Skip to content

Commit

Permalink
snapsync: fix some sync error;
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbundler committed Nov 27, 2023
1 parent ebb9d1b commit 890bc31
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion core/state/state_expiry.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func tryReviveState(meta *stateExpiryMeta, addr common.Address, root common.Hash
case *trie.MissingNodeError:
// cannot revive locally, request from remote
case nil:
log.Info("tryReviveState localrevive", "addr", addr, "key", key, "val", common.BytesToHash(val), "err", err)
//log.Debug("tryReviveState localrevive", "addr", addr, "key", key, "val", common.BytesToHash(val), "err", err)
reviveFromLocalMeter.Mark(1)
return map[string][]byte{string(crypto.Keccak256(key[:])): val}, nil
default:
Expand Down
18 changes: 8 additions & 10 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
"sync"
"time"

"github.com/ethereum/go-ethereum/log"

"github.com/ethereum/go-ethereum/core/state/snapshot"
"github.com/ethereum/go-ethereum/trie"

Expand Down Expand Up @@ -238,19 +236,19 @@ func (s *stateObject) GetCommittedState(key common.Hash) common.Hash {
getCommittedStorageMeter.Mark(1)
// If we have a pending write or clean cached, return that
if value, pending := s.pendingStorage[key]; pending {
log.Info("GetCommittedState pendingStorage", "addr", s.address, "key", key, "val", value)
//log.Debug("GetCommittedState pendingStorage", "addr", s.address, "key", key, "val", value)
return value
}

if s.db.EnableExpire() {
if revived, revive := s.queryFromReviveState(s.pendingReviveState, key); revive {
log.Info("GetCommittedState queryFromReviveState", "addr", s.address, "key", key, "val", revived)
//log.Debug("GetCommittedState queryFromReviveState", "addr", s.address, "key", key, "val", revived)
return revived
}
}

if value, cached := s.getOriginStorage(key); cached {
log.Info("GetCommittedState getOriginStorage", "addr", s.address, "key", key, "val", value)
//log.Debug("GetCommittedState getOriginStorage", "addr", s.address, "key", key, "val", value)
return value
}

Expand All @@ -277,7 +275,7 @@ func (s *stateObject) GetCommittedState(key common.Hash) common.Hash {
enc, err = s.getExpirySnapStorage(key)
if len(enc) > 0 {
value.SetBytes(enc)
log.Info("GetCommittedState getExpirySnapStorage", "addr", s.address, "key", key, "val", value)
//log.Debug("GetCommittedState getExpirySnapStorage", "addr", s.address, "key", key, "val", value)
}
} else {
enc, err = s.db.snap.Storage(s.addrHash, crypto.Keccak256Hash(key.Bytes()))
Expand All @@ -287,7 +285,7 @@ func (s *stateObject) GetCommittedState(key common.Hash) common.Hash {
s.db.setError(err)
}
value.SetBytes(content)
log.Info("GetCommittedState Storage", "addr", s.address, "key", key, "val", value, "err", err)
//log.Debug("GetCommittedState Storage", "addr", s.address, "key", key, "val", value, "err", err)
}
}
if metrics.EnabledExpensive {
Expand All @@ -311,7 +309,7 @@ func (s *stateObject) GetCommittedState(key common.Hash) common.Hash {
}
var val []byte
val, err = tr.GetStorage(s.address, key.Bytes())
log.Info("GetCommittedState GetStorage", "addr", s.address, "key", key, "val", common.BytesToHash(val), "err", err)
//log.Debug("GetCommittedState GetStorage", "addr", s.address, "key", key, "val", common.BytesToHash(val), "err", err)
if metrics.EnabledExpensive {
s.db.StorageReads += time.Since(start)
}
Expand All @@ -320,7 +318,7 @@ func (s *stateObject) GetCommittedState(key common.Hash) common.Hash {
if path, ok := trie.ParseExpiredNodeErr(err); ok {
val, err = s.tryReviveState(path, key)
getCommittedStorageExpiredMeter.Mark(1)
log.Info("GetCommittedState tryReviveState", "addr", s.address, "key", key, "val", common.BytesToHash(val), "err", err)
//log.Debug("GetCommittedState tryReviveState", "addr", s.address, "key", key, "val", common.BytesToHash(val), "err", err)
} else if err == nil {
getCommittedStorageUnexpiredMeter.Mark(1)
// TODO(0xbundler): add epoch record cache for prevent frequency access epoch update, may implement later
Expand Down Expand Up @@ -942,7 +940,7 @@ func (s *stateObject) tryReviveState(prefixKey []byte, key common.Hash) ([]byte,

for k, v := range kvs {
s.pendingReviveState[k] = common.BytesToHash(v)
log.Info("tryReviveState tryReviveState", "addr", s.address, "key", key, "kvk", k, "kvv", common.BytesToHash(v))
//log.Debug("tryReviveState tryReviveState", "addr", s.address, "key", key, "kvk", k, "kvv", common.BytesToHash(v))
}

getCommittedStorageRemoteMeter.Mark(1)
Expand Down
7 changes: 6 additions & 1 deletion trie/secure_trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,5 +327,10 @@ func (t *StateTrie) TryRevive(key []byte, proof []*MPTProofNub) ([]*MPTProofNub,

func (t *StateTrie) TryLocalRevive(_ common.Address, key []byte) ([]byte, error) {
key = t.hashKey(key)
return t.trie.TryLocalRevive(key)
enc, err := t.trie.TryLocalRevive(key)
if err != nil || len(enc) == 0 {
return nil, err
}
_, content, _, err := rlp.Split(enc)
return content, err
}

0 comments on commit 890bc31

Please sign in to comment.