Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[R4R] fix: remove diffhash patch introduced from separate node #1020

Merged
merged 1 commit into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 1 addition & 16 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,19 @@ package state

import (
"bytes"
"errors"
"fmt"
"io"
"math/big"
"sync"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state/snapshot"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/rlp"
)

const snapshotStaleRetryInterval = time.Millisecond * 10

var emptyCodeHash = crypto.Keccak256(nil)

type Code []byte
Expand Down Expand Up @@ -271,18 +267,7 @@ func (s *StateObject) GetCommittedState(db Database, key common.Hash) common.Has
}
enc, err = s.db.snap.Storage(s.addrHash, crypto.Keccak256Hash(key.Bytes()))
}
// ErrSnapshotStale may occur due to diff layers in the update, so we should try again in noTrie mode.
if s.db.NoTrie() && err != nil && errors.Is(err, snapshot.ErrSnapshotStale) {
// This error occurs when statedb.snaps.Cap changes the state of the merged difflayer
// to stale during the refresh of the difflayer, indicating that it is about to be discarded.
// Since the difflayer is refreshed in parallel,
// there is a small chance that the difflayer of the stale will be read while reading,
// resulting in an empty array being returned here.
// Therefore, noTrie mode must retry here,
// and add a time interval when retrying to avoid stacking too much and causing stack overflow.
time.Sleep(snapshotStaleRetryInterval)
return s.GetCommittedState(db, key)
}

// If snapshot unavailable or reading from it failed, load from the database
if s.db.snap == nil || err != nil {
if meter != nil {
Expand Down
13 changes: 0 additions & 13 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,19 +655,6 @@ func (s *StateDB) getDeletedStateObject(addr common.Address) *StateObject {
}
}

// ErrSnapshotStale may occur due to diff layers in the update, so we should try again in noTrie mode.
if s.NoTrie() && err != nil && errors.Is(err, snapshot.ErrSnapshotStale) {
// This error occurs when statedb.snaps.Cap changes the state of the merged difflayer
// to stale during the refresh of the difflayer, indicating that it is about to be discarded.
// Since the difflayer is refreshed in parallel,
// there is a small chance that the difflayer of the stale will be read while reading,
// resulting in an empty array being returned here.
// Therefore, noTrie mode must retry here,
// and add a time interval when retrying to avoid stacking too much and causing OOM.
time.Sleep(snapshotStaleRetryInterval)
return s.getDeletedStateObject(addr)
}

// If snapshot unavailable or reading from it failed, load from the database
if s.snap == nil || err != nil {
if s.trie == nil {
Expand Down