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

Commit

Permalink
nit: unexport makeid, splitid
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxcanfly committed Feb 12, 2024
1 parent 214d131 commit 8c4a8c9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions celestia/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (c *CelestiaDA) Get(ctx context.Context, ids []da.ID, ns da.Namespace) ([]d
}

Check warning on line 56 in celestia/celestia.go

View check run for this annotation

Codecov / codecov/patch

celestia/celestia.go#L55-L56

Added lines #L55 - L56 were not covered by tests
var blobs []da.Blob
for _, id := range ids {
height, commitment := SplitID(id)
height, commitment := splitID(id)
blob, err := c.client.Blob.Get(ctx, height, ns, commitment)
if err != nil {
return nil, err
Expand All @@ -77,7 +77,7 @@ func (c *CelestiaDA) GetIDs(ctx context.Context, height uint64, ns da.Namespace)
return nil, err
}
for _, b := range blobs {
ids = append(ids, MakeID(height, b.Commitment))
ids = append(ids, makeID(height, b.Commitment))
}
return ids, nil
}
Expand Down Expand Up @@ -107,7 +107,7 @@ func (c *CelestiaDA) Submit(ctx context.Context, daBlobs []da.Blob, gasPrice flo
log.Println("successfully submitted blobs", "height", height, "gasPrice", gasPrice)
ids := make([]da.ID, len(blobs))
for i, blob := range blobs {
ids[i] = MakeID(height, blob.Commitment)
ids[i] = makeID(height, blob.Commitment)
}
return ids, nil
}
Expand All @@ -119,7 +119,7 @@ func (c *CelestiaDA) GetProofs(ctx context.Context, daIDs []da.ID, ns da.Namespa
}
proofs := make([]da.Proof, len(daIDs))
for i, id := range daIDs {
height, commitment := SplitID(id)
height, commitment := splitID(id)
proof, err := c.client.Blob.GetProof(ctx, height, ns, commitment)

Check warning on line 123 in celestia/celestia.go

View check run for this annotation

Codecov / codecov/patch

celestia/celestia.go#L116-L123

Added lines #L116 - L123 were not covered by tests
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 @@ -168,7 +168,7 @@ func (c *CelestiaDA) Validate(ctx context.Context, ids []da.ID, daProofs []da.Pr
proofs = append(proofs, proof)
}
for i, id := range ids {
height, commitment := SplitID(id)
height, commitment := splitID(id)
// 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
Expand All @@ -184,15 +184,15 @@ func (c *CelestiaDA) Validate(ctx context.Context, ids []da.ID, daProofs []da.Pr
const heightLen = 8

// MakeID returns the ID from the height and commitment.
func MakeID(height uint64, commitment da.Commitment) da.ID {
func makeID(height uint64, commitment da.Commitment) da.ID {
id := make([]byte, heightLen+len(commitment))
binary.LittleEndian.PutUint64(id, height)
copy(id[heightLen:], commitment)
return id
}

// SplitID returns the height and commitment from the ID.
func SplitID(id da.ID) (uint64, da.Commitment) {
func splitID(id da.ID) (uint64, da.Commitment) {
if len(id) <= heightLen {
return 0, nil
}
Expand Down
6 changes: 3 additions & 3 deletions celestia/celestia_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestCelestiaDA(t *testing.T) {
t.Run("Get_existing", func(t *testing.T) {
commitment, err := hex.DecodeString("1b454951cd722b2cf7be5b04554b76ccf48f65a7ad6af45055006994ce70fd9d")
assert.NoError(t, err)
blobs, err := m.Get(ctx, []ID{MakeID(42, commitment)}, ns)
blobs, err := m.Get(ctx, []ID{makeID(42, commitment)}, ns)
assert.NoError(t, err)
assert.Equal(t, 1, len(blobs))
blob1 := blobs[0]
Expand All @@ -114,7 +114,7 @@ func TestCelestiaDA(t *testing.T) {
id1 := ids[0]
commitment, err := hex.DecodeString("1b454951cd722b2cf7be5b04554b76ccf48f65a7ad6af45055006994ce70fd9d")
assert.NoError(t, err)
assert.Equal(t, MakeID(42, commitment), id1)
assert.Equal(t, makeID(42, commitment), id1)
})

t.Run("Commit_existing", func(t *testing.T) {
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestCelestiaDA(t *testing.T) {
proof := nmt.NewInclusionProof(0, 4, [][]byte{[]byte("test")}, true)
proofJSON, err := proof.MarshalJSON()
assert.NoError(t, err)
ids := []ID{MakeID(42, commitment)}
ids := []ID{makeID(42, commitment)}
proofs := []Proof{proofJSON}
valids, err := m.Validate(ctx, ids, proofs, ns)
assert.NoError(t, err)
Expand Down

0 comments on commit 8c4a8c9

Please sign in to comment.