diff --git a/cmd/tomo/main.go b/cmd/tomo/main.go index 60442de7e6..1faa8e331a 100644 --- a/cmd/tomo/main.go +++ b/cmd/tomo/main.go @@ -29,8 +29,8 @@ import ( "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/consensus/clique" "github.com/ethereum/go-ethereum/console" + "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/internal/debug" @@ -316,42 +316,39 @@ func startNode(ctx *cli.Context, stack *node.Node) { started = true log.Info("Enabled mining node!!!") } - defer close(clique.Checkpoint) + defer close(core.Checkpoint) - for { - select { - case _ = <-clique.Checkpoint: - log.Info("Checkpoint!!! It's time to reconcile node's state...") - ok, err := ethereum.ValidateMiner() - if err != nil { - utils.Fatalf("Can't verify validator permission: %v", err) + for range core.Checkpoint { + log.Info("Checkpoint!!! It's time to reconcile node's state...") + ok, err := ethereum.ValidateMiner() + if err != nil { + utils.Fatalf("Can't verify validator permission: %v", err) + } + if !ok { + log.Info("Only validator can mine blocks. Cancelling mining on this node...") + if started { + ethereum.StopMining() + started = false } - if !ok { - log.Info("Only validator can mine blocks. Cancelling mining on this node...") - if started { - ethereum.StopMining() - started = false + log.Info("Cancelled mining mode!!!") + } else if !started { + log.Info("Validator found. Enabling mining mode...") + // Use a reduced number of threads if requested + if threads := ctx.GlobalInt(utils.MinerThreadsFlag.Name); threads > 0 { + type threaded interface { + SetThreads(threads int) } - log.Info("Cancelled mining mode!!!") - } else if !started { - log.Info("Validator found. Enabling mining mode...") - // 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) - } + 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) - } - started = true - log.Info("Enabled mining node!!!") } + // 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) + } + started = true + log.Info("Enabled mining node!!!") } } }() diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index 60c0ec4b1d..13e8bb878e 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -65,7 +65,6 @@ var ( diffInTurn = big.NewInt(2) // Block difficulty for in-turn signatures diffNoTurn = big.NewInt(1) // Block difficulty for out-of-turn signatures - Checkpoint chan int ) // Various error messages to mark blocks invalid. These should be private to @@ -217,7 +216,6 @@ func New(config *params.CliqueConfig, db ethdb.Database) *Clique { if conf.Epoch == 0 { conf.Epoch = epochLength } - Checkpoint = make(chan int) // Allocate the snapshot caches and create the engine recents, _ := lru.NewARC(inmemorySnapshots) signatures, _ := lru.NewARC(inmemorySignatures) diff --git a/core/blockchain.go b/core/blockchain.go index ba13c23192..64f20b5840 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -30,7 +30,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/mclock" "github.com/ethereum/go-ethereum/consensus" - "github.com/ethereum/go-ethereum/consensus/clique" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" @@ -48,8 +47,8 @@ import ( var ( blockInsertTimer = metrics.NewRegisteredTimer("chain/inserts", nil) - - ErrNoGenesis = errors.New("Genesis not found in chain") + Checkpoint = make(chan int) + ErrNoGenesis = errors.New("Genesis not found in chain") ) const ( @@ -1188,7 +1187,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks) (int, []interface{}, []*ty stats.report(chain, i, bc.stateCache.TrieDB().Size()) if i == len(chain)-1 { if (chain[i].NumberU64() % bc.chainConfig.Clique.Epoch) == 0 { - clique.Checkpoint <- 1 + Checkpoint <- 1 } } } diff --git a/miner/worker.go b/miner/worker.go index e2ef0f5ad4..6062affc01 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -26,7 +26,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/consensus" - "github.com/ethereum/go-ethereum/consensus/clique" "github.com/ethereum/go-ethereum/consensus/misc" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/state" @@ -491,7 +490,7 @@ func (self *worker) commitNewWork() { } if (work.Block.NumberU64() % work.config.Clique.Epoch) == 0 { log.Info("hey checkpoint") - clique.Checkpoint <- 1 + core.Checkpoint <- 1 } self.push(work) }