mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 10:50:44 +00:00
bug fix for snapshot failed to load from db (#91)
This commit is contained in:
parent
ca336f6029
commit
882add50f5
2 changed files with 27 additions and 0 deletions
|
|
@ -582,6 +582,7 @@ func (x *XDPoS_v2) VerifyVoteMessage(chain consensus.ChainReader, vote *types.Vo
|
||||||
snapshot, err := x.getSnapshot(chain, vote.GapNumber, true)
|
snapshot, err := x.getSnapshot(chain, vote.GapNumber, true)
|
||||||
if err != nil {
|
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())
|
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{
|
verified, _, err := x.verifyMsgSignature(types.VoteSigHash(&types.VoteForSign{
|
||||||
ProposedBlockInfo: vote.ProposedBlockInfo,
|
ProposedBlockInfo: vote.ProposedBlockInfo,
|
||||||
|
|
|
||||||
|
|
@ -510,6 +510,32 @@ func TestVerifyVoteMsg(t *testing.T) {
|
||||||
assert.Nil(t, err)
|
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) {
|
func TestVoteMessageHandlerWrongGapNumber(t *testing.T) {
|
||||||
blockchain, _, currentBlock, signer, signFn, _ := PrepareXDCTestBlockChainForV2Engine(t, 905, params.TestXDPoSMockChainConfig, nil)
|
blockchain, _, currentBlock, signer, signFn, _ := PrepareXDCTestBlockChainForV2Engine(t, 905, params.TestXDPoSMockChainConfig, nil)
|
||||||
engineV2 := blockchain.Engine().(*XDPoS.XDPoS).EngineV2
|
engineV2 := blockchain.Engine().(*XDPoS.XDPoS).EngineV2
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue