fixes to replay ~500 blocks

This commit is contained in:
Guillaume Ballet 2023-08-14 16:56:43 +02:00
parent 54e060f094
commit a80c2aa8b5
3 changed files with 15 additions and 18 deletions

View file

@ -1746,6 +1746,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
if parent.Number.Uint64() == conversionBlock { if parent.Number.Uint64() == conversionBlock {
bc.StartVerkleTransition(parent.Root, emptyVerkleRoot, bc.Config(), &parent.Time) bc.StartVerkleTransition(parent.Root, emptyVerkleRoot, bc.Config(), &parent.Time)
bc.stateCache.SetLastMerkleRoot(parent.Root)
} }
statedb, err := state.New(parent.Root, bc.stateCache, bc.snaps) statedb, err := state.New(parent.Root, bc.stateCache, bc.snaps)
if err != nil { if err != nil {

View file

@ -1080,6 +1080,10 @@ func (s *StateDB) clearJournalAndRefund() {
// deleteStorage iterates the storage trie belongs to the account and mark all // deleteStorage iterates the storage trie belongs to the account and mark all
// slots inside as deleted. // slots inside as deleted.
func (s *StateDB) deleteStorage(addr common.Address, addrHash common.Hash, root common.Hash) (bool, map[common.Hash][]byte, *trienode.NodeSet, error) { func (s *StateDB) deleteStorage(addr common.Address, addrHash common.Hash, root common.Hash) (bool, map[common.Hash][]byte, *trienode.NodeSet, error) {
// verkle: a deletion is akin to overwriting with 0s
if s.GetTrie().IsVerkle() {
return false, nil, nil, nil
}
start := time.Now() start := time.Now()
tr, err := s.db.OpenStorageTrie(s.originalRoot, addr, root, s.trie) tr, err := s.db.OpenStorageTrie(s.originalRoot, addr, root, s.trie)
// XXX NOTE: it might just be possible to use an empty trie here, as verkle will not // XXX NOTE: it might just be possible to use an empty trie here, as verkle will not

View file

@ -20,7 +20,6 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie/trienode" "github.com/ethereum/go-ethereum/trie/trienode"
"github.com/gballet/go-verkle" "github.com/gballet/go-verkle"
) )
@ -67,22 +66,7 @@ func (t *TransitionTrie) GetStorage(addr common.Address, key []byte) ([]byte, er
return val, nil return val, nil
} }
// TODO also insert value into overlay // TODO also insert value into overlay
rlpval, err := t.base.GetStorage(addr, key) return t.base.GetStorage(addr, key)
if err != nil {
return nil, err
}
if len(rlpval) == 0 {
return nil, nil
}
// the value will come as RLP, decode it so that the
// interface is consistent.
_, content, _, err := rlp.Split(rlpval)
if err != nil || len(content) == 0 {
return nil, err
}
var v [32]byte
copy(v[32-len(content):], content)
return v[:], nil
} }
// GetAccount abstract an account read from the trie. // GetAccount abstract an account read from the trie.
@ -111,7 +95,15 @@ func (t *TransitionTrie) GetAccount(address common.Address) (*types.StateAccount
// by the caller while they are stored in the trie. If a node was not found in the // by the caller while they are stored in the trie. If a node was not found in the
// database, a trie.MissingNodeError is returned. // database, a trie.MissingNodeError is returned.
func (t *TransitionTrie) UpdateStorage(address common.Address, key []byte, value []byte) error { func (t *TransitionTrie) UpdateStorage(address common.Address, key []byte, value []byte) error {
return t.overlay.UpdateStorage(address, key, value) var v []byte
if len(value) >= 32 {
v = value[:32]
} else {
var val [32]byte
copy(val[32-len(value):], value[:])
v = val[:]
}
return t.overlay.UpdateStorage(address, key, v)
} }
// UpdateAccount abstract an account write to the trie. // UpdateAccount abstract an account write to the trie.