@@ -99,14 +99,15 @@ func newPayload(empty *types.Block, emptyRequests [][]byte, witness *stateless.W
9999 return payload
100100}
101101
102- // update updates the full-block with latest built version.
103- func (payload * Payload ) update (r * newPayloadResult , elapsed time.Duration ) {
102+ // update updates the full-block with latest built version. It returns true if
103+ // the update was accepted (i.e. the new block has higher fees than the previous).
104+ func (payload * Payload ) update (r * newPayloadResult , elapsed time.Duration ) bool {
104105 payload .lock .Lock ()
105106 defer payload .lock .Unlock ()
106107
107108 select {
108109 case <- payload .stop :
109- return // reject stale update
110+ return false // reject stale update
110111 default :
111112 }
112113 // Ensure the newly provided full block has a higher transaction fee.
@@ -131,8 +132,10 @@ func (payload *Payload) update(r *newPayloadResult, elapsed time.Duration) {
131132 "root" , r .block .Root (),
132133 "elapsed" , common .PrettyDuration (elapsed ),
133134 )
135+ payload .cond .Broadcast () // fire signal for notifying full block
136+ return true
134137 }
135- payload . cond . Broadcast () // fire signal for notifying full block
138+ return false
136139}
137140
138141// Resolve returns the latest built payload and also terminates the background
@@ -209,7 +212,12 @@ func (payload *Payload) ResolveFull() *engine.ExecutionPayloadEnvelope {
209212
210213// buildPayload builds the payload according to the provided parameters.
211214func (miner * Miner ) buildPayload (ctx context.Context , args * BuildPayloadArgs , witness bool ) (result * Payload , err error ) {
212- ctx , _ , spanEnd := telemetry .StartSpan (ctx , "miner.buildPayload" )
215+ payloadID := args .Id ()
216+ ctx , _ , spanEnd := telemetry .StartSpan (ctx , "miner.buildPayload" ,
217+ telemetry .StringAttribute ("payload.id" , payloadID .String ()),
218+ telemetry .StringAttribute ("parent.hash" , args .Parent .String ()),
219+ telemetry .Int64Attribute ("timestamp" , int64 (args .Timestamp )),
220+ )
213221 defer spanEnd (err )
214222
215223 // Build the initial version with no transaction included. It should be fast
@@ -225,18 +233,25 @@ func (miner *Miner) buildPayload(ctx context.Context, args *BuildPayloadArgs, wi
225233 beaconRoot : args .BeaconRoot ,
226234 noTxs : true ,
227235 }
228- empty := miner .generateWork (emptyParams , witness )
236+ empty := miner .generateWork (ctx , emptyParams , witness )
229237 if empty .err != nil {
230238 return nil , empty .err
231239 }
232240 // Construct a payload object for return.
233- payload := newPayload (empty .block , empty .requests , empty .witness , args . Id () )
241+ payload := newPayload (empty .block , empty .requests , empty .witness , payloadID )
234242
235243 // Spin up a routine for updating the payload in background. This strategy
236244 // can maximum the revenue for including transactions with highest fee.
237245 go func () {
238- bCtx , bSpan , bSpanEnd := telemetry .StartSpan (ctx , "miner.background" )
239- defer bSpanEnd (nil )
246+ var iteration int
247+
248+ bCtx , bSpan , bSpanEnd := telemetry .StartSpan (ctx , "miner.background" ,
249+ telemetry .StringAttribute ("payload.id" , payloadID .String ()),
250+ )
251+ defer func () {
252+ bSpan .SetAttributes (telemetry .Int64Attribute ("iterations.total" , int64 (iteration )))
253+ bSpanEnd (nil )
254+ }()
240255
241256 // Setup the timer for re-building the payload. The initial clock is kept
242257 // for triggering process immediately.
@@ -258,23 +273,31 @@ func (miner *Miner) buildPayload(ctx context.Context, args *BuildPayloadArgs, wi
258273 beaconRoot : args .BeaconRoot ,
259274 noTxs : false ,
260275 }
261-
262276 for {
263277 select {
264278 case <- timer .C :
265- _ , _ , iterSpanEnd := telemetry .StartSpan (bCtx , "miner.generateWork" )
279+ iteration ++
280+ iterCtx , iterSpan , iterSpanEnd := telemetry .StartSpan (bCtx , "miner.buildIteration" ,
281+ telemetry .Int64Attribute ("iteration" , int64 (iteration )),
282+ )
266283 start := time .Now ()
267-
268- r := miner .generateWork (fullParams , witness )
284+ r := miner .generateWork (iterCtx , fullParams , witness )
269285 if r .err == nil {
270- payload .update (r , time .Since (start ))
286+ accepted := payload .update (r , time .Since (start ))
287+ iterSpan .SetAttributes (telemetry .BoolAttribute ("update.accepted" , accepted ))
271288 } else {
272289 log .Info ("Error while generating work" , "id" , payload .id , "err" , r .err )
273290 }
274- timer .Reset (miner .config .Recommit )
275291 iterSpanEnd (r .err )
292+ timer .Reset (miner .config .Recommit )
276293 case <- payload .stop :
277- bSpan .SetAttributes (telemetry .StringAttribute ("exit.reason" , "delivery" ))
294+ payload .lock .Lock ()
295+ emptyDelivered := payload .full == nil
296+ payload .lock .Unlock ()
297+ bSpan .SetAttributes (
298+ telemetry .StringAttribute ("exit.reason" , "delivery" ),
299+ telemetry .BoolAttribute ("empty.delivered" , emptyDelivered ),
300+ )
278301 log .Info ("Stopping work on payload" , "id" , payload .id , "reason" , "delivery" )
279302 return
280303 case <- endTimer .C :
0 commit comments