erigontech / erigontech/erigon

Extract EEST edge cases into unit tests + finalize data structure optimization

Open
#19,824 1 comment 0 reactions 1 assignee Claimed by @mh0lt View on GitHub
Glamsterdam
Dominant language
Go
Stars
3.6k
Forks
1.5k
Avg merge
1d 16h
Merged PRs (30d)
455

Description

## Context

The parallel finalize path (`finalizeTx` in `exec3_parallel.go`) and its building blocks (`SetAccountBalanceOrDelete`, `StripBalanceWrite`, `ApplyVersionedWrites`) now have 17 unit tests pinning their behavior (added in #19814). These tests run in ~80ms vs ~90s for the full EEST BAL suite, catching regressions early.

However, several EEST edge cases are not yet covered by unit tests, and the data structures used in the finalize path have not been optimized for performance or memory.

## Unit test extraction

Extract the following EEST edge cases into targeted unit tests in `execution/state/versionedio_test.go`:

- **System call BAL reads (EIP-4788/2935)**: What reads/writes do system txs generate for BAL hash computation. Currently 5 pre-existing EEST failures:
- `test_bal_4788_simple`
- `test_bal_2935_simple`
- `test_bal_withdrawal_to_coinbase`
- `test_bal_withdrawal_and_value_transfer_same_address`
- `test_bal_multiple_balance_changes_same_account`
- **Withdrawal balance credits**: How withdrawals affect BAL tracking (block-end tx with balance changes)
- **Multi-change same-account**: Multiple balance changes within a block, net-zero detection with intermediates
- **Fee-calc delta/strip with complex interactions**: Coinbase touched during execution + fee addition, burnt contract edge cases

## Data structure optimization

Once unit test coverage is sufficient, optimize the finalize path data structures:

- `ReadSet` (`map[Address]map[AccountKey]*VersionedRead`) — nested maps with many small allocations; consider flat sorted slice
- `VersionedWrites` (`[]*VersionedWrite`) — pointer slice; consider value slice to reduce GC pressure
- `seen` map in `finalizeTx` reads loop — could use sorted scan of TxOut instead of map allocation
- `SetAccountBalanceOrDelete` linear scans — O(n) per call, could be O(1) with index

## Related

- PR #19814: exec3-parallel-direct-finalize (direct finalize path + BAL reads fix)
- Existing tests: execution/state/versionedio_test.go (17 finalize building block tests)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.