mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-16 18:00:46 +00:00
fix vote test and optimize log (#750)
Co-authored-by: liam.lai <liam.lai@us>
This commit is contained in:
parent
4278930885
commit
a8560300a4
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)
|
epochInfo, err := x.getEpochSwitchInfo(chain, nil, voteMsg.ProposedBlockInfo.Hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("[voteHandler] Error when getting epoch switch Info", "error", err)
|
return &utils.ErrIncomingMessageBlockNotFound{
|
||||||
return errors.New("fail on voteHandler due to failure in getting epoch switch info")
|
Type: "vote",
|
||||||
|
IncomingBlockHash: voteMsg.ProposedBlockInfo.Hash,
|
||||||
|
IncomingBlockNumber: voteMsg.ProposedBlockInfo.Number,
|
||||||
|
Err: err,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
certThreshold := x.config.V2.Config(uint64(voteMsg.ProposedBlockInfo.Round)).CertThreshold
|
certThreshold := x.config.V2.Config(uint64(voteMsg.ProposedBlockInfo.Round)).CertThreshold
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,9 @@ package utils
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/big"
|
||||||
|
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/common"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/types"
|
"github.com/XinFinOrg/XDPoSChain/core/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -120,3 +122,14 @@ type ErrIncomingMessageRoundTooFarFromCurrentRound struct {
|
||||||
func (e *ErrIncomingMessageRoundTooFarFromCurrentRound) Error() string {
|
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)
|
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"
|
||||||
"github.com/XinFinOrg/XDPoSChain/accounts/abi/bind/backends"
|
"github.com/XinFinOrg/XDPoSChain/accounts/abi/bind/backends"
|
||||||
"github.com/XinFinOrg/XDPoSChain/common"
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/consensus/XDPoS"
|
"github.com/XinFinOrg/XDPoSChain/consensus/XDPoS"
|
||||||
"github.com/XinFinOrg/XDPoSChain/core/types"
|
"github.com/XinFinOrg/XDPoSChain/core/types"
|
||||||
"github.com/XinFinOrg/XDPoSChain/params"
|
"github.com/XinFinOrg/XDPoSChain/params"
|
||||||
|
|
@ -195,11 +194,11 @@ func TestVoteMessageHandlerSuccessfullyGeneratedAndProcessQC(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestThrowErrorIfVoteMsgRoundIsMoreThanOneRoundAwayFromCurrentRound(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
|
engineV2 := blockchain.Engine().(*XDPoS.XDPoS).EngineV2
|
||||||
|
|
||||||
blockInfo := &types.BlockInfo{
|
blockInfo := &types.BlockInfo{
|
||||||
Hash: common.HexToHash("0x1"),
|
Hash: currentBlock.Hash(),
|
||||||
Round: types.Round(6),
|
Round: types.Round(6),
|
||||||
Number: big.NewInt(999),
|
Number: big.NewInt(999),
|
||||||
}
|
}
|
||||||
|
|
@ -397,7 +396,7 @@ func TestVoteMessageShallNotThrowErrorIfBlockNotYetExist(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
err := engineV2.VoteHandler(blockchain, voteMsg)
|
err := engineV2.VoteHandler(blockchain, voteMsg)
|
||||||
assert.Nil(t, err)
|
assert.Contains(t, err.Error(), "proposed block is not found")
|
||||||
|
|
||||||
voteMsg = &types.Vote{
|
voteMsg = &types.Vote{
|
||||||
ProposedBlockInfo: blockInfo,
|
ProposedBlockInfo: blockInfo,
|
||||||
|
|
@ -405,7 +404,7 @@ func TestVoteMessageShallNotThrowErrorIfBlockNotYetExist(t *testing.T) {
|
||||||
GapNumber: 450,
|
GapNumber: 450,
|
||||||
}
|
}
|
||||||
err = engineV2.VoteHandler(blockchain, voteMsg)
|
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
|
// Create a vote message that should trigger vote pool hook, but it shall not produce any QC yet
|
||||||
voteMsg = &types.Vote{
|
voteMsg = &types.Vote{
|
||||||
|
|
@ -415,7 +414,7 @@ func TestVoteMessageShallNotThrowErrorIfBlockNotYetExist(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
err = engineV2.VoteHandler(blockchain, voteMsg)
|
err = engineV2.VoteHandler(blockchain, voteMsg)
|
||||||
assert.Nil(t, err)
|
assert.Contains(t, err.Error(), "proposed block is not found")
|
||||||
currentRound, lockQuorumCert, highestQuorumCert, _, _, _ := engineV2.GetPropertiesFaker()
|
currentRound, lockQuorumCert, highestQuorumCert, _, _, _ := engineV2.GetPropertiesFaker()
|
||||||
// Still using the initlised value because we did not yet go to the next round
|
// Still using the initlised value because we did not yet go to the next round
|
||||||
assert.Nil(t, lockQuorumCert)
|
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())
|
log.Debug("vote round not equal", "error", err, "vote", vote.Hash())
|
||||||
return err
|
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)
|
log.Error("handle BFT Vote", "error", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -854,7 +854,7 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
|
||||||
if !exist {
|
if !exist {
|
||||||
go pm.bft.Vote(p.id, &vote)
|
go pm.bft.Vote(p.id, &vote)
|
||||||
} else {
|
} 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:
|
case msg.Code == TimeoutMsg:
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,6 @@ func AttachConsensusV2Hooks(adaptor *XDPoS.XDPoS, bc *core.BlockChain, chainConf
|
||||||
parentNumber--
|
parentNumber--
|
||||||
parentHash = parentHeader.ParentHash
|
parentHash = parentHeader.ParentHash
|
||||||
listBlockHash = append(listBlockHash, parentHash)
|
listBlockHash = append(listBlockHash, parentHash)
|
||||||
log.Debug("[HookPenalty] listBlockHash", "i", i, "len", len(listBlockHash), "parentHash", parentHash, "parentNumber", parentNumber)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// add list not miner to penalties
|
// add list not miner to penalties
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue