Skip to content

Commit dc1eb96

Browse files
winder0xAustinWang
andauthored
Truncate data logged when fetching commit reports. (#1036)
* Truncate data logged when fetching commit reports. * Add a test. * Fix lint warning. * Rename print function. * Log reports that are being dropped. * Rename function. * Fix test. * Fix warning. * consolidate message for truncated reports * only log reports that have no roots --------- Co-authored-by: 0xAustinWang <[email protected]>
1 parent edb351d commit dc1eb96

File tree

3 files changed

+144
-3
lines changed

3 files changed

+144
-3
lines changed

pkg/chainaccessor/default_accessor.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ import (
1111

1212
"github.com/smartcontractkit/chainlink-common/pkg/logger"
1313
"github.com/smartcontractkit/chainlink-common/pkg/types"
14+
cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3"
1415
"github.com/smartcontractkit/chainlink-common/pkg/types/query"
1516
"github.com/smartcontractkit/chainlink-common/pkg/types/query/primitives"
1617

17-
cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3"
18-
1918
"github.com/smartcontractkit/chainlink-ccip/internal/libs/slicelib"
2019
"github.com/smartcontractkit/chainlink-ccip/pkg/consts"
2120
"github.com/smartcontractkit/chainlink-ccip/pkg/contractreader"
@@ -997,6 +996,13 @@ func (l *DefaultAccessor) processCommitReports(
997996
if len(reports) < limit {
998997
return reports
999998
}
999+
lggr.Errorw("too many commit reports received, commit report results are truncated",
1000+
"numTruncatedReports", len(reports)-limit)
1001+
for l := limit; l < len(reports); l++ {
1002+
if !reports[l].Report.HasNoRoots() {
1003+
lggr.Warnw("dropping merkle root commit report which doesn't fit in limit", "report", reports[l])
1004+
}
1005+
}
10001006
return reports[:limit]
10011007
}
10021008

pkg/reader/ccip.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,32 @@ func (r *ccipChainReader) Close() error {
175175

176176
// ---------------------------------------------------
177177

178+
// printReports is used to trim the size of the printed report. There can be a
179+
// large number of reports, especially on Solana where gas and token
180+
// price updates are split into separate reports. This function removes price
181+
// only reports, and removes price data from combined reports in an attempt to
182+
// ensure merkle roots are easier to find if logs are truncated.
183+
func printReports(lggr logger.Logger, reports []cciptypes.CommitPluginReportWithMeta) {
184+
tokenPriceUpdates := 0
185+
gasPriceUpdates := 0
186+
var reportsWithRoots []cciptypes.CommitPluginReportWithMeta
187+
for _, report := range reports {
188+
gasPriceUpdates += len(report.Report.PriceUpdates.GasPriceUpdates)
189+
tokenPriceUpdates += len(report.Report.PriceUpdates.TokenPriceUpdates)
190+
191+
if !report.Report.HasNoRoots() {
192+
// remove price updates from the report.
193+
cp := report
194+
cp.Report.PriceUpdates = cciptypes.PriceUpdates{}
195+
reportsWithRoots = append(reportsWithRoots, cp)
196+
}
197+
}
198+
lggr.Debugw("decoded commit reports",
199+
"numTokenPriceUpdates", tokenPriceUpdates,
200+
"numGasPriceUpdates", gasPriceUpdates,
201+
"reportsWithRoots", reportsWithRoots)
202+
}
203+
178204
func (r *ccipChainReader) CommitReportsGTETimestamp(
179205
ctx context.Context,
180206
ts time.Time,
@@ -193,7 +219,8 @@ func (r *ccipChainReader) CommitReportsGTETimestamp(
193219
return nil, fmt.Errorf("failed to get commit reports from accessor: %w", err)
194220
}
195221

196-
lggr.Debugw("decoded commit reports", "reports", reports)
222+
printReports(lggr, reports)
223+
197224
return reports, nil
198225
}
199226

pkg/reader/ccip_test.go

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,3 +1790,111 @@ func (m *mockConfigCache) Name() string {
17901790
func (m *mockConfigCache) Ready() error {
17911791
return m.Called().Error(0)
17921792
}
1793+
1794+
func Test_printReports(t *testing.T) {
1795+
genGasPriceReport := func() cciptypes.CommitPluginReportWithMeta {
1796+
return cciptypes.CommitPluginReportWithMeta{
1797+
Report: cciptypes.CommitPluginReport{
1798+
PriceUpdates: cciptypes.PriceUpdates{
1799+
GasPriceUpdates: []cciptypes.GasPriceChain{
1800+
{
1801+
ChainSel: cciptypes.ChainSelector(1),
1802+
GasPrice: cciptypes.NewBigInt(big.NewInt(100)),
1803+
},
1804+
},
1805+
},
1806+
},
1807+
}
1808+
}
1809+
genTokenPriceReport := func() cciptypes.CommitPluginReportWithMeta {
1810+
return cciptypes.CommitPluginReportWithMeta{
1811+
Report: cciptypes.CommitPluginReport{
1812+
PriceUpdates: cciptypes.PriceUpdates{
1813+
TokenPriceUpdates: []cciptypes.TokenPrice{
1814+
{
1815+
Price: cciptypes.NewBigInt(big.NewInt(100)),
1816+
},
1817+
},
1818+
},
1819+
},
1820+
}
1821+
}
1822+
genReport := func(withPrice bool) cciptypes.CommitPluginReportWithMeta {
1823+
var pu cciptypes.PriceUpdates
1824+
if withPrice {
1825+
pu = cciptypes.PriceUpdates{
1826+
TokenPriceUpdates: []cciptypes.TokenPrice{
1827+
{
1828+
Price: cciptypes.NewBigInt(big.NewInt(100)),
1829+
},
1830+
},
1831+
}
1832+
}
1833+
return cciptypes.CommitPluginReportWithMeta{
1834+
Report: cciptypes.CommitPluginReport{
1835+
PriceUpdates: pu,
1836+
UnblessedMerkleRoots: []cciptypes.MerkleRootChain{
1837+
{
1838+
ChainSel: cciptypes.ChainSelector(1),
1839+
OnRampAddress: nil,
1840+
SeqNumsRange: cciptypes.SeqNumRange{1, 2},
1841+
MerkleRoot: cciptypes.Bytes32{},
1842+
},
1843+
},
1844+
},
1845+
}
1846+
}
1847+
1848+
t.Run("prices", func(t *testing.T) {
1849+
var reports []cciptypes.CommitPluginReportWithMeta
1850+
for i := 0; i < 50; i++ {
1851+
reports = append(reports, genGasPriceReport())
1852+
reports = append(reports, genTokenPriceReport())
1853+
}
1854+
1855+
lggr, hook := logger.TestObserved(t, zapcore.DebugLevel)
1856+
printReports(lggr, reports)
1857+
1858+
fmt.Println(hook.Len())
1859+
assert.Len(t, hook.All(), 1)
1860+
z := hook.All()[0]
1861+
for _, ctx := range z.Context {
1862+
switch ctx.Key {
1863+
case "numGasPriceUpdates":
1864+
assert.Equal(t, int64(50), ctx.Integer)
1865+
case "numTokenPriceUpdates":
1866+
assert.Equal(t, int64(50), ctx.Integer)
1867+
case "reportsWithRoots":
1868+
assert.Nil(t, ctx.Interface)
1869+
default:
1870+
assert.Fail(t, "unexpected context key: %s", ctx.Key)
1871+
}
1872+
}
1873+
})
1874+
1875+
t.Run("reports", func(t *testing.T) {
1876+
var reports []cciptypes.CommitPluginReportWithMeta
1877+
for i := 0; i < 50; i++ {
1878+
reports = append(reports, genReport(i%2 == 0))
1879+
}
1880+
1881+
lggr, hook := logger.TestObserved(t, zapcore.DebugLevel)
1882+
printReports(lggr, reports)
1883+
1884+
fmt.Println(hook.Len())
1885+
assert.Len(t, hook.All(), 1)
1886+
z := hook.All()[0]
1887+
for _, ctx := range z.Context {
1888+
switch ctx.Key {
1889+
case "numGasPriceUpdates":
1890+
assert.Equal(t, int64(0), ctx.Integer)
1891+
case "numTokenPriceUpdates":
1892+
assert.Equal(t, int64(25), ctx.Integer)
1893+
case "reportsWithRoots":
1894+
assert.Len(t, ctx.Interface, 50)
1895+
default:
1896+
assert.Fail(t, "unexpected context key: %s", ctx.Key)
1897+
}
1898+
}
1899+
})
1900+
}

0 commit comments

Comments
 (0)