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:
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
Problem
Deferred branch updates (parallel commitment path) are managed via
BranchEncoder.CollectDeferredUpdateandApplyDeferredBranchUpdates, which callctx.PutBranchdirectly. The deferred queue logic is interleaved with trie processing, making it hard to reason about and test.Proposed Solution
Extend
PatriciaContext(or add a newWritablePatriciaContext) to accept deferred writes transparently:Result
ctx.PutBranchuniformly — whether immediate or deferred isPatriciaContext's concernBranchEncoderno longer needs deferred queue managementRelated