Skip to content

Commit fe91d47

Browse files
authored
all: remove the dependency from trie to triedb (#28824)
This change removes the dependency from trie package to triedb package.
1 parent 4c15d58 commit fe91d47

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+597
-425
lines changed

cmd/evm/internal/t8ntool/execution.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/ethereum/go-ethereum/params"
3737
"github.com/ethereum/go-ethereum/rlp"
3838
"github.com/ethereum/go-ethereum/trie"
39+
"github.com/ethereum/go-ethereum/triedb"
3940
"github.com/holiman/uint256"
4041
"golang.org/x/crypto/sha3"
4142
)
@@ -355,7 +356,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
355356
}
356357

357358
func MakePreState(db ethdb.Database, accounts core.GenesisAlloc) *state.StateDB {
358-
sdb := state.NewDatabaseWithConfig(db, &trie.Config{Preimages: true})
359+
sdb := state.NewDatabaseWithConfig(db, &triedb.Config{Preimages: true})
359360
statedb, _ := state.New(types.EmptyRootHash, sdb, nil)
360361
for addr, a := range accounts {
361362
statedb.SetCode(addr, a.Code)

cmd/evm/runner.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ import (
3838
"github.com/ethereum/go-ethereum/eth/tracers/logger"
3939
"github.com/ethereum/go-ethereum/internal/flags"
4040
"github.com/ethereum/go-ethereum/params"
41-
"github.com/ethereum/go-ethereum/trie"
42-
"github.com/ethereum/go-ethereum/trie/triedb/hashdb"
41+
"github.com/ethereum/go-ethereum/triedb"
42+
"github.com/ethereum/go-ethereum/triedb/hashdb"
4343
"github.com/urfave/cli/v2"
4444
)
4545

@@ -148,7 +148,7 @@ func runCmd(ctx *cli.Context) error {
148148
}
149149

150150
db := rawdb.NewMemoryDatabase()
151-
triedb := trie.NewDatabase(db, &trie.Config{
151+
triedb := triedb.NewDatabase(db, &triedb.Config{
152152
Preimages: preimages,
153153
HashDB: hashdb.Defaults,
154154
})

cmd/utils/flags.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ import (
6969
"github.com/ethereum/go-ethereum/p2p/netutil"
7070
"github.com/ethereum/go-ethereum/params"
7171
"github.com/ethereum/go-ethereum/rpc"
72-
"github.com/ethereum/go-ethereum/trie"
73-
"github.com/ethereum/go-ethereum/trie/triedb/hashdb"
74-
"github.com/ethereum/go-ethereum/trie/triedb/pathdb"
72+
"github.com/ethereum/go-ethereum/triedb"
73+
"github.com/ethereum/go-ethereum/triedb/hashdb"
74+
"github.com/ethereum/go-ethereum/triedb/pathdb"
7575
pcsclite "github.com/gballet/go-libpcsclite"
7676
gopsutil "github.com/shirou/gopsutil/mem"
7777
"github.com/urfave/cli/v2"
@@ -2146,8 +2146,8 @@ func MakeConsolePreloads(ctx *cli.Context) []string {
21462146
}
21472147

21482148
// MakeTrieDatabase constructs a trie database based on the configured scheme.
2149-
func MakeTrieDatabase(ctx *cli.Context, disk ethdb.Database, preimage bool, readOnly bool, isVerkle bool) *trie.Database {
2150-
config := &trie.Config{
2149+
func MakeTrieDatabase(ctx *cli.Context, disk ethdb.Database, preimage bool, readOnly bool, isVerkle bool) *triedb.Database {
2150+
config := &triedb.Config{
21512151
Preimages: preimage,
21522152
IsVerkle: isVerkle,
21532153
}
@@ -2160,12 +2160,12 @@ func MakeTrieDatabase(ctx *cli.Context, disk ethdb.Database, preimage bool, read
21602160
// ignore the parameter silently. TODO(rjl493456442)
21612161
// please config it if read mode is implemented.
21622162
config.HashDB = hashdb.Defaults
2163-
return trie.NewDatabase(disk, config)
2163+
return triedb.NewDatabase(disk, config)
21642164
}
21652165
if readOnly {
21662166
config.PathDB = pathdb.ReadOnly
21672167
} else {
21682168
config.PathDB = pathdb.Defaults
21692169
}
2170-
return trie.NewDatabase(disk, config)
2170+
return triedb.NewDatabase(disk, config)
21712171
}

core/blockchain.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ import (
4747
"github.com/ethereum/go-ethereum/metrics"
4848
"github.com/ethereum/go-ethereum/params"
4949
"github.com/ethereum/go-ethereum/rlp"
50-
"github.com/ethereum/go-ethereum/trie"
51-
"github.com/ethereum/go-ethereum/trie/triedb/hashdb"
52-
"github.com/ethereum/go-ethereum/trie/triedb/pathdb"
50+
"github.com/ethereum/go-ethereum/triedb"
51+
"github.com/ethereum/go-ethereum/triedb/hashdb"
52+
"github.com/ethereum/go-ethereum/triedb/pathdb"
5353
"golang.org/x/exp/slices"
5454
)
5555

@@ -149,8 +149,8 @@ type CacheConfig struct {
149149
}
150150

151151
// triedbConfig derives the configures for trie database.
152-
func (c *CacheConfig) triedbConfig() *trie.Config {
153-
config := &trie.Config{Preimages: c.Preimages}
152+
func (c *CacheConfig) triedbConfig() *triedb.Config {
153+
config := &triedb.Config{Preimages: c.Preimages}
154154
if c.StateScheme == rawdb.HashScheme {
155155
config.HashDB = &hashdb.Config{
156156
CleanCacheSize: c.TrieCleanLimit * 1024 * 1024,
@@ -216,7 +216,7 @@ type BlockChain struct {
216216
gcproc time.Duration // Accumulates canonical block processing for trie dumping
217217
lastWrite uint64 // Last block when the state was flushed
218218
flushInterval atomic.Int64 // Time interval (processing time) after which to flush a state
219-
triedb *trie.Database // The database handler for maintaining trie nodes.
219+
triedb *triedb.Database // The database handler for maintaining trie nodes.
220220
stateCache state.Database // State database to reuse between imports (contains state cache)
221221
txIndexer *txIndexer // Transaction indexer, might be nil if not enabled
222222

@@ -269,7 +269,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
269269
cacheConfig = defaultCacheConfig
270270
}
271271
// Open trie database with provided config
272-
triedb := trie.NewDatabase(db, cacheConfig.triedbConfig())
272+
triedb := triedb.NewDatabase(db, cacheConfig.triedbConfig())
273273

274274
// Setup the genesis block, commit the provided genesis specification
275275
// to database if the genesis block is not present yet, or load the

core/blockchain_reader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"github.com/ethereum/go-ethereum/event"
3131
"github.com/ethereum/go-ethereum/params"
3232
"github.com/ethereum/go-ethereum/rlp"
33-
"github.com/ethereum/go-ethereum/trie"
33+
"github.com/ethereum/go-ethereum/triedb"
3434
)
3535

3636
// CurrentHeader retrieves the current head header of the canonical chain. The
@@ -406,7 +406,7 @@ func (bc *BlockChain) TxIndexProgress() (TxIndexProgress, error) {
406406
}
407407

408408
// TrieDB retrieves the low level trie database used for data storage.
409-
func (bc *BlockChain) TrieDB() *trie.Database {
409+
func (bc *BlockChain) TrieDB() *triedb.Database {
410410
return bc.triedb
411411
}
412412

core/blockchain_sethead_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ import (
3434
"github.com/ethereum/go-ethereum/core/types"
3535
"github.com/ethereum/go-ethereum/core/vm"
3636
"github.com/ethereum/go-ethereum/params"
37-
"github.com/ethereum/go-ethereum/trie"
38-
"github.com/ethereum/go-ethereum/trie/triedb/hashdb"
39-
"github.com/ethereum/go-ethereum/trie/triedb/pathdb"
37+
"github.com/ethereum/go-ethereum/triedb"
38+
"github.com/ethereum/go-ethereum/triedb/hashdb"
39+
"github.com/ethereum/go-ethereum/triedb/pathdb"
4040
)
4141

4242
// rewindTest is a test case for chain rollback upon user request.
@@ -2033,13 +2033,13 @@ func testSetHeadWithScheme(t *testing.T, tt *rewindTest, snapshots bool, scheme
20332033
}
20342034
// Reopen the trie database without persisting in-memory dirty nodes.
20352035
chain.triedb.Close()
2036-
dbconfig := &trie.Config{}
2036+
dbconfig := &triedb.Config{}
20372037
if scheme == rawdb.PathScheme {
20382038
dbconfig.PathDB = pathdb.Defaults
20392039
} else {
20402040
dbconfig.HashDB = hashdb.Defaults
20412041
}
2042-
chain.triedb = trie.NewDatabase(chain.db, dbconfig)
2042+
chain.triedb = triedb.NewDatabase(chain.db, dbconfig)
20432043
chain.stateCache = state.NewDatabaseWithNodeDB(chain.db, chain.triedb)
20442044

20452045
// Force run a freeze cycle

core/chain_makers.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
"github.com/ethereum/go-ethereum/core/vm"
3232
"github.com/ethereum/go-ethereum/ethdb"
3333
"github.com/ethereum/go-ethereum/params"
34-
"github.com/ethereum/go-ethereum/trie"
34+
"github.com/ethereum/go-ethereum/triedb"
3535
"github.com/holiman/uint256"
3636
)
3737

@@ -312,7 +312,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
312312
}
313313
cm := newChainMaker(parent, config, engine)
314314

315-
genblock := func(i int, parent *types.Block, triedb *trie.Database, statedb *state.StateDB) (*types.Block, types.Receipts) {
315+
genblock := func(i int, parent *types.Block, triedb *triedb.Database, statedb *state.StateDB) (*types.Block, types.Receipts) {
316316
b := &BlockGen{i: i, cm: cm, parent: parent, statedb: statedb, engine: engine}
317317
b.header = cm.makeHeader(parent, statedb, b.engine)
318318

@@ -362,7 +362,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
362362
}
363363

364364
// Forcibly use hash-based state scheme for retaining all nodes in disk.
365-
triedb := trie.NewDatabase(db, trie.HashDefaults)
365+
triedb := triedb.NewDatabase(db, triedb.HashDefaults)
366366
defer triedb.Close()
367367

368368
for i := 0; i < n; i++ {
@@ -407,7 +407,7 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse
407407
// then generate chain on top.
408408
func GenerateChainWithGenesis(genesis *Genesis, engine consensus.Engine, n int, gen func(int, *BlockGen)) (ethdb.Database, []*types.Block, []types.Receipts) {
409409
db := rawdb.NewMemoryDatabase()
410-
triedb := trie.NewDatabase(db, trie.HashDefaults)
410+
triedb := triedb.NewDatabase(db, triedb.HashDefaults)
411411
defer triedb.Close()
412412
_, err := genesis.Commit(db, triedb)
413413
if err != nil {

core/chain_makers_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
"github.com/ethereum/go-ethereum/core/vm"
3232
"github.com/ethereum/go-ethereum/crypto"
3333
"github.com/ethereum/go-ethereum/params"
34-
"github.com/ethereum/go-ethereum/trie"
34+
"github.com/ethereum/go-ethereum/triedb"
3535
)
3636

3737
func TestGeneratePOSChain(t *testing.T) {
@@ -81,7 +81,7 @@ func TestGeneratePOSChain(t *testing.T) {
8181
Storage: storage,
8282
Code: common.Hex2Bytes("600154600354"),
8383
}
84-
genesis := gspec.MustCommit(gendb, trie.NewDatabase(gendb, trie.HashDefaults))
84+
genesis := gspec.MustCommit(gendb, triedb.NewDatabase(gendb, triedb.HashDefaults))
8585

8686
genchain, genreceipts := GenerateChain(gspec.Config, genesis, beacon.NewFaker(), gendb, 4, func(i int, gen *BlockGen) {
8787
gen.SetParentBeaconRoot(common.Hash{byte(i + 1)})
@@ -204,7 +204,7 @@ func ExampleGenerateChain() {
204204
Config: &params.ChainConfig{HomesteadBlock: new(big.Int)},
205205
Alloc: GenesisAlloc{addr1: {Balance: big.NewInt(1000000)}},
206206
}
207-
genesis := gspec.MustCommit(genDb, trie.NewDatabase(genDb, trie.HashDefaults))
207+
genesis := gspec.MustCommit(genDb, triedb.NewDatabase(genDb, triedb.HashDefaults))
208208

209209
// This call generates a chain of 5 blocks. The function runs for
210210
// each block and adds different features to gen based on the

core/genesis.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ import (
3737
"github.com/ethereum/go-ethereum/params"
3838
"github.com/ethereum/go-ethereum/rlp"
3939
"github.com/ethereum/go-ethereum/trie"
40-
"github.com/ethereum/go-ethereum/trie/triedb/pathdb"
40+
"github.com/ethereum/go-ethereum/triedb"
41+
"github.com/ethereum/go-ethereum/triedb/pathdb"
4142
"github.com/holiman/uint256"
4243
)
4344

@@ -127,9 +128,9 @@ func (ga *GenesisAlloc) hash(isVerkle bool) (common.Hash, error) {
127128
// If a genesis-time verkle trie is requested, create a trie config
128129
// with the verkle trie enabled so that the tree can be initialized
129130
// as such.
130-
var config *trie.Config
131+
var config *triedb.Config
131132
if isVerkle {
132-
config = &trie.Config{
133+
config = &triedb.Config{
133134
PathDB: pathdb.Defaults,
134135
IsVerkle: true,
135136
}
@@ -157,7 +158,7 @@ func (ga *GenesisAlloc) hash(isVerkle bool) (common.Hash, error) {
157158
// flush is very similar with hash, but the main difference is all the generated
158159
// states will be persisted into the given database. Also, the genesis state
159160
// specification will be flushed as well.
160-
func (ga *GenesisAlloc) flush(db ethdb.Database, triedb *trie.Database, blockhash common.Hash) error {
161+
func (ga *GenesisAlloc) flush(db ethdb.Database, triedb *triedb.Database, blockhash common.Hash) error {
161162
statedb, err := state.New(types.EmptyRootHash, state.NewDatabaseWithNodeDB(db, triedb), nil)
162163
if err != nil {
163164
return err
@@ -272,11 +273,11 @@ type ChainOverrides struct {
272273
// error is a *params.ConfigCompatError and the new, unwritten config is returned.
273274
//
274275
// The returned chain configuration is never nil.
275-
func SetupGenesisBlock(db ethdb.Database, triedb *trie.Database, genesis *Genesis) (*params.ChainConfig, common.Hash, error) {
276+
func SetupGenesisBlock(db ethdb.Database, triedb *triedb.Database, genesis *Genesis) (*params.ChainConfig, common.Hash, error) {
276277
return SetupGenesisBlockWithOverride(db, triedb, genesis, nil)
277278
}
278279

279-
func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *trie.Database, genesis *Genesis, overrides *ChainOverrides) (*params.ChainConfig, common.Hash, error) {
280+
func SetupGenesisBlockWithOverride(db ethdb.Database, triedb *triedb.Database, genesis *Genesis, overrides *ChainOverrides) (*params.ChainConfig, common.Hash, error) {
280281
if genesis != nil && genesis.Config == nil {
281282
return params.AllEthashProtocolChanges, common.Hash{}, errGenesisNoConfig
282283
}
@@ -491,7 +492,7 @@ func (g *Genesis) ToBlock() *types.Block {
491492

492493
// Commit writes the block and state of a genesis specification to the database.
493494
// The block is committed as the canonical head block.
494-
func (g *Genesis) Commit(db ethdb.Database, triedb *trie.Database) (*types.Block, error) {
495+
func (g *Genesis) Commit(db ethdb.Database, triedb *triedb.Database) (*types.Block, error) {
495496
block := g.ToBlock()
496497
if block.Number().Sign() != 0 {
497498
return nil, errors.New("can't commit genesis block with number > 0")
@@ -525,7 +526,7 @@ func (g *Genesis) Commit(db ethdb.Database, triedb *trie.Database) (*types.Block
525526

526527
// MustCommit writes the genesis block and state to db, panicking on error.
527528
// The block is committed as the canonical head block.
528-
func (g *Genesis) MustCommit(db ethdb.Database, triedb *trie.Database) *types.Block {
529+
func (g *Genesis) MustCommit(db ethdb.Database, triedb *triedb.Database) *types.Block {
529530
block, err := g.Commit(db, triedb)
530531
if err != nil {
531532
panic(err)

0 commit comments

Comments
 (0)