Rename Transaction last_id field to recent_block_hash

This commit is contained in:
Michael Vines
2019-03-02 09:17:03 -08:00
committed by Greg Fitzgerald
parent 16b71a6be0
commit 176d5e0d37
14 changed files with 81 additions and 80 deletions

View File

@ -284,7 +284,7 @@ impl StorageStage {
let mut seed = [0u8; 32]; let mut seed = [0u8; 32];
let signature = keypair.sign(&entry_id.as_ref()); let signature = keypair.sign(&entry_id.as_ref());
let tx = StorageTransaction::new_advertise_last_id( let tx = StorageTransaction::new_advertise_recent_block_hash(
keypair, keypair,
entry_id, entry_id,
Hash::default(), Hash::default(),

View File

@ -368,7 +368,7 @@ mod tests {
assert_eq!(tx.signatures.len(), 1); assert_eq!(tx.signatures.len(), 1);
assert_eq!(tx.account_keys, vec![mint_pubkey, to]); 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.program_ids, vec![system_program::id()]);
assert_eq!(tx.instructions.len(), 1); assert_eq!(tx.instructions.len(), 1);

View File

@ -229,7 +229,7 @@ mod test {
let pubkey = keypair.pubkey(); let pubkey = keypair.pubkey();
keyed_accounts.push(KeyedAccount::new(&pubkey, true, &mut user_account)); 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, &keypair,
Hash::default(), Hash::default(),
Hash::default(), Hash::default(),
@ -287,7 +287,7 @@ mod test {
let mut accounts = [Account::default(), Account::default()]; let mut accounts = [Account::default(), Account::default()];
accounts[0].userdata.resize(16 * 1024, 0); accounts[0].userdata.resize(16 * 1024, 0);
let tx = StorageTransaction::new_advertise_last_id( let tx = StorageTransaction::new_advertise_recent_block_hash(
&keypair, &keypair,
Hash::default(), Hash::default(),
Hash::default(), Hash::default(),
@ -316,7 +316,7 @@ mod test {
let entry_height = 0; let entry_height = 0;
let tx = StorageTransaction::new_advertise_last_id( let tx = StorageTransaction::new_advertise_recent_block_hash(
&keypair, &keypair,
Hash::default(), Hash::default(),
Hash::default(), Hash::default(),
@ -334,7 +334,7 @@ mod test {
); );
test_transaction(&tx, &mut accounts).unwrap(); test_transaction(&tx, &mut accounts).unwrap();
let tx = StorageTransaction::new_advertise_last_id( let tx = StorageTransaction::new_advertise_recent_block_hash(
&keypair, &keypair,
Hash::default(), Hash::default(),
Hash::default(), Hash::default(),
@ -350,7 +350,7 @@ mod test {
); );
test_transaction(&tx, &mut accounts).unwrap(); test_transaction(&tx, &mut accounts).unwrap();
let tx = StorageTransaction::new_advertise_last_id( let tx = StorageTransaction::new_advertise_recent_block_hash(
&keypair, &keypair,
Hash::default(), Hash::default(),
Hash::default(), Hash::default(),

View File

@ -69,7 +69,7 @@ fn test_bank_storage() {
bank.process_transaction(&tx).unwrap(); bank.process_transaction(&tx).unwrap();
let tx = StorageTransaction::new_advertise_last_id( let tx = StorageTransaction::new_advertise_recent_block_hash(
&bob, &bob,
storage_last_id, storage_last_id,
last_id, last_id,

View File

@ -425,7 +425,7 @@ impl Bank {
txs.iter() txs.iter()
.zip(lock_results.into_iter()) .zip(lock_results.into_iter())
.map(|(tx, lock_res)| { .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; error_counters.reserve_last_id += 1;
Err(BankError::LastIdNotFound) Err(BankError::LastIdNotFound)
} else { } else {

View File

@ -20,7 +20,7 @@ impl BudgetTransaction {
from_keypair: &Keypair, from_keypair: &Keypair,
to: Pubkey, to: Pubkey,
tokens: u64, tokens: u64,
last_id: Hash, recent_block_hash: Hash,
fee: u64, fee: u64,
) -> Transaction { ) -> Transaction {
let contract = Keypair::new().pubkey(); let contract = Keypair::new().pubkey();
@ -29,13 +29,13 @@ impl BudgetTransaction {
TransactionBuilder::new(fee) TransactionBuilder::new(fee)
.push(SystemInstruction::new_move(from, contract, tokens)) .push(SystemInstruction::new_move(from, contract, tokens))
.push(Instruction::new_budget(contract, payment)) .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. /// Create and sign a new Transaction. Used for unit-testing.
#[allow(clippy::new_ret_no_self)] #[allow(clippy::new_ret_no_self)]
pub fn new(from_keypair: &Keypair, to: Pubkey, tokens: u64, last_id: Hash) -> Transaction { pub fn new(from_keypair: &Keypair, to: Pubkey, tokens: u64, recent_block_hash: Hash) -> Transaction {
Self::new_payment(from_keypair, to, tokens, last_id, 0) Self::new_payment(from_keypair, to, tokens, recent_block_hash, 0)
} }
/// Create and sign a new Witness Timestamp. Used for unit-testing. /// Create and sign a new Witness Timestamp. Used for unit-testing.
@ -44,7 +44,7 @@ impl BudgetTransaction {
contract: Pubkey, contract: Pubkey,
to: Pubkey, to: Pubkey,
dt: DateTime<Utc>, dt: DateTime<Utc>,
last_id: Hash, recent_block_hash: Hash,
) -> Transaction { ) -> Transaction {
let instruction = Instruction::ApplyTimestamp(dt); let instruction = Instruction::ApplyTimestamp(dt);
Transaction::new( Transaction::new(
@ -52,7 +52,7 @@ impl BudgetTransaction {
&[contract, to], &[contract, to],
budget_program::id(), budget_program::id(),
&instruction, &instruction,
last_id, recent_block_hash,
0, 0,
) )
} }
@ -62,7 +62,7 @@ impl BudgetTransaction {
from_keypair: &Keypair, from_keypair: &Keypair,
contract: Pubkey, contract: Pubkey,
to: Pubkey, to: Pubkey,
last_id: Hash, recent_block_hash: Hash,
) -> Transaction { ) -> Transaction {
let instruction = Instruction::ApplySignature; let instruction = Instruction::ApplySignature;
let mut keys = vec![contract]; let mut keys = vec![contract];
@ -74,7 +74,7 @@ impl BudgetTransaction {
&keys, &keys,
budget_program::id(), budget_program::id(),
&instruction, &instruction,
last_id, recent_block_hash,
0, 0,
) )
} }
@ -88,7 +88,7 @@ impl BudgetTransaction {
dt_pubkey: Pubkey, dt_pubkey: Pubkey,
cancelable: Option<Pubkey>, cancelable: Option<Pubkey>,
tokens: u64, tokens: u64,
last_id: Hash, recent_block_hash: Hash,
) -> Transaction { ) -> Transaction {
let expr = if let Some(from) = cancelable { let expr = if let Some(from) = cancelable {
BudgetExpr::Or( BudgetExpr::Or(
@ -113,7 +113,7 @@ impl BudgetTransaction {
&[contract], &[contract],
budget_program::id(), budget_program::id(),
&instruction, &instruction,
last_id, recent_block_hash,
0, 0,
) )
} }
@ -125,7 +125,7 @@ impl BudgetTransaction {
witness: Pubkey, witness: Pubkey,
cancelable: Option<Pubkey>, cancelable: Option<Pubkey>,
tokens: u64, tokens: u64,
last_id: Hash, recent_block_hash: Hash,
) -> Transaction { ) -> Transaction {
let expr = if let Some(from) = cancelable { let expr = if let Some(from) = cancelable {
BudgetExpr::Or( BudgetExpr::Or(
@ -150,7 +150,7 @@ impl BudgetTransaction {
&[contract], &[contract],
budget_program::id(), budget_program::id(),
&instruction, &instruction,
last_id, recent_block_hash,
0, 0,
) )
} }

View File

@ -14,20 +14,20 @@ impl LoaderTransaction {
loader: Pubkey, loader: Pubkey,
offset: u32, offset: u32,
bytes: Vec<u8>, bytes: Vec<u8>,
last_id: Hash, recent_block_hash: Hash,
fee: u64, fee: u64,
) -> Transaction { ) -> Transaction {
let instruction = LoaderInstruction::Write { offset, bytes }; 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( pub fn new_finalize(
from_keypair: &Keypair, from_keypair: &Keypair,
loader: Pubkey, loader: Pubkey,
last_id: Hash, recent_block_hash: Hash,
fee: u64, fee: u64,
) -> Transaction { ) -> Transaction {
let instruction = LoaderInstruction::Finalize; let instruction = LoaderInstruction::Finalize;
Transaction::new(from_keypair, &[], loader, &instruction, last_id, fee) Transaction::new(from_keypair, &[], loader, &instruction, recent_block_hash, fee)
} }
} }

View File

@ -80,7 +80,7 @@ impl StorageTransaction {
pub fn new_mining_proof( pub fn new_mining_proof(
from_keypair: &Keypair, from_keypair: &Keypair,
sha_state: Hash, sha_state: Hash,
last_id: Hash, recent_block_hash: Hash,
entry_height: u64, entry_height: u64,
signature: Signature, signature: Signature,
) -> Transaction { ) -> Transaction {
@ -89,25 +89,25 @@ impl StorageTransaction {
entry_height, entry_height,
signature, 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, from_keypair: &Keypair,
storage_id: Hash, storage_id: Hash,
last_id: Hash, recent_block_hash: Hash,
entry_height: u64, entry_height: u64,
) -> Transaction { ) -> Transaction {
let program = StorageProgram::AdvertiseStorageLastId { let program = StorageProgram::AdvertiseStorageLastId {
id: storage_id, id: storage_id,
entry_height, 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( pub fn new_proof_validation(
from_keypair: &Keypair, from_keypair: &Keypair,
last_id: Hash, recent_block_hash: Hash,
entry_height: u64, entry_height: u64,
proof_mask: Vec<ProofStatus>, proof_mask: Vec<ProofStatus>,
) -> Transaction { ) -> Transaction {
@ -115,15 +115,15 @@ impl StorageTransaction {
entry_height, entry_height,
proof_mask, 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( pub fn new_reward_claim(
from_keypair: &Keypair, from_keypair: &Keypair,
last_id: Hash, recent_block_hash: Hash,
entry_height: u64, entry_height: u64,
) -> Transaction { ) -> Transaction {
let program = StorageProgram::ClaimStorageReward { entry_height }; 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)
} }
} }

View File

@ -14,7 +14,7 @@ impl SystemTransaction {
pub fn new_program_account( pub fn new_program_account(
from_keypair: &Keypair, from_keypair: &Keypair,
to: Pubkey, to: Pubkey,
last_id: Hash, recent_block_hash: Hash,
tokens: u64, tokens: u64,
space: u64, space: u64,
program_id: Pubkey, program_id: Pubkey,
@ -30,7 +30,7 @@ impl SystemTransaction {
&[to], &[to],
system_program::id(), system_program::id(),
&create, &create,
last_id, recent_block_hash,
fee, fee,
) )
} }
@ -40,16 +40,16 @@ impl SystemTransaction {
from_keypair: &Keypair, from_keypair: &Keypair,
to: Pubkey, to: Pubkey,
tokens: u64, tokens: u64,
last_id: Hash, recent_block_hash: Hash,
fee: u64, fee: u64,
) -> Transaction { ) -> Transaction {
let program_id = system_program::id(); 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 /// Create and sign new SystemInstruction::Assign transaction
pub fn new_assign( pub fn new_assign(
from_keypair: &Keypair, from_keypair: &Keypair,
last_id: Hash, recent_block_hash: Hash,
program_id: Pubkey, program_id: Pubkey,
fee: u64, fee: u64,
) -> Transaction { ) -> Transaction {
@ -59,7 +59,7 @@ impl SystemTransaction {
&[], &[],
system_program::id(), system_program::id(),
&assign, &assign,
last_id, recent_block_hash,
fee, fee,
) )
} }
@ -68,7 +68,7 @@ impl SystemTransaction {
from_keypair: &Keypair, from_keypair: &Keypair,
to: Pubkey, to: Pubkey,
tokens: u64, tokens: u64,
last_id: Hash, recent_block_hash: Hash,
fee: u64, fee: u64,
) -> Transaction { ) -> Transaction {
let move_tokens = SystemInstruction::Move { tokens }; let move_tokens = SystemInstruction::Move { tokens };
@ -77,7 +77,7 @@ impl SystemTransaction {
&[to], &[to],
system_program::id(), system_program::id(),
&move_tokens, &move_tokens,
last_id, recent_block_hash,
fee, fee,
) )
} }
@ -85,7 +85,7 @@ impl SystemTransaction {
pub fn new_move_many( pub fn new_move_many(
from: &Keypair, from: &Keypair,
moves: &[(Pubkey, u64)], moves: &[(Pubkey, u64)],
last_id: Hash, recent_block_hash: Hash,
fee: u64, fee: u64,
) -> Transaction { ) -> Transaction {
let instructions: Vec<_> = moves let instructions: Vec<_> = moves
@ -101,7 +101,7 @@ impl SystemTransaction {
Transaction::new_with_instructions( Transaction::new_with_instructions(
&[from], &[from],
&to_keys, &to_keys,
last_id, recent_block_hash,
fee, fee,
vec![system_program::id()], vec![system_program::id()],
instructions, instructions,

View File

@ -9,10 +9,10 @@ pub const NUM_TICKS_PER_SECOND: u64 = 10;
pub const DEFAULT_TICKS_PER_SLOT: u64 = 80; pub const DEFAULT_TICKS_PER_SLOT: u64 = 80;
pub const DEFAULT_SLOTS_PER_EPOCH: u64 = 64; pub const DEFAULT_SLOTS_PER_EPOCH: u64 = 64;
/// The time window of recent `last_id` values that the bank will track the signatures /// The time window of recent block hash values that the bank will track the signatures
/// of over. Once the bank discards a `last_id`, it will reject any transactions that use /// of over. Once the bank discards a block hash, it will reject any transactions that use
/// that `last_id` in a transaction. Lowering this value reduces memory consumption, /// that `recent_block_hash` in a transaction. Lowering this value reduces memory consumption,
/// but requires clients to update its `last_id` more frequently. Raising the value /// 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 /// lengthens the time a client must wait to be certain a missing transaction will
/// not be processed by the network. /// not be processed by the network.
pub const MAX_HASH_AGE_IN_SECONDS: usize = 120; pub const MAX_HASH_AGE_IN_SECONDS: usize = 120;

View File

@ -79,13 +79,13 @@ impl Instruction<u8, u8> {
/// An atomic transaction /// An atomic transaction
#[derive(Debug, PartialEq, Eq, Clone)] #[derive(Debug, PartialEq, Eq, Clone)]
pub struct Transaction { 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 /// signatures.len() keys of account_keys
pub signatures: Vec<Signature>, pub signatures: Vec<Signature>,
/// All the account keys used by this transaction /// All the account keys used by this transaction
pub account_keys: Vec<Pubkey>, pub account_keys: Vec<Pubkey>,
/// The id of a recent ledger entry. /// 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. /// The number of tokens paid for processing and storing of this transaction.
pub fee: u64, pub fee: u64,
/// All the program id keys used to execute this transaction's instructions /// All the program id keys used to execute this transaction's instructions
@ -101,7 +101,7 @@ impl Transaction {
transaction_keys: &[Pubkey], transaction_keys: &[Pubkey],
program_id: Pubkey, program_id: Pubkey,
userdata: &S, userdata: &S,
last_id: Hash, recent_block_hash: Hash,
fee: u64, fee: u64,
) -> Self { ) -> Self {
let program_ids = vec![program_id]; let program_ids = vec![program_id];
@ -110,7 +110,7 @@ impl Transaction {
Self::new_with_instructions( Self::new_with_instructions(
&[from_keypair], &[from_keypair],
transaction_keys, transaction_keys,
last_id, recent_block_hash,
fee, fee,
program_ids, program_ids,
instructions, instructions,
@ -121,7 +121,7 @@ impl Transaction {
transaction_keys: &[Pubkey], transaction_keys: &[Pubkey],
program_id: Pubkey, program_id: Pubkey,
userdata: &T, userdata: &T,
last_id: Hash, recent_block_hash: Hash,
fee: u64, fee: u64,
) -> Self { ) -> Self {
let program_ids = vec![program_id]; let program_ids = vec![program_id];
@ -132,7 +132,7 @@ impl Transaction {
Self::new_with_instructions::<Keypair>( Self::new_with_instructions::<Keypair>(
&[], &[],
&keys[..], &keys[..],
last_id, recent_block_hash,
fee, fee,
program_ids, program_ids,
instructions, instructions,
@ -142,14 +142,14 @@ impl Transaction {
/// * `from_keypair` - The key used to sign the transaction. This key is stored as keys[0] /// * `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 /// * `account_keys` - The keys for the transaction. These are the program state
/// instances or token recipient keys. /// instances or token recipient keys.
/// * `last_id` - The PoH hash. /// * `recent_block_hash` - The PoH hash.
/// * `fee` - The transaction fee. /// * `fee` - The transaction fee.
/// * `program_ids` - The keys that identify programs used in the `instruction` vector. /// * `program_ids` - The keys that identify programs used in the `instruction` vector.
/// * `instructions` - The programs and their arguments that the transaction will execute atomically /// * `instructions` - The programs and their arguments that the transaction will execute atomically
pub fn new_with_instructions<T: KeypairUtil>( pub fn new_with_instructions<T: KeypairUtil>(
from_keypairs: &[&T], from_keypairs: &[&T],
keys: &[Pubkey], keys: &[Pubkey],
last_id: Hash, recent_block_hash: Hash,
fee: u64, fee: u64,
program_ids: Vec<Pubkey>, program_ids: Vec<Pubkey>,
instructions: Vec<Instruction<u8, u8>>, instructions: Vec<Instruction<u8, u8>>,
@ -162,12 +162,12 @@ impl Transaction {
let mut tx = Transaction { let mut tx = Transaction {
signatures: vec![], signatures: vec![],
account_keys, account_keys,
last_id: Hash::default(), recent_block_hash: Hash::default(),
fee, fee,
program_ids, program_ids,
instructions, instructions,
}; };
tx.sign(from_keypairs, last_id); tx.sign(from_keypairs, recent_block_hash);
tx tx
} }
pub fn userdata(&self, instruction_index: usize) -> &[u8] { pub fn userdata(&self, instruction_index: usize) -> &[u8] {
@ -205,8 +205,8 @@ impl Transaction {
let mut wr = Cursor::new(&mut buf[..]); let mut wr = Cursor::new(&mut buf[..]);
serialize_vec_with(&mut wr, &self.account_keys, Transaction::serialize_pubkey) serialize_vec_with(&mut wr, &self.account_keys, Transaction::serialize_pubkey)
.expect("serialize account_keys"); .expect("serialize account_keys");
wr.write_all(self.last_id.as_ref()) wr.write_all(self.recent_block_hash.as_ref())
.expect("serialize last_id"); .expect("serialize recent_block_hash");
wr.write_u64::<LittleEndian>(self.fee) wr.write_u64::<LittleEndian>(self.fee)
.expect("serialize fee"); .expect("serialize fee");
serialize_vec_with(&mut wr, &self.program_ids, Transaction::serialize_pubkey) serialize_vec_with(&mut wr, &self.program_ids, Transaction::serialize_pubkey)
@ -218,8 +218,8 @@ impl Transaction {
} }
/// Sign this transaction. /// Sign this transaction.
pub fn sign<T: KeypairUtil>(&mut self, keypairs: &[&T], last_id: Hash) { pub fn sign<T: KeypairUtil>(&mut self, keypairs: &[&T], recent_block_hash: Hash) {
self.last_id = last_id; self.recent_block_hash = recent_block_hash;
let message = self.message(); let message = self.message();
self.signatures = keypairs self.signatures = keypairs
.iter() .iter()
@ -332,7 +332,7 @@ impl Serialize for Transaction {
.map_err(Error::custom)?; .map_err(Error::custom)?;
serialize_vec_with(&mut wr, &self.account_keys, Transaction::serialize_pubkey) serialize_vec_with(&mut wr, &self.account_keys, Transaction::serialize_pubkey)
.map_err(Error::custom)?; .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::<LittleEndian>(self.fee) wr.write_u64::<LittleEndian>(self.fee)
.map_err(Error::custom)?; .map_err(Error::custom)?;
serialize_vec_with(&mut wr, &self.program_ids, Transaction::serialize_pubkey) 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)?; .map_err(Error::custom)?;
let mut buf = [0; size_of::<Hash>()]; let mut buf = [0; size_of::<Hash>()];
rd.read_exact(&mut buf).map_err(Error::custom)?; 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::<LittleEndian>().map_err(Error::custom)?; let fee = rd.read_u64::<LittleEndian>().map_err(Error::custom)?;
let program_ids: Vec<Pubkey> = let program_ids: Vec<Pubkey> =
deserialize_vec_with(&mut rd, Transaction::deserialize_pubkey) deserialize_vec_with(&mut rd, Transaction::deserialize_pubkey)
@ -375,7 +375,7 @@ impl<'a> serde::de::Visitor<'a> for TransactionVisitor {
Ok(Transaction { Ok(Transaction {
signatures, signatures,
account_keys, account_keys,
last_id, recent_block_hash,
fee, fee,
program_ids, program_ids,
instructions, instructions,

View File

@ -91,7 +91,7 @@ impl TransactionBuilder {
} }
/// Return a signed transaction. /// Return a signed transaction.
pub fn sign<T: KeypairUtil>(&self, keypairs: &[&T], last_id: Hash) -> Transaction { pub fn sign<T: KeypairUtil>(&self, keypairs: &[&T], recent_block_hash: Hash) -> Transaction {
let program_ids = self.program_ids(); let program_ids = self.program_ids();
let (mut signed_keys, unsigned_keys) = self.keys(); let (mut signed_keys, unsigned_keys) = self.keys();
for (i, keypair) in keypairs.iter().enumerate() { for (i, keypair) in keypairs.iter().enumerate() {
@ -104,7 +104,7 @@ impl TransactionBuilder {
Transaction::new_with_instructions( Transaction::new_with_instructions(
keypairs, keypairs,
&unsigned_keys, &unsigned_keys,
last_id, recent_block_hash,
self.fee, self.fee,
program_ids, program_ids,
instructions, instructions,

View File

@ -16,20 +16,20 @@ impl VoteTransaction {
pub fn new_vote<T: KeypairUtil>( pub fn new_vote<T: KeypairUtil>(
voting_keypair: &T, voting_keypair: &T,
slot_height: u64, slot_height: u64,
last_id: Hash, recent_block_hash: Hash,
fee: u64, fee: u64,
) -> Transaction { ) -> Transaction {
let vote = Vote { slot_height }; let vote = Vote { slot_height };
TransactionBuilder::new(fee) TransactionBuilder::new(fee)
.push(VoteInstruction::new_vote(voting_keypair.pubkey(), vote)) .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 /// Fund or create the staking account with tokens
pub fn fund_staking_account( pub fn fund_staking_account(
from_keypair: &Keypair, from_keypair: &Keypair,
vote_account_id: Pubkey, vote_account_id: Pubkey,
last_id: Hash, recent_block_hash: Hash,
num_tokens: u64, num_tokens: u64,
fee: u64, fee: u64,
) -> Transaction { ) -> Transaction {
@ -41,7 +41,7 @@ impl VoteTransaction {
Transaction::new_with_instructions( Transaction::new_with_instructions(
&[from_keypair], &[from_keypair],
&[vote_account_id], &[vote_account_id],
last_id, recent_block_hash,
fee, fee,
vec![system_program::id(), vote_program::id()], vec![system_program::id(), vote_program::id()],
vec![ vec![
@ -54,7 +54,7 @@ impl VoteTransaction {
/// Choose a node id to `delegate` or `assign` this vote account to /// Choose a node id to `delegate` or `assign` this vote account to
pub fn delegate_vote_account<T: KeypairUtil>( pub fn delegate_vote_account<T: KeypairUtil>(
vote_keypair: &T, vote_keypair: &T,
last_id: Hash, recent_block_hash: Hash,
node_id: Pubkey, node_id: Pubkey,
fee: u64, fee: u64,
) -> Transaction { ) -> Transaction {
@ -63,7 +63,7 @@ impl VoteTransaction {
vote_keypair.pubkey(), vote_keypair.pubkey(),
node_id, 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)> { 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(); let instruction = deserialize(&tx.userdata(ix_index)).unwrap();
if let VoteInstruction::Vote(vote) = instruction { 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 { } else {
None None
} }
@ -93,11 +93,11 @@ mod tests {
fn test_get_votes() { fn test_get_votes() {
let keypair = Keypair::new(); let keypair = Keypair::new();
let slot_height = 1; let slot_height = 1;
let last_id = Hash::default(); let recent_block_hash = Hash::default();
let transaction = VoteTransaction::new_vote(&keypair, slot_height, last_id, 0); let transaction = VoteTransaction::new_vote(&keypair, slot_height, recent_block_hash, 0);
assert_eq!( assert_eq!(
VoteTransaction::get_votes(&transaction), VoteTransaction::get_votes(&transaction),
vec![(keypair.pubkey(), Vote::new(slot_height), last_id)] vec![(keypair.pubkey(), Vote::new(slot_height), recent_block_hash)]
); );
} }
} }

View File

@ -900,7 +900,8 @@ fn send_and_confirm_transactions(
send_retries -= 1; send_retries -= 1;
// Re-sign any failed transactions with a new last_id and retry // 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 transactions = transactions_signatures
.into_iter() .into_iter()
.map(|(mut transaction, _)| { .map(|(mut transaction, _)| {
@ -916,7 +917,7 @@ fn resign_transaction(
tx: &mut Transaction, tx: &mut Transaction,
signer_key: &Keypair, signer_key: &Keypair,
) -> Result<(), Box<dyn error::Error>> { ) -> Result<(), Box<dyn error::Error>> {
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); tx.sign(&[signer_key], last_id);
Ok(()) Ok(())
} }
@ -1596,7 +1597,7 @@ mod tests {
assert_ne!(prev_tx, tx); assert_ne!(prev_tx, tx);
assert_ne!(prev_tx.signatures, tx.signatures); 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.fee, tx.fee);
assert_eq!(prev_tx.account_keys, tx.account_keys); assert_eq!(prev_tx.account_keys, tx.account_keys);
assert_eq!(prev_tx.instructions, tx.instructions); assert_eq!(prev_tx.instructions, tx.instructions);