Skip to content

Commit 9830d93

Browse files
committed
linter fixes
1 parent 145561d commit 9830d93

File tree

6 files changed

+71
-60
lines changed

6 files changed

+71
-60
lines changed

crates/flashblocks-rpc/src/pending_blocks.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ use alloy_rpc_types_eth::{Filter, Header as RPCHeader, Log};
1010
use eyre::eyre;
1111
use op_alloy_network::Optimism;
1212
use op_alloy_rpc_types::{OpTransactionReceipt, Transaction};
13-
use reth::revm::{db::{BundleState, Cache}, state::EvmState};
13+
use reth::revm::{
14+
db::{BundleState, Cache},
15+
state::EvmState,
16+
};
1417
use reth_rpc_eth_api::RpcBlock;
1518

1619
use crate::subscription::Flashblock;

crates/flashblocks-rpc/src/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use reth::providers::{BlockReaderIdExt, StateProviderFactory};
2121
use reth::revm::context::result::ResultAndState;
2222
use reth::revm::database::StateProviderDatabase;
2323
use reth::revm::db::CacheDB;
24-
use revm_database::states::bundle_state::BundleRetention;
2524
use reth::revm::{DatabaseCommit, State};
2625
use reth_evm::{ConfigureEvm, Evm};
2726
use reth_optimism_chainspec::OpHardforks;
@@ -31,6 +30,7 @@ use reth_optimism_rpc::OpReceiptBuilder;
3130
use reth_primitives::RecoveredBlock;
3231
use reth_rpc_convert::{transaction::ConvertReceiptInput, RpcTransaction};
3332
use reth_rpc_eth_api::{RpcBlock, RpcReceipt};
33+
use revm_database::states::bundle_state::BundleRetention;
3434
use std::collections::{BTreeMap, HashSet};
3535
use std::sync::Arc;
3636
use std::time::Instant;

crates/metering/src/flashblock_trie_cache.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,12 @@ impl FlashblockTrieCache {
9292
// Need to compute the flashblock trie (this will replace any existing cache entry)
9393

9494
// Compute hashed post state from the bundle
95-
let hashed_state = canonical_state_provider.hashed_post_state(&flashblocks_state.bundle_state);
95+
let hashed_state =
96+
canonical_state_provider.hashed_post_state(&flashblocks_state.bundle_state);
9697

9798
// Calculate state root with updates to get the trie nodes
98-
let (_state_root, trie_updates) = canonical_state_provider.state_root_with_updates(hashed_state.clone())?;
99+
let (_state_root, trie_updates) =
100+
canonical_state_provider.state_root_with_updates(hashed_state.clone())?;
99101

100102
// Create the trie data
101103
let trie_data = FlashblockTrieData {

crates/metering/src/meter.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,15 @@ where
6565

6666
// If we have flashblocks but no cached trie, compute the flashblock trie first
6767
// (before starting any timers, since we only want to time the bundle's execution and state root)
68-
let flashblock_trie = if cached_flashblock_trie.is_none() && flashblocks_state.is_some() {
69-
let fb_state = flashblocks_state.as_ref().unwrap();
70-
let fb_hashed_state = state_provider.hashed_post_state(&fb_state.bundle_state);
71-
let (_fb_state_root, fb_trie_updates) = state_provider.state_root_with_updates(fb_hashed_state.clone())?;
72-
Some((fb_trie_updates, fb_hashed_state))
68+
let flashblock_trie = if cached_flashblock_trie.is_none() {
69+
if let Some(ref fb_state) = flashblocks_state {
70+
let fb_hashed_state = state_provider.hashed_post_state(&fb_state.bundle_state);
71+
let (_fb_state_root, fb_trie_updates) =
72+
state_provider.state_root_with_updates(fb_hashed_state.clone())?;
73+
Some((fb_trie_updates, fb_hashed_state))
74+
} else {
75+
None
76+
}
7377
} else {
7478
None
7579
};

crates/metering/src/rpc.rs

Lines changed: 49 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -74,49 +74,51 @@ where
7474

7575
// Get header and flashblock index from pending blocks
7676
// If no pending blocks exist, fall back to latest canonical block
77-
let (header, flashblock_index, canonical_block_number) = if let Some(pb) = pending_blocks.as_ref() {
78-
let latest_header: Sealed<Header> = pb.latest_header();
79-
let flashblock_index = pb.latest_flashblock_index();
80-
let canonical_block_number = pb.canonical_block_number();
81-
82-
info!(
83-
latest_block = latest_header.number,
84-
canonical_block = %canonical_block_number,
85-
flashblock_index = flashblock_index,
86-
"Using latest flashblock state for metering"
87-
);
88-
89-
// Convert Sealed<Header> to SealedHeader
90-
let sealed_header = SealedHeader::new(latest_header.inner().clone(), latest_header.hash());
91-
(sealed_header, flashblock_index, canonical_block_number)
92-
} else {
93-
// No pending blocks, use latest canonical block
94-
let canonical_block_number = pending_blocks.get_canonical_block_number();
95-
let header = self
96-
.provider
97-
.sealed_header_by_number_or_tag(canonical_block_number)
98-
.map_err(|e| {
99-
jsonrpsee::types::ErrorObjectOwned::owned(
100-
jsonrpsee::types::ErrorCode::InternalError.code(),
101-
format!("Failed to get canonical block header: {}", e),
102-
None::<()>,
103-
)
104-
})?
105-
.ok_or_else(|| {
106-
jsonrpsee::types::ErrorObjectOwned::owned(
107-
jsonrpsee::types::ErrorCode::InternalError.code(),
108-
"Canonical block not found".to_string(),
109-
None::<()>,
110-
)
111-
})?;
112-
113-
info!(
114-
canonical_block = header.number,
115-
"No flashblocks available, using canonical block state for metering"
116-
);
117-
118-
(header, 0, canonical_block_number)
119-
};
77+
let (header, flashblock_index, canonical_block_number) =
78+
if let Some(pb) = pending_blocks.as_ref() {
79+
let latest_header: Sealed<Header> = pb.latest_header();
80+
let flashblock_index = pb.latest_flashblock_index();
81+
let canonical_block_number = pb.canonical_block_number();
82+
83+
info!(
84+
latest_block = latest_header.number,
85+
canonical_block = %canonical_block_number,
86+
flashblock_index = flashblock_index,
87+
"Using latest flashblock state for metering"
88+
);
89+
90+
// Convert Sealed<Header> to SealedHeader
91+
let sealed_header =
92+
SealedHeader::new(latest_header.inner().clone(), latest_header.hash());
93+
(sealed_header, flashblock_index, canonical_block_number)
94+
} else {
95+
// No pending blocks, use latest canonical block
96+
let canonical_block_number = pending_blocks.get_canonical_block_number();
97+
let header = self
98+
.provider
99+
.sealed_header_by_number_or_tag(canonical_block_number)
100+
.map_err(|e| {
101+
jsonrpsee::types::ErrorObjectOwned::owned(
102+
jsonrpsee::types::ErrorCode::InternalError.code(),
103+
format!("Failed to get canonical block header: {}", e),
104+
None::<()>,
105+
)
106+
})?
107+
.ok_or_else(|| {
108+
jsonrpsee::types::ErrorObjectOwned::owned(
109+
jsonrpsee::types::ErrorCode::InternalError.code(),
110+
"Canonical block not found".to_string(),
111+
None::<()>,
112+
)
113+
})?;
114+
115+
info!(
116+
canonical_block = header.number,
117+
"No flashblocks available, using canonical block state for metering"
118+
);
119+
120+
(header, 0, canonical_block_number)
121+
};
120122

121123
// Manually decode transactions to OpTxEnvelope (op-alloy 0.20) instead of using
122124
// BundleWithMetadata.transactions() which returns op-alloy 0.21 types incompatible with reth.
@@ -162,7 +164,9 @@ where
162164
});
163165

164166
// Get the flashblock index if we have pending flashblocks
165-
let state_flashblock_index = pending_blocks.as_ref().map(|pb| pb.latest_flashblock_index());
167+
let state_flashblock_index = pending_blocks
168+
.as_ref()
169+
.map(|pb| pb.latest_flashblock_index());
166170

167171
// If we have flashblocks, ensure the trie is cached and get it
168172
let cached_trie = if let Some(ref fb_state) = flashblocks_state {
@@ -171,12 +175,7 @@ where
171175
// Ensure the flashblock trie is cached and return it
172176
Some(
173177
self.trie_cache
174-
.ensure_cached(
175-
header.hash(),
176-
fb_index,
177-
fb_state,
178-
&*state_provider,
179-
)
178+
.ensure_cached(header.hash(), fb_index, fb_state, &*state_provider)
180179
.map_err(|e| {
181180
error!(error = %e, "Failed to cache flashblock trie");
182181
jsonrpsee::types::ErrorObjectOwned::owned(

crates/metering/src/tests/rpc.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,10 @@ mod tests {
174174
assert!(response.total_execution_time_us > 0);
175175

176176
// Verify state root time is present and non-zero
177-
assert!(response.state_root_time_us > 0, "state_root_time_us should be greater than zero");
177+
assert!(
178+
response.state_root_time_us > 0,
179+
"state_root_time_us should be greater than zero"
180+
);
178181

179182
// Verify invariant: total execution time includes state root time
180183
assert!(

0 commit comments

Comments
 (0)