Skip to content

Commit c1e6d7d

Browse files
authored
Merge of #5120
2 parents ac66cb5 + 0aa5ed2 commit c1e6d7d

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

beacon_node/beacon_chain/src/data_availability_checker.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,18 @@ pub struct AvailableBlock<E: EthSpec> {
545545
}
546546

547547
impl<E: EthSpec> AvailableBlock<E> {
548+
pub fn __new_for_testing(
549+
block_root: Hash256,
550+
block: Arc<SignedBeaconBlock<E>>,
551+
blobs: Option<BlobSidecarList<E>>,
552+
) -> Self {
553+
Self {
554+
block_root,
555+
block,
556+
blobs,
557+
}
558+
}
559+
548560
pub fn block(&self) -> &SignedBeaconBlock<E> {
549561
&self.block
550562
}

beacon_node/beacon_chain/src/historical_blocks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,20 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
135135

136136
prev_block_slot = block.slot();
137137
expected_block_root = block.message().parent_root();
138+
signed_blocks.push(block);
138139

139140
// If we've reached genesis, add the genesis block root to the batch for all slots
140141
// between 0 and the first block slot, and set the anchor slot to 0 to indicate
141142
// completion.
142143
if expected_block_root == self.genesis_block_root {
143144
let genesis_slot = self.spec.genesis_slot;
144-
for slot in genesis_slot.as_usize()..block.slot().as_usize() {
145+
for slot in genesis_slot.as_usize()..prev_block_slot.as_usize() {
145146
chunk_writer.set(slot, self.genesis_block_root, &mut cold_batch)?;
146147
}
147148
prev_block_slot = genesis_slot;
148149
expected_block_root = Hash256::zero();
149150
break;
150151
}
151-
signed_blocks.push(block);
152152
}
153153
chunk_writer.write(&mut cold_batch)?;
154154
// these were pushed in reverse order so we reverse again

beacon_node/beacon_chain/tests/store_tests.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use beacon_chain::attestation_verification::Error as AttnError;
44
use beacon_chain::block_verification_types::RpcBlock;
55
use beacon_chain::builder::BeaconChainBuilder;
6+
use beacon_chain::data_availability_checker::AvailableBlock;
67
use beacon_chain::schema_change::migrate_schema;
78
use beacon_chain::test_utils::{
89
mock_execution_layer_from_parts, test_spec, AttestationStrategy, BeaconChainHarness,
@@ -2547,6 +2548,25 @@ async fn weak_subjectivity_sync_test(slots: Vec<Slot>, checkpoint_slot: Slot) {
25472548
}
25482549
}
25492550

2551+
// Corrupt the signature on the 1st block to ensure that the backfill processor is checking
2552+
// signatures correctly. Regression test for https://github.com/sigp/lighthouse/pull/5120.
2553+
let mut batch_with_invalid_first_block = available_blocks.clone();
2554+
batch_with_invalid_first_block[0] = {
2555+
let (block_root, block, blobs) = available_blocks[0].clone().deconstruct();
2556+
let mut corrupt_block = (*block).clone();
2557+
*corrupt_block.signature_mut() = Signature::empty();
2558+
AvailableBlock::__new_for_testing(block_root, Arc::new(corrupt_block), blobs)
2559+
};
2560+
2561+
// Importing the invalid batch should error.
2562+
assert!(matches!(
2563+
beacon_chain
2564+
.import_historical_block_batch(batch_with_invalid_first_block)
2565+
.unwrap_err(),
2566+
BeaconChainError::HistoricalBlockError(HistoricalBlockError::InvalidSignature)
2567+
));
2568+
2569+
// Importing the batch with valid signatures should succeed.
25502570
beacon_chain
25512571
.import_historical_block_batch(available_blocks.clone())
25522572
.unwrap();

0 commit comments

Comments
 (0)