Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add slave mode #17

Merged
merged 1 commit into from
Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 40 additions & 28 deletions cmd/tomo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ var (
utils.AnnounceTxsFlag,
utils.StoreRewardFlag,
utils.RollbackFlag,
utils.TomoSlaveModeFlag,
}

rpcFlags = []cli.Flag{
Expand Down Expand Up @@ -296,6 +297,7 @@ func startNode(ctx *cli.Context, stack *node.Node, cfg tomoConfig) {
go func() {
started := false
ok := false
slaveMode := ctx.GlobalIsSet(utils.TomoSlaveModeFlag.Name)
var err error
if common.IsTestnet {
ok, err = ethereum.ValidateMasternodeTestnet()
Expand All @@ -309,23 +311,28 @@ func startNode(ctx *cli.Context, stack *node.Node, cfg tomoConfig) {
}
}
if ok {
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 slaveMode {
log.Info("Masternode slave mode found.")
started = false
} else {
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)
}
}
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)
}
started = true
log.Info("Enabled staking node!!!")
}
defer close(core.CheckpointCh)
for range core.CheckpointCh {
Expand All @@ -349,23 +356,28 @@ func startNode(ctx *cli.Context, stack *node.Node, cfg tomoConfig) {
log.Info("Cancelled mining mode!!!")
}
} 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 slaveMode {
log.Info("Masternode slave mode found.")
started = false
} else {
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)
}
}
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)
}
started = true
log.Info("Enabled staking node!!!")
}
}
}()
Expand Down
4 changes: 4 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,10 @@ var (
Name: "tomox.dbReplicaSetName",
Usage: "ReplicaSetName if Master-Slave is setup",
}
TomoSlaveModeFlag = cli.BoolFlag{
Name: "slave",
Usage: "Enable slave mode",
}
)

// MakeDataDir retrieves the currently requested data directory, terminating
Expand Down