From ae954d012e0ba4b9798a2c5418f94966ca612d88 Mon Sep 17 00:00:00 2001 From: Jack Li Date: Sun, 24 Nov 2024 12:01:18 +0800 Subject: [PATCH] fix: use -1 as default for v1 selection algo --- cmd/themisd/service/service.go | 2 +- helper/config.go | 3 ++- metis/selection.go | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/themisd/service/service.go b/cmd/themisd/service/service.go index e04e155..38821c0 100644 --- a/cmd/themisd/service/service.go +++ b/cmd/themisd/service/service.go @@ -323,7 +323,7 @@ which accepts a path for the resulting pprof file. FlagMinGasPrices, "", "Minimum gas prices to accept for transactions; Any fee in a tx must meet this minimum (e.g. 0.01photino;0.0001stake)", ) - cmd.Flags().Uint64(FlagSelectionAlgoV1Height, 0, "Height at which to switch to election algorithm v1") + cmd.Flags().Int64(FlagSelectionAlgoV1Height, -1, "Height at which to switch to election algorithm v1") cmd.Flags().Uint64(FlagHaltHeight, 0, "Height at which to gracefully halt the chain and shutdown the node") cmd.Flags().Uint64(FlagHaltTime, 0, "Minimum block time (in Unix seconds) at which to gracefully halt the chain and shutdown the node") cmd.Flags().String(flagCPUProfile, "", "Enable CPU profiling and write to the provided file") diff --git a/helper/config.go b/helper/config.go index 58fffc6..37d036d 100644 --- a/helper/config.go +++ b/helper/config.go @@ -216,7 +216,7 @@ var Logger logger.Logger // GenesisDoc contains the genesis file var GenesisDoc tmTypes.GenesisDoc -var newSelectionAlgoHeight int64 = 0 +var newSelectionAlgoHeight int64 = -1 var spanOverrideHeight int64 = 0 @@ -366,6 +366,7 @@ func InitThemisConfigWith(homeDir string, themisConfigFileFromFLag string) { spanOverrideHeight = 0 } + panic(conf.SelectionAlgoV1Height) } // GetDefaultThemisConfig returns configration with default params diff --git a/metis/selection.go b/metis/selection.go index 2921ebf..06c4a4c 100644 --- a/metis/selection.go +++ b/metis/selection.go @@ -87,7 +87,7 @@ func SelectNextProducers(ctx sdk.Context, blkHash common.Hash, spanEligibleValid */ var targetWeight uint64 - if ctx.BlockHeight() < helper.GetNewSelectionAlgoHeight() { + if helper.GetNewSelectionAlgoHeight() < 0 || ctx.BlockHeight() < helper.GetNewSelectionAlgoHeight() { targetWeight = randomRangeInclusive(1, totalVotingPower) ctx.Logger().Debug("Selecting new proposer", "algoVersion", 0, "totalVotingPower", totalVotingPower, "targetWeight", targetWeight,