mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
cherry pick vote test fix
This commit is contained in:
parent
c98f42c0ff
commit
78331172f3
6 changed files with 29 additions and 10 deletions
|
|
@ -78,8 +78,12 @@ func (x *XDPoS_v2) voteHandler(chain consensus.ChainReader, voteMsg *types.Vote)
|
|||
|
||||
epochInfo, err := x.getEpochSwitchInfo(chain, nil, voteMsg.ProposedBlockInfo.Hash)
|
||||
if err != nil {
|
||||
log.Error("[voteHandler] Error when getting epoch switch Info", "error", err)
|
||||
return errors.New("Fail on voteHandler due to failure in getting epoch switch info")
|
||||
return &utils.ErrIncomingMessageBlockNotFound{
|
||||
Type: "vote",
|
||||
IncomingBlockHash: voteMsg.ProposedBlockInfo.Hash,
|
||||
IncomingBlockNumber: voteMsg.ProposedBlockInfo.Number,
|
||||
Err: err,
|
||||
}
|
||||
}
|
||||
|
||||
certThreshold := x.config.V2.Config(uint64(voteMsg.ProposedBlockInfo.Round)).CertThreshold
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@ package utils
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"github.com/XinFinOrg/XDPoSChain/common"
|
||||
"github.com/XinFinOrg/XDPoSChain/core/types"
|
||||
)
|
||||
|
||||
|
|
@ -120,3 +122,14 @@ type ErrIncomingMessageRoundTooFarFromCurrentRound struct {
|
|||
func (e *ErrIncomingMessageRoundTooFarFromCurrentRound) Error() string {
|
||||
return fmt.Sprintf("%s message round number: %v is too far away from currentRound: %v", e.Type, e.IncomingRound, e.CurrentRound)
|
||||
}
|
||||
|
||||
type ErrIncomingMessageBlockNotFound struct {
|
||||
Type string
|
||||
IncomingBlockHash common.Hash
|
||||
IncomingBlockNumber *big.Int
|
||||
Err error
|
||||
}
|
||||
|
||||
func (e *ErrIncomingMessageBlockNotFound) Error() string {
|
||||
return fmt.Sprintf("%s proposed block is not found hash: %v, block number: %v, error: %s", e.Type, e.IncomingBlockHash.Hex(), e.IncomingBlockNumber, e.Err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import (
|
|||
|
||||
"github.com/XinFinOrg/XDPoSChain/accounts"
|
||||
"github.com/XinFinOrg/XDPoSChain/accounts/abi/bind/backends"
|
||||
"github.com/XinFinOrg/XDPoSChain/common"
|
||||
"github.com/XinFinOrg/XDPoSChain/consensus/XDPoS"
|
||||
"github.com/XinFinOrg/XDPoSChain/core/types"
|
||||
"github.com/XinFinOrg/XDPoSChain/params"
|
||||
|
|
@ -195,11 +194,11 @@ func TestVoteMessageHandlerSuccessfullyGeneratedAndProcessQC(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestThrowErrorIfVoteMsgRoundIsMoreThanOneRoundAwayFromCurrentRound(t *testing.T) {
|
||||
blockchain, _, _, _, _, _ := PrepareXDCTestBlockChainForV2Engine(t, 905, params.TestXDPoSMockChainConfig, nil)
|
||||
blockchain, _, currentBlock, _, _, _ := PrepareXDCTestBlockChainForV2Engine(t, 905, params.TestXDPoSMockChainConfig, nil)
|
||||
engineV2 := blockchain.Engine().(*XDPoS.XDPoS).EngineV2
|
||||
|
||||
blockInfo := &types.BlockInfo{
|
||||
Hash: common.HexToHash("0x1"),
|
||||
Hash: currentBlock.Hash(),
|
||||
Round: types.Round(6),
|
||||
Number: big.NewInt(999),
|
||||
}
|
||||
|
|
@ -397,7 +396,7 @@ func TestVoteMessageShallNotThrowErrorIfBlockNotYetExist(t *testing.T) {
|
|||
}
|
||||
|
||||
err := engineV2.VoteHandler(blockchain, voteMsg)
|
||||
assert.Nil(t, err)
|
||||
assert.Contains(t, err.Error(), "proposed block is not found")
|
||||
|
||||
voteMsg = &types.Vote{
|
||||
ProposedBlockInfo: blockInfo,
|
||||
|
|
@ -405,7 +404,7 @@ func TestVoteMessageShallNotThrowErrorIfBlockNotYetExist(t *testing.T) {
|
|||
GapNumber: 450,
|
||||
}
|
||||
err = engineV2.VoteHandler(blockchain, voteMsg)
|
||||
assert.Nil(t, err)
|
||||
assert.Contains(t, err.Error(), "proposed block is not found")
|
||||
|
||||
// Create a vote message that should trigger vote pool hook, but it shall not produce any QC yet
|
||||
voteMsg = &types.Vote{
|
||||
|
|
@ -415,7 +414,7 @@ func TestVoteMessageShallNotThrowErrorIfBlockNotYetExist(t *testing.T) {
|
|||
}
|
||||
|
||||
err = engineV2.VoteHandler(blockchain, voteMsg)
|
||||
assert.Nil(t, err)
|
||||
assert.Contains(t, err.Error(), "proposed block is not found")
|
||||
currentRound, lockQuorumCert, highestQuorumCert, _, _, _ := engineV2.GetPropertiesFaker()
|
||||
// Still using the initlised value because we did not yet go to the next round
|
||||
assert.Nil(t, lockQuorumCert)
|
||||
|
|
|
|||
|
|
@ -101,6 +101,10 @@ func (b *Bfter) Vote(peer string, vote *types.Vote) error {
|
|||
log.Debug("vote round not equal", "error", err, "vote", vote.Hash())
|
||||
return err
|
||||
}
|
||||
if _, ok := err.(*utils.ErrIncomingMessageBlockNotFound); ok {
|
||||
log.Debug("vote proposed block not found", "error", err, "vote", vote.Hash())
|
||||
return err
|
||||
}
|
||||
log.Error("handle BFT Vote", "error", err)
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -863,7 +863,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
|||
if !exist {
|
||||
go pm.bft.Vote(p.id, &vote)
|
||||
} else {
|
||||
log.Debug("Discarded vote, known vote", "vote hash", vote.Hash(), "voted block hash", vote.ProposedBlockInfo.Hash.Hex(), "number", vote.ProposedBlockInfo.Number, "round", vote.ProposedBlockInfo.Round)
|
||||
log.Trace("Discarded vote, known vote", "vote hash", vote.Hash(), "voted block hash", vote.ProposedBlockInfo.Hash.Hex(), "number", vote.ProposedBlockInfo.Number, "round", vote.ProposedBlockInfo.Round)
|
||||
}
|
||||
|
||||
case msg.Code == TimeoutMsg:
|
||||
|
|
|
|||
|
|
@ -64,7 +64,6 @@ func AttachConsensusV2Hooks(adaptor *XDPoS.XDPoS, bc *core.BlockChain, chainConf
|
|||
parentNumber--
|
||||
parentHash = parentHeader.ParentHash
|
||||
listBlockHash = append(listBlockHash, parentHash)
|
||||
log.Debug("[HookPenalty] listBlockHash", "i", i, "len", len(listBlockHash), "parentHash", parentHash, "parentNumber", parentNumber)
|
||||
}
|
||||
|
||||
// add list not miner to penalties
|
||||
|
|
|
|||
Loading…
Reference in a new issue