Skip to content

Commit

Permalink
chore: addd minimum gas
Browse files Browse the repository at this point in the history
  • Loading branch information
albert-llimos committed Feb 17, 2025
1 parent ed8197c commit f289542
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
15 changes: 10 additions & 5 deletions bouncer/shared/swapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,16 @@ export async function newCcmMetadata(
let userLogicGasBudget;
if (destChain === 'Arbitrum' || destChain === 'Ethereum') {
// Do the gas estimation of the call to the CF Tester contract and add a small buffer.
// This is what integrators are expected to do and it'll give a good estimate of the gas
// needed for the user logic. Extra buffer for Arbitrum due to the gas estimation uncertainties.
userLogicGasBudget = Math.trunc(
(await estimateCcmCfTesterGas(message)) * (destChain === 'Arbitrum' ? 1.75 : 1.2),
);
// A 5-10% works for almost all swaps. However, there is some flakiness in Arbitrum for
// swaps that require small amounts of gas. That is because Arbitrum's fees in localnet
// are extremely high (two orders of magniture larger than in mainnnet) so small gas
// fluctuations cause flakiness for those CCM swaps with low gas.
// Therefore we apply a minimum gas budget to ensure the swap succeeds.
userLogicGasBudget = Math.trunc((await estimateCcmCfTesterGas(message)) * 1.1);
if (destChain === 'Arbitrum') {
const minGasBudget = 30000;
userLogicGasBudget = userLogicGasBudget < minGasBudget ? minGasBudget : userLogicGasBudget;
}
} else if (destChain === 'Solana') {
// We don't bother estimating in Solana since the gas needed doesn't really change upon the message length.
userLogicGasBudget = OVERHEAD_COMPUTE_UNITS.toString();
Expand Down
4 changes: 2 additions & 2 deletions bouncer/tests/gaslimit_ccm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import { ExecutableTest } from '../shared/executable_test';
/* eslint-disable @typescript-eslint/no-use-before-define */
export const testGasLimitCcmSwaps = new ExecutableTest('Gas-Limit-Ccm-Swaps', main, 1800);

// Minimum and maximum gas consumption values to be in a useful range for testing. Not using very low numbers
// to avoid flakiness in the tests expecting a broadcast abort due to not having enough gas.
// Minimum and maximum gas consumption values to be in a useful range for testing. The gas consumption should
// be significantly larger than the base cost of the CCM to avoid flakiness.
const RANGE_TEST_GAS_CONSUMPTION: Record<string, { min: number; max: number }> = {
Ethereum: { min: 150000, max: 1000000 },
Arbitrum: { min: 5000000, max: 15000000 },
Expand Down
4 changes: 2 additions & 2 deletions state-chain/chains/src/arb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,11 @@ mod test {
};

let gas_limit = arb_tracked_data.calculate_ccm_gas_limit(true, GAS_BUDGET, MESSAGE_LENGTH);
assert_eq!(gas_limit, 2541810u128);
assert_eq!(gas_limit, 2552810u128);

let gas_limit_token =
arb_tracked_data.calculate_ccm_gas_limit(false, GAS_BUDGET, MESSAGE_LENGTH);
assert_eq!(gas_limit_token, 2574810u128);
assert_eq!(gas_limit_token, 2585810_u128);
}

#[test]
Expand Down

0 comments on commit f289542

Please sign in to comment.