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

bump(deps): update celestia-node to v0.13.0 #76

Merged
merged 6 commits into from
Feb 12, 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
81 changes: 42 additions & 39 deletions celestia/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
"context"
"encoding/binary"
"log"
"math"
"strings"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
"github.com/celestiaorg/celestia-app/x/blob/types"
rpc "github.com/celestiaorg/celestia-node/api/rpc/client"
"github.com/celestiaorg/celestia-node/blob"
"github.com/celestiaorg/celestia-node/share"
"github.com/celestiaorg/nmt"
sdktypes "github.com/cosmos/cosmos-sdk/types"
auth "github.com/cosmos/cosmos-sdk/x/auth/types"

"github.com/rollkit/go-da"
)
Expand Down Expand Up @@ -47,14 +43,22 @@
}
}

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
return DefaultMaxBytes, nil
}

// Get returns Blob for each given ID, or an error.
func (c *CelestiaDA) Get(ctx context.Context, ids []da.ID) ([]da.Blob, error) {
func (c *CelestiaDA) Get(ctx context.Context, ids []da.ID, ns da.Namespace) ([]da.Blob, error) {
c.namespace = c.defaultNamespace(ns)
var blobs []da.Blob
for _, id := range ids {
height, commitment := splitID(id)
Expand All @@ -68,7 +72,8 @@
}

// GetIDs returns IDs of all Blobs located in DA at given height.
func (c *CelestiaDA) GetIDs(ctx context.Context, height uint64) ([]da.ID, error) {
func (c *CelestiaDA) GetIDs(ctx context.Context, height uint64, ns da.Namespace) ([]da.ID, error) {
c.namespace = c.defaultNamespace(ns)
var ids []da.ID
blobs, err := c.client.Blob.GetAll(ctx, height, []share.Namespace{c.namespace})
if err != nil {
Expand All @@ -84,58 +89,55 @@
}

// Commit creates a Commitment for each given Blob.
func (c *CelestiaDA) Commit(ctx context.Context, daBlobs []da.Blob) ([]da.Commitment, error) {
_, commitments, err := c.blobsAndCommitments(daBlobs)
func (c *CelestiaDA) Commit(ctx context.Context, daBlobs []da.Blob, ns da.Namespace) ([]da.Commitment, error) {
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) ([]da.ID, []da.Proof, error) {
blobs, commitments, err := c.blobsAndCommitments(daBlobs)
func (c *CelestiaDA) Submit(ctx context.Context, daBlobs []da.Blob, gasPrice float64, ns da.Namespace) ([]da.ID, error) {
c.namespace = c.defaultNamespace(ns)
blobs, _, err := c.blobsAndCommitments(daBlobs, c.namespace)
if err != nil {
return nil, nil, err
}
options := blob.DefaultSubmitOptions()
// if gas price was configured globally use that as the default
if c.gasPrice >= 0 && gasPrice < 0 {
gasPrice = c.gasPrice
}
if gasPrice >= 0 {
blobSizes := make([]uint32, len(blobs))
for i, blob := range blobs {
blobSizes[i] = uint32(len(blob.Data))
}
options.GasLimit = types.EstimateGas(blobSizes, appconsts.DefaultGasPerBlobByte, auth.DefaultTxSizeCostPerByte)
options.Fee = sdktypes.NewInt(int64(math.Ceil(gasPrice * float64(options.GasLimit)))).Int64()
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
}
height, err := c.client.Blob.Submit(ctx, blobs, options)
height, err := c.client.Blob.Submit(ctx, blobs, blob.GasPrice(gasPrice))
if err != nil {
return nil, nil, err
return nil, err
}

Check warning on line 108 in celestia/celestia.go

View check run for this annotation

Codecov / codecov/patch

celestia/celestia.go#L107-L108

Added lines #L107 - L108 were not covered by tests
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)
}
log.Println("successfully submitted blobs", "height", height, "gas", options.GasLimit, "fee", options.Fee)
ids := make([]da.ID, len(daBlobs))
proofs := make([]da.Proof, len(daBlobs))
for i, commitment := range commitments {
ids[i] = makeID(height, commitment)
return ids, nil
}

// 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) {
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, c.namespace, commitment)
if err != nil {
return nil, nil, err
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
}
// TODO(tzdybal): does always len(*proof) == 1?
proofs[i], err = (*proof)[0].MarshalJSON()
proofs[i], err = proof.MarshalJSON()

Check warning on line 127 in celestia/celestia.go

View check run for this annotation

Codecov / codecov/patch

celestia/celestia.go#L127

Added line #L127 was not covered by tests
if err != nil {
return nil, nil, err
return nil, err

Check warning on line 129 in celestia/celestia.go

View check run for this annotation

Codecov / codecov/patch

celestia/celestia.go#L129

Added line #L129 was not covered by tests
}
}
return ids, proofs, nil
return proofs, nil

Check warning on line 132 in celestia/celestia.go

View check run for this annotation

Codecov / codecov/patch

celestia/celestia.go#L132

Added line #L132 was not covered by tests
}

// blobsAndCommitments converts []da.Blob to []*blob.Blob and generates corresponding []da.Commitment
func (c *CelestiaDA) blobsAndCommitments(daBlobs []da.Blob) ([]*blob.Blob, []da.Commitment, error) {
func (c *CelestiaDA) blobsAndCommitments(daBlobs []da.Blob, ns da.Namespace) ([]*blob.Blob, []da.Commitment, error) {
var blobs []*blob.Blob
var commitments []da.Commitment
for _, daBlob := range daBlobs {
b, err := blob.NewBlobV0(c.namespace, daBlob)
b, err := blob.NewBlobV0(ns, daBlob)
if err != nil {
return nil, nil, err
}
Expand All @@ -151,7 +153,8 @@
}

// 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) ([]bool, error) {
func (c *CelestiaDA) Validate(ctx context.Context, ids []da.ID, daProofs []da.Proof, ns da.Namespace) ([]bool, error) {
c.namespace = c.defaultNamespace(ns)
var included []bool
var proofs []*blob.Proof
for _, daProof := range daProofs {
Expand Down
45 changes: 24 additions & 21 deletions celestia/celestia_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ func setup(t *testing.T) *mockDA {

t.Logf("mock json-rpc server listening on: %s", mockService.server.URL)

ctx := context.TODO()
client, err := rpc.NewClient(ctx, mockService.server.URL, "test")
nsHex, err := hex.DecodeString("0000c9761e8b221ae42f")
assert.NoError(t, err)
ns, err := hex.DecodeString("0000c9761e8b221ae42f")
ns, err := share.NewBlobNamespaceV0(nsHex)
assert.NoError(t, err)
namespace, err := share.NewBlobNamespaceV0(ns)

ctx := context.TODO()
client, err := rpc.NewClient(ctx, mockService.server.URL, "test")
assert.NoError(t, err)
da := NewCelestiaDA(client, namespace, -1, ctx)
da := NewCelestiaDA(client, ns, -1, ctx)
assert.Equal(t, da.client, client)

return &mockDA{mockService, *da}
Expand All @@ -54,55 +55,60 @@ func TestCelestiaDA(t *testing.T) {
m := setup(t)
defer teardown(m)

nsHex, err := hex.DecodeString("0000c9761e8b221ae42f")
assert.NoError(t, err)
ns, err := share.NewBlobNamespaceV0(nsHex)
assert.NoError(t, err)

assert.NoError(t, err)
t.Run("MaxBlobSize", func(t *testing.T) {
maxBlobSize, err := m.MaxBlobSize(ctx)
assert.NoError(t, err)
assert.Equal(t, uint64(DefaultMaxBytes), maxBlobSize)
})

t.Run("Get_empty", func(t *testing.T) {
blobs, err := m.Get(ctx, nil)
blobs, err := m.Get(ctx, nil, ns)
assert.NoError(t, err)
assert.Equal(t, 0, len(blobs))
})

t.Run("GetIDs_empty", func(t *testing.T) {
blobs, err := m.GetIDs(ctx, 0)
blobs, err := m.GetIDs(ctx, 0, ns)
assert.NoError(t, err)
assert.Equal(t, 0, len(blobs))
})

t.Run("Commit_empty", func(t *testing.T) {
commitments, err := m.Commit(ctx, nil)
commitments, err := m.Commit(ctx, nil, ns)
assert.NoError(t, err)
assert.Equal(t, 0, len(commitments))
})

t.Run("Submit_empty", func(t *testing.T) {
blobs, proofs, err := m.Submit(ctx, nil, -1)
blobs, err := m.Submit(ctx, nil, -1, ns)
assert.NoError(t, err)
assert.Equal(t, 0, len(blobs))
assert.Equal(t, 0, len(proofs))
})

t.Run("Validate_empty", func(t *testing.T) {
valids, err := m.Validate(ctx, nil, nil)
valids, err := m.Validate(ctx, nil, nil, ns)
assert.NoError(t, err)
assert.Equal(t, 0, len(valids))
})

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)})
blobs, err := m.Get(ctx, []ID{makeID(42, commitment)}, ns)
assert.NoError(t, err)
assert.Equal(t, 1, len(blobs))
blob1 := blobs[0]
assert.Equal(t, "This is an example of some blob data", string(blob1))
})

t.Run("GetIDs_existing", func(t *testing.T) {
ids, err := m.GetIDs(ctx, 42)
ids, err := m.GetIDs(ctx, 42, ns)
assert.NoError(t, err)
assert.Equal(t, 1, len(ids))
id1 := ids[0]
Expand All @@ -112,31 +118,28 @@ func TestCelestiaDA(t *testing.T) {
})

t.Run("Commit_existing", func(t *testing.T) {
commitments, err := m.Commit(ctx, []Blob{[]byte{0x00, 0x01, 0x02}})
commitments, err := m.Commit(ctx, []Blob{[]byte{0x00, 0x01, 0x02}}, ns)
assert.NoError(t, err)
assert.Equal(t, 1, len(commitments))
})

t.Run("Submit_existing", func(t *testing.T) {
blobs, proofs, err := m.Submit(ctx, []Blob{[]byte{0x00, 0x01, 0x02}}, -1)
blobs, err := m.Submit(ctx, []Blob{[]byte{0x00, 0x01, 0x02}}, -1, ns)
assert.NoError(t, err)
assert.Equal(t, 1, len(blobs))
assert.Equal(t, 1, len(proofs))
})

t.Run("Submit_existing_with_gasprice_global", func(t *testing.T) {
m.CelestiaDA.gasPrice = 0.01
blobs, proofs, err := m.Submit(ctx, []Blob{[]byte{0x00, 0x01, 0x02}}, -1)
blobs, err := m.Submit(ctx, []Blob{[]byte{0x00, 0x01, 0x02}}, -1, ns)
assert.NoError(t, err)
assert.Equal(t, 1, len(blobs))
assert.Equal(t, 1, len(proofs))
})

t.Run("Submit_existing_with_gasprice_override", func(t *testing.T) {
blobs, proofs, err := m.Submit(ctx, []Blob{[]byte{0x00, 0x01, 0x02}}, 0.5)
blobs, err := m.Submit(ctx, []Blob{[]byte{0x00, 0x01, 0x02}}, 0.5, ns)
assert.NoError(t, err)
assert.Equal(t, 1, len(blobs))
assert.Equal(t, 1, len(proofs))
})

t.Run("Validate_existing", func(t *testing.T) {
Expand All @@ -147,7 +150,7 @@ func TestCelestiaDA(t *testing.T) {
assert.NoError(t, err)
ids := []ID{makeID(42, commitment)}
proofs := []Proof{proofJSON}
valids, err := m.Validate(ctx, ids, proofs)
valids, err := m.Validate(ctx, ids, proofs, ns)
assert.NoError(t, err)
assert.Equal(t, 1, len(valids))
})
Expand Down
2 changes: 1 addition & 1 deletion celestia/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type MockBlobAPI struct {
}

// Submit mocks the blob.Submit method
func (m *MockBlobAPI) Submit(ctx context.Context, blobs []*blob.Blob, options *blob.SubmitOptions) (uint64, error) {
func (m *MockBlobAPI) Submit(ctx context.Context, blobs []*blob.Blob, gasPrice float64) (uint64, error) {
m.height += 1
return m.height, nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/celestia-da/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func WithDataAvailabilityService(flags []*pflag.FlagSet) func(*cobra.Command) {
grpcFlags := &pflag.FlagSet{}
grpcFlags.String(grpcAddrFlag, "http://127.0.0.1:26658", "celestia-node RPC endpoint address")
grpcFlags.String(grpcTokenFlag, "", "celestia-node RPC auth token")
grpcFlags.String(grpcNamespaceFlag, "", "celestia namespace to use (hex encoded)")
grpcFlags.String(grpcNamespaceFlag, "", "celestia namespace to use (hex encoded) [Deprecated]")
tuxcanfly marked this conversation as resolved.
Show resolved Hide resolved
grpcFlags.String(grpcListenFlag, "127.0.0.1:0", "gRPC service listen address")
grpcFlags.String(grpcNetworkFlag, "tcp", "gRPC service listen network type must be \"tcp\", \"tcp4\", \"tcp6\", \"unix\" or \"unixpacket\"")
grpcFlags.Float64(grpcGasPriceFlag, -1, "gas price for estimating fee (utia/gas) default: -1 for default fees")
Expand Down
Loading
Loading