diff --git a/banks-client/src/lib.rs b/banks-client/src/lib.rs index ac380a36df..46ac029817 100644 --- a/banks-client/src/lib.rs +++ b/banks-client/src/lib.rs @@ -62,7 +62,7 @@ impl BanksClient { &mut self, ctx: Context, commitment: CommitmentLevel, - ) -> impl Future> + '_ { + ) -> impl Future> + '_ { self.inner .get_fees_with_commitment_and_context(ctx, commitment) } @@ -84,6 +84,14 @@ impl BanksClient { self.inner.get_slot_with_context(ctx, commitment) } + pub fn get_block_height_with_context( + &mut self, + ctx: Context, + commitment: CommitmentLevel, + ) -> impl Future> + '_ { + self.inner.get_block_height_with_context(ctx, commitment) + } + pub fn process_transaction_with_commitment_and_context( &mut self, ctx: Context, @@ -119,7 +127,7 @@ impl BanksClient { /// use them to calculate the transaction fee. pub fn get_fees( &mut self, - ) -> impl Future> + '_ { + ) -> impl Future> + '_ { self.get_fees_with_commitment_and_context(context::current(), CommitmentLevel::default()) } @@ -195,12 +203,18 @@ impl BanksClient { self.process_transactions_with_commitment(transactions, CommitmentLevel::default()) } - /// Return the most recent rooted slot height. All transactions at or below this height - /// are said to be finalized. The cluster will not fork to a higher slot height. + /// Return the most recent rooted slot. All transactions at or below this slot + /// are said to be finalized. The cluster will not fork to a higher slot. pub fn get_root_slot(&mut self) -> impl Future> + '_ { self.get_slot_with_context(context::current(), CommitmentLevel::default()) } + /// Return the most recent rooted block height. All transactions at or below this height + /// are said to be finalized. The cluster will not fork to a higher block height. + pub fn get_root_block_height(&mut self) -> impl Future> + '_ { + self.get_block_height_with_context(context::current(), CommitmentLevel::default()) + } + /// Return the account at the given address at the slot corresponding to the given /// commitment level. If the account is not found, None is returned. pub fn get_account_with_commitment( @@ -386,7 +400,7 @@ mod tests { Runtime::new()?.block_on(async { let client_transport = start_local_server(bank_forks, block_commitment_cache).await; let mut banks_client = start_client(client_transport).await?; - let (_, recent_blockhash, last_valid_slot) = banks_client.get_fees().await?; + let (_, recent_blockhash, last_valid_block_height) = banks_client.get_fees().await?; let transaction = Transaction::new(&[&genesis.mint_keypair], message, recent_blockhash); let signature = transaction.signatures[0]; banks_client.send_transaction(transaction).await?; @@ -394,8 +408,8 @@ mod tests { let mut status = banks_client.get_transaction_status(signature).await?; while status.is_none() { - let root_slot = banks_client.get_root_slot().await?; - if root_slot > last_valid_slot { + let root_block_height = banks_client.get_root_block_height().await?; + if root_block_height > last_valid_block_height { break; } sleep(Duration::from_millis(100)).await; diff --git a/banks-interface/src/lib.rs b/banks-interface/src/lib.rs index 5c03e97382..0ee4fddabb 100644 --- a/banks-interface/src/lib.rs +++ b/banks-interface/src/lib.rs @@ -34,6 +34,7 @@ pub trait Banks { async fn get_transaction_status_with_context(signature: Signature) -> Option; async fn get_slot_with_context(commitment: CommitmentLevel) -> Slot; + async fn get_block_height_with_context(commitment: CommitmentLevel) -> u64; async fn process_transaction_with_commitment_and_context( transaction: Transaction, commitment: CommitmentLevel, diff --git a/banks-server/src/banks_server.rs b/banks-server/src/banks_server.rs index c2af1470b9..368eeafe6a 100644 --- a/banks-server/src/banks_server.rs +++ b/banks-server/src/banks_server.rs @@ -110,7 +110,7 @@ impl BanksServer { self, signature: &Signature, blockhash: &Hash, - last_valid_slot: Slot, + last_valid_block_height: u64, commitment: CommitmentLevel, ) -> Option> { let mut status = self @@ -119,7 +119,7 @@ impl BanksServer { while status.is_none() { sleep(Duration::from_millis(200)).await; let bank = self.bank(commitment); - if bank.slot() > last_valid_slot { + if bank.block_height() > last_valid_block_height { break; } status = bank.get_signature_status_with_blockhash(signature, blockhash); @@ -145,16 +145,19 @@ fn verify_transaction( impl Banks for BanksServer { async fn send_transaction_with_context(self, _: Context, transaction: Transaction) { let blockhash = &transaction.message.recent_blockhash; - let last_valid_slot = self + let last_valid_block_height = self .bank_forks .read() .unwrap() .root_bank() - .get_blockhash_last_valid_slot(blockhash) + .get_blockhash_last_valid_block_height(blockhash) .unwrap(); let signature = transaction.signatures.get(0).cloned().unwrap_or_default(); - let info = - TransactionInfo::new(signature, serialize(&transaction).unwrap(), last_valid_slot); + let info = TransactionInfo::new( + signature, + serialize(&transaction).unwrap(), + last_valid_block_height, + ); self.transaction_sender.send(info).unwrap(); } @@ -162,11 +165,13 @@ impl Banks for BanksServer { self, _: Context, commitment: CommitmentLevel, - ) -> (FeeCalculator, Hash, Slot) { + ) -> (FeeCalculator, Hash, u64) { let bank = self.bank(commitment); let (blockhash, fee_calculator) = bank.last_blockhash_with_fee_calculator(); - let last_valid_slot = bank.get_blockhash_last_valid_slot(&blockhash).unwrap(); - (fee_calculator, blockhash, last_valid_slot) + let last_valid_block_height = bank + .get_blockhash_last_valid_block_height(&blockhash) + .unwrap(); + (fee_calculator, blockhash, last_valid_block_height) } async fn get_transaction_status_with_context( @@ -209,6 +214,10 @@ impl Banks for BanksServer { self.slot(commitment) } + async fn get_block_height_with_context(self, _: Context, commitment: CommitmentLevel) -> u64 { + self.bank(commitment).block_height() + } + async fn process_transaction_with_commitment_and_context( self, _: Context, @@ -223,18 +232,21 @@ impl Banks for BanksServer { } let blockhash = &transaction.message.recent_blockhash; - let last_valid_slot = self + let last_valid_block_height = self .bank_forks .read() .unwrap() .root_bank() - .get_blockhash_last_valid_slot(blockhash) + .get_blockhash_last_valid_block_height(blockhash) .unwrap(); let signature = transaction.signatures.get(0).cloned().unwrap_or_default(); - let info = - TransactionInfo::new(signature, serialize(&transaction).unwrap(), last_valid_slot); + let info = TransactionInfo::new( + signature, + serialize(&transaction).unwrap(), + last_valid_block_height, + ); self.transaction_sender.send(info).unwrap(); - self.poll_signature_status(&signature, blockhash, last_valid_slot, commitment) + self.poll_signature_status(&signature, blockhash, last_valid_block_height, commitment) .await } diff --git a/banks-server/src/send_transaction_service.rs b/banks-server/src/send_transaction_service.rs index f062a55656..d65e2e6752 100644 --- a/banks-server/src/send_transaction_service.rs +++ b/banks-server/src/send_transaction_service.rs @@ -2,7 +2,7 @@ use log::*; use solana_metrics::{datapoint_warn, inc_new_counter_info}; use solana_runtime::{bank::Bank, bank_forks::BankForks}; -use solana_sdk::{clock::Slot, signature::Signature}; +use solana_sdk::signature::Signature; use std::{ collections::HashMap, net::{SocketAddr, UdpSocket}, @@ -24,15 +24,19 @@ pub struct SendTransactionService { pub struct TransactionInfo { pub signature: Signature, pub wire_transaction: Vec, - pub last_valid_slot: Slot, + pub last_valid_block_height: u64, } impl TransactionInfo { - pub fn new(signature: Signature, wire_transaction: Vec, last_valid_slot: Slot) -> Self { + pub fn new( + signature: Signature, + wire_transaction: Vec, + last_valid_block_height: u64, + ) -> Self { Self { signature, wire_transaction, - last_valid_slot, + last_valid_block_height, } } } @@ -124,7 +128,7 @@ impl SendTransactionService { result.rooted += 1; inc_new_counter_info!("send_transaction_service-rooted", 1); false - } else if transaction_info.last_valid_slot < root_bank.slot() { + } else 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); diff --git a/cli/src/program.rs b/cli/src/program.rs index aa36361615..d467c0b4c8 100644 --- a/cli/src/program.rs +++ b/cli/src/program.rs @@ -23,6 +23,7 @@ use solana_client::{ rpc_config::{RpcAccountInfoConfig, RpcProgramAccountsConfig}, rpc_filter::{Memcmp, MemcmpEncodedBytes, RpcFilterType}, rpc_request::MAX_GET_SIGNATURE_STATUSES_QUERY_ITEMS, + rpc_response::Fees, tpu_client::{TpuClient, TpuClientConfig}, }; use solana_rbpf::{ @@ -35,7 +36,6 @@ use solana_sdk::{ account_utils::StateMut, bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable::{self, UpgradeableLoaderState}, - clock::Slot, commitment_config::CommitmentConfig, instruction::Instruction, instruction::InstructionError, @@ -1943,8 +1943,12 @@ fn send_deploy_messages( if let Some(write_messages) = write_messages { if let Some(write_signer) = write_signer { trace!("Writing program data"); - let (blockhash, _, last_valid_slot) = rpc_client - .get_recent_blockhash_with_commitment(config.commitment)? + let Fees { + blockhash, + last_valid_block_height, + .. + } = rpc_client + .get_fees_with_commitment(config.commitment)? .value; let mut write_transactions = vec![]; for message in write_messages.iter() { @@ -1959,7 +1963,7 @@ fn send_deploy_messages( write_transactions, &[payer_signer, write_signer], config.commitment, - last_valid_slot, + last_valid_block_height, ) .map_err(|err| format!("Data writes to account failed: {}", err))?; } @@ -2029,7 +2033,7 @@ fn send_and_confirm_transactions_with_spinner( mut transactions: Vec, signer_keys: &T, commitment: CommitmentConfig, - mut last_valid_slot: Slot, + mut last_valid_block_height: u64, ) -> Result<(), Box> { let progress_bar = new_spinner_progress_bar(); let mut send_retries = 5; @@ -2069,7 +2073,7 @@ fn send_and_confirm_transactions_with_spinner( // Collect statuses for all the transactions, drop those that are confirmed loop { - let mut slot = 0; + let mut block_height = 0; let pending_signatures = pending_transactions.keys().cloned().collect::>(); for pending_signatures_chunk in pending_signatures.chunks(MAX_GET_SIGNATURE_STATUSES_QUERY_ITEMS) @@ -2094,12 +2098,12 @@ fn send_and_confirm_transactions_with_spinner( } } - slot = rpc_client.get_slot()?; + block_height = rpc_client.get_block_height()?; progress_bar.set_message(format!( - "[{}/{}] Transactions confirmed. Retrying in {} slots", + "[{}/{}] Transactions confirmed. Retrying in {} blocks", num_transactions - pending_transactions.len(), num_transactions, - last_valid_slot.saturating_sub(slot) + last_valid_block_height.saturating_sub(block_height) )); } @@ -2107,7 +2111,7 @@ fn send_and_confirm_transactions_with_spinner( return Ok(()); } - if slot > last_valid_slot { + if block_height > last_valid_block_height { break; } @@ -2137,10 +2141,12 @@ fn send_and_confirm_transactions_with_spinner( send_retries -= 1; // Re-sign any failed transactions with a new blockhash and retry - let (blockhash, _fee_calculator, new_last_valid_slot) = rpc_client - .get_recent_blockhash_with_commitment(commitment)? - .value; - last_valid_slot = new_last_valid_slot; + let Fees { + blockhash, + last_valid_block_height: new_last_valid_block_height, + .. + } = rpc_client.get_fees_with_commitment(commitment)?.value; + last_valid_block_height = new_last_valid_block_height; transactions = vec![]; for (_, mut transaction) in pending_transactions.into_iter() { transaction.try_sign(signer_keys, blockhash)?; diff --git a/client/src/blockhash_query.rs b/client/src/blockhash_query.rs index ced886b04b..78dd26e391 100644 --- a/client/src/blockhash_query.rs +++ b/client/src/blockhash_query.rs @@ -122,10 +122,10 @@ mod tests { use crate::{ blockhash_query, rpc_request::RpcRequest, - rpc_response::{Response, RpcFeeCalculator, RpcResponseContext}, + rpc_response::{Response, RpcFeeCalculator, RpcFees, RpcResponseContext}, }; use clap::App; - use serde_json::{self, json, Value}; + use serde_json::{self, json}; use solana_account_decoder::{UiAccount, UiAccountEncoding}; use solana_sdk::{account::Account, hash::hash, nonce, system_program}; use std::collections::HashMap; @@ -288,10 +288,12 @@ mod tests { let rpc_fee_calc = FeeCalculator::new(42); let get_recent_blockhash_response = json!(Response { context: RpcResponseContext { slot: 1 }, - value: json!(( - Value::String(rpc_blockhash.to_string()), - serde_json::to_value(rpc_fee_calc.clone()).unwrap() - )), + value: json!(RpcFees { + blockhash: rpc_blockhash.to_string(), + fee_calculator: rpc_fee_calc.clone(), + last_valid_slot: 42, + last_valid_block_height: 42, + }), }); let get_fee_calculator_for_blockhash_response = json!(Response { context: RpcResponseContext { slot: 1 }, @@ -300,10 +302,7 @@ mod tests { }), }); let mut mocks = HashMap::new(); - mocks.insert( - RpcRequest::GetRecentBlockhash, - get_recent_blockhash_response.clone(), - ); + mocks.insert(RpcRequest::GetFees, get_recent_blockhash_response.clone()); let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks); assert_eq!( BlockhashQuery::default() @@ -312,10 +311,7 @@ mod tests { (rpc_blockhash, rpc_fee_calc.clone()), ); let mut mocks = HashMap::new(); - mocks.insert( - RpcRequest::GetRecentBlockhash, - get_recent_blockhash_response.clone(), - ); + mocks.insert(RpcRequest::GetFees, get_recent_blockhash_response.clone()); mocks.insert( RpcRequest::GetFeeCalculatorForBlockhash, get_fee_calculator_for_blockhash_response, @@ -328,10 +324,7 @@ mod tests { (test_blockhash, rpc_fee_calc), ); let mut mocks = HashMap::new(); - mocks.insert( - RpcRequest::GetRecentBlockhash, - get_recent_blockhash_response, - ); + mocks.insert(RpcRequest::GetFees, get_recent_blockhash_response); let rpc_client = RpcClient::new_mock_with_mocks("".to_string(), mocks); assert_eq!( BlockhashQuery::None(test_blockhash) diff --git a/client/src/fees.rs b/client/src/fees.rs deleted file mode 100644 index f73545b01e..0000000000 --- a/client/src/fees.rs +++ /dev/null @@ -1,9 +0,0 @@ -use crate::{fee_calculator::FeeCalculator, hash::Hash}; - -#[derive(Serialize, Deserialize, Clone, Debug)] -#[serde(rename_all = "camelCase")] -pub struct Fees { - pub blockhash: Hash, - pub fee_calculator: FeeCalculator, - pub last_valid_block_height: u64, -} diff --git a/client/src/mock_sender.rs b/client/src/mock_sender.rs index 1426af020a..3cd31623af 100644 --- a/client/src/mock_sender.rs +++ b/client/src/mock_sender.rs @@ -6,7 +6,7 @@ use { rpc_config::RpcBlockProductionConfig, rpc_request::RpcRequest, rpc_response::{ - Response, RpcAccountBalance, RpcBlockProduction, RpcBlockProductionRange, + Response, RpcAccountBalance, RpcBlockProduction, RpcBlockProductionRange, RpcFees, RpcResponseContext, RpcSimulateTransactionResult, RpcStakeActivation, RpcSupply, RpcVersionInfo, RpcVoteAccountStatus, StakeActivationState, }, @@ -123,6 +123,16 @@ impl RpcSender for MockSender { context: RpcResponseContext { slot: 1 }, value: serde_json::to_value(FeeRateGovernor::default()).unwrap(), })?, + "getFees" => serde_json::to_value(Response { + context: RpcResponseContext { slot: 1 }, + value: serde_json::to_value(RpcFees { + blockhash: PUBKEY.to_string(), + fee_calculator: FeeCalculator::default(), + last_valid_slot: 42, + last_valid_block_height: 42, + }) + .unwrap(), + })?, "getSignatureStatuses" => { let status: transaction::Result<()> = if self.url == "account_in_use" { Err(TransactionError::AccountInUse) diff --git a/rpc/src/rpc.rs b/rpc/src/rpc.rs index af30684d80..db3fa10689 100644 --- a/rpc/src/rpc.rs +++ b/rpc/src/rpc.rs @@ -544,6 +544,7 @@ impl JsonRpcRequestProcessor { fn get_fees(&self, commitment: Option) -> RpcResponse { 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, - last_valid_slot: Slot, + last_valid_block_height: u64, durable_nonce_info: Option<(Pubkey, Hash)>, ) -> Result { 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, ) } diff --git a/rpc/src/send_transaction_service.rs b/rpc/src/send_transaction_service.rs index a9172811b3..9b06c644e0 100644 --- a/rpc/src/send_transaction_service.rs +++ b/rpc/src/send_transaction_service.rs @@ -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, - 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, - 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)), ), ); diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index cc4615ab3b..185ddbdd2a 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -2692,7 +2692,10 @@ impl Bank { &self.fee_rate_governor } - // DEPRECATED + #[deprecated( + since = "1.6.11", + note = "Please use `get_blockhash_last_valid_block_height`" + )] pub fn get_blockhash_last_valid_slot(&self, blockhash: &Hash) -> Option { let blockhash_queue = self.blockhash_queue.read().unwrap(); // This calculation will need to be updated to consider epoch boundaries if BlockhashQueue diff --git a/runtime/src/bank_client.rs b/runtime/src/bank_client.rs index bb66f6568d..30b54c9b70 100644 --- a/runtime/src/bank_client.rs +++ b/runtime/src/bank_client.rs @@ -156,6 +156,7 @@ impl SyncClient for BankClient { _commitment_config: CommitmentConfig, ) -> Result<(Hash, FeeCalculator, u64)> { let (blockhash, fee_calculator) = self.bank.last_blockhash_with_fee_calculator(); + #[allow(deprecated)] let last_valid_slot = self .bank .get_blockhash_last_valid_slot(&blockhash) diff --git a/tokens/src/commands.rs b/tokens/src/commands.rs index 70d8a3f9c5..11abba3a9b 100644 --- a/tokens/src/commands.rs +++ b/tokens/src/commands.rs @@ -19,6 +19,7 @@ use solana_client::{ rpc_client::RpcClient, rpc_config::RpcSendTransactionConfig, rpc_request::MAX_GET_SIGNATURE_STATUSES_QUERY_ITEMS, + rpc_response::Fees, }; use solana_sdk::{ clock::Slot, @@ -386,8 +387,12 @@ fn send_messages( if args.dry_run { Ok((Transaction::new_unsigned(message), std::u64::MAX)) } else { - let (blockhash, _fee_calculator, last_valid_slot) = client - .get_recent_blockhash_with_commitment(CommitmentConfig::default())? + let Fees { + blockhash, + last_valid_block_height, + .. + } = client + .get_fees_with_commitment(CommitmentConfig::default())? .value; let transaction = Transaction::new(&signers, message, blockhash); let config = RpcSendTransactionConfig { @@ -395,11 +400,11 @@ fn send_messages( ..RpcSendTransactionConfig::default() }; client.send_transaction_with_config(&transaction, config)?; - Ok((transaction, last_valid_slot)) + Ok((transaction, last_valid_block_height)) } }; match result { - Ok((transaction, last_valid_slot)) => { + Ok((transaction, last_valid_block_height)) => { let new_stake_account_address_option = args.stake_args.as_ref().map(|_| &new_stake_account_address); db::set_transaction_info( @@ -409,7 +414,7 @@ fn send_messages( &transaction, new_stake_account_address_option, false, - last_valid_slot, + last_valid_block_height, lockup_date, )?; } @@ -658,7 +663,7 @@ fn update_finalized_transactions( if info.finalized_date.is_some() { None } else { - Some((&info.transaction, info.last_valid_slot)) + Some((&info.transaction, info.last_valid_block_height)) } }) .collect(); @@ -700,8 +705,8 @@ fn log_transaction_confirmations( statuses: Vec>, confirmations: &mut Option, ) -> Result<(), Error> { - let root_slot = client.get_slot()?; - for ((transaction, last_valid_slot), opt_transaction_status) in unconfirmed_transactions + let finalized_block_height = client.get_block_height()?; + for ((transaction, last_valid_block_height), opt_transaction_status) in unconfirmed_transactions .into_iter() .zip(statuses.into_iter()) { @@ -709,8 +714,8 @@ fn log_transaction_confirmations( db, &transaction.signatures[0], opt_transaction_status, - last_valid_slot, - root_slot, + last_valid_block_height, + finalized_block_height, ) { Ok(Some(confs)) => { *confirmations = Some(cmp::min(confs, confirmations.unwrap_or(usize::MAX))); @@ -1982,7 +1987,7 @@ mod tests { let sender = Keypair::new(); let recipient = Pubkey::new_unique(); let amount = sol_to_lamports(1.0); - let last_valid_slot = 222; + let last_valid_block_height = 222; let transaction = transfer(&client, amount, &sender, &recipient).unwrap(); // Queue db data @@ -1993,7 +1998,7 @@ mod tests { &transaction, None, false, - last_valid_slot, + last_valid_block_height, None, ) .unwrap(); @@ -2082,7 +2087,7 @@ mod tests { new_stake_account_address: None, finalized_date: None, transaction, - last_valid_slot, + last_valid_block_height, lockup_date: None, } ); @@ -2104,7 +2109,7 @@ mod tests { let sender = Keypair::new(); let recipient = Pubkey::new_unique(); let amount = sol_to_lamports(1.0); - let last_valid_slot = 222; + let last_valid_block_height = 222; let transaction = transfer(&client, amount, &sender, &recipient).unwrap(); // Queue db data @@ -2115,7 +2120,7 @@ mod tests { &transaction, None, false, - last_valid_slot, + last_valid_block_height, None, ) .unwrap(); @@ -2186,7 +2191,7 @@ mod tests { new_stake_account_address: None, finalized_date: None, transaction, - last_valid_slot, + last_valid_block_height, lockup_date: None, })); assert!(transaction_info.contains(&TransactionInfo { @@ -2195,7 +2200,7 @@ mod tests { new_stake_account_address: None, finalized_date: None, transaction: Transaction::new_unsigned(message), - last_valid_slot: std::u64::MAX, + last_valid_block_height: std::u64::MAX, lockup_date: None, })); @@ -2281,7 +2286,7 @@ mod tests { let sender = Keypair::new(); let recipient = Pubkey::new_unique(); let amount = sol_to_lamports(1.0); - let last_valid_slot = 222; + let last_valid_block_height = 222; let transaction = transfer(&client, amount, &sender, &recipient).unwrap(); // Queue unconfirmed transaction into db @@ -2292,7 +2297,7 @@ mod tests { &transaction, None, false, - last_valid_slot, + last_valid_block_height, None, ) .unwrap(); @@ -2374,7 +2379,7 @@ mod tests { let sender = Keypair::new(); let recipient = Pubkey::new_unique(); let amount = sol_to_lamports(1.0); - let last_valid_slot = 222; + let last_valid_block_height = 222; let transaction = transfer(&client, amount, &sender, &recipient).unwrap(); // Queue unconfirmed transaction into db @@ -2385,7 +2390,7 @@ mod tests { &transaction, None, false, - last_valid_slot, + last_valid_block_height, None, ) .unwrap(); diff --git a/tokens/src/db.rs b/tokens/src/db.rs index 1aaa92f06d..bd250597c7 100644 --- a/tokens/src/db.rs +++ b/tokens/src/db.rs @@ -12,7 +12,7 @@ pub struct TransactionInfo { pub new_stake_account_address: Option, pub finalized_date: Option>, pub transaction: Transaction, - pub last_valid_slot: Slot, + pub last_valid_block_height: Slot, pub lockup_date: Option>, } @@ -38,7 +38,7 @@ impl Default for TransactionInfo { new_stake_account_address: None, finalized_date: None, transaction, - last_valid_slot: 0, + last_valid_block_height: 0, lockup_date: None, } } @@ -108,7 +108,7 @@ pub fn set_transaction_info( transaction: &Transaction, new_stake_account_address: Option<&Pubkey>, finalized: bool, - last_valid_slot: Slot, + last_valid_block_height: u64, lockup_date: Option>, ) -> Result<(), Error> { let finalized_date = if finalized { Some(Utc::now()) } else { None }; @@ -118,7 +118,7 @@ pub fn set_transaction_info( new_stake_account_address: new_stake_account_address.cloned(), finalized_date, transaction: transaction.clone(), - last_valid_slot, + last_valid_block_height, lockup_date, }; let signature = transaction.signatures[0]; @@ -134,11 +134,11 @@ pub fn update_finalized_transaction( db: &mut PickleDb, signature: &Signature, opt_transaction_status: Option, - last_valid_slot: Slot, - root_slot: Slot, + last_valid_block_height: u64, + finalized_block_height: u64, ) -> Result, Error> { if opt_transaction_status.is_none() { - if root_slot > last_valid_slot { + if finalized_block_height > last_valid_block_height { eprintln!( "Signature not found {} and blockhash expired. Transaction either dropped or the validator purged the transaction status.", signature