Commit graph

6 commits

Author SHA1 Message Date
Guillaume Ballet
9a5140a590
self-review 2026-04-30 14:31:38 +02:00
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
Guillaume Ballet
40c29ad53a
core/overlay: load transition state from system contract
Replace the gob-encoded `rawdb.{Read,Write}VerkleTransitionState`
plumbing with a direct read from the binary transition registry system
contract at `params.BinaryTransitionRegistryAddress`. The registry
exposes the transition state via fixed storage slots; a tiny
`StorageReader` interface (`Storage(addr, slot) (Hash, error)`)
captures what the loader needs.

`LoadTransitionState` now takes a `StorageReader` instead of an
`ethdb.KeyValueReader` and returns `nil` when the registry has not been
initialised (slot 0 unset). `IsTransitionActive` is exposed for callers
that only need the started flag.

`core/state/reader.go:newUBTTrieReader` is updated:
  - It now takes the binary triedb, an optional MPT triedb, and a
    `wrapInTransitionTrie` flag so callers can opt out of the wrap.
  - It uses a small `binTrieStorageReader` adapter to query the
    registry directly from the binary trie at the requested root,
    avoiding the MPT key-hashing in `flatReader`.
  - When wrap=true and the registry's BaseRoot is non-zero, the MPT
    base is opened against the supplied MPT triedb. With the current
    callers (mptdb=nil) the wrap degenerates to a passthrough,
    preserving existing master semantics until the dual-triedb routing
    lands in the next commit.

The dead `rawdb` accessors and `VerkleTransitionStatePrefix` schema
constant are removed.
2026-04-29 16:21:59 +02:00
rjl493456442
acbf699c33
core/state: export StateUpdate struct (#34724)
Some checks are pending
/ Linux Build (push) Waiting to run
/ Linux Build (arm) (push) Waiting to run
/ Keeper Build (push) Waiting to run
/ Windows Build (push) Waiting to run
/ Docker Image (push) Waiting to run
In the recent refactoring, the state commit logic has been abstracted, 
making it more flexible to design state databases for various use cases.
For example, execution-only modes where state mutation is disabled.

As part of this change, the database interface was extended with a 
Commit function. However, it currently accepts an unexported struct
`stateUpdate`, which prevents downstream projects from customizing
the state commit behavior.

To address this limitation, the stateUpdate type is now exported.
2026-04-20 17:12:10 +02:00
rjl493456442
7e388fd09e
core/state: separate trie reader to mptReader and ubtReader (#34763)
This PR separates the trie reader to mptTrieReader and ubtTrieReader for
improved readability and extensibility.

---------

Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-04-20 15:04:42 +02:00
Guillaume Ballet
ba215fd927
cmd, core, trie, triedb: split CachingDB into merkle + binary dbs. (#34700)
This Pr implements some prerequisite changes for #34004 : split the
`CachingDB` into a `MerkleDB` and a `UBTDB`, so that very different
behaviors don't clash as much.

The transition isn't handled by this PR, but after talking to Gary we
agreed that `UBTDB` should receive another `triedb`, which will only be
loaded if the `Ended` flag is set to false in the conversion contract.
If this is too hard to achieve, it makes sense to load it regardless,
and then loading can be prevented at a later stage by adding a
`UBTTransitionFinalizationTime` in `ChainConfig`.

---------

Co-authored-by: Gary Rong <garyrong0905@gmail.com>
2026-04-17 08:55:54 +08:00