Skip to content

Commit

Permalink
drop peer if received bad block data which does not include the valid…
Browse files Browse the repository at this point in the history
…ator field (#494)

Co-authored-by: wjrjerome <wjrjerome@babylonchain.io>
  • Loading branch information
wjrjerome and jrwbabylonlab committed Mar 22, 2024
1 parent e5317a0 commit 816dce9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion consensus/XDPoS/engines/engine_v2/verifyHeader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions consensus/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion consensus/tests/engine_v2_tests/verify_header_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 816dce9

Please sign in to comment.