Skip to content

Commit

Permalink
remove prefetch
Browse files Browse the repository at this point in the history
  • Loading branch information
Jolly23 committed Mar 15, 2024
1 parent 3462009 commit a0a39d1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 45 deletions.
2 changes: 1 addition & 1 deletion core/puissant.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func (pc *snapshotSet) revert(bID types.PuissantID, currEnv *MinerEnvironment) {

if currEnv.TxCount != load.storeEnv.TxCount {
// should reload work env
load.storeEnv.State.TransferPrefetcher(currEnv.State)
//load.storeEnv.State.TransferPrefetcher(currEnv.State)
*currEnv = *load.storeEnv
}

Expand Down
2 changes: 1 addition & 1 deletion core/puissant_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (env *MinerEnvironment) Copy() *MinerEnvironment {
// the go-routine leak can happen.
func (env *MinerEnvironment) Discard() {
if env.State != nil {
env.State.StopPrefetcher()
//env.State.StopPrefetcher()
}
}

Expand Down
9 changes: 1 addition & 8 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ type worker struct {

wg sync.WaitGroup

current *core.MinerEnvironment // An environment for current running cycle.

mu sync.RWMutex // The lock used to protect the coinbase and extra fields
coinbase common.Address
extra []byte
Expand Down Expand Up @@ -447,11 +445,6 @@ func (w *worker) newWorkLoop(recommit time.Duration) {
func (w *worker) mainLoop() {
defer w.wg.Done()
defer w.chainHeadSub.Unsubscribe()
defer func() {
if w.current != nil {
w.current.Discard()
}
}()

for {
select {
Expand Down Expand Up @@ -700,7 +693,7 @@ func (w *worker) prepareWork(genParams *generateParams) (*core.MinerEnvironment,
// Could potentially happen if starting to mine in an odd state.
// Note genParams.coinbase can be different with header.Coinbase
// since clique algorithm can modify the coinbase field in header.
env, err := w.makeEnv(parent, header, genParams.coinbase, genParams.prevWork)
env, err := w.makeEnv(parent, header, genParams.coinbase)
if err != nil {
log.Error("Failed to create sealing context", "err", err)
return nil, err
Expand Down
38 changes: 3 additions & 35 deletions miner/worker_puissant.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ type generateParams struct {
coinbase common.Address // The fee recipient address for including transaction
random common.Hash // The randomness generated by beacon chain, empty before the merge
withdrawals types.Withdrawals // List of withdrawals to include in block.
prevWork *core.MinerEnvironment
noTxs bool // Flag whether an empty block without any transaction is expected
noTxs bool // Flag whether an empty block without any transaction is expected
}

type multiPackingWork struct {
Expand All @@ -46,20 +45,11 @@ type multiPackingWork struct {
}

// makeEnv creates a new environment for the sealing block.
func (w *worker) makeEnv(parent *types.Header, header *types.Header, coinbase common.Address,
prevEnv *core.MinerEnvironment) (*core.MinerEnvironment, error) {

// Retrieve the parent state to execute on top and start a prefetcher for
// the miner to speed block sealing up a bit
func (w *worker) makeEnv(parent *types.Header, header *types.Header, coinbase common.Address) (*core.MinerEnvironment, error) {
topState, err := w.chain.StateAt(parent.Root)
if err != nil {
return nil, err
}
if prevEnv == nil {
topState.StartPrefetcher("miner")
} else {
topState.TransferPrefetcher(prevEnv.State)
}

// Note the passed coinbase may be different with header.Coinbase.
env := &core.MinerEnvironment{
Expand Down Expand Up @@ -97,32 +87,17 @@ func (w *worker) commitWork(interruptCh chan int32, timestamp int64) {
return
}
}
var prevWork *core.MinerEnvironment
defer func() {
for _, wk := range workList {
// only keep the best work, discard others.
if wk.work == w.current {
continue
}
wk.work.Discard()
}
}()

// validator can try several times to get the most profitable block,
// as long as the timestamp is not reached.
LOOP:
for round := 0; round < math.MaxInt64; round++ {
roundStart := time.Now()

work, err := w.prepareWork(&generateParams{
timestamp: uint64(timestamp),
coinbase: coinbase,
prevWork: prevWork,
})
work, err := w.prepareWork(&generateParams{timestamp: uint64(timestamp), coinbase: coinbase})
if err != nil {
return
}
prevWork = work
thisRound := &multiPackingWork{round: round, work: work, income: new(big.Int)}
workList = append(workList, thisRound)

Expand Down Expand Up @@ -243,13 +218,6 @@ LOOP:
bestWork := pickTheMostProfitableWork(workList)
_ = w.commit(bestWork.work, w.fullTaskHook, true, start)

// Swap out the old work with the new one, terminating any leftover
// prefetcher processes in the mean time and starting a new one.
if w.current != nil {
w.current.Discard()
}
w.current = bestWork.work

if p, ok := w.engine.(*parlia.Parlia); ok {
go func() {
tgMsg := pReporter.Finalize(blockNumber, bestWork.round, bestWork.income, p.SignText)
Expand Down

0 comments on commit a0a39d1

Please sign in to comment.