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 pipecommit active statedb #1002

Merged
merged 2 commits into from
Jul 26, 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
16 changes: 10 additions & 6 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,11 @@ func (s *StateObject) getTrie(db Database) Trie {
if s.trie == nil {
// Try fetching from prefetcher first
// We don't prefetch empty tries
if s.data.Root != emptyRoot && s.db.prefetcher != nil {
prefetcher := s.db.prefetcher
if s.data.Root != emptyRoot && prefetcher != nil {
// When the miner is creating the pending state, there is no
// prefetcher
s.trie = s.db.prefetcher.trie(s.data.Root)
s.trie = prefetcher.trie(s.data.Root)
}
if s.trie == nil {
var err error
Expand Down Expand Up @@ -375,8 +376,9 @@ func (s *StateObject) finalise(prefetch bool) {
}
}

if s.db.prefetcher != nil && prefetch && len(slotsToPrefetch) > 0 && s.data.Root != emptyRoot && s.data.Root != dummyRoot {
s.db.prefetcher.prefetch(s.data.Root, slotsToPrefetch, s.addrHash)
prefetcher := s.db.prefetcher
if prefetcher != nil && prefetch && len(slotsToPrefetch) > 0 && s.data.Root != emptyRoot && s.data.Root != dummyRoot {
prefetcher.prefetch(s.data.Root, slotsToPrefetch, s.addrHash)
}
if len(s.dirtyStorage) > 0 {
s.dirtyStorage = make(Storage)
Expand Down Expand Up @@ -455,9 +457,11 @@ func (s *StateObject) updateTrie(db Database) Trie {
}
wg.Wait()

if s.db.prefetcher != nil {
s.db.prefetcher.used(s.data.Root, usedStorage)
prefetcher := s.db.prefetcher
if prefetcher != nil {
prefetcher.used(s.data.Root, usedStorage)
}

if len(s.pendingStorage) > 0 {
s.pendingStorage = make(Storage)
}
Expand Down
10 changes: 6 additions & 4 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,8 +857,9 @@ func (s *StateDB) Copy() *StateDB {
// If there's a prefetcher running, make an inactive copy of it that can
// only access data but does not actively preload (since the user will not
// know that they need to explicitly terminate an active copy).
if s.prefetcher != nil {
state.prefetcher = s.prefetcher.copy()
prefetcher := s.prefetcher
if prefetcher != nil {
state.prefetcher = prefetcher.copy()
}
if s.snaps != nil {
// In order for the miner to be able to use and make additions
Expand Down Expand Up @@ -970,8 +971,9 @@ func (s *StateDB) Finalise(deleteEmptyObjects bool) {
addressesToPrefetch = append(addressesToPrefetch, common.CopyBytes(addr[:])) // Copy needed for closure
}
}
if s.prefetcher != nil && len(addressesToPrefetch) > 0 {
s.prefetcher.prefetch(s.originalRoot, addressesToPrefetch, emptyAddr)
prefetcher := s.prefetcher
if prefetcher != nil && len(addressesToPrefetch) > 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add some UTs to battle test the concurrence issue of statedb?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pointer assignment is actually atomic, but would fail race detection.

prefetcher.prefetch(s.originalRoot, addressesToPrefetch, emptyAddr)
}
// Invalidate journal because reverting across transactions is not allowed.
s.clearJournalAndRefund()
Expand Down