diff --git a/celestia/celestia.go b/celestia/celestia.go index 5f62717..f66934d 100644 --- a/celestia/celestia.go +++ b/celestia/celestia.go @@ -38,16 +38,17 @@ func NewCelestiaDA(client *rpc.Client, namespace share.Namespace, gasPrice float } // MaxBlobSize returns the max blob size -func (c *CelestiaDA) MaxBlobSize() (uint64, error) { +func (c *CelestiaDA) MaxBlobSize(ctx context.Context) (uint64, error) { + // TODO: pass-through query to node, app return appconsts.DefaultMaxBytes, nil } // Get returns Blob for each given ID, or an error. -func (c *CelestiaDA) Get(ids []da.ID) ([]da.Blob, error) { +func (c *CelestiaDA) Get(ctx context.Context, ids []da.ID) ([]da.Blob, error) { var blobs []da.Blob for _, id := range ids { height, commitment := splitID(id) - blob, err := c.client.Blob.Get(c.ctx, height, c.namespace, commitment) + blob, err := c.client.Blob.Get(ctx, height, c.namespace, commitment) if err != nil { return nil, err } @@ -57,9 +58,9 @@ func (c *CelestiaDA) Get(ids []da.ID) ([]da.Blob, error) { } // GetIDs returns IDs of all Blobs located in DA at given height. -func (c *CelestiaDA) GetIDs(height uint64) ([]da.ID, error) { +func (c *CelestiaDA) GetIDs(ctx context.Context, height uint64) ([]da.ID, error) { var ids []da.ID - blobs, err := c.client.Blob.GetAll(c.ctx, height, []share.Namespace{c.namespace}) + 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 @@ -73,13 +74,13 @@ func (c *CelestiaDA) GetIDs(height uint64) ([]da.ID, error) { } // Commit creates a Commitment for each given Blob. -func (c *CelestiaDA) Commit(daBlobs []da.Blob) ([]da.Commitment, error) { +func (c *CelestiaDA) Commit(ctx context.Context, daBlobs []da.Blob) ([]da.Commitment, error) { _, commitments, err := c.blobsAndCommitments(daBlobs) return commitments, err } // Submit submits the Blobs to Data Availability layer. -func (c *CelestiaDA) Submit(daBlobs []da.Blob, gasPrice float64) ([]da.ID, []da.Proof, error) { +func (c *CelestiaDA) Submit(ctx context.Context, daBlobs []da.Blob, gasPrice float64) ([]da.ID, []da.Proof, error) { blobs, commitments, err := c.blobsAndCommitments(daBlobs) if err != nil { return nil, nil, err @@ -97,7 +98,7 @@ func (c *CelestiaDA) Submit(daBlobs []da.Blob, gasPrice float64) ([]da.ID, []da. options.GasLimit = types.EstimateGas(blobSizes, appconsts.DefaultGasPerBlobByte, auth.DefaultTxSizeCostPerByte) options.Fee = sdktypes.NewInt(int64(math.Ceil(gasPrice * float64(options.GasLimit)))).Int64() } - height, err := c.client.Blob.Submit(c.ctx, blobs, options) + height, err := c.client.Blob.Submit(ctx, blobs, options) if err != nil { return nil, nil, err } @@ -106,7 +107,7 @@ func (c *CelestiaDA) Submit(daBlobs []da.Blob, gasPrice float64) ([]da.ID, []da. proofs := make([]da.Proof, len(daBlobs)) for i, commitment := range commitments { ids[i] = makeID(height, commitment) - proof, err := c.client.Blob.GetProof(c.ctx, height, c.namespace, commitment) + proof, err := c.client.Blob.GetProof(ctx, height, c.namespace, commitment) if err != nil { return nil, nil, err } @@ -140,7 +141,7 @@ func (c *CelestiaDA) blobsAndCommitments(daBlobs []da.Blob) ([]*blob.Blob, []da. } // Validate validates Commitments against the corresponding Proofs. This should be possible without retrieving the Blobs. -func (c *CelestiaDA) Validate(ids []da.ID, daProofs []da.Proof) ([]bool, error) { +func (c *CelestiaDA) Validate(ctx context.Context, ids []da.ID, daProofs []da.Proof) ([]bool, error) { var included []bool var proofs []*blob.Proof for _, daProof := range daProofs { @@ -156,7 +157,7 @@ func (c *CelestiaDA) Validate(ids []da.ID, daProofs []da.Proof) ([]bool, error) // 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(c.ctx, height, c.namespace, proofs[i], commitment) + isIncluded, _ := c.client.Blob.Included(ctx, height, c.namespace, proofs[i], commitment) included = append(included, isIncluded) } return included, nil diff --git a/celestia/celestia_test.go b/celestia/celestia_test.go index c35371e..5b3de0f 100644 --- a/celestia/celestia_test.go +++ b/celestia/celestia_test.go @@ -51,42 +51,43 @@ func teardown(m *mockDA) { // TestCelestiaDA is the test suite function. func TestCelestiaDA(t *testing.T) { + ctx := context.TODO() m := setup(t) defer teardown(m) t.Run("MaxBlobSize", func(t *testing.T) { - maxBlobSize, err := m.MaxBlobSize() + maxBlobSize, err := m.MaxBlobSize(ctx) assert.NoError(t, err) assert.Equal(t, uint64(appconsts.DefaultMaxBytes), maxBlobSize) }) t.Run("Get_empty", func(t *testing.T) { - blobs, err := m.Get(nil) + blobs, err := m.Get(ctx, nil) assert.NoError(t, err) assert.Equal(t, 0, len(blobs)) }) t.Run("GetIDs_empty", func(t *testing.T) { - blobs, err := m.GetIDs(0) + blobs, err := m.GetIDs(ctx, 0) assert.NoError(t, err) assert.Equal(t, 0, len(blobs)) }) t.Run("Commit_empty", func(t *testing.T) { - commitments, err := m.Commit(nil) + commitments, err := m.Commit(ctx, nil) assert.NoError(t, err) assert.Equal(t, 0, len(commitments)) }) t.Run("Submit_empty", func(t *testing.T) { - blobs, proofs, err := m.Submit(nil, -1) + blobs, proofs, err := m.Submit(ctx, nil, -1) 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(nil, nil) + valids, err := m.Validate(ctx, nil, nil) assert.NoError(t, err) assert.Equal(t, 0, len(valids)) }) @@ -94,7 +95,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([]ID{makeID(42, commitment)}) + blobs, err := m.Get(ctx, []ID{makeID(42, commitment)}) assert.NoError(t, err) assert.Equal(t, 1, len(blobs)) blob1 := blobs[0] @@ -102,7 +103,7 @@ func TestCelestiaDA(t *testing.T) { }) t.Run("GetIDs_existing", func(t *testing.T) { - ids, err := m.GetIDs(42) + ids, err := m.GetIDs(ctx, 42) assert.NoError(t, err) assert.Equal(t, 1, len(ids)) id1 := ids[0] @@ -112,13 +113,13 @@ func TestCelestiaDA(t *testing.T) { }) t.Run("Commit_existing", func(t *testing.T) { - commitments, err := m.Commit([]Blob{[]byte{0x00, 0x01, 0x02}}) + commitments, err := m.Commit(ctx, []Blob{[]byte{0x00, 0x01, 0x02}}) assert.NoError(t, err) assert.Equal(t, 1, len(commitments)) }) t.Run("Submit_existing", func(t *testing.T) { - blobs, proofs, err := m.Submit([]Blob{[]byte{0x00, 0x01, 0x02}}, -1) + blobs, proofs, err := m.Submit(ctx, []Blob{[]byte{0x00, 0x01, 0x02}}, -1) assert.NoError(t, err) assert.Equal(t, 1, len(blobs)) assert.Equal(t, 1, len(proofs)) @@ -126,14 +127,14 @@ func TestCelestiaDA(t *testing.T) { t.Run("Submit_existing_with_gasprice_global", func(t *testing.T) { m.CelestiaDA.gasPrice = 0.01 - blobs, proofs, err := m.Submit([]Blob{[]byte{0x00, 0x01, 0x02}}, -1) + blobs, proofs, err := m.Submit(ctx, []Blob{[]byte{0x00, 0x01, 0x02}}, -1) 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([]Blob{[]byte{0x00, 0x01, 0x02}}, 0.5) + blobs, proofs, err := m.Submit(ctx, []Blob{[]byte{0x00, 0x01, 0x02}}, 0.5) assert.NoError(t, err) assert.Equal(t, 1, len(blobs)) assert.Equal(t, 1, len(proofs)) @@ -147,7 +148,7 @@ func TestCelestiaDA(t *testing.T) { assert.NoError(t, err) ids := []ID{makeID(42, commitment)} proofs := []Proof{proofJSON} - valids, err := m.Validate(ids, proofs) + valids, err := m.Validate(ctx, ids, proofs) assert.NoError(t, err) assert.Equal(t, 1, len(valids)) }) diff --git a/celestia_test.go b/celestia_test.go index c8738ff..0e62728 100644 --- a/celestia_test.go +++ b/celestia_test.go @@ -22,6 +22,8 @@ import ( "github.com/rollkit/go-da/test" ) +const localCelestiaDevnetImageVersion = "v0.12.5" + type TestSuite struct { suite.Suite @@ -45,7 +47,7 @@ func (t *TestSuite) SetupSuite() { } // pulls an image, creates a container based on it and runs it - resource, err := pool.Run("ghcr.io/rollkit/local-celestia-devnet", "v0.12.5", []string{}) + resource, err := pool.Run("ghcr.io/rollkit/local-celestia-devnet", localCelestiaDevnetImageVersion, []string{}) if err != nil { t.Failf("Could not start resource", "error: %v\n", err) } diff --git a/go.mod b/go.mod index 6d7cbe5..0c83819 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/ipfs/go-log/v2 v2.5.1 github.com/mitchellh/go-homedir v1.1.0 github.com/ory/dockertest/v3 v3.10.0 - github.com/rollkit/go-da v0.1.0 + github.com/rollkit/go-da v0.2.0 github.com/spf13/cobra v1.8.0 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index 83d7af6..fd33f50 100644 --- a/go.sum +++ b/go.sum @@ -2103,8 +2103,8 @@ github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTE github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= -github.com/rollkit/go-da v0.1.0 h1:FAEMTNF8mTsPuiUgYt2dQSMzw8iYPjiWq7692CS2mbY= -github.com/rollkit/go-da v0.1.0/go.mod h1:Kef0XI5ecEKd3TXzI8S+9knAUJnZg0svh2DuXoCsPlM= +github.com/rollkit/go-da v0.2.0 h1:rNpWBa2inczgZ955ky3wy8FbrMajzVbm0UfbBGzm5UE= +github.com/rollkit/go-da v0.2.0/go.mod h1:Kef0XI5ecEKd3TXzI8S+9knAUJnZg0svh2DuXoCsPlM= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/cors v1.9.0 h1:l9HGsTsHJcvW14Nk7J9KFz8bzeAWXn3CG6bgt7LsrAE= github.com/rs/cors v1.9.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU=