Skip to content

Commit

Permalink
SOM: balance monitoring (#654)
Browse files Browse the repository at this point in the history
* add gitignore

* reorgnization + renaming

* update mocks

* finish renaming + splitting to feed balances

* cleanup code + add test case

* add test to balances source

* add test for txresults

* refactor: new network monitor structure

* bump common: stable commit

* bump core: compilation
  • Loading branch information
aalu1418 committed Apr 16, 2024
1 parent fe4ac30 commit c808024
Show file tree
Hide file tree
Showing 41 changed files with 1,450 additions and 562 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/relay.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ jobs:
git diff --stat --exit-code
- name: Install Solana CLI
run: ./scripts/install-solana-ci.sh
- name: Compilation check
run: go test -run=xxx ./... # check compilation across tests + relayer / monitoring go code without running
- name: Build
run: go build -v ./pkg/...
- name: Test
Expand All @@ -35,4 +37,4 @@ jobs:
name: go-relay-test-results
path: |
./race_coverage.txt
./integration_coverage.txt
./integration_coverage.txt
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,8 @@ overrides.toml
*report.json
*.out
*coverage*
eslint-report.json
eslint-report.json
.run.id

# go work files
go.work*
3 changes: 3 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@

# relayer ownership
/pkg @smartcontractkit/bix-build

# monitoring ownership
/pkg/monitoring @smartcontractkit/realtime
35 changes: 24 additions & 11 deletions cmd/monitoring/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import (
"github.com/gagliardetto/solana-go/rpc"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
relayMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring"
commonMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring"

"github.com/smartcontractkit/chainlink-solana/pkg/monitoring"
"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/config"
"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/exporter"
"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/metrics"
)

func main() {
Expand All @@ -23,7 +26,7 @@ func main() {
}
}()

chainConfig, err := monitoring.ParseSolanaConfig()
chainConfig, err := config.ParseSolanaConfig()
if err != nil {
log.Fatalw("failed to parse solana-specific config", "error", err)
}
Expand All @@ -40,31 +43,41 @@ func main() {
logger.With(log, "component", "source-txresults"),
)

monitor, err := relayMonitoring.NewMonitor(
monitor, err := commonMonitoring.NewMonitor(
context.Background(),
log,
chainConfig,
envelopeSourceFactory,
txResultsSourceFactory,
monitoring.SolanaFeedsParser,
monitoring.SolanaNodesParser,
config.SolanaFeedsParser,
config.SolanaNodesParser,
)
if err != nil {
log.Fatalw("failed to build monitor", "error", err)
return
}

balancesSourceFactory := monitoring.NewBalancesSourceFactory(
feedBalancesSourceFactory := monitoring.NewFeedBalancesSourceFactory(
chainReader,
logger.With(log, "component", "source-balances"),
logger.With(log, "component", "source-feed-balances"),
)
monitor.SourceFactories = append(monitor.SourceFactories, balancesSourceFactory)
nodeBalancesSourceFactory := monitoring.NewNodeBalancesSourceFactory(
chainReader,
logger.With(log, "component", "source-node-balances"),
)
monitor.SourceFactories = append(monitor.SourceFactories, feedBalancesSourceFactory)
monitor.NetworkSourceFactories = append(monitor.NetworkSourceFactories, nodeBalancesSourceFactory)

promExporterFactory := monitoring.NewPrometheusExporterFactory(
feedBalancesExporterFactory := exporter.NewFeedBalancesFactory(
logger.With(log, "component", "solana-prom-exporter"),
metrics.NewFeedBalances(logger.With(log, "component", "solana-metrics")),
)
nodeBalancesExporterFactory := exporter.NewNodeBalancesFactory(
logger.With(log, "component", "solana-prom-exporter"),
monitoring.NewMetrics(logger.With(log, "component", "solana-metrics")),
metrics.NewNodeBalances,
)
monitor.ExporterFactories = append(monitor.ExporterFactories, promExporterFactory)
monitor.ExporterFactories = append(monitor.ExporterFactories, feedBalancesExporterFactory)
monitor.NetworkExporterFactories = append(monitor.NetworkExporterFactories, nodeBalancesExporterFactory)

monitor.Run()
log.Infow("monitor stopped")
Expand Down
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/smartcontractkit/chainlink-solana
go 1.21

require (
github.com/davecgh/go-spew v1.1.1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/gagliardetto/binary v0.7.1
github.com/gagliardetto/gofuzz v1.2.2
github.com/gagliardetto/solana-go v1.4.1-0.20220428092759-5250b4abbb27
Expand All @@ -15,8 +15,8 @@ require (
github.com/pelletier/go-toml/v2 v2.1.1
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.17.0
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240312172711-7ec0dab0a498
github.com/smartcontractkit/libocr v0.0.0-20240112202000-6359502d2ff1
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240415221539-61f49438443a
github.com/smartcontractkit/libocr v0.0.0-20240326191951-2bbe9382d052
github.com/stretchr/testify v1.9.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.26.0
Expand All @@ -39,7 +39,8 @@ require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/confluentinc/confluent-kafka-go/v2 v2.3.0 // indirect
github.com/dfuse-io/logging v0.0.0-20210109005628-b97a57253f70 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/ethereum/go-ethereum v1.13.8 // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/fxamacker/cbor/v2 v2.5.0 // indirect
github.com/go-json-experiment/json v0.0.0-20231102232822-2e55bd4e08b0 // indirect
github.com/go-logr/logr v1.2.4 // indirect
Expand All @@ -53,6 +54,7 @@ require (
github.com/hako/durafmt v0.0.0-20200710122514-c0fb7b4da026 // indirect
github.com/hashicorp/go-hclog v1.5.0 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.15.15 // indirect
Expand Down
18 changes: 12 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsr
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dfuse-io/logging v0.0.0-20201110202154-26697de88c79/go.mod h1:V+ED4kT/t/lKtH99JQmKIb0v9WL3VaYkJ36CfHlVECI=
github.com/dfuse-io/logging v0.0.0-20210109005628-b97a57253f70 h1:CuJS05R9jmNlUK8GOxrEELPbfXm0EuGh/30LjkjN5vo=
github.com/dfuse-io/logging v0.0.0-20210109005628-b97a57253f70/go.mod h1:EoK/8RFbMEteaCaz89uessDTnCWjbbcr+DXcBh4el5o=
Expand All @@ -133,10 +134,13 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/envoyproxy/protoc-gen-validate v1.0.2 h1:QkIBuU5k+x7/QXPvPPnWXWlCdaBFApVqftFV6k087DA=
github.com/envoyproxy/protoc-gen-validate v1.0.2/go.mod h1:GpiZQP3dDbg4JouG/NNS7QWXpgx6x8QiMKdmN72jogE=
github.com/ethereum/go-ethereum v1.13.8 h1:1od+thJel3tM52ZUNQwvpYOeRHlbkVFZ5S8fhi0Lgsg=
github.com/ethereum/go-ethereum v1.13.8/go.mod h1:sc48XYQxCzH3fG9BcrXCOOgQk2JfZzNAmIKnceogzsA=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
github.com/fatih/color v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
github.com/fatih/color v1.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w=
github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fxamacker/cbor/v2 v2.5.0 h1:oHsG0V/Q6E/wqTS2O1Cozzsy69nqCiguo5Q1a1ADivE=
github.com/fxamacker/cbor/v2 v2.5.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrtAnWBwBCVo=
Expand Down Expand Up @@ -277,6 +281,8 @@ github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2p
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE=
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
github.com/holiman/uint256 v1.2.4 h1:jUc4Nk8fm9jZabQuqr2JzednajVmBpC+oiTiXZJEApU=
github.com/holiman/uint256 v1.2.4/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
Expand Down Expand Up @@ -438,14 +444,14 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240312172711-7ec0dab0a498 h1:WeLb67RVd0lqdbm8qJ/LqrcfoLr7PoMjzi9wGy7ocqc=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240312172711-7ec0dab0a498/go.mod h1:8sn4HEfG8lR/D1Ov0yPHsY4kOleDKZKh2r8Op4oaAFE=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240415221539-61f49438443a h1:TNy4hMoRWCoq9KzrJ0G1aaX1sY75LisvwvVHl71vWPo=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240415221539-61f49438443a/go.mod h1:kstYjAGqBswdZpl7YkSPeXBDVwaY1VaR6tUMPWl8ykA=
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=
github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f/go.mod h1:MvMXoufZAtqExNexqi4cjrNYE9MefKddKylxjS+//n0=
github.com/smartcontractkit/libocr v0.0.0-20240112202000-6359502d2ff1 h1:3y9WsXkZ5lxFrmfH7DQHs/q308lylKId5l/3VC0QAdM=
github.com/smartcontractkit/libocr v0.0.0-20240112202000-6359502d2ff1/go.mod h1:kC0qmVPUaVkFqGiZMNhmRmjdphuUmeyLEdlWFOQzFWI=
github.com/smartcontractkit/libocr v0.0.0-20240326191951-2bbe9382d052 h1:1WFjrrVrWoQ9UpVMh7Mx4jDpzhmo1h8hFUKd9awIhIU=
github.com/smartcontractkit/libocr v0.0.0-20240326191951-2bbe9382d052/go.mod h1:SJEZCHgMCAzzBvo9vMV2DQ9onfEcIJCYSViyP4JI6c4=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ require (
github.com/lib/pq v1.10.9
github.com/onsi/gomega v1.30.0
github.com/rs/zerolog v1.30.0
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240405173118-f5bf144ec6b3
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240415221539-61f49438443a
github.com/smartcontractkit/chainlink-solana v1.0.3-0.20240216142700-c5869534c19e
github.com/smartcontractkit/chainlink-testing-framework v1.28.2
github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20240412213018-3896768a601d
github.com/smartcontractkit/chainlink/v2 v2.10.0-beta0.0.20240412213018-3896768a601d
github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20240415213707-06bad6e44ff7
github.com/smartcontractkit/chainlink/v2 v2.10.0-beta0.0.20240415213707-06bad6e44ff7
github.com/smartcontractkit/libocr v0.0.0-20240326191951-2bbe9382d052
github.com/stretchr/testify v1.9.0
github.com/testcontainers/testcontainers-go v0.28.0
Expand Down
12 changes: 6 additions & 6 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1413,8 +1413,8 @@ github.com/smartcontractkit/chain-selectors v1.0.10 h1:t9kJeE6B6G+hKD0GYR4kGJSCq
github.com/smartcontractkit/chain-selectors v1.0.10/go.mod h1:d4Hi+E1zqjy9HqMkjBE5q1vcG9VGgxf5VxiRHfzi2kE=
github.com/smartcontractkit/chainlink-automation v1.0.3 h1:h/ijT0NiyV06VxYVgcNfsE3+8OEzT3Q0Z9au0z1BPWs=
github.com/smartcontractkit/chainlink-automation v1.0.3/go.mod h1:RjboV0Qd7YP+To+OrzHGXaxUxoSONveCoAK2TQ1INLU=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240405173118-f5bf144ec6b3 h1:LCVHf/ooB4HDkgfLUq+jK4CuCr6SsdNCQZt3/etJ8ms=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240405173118-f5bf144ec6b3/go.mod h1:kstYjAGqBswdZpl7YkSPeXBDVwaY1VaR6tUMPWl8ykA=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240415221539-61f49438443a h1:TNy4hMoRWCoq9KzrJ0G1aaX1sY75LisvwvVHl71vWPo=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240415221539-61f49438443a/go.mod h1:kstYjAGqBswdZpl7YkSPeXBDVwaY1VaR6tUMPWl8ykA=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240213120401-01a23955f9f8 h1:I326nw5GwHQHsLKHwtu5Sb9EBLylC8CfUd7BFAS0jtg=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240213120401-01a23955f9f8/go.mod h1:a65NtrK4xZb01mf0dDNghPkN2wXgcqFQ55ADthVBgMc=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240220203239-09be0ea34540 h1:xFSv8561jsLtF6gYZr/zW2z5qUUAkcFkApin2mnbYTo=
Expand All @@ -1427,10 +1427,10 @@ github.com/smartcontractkit/chainlink-testing-framework v1.28.2 h1:H4/RW9J3EmHi4
github.com/smartcontractkit/chainlink-testing-framework v1.28.2/go.mod h1:jN+HgXbriq6fKRlIqLw9F3I81aYImV6kBJkIfz0mdIA=
github.com/smartcontractkit/chainlink-vrf v0.0.0-20231120191722-fef03814f868 h1:FFdvEzlYwcuVHkdZ8YnZR/XomeMGbz5E2F2HZI3I3w8=
github.com/smartcontractkit/chainlink-vrf v0.0.0-20231120191722-fef03814f868/go.mod h1:Kn1Hape05UzFZ7bOUnm3GVsHzP0TNrVmpfXYNHdqGGs=
github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20240412213018-3896768a601d h1:lezN+NmEUGfSfnxuhWDnSRcYalW8VtnS7pBlTWuEcmo=
github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20240412213018-3896768a601d/go.mod h1:GgCQMcLCcgbZlgIpjof3qw0Bf/MQh+opDOFg1Q/Wr/c=
github.com/smartcontractkit/chainlink/v2 v2.10.0-beta0.0.20240412213018-3896768a601d h1:jrftfc8rLcuai8yDBct5jEBAq4sfyevKTXdgq4XiA+U=
github.com/smartcontractkit/chainlink/v2 v2.10.0-beta0.0.20240412213018-3896768a601d/go.mod h1:Lh0bjLqR5Vjug8JxXkwU31+A4L3S5+Dg4+jN2W7MH2g=
github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20240415213707-06bad6e44ff7 h1:/EW/44obUyAXuha+K89RHJJ5zLLwho500rNPwB2QyGU=
github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20240415213707-06bad6e44ff7/go.mod h1:YnDzdGyqoqUHUYNf/9c2k79WIQDT69qOePd+s8UcboU=
github.com/smartcontractkit/chainlink/v2 v2.10.0-beta0.0.20240415213707-06bad6e44ff7 h1:taia8w1/Tmg8FbwV+ZEY003gJDs5jbfWuiExd0NIQOE=
github.com/smartcontractkit/chainlink/v2 v2.10.0-beta0.0.20240415213707-06bad6e44ff7/go.mod h1:pLFAn8V6R43E1UnjlyHLx+AizzqFTfcDCDub2zVprKA=
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=
Expand Down
1 change: 1 addition & 0 deletions pkg/monitoring/chain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
pkgSolana "github.com/smartcontractkit/chainlink-solana/pkg/solana"
)

//go:generate mockery --name ChainReader --output ./mocks/
type ChainReader interface {
GetState(ctx context.Context, account solana.PublicKey, commitment rpc.CommitmentType) (state pkgSolana.State, blockHeight uint64, err error)
GetLatestTransmission(ctx context.Context, account solana.PublicKey, commitment rpc.CommitmentType) (answer pkgSolana.Answer, blockHeight uint64, err error)
Expand Down
6 changes: 3 additions & 3 deletions pkg/monitoring/config.go → pkg/monitoring/config/config.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package monitoring
package config

import (
"fmt"
"net/url"
"os"
"time"

relayMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring"
commonMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring"
)

type SolanaConfig struct {
Expand All @@ -18,7 +18,7 @@ type SolanaConfig struct {
PollInterval time.Duration
}

var _ relayMonitoring.ChainConfig = SolanaConfig{}
var _ commonMonitoring.ChainConfig = SolanaConfig{}

func (s SolanaConfig) GetRPCEndpoint() string { return s.RPCEndpoint }
func (s SolanaConfig) GetNetworkName() string { return s.NetworkName }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package monitoring
package config

import (
"encoding/json"
Expand All @@ -8,7 +8,7 @@ import (

"github.com/gagliardetto/solana-go"

relayMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring"
commonMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring"
)

type SolanaFeedConfig struct {
Expand All @@ -30,7 +30,7 @@ type SolanaFeedConfig struct {
StateAccount solana.PublicKey `json:"-"`
}

var _ relayMonitoring.FeedConfig = SolanaFeedConfig{}
var _ commonMonitoring.FeedConfig = SolanaFeedConfig{}

// GetID returns the state account's address as that uniquely
// identifies a feed on Solana. In Solana, a program is stateless and we
Expand Down Expand Up @@ -104,13 +104,13 @@ func (s SolanaFeedConfig) ToMapping() map[string]interface{} {
}
}

func SolanaFeedsParser(buf io.ReadCloser) ([]relayMonitoring.FeedConfig, error) {
func SolanaFeedsParser(buf io.ReadCloser) ([]commonMonitoring.FeedConfig, error) {
rawFeeds := []SolanaFeedConfig{}
decoder := json.NewDecoder(buf)
if err := decoder.Decode(&rawFeeds); err != nil {
return nil, fmt.Errorf("unable to unmarshal feeds config data: %w", err)
}
feeds := make([]relayMonitoring.FeedConfig, len(rawFeeds))
feeds := make([]commonMonitoring.FeedConfig, len(rawFeeds))
for i, rawFeed := range rawFeeds {
contractAddress, err := solana.PublicKeyFromBase58(rawFeed.ContractAddressBase58)
if err != nil {
Expand All @@ -129,7 +129,7 @@ func SolanaFeedsParser(buf io.ReadCloser) ([]relayMonitoring.FeedConfig, error)
return nil, fmt.Errorf("failed to parse multiply '%s' into a big.Int", rawFeed.MultiplyRaw)
}
// NOTE: multiply is not required so if a parse error occurs, we'll use 0.
feeds[i] = relayMonitoring.FeedConfig(SolanaFeedConfig{
feeds[i] = commonMonitoring.FeedConfig(SolanaFeedConfig{
rawFeed.Name,
rawFeed.Path,
rawFeed.Symbol,
Expand Down
61 changes: 61 additions & 0 deletions pkg/monitoring/config/node_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package config

import (
"encoding/json"
"fmt"
"io"

"github.com/gagliardetto/solana-go"
"github.com/smartcontractkit/libocr/offchainreporting2/types"

commonMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring"
)

type SolanaNodeConfig struct {
ID string `json:"id,omitempty"`
NodeAddress []string `json:"nodeAddress,omitempty"`
}

func (s SolanaNodeConfig) GetName() string {
return s.ID
}

func (s SolanaNodeConfig) GetAccount() types.Account {
address := ""
if len(s.NodeAddress) != 0 {
address = s.NodeAddress[0]
}
return types.Account(address)
}

func (s SolanaNodeConfig) PublicKey() (solana.PublicKey, error) {
return solana.PublicKeyFromBase58(string(s.GetAccount()))
}

func SolanaNodesParser(buf io.ReadCloser) ([]commonMonitoring.NodeConfig, error) {
rawNodes := []SolanaNodeConfig{}
decoder := json.NewDecoder(buf)
if err := decoder.Decode(&rawNodes); err != nil {
return nil, fmt.Errorf("unable to unmarshal nodes config data: %w", err)
}
nodes := make([]commonMonitoring.NodeConfig, len(rawNodes))
for i, rawNode := range rawNodes {
nodes[i] = rawNode
}
return nodes, nil
}

func MakeSolanaNodeConfigs(in []commonMonitoring.NodeConfig) (out []SolanaNodeConfig, err error) {
for i := range in {
if in[i] == nil {
return nil, fmt.Errorf("node config is nil")
}

cfg, ok := in[i].(SolanaNodeConfig)
if !ok {
return nil, fmt.Errorf("expected NodeConfig to be of type config.SolanaFeedConfig not %T - node name %s", in[i], in[i].GetName())
}
out = append(out, cfg)
}
return out, nil
}

0 comments on commit c808024

Please sign in to comment.