Skip to content

Commit 232ec80

Browse files
committed
Fix custody context initialization race condition that caused panic (#8391)
1 parent 47b984e commit 232ec80

File tree

15 files changed

+221
-190
lines changed

15 files changed

+221
-190
lines changed

beacon_node/beacon_chain/src/builder.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ use std::time::Duration;
4040
use store::{Error as StoreError, HotColdDB, ItemStore, KeyValueStoreOp};
4141
use task_executor::{ShutdownReason, TaskExecutor};
4242
use tracing::{debug, error, info};
43+
use types::data_column_custody_group::CustodyIndex;
4344
use types::{
44-
BeaconBlock, BeaconState, BlobSidecarList, ChainSpec, DataColumnSidecarList, Epoch, EthSpec,
45-
FixedBytesExtended, Hash256, Signature, SignedBeaconBlock, Slot,
45+
BeaconBlock, BeaconState, BlobSidecarList, ChainSpec, ColumnIndex, DataColumnSidecarList,
46+
Epoch, EthSpec, FixedBytesExtended, Hash256, Signature, SignedBeaconBlock, Slot,
4647
};
4748

4849
/// An empty struct used to "witness" all the `BeaconChainTypes` traits. It has no user-facing
@@ -102,6 +103,7 @@ pub struct BeaconChainBuilder<T: BeaconChainTypes> {
102103
task_executor: Option<TaskExecutor>,
103104
validator_monitor_config: Option<ValidatorMonitorConfig>,
104105
node_custody_type: NodeCustodyType,
106+
ordered_custody_column_indices: Option<Vec<CustodyIndex>>,
105107
rng: Option<Box<dyn RngCore + Send>>,
106108
}
107109

@@ -141,6 +143,7 @@ where
141143
task_executor: None,
142144
validator_monitor_config: None,
143145
node_custody_type: NodeCustodyType::Fullnode,
146+
ordered_custody_column_indices: None,
144147
rng: None,
145148
}
146149
}
@@ -647,6 +650,16 @@ where
647650
self
648651
}
649652

653+
/// Sets the ordered custody column indices for this node.
654+
/// This is used to determine the data columns the node is required to custody.
655+
pub fn ordered_custody_column_indices(
656+
mut self,
657+
ordered_custody_column_indices: Vec<ColumnIndex>,
658+
) -> Self {
659+
self.ordered_custody_column_indices = Some(ordered_custody_column_indices);
660+
self
661+
}
662+
650663
/// Sets the `BeaconChain` event handler backend.
651664
///
652665
/// For example, provide `ServerSentEventHandler` as a `handler`.
@@ -740,6 +753,9 @@ where
740753
.genesis_state_root
741754
.ok_or("Cannot build without a genesis state root")?;
742755
let validator_monitor_config = self.validator_monitor_config.unwrap_or_default();
756+
let ordered_custody_column_indices = self
757+
.ordered_custody_column_indices
758+
.ok_or("Cannot build without ordered custody column indices")?;
743759
let rng = self.rng.ok_or("Cannot build without an RNG")?;
744760
let beacon_proposer_cache: Arc<Mutex<BeaconProposerCache>> = <_>::default();
745761

@@ -942,11 +958,16 @@ where
942958
custody,
943959
self.node_custody_type,
944960
head_epoch,
961+
ordered_custody_column_indices,
945962
&self.spec,
946963
)
947964
} else {
948965
(
949-
CustodyContext::new(self.node_custody_type, &self.spec),
966+
CustodyContext::new(
967+
self.node_custody_type,
968+
ordered_custody_column_indices,
969+
&self.spec,
970+
),
950971
None,
951972
)
952973
};
@@ -1272,6 +1293,9 @@ mod test {
12721293
.expect("should configure testing slot clock")
12731294
.shutdown_sender(shutdown_tx)
12741295
.rng(Box::new(StdRng::seed_from_u64(42)))
1296+
.ordered_custody_column_indices(
1297+
(0..MinimalEthSpec::number_of_columns() as u64).collect(),
1298+
)
12751299
.build()
12761300
.expect("should build");
12771301

0 commit comments

Comments
 (0)