Commit graph

1 commit

Author SHA1 Message Date
Guillaume Ballet
d8ed290a40
core, core/state: dual-triedb routing for the MPT-to-UBT transition
This is the wiring that makes the binary transition registry actually
useful. The chain now keeps two trie databases in parallel during the
fork window:

  - bc.triedb stays in MPT mode and holds pre-fork state.
  - bc.bintriedb is a sibling triedb in UBT mode, allocated when
    UBTTime is set and the chain did not start binary at genesis.

Routing happens through the new bc.stateDatabase(parentRoot, header):

  - pre-UBT block: MPTDatabase backed by bc.triedb.
  - post-UBTTransitionEndTime block: plain UBTDatabase with the
    transition tree wrap explicitly disabled.
  - first UBT block (parent is pre-UBT): a transition UBTDatabase
    seeded with the parent root as the frozen MPT base.
  - subsequent UBT block while transitioning: probeTransitionDatabase
    inspects the registry and chooses between the transition variant
    (when slot 5 still records a non-zero base root) and the plain
    variant otherwise.

UBTDatabase grows the supporting fields:
  - mpttriedb + baseRoot for the transition window.
  - NewTransitionUBTDatabase constructor.
  - WithTransitionTreeWrap(bool) toggle for the override path.
  - OpenTrie / OpenStorageTrie now serve TransitionTrie / MPT storage
    tries while the transition is live.
  - Commit substitutes EmptyBinaryHash for the originRoot on the very
    first transition block, so the binary triedb does not reject the
    MPT-rooted parent.

StateAt / StateAtForkBoundary on BlockChain now defer to
stateDatabase, so the miner, ProcessBlock and historical state lookups
all share one routing path.

bc.bintriedb is journaled and closed alongside bc.triedb.

Adds core/chain_makers.go BlockGen.GetState so tests can inspect
storage slots written during block production, and a new
core/bintrie_transition_test.go that walks a chain across the fork
and asserts the registry's started flag and base root are populated
exactly when expected.
2026-04-29 16:55:13 +02:00