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

add sharedStorage to the prefetcher of miner #818

Merged
merged 2 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,11 @@ func (bc *BlockChain) StateAt(root common.Hash) (*state.StateDB, error) {
return state.New(root, bc.stateCache, bc.snaps)
}

// StateAtWithSharedPool returns a new mutable state based on a particular point in time with sharedStorage
func (bc *BlockChain) StateAtWithSharedPool(root common.Hash) (*state.StateDB, error) {
return state.NewWithSharedPool(root, bc.stateCache, bc.snaps)
}

// StateCache returns the caching database underpinning the blockchain instance.
func (bc *BlockChain) StateCache() state.Database {
return bc.stateCache
Expand Down
4 changes: 2 additions & 2 deletions core/state/state_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ type StateObject struct {
trie Trie // storage trie, which becomes non-nil on first access
code Code // contract bytecode, which gets set when code is loaded

sharedOriginStorage *sync.Map // Storage cache of original entries to dedup rewrites, reset for every transaction
originStorage Storage
sharedOriginStorage *sync.Map // Point to the entry of the stateObject in sharedPool
originStorage Storage // Storage cache of original entries to dedup rewrites, reset for every transaction

pendingStorage Storage // Storage entries that need to be flushed to disk, at the end of an entire block
dirtyStorage Storage // Storage entries that have been modified in the current transaction execution
Expand Down
6 changes: 4 additions & 2 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ func (w *worker) resultLoop() {
func (w *worker) makeCurrent(parent *types.Block, header *types.Header) error {
// Retrieve the parent state to execute on top and start a prefetcher for
// the miner to speed block sealing up a bit
state, err := w.chain.StateAt(parent.Root())
state, err := w.chain.StateAtWithSharedPool(parent.Root())
if err != nil {
return err
}
Expand Down Expand Up @@ -786,7 +786,9 @@ func (w *worker) commitTransactions(txs *types.TransactionsByPriceAndNonce, coin
txCurr := &tx
//prefetch txs from all pending txs
txsPrefetch := txs.Copy()
w.prefetcher.PrefetchMining(txsPrefetch, w.current.header, w.current.gasPool.Gas(), w.current.state.Copy(), *w.chain.GetVMConfig(), interruptCh, txCurr)
newStatedb := w.current.state.Copy()
qinglin89 marked this conversation as resolved.
Show resolved Hide resolved
newStatedb.EnableWriteOnSharedStorage()
w.prefetcher.PrefetchMining(txsPrefetch, w.current.header, w.current.gasPool.Gas(), newStatedb, *w.chain.GetVMConfig(), interruptCh, txCurr)

LOOP:
for {
Expand Down