Skip to content

Commit

Permalink
Merge pull request #5203 from oasisprotocol/kostko/stable/22.2.x/back…
Browse files Browse the repository at this point in the history
…port-5200

[BACKPORT/22.2.x] Move halt epoch from genesis to node-local configuration
  • Loading branch information
kostko authored Feb 27, 2023
2 parents 1839b9f + 26f1e17 commit c06a5d8
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 47 deletions.
1 change: 1 addition & 0 deletions .changelog/5200.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Move halt epoch from genesis to node-local configuration
14 changes: 7 additions & 7 deletions go/consensus/tendermint/abci/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ var (

// ApplicationConfig is the configuration for the consensus application.
type ApplicationConfig struct { // nolint: maligned
DataDir string
StorageBackend string
Pruning PruneConfig
HaltEpochHeight beacon.EpochTime
HaltBlockHeight uint64
MinGasPrice uint64
DataDir string
StorageBackend string
Pruning PruneConfig
HaltEpoch beacon.EpochTime
HaltHeight uint64
MinGasPrice uint64

DisableCheckpointer bool
CheckpointerCheckInterval time.Duration
Expand Down Expand Up @@ -440,7 +440,7 @@ func (mux *abciMux) BeginBlock(req types.RequestBeginBlock) types.ResponseBeginB
// On transition, trigger halt hooks.
mux.logger.Info("BeginBlock: halt mode transition, emitting empty block",
"block_height", blockHeight,
"epoch", mux.state.haltEpochHeight,
"epoch", currentEpoch,
)
mux.logger.Debug("dispatching halt hooks before halt point")
mux.dispatchHaltHooks(blockHeight, currentEpoch, nil)
Expand Down
18 changes: 9 additions & 9 deletions go/consensus/tendermint/abci/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ type applicationState struct { // nolint: maligned

timeSource beacon.Backend

haltMode bool
haltEpochHeight beacon.EpochTime
haltBlockHeight uint64
haltMode bool
haltEpoch beacon.EpochTime
haltHeight uint64

minGasPrice quantity.Quantity
ownTxSigner signature.PublicKey
Expand Down Expand Up @@ -259,13 +259,13 @@ func (s *applicationState) shouldHalt(ctx *api.Context) bool {
// If there is a halt block height configured, and the height(+1)
// is greater than or equal to the height point, transition into
// the halting state.
if s.haltBlockHeight != 0 && uint64(h) >= s.haltBlockHeight {
if s.haltHeight != 0 && uint64(h) >= s.haltHeight {
s.logger.Info("shouldHalt: reached halt block height",
"block_height", h,
"halt_block_height", s.haltBlockHeight,
"halt_block_height", s.haltHeight,
)
s.haltMode = true
} else {
} else if s.haltEpoch > 0 {
// Otherwise, check to see if the epoch will be equal to
// the halt epoch (if any).
currentEpoch, err := s.GetEpoch(ctx, h)
Expand All @@ -276,7 +276,7 @@ func (s *applicationState) shouldHalt(ctx *api.Context) bool {
)
return false
}
s.haltMode = currentEpoch == s.haltEpochHeight
s.haltMode = currentEpoch == s.haltEpoch
}

return s.haltMode
Expand Down Expand Up @@ -589,8 +589,8 @@ func newApplicationState(ctx context.Context, upgrader upgrade.Backend, cfg *App
prunerNotifyCh: channels.NewRingChannel(1),
pruneInterval: cfg.Pruning.PruneInterval,
upgrader: upgrader,
haltEpochHeight: cfg.HaltEpochHeight,
haltBlockHeight: cfg.HaltBlockHeight,
haltEpoch: cfg.HaltEpoch,
haltHeight: cfg.HaltHeight,
minGasPrice: minGasPrice,
ownTxSigner: cfg.OwnTxSigner,
ownTxSignerAddress: staking.NewAddress(cfg.OwnTxSigner),
Expand Down
1 change: 0 additions & 1 deletion go/consensus/tendermint/full/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ func NewArchive(
Strategy: abci.PruneNone,
PruneInterval: time.Hour * 100, // Irrelevant as pruning is disabled.
},
HaltEpochHeight: srv.genesis.HaltEpoch,
OwnTxSigner: srv.identity.NodeSigner.Public(),
DisableCheckpointer: true,
InitialHeight: uint64(srv.genesis.Height),
Expand Down
9 changes: 6 additions & 3 deletions go/consensus/tendermint/full/full.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ const (

// CfgHaltHeight is the block height at which the local node should be shutdown.
CfgHaltHeight = "consensus.tendermint.halt_height"
// CfgHaltEpoch is the epoch at which the local node should be shutdown.
CfgHaltEpoch = "consensus.tendermint.halt_epoch"
)

const (
Expand Down Expand Up @@ -579,8 +581,8 @@ func (t *fullService) lazyInit() error {
DataDir: filepath.Join(t.dataDir, tmcommon.StateDir),
StorageBackend: db.GetBackendName(),
Pruning: pruneCfg,
HaltEpochHeight: t.genesis.HaltEpoch,
HaltBlockHeight: viper.GetUint64(CfgHaltHeight),
HaltEpoch: beaconAPI.EpochTime(viper.GetUint64(CfgHaltEpoch)),
HaltHeight: viper.GetUint64(CfgHaltHeight),
MinGasPrice: viper.GetUint64(CfgMinGasPrice),
OwnTxSigner: t.identity.NodeSigner.Public(),
DisableCheckpointer: viper.GetBool(CfgCheckpointerDisabled),
Expand Down Expand Up @@ -1015,7 +1017,8 @@ func init() {
Flags.Bool(CfgSupplementarySanityEnabled, false, "enable supplementary sanity checks (slows down consensus)")
Flags.Uint64(CfgSupplementarySanityInterval, 10, "supplementary sanity check interval (in blocks)")

Flags.Uint64(CfgHaltHeight, 0, "height at which to force-shutdown the node (in blocks)")
Flags.Uint64(CfgHaltHeight, 0, "height at which to force-shutdown the node (in blocks, zero to disable)")
Flags.Uint64(CfgHaltEpoch, 0, "epoch at which to force-shutdown the node (in epochs, zero to disable)")

// State sync.
Flags.Bool(CfgConsensusStateSyncEnabled, false, "enable state sync")
Expand Down
8 changes: 8 additions & 0 deletions go/oasis-test-runner/oasis/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/oasisprotocol/oasis-core/go/common/quantity"
"github.com/oasisprotocol/oasis-core/go/consensus/api/transaction"
consensusGenesis "github.com/oasisprotocol/oasis-core/go/consensus/genesis"
tendermintFull "github.com/oasisprotocol/oasis-core/go/consensus/tendermint/full"
genesisFile "github.com/oasisprotocol/oasis-core/go/genesis/file"
genesisTestHelpers "github.com/oasisprotocol/oasis-core/go/genesis/tests"
governance "github.com/oasisprotocol/oasis-core/go/governance/api"
Expand Down Expand Up @@ -614,6 +615,13 @@ func (net *Network) startOasisNode(
tendermintDebugAddrBookLenient().
tendermintDebugAllowDuplicateIP().
tendermintUpgradeStopDelay(10 * time.Second)

if haltEpoch := net.cfg.HaltEpoch; haltEpoch > 0 {
extraArgs = extraArgs.extraArgs([]Argument{{
Name: tendermintFull.CfgHaltEpoch,
Values: []string{strconv.FormatUint(haltEpoch, 10)},
}})
}
}
if net.cfg.UseShortGrpcSocketPaths {
// Keep the socket, if it was already generated!
Expand Down
8 changes: 4 additions & 4 deletions go/oasis-test-runner/scenario/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,15 @@ func (sc *E2E) DumpRestoreNetwork(
}
}

// If network is used, enable shorter per-node socket paths, because some e2e test datadir
// exceed maximum unix socket path length.
fixture.Network.UseShortGrpcSocketPaths = true

var err error
if sc.Net, err = fixture.Create(childEnv); err != nil {
return err
}

// If network is used, enable shorter per-node socket paths, because some e2e test datadir
// exceed maximum unix socket path length.
sc.Net.Config().UseShortGrpcSocketPaths = true

return nil
}

Expand Down
21 changes: 6 additions & 15 deletions go/oasis-test-runner/scenario/e2e/runtime/halt_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package runtime
import (
"context"
"fmt"
"math"
"reflect"

beacon "github.com/oasisprotocol/oasis-core/go/beacon/api"
Expand Down Expand Up @@ -168,8 +167,7 @@ func (sc *haltRestoreImpl) Run(childEnv *env.Env) error { // nolint: gocyclo
// works with restored state.
sc.Logger.Info("starting the network again")

// Update halt epoch in the exported genesis so the network doesn't
// instantly halt.
// Ensure compute runtime in genesis is in expected state.
genesisFileProvider, err := genesis.NewFileProvider(files[0])
if err != nil {
sc.Logger.Error("failed getting genesis file provider",
Expand All @@ -185,15 +183,7 @@ func (sc *haltRestoreImpl) Run(childEnv *env.Env) error { // nolint: gocyclo
)
return err
}
genesisDoc.HaltEpoch = math.MaxUint64
if err = genesisDoc.WriteFileJSON(files[0]); err != nil {
sc.Logger.Error("failed to update genesis",
"err", err,
)
return err
}

// Ensure compute runtime in genesis is in expected state.
var rtList []*registry.Runtime
switch sc.suspendRuntime {
case true:
Expand All @@ -217,19 +207,20 @@ func (sc *haltRestoreImpl) Run(childEnv *env.Env) error { // nolint: gocyclo
return fmt.Errorf("runtime not in expected state")
}

// Disable halt epoch so the network doesn't instantly halt.
fixture.Network.HaltEpoch = 0
// Use the updated genesis file.
fixture.Network.GenesisFile = files[0]
// Make sure to not overwrite the entity.
fixture.Entities[1].Restore = true
// If network is used, enable shorter per-node socket paths, because some e2e test datadir
// exceed maximum unix socket path length.
fixture.Network.UseShortGrpcSocketPaths = true

if sc.Net, err = fixture.Create(childEnv); err != nil {
return err
}

// If network is used, enable shorter per-node socket paths, because some e2e test datadir exceed maximum unix
// socket path length.
sc.Net.Config().UseShortGrpcSocketPaths = true

newTestClient := sc.testClient.Clone().(*LongTermTestClient)
sc.runtimeImpl.testClient = newTestClient.WithMode(ModePart2).WithSeed("second_seed")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package runtime
import (
"context"
"fmt"
"math"
"reflect"

genesis "github.com/oasisprotocol/oasis-core/go/genesis/file"
Expand Down Expand Up @@ -97,8 +96,7 @@ func (sc *haltRestoreNonMockImpl) Run(childEnv *env.Env) error { // nolint: gocy
// works with restored state.
sc.Logger.Info("starting the network again")

// Update halt epoch in the exported genesis so the network doesn't
// instantly halt.
// Update genesis file.
genesisFileProvider, err := genesis.NewFileProvider(files[0])
if err != nil {
sc.Logger.Error("failed getting genesis file provider",
Expand All @@ -114,7 +112,6 @@ func (sc *haltRestoreNonMockImpl) Run(childEnv *env.Env) error { // nolint: gocy
)
return err
}
genesisDoc.HaltEpoch = math.MaxUint64
genesisDoc.Beacon.Parameters.VRFParameters.Interval -= 5 // Reduce interval.
if err = genesisDoc.WriteFileJSON(files[0]); err != nil {
sc.Logger.Error("failed to update genesis",
Expand All @@ -123,19 +120,20 @@ func (sc *haltRestoreNonMockImpl) Run(childEnv *env.Env) error { // nolint: gocy
return err
}

// Disable halt epoch so the network doesn't instantly halt.
fixture.Network.HaltEpoch = 0
// Use the updated genesis file.
fixture.Network.GenesisFile = files[0]
// Make sure to not overwrite the entity.
fixture.Entities[1].Restore = true
// If network is used, enable shorter per-node socket paths, because some e2e test datadir
// exceed maximum unix socket path length.
fixture.Network.UseShortGrpcSocketPaths = true

if sc.Net, err = fixture.Create(childEnv); err != nil {
return err
}

// If network is used, enable shorter per-node socket paths, because some e2e test datadir
// exceed maximum unix socket path length.
sc.Net.Config().UseShortGrpcSocketPaths = true

newTestClient := sc.testClient.Clone().(*LongTermTestClient)
sc.runtimeImpl.testClient = newTestClient.WithMode(ModePart2).WithSeed("second_seed")

Expand Down

0 comments on commit c06a5d8

Please sign in to comment.