diff --git a/core/services/ocr2/plugins/ccip/ccipcommit/ocr2.go b/core/services/ocr2/plugins/ccip/ccipcommit/ocr2.go index 4e6c3f20b2..f1e732ebbc 100644 --- a/core/services/ocr2/plugins/ccip/ccipcommit/ocr2.go +++ b/core/services/ocr2/plugins/ccip/ccipcommit/ocr2.go @@ -640,12 +640,15 @@ func (r *CommitReportingPlugin) isStaleMerkleRoot(ctx context.Context, lggr logg return true } - if nextSeqNum > reportInterval.Min { - // If the next min is already greater than this reports min, this report is stale. - lggr.Infow("Report is stale because of root", "onchain min", nextSeqNum, "report min", reportInterval.Min) + // The report is not stale and correct only if nextSeqNum == reportInterval.Min. + // Mark it stale if the condition isn't met. + if nextSeqNum != reportInterval.Min { + lggr.Infow("The report is stale because of sequence number mismatch with the commit store interval min value", + "nextSeqNum", nextSeqNum, "reportIntervalMin", reportInterval.Min) return true } - lggr.Infow("Report root is not stale", "onchain min", nextSeqNum, "report min", reportInterval.Min) + + lggr.Infow("Report root is not stale", "nextSeqNum", nextSeqNum, "reportIntervalMin", reportInterval.Min) // If a report has root and valid sequence number, the report should be submitted, regardless of price staleness return false diff --git a/core/services/ocr2/plugins/ccip/ccipcommit/ocr2_test.go b/core/services/ocr2/plugins/ccip/ccipcommit/ocr2_test.go index e121a8906d..880f2208a4 100644 --- a/core/services/ocr2/plugins/ccip/ccipcommit/ocr2_test.go +++ b/core/services/ocr2/plugins/ccip/ccipcommit/ocr2_test.go @@ -1197,13 +1197,36 @@ func TestCommitReportingPlugin_isStaleReport(t *testing.T) { commitStoreReader: commitStoreReader, } - assert.False(t, r.isStaleReport(ctx, lggr, cciptypes.CommitStoreReport{ - MerkleRoot: merkleRoot1, - Interval: cciptypes.CommitStoreInterval{Min: expNextSeqNum + 1, Max: expNextSeqNum + 10}, - }, types.ReportTimestamp{})) + testCases := map[string]struct { + interval cciptypes.CommitStoreInterval + result bool + }{ + "The nextSeqNumber is equal to the commit store interval Min value": { + interval: cciptypes.CommitStoreInterval{Min: expNextSeqNum, Max: expNextSeqNum + 10}, + result: false, + }, + "The nextSeqNumber is less than the commit store interval Min value": { + interval: cciptypes.CommitStoreInterval{Min: expNextSeqNum + 1, Max: expNextSeqNum + 10}, + result: true, + }, + "The nextSeqNumber is greater than the commit store interval Min value": { + interval: cciptypes.CommitStoreInterval{Min: expNextSeqNum - 1, Max: expNextSeqNum + 10}, + result: true, + }, + "Empty interval": { + interval: cciptypes.CommitStoreInterval{}, + result: true, + }, + } - assert.True(t, r.isStaleReport(ctx, lggr, cciptypes.CommitStoreReport{ - MerkleRoot: merkleRoot1}, types.ReportTimestamp{})) + for tcName, tc := range testCases { + t.Run(tcName, func(t *testing.T) { + assert.Equal(t, tc.result, r.isStaleReport(ctx, lggr, cciptypes.CommitStoreReport{ + MerkleRoot: merkleRoot1, + Interval: tc.interval, + }, types.ReportTimestamp{})) + }) + } }) }