Skip to content

Commit

Permalink
Reduce redunant payload creation (ethereum#44)
Browse files Browse the repository at this point in the history
* Remove redundant payload creation

* pr comments
  • Loading branch information
avalonche authored Mar 9, 2023
1 parent d42e650 commit e311c80
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
16 changes: 10 additions & 6 deletions miner/multi_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,27 @@ func (w *multiWorker) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
// Construct a payload object for return.
payload := newPayload(empty, args.Id())

if len(w.workers) == 0 {
return payload, nil
}

// Keep separate payloads for each worker so that ResolveFull actually resolves the best of all workers
workerPayloads := []*Payload{}

for _, worker := range w.workers {
for _, w := range w.workers {
workerPayload := newPayload(empty, args.Id())
workerPayloads = append(workerPayloads, workerPayload)
go func() {
// Update routine done elsewhere!

go func(w *worker) {
// Update routine done elsewhere!
start := time.Now()
block, fees, err := worker.getSealingBlock(args.Parent, args.Timestamp, args.FeeRecipient, args.GasLimit, args.Random, args.Withdrawals, false, args.BlockHook)
block, fees, err := w.getSealingBlock(args.Parent, args.Timestamp, args.FeeRecipient, args.GasLimit, args.Random, args.Withdrawals, false, args.BlockHook)
if err == nil {
workerPayload.update(block, fees, time.Since(start))
}
}()
}(w)
}

go payload.resolveBestFullPayload(workerPayloads)

return payload, nil
Expand Down
8 changes: 4 additions & 4 deletions miner/payload_building.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func newPayload(empty *types.Block, id engine.PayloadID) *Payload {
empty: empty,
stop: make(chan struct{}),
}
log.Info("Starting work on payload", "id", payload.id)

payload.cond = sync.NewCond(&payload.lock)
return payload
}
Expand Down Expand Up @@ -113,7 +113,7 @@ func (payload *Payload) resolveBestFullPayload(payloads []*Payload) {
payload.lock.Lock()
defer payload.lock.Unlock()

log.Info("XXX resolving")
log.Trace("resolving best payload")
for _, p := range payloads {
p.lock.Lock()

Expand All @@ -132,15 +132,15 @@ func (payload *Payload) resolveBestFullPayload(payloads []*Payload) {
}

if payload.full == nil || payload.fullFees.Cmp(p.fullFees) < 0 {
log.Info("XXX updated")
log.Trace("best payload updated", "id", p.id, "blockHash", p.full.Hash())
payload.full = p.full
payload.fullFees = p.fullFees
}
p.lock.Unlock()
}
}

log.Info("XXX resolved")
log.Trace("best payload resolved", "id", payload.id, "blockHash", payload.full.Hash())
payload.cond.Broadcast() // fire signal for notifying full block
}

Expand Down

0 comments on commit e311c80

Please sign in to comment.