diff --git a/cmd/tomo/config.go b/cmd/tomo/config.go index 6fc12571e7..51d6bf8869 100644 --- a/cmd/tomo/config.go +++ b/cmd/tomo/config.go @@ -36,6 +36,7 @@ import ( "github.com/ethereum/go-ethereum/params" whisper "github.com/ethereum/go-ethereum/whisper/whisperv6" "github.com/naoina/toml" + "github.com/ethereum/go-ethereum/common" ) var ( @@ -151,6 +152,11 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, tomoConfig) { ctx.Set(utils.NATFlag.Name, cfg.NAT) } + // Check testnet is enable. + if ctx.GlobalBool(utils.TomoTestnetFlag.Name) { + common.IsTestnet = true + } + // read passwords from environment passwords := []string{} for _, env := range cfg.Account.Passwords { diff --git a/cmd/tomo/main.go b/cmd/tomo/main.go index 9a125d0485..751c4babf0 100644 --- a/cmd/tomo/main.go +++ b/cmd/tomo/main.go @@ -109,6 +109,7 @@ var ( //utils.TestnetFlag, //utils.RinkebyFlag, //utils.VMEnableDebugFlag, + utils.TomoTestnetFlag, utils.NetworkIdFlag, utils.RPCCORSDomainFlag, utils.RPCVirtualHostsFlag, diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index f158819e42..a33380d9ff 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -139,6 +139,10 @@ var ( Name: "testnet", Usage: "Ropsten network: pre-configured proof-of-work test network", } + TomoTestnetFlag = cli.BoolFlag{ + Name: "tomo-testnet", + Usage: "Tomo test network", + } RinkebyFlag = cli.BoolFlag{ Name: "rinkeby", Usage: "Rinkeby network: pre-configured proof-of-authority test network", diff --git a/common/constants.go b/common/constants.go index 0571a8cf11..89ded09a84 100644 --- a/common/constants.go +++ b/common/constants.go @@ -16,3 +16,5 @@ const ( LimitThresholdNonceInQueue = 10 MinGasPrice = 2500 ) + +var IsTestnet bool = false diff --git a/consensus/posv/posv.go b/consensus/posv/posv.go index 66daca10a6..3bf49e95ae 100644 --- a/consensus/posv/posv.go +++ b/consensus/posv/posv.go @@ -45,8 +45,8 @@ import ( ) const ( - inmemorySnapshots = 128 // Number of recent vote snapshots to keep in memory - M2ByteLength = 4 + inmemorySnapshots = 128 // Number of recent vote snapshots to keep in memory + M2ByteLength = 4 ) type Masternode struct { @@ -476,7 +476,11 @@ func whoIsCreator(snap *Snapshot, header *types.Header) (common.Address, error) func (c *Posv) YourTurn(chain consensus.ChainReader, parent *types.Header, signer common.Address) (int, int, int, bool, error) { masternodes := c.GetMasternodes(chain, parent) - masternodes = masternodes[:len(masternodes)/2+1] + if common.IsTestnet { + // Only three mns for tomo testnet. + masternodes = masternodes[:3] + } + log.Error("masternodes", "masternodes", len(masternodes)) snap, err := c.GetSnapshot(chain, parent) if err != nil { log.Warn("Failed when trying to commit new work", "err", err)