mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
miner: return newPayloadResult from getSealingBlock
This commit is contained in:
parent
cea826c243
commit
f1a8cc2f28
3 changed files with 37 additions and 33 deletions
|
|
@ -85,7 +85,7 @@ func newPayload(empty *types.Block, id engine.PayloadID) *Payload {
|
|||
}
|
||||
|
||||
// update updates the full-block with latest built version.
|
||||
func (payload *Payload) update(block *types.Block, fees *big.Int, sidecars []*types.BlobTxSidecar, elapsed time.Duration) {
|
||||
func (payload *Payload) update(r *newPayloadResult, elapsed time.Duration) {
|
||||
payload.lock.Lock()
|
||||
defer payload.lock.Unlock()
|
||||
|
||||
|
|
@ -97,15 +97,23 @@ func (payload *Payload) update(block *types.Block, fees *big.Int, sidecars []*ty
|
|||
// Ensure the newly provided full block has a higher transaction fee.
|
||||
// In post-merge stage, there is no uncle reward anymore and transaction
|
||||
// fee(apart from the mev revenue) is the only indicator for comparison.
|
||||
if payload.full == nil || fees.Cmp(payload.fullFees) > 0 {
|
||||
payload.full = block
|
||||
payload.fullFees = fees
|
||||
payload.sidecars = sidecars
|
||||
if payload.full == nil || r.fees.Cmp(payload.fullFees) > 0 {
|
||||
payload.full = r.block
|
||||
payload.fullFees = r.fees
|
||||
payload.sidecars = r.sidecars
|
||||
|
||||
feesInEther := new(big.Float).Quo(new(big.Float).SetInt(fees), big.NewFloat(params.Ether))
|
||||
log.Info("Updated payload", "id", payload.id, "number", block.NumberU64(), "hash", block.Hash(),
|
||||
"txs", len(block.Transactions()), "withdrawals", len(block.Withdrawals()), "gas", block.GasUsed(),
|
||||
"fees", feesInEther, "root", block.Root(), "elapsed", common.PrettyDuration(elapsed))
|
||||
feesInEther := new(big.Float).Quo(new(big.Float).SetInt(r.fees), big.NewFloat(params.Ether))
|
||||
log.Info("Updated payload",
|
||||
"id", payload.id,
|
||||
"number", r.block.NumberU64(),
|
||||
"hash", r.block.Hash(),
|
||||
"txs", len(r.block.Transactions()),
|
||||
"withdrawals", len(r.block.Withdrawals()),
|
||||
"gas", r.block.GasUsed(),
|
||||
"fees", feesInEther,
|
||||
"root", r.block.Root(),
|
||||
"elapsed", common.PrettyDuration(elapsed),
|
||||
)
|
||||
}
|
||||
payload.cond.Broadcast() // fire signal for notifying full block
|
||||
}
|
||||
|
|
@ -167,12 +175,12 @@ 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.
|
||||
empty, _, _, err := w.getSealingBlock(args.Parent, args.Timestamp, args.FeeRecipient, args.Random, args.Withdrawals, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
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, args.Id())
|
||||
payload := newPayload(empty.block, args.Id())
|
||||
|
||||
// Spin up a routine for updating the payload in background. This strategy
|
||||
// can maximum the revenue for including transactions with highest fee.
|
||||
|
|
@ -191,9 +199,9 @@ func (w *worker) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
|
|||
select {
|
||||
case <-timer.C:
|
||||
start := time.Now()
|
||||
block, fees, sidecars, err := w.getSealingBlock(args.Parent, args.Timestamp, args.FeeRecipient, args.Random, args.Withdrawals, false)
|
||||
if err == nil {
|
||||
payload.update(block, fees, sidecars, time.Since(start))
|
||||
r := w.getSealingBlock(args.Parent, args.Timestamp, args.FeeRecipient, args.Random, args.Withdrawals, false)
|
||||
if r.err == nil {
|
||||
payload.update(r, time.Since(start))
|
||||
}
|
||||
timer.Reset(w.recommit)
|
||||
case <-payload.stop:
|
||||
|
|
|
|||
|
|
@ -1106,7 +1106,7 @@ 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(parent common.Hash, timestamp uint64, coinbase common.Address, random common.Hash, withdrawals types.Withdrawals, noTxs bool) (*types.Block, *big.Int, []*types.BlobTxSidecar, error) {
|
||||
func (w *worker) getSealingBlock(parent common.Hash, timestamp uint64, coinbase common.Address, random common.Hash, withdrawals types.Withdrawals, noTxs bool) *newPayloadResult {
|
||||
req := &getWorkReq{
|
||||
params: &generateParams{
|
||||
timestamp: timestamp,
|
||||
|
|
@ -1121,13 +1121,9 @@ func (w *worker) getSealingBlock(parent common.Hash, timestamp uint64, coinbase
|
|||
}
|
||||
select {
|
||||
case w.getWorkCh <- req:
|
||||
result := <-req.result
|
||||
if result.err != nil {
|
||||
return nil, nil, nil, result.err
|
||||
}
|
||||
return result.block, result.fees, result.sidecars, nil
|
||||
return <-req.result
|
||||
case <-w.exitCh:
|
||||
return nil, nil, nil, errors.New("miner closed")
|
||||
return &newPayloadResult{err: errors.New("miner closed")}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -452,32 +452,32 @@ 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 {
|
||||
block, _, _, err := w.getSealingBlock(c.parent, timestamp, c.coinbase, c.random, nil, false)
|
||||
r := w.getSealingBlock(c.parent, timestamp, c.coinbase, c.random, nil, false)
|
||||
if c.expectErr {
|
||||
if err == nil {
|
||||
if r.err == nil {
|
||||
t.Error("Expect error but get nil")
|
||||
}
|
||||
} else {
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error %v", err)
|
||||
if r.err != nil {
|
||||
t.Errorf("Unexpected error %v", r.err)
|
||||
}
|
||||
assertBlock(block, c.expectNumber, c.coinbase, c.random)
|
||||
assertBlock(r.block, c.expectNumber, c.coinbase, c.random)
|
||||
}
|
||||
}
|
||||
|
||||
// This API should work even when the automatic sealing is enabled
|
||||
w.start()
|
||||
for _, c := range cases {
|
||||
block, _, _, err := w.getSealingBlock(c.parent, timestamp, c.coinbase, c.random, nil, false)
|
||||
r := w.getSealingBlock(c.parent, timestamp, c.coinbase, c.random, nil, false)
|
||||
if c.expectErr {
|
||||
if err == nil {
|
||||
if r.err == nil {
|
||||
t.Error("Expect error but get nil")
|
||||
}
|
||||
} else {
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error %v", err)
|
||||
if r.err != nil {
|
||||
t.Errorf("Unexpected error %v", r.err)
|
||||
}
|
||||
assertBlock(block, c.expectNumber, c.coinbase, c.random)
|
||||
assertBlock(r.block, c.expectNumber, c.coinbase, c.random)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue