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

[21.2.x] upgrade/migrations: max allowances upgrade #4064

Merged
merged 1 commit into from
Jun 22, 2021
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
4 changes: 4 additions & 0 deletions .changelog/4064.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
upgrade/migrations: add max allowances upgrade handler

Adds `"consensus-staking-max-allowances-16"` upgrade handler which updates
the consensus staking parameter `MaxAllowances` to `16`.
52 changes: 52 additions & 0 deletions go/upgrade/migrations/consensus_max_allowances.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package migrations

import (
"fmt"

abciAPI "github.com/oasisprotocol/oasis-core/go/consensus/tendermint/api"
stakingState "github.com/oasisprotocol/oasis-core/go/consensus/tendermint/apps/staking/state"
)

const (
// ConsensusMaxAllowances16Handler is the name of the upgrade that sets the
// staking max allowances consensus parameter to 16.
ConsensusMaxAllowances16Handler = "consensus-max-allowances-16"
)

var _ Handler = (*maxAllowances16Handler)(nil)

type maxAllowances16Handler struct {
}

func (th *maxAllowances16Handler) StartupUpgrade(ctx *Context) error {
return nil
}

func (th *maxAllowances16Handler) ConsensusUpgrade(ctx *Context, privateCtx interface{}) error {
abciCtx := privateCtx.(*abciAPI.Context)
switch abciCtx.Mode() {
case abciAPI.ContextBeginBlock:
// Nothing to do during begin block.
case abciAPI.ContextEndBlock:
// Update a consensus parameter during EndBlock.
state := stakingState.NewMutableState(abciCtx.State())

params, err := state.ConsensusParameters(abciCtx)
if err != nil {
return fmt.Errorf("unable to load staking consensus parameters: %w", err)
}

params.MaxAllowances = 16

if err = state.SetConsensusParameters(abciCtx, params); err != nil {
return fmt.Errorf("failed to update staking consensus parameters: %w", err)
}
default:
return fmt.Errorf("upgrade handler called in unexpected context: %s", abciCtx.Mode())
}
return nil
}

func init() {
Register(ConsensusMaxAllowances16Handler, &maxAllowances16Handler{})
}