From 54dbb2ba057928e4c6e02913a58e4fd3b0d7d5c3 Mon Sep 17 00:00:00 2001 From: NathanBSC <122502194+NathanBSC@users.noreply.github.com> Date: Wed, 2 Aug 2023 18:10:04 +0800 Subject: [PATCH] finality: add more check to ensure reuslt of assembleVoteAttestation (#1791) --- 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 c79eccb91..3ea1591c1 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 }