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

Commit

Permalink
Merge pull request #46 from rollkit/tux/gas-price
Browse files Browse the repository at this point in the history
da: replace submit options with gas price
  • Loading branch information
tuxcanfly authored Jan 10, 2024
2 parents bec96db + f271436 commit 0d72059
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 10 deletions.
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 {
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, -1)
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}}, -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)
assert.NoError(t, err)
assert.Equal(t, 1, len(blobs))
assert.Equal(t, 1, len(proofs))
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(context.Context, []*blob.Blob, *blob.SubmitOptions) (uint64, error) {
func (m *MockBlobAPI) Submit(ctx context.Context, blobs []*blob.Blob, options *blob.SubmitOptions) (uint64, error) {
m.height += 1
return m.height, nil
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ 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
github.com/mitchellh/go-homedir v1.1.0
github.com/ory/dockertest/v3 v3.10.0
github.com/rollkit/go-da v0.0.0-20231225164956-a3533025ce47
github.com/rollkit/go-da v0.1.0
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
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
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.1.0 h1:FAEMTNF8mTsPuiUgYt2dQSMzw8iYPjiWq7692CS2mbY=
github.com/rollkit/go-da v0.1.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=
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 greater than or equal to zero.

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

If `gasPrice` is less than 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 increase the `gasPrice` to increase the fee for the transaction or use the default by passing a negative `gasPrice`.

### Validate

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

0 comments on commit 0d72059

Please sign in to comment.