erigontech / erigontech/erigon
Remove ExecV3: Refactor BlockAssembler to accept StateWriter
- Dominant language
- Go
- Stars
- 3.6k
- Forks
- 1.5k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 455
Description
## Sub-task of #19318
### Phase 2: Refactor BlockAssembler
**File**: `execution/exec/block_assembler.go`
The `BlockAssembler` currently hardcodes `NoopWriter` at 3 locations:
| Method | Line | Writes via |
|--------|------|-----------|
| `Initialize()` | 135 | `InitializeBlockExecution` → `FinalizeTx(rules, writer)` |
| `AddTransactions()` | 165,216 | `ApplyTransaction` → `FinalizeTx(rules, writer)` |
| `AssembleBlock()` | 328 | `FinalizeBlockExecution` → `CommitBlock(rules, writer)` |
### Changes
1. Add `stateWriter state.StateWriter` field to `BlockAssembler`
2. Modify `NewBlockAssembler` to accept optional `StateWriter` parameter (nil → `NoopWriter` for backward compatibility)
3. Add `OnTxCommitted func()` callback field — called after each successful user tx commit (used by caller to advance txNum)
4. Replace 3 hardcoded `NoopWriter` usages with `ba.stateWriter`
5. In `AddTransactions`, after each successful `commitTx`, call `ba.OnTxCommitted()` if set
When `NoopWriter` is used (default), behavior is identical to today. When a real `Writer` is passed, `FinalizeTx` and `CommitBlock` write state changes to `SharedDomains`.
### Key state write flow
- `ApplyTransaction` → `applyTransaction` → `ibs.FinalizeTx(rules, stateWriter)` (state_processor.go:99)
- `FinalizeBlockExecution` → `ibs.CommitBlock(rules, stateWriter)` (block_exec.go:350)
- `InitializeBlockExecution` → `ibs.FinalizeTx(rules, stateWriter)` (block_exec.go:371)
`FinalizeTx` writes per-tx dirty state objects. `CommitBlock` writes remaining dirty state at block end. They're complementary — `FinalizeTx` clears the journal after writing.
Contributor guide
Assessment
This issue has not been assessed yet.