Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
}

func MakePreState(db ethdb.Database, accounts types.GenesisAlloc, isBintrie bool) *state.StateDB {
tdb := triedb.NewDatabase(db, &triedb.Config{Preimages: true, IsVerkle: isBintrie})
tdb := triedb.NewDatabase(db, &triedb.Config{Preimages: true, IsUBT: isBintrie})
sdb := state.NewDatabase(tdb, nil)

root := types.EmptyRootHash
Expand Down
4 changes: 2 additions & 2 deletions cmd/evm/internal/t8ntool/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ func BinKeys(ctx *cli.Context) error {
return err
}
}
db := triedb.NewDatabase(rawdb.NewMemoryDatabase(), triedb.VerkleDefaults)
db := triedb.NewDatabase(rawdb.NewMemoryDatabase(), triedb.UBTDefaults)
defer db.Close()

bt, err := genBinTrieFromAlloc(alloc, db)
Expand Down Expand Up @@ -517,7 +517,7 @@ func BinTrieRoot(ctx *cli.Context) error {
return err
}
}
db := triedb.NewDatabase(rawdb.NewMemoryDatabase(), triedb.VerkleDefaults)
db := triedb.NewDatabase(rawdb.NewMemoryDatabase(), triedb.UBTDefaults)
defer db.Close()

bt, err := genBinTrieFromAlloc(alloc, db)
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/bintrie_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func convertToBinaryTrie(ctx *cli.Context) error {
defer srcTriedb.Close()

destTriedb := triedb.NewDatabase(chaindb, &triedb.Config{
IsVerkle: true,
IsUBT: true,
PathDB: &pathdb.Config{
JournalDirectory: stack.ResolvePath("triedb-bintrie"),
},
Expand Down
8 changes: 4 additions & 4 deletions cmd/geth/bintrie_convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ func TestBintrieConvert(t *testing.T) {
defer srcTriedb2.Close()

destTriedb := triedb.NewDatabase(chaindb, &triedb.Config{
IsVerkle: true,
PathDB: pathdb.Defaults,
IsUBT: true,
PathDB: pathdb.Defaults,
})
defer destTriedb.Close()

Expand Down Expand Up @@ -190,8 +190,8 @@ func TestBintrieConvertDeleteSource(t *testing.T) {
})

destTriedb := triedb.NewDatabase(chaindb, &triedb.Config{
IsVerkle: true,
PathDB: pathdb.Defaults,
IsUBT: true,
PathDB: pathdb.Defaults,
})

bt, err := bintrie.NewBinaryTrie(types.EmptyBinaryHash, destTriedb)
Expand Down
2 changes: 1 addition & 1 deletion cmd/geth/chaincmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func initGenesis(ctx *cli.Context) error {
chaindb := utils.MakeChainDatabase(ctx, stack, false, false)
defer chaindb.Close()

triedb := utils.MakeTrieDatabase(ctx, stack, chaindb, ctx.Bool(utils.CachePreimagesFlag.Name), false, genesis.IsVerkle())
triedb := utils.MakeTrieDatabase(ctx, stack, chaindb, ctx.Bool(utils.CachePreimagesFlag.Name), false, genesis.IsUBT())
defer triedb.Close()

_, hash, compatErr, err := core.SetupGenesisBlockWithOverride(chaindb, triedb, genesis, &overrides)
Expand Down
4 changes: 2 additions & 2 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2604,10 +2604,10 @@ func MakeConsolePreloads(ctx *cli.Context) []string {
}

// MakeTrieDatabase constructs a trie database based on the configured scheme.
func MakeTrieDatabase(ctx *cli.Context, stack *node.Node, disk ethdb.Database, preimage bool, readOnly bool, isVerkle bool) *triedb.Database {
func MakeTrieDatabase(ctx *cli.Context, stack *node.Node, disk ethdb.Database, preimage bool, readOnly bool, isUBT bool) *triedb.Database {
config := &triedb.Config{
Preimages: preimage,
IsVerkle: isVerkle,
IsUBT: isUBT,
}
scheme, err := rawdb.ParseStateScheme(ctx.String(StateSchemeFlag.Name), disk)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,10 @@ func (cfg BlockChainConfig) GetTriesInMemory() uint64 {
}

// triedbConfig derives the configures for trie database.
func (cfg *BlockChainConfig) triedbConfig(isVerkle bool) *triedb.Config {
func (cfg *BlockChainConfig) triedbConfig(isUBT bool) *triedb.Config {
config := &triedb.Config{
Preimages: cfg.Preimages,
IsVerkle: isVerkle,
IsUBT: isUBT,
}
if cfg.StateScheme == rawdb.HashScheme {
config.HashDB = &hashdb.Config{
Expand Down Expand Up @@ -383,7 +383,7 @@ type BlockChain struct {
lastWrite uint64 // Last block when the state was flushed
flushInterval atomic.Int64 // Time interval (processing time) after which to flush a state
triedb *triedb.Database // The database handler for maintaining trie nodes.
statedb *state.CachingDB // State database to reuse between imports (contains state cache)
statedb *state.MPTDatabase // State database to reuse between imports (contains state cache)
txIndexer *txIndexer // Transaction indexer, might be nil if not enabled

hc *HeaderChain
Expand Down Expand Up @@ -454,7 +454,7 @@ func NewBlockChain(db ethdb.Database, genesis *Genesis, engine consensus.Engine,
}

// Open trie database with provided config
enableVerkle, err := EnableVerkleAtGenesis(db, genesis)
enableVerkle, err := EnableUBTAtGenesis(db, genesis)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -508,7 +508,7 @@ func NewBlockChain(db ethdb.Database, genesis *Genesis, engine consensus.Engine,
bc.flushInterval.Store(int64(cfg.TrieTimeLimit))
bc.forker = NewForkChoice(bc, cfg.ShouldPreserve, cfg.Checker)

bc.statedb = state.NewDatabase(bc.triedb, nil)
bc.statedb = state.NewMPTDatabase(bc.triedb, nil)
bc.validator = NewBlockValidator(chainConfig, bc)
bc.prefetcher = NewStatePrefetcher(chainConfig, bc.hc)
bc.processor = NewStateProcessor(bc.hc)
Expand Down Expand Up @@ -1032,7 +1032,7 @@ func (bc *BlockChain) setupSnapshot() {
bc.snaps, _ = snapshot.New(snapconfig, bc.db, bc.triedb, head.Root)

// Re-initialize the state database with snapshot
bc.statedb = state.NewDatabase(bc.triedb, bc.snaps)
bc.statedb = state.NewMPTDatabase(bc.triedb, bc.snaps)
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/blockchain_sethead_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2041,7 +2041,7 @@ func testSetHeadWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme
dbconfig.HashDB = hashdb.Defaults
}
chain.triedb = triedb.NewDatabase(chain.db, dbconfig)
chain.statedb = state.NewDatabase(chain.triedb, chain.snaps)
chain.statedb = state.NewMPTDatabase(chain.triedb, chain.snaps)

// Force run a freeze cycle
type freezer interface {
Expand Down
6 changes: 3 additions & 3 deletions core/chain_makers.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (b *BlockGen) addTx(bc *BlockChain, vmConfig vm.Config, tx *types.Transacti

// Merge the tx-local access event into the "block-local" one, in order to collect
// all values, so that the witness can be built.
if b.statedb.Database().TrieDB().IsVerkle() {
if b.statedb.Database().Type().Is(state.TypeUBT) {
b.statedb.AccessEvents().Merge(evm.AccessEvents)
}
b.txs = append(b.txs, tx)
Expand Down Expand Up @@ -445,7 +445,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
// Forcibly use hash-based state scheme for retaining all nodes in disk.
var triedbConfig *triedb.Config = triedb.HashDefaults
if config.IsVerkle(config.ChainID) {
triedbConfig = triedb.VerkleDefaults
triedbConfig = triedb.UBTDefaults
}
triedb := triedb.NewDatabase(db, triedbConfig)
defer triedb.Close()
Expand Down Expand Up @@ -494,7 +494,7 @@ func GenerateChainWithGenesis(genesis *Genesis, engine consensus.Engine, n int,
db := rawdb.NewMemoryDatabase()
var triedbConfig *triedb.Config = triedb.HashDefaults
if genesis.Config != nil && genesis.Config.IsVerkle(genesis.Config.ChainID) {
triedbConfig = triedb.VerkleDefaults
triedbConfig = triedb.UBTDefaults
}
genesisTriedb := triedb.NewDatabase(db, triedbConfig)
block, err := genesis.Commit(db, genesisTriedb)
Expand Down
26 changes: 13 additions & 13 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,22 @@ func ReadGenesis(db ethdb.Database) (*Genesis, error) {
}

// hashAlloc computes the state root according to the genesis specification.
func hashAlloc(ga *types.GenesisAlloc, isVerkle bool) (common.Hash, error) {
func hashAlloc(ga *types.GenesisAlloc, isUBT bool) (common.Hash, error) {
// If a genesis-time verkle trie is requested, create a trie config
// with the verkle trie enabled so that the tree can be initialized
// as such.
var config *triedb.Config
if isVerkle {
if isUBT {
config = &triedb.Config{
PathDB: pathdb.Defaults,
IsVerkle: true,
PathDB: pathdb.Defaults,
IsUBT: true,
}
}
// Create an ephemeral in-memory database for computing hash,
// all the derived states will be discarded to not pollute disk.
emptyRoot := types.EmptyRootHash
if isVerkle {
emptyRoot = types.EmptyVerkleHash
if isUBT {
emptyRoot = types.EmptyBinaryHash
}
db := rawdb.NewMemoryDatabase()
statedb, err := state.New(emptyRoot, state.NewDatabase(triedb.NewDatabase(db, config), nil))
Expand All @@ -184,8 +184,8 @@ func hashAlloc(ga *types.GenesisAlloc, isVerkle bool) (common.Hash, error) {
// generated states will be persisted into the given database.
func flushAlloc(ga *types.GenesisAlloc, triedb *triedb.Database) (common.Hash, error) {
emptyRoot := types.EmptyRootHash
if triedb.IsVerkle() {
emptyRoot = types.EmptyVerkleHash
if triedb.IsUBT() {
emptyRoot = types.EmptyBinaryHash
}
statedb, err := state.New(emptyRoot, state.NewDatabase(triedb, nil))
if err != nil {
Expand Down Expand Up @@ -474,15 +474,15 @@ func (g *Genesis) chainConfigOrDefault(ghash common.Hash, stored *params.ChainCo
}
}

// IsVerkle indicates whether the state is already stored in a verkle
// IsUBT indicates whether the state is already stored in a unified binary
// tree at genesis time.
func (g *Genesis) IsVerkle() bool {
func (g *Genesis) IsUBT() bool {
return false
}

// ToBlock returns the genesis block according to genesis specification.
func (g *Genesis) ToBlock() *types.Block {
root, err := hashAlloc(&g.Alloc, g.IsVerkle())
root, err := hashAlloc(&g.Alloc, g.IsUBT())
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -631,14 +631,14 @@ func GenesisBlockForTesting(db ethdb.Database, addr common.Address, balance *big
return g.MustCommit(db, triedb.NewDatabase(db, triedb.HashDefaults))
}

// EnableVerkleAtGenesis indicates whether the verkle fork should be activated
// EnableUBTAtGenesis indicates whether the verkle fork should be activated
// at genesis. This is a temporary solution only for verkle devnet testing, where
// verkle fork is activated at genesis, and the configured activation date has
// already passed.
//
// In production networks (mainnet and public testnets), verkle activation always
// occurs after the genesis block, making this function irrelevant in those cases.
func EnableVerkleAtGenesis(db ethdb.Database, genesis *Genesis) (bool, error) {
func EnableUBTAtGenesis(db ethdb.Database, genesis *Genesis) (bool, error) {
if genesis != nil {
if genesis.Config == nil {
return false, errGenesisNoConfig
Expand Down
6 changes: 3 additions & 3 deletions core/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,16 +343,16 @@ func TestVerkleGenesisCommit(t *testing.T) {
config.NoAsyncFlush = true

triedb := triedb.NewDatabase(db, &triedb.Config{
IsVerkle: true,
PathDB: &config,
IsUBT: true,
PathDB: &config,
})
block := genesis.MustCommit(db, triedb)
if !bytes.Equal(block.Root().Bytes(), expected) {
t.Fatalf("invalid genesis state root, expected %x, got %x", expected, block.Root())
}

// Test that the trie is verkle
if !triedb.IsVerkle() {
if !triedb.IsUBT() {
t.Fatalf("expected trie to be verkle")
}
vdb := rawdb.NewTable(db, string(rawdb.VerklePrefix))
Expand Down
Loading
Loading