Skip to content

Commit

Permalink
require to account signature (solana-labs#6658)
Browse files Browse the repository at this point in the history
* require to signature

* fixing invocation to create_account

* fix create_account references

* address review comment

* whacking bugs in tests

* fixing stake program tests
  • Loading branch information
ParthDesai authored Nov 8, 2019
1 parent f7b6e77 commit 5bd05fb
Show file tree
Hide file tree
Showing 29 changed files with 277 additions and 153 deletions.
78 changes: 53 additions & 25 deletions bench-exchange/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,28 @@ where

info!("Generating {:?} account keys", total_keys);
let mut account_keypairs = generate_keypairs(total_keys);
let src_pubkeys: Vec<_> = account_keypairs
let src_keypairs: Vec<_> = account_keypairs
.drain(0..accounts_in_groups)
.map(|keypair| keypair)
.collect();
let src_pubkeys: Vec<Pubkey> = src_keypairs
.iter()
.map(|keypair| keypair.pubkey())
.collect();
let profit_pubkeys: Vec<_> = account_keypairs

let profit_keypairs: Vec<_> = account_keypairs
.drain(0..accounts_in_groups)
.map(|keypair| keypair)
.collect();
let profit_pubkeys: Vec<Pubkey> = profit_keypairs
.iter()
.map(|keypair| keypair.pubkey())
.collect();

info!("Create {:?} source token accounts", src_pubkeys.len());
create_token_accounts(client, &trader_signers, &src_pubkeys);
create_token_accounts(client, &trader_signers, &src_keypairs);
info!("Create {:?} profit token accounts", profit_pubkeys.len());
create_token_accounts(client, &swapper_signers, &profit_pubkeys);
create_token_accounts(client, &swapper_signers, &profit_keypairs);

// Collect the max transaction rate and total tx count seen (single node only)
let sample_stats = Arc::new(RwLock::new(Vec::new()));
Expand Down Expand Up @@ -564,7 +573,7 @@ fn trader<T>(
trade_account: trade.pubkey(),
order_info,
});
trades.push((signer, trade.pubkey(), side, src));
trades.push((signer, trade, side, src));
}
account_group = (account_group + 1) % account_groups as usize;

Expand All @@ -575,16 +584,28 @@ fn trader<T>(
trades.chunks(chunk_size).for_each(|chunk| {
let trades_txs: Vec<_> = chunk
.par_iter()
.map(|(signer, trade, side, src)| {
let s: &Keypair = &signer;
let owner = &signer.pubkey();
.map(|(owner, trade, side, src)| {
let owner_pubkey = &owner.pubkey();
let trade_pubkey = &trade.pubkey();
let space = mem::size_of::<ExchangeState>() as u64;
Transaction::new_signed_instructions(
&[s],
&[owner.as_ref(), trade],
vec![
system_instruction::create_account(owner, trade, 1, space, &id()),
system_instruction::create_account(
owner_pubkey,
trade_pubkey,
1,
space,
&id(),
),
exchange_instruction::trade_request(
owner, trade, *side, pair, tokens, price, src,
owner_pubkey,
trade_pubkey,
*side,
pair,
tokens,
price,
src,
),
],
blockhash,
Expand Down Expand Up @@ -803,21 +824,27 @@ pub fn fund_keys(client: &dyn Client, source: &Keypair, dests: &[Arc<Keypair>],
}
}

pub fn create_token_accounts(client: &dyn Client, signers: &[Arc<Keypair>], accounts: &[Pubkey]) {
let mut notfunded: Vec<(&Arc<Keypair>, &Pubkey)> = signers.iter().zip(accounts).collect();
pub fn create_token_accounts(client: &dyn Client, signers: &[Arc<Keypair>], accounts: &[Keypair]) {
let mut notfunded: Vec<(&Arc<Keypair>, &Keypair)> = signers.iter().zip(accounts).collect();

while !notfunded.is_empty() {
notfunded.chunks(FUND_CHUNK_LEN).for_each(|chunk| {
let mut to_create_txs: Vec<_> = chunk
.par_iter()
.map(|(signer, new)| {
let owner_pubkey = &signer.pubkey();
.map(|(from_keypair, new_keypair)| {
let owner_pubkey = &from_keypair.pubkey();
let space = mem::size_of::<ExchangeState>() as u64;
let create_ix =
system_instruction::create_account(owner_pubkey, new, 1, space, &id());
let request_ix = exchange_instruction::account_request(owner_pubkey, new);
let create_ix = system_instruction::create_account(
owner_pubkey,
&new_keypair.pubkey(),
1,
space,
&id(),
);
let request_ix =
exchange_instruction::account_request(owner_pubkey, &new_keypair.pubkey());
(
signer,
(from_keypair, new_keypair),
Transaction::new_unsigned_instructions(vec![create_ix, request_ix]),
)
})
Expand All @@ -838,10 +865,11 @@ pub fn create_token_accounts(client: &dyn Client, signers: &[Arc<Keypair>], acco
let (blockhash, _fee_calculator) = client
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
.expect("Failed to get blockhash");
to_create_txs.par_iter_mut().for_each(|(k, tx)| {
let kp: &Keypair = k;
tx.sign(&[kp], blockhash);
});
to_create_txs
.par_iter_mut()
.for_each(|((from_keypair, to_keypair), tx)| {
tx.sign(&[from_keypair.as_ref(), to_keypair], blockhash);
});
to_create_txs.iter().for_each(|(_, tx)| {
client.async_send_transaction(tx.clone()).expect("transfer");
});
Expand Down Expand Up @@ -878,10 +906,10 @@ pub fn create_token_accounts(client: &dyn Client, signers: &[Arc<Keypair>], acco
}
});

let mut new_notfunded: Vec<(&Arc<Keypair>, &Pubkey)> = vec![];
let mut new_notfunded: Vec<(&Arc<Keypair>, &Keypair)> = vec![];
for f in &notfunded {
if client
.get_balance_with_commitment(&f.1, CommitmentConfig::recent())
.get_balance_with_commitment(&f.1.pubkey(), CommitmentConfig::recent())
.unwrap_or(0)
== 0
{
Expand Down
20 changes: 8 additions & 12 deletions bench-tps/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,13 +795,10 @@ fn fund_move_keys<T: Client>(

info!("creating the libra funding account..");
let libra_funding_key = Keypair::new();
let tx = librapay_transaction::create_account(
funding_key,
&libra_funding_key.pubkey(),
1,
blockhash,
);
client.send_message(&[funding_key], tx.message).unwrap();
let tx = librapay_transaction::create_account(funding_key, &libra_funding_key, 1, blockhash);
client
.send_message(&[funding_key, &libra_funding_key], tx.message)
.unwrap();

info!("minting to funding keypair");
let tx = librapay_transaction::mint_tokens(
Expand Down Expand Up @@ -829,8 +826,8 @@ fn fund_move_keys<T: Client>(
break;
}

let pubkeys: Vec<_> = keys.iter().map(|k| k.pubkey()).collect();
let tx = librapay_transaction::create_accounts(funding_key, &pubkeys, 1, blockhash);
let keypairs: Vec<_> = keys.iter().map(|k| k).collect();
let tx = librapay_transaction::create_accounts(funding_key, &keypairs, 1, blockhash);

let ser_size = bincode::serialized_size(&tx).unwrap();

Expand Down Expand Up @@ -877,10 +874,9 @@ fn fund_move_keys<T: Client>(

let libra_funding_keys: Vec<_> = (0..NUM_FUNDING_KEYS).map(|_| Keypair::new()).collect();
for (i, key) in libra_funding_keys.iter().enumerate() {
let tx =
librapay_transaction::create_account(&funding_keys[i], &key.pubkey(), 1, blockhash);
let tx = librapay_transaction::create_account(&funding_keys[i], &key, 1, blockhash);
client
.send_message(&[&funding_keys[i]], tx.message)
.send_message(&[&funding_keys[i], &key], tx.message)
.unwrap();

let tx = librapay_transaction::transfer(
Expand Down
23 changes: 16 additions & 7 deletions cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ fn process_deploy(
let minimum_balance = rpc_client.get_minimum_balance_for_rent_exemption(program_data.len())?;
let mut create_account_tx = system_transaction::create_account(
&config.keypair,
&program_id.pubkey(),
&program_id,
blockhash,
minimum_balance,
program_data.len() as u64,
Expand Down Expand Up @@ -656,8 +656,7 @@ fn process_deploy(
check_account_for_multiple_fees(rpc_client, config, &fee_calculator, &messages)?;

trace!("Creating program account");
let result =
rpc_client.send_and_confirm_transaction(&mut create_account_tx, &[&config.keypair]);
let result = rpc_client.send_and_confirm_transaction(&mut create_account_tx, &signers);
log_instruction_custom_error::<SystemError>(result)
.map_err(|_| CliError::DynamicProgramError("Program allocate space failed".to_string()))?;

Expand Down Expand Up @@ -723,9 +722,14 @@ fn process_pay(
cancelable,
lamports,
);
let mut tx = Transaction::new_signed_instructions(&[&config.keypair], ixs, blockhash);
let mut tx = Transaction::new_signed_instructions(
&[&config.keypair, &contract_state],
ixs,
blockhash,
);
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair]);
let result =
rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair, &contract_state]);
let signature_str = log_instruction_custom_error::<BudgetError>(result)?;

Ok(json!({
Expand Down Expand Up @@ -756,8 +760,13 @@ fn process_pay(
cancelable,
lamports,
);
let mut tx = Transaction::new_signed_instructions(&[&config.keypair], ixs, blockhash);
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair]);
let mut tx = Transaction::new_signed_instructions(
&[&config.keypair, &contract_state],
ixs,
blockhash,
);
let result =
rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair, &contract_state]);
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
let signature_str = log_instruction_custom_error::<BudgetError>(result)?;

Expand Down
5 changes: 3 additions & 2 deletions cli/src/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,11 +424,12 @@ pub fn process_create_stake_account(
let mut tx = Transaction::new_signed_with_payer(
ixs,
Some(&config.keypair.pubkey()),
&[&config.keypair],
&[&config.keypair, stake_account],
recent_blockhash,
);
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair]);
let result =
rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair, stake_account]);
log_instruction_custom_error::<SystemError>(result)
}

Expand Down
9 changes: 7 additions & 2 deletions cli/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,14 @@ pub fn process_create_storage_account(
1,
account_type,
);
let mut tx = Transaction::new_signed_instructions(&[&config.keypair], ixs, recent_blockhash);
let mut tx = Transaction::new_signed_instructions(
&[&config.keypair, &storage_account],
ixs,
recent_blockhash,
);
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair]);
let result =
rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair, &storage_account]);
log_instruction_custom_error::<SystemError>(result)
}

Expand Down
8 changes: 6 additions & 2 deletions cli/src/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,13 @@ pub fn process_create_vote_account(
lamports,
);
let (recent_blockhash, fee_calculator) = rpc_client.get_recent_blockhash()?;
let mut tx = Transaction::new_signed_instructions(&[&config.keypair], ixs, recent_blockhash);
let mut tx = Transaction::new_signed_instructions(
&[&config.keypair, vote_account],
ixs,
recent_blockhash,
);
check_account_for_fee(rpc_client, config, &fee_calculator, &tx.message)?;
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair]);
let result = rpc_client.send_and_confirm_transaction(&mut tx, &[&config.keypair, vote_account]);
log_instruction_custom_error::<SystemError>(result)
}

Expand Down
6 changes: 5 additions & 1 deletion core/src/rpc_pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,11 @@ mod tests {
None,
51,
);
let tx = Transaction::new_signed_instructions(&[&contract_funds], ixs, blockhash);
let tx = Transaction::new_signed_instructions(
&[&contract_funds, &contract_state],
ixs,
blockhash,
);
process_transaction_and_notify(&bank_forks, &tx, &rpc.subscriptions).unwrap();
sleep(Duration::from_millis(200));

Expand Down
4 changes: 2 additions & 2 deletions core/src/rpc_subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ mod tests {
let alice = Keypair::new();
let tx = system_transaction::create_account(
&mint_keypair,
&alice.pubkey(),
&alice,
blockhash,
1,
16,
Expand Down Expand Up @@ -371,7 +371,7 @@ mod tests {
let alice = Keypair::new();
let tx = system_transaction::create_account(
&mint_keypair,
&alice.pubkey(),
&alice,
blockhash,
1,
16,
Expand Down
2 changes: 1 addition & 1 deletion core/tests/storage_stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ mod tests {
StorageAccountType::Archiver,
);
let account_tx = Transaction::new_signed_instructions(
&[&mint_keypair],
&[&mint_keypair, &archiver_keypair],
account_ix,
bank.last_blockhash(),
);
Expand Down
13 changes: 11 additions & 2 deletions ledger/src/blocktree_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ pub mod tests {
};
use matches::assert_matches;
use rand::{thread_rng, Rng};
use solana_sdk::account::Account;
use solana_sdk::{
epoch_schedule::EpochSchedule,
hash::Hash,
Expand Down Expand Up @@ -1576,6 +1577,10 @@ pub mod tests {
}
let mut hash = bank.last_blockhash();

let present_account_key = Keypair::new();
let present_account = Account::new(1, 10, &Pubkey::default());
bank.store_account(&present_account_key.pubkey(), &present_account);

let entries: Vec<_> = (0..NUM_TRANSFERS)
.step_by(NUM_TRANSFERS_PER_ENTRY)
.map(|i| {
Expand All @@ -1592,7 +1597,7 @@ pub mod tests {

transactions.push(system_transaction::create_account(
&mint_keypair,
&solana_sdk::sysvar::clock::id(), // puts a TX error in results
&present_account_key, // puts a TX error in results
bank.last_blockhash(),
1,
0,
Expand Down Expand Up @@ -1926,6 +1931,10 @@ pub mod tests {
.expect("funding failed");
}

let present_account_key = Keypair::new();
let present_account = Account::new(1, 10, &Pubkey::default());
bank.store_account(&present_account_key.pubkey(), &present_account);

let mut i = 0;
let mut hash = bank.last_blockhash();
let mut root: Option<Arc<Bank>> = None;
Expand All @@ -1947,7 +1956,7 @@ pub mod tests {

transactions.push(system_transaction::create_account(
&mint_keypair,
&solana_sdk::sysvar::clock::id(), // puts a TX error in results
&present_account_key, // puts a TX error in results
bank.last_blockhash(),
100,
100,
Expand Down
6 changes: 4 additions & 2 deletions ledger/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,10 @@ mod tests {

fn create_sample_payment(keypair: &Keypair, hash: Hash) -> Transaction {
let pubkey = keypair.pubkey();
let ixs = budget_instruction::payment(&pubkey, &pubkey, 1);
Transaction::new_signed_instructions(&[keypair], ixs, hash)
let budget_contract = Keypair::new();
let budget_pubkey = budget_contract.pubkey();
let ixs = budget_instruction::payment(&pubkey, &pubkey, &budget_pubkey, 1);
Transaction::new_signed_instructions(&[keypair, &budget_contract], ixs, hash)
}

fn create_sample_timestamp(keypair: &Keypair, hash: Hash) -> Transaction {
Expand Down
Loading

0 comments on commit 5bd05fb

Please sign in to comment.