diff --git a/consensus/XDPoS/engines/engine_v2/vote.go b/consensus/XDPoS/engines/engine_v2/vote.go index 592a5741cb91..f31e95c86284 100644 --- a/consensus/XDPoS/engines/engine_v2/vote.go +++ b/consensus/XDPoS/engines/engine_v2/vote.go @@ -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 diff --git a/consensus/XDPoS/utils/errors.go b/consensus/XDPoS/utils/errors.go index da83ec706474..eec246b54b7b 100644 --- a/consensus/XDPoS/utils/errors.go +++ b/consensus/XDPoS/utils/errors.go @@ -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) +} diff --git a/consensus/tests/engine_v2_tests/vote_test.go b/consensus/tests/engine_v2_tests/vote_test.go index 4a58ad08abda..afaf5e818dfe 100644 --- a/consensus/tests/engine_v2_tests/vote_test.go +++ b/consensus/tests/engine_v2_tests/vote_test.go @@ -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) diff --git a/eth/bft/bft_handler.go b/eth/bft/bft_handler.go index 44d7c9b42378..267153dfb55d 100644 --- a/eth/bft/bft_handler.go +++ b/eth/bft/bft_handler.go @@ -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 } diff --git a/eth/handler.go b/eth/handler.go index 3bb563ddcdaa..503671eb5280 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -854,7 +854,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: diff --git a/eth/hooks/engine_v2_hooks.go b/eth/hooks/engine_v2_hooks.go index 8cb27cdd49c4..fde8e924879f 100644 --- a/eth/hooks/engine_v2_hooks.go +++ b/eth/hooks/engine_v2_hooks.go @@ -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