Improve bench-tps funding in move mode (#5442)

This commit is contained in:
sakridge 2019-08-07 08:55:01 -07:00 committed by GitHub
parent d6aaab0b2c
commit 7911895b67
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 96 additions and 77 deletions

View File

@ -440,7 +440,12 @@ pub fn fund_keys<T: Client>(
let mut notfunded: Vec<&Keypair> = dests.iter().collect(); let mut notfunded: Vec<&Keypair> = dests.iter().collect();
let lamports_per_account = (total - (extra * max_fee)) / (notfunded.len() as u64 + 1); let lamports_per_account = (total - (extra * max_fee)) / (notfunded.len() as u64 + 1);
println!("funding keys {}", dests.len()); println!(
"funding keys {} with lamports: {:?} total: {}",
dests.len(),
client.get_balance(&source.pubkey()),
total
);
while !notfunded.is_empty() { while !notfunded.is_empty() {
let mut new_funded: Vec<(&Keypair, u64)> = vec![]; let mut new_funded: Vec<(&Keypair, u64)> = vec![];
let mut to_fund = vec![]; let mut to_fund = vec![];
@ -705,10 +710,7 @@ fn fund_move_keys<T: Client>(
1, 1,
blockhash, blockhash,
); );
let sig = client client.send_message(&[funding_key], tx.message).unwrap();
.async_send_transaction(tx)
.expect("create_account in generate_and_fund_keypairs");
client.poll_for_signature(&sig).unwrap();
info!("minting to funding keypair"); info!("minting to funding keypair");
let tx = librapay_transaction::mint_tokens( let tx = librapay_transaction::mint_tokens(
@ -719,12 +721,11 @@ fn fund_move_keys<T: Client>(
total, total,
blockhash, blockhash,
); );
let sig = client client
.async_send_transaction(tx) .send_message(&[funding_key, libra_mint_key], tx.message)
.expect("create_account in generate_and_fund_keypairs"); .unwrap();
client.poll_for_signature(&sig).unwrap();
info!("creating move accounts.. {}", keypairs.len()); info!("creating {} move accounts...", keypairs.len());
let create_len = 8; let create_len = 8;
let mut funding_time = Measure::start("funding_time"); let mut funding_time = Measure::start("funding_time");
for (i, keys) in keypairs.chunks(create_len).enumerate() { for (i, keys) in keypairs.chunks(create_len).enumerate() {
@ -733,97 +734,115 @@ fn fund_move_keys<T: Client>(
break; break;
} }
let mut tx_send = Measure::start("poll");
let pubkeys: Vec<_> = keys.iter().map(|k| k.pubkey()).collect(); let pubkeys: Vec<_> = keys.iter().map(|k| k.pubkey()).collect();
let tx = librapay_transaction::create_accounts(funding_key, &pubkeys, 1, blockhash); let tx = librapay_transaction::create_accounts(funding_key, &pubkeys, 1, blockhash);
let ser_size = bincode::serialized_size(&tx).unwrap(); let ser_size = bincode::serialized_size(&tx).unwrap();
let sig = client
.async_send_transaction(tx) client.send_message(&[funding_key], tx.message).unwrap();
.expect("create_account in generate_and_fund_keypairs");
tx_send.stop();
let mut poll = Measure::start("poll");
client.poll_for_signature(&sig).unwrap();
poll.stop();
if i % 10 == 0 { if i % 10 == 0 {
blockhash = client.get_recent_blockhash().unwrap().0;
info!( info!(
"size: {} created {} accounts of {} sig: {}us send: {}us", "size: {} created {} accounts of {}",
ser_size, ser_size,
i, i,
(keypairs.len() / create_len), (keypairs.len() / create_len),
poll.as_us(),
tx_send.as_us()
); );
} }
} }
funding_time.stop(); funding_time.stop();
info!("funding accounts {}ms", funding_time.as_ms()); info!("funding accounts {}ms", funding_time.as_ms());
let mut sigs = vec![];
let tx_count = keypairs.len(); const NUM_FUNDING_KEYS: usize = 4;
let amount = total / (tx_count as u64); let funding_keys: Vec<_> = (0..NUM_FUNDING_KEYS).map(|_| Keypair::new()).collect();
for (i, key) in keypairs[..tx_count].iter().enumerate() { let pubkey_amounts: Vec<_> = funding_keys
.iter()
.map(|key| (key.pubkey(), total / NUM_FUNDING_KEYS as u64))
.collect();
let tx = Transaction::new_signed_instructions(
&[funding_key],
system_instruction::transfer_many(&funding_key.pubkey(), &pubkey_amounts),
blockhash,
);
client.send_message(&[funding_key], tx.message).unwrap();
let mut balance = 0;
for _ in 0..20 {
balance = client.get_balance(&funding_keys[0].pubkey()).unwrap();
if balance > 0 {
break;
} else {
sleep(Duration::from_millis(100));
}
}
assert!(balance > 0);
info!("funded multiple funding accounts.. {:?}", balance);
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);
client
.send_message(&[&funding_keys[i]], tx.message)
.unwrap();
let tx = librapay_transaction::transfer( let tx = librapay_transaction::transfer(
libra_pay_program_id, libra_pay_program_id,
&libra_mint_key.pubkey(), &libra_mint_key.pubkey(),
funding_key, &funding_keys[i],
&libra_funding_key, &libra_funding_key,
&key.pubkey(), &key.pubkey(),
amount, total / NUM_FUNDING_KEYS as u64,
blockhash, blockhash,
); );
client
.send_message(&[&funding_keys[i], &libra_funding_key], tx.message)
.unwrap();
let sig = client info!("funded libra funding key {}", i);
.async_send_transaction(tx.clone())
.expect("create_account in generate_and_fund_keypairs");
let mut poll_time = Measure::start("poll_start");
let poll_status = client.poll_for_signature(&sig);
poll_time.stop();
info!(
"i: {} poll: {:?} time: {}ms",
i,
poll_status,
poll_time.as_ms()
);
sigs.push((sig, key));
if i % 50 == 0 {
blockhash = client.get_recent_blockhash().unwrap().0;
}
} }
for (i, (sig, key)) in sigs.iter().enumerate() { let tx_count = keypairs.len();
let mut times = 0; let amount = total / (tx_count as u64);
loop { for (i, keys) in keypairs[..tx_count].chunks(NUM_FUNDING_KEYS).enumerate() {
match client.poll_for_signature(&sig) { for (j, key) in keys.iter().enumerate() {
Ok(_) => { let tx = librapay_transaction::transfer(
libra_pay_program_id,
&libra_mint_key.pubkey(),
&funding_keys[j],
&libra_funding_keys[j],
&key.pubkey(),
amount,
blockhash,
);
let _sig = client
.async_send_transaction(tx.clone())
.expect("create_account in generate_and_fund_keypairs");
}
info!("sent... checking balance {}", i);
for (j, key) in keys.iter().enumerate() {
let mut times = 0;
loop {
let balance =
librapay_transaction::get_libra_balance(client, &key.pubkey()).unwrap();
if balance >= amount {
break; break;
} } else if times > 20 {
Err(e) => { info!("timed out.. {} key: {} balance: {}", i, j, balance);
info!("e :{:?} waiting times: {} sig: {}", e, times, sig); break;
} else {
times += 1; times += 1;
sleep(Duration::from_secs(1)); sleep(Duration::from_millis(100));
} }
} }
} }
times = 0;
loop { info!("funded: {} of {}", i, keypairs.len() / NUM_FUNDING_KEYS);
let balance = librapay_transaction::get_libra_balance(client, &key.pubkey()).unwrap(); blockhash = client.get_recent_blockhash().unwrap().0;
if balance < amount {
info!("i: {} balance: {} times: {}", i, balance, times);
times += 1;
sleep(Duration::from_secs(1));
} else {
break;
}
}
if i % 10 == 0 {
info!("funding {} of {}", i, tx_count);
}
} }
info!("done..");
info!("done funding keys..");
} }
pub fn generate_and_fund_keypairs<T: Client>( pub fn generate_and_fund_keypairs<T: Client>(
@ -853,7 +872,7 @@ pub fn generate_and_fund_keypairs<T: Client>(
let extra_fees = extra * fee_calculator.max_lamports_per_signature; let extra_fees = extra * fee_calculator.max_lamports_per_signature;
let mut total = account_desired_balance * (1 + keypairs.len() as u64) + extra_fees; let mut total = account_desired_balance * (1 + keypairs.len() as u64) + extra_fees;
if use_move { if use_move {
total *= 2; total *= 3;
} }
println!("Previous key balance: {} max_fee: {} lamports_per_account: {} extra: {} desired_balance: {} total: {}", println!("Previous key balance: {} max_fee: {} lamports_per_account: {} extra: {} desired_balance: {} total: {}",
@ -866,7 +885,7 @@ pub fn generate_and_fund_keypairs<T: Client>(
} }
if use_move { if use_move {
let libra_genesis_keypair = create_genesis(&funding_key, client, 1_000_000); let libra_genesis_keypair = create_genesis(&funding_key, client, 10_000_000);
let libra_mint_program_id = upload_mint_program(&funding_key, client); let libra_mint_program_id = upload_mint_program(&funding_key, client);
let libra_pay_program_id = upload_payment_program(&funding_key, client); let libra_pay_program_id = upload_payment_program(&funding_key, client);
@ -879,7 +898,7 @@ pub fn generate_and_fund_keypairs<T: Client>(
client, client,
funding_key, funding_key,
&move_keypairs, &move_keypairs,
total / 2, total / 3,
&libra_pay_program_id, &libra_pay_program_id,
&libra_mint_program_id, &libra_mint_program_id,
&libra_genesis_keypair, &libra_genesis_keypair,
@ -891,8 +910,8 @@ pub fn generate_and_fund_keypairs<T: Client>(
move_keypairs, move_keypairs,
)); ));
// Give solana keys half and move keys half the lamports. // Give solana keys 1/3 and move keys 1/3 the lamports. Keep 1/3 for fees.
total /= 2; total /= 3;
} }
fund_keys( fund_keys(