cargo fmt

This commit is contained in:
Michael Vines
2019-03-02 10:20:10 -08:00
committed by Greg Fitzgerald
parent 85159a0eb4
commit 0f1582c196
17 changed files with 195 additions and 52 deletions

View File

@ -464,7 +464,8 @@ mod tests {
for _ in 0..3 {
// Transfer one token from the mint to a random account
let keypair = Keypair::new();
let tx = SystemTransaction::new_account(&mint_keypair, keypair.pubkey(), 1, block_hash, 0);
let tx =
SystemTransaction::new_account(&mint_keypair, keypair.pubkey(), 1, block_hash, 0);
let entry = Entry::new(&last_entry_hash, 1, vec![tx]);
last_entry_hash = entry.hash;
entries.push(entry);
@ -547,11 +548,21 @@ mod tests {
let block_hash = bank.last_block_hash();
// ensure bank can process 2 entries that have a common account and no tick is registered
let tx =
SystemTransaction::new_account(&mint_keypair, keypair1.pubkey(), 2, bank.last_block_hash(), 0);
let tx = SystemTransaction::new_account(
&mint_keypair,
keypair1.pubkey(),
2,
bank.last_block_hash(),
0,
);
let entry_1 = next_entry(&block_hash, 1, vec![tx]);
let tx =
SystemTransaction::new_account(&mint_keypair, keypair2.pubkey(), 2, bank.last_block_hash(), 0);
let tx = SystemTransaction::new_account(
&mint_keypair,
keypair2.pubkey(),
2,
bank.last_block_hash(),
0,
);
let entry_2 = next_entry(&entry_1.hash, 1, vec![tx]);
assert_eq!(par_process_entries(&bank, &[entry_1, entry_2]), Ok(()));
assert_eq!(bank.get_balance(&keypair1.pubkey()), 2);
@ -594,7 +605,13 @@ mod tests {
&entry_1_to_mint.hash,
1,
vec![
SystemTransaction::new_account(&keypair2, keypair3.pubkey(), 2, bank.last_block_hash(), 0), // should be fine
SystemTransaction::new_account(
&keypair2,
keypair3.pubkey(),
2,
bank.last_block_hash(),
0,
), // should be fine
SystemTransaction::new_account(
&keypair1,
mint_keypair.pubkey(),
@ -625,18 +642,40 @@ mod tests {
let keypair4 = Keypair::new();
//load accounts
let tx =
SystemTransaction::new_account(&mint_keypair, keypair1.pubkey(), 1, bank.last_block_hash(), 0);
let tx = SystemTransaction::new_account(
&mint_keypair,
keypair1.pubkey(),
1,
bank.last_block_hash(),
0,
);
assert_eq!(bank.process_transaction(&tx), Ok(()));
let tx =
SystemTransaction::new_account(&mint_keypair, keypair2.pubkey(), 1, bank.last_block_hash(), 0);
let tx = SystemTransaction::new_account(
&mint_keypair,
keypair2.pubkey(),
1,
bank.last_block_hash(),
0,
);
assert_eq!(bank.process_transaction(&tx), Ok(()));
// ensure bank can process 2 entries that do not have a common account and no tick is registered
let block_hash = bank.last_block_hash();
let tx = SystemTransaction::new_account(&keypair1, keypair3.pubkey(), 1, bank.last_block_hash(), 0);
let tx = SystemTransaction::new_account(
&keypair1,
keypair3.pubkey(),
1,
bank.last_block_hash(),
0,
);
let entry_1 = next_entry(&block_hash, 1, vec![tx]);
let tx = SystemTransaction::new_account(&keypair2, keypair4.pubkey(), 1, bank.last_block_hash(), 0);
let tx = SystemTransaction::new_account(
&keypair2,
keypair4.pubkey(),
1,
bank.last_block_hash(),
0,
);
let entry_2 = next_entry(&entry_1.hash, 1, vec![tx]);
assert_eq!(par_process_entries(&bank, &[entry_1, entry_2]), Ok(()));
assert_eq!(bank.get_balance(&keypair3.pubkey()), 1);
@ -654,11 +693,21 @@ mod tests {
let keypair4 = Keypair::new();
//load accounts
let tx =
SystemTransaction::new_account(&mint_keypair, keypair1.pubkey(), 1, bank.last_block_hash(), 0);
let tx = SystemTransaction::new_account(
&mint_keypair,
keypair1.pubkey(),
1,
bank.last_block_hash(),
0,
);
assert_eq!(bank.process_transaction(&tx), Ok(()));
let tx =
SystemTransaction::new_account(&mint_keypair, keypair2.pubkey(), 1, bank.last_block_hash(), 0);
let tx = SystemTransaction::new_account(
&mint_keypair,
keypair2.pubkey(),
1,
bank.last_block_hash(),
0,
);
assert_eq!(bank.process_transaction(&tx), Ok(()));
let block_hash = bank.last_block_hash();
@ -670,7 +719,13 @@ mod tests {
let tx = SystemTransaction::new_account(&keypair2, keypair3.pubkey(), 1, block_hash, 0);
let entry_1 = next_entry(&block_hash, 1, vec![tx]);
let tick = next_entry(&entry_1.hash, 1, vec![]);
let tx = SystemTransaction::new_account(&keypair1, keypair4.pubkey(), 1, bank.last_block_hash(), 0);
let tx = SystemTransaction::new_account(
&keypair1,
keypair4.pubkey(),
1,
bank.last_block_hash(),
0,
);
let entry_2 = next_entry(&tick.hash, 1, vec![tx]);
assert_eq!(
par_process_entries(&bank, &[entry_1.clone(), tick.clone(), entry_2.clone()]),
@ -680,7 +735,13 @@ mod tests {
assert_eq!(bank.get_balance(&keypair4.pubkey()), 1);
// ensure that an error is returned for an empty account (keypair2)
let tx = SystemTransaction::new_account(&keypair2, keypair3.pubkey(), 1, bank.last_block_hash(), 0);
let tx = SystemTransaction::new_account(
&keypair2,
keypair3.pubkey(),
1,
bank.last_block_hash(),
0,
);
let entry_3 = next_entry(&entry_2.hash, 1, vec![tx]);
assert_eq!(
par_process_entries(&bank, &[entry_3]),

View File

@ -124,7 +124,11 @@ impl Fullnode {
let bank_info = &bank_forks_info[0];
let bank = bank_forks[bank_info.bank_id].clone();
info!("starting PoH... {} {}", bank.tick_height(), bank.last_block_hash(),);
info!(
"starting PoH... {} {}",
bank.tick_height(),
bank.last_block_hash(),
);
let poh_recorder = Arc::new(Mutex::new(PohRecorder::new(
bank.tick_height(),
bank.last_block_hash(),
@ -441,8 +445,13 @@ pub fn make_active_set_entries(
num_ending_ticks: u64,
) -> (Vec<Entry>, VotingKeypair) {
// 1) Assume the active_keypair node has no tokens staked
let transfer_tx =
SystemTransaction::new_account(&token_source, active_keypair.pubkey(), stake, *block_hash, 0);
let transfer_tx = SystemTransaction::new_account(
&token_source,
active_keypair.pubkey(),
stake,
*block_hash,
0,
);
let mut last_entry_hash = *block_hash;
let transfer_entry = next_entry_mut(&mut last_entry_hash, 1, vec![transfer_tx]);
@ -455,7 +464,8 @@ pub fn make_active_set_entries(
let new_vote_account_entry = next_entry_mut(&mut last_entry_hash, 1, vec![new_vote_account_tx]);
// 3) Create vote entry
let vote_tx = VoteTransaction::new_vote(&voting_keypair, slot_height_to_vote_on, *block_hash, 0);
let vote_tx =
VoteTransaction::new_vote(&voting_keypair, slot_height_to_vote_on, *block_hash, 0);
let vote_entry = next_entry_mut(&mut last_entry_hash, 1, vec![vote_tx]);
// 4) Create `num_ending_ticks` empty ticks

View File

@ -206,7 +206,9 @@ impl ReplayStage {
progress: &mut HashMap<u64, (Hash, usize)>,
) -> result::Result<(Vec<Entry>, usize)> {
let bank_id = bank.slot();
let bank_progress = &mut progress.entry(bank_id).or_insert((bank.last_block_hash(), 0));
let bank_progress = &mut progress
.entry(bank_id)
.or_insert((bank.last_block_hash(), 0));
blocktree.get_slot_entries_with_blob_count(bank_id, bank_progress.1 as u64, None)
}
@ -217,7 +219,9 @@ impl ReplayStage {
forward_entry_sender: &EntrySender,
num: usize,
) -> result::Result<()> {
let bank_progress = &mut progress.entry(bank.slot()).or_insert((bank.last_block_hash(), 0));
let bank_progress = &mut progress
.entry(bank.slot())
.or_insert((bank.last_block_hash(), 0));
let result = Self::verify_and_process_entries(&bank, &entries, &bank_progress.0);
bank_progress.1 += num;
if let Some(last_entry) = entries.last() {

View File

@ -211,7 +211,10 @@ impl RpcSol for RpcSolImpl {
fn get_recent_block_hash(&self, meta: Self::Metadata) -> Result<String> {
info!("get_recent_block_hash rpc request received");
meta.request_processor.read().unwrap().get_recent_block_hash()
meta.request_processor
.read()
.unwrap()
.get_recent_block_hash()
}
fn get_signature_status(&self, meta: Self::Metadata, id: String) -> Result<RpcSignatureStatus> {
@ -255,12 +258,19 @@ impl RpcSol for RpcSolImpl {
trace!("request_airdrop id={} tokens={}", id, tokens);
let pubkey = verify_pubkey(id)?;
let block_hash = meta.request_processor.read().unwrap().bank()?.last_block_hash();
let transaction = request_airdrop_transaction(&meta.drone_addr, &pubkey, tokens, block_hash)
.map_err(|err| {
info!("request_airdrop_transaction failed: {:?}", err);
Error::internal_error()
})?;;
let block_hash = meta
.request_processor
.read()
.unwrap()
.bank()?
.last_block_hash();
let transaction =
request_airdrop_transaction(&meta.drone_addr, &pubkey, tokens, block_hash).map_err(
|err| {
info!("request_airdrop_transaction failed: {:?}", err);
Error::internal_error()
},
)?;;
let data = serialize(&transaction).map_err(|err| {
info!("request_airdrop: serialize error: {:?}", err);

View File

@ -220,9 +220,9 @@ impl ThinClient {
pub fn try_get_recent_block_hash(&mut self, mut num_retries: u64) -> Option<Hash> {
loop {
trace!("try_get_recent_block_hash send_to {}", &self.rpc_addr);
let response = self
.rpc_client
.make_rpc_request(1, RpcRequest::GetRecentBlockHash, None);
let response =
self.rpc_client
.make_rpc_request(1, RpcRequest::GetRecentBlockHash, None);
match response {
Ok(value) => {
@ -514,7 +514,9 @@ mod tests {
let block_hash = client.get_recent_block_hash();
info!("test_thin_client block_hash: {:?}", block_hash);
let signature = client.transfer(500, &alice, bob_pubkey, &block_hash).unwrap();
let signature = client
.transfer(500, &alice, bob_pubkey, &block_hash)
.unwrap();
info!("test_thin_client signature: {:?}", signature);
client.poll_for_signature(&signature).unwrap();

View File

@ -34,7 +34,7 @@ use std::thread;
pub struct TvuRotationInfo {
pub tick_height: u64, // tick height, bank might not exist yet
pub block_hash: Hash, // block_hash that was voted on
pub block_hash: Hash, // block_hash that was voted on
pub slot: u64, // slot height to initiate a rotation
pub leader_id: Pubkey, // leader upon rotation
}