Skip to content

Commit 3838897

Browse files
authored
Strict match of errors in backfill sync (#6520)
* Strict match of errors in backfill sync * Fix tests
1 parent 6a8d13e commit 3838897

File tree

6 files changed

+113
-143
lines changed

6 files changed

+113
-143
lines changed

beacon_node/beacon_chain/src/beacon_chain.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ use crate::execution_payload::{get_execution_payload, NotifyExecutionLayer, Prep
3434
use crate::fork_choice_signal::{ForkChoiceSignalRx, ForkChoiceSignalTx, ForkChoiceWaitResult};
3535
use crate::graffiti_calculator::GraffitiCalculator;
3636
use crate::head_tracker::{HeadTracker, HeadTrackerReader, SszHeadTracker};
37-
use crate::historical_blocks::HistoricalBlockError;
3837
use crate::light_client_finality_update_verification::{
3938
Error as LightClientFinalityUpdateError, VerifiedLightClientFinalityUpdate,
4039
};
@@ -755,12 +754,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
755754
) -> Result<impl Iterator<Item = Result<(Hash256, Slot), Error>> + '_, Error> {
756755
let oldest_block_slot = self.store.get_oldest_block_slot();
757756
if start_slot < oldest_block_slot {
758-
return Err(Error::HistoricalBlockError(
759-
HistoricalBlockError::BlockOutOfRange {
760-
slot: start_slot,
761-
oldest_block_slot,
762-
},
763-
));
757+
return Err(Error::HistoricalBlockOutOfRange {
758+
slot: start_slot,
759+
oldest_block_slot,
760+
});
764761
}
765762

766763
let local_head = self.head_snapshot();
@@ -785,12 +782,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
785782
) -> Result<impl Iterator<Item = Result<(Hash256, Slot), Error>> + '_, Error> {
786783
let oldest_block_slot = self.store.get_oldest_block_slot();
787784
if start_slot < oldest_block_slot {
788-
return Err(Error::HistoricalBlockError(
789-
HistoricalBlockError::BlockOutOfRange {
790-
slot: start_slot,
791-
oldest_block_slot,
792-
},
793-
));
785+
return Err(Error::HistoricalBlockOutOfRange {
786+
slot: start_slot,
787+
oldest_block_slot,
788+
});
794789
}
795790

796791
self.with_head(move |head| {
@@ -991,7 +986,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
991986
WhenSlotSkipped::Prev => self.block_root_at_slot_skips_prev(request_slot),
992987
}
993988
.or_else(|e| match e {
994-
Error::HistoricalBlockError(_) => Ok(None),
989+
Error::HistoricalBlockOutOfRange { .. } => Ok(None),
995990
e => Err(e),
996991
})
997992
}

beacon_node/beacon_chain/src/errors.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::beacon_chain::ForkChoiceError;
44
use crate::beacon_fork_choice_store::Error as ForkChoiceStoreError;
55
use crate::data_availability_checker::AvailabilityCheckError;
66
use crate::eth1_chain::Error as Eth1ChainError;
7-
use crate::historical_blocks::HistoricalBlockError;
87
use crate::migrate::PruningError;
98
use crate::naive_aggregation_pool::Error as NaiveAggregationError;
109
use crate::observed_aggregates::Error as ObservedAttestationsError;
@@ -123,7 +122,11 @@ pub enum BeaconChainError {
123122
block_slot: Slot,
124123
state_slot: Slot,
125124
},
126-
HistoricalBlockError(HistoricalBlockError),
125+
/// Block is not available (only returned when fetching historic blocks).
126+
HistoricalBlockOutOfRange {
127+
slot: Slot,
128+
oldest_block_slot: Slot,
129+
},
127130
InvalidStateForShuffling {
128131
state_epoch: Epoch,
129132
shuffling_epoch: Epoch,
@@ -245,7 +248,6 @@ easy_from_to!(BlockSignatureVerifierError, BeaconChainError);
245248
easy_from_to!(PruningError, BeaconChainError);
246249
easy_from_to!(ArithError, BeaconChainError);
247250
easy_from_to!(ForkChoiceStoreError, BeaconChainError);
248-
easy_from_to!(HistoricalBlockError, BeaconChainError);
249251
easy_from_to!(StateAdvanceError, BeaconChainError);
250252
easy_from_to!(BlockReplayError, BeaconChainError);
251253
easy_from_to!(InconsistentFork, BeaconChainError);

beacon_node/beacon_chain/src/historical_blocks.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::data_availability_checker::AvailableBlock;
2-
use crate::{errors::BeaconChainError as Error, metrics, BeaconChain, BeaconChainTypes};
2+
use crate::{metrics, BeaconChain, BeaconChainTypes};
33
use itertools::Itertools;
44
use slog::debug;
55
use state_processing::{
@@ -10,18 +10,20 @@ use std::borrow::Cow;
1010
use std::iter;
1111
use std::time::Duration;
1212
use store::metadata::DataColumnInfo;
13-
use store::{chunked_vector::BlockRoots, AnchorInfo, BlobInfo, ChunkWriter, KeyValueStore};
13+
use store::{
14+
chunked_vector::BlockRoots, AnchorInfo, BlobInfo, ChunkWriter, Error as StoreError,
15+
KeyValueStore,
16+
};
17+
use strum::IntoStaticStr;
1418
use types::{FixedBytesExtended, Hash256, Slot};
1519

1620
/// Use a longer timeout on the pubkey cache.
1721
///
1822
/// It's ok if historical sync is stalled due to writes from forwards block processing.
1923
const PUBKEY_CACHE_LOCK_TIMEOUT: Duration = Duration::from_secs(30);
2024

21-
#[derive(Debug)]
25+
#[derive(Debug, IntoStaticStr)]
2226
pub enum HistoricalBlockError {
23-
/// Block is not available (only returned when fetching historic blocks).
24-
BlockOutOfRange { slot: Slot, oldest_block_slot: Slot },
2527
/// Block root mismatch, caller should retry with different blocks.
2628
MismatchedBlockRoot {
2729
block_root: Hash256,
@@ -37,6 +39,14 @@ pub enum HistoricalBlockError {
3739
NoAnchorInfo,
3840
/// Logic error: should never occur.
3941
IndexOutOfBounds,
42+
/// Internal store error
43+
StoreError(StoreError),
44+
}
45+
46+
impl From<StoreError> for HistoricalBlockError {
47+
fn from(e: StoreError) -> Self {
48+
Self::StoreError(e)
49+
}
4050
}
4151

4252
impl<T: BeaconChainTypes> BeaconChain<T> {
@@ -61,7 +71,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
6171
pub fn import_historical_block_batch(
6272
&self,
6373
mut blocks: Vec<AvailableBlock<T::EthSpec>>,
64-
) -> Result<usize, Error> {
74+
) -> Result<usize, HistoricalBlockError> {
6575
let anchor_info = self
6676
.store
6777
.get_anchor_info()
@@ -127,8 +137,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
127137
return Err(HistoricalBlockError::MismatchedBlockRoot {
128138
block_root,
129139
expected_block_root,
130-
}
131-
.into());
140+
});
132141
}
133142

134143
let blinded_block = block.clone_as_blinded();
@@ -212,7 +221,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
212221

213222
let verify_timer = metrics::start_timer(&metrics::BACKFILL_SIGNATURE_VERIFY_TIMES);
214223
if !signature_set.verify() {
215-
return Err(HistoricalBlockError::InvalidSignature.into());
224+
return Err(HistoricalBlockError::InvalidSignature);
216225
}
217226
drop(verify_timer);
218227
drop(sig_timer);

beacon_node/beacon_chain/tests/store_tests.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2669,9 +2669,7 @@ async fn weak_subjectivity_sync_test(slots: Vec<Slot>, checkpoint_slot: Slot) {
26692669
// Forwards iterator from 0 should fail as we lack blocks.
26702670
assert!(matches!(
26712671
beacon_chain.forwards_iter_block_roots(Slot::new(0)),
2672-
Err(BeaconChainError::HistoricalBlockError(
2673-
HistoricalBlockError::BlockOutOfRange { .. }
2674-
))
2672+
Err(BeaconChainError::HistoricalBlockOutOfRange { .. })
26752673
));
26762674

26772675
// Simulate processing of a `StatusMessage` with an older finalized epoch by calling
@@ -2739,7 +2737,7 @@ async fn weak_subjectivity_sync_test(slots: Vec<Slot>, checkpoint_slot: Slot) {
27392737
beacon_chain
27402738
.import_historical_block_batch(batch_with_invalid_first_block)
27412739
.unwrap_err(),
2742-
BeaconChainError::HistoricalBlockError(HistoricalBlockError::InvalidSignature)
2740+
HistoricalBlockError::InvalidSignature
27432741
));
27442742

27452743
// Importing the batch with valid signatures should succeed.

beacon_node/network/src/network_beacon_processor/rpc_methods.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::network_beacon_processor::{NetworkBeaconProcessor, FUTURE_SLOT_TOLERA
22
use crate::service::NetworkMessage;
33
use crate::status::ToStatusMessage;
44
use crate::sync::SyncMessage;
5-
use beacon_chain::{BeaconChainError, BeaconChainTypes, HistoricalBlockError, WhenSlotSkipped};
5+
use beacon_chain::{BeaconChainError, BeaconChainTypes, WhenSlotSkipped};
66
use itertools::process_results;
77
use lighthouse_network::discovery::ConnectionId;
88
use lighthouse_network::rpc::methods::{
@@ -682,12 +682,10 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
682682
.forwards_iter_block_roots(Slot::from(*req.start_slot()))
683683
{
684684
Ok(iter) => iter,
685-
Err(BeaconChainError::HistoricalBlockError(
686-
HistoricalBlockError::BlockOutOfRange {
687-
slot,
688-
oldest_block_slot,
689-
},
690-
)) => {
685+
Err(BeaconChainError::HistoricalBlockOutOfRange {
686+
slot,
687+
oldest_block_slot,
688+
}) => {
691689
debug!(self.log, "Range request failed during backfill";
692690
"requested_slot" => slot,
693691
"oldest_known_slot" => oldest_block_slot
@@ -941,12 +939,10 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
941939
let forwards_block_root_iter =
942940
match self.chain.forwards_iter_block_roots(request_start_slot) {
943941
Ok(iter) => iter,
944-
Err(BeaconChainError::HistoricalBlockError(
945-
HistoricalBlockError::BlockOutOfRange {
946-
slot,
947-
oldest_block_slot,
948-
},
949-
)) => {
942+
Err(BeaconChainError::HistoricalBlockOutOfRange {
943+
slot,
944+
oldest_block_slot,
945+
}) => {
950946
debug!(self.log, "Range request failed during backfill";
951947
"requested_slot" => slot,
952948
"oldest_known_slot" => oldest_block_slot
@@ -1147,12 +1143,10 @@ impl<T: BeaconChainTypes> NetworkBeaconProcessor<T> {
11471143
let forwards_block_root_iter =
11481144
match self.chain.forwards_iter_block_roots(request_start_slot) {
11491145
Ok(iter) => iter,
1150-
Err(BeaconChainError::HistoricalBlockError(
1151-
HistoricalBlockError::BlockOutOfRange {
1152-
slot,
1153-
oldest_block_slot,
1154-
},
1155-
)) => {
1146+
Err(BeaconChainError::HistoricalBlockOutOfRange {
1147+
slot,
1148+
oldest_block_slot,
1149+
}) => {
11561150
debug!(self.log, "Range request failed during backfill";
11571151
"requested_slot" => slot,
11581152
"oldest_known_slot" => oldest_block_slot

0 commit comments

Comments
 (0)