From 57887d87fc5d31bb855936843290cc26a6aaa668 Mon Sep 17 00:00:00 2001 From: NathanBSC Date: Wed, 2 Aug 2023 16:29:12 +0800 Subject: [PATCH] finality: add more check to ensure reuslt of assembleVoteAttestation --- consensus/parlia/parlia.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/consensus/parlia/parlia.go b/consensus/parlia/parlia.go index c79eccb91d..3ea1591c1c 100644 --- a/consensus/parlia/parlia.go +++ b/consensus/parlia/parlia.go @@ -882,6 +882,11 @@ func (p *Parlia) assembleVoteAttestation(chain consensus.ChainHeaderReader, head attestation.VoteAddressSet |= 1 << (valInfo.Index - 1) //Index is offset by 1 } } + validatorsBitSet := bitset.From([]uint64{uint64(attestation.VoteAddressSet)}) + if validatorsBitSet.Count() < uint(len(signatures)) { + log.Warn(fmt.Sprintf("assembleVoteAttestation, check VoteAddress Set failed, expected:%d, real:%d", len(signatures), validatorsBitSet.Count())) + return fmt.Errorf("invalid attestation, check VoteAddress Set failed") + } // Append attestation to header extra field. buf := new(bytes.Buffer) @@ -1758,7 +1763,6 @@ func (p *Parlia) GetFinalizedHeader(chain consensus.ChainHeaderReader, header *t return nil } - // snap.Attestation is nil after plato upgrade, only can happen in local testnet if snap.Attestation == nil { return chain.GetHeaderByNumber(0) // keep consistent with GetJustifiedNumberAndHash }