Commit graph

16921 commits

Author SHA1 Message Date
CPerezz
51fdf0e053
core: drop and tighten comments per PR feedback 2026-05-04 18:42:03 +02:00
CPerezz
3cdb836553
core: drop redundant WaitPrefetch in BAL block stats path
The BAL block has been verified and committed by the time we reach the
read-time accounting block, so the prefetcher (whose workload is bounded
by the BAL contents) has no outstanding tasks to wait on.
2026-05-04 12:46:20 +02:00
CPerezz
adb545b20c
core/state: colocate StateCounts/ReadDurations with StateDB
Moves the snapshot DTOs into statedb.go directly above SnapshotCounts
and SnapshotReads, so the types and their sole constructors live in the
same file. Avoids a single-purpose state_counts.go.
2026-05-01 15:31:22 +02:00
CPerezz
563cf08147
core: move slowBlockBAL field docs onto the struct
Field semantics belong on the type so they survive future call sites and
show up in godoc; the per-line comments at the constructor in
buildSlowBlockLog were redundant with the struct definition.
2026-05-01 14:40:07 +02:00
CPerezz
aa13b208b1
core: deduplicate CodeLoaded/CodeLoadBytes for BAL blocks
The previous follow-up note: per-tx + pre-tx + post-tx StateDBs each
have their own stateObjects, so summing CodeLoaded/CodeLoadBytes
over-counts contracts whose code body was fetched by multiple phases.

Fix: snapshot per-StateDB the {address: codeLen} map of contracts whose
s.code is populated, plumb through the existing aggregation pipeline,
dedupe by address in resultHandler/prepareExecResult. The merged map's
size and value-sum become CodeLoaded and CodeLoadBytes respectively,
overriding the per-tx-summed values at the wiring site.

Empirical: a 3-tx block touching the same set of system contracts now
reports code=4, code_bytes=1098 (matches single-tx baseline) instead
of code=12, code_bytes=3294 under the prior over-count.
2026-05-01 10:40:40 +02:00
CPerezz
3d135baa36
core: clarify ProcessResultWithMetrics.Counts/Reads semantics 2026-05-01 02:08:12 +02:00
CPerezz
823b582fc4
core: derive BAL block account/storage read counts from access list
Per-tx + pre-tx + post-tx StateDBs each have independent stateObjects
caches, so summing their AccountLoaded/StorageLoaded counts over-counts
addresses/slots touched by multiple phase StateDBs (compared to non-BAL
single-StateDB semantics where the cache deduplicates).

Override the read counts at the BAL stats wiring site using two new
helpers on bal.BlockAccessList. The BAL is the canonical block-level
deduplicated access record, so this restores cross-client comparable
"unique accounts/slots touched" semantics.

CodeLoaded/CodeLoadBytes still sum per-tx — the BAL doesn't track code-
fetch events distinctly. Slight over-count remains there, documented.
2026-05-01 02:07:23 +02:00
CPerezz
4d9405a201
core: comment slowBlockBAL population fields 2026-05-01 01:54:03 +02:00
CPerezz
7cd28d35ce
core: remove blockchain_stats_test.go 2026-05-01 01:54:03 +02:00
CPerezz
63660b25d8
core: lock down state.ReadDurations.Add merge primitive 2026-05-01 00:49:43 +02:00
CPerezz
8797d1af8e
core: tighten metric doc comments
- Replace reader.go:553 line citation in GetStateStats with the function
  name; line numbers rot.
- Note the BAL sum-of-CPU-time semantics on the read-time field group
  in ExecuteStats so cross-client consumers don't read total ≤ TotalTime
  as an invariant.
2026-05-01 00:38:31 +02:00
CPerezz
13733390da
core: extract state.ReadDurations triple
Replace the {Account, Storage, Code} time.Duration scalars threaded through
ProcessResultWithMetrics, txExecResult, processBlockPreTx and resultHandler
with a single ReadDurations struct + Add merge primitive. Same shape as
StateCounts. Adds (*StateDB).SnapshotReads() helper at the boundary.
2026-05-01 00:16:55 +02:00
CPerezz
546d2b457e
core: split BAL read-time access from cached metrics struct
Replace the cached AccountReadTime/StorageReadTime fields (which had a
snapshot-staleness bug fixed in 16e98f5d9 by re-calling Metrics()) with
a live ReadTimes() accessor. Metrics() now only returns commit/hash-phase
timings — it no longer touches atomics. blockchain.go reads atomics
directly via stateTransition.ReadTimes(), eliminating the refresh hack.

Also resolves the I1 fragility: Metrics() returning &s.metrics no longer
involves any writes inside the function, so concurrent callers can't race
on the read-time field updates.
2026-05-01 00:12:54 +02:00
CPerezz
eb4d17595f
core/state: change BAL plain-int counter fields from int64 to int 2026-04-30 23:59:14 +02:00
CPerezz
cd8ce62b40
core: wait for prefetcher before reading PrefetchReadTimes
Forward prefetchStateReader.Wait() through *reader.WaitPrefetch and call
it before reading the read-time atomics. Eliminates the edge-case where
prefetcher goroutines outlast block execution + commit. For slow blocks
(the metric's target audience) this is a no-op; for fast blocks it
ensures the metric is complete rather than slightly under.
2026-04-30 23:57:23 +02:00
CPerezz
16e98f5d93
core: refresh BAL Metrics() snapshot after writeBlockWithState
The first Metrics() call inside calcAndVerifyRoot snapshots accountReadNS
and storageReadNS into the cached AccountReadTime/StorageReadTime fields.
But commitAccount (called from writeBlockWithState's CommitWithUpdate
path) increments storageReadNS *after* that snapshot, so reading
m.StorageReadTime later would silently drop those reads.

Re-call Metrics() before reading the read-time fields so the cache
reflects the post-commit atomics. Other metric fields (AccountUpdate,
AccountCommits, etc.) are written directly to s.metrics elsewhere and
remain untouched by Metrics().

Found via the metric-correctness audit.
2026-04-30 23:14:35 +02:00
CPerezz
1afcea992c
core/state: change StateCounts.Add to value receiver
The struct is 80 bytes (10 ints) — value semantics matches the type's
"snapshot, safe to pass by value" thesis stated in its doc comment, and
removes three unnecessary &-takings at call sites. No behavior change.
2026-04-30 14:03:23 +02:00
CPerezz
cdfad0d343
core/state: comment len(code) > 0 gate, drop dead OriginStorageLoadTime
- Add a comment at the code-mutation gate explaining the deliberate
  len(code) > 0 (vs code != nil) match against non-BAL semantics; in
  devnet-3 BAL access lists, an empty []byte is non-nil but encodes
  "no code install".
- Remove BALStateTransitionMetrics.OriginStorageLoadTime: declared but
  never assigned anywhere in the tree. The actual state-transition
  read time is captured by AccountReadTime/StorageReadTime added in
  the prior commit.
2026-04-30 14:03:23 +02:00
CPerezz
6951ad7c50
core: nil-guard balTransitionStats in reportBALMetrics
Mirrors the nil-check already used in buildSlowBlockLog. The previous
unguarded access was safe today only because parallel_state_processor
short-circuits on error before the metrics path is reached, but the API
contract was fragile — a future caller could reach reportBALMetrics
without an established balTransitionStats and panic.
2026-04-30 14:03:23 +02:00
CPerezz
6b1ea9a498
core/state: forward prefetcher read times through the reader aggregator
Without this, the inline interface assertion in processBlockWithAccessList
silently fell through (the prefetchReader returned by ReaderEIP7928 is a
*reader wrapper, not the inner *prefetchStateReader), causing the
prefetcher contribution to state_read_ms to drop to zero in production.

Mirrors the existing GetStateStats forwarding pattern. Adds a regression
test that asserts *reader exposes PrefetchReadTimes via the BAL chain,
plus a fallback test for non-prefetch readers.
2026-04-30 14:03:23 +02:00
CPerezz
812fa198c3
core/state, core: introduce state.StateCounts snapshot type
Adds the StateCounts type that the BAL slow-block work depends on:
- core/state/state_counts.go: 10-field plain-int snapshot type with
  Add merge primitive; isolates the live atomic mutation surface from
  the value-typed aggregation pipeline.
- core/state/statedb.go: SnapshotCounts() method that converts the
  StateDB's atomic counters to a plain StateCounts at the boundary.
- core/blockchain_stats.go: ExecuteStats embeds state.StateCounts;
  adds ExecWall/PostProcess/Prefetch BAL extension fields, the
  slowBlockBAL JSON struct + BAL field on slowBlockLog, and extracts
  buildSlowBlockLog as a pure helper for direct testing.

Without this commit the bal-devnet-3 branch as committed in subsequent
commits would not build for a fresh clone (state.StateCounts undefined).
2026-04-30 14:03:23 +02:00
CPerezz
ae69e96efd
core: extend slow-block JSON shape test with state_writes, cache, state_read_ms 2026-04-30 14:03:23 +02:00
CPerezz
d611185f09
core: sum prefetcher + per-tx + BAL state-transition reads into state_read_ms 2026-04-30 14:03:23 +02:00
CPerezz
cd93a42b5b
core/state: instrument prefetcher read times 2026-04-30 14:03:23 +02:00
CPerezz
bcdc309f0b
core/state: instrument BAL state-transition read times 2026-04-30 14:03:22 +02:00
CPerezz
6730ab31e5
core: aggregate per-tx state-read durations through parallel pipeline 2026-04-30 14:03:22 +02:00
CPerezz
d419d91c44
core/state: surface BAL write counters via WriteCounts 2026-04-30 14:03:22 +02:00
CPerezz
78cb5b98df
core/state: increment write counters in BAL state transition 2026-04-30 14:03:22 +02:00
CPerezz
3dc4dcaff8
core/state: add code-write counter fields to BALStateTransition 2026-04-30 14:03:22 +02:00
CPerezz
f089266126
core/state: forward cache stats from prefetchStateReader 2026-04-30 14:03:22 +02:00
MariusVanDerWijden
2bb95a19a4 eth/catalyst: allow reorging the head block to a parent 2026-04-30 11:46:23 +02:00
felipe
c30c846ce8
eth/catalyst: wire up slotnum for testing_buildBlockV1 (#34721)
Wire up slotnum for `testing_buildBlockV1` for `bal-devnet-3` branch

We are experimenting testing block building through hive via EELS (PR
[here](https://github.com/ethereum/execution-specs/pull/2679)). This is
the only change needed to test against `bal-devnet-3` - missing slotnum.
2026-04-14 19:01:48 -04:00
Marius van der Wijden
189bbd91b4 core: fix 8037 transaction inclusion 2026-04-09 15:19:26 +02:00
Marius van der Wijden
33c9201262 build: update BAL tests 2026-04-09 15:05:13 +02:00
Marius van der Wijden
cd2095fb4a core/vm: fix two bugs
Fixes the collision bugs and create gas ordering
2026-04-09 15:05:13 +02:00
Sina M
407cf11930
core/state: touch BAL on statedb cache (#34684)
The BAL reader tracker captures access list reads at the reader level.
When statedb has an account cached the BAL tracker is not informed of
the access. This is ok during the lifetime of a transaction because you
only need to record the access the first time. It is also ok during the
lifetime of a block because BAL reads are block-level (same as statedb
caches).

Where I think the issue can rise is in the miner. Namely when building a
block, if the miner picks up a tx which fails, it drops it and picks up
another tx to include. There might be some edge case here where the
failed tx which is not included poisons the cache and a future block
which is included omits an account because it wasn't aware of the
access.
2026-04-08 13:20:58 -04:00
Marius van der Wijden
fa79954576 core: fix rebasing issue 2026-04-08 16:19:24 +02:00
Marius van der Wijden
ce91d227c2 core/vm: fix gas usage 2026-04-08 16:18:54 +02:00
Marius van der Wijden
778326725b core: introduce vm.GasBudget 2026-04-08 15:35:49 +02:00
Marius van der Wijden
0578ebbe1a core/vm: easier logic 2026-04-08 15:34:58 +02:00
Marius van der Wijden
3e37ed1b82 core: fix tx-inclusion tests 2026-04-08 12:44:39 +02:00
Sina M
60096253be
core/types: fix merging state mutations (EIP-7928) (#34640) 2026-04-07 08:57:43 -04:00
Jared Wasinger
6a79e3693b core: preface invalid bal errors so they are caught by the exception mapper 2026-04-05 18:14:18 -04:00
jwasinger
985cdac8a7
core: fix 8037 gas accounting (#34631)
To check whether a transaction can be applied, we validate that
`blockGasLimit > txGasLimit + (cumulativeRegularGasUsed +
cumulativeStateGasUsed)`. However, the check should only be applied to
the bottleneck resource, i.e. `blockGasLimit >
max(txRegularGasUsed+cumulativeRegularGasUsed, txStateGasUsed+
cumulativeStateGasUsed)`.

The changes here break multiple tests.  I am trying to determine why.

---------

Co-authored-by: qu0b <stefan@starflinger.eu>
2026-04-05 18:12:48 -04:00
Jared Wasinger
710ffb03ad core: perform BAL validation against gas limit for blocks which come with access lists
Co-authored-by: spencer <spencer.tb@ethereum.org>
2026-04-05 15:33:42 -04:00
Sina M
c3ad7547ce
core/state: various fixes in EIP-7928 (#34641)
Co-authored-by: jwasinger <j-wasinger@hotmail.com>
2026-04-03 12:41:45 -04:00
Jared Wasinger
6cc0be1e93 update to eest bal 5.6.0 release 2026-04-02 14:20:39 -04:00
Josh Klopfenstein
53719add20 Some fixes for bal-devnet-3 (#34090)
Rename `balHash` to `blockAccessListHash` in json encoding of block header.  Fix miner panic when attempting to create pre-amsterdam blocks.
2026-03-31 17:59:45 -04:00
Jared Wasinger
c339f4e241 fix stale generated file that I forgot to include with recent PR that made some changes to the --bal.executionmode flag 2026-03-31 17:59:45 -04:00
Jared Wasinger
e4f847871b core/types: don't include BAL in rlp encoding of full block. Set access list hash on block header when calling 'Block.WithAccessList' 2026-03-31 17:59:43 -04:00