chore: add influence for versadb
This commit is contained in:
parent
83a9b13771
commit
ba71e76c55
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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())
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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))
|
||||
|
@ -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,
|
||||
|
@ -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 (
|
||||
|
@ -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)
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user