rebuild nonce and swqos strategy

This commit is contained in:
wood
2025-09-20 14:00:45 +08:00
parent 4df22f2057
commit b46582a273
7 changed files with 120 additions and 124 deletions
+15 -10
View File
@@ -2,6 +2,8 @@ use solana_hash::Hash;
use solana_sdk::{instruction::Instruction, pubkey::Pubkey, signature::Keypair, signer::Signer};
use solana_system_interface::instruction::advance_nonce_account;
use crate::common::nonce_cache::DurableNonceInfo;
/// Add nonce advance instruction to the instruction set
///
/// Nonce functionality is only used when nonce_pubkey is provided
@@ -10,26 +12,29 @@ use solana_system_interface::instruction::advance_nonce_account;
pub fn add_nonce_instruction(
instructions: &mut Vec<Instruction>,
payer: &Keypair,
nonce_account: Option<Pubkey>,
current_nonce: Option<Hash>,
// nonce_account: Option<Pubkey>,
// current_nonce: Option<Hash>,
durable_nonce: Option<DurableNonceInfo>,
) -> Result<(), anyhow::Error> {
if nonce_account.is_some() && current_nonce.is_some() {
let nonce_advance_ix = advance_nonce_account(&nonce_account.unwrap(), &payer.pubkey());
if let Some(durable_nonce) = durable_nonce {
let nonce_advance_ix = advance_nonce_account(&durable_nonce.nonce_account.unwrap(), &payer.pubkey());
instructions.push(nonce_advance_ix);
}
Ok(())
}
/// Get blockhash for transaction
/// If nonce account is used, return blockhash from nonce, otherwise return the provided recent_blockhash
pub fn get_transaction_blockhash(
recent_blockhash: Hash,
nonce_account: Option<Pubkey>,
current_nonce: Option<Hash>,
recent_blockhash: Option<Hash>,
durable_nonce: Option<DurableNonceInfo>,
// nonce_account: Option<Pubkey>,
// current_nonce: Option<Hash>,
) -> Hash {
if nonce_account.is_some() && current_nonce.is_some() {
current_nonce.unwrap()
if let Some(durable_nonce) = durable_nonce {
durable_nonce.current_nonce.unwrap()
} else {
recent_blockhash
recent_blockhash.unwrap()
}
}