mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +00:00
fixed
This commit is contained in:
parent
f0cf0a9f15
commit
5501a5707c
6 changed files with 44 additions and 48 deletions
|
|
@ -120,7 +120,7 @@ var (
|
||||||
//utils.GpoPercentileFlag,
|
//utils.GpoPercentileFlag,
|
||||||
//utils.ExtraDataFlag,
|
//utils.ExtraDataFlag,
|
||||||
configFileFlag,
|
configFileFlag,
|
||||||
utils.CommitTxWhenNotMiningFlag,
|
utils.AnnounceTxsFlag,
|
||||||
}
|
}
|
||||||
|
|
||||||
rpcFlags = []cli.Flag{
|
rpcFlags = []cli.Flag{
|
||||||
|
|
|
||||||
|
|
@ -111,10 +111,9 @@ func NewApp(gitCommit, usage string) *cli.App {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// General settings
|
// General settings
|
||||||
CommitTxWhenNotMiningFlag = DirectoryFlag{
|
AnnounceTxsFlag = cli.BoolFlag{
|
||||||
Name: "committxwhennotmining",
|
Name: "announce-txs",
|
||||||
Usage: "Always commit transactions",
|
Usage: "Always commit transactions",
|
||||||
Value: DirectoryString{node.DefaultDataDir()},
|
|
||||||
}
|
}
|
||||||
DataDirFlag = DirectoryFlag{
|
DataDirFlag = DirectoryFlag{
|
||||||
Name: "datadir",
|
Name: "datadir",
|
||||||
|
|
@ -900,8 +899,8 @@ func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
|
||||||
if ctx.GlobalIsSet(NoUSBFlag.Name) {
|
if ctx.GlobalIsSet(NoUSBFlag.Name) {
|
||||||
cfg.NoUSB = ctx.GlobalBool(NoUSBFlag.Name)
|
cfg.NoUSB = ctx.GlobalBool(NoUSBFlag.Name)
|
||||||
}
|
}
|
||||||
if ctx.GlobalIsSet(CommitTxWhenNotMiningFlag.Name) {
|
if ctx.GlobalIsSet(AnnounceTxsFlag.Name) {
|
||||||
cfg.CommitTxWhenNotMining = ctx.GlobalBool(CommitTxWhenNotMiningFlag.Name)
|
cfg.AnnounceTxs = ctx.GlobalBool(AnnounceTxsFlag.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -174,7 +174,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
||||||
if eth.protocolManager, err = NewProtocolManager(eth.chainConfig, config.SyncMode, config.NetworkId, eth.eventMux, eth.txPool, eth.engine, eth.blockchain, chainDb); err != nil {
|
if eth.protocolManager, err = NewProtocolManager(eth.chainConfig, config.SyncMode, config.NetworkId, eth.eventMux, eth.txPool, eth.engine, eth.blockchain, chainDb); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
eth.miner = miner.New(eth, eth.chainConfig, eth.EventMux(), eth.engine, ctx.GetConfig().CommitTxWhenNotMining)
|
eth.miner = miner.New(eth, eth.chainConfig, eth.EventMux(), eth.engine, ctx.GetConfig().AnnounceTxs)
|
||||||
eth.miner.SetExtra(makeExtraData(config.ExtraData))
|
eth.miner.SetExtra(makeExtraData(config.ExtraData))
|
||||||
|
|
||||||
eth.ApiBackend = &EthApiBackend{eth, nil}
|
eth.ApiBackend = &EthApiBackend{eth, nil}
|
||||||
|
|
@ -231,19 +231,16 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
||||||
eth.protocolManager.fetcher.SetSignHook(signHook)
|
eth.protocolManager.fetcher.SetSignHook(signHook)
|
||||||
eth.protocolManager.fetcher.SetAppendM2HeaderHook(appendM2HeaderHook)
|
eth.protocolManager.fetcher.SetAppendM2HeaderHook(appendM2HeaderHook)
|
||||||
|
|
||||||
// Hook prepares validators M2 for the current epoch
|
// Hook prepares validators M2 for the current epoch at checkpoint block
|
||||||
c.HookValidator = func(header *types.Header, signers []common.Address) error {
|
c.HookValidator = func(header *types.Header, signers []common.Address) ([]byte, error) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
number := header.Number.Int64()
|
validators, err := GetValidators(eth.blockchain, signers)
|
||||||
if number > 0 && number%common.EpocBlockRandomize == 0 {
|
if err != nil {
|
||||||
validators, err := GetValidators(eth.blockchain, signers)
|
return []byte{}, err
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
header.Validators = validators
|
|
||||||
}
|
}
|
||||||
|
header.Validators = validators
|
||||||
log.Debug("Time Calculated HookValidator ", "block", header.Number.Uint64(), "time", common.PrettyDuration(time.Since(start)))
|
log.Debug("Time Calculated HookValidator ", "block", header.Number.Uint64(), "time", common.PrettyDuration(time.Since(start)))
|
||||||
return nil
|
return validators, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hook scans for bad masternodes and decide to penalty them
|
// Hook scans for bad masternodes and decide to penalty them
|
||||||
|
|
|
||||||
|
|
@ -57,12 +57,12 @@ 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, commitTxWhenNotMining bool) *Miner {
|
func New(eth Backend, config *params.ChainConfig, mux *event.TypeMux, engine consensus.Engine, announceTxs bool) *Miner {
|
||||||
miner := &Miner{
|
miner := &Miner{
|
||||||
eth: eth,
|
eth: eth,
|
||||||
mux: mux,
|
mux: mux,
|
||||||
engine: engine,
|
engine: engine,
|
||||||
worker: newWorker(config, engine, common.Address{}, eth, mux, commitTxWhenNotMining),
|
worker: newWorker(config, engine, common.Address{}, eth, mux, announceTxs),
|
||||||
canStart: 1,
|
canStart: 1,
|
||||||
}
|
}
|
||||||
miner.Register(NewCpuAgent(eth.BlockChain(), engine))
|
miner.Register(NewCpuAgent(eth.BlockChain(), engine))
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
// Copyright 2015 The go-ethereum Authors
|
// Copyright 2015 The go-ethereum Authors
|
||||||
// This file is part of the go-ethereum library.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
|
|
@ -55,7 +56,7 @@ const (
|
||||||
// timeout waiting for M1
|
// timeout waiting for M1
|
||||||
waitPeriod = 10
|
waitPeriod = 10
|
||||||
// timeout for checkpoint.
|
// timeout for checkpoint.
|
||||||
waitPeriodCheckpoint = 60
|
waitPeriodCheckpoint = 30
|
||||||
)
|
)
|
||||||
|
|
||||||
// Agent can register themself with the worker
|
// Agent can register themself with the worker
|
||||||
|
|
@ -132,30 +133,30 @@ type worker struct {
|
||||||
// atomic status counters
|
// atomic status counters
|
||||||
mining int32
|
mining int32
|
||||||
atWork int32
|
atWork int32
|
||||||
commitTxWhenNotMining bool
|
announceTxs bool
|
||||||
lastParentBlockCommit string
|
lastParentBlockCommit string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newWorker(config *params.ChainConfig, engine consensus.Engine, coinbase common.Address, eth Backend, mux *event.TypeMux, commitTxWhenNotMining bool) *worker {
|
func newWorker(config *params.ChainConfig, engine consensus.Engine, coinbase common.Address, eth Backend, mux *event.TypeMux, announceTxs bool) *worker {
|
||||||
worker := &worker{
|
worker := &worker{
|
||||||
config: config,
|
config: config,
|
||||||
engine: engine,
|
engine: engine,
|
||||||
eth: eth,
|
eth: eth,
|
||||||
mux: mux,
|
mux: mux,
|
||||||
txCh: make(chan core.TxPreEvent, txChanSize),
|
txCh: make(chan core.TxPreEvent, txChanSize),
|
||||||
chainHeadCh: make(chan core.ChainHeadEvent, chainHeadChanSize),
|
chainHeadCh: make(chan core.ChainHeadEvent, chainHeadChanSize),
|
||||||
chainSideCh: make(chan core.ChainSideEvent, chainSideChanSize),
|
chainSideCh: make(chan core.ChainSideEvent, chainSideChanSize),
|
||||||
chainDb: eth.ChainDb(),
|
chainDb: eth.ChainDb(),
|
||||||
recv: make(chan *Result, resultQueueSize),
|
recv: make(chan *Result, resultQueueSize),
|
||||||
chain: eth.BlockChain(),
|
chain: eth.BlockChain(),
|
||||||
proc: eth.BlockChain().Validator(),
|
proc: eth.BlockChain().Validator(),
|
||||||
possibleUncles: make(map[common.Hash]*types.Block),
|
possibleUncles: make(map[common.Hash]*types.Block),
|
||||||
coinbase: coinbase,
|
coinbase: coinbase,
|
||||||
agents: make(map[Agent]struct{}),
|
agents: make(map[Agent]struct{}),
|
||||||
unconfirmed: newUnconfirmedBlocks(eth.BlockChain(), miningLogAtDepth),
|
unconfirmed: newUnconfirmedBlocks(eth.BlockChain(), miningLogAtDepth),
|
||||||
commitTxWhenNotMining: commitTxWhenNotMining,
|
announceTxs: announceTxs,
|
||||||
}
|
}
|
||||||
if worker.commitTxWhenNotMining {
|
if worker.announceTxs {
|
||||||
// Subscribe TxPreEvent for tx pool
|
// Subscribe TxPreEvent for tx pool
|
||||||
worker.txSub = eth.TxPool().SubscribeTxPreEvent(worker.txCh)
|
worker.txSub = eth.TxPool().SubscribeTxPreEvent(worker.txCh)
|
||||||
}
|
}
|
||||||
|
|
@ -253,7 +254,7 @@ func (self *worker) unregister(agent Agent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *worker) update() {
|
func (self *worker) update() {
|
||||||
if self.commitTxWhenNotMining {
|
if self.announceTxs {
|
||||||
defer self.txSub.Unsubscribe()
|
defer self.txSub.Unsubscribe()
|
||||||
}
|
}
|
||||||
defer self.chainHeadSub.Unsubscribe()
|
defer self.chainHeadSub.Unsubscribe()
|
||||||
|
|
@ -486,7 +487,7 @@ func (self *worker) commitNewWork() {
|
||||||
if parent.Hash().Hex() == self.lastParentBlockCommit {
|
if parent.Hash().Hex() == self.lastParentBlockCommit {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !self.commitTxWhenNotMining && atomic.LoadInt32(&self.mining) == 0 {
|
if !self.announceTxs && atomic.LoadInt32(&self.mining) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -497,7 +498,7 @@ func (self *worker) commitNewWork() {
|
||||||
if self.config.XDPoS != nil {
|
if self.config.XDPoS != nil {
|
||||||
// get masternodes set from latest checkpoint
|
// get masternodes set from latest checkpoint
|
||||||
c := self.engine.(*XDPoS.XDPoS)
|
c := self.engine.(*XDPoS.XDPoS)
|
||||||
len, preIndex, curIndex, ok, err := c.YourTurn(self.chain, parent.Header())
|
len, preIndex, curIndex, ok, err := c.YourTurn(self.chain, parent.Header(),self.coinbase)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed when trying to commit new work", "err", err)
|
log.Error("Failed when trying to commit new work", "err", err)
|
||||||
return
|
return
|
||||||
|
|
@ -518,7 +519,7 @@ func (self *worker) commitNewWork() {
|
||||||
// Check nearest checkpoint block in hop range.
|
// Check nearest checkpoint block in hop range.
|
||||||
nearest := self.config.XDPoS.Epoch - (parent.Header().Number.Uint64() % self.config.XDPoS.Epoch)
|
nearest := self.config.XDPoS.Epoch - (parent.Header().Number.Uint64() % self.config.XDPoS.Epoch)
|
||||||
if uint64(h) >= nearest {
|
if uint64(h) >= nearest {
|
||||||
gap += waitPeriodCheckpoint
|
gap = waitPeriodCheckpoint * int64(h)
|
||||||
}
|
}
|
||||||
log.Info("Distance from the parent block", "seconds", gap, "hops", h)
|
log.Info("Distance from the parent block", "seconds", gap, "hops", h)
|
||||||
waitedTime := time.Now().Unix() - parent.Header().Time.Int64()
|
waitedTime := time.Now().Unix() - parent.Header().Time.Int64()
|
||||||
|
|
@ -553,7 +554,7 @@ func (self *worker) commitNewWork() {
|
||||||
header.Coinbase = self.coinbase
|
header.Coinbase = self.coinbase
|
||||||
}
|
}
|
||||||
if err := self.engine.Prepare(self.chain, header); err != nil {
|
if err := self.engine.Prepare(self.chain, header); err != nil {
|
||||||
log.Error("Failed to prepare header for mining", "err", err)
|
log.Error("Failed to prepare header for new block", "err", err)
|
||||||
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
|
||||||
|
|
@ -617,9 +618,8 @@ func (self *worker) commitNewWork() {
|
||||||
log.Error("Failed to finalize block for sealing", "err", err)
|
log.Error("Failed to finalize block for sealing", "err", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// We only care about logging if we're actually mining.
|
|
||||||
if atomic.LoadInt32(&self.mining) == 1 {
|
if atomic.LoadInt32(&self.mining) == 1 {
|
||||||
log.Info("Commit new mining work", "number", work.Block.Number(), "txs", work.tcount, "special txs", len(specialTxs), "uncles", len(uncles), "elapsed", common.PrettyDuration(time.Since(tstart)))
|
log.Info("Committing new block", "number", work.Block.Number(), "txs", work.tcount, "special txs", len(specialTxs), "uncles", len(uncles), "elapsed", common.PrettyDuration(time.Since(tstart)))
|
||||||
self.unconfirmed.Shift(work.Block.NumberU64() - 1)
|
self.unconfirmed.Shift(work.Block.NumberU64() - 1)
|
||||||
self.lastParentBlockCommit = parent.Hash().Hex()
|
self.lastParentBlockCommit = parent.Hash().Hex()
|
||||||
}
|
}
|
||||||
|
|
@ -741,7 +741,7 @@ func (env *Work) commitTransactions(mux *event.TypeMux, txs *types.TransactionsB
|
||||||
|
|
||||||
case core.ErrNonceTooHigh:
|
case core.ErrNonceTooHigh:
|
||||||
// Reorg notification data race between the transaction pool and miner, skip account =
|
// Reorg notification data race between the transaction pool and miner, skip account =
|
||||||
log.Trace("Skipping account with hight nonce", "sender", from, "nonce", tx.Nonce())
|
log.Trace("Skipping account with high nonce", "sender", from, "nonce", tx.Nonce())
|
||||||
txs.Pop()
|
txs.Pop()
|
||||||
|
|
||||||
case nil:
|
case nil:
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,7 @@ type Config struct {
|
||||||
// Logger is a custom logger to use with the p2p.Server.
|
// Logger is a custom logger to use with the p2p.Server.
|
||||||
Logger log.Logger `toml:",omitempty"`
|
Logger log.Logger `toml:",omitempty"`
|
||||||
|
|
||||||
CommitTxWhenNotMining bool `toml:",omitempty"`
|
AnnounceTxs bool `toml:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IPCEndpoint resolves an IPC endpoint based on a configured value, taking into
|
// IPCEndpoint resolves an IPC endpoint based on a configured value, taking into
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue