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

da: replace submit options with gas price #46

Merged
merged 9 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
16 changes: 14 additions & 2 deletions celestia/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/binary"
"log"
"math"
"strings"

"github.com/celestiaorg/celestia-app/pkg/appconsts"
Expand All @@ -12,6 +13,8 @@ import (
"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 @@ -74,12 +77,21 @@ func (c *CelestiaDA) Commit(daBlobs []da.Blob) ([]da.Commitment, error) {
}

// Submit submits the Blobs to Data Availability layer.
func (c *CelestiaDA) Submit(daBlobs []da.Blob) ([]da.ID, []da.Proof, error) {
func (c *CelestiaDA) Submit(daBlobs []da.Blob, gasPrice float64) ([]da.ID, []da.Proof, error) {
blobs, commitments, err := c.blobsAndCommitments(daBlobs)
if err != nil {
return nil, nil, err
}
height, err := c.client.Blob.Submit(c.ctx, blobs, blob.DefaultSubmitOptions())
options := blob.DefaultSubmitOptions()
if gasPrice != 0 {
tuxcanfly marked this conversation as resolved.
Show resolved Hide resolved
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()
}
height, err := c.client.Blob.Submit(c.ctx, blobs, options)
if err != nil {
return nil, nil, err
}
Expand Down
11 changes: 9 additions & 2 deletions celestia/celestia_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestCelestiaDA(t *testing.T) {
})

t.Run("Submit_empty", func(t *testing.T) {
blobs, proofs, err := m.Submit(nil)
blobs, proofs, err := m.Submit(nil, 0)
assert.NoError(t, err)
assert.Equal(t, 0, len(blobs))
assert.Equal(t, 0, len(proofs))
Expand Down Expand Up @@ -118,7 +118,14 @@ func TestCelestiaDA(t *testing.T) {
})

t.Run("Submit_existing", func(t *testing.T) {
blobs, proofs, err := m.Submit([]Blob{[]byte{0x00, 0x01, 0x02}})
blobs, proofs, err := m.Submit([]Blob{[]byte{0x00, 0x01, 0x02}}, 0)
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)
assert.NoError(t, err)
assert.Equal(t, 1, len(blobs))
assert.Equal(t, 1, len(proofs))
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/celestiaorg/celestia-app v1.6.0
github.com/celestiaorg/celestia-node v0.12.2
github.com/celestiaorg/nmt v0.20.0
github.com/cosmos/cosmos-sdk v0.46.14
github.com/cristalhq/jwt v1.2.0
github.com/filecoin-project/go-jsonrpc v0.3.1
github.com/ipfs/go-log/v2 v2.5.1
Expand Down Expand Up @@ -69,7 +70,6 @@ require (
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-proto v1.0.0-alpha8 // indirect
github.com/cosmos/cosmos-sdk v0.46.14 // indirect
github.com/cosmos/cosmos-sdk/api v0.1.0 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogoproto v1.4.11 // indirect
Expand Down Expand Up @@ -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
)

tuxcanfly marked this conversation as resolved.
Show resolved Hide resolved
replace github.com/rollkit/go-da => github.com/rollkit/go-da v0.0.2-0.20240109213634-1bddfc5ae4fb
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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.0.0-20231225164956-a3533025ce47 h1:aprTK4O2aqZ/Mb1pqrxH6EdKs331oJEyf5OROpN1o1Q=
github.com/rollkit/go-da v0.0.0-20231225164956-a3533025ce47/go.mod h1:cy1LA9kCyCJHgszKkTh9hJn816l5Oa87GMA2c1imfqA=
github.com/rollkit/go-da v0.0.2-0.20240109213634-1bddfc5ae4fb h1:Z2KTpksnwizQ1/uY4owvwdZ52HGz4xuvqTuWDYtlsv8=
github.com/rollkit/go-da v0.0.2-0.20240109213634-1bddfc5ae4fb/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=
Expand Down
6 changes: 5 additions & 1 deletion specs/src/celestia-da.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,14 @@ The implementation calls `blob.CreateCommitments` which does not call any RPC me

Submit submits blobs and returns their ids and proofs.

The implementation calls [blob.Submit] RPC method with `DefaultSubmitOptions` on the Celestia Node API.
The implementation calls [blob.Submit] RPC method with `DefaultSubmitOptions` on the Celestia Node API if gasPrice is set to zero.

`DefaultSubmitOptions` uses default values for `Fee` and `GasLimit`.

If `gasPrice` is not zero, then it uses `app types` to `EstimateGas` based on the blob sizes and updates `GasLimit` and `Fee` on the `SubmitOptions` accordingly.

This way the client can default to `DefaultSubmitOptions` by passing in zero `gasPrice` and increase it to prioritise the transaction.

### Validate

Validate validates blob ids and proofs and returns whether they are included.
Expand Down