Purge remaining last_id (now called block_hash)

This commit is contained in:
Michael Vines
2019-03-02 10:09:09 -08:00
committed by Greg Fitzgerald
parent 2bfad87a5f
commit 258cf21416
39 changed files with 369 additions and 369 deletions

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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<Hash>,
block_hash: Option<Hash>,
// 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::<Entry>(&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<Hash> {
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]

View File

@ -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]);

View File

@ -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<Entry>, 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,
)
}
}

View File

@ -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(

View File

@ -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,

View File

@ -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) {

View File

@ -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);
}

View File

@ -80,7 +80,7 @@ pub fn sample_file(in_path: &Path, sample_offsets: &[u64]) -> io::Result<Hash> {
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<RwLock<ClusterInfo>>,
) -> 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();

View File

@ -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!(

View File

@ -98,14 +98,14 @@ pub fn request_airdrop_transaction(
_drone_addr: &SocketAddr,
_id: &Pubkey,
tokens: u64,
_last_id: Hash,
_block_hash: Hash,
) -> Result<Transaction, Error> {
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)
}

View File

@ -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));

View File

@ -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]

View File

@ -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();

View File

@ -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,

View File

@ -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();

View File

@ -123,17 +123,17 @@ impl ThinClient {
tokens: u64,
keypair: &Keypair,
to: Pubkey,
last_id: &Hash,
block_hash: &Hash,
) -> io::Result<Signature> {
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<Hash> {
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();

View File

@ -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
}

View File

@ -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<T: KeypairUtil>(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();
}