Skip to content
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

feat: use medibloc/cosmos-sdk for min_commission_rate + add upgrade handler #291

Merged
merged 11 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from 9 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
3 changes: 2 additions & 1 deletion .gitbook/guide/interaction-with-the-network-cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ panacead tx staking create-validator \
For details about various key types, please see this [guide](interaction-with-the-network-cli.md#keys).
- `moniker`: A validator nickname that will be displayed publicly
- `commission-rate`: An initial commission rate on block rewards and fees charged to delegators
- This shouldn't be smaller than the minimum commission rate (a genesis parameter) that can be queried by `panacead query staking params`.
- `commission-max-rate`: A maximum commission rate which this validator can charge. This cannot be changed after the
`create-validator` transaction is processed.
- `commission-max-change-rate`: A maximum daily increase of the validator commission. This cannot be changed after the
Expand Down Expand Up @@ -331,7 +332,7 @@ panacead tx staking edit-validator \

**Note**: The `--commission-rate` value must adhere to the following invariants:

- Must be between 0 and the validator's `commission-max-rate`
- Must be between the minimum commission rate (a genesis parameter) and the validator's `commission-max-rate`
- Must not exceed the validator's `commission-max-change-rate` which is maximum % point change rate **per day**.
In other words, a validator can only change its commission once per day and within `commission-max-change-rate` bounds.

Expand Down
7 changes: 4 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,14 @@ proto-lint:
$(DOCKER) run --rm -v $(CURDIR):/workspace --workdir /workspace bufbuild/buf lint --error-format=json

PROTO_DIR = third_party/proto
COSMOS_VER_SHORT = 0.42.7
# TODO: use the correct version after releasing medibloc/cosmos-sdk
COSMOS_VER_SHORT = 0.42.11-panacea-min-commission-rate-28eaec9
COSMOS_VER = v$(COSMOS_VER_SHORT)

proto-update-dep:
@mkdir -p $(PROTO_DIR)
@curl https://codeload.github.com/cosmos/cosmos-sdk/tar.gz/$(COSMOS_VER) | tar -xz -C $(PROTO_DIR) --strip=3 cosmos-sdk-$(COSMOS_VER_SHORT)/third_party/proto
@curl https://codeload.github.com/cosmos/cosmos-sdk/tar.gz/$(COSMOS_VER) | tar -xz -C $(PROTO_DIR) --strip=2 cosmos-sdk-$(COSMOS_VER_SHORT)/proto
@curl https://codeload.github.com/medibloc/cosmos-sdk/tar.gz/$(COSMOS_VER) | tar -xz -C $(PROTO_DIR) --strip=3 cosmos-sdk-$(COSMOS_VER_SHORT)/third_party/proto
@curl https://codeload.github.com/medibloc/cosmos-sdk/tar.gz/$(COSMOS_VER) | tar -xz -C $(PROTO_DIR) --strip=2 cosmos-sdk-$(COSMOS_VER_SHORT)/proto

########################################
### Build/Install
Expand Down
35 changes: 33 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -728,5 +728,36 @@ func initParamsKeeper(appCodec codec.BinaryMarshaler, legacyAmino *codec.LegacyA
}

func (app *App) registerUpgradeHandlers() {
app.UpgradeKeeper.SetUpgradeHandler("v2.0.2", func(ctx sdk.Context, plan upgradetypes.Plan) { })
}
app.UpgradeKeeper.SetUpgradeHandler("v2.0.2", func(ctx sdk.Context, plan upgradetypes.Plan) {})

app.UpgradeKeeper.SetUpgradeHandler("v2.0.3", func(ctx sdk.Context, plan upgradetypes.Plan) {
// Set the min-commission-rate to 3%
newParams := stakingtypes.NewParams(
app.StakingKeeper.UnbondingTime(ctx),
app.StakingKeeper.MaxValidators(ctx),
app.StakingKeeper.MaxEntries(ctx),
app.StakingKeeper.HistoricalEntries(ctx),
app.StakingKeeper.BondDenom(ctx),
sdk.NewDecWithPrec(3, 2), // min-commission-rate
)
app.StakingKeeper.SetParams(ctx, newParams)

// Update the commission rate of all validators whose commission rate is smaller than min-commission-rate
validators := app.StakingKeeper.GetAllValidators(ctx)
minCommissionRate := app.StakingKeeper.GetParams(ctx).MinCommissionRate
for _, v := range validators {
if v.Commission.Rate.LT(minCommissionRate) {
comm, err := app.StakingKeeper.MustUpdateValidatorCommission(ctx, v, minCommissionRate)
if err != nil {
panic(err)
}
v.Commission = comm

// call the before-modification hook since we're about to update the commission
app.StakingKeeper.BeforeValidatorModified(ctx, v.GetOperator())

app.StakingKeeper.SetValidator(ctx, v)
}
}
})
}
251 changes: 248 additions & 3 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5242,7 +5242,7 @@ paths:
format: boolean
tags:
- Query
'/cosmos/bank/v1beta1/balances/{address}/{denom}':
'/cosmos/bank/v1beta1/balances/{address}/by_denom':
get:
summary: Balance queries the balance of a single coin for a single account.
operationId: Balance
Expand Down Expand Up @@ -5300,8 +5300,8 @@ paths:
type: string
- name: denom
description: denom is the coin denom to query balances for.
in: path
required: true
in: query
required: false
type: string
tags:
- Query
Expand Down Expand Up @@ -16129,6 +16129,11 @@ paths:
bond_denom:
type: string
description: bond_denom defines the bondable coin denomination.
min_commission_rate:
type: string
title: >-
min_commission_rate is the chain-wide minimum commission
rate that a validator can charge their delegators
description: >-
QueryParamsResponse is response type for the Query/Params RPC
method.
Expand Down Expand Up @@ -19652,6 +19657,53 @@ paths:
For height == 1,

it's genesis time.
events:
type: array
items:
type: object
properties:
type:
type: string
attributes:
type: array
items:
type: object
properties:
key:
type: string
format: byte
value:
type: string
format: byte
index:
type: boolean
format: boolean
description: >-
EventAttribute is a single key-value pair,
associated with an event.
description: >-
Event allows application developers to attach additional
information to

ResponseBeginBlock, ResponseEndBlock, ResponseCheckTx
and ResponseDeliverTx.

Later, transactions may be queried using these events.
description: >-
Events defines all the events emitted by processing a
transaction. Note,

these events include those emitted by processing all the
messages and those

emitted from the ante handler. Whereas Logs contains the
events, with

additional metadata, emitted only by processing the
messages.


Since: cosmos-sdk 0.42.11, 0.44.5, 0.45
description: >-
TxResponse defines a structure containing relevant tx data and
metadata. The
Expand Down Expand Up @@ -39455,6 +39507,11 @@ definitions:
bond_denom:
type: string
description: bond_denom defines the bondable coin denomination.
min_commission_rate:
type: string
title: >-
min_commission_rate is the chain-wide minimum commission rate that a
validator can charge their delegators
description: Params defines the parameters for the staking module.
cosmos.staking.v1beta1.Pool:
type: object
Expand Down Expand Up @@ -40695,6 +40752,11 @@ definitions:
bond_denom:
type: string
description: bond_denom defines the bondable coin denomination.
min_commission_rate:
type: string
title: >-
min_commission_rate is the chain-wide minimum commission rate that
a validator can charge their delegators
description: QueryParamsResponse is response type for the Query/Params RPC method.
cosmos.staking.v1beta1.QueryPoolResponse:
type: object
Expand Down Expand Up @@ -42581,6 +42643,51 @@ definitions:
== 1,

it's genesis time.
events:
type: array
items:
type: object
properties:
type:
type: string
attributes:
type: array
items:
type: object
properties:
key:
type: string
format: byte
value:
type: string
format: byte
index:
type: boolean
format: boolean
description: >-
EventAttribute is a single key-value pair, associated with an
event.
description: >-
Event allows application developers to attach additional information
to

ResponseBeginBlock, ResponseEndBlock, ResponseCheckTx and
ResponseDeliverTx.

Later, transactions may be queried using these events.
description: >-
Events defines all the events emitted by processing a transaction.
Note,

these events include those emitted by processing all the messages and
those

emitted from the ante handler. Whereas Logs contains the events, with

additional metadata, emitted only by processing the messages.


Since: cosmos-sdk 0.42.11, 0.44.5, 0.45
description: >-
TxResponse defines a structure containing relevant tx data and metadata.
The
Expand Down Expand Up @@ -43011,6 +43118,52 @@ definitions:
height == 1,

it's genesis time.
events:
type: array
items:
type: object
properties:
type:
type: string
attributes:
type: array
items:
type: object
properties:
key:
type: string
format: byte
value:
type: string
format: byte
index:
type: boolean
format: boolean
description: >-
EventAttribute is a single key-value pair, associated with
an event.
description: >-
Event allows application developers to attach additional
information to

ResponseBeginBlock, ResponseEndBlock, ResponseCheckTx and
ResponseDeliverTx.

Later, transactions may be queried using these events.
description: >-
Events defines all the events emitted by processing a transaction.
Note,

these events include those emitted by processing all the messages
and those

emitted from the ante handler. Whereas Logs contains the events,
with

additional metadata, emitted only by processing the messages.


Since: cosmos-sdk 0.42.11, 0.44.5, 0.45
description: >-
TxResponse defines a structure containing relevant tx data and
metadata. The
Expand Down Expand Up @@ -43338,6 +43491,52 @@ definitions:
height == 1,

it's genesis time.
events:
type: array
items:
type: object
properties:
type:
type: string
attributes:
type: array
items:
type: object
properties:
key:
type: string
format: byte
value:
type: string
format: byte
index:
type: boolean
format: boolean
description: >-
EventAttribute is a single key-value pair, associated with
an event.
description: >-
Event allows application developers to attach additional
information to

ResponseBeginBlock, ResponseEndBlock, ResponseCheckTx and
ResponseDeliverTx.

Later, transactions may be queried using these events.
description: >-
Events defines all the events emitted by processing a transaction.
Note,

these events include those emitted by processing all the messages
and those

emitted from the ante handler. Whereas Logs contains the events,
with

additional metadata, emitted only by processing the messages.


Since: cosmos-sdk 0.42.11, 0.44.5, 0.45
description: >-
TxResponse defines a structure containing relevant tx data and
metadata. The
Expand Down Expand Up @@ -43617,6 +43816,52 @@ definitions:
height == 1,

it's genesis time.
events:
type: array
items:
type: object
properties:
type:
type: string
attributes:
type: array
items:
type: object
properties:
key:
type: string
format: byte
value:
type: string
format: byte
index:
type: boolean
format: boolean
description: >-
EventAttribute is a single key-value pair, associated
with an event.
description: >-
Event allows application developers to attach additional
information to

ResponseBeginBlock, ResponseEndBlock, ResponseCheckTx and
ResponseDeliverTx.

Later, transactions may be queried using these events.
description: >-
Events defines all the events emitted by processing a
transaction. Note,

these events include those emitted by processing all the
messages and those

emitted from the ante handler. Whereas Logs contains the events,
with

additional metadata, emitted only by processing the messages.


Since: cosmos-sdk 0.42.11, 0.44.5, 0.45
description: >-
TxResponse defines a structure containing relevant tx data and
metadata. The
Expand Down
Loading