Skip to content

Commit

Permalink
revert niche lps change
Browse files Browse the repository at this point in the history
  • Loading branch information
2501babe committed Sep 6, 2024
1 parent 642ca9c commit 4131482
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions runtime/src/bank/check_transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl Bank {
let last_blockhash = hash_queue.last_hash();
let next_durable_nonce = DurableNonce::from_blockhash(&last_blockhash);
// safe so long as the BlockhashQueue is consistent
let lamports_per_signature = hash_queue
let next_lamports_per_signature = hash_queue
.get_lamports_per_signature(&last_blockhash)
.unwrap();

Expand All @@ -93,7 +93,7 @@ impl Bank {
max_age,
&next_durable_nonce,
&hash_queue,
lamports_per_signature,
next_lamports_per_signature,
error_counters,
),
Err(e) => Err(e.clone()),
Expand All @@ -107,7 +107,7 @@ impl Bank {
max_age: usize,
next_durable_nonce: &DurableNonce,
hash_queue: &BlockhashQueue,
lamports_per_signature: u64,
next_lamports_per_signature: u64,
error_counters: &mut TransactionErrorMetrics,
) -> TransactionCheckResult {
let recent_blockhash = tx.message().recent_blockhash();
Expand All @@ -116,14 +116,16 @@ impl Bank {
nonce: None,
lamports_per_signature: hash_info.lamports_per_signature(),
})
} else if let Some(nonce) = self.check_load_and_advance_message_nonce_account(
tx.message(),
next_durable_nonce,
lamports_per_signature,
) {
} else if let Some((nonce, previous_lamports_per_signature)) = self
.check_load_and_advance_message_nonce_account(
tx.message(),
next_durable_nonce,
next_lamports_per_signature,
)
{
Ok(CheckedTransactionDetails {
nonce: Some(nonce),
lamports_per_signature,
lamports_per_signature: previous_lamports_per_signature,
})
} else {
error_counters.blockhash_not_found += 1;
Expand All @@ -135,8 +137,8 @@ impl Bank {
&self,
message: &SanitizedMessage,
next_durable_nonce: &DurableNonce,
lamports_per_signature: u64,
) -> Option<NonceInfo> {
next_lamports_per_signature: u64,
) -> Option<(NonceInfo, u64)> {
let nonce_is_advanceable = message.recent_blockhash() != next_durable_nonce.as_hash();
if !nonce_is_advanceable {
return None;
Expand All @@ -145,16 +147,20 @@ impl Bank {
let (nonce_address, mut nonce_account, nonce_data) =
self.load_message_nonce_account(message)?;

let previous_lamports_per_signature = nonce_data.get_lamports_per_signature();
let next_nonce_state = NonceState::new_initialized(
&nonce_data.authority,
*next_durable_nonce,
lamports_per_signature,
next_lamports_per_signature,
);
nonce_account
.set_state(&NonceVersions::new(next_nonce_state))
.ok()?;

Some(NonceInfo::new(nonce_address, nonce_account))
Some((
NonceInfo::new(nonce_address, nonce_account),
previous_lamports_per_signature,
))
}

pub(super) fn load_message_nonce_account(
Expand Down Expand Up @@ -229,6 +235,7 @@ mod tests {

#[test]
fn test_check_and_load_message_nonce_account_ok() {
const STALE_LAMPORTS_PER_SIGNATURE: u64 = 42;
let (bank, _mint_keypair, custodian_keypair, nonce_keypair, _) = setup_nonce_with_bank(
10_000_000,
|_| {},
Expand All @@ -240,7 +247,6 @@ mod tests {
.unwrap();
let custodian_pubkey = custodian_keypair.pubkey();
let nonce_pubkey = nonce_keypair.pubkey();
let stale_lamports_per_signature = 42;

let nonce_hash = get_nonce_blockhash(&bank, &nonce_pubkey).unwrap();
let message = new_sanitized_message(Message::new_with_blockhash(
Expand All @@ -259,28 +265,29 @@ mod tests {
.set_state(&NonceVersions::new(NonceState::new_initialized(
&nonce_data.authority,
nonce_data.durable_nonce,
stale_lamports_per_signature,
STALE_LAMPORTS_PER_SIGNATURE,
)))
.unwrap();
bank.store_account(&nonce_pubkey, &nonce_account);

let nonce_account = bank.get_account(&nonce_pubkey).unwrap();
let (_, lamports_per_signature) = bank.last_blockhash_and_lamports_per_signature();
let (_, next_lamports_per_signature) = bank.last_blockhash_and_lamports_per_signature();
let mut expected_nonce_info = NonceInfo::new(nonce_pubkey, nonce_account);
expected_nonce_info
.try_advance_nonce(bank.next_durable_nonce(), lamports_per_signature)
.try_advance_nonce(bank.next_durable_nonce(), next_lamports_per_signature)
.unwrap();

// we now expect to:
// * advance the nonce to the current value
// * advance the nonce account to the current durable nonce value
// * set the blockhash queue's last blockhash's lamports_per_signature value in the nonce data
// * retrieve the previous lamports_per_signature value set on the nonce data for transaction fee checks
assert_eq!(
bank.check_load_and_advance_message_nonce_account(
&message,
&bank.next_durable_nonce(),
lamports_per_signature
next_lamports_per_signature
),
Some(expected_nonce_info),
Some((expected_nonce_info, STALE_LAMPORTS_PER_SIGNATURE)),
);
}

Expand Down

0 comments on commit 4131482

Please sign in to comment.