From b004f7abbd4d0ad448934cdd4b0fb83d6ab9e47e Mon Sep 17 00:00:00 2001 From: Michael Tsitrin <114929630+mtsitrin@users.noreply.github.com> Date: Sun, 5 May 2024 13:31:16 +0300 Subject: [PATCH] feat!(celestia): update celestia-node api to `v0.13.x` (#779) Co-authored-by: github-actions --- config/toml.go | 2 +- da/celestia/celestia.go | 34 ++--- da/celestia/celestia_test.go | 23 ++-- da/celestia/config.go | 17 +-- da/celestia/fees.go | 72 ---------- da/celestia/fees_test.go | 79 ----------- da/celestia/rpc.go | 26 +--- da/celestia/rpc_test.go | 14 +- da/celestia/types/rpc.go | 25 ++-- da/da.go | 2 +- da/da_test.go | 7 +- go.mod | 5 +- go.sum | 8 +- .../celestia/types/mock_CelestiaRPCClient.go | 125 +++++------------- 14 files changed, 90 insertions(+), 349 deletions(-) delete mode 100644 da/celestia/fees.go delete mode 100644 da/celestia/fees_test.go diff --git a/config/toml.go b/config/toml.go index 4f9249dd9..75b0e1e28 100644 --- a/config/toml.go +++ b/config/toml.go @@ -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}" diff --git a/da/celestia/celestia.go b/da/celestia/celestia.go index a26e5fc84..d717581f8 100644 --- a/da/celestia/celestia.go +++ b/da/celestia/celestia.go @@ -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" @@ -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 @@ -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() @@ -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), @@ -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 } @@ -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 } diff --git a/da/celestia/celestia_test.go b/da/celestia/celestia_test.go index db45956a4..e575fb0ba 100644 --- a/da/celestia/celestia_test.go +++ b/da/celestia/celestia_test.go @@ -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" @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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() diff --git a/da/celestia/config.go b/da/celestia/config.go index 21fd1c6b1..d76512e96 100644 --- a/da/celestia/config.go +++ b/da/celestia/config.go @@ -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( @@ -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:"-"` @@ -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}}, } diff --git a/da/celestia/fees.go b/da/celestia/fees.go deleted file mode 100644 index 0418db0c9..000000000 --- a/da/celestia/fees.go +++ /dev/null @@ -1,72 +0,0 @@ -package celestia - -import ( - "math" - - "github.com/dymensionxyz/dymint/da/celestia/types" -) - -const ( - ShareSize = types.ShareSize - - // PFBGasFixedCost is a rough estimate for the "fixed cost" in the gas cost - // formula: gas cost = gas per byte * bytes per share * shares occupied by - // blob + "fixed cost". In this context, "fixed cost" accounts for the gas - // consumed by operations outside the blob's GasToConsume function (i.e. - // signature verification, tx size, read access to accounts). - // - // Since the gas cost of these operations is not easy to calculate, linear - // regression was performed on a set of observed data points to derive an - // approximate formula for gas cost. Assuming gas per byte = 8 and bytes per - // share = 512, we can solve for "fixed cost" and arrive at 65,000. gas cost - // = 8 * 512 * number of shares occupied by the blob + 65,000 has a - // correlation coefficient of 0.996. To be conservative, we round up "fixed - // cost" to 75,000 because the first tx always takes up 10,000 more gas than - // subsequent txs. - PFBGasFixedCost = 75000 - - // BytesPerBlobInfo is a rough estimation for the amount of extra bytes in - // information a blob adds to the size of the underlying transaction. - BytesPerBlobInfo = 70 - - // DefaultGasPerBlobByte is the default gas cost deducted per byte of blob - // included in a PayForBlobs txn - DefaultGasPerBlobByte = 8 - - DefaultTxSizeCostPerByte uint64 = 10 -) - -func (c *DataAvailabilityLayerClient) calculateFees(gas uint64) int64 { - fees := c.config.Fee - if fees == 0 { - fees = int64(math.Ceil(c.config.GasPrices * float64(gas))) - } - - return fees -} - -// GasToConsume works out the extra gas charged to pay for a set of blobs in a PFB. -// Note that tranasctions will incur other gas costs, such as the signature verification -// and reads to the user's account. -func GasToConsume(blobSizes []uint32, gasPerByte uint32) uint64 { - var totalSharesUsed uint64 - for _, size := range blobSizes { - totalSharesUsed += uint64(types.SparseSharesNeeded(size)) - } - - return totalSharesUsed * types.ShareSize * uint64(gasPerByte) -} - -// EstimateGas estimates the total gas required to pay for a set of blobs in a PFB. -// It is based on a linear model that is dependent on the governance parameters: -// gasPerByte and txSizeCost. It assumes other variables are constant. This includes -// assuming the PFB is the only message in the transaction. -func EstimateGas(blobSizes []uint32, gasPerByte uint32, txSizeCost uint64) uint64 { - return GasToConsume(blobSizes, gasPerByte) + (txSizeCost * BytesPerBlobInfo * uint64(len(blobSizes))) + PFBGasFixedCost -} - -// DefaultEstimateGas runs EstimateGas with the system defaults. The network may change these values -// through governance, thus this function should predominantly be used in testing. -func DefaultEstimateGas(blobSize uint32) uint64 { - return EstimateGas([]uint32{blobSize}, DefaultGasPerBlobByte, DefaultTxSizeCostPerByte) -} diff --git a/da/celestia/fees_test.go b/da/celestia/fees_test.go deleted file mode 100644 index f17db83dc..000000000 --- a/da/celestia/fees_test.go +++ /dev/null @@ -1,79 +0,0 @@ -package celestia_test - -import ( - "testing" - - "github.com/dymensionxyz/dymint/da/celestia" - "github.com/stretchr/testify/assert" -) - -const ( - gasAdjust = 2 -) - -func Test(t *testing.T) { - testCases := []struct { - desc string - blobSize uint32 - measuredGas uint64 - gasAdjust float64 - }{ - { - desc: "", - blobSize: 3576, - measuredGas: 106230, - }, - { - desc: "", - blobSize: 6282, - measuredGas: 120850, - }, - { - desc: "", - blobSize: 12074, - measuredGas: 170002, - gasAdjust: gasAdjust, - }, - { - desc: "", - blobSize: 16908, - measuredGas: 323804, - gasAdjust: gasAdjust, - }, - { - desc: "", - blobSize: 31343, - measuredGas: 333852, - }, - { - desc: "", - blobSize: 43248, - measuredGas: 432156, - }, - { - // time="2023-07-30T18:23:38Z" level=debug msg="Submitting to da blob with size[size 506524]" module=celestia - // time="2023-07-30T18:23:38Z" level=error msg="Failed to submit DA batch. Emitting health event and trying again[txResponse insufficient fees; got: 100000utia required: 668882utia: insufficient fee code 13]" module=celestia - desc: "logged while using fixed price", - blobSize: 506524, - measuredGas: 6688820, - gasAdjust: gasAdjust, - }, - { - // time="2023-07-31T09:09:38Z" level=debug msg="Submitting to da blob with size[size 1499572]" module=celestia - // time="2023-07-31T09:09:40Z" level=error msg="Failed to submit DA batch. Emitting health event and trying again[txResponse insufficient fees; got: 1000000utia required: 1959844utia: insufficient fee code 13]" module=celestia - desc: "logged while using fixed price", - blobSize: 1499572, - measuredGas: 19598440, - gasAdjust: gasAdjust, - }, - } - for _, tC := range testCases { - t.Run(tC.desc, func(t *testing.T) { - expectedGas := celestia.DefaultEstimateGas(tC.blobSize) - if tC.gasAdjust != 0 { - expectedGas = uint64(float64(expectedGas) * tC.gasAdjust) - } - assert.GreaterOrEqual(t, expectedGas, tC.measuredGas, "calculated gas is less than actually measured") - }) - } -} diff --git a/da/celestia/rpc.go b/da/celestia/rpc.go index 48eec1c67..65304951a 100644 --- a/da/celestia/rpc.go +++ b/da/celestia/rpc.go @@ -3,12 +3,10 @@ package celestia import ( "context" - "github.com/rollkit/celestia-openrpc/types/blob" - "github.com/rollkit/celestia-openrpc/types/header" - "github.com/rollkit/celestia-openrpc/types/share" - "github.com/rollkit/celestia-openrpc/types/state" - - openrpc "github.com/rollkit/celestia-openrpc" + openrpc "github.com/celestiaorg/celestia-openrpc" + "github.com/celestiaorg/celestia-openrpc/types/blob" + "github.com/celestiaorg/celestia-openrpc/types/header" + "github.com/celestiaorg/celestia-openrpc/types/share" "github.com/dymensionxyz/dymint/da/celestia/types" ) @@ -27,24 +25,14 @@ func NewOpenRPC(rpc *openrpc.Client) *OpenRPC { } } -// SubmitPayForBlob submits a pay for blob transaction. -func (c *OpenRPC) SubmitPayForBlob( - ctx context.Context, - fee state.Int, - gasLim uint64, - blobs []*blob.Blob, -) (*state.TxResponse, error) { - return c.rpc.State.SubmitPayForBlob(ctx, fee, gasLim, blobs) -} - // GetAll gets all blobs. func (c *OpenRPC) GetAll(ctx context.Context, height uint64, namespaces []share.Namespace) ([]*blob.Blob, error) { return c.rpc.Blob.GetAll(ctx, height, namespaces) } // Submit blobs. -func (c *OpenRPC) Submit(ctx context.Context, blobs []*blob.Blob, options *openrpc.SubmitOptions) (uint64, error) { - return c.rpc.Blob.Submit(ctx, blobs, options) +func (c *OpenRPC) Submit(ctx context.Context, blobs []*blob.Blob, gasPrice openrpc.GasPrice) (uint64, error) { + return c.rpc.Blob.Submit(ctx, blobs, gasPrice) } // Getting proof for submitted blob @@ -58,7 +46,7 @@ func (c *OpenRPC) Get(ctx context.Context, height uint64, namespace share.Namesp } // Get extended Celestia headers for a specific height -func (c *OpenRPC) GetHeaders(ctx context.Context, height uint64) (*header.ExtendedHeader, error) { +func (c *OpenRPC) GetByHeight(ctx context.Context, height uint64) (*header.ExtendedHeader, error) { return c.rpc.Header.GetByHeight(ctx, height) } diff --git a/da/celestia/rpc_test.go b/da/celestia/rpc_test.go index 3ab20d64b..11f622533 100644 --- a/da/celestia/rpc_test.go +++ b/da/celestia/rpc_test.go @@ -10,6 +10,8 @@ import ( "testing" "time" + "github.com/celestiaorg/celestia-openrpc/types/blob" + "github.com/celestiaorg/celestia-openrpc/types/header" uretry "github.com/dymensionxyz/dymint/utils/retry" "github.com/dymensionxyz/dymint/da" @@ -17,8 +19,6 @@ import ( mocks "github.com/dymensionxyz/dymint/mocks/github.com/dymensionxyz/dymint/da/celestia/types" "github.com/dymensionxyz/dymint/testutil" "github.com/dymensionxyz/dymint/types" - "github.com/rollkit/celestia-openrpc/types/blob" - "github.com/rollkit/celestia-openrpc/types/header" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" @@ -30,10 +30,10 @@ import ( ) const ( - submitPFBFuncName = "Submit" - getProofFuncName = "GetProof" - includedFuncName = "Included" - getHeadersFuncName = "GetHeaders" + submitPFBFuncName = "Submit" + getProofFuncName = "GetProof" + includedFuncName = "Included" + getByHeightFuncName = "GetByHeight" ) // exampleNMT creates a new NamespacedMerkleTree with the given namespace ID size and leaf namespace IDs. Each byte in the leavesNIDs parameter corresponds to one leaf's namespace ID. If nidSize is greater than 1, the function repeats each NID in leavesNIDs nidSize times before prepending it to the leaf data. @@ -140,7 +140,7 @@ func TestSubmitBatch(t *testing.T) { if tc.name == "TestSubmitPFBResponseCodeSuccess" { mockRPCClient.On(getProofFuncName, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(tc.getProofReturn...).Run(tc.getProofDRun) mockRPCClient.On(includedFuncName, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(tc.includedReturn...).Run(tc.includedRun) - mockRPCClient.On(getHeadersFuncName, mock.Anything, mock.Anything).Return(header, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) }) + mockRPCClient.On(getByHeightFuncName, mock.Anything, mock.Anything).Return(header, nil).Once().Run(func(args mock.Arguments) { time.Sleep(10 * time.Millisecond) }) } done := make(chan bool) diff --git a/da/celestia/types/rpc.go b/da/celestia/types/rpc.go index 807f997e3..6f47dd2db 100644 --- a/da/celestia/types/rpc.go +++ b/da/celestia/types/rpc.go @@ -3,25 +3,20 @@ package types import ( "context" - 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" - "github.com/rollkit/celestia-openrpc/types/state" + openrpc "github.com/celestiaorg/celestia-openrpc" + "github.com/celestiaorg/celestia-openrpc/types/blob" + "github.com/celestiaorg/celestia-openrpc/types/header" + "github.com/celestiaorg/celestia-openrpc/types/share" ) type CelestiaRPCClient interface { - SubmitPayForBlob( - ctx context.Context, - fee state.Int, - gasLim uint64, - blobs []*blob.Blob, - ) (*state.TxResponse, error) + /* ---------------------------------- blob ---------------------------------- */ + Get(ctx context.Context, height uint64, namespace share.Namespace, commitment blob.Commitment) (*blob.Blob, error) GetAll(context.Context, uint64, []share.Namespace) ([]*blob.Blob, error) - Submit(ctx context.Context, blobs []*blob.Blob, options *openrpc.SubmitOptions) (uint64, error) GetProof(ctx context.Context, height uint64, namespace share.Namespace, commitment blob.Commitment) (*blob.Proof, error) - Get(ctx context.Context, height uint64, namespace share.Namespace, commitment blob.Commitment) (*blob.Blob, error) - GetHeaders(ctx context.Context, height uint64) (*header.ExtendedHeader, error) Included(ctx context.Context, height uint64, namespace share.Namespace, proof *blob.Proof, commitment blob.Commitment) (bool, error) + Submit(ctx context.Context, blobs []*blob.Blob, gasPrice openrpc.GasPrice) (uint64, error) + + /* --------------------------------- header --------------------------------- */ + GetByHeight(ctx context.Context, height uint64) (*header.ExtendedHeader, error) } diff --git a/da/da.go b/da/da.go index 565bdcb98..62f2502cc 100644 --- a/da/da.go +++ b/da/da.go @@ -6,10 +6,10 @@ import ( "strconv" "strings" + "github.com/celestiaorg/celestia-openrpc/types/blob" "github.com/cometbft/cometbft/crypto/merkle" "github.com/dymensionxyz/dymint/store" "github.com/dymensionxyz/dymint/types" - "github.com/rollkit/celestia-openrpc/types/blob" "github.com/tendermint/tendermint/libs/pubsub" ) diff --git a/da/da_test.go b/da/da_test.go index dce8ee686..dddbee57c 100644 --- a/da/da_test.go +++ b/da/da_test.go @@ -138,10 +138,9 @@ func doTestRetrieve(t *testing.T, dalc da.DataAvailabilityLayerClient) { } if _, ok := dalc.(*celestia.DataAvailabilityLayerClient); ok { config := celestia.Config{ - BaseURL: "http://localhost:26658", - Timeout: 30 * time.Second, - GasLimit: 3000000, - Fee: 2000000, + BaseURL: "http://localhost:26658", + Timeout: 30 * time.Second, + GasPrices: celestia.CelestiaDefaultConfig.GasPrices, } err := config.InitNamespaceID() require.NoError(err) diff --git a/go.mod b/go.mod index 538b859cd..6aa73f21f 100644 --- a/go.mod +++ b/go.mod @@ -7,6 +7,7 @@ require ( cosmossdk.io/errors v1.0.1 cosmossdk.io/math v1.3.0 github.com/avast/retry-go/v4 v4.5.0 + github.com/celestiaorg/celestia-openrpc v0.4.0-rc.1 github.com/celestiaorg/go-cnc v0.4.2 github.com/centrifuge/go-substrate-rpc-client/v4 v4.0.12 github.com/cosmos/cosmos-sdk v0.46.16 @@ -29,7 +30,6 @@ require ( github.com/libp2p/go-libp2p-pubsub v0.9.3 github.com/multiformats/go-multiaddr v0.11.0 github.com/prometheus/client_golang v1.16.0 - github.com/rollkit/celestia-openrpc v0.0.0-00010101000000-000000000000 github.com/rs/cors v1.9.0 github.com/spf13/cobra v1.8.0 github.com/spf13/viper v1.15.0 @@ -56,7 +56,7 @@ require ( github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect github.com/celestiaorg/go-fraud v0.2.0 // indirect - github.com/celestiaorg/go-header v0.4.0 // indirect + github.com/celestiaorg/go-header v0.4.1 // indirect github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4 // indirect github.com/celestiaorg/nmt v0.20.0 github.com/celestiaorg/rsmt2d v0.11.0 // indirect @@ -283,7 +283,6 @@ replace ( github.com/gorilla/rpc => github.com/dymensionxyz/rpc v1.3.1 github.com/libp2p/go-libp2p-pubsub => github.com/dymensionxyz/go-libp2p-pubsub v0.0.0-20231220125656-9e904c648367 - github.com/rollkit/celestia-openrpc => github.com/celestiaorg/celestia-openrpc v0.3.0 github.com/tendermint/tendermint => github.com/cometbft/cometbft v0.34.28 ) diff --git a/go.sum b/go.sum index d514938c6..d3611644c 100644 --- a/go.sum +++ b/go.sum @@ -151,14 +151,14 @@ github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= github.com/buger/jsonparser v0.0.0-20181115193947-bf1c66bbce23/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s= -github.com/celestiaorg/celestia-openrpc v0.3.0 h1:/0lzmgg1v/9ONwFs9fNVti3x11kI/Sk87dsYLcms43Q= -github.com/celestiaorg/celestia-openrpc v0.3.0/go.mod h1:2ZhU01YF2hsHIROWzxfMZOYM09Kgyy4roH5JWoNJzp0= +github.com/celestiaorg/celestia-openrpc v0.4.0-rc.1 h1:CLhcfNP4496pg0aptcgHJubNXoY97PMHF0sDWx4HRrg= +github.com/celestiaorg/celestia-openrpc v0.4.0-rc.1/go.mod h1:+2xwD+PBy76D2XOAwDbkuNVUSAvwUFV54cQqMFBA1s0= github.com/celestiaorg/go-cnc v0.4.2 h1:7ixf3tevMB7Lvz2mbyRG0ZOK+8qoPm7wNhdgpi8VreU= github.com/celestiaorg/go-cnc v0.4.2/go.mod h1:zYzvHudSd1iNPuHBMyvZ1YvWou5aT9JXgtch9Tkaf70= github.com/celestiaorg/go-fraud v0.2.0 h1:aaq2JiW0gTnhEdac3l51UCqSyJ4+VjFGTTpN83V4q7I= github.com/celestiaorg/go-fraud v0.2.0/go.mod h1:lNY1i4K6kUeeE60Z2VK8WXd+qXb8KRzfBhvwPkK6aUc= -github.com/celestiaorg/go-header v0.4.0 h1:Ine/xpvFx8o9p6fXW+h2RSPp68rn7VUxTkW1okJxcEY= -github.com/celestiaorg/go-header v0.4.0/go.mod h1:H8xhnDLDLbkpwmWPhCaZyTnIV3dlVxBHPnxNXS2Qu6c= +github.com/celestiaorg/go-header v0.4.1 h1:bjbUcKDnhrJJ9EoE7vtPpgleNLVjc2S+cB4/qe8nQmo= +github.com/celestiaorg/go-header v0.4.1/go.mod h1:H8xhnDLDLbkpwmWPhCaZyTnIV3dlVxBHPnxNXS2Qu6c= github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4 h1:CJdIpo8n5MFP2MwK0gSRcOVlDlFdQJO1p+FqdxYzmvc= github.com/celestiaorg/merkletree v0.0.0-20210714075610-a84dc3ddbbe4/go.mod h1:fzuHnhzj1pUygGz+1ZkB3uQbEUL4htqCGJ4Qs2LwMZA= github.com/celestiaorg/nmt v0.20.0 h1:9i7ultZ8Wv5ytt8ZRaxKQ5KOOMo4A2K2T/aPGjIlSas= diff --git a/mocks/github.com/dymensionxyz/dymint/da/celestia/types/mock_CelestiaRPCClient.go b/mocks/github.com/dymensionxyz/dymint/da/celestia/types/mock_CelestiaRPCClient.go index 642c975e2..435fabe8c 100644 --- a/mocks/github.com/dymensionxyz/dymint/da/celestia/types/mock_CelestiaRPCClient.go +++ b/mocks/github.com/dymensionxyz/dymint/da/celestia/types/mock_CelestiaRPCClient.go @@ -3,20 +3,16 @@ package types import ( - client "github.com/rollkit/celestia-openrpc" - blob "github.com/rollkit/celestia-openrpc/types/blob" + client "github.com/celestiaorg/celestia-openrpc" + blob "github.com/celestiaorg/celestia-openrpc/types/blob" context "context" - header "github.com/rollkit/celestia-openrpc/types/header" - - math "cosmossdk.io/math" + header "github.com/celestiaorg/celestia-openrpc/types/header" mock "github.com/stretchr/testify/mock" - sdk "github.com/rollkit/celestia-openrpc/types/sdk" - - share "github.com/rollkit/celestia-openrpc/types/share" + share "github.com/celestiaorg/celestia-openrpc/types/share" ) // MockCelestiaRPCClient is an autogenerated mock type for the CelestiaRPCClient type @@ -153,12 +149,12 @@ func (_c *MockCelestiaRPCClient_GetAll_Call) RunAndReturn(run func(context.Conte return _c } -// GetHeaders provides a mock function with given fields: ctx, height -func (_m *MockCelestiaRPCClient) GetHeaders(ctx context.Context, height uint64) (*header.ExtendedHeader, error) { +// GetByHeight provides a mock function with given fields: ctx, height +func (_m *MockCelestiaRPCClient) GetByHeight(ctx context.Context, height uint64) (*header.ExtendedHeader, error) { ret := _m.Called(ctx, height) if len(ret) == 0 { - panic("no return value specified for GetHeaders") + panic("no return value specified for GetByHeight") } var r0 *header.ExtendedHeader @@ -183,31 +179,31 @@ func (_m *MockCelestiaRPCClient) GetHeaders(ctx context.Context, height uint64) return r0, r1 } -// MockCelestiaRPCClient_GetHeaders_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetHeaders' -type MockCelestiaRPCClient_GetHeaders_Call struct { +// MockCelestiaRPCClient_GetByHeight_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetByHeight' +type MockCelestiaRPCClient_GetByHeight_Call struct { *mock.Call } -// GetHeaders is a helper method to define mock.On call +// GetByHeight is a helper method to define mock.On call // - ctx context.Context // - height uint64 -func (_e *MockCelestiaRPCClient_Expecter) GetHeaders(ctx interface{}, height interface{}) *MockCelestiaRPCClient_GetHeaders_Call { - return &MockCelestiaRPCClient_GetHeaders_Call{Call: _e.mock.On("GetHeaders", ctx, height)} +func (_e *MockCelestiaRPCClient_Expecter) GetByHeight(ctx interface{}, height interface{}) *MockCelestiaRPCClient_GetByHeight_Call { + return &MockCelestiaRPCClient_GetByHeight_Call{Call: _e.mock.On("GetByHeight", ctx, height)} } -func (_c *MockCelestiaRPCClient_GetHeaders_Call) Run(run func(ctx context.Context, height uint64)) *MockCelestiaRPCClient_GetHeaders_Call { +func (_c *MockCelestiaRPCClient_GetByHeight_Call) Run(run func(ctx context.Context, height uint64)) *MockCelestiaRPCClient_GetByHeight_Call { _c.Call.Run(func(args mock.Arguments) { run(args[0].(context.Context), args[1].(uint64)) }) return _c } -func (_c *MockCelestiaRPCClient_GetHeaders_Call) Return(_a0 *header.ExtendedHeader, _a1 error) *MockCelestiaRPCClient_GetHeaders_Call { +func (_c *MockCelestiaRPCClient_GetByHeight_Call) Return(_a0 *header.ExtendedHeader, _a1 error) *MockCelestiaRPCClient_GetByHeight_Call { _c.Call.Return(_a0, _a1) return _c } -func (_c *MockCelestiaRPCClient_GetHeaders_Call) RunAndReturn(run func(context.Context, uint64) (*header.ExtendedHeader, error)) *MockCelestiaRPCClient_GetHeaders_Call { +func (_c *MockCelestiaRPCClient_GetByHeight_Call) RunAndReturn(run func(context.Context, uint64) (*header.ExtendedHeader, error)) *MockCelestiaRPCClient_GetByHeight_Call { _c.Call.Return(run) return _c } @@ -333,9 +329,9 @@ func (_c *MockCelestiaRPCClient_Included_Call) RunAndReturn(run func(context.Con return _c } -// Submit provides a mock function with given fields: ctx, blobs, options -func (_m *MockCelestiaRPCClient) Submit(ctx context.Context, blobs []*blob.Blob, options *client.SubmitOptions) (uint64, error) { - ret := _m.Called(ctx, blobs, options) +// Submit provides a mock function with given fields: ctx, blobs, gasPrice +func (_m *MockCelestiaRPCClient) Submit(ctx context.Context, blobs []*blob.Blob, gasPrice client.GasPrice) (uint64, error) { + ret := _m.Called(ctx, blobs, gasPrice) if len(ret) == 0 { panic("no return value specified for Submit") @@ -343,17 +339,17 @@ func (_m *MockCelestiaRPCClient) Submit(ctx context.Context, blobs []*blob.Blob, var r0 uint64 var r1 error - if rf, ok := ret.Get(0).(func(context.Context, []*blob.Blob, *client.SubmitOptions) (uint64, error)); ok { - return rf(ctx, blobs, options) + if rf, ok := ret.Get(0).(func(context.Context, []*blob.Blob, client.GasPrice) (uint64, error)); ok { + return rf(ctx, blobs, gasPrice) } - if rf, ok := ret.Get(0).(func(context.Context, []*blob.Blob, *client.SubmitOptions) uint64); ok { - r0 = rf(ctx, blobs, options) + if rf, ok := ret.Get(0).(func(context.Context, []*blob.Blob, client.GasPrice) uint64); ok { + r0 = rf(ctx, blobs, gasPrice) } else { r0 = ret.Get(0).(uint64) } - if rf, ok := ret.Get(1).(func(context.Context, []*blob.Blob, *client.SubmitOptions) error); ok { - r1 = rf(ctx, blobs, options) + if rf, ok := ret.Get(1).(func(context.Context, []*blob.Blob, client.GasPrice) error); ok { + r1 = rf(ctx, blobs, gasPrice) } else { r1 = ret.Error(1) } @@ -369,14 +365,14 @@ type MockCelestiaRPCClient_Submit_Call struct { // Submit is a helper method to define mock.On call // - ctx context.Context // - blobs []*blob.Blob -// - options *client.SubmitOptions -func (_e *MockCelestiaRPCClient_Expecter) Submit(ctx interface{}, blobs interface{}, options interface{}) *MockCelestiaRPCClient_Submit_Call { - return &MockCelestiaRPCClient_Submit_Call{Call: _e.mock.On("Submit", ctx, blobs, options)} +// - gasPrice client.GasPrice +func (_e *MockCelestiaRPCClient_Expecter) Submit(ctx interface{}, blobs interface{}, gasPrice interface{}) *MockCelestiaRPCClient_Submit_Call { + return &MockCelestiaRPCClient_Submit_Call{Call: _e.mock.On("Submit", ctx, blobs, gasPrice)} } -func (_c *MockCelestiaRPCClient_Submit_Call) Run(run func(ctx context.Context, blobs []*blob.Blob, options *client.SubmitOptions)) *MockCelestiaRPCClient_Submit_Call { +func (_c *MockCelestiaRPCClient_Submit_Call) Run(run func(ctx context.Context, blobs []*blob.Blob, gasPrice client.GasPrice)) *MockCelestiaRPCClient_Submit_Call { _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].([]*blob.Blob), args[2].(*client.SubmitOptions)) + run(args[0].(context.Context), args[1].([]*blob.Blob), args[2].(client.GasPrice)) }) return _c } @@ -386,68 +382,7 @@ func (_c *MockCelestiaRPCClient_Submit_Call) Return(_a0 uint64, _a1 error) *Mock return _c } -func (_c *MockCelestiaRPCClient_Submit_Call) RunAndReturn(run func(context.Context, []*blob.Blob, *client.SubmitOptions) (uint64, error)) *MockCelestiaRPCClient_Submit_Call { - _c.Call.Return(run) - return _c -} - -// SubmitPayForBlob provides a mock function with given fields: ctx, fee, gasLim, blobs -func (_m *MockCelestiaRPCClient) SubmitPayForBlob(ctx context.Context, fee math.Int, gasLim uint64, blobs []*blob.Blob) (*sdk.TxResponse, error) { - ret := _m.Called(ctx, fee, gasLim, blobs) - - if len(ret) == 0 { - panic("no return value specified for SubmitPayForBlob") - } - - var r0 *sdk.TxResponse - var r1 error - if rf, ok := ret.Get(0).(func(context.Context, math.Int, uint64, []*blob.Blob) (*sdk.TxResponse, error)); ok { - return rf(ctx, fee, gasLim, blobs) - } - if rf, ok := ret.Get(0).(func(context.Context, math.Int, uint64, []*blob.Blob) *sdk.TxResponse); ok { - r0 = rf(ctx, fee, gasLim, blobs) - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(*sdk.TxResponse) - } - } - - if rf, ok := ret.Get(1).(func(context.Context, math.Int, uint64, []*blob.Blob) error); ok { - r1 = rf(ctx, fee, gasLim, blobs) - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - -// MockCelestiaRPCClient_SubmitPayForBlob_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'SubmitPayForBlob' -type MockCelestiaRPCClient_SubmitPayForBlob_Call struct { - *mock.Call -} - -// SubmitPayForBlob is a helper method to define mock.On call -// - ctx context.Context -// - fee math.Int -// - gasLim uint64 -// - blobs []*blob.Blob -func (_e *MockCelestiaRPCClient_Expecter) SubmitPayForBlob(ctx interface{}, fee interface{}, gasLim interface{}, blobs interface{}) *MockCelestiaRPCClient_SubmitPayForBlob_Call { - return &MockCelestiaRPCClient_SubmitPayForBlob_Call{Call: _e.mock.On("SubmitPayForBlob", ctx, fee, gasLim, blobs)} -} - -func (_c *MockCelestiaRPCClient_SubmitPayForBlob_Call) Run(run func(ctx context.Context, fee math.Int, gasLim uint64, blobs []*blob.Blob)) *MockCelestiaRPCClient_SubmitPayForBlob_Call { - _c.Call.Run(func(args mock.Arguments) { - run(args[0].(context.Context), args[1].(math.Int), args[2].(uint64), args[3].([]*blob.Blob)) - }) - return _c -} - -func (_c *MockCelestiaRPCClient_SubmitPayForBlob_Call) Return(_a0 *sdk.TxResponse, _a1 error) *MockCelestiaRPCClient_SubmitPayForBlob_Call { - _c.Call.Return(_a0, _a1) - return _c -} - -func (_c *MockCelestiaRPCClient_SubmitPayForBlob_Call) RunAndReturn(run func(context.Context, math.Int, uint64, []*blob.Blob) (*sdk.TxResponse, error)) *MockCelestiaRPCClient_SubmitPayForBlob_Call { +func (_c *MockCelestiaRPCClient_Submit_Call) RunAndReturn(run func(context.Context, []*blob.Blob, client.GasPrice) (uint64, error)) *MockCelestiaRPCClient_Submit_Call { _c.Call.Return(run) return _c }