From 8358ba8974a94769af1f2faa6678a37236bf4859 Mon Sep 17 00:00:00 2001 From: setunapo Date: Wed, 31 May 2023 09:24:12 +0800 Subject: [PATCH] fix: remove naturally finality detail refer: https://github.com/bnb-chain/bsc/pull/1651 --- consensus/parlia/parlia.go | 22 +++------------------- consensus/parlia/snapshot.go | 10 +++++----- core/types/vote.go | 1 - 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/consensus/parlia/parlia.go b/consensus/parlia/parlia.go index 9765d9f5714..31b6209ebef 100644 --- a/consensus/parlia/parlia.go +++ b/consensus/parlia/parlia.go @@ -1617,19 +1617,13 @@ func (p *Parlia) GetJustifiedNumberAndHash(chain consensus.ChainHeaderReader, he } // GetFinalizedHeader returns highest finalized block header. -// It will find vote finalized block within NaturallyFinalizedDist blocks firstly, -// If the vote finalized block not found, return its naturally finalized block. func (p *Parlia) GetFinalizedHeader(chain consensus.ChainHeaderReader, header *types.Header) *types.Header { - backward := uint64(types.NaturallyFinalizedDist) if chain == nil || header == nil { return nil } if !chain.Config().IsPlato(header.Number.Uint64()) { return chain.GetHeaderByNumber(0) } - if header.Number.Uint64() < backward { - backward = header.Number.Uint64() - } snap, err := p.snapshot(chain, header.Number.Uint64(), header.Hash(), nil, true) if err != nil { @@ -1638,18 +1632,8 @@ func (p *Parlia) GetFinalizedHeader(chain consensus.ChainHeaderReader, header *t return nil } - for snap.Attestation != nil && snap.Attestation.SourceNumber >= header.Number.Uint64()-backward { - if snap.Attestation.TargetNumber == snap.Attestation.SourceNumber+1 { - return chain.GetHeaderByHash(snap.Attestation.SourceHash) - } - - snap, err = p.snapshot(chain, snap.Attestation.SourceNumber, snap.Attestation.SourceHash, nil, true) - if err != nil { - log.Error("GetFinalizedHeader snapshot", - "error", err, "SourceNumber", snap.Attestation.SourceNumber, "SourceHash", snap.Attestation.SourceHash) - return nil - } + if snap.Attestation != nil { + return chain.GetHeader(snap.Attestation.SourceHash, snap.Attestation.SourceNumber) } - - return FindAncientHeader(header, backward, chain, nil) + return nil } diff --git a/consensus/parlia/snapshot.go b/consensus/parlia/snapshot.go index 29007ef2b93..94272822709 100644 --- a/consensus/parlia/snapshot.go +++ b/consensus/parlia/snapshot.go @@ -215,11 +215,11 @@ func (s *Snapshot) updateAttestation(header *types.Header, chainConfig *chain.Co } // Update attestation - s.Attestation = &types.VoteData{ - SourceNumber: attestation.Data.SourceNumber, - SourceHash: attestation.Data.SourceHash, - TargetNumber: attestation.Data.TargetNumber, - TargetHash: attestation.Data.TargetHash, + if s.Attestation != nil && attestation.Data.SourceNumber+1 != attestation.Data.TargetNumber { + s.Attestation.TargetNumber = attestation.Data.TargetNumber + s.Attestation.TargetHash = attestation.Data.TargetHash + } else { + s.Attestation = attestation.Data } } diff --git a/core/types/vote.go b/core/types/vote.go index 8c4882243ce..3533b220c78 100644 --- a/core/types/vote.go +++ b/core/types/vote.go @@ -13,7 +13,6 @@ const ( BLSSignatureLength = 96 MaxAttestationExtraLength = 256 - NaturallyFinalizedDist = 21 // The distance to naturally finalized a block ) type BLSPublicKey [BLSPublicKeyLength]byte