diff --git a/src/client/mod.rs b/src/client/mod.rs index 635beae4a..19728958f 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -1,5 +1,5 @@ use crate::{ - constants::ETH_CHAIN_ID, + constants::{ETH_CHAIN_ID, KKRT_BLOCK_GAS_LIMIT}, pool::{ mempool::{KakarotPool, TransactionOrdering}, validate::KakarotTransactionValidatorBuilder, @@ -65,6 +65,7 @@ where let validator = KakarotTransactionValidatorBuilder::new(&Arc::new(ChainSpec { chain: (*ETH_CHAIN_ID).into(), + max_gas_limit: KKRT_BLOCK_GAS_LIMIT, ..Default::default() })) .build::<_, EthPooledTransaction>(eth_provider.clone()); diff --git a/src/constants.rs b/src/constants.rs index b99dd8013..0fa64abb7 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -29,3 +29,6 @@ pub static KAKAROT_RPC_CONFIG: LazyLock = /// The RPC configuration. pub static RPC_CONFIG: LazyLock = LazyLock::new(|| RPCConfig::from_env().expect("failed to load RPC config")); + +/// The gas limit for Kakarot blocks. +pub const KKRT_BLOCK_GAS_LIMIT: u64 = 7_000_000; diff --git a/src/main.rs b/src/main.rs index 6ccf61e5f..df1c9bb5a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use dotenvy::dotenv; use eyre::Result; use kakarot_rpc::{ client::EthClient, - constants::{KAKAROT_RPC_CONFIG, RPC_CONFIG}, + constants::{KAKAROT_RPC_CONFIG, KKRT_BLOCK_GAS_LIMIT, RPC_CONFIG}, eth_rpc::{rpc::KakarotRpcModuleBuilder, run_server}, pool::{ constants::PRUNE_DURATION, @@ -54,7 +54,8 @@ async fn main() -> Result<()> { let contract_reader = KakarotCoreReader::new(*KAKAROT_ADDRESS, starknet_provider.clone()); let base_fee = contract_reader.get_base_fee().block_id(BlockId::Tag(BlockTag::Pending)).call().await?.base_fee; let base_fee = base_fee.try_into()?; - let config = PoolConfig { minimal_protocol_basefee: base_fee, ..Default::default() }; + let config = + PoolConfig { minimal_protocol_basefee: base_fee, gas_limit: KKRT_BLOCK_GAS_LIMIT, ..Default::default() }; // Init the Ethereum Client let eth_client = EthClient::new(starknet_provider, config, db.clone()); diff --git a/src/pool/mempool.rs b/src/pool/mempool.rs index 4e42bfff2..7dd473cf7 100644 --- a/src/pool/mempool.rs +++ b/src/pool/mempool.rs @@ -3,7 +3,7 @@ use super::validate::KakarotTransactionValidator; use crate::{ client::EthClient, - constants::KAKAROT_RPC_CONFIG, + constants::{KAKAROT_RPC_CONFIG, KKRT_BLOCK_GAS_LIMIT}, into_via_try_wrapper, pool::constants::ONE_TENTH_ETH, providers::eth_provider::{database::state::EthDatabase, starknet::relayer::Relayer, BlockProvider}, @@ -249,10 +249,13 @@ where let latest_header = latest_block.header.clone().seal(hash); // Update the block information in the pool - let chain_spec = - ChainSpec { chain: eth_client.eth_provider().chain_id.into(), ..Default::default() }; + let chain_spec = ChainSpec { + chain: eth_client.eth_provider().chain_id.into(), + max_gas_limit: KKRT_BLOCK_GAS_LIMIT, + ..Default::default() + }; let info = BlockInfo { - block_gas_limit: latest_header.gas_limit, + block_gas_limit: KKRT_BLOCK_GAS_LIMIT, last_seen_block_hash: hash, last_seen_block_number: latest_header.number, pending_basefee: latest_header diff --git a/src/test_utils/katana/mod.rs b/src/test_utils/katana/mod.rs index e91e38cf0..d9ee60d24 100644 --- a/src/test_utils/katana/mod.rs +++ b/src/test_utils/katana/mod.rs @@ -3,6 +3,7 @@ pub mod genesis; use super::mongo::MongoImage; use crate::{ client::EthClient, + constants::KKRT_BLOCK_GAS_LIMIT, providers::eth_provider::{ constant::U64_HEX_STRING_LEN, database::{ @@ -32,6 +33,7 @@ use mongodb::{ bson::{doc, Document}, options::{UpdateModifications, UpdateOptions}, }; +use reth_transaction_pool::PoolConfig; use starknet::providers::{jsonrpc::HttpTransport, JsonRpcClient}; use std::{path::Path, sync::Arc}; use testcontainers::ContainerAsync; @@ -153,7 +155,11 @@ impl<'a> Katana { let database = mongo_fuzzer.finalize().await; // Initialize the EthClient - let eth_client = EthClient::new(starknet_provider, Default::default(), database); + let eth_client = EthClient::new( + starknet_provider, + PoolConfig { gas_limit: KKRT_BLOCK_GAS_LIMIT, ..Default::default() }, + database, + ); // Create a new Kakarot EOA instance with the private key and EthDataProvider instance. let eoa = KakarotEOA::new(pk, Arc::new(eth_client.clone()), sequencer.account()); @@ -200,7 +206,11 @@ impl<'a> Katana { let database = mongo_fuzzer.finalize().await; // Initialize the EthClient - let eth_client = EthClient::new(starknet_provider, Default::default(), database); + let eth_client = EthClient::new( + starknet_provider, + PoolConfig { gas_limit: KKRT_BLOCK_GAS_LIMIT, ..Default::default() }, + database, + ); // Create a new Kakarot EOA instance with the private key and EthDataProvider instance. let eoa = KakarotEOA::new(pk, Arc::new(eth_client.clone()), sequencer.account()); diff --git a/tests/tests/mempool.rs b/tests/tests/mempool.rs index 6468ddab0..bb351ef32 100644 --- a/tests/tests/mempool.rs +++ b/tests/tests/mempool.rs @@ -5,6 +5,7 @@ use alloy_eips::eip2718::Encodable2718; use alloy_primitives::{Address, TxKind, B64, U256}; use alloy_rpc_types::Header; use kakarot_rpc::{ + constants::KKRT_BLOCK_GAS_LIMIT, pool::mempool::maintain_transaction_pool, providers::eth_provider::{ constant::U64_HEX_STRING_LEN, @@ -457,6 +458,9 @@ async fn test_maintain_mempool(#[future] katana: Katana, _setup: ()) { // We expect them to still be in the mempool until 1 second has elapsed. assert!(eth_client.mempool().contains(transaction1.hash()), "Transaction 1 should still be in the mempool"); assert!(eth_client.mempool().contains(transaction2.hash()), "Transaction 2 should still be in the mempool"); + + // Check the gas limit for Kakarot blocks + assert_eq!(eth_client.mempool().config().gas_limit, KKRT_BLOCK_GAS_LIMIT); } // Sleep for some additional time to allow the pruning to occur. @@ -466,6 +470,19 @@ async fn test_maintain_mempool(#[future] katana: Katana, _setup: ()) { assert!(!eth_client.mempool().contains(transaction1.hash()), "Transaction 1 should be pruned after 1 second"); assert!(!eth_client.mempool().contains(transaction2.hash()), "Transaction 2 should be pruned after 1 second"); + // Check the gas limit for Kakarot blocks + assert_eq!(eth_client.mempool().config().gas_limit, KKRT_BLOCK_GAS_LIMIT); + // Ensure the background task is stopped gracefully. maintain_task.abort(); } + +#[rstest] +#[awt] +#[tokio::test(flavor = "multi_thread")] +async fn test_mempool_config(#[future] katana: Katana, _setup: ()) { + let eth_client = Arc::new(katana.eth_client()); + + // Check the gas limit for Kakarot blocks + assert_eq!(eth_client.mempool().config().gas_limit, KKRT_BLOCK_GAS_LIMIT); +}