Skip to content

fix: execute blocks in chain.rlp#258

Merged
fmoletta merged 1 commit into
mainfrom
execute-blocks-in-chain-rlp
Aug 16, 2024
Merged

fix: execute blocks in chain.rlp#258
fmoletta merged 1 commit into
mainfrom
execute-blocks-in-chain-rlp

Conversation

@fmoletta

Copy link
Copy Markdown
Contributor

Motivation

When we import the chain.rlp we add the blocks to the db but we don't execute the blocks so the accounts never get updated. This PR aims to fix this by executing each block in the chain.

Description

  • Replace add_block with execute_block when consuming blocks imported from the chain rlp file

Closes None, but makes hive test eth_getBalance/get-balance pass

@fmoletta fmoletta marked this pull request as ready for review August 14, 2024 19:53
@fmoletta fmoletta requested a review from a team as a code owner August 14, 2024 19:53
@fmoletta fmoletta added this pull request to the merge queue Aug 16, 2024
Merged via the queue into main with commit 133e190 Aug 16, 2024
@fmoletta fmoletta deleted the execute-blocks-in-chain-rlp branch August 16, 2024 13:18
github-merge-queue Bot pushed a commit that referenced this pull request Feb 9, 2026
## Motivation

eBPF profiling on a live Hoodi node shows secp256k1 at ~11% of total
CPU, with
53% from P2P transaction validation. `Transaction::sender()` recomputes
ECDSA
public key recovery on every call — when the same transaction has
`sender()`
called multiple times (mempool checks, block building), each triggers a
fresh
recovery.

## Description

Add `sender_cache: OnceCell<Address>` to all transaction types,
following the
same pattern as the existing `inner_hash: OnceCell<H256>` cache for
`Transaction::hash()`. The first `sender()` call computes and caches;
subsequent
calls return the cached value.

Changes:
- Added `sender_cache: OnceCell<Address>` field to all 7 transaction
structs
  (Legacy, EIP2930, EIP1559, EIP4844, EIP7702, PrivilegedL2, FeeToken)
- `sender()` now delegates to `get_or_try_init(compute_sender)` — zero
behavior change
- Field uses `#[rkyv(with=rkyv::with::Skip)]` (same as `inner_hash`)
- All construction sites updated (RLPDecode impls + l1_watcher explicit
construction)
- Sites using `..Default::default()` automatically pick up the new field

## EXPB Benchmark Results

**Fast scenario** (vs main baselines #253/#258):

| Metric | Main | cache-tx-sender | Change |
|--------|------|-----------------|--------|
| latency_avg | 26.23 ms | 25.69 ms | **-2.1%** |
| mgas_avg | 775.78 | 795.35 | **+2.5%** |

**Gigablocks scenario** (vs main #254):

| Metric | Main | cache-tx-sender | Change |
|--------|------|-----------------|--------|
| latency_avg | 754.51 ms | 723.45 ms | **-4.1%** |
| mgas_avg | 1547.14 | 1616.66 | **+4.5%** |

Fast shows ~2% improvement (noise range). Gigablocks shows a meaningful
**4.5%
mgas improvement** — more transactions per block means more cache hits.

## How to Test

```bash
cargo test -p ethrex-common -p ethrex-blockchain -p ethrex-p2p
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants