Skip to content

Commit

Permalink
Merge pull request #5760 from oasisprotocol/peternose/internal/consen…
Browse files Browse the repository at this point in the history
…sus-software-version

go/consensus: Add the latest consensus-breaking software version
  • Loading branch information
peternose committed Jul 5, 2024
2 parents 5b94237 + e48a2cf commit 66af606
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changelog/5760.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
go/consensus: Add the latest consensus-breaking software feature version

Useful for enabling new consensus-breaking features with upcoming releases.
A feature is enabled if the latest consensus-breaking software feature
version is not lower than the version in which the feature is to be enabled.
21 changes: 21 additions & 0 deletions go/consensus/cometbft/features/features.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package api

import (
"fmt"

consensusState "github.com/oasisprotocol/oasis-core/go/consensus/cometbft/abci/state"
tmapi "github.com/oasisprotocol/oasis-core/go/consensus/cometbft/api"
)

// IsFeatureVersion returns true iff the consensus feature version is high
// enough for the feature to be enabled.
func IsFeatureVersion(ctx *tmapi.Context, minVersion string) (bool, error) {
// Consensus parameters.
consState := consensusState.NewMutableState(ctx.State())
consParams, err := consState.ConsensusParameters(ctx)
if err != nil {
return false, fmt.Errorf("failed to load consensus parameters: %w", err)
}

return consParams.IsFeatureVersion(minVersion)
}
20 changes: 20 additions & 0 deletions go/consensus/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/oasisprotocol/oasis-core/go/common/crypto/signature"
"github.com/oasisprotocol/oasis-core/go/common/version"
"github.com/oasisprotocol/oasis-core/go/consensus/api/transaction"
"github.com/oasisprotocol/oasis-core/go/oasis-node/cmd/common/flags"
)
Expand Down Expand Up @@ -42,6 +43,25 @@ type Parameters struct { // nolint: maligned

// PublicKeyBlacklist is the network-wide public key blacklist.
PublicKeyBlacklist []signature.PublicKey `json:"public_key_blacklist,omitempty"`

// FeatureVersion represents the latest consensus-breaking software version
// that follows calendar versioning (yy.minor[.micro]).
FeatureVersion *version.Version `json:"feature_version,omitempty"`
}

// IsFeatureVersion returns true iff the consensus feature version is high
// enough for the feature to be enabled.
func (p *Parameters) IsFeatureVersion(minVersion string) (bool, error) {
mimFeatureVersion, err := version.FromString(minVersion)
if err != nil {
return false, err
}

if p.FeatureVersion == nil {
return false, nil
}

return p.FeatureVersion.ToU64() >= mimFeatureVersion.ToU64(), nil
}

const (
Expand Down
16 changes: 16 additions & 0 deletions go/oasis-node/cmd/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/oasisprotocol/oasis-core/go/common/logging"
"github.com/oasisprotocol/oasis-core/go/common/node"
"github.com/oasisprotocol/oasis-core/go/common/quantity"
"github.com/oasisprotocol/oasis-core/go/common/version"
consensus "github.com/oasisprotocol/oasis-core/go/consensus/api"
"github.com/oasisprotocol/oasis-core/go/consensus/api/transaction"
cmt "github.com/oasisprotocol/oasis-core/go/consensus/cometbft/api"
Expand Down Expand Up @@ -115,6 +116,7 @@ const (
CfgConsensusStateCheckpointChunkSize = "consensus.state_checkpoint.chunk_size"
CfgConsensusGasCostsTxByte = "consensus.gas_costs.tx_byte"
cfgConsensusBlacklistPublicKey = "consensus.blacklist_public_key"
CfgConsensusFeatureVersion = "consensus.feature_version"

// Consensus backend config flag.
CfgConsensusBackend = "consensus.backend"
Expand Down Expand Up @@ -284,6 +286,18 @@ func doInitGenesis(*cobra.Command, []string) {
return
}

var featureVersion *version.Version
if s := viper.GetString(CfgConsensusFeatureVersion); s != "" {
version, err := version.FromString(s)
if err != nil {
logger.Error("failed to parse consensus feature version",
"err", err,
)
return
}
featureVersion = &version
}

doc.Consensus = consensusGenesis.Genesis{
Backend: viper.GetString(CfgConsensusBackend),
Parameters: consensusGenesis.Parameters{
Expand All @@ -301,6 +315,7 @@ func doInitGenesis(*cobra.Command, []string) {
consensusGenesis.GasOpTxByte: transaction.Gas(viper.GetUint64(CfgConsensusGasCostsTxByte)),
},
PublicKeyBlacklist: pkBlacklist,
FeatureVersion: featureVersion,
},
}

Expand Down Expand Up @@ -863,6 +878,7 @@ func init() {
initGenesisFlags.String(CfgConsensusStateCheckpointChunkSize, "8mb", "consensus state checkpoint chunk size (in bytes)")
initGenesisFlags.Uint64(CfgConsensusGasCostsTxByte, 1, "consensus gas costs: each transaction byte")
initGenesisFlags.StringSlice(cfgConsensusBlacklistPublicKey, nil, "blacklist public key")
initGenesisFlags.String(CfgConsensusFeatureVersion, "", "latest consensus breaking software feature version")

// Consensus backend flag.
initGenesisFlags.String(CfgConsensusBackend, cmt.BackendName, "consensus backend")
Expand Down
1 change: 1 addition & 0 deletions go/oasis-test-runner/oasis/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ func (net *Network) MakeGenesis() error {
"--" + genesis.CfgConsensusGasCostsTxByte, strconv.FormatUint(uint64(net.cfg.Consensus.Parameters.GasCosts[consensusGenesis.GasOpTxByte]), 10),
"--" + genesis.CfgConsensusStateCheckpointInterval, strconv.FormatUint(net.cfg.Consensus.Parameters.StateCheckpointInterval, 10),
"--" + genesis.CfgConsensusStateCheckpointNumKept, strconv.FormatUint(net.cfg.Consensus.Parameters.StateCheckpointNumKept, 10),
"--" + genesis.CfgConsensusFeatureVersion, "100.0", // High enough to enable all features.
"--" + genesis.CfgStakingTokenSymbol, genesisTestHelpers.TestStakingTokenSymbol,
"--" + genesis.CfgStakingTokenValueExponent, strconv.FormatUint(uint64(genesisTestHelpers.TestStakingTokenValueExponent), 10),
"--" + genesis.CfgBeaconBackend, net.cfg.Beacon.Backend,
Expand Down

0 comments on commit 66af606

Please sign in to comment.