diff --git a/core/src/storage_stage.rs b/core/src/storage_stage.rs index 1af789fb4..70acb2aea 100644 --- a/core/src/storage_stage.rs +++ b/core/src/storage_stage.rs @@ -284,7 +284,7 @@ impl StorageStage { let mut seed = [0u8; 32]; let signature = keypair.sign(&entry_id.as_ref()); - let tx = StorageTransaction::new_advertise_last_id( + let tx = StorageTransaction::new_advertise_recent_block_hash( keypair, entry_id, Hash::default(), diff --git a/drone/src/drone.rs b/drone/src/drone.rs index a848d295c..66aab8460 100644 --- a/drone/src/drone.rs +++ b/drone/src/drone.rs @@ -368,7 +368,7 @@ mod tests { assert_eq!(tx.signatures.len(), 1); assert_eq!(tx.account_keys, vec![mint_pubkey, to]); - assert_eq!(tx.last_id, last_id); + assert_eq!(tx.recent_block_hash, last_id); assert_eq!(tx.program_ids, vec![system_program::id()]); assert_eq!(tx.instructions.len(), 1); diff --git a/programs/native/storage/src/lib.rs b/programs/native/storage/src/lib.rs index 3bace689c..cd2084842 100644 --- a/programs/native/storage/src/lib.rs +++ b/programs/native/storage/src/lib.rs @@ -229,7 +229,7 @@ mod test { let pubkey = keypair.pubkey(); keyed_accounts.push(KeyedAccount::new(&pubkey, true, &mut user_account)); - let tx = StorageTransaction::new_advertise_last_id( + let tx = StorageTransaction::new_advertise_recent_block_hash( &keypair, Hash::default(), Hash::default(), @@ -287,7 +287,7 @@ mod test { let mut accounts = [Account::default(), Account::default()]; accounts[0].userdata.resize(16 * 1024, 0); - let tx = StorageTransaction::new_advertise_last_id( + let tx = StorageTransaction::new_advertise_recent_block_hash( &keypair, Hash::default(), Hash::default(), @@ -316,7 +316,7 @@ mod test { let entry_height = 0; - let tx = StorageTransaction::new_advertise_last_id( + let tx = StorageTransaction::new_advertise_recent_block_hash( &keypair, Hash::default(), Hash::default(), @@ -334,7 +334,7 @@ mod test { ); test_transaction(&tx, &mut accounts).unwrap(); - let tx = StorageTransaction::new_advertise_last_id( + let tx = StorageTransaction::new_advertise_recent_block_hash( &keypair, Hash::default(), Hash::default(), @@ -350,7 +350,7 @@ mod test { ); test_transaction(&tx, &mut accounts).unwrap(); - let tx = StorageTransaction::new_advertise_last_id( + let tx = StorageTransaction::new_advertise_recent_block_hash( &keypair, Hash::default(), Hash::default(), diff --git a/programs/native/storage/tests/storage.rs b/programs/native/storage/tests/storage.rs index 6fb5c07b0..4629ab3ac 100644 --- a/programs/native/storage/tests/storage.rs +++ b/programs/native/storage/tests/storage.rs @@ -69,7 +69,7 @@ fn test_bank_storage() { bank.process_transaction(&tx).unwrap(); - let tx = StorageTransaction::new_advertise_last_id( + let tx = StorageTransaction::new_advertise_recent_block_hash( &bob, storage_last_id, last_id, diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index e744a8367..d00deaf94 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -425,7 +425,7 @@ impl Bank { txs.iter() .zip(lock_results.into_iter()) .map(|(tx, lock_res)| { - if lock_res.is_ok() && !hash_queue.check_entry_age(tx.last_id, max_age) { + if lock_res.is_ok() && !hash_queue.check_entry_age(tx.recent_block_hash, max_age) { error_counters.reserve_last_id += 1; Err(BankError::LastIdNotFound) } else { diff --git a/sdk/src/budget_transaction.rs b/sdk/src/budget_transaction.rs index f393e3122..2d42f5a4d 100644 --- a/sdk/src/budget_transaction.rs +++ b/sdk/src/budget_transaction.rs @@ -20,7 +20,7 @@ impl BudgetTransaction { from_keypair: &Keypair, to: Pubkey, tokens: u64, - last_id: Hash, + recent_block_hash: Hash, fee: u64, ) -> Transaction { let contract = Keypair::new().pubkey(); @@ -29,13 +29,13 @@ impl BudgetTransaction { TransactionBuilder::new(fee) .push(SystemInstruction::new_move(from, contract, tokens)) .push(Instruction::new_budget(contract, payment)) - .sign(&[from_keypair], last_id) + .sign(&[from_keypair], recent_block_hash) } /// Create and sign a new Transaction. Used for unit-testing. #[allow(clippy::new_ret_no_self)] - pub fn new(from_keypair: &Keypair, to: Pubkey, tokens: u64, last_id: Hash) -> Transaction { - Self::new_payment(from_keypair, to, tokens, last_id, 0) + pub fn new(from_keypair: &Keypair, to: Pubkey, tokens: u64, recent_block_hash: Hash) -> Transaction { + Self::new_payment(from_keypair, to, tokens, recent_block_hash, 0) } /// Create and sign a new Witness Timestamp. Used for unit-testing. @@ -44,7 +44,7 @@ impl BudgetTransaction { contract: Pubkey, to: Pubkey, dt: DateTime, - last_id: Hash, + recent_block_hash: Hash, ) -> Transaction { let instruction = Instruction::ApplyTimestamp(dt); Transaction::new( @@ -52,7 +52,7 @@ impl BudgetTransaction { &[contract, to], budget_program::id(), &instruction, - last_id, + recent_block_hash, 0, ) } @@ -62,7 +62,7 @@ impl BudgetTransaction { from_keypair: &Keypair, contract: Pubkey, to: Pubkey, - last_id: Hash, + recent_block_hash: Hash, ) -> Transaction { let instruction = Instruction::ApplySignature; let mut keys = vec![contract]; @@ -74,7 +74,7 @@ impl BudgetTransaction { &keys, budget_program::id(), &instruction, - last_id, + recent_block_hash, 0, ) } @@ -88,7 +88,7 @@ impl BudgetTransaction { dt_pubkey: Pubkey, cancelable: Option, tokens: u64, - last_id: Hash, + recent_block_hash: Hash, ) -> Transaction { let expr = if let Some(from) = cancelable { BudgetExpr::Or( @@ -113,7 +113,7 @@ impl BudgetTransaction { &[contract], budget_program::id(), &instruction, - last_id, + recent_block_hash, 0, ) } @@ -125,7 +125,7 @@ impl BudgetTransaction { witness: Pubkey, cancelable: Option, tokens: u64, - last_id: Hash, + recent_block_hash: Hash, ) -> Transaction { let expr = if let Some(from) = cancelable { BudgetExpr::Or( @@ -150,7 +150,7 @@ impl BudgetTransaction { &[contract], budget_program::id(), &instruction, - last_id, + recent_block_hash, 0, ) } diff --git a/sdk/src/loader_transaction.rs b/sdk/src/loader_transaction.rs index 57658027f..978743375 100644 --- a/sdk/src/loader_transaction.rs +++ b/sdk/src/loader_transaction.rs @@ -14,20 +14,20 @@ impl LoaderTransaction { loader: Pubkey, offset: u32, bytes: Vec, - last_id: Hash, + recent_block_hash: Hash, fee: u64, ) -> Transaction { let instruction = LoaderInstruction::Write { offset, bytes }; - Transaction::new(from_keypair, &[], loader, &instruction, last_id, fee) + Transaction::new(from_keypair, &[], loader, &instruction, recent_block_hash, fee) } pub fn new_finalize( from_keypair: &Keypair, loader: Pubkey, - last_id: Hash, + recent_block_hash: Hash, fee: u64, ) -> Transaction { let instruction = LoaderInstruction::Finalize; - Transaction::new(from_keypair, &[], loader, &instruction, last_id, fee) + Transaction::new(from_keypair, &[], loader, &instruction, recent_block_hash, fee) } } diff --git a/sdk/src/storage_program.rs b/sdk/src/storage_program.rs index 21d0a9839..e6b2f50c1 100644 --- a/sdk/src/storage_program.rs +++ b/sdk/src/storage_program.rs @@ -80,7 +80,7 @@ impl StorageTransaction { pub fn new_mining_proof( from_keypair: &Keypair, sha_state: Hash, - last_id: Hash, + recent_block_hash: Hash, entry_height: u64, signature: Signature, ) -> Transaction { @@ -89,25 +89,25 @@ impl StorageTransaction { entry_height, signature, }; - Transaction::new(from_keypair, &[], id(), &program, last_id, 0) + Transaction::new(from_keypair, &[], id(), &program, recent_block_hash, 0) } - pub fn new_advertise_last_id( + pub fn new_advertise_recent_block_hash( from_keypair: &Keypair, storage_id: Hash, - last_id: Hash, + recent_block_hash: Hash, entry_height: u64, ) -> Transaction { let program = StorageProgram::AdvertiseStorageLastId { id: storage_id, entry_height, }; - Transaction::new(from_keypair, &[], id(), &program, last_id, 0) + Transaction::new(from_keypair, &[], id(), &program, recent_block_hash, 0) } pub fn new_proof_validation( from_keypair: &Keypair, - last_id: Hash, + recent_block_hash: Hash, entry_height: u64, proof_mask: Vec, ) -> Transaction { @@ -115,15 +115,15 @@ impl StorageTransaction { entry_height, proof_mask, }; - Transaction::new(from_keypair, &[], id(), &program, last_id, 0) + Transaction::new(from_keypair, &[], id(), &program, recent_block_hash, 0) } pub fn new_reward_claim( from_keypair: &Keypair, - last_id: Hash, + recent_block_hash: Hash, entry_height: u64, ) -> Transaction { let program = StorageProgram::ClaimStorageReward { entry_height }; - Transaction::new(from_keypair, &[], id(), &program, last_id, 0) + Transaction::new(from_keypair, &[], id(), &program, recent_block_hash, 0) } } diff --git a/sdk/src/system_transaction.rs b/sdk/src/system_transaction.rs index f892eb235..194a3f1f4 100644 --- a/sdk/src/system_transaction.rs +++ b/sdk/src/system_transaction.rs @@ -14,7 +14,7 @@ impl SystemTransaction { pub fn new_program_account( from_keypair: &Keypair, to: Pubkey, - last_id: Hash, + recent_block_hash: Hash, tokens: u64, space: u64, program_id: Pubkey, @@ -30,7 +30,7 @@ impl SystemTransaction { &[to], system_program::id(), &create, - last_id, + recent_block_hash, fee, ) } @@ -40,16 +40,16 @@ impl SystemTransaction { from_keypair: &Keypair, to: Pubkey, tokens: u64, - last_id: Hash, + recent_block_hash: Hash, fee: u64, ) -> Transaction { let program_id = system_program::id(); - Self::new_program_account(from_keypair, to, last_id, tokens, 0, program_id, fee) + Self::new_program_account(from_keypair, to, recent_block_hash, tokens, 0, program_id, fee) } /// Create and sign new SystemInstruction::Assign transaction pub fn new_assign( from_keypair: &Keypair, - last_id: Hash, + recent_block_hash: Hash, program_id: Pubkey, fee: u64, ) -> Transaction { @@ -59,7 +59,7 @@ impl SystemTransaction { &[], system_program::id(), &assign, - last_id, + recent_block_hash, fee, ) } @@ -68,7 +68,7 @@ impl SystemTransaction { from_keypair: &Keypair, to: Pubkey, tokens: u64, - last_id: Hash, + recent_block_hash: Hash, fee: u64, ) -> Transaction { let move_tokens = SystemInstruction::Move { tokens }; @@ -77,7 +77,7 @@ impl SystemTransaction { &[to], system_program::id(), &move_tokens, - last_id, + recent_block_hash, fee, ) } @@ -85,7 +85,7 @@ impl SystemTransaction { pub fn new_move_many( from: &Keypair, moves: &[(Pubkey, u64)], - last_id: Hash, + recent_block_hash: Hash, fee: u64, ) -> Transaction { let instructions: Vec<_> = moves @@ -101,7 +101,7 @@ impl SystemTransaction { Transaction::new_with_instructions( &[from], &to_keys, - last_id, + recent_block_hash, fee, vec![system_program::id()], instructions, diff --git a/sdk/src/timing.rs b/sdk/src/timing.rs index eb4eb4405..854580dfb 100644 --- a/sdk/src/timing.rs +++ b/sdk/src/timing.rs @@ -9,10 +9,10 @@ pub const NUM_TICKS_PER_SECOND: u64 = 10; pub const DEFAULT_TICKS_PER_SLOT: u64 = 80; pub const DEFAULT_SLOTS_PER_EPOCH: u64 = 64; -/// The time window of recent `last_id` values that the bank will track the signatures -/// of over. Once the bank discards a `last_id`, it will reject any transactions that use -/// that `last_id` in a transaction. Lowering this value reduces memory consumption, -/// but requires clients to update its `last_id` more frequently. Raising the value +/// The time window of recent block hash values that the bank will track the signatures +/// of over. Once the bank discards a block hash, it will reject any transactions that use +/// that `recent_block_hash` in a transaction. Lowering this value reduces memory consumption, +/// but requires clients to update its `recent_block_hash` more frequently. Raising the value /// lengthens the time a client must wait to be certain a missing transaction will /// not be processed by the network. pub const MAX_HASH_AGE_IN_SECONDS: usize = 120; diff --git a/sdk/src/transaction.rs b/sdk/src/transaction.rs index 3a488f86a..c2aa28de1 100644 --- a/sdk/src/transaction.rs +++ b/sdk/src/transaction.rs @@ -79,13 +79,13 @@ impl Instruction { /// An atomic transaction #[derive(Debug, PartialEq, Eq, Clone)] pub struct Transaction { - /// A set of digital signatures of `account_keys`, `program_ids`, `last_id`, `fee` and `instructions`, signed by the first + /// A set of digital signatures of `account_keys`, `program_ids`, `recent_block_hash`, `fee` and `instructions`, signed by the first /// signatures.len() keys of account_keys pub signatures: Vec, /// All the account keys used by this transaction pub account_keys: Vec, /// The id of a recent ledger entry. - pub last_id: Hash, + pub recent_block_hash: Hash, /// The number of tokens paid for processing and storing of this transaction. pub fee: u64, /// All the program id keys used to execute this transaction's instructions @@ -101,7 +101,7 @@ impl Transaction { transaction_keys: &[Pubkey], program_id: Pubkey, userdata: &S, - last_id: Hash, + recent_block_hash: Hash, fee: u64, ) -> Self { let program_ids = vec![program_id]; @@ -110,7 +110,7 @@ impl Transaction { Self::new_with_instructions( &[from_keypair], transaction_keys, - last_id, + recent_block_hash, fee, program_ids, instructions, @@ -121,7 +121,7 @@ impl Transaction { transaction_keys: &[Pubkey], program_id: Pubkey, userdata: &T, - last_id: Hash, + recent_block_hash: Hash, fee: u64, ) -> Self { let program_ids = vec![program_id]; @@ -132,7 +132,7 @@ impl Transaction { Self::new_with_instructions::( &[], &keys[..], - last_id, + recent_block_hash, fee, program_ids, instructions, @@ -142,14 +142,14 @@ impl Transaction { /// * `from_keypair` - The key used to sign the transaction. This key is stored as keys[0] /// * `account_keys` - The keys for the transaction. These are the program state /// instances or token recipient keys. - /// * `last_id` - The PoH hash. + /// * `recent_block_hash` - The PoH hash. /// * `fee` - The transaction fee. /// * `program_ids` - The keys that identify programs used in the `instruction` vector. /// * `instructions` - The programs and their arguments that the transaction will execute atomically pub fn new_with_instructions( from_keypairs: &[&T], keys: &[Pubkey], - last_id: Hash, + recent_block_hash: Hash, fee: u64, program_ids: Vec, instructions: Vec>, @@ -162,12 +162,12 @@ impl Transaction { let mut tx = Transaction { signatures: vec![], account_keys, - last_id: Hash::default(), + recent_block_hash: Hash::default(), fee, program_ids, instructions, }; - tx.sign(from_keypairs, last_id); + tx.sign(from_keypairs, recent_block_hash); tx } pub fn userdata(&self, instruction_index: usize) -> &[u8] { @@ -205,8 +205,8 @@ impl Transaction { let mut wr = Cursor::new(&mut buf[..]); serialize_vec_with(&mut wr, &self.account_keys, Transaction::serialize_pubkey) .expect("serialize account_keys"); - wr.write_all(self.last_id.as_ref()) - .expect("serialize last_id"); + wr.write_all(self.recent_block_hash.as_ref()) + .expect("serialize recent_block_hash"); wr.write_u64::(self.fee) .expect("serialize fee"); serialize_vec_with(&mut wr, &self.program_ids, Transaction::serialize_pubkey) @@ -218,8 +218,8 @@ impl Transaction { } /// Sign this transaction. - pub fn sign(&mut self, keypairs: &[&T], last_id: Hash) { - self.last_id = last_id; + pub fn sign(&mut self, keypairs: &[&T], recent_block_hash: Hash) { + self.recent_block_hash = recent_block_hash; let message = self.message(); self.signatures = keypairs .iter() @@ -332,7 +332,7 @@ impl Serialize for Transaction { .map_err(Error::custom)?; serialize_vec_with(&mut wr, &self.account_keys, Transaction::serialize_pubkey) .map_err(Error::custom)?; - wr.write_all(self.last_id.as_ref()).map_err(Error::custom)?; + wr.write_all(self.recent_block_hash.as_ref()).map_err(Error::custom)?; wr.write_u64::(self.fee) .map_err(Error::custom)?; serialize_vec_with(&mut wr, &self.program_ids, Transaction::serialize_pubkey) @@ -365,7 +365,7 @@ impl<'a> serde::de::Visitor<'a> for TransactionVisitor { .map_err(Error::custom)?; let mut buf = [0; size_of::()]; rd.read_exact(&mut buf).map_err(Error::custom)?; - let last_id: Hash = Hash::new(&buf); + let recent_block_hash: Hash = Hash::new(&buf); let fee = rd.read_u64::().map_err(Error::custom)?; let program_ids: Vec = deserialize_vec_with(&mut rd, Transaction::deserialize_pubkey) @@ -375,7 +375,7 @@ impl<'a> serde::de::Visitor<'a> for TransactionVisitor { Ok(Transaction { signatures, account_keys, - last_id, + recent_block_hash, fee, program_ids, instructions, diff --git a/sdk/src/transaction_builder.rs b/sdk/src/transaction_builder.rs index aeb6615a3..dbc1323e7 100644 --- a/sdk/src/transaction_builder.rs +++ b/sdk/src/transaction_builder.rs @@ -91,7 +91,7 @@ impl TransactionBuilder { } /// Return a signed transaction. - pub fn sign(&self, keypairs: &[&T], last_id: Hash) -> Transaction { + pub fn sign(&self, keypairs: &[&T], recent_block_hash: Hash) -> Transaction { let program_ids = self.program_ids(); let (mut signed_keys, unsigned_keys) = self.keys(); for (i, keypair) in keypairs.iter().enumerate() { @@ -104,7 +104,7 @@ impl TransactionBuilder { Transaction::new_with_instructions( keypairs, &unsigned_keys, - last_id, + recent_block_hash, self.fee, program_ids, instructions, diff --git a/sdk/src/vote_transaction.rs b/sdk/src/vote_transaction.rs index efb8ef020..336a013f9 100644 --- a/sdk/src/vote_transaction.rs +++ b/sdk/src/vote_transaction.rs @@ -16,20 +16,20 @@ impl VoteTransaction { pub fn new_vote( voting_keypair: &T, slot_height: u64, - last_id: Hash, + recent_block_hash: Hash, fee: u64, ) -> Transaction { let vote = Vote { slot_height }; TransactionBuilder::new(fee) .push(VoteInstruction::new_vote(voting_keypair.pubkey(), vote)) - .sign(&[voting_keypair], last_id) + .sign(&[voting_keypair], recent_block_hash) } /// Fund or create the staking account with tokens pub fn fund_staking_account( from_keypair: &Keypair, vote_account_id: Pubkey, - last_id: Hash, + recent_block_hash: Hash, num_tokens: u64, fee: u64, ) -> Transaction { @@ -41,7 +41,7 @@ impl VoteTransaction { Transaction::new_with_instructions( &[from_keypair], &[vote_account_id], - last_id, + recent_block_hash, fee, vec![system_program::id(), vote_program::id()], vec![ @@ -54,7 +54,7 @@ impl VoteTransaction { /// Choose a node id to `delegate` or `assign` this vote account to pub fn delegate_vote_account( vote_keypair: &T, - last_id: Hash, + recent_block_hash: Hash, node_id: Pubkey, fee: u64, ) -> Transaction { @@ -63,7 +63,7 @@ impl VoteTransaction { vote_keypair.pubkey(), node_id, )) - .sign(&[vote_keypair], last_id) + .sign(&[vote_keypair], recent_block_hash) } fn get_vote(tx: &Transaction, ix_index: usize) -> Option<(Pubkey, Vote, Hash)> { @@ -72,7 +72,7 @@ impl VoteTransaction { } let instruction = deserialize(&tx.userdata(ix_index)).unwrap(); if let VoteInstruction::Vote(vote) = instruction { - Some((tx.account_keys[0], vote, tx.last_id)) + Some((tx.account_keys[0], vote, tx.recent_block_hash)) } else { None } @@ -93,11 +93,11 @@ mod tests { fn test_get_votes() { let keypair = Keypair::new(); let slot_height = 1; - let last_id = Hash::default(); - let transaction = VoteTransaction::new_vote(&keypair, slot_height, last_id, 0); + let recent_block_hash = Hash::default(); + let transaction = VoteTransaction::new_vote(&keypair, slot_height, recent_block_hash, 0); assert_eq!( VoteTransaction::get_votes(&transaction), - vec![(keypair.pubkey(), Vote::new(slot_height), last_id)] + vec![(keypair.pubkey(), Vote::new(slot_height), recent_block_hash)] ); } } diff --git a/wallet/src/wallet.rs b/wallet/src/wallet.rs index 7d920afb1..f5fc5c49d 100644 --- a/wallet/src/wallet.rs +++ b/wallet/src/wallet.rs @@ -900,7 +900,8 @@ fn send_and_confirm_transactions( send_retries -= 1; // Re-sign any failed transactions with a new last_id and retry - let last_id = get_next_last_id(rpc_client, &transactions_signatures[0].0.last_id)?; + let last_id = + get_next_last_id(rpc_client, &transactions_signatures[0].0.recent_block_hash)?; transactions = transactions_signatures .into_iter() .map(|(mut transaction, _)| { @@ -916,7 +917,7 @@ fn resign_transaction( tx: &mut Transaction, signer_key: &Keypair, ) -> Result<(), Box> { - let last_id = get_next_last_id(rpc_client, &tx.last_id)?; + let last_id = get_next_last_id(rpc_client, &tx.recent_block_hash)?; tx.sign(&[signer_key], last_id); Ok(()) } @@ -1596,7 +1597,7 @@ mod tests { assert_ne!(prev_tx, tx); assert_ne!(prev_tx.signatures, tx.signatures); - assert_ne!(prev_tx.last_id, tx.last_id); + assert_ne!(prev_tx.recent_block_hash, tx.recent_block_hash); assert_eq!(prev_tx.fee, tx.fee); assert_eq!(prev_tx.account_keys, tx.account_keys); assert_eq!(prev_tx.instructions, tx.instructions);