Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,14 @@ type Config struct {

// DefaultConfig contains default settings for miner.
var DefaultConfig = Config{
GasCeil: 30000000,
GasPrice: big.NewInt(params.GWei),
Recommit: 3 * time.Second,
GasCeil: 30000000,
GasPrice: big.NewInt(params.GWei),

// 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,
}

Expand Down
20 changes: 13 additions & 7 deletions miner/payload_building.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/beacon"
"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.
Expand All @@ -46,23 +48,22 @@ type Payload struct {
full *types.Block
fullFees *big.Int
stop chan struct{}
lock *sync.Mutex
lock sync.Mutex
cond *sync.Cond
}

// newPayload initializes the payload object.
func newPayload(empty *types.Block) *Payload {
lock := new(sync.Mutex)
return &Payload{
payload := &Payload{
empty: empty,
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.
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()
defer payload.lock.Unlock()

Expand All @@ -77,6 +78,10 @@ func (payload *Payload) update(block *types.Block, fees *big.Int) {
if payload.full == nil || fees.Cmp(payload.fullFees) > 0 {
payload.full = block
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
}
Expand Down Expand Up @@ -152,9 +157,10 @@ func (w *worker) buildPayload(args *BuildPayloadArgs) (*Payload, error) {
for {
select {
case <-timer.C:
start := time.Now()
block, fees, err := w.getSealingBlock(args.Parent, args.Timestamp, args.FeeRecipient, args.Random, false)
if err == nil {
payload.update(block, fees)
payload.update(block, fees, time.Since(start))
}
timer.Reset(w.recommit)
case <-payload.stop:
Expand Down
2 changes: 1 addition & 1 deletion miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@ func (w *worker) commit(env *environment, interval func(), update bool, start ti
w.unconfirmed.Shift(block.NumberU64() - 1)

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()),
"uncles", len(env.uncles), "txs", env.tcount,
"gas", block.GasUsed(), "fees", feesInEther,
Expand Down