@@ -2296,29 +2296,31 @@ func (p *Parlia) GetFinalizedHeader(chain consensus.ChainHeaderReader, header *t
22962296 return chain .GetHeaderByNumber (0 ) // keep consistent with GetJustifiedNumberAndHash
22972297 }
22982298
2299- currentJustifiedNumber := snap .Attestation .TargetNumber
2300- currentJustifiedHash := snap .Attestation .TargetHash
2299+ finalizedHash := snap .Attestation .SourceHash
2300+ finalizedNumber := snap .Attestation .SourceNumber
23012301
2302+ currentJustifiedHash := snap .Attestation .TargetHash
2303+ currentJustifiedNumber := snap .Attestation .TargetNumber
23022304 // Try to check if currentJustifiedNumber can become finalized by checking VotePool.
23032305 // We only need to check currentJustifiedNumber + 1, since currentJustifiedNumber is already the latest justified.
23042306 if p .VotePool != nil && currentJustifiedNumber == header .Number .Uint64 ()- 1 {
23052307 parentSnap , err := p .snapshot (chain , header .Number .Uint64 ()- 1 , header .ParentHash , nil )
2306- if err != nil {
2308+ if err == nil {
2309+ // Check if the next block (direct child) has reached quorum in VotePool
2310+ votes := p .VotePool .FetchVotesByBlockHash (header .Hash (), currentJustifiedNumber )
2311+ quorum := cmath .CeilDiv (len (parentSnap .Validators )* 2 , 3 )
2312+
2313+ if len (votes ) >= quorum {
2314+ finalizedHash = currentJustifiedHash
2315+ finalizedNumber = currentJustifiedNumber
2316+ }
2317+ } else {
23072318 log .Error ("Failed to get parent snapshot for finality check" ,
23082319 "error" , err , "blockNumber" , header .Number .Uint64 ()- 1 , "blockHash" , header .ParentHash )
2309- return chain .GetHeader (snap .Attestation .SourceHash , snap .Attestation .SourceNumber )
2310- }
2311- // Check if the next block (direct child) has reached quorum in VotePool
2312- votes := p .VotePool .FetchVotesByBlockHash (header .Hash (), currentJustifiedNumber )
2313- quorum := cmath .CeilDiv (len (parentSnap .Validators )* 2 , 3 )
2314-
2315- if len (votes ) >= quorum {
2316- return chain .GetHeader (currentJustifiedHash , currentJustifiedNumber )
23172320 }
23182321 }
23192322
2320- // Fallback to the original logic: finalized is the source in attestation
2321- return chain .GetHeader (snap .Attestation .SourceHash , snap .Attestation .SourceNumber )
2323+ return chain .GetHeader (finalizedHash , finalizedNumber )
23222324}
23232325
23242326// CheckFinalityAndNotify checks if votes for the target block have reached quorum,
0 commit comments