Skip to content

Commit

Permalink
refactor(x/minfee)!: rename to network min gas price (#3575)
Browse files Browse the repository at this point in the history
Closes #3568

## Testing

Started a node and then:

```shell
$ celestia-appd query params subspace minfee NetworkMinGasPrice
key: NetworkMinGasPrice
subspace: minfee
value: '"0.000001000000000000"'
```
  • Loading branch information
rootulp authored Jun 18, 2024
1 parent 6171e5c commit 4c732d3
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 85 deletions.
20 changes: 10 additions & 10 deletions app/ante/fee_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func ValidateTxFeeWrapper(paramKeeper params.Keeper) ante.TxFeeChecker {

// ValidateTxFee implements default fee validation logic for transactions.
// It ensures that the provided transaction fee meets a minimum threshold for the node
// as well as a global minimum threshold and computes the tx priority based on the gas price.
// as well as a network minimum threshold and computes the tx priority based on the gas price.
func ValidateTxFee(ctx sdk.Context, tx sdk.Tx, paramKeeper params.Keeper) (sdk.Coins, int64, error) {
feeTx, ok := tx.(sdk.FeeTx)
if !ok {
Expand All @@ -50,24 +50,24 @@ func ValidateTxFee(ctx sdk.Context, tx sdk.Tx, paramKeeper params.Keeper) (sdk.C
}
}

// Ensure that the provided fee meets a global minimum threshold.
// Global minimum fee only applies to app versions greater than one
// Ensure that the provided fee meets a network minimum threshold.
// Network minimum fee only applies to app versions greater than one.
if ctx.BlockHeader().Version.App > v1.Version {
subspace, exists := paramKeeper.GetSubspace(minfee.ModuleName)
if !exists {
return nil, 0, errors.Wrap(sdkerror.ErrInvalidRequest, "minfee is not a registered subspace")
}

if !subspace.Has(ctx, minfee.KeyGlobalMinGasPrice) {
return nil, 0, errors.Wrap(sdkerror.ErrKeyNotFound, "GlobalMinGasPrice")
if !subspace.Has(ctx, minfee.KeyNetworkMinGasPrice) {
return nil, 0, errors.Wrap(sdkerror.ErrKeyNotFound, "NetworkMinGasPrice")
}

var globalMinGasPrice sdk.Dec
// Gets the global minimum gas price from the param store
// panics if not configured properly
subspace.Get(ctx, minfee.KeyGlobalMinGasPrice, &globalMinGasPrice)
var networkMinGasPrice sdk.Dec
// Gets the network minimum gas price from the param store.
// Panics if not configured properly.
subspace.Get(ctx, minfee.KeyNetworkMinGasPrice, &networkMinGasPrice)

err := verifyMinFee(fee, gas, globalMinGasPrice, "insufficient gas price for the network")
err := verifyMinFee(fee, gas, networkMinGasPrice, "insufficient gas price for the network")
if err != nil {
return nil, 0, err
}
Expand Down
16 changes: 8 additions & 8 deletions app/ante/min_fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
tmdb "github.com/tendermint/tm-db"
)

func TestCheckTxFeeWithGlobalMinGasPrices(t *testing.T) {
func TestValidateTxFee(t *testing.T) {
encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...)

builder := encCfg.TxConfig.NewTxBuilder()
Expand Down Expand Up @@ -58,31 +58,31 @@ 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) / v2.NetworkMinGasPrice),
appVersion: uint64(2),
isCheckTx: false,
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) / v2.NetworkMinGasPrice),
appVersion: uint64(2),
isCheckTx: false,
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) / v2.NetworkMinGasPrice),
appVersion: uint64(2),
isCheckTx: false,
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) / v2.NetworkMinGasPrice),
appVersion: uint64(1),
isCheckTx: false,
expErr: false,
Expand Down Expand Up @@ -143,12 +143,12 @@ func TestCheckTxFeeWithGlobalMinGasPrices(t *testing.T) {

ctx = ctx.WithMinGasPrices(sdk.DecCoins{validatorMinGasPriceCoin})

globalminGasPriceDec, err := sdk.NewDecFromStr(fmt.Sprintf("%f", v2.GlobalMinGasPrice))
networkMinGasPriceDec, err := sdk.NewDecFromStr(fmt.Sprintf("%f", v2.NetworkMinGasPrice))
require.NoError(t, err)

subspace, _ := paramsKeeper.GetSubspace(minfee.ModuleName)
subspace = minfee.RegisterMinFeeParamTable(subspace)
subspace.Set(ctx, minfee.KeyGlobalMinGasPrice, globalminGasPriceDec)
subspace.Set(ctx, minfee.KeyNetworkMinGasPrice, networkMinGasPriceDec)

_, _, err = ante.ValidateTxFee(ctx, tx, paramsKeeper)
if tc.expErr {
Expand All @@ -173,7 +173,7 @@ func setUp(t *testing.T) (paramkeeper.Keeper, storetypes.CommitMultiStore) {

registry := codectypes.NewInterfaceRegistry()

// Create a params keeper and set the global min gas price
// Create a params keeper and set the network min gas price.
paramsKeeper := paramkeeper.NewKeeper(codec.NewProtoCodec(registry), codec.NewLegacyAmino(), storeKey, tStoreKey)
paramsKeeper.Subspace(minfee.ModuleName)
return paramsKeeper, stateStore
Expand Down
6 changes: 3 additions & 3 deletions app/test/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
// TestAppUpgrades verifies that the all module's params are overridden during an
// upgrade from v1 -> v2 and the app version changes correctly.
func TestAppUpgrades(t *testing.T) {
GlobalMinGasPriceDec, err := sdk.NewDecFromStr(fmt.Sprintf("%f", v2.GlobalMinGasPrice))
NetworkMinGasPriceDec, err := sdk.NewDecFromStr(fmt.Sprintf("%f", v2.NetworkMinGasPrice))
require.NoError(t, err)

tests := []struct {
Expand All @@ -42,8 +42,8 @@ func TestAppUpgrades(t *testing.T) {
{
module: "MinFee",
subspace: minfee.ModuleName,
key: string(minfee.KeyGlobalMinGasPrice),
expectedValue: GlobalMinGasPriceDec.String(),
key: string(minfee.KeyNetworkMinGasPrice),
expectedValue: NetworkMinGasPriceDec.String(),
},
{
module: "ICA",
Expand Down
2 changes: 1 addition & 1 deletion local_devnet/celestia-app/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@
}
},
"minfee": {
"global_min_gas_price": "0.000001000000000000"
"network_min_gas_price": "0.000001000000000000"
},
"mint": {
"bond_denom": "utia"
Expand Down
6 changes: 3 additions & 3 deletions pkg/appconsts/v2/app_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const (
Version uint64 = 2
SquareSizeUpperBound int = 128
SubtreeRootThreshold int = 64
// GlobalMinGasPrice is used by x/minfee to prevent transactions from being
// included in a block if they specify a gas price lower than this
GlobalMinGasPrice float64 = 0.000001 // utia
// NetworkMinGasPrice is used by x/minfee to prevent transactions from being
// included in a block if they specify a gas price lower than this.
NetworkMinGasPrice float64 = 0.000001 // utia
)
24 changes: 12 additions & 12 deletions pkg/user/tx_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (client *TxClient) SubmitPayForBlobWithAccount(ctx context.Context, account
// BroadcastPayForBlob signs and broadcasts a transaction to pay for blobs.
// It does not confirm that the transaction has been committed on chain.
// If no gas or gas price is set, it will estimate the gas and use
// the max effective gas price: max(localMinGasPrice, globalMinGasPrice).
// the max effective gas price: max(localMinGasPrice, networkMinGasPrice).
func (client *TxClient) BroadcastPayForBlob(ctx context.Context, blobs []*blob.Blob, opts ...TxOption) (*sdktypes.TxResponse, error) {
return client.BroadcastPayForBlobWithAccount(ctx, client.defaultAccount, blobs, opts...)
}
Expand Down Expand Up @@ -559,7 +559,7 @@ func (client *TxClient) SetGasMultiplier(multiplier float64) {
}

// QueryMinimumGasPrice queries both the nodes local and network wide
// minimum gas prices, returning the maximum of the two
// minimum gas prices, returning the maximum of the two.
func QueryMinimumGasPrice(ctx context.Context, grpcConn *grpc.ClientConn) (float64, error) {
cfgRsp, err := nodeservice.NewServiceClient(grpcConn).Config(ctx, &nodeservice.ConfigRequest{})
if err != nil {
Expand All @@ -572,7 +572,7 @@ func QueryMinimumGasPrice(ctx context.Context, grpcConn *grpc.ClientConn) (float
}
localMinPrice := localMinCoins.AmountOf(app.BondDenom).MustFloat64()

globalMinPrice, err := QueryGlobalMinGasPrice(ctx, grpcConn)
networkMinPrice, err := QueryNetworkMinGasPrice(ctx, grpcConn)
if err != nil {
// check if the network version supports a global min gas
// price using a regex check. If not (i.e. v1) use the
Expand All @@ -584,27 +584,27 @@ func QueryMinimumGasPrice(ctx context.Context, grpcConn *grpc.ClientConn) (float
}

// return the highest value of the two
if globalMinPrice > localMinPrice {
return globalMinPrice, nil
if networkMinPrice > localMinPrice {
return networkMinPrice, nil
}
return localMinPrice, nil
}

func QueryGlobalMinGasPrice(ctx context.Context, grpcConn *grpc.ClientConn) (float64, error) {
func QueryNetworkMinGasPrice(ctx context.Context, grpcConn *grpc.ClientConn) (float64, error) {
paramsClient := paramtypes.NewQueryClient(grpcConn)
// NOTE: that we don't prove that this is the correct value
paramResponse, err := paramsClient.Params(ctx, &paramtypes.QueryParamsRequest{Subspace: minfee.ModuleName, Key: string(minfee.KeyGlobalMinGasPrice)})
paramResponse, err := paramsClient.Params(ctx, &paramtypes.QueryParamsRequest{Subspace: minfee.ModuleName, Key: string(minfee.KeyNetworkMinGasPrice)})
if err != nil {
return 0, fmt.Errorf("querying params module: %w", err)
}

var globalMinPrice float64
// Value is empty if global min gas price is not supported i.e. v1 state machine
var networkMinPrice float64
// Value is empty if network min gas price is not supported i.e. v1 state machine.
if paramResponse.Param.Value != "" {
globalMinPrice, err = strconv.ParseFloat(strings.Trim(paramResponse.Param.Value, `"`), 64)
networkMinPrice, err = strconv.ParseFloat(strings.Trim(paramResponse.Param.Value, `"`), 64)
if err != nil {
return 0, fmt.Errorf("parsing global min gas price: %w", err)
return 0, fmt.Errorf("parsing network min gas price: %w", err)
}
}
return globalMinPrice, nil
return networkMinPrice, nil
}
2 changes: 1 addition & 1 deletion proto/celestia/minfee/v1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ option go_package = "github.com/celestiaorg/celestia-app/x/minfee";

// GenesisState defines the minfee module's genesis state.
message GenesisState {
string global_min_gas_price = 1 [
string network_min_gas_price = 1 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
Expand Down
8 changes: 4 additions & 4 deletions specs/src/specs/params.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ are blocked by the `x/paramfilter` module.

### Global parameters

| Parameter | Default | Summary | Changeable via Governance |
|---------------|---------|------------------------------------------------------------------------------------------------------------------------|---------------------------|
| Parameter | Default | Summary | Changeable via Governance |
|-------------------|---------|------------------------------------------------------------------------------------------------------------------------|---------------------------|
| MaxBlockSizeBytes | 100MiB | Hardcoded value in CometBFT for the protobuf encoded block. | False |
| MaxSquareSize | 128 | Hardcoded maximum square size determined per shares per row or column for the original data square (not yet extended). | False |
| MaxSquareSize | 128 | Hardcoded maximum square size determined per shares per row or column for the original data square (not yet extended). | False |

### Module parameters

Expand Down Expand Up @@ -49,7 +49,7 @@ are blocked by the `x/paramfilter` module.
| ibc.ConnectionGenesis.MaxExpectedTimePerBlock | 7500000000000 (75 seconds) | Maximum expected time per block in nanoseconds under normal operation. | True |
| ibc.Transfer.ReceiveEnabled | true | Enable receiving tokens via IBC. | True |
| ibc.Transfer.SendEnabled | true | Enable sending tokens via IBC. | True |
| minfee.GlobalMinGasPrice | 0.000001 utia | All transactions must have a gas price greater than or equal to this value. | True |
| minfee.NetworkMinGasPrice | 0.000001 utia | All transactions must have a gas price greater than or equal to this value. | True |
| mint.BondDenom | utia | Denomination that is inflated and sent to the distribution module account. | False |
| mint.DisinflationRate | 0.10 (10%) | The rate at which the inflation rate decreases each year. | False |
| mint.InitialInflationRate | 0.08 (8%) | The inflation rate the network starts at. | False |
Expand Down
6 changes: 3 additions & 3 deletions specs/src/specs/resource_pricing.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ By default, Celestia's consensus nodes prioritize transactions in their mempools
based on gas price. In version 1, there was no enforced minimum gas price, which
allowed each consensus node to independently set its own minimum gas price in
`app.toml`. This even permitted a gas price of 0, thereby creating the
possibility of secondary markets. In version 2, Celestia introduces a global
possibility of secondary markets. In version 2, Celestia introduces a network
minimum gas price, a consensus constant, unaffected by individual node
configurations. Although nodes retain the freedom to increase gas prices
locally, all transactions in a block must be greater than or equal to the global
locally, all transactions in a block must be greater than or equal to the network
minimum threshold. If a block is proposed that contains a tx with a gas price
below the global min gas price, the block will be rejected as invalid.
below the network min gas price, the block will be rejected as invalid.

## Estimating PFB cost

Expand Down
2 changes: 1 addition & 1 deletion test/tokenfilter/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ func SetupWithGenesisValSet(t testing.TB, valSet *tmtypes.ValidatorSet, genAccs
subspace := app.GetSubspace(minfee.ModuleName)
subspace = minfee.RegisterMinFeeParamTable(subspace)
ctx := sdk.NewContext(app.CommitMultiStore(), tmproto.Header{}, false, log.NewNopLogger())
subspace.Set(ctx, minfee.KeyGlobalMinGasPrice, sdk.NewDec(0))
subspace.Set(ctx, minfee.KeyNetworkMinGasPrice, sdk.NewDec(0))

return app
}
2 changes: 1 addition & 1 deletion x/minfee/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Abstract

The `x/minfee` module is responsible for managing the gov-modifiable parameter `GlobalMinGasPrice` introduced in app version 2. `GlobalMinGasPrice` ensures that all transactions adhere to this global minimum threshold, which is set in the genesis file and can be updated via governance proposals.
The `x/minfee` module is responsible for managing the gov-modifiable parameter `NetworkMinGasPrice` introduced in app version 2. `NetworkMinGasPrice` ensures that all transactions adhere to this network minimum threshold, which is set in the genesis file and can be updated via governance proposals.

## Resources

Expand Down
12 changes: 6 additions & 6 deletions x/minfee/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import (
// DefaultGenesis returns the default genesis state.
func DefaultGenesis() *GenesisState {
return &GenesisState{
GlobalMinGasPrice: DefaultGlobalMinGasPrice,
NetworkMinGasPrice: DefaultNetworkMinGasPrice,
}
}

// ValidateGenesis performs basic validation of genesis data returning an error for any failed validation criteria.
func ValidateGenesis(genesis *GenesisState) error {
if genesis.GlobalMinGasPrice.IsNegative() || genesis.GlobalMinGasPrice.IsZero() {
return fmt.Errorf("global min gas price cannot be negative: %g", genesis.GlobalMinGasPrice)
if genesis.NetworkMinGasPrice.IsNegative() || genesis.NetworkMinGasPrice.IsZero() {
return fmt.Errorf("network min gas price cannot be negative or zero: %g", genesis.NetworkMinGasPrice)
}

return nil
Expand All @@ -31,8 +31,8 @@ func ExportGenesis(ctx sdk.Context, k params.Keeper) *GenesisState {
}
subspace = RegisterMinFeeParamTable(subspace)

var globalMinGasPrice sdk.Dec
subspace.Get(ctx, KeyGlobalMinGasPrice, &globalMinGasPrice)
var networkMinGasPrice sdk.Dec
subspace.Get(ctx, KeyNetworkMinGasPrice, &networkMinGasPrice)

return &GenesisState{GlobalMinGasPrice: globalMinGasPrice}
return &GenesisState{NetworkMinGasPrice: networkMinGasPrice}
}
Loading

0 comments on commit 4c732d3

Please sign in to comment.