mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
removed for loop from buildPayload
This commit is contained in:
parent
100f133d49
commit
23275e0934
1 changed files with 12 additions and 30 deletions
|
|
@ -21,7 +21,6 @@ import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"math/big"
|
"math/big"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/beacon/engine"
|
"github.com/ethereum/go-ethereum/beacon/engine"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
|
@ -84,7 +83,7 @@ func newPayload(empty *types.Block, id engine.PayloadID) *Payload {
|
||||||
}
|
}
|
||||||
|
|
||||||
// update updates the full-block with latest built version.
|
// update updates the full-block with latest built version.
|
||||||
func (payload *Payload) update(block *types.Block, fees *big.Int, elapsed time.Duration) {
|
func (payload *Payload) update(block *types.Block, fees *big.Int) {
|
||||||
payload.lock.Lock()
|
payload.lock.Lock()
|
||||||
defer payload.lock.Unlock()
|
defer payload.lock.Unlock()
|
||||||
|
|
||||||
|
|
@ -103,7 +102,7 @@ func (payload *Payload) update(block *types.Block, fees *big.Int, elapsed time.D
|
||||||
feesInEther := new(big.Float).Quo(new(big.Float).SetInt(fees), big.NewFloat(params.Ether))
|
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(),
|
log.Info("Updated payload", "id", payload.id, "number", block.NumberU64(), "hash", block.Hash(),
|
||||||
"txs", len(block.Transactions()), "gas", block.GasUsed(), "fees", feesInEther,
|
"txs", len(block.Transactions()), "gas", block.GasUsed(), "fees", feesInEther,
|
||||||
"root", block.Root(), "elapsed", common.PrettyDuration(elapsed))
|
"root", block.Root())
|
||||||
}
|
}
|
||||||
payload.cond.Broadcast() // fire signal for notifying full block
|
payload.cond.Broadcast() // fire signal for notifying full block
|
||||||
}
|
}
|
||||||
|
|
@ -160,34 +159,17 @@ func (w *worker) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Construct a payload object for return.
|
// Construct a payload object for updating the block.
|
||||||
payload := newPayload(empty, args.Id())
|
payload := newPayload(empty, args.Id())
|
||||||
|
|
||||||
// Setup the timer for re-building the payload. The initial clock is kept
|
// Get the block to update with the payload
|
||||||
// for triggering process immediately.
|
block, fees, err := w.getSealingBlock(args.Parent, args.Timestamp, args.FeeRecipient, args.Random, args.Withdrawals, false)
|
||||||
timer := time.NewTimer(0)
|
if err == nil {
|
||||||
defer timer.Stop()
|
payload.update(block, fees)
|
||||||
|
log.Info("Stopping work on payload", "id", payload.id, "reason", "delivery")
|
||||||
// Setup the timer for terminating the process if payload building exceeds 5 seconds.
|
return payload, nil
|
||||||
// This should be much longer than normal payload building should take.
|
} else {
|
||||||
endTimer := time.NewTimer(time.Second * 5)
|
log.Info("Stopping work on payload", "id", payload.id, "reason", "failed to retrieve payload")
|
||||||
|
return payload, nil
|
||||||
// TODO: figure out if timeout case can be removed
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-timer.C:
|
|
||||||
start := time.Now()
|
|
||||||
block, fees, err := w.getSealingBlock(args.Parent, args.Timestamp, args.FeeRecipient, args.Random, args.Withdrawals, false)
|
|
||||||
if err == nil {
|
|
||||||
payload.update(block, fees, time.Since(start))
|
|
||||||
}
|
|
||||||
timer.Reset(w.recommit)
|
|
||||||
case <-payload.stop:
|
|
||||||
log.Info("Stopping work on payload", "id", payload.id, "reason", "delivery")
|
|
||||||
return payload, nil
|
|
||||||
case <-endTimer.C:
|
|
||||||
log.Info("Stopping work on payload", "id", payload.id, "reason", "timeout")
|
|
||||||
return payload, nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue