Rpc Client: Prevent error out on get_num_blocks_since_signature_confirmation (#9792)

automerge
This commit is contained in:
Tyera Eulberg 2020-04-29 14:12:38 -06:00 committed by GitHub
parent efb4988d10
commit 2f08b12753
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 2 deletions

View File

@ -12,7 +12,10 @@ use log::*;
use serde_json::{json, Value}; use serde_json::{json, Value};
use solana_sdk::{ use solana_sdk::{
account::Account, account::Account,
clock::{Slot, UnixTimestamp, DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT}, clock::{
Slot, UnixTimestamp, DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT,
MAX_HASH_AGE_IN_SECONDS,
},
commitment_config::CommitmentConfig, commitment_config::CommitmentConfig,
epoch_schedule::EpochSchedule, epoch_schedule::EpochSchedule,
fee_calculator::{FeeCalculator, FeeRateGovernor}, fee_calculator::{FeeCalculator, FeeRateGovernor},
@ -1131,6 +1134,7 @@ impl RpcClient {
} }
} }
}; };
let now = Instant::now();
loop { loop {
// Return when default (max) commitment is reached // Return when default (max) commitment is reached
// Failed transactions have already been eliminated, `is_some` check is sufficient // Failed transactions have already been eliminated, `is_some` check is sufficient
@ -1146,7 +1150,14 @@ impl RpcClient {
signature, signature,
)); ));
sleep(Duration::from_millis(500)); sleep(Duration::from_millis(500));
confirmations = self.get_num_blocks_since_signature_confirmation(&signature)?; confirmations = self
.get_num_blocks_since_signature_confirmation(&signature)
.unwrap_or(confirmations);
if now.elapsed().as_secs() >= MAX_HASH_AGE_IN_SECONDS as u64 {
return Err(
RpcError::ForUser("transaction not finalized. This can happen when a transaction lands in an abandoned fork. Please retry.".to_string()).into(),
);
}
} }
} }