From 0166b8267e96dad057bf9dc639f4f4cd0a1101a0 Mon Sep 17 00:00:00 2001 From: gupadhyaya Date: Fri, 19 Jul 2024 18:53:07 +0400 Subject: [PATCH] lint fixes --- README.md | 2 +- proxy/client.go | 1 + proxy/grpc/client.go | 3 ++- proxy/grpc/server.go | 7 ++++++- serialization.go | 4 ++++ test/dummy.go | 5 ++++- 6 files changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f5b36ed..bf48f81 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,4 @@ go-sequencing defines a generic sequencing interface for modular blockchains ## Sequencing Interface -## Implementations \ No newline at end of file +## Implementations diff --git a/proxy/client.go b/proxy/client.go index a5f0ec6..db4c128 100644 --- a/proxy/client.go +++ b/proxy/client.go @@ -11,6 +11,7 @@ import ( proxygrpc "github.com/rollkit/go-sequencing/proxy/grpc" ) +// NewClient creates a new Sequencer client. func NewClient(uri string) (sequencing.Sequencer, error) { addr, err := url.Parse(uri) if err != nil { diff --git a/proxy/grpc/client.go b/proxy/grpc/client.go index 2fbf889..de7b72d 100644 --- a/proxy/grpc/client.go +++ b/proxy/grpc/client.go @@ -3,9 +3,10 @@ package grpc import ( "context" + "google.golang.org/grpc" + "github.com/rollkit/go-sequencing" pbseq "github.com/rollkit/go-sequencing/types/pb/sequencing" - "google.golang.org/grpc" ) // Client is a gRPC proxy client for DA interface. diff --git a/proxy/grpc/server.go b/proxy/grpc/server.go index 0bf6901..46221c4 100644 --- a/proxy/grpc/server.go +++ b/proxy/grpc/server.go @@ -3,12 +3,14 @@ package grpc import ( "context" - "github.com/rollkit/go-sequencing" "google.golang.org/grpc" + "github.com/rollkit/go-sequencing" + pbseq "github.com/rollkit/go-sequencing/types/pb/sequencing" ) +// NewServer creates a new gRPC server for the Sequencer service. func NewServer( input sequencing.SequencerInput, output sequencing.SequencerOutput, @@ -40,6 +42,7 @@ type proxyVerificationSrv struct { sequencing.BatchVerifier } +// SubmitRollupTransaction submits a transaction from rollup to sequencer. func (s *proxyInputSrv) SubmitRollupTransaction(ctx context.Context, req *pbseq.SubmitRollupTransactionRequest) (*pbseq.SubmitRollupTransactionResponse, error) { err := s.SequencerInput.SubmitRollupTransaction(ctx, req.RollupId, req.Data) if err != nil { @@ -48,6 +51,7 @@ func (s *proxyInputSrv) SubmitRollupTransaction(ctx context.Context, req *pbseq. return &pbseq.SubmitRollupTransactionResponse{}, nil } +// GetNextBatch returns the next batch of transactions from sequencer to rollup. func (s *proxyOutputSrv) GetNextBatch(ctx context.Context, req *pbseq.Batch) (*pbseq.Batch, error) { lastBatch := sequencing.Batch{} lastBatch.FromProto(req) @@ -58,6 +62,7 @@ func (s *proxyOutputSrv) GetNextBatch(ctx context.Context, req *pbseq.Batch) (*p return batch.ToProto(), nil } +// VerifyBatch verifies a batch of transactions received from the sequencer. func (s *proxyVerificationSrv) VerifyBatch(ctx context.Context, req *pbseq.Batch) (*pbseq.VerificationResponse, error) { batch := sequencing.Batch{} batch.FromProto(req) diff --git a/serialization.go b/serialization.go index c034bd2..06928ac 100644 --- a/serialization.go +++ b/serialization.go @@ -4,10 +4,12 @@ import ( pbseq "github.com/rollkit/go-sequencing/types/pb/sequencing" ) +// ToProto serializes a batch to a protobuf message. func (batch *Batch) ToProto() *pbseq.Batch { return &pbseq.Batch{Transactions: txsToByteSlices(batch.Transactions)} } +// FromProto deserializes a batch from a protobuf message. func (batch *Batch) FromProto(pb *pbseq.Batch) { batch.Transactions = byteSlicesToTxs(pb.Transactions) } @@ -30,11 +32,13 @@ func byteSlicesToTxs(bytes [][]byte) []Tx { return txs } +// Marshal serializes a batch to a byte slice. func (batch *Batch) Marshal() ([]byte, error) { pb := batch.ToProto() return pb.Marshal() } +// Unmarshal deserializes a batch from a byte slice. func (batch *Batch) Unmarshal(data []byte) error { var pb pbseq.Batch if err := pb.Unmarshal(data); err != nil { diff --git a/test/dummy.go b/test/dummy.go index b100ea1..bfffc89 100644 --- a/test/dummy.go +++ b/test/dummy.go @@ -10,8 +10,10 @@ import ( "github.com/rollkit/go-sequencing" ) +// ErrorRollupIdMismatch is returned when the rollup id does not match var ErrorRollupIdMismatch = errors.New("rollup id mismatch") +// TransactionQueue is a queue of transactions type TransactionQueue struct { queue []sequencing.Tx mu sync.Mutex @@ -31,7 +33,7 @@ func (tq *TransactionQueue) AddTransaction(tx sequencing.Tx) { tq.queue = append(tq.queue, tx) } -// GetBatch extracts a batch of transactions from the queue +// GetNextBatch extracts a batch of transactions from the queue func (tq *TransactionQueue) GetNextBatch() sequencing.Batch { tq.mu.Lock() defer tq.mu.Unlock() @@ -89,6 +91,7 @@ func (d *DummySequencer) VerifyBatch(ctx context.Context, batch sequencing.Batch return ok, nil } +// NewDummySequencer creates a new DummySequencer func NewDummySequencer() *DummySequencer { return &DummySequencer{ tq: NewTransactionQueue(),