Skip to content

Commit

Permalink
bug fix for snapshot failed to load from db (ethereum#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
liam-lai authored May 23, 2022
1 parent ca336f6 commit 882add5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions consensus/XDPoS/engines/engine_v2/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 26 additions & 0 deletions consensus/tests/engine_v2_tests/vote_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 882add5

Please sign in to comment.