-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upgrade/migrations: max allowances parameter update
- Loading branch information
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{}) | ||
} |