Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

set block gas limit in pool to 7M #1517

Merged
merged 4 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/client/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
constants::ETH_CHAIN_ID,
constants::{ETH_CHAIN_ID, KKRT_BLOCK_GAS_LIMIT},
pool::{
mempool::{KakarotPool, TransactionOrdering},
validate::KakarotTransactionValidatorBuilder,
Expand Down Expand Up @@ -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());
Expand Down
3 changes: 3 additions & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ pub static KAKAROT_RPC_CONFIG: LazyLock<KakarotRpcConfig> =
/// The RPC configuration.
pub static RPC_CONFIG: LazyLock<RPCConfig> =
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;
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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());
Expand Down
11 changes: 7 additions & 4 deletions src/pool/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions src/test_utils/katana/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
17 changes: 17 additions & 0 deletions tests/tests/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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);
}
Loading