staking not mining

This commit is contained in:
AnilChinchawale 2018-10-21 16:42:10 +05:30
parent 264a6dc9db
commit 77ac77cdb1
5 changed files with 25 additions and 25 deletions

View file

@ -99,8 +99,8 @@ var (
utils.MaxPendingPeersFlag, utils.MaxPendingPeersFlag,
utils.EtherbaseFlag, utils.EtherbaseFlag,
utils.GasPriceFlag, utils.GasPriceFlag,
utils.MinerThreadsFlag, utils.StakerThreadsFlag,
utils.MiningEnabledFlag, utils.StakingEnabledFlag,
utils.TargetGasLimitFlag, utils.TargetGasLimitFlag,
utils.NATFlag, utils.NATFlag,
utils.NoDiscoverFlag, utils.NoDiscoverFlag,
@ -283,10 +283,10 @@ func startNode(ctx *cli.Context, stack *node.Node) {
} }
}() }()
// Start auxiliary services if enabled // 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 // Mining only makes sense if a full Ethereum node is running
if ctx.GlobalBool(utils.LightModeFlag.Name) || ctx.GlobalString(utils.SyncModeFlag.Name) == "light" { 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 var ethereum *eth.Ethereum
if err := stack.Service(&ethereum); err != nil { if err := stack.Service(&ethereum); err != nil {
@ -299,9 +299,9 @@ func startNode(ctx *cli.Context, stack *node.Node) {
utils.Fatalf("Can't verify validator permission: %v", err) utils.Fatalf("Can't verify validator permission: %v", err)
} }
if ok { if ok {
log.Info("Validator found. Enabling mining mode...") log.Info("Validator found. Enabling staking mode...")
// Use a reduced number of threads if requested // 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 { type threaded interface {
SetThreads(threads int) SetThreads(threads int)
} }
@ -315,7 +315,7 @@ func startNode(ctx *cli.Context, stack *node.Node) {
utils.Fatalf("Failed to start staking: %v", err) utils.Fatalf("Failed to start staking: %v", err)
} }
started = true started = true
log.Info("Enabled mining node!!!") log.Info("Enabled staking node!!!")
} }
defer close(core.CheckpointCh) defer close(core.CheckpointCh)
defer close(core.M1Ch) defer close(core.M1Ch)
@ -329,15 +329,15 @@ func startNode(ctx *cli.Context, stack *node.Node) {
} }
if !ok { if !ok {
if started { if started {
log.Info("Only masternode can propose and verify blocks. Cancelling mining on this node...") log.Info("Only masternode can propose and verify blocks. Cancelling staking on this node...")
ethereum.StopMining() ethereum.StopStaking()
started = false started = false
log.Info("Cancelled mining mode!!!") log.Info("Cancelled mining mode!!!")
} }
} else if !started { } 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 // 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 { type threaded interface {
SetThreads(threads int) SetThreads(threads int)
} }
@ -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 // Set the gas price to the limits from the CLI and start mining
ethereum.TxPool().SetGasPrice(utils.GlobalBig(ctx, utils.GasPriceFlag.Name)) ethereum.TxPool().SetGasPrice(utils.GlobalBig(ctx, utils.GasPriceFlag.Name))
if err := ethereum.StartStaking(true); err != nil { 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 started = true
log.Info("Enabled mining node!!!") log.Info("Enabled staking node!!!")
} }
case <-core.M1Ch: case <-core.M1Ch:
log.Info("It's time to update new set of masternodes for the next epoch...") log.Info("It's time to update new set of masternodes for the next epoch...")

View file

@ -182,8 +182,8 @@ var AppHelpFlagGroups = []flagGroup{
{ {
Name: "MINER", Name: "MINER",
Flags: []cli.Flag{ Flags: []cli.Flag{
utils.MiningEnabledFlag, utils.StakingEnabledFlag,
utils.MinerThreadsFlag, utils.StakerThreadsFlag,
utils.EtherbaseFlag, utils.EtherbaseFlag,
utils.TargetGasLimitFlag, utils.TargetGasLimitFlag,
utils.GasPriceFlag, utils.GasPriceFlag,

View file

@ -311,13 +311,13 @@ var (
Value: int(state.MaxTrieCacheGen), Value: int(state.MaxTrieCacheGen),
} }
// Miner settings // Miner settings
MiningEnabledFlag = cli.BoolFlag{ StakingEnabledFlag = cli.BoolFlag{
Name: "mine", Name: "mine",
Usage: "Enable mining", Usage: "Enable staking",
} }
MinerThreadsFlag = cli.IntFlag{ StakerThreadsFlag = cli.IntFlag{
Name: "minerthreads", Name: "minerthreads",
Usage: "Number of CPU threads to use for mining", Usage: "Number of CPU threads to use for staking",
Value: runtime.NumCPU(), Value: runtime.NumCPU(),
} }
TargetGasLimitFlag = cli.Uint64Flag{ TargetGasLimitFlag = cli.Uint64Flag{

View file

@ -81,7 +81,7 @@ func NewPublicMinerAPI(e *Ethereum) *PublicMinerAPI {
// Mining returns an indication if this node is currently mining. // Mining returns an indication if this node is currently mining.
func (api *PublicMinerAPI) Mining() bool { 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 // 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[1], 32 bytes hex encoded seed hash used for DAG
// result[2], 32 bytes hex encoded boundary condition ("target"), 2^256/difficulty // result[2], 32 bytes hex encoded boundary condition ("target"), 2^256/difficulty
func (api *PublicMinerAPI) GetWork() ([3]string, error) { func (api *PublicMinerAPI) GetWork() ([3]string, error) {
if !api.e.IsMining() { if !api.e.IsStaking() {
if err := api.e.StartStaking(false); err != nil { if err := api.e.StartStaking(false); err != nil {
return [3]string{}, err return [3]string{}, err
} }
@ -145,7 +145,7 @@ func (api *PrivateMinerAPI) Start(threads *int) error {
th.SetThreads(*threads) th.SetThreads(*threads)
} }
// Start the miner and return // Start the miner and return
if !api.e.IsMining() { if !api.e.IsStaking() {
// Propagate the initial price point to the transaction pool // Propagate the initial price point to the transaction pool
api.e.lock.RLock() api.e.lock.RLock()
price := api.e.gasPrice price := api.e.gasPrice
@ -165,7 +165,7 @@ func (api *PrivateMinerAPI) Stop() bool {
if th, ok := api.e.engine.(threaded); ok { if th, ok := api.e.engine.(threaded); ok {
th.SetThreads(-1) th.SetThreads(-1)
} }
api.e.StopMining() api.e.StopStaking()
return true return true
} }

View file

@ -471,8 +471,8 @@ func (s *Ethereum) StartStaking(local bool) error {
return nil return nil
} }
func (s *Ethereum) StopMining() { s.miner.Stop() } func (s *Ethereum) StopStaking() { s.miner.Stop() }
func (s *Ethereum) IsMining() bool { return s.miner.Mining() } func (s *Ethereum) IsStaking() bool { return s.miner.Mining() }
func (s *Ethereum) Miner() *miner.Miner { return s.miner } func (s *Ethereum) Miner() *miner.Miner { return s.miner }
func (s *Ethereum) AccountManager() *accounts.Manager { return s.accountManager } func (s *Ethereum) AccountManager() *accounts.Manager { return s.accountManager }