mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
Fix wrong columns getting processed on a CGC change (#7792)
This PR fixes a bug where wrong columns could get processed immediately after a CGC increase.
Scenario:
- The node's CGC increased due to additional validators attached to it (lets say from 10 to 11)
- The new CGC is advertised and new subnets are subscribed immediately, however the change won't be effective in the data availability check until the next epoch (See [this](ab0e8870b4/beacon_node/beacon_chain/src/validator_custody.rs (L93-L99))). Data availability checker still only require 10 columns for the current epoch.
- During this time, data columns for the additional custody column (lets say column 11) may arrive via gossip as we're already subscribed to the topic, and it may be incorrectly used to satisfy the existing data availability requirement (10 columns), and result in this additional column (instead of a required one) getting persisted, resulting in database inconsistency.
This commit is contained in:
@@ -780,7 +780,7 @@ impl ChainSpec {
|
||||
}
|
||||
|
||||
/// Returns the number of column sidecars to sample per slot.
|
||||
pub fn sampling_size_columns(&self, custody_group_count: u64) -> Result<u64, String> {
|
||||
pub fn sampling_size_columns(&self, custody_group_count: u64) -> Result<usize, String> {
|
||||
let sampling_size_groups = self.sampling_size_custody_groups(custody_group_count)?;
|
||||
|
||||
let columns_per_custody_group = self
|
||||
@@ -792,7 +792,7 @@ impl ChainSpec {
|
||||
.safe_mul(sampling_size_groups)
|
||||
.map_err(|_| "Computing sampling size should not overflow")?;
|
||||
|
||||
Ok(sampling_size_columns)
|
||||
Ok(sampling_size_columns as usize)
|
||||
}
|
||||
|
||||
/// Returns the number of custody groups to sample per slot.
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use crate::{ChainSpec, ColumnIndex, DataColumnSubnetId};
|
||||
use alloy_primitives::U256;
|
||||
use itertools::Itertools;
|
||||
use maplit::hashset;
|
||||
use safe_arith::{ArithError, SafeArith};
|
||||
use std::collections::HashSet;
|
||||
|
||||
@@ -25,13 +24,32 @@ pub fn get_custody_groups(
|
||||
custody_group_count: u64,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<HashSet<CustodyIndex>, DataColumnCustodyGroupError> {
|
||||
get_custody_groups_ordered(raw_node_id, custody_group_count, spec)
|
||||
.map(|custody_groups| custody_groups.into_iter().collect())
|
||||
}
|
||||
|
||||
/// Returns a deterministically ordered list of custody groups assigned to a node,
|
||||
/// preserving the order in which they were computed during iteration.
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `raw_node_id` - 32-byte node identifier
|
||||
/// * `custody_group_count` - Number of custody groups to generate
|
||||
/// * `spec` - Chain specification containing custody group parameters
|
||||
///
|
||||
/// # Returns
|
||||
/// Vector of custody group indices in computation order or error if parameters are invalid
|
||||
pub fn get_custody_groups_ordered(
|
||||
raw_node_id: [u8; 32],
|
||||
custody_group_count: u64,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<Vec<CustodyIndex>, DataColumnCustodyGroupError> {
|
||||
if custody_group_count > spec.number_of_custody_groups {
|
||||
return Err(DataColumnCustodyGroupError::InvalidCustodyGroupCount(
|
||||
custody_group_count,
|
||||
));
|
||||
}
|
||||
|
||||
let mut custody_groups: HashSet<u64> = hashset![];
|
||||
let mut custody_groups = vec![];
|
||||
let mut current_id = U256::from_be_slice(&raw_node_id);
|
||||
while custody_groups.len() < custody_group_count as usize {
|
||||
let mut node_id_bytes = [0u8; 32];
|
||||
@@ -44,7 +62,9 @@ pub fn get_custody_groups(
|
||||
let custody_group = hash_prefix_u64
|
||||
.safe_rem(spec.number_of_custody_groups)
|
||||
.expect("spec.number_of_custody_groups must not be zero");
|
||||
custody_groups.insert(custody_group);
|
||||
if !custody_groups.contains(&custody_group) {
|
||||
custody_groups.push(custody_group);
|
||||
}
|
||||
|
||||
current_id = current_id.wrapping_add(U256::from(1u64));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user