Skip to content

Commit

Permalink
Revert "miner: refactor getSealingBlock method (ethereum#27993)"
Browse files Browse the repository at this point in the history
This reverts commit 4c1fe06.
  • Loading branch information
devopsbo3 committed Nov 10, 2023
1 parent 73c4545 commit 66462eb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 42 deletions.
24 changes: 2 additions & 22 deletions miner/payload_building.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,10 @@ func (w *worker) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
// Build the initial version with no transaction included. It should be fast
// enough to run. The empty payload can at least make sure there is something
// to deliver for not missing slot.
emptyParams := &generateParams{
timestamp: args.Timestamp,
forceTime: true,
parentHash: args.Parent,
coinbase: args.FeeRecipient,
random: args.Random,
withdrawals: args.Withdrawals,
noTxs: true,
}
empty := w.getSealingBlock(emptyParams)
empty := w.getSealingBlock(args.Parent, args.Timestamp, args.FeeRecipient, args.Random, args.Withdrawals, true)
if empty.err != nil {
return nil, empty.err
}

// Construct a payload object for return.
payload := newPayload(empty.block, args.Id())

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

fullParams := &generateParams{
timestamp: args.Timestamp,
forceTime: true,
parentHash: args.Parent,
coinbase: args.FeeRecipient,
random: args.Random,
withdrawals: args.Withdrawals,
noTxs: false,
}

for {
select {
case <-timer.C:
start := time.Now()
r := w.getSealingBlock(fullParams)
r := w.getSealingBlock(args.Parent, args.Timestamp, args.FeeRecipient, args.Random, args.Withdrawals, false)
if r.err == nil {
payload.update(r, time.Since(start))
}
Expand Down
12 changes: 10 additions & 2 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1106,9 +1106,17 @@ func (w *worker) commit(env *environment, interval func(), update bool, start ti
// getSealingBlock generates the sealing block based on the given parameters.
// The generation result will be passed back via the given channel no matter
// the generation itself succeeds or not.
func (w *worker) getSealingBlock(params *generateParams) *newPayloadResult {
func (w *worker) getSealingBlock(parent common.Hash, timestamp uint64, coinbase common.Address, random common.Hash, withdrawals types.Withdrawals, noTxs bool) *newPayloadResult {
req := &getWorkReq{
params: params,
params: &generateParams{
timestamp: timestamp,
forceTime: true,
parentHash: parent,
coinbase: coinbase,
random: random,
withdrawals: withdrawals,
noTxs: noTxs,
},
result: make(chan *newPayloadResult, 1),
}
select {
Expand Down
20 changes: 2 additions & 18 deletions miner/worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,15 +452,7 @@ func testGetSealingWork(t *testing.T, chainConfig *params.ChainConfig, engine co

// This API should work even when the automatic sealing is not enabled
for _, c := range cases {
r := w.getSealingBlock(&generateParams{
parentHash: c.parent,
timestamp: timestamp,
coinbase: c.coinbase,
random: c.random,
withdrawals: nil,
noTxs: false,
forceTime: true,
})
r := w.getSealingBlock(c.parent, timestamp, c.coinbase, c.random, nil, false)
if c.expectErr {
if r.err == nil {
t.Error("Expect error but get nil")
Expand All @@ -476,15 +468,7 @@ func testGetSealingWork(t *testing.T, chainConfig *params.ChainConfig, engine co
// This API should work even when the automatic sealing is enabled
w.start()
for _, c := range cases {
r := w.getSealingBlock(&generateParams{
parentHash: c.parent,
timestamp: timestamp,
coinbase: c.coinbase,
random: c.random,
withdrawals: nil,
noTxs: false,
forceTime: true,
})
r := w.getSealingBlock(c.parent, timestamp, c.coinbase, c.random, nil, false)
if c.expectErr {
if r.err == nil {
t.Error("Expect error but get nil")
Expand Down

0 comments on commit 66462eb

Please sign in to comment.