mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +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"
|
||||||
"github.com/ethereum/go-ethereum/accounts/keystore"
|
"github.com/ethereum/go-ethereum/accounts/keystore"
|
||||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
"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/consensus/posv"
|
||||||
"github.com/ethereum/go-ethereum/console"
|
"github.com/ethereum/go-ethereum/console"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"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 {
|
if _, ok := ethereum.Engine().(*posv.Posv); ok {
|
||||||
go func() {
|
go func() {
|
||||||
started := false
|
started := false
|
||||||
ok, err := ethereum.ValidateMasternode()
|
ok := false
|
||||||
|
var err error
|
||||||
|
if common.IsTestnet {
|
||||||
|
ok, err = ethereum.ValidateMasternodeTestnet()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
utils.Fatalf("Can't verify masternode permission: %v", err)
|
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 ok {
|
||||||
log.Info("Masternode found. Enabling staking mode...")
|
log.Info("Masternode found. Enabling staking mode...")
|
||||||
// Use a reduced number of threads if requested
|
// 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)
|
defer close(core.CheckpointCh)
|
||||||
for range core.CheckpointCh {
|
for range core.CheckpointCh {
|
||||||
log.Info("Checkpoint!!! It's time to reconcile node's state...")
|
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 {
|
if err != nil {
|
||||||
utils.Fatalf("Can't verify masternode permission: %v", err)
|
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 !ok {
|
||||||
if started {
|
if started {
|
||||||
log.Info("Only masternode can propose and verify blocks. Cancelling staking on this node...")
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("Can't verify masternode permission: %v", err)
|
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
|
// silently return as this node doesn't have masternode permission to sign block
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -580,7 +580,18 @@ func (s *Ethereum) ValidateMasternode() (bool, error) {
|
||||||
} else {
|
} else {
|
||||||
return false, fmt.Errorf("Only verify masternode permission in PoSV protocol")
|
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{
|
masternodes := []common.Address{
|
||||||
common.HexToAddress("0xfFC679Dcdf444D2eEb0491A998E7902B411CcF20"),
|
common.HexToAddress("0xfFC679Dcdf444D2eEb0491A998E7902B411CcF20"),
|
||||||
common.HexToAddress("0xd76fd76F7101811726DCE9E43C2617706a4c45c8"),
|
common.HexToAddress("0xd76fd76F7101811726DCE9E43C2617706a4c45c8"),
|
||||||
|
|
@ -593,8 +604,6 @@ func (s *Ethereum) ValidateMasternode() (bool, error) {
|
||||||
}
|
}
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Ethereum) StartStaking(local bool) error {
|
func (s *Ethereum) StartStaking(local bool) error {
|
||||||
eb, err := s.Etherbase()
|
eb, err := s.Etherbase()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue