mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 09:16:00 +00:00
Remove CGC from data_availability checker (#7033)
- Part of https://github.com/sigp/lighthouse/issues/6767 Validator custody makes the CGC and set of sampling columns dynamic. Right now this information is stored twice: - in the data availability checker - in the network globals If that state becomes dynamic we must make sure it is in sync updating it twice, or guarding it behind a mutex. However, I noted that we don't really have to keep the CGC inside the data availability checker. All consumers can actually read it from the network globals, and we can update `make_available` to read the expected count of data columns from the block.
This commit is contained in:
@@ -30,6 +30,8 @@ type E = MainnetEthSpec;
|
||||
const VALIDATOR_COUNT: usize = 24;
|
||||
const CHAIN_SEGMENT_LENGTH: usize = 64 * 5;
|
||||
const BLOCK_INDICES: &[usize] = &[0, 1, 32, 64, 68 + 1, 129, CHAIN_SEGMENT_LENGTH - 1];
|
||||
// Default custody group count for tests
|
||||
const CGC: usize = 8;
|
||||
|
||||
/// A cached set of keys.
|
||||
static KEYPAIRS: LazyLock<Vec<Keypair>> =
|
||||
@@ -142,7 +144,8 @@ fn build_rpc_block(
|
||||
RpcBlock::new(None, block, Some(blobs.clone())).unwrap()
|
||||
}
|
||||
Some(DataSidecars::DataColumns(columns)) => {
|
||||
RpcBlock::new_with_custody_columns(None, block, columns.clone(), spec).unwrap()
|
||||
RpcBlock::new_with_custody_columns(None, block, columns.clone(), columns.len(), spec)
|
||||
.unwrap()
|
||||
}
|
||||
None => RpcBlock::new_without_blobs(None, block),
|
||||
}
|
||||
@@ -991,6 +994,7 @@ async fn block_gossip_verification() {
|
||||
let (chain_segment, chain_segment_blobs) = get_chain_segment().await;
|
||||
|
||||
let block_index = CHAIN_SEGMENT_LENGTH - 2;
|
||||
let cgc = harness.chain.spec.custody_requirement as usize;
|
||||
|
||||
harness
|
||||
.chain
|
||||
@@ -1004,7 +1008,7 @@ async fn block_gossip_verification() {
|
||||
{
|
||||
let gossip_verified = harness
|
||||
.chain
|
||||
.verify_block_for_gossip(snapshot.beacon_block.clone())
|
||||
.verify_block_for_gossip(snapshot.beacon_block.clone(), get_cgc(&blobs_opt))
|
||||
.await
|
||||
.expect("should obtain gossip verified block");
|
||||
|
||||
@@ -1046,7 +1050,7 @@ async fn block_gossip_verification() {
|
||||
*block.slot_mut() = expected_block_slot;
|
||||
assert!(
|
||||
matches!(
|
||||
unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(SignedBeaconBlock::from_block(block, signature))).await),
|
||||
unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(SignedBeaconBlock::from_block(block, signature)), cgc).await),
|
||||
BlockError::FutureSlot {
|
||||
present_slot,
|
||||
block_slot,
|
||||
@@ -1080,7 +1084,7 @@ async fn block_gossip_verification() {
|
||||
*block.slot_mut() = expected_finalized_slot;
|
||||
assert!(
|
||||
matches!(
|
||||
unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(SignedBeaconBlock::from_block(block, signature))).await),
|
||||
unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(SignedBeaconBlock::from_block(block, signature)), cgc).await),
|
||||
BlockError::WouldRevertFinalizedSlot {
|
||||
block_slot,
|
||||
finalized_slot,
|
||||
@@ -1110,10 +1114,10 @@ async fn block_gossip_verification() {
|
||||
unwrap_err(
|
||||
harness
|
||||
.chain
|
||||
.verify_block_for_gossip(Arc::new(SignedBeaconBlock::from_block(
|
||||
block,
|
||||
junk_signature()
|
||||
)))
|
||||
.verify_block_for_gossip(
|
||||
Arc::new(SignedBeaconBlock::from_block(block, junk_signature())),
|
||||
cgc
|
||||
)
|
||||
.await
|
||||
),
|
||||
BlockError::InvalidSignature(InvalidSignature::ProposerSignature)
|
||||
@@ -1138,7 +1142,7 @@ async fn block_gossip_verification() {
|
||||
*block.parent_root_mut() = parent_root;
|
||||
assert!(
|
||||
matches!(
|
||||
unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(SignedBeaconBlock::from_block(block, signature))).await),
|
||||
unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(SignedBeaconBlock::from_block(block, signature)), cgc).await),
|
||||
BlockError::ParentUnknown {parent_root: p}
|
||||
if p == parent_root
|
||||
),
|
||||
@@ -1164,7 +1168,7 @@ async fn block_gossip_verification() {
|
||||
*block.parent_root_mut() = parent_root;
|
||||
assert!(
|
||||
matches!(
|
||||
unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(SignedBeaconBlock::from_block(block, signature))).await),
|
||||
unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(SignedBeaconBlock::from_block(block, signature)), cgc).await),
|
||||
BlockError::NotFinalizedDescendant { block_parent_root }
|
||||
if block_parent_root == parent_root
|
||||
),
|
||||
@@ -1201,7 +1205,7 @@ async fn block_gossip_verification() {
|
||||
);
|
||||
assert!(
|
||||
matches!(
|
||||
unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(block.clone())).await),
|
||||
unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(block.clone()), cgc).await),
|
||||
BlockError::IncorrectBlockProposer {
|
||||
block,
|
||||
local_shuffling,
|
||||
@@ -1213,7 +1217,7 @@ async fn block_gossip_verification() {
|
||||
// Check to ensure that we registered this is a valid block from this proposer.
|
||||
assert!(
|
||||
matches!(
|
||||
unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(block.clone())).await),
|
||||
unwrap_err(harness.chain.verify_block_for_gossip(Arc::new(block.clone()), cgc).await),
|
||||
BlockError::DuplicateImportStatusUnknown(_),
|
||||
),
|
||||
"should register any valid signature against the proposer, even if the block failed later verification"
|
||||
@@ -1221,7 +1225,11 @@ async fn block_gossip_verification() {
|
||||
|
||||
let block = chain_segment[block_index].beacon_block.clone();
|
||||
assert!(
|
||||
harness.chain.verify_block_for_gossip(block).await.is_ok(),
|
||||
harness
|
||||
.chain
|
||||
.verify_block_for_gossip(block, cgc)
|
||||
.await
|
||||
.is_ok(),
|
||||
"the valid block should be processed"
|
||||
);
|
||||
|
||||
@@ -1239,7 +1247,7 @@ async fn block_gossip_verification() {
|
||||
matches!(
|
||||
harness
|
||||
.chain
|
||||
.verify_block_for_gossip(block.clone())
|
||||
.verify_block_for_gossip(block.clone(), cgc)
|
||||
.await
|
||||
.expect_err("should error when processing known block"),
|
||||
BlockError::DuplicateImportStatusUnknown(_)
|
||||
@@ -1315,8 +1323,17 @@ async fn verify_block_for_gossip_slashing_detection() {
|
||||
let state = harness.get_current_state();
|
||||
let ((block1, blobs1), _) = harness.make_block(state.clone(), Slot::new(1)).await;
|
||||
let ((block2, _blobs2), _) = harness.make_block(state, Slot::new(1)).await;
|
||||
let cgc = if block1.fork_name_unchecked().fulu_enabled() {
|
||||
harness.get_sampling_column_count()
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
let verified_block = harness.chain.verify_block_for_gossip(block1).await.unwrap();
|
||||
let verified_block = harness
|
||||
.chain
|
||||
.verify_block_for_gossip(block1, cgc)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
if let Some((kzg_proofs, blobs)) = blobs1 {
|
||||
harness
|
||||
@@ -1339,7 +1356,7 @@ async fn verify_block_for_gossip_slashing_detection() {
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
unwrap_err(harness.chain.verify_block_for_gossip(block2).await);
|
||||
unwrap_err(harness.chain.verify_block_for_gossip(block2, CGC).await);
|
||||
|
||||
// Slasher should have been handed the two conflicting blocks and crafted a slashing.
|
||||
slasher.process_queued(Epoch::new(0)).unwrap();
|
||||
@@ -1363,7 +1380,11 @@ async fn verify_block_for_gossip_doppelganger_detection() {
|
||||
.attestations()
|
||||
.map(|att| att.clone_as_attestation())
|
||||
.collect::<Vec<_>>();
|
||||
let verified_block = harness.chain.verify_block_for_gossip(block).await.unwrap();
|
||||
let verified_block = harness
|
||||
.chain
|
||||
.verify_block_for_gossip(block, CGC)
|
||||
.await
|
||||
.unwrap();
|
||||
harness
|
||||
.chain
|
||||
.process_block(
|
||||
@@ -1510,7 +1531,7 @@ async fn add_base_block_to_altair_chain() {
|
||||
assert!(matches!(
|
||||
harness
|
||||
.chain
|
||||
.verify_block_for_gossip(Arc::new(base_block.clone()))
|
||||
.verify_block_for_gossip(Arc::new(base_block.clone()), CGC)
|
||||
.await
|
||||
.expect_err("should error when processing base block"),
|
||||
BlockError::InconsistentFork(InconsistentFork {
|
||||
@@ -1646,7 +1667,7 @@ async fn add_altair_block_to_base_chain() {
|
||||
assert!(matches!(
|
||||
harness
|
||||
.chain
|
||||
.verify_block_for_gossip(Arc::new(altair_block.clone()))
|
||||
.verify_block_for_gossip(Arc::new(altair_block.clone()), CGC)
|
||||
.await
|
||||
.expect_err("should error when processing altair block"),
|
||||
BlockError::InconsistentFork(InconsistentFork {
|
||||
@@ -1810,3 +1831,14 @@ async fn import_execution_pending_block<T: BeaconChainTypes>(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_cgc<E: EthSpec>(blobs_opt: &Option<DataSidecars<E>>) -> usize {
|
||||
if let Some(data_sidecars) = blobs_opt.as_ref() {
|
||||
match data_sidecars {
|
||||
DataSidecars::Blobs(_) => 0,
|
||||
DataSidecars::DataColumns(d) => d.len(),
|
||||
}
|
||||
} else {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ use task_executor::ShutdownReason;
|
||||
use types::*;
|
||||
|
||||
const VALIDATOR_COUNT: usize = 32;
|
||||
const CGC: usize = 8;
|
||||
|
||||
type E = MainnetEthSpec;
|
||||
|
||||
@@ -1050,7 +1051,7 @@ async fn invalid_parent() {
|
||||
|
||||
// Ensure the block built atop an invalid payload is invalid for gossip.
|
||||
assert!(matches!(
|
||||
rig.harness.chain.clone().verify_block_for_gossip(block.clone()).await,
|
||||
rig.harness.chain.clone().verify_block_for_gossip(block.clone(), CGC).await,
|
||||
Err(BlockError::ParentExecutionPayloadInvalid { parent_root: invalid_root })
|
||||
if invalid_root == parent_root
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user