Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion core/src/replay_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1498,7 +1498,9 @@ impl ReplayStage {
) -> Result<Tower, TowerError> {
let tower = Tower::restore(tower_storage, node_pubkey).and_then(|restored_tower| {
let root_bank = bank_forks.read().unwrap().root_bank();
let slot_history = root_bank.get_slot_history();
let slot_history = root_bank
.get_slot_history()
.expect("slot history must exist");
restored_tower.adjust_lockouts_after_replay(root_bank.slot(), &slot_history)
});
match tower {
Expand Down
4 changes: 3 additions & 1 deletion core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2084,7 +2084,9 @@ fn post_process_restored_tower(

let restored_tower = restored_tower.and_then(|tower| {
let root_bank = bank_forks.root_bank();
let slot_history = root_bank.get_slot_history();
let slot_history = root_bank
.get_slot_history()
.expect("slot history must exist");
// make sure tower isn't corrupted first before the following hard fork check
let tower = tower.adjust_lockouts_after_replay(root_bank.slot(), &slot_history);

Expand Down
8 changes: 8 additions & 0 deletions rpc-client-api/src/custom_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub const JSON_RPC_SERVER_ERROR_EPOCH_REWARDS_PERIOD_ACTIVE: i64 = -32017;
pub const JSON_RPC_SERVER_ERROR_SLOT_NOT_EPOCH_BOUNDARY: i64 = -32018;
pub const JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_UNREACHABLE: i64 = -32019;
pub const JSON_RPC_SERVER_ERROR_FILTER_TRANSACTION_NOT_FOUND: i64 = -32020;
pub const JSON_RPC_SERVER_ERROR_NO_SLOT_HISTORY: i64 = -32021;

#[derive(Error, Debug)]
#[allow(clippy::large_enum_variant)]
Expand Down Expand Up @@ -83,6 +84,8 @@ pub enum RpcCustomError {
LongTermStorageUnreachable,
#[error("FilterTransactionNotFound")]
FilterTransactionNotFound { signature: String },
#[error("NoSlotHistory")]
NoSlotHistory,
}

#[derive(Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -267,6 +270,11 @@ impl From<RpcCustomError> for Error {
message: format!("Transaction {signature} not found"),
data: None,
},
RpcCustomError::NoSlotHistory => Self {
code: ErrorCode::ServerError(JSON_RPC_SERVER_ERROR_NO_SLOT_HISTORY),
message: "No slot history".to_string(),
data: None,
},
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3121,7 +3121,9 @@ pub mod rpc_bank {
}
};

let slot_history = bank.get_slot_history();
let Some(slot_history) = bank.get_slot_history() else {
return Err(RpcCustomError::NoSlotHistory.into());
};
if first_slot < slot_history.oldest() {
return Err(Error::invalid_params(format!(
"firstSlot, {}, is too small; min {}",
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2326,8 +2326,8 @@ impl Bank {
});
}

pub fn get_slot_history(&self) -> SlotHistory {
from_account(&self.get_account(&sysvar::slot_history::id()).unwrap()).unwrap()
pub fn get_slot_history(&self) -> Option<SlotHistory> {
from_account(&self.get_account(&sysvar::slot_history::id())?)
}

fn update_epoch_stakes(&mut self, leader_schedule_epoch: Epoch) {
Expand Down
5 changes: 4 additions & 1 deletion runtime/src/snapshot_bank_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,10 @@ fn verify_slot_deltas(
bank: &Bank,
) -> std::result::Result<(), VerifySlotDeltasError> {
let info = verify_slot_deltas_structural(slot_deltas, bank.slot())?;
verify_slot_deltas_with_history(&info.slots, &bank.get_slot_history(), bank.slot())
let slot_history = bank
.get_slot_history()
.expect("snapshot bank must have slot history");
verify_slot_deltas_with_history(&info.slots, &slot_history, bank.slot())
}

/// Verify that the snapshot's slot deltas are not corrupt/invalid
Expand Down
Loading