Update thinclient to resend the same tx until its blockhash expires (#4807)
This commit is contained in:
parent
70f93cc126
commit
74a06e4230
|
@ -16,7 +16,7 @@ use solana_sdk::packet::PACKET_DATA_SIZE;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
use solana_sdk::signature::{Keypair, KeypairUtil, Signature};
|
||||||
use solana_sdk::system_instruction;
|
use solana_sdk::system_instruction;
|
||||||
use solana_sdk::timing::duration_as_ms;
|
use solana_sdk::timing::{duration_as_ms, MAX_PROCESSING_AGE};
|
||||||
use solana_sdk::transaction::{self, Transaction};
|
use solana_sdk::transaction::{self, Transaction};
|
||||||
use solana_sdk::transport::Result as TransportResult;
|
use solana_sdk::transport::Result as TransportResult;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
@ -206,17 +206,24 @@ impl ThinClient {
|
||||||
min_confirmed_blocks: usize,
|
min_confirmed_blocks: usize,
|
||||||
) -> io::Result<Signature> {
|
) -> io::Result<Signature> {
|
||||||
for x in 0..tries {
|
for x in 0..tries {
|
||||||
|
let now = Instant::now();
|
||||||
let mut buf = vec![0; serialized_size(&transaction).unwrap() as usize];
|
let mut buf = vec![0; serialized_size(&transaction).unwrap() as usize];
|
||||||
let mut wr = std::io::Cursor::new(&mut buf[..]);
|
let mut wr = std::io::Cursor::new(&mut buf[..]);
|
||||||
serialize_into(&mut wr, &transaction)
|
serialize_into(&mut wr, &transaction)
|
||||||
.expect("serialize Transaction in pub fn transfer_signed");
|
.expect("serialize Transaction in pub fn transfer_signed");
|
||||||
self.transactions_socket
|
// resend the same transaction until the transaction has no chance of succeeding
|
||||||
.send_to(&buf[..], &self.transactions_addr())?;
|
while now.elapsed().as_secs() < MAX_PROCESSING_AGE as u64 {
|
||||||
if self
|
self.transactions_socket
|
||||||
.poll_for_signature_confirmation(&transaction.signatures[0], min_confirmed_blocks)
|
.send_to(&buf[..], &self.transactions_addr())?;
|
||||||
.is_ok()
|
if self
|
||||||
{
|
.poll_for_signature_confirmation(
|
||||||
return Ok(transaction.signatures[0]);
|
&transaction.signatures[0],
|
||||||
|
min_confirmed_blocks,
|
||||||
|
)
|
||||||
|
.is_ok()
|
||||||
|
{
|
||||||
|
return Ok(transaction.signatures[0]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
info!(
|
info!(
|
||||||
"{} tries failed transfer to {}",
|
"{} tries failed transfer to {}",
|
||||||
|
|
|
@ -22,8 +22,8 @@ use solana_runtime::locked_accounts_results::LockedAccountsResults;
|
||||||
use solana_sdk::poh_config::PohConfig;
|
use solana_sdk::poh_config::PohConfig;
|
||||||
use solana_sdk::pubkey::Pubkey;
|
use solana_sdk::pubkey::Pubkey;
|
||||||
use solana_sdk::timing::{
|
use solana_sdk::timing::{
|
||||||
self, duration_as_us, DEFAULT_NUM_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT,
|
self, duration_as_us, DEFAULT_NUM_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT, MAX_PROCESSING_AGE,
|
||||||
MAX_RECENT_BLOCKHASHES, MAX_TRANSACTION_FORWARDING_DELAY,
|
MAX_TRANSACTION_FORWARDING_DELAY,
|
||||||
};
|
};
|
||||||
use solana_sdk::transaction::{self, Transaction, TransactionError};
|
use solana_sdk::transaction::{self, Transaction, TransactionError};
|
||||||
use std::net::UdpSocket;
|
use std::net::UdpSocket;
|
||||||
|
@ -423,7 +423,7 @@ impl BankingStage {
|
||||||
// TODO: Banking stage threads should be prioritized to complete faster then this queue
|
// TODO: Banking stage threads should be prioritized to complete faster then this queue
|
||||||
// expires.
|
// expires.
|
||||||
let (loaded_accounts, results) =
|
let (loaded_accounts, results) =
|
||||||
bank.load_and_execute_transactions(txs, lock_results, MAX_RECENT_BLOCKHASHES / 2);
|
bank.load_and_execute_transactions(txs, lock_results, MAX_PROCESSING_AGE);
|
||||||
let load_execute_time = now.elapsed();
|
let load_execute_time = now.elapsed();
|
||||||
|
|
||||||
let freeze_lock = bank.freeze_lock();
|
let freeze_lock = bank.freeze_lock();
|
||||||
|
@ -620,7 +620,7 @@ impl BankingStage {
|
||||||
let result = bank.check_transactions(
|
let result = bank.check_transactions(
|
||||||
transactions,
|
transactions,
|
||||||
&filter,
|
&filter,
|
||||||
(MAX_RECENT_BLOCKHASHES / 2)
|
(MAX_PROCESSING_AGE)
|
||||||
.saturating_sub(MAX_TRANSACTION_FORWARDING_DELAY)
|
.saturating_sub(MAX_TRANSACTION_FORWARDING_DELAY)
|
||||||
.saturating_sub(
|
.saturating_sub(
|
||||||
(FORWARD_TRANSACTIONS_TO_LEADER_AT_SLOT_OFFSET * bank.ticks_per_slot()
|
(FORWARD_TRANSACTIONS_TO_LEADER_AT_SLOT_OFFSET * bank.ticks_per_slot()
|
||||||
|
|
|
@ -500,7 +500,11 @@ impl Replicator {
|
||||||
> 0
|
> 0
|
||||||
);
|
);
|
||||||
// ...or no lamports for fees
|
// ...or no lamports for fees
|
||||||
assert!(client.poll_get_balance(&self.keypair.pubkey()).unwrap() > 0);
|
let balance = client.poll_get_balance(&self.keypair.pubkey()).unwrap();
|
||||||
|
if balance == 0 {
|
||||||
|
error!("Unable to submit mining proof, insufficient Replicator Account balance");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let (blockhash, _) = client.get_recent_blockhash().expect("No recent blockhash");
|
let (blockhash, _) = client.get_recent_blockhash().expect("No recent blockhash");
|
||||||
let instruction = storage_instruction::mining_proof(
|
let instruction = storage_instruction::mining_proof(
|
||||||
|
|
|
@ -26,6 +26,9 @@ pub const MAX_HASH_AGE_IN_SECONDS: usize = 120;
|
||||||
// This must be <= MAX_HASH_AGE_IN_SECONDS, otherwise there's risk for DuplicateSignature errors
|
// This must be <= MAX_HASH_AGE_IN_SECONDS, otherwise there's risk for DuplicateSignature errors
|
||||||
pub const MAX_RECENT_BLOCKHASHES: usize = MAX_HASH_AGE_IN_SECONDS;
|
pub const MAX_RECENT_BLOCKHASHES: usize = MAX_HASH_AGE_IN_SECONDS;
|
||||||
|
|
||||||
|
// The maximum age of a blockhash that will be accepted by the leader
|
||||||
|
pub const MAX_PROCESSING_AGE: usize = MAX_RECENT_BLOCKHASHES / 2;
|
||||||
|
|
||||||
/// This is maximum time consumed in forwarding a transaction from one node to next, before
|
/// This is maximum time consumed in forwarding a transaction from one node to next, before
|
||||||
/// it can be processed in the target node
|
/// it can be processed in the target node
|
||||||
#[cfg(feature = "cuda")]
|
#[cfg(feature = "cuda")]
|
||||||
|
|
Loading…
Reference in New Issue