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:
Jimmy Chen
2025-11-17 16:23:12 +11:00
committed by GitHub
parent f2b945a5b5
commit af1d9b9991
15 changed files with 230 additions and 196 deletions

View File

@@ -42,7 +42,7 @@ pub fn get_custody_groups(
///
/// # Returns
/// Vector of custody group indices in computation order or error if parameters are invalid
pub fn get_custody_groups_ordered(
fn get_custody_groups_ordered(
raw_node_id: [u8; 32],
custody_group_count: u64,
spec: &ChainSpec,
@@ -76,6 +76,27 @@ pub fn get_custody_groups_ordered(
Ok(custody_groups)
}
/// Returns a deterministically ordered list of custody columns assigned to a node,
/// preserving the order in which they were computed during iteration.
///
/// # Arguments
/// * `raw_node_id` - 32-byte node identifier
/// * `spec` - Chain specification containing custody parameters
pub fn compute_ordered_custody_column_indices<E: EthSpec>(
raw_node_id: [u8; 32],
spec: &ChainSpec,
) -> Result<Vec<ColumnIndex>, DataColumnCustodyGroupError> {
let all_custody_groups_ordered =
get_custody_groups_ordered(raw_node_id, spec.number_of_custody_groups, spec)?;
let mut ordered_custody_columns = vec![];
for custody_index in all_custody_groups_ordered {
let columns = compute_columns_for_custody_group::<E>(custody_index, spec)?;
ordered_custody_columns.extend(columns);
}
Ok(ordered_custody_columns)
}
/// Returns the columns that are associated with a given custody group.
///
/// spec: https://github.com/ethereum/consensus-specs/blob/8e0d0d48e81d6c7c5a8253ab61340f5ea5bac66a/specs/fulu/das-core.md#compute_columns_for_custody_group