Skip to content

Commit

Permalink
go/upgrade/migrations: Prepare handler for version 24.0.0
Browse files Browse the repository at this point in the history
The handler enables the key manager CHURP extension.
  • Loading branch information
peternose committed Feb 27, 2024
1 parent 7b04a87 commit 950bfbc
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/5571.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
go/upgrade/migrations: Prepare handler for version 24.0.0

The handler enables the key manager CHURP extension.
9 changes: 8 additions & 1 deletion go/oasis-test-runner/oasis/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ type NetworkCfg struct { // nolint: maligned
// left empty. Nodes are started in the order in which they appear here (automatically created
// nodes are appended).
Nodes []string

// EnableKeyManagerCHURP is the enable key manager CHURP extension flag.
EnableKeyManagerCHURP bool `json:"enable_km_churp,omitempty"`
}

// SetMockEpoch force-enables the mock epoch time keeping.
Expand Down Expand Up @@ -778,7 +781,6 @@ func (net *Network) MakeGenesis() error {
"--" + genesis.CfgConsensusBackend, net.cfg.Consensus.Backend,
"--" + genesis.CfgConsensusTimeoutCommit, net.cfg.Consensus.Parameters.TimeoutCommit.String(),
"--" + genesis.CfgRegistryEnableRuntimeGovernanceModels, "entity,runtime",
"--" + genesis.CfgRegistryEnableKeyManagerCHURP, "true",
"--" + genesis.CfgRegistryDebugAllowUnroutableAddresses, "true",
"--" + genesis.CfgRegistryDebugAllowTestRuntimes, "true",
"--" + genesis.CfgSchedulerMaxValidatorsPerEntity, strconv.Itoa(len(net.Validators())),
Expand All @@ -789,6 +791,11 @@ func (net *Network) MakeGenesis() error {
"--" + genesis.CfgStakingTokenValueExponent, strconv.FormatUint(uint64(genesisTestHelpers.TestStakingTokenValueExponent), 10),
"--" + genesis.CfgBeaconBackend, net.cfg.Beacon.Backend,
}
if net.cfg.EnableKeyManagerCHURP {
args = append(args, []string{
"--" + genesis.CfgRegistryEnableKeyManagerCHURP, "true",
}...)
}
switch net.cfg.Beacon.Backend {
case beacon.BackendInsecure:
args = append(args, []string{
Expand Down
1 change: 1 addition & 0 deletions go/oasis-test-runner/scenario/e2e/scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func RegisterScenarios() error {
NodeUpgradeDummy,
NodeUpgradeEmpty,
NodeUpgradeCancel,
NodeUpgradeConsensus240,
// Debonding entries from genesis test.
Debond,
// Consensus state sync.
Expand Down
47 changes: 47 additions & 0 deletions go/oasis-test-runner/scenario/e2e/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"path"
"path/filepath"
"reflect"
"sync"
"time"

Expand All @@ -17,6 +18,7 @@ import (
"github.com/oasisprotocol/oasis-core/go/common/pubsub"
"github.com/oasisprotocol/oasis-core/go/common/version"
consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
"github.com/oasisprotocol/oasis-core/go/keymanager/churp"
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/env"
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/log"
"github.com/oasisprotocol/oasis-core/go/oasis-test-runner/oasis"
Expand Down Expand Up @@ -80,11 +82,56 @@ func (n *noOpUpgradeChecker) PostUpgradeFn(context.Context, *oasis.Controller) e
return nil
}

type upgrade240Checker struct{}

func (c *upgrade240Checker) PreUpgradeFn(ctx context.Context, ctrl *oasis.Controller) error {
// Check registry parameters.
registryParams, err := ctrl.Registry.ConsensusParameters(ctx, consensus.HeightLatest)
if err != nil {
return fmt.Errorf("can't get registry consensus parameters: %w", err)
}
if registryParams.EnableKeyManagerCHURP {
return fmt.Errorf("key manager CHURP extension is enabled")
}

// Check CHURP parameters.
_, err = ctrl.Keymanager.Churp().ConsensusParameters(ctx, consensus.HeightLatest)
if err == nil {
return fmt.Errorf("key manager CHURP consensus parameters shouldn't be set: %w", err)
}

return nil
}

func (c *upgrade240Checker) PostUpgradeFn(ctx context.Context, ctrl *oasis.Controller) error {
// Check updated registry parameters.
registryParams, err := ctrl.Registry.ConsensusParameters(ctx, consensus.HeightLatest)
if err != nil {
return fmt.Errorf("can't get registry consensus parameters: %w", err)
}
if !registryParams.EnableKeyManagerCHURP {
return fmt.Errorf("key manager CHURP extension is disabled")
}

// Check updated CHURP parameters.
churpParams, err := ctrl.Keymanager.Churp().ConsensusParameters(ctx, consensus.HeightLatest)
if err != nil {
return fmt.Errorf("can't get key manager CHURP consensus parameters: %w", err)
}
if !reflect.DeepEqual(*churpParams, churp.DefaultConsensusParameters) {
return fmt.Errorf("key manager CHURP consensus parameters are not default")
}

return nil
}

var (
// NodeUpgradeDummy is the node upgrade dummy scenario.
NodeUpgradeDummy scenario.Scenario = newNodeUpgradeImpl(migrations.DummyUpgradeHandler, &dummyUpgradeChecker{})
// NodeUpgradeEmpty is the empty node upgrade scenario.
NodeUpgradeEmpty scenario.Scenario = newNodeUpgradeImpl(migrations.EmptyHandler, &noOpUpgradeChecker{})
// NodeUpgradeConsensus240 is the node upgrade scenario for migrating to consensus 24.0.
NodeUpgradeConsensus240 scenario.Scenario = newNodeUpgradeImpl(migrations.Consensus240, &upgrade240Checker{})

malformedDescriptor = []byte(`{
"v": 1,
Expand Down
65 changes: 65 additions & 0 deletions go/upgrade/migrations/consensus_240.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package migrations

import (
"fmt"

abciAPI "github.com/oasisprotocol/oasis-core/go/consensus/cometbft/api"
churpState "github.com/oasisprotocol/oasis-core/go/consensus/cometbft/apps/keymanager/churp/state"
registryState "github.com/oasisprotocol/oasis-core/go/consensus/cometbft/apps/registry/state"
"github.com/oasisprotocol/oasis-core/go/keymanager/churp"
)

const (
// Consensus240 is the name of the upgrade that transitions Oasis Core
// from version 23.0.x to 24.0.0.
//
// This upgrade enables the key manager CHURP extension.
Consensus240 = "consensus240"
)

var _ Handler = (*Handler240)(nil)

// Handler240 is the upgrade handler that transitions Oasis Core
// from version 23.0.x to 24.0.0.
type Handler240 struct{}

// StartupUpgrade implements Handler.
func (h *Handler240) StartupUpgrade() error {
return nil
}

// ConsensusUpgrade implements Handler.
func (h *Handler240) ConsensusUpgrade(privateCtx interface{}) error {
abciCtx := privateCtx.(*abciAPI.Context)
switch abciCtx.Mode() {
case abciAPI.ContextBeginBlock:
// Nothing to do.
case abciAPI.ContextEndBlock:
// Registry.
regState := registryState.NewMutableState(abciCtx.State())

regParams, err := regState.ConsensusParameters(abciCtx)
if err != nil {
return fmt.Errorf("failed to load registry consensus parameters: %w", err)

Check warning on line 43 in go/upgrade/migrations/consensus_240.go

View check run for this annotation

Codecov / codecov/patch

go/upgrade/migrations/consensus_240.go#L43

Added line #L43 was not covered by tests
}
regParams.EnableKeyManagerCHURP = true

if err = regState.SetConsensusParameters(abciCtx, regParams); err != nil {
return fmt.Errorf("failed to update registry consensus parameters: %w", err)

Check warning on line 48 in go/upgrade/migrations/consensus_240.go

View check run for this annotation

Codecov / codecov/patch

go/upgrade/migrations/consensus_240.go#L48

Added line #L48 was not covered by tests
}

// CHURP.
state := churpState.NewMutableState(abciCtx.State())

if err := state.SetConsensusParameters(abciCtx, &churp.DefaultConsensusParameters); err != nil {
return fmt.Errorf("failed to set CHURP consensus parameters: %w", err)

Check warning on line 55 in go/upgrade/migrations/consensus_240.go

View check run for this annotation

Codecov / codecov/patch

go/upgrade/migrations/consensus_240.go#L55

Added line #L55 was not covered by tests
}
default:
return fmt.Errorf("upgrade handler called in unexpected context: %s", abciCtx.Mode())

Check warning on line 58 in go/upgrade/migrations/consensus_240.go

View check run for this annotation

Codecov / codecov/patch

go/upgrade/migrations/consensus_240.go#L57-L58

Added lines #L57 - L58 were not covered by tests
}
return nil
}

func init() {
Register(Consensus240, &Handler240{})
}

0 comments on commit 950bfbc

Please sign in to comment.