Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove naturally finality #110

Merged
merged 1 commit into from
May 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 3 additions & 19 deletions consensus/parlia/parlia.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
10 changes: 5 additions & 5 deletions consensus/parlia/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
1 change: 0 additions & 1 deletion core/types/vote.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const (
BLSSignatureLength = 96

MaxAttestationExtraLength = 256
NaturallyFinalizedDist = 21 // The distance to naturally finalized a block
)

type BLSPublicKey [BLSPublicKeyLength]byte
Expand Down