Patch for concurrent iterator & others (onto v1.11.6) #386

Closed
roysc wants to merge 1565 commits from v1.11.6-statediff-v5 into master
3 changed files with 22 additions and 11 deletions
Showing only changes of commit 08fb1aade6 - Show all commits

View File

@ -60,9 +60,14 @@ type Config struct {
// DefaultConfig contains default settings for miner. // DefaultConfig contains default settings for miner.
var DefaultConfig = Config{ var DefaultConfig = Config{
GasCeil: 30000000, GasCeil: 30000000,
GasPrice: big.NewInt(params.GWei), GasPrice: big.NewInt(params.GWei),
Recommit: 3 * time.Second,
// The default recommit time is chosen as two seconds since
// consensus-layer usually will wait a half slot of time(6s)
// for payload generation. It should be enough for Geth to
// run 3 rounds.
Recommit: 2 * time.Second,
NewPayloadTimeout: 2 * time.Second, NewPayloadTimeout: 2 * time.Second,
} }

View File

@ -24,6 +24,8 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/beacon" "github.com/ethereum/go-ethereum/core/beacon"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
) )
// BuildPayloadArgs contains the provided parameters for building payload. // BuildPayloadArgs contains the provided parameters for building payload.
@ -46,23 +48,22 @@ type Payload struct {
full *types.Block full *types.Block
fullFees *big.Int fullFees *big.Int
stop chan struct{} stop chan struct{}
lock *sync.Mutex lock sync.Mutex
cond *sync.Cond cond *sync.Cond
} }
// newPayload initializes the payload object. // newPayload initializes the payload object.
func newPayload(empty *types.Block) *Payload { func newPayload(empty *types.Block) *Payload {
lock := new(sync.Mutex) payload := &Payload{
return &Payload{
empty: empty, empty: empty,
stop: make(chan struct{}), stop: make(chan struct{}),
lock: lock,
cond: sync.NewCond(lock),
} }
payload.cond = sync.NewCond(&payload.lock)
return 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) { func (payload *Payload) update(block *types.Block, fees *big.Int, elapsed time.Duration) {
payload.lock.Lock() payload.lock.Lock()
defer payload.lock.Unlock() defer payload.lock.Unlock()
@ -77,6 +78,10 @@ func (payload *Payload) update(block *types.Block, fees *big.Int) {
if payload.full == nil || fees.Cmp(payload.fullFees) > 0 { if payload.full == nil || fees.Cmp(payload.fullFees) > 0 {
payload.full = block payload.full = block
payload.fullFees = fees payload.fullFees = fees
feesInEther := new(big.Float).Quo(new(big.Float).SetInt(fees), big.NewFloat(params.Ether))
log.Info("Updated payload", "number", block.NumberU64(), "hash", block.Hash(),
"txs", len(block.Transactions()), "gas", block.GasUsed(), "fees", feesInEther, "elapsed", common.PrettyDuration(elapsed))
} }
payload.cond.Broadcast() // fire signal for notifying full block payload.cond.Broadcast() // fire signal for notifying full block
} }
@ -152,9 +157,10 @@ func (w *worker) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
for { for {
select { select {
case <-timer.C: case <-timer.C:
start := time.Now()
block, fees, err := w.getSealingBlock(args.Parent, args.Timestamp, args.FeeRecipient, args.Random, false) block, fees, err := w.getSealingBlock(args.Parent, args.Timestamp, args.FeeRecipient, args.Random, false)
if err == nil { if err == nil {
payload.update(block, fees) payload.update(block, fees, time.Since(start))
} }
timer.Reset(w.recommit) timer.Reset(w.recommit)
case <-payload.stop: case <-payload.stop:

View File

@ -1196,7 +1196,7 @@ func (w *worker) commit(env *environment, interval func(), update bool, start ti
w.unconfirmed.Shift(block.NumberU64() - 1) w.unconfirmed.Shift(block.NumberU64() - 1)
fees := totalFees(block, env.receipts) fees := totalFees(block, env.receipts)
feesInEther := new(big.Float).Quo(new(big.Float).SetInt(fees), new(big.Float).SetInt(big.NewInt(params.Ether))) feesInEther := new(big.Float).Quo(new(big.Float).SetInt(fees), big.NewFloat(params.Ether))
log.Info("Commit new sealing work", "number", block.Number(), "sealhash", w.engine.SealHash(block.Header()), log.Info("Commit new sealing work", "number", block.Number(), "sealhash", w.engine.SealHash(block.Header()),
"uncles", len(env.uncles), "txs", env.tcount, "uncles", len(env.uncles), "txs", env.tcount,
"gas", block.GasUsed(), "fees", feesInEther, "gas", block.GasUsed(), "fees", feesInEther,