diff --git a/celestia/celestia.go b/celestia/celestia.go index 9d7ac5c..87de649 100644 --- a/celestia/celestia.go +++ b/celestia/celestia.go @@ -36,16 +36,17 @@ func NewCelestiaDA(client *rpc.Client, namespace share.Namespace, ctx context.Co } // 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 } @@ -55,9 +56,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 @@ -71,13 +72,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 @@ -91,7 +92,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 } @@ -100,7 +101,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 } @@ -134,7 +135,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 { @@ -150,7 +151,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 ac4a26f..f4cdd19 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,20 +113,20 @@ 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)) }) t.Run("Submit_existing_with_gasprice", 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)) @@ -139,7 +140,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 82815e6..ee3ff29 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 b2680e9..d94d0cc 100644 --- a/go.mod +++ b/go.mod @@ -350,3 +350,5 @@ replace ( github.com/filecoin-project/dagstore => github.com/celestiaorg/dagstore v0.0.0-20230824094345-537c012aa403 github.com/tendermint/tendermint => github.com/celestiaorg/celestia-core v1.29.0-tm-v0.34.29 ) + +replace github.com/rollkit/go-da => github.com/rollkit/go-da v0.1.1-0.20240111224712-bff650eba569 diff --git a/go.sum b/go.sum index 6e80867..ca3a452 100644 --- a/go.sum +++ b/go.sum @@ -2102,8 +2102,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.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= -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.1.1-0.20240111224712-bff650eba569 h1:vNTYh1KJA7vgUWmHtbLlTLN18WExqlBtd368WX+GSBQ= +github.com/rollkit/go-da v0.1.1-0.20240111224712-bff650eba569/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=