Skip to content

Commit 4087d9e

Browse files
fix(kms-connector): increase gas_limit to 300% (#324)
1 parent 35180d2 commit 4087d9e

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

  • kms-connector/simple-connector/src/gw_adapters/decryption

kms-connector/simple-connector/src/gw_adapters/decryption/adapter.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ use fhevm_gateway_rust_bindings::decryption::Decryption;
99
use std::{sync::Arc, time::Duration};
1010
use tracing::{debug, info, warn};
1111

12-
/// The max value for the `gas_limit` of a transaction.
13-
const INFINITE_GAS_LIMIT: u64 = u64::MAX;
14-
1512
/// The time to wait between two transactions attempt.
1613
const TX_INTERVAL: Duration = Duration::from_secs(3);
1714

@@ -131,16 +128,20 @@ impl<P: Provider + Clone> DecryptionAdapter<P> {
131128

132129
/// Estimates the `gas_limit` for the upcoming transaction.
133130
async fn estimate_gas(&self, id: U256, call: &mut TransactionRequest) {
134-
match self.provider.estimate_gas(call.clone()).await {
135-
Ok(gas) => info!(decryption_id = ?id, "Initial gas estimation for the tx: {gas}"),
136-
Err(e) => warn!(decryption_id = ?id, "Failed to estimate gas for the tx: {e}"),
137-
}
131+
let gas_estimation = match self.provider.estimate_gas(call.clone()).await {
132+
Ok(estimation) => estimation,
133+
Err(e) => return warn!(decryption_id = ?id, "Failed to estimate gas for the tx: {e}"),
134+
};
135+
info!(decryption_id = ?id, "Initial gas estimation for the tx: {gas_estimation}");
138136

137+
// Increase estimation to 300%
139138
// TODO: temporary workaround for out-of-gas errors
140139
// Our automatic estimation fails during gas pikes.
141140
// (see https://zama-ai.slack.com/archives/C0915Q59CKG/p1749843623276629?thread_ts=1749828466.079719&cid=C0915Q59CKG)
142-
info!(decryption_id = ?id, "Updating `gas_limit` to max value");
143-
call.gas = Some(INFINITE_GAS_LIMIT);
141+
let new_gas_value = gas_estimation.saturating_mul(3);
142+
143+
info!(decryption_id = ?id, "Updating `gas_limit` to {new_gas_value}");
144+
call.gas = Some(new_gas_value);
144145
}
145146

146147
/// Sends the requested transactions with one retry.

0 commit comments

Comments
 (0)