Skip to content

Commit

Permalink
Refactor Bank EAH fetch method (solana-labs#2477)
Browse files Browse the repository at this point in the history
Shift the check for whether *this* bank should include the EAH inside
the fetch function; will avoid code duplication later
  • Loading branch information
steviez authored Aug 19, 2024
1 parent 8f675eb commit 7ae496a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5215,11 +5215,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 @@ -5264,9 +5263,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 @@ -5279,7 +5282,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

0 comments on commit 7ae496a

Please sign in to comment.