Skip to content
Closed
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
2 changes: 2 additions & 0 deletions cmd/devp2p/internal/ethtest/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/ethereum/go-ethereum/eth/catalyst"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/internal/utesting"
"github.com/ethereum/go-ethereum/miner/minerconfig"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p"
)
Expand Down Expand Up @@ -143,6 +144,7 @@ func setupGeth(stack *node.Node, dir string) error {
TrieTimeout: 60 * time.Minute,
SnapshotCache: 10,
TriesInMemory: 128,
Miner: &minerconfig.Config{},
})
if err != nil {
return err
Expand Down
5 changes: 4 additions & 1 deletion cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ func loadBaseConfig(ctx *cli.Context) gethConfig {
if err := loadConfig(file, &cfg); err != nil {
utils.Fatalf("%v", err)
}
// some default options could be overwritten after `loadConfig()`
// apply the default value if the options are not specified in config.toml file.
ethconfig.ApplyDefaultEthConfig(&cfg.Eth)
}

scheme := cfg.Eth.StateScheme
Expand Down Expand Up @@ -276,7 +279,7 @@ func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend) {
git, _ := version.VCS()
utils.SetupMetrics(&cfg.Metrics,
utils.EnableBuildInfo(git.Commit, git.Date),
utils.EnableMinerInfo(ctx, &cfg.Eth.Miner),
utils.EnableMinerInfo(ctx, cfg.Eth.Miner),
utils.EnableNodeInfo(&cfg.Eth.TxPool, stack.Server().NodeInfo()),
utils.EnableNodeTrack(ctx, &cfg.Eth, stack),
)
Expand Down
15 changes: 9 additions & 6 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,13 +641,13 @@ var (
MinerRecommitIntervalFlag = &cli.DurationFlag{
Name: "miner.recommit",
Usage: "Time interval to recreate the block being mined",
Value: ethconfig.Defaults.Miner.Recommit,
Value: *ethconfig.Defaults.Miner.Recommit,
Category: flags.MinerCategory,
}
MinerDelayLeftoverFlag = &cli.DurationFlag{
Name: "miner.delayleftover",
Usage: "Time reserved to finalize a block",
Value: ethconfig.Defaults.Miner.DelayLeftOver,
Value: *ethconfig.Defaults.Miner.DelayLeftOver,
Category: flags.MinerCategory,
}

Expand Down Expand Up @@ -1862,17 +1862,20 @@ func setMiner(ctx *cli.Context, cfg *minerconfig.Config) {
cfg.GasPrice = flags.GlobalBig(ctx, MinerGasPriceFlag.Name)
}
if ctx.IsSet(MinerRecommitIntervalFlag.Name) {
cfg.Recommit = ctx.Duration(MinerRecommitIntervalFlag.Name)
recommit := ctx.Duration(MinerRecommitIntervalFlag.Name)
cfg.Recommit = &recommit
}
if ctx.IsSet(MinerDelayLeftoverFlag.Name) {
cfg.DelayLeftOver = ctx.Duration(MinerDelayLeftoverFlag.Name)
delayLeftOver := ctx.Duration(MinerDelayLeftoverFlag.Name)
cfg.DelayLeftOver = &delayLeftOver
}
if ctx.Bool(VotingEnabledFlag.Name) {
cfg.VoteEnable = true
}
if ctx.IsSet(MinerNewPayloadTimeoutFlag.Name) {
log.Warn("The flag --miner.newpayload-timeout is deprecated and will be removed, please use --miner.recommit")
cfg.Recommit = ctx.Duration(MinerNewPayloadTimeoutFlag.Name)
recommit := ctx.Duration(MinerNewPayloadTimeoutFlag.Name)
cfg.Recommit = &recommit
}
if ctx.Bool(DisableVoteAttestationFlag.Name) {
cfg.DisableVoteAttestation = true
Expand Down Expand Up @@ -1959,7 +1962,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
setGPO(ctx, &cfg.GPO)
setTxPool(ctx, &cfg.TxPool)
setBlobPool(ctx, &cfg.BlobPool)
setMiner(ctx, &cfg.Miner)
setMiner(ctx, cfg.Miner)
setRequiredBlocks(ctx, cfg)
setLes(ctx, cfg)

Expand Down
2 changes: 1 addition & 1 deletion cmd/utils/flags_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ var (
MinerNewPayloadTimeoutFlag = &cli.DurationFlag{
Name: "miner.newpayload-timeout",
Usage: "Specify the maximum time allowance for creating a new payload (deprecated)",
Value: ethconfig.Defaults.Miner.Recommit,
Value: *ethconfig.Defaults.Miner.Recommit,
Category: flags.DeprecatedCategory,
}
MetricsEnabledExpensiveFlag = &cli.BoolFlag{
Expand Down
2 changes: 1 addition & 1 deletion console/console_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func newTester(t *testing.T, confOverride func(*ethconfig.Config)) *tester {
}
ethConf := &ethconfig.Config{
Genesis: core.DeveloperGenesisBlock(11_500_000, nil),
Miner: minerconfig.Config{
Miner: &minerconfig.Config{
Etherbase: common.HexToAddress(testAddress),
},
}
Expand Down
2 changes: 1 addition & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
return nil, err
}

eth.miner = miner.New(eth, &config.Miner, eth.EventMux(), eth.engine)
eth.miner = miner.New(eth, config.Miner, eth.EventMux(), eth.engine)
eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))
eth.miner.SetPrioAddresses(config.TxPool.Locals)

Expand Down
2 changes: 1 addition & 1 deletion eth/catalyst/simulated_beacon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func startSimulatedBeaconEthService(t *testing.T, genesis *core.Genesis, period
t.Fatal("can't create node:", err)
}

ethcfg := &ethconfig.Config{Genesis: genesis, SyncMode: ethconfig.FullSync, TrieTimeout: time.Minute, TrieDirtyCache: 256, TrieCleanCache: 256, Miner: minerconfig.DefaultConfig}
ethcfg := &ethconfig.Config{Genesis: genesis, SyncMode: ethconfig.FullSync, TrieTimeout: time.Minute, TrieDirtyCache: 256, TrieCleanCache: 256, Miner: &minerconfig.DefaultConfig}
ethservice, err := eth.New(n, ethcfg)
if err != nil {
t.Fatal("can't create eth service:", err)
Expand Down
14 changes: 12 additions & 2 deletions eth/ethconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var Defaults = Config{
SnapshotCache: 102,
DiffBlock: uint64(86400),
FilterLogCacheSize: 32,
Miner: minerconfig.DefaultConfig,
Miner: &minerconfig.DefaultConfig,
TxPool: legacypool.DefaultConfig,
BlobPool: blobpool.DefaultConfig,
RPCGasCap: 50000000,
Expand Down Expand Up @@ -156,7 +156,7 @@ type Config struct {
FilterLogCacheSize int

// Mining options
Miner minerconfig.Config
Miner *minerconfig.Config

// Transaction pool options
TxPool legacypool.Config
Expand Down Expand Up @@ -215,3 +215,13 @@ func CreateConsensusEngine(config *params.ChainConfig, db ethdb.Database, ee *et
}
return beacon.New(ethash.NewFaker()), nil
}

func ApplyDefaultEthConfig(cfg *Config) {
if cfg == nil {
// [Eth] is a mandatory option in config.toml, it should never be nil
log.Error("ApplyDefaultEthConfig cfg should not be nil")
return
}

cfg.Miner = cfg.Miner.ApplyDefaultMinerConfig()
}
4 changes: 2 additions & 2 deletions eth/ethconfig/gen_config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion ethclient/ethclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/miner/minerconfig"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
Expand Down Expand Up @@ -195,7 +196,7 @@ func newTestBackend(config *node.Config) (*node.Node, []*types.Block, error) {
return nil, nil, fmt.Errorf("can't create new node: %v", err)
}
// Create Ethereum Service
ecfg := &ethconfig.Config{Genesis: genesis, RPCGasCap: 1000000}
ecfg := &ethconfig.Config{Genesis: genesis, RPCGasCap: 1000000, Miner: &minerconfig.Config{}}
ecfg.SnapshotCache = 256
ecfg.TriesInMemory = 128
ethservice, err := eth.New(n, ecfg)
Expand Down
3 changes: 2 additions & 1 deletion ethclient/gethclient/gethclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/eth/filters"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/miner/minerconfig"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
Expand All @@ -58,7 +59,7 @@ func newTestBackend(t *testing.T) (*node.Node, []*types.Block) {
t.Fatalf("can't create new node: %v", err)
}
// Create Ethereum Service
config := &ethconfig.Config{Genesis: genesis, RPCGasCap: 1000000}
config := &ethconfig.Config{Genesis: genesis, RPCGasCap: 1000000, Miner: &minerconfig.Config{}}
ethservice, err := eth.New(n, config)
if err != nil {
t.Fatalf("can't create new ethereum service: %v", err)
Expand Down
2 changes: 2 additions & 0 deletions graphql/graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/eth/filters"
"github.com/ethereum/go-ethereum/miner/minerconfig"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/params"

Expand Down Expand Up @@ -455,6 +456,7 @@ func newGQLService(t *testing.T, stack *node.Node, shanghai bool, gspec *core.Ge
SnapshotCache: 5,
RPCGasCap: 1000000,
StateScheme: rawdb.HashScheme,
Miner: &minerconfig.Config{},
}
var engine consensus.Engine = ethash.NewFaker()
if shanghai {
Expand Down
15 changes: 8 additions & 7 deletions miner/bid_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func (b *bidSimulator) canBeInterrupted(targetTime uint64) bool {
return true
}
left := time.Until(time.UnixMilli(int64(targetTime)))
return left >= b.config.NoInterruptLeftOver
return left >= *b.config.NoInterruptLeftOver
}

func (b *bidSimulator) newBidLoop() {
Expand Down Expand Up @@ -396,7 +396,7 @@ func (b *bidSimulator) newBidLoop() {
continue
}

bidRuntime, err := newBidRuntime(newBid.bid, b.config.ValidatorCommission)
bidRuntime, err := newBidRuntime(newBid.bid, *b.config.ValidatorCommission)
if err != nil {
if newBid.feedback != nil {
newBid.feedback <- err
Expand All @@ -408,7 +408,7 @@ func (b *bidSimulator) newBidLoop() {
toCommit := true
bestBidToRun := b.GetBestBidToRun(newBid.bid.ParentHash)
if bestBidToRun != nil {
bestBidRuntime, _ := newBidRuntime(bestBidToRun, b.config.ValidatorCommission)
bestBidRuntime, _ := newBidRuntime(bestBidToRun, *b.config.ValidatorCommission)
if bidRuntime.isExpectedBetterThan(bestBidRuntime) {
// new bid has better expectedBlockReward, use bidRuntime
log.Debug("new bid has better expectedBlockReward",
Expand Down Expand Up @@ -494,7 +494,7 @@ func (b *bidSimulator) getBlockInterval(parentHeader *types.Header) uint64 {

func (b *bidSimulator) bidBetterBefore(parentHash common.Hash) time.Time {
parentHeader := b.chain.GetHeaderByHash(parentHash)
return bidutil.BidBetterBefore(parentHeader, b.getBlockInterval(parentHeader), b.delayLeftOver, b.config.BidSimulationLeftOver)
return bidutil.BidBetterBefore(parentHeader, b.getBlockInterval(parentHeader), b.delayLeftOver, *b.config.BidSimulationLeftOver)
}

func (b *bidSimulator) clearLoop() {
Expand Down Expand Up @@ -739,7 +739,7 @@ func (b *bidSimulator) simBid(interruptCh chan int32, bidRuntime *BidRuntime) {

// check if bid reward is valid
{
bidRuntime.packReward(b.config.ValidatorCommission)
bidRuntime.packReward(*b.config.ValidatorCommission)
if !bidRuntime.validReward() {
err = errors.New("reward does not achieve the expectation")
return
Expand Down Expand Up @@ -786,7 +786,7 @@ func (b *bidSimulator) simBid(interruptCh chan int32, bidRuntime *BidRuntime) {
}

// if enable greedy merge, fill bid env with transactions from mempool
if b.config.GreedyMergeTx {
if *b.config.GreedyMergeTx {
endingBidsExtra := 20 * time.Millisecond // Add a buffer to ensure ending bids before `delayLeftOver`
minTimeLeftForEndingBids := b.delayLeftOver + endingBidsExtra
delay := b.engine.Delay(b.chain, bidRuntime.env.header, &minTimeLeftForEndingBids)
Expand All @@ -802,7 +802,7 @@ func (b *bidSimulator) simBid(interruptCh chan int32, bidRuntime *BidRuntime) {
"builder", bidRuntime.bid.Builder, "tx count", bidRuntime.env.tcount-bidTxLen+1, "err", fillErr)

// recalculate the packed reward
bidRuntime.packReward(b.config.ValidatorCommission)
bidRuntime.packReward(*b.config.ValidatorCommission)
}
}

Expand Down Expand Up @@ -838,6 +838,7 @@ func (b *bidSimulator) simBid(interruptCh chan int32, bidRuntime *BidRuntime) {
}

if bidRuntime.bid.Hash() != bestBid.bid.Hash() {
// will stop recommit..., the bestBidToRun will be cleaned.
log.Info("[BID RESULT]",
"win", bidRuntime.packedBlockReward.Cmp(bestBid.packedBlockReward) >= 0,

Expand Down
18 changes: 17 additions & 1 deletion miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,24 @@ func New(eth Backend, config *minerconfig.Config, mux *event.TypeMux, engine con
stopCh: make(chan struct{}),
worker: newWorker(config, engine, eth, mux, false),
}
mev := config.Mev
if mev == nil {
// for unit test, it could be nil, as it is not initialized
mev = &minerconfig.MevConfig{}
}

delayLeftOver := config.DelayLeftOver
if delayLeftOver == nil {
// for unit test, it could be nil, as it is not initialized
delayLeftOver = new(time.Duration)
}
gasPrice := config.GasPrice
if gasPrice == nil {
// for unit test, it could be nil, as it is not initialized
gasPrice = new(big.Int)
}

miner.bidSimulator = newBidSimulator(&config.Mev, config.DelayLeftOver, config.GasPrice, eth, eth.BlockChain().Config(), engine, miner.worker)
miner.bidSimulator = newBidSimulator(mev, *delayLeftOver, gasPrice, eth, eth.BlockChain().Config(), engine, miner.worker)
miner.worker.setBestBidFetcher(miner.bidSimulator)

miner.wg.Add(1)
Expand Down
6 changes: 3 additions & 3 deletions miner/miner_mev.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ func (miner *Miner) MevParams() *types.MevParams {
}

return &types.MevParams{
ValidatorCommission: miner.worker.config.Mev.ValidatorCommission,
BidSimulationLeftOver: miner.worker.config.Mev.BidSimulationLeftOver,
NoInterruptLeftOver: miner.worker.config.Mev.NoInterruptLeftOver,
ValidatorCommission: *miner.worker.config.Mev.ValidatorCommission,
BidSimulationLeftOver: *miner.worker.config.Mev.BidSimulationLeftOver,
NoInterruptLeftOver: *miner.worker.config.Mev.NoInterruptLeftOver,
GasCeil: miner.worker.config.GasCeil,
GasPrice: miner.worker.config.GasPrice,
BuilderFeeCeil: builderFeeCeil,
Expand Down
1 change: 1 addition & 0 deletions miner/miner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ func createMiner(t *testing.T) (*Miner, *event.TypeMux, func(skipMiner bool)) {
// Create Ethash config
config := minerconfig.Config{
Etherbase: common.HexToAddress("123456789"),
Recommit: new(time.Duration),
}
// Create chainConfig
chainDB := rawdb.NewMemoryDatabase()
Expand Down
Loading