From 8bc479563c69a45f5c75a604df3e08dd87b44a1e Mon Sep 17 00:00:00 2001 From: Michael Tsitrin <114929630+mtsitrin@users.noreply.github.com> Date: Mon, 31 Jul 2023 14:04:21 +0300 Subject: [PATCH] fix: fix gas adjustment parameter (#432) --- config/toml.go | 2 +- da/celestia/celestia.go | 12 ++++++------ da/celestia/fees.go | 4 +++- da/celestia/fees_test.go | 16 ++++++++++++++++ settlement/dymension/dymension.go | 2 +- 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/config/toml.go b/config/toml.go index 632f6fcc5..a0a2c997f 100644 --- a/config/toml.go +++ b/config/toml.go @@ -85,7 +85,7 @@ da_config = "{{ .DAConfig }}" block_batch_max_size_bytes = {{ .BlockManagerConfig.BlockBatchMaxSizeBytes }} #celestia config example: -# da_config = "{\"base_url\": \"http://127.0.0.1:26659\", \"timeout\": 60000000000, \"gas_prices\":0.1, \"gas_limit\": 20000000, \"namespace_id\":\"000000000000ffff\"}" +# da_config = "{\"base_url\": \"http://127.0.0.1:26659\", \"timeout\": 60000000000, \"gas_prices\":0.1, \"gas_adjustment\": 1.3, \"namespace_id\":\"000000000000ffff\"}" # 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 ff995b488..d7ea02565 100644 --- a/da/celestia/celestia.go +++ b/da/celestia/celestia.go @@ -164,19 +164,19 @@ func (c *DataAvailabilityLayerClient) SubmitBatch(batch *types.Batch) da.ResultS }, } } - c.logger.Debug("Submitting to da blob with size", "size", len(blob)) + estimatedGas := DefaultEstimateGas(uint32(len(blob))) + gasWanted := uint64(float64(estimatedGas) * c.config.GasAdjustment) + fees := c.calculateFees(gasWanted) + c.logger.Debug("Submitting to da blob with size", "size", len(blob), "estimatedGas", estimatedGas, "gasAdjusted", gasWanted, "fees", fees) + for { select { case <-c.ctx.Done(): c.logger.Debug("Context cancelled") return da.ResultSubmitBatch{} default: - estimatedGas := DefaultEstimateGas(uint32(len(blob))) - gasWanted := uint64(float64(estimatedGas) * c.config.GasAdjustment) - fees := c.calculateFees(gasWanted) - //SubmitPFB sets an error if the txResponse has error, so we check check the txResponse for error - txResponse, err := c.client.SubmitPFB(c.ctx, c.config.NamespaceID, blob, int64(fees), gasWanted) + txResponse, err := c.client.SubmitPFB(c.ctx, c.config.NamespaceID, blob, fees, gasWanted) if txResponse == nil { c.logger.Error("Failed to submit DA batch. Emitting health event and trying again", "error", err) res, err := da.SubmitBatchHealthEventHelper(c.pubsubServer, c.ctx, false, err) diff --git a/da/celestia/fees.go b/da/celestia/fees.go index 8240b5f00..0418db0c9 100644 --- a/da/celestia/fees.go +++ b/da/celestia/fees.go @@ -1,6 +1,8 @@ package celestia import ( + "math" + "github.com/dymensionxyz/dymint/da/celestia/types" ) @@ -37,7 +39,7 @@ const ( func (c *DataAvailabilityLayerClient) calculateFees(gas uint64) int64 { fees := c.config.Fee if fees == 0 { - fees = int64(c.config.GasPrices * float64(gas)) + fees = int64(math.Ceil(c.config.GasPrices * float64(gas))) } return fees diff --git a/da/celestia/fees_test.go b/da/celestia/fees_test.go index 1359bac81..19356e00d 100644 --- a/da/celestia/fees_test.go +++ b/da/celestia/fees_test.go @@ -49,6 +49,22 @@ func Test(t *testing.T) { 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) { diff --git a/settlement/dymension/dymension.go b/settlement/dymension/dymension.go index ffe10f135..60e214f89 100644 --- a/settlement/dymension/dymension.go +++ b/settlement/dymension/dymension.go @@ -337,7 +337,7 @@ func (d *HubClient) submitBatch(msgUpdateState *rollapptypes.MsgUpdateState) err err := retry.Do(func() error { txResp, err := d.client.BroadcastTx(d.config.DymAccountName, msgUpdateState) if err != nil || txResp.Code != 0 { - d.logger.Error("Error sending batch to settlement layer", "resp", txResp.RawLog, "error", err) + d.logger.Error("Error sending batch to settlement layer", "error", err) return err } return nil