From 2dc0333318612b9680737804c1b47b7fa78802db Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Tue, 24 Oct 2023 09:00:40 -0500 Subject: [PATCH] plugins: remove cmd/chainlink-starknet (#11058) --- GNUmakefile | 4 -- core/scripts/go.mod | 2 +- core/scripts/go.sum | 4 +- go.mod | 2 +- go.sum | 4 +- integration-tests/go.mod | 2 +- integration-tests/go.sum | 4 +- plugins/README.md | 4 +- plugins/chainlink.Dockerfile | 20 ++++-- plugins/cmd/chainlink-starknet/README.md | 76 ---------------------- plugins/cmd/chainlink-starknet/main.go | 81 ------------------------ 11 files changed, 24 insertions(+), 179 deletions(-) delete mode 100644 plugins/cmd/chainlink-starknet/README.md delete mode 100644 plugins/cmd/chainlink-starknet/main.go diff --git a/GNUmakefile b/GNUmakefile index 9fbd19154e7..957df96ce45 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -61,10 +61,6 @@ chainlink-local-start: install-median: ## Build & install the chainlink-median binary. go install $(GOFLAGS) ./plugins/cmd/chainlink-median -.PHONY: install-starknet -install-starknet: ## Build & install the chainlink-starknet binary. - go install $(GOFLAGS) ./plugins/cmd/chainlink-starknet - .PHONY: docker ## Build the chainlink docker image docker: docker buildx build \ diff --git a/core/scripts/go.mod b/core/scripts/go.mod index bdd85660c8b..c8b616a4b6e 100644 --- a/core/scripts/go.mod +++ b/core/scripts/go.mod @@ -304,7 +304,7 @@ require ( github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20230913032705-f924d753cc47 // indirect github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231020230319-2ede955d1dc9 // indirect github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231023133638-72f4e799ab05 // indirect - github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231023224324-9be0aa99cc92 // indirect + github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231024133459-1ef3a11319eb // indirect github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1 // indirect github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230906073235-9e478e5e19f1 // indirect github.com/smartcontractkit/wsrpc v0.7.2 // indirect diff --git a/core/scripts/go.sum b/core/scripts/go.sum index 9bfd7d56f62..c4d0575bb20 100644 --- a/core/scripts/go.sum +++ b/core/scripts/go.sum @@ -1462,8 +1462,8 @@ github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231020230319-2ede955d1dc9 github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231020230319-2ede955d1dc9/go.mod h1:M9U1JV7IQi8Sfj4JR1qSi1tIh6omgW78W/8SHN/8BUQ= github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231023133638-72f4e799ab05 h1:DaPSVnxe7oz1QJ+AVIhQWs1W3ubQvwvGo9NbHpMs1OQ= github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231023133638-72f4e799ab05/go.mod h1:o0Pn1pbaUluboaK6/yhf8xf7TiFCkyFl6WUOdwqamuU= -github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231023224324-9be0aa99cc92 h1:WJHoy1d8idGv5rPwY1F46D+gFT9rH4q+aCyDV64Xgqo= -github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231023224324-9be0aa99cc92/go.mod h1:/30flFG4L/iCYAFeA3DUzR0xuHSxAMONiWTzyzvsNwo= +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/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/go.mod b/go.mod index 5ec3e45b10a..df970160acc 100644 --- a/go.mod +++ b/go.mod @@ -70,7 +70,7 @@ require ( github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20230913032705-f924d753cc47 github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231020230319-2ede955d1dc9 github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231023133638-72f4e799ab05 - github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231023224324-9be0aa99cc92 + github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231024133459-1ef3a11319eb github.com/smartcontractkit/libocr v0.0.0-20231020123319-d255366a6545 github.com/smartcontractkit/ocr2keepers v0.7.27 github.com/smartcontractkit/ocr2vrf v0.0.0-20230804151440-2f1eb1e20687 diff --git a/go.sum b/go.sum index e822318e94d..59286787c2e 100644 --- a/go.sum +++ b/go.sum @@ -1463,8 +1463,8 @@ github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231020230319-2ede955d1dc9 github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231020230319-2ede955d1dc9/go.mod h1:M9U1JV7IQi8Sfj4JR1qSi1tIh6omgW78W/8SHN/8BUQ= github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231023133638-72f4e799ab05 h1:DaPSVnxe7oz1QJ+AVIhQWs1W3ubQvwvGo9NbHpMs1OQ= github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231023133638-72f4e799ab05/go.mod h1:o0Pn1pbaUluboaK6/yhf8xf7TiFCkyFl6WUOdwqamuU= -github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231023224324-9be0aa99cc92 h1:WJHoy1d8idGv5rPwY1F46D+gFT9rH4q+aCyDV64Xgqo= -github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231023224324-9be0aa99cc92/go.mod h1:/30flFG4L/iCYAFeA3DUzR0xuHSxAMONiWTzyzvsNwo= +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/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/go.mod b/integration-tests/go.mod index 4ce9923b899..7dd2d017785 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -387,7 +387,7 @@ require ( github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20230913032705-f924d753cc47 // indirect github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231020230319-2ede955d1dc9 // indirect github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231023133638-72f4e799ab05 // indirect - github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231023224324-9be0aa99cc92 // indirect + github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231024133459-1ef3a11319eb // indirect github.com/smartcontractkit/sqlx v1.3.5-0.20210805004948-4be295aacbeb // indirect github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1 // indirect github.com/smartcontractkit/wsrpc v0.7.2 // indirect diff --git a/integration-tests/go.sum b/integration-tests/go.sum index 189aed8d232..3be74077277 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -2368,8 +2368,8 @@ github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231020230319-2ede955d1dc9 github.com/smartcontractkit/chainlink-relay v0.1.7-0.20231020230319-2ede955d1dc9/go.mod h1:M9U1JV7IQi8Sfj4JR1qSi1tIh6omgW78W/8SHN/8BUQ= github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231023133638-72f4e799ab05 h1:DaPSVnxe7oz1QJ+AVIhQWs1W3ubQvwvGo9NbHpMs1OQ= github.com/smartcontractkit/chainlink-solana v1.0.3-0.20231023133638-72f4e799ab05/go.mod h1:o0Pn1pbaUluboaK6/yhf8xf7TiFCkyFl6WUOdwqamuU= -github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231023224324-9be0aa99cc92 h1:WJHoy1d8idGv5rPwY1F46D+gFT9rH4q+aCyDV64Xgqo= -github.com/smartcontractkit/chainlink-starknet/relayer v0.0.1-beta-test.0.20231023224324-9be0aa99cc92/go.mod h1:/30flFG4L/iCYAFeA3DUzR0xuHSxAMONiWTzyzvsNwo= +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-testing-framework v1.17.12-0.20231018101901-23824db88d36 h1:ow84QG8vEHMvfjGg0RF8HNYh80WcHci6PIenXyY6K8Y= github.com/smartcontractkit/chainlink-testing-framework v1.17.12-0.20231018101901-23824db88d36/go.mod h1:RWlmjwnjIGbQAnRfKwe02Ife82nNI3rZmdI0zgkfbyk= github.com/smartcontractkit/go-plugin v0.0.0-20231003134350-e49dad63b306 h1:ko88+ZznniNJZbZPWAvHQU8SwKAdHngdDZ+pvVgB5ss= diff --git a/plugins/README.md b/plugins/README.md index 61667d8d392..35d6af7f637 100644 --- a/plugins/README.md +++ b/plugins/README.md @@ -7,8 +7,8 @@ separate processes, plug-in via [github.com/hashicorp/go-plugin](https://github. communicate via [GRPC](https://grpc.io). There are currently two kinds of plugins: Relayer plugins, and a Median product plugin. The [cmd](cmd) directory contains -some `package main`s for now, and they can be built via `make install-starknet` and `make install-median`. Solana has been -moved to the `chainlink-solana` repo, and these will soon be moved too. +some `package main`s while we transition, and they can be built via `make install-`. Solana & Starknet has been +moved to their respective repos, and all must be moved out of this module eventually. ## How to use diff --git a/plugins/chainlink.Dockerfile b/plugins/chainlink.Dockerfile index ec0574e1738..001ee30bf74 100644 --- a/plugins/chainlink.Dockerfile +++ b/plugins/chainlink.Dockerfile @@ -18,18 +18,23 @@ COPY . . RUN make install-chainlink # Build LOOP Plugins RUN make install-median -RUN make install-starknet RUN go list -m -f "{{.Dir}}" github.com/smartcontractkit/chainlink-solana | xargs -I % ln -s % /chainlink-solana +RUN mkdir /chainlink-starknet +RUN go list -m -f "{{.Dir}}" github.com/smartcontractkit/chainlink-starknet/relayer | xargs -I % ln -s % /chainlink-starknet/relayer -# Build image: Solana Plugin -FROM golang:1.21-bullseye as buildsol +# Build image: Plugins +FROM golang:1.21-bullseye as buildplugins RUN go version -WORKDIR /chainlink-solana +WORKDIR /chainlink-solana COPY --from=buildgo /chainlink-solana . RUN go install ./pkg/solana/cmd/chainlink-solana +WORKDIR /chainlink-starknet/relayer +COPY --from=buildgo /chainlink-starknet/relayer . +RUN go install ./pkg/chainlink/cmd/chainlink-starknet + # Final image: ubuntu with chainlink binary FROM ubuntu:20.04 @@ -46,10 +51,11 @@ RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \ COPY --from=buildgo /go/bin/chainlink /usr/local/bin/ COPY --from=buildgo /go/bin/chainlink-median /usr/local/bin/ ENV CL_MEDIAN_CMD chainlink-median -COPY --from=buildgo /go/bin/chainlink-starknet /usr/local/bin/ -ENV CL_STARKNET_CMD chainlink-starknet -COPY --from=buildsol /go/bin/chainlink-solana /usr/local/bin/ + +COPY --from=buildplugins /go/bin/chainlink-solana /usr/local/bin/ ENV CL_SOLANA_CMD chainlink-solana +COPY --from=buildplugins /go/bin/chainlink-starknet /usr/local/bin/ +ENV CL_STARKNET_CMD chainlink-starknet # Dependency of CosmWasm/wasmd COPY --from=buildgo /go/pkg/mod/github.com/\!cosm\!wasm/wasmvm@v*/internal/api/libwasmvm.*.so /usr/lib/ diff --git a/plugins/cmd/chainlink-starknet/README.md b/plugins/cmd/chainlink-starknet/README.md deleted file mode 100644 index efeb5221db2..00000000000 --- a/plugins/cmd/chainlink-starknet/README.md +++ /dev/null @@ -1,76 +0,0 @@ -# Staknet LOOP Plugin - -:warning: WIP, Experimental :warning: - -## Background - -This README is a temporary stop gap to capture the design design choices in the starknet stack that -are not obvious from reading the code. - -For information about LOOP Plugings in general, see `plugins/README.md` and the CLIP - -## LOOP Relayer summary - -For our purposes, the key points about LOOP Plugins are: - -- Node configuration determines which LOOPps are launched -- Orchestration between the node and LOOPps is facilitated by a common api - - Each LOOPp implementation needs to implements a factory function that instatates a LOOPp-specific implementation of the api - - The factory function itself is part of the api and therefore must have a common signature amongst all LOOPp implementations -- Each LOOPp relayer implementation must be able to sign transactions -- *All of the above imply a requirement for a common, abstract keystore in the node-LOOPp API* - -### Starknet Signing - -The existing `caigo` library passes around private keys in it's API. An explicit private key is required to create an `account` and -an `account` is needed to `Sign` a transaction. - -Given this, and the requirement above, our choices are -- Expose private keys via our abstract keystore -- Change `caigo` -- ? something else that I haven't thought about... open to ideas - -Exposing private keys is both an anti-pattern and a long term risk that we want to avoid. As such, we have choosen to change `caigo`. -By happenstance, we already support our own private fork of `caigo` so there is less friction to implementing this kind of change. - -#### Keystore design - -There are three layers to the problem, starting at the top of the stack: - -1. The starknet LOOPp implementation must implement a factory functions that accepts the abstract keystore, as discussed above -2. The starknet transaction manager must be changed to operate with this new keystore interface -3. `caigo` must expose an API that the transaction manager can use without requiring explicit private keys - -At the top of the stack, the abstract keystore, everything is bytes. This enables it to be generic and implementable in each LOOPp. At the -bottom of the stack, `caigo` the signature algorithms use a `*big.Int` types as dictated by the starknet curve. Given these observations, -the most natural layering is to change `caigo` to support a Keystore that operates on `*big.Int` and use our Transaction Manager -implementation to adapt from the generic LOOPp Keystore to the specific `caigo` Keystore. - - -```mermaid -classDiagram - -class caigo_Keystore{ - Sign(senderAddr string , msgHash *big.Int) (*big.Int, *big.Int,error) - } -class caigo_Account { - ... - caigo.Keystore -} -class loopp_Keystore{ - Sign(id string, data []byte) ([]byte,error) - } - -class starknet_KeystoreAdapter{ - looppKS loop.Keystore - +Sign(senderAddr string , msgHash *big.Int) (*big.Int, *big.Int,error) -} -note for starknet_KeystoreAdapter "responsible for translating from -generic LOOPp interface (bytes) to -caigo interface (*big.Int)" - -caigo_Keystore <|-- starknet_KeystoreAdapter : implements -loopp_Keystore *-- starknet_KeystoreAdapter : composition -caigo_Keystore *-- caigo_Account : composition - -``` diff --git a/plugins/cmd/chainlink-starknet/main.go b/plugins/cmd/chainlink-starknet/main.go deleted file mode 100644 index ea73858501d..00000000000 --- a/plugins/cmd/chainlink-starknet/main.go +++ /dev/null @@ -1,81 +0,0 @@ -package main - -import ( - "context" - "fmt" - "strings" - - "github.com/hashicorp/go-plugin" - "github.com/pelletier/go-toml/v2" - - "github.com/smartcontractkit/chainlink-relay/pkg/loop" - pkgstarknet "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink" - starkchain "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/chain" - stkcfg "github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/config" -) - -const ( - loggerName = "PluginStarknet" -) - -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 -} - -// NewRelayer implements the Loopp factory method used by the Loopp server to instantiate a starknet relayer -// [github.com/smartcontractkit/chainlink-relay/pkg/loop.PluginRelayer] -// loopKs must be an implementation that can construct a starknet keystore adapter -// [github.com/smartcontractkit/chainlink-starknet/relayer/pkg/chainlink/txm.NewKeystoreAdapter] -func (c *pluginRelayer) NewRelayer(ctx context.Context, config string, loopKs loop.Keystore) (loop.Relayer, error) { - d := toml.NewDecoder(strings.NewReader(config)) - d.DisallowUnknownFields() - var cfg struct { - Starknet stkcfg.TOMLConfig - } - if err := d.Decode(&cfg); err != nil { - return nil, fmt.Errorf("failed to decode config toml: %w:\n\t%s", err, config) - } - - opts := starkchain.ChainOpts{ - Logger: c.Logger, - KeyStore: loopKs, - } - - chain, err := starkchain.NewChain(&cfg.Starknet, opts) - if err != nil { - return nil, fmt.Errorf("failed to create chain: %w", err) - } - ra := &loop.RelayerAdapter{Relayer: pkgstarknet.NewRelayer(c.Logger, chain), RelayerExt: chain} - - c.SubService(ra) - - return ra, nil -}