From 6b83ce493715012f83083fa083360cf5dcafcedc Mon Sep 17 00:00:00 2001 From: Pankaj Garg Date: Fri, 1 Mar 2019 17:16:49 -0800 Subject: [PATCH] address review comments --- src/local_cluster.rs | 68 +++++++++----------------------------------- 1 file changed, 13 insertions(+), 55 deletions(-) diff --git a/src/local_cluster.rs b/src/local_cluster.rs index 134822badc..8c2a173ea5 100644 --- a/src/local_cluster.rs +++ b/src/local_cluster.rs @@ -86,7 +86,7 @@ impl LocalCluster { &ledger_path, voting_keypair, Some(&leader_node_info), - &FullnodeConfig::default(), + &fullnode_config, ); let (thread, exit, _) = validator_server.start(None); fullnode_hdls.push((thread, exit)); @@ -143,69 +143,27 @@ impl LocalCluster { from_account: &Arc, amount: u64, ) -> Result<()> { - let pubkey = from_account.pubkey(); - let node_balance = client.poll_get_balance(&pubkey)?; - info!("node balance is {}", node_balance); - if node_balance < 1 { - return Err(Error::new( - ErrorKind::Other, - "insufficient tokens, one token required", - )); - } - // Create the vote account if necessary if client.poll_get_balance(&vote_account).unwrap_or(0) == 0 { - // Need at least two tokens as one token will be spent on a vote_account_new() transaction - if node_balance < 2 { - error!("insufficient tokens, two tokens required"); - return Err(Error::new( - ErrorKind::Other, - "insufficient tokens, two tokens required", - )); - } - loop { - let last_id = client.get_last_id(); - info!("create_and_fund_vote_account last_id={:?}", last_id); - let transaction = VoteTransaction::fund_staking_account( - from_account, - vote_account, - last_id, - amount, - 1, - ); + let mut transaction = VoteTransaction::fund_staking_account( + from_account, + vote_account, + client.get_last_id(), + amount, + 1, + ); - match client.transfer_signed(&transaction) { - Ok(signature) => { - match client.poll_for_signature(&signature) { - Ok(_) => match client.poll_get_balance(&vote_account) { - Ok(balance) => { - info!("vote account balance: {}", balance); - break; - } - Err(e) => { - info!("Failed to get vote account balance: {:?}", e); - } - }, - Err(e) => { - info!( - "vote_account_new signature not found: {:?}: {:?}", - signature, e - ); - } - }; - } - Err(e) => { - info!("Failed to send vote_account_new transaction: {:?}", e); - } - }; - } + client + .retry_transfer(&from_account, &mut transaction, 5) + .expect("client transfer"); + retry_get_balance(client, &vote_account, Some(amount)).expect("get balance"); } info!("Checking for vote account registration"); let vote_account_user_data = client.get_account_userdata(&vote_account); if let Ok(Some(vote_account_user_data)) = vote_account_user_data { if let Ok(vote_state) = VoteState::deserialize(&vote_account_user_data) { - if vote_state.delegate_id == pubkey { + if vote_state.delegate_id == from_account.pubkey() { return Ok(()); } }