Skip to content

Commit

Permalink
Post review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mateusz-sekara committed Jul 25, 2024
1 parent 938190f commit 615302d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 37 deletions.
17 changes: 2 additions & 15 deletions core/services/ocr2/plugins/ccip/ccipexec/ocr2.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,11 @@ func (r *ExecutionReportingPlugin) Observation(ctx context.Context, timestamp ty
}

func (r *ExecutionReportingPlugin) getExecutableObservations(ctx context.Context, lggr logger.Logger, inflight []InflightInternalExecutionReport) ([]ccip.ObservedMessage, error) {
unexpiredReports, err := r.getUnexpiredCommitReports(ctx, r.commitStoreReader, lggr)
unexpiredReports, err := r.commitRootsCache.RootsEligibleForExecution(ctx)
if err != nil {
return nil, err
}
r.metricsCollector.UnexpiredCommitRoots(len(unexpiredReports))

if len(unexpiredReports) == 0 {
return []ccip.ObservedMessage{}, nil
Expand Down Expand Up @@ -860,20 +861,6 @@ func getTokensPrices(ctx context.Context, priceRegistry ccipdata.PriceRegistryRe
return tokenPrices, nil
}

func (r *ExecutionReportingPlugin) getUnexpiredCommitReports(
ctx context.Context,
commitStoreReader ccipdata.CommitStoreReader,
lggr logger.Logger,
) ([]cciptypes.CommitStoreReport, error) {
eligibleRootsForExec, err := r.commitRootsCache.RootsEligibleForExecution(ctx)
if err != nil {
return nil, err
}

r.metricsCollector.UnexpiredCommitRoots(len(eligibleRootsForExec))
return eligibleRootsForExec, nil
}

type execTokenData struct {
rateLimiterTokenBucket cciptypes.TokenBucketRateLimit
sourceTokenPrices map[cciptypes.Address]*big.Int
Expand Down
45 changes: 23 additions & 22 deletions core/services/ocr2/plugins/ccip/internal/cache/commit_roots_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ func Test_RootsEligibleForExecution(t *testing.T) {

commitStoreAddr := utils.RandomAddress()

block1 := time.Now().Add(-8 * time.Hour)
block2 := time.Now().Add(-5 * time.Hour)
block25 := time.Now().Add(-4 * time.Hour)
block3 := time.Now().Add(-1 * time.Hour)
block4 := time.Now()
block2 := time.Now().Add(-8 * time.Hour)
block3 := time.Now().Add(-5 * time.Hour)
block4 := time.Now().Add(-1 * time.Hour)
newBlock4 := time.Now().Add(-2 * time.Hour)
block5 := time.Now()

root1 := utils.RandomBytes32()
root2 := utils.RandomBytes32()
Expand All @@ -49,8 +49,8 @@ func Test_RootsEligibleForExecution(t *testing.T) {
root5 := utils.RandomBytes32()

inputLogs := []logpoller.Log{
createReportAcceptedLog(t, chainID, commitStoreAddr, 2, 1, root1, block1),
createReportAcceptedLog(t, chainID, commitStoreAddr, 2, 2, root2, block1),
createReportAcceptedLog(t, chainID, commitStoreAddr, 2, 1, root1, block2),
createReportAcceptedLog(t, chainID, commitStoreAddr, 2, 2, root2, block2),
}
require.NoError(t, orm.InsertLogsWithBlock(ctx, inputLogs, logpoller.NewLogPollerBlock(utils.RandomBytes32(), 2, time.Now(), 1)))

Expand Down Expand Up @@ -91,9 +91,9 @@ func Test_RootsEligibleForExecution(t *testing.T) {
assertRoots(t, roots, root2)

inputLogs = []logpoller.Log{
createReportAcceptedLog(t, chainID, commitStoreAddr, 3, 1, root3, block2),
createReportAcceptedLog(t, chainID, commitStoreAddr, 4, 1, root4, block3),
createReportAcceptedLog(t, chainID, commitStoreAddr, 5, 1, root5, block4),
createReportAcceptedLog(t, chainID, commitStoreAddr, 3, 1, root3, block3),
createReportAcceptedLog(t, chainID, commitStoreAddr, 4, 1, root4, block4),
createReportAcceptedLog(t, chainID, commitStoreAddr, 5, 1, root5, block5),
}
require.NoError(t, orm.InsertLogsWithBlock(ctx, inputLogs, logpoller.NewLogPollerBlock(utils.RandomBytes32(), 5, time.Now(), 3)))
roots, err = rootsCache.RootsEligibleForExecution(ctx)
Expand All @@ -112,9 +112,9 @@ func Test_RootsEligibleForExecution(t *testing.T) {
require.NoError(t, err)
assertRoots(t, roots, root2)

// Root4 comes back but in the
// Root4 comes back but with the different block_timestamp (before the reorged block)
inputLogs = []logpoller.Log{
createReportAcceptedLog(t, chainID, commitStoreAddr, 4, 1, root4, block25),
createReportAcceptedLog(t, chainID, commitStoreAddr, 4, 1, root4, newBlock4),
}
require.NoError(t, orm.InsertLogsWithBlock(ctx, inputLogs, logpoller.NewLogPollerBlock(utils.RandomBytes32(), 5, time.Now(), 3)))
roots, err = rootsCache.RootsEligibleForExecution(ctx)
Expand Down Expand Up @@ -146,7 +146,8 @@ func Test_RootsEligibleForExecutionWithReorgs(t *testing.T) {

block1 := time.Now().Add(-8 * time.Hour)
block2 := time.Now().Add(-5 * time.Hour)
block3 := time.Now().Add(-1 * time.Hour)
block3 := time.Now().Add(-2 * time.Hour)
block4 := time.Now().Add(-1 * time.Hour)

root1 := utils.RandomBytes32()
root2 := utils.RandomBytes32()
Expand All @@ -155,9 +156,9 @@ func Test_RootsEligibleForExecutionWithReorgs(t *testing.T) {
// Genesis block
require.NoError(t, orm.InsertBlock(ctx, utils.RandomBytes32(), 1, block1, 1))
inputLogs := []logpoller.Log{
createReportAcceptedLog(t, chainID, commitStoreAddr, 2, 1, root1, block1),
createReportAcceptedLog(t, chainID, commitStoreAddr, 2, 2, root2, block1),
createReportAcceptedLog(t, chainID, commitStoreAddr, 3, 1, root3, block2),
createReportAcceptedLog(t, chainID, commitStoreAddr, 2, 1, root1, block2),
createReportAcceptedLog(t, chainID, commitStoreAddr, 2, 2, root2, block2),
createReportAcceptedLog(t, chainID, commitStoreAddr, 3, 1, root3, block3),
}
require.NoError(t, orm.InsertLogsWithBlock(ctx, inputLogs, logpoller.NewLogPollerBlock(utils.RandomBytes32(), 3, time.Now(), 1)))

Expand All @@ -179,9 +180,9 @@ func Test_RootsEligibleForExecutionWithReorgs(t *testing.T) {

// Reinsert the logs, mark first one as finalized
inputLogs = []logpoller.Log{
createReportAcceptedLog(t, chainID, commitStoreAddr, 3, 1, root1, block1),
createReportAcceptedLog(t, chainID, commitStoreAddr, 4, 2, root2, block2),
createReportAcceptedLog(t, chainID, commitStoreAddr, 5, 1, root3, block3),
createReportAcceptedLog(t, chainID, commitStoreAddr, 3, 1, root1, block3),
createReportAcceptedLog(t, chainID, commitStoreAddr, 4, 1, root2, block4),
createReportAcceptedLog(t, chainID, commitStoreAddr, 4, 2, root3, block4),
}
require.NoError(t, orm.InsertLogsWithBlock(ctx, inputLogs, logpoller.NewLogPollerBlock(utils.RandomBytes32(), 5, time.Now(), 3)))
roots, err = rootsCache.RootsEligibleForExecution(ctx)
Expand Down Expand Up @@ -211,12 +212,12 @@ func Test_BlocksWithTheSameTimestamps(t *testing.T) {

commitStoreAddr := utils.RandomAddress()

block1 := time.Now().Add(-1 * time.Hour).Truncate(time.Second)
block := time.Now().Add(-1 * time.Hour).Truncate(time.Second)
root1 := utils.RandomBytes32()
root2 := utils.RandomBytes32()

inputLogs := []logpoller.Log{
createReportAcceptedLog(t, chainID, commitStoreAddr, 2, 1, root1, block1),
createReportAcceptedLog(t, chainID, commitStoreAddr, 2, 1, root1, block),
}
require.NoError(t, orm.InsertLogsWithBlock(ctx, inputLogs, logpoller.NewLogPollerBlock(utils.RandomBytes32(), 2, time.Now(), 2)))

Expand All @@ -229,7 +230,7 @@ func Test_BlocksWithTheSameTimestamps(t *testing.T) {
assertRoots(t, roots, root1)

inputLogs = []logpoller.Log{
createReportAcceptedLog(t, chainID, commitStoreAddr, 3, 1, root2, block1),
createReportAcceptedLog(t, chainID, commitStoreAddr, 3, 1, root2, block),
}
require.NoError(t, orm.InsertLogsWithBlock(ctx, inputLogs, logpoller.NewLogPollerBlock(utils.RandomBytes32(), 3, time.Now(), 3)))

Expand Down

0 comments on commit 615302d

Please sign in to comment.