Skip to content

Commit

Permalink
fix: prevent compute unit calculations to exceed the max cp limit
Browse files Browse the repository at this point in the history
  • Loading branch information
eloylp committed Feb 6, 2025
1 parent 4b60662 commit e05459f
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ solana-rpc-client-api = "=2.0.16"
solana-program = "=2.0.16"
solana-sdk = "=2.0.16"
solana-transaction-status = "=2.0.16"
solana-compute-budget = "=2.0.16"

# Async
tokio = { version = "1", features = ["rt", "signal", "rt-multi-thread", "macros"] }
Expand Down
1 change: 1 addition & 0 deletions crates/effective-tx-sender/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ eyre.workspace = true
thiserror.workspace = true
solana-sdk.workspace = true
solana-client.workspace = true
solana-compute-budget.workspace = true
itertools.workspace = true
futures.workspace = true
tracing.workspace = true
Expand Down
2 changes: 2 additions & 0 deletions crates/effective-tx-sender/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use futures::TryFutureExt as _;
use itertools::Itertools as _;
use solana_client::nonblocking::rpc_client::RpcClient;
use solana_client::rpc_response::RpcSimulateTransactionResult;
use solana_compute_budget::compute_budget_processor::MAX_COMPUTE_UNIT_LIMIT;
use solana_sdk::compute_budget::ComputeBudgetInstruction;
use solana_sdk::instruction::Instruction;
use solana_sdk::signature::{Keypair, Signature};
Expand Down Expand Up @@ -198,6 +199,7 @@ pub(crate) async fn compute_budget(
.checked_div(PERCENT_POINTS_TO_TOP_UP)
.unwrap_or(0);
let compute_budget = computed_units.saturating_add(top_up);
let compute_budget = compute_budget.min(MAX_COMPUTE_UNIT_LIMIT as u64); // Safe conversion since we move from an u32 to u64
let ix = ComputeBudgetInstruction::set_compute_unit_limit(
compute_budget
.try_into()
Expand Down

0 comments on commit e05459f

Please sign in to comment.