From 615b008f6e39a7c25f6302aec41a79160c7decb1 Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Thu, 16 Nov 2023 16:02:15 -0600 Subject: [PATCH] switch from chainlink-relay to chainlink-common --- cmd/monitoring/main.go | 5 +- go.mod | 2 +- go.sum | 4 +- integration-tests/common/common.go | 19 +++-- integration-tests/go.mod | 12 ++-- integration-tests/go.sum | 20 +++--- pkg/monitoring/config.go | 2 +- pkg/monitoring/feed_config.go | 3 +- pkg/monitoring/metrics.go | 3 +- pkg/monitoring/node_config.go | 3 +- pkg/monitoring/prometheus_exporter.go | 3 +- pkg/monitoring/prometheus_exporter_test.go | 5 +- pkg/monitoring/source_balances.go | 3 +- pkg/monitoring/source_envelope.go | 7 +- pkg/monitoring/source_envelope_test.go | 7 +- pkg/monitoring/source_txresults.go | 3 +- pkg/monitoring/testutils.go | 5 +- pkg/solana/cache_test.go | 2 +- pkg/solana/chain.go | 20 +++--- pkg/solana/chain_test.go | 54 +++++++------- pkg/solana/client/client_test.go | 2 +- pkg/solana/client/test_helpers.go | 3 +- pkg/solana/client/test_helpers_test.go | 7 +- pkg/solana/cmd/chainlink-solana/main.go | 2 +- pkg/solana/config.go | 4 +- pkg/solana/config/config.go | 82 +++++++++++----------- pkg/solana/db/db.go | 18 ++--- pkg/solana/fees/recent_fees.go | 5 +- pkg/solana/logger/logger.go | 2 +- pkg/solana/monitor/balance.go | 9 +-- pkg/solana/monitor/balance_test.go | 4 +- pkg/solana/relay.go | 10 +-- pkg/solana/report_test.go | 3 +- pkg/solana/state_cache.go | 5 +- pkg/solana/transmissions_cache.go | 7 +- pkg/solana/transmitter.go | 3 +- pkg/solana/txm/pendingtx_test.go | 6 +- pkg/solana/txm/txm.go | 23 +++--- pkg/solana/txm/txm_internal_test.go | 8 +-- pkg/solana/txm/txm_race_test.go | 8 +-- pkg/solana/txm/txm_test.go | 10 +-- 41 files changed, 208 insertions(+), 195 deletions(-) diff --git a/cmd/monitoring/main.go b/cmd/monitoring/main.go index 00512d2c2..1dda5d5ec 100644 --- a/cmd/monitoring/main.go +++ b/cmd/monitoring/main.go @@ -5,8 +5,9 @@ import ( "fmt" "github.com/gagliardetto/solana-go/rpc" - "github.com/smartcontractkit/chainlink-relay/pkg/logger" - relayMonitoring "github.com/smartcontractkit/chainlink-relay/pkg/monitoring" + + "github.com/smartcontractkit/chainlink-common/pkg/logger" + relayMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring" "github.com/smartcontractkit/chainlink-solana/pkg/monitoring" ) diff --git a/go.mod b/go.mod index fd880ea44..3b4b2e170 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/pelletier/go-toml/v2 v2.1.0 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.17.0 - github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231020230319-2ede955d1dc9 + github.com/smartcontractkit/chainlink-common v0.1.7-0.20231117021201-6814387d8d3e github.com/smartcontractkit/libocr v0.0.0-20230925165524-ffa38fe11ef8 github.com/stretchr/testify v1.8.4 go.uber.org/multierr v1.11.0 diff --git a/go.sum b/go.sum index c9f0c3b51..4008cb38d 100644 --- a/go.sum +++ b/go.sum @@ -429,8 +429,8 @@ github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5g github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= -github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231020230319-2ede955d1dc9 h1:fFD5SgSJtnXvkGLK3CExNKpUIz4sGrNNkKv3Ljw63Hk= -github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231020230319-2ede955d1dc9/go.mod h1:M9U1JV7IQi8Sfj4JR1qSi1tIh6omgW78W/8SHN/8BUQ= +github.com/smartcontractkit/chainlink-common v0.1.7-0.20231117021201-6814387d8d3e h1:Fsx5IJDD14wdCAe2lEI1xgztIvzjiE2iVHvYzg/grew= +github.com/smartcontractkit/chainlink-common v0.1.7-0.20231117021201-6814387d8d3e/go.mod h1:Hrru9i7n+WEYyW2aIt3/YGPhxLX+HEGWnhk3yVXeDF8= github.com/smartcontractkit/go-plugin v0.0.0-20231003134350-e49dad63b306 h1:ko88+ZznniNJZbZPWAvHQU8SwKAdHngdDZ+pvVgB5ss= github.com/smartcontractkit/go-plugin v0.0.0-20231003134350-e49dad63b306/go.mod h1:w1sAEES3g3PuV/RzUrgow20W2uErMly84hhD3um1WL4= github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f h1:hgJif132UCdjo8u43i7iPN1/MFnu49hv7lFGFftCHKU= diff --git a/integration-tests/common/common.go b/integration-tests/common/common.go index b767b7c8a..a1cb526ce 100644 --- a/integration-tests/common/common.go +++ b/integration-tests/common/common.go @@ -18,31 +18,30 @@ import ( "golang.org/x/crypto/curve25519" "gopkg.in/guregu/null.v4" - "github.com/smartcontractkit/chainlink-solana/pkg/solana" + "github.com/smartcontractkit/libocr/offchainreporting2/confighelper" + "github.com/smartcontractkit/libocr/offchainreporting2/reportingplugin/median" + "github.com/smartcontractkit/libocr/offchainreporting2/types" + + "github.com/smartcontractkit/chainlink-common/pkg/config" + ctf_test_env "github.com/smartcontractkit/chainlink-testing-framework/docker/test_env" "github.com/smartcontractkit/chainlink-testing-framework/k8s/environment" "github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg/alias" "github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg/helm/chainlink" mock_adapter "github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg/helm/mock-adapter" "github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg/helm/sol" - - "github.com/smartcontractkit/libocr/offchainreporting2/confighelper" - "github.com/smartcontractkit/libocr/offchainreporting2/reportingplugin/median" - "github.com/smartcontractkit/libocr/offchainreporting2/types" - "github.com/smartcontractkit/chainlink-testing-framework/utils/ptr" "github.com/smartcontractkit/chainlink/integration-tests/client" "github.com/smartcontractkit/chainlink/integration-tests/contracts" "github.com/smartcontractkit/chainlink/integration-tests/docker/test_env" "github.com/smartcontractkit/chainlink/integration-tests/types/config/node" + cl "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" "github.com/smartcontractkit/chainlink/v2/core/services/job" "github.com/smartcontractkit/chainlink/v2/core/store/models" - relay_utils "github.com/smartcontractkit/chainlink-relay/pkg/utils" test_env_sol "github.com/smartcontractkit/chainlink-solana/integration-tests/docker/test_env" "github.com/smartcontractkit/chainlink-solana/integration-tests/solclient" + "github.com/smartcontractkit/chainlink-solana/pkg/solana" solcfg "github.com/smartcontractkit/chainlink-solana/pkg/solana/config" - ctf_test_env "github.com/smartcontractkit/chainlink-testing-framework/docker/test_env" - cl "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" ) const ( @@ -501,7 +500,7 @@ func (c *Common) DefaultNodeConfig() *cl.Config { Nodes: []*solcfg.Node{ { Name: ptr.Ptr("primary"), - URL: relay_utils.MustParseURL(c.SolanaUrl), + URL: config.MustParseURL(c.SolanaUrl), }, }, } diff --git a/integration-tests/go.mod b/integration-tests/go.mod index 08ddbd3ad..45c0179ad 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -15,11 +15,11 @@ require ( github.com/onsi/gomega v1.27.8 github.com/rs/zerolog v1.30.0 github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b - github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231115124244-8303409abccd - github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231023133638-72f4e799ab05 + github.com/smartcontractkit/chainlink-common v0.1.7-0.20231117021201-6814387d8d3e + github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231116220215-93510f138ff6 github.com/smartcontractkit/chainlink-testing-framework v1.19.0 - github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20231116210131-a9d81ae52ccd - github.com/smartcontractkit/chainlink/v2 v2.5.1-0.20231116210131-a9d81ae52ccd + github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20231116224343-7780eb63d8dc + github.com/smartcontractkit/chainlink/v2 v2.5.1-0.20231116224343-7780eb63d8dc github.com/smartcontractkit/libocr v0.0.0-20231107151413-13e0202ae8d7 github.com/stretchr/testify v1.8.4 github.com/testcontainers/testcontainers-go v0.23.0 @@ -379,8 +379,8 @@ require ( github.com/sirupsen/logrus v1.9.3 // indirect github.com/slack-go/slack v0.12.2 // indirect github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 // indirect - github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231109141932-cb1ea9020255 // indirect - github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231024133459-1ef3a11319eb // indirect + github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231116223324-56d60ee456c3 // indirect + github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231116220530-9d5db8010d3b // indirect github.com/smartcontractkit/ocr2keepers v0.7.28 // indirect github.com/smartcontractkit/ocr2vrf v0.0.0-20230804151440-2f1eb1e20687 // indirect github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1 // indirect diff --git a/integration-tests/go.sum b/integration-tests/go.sum index eedf639e5..26fea8028 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -2355,18 +2355,18 @@ github.com/slack-go/slack v0.12.2 h1:x3OppyMyGIbbiyFhsBmpf9pwkUzMhthJMRNmNlA4LaQ github.com/slack-go/slack v0.12.2/go.mod h1:hlGi5oXA+Gt+yWTPP0plCdRKmjsDxecdHxYQdlMQKOw= github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 h1:T3lFWumvbfM1u/etVq42Afwq/jtNSBSOA8n5jntnNPo= github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704/go.mod h1:2QuJdEouTWjh5BDy5o/vgGXQtR4Gz8yH1IYB5eT7u4M= -github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231109141932-cb1ea9020255 h1:Pt6c7bJU9wIN6PQQnmN8UmYYH6lpfiQ6U/B8yEC2s5s= -github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231109141932-cb1ea9020255/go.mod h1:EHppaccd/LTlTMI2o4dmBHe4BknEgEFFDjDGMNuGb3k= -github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231115124244-8303409abccd h1:PRVJxNK67pQWufXuB1cxckH/xZkcQFDy8KjN9ZYqong= -github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231115124244-8303409abccd/go.mod h1:rOayi690YxLlkQy959PD8INhOAIAUi9LoN0G+J/CEf4= -github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231024133459-1ef3a11319eb h1:HiluOfEVGOQTM6BTDImOqYdMZZ7qq7fkZ3TJdmItNr8= -github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231024133459-1ef3a11319eb/go.mod h1:/30flFG4L/iCYAFeA3DUzR0xuHSxAMONiWTzyzvsNwo= +github.com/smartcontractkit/chainlink-common v0.1.7-0.20231117021201-6814387d8d3e h1:Fsx5IJDD14wdCAe2lEI1xgztIvzjiE2iVHvYzg/grew= +github.com/smartcontractkit/chainlink-common v0.1.7-0.20231117021201-6814387d8d3e/go.mod h1:Hrru9i7n+WEYyW2aIt3/YGPhxLX+HEGWnhk3yVXeDF8= +github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231116223324-56d60ee456c3 h1:Z26fE3PWqlQRqW7QSRYCSpfTXzHkPqcppMPMASU8Z6g= +github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231116223324-56d60ee456c3/go.mod h1:EnvRRl5epzfFyXzo2JkQAh1N3EvDZOF5+ExjId4uyi0= +github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231116220530-9d5db8010d3b h1:KWfn3upgUYbOoOEUAuTJndS2OOmvO67h78P/oF3kbwM= +github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231116220530-9d5db8010d3b/go.mod h1:ShLh2mumD8ShuRBS6ONHDaW6BDloVA3fAbGysJg4Ht4= github.com/smartcontractkit/chainlink-testing-framework v1.19.0 h1:ungyY1gYcXCtmdX2yCon8pkx9HgPPLg4aNAhKNZFP5c= github.com/smartcontractkit/chainlink-testing-framework v1.19.0/go.mod h1:zScXRqmvbyTFUooyLYrOp4+V/sFPUbFJNRc72YmnuIk= -github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20231116210131-a9d81ae52ccd h1:55Zi3Ed6+xJYs+qCORNPVvoitUh/WP8B0AwUtWZ+m3M= -github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20231116210131-a9d81ae52ccd/go.mod h1:4/r8AW79/ZW0tED8GfOjO17AyXyEDZLdgeeZeLpkT1c= -github.com/smartcontractkit/chainlink/v2 v2.5.1-0.20231116210131-a9d81ae52ccd h1:hBerlu8Kus3+a+IUjLiwRmIzLMW663kEFxBCbiFOjrQ= -github.com/smartcontractkit/chainlink/v2 v2.5.1-0.20231116210131-a9d81ae52ccd/go.mod h1:8wHqNlLPdwa9ByE9lPnhrLHdlvfjZI1uj5RRrhrT4Ys= +github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20231116224343-7780eb63d8dc h1:avcEXOkSX95tITMGImqGl1nwX+cmm+q74cXRiVHdBbQ= +github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20231116224343-7780eb63d8dc/go.mod h1:JATrsArYN6wOfkjQ0i/UHnUTXrCK6v5Qr6WwPmG+vQc= +github.com/smartcontractkit/chainlink/v2 v2.5.1-0.20231116224343-7780eb63d8dc h1:JgldMjvhBvsYRRhcfHZrsX35sMMXep+ZD46x3lP/oDE= +github.com/smartcontractkit/chainlink/v2 v2.5.1-0.20231116224343-7780eb63d8dc/go.mod h1:A3oWdc95WLNcQSlxmDuQoEnmVY1uJVPNH+BEElTMJho= github.com/smartcontractkit/go-plugin v0.0.0-20231003134350-e49dad63b306 h1:ko88+ZznniNJZbZPWAvHQU8SwKAdHngdDZ+pvVgB5ss= github.com/smartcontractkit/go-plugin v0.0.0-20231003134350-e49dad63b306/go.mod h1:w1sAEES3g3PuV/RzUrgow20W2uErMly84hhD3um1WL4= github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f h1:hgJif132UCdjo8u43i7iPN1/MFnu49hv7lFGFftCHKU= diff --git a/pkg/monitoring/config.go b/pkg/monitoring/config.go index c47e1cfcd..6a038ac34 100644 --- a/pkg/monitoring/config.go +++ b/pkg/monitoring/config.go @@ -6,7 +6,7 @@ import ( "os" "time" - relayMonitoring "github.com/smartcontractkit/chainlink-relay/pkg/monitoring" + relayMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring" ) type SolanaConfig struct { diff --git a/pkg/monitoring/feed_config.go b/pkg/monitoring/feed_config.go index f9ae5658a..26b6de677 100644 --- a/pkg/monitoring/feed_config.go +++ b/pkg/monitoring/feed_config.go @@ -7,7 +7,8 @@ import ( "math/big" "github.com/gagliardetto/solana-go" - relayMonitoring "github.com/smartcontractkit/chainlink-relay/pkg/monitoring" + + relayMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring" ) type SolanaFeedConfig struct { diff --git a/pkg/monitoring/metrics.go b/pkg/monitoring/metrics.go index 5fc36d134..f6c8401e9 100644 --- a/pkg/monitoring/metrics.go +++ b/pkg/monitoring/metrics.go @@ -5,7 +5,8 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promauto" - relayMonitoring "github.com/smartcontractkit/chainlink-relay/pkg/monitoring" + + relayMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring" ) var BalanceAccountNames = []string{ diff --git a/pkg/monitoring/node_config.go b/pkg/monitoring/node_config.go index 5e12a447f..bafa53f2d 100644 --- a/pkg/monitoring/node_config.go +++ b/pkg/monitoring/node_config.go @@ -5,8 +5,9 @@ import ( "fmt" "io" - relayMonitoring "github.com/smartcontractkit/chainlink-relay/pkg/monitoring" "github.com/smartcontractkit/libocr/offchainreporting2/types" + + relayMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring" ) type SolanaNodeConfig struct { diff --git a/pkg/monitoring/prometheus_exporter.go b/pkg/monitoring/prometheus_exporter.go index 7fbf98385..dfda6e1e0 100644 --- a/pkg/monitoring/prometheus_exporter.go +++ b/pkg/monitoring/prometheus_exporter.go @@ -5,7 +5,8 @@ import ( "sync" "github.com/gagliardetto/solana-go" - relayMonitoring "github.com/smartcontractkit/chainlink-relay/pkg/monitoring" + + relayMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring" ) func NewPrometheusExporterFactory( diff --git a/pkg/monitoring/prometheus_exporter_test.go b/pkg/monitoring/prometheus_exporter_test.go index 38dc9c219..268c0125f 100644 --- a/pkg/monitoring/prometheus_exporter_test.go +++ b/pkg/monitoring/prometheus_exporter_test.go @@ -5,9 +5,10 @@ import ( "testing" "time" - relayMonitoring "github.com/smartcontractkit/chainlink-relay/pkg/monitoring" - "github.com/smartcontractkit/chainlink-solana/pkg/monitoring/mocks" "github.com/stretchr/testify/require" + + relayMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring" + "github.com/smartcontractkit/chainlink-solana/pkg/monitoring/mocks" ) func TestPrometheusExporter(t *testing.T) { diff --git a/pkg/monitoring/source_balances.go b/pkg/monitoring/source_balances.go index 4746e44d3..8f7bf42d3 100644 --- a/pkg/monitoring/source_balances.go +++ b/pkg/monitoring/source_balances.go @@ -7,7 +7,8 @@ import ( "github.com/gagliardetto/solana-go" "github.com/gagliardetto/solana-go/rpc" - relayMonitoring "github.com/smartcontractkit/chainlink-relay/pkg/monitoring" + + relayMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring" ) type Balances struct { diff --git a/pkg/monitoring/source_envelope.go b/pkg/monitoring/source_envelope.go index 0b7ccac39..49bedf6ec 100644 --- a/pkg/monitoring/source_envelope.go +++ b/pkg/monitoring/source_envelope.go @@ -9,11 +9,12 @@ import ( "github.com/gagliardetto/solana-go" "github.com/gagliardetto/solana-go/rpc" - relayMonitoring "github.com/smartcontractkit/chainlink-relay/pkg/monitoring" - "github.com/smartcontractkit/chainlink-solana/pkg/monitoring/event" - pkgSolana "github.com/smartcontractkit/chainlink-solana/pkg/solana" "github.com/smartcontractkit/libocr/offchainreporting2/types" "go.uber.org/multierr" + + relayMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring" + "github.com/smartcontractkit/chainlink-solana/pkg/monitoring/event" + pkgSolana "github.com/smartcontractkit/chainlink-solana/pkg/solana" ) func NewEnvelopeSourceFactory( diff --git a/pkg/monitoring/source_envelope_test.go b/pkg/monitoring/source_envelope_test.go index 2fdf695ad..62e1a108a 100644 --- a/pkg/monitoring/source_envelope_test.go +++ b/pkg/monitoring/source_envelope_test.go @@ -10,12 +10,13 @@ import ( bin "github.com/gagliardetto/binary" "github.com/gagliardetto/solana-go" "github.com/gagliardetto/solana-go/rpc" - relayMonitoring "github.com/smartcontractkit/chainlink-relay/pkg/monitoring" - "github.com/smartcontractkit/chainlink-solana/pkg/monitoring/mocks" - pkgSolana "github.com/smartcontractkit/chainlink-solana/pkg/solana" "github.com/smartcontractkit/libocr/offchainreporting2/types" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" + + relayMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring" + "github.com/smartcontractkit/chainlink-solana/pkg/monitoring/mocks" + pkgSolana "github.com/smartcontractkit/chainlink-solana/pkg/solana" ) var ( diff --git a/pkg/monitoring/source_txresults.go b/pkg/monitoring/source_txresults.go index ecccc1f46..a539be472 100644 --- a/pkg/monitoring/source_txresults.go +++ b/pkg/monitoring/source_txresults.go @@ -7,7 +7,8 @@ import ( "github.com/gagliardetto/solana-go" "github.com/gagliardetto/solana-go/rpc" - relayMonitoring "github.com/smartcontractkit/chainlink-relay/pkg/monitoring" + + relayMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring" ) func NewTxResultsSourceFactory( diff --git a/pkg/monitoring/testutils.go b/pkg/monitoring/testutils.go index 13d07e612..1db1e6ecb 100644 --- a/pkg/monitoring/testutils.go +++ b/pkg/monitoring/testutils.go @@ -7,8 +7,9 @@ import ( "time" "github.com/gagliardetto/solana-go" - "github.com/smartcontractkit/chainlink-relay/pkg/logger" - relayMonitoring "github.com/smartcontractkit/chainlink-relay/pkg/monitoring" + + "github.com/smartcontractkit/chainlink-common/pkg/logger" + relayMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring" ) // Generators diff --git a/pkg/solana/cache_test.go b/pkg/solana/cache_test.go index 0545fb062..57fc83bba 100644 --- a/pkg/solana/cache_test.go +++ b/pkg/solana/cache_test.go @@ -18,7 +18,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/smartcontractkit/chainlink-relay/pkg/logger" + "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-solana/pkg/solana/client" "github.com/smartcontractkit/chainlink-solana/pkg/solana/config" diff --git a/pkg/solana/chain.go b/pkg/solana/chain.go index b4d9885e0..f295bc086 100644 --- a/pkg/solana/chain.go +++ b/pkg/solana/chain.go @@ -15,14 +15,12 @@ import ( "github.com/pkg/errors" "go.uber.org/multierr" - "github.com/smartcontractkit/chainlink-relay/pkg/chains" - "github.com/smartcontractkit/chainlink-relay/pkg/logger" - "github.com/smartcontractkit/chainlink-relay/pkg/loop" - "github.com/smartcontractkit/chainlink-relay/pkg/services" - "github.com/smartcontractkit/chainlink-relay/pkg/types" - relaytypes "github.com/smartcontractkit/chainlink-relay/pkg/types" - "github.com/smartcontractkit/chainlink-relay/pkg/utils" - + "github.com/smartcontractkit/chainlink-common/pkg/chains" + "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink-common/pkg/loop" + "github.com/smartcontractkit/chainlink-common/pkg/services" + "github.com/smartcontractkit/chainlink-common/pkg/types" + relaytypes "github.com/smartcontractkit/chainlink-common/pkg/types" "github.com/smartcontractkit/chainlink-solana/pkg/solana/client" "github.com/smartcontractkit/chainlink-solana/pkg/solana/config" "github.com/smartcontractkit/chainlink-solana/pkg/solana/db" @@ -80,7 +78,7 @@ func NewChain(cfg *TOMLConfig, opts ChainOpts) (Chain, error) { var _ Chain = (*chain)(nil) type chain struct { - utils.StartStopOnce + services.StateMachine id string cfg *TOMLConfig txm *txm.Txm @@ -386,13 +384,13 @@ func (c *chain) Close() error { func (c *chain) Ready() error { return multierr.Combine( - c.StartStopOnce.Ready(), + c.StateMachine.Ready(), c.txm.Ready(), ) } func (c *chain) HealthReport() map[string]error { - report := map[string]error{c.Name(): c.StartStopOnce.Healthy()} + report := map[string]error{c.Name(): c.Healthy()} services.CopyHealth(report, c.txm.HealthReport()) return report } diff --git a/pkg/solana/chain_test.go b/pkg/solana/chain_test.go index 33dc849bc..af87f0485 100644 --- a/pkg/solana/chain_test.go +++ b/pkg/solana/chain_test.go @@ -13,12 +13,12 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/smartcontractkit/chainlink-relay/pkg/utils" + "github.com/smartcontractkit/chainlink-common/pkg/config" + "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink-solana/pkg/solana/client" solcfg "github.com/smartcontractkit/chainlink-solana/pkg/solana/config" "github.com/smartcontractkit/chainlink-solana/pkg/solana/db" - - "github.com/smartcontractkit/chainlink-relay/pkg/logger" ) const TestSolanaGenesisHashTemplate = `{"jsonrpc":"2.0","result":"%s","id":1}` @@ -57,42 +57,42 @@ func TestSolanaChain_GetClient(t *testing.T) { clientCache: map[string]*verifiedCachedClient{}, } - cfg.Nodes = SolanaNodes([]*solcfg.Node{ - &solcfg.Node{ + cfg.Nodes = []*solcfg.Node{ + { Name: ptr("devnet"), - URL: utils.MustParseURL(mockServer.URL + "/1"), + URL: config.MustParseURL(mockServer.URL + "/1"), }, - &solcfg.Node{ + { Name: ptr("devnet"), - URL: utils.MustParseURL(mockServer.URL + "/2"), + URL: config.MustParseURL(mockServer.URL + "/2"), }, - }) + } _, err := testChain.getClient() assert.NoError(t, err) // random nodes (happy path, 1 valid + multiple invalid) - cfg.Nodes = SolanaNodes([]*solcfg.Node{ - &solcfg.Node{ + cfg.Nodes = []*solcfg.Node{ + { Name: ptr("devnet"), - URL: utils.MustParseURL(mockServer.URL + "/1"), + URL: config.MustParseURL(mockServer.URL + "/1"), }, - &solcfg.Node{ + { Name: ptr("devnet"), - URL: utils.MustParseURL(mockServer.URL + "/mismatch/1"), + URL: config.MustParseURL(mockServer.URL + "/mismatch/1"), }, - &solcfg.Node{ + { Name: ptr("devnet"), - URL: utils.MustParseURL(mockServer.URL + "/mismatch/2"), + URL: config.MustParseURL(mockServer.URL + "/mismatch/2"), }, - &solcfg.Node{ + { Name: ptr("devnet"), - URL: utils.MustParseURL(mockServer.URL + "/mismatch/3"), + URL: config.MustParseURL(mockServer.URL + "/mismatch/3"), }, - &solcfg.Node{ + { Name: ptr("devnet"), - URL: utils.MustParseURL(mockServer.URL + "/mismatch/4"), + URL: config.MustParseURL(mockServer.URL + "/mismatch/4"), }, - }) + } _, err = testChain.getClient() assert.NoError(t, err) @@ -102,16 +102,16 @@ func TestSolanaChain_GetClient(t *testing.T) { assert.Error(t, err) // no valid nodes to select from - cfg.Nodes = SolanaNodes([]*solcfg.Node{ - &solcfg.Node{ + cfg.Nodes = []*solcfg.Node{ + { Name: ptr("devnet"), - URL: utils.MustParseURL(mockServer.URL + "/mismatch/1"), + URL: config.MustParseURL(mockServer.URL + "/mismatch/1"), }, - &solcfg.Node{ + { Name: ptr("devnet"), - URL: utils.MustParseURL(mockServer.URL + "/mismatch/2"), + URL: config.MustParseURL(mockServer.URL + "/mismatch/2"), }, - }) + } _, err = testChain.getClient() assert.NoError(t, err) } diff --git a/pkg/solana/client/client_test.go b/pkg/solana/client/client_test.go index cc378f4fb..d4c4b4ae0 100644 --- a/pkg/solana/client/client_test.go +++ b/pkg/solana/client/client_test.go @@ -17,7 +17,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/smartcontractkit/chainlink-relay/pkg/logger" + "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-solana/pkg/solana/config" "github.com/smartcontractkit/chainlink-solana/pkg/solana/db" diff --git a/pkg/solana/client/test_helpers.go b/pkg/solana/client/test_helpers.go index e763607df..12374bee6 100644 --- a/pkg/solana/client/test_helpers.go +++ b/pkg/solana/client/test_helpers.go @@ -9,9 +9,10 @@ import ( "github.com/gagliardetto/solana-go" "github.com/gagliardetto/solana-go/rpc" - "github.com/smartcontractkit/chainlink-relay/pkg/utils" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/smartcontractkit/chainlink-common/pkg/utils" ) // SetupLocalSolNode sets up a local solana node via solana cli, and returns the url diff --git a/pkg/solana/client/test_helpers_test.go b/pkg/solana/client/test_helpers_test.go index c303888f0..f1f1dfffe 100644 --- a/pkg/solana/client/test_helpers_test.go +++ b/pkg/solana/client/test_helpers_test.go @@ -5,11 +5,12 @@ import ( "time" "github.com/gagliardetto/solana-go" - "github.com/smartcontractkit/chainlink-relay/pkg/logger" - "github.com/smartcontractkit/chainlink-solana/pkg/solana/config" - "github.com/smartcontractkit/chainlink-solana/pkg/solana/db" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink-solana/pkg/solana/config" + "github.com/smartcontractkit/chainlink-solana/pkg/solana/db" ) func TestSetupLocalSolNode_SimultaneousNetworks(t *testing.T) { diff --git a/pkg/solana/cmd/chainlink-solana/main.go b/pkg/solana/cmd/chainlink-solana/main.go index 707eea418..924dd5a2b 100644 --- a/pkg/solana/cmd/chainlink-solana/main.go +++ b/pkg/solana/cmd/chainlink-solana/main.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/go-plugin" "github.com/pelletier/go-toml/v2" - "github.com/smartcontractkit/chainlink-relay/pkg/loop" + "github.com/smartcontractkit/chainlink-common/pkg/loop" "github.com/smartcontractkit/chainlink-solana/pkg/solana" ) diff --git a/pkg/solana/config.go b/pkg/solana/config.go index 5f720e56c..822064edd 100644 --- a/pkg/solana/config.go +++ b/pkg/solana/config.go @@ -10,8 +10,8 @@ import ( "go.uber.org/multierr" "golang.org/x/exp/slices" - "github.com/smartcontractkit/chainlink-relay/pkg/config" - relaytypes "github.com/smartcontractkit/chainlink-relay/pkg/types" + "github.com/smartcontractkit/chainlink-common/pkg/config" + relaytypes "github.com/smartcontractkit/chainlink-common/pkg/types" solcfg "github.com/smartcontractkit/chainlink-solana/pkg/solana/config" soldb "github.com/smartcontractkit/chainlink-solana/pkg/solana/db" diff --git a/pkg/solana/config/config.go b/pkg/solana/config/config.go index c680b09fc..fd07bf57a 100644 --- a/pkg/solana/config/config.go +++ b/pkg/solana/config/config.go @@ -7,9 +7,7 @@ import ( "github.com/gagliardetto/solana-go/rpc" "go.uber.org/multierr" - relaycfg "github.com/smartcontractkit/chainlink-relay/pkg/config" - "github.com/smartcontractkit/chainlink-relay/pkg/utils" - + "github.com/smartcontractkit/chainlink-common/pkg/config" "github.com/smartcontractkit/chainlink-solana/pkg/solana/db" "github.com/smartcontractkit/chainlink-solana/pkg/solana/logger" ) @@ -76,10 +74,10 @@ type configSet struct { FeeBumpPeriod time.Duration } -var _ Config = (*config)(nil) +var _ Config = (*cfg)(nil) // Deprecated -type config struct { +type cfg struct { defaults configSet chain db.ChainCfg lggr logger.Logger @@ -87,15 +85,15 @@ type config struct { // NewConfig returns a Config with defaults overridden by dbcfg. // Deprecated -func NewConfig(dbcfg db.ChainCfg, lggr logger.Logger) *config { - return &config{ +func NewConfig(dbcfg db.ChainCfg, lggr logger.Logger) *cfg { + return &cfg{ defaults: defaultConfigSet, chain: dbcfg, lggr: lggr, } } -func (c *config) BalancePollPeriod() time.Duration { +func (c *cfg) BalancePollPeriod() time.Duration { ch := c.chain.BalancePollPeriod if ch != nil { return ch.Duration() @@ -103,7 +101,7 @@ func (c *config) BalancePollPeriod() time.Duration { return c.defaults.BalancePollPeriod } -func (c *config) ConfirmPollPeriod() time.Duration { +func (c *cfg) ConfirmPollPeriod() time.Duration { ch := c.chain.ConfirmPollPeriod if ch != nil { return ch.Duration() @@ -111,7 +109,7 @@ func (c *config) ConfirmPollPeriod() time.Duration { return c.defaults.ConfirmPollPeriod } -func (c *config) OCR2CachePollPeriod() time.Duration { +func (c *cfg) OCR2CachePollPeriod() time.Duration { ch := c.chain.OCR2CachePollPeriod if ch != nil { return ch.Duration() @@ -119,7 +117,7 @@ func (c *config) OCR2CachePollPeriod() time.Duration { return c.defaults.OCR2CachePollPeriod } -func (c *config) OCR2CacheTTL() time.Duration { +func (c *cfg) OCR2CacheTTL() time.Duration { ch := c.chain.OCR2CacheTTL if ch != nil { return ch.Duration() @@ -127,7 +125,7 @@ func (c *config) OCR2CacheTTL() time.Duration { return c.defaults.OCR2CacheTTL } -func (c *config) TxTimeout() time.Duration { +func (c *cfg) TxTimeout() time.Duration { ch := c.chain.TxTimeout if ch != nil { return ch.Duration() @@ -135,7 +133,7 @@ func (c *config) TxTimeout() time.Duration { return c.defaults.TxTimeout } -func (c *config) TxRetryTimeout() time.Duration { +func (c *cfg) TxRetryTimeout() time.Duration { ch := c.chain.TxRetryTimeout if ch != nil { return ch.Duration() @@ -143,7 +141,7 @@ func (c *config) TxRetryTimeout() time.Duration { return c.defaults.TxRetryTimeout } -func (c *config) TxConfirmTimeout() time.Duration { +func (c *cfg) TxConfirmTimeout() time.Duration { ch := c.chain.TxConfirmTimeout if ch != nil { return ch.Duration() @@ -151,7 +149,7 @@ func (c *config) TxConfirmTimeout() time.Duration { return c.defaults.TxConfirmTimeout } -func (c *config) SkipPreflight() bool { +func (c *cfg) SkipPreflight() bool { ch := c.chain.SkipPreflight if ch.Valid { return ch.Bool @@ -159,7 +157,7 @@ func (c *config) SkipPreflight() bool { return c.defaults.SkipPreflight } -func (c *config) Commitment() rpc.CommitmentType { +func (c *cfg) Commitment() rpc.CommitmentType { ch := c.chain.Commitment if ch.Valid { str := ch.String @@ -180,7 +178,7 @@ func (c *config) Commitment() rpc.CommitmentType { return c.defaults.Commitment } -func (c *config) FeeEstimatorMode() string { +func (c *cfg) FeeEstimatorMode() string { ch := c.chain.FeeEstimatorMode if ch.Valid { return strings.ToLower(ch.String) @@ -188,7 +186,7 @@ func (c *config) FeeEstimatorMode() string { return c.defaults.FeeEstimatorMode } -func (c *config) ComputeUnitPriceMax() uint64 { +func (c *cfg) ComputeUnitPriceMax() uint64 { ch := c.chain.ComputeUnitPriceMax if ch.Valid { if ch.Int64 >= 0 { @@ -199,7 +197,7 @@ func (c *config) ComputeUnitPriceMax() uint64 { return c.defaults.ComputeUnitPriceMax } -func (c *config) ComputeUnitPriceMin() uint64 { +func (c *cfg) ComputeUnitPriceMin() uint64 { ch := c.chain.ComputeUnitPriceMin if ch.Valid { if ch.Int64 >= 0 { @@ -210,7 +208,7 @@ func (c *config) ComputeUnitPriceMin() uint64 { return c.defaults.ComputeUnitPriceMin } -func (c *config) ComputeUnitPriceDefault() uint64 { +func (c *cfg) ComputeUnitPriceDefault() uint64 { ch := c.chain.ComputeUnitPriceDefault if ch.Valid { if ch.Int64 >= 0 { @@ -221,7 +219,7 @@ func (c *config) ComputeUnitPriceDefault() uint64 { return c.defaults.ComputeUnitPriceDefault } -func (c *config) MaxRetries() *uint { +func (c *cfg) MaxRetries() *uint { ch := c.chain.MaxRetries if ch.Valid { if ch.Int64 < 0 { @@ -234,7 +232,7 @@ func (c *config) MaxRetries() *uint { return c.defaults.MaxRetries } -func (c *config) FeeBumpPeriod() time.Duration { +func (c *cfg) FeeBumpPeriod() time.Duration { ch := c.chain.FeeBumpPeriod if ch != nil { return ch.Duration() @@ -243,13 +241,13 @@ func (c *config) FeeBumpPeriod() time.Duration { } type Chain struct { - BalancePollPeriod *utils.Duration - ConfirmPollPeriod *utils.Duration - OCR2CachePollPeriod *utils.Duration - OCR2CacheTTL *utils.Duration - TxTimeout *utils.Duration - TxRetryTimeout *utils.Duration - TxConfirmTimeout *utils.Duration + BalancePollPeriod *config.Duration + ConfirmPollPeriod *config.Duration + OCR2CachePollPeriod *config.Duration + OCR2CacheTTL *config.Duration + TxTimeout *config.Duration + TxRetryTimeout *config.Duration + TxConfirmTimeout *config.Duration SkipPreflight *bool Commitment *string MaxRetries *int64 @@ -257,30 +255,30 @@ type Chain struct { ComputeUnitPriceMax *uint64 ComputeUnitPriceMin *uint64 ComputeUnitPriceDefault *uint64 - FeeBumpPeriod *utils.Duration + FeeBumpPeriod *config.Duration } func (c *Chain) SetDefaults() { if c.BalancePollPeriod == nil { - c.BalancePollPeriod = utils.MustNewDuration(defaultConfigSet.BalancePollPeriod) + c.BalancePollPeriod = config.MustNewDuration(defaultConfigSet.BalancePollPeriod) } if c.ConfirmPollPeriod == nil { - c.ConfirmPollPeriod = utils.MustNewDuration(defaultConfigSet.ConfirmPollPeriod) + c.ConfirmPollPeriod = config.MustNewDuration(defaultConfigSet.ConfirmPollPeriod) } if c.OCR2CachePollPeriod == nil { - c.OCR2CachePollPeriod = utils.MustNewDuration(defaultConfigSet.OCR2CachePollPeriod) + c.OCR2CachePollPeriod = config.MustNewDuration(defaultConfigSet.OCR2CachePollPeriod) } if c.OCR2CacheTTL == nil { - c.OCR2CacheTTL = utils.MustNewDuration(defaultConfigSet.OCR2CacheTTL) + c.OCR2CacheTTL = config.MustNewDuration(defaultConfigSet.OCR2CacheTTL) } if c.TxTimeout == nil { - c.TxTimeout = utils.MustNewDuration(defaultConfigSet.TxTimeout) + c.TxTimeout = config.MustNewDuration(defaultConfigSet.TxTimeout) } if c.TxRetryTimeout == nil { - c.TxRetryTimeout = utils.MustNewDuration(defaultConfigSet.TxRetryTimeout) + c.TxRetryTimeout = config.MustNewDuration(defaultConfigSet.TxRetryTimeout) } if c.TxConfirmTimeout == nil { - c.TxConfirmTimeout = utils.MustNewDuration(defaultConfigSet.TxConfirmTimeout) + c.TxConfirmTimeout = config.MustNewDuration(defaultConfigSet.TxConfirmTimeout) } if c.SkipPreflight == nil { c.SkipPreflight = &defaultConfigSet.SkipPreflight @@ -305,24 +303,24 @@ func (c *Chain) SetDefaults() { c.ComputeUnitPriceDefault = &defaultConfigSet.ComputeUnitPriceDefault } if c.FeeBumpPeriod == nil { - c.FeeBumpPeriod = utils.MustNewDuration(defaultConfigSet.FeeBumpPeriod) + c.FeeBumpPeriod = config.MustNewDuration(defaultConfigSet.FeeBumpPeriod) } return } type Node struct { Name *string - URL *utils.URL + URL *config.URL } func (n *Node) ValidateConfig() (err error) { if n.Name == nil { - err = multierr.Append(err, relaycfg.ErrMissing{Name: "Name", Msg: "required for all nodes"}) + err = multierr.Append(err, config.ErrMissing{Name: "Name", Msg: "required for all nodes"}) } else if *n.Name == "" { - err = multierr.Append(err, relaycfg.ErrEmpty{Name: "Name", Msg: "required for all nodes"}) + err = multierr.Append(err, config.ErrEmpty{Name: "Name", Msg: "required for all nodes"}) } if n.URL == nil { - err = multierr.Append(err, relaycfg.ErrMissing{Name: "URL", Msg: "required for all nodes"}) + err = multierr.Append(err, config.ErrMissing{Name: "URL", Msg: "required for all nodes"}) } return } diff --git a/pkg/solana/db/db.go b/pkg/solana/db/db.go index 6fb7719ab..30c3e6a1a 100644 --- a/pkg/solana/db/db.go +++ b/pkg/solana/db/db.go @@ -8,7 +8,7 @@ import ( "gopkg.in/guregu/null.v4" - "github.com/smartcontractkit/chainlink-relay/pkg/utils" + "github.com/smartcontractkit/chainlink-common/pkg/config" ) type Node struct { @@ -22,13 +22,13 @@ type Node struct { // Deprecated type ChainCfg struct { - BalancePollPeriod *utils.Duration - ConfirmPollPeriod *utils.Duration - OCR2CachePollPeriod *utils.Duration - OCR2CacheTTL *utils.Duration - TxTimeout *utils.Duration - TxRetryTimeout *utils.Duration - TxConfirmTimeout *utils.Duration + BalancePollPeriod *config.Duration + ConfirmPollPeriod *config.Duration + OCR2CachePollPeriod *config.Duration + OCR2CacheTTL *config.Duration + TxTimeout *config.Duration + TxRetryTimeout *config.Duration + TxConfirmTimeout *config.Duration SkipPreflight null.Bool // to enable or disable preflight checks Commitment null.String MaxRetries null.Int @@ -37,7 +37,7 @@ type ChainCfg struct { ComputeUnitPriceMax null.Int ComputeUnitPriceMin null.Int ComputeUnitPriceDefault null.Int - FeeBumpPeriod *utils.Duration + FeeBumpPeriod *config.Duration } func (c *ChainCfg) Scan(value interface{}) error { diff --git a/pkg/solana/fees/recent_fees.go b/pkg/solana/fees/recent_fees.go index e20b6f912..e331a1314 100644 --- a/pkg/solana/fees/recent_fees.go +++ b/pkg/solana/fees/recent_fees.go @@ -6,7 +6,8 @@ import ( "sync" "time" - "github.com/smartcontractkit/chainlink-relay/pkg/utils" + "github.com/smartcontractkit/chainlink-common/pkg/services" + "github.com/smartcontractkit/chainlink-common/pkg/utils" "github.com/smartcontractkit/chainlink-solana/pkg/solana/config" ) @@ -17,7 +18,7 @@ var ( var _ Estimator = &recentFeeEstimator{} type recentFeeEstimator struct { - starter utils.StartStopOnce + starter services.StateMachine chStop chan struct{} done sync.WaitGroup diff --git a/pkg/solana/logger/logger.go b/pkg/solana/logger/logger.go index c19ecb968..819a75a7d 100644 --- a/pkg/solana/logger/logger.go +++ b/pkg/solana/logger/logger.go @@ -1,6 +1,6 @@ package logger -import "github.com/smartcontractkit/chainlink-relay/pkg/logger" +import "github.com/smartcontractkit/chainlink-common/pkg/logger" // Logger is an alias for backwards compatibility. type Logger = logger.Logger diff --git a/pkg/solana/monitor/balance.go b/pkg/solana/monitor/balance.go index bd6593240..d4b10dbdd 100644 --- a/pkg/solana/monitor/balance.go +++ b/pkg/solana/monitor/balance.go @@ -6,9 +6,10 @@ import ( "github.com/gagliardetto/solana-go" - "github.com/smartcontractkit/chainlink-relay/pkg/logger" - "github.com/smartcontractkit/chainlink-relay/pkg/types" - "github.com/smartcontractkit/chainlink-relay/pkg/utils" + "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink-common/pkg/services" + "github.com/smartcontractkit/chainlink-common/pkg/types" + "github.com/smartcontractkit/chainlink-common/pkg/utils" solanaClient "github.com/smartcontractkit/chainlink-solana/pkg/solana/client" ) @@ -43,7 +44,7 @@ func newBalanceMonitor(chainID string, cfg Config, lggr logger.Logger, ks Keysto } type balanceMonitor struct { - utils.StartStopOnce + services.StateMachine chainID string cfg Config lggr logger.Logger diff --git a/pkg/solana/monitor/balance_test.go b/pkg/solana/monitor/balance_test.go index db437cdb0..508661007 100644 --- a/pkg/solana/monitor/balance_test.go +++ b/pkg/solana/monitor/balance_test.go @@ -11,8 +11,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "github.com/smartcontractkit/chainlink-relay/pkg/logger" - "github.com/smartcontractkit/chainlink-relay/pkg/utils/tests" + "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" "github.com/smartcontractkit/chainlink-solana/pkg/solana/client/mocks" "github.com/smartcontractkit/chainlink-solana/pkg/solana/internal" ) diff --git a/pkg/solana/relay.go b/pkg/solana/relay.go index 9f86ffcee..c9e8c5a2f 100644 --- a/pkg/solana/relay.go +++ b/pkg/solana/relay.go @@ -10,13 +10,13 @@ import ( "github.com/smartcontractkit/libocr/offchainreporting2/reportingplugin/median" "github.com/smartcontractkit/libocr/offchainreporting2/types" - relaylogger "github.com/smartcontractkit/chainlink-relay/pkg/logger" - relaytypes "github.com/smartcontractkit/chainlink-relay/pkg/types" - "github.com/smartcontractkit/chainlink-relay/pkg/utils" - "github.com/smartcontractkit/chainlink-solana/pkg/solana/txm" + relaylogger "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink-common/pkg/services" + relaytypes "github.com/smartcontractkit/chainlink-common/pkg/types" "github.com/smartcontractkit/chainlink-solana/pkg/solana/client" "github.com/smartcontractkit/chainlink-solana/pkg/solana/logger" + "github.com/smartcontractkit/chainlink-solana/pkg/solana/txm" ) var _ TxManager = (*txm.Txm)(nil) @@ -143,7 +143,7 @@ func (r *Relayer) NewFunctionsProvider(rargs relaytypes.RelayArgs, pargs relayty var _ relaytypes.ConfigProvider = &configProvider{} type configProvider struct { - utils.StartStopOnce + services.StateMachine chainID string programID, storeProgramID, stateID solana.PublicKey stateCache *StateCache diff --git a/pkg/solana/report_test.go b/pkg/solana/report_test.go index b27d4c9fc..6209ddf85 100644 --- a/pkg/solana/report_test.go +++ b/pkg/solana/report_test.go @@ -9,12 +9,13 @@ import ( "time" bin "github.com/gagliardetto/binary" - "github.com/smartcontractkit/chainlink-relay/pkg/utils" "github.com/smartcontractkit/libocr/commontypes" "github.com/smartcontractkit/libocr/offchainreporting2/reportingplugin/median" "github.com/smartcontractkit/libocr/offchainreporting2/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/smartcontractkit/chainlink-common/pkg/utils" ) func TestBuildReport(t *testing.T) { diff --git a/pkg/solana/state_cache.go b/pkg/solana/state_cache.go index 563acae4c..18f1e7634 100644 --- a/pkg/solana/state_cache.go +++ b/pkg/solana/state_cache.go @@ -12,7 +12,8 @@ import ( "github.com/gagliardetto/solana-go" "github.com/gagliardetto/solana-go/rpc" - "github.com/smartcontractkit/chainlink-relay/pkg/utils" + "github.com/smartcontractkit/chainlink-common/pkg/services" + "github.com/smartcontractkit/chainlink-common/pkg/utils" "github.com/smartcontractkit/chainlink-solana/pkg/solana/client" "github.com/smartcontractkit/chainlink-solana/pkg/solana/config" @@ -24,7 +25,7 @@ var ( ) type StateCache struct { - utils.StartStopOnce + services.StateMachine // on-chain program + 2x state accounts (state + transmissions) StateID solana.PublicKey diff --git a/pkg/solana/transmissions_cache.go b/pkg/solana/transmissions_cache.go index e2e27ec57..adea65104 100644 --- a/pkg/solana/transmissions_cache.go +++ b/pkg/solana/transmissions_cache.go @@ -10,7 +10,8 @@ import ( "github.com/gagliardetto/solana-go/rpc" "github.com/pkg/errors" - "github.com/smartcontractkit/chainlink-relay/pkg/utils" + "github.com/smartcontractkit/chainlink-common/pkg/services" + "github.com/smartcontractkit/chainlink-common/pkg/utils" "github.com/smartcontractkit/chainlink-solana/pkg/solana/client" "github.com/smartcontractkit/chainlink-solana/pkg/solana/config" @@ -18,6 +19,8 @@ import ( ) type TransmissionsCache struct { + services.StateMachine + // on-chain program + 2x state accounts (state + transmissions) TransmissionsID solana.PublicKey @@ -34,8 +37,6 @@ type TransmissionsCache struct { done chan struct{} ctx context.Context cancel context.CancelFunc - - utils.StartStopOnce } func NewTransmissionsCache(transmissionsID solana.PublicKey, cfg config.Config, reader client.Reader, lggr logger.Logger) *TransmissionsCache { diff --git a/pkg/solana/transmitter.go b/pkg/solana/transmitter.go index 8c71b7452..3d4eb971d 100644 --- a/pkg/solana/transmitter.go +++ b/pkg/solana/transmitter.go @@ -6,9 +6,10 @@ import ( "github.com/gagliardetto/solana-go" "github.com/pkg/errors" - "github.com/smartcontractkit/chainlink-relay/pkg/utils" "github.com/smartcontractkit/libocr/offchainreporting2/types" + "github.com/smartcontractkit/chainlink-common/pkg/utils" + "github.com/smartcontractkit/chainlink-solana/pkg/solana/client" "github.com/smartcontractkit/chainlink-solana/pkg/solana/logger" ) diff --git a/pkg/solana/txm/pendingtx_test.go b/pkg/solana/txm/pendingtx_test.go index 1017572fd..5639bff59 100644 --- a/pkg/solana/txm/pendingtx_test.go +++ b/pkg/solana/txm/pendingtx_test.go @@ -12,12 +12,12 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - relayutils "github.com/smartcontractkit/chainlink-relay/pkg/utils" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" ) func TestPendingTxContext(t *testing.T) { var wg sync.WaitGroup - ctx := relayutils.Context(t) + ctx := tests.Context(t) newProcess := func(i int) (solana.Signature, context.CancelFunc) { // make random signature @@ -66,7 +66,7 @@ func TestPendingTxContext(t *testing.T) { } func TestPendingTxContext_expired(t *testing.T) { - _, cancel := context.WithCancel(relayutils.Context(t)) + _, cancel := context.WithCancel(tests.Context(t)) sig := solana.Signature{} txs := newPendingTxContext() diff --git a/pkg/solana/txm/txm.go b/pkg/solana/txm/txm.go index 02a86561a..d4ac9389d 100644 --- a/pkg/solana/txm/txm.go +++ b/pkg/solana/txm/txm.go @@ -12,13 +12,13 @@ import ( "github.com/google/uuid" "github.com/pkg/errors" - "github.com/smartcontractkit/chainlink-relay/pkg/services" + "github.com/smartcontractkit/chainlink-common/pkg/services" solanaClient "github.com/smartcontractkit/chainlink-solana/pkg/solana/client" "github.com/smartcontractkit/chainlink-solana/pkg/solana/config" "github.com/smartcontractkit/chainlink-solana/pkg/solana/fees" "github.com/smartcontractkit/chainlink-solana/pkg/solana/logger" - relayutils "github.com/smartcontractkit/chainlink-relay/pkg/utils" + relayutils "github.com/smartcontractkit/chainlink-common/pkg/utils" ) const ( @@ -37,7 +37,7 @@ type SimpleKeystore interface { // Txm manages transactions for the solana blockchain. // simple implementation with no persistently stored txs type Txm struct { - starter relayutils.StartStopOnce + starter services.StateMachine lggr logger.Logger chSend chan pendingTx chSim chan pendingTx @@ -60,15 +60,14 @@ type pendingTx struct { // NewTxm creates a txm. Uses simulation so should only be used to send txes to trusted contracts i.e. OCR. func NewTxm(chainID string, tc func() (solanaClient.ReaderWriter, error), cfg config.Config, ks SimpleKeystore, lggr logger.Logger) *Txm { return &Txm{ - starter: relayutils.StartStopOnce{}, - lggr: lggr, - chSend: make(chan pendingTx, MaxQueueLen), // queue can support 1000 pending txs - chSim: make(chan pendingTx, MaxQueueLen), // queue can support 1000 pending txs - chStop: make(chan struct{}), - cfg: cfg, - txs: newPendingTxContextWithProm(chainID), - ks: ks, - client: relayutils.NewLazyLoad(tc), + lggr: lggr, + chSend: make(chan pendingTx, MaxQueueLen), // queue can support 1000 pending txs + chSim: make(chan pendingTx, MaxQueueLen), // queue can support 1000 pending txs + chStop: make(chan struct{}), + cfg: cfg, + txs: newPendingTxContextWithProm(chainID), + ks: ks, + client: relayutils.NewLazyLoad(tc), } } diff --git a/pkg/solana/txm/txm_internal_test.go b/pkg/solana/txm/txm_internal_test.go index c7312c298..8adb606e6 100644 --- a/pkg/solana/txm/txm_internal_test.go +++ b/pkg/solana/txm/txm_internal_test.go @@ -25,9 +25,9 @@ import ( "github.com/smartcontractkit/chainlink-solana/pkg/solana/fees" keyMocks "github.com/smartcontractkit/chainlink-solana/pkg/solana/txm/mocks" - relayconfig "github.com/smartcontractkit/chainlink-relay/pkg/config" - "github.com/smartcontractkit/chainlink-relay/pkg/logger" - relayutils "github.com/smartcontractkit/chainlink-relay/pkg/utils" + relayconfig "github.com/smartcontractkit/chainlink-common/pkg/config" + "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" ) type soltxmProm struct { @@ -91,7 +91,7 @@ func TestTxm(t *testing.T) { id := "mocknet" t.Log("Starting new iteration") - ctx := relayutils.Context(t) + ctx := tests.Context(t) lggr := logger.Test(t) cfg := config.NewConfig(db.ChainCfg{}, lggr) diff --git a/pkg/solana/txm/txm_race_test.go b/pkg/solana/txm/txm_race_test.go index c796c6df5..13d54b907 100644 --- a/pkg/solana/txm/txm_race_test.go +++ b/pkg/solana/txm/txm_race_test.go @@ -11,8 +11,8 @@ import ( solanaGo "github.com/gagliardetto/solana-go" "go.uber.org/zap/zapcore" - "github.com/smartcontractkit/chainlink-relay/pkg/logger" - "github.com/smartcontractkit/chainlink-relay/pkg/utils" + "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" solanaClient "github.com/smartcontractkit/chainlink-solana/pkg/solana/client" clientmocks "github.com/smartcontractkit/chainlink-solana/pkg/solana/client/mocks" @@ -67,7 +67,7 @@ func TestTxm_SendWithRetry_Race(t *testing.T) { txm.fee = fee _, _, _, err := txm.sendWithRetry( - utils.Context(t), + tests.Context(t), tx, txRetryDuration, ) @@ -227,4 +227,4 @@ func TestTxm_SendWithRetry_Race(t *testing.T) { testRunner(t, client) }) -} \ No newline at end of file +} diff --git a/pkg/solana/txm/txm_test.go b/pkg/solana/txm/txm_test.go index c56574090..c513e6d9b 100644 --- a/pkg/solana/txm/txm_test.go +++ b/pkg/solana/txm/txm_test.go @@ -20,13 +20,13 @@ import ( "github.com/smartcontractkit/chainlink-solana/pkg/solana/txm" keyMocks "github.com/smartcontractkit/chainlink-solana/pkg/solana/txm/mocks" - relayconfig "github.com/smartcontractkit/chainlink-relay/pkg/config" - "github.com/smartcontractkit/chainlink-relay/pkg/logger" - relayutils "github.com/smartcontractkit/chainlink-relay/pkg/utils" + relayconfig "github.com/smartcontractkit/chainlink-common/pkg/config" + "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink-common/pkg/utils/tests" ) func TestTxm_Integration(t *testing.T) { - ctx := relayutils.Context(t) + ctx := tests.Context(t) url := solanaClient.SetupLocalSolNode(t) // setup key @@ -59,7 +59,7 @@ func TestTxm_Integration(t *testing.T) { // set up txm lggr := logger.Test(t) - confirmDuration, err := relayutils.NewDuration(500 * time.Millisecond) + confirmDuration, err := config.NewDuration(500 * time.Millisecond) require.NoError(t, err) cfg := config.NewConfig(db.ChainCfg{ ConfirmPollPeriod: &confirmDuration,