erigontech / erigontech/erigon
commitment: move deferred branch writes behind PatriciaContext
- Dominant language
- Go
- Stars
- 3.6k
- Forks
- 1.5k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 455
Description
## Problem
Deferred branch updates (parallel commitment path) are managed via `BranchEncoder.CollectDeferredUpdate` and `ApplyDeferredBranchUpdates`, which call `ctx.PutBranch` directly. The deferred queue logic is interleaved with trie processing, making it hard to reason about and test.
## Proposed Solution
Extend `PatriciaContext` (or add a new `WritablePatriciaContext`) to accept deferred writes transparently:
```go
type DeferringPatriciaContext struct {
inner PatriciaContext
deferred []deferredBranchUpdate
}
func (d *DeferringPatriciaContext) PutBranch(prefix, data, prev []byte) error {
d.deferred = append(d.deferred, deferredBranchUpdate{prefix, data, prev})
return nil
}
func (d *DeferringPatriciaContext) Flush() error {
// apply all deferred updates, potentially in parallel
}
```
## Result
- Trie calls `ctx.PutBranch` uniformly — whether immediate or deferred is `PatriciaContext`'s concern
- `BranchEncoder` no longer needs deferred queue management
- Parallel and sequential paths share the same trie code
- Simpler testing: swap context implementation to control write ordering
## Related
- #20277 (move warmup cache behind PatriciaContext)
Contributor guide
Assessment
This issue has not been assessed yet.