mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-08 16:01:36 +00:00
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.
107 lines
4 KiB
Go
107 lines
4 KiB
Go
// Copyright 2026 The go-ethereum Authors
|
|
// This file is part of the go-ethereum library.
|
|
//
|
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Lesser General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package core
|
|
|
|
import (
|
|
"math/big"
|
|
"testing"
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
"github.com/ethereum/go-ethereum/consensus/beacon"
|
|
"github.com/ethereum/go-ethereum/consensus/ethash"
|
|
"github.com/ethereum/go-ethereum/params"
|
|
)
|
|
|
|
// TestBinaryTransitionRegistryBootstrap exercises the registry deployment on
|
|
// the first UBT block: pre-fork blocks must leave the registry uninitialised,
|
|
// the first UBT block must mark started=true and the base root must be
|
|
// captured for every subsequent UBT block.
|
|
func TestBinaryTransitionRegistryBootstrap(t *testing.T) {
|
|
var (
|
|
ubtTime uint64 = 30
|
|
coinbase = common.HexToAddress("0x71562b71999873DB5b286dF957af199Ec94617F7")
|
|
gspec = &Genesis{
|
|
Config: ¶ms.ChainConfig{
|
|
ChainID: big.NewInt(1),
|
|
HomesteadBlock: big.NewInt(0),
|
|
EIP150Block: big.NewInt(0),
|
|
EIP155Block: big.NewInt(0),
|
|
EIP158Block: big.NewInt(0),
|
|
ByzantiumBlock: big.NewInt(0),
|
|
ConstantinopleBlock: big.NewInt(0),
|
|
PetersburgBlock: big.NewInt(0),
|
|
IstanbulBlock: big.NewInt(0),
|
|
MuirGlacierBlock: big.NewInt(0),
|
|
BerlinBlock: big.NewInt(0),
|
|
LondonBlock: big.NewInt(0),
|
|
Ethash: new(params.EthashConfig),
|
|
ShanghaiTime: u64(0),
|
|
CancunTime: u64(0),
|
|
PragueTime: u64(0),
|
|
UBTTime: &ubtTime,
|
|
TerminalTotalDifficulty: common.Big0,
|
|
EnableUBTAtGenesis: false,
|
|
BlobScheduleConfig: ¶ms.BlobScheduleConfig{
|
|
Cancun: params.DefaultCancunBlobConfig,
|
|
Prague: params.DefaultPragueBlobConfig,
|
|
UBT: params.DefaultPragueBlobConfig,
|
|
},
|
|
},
|
|
Alloc: GenesisAlloc{
|
|
coinbase: {
|
|
Balance: big.NewInt(1000000000000000000),
|
|
},
|
|
params.BeaconRootsAddress: {Nonce: 1, Code: params.BeaconRootsCode, Balance: common.Big0},
|
|
params.HistoryStorageAddress: {Nonce: 1, Code: params.HistoryStorageCode, Balance: common.Big0},
|
|
params.WithdrawalQueueAddress: {Nonce: 1, Code: params.WithdrawalQueueCode, Balance: common.Big0},
|
|
params.ConsolidationQueueAddress: {Nonce: 1, Code: params.ConsolidationQueueCode, Balance: common.Big0},
|
|
},
|
|
}
|
|
)
|
|
config := gspec.Config
|
|
engine := beacon.New(ethash.NewFaker())
|
|
|
|
registryAddr := params.BinaryTransitionRegistryAddress
|
|
slotStarted := common.Hash{}
|
|
slotBaseRoot := common.BytesToHash([]byte{5})
|
|
|
|
GenerateChainWithGenesis(gspec, engine, 6, func(i int, gen *BlockGen) {
|
|
gen.SetPoS()
|
|
|
|
blockNum := gen.Number()
|
|
blockTime := gen.Timestamp()
|
|
isUBT := config.IsUBT(blockNum, blockTime)
|
|
|
|
started := gen.GetState(registryAddr, slotStarted)
|
|
baseRoot := gen.GetState(registryAddr, slotBaseRoot)
|
|
t.Logf("block %d: num=%d time=%d isUBT=%v started=%x baseRoot=%x",
|
|
i, blockNum.Uint64(), blockTime, isUBT, started, baseRoot)
|
|
|
|
if !isUBT {
|
|
if started != (common.Hash{}) {
|
|
t.Errorf("block %d: pre-transition block should not have registry initialized", i)
|
|
}
|
|
return
|
|
}
|
|
if started == (common.Hash{}) {
|
|
t.Errorf("block %d: UBT block should have registry slot 0 (started) set", i)
|
|
}
|
|
if baseRoot == (common.Hash{}) {
|
|
t.Errorf("block %d: UBT block should have registry slot 5 (base root) set", i)
|
|
}
|
|
})
|
|
}
|