Skip to content

Commit

Permalink
Refactor Bank EAH fetch methods
Browse files Browse the repository at this point in the history
Shift the logic for checking if the hash should be fetched for this Bank
(slot) inside the fetch methods
  • Loading branch information
steviez committed Aug 7, 2024
1 parent f1de5c0 commit 55a9cae
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5199,11 +5199,10 @@ impl Bank {
self.last_blockhash().as_ref(),
]);

let epoch_accounts_hash = self.should_include_epoch_accounts_hash().then(|| {
let epoch_accounts_hash = self.wait_get_epoch_accounts_hash();
let epoch_accounts_hash = self.wait_get_epoch_accounts_hash();
if let Some(epoch_accounts_hash) = epoch_accounts_hash {
hash = hashv(&[hash.as_ref(), epoch_accounts_hash.as_ref().as_ref()]);
epoch_accounts_hash
});
};

let buf = self
.hard_forks
Expand Down Expand Up @@ -5248,9 +5247,13 @@ impl Bank {
self.parent_slot() < stop_slot && self.slot() >= stop_slot
}

/// If the epoch accounts hash should be included in this Bank, then fetch it. If the EAH
/// If the epoch accounts hash should be included in this Bank, then fetch it. If the EAH
/// calculation has not completed yet, this fn will block until it does complete.
fn wait_get_epoch_accounts_hash(&self) -> EpochAccountsHash {
fn wait_get_epoch_accounts_hash(&self) -> Option<EpochAccountsHash> {
if !self.should_include_epoch_accounts_hash() {
return None;
}

let (epoch_accounts_hash, waiting_time_us) = measure_us!(self
.rc
.accounts
Expand All @@ -5263,7 +5266,7 @@ impl Bank {
("slot", self.slot(), i64),
("waiting-time-us", waiting_time_us, i64),
);
epoch_accounts_hash
Some(epoch_accounts_hash)
}

/// Used by ledger tool to run a final hash calculation once all ledger replay has completed.
Expand Down Expand Up @@ -6400,8 +6403,13 @@ impl Bank {
Some(epoch_accounts_hash)
}

/// Convenience fn to get the Epoch Accounts Hash
/// If the epoch accounts hash should be included in this Bank, then fetch it. If the EAH
/// calculation has not completed yet, this fn will return None immediately
pub fn epoch_accounts_hash(&self) -> Option<EpochAccountsHash> {
if !self.should_include_epoch_accounts_hash() {
return None;
}

self.rc
.accounts
.accounts_db
Expand Down

0 comments on commit 55a9cae

Please sign in to comment.