miner: polish miner configuration (#19480)
* cmd, eth, miner: disable advance sealing if user require * cmd, console, miner, les, eth: wrap the miner config * eth: remove todo * cmd, miner: revert noadvance flag The reason for this is: if the transaction execution is even longer than block time, then this kind of transactions is DoS attack.
This commit is contained in:
parent
d9403690ec
commit
6269e5574c
@ -49,6 +49,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/metrics"
|
"github.com/ethereum/go-ethereum/metrics"
|
||||||
"github.com/ethereum/go-ethereum/metrics/influxdb"
|
"github.com/ethereum/go-ethereum/metrics/influxdb"
|
||||||
|
"github.com/ethereum/go-ethereum/miner"
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
"github.com/ethereum/go-ethereum/p2p/discv5"
|
"github.com/ethereum/go-ethereum/p2p/discv5"
|
||||||
@ -375,27 +376,27 @@ var (
|
|||||||
MinerGasTargetFlag = cli.Uint64Flag{
|
MinerGasTargetFlag = cli.Uint64Flag{
|
||||||
Name: "miner.gastarget",
|
Name: "miner.gastarget",
|
||||||
Usage: "Target gas floor for mined blocks",
|
Usage: "Target gas floor for mined blocks",
|
||||||
Value: eth.DefaultConfig.MinerGasFloor,
|
Value: eth.DefaultConfig.Miner.GasFloor,
|
||||||
}
|
}
|
||||||
MinerLegacyGasTargetFlag = cli.Uint64Flag{
|
MinerLegacyGasTargetFlag = cli.Uint64Flag{
|
||||||
Name: "targetgaslimit",
|
Name: "targetgaslimit",
|
||||||
Usage: "Target gas floor for mined blocks (deprecated, use --miner.gastarget)",
|
Usage: "Target gas floor for mined blocks (deprecated, use --miner.gastarget)",
|
||||||
Value: eth.DefaultConfig.MinerGasFloor,
|
Value: eth.DefaultConfig.Miner.GasFloor,
|
||||||
}
|
}
|
||||||
MinerGasLimitFlag = cli.Uint64Flag{
|
MinerGasLimitFlag = cli.Uint64Flag{
|
||||||
Name: "miner.gaslimit",
|
Name: "miner.gaslimit",
|
||||||
Usage: "Target gas ceiling for mined blocks",
|
Usage: "Target gas ceiling for mined blocks",
|
||||||
Value: eth.DefaultConfig.MinerGasCeil,
|
Value: eth.DefaultConfig.Miner.GasCeil,
|
||||||
}
|
}
|
||||||
MinerGasPriceFlag = BigFlag{
|
MinerGasPriceFlag = BigFlag{
|
||||||
Name: "miner.gasprice",
|
Name: "miner.gasprice",
|
||||||
Usage: "Minimum gas price for mining a transaction",
|
Usage: "Minimum gas price for mining a transaction",
|
||||||
Value: eth.DefaultConfig.MinerGasPrice,
|
Value: eth.DefaultConfig.Miner.GasPrice,
|
||||||
}
|
}
|
||||||
MinerLegacyGasPriceFlag = BigFlag{
|
MinerLegacyGasPriceFlag = BigFlag{
|
||||||
Name: "gasprice",
|
Name: "gasprice",
|
||||||
Usage: "Minimum gas price for mining a transaction (deprecated, use --miner.gasprice)",
|
Usage: "Minimum gas price for mining a transaction (deprecated, use --miner.gasprice)",
|
||||||
Value: eth.DefaultConfig.MinerGasPrice,
|
Value: eth.DefaultConfig.Miner.GasPrice,
|
||||||
}
|
}
|
||||||
MinerEtherbaseFlag = cli.StringFlag{
|
MinerEtherbaseFlag = cli.StringFlag{
|
||||||
Name: "miner.etherbase",
|
Name: "miner.etherbase",
|
||||||
@ -418,7 +419,7 @@ var (
|
|||||||
MinerRecommitIntervalFlag = cli.DurationFlag{
|
MinerRecommitIntervalFlag = cli.DurationFlag{
|
||||||
Name: "miner.recommit",
|
Name: "miner.recommit",
|
||||||
Usage: "Time interval to recreate the block being mined",
|
Usage: "Time interval to recreate the block being mined",
|
||||||
Value: eth.DefaultConfig.MinerRecommit,
|
Value: eth.DefaultConfig.Miner.Recommit,
|
||||||
}
|
}
|
||||||
MinerNoVerfiyFlag = cli.BoolFlag{
|
MinerNoVerfiyFlag = cli.BoolFlag{
|
||||||
Name: "miner.noverify",
|
Name: "miner.noverify",
|
||||||
@ -1023,7 +1024,7 @@ func setEtherbase(ctx *cli.Context, ks *keystore.KeyStore, cfg *eth.Config) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
Fatalf("Invalid miner etherbase: %v", err)
|
Fatalf("Invalid miner etherbase: %v", err)
|
||||||
}
|
}
|
||||||
cfg.Etherbase = account.Address
|
cfg.Miner.Etherbase = account.Address
|
||||||
} else {
|
} else {
|
||||||
Fatalf("No etherbase configured")
|
Fatalf("No etherbase configured")
|
||||||
}
|
}
|
||||||
@ -1231,6 +1232,39 @@ func setEthash(ctx *cli.Context, cfg *eth.Config) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setMiner(ctx *cli.Context, cfg *miner.Config) {
|
||||||
|
if ctx.GlobalIsSet(MinerNotifyFlag.Name) {
|
||||||
|
cfg.Notify = strings.Split(ctx.GlobalString(MinerNotifyFlag.Name), ",")
|
||||||
|
}
|
||||||
|
if ctx.GlobalIsSet(MinerLegacyExtraDataFlag.Name) {
|
||||||
|
cfg.ExtraData = []byte(ctx.GlobalString(MinerLegacyExtraDataFlag.Name))
|
||||||
|
}
|
||||||
|
if ctx.GlobalIsSet(MinerExtraDataFlag.Name) {
|
||||||
|
cfg.ExtraData = []byte(ctx.GlobalString(MinerExtraDataFlag.Name))
|
||||||
|
}
|
||||||
|
if ctx.GlobalIsSet(MinerLegacyGasTargetFlag.Name) {
|
||||||
|
cfg.GasFloor = ctx.GlobalUint64(MinerLegacyGasTargetFlag.Name)
|
||||||
|
}
|
||||||
|
if ctx.GlobalIsSet(MinerGasTargetFlag.Name) {
|
||||||
|
cfg.GasFloor = ctx.GlobalUint64(MinerGasTargetFlag.Name)
|
||||||
|
}
|
||||||
|
if ctx.GlobalIsSet(MinerGasLimitFlag.Name) {
|
||||||
|
cfg.GasCeil = ctx.GlobalUint64(MinerGasLimitFlag.Name)
|
||||||
|
}
|
||||||
|
if ctx.GlobalIsSet(MinerLegacyGasPriceFlag.Name) {
|
||||||
|
cfg.GasPrice = GlobalBig(ctx, MinerLegacyGasPriceFlag.Name)
|
||||||
|
}
|
||||||
|
if ctx.GlobalIsSet(MinerGasPriceFlag.Name) {
|
||||||
|
cfg.GasPrice = GlobalBig(ctx, MinerGasPriceFlag.Name)
|
||||||
|
}
|
||||||
|
if ctx.GlobalIsSet(MinerRecommitIntervalFlag.Name) {
|
||||||
|
cfg.Recommit = ctx.Duration(MinerRecommitIntervalFlag.Name)
|
||||||
|
}
|
||||||
|
if ctx.GlobalIsSet(MinerNoVerfiyFlag.Name) {
|
||||||
|
cfg.Noverify = ctx.Bool(MinerNoVerfiyFlag.Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func setWhitelist(ctx *cli.Context, cfg *eth.Config) {
|
func setWhitelist(ctx *cli.Context, cfg *eth.Config) {
|
||||||
whitelist := ctx.GlobalString(WhitelistFlag.Name)
|
whitelist := ctx.GlobalString(WhitelistFlag.Name)
|
||||||
if whitelist == "" {
|
if whitelist == "" {
|
||||||
@ -1323,6 +1357,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
|
|||||||
setGPO(ctx, &cfg.GPO)
|
setGPO(ctx, &cfg.GPO)
|
||||||
setTxPool(ctx, &cfg.TxPool)
|
setTxPool(ctx, &cfg.TxPool)
|
||||||
setEthash(ctx, cfg)
|
setEthash(ctx, cfg)
|
||||||
|
setMiner(ctx, &cfg.Miner)
|
||||||
setWhitelist(ctx, cfg)
|
setWhitelist(ctx, cfg)
|
||||||
|
|
||||||
if ctx.GlobalIsSet(SyncModeFlag.Name) {
|
if ctx.GlobalIsSet(SyncModeFlag.Name) {
|
||||||
@ -1359,39 +1394,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
|
|||||||
if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheGCFlag.Name) {
|
if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheGCFlag.Name) {
|
||||||
cfg.TrieDirtyCache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheGCFlag.Name) / 100
|
cfg.TrieDirtyCache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheGCFlag.Name) / 100
|
||||||
}
|
}
|
||||||
if ctx.GlobalIsSet(MinerNotifyFlag.Name) {
|
|
||||||
cfg.MinerNotify = strings.Split(ctx.GlobalString(MinerNotifyFlag.Name), ",")
|
|
||||||
}
|
|
||||||
if ctx.GlobalIsSet(DocRootFlag.Name) {
|
if ctx.GlobalIsSet(DocRootFlag.Name) {
|
||||||
cfg.DocRoot = ctx.GlobalString(DocRootFlag.Name)
|
cfg.DocRoot = ctx.GlobalString(DocRootFlag.Name)
|
||||||
}
|
}
|
||||||
if ctx.GlobalIsSet(MinerLegacyExtraDataFlag.Name) {
|
|
||||||
cfg.MinerExtraData = []byte(ctx.GlobalString(MinerLegacyExtraDataFlag.Name))
|
|
||||||
}
|
|
||||||
if ctx.GlobalIsSet(MinerExtraDataFlag.Name) {
|
|
||||||
cfg.MinerExtraData = []byte(ctx.GlobalString(MinerExtraDataFlag.Name))
|
|
||||||
}
|
|
||||||
if ctx.GlobalIsSet(MinerLegacyGasTargetFlag.Name) {
|
|
||||||
cfg.MinerGasFloor = ctx.GlobalUint64(MinerLegacyGasTargetFlag.Name)
|
|
||||||
}
|
|
||||||
if ctx.GlobalIsSet(MinerGasTargetFlag.Name) {
|
|
||||||
cfg.MinerGasFloor = ctx.GlobalUint64(MinerGasTargetFlag.Name)
|
|
||||||
}
|
|
||||||
if ctx.GlobalIsSet(MinerGasLimitFlag.Name) {
|
|
||||||
cfg.MinerGasCeil = ctx.GlobalUint64(MinerGasLimitFlag.Name)
|
|
||||||
}
|
|
||||||
if ctx.GlobalIsSet(MinerLegacyGasPriceFlag.Name) {
|
|
||||||
cfg.MinerGasPrice = GlobalBig(ctx, MinerLegacyGasPriceFlag.Name)
|
|
||||||
}
|
|
||||||
if ctx.GlobalIsSet(MinerGasPriceFlag.Name) {
|
|
||||||
cfg.MinerGasPrice = GlobalBig(ctx, MinerGasPriceFlag.Name)
|
|
||||||
}
|
|
||||||
if ctx.GlobalIsSet(MinerRecommitIntervalFlag.Name) {
|
|
||||||
cfg.MinerRecommit = ctx.Duration(MinerRecommitIntervalFlag.Name)
|
|
||||||
}
|
|
||||||
if ctx.GlobalIsSet(MinerNoVerfiyFlag.Name) {
|
|
||||||
cfg.MinerNoverify = ctx.Bool(MinerNoVerfiyFlag.Name)
|
|
||||||
}
|
|
||||||
if ctx.GlobalIsSet(VMEnableDebugFlag.Name) {
|
if ctx.GlobalIsSet(VMEnableDebugFlag.Name) {
|
||||||
// TODO(fjl): force-enable this in --dev mode
|
// TODO(fjl): force-enable this in --dev mode
|
||||||
cfg.EnablePreimageRecording = ctx.GlobalBool(VMEnableDebugFlag.Name)
|
cfg.EnablePreimageRecording = ctx.GlobalBool(VMEnableDebugFlag.Name)
|
||||||
@ -1449,7 +1454,7 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) {
|
|||||||
|
|
||||||
cfg.Genesis = core.DeveloperGenesisBlock(uint64(ctx.GlobalInt(DeveloperPeriodFlag.Name)), developer.Address)
|
cfg.Genesis = core.DeveloperGenesisBlock(uint64(ctx.GlobalInt(DeveloperPeriodFlag.Name)), developer.Address)
|
||||||
if !ctx.GlobalIsSet(MinerGasPriceFlag.Name) && !ctx.GlobalIsSet(MinerLegacyGasPriceFlag.Name) {
|
if !ctx.GlobalIsSet(MinerGasPriceFlag.Name) && !ctx.GlobalIsSet(MinerLegacyGasPriceFlag.Name) {
|
||||||
cfg.MinerGasPrice = big.NewInt(1)
|
cfg.Miner.GasPrice = big.NewInt(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,7 @@ import (
|
|||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
"github.com/ethereum/go-ethereum/internal/jsre"
|
"github.com/ethereum/go-ethereum/internal/jsre"
|
||||||
|
"github.com/ethereum/go-ethereum/miner"
|
||||||
"github.com/ethereum/go-ethereum/node"
|
"github.com/ethereum/go-ethereum/node"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -97,7 +98,9 @@ func newTester(t *testing.T, confOverride func(*eth.Config)) *tester {
|
|||||||
}
|
}
|
||||||
ethConf := ð.Config{
|
ethConf := ð.Config{
|
||||||
Genesis: core.DeveloperGenesisBlock(15, common.Address{}),
|
Genesis: core.DeveloperGenesisBlock(15, common.Address{}),
|
||||||
|
Miner: miner.Config{
|
||||||
Etherbase: common.HexToAddress(testAddress),
|
Etherbase: common.HexToAddress(testAddress),
|
||||||
|
},
|
||||||
Ethash: ethash.Config{
|
Ethash: ethash.Config{
|
||||||
PowMode: ethash.ModeTest,
|
PowMode: ethash.ModeTest,
|
||||||
},
|
},
|
||||||
|
@ -109,9 +109,9 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
|||||||
if !config.SyncMode.IsValid() {
|
if !config.SyncMode.IsValid() {
|
||||||
return nil, fmt.Errorf("invalid sync mode %d", config.SyncMode)
|
return nil, fmt.Errorf("invalid sync mode %d", config.SyncMode)
|
||||||
}
|
}
|
||||||
if config.MinerGasPrice == nil || config.MinerGasPrice.Cmp(common.Big0) <= 0 {
|
if config.Miner.GasPrice == nil || config.Miner.GasPrice.Cmp(common.Big0) <= 0 {
|
||||||
log.Warn("Sanitizing invalid miner gas price", "provided", config.MinerGasPrice, "updated", DefaultConfig.MinerGasPrice)
|
log.Warn("Sanitizing invalid miner gas price", "provided", config.Miner.GasPrice, "updated", DefaultConfig.Miner.GasPrice)
|
||||||
config.MinerGasPrice = new(big.Int).Set(DefaultConfig.MinerGasPrice)
|
config.Miner.GasPrice = new(big.Int).Set(DefaultConfig.Miner.GasPrice)
|
||||||
}
|
}
|
||||||
if config.NoPruning && config.TrieDirtyCache > 0 {
|
if config.NoPruning && config.TrieDirtyCache > 0 {
|
||||||
config.TrieCleanCache += config.TrieDirtyCache
|
config.TrieCleanCache += config.TrieDirtyCache
|
||||||
@ -135,11 +135,11 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
|||||||
chainDb: chainDb,
|
chainDb: chainDb,
|
||||||
eventMux: ctx.EventMux,
|
eventMux: ctx.EventMux,
|
||||||
accountManager: ctx.AccountManager,
|
accountManager: ctx.AccountManager,
|
||||||
engine: CreateConsensusEngine(ctx, chainConfig, &config.Ethash, config.MinerNotify, config.MinerNoverify, chainDb),
|
engine: CreateConsensusEngine(ctx, chainConfig, &config.Ethash, config.Miner.Notify, config.Miner.Noverify, chainDb),
|
||||||
shutdownChan: make(chan bool),
|
shutdownChan: make(chan bool),
|
||||||
networkID: config.NetworkId,
|
networkID: config.NetworkId,
|
||||||
gasPrice: config.MinerGasPrice,
|
gasPrice: config.Miner.GasPrice,
|
||||||
etherbase: config.Etherbase,
|
etherbase: config.Miner.Etherbase,
|
||||||
bloomRequests: make(chan chan *bloombits.Retrieval),
|
bloomRequests: make(chan chan *bloombits.Retrieval),
|
||||||
bloomIndexer: NewBloomIndexer(chainDb, params.BloomBitsBlocks, params.BloomConfirms),
|
bloomIndexer: NewBloomIndexer(chainDb, params.BloomBitsBlocks, params.BloomConfirms),
|
||||||
}
|
}
|
||||||
@ -194,13 +194,13 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
eth.miner = miner.New(eth, chainConfig, eth.EventMux(), eth.engine, config.MinerRecommit, config.MinerGasFloor, config.MinerGasCeil, eth.isLocalBlock)
|
eth.miner = miner.New(eth, &config.Miner, chainConfig, eth.EventMux(), eth.engine, eth.isLocalBlock)
|
||||||
eth.miner.SetExtra(makeExtraData(config.MinerExtraData))
|
eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))
|
||||||
|
|
||||||
eth.APIBackend = &EthAPIBackend{ctx.ExtRPCEnabled(), eth, nil}
|
eth.APIBackend = &EthAPIBackend{ctx.ExtRPCEnabled(), eth, nil}
|
||||||
gpoParams := config.GPO
|
gpoParams := config.GPO
|
||||||
if gpoParams.Default == nil {
|
if gpoParams.Default == nil {
|
||||||
gpoParams.Default = config.MinerGasPrice
|
gpoParams.Default = config.Miner.GasPrice
|
||||||
}
|
}
|
||||||
eth.APIBackend.gpo = gasprice.NewOracle(eth.APIBackend, gpoParams)
|
eth.APIBackend.gpo = gasprice.NewOracle(eth.APIBackend, gpoParams)
|
||||||
|
|
||||||
|
@ -25,11 +25,11 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
||||||
"github.com/ethereum/go-ethereum/consensus/ethash"
|
"github.com/ethereum/go-ethereum/consensus/ethash"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/eth/downloader"
|
"github.com/ethereum/go-ethereum/eth/downloader"
|
||||||
"github.com/ethereum/go-ethereum/eth/gasprice"
|
"github.com/ethereum/go-ethereum/eth/gasprice"
|
||||||
|
"github.com/ethereum/go-ethereum/miner"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -49,11 +49,12 @@ var DefaultConfig = Config{
|
|||||||
TrieCleanCache: 256,
|
TrieCleanCache: 256,
|
||||||
TrieDirtyCache: 256,
|
TrieDirtyCache: 256,
|
||||||
TrieTimeout: 60 * time.Minute,
|
TrieTimeout: 60 * time.Minute,
|
||||||
MinerGasFloor: 8000000,
|
Miner: miner.Config{
|
||||||
MinerGasCeil: 8000000,
|
GasFloor: 8000000,
|
||||||
MinerGasPrice: big.NewInt(params.GWei),
|
GasCeil: 8000000,
|
||||||
MinerRecommit: 3 * time.Second,
|
GasPrice: big.NewInt(params.GWei),
|
||||||
|
Recommit: 3 * time.Second,
|
||||||
|
},
|
||||||
TxPool: core.DefaultTxPoolConfig,
|
TxPool: core.DefaultTxPoolConfig,
|
||||||
GPO: gasprice.Config{
|
GPO: gasprice.Config{
|
||||||
Blocks: 20,
|
Blocks: 20,
|
||||||
@ -82,7 +83,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//go:generate gencodec -type Config -field-override configMarshaling -formats toml -out gen_config.go
|
//go:generate gencodec -type Config -formats toml -out gen_config.go
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
// The genesis block, which is inserted if the database is empty.
|
// The genesis block, which is inserted if the database is empty.
|
||||||
@ -118,15 +119,8 @@ type Config struct {
|
|||||||
TrieDirtyCache int
|
TrieDirtyCache int
|
||||||
TrieTimeout time.Duration
|
TrieTimeout time.Duration
|
||||||
|
|
||||||
// Mining-related options
|
// Mining options
|
||||||
Etherbase common.Address `toml:",omitempty"`
|
Miner miner.Config
|
||||||
MinerNotify []string `toml:",omitempty"`
|
|
||||||
MinerExtraData []byte `toml:",omitempty"`
|
|
||||||
MinerGasFloor uint64
|
|
||||||
MinerGasCeil uint64
|
|
||||||
MinerGasPrice *big.Int
|
|
||||||
MinerRecommit time.Duration
|
|
||||||
MinerNoverify bool
|
|
||||||
|
|
||||||
// Ethash options
|
// Ethash options
|
||||||
Ethash ethash.Config
|
Ethash ethash.Config
|
||||||
@ -155,7 +149,3 @@ type Config struct {
|
|||||||
// RPCGasCap is the global gas cap for eth-call variants.
|
// RPCGasCap is the global gas cap for eth-call variants.
|
||||||
RPCGasCap *big.Int `toml:",omitempty"`
|
RPCGasCap *big.Int `toml:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type configMarshaling struct {
|
|
||||||
MinerExtraData hexutil.Bytes
|
|
||||||
}
|
|
||||||
|
@ -7,15 +7,13 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
||||||
"github.com/ethereum/go-ethereum/consensus/ethash"
|
"github.com/ethereum/go-ethereum/consensus/ethash"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/eth/downloader"
|
"github.com/ethereum/go-ethereum/eth/downloader"
|
||||||
"github.com/ethereum/go-ethereum/eth/gasprice"
|
"github.com/ethereum/go-ethereum/eth/gasprice"
|
||||||
|
"github.com/ethereum/go-ethereum/miner"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = (*configMarshaling)(nil)
|
|
||||||
|
|
||||||
// MarshalTOML marshals as TOML.
|
// MarshalTOML marshals as TOML.
|
||||||
func (c Config) MarshalTOML() (interface{}, error) {
|
func (c Config) MarshalTOML() (interface{}, error) {
|
||||||
type Config struct {
|
type Config struct {
|
||||||
@ -23,6 +21,8 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
|||||||
NetworkId uint64
|
NetworkId uint64
|
||||||
SyncMode downloader.SyncMode
|
SyncMode downloader.SyncMode
|
||||||
NoPruning bool
|
NoPruning bool
|
||||||
|
NoPrefetch bool
|
||||||
|
Whitelist map[uint64]common.Hash `toml:"-"`
|
||||||
LightServ int `toml:",omitempty"`
|
LightServ int `toml:",omitempty"`
|
||||||
LightBandwidthIn int `toml:",omitempty"`
|
LightBandwidthIn int `toml:",omitempty"`
|
||||||
LightBandwidthOut int `toml:",omitempty"`
|
LightBandwidthOut int `toml:",omitempty"`
|
||||||
@ -35,14 +35,7 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
|||||||
TrieCleanCache int
|
TrieCleanCache int
|
||||||
TrieDirtyCache int
|
TrieDirtyCache int
|
||||||
TrieTimeout time.Duration
|
TrieTimeout time.Duration
|
||||||
Etherbase common.Address `toml:",omitempty"`
|
Miner miner.Config
|
||||||
MinerNotify []string `toml:",omitempty"`
|
|
||||||
MinerExtraData hexutil.Bytes `toml:",omitempty"`
|
|
||||||
MinerGasFloor uint64
|
|
||||||
MinerGasCeil uint64
|
|
||||||
MinerGasPrice *big.Int
|
|
||||||
MinerRecommit time.Duration
|
|
||||||
MinerNoverify bool
|
|
||||||
Ethash ethash.Config
|
Ethash ethash.Config
|
||||||
TxPool core.TxPoolConfig
|
TxPool core.TxPoolConfig
|
||||||
GPO gasprice.Config
|
GPO gasprice.Config
|
||||||
@ -50,12 +43,16 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
|||||||
DocRoot string `toml:"-"`
|
DocRoot string `toml:"-"`
|
||||||
EWASMInterpreter string
|
EWASMInterpreter string
|
||||||
EVMInterpreter string
|
EVMInterpreter string
|
||||||
|
ConstantinopleOverride *big.Int
|
||||||
|
RPCGasCap *big.Int `toml:",omitempty"`
|
||||||
}
|
}
|
||||||
var enc Config
|
var enc Config
|
||||||
enc.Genesis = c.Genesis
|
enc.Genesis = c.Genesis
|
||||||
enc.NetworkId = c.NetworkId
|
enc.NetworkId = c.NetworkId
|
||||||
enc.SyncMode = c.SyncMode
|
enc.SyncMode = c.SyncMode
|
||||||
enc.NoPruning = c.NoPruning
|
enc.NoPruning = c.NoPruning
|
||||||
|
enc.NoPrefetch = c.NoPrefetch
|
||||||
|
enc.Whitelist = c.Whitelist
|
||||||
enc.LightServ = c.LightServ
|
enc.LightServ = c.LightServ
|
||||||
enc.LightBandwidthIn = c.LightBandwidthIn
|
enc.LightBandwidthIn = c.LightBandwidthIn
|
||||||
enc.LightBandwidthOut = c.LightBandwidthOut
|
enc.LightBandwidthOut = c.LightBandwidthOut
|
||||||
@ -68,22 +65,16 @@ func (c Config) MarshalTOML() (interface{}, error) {
|
|||||||
enc.TrieCleanCache = c.TrieCleanCache
|
enc.TrieCleanCache = c.TrieCleanCache
|
||||||
enc.TrieDirtyCache = c.TrieDirtyCache
|
enc.TrieDirtyCache = c.TrieDirtyCache
|
||||||
enc.TrieTimeout = c.TrieTimeout
|
enc.TrieTimeout = c.TrieTimeout
|
||||||
enc.Etherbase = c.Etherbase
|
enc.Miner = c.Miner
|
||||||
enc.MinerNotify = c.MinerNotify
|
|
||||||
enc.MinerExtraData = c.MinerExtraData
|
|
||||||
enc.MinerGasFloor = c.MinerGasFloor
|
|
||||||
enc.MinerGasCeil = c.MinerGasCeil
|
|
||||||
enc.MinerGasPrice = c.MinerGasPrice
|
|
||||||
enc.MinerRecommit = c.MinerRecommit
|
|
||||||
enc.MinerNoverify = c.MinerNoverify
|
|
||||||
enc.Ethash = c.Ethash
|
enc.Ethash = c.Ethash
|
||||||
enc.TxPool = c.TxPool
|
enc.TxPool = c.TxPool
|
||||||
enc.GPO = c.GPO
|
enc.GPO = c.GPO
|
||||||
|
|
||||||
enc.EnablePreimageRecording = c.EnablePreimageRecording
|
enc.EnablePreimageRecording = c.EnablePreimageRecording
|
||||||
enc.DocRoot = c.DocRoot
|
enc.DocRoot = c.DocRoot
|
||||||
enc.EWASMInterpreter = c.EWASMInterpreter
|
enc.EWASMInterpreter = c.EWASMInterpreter
|
||||||
enc.EVMInterpreter = c.EVMInterpreter
|
enc.EVMInterpreter = c.EVMInterpreter
|
||||||
|
enc.ConstantinopleOverride = c.ConstantinopleOverride
|
||||||
|
enc.RPCGasCap = c.RPCGasCap
|
||||||
return &enc, nil
|
return &enc, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,6 +85,8 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
|||||||
NetworkId *uint64
|
NetworkId *uint64
|
||||||
SyncMode *downloader.SyncMode
|
SyncMode *downloader.SyncMode
|
||||||
NoPruning *bool
|
NoPruning *bool
|
||||||
|
NoPrefetch *bool
|
||||||
|
Whitelist map[uint64]common.Hash `toml:"-"`
|
||||||
LightServ *int `toml:",omitempty"`
|
LightServ *int `toml:",omitempty"`
|
||||||
LightBandwidthIn *int `toml:",omitempty"`
|
LightBandwidthIn *int `toml:",omitempty"`
|
||||||
LightBandwidthOut *int `toml:",omitempty"`
|
LightBandwidthOut *int `toml:",omitempty"`
|
||||||
@ -106,14 +99,7 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
|||||||
TrieCleanCache *int
|
TrieCleanCache *int
|
||||||
TrieDirtyCache *int
|
TrieDirtyCache *int
|
||||||
TrieTimeout *time.Duration
|
TrieTimeout *time.Duration
|
||||||
Etherbase *common.Address `toml:",omitempty"`
|
Miner *miner.Config
|
||||||
MinerNotify []string `toml:",omitempty"`
|
|
||||||
MinerExtraData *hexutil.Bytes `toml:",omitempty"`
|
|
||||||
MinerGasFloor *uint64
|
|
||||||
MinerGasCeil *uint64
|
|
||||||
MinerGasPrice *big.Int
|
|
||||||
MinerRecommit *time.Duration
|
|
||||||
MinerNoverify *bool
|
|
||||||
Ethash *ethash.Config
|
Ethash *ethash.Config
|
||||||
TxPool *core.TxPoolConfig
|
TxPool *core.TxPoolConfig
|
||||||
GPO *gasprice.Config
|
GPO *gasprice.Config
|
||||||
@ -121,6 +107,8 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
|||||||
DocRoot *string `toml:"-"`
|
DocRoot *string `toml:"-"`
|
||||||
EWASMInterpreter *string
|
EWASMInterpreter *string
|
||||||
EVMInterpreter *string
|
EVMInterpreter *string
|
||||||
|
ConstantinopleOverride *big.Int
|
||||||
|
RPCGasCap *big.Int `toml:",omitempty"`
|
||||||
}
|
}
|
||||||
var dec Config
|
var dec Config
|
||||||
if err := unmarshal(&dec); err != nil {
|
if err := unmarshal(&dec); err != nil {
|
||||||
@ -138,6 +126,12 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
|||||||
if dec.NoPruning != nil {
|
if dec.NoPruning != nil {
|
||||||
c.NoPruning = *dec.NoPruning
|
c.NoPruning = *dec.NoPruning
|
||||||
}
|
}
|
||||||
|
if dec.NoPrefetch != nil {
|
||||||
|
c.NoPrefetch = *dec.NoPrefetch
|
||||||
|
}
|
||||||
|
if dec.Whitelist != nil {
|
||||||
|
c.Whitelist = dec.Whitelist
|
||||||
|
}
|
||||||
if dec.LightServ != nil {
|
if dec.LightServ != nil {
|
||||||
c.LightServ = *dec.LightServ
|
c.LightServ = *dec.LightServ
|
||||||
}
|
}
|
||||||
@ -174,29 +168,8 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
|||||||
if dec.TrieTimeout != nil {
|
if dec.TrieTimeout != nil {
|
||||||
c.TrieTimeout = *dec.TrieTimeout
|
c.TrieTimeout = *dec.TrieTimeout
|
||||||
}
|
}
|
||||||
if dec.Etherbase != nil {
|
if dec.Miner != nil {
|
||||||
c.Etherbase = *dec.Etherbase
|
c.Miner = *dec.Miner
|
||||||
}
|
|
||||||
if dec.MinerNotify != nil {
|
|
||||||
c.MinerNotify = dec.MinerNotify
|
|
||||||
}
|
|
||||||
if dec.MinerExtraData != nil {
|
|
||||||
c.MinerExtraData = *dec.MinerExtraData
|
|
||||||
}
|
|
||||||
if dec.MinerGasFloor != nil {
|
|
||||||
c.MinerGasFloor = *dec.MinerGasFloor
|
|
||||||
}
|
|
||||||
if dec.MinerGasCeil != nil {
|
|
||||||
c.MinerGasCeil = *dec.MinerGasCeil
|
|
||||||
}
|
|
||||||
if dec.MinerGasPrice != nil {
|
|
||||||
c.MinerGasPrice = dec.MinerGasPrice
|
|
||||||
}
|
|
||||||
if dec.MinerRecommit != nil {
|
|
||||||
c.MinerRecommit = *dec.MinerRecommit
|
|
||||||
}
|
|
||||||
if dec.MinerNoverify != nil {
|
|
||||||
c.MinerNoverify = *dec.MinerNoverify
|
|
||||||
}
|
}
|
||||||
if dec.Ethash != nil {
|
if dec.Ethash != nil {
|
||||||
c.Ethash = *dec.Ethash
|
c.Ethash = *dec.Ethash
|
||||||
@ -219,5 +192,11 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
|
|||||||
if dec.EVMInterpreter != nil {
|
if dec.EVMInterpreter != nil {
|
||||||
c.EVMInterpreter = *dec.EVMInterpreter
|
c.EVMInterpreter = *dec.EVMInterpreter
|
||||||
}
|
}
|
||||||
|
if dec.ConstantinopleOverride != nil {
|
||||||
|
c.ConstantinopleOverride = dec.ConstantinopleOverride
|
||||||
|
}
|
||||||
|
if dec.RPCGasCap != nil {
|
||||||
|
c.RPCGasCap = dec.RPCGasCap
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,7 @@ func New(ctx *node.ServiceContext, config *eth.Config) (*LightEthereum, error) {
|
|||||||
|
|
||||||
gpoParams := config.GPO
|
gpoParams := config.GPO
|
||||||
if gpoParams.Default == nil {
|
if gpoParams.Default == nil {
|
||||||
gpoParams.Default = config.MinerGasPrice
|
gpoParams.Default = config.Miner.GasPrice
|
||||||
}
|
}
|
||||||
leth.ApiBackend.gpo = gasprice.NewOracle(leth.ApiBackend, gpoParams)
|
leth.ApiBackend.gpo = gasprice.NewOracle(leth.ApiBackend, gpoParams)
|
||||||
return leth, nil
|
return leth, nil
|
||||||
|
@ -19,10 +19,12 @@ package miner
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/big"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/consensus"
|
"github.com/ethereum/go-ethereum/consensus"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/state"
|
"github.com/ethereum/go-ethereum/core/state"
|
||||||
@ -39,6 +41,18 @@ type Backend interface {
|
|||||||
TxPool() *core.TxPool
|
TxPool() *core.TxPool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Config is the configuration parameters of mining.
|
||||||
|
type Config struct {
|
||||||
|
Etherbase common.Address `toml:",omitempty"` // Public address for block mining rewards (default = first account)
|
||||||
|
Notify []string `toml:",omitempty"` // HTTP URL list to be notified of new work packages(only useful in ethash).
|
||||||
|
ExtraData hexutil.Bytes `toml:",omitempty"` // Block extra data set by the miner
|
||||||
|
GasFloor uint64 // Target gas floor for mined blocks.
|
||||||
|
GasCeil uint64 // Target gas ceiling for mined blocks.
|
||||||
|
GasPrice *big.Int // Minimum gas price for mining a transaction
|
||||||
|
Recommit time.Duration // The time interval for miner to re-create mining work.
|
||||||
|
Noverify bool // Disable remote mining solution verification(only useful in ethash).
|
||||||
|
}
|
||||||
|
|
||||||
// Miner creates blocks and searches for proof-of-work values.
|
// Miner creates blocks and searches for proof-of-work values.
|
||||||
type Miner struct {
|
type Miner struct {
|
||||||
mux *event.TypeMux
|
mux *event.TypeMux
|
||||||
@ -52,13 +66,13 @@ type Miner struct {
|
|||||||
shouldStart int32 // should start indicates whether we should start after sync
|
shouldStart int32 // should start indicates whether we should start after sync
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(eth Backend, config *params.ChainConfig, mux *event.TypeMux, engine consensus.Engine, recommit time.Duration, gasFloor, gasCeil uint64, isLocalBlock func(block *types.Block) bool) *Miner {
|
func New(eth Backend, config *Config, chainConfig *params.ChainConfig, mux *event.TypeMux, engine consensus.Engine, isLocalBlock func(block *types.Block) bool) *Miner {
|
||||||
miner := &Miner{
|
miner := &Miner{
|
||||||
eth: eth,
|
eth: eth,
|
||||||
mux: mux,
|
mux: mux,
|
||||||
engine: engine,
|
engine: engine,
|
||||||
exitCh: make(chan struct{}),
|
exitCh: make(chan struct{}),
|
||||||
worker: newWorker(config, engine, eth, mux, recommit, gasFloor, gasCeil, isLocalBlock),
|
worker: newWorker(config, chainConfig, engine, eth, mux, isLocalBlock),
|
||||||
canStart: 1,
|
canStart: 1,
|
||||||
}
|
}
|
||||||
go miner.update()
|
go miner.update()
|
||||||
|
@ -199,10 +199,12 @@ func makeSealer(genesis *core.Genesis) (*node.Node, error) {
|
|||||||
DatabaseHandles: 256,
|
DatabaseHandles: 256,
|
||||||
TxPool: core.DefaultTxPoolConfig,
|
TxPool: core.DefaultTxPoolConfig,
|
||||||
GPO: eth.DefaultConfig.GPO,
|
GPO: eth.DefaultConfig.GPO,
|
||||||
MinerGasFloor: genesis.GasLimit * 9 / 10,
|
Miner: Config{
|
||||||
MinerGasCeil: genesis.GasLimit * 11 / 10,
|
GasFloor: genesis.GasLimit * 9 / 10,
|
||||||
MinerGasPrice: big.NewInt(1),
|
GasCeil: genesis.GasLimit * 11 / 10,
|
||||||
MinerRecommit: time.Second,
|
GasPrice: big.NewInt(1),
|
||||||
|
Recommit: time.Second,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -179,10 +179,12 @@ func makeMiner(genesis *core.Genesis) (*node.Node, error) {
|
|||||||
TxPool: core.DefaultTxPoolConfig,
|
TxPool: core.DefaultTxPoolConfig,
|
||||||
GPO: eth.DefaultConfig.GPO,
|
GPO: eth.DefaultConfig.GPO,
|
||||||
Ethash: eth.DefaultConfig.Ethash,
|
Ethash: eth.DefaultConfig.Ethash,
|
||||||
MinerGasFloor: genesis.GasLimit * 9 / 10,
|
Miner: Config{
|
||||||
MinerGasCeil: genesis.GasLimit * 11 / 10,
|
GasFloor: genesis.GasLimit * 9 / 10,
|
||||||
MinerGasPrice: big.NewInt(1),
|
GasCeil: genesis.GasLimit * 11 / 10,
|
||||||
MinerRecommit: time.Second,
|
GasPrice: big.NewInt(1),
|
||||||
|
Recommit: time.Second,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -122,14 +122,12 @@ type intervalAdjust struct {
|
|||||||
// worker is the main object which takes care of submitting new work to consensus engine
|
// worker is the main object which takes care of submitting new work to consensus engine
|
||||||
// and gathering the sealing result.
|
// and gathering the sealing result.
|
||||||
type worker struct {
|
type worker struct {
|
||||||
config *params.ChainConfig
|
config *Config
|
||||||
|
chainConfig *params.ChainConfig
|
||||||
engine consensus.Engine
|
engine consensus.Engine
|
||||||
eth Backend
|
eth Backend
|
||||||
chain *core.BlockChain
|
chain *core.BlockChain
|
||||||
|
|
||||||
gasFloor uint64
|
|
||||||
gasCeil uint64
|
|
||||||
|
|
||||||
// Subscriptions
|
// Subscriptions
|
||||||
mux *event.TypeMux
|
mux *event.TypeMux
|
||||||
txsCh chan core.NewTxsEvent
|
txsCh chan core.NewTxsEvent
|
||||||
@ -178,15 +176,14 @@ type worker struct {
|
|||||||
resubmitHook func(time.Duration, time.Duration) // Method to call upon updating resubmitting interval.
|
resubmitHook func(time.Duration, time.Duration) // Method to call upon updating resubmitting interval.
|
||||||
}
|
}
|
||||||
|
|
||||||
func newWorker(config *params.ChainConfig, engine consensus.Engine, eth Backend, mux *event.TypeMux, recommit time.Duration, gasFloor, gasCeil uint64, isLocalBlock func(*types.Block) bool) *worker {
|
func newWorker(config *Config, chainConfig *params.ChainConfig, engine consensus.Engine, eth Backend, mux *event.TypeMux, isLocalBlock func(*types.Block) bool) *worker {
|
||||||
worker := &worker{
|
worker := &worker{
|
||||||
config: config,
|
config: config,
|
||||||
|
chainConfig: chainConfig,
|
||||||
engine: engine,
|
engine: engine,
|
||||||
eth: eth,
|
eth: eth,
|
||||||
mux: mux,
|
mux: mux,
|
||||||
chain: eth.BlockChain(),
|
chain: eth.BlockChain(),
|
||||||
gasFloor: gasFloor,
|
|
||||||
gasCeil: gasCeil,
|
|
||||||
isLocalBlock: isLocalBlock,
|
isLocalBlock: isLocalBlock,
|
||||||
localUncles: make(map[common.Hash]*types.Block),
|
localUncles: make(map[common.Hash]*types.Block),
|
||||||
remoteUncles: make(map[common.Hash]*types.Block),
|
remoteUncles: make(map[common.Hash]*types.Block),
|
||||||
@ -210,6 +207,7 @@ func newWorker(config *params.ChainConfig, engine consensus.Engine, eth Backend,
|
|||||||
worker.chainSideSub = eth.BlockChain().SubscribeChainSideEvent(worker.chainSideCh)
|
worker.chainSideSub = eth.BlockChain().SubscribeChainSideEvent(worker.chainSideCh)
|
||||||
|
|
||||||
// Sanitize recommit interval if the user-specified one is too short.
|
// Sanitize recommit interval if the user-specified one is too short.
|
||||||
|
recommit := worker.config.Recommit
|
||||||
if recommit < minRecommitInterval {
|
if recommit < minRecommitInterval {
|
||||||
log.Warn("Sanitizing miner recommit interval", "provided", recommit, "updated", minRecommitInterval)
|
log.Warn("Sanitizing miner recommit interval", "provided", recommit, "updated", minRecommitInterval)
|
||||||
recommit = minRecommitInterval
|
recommit = minRecommitInterval
|
||||||
@ -354,7 +352,7 @@ func (w *worker) newWorkLoop(recommit time.Duration) {
|
|||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
// If mining is running resubmit a new work cycle periodically to pull in
|
// If mining is running resubmit a new work cycle periodically to pull in
|
||||||
// higher priced transactions. Disable this overhead for pending blocks.
|
// higher priced transactions. Disable this overhead for pending blocks.
|
||||||
if w.isRunning() && (w.config.Clique == nil || w.config.Clique.Period > 0) {
|
if w.isRunning() && (w.chainConfig.Clique == nil || w.chainConfig.Clique.Period > 0) {
|
||||||
// Short circuit if no new transaction arrives.
|
// Short circuit if no new transaction arrives.
|
||||||
if atomic.LoadInt32(&w.newTxs) == 0 {
|
if atomic.LoadInt32(&w.newTxs) == 0 {
|
||||||
timer.Reset(recommit)
|
timer.Reset(recommit)
|
||||||
@ -468,9 +466,10 @@ func (w *worker) mainLoop() {
|
|||||||
w.commitTransactions(txset, coinbase, nil)
|
w.commitTransactions(txset, coinbase, nil)
|
||||||
w.updateSnapshot()
|
w.updateSnapshot()
|
||||||
} else {
|
} else {
|
||||||
// If we're mining, but nothing is being processed, wake on new transactions
|
// If clique is running in dev mode(period is 0), disable
|
||||||
if w.config.Clique != nil && w.config.Clique.Period == 0 {
|
// advance sealing here.
|
||||||
w.commitNewWork(nil, false, time.Now().Unix())
|
if w.chainConfig.Clique != nil && w.chainConfig.Clique.Period == 0 {
|
||||||
|
w.commitNewWork(nil, true, time.Now().Unix())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
atomic.AddInt32(&w.newTxs, int32(len(ev.Txs)))
|
atomic.AddInt32(&w.newTxs, int32(len(ev.Txs)))
|
||||||
@ -618,7 +617,7 @@ func (w *worker) makeCurrent(parent *types.Block, header *types.Header) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
env := &environment{
|
env := &environment{
|
||||||
signer: types.NewEIP155Signer(w.config.ChainID),
|
signer: types.NewEIP155Signer(w.chainConfig.ChainID),
|
||||||
state: state,
|
state: state,
|
||||||
ancestors: mapset.NewSet(),
|
ancestors: mapset.NewSet(),
|
||||||
family: mapset.NewSet(),
|
family: mapset.NewSet(),
|
||||||
@ -696,7 +695,7 @@ func (w *worker) updateSnapshot() {
|
|||||||
func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Address) ([]*types.Log, error) {
|
func (w *worker) commitTransaction(tx *types.Transaction, coinbase common.Address) ([]*types.Log, error) {
|
||||||
snap := w.current.state.Snapshot()
|
snap := w.current.state.Snapshot()
|
||||||
|
|
||||||
receipt, _, err := core.ApplyTransaction(w.config, w.chain, &coinbase, w.current.gasPool, w.current.state, w.current.header, tx, &w.current.header.GasUsed, *w.chain.GetVMConfig())
|
receipt, _, err := core.ApplyTransaction(w.chainConfig, w.chain, &coinbase, w.current.gasPool, w.current.state, w.current.header, tx, &w.current.header.GasUsed, *w.chain.GetVMConfig())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.current.state.RevertToSnapshot(snap)
|
w.current.state.RevertToSnapshot(snap)
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -757,8 +756,8 @@ func (w *worker) commitTransactions(txs *types.TransactionsByPriceAndNonce, coin
|
|||||||
from, _ := types.Sender(w.current.signer, tx)
|
from, _ := types.Sender(w.current.signer, tx)
|
||||||
// Check whether the tx is replay protected. If we're not in the EIP155 hf
|
// Check whether the tx is replay protected. If we're not in the EIP155 hf
|
||||||
// phase, start ignoring the sender until we do.
|
// phase, start ignoring the sender until we do.
|
||||||
if tx.Protected() && !w.config.IsEIP155(w.current.header.Number) {
|
if tx.Protected() && !w.chainConfig.IsEIP155(w.current.header.Number) {
|
||||||
log.Trace("Ignoring reply protected transaction", "hash", tx.Hash(), "eip155", w.config.EIP155Block)
|
log.Trace("Ignoring reply protected transaction", "hash", tx.Hash(), "eip155", w.chainConfig.EIP155Block)
|
||||||
|
|
||||||
txs.Pop()
|
txs.Pop()
|
||||||
continue
|
continue
|
||||||
@ -842,7 +841,7 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
|
|||||||
header := &types.Header{
|
header := &types.Header{
|
||||||
ParentHash: parent.Hash(),
|
ParentHash: parent.Hash(),
|
||||||
Number: num.Add(num, common.Big1),
|
Number: num.Add(num, common.Big1),
|
||||||
GasLimit: core.CalcGasLimit(parent, w.gasFloor, w.gasCeil),
|
GasLimit: core.CalcGasLimit(parent, w.config.GasFloor, w.config.GasCeil),
|
||||||
Extra: w.extra,
|
Extra: w.extra,
|
||||||
Time: uint64(timestamp),
|
Time: uint64(timestamp),
|
||||||
}
|
}
|
||||||
@ -859,12 +858,12 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
// If we are care about TheDAO hard-fork check whether to override the extra-data or not
|
// If we are care about TheDAO hard-fork check whether to override the extra-data or not
|
||||||
if daoBlock := w.config.DAOForkBlock; daoBlock != nil {
|
if daoBlock := w.chainConfig.DAOForkBlock; daoBlock != nil {
|
||||||
// Check whether the block is among the fork extra-override range
|
// Check whether the block is among the fork extra-override range
|
||||||
limit := new(big.Int).Add(daoBlock, params.DAOForkExtraRange)
|
limit := new(big.Int).Add(daoBlock, params.DAOForkExtraRange)
|
||||||
if header.Number.Cmp(daoBlock) >= 0 && header.Number.Cmp(limit) < 0 {
|
if header.Number.Cmp(daoBlock) >= 0 && header.Number.Cmp(limit) < 0 {
|
||||||
// Depending whether we support or oppose the fork, override differently
|
// Depending whether we support or oppose the fork, override differently
|
||||||
if w.config.DAOForkSupport {
|
if w.chainConfig.DAOForkSupport {
|
||||||
header.Extra = common.CopyBytes(params.DAOForkBlockExtra)
|
header.Extra = common.CopyBytes(params.DAOForkBlockExtra)
|
||||||
} else if bytes.Equal(header.Extra, params.DAOForkBlockExtra) {
|
} else if bytes.Equal(header.Extra, params.DAOForkBlockExtra) {
|
||||||
header.Extra = []byte{} // If miner opposes, don't let it use the reserved extra-data
|
header.Extra = []byte{} // If miner opposes, don't let it use the reserved extra-data
|
||||||
@ -879,7 +878,7 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
|
|||||||
}
|
}
|
||||||
// Create the current work task and check any fork transitions needed
|
// Create the current work task and check any fork transitions needed
|
||||||
env := w.current
|
env := w.current
|
||||||
if w.config.DAOForkSupport && w.config.DAOForkBlock != nil && w.config.DAOForkBlock.Cmp(header.Number) == 0 {
|
if w.chainConfig.DAOForkSupport && w.chainConfig.DAOForkBlock != nil && w.chainConfig.DAOForkBlock.Cmp(header.Number) == 0 {
|
||||||
misc.ApplyDAOHardFork(env.state)
|
misc.ApplyDAOHardFork(env.state)
|
||||||
}
|
}
|
||||||
// Accumulate the uncles for the current block
|
// Accumulate the uncles for the current block
|
||||||
|
@ -52,6 +52,12 @@ var (
|
|||||||
// Test transactions
|
// Test transactions
|
||||||
pendingTxs []*types.Transaction
|
pendingTxs []*types.Transaction
|
||||||
newTxs []*types.Transaction
|
newTxs []*types.Transaction
|
||||||
|
|
||||||
|
testConfig = &Config{
|
||||||
|
Recommit: time.Second,
|
||||||
|
GasFloor: params.GenesisGasLimit,
|
||||||
|
GasCeil: params.GenesisGasLimit,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -134,7 +140,7 @@ func (b *testWorkerBackend) PostChainEvents(events []interface{}) {
|
|||||||
func newTestWorker(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine, blocks int) (*worker, *testWorkerBackend) {
|
func newTestWorker(t *testing.T, chainConfig *params.ChainConfig, engine consensus.Engine, blocks int) (*worker, *testWorkerBackend) {
|
||||||
backend := newTestWorkerBackend(t, chainConfig, engine, blocks)
|
backend := newTestWorkerBackend(t, chainConfig, engine, blocks)
|
||||||
backend.txPool.AddLocals(pendingTxs)
|
backend.txPool.AddLocals(pendingTxs)
|
||||||
w := newWorker(chainConfig, engine, backend, new(event.TypeMux), time.Second, params.GenesisGasLimit, params.GenesisGasLimit, nil)
|
w := newWorker(testConfig, chainConfig, engine, backend, new(event.TypeMux), nil)
|
||||||
w.setEtherbase(testBankAddress)
|
w.setEtherbase(testBankAddress)
|
||||||
return w, backend
|
return w, backend
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user