From 5ef031c1e123524d4eccfeaa856846808948eecc Mon Sep 17 00:00:00 2001 From: Patrick Date: Wed, 24 Jul 2024 13:01:03 +0200 Subject: [PATCH] moving backfilled oracle blocking start work to background thread (#1201) ## Motivation [Old impl](https://github.com/smartcontractkit/ccip/blob/7d2cae3660bac29ba9dd48b03d88a761c154d6ae/core/services/ocr2/plugins/ccip/internal/oraclelib/backfilled_oracle.go#L41) of backfilled oracle would run log poller in a non-blocking fashion on job creation. The new implementation has it blocking on job creation, which is impacting load testing. ## Solution Move back to the old background thread pattern. --- .../plugins/ccip/internal/oraclelib/backfilled_oracle.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/services/ocr2/plugins/ccip/internal/oraclelib/backfilled_oracle.go b/core/services/ocr2/plugins/ccip/internal/oraclelib/backfilled_oracle.go index 599a6206a1..3c5ab64103 100644 --- a/core/services/ocr2/plugins/ccip/internal/oraclelib/backfilled_oracle.go +++ b/core/services/ocr2/plugins/ccip/internal/oraclelib/backfilled_oracle.go @@ -141,7 +141,12 @@ type ChainAgnosticBackFilledOracle struct { } func (r *ChainAgnosticBackFilledOracle) Start(ctx context.Context) error { - ctx, cancelFn := context.WithCancel(context.Background()) + go r.run(ctx) + return nil +} + +func (r *ChainAgnosticBackFilledOracle) run(ctx context.Context) { + ctx, cancelFn := context.WithCancel(ctx) r.cancelFn = cancelFn var err error var errMu sync.Mutex @@ -175,7 +180,6 @@ func (r *ChainAgnosticBackFilledOracle) Start(ctx context.Context) error { } if err := ctx.Err(); err != nil { r.lggr.Errorw("context already cancelled", "err", err) - return nil } // Start oracle with all logs present from dstStartBlock on dst and // all logs from srcStartBlock on src. @@ -185,7 +189,6 @@ func (r *ChainAgnosticBackFilledOracle) Start(ctx context.Context) error { } else { r.oracleStarted.Store(true) } - return nil } func (r *ChainAgnosticBackFilledOracle) Close() error {