forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add dynamicfee module #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
giuliostramondo
wants to merge
6
commits into
release/v0.50.x
Choose a base branch
from
giuliostramondo/chore/dynamicfee-sdk
base: release/v0.50.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
cca4024
added dynamicfee module to sdk, make test-all passes
giuliostramondo 50c3e61
fixed lint errors
giuliostramondo fa664db
fix(dynamicfee): add params.ValidateBasic to types MsgUpdateParams
giuliostramondo d5cc064
Added test for MsgUpdateParams of dynamicfee
giuliostramondo dc057b0
go mod tidy
giuliostramondo bd7bb96
Update x/dynamicfee/types/params.go
giuliostramondo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package cosmos.dynamicfee.module.v1; | ||
|
|
||
| import "cosmos/app/v1alpha1/module.proto"; | ||
|
|
||
| option go_package = "github.com/cosmos/cosmos-sdk/x/dynamicfee/types/module"; | ||
|
|
||
| // Module is the config object of the builder module. | ||
| message Module { | ||
| option (cosmos.app.v1alpha1.module) = { | ||
| go_import: "github.com/cosmos/cosmos-sdk/x/dynamicfee" | ||
| }; | ||
|
|
||
| // Authority defines the custom module authority. If not set, defaults to the | ||
| // governance module. | ||
| string authority = 1; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| syntax = "proto3"; | ||
| package cosmos.dynamicfee.v1; | ||
|
|
||
| option go_package = "github.com/cosmos/cosmos-sdk/x/dynamicfee/types"; | ||
|
|
||
| import "gogoproto/gogo.proto"; | ||
| import "cosmos_proto/cosmos.proto"; | ||
| import "cosmos/dynamicfee/v1/params.proto"; | ||
|
|
||
| // GenesisState defines the dynamicfee module's genesis state. | ||
| message GenesisState { | ||
| // Params are the parameters for the dynamicfee module. These parameters | ||
| // can be utilized to implement both the base EIP-1559 dynamic fee pricing | ||
| // and the AIMD EIP-1559 dynamic fee pricing. | ||
| Params params = 1 [(gogoproto.nullable) = false]; | ||
|
|
||
| // State contains the current state of the AIMD dynamic fee pricer. | ||
| State state = 2 [(gogoproto.nullable) = false]; | ||
| } | ||
|
|
||
| // State is utilized to track the current state of the dynamic fee pricer. | ||
| // This includes the current base fee, learning rate, and block gas within the | ||
| // specified AIMD window. | ||
| message State { | ||
| // BaseGasPrice is the current base fee. This is denominated in the fee per | ||
| // gas unit. | ||
| string base_gas_price = 1 [ | ||
| (cosmos_proto.scalar) = "cosmos.Dec", | ||
| (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", | ||
| (gogoproto.nullable) = false | ||
| ]; | ||
|
|
||
| // LearningRate is the current learning rate. | ||
| string learning_rate = 2 [ | ||
| (cosmos_proto.scalar) = "cosmos.Dec", | ||
| (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", | ||
| (gogoproto.nullable) = false | ||
| ]; | ||
|
|
||
| // Window contains a list of the last blocks' gas values. This is used | ||
| // to calculate the next base fee. This stores the number of units of gas | ||
| // consumed per block. | ||
| repeated uint64 window = 3; | ||
|
|
||
| // Index is the index of the current block in the block gas window. | ||
| uint64 index = 4; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| syntax = "proto3"; | ||
| package cosmos.dynamicfee.v1; | ||
|
|
||
| option go_package = "github.com/cosmos/cosmos-sdk/x/dynamicfee/types"; | ||
|
|
||
| import "cosmos_proto/cosmos.proto"; | ||
| import "gogoproto/gogo.proto"; | ||
|
|
||
| // Params contains the required set of parameters for the EIP1559 dynamic fee | ||
| // pricing implementation. | ||
| message Params { | ||
| // Alpha is the amount we additively increase the learning rate | ||
| // when it is above or below the target +/- threshold. | ||
| // | ||
| // Must be > 0. | ||
| string alpha = 1 [ | ||
| (cosmos_proto.scalar) = "cosmos.Dec", | ||
| (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", | ||
| (gogoproto.nullable) = false | ||
| ]; | ||
|
|
||
| // Beta is the amount we multiplicatively decrease the learning rate | ||
| // when it is within the target +/- threshold. | ||
| // | ||
| // Must be [0, 1]. | ||
| string beta = 2 [ | ||
| (cosmos_proto.scalar) = "cosmos.Dec", | ||
| (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", | ||
| (gogoproto.nullable) = false | ||
| ]; | ||
|
|
||
| // Gamma is the threshold for the learning rate. If the learning rate is | ||
| // above or below the target +/- threshold, we additively increase the | ||
| // learning rate by Alpha. Otherwise, we multiplicatively decrease the | ||
| // learning rate by Beta. | ||
| // | ||
| // Must be [0, 0.5]. | ||
| string gamma = 3 [ | ||
| (cosmos_proto.scalar) = "cosmos.Dec", | ||
| (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", | ||
| (gogoproto.nullable) = false | ||
| ]; | ||
|
|
||
| // MinBaseGasPrice determines the initial gas price of the module and the | ||
| // global minimum for the network. | ||
| string min_base_gas_price = 5 [ | ||
| (cosmos_proto.scalar) = "cosmos.Dec", | ||
| (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", | ||
| (gogoproto.nullable) = false | ||
| ]; | ||
|
|
||
| // TargetBlockUtilization is the target block utilization expressed as a | ||
| // decimal value between 0 and 1. It is the target percentage utilization | ||
| // of the block in relation to the consensus_params.block.max_gas parameter. | ||
| string target_block_utilization = 6 [ | ||
| (cosmos_proto.scalar) = "cosmos.Dec", | ||
| (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", | ||
| (gogoproto.nullable) = false | ||
| ]; | ||
|
|
||
| // DefaultMaxBlockGas is the default max block gas. | ||
| // This parameter is used by the dynamicfee module | ||
| // in the case consensus_params.block.max_gas returns 0 or -1. | ||
| uint64 default_max_block_gas = 7; | ||
|
|
||
| // MinLearningRate is the lower bound for the learning rate. | ||
| string min_learning_rate = 8 [ | ||
| (cosmos_proto.scalar) = "cosmos.Dec", | ||
| (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", | ||
| (gogoproto.nullable) = false | ||
| ]; | ||
|
|
||
| // MaxLearningRate is the upper bound for the learning rate. | ||
| string max_learning_rate = 9 [ | ||
| (cosmos_proto.scalar) = "cosmos.Dec", | ||
| (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", | ||
| (gogoproto.nullable) = false | ||
| ]; | ||
|
|
||
| // Window defines the window size for calculating an adaptive learning rate | ||
| // over a moving window of blocks. | ||
| uint64 window = 10; | ||
|
|
||
| // FeeDenom is the denom that will be used for all fee payments. | ||
| string fee_denom = 11; | ||
|
|
||
| // Enabled is a boolean that determines whether the EIP1559 dynamic fee | ||
| // pricing is enabled. | ||
| bool enabled = 12; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| syntax = "proto3"; | ||
| package cosmos.dynamicfee.v1; | ||
|
|
||
| option go_package = "github.com/cosmos/cosmos-sdk/x/dynamicfee/types"; | ||
|
|
||
| import "gogoproto/gogo.proto"; | ||
| import "google/api/annotations.proto"; | ||
| import "cosmos/base/v1beta1/coin.proto"; | ||
| import "amino/amino.proto"; | ||
| import "cosmos/dynamicfee/v1/params.proto"; | ||
| import "cosmos/dynamicfee/v1/genesis.proto"; | ||
|
|
||
| // Query Service for the dynamicfee module. | ||
| service Query { | ||
| // Params returns the current dynamicfee module parameters. | ||
| rpc Params(ParamsRequest) returns (ParamsResponse) { | ||
| option (google.api.http) = { | ||
| get: "/cosmos/dynamicfee/v1/params" | ||
| }; | ||
| }; | ||
|
|
||
| // State returns the current dynamicfee module state. | ||
| rpc State(StateRequest) returns (StateResponse) { | ||
| option (google.api.http) = { | ||
| get: "/cosmos/dynamicfee/v1/state" | ||
| }; | ||
| }; | ||
|
|
||
| // GasPrice returns the current dynamicfee module gas price | ||
| // for specified denom. | ||
| rpc GasPrice(GasPriceRequest) returns (GasPriceResponse) { | ||
| option (google.api.http) = { | ||
| get: "/cosmos/dynamicfee/v1/gas_price/{denom}" | ||
| }; | ||
| }; | ||
|
|
||
| // GasPrices returns the current dynamicfee module list of gas prices | ||
| // in all available denoms. | ||
| rpc GasPrices(GasPricesRequest) returns (GasPricesResponse) { | ||
| option (google.api.http) = { | ||
| get: "/cosmos/dynamicfee/v1/gas_prices" | ||
| }; | ||
| }; | ||
| } | ||
|
|
||
| // ParamsRequest is the request type for the Query/Params RPC method. | ||
| message ParamsRequest {} | ||
|
|
||
| // ParamsResponse is the response type for the Query/Params RPC method. | ||
| message ParamsResponse { | ||
| Params params = 1 [(gogoproto.nullable) = false]; | ||
| } | ||
|
|
||
| // StateRequest is the request type for the Query/State RPC method. | ||
| message StateRequest {} | ||
|
|
||
| // StateResponse is the response type for the Query/State RPC method. | ||
| message StateResponse { | ||
| State state = 1 [(gogoproto.nullable) = false]; | ||
| } | ||
|
|
||
| // GasPriceRequest is the request type for the Query/GasPrice RPC method. | ||
| message GasPriceRequest { | ||
| // denom we are querying gas price in | ||
| string denom = 1; | ||
| } | ||
|
|
||
| // GasPriceResponse is the response type for the Query/GasPrice RPC method. | ||
| // Returns a gas price in specified denom. | ||
| message GasPriceResponse { | ||
| cosmos.base.v1beta1.DecCoin price = 1 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true]; | ||
| } | ||
|
|
||
| // GasPriceRequest is the request type for the Query/GasPrices RPC method. | ||
| message GasPricesRequest {} | ||
|
|
||
| // GasPricesResponse is the response type for the Query/GasPrices RPC method. | ||
| // Returns a gas price in all available denoms. | ||
| message GasPricesResponse { | ||
| repeated cosmos.base.v1beta1.DecCoin prices = 1 [ | ||
| (gogoproto.nullable) = false, | ||
| (amino.dont_omitempty) = true, | ||
| (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins" | ||
| ]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| syntax = "proto3"; | ||
| package cosmos.dynamicfee.v1; | ||
|
|
||
| import "cosmos/dynamicfee/v1/params.proto"; | ||
| import "cosmos_proto/cosmos.proto"; | ||
| import "cosmos/msg/v1/msg.proto"; | ||
| import "gogoproto/gogo.proto"; | ||
| import "amino/amino.proto"; | ||
|
|
||
| option go_package = "github.com/cosmos/cosmos-sdk/x/dynamicfee/types"; | ||
|
|
||
| // Message service defines the types of messages supported by the dynamicfee | ||
| // module. | ||
| service Msg { | ||
| option (cosmos.msg.v1.service) = true; | ||
|
|
||
| // UpdateParams defines a method for updating the dynamicfee module parameters. | ||
| rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); | ||
| } | ||
|
|
||
| // MsgUpdateParams defines the sdk.Msg/UpdateParams request type. It contains | ||
| // the new parameters for the dynamicfee module. | ||
| message MsgUpdateParams { | ||
| option (cosmos.msg.v1.signer) = "authority"; | ||
| option (amino.name) = "cosmos/x/dynamicfee/v1/MsgUpdateParams"; | ||
|
|
||
| // Authority defines the authority that is updating the dynamicfee module | ||
| // parameters. | ||
| string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; | ||
| // Params defines the new parameters for the dynamicfee module. | ||
| Params params = 2 [(gogoproto.nullable) = false]; | ||
| } | ||
|
|
||
| // MsgUpdateParamsResponse defines the response structure for executing a | ||
| // MsgUpdateParams message. | ||
| message MsgUpdateParamsResponse {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if we change the proto path, which sounds legit, we'll break again the API.
Fortunately it should not be widely used, but there's a pending PR on Hermes that will need to be updated (even though it will never be merged, let's be honest...)