From f394faf509326e09d65a78dd930eeed9b5216711 Mon Sep 17 00:00:00 2001 From: benjyz Date: Thu, 5 Jul 2018 11:44:40 +0200 Subject: [PATCH 1/2] staking not mining --- cmd/tomo/main.go | 22 +++++++++++----------- cmd/tomo/usage.go | 4 ++-- cmd/utils/flags.go | 8 ++++---- eth/api.go | 8 ++++---- eth/backend.go | 4 ++-- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/cmd/tomo/main.go b/cmd/tomo/main.go index 82e26a782a..6a1db28ac0 100644 --- a/cmd/tomo/main.go +++ b/cmd/tomo/main.go @@ -99,8 +99,8 @@ var ( utils.MaxPendingPeersFlag, utils.EtherbaseFlag, utils.GasPriceFlag, - utils.MinerThreadsFlag, - utils.MiningEnabledFlag, + utils.StakerThreadsFlag, + utils.StakingEnabledFlag, utils.TargetGasLimitFlag, utils.NATFlag, utils.NoDiscoverFlag, @@ -283,10 +283,10 @@ func startNode(ctx *cli.Context, stack *node.Node) { } }() // Start auxiliary services if enabled - if ctx.GlobalBool(utils.MiningEnabledFlag.Name) || ctx.GlobalBool(utils.DeveloperFlag.Name) { + if ctx.GlobalBool(utils.StakingEnabledFlag.Name) || ctx.GlobalBool(utils.DeveloperFlag.Name) { // Mining only makes sense if a full Ethereum node is running if ctx.GlobalBool(utils.LightModeFlag.Name) || ctx.GlobalString(utils.SyncModeFlag.Name) == "light" { - utils.Fatalf("Light clients do not support mining") + utils.Fatalf("Light clients do not support staking") } var ethereum *eth.Ethereum if err := stack.Service(ðereum); err != nil { @@ -299,7 +299,7 @@ func startNode(ctx *cli.Context, stack *node.Node) { utils.Fatalf("Can't verify validator permission: %v", err) } if ok { - log.Info("Validator found. Enabling mining mode...") + log.Info("Validator found. Enabling staking mode...") // Use a reduced number of threads if requested if threads := ctx.GlobalInt(utils.MinerThreadsFlag.Name); threads > 0 { type threaded interface { @@ -315,7 +315,7 @@ func startNode(ctx *cli.Context, stack *node.Node) { utils.Fatalf("Failed to start staking: %v", err) } started = true - log.Info("Enabled mining node!!!") + log.Info("Enabled staking node!!!") } defer close(core.CheckpointCh) defer close(core.M1Ch) @@ -329,13 +329,13 @@ func startNode(ctx *cli.Context, stack *node.Node) { } if !ok { if started { - log.Info("Only masternode can propose and verify blocks. Cancelling mining on this node...") - ethereum.StopMining() + log.Info("Only masternode can propose and verify blocks. Cancelling staking on this node...") + ethereum.StopStaking() started = false log.Info("Cancelled mining mode!!!") } } else if !started { - log.Info("Masternode found. Enabling mining mode...") + log.Info("Masternode found. Enabling staking mode...") // Use a reduced number of threads if requested if threads := ctx.GlobalInt(utils.MinerThreadsFlag.Name); threads > 0 { type threaded interface { @@ -348,10 +348,10 @@ func startNode(ctx *cli.Context, stack *node.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.StartStaking(true); err != nil { - utils.Fatalf("Failed to start mining: %v", err) + utils.Fatalf("Failed to start staking: %v", err) } started = true - log.Info("Enabled mining node!!!") + log.Info("Enabled staking node!!!") } case <-core.M1Ch: log.Info("It's time to update new set of masternodes for the next epoch...") diff --git a/cmd/tomo/usage.go b/cmd/tomo/usage.go index 6d5ede210d..f2750564d6 100644 --- a/cmd/tomo/usage.go +++ b/cmd/tomo/usage.go @@ -182,8 +182,8 @@ var AppHelpFlagGroups = []flagGroup{ { Name: "MINER", Flags: []cli.Flag{ - utils.MiningEnabledFlag, - utils.MinerThreadsFlag, + utils.StakingEnabledFlag, + utils.StakerThreadsFlag, utils.EtherbaseFlag, utils.TargetGasLimitFlag, utils.GasPriceFlag, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 674c2b5f44..a1ceea6450 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -311,13 +311,13 @@ var ( Value: int(state.MaxTrieCacheGen), } // Miner settings - MiningEnabledFlag = cli.BoolFlag{ + StakingEnabledFlag = cli.BoolFlag{ Name: "mine", - Usage: "Enable mining", + Usage: "Enable staking", } - MinerThreadsFlag = cli.IntFlag{ + StakerThreadsFlag = cli.IntFlag{ Name: "minerthreads", - Usage: "Number of CPU threads to use for mining", + Usage: "Number of CPU threads to use for staking", Value: runtime.NumCPU(), } TargetGasLimitFlag = cli.Uint64Flag{ diff --git a/eth/api.go b/eth/api.go index 24f8f7aaa5..c0dff79341 100644 --- a/eth/api.go +++ b/eth/api.go @@ -81,7 +81,7 @@ func NewPublicMinerAPI(e *Ethereum) *PublicMinerAPI { // Mining returns an indication if this node is currently mining. func (api *PublicMinerAPI) Mining() bool { - return api.e.IsMining() + return api.e.IsStaking() } // SubmitWork can be used by external miner to submit their POW solution. It returns an indication if the work was @@ -95,7 +95,7 @@ func (api *PublicMinerAPI) SubmitWork(nonce types.BlockNonce, solution, digest c // result[1], 32 bytes hex encoded seed hash used for DAG // result[2], 32 bytes hex encoded boundary condition ("target"), 2^256/difficulty func (api *PublicMinerAPI) GetWork() ([3]string, error) { - if !api.e.IsMining() { + if !api.e.IsStaking() { if err := api.e.StartStaking(false); err != nil { return [3]string{}, err } @@ -145,7 +145,7 @@ func (api *PrivateMinerAPI) Start(threads *int) error { th.SetThreads(*threads) } // Start the miner and return - if !api.e.IsMining() { + if !api.e.IsStaking() { // Propagate the initial price point to the transaction pool api.e.lock.RLock() price := api.e.gasPrice @@ -165,7 +165,7 @@ func (api *PrivateMinerAPI) Stop() bool { if th, ok := api.e.engine.(threaded); ok { th.SetThreads(-1) } - api.e.StopMining() + api.e.StopStaking() return true } diff --git a/eth/backend.go b/eth/backend.go index 8e69e5858a..f4cb5bc150 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -460,8 +460,8 @@ func (s *Ethereum) StartStaking(local bool) error { return nil } -func (s *Ethereum) StopMining() { s.miner.Stop() } -func (s *Ethereum) IsMining() bool { return s.miner.Mining() } +func (s *Ethereum) StopStaking() { s.miner.Stop() } +func (s *Ethereum) IsStaking() bool { return s.miner.Mining() } func (s *Ethereum) Miner() *miner.Miner { return s.miner } func (s *Ethereum) AccountManager() *accounts.Manager { return s.accountManager } From 2bd14237ee2dbab6b19a47f7d1dd463494891551 Mon Sep 17 00:00:00 2001 From: benjyz Date: Thu, 5 Jul 2018 12:48:16 +0200 Subject: [PATCH 2/2] fix flags --- cmd/tomo/main.go | 4 ++-- cmd/utils/flags.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/tomo/main.go b/cmd/tomo/main.go index 6a1db28ac0..8963de950c 100644 --- a/cmd/tomo/main.go +++ b/cmd/tomo/main.go @@ -301,7 +301,7 @@ func startNode(ctx *cli.Context, stack *node.Node) { if ok { log.Info("Validator found. Enabling staking mode...") // Use a reduced number of threads if requested - if threads := ctx.GlobalInt(utils.MinerThreadsFlag.Name); threads > 0 { + if threads := ctx.GlobalInt(utils.StakerThreadsFlag.Name); threads > 0 { type threaded interface { SetThreads(threads int) } @@ -337,7 +337,7 @@ func startNode(ctx *cli.Context, stack *node.Node) { } else if !started { log.Info("Masternode found. Enabling staking mode...") // Use a reduced number of threads if requested - if threads := ctx.GlobalInt(utils.MinerThreadsFlag.Name); threads > 0 { + if threads := ctx.GlobalInt(utils.StakerThreadsFlag.Name); threads > 0 { type threaded interface { SetThreads(threads int) } diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index a1ceea6450..998db9dccf 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1054,8 +1054,8 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *eth.Config) { if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheGCFlag.Name) { cfg.TrieCache = ctx.GlobalInt(CacheFlag.Name) * ctx.GlobalInt(CacheGCFlag.Name) / 100 } - if ctx.GlobalIsSet(MinerThreadsFlag.Name) { - cfg.MinerThreads = ctx.GlobalInt(MinerThreadsFlag.Name) + if ctx.GlobalIsSet(StakerThreadsFlag.Name) { + cfg.MinerThreads = ctx.GlobalInt(StakerThreadsFlag.Name) } if ctx.GlobalIsSet(DocRootFlag.Name) { cfg.DocRoot = ctx.GlobalString(DocRootFlag.Name)