Remove blockhash parameter from Bank::transfer

That parameter is an artifact from the Loom days, when I thought
Bank should implement the same interace as ThinClient.
This commit is contained in:
Greg Fitzgerald 2019-03-27 05:59:30 -06:00
parent 0ac865f08c
commit cecdb7061e
5 changed files with 21 additions and 47 deletions

View File

@ -568,14 +568,8 @@ mod tests {
let keypair3 = Keypair::new(); let keypair3 = Keypair::new();
// fund: put 4 in each of 1 and 2 // fund: put 4 in each of 1 and 2
assert_matches!( assert_matches!(bank.transfer(4, &mint_keypair, &keypair1.pubkey()), Ok(_));
bank.transfer(4, &mint_keypair, &keypair1.pubkey(), bank.last_blockhash()), assert_matches!(bank.transfer(4, &mint_keypair, &keypair2.pubkey()), Ok(_));
Ok(_)
);
assert_matches!(
bank.transfer(4, &mint_keypair, &keypair2.pubkey(), bank.last_blockhash()),
Ok(_)
);
// construct an Entry whose 2nd transaction would cause a lock conflict with previous entry // construct an Entry whose 2nd transaction would cause a lock conflict with previous entry
let entry_1_to_mint = next_entry( let entry_1_to_mint = next_entry(

View File

@ -144,8 +144,6 @@ mod tests {
bank = Arc::new(Bank::new_from_parent(&bank, &Pubkey::default(), slot)); bank = Arc::new(Bank::new_from_parent(&bank, &Pubkey::default(), slot));
} }
let blockhash = bank.last_blockhash();
// Create a total of 10 vote accounts, each will have a balance of 1 (after giving 1 to // Create a total of 10 vote accounts, each will have a balance of 1 (after giving 1 to
// their vote account), for a total staking pool of 10 lamports. // their vote account), for a total staking pool of 10 lamports.
let vote_accounts: Vec<_> = (0..10) let vote_accounts: Vec<_> = (0..10)
@ -156,7 +154,7 @@ mod tests {
let voting_pubkey = voting_keypair.pubkey(); let voting_pubkey = voting_keypair.pubkey();
// Give the validator some lamports // Give the validator some lamports
bank.transfer(2, &mint_keypair, &validator_keypair.pubkey(), blockhash) bank.transfer(2, &mint_keypair, &validator_keypair.pubkey())
.unwrap(); .unwrap();
new_vote_account(&validator_keypair, &voting_pubkey, &bank, 1); new_vote_account(&validator_keypair, &voting_pubkey, &bank, 1);
@ -177,6 +175,7 @@ mod tests {
assert_eq!(last_confirmation_time, 0); assert_eq!(last_confirmation_time, 0);
// Get another validator to vote, so we now have 2/3 consensus // Get another validator to vote, so we now have 2/3 consensus
let blockhash = bank.last_blockhash();
let voting_keypair = &vote_accounts[7].0; let voting_keypair = &vote_accounts[7].0;
let vote = Vote::new(MAX_RECENT_BLOCKHASHES as u64); let vote = Vote::new(MAX_RECENT_BLOCKHASHES as u64);
let vote_ix = VoteInstruction::new_vote(&voting_keypair.pubkey(), vote); let vote_ix = VoteInstruction::new_vote(&voting_keypair.pubkey(), vote);

View File

@ -193,7 +193,7 @@ mod tests {
// Give the validator some stake but don't setup a staking account // Give the validator some stake but don't setup a staking account
// Validator has no lamports staked, so they get filtered out. Only the bootstrap leader // Validator has no lamports staked, so they get filtered out. Only the bootstrap leader
// created by the genesis block will get included // created by the genesis block will get included
bank.transfer(1, &mint_keypair, &validator.pubkey(), genesis_block.hash()) bank.transfer(1, &mint_keypair, &validator.pubkey())
.unwrap(); .unwrap();
// Make a mint vote account. Because the mint has nonzero stake, this // Make a mint vote account. Because the mint has nonzero stake, this

View File

@ -142,8 +142,7 @@ mod tests {
let (bank, mint_keypair) = create_bank(10_000); let (bank, mint_keypair) = create_bank(10_000);
let system_keypair = Keypair::new(); let system_keypair = Keypair::new();
let system_pubkey = system_keypair.pubkey(); let system_pubkey = system_keypair.pubkey();
bank.transfer(42, &mint_keypair, &system_pubkey, bank.last_blockhash()) bank.transfer(42, &mint_keypair, &system_pubkey).unwrap();
.unwrap();
let (_config_client, from_pubkey, config_pubkey) = let (_config_client, from_pubkey, config_pubkey) =
create_config_client(&bank, mint_keypair); create_config_client(&bank, mint_keypair);

View File

@ -719,13 +719,8 @@ impl Bank {
/// Create, sign, and process a Transaction from `keypair` to `to` of /// Create, sign, and process a Transaction from `keypair` to `to` of
/// `n` lamports where `blockhash` is the last Entry ID observed by the client. /// `n` lamports where `blockhash` is the last Entry ID observed by the client.
pub fn transfer( pub fn transfer(&self, n: u64, keypair: &Keypair, to: &Pubkey) -> Result<Signature> {
&self, let blockhash = self.last_blockhash();
n: u64,
keypair: &Keypair,
to: &Pubkey,
blockhash: Hash,
) -> Result<Signature> {
let tx = SystemTransaction::new_account(keypair, to, n, blockhash, 0); let tx = SystemTransaction::new_account(keypair, to, n, blockhash, 0);
let signature = tx.signatures[0]; let signature = tx.signatures[0];
self.process_transaction(&tx).map(|_| signature) self.process_transaction(&tx).map(|_| signature)
@ -967,12 +962,10 @@ mod tests {
let bank = Bank::new(&genesis_block); let bank = Bank::new(&genesis_block);
assert_eq!(bank.last_blockhash(), genesis_block.hash()); assert_eq!(bank.last_blockhash(), genesis_block.hash());
bank.transfer(1_000, &mint_keypair, &pubkey, genesis_block.hash()) bank.transfer(1_000, &mint_keypair, &pubkey).unwrap();
.unwrap();
assert_eq!(bank.get_balance(&pubkey), 1_000); assert_eq!(bank.get_balance(&pubkey), 1_000);
bank.transfer(500, &mint_keypair, &pubkey, genesis_block.hash()) bank.transfer(500, &mint_keypair, &pubkey).unwrap();
.unwrap();
assert_eq!(bank.get_balance(&pubkey), 1_500); assert_eq!(bank.get_balance(&pubkey), 1_500);
assert_eq!(bank.transaction_count(), 2); assert_eq!(bank.transaction_count(), 2);
} }
@ -1087,7 +1080,7 @@ mod tests {
let bank = Bank::new(&genesis_block); let bank = Bank::new(&genesis_block);
let keypair = Keypair::new(); let keypair = Keypair::new();
assert_eq!( assert_eq!(
bank.transfer(1, &keypair, &mint_keypair.pubkey(), genesis_block.hash()), bank.transfer(1, &keypair, &mint_keypair.pubkey()),
Err(TransactionError::AccountNotFound) Err(TransactionError::AccountNotFound)
); );
assert_eq!(bank.transaction_count(), 0); assert_eq!(bank.transaction_count(), 0);
@ -1098,12 +1091,11 @@ mod tests {
let (genesis_block, mint_keypair) = GenesisBlock::new(11_000); let (genesis_block, mint_keypair) = GenesisBlock::new(11_000);
let bank = Bank::new(&genesis_block); let bank = Bank::new(&genesis_block);
let pubkey = Keypair::new().pubkey(); let pubkey = Keypair::new().pubkey();
bank.transfer(1_000, &mint_keypair, &pubkey, genesis_block.hash()) bank.transfer(1_000, &mint_keypair, &pubkey).unwrap();
.unwrap();
assert_eq!(bank.transaction_count(), 1); assert_eq!(bank.transaction_count(), 1);
assert_eq!(bank.get_balance(&pubkey), 1_000); assert_eq!(bank.get_balance(&pubkey), 1_000);
assert_eq!( assert_eq!(
bank.transfer(10_001, &mint_keypair, &pubkey, genesis_block.hash()), bank.transfer(10_001, &mint_keypair, &pubkey),
Err(TransactionError::InstructionError( Err(TransactionError::InstructionError(
0, 0,
InstructionError::new_result_with_negative_lamports(), InstructionError::new_result_with_negative_lamports(),
@ -1121,8 +1113,7 @@ mod tests {
let (genesis_block, mint_keypair) = GenesisBlock::new(10_000); let (genesis_block, mint_keypair) = GenesisBlock::new(10_000);
let bank = Bank::new(&genesis_block); let bank = Bank::new(&genesis_block);
let pubkey = Keypair::new().pubkey(); let pubkey = Keypair::new().pubkey();
bank.transfer(500, &mint_keypair, &pubkey, genesis_block.hash()) bank.transfer(500, &mint_keypair, &pubkey).unwrap();
.unwrap();
assert_eq!(bank.get_balance(&pubkey), 500); assert_eq!(bank.get_balance(&pubkey), 500);
} }
@ -1282,21 +1273,19 @@ mod tests {
// try executing an interleaved transfer twice // try executing an interleaved transfer twice
assert_eq!( assert_eq!(
bank.transfer(1, &mint_keypair, &bob.pubkey(), genesis_block.hash()), bank.transfer(1, &mint_keypair, &bob.pubkey()),
Err(TransactionError::AccountInUse) Err(TransactionError::AccountInUse)
); );
// the second time should fail as well // the second time should fail as well
// this verifies that `unlock_accounts` doesn't unlock `AccountInUse` accounts // this verifies that `unlock_accounts` doesn't unlock `AccountInUse` accounts
assert_eq!( assert_eq!(
bank.transfer(1, &mint_keypair, &bob.pubkey(), genesis_block.hash()), bank.transfer(1, &mint_keypair, &bob.pubkey()),
Err(TransactionError::AccountInUse) Err(TransactionError::AccountInUse)
); );
bank.unlock_accounts(&pay_alice, &results_alice); bank.unlock_accounts(&pay_alice, &results_alice);
assert!(bank assert!(bank.transfer(2, &mint_keypair, &bob.pubkey()).is_ok());
.transfer(2, &mint_keypair, &bob.pubkey(), genesis_block.hash())
.is_ok());
} }
#[test] #[test]
@ -1334,8 +1323,7 @@ mod tests {
let key1 = Keypair::new(); let key1 = Keypair::new();
let bank = Bank::new(&genesis_block); let bank = Bank::new(&genesis_block);
bank.transfer(1, &mint_keypair, &key1.pubkey(), genesis_block.hash()) bank.transfer(1, &mint_keypair, &key1.pubkey()).unwrap();
.unwrap();
assert_eq!(bank.get_balance(&key1.pubkey()), 1); assert_eq!(bank.get_balance(&key1.pubkey()), 1);
let tx = SystemTransaction::new_move(&key1, &key1.pubkey(), 1, genesis_block.hash(), 0); let tx = SystemTransaction::new_move(&key1, &key1.pubkey(), 1, genesis_block.hash(), 0);
let res = bank.process_transactions(&vec![tx.clone()]); let res = bank.process_transactions(&vec![tx.clone()]);
@ -1407,13 +1395,9 @@ mod tests {
assert_eq!(bank1.hash_internal_state(), initial_state); assert_eq!(bank1.hash_internal_state(), initial_state);
let pubkey = Keypair::new().pubkey(); let pubkey = Keypair::new().pubkey();
bank0 bank0.transfer(1_000, &mint_keypair, &pubkey).unwrap();
.transfer(1_000, &mint_keypair, &pubkey, bank0.last_blockhash())
.unwrap();
assert_ne!(bank0.hash_internal_state(), initial_state); assert_ne!(bank0.hash_internal_state(), initial_state);
bank1 bank1.transfer(1_000, &mint_keypair, &pubkey).unwrap();
.transfer(1_000, &mint_keypair, &pubkey, bank1.last_blockhash())
.unwrap();
assert_eq!(bank0.hash_internal_state(), bank1.hash_internal_state()); assert_eq!(bank0.hash_internal_state(), bank1.hash_internal_state());
// Checkpointing should not change its state // Checkpointing should not change its state
@ -1499,9 +1483,7 @@ mod tests {
let key1 = Keypair::new(); let key1 = Keypair::new();
parent parent.transfer(1, &mint_keypair, &key1.pubkey()).unwrap();
.transfer(1, &mint_keypair, &key1.pubkey(), genesis_block.hash())
.unwrap();
assert_eq!(parent.get_balance(&key1.pubkey()), 1); assert_eq!(parent.get_balance(&key1.pubkey()), 1);
let bank = new_from_parent(&parent); let bank = new_from_parent(&parent);
bank.squash(); bank.squash();