drop peer if received bad block data which does not include the validator field (#494)

Co-authored-by: wjrjerome <wjrjerome@babylonchain.io>
This commit is contained in:
Banana-J 2024-03-23 09:18:21 +11:00 committed by GitHub
parent e5317a0ff6
commit 816dce9527
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 5 additions and 2 deletions

View file

@ -36,7 +36,8 @@ func (x *XDPoS_v2) verifyHeader(chain consensus.ChainReader, header *types.Heade
}
if len(header.Validator) == 0 {
return consensus.ErrNoValidatorSignature
// This should never happen, if it does, then it means the peer is sending us invalid data.
return consensus.ErrNoValidatorSignatureV2
}
if fullVerify {

View file

@ -39,6 +39,8 @@ var (
ErrNoValidatorSignature = errors.New("no validator in header")
ErrNoValidatorSignatureV2 = errors.New("no validator in v2 header")
ErrNotReadyToPropose = errors.New("not ready to propose, QC is not ready")
ErrNotReadyToMine = errors.New("Not ready to mine, it's not your turn")

View file

@ -50,7 +50,7 @@ func TestShouldVerifyBlock(t *testing.T) {
noValidatorBlock := blockchain.GetBlockByNumber(902).Header()
noValidatorBlock.Validator = []byte{}
err = adaptor.VerifyHeader(blockchain, noValidatorBlock, true)
assert.Equal(t, consensus.ErrNoValidatorSignature, err)
assert.Equal(t, consensus.ErrNoValidatorSignatureV2, err)
blockFromFuture := blockchain.GetBlockByNumber(902).Header()
blockFromFuture.Time = big.NewInt(time.Now().Unix() + 10000)