diff --git a/cmd/evm/internal/t8ntool/execution.go b/cmd/evm/internal/t8ntool/execution.go index 1decb81934..d0674bdab0 100644 --- a/cmd/evm/internal/t8ntool/execution.go +++ b/cmd/evm/internal/t8ntool/execution.go @@ -349,6 +349,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig, } // Re-create statedb instance with new root upon the updated database // for accessing latest states. + // TODO:: state.NewDatabase internally compatible with versa is sufficient. statedb, err = state.New(root, statedb.Database(), nil) if err != nil { return nil, nil, nil, NewError(ErrorEVM, fmt.Errorf("could not reopen state: %v", err)) @@ -358,7 +359,9 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig, } func MakePreState(db ethdb.Database, accounts types.GenesisAlloc) *state.StateDB { + // TODO:: state.NewDatabase internally compatible with versa is sufficient. sdb := state.NewDatabaseWithConfig(db, &triedb.Config{Preimages: true}) + // TODO:: state.NewDatabase internally compatible with versa is sufficient. statedb, _ := state.New(types.EmptyRootHash, sdb, nil) for addr, a := range accounts { statedb.SetCode(addr, a.Code) @@ -372,6 +375,7 @@ func MakePreState(db ethdb.Database, accounts types.GenesisAlloc) *state.StateDB statedb.Finalise(false) statedb.AccountsIntermediateRoot() root, _, _ := statedb.Commit(0, nil) + // TODO:: state.NewDatabase internally compatible with versa is sufficient. statedb, _ = state.New(root, sdb, nil) return statedb } diff --git a/cmd/evm/runner.go b/cmd/evm/runner.go index 274b4ab625..94033be229 100644 --- a/cmd/evm/runner.go +++ b/cmd/evm/runner.go @@ -148,12 +148,14 @@ func runCmd(ctx *cli.Context) error { } db := rawdb.NewMemoryDatabase() + // TODO:: ignore cmd, if use versa if should be nil, if triedb is not used later in this func triedb := triedb.NewDatabase(db, &triedb.Config{ Preimages: preimages, HashDB: hashdb.Defaults, }) defer triedb.Close() genesis := genesisConfig.MustCommit(db, triedb) + // TODO:: ignore cmd, internally compatible with versa is sufficient. sdb := state.NewDatabaseWithNodeDB(db, triedb) statedb, _ = state.New(genesis.Root(), sdb, nil) chainConfig = genesisConfig.Config diff --git a/cmd/evm/staterunner.go b/cmd/evm/staterunner.go index 458d809ad8..8443faa045 100644 --- a/cmd/evm/staterunner.go +++ b/cmd/evm/staterunner.go @@ -109,6 +109,7 @@ func runStateTest(fname string, cfg vm.Config, jsonOut, dump bool) error { fmt.Fprintf(os.Stderr, "{\"stateRoot\": \"%#x\"}\n", root) } if dump { // Dump any state to aid debugging + // TODO:: state.NewDatabase internally compatible with versa is sufficient. cpy, _ := state.New(root, tstate.StateDB.Database(), nil) dump := cpy.RawDump(nil) result.State = &dump diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index afcb474848..7a77ded569 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -778,6 +778,7 @@ func parseDumpConfig(ctx *cli.Context, stack *node.Node) (*state.DumpConfig, eth } } else { // Use latest + // TODO:: if versa, scheme = VersaScheme if scheme == rawdb.PathScheme { triedb := triedb.NewDatabase(db, &triedb.Config{PathDB: utils.PathDBConfigAddJournalFilePath(stack, pathdb.ReadOnly)}) defer triedb.Close() @@ -833,6 +834,7 @@ func dump(ctx *cli.Context) error { triedb := utils.MakeTrieDatabase(ctx, stack, db, true, true, false) // always enable preimage lookup defer triedb.Close() + // TODO:: state.NewDatabase internally compatible with versa is sufficient. state, err := state.New(root, state.NewDatabaseWithNodeDB(db, triedb), nil) if err != nil { return err @@ -850,6 +852,7 @@ func dumpAllRootHashInPath(ctx *cli.Context) error { defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, true, false) defer db.Close() + // TODO:: ignore cmd triedb := triedb.NewDatabase(db, &triedb.Config{PathDB: utils.PathDBConfigAddJournalFilePath(stack, pathdb.ReadOnly)}) defer triedb.Close() diff --git a/cmd/geth/dbcmd.go b/cmd/geth/dbcmd.go index 282f035bb4..0b9a306e8e 100644 --- a/cmd/geth/dbcmd.go +++ b/cmd/geth/dbcmd.go @@ -457,6 +457,7 @@ func inspectTrie(ctx *cli.Context) error { config = triedb.HashDefaults } + // TODO:: ignore cmd triedb := triedb.NewDatabase(db, config) theTrie, err := trie.New(trie.TrieID(trieRootHash), triedb) if err != nil { @@ -1268,6 +1269,7 @@ func hbss2pbss(ctx *cli.Context) error { } if lastStateID == 0 || force { config := triedb.HashDefaults + // TODO:: ignore cmd triedb := triedb.NewDatabase(db, config) triedb.Cap(0) log.Info("hbss2pbss triedb", "scheme", triedb.Scheme()) diff --git a/cmd/geth/snapshot.go b/cmd/geth/snapshot.go index 040736a0d7..f73bb74988 100644 --- a/cmd/geth/snapshot.go +++ b/cmd/geth/snapshot.go @@ -256,6 +256,7 @@ func accessDb(ctx *cli.Context, stack *node.Node) (ethdb.Database, error) { } else if dbScheme == rawdb.HashScheme { config = triedb.HashDefaults } + // TODO:: ignore snapshot snaptree, err := snapshot.New(snapconfig, chaindb, triedb.NewDatabase(chaindb, config), headBlock.Root(), TriesInMemory, false) if err != nil { log.Error("snaptree error", "err", err) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 62b3b2f397..b07280a190 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -2589,6 +2589,7 @@ func MakeTrieDatabase(ctx *cli.Context, stack *node.Node, disk ethdb.Database, p // ignore the parameter silently. TODO(rjl493456442) // please config it if read mode is implemented. config.HashDB = hashdb.Defaults + // TODO::skip MakeTrieDatabase return triedb.NewDatabase(disk, config) } if readOnly { @@ -2597,6 +2598,7 @@ func MakeTrieDatabase(ctx *cli.Context, stack *node.Node, disk ethdb.Database, p config.PathDB = pathdb.Defaults } config.PathDB.JournalFilePath = fmt.Sprintf("%s/%s", stack.ResolvePath("chaindata"), eth.JournalFileName) + // TODO::skip MakeTrieDatabase return triedb.NewDatabase(disk, config) } diff --git a/core/blockchain.go b/core/blockchain.go index 51387a13f0..1ceff7eca8 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -336,6 +336,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis diffLayerChanCache, _ := exlru.New(diffLayerCacheLimit) // Open trie database with provided config + // TODO:: if versa , have its owen init genesis logic triedb := triedb.NewDatabase(db, cacheConfig.triedbConfig()) // Setup the genesis block, commit the provided genesis specification @@ -384,6 +385,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis } bc.flushInterval.Store(int64(cacheConfig.TrieTimeLimit)) bc.forker = NewForkChoice(bc, shouldPreserve) + // TODO:: state.NewDatabase internally compatible with versa is sufficient. bc.stateCache = state.NewDatabaseWithNodeDB(bc.db, bc.triedb) bc.validator = NewBlockValidator(chainConfig, bc, engine) bc.prefetcher = NewStatePrefetcher(chainConfig, bc, engine) @@ -2232,6 +2234,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) parent = bc.GetHeader(block.ParentHash(), block.NumberU64()-1) } + // TODO:: state.NewDatabase internally compatible with versa is sufficient. statedb, err := state.NewWithSharedPool(parent.Root, bc.stateCache, bc.snaps) if err != nil { return it.index, err diff --git a/core/blockchain_reader.go b/core/blockchain_reader.go index 84bbbc25f2..8c3b1f0419 100644 --- a/core/blockchain_reader.go +++ b/core/blockchain_reader.go @@ -396,6 +396,7 @@ func (bc *BlockChain) State() (*state.StateDB, error) { // StateAt returns a new mutable state based on a particular point in time. func (bc *BlockChain) StateAt(root common.Hash) (*state.StateDB, error) { + // TODO:: state.NewDatabase internally compatible with versa is sufficient. stateDb, err := state.New(root, bc.stateCache, bc.snaps) if err != nil { return nil, err diff --git a/core/chain_makers.go b/core/chain_makers.go index 0592210dba..8b7f601bae 100644 --- a/core/chain_makers.go +++ b/core/chain_makers.go @@ -397,10 +397,12 @@ func GenerateChain(config *params.ChainConfig, parent *types.Block, engine conse } // Forcibly use hash-based state scheme for retaining all nodes in disk. + // TODO:: ignore, only use to UT triedb := triedb.NewDatabase(db, triedb.HashDefaults) defer triedb.Close() for i := 0; i < n; i++ { + // @TODO:: ignore, it used to UT, state.NewDatabase internally compatible with versa is sufficient. statedb, err := state.New(parent.Root(), state.NewDatabaseWithNodeDB(db, triedb), nil) if err != nil { panic(err) diff --git a/core/genesis.go b/core/genesis.go index 71787ce2bf..abf4becd7f 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -126,7 +126,9 @@ func hashAlloc(ga *types.GenesisAlloc, isVerkle bool) (common.Hash, error) { } // Create an ephemeral in-memory database for computing hash, // all the derived states will be discarded to not pollute disk. + // TODO:: state.NewDatabase internally compatible with versa is sufficient. db := state.NewDatabaseWithConfig(rawdb.NewMemoryDatabase(), config) + // TODO:: state.NewDatabase internally compatible with versa is sufficient. statedb, err := state.New(types.EmptyRootHash, db, nil) if err != nil { return common.Hash{}, err @@ -154,6 +156,7 @@ func flushAlloc(ga *types.GenesisAlloc, db ethdb.Database, triedb *triedb.Databa if triedbConfig != nil { triedbConfig.NoTries = false } + // TODO:: state.NewDatabase internally compatible with versa is sufficient. statedb, err := state.New(types.EmptyRootHash, state.NewDatabaseWithNodeDB(db, triedb), nil) if err != nil { return err diff --git a/core/state/pruner/pruner.go b/core/state/pruner/pruner.go index f4820c06b2..6d6564d680 100644 --- a/core/state/pruner/pruner.go +++ b/core/state/pruner/pruner.go @@ -232,6 +232,7 @@ func pruneAll(maindb ethdb.Database, g *core.Genesis) error { } log.Info("Database compaction finished", "elapsed", common.PrettyDuration(time.Since(cstart))) } + // TODO:: ignore, versa has its own prunner statedb, _ := state.New(common.Hash{}, state.NewDatabase(maindb), nil) for addr, account := range g.Alloc { statedb.AddBalance(addr, uint256.MustFromBig(account.Balance)) diff --git a/core/state/snapshot/snapshot.go b/core/state/snapshot/snapshot.go index 117504f8b6..6f1463eab4 100644 --- a/core/state/snapshot/snapshot.go +++ b/core/state/snapshot/snapshot.go @@ -205,6 +205,8 @@ type Tree struct { // state trie. // - otherwise, the entire snapshot is considered invalid and will be recreated on // a background thread. +// +// TODO:: if use versa, set SnapshotLimit == 0, will forbidden to use func New(config Config, diskdb ethdb.KeyValueStore, triedb *triedb.Database, root common.Hash, cap int, withoutTrie bool) (*Tree, error) { snap := &Tree{ config: config, diff --git a/core/vm/runtime/runtime.go b/core/vm/runtime/runtime.go index 46f2bb5d5f..b5e51288a1 100644 --- a/core/vm/runtime/runtime.go +++ b/core/vm/runtime/runtime.go @@ -115,6 +115,7 @@ func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) { setDefaults(cfg) if cfg.State == nil { + // TODO:: state.NewDatabase internally compatible with versa is sufficient. cfg.State, _ = state.New(types.EmptyRootHash, state.NewDatabase(rawdb.NewMemoryDatabase()), nil) } var ( @@ -149,6 +150,7 @@ func Create(input []byte, cfg *Config) ([]byte, common.Address, uint64, error) { setDefaults(cfg) if cfg.State == nil { + // TODO:: state.NewDatabase internally compatible with versa is sufficient. cfg.State, _ = state.New(types.EmptyRootHash, state.NewDatabase(rawdb.NewMemoryDatabase()), nil) } var ( diff --git a/eth/state_accessor.go b/eth/state_accessor.go index 946b292926..cced8ae33d 100644 --- a/eth/state_accessor.go +++ b/eth/state_accessor.go @@ -71,7 +71,9 @@ func (eth *Ethereum) hashState(ctx context.Context, block *types.Block, reexec u // the internal junks created by tracing will be persisted into the disk. // TODO(rjl493456442), clean cache is disabled to prevent memory leak, // please re-enable it for better performance. + // TODO:: state.NewDatabase internally compatible with versa is sufficient. database = state.NewDatabaseWithConfig(eth.chainDb, triedb.HashDefaults) + // TODO:: state.NewDatabase internally compatible with versa is sufficient. if statedb, err = state.New(block.Root(), database, nil); err == nil { log.Info("Found disk backend for state trie", "root", block.Root(), "number", block.Number()) return statedb, noopReleaser, nil @@ -91,13 +93,16 @@ func (eth *Ethereum) hashState(ctx context.Context, block *types.Block, reexec u // the internal junks created by tracing will be persisted into the disk. // TODO(rjl493456442), clean cache is disabled to prevent memory leak, // please re-enable it for better performance. + // TODO:: if use versa, tdb == nil tdb = triedb.NewDatabase(eth.chainDb, triedb.HashDefaults) + // TODO:: state.NewDatabase internally compatible with versa is sufficient. database = state.NewDatabaseWithNodeDB(eth.chainDb, tdb) // If we didn't check the live database, do check state over ephemeral database, // otherwise we would rewind past a persisted block (specific corner case is // chain tracing from the genesis). if !readOnly { + // TODO:: state.NewDatabase internally compatible with versa is sufficient. statedb, err = state.New(current.Root(), database, nil) if err == nil { return statedb, noopReleaser, nil @@ -116,7 +121,7 @@ func (eth *Ethereum) hashState(ctx context.Context, block *types.Block, reexec u return nil, nil, fmt.Errorf("missing block %v %d", current.ParentHash(), current.NumberU64()-1) } current = parent - + // TODO:: state.NewDatabase internally compatible with versa is sufficient. statedb, err = state.New(current.Root(), database, nil) if err == nil { break @@ -164,6 +169,7 @@ func (eth *Ethereum) hashState(ctx context.Context, block *types.Block, reexec u return nil, nil, fmt.Errorf("stateAtBlock commit failed, number %d root %v: %w", current.NumberU64(), current.Root().Hex(), err) } + // TODO:: state.NewDatabase internally compatible with versa is sufficient. statedb, err = state.New(root, database, nil) // nolint:staticcheck if err != nil { return nil, nil, fmt.Errorf("state reset after block %d failed: %v", current.NumberU64(), err) diff --git a/ethdb/database.go b/ethdb/database.go index 5d7d54353c..304fa79129 100644 --- a/ethdb/database.go +++ b/ethdb/database.go @@ -245,6 +245,7 @@ type BlockStore interface { HasSeparateBlockStore() bool } +// @TODO:: add VersaDB() method // Database contains all the methods required by the high level database to not // only access the key-value data store but also the chain freezer. type Database interface {