From b1592c314d4dca77c477e62ee1890970c6ee6e0c 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 22:35:51 +0100 Subject: [PATCH] chore: move v2 consts to v2 directory (#3040) ## Overview moving GlobalMinGasPrice constant under v2 Fixes - #3035 --------- Co-authored-by: Rootul P --- app/ante/fee_checker.go | 12 +++++++++--- app/ante/min_fee_test.go | 11 +++++++---- go.work.sum | 6 ++++++ pkg/appconsts/initial_consts.go | 4 ---- pkg/appconsts/v2/app_consts.go | 7 ++++--- pkg/appconsts/versioned_consts.go | 13 +++++++++++++ 6 files changed, 39 insertions(+), 14 deletions(-) diff --git a/app/ante/fee_checker.go b/app/ante/fee_checker.go index 372e44b8ff..f38fdaf123 100644 --- a/app/ante/fee_checker.go +++ b/app/ante/fee_checker.go @@ -25,17 +25,23 @@ 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 { + 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", appconsts.GlobalMinGasPrice)) + 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) diff --git a/app/ante/min_fee_test.go b/app/ante/min_fee_test.go index 303f23ec74..91d06946b7 100644 --- a/app/ante/min_fee_test.go +++ b/app/ante/min_fee_test.go @@ -31,6 +31,9 @@ func TestCheckTxFeeWithGlobalMinGasPrices(t *testing.T) { ctx := sdk.Context{} + globalMinGasPrice, err := appconsts.GlobalMinGasPrice(appconsts.LatestVersion) + require.NoError(t, err) + testCases := []struct { name string fee sdk.Coins @@ -41,28 +44,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) / 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) / 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) / 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) / 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..3760acf696 100644 --- a/pkg/appconsts/v2/app_consts.go +++ b/pkg/appconsts/v2/app_consts.go @@ -1,7 +1,8 @@ package v2 const ( - Version uint64 = 2 - SquareSizeUpperBound int = 128 - SubtreeRootThreshold int = 64 + 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`.