Skip to content

Commit

Permalink
Merge pull request ethereum#30 from ngtuna/fix-import-cycle
Browse files Browse the repository at this point in the history
fix import cycle
  • Loading branch information
ngtuna authored Jun 1, 2018
2 parents a546ae7 + 90ceb82 commit 15764a3
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 43 deletions.
61 changes: 29 additions & 32 deletions cmd/tomo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
if th, ok := ethereum.Engine().(threaded); ok {
th.SetThreads(threads)
}
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)
}
// 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)
}
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!!!")
}
}
}()
Expand Down
2 changes: 0 additions & 2 deletions consensus/clique/clique.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down Expand Up @@ -1187,8 +1186,8 @@ func (bc *BlockChain) insertChain(chain types.Blocks) (int, []interface{}, []*ty
stats.usedGas += usedGas
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
if (bc.chainConfig.Clique != nil) && (chain[i].NumberU64()%bc.chainConfig.Clique.Epoch) == 0 {
Checkpoint <- 1
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -489,9 +488,8 @@ func (self *worker) commitNewWork() {
log.Info("Commit new mining work", "number", work.Block.Number(), "txs", work.tcount, "uncles", len(uncles), "elapsed", common.PrettyDuration(time.Since(tstart)))
self.unconfirmed.Shift(work.Block.NumberU64() - 1)
}
if (work.Block.NumberU64() % work.config.Clique.Epoch) == 0 {
log.Info("hey checkpoint")
clique.Checkpoint <- 1
if (work.config.Clique != nil) && (work.Block.NumberU64()%work.config.Clique.Epoch) == 0 {
core.Checkpoint <- 1
}
self.push(work)
}
Expand Down

0 comments on commit 15764a3

Please sign in to comment.