Skip to content

Commit 519d506

Browse files
committed
Fix build issues after rebase
- Fix load_account -> load_cache_account in processor.rs (State API differs from CacheDB) - Add FB generic parameter to MeteringApiImpl for flashblocks support - Fix revm module paths in tests (revm:: -> reth::revm::) - Add DummyFlashblocks implementation for meter_rpc tests - Add dev-dependencies: alloy-genesis, reth-optimism-node - Remove non-existent pub mod flashblocks from test-utils
1 parent 8e42c76 commit 519d506

File tree

7 files changed

+86
-19
lines changed

7 files changed

+86
-19
lines changed

Cargo.lock

Lines changed: 37 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/flashblocks/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,14 @@ metrics-derive.workspace = true
6161
rayon.workspace = true
6262

6363
[dev-dependencies]
64+
alloy-genesis.workspace = true
6465
rand.workspace = true
6566
revm.workspace = true
6667
reth-db.workspace = true
6768
once_cell.workspace = true
6869
reth-provider.workspace = true
6970
reth-db-common.workspace = true
71+
reth-optimism-node.workspace = true
7072
alloy-rpc-client.workspace = true
7173
op-alloy-consensus.workspace = true
7274
reth-testing-utils.workspace = true

crates/flashblocks/src/processor.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use reth::{
3232
},
3333
};
3434
use reth_evm::{ConfigureEvm, Evm, eth::receipt_builder::ReceiptBuilderCtx};
35-
use revm_database::states::bundle_state::BundleRetention;
3635
use reth_optimism_chainspec::OpHardforks;
3736
use reth_optimism_evm::{OpEvmConfig, OpNextBlockEnvAttributes};
3837
use reth_optimism_primitives::{OpBlock, OpPrimitives};
@@ -551,8 +550,12 @@ where
551550
&& transaction.is_deposit())
552551
.then(|| {
553552
evm.db_mut()
554-
.load_account(recovered_transaction.signer())
555-
.map(|acc| acc.info.nonce)
553+
.load_cache_account(recovered_transaction.signer())
554+
.map(|acc| {
555+
acc.account_info()
556+
.map(|info| info.nonce)
557+
.unwrap_or(0)
558+
})
556559
})
557560
.transpose()
558561
.map_err(|_| {

crates/rpc/src/base/meter_rpc.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use reth_provider::{BlockReader, ChainSpecProvider, HeaderProvider, StateProvide
1313
use tips_core::types::{Bundle, MeterBundleResponse, ParsedBundle};
1414
use tracing::{error, info};
1515

16-
use crate::{FlashblockTrieCache, MeteringApiServer, meter_bundle};
1716
use super::{block::meter_block, types::MeterBlockResponse};
17+
use crate::{FlashblockTrieCache, MeteringApiServer, meter_bundle};
1818

1919
/// Implementation of the metering RPC API.
2020
#[derive(Debug)]
@@ -289,7 +289,7 @@ where
289289
}
290290
}
291291

292-
impl<Provider> MeteringApiImpl<Provider>
292+
impl<Provider, FB> MeteringApiImpl<Provider, FB>
293293
where
294294
Provider: StateProviderFactory
295295
+ ChainSpecProvider<ChainSpec = OpChainSpec>
@@ -300,6 +300,7 @@ where
300300
+ Send
301301
+ Sync
302302
+ 'static,
303+
FB: FlashblocksAPI + Send + Sync + 'static,
303304
{
304305
/// Internal helper to meter a block's execution
305306
fn meter_block_internal(&self, block: &OpBlock) -> RpcResult<MeterBlockResponse> {

crates/rpc/tests/meter.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ use rand::{SeedableRng, rngs::StdRng};
1414
use reth::{
1515
api::NodeTypesWithDBAdapter,
1616
chainspec::EthChainSpec,
17-
revm::db::{BundleState, Cache},
17+
revm::{
18+
db::{BundleState, Cache},
19+
primitives::KECCAK_EMPTY,
20+
},
1821
};
1922
use reth_db::{DatabaseEnv, test_utils::TempDatabase};
2023
use reth_optimism_chainspec::{BASE_MAINNET, OpChainSpec, OpChainSpecBuilder};
@@ -24,7 +27,6 @@ use reth_primitives_traits::SealedHeader;
2427
use reth_provider::{HeaderProvider, StateProviderFactory, providers::BlockchainProvider};
2528
use reth_testing_utils::generators::generate_keys;
2629
use reth_transaction_pool::test_utils::TransactionBuilder;
27-
use revm::primitives::KECCAK_EMPTY;
2830
use tips_core::types::{Bundle, ParsedBundle};
2931

3032
type NodeTypes = NodeTypesWithDBAdapter<OpNode, Arc<TempDatabase<DatabaseEnv>>>;
@@ -426,25 +428,26 @@ fn meter_bundle_requires_correct_layering_for_pending_nonce() -> eyre::Result<()
426428
let bundle_state = BundleState::new(
427429
[(
428430
alice_address,
429-
Some(revm::state::AccountInfo {
431+
Some(reth::revm::state::AccountInfo {
430432
balance: U256::from(1_000_000_000u64),
431433
nonce: 0, // original
432434
code_hash: KECCAK_EMPTY,
433435
code: None,
434436
}),
435-
Some(revm::state::AccountInfo {
437+
Some(reth::revm::state::AccountInfo {
436438
balance: U256::from(1_000_000_000u64),
437439
nonce: 1, // pending (after first flashblock tx)
438440
code_hash: KECCAK_EMPTY,
439441
code: None,
440442
}),
441443
Default::default(), // no storage changes
442444
)],
443-
Vec::<Vec<(Address, Option<Option<revm::state::AccountInfo>>, Vec<(U256, U256)>)>>::new(),
444-
Vec::<(B256, revm::bytecode::Bytecode)>::new(),
445+
Vec::<Vec<(Address, Option<Option<reth::revm::state::AccountInfo>>, Vec<(U256, U256)>)>>::new(),
446+
Vec::<(B256, reth::revm::bytecode::Bytecode)>::new(),
445447
);
446448

447-
let flashblocks_state = FlashblocksState { cache: Cache::default(), bundle_state };
449+
let flashblocks_state =
450+
base_reth_rpc::FlashblocksState { cache: Cache::default(), bundle_state };
448451

449452
// With correct flashblocks state, transaction should succeed
450453
let state_provider2 = harness

crates/rpc/tests/meter_rpc.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use std::{any::Any, net::SocketAddr, sync::Arc};
55
use alloy_eips::Encodable2718;
66
use alloy_primitives::{Bytes, U256, address, b256, bytes};
77
use alloy_rpc_client::RpcClient;
8+
use arc_swap::Guard;
9+
use base_reth_flashblocks::{FlashblocksAPI, PendingBlocks};
810
use base_reth_rpc::{MeterBundleResponse, MeteringApiImpl, MeteringApiServer};
911
use base_reth_test_utils::{init_silenced_tracing, load_genesis};
1012
use op_alloy_consensus::OpTxEnvelope;
@@ -21,13 +23,37 @@ use reth_optimism_primitives::OpTransactionSigned;
2123
use reth_provider::providers::BlockchainProvider;
2224
use reth_transaction_pool::test_utils::TransactionBuilder;
2325
use tips_core::types::Bundle;
26+
use tokio::sync::broadcast;
2427

2528
struct NodeContext {
2629
http_api_addr: SocketAddr,
2730
_node_exit_future: NodeExitFuture,
2831
_node: Box<dyn Any + Sync + Send>,
2932
}
3033

34+
/// Dummy FlashblocksAPI implementation for tests that don't need flashblock state
35+
struct DummyFlashblocks {
36+
pending_blocks: arc_swap::ArcSwapOption<PendingBlocks>,
37+
}
38+
39+
impl Default for DummyFlashblocks {
40+
fn default() -> Self {
41+
Self { pending_blocks: arc_swap::ArcSwapOption::new(None) }
42+
}
43+
}
44+
45+
impl FlashblocksAPI for DummyFlashblocks {
46+
fn get_pending_blocks(&self) -> Guard<Option<Arc<PendingBlocks>>> {
47+
self.pending_blocks.load()
48+
}
49+
50+
fn subscribe_to_flashblocks(&self) -> broadcast::Receiver<Arc<PendingBlocks>> {
51+
let (tx, rx) = broadcast::channel(1);
52+
drop(tx);
53+
rx
54+
}
55+
}
56+
3157
// Helper function to create a Bundle with default fields
3258
fn create_bundle(txs: Vec<Bytes>, block_number: u64, min_timestamp: Option<u64>) -> Bundle {
3359
Bundle {
@@ -84,7 +110,8 @@ async fn setup_node() -> eyre::Result<NodeContext> {
84110
.with_components(node.components_builder())
85111
.with_add_ons(node.add_ons())
86112
.extend_rpc_modules(move |ctx| {
87-
let metering_api = MeteringApiImpl::new(ctx.provider().clone());
113+
let metering_api =
114+
MeteringApiImpl::new(ctx.provider().clone(), Arc::new(DummyFlashblocks::default()));
88115
ctx.modules.merge_configured(metering_api.into_rpc())?;
89116
Ok(())
90117
})

crates/test-utils/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ pub use engine::{EngineAddress, EngineApi, EngineProtocol, HttpEngine, IpcEngine
2121
mod fixtures;
2222
pub use fixtures::{create_provider_factory, load_genesis};
2323

24-
pub mod flashblocks;
25-
2624
mod flashblocks_harness;
2725
pub use flashblocks_harness::FlashblocksHarness;
2826

0 commit comments

Comments
 (0)