Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gupadhyaya committed Jul 19, 2024
1 parent c47d0a7 commit 0166b82
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ go-sequencing defines a generic sequencing interface for modular blockchains

## Sequencing Interface

## Implementations
## Implementations
1 change: 1 addition & 0 deletions proxy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion proxy/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion proxy/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions serialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion test/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 0166b82

Please sign in to comment.