mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-16 18:00:46 +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)
|
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)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue