mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-20 13:44:31 +00:00
added MINING PERMISSION EVERY EPOCH BLOCK +1
This commit is contained in:
parent
d06703c251
commit
2cde3e9fe8
2 changed files with 33 additions and 20 deletions
|
|
@ -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)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue