From 346ec13a191e0cdacc7180ca0a411fe32d170519 Mon Sep 17 00:00:00 2001 From: Christian Lohr Date: Thu, 5 Sep 2024 15:06:47 +0200 Subject: [PATCH] feat: adapt gas estimation to reduce 120% safety buffer (#1283) --- util/libcons/consensus.go | 4 ---- x/consensus/keeper/estimate_test.go | 14 +++++++------- x/skyway/abci_test.go | 2 +- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/util/libcons/consensus.go b/util/libcons/consensus.go index d7b0e327..ce345723 100644 --- a/util/libcons/consensus.go +++ b/util/libcons/consensus.go @@ -226,7 +226,6 @@ func (c ConsensusChecker) VerifyGasEstimates(ctx context.Context, p liblog.LogPr } // Retrieve the median value of the gas estimates and - // multiply value by 1.2 to allow for some security margin winner := palomath.Median(estimateValues) logger.WithFields("gas-estimate", winner).Debug("Built median value of gas estimates.") @@ -234,8 +233,5 @@ func (c ConsensusChecker) VerifyGasEstimates(ctx context.Context, p liblog.LogPr return 0, fmt.Errorf("gas estimate is zero") } - winner = (winner * 6) / 5 - - logger.WithFields("gas-estimate", winner).Debug("Adding security margin.") return winner, nil } diff --git a/x/consensus/keeper/estimate_test.go b/x/consensus/keeper/estimate_test.go index 502c56ad..aaf63cf4 100644 --- a/x/consensus/keeper/estimate_test.go +++ b/x/consensus/keeper/estimate_test.go @@ -116,9 +116,9 @@ func Test_CheckAndProcessEstimatedMessages(t *testing.T) { } r.NotNil(slc.Fees) - r.Equal(uint64(31500), slc.Fees.RelayerFee, "relayer fee: got %d", slc.Fees.RelayerFee) - r.Equal(uint64(9450), slc.Fees.CommunityFee, "community fee: got %d", slc.Fees.CommunityFee) - r.Equal(uint64(315), slc.Fees.SecurityFee, "security fee: got %d", slc.Fees.SecurityFee) + r.Equal(uint64(26250), slc.Fees.RelayerFee, "relayer fee: got %d", slc.Fees.RelayerFee) + r.Equal(uint64(7875), slc.Fees.CommunityFee, "community fee: got %d", slc.Fees.CommunityFee) + r.Equal(uint64(263), slc.Fees.SecurityFee, "security fee: got %d", slc.Fees.SecurityFee) return true }, }, @@ -142,9 +142,9 @@ func Test_CheckAndProcessEstimatedMessages(t *testing.T) { } r.NotNil(usc.Fees) - r.Equal(uint64(31500), usc.Fees.RelayerFee, "relayer fee: got %d", usc.Fees.RelayerFee) - r.Equal(uint64(9450), usc.Fees.CommunityFee, "community fee: got %d", usc.Fees.CommunityFee) - r.Equal(uint64(315), usc.Fees.SecurityFee, "security fee: got %d", usc.Fees.SecurityFee) + r.Equal(uint64(26250), usc.Fees.RelayerFee, "relayer fee: got %d", usc.Fees.RelayerFee) + r.Equal(uint64(7875), usc.Fees.CommunityFee, "community fee: got %d", usc.Fees.CommunityFee) + r.Equal(uint64(263), usc.Fees.SecurityFee, "security fee: got %d", usc.Fees.SecurityFee) return true }, }, @@ -205,7 +205,7 @@ func Test_CheckAndProcessEstimatedMessages(t *testing.T) { m, err := q.GetMsgByID(ctx, mid) r.NoError(err) r.Len(m.GetGasEstimates(), 7) - r.Equal(uint64(25200), m.GetGasEstimate()) + r.Equal(uint64(21000), m.GetGasEstimate()) tc.slcCheck(getMsg(mid), r, true) }) } diff --git a/x/skyway/abci_test.go b/x/skyway/abci_test.go index d54d36c8..03502423 100644 --- a/x/skyway/abci_test.go +++ b/x/skyway/abci_test.go @@ -367,7 +367,7 @@ func TestGasEstimation(t *testing.T) { gotBatch, err = input.SkywayKeeper.GetOutgoingTXBatch(ctx, b.TokenContract, b.BatchNonce) require.NoError(t, err) - require.Equal(t, uint64(25200), gotBatch.GasEstimate) + require.Equal(t, uint64(21000), gotBatch.GasEstimate, "want: %d, got: %d", uint64(20000), gotBatch.GasEstimate) // Removing those again to avoid invariant issues due to dummy signatures err = input.SkywayKeeper.CancelOutgoingTXBatch(ctx, gotBatch.TokenContract, gotBatch.BatchNonce)