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)
}
// Mining only enabled for validator nodes
if ok, err := ethereum.ValidateMiner(); err != nil {
utils.Fatalf("Can't verify validator permission: %v", err)
} else if !ok {
log.Info("Only validator can mine blocks. Cancel mining on this node")
return
}
go func() {
for {
if ethereum.Checkpoint() {
// Mining only enabled for validator nodes
if ok, err := ethereum.ValidateMiner(); err != nil {
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
if threads := ctx.GlobalInt(utils.MinerThreadsFlag.Name); threads > 0 {
type threaded interface {
SetThreads(threads int)
// Use a reduced number of threads if requested
if threads := ctx.GlobalInt(utils.MinerThreadsFlag.Name); threads > 0 {
type threaded interface {
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
}
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 {
eb, err := s.Etherbase()
if err != nil {