From bce5e5f8c1b6aad6cfdc1e2838c123c536c011c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nina=20/=20=E1=83=9C=E1=83=98=E1=83=9C=E1=83=90?= Date: Wed, 31 Jan 2024 18:45:15 +0100 Subject: [PATCH] fix: global min gas price version error (#3069) Fixes - #3067 --- app/ante/fee_checker.go | 5 +---- app/ante/min_fee_test.go | 2 +- go.work.sum | 5 +++++ pkg/appconsts/versioned_consts.go | 12 +++--------- pkg/appconsts/versioned_consts_test.go | 18 +++++++----------- 5 files changed, 17 insertions(+), 25 deletions(-) diff --git a/app/ante/fee_checker.go b/app/ante/fee_checker.go index f38fdaf123..0764c01797 100644 --- a/app/ante/fee_checker.go +++ b/app/ante/fee_checker.go @@ -29,10 +29,7 @@ func CheckTxFeeWithGlobalMinGasPrices(ctx sdk.Context, tx sdk.Tx) (sdk.Coins, in // global minimum fee only applies to app versions greater than one if appVersion > v1.Version { - globalMinGasPrice, err := appconsts.GlobalMinGasPrice(appVersion) - if err != nil { - return nil, 0, errors.Wrapf(err, "failed to get GlobalMinGasPrice for app version %d", appVersion) - } + globalMinGasPrice := appconsts.GlobalMinGasPrice(appVersion) // convert the global minimum gas price to a big.Int globalMinGasPriceInt, err := sdk.NewDecFromStr(fmt.Sprintf("%f", globalMinGasPrice)) diff --git a/app/ante/min_fee_test.go b/app/ante/min_fee_test.go index 91d06946b7..e4fec46d1a 100644 --- a/app/ante/min_fee_test.go +++ b/app/ante/min_fee_test.go @@ -31,7 +31,7 @@ func TestCheckTxFeeWithGlobalMinGasPrices(t *testing.T) { ctx := sdk.Context{} - globalMinGasPrice, err := appconsts.GlobalMinGasPrice(appconsts.LatestVersion) + globalMinGasPrice := appconsts.DefaultGlobalMinGasPrice require.NoError(t, err) testCases := []struct { diff --git a/go.work.sum b/go.work.sum index 4cf0be8d93..424b67f32d 100644 --- a/go.work.sum +++ b/go.work.sum @@ -928,6 +928,7 @@ google.golang.org/genproto v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:J7XzRzVy google.golang.org/genproto/googleapis/api v0.0.0-20230822172742-b8732ec3820d/go.mod h1:KjSP20unUpOx5kyQUFa7k4OJg0qeJ7DEZflGDu2p6Bk= google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:IBQ646DjkDkvUIsVq/cc03FUFQ9wbZu7yE396YcL870= google.golang.org/genproto/googleapis/api v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:0xJLfVdJqpAPl8tDg1ujOCGzx6LFLttXT5NhllGOXY4= +google.golang.org/genproto/googleapis/bytestream v0.0.0-20230530153820-e85fd2cbaebc/go.mod h1:ylj+BE99M198VPbBh6A8d9n3w8fChvyLK3wwBOjXBFA= google.golang.org/genproto/googleapis/bytestream v0.0.0-20231030173426-d783a09b4405/go.mod h1:GRUCuLdzVqZte8+Dl/D4N25yLzcGqqWaYkeVOwulFqw= google.golang.org/genproto/googleapis/rpc v0.0.0-20230822172742-b8732ec3820d/go.mod h1:+Bk1OCOj40wS2hwAMA+aCW9ypzm63QTBBHp6lQ3p+9M= google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:swOH3j0KzcDDgGUWr+SNpyTen5YrXjS3eyPzFYKc6lc= @@ -940,4 +941,8 @@ google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqw google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8= +mvdan.cc/gofumpt v0.4.0/go.mod h1:PljLOHDeZqgS8opHRKLzp2It2VBuSdteAgqUfzMTxlQ= +mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc= +mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4= +mvdan.cc/unparam v0.0.0-20221223090309-7455f1af531d/go.mod h1:IeHQjmn6TOD+e4Z3RFiZMMsLVL+A96Nvptar8Fj71is= sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e h1:4Z09Hglb792X0kfOBBJUPFEyvVfQWrYT/l8h5EKA6JQ= diff --git a/pkg/appconsts/versioned_consts.go b/pkg/appconsts/versioned_consts.go index 2067e775c9..e1316e51fa 100644 --- a/pkg/appconsts/versioned_consts.go +++ b/pkg/appconsts/versioned_consts.go @@ -1,8 +1,6 @@ package appconsts import ( - "fmt" - "github.com/celestiaorg/celestia-app/pkg/appconsts/testground" v1 "github.com/celestiaorg/celestia-app/pkg/appconsts/v1" v2 "github.com/celestiaorg/celestia-app/pkg/appconsts/v2" @@ -26,13 +24,8 @@ func SubtreeRootThreshold(_ uint64) int { // GlobalMinGasPrice is used in the processProposal to ensure // that all transactions have a gas price greater than or equal to this value. -func GlobalMinGasPrice(version uint64) (float64, error) { - switch version { - case v2.Version: - return v2.GlobalMinGasPrice, nil - default: - return 0, fmt.Errorf("global min gas price not defined for version %d", version) - } +func GlobalMinGasPrice(_ uint64) float64 { + return v2.GlobalMinGasPrice } // SquareSizeUpperBound is the maximum original square width possible @@ -51,4 +44,5 @@ func SquareSizeUpperBound(v uint64) int { var ( DefaultSubtreeRootThreshold = SubtreeRootThreshold(LatestVersion) DefaultSquareSizeUpperBound = SquareSizeUpperBound(LatestVersion) + DefaultGlobalMinGasPrice = GlobalMinGasPrice(LatestVersion) ) diff --git a/pkg/appconsts/versioned_consts_test.go b/pkg/appconsts/versioned_consts_test.go index 46dda05c09..dafdd7d8c3 100644 --- a/pkg/appconsts/versioned_consts_test.go +++ b/pkg/appconsts/versioned_consts_test.go @@ -44,30 +44,26 @@ func TestGlobalMinGasPrice(t *testing.T) { testCases := []struct { version uint64 expected float64 - expErr bool }{ { version: v2.Version, expected: v2.GlobalMinGasPrice, - expErr: false, }, { version: v1.Version, - expected: 0, - expErr: true, + expected: v2.GlobalMinGasPrice, + }, + { + version: testground.Version, + expected: v2.GlobalMinGasPrice, }, } for _, tc := range testCases { name := fmt.Sprintf("version %v", tc.version) t.Run(name, func(t *testing.T) { - got, err := appconsts.GlobalMinGasPrice(tc.version) - if tc.expErr { - require.Error(t, err) - } else { - require.NoError(t, err) - require.Equal(t, tc.expected, got) - } + got := appconsts.GlobalMinGasPrice(tc.version) + require.Equal(t, tc.expected, got) }) } }