Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Contains all the PRs that improved the code without changing the behaviours.
### Added

- [#330](https://github.com/archway-network/archway/pull/330) Proper chain upgrade flow.
- [#351](https://github.com/archway-network/archway/pull/351) Add minimum price of gas.

### Changed

Expand Down
102 changes: 101 additions & 1 deletion docs/proto/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
- [archway/rewards/v1beta1/rewards.proto](#archway/rewards/v1beta1/rewards.proto)
- [BlockRewards](#archway.rewards.v1beta1.BlockRewards)
- [ContractMetadata](#archway.rewards.v1beta1.ContractMetadata)
- [FlatFee](#archway.rewards.v1beta1.FlatFee)
- [Params](#archway.rewards.v1beta1.Params)
- [RewardsRecord](#archway.rewards.v1beta1.RewardsRecord)
- [TxRewards](#archway.rewards.v1beta1.TxRewards)

- [archway/rewards/v1beta1/events.proto](#archway/rewards/v1beta1/events.proto)
- [ContractFlatFeeSetEvent](#archway.rewards.v1beta1.ContractFlatFeeSetEvent)
- [ContractMetadataSetEvent](#archway.rewards.v1beta1.ContractMetadataSetEvent)
- [ContractRewardCalculationEvent](#archway.rewards.v1beta1.ContractRewardCalculationEvent)
- [MinConsensusFeeSetEvent](#archway.rewards.v1beta1.MinConsensusFeeSetEvent)
Expand All @@ -28,6 +30,8 @@
- [QueryContractMetadataResponse](#archway.rewards.v1beta1.QueryContractMetadataResponse)
- [QueryEstimateTxFeesRequest](#archway.rewards.v1beta1.QueryEstimateTxFeesRequest)
- [QueryEstimateTxFeesResponse](#archway.rewards.v1beta1.QueryEstimateTxFeesResponse)
- [QueryFlatFeeRequest](#archway.rewards.v1beta1.QueryFlatFeeRequest)
- [QueryFlatFeeResponse](#archway.rewards.v1beta1.QueryFlatFeeResponse)
- [QueryOutstandingRewardsRequest](#archway.rewards.v1beta1.QueryOutstandingRewardsRequest)
- [QueryOutstandingRewardsResponse](#archway.rewards.v1beta1.QueryOutstandingRewardsResponse)
- [QueryParamsRequest](#archway.rewards.v1beta1.QueryParamsRequest)
Expand All @@ -42,6 +46,8 @@
- [archway/rewards/v1beta1/tx.proto](#archway/rewards/v1beta1/tx.proto)
- [MsgSetContractMetadata](#archway.rewards.v1beta1.MsgSetContractMetadata)
- [MsgSetContractMetadataResponse](#archway.rewards.v1beta1.MsgSetContractMetadataResponse)
- [MsgSetFlatFee](#archway.rewards.v1beta1.MsgSetFlatFee)
- [MsgSetFlatFeeResponse](#archway.rewards.v1beta1.MsgSetFlatFeeResponse)
- [MsgWithdrawRewards](#archway.rewards.v1beta1.MsgWithdrawRewards)
- [MsgWithdrawRewards.RecordIDs](#archway.rewards.v1beta1.MsgWithdrawRewards.RecordIDs)
- [MsgWithdrawRewards.RecordsLimit](#archway.rewards.v1beta1.MsgWithdrawRewards.RecordsLimit)
Expand Down Expand Up @@ -111,6 +117,22 @@ ContractMetadata defines the contract rewards distribution options for a particu



<a name="archway.rewards.v1beta1.FlatFee"></a>

### FlatFee
FlatFee defines the flat fee for a particular contract.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `contract_address` | [string](#string) | | contract_address defines the contract address (bech32 encoded). |
| `flat_fee` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | flat_fee defines the minimum flat fee set by the contract_owner |






<a name="archway.rewards.v1beta1.Params"></a>

### Params
Expand All @@ -122,6 +144,7 @@ Params defines the module parameters.
| `inflation_rewards_ratio` | [string](#string) | | inflation_rewards_ratio defines the percentage of minted inflation tokens that are used for dApp rewards [0.0, 1.0]. If set to 0.0, no inflation rewards are distributed. |
| `tx_fee_rebate_ratio` | [string](#string) | | tx_fee_rebate_ratio defines the percentage of tx fees that are used for dApp rewards [0.0, 1.0]. If set to 0.0, no fee rewards are distributed. |
| `max_withdraw_records` | [uint64](#uint64) | | max_withdraw_records defines the maximum number of RewardsRecord objects used for the withdrawal operation. |
| `min_price_of_gas` | [cosmos.base.v1beta1.DecCoin](#cosmos.base.v1beta1.DecCoin) | | min_price_of_gas defines the minimum price for each single unit of gas in the network. during the min consensus fee ante handler we will be taking the max between min consensus fee and minimum price of gas to compute the minimum tx computational fees, which are independent from contract flat fees (premiums) |



Expand Down Expand Up @@ -184,6 +207,22 @@ TxRewards defines transaction related rewards distribution data.



<a name="archway.rewards.v1beta1.ContractFlatFeeSetEvent"></a>

### ContractFlatFeeSetEvent
ContractFlatFeeSetEvent is emitted when the contract flat fee is updated


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `contract_address` | [string](#string) | | contract_address defines the bech32 address of the contract for which the flat fee is set |
| `flat_fee` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | flat_fee defines the amount that has been set as the minimum fee for the contract |






<a name="archway.rewards.v1beta1.ContractMetadataSetEvent"></a>

### ContractMetadataSetEvent
Expand Down Expand Up @@ -282,6 +321,7 @@ GenesisState defines the initial state of the tracking module.
| `min_consensus_fee` | [cosmos.base.v1beta1.DecCoin](#cosmos.base.v1beta1.DecCoin) | | min_consensus_fee defines the minimum gas unit price. |
| `rewards_record_last_id` | [uint64](#uint64) | | rewards_record_last_id defines the last unique ID for a RewardsRecord objs. |
| `rewards_records` | [RewardsRecord](#archway.rewards.v1beta1.RewardsRecord) | repeated | rewards_records defines a list of all active (undistributed) rewards records. |
| `flat_fees` | [FlatFee](#archway.rewards.v1beta1.FlatFee) | repeated | flat_fees defines a list of contract flat fee. |



Expand Down Expand Up @@ -384,6 +424,7 @@ QueryEstimateTxFeesRequest is the request for Query.EstimateTxFees.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `gas_limit` | [uint64](#uint64) | | gas_limit is the transaction gas limit. |
| `contract_address` | [string](#string) | | contract_address whose flat fee is considered when estimating tx fees. |



Expand All @@ -399,7 +440,37 @@ QueryEstimateTxFeesResponse is the response for Query.EstimateTxFees.
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `gas_unit_price` | [cosmos.base.v1beta1.DecCoin](#cosmos.base.v1beta1.DecCoin) | | gas_unit_price defines the minimum transaction fee per gas unit. |
| `estimated_fee` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | estimated_fee is the estimated transaction fee for a given gas limit. |
| `estimated_fee` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | repeated | estimated_fee is the estimated transaction fee for a given gas limit. |






<a name="archway.rewards.v1beta1.QueryFlatFeeRequest"></a>

### QueryFlatFeeRequest
QueryFlatFeeRequest is the request for Query.FlatFeet


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `contract_address` | [string](#string) | | contract_address is the contract address (bech32 encoded). |






<a name="archway.rewards.v1beta1.QueryFlatFeeResponse"></a>

### QueryFlatFeeResponse
QueryFlatFeeResponse is the response for Query.FlatFee


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `flat_fee_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | flat_fee_amount defines the minimum flat fee set by the contract_owner per contract execution. |



Expand Down Expand Up @@ -540,6 +611,7 @@ Query service for the tracking module.
| `EstimateTxFees` | [QueryEstimateTxFeesRequest](#archway.rewards.v1beta1.QueryEstimateTxFeesRequest) | [QueryEstimateTxFeesResponse](#archway.rewards.v1beta1.QueryEstimateTxFeesResponse) | EstimateTxFees returns the estimated transaction fees for the given transaction gas limit using the minimum consensus fee value for the current block. | GET|/archway/rewards/v1/estimate_tx_fees|
| `RewardsRecords` | [QueryRewardsRecordsRequest](#archway.rewards.v1beta1.QueryRewardsRecordsRequest) | [QueryRewardsRecordsResponse](#archway.rewards.v1beta1.QueryRewardsRecordsResponse) | RewardsRecords returns the paginated list of RewardsRecord objects stored for the provided rewards_address. | GET|/archway/rewards/v1/rewards_records|
| `OutstandingRewards` | [QueryOutstandingRewardsRequest](#archway.rewards.v1beta1.QueryOutstandingRewardsRequest) | [QueryOutstandingRewardsResponse](#archway.rewards.v1beta1.QueryOutstandingRewardsResponse) | OutstandingRewards returns total rewards credited from different contracts for the provided rewards_address. | GET|/archway/rewards/v1/outstanding_rewards|
| `FlatFee` | [QueryFlatFeeRequest](#archway.rewards.v1beta1.QueryFlatFeeRequest) | [QueryFlatFeeResponse](#archway.rewards.v1beta1.QueryFlatFeeResponse) | FlatFee returns the flat fee set by the contract owner for the provided contract_address | GET|/archway/rewards/v1/flat_fee|

<!-- end services -->

Expand Down Expand Up @@ -578,6 +650,33 @@ MsgSetContractMetadataResponse is the response for Msg.SetContractMetadata.



<a name="archway.rewards.v1beta1.MsgSetFlatFee"></a>

### MsgSetFlatFee
MsgSetFlatFee is the request for Msg.SetFlatFee.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `sender_address` | [string](#string) | | sender_address is the msg sender address (bech32 encoded). |
| `contract_address` | [string](#string) | | contract_address is the contract address (bech32 encoded). |
| `flat_fee_amount` | [cosmos.base.v1beta1.Coin](#cosmos.base.v1beta1.Coin) | | flat_fee_amount defines the minimum flat fee set by the contract_owner |






<a name="archway.rewards.v1beta1.MsgSetFlatFeeResponse"></a>

### MsgSetFlatFeeResponse
MsgSetFlatFeeResponse is the response for Msg.SetFlatFee.






<a name="archway.rewards.v1beta1.MsgWithdrawRewards"></a>

### MsgWithdrawRewards
Expand Down Expand Up @@ -656,6 +755,7 @@ Msg defines the module messaging service.
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `SetContractMetadata` | [MsgSetContractMetadata](#archway.rewards.v1beta1.MsgSetContractMetadata) | [MsgSetContractMetadataResponse](#archway.rewards.v1beta1.MsgSetContractMetadataResponse) | SetContractMetadata creates or updates an existing contract metadata. Method is authorized to the contract owner (admin if no metadata exists). | |
| `WithdrawRewards` | [MsgWithdrawRewards](#archway.rewards.v1beta1.MsgWithdrawRewards) | [MsgWithdrawRewardsResponse](#archway.rewards.v1beta1.MsgWithdrawRewardsResponse) | WithdrawRewards performs collected rewards distribution. Rewards might be credited from multiple contracts (rewards_address must be set in the corresponding contract metadata). | |
| `SetFlatFee` | [MsgSetFlatFee](#archway.rewards.v1beta1.MsgSetFlatFee) | [MsgSetFlatFeeResponse](#archway.rewards.v1beta1.MsgSetFlatFeeResponse) | SetFlatFee sets or updates or removes the flat fee to interact with the contract Method is authorized to the contract owner. | |

<!-- end services -->

Expand Down
2 changes: 1 addition & 1 deletion e2e/txfees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// Test configures a chain based on the Archway mainnet parameters.
func (s *E2ETestSuite) TestTxFees() {
const (
txGasLimit = 200_000
txGasLimit = 201_000
txFeeAmtIncrement = 1000
)

Expand Down
6 changes: 6 additions & 0 deletions proto/archway/rewards/v1beta1/rewards.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ message Params {
];
// max_withdraw_records defines the maximum number of RewardsRecord objects used for the withdrawal operation.
uint64 max_withdraw_records = 3;

// min_price_of_gas defines the minimum price for each single unit of gas in the network.
// during the min consensus fee ante handler we will be taking the max between min consensus
// fee and minimum price of gas to compute the minimum tx computational fees, which are independent
// from contract flat fees (premiums)
cosmos.base.v1beta1.DecCoin min_price_of_gas = 4 [ (gogoproto.nullable) = false ];
}

// ContractMetadata defines the contract rewards distribution options for a particular contract.
Expand Down
2 changes: 1 addition & 1 deletion x/rewards/ante/ante_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// RewardsKeeperExpected defines the expected interface for the x/rewards keeper.
type RewardsKeeperExpected interface {
// Used in MinFeeDecorator
GetMinConsensusFee(ctx sdk.Context) (sdk.DecCoin, bool)
ComputationalPriceOfGas(ctx sdk.Context) sdk.DecCoin
GetFlatFee(ctx sdk.Context, contractAddr sdk.AccAddress) (sdk.Coin, bool)
CreateFlatFeeRewardsRecords(ctx sdk.Context, contractAddress sdk.AccAddress, flatfee sdk.Coins)

Expand Down
23 changes: 7 additions & 16 deletions x/rewards/ante/min_cons_fee.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkErrors "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/archway-network/archway/pkg"
)

// MinFeeDecorator rejects transaction if its fees are less than minimum fees defined by the x/rewards module.
Expand Down Expand Up @@ -38,20 +36,13 @@ func (mfd MinFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool,
}

var expectedFees sdk.Coins // All the fees which need to be paid for the given tx. includes min consensus fee + every contract flat fee
gasUnitPrice, found := mfd.rewardsKeeper.GetMinConsensusFee(ctx)
if found {
// Estimate the minimum fee expected
// We use RoundInt here since minimum fee must be GTE calculated amount
txGasLimit := pkg.NewDecFromUint64(feeTx.GetGas())
if txGasLimit.IsZero() {
return ctx, sdkErrors.Wrap(sdkErrors.ErrInvalidRequest, "tx gas limit is not set")
}
minFeeExpected := sdk.Coin{
Denom: gasUnitPrice.Denom,
Amount: gasUnitPrice.Amount.Mul(txGasLimit).RoundInt(),
}
expectedFees = expectedFees.Add(minFeeExpected)
}
computationalGasPrice := mfd.rewardsKeeper.ComputationalPriceOfGas(ctx)
expectedFees = expectedFees.Add(
sdk.NewCoin(
computationalGasPrice.Denom,
computationalGasPrice.Amount.MulInt(sdk.NewIntFromUint64(feeTx.GetGas())).TruncateInt(),
),
)

// Get flatfees for any contracts being called in the tx.msgs
for _, m := range tx.GetMsgs() {
Expand Down
27 changes: 27 additions & 0 deletions x/rewards/ante/min_cons_fee_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func TestRewardsMinFeeAnteHandler(t *testing.T) {
txFees string // transaction fees [sdk.Coins]
txGasLimit uint64 // transaction gas limit
minConsFee string // min consensus fee [sdk.DecCoin]
minPoG string
// Output expected
errExpected error // concrete error expected (or nil if no error expected)
}
Expand All @@ -34,31 +35,52 @@ func TestRewardsMinFeeAnteHandler(t *testing.T) {
txFees: "200stake",
txGasLimit: 1000,
minConsFee: "0.1stake",
minPoG: "0stake",
},
{
name: "OK: 100stake fee == 100stake min fee",
txFees: "100stake",
txGasLimit: 1000,
minConsFee: "0.1stake",
minPoG: "0stake",
},
{
name: "Fail: 99stake fee < 100stake min fee",
txFees: "99stake",
txGasLimit: 1000,
minConsFee: "0.1stake",
minPoG: "0stake",
errExpected: sdkErrors.ErrInsufficientFee,
},
{
name: "OK: min consensus fee is zero",
txFees: "100stake",
txGasLimit: 1000,
minConsFee: "0stake",
minPoG: "0stake",
},
{
name: "OK: expected fee is too low (zero)",
txFees: "1stake",
txGasLimit: 1000,
minConsFee: "0.000000000001stake",
minPoG: "0stake",
},
{
name: "OK: min PoG used, min cons fee not set",
txFees: "1000stake",
txGasLimit: 1000,
minConsFee: "0stake",
minPoG: "1stake",
errExpected: nil,
},
{
name: "OK: min PoG used, min cons fee lower",
txFees: "1000stake",
txGasLimit: 1000,
minConsFee: "0.1stake",
minPoG: "1stake",
errExpected: nil,
},
}

Expand All @@ -73,6 +95,11 @@ func TestRewardsMinFeeAnteHandler(t *testing.T) {
require.NoError(t, err)

chain.GetApp().RewardsKeeper.GetState().MinConsensusFee(ctx).SetFee(minConsFee)
params := chain.GetApp().RewardsKeeper.GetParams(ctx)
coin, err := sdk.ParseDecCoin(tc.minPoG)
require.NoError(t, err)
params.MinPriceOfGas = coin
chain.GetApp().RewardsKeeper.SetParams(ctx, params)

// Build transaction
txFees, err := sdk.ParseCoinsNormalized(tc.txFees)
Expand Down
1 change: 1 addition & 0 deletions x/rewards/keeper/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func (s *KeeperTestSuite) TestGenesisImportExport() {
sdk.NewDecWithPrec(99, 2),
sdk.NewDecWithPrec(98, 2),
1001,
types.DefaultMinPriceOfGas,
)

newMetadata := []types.ContractMetadata{
Expand Down
13 changes: 4 additions & 9 deletions x/rewards/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,9 @@ func (s *QueryServer) EstimateTxFees(c context.Context, request *types.QueryEsti

ctx := sdk.UnwrapSDKContext(c)

var fees sdk.Coins
minConsFee, found := s.keeper.GetMinConsensusFee(ctx)
if found {
fees = fees.Add(sdk.Coin{
Denom: minConsFee.Denom,
Amount: minConsFee.Amount.MulInt64(int64(request.GasLimit)).RoundInt(),
})
}
fees := sdk.NewCoins()
computationalPoG := s.keeper.ComputationalPriceOfGas(ctx)
fees = fees.Add(sdk.NewCoin(computationalPoG.Denom, computationalPoG.Amount.MulInt(sdk.NewIntFromUint64(request.GasLimit)).RoundInt()))

if request.ContractAddress != "" { // if contract address is passed in, get the flat fee and add that.
contractAddr, err := sdk.AccAddressFromBech32(request.ContractAddress)
Expand All @@ -126,7 +121,7 @@ func (s *QueryServer) EstimateTxFees(c context.Context, request *types.QueryEsti
}

return &types.QueryEstimateTxFeesResponse{
GasUnitPrice: minConsFee,
GasUnitPrice: computationalPoG,
EstimatedFee: fees.Sort(),
}, nil
}
Expand Down
5 changes: 2 additions & 3 deletions x/rewards/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func (s *KeeperTestSuite) TestGRPC_Params() {
InflationRewardsRatio: sdk.MustNewDecFromStr("0.1"),
TxFeeRebateRatio: sdk.MustNewDecFromStr("0.1"),
MaxWithdrawRecords: uint64(2),
MinPriceOfGas: rewardsTypes.DefaultMinPriceOfGas,
}
k.SetParams(ctx, params)

Expand All @@ -32,9 +33,7 @@ func (s *KeeperTestSuite) TestGRPC_Params() {
s.Run("ok: gets params", func() {
res, err := querySrvr.Params(sdk.WrapSDKContext(ctx), &rewardsTypes.QueryParamsRequest{})
s.Require().NoError(err)
s.Require().Equal(params.InflationRewardsRatio, res.Params.InflationRewardsRatio)
s.Require().Equal(params.TxFeeRebateRatio, res.Params.TxFeeRebateRatio)
s.Require().Equal(params.MaxWithdrawRecords, res.Params.MaxWithdrawRecords)
s.Require().Equal(params, res.Params)
})
}

Expand Down
Loading