From c91444b32e7a42f63813fcced36a3aa12ee4a488 Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Tue, 14 May 2024 13:00:01 +0300 Subject: [PATCH 1/2] cleanup proposal misses --- process/scToProtocol/stakingToPeer.go | 6 ++++-- state/interface.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/process/scToProtocol/stakingToPeer.go b/process/scToProtocol/stakingToPeer.go index e9b166b52ea..b0a0d973786 100644 --- a/process/scToProtocol/stakingToPeer.go +++ b/process/scToProtocol/stakingToPeer.go @@ -11,14 +11,15 @@ import ( "github.com/multiversx/mx-chain-core-go/data/smartContractResult" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + "github.com/multiversx/mx-chain-logger-go" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/vm" "github.com/multiversx/mx-chain-go/vm/systemSmartContracts" - "github.com/multiversx/mx-chain-logger-go" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) var _ process.SmartContractToProtocolHandler = (*stakingToPeer)(nil) @@ -341,6 +342,7 @@ func (stp *stakingToPeer) updatePeerState( if account.GetTempRating() < stp.unJailRating { log.Debug("node is unJailed, setting temp rating to start rating", "blsKey", blsPubKey) account.SetTempRating(stp.unJailRating) + account.SetConsecutiveProposerMisses(0) } isNewValidator := !isValidator && stakingData.Staked diff --git a/state/interface.go b/state/interface.go index d78c6e90997..a5766b6fffc 100644 --- a/state/interface.go +++ b/state/interface.go @@ -59,7 +59,7 @@ type PeerAccountHandler interface { GetTempRating() uint32 SetTempRating(uint32) GetConsecutiveProposerMisses() uint32 - SetConsecutiveProposerMisses(uint322 uint32) + SetConsecutiveProposerMisses(consecutiveMisses uint32) ResetAtNewEpoch() SetPreviousList(list string) vmcommon.AccountHandler From 288012b6e12eaff2b040cd1d3432536fbc10a9bf Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Tue, 21 May 2024 14:06:59 +0300 Subject: [PATCH 2/2] add activation flag for unjail cleanup backwards compatibility --- cmd/node/config/enableEpochs.toml | 3 +++ common/constants.go | 1 + common/enablers/enableEpochsHandler.go | 9 ++++++++- config/epochConfig.go | 1 + process/scToProtocol/stakingToPeer.go | 5 ++++- 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index 657d365fdc9..b5ece669247 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -314,6 +314,9 @@ # CryptoOpcodesV2EnableEpoch represents the epoch when BLSMultiSig, Secp256r1 and other opcodes are enabled CryptoOpcodesV2EnableEpoch = 4 + # UnjailCleanupEnableEpoch represents the epoch when the cleanup of the unjailed nodes is enabled + UnJailCleanupEnableEpoch = 4 + # BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers BLSMultiSignerEnableEpoch = [ { EnableEpoch = 0, Type = "no-KOSK" }, diff --git a/common/constants.go b/common/constants.go index 13fedb7e0bd..53f6d461412 100644 --- a/common/constants.go +++ b/common/constants.go @@ -1016,5 +1016,6 @@ const ( DynamicESDTFlag core.EnableEpochFlag = "DynamicEsdtFlag" EGLDInESDTMultiTransferFlag core.EnableEpochFlag = "EGLDInESDTMultiTransferFlag" CryptoOpcodesV2Flag core.EnableEpochFlag = "CryptoOpcodesV2Flag" + UnJailCleanupFlag core.EnableEpochFlag = "UnJailCleanupFlag" // all new flags must be added to createAllFlagsMap method, as part of enableEpochsHandler allFlagsDefined ) diff --git a/common/enablers/enableEpochsHandler.go b/common/enablers/enableEpochsHandler.go index efe8b4f304d..5313fb90972 100644 --- a/common/enablers/enableEpochsHandler.go +++ b/common/enablers/enableEpochsHandler.go @@ -6,10 +6,11 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/process" - logger "github.com/multiversx/mx-chain-logger-go" ) var log = logger.GetOrCreate("common/enablers") @@ -743,6 +744,12 @@ func (handler *enableEpochsHandler) createAllFlagsMap() { }, activationEpoch: handler.enableEpochsConfig.CryptoOpcodesV2EnableEpoch, }, + common.UnJailCleanupFlag: { + isActiveInEpoch: func(epoch uint32) bool { + return epoch >= handler.enableEpochsConfig.UnJailCleanupEnableEpoch + }, + activationEpoch: handler.enableEpochsConfig.UnJailCleanupEnableEpoch, + }, } } diff --git a/config/epochConfig.go b/config/epochConfig.go index 5f5f4ff7a0e..62191f0fe82 100644 --- a/config/epochConfig.go +++ b/config/epochConfig.go @@ -116,6 +116,7 @@ type EnableEpochs struct { DynamicESDTEnableEpoch uint32 EGLDInMultiTransferEnableEpoch uint32 CryptoOpcodesV2EnableEpoch uint32 + UnJailCleanupEnableEpoch uint32 BLSMultiSignerEnableEpoch []MultiSignerConfig } diff --git a/process/scToProtocol/stakingToPeer.go b/process/scToProtocol/stakingToPeer.go index b0a0d973786..363a7975a7a 100644 --- a/process/scToProtocol/stakingToPeer.go +++ b/process/scToProtocol/stakingToPeer.go @@ -110,6 +110,7 @@ func checkIfNil(args ArgStakingToPeer) error { return core.CheckHandlerCompatibility(args.EnableEpochsHandler, []core.EnableEpochFlag{ common.StakeFlag, common.ValidatorToDelegationFlag, + common.UnJailCleanupFlag, }) } @@ -342,7 +343,9 @@ func (stp *stakingToPeer) updatePeerState( if account.GetTempRating() < stp.unJailRating { log.Debug("node is unJailed, setting temp rating to start rating", "blsKey", blsPubKey) account.SetTempRating(stp.unJailRating) - account.SetConsecutiveProposerMisses(0) + if stp.enableEpochsHandler.IsFlagEnabled(common.UnJailCleanupFlag) { + account.SetConsecutiveProposerMisses(0) + } } isNewValidator := !isValidator && stakingData.Staked