Skip to content

Commit 989d6ac

Browse files
authored
Enhance exec report handling by enforcing maximum report count limit (#973)
1 parent e52d53e commit 989d6ac

File tree

2 files changed

+86
-7
lines changed

2 files changed

+86
-7
lines changed

execute/report/builder.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,6 @@ func (b *execReportBuilder) Add(
188188
ctx context.Context,
189189
commitReport exectypes.CommitData,
190190
) (exectypes.CommitData, error) {
191-
if uint64(len(b.execReports)) > b.maxReportCount {
192-
return commitReport, nil
193-
}
194-
195191
b.checkInitialize()
196192

197193
// Validate nonces for multiple reports mode
@@ -223,6 +219,13 @@ func (b *execReportBuilder) Add(
223219
b.createNewExecReport()
224220
}
225221

222+
if uint64(len(b.execReports)) > b.maxReportCount {
223+
b.lggr.Debugw("Reached maximum report count, stopping further processing",
224+
"maxReportCount", b.maxReportCount,
225+
"currentCount", len(b.execReports))
226+
return currentCommitReport, nil
227+
}
228+
226229
// Try to build a report with current messages
227230
updatedReport, shouldContinue, err := b.tryBuildReport(ctx, currentCommitReport, readyMessages)
228231
if err != nil {
@@ -276,8 +279,11 @@ func (b *execReportBuilder) handleEmptyReport(
276279
return commitReport, false, nil
277280
}
278281

279-
// TODO: log adding messages to a new exec report
280-
282+
// Don't create new reports if we've reached the max count
283+
if uint64(len(b.execReports)) >= b.maxReportCount {
284+
return commitReport, false, nil
285+
}
286+
b.lggr.Debugw("Creating new exec report due to empty report")
281287
// Try with a new exec report
282288
b.createNewExecReport()
283289
currentIndex := len(b.execReports) - 1

execute/report/report_test.go

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1618,6 +1618,7 @@ func Test_Builder_MultiReport(t *testing.T) {
16181618
expectedChainReportsPerExec []int
16191619
// Map tracking which sequence numbers to skip per chain selector
16201620
expectedSkippedSeqsByChain map[cciptypes.ChainSelector]mapset.Set[cciptypes.SeqNum]
1621+
overrideMaxReportsCount uint64
16211622
wantErr string
16221623
}{
16231624
{
@@ -1762,6 +1763,49 @@ func Test_Builder_MultiReport(t *testing.T) {
17621763
expectedExecReports: 4,
17631764
expectedChainReportsPerExec: []int{1, 1, 1, 1}, // Each report has one chain report
17641765
},
1766+
{
1767+
name: "Solana case with max report count: report multiple reports when input multiple" +
1768+
" reports with single message each",
1769+
args: args{
1770+
maxReportSize: 2800,
1771+
maxGasLimit: 10000000,
1772+
maxMessages: 1,
1773+
maxSingleChainReports: 1,
1774+
nonces: defaultNonces,
1775+
reports: []exectypes.CommitData{
1776+
makeTestCommitReport(hasher, 1, 2, 100, 999, 10101010101,
1777+
sender,
1778+
cciptypes.Bytes32{}, // generate a correct root.
1779+
nil, // executed
1780+
true, // zero nonces
1781+
),
1782+
makeTestCommitReport(hasher, 1, 2, 101, 999, 10101010101,
1783+
sender,
1784+
cciptypes.Bytes32{}, // generate a correct root.
1785+
nil, // executed
1786+
true, // zero nonces
1787+
),
1788+
makeTestCommitReport(hasher, 1, 2, 102, 999, 10101010101,
1789+
sender,
1790+
cciptypes.Bytes32{}, // generate a correct root.
1791+
nil, // executed
1792+
true, // zero nonces
1793+
),
1794+
makeTestCommitReport(hasher, 1, 2, 103, 999, 10101010101,
1795+
sender,
1796+
cciptypes.Bytes32{}, // generate a correct root.
1797+
nil, // executed
1798+
true, // zero nonces
1799+
),
1800+
},
1801+
},
1802+
overrideMaxReportsCount: 2,
1803+
expectedExecReports: 2,
1804+
expectedChainReportsPerExec: []int{1, 1}, // Each report has one chain report
1805+
expectedSkippedSeqsByChain: map[cciptypes.ChainSelector]mapset.Set[cciptypes.SeqNum]{
1806+
2: mapset.NewSet(cciptypes.SeqNum(102), cciptypes.SeqNum(103)),
1807+
},
1808+
},
17651809
{
17661810
name: "multiple reports - max single chain reports",
17671811
args: args{
@@ -1860,6 +1904,30 @@ func Test_Builder_MultiReport(t *testing.T) {
18601904
2: mapset.NewSet(cciptypes.SeqNum(101), cciptypes.SeqNum(103)),
18611905
},
18621906
},
1907+
{
1908+
name: "report max count limit",
1909+
args: args{
1910+
maxReportSize: 2800,
1911+
maxGasLimit: 10000000,
1912+
maxMessages: 1,
1913+
maxSingleChainReports: 1,
1914+
nonces: defaultNonces,
1915+
reports: []exectypes.CommitData{
1916+
makeTestCommitReport(hasher, 6, 2, 100, 999, 10101010101,
1917+
sender,
1918+
cciptypes.Bytes32{}, // generate a correct root.
1919+
nil, // executed
1920+
true, // zero nonces
1921+
),
1922+
},
1923+
},
1924+
overrideMaxReportsCount: 4,
1925+
expectedExecReports: 4,
1926+
expectedChainReportsPerExec: []int{1, 1, 1, 1}, // Each report has one chain report
1927+
expectedSkippedSeqsByChain: map[cciptypes.ChainSelector]mapset.Set[cciptypes.SeqNum]{
1928+
2: mapset.NewSet[cciptypes.SeqNum](104, 105),
1929+
},
1930+
},
18631931
}
18641932

18651933
mockAddrCodec := internal.NewMockAddressCodecHex(t)
@@ -1872,6 +1940,11 @@ func Test_Builder_MultiReport(t *testing.T) {
18721940
ep.EXPECT().CalculateMessageMaxGas(mock.Anything).Return(uint64(0)).Maybe()
18731941
ep.EXPECT().CalculateMerkleTreeGas(mock.Anything).Return(uint64(0)).Maybe()
18741942

1943+
maxReportCount := uint64(10)
1944+
if tt.overrideMaxReportsCount > 0 {
1945+
maxReportCount = tt.overrideMaxReportsCount
1946+
}
1947+
18751948
builder := NewBuilder(
18761949
lggr,
18771950
hasher,
@@ -1885,7 +1958,7 @@ func Test_Builder_MultiReport(t *testing.T) {
18851958
WithMaxSingleChainReports(tt.args.maxSingleChainReports),
18861959
WithExtraMessageCheck(CheckNonces(tt.args.nonces, mockAddrCodec)),
18871960
WithMultipleReports(true), // all tests are for multi reports
1888-
WithMaxReportsCount(10),
1961+
WithMaxReportsCount(maxReportCount),
18891962
)
18901963

18911964
foundError := false

0 commit comments

Comments
 (0)