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 all commits
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
3 changes: 2 additions & 1 deletion .markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
default: true
MD010:
code_blocks: false
MD013: false
MD013:
tables: false
MD024:
allow_different_nesting: true
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ go-da defines a generic Data Availability interface for modular blockchains.

## DA Interface

| Method | Params | Return |
| ----------- |-------------------------------| -------------|
| `MaxBlobSize` | | `uint64` |
| `Get` | `ids []ID` | `[]Blobs` |
| `GetIDs` | `height uint64` | `[]ID` |
| `Commit` | `blobs []Blob` | `[]Commitment` |
| `Validate` | `ids []Blob, proofs []Proof` | `[]bool` |
| Method | Params | Return |
| ------------- | -------------------------------------------------------- | --------------- |
| `MaxBlobSize` | | `uint64` |
| `Get` | `ids []ID, namespace Namespace` | `[]Blobs` |
| `GetIDs` | `height uint64, namespace Namespace` | `[]ID` |
| `Commit` | `blobs []Blob, namespace Namespace` | `[]Commitment` |
| `Validate` | `ids []Blob, proofs []Proof, namespace Namespace` | `[]bool` |
| `Submit` | `blobs []Blob, gasPrice float64, namespace Namespace` | `[]ID, []Proof` |

NOTE: The `Namespace` parameter in the interface methods is optional and used
only on DA layers that support the functionality, for example Celestia
namespaces and Avail AppIDs.

## Implementations

Expand Down
16 changes: 5 additions & 11 deletions da.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,23 @@ type DA interface {
//
// Error should be returned if ID is not formatted properly, there is no Blob for given ID or any other client-level
// error occurred (dropped connection, timeout, etc).
Get(ctx context.Context, ids []ID) ([]Blob, error)
Get(ctx context.Context, ids []ID, namespace Namespace) ([]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)
tuxcanfly marked this conversation as resolved.
Show resolved Hide resolved

// Submit submits the Blobs to Data Availability layer.
//
// This method is synchronous. Upon successful submission to Data Availability layer, it returns ID identifying blob
// in DA and Proof of inclusion.
// If options is nil, default options are used.
Submit(ctx context.Context, blobs []Blob, opts *SubmitOptions) ([]ID, []Proof, error)
Submit(ctx context.Context, blobs []Blob, gasPrice float64, namespace Namespace) ([]ID, []Proof, error)

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

// SubmitOptions are the parameters used for blob submission.
type SubmitOptions struct {
GasPrice float64
Namespace Namespace
Validate(ctx context.Context, ids []ID, proofs []Proof, namespace Namespace) ([]bool, error)
}

// Namespace is an optional parameter used to set the location a blob should be
Expand Down
4 changes: 4 additions & 0 deletions proto/da/da.proto
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ message MaxBlobSizeResponse {
// GetRequest is the request type for the Get rpc method.
message GetRequest {
repeated ID ids = 1;
Namespace namespace = 2;
}

// GetResponse is the response type for the Get rpc method.
Expand All @@ -69,6 +70,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 +81,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 All @@ -103,6 +106,7 @@ message SubmitResponse {
message ValidateRequest {
repeated ID ids = 1;
repeated Proof proofs = 2;
Namespace namespace = 3;
}

// ValidateResponse is the response type for the Validate rpc method.
Expand Down
27 changes: 15 additions & 12 deletions proxy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ func (c *Client) MaxBlobSize(ctx context.Context) (uint64, error) {
}

// Get returns Blob for each given ID, or an error.
func (c *Client) Get(ctx context.Context, ids []da.ID) ([]da.Blob, error) {
func (c *Client) Get(ctx context.Context, ids []da.ID, namespace da.Namespace) ([]da.Blob, error) {
req := &pbda.GetRequest{
Ids: make([]*pbda.ID, len(ids)),
Ids: make([]*pbda.ID, len(ids)),
Namespace: &pbda.Namespace{Value: namespace},
}
for i := range ids {
req.Ids[i] = &pbda.ID{Value: ids[i]}
Expand All @@ -64,8 +65,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 +76,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},
distractedm1nd marked this conversation as resolved.
Show resolved Hide resolved
}

resp, err := c.client.Commit(ctx, req)
Expand All @@ -89,11 +91,11 @@ func (c *Client) Commit(ctx context.Context, blobs []da.Blob) ([]da.Commitment,
}

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

resp, err := c.client.Submit(ctx, req)
Expand All @@ -112,10 +114,11 @@ func (c *Client) Submit(ctx context.Context, blobs []da.Blob, opts *da.SubmitOpt
}

// Validate validates Commitments against the corresponding Proofs. This should be possible without retrieving the Blobs.
func (c *Client) Validate(ctx context.Context, ids []da.ID, proofs []da.Proof) ([]bool, error) {
func (c *Client) Validate(ctx context.Context, ids []da.ID, proofs []da.Proof, namespace da.Namespace) ([]bool, error) {
req := &pbda.ValidateRequest{
Ids: idsDA2PB(ids),
Proofs: proofsDA2PB(proofs),
Ids: idsDA2PB(ids),
Proofs: proofsDA2PB(proofs),
Namespace: &pbda.Namespace{Value: namespace},
}
resp, err := c.client.Validate(ctx, req)
return resp.Results, err
Expand Down
17 changes: 8 additions & 9 deletions proxy/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,21 @@
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
}

func (p *proxySrv) Get(ctx context.Context, request *pbda.GetRequest) (*pbda.GetResponse, error) {
ids := idsPB2DA(request.Ids)
blobs, err := p.target.Get(ctx, ids)
blobs, err := p.target.Get(ctx, ids, request.Namespace.GetValue())
return &pbda.GetResponse{Blobs: blobsDA2PB(blobs)}, err
}

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 All @@ -57,10 +59,7 @@
func (p *proxySrv) Submit(ctx context.Context, request *pbda.SubmitRequest) (*pbda.SubmitResponse, error) {
blobs := blobsPB2DA(request.Blobs)

ids, proofs, err := p.target.Submit(ctx, blobs, &da.SubmitOptions{
GasPrice: request.GasPrice,
Namespace: request.Namespace.GetValue(),
})
ids, proofs, err := p.target.Submit(ctx, blobs, request.GasPrice, request.Namespace.GetValue())
if err != nil {
return nil, err
}
Expand All @@ -82,7 +81,7 @@
ids := idsPB2DA(request.Ids)
proofs := proofsPB2DA(request.Proofs)
//TODO implement me
validity, err := p.target.Validate(ctx, ids, proofs)
validity, err := p.target.Validate(ctx, ids, proofs, request.Namespace.GetValue())
if err != nil {
return nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions test/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (d *DummyDA) MaxBlobSize(ctx context.Context) (uint64, error) {
}

// Get returns Blobs for given IDs.
func (d *DummyDA) Get(ctx context.Context, ids []da.ID) ([]da.Blob, error) {
func (d *DummyDA) Get(ctx context.Context, ids []da.ID, _ da.Namespace) ([]da.Blob, error) {
d.mu.Lock()
defer d.mu.Unlock()
blobs := make([]da.Blob, len(ids))
Expand All @@ -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 All @@ -100,7 +100,7 @@ func (d *DummyDA) Commit(ctx context.Context, blobs []da.Blob) ([]da.Commitment,
}

// Submit stores blobs in DA layer.
func (d *DummyDA) Submit(ctx context.Context, blobs []da.Blob, opts *da.SubmitOptions) ([]da.ID, []da.Proof, error) {
func (d *DummyDA) Submit(ctx context.Context, blobs []da.Blob, gasPrice float64, namespace da.Namespace) ([]da.ID, []da.Proof, error) {
nashqueue marked this conversation as resolved.
Show resolved Hide resolved
d.mu.Lock()
defer d.mu.Unlock()
ids := make([]da.ID, len(blobs))
Expand All @@ -117,7 +117,7 @@ func (d *DummyDA) Submit(ctx context.Context, blobs []da.Blob, opts *da.SubmitOp
}

// Validate checks the Proofs for given IDs.
func (d *DummyDA) Validate(ctx context.Context, ids []da.ID, proofs []da.Proof) ([]bool, error) {
func (d *DummyDA) Validate(ctx context.Context, ids []da.ID, proofs []da.Proof, _ da.Namespace) ([]bool, error) {
if len(ids) != len(proofs) {
return nil, errors.New("number of IDs doesn't equal to number of proofs")
}
Expand Down
Loading
Loading