Skip to content

Commit

Permalink
fix: global min gas price version error (celestiaorg#3069)
Browse files Browse the repository at this point in the history
  • Loading branch information
ninabarbakadze authored Jan 31, 2024
1 parent c505b88 commit bce5e5f
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 25 deletions.
5 changes: 1 addition & 4 deletions app/ante/fee_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion app/ante/min_fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
12 changes: 3 additions & 9 deletions pkg/appconsts/versioned_consts.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand All @@ -51,4 +44,5 @@ func SquareSizeUpperBound(v uint64) int {
var (
DefaultSubtreeRootThreshold = SubtreeRootThreshold(LatestVersion)
DefaultSquareSizeUpperBound = SquareSizeUpperBound(LatestVersion)
DefaultGlobalMinGasPrice = GlobalMinGasPrice(LatestVersion)
)
18 changes: 7 additions & 11 deletions pkg/appconsts/versioned_consts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
}
Expand Down

0 comments on commit bce5e5f

Please sign in to comment.