Skip to content

Commit

Permalink
replace context.Background() (#11334)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 authored Nov 21, 2023
1 parent c9312c6 commit f7949c5
Show file tree
Hide file tree
Showing 51 changed files with 269 additions and 269 deletions.
4 changes: 3 additions & 1 deletion charts/chainlink-cluster/dashboard/cmd/dashboard_deploy.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package main

import (
"context"
"os"

"github.com/smartcontractkit/chainlink/v2/dashboard/dashboard"
)

func main() {
ctx := context.Background()
name := os.Getenv("DASHBOARD_NAME")
if name == "" {
panic("DASHBOARD_NAME must be provided")
Expand Down Expand Up @@ -36,7 +38,7 @@ func main() {
if err != nil {
panic(err)
}
if err := db.Deploy(); err != nil {
if err := db.Deploy(ctx); err != nil {
panic(err)
}
}
3 changes: 1 addition & 2 deletions charts/chainlink-cluster/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,7 @@ func (m *CLClusterDashboard) generate() error {
}

// Deploy deploys the dashboard to Grafana
func (m *CLClusterDashboard) Deploy() error {
ctx := context.Background()
func (m *CLClusterDashboard) Deploy(ctx context.Context) error {
client := grabana.NewClient(&http.Client{}, m.GrafanaURL, grabana.WithAPIToken(m.GrafanaToken))
folder, err := client.FindOrCreateFolder(ctx, m.Folder)
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions common/client/send_only_node_lifecycle.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package client

import (
"context"
"fmt"
"time"

Expand All @@ -14,15 +13,17 @@ import (
// It will continue checking until success and then exit permanently.
func (s *sendOnlyNode[CHAIN_ID, RPC]) verifyLoop() {
defer s.wg.Done()
ctx, cancel := s.chStop.NewCtx()
defer cancel()

backoff := utils.NewRedialBackoff()
for {
select {
case <-s.chStop:
case <-ctx.Done():
return
case <-time.After(backoff.Duration()):
}
chainID, err := s.rpc.ChainID(context.Background())
chainID, err := s.rpc.ChainID(ctx)
if err != nil {
ok := s.IfStarted(func() {
if changed := s.setState(nodeStateUnreachable); changed {
Expand Down
7 changes: 4 additions & 3 deletions core/chains/evm/client/send_only_node_lifecycle.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package client

import (
"context"
"fmt"
"time"

Expand All @@ -14,12 +13,14 @@ import (
// It will continue checking until success and then exit permanently.
func (s *sendOnlyNode) verifyLoop() {
defer s.wg.Done()
ctx, cancel := s.chStop.NewCtx()
defer cancel()

backoff := utils.NewRedialBackoff()
for {
select {
case <-time.After(backoff.Duration()):
chainID, err := s.sender.ChainID(context.Background())
chainID, err := s.sender.ChainID(ctx)
if err != nil {
ok := s.IfStarted(func() {
if changed := s.setState(NodeStateUnreachable); changed {
Expand Down Expand Up @@ -60,7 +61,7 @@ func (s *sendOnlyNode) verifyLoop() {
s.log.Infow("Sendonly RPC Node is online", "nodeState", s.state)
return
}
case <-s.chStop:
case <-ctx.Done():
return
}
}
Expand Down
4 changes: 2 additions & 2 deletions core/chains/evm/gas/models_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gas_test

import (
"context"
"math/big"
"testing"

Expand All @@ -14,11 +13,12 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas/mocks"
rollupMocks "github.com/smartcontractkit/chainlink/v2/core/chains/evm/gas/rollups/mocks"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
)

func TestWrappedEvmEstimator(t *testing.T) {
t.Parallel()
ctx := context.Background()
ctx := testutils.Context(t)

// fee values
gasLimit := uint32(10)
Expand Down
11 changes: 5 additions & 6 deletions core/chains/evm/logpoller/log_poller.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,10 @@ type logPoller struct {
// support chain, polygon, which has 2s block times, we need RPCs roughly with <= 500ms latency
func NewLogPoller(orm ORM, ec Client, lggr logger.Logger, pollPeriod time.Duration,
useFinalityTag bool, finalityDepth int64, backfillBatchSize int64, rpcBatchSize int64, keepFinalizedBlocksDepth int64) *logPoller {

ctx, cancel := context.WithCancel(context.Background())
return &logPoller{
ctx: ctx,
cancel: cancel,
ec: ec,
orm: orm,
lggr: lggr.Named("LogPoller"),
Expand Down Expand Up @@ -371,18 +373,15 @@ func (lp *logPoller) recvReplayComplete() {
func (lp *logPoller) ReplayAsync(fromBlock int64) {
lp.wg.Add(1)
go func() {
if err := lp.Replay(context.Background(), fromBlock); err != nil {
if err := lp.Replay(lp.ctx, fromBlock); err != nil {
lp.lggr.Error(err)
}
lp.wg.Done()
}()
}

func (lp *logPoller) Start(parentCtx context.Context) error {
func (lp *logPoller) Start(context.Context) error {
return lp.StartOnce("LogPoller", func() error {
ctx, cancel := context.WithCancel(parentCtx)
lp.ctx = ctx
lp.cancel = cancel
lp.wg.Add(1)
go lp.run()
return nil
Expand Down
Loading

0 comments on commit f7949c5

Please sign in to comment.