Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
nit: default namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxcanfly committed Feb 12, 2024
1 parent 49591b2 commit a648be6
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions celestia/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ func NewCelestiaDA(client *rpc.Client, namespace share.Namespace, gasPrice float
}
}

func (c *CelestiaDA) defaultNamespace(ns da.Namespace) da.Namespace {
if ns == nil {
return c.namespace
}

Check warning on line 49 in celestia/celestia.go

View check run for this annotation

Codecov / codecov/patch

celestia/celestia.go#L48-L49

Added lines #L48 - L49 were not covered by tests
return ns
}

// MaxBlobSize returns the max blob size
func (c *CelestiaDA) MaxBlobSize(ctx context.Context) (uint64, error) {
// TODO: pass-through query to node, app
Expand All @@ -51,13 +58,11 @@ func (c *CelestiaDA) MaxBlobSize(ctx context.Context) (uint64, error) {

// Get returns Blob for each given ID, or an error.
func (c *CelestiaDA) Get(ctx context.Context, ids []da.ID, ns da.Namespace) ([]da.Blob, error) {
if ns == nil {
ns = c.namespace
}
c.namespace = c.defaultNamespace(ns)
var blobs []da.Blob
for _, id := range ids {
height, commitment := splitID(id)
blob, err := c.client.Blob.Get(ctx, height, ns, commitment)
blob, err := c.client.Blob.Get(ctx, height, c.namespace, commitment)
if err != nil {
return nil, err
}
Expand All @@ -68,11 +73,9 @@ func (c *CelestiaDA) Get(ctx context.Context, ids []da.ID, ns da.Namespace) ([]d

// GetIDs returns IDs of all Blobs located in DA at given height.
func (c *CelestiaDA) GetIDs(ctx context.Context, height uint64, ns da.Namespace) ([]da.ID, error) {
if ns == nil {
ns = c.namespace
}
c.namespace = c.defaultNamespace(ns)
var ids []da.ID
blobs, err := c.client.Blob.GetAll(ctx, height, []share.Namespace{ns})
blobs, err := c.client.Blob.GetAll(ctx, height, []share.Namespace{c.namespace})
if err != nil {
if strings.Contains(err.Error(), blob.ErrBlobNotFound.Error()) {
return nil, nil
Expand All @@ -87,19 +90,15 @@ func (c *CelestiaDA) GetIDs(ctx context.Context, height uint64, ns da.Namespace)

// Commit creates a Commitment for each given Blob.
func (c *CelestiaDA) Commit(ctx context.Context, daBlobs []da.Blob, ns da.Namespace) ([]da.Commitment, error) {
if ns == nil {
ns = c.namespace
}
_, commitments, err := c.blobsAndCommitments(daBlobs, ns)
c.namespace = c.defaultNamespace(ns)
_, commitments, err := c.blobsAndCommitments(daBlobs, c.namespace)
return commitments, err
}

// Submit submits the Blobs to Data Availability layer.
func (c *CelestiaDA) Submit(ctx context.Context, daBlobs []da.Blob, gasPrice float64, ns da.Namespace) ([]da.ID, error) {
if ns == nil {
ns = c.namespace
}
blobs, _, err := c.blobsAndCommitments(daBlobs, ns)
c.namespace = c.defaultNamespace(ns)
blobs, _, err := c.blobsAndCommitments(daBlobs, c.namespace)
if err != nil {
return nil, err

Check warning on line 103 in celestia/celestia.go

View check run for this annotation

Codecov / codecov/patch

celestia/celestia.go#L103

Added line #L103 was not covered by tests
}
Expand All @@ -117,13 +116,11 @@ func (c *CelestiaDA) Submit(ctx context.Context, daBlobs []da.Blob, gasPrice flo

// GetProofs returns the inclusion proofs for the given IDs.
func (c *CelestiaDA) GetProofs(ctx context.Context, daIDs []da.ID, ns da.Namespace) ([]da.Proof, error) {
if ns == nil {
ns = c.namespace
}
c.namespace = c.defaultNamespace(ns)
proofs := make([]da.Proof, len(daIDs))
for i, id := range daIDs {
height, commitment := splitID(id)

Check warning on line 122 in celestia/celestia.go

View check run for this annotation

Codecov / codecov/patch

celestia/celestia.go#L118-L122

Added lines #L118 - L122 were not covered by tests
proof, err := c.client.Blob.GetProof(ctx, height, ns, commitment)
proof, err := c.client.Blob.GetProof(ctx, height, c.namespace, commitment)
if err != nil {
return nil, err

Check warning on line 125 in celestia/celestia.go

View check run for this annotation

Codecov / codecov/patch

celestia/celestia.go#L125

Added line #L125 was not covered by tests
}
Expand Down Expand Up @@ -157,9 +154,7 @@ func (c *CelestiaDA) blobsAndCommitments(daBlobs []da.Blob, ns da.Namespace) ([]

// Validate validates Commitments against the corresponding Proofs. This should be possible without retrieving the Blobs.
func (c *CelestiaDA) Validate(ctx context.Context, ids []da.ID, daProofs []da.Proof, ns da.Namespace) ([]bool, error) {
if ns == nil {
ns = c.namespace
}
c.namespace = c.defaultNamespace(ns)
var included []bool
var proofs []*blob.Proof
for _, daProof := range daProofs {
Expand All @@ -175,7 +170,7 @@ func (c *CelestiaDA) Validate(ctx context.Context, ids []da.ID, daProofs []da.Pr
// TODO(tzdybal): for some reason, if proof doesn't match commitment, API returns (false, "blob: invalid proof")
// but analysis of the code in celestia-node implies this should never happen - maybe it's caused by openrpc?
// there is no way of gently handling errors here, but returned value is fine for us
isIncluded, _ := c.client.Blob.Included(ctx, height, ns, proofs[i], commitment)
isIncluded, _ := c.client.Blob.Included(ctx, height, c.namespace, proofs[i], commitment)
included = append(included, isIncluded)
}
return included, nil
Expand Down

0 comments on commit a648be6

Please sign in to comment.