core/state: value diff tracking in StateDB (#27349)
This change makes the StateDB track the state key value diff of a block transition. We already tracked current account and storage values for the purpose of updating the state snapshot. With this PR, we now also track the original (pre-transition) values of accounts and storage slots.
This commit is contained in:
@@ -220,7 +220,7 @@ func (c *ChtIndexerBackend) Commit() error {
|
||||
}
|
||||
// Commit trie changes into trie database in case it's not nil.
|
||||
if nodes != nil {
|
||||
if err := c.triedb.Update(root, c.originRoot, trienode.NewWithNodeSet(nodes)); err != nil {
|
||||
if err := c.triedb.Update(root, c.originRoot, trienode.NewWithNodeSet(nodes), nil); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := c.triedb.Commit(root, false); err != nil {
|
||||
@@ -473,7 +473,7 @@ func (b *BloomTrieIndexerBackend) Commit() error {
|
||||
}
|
||||
// Commit trie changes into trie database in case it's not nil.
|
||||
if nodes != nil {
|
||||
if err := b.triedb.Update(root, b.originRoot, trienode.NewWithNodeSet(nodes)); err != nil {
|
||||
if err := b.triedb.Update(root, b.originRoot, trienode.NewWithNodeSet(nodes), nil); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := b.triedb.Commit(root, false); err != nil {
|
||||
|
||||
+14
-11
@@ -121,19 +121,22 @@ func (t *odrTrie) GetStorage(_ common.Address, key []byte) ([]byte, error) {
|
||||
}
|
||||
|
||||
func (t *odrTrie) GetAccount(address common.Address) (*types.StateAccount, error) {
|
||||
var res types.StateAccount
|
||||
key := crypto.Keccak256(address.Bytes())
|
||||
var (
|
||||
enc []byte
|
||||
key = crypto.Keccak256(address.Bytes())
|
||||
)
|
||||
err := t.do(key, func() (err error) {
|
||||
value, err := t.trie.Get(key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if value == nil {
|
||||
return nil
|
||||
}
|
||||
return rlp.DecodeBytes(value, &res)
|
||||
enc, err = t.trie.Get(key)
|
||||
return err
|
||||
})
|
||||
return &res, err
|
||||
if err != nil || len(enc) == 0 {
|
||||
return nil, err
|
||||
}
|
||||
acct := new(types.StateAccount)
|
||||
if err := rlp.DecodeBytes(enc, acct); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return acct, nil
|
||||
}
|
||||
|
||||
func (t *odrTrie) UpdateAccount(address common.Address, acc *types.StateAccount) error {
|
||||
|
||||
Reference in New Issue
Block a user