From fdc932b6fd654c04049e45c6d480620492b878bc Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 24 Jan 2024 16:59:07 +0100 Subject: [PATCH 1/5] chore: move v2 consts to v2 directory --- app/ante/fee_checker.go | 3 ++- app/ante/min_fee_test.go | 9 +++++---- go.work.sum | 6 ++++++ pkg/appconsts/initial_consts.go | 4 ---- pkg/appconsts/v2/app_consts.go | 4 ++++ 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/app/ante/fee_checker.go b/app/ante/fee_checker.go index 372e44b8ff..320241f634 100644 --- a/app/ante/fee_checker.go +++ b/app/ante/fee_checker.go @@ -6,6 +6,7 @@ import ( errors "cosmossdk.io/errors" "github.com/celestiaorg/celestia-app/pkg/appconsts" v1 "github.com/celestiaorg/celestia-app/pkg/appconsts/v1" + v2 "github.com/celestiaorg/celestia-app/pkg/appconsts/v2" sdk "github.com/cosmos/cosmos-sdk/types" sdkerror "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -29,7 +30,7 @@ func CheckTxFeeWithGlobalMinGasPrices(ctx sdk.Context, tx sdk.Tx) (sdk.Coins, in // global minimum fee only applies to app versions greater than one if ctx.BlockHeader().Version.App > v1.Version { // convert the global minimum gas price to a big.Int - globalMinGasPrice, err := sdk.NewDecFromStr(fmt.Sprintf("%f", appconsts.GlobalMinGasPrice)) + globalMinGasPrice, err := sdk.NewDecFromStr(fmt.Sprintf("%f", v2.GlobalMinGasPrice)) if err != nil { return nil, 0, errors.Wrap(err, "invalid GlobalMinGasPrice") } diff --git a/app/ante/min_fee_test.go b/app/ante/min_fee_test.go index 303f23ec74..810c5ad96e 100644 --- a/app/ante/min_fee_test.go +++ b/app/ante/min_fee_test.go @@ -14,6 +14,7 @@ import ( "github.com/stretchr/testify/require" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" version "github.com/tendermint/tendermint/proto/tendermint/version" + v2 "github.com/celestiaorg/celestia-app/pkg/appconsts/v2" ) func TestCheckTxFeeWithGlobalMinGasPrices(t *testing.T) { @@ -41,28 +42,28 @@ func TestCheckTxFeeWithGlobalMinGasPrices(t *testing.T) { { name: "bad tx; fee below required minimum", fee: sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, feeAmount-1)), - gasLimit: uint64(float64(feeAmount) / appconsts.GlobalMinGasPrice), + gasLimit: uint64(float64(feeAmount) / v2.GlobalMinGasPrice), appVersion: uint64(2), expErr: true, }, { name: "good tx; fee equal to required minimum", fee: sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, feeAmount)), - gasLimit: uint64(float64(feeAmount) / appconsts.GlobalMinGasPrice), + gasLimit: uint64(float64(feeAmount) / v2.GlobalMinGasPrice), appVersion: uint64(2), expErr: false, }, { name: "good tx; fee above required minimum", fee: sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, feeAmount+1)), - gasLimit: uint64(float64(feeAmount) / appconsts.GlobalMinGasPrice), + gasLimit: uint64(float64(feeAmount) / v2.GlobalMinGasPrice), appVersion: uint64(2), expErr: false, }, { name: "good tx; with no fee (v1)", fee: sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, feeAmount)), - gasLimit: uint64(float64(feeAmount) / appconsts.GlobalMinGasPrice), + gasLimit: uint64(float64(feeAmount) / v2.GlobalMinGasPrice), appVersion: uint64(1), expErr: false, }, diff --git a/go.work.sum b/go.work.sum index d9a0fc0928..3715ae962a 100644 --- a/go.work.sum +++ b/go.work.sum @@ -634,10 +634,12 @@ github.com/daixiang0/gci v0.10.1/go.mod h1:xtHP9N7AHdNvtRNfcx9gwTDfw7FRJx4bZUsiE github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4= github.com/denis-tingaikin/go-header v0.4.3/go.mod h1:0wOCWuN71D5qIgE2nz9KrKmuYBAC2Mra5RassOIQ2/c= github.com/dgraph-io/badger v1.6.0/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4= +github.com/dlclark/regexp2 v1.7.0 h1:7lJfhqlPssTb1WQx4yvTHN0uElPEv52sbaECrAQxjAo= github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/docker/cli v23.0.1+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= github.com/docker/docker-credential-helpers v0.7.0/go.mod h1:rETQfLdHNT3foU5kuNkFR1R1V12OJRRO5lzt2D1b5X0= github.com/dop251/goja v0.0.0-20211022113120-dc8c55024d06/go.mod h1:R9ET47fwRVRPZnOGvHxxhuZcbrMCuiqOz3Rlrh4KSnk= +github.com/dop251/goja v0.0.0-20230806174421-c933cf95e127 h1:qwcF+vdFrvPSEUDSX5RVoRccG8a5DhOdWdQ4zN62zzo= github.com/dop251/goja v0.0.0-20230806174421-c933cf95e127/go.mod h1:QMWlm50DNe14hD7t24KEqZuUdC9sOTy8W6XbCU1mlw4= github.com/dop251/goja_nodejs v0.0.0-20211022123610-8dd9abb0616d/go.mod h1:DngW8aVqWbuLRMHItjPUyqdj+HWPvnQe8V8y1nDpIbM= github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM= @@ -650,6 +652,7 @@ github.com/etcd-io/bbolt v1.3.3/go.mod h1:ZF2nL25h33cCyBtcyWeZ2/I3HQOfTP+0PIEvHj github.com/ettle/strcase v0.1.1/go.mod h1:hzDLsPC7/lwKyBOywSHEP89nt2pDgdy+No1NBA9o9VY= github.com/evanphx/json-patch v4.12.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8= +github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs= github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= @@ -672,6 +675,7 @@ github.com/go-kit/log v0.2.0/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBj github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-logr/logr v1.2.3/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8= +github.com/go-sourcemap/sourcemap v2.1.3+incompatible h1:W1iEw64niKVGogNgBN3ePyLFfuisuzeidWPMPWmECqU= github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP3XYfe4= github.com/go-toolsmith/astcast v1.0.0/go.mod h1:mt2OdQTeAQcY4DQgPSArJjHCcOwlX+Wl/kwN+LbLGQ4= github.com/go-toolsmith/astcast v1.1.0/go.mod h1:qdcuFWeGGS2xX5bLM/c3U9lewg7+Zu4mr+xPwZIB4ZU= @@ -761,6 +765,7 @@ github.com/juju/testing v0.0.0-20180920084828-472a3e8b2073/go.mod h1:63prj8cnj0t github.com/julz/importas v0.1.0/go.mod h1:oSFU2R4XK/P7kNBrnL/FEQlDGN1/6WoxXEjSSXO0DV0= github.com/junk1tm/musttag v0.5.0/go.mod h1:PcR7BA+oREQYvHwgjIDmw3exJeds5JzRcvEJTfjrA0M= github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k= +github.com/karalabe/usb v0.0.2 h1:M6QQBNxF+CQ8OFvxrT90BA0qBOXymndZnk5q235mFc4= github.com/kataras/golog v0.0.9/go.mod h1:12HJgwBIZFNGL0EJnMRhmvGA0PQGx8VFwrZtM4CqbAk= github.com/kataras/iris/v12 v12.0.1/go.mod h1:udK4vLQKkdDqMGJJVd/msuMtN6hpYJhg/lSzuxjhO+U= github.com/kataras/neffos v0.0.10/go.mod h1:ZYmJC07hQPW67eKuzlfY7SO3bC0mw83A3j6im82hfqw= @@ -829,6 +834,7 @@ github.com/openzipkin/zipkin-go v0.2.5/go.mod h1:KpXfKdgRDnnhsxw4pNIH9Md5lyFqKUa github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8= github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/performancecopilot/speed/v4 v4.0.0/go.mod h1:qxrSyuDGrTOWfV+uKRFhfxw6h/4HXRGUiZiufxo49BM= +github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 h1:oYW+YCJ1pachXTQmzR3rNLYGGz4g/UgFcjb28p/viDM= github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= github.com/pjbgf/sha1cd v0.3.0/go.mod h1:nZ1rrWOcGJ5uZgEEVL1VUM9iRQiZvWdbZjkKyFzPPsI= github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8/go.mod h1:HKlIX3XHQyzLZPlr7++PzdhaXEj94dEiJgZDTsxEqUI= diff --git a/pkg/appconsts/initial_consts.go b/pkg/appconsts/initial_consts.go index c8a47aa546..c74cc2ebaf 100644 --- a/pkg/appconsts/initial_consts.go +++ b/pkg/appconsts/initial_consts.go @@ -22,10 +22,6 @@ const ( // a nodes `CheckTx` and thus not be proposed by that node. DefaultMinGasPrice = 0.002 - // GlobalMinGasPrice is used in the processProposal to ensure - // that all transactions have a gas price greater than or equal to this value. - GlobalMinGasPrice = DefaultMinGasPrice - // DefaultUnbondingTime is the default time a validator must wait // to unbond in a proof of stake system. Any validator within this // time can be subject to slashing under conditions of misbehavior. diff --git a/pkg/appconsts/v2/app_consts.go b/pkg/appconsts/v2/app_consts.go index d5829e84c5..73ee1371e1 100644 --- a/pkg/appconsts/v2/app_consts.go +++ b/pkg/appconsts/v2/app_consts.go @@ -4,4 +4,8 @@ const ( Version uint64 = 2 SquareSizeUpperBound int = 128 SubtreeRootThreshold int = 64 + + // GlobalMinGasPrice is used in the processProposal to ensure + // that all transactions have a gas price greater than or equal to this value. + GlobalMinGasPrice = 0.002 // same as DefaultMinGasPrice ) From 0937ea21dce70f4c3613d0f29952ddf6f67968c4 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 24 Jan 2024 17:43:13 +0100 Subject: [PATCH 2/5] style: lint --- app/ante/min_fee_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/ante/min_fee_test.go b/app/ante/min_fee_test.go index 810c5ad96e..a7b8e05131 100644 --- a/app/ante/min_fee_test.go +++ b/app/ante/min_fee_test.go @@ -8,13 +8,13 @@ import ( "github.com/celestiaorg/celestia-app/app/ante" "github.com/celestiaorg/celestia-app/app/encoding" "github.com/celestiaorg/celestia-app/pkg/appconsts" + v2 "github.com/celestiaorg/celestia-app/pkg/appconsts/v2" "github.com/celestiaorg/celestia-app/test/util/testnode" sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/stretchr/testify/require" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" version "github.com/tendermint/tendermint/proto/tendermint/version" - v2 "github.com/celestiaorg/celestia-app/pkg/appconsts/v2" ) func TestCheckTxFeeWithGlobalMinGasPrices(t *testing.T) { From 28d04e93dcb9b63ea16f57b304e6ebc207cffe50 Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 24 Jan 2024 20:18:51 +0100 Subject: [PATCH 3/5] refactor: add GlobalMinGasPrice in versioned constants and refactor the use --- app/ante/fee_checker.go | 11 ++++++++--- app/ante/min_fee_test.go | 11 ++++++----- pkg/appconsts/v2/app_consts.go | 11 ++++------- pkg/appconsts/versioned_consts.go | 13 +++++++++++++ 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/app/ante/fee_checker.go b/app/ante/fee_checker.go index 320241f634..35b5524c03 100644 --- a/app/ante/fee_checker.go +++ b/app/ante/fee_checker.go @@ -6,7 +6,6 @@ import ( errors "cosmossdk.io/errors" "github.com/celestiaorg/celestia-app/pkg/appconsts" v1 "github.com/celestiaorg/celestia-app/pkg/appconsts/v1" - v2 "github.com/celestiaorg/celestia-app/pkg/appconsts/v2" sdk "github.com/cosmos/cosmos-sdk/types" sdkerror "github.com/cosmos/cosmos-sdk/types/errors" ) @@ -26,11 +25,17 @@ func CheckTxFeeWithGlobalMinGasPrices(ctx sdk.Context, tx sdk.Tx) (sdk.Coins, in fee := feeTx.GetFee().AmountOf(appconsts.BondDenom) gas := feeTx.GetGas() + appVersion := ctx.BlockHeader().Version.App // global minimum fee only applies to app versions greater than one - if ctx.BlockHeader().Version.App > v1.Version { + if appVersion > v1.Version { + gmgp, err := appconsts.GlobalMinGasPrice(appVersion) + if err != nil { + return nil, 0, errors.Wrapf(err, "failed to get GlobalMinGasPrice for app version %d", appVersion) + } + // convert the global minimum gas price to a big.Int - globalMinGasPrice, err := sdk.NewDecFromStr(fmt.Sprintf("%f", v2.GlobalMinGasPrice)) + globalMinGasPrice, err := sdk.NewDecFromStr(fmt.Sprintf("%f", gmgp)) if err != nil { return nil, 0, errors.Wrap(err, "invalid GlobalMinGasPrice") } diff --git a/app/ante/min_fee_test.go b/app/ante/min_fee_test.go index a7b8e05131..412087f2e2 100644 --- a/app/ante/min_fee_test.go +++ b/app/ante/min_fee_test.go @@ -8,7 +8,6 @@ import ( "github.com/celestiaorg/celestia-app/app/ante" "github.com/celestiaorg/celestia-app/app/encoding" "github.com/celestiaorg/celestia-app/pkg/appconsts" - v2 "github.com/celestiaorg/celestia-app/pkg/appconsts/v2" "github.com/celestiaorg/celestia-app/test/util/testnode" sdk "github.com/cosmos/cosmos-sdk/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" @@ -32,6 +31,8 @@ func TestCheckTxFeeWithGlobalMinGasPrices(t *testing.T) { ctx := sdk.Context{} + globalMinGasPrice, _ := appconsts.GlobalMinGasPrice(appconsts.LatestVersion) + testCases := []struct { name string fee sdk.Coins @@ -42,28 +43,28 @@ func TestCheckTxFeeWithGlobalMinGasPrices(t *testing.T) { { name: "bad tx; fee below required minimum", fee: sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, feeAmount-1)), - gasLimit: uint64(float64(feeAmount) / v2.GlobalMinGasPrice), + gasLimit: uint64(float64(feeAmount) / globalMinGasPrice), appVersion: uint64(2), expErr: true, }, { name: "good tx; fee equal to required minimum", fee: sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, feeAmount)), - gasLimit: uint64(float64(feeAmount) / v2.GlobalMinGasPrice), + gasLimit: uint64(float64(feeAmount) / globalMinGasPrice), appVersion: uint64(2), expErr: false, }, { name: "good tx; fee above required minimum", fee: sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, feeAmount+1)), - gasLimit: uint64(float64(feeAmount) / v2.GlobalMinGasPrice), + gasLimit: uint64(float64(feeAmount) / globalMinGasPrice), appVersion: uint64(2), expErr: false, }, { name: "good tx; with no fee (v1)", fee: sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, feeAmount)), - gasLimit: uint64(float64(feeAmount) / v2.GlobalMinGasPrice), + gasLimit: uint64(float64(feeAmount) / globalMinGasPrice), appVersion: uint64(1), expErr: false, }, diff --git a/pkg/appconsts/v2/app_consts.go b/pkg/appconsts/v2/app_consts.go index 73ee1371e1..3760acf696 100644 --- a/pkg/appconsts/v2/app_consts.go +++ b/pkg/appconsts/v2/app_consts.go @@ -1,11 +1,8 @@ package v2 const ( - Version uint64 = 2 - SquareSizeUpperBound int = 128 - SubtreeRootThreshold int = 64 - - // GlobalMinGasPrice is used in the processProposal to ensure - // that all transactions have a gas price greater than or equal to this value. - GlobalMinGasPrice = 0.002 // same as DefaultMinGasPrice + Version uint64 = 2 + SquareSizeUpperBound int = 128 + SubtreeRootThreshold int = 64 + GlobalMinGasPrice float64 = 0.002 // same as DefaultMinGasPrice ) diff --git a/pkg/appconsts/versioned_consts.go b/pkg/appconsts/versioned_consts.go index f64b43e8c0..2067e775c9 100644 --- a/pkg/appconsts/versioned_consts.go +++ b/pkg/appconsts/versioned_consts.go @@ -1,6 +1,8 @@ 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" @@ -22,6 +24,17 @@ func SubtreeRootThreshold(_ uint64) int { return v1.SubtreeRootThreshold } +// 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) + } +} + // SquareSizeUpperBound is the maximum original square width possible // for a version of the state machine. The maximum is decided through // governance. See `DefaultGovMaxSquareSize`. From f46860f16fa36e1a581969b85b358281c9b6654d Mon Sep 17 00:00:00 2001 From: Nina Barbakadze Date: Wed, 24 Jan 2024 20:23:06 +0100 Subject: [PATCH 4/5] refactor: rename gmgp --- app/ante/fee_checker.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/ante/fee_checker.go b/app/ante/fee_checker.go index 35b5524c03..f38fdaf123 100644 --- a/app/ante/fee_checker.go +++ b/app/ante/fee_checker.go @@ -29,19 +29,19 @@ 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 { - gmgp, err := appconsts.GlobalMinGasPrice(appVersion) + globalMinGasPrice, err := appconsts.GlobalMinGasPrice(appVersion) if err != nil { return nil, 0, errors.Wrapf(err, "failed to get GlobalMinGasPrice for app version %d", appVersion) } // convert the global minimum gas price to a big.Int - globalMinGasPrice, err := sdk.NewDecFromStr(fmt.Sprintf("%f", gmgp)) + globalMinGasPriceInt, err := sdk.NewDecFromStr(fmt.Sprintf("%f", globalMinGasPrice)) if err != nil { return nil, 0, errors.Wrap(err, "invalid GlobalMinGasPrice") } gasInt := sdk.NewIntFromUint64(gas) - minFee := globalMinGasPrice.MulInt(gasInt).RoundInt() + minFee := globalMinGasPriceInt.MulInt(gasInt).RoundInt() if !fee.GTE(minFee) { return nil, 0, errors.Wrapf(sdkerror.ErrInsufficientFee, "insufficient fees; got: %s required: %s", fee, minFee) From acf523f34e0e074fe0cd17a0b3dea488f3b89167 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, 24 Jan 2024 20:43:43 +0100 Subject: [PATCH 5/5] test: catch the error Co-authored-by: Rootul P --- app/ante/min_fee_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/ante/min_fee_test.go b/app/ante/min_fee_test.go index 412087f2e2..91d06946b7 100644 --- a/app/ante/min_fee_test.go +++ b/app/ante/min_fee_test.go @@ -31,7 +31,8 @@ func TestCheckTxFeeWithGlobalMinGasPrices(t *testing.T) { ctx := sdk.Context{} - globalMinGasPrice, _ := appconsts.GlobalMinGasPrice(appconsts.LatestVersion) + globalMinGasPrice, err := appconsts.GlobalMinGasPrice(appconsts.LatestVersion) + require.NoError(t, err) testCases := []struct { name string