fix(consensus, span): avoid duplicate span commit for spanId 1 (#1559)

fix(consensus, span): avoid duplicate span commit for spanId 1
This commit is contained in:
Krishang Shah 2025-06-02 22:33:05 +05:30 committed by GitHub
parent e41a830bc7
commit 37d853f237
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1140,18 +1140,25 @@ func (c *Bor) checkAndCommitSpan(
}
func (c *Bor) needToCommitSpan(currentSpan *span.Span, headerNumber uint64) bool {
// if span is nil
// If span is nil, return false.
if currentSpan == nil {
return false
}
// check span is not set initially
// Check if span is not set initially, we commit the span with spanId 1, which will also commit the 0th span.
// Check: https://github.com/maticnetwork/genesis-contracts/blob/5dcbcc72f10ab847276586e629f96b8a6d369e1d/contracts/BorValidatorSet.template#L229
if currentSpan.EndBlock == 0 {
return true
}
// if current block is first block of last sprint in current span
// If the current block is the first block of the last sprint in the current span.
// But here we should skip the check for the 0th span, as it will cause the span to be committed to be committed twice.
if currentSpan.EndBlock > c.config.CalculateSprint(headerNumber) && currentSpan.EndBlock-c.config.CalculateSprint(headerNumber)+1 == headerNumber {
if currentSpan.ID == 0 {
// If the current span is the 0th span, we will skip committing the span.
log.Info("Skipping the last sprint commit for 0th span", "spanID", currentSpan.ID, "headerNumber", headerNumber)
return false
}
return true
}