Skip to content

Commit

Permalink
Merge pull request #4978 from oasisprotocol/kostko/feature/merge-upgr…
Browse files Browse the repository at this point in the history
…ades-v61

go/upgrade: Merge TEE PCS/change parameters upgrade handlers
  • Loading branch information
kostko authored Oct 13, 2022
2 parents 5985dc5 + 7d5d0bb commit 2378dd5
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 120 deletions.
Empty file added .changelog/4978.trivial.md
Empty file.
2 changes: 1 addition & 1 deletion go/oasis-test-runner/scenario/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ func RegisterScenarios() error {
// Node upgrade tests.
NodeUpgradeDummy,
NodeUpgradeMaxAllowances,
NodeUpgradeTEEPCS,
NodeUpgradeV61,
NodeUpgradeEmpty,
NodeUpgradeCancel,
// Debonding entries from genesis test.
Expand Down
19 changes: 14 additions & 5 deletions go/oasis-test-runner/scenario/e2e/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ func (n *noOpUpgradeChecker) PostUpgradeFn(ctx context.Context, ctrl *oasis.Cont
return nil
}

type upgradeTeePcsChecker struct{}
type upgradeV61Checker struct{}

func (n *upgradeTeePcsChecker) PreUpgradeFn(ctx context.Context, ctrl *oasis.Controller) error {
func (n *upgradeV61Checker) PreUpgradeFn(ctx context.Context, ctrl *oasis.Controller) error {
return nil
}

func (n *upgradeTeePcsChecker) PostUpgradeFn(ctx context.Context, ctrl *oasis.Controller) error {
func (n *upgradeV61Checker) PostUpgradeFn(ctx context.Context, ctrl *oasis.Controller) error {
// Check updated registry parameters.
registryParams, err := ctrl.Registry.ConsensusParameters(ctx, consensus.HeightLatest)
if err != nil {
Expand All @@ -111,6 +111,15 @@ func (n *upgradeTeePcsChecker) PostUpgradeFn(ctx context.Context, ctrl *oasis.Co
return fmt.Errorf("default gas cost for freshness proofs is not set")
}

// Check updated governance parameters.
govParams, err := ctrl.Governance.ConsensusParameters(ctx, consensus.HeightLatest)
if err != nil {
return fmt.Errorf("can't get governance consensus parameters: %w", err)
}
if !govParams.EnableChangeParametersProposal {
return fmt.Errorf("change parameters proposal is disabled")
}

return nil
}

Expand All @@ -119,8 +128,8 @@ var (
NodeUpgradeDummy scenario.Scenario = newNodeUpgradeImpl(migrations.DummyUpgradeHandler, &dummyUpgradeChecker{})
// NodeUpgradeMaxAllowances is the node upgrade max allowances scenario.
NodeUpgradeMaxAllowances scenario.Scenario = newNodeUpgradeImpl(migrations.ConsensusMaxAllowances16Handler, &noOpUpgradeChecker{})
// NodeUpgradeTEEPCS is the node consensus TEE PCS enablement scenario.
NodeUpgradeTEEPCS scenario.Scenario = newNodeUpgradeImpl(migrations.ConsensusTEEPCSHandler, &upgradeTeePcsChecker{})
// NodeUpgradeV61 is the node consensus V61 migration scenario.
NodeUpgradeV61 scenario.Scenario = newNodeUpgradeImpl(migrations.ConsensusV61, &upgradeV61Checker{})
// NodeUpgradeEmpty is the empty node upgrade scenario.
NodeUpgradeEmpty scenario.Scenario = newNodeUpgradeImpl(migrations.EmptyHandler, &noOpUpgradeChecker{})

Expand Down
51 changes: 0 additions & 51 deletions go/upgrade/migrations/consensus_change_parameters.go

This file was deleted.

63 changes: 0 additions & 63 deletions go/upgrade/migrations/consensus_tee_pcs.go

This file was deleted.

81 changes: 81 additions & 0 deletions go/upgrade/migrations/consensus_v61.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package migrations

import (
"fmt"

"github.com/oasisprotocol/oasis-core/go/common/node"
abciAPI "github.com/oasisprotocol/oasis-core/go/consensus/tendermint/api"
governanceState "github.com/oasisprotocol/oasis-core/go/consensus/tendermint/apps/governance/state"
registryState "github.com/oasisprotocol/oasis-core/go/consensus/tendermint/apps/registry/state"
registry "github.com/oasisprotocol/oasis-core/go/registry/api"
)

const (
// ConsensusV61 is the name of the upgrade that enables multiple features added in Oasis Core
// version 22.2.x, specifically PCS support for Intel SGX, remote attestation binding to node
// identities and client freshness proofs.
ConsensusV61 = "consensus-v61"
)

var _ Handler = (*v61Handler)(nil)

type v61Handler struct{}

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

func (th *v61Handler) 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 parameters during EndBlock.

// Registry.
regState := registryState.NewMutableState(abciCtx.State())

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

regParams.TEEFeatures = &node.TEEFeatures{
SGX: node.TEEFeaturesSGX{
PCS: true,
SignedAttestations: true,
DefaultMaxAttestationAge: 1200, // ~2 hours at 6 sec per block.
},
FreshnessProofs: true,
}

// Configure the default gas cost for freshness proofs.
regParams.GasCosts[registry.GasOpProveFreshness] = registry.DefaultGasCosts[registry.GasOpProveFreshness]

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

// Governance.
govState := governanceState.NewMutableState(abciCtx.State())

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

govParams.EnableChangeParametersProposal = true

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

func init() {
Register(ConsensusV61, &v61Handler{})
}

0 comments on commit 2378dd5

Please sign in to comment.