mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
review feedback + root node resolution in OpenTrie
This commit is contained in:
parent
3249aa6949
commit
9a95be4ba1
3 changed files with 19 additions and 3 deletions
|
|
@ -421,13 +421,15 @@ func (g *Genesis) configOrDefault(ghash common.Hash) *params.ChainConfig {
|
|||
}
|
||||
}
|
||||
|
||||
func (g *Genesis) isVerkle() bool {
|
||||
// IsVerkle indicates whether the state is already stored in a verkle
|
||||
// tree at genesis time.
|
||||
func (g *Genesis) IsVerkle() bool {
|
||||
return g.Config.IsVerkle(new(big.Int).SetUint64(g.Number), g.Timestamp)
|
||||
}
|
||||
|
||||
// ToBlock returns the genesis block according to genesis specification.
|
||||
func (g *Genesis) ToBlock() *types.Block {
|
||||
root, err := g.Alloc.hash(g.isVerkle())
|
||||
root, err := g.Alloc.hash(g.IsVerkle())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import (
|
|||
"github.com/ethereum/go-ethereum/trie"
|
||||
"github.com/ethereum/go-ethereum/trie/trienode"
|
||||
"github.com/ethereum/go-ethereum/trie/utils"
|
||||
"github.com/gballet/go-verkle"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
@ -172,7 +173,19 @@ type cachingDB struct {
|
|||
// OpenTrie opens the main account trie at a specific root hash.
|
||||
func (db *cachingDB) OpenTrie(root common.Hash) (Trie, error) {
|
||||
if db.triedb.IsVerkle() {
|
||||
return trie.NewVerkleTrie(nil, db.triedb, utils.NewPointCache(), true)
|
||||
reader, err := db.triedb.Reader(root)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get node reader in OpenTrie: %w", err)
|
||||
}
|
||||
verklerootbytes, err := reader.Node(common.Hash{}, nil, common.Hash{})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get serialized root node in OpenTrie: %w", err)
|
||||
}
|
||||
verkleroot, err := verkle.ParseNode(verklerootbytes, 0)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to deserialize root node in OpenTrie: %w", err)
|
||||
}
|
||||
return trie.NewVerkleTrie(verkleroot, db.triedb, utils.NewPointCache(), true)
|
||||
}
|
||||
tr, err := trie.NewStateTrie(trie.StateTrieID(root), db.triedb)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -284,6 +284,7 @@ func (trie *VerkleTrie) Copy() *VerkleTrie {
|
|||
}
|
||||
}
|
||||
|
||||
// IsVerkle indicates if the trie is a Verkle trie.
|
||||
func (trie *VerkleTrie) IsVerkle() bool {
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue