bug fix for snapshot failed to load from db (#91)

This commit is contained in:
Liam 2022-05-22 19:15:25 -05:00 committed by GitHub
parent ca336f6029
commit 882add50f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View file

@ -582,6 +582,7 @@ func (x *XDPoS_v2) VerifyVoteMessage(chain consensus.ChainReader, vote *types.Vo
snapshot, err := x.getSnapshot(chain, vote.GapNumber, true)
if err != nil {
log.Error("[VerifyVoteMessage] fail to get snapshot for a vote message", "BlockNum", vote.ProposedBlockInfo.Number, "Hash", vote.ProposedBlockInfo.Hash, "Error", err.Error())
return false, err
}
verified, _, err := x.verifyMsgSignature(types.VoteSigHash(&types.VoteForSign{
ProposedBlockInfo: vote.ProposedBlockInfo,

View file

@ -510,6 +510,32 @@ func TestVerifyVoteMsg(t *testing.T) {
assert.Nil(t, err)
}
func TestVoteMsgMissingSnapshot(t *testing.T) {
blockchain, _, currentBlock, signer, signFn, _ := PrepareXDCTestBlockChainForV2Engine(t, 915, params.TestXDPoSMockChainConfig, nil)
engineV2 := blockchain.Engine().(*XDPoS.XDPoS).EngineV2
blockInfo := &utils.BlockInfo{
Hash: currentBlock.Hash(),
Round: utils.Round(14),
Number: big.NewInt(915),
}
voteForSign := &utils.VoteForSign{
ProposedBlockInfo: blockInfo,
GapNumber: 450,
}
signHash, _ := signFn(accounts.Account{Address: signer}, utils.VoteSigHash(voteForSign).Bytes())
voteMsg := &utils.Vote{
ProposedBlockInfo: blockInfo,
Signature: signHash,
GapNumber: 1350, // missing 1350 snapshot
}
engineV2.SetNewRoundFaker(blockchain, utils.Round(14), false)
verified, err := engineV2.VerifyVoteMessage(blockchain, voteMsg)
assert.False(t, verified)
assert.NotNil(t, err)
}
func TestVoteMessageHandlerWrongGapNumber(t *testing.T) {
blockchain, _, currentBlock, signer, signFn, _ := PrepareXDCTestBlockChainForV2Engine(t, 905, params.TestXDPoSMockChainConfig, nil)
engineV2 := blockchain.Engine().(*XDPoS.XDPoS).EngineV2