Skip to content

Commit a74395f

Browse files
authored
ledger: Propagate error for unable to replay bank 0 (anza-xyz#5200)
We currently .expect() which panics and reports a datapoint which adds noise to the list of panics when looking at metrics. These can be filtered out, but propagating the error is more proper anyways
1 parent 01e50dc commit a74395f

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

core/src/replay_stage.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9194,7 +9194,8 @@ pub(crate) mod tests {
91949194
&recyclers,
91959195
None,
91969196
None,
9197-
);
9197+
)
9198+
.unwrap();
91989199

91999200
// Mark block 1, 3, 4, 5 as duplicate
92009201
blockstore.store_duplicate_slot(1, vec![], vec![]).unwrap();

ledger/src/bank_forks_utils.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ pub enum BankForksUtilsError {
5858
path: PathBuf,
5959
},
6060

61+
#[error("failed to process blockstore from genesis: {0}")]
62+
ProcessBlockstoreFromGenesis(#[source] BlockstoreProcessorError),
63+
6164
#[error("failed to process blockstore from root: {0}")]
6265
ProcessBlockstoreFromRoot(#[source] BlockstoreProcessorError),
6366
}
@@ -195,7 +198,8 @@ pub fn load_bank_forks(
195198
entry_notification_sender,
196199
accounts_update_notifier,
197200
exit,
198-
);
201+
)
202+
.map_err(BankForksUtilsError::ProcessBlockstoreFromGenesis)?;
199203
bank_forks
200204
.read()
201205
.unwrap()

ledger/src/blockstore_processor.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,9 @@ pub enum BlockstoreProcessorError {
859859
#[error("failed to load meta")]
860860
FailedToLoadMeta,
861861

862+
#[error("failed to replay bank 0, did you forget to provide a snapshot")]
863+
FailedToReplayBank0,
864+
862865
#[error("invalid block error: {0}")]
863866
InvalidBlock(#[from] BlockError),
864867

@@ -994,7 +997,7 @@ pub(crate) fn process_blockstore_for_bank_0(
994997
entry_notification_sender: Option<&EntryNotifierSender>,
995998
accounts_update_notifier: Option<AccountsUpdateNotifier>,
996999
exit: Arc<AtomicBool>,
997-
) -> Arc<RwLock<BankForks>> {
1000+
) -> result::Result<Arc<RwLock<BankForks>>, BlockstoreProcessorError> {
9981001
// Setup bank for slot 0
9991002
let bank0 = Bank::new_with_paths(
10001003
genesis_config,
@@ -1027,8 +1030,9 @@ pub(crate) fn process_blockstore_for_bank_0(
10271030
&VerifyRecyclers::default(),
10281031
block_meta_sender,
10291032
entry_notification_sender,
1030-
);
1031-
bank_forks
1033+
)?;
1034+
1035+
Ok(bank_forks)
10321036
}
10331037

10341038
/// Process blockstore from a known root bank
@@ -1818,7 +1822,7 @@ fn process_bank_0(
18181822
recyclers: &VerifyRecyclers,
18191823
block_meta_sender: Option<&BlockMetaSender>,
18201824
entry_notification_sender: Option<&EntryNotifierSender>,
1821-
) {
1825+
) -> result::Result<(), BlockstoreProcessorError> {
18221826
assert_eq!(bank0.slot(), 0);
18231827
let mut progress = ConfirmationProgress::new(bank0.last_blockhash());
18241828
confirm_full_slot(
@@ -1833,7 +1837,7 @@ fn process_bank_0(
18331837
None,
18341838
&mut ExecuteTimings::default(),
18351839
)
1836-
.expect("Failed to process bank 0 from ledger. Did you forget to provide a snapshot?");
1840+
.map_err(|_| BlockstoreProcessorError::FailedToReplayBank0)?;
18371841
if let Some((result, _timings)) = bank0.wait_for_completed_scheduler() {
18381842
result.unwrap();
18391843
}
@@ -1842,6 +1846,8 @@ fn process_bank_0(
18421846
blockstore.insert_bank_hash(bank0.slot(), bank0.hash(), false);
18431847
}
18441848
send_block_meta(bank0, block_meta_sender);
1849+
1850+
Ok(())
18451851
}
18461852

18471853
// Given a bank, add its children to the pending slots queue if those children slots are
@@ -4201,7 +4207,8 @@ pub mod tests {
42014207
&recyclers,
42024208
None,
42034209
None,
4204-
);
4210+
)
4211+
.unwrap();
42054212
let bank0_last_blockhash = bank0.last_blockhash();
42064213
let bank1 = bank_forks.write().unwrap().insert(Bank::new_from_parent(
42074214
bank0.clone_without_scheduler(),

0 commit comments

Comments
 (0)