Skip to content

Commit

Permalink
feat!(celestia): update celestia-node api to v0.13.x (#779)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions <[email protected]>
  • Loading branch information
mtsitrin and github-actions authored May 5, 2024
1 parent 851b312 commit b004f7a
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 349 deletions.
2 changes: 1 addition & 1 deletion config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ gossiped_blocks_cache_size = {{ .BlockManagerConfig.GossipedBlocksCacheSize }}
bootstrap_time = "{{ .BootstrapTime }}"
#celestia config example:
# da_config = "{\"base_url\": \"http://127.0.0.1:26658\", \"timeout\": 60000000000, \"gas_prices\":0.1, \"gas_adjustment\": 1.3, \"token\":\"TOKEN\"}"
# da_config = "{\"base_url\": \"http://127.0.0.1:26658\", \"timeout\": 60000000000, \"gas_prices\":0.1, \"token\":\"TOKEN\"}"
# Avail config example:
# da_config = "{\"seed\": \"MNEMONIC\", \"api_url\": \"wss://kate.avail.tools/ws\", \"app_id\": 0, \"tip\":10}"
Expand Down
34 changes: 9 additions & 25 deletions da/celestia/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ import (
"github.com/dymensionxyz/dymint/gerr"

"github.com/avast/retry-go/v4"
"github.com/celestiaorg/celestia-openrpc/types/blob"
"github.com/celestiaorg/celestia-openrpc/types/header"
"github.com/celestiaorg/nmt"
"github.com/gogo/protobuf/proto"
"github.com/tendermint/tendermint/libs/pubsub"

openrpc "github.com/rollkit/celestia-openrpc"

"github.com/rollkit/celestia-openrpc/types/blob"
"github.com/rollkit/celestia-openrpc/types/header"
"github.com/rollkit/celestia-openrpc/types/share"
openrpc "github.com/celestiaorg/celestia-openrpc"
"github.com/celestiaorg/celestia-openrpc/types/share"

"github.com/dymensionxyz/dymint/da"
celtypes "github.com/dymensionxyz/dymint/da/celestia/types"
Expand Down Expand Up @@ -92,16 +91,8 @@ func (c *DataAvailabilityLayerClient) Init(config []byte, pubsubServer *pubsub.S
return err
}

if c.config.GasPrices != 0 && c.config.Fee != 0 {
return errors.New("can't set both gas prices and fee")
}

if c.config.Fee == 0 && c.config.GasPrices == 0 {
return errors.New("fee or gas prices must be set")
}

if c.config.GasAdjustment == 0 {
c.config.GasAdjustment = defaultGasAdjustment
if c.config.GasPrices == 0 {
return errors.New("gas prices must be set")
}

c.pubsubServer = pubsubServer
Expand Down Expand Up @@ -557,18 +548,11 @@ func (c *DataAvailabilityLayerClient) submit(daBlob da.Blob) (uint64, da.Commitm
return 0, nil, fmt.Errorf("zero commitments: %w", gerr.ErrNotFound)
}

options := openrpc.DefaultSubmitOptions()

blobSizes := make([]uint32, len(blobs))
for i, blob := range blobs {
blobSizes[i] = uint32(len(blob.Data))
}

estimatedGas := EstimateGas(blobSizes, DefaultGasPerBlobByte, DefaultTxSizeCostPerByte)
gasWanted := uint64(float64(estimatedGas) * c.config.GasAdjustment)
fees := c.calculateFees(gasWanted)
options.Fee = fees
options.GasLimit = gasWanted
ctx, cancel := context.WithTimeout(c.ctx, c.config.Timeout)
defer cancel()

Expand All @@ -581,7 +565,7 @@ func (c *DataAvailabilityLayerClient) submit(daBlob da.Blob) (uint64, da.Commitm
err = retry.Do(
func() error {
var err error
height, err = c.rpc.Submit(ctx, blobs, options)
height, err = c.rpc.Submit(ctx, blobs, openrpc.GasPrice(c.config.GasPrices))
return err
},
retry.Context(c.ctx),
Expand All @@ -594,7 +578,7 @@ func (c *DataAvailabilityLayerClient) submit(daBlob da.Blob) (uint64, da.Commitm
return 0, nil, fmt.Errorf("do rpc submit: %w", err)
}

c.logger.Info("Successfully submitted blobs to Celestia", "height", height, "gas", options.GasLimit, "fee", options.Fee)
c.logger.Info("Successfully submitted blobs to Celestia", "height", height)

return height, commitments[0], nil
}
Expand Down Expand Up @@ -643,7 +627,7 @@ func (c *DataAvailabilityLayerClient) getDataAvailabilityHeaders(height uint64)
ctx, cancel := context.WithTimeout(c.ctx, c.config.Timeout)
defer cancel()

headers, err := c.rpc.GetHeaders(ctx, height)
headers, err := c.rpc.GetByHeight(ctx, height)
if err != nil {
return nil, err
}
Expand Down
23 changes: 11 additions & 12 deletions da/celestia/celestia_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"testing"
"time"

"github.com/celestiaorg/celestia-openrpc/types/blob"
"github.com/celestiaorg/celestia-openrpc/types/header"
"github.com/celestiaorg/nmt"
"github.com/rollkit/celestia-openrpc/types/blob"
"github.com/rollkit/celestia-openrpc/types/header"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
Expand Down Expand Up @@ -59,12 +59,12 @@ func TestDALC(t *testing.T) {
mockRPCClient.On("Submit", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(uint64(1234), nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("GetProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&blobProof, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("Included", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(true, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("GetHeaders", mock.Anything, mock.Anything).Return(header, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("GetByHeight", mock.Anything, mock.Anything).Return(header, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })

mockRPCClient.On("Submit", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(uint64(1234), nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("GetProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&blobProof, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("Included", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(true, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("GetHeaders", mock.Anything, mock.Anything).Return(header, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("GetByHeight", mock.Anything, mock.Anything).Return(header, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })

time.Sleep(2 * mockDaBlockTime)

Expand Down Expand Up @@ -116,7 +116,7 @@ func TestRetrievalNotFound(t *testing.T) {
mockRPCClient.On("Submit", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(uint64(1234), nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("GetProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&blobProof, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("Included", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(true, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("GetHeaders", mock.Anything, mock.Anything).Return(headers, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("GetByHeight", mock.Anything, mock.Anything).Return(headers, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })

time.Sleep(2 * mockDaBlockTime)

Expand Down Expand Up @@ -189,7 +189,7 @@ func TestAvalabilityOK(t *testing.T) {
mockRPCClient.On("Submit", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(uint64(1234), nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("GetProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&blobProof, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("Included", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(true, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("GetHeaders", mock.Anything, mock.Anything).Return(headers, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("GetByHeight", mock.Anything, mock.Anything).Return(headers, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })

time.Sleep(2 * mockDaBlockTime)

Expand All @@ -203,7 +203,7 @@ func TestAvalabilityOK(t *testing.T) {

mockRPCClient.On("GetProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&blobProof, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("Included", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(true, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("GetHeaders", mock.Anything, mock.Anything).Return(headers, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("GetByHeight", mock.Anything, mock.Anything).Return(headers, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })

retriever := dalc.(da.BatchRetriever)

Expand Down Expand Up @@ -233,7 +233,7 @@ func TestAvalabilityWrongProof(t *testing.T) {
mockRPCClient.On("Submit", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(uint64(1234), nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("GetProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&blobProof, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("Included", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(true, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("GetHeaders", mock.Anything, mock.Anything).Return(headers, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("GetByHeight", mock.Anything, mock.Anything).Return(headers, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })

time.Sleep(2 * mockDaBlockTime)

Expand All @@ -246,7 +246,7 @@ func TestAvalabilityWrongProof(t *testing.T) {
assert.Equal(da.StatusSuccess, res1.Code)

mockRPCClient.On("GetProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("GetHeaders", mock.Anything, mock.Anything).Return(headers, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("GetByHeight", mock.Anything, mock.Anything).Return(headers, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })

retriever := dalc.(da.BatchRetriever)

Expand Down Expand Up @@ -278,7 +278,7 @@ func TestRetrievalWrongCommitment(t *testing.T) {
require.True(len(retrieveRes.Batches) == 0)

mockRPCClient.On("GetProof", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("GetHeaders", mock.Anything, mock.Anything).Return(headers, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })
mockRPCClient.On("GetByHeight", mock.Anything, mock.Anything).Return(headers, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) })

availRes := retriever.CheckBatchAvailability(h1)
assert.ErrorIs(availRes.Error, da.ErrUnableToGetProof)
Expand All @@ -302,8 +302,7 @@ func setDAandMock(t *testing.T) (*mocks.MockCelestiaRPCClient, da.DataAvailabili
config := celestia.Config{
BaseURL: "http://localhost:26658",
Timeout: 30 * time.Second,
GasLimit: 3000000,
Fee: 200000000,
GasPrices: celestia.CelestiaDefaultConfig.GasPrices,
NamespaceIDStr: "0000000000000000ffff",
}
err = config.InitNamespaceID()
Expand Down
17 changes: 5 additions & 12 deletions da/celestia/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import (

uretry "github.com/dymensionxyz/dymint/utils/retry"

openrpcns "github.com/rollkit/celestia-openrpc/types/namespace"
openrpcns "github.com/celestiaorg/celestia-openrpc/types/namespace"
)

const (
defaultRpcRetryDelay = 1 * time.Second
defaultRpcCheckAttempts = 10
namespaceVersion = 0
defaultGasPrices = 0.1
defaultGasAdjustment float64 = 1.3
defaultRpcRetryDelay = 1 * time.Second
defaultRpcCheckAttempts = 10
namespaceVersion = 0
defaultGasPrices = 0.1
)

var defaultSubmitBackoff = uretry.NewBackoffConfig(
Expand All @@ -29,10 +28,7 @@ type Config struct {
BaseURL string `json:"base_url"`
AppNodeURL string `json:"app_node_url"`
Timeout time.Duration `json:"timeout"`
Fee int64 `json:"fee"`
GasPrices float64 `json:"gas_prices"`
GasAdjustment float64 `json:"gas_adjustment"`
GasLimit uint64 `json:"gas_limit"`
NamespaceIDStr string `json:"namespace_id"`
AuthToken string `json:"auth_token"`
NamespaceID openrpcns.Namespace `json:"-"`
Expand All @@ -42,10 +38,7 @@ var CelestiaDefaultConfig = Config{
BaseURL: "http://127.0.0.1:26658",
AppNodeURL: "",
Timeout: 5 * time.Second,
Fee: 0,
GasLimit: 20000000,
GasPrices: defaultGasPrices,
GasAdjustment: defaultGasAdjustment,
NamespaceIDStr: "",
NamespaceID: openrpcns.Namespace{Version: namespaceVersion, ID: []byte{0, 0, 0, 0, 0, 0, 0, 0, 255, 255}},
}
Expand Down
72 changes: 0 additions & 72 deletions da/celestia/fees.go

This file was deleted.

79 changes: 0 additions & 79 deletions da/celestia/fees_test.go

This file was deleted.

Loading

0 comments on commit b004f7a

Please sign in to comment.