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

consortium/v2: fix the incorrect snapshot lookup in GetFinalizedBlock #330

Merged
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
11 changes: 7 additions & 4 deletions consensus/consortium/v2/consortium.go
Original file line number Diff line number Diff line change
Expand Up @@ -1197,8 +1197,14 @@ func (c *Consortium) GetFinalizedBlock(
justifiedHash, descendantJustifiedHash common.Hash
)

justifiedNumber = headNumber
justifiedHash = headHash

for {
justifiedNumber, justifiedHash = c.GetJustifiedBlock(chain, headNumber, headHash)
// When getting the snapshot at block N, the maximum justified number is N - 1.
// Here, we want to check if the block at justifiedNumber - 1 is justified too.
// So, the snapshot we need to look up is at justifiedNumber.
justifiedNumber, justifiedHash = c.GetJustifiedBlock(chain, justifiedNumber, justifiedHash)
if justifiedNumber == 0 {
return 0, common.Hash{}
}
Expand Down Expand Up @@ -1235,9 +1241,6 @@ func (c *Consortium) GetFinalizedBlock(
}
}

header := chain.GetHeaderByHash(justifiedHash)
headNumber = header.Number.Uint64() - 1
headHash = header.ParentHash
descendantJustifiedNumber = justifiedNumber
descendantJustifiedHash = justifiedHash
}
Expand Down