From 37d853f237db906ede2bfb5f98a8fa164a46710d Mon Sep 17 00:00:00 2001 From: Krishang Shah <109511742+kamuikatsurgi@users.noreply.github.com> Date: Mon, 2 Jun 2025 22:33:05 +0530 Subject: [PATCH] fix(consensus, span): avoid duplicate span commit for spanId 1 (#1559) fix(consensus, span): avoid duplicate span commit for spanId 1 --- consensus/bor/bor.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/consensus/bor/bor.go b/consensus/bor/bor.go index adb9e7857b..5303be53e2 100644 --- a/consensus/bor/bor.go +++ b/consensus/bor/bor.go @@ -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 }