added MINING PERMISSION EVERY EPOCH BLOCK +1

This commit is contained in:
AnilChinchawale 2018-06-22 14:14:13 +05:30
parent d06703c251
commit 2cde3e9fe8
2 changed files with 33 additions and 20 deletions

View file

@ -290,27 +290,35 @@ func startNode(ctx *cli.Context, stack *node.Node) {
utils.Fatalf("Ethereum service not running: %v", err) utils.Fatalf("Ethereum service not running: %v", err)
} }
// Mining only enabled for validator nodes go func() {
if ok, err := ethereum.ValidateMiner(); err != nil { for {
utils.Fatalf("Can't verify validator permission: %v", err) if ethereum.Checkpoint() {
} else if !ok { // Mining only enabled for validator nodes
log.Info("Only validator can mine blocks. Cancel mining on this node") if ok, err := ethereum.ValidateMiner(); err != nil {
return utils.Fatalf("Can't verify validator permission: %v", err)
} } else if !ok {
log.Info("Only validator can mine blocks. Cancel mining on this node")
ethereum.StopMining()
continue
}
// Use a reduced number of threads if requested // Use a reduced number of threads if requested
if threads := ctx.GlobalInt(utils.MinerThreadsFlag.Name); threads > 0 { if threads := ctx.GlobalInt(utils.MinerThreadsFlag.Name); threads > 0 {
type threaded interface { type threaded interface {
SetThreads(threads int) SetThreads(threads int)
}
if th, ok := ethereum.Engine().(threaded); ok {
th.SetThreads(threads)
}
}
// Set the gas price to the limits from the CLI and start mining
ethereum.TxPool().SetGasPrice(utils.GlobalBig(ctx, utils.GasPriceFlag.Name))
if err := ethereum.StartMining(true); err != nil {
utils.Fatalf("Failed to start mining: %v", err)
}
}
} }
if th, ok := ethereum.Engine().(threaded); ok { }()
th.SetThreads(threads)
}
}
// Set the gas price to the limits from the CLI and start mining
ethereum.TxPool().SetGasPrice(utils.GlobalBig(ctx, utils.GasPriceFlag.Name))
if err := ethereum.StartMining(true); err != nil {
utils.Fatalf("Failed to start mining: %v", err)
}
} }
} }

View file

@ -356,6 +356,11 @@ func (s *Ethereum) ValidateMiner() (bool, error) {
return true, nil return true, nil
} }
func (s *Ethereum) Checkpoint() bool {
number := s.blockchain.CurrentHeader().Number.Uint64()
return number%s.chainConfig.Clique.Epoch == 1
}
func (s *Ethereum) StartMining(local bool) error { func (s *Ethereum) StartMining(local bool) error {
eb, err := s.Etherbase() eb, err := s.Etherbase()
if err != nil { if err != nil {