Skip to content
This repository was archived by the owner on Jan 12, 2026. It is now read-only.

Commit fb48d3d

Browse files
committed
Fix issue with precompile conflicts
1 parent 49a5b53 commit fb48d3d

2 files changed

Lines changed: 18 additions & 82 deletions

File tree

crates/op-rbuilder/src/block_stm/executor.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use revm::{
1515
Database, DatabaseRef,
1616
context::result::{EVMError, ExecutionResult, ResultAndState},
1717
primitives::HashMap,
18-
state::{Account, EvmState},
18+
state::{Account, AccountInfo, EvmState},
1919
};
2020
use tokio_util::sync::CancellationToken;
2121
use tracing::{Span, debug, info};
@@ -239,34 +239,38 @@ impl<
239239
// Add writes only for values that actually changed
240240
for (addr, account) in state.loaded_state.iter() {
241241
if account.is_touched() {
242+
let original_account = self
243+
.base_db
244+
.basic_ref(*addr)
245+
.ok()
246+
.flatten()
247+
.unwrap_or_default();
242248
// Get original values from captured reads (if available)
243-
let original_balance = captured_reads.get(&EvmStateKey::Balance(*addr));
244-
let original_nonce = captured_reads.get(&EvmStateKey::Nonce(*addr));
245-
let original_code_hash =
246-
captured_reads.get(&EvmStateKey::CodeHash(*addr));
249+
let AccountInfo {
250+
balance: original_balance,
251+
nonce: original_nonce,
252+
code_hash: original_code_hash,
253+
..
254+
} = original_account;
247255

248256
// Only write balance if it changed
249-
if original_balance
250-
!= Some(&EvmStateValue::Balance(account.info.balance))
251-
{
257+
if original_balance != account.info.balance {
252258
write_set.insert((
253259
EvmStateKey::Balance(*addr),
254260
EvmStateValue::Balance(account.info.balance),
255261
));
256262
}
257263

258264
// Only write nonce if it changed
259-
if original_nonce != Some(&EvmStateValue::Nonce(account.info.nonce)) {
265+
if original_nonce != account.info.nonce {
260266
write_set.insert((
261267
EvmStateKey::Nonce(*addr),
262268
EvmStateValue::Nonce(account.info.nonce),
263269
));
264270
}
265271

266272
// Only write code hash if it changed
267-
if original_code_hash
268-
!= Some(&EvmStateValue::CodeHash(account.info.code_hash))
269-
{
273+
if original_code_hash != account.info.code_hash {
270274
write_set.insert((
271275
EvmStateKey::CodeHash(*addr),
272276
EvmStateValue::CodeHash(account.info.code_hash),

crates/op-rbuilder/src/builders/context.rs

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -621,16 +621,6 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx, OpEvmFactory> {
621621
};
622622
info.receipts.push(self.build_receipt(ctx, None));
623623

624-
// Log state before commit (sequential mode)
625-
trace!(
626-
target: "payload_builder",
627-
mode = "sequential",
628-
txn_idx,
629-
num_accounts = state.len(),
630-
has_storage_count = state.iter().filter(|(_, a)| !a.storage.is_empty()).count(),
631-
"SEQUENTIAL: Before commit"
632-
);
633-
634624
// commit changes
635625
evm.db_mut().commit(state);
636626

@@ -974,19 +964,12 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx, OpEvmFactory> {
974964
&& previous_result.map(|r| r.result.is_some()).unwrap_or(false);
975965

976966
if !conflicting_keys.is_empty() {
977-
trace!(
978-
target: "payload_builder",
979-
conflict_keys_count = conflicting_keys.len(),
980-
resource_only = conflicts_are_resource_only,
981-
has_previous = previous_result.is_some(),
982-
skip_evm = can_skip_evm,
983-
"Block-STM conflict check"
984-
);
967+
debug!(target: "payload_builder", "Conflicting keys: {:?}", conflicting_keys.iter().collect::<Vec<_>>());
985968
}
986969

987970
// 3. Execute or reuse
988971
let (result, evm_state) = if can_skip_evm {
989-
trace!(target: "payload_builder", "Skipping EVM re-execution (resource-only conflict)");
972+
debug!(target: "payload_builder", "Skipping EVM re-execution (resource-only conflict)");
990973
// Reuse previous result - extract just the loaded_state, not the full StateWithIncrements
991974
let prev = previous_result.unwrap();
992975
(prev.result.clone().unwrap(), prev.state.clone())
@@ -1062,12 +1045,6 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx, OpEvmFactory> {
10621045
if let Some(da_footprint_gas_scalar) = da_footprint_gas_scalar {
10631046
let total_da_bytes_after = cumulative_da_bytes.saturating_add(tx_da_size);
10641047
let da_footprint_after = total_da_bytes_after.saturating_mul(da_footprint_gas_scalar as u64);
1065-
trace!(
1066-
target: "payload_builder",
1067-
"DA footprint check: total_da_bytes={}, scalar={}, footprint={}, limit={}",
1068-
total_da_bytes_after, da_footprint_gas_scalar, da_footprint_after,
1069-
block_da_footprint_limit.unwrap_or(block_gas_limit)
1070-
);
10711048
if da_footprint_after > block_da_footprint_limit.unwrap_or(block_gas_limit) {
10721049
return Err(EVMError::Database(VersionedDbError::BaseDbError(
10731050
format!("Block DA footprint limit exceeded: {} > {} (total_da_bytes={}, base={}, da_increment={}, tx_da={}, scalar={})",
@@ -1114,12 +1091,6 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx, OpEvmFactory> {
11141091
let new_da_cumulative = da_increment + tx_da_size;
11151092
let new_address_gas_cumulative = address_gas_used + tx_gas_used;
11161093

1117-
trace!(
1118-
target: "payload_builder",
1119-
"Writing increments: new_gas={}, new_da={}, new_address_gas={} (gas_increment={} + tx_gas={}, da_increment={} + tx_da={}, address_gas={} + tx_gas={})",
1120-
new_gas_cumulative, new_da_cumulative, new_address_gas_cumulative, gas_increment, tx_gas_used, da_increment, tx_da_size, address_gas_used, tx_gas_used
1121-
);
1122-
11231094
state.inner_mut().database.write_block_resource(
11241095
BlockResourceType::Gas,
11251096
new_gas_cumulative
@@ -1226,41 +1197,6 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx, OpEvmFactory> {
12261197
}
12271198
}
12281199

1229-
// Commit resolved state to actual DB
1230-
let num_accounts_with_storage = resolved_state
1231-
.iter()
1232-
.filter(|(_, acct)| !acct.storage.is_empty())
1233-
.count();
1234-
1235-
trace!(
1236-
target: "payload_builder",
1237-
mode = "parallel",
1238-
tx_hash = ?tx_result.tx.tx_hash(),
1239-
num_accounts = resolved_state.len(),
1240-
num_accounts_with_storage,
1241-
"PARALLEL: Before commit"
1242-
);
1243-
1244-
if num_accounts_with_storage > 0 {
1245-
for (addr, account) in resolved_state.iter() {
1246-
if !account.storage.is_empty() {
1247-
let num_changed = account
1248-
.storage
1249-
.iter()
1250-
.filter(|(_, v)| v.is_changed())
1251-
.count();
1252-
trace!(
1253-
target: "payload_builder",
1254-
address = ?addr,
1255-
num_storage_slots = account.storage.len(),
1256-
num_changed_slots = num_changed,
1257-
is_touched = account.is_touched(),
1258-
is_selfdestructed = account.is_selfdestructed(),
1259-
"Account has storage in resolved_state before commit"
1260-
);
1261-
}
1262-
}
1263-
}
12641200
db.commit(resolved_state);
12651201

12661202
// Consume gas in address gas limiter now that the transaction is committed
@@ -1426,10 +1362,6 @@ impl<ExtraCtx: Debug + Default> OpPayloadBuilderCtx<ExtraCtx, OpEvmFactory> {
14261362
}
14271363

14281364
applied_count += 1;
1429-
trace!(
1430-
cumulative_gas = info.cumulative_gas_used,
1431-
"Committed transaction"
1432-
);
14331365
}
14341366

14351367
info!(

0 commit comments

Comments
 (0)