Skip to content

commitment: move deferred branch writes behind PatriciaContext #20278

Description

@awskii

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

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions