diff --git a/cmd/sovereignnode/chainSimulator/sovereignChainSimulator.go b/cmd/sovereignnode/chainSimulator/sovereignChainSimulator.go index 39a261dd35b..042e185f971 100644 --- a/cmd/sovereignnode/chainSimulator/sovereignChainSimulator.go +++ b/cmd/sovereignnode/chainSimulator/sovereignChainSimulator.go @@ -53,7 +53,7 @@ func NewSovereignChainSimulator(args ArgsSovereignChainSimulator) (chainSimulato } args.CreateRunTypeCoreComponents = func() (factory.RunTypeCoreComponentsHolder, error) { - return createSovereignRunTypeCoreComponents() + return createSovereignRunTypeCoreComponents(*configs.SovereignEpochConfig) } args.CreateIncomingHeaderSubscriber = func(config config.WebSocketConfig, dataPool dataRetriever.PoolsHolder, mainChainNotarizationStartRound uint64, runTypeComponents factory.RunTypeComponentsHolder) (process.IncomingHeaderSubscriber, error) { return incomingHeader.CreateIncomingHeaderProcessor(config, dataPool, mainChainNotarizationStartRound, runTypeComponents) @@ -86,17 +86,23 @@ func loadSovereignConfigs(configsPath string) (*sovereignConfig.SovereignConfig, return nil, err } + sovereignEpochConfig, err := sovereignConfig.LoadSovereignEpochConfig(path.Join(configsPath, "enableEpochs.toml")) + if err != nil { + return nil, err + } + return &sovereignConfig.SovereignConfig{ Configs: &config.Configs{ EpochConfig: epochConfig, EconomicsConfig: economicsConfig, }, SovereignExtraConfig: sovereignExtraConfig, + SovereignEpochConfig: sovereignEpochConfig, }, nil } -func createSovereignRunTypeCoreComponents() (factory.RunTypeCoreComponentsHolder, error) { - sovereignRunTypeCoreComponentsFactory := runType.NewSovereignRunTypeCoreComponentsFactory() +func createSovereignRunTypeCoreComponents(sovereignEpochConfig config.SovereignEpochConfig) (factory.RunTypeCoreComponentsHolder, error) { + sovereignRunTypeCoreComponentsFactory := runType.NewSovereignRunTypeCoreComponentsFactory(sovereignEpochConfig) managedRunTypeCoreComponents, err := runType.NewManagedRunTypeCoreComponents(sovereignRunTypeCoreComponentsFactory) if err != nil { return nil, err diff --git a/cmd/sovereignnode/chainSimulator/sovereignChainSimulator_test.go b/cmd/sovereignnode/chainSimulator/sovereignChainSimulator_test.go index 4715334f191..b5f68cff53b 100644 --- a/cmd/sovereignnode/chainSimulator/sovereignChainSimulator_test.go +++ b/cmd/sovereignnode/chainSimulator/sovereignChainSimulator_test.go @@ -4,13 +4,13 @@ import ( "testing" "time" + "github.com/multiversx/mx-chain-core-go/core" + "github.com/stretchr/testify/require" + chainSimulatorCommon "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" chainSim "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" - - "github.com/multiversx/mx-chain-core-go/core" - "github.com/stretchr/testify/require" ) const ( @@ -57,9 +57,12 @@ func TestChainSimulator_GenerateBlocksShouldWork(t *testing.T) { PathToInitialConfig: defaultPathToInitialConfig, GenesisTimestamp: time.Now().Unix(), RoundDurationInMillis: uint64(6000), - RoundsPerEpoch: core.OptionalUint64{}, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 2, + RoundsPerEpoch: core.OptionalUint64{ + HasValue: true, + Value: 20, + }, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 2, }, }) require.Nil(t, err) diff --git a/cmd/sovereignnode/config/common.go b/cmd/sovereignnode/config/common.go index 59c6139791d..7976b37768d 100644 --- a/cmd/sovereignnode/config/common.go +++ b/cmd/sovereignnode/config/common.go @@ -2,6 +2,7 @@ package config import ( "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-go/config" ) @@ -15,3 +16,14 @@ func LoadSovereignGeneralConfig(filepath string) (*config.SovereignConfig, error return cfg, nil } + +// LoadSovereignEpochConfig returns the epoch config necessary by sovereign by reading it from the provided file +func LoadSovereignEpochConfig(filepath string) (*config.SovereignEpochConfig, error) { + cfg := &config.SovereignEpochConfig{} + err := core.LoadTomlFile(cfg, filepath) + if err != nil { + return nil, err + } + + return cfg, nil +} diff --git a/cmd/sovereignnode/config/config.go b/cmd/sovereignnode/config/config.go index 41b146814b7..5b34c6064be 100644 --- a/cmd/sovereignnode/config/config.go +++ b/cmd/sovereignnode/config/config.go @@ -6,4 +6,5 @@ import "github.com/multiversx/mx-chain-go/config" type SovereignConfig struct { *config.Configs SovereignExtraConfig *config.SovereignConfig + SovereignEpochConfig *config.SovereignEpochConfig } diff --git a/cmd/sovereignnode/config/enableEpochs.toml b/cmd/sovereignnode/config/enableEpochs.toml index eab8edf5055..ea0836b4741 100644 --- a/cmd/sovereignnode/config/enableEpochs.toml +++ b/cmd/sovereignnode/config/enableEpochs.toml @@ -6,7 +6,7 @@ BuiltInFunctionsEnableEpoch = 0 # RelayedTransactionsEnableEpoch represents the epoch when the relayed transactions will be enabled - RelayedTransactionsEnableEpoch = 1 + RelayedTransactionsEnableEpoch = 0 # PenalizedTooMuchGasEnableEpoch represents the epoch when the penalization for using too much gas will be enabled PenalizedTooMuchGasEnableEpoch = 0 @@ -19,35 +19,35 @@ # SwitchHysteresisForMinNodesEnableEpoch represents the epoch when the system smart contract changes its config to consider # also (minimum) hysteresis nodes for the minimum number of nodes - SwitchHysteresisForMinNodesEnableEpoch = 1 + SwitchHysteresisForMinNodesEnableEpoch = 0 # TransactionSignedWithTxHashEnableEpoch represents the epoch when the node will also accept transactions that are # signed with the hash of transaction TransactionSignedWithTxHashEnableEpoch = 0 # MetaProtectionEnableEpoch represents the epoch when the transactions to the metachain are checked to have enough gas - MetaProtectionEnableEpoch = 1 + MetaProtectionEnableEpoch = 0 # AheadOfTimeGasUsageEnableEpoch represents the epoch when the cost of smart contract prepare changes from compiler per byte to ahead of time prepare per byte - AheadOfTimeGasUsageEnableEpoch = 1 + AheadOfTimeGasUsageEnableEpoch = 0 # GasPriceModifierEnableEpoch represents the epoch when the gas price modifier in fee computation is enabled - GasPriceModifierEnableEpoch = 1 + GasPriceModifierEnableEpoch = 0 # RepairCallbackEnableEpoch represents the epoch when the callback repair is activated for scrs - RepairCallbackEnableEpoch = 1 + RepairCallbackEnableEpoch = 0 # BlockGasAndFeesReCheckEnableEpoch represents the epoch when gas and fees used in each created or processed block are re-checked - BlockGasAndFeesReCheckEnableEpoch = 1 + BlockGasAndFeesReCheckEnableEpoch = 0 # BalanceWaitingListsEnableEpoch represents the epoch when the shard waiting lists are balanced at the start of an epoch - BalanceWaitingListsEnableEpoch = 1 + BalanceWaitingListsEnableEpoch = 0 # ReturnDataToLastTransferEnableEpoch represents the epoch when returned data is added to last output transfer for callbacks - ReturnDataToLastTransferEnableEpoch = 1 + ReturnDataToLastTransferEnableEpoch = 0 # SenderInOutTransferEnableEpoch represents the epoch when the feature of having different senders in output transfer is enabled - SenderInOutTransferEnableEpoch = 1 + SenderInOutTransferEnableEpoch = 0 # StakeEnableEpoch represents the epoch when staking is enabled StakeEnableEpoch = 0 @@ -56,7 +56,7 @@ StakingV2EnableEpoch = 0 # DoubleKeyProtectionEnableEpoch represents the epoch when the double key protection will be enabled - DoubleKeyProtectionEnableEpoch = 1 + DoubleKeyProtectionEnableEpoch = 0 # ESDTEnableEpoch represents the epoch when ESDT is enabled ESDTEnableEpoch = 0 @@ -70,33 +70,32 @@ # DelegationSmartContractEnableEpoch represents the epoch when delegation smart contract is enabled # epoch should not be 0 - DelegationSmartContractEnableEpoch = 1 + DelegationSmartContractEnableEpoch = 0 - # TODO: MX-15702: Sovereign enable epoch handler should have all these type of flags always disabled # CorrectLastUnjailedEnableEpoch represents the epoch when the fix regaring the last unjailed node should apply - CorrectLastUnjailedEnableEpoch = 1000000 + CorrectLastUnjailedEnableEpoch = 0 # RelayedTransactionsV2EnableEpoch represents the epoch when the relayed transactions V2 will be enabled - RelayedTransactionsV2EnableEpoch = 1 + RelayedTransactionsV2EnableEpoch = 0 # UnbondTokensV2EnableEpoch represents the epoch when the new implementation of the unbond tokens function is available - UnbondTokensV2EnableEpoch = 1 + UnbondTokensV2EnableEpoch = 0 # SaveJailedAlwaysEnableEpoch represents the epoch when saving jailed status at end of epoch will happen in all cases - SaveJailedAlwaysEnableEpoch = 1 + SaveJailedAlwaysEnableEpoch = 0 # ReDelegateBelowMinCheckEnableEpoch represents the epoch when the check for the re-delegated value will be enabled - ReDelegateBelowMinCheckEnableEpoch = 1 + ReDelegateBelowMinCheckEnableEpoch = 0 # ValidatorToDelegationEnableEpoch represents the epoch when the validator-to-delegation feature will be enabled - ValidatorToDelegationEnableEpoch = 1 + ValidatorToDelegationEnableEpoch = 0 # WaitingListFixEnableEpoch represents the epoch when the 6 epoch waiting list fix is enabled - WaitingListFixEnableEpoch = 1000000 + WaitingListFixEnableEpoch = 0 # IncrementSCRNonceInMultiTransferEnableEpoch represents the epoch when the fix for preventing the generation of the same SCRs # is enabled. The fix is done by adding an extra increment. - IncrementSCRNonceInMultiTransferEnableEpoch = 1 + IncrementSCRNonceInMultiTransferEnableEpoch = 0 # ESDTMultiTransferEnableEpoch represents the epoch when esdt multitransfer built in function is enabled ESDTMultiTransferEnableEpoch = 0 @@ -107,17 +106,14 @@ # ESDTTransferRoleEnableEpoch represents the epoch when esdt transfer role set is enabled ESDTTransferRoleEnableEpoch = 0 - # BuiltInFunctionOnMetaEnableEpoch represents the epoch when built in function processing on metachain is enabled - BuiltInFunctionOnMetaEnableEpoch = 1000000 - # ComputeRewardCheckpointEnableEpoch represents the epoch when compute rewards checkpoint epoch is enabled - ComputeRewardCheckpointEnableEpoch = 1 + ComputeRewardCheckpointEnableEpoch = 0 # SCRSizeInvariantCheckEnableEpoch represents the epoch when the scr size invariant check is enabled - SCRSizeInvariantCheckEnableEpoch = 1 + SCRSizeInvariantCheckEnableEpoch = 0 # BackwardCompSaveKeyValueEnableEpoch represents the epoch when the backward compatibility for save key value error is enabled - BackwardCompSaveKeyValueEnableEpoch = 1 + BackwardCompSaveKeyValueEnableEpoch = 0 # ESDTNFTCreateOnMultiShardEnableEpoch represents the epoch when esdt nft creation is enabled on multiple shards ESDTNFTCreateOnMultiShardEnableEpoch = 0 @@ -126,37 +122,37 @@ MetaESDTSetEnableEpoch = 0 # AddTokensToDelegationEnableEpoch represents the epoch when adding tokens to delegation is enabled for whitelisted address - AddTokensToDelegationEnableEpoch = 1 + AddTokensToDelegationEnableEpoch = 0 # MultiESDTTransferFixOnCallBackOnEnableEpoch represents the epoch when multi esdt transfer on callback fix is enabled MultiESDTTransferFixOnCallBackOnEnableEpoch = 0 # OptimizeGasUsedInCrossMiniBlocksEnableEpoch represents the epoch when gas used in cross shard mini blocks will be optimized - OptimizeGasUsedInCrossMiniBlocksEnableEpoch = 1 + OptimizeGasUsedInCrossMiniBlocksEnableEpoch = 0 # CorrectFirstQueuedEpoch represents the epoch when the backward compatibility for setting the first queued node is enabled - CorrectFirstQueuedEpoch = 1 + CorrectFirstQueuedEpoch = 0 # DeleteDelegatorAfterClaimRewardsEnableEpoch represents the epoch when the delegators data is deleted for delegators that have to claim rewards after they withdraw all funds - DeleteDelegatorAfterClaimRewardsEnableEpoch = 1 + DeleteDelegatorAfterClaimRewardsEnableEpoch = 0 # FixOOGReturnCodeEnableEpoch represents the epoch when the backward compatibility returning out of gas error is enabled - FixOOGReturnCodeEnableEpoch = 1 + FixOOGReturnCodeEnableEpoch = 0 # RemoveNonUpdatedStorageEnableEpoch represents the epoch when the backward compatibility for removing non updated storage is enabled - RemoveNonUpdatedStorageEnableEpoch = 1 + RemoveNonUpdatedStorageEnableEpoch = 0 # OptimizeNFTStoreEnableEpoch represents the epoch when optimizations on NFT metadata store and send are enabled OptimizeNFTStoreEnableEpoch = 0 # CreateNFTThroughExecByCallerEnableEpoch represents the epoch when nft creation through execution on destination by caller is enabled - CreateNFTThroughExecByCallerEnableEpoch = 1 + CreateNFTThroughExecByCallerEnableEpoch = 0 # StopDecreasingValidatorRatingWhenStuckEnableEpoch represents the epoch when we should stop decreasing validator's rating if, for instance, a shard gets stuck - StopDecreasingValidatorRatingWhenStuckEnableEpoch = 1 + StopDecreasingValidatorRatingWhenStuckEnableEpoch = 0 # FrontRunningProtectionEnableEpoch represents the epoch when the first version of protection against front running is enabled - FrontRunningProtectionEnableEpoch = 1 + FrontRunningProtectionEnableEpoch = 0 # IsPayableBySCEnableEpoch represents the epoch when a new flag isPayable by SC is enabled IsPayableBySCEnableEpoch = 0 @@ -168,7 +164,7 @@ StorageAPICostOptimizationEnableEpoch = 0 # TransformToMultiShardCreateEnableEpoch represents the epoch when the new function on esdt system sc is enabled to transfer create role into multishard - TransformToMultiShardCreateEnableEpoch = 1 + TransformToMultiShardCreateEnableEpoch = 0 # ESDTRegisterAndSetAllRolesEnableEpoch represents the epoch when new function to register tickerID and set all roles is enabled ESDTRegisterAndSetAllRolesEnableEpoch = 0 @@ -177,71 +173,71 @@ ScheduledMiniBlocksEnableEpoch = 0 # CorrectJailedNotUnstakedEpoch represents the epoch when the jailed validators will also be unstaked if the queue is empty - CorrectJailedNotUnstakedEmptyQueueEpoch = 1 + CorrectJailedNotUnstakedEmptyQueueEpoch = 0 # DoNotReturnOldBlockInBlockchainHookEnableEpoch represents the epoch when the fetch old block operation is # disabled in the blockchain hook component - DoNotReturnOldBlockInBlockchainHookEnableEpoch = 1 + DoNotReturnOldBlockInBlockchainHookEnableEpoch = 0 # AddFailedRelayedTxToInvalidMBsDisableEpoch represents the epoch when adding the failed relayed txs to invalid miniblocks is disabled - AddFailedRelayedTxToInvalidMBsDisableEpoch = 1 + AddFailedRelayedTxToInvalidMBsDisableEpoch = 0 # SCRSizeInvariantOnBuiltInResultEnableEpoch represents the epoch when scr size invariant on built in result is enabled - SCRSizeInvariantOnBuiltInResultEnableEpoch = 1 + SCRSizeInvariantOnBuiltInResultEnableEpoch = 0 # CheckCorrectTokenIDForTransferRoleEnableEpoch represents the epoch when the correct token ID check is applied for transfer role verification - CheckCorrectTokenIDForTransferRoleEnableEpoch = 1 + CheckCorrectTokenIDForTransferRoleEnableEpoch = 0 # DisableExecByCallerEnableEpoch represents the epoch when the check on value is disabled on exec by caller - DisableExecByCallerEnableEpoch = 1 + DisableExecByCallerEnableEpoch = 0 # RefactorContextEnableEpoch represents the epoch when refactoring/simplifying is enabled in contexts - RefactorContextEnableEpoch = 1 + RefactorContextEnableEpoch = 0 # FailExecutionOnEveryAPIErrorEnableEpoch represent the epoch when new protection in VM is enabled to fail all wrong API calls - FailExecutionOnEveryAPIErrorEnableEpoch = 1 + FailExecutionOnEveryAPIErrorEnableEpoch = 0 # ManagedCryptoAPIsEnableEpoch represents the epoch when new managed crypto APIs are enabled in the wasm VM - ManagedCryptoAPIsEnableEpoch = 1 + ManagedCryptoAPIsEnableEpoch = 0 # CheckFunctionArgumentEnableEpoch represents the epoch when the extra argument check is enabled in vm-common - CheckFunctionArgumentEnableEpoch = 1 + CheckFunctionArgumentEnableEpoch = 0 # CheckExecuteOnReadOnlyEnableEpoch represents the epoch when the extra checks are enabled for execution on read only - CheckExecuteOnReadOnlyEnableEpoch = 1 + CheckExecuteOnReadOnlyEnableEpoch = 0 # ESDTMetadataContinuousCleanupEnableEpoch represents the epoch when esdt metadata is automatically deleted according to inshard liquidity ESDTMetadataContinuousCleanupEnableEpoch = 0 # MiniBlockPartialExecutionEnableEpoch represents the epoch when mini block partial execution will be enabled - MiniBlockPartialExecutionEnableEpoch = 1 + MiniBlockPartialExecutionEnableEpoch = 0 # FixAsyncCallBackArgsListEnableEpoch represents the epoch when the async callback arguments lists fix will be enabled - FixAsyncCallBackArgsListEnableEpoch = 1 + FixAsyncCallBackArgsListEnableEpoch = 0 # FixOldTokenLiquidityEnableEpoch represents the epoch when the fix for old token liquidity is enabled FixOldTokenLiquidityEnableEpoch = 0 # RuntimeMemStoreLimitEnableEpoch represents the epoch when the condition for Runtime MemStore is enabled - RuntimeMemStoreLimitEnableEpoch = 1 + RuntimeMemStoreLimitEnableEpoch = 0 # SetSenderInEeiOutputTransferEnableEpoch represents the epoch when setting the sender in eei output transfers will be enabled - SetSenderInEeiOutputTransferEnableEpoch = 1 + SetSenderInEeiOutputTransferEnableEpoch = 0 # RefactorPeersMiniBlocksEnableEpoch represents the epoch when refactor of the peers mini blocks will be enabled - RefactorPeersMiniBlocksEnableEpoch = 1 + RefactorPeersMiniBlocksEnableEpoch = 0 # MaxBlockchainHookCountersEnableEpoch represents the epoch when the max blockchainhook counters are enabled - MaxBlockchainHookCountersEnableEpoch = 1 + MaxBlockchainHookCountersEnableEpoch = 0 # WipeSingleNFTLiquidityDecreaseEnableEpoch represents the epoch when the system account liquidity is decreased for wipeSingleNFT as well - WipeSingleNFTLiquidityDecreaseEnableEpoch = 1 + WipeSingleNFTLiquidityDecreaseEnableEpoch = 0 # AlwaysSaveTokenMetaDataEnableEpoch represents the epoch when the token metadata is always saved AlwaysSaveTokenMetaDataEnableEpoch = 0 # RuntimeCodeSizeFixEnableEpoch represents the epoch when the code size fix in the VM is enabled - RuntimeCodeSizeFixEnableEpoch = 2 + RuntimeCodeSizeFixEnableEpoch = 0 # BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers BLSMultiSignerEnableEpoch = [ @@ -256,5 +252,9 @@ [GasSchedule] # GasScheduleByEpochs holds the configuration for the gas schedule that will be applied from specific epochs GasScheduleByEpochs = [ - { StartEpoch = 0, FileName = "gasScheduleV7.toml" }, + { StartEpoch = 0, FileName = "gasScheduleV8.toml" }, ] + +[SovereignEnableEpochs] + +[SovereignChainSpecificEnableEpochs] diff --git a/cmd/sovereignnode/main.go b/cmd/sovereignnode/main.go index 82187eedf68..a202fe0b71b 100644 --- a/cmd/sovereignnode/main.go +++ b/cmd/sovereignnode/main.go @@ -8,14 +8,15 @@ 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-logger-go/file" + "github.com/urfave/cli" + "github.com/multiversx/mx-chain-go/cmd/node/factory" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/config/overridableConfig" sovereignConfig "github.com/multiversx/mx-chain-go/sovereignnode/config" - logger "github.com/multiversx/mx-chain-logger-go" - "github.com/multiversx/mx-chain-logger-go/file" - "github.com/urfave/cli" // test point 1 for custom profiler ) @@ -239,6 +240,13 @@ func readConfigs(ctx *cli.Context, log logger.Logger) (*sovereignConfig.Sovereig } log.Debug("config", "file", sovereignExtraConfigPath) + configurationPaths.Epoch = ctx.GlobalString(epochConfigurationFile.Name) + sovereignEpochConfig, err := sovereignConfig.LoadSovereignEpochConfig(configurationPaths.Epoch) + if err != nil { + return nil, err + } + log.Debug("config sovereign", "file", configurationPaths.Epoch) + sovereignExtraConfig.OutGoingBridgeCertificate = config.OutGoingBridgeCertificate{ CertificatePath: ctx.GlobalString(sovereignBridgeCertificateFile.Name), CertificatePkPath: ctx.GlobalString(sovereignBridgeCertificatePkFile.Name), @@ -277,6 +285,7 @@ func readConfigs(ctx *cli.Context, log logger.Logger) (*sovereignConfig.Sovereig RoundConfig: roundConfig, }, SovereignExtraConfig: sovereignExtraConfig, + SovereignEpochConfig: sovereignEpochConfig, }, nil } diff --git a/cmd/sovereignnode/sovereignNodeRunner.go b/cmd/sovereignnode/sovereignNodeRunner.go index fabff48dedb..27706d9faad 100644 --- a/cmd/sovereignnode/sovereignNodeRunner.go +++ b/cmd/sovereignnode/sovereignNodeRunner.go @@ -441,6 +441,7 @@ func (snr *sovereignNodeRunner) executeOneComponentCreationCycle( managedProcessComponents, err := snr.CreateManagedProcessComponents( managedRunTypeComponents, + managedRunTypeCoreComponents, managedCoreComponents, managedCryptoComponents, managedNetworkComponents, @@ -1286,6 +1287,7 @@ func (snr *sovereignNodeRunner) logSessionInformation( // CreateManagedProcessComponents is the managed process components factory func (snr *sovereignNodeRunner) CreateManagedProcessComponents( runTypeComponents mainFactory.RunTypeComponentsHolder, + runTypeCoreComponents mainFactory.RunTypeCoreComponentsHolder, coreComponents mainFactory.CoreComponentsHolder, cryptoComponents mainFactory.CryptoComponentsHolder, networkComponents mainFactory.NetworkComponentsHolder, @@ -1378,6 +1380,7 @@ func (snr *sovereignNodeRunner) CreateManagedProcessComponents( FlagsConfig: *configs.FlagsConfig, TxExecutionOrderHandler: ordering.NewOrderedCollection(), RunTypeComponents: runTypeComponents, + EnableEpochsFactory: runTypeCoreComponents.EnableEpochsFactoryCreator(), IncomingHeaderSubscriber: incomingHeaderHandler, } processComponentsFactory, err := processComp.NewProcessComponentsFactory(processArgs) @@ -1579,18 +1582,17 @@ func (snr *sovereignNodeRunner) CreateManagedCoreComponents( runTypeCoreComponents mainFactory.RunTypeCoreComponentsHolder, ) (mainFactory.CoreComponentsHandler, error) { coreArgs := coreComp.CoreComponentsFactoryArgs{ - Config: *snr.configs.GeneralConfig, - ConfigPathsHolder: *snr.configs.ConfigurationPathsHolder, - EpochConfig: *snr.configs.EpochConfig, - RoundConfig: *snr.configs.RoundConfig, - ImportDbConfig: *snr.configs.ImportDbConfig, - RatingsConfig: *snr.configs.RatingsConfig, - EconomicsConfig: *snr.configs.EconomicsConfig, - NodesFilename: snr.configs.ConfigurationPathsHolder.Nodes, - WorkingDirectory: snr.configs.FlagsConfig.DbDir, - ChanStopNodeProcess: chanStopNodeProcess, - GenesisNodesSetupFactory: runTypeCoreComponents.GenesisNodesSetupFactoryCreator(), - RatingsDataFactory: runTypeCoreComponents.RatingsDataFactoryCreator(), + Config: *snr.configs.GeneralConfig, + ConfigPathsHolder: *snr.configs.ConfigurationPathsHolder, + EpochConfig: *snr.configs.EpochConfig, + RoundConfig: *snr.configs.RoundConfig, + ImportDbConfig: *snr.configs.ImportDbConfig, + RatingsConfig: *snr.configs.RatingsConfig, + EconomicsConfig: *snr.configs.EconomicsConfig, + NodesFilename: snr.configs.ConfigurationPathsHolder.Nodes, + WorkingDirectory: snr.configs.FlagsConfig.DbDir, + ChanStopNodeProcess: chanStopNodeProcess, + RunTypeCoreComponents: runTypeCoreComponents, } coreComponentsFactory, err := coreComp.NewCoreComponentsFactory(coreArgs) @@ -1683,7 +1685,7 @@ func (snr *sovereignNodeRunner) CreateManagedCryptoComponents( // CreateManagedRunTypeCoreComponents creates the managed run type core components func (snr *sovereignNodeRunner) CreateManagedRunTypeCoreComponents() (mainFactory.RunTypeCoreComponentsHandler, error) { - sovereignRunTypeCoreComponentsFactory := runType.NewSovereignRunTypeCoreComponentsFactory() + sovereignRunTypeCoreComponentsFactory := runType.NewSovereignRunTypeCoreComponentsFactory(*snr.configs.SovereignEpochConfig) managedRunTypeCoreComponents, err := runType.NewManagedRunTypeCoreComponents(sovereignRunTypeCoreComponentsFactory) if err != nil { return nil, err diff --git a/common/enablers/enableEpochsFactory.go b/common/enablers/enableEpochsFactory.go new file mode 100644 index 00000000000..38f5961e55a --- /dev/null +++ b/common/enablers/enableEpochsFactory.go @@ -0,0 +1,24 @@ +package enablers + +import ( + "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/process" +) + +type enableEpochsFactory struct{} + +// NewEnableEpochsFactory creates an enable epochs factory for regular chain +func NewEnableEpochsFactory() EnableEpochsFactory { + return &enableEpochsFactory{} +} + +// CreateEnableEpochsHandler creates an enable epochs handler for regular chain +func (eef *enableEpochsFactory) CreateEnableEpochsHandler(enableEpochs config.EnableEpochs, epochNotifier process.EpochNotifier) (common.EnableEpochsHandler, error) { + return NewEnableEpochsHandler(enableEpochs, epochNotifier) +} + +// IsInterfaceNil checks if the underlying pointer is nil +func (eef *enableEpochsFactory) IsInterfaceNil() bool { + return eef == nil +} diff --git a/common/enablers/enableEpochsFactory_test.go b/common/enablers/enableEpochsFactory_test.go new file mode 100644 index 00000000000..bc3bc346b3d --- /dev/null +++ b/common/enablers/enableEpochsFactory_test.go @@ -0,0 +1,22 @@ +package enablers + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" +) + +func TestEnableEpochsFactory_CreateEnableEpochsHandler(t *testing.T) { + t.Parallel() + + factory := NewEnableEpochsFactory() + require.False(t, factory.IsInterfaceNil()) + + eeh, err := factory.CreateEnableEpochsHandler(config.EnableEpochs{}, &epochNotifier.EpochNotifierStub{}) + require.Nil(t, err) + require.NotNil(t, eeh) + require.IsType(t, &enableEpochsHandler{}, eeh) +} diff --git a/common/enablers/errors.go b/common/enablers/errors.go index 388a8ad96bd..6772f09fefb 100644 --- a/common/enablers/errors.go +++ b/common/enablers/errors.go @@ -3,3 +3,6 @@ package enablers import "errors" var errMissingRoundActivation = errors.New("missing round activation definition") + +// ErrNilEnableEpochsFactory signals that a nil enable epochs factory has been provided +var ErrNilEnableEpochsFactory = errors.New("nil enable epochs factory has been provided") diff --git a/common/enablers/interface.go b/common/enablers/interface.go new file mode 100644 index 00000000000..7ab2d0301b4 --- /dev/null +++ b/common/enablers/interface.go @@ -0,0 +1,13 @@ +package enablers + +import ( + "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/process" +) + +// EnableEpochsFactory defines enable epochs handler factory behavior +type EnableEpochsFactory interface { + CreateEnableEpochsHandler(enableEpochs config.EnableEpochs, epochNotifier process.EpochNotifier) (common.EnableEpochsHandler, error) + IsInterfaceNil() bool +} diff --git a/common/enablers/sovereignEnableEpochsFactory.go b/common/enablers/sovereignEnableEpochsFactory.go new file mode 100644 index 00000000000..6afb31b2e50 --- /dev/null +++ b/common/enablers/sovereignEnableEpochsFactory.go @@ -0,0 +1,28 @@ +package enablers + +import ( + "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/process" +) + +type sovereignEnableEpochsFactory struct { + sovereignEpochConfig config.SovereignEpochConfig +} + +// NewSovereignEnableEpochsFactory creates an enable epochs factory for sovereign chain +func NewSovereignEnableEpochsFactory(sovereignEpochConfig config.SovereignEpochConfig) EnableEpochsFactory { + return &sovereignEnableEpochsFactory{ + sovereignEpochConfig: sovereignEpochConfig, + } +} + +// CreateEnableEpochsHandler creates an enable epochs handler for sovereign chain +func (seef *sovereignEnableEpochsFactory) CreateEnableEpochsHandler(enableEpochs config.EnableEpochs, epochNotifier process.EpochNotifier) (common.EnableEpochsHandler, error) { + return NewSovereignEnableEpochsHandler(enableEpochs, seef.sovereignEpochConfig, epochNotifier) +} + +// IsInterfaceNil checks if the underlying pointer is nil +func (seef *sovereignEnableEpochsFactory) IsInterfaceNil() bool { + return seef == nil +} diff --git a/common/enablers/sovereignEnableEpochsFactory_test.go b/common/enablers/sovereignEnableEpochsFactory_test.go new file mode 100644 index 00000000000..692fecd9916 --- /dev/null +++ b/common/enablers/sovereignEnableEpochsFactory_test.go @@ -0,0 +1,22 @@ +package enablers + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" +) + +func TestSovereignEnableEpochsFactory_CreateEnableEpochsHandler(t *testing.T) { + t.Parallel() + + factory := NewSovereignEnableEpochsFactory(config.SovereignEpochConfig{}) + require.False(t, factory.IsInterfaceNil()) + + eeh, err := factory.CreateEnableEpochsHandler(config.EnableEpochs{}, &epochNotifier.EpochNotifierStub{}) + require.Nil(t, err) + require.NotNil(t, eeh) + require.IsType(t, &sovereignEnableEpochsHandler{}, eeh) +} diff --git a/common/enablers/sovereignEnableEpochsHandler.go b/common/enablers/sovereignEnableEpochsHandler.go new file mode 100644 index 00000000000..cf3eea637c4 --- /dev/null +++ b/common/enablers/sovereignEnableEpochsHandler.go @@ -0,0 +1,60 @@ +package enablers + +import ( + "github.com/multiversx/mx-chain-core-go/core/check" + + "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/process" +) + +type sovereignEnableEpochsHandler struct { + *enableEpochsHandler + sovereignEnableEpochsConfig config.SovereignEnableEpochs + sovereignChainSpecificEnableEpochsConfig config.SovereignChainSpecificEnableEpochs +} + +// NewSovereignEnableEpochsHandler creates a new instance of sovereign enable epochs handler +func NewSovereignEnableEpochsHandler( + enableEpochsConfig config.EnableEpochs, + sovereignEpochConfig config.SovereignEpochConfig, + epochNotifier process.EpochNotifier, +) (*sovereignEnableEpochsHandler, error) { + if check.IfNil(epochNotifier) { + return nil, process.ErrNilEpochNotifier + } + + sovHandler := &sovereignEnableEpochsHandler{ + enableEpochsHandler: &enableEpochsHandler{ + enableEpochsConfig: enableEpochsConfig, + }, + sovereignEnableEpochsConfig: sovereignEpochConfig.SovereignEnableEpochs, + sovereignChainSpecificEnableEpochsConfig: sovereignEpochConfig.SovereignChainSpecificEnableEpochs, + } + + sovHandler.createAllFlagsMap() + + epochNotifier.RegisterNotifyHandler(sovHandler) + + return sovHandler, nil +} + +func (sovHandler *sovereignEnableEpochsHandler) createAllFlagsMap() { + sovHandler.enableEpochsHandler.createAllFlagsMap() + sovHandler.addSovereignFlags() + sovHandler.addSovereignChainSpecificFlags() +} + +func (sovHandler *sovereignEnableEpochsHandler) addSovereignFlags() { + // follow the implementation from enableEpochsHandler.go to add a new sovereign flag + // add the new flags in sovHandler.enableEpochsHandler.allFlagsDefined map +} + +func (sovHandler *sovereignEnableEpochsHandler) addSovereignChainSpecificFlags() { + // follow the implementation from enableEpochsHandler.go to add a new sovereign flag + // add the new flags in sovHandler.enableEpochsHandler.allFlagsDefined map +} + +// IsInterfaceNil returns true if there is no value under the interface +func (sovHandler *sovereignEnableEpochsHandler) IsInterfaceNil() bool { + return sovHandler == nil +} diff --git a/common/enablers/sovereignEnableEpochsHandler_test.go b/common/enablers/sovereignEnableEpochsHandler_test.go new file mode 100644 index 00000000000..7c564f50e8d --- /dev/null +++ b/common/enablers/sovereignEnableEpochsHandler_test.go @@ -0,0 +1,38 @@ +package enablers + +import ( + "testing" + + "github.com/multiversx/mx-chain-core-go/core/check" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/stretchr/testify/require" + + "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" +) + +func TestNewSovereignEnableEpochsHandler(t *testing.T) { + t.Parallel() + + t.Run("nil epoch notifier should error", func(t *testing.T) { + t.Parallel() + + sovHandler, err := NewSovereignEnableEpochsHandler(createEnableEpochsConfig(), config.SovereignEpochConfig{}, nil) + require.Equal(t, process.ErrNilEpochNotifier, err) + require.True(t, sovHandler.IsInterfaceNil()) + }) + t.Run("should work", func(t *testing.T) { + t.Parallel() + + wasCalled := false + sovHandler, err := NewSovereignEnableEpochsHandler(createEnableEpochsConfig(), config.SovereignEpochConfig{}, &epochNotifier.EpochNotifierStub{ + RegisterNotifyHandlerCalled: func(handler vmcommon.EpochSubscriberHandler) { + wasCalled = true + }, + }) + require.Nil(t, err) + require.False(t, check.IfNil(sovHandler)) + require.True(t, wasCalled) + }) +} diff --git a/config/sovereignEpochConfig.go b/config/sovereignEpochConfig.go new file mode 100644 index 00000000000..252e4e4b5f9 --- /dev/null +++ b/config/sovereignEpochConfig.go @@ -0,0 +1,13 @@ +package config + +// SovereignEpochConfig will hold sovereign epoch configurations +type SovereignEpochConfig struct { + SovereignEnableEpochs SovereignEnableEpochs + SovereignChainSpecificEnableEpochs SovereignChainSpecificEnableEpochs +} + +// SovereignEnableEpochs will hold the configuration for sovereign activation epochs +type SovereignEnableEpochs struct{} + +// SovereignChainSpecificEnableEpochs will hold the configuration for sovereign chain specific activation epochs +type SovereignChainSpecificEnableEpochs struct{} diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index e3a63c47734..d5a29ea284b 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -907,40 +907,40 @@ func TestEnableEpochConfig(t *testing.T) { expectedCfg := EpochConfig{ EnableEpochs: EnableEpochs{ - SCDeployEnableEpoch: 1, - BuiltInFunctionsEnableEpoch: 2, - RelayedTransactionsEnableEpoch: 3, - PenalizedTooMuchGasEnableEpoch: 4, - SwitchJailWaitingEnableEpoch: 5, - BelowSignedThresholdEnableEpoch: 6, - SwitchHysteresisForMinNodesEnableEpoch: 7, - TransactionSignedWithTxHashEnableEpoch: 8, - MetaProtectionEnableEpoch: 9, - AheadOfTimeGasUsageEnableEpoch: 10, - GasPriceModifierEnableEpoch: 11, - RepairCallbackEnableEpoch: 12, - BlockGasAndFeesReCheckEnableEpoch: 13, - BalanceWaitingListsEnableEpoch: 14, - ReturnDataToLastTransferEnableEpoch: 15, - SenderInOutTransferEnableEpoch: 16, - StakeEnableEpoch: 17, - StakingV2EnableEpoch: 18, - DoubleKeyProtectionEnableEpoch: 19, - ESDTEnableEpoch: 20, - GovernanceEnableEpoch: 21, - DelegationManagerEnableEpoch: 22, - DelegationSmartContractEnableEpoch: 23, - CorrectLastUnjailedEnableEpoch: 24, - RelayedTransactionsV2EnableEpoch: 25, - UnbondTokensV2EnableEpoch: 26, - SaveJailedAlwaysEnableEpoch: 27, - ReDelegateBelowMinCheckEnableEpoch: 28, - ValidatorToDelegationEnableEpoch: 29, - - IncrementSCRNonceInMultiTransferEnableEpoch: 31, - ESDTMultiTransferEnableEpoch: 32, - GlobalMintBurnDisableEpoch: 33, - ESDTTransferRoleEnableEpoch: 34, + SCDeployEnableEpoch: 1, + BuiltInFunctionsEnableEpoch: 2, + RelayedTransactionsEnableEpoch: 3, + PenalizedTooMuchGasEnableEpoch: 4, + SwitchJailWaitingEnableEpoch: 5, + BelowSignedThresholdEnableEpoch: 6, + SwitchHysteresisForMinNodesEnableEpoch: 7, + TransactionSignedWithTxHashEnableEpoch: 8, + MetaProtectionEnableEpoch: 9, + AheadOfTimeGasUsageEnableEpoch: 10, + GasPriceModifierEnableEpoch: 11, + RepairCallbackEnableEpoch: 12, + BlockGasAndFeesReCheckEnableEpoch: 13, + BalanceWaitingListsEnableEpoch: 14, + ReturnDataToLastTransferEnableEpoch: 15, + SenderInOutTransferEnableEpoch: 16, + StakeEnableEpoch: 17, + StakingV2EnableEpoch: 18, + DoubleKeyProtectionEnableEpoch: 19, + ESDTEnableEpoch: 20, + GovernanceEnableEpoch: 21, + DelegationManagerEnableEpoch: 22, + DelegationSmartContractEnableEpoch: 23, + CorrectLastUnjailedEnableEpoch: 24, + RelayedTransactionsV2EnableEpoch: 25, + UnbondTokensV2EnableEpoch: 26, + SaveJailedAlwaysEnableEpoch: 27, + ReDelegateBelowMinCheckEnableEpoch: 28, + ValidatorToDelegationEnableEpoch: 29, + + IncrementSCRNonceInMultiTransferEnableEpoch: 31, + ESDTMultiTransferEnableEpoch: 32, + GlobalMintBurnDisableEpoch: 33, + ESDTTransferRoleEnableEpoch: 34, ComputeRewardCheckpointEnableEpoch: 36, SCRSizeInvariantCheckEnableEpoch: 37, @@ -1053,3 +1053,20 @@ func TestEnableEpochConfig(t *testing.T) { assert.Nil(t, err) assert.Equal(t, expectedCfg, cfg) } + +func TestSovereignEnableEpochConfig(t *testing.T) { + testString := ` +[SovereignEnableEpochs] + +[SovereignChainSpecificEnableEpochs] +` + + expectedCfg := SovereignEpochConfig{ + SovereignEnableEpochs: SovereignEnableEpochs{}, + } + + cfg := SovereignEpochConfig{} + err := toml.Unmarshal([]byte(testString), &cfg) + require.Nil(t, err) + require.Equal(t, expectedCfg, cfg) +} diff --git a/factory/core/coreComponents.go b/factory/core/coreComponents.go index 76472e8bdbc..43dd2906b92 100644 --- a/factory/core/coreComponents.go +++ b/factory/core/coreComponents.go @@ -19,6 +19,8 @@ import ( hasherFactory "github.com/multiversx/mx-chain-core-go/hashing/factory" "github.com/multiversx/mx-chain-core-go/marshal" marshalizerFactory "github.com/multiversx/mx-chain-core-go/marshal/factory" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/enablers" commonFactory "github.com/multiversx/mx-chain-go/common/factory" @@ -38,41 +40,38 @@ import ( "github.com/multiversx/mx-chain-go/statusHandler" "github.com/multiversx/mx-chain-go/storage" storageFactory "github.com/multiversx/mx-chain-go/storage/factory" - logger "github.com/multiversx/mx-chain-logger-go" ) var log = logger.GetOrCreate("factory") // CoreComponentsFactoryArgs holds the arguments needed for creating a core components factory type CoreComponentsFactoryArgs struct { - Config config.Config - ConfigPathsHolder config.ConfigurationPathsHolder - EpochConfig config.EpochConfig - RoundConfig config.RoundConfig - RatingsConfig config.RatingsConfig - EconomicsConfig config.EconomicsConfig - ImportDbConfig config.ImportDbConfig - NodesFilename string - WorkingDirectory string - ChanStopNodeProcess chan endProcess.ArgEndProcess - GenesisNodesSetupFactory sharding.GenesisNodesSetupFactory - RatingsDataFactory rating.RatingsDataFactory + Config config.Config + ConfigPathsHolder config.ConfigurationPathsHolder + EpochConfig config.EpochConfig + RoundConfig config.RoundConfig + RatingsConfig config.RatingsConfig + EconomicsConfig config.EconomicsConfig + ImportDbConfig config.ImportDbConfig + NodesFilename string + WorkingDirectory string + ChanStopNodeProcess chan endProcess.ArgEndProcess + RunTypeCoreComponents factory.RunTypeCoreComponentsHolder } // coreComponentsFactory is responsible for creating the core components type coreComponentsFactory struct { - config config.Config - configPathsHolder config.ConfigurationPathsHolder - epochConfig config.EpochConfig - roundConfig config.RoundConfig - ratingsConfig config.RatingsConfig - economicsConfig config.EconomicsConfig - importDbConfig config.ImportDbConfig - nodesFilename string - workingDir string - chanStopNodeProcess chan endProcess.ArgEndProcess - genesisNodesSetupFactory sharding.GenesisNodesSetupFactory - ratingsDataFactory rating.RatingsDataFactory + config config.Config + configPathsHolder config.ConfigurationPathsHolder + epochConfig config.EpochConfig + roundConfig config.RoundConfig + ratingsConfig config.RatingsConfig + economicsConfig config.EconomicsConfig + importDbConfig config.ImportDbConfig + nodesFilename string + workingDir string + chanStopNodeProcess chan endProcess.ArgEndProcess + runTypeCoreComponents factory.RunTypeCoreComponentsHolder } // coreComponents is the DTO used for core components @@ -115,26 +114,31 @@ type coreComponents struct { // NewCoreComponentsFactory initializes the factory which is responsible to creating core components func NewCoreComponentsFactory(args CoreComponentsFactoryArgs) (*coreComponentsFactory, error) { - if check.IfNil(args.GenesisNodesSetupFactory) { - return nil, errors.ErrNilNodesSetupFactory + if check.IfNil(args.RunTypeCoreComponents) { + return nil, errors.ErrNilRunTypeCoreComponents } - if check.IfNil(args.RatingsDataFactory) { + if check.IfNil(args.RunTypeCoreComponents.GenesisNodesSetupFactoryCreator()) { + return nil, sharding.ErrNilGenesisNodesSetupFactory + } + if check.IfNil(args.RunTypeCoreComponents.RatingsDataFactoryCreator()) { return nil, errors.ErrNilRatingsDataFactory } + if check.IfNil(args.RunTypeCoreComponents.EnableEpochsFactoryCreator()) { + return nil, enablers.ErrNilEnableEpochsFactory + } return &coreComponentsFactory{ - config: args.Config, - configPathsHolder: args.ConfigPathsHolder, - epochConfig: args.EpochConfig, - roundConfig: args.RoundConfig, - ratingsConfig: args.RatingsConfig, - importDbConfig: args.ImportDbConfig, - economicsConfig: args.EconomicsConfig, - workingDir: args.WorkingDirectory, - chanStopNodeProcess: args.ChanStopNodeProcess, - nodesFilename: args.NodesFilename, - genesisNodesSetupFactory: args.GenesisNodesSetupFactory, - ratingsDataFactory: args.RatingsDataFactory, + config: args.Config, + configPathsHolder: args.ConfigPathsHolder, + epochConfig: args.EpochConfig, + roundConfig: args.RoundConfig, + ratingsConfig: args.RatingsConfig, + importDbConfig: args.ImportDbConfig, + economicsConfig: args.EconomicsConfig, + workingDir: args.WorkingDirectory, + chanStopNodeProcess: args.ChanStopNodeProcess, + nodesFilename: args.NodesFilename, + runTypeCoreComponents: args.RunTypeCoreComponents, }, nil } @@ -191,7 +195,7 @@ func (ccf *coreComponentsFactory) Create() (*coreComponents, error) { syncer.StartSyncingTime() log.Debug("NTP average clock offset", "value", syncer.ClockOffset()) - genesisNodesConfig, err := ccf.genesisNodesSetupFactory.CreateNodesSetup( + genesisNodesConfig, err := ccf.runTypeCoreComponents.GenesisNodesSetupFactoryCreator().CreateNodesSetup( &sharding.NodesSetupArgs{ NodesFilePath: ccf.nodesFilename, AddressPubKeyConverter: addressPubkeyConverter, @@ -252,7 +256,7 @@ func (ccf *coreComponentsFactory) Create() (*coreComponents, error) { } epochNotifier := forking.NewGenericEpochNotifier() - enableEpochsHandler, err := enablers.NewEnableEpochsHandler(ccf.epochConfig.EnableEpochs, epochNotifier) + enableEpochsHandler, err := ccf.runTypeCoreComponents.EnableEpochsFactoryCreator().CreateEnableEpochsHandler(ccf.epochConfig.EnableEpochs, epochNotifier) if err != nil { return nil, err } @@ -287,7 +291,7 @@ func (ccf *coreComponentsFactory) Create() (*coreComponents, error) { MetaMinNodes: genesisNodesConfig.MinNumberOfMetaNodes(), RoundDurationMiliseconds: genesisNodesConfig.GetRoundDuration(), } - ratingsData, err := ccf.ratingsDataFactory.CreateRatingsData(ratingDataArgs) + ratingsData, err := ccf.runTypeCoreComponents.RatingsDataFactoryCreator().CreateRatingsData(ratingDataArgs) if err != nil { return nil, err } diff --git a/factory/core/coreComponents_test.go b/factory/core/coreComponents_test.go index 071664d0431..c119627f27d 100644 --- a/factory/core/coreComponents_test.go +++ b/factory/core/coreComponents_test.go @@ -4,12 +4,17 @@ import ( "errors" "testing" + "github.com/stretchr/testify/require" + + "github.com/multiversx/mx-chain-go/common/enablers" "github.com/multiversx/mx-chain-go/config" errorsMx "github.com/multiversx/mx-chain-go/errors" + "github.com/multiversx/mx-chain-go/factory" coreComp "github.com/multiversx/mx-chain-go/factory/core" + "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/state" componentsMock "github.com/multiversx/mx-chain-go/testscommon/components" - "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/testscommon/genesisMocks" ) func TestNewCoreComponentsFactory(t *testing.T) { @@ -21,20 +26,48 @@ func TestNewCoreComponentsFactory(t *testing.T) { require.NotNil(t, ccf) require.Nil(t, err) }) + t.Run("nil run type core components, should return error", func(t *testing.T) { + args := componentsMock.GetCoreArgs() + args.RunTypeCoreComponents = nil + ccf, err := coreComp.NewCoreComponentsFactory(args) + require.Nil(t, ccf) + require.Equal(t, errorsMx.ErrNilRunTypeCoreComponents, err) + }) t.Run("nil genesis nodes setup factory, should return error", func(t *testing.T) { args := componentsMock.GetCoreArgs() - args.GenesisNodesSetupFactory = nil + rtCoreMock := getRunTypeCoreComponentsMock(componentsMock.GetRunTypeCoreComponents()) + rtCoreMock.GenesisNodesSetupFactory = nil + args.RunTypeCoreComponents = rtCoreMock ccf, err := coreComp.NewCoreComponentsFactory(args) require.Nil(t, ccf) - require.Equal(t, errorsMx.ErrNilNodesSetupFactory, err) + require.Equal(t, sharding.ErrNilGenesisNodesSetupFactory, err) }) t.Run("nil ratings data factory, should return error", func(t *testing.T) { args := componentsMock.GetCoreArgs() - args.RatingsDataFactory = nil + rtCoreMock := getRunTypeCoreComponentsMock(componentsMock.GetRunTypeCoreComponents()) + rtCoreMock.RatingsDataFactory = nil + args.RunTypeCoreComponents = rtCoreMock ccf, err := coreComp.NewCoreComponentsFactory(args) require.Nil(t, ccf) require.Equal(t, errorsMx.ErrNilRatingsDataFactory, err) }) + t.Run("nil enable epochs factory, should return error", func(t *testing.T) { + args := componentsMock.GetCoreArgs() + rtCoreMock := getRunTypeCoreComponentsMock(componentsMock.GetRunTypeCoreComponents()) + rtCoreMock.EnableEpochsFactory = nil + args.RunTypeCoreComponents = rtCoreMock + ccf, err := coreComp.NewCoreComponentsFactory(args) + require.Nil(t, ccf) + require.Equal(t, enablers.ErrNilEnableEpochsFactory, err) + }) +} + +func getRunTypeCoreComponentsMock(rtc factory.RunTypeCoreComponentsHolder) *genesisMocks.RunTypeCoreComponentsStub { + return &genesisMocks.RunTypeCoreComponentsStub{ + GenesisNodesSetupFactory: rtc.GenesisNodesSetupFactoryCreator(), + RatingsDataFactory: rtc.RatingsDataFactoryCreator(), + EnableEpochsFactory: rtc.EnableEpochsFactoryCreator(), + } } func TestCoreComponentsFactory_CreateCoreComponentsNoHasherConfigShouldErr(t *testing.T) { diff --git a/factory/interface.go b/factory/interface.go index db293c58c52..4d0acd65bf2 100644 --- a/factory/interface.go +++ b/factory/interface.go @@ -19,6 +19,7 @@ import ( "github.com/multiversx/mx-chain-go/cmd/node/factory" "github.com/multiversx/mx-chain-go/common" cryptoCommon "github.com/multiversx/mx-chain-go/common/crypto" + "github.com/multiversx/mx-chain-go/common/enablers" "github.com/multiversx/mx-chain-go/common/statistics" "github.com/multiversx/mx-chain-go/consensus" "github.com/multiversx/mx-chain-go/consensus/spos/sposFactory" @@ -668,6 +669,7 @@ type RunTypeCoreComponentsHandler interface { type RunTypeCoreComponentsHolder interface { GenesisNodesSetupFactoryCreator() sharding.GenesisNodesSetupFactory RatingsDataFactoryCreator() rating.RatingsDataFactory + EnableEpochsFactoryCreator() enablers.EnableEpochsFactory Create() error Close() error CheckSubcomponents() error diff --git a/factory/processing/processComponents.go b/factory/processing/processComponents.go index f00cf04520c..97bbd5be661 100644 --- a/factory/processing/processComponents.go +++ b/factory/processing/processComponents.go @@ -21,6 +21,7 @@ import ( nodeFactory "github.com/multiversx/mx-chain-go/cmd/node/factory" "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/common/enablers" "github.com/multiversx/mx-chain-go/common/errChan" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/consensus" @@ -162,6 +163,7 @@ type ProcessComponentsFactoryArgs struct { StatusCoreComponents factory.StatusCoreComponentsHolder RunTypeComponents factory.RunTypeComponentsHolder TxExecutionOrderHandler common.TxExecutionOrderHandler + EnableEpochsFactory enablers.EnableEpochsFactory GenesisNonce uint64 GenesisRound uint64 @@ -204,6 +206,7 @@ type processComponentsFactory struct { statusCoreComponents factory.StatusCoreComponentsHolder txExecutionOrderHandler common.TxExecutionOrderHandler runTypeComponents factory.RunTypeComponentsHolder + enableEpochsFactory enablers.EnableEpochsFactory genesisNonce uint64 genesisRound uint64 @@ -249,6 +252,7 @@ func NewProcessComponentsFactory(args ProcessComponentsFactoryArgs) (*processCom genesisRound: args.GenesisRound, roundConfig: args.RoundConfig, runTypeComponents: args.RunTypeComponents, + enableEpochsFactory: args.EnableEpochsFactory, incomingHeaderSubscriber: args.IncomingHeaderSubscriber, auctionListSelectorAPI: disabled.NewDisabledAuctionListSelector(), stakingDataProviderAPI: disabled.NewDisabledStakingDataProvider(), @@ -878,6 +882,7 @@ func (pcf *processComponentsFactory) generateGenesisHeadersAndApplyInitialBalanc GenesisNonce: pcf.genesisNonce, GenesisRound: pcf.genesisRound, RunTypeComponents: pcf.runTypeComponents, + EnableEpochsFactory: pcf.enableEpochsFactory, DNSV2Addresses: pcf.config.BuiltInFunctions.DNSV2Addresses, // TODO: We should only pass the whole config instead of passing sub-configs as above Config: pcf.config, @@ -2122,6 +2127,9 @@ func checkProcessComponentsArgs(args ProcessComponentsFactoryArgs) error { if check.IfNil(args.IncomingHeaderSubscriber) { return fmt.Errorf("%s: %w", baseErrMessage, errorsMx.ErrNilIncomingHeaderSubscriber) } + if check.IfNil(args.EnableEpochsFactory) { + return fmt.Errorf("%s: %w", baseErrMessage, enablers.ErrNilEnableEpochsFactory) + } return nil } diff --git a/factory/processing/processComponentsHandler_test.go b/factory/processing/processComponentsHandler_test.go index b0851fd3318..1a8fee97364 100644 --- a/factory/processing/processComponentsHandler_test.go +++ b/factory/processing/processComponentsHandler_test.go @@ -6,6 +6,7 @@ import ( "github.com/multiversx/mx-chain-go/common" errorsMx "github.com/multiversx/mx-chain-go/errors" + "github.com/multiversx/mx-chain-go/factory" processComp "github.com/multiversx/mx-chain-go/factory/processing" "github.com/multiversx/mx-chain-go/process/mock" componentsMock "github.com/multiversx/mx-chain-go/testscommon/components" @@ -43,12 +44,12 @@ func TestManagedProcessComponents_CreateShouldWork(t *testing.T) { t.Skip("this is not a short test") } - testManagedProcessComponentsCreateShouldWork(t, common.MetachainShardId, getRunTypeComponentsMock()) - testManagedProcessComponentsCreateShouldWork(t, 0, getRunTypeComponentsMock()) - testManagedProcessComponentsCreateShouldWork(t, core.SovereignChainShardId, getSovereignRunTypeComponentsMock()) + testManagedProcessComponentsCreateShouldWork(t, common.MetachainShardId, componentsMock.GetRunTypeCoreComponents(), getRunTypeComponentsMock()) + testManagedProcessComponentsCreateShouldWork(t, 0, componentsMock.GetRunTypeCoreComponents(), getRunTypeComponentsMock()) + testManagedProcessComponentsCreateShouldWork(t, core.SovereignChainShardId, componentsMock.GetRunTypeCoreComponents(), getSovereignRunTypeComponentsMock()) } -func testManagedProcessComponentsCreateShouldWork(t *testing.T, shardID uint32, rtch *mainFactoryMocks.RunTypeComponentsStub) { +func testManagedProcessComponentsCreateShouldWork(t *testing.T, shardID uint32, rttc factory.RunTypeCoreComponentsHolder, rtc *mainFactoryMocks.RunTypeComponentsStub) { shardCoordinator := mock.NewMultiShardsCoordinatorMock(1) shardCoordinator.CurrentShard = shardID @@ -60,7 +61,7 @@ func testManagedProcessComponentsCreateShouldWork(t *testing.T, shardID uint32, return 0 } - args := createProcessComponentsFactoryArgs(rtch) + args := createProcessComponentsFactoryArgs(rttc, rtc) componentsMock.SetShardCoordinator(t, args.BootstrapComponents, shardCoordinator) processComponentsFactory, _ := processComp.NewProcessComponentsFactory(args) managedProcessComponents, _ := processComp.NewManagedProcessComponents(processComponentsFactory) diff --git a/factory/processing/processComponents_test.go b/factory/processing/processComponents_test.go index 2800fe700b3..508f75799d6 100644 --- a/factory/processing/processComponents_test.go +++ b/factory/processing/processComponents_test.go @@ -23,6 +23,7 @@ import ( "github.com/stretchr/testify/require" "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/common/enablers" "github.com/multiversx/mx-chain-go/common/factory" disabledStatistics "github.com/multiversx/mx-chain-go/common/statistics/disabled" "github.com/multiversx/mx-chain-go/config" @@ -85,14 +86,14 @@ var ( ) func createMockProcessComponentsFactoryArgs() processComp.ProcessComponentsFactoryArgs { - return createProcessComponentsFactoryArgs(getRunTypeComponentsMock()) + return createProcessComponentsFactoryArgs(components.GetRunTypeCoreComponents(), getRunTypeComponentsMock()) } func createMockSovereignProcessComponentsFactoryArgs() processComp.ProcessComponentsFactoryArgs { - return createProcessComponentsFactoryArgs(getSovereignRunTypeComponentsMock()) + return createProcessComponentsFactoryArgs(components.GetSovereignRunTypeCoreComponents(), getSovereignRunTypeComponentsMock()) } -func createProcessComponentsFactoryArgs(runTypeComponents *mainFactoryMocks.RunTypeComponentsStub) processComp.ProcessComponentsFactoryArgs { +func createProcessComponentsFactoryArgs(runTypeCoreComponents runType.RunTypeCoreComponentsHolder, runTypeComponents *mainFactoryMocks.RunTypeComponentsStub) processComp.ProcessComponentsFactoryArgs { args := processComp.ProcessComponentsFactoryArgs{ Config: testscommon.GetGeneralConfig(), EpochConfig: config.EpochConfig{ @@ -282,6 +283,7 @@ func createProcessComponentsFactoryArgs(runTypeComponents *mainFactoryMocks.RunT }, } args.RunTypeComponents = runTypeComponents + args.EnableEpochsFactory = runTypeCoreComponents.EnableEpochsFactoryCreator() return args } @@ -1060,6 +1062,15 @@ func TestNewProcessComponentsFactory(t *testing.T) { require.True(t, errors.Is(err, errorsMx.ErrNilExportHandlerFactoryCreator)) require.Nil(t, pcf) }) + t.Run("nil EnableEpochsFactory should error", func(t *testing.T) { + t.Parallel() + + args := createMockProcessComponentsFactoryArgs() + args.EnableEpochsFactory = nil + pcf, err := processComp.NewProcessComponentsFactory(args) + require.True(t, errors.Is(err, enablers.ErrNilEnableEpochsFactory)) + require.Nil(t, pcf) + }) t.Run("nil OutportDataProviderFactory should error", func(t *testing.T) { t.Parallel() diff --git a/factory/runType/runTypeCoreComponents.go b/factory/runType/runTypeCoreComponents.go index 2de2f25fc93..2ab8a5a21ea 100644 --- a/factory/runType/runTypeCoreComponents.go +++ b/factory/runType/runTypeCoreComponents.go @@ -1,6 +1,7 @@ package runType import ( + "github.com/multiversx/mx-chain-go/common/enablers" "github.com/multiversx/mx-chain-go/process/rating" "github.com/multiversx/mx-chain-go/sharding" ) @@ -8,6 +9,7 @@ import ( type runTypeCoreComponents struct { genesisNodesSetupFactory sharding.GenesisNodesSetupFactory ratingsDataFactory rating.RatingsDataFactory + enableEpochsFactory enablers.EnableEpochsFactory } // Close does nothing diff --git a/factory/runType/runTypeCoreComponentsFactory.go b/factory/runType/runTypeCoreComponentsFactory.go index bf34c7ed37c..866daaf5ea7 100644 --- a/factory/runType/runTypeCoreComponentsFactory.go +++ b/factory/runType/runTypeCoreComponentsFactory.go @@ -1,6 +1,7 @@ package runType import ( + "github.com/multiversx/mx-chain-go/common/enablers" "github.com/multiversx/mx-chain-go/process/rating" "github.com/multiversx/mx-chain-go/sharding" ) @@ -18,6 +19,7 @@ func (rccf *runTypeCoreComponentsFactory) Create() *runTypeCoreComponents { return &runTypeCoreComponents{ genesisNodesSetupFactory: sharding.NewGenesisNodesSetupFactory(), ratingsDataFactory: rating.NewRatingsDataFactory(), + enableEpochsFactory: enablers.NewEnableEpochsFactory(), } } diff --git a/factory/runType/runTypeCoreComponentsHandler.go b/factory/runType/runTypeCoreComponentsHandler.go index f9bc4b5331c..21b21e4cc35 100644 --- a/factory/runType/runTypeCoreComponentsHandler.go +++ b/factory/runType/runTypeCoreComponentsHandler.go @@ -5,6 +5,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core/check" + "github.com/multiversx/mx-chain-go/common/enablers" "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/factory" "github.com/multiversx/mx-chain-go/process/rating" @@ -76,6 +77,9 @@ func (mrcc *managedRunTypeCoreComponents) CheckSubcomponents() error { if check.IfNil(mrcc.ratingsDataFactory) { return errors.ErrNilRatingsDataFactory } + if check.IfNil(mrcc.enableEpochsFactory) { + return enablers.ErrNilEnableEpochsFactory + } return nil } @@ -103,6 +107,18 @@ func (mrcc *managedRunTypeCoreComponents) RatingsDataFactoryCreator() rating.Rat return mrcc.runTypeCoreComponents.ratingsDataFactory } +// EnableEpochsFactoryCreator returns the enable epochs factory creator +func (mrcc *managedRunTypeCoreComponents) EnableEpochsFactoryCreator() enablers.EnableEpochsFactory { + mrcc.mutRunTypeCoreComponents.RLock() + defer mrcc.mutRunTypeCoreComponents.RUnlock() + + if check.IfNil(mrcc.runTypeCoreComponents) { + return nil + } + + return mrcc.runTypeCoreComponents.enableEpochsFactory +} + // IsInterfaceNil returns true if the interface is nil func (mrcc *managedRunTypeCoreComponents) IsInterfaceNil() bool { return mrcc == nil diff --git a/factory/runType/runTypeCoreComponentsHandler_test.go b/factory/runType/runTypeCoreComponentsHandler_test.go index 879014863ac..73b8a623e69 100644 --- a/factory/runType/runTypeCoreComponentsHandler_test.go +++ b/factory/runType/runTypeCoreComponentsHandler_test.go @@ -42,12 +42,14 @@ func TestManagedRunTypeCoreComponents_Create(t *testing.T) { require.Nil(t, managedRunTypeCoreComponents.GenesisNodesSetupFactoryCreator()) require.Nil(t, managedRunTypeCoreComponents.RatingsDataFactoryCreator()) + require.Nil(t, managedRunTypeCoreComponents.EnableEpochsFactoryCreator()) err = managedRunTypeCoreComponents.Create() require.NoError(t, err) require.NotNil(t, managedRunTypeCoreComponents.GenesisNodesSetupFactoryCreator()) require.NotNil(t, managedRunTypeCoreComponents.RatingsDataFactoryCreator()) + require.NotNil(t, managedRunTypeCoreComponents.EnableEpochsFactoryCreator()) require.Equal(t, factory.RunTypeCoreComponentsName, managedRunTypeCoreComponents.String()) require.NoError(t, managedRunTypeCoreComponents.Close()) diff --git a/factory/runType/sovereignRunTypeCoreComponents.go b/factory/runType/sovereignRunTypeCoreComponents.go index 8a9730d00f8..a14023472bf 100644 --- a/factory/runType/sovereignRunTypeCoreComponents.go +++ b/factory/runType/sovereignRunTypeCoreComponents.go @@ -1,16 +1,21 @@ package runType import ( + "github.com/multiversx/mx-chain-go/common/enablers" + "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/process/rating" "github.com/multiversx/mx-chain-go/sharding" ) type sovereignRunTypeCoreComponentsFactory struct { + sovereignEpochConfig config.SovereignEpochConfig } // NewSovereignRunTypeCoreComponentsFactory will return a new instance of sovereign runType core components factory -func NewSovereignRunTypeCoreComponentsFactory() *sovereignRunTypeCoreComponentsFactory { - return &sovereignRunTypeCoreComponentsFactory{} +func NewSovereignRunTypeCoreComponentsFactory(sovereignEpochConfig config.SovereignEpochConfig) *sovereignRunTypeCoreComponentsFactory { + return &sovereignRunTypeCoreComponentsFactory{ + sovereignEpochConfig: sovereignEpochConfig, + } } // Create will return a new instance of runType core components @@ -18,6 +23,7 @@ func (srccf *sovereignRunTypeCoreComponentsFactory) Create() *runTypeCoreCompone return &runTypeCoreComponents{ genesisNodesSetupFactory: sharding.NewSovereignGenesisNodesSetupFactory(), ratingsDataFactory: rating.NewSovereignRatingsDataFactory(), + enableEpochsFactory: enablers.NewSovereignEnableEpochsFactory(srccf.sovereignEpochConfig), } } diff --git a/factory/runType/sovereignRunTypeCoreComponents_test.go b/factory/runType/sovereignRunTypeCoreComponents_test.go index 650f2f3f33d..b04eac2a097 100644 --- a/factory/runType/sovereignRunTypeCoreComponents_test.go +++ b/factory/runType/sovereignRunTypeCoreComponents_test.go @@ -5,13 +5,14 @@ import ( "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/factory/runType" ) func TestSovereignRunTypeCoreComponentsFactory_CreateAndClose(t *testing.T) { t.Parallel() - srccf := runType.NewSovereignRunTypeCoreComponentsFactory() + srccf := runType.NewSovereignRunTypeCoreComponentsFactory(config.SovereignEpochConfig{}) require.NotNil(t, srccf) rcc := srccf.Create() diff --git a/genesis/mock/genesisNodesSetupFactoryMock.go b/genesis/mock/genesisNodesSetupFactoryMock.go new file mode 100644 index 00000000000..94446b36304 --- /dev/null +++ b/genesis/mock/genesisNodesSetupFactoryMock.go @@ -0,0 +1,24 @@ +package mock + +import ( + "github.com/multiversx/mx-chain-go/sharding" + "github.com/multiversx/mx-chain-go/update/mock" +) + +// GenesisNodesSetupFactoryMock - +type GenesisNodesSetupFactoryMock struct { + CreateNodesSetupCalled func(args *sharding.NodesSetupArgs) (sharding.GenesisNodesSetupHandler, error) +} + +// CreateNodesSetup - +func (f *GenesisNodesSetupFactoryMock) CreateNodesSetup(args *sharding.NodesSetupArgs) (sharding.GenesisNodesSetupHandler, error) { + if f.CreateNodesSetupCalled != nil { + return f.CreateNodesSetupCalled(args) + } + return &mock.GenesisNodesSetupHandlerStub{}, nil +} + +// IsInterfaceNil - +func (f *GenesisNodesSetupFactoryMock) IsInterfaceNil() bool { + return f == nil +} diff --git a/genesis/process/argGenesisBlockCreator.go b/genesis/process/argGenesisBlockCreator.go index 7fbc77cd488..1b1f6b578f4 100644 --- a/genesis/process/argGenesisBlockCreator.go +++ b/genesis/process/argGenesisBlockCreator.go @@ -11,6 +11,7 @@ import ( crypto "github.com/multiversx/mx-chain-crypto-go" "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/common/enablers" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/dblookupext" @@ -98,6 +99,7 @@ type ArgsGenesisBlockCreator struct { TxExecutionOrderHandler common.TxExecutionOrderHandler RunTypeComponents runTypeComponentsHandler Config config.Config + EnableEpochsFactory enablers.EnableEpochsFactory GenesisNodePrice *big.Int GenesisString string diff --git a/genesis/process/genesisBlockCreator.go b/genesis/process/genesisBlockCreator.go index b2281bffd3c..bce0a45ee16 100644 --- a/genesis/process/genesisBlockCreator.go +++ b/genesis/process/genesisBlockCreator.go @@ -13,14 +13,13 @@ import ( "github.com/multiversx/mx-chain-core-go/data/block" vmcommonBuiltInFunctions "github.com/multiversx/mx-chain-vm-common-go/builtInFunctions" - "github.com/multiversx/mx-chain-go/factory/vm" - "github.com/multiversx/mx-chain-go/common/enablers" "github.com/multiversx/mx-chain-go/common/forking" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/dataRetriever/blockchain" "github.com/multiversx/mx-chain-go/errors" + "github.com/multiversx/mx-chain-go/factory/vm" "github.com/multiversx/mx-chain-go/genesis" "github.com/multiversx/mx-chain-go/genesis/process/disabled" "github.com/multiversx/mx-chain-go/genesis/process/intermediate" @@ -234,6 +233,9 @@ func checkArgumentsForBlockCreator(arg ArgsGenesisBlockCreator) error { if check.IfNil(arg.RunTypeComponents.PreProcessorsContainerFactoryCreator()) { return errors.ErrNilPreProcessorsContainerFactoryCreator } + if check.IfNil(arg.EnableEpochsFactory) { + return enablers.ErrNilEnableEpochsFactory + } if arg.TrieStorageManagers == nil { return genesis.ErrNilTrieStorageManager } @@ -477,7 +479,7 @@ func (gbc *genesisBlockCreator) computeDNSAddresses( Epoch: gbc.arg.StartEpochNum, TimeStamp: gbc.arg.GenesisTime, } - enableEpochsHandler, err := enablers.NewEnableEpochsHandler(enableEpochsConfig, epochNotifier) + enableEpochsHandler, err := gbc.arg.EnableEpochsFactory.CreateEnableEpochsHandler(enableEpochsConfig, epochNotifier) if err != nil { return err } diff --git a/genesis/process/genesisBlockCreator_test.go b/genesis/process/genesisBlockCreator_test.go index fe489d3aee2..0b80dc82a0a 100644 --- a/genesis/process/genesisBlockCreator_test.go +++ b/genesis/process/genesisBlockCreator_test.go @@ -58,7 +58,7 @@ func createMockArgument( initialNodes genesis.InitialNodesHandler, entireSupply *big.Int, ) ArgsGenesisBlockCreator { - return createArgument(t, genesisFilename, initialNodes, entireSupply, genesisMocks.NewRunTypeComponentsStub()) + return createArgument(t, genesisFilename, initialNodes, entireSupply, genesisMocks.NewRunTypeCoreComponentsStub(), genesisMocks.NewRunTypeComponentsStub()) } func createSovereignMockArgument( @@ -67,7 +67,7 @@ func createSovereignMockArgument( initialNodes genesis.InitialNodesHandler, entireSupply *big.Int, ) ArgsGenesisBlockCreator { - return createArgument(t, genesisFilename, initialNodes, entireSupply, genesisMocks.NewSovereignRunTypeComponentsStub()) + return createArgument(t, genesisFilename, initialNodes, entireSupply, genesisMocks.NewSovereignRunTypeCoreComponentsStub(), genesisMocks.NewSovereignRunTypeComponentsStub()) } // TODO improve code coverage of this package @@ -76,6 +76,7 @@ func createArgument( genesisFilename string, initialNodes genesis.InitialNodesHandler, entireSupply *big.Int, + runTypeCoreComponents *genesisMocks.RunTypeCoreComponentsStub, runTypeComponents *genesisMocks.RunTypeComponentsStub, ) ArgsGenesisBlockCreator { trieStorageManagers := createTrieStorageManagers() @@ -280,6 +281,7 @@ func createArgument( require.Nil(t, err) arg.InitialNodesSetup = initialNodes + arg.EnableEpochsFactory = runTypeCoreComponents.EnableEpochsFactoryCreator() arg.RunTypeComponents = runTypeComponents return arg diff --git a/genesis/process/metaGenesisBlockCreator.go b/genesis/process/metaGenesisBlockCreator.go index 0b327f813f3..401b5dbb8d1 100644 --- a/genesis/process/metaGenesisBlockCreator.go +++ b/genesis/process/metaGenesisBlockCreator.go @@ -307,7 +307,7 @@ func createProcessorsForMetaGenesisBlock(arg ArgsGenesisBlockCreator, enableEpoc Epoch: arg.StartEpochNum, TimeStamp: arg.GenesisTime, } - enableEpochsHandler, err := enablers.NewEnableEpochsHandler(enableEpochsConfig, epochNotifier) + enableEpochsHandler, err := arg.EnableEpochsFactory.CreateEnableEpochsHandler(enableEpochsConfig, epochNotifier) if err != nil { return nil, err } @@ -444,29 +444,29 @@ func createProcessorsForMetaGenesisBlock(arg ArgsGenesisBlockCreator, enableEpoc argsParser := smartContract.NewArgumentParser() argsNewSCProcessor := scrCommon.ArgsNewSmartContractProcessor{ - VmContainer: vmContainer, - ArgsParser: argsParser, - Hasher: arg.Core.Hasher(), - Marshalizer: arg.Core.InternalMarshalizer(), - AccountsDB: arg.Accounts, - BlockChainHook: metaVMFactory.BlockChainHookImpl(), - BuiltInFunctions: builtInFuncs, - PubkeyConv: arg.Core.AddressPubKeyConverter(), - ShardCoordinator: arg.ShardCoordinator, - ScrForwarder: scForwarder, - TxFeeHandler: genesisFeeHandler, - EconomicsFee: genesisFeeHandler, - TxTypeHandler: txTypeHandler, - GasHandler: gasHandler, - GasSchedule: arg.GasSchedule, - TxLogsProcessor: arg.TxLogsProcessor, - BadTxForwarder: badTxForwarder, - EnableRoundsHandler: enableRoundsHandler, - EnableEpochsHandler: enableEpochsHandler, - IsGenesisProcessing: true, - WasmVMChangeLocker: &sync.RWMutex{}, // local Locker as to not interfere with the rest of the components - VMOutputCacher: txcache.NewDisabledCache(), - EpochNotifier: epochNotifier, + VmContainer: vmContainer, + ArgsParser: argsParser, + Hasher: arg.Core.Hasher(), + Marshalizer: arg.Core.InternalMarshalizer(), + AccountsDB: arg.Accounts, + BlockChainHook: metaVMFactory.BlockChainHookImpl(), + BuiltInFunctions: builtInFuncs, + PubkeyConv: arg.Core.AddressPubKeyConverter(), + ShardCoordinator: arg.ShardCoordinator, + ScrForwarder: scForwarder, + TxFeeHandler: genesisFeeHandler, + EconomicsFee: genesisFeeHandler, + TxTypeHandler: txTypeHandler, + GasHandler: gasHandler, + GasSchedule: arg.GasSchedule, + TxLogsProcessor: arg.TxLogsProcessor, + BadTxForwarder: badTxForwarder, + EnableRoundsHandler: enableRoundsHandler, + EnableEpochsHandler: enableEpochsHandler, + IsGenesisProcessing: true, + WasmVMChangeLocker: &sync.RWMutex{}, // local Locker as to not interfere with the rest of the components + VMOutputCacher: txcache.NewDisabledCache(), + EpochNotifier: epochNotifier, } scProcessorProxy, err := processProxy.NewSmartContractProcessorProxy(argsNewSCProcessor) diff --git a/genesis/process/shardGenesisBlockCreator.go b/genesis/process/shardGenesisBlockCreator.go index e2e15c1cae5..5ba349e4a10 100644 --- a/genesis/process/shardGenesisBlockCreator.go +++ b/genesis/process/shardGenesisBlockCreator.go @@ -11,7 +11,6 @@ import ( "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/block" dataBlock "github.com/multiversx/mx-chain-core-go/data/block" - shardData "github.com/multiversx/mx-chain-go/process/factory/shard/data" logger "github.com/multiversx/mx-chain-logger-go" "github.com/multiversx/mx-chain-vm-common-go/parsers" @@ -30,6 +29,7 @@ import ( "github.com/multiversx/mx-chain-go/process/block/preprocess" "github.com/multiversx/mx-chain-go/process/coordinator" "github.com/multiversx/mx-chain-go/process/factory/shard" + shardData "github.com/multiversx/mx-chain-go/process/factory/shard/data" disabledGuardian "github.com/multiversx/mx-chain-go/process/guardian/disabled" "github.com/multiversx/mx-chain-go/process/receipts" "github.com/multiversx/mx-chain-go/process/rewardTransaction" @@ -360,7 +360,7 @@ func setBalanceToTrie(arg ArgsGenesisBlockCreator, accnt genesis.InitialAccountH func createProcessorsForShardGenesisBlock(arg ArgsGenesisBlockCreator, enableEpochsConfig config.EnableEpochs, roundConfig config.RoundConfig) (*genesisProcessors, error) { genesisWasmVMLocker := &sync.RWMutex{} // use a local instance as to not run in concurrent issues when doing bootstrap epochNotifier := forking.NewGenericEpochNotifier() - enableEpochsHandler, err := enablers.NewEnableEpochsHandler(enableEpochsConfig, epochNotifier) + enableEpochsHandler, err := arg.EnableEpochsFactory.CreateEnableEpochsHandler(enableEpochsConfig, epochNotifier) if err != nil { return nil, err } @@ -536,29 +536,29 @@ func createProcessorsForShardGenesisBlock(arg ArgsGenesisBlockCreator, enableEpo } argsNewScProcessor := scrCommon.ArgsNewSmartContractProcessor{ - VmContainer: vmContainer, - ArgsParser: smartContract.NewArgumentParser(), - Hasher: arg.Core.Hasher(), - Marshalizer: arg.Core.InternalMarshalizer(), - AccountsDB: arg.Accounts, - BlockChainHook: vmFactoryImpl.BlockChainHookImpl(), - BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), - PubkeyConv: arg.Core.AddressPubKeyConverter(), - ShardCoordinator: arg.ShardCoordinator, - ScrForwarder: scForwarder, - TxFeeHandler: genesisFeeHandler, - EconomicsFee: genesisFeeHandler, - TxTypeHandler: txTypeHandler, - GasHandler: gasHandler, - GasSchedule: arg.GasSchedule, - TxLogsProcessor: arg.TxLogsProcessor, - BadTxForwarder: badTxInterim, - EnableRoundsHandler: enableRoundsHandler, - EnableEpochsHandler: enableEpochsHandler, - IsGenesisProcessing: true, - VMOutputCacher: txcache.NewDisabledCache(), - WasmVMChangeLocker: genesisWasmVMLocker, - EpochNotifier: epochNotifier, + VmContainer: vmContainer, + ArgsParser: smartContract.NewArgumentParser(), + Hasher: arg.Core.Hasher(), + Marshalizer: arg.Core.InternalMarshalizer(), + AccountsDB: arg.Accounts, + BlockChainHook: vmFactoryImpl.BlockChainHookImpl(), + BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), + PubkeyConv: arg.Core.AddressPubKeyConverter(), + ShardCoordinator: arg.ShardCoordinator, + ScrForwarder: scForwarder, + TxFeeHandler: genesisFeeHandler, + EconomicsFee: genesisFeeHandler, + TxTypeHandler: txTypeHandler, + GasHandler: gasHandler, + GasSchedule: arg.GasSchedule, + TxLogsProcessor: arg.TxLogsProcessor, + BadTxForwarder: badTxInterim, + EnableRoundsHandler: enableRoundsHandler, + EnableEpochsHandler: enableEpochsHandler, + IsGenesisProcessing: true, + VMOutputCacher: txcache.NewDisabledCache(), + WasmVMChangeLocker: genesisWasmVMLocker, + EpochNotifier: epochNotifier, } scProcessorProxy, err := arg.RunTypeComponents.SCProcessorCreator().CreateSCProcessor(argsNewScProcessor) diff --git a/genesis/process/sovereignGenesisBlockCreator.go b/genesis/process/sovereignGenesisBlockCreator.go index fb668bb3263..a7c96cbaa55 100644 --- a/genesis/process/sovereignGenesisBlockCreator.go +++ b/genesis/process/sovereignGenesisBlockCreator.go @@ -126,11 +126,7 @@ func (gbc *sovereignGenesisBlockCreator) setGenesisEmptyBlockData( } func createSovereignGenesisConfig(providedEnableEpochs config.EnableEpochs) config.EnableEpochs { - cfg := createGenesisConfig(providedEnableEpochs) - cfg.ESDTMultiTransferEnableEpoch = 0 - cfg.StakeEnableEpoch = 0 - cfg.PenalizedTooMuchGasEnableEpoch = 0 - return cfg + return providedEnableEpochs } func (gbc *sovereignGenesisBlockCreator) computeSovereignDNSAddresses(enableEpochsConfig config.EnableEpochs) error { diff --git a/integrationTests/factory/consensusComponents/consensusComponents_test.go b/integrationTests/factory/consensusComponents/consensusComponents_test.go index 4a02a7778c6..ef679ce8409 100644 --- a/integrationTests/factory/consensusComponents/consensusComponents_test.go +++ b/integrationTests/factory/consensusComponents/consensusComponents_test.go @@ -108,6 +108,7 @@ func TestConsensusComponents_Close_ShouldWork(t *testing.T) { managedStatusComponents, managedStatusCoreComponents, managedRunTypeComponents, + managedRunTypeCoreComponents, gasScheduleNotifier, nodesCoord, ) diff --git a/integrationTests/factory/heartbeatComponents/heartbeatComponents_test.go b/integrationTests/factory/heartbeatComponents/heartbeatComponents_test.go index d0096bb77d7..b978206a18a 100644 --- a/integrationTests/factory/heartbeatComponents/heartbeatComponents_test.go +++ b/integrationTests/factory/heartbeatComponents/heartbeatComponents_test.go @@ -108,6 +108,7 @@ func TestHeartbeatComponents_Close_ShouldWork(t *testing.T) { managedStatusComponents, managedStatusCoreComponents, managedRunTypeComponents, + managedRunTypeCoreComponents, gasScheduleNotifier, nodesCoord, ) diff --git a/integrationTests/factory/processComponents/processComponents_test.go b/integrationTests/factory/processComponents/processComponents_test.go index 4a2a147c32e..6069d5b375d 100644 --- a/integrationTests/factory/processComponents/processComponents_test.go +++ b/integrationTests/factory/processComponents/processComponents_test.go @@ -106,6 +106,7 @@ func TestProcessComponents_Close_ShouldWork(t *testing.T) { managedStatusComponents, managedStatusCoreComponents, managedRunTypeComponents, + managedRunTypeCoreComponents, gasScheduleNotifier, nodesCoord, ) diff --git a/integrationTests/factory/statusComponents/statusComponents_test.go b/integrationTests/factory/statusComponents/statusComponents_test.go index a7d1ed6734d..f9a7fa7b0ec 100644 --- a/integrationTests/factory/statusComponents/statusComponents_test.go +++ b/integrationTests/factory/statusComponents/statusComponents_test.go @@ -108,6 +108,7 @@ func TestStatusComponents_Create_Close_ShouldWork(t *testing.T) { managedStatusComponents, managedStatusCoreComponents, managedRunTypeComponents, + managedRunTypeCoreComponents, gasScheduleNotifier, nodesCoord, ) diff --git a/integrationTests/multiShard/hardFork/hardFork_test.go b/integrationTests/multiShard/hardFork/hardFork_test.go index b51087bfc78..f07a53544cd 100644 --- a/integrationTests/multiShard/hardFork/hardFork_test.go +++ b/integrationTests/multiShard/hardFork/hardFork_test.go @@ -12,15 +12,16 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/block" - mxFactory "github.com/multiversx/mx-chain-go/factory" logger "github.com/multiversx/mx-chain-logger-go" wasmConfig "github.com/multiversx/mx-chain-vm-go/config" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/common/enablers" "github.com/multiversx/mx-chain-go/common/statistics/disabled" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/dataRetriever" + mxFactory "github.com/multiversx/mx-chain-go/factory" "github.com/multiversx/mx-chain-go/genesis/process" "github.com/multiversx/mx-chain-go/integrationTests" "github.com/multiversx/mx-chain-go/integrationTests/mock" @@ -506,6 +507,7 @@ func hardForkImport( HistoryRepository: &dblookupext.HistoryRepositoryStub{}, TxExecutionOrderHandler: &commonMocks.TxExecutionOrderHandlerStub{}, RunTypeComponents: componentsMock.GetRunTypeComponents(), + EnableEpochsFactory: enablers.NewEnableEpochsFactory(), } genesisProcessor, err := process.NewGenesisBlockCreator(argsGenesis) diff --git a/integrationTests/realcomponents/processorRunner.go b/integrationTests/realcomponents/processorRunner.go index 5fd313c64f5..e28b22b08d5 100644 --- a/integrationTests/realcomponents/processorRunner.go +++ b/integrationTests/realcomponents/processorRunner.go @@ -32,8 +32,6 @@ import ( "github.com/multiversx/mx-chain-go/integrationTests/vm" "github.com/multiversx/mx-chain-go/integrationTests/vm/wasm" "github.com/multiversx/mx-chain-go/process/interceptors" - "github.com/multiversx/mx-chain-go/process/rating" - "github.com/multiversx/mx-chain-go/sharding" nodesCoord "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/storage/cache" @@ -50,19 +48,20 @@ import ( // ProcessorRunner is a test emulation to the nodeRunner component type ProcessorRunner struct { - closers []io.Closer - Config config.Configs - CoreComponents factory.CoreComponentsHolder - CryptoComponents factory.CryptoComponentsHandler - StatusCoreComponents factory.StatusCoreComponentsHolder - NetworkComponents factory.NetworkComponentsHolder - BootstrapComponents factory.BootstrapComponentsHolder - DataComponents factory.DataComponentsHolder - StateComponents factory.StateComponentsHolder - NodesCoordinator nodesCoord.NodesCoordinator - StatusComponents factory.StatusComponentsHolder - ProcessComponents factory.ProcessComponentsHolder - RunTypeComponents factory.RunTypeComponentsHolder + closers []io.Closer + Config config.Configs + CoreComponents factory.CoreComponentsHolder + CryptoComponents factory.CryptoComponentsHandler + StatusCoreComponents factory.StatusCoreComponentsHolder + NetworkComponents factory.NetworkComponentsHolder + BootstrapComponents factory.BootstrapComponentsHolder + DataComponents factory.DataComponentsHolder + StateComponents factory.StateComponentsHolder + NodesCoordinator nodesCoord.NodesCoordinator + StatusComponents factory.StatusComponentsHolder + ProcessComponents factory.ProcessComponentsHolder + RunTypeComponents factory.RunTypeComponentsHolder + RunTypeCoreComponents factory.RunTypeCoreComponentsHolder } // NewProcessorRunner returns a new instance of ProcessorRunner @@ -78,6 +77,7 @@ func NewProcessorRunner(tb testing.TB, config config.Configs) *ProcessorRunner { } func (pr *ProcessorRunner) createComponents(tb testing.TB) { + pr.createRunTypeCoreComponents(tb) pr.createCoreComponents(tb) pr.createCryptoComponents(tb) pr.createRunTypeComponents(tb) @@ -90,6 +90,21 @@ func (pr *ProcessorRunner) createComponents(tb testing.TB) { pr.createProcessComponents(tb) } +func (pr *ProcessorRunner) createRunTypeCoreComponents(tb testing.TB) { + rtcFactory := runType.NewRunTypeCoreComponentsFactory() + + rtcComp, err := runType.NewManagedRunTypeCoreComponents(rtcFactory) + require.Nil(tb, err) + + err = rtcComp.Create() + require.Nil(tb, err) + require.Nil(tb, rtcComp.CheckSubcomponents()) + + pr.closers = append(pr.closers, rtcComp) + pr.RunTypeCoreComponents = rtcComp + +} + func (pr *ProcessorRunner) createRunTypeComponents(tb testing.TB) { initialAccounts, err := commonRunType.ReadInitialAccounts(pr.Config.ConfigurationPathsHolder.Genesis) require.Nil(tb, err) @@ -115,18 +130,17 @@ func (pr *ProcessorRunner) createRunTypeComponents(tb testing.TB) { func (pr *ProcessorRunner) createCoreComponents(tb testing.TB) { argsCore := factoryCore.CoreComponentsFactoryArgs{ - Config: *pr.Config.GeneralConfig, - ConfigPathsHolder: *pr.Config.ConfigurationPathsHolder, - EpochConfig: *pr.Config.EpochConfig, - RoundConfig: *pr.Config.RoundConfig, - RatingsConfig: *pr.Config.RatingsConfig, - EconomicsConfig: *pr.Config.EconomicsConfig, - ImportDbConfig: *pr.Config.ImportDbConfig, - NodesFilename: pr.Config.ConfigurationPathsHolder.Nodes, - WorkingDirectory: pr.Config.FlagsConfig.WorkingDir, - ChanStopNodeProcess: make(chan endProcess.ArgEndProcess), - GenesisNodesSetupFactory: sharding.NewGenesisNodesSetupFactory(), - RatingsDataFactory: rating.NewRatingsDataFactory(), + Config: *pr.Config.GeneralConfig, + ConfigPathsHolder: *pr.Config.ConfigurationPathsHolder, + EpochConfig: *pr.Config.EpochConfig, + RoundConfig: *pr.Config.RoundConfig, + RatingsConfig: *pr.Config.RatingsConfig, + EconomicsConfig: *pr.Config.EconomicsConfig, + ImportDbConfig: *pr.Config.ImportDbConfig, + NodesFilename: pr.Config.ConfigurationPathsHolder.Nodes, + WorkingDirectory: pr.Config.FlagsConfig.WorkingDir, + ChanStopNodeProcess: make(chan endProcess.ArgEndProcess), + RunTypeCoreComponents: pr.RunTypeCoreComponents, } coreFactory, err := factoryCore.NewCoreComponentsFactory(argsCore) require.Nil(tb, err) @@ -456,6 +470,7 @@ func (pr *ProcessorRunner) createProcessComponents(tb testing.TB) { TxExecutionOrderHandler: txExecutionOrderHandler, RunTypeComponents: pr.RunTypeComponents, IncomingHeaderSubscriber: &disabled.IncomingHeaderProcessor{}, + EnableEpochsFactory: pr.RunTypeCoreComponents.EnableEpochsFactoryCreator(), } processFactory, err := factoryProcessing.NewProcessComponentsFactory(argsProcess) diff --git a/integrationTests/testInitializer.go b/integrationTests/testInitializer.go index 40a6c7112d3..bd2a6727e87 100644 --- a/integrationTests/testInitializer.go +++ b/integrationTests/testInitializer.go @@ -34,6 +34,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/common/enablers" "github.com/multiversx/mx-chain-go/common/statistics" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/dataRetriever" @@ -747,6 +748,7 @@ func CreateFullGenesisBlocks( HistoryRepository: &dblookupext.HistoryRepositoryStub{}, TxExecutionOrderHandler: &commonMocks.TxExecutionOrderHandlerStub{}, RunTypeComponents: runTypeComp, + EnableEpochsFactory: enablers.NewEnableEpochsFactory(), } genesisProcessor, _ := genesisProcess.NewGenesisBlockCreator(argsGenesis) @@ -865,6 +867,7 @@ func CreateGenesisMetaBlock( HistoryRepository: &dblookupext.HistoryRepositoryStub{}, TxExecutionOrderHandler: &commonMocks.TxExecutionOrderHandlerStub{}, RunTypeComponents: runTypeComp, + EnableEpochsFactory: enablers.NewEnableEpochsFactory(), } if shardCoordinator.SelfId() != core.MetachainShardId { diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index dbed9fc40a9..7c73741305b 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -432,7 +432,8 @@ type TestProcessorNode struct { BlockTrackerCreator track.BlockTrackerCreator BlockProcessorCreator processing.BlockProcessorCreator - RunTypeComponents factory.RunTypeComponentsHolder + RunTypeComponents factory.RunTypeComponentsHolder + EnableEpochsFactory enablers.EnableEpochsFactory } // CreatePkBytes creates 'numShards' public key-like byte slices @@ -565,6 +566,7 @@ func newBaseTestProcessorNode(args ArgTestProcessorNode) *TestProcessorNode { BlockProcessorCreator: args.RunTypeComponents.BlockProcessorCreator(), BlockTrackerCreator: args.RunTypeComponents.BlockTrackerCreator(), RunTypeComponents: args.RunTypeComponents, + EnableEpochsFactory: enablers.NewEnableEpochsFactory(), } tpn.NodeKeys = args.NodeKeys diff --git a/node/chainSimulator/components/coreComponents.go b/node/chainSimulator/components/coreComponents.go index b966809825a..7d6760fa0e4 100644 --- a/node/chainSimulator/components/coreComponents.go +++ b/node/chainSimulator/components/coreComponents.go @@ -165,11 +165,7 @@ func CreateCoreComponents(args ArgsCoreComponentsHolder) (*coreComponentsHolder, instance.wasmVMChangeLocker = &sync.RWMutex{} instance.txVersionChecker = versioning.NewTxVersionChecker(args.Config.GeneralSettings.MinTransactionVersion) instance.epochNotifier = forking.NewGenericEpochNotifier() - instance.enableEpochsHandler, err = enablers.NewEnableEpochsHandler(args.EnableEpochsConfig, instance.epochNotifier) - if err != nil { - return nil, err - } - + instance.enableEpochsHandler, err = args.RunTypeCoreComponents.EnableEpochsFactoryCreator().CreateEnableEpochsHandler(args.EnableEpochsConfig, instance.epochNotifier) if err != nil { return nil, err } diff --git a/node/chainSimulator/components/processComponents.go b/node/chainSimulator/components/processComponents.go index 9fceafc625d..474f0674a08 100644 --- a/node/chainSimulator/components/processComponents.go +++ b/node/chainSimulator/components/processComponents.go @@ -7,7 +7,10 @@ import ( "time" "github.com/multiversx/mx-chain-core-go/core/partitioning" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/common/enablers" "github.com/multiversx/mx-chain-go/common/forking" "github.com/multiversx/mx-chain-go/common/ordering" "github.com/multiversx/mx-chain-go/config" @@ -27,8 +30,6 @@ import ( "github.com/multiversx/mx-chain-go/storage/cache" "github.com/multiversx/mx-chain-go/update" "github.com/multiversx/mx-chain-go/update/trigger" - - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) // ArgsProcessComponentsHolder will hold the components needed for process components @@ -43,6 +44,7 @@ type ArgsProcessComponentsHolder struct { StatusCoreComponents factory.StatusCoreComponentsHolder NodesCoordinator nodesCoordinator.NodesCoordinator RunTypeComponents factory.RunTypeComponentsHolder + EnableEpochsFactory enablers.EnableEpochsFactory IncomingHeaderSubscriber process.IncomingHeaderSubscriber Configs config.Configs @@ -196,6 +198,7 @@ func CreateProcessComponents(args ArgsProcessComponentsHolder) (*processComponen GenesisNonce: args.GenesisNonce, GenesisRound: args.GenesisRound, RunTypeComponents: args.RunTypeComponents, + EnableEpochsFactory: args.EnableEpochsFactory, IncomingHeaderSubscriber: args.IncomingHeaderSubscriber, } processComponentsFactory, err := processComp.NewProcessComponentsFactory(processArgs) diff --git a/node/chainSimulator/components/processComponents_test.go b/node/chainSimulator/components/processComponents_test.go index 50f28c2e8ef..12ce95b9f51 100644 --- a/node/chainSimulator/components/processComponents_test.go +++ b/node/chainSimulator/components/processComponents_test.go @@ -247,9 +247,11 @@ func createArgsProcessComponentsHolder() ArgsProcessComponentsHolder { InitialAccounts: initialAccounts, } runTypeComponents, _ := createRunTypeComponents(argsRunType) + runTypeCoreComponents, _ := createRunTypeCoreComponents() args.StateComponents = components.GetStateComponents(args.CoreComponents, args.StatusCoreComponents) args.RunTypeComponents = runTypeComponents + args.EnableEpochsFactory = runTypeCoreComponents.EnableEpochsFactoryCreator() return args } diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index e306b732795..81d7aa2e5f0 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -244,6 +244,7 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces GenesisNonce: args.InitialNonce, GenesisRound: uint64(args.InitialRound), RunTypeComponents: instance.RunTypeComponents, + EnableEpochsFactory: runTypeCoreComponents.EnableEpochsFactoryCreator(), IncomingHeaderSubscriber: instance.IncomingHeaderSubscriber, }) if err != nil { diff --git a/node/nodeRunner.go b/node/nodeRunner.go index d131d9d4e50..b288d4644b0 100644 --- a/node/nodeRunner.go +++ b/node/nodeRunner.go @@ -444,6 +444,7 @@ func (nr *nodeRunner) executeOneComponentCreationCycle( managedStatusComponents, managedStatusCoreComponents, managedRunTypeComponents, + managedRunTypeCoreComponents, gasScheduleNotifier, nodesCoordinatorInstance, ) @@ -1178,6 +1179,7 @@ func (nr *nodeRunner) CreateManagedProcessComponents( statusComponents mainFactory.StatusComponentsHolder, statusCoreComponents mainFactory.StatusCoreComponentsHolder, runTypeComponents mainFactory.RunTypeComponentsHolder, + runTypeCoreComponents mainFactory.RunTypeCoreComponentsHolder, gasScheduleNotifier core.GasScheduleNotifier, nodesCoordinator nodesCoordinator.NodesCoordinator, ) (mainFactory.ProcessComponentsHandler, error) { @@ -1265,6 +1267,7 @@ func (nr *nodeRunner) CreateManagedProcessComponents( TxExecutionOrderHandler: txExecutionOrderHandler, RunTypeComponents: runTypeComponents, IncomingHeaderSubscriber: &factoryDisabled.IncomingHeaderProcessor{}, + EnableEpochsFactory: runTypeCoreComponents.EnableEpochsFactoryCreator(), } processComponentsFactory, err := processComp.NewProcessComponentsFactory(processArgs) if err != nil { @@ -1465,18 +1468,17 @@ func (nr *nodeRunner) CreateManagedCoreComponents( runTypeCoreComponents mainFactory.RunTypeCoreComponentsHolder, ) (mainFactory.CoreComponentsHandler, error) { coreArgs := coreComp.CoreComponentsFactoryArgs{ - Config: *nr.configs.GeneralConfig, - ConfigPathsHolder: *nr.configs.ConfigurationPathsHolder, - EpochConfig: *nr.configs.EpochConfig, - RoundConfig: *nr.configs.RoundConfig, - ImportDbConfig: *nr.configs.ImportDbConfig, - RatingsConfig: *nr.configs.RatingsConfig, - EconomicsConfig: *nr.configs.EconomicsConfig, - NodesFilename: nr.configs.ConfigurationPathsHolder.Nodes, - WorkingDirectory: nr.configs.FlagsConfig.DbDir, - ChanStopNodeProcess: chanStopNodeProcess, - GenesisNodesSetupFactory: runTypeCoreComponents.GenesisNodesSetupFactoryCreator(), - RatingsDataFactory: runTypeCoreComponents.RatingsDataFactoryCreator(), + Config: *nr.configs.GeneralConfig, + ConfigPathsHolder: *nr.configs.ConfigurationPathsHolder, + EpochConfig: *nr.configs.EpochConfig, + RoundConfig: *nr.configs.RoundConfig, + ImportDbConfig: *nr.configs.ImportDbConfig, + RatingsConfig: *nr.configs.RatingsConfig, + EconomicsConfig: *nr.configs.EconomicsConfig, + NodesFilename: nr.configs.ConfigurationPathsHolder.Nodes, + WorkingDirectory: nr.configs.FlagsConfig.DbDir, + ChanStopNodeProcess: chanStopNodeProcess, + RunTypeCoreComponents: runTypeCoreComponents, } coreComponentsFactory, err := coreComp.NewCoreComponentsFactory(coreArgs) diff --git a/sharding/errors.go b/sharding/errors.go index 132b73d41fa..a46ae3fac59 100644 --- a/sharding/errors.go +++ b/sharding/errors.go @@ -41,3 +41,6 @@ var ErrNilOwnPublicKey = errors.New("nil own public key") var ErrNilEndOfProcessingHandler = errors.New("nil end of processing handler") var errSovereignInvalidMetaConsensusSize = errors.New("invalid metachain config for sovereign") + +// ErrNilGenesisNodesSetupFactory signals that a nil genesis nodes setup factory has been provided +var ErrNilGenesisNodesSetupFactory = errors.New("nil genesis nodes setup factory") diff --git a/testscommon/common/enableEpochsFactoryMock.go b/testscommon/common/enableEpochsFactoryMock.go new file mode 100644 index 00000000000..d2519e833dd --- /dev/null +++ b/testscommon/common/enableEpochsFactoryMock.go @@ -0,0 +1,27 @@ +package common + +import ( + "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/sharding/mock" +) + +// EnableEpochsFactoryMock - +type EnableEpochsFactoryMock struct { + CreateEnableEpochsHandlerCaller func(epochConfig config.EpochConfig, epochNotifier process.EpochNotifier) (common.EnableEpochsHandler, error) +} + +// CreateEnableEpochsHandler - +func (f *EnableEpochsFactoryMock) CreateEnableEpochsHandler(epochConfig config.EpochConfig, epochNotifier process.EpochNotifier) (common.EnableEpochsHandler, error) { + if f.CreateEnableEpochsHandlerCaller != nil { + return f.CreateEnableEpochsHandlerCaller(epochConfig, epochNotifier) + } + + return &mock.EnableEpochsHandlerMock{}, nil +} + +// IsInterfaceNil - +func (f *EnableEpochsFactoryMock) IsInterfaceNil() bool { + return f == nil +} diff --git a/testscommon/components/components.go b/testscommon/components/components.go index 05bd4c3bd43..ec360d4dd0d 100644 --- a/testscommon/components/components.go +++ b/testscommon/components/components.go @@ -99,7 +99,7 @@ func GetRunTypeCoreComponents() factory.RunTypeCoreComponentsHolder { // GetSovereignRunTypeCoreComponents - func GetSovereignRunTypeCoreComponents() factory.RunTypeCoreComponentsHolder { - sovRunTypeCoreComponentsFactory := runType.NewSovereignRunTypeCoreComponentsFactory() + sovRunTypeCoreComponentsFactory := runType.NewSovereignRunTypeCoreComponentsFactory(config.SovereignEpochConfig{}) managedRunTypeCoreComponents, err := runType.NewManagedRunTypeCoreComponents(sovRunTypeCoreComponentsFactory) if err != nil { log.Error("GetSovereignRunTypeCoreComponents.NewManagedRunTypeCoreComponents", "error", err.Error()) @@ -143,8 +143,7 @@ func GetCoreArgs() coreComp.CoreComponentsFactoryArgs { }, }, }, - GenesisNodesSetupFactory: runTypeCoreComponents.GenesisNodesSetupFactoryCreator(), - RatingsDataFactory: runTypeCoreComponents.RatingsDataFactoryCreator(), + RunTypeCoreComponents: runTypeCoreComponents, } } @@ -342,8 +341,7 @@ func GetSovereignCoreComponents() factory.CoreComponentsHolder { sovRunTypeCoreComponents := GetSovereignRunTypeCoreComponents() coreArgs := GetCoreArgs() coreArgs.NodesFilename = "../mock/testdata/sovereignNodesSetupMock.json" - coreArgs.GenesisNodesSetupFactory = sovRunTypeCoreComponents.GenesisNodesSetupFactoryCreator() - coreArgs.RatingsDataFactory = sovRunTypeCoreComponents.RatingsDataFactoryCreator() + coreArgs.RunTypeCoreComponents = sovRunTypeCoreComponents return createCoreComponents(coreArgs) } @@ -690,8 +688,8 @@ func GetProcessArgs( }, nil }, } - args.RunTypeComponents = runTypeComponents + args.EnableEpochsFactory = GetRunTypeCoreComponents().EnableEpochsFactoryCreator() return args } @@ -746,6 +744,7 @@ func GetSovereignProcessArgs( processArgs.StatusCoreComponents = statusCoreComponents processArgs.IncomingHeaderSubscriber = &sovereign.IncomingHeaderSubscriberStub{} processArgs.RunTypeComponents = runTypeComponents + processArgs.EnableEpochsFactory = GetSovereignRunTypeCoreComponents().EnableEpochsFactoryCreator() return processArgs } diff --git a/testscommon/genesisMocks/runTypeCoreComponentsStub.go b/testscommon/genesisMocks/runTypeCoreComponentsStub.go new file mode 100644 index 00000000000..4b81d0b7c80 --- /dev/null +++ b/testscommon/genesisMocks/runTypeCoreComponentsStub.go @@ -0,0 +1,75 @@ +package genesisMocks + +import ( + "github.com/multiversx/mx-chain-go/common/enablers" + "github.com/multiversx/mx-chain-go/config" + genesisMocks "github.com/multiversx/mx-chain-go/genesis/mock" + "github.com/multiversx/mx-chain-go/process/rating" + "github.com/multiversx/mx-chain-go/sharding" + "github.com/multiversx/mx-chain-go/testscommon" +) + +// RunTypeCoreComponentsStub - +type RunTypeCoreComponentsStub struct { + GenesisNodesSetupFactory sharding.GenesisNodesSetupFactory + RatingsDataFactory rating.RatingsDataFactory + EnableEpochsFactory enablers.EnableEpochsFactory +} + +// NewRunTypeCoreComponentsStub - +func NewRunTypeCoreComponentsStub() *RunTypeCoreComponentsStub { + return &RunTypeCoreComponentsStub{ + GenesisNodesSetupFactory: &genesisMocks.GenesisNodesSetupFactoryMock{}, + RatingsDataFactory: &testscommon.RatingsDataFactoryMock{}, + EnableEpochsFactory: enablers.NewEnableEpochsFactory(), + } +} + +// NewSovereignRunTypeCoreComponentsStub - +func NewSovereignRunTypeCoreComponentsStub() *RunTypeCoreComponentsStub { + return &RunTypeCoreComponentsStub{ + GenesisNodesSetupFactory: &genesisMocks.GenesisNodesSetupFactoryMock{}, + RatingsDataFactory: &testscommon.RatingsDataFactoryMock{}, + EnableEpochsFactory: enablers.NewSovereignEnableEpochsFactory(config.SovereignEpochConfig{}), + } +} + +// Create - +func (r *RunTypeCoreComponentsStub) Create() error { + return nil +} + +// Close - +func (r *RunTypeCoreComponentsStub) Close() error { + return nil +} + +// CheckSubcomponents - +func (r *RunTypeCoreComponentsStub) CheckSubcomponents() error { + return nil +} + +// String - +func (r *RunTypeCoreComponentsStub) String() string { + return "" +} + +// GenesisNodesSetupFactoryCreator - +func (r *RunTypeCoreComponentsStub) GenesisNodesSetupFactoryCreator() sharding.GenesisNodesSetupFactory { + return r.GenesisNodesSetupFactory +} + +// RatingsDataFactoryCreator - +func (r *RunTypeCoreComponentsStub) RatingsDataFactoryCreator() rating.RatingsDataFactory { + return r.RatingsDataFactory +} + +// EnableEpochsFactoryCreator - +func (r *RunTypeCoreComponentsStub) EnableEpochsFactoryCreator() enablers.EnableEpochsFactory { + return r.EnableEpochsFactory +} + +// IsInterfaceNil - +func (r *RunTypeCoreComponentsStub) IsInterfaceNil() bool { + return r == nil +} diff --git a/testscommon/mainFactoryMocks/runTypeComponentStub.go b/testscommon/mainFactoryMocks/runTypeComponentStub.go index d3814f681e5..88828ecd47b 100644 --- a/testscommon/mainFactoryMocks/runTypeComponentStub.go +++ b/testscommon/mainFactoryMocks/runTypeComponentStub.go @@ -177,7 +177,7 @@ func (r *RunTypeComponentsStub) CheckSubcomponents() error { return nil } -// BlockChainHookHandlerCreator - +// String - func (r *RunTypeComponentsStub) String() string { return "" } diff --git a/testscommon/ratingsDataFactoryMock.go b/testscommon/ratingsDataFactoryMock.go new file mode 100644 index 00000000000..06789b08f92 --- /dev/null +++ b/testscommon/ratingsDataFactoryMock.go @@ -0,0 +1,25 @@ +package testscommon + +import ( + "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/process/rating" +) + +// RatingsDataFactoryMock - +type RatingsDataFactoryMock struct { + CreateRatingsDataCalled func(args rating.RatingsDataArg) (process.RatingsInfoHandler, error) +} + +// CreateRatingsData - +func (f *RatingsDataFactoryMock) CreateRatingsData(args rating.RatingsDataArg) (process.RatingsInfoHandler, error) { + if f.CreateRatingsDataCalled != nil { + return f.CreateRatingsDataCalled(args) + } + + return &RatingsInfoMock{}, nil +} + +// IsInterfaceNil - +func (f *RatingsDataFactoryMock) IsInterfaceNil() bool { + return f == nil +} diff --git a/update/mock/nodesSetupHandlerStub.go b/update/mock/nodesSetupHandlerStub.go index 499e14187c2..a5841385d69 100644 --- a/update/mock/nodesSetupHandlerStub.go +++ b/update/mock/nodesSetupHandlerStub.go @@ -8,20 +8,28 @@ import ( // GenesisNodesSetupHandlerStub - type GenesisNodesSetupHandlerStub struct { - InitialNodesInfoForShardCalled func(shardId uint32) ([]nodesCoordinator.GenesisNodeInfoHandler, []nodesCoordinator.GenesisNodeInfoHandler, error) - InitialNodesInfoCalled func() (map[uint32][]nodesCoordinator.GenesisNodeInfoHandler, map[uint32][]nodesCoordinator.GenesisNodeInfoHandler) - GetStartTimeCalled func() int64 - GetRoundDurationCalled func() uint64 - GetChainIdCalled func() string - GetMinTransactionVersionCalled func() uint32 - GetShardConsensusGroupSizeCalled func() uint32 - GetMetaConsensusGroupSizeCalled func() uint32 - MinNumberOfShardNodesCalled func() uint32 - MinNumberOfMetaNodesCalled func() uint32 - GetHysteresisCalled func() float32 - GetAdaptivityCalled func() bool - NumberOfShardsCalled func() uint32 - MinNumberOfNodesCalled func() uint32 + InitialNodesInfoForShardCalled func(shardId uint32) ([]nodesCoordinator.GenesisNodeInfoHandler, []nodesCoordinator.GenesisNodeInfoHandler, error) + InitialNodesInfoCalled func() (map[uint32][]nodesCoordinator.GenesisNodeInfoHandler, map[uint32][]nodesCoordinator.GenesisNodeInfoHandler) + GetStartTimeCalled func() int64 + GetRoundDurationCalled func() uint64 + GetChainIdCalled func() string + GetMinTransactionVersionCalled func() uint32 + GetShardConsensusGroupSizeCalled func() uint32 + GetMetaConsensusGroupSizeCalled func() uint32 + MinNumberOfShardNodesCalled func() uint32 + MinNumberOfMetaNodesCalled func() uint32 + GetHysteresisCalled func() float32 + GetAdaptivityCalled func() bool + NumberOfShardsCalled func() uint32 + MinNumberOfNodesCalled func() uint32 + AllInitialNodesCalled func() []nodesCoordinator.GenesisNodeInfoHandler + InitialNodesPubKeysCalled func() map[uint32][]string + GetShardIDForPubKeyCalled func(pubkey []byte) (uint32, error) + InitialEligibleNodesPubKeysForShardCalled func(shardId uint32) ([]string, error) + SetStartTimeCalled func(startTime int64) + MinNumberOfNodesWithHysteresisCalled func() uint32 + MinShardHysteresisNodesCalled func() uint32 + MinMetaHysteresisNodesCalled func() uint32 } // InitialNodesInfoForShard - @@ -150,6 +158,76 @@ func (g *GenesisNodesSetupHandlerStub) MinNumberOfNodes() uint32 { return 1 } +// AllInitialNodes - +func (g *GenesisNodesSetupHandlerStub) AllInitialNodes() []nodesCoordinator.GenesisNodeInfoHandler { + if g.AllInitialNodesCalled != nil { + return g.AllInitialNodesCalled() + } + + return nil +} + +// InitialNodesPubKeys - +func (g *GenesisNodesSetupHandlerStub) InitialNodesPubKeys() map[uint32][]string { + if g.InitialNodesPubKeysCalled != nil { + return g.InitialNodesPubKeysCalled() + } + + return nil +} + +// GetShardIDForPubKey - +func (g *GenesisNodesSetupHandlerStub) GetShardIDForPubKey(pubkey []byte) (uint32, error) { + if g.GetShardIDForPubKeyCalled != nil { + return g.GetShardIDForPubKeyCalled(pubkey) + } + + return 0, nil +} + +// InitialEligibleNodesPubKeysForShard - +func (g *GenesisNodesSetupHandlerStub) InitialEligibleNodesPubKeysForShard(shardId uint32) ([]string, error) { + if g.InitialEligibleNodesPubKeysForShardCalled != nil { + return g.InitialEligibleNodesPubKeysForShardCalled(shardId) + } + + return nil, nil +} + +// SetStartTime - +func (g *GenesisNodesSetupHandlerStub) SetStartTime(startTime int64) { + if g.SetStartTimeCalled != nil { + g.SetStartTimeCalled(startTime) + } +} + +// MinNumberOfNodesWithHysteresis - +func (g *GenesisNodesSetupHandlerStub) MinNumberOfNodesWithHysteresis() uint32 { + if g.MinNumberOfNodesWithHysteresisCalled != nil { + return g.MinNumberOfNodesWithHysteresisCalled() + } + + return 0 +} + +// MinShardHysteresisNodes - +func (g *GenesisNodesSetupHandlerStub) MinShardHysteresisNodes() uint32 { + if g.MinShardHysteresisNodesCalled != nil { + return g.MinShardHysteresisNodesCalled() + } + + return 0 +} + +// MinMetaHysteresisNodes - +func (g *GenesisNodesSetupHandlerStub) MinMetaHysteresisNodes() uint32 { + if g.MinMetaHysteresisNodesCalled != nil { + return g.MinMetaHysteresisNodesCalled() + } + + return 0 +} + // IsInterfaceNil - func (g *GenesisNodesSetupHandlerStub) IsInterfaceNil() bool { return g == nil