diff --git a/bench-tps/src/bench.rs b/bench-tps/src/bench.rs index 3061f8758..feff92b8f 100644 --- a/bench-tps/src/bench.rs +++ b/bench-tps/src/bench.rs @@ -100,7 +100,7 @@ pub fn sample_tx_count( } /// Send loopback payment of 0 tokens and confirm the network processed it -pub fn send_barrier_transaction(barrier_client: &mut ThinClient, last_id: &mut Hash, id: &Keypair) { +pub fn send_barrier_transaction(barrier_client: &mut ThinClient, block_hash: &mut Hash, id: &Keypair) { let transfer_start = Instant::now(); let mut poll_count = 0; @@ -112,9 +112,9 @@ pub fn send_barrier_transaction(barrier_client: &mut ThinClient, last_id: &mut H ); } - *last_id = barrier_client.get_recent_block_hash(); + *block_hash = barrier_client.get_recent_block_hash(); let signature = barrier_client - .transfer(0, &id, id.pubkey(), last_id) + .transfer(0, &id, id.pubkey(), block_hash) .expect("Unable to send barrier transaction"); let confirmatiom = barrier_client.poll_for_signature(&signature); @@ -154,13 +154,13 @@ pub fn send_barrier_transaction(barrier_client: &mut ThinClient, last_id: &mut H exit(1); } - let new_last_id = barrier_client.get_recent_block_hash(); - if new_last_id == *last_id { + let new_block_hash = barrier_client.get_recent_block_hash(); + if new_block_hash == *block_hash { if poll_count > 0 && poll_count % 8 == 0 { - println!("last_id is not advancing, still at {:?}", *last_id); + println!("block_hash is not advancing, still at {:?}", *block_hash); } } else { - *last_id = new_last_id; + *block_hash = new_block_hash; } poll_count += 1; @@ -176,7 +176,7 @@ pub fn generate_txs( leader: &NodeInfo, ) { let mut client = mk_client(leader); - let last_id = client.get_recent_block_hash(); + let block_hash = client.get_recent_block_hash(); let tx_count = source.len(); println!("Signing transactions... {} (reclaim={})", tx_count, reclaim); let signing_start = Instant::now(); @@ -190,7 +190,7 @@ pub fn generate_txs( .par_iter() .map(|(id, keypair)| { ( - SystemTransaction::new_account(id, keypair.pubkey(), 1, last_id, 0), + SystemTransaction::new_account(id, keypair.pubkey(), 1, block_hash, 0), timestamp(), ) }) @@ -205,7 +205,7 @@ pub fn generate_txs( bsps * 1_000_000_f64, nsps / 1_000_f64, duration_as_ms(&duration), - last_id, + block_hash, ); solana_metrics::submit( influxdb::Point::new("bench-tps") @@ -328,7 +328,7 @@ pub fn fund_keys(client: &mut ThinClient, source: &Keypair, dests: &[Keypair], t } } - // try to transfer a "few" at a time with recent last_id + // try to transfer a "few" at a time with recent block_hash // assume 4MB network buffers, and 512 byte packets const FUND_CHUNK_LEN: usize = 4 * 1024 * 1024 / 512; @@ -366,11 +366,11 @@ pub fn fund_keys(client: &mut ThinClient, source: &Keypair, dests: &[Keypair], t to_fund_txs.len(), ); - let last_id = client.get_recent_block_hash(); + let block_hash = client.get_recent_block_hash(); - // re-sign retained to_fund_txes with updated last_id + // re-sign retained to_fund_txes with updated block_hash to_fund_txs.par_iter_mut().for_each(|(k, tx)| { - tx.sign(&[*k], last_id); + tx.sign(&[*k], block_hash); }); to_fund_txs.iter().for_each(|(_, tx)| { @@ -410,8 +410,8 @@ pub fn airdrop_tokens( id.pubkey(), ); - let last_id = client.get_recent_block_hash(); - match request_airdrop_transaction(&drone_addr, &id.pubkey(), airdrop_amount, last_id) { + let block_hash = client.get_recent_block_hash(); + match request_airdrop_transaction(&drone_addr, &id.pubkey(), airdrop_amount, block_hash) { Ok(transaction) => { let signature = client.transfer_signed(&transaction).unwrap(); client.poll_for_signature(&signature).unwrap(); diff --git a/bench-tps/src/main.rs b/bench-tps/src/main.rs index b3364181b..f22673e8e 100644 --- a/bench-tps/src/main.rs +++ b/bench-tps/src/main.rs @@ -170,8 +170,8 @@ fn main() { airdrop_tokens(&mut barrier_client, &drone_addr, &barrier_id, 1); println!("Get last ID..."); - let mut last_id = client.get_recent_block_hash(); - println!("Got last ID {:?}", last_id); + let mut block_hash = client.get_recent_block_hash(); + println!("Got last ID {:?}", block_hash); let first_tx_count = client.transaction_count(); println!("Initial transaction count {}", first_tx_count); @@ -254,7 +254,7 @@ fn main() { // It's not feasible (would take too much time) to confirm each of the `tx_count / 2` // transactions sent by `generate_txs()` so instead send and confirm a single transaction // to validate the network is still functional. - send_barrier_transaction(&mut barrier_client, &mut last_id, &barrier_id); + send_barrier_transaction(&mut barrier_client, &mut block_hash, &barrier_id); i += 1; if should_switch_directions(num_tokens_per_account, i) { diff --git a/core/src/banking_stage.rs b/core/src/banking_stage.rs index f4f2f726b..49907380c 100644 --- a/core/src/banking_stage.rs +++ b/core/src/banking_stage.rs @@ -66,7 +66,7 @@ impl BankingStage { // Single thread to generate entries from many banks. // This thread talks to poh_service and broadcasts the entries once they have been recorded. - // Once an entry has been recorded, its last_id is registered with the bank. + // Once an entry has been recorded, its block_hash is registered with the bank. let exit = Arc::new(AtomicBool::new(false)); // Single thread to compute confirmation @@ -464,11 +464,11 @@ mod tests { assert!(entries.len() >= 1); - let mut last_id = start_hash; + let mut block_hash = start_hash; entries.iter().for_each(|entries| { assert_eq!(entries.len(), 1); - assert!(entries.verify(&last_id)); - last_id = entries.last().unwrap().hash; + assert!(entries.verify(&block_hash)); + block_hash = entries.last().unwrap().hash; }); drop(entry_receiver); banking_stage.join().unwrap(); diff --git a/core/src/blockstream.rs b/core/src/blockstream.rs index 3b8de3eb2..e8c94d1fb 100644 --- a/core/src/blockstream.rs +++ b/core/src/blockstream.rs @@ -71,7 +71,7 @@ pub trait BlockstreamEvents { slot: u64, tick_height: u64, leader_id: Pubkey, - last_id: Hash, + block_hash: Hash, ) -> Result<()>; } @@ -109,7 +109,7 @@ where slot: u64, tick_height: u64, leader_id: Pubkey, - last_id: Hash, + block_hash: Hash, ) -> Result<()> { let payload = format!( r#"{{"dt":"{}","t":"block","s":{},"h":{},"l":"{:?}","id":"{:?}"}}"#, @@ -117,7 +117,7 @@ where slot, tick_height, leader_id, - last_id, + block_hash, ); self.output.write(payload)?; Ok(()) @@ -163,7 +163,7 @@ mod test { let blockstream = MockBlockstream::new("test_stream".to_string()); let ticks_per_slot = 5; - let mut last_id = Hash::default(); + let mut block_hash = Hash::default(); let mut entries = Vec::new(); let mut expected_entries = Vec::new(); @@ -175,12 +175,12 @@ mod test { for tick_height in tick_height_initial..=tick_height_final { if tick_height == 5 { blockstream - .emit_block_event(curr_slot, tick_height - 1, leader_id, last_id) + .emit_block_event(curr_slot, tick_height - 1, leader_id, block_hash) .unwrap(); curr_slot += 1; } - let entry = Entry::new(&mut last_id, 1, vec![]); // just ticks - last_id = entry.hash; + let entry = Entry::new(&mut block_hash, 1, vec![]); // just ticks + block_hash = entry.hash; blockstream .emit_entry_event(curr_slot, tick_height, leader_id, &entry) .unwrap(); diff --git a/core/src/blockstream_service.rs b/core/src/blockstream_service.rs index 8ed792086..4e7b4c0f2 100644 --- a/core/src/blockstream_service.rs +++ b/core/src/blockstream_service.rs @@ -125,7 +125,7 @@ mod test { let (mut genesis_block, _mint_keypair) = GenesisBlock::new(1000); genesis_block.ticks_per_slot = ticks_per_slot; - let (ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block); + let (ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block); let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap(); // Set up blockstream @@ -138,12 +138,12 @@ mod test { let mut entries = create_ticks(4, Hash::default()); let keypair = Keypair::new(); - let mut last_id = entries[3].hash; + let mut block_hash = entries[3].hash; let tx = SystemTransaction::new_account(&keypair, keypair.pubkey(), 1, Hash::default(), 0); - let entry = Entry::new(&mut last_id, 1, vec![tx]); - last_id = entry.hash; + let entry = Entry::new(&mut block_hash, 1, vec![tx]); + block_hash = entry.hash; entries.push(entry); - let final_tick = create_ticks(1, last_id); + let final_tick = create_ticks(1, block_hash); entries.extend_from_slice(&final_tick); let expected_entries = entries.clone(); diff --git a/core/src/blocktree.rs b/core/src/blocktree.rs index eefd6e080..568b0e54c 100644 --- a/core/src/blocktree.rs +++ b/core/src/blocktree.rs @@ -689,7 +689,7 @@ impl Blocktree { db_iterator.seek_to_first(); Ok(EntryIterator { db_iterator, - last_id: None, + block_hash: None, }) } @@ -1250,7 +1250,7 @@ struct EntryIterator { // TODO: remove me when replay_stage is iterating by block (Blocktree) // this verification is duplicating that of replay_stage, which // can do this in parallel - last_id: Option, + block_hash: Option, // https://github.com/rust-rocksdb/rust-rocksdb/issues/234 // rocksdb issue: the _blocktree member must be lower in the struct to prevent a crash // when the db_iterator member above is dropped. @@ -1267,13 +1267,13 @@ impl Iterator for EntryIterator { if self.db_iterator.valid() { if let Some(value) = self.db_iterator.value() { if let Ok(entry) = deserialize::(&value[BLOB_HEADER_SIZE..]) { - if let Some(last_id) = self.last_id { - if !entry.verify(&last_id) { + if let Some(block_hash) = self.block_hash { + if !entry.verify(&block_hash) { return None; } } self.db_iterator.next(); - self.last_id = Some(entry.hash); + self.block_hash = Some(entry.hash); return Some(entry); } } @@ -1284,7 +1284,7 @@ impl Iterator for EntryIterator { // Creates a new ledger with slot 0 full of ticks (and only ticks). // -// Returns the last_id that can be used to append entries with. +// Returns the block_hash that can be used to append entries with. pub fn create_new_ledger(ledger_path: &str, genesis_block: &GenesisBlock) -> Result { let ticks_per_slot = genesis_block.ticks_per_slot; Blocktree::destroy(ledger_path)?; @@ -1362,8 +1362,8 @@ macro_rules! create_new_tmp_ledger { // ticks) pub fn create_new_tmp_ledger(name: &str, genesis_block: &GenesisBlock) -> (String, Hash) { let ledger_path = get_tmp_ledger_path(name); - let last_id = create_new_ledger(&ledger_path, genesis_block).unwrap(); - (ledger_path, last_id) + let block_hash = create_new_ledger(&ledger_path, genesis_block).unwrap(); + (ledger_path, block_hash) } #[macro_export] diff --git a/core/src/blocktree_processor.rs b/core/src/blocktree_processor.rs index aa1a82a0a..813394e73 100644 --- a/core/src/blocktree_processor.rs +++ b/core/src/blocktree_processor.rs @@ -286,7 +286,7 @@ mod tests { */ // Create a new ledger with slot 0 full of ticks - let (ledger_path, mut last_id) = create_new_tmp_ledger!(&genesis_block); + let (ledger_path, mut block_hash) = create_new_tmp_ledger!(&genesis_block); debug!("ledger_path: {:?}", ledger_path); let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot) @@ -297,8 +297,8 @@ mod tests { { let parent_slot = 0; let slot = 1; - let mut entries = create_ticks(ticks_per_slot, last_id); - last_id = entries.last().unwrap().hash; + let mut entries = create_ticks(ticks_per_slot, block_hash); + block_hash = entries.last().unwrap().hash; entries.pop(); @@ -307,7 +307,7 @@ mod tests { } // slot 2, points at slot 1 - fill_blocktree_slot_with_ticks(&blocktree, ticks_per_slot, 2, 1, last_id); + fill_blocktree_slot_with_ticks(&blocktree, ticks_per_slot, 2, 1, block_hash); let (mut _bank_forks, bank_forks_info) = process_blocktree(&genesis_block, &blocktree, None).unwrap(); @@ -330,9 +330,9 @@ mod tests { let ticks_per_slot = genesis_block.ticks_per_slot; // Create a new ledger with slot 0 full of ticks - let (ledger_path, last_id) = create_new_tmp_ledger!(&genesis_block); + let (ledger_path, block_hash) = create_new_tmp_ledger!(&genesis_block); debug!("ledger_path: {:?}", ledger_path); - let mut last_entry_hash = last_id; + let mut last_entry_hash = block_hash; /* Build a blocktree in the ledger with the following fork structure: @@ -460,11 +460,11 @@ mod tests { debug!("ledger_path: {:?}", ledger_path); let mut entries = vec![]; - let last_id = genesis_block.hash(); + let block_hash = genesis_block.hash(); 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, last_id, 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); @@ -472,7 +472,7 @@ mod tests { // Add a second Transaction that will produce a // ProgramError<0, ResultWithNegativeTokens> error when processed let keypair2 = Keypair::new(); - let tx = SystemTransaction::new_account(&keypair, keypair2.pubkey(), 42, last_id, 0); + let tx = SystemTransaction::new_account(&keypair, keypair2.pubkey(), 42, block_hash, 0); let entry = Entry::new(&last_entry_hash, 1, vec![tx]); last_entry_hash = entry.hash; entries.push(entry); @@ -507,7 +507,7 @@ mod tests { fn test_process_ledger_with_one_tick_per_slot() { let (mut genesis_block, _mint_keypair) = GenesisBlock::new(123); genesis_block.ticks_per_slot = 1; - let (ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block); + let (ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block); let blocktree = Blocktree::open(&ledger_path).unwrap(); let (bank_forks, bank_forks_info) = @@ -544,19 +544,19 @@ mod tests { let keypair1 = Keypair::new(); let keypair2 = Keypair::new(); - let last_id = bank.last_block_hash(); + 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 entry_1 = next_entry(&last_id, 1, vec![tx]); + 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 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); assert_eq!(bank.get_balance(&keypair2.pubkey()), 2); - assert_eq!(bank.last_block_hash(), last_id); + assert_eq!(bank.last_block_hash(), block_hash); } #[test] @@ -633,15 +633,15 @@ mod tests { 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 last_id = bank.last_block_hash(); + let block_hash = bank.last_block_hash(); let tx = SystemTransaction::new_account(&keypair1, keypair3.pubkey(), 1, bank.last_block_hash(), 0); - let entry_1 = next_entry(&last_id, 1, vec![tx]); + 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 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); assert_eq!(bank.get_balance(&keypair4.pubkey()), 1); - assert_eq!(bank.last_block_hash(), last_id); + assert_eq!(bank.last_block_hash(), block_hash); } #[test] @@ -661,14 +661,14 @@ mod tests { SystemTransaction::new_account(&mint_keypair, keypair2.pubkey(), 1, bank.last_block_hash(), 0); assert_eq!(bank.process_transaction(&tx), Ok(())); - let last_id = bank.last_block_hash(); - while last_id == bank.last_block_hash() { + let block_hash = bank.last_block_hash(); + while block_hash == bank.last_block_hash() { bank.register_tick(&Hash::default()); } // ensure bank can process 2 entries that do not have a common account and tick is registered - let tx = SystemTransaction::new_account(&keypair2, keypair3.pubkey(), 1, last_id, 0); - let entry_1 = next_entry(&last_id, 1, vec![tx]); + 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 entry_2 = next_entry(&tick.hash, 1, vec![tx]); diff --git a/core/src/fullnode.rs b/core/src/fullnode.rs index a310f1a1a..2e41d764d 100644 --- a/core/src/fullnode.rs +++ b/core/src/fullnode.rs @@ -331,12 +331,12 @@ impl Fullnode { //instead of here info!( "reset PoH... {} {}", - rotation_info.tick_height, rotation_info.last_id + rotation_info.tick_height, rotation_info.block_hash ); self.poh_recorder .lock() .unwrap() - .reset(rotation_info.tick_height, rotation_info.last_id); + .reset(rotation_info.tick_height, rotation_info.block_hash); let slot = rotation_info.slot; self.rotate(rotation_info); debug!("role transition complete"); @@ -437,13 +437,13 @@ pub fn make_active_set_entries( token_source: &Keypair, stake: u64, slot_height_to_vote_on: u64, - last_id: &Hash, + block_hash: &Hash, num_ending_ticks: u64, ) -> (Vec, VotingKeypair) { // 1) Assume the active_keypair node has no tokens staked let transfer_tx = - SystemTransaction::new_account(&token_source, active_keypair.pubkey(), stake, *last_id, 0); - let mut last_entry_hash = *last_id; + 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]); // 2) Create and register a vote account for active_keypair @@ -451,11 +451,11 @@ pub fn make_active_set_entries( let vote_account_id = voting_keypair.pubkey(); let new_vote_account_tx = - VoteTransaction::fund_staking_account(active_keypair, vote_account_id, *last_id, 1, 1); + VoteTransaction::fund_staking_account(active_keypair, vote_account_id, *block_hash, 1, 1); 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, *last_id, 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 @@ -486,7 +486,7 @@ mod tests { let validator_node = Node::new_localhost_with_pubkey(validator_keypair.pubkey()); let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(10_000, leader_keypair.pubkey(), 1000); - let (validator_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block); + let (validator_ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block); let validator = Fullnode::new( validator_node, @@ -512,7 +512,7 @@ mod tests { let validator_node = Node::new_localhost_with_pubkey(validator_keypair.pubkey()); let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(10_000, leader_keypair.pubkey(), 1000); - let (validator_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block); + let (validator_ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block); ledger_paths.push(validator_ledger_path.clone()); Fullnode::new( validator_node, @@ -560,7 +560,7 @@ mod tests { genesis_block.ticks_per_slot = ticks_per_slot; genesis_block.slots_per_epoch = slots_per_epoch; - let (bootstrap_leader_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block); + let (bootstrap_leader_ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block); // Start the bootstrap leader let bootstrap_leader = Fullnode::new( @@ -657,7 +657,7 @@ mod tests { let leader_keypair = Arc::new(Keypair::new()); let validator_keypair = Arc::new(Keypair::new()); let fullnode_config = FullnodeConfig::default(); - let (leader_node, validator_node, validator_ledger_path, ledger_initial_len, last_id) = + let (leader_node, validator_node, validator_ledger_path, ledger_initial_len, block_hash) = setup_leader_validator(&leader_keypair, &validator_keypair, ticks_per_slot, 0); let leader_id = leader_keypair.pubkey(); @@ -697,7 +697,7 @@ mod tests { &leader_id, blobs_to_send, ledger_initial_len, - last_id, + block_hash, &tvu_address, ) .into_iter() @@ -747,7 +747,7 @@ mod tests { GenesisBlock::new_with_leader(10_000, leader_node.info.id, 500); genesis_block.ticks_per_slot = ticks_per_slot; - let (ledger_path, last_id) = create_new_tmp_ledger!(&genesis_block); + let (ledger_path, block_hash) = create_new_tmp_ledger!(&genesis_block); // Add entries so that the validator is in the active set, then finish up the slot with // ticks (and maybe add extra slots full of empty ticks) @@ -756,12 +756,12 @@ mod tests { &mint_keypair, 10, 0, - &last_id, + &block_hash, ticks_per_slot * (num_ending_slots + 1), ); let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap(); - let last_id = entries.last().unwrap().hash; + let block_hash = entries.last().unwrap().hash; let entry_height = ticks_per_slot + entries.len() as u64; blocktree.write_entries(1, 0, 0, entries).unwrap(); @@ -770,7 +770,7 @@ mod tests { validator_node, ledger_path, entry_height, - last_id, + block_hash, ) } } diff --git a/core/src/leader_confirmation_service.rs b/core/src/leader_confirmation_service.rs index 1ccb6695e..12769415f 100644 --- a/core/src/leader_confirmation_service.rs +++ b/core/src/leader_confirmation_service.rs @@ -154,7 +154,7 @@ mod tests { tick_hash = hash(&serialize(&tick_hash).unwrap()); bank.register_tick(&tick_hash); } - let last_id = bank.last_block_hash(); + let block_hash = bank.last_block_hash(); // Create a total of 10 vote accounts, each will have a balance of 1 (after giving 1 to // their vote account), for a total staking pool of 10 tokens. @@ -166,7 +166,7 @@ mod tests { let voting_pubkey = voting_keypair.pubkey(); // Give the validator some tokens - bank.transfer(2, &mint_keypair, validator_keypair.pubkey(), last_id) + bank.transfer(2, &mint_keypair, validator_keypair.pubkey(), block_hash) .unwrap(); new_vote_account(&validator_keypair, &voting_pubkey, &bank, 1); @@ -188,7 +188,7 @@ mod tests { // Get another validator to vote, so we now have 2/3 consensus let voting_keypair = &vote_accounts[7].0; - let vote_tx = VoteTransaction::new_vote(voting_keypair, 7, last_id, 0); + let vote_tx = VoteTransaction::new_vote(voting_keypair, 7, block_hash, 0); bank.process_transaction(&vote_tx).unwrap(); LeaderConfirmationService::compute_confirmation( diff --git a/core/src/local_cluster.rs b/core/src/local_cluster.rs index f38b555b1..0f0e3ccd0 100644 --- a/core/src/local_cluster.rs +++ b/core/src/local_cluster.rs @@ -34,7 +34,7 @@ impl LocalCluster { let leader_node = Node::new_localhost_with_pubkey(leader_keypair.pubkey()); let (genesis_block, mint_keypair) = GenesisBlock::new_with_leader(cluster_lamports, leader_pubkey, lamports_per_node); - let (genesis_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block); + let (genesis_ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block); let leader_ledger_path = tmp_copy_blocktree!(&genesis_ledger_path); let mut ledger_paths = vec![]; ledger_paths.push(genesis_ledger_path.clone()); @@ -121,10 +121,10 @@ impl LocalCluster { dest_pubkey: &Pubkey, lamports: u64, ) -> u64 { - trace!("getting leader last_id"); - let last_id = client.get_recent_block_hash(); + trace!("getting leader block_hash"); + let block_hash = client.get_recent_block_hash(); let mut tx = - SystemTransaction::new_account(&source_keypair, *dest_pubkey, lamports, last_id, 0); + SystemTransaction::new_account(&source_keypair, *dest_pubkey, lamports, block_hash, 0); info!( "executing transfer of {} from {} to {}", lamports, diff --git a/core/src/poh_recorder.rs b/core/src/poh_recorder.rs index 24ca79c15..7d1a19883 100644 --- a/core/src/poh_recorder.rs +++ b/core/src/poh_recorder.rs @@ -52,14 +52,14 @@ impl PohRecorder { } // synchronize PoH with a bank - pub fn reset(&mut self, tick_height: u64, last_id: Hash) { + pub fn reset(&mut self, tick_height: u64, block_hash: Hash) { let mut cache = vec![]; info!( "reset poh from: {},{} to: {},{}", - self.poh.hash, self.poh.tick_height, last_id, tick_height, + self.poh.hash, self.poh.tick_height, block_hash, tick_height, ); std::mem::swap(&mut cache, &mut self.tick_cache); - self.poh = Poh::new(last_id, tick_height); + self.poh = Poh::new(block_hash, tick_height); } pub fn set_working_bank(&mut self, working_bank: WorkingBank) { diff --git a/core/src/replay_stage.rs b/core/src/replay_stage.rs index e0e1b53c0..075145c7c 100644 --- a/core/src/replay_stage.rs +++ b/core/src/replay_stage.rs @@ -152,7 +152,7 @@ impl ReplayStage { ); to_leader_sender.send(TvuRotationInfo { tick_height: parent.tick_height(), - last_id: parent.last_block_hash(), + block_hash: parent.last_block_hash(), slot: next_slot, leader_id: next_leader, })?; @@ -329,7 +329,7 @@ mod test { let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(10_000, leader_id, 500); - let (my_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block); + let (my_ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block); // Set up the cluster info let cluster_info_me = Arc::new(RwLock::new(ClusterInfo::new(my_node.info.clone()))); @@ -383,10 +383,10 @@ mod test { let (forward_entry_sender, forward_entry_receiver) = channel(); let genesis_block = GenesisBlock::new(10_000).0; let bank = Arc::new(Bank::new(&genesis_block)); - let mut last_id = bank.last_block_hash(); + let mut block_hash = bank.last_block_hash(); let mut entries = Vec::new(); for _ in 0..5 { - let entry = next_entry_mut(&mut last_id, 1, vec![]); //just ticks + let entry = next_entry_mut(&mut block_hash, 1, vec![]); //just ticks entries.push(entry); } diff --git a/core/src/replicator.rs b/core/src/replicator.rs index d2d8ddd39..089025cad 100644 --- a/core/src/replicator.rs +++ b/core/src/replicator.rs @@ -80,7 +80,7 @@ pub fn sample_file(in_path: &Path, sample_offsets: &[u64]) -> io::Result { Ok(hasher.result()) } -fn get_entry_heights_from_last_id( +fn get_entry_heights_from_block_hash( signature: &ring::signature::Signature, storage_entry_height: u64, ) -> u64 { @@ -159,10 +159,10 @@ impl Replicator { info!("Got leader: {:?}", leader); let (storage_block_hash, storage_entry_height) = - Self::poll_for_last_id_and_entry_height(&cluster_info)?; + Self::poll_for_block_hash_and_entry_height(&cluster_info)?; let signature = keypair.sign(storage_block_hash.as_ref()); - let entry_height = get_entry_heights_from_last_id(&signature, storage_entry_height); + let entry_height = get_entry_heights_from_block_hash(&signature, storage_entry_height); info!("replicating entry_height: {}", entry_height); @@ -254,12 +254,12 @@ impl Replicator { match sample_file(&ledger_data_file_encrypted, &sampling_offsets) { Ok(hash) => { - let last_id = client.get_recent_block_hash(); + let block_hash = client.get_recent_block_hash(); info!("sampled hash: {}", hash); let mut tx = StorageTransaction::new_mining_proof( &keypair, hash, - last_id, + block_hash, entry_height, Signature::new(signature.as_ref()), ); @@ -326,7 +326,7 @@ impl Replicator { } } - fn poll_for_last_id_and_entry_height( + fn poll_for_block_hash_and_entry_height( cluster_info: &Arc>, ) -> Result<(String, u64)> { for _ in 0..10 { @@ -355,7 +355,7 @@ impl Replicator { } Err(Error::new( ErrorKind::Other, - "Couldn't get last_id or entry_height", + "Couldn't get block_hash or entry_height", ))? } @@ -366,12 +366,12 @@ impl Replicator { let airdrop_amount = 1; - let last_id = client.get_recent_block_hash(); + let block_hash = client.get_recent_block_hash(); match request_airdrop_transaction( &drone_addr, &keypair.pubkey(), airdrop_amount, - last_id, + block_hash, ) { Ok(transaction) => { let signature = client.transfer_signed(&transaction).unwrap(); diff --git a/core/src/rpc.rs b/core/src/rpc.rs index fcf24c79c..8279c3509 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -255,8 +255,8 @@ impl RpcSol for RpcSolImpl { trace!("request_airdrop id={} tokens={}", id, tokens); let pubkey = verify_pubkey(id)?; - let last_id = meta.request_processor.read().unwrap().bank()?.last_block_hash(); - let transaction = request_airdrop_transaction(&meta.drone_addr, &pubkey, tokens, last_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() @@ -370,8 +370,8 @@ mod tests { let (genesis_block, alice) = GenesisBlock::new(10_000); let bank = Arc::new(Bank::new(&genesis_block)); - let last_id = bank.last_block_hash(); - let tx = SystemTransaction::new_move(&alice, pubkey, 20, last_id, 0); + let block_hash = bank.last_block_hash(); + let tx = SystemTransaction::new_move(&alice, pubkey, 20, block_hash, 0); bank.process_transaction(&tx).expect("process transaction"); let request_processor = Arc::new(RwLock::new(JsonRpcRequestProcessor::new( @@ -395,7 +395,7 @@ mod tests { drone_addr, rpc_addr, }; - (io, meta, last_id, alice) + (io, meta, block_hash, alice) } #[test] @@ -406,8 +406,8 @@ mod tests { let mut request_processor = JsonRpcRequestProcessor::new(StorageState::default()); request_processor.set_bank(&bank); thread::spawn(move || { - let last_id = bank.last_block_hash(); - let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, last_id, 0); + let block_hash = bank.last_block_hash(); + let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, block_hash, 0); bank.process_transaction(&tx).expect("process transaction"); }) .join() @@ -418,7 +418,7 @@ mod tests { #[test] fn test_rpc_get_balance() { let bob_pubkey = Keypair::new().pubkey(); - let (io, meta, _last_id, _alice) = start_rpc_handler_with_tx(bob_pubkey); + let (io, meta, _block_hash, _alice) = start_rpc_handler_with_tx(bob_pubkey); let req = format!( r#"{{"jsonrpc":"2.0","id":1,"method":"getBalance","params":["{}"]}}"#, @@ -436,7 +436,7 @@ mod tests { #[test] fn test_rpc_get_tx_count() { let bob_pubkey = Keypair::new().pubkey(); - let (io, meta, _last_id, _alice) = start_rpc_handler_with_tx(bob_pubkey); + let (io, meta, _block_hash, _alice) = start_rpc_handler_with_tx(bob_pubkey); let req = format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getTransactionCount"}}"#); let res = io.handle_request_sync(&req, meta); @@ -451,7 +451,7 @@ mod tests { #[test] fn test_rpc_get_account_info() { let bob_pubkey = Keypair::new().pubkey(); - let (io, meta, _last_id, _alice) = start_rpc_handler_with_tx(bob_pubkey); + let (io, meta, _block_hash, _alice) = start_rpc_handler_with_tx(bob_pubkey); let req = format!( r#"{{"jsonrpc":"2.0","id":1,"method":"getAccountInfo","params":["{}"]}}"#, @@ -478,8 +478,8 @@ mod tests { #[test] fn test_rpc_confirm_tx() { let bob_pubkey = Keypair::new().pubkey(); - let (io, meta, last_id, alice) = start_rpc_handler_with_tx(bob_pubkey); - let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, last_id, 0); + let (io, meta, block_hash, alice) = start_rpc_handler_with_tx(bob_pubkey); + let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, block_hash, 0); let req = format!( r#"{{"jsonrpc":"2.0","id":1,"method":"confirmTransaction","params":["{}"]}}"#, @@ -497,8 +497,8 @@ mod tests { #[test] fn test_rpc_get_signature_status() { let bob_pubkey = Keypair::new().pubkey(); - let (io, meta, last_id, alice) = start_rpc_handler_with_tx(bob_pubkey); - let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, last_id, 0); + let (io, meta, block_hash, alice) = start_rpc_handler_with_tx(bob_pubkey); + let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, block_hash, 0); let req = format!( r#"{{"jsonrpc":"2.0","id":1,"method":"getSignatureStatus","params":["{}"]}}"#, @@ -513,7 +513,7 @@ mod tests { assert_eq!(expected, result); // Test getSignatureStatus request on unprocessed tx - let tx = SystemTransaction::new_move(&alice, bob_pubkey, 10, last_id, 0); + let tx = SystemTransaction::new_move(&alice, bob_pubkey, 10, block_hash, 0); let req = format!( r#"{{"jsonrpc":"2.0","id":1,"method":"getSignatureStatus","params":["{}"]}}"#, tx.signatures[0] @@ -530,11 +530,11 @@ mod tests { #[test] fn test_rpc_get_recent_block_hash() { let bob_pubkey = Keypair::new().pubkey(); - let (io, meta, last_id, _alice) = start_rpc_handler_with_tx(bob_pubkey); + let (io, meta, block_hash, _alice) = start_rpc_handler_with_tx(bob_pubkey); let req = format!(r#"{{"jsonrpc":"2.0","id":1,"method":"getLastId"}}"#); let res = io.handle_request_sync(&req, meta); - let expected = format!(r#"{{"jsonrpc":"2.0","result":"{}","id":1}}"#, last_id); + let expected = format!(r#"{{"jsonrpc":"2.0","result":"{}","id":1}}"#, block_hash); let expected: Response = serde_json::from_str(&expected).expect("expected response deserialization"); let result: Response = serde_json::from_str(&res.expect("actual response")) @@ -545,7 +545,7 @@ mod tests { #[test] fn test_rpc_fail_request_airdrop() { let bob_pubkey = Keypair::new().pubkey(); - let (io, meta, _last_id, _alice) = start_rpc_handler_with_tx(bob_pubkey); + let (io, meta, _block_hash, _alice) = start_rpc_handler_with_tx(bob_pubkey); // Expect internal error because no leader is running let req = format!( diff --git a/core/src/rpc_mock.rs b/core/src/rpc_mock.rs index eda4a3e69..89236aaaa 100644 --- a/core/src/rpc_mock.rs +++ b/core/src/rpc_mock.rs @@ -98,14 +98,14 @@ pub fn request_airdrop_transaction( _drone_addr: &SocketAddr, _id: &Pubkey, tokens: u64, - _last_id: Hash, + _block_hash: Hash, ) -> Result { if tokens == 0 { Err(Error::new(ErrorKind::Other, "Airdrop failed"))? } let key = Keypair::new(); let to = Keypair::new().pubkey(); - let last_id = Hash::default(); - let tx = SystemTransaction::new_account(&key, to, 50, last_id, 0); + let block_hash = Hash::default(); + let tx = SystemTransaction::new_account(&key, to, 50, block_hash, 0); Ok(tx) } diff --git a/core/src/rpc_pubsub.rs b/core/src/rpc_pubsub.rs index 716409483..0fa912343 100644 --- a/core/src/rpc_pubsub.rs +++ b/core/src/rpc_pubsub.rs @@ -203,12 +203,12 @@ mod tests { let bob_pubkey = bob.pubkey(); let bank = Bank::new(&genesis_block); let arc_bank = Arc::new(bank); - let last_id = arc_bank.last_block_hash(); + let block_hash = arc_bank.last_block_hash(); let rpc = RpcSolPubSubImpl::default(); // Test signature subscriptions - let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, last_id, 0); + let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, block_hash, 0); let session = create_session(); let (subscriber, _id_receiver, mut receiver) = @@ -232,7 +232,7 @@ mod tests { let bob_pubkey = Keypair::new().pubkey(); let bank = Bank::new(&genesis_block); let arc_bank = Arc::new(bank); - let last_id = arc_bank.last_block_hash(); + let block_hash = arc_bank.last_block_hash(); let session = create_session(); @@ -240,7 +240,7 @@ mod tests { let rpc = RpcSolPubSubImpl::default(); io.extend_with(rpc.to_delegate()); - let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, last_id, 0); + let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, block_hash, 0); let req = format!( r#"{{"jsonrpc":"2.0","id":1,"method":"signatureSubscribe","params":["{}"]}}"#, tx.signatures[0].to_string() @@ -279,7 +279,7 @@ mod tests { let executable = false; // TODO let bank = Bank::new(&genesis_block); let arc_bank = Arc::new(bank); - let last_id = arc_bank.last_block_hash(); + let block_hash = arc_bank.last_block_hash(); let rpc = RpcSolPubSubImpl::default(); let session = create_session(); @@ -289,7 +289,7 @@ mod tests { let tx = SystemTransaction::new_program_account( &alice, contract_funds.pubkey(), - last_id, + block_hash, 50, 0, budget_program_id, @@ -300,7 +300,7 @@ mod tests { let tx = SystemTransaction::new_program_account( &alice, contract_state.pubkey(), - last_id, + block_hash, 1, 196, budget_program_id, @@ -342,7 +342,7 @@ mod tests { witness.pubkey(), None, 50, - last_id, + block_hash, ); let arc_bank = process_transaction_and_notify(&arc_bank, &tx, &rpc.subscriptions).unwrap(); sleep(Duration::from_millis(200)); @@ -371,14 +371,14 @@ mod tests { assert_eq!(serde_json::to_string(&expected).unwrap(), response); } - let tx = SystemTransaction::new_account(&alice, witness.pubkey(), 1, last_id, 0); + let tx = SystemTransaction::new_account(&alice, witness.pubkey(), 1, block_hash, 0); let arc_bank = process_transaction_and_notify(&arc_bank, &tx, &rpc.subscriptions).unwrap(); sleep(Duration::from_millis(200)); let tx = BudgetTransaction::new_signature( &witness, contract_state.pubkey(), bob_pubkey, - last_id, + block_hash, ); let arc_bank = process_transaction_and_notify(&arc_bank, &tx, &rpc.subscriptions).unwrap(); sleep(Duration::from_millis(200)); diff --git a/core/src/rpc_request.rs b/core/src/rpc_request.rs index eb4694926..496cc1cff 100644 --- a/core/src/rpc_request.rs +++ b/core/src/rpc_request.rs @@ -275,16 +275,16 @@ mod tests { ); assert_eq!(balance.unwrap().as_u64().unwrap(), 50); - let last_id = rpc_client.make_rpc_request(2, RpcRequest::GetLastId, None); + let block_hash = rpc_client.make_rpc_request(2, RpcRequest::GetLastId, None); assert_eq!( - last_id.unwrap().as_str().unwrap(), + block_hash.unwrap().as_str().unwrap(), "deadbeefXjn8o3yroDHxUtKsZZgoy4GPkPPXfouKNHhx" ); // Send erroneous parameter - let last_id = + let block_hash = rpc_client.make_rpc_request(3, RpcRequest::GetLastId, Some(json!("paramter"))); - assert_eq!(last_id.is_err(), true); + assert_eq!(block_hash.is_err(), true); } #[test] diff --git a/core/src/rpc_subscriptions.rs b/core/src/rpc_subscriptions.rs index 5d61c6c62..065ea1362 100644 --- a/core/src/rpc_subscriptions.rs +++ b/core/src/rpc_subscriptions.rs @@ -156,11 +156,11 @@ mod tests { let (genesis_block, mint_keypair) = GenesisBlock::new(100); let bank = Bank::new(&genesis_block); let alice = Keypair::new(); - let last_id = bank.last_block_hash(); + let block_hash = bank.last_block_hash(); let tx = SystemTransaction::new_program_account( &mint_keypair, alice.pubkey(), - last_id, + block_hash, 1, 16, budget_program::id(), @@ -201,8 +201,8 @@ mod tests { let (genesis_block, mint_keypair) = GenesisBlock::new(100); let bank = Bank::new(&genesis_block); let alice = Keypair::new(); - let last_id = bank.last_block_hash(); - let tx = SystemTransaction::new_move(&mint_keypair, alice.pubkey(), 20, last_id, 0); + let block_hash = bank.last_block_hash(); + let tx = SystemTransaction::new_move(&mint_keypair, alice.pubkey(), 20, block_hash, 0); let signature = tx.signatures[0]; bank.process_transaction(&tx).unwrap(); diff --git a/core/src/sigverify.rs b/core/src/sigverify.rs index 4ed44ee91..4a1cb0bca 100644 --- a/core/src/sigverify.rs +++ b/core/src/sigverify.rs @@ -495,7 +495,7 @@ mod tests { let keypairs = vec![&keypair0, &keypair1]; let tokens = 5; let fee = 2; - let last_id = Hash::default(); + let block_hash = Hash::default(); let keys = vec![keypair0.pubkey(), keypair1.pubkey()]; @@ -508,7 +508,7 @@ mod tests { let tx = Transaction::new_with_instructions( &keypairs, &keys, - last_id, + block_hash, fee, program_ids, instructions, diff --git a/core/src/storage_stage.rs b/core/src/storage_stage.rs index e33c6cfcf..24682d497 100644 --- a/core/src/storage_stage.rs +++ b/core/src/storage_stage.rs @@ -235,10 +235,10 @@ impl StorageStage { } } - let mut last_id = None; + let mut block_hash = None; for _ in 0..10 { - if let Some(new_last_id) = client.try_get_recent_block_hash(1) { - last_id = Some(new_last_id); + if let Some(new_block_hash) = client.try_get_recent_block_hash(1) { + block_hash = Some(new_block_hash); break; } @@ -247,8 +247,8 @@ impl StorageStage { } } - if let Some(last_id) = last_id { - tx.sign(&[keypair.as_ref()], last_id); + if let Some(block_hash) = block_hash { + tx.sign(&[keypair.as_ref()], block_hash); if exit.load(Ordering::Relaxed) { Err(io::Error::new(io::ErrorKind::Other, "exit signaled"))?; @@ -505,7 +505,7 @@ mod tests { let (genesis_block, _mint_keypair) = GenesisBlock::new(1000); let ticks_per_slot = genesis_block.ticks_per_slot; - let (ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block); + let (ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block); let entries = make_tiny_test_entries(64); let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap(); @@ -567,7 +567,7 @@ mod tests { let (genesis_block, _mint_keypair) = GenesisBlock::new(1000); let ticks_per_slot = genesis_block.ticks_per_slot;; - let (ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block); + let (ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block); let entries = make_tiny_test_entries(128); let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap(); diff --git a/core/src/thin_client.rs b/core/src/thin_client.rs index 91cfec3a4..316c2a7d4 100644 --- a/core/src/thin_client.rs +++ b/core/src/thin_client.rs @@ -123,17 +123,17 @@ impl ThinClient { tokens: u64, keypair: &Keypair, to: Pubkey, - last_id: &Hash, + block_hash: &Hash, ) -> io::Result { debug!( - "transfer: tokens={} from={:?} to={:?} last_id={:?}", + "transfer: tokens={} from={:?} to={:?} block_hash={:?}", tokens, keypair.pubkey(), to, - last_id + block_hash ); let now = Instant::now(); - let transaction = SystemTransaction::new_account(keypair, to, tokens, *last_id, 0); + let transaction = SystemTransaction::new_account(keypair, to, tokens, *block_hash, 0); let result = self.transfer_signed(&transaction); solana_metrics::submit( influxdb::Point::new("thinclient") @@ -216,7 +216,7 @@ impl ThinClient { } /// Request the last Entry ID from the server without blocking. - /// Returns the last_id Hash or None if there was no response from the server. + /// Returns the block_hash Hash or None if there was no response from the server. pub fn try_get_recent_block_hash(&mut self, mut num_retries: u64) -> Option { loop { trace!("try_get_recent_block_hash send_to {}", &self.rpc_addr); @@ -226,9 +226,9 @@ impl ThinClient { match response { Ok(value) => { - let last_id_str = value.as_str().unwrap(); - let last_id_vec = bs58::decode(last_id_str).into_vec().unwrap(); - return Some(Hash::new(&last_id_vec)); + let block_hash_str = value.as_str().unwrap(); + let block_hash_vec = bs58::decode(block_hash_str).into_vec().unwrap(); + return Some(Hash::new(&block_hash_vec)); } Err(error) => { debug!("thin_client get_recent_block_hash error: {:?}", error); @@ -254,18 +254,18 @@ impl ThinClient { /// Request a new last Entry ID from the server. This method blocks /// until the server sends a response. - pub fn get_next_last_id(&mut self, previous_last_id: &Hash) -> Hash { - self.get_next_last_id_ext(previous_last_id, &|| { + pub fn get_next_block_hash(&mut self, previous_block_hash: &Hash) -> Hash { + self.get_next_block_hash_ext(previous_block_hash, &|| { sleep(Duration::from_millis(100)); }) } - pub fn get_next_last_id_ext(&mut self, previous_last_id: &Hash, func: &Fn()) -> Hash { + pub fn get_next_block_hash_ext(&mut self, previous_block_hash: &Hash, func: &Fn()) -> Hash { loop { - let last_id = self.get_recent_block_hash(); - if last_id != *previous_last_id { - break last_id; + let block_hash = self.get_recent_block_hash(); + if block_hash != *previous_block_hash { + break block_hash; } - debug!("Got same last_id ({:?}), will retry...", last_id); + debug!("Got same block_hash ({:?}), will retry...", block_hash); func() } } @@ -468,7 +468,7 @@ pub fn new_fullnode() -> (Fullnode, NodeInfo, Keypair, String) { let node_info = node.info.clone(); let (genesis_block, mint_keypair) = GenesisBlock::new_with_leader(10_000, node_info.id, 42); - let (ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block); + let (ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block); let vote_account_keypair = Arc::new(Keypair::new()); let voting_keypair = VotingKeypair::new_local(&vote_account_keypair); @@ -511,10 +511,10 @@ mod tests { let transaction_count = client.transaction_count(); assert_eq!(transaction_count, 0); - let last_id = client.get_recent_block_hash(); - info!("test_thin_client last_id: {:?}", last_id); + let block_hash = client.get_recent_block_hash(); + info!("test_thin_client block_hash: {:?}", block_hash); - let signature = client.transfer(500, &alice, bob_pubkey, &last_id).unwrap(); + let signature = client.transfer(500, &alice, bob_pubkey, &block_hash).unwrap(); info!("test_thin_client signature: {:?}", signature); client.poll_for_signature(&signature).unwrap(); @@ -541,15 +541,15 @@ mod tests { let mut client = mk_client(&leader_data); - let last_id = client.get_recent_block_hash(); + let block_hash = client.get_recent_block_hash(); - let tx = SystemTransaction::new_account(&alice, bob_pubkey, 500, last_id, 0); + let tx = SystemTransaction::new_account(&alice, bob_pubkey, 500, block_hash, 0); let _sig = client.transfer_signed(&tx).unwrap(); - let last_id = client.get_recent_block_hash(); + let block_hash = client.get_recent_block_hash(); - let mut tr2 = SystemTransaction::new_account(&alice, bob_pubkey, 501, last_id, 0); + let mut tr2 = SystemTransaction::new_account(&alice, bob_pubkey, 501, block_hash, 0); let mut instruction2 = deserialize(tr2.userdata(0)).unwrap(); if let SystemInstruction::Move { ref mut tokens } = instruction2 { *tokens = 502; @@ -578,9 +578,9 @@ mod tests { // Create the validator account, transfer some tokens to that account let validator_keypair = Keypair::new(); - let last_id = client.get_recent_block_hash(); + let block_hash = client.get_recent_block_hash(); let signature = client - .transfer(500, &alice, validator_keypair.pubkey(), &last_id) + .transfer(500, &alice, validator_keypair.pubkey(), &block_hash) .unwrap(); client.poll_for_signature(&signature).unwrap(); @@ -588,12 +588,12 @@ mod tests { // Create and register the vote account let validator_vote_account_keypair = Keypair::new(); let vote_account_id = validator_vote_account_keypair.pubkey(); - let last_id = client.get_recent_block_hash(); + let block_hash = client.get_recent_block_hash(); let transaction = VoteTransaction::fund_staking_account( &validator_keypair, vote_account_id, - last_id, + block_hash, 1, 1, ); @@ -652,15 +652,15 @@ mod tests { ); let mut client = mk_client(&leader_data); - let last_id = client.get_recent_block_hash(); - info!("test_thin_client last_id: {:?}", last_id); + let block_hash = client.get_recent_block_hash(); + info!("test_thin_client block_hash: {:?}", block_hash); let starting_alice_balance = client.poll_get_balance(&alice.pubkey()).unwrap(); info!("Alice has {} tokens", starting_alice_balance); info!("Give Bob 500 tokens"); let signature = client - .transfer(500, &alice, bob_keypair.pubkey(), &last_id) + .transfer(500, &alice, bob_keypair.pubkey(), &block_hash) .unwrap(); client.poll_for_signature(&signature).unwrap(); @@ -669,7 +669,7 @@ mod tests { info!("Take Bob's 500 tokens away"); let signature = client - .transfer(500, &bob_keypair, alice.pubkey(), &last_id) + .transfer(500, &bob_keypair, alice.pubkey(), &block_hash) .unwrap(); client.poll_for_signature(&signature).unwrap(); let alice_balance = client.poll_get_balance(&alice.pubkey()).unwrap(); diff --git a/core/src/tvu.rs b/core/src/tvu.rs index bbb8c861e..23e64d1c6 100644 --- a/core/src/tvu.rs +++ b/core/src/tvu.rs @@ -34,7 +34,7 @@ use std::thread; pub struct TvuRotationInfo { pub tick_height: u64, // tick height, bank might not exist yet - pub last_id: Hash, // last_id 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 } diff --git a/core/src/voting_keypair.rs b/core/src/voting_keypair.rs index 8857ea07e..817929f65 100644 --- a/core/src/voting_keypair.rs +++ b/core/src/voting_keypair.rs @@ -1,4 +1,4 @@ -//! The `vote_signer_proxy` votes on the `last_id` of the bank at a regular cadence +//! The `vote_signer_proxy` votes on the `block_hash` of the bank at a regular cadence use crate::rpc_request::{RpcClient, RpcRequest}; use jsonrpc_core; @@ -109,11 +109,11 @@ pub mod tests { bank: &Bank, num_tokens: u64, ) { - let last_id = bank.last_block_hash(); + let block_hash = bank.last_block_hash(); let tx = VoteTransaction::fund_staking_account( from_keypair, *voting_pubkey, - last_id, + block_hash, num_tokens, 0, ); @@ -121,8 +121,8 @@ pub mod tests { } pub fn push_vote(voting_keypair: &T, bank: &Bank, slot_height: u64) { - let last_id = bank.last_block_hash(); - let tx = VoteTransaction::new_vote(voting_keypair, slot_height, last_id, 0); + let block_hash = bank.last_block_hash(); + let tx = VoteTransaction::new_vote(voting_keypair, slot_height, block_hash, 0); bank.process_transaction(&tx).unwrap(); } diff --git a/drone/src/drone.rs b/drone/src/drone.rs index 66aab8460..7c8db65f5 100644 --- a/drone/src/drone.rs +++ b/drone/src/drone.rs @@ -50,7 +50,7 @@ pub enum DroneRequest { GetAirdrop { tokens: u64, to: Pubkey, - last_id: Hash, + block_hash: Hash, }, } @@ -110,7 +110,7 @@ impl Drone { DroneRequest::GetAirdrop { tokens, to, - last_id, + block_hash, } => { if self.check_request_limit(tokens) { self.request_current += tokens; @@ -137,11 +137,11 @@ impl Drone { &[to], system_program::id(), &create_instruction, - last_id, + block_hash, 0, /*fee*/ ); - transaction.sign(&[&self.mint_keypair], last_id); + transaction.sign(&[&self.mint_keypair], block_hash); Ok(transaction) } else { Err(Error::new(ErrorKind::Other, "token limit reached")) @@ -194,18 +194,18 @@ pub fn request_airdrop_transaction( drone_addr: &SocketAddr, id: &Pubkey, tokens: u64, - last_id: Hash, + block_hash: Hash, ) -> Result { info!( - "request_airdrop_transaction: drone_addr={} id={} tokens={} last_id={}", - drone_addr, id, tokens, last_id + "request_airdrop_transaction: drone_addr={} id={} tokens={} block_hash={}", + drone_addr, id, tokens, block_hash ); // TODO: make this async tokio client let mut stream = TcpStream::connect_timeout(drone_addr, Duration::new(3, 0))?; stream.set_read_timeout(Some(Duration::new(10, 0)))?; let req = DroneRequest::GetAirdrop { tokens, - last_id, + block_hash, to: *id, }; let req = serialize(&req).expect("serialize drone request"); @@ -353,11 +353,11 @@ mod tests { #[test] fn test_drone_build_airdrop_transaction() { let to = Keypair::new().pubkey(); - let last_id = Hash::default(); + let block_hash = Hash::default(); let request = DroneRequest::GetAirdrop { tokens: 2, to, - last_id, + block_hash, }; let mint = Keypair::new(); @@ -368,7 +368,7 @@ mod tests { assert_eq!(tx.signatures.len(), 1); assert_eq!(tx.account_keys, vec![mint_pubkey, to]); - assert_eq!(tx.recent_block_hash, last_id); + assert_eq!(tx.recent_block_hash, block_hash); assert_eq!(tx.program_ids, vec![system_program::id()]); assert_eq!(tx.instructions.len(), 1); @@ -391,11 +391,11 @@ mod tests { #[test] fn test_process_drone_request() { let to = Keypair::new().pubkey(); - let last_id = Hash::new(&to.as_ref()); + let block_hash = Hash::new(&to.as_ref()); let tokens = 50; let req = DroneRequest::GetAirdrop { tokens, - last_id, + block_hash, to, }; let req = serialize(&req).unwrap(); @@ -413,10 +413,10 @@ mod tests { &[to], system_program::id(), &expected_instruction, - last_id, + block_hash, 0, ); - expected_tx.sign(&[&keypair], last_id); + expected_tx.sign(&[&keypair], block_hash); let expected_bytes = serialize(&expected_tx).unwrap(); let mut expected_vec_with_length = vec![0; 2]; LittleEndian::write_u16(&mut expected_vec_with_length, expected_bytes.len() as u16); diff --git a/drone/tests/local-drone.rs b/drone/tests/local-drone.rs index 67d6cb194..5dddb9ef9 100644 --- a/drone/tests/local-drone.rs +++ b/drone/tests/local-drone.rs @@ -11,7 +11,7 @@ fn test_local_drone() { let keypair = Keypair::new(); let to = Keypair::new().pubkey(); let tokens = 50; - let last_id = Hash::new(&to.as_ref()); + let block_hash = Hash::new(&to.as_ref()); let expected_instruction = SystemInstruction::CreateAccount { tokens, space: 0, @@ -22,15 +22,15 @@ fn test_local_drone() { &[to], system_program::id(), &expected_instruction, - last_id, + block_hash, 0, ); - expected_tx.sign(&[&keypair], last_id); + expected_tx.sign(&[&keypair], block_hash); let (sender, receiver) = channel(); run_local_drone(keypair, sender); let drone_addr = receiver.recv().unwrap(); - let result = request_airdrop_transaction(&drone_addr, &to, tokens, last_id); + let result = request_airdrop_transaction(&drone_addr, &to, tokens, block_hash); assert_eq!(expected_tx, result.unwrap()); } diff --git a/fullnode/src/main.rs b/fullnode/src/main.rs index ed87248de..5395e3bfa 100644 --- a/fullnode/src/main.rs +++ b/fullnode/src/main.rs @@ -74,10 +74,10 @@ fn create_and_fund_vote_account( )); } loop { - let last_id = client.get_recent_block_hash(); - info!("create_and_fund_vote_account last_id={:?}", last_id); + let block_hash = client.get_recent_block_hash(); + info!("create_and_fund_vote_account block_hash={:?}", block_hash); let transaction = - VoteTransaction::fund_staking_account(node_keypair, vote_account, last_id, 1, 1); + VoteTransaction::fund_staking_account(node_keypair, vote_account, block_hash, 1, 1); match client.transfer_signed(&transaction) { Ok(signature) => { diff --git a/ledger-tool/tests/basic.rs b/ledger-tool/tests/basic.rs index 317a3e62a..066078fec 100644 --- a/ledger-tool/tests/basic.rs +++ b/ledger-tool/tests/basic.rs @@ -38,7 +38,7 @@ fn nominal() { let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(100, keypair.pubkey(), 50); let ticks_per_slot = genesis_block.ticks_per_slot; - let (ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block); + let (ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block); let ticks = ticks_per_slot as usize; // Basic validation diff --git a/programs/native/rewards/tests/rewards.rs b/programs/native/rewards/tests/rewards.rs index 016015720..86541ad41 100644 --- a/programs/native/rewards/tests/rewards.rs +++ b/programs/native/rewards/tests/rewards.rs @@ -24,8 +24,8 @@ impl<'a> RewardsBank<'a> { rewards_id: Pubkey, lamports: u64, ) -> Result<()> { - let last_id = self.bank.last_block_hash(); - let tx = RewardsTransaction::new_account(from_keypair, rewards_id, last_id, lamports, 0); + let block_hash = self.bank.last_block_hash(); + let tx = RewardsTransaction::new_account(from_keypair, rewards_id, block_hash, lamports, 0); self.bank.process_transaction(&tx) } @@ -35,24 +35,24 @@ impl<'a> RewardsBank<'a> { vote_id: Pubkey, lamports: u64, ) -> Result<()> { - let last_id = self.bank.last_block_hash(); - let tx = VoteTransaction::fund_staking_account(from_keypair, vote_id, last_id, lamports, 0); + let block_hash = self.bank.last_block_hash(); + let tx = VoteTransaction::fund_staking_account(from_keypair, vote_id, block_hash, lamports, 0); self.bank.process_transaction(&tx) } fn submit_vote(&self, vote_keypair: &Keypair, tick_height: u64) -> Result { - let last_id = self.bank.last_block_hash(); - let tx = VoteTransaction::new_vote(vote_keypair, tick_height, last_id, 0); + let block_hash = self.bank.last_block_hash(); + let tx = VoteTransaction::new_vote(vote_keypair, tick_height, block_hash, 0); self.bank.process_transaction(&tx)?; - self.bank.register_tick(&hash(last_id.as_ref())); + self.bank.register_tick(&hash(block_hash.as_ref())); let vote_account = self.bank.get_account(&vote_keypair.pubkey()).unwrap(); Ok(VoteState::deserialize(&vote_account.userdata).unwrap()) } fn redeem_credits(&self, rewards_id: Pubkey, vote_keypair: &Keypair) -> Result { - let last_id = self.bank.last_block_hash(); - let tx = RewardsTransaction::new_redeem_credits(&vote_keypair, rewards_id, last_id, 0); + let block_hash = self.bank.last_block_hash(); + let tx = RewardsTransaction::new_redeem_credits(&vote_keypair, rewards_id, block_hash, 0); self.bank.process_transaction(&tx)?; let vote_account = self.bank.get_account(&vote_keypair.pubkey()).unwrap(); Ok(VoteState::deserialize(&vote_account.userdata).unwrap()) diff --git a/programs/native/rewards_api/src/rewards_transaction.rs b/programs/native/rewards_api/src/rewards_transaction.rs index 82b18295e..c953f3bb5 100644 --- a/programs/native/rewards_api/src/rewards_transaction.rs +++ b/programs/native/rewards_api/src/rewards_transaction.rs @@ -18,14 +18,14 @@ impl RewardsTransaction { pub fn new_account( from_keypair: &Keypair, rewards_id: Pubkey, - last_id: Hash, + block_hash: Hash, num_tokens: u64, fee: u64, ) -> Transaction { SystemTransaction::new_program_account( from_keypair, rewards_id, - last_id, + block_hash, num_tokens, RewardsState::max_size() as u64, id(), @@ -36,7 +36,7 @@ impl RewardsTransaction { pub fn new_redeem_credits( vote_keypair: &Keypair, rewards_id: Pubkey, - last_id: Hash, + block_hash: Hash, fee: u64, ) -> Transaction { let vote_id = vote_keypair.pubkey(); @@ -45,6 +45,6 @@ impl RewardsTransaction { vote_id, rewards_id, )) .push(VoteInstruction::new_clear_credits(vote_id)) - .sign(&[vote_keypair], last_id) + .sign(&[vote_keypair], block_hash) } } diff --git a/programs/native/storage/tests/storage.rs b/programs/native/storage/tests/storage.rs index 7458dd95e..a04c66677 100644 --- a/programs/native/storage/tests/storage.rs +++ b/programs/native/storage/tests/storage.rs @@ -46,21 +46,21 @@ fn test_bank_storage() { let jill = Keypair::new(); let x = 42; - let last_id = genesis_block.hash(); + let block_hash = genesis_block.hash(); let x2 = x * 2; let storage_block_hash = hash(&[x2]); - bank.register_tick(&last_id); + bank.register_tick(&block_hash); - bank.transfer(10, &alice, jill.pubkey(), last_id).unwrap(); + bank.transfer(10, &alice, jill.pubkey(), block_hash).unwrap(); - bank.transfer(10, &alice, bob.pubkey(), last_id).unwrap(); - bank.transfer(10, &alice, jack.pubkey(), last_id).unwrap(); + bank.transfer(10, &alice, bob.pubkey(), block_hash).unwrap(); + bank.transfer(10, &alice, jack.pubkey(), block_hash).unwrap(); let tx = SystemTransaction::new_program_account( &alice, bob.pubkey(), - last_id, + block_hash, 1, 4 * 1024, storage_program::id(), @@ -72,7 +72,7 @@ fn test_bank_storage() { let tx = StorageTransaction::new_advertise_recent_block_hash( &bob, storage_block_hash, - last_id, + block_hash, ENTRIES_PER_SEGMENT, ); @@ -84,7 +84,7 @@ fn test_bank_storage() { //let tx = StorageTransaction::new_mining_proof( // &jack, // Hash::default(), - // last_id, + // block_hash, // entry_height, // Signature::default(), //); diff --git a/programs/native/vote/tests/vote.rs b/programs/native/vote/tests/vote.rs index b7ddac4b5..0e8ce949c 100644 --- a/programs/native/vote/tests/vote.rs +++ b/programs/native/vote/tests/vote.rs @@ -26,16 +26,16 @@ impl<'a> VoteBank<'a> { vote_id: Pubkey, lamports: u64, ) -> Result<()> { - let last_id = self.bank.last_block_hash(); - let tx = VoteTransaction::fund_staking_account(from_keypair, vote_id, last_id, lamports, 0); + let block_hash = self.bank.last_block_hash(); + let tx = VoteTransaction::fund_staking_account(from_keypair, vote_id, block_hash, lamports, 0); self.bank.process_transaction(&tx) } fn submit_vote(&self, vote_keypair: &Keypair, tick_height: u64) -> Result { - let last_id = self.bank.last_block_hash(); - let tx = VoteTransaction::new_vote(vote_keypair, tick_height, last_id, 0); + let block_hash = self.bank.last_block_hash(); + let tx = VoteTransaction::new_vote(vote_keypair, tick_height, block_hash, 0); self.bank.process_transaction(&tx)?; - self.bank.register_tick(&hash(last_id.as_ref())); + self.bank.register_tick(&hash(block_hash.as_ref())); let vote_account = self.bank.get_account(&vote_keypair.pubkey()).unwrap(); Ok(VoteState::deserialize(&vote_account.userdata).unwrap()) @@ -71,7 +71,7 @@ fn test_vote_via_bank_with_no_signature() { .unwrap(); let mallory_id = mallory_keypair.pubkey(); - let last_id = bank.last_block_hash(); + let block_hash = bank.last_block_hash(); let vote_ix = BuilderInstruction::new( vote_program::id(), &VoteInstruction::Vote(Vote::new(0)), @@ -84,7 +84,7 @@ fn test_vote_via_bank_with_no_signature() { let tx = TransactionBuilder::default() .push(SystemInstruction::new_move(mallory_id, vote_id, 1)) .push(vote_ix) - .sign(&[&mallory_keypair], last_id); + .sign(&[&mallory_keypair], block_hash); let result = bank.process_transaction(&tx); diff --git a/runtime/benches/bloom.rs b/runtime/benches/bloom.rs index cb5b90192..8841e4321 100644 --- a/runtime/benches/bloom.rs +++ b/runtime/benches/bloom.rs @@ -44,15 +44,15 @@ fn bench_sigs_bloom(bencher: &mut Bencher) { // 1M TPS * 1s (length of block in sigs) == 1M items in filter // 1.0E-8 false positive rate // https://hur.st/bloomfilter/?n=1000000&p=1.0E-8&m=&k= - let last_id = hash(Hash::default().as_ref()); - // eprintln!("last_id = {:?}", last_id); + let block_hash = hash(Hash::default().as_ref()); + // eprintln!("block_hash = {:?}", block_hash); let keys = (0..27) .into_iter() - .map(|i| last_id.hash_at_index(i)) + .map(|i| block_hash.hash_at_index(i)) .collect(); let mut sigs: Bloom = Bloom::new(38_340_234, keys); - let mut id = last_id; + let mut id = block_hash; let mut falses = 0; let mut iterations = 0; bencher.iter(|| { @@ -76,11 +76,11 @@ fn bench_sigs_bloom(bencher: &mut Bencher) { #[ignore] fn bench_sigs_hashmap(bencher: &mut Bencher) { // same structure as above, new - let last_id = hash(Hash::default().as_ref()); - // eprintln!("last_id = {:?}", last_id); + let block_hash = hash(Hash::default().as_ref()); + // eprintln!("block_hash = {:?}", block_hash); let mut sigs: HashSet = HashSet::new(); - let mut id = last_id; + let mut id = block_hash; let mut falses = 0; let mut iterations = 0; bencher.iter(|| { diff --git a/runtime/src/accounts.rs b/runtime/src/accounts.rs index d5609aa33..dc82c295a 100644 --- a/runtime/src/accounts.rs +++ b/runtime/src/accounts.rs @@ -27,9 +27,9 @@ pub struct ErrorCounters { pub account_not_found: usize, pub account_in_use: usize, pub account_loaded_twice: usize, - pub last_id_not_found: usize, - pub last_id_too_old: usize, - pub reserve_last_id: usize, + pub block_hash_not_found: usize, + pub block_hash_too_old: usize, + pub reserve_block_hash: usize, pub insufficient_funds: usize, pub duplicate_signature: usize, pub call_chain_too_deep: usize, diff --git a/runtime/src/bank.rs b/runtime/src/bank.rs index c81545156..2e27f3fbc 100644 --- a/runtime/src/bank.rs +++ b/runtime/src/bank.rs @@ -426,7 +426,7 @@ impl Bank { .zip(lock_results.into_iter()) .map(|(tx, lock_res)| { if lock_res.is_ok() && !hash_queue.check_entry_age(tx.recent_block_hash, max_age) { - error_counters.reserve_last_id += 1; + error_counters.reserve_block_hash += 1; Err(BankError::BlockHashNotFound) } else { lock_res @@ -523,16 +523,16 @@ impl Bank { .increment_transaction_count(self.accounts_id, tx_count); inc_new_counter_info!("bank-process_transactions-txs", tx_count); - if 0 != error_counters.last_id_not_found { + if 0 != error_counters.block_hash_not_found { inc_new_counter_info!( - "bank-process_transactions-error-last_id_not_found", - error_counters.last_id_not_found + "bank-process_transactions-error-block_hash_not_found", + error_counters.block_hash_not_found ); } - if 0 != error_counters.reserve_last_id { + if 0 != error_counters.reserve_block_hash { inc_new_counter_info!( - "bank-process_transactions-error-reserve_last_id", - error_counters.reserve_last_id + "bank-process_transactions-error-reserve_block_hash", + error_counters.reserve_block_hash ); } if 0 != error_counters.duplicate_signature { @@ -633,15 +633,15 @@ impl Bank { } /// Create, sign, and process a Transaction from `keypair` to `to` of - /// `n` tokens where `last_id` is the last Entry ID observed by the client. + /// `n` tokens where `block_hash` is the last Entry ID observed by the client. pub fn transfer( &self, n: u64, keypair: &Keypair, to: Pubkey, - last_id: Hash, + block_hash: Hash, ) -> Result { - let tx = SystemTransaction::new_account(keypair, to, n, last_id, 0); + let tx = SystemTransaction::new_account(keypair, to, n, block_hash, 0); let signature = tx.signatures[0]; self.process_transaction(&tx).map(|_| signature) } diff --git a/runtime/src/status_cache.rs b/runtime/src/status_cache.rs index 59140b49c..f03e90678 100644 --- a/runtime/src/status_cache.rs +++ b/runtime/src/status_cache.rs @@ -31,8 +31,8 @@ impl Default for StatusCache { } impl StatusCache { - pub fn new(last_id: &Hash) -> Self { - let keys = (0..27).map(|i| last_id.hash_at_index(i)).collect(); + pub fn new(block_hash: &Hash) -> Self { + let keys = (0..27).map(|i| block_hash.hash_at_index(i)).collect(); Self { signatures: Bloom::new(38_340_234, keys), failures: HashMap::new(), @@ -118,8 +118,8 @@ impl StatusCache { } /// Crate a new cache, pushing the old cache into the merged queue - pub fn new_cache(&mut self, last_id: &Hash) { - let mut old = Self::new(last_id); + pub fn new_cache(&mut self, block_hash: &Hash) { + let mut old = Self::new(block_hash); std::mem::swap(&mut old.signatures, &mut self.signatures); std::mem::swap(&mut old.failures, &mut self.failures); assert!(old.merges.is_empty()); @@ -175,8 +175,8 @@ mod tests { #[test] fn test_has_signature() { let sig = Signature::default(); - let last_id = hash(Hash::default().as_ref()); - let mut status_cache = BankStatusCache::new(&last_id); + let block_hash = hash(Hash::default().as_ref()); + let mut status_cache = BankStatusCache::new(&block_hash); assert_eq!(status_cache.has_signature(&sig), false); assert_eq!(status_cache.get_signature_status(&sig), None); status_cache.add(&sig); @@ -187,12 +187,12 @@ mod tests { #[test] fn test_has_signature_checkpoint() { let sig = Signature::default(); - let last_id = hash(Hash::default().as_ref()); - let mut first = BankStatusCache::new(&last_id); + let block_hash = hash(Hash::default().as_ref()); + let mut first = BankStatusCache::new(&block_hash); first.add(&sig); assert_eq!(first.get_signature_status(&sig), Some(Ok(()))); - let last_id = hash(last_id.as_ref()); - let second = StatusCache::new(&last_id); + let block_hash = hash(block_hash.as_ref()); + let second = StatusCache::new(&block_hash); let checkpoints = [&second, &first]; assert_eq!( BankStatusCache::get_signature_status_all(&checkpoints, &sig), @@ -204,12 +204,12 @@ mod tests { #[test] fn test_new_cache() { let sig = Signature::default(); - let last_id = hash(Hash::default().as_ref()); - let mut first = BankStatusCache::new(&last_id); + let block_hash = hash(Hash::default().as_ref()); + let mut first = BankStatusCache::new(&block_hash); first.add(&sig); assert_eq!(first.get_signature_status(&sig), Some(Ok(()))); - let last_id = hash(last_id.as_ref()); - first.new_cache(&last_id); + let block_hash = hash(block_hash.as_ref()); + first.new_cache(&block_hash); assert_eq!(first.get_signature_status(&sig), Some(Ok(()))); assert!(first.has_signature(&sig)); first.clear(); @@ -220,13 +220,13 @@ mod tests { #[test] fn test_new_cache_full() { let sig = Signature::default(); - let last_id = hash(Hash::default().as_ref()); - let mut first = BankStatusCache::new(&last_id); + let block_hash = hash(Hash::default().as_ref()); + let mut first = BankStatusCache::new(&block_hash); first.add(&sig); assert_eq!(first.get_signature_status(&sig), Some(Ok(()))); for _ in 0..(MAX_CACHE_ENTRIES + 1) { - let last_id = hash(last_id.as_ref()); - first.new_cache(&last_id); + let block_hash = hash(block_hash.as_ref()); + first.new_cache(&block_hash); } assert_eq!(first.get_signature_status(&sig), None); assert!(!first.has_signature(&sig)); @@ -235,17 +235,17 @@ mod tests { #[test] fn test_status_cache_squash_has_signature() { let sig = Signature::default(); - let last_id = hash(Hash::default().as_ref()); - let mut first = BankStatusCache::new(&last_id); + let block_hash = hash(Hash::default().as_ref()); + let mut first = BankStatusCache::new(&block_hash); first.add(&sig); assert_eq!(first.get_signature_status(&sig), Some(Ok(()))); // give first a merge - let last_id = hash(last_id.as_ref()); - first.new_cache(&last_id); + let block_hash = hash(block_hash.as_ref()); + first.new_cache(&block_hash); - let last_id = hash(last_id.as_ref()); - let mut second = BankStatusCache::new(&last_id); + let block_hash = hash(block_hash.as_ref()); + let mut second = BankStatusCache::new(&block_hash); second.squash(&[&first]); @@ -256,21 +256,21 @@ mod tests { #[test] #[ignore] // takes a lot of time or RAM or both.. fn test_status_cache_squash_overflow() { - let mut last_id = hash(Hash::default().as_ref()); - let mut cache = BankStatusCache::new(&last_id); + let mut block_hash = hash(Hash::default().as_ref()); + let mut cache = BankStatusCache::new(&block_hash); let parents: Vec<_> = (0..MAX_CACHE_ENTRIES) .map(|_| { - last_id = hash(last_id.as_ref()); + block_hash = hash(block_hash.as_ref()); - BankStatusCache::new(&last_id) + BankStatusCache::new(&block_hash) }) .collect(); let mut parents_refs: Vec<_> = parents.iter().collect(); - last_id = hash(Hash::default().as_ref()); - let mut root = BankStatusCache::new(&last_id); + block_hash = hash(Hash::default().as_ref()); + let mut root = BankStatusCache::new(&block_hash); let sig = Signature::default(); root.add(&sig); @@ -290,8 +290,8 @@ mod tests { #[test] fn test_failure_status() { let sig = Signature::default(); - let last_id = hash(Hash::default().as_ref()); - let mut first = StatusCache::new(&last_id); + let block_hash = hash(Hash::default().as_ref()); + let mut first = StatusCache::new(&block_hash); first.add(&sig); first.save_failure_status(&sig, BankError::DuplicateSignature); assert_eq!(first.has_signature(&sig), true); @@ -304,8 +304,8 @@ mod tests { #[test] fn test_clear_signatures() { let sig = Signature::default(); - let last_id = hash(Hash::default().as_ref()); - let mut first = StatusCache::new(&last_id); + let block_hash = hash(Hash::default().as_ref()); + let mut first = StatusCache::new(&block_hash); first.add(&sig); assert_eq!(first.has_signature(&sig), true); first.save_failure_status(&sig, BankError::DuplicateSignature); @@ -320,11 +320,11 @@ mod tests { #[test] fn test_clear_signatures_all() { let sig = Signature::default(); - let last_id = hash(Hash::default().as_ref()); - let mut first = StatusCache::new(&last_id); + let block_hash = hash(Hash::default().as_ref()); + let mut first = StatusCache::new(&block_hash); first.add(&sig); assert_eq!(first.has_signature(&sig), true); - let mut second = StatusCache::new(&last_id); + let mut second = StatusCache::new(&block_hash); let mut checkpoints = [&mut second, &mut first]; BankStatusCache::clear_all(&mut checkpoints); assert_eq!( diff --git a/tests/replicator.rs b/tests/replicator.rs index 93c3782c3..23d892580 100644 --- a/tests/replicator.rs +++ b/tests/replicator.rs @@ -44,7 +44,7 @@ fn test_replicator_startup_basic() { let (genesis_block, mint_keypair) = GenesisBlock::new_with_leader(1_000_000_000, leader_info.id, 42); - let (leader_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block); + let (leader_ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block); let validator_ledger_path = tmp_copy_blocktree!(&leader_ledger_path); @@ -72,11 +72,11 @@ fn test_replicator_startup_basic() { let voting_keypair = VotingKeypair::new_local(&validator_keypair); let mut leader_client = mk_client(&leader_info); - let last_id = leader_client.get_recent_block_hash(); - debug!("last_id: {:?}", last_id); + let block_hash = leader_client.get_recent_block_hash(); + debug!("block_hash: {:?}", block_hash); leader_client - .transfer(10, &mint_keypair, validator_keypair.pubkey(), &last_id) + .transfer(10, &mint_keypair, validator_keypair.pubkey(), &block_hash) .unwrap(); let validator_node = Node::new_localhost_with_pubkey(validator_keypair.pubkey()); @@ -98,9 +98,9 @@ fn test_replicator_startup_basic() { info!("starting transfers.."); for i in 0..64 { debug!("transfer {}", i); - let last_id = leader_client.get_recent_block_hash(); + let block_hash = leader_client.get_recent_block_hash(); let mut transaction = - SystemTransaction::new_account(&mint_keypair, bob.pubkey(), 1, last_id, 0); + SystemTransaction::new_account(&mint_keypair, bob.pubkey(), 1, block_hash, 0); leader_client .retry_transfer(&mint_keypair, &mut transaction, 5) .unwrap(); @@ -116,13 +116,13 @@ fn test_replicator_startup_basic() { info!("giving replicator tokens.."); - let last_id = leader_client.get_recent_block_hash(); + let block_hash = leader_client.get_recent_block_hash(); // Give the replicator some tokens let mut tx = SystemTransaction::new_account( &mint_keypair, replicator_keypair.pubkey(), 1, - last_id, + block_hash, 0, ); leader_client @@ -238,7 +238,7 @@ fn test_replicator_startup_leader_hang() { let leader_ledger_path = "replicator_test_leader_ledger"; let (genesis_block, _mint_keypair) = GenesisBlock::new(10_000); - let (replicator_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block); + let (replicator_ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block); { let replicator_keypair = Keypair::new(); @@ -275,13 +275,13 @@ fn test_replicator_startup_ledger_hang() { let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(100, leader_keypair.pubkey(), 42); - let (replicator_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block); + let (replicator_ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block); info!("starting leader node"); let leader_node = Node::new_localhost_with_pubkey(leader_keypair.pubkey()); let leader_info = leader_node.info.clone(); - let (leader_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block); + let (leader_ledger_path, _block_hash) = create_new_tmp_ledger!(&genesis_block); let validator_ledger_path = tmp_copy_blocktree!(&leader_ledger_path); { diff --git a/tests/rpc.rs b/tests/rpc.rs index 7ff6e8048..5e4841f58 100644 --- a/tests/rpc.rs +++ b/tests/rpc.rs @@ -36,13 +36,13 @@ fn test_rpc_send_tx() { .send() .unwrap(); let json: Value = serde_json::from_str(&response.text().unwrap()).unwrap(); - let last_id_vec = bs58::decode(json["result"].as_str().unwrap()) + let block_hash_vec = bs58::decode(json["result"].as_str().unwrap()) .into_vec() .unwrap(); - let last_id = Hash::new(&last_id_vec); + let block_hash = Hash::new(&block_hash_vec); - info!("last_id: {:?}", last_id); - let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, last_id, 0); + info!("block_hash: {:?}", block_hash); + let tx = SystemTransaction::new_move(&alice, bob_pubkey, 20, block_hash, 0); let serial_tx = serialize(&tx).unwrap(); let client = reqwest::Client::new(); diff --git a/tests/tvu.rs b/tests/tvu.rs index 7d3046ceb..7606902a9 100644 --- a/tests/tvu.rs +++ b/tests/tvu.rs @@ -86,7 +86,7 @@ fn test_replay() { let tvu_addr = target1.info.tvu; let bank = Bank::new(&genesis_block); - let last_id = bank.last_block_hash(); + let block_hash = bank.last_block_hash(); let bank_forks = BankForks::new(0, bank); let bank_forks_info = vec![BankForksInfo { bank_id: 0, @@ -138,7 +138,7 @@ fn test_replay() { let num_transfers = 10; let mut transfer_amount = 501; let bob_keypair = Keypair::new(); - let mut cur_hash = last_id; + let mut cur_hash = block_hash; for i in 0..num_transfers { let entry0 = next_entry_mut(&mut cur_hash, i, vec![]); let entry_tick0 = next_entry_mut(&mut cur_hash, i + 1, vec![]); @@ -147,7 +147,7 @@ fn test_replay() { &mint_keypair, bob_keypair.pubkey(), transfer_amount, - last_id, + block_hash, 0, ); let entry_tick1 = next_entry_mut(&mut cur_hash, i + 1, vec![]); diff --git a/wallet/src/wallet.rs b/wallet/src/wallet.rs index 9fca13d65..26de63244 100644 --- a/wallet/src/wallet.rs +++ b/wallet/src/wallet.rs @@ -401,7 +401,7 @@ fn process_deploy( } } - let last_id = get_recent_block_hash(&rpc_client)?; + let block_hash = get_recent_block_hash(&rpc_client)?; let program_id = Keypair::new(); let mut file = File::open(program_location).map_err(|err| { WalletError::DynamicProgramError( @@ -418,7 +418,7 @@ fn process_deploy( let mut tx = SystemTransaction::new_program_account( &config.id, program_id.pubkey(), - last_id, + block_hash, 1, program_userdata.len() as u64, bpf_loader::id(), @@ -439,7 +439,7 @@ fn process_deploy( bpf_loader::id(), (i * USERDATA_CHUNK_SIZE) as u32, chunk.to_vec(), - last_id, + block_hash, 0, ) }) @@ -447,7 +447,7 @@ fn process_deploy( send_and_confirm_transactions(&rpc_client, write_transactions, &program_id)?; trace!("Finalizing program account"); - let mut tx = LoaderTransaction::new_finalize(&program_id, bpf_loader::id(), last_id, 0); + let mut tx = LoaderTransaction::new_finalize(&program_id, bpf_loader::id(), block_hash, 0); send_and_confirm_transaction(&rpc_client, &mut tx, &program_id).map_err(|_| { WalletError::DynamicProgramError("Program finalize transaction failed".to_string()) })?; @@ -468,10 +468,10 @@ fn process_pay( witnesses: &Option>, cancelable: Option, ) -> ProcessResult { - let last_id = get_recent_block_hash(&rpc_client)?; + let block_hash = get_recent_block_hash(&rpc_client)?; if timestamp == None && *witnesses == None { - let mut tx = SystemTransaction::new_account(&config.id, to, tokens, last_id, 0); + let mut tx = SystemTransaction::new_account(&config.id, to, tokens, block_hash, 0); let signature_str = send_and_confirm_transaction(&rpc_client, &mut tx, &config.id)?; Ok(signature_str.to_string()) } else if *witnesses == None { @@ -489,7 +489,7 @@ fn process_pay( let mut tx = SystemTransaction::new_program_account( &config.id, contract_funds.pubkey(), - last_id, + block_hash, tokens, 0, budget_program_id, @@ -501,7 +501,7 @@ fn process_pay( let mut tx = SystemTransaction::new_program_account( &config.id, contract_state.pubkey(), - last_id, + block_hash, 1, 196, budget_program_id, @@ -518,7 +518,7 @@ fn process_pay( dt_pubkey, cancelable, tokens, - last_id, + block_hash, ); let signature_str = send_and_confirm_transaction(&rpc_client, &mut tx, &config.id)?; @@ -528,7 +528,7 @@ fn process_pay( }) .to_string()) } else if timestamp == None { - let last_id = get_recent_block_hash(&rpc_client)?; + let block_hash = get_recent_block_hash(&rpc_client)?; let witness = if let Some(ref witness_vec) = *witnesses { witness_vec[0] @@ -546,7 +546,7 @@ fn process_pay( let mut tx = SystemTransaction::new_program_account( &config.id, contract_funds.pubkey(), - last_id, + block_hash, tokens, 0, budget_program_id, @@ -558,7 +558,7 @@ fn process_pay( let mut tx = SystemTransaction::new_program_account( &config.id, contract_state.pubkey(), - last_id, + block_hash, 1, 196, budget_program_id, @@ -574,7 +574,7 @@ fn process_pay( witness, cancelable, tokens, - last_id, + block_hash, ); let signature_str = send_and_confirm_transaction(&rpc_client, &mut tx, &config.id)?; @@ -589,8 +589,8 @@ fn process_pay( } fn process_cancel(rpc_client: &RpcClient, config: &WalletConfig, pubkey: Pubkey) -> ProcessResult { - let last_id = get_recent_block_hash(&rpc_client)?; - let mut tx = BudgetTransaction::new_signature(&config.id, pubkey, config.id.pubkey(), last_id); + let block_hash = get_recent_block_hash(&rpc_client)?; + let mut tx = BudgetTransaction::new_signature(&config.id, pubkey, config.id.pubkey(), block_hash); let signature_str = send_and_confirm_transaction(&rpc_client, &mut tx, &config.id)?; Ok(signature_str.to_string()) } @@ -621,9 +621,9 @@ fn process_time_elapsed( request_and_confirm_airdrop(&rpc_client, &drone_addr, &config.id, 1)?; } - let last_id = get_recent_block_hash(&rpc_client)?; + let block_hash = get_recent_block_hash(&rpc_client)?; - let mut tx = BudgetTransaction::new_timestamp(&config.id, pubkey, to, dt, last_id); + let mut tx = BudgetTransaction::new_timestamp(&config.id, pubkey, to, dt, block_hash); let signature_str = send_and_confirm_transaction(&rpc_client, &mut tx, &config.id)?; Ok(signature_str.to_string()) @@ -642,8 +642,8 @@ fn process_witness( request_and_confirm_airdrop(&rpc_client, &drone_addr, &config.id, 1)?; } - let last_id = get_recent_block_hash(&rpc_client)?; - let mut tx = BudgetTransaction::new_signature(&config.id, pubkey, to, last_id); + let block_hash = get_recent_block_hash(&rpc_client)?; + let mut tx = BudgetTransaction::new_signature(&config.id, pubkey, to, block_hash); let signature_str = send_and_confirm_transaction(&rpc_client, &mut tx, &config.id)?; Ok(signature_str.to_string()) @@ -717,41 +717,41 @@ fn get_recent_block_hash(rpc_client: &RpcClient) -> Result Result> { - let mut next_last_id_retries = 3; + let mut next_block_hash_retries = 3; loop { - let next_last_id = get_recent_block_hash(rpc_client)?; + let next_block_hash = get_recent_block_hash(rpc_client)?; if cfg!(not(test)) { - if next_last_id != *previous_last_id { - return Ok(next_last_id); + if next_block_hash != *previous_block_hash { + return Ok(next_block_hash); } } else { // When using MockRpcClient, get_recent_block_hash() returns a constant value - return Ok(next_last_id); + return Ok(next_block_hash); } - if next_last_id_retries == 0 { + if next_block_hash_retries == 0 { Err(WalletError::RpcRequestError( format!( - "Unable to fetch new last_id, last_id stuck at {:?}", - next_last_id + "Unable to fetch new block_hash, block_hash stuck at {:?}", + next_block_hash ) .to_string(), ))?; } - next_last_id_retries -= 1; + next_block_hash_retries -= 1; // Retry ~twice during a slot sleep(Duration::from_millis( 500 * DEFAULT_TICKS_PER_SLOT / NUM_TICKS_PER_SECOND, @@ -822,7 +822,7 @@ fn send_and_confirm_transaction( }; match status { RpcSignatureStatus::AccountInUse | RpcSignatureStatus::SignatureNotFound => { - // Fetch a new last_id and re-sign the transaction before sending it again + // Fetch a new block_hash and re-sign the transaction before sending it again resign_transaction(rpc_client, transaction, signer)?; send_retries -= 1; } @@ -899,13 +899,13 @@ fn send_and_confirm_transactions( } send_retries -= 1; - // Re-sign any failed transactions with a new last_id and retry - let last_id = - get_next_last_id(rpc_client, &transactions_signatures[0].0.recent_block_hash)?; + // Re-sign any failed transactions with a new block_hash and retry + let block_hash = + get_next_block_hash(rpc_client, &transactions_signatures[0].0.recent_block_hash)?; transactions = transactions_signatures .into_iter() .map(|(mut transaction, _)| { - transaction.sign(&[signer], last_id); + transaction.sign(&[signer], block_hash); transaction }) .collect(); @@ -917,8 +917,8 @@ fn resign_transaction( tx: &mut Transaction, signer_key: &Keypair, ) -> Result<(), Box> { - let last_id = get_next_last_id(rpc_client, &tx.recent_block_hash)?; - tx.sign(&[signer_key], last_id); + let block_hash = get_next_block_hash(rpc_client, &tx.recent_block_hash)?; + tx.sign(&[signer_key], block_hash); Ok(()) } @@ -928,8 +928,8 @@ pub fn request_and_confirm_airdrop( signer: &Keypair, tokens: u64, ) -> Result<(), Box> { - let last_id = get_recent_block_hash(rpc_client)?; - let mut tx = request_airdrop_transaction(drone_addr, &signer.pubkey(), tokens, last_id)?; + let block_hash = get_recent_block_hash(rpc_client)?; + let mut tx = request_airdrop_transaction(drone_addr, &signer.pubkey(), tokens, block_hash)?; send_and_confirm_transaction(rpc_client, &mut tx, signer)?; Ok(()) } @@ -1510,15 +1510,15 @@ mod tests { let rpc_client = RpcClient::new("succeeds".to_string()); let vec = bs58::decode(PUBKEY).into_vec().unwrap(); - let expected_last_id = Hash::new(&vec); + let expected_block_hash = Hash::new(&vec); - let last_id = get_recent_block_hash(&rpc_client); - assert_eq!(last_id.unwrap(), expected_last_id); + let block_hash = get_recent_block_hash(&rpc_client); + assert_eq!(block_hash.unwrap(), expected_block_hash); let rpc_client = RpcClient::new("fails".to_string()); - let last_id = get_recent_block_hash(&rpc_client); - assert!(last_id.is_err()); + let block_hash = get_recent_block_hash(&rpc_client); + assert!(block_hash.is_err()); } #[test] @@ -1527,8 +1527,8 @@ mod tests { let key = Keypair::new(); let to = Keypair::new().pubkey(); - let last_id = Hash::default(); - let tx = SystemTransaction::new_account(&key, to, 50, last_id, 0); + let block_hash = Hash::default(); + let tx = SystemTransaction::new_account(&key, to, 50, block_hash, 0); let signature = send_transaction(&rpc_client, &tx); assert_eq!(signature.unwrap(), SIGNATURE.to_string()); @@ -1563,8 +1563,8 @@ mod tests { let key = Keypair::new(); let to = Keypair::new().pubkey(); - let last_id = Hash::default(); - let mut tx = SystemTransaction::new_account(&key, to, 50, last_id, 0); + let block_hash = Hash::default(); + let mut tx = SystemTransaction::new_account(&key, to, 50, block_hash, 0); let signer = Keypair::new(); @@ -1589,9 +1589,9 @@ mod tests { let vec = bs58::decode("HUu3LwEzGRsUkuJS121jzkPJW39Kq62pXCTmTa1F9jDL") .into_vec() .unwrap(); - let last_id = Hash::new(&vec); - let prev_tx = SystemTransaction::new_account(&key, to, 50, last_id, 0); - let mut tx = SystemTransaction::new_account(&key, to, 50, last_id, 0); + let block_hash = Hash::new(&vec); + let prev_tx = SystemTransaction::new_account(&key, to, 50, block_hash, 0); + let mut tx = SystemTransaction::new_account(&key, to, 50, block_hash, 0); resign_transaction(&rpc_client, &mut tx, &key).unwrap();