Skip to content

Commit

Permalink
upgrade/migrations: max allowances parameter update
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed Jun 22, 2021
1 parent 3e998b4 commit 39e946a
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions go/upgrade/migrations/consensus_max_allowances.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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 (
// ConsensusMaxAllowancesHandler is the name of the upgrade that sets the
// staking max allowances consensus parameter to 16.
ConsensusMaxAllowancesHandler = "consensus-staking-max-allowances-16"
)

var (
_ Handler = (*maxAllowancesHandler)(nil)
)

type maxAllowancesHandler struct {
}

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

func (th *maxAllowancesHandler) 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(ConsensusMaxAllowancesHandler, &maxAllowancesHandler{})
}

0 comments on commit 39e946a

Please sign in to comment.