From 79995afe7bd3479e14010e5fa81f4f726dd3c73b Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Tue, 10 Oct 2023 08:50:44 -0500 Subject: [PATCH] BCF-2685: move LOOPP command from core --- go.mod | 5 +- go.sum | 7 +-- integration-tests/go.mod | 8 +-- integration-tests/go.sum | 12 ++-- pkg/solana/cmd/chainlink-solana/main.go | 75 +++++++++++++++++++++++++ 5 files changed, 90 insertions(+), 17 deletions(-) create mode 100644 pkg/solana/cmd/chainlink-solana/main.go diff --git a/go.mod b/go.mod index 66bd53cd9..c3e2ea150 100644 --- a/go.mod +++ b/go.mod @@ -9,10 +9,11 @@ require ( github.com/gagliardetto/solana-go v1.4.1-0.20220428092759-5250b4abbb27 github.com/gagliardetto/treeout v0.1.4 github.com/google/uuid v1.3.1 + github.com/hashicorp/go-plugin v1.5.2 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.20231016132219-9c6fdb379595 + github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231017172544-b4fc52327846 github.com/smartcontractkit/libocr v0.0.0-20230925165524-ffa38fe11ef8 github.com/stretchr/testify v1.8.4 go.uber.org/multierr v1.11.0 @@ -42,7 +43,6 @@ require ( github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.0 // indirect github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.0.0-rc.3 // indirect github.com/hashicorp/go-hclog v1.5.0 // indirect - github.com/hashicorp/go-plugin v1.5.2 // indirect github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb // indirect github.com/jpillora/backoff v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect @@ -79,7 +79,6 @@ require ( go.opentelemetry.io/otel/metric v1.19.0 // indirect go.opentelemetry.io/otel/sdk v1.19.0 // indirect go.opentelemetry.io/otel/trace v1.19.0 // indirect - go.uber.org/atomic v1.10.0 // indirect go.uber.org/ratelimit v0.2.0 // indirect golang.org/x/crypto v0.13.0 // indirect golang.org/x/net v0.15.0 // indirect diff --git a/go.sum b/go.sum index 941b80637..1b8a69bb4 100644 --- a/go.sum +++ b/go.sum @@ -423,8 +423,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.20231016132219-9c6fdb379595 h1:a6GfS0N4/7X5YQAdne0TLcdSA7w5UwJ1dG0wx6tP3GY= -github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231016132219-9c6fdb379595/go.mod h1:mV+ayN6figopkI+9OwHUbBdYMhsrXa+CDvCkEM3FNt0= +github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231017172544-b4fc52327846 h1:3KikrKcUFDjZJSdICTxFnc2oaW3X4jTgcxoycmzQ3Mg= +github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231017172544-b4fc52327846/go.mod h1:mV+ayN6figopkI+9OwHUbBdYMhsrXa+CDvCkEM3FNt0= 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= @@ -506,9 +506,8 @@ go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqe go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= +go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= -go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ= -go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= diff --git a/integration-tests/go.mod b/integration-tests/go.mod index 965bd8228..c7ad1b0f3 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -16,11 +16,11 @@ require ( github.com/rs/zerolog v1.30.0 github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b github.com/smartcontractkit/chainlink-env v0.38.3 - github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231016132219-9c6fdb379595 - github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231016132516-795ee7ce8d00 + github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231017172544-b4fc52327846 + github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231017172647-67d91d916f48 github.com/smartcontractkit/chainlink-testing-framework v1.17.12-0.20231016091231-25809996fbd4 - github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20231016132655-7950ae7befec - github.com/smartcontractkit/chainlink/v2 v2.5.1-0.20231016132655-7950ae7befec + github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20231017174030-d74ca31b0806 + github.com/smartcontractkit/chainlink/v2 v2.5.1-0.20231017174030-d74ca31b0806 github.com/smartcontractkit/libocr v0.0.0-20230925165524-ffa38fe11ef8 github.com/stretchr/testify v1.8.4 github.com/testcontainers/testcontainers-go v0.23.0 diff --git a/integration-tests/go.sum b/integration-tests/go.sum index 48c4332ac..e4f3de41f 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -2347,16 +2347,16 @@ github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20230913032705-f924d753cc4 github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20230913032705-f924d753cc47/go.mod h1:xMwqRdj5vqYhCJXgKVqvyAwdcqM6ZAEhnwEQ4Khsop8= github.com/smartcontractkit/chainlink-env v0.38.3 h1:ZtOnwkG622R0VCTxL5V09AnT/QXhlFwkGTjd0Lsfpfg= github.com/smartcontractkit/chainlink-env v0.38.3/go.mod h1:7z4sw/hN8TxioQCLwFqQdhK3vaOV0a22Qe99z4bRUcg= -github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231016132219-9c6fdb379595 h1:a6GfS0N4/7X5YQAdne0TLcdSA7w5UwJ1dG0wx6tP3GY= -github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231016132219-9c6fdb379595/go.mod h1:mV+ayN6figopkI+9OwHUbBdYMhsrXa+CDvCkEM3FNt0= +github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231017172544-b4fc52327846 h1:3KikrKcUFDjZJSdICTxFnc2oaW3X4jTgcxoycmzQ3Mg= +github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231017172544-b4fc52327846/go.mod h1:mV+ayN6figopkI+9OwHUbBdYMhsrXa+CDvCkEM3FNt0= github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20230901115736-bbabe542a918 h1:ByVauKFXphRlSNG47lNuxZ9aicu+r8AoNp933VRPpCw= github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20230901115736-bbabe542a918/go.mod h1:/yp/sqD8Iz5GU5fcercjrw0ivJF7HDcupYg+Gjr7EPg= github.com/smartcontractkit/chainlink-testing-framework v1.17.12-0.20231016091231-25809996fbd4 h1:yidN70ecUI3Ydweggk9eHyCSLX7N39YDmYt8GoYx2XU= github.com/smartcontractkit/chainlink-testing-framework v1.17.12-0.20231016091231-25809996fbd4/go.mod h1:RWlmjwnjIGbQAnRfKwe02Ife82nNI3rZmdI0zgkfbyk= -github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20231016132655-7950ae7befec h1:MPPsc+mPDXPUyj+/fnAl2LpFvr+e4KGuEUE38CO+iEo= -github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20231016132655-7950ae7befec/go.mod h1:wrww/GG1adQOm3myNiTCkqxmh5fhXhWbaioyjOeSZoo= -github.com/smartcontractkit/chainlink/v2 v2.5.1-0.20231016132655-7950ae7befec h1:zfHk2cClAfBNlVA3hgxp4dfyBlHxpuJq65alzxjRO4k= -github.com/smartcontractkit/chainlink/v2 v2.5.1-0.20231016132655-7950ae7befec/go.mod h1:A0c2IZIusJlMxbmXkxKi9q/aDzh4i/5e7aiIz5/nbPk= +github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20231017174030-d74ca31b0806 h1:JWGjtTwv6TuAjMw+5oodxY/GCRwSJ53zyYFq93QhtxA= +github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20231017174030-d74ca31b0806/go.mod h1:gEYJKIjMcpZWNXR25fEkdGrBmcJK7wTKZEAigb1qnwM= +github.com/smartcontractkit/chainlink/v2 v2.5.1-0.20231017174030-d74ca31b0806 h1:GGwC6ra2VyVqrDbpNgS4v7c1PO3c+aMmMQZDzYvRusc= +github.com/smartcontractkit/chainlink/v2 v2.5.1-0.20231017174030-d74ca31b0806/go.mod h1:MMEqII4nRAqutV49I8zLONtm4ugzvEhYWsXjF96/tis= 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/solana/cmd/chainlink-solana/main.go b/pkg/solana/cmd/chainlink-solana/main.go new file mode 100644 index 000000000..707eea418 --- /dev/null +++ b/pkg/solana/cmd/chainlink-solana/main.go @@ -0,0 +1,75 @@ +package main + +import ( + "context" + "fmt" + "strings" + + "github.com/hashicorp/go-plugin" + "github.com/pelletier/go-toml/v2" + + "github.com/smartcontractkit/chainlink-relay/pkg/loop" + "github.com/smartcontractkit/chainlink-solana/pkg/solana" +) + +const ( + loggerName = "PluginSolana" +) + +func main() { + s := loop.MustNewStartedServer(loggerName) + defer s.Stop() + + p := &pluginRelayer{Plugin: loop.Plugin{Logger: s.Logger}} + defer s.Logger.ErrorIfFn(p.Close, "Failed to close") + + s.MustRegister(p) + + stopCh := make(chan struct{}) + defer close(stopCh) + + plugin.Serve(&plugin.ServeConfig{ + HandshakeConfig: loop.PluginRelayerHandshakeConfig(), + Plugins: map[string]plugin.Plugin{ + loop.PluginRelayerName: &loop.GRPCPluginRelayer{ + PluginServer: p, + BrokerConfig: loop.BrokerConfig{ + StopCh: stopCh, + Logger: s.Logger, + GRPCOpts: s.GRPCOpts, + }, + }, + }, + GRPCServer: s.GRPCOpts.NewServer, + }) +} + +type pluginRelayer struct { + loop.Plugin +} + +func (c *pluginRelayer) NewRelayer(ctx context.Context, config string, keystore loop.Keystore) (loop.Relayer, error) { + d := toml.NewDecoder(strings.NewReader(config)) + d.DisallowUnknownFields() + var cfg struct { + Solana solana.TOMLConfig + } + + if err := d.Decode(&cfg); err != nil { + return nil, fmt.Errorf("failed to decode config toml: %w:\n\t%s", err, config) + } + + opts := solana.ChainOpts{ + Logger: c.Logger, + KeyStore: keystore, + } + chain, err := solana.NewChain(&cfg.Solana, opts) + if err != nil { + return nil, fmt.Errorf("failed to create chain: %w", err) + } + ra := &loop.RelayerAdapter{Relayer: solana.NewRelayer(c.Logger, chain), RelayerExt: chain} + + c.SubService(ra) + + return ra, nil +}