Rename get_last_id() to get_recent_block_hash()

This commit is contained in:
Michael Vines 2019-03-02 10:01:13 -08:00 committed by Greg Fitzgerald
parent 4f3e149a98
commit ce1b72809a
11 changed files with 49 additions and 49 deletions

View File

@ -112,7 +112,7 @@ pub fn send_barrier_transaction(barrier_client: &mut ThinClient, last_id: &mut H
);
}
*last_id = barrier_client.get_last_id();
*last_id = barrier_client.get_recent_block_hash();
let signature = barrier_client
.transfer(0, &id, id.pubkey(), last_id)
.expect("Unable to send barrier transaction");
@ -154,7 +154,7 @@ pub fn send_barrier_transaction(barrier_client: &mut ThinClient, last_id: &mut H
exit(1);
}
let new_last_id = barrier_client.get_last_id();
let new_last_id = barrier_client.get_recent_block_hash();
if new_last_id == *last_id {
if poll_count > 0 && poll_count % 8 == 0 {
println!("last_id is not advancing, still at {:?}", *last_id);
@ -176,7 +176,7 @@ pub fn generate_txs(
leader: &NodeInfo,
) {
let mut client = mk_client(leader);
let last_id = client.get_last_id();
let last_id = client.get_recent_block_hash();
let tx_count = source.len();
println!("Signing transactions... {} (reclaim={})", tx_count, reclaim);
let signing_start = Instant::now();
@ -366,7 +366,7 @@ pub fn fund_keys(client: &mut ThinClient, source: &Keypair, dests: &[Keypair], t
to_fund_txs.len(),
);
let last_id = client.get_last_id();
let last_id = client.get_recent_block_hash();
// re-sign retained to_fund_txes with updated last_id
to_fund_txs.par_iter_mut().for_each(|(k, tx)| {
@ -410,7 +410,7 @@ pub fn airdrop_tokens(
id.pubkey(),
);
let last_id = client.get_last_id();
let last_id = client.get_recent_block_hash();
match request_airdrop_transaction(&drone_addr, &id.pubkey(), airdrop_amount, last_id) {
Ok(transaction) => {
let signature = client.transfer_signed(&transaction).unwrap();

View File

@ -170,7 +170,7 @@ fn main() {
airdrop_tokens(&mut barrier_client, &drone_addr, &barrier_id, 1);
println!("Get last ID...");
let mut last_id = client.get_last_id();
let mut last_id = client.get_recent_block_hash();
println!("Got last ID {:?}", last_id);
let first_tx_count = client.transaction_count();

View File

@ -27,7 +27,7 @@ pub fn spend_and_verify_all_nodes(
&funding_keypair,
random_keypair.pubkey(),
1,
client.get_last_id(),
client.get_recent_block_hash(),
0,
);
let sig = client

View File

@ -122,7 +122,7 @@ impl LocalCluster {
lamports: u64,
) -> u64 {
trace!("getting leader last_id");
let last_id = client.get_last_id();
let last_id = client.get_recent_block_hash();
let mut tx =
SystemTransaction::new_account(&source_keypair, *dest_pubkey, lamports, last_id, 0);
info!(
@ -148,7 +148,7 @@ impl LocalCluster {
let mut transaction = VoteTransaction::fund_staking_account(
from_account,
vote_account,
client.get_last_id(),
client.get_recent_block_hash(),
amount,
1,
);

View File

@ -254,7 +254,7 @@ impl Replicator {
match sample_file(&ledger_data_file_encrypted, &sampling_offsets) {
Ok(hash) => {
let last_id = client.get_last_id();
let last_id = client.get_recent_block_hash();
info!("sampled hash: {}", hash);
let mut tx = StorageTransaction::new_mining_proof(
&keypair,
@ -366,7 +366,7 @@ impl Replicator {
let airdrop_amount = 1;
let last_id = client.get_last_id();
let last_id = client.get_recent_block_hash();
match request_airdrop_transaction(
&drone_addr,
&keypair.pubkey(),

View File

@ -57,7 +57,7 @@ impl JsonRpcRequestProcessor {
Ok(val)
}
fn get_last_id(&self) -> Result<String> {
fn get_recent_block_hash(&self) -> Result<String> {
let id = self.bank()?.last_id();
Ok(bs58::encode(id).into_string())
}
@ -156,7 +156,7 @@ pub trait RpcSol {
fn get_balance(&self, _: Self::Metadata, _: String) -> Result<u64>;
#[rpc(meta, name = "getLastId")]
fn get_last_id(&self, _: Self::Metadata) -> Result<String>;
fn get_recent_block_hash(&self, _: Self::Metadata) -> Result<String>;
#[rpc(meta, name = "getSignatureStatus")]
fn get_signature_status(&self, _: Self::Metadata, _: String) -> Result<RpcSignatureStatus>;
@ -209,9 +209,9 @@ impl RpcSol for RpcSolImpl {
meta.request_processor.read().unwrap().get_balance(pubkey)
}
fn get_last_id(&self, meta: Self::Metadata) -> Result<String> {
info!("get_last_id rpc request received");
meta.request_processor.read().unwrap().get_last_id()
fn get_recent_block_hash(&self, meta: Self::Metadata) -> Result<String> {
info!("get_recent_block_hash rpc request received");
meta.request_processor.read().unwrap().get_recent_block_hash()
}
fn get_signature_status(&self, meta: Self::Metadata, id: String) -> Result<RpcSignatureStatus> {
@ -528,7 +528,7 @@ mod tests {
}
#[test]
fn test_rpc_get_last_id() {
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);

View File

@ -237,7 +237,7 @@ impl StorageStage {
let mut last_id = None;
for _ in 0..10 {
if let Some(new_last_id) = client.try_get_last_id(1) {
if let Some(new_last_id) = client.try_get_recent_block_hash(1) {
last_id = Some(new_last_id);
break;
}

View File

@ -99,7 +99,7 @@ impl ThinClient {
tries: usize,
) -> io::Result<Signature> {
for x in 0..tries {
transaction.sign(&[keypair], self.get_last_id());
transaction.sign(&[keypair], self.get_recent_block_hash());
let mut buf = vec![0; transaction.serialized_size().unwrap() as usize];
let mut wr = std::io::Cursor::new(&mut buf[..]);
serialize_into(&mut wr, &transaction)
@ -217,9 +217,9 @@ 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.
pub fn try_get_last_id(&mut self, mut num_retries: u64) -> Option<Hash> {
pub fn try_get_recent_block_hash(&mut self, mut num_retries: u64) -> Option<Hash> {
loop {
trace!("try_get_last_id send_to {}", &self.rpc_addr);
trace!("try_get_recent_block_hash send_to {}", &self.rpc_addr);
let response = self
.rpc_client
.make_rpc_request(1, RpcRequest::GetLastId, None);
@ -231,7 +231,7 @@ impl ThinClient {
return Some(Hash::new(&last_id_vec));
}
Err(error) => {
debug!("thin_client get_last_id error: {:?}", error);
debug!("thin_client get_recent_block_hash error: {:?}", error);
num_retries -= 1;
if num_retries == 0 {
return None;
@ -243,10 +243,10 @@ impl ThinClient {
/// Request the last Entry ID from the server. This method blocks
/// until the server sends a response.
pub fn get_last_id(&mut self) -> Hash {
pub fn get_recent_block_hash(&mut self) -> Hash {
loop {
trace!("get_last_id send_to {}", &self.rpc_addr);
if let Some(hash) = self.try_get_last_id(10) {
trace!("get_recent_block_hash send_to {}", &self.rpc_addr);
if let Some(hash) = self.try_get_recent_block_hash(10) {
return hash;
}
}
@ -261,7 +261,7 @@ impl ThinClient {
}
pub fn get_next_last_id_ext(&mut self, previous_last_id: &Hash, func: &Fn()) -> Hash {
loop {
let last_id = self.get_last_id();
let last_id = self.get_recent_block_hash();
if last_id != *previous_last_id {
break last_id;
}
@ -511,7 +511,7 @@ mod tests {
let transaction_count = client.transaction_count();
assert_eq!(transaction_count, 0);
let last_id = client.get_last_id();
let last_id = client.get_recent_block_hash();
info!("test_thin_client last_id: {:?}", last_id);
let signature = client.transfer(500, &alice, bob_pubkey, &last_id).unwrap();
@ -541,13 +541,13 @@ mod tests {
let mut client = mk_client(&leader_data);
let last_id = client.get_last_id();
let last_id = client.get_recent_block_hash();
let tx = SystemTransaction::new_account(&alice, bob_pubkey, 500, last_id, 0);
let _sig = client.transfer_signed(&tx).unwrap();
let last_id = client.get_last_id();
let last_id = client.get_recent_block_hash();
let mut tr2 = SystemTransaction::new_account(&alice, bob_pubkey, 501, last_id, 0);
let mut instruction2 = deserialize(tr2.userdata(0)).unwrap();
@ -578,7 +578,7 @@ mod tests {
// Create the validator account, transfer some tokens to that account
let validator_keypair = Keypair::new();
let last_id = client.get_last_id();
let last_id = client.get_recent_block_hash();
let signature = client
.transfer(500, &alice, validator_keypair.pubkey(), &last_id)
.unwrap();
@ -588,7 +588,7 @@ 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_last_id();
let last_id = client.get_recent_block_hash();
let transaction = VoteTransaction::fund_staking_account(
&validator_keypair,
@ -652,7 +652,7 @@ mod tests {
);
let mut client = mk_client(&leader_data);
let last_id = client.get_last_id();
let last_id = client.get_recent_block_hash();
info!("test_thin_client last_id: {:?}", last_id);
let starting_alice_balance = client.poll_get_balance(&alice.pubkey()).unwrap();

View File

@ -74,7 +74,7 @@ fn create_and_fund_vote_account(
));
}
loop {
let last_id = client.get_last_id();
let last_id = client.get_recent_block_hash();
info!("create_and_fund_vote_account last_id={:?}", last_id);
let transaction =
VoteTransaction::fund_staking_account(node_keypair, vote_account, last_id, 1, 1);

View File

@ -72,7 +72,7 @@ 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_last_id();
let last_id = leader_client.get_recent_block_hash();
debug!("last_id: {:?}", last_id);
leader_client
@ -98,7 +98,7 @@ fn test_replicator_startup_basic() {
info!("starting transfers..");
for i in 0..64 {
debug!("transfer {}", i);
let last_id = leader_client.get_last_id();
let last_id = leader_client.get_recent_block_hash();
let mut transaction =
SystemTransaction::new_account(&mint_keypair, bob.pubkey(), 1, last_id, 0);
leader_client
@ -116,7 +116,7 @@ fn test_replicator_startup_basic() {
info!("giving replicator tokens..");
let last_id = leader_client.get_last_id();
let last_id = leader_client.get_recent_block_hash();
// Give the replicator some tokens
let mut tx = SystemTransaction::new_account(
&mint_keypair,

View File

@ -401,7 +401,7 @@ fn process_deploy(
}
}
let last_id = get_last_id(&rpc_client)?;
let last_id = get_recent_block_hash(&rpc_client)?;
let program_id = Keypair::new();
let mut file = File::open(program_location).map_err(|err| {
WalletError::DynamicProgramError(
@ -468,7 +468,7 @@ fn process_pay(
witnesses: &Option<Vec<Pubkey>>,
cancelable: Option<Pubkey>,
) -> ProcessResult {
let last_id = get_last_id(&rpc_client)?;
let last_id = get_recent_block_hash(&rpc_client)?;
if timestamp == None && *witnesses == None {
let mut tx = SystemTransaction::new_account(&config.id, to, tokens, last_id, 0);
@ -528,7 +528,7 @@ fn process_pay(
})
.to_string())
} else if timestamp == None {
let last_id = get_last_id(&rpc_client)?;
let last_id = get_recent_block_hash(&rpc_client)?;
let witness = if let Some(ref witness_vec) = *witnesses {
witness_vec[0]
@ -589,7 +589,7 @@ fn process_pay(
}
fn process_cancel(rpc_client: &RpcClient, config: &WalletConfig, pubkey: Pubkey) -> ProcessResult {
let last_id = get_last_id(&rpc_client)?;
let last_id = get_recent_block_hash(&rpc_client)?;
let mut tx = BudgetTransaction::new_signature(&config.id, pubkey, config.id.pubkey(), last_id);
let signature_str = send_and_confirm_transaction(&rpc_client, &mut tx, &config.id)?;
Ok(signature_str.to_string())
@ -621,7 +621,7 @@ fn process_time_elapsed(
request_and_confirm_airdrop(&rpc_client, &drone_addr, &config.id, 1)?;
}
let last_id = get_last_id(&rpc_client)?;
let last_id = get_recent_block_hash(&rpc_client)?;
let mut tx = BudgetTransaction::new_timestamp(&config.id, pubkey, to, dt, last_id);
let signature_str = send_and_confirm_transaction(&rpc_client, &mut tx, &config.id)?;
@ -642,7 +642,7 @@ fn process_witness(
request_and_confirm_airdrop(&rpc_client, &drone_addr, &config.id, 1)?;
}
let last_id = get_last_id(&rpc_client)?;
let last_id = get_recent_block_hash(&rpc_client)?;
let mut tx = BudgetTransaction::new_signature(&config.id, pubkey, to, last_id);
let signature_str = send_and_confirm_transaction(&rpc_client, &mut tx, &config.id)?;
@ -713,7 +713,7 @@ pub fn process_command(config: &WalletConfig) -> ProcessResult {
}
}
fn get_last_id(rpc_client: &RpcClient) -> Result<Hash, Box<dyn error::Error>> {
fn get_recent_block_hash(rpc_client: &RpcClient) -> Result<Hash, Box<dyn error::Error>> {
let result = rpc_client.retry_make_rpc_request(1, &RpcRequest::GetLastId, None, 5)?;
if result.as_str().is_none() {
Err(WalletError::RpcRequestError(
@ -733,13 +733,13 @@ fn get_next_last_id(
) -> Result<Hash, Box<dyn error::Error>> {
let mut next_last_id_retries = 3;
loop {
let next_last_id = get_last_id(rpc_client)?;
let next_last_id = get_recent_block_hash(rpc_client)?;
if cfg!(not(test)) {
if next_last_id != *previous_last_id {
return Ok(next_last_id);
}
} else {
// When using MockRpcClient, get_last_id() returns a constant value
// When using MockRpcClient, get_recent_block_hash() returns a constant value
return Ok(next_last_id);
}
if next_last_id_retries == 0 {
@ -928,7 +928,7 @@ pub fn request_and_confirm_airdrop(
signer: &Keypair,
tokens: u64,
) -> Result<(), Box<dyn error::Error>> {
let last_id = get_last_id(rpc_client)?;
let last_id = get_recent_block_hash(rpc_client)?;
let mut tx = request_airdrop_transaction(drone_addr, &signer.pubkey(), tokens, last_id)?;
send_and_confirm_transaction(rpc_client, &mut tx, signer)?;
Ok(())
@ -1506,18 +1506,18 @@ mod tests {
}
#[test]
fn test_wallet_get_last_id() {
fn test_wallet_get_recent_block_hash() {
let rpc_client = RpcClient::new("succeeds".to_string());
let vec = bs58::decode(PUBKEY).into_vec().unwrap();
let expected_last_id = Hash::new(&vec);
let last_id = get_last_id(&rpc_client);
let last_id = get_recent_block_hash(&rpc_client);
assert_eq!(last_id.unwrap(), expected_last_id);
let rpc_client = RpcClient::new("fails".to_string());
let last_id = get_last_id(&rpc_client);
let last_id = get_recent_block_hash(&rpc_client);
assert!(last_id.is_err());
}