system_instruction_processor updates (#6448)

* zero lamport account creation

* whack create_user_account, take 2

* target->to

* ..

* ..

* update chacha golden

* update chacha golden

* ..

* ..
This commit is contained in:
Rob Walker
2019-10-19 18:23:27 -07:00
committed by GitHub
parent 74ee88d9bc
commit e2c316d2d0
28 changed files with 377 additions and 255 deletions

View File

@ -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]);
@ -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,
@ -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,
@ -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,

View File

@ -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);

View File

@ -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,
@ -869,12 +869,8 @@ 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);
@ -882,12 +878,7 @@ pub mod tests {
// 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);
@ -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];
@ -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,
@ -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,
@ -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,
@ -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,
@ -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,
@ -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,
@ -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,
@ -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,
@ -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,
@ -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,
@ -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,
@ -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,
@ -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
@ -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,

View File

@ -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,

View File

@ -78,12 +78,12 @@ mod tests {
use solana_ledger::blocktree::Blocktree;
use solana_ledger::entry::Entry;
use solana_sdk::hash::{hash, Hash, Hasher};
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::KeypairUtil;
use solana_sdk::system_transaction;
use std::fs::remove_file;
use std::fs::File;
use std::io::Read;
use std::path::Path;
use std::sync::Arc;
fn make_tiny_deterministic_test_entries(num: usize) -> Vec<Entry> {
@ -101,7 +101,7 @@ mod tests {
Entry::new_mut(
&mut id,
&mut num_hashes,
vec![system_transaction::create_user_account(
vec![system_transaction::transfer_now(
&keypair,
&keypair.pubkey(),
1,
@ -112,6 +112,18 @@ mod tests {
.collect()
}
use std::{env, fs::create_dir_all, path::PathBuf};
fn tmp_file_path(name: &str) -> PathBuf {
let out_dir = env::var("FARF_DIR").unwrap_or_else(|_| "farf".to_string());
let mut path = PathBuf::new();
path.push(out_dir);
path.push("tmp");
create_dir_all(&path).unwrap();
path.push(format!("{}-{}", name, Pubkey::new_rand()));
path
}
#[test]
fn test_encrypt_ledger() {
solana_logger::setup();
@ -120,7 +132,7 @@ mod tests {
let ticks_per_slot = 16;
let slots_per_segment = 32;
let blocktree = Arc::new(Blocktree::open(&ledger_path).unwrap());
let out_path = Path::new("test_chacha_encrypt_file_output.txt.enc");
let out_path = tmp_file_path("test_encrypt_ledger");
let seed = [2u8; 32];
let mut rnd = GenKeys::new(seed);
@ -144,20 +156,20 @@ mod tests {
"abcd1234abcd1234abcd1234abcd1234 abcd1234abcd1234abcd1234abcd1234
abcd1234abcd1234abcd1234abcd1234 abcd1234abcd1234abcd1234abcd1234"
);
chacha_cbc_encrypt_ledger(&blocktree, 0, slots_per_segment as u64, out_path, &mut key)
chacha_cbc_encrypt_ledger(&blocktree, 0, slots_per_segment as u64, &out_path, &mut key)
.unwrap();
let mut out_file = File::open(out_path).unwrap();
let mut out_file = File::open(&out_path).unwrap();
let mut buf = vec![];
let size = out_file.read_to_end(&mut buf).unwrap();
let mut hasher = Hasher::default();
hasher.hash(&buf[..size]);
// golden needs to be updated if blob stuff changes....
let golden: Hash = "F3Grk43JpRUPeCuB8CbYovjxq2Bh77bh4uLB2UXKBFN8"
let golden: Hash = "BdmY3efqu7zbnFuGRAeFANwa35HkDdQ7hwhYez3xGXiM"
.parse()
.unwrap();
assert_eq!(hasher.result(), golden);
remove_file(out_path).unwrap();
remove_file(&out_path).unwrap();
}
}

View File

@ -602,7 +602,7 @@ mod tests {
fn test_to_packets() {
let keypair = Keypair::new();
let hash = Hash::new(&[1; 32]);
let tx = system_transaction::create_user_account(&keypair, &keypair.pubkey(), 1, hash);
let tx = system_transaction::transfer_now(&keypair, &keypair.pubkey(), 1, hash);
let rv = to_packets(&vec![tx.clone(); 1]);
assert_eq!(rv.len(), 1);
assert_eq!(rv[0].packets.len(), 1);

View File

@ -952,12 +952,7 @@ mod test {
blockhash,
1,
vec![
system_transaction::create_user_account(
&keypair1,
&keypair2.pubkey(),
2,
*blockhash,
), // should be fine,
system_transaction::transfer_now(&keypair1, &keypair2.pubkey(), 2, *blockhash), // should be fine,
system_transaction::transfer(
&missing_keypair,
&missing_keypair2.pubkey(),
@ -985,7 +980,7 @@ mod test {
// User wrong blockhash so that the entry causes an entry verification failure
&bad_hash,
1,
vec![system_transaction::create_user_account(
vec![system_transaction::transfer_now(
&keypair1,
&keypair2.pubkey(),
2,

View File

@ -391,12 +391,7 @@ mod tests {
None,
);
let tx = system_transaction::create_user_account(
&alice,
&contract_funds.pubkey(),
51,
blockhash,
);
let tx = system_transaction::transfer_now(&alice, &contract_funds.pubkey(), 51, blockhash);
process_transaction_and_notify(&bank_forks, &tx, &rpc.subscriptions).unwrap();
let ixs = budget_instruction::when_signed(
@ -440,7 +435,7 @@ mod tests {
assert_eq!(serde_json::to_string(&expected).unwrap(), response);
}
let tx = system_transaction::create_user_account(&alice, &witness.pubkey(), 1, blockhash);
let tx = system_transaction::transfer_now(&alice, &witness.pubkey(), 1, blockhash);
process_transaction_and_notify(&bank_forks, &tx, &rpc.subscriptions).unwrap();
sleep(Duration::from_millis(200));
let ix = budget_instruction::apply_signature(

View File

@ -10,7 +10,7 @@ pub fn test_tx() -> Transaction {
let keypair1 = Keypair::new();
let pubkey1 = keypair1.pubkey();
let zero = Hash::default();
system_transaction::create_user_account(&keypair1, &pubkey1, 42, zero)
system_transaction::transfer_now(&keypair1, &pubkey1, 42, zero)
}
pub fn test_multisig_tx() -> Transaction {