Skip to content

Commit

Permalink
Merge pull request ethereum#444 from ngtuna/validate-mn-testnet
Browse files Browse the repository at this point in the history
separate validateMN func for testnet
  • Loading branch information
ngtuna authored Feb 13, 2019
2 parents 3d52e89 + be6082e commit d53c0a6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 19 deletions.
29 changes: 23 additions & 6 deletions cmd/tomo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/posv"
"github.com/ethereum/go-ethereum/console"
"github.com/ethereum/go-ethereum/core"
Expand Down Expand Up @@ -292,9 +293,18 @@ func startNode(ctx *cli.Context, stack *node.Node, cfg tomoConfig) {
if _, ok := ethereum.Engine().(*posv.Posv); ok {
go func() {
started := false
ok, err := ethereum.ValidateMasternode()
if err != nil {
utils.Fatalf("Can't verify masternode permission: %v", err)
ok := false
var err error
if common.IsTestnet {
ok, err = ethereum.ValidateMasternodeTestnet()
if err != nil {
utils.Fatalf("Can't verify masternode permission: %v", err)
}
} else {
ok, err = ethereum.ValidateMasternode()
if err != nil {
utils.Fatalf("Can't verify masternode permission: %v", err)
}
}
if ok {
log.Info("Masternode found. Enabling staking mode...")
Expand All @@ -318,9 +328,16 @@ func startNode(ctx *cli.Context, stack *node.Node, cfg tomoConfig) {
defer close(core.CheckpointCh)
for range core.CheckpointCh {
log.Info("Checkpoint!!! It's time to reconcile node's state...")
ok, err := ethereum.ValidateMasternode()
if err != nil {
utils.Fatalf("Can't verify masternode permission: %v", err)
if common.IsTestnet {
ok, err = ethereum.ValidateMasternodeTestnet()
if err != nil {
utils.Fatalf("Can't verify masternode permission: %v", err)
}
} else {
ok, err = ethereum.ValidateMasternode()
if err != nil {
utils.Fatalf("Can't verify masternode permission: %v", err)
}
}
if !ok {
if started {
Expand Down
35 changes: 22 additions & 13 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
if err != nil {
return fmt.Errorf("Can't verify masternode permission: %v", err)
}
if !ok && !common.IsTestnet {
if !ok {
// silently return as this node doesn't have masternode permission to sign block
return nil
}
Expand Down Expand Up @@ -580,20 +580,29 @@ func (s *Ethereum) ValidateMasternode() (bool, error) {
} else {
return false, fmt.Errorf("Only verify masternode permission in PoSV protocol")
}
if common.IsTestnet {
masternodes := []common.Address{
common.HexToAddress("0xfFC679Dcdf444D2eEb0491A998E7902B411CcF20"),
common.HexToAddress("0xd76fd76F7101811726DCE9E43C2617706a4c45c8"),
common.HexToAddress("0x8A97753311aeAFACfd76a68Cf2e2a9808d3e65E8"),
}
for _, m := range masternodes {
if m == eb {
return true, nil
}
return true, nil
}

// ValidateMasternodeTestNet checks if node's address is in set of masternodes in Testnet
func (s *Ethereum) ValidateMasternodeTestnet() (bool, error) {
eb, err := s.Etherbase()
if err != nil {
return false, err
}
if s.chainConfig.Posv == nil {
return false, fmt.Errorf("Only verify masternode permission in PoSV protocol")
}
masternodes := []common.Address{
common.HexToAddress("0xfFC679Dcdf444D2eEb0491A998E7902B411CcF20"),
common.HexToAddress("0xd76fd76F7101811726DCE9E43C2617706a4c45c8"),
common.HexToAddress("0x8A97753311aeAFACfd76a68Cf2e2a9808d3e65E8"),
}
for _, m := range masternodes {
if m == eb {
return true, nil
}
return false, nil
}
return true, nil
return false, nil
}

func (s *Ethereum) StartStaking(local bool) error {
Expand Down

0 comments on commit d53c0a6

Please sign in to comment.