Skip to content
This repository was archived by the owner on May 2, 2025. It is now read-only.

Commit 2abeb01

Browse files
authored
feat: extend api to include rollup id, add Hash function to Batch, add maxBytes (#13)
* extend api to include rollup id, add Hash function to Batch, add maxBytes * minor fixes * fix issues * fix test and comments * concurrency safe * fix verify batch * remove rollup id storage * minor fixes to test * fix GetNextBatch for max bytes and add additional tests * reintroduce rollupId, but as a config in the constructor * minor * fix * minor fixes to submit tx in client
1 parent ec3f843 commit 2abeb01

File tree

10 files changed

+747
-105
lines changed

10 files changed

+747
-105
lines changed

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ go 1.21.0
44

55
require (
66
github.com/cosmos/gogoproto v1.7.0
7+
github.com/stretchr/testify v1.8.4
78
google.golang.org/grpc v1.67.1
89
)
910

1011
require (
12+
github.com/davecgh/go-spew v1.1.1 // indirect
1113
github.com/google/go-cmp v0.6.0 // indirect
14+
github.com/pmezard/go-difflib v1.0.0 // indirect
1215
golang.org/x/net v0.28.0 // indirect
1316
golang.org/x/sys v0.24.0 // indirect
1417
golang.org/x/text v0.17.0 // indirect
1518
google.golang.org/genproto/googleapis/rpc v0.0.0-20240827150818-7e3bb234dfed // indirect
1619
google.golang.org/protobuf v1.34.2 // indirect
20+
gopkg.in/yaml.v3 v3.0.1 // indirect
1721
)

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
github.com/cosmos/gogoproto v1.7.0 h1:79USr0oyXAbxg3rspGh/m4SWNyoz/GLaAh0QlCe2fro=
22
github.com/cosmos/gogoproto v1.7.0/go.mod h1:yWChEv5IUEYURQasfyBW5ffkMHR/90hiHgbNgrtp4j0=
3+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
4+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
35
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
46
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
57
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
68
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
9+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
10+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
11+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
12+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
713
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
814
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
915
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
@@ -16,3 +22,7 @@ google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
1622
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
1723
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
1824
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
25+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
26+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
27+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
28+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

proto/sequencing/sequencing.proto

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ service SequencerOutput {
2929

3030
// GetNextBatchRequest ...
3131
message GetNextBatchRequest {
32+
// the unhashed rollup id
33+
bytes rollup_id = 1;
3234
// Merkle tree hash of the last batch
33-
bytes last_batch_hash = 1;
35+
bytes last_batch_hash = 2;
36+
// maximum bytes that execution client can support per block
37+
uint64 max_bytes = 3;
3438
}
3539

3640
// GetNextBatchResponse ...
@@ -52,8 +56,10 @@ service BatchVerifier {
5256

5357
// VerifyBatchRequest ...
5458
message VerifyBatchRequest {
59+
// the unhashed rollup id
60+
bytes rollup_id = 1;
5561
// Merkle tree hash of the batch
56-
bytes batch_hash = 1;
62+
bytes batch_hash = 2;
5763
}
5864

5965
// VerifyBatchResponse

proxy/grpc/client.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package grpc
22

33
import (
44
"context"
5-
"time"
65

76
"google.golang.org/grpc"
87

@@ -46,34 +45,39 @@ func (c *Client) Stop() error {
4645
}
4746

4847
// SubmitRollupTransaction submits a transaction from rollup to sequencer.
49-
func (c *Client) SubmitRollupTransaction(ctx context.Context, rollupId []byte, tx []byte) error {
48+
func (c *Client) SubmitRollupTransaction(ctx context.Context, req sequencing.SubmitRollupTransactionRequest) (*sequencing.SubmitRollupTransactionResponse, error) {
5049
_, err := c.SequencerInputClient.SubmitRollupTransaction(ctx, &pbseq.SubmitRollupTransactionRequest{
51-
RollupId: rollupId,
52-
Data: tx,
50+
RollupId: req.RollupId,
51+
Data: req.Tx,
5352
})
54-
return err
53+
if err != nil {
54+
return nil, err
55+
}
56+
return &sequencing.SubmitRollupTransactionResponse{}, nil
5557
}
5658

5759
// GetNextBatch returns the next batch of transactions from sequencer to rollup.
58-
func (c *Client) GetNextBatch(ctx context.Context, lastBatchHash []byte) (*sequencing.Batch, time.Time, error) {
59-
resp, err := c.SequencerOutputClient.GetNextBatch(ctx, &pbseq.GetNextBatchRequest{LastBatchHash: lastBatchHash[:]})
60+
func (c *Client) GetNextBatch(ctx context.Context, req sequencing.GetNextBatchRequest) (*sequencing.GetNextBatchResponse, error) {
61+
resp, err := c.SequencerOutputClient.GetNextBatch(ctx, &pbseq.GetNextBatchRequest{RollupId: req.RollupId, LastBatchHash: req.LastBatchHash})
6062
if err != nil {
61-
return nil, time.Now(), err
63+
return nil, err
6264
}
6365
b := &sequencing.Batch{}
6466
b.FromProto(resp.Batch)
6567
t, err := types.TimestampFromProto(resp.Timestamp)
6668
if err != nil {
67-
return nil, time.Now(), err
69+
return nil, err
6870
}
69-
return b, t, nil
71+
return &sequencing.GetNextBatchResponse{Batch: b, Timestamp: t}, nil
7072
}
7173

7274
// VerifyBatch verifies a batch of transactions received from the sequencer.
73-
func (c *Client) VerifyBatch(ctx context.Context, batchHash []byte) (bool, error) {
74-
resp, err := c.BatchVerifierClient.VerifyBatch(ctx, &pbseq.VerifyBatchRequest{BatchHash: batchHash[:]})
75+
func (c *Client) VerifyBatch(ctx context.Context, req sequencing.VerifyBatchRequest) (*sequencing.VerifyBatchResponse, error) {
76+
resp, err := c.BatchVerifierClient.VerifyBatch(ctx, &pbseq.VerifyBatchRequest{RollupId: req.RollupId, BatchHash: req.BatchHash})
7577
if err != nil {
76-
return false, err
78+
return nil, err
7779
}
78-
return resp.Status, nil
80+
return &sequencing.VerifyBatchResponse{Status: resp.Status}, nil
7981
}
82+
83+
var _ sequencing.Sequencer = &Client{}

proxy/grpc/server.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type proxyVerificationSrv struct {
4646

4747
// SubmitRollupTransaction submits a transaction from rollup to sequencer.
4848
func (s *proxyInputSrv) SubmitRollupTransaction(ctx context.Context, req *pbseq.SubmitRollupTransactionRequest) (*pbseq.SubmitRollupTransactionResponse, error) {
49-
err := s.SequencerInput.SubmitRollupTransaction(ctx, req.RollupId, req.Data)
49+
_, err := s.SequencerInput.SubmitRollupTransaction(ctx, sequencing.SubmitRollupTransactionRequest{RollupId: req.RollupId, Tx: req.Data})
5050
if err != nil {
5151
return nil, err
5252
}
@@ -55,22 +55,22 @@ func (s *proxyInputSrv) SubmitRollupTransaction(ctx context.Context, req *pbseq.
5555

5656
// GetNextBatch returns the next batch of transactions from sequencer to rollup.
5757
func (s *proxyOutputSrv) GetNextBatch(ctx context.Context, req *pbseq.GetNextBatchRequest) (*pbseq.GetNextBatchResponse, error) {
58-
batch, timestamp, err := s.SequencerOutput.GetNextBatch(ctx, req.LastBatchHash[:])
58+
resp, err := s.SequencerOutput.GetNextBatch(ctx, sequencing.GetNextBatchRequest{RollupId: req.RollupId, LastBatchHash: req.LastBatchHash})
5959
if err != nil {
6060
return nil, err
6161
}
62-
ts, err := types.TimestampProto(timestamp)
62+
ts, err := types.TimestampProto(resp.Timestamp)
6363
if err != nil {
6464
return nil, err
6565
}
66-
return &pbseq.GetNextBatchResponse{Batch: batch.ToProto(), Timestamp: ts}, nil
66+
return &pbseq.GetNextBatchResponse{Batch: resp.Batch.ToProto(), Timestamp: ts}, nil
6767
}
6868

6969
// VerifyBatch verifies a batch of transactions received from the sequencer.
7070
func (s *proxyVerificationSrv) VerifyBatch(ctx context.Context, req *pbseq.VerifyBatchRequest) (*pbseq.VerifyBatchResponse, error) {
71-
ok, err := s.BatchVerifier.VerifyBatch(ctx, req.BatchHash[:])
71+
resp, err := s.BatchVerifier.VerifyBatch(ctx, sequencing.VerifyBatchRequest{BatchHash: req.BatchHash})
7272
if err != nil {
7373
return nil, err
7474
}
75-
return &pbseq.VerifyBatchResponse{Status: ok}, nil
75+
return &pbseq.VerifyBatchResponse{Status: resp.Status}, nil
7676
}

sequencing.go

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,29 @@ type Sequencer interface {
1515
// SequencerInput provides a method for submitting a transaction from rollup to sequencer
1616
type SequencerInput interface {
1717
// SubmitRollupTransaction submits a transaction from rollup to sequencer
18-
SubmitRollupTransaction(ctx context.Context, rollupId RollupId, tx Tx) error
18+
// RollupId is the unique identifier for the rollup chain
19+
// Tx is the transaction to submit
20+
// returns an error if any from the sequencer
21+
SubmitRollupTransaction(ctx context.Context, req SubmitRollupTransactionRequest) (*SubmitRollupTransactionResponse, error)
1922
}
2023

2124
// SequencerOutput provides a method for getting the next batch of transactions from sequencer to rollup
2225
type SequencerOutput interface {
2326
// GetNextBatch returns the next batch of transactions from sequencer to rollup
24-
// lastBatch is the last batch of transactions received from the sequencer
27+
// RollupId is the unique identifier for the rollup chain
28+
// LastBatchHash is the cryptographic hash of the last batch received by the rollup
29+
// MaxBytes is the maximum number of bytes to return in the batch
2530
// returns the next batch of transactions and an error if any from the sequencer
26-
GetNextBatch(ctx context.Context, lastBatchHash Hash) (*Batch, time.Time, error)
31+
GetNextBatch(ctx context.Context, req GetNextBatchRequest) (*GetNextBatchResponse, error)
2732
}
2833

2934
// BatchVerifier provides a method for verifying a batch of transactions received from the sequencer
3035
type BatchVerifier interface {
3136
// VerifyBatch verifies a batch of transactions received from the sequencer
32-
VerifyBatch(ctx context.Context, batchHash Hash) (bool, error)
37+
// RollupId is the unique identifier for the rollup chain
38+
// BatchHash is the cryptographic hash of the batch to verify
39+
// returns a boolean indicating if the batch is valid and an error if any from the sequencer
40+
VerifyBatch(ctx context.Context, req VerifyBatchRequest) (*VerifyBatchResponse, error)
3341
}
3442

3543
// RollupId is a unique identifier for a rollup chain
@@ -45,3 +53,37 @@ type Hash = []byte
4553
type Batch struct {
4654
Transactions []Tx
4755
}
56+
57+
// SubmitRollupTransactionRequest is a request to submit a transaction from rollup to sequencer
58+
type SubmitRollupTransactionRequest struct {
59+
RollupId RollupId
60+
Tx Tx
61+
}
62+
63+
// SubmitRollupTransactionResponse is a response to submitting a transaction from rollup to sequencer
64+
type SubmitRollupTransactionResponse struct {
65+
}
66+
67+
// GetNextBatchRequest is a request to get the next batch of transactions from sequencer to rollup
68+
type GetNextBatchRequest struct {
69+
RollupId RollupId
70+
LastBatchHash Hash
71+
MaxBytes uint64
72+
}
73+
74+
// GetNextBatchResponse is a response to getting the next batch of transactions from sequencer to rollup
75+
type GetNextBatchResponse struct {
76+
Batch *Batch
77+
Timestamp time.Time
78+
}
79+
80+
// VerifyBatchRequest is a request to verify a batch of transactions received from the sequencer
81+
type VerifyBatchRequest struct {
82+
RollupId RollupId
83+
BatchHash Hash
84+
}
85+
86+
// VerifyBatchResponse is a response to verifying a batch of transactions received from the sequencer
87+
type VerifyBatchResponse struct {
88+
Status bool
89+
}

serialization.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package sequencing
22

33
import (
4+
"crypto/sha256"
5+
46
pbseq "github.com/rollkit/go-sequencing/types/pb/sequencing"
57
)
68

@@ -46,3 +48,13 @@ func (batch *Batch) Unmarshal(data []byte) error {
4648
batch.FromProto(&pb)
4749
return nil
4850
}
51+
52+
// Hash returns the hash of a batch.
53+
func (batch *Batch) Hash() ([]byte, error) {
54+
batchBytes, err := batch.Marshal()
55+
if err != nil {
56+
return nil, err
57+
}
58+
hash := sha256.Sum256(batchBytes)
59+
return hash[:], nil
60+
}

0 commit comments

Comments
 (0)