Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
Update solana program to use last_valid_block_height
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyera Eulberg committed Aug 10, 2021
1 parent 4a6c743 commit 75547bc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
34 changes: 20 additions & 14 deletions cli/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use solana_client::{
rpc_config::{RpcAccountInfoConfig, RpcProgramAccountsConfig},
rpc_filter::{Memcmp, MemcmpEncodedBytes, RpcFilterType},
rpc_request::MAX_GET_SIGNATURE_STATUSES_QUERY_ITEMS,
rpc_response::Fees,
tpu_client::{TpuClient, TpuClientConfig},
};
use solana_rbpf::{
Expand All @@ -35,7 +36,6 @@ use solana_sdk::{
account_utils::StateMut,
bpf_loader, bpf_loader_deprecated,
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
clock::Slot,
commitment_config::CommitmentConfig,
instruction::Instruction,
instruction::InstructionError,
Expand Down Expand Up @@ -1943,8 +1943,12 @@ fn send_deploy_messages(
if let Some(write_messages) = write_messages {
if let Some(write_signer) = write_signer {
trace!("Writing program data");
let (blockhash, _, last_valid_slot) = rpc_client
.get_recent_blockhash_with_commitment(config.commitment)?
let Fees {
blockhash,
last_valid_block_height,
..
} = rpc_client
.get_fees_with_commitment(config.commitment)?
.value;
let mut write_transactions = vec![];
for message in write_messages.iter() {
Expand All @@ -1959,7 +1963,7 @@ fn send_deploy_messages(
write_transactions,
&[payer_signer, write_signer],
config.commitment,
last_valid_slot,
last_valid_block_height,
)
.map_err(|err| format!("Data writes to account failed: {}", err))?;
}
Expand Down Expand Up @@ -2029,7 +2033,7 @@ fn send_and_confirm_transactions_with_spinner<T: Signers>(
mut transactions: Vec<Transaction>,
signer_keys: &T,
commitment: CommitmentConfig,
mut last_valid_slot: Slot,
mut last_valid_block_height: u64,
) -> Result<(), Box<dyn error::Error>> {
let progress_bar = new_spinner_progress_bar();
let mut send_retries = 5;
Expand Down Expand Up @@ -2069,7 +2073,7 @@ fn send_and_confirm_transactions_with_spinner<T: Signers>(

// Collect statuses for all the transactions, drop those that are confirmed
loop {
let mut slot = 0;
let mut block_height = 0;
let pending_signatures = pending_transactions.keys().cloned().collect::<Vec<_>>();
for pending_signatures_chunk in
pending_signatures.chunks(MAX_GET_SIGNATURE_STATUSES_QUERY_ITEMS)
Expand All @@ -2094,20 +2098,20 @@ fn send_and_confirm_transactions_with_spinner<T: Signers>(
}
}

slot = rpc_client.get_slot()?;
block_height = rpc_client.get_block_height()?;
progress_bar.set_message(format!(
"[{}/{}] Transactions confirmed. Retrying in {} slots",
"[{}/{}] Transactions confirmed. Retrying in {} blocks",
num_transactions - pending_transactions.len(),
num_transactions,
last_valid_slot.saturating_sub(slot)
last_valid_block_height.saturating_sub(block_height)
));
}

if pending_transactions.is_empty() {
return Ok(());
}

if slot > last_valid_slot {
if block_height > last_valid_block_height {
break;
}

Expand Down Expand Up @@ -2137,10 +2141,12 @@ fn send_and_confirm_transactions_with_spinner<T: Signers>(
send_retries -= 1;

// Re-sign any failed transactions with a new blockhash and retry
let (blockhash, _fee_calculator, new_last_valid_slot) = rpc_client
.get_recent_blockhash_with_commitment(commitment)?
.value;
last_valid_slot = new_last_valid_slot;
let Fees {
blockhash,
last_valid_block_height: new_last_valid_block_height,
..
} = rpc_client.get_fees_with_commitment(commitment)?.value;
last_valid_block_height = new_last_valid_block_height;
transactions = vec![];
for (_, mut transaction) in pending_transactions.into_iter() {
transaction.try_sign(signer_keys, blockhash)?;
Expand Down
12 changes: 11 additions & 1 deletion client/src/mock_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use {
rpc_config::RpcBlockProductionConfig,
rpc_request::RpcRequest,
rpc_response::{
Response, RpcAccountBalance, RpcBlockProduction, RpcBlockProductionRange,
Response, RpcAccountBalance, RpcBlockProduction, RpcBlockProductionRange, RpcFees,
RpcResponseContext, RpcSimulateTransactionResult, RpcStakeActivation, RpcSupply,
RpcVersionInfo, RpcVoteAccountStatus, StakeActivationState,
},
Expand Down Expand Up @@ -123,6 +123,16 @@ impl RpcSender for MockSender {
context: RpcResponseContext { slot: 1 },
value: serde_json::to_value(FeeRateGovernor::default()).unwrap(),
})?,
"getFees" => serde_json::to_value(Response {
context: RpcResponseContext { slot: 1 },
value: serde_json::to_value(RpcFees {
blockhash: PUBKEY.to_string(),
fee_calculator: FeeCalculator::default(),
last_valid_slot: 42,
last_valid_block_height: 42,
})
.unwrap(),
})?,
"getSignatureStatuses" => {
let status: transaction::Result<()> = if self.url == "account_in_use" {
Err(TransactionError::AccountInUse)
Expand Down

0 comments on commit 75547bc

Please sign in to comment.