erigontech / erigontech/erigon
IBS 2-Cache Phase 4: Journal reverts via VersionedWrites only; migrate resetObjectChange
- Dominant language
- Go
- Stars
- 3.6k
- Forks
- 1.5k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 455
Description
Part of #19623 — Rationalize IntraBlockState to a 2-Cache Model.
Depends on #19702 (Phase 3).
## Goal
Decouple the journal revert mechanism from `stateObject` fields so Phase 5 can remove `stateObject` entirely. After this phase, all snapshot/revert operations drive `VersionedWrites` directly — `stateObject` mutations inside journal `revert()` methods become dead code and are removed.
## Changes
- In all journal entry types (`balanceChange`, `nonceChange`, `storageChange`, `addSlotToAccessListChange`, etc.) in `journal.go`: remove the `stateObject` field mutations from their `revert()` methods. The `VersionedWrites` revert path (already present in `if s.versionMap != nil` blocks) is the only one that matters.
- Migrate `resetObjectChange`: instead of storing `*stateObject` (a snapshot of the whole object), store `map[AccountKey]*VersionedWrite` — a snapshot of the pre-`CreateAccount` writes for that address. `revert()` restores those entries into `VersionedWrites`.
- Remove `balanceInc` map from `IntraBlockState` (only used in the serial path, which is being decommissioned).
- Verify `newlyCreated` flag (EIP-6780 / SELFDESTRUCT semantics) is correctly derivable from `VersionedWrites` by checking for `IncarnationPath` write in the current tx.
## New feature tests
- **`TestJournalRevertWithVersionMap`** — revert every journal entry type and assert `VersionedWrites` contains the correct previous value after revert, with no stateObject side effects.
- **`TestResetObjectChangeMigrateWrites`** — create an account, write to it, `CreateAccount` over it, then revert; assert the pre-creation writes are fully restored in `VersionedWrites`.
- **`TestSnapshotRandomWithVersionMapExtended`** — extend Phase 1 `TestSnapshotRandomWithVersionMap` with `CreateAccount`-over-existing, code sets, and self-destructs. Must pass with journal reverts driven solely by `VersionedWrites`.
- **`TestNewlyCreatedFlagFromVersionedWrites`** — assert EIP-6780 `newlyCreated` logic is correct when derived from presence of `IncarnationPath` in current tx's `VersionedWrites`.
## Regression tests
- **`TestSnapshotRandom`** (existing) — must still pass; snapshot/revert behaviour must be unchanged.
- **`TestApplyVersionedWrites`** (existing) — must pass; revert-then-reapply pattern must work.
- **`TestSnapshotRandomWithVersionMap`** (Phase 1) — must pass.
- Run `TestExecutionSpecBlockchain` — full EEST fixture suite must pass.
- Run existing `TestDeleteRecreateSlots`, `TestDeleteCreateRevert` chain-level tests — must continue to pass.
- `go test -race ./execution/state/...` — no data races.
## Files affected
- `execution/state/journal.go` — remove stateObject mutations from revert(); migrate `resetObjectChange`
- `execution/state/intra_block_state.go` — remove `balanceInc`; update EIP-6780 `newlyCreated` derivation
## Acceptance criteria
- All journal entry reverts work identically to before, as proven by `TestSnapshotRandom` and `TestSnapshotRandomWithVersionMapExtended`
- `TestResetObjectChangeMigrateWrites` passes
- `TestNewlyCreatedFlagFromVersionedWrites` passes
- `make test-short` passes
Contributor guide
Assessment
This issue has not been assessed yet.