diff --git a/core/blockchain.go b/core/blockchain.go index 1c7dad957e..b3513ff4cd 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1746,6 +1746,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) if parent.Number.Uint64() == conversionBlock { bc.StartVerkleTransition(parent.Root, emptyVerkleRoot, bc.Config(), &parent.Time) + bc.stateCache.SetLastMerkleRoot(parent.Root) } statedb, err := state.New(parent.Root, bc.stateCache, bc.snaps) if err != nil { diff --git a/core/state/statedb.go b/core/state/statedb.go index f0ec65d1d2..1a64ba0bb5 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -1080,6 +1080,10 @@ func (s *StateDB) clearJournalAndRefund() { // deleteStorage iterates the storage trie belongs to the account and mark all // 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) { + // verkle: a deletion is akin to overwriting with 0s + if s.GetTrie().IsVerkle() { + return false, nil, nil, nil + } start := time.Now() 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 diff --git a/trie/transition.go b/trie/transition.go index 514d3e9982..ad5a7dc701 100644 --- a/trie/transition.go +++ b/trie/transition.go @@ -20,7 +20,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethdb" - "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/trie/trienode" "github.com/gballet/go-verkle" ) @@ -67,22 +66,7 @@ func (t *TransitionTrie) GetStorage(addr common.Address, key []byte) ([]byte, er return val, nil } // TODO also insert value into overlay - rlpval, err := 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 + return t.base.GetStorage(addr, key) } // 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 // database, a trie.MissingNodeError is returned. 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.