Skip to content

Commit

Permalink
Merge pull request ethereum#74 from benjyz/word-staking
Browse files Browse the repository at this point in the history
staking not mining
  • Loading branch information
ngtuna authored Jul 10, 2018
2 parents 02a1bd2 + 2bd1423 commit d4b7305
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
26 changes: 13 additions & 13 deletions cmd/tomo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(&ethereum); err != nil {
Expand All @@ -299,9 +299,9 @@ 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 {
if threads := ctx.GlobalInt(utils.StakerThreadsFlag.Name); threads > 0 {
type threaded interface {
SetThreads(threads int)
}
Expand All @@ -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)
Expand All @@ -329,15 +329,15 @@ 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 {
if threads := ctx.GlobalInt(utils.StakerThreadsFlag.Name); threads > 0 {
type threaded interface {
SetThreads(threads int)
}
Expand All @@ -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...")
Expand Down
4 changes: 2 additions & 2 deletions cmd/tomo/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions eth/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,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 }
Expand Down

0 comments on commit d4b7305

Please sign in to comment.