From 4ceb65f9a5f36101498e42fb4ae94d8b1a643960 Mon Sep 17 00:00:00 2001 From: Tuna Date: Thu, 6 Sep 2018 10:45:10 +0700 Subject: [PATCH] fix unit tests --- cmd/tomo/main.go | 125 +++++++++++++++++++++++---------------------- core/blockchain.go | 2 +- 2 files changed, 65 insertions(+), 62 deletions(-) diff --git a/cmd/tomo/main.go b/cmd/tomo/main.go index c68c62376d..7d3b328416 100644 --- a/cmd/tomo/main.go +++ b/cmd/tomo/main.go @@ -27,6 +27,7 @@ import ( "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts/keystore" "github.com/ethereum/go-ethereum/cmd/utils" + "github.com/ethereum/go-ethereum/consensus/posv" "github.com/ethereum/go-ethereum/console" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/eth" @@ -293,73 +294,75 @@ func startNode(ctx *cli.Context, stack *node.Node, cfg tomoConfig) { if err := stack.Service(ðereum); err != nil { utils.Fatalf("Ethereum service not running: %v", err) } - go func() { - started := false - ok, err := ethereum.ValidateStaker() - if err != nil { - utils.Fatalf("Can't verify validator permission: %v", err) - } - if ok { - log.Info("Validator found. Enabling staking mode...") - // Use a reduced number of threads if requested - if threads := ctx.GlobalInt(utils.StakerThreadsFlag.Name); threads > 0 { - type threaded interface { - SetThreads(threads int) - } - if th, ok := ethereum.Engine().(threaded); ok { - th.SetThreads(threads) - } + if _, ok := ethereum.Engine().(*posv.Posv); ok { + go func() { + started := false + ok, err := ethereum.ValidateStaker() + if err != nil { + utils.Fatalf("Can't verify validator permission: %v", err) } - // Set the gas price to the limits from the CLI and start mining - ethereum.TxPool().SetGasPrice(cfg.Eth.GasPrice) - if err := ethereum.StartStaking(true); err != nil { - utils.Fatalf("Failed to start staking: %v", err) - } - started = true - log.Info("Enabled staking node!!!") - } - defer close(core.CheckpointCh) - defer close(core.M1Ch) - for { - select { - case <-core.CheckpointCh: - log.Info("Checkpoint!!! It's time to reconcile node's state...") - ok, err := ethereum.ValidateStaker() - if err != nil { - utils.Fatalf("Can't verify masternode permission: %v", err) - } - if !ok { - if started { - log.Info("Only masternode can propose and verify blocks. Cancelling staking on this node...") - ethereum.StopStaking() - started = false - log.Info("Cancelled mining mode!!!") + if ok { + log.Info("Validator found. Enabling staking mode...") + // Use a reduced number of threads if requested + if threads := ctx.GlobalInt(utils.StakerThreadsFlag.Name); threads > 0 { + type threaded interface { + SetThreads(threads int) } - } else if !started { - log.Info("Masternode found. Enabling staking mode...") - // Use a reduced number of threads if requested - if threads := ctx.GlobalInt(utils.StakerThreadsFlag.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(cfg.Eth.GasPrice) + if err := ethereum.StartStaking(true); err != nil { + utils.Fatalf("Failed to start staking: %v", err) + } + started = true + log.Info("Enabled staking node!!!") + } + defer close(core.CheckpointCh) + defer close(core.M1Ch) + for { + select { + case <-core.CheckpointCh: + log.Info("Checkpoint!!! It's time to reconcile node's state...") + ok, err := ethereum.ValidateStaker() + if err != nil { + utils.Fatalf("Can't verify masternode permission: %v", err) + } + if !ok { + if started { + log.Info("Only masternode can propose and verify blocks. Cancelling staking on this node...") + ethereum.StopStaking() + started = false + log.Info("Cancelled mining mode!!!") } - if th, ok := ethereum.Engine().(threaded); ok { - th.SetThreads(threads) + } else if !started { + log.Info("Masternode found. Enabling staking mode...") + // Use a reduced number of threads if requested + if threads := ctx.GlobalInt(utils.StakerThreadsFlag.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(cfg.Eth.GasPrice) + if err := ethereum.StartStaking(true); err != nil { + utils.Fatalf("Failed to start staking: %v", err) + } + started = true + log.Info("Enabled staking node!!!") } - // Set the gas price to the limits from the CLI and start mining - ethereum.TxPool().SetGasPrice(cfg.Eth.GasPrice) - if err := ethereum.StartStaking(true); err != nil { - utils.Fatalf("Failed to start staking: %v", err) + case <-core.M1Ch: + err := ethereum.BlockChain().UpdateM1() + if err != nil { + log.Error("Error when update M1", err) } - started = true - log.Info("Enabled staking node!!!") - } - case <-core.M1Ch: - err := ethereum.BlockChain().UpdateM1() - if err != nil { - log.Error("Error when update M1", err) } } - } - }() + }() + } } diff --git a/core/blockchain.go b/core/blockchain.go index 78a1a53be3..ff234c4b5b 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -698,7 +698,7 @@ func (bc *BlockChain) procFutureBlocks() { type WriteStatus byte const ( - NonStatTy WriteStatus = iota + NonStatTy WriteStatus = iota CanonStatTy SideStatTy )