Use last_valid_block_height in services and client apps (#19163)
* Add deprecated tag to Bank::get_blockhash_last_valid_slot * Update SendTransactionService to use last_valid_block_height * Update solana-tokens to use last_valid_block_height * Remove dangling file * Update solana program to use last_valid_block_height * Update Banks crates to use last_valid_block_height
This commit is contained in:
@ -544,6 +544,7 @@ impl JsonRpcRequestProcessor {
|
||||
fn get_fees(&self, commitment: Option<CommitmentConfig>) -> RpcResponse<RpcFees> {
|
||||
let bank = self.bank(commitment);
|
||||
let (blockhash, fee_calculator) = bank.confirmed_last_blockhash();
|
||||
#[allow(deprecated)]
|
||||
let last_valid_slot = bank
|
||||
.get_blockhash_last_valid_slot(&blockhash)
|
||||
.expect("bank blockhash queue should contain blockhash");
|
||||
@ -2140,7 +2141,7 @@ fn _send_transaction(
|
||||
meta: JsonRpcRequestProcessor,
|
||||
transaction: Transaction,
|
||||
wire_transaction: Vec<u8>,
|
||||
last_valid_slot: Slot,
|
||||
last_valid_block_height: u64,
|
||||
durable_nonce_info: Option<(Pubkey, Hash)>,
|
||||
) -> Result<String> {
|
||||
if transaction.signatures.is_empty() {
|
||||
@ -2150,7 +2151,7 @@ fn _send_transaction(
|
||||
let transaction_info = TransactionInfo::new(
|
||||
signature,
|
||||
wire_transaction,
|
||||
last_valid_slot,
|
||||
last_valid_block_height,
|
||||
durable_nonce_info,
|
||||
);
|
||||
meta.transaction_sender
|
||||
@ -3233,7 +3234,9 @@ pub mod rpc_full {
|
||||
} else {
|
||||
bank.confirmed_last_blockhash().0
|
||||
};
|
||||
let last_valid_slot = bank.get_blockhash_last_valid_slot(&blockhash).unwrap_or(0);
|
||||
let last_valid_block_height = bank
|
||||
.get_blockhash_last_valid_block_height(&blockhash)
|
||||
.unwrap_or(0);
|
||||
|
||||
let transaction =
|
||||
request_airdrop_transaction(&faucet_addr, &pubkey, lamports, blockhash).map_err(
|
||||
@ -3248,7 +3251,13 @@ pub mod rpc_full {
|
||||
Error::internal_error()
|
||||
})?;
|
||||
|
||||
_send_transaction(meta, transaction, wire_transaction, last_valid_slot, None)
|
||||
_send_transaction(
|
||||
meta,
|
||||
transaction,
|
||||
wire_transaction,
|
||||
last_valid_block_height,
|
||||
None,
|
||||
)
|
||||
}
|
||||
|
||||
fn send_transaction(
|
||||
@ -3267,8 +3276,8 @@ pub mod rpc_full {
|
||||
.map(|commitment| CommitmentConfig { commitment });
|
||||
let preflight_bank = &*meta.bank(preflight_commitment);
|
||||
|
||||
let mut last_valid_slot = preflight_bank
|
||||
.get_blockhash_last_valid_slot(&transaction.message.recent_blockhash)
|
||||
let mut last_valid_block_height = preflight_bank
|
||||
.get_blockhash_last_valid_block_height(&transaction.message.recent_blockhash)
|
||||
.unwrap_or(0);
|
||||
|
||||
let durable_nonce_info = solana_sdk::transaction::uses_durable_nonce(&transaction)
|
||||
@ -3280,11 +3289,12 @@ pub mod rpc_full {
|
||||
})
|
||||
.map(|&pubkey| (pubkey, transaction.message.recent_blockhash));
|
||||
if durable_nonce_info.is_some() {
|
||||
// While it uses a defined constant, this last_valid_slot value is chosen arbitrarily.
|
||||
// While it uses a defined constant, this last_valid_block_height value is chosen arbitrarily.
|
||||
// It provides a fallback timeout for durable-nonce transaction retries in case of
|
||||
// malicious packing of the retry queue. Durable-nonce transactions are otherwise
|
||||
// retried until the nonce is advanced.
|
||||
last_valid_slot = preflight_bank.slot() + MAX_RECENT_BLOCKHASHES as u64;
|
||||
last_valid_block_height =
|
||||
preflight_bank.block_height() + MAX_RECENT_BLOCKHASHES as u64;
|
||||
}
|
||||
|
||||
if !config.skip_preflight {
|
||||
@ -3345,7 +3355,7 @@ pub mod rpc_full {
|
||||
meta,
|
||||
transaction,
|
||||
wire_transaction,
|
||||
last_valid_slot,
|
||||
last_valid_block_height,
|
||||
durable_nonce_info,
|
||||
)
|
||||
}
|
||||
|
@ -6,10 +6,7 @@ use {
|
||||
solana_poh::poh_recorder::PohRecorder,
|
||||
solana_runtime::{bank::Bank, bank_forks::BankForks},
|
||||
solana_sdk::{
|
||||
clock::{Slot, NUM_CONSECUTIVE_LEADER_SLOTS},
|
||||
hash::Hash,
|
||||
nonce_account,
|
||||
pubkey::Pubkey,
|
||||
clock::NUM_CONSECUTIVE_LEADER_SLOTS, hash::Hash, nonce_account, pubkey::Pubkey,
|
||||
signature::Signature,
|
||||
},
|
||||
std::{
|
||||
@ -34,7 +31,7 @@ pub struct SendTransactionService {
|
||||
pub struct TransactionInfo {
|
||||
pub signature: Signature,
|
||||
pub wire_transaction: Vec<u8>,
|
||||
pub last_valid_slot: Slot,
|
||||
pub last_valid_block_height: u64,
|
||||
pub durable_nonce_info: Option<(Pubkey, Hash)>,
|
||||
}
|
||||
|
||||
@ -42,13 +39,13 @@ impl TransactionInfo {
|
||||
pub fn new(
|
||||
signature: Signature,
|
||||
wire_transaction: Vec<u8>,
|
||||
last_valid_slot: Slot,
|
||||
last_valid_block_height: u64,
|
||||
durable_nonce_info: Option<(Pubkey, Hash)>,
|
||||
) -> Self {
|
||||
Self {
|
||||
signature,
|
||||
wire_transaction,
|
||||
last_valid_slot,
|
||||
last_valid_block_height,
|
||||
durable_nonce_info,
|
||||
}
|
||||
}
|
||||
@ -244,7 +241,7 @@ impl SendTransactionService {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if transaction_info.last_valid_slot < root_bank.slot() {
|
||||
if transaction_info.last_valid_block_height < root_bank.block_height() {
|
||||
info!("Dropping expired transaction: {}", signature);
|
||||
result.expired += 1;
|
||||
inc_new_counter_info!("send_transaction_service-expired", 1);
|
||||
@ -391,7 +388,12 @@ mod test {
|
||||
info!("Expired transactions are dropped...");
|
||||
transactions.insert(
|
||||
Signature::default(),
|
||||
TransactionInfo::new(Signature::default(), vec![], root_bank.slot() - 1, None),
|
||||
TransactionInfo::new(
|
||||
Signature::default(),
|
||||
vec![],
|
||||
root_bank.block_height() - 1,
|
||||
None,
|
||||
),
|
||||
);
|
||||
let result = SendTransactionService::process_transactions(
|
||||
&working_bank,
|
||||
@ -414,7 +416,7 @@ mod test {
|
||||
info!("Rooted transactions are dropped...");
|
||||
transactions.insert(
|
||||
rooted_signature,
|
||||
TransactionInfo::new(rooted_signature, vec![], working_bank.slot(), None),
|
||||
TransactionInfo::new(rooted_signature, vec![], working_bank.block_height(), None),
|
||||
);
|
||||
let result = SendTransactionService::process_transactions(
|
||||
&working_bank,
|
||||
@ -437,7 +439,7 @@ mod test {
|
||||
info!("Failed transactions are dropped...");
|
||||
transactions.insert(
|
||||
failed_signature,
|
||||
TransactionInfo::new(failed_signature, vec![], working_bank.slot(), None),
|
||||
TransactionInfo::new(failed_signature, vec![], working_bank.block_height(), None),
|
||||
);
|
||||
let result = SendTransactionService::process_transactions(
|
||||
&working_bank,
|
||||
@ -460,7 +462,12 @@ mod test {
|
||||
info!("Non-rooted transactions are kept...");
|
||||
transactions.insert(
|
||||
non_rooted_signature,
|
||||
TransactionInfo::new(non_rooted_signature, vec![], working_bank.slot(), None),
|
||||
TransactionInfo::new(
|
||||
non_rooted_signature,
|
||||
vec![],
|
||||
working_bank.block_height(),
|
||||
None,
|
||||
),
|
||||
);
|
||||
let result = SendTransactionService::process_transactions(
|
||||
&working_bank,
|
||||
@ -484,7 +491,12 @@ mod test {
|
||||
info!("Unknown transactions are retried...");
|
||||
transactions.insert(
|
||||
Signature::default(),
|
||||
TransactionInfo::new(Signature::default(), vec![], working_bank.slot(), None),
|
||||
TransactionInfo::new(
|
||||
Signature::default(),
|
||||
vec![],
|
||||
working_bank.block_height(),
|
||||
None,
|
||||
),
|
||||
);
|
||||
let result = SendTransactionService::process_transactions(
|
||||
&working_bank,
|
||||
@ -542,7 +554,7 @@ mod test {
|
||||
.transfer(2, &mint_keypair, &mint_keypair.pubkey())
|
||||
.unwrap();
|
||||
|
||||
let last_valid_slot = working_bank.slot() + 300;
|
||||
let last_valid_block_height = working_bank.block_height() + 300;
|
||||
|
||||
let failed_signature = {
|
||||
let blockhash = working_bank.last_blockhash();
|
||||
@ -561,7 +573,7 @@ mod test {
|
||||
TransactionInfo::new(
|
||||
rooted_signature,
|
||||
vec![],
|
||||
last_valid_slot,
|
||||
last_valid_block_height,
|
||||
Some((nonce_address, durable_nonce)),
|
||||
),
|
||||
);
|
||||
@ -588,7 +600,7 @@ mod test {
|
||||
TransactionInfo::new(
|
||||
rooted_signature,
|
||||
vec![],
|
||||
last_valid_slot,
|
||||
last_valid_block_height,
|
||||
Some((nonce_address, Hash::new_unique())),
|
||||
),
|
||||
);
|
||||
@ -617,7 +629,7 @@ mod test {
|
||||
TransactionInfo::new(
|
||||
Signature::default(),
|
||||
vec![],
|
||||
last_valid_slot,
|
||||
last_valid_block_height,
|
||||
Some((nonce_address, Hash::new_unique())),
|
||||
),
|
||||
);
|
||||
@ -638,13 +650,13 @@ mod test {
|
||||
..ProcessTransactionsResult::default()
|
||||
}
|
||||
);
|
||||
// ... or last_valid_slot timeout has passed
|
||||
// ... or last_valid_block_height timeout has passed
|
||||
transactions.insert(
|
||||
Signature::default(),
|
||||
TransactionInfo::new(
|
||||
Signature::default(),
|
||||
vec![],
|
||||
root_bank.slot() - 1,
|
||||
root_bank.block_height() - 1,
|
||||
Some((nonce_address, durable_nonce)),
|
||||
),
|
||||
);
|
||||
@ -672,7 +684,7 @@ mod test {
|
||||
TransactionInfo::new(
|
||||
failed_signature,
|
||||
vec![],
|
||||
last_valid_slot,
|
||||
last_valid_block_height,
|
||||
Some((nonce_address, Hash::new_unique())), // runtime should advance nonce on failed transactions
|
||||
),
|
||||
);
|
||||
@ -700,7 +712,7 @@ mod test {
|
||||
TransactionInfo::new(
|
||||
non_rooted_signature,
|
||||
vec![],
|
||||
last_valid_slot,
|
||||
last_valid_block_height,
|
||||
Some((nonce_address, Hash::new_unique())), // runtime advances nonce when transaction lands
|
||||
),
|
||||
);
|
||||
@ -729,7 +741,7 @@ mod test {
|
||||
TransactionInfo::new(
|
||||
Signature::default(),
|
||||
vec![],
|
||||
last_valid_slot,
|
||||
last_valid_block_height,
|
||||
Some((nonce_address, durable_nonce)),
|
||||
),
|
||||
);
|
||||
|
Reference in New Issue
Block a user