Skip to content

Commit

Permalink
feat: composer grpc works
Browse files Browse the repository at this point in the history
  • Loading branch information
quasystaty1 committed Apr 16, 2024
1 parent b2fe796 commit 824f595
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
5 changes: 3 additions & 2 deletions astria/mempool/reaper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mempool

import (
"fmt"
"sync"

"github.com/astriaorg/rollkit/astria/sequencer"
Expand Down Expand Up @@ -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")

Expand Down
19 changes: 15 additions & 4 deletions astria/sequencer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sequencer
import (
"context"
"crypto/ed25519"
"flag"
"fmt"

astriaPb "buf.build/gen/go/astria/astria/protocolbuffers/go/astria/sequencer/v1"
Expand All @@ -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
Expand All @@ -28,24 +33,28 @@ 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)
}

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,
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
6 changes: 2 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 824f595

Please sign in to comment.