From b9e33bea6a67fc3faae056ed5f8aabe1299056b6 Mon Sep 17 00:00:00 2001 From: Albert Llimos <53186777+albert-llimos@users.noreply.github.com> Date: Tue, 31 Oct 2023 11:05:10 +0100 Subject: [PATCH] chore: set the gas limit max in the state chain (#4174) * chore: set the gas limit max in the state chain * chore: lint * chore: clippy * chore: add bouncer deficit tests * chore: PR comment --- bouncer/shared/gaslimit_ccm.ts | 5 +---- bouncer/tests/all_concurrent_tests.ts | 5 +++-- bouncer/tests/gaslimit_ccm.ts | 22 +++++++++++++++++++++- engine/src/eth/retry_rpc.rs | 5 +---- state-chain/runtime/src/chainflip.rs | 4 +++- 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/bouncer/shared/gaslimit_ccm.ts b/bouncer/shared/gaslimit_ccm.ts index 29bdf04187..aa47e9625c 100644 --- a/bouncer/shared/gaslimit_ccm.ts +++ b/bouncer/shared/gaslimit_ccm.ts @@ -223,6 +223,7 @@ async function testGasLimitSwap( if (ccmReceived?.returnValues.ccmTestGasUsed < gasConsumption) { throw new Error(`${tag} CCM event emitted. Gas consumed is less than expected!`); } + const web3 = new Web3(process.env.ETH_ENDPOINT ?? 'http://127.0.0.1:8545'); const receipt = await web3.eth.getTransactionReceipt(ccmReceived?.txHash as string); const tx = await web3.eth.getTransaction(ccmReceived?.txHash as string); @@ -272,8 +273,6 @@ function getRandomGasConsumption(): number { } export async function testGasLimitCcmSwaps() { - console.log('=== Testing GasLimit CCM swaps ==='); - // Spam ethereum with transfers to increase the gasLimitBudget price const spamming = spamEthereum(); @@ -334,6 +333,4 @@ export async function testGasLimitCcmSwaps() { // Make sure all the spamming has stopped to avoid triggering connectivity issues when running the next test. await sleep(10000); - - console.log('=== GasLimit CCM test completed ==='); } diff --git a/bouncer/tests/all_concurrent_tests.ts b/bouncer/tests/all_concurrent_tests.ts index 692dda3569..7b37db9f5d 100755 --- a/bouncer/tests/all_concurrent_tests.ts +++ b/bouncer/tests/all_concurrent_tests.ts @@ -8,7 +8,8 @@ import { testLpApi } from '../shared/lp_api_test'; async function runAllConcurrentTests() { let stopObserving = false; - const observingBadEvents = observeBadEvents(':BroadcastAborted', () => stopObserving); + const broadcastAborted = observeBadEvents(':BroadcastAborted', () => stopObserving); + const feeDeficitRefused = observeBadEvents(':TransactionFeeDeficitRefused', () => stopObserving); await Promise.all([ testAllSwaps(), @@ -20,7 +21,7 @@ async function runAllConcurrentTests() { // Gracefully exit the broadcast abort observer stopObserving = true; - await observingBadEvents; + await Promise.all([broadcastAborted, feeDeficitRefused]); } runWithTimeout(runAllConcurrentTests(), 1800000) diff --git a/bouncer/tests/gaslimit_ccm.ts b/bouncer/tests/gaslimit_ccm.ts index f8515637a8..0d4c198c23 100755 --- a/bouncer/tests/gaslimit_ccm.ts +++ b/bouncer/tests/gaslimit_ccm.ts @@ -1,11 +1,31 @@ #!/usr/bin/env -S pnpm tsx import { testGasLimitCcmSwaps } from '../shared/gaslimit_ccm'; -import { runWithTimeout } from '../shared/utils'; +import { + runWithTimeout, + observeBadEvents, + sleep, + observeEvent, + getChainflipApi, +} from '../shared/utils'; // Running this test separately from all the concurrent tests because there will // be BroadcastAborted events emited. async function testGasLimitCcmTest() { + console.log('=== Testing GasLimit CCM swaps ==='); + + let stopObserving = false; + const feeDeficitRefused = observeBadEvents(':TransactionFeeDeficitRefused', () => stopObserving); + await testGasLimitCcmSwaps(); + + console.log('Waiting for the fee deficits to be recorded...'); + await observeEvent('ethereumBroadcaster:TransactionFeeDeficitRecorded', await getChainflipApi()); + // Wait for some blocks after the first fee deficit is recorded + await sleep(30000); + stopObserving = true; + await feeDeficitRefused; + + console.log('=== GasLimit CCM test completed ==='); } runWithTimeout(testGasLimitCcmTest(), 1800000) diff --git a/engine/src/eth/retry_rpc.rs b/engine/src/eth/retry_rpc.rs index a0bd094dbf..1fc02a584f 100644 --- a/engine/src/eth/retry_rpc.rs +++ b/engine/src/eth/retry_rpc.rs @@ -113,8 +113,6 @@ impl EthersRetryRpcApi for EthersRetryRpcClient { &self, tx: cf_chains::evm::Transaction, ) -> anyhow::Result { - // We arbitrarily set the MAX_GAS_LIMIT we are willing broadcast to 10M. - const MAX_GAS_LIMIT: u128 = 10_000_000; let log = RequestLog::new("broadcast_transaction".to_string(), Some(format!("{tx:?}"))); self.rpc_retry_client .request_with_limit( @@ -148,7 +146,7 @@ impl EthersRetryRpcApi for EthersRetryRpcClient { "Estimated gas is greater than the gas limit" )) } else { - gas_limit.min(MAX_GAS_LIMIT.into()) + gas_limit }, None => { // increase the estimate by 33% for normal transactions @@ -156,7 +154,6 @@ impl EthersRetryRpcApi for EthersRetryRpcClient { .saturating_mul(U256::from(4u64)) .checked_div(U256::from(3u64)) .unwrap() - .min(MAX_GAS_LIMIT.into()) }, }); diff --git a/state-chain/runtime/src/chainflip.rs b/state-chain/runtime/src/chainflip.rs index 7902d951aa..8dd05b8dac 100644 --- a/state-chain/runtime/src/chainflip.rs +++ b/state-chain/runtime/src/chainflip.rs @@ -136,6 +136,8 @@ impl cf_traits::WaivedFees for WaivedFees { /// We are willing to pay at most 2x the base fee. This is approximately the theoretical /// limit of the rate of increase of the base fee over 6 blocks (12.5% per block). const ETHEREUM_BASE_FEE_MULTIPLIER: FixedU64 = FixedU64::from_rational(2, 1); +// We arbitrarily set the MAX_GAS_LIMIT we are willing broadcast to 10M. +const ETHEREUM_MAX_GAS_LIMIT: u128 = 10_000_000; pub struct EthTransactionBuilder; @@ -195,7 +197,7 @@ impl TransactionBuilder> for EthTransactio .unwrap_or_else(||{ log::warn!("Current gas price for Ethereum is 0. This should never happen. Please check Chain Tracking data."); Default::default() - }) + }).min(ETHEREUM_MAX_GAS_LIMIT) .into()) } else { None