Skip to content

Commit e311c80

Browse files
authored
Reduce redunant payload creation (ethereum#44)
* Remove redundant payload creation * pr comments
1 parent d42e650 commit e311c80

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

miner/multi_worker.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,23 +113,27 @@ func (w *multiWorker) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
113113
// Construct a payload object for return.
114114
payload := newPayload(empty, args.Id())
115115

116+
if len(w.workers) == 0 {
117+
return payload, nil
118+
}
119+
116120
// Keep separate payloads for each worker so that ResolveFull actually resolves the best of all workers
117121
workerPayloads := []*Payload{}
118122

119-
for _, worker := range w.workers {
123+
for _, w := range w.workers {
120124
workerPayload := newPayload(empty, args.Id())
121125
workerPayloads = append(workerPayloads, workerPayload)
122-
go func() {
123-
// Update routine done elsewhere!
124126

127+
go func(w *worker) {
128+
// Update routine done elsewhere!
125129
start := time.Now()
126-
block, fees, err := worker.getSealingBlock(args.Parent, args.Timestamp, args.FeeRecipient, args.GasLimit, args.Random, args.Withdrawals, false, args.BlockHook)
130+
block, fees, err := w.getSealingBlock(args.Parent, args.Timestamp, args.FeeRecipient, args.GasLimit, args.Random, args.Withdrawals, false, args.BlockHook)
127131
if err == nil {
128132
workerPayload.update(block, fees, time.Since(start))
129133
}
130-
}()
134+
}(w)
131135
}
132-
136+
133137
go payload.resolveBestFullPayload(workerPayloads)
134138

135139
return payload, nil

miner/payload_building.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func newPayload(empty *types.Block, id engine.PayloadID) *Payload {
7979
empty: empty,
8080
stop: make(chan struct{}),
8181
}
82-
log.Info("Starting work on payload", "id", payload.id)
82+
8383
payload.cond = sync.NewCond(&payload.lock)
8484
return payload
8585
}
@@ -113,7 +113,7 @@ func (payload *Payload) resolveBestFullPayload(payloads []*Payload) {
113113
payload.lock.Lock()
114114
defer payload.lock.Unlock()
115115

116-
log.Info("XXX resolving")
116+
log.Trace("resolving best payload")
117117
for _, p := range payloads {
118118
p.lock.Lock()
119119

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

134134
if payload.full == nil || payload.fullFees.Cmp(p.fullFees) < 0 {
135-
log.Info("XXX updated")
135+
log.Trace("best payload updated", "id", p.id, "blockHash", p.full.Hash())
136136
payload.full = p.full
137137
payload.fullFees = p.fullFees
138138
}
139139
p.lock.Unlock()
140140
}
141141
}
142142

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

0 commit comments

Comments
 (0)