From 824f59539497ad12c0016c69e240f97ab9e16898 Mon Sep 17 00:00:00 2001 From: quasystaty Date: Tue, 16 Apr 2024 17:47:55 +0300 Subject: [PATCH] feat: composer grpc works --- astria/mempool/reaper.go | 5 +++-- astria/sequencer/client.go | 19 +++++++++++++++---- config/defaults.go | 2 +- go.mod | 6 ++---- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/astria/mempool/reaper.go b/astria/mempool/reaper.go index 20e553fb9..d0d00b9eb 100644 --- a/astria/mempool/reaper.go +++ b/astria/mempool/reaper.go @@ -1,6 +1,7 @@ package mempool import ( + "fmt" "sync" "github.com/astriaorg/rollkit/astria/sequencer" @@ -53,14 +54,14 @@ func (mr *MempoolReaper) Reap() { // submit to shared sequencer err := mr.c.SendMessageViaComposer(mempoolTx.Tx()) if err != nil { - mr.logger.Info("error sending message via composer, trying directly: %s\n", err) + //TODO: remove support for direct sequencer tx submission + mr.logger.Info(fmt.Sprint("error sending message via composer, trying directly: \n", err)) res, err := mr.c.BroadcastTx(mempoolTx.Tx()) if err != nil { mr.logger.Error("error sending message: %s\n", err) } mr.logger.Debug("tx response", "log", res.Log) - return } mr.logger.Debug("succesfully sent transaction to composer") diff --git a/astria/sequencer/client.go b/astria/sequencer/client.go index 2fa2a338e..3c4a70579 100644 --- a/astria/sequencer/client.go +++ b/astria/sequencer/client.go @@ -3,6 +3,7 @@ package sequencer import ( "context" "crypto/ed25519" + "flag" "fmt" astriaPb "buf.build/gen/go/astria/astria/protocolbuffers/go/astria/sequencer/v1" @@ -16,6 +17,10 @@ import ( "google.golang.org/protobuf/encoding/protojson" ) +var ( + addr = flag.String("addr", "127.0.0.1:5053", "the address to connect to") +) + // SequencerClient is a client for interacting with the sequencer. type Client struct { Client *client.Client @@ -28,11 +33,14 @@ type Client struct { func NewClient(sequencerAddr string, composerAddr string, private ed25519.PrivateKey, rollupId []byte, logger log.Logger) *Client { c, err := client.NewClient(sequencerAddr) + + // Signer for the sequencer client + signer := client.NewSigner(private) if err != nil { panic(err) } - - conn, err := grpc.Dial(composerAddr, grpc.WithTransportCredentials(insecure.NewCredentials())) + // TODO: get addr from env + conn, err := grpc.Dial(*addr, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { panic(err) } @@ -40,12 +48,13 @@ func NewClient(sequencerAddr string, composerAddr string, private ed25519.Privat return &Client{ Client: c, composerClient: conn, - Signer: client.NewSigner(private), + Signer: signer, rollupId: rollupId, logger: logger, } } +// TODO: remove support for direct sequencer tx submission func (c *Client) BroadcastTx(tx []byte) (*tendermintPb.ResultBroadcastTx, error) { unsigned := &astriaPb.UnsignedTransaction{ Nonce: c.nonce, @@ -110,12 +119,14 @@ func (c *Client) BroadcastTx(tx []byte) (*tendermintPb.ResultBroadcastTx, error) } func (sc *Client) SendMessageViaComposer(tx []byte) error { + grpcCollectorServiceClient := composerv1alpha1grpc.NewGrpcCollectorServiceClient(sc.composerClient) // if the request succeeds, then an empty response will be returned which can be ignored for now - _, err := grpcCollectorServiceClient.SubmitRollupTransaction(context.Background(), &astriaComposerPb.SubmitRollupTransactionRequest{ + resp, err := grpcCollectorServiceClient.SubmitRollupTransaction(context.Background(), &astriaComposerPb.SubmitRollupTransactionRequest{ RollupId: sc.rollupId, Data: tx, }) + sc.logger.Info("Sending through composer grpc collector", "respond", resp.String()) if err != nil { return err } diff --git a/config/defaults.go b/config/defaults.go index 3d4c9164e..f4ea9ac04 100644 --- a/config/defaults.go +++ b/config/defaults.go @@ -26,7 +26,7 @@ var DefaultNodeConfig = NodeConfig{ Astria: AstriaSeqConfig{ GrpcListen: ":50051", SeqAddress: "http://localhost:26657", - ComposerRpc: "127.0.0.1:5053", + ComposerRpc: "http://127.0.0.1:5053", SeqPrivate: "2bd806c97f0e00af1a1fc3328fa763a9269723c8db8fac4f93af71db186d6e90", SeqInitialHeight: 1, }, diff --git a/go.mod b/go.mod index 12217cece..8063c0821 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,6 @@ module github.com/astriaorg/rollkit go 1.21.1 -toolchain go1.21.4 - require ( github.com/celestiaorg/utils v0.1.0 github.com/cometbft/cometbft v0.38.5 @@ -34,6 +32,8 @@ require ( require ( buf.build/gen/go/astria/astria/protocolbuffers/go v1.33.0-20240403190008-c770a4039013.1 + buf.build/gen/go/astria/composer-apis/grpc/go v1.3.0-20240329163554-64ef75007d48.2 + buf.build/gen/go/astria/composer-apis/protocolbuffers/go v1.33.0-20240329163554-64ef75007d48.1 buf.build/gen/go/astria/execution-apis/grpc/go v1.3.0-20240209225522-97e3bc68f856.2 buf.build/gen/go/astria/execution-apis/protocolbuffers/go v1.32.0-20240209225522-97e3bc68f856.1 github.com/astriaorg/go-sequencer-client v0.2.0-alpha.2.0.20240319201724-8dfc0ed60f1b @@ -42,8 +42,6 @@ require ( ) require ( - buf.build/gen/go/astria/composer-apis/grpc/go v1.3.0-20240329163554-64ef75007d48.2 // indirect - buf.build/gen/go/astria/composer-apis/protocolbuffers/go v1.33.0-20240329163554-64ef75007d48.1 // indirect github.com/benbjohnson/clock v1.3.5 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect