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 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
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.15
go-version: 1.17
id: go

- name: Check out code into the Go module directory
Expand All @@ -29,7 +29,7 @@ jobs:
run: make test

- name: Lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
version: v1.30

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)
}
}
})
}
Loading