mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-06 10:11:44 +00:00
Fix custody context initialization race condition that caused panic (#8391)
Take 2 of #8390. Fixes the race condition properly instead of propagating the error. I think this is a better alternative, and doesn't seem to look that bad. * Lift node id loading or generation from `NetworkService ` startup to the `ClientBuilder`, so that it can be used to compute custody columns for the beacon chain without waiting for Network bootstrap. I've considered and implemented a few alternatives: 1. passing `node_id` to beacon chain builder and compute columns when creating `CustodyContext`. This approach isn't good for separation of concerns and isn't great for testability 2. passing `ordered_custody_groups` to beacon chain. `CustodyContext` only uses this to compute ordered custody columns, so we might as well lift this logic out, so we don't have to do error handling in `CustodyContext` construction. Less tests to update;. Co-Authored-By: Jimmy Chen <jchen.tc@gmail.com>
This commit is contained in:
@@ -9,6 +9,8 @@ pub use client::{Client, ClientBuilder, ClientConfig, ClientGenesis};
|
||||
pub use config::{get_config, get_data_dir, set_network_config};
|
||||
use environment::RuntimeContext;
|
||||
pub use eth2_config::Eth2Config;
|
||||
use lighthouse_network::load_private_key;
|
||||
use network_utils::enr_ext::peer_id_to_node_id;
|
||||
use slasher::{DatabaseBackendOverride, Slasher};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::sync::Arc;
|
||||
@@ -120,8 +122,12 @@ impl<E: EthSpec> ProductionBeaconNode<E> {
|
||||
builder
|
||||
};
|
||||
|
||||
// Generate or load the node id.
|
||||
let local_keypair = load_private_key(&client_config.network);
|
||||
let node_id = peer_id_to_node_id(&local_keypair.public().to_peer_id())?.raw();
|
||||
|
||||
let builder = builder
|
||||
.beacon_chain_builder(client_genesis, client_config.clone())
|
||||
.beacon_chain_builder(client_genesis, client_config.clone(), node_id)
|
||||
.await?;
|
||||
info!("Block production enabled");
|
||||
|
||||
@@ -133,7 +139,7 @@ impl<E: EthSpec> ProductionBeaconNode<E> {
|
||||
|
||||
builder
|
||||
.build_beacon_chain()?
|
||||
.network(Arc::new(client_config.network))
|
||||
.network(Arc::new(client_config.network), local_keypair)
|
||||
.await?
|
||||
.notifier()?
|
||||
.http_metrics_config(client_config.http_metrics.clone())
|
||||
|
||||
Reference in New Issue
Block a user