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,12 +290,16 @@ func startNode(ctx *cli.Context, stack *node.Node) {
utils.Fatalf("Ethereum service not running: %v", err) utils.Fatalf("Ethereum service not running: %v", err)
} }
go func() {
for {
if ethereum.Checkpoint() {
// Mining only enabled for validator nodes // Mining only enabled for validator nodes
if ok, err := ethereum.ValidateMiner(); err != nil { if ok, err := ethereum.ValidateMiner(); err != nil {
utils.Fatalf("Can't verify validator permission: %v", err) utils.Fatalf("Can't verify validator permission: %v", err)
} else if !ok { } else if !ok {
log.Info("Only validator can mine blocks. Cancel mining on this node") log.Info("Only validator can mine blocks. Cancel mining on this node")
return ethereum.StopMining()
continue
} }
// Use a reduced number of threads if requested // Use a reduced number of threads if requested
@ -313,4 +317,8 @@ func startNode(ctx *cli.Context, stack *node.Node) {
utils.Fatalf("Failed to start mining: %v", err) 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 {