mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 02:10:46 +00:00
fixed double validater
This commit is contained in:
parent
8b92c4176c
commit
3f1aadb861
3 changed files with 24 additions and 24 deletions
|
|
@ -572,4 +572,4 @@ func GetM1M2FromCheckpointBlock(checkpointBlock *types.Block) (map[common.Addres
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return m1m2, nil
|
return m1m2, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/consensus"
|
"github.com/ethereum/go-ethereum/consensus"
|
||||||
"github.com/ethereum/go-ethereum/consensus/ethash"
|
"github.com/ethereum/go-ethereum/consensus/ethash"
|
||||||
"github.com/ethereum/go-ethereum/consensus/posv"
|
"github.com/ethereum/go-ethereum/consensus/XDPoS"
|
||||||
"github.com/ethereum/go-ethereum/contracts"
|
"github.com/ethereum/go-ethereum/contracts"
|
||||||
"github.com/ethereum/go-ethereum/contracts/validator/contract"
|
"github.com/ethereum/go-ethereum/contracts/validator/contract"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
|
|
@ -186,8 +186,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
||||||
// Set global ipc endpoint.
|
// Set global ipc endpoint.
|
||||||
eth.blockchain.IPCEndpoint = ctx.GetConfig().IPCEndpoint()
|
eth.blockchain.IPCEndpoint = ctx.GetConfig().IPCEndpoint()
|
||||||
|
|
||||||
if eth.chainConfig.Posv != nil {
|
if eth.chainConfig.XDPoS != nil {
|
||||||
c := eth.engine.(*posv.Posv)
|
c := eth.engine.(*XDPoS.XDPoS)
|
||||||
|
|
||||||
// Hook double validation
|
// Hook double validation
|
||||||
doubleValidateHook := func(block *types.Block) error {
|
doubleValidateHook := func(block *types.Block) error {
|
||||||
|
|
@ -272,7 +272,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
prevEpoc := blockNumberEpoc - chain.Config().Posv.Epoch
|
prevEpoc := blockNumberEpoc - chain.Config().XDPoS.Epoch
|
||||||
if prevEpoc >= 0 {
|
if prevEpoc >= 0 {
|
||||||
prevHeader := chain.GetHeaderByNumber(prevEpoc)
|
prevHeader := chain.GetHeaderByNumber(prevEpoc)
|
||||||
penSigners := c.GetMasternodes(chain, prevHeader)
|
penSigners := c.GetMasternodes(chain, prevHeader)
|
||||||
|
|
@ -314,15 +314,15 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
||||||
log.Error("Fail to connect IPC client for blockSigner", "error", err)
|
log.Error("Fail to connect IPC client for blockSigner", "error", err)
|
||||||
}
|
}
|
||||||
number := header.Number.Uint64()
|
number := header.Number.Uint64()
|
||||||
rCheckpoint := chain.Config().Posv.RewardCheckpoint
|
rCheckpoint := chain.Config().XDPoS.RewardCheckpoint
|
||||||
foudationWalletAddr := chain.Config().Posv.FoudationWalletAddr
|
foudationWalletAddr := chain.Config().XDPoS.FoudationWalletAddr
|
||||||
if foudationWalletAddr == (common.Address{}) {
|
if foudationWalletAddr == (common.Address{}) {
|
||||||
log.Error("Foundation Wallet Address is empty", "error", foudationWalletAddr)
|
log.Error("Foundation Wallet Address is empty", "error", foudationWalletAddr)
|
||||||
}
|
}
|
||||||
if number > 0 && number-rCheckpoint > 0 && foudationWalletAddr != (common.Address{}) {
|
if number > 0 && number-rCheckpoint > 0 && foudationWalletAddr != (common.Address{}) {
|
||||||
// Get signers in blockSigner smartcontract.
|
// Get signers in blockSigner smartcontract.
|
||||||
addr := common.HexToAddress(common.BlockSigners)
|
addr := common.HexToAddress(common.BlockSigners)
|
||||||
chainReward := new(big.Int).Mul(new(big.Int).SetUint64(chain.Config().Posv.Reward), new(big.Int).SetUint64(params.Ether))
|
chainReward := new(big.Int).Mul(new(big.Int).SetUint64(chain.Config().XDPoS.Reward), new(big.Int).SetUint64(params.Ether))
|
||||||
totalSigner := new(uint64)
|
totalSigner := new(uint64)
|
||||||
signers, err := contracts.GetRewardForCheckpoint(chain, addr, number, rCheckpoint, client, totalSigner)
|
signers, err := contracts.GetRewardForCheckpoint(chain, addr, number, rCheckpoint, client, totalSigner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -333,9 +333,9 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
||||||
log.Error("Fail to calculate reward for signers", "error", err)
|
log.Error("Fail to calculate reward for signers", "error", err)
|
||||||
}
|
}
|
||||||
// Get validator.
|
// Get validator.
|
||||||
validator, err := contract.NewTomoValidator(common.HexToAddress(common.MasternodeVotingSMC), client)
|
validator, err := contract.NewXDCValidator(common.HexToAddress(common.MasternodeVotingSMC), client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Fail get instance of Tomo Validator", "error", err)
|
log.Error("Fail get instance of XDC Validator", "error", err)
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -362,7 +362,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !bytes.Equal(header.Validators, validators) {
|
if !bytes.Equal(header.Validators, validators) {
|
||||||
return posv.ErrInvalidCheckpointValidators
|
return XDPoS.ErrInvalidCheckpointValidators
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -372,8 +372,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
|
||||||
return eth, nil
|
return eth, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getM2(snap *posv.Snapshot, eth *Ethereum, block *types.Block) (common.Address, error) {
|
func getM2(snap *XDPoS.Snapshot, eth *Ethereum, block *types.Block) (common.Address, error) {
|
||||||
epoch := eth.chainConfig.Posv.Epoch
|
epoch := eth.chainConfig.XDPoS.Epoch
|
||||||
no := block.NumberU64()
|
no := block.NumberU64()
|
||||||
cpNo := no
|
cpNo := no
|
||||||
if no%epoch != 0 {
|
if no%epoch != 0 {
|
||||||
|
|
@ -387,7 +387,7 @@ func getM2(snap *posv.Snapshot, eth *Ethereum, block *types.Block) (common.Addre
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.Address{}, err
|
return common.Address{}, err
|
||||||
}
|
}
|
||||||
m1, err := posv.WhoIsCreator(snap, block.Header())
|
m1, err := XDPoS.WhoIsCreator(snap, block.Header())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return common.Address{}, err
|
return common.Address{}, err
|
||||||
}
|
}
|
||||||
|
|
@ -426,8 +426,8 @@ func CreateDB(ctx *node.ServiceContext, config *Config, name string) (ethdb.Data
|
||||||
// CreateConsensusEngine creates the required type of consensus engine instance for an Ethereum service
|
// CreateConsensusEngine creates the required type of consensus engine instance for an Ethereum service
|
||||||
func CreateConsensusEngine(ctx *node.ServiceContext, config *ethash.Config, chainConfig *params.ChainConfig, db ethdb.Database) consensus.Engine {
|
func CreateConsensusEngine(ctx *node.ServiceContext, config *ethash.Config, chainConfig *params.ChainConfig, db ethdb.Database) consensus.Engine {
|
||||||
// If proof-of-stake-voting is requested, set it up
|
// If proof-of-stake-voting is requested, set it up
|
||||||
if chainConfig.Posv != nil {
|
if chainConfig.XDPoS != nil {
|
||||||
return posv.New(chainConfig.Posv, db)
|
return XDPoS.New(chainConfig.XDPoS, db)
|
||||||
}
|
}
|
||||||
// Otherwise assume proof-of-work
|
// Otherwise assume proof-of-work
|
||||||
switch {
|
switch {
|
||||||
|
|
@ -553,9 +553,9 @@ func (s *Ethereum) ValidateStaker() (bool, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
if s.chainConfig.Posv != nil {
|
if s.chainConfig.XDPoS != nil {
|
||||||
//check if miner's wallet is in set of validators
|
//check if miner's wallet is in set of validators
|
||||||
c := s.engine.(*posv.Posv)
|
c := s.engine.(*XDPoS.XDPoS)
|
||||||
snap, err := c.GetSnapshot(s.blockchain, s.blockchain.CurrentHeader())
|
snap, err := c.GetSnapshot(s.blockchain, s.blockchain.CurrentHeader())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, fmt.Errorf("Can't verify miner: %v", err)
|
return false, fmt.Errorf("Can't verify miner: %v", err)
|
||||||
|
|
@ -565,7 +565,7 @@ func (s *Ethereum) ValidateStaker() (bool, error) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return false, fmt.Errorf("Only verify miners in Posv protocol")
|
return false, fmt.Errorf("Only verify miners in XDPoS protocol")
|
||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
@ -576,13 +576,13 @@ func (s *Ethereum) StartStaking(local bool) error {
|
||||||
log.Error("Cannot start mining without etherbase", "err", err)
|
log.Error("Cannot start mining without etherbase", "err", err)
|
||||||
return fmt.Errorf("etherbase missing: %v", err)
|
return fmt.Errorf("etherbase missing: %v", err)
|
||||||
}
|
}
|
||||||
if posv, ok := s.engine.(*posv.Posv); ok {
|
if XDPoS, ok := s.engine.(*XDPoS.XDPoS); ok {
|
||||||
wallet, err := s.accountManager.Find(accounts.Account{Address: eb})
|
wallet, err := s.accountManager.Find(accounts.Account{Address: eb})
|
||||||
if wallet == nil || err != nil {
|
if wallet == nil || err != nil {
|
||||||
log.Error("Etherbase account unavailable locally", "err", err)
|
log.Error("Etherbase account unavailable locally", "err", err)
|
||||||
return fmt.Errorf("signer missing: %v", err)
|
return fmt.Errorf("signer missing: %v", err)
|
||||||
}
|
}
|
||||||
posv.Authorize(eb, wallet.SignHash)
|
XDPoS.Authorize(eb, wallet.SignHash)
|
||||||
}
|
}
|
||||||
if local {
|
if local {
|
||||||
// If local (CPU) mining is started, we can disable the transaction rejection
|
// If local (CPU) mining is started, we can disable the transaction rejection
|
||||||
|
|
@ -667,8 +667,8 @@ func (s *Ethereum) Stop() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetValidators(bc *core.BlockChain, masternodes []common.Address) ([]byte, error) {
|
func GetValidators(bc *core.BlockChain, masternodes []common.Address) ([]byte, error) {
|
||||||
if bc.Config().Posv == nil {
|
if bc.Config().XDPoS == nil {
|
||||||
return nil, core.ErrNotPoSV
|
return nil, core.ErrNotXDPoS
|
||||||
}
|
}
|
||||||
client, err := bc.GetClient()
|
client, err := bc.GetClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -318,7 +318,7 @@ func (t *dialTask) Do(srv *Server) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Trace("Dial pair connection sucess", "task", t.dest)
|
log.Trace("Dial pair connection success", "task", t.dest)
|
||||||
} else {
|
} else {
|
||||||
log.Trace("Dial pair connection error", "task", t.dest, "err", err)
|
log.Trace("Dial pair connection error", "task", t.dest, "err", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue