Skip to content
Open
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
12 changes: 12 additions & 0 deletions core/state/snapshot/difflayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,18 @@ func (dl *diffLayer) accountRLP(hash common.Hash, depth int) ([]byte, error) {
return dl.parent.AccountRLP(hash)
}

// StaleOrGenerating returns whether the snapshot is stale or generating
func (dl *diffLayer) StaleOrGenerating() bool {
dl.lock.RLock()
defer dl.lock.RUnlock()

if dl.Stale() {
return true
}

return dl.parent.Stale()
}

// Storage directly retrieves the storage data associated with a particular hash,
// within a particular account. If the slot is unknown to this diff, it's parent
// is consulted.
Expand Down
12 changes: 12 additions & 0 deletions core/state/snapshot/disklayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,18 @@ func (dl *diskLayer) AccountRLP(hash common.Hash) ([]byte, error) {
return blob, nil
}

// StaleOrGenerating returns whether the snapshot is stale or generating
func (dl *diskLayer) StaleOrGenerating() bool {
dl.lock.RLock()
defer dl.lock.RUnlock()

if dl.Stale() || dl.genMarker != nil {
return true
}

return false
}

// Storage directly retrieves the storage data associated with a particular hash,
// within a particular account.
func (dl *diskLayer) Storage(accountHash, storageHash common.Hash) ([]byte, error) {
Expand Down
3 changes: 3 additions & 0 deletions core/state/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ type Snapshot interface {
// Storage directly retrieves the storage data associated with a particular hash,
// within a particular account.
Storage(accountHash, storageHash common.Hash) ([]byte, error)

// StaleOrGenerating returns whether the snapshot is stale or generating
StaleOrGenerating() bool
}

// snapshot is the internal version of the snapshot data layer that supports some
Expand Down
8 changes: 8 additions & 0 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,14 @@ func newStateDB(root common.Hash, db Database, snaps *snapshot.Tree) (*StateDB,
return sdb, nil
}

func (s *StateDB) SnapshotAvailable() bool {
if s.snap == nil {
return false
}

return !s.snap.StaleOrGenerating()
}

func (s *StateDB) getBaseStateDB() *StateDB {
return s
}
Expand Down
5 changes: 5 additions & 0 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,11 @@ func (p *ParallelStateProcessor) doCleanUp() {

// Implement BEP-130: Parallel Transaction Execution.
func (p *ParallelStateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (*state.StateDB, types.Receipts, []*types.Log, uint64, error) {
// if snapshot is nil or generating, fall back to sequential process
if !statedb.SnapshotAvailable() {
return p.StateProcessor.Process(block, statedb, cfg)
}

var (
usedGas = new(uint64)
header = block.Header()
Expand Down