fixed double validater

This commit is contained in:
AnilChinchwale 2018-11-09 15:43:29 +05:30
parent 8b92c4176c
commit 3f1aadb861
3 changed files with 24 additions and 24 deletions

View file

@ -572,4 +572,4 @@ func GetM1M2FromCheckpointBlock(checkpointBlock *types.Block) (map[common.Addres
}
}
return m1m2, nil
}
}

View file

@ -32,7 +32,7 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus"
"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/validator/contract"
"github.com/ethereum/go-ethereum/core"
@ -186,8 +186,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
// Set global ipc endpoint.
eth.blockchain.IPCEndpoint = ctx.GetConfig().IPCEndpoint()
if eth.chainConfig.Posv != nil {
c := eth.engine.(*posv.Posv)
if eth.chainConfig.XDPoS != nil {
c := eth.engine.(*XDPoS.XDPoS)
// Hook double validation
doubleValidateHook := func(block *types.Block) error {
@ -272,7 +272,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
if err != nil {
return nil, err
}
prevEpoc := blockNumberEpoc - chain.Config().Posv.Epoch
prevEpoc := blockNumberEpoc - chain.Config().XDPoS.Epoch
if prevEpoc >= 0 {
prevHeader := chain.GetHeaderByNumber(prevEpoc)
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)
}
number := header.Number.Uint64()
rCheckpoint := chain.Config().Posv.RewardCheckpoint
foudationWalletAddr := chain.Config().Posv.FoudationWalletAddr
rCheckpoint := chain.Config().XDPoS.RewardCheckpoint
foudationWalletAddr := chain.Config().XDPoS.FoudationWalletAddr
if foudationWalletAddr == (common.Address{}) {
log.Error("Foundation Wallet Address is empty", "error", foudationWalletAddr)
}
if number > 0 && number-rCheckpoint > 0 && foudationWalletAddr != (common.Address{}) {
// Get signers in blockSigner smartcontract.
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)
signers, err := contracts.GetRewardForCheckpoint(chain, addr, number, rCheckpoint, client, totalSigner)
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)
}
// Get validator.
validator, err := contract.NewTomoValidator(common.HexToAddress(common.MasternodeVotingSMC), client)
validator, err := contract.NewXDCValidator(common.HexToAddress(common.MasternodeVotingSMC), client)
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
}
@ -362,7 +362,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
return err
}
if !bytes.Equal(header.Validators, validators) {
return posv.ErrInvalidCheckpointValidators
return XDPoS.ErrInvalidCheckpointValidators
}
}
return nil
@ -372,8 +372,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) {
return eth, nil
}
func getM2(snap *posv.Snapshot, eth *Ethereum, block *types.Block) (common.Address, error) {
epoch := eth.chainConfig.Posv.Epoch
func getM2(snap *XDPoS.Snapshot, eth *Ethereum, block *types.Block) (common.Address, error) {
epoch := eth.chainConfig.XDPoS.Epoch
no := block.NumberU64()
cpNo := no
if no%epoch != 0 {
@ -387,7 +387,7 @@ func getM2(snap *posv.Snapshot, eth *Ethereum, block *types.Block) (common.Addre
if err != nil {
return common.Address{}, err
}
m1, err := posv.WhoIsCreator(snap, block.Header())
m1, err := XDPoS.WhoIsCreator(snap, block.Header())
if err != nil {
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
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 chainConfig.Posv != nil {
return posv.New(chainConfig.Posv, db)
if chainConfig.XDPoS != nil {
return XDPoS.New(chainConfig.XDPoS, db)
}
// Otherwise assume proof-of-work
switch {
@ -553,9 +553,9 @@ func (s *Ethereum) ValidateStaker() (bool, error) {
if err != nil {
return false, err
}
if s.chainConfig.Posv != nil {
if s.chainConfig.XDPoS != nil {
//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())
if err != nil {
return false, fmt.Errorf("Can't verify miner: %v", err)
@ -565,7 +565,7 @@ func (s *Ethereum) ValidateStaker() (bool, error) {
return false, nil
}
} else {
return false, fmt.Errorf("Only verify miners in Posv protocol")
return false, fmt.Errorf("Only verify miners in XDPoS protocol")
}
return true, nil
}
@ -576,13 +576,13 @@ func (s *Ethereum) StartStaking(local bool) error {
log.Error("Cannot start mining without etherbase", "err", 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})
if wallet == nil || err != nil {
log.Error("Etherbase account unavailable locally", "err", err)
return fmt.Errorf("signer missing: %v", err)
}
posv.Authorize(eb, wallet.SignHash)
XDPoS.Authorize(eb, wallet.SignHash)
}
if local {
// 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) {
if bc.Config().Posv == nil {
return nil, core.ErrNotPoSV
if bc.Config().XDPoS == nil {
return nil, core.ErrNotXDPoS
}
client, err := bc.GetClient()
if err != nil {

View file

@ -318,7 +318,7 @@ func (t *dialTask) Do(srv *Server) {
}
}
if err == nil {
log.Trace("Dial pair connection sucess", "task", t.dest)
log.Trace("Dial pair connection success", "task", t.dest)
} else {
log.Trace("Dial pair connection error", "task", t.dest, "err", err)
}