Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: adding Namespace to remaining endpoints #35

Merged
merged 5 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions da.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ type DA interface {
Get(ctx context.Context, ids []ID) ([]Blob, error)

// GetIDs returns IDs of all Blobs located in DA at given height.
GetIDs(ctx context.Context, height uint64) ([]ID, error)
GetIDs(ctx context.Context, height uint64, namespace Namespace) ([]ID, error)

// Commit creates a Commitment for each given Blob.
Commit(ctx context.Context, blobs []Blob) ([]Commitment, error)
Commit(ctx context.Context, blobs []Blob, namespace Namespace) ([]Commitment, error)

// Submit submits the Blobs to Data Availability layer.
//
Expand Down
2 changes: 2 additions & 0 deletions proto/da/da.proto
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ message GetResponse {
// GetIDsRequest is the request type for the GetIDs rpc method.
message GetIDsRequest {
uint64 height = 1;
Namespace namespace = 2;
}

// GetIDsResponse is the response type for the GetIDs rpc method.
Expand All @@ -79,6 +80,7 @@ message GetIDsResponse {
// CommitRequest is the request type for the Commit rpc method.
message CommitRequest {
repeated Blob blobs = 1;
Namespace namespace = 2;
}

// CommitResponse is the response type for the Commit rpc method.
Expand Down
9 changes: 5 additions & 4 deletions proxy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func (c *Client) Get(ctx context.Context, ids []da.ID) ([]da.Blob, error) {
}

// GetIDs returns IDs of all Blobs located in DA at given height.
func (c *Client) GetIDs(ctx context.Context, height uint64) ([]da.ID, error) {
req := &pbda.GetIDsRequest{Height: height}
func (c *Client) GetIDs(ctx context.Context, height uint64, namespace da.Namespace) ([]da.ID, error) {
req := &pbda.GetIDsRequest{Height: height, Namespace: &pbda.Namespace{Value: namespace}}
resp, err := c.client.GetIDs(ctx, req)
if err != nil {
return nil, err
Expand All @@ -75,9 +75,10 @@ func (c *Client) GetIDs(ctx context.Context, height uint64) ([]da.ID, error) {
}

// Commit creates a Commitment for each given Blob.
func (c *Client) Commit(ctx context.Context, blobs []da.Blob) ([]da.Commitment, error) {
func (c *Client) Commit(ctx context.Context, blobs []da.Blob, namespace da.Namespace) ([]da.Commitment, error) {
req := &pbda.CommitRequest{
Blobs: blobsDA2PB(blobs),
Blobs: blobsDA2PB(blobs),
Namespace: &pbda.Namespace{Value: namespace},
}

resp, err := c.client.Commit(ctx, req)
Expand Down
8 changes: 5 additions & 3 deletions proxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
target da.DA
}

func (p *proxySrv) MaxBlobSize(ctx context.Context, request *pbda.MaxBlobSizeRequest) (*pbda.MaxBlobSizeResponse, error) {
func (p *proxySrv) MaxBlobSize(
ctx context.Context, request *pbda.MaxBlobSizeRequest,
) (*pbda.MaxBlobSizeResponse, error) {

Check warning on line 29 in proxy/server.go

View check run for this annotation

Codecov / codecov/patch

proxy/server.go#L29

Added line #L29 was not covered by tests
maxBlobSize, err := p.target.MaxBlobSize(ctx)
return &pbda.MaxBlobSizeResponse{MaxBlobSize: maxBlobSize}, err
}
Expand All @@ -36,7 +38,7 @@
}

func (p *proxySrv) GetIDs(ctx context.Context, request *pbda.GetIDsRequest) (*pbda.GetIDsResponse, error) {
ids, err := p.target.GetIDs(ctx, request.Height)
ids, err := p.target.GetIDs(ctx, request.Height, request.Namespace.GetValue())
if err != nil {
return nil, err
}
Expand All @@ -46,7 +48,7 @@

func (p *proxySrv) Commit(ctx context.Context, request *pbda.CommitRequest) (*pbda.CommitResponse, error) {
blobs := blobsPB2DA(request.Blobs)
commits, err := p.target.Commit(ctx, blobs)
commits, err := p.target.Commit(ctx, blobs, request.Namespace.GetValue())
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions test/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (d *DummyDA) Get(ctx context.Context, ids []da.ID) ([]da.Blob, error) {
}

// GetIDs returns IDs of Blobs at given DA height.
func (d *DummyDA) GetIDs(ctx context.Context, height uint64) ([]da.ID, error) {
func (d *DummyDA) GetIDs(ctx context.Context, height uint64, _ da.Namespace) ([]da.ID, error) {
d.mu.Lock()
defer d.mu.Unlock()
kvps := d.data[height]
Expand All @@ -91,7 +91,7 @@ func (d *DummyDA) GetIDs(ctx context.Context, height uint64) ([]da.ID, error) {
}

// Commit returns cryptographic Commitments for given blobs.
func (d *DummyDA) Commit(ctx context.Context, blobs []da.Blob) ([]da.Commitment, error) {
func (d *DummyDA) Commit(ctx context.Context, blobs []da.Blob, _ da.Namespace) ([]da.Commitment, error) {
commits := make([]da.Commitment, len(blobs))
for i, blob := range blobs {
commits[i] = d.getHash(blob)
Expand Down
8 changes: 4 additions & 4 deletions test/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ func BasicDATest(t *testing.T, d da.DA) {
assert.NoError(t, err)
assert.Equal(t, []da.Blob{msg1}, ret)

commitment1, err := d.Commit(ctx, []da.Blob{msg1})
commitment1, err := d.Commit(ctx, []da.Blob{msg1}, []byte{})
assert.NoError(t, err)
assert.NotEmpty(t, commitment1)

commitment2, err := d.Commit(ctx, []da.Blob{msg2})
commitment2, err := d.Commit(ctx, []da.Blob{msg2}, []byte{})
assert.NoError(t, err)
assert.NotEmpty(t, commitment2)

Expand Down Expand Up @@ -130,7 +130,7 @@ func GetIDsTest(t *testing.T, d da.DA) {
// As we're the only user, we don't need to handle external data (that could be submitted in real world).
// There is no notion of height, so we need to scan the DA to get test data back.
for i := uint64(1); !found && !time.Now().After(end); i++ {
ret, err := d.GetIDs(ctx, i)
ret, err := d.GetIDs(ctx, i, []byte{})
if err != nil {
t.Error("failed to get IDs:", err)
}
Expand Down Expand Up @@ -164,7 +164,7 @@ func ConcurrentReadWriteTest(t *testing.T, d da.DA) {
go func() {
defer wg.Done()
for i := uint64(1); i <= 100; i++ {
_, err := d.GetIDs(ctx, i)
_, err := d.GetIDs(ctx, i, []byte{})
assert.NoError(t, err)
}
}()
Expand Down
Loading
Loading