Skip to content

Commit d853a41

Browse files
feat: adding SubmitOptions to Submit (#34)
1 parent fd02dcb commit d853a41

File tree

7 files changed

+348
-86
lines changed

7 files changed

+348
-86
lines changed

da.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,22 @@ type DA interface {
2424
// This method is synchronous. Upon successful submission to Data Availability layer, it returns ID identifying blob
2525
// in DA and Proof of inclusion.
2626
// If options is nil, default options are used.
27-
Submit(ctx context.Context, blobs []Blob, gasPrice float64) ([]ID, []Proof, error)
27+
Submit(ctx context.Context, blobs []Blob, opts *SubmitOptions) ([]ID, []Proof, error)
2828

2929
// Validate validates Commitments against the corresponding Proofs. This should be possible without retrieving the Blobs.
3030
Validate(ctx context.Context, ids []ID, proofs []Proof) ([]bool, error)
3131
}
3232

33+
// SubmitOptions are the parameters used for blob submission.
34+
type SubmitOptions struct {
35+
GasPrice float64
36+
Namespace Namespace
37+
}
38+
39+
// Namespace is an optional parameter used to set the location a blob should be
40+
// posted to, for DA layers supporting the functionality.
41+
type Namespace = []byte
42+
3343
// Blob is the data submitted/received from DA interface.
3444
type Blob = []byte
3545

proto/da/da.proto

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ service DAService {
2222
rpc Validate(ValidateRequest) returns (ValidateResponse) {}
2323
}
2424

25+
// Namespace is the location for the blob to be submitted to, if supported by the DA layer.
26+
message Namespace {
27+
bytes value = 1;
28+
}
29+
2530
// Blob is the data submitted/received from DA interface.
2631
message Blob {
2732
bytes value = 1;
@@ -85,6 +90,7 @@ message CommitResponse {
8590
message SubmitRequest {
8691
repeated Blob blobs = 1;
8792
double gas_price = 2;
93+
Namespace namespace = 3;
8894
}
8995

9096
// SubmitResponse is the response type for the Submit rpc method.

proxy/client.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,11 @@ func (c *Client) Commit(ctx context.Context, blobs []da.Blob) ([]da.Commitment,
8989
}
9090

9191
// Submit submits the Blobs to Data Availability layer.
92-
func (c *Client) Submit(ctx context.Context, blobs []da.Blob, gasPrice float64) ([]da.ID, []da.Proof, error) {
92+
func (c *Client) Submit(ctx context.Context, blobs []da.Blob, opts *da.SubmitOptions) ([]da.ID, []da.Proof, error) {
9393
req := &pbda.SubmitRequest{
94-
Blobs: blobsDA2PB(blobs),
95-
GasPrice: gasPrice,
94+
Blobs: blobsDA2PB(blobs),
95+
GasPrice: opts.GasPrice,
96+
Namespace: &pbda.Namespace{Value: opts.Namespace},
9697
}
9798

9899
resp, err := c.client.Submit(ctx, req)

proxy/server.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ func (p *proxySrv) Commit(ctx context.Context, request *pbda.CommitRequest) (*pb
5757
func (p *proxySrv) Submit(ctx context.Context, request *pbda.SubmitRequest) (*pbda.SubmitResponse, error) {
5858
blobs := blobsPB2DA(request.Blobs)
5959

60-
ids, proofs, err := p.target.Submit(ctx, blobs, request.GasPrice)
60+
ids, proofs, err := p.target.Submit(ctx, blobs, &da.SubmitOptions{
61+
GasPrice: request.GasPrice,
62+
Namespace: request.Namespace.GetValue(),
63+
})
6164
if err != nil {
6265
return nil, err
6366
}

test/dummy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (d *DummyDA) Commit(ctx context.Context, blobs []da.Blob) ([]da.Commitment,
100100
}
101101

102102
// Submit stores blobs in DA layer.
103-
func (d *DummyDA) Submit(ctx context.Context, blobs []da.Blob, gasPrice float64) ([]da.ID, []da.Proof, error) {
103+
func (d *DummyDA) Submit(ctx context.Context, blobs []da.Blob, opts *da.SubmitOptions) ([]da.ID, []da.Proof, error) {
104104
d.mu.Lock()
105105
defer d.mu.Unlock()
106106
ids := make([]da.ID, len(blobs))

test/test_suite.go

+36-29
Original file line numberDiff line numberDiff line change
@@ -28,72 +28,73 @@ func RunDATestSuite(t *testing.T, d da.DA) {
2828
})
2929
}
3030

31-
// TODO(tzdybal): how to get rid of those aliases?
32-
33-
// Blob is a type alias
34-
type Blob = da.Blob
35-
36-
// ID is a type alias
37-
type ID = da.ID
38-
3931
// BasicDATest tests round trip of messages to DA and back.
40-
func BasicDATest(t *testing.T, da da.DA) {
32+
func BasicDATest(t *testing.T, d da.DA) {
4133
msg1 := []byte("message 1")
4234
msg2 := []byte("message 2")
4335

4436
ctx := context.TODO()
45-
id1, proof1, err := da.Submit(ctx, []Blob{msg1}, -1)
37+
id1, proof1, err := d.Submit(ctx, []da.Blob{msg1}, &da.SubmitOptions{
38+
GasPrice: 0,
39+
Namespace: []byte{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
40+
})
4641
assert.NoError(t, err)
4742
assert.NotEmpty(t, id1)
4843
assert.NotEmpty(t, proof1)
4944

50-
id2, proof2, err := da.Submit(ctx, []Blob{msg2}, -1)
45+
id2, proof2, err := d.Submit(ctx, []da.Blob{msg2}, &da.SubmitOptions{
46+
GasPrice: 0,
47+
Namespace: []byte{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
48+
})
5149
assert.NoError(t, err)
5250
assert.NotEmpty(t, id2)
5351
assert.NotEmpty(t, proof2)
5452

55-
id3, proof3, err := da.Submit(ctx, []Blob{msg1}, -1)
53+
id3, proof3, err := d.Submit(ctx, []da.Blob{msg1}, &da.SubmitOptions{
54+
GasPrice: 0,
55+
Namespace: []byte{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
56+
})
5657
assert.NoError(t, err)
5758
assert.NotEmpty(t, id3)
5859
assert.NotEmpty(t, proof3)
5960

6061
assert.NotEqual(t, id1, id2)
6162
assert.NotEqual(t, id1, id3)
6263

63-
ret, err := da.Get(ctx, id1)
64+
ret, err := d.Get(ctx, id1)
6465
assert.NoError(t, err)
65-
assert.Equal(t, []Blob{msg1}, ret)
66+
assert.Equal(t, []da.Blob{msg1}, ret)
6667

67-
commitment1, err := da.Commit(ctx, []Blob{msg1})
68+
commitment1, err := d.Commit(ctx, []da.Blob{msg1})
6869
assert.NoError(t, err)
6970
assert.NotEmpty(t, commitment1)
7071

71-
commitment2, err := da.Commit(ctx, []Blob{msg2})
72+
commitment2, err := d.Commit(ctx, []da.Blob{msg2})
7273
assert.NoError(t, err)
7374
assert.NotEmpty(t, commitment2)
7475

75-
oks, err := da.Validate(ctx, id1, proof1)
76+
oks, err := d.Validate(ctx, id1, proof1)
7677
assert.NoError(t, err)
7778
assert.NotEmpty(t, oks)
7879
for _, ok := range oks {
7980
assert.True(t, ok)
8081
}
8182

82-
oks, err = da.Validate(ctx, id2, proof2)
83+
oks, err = d.Validate(ctx, id2, proof2)
8384
assert.NoError(t, err)
8485
assert.NotEmpty(t, oks)
8586
for _, ok := range oks {
8687
assert.True(t, ok)
8788
}
8889

89-
oks, err = da.Validate(ctx, id1, proof2)
90+
oks, err = d.Validate(ctx, id1, proof2)
9091
assert.NoError(t, err)
9192
assert.NotEmpty(t, oks)
9293
for _, ok := range oks {
9394
assert.False(t, ok)
9495
}
9596

96-
oks, err = da.Validate(ctx, id2, proof1)
97+
oks, err = d.Validate(ctx, id2, proof1)
9798
assert.NoError(t, err)
9899
assert.NotEmpty(t, oks)
99100
for _, ok := range oks {
@@ -102,19 +103,22 @@ func BasicDATest(t *testing.T, da da.DA) {
102103
}
103104

104105
// CheckErrors ensures that errors are handled properly by DA.
105-
func CheckErrors(t *testing.T, da da.DA) {
106+
func CheckErrors(t *testing.T, d da.DA) {
106107
ctx := context.TODO()
107-
blob, err := da.Get(ctx, []ID{[]byte("invalid")})
108+
blob, err := d.Get(ctx, []da.ID{[]byte("invalid")})
108109
assert.Error(t, err)
109110
assert.Empty(t, blob)
110111
}
111112

112113
// GetIDsTest tests iteration over DA
113-
func GetIDsTest(t *testing.T, da da.DA) {
114+
func GetIDsTest(t *testing.T, d da.DA) {
114115
msgs := [][]byte{[]byte("msg1"), []byte("msg2"), []byte("msg3")}
115116

116117
ctx := context.TODO()
117-
ids, proofs, err := da.Submit(ctx, msgs, -1)
118+
ids, proofs, err := d.Submit(ctx, msgs, &da.SubmitOptions{
119+
GasPrice: 0,
120+
Namespace: []byte{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
121+
})
118122
assert.NoError(t, err)
119123
assert.Len(t, ids, len(msgs))
120124
assert.Len(t, proofs, len(msgs))
@@ -126,12 +130,12 @@ func GetIDsTest(t *testing.T, da da.DA) {
126130
// As we're the only user, we don't need to handle external data (that could be submitted in real world).
127131
// There is no notion of height, so we need to scan the DA to get test data back.
128132
for i := uint64(1); !found && !time.Now().After(end); i++ {
129-
ret, err := da.GetIDs(ctx, i)
133+
ret, err := d.GetIDs(ctx, i)
130134
if err != nil {
131135
t.Error("failed to get IDs:", err)
132136
}
133137
if len(ret) > 0 {
134-
blobs, err := da.Get(ctx, ret)
138+
blobs, err := d.Get(ctx, ret)
135139
assert.NoError(t, err)
136140

137141
// Submit ensures atomicity of batch, so it makes sense to compare actual blobs (bodies) only when lengths
@@ -151,7 +155,7 @@ func GetIDsTest(t *testing.T, da da.DA) {
151155
}
152156

153157
// ConcurrentReadWriteTest tests the use of mutex lock in DummyDA by calling separate methods that use `d.data` and making sure there's no race conditions
154-
func ConcurrentReadWriteTest(t *testing.T, da da.DA) {
158+
func ConcurrentReadWriteTest(t *testing.T, d da.DA) {
155159
var wg sync.WaitGroup
156160
wg.Add(2)
157161

@@ -160,15 +164,18 @@ func ConcurrentReadWriteTest(t *testing.T, da da.DA) {
160164
go func() {
161165
defer wg.Done()
162166
for i := uint64(1); i <= 100; i++ {
163-
_, err := da.GetIDs(ctx, i)
167+
_, err := d.GetIDs(ctx, i)
164168
assert.NoError(t, err)
165169
}
166170
}()
167171

168172
go func() {
169173
defer wg.Done()
170174
for i := uint64(1); i <= 100; i++ {
171-
_, _, err := da.Submit(ctx, [][]byte{[]byte("test")}, -1)
175+
_, _, err := d.Submit(ctx, [][]byte{[]byte("test")}, &da.SubmitOptions{
176+
GasPrice: 0,
177+
Namespace: []byte{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
178+
})
172179
assert.NoError(t, err)
173180
}
174181
}()

0 commit comments

Comments
 (0)