Skip to content

Commit

Permalink
accept nil, but handle it
Browse files Browse the repository at this point in the history
  • Loading branch information
gupadhyaya committed Aug 19, 2024
1 parent 2aa5751 commit 4a32f0b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 23 deletions.
14 changes: 4 additions & 10 deletions proxy/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,8 @@ func (s *proxyInputSrv) SubmitRollupTransaction(ctx context.Context, req *pbseq.

// GetNextBatch returns the next batch of transactions from sequencer to rollup.
func (s *proxyOutputSrv) GetNextBatch(ctx context.Context, req *pbseq.Batch) (*pbseq.Batch, error) {
var lastBatch *sequencing.Batch
if req.Transactions != nil {
lastBatch = &sequencing.Batch{}
lastBatch.FromProto(req)
}
lastBatch := &sequencing.Batch{}
lastBatch.FromProto(req)
batch, err := s.SequencerOutput.GetNextBatch(ctx, lastBatch)
if err != nil {
return nil, err
Expand All @@ -70,11 +67,8 @@ func (s *proxyOutputSrv) GetNextBatch(ctx context.Context, req *pbseq.Batch) (*p

// VerifyBatch verifies a batch of transactions received from the sequencer.
func (s *proxyVerificationSrv) VerifyBatch(ctx context.Context, req *pbseq.Batch) (*pbseq.VerificationResponse, error) {
var batch *sequencing.Batch
if req.Transactions != nil {
batch = &sequencing.Batch{}
batch.FromProto(req)
}
batch := &sequencing.Batch{}
batch.FromProto(req)
ok, err := s.BatchVerifier.VerifyBatch(ctx, batch)
if err != nil {
return nil, err
Expand Down
13 changes: 2 additions & 11 deletions serialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import (

// ToProto serializes a batch to a protobuf message.
func (batch *Batch) ToProto() *pbseq.Batch {
var txs [][]byte
if batch != nil {
txs = batch.Transactions
}
return &pbseq.Batch{Transactions: txsToByteSlices(txs)}
return &pbseq.Batch{Transactions: txsToByteSlices(batch.Transactions)}
}

// FromProto deserializes a batch from a protobuf message.
Expand Down Expand Up @@ -38,12 +34,7 @@ func byteSlicesToTxs(bytes [][]byte) []Tx {

// Marshal serializes a batch to a byte slice.
func (batch *Batch) Marshal() ([]byte, error) {
var b []byte
if batch == nil {
return b, nil
}
pb := batch.ToProto()
return pb.Marshal()
return batch.ToProto().Marshal()
}

// Unmarshal deserializes a batch from a byte slice.
Expand Down
4 changes: 2 additions & 2 deletions test/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ func (d *DummySequencer) SubmitRollupTransaction(ctx context.Context, rollupId [
// GetNextBatch implements sequencing.Sequencer.
func (d *DummySequencer) GetNextBatch(ctx context.Context, lastBatch *sequencing.Batch) (*sequencing.Batch, error) {
if d.lastBatchHash == nil {
if lastBatch != nil {
if lastBatch.Transactions != nil {
return nil, errors.New("lastBatch is supposed to be nil")
}
} else if lastBatch == nil {
} else if lastBatch.Transactions == nil {
return nil, errors.New("lastBatch is not supposed to be nil")
} else {
lastBatchBytes, err := lastBatch.Marshal()
Expand Down

0 comments on commit 4a32f0b

Please sign in to comment.