Skip to content

Commit 60ec41c

Browse files
miner: refactor getSealingBlock method (#27993)
1 parent feb8f41 commit 60ec41c

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

miner/payload_building.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,20 @@ func (w *worker) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
175175
// Build the initial version with no transaction included. It should be fast
176176
// enough to run. The empty payload can at least make sure there is something
177177
// to deliver for not missing slot.
178-
empty := w.getSealingBlock(args.Parent, args.Timestamp, args.FeeRecipient, args.Random, args.Withdrawals, true)
178+
emptyParams := &generateParams{
179+
timestamp: args.Timestamp,
180+
forceTime: true,
181+
parentHash: args.Parent,
182+
coinbase: args.FeeRecipient,
183+
random: args.Random,
184+
withdrawals: args.Withdrawals,
185+
noTxs: true,
186+
}
187+
empty := w.getSealingBlock(emptyParams)
179188
if empty.err != nil {
180189
return nil, empty.err
181190
}
191+
182192
// Construct a payload object for return.
183193
payload := newPayload(empty.block, args.Id())
184194

@@ -195,11 +205,21 @@ func (w *worker) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
195205
// by the timestamp parameter.
196206
endTimer := time.NewTimer(time.Second * 12)
197207

208+
fullParams := &generateParams{
209+
timestamp: args.Timestamp,
210+
forceTime: true,
211+
parentHash: args.Parent,
212+
coinbase: args.FeeRecipient,
213+
random: args.Random,
214+
withdrawals: args.Withdrawals,
215+
noTxs: false,
216+
}
217+
198218
for {
199219
select {
200220
case <-timer.C:
201221
start := time.Now()
202-
r := w.getSealingBlock(args.Parent, args.Timestamp, args.FeeRecipient, args.Random, args.Withdrawals, false)
222+
r := w.getSealingBlock(fullParams)
203223
if r.err == nil {
204224
payload.update(r, time.Since(start))
205225
}

miner/worker.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,17 +1106,9 @@ func (w *worker) commit(env *environment, interval func(), update bool, start ti
11061106
// getSealingBlock generates the sealing block based on the given parameters.
11071107
// The generation result will be passed back via the given channel no matter
11081108
// the generation itself succeeds or not.
1109-
func (w *worker) getSealingBlock(parent common.Hash, timestamp uint64, coinbase common.Address, random common.Hash, withdrawals types.Withdrawals, noTxs bool) *newPayloadResult {
1109+
func (w *worker) getSealingBlock(params *generateParams) *newPayloadResult {
11101110
req := &getWorkReq{
1111-
params: &generateParams{
1112-
timestamp: timestamp,
1113-
forceTime: true,
1114-
parentHash: parent,
1115-
coinbase: coinbase,
1116-
random: random,
1117-
withdrawals: withdrawals,
1118-
noTxs: noTxs,
1119-
},
1111+
params: params,
11201112
result: make(chan *newPayloadResult, 1),
11211113
}
11221114
select {

miner/worker_test.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,15 @@ func testGetSealingWork(t *testing.T, chainConfig *params.ChainConfig, engine co
452452

453453
// This API should work even when the automatic sealing is not enabled
454454
for _, c := range cases {
455-
r := w.getSealingBlock(c.parent, timestamp, c.coinbase, c.random, nil, false)
455+
r := w.getSealingBlock(&generateParams{
456+
parentHash: c.parent,
457+
timestamp: timestamp,
458+
coinbase: c.coinbase,
459+
random: c.random,
460+
withdrawals: nil,
461+
noTxs: false,
462+
forceTime: true,
463+
})
456464
if c.expectErr {
457465
if r.err == nil {
458466
t.Error("Expect error but get nil")
@@ -468,7 +476,15 @@ func testGetSealingWork(t *testing.T, chainConfig *params.ChainConfig, engine co
468476
// This API should work even when the automatic sealing is enabled
469477
w.start()
470478
for _, c := range cases {
471-
r := w.getSealingBlock(c.parent, timestamp, c.coinbase, c.random, nil, false)
479+
r := w.getSealingBlock(&generateParams{
480+
parentHash: c.parent,
481+
timestamp: timestamp,
482+
coinbase: c.coinbase,
483+
random: c.random,
484+
withdrawals: nil,
485+
noTxs: false,
486+
forceTime: true,
487+
})
472488
if c.expectErr {
473489
if r.err == nil {
474490
t.Error("Expect error but get nil")

0 commit comments

Comments
 (0)