Skip to content

Commit 7d0c728

Browse files
feat!: adding Namespace to remaining endpoints (#35)
* adding namespaces * changing submitoptions to gasprice,ns * adding namespace to remaining endpoints * updating readme w note * nit: lint md013 - skip tables --------- Co-authored-by: Javed Khan <tuxcanfly@gmail.com> updating readme w note feat: GetProofs introduction updating readme
1 parent 58fb4d0 commit 7d0c728

File tree

8 files changed

+553
-133
lines changed

8 files changed

+553
-133
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ go-da defines a generic Data Availability interface for modular blockchains.
1717
| `MaxBlobSize` | | `uint64` |
1818
| `Get` | `ids []ID, namespace Namespace` | `[]Blobs` |
1919
| `GetIDs` | `height uint64, namespace Namespace` | `[]ID` |
20+
| `GetProofs` | `height uint64, namespace Namespace` | `[]Proof` |
2021
| `Commit` | `blobs []Blob, namespace Namespace` | `[]Commitment` |
2122
| `Validate` | `ids []Blob, proofs []Proof, namespace Namespace` | `[]bool` |
22-
| `Submit` | `blobs []Blob, gasPrice float64, namespace Namespace` | `[]ID, []Proof` |
23+
| `Submit` | `blobs []Blob, gasPrice float64, namespace Namespace` | `[]ID` |
24+
>>>>>>> 7e98847 (feat!: adding Namespace to remaining endpoints (#35))
2325
2426
NOTE: The `Namespace` parameter in the interface methods is optional and used
2527
only on DA layers that support the functionality, for example Celestia

da.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@ type DA interface {
1616
// GetIDs returns IDs of all Blobs located in DA at given height.
1717
GetIDs(ctx context.Context, height uint64, namespace Namespace) ([]ID, error)
1818

19+
// GetProofs returns inclusion Proofs for all Blobs located in DA at given height.
20+
GetProofs(ctx context.Context, height uint64, namespace Namespace) ([]Proof, error)
21+
1922
// Commit creates a Commitment for each given Blob.
2023
Commit(ctx context.Context, blobs []Blob, namespace Namespace) ([]Commitment, error)
2124

2225
// Submit submits the Blobs to Data Availability layer.
2326
//
24-
// This method is synchronous. Upon successful submission to Data Availability layer, it returns ID identifying blob
25-
// in DA and Proof of inclusion.
26-
// If options is nil, default options are used.
27-
Submit(ctx context.Context, blobs []Blob, gasPrice float64, namespace Namespace) ([]ID, []Proof, error)
27+
// This method is synchronous. Upon successful submission to Data Availability layer, it returns the IDs identifying blobs
28+
// in DA.
29+
Submit(ctx context.Context, blobs []Blob, gasPrice float64, namespace Namespace) ([]ID, error)
2830

2931
// Validate validates Commitments against the corresponding Proofs. This should be possible without retrieving the Blobs.
3032
Validate(ctx context.Context, ids []ID, proofs []Proof, namespace Namespace) ([]bool, error)

proto/da/da.proto

+14-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ service DAService {
1212
// GetIDs returns IDs of all Blobs located in DA at given height.
1313
rpc GetIDs(GetIDsRequest) returns (GetIDsResponse) {}
1414

15+
// GetProofs returns inclusion Proofs for all Blobs located in DA at given height.
16+
rpc GetProofs(GetProofsRequest) returns (GetProofsResponse) {}
17+
1518
// Commit creates a Commitment for each given Blob.
1619
rpc Commit(CommitRequest) returns (CommitResponse) {}
1720

@@ -78,6 +81,17 @@ message GetIDsResponse {
7881
repeated ID ids = 1;
7982
}
8083

84+
// GetProofsRequest is the request type for the GetProofs rpc method.
85+
message GetProofsRequest {
86+
uint64 height = 1;
87+
Namespace namespace = 2;
88+
}
89+
90+
// GetProofsResponse is the response type for the GetProofs rpc method.
91+
message GetProofsResponse {
92+
repeated Proof proofs = 1;
93+
}
94+
8195
// CommitRequest is the request type for the Commit rpc method.
8296
message CommitRequest {
8397
repeated Blob blobs = 1;
@@ -99,7 +113,6 @@ message SubmitRequest {
99113
// SubmitResponse is the response type for the Submit rpc method.
100114
message SubmitResponse {
101115
repeated ID ids = 1;
102-
repeated Proof proofs = 2;
103116
}
104117

105118
// ValidateRequest is the request type for the Validate rpc method.

proxy/client.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ func (c *Client) GetIDs(ctx context.Context, height uint64, namespace da.Namespa
7575
return idsPB2DA(resp.Ids), nil
7676
}
7777

78+
// GetProofs returns inclusion Proofs for all Blobs located in DA at given height.
79+
func (c *Client) GetProofs(ctx context.Context, height uint64, namespace da.Namespace) ([]da.Proof, error) {
80+
req := &pbda.GetProofsRequest{Height: height, Namespace: &pbda.Namespace{Value: namespace}}
81+
resp, err := c.client.GetProofs(ctx, req)
82+
if err != nil {
83+
return nil, err
84+
}
85+
86+
return proofsPB2DA(resp.Proofs), nil
87+
}
88+
7889
// Commit creates a Commitment for each given Blob.
7990
func (c *Client) Commit(ctx context.Context, blobs []da.Blob, namespace da.Namespace) ([]da.Commitment, error) {
8091
req := &pbda.CommitRequest{
@@ -91,7 +102,7 @@ func (c *Client) Commit(ctx context.Context, blobs []da.Blob, namespace da.Names
91102
}
92103

93104
// Submit submits the Blobs to Data Availability layer.
94-
func (c *Client) Submit(ctx context.Context, blobs []da.Blob, gasPrice float64, namespace da.Namespace) ([]da.ID, []da.Proof, error) {
105+
func (c *Client) Submit(ctx context.Context, blobs []da.Blob, gasPrice float64, namespace da.Namespace) ([]da.ID, error) {
95106
req := &pbda.SubmitRequest{
96107
Blobs: blobsDA2PB(blobs),
97108
GasPrice: gasPrice,
@@ -100,17 +111,15 @@ func (c *Client) Submit(ctx context.Context, blobs []da.Blob, gasPrice float64,
100111

101112
resp, err := c.client.Submit(ctx, req)
102113
if err != nil {
103-
return nil, nil, err
114+
return nil, err
104115
}
105116

106117
ids := make([]da.ID, len(resp.Ids))
107-
proofs := make([]da.Proof, len(resp.Proofs))
108118
for i := range resp.Ids {
109119
ids[i] = resp.Ids[i].Value
110-
proofs[i] = resp.Proofs[i].Value
111120
}
112121

113-
return ids, proofs, nil
122+
return ids, nil
114123
}
115124

116125
// Validate validates Commitments against the corresponding Proofs. This should be possible without retrieving the Blobs.

proxy/server.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,29 @@ func (p *proxySrv) Commit(ctx context.Context, request *pbda.CommitRequest) (*pb
5656
return &pbda.CommitResponse{Commitments: commitsDA2PB(commits)}, nil
5757
}
5858

59+
func (p *proxySrv) GetProofs(ctx context.Context, request *pbda.GetProofsRequest) (*pbda.GetProofsResponse, error) {
60+
proofs, err := p.target.GetProofs(ctx, request.Height, request.Namespace.GetValue())
61+
if err != nil {
62+
return nil, err
63+
}
64+
65+
return &pbda.GetProofsResponse{Proofs: proofsDA2PB(proofs)}, nil
66+
}
67+
5968
func (p *proxySrv) Submit(ctx context.Context, request *pbda.SubmitRequest) (*pbda.SubmitResponse, error) {
6069
blobs := blobsPB2DA(request.Blobs)
6170

62-
ids, proofs, err := p.target.Submit(ctx, blobs, request.GasPrice, request.Namespace.GetValue())
71+
ids, err := p.target.Submit(ctx, blobs, request.GasPrice, request.Namespace.GetValue())
6372
if err != nil {
6473
return nil, err
6574
}
6675

6776
resp := &pbda.SubmitResponse{
68-
Ids: make([]*pbda.ID, len(ids)),
69-
Proofs: make([]*pbda.Proof, len(proofs)),
77+
Ids: make([]*pbda.ID, len(ids)),
7078
}
7179

7280
for i := range ids {
7381
resp.Ids[i] = &pbda.ID{Value: ids[i]}
74-
resp.Proofs[i] = &pbda.Proof{Value: proofs[i]}
7582
}
7683

7784
return resp, nil

test/dummy.go

+14-4
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ func (d *DummyDA) GetIDs(ctx context.Context, height uint64, _ da.Namespace) ([]
9090
return ids, nil
9191
}
9292

93+
// GetProofs returns inclusion Proofs for all Blobs located in DA at given height.
94+
func (d *DummyDA) GetProofs(ctx context.Context, height uint64, _ da.Namespace) ([]da.ID, error) {
95+
d.mu.Lock()
96+
defer d.mu.Unlock()
97+
kvps := d.data[height]
98+
proofs := make([]da.Proof, len(kvps))
99+
for i, kv := range kvps {
100+
proofs[i] = d.getProof(kv.key, kv.value)
101+
}
102+
return proofs, nil
103+
}
104+
93105
// Commit returns cryptographic Commitments for given blobs.
94106
func (d *DummyDA) Commit(ctx context.Context, blobs []da.Blob, _ da.Namespace) ([]da.Commitment, error) {
95107
commits := make([]da.Commitment, len(blobs))
@@ -100,20 +112,18 @@ func (d *DummyDA) Commit(ctx context.Context, blobs []da.Blob, _ da.Namespace) (
100112
}
101113

102114
// Submit stores blobs in DA layer.
103-
func (d *DummyDA) Submit(ctx context.Context, blobs []da.Blob, gasPrice float64, namespace da.Namespace) ([]da.ID, []da.Proof, error) {
115+
func (d *DummyDA) Submit(ctx context.Context, blobs []da.Blob, gasPrice float64, namespace da.Namespace) ([]da.ID, error) {
104116
d.mu.Lock()
105117
defer d.mu.Unlock()
106118
ids := make([]da.ID, len(blobs))
107-
proofs := make([]da.Proof, len(blobs))
108119
d.height += 1
109120
for i, blob := range blobs {
110121
ids[i] = append(d.nextID(), d.getHash(blob)...)
111-
proofs[i] = d.getProof(ids[i], blob)
112122

113123
d.data[d.height] = append(d.data[d.height], kvp{ids[i], blob})
114124
}
115125

116-
return ids, proofs, nil
126+
return ids, nil
117127
}
118128

119129
// Validate checks the Proofs for given IDs.

test/test_suite.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,17 @@ func BasicDATest(t *testing.T, d da.DA) {
3636
msg2 := []byte("message 2")
3737

3838
ctx := context.TODO()
39-
id1, proof1, err := d.Submit(ctx, []da.Blob{msg1}, 0, testNamespace)
39+
id1, err := d.Submit(ctx, []da.Blob{msg1}, 0, testNamespace)
4040
assert.NoError(t, err)
4141
assert.NotEmpty(t, id1)
42-
assert.NotEmpty(t, proof1)
4342

44-
id2, proof2, err := d.Submit(ctx, []da.Blob{msg2}, 0, testNamespace)
43+
id2, err := d.Submit(ctx, []da.Blob{msg2}, 0, testNamespace)
4544
assert.NoError(t, err)
4645
assert.NotEmpty(t, id2)
47-
assert.NotEmpty(t, proof2)
4846

49-
id3, proof3, err := d.Submit(ctx, []da.Blob{msg1}, 0, testNamespace)
47+
id3, err := d.Submit(ctx, []da.Blob{msg1}, 0, testNamespace)
5048
assert.NoError(t, err)
5149
assert.NotEmpty(t, id3)
52-
assert.NotEmpty(t, proof3)
5350

5451
assert.NotEqual(t, id1, id2)
5552
assert.NotEqual(t, id1, id3)
@@ -66,13 +63,19 @@ func BasicDATest(t *testing.T, d da.DA) {
6663
assert.NoError(t, err)
6764
assert.NotEmpty(t, commitment2)
6865

66+
proof1, err := d.GetProofs(ctx, 1, testNamespace)
67+
assert.NoError(t, err)
68+
assert.NotEmpty(t, proof1)
6969
oks, err := d.Validate(ctx, id1, proof1, testNamespace)
7070
assert.NoError(t, err)
7171
assert.NotEmpty(t, oks)
7272
for _, ok := range oks {
7373
assert.True(t, ok)
7474
}
7575

76+
proof2, err := d.GetProofs(ctx, 2, testNamespace)
77+
assert.NoError(t, err)
78+
assert.NotEmpty(t, proof2)
7679
oks, err = d.Validate(ctx, id2, proof2, testNamespace)
7780
assert.NoError(t, err)
7881
assert.NotEmpty(t, oks)
@@ -108,10 +111,9 @@ func GetIDsTest(t *testing.T, d da.DA) {
108111
msgs := [][]byte{[]byte("msg1"), []byte("msg2"), []byte("msg3")}
109112

110113
ctx := context.TODO()
111-
ids, proofs, err := d.Submit(ctx, msgs, 0, []byte{9, 8, 7, 6, 5, 4, 3, 2, 1, 0})
114+
ids, err := d.Submit(ctx, msgs, 0, testNamespace)
112115
assert.NoError(t, err)
113116
assert.Len(t, ids, len(msgs))
114-
assert.Len(t, proofs, len(msgs))
115117

116118
found := false
117119
end := time.Now().Add(1 * time.Second)
@@ -162,7 +164,7 @@ func ConcurrentReadWriteTest(t *testing.T, d da.DA) {
162164
go func() {
163165
defer wg.Done()
164166
for i := uint64(1); i <= 100; i++ {
165-
_, _, err := d.Submit(ctx, [][]byte{[]byte("test")}, 0, []byte{9, 8, 7, 6, 5, 4, 3, 2, 1, 0})
167+
_, err := d.Submit(ctx, [][]byte{[]byte("test")}, 0, testNamespace)
166168
assert.NoError(t, err)
167169
}
168170
}()

0 commit comments

Comments
 (0)