Skip to content

Commit

Permalink
fix: fix gas adjustment parameter (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtsitrin authored and omritoptix committed Jul 31, 2023
1 parent 9e359f6 commit 8bc4795
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
12 changes: 6 additions & 6 deletions da/celestia/celestia.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion da/celestia/fees.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package celestia

import (
"math"

"github.com/dymensionxyz/dymint/da/celestia/types"
)

Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions da/celestia/fees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion settlement/dymension/dymension.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8bc4795

Please sign in to comment.