Skip to content

Commit

Permalink
system_instruction_processor updates (solana-labs#6448)
Browse files Browse the repository at this point in the history
* zero lamport account creation

* whack create_user_account, take 2

* target->to

* ..

* ..

* update chacha golden

* update chacha golden

* ..

* ..
  • Loading branch information
rob-solana authored Oct 20, 2019
1 parent 74ee88d commit e2c316d
Show file tree
Hide file tree
Showing 28 changed files with 377 additions and 255 deletions.
2 changes: 1 addition & 1 deletion bench-tps/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ fn generate_system_txs(
.par_iter()
.map(|(from, to)| {
(
system_transaction::create_user_account(from, &to.pubkey(), 1, *blockhash),
system_transaction::transfer_now(from, &to.pubkey(), 1, *blockhash),
timestamp(),
)
})
Expand Down
8 changes: 4 additions & 4 deletions client/src/rpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ mod tests {
let key = Keypair::new();
let to = Pubkey::new_rand();
let blockhash = Hash::default();
let tx = system_transaction::create_user_account(&key, &to, 50, blockhash);
let tx = system_transaction::transfer_now(&key, &to, 50, blockhash);

let signature = rpc_client.send_transaction(&tx);
assert_eq!(signature.unwrap(), SIGNATURE.to_string());
Expand Down Expand Up @@ -900,7 +900,7 @@ mod tests {
let key = Keypair::new();
let to = Pubkey::new_rand();
let blockhash = Hash::default();
let mut tx = system_transaction::create_user_account(&key, &to, 50, blockhash);
let mut tx = system_transaction::transfer_now(&key, &to, 50, blockhash);

let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&key]);
result.unwrap();
Expand All @@ -923,8 +923,8 @@ mod tests {
let blockhash: Hash = "HUu3LwEzGRsUkuJS121jzkPJW39Kq62pXCTmTa1F9jDL"
.parse()
.unwrap();
let prev_tx = system_transaction::create_user_account(&key, &to, 50, blockhash);
let mut tx = system_transaction::create_user_account(&key, &to, 50, blockhash);
let prev_tx = system_transaction::transfer_now(&key, &to, 50, blockhash);
let mut tx = system_transaction::transfer_now(&key, &to, 50, blockhash);

rpc_client.resign_transaction(&mut tx, &[&key]).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion core/benches/poh_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn bench_poh_verify_transaction_entries(bencher: &mut Bencher) {

let mut ticks: Vec<Entry> = Vec::with_capacity(NUM_ENTRIES);
for _ in 0..NUM_ENTRIES {
let tx = system_transaction::create_user_account(&keypair1, &pubkey1, 42, cur_hash);
let tx = system_transaction::transfer_now(&keypair1, &pubkey1, 42, cur_hash);
ticks.push(next_entry_mut(&mut cur_hash, NUM_HASHES, vec![tx]));
}

Expand Down
20 changes: 8 additions & 12 deletions core/src/banking_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1095,26 +1095,22 @@ mod tests {

// fund another account so we can send 2 good transactions in a single batch.
let keypair = Keypair::new();
let fund_tx = system_transaction::create_user_account(
&mint_keypair,
&keypair.pubkey(),
2,
start_hash,
);
let fund_tx =
system_transaction::transfer_now(&mint_keypair, &keypair.pubkey(), 2, start_hash);
bank.process_transaction(&fund_tx).unwrap();

// good tx
let to = Pubkey::new_rand();
let tx = system_transaction::create_user_account(&mint_keypair, &to, 1, start_hash);
let tx = system_transaction::transfer_now(&mint_keypair, &to, 1, start_hash);

// good tx, but no verify
let to2 = Pubkey::new_rand();
let tx_no_ver = system_transaction::create_user_account(&keypair, &to2, 2, start_hash);
let tx_no_ver = system_transaction::transfer_now(&keypair, &to2, 2, start_hash);

// bad tx, AccountNotFound
let keypair = Keypair::new();
let to3 = Pubkey::new_rand();
let tx_anf = system_transaction::create_user_account(&keypair, &to3, 1, start_hash);
let tx_anf = system_transaction::transfer_now(&keypair, &to3, 1, start_hash);

// send 'em over
let packets = to_packets(&[tx_no_ver, tx_anf, tx]);
Expand Down Expand Up @@ -1190,7 +1186,7 @@ mod tests {

// Process a batch that includes a transaction that receives two lamports.
let alice = Keypair::new();
let tx = system_transaction::create_user_account(
let tx = system_transaction::transfer_now(
&mint_keypair,
&alice.pubkey(),
2,
Expand All @@ -1205,7 +1201,7 @@ mod tests {
verified_sender.send(packets).unwrap();

// Process a second batch that spends one of those lamports.
let tx = system_transaction::create_user_account(
let tx = system_transaction::transfer_now(
&alice,
&mint_keypair.pubkey(),
1,
Expand Down Expand Up @@ -1611,7 +1607,7 @@ mod tests {
let bank = Arc::new(Bank::new(&genesis_block));
let pubkey = Pubkey::new_rand();

let transactions = vec![system_transaction::create_user_account(
let transactions = vec![system_transaction::transfer_now(
&mint_keypair,
&pubkey,
1,
Expand Down
7 changes: 1 addition & 6 deletions core/src/blockstream_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,7 @@ mod test {

let keypair = Keypair::new();
let mut blockhash = entries[3].hash;
let tx = system_transaction::create_user_account(
&keypair,
&keypair.pubkey(),
1,
Hash::default(),
);
let tx = system_transaction::transfer_now(&keypair, &keypair.pubkey(), 1, Hash::default());
let entry = Entry::new(&mut blockhash, 1, vec![tx]);
blockhash = entry.hash;
entries.push(entry);
Expand Down
79 changes: 30 additions & 49 deletions core/src/blocktree_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ pub mod tests {
let bank = Arc::new(Bank::new(&genesis_block));
let keypair = Keypair::new();
let slot_entries = create_ticks(genesis_block.ticks_per_slot, genesis_block.hash());
let tx = system_transaction::create_user_account(
let tx = system_transaction::transfer_now(
&mint_keypair,
&keypair.pubkey(),
1,
Expand Down Expand Up @@ -869,25 +869,16 @@ pub mod tests {
for _ in 0..deducted_from_mint {
// Transfer one token from the mint to a random account
let keypair = Keypair::new();
let tx = system_transaction::create_user_account(
&mint_keypair,
&keypair.pubkey(),
1,
blockhash,
);
let tx =
system_transaction::transfer_now(&mint_keypair, &keypair.pubkey(), 1, blockhash);
let entry = Entry::new(&last_entry_hash, 1, vec![tx]);
last_entry_hash = entry.hash;
entries.push(entry);

// Add a second Transaction that will produce a
// InstructionError<0, ResultWithNegativeLamports> error when processed
let keypair2 = Keypair::new();
let tx = system_transaction::create_user_account(
&keypair,
&keypair2.pubkey(),
42,
blockhash,
);
let tx = system_transaction::transfer_now(&keypair, &keypair2.pubkey(), 42, blockhash);
let entry = Entry::new(&last_entry_hash, 1, vec![tx]);
last_entry_hash = entry.hash;
entries.push(entry);
Expand Down Expand Up @@ -996,20 +987,12 @@ pub mod tests {
let blockhash = genesis_block.hash();
let keypairs = [Keypair::new(), Keypair::new(), Keypair::new()];

let tx = system_transaction::create_user_account(
&mint_keypair,
&keypairs[0].pubkey(),
1,
blockhash,
);
let tx =
system_transaction::transfer_now(&mint_keypair, &keypairs[0].pubkey(), 1, blockhash);
let entry_1 = next_entry(&last_entry_hash, 1, vec![tx]);

let tx = system_transaction::create_user_account(
&mint_keypair,
&keypairs[1].pubkey(),
1,
blockhash,
);
let tx =
system_transaction::transfer_now(&mint_keypair, &keypairs[1].pubkey(), 1, blockhash);
let entry_2 = next_entry(&entry_1.hash, 1, vec![tx]);

let mut entries = vec![entry_1, entry_2];
Expand Down Expand Up @@ -1074,14 +1057,14 @@ pub mod tests {
let blockhash = bank.last_blockhash();

// ensure bank can process 2 entries that have a common account and no tick is registered
let tx = system_transaction::create_user_account(
let tx = system_transaction::transfer_now(
&mint_keypair,
&keypair1.pubkey(),
2,
bank.last_blockhash(),
);
let entry_1 = next_entry(&blockhash, 1, vec![tx]);
let tx = system_transaction::create_user_account(
let tx = system_transaction::transfer_now(
&mint_keypair,
&keypair2.pubkey(),
2,
Expand Down Expand Up @@ -1114,7 +1097,7 @@ pub mod tests {
let entry_1_to_mint = next_entry(
&bank.last_blockhash(),
1,
vec![system_transaction::create_user_account(
vec![system_transaction::transfer_now(
&keypair1,
&mint_keypair.pubkey(),
1,
Expand All @@ -1126,13 +1109,13 @@ pub mod tests {
&entry_1_to_mint.hash,
1,
vec![
system_transaction::create_user_account(
system_transaction::transfer_now(
&keypair2,
&keypair3.pubkey(),
2,
bank.last_blockhash(),
), // should be fine
system_transaction::create_user_account(
system_transaction::transfer_now(
&keypair1,
&mint_keypair.pubkey(),
2,
Expand Down Expand Up @@ -1174,7 +1157,7 @@ pub mod tests {
&bank.last_blockhash(),
1,
vec![
system_transaction::create_user_account(
system_transaction::transfer_now(
&keypair1,
&mint_keypair.pubkey(),
1,
Expand All @@ -1193,13 +1176,13 @@ pub mod tests {
&entry_1_to_mint.hash,
1,
vec![
system_transaction::create_user_account(
system_transaction::transfer_now(
&keypair2,
&keypair3.pubkey(),
2,
bank.last_blockhash(),
), // should be fine
system_transaction::create_user_account(
system_transaction::transfer_now(
&keypair1,
&mint_keypair.pubkey(),
2,
Expand Down Expand Up @@ -1272,7 +1255,7 @@ pub mod tests {
&entry_1_to_mint.hash,
1,
vec![
system_transaction::create_user_account(
system_transaction::transfer_now(
&keypair2,
&keypair3.pubkey(),
2,
Expand Down Expand Up @@ -1345,14 +1328,14 @@ pub mod tests {
let keypair4 = Keypair::new();

//load accounts
let tx = system_transaction::create_user_account(
let tx = system_transaction::transfer_now(
&mint_keypair,
&keypair1.pubkey(),
1,
bank.last_blockhash(),
);
assert_eq!(bank.process_transaction(&tx), Ok(()));
let tx = system_transaction::create_user_account(
let tx = system_transaction::transfer_now(
&mint_keypair,
&keypair2.pubkey(),
1,
Expand All @@ -1362,14 +1345,14 @@ pub mod tests {

// ensure bank can process 2 entries that do not have a common account and no tick is registered
let blockhash = bank.last_blockhash();
let tx = system_transaction::create_user_account(
let tx = system_transaction::transfer_now(
&keypair1,
&keypair3.pubkey(),
1,
bank.last_blockhash(),
);
let entry_1 = next_entry(&blockhash, 1, vec![tx]);
let tx = system_transaction::create_user_account(
let tx = system_transaction::transfer_now(
&keypair2,
&keypair4.pubkey(),
1,
Expand Down Expand Up @@ -1455,7 +1438,7 @@ pub mod tests {

for _ in 0..num_accounts {
let keypair = Keypair::new();
let create_account_tx = system_transaction::create_user_account(
let create_account_tx = system_transaction::transfer_now(
&mint_keypair,
&keypair.pubkey(),
0,
Expand Down Expand Up @@ -1523,14 +1506,14 @@ pub mod tests {
let keypair4 = Keypair::new();

//load accounts
let tx = system_transaction::create_user_account(
let tx = system_transaction::transfer_now(
&mint_keypair,
&keypair1.pubkey(),
1,
bank.last_blockhash(),
);
assert_eq!(bank.process_transaction(&tx), Ok(()));
let tx = system_transaction::create_user_account(
let tx = system_transaction::transfer_now(
&mint_keypair,
&keypair2.pubkey(),
1,
Expand All @@ -1544,11 +1527,10 @@ pub mod tests {
}

// ensure bank can process 2 entries that do not have a common account and tick is registered
let tx =
system_transaction::create_user_account(&keypair2, &keypair3.pubkey(), 1, blockhash);
let tx = system_transaction::transfer_now(&keypair2, &keypair3.pubkey(), 1, blockhash);
let entry_1 = next_entry(&blockhash, 1, vec![tx]);
let tick = next_entry(&entry_1.hash, 1, vec![]);
let tx = system_transaction::create_user_account(
let tx = system_transaction::transfer_now(
&keypair1,
&keypair4.pubkey(),
1,
Expand All @@ -1567,7 +1549,7 @@ pub mod tests {
assert_eq!(bank.get_balance(&keypair4.pubkey()), 1);

// ensure that an error is returned for an empty account (keypair2)
let tx = system_transaction::create_user_account(
let tx = system_transaction::transfer_now(
&keypair2,
&keypair3.pubkey(),
1,
Expand Down Expand Up @@ -1606,8 +1588,7 @@ pub mod tests {
);

// Make sure other errors don't update the signature cache
let tx =
system_transaction::create_user_account(&mint_keypair, &pubkey, 1000, Hash::default());
let tx = system_transaction::transfer_now(&mint_keypair, &pubkey, 1000, Hash::default());
let signature = tx.signatures[0];

// Should fail with blockhash not found
Expand All @@ -1633,13 +1614,13 @@ pub mod tests {
let bank = Arc::new(Bank::new(&genesis_block));
let keypair1 = Keypair::new();
let keypair2 = Keypair::new();
let success_tx = system_transaction::create_user_account(
let success_tx = system_transaction::transfer_now(
&mint_keypair,
&keypair1.pubkey(),
1,
bank.last_blockhash(),
);
let fail_tx = system_transaction::create_user_account(
let fail_tx = system_transaction::transfer_now(
&mint_keypair,
&keypair2.pubkey(),
2,
Expand Down
2 changes: 1 addition & 1 deletion core/src/broadcast_stage/broadcast_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ mod tests {
..
} = create_genesis_block(2);
let bank0 = Arc::new(Bank::new(&genesis_block));
let tx = system_transaction::create_user_account(
let tx = system_transaction::transfer_now(
&mint_keypair,
&Pubkey::new_rand(),
1,
Expand Down
Loading

0 comments on commit e2c316d

Please sign in to comment.