mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
separate validateMN func
This commit is contained in:
parent
3d52e89dd8
commit
be6082e77f
2 changed files with 46 additions and 20 deletions
|
|
@ -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"
|
||||
|
|
@ -292,10 +293,19 @@ 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()
|
||||
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...")
|
||||
// Use a reduced number of threads if requested
|
||||
|
|
@ -318,10 +328,17 @@ 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 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 {
|
||||
log.Info("Only masternode can propose and verify blocks. Cancelling staking on this node...")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -580,7 +580,18 @@ func (s *Ethereum) ValidateMasternode() (bool, error) {
|
|||
} else {
|
||||
return false, fmt.Errorf("Only verify masternode permission in PoSV protocol")
|
||||
}
|
||||
if common.IsTestnet {
|
||||
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"),
|
||||
|
|
@ -592,8 +603,6 @@ func (s *Ethereum) ValidateMasternode() (bool, error) {
|
|||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (s *Ethereum) StartStaking(local bool) error {
|
||||
|
|
|
|||
Loading…
Reference in a new issue