From 06ec4812b0041ad6599d5d04b77f21e38e175feb Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Fri, 22 Nov 2024 16:58:03 +0200 Subject: [PATCH 01/23] sovereign enable epochs handler components --- cmd/sovereignnode/config/enableEpochs.toml | 4 ++ .../enablers/sovereignEnableEpochsHandler.go | 68 +++++++++++++++++++ .../sovereignEnableEpochsHandler_test.go | 38 +++++++++++ config/epochConfig.go | 12 +++- 4 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 common/enablers/sovereignEnableEpochsHandler.go create mode 100644 common/enablers/sovereignEnableEpochsHandler_test.go diff --git a/cmd/sovereignnode/config/enableEpochs.toml b/cmd/sovereignnode/config/enableEpochs.toml index eab8edf5055..5d765af378c 100644 --- a/cmd/sovereignnode/config/enableEpochs.toml +++ b/cmd/sovereignnode/config/enableEpochs.toml @@ -258,3 +258,7 @@ GasScheduleByEpochs = [ { StartEpoch = 0, FileName = "gasScheduleV7.toml" }, ] + +[SovereignEnableEpochs] + +[SovereignChainSpecificEnableEpochs] diff --git a/common/enablers/sovereignEnableEpochsHandler.go b/common/enablers/sovereignEnableEpochsHandler.go new file mode 100644 index 00000000000..115a1d379b6 --- /dev/null +++ b/common/enablers/sovereignEnableEpochsHandler.go @@ -0,0 +1,68 @@ +package enablers + +import ( + "github.com/multiversx/mx-chain-core-go/core" + "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, + sovereignEnableEpochsConfig config.SovereignEnableEpochs, + sovereignChainSpecificEnableEpochsConfig config.SovereignChainSpecificEnableEpochs, + epochNotifier process.EpochNotifier, +) (*sovereignEnableEpochsHandler, error) { + if check.IfNil(epochNotifier) { + return nil, process.ErrNilEpochNotifier + } + + sovHandler := &sovereignEnableEpochsHandler{ + enableEpochsHandler: &enableEpochsHandler{ + enableEpochsConfig: enableEpochsConfig, + }, + sovereignEnableEpochsConfig: sovereignEnableEpochsConfig, + sovereignChainSpecificEnableEpochsConfig: sovereignChainSpecificEnableEpochsConfig, + } + + sovHandler.createAllFlagsMap() + + epochNotifier.RegisterNotifyHandler(sovHandler) + + return sovHandler, nil +} + +func (sovHandler *sovereignEnableEpochsHandler) createAllFlagsMap() { + sovHandler.enableEpochsHandler.createAllFlagsMap() + sovHandler.addSovereignFlags() + sovHandler.addSovereignChainSpecificFlags() +} + +func (sovHandler *sovereignEnableEpochsHandler) addSovereignFlags() { + sovereignFlags := map[core.EnableEpochFlag]flagHandler{} + + for key, value := range sovereignFlags { + sovHandler.enableEpochsHandler.allFlagsDefined[key] = value + } +} + +func (sovHandler *sovereignEnableEpochsHandler) addSovereignChainSpecificFlags() { + sovereignChainSpecificFlags := map[core.EnableEpochFlag]flagHandler{} + + for key, value := range sovereignChainSpecificFlags { + sovHandler.enableEpochsHandler.allFlagsDefined[key] = value + } +} + +// 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..1c90a13ade6 --- /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.SovereignEnableEpochs{}, config.SovereignChainSpecificEnableEpochs{}, 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.SovereignEnableEpochs{}, config.SovereignChainSpecificEnableEpochs{}, &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/epochConfig.go b/config/epochConfig.go index 0fc78e95853..d52b9860410 100644 --- a/config/epochConfig.go +++ b/config/epochConfig.go @@ -2,8 +2,10 @@ package config // EpochConfig will hold epoch configurations type EpochConfig struct { - EnableEpochs EnableEpochs - GasSchedule GasScheduleConfig + EnableEpochs EnableEpochs + SovereignEnableEpochs SovereignEnableEpochs + SovereignChainSpecificEnableEpochs SovereignChainSpecificEnableEpochs + GasSchedule GasScheduleConfig } // GasScheduleConfig represents the versioning config area for the gas schedule toml @@ -126,6 +128,12 @@ type EnableEpochs struct { BLSMultiSignerEnableEpoch []MultiSignerConfig } +// 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{} + // GasScheduleByEpochs represents a gas schedule toml entry that will be applied from the provided epoch type GasScheduleByEpochs struct { StartEpoch uint32 From 616fb58d20c189f9be659560dd2ba52290f8761d Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Fri, 22 Nov 2024 17:40:12 +0200 Subject: [PATCH 02/23] enable epoch handler in run type core components --- cmd/sovereignnode/sovereignNodeRunner.go | 7 +++- errors/errors.go | 3 ++ factory/interface.go | 4 +- factory/runType/interface.go | 2 +- factory/runType/runTypeCoreComponents.go | 2 + .../runType/runTypeCoreComponentsFactory.go | 23 ++++++++-- .../runType/runTypeCoreComponentsHandler.go | 22 +++++++++- .../runTypeCoreComponentsHandler_test.go | 7 +++- factory/runType/runTypeCoreComponents_test.go | 13 +++--- .../runType/sovereignRunTypeCoreComponents.go | 29 +++++++++++-- .../sovereignRunTypeCoreComponents_test.go | 22 +++++++--- node/chainSimulator/chainSimulator.go | 42 +++++++++---------- .../components/testOnlyProcessingNode.go | 4 +- node/nodeRunner.go | 2 +- testscommon/components/components.go | 9 +++- 15 files changed, 141 insertions(+), 50 deletions(-) diff --git a/cmd/sovereignnode/sovereignNodeRunner.go b/cmd/sovereignnode/sovereignNodeRunner.go index 66d6c276467..457ee6b3809 100644 --- a/cmd/sovereignnode/sovereignNodeRunner.go +++ b/cmd/sovereignnode/sovereignNodeRunner.go @@ -1678,7 +1678,12 @@ func (snr *sovereignNodeRunner) CreateManagedCryptoComponents( // CreateManagedRunTypeCoreComponents creates the managed run type core components func (snr *sovereignNodeRunner) CreateManagedRunTypeCoreComponents() (mainFactory.RunTypeCoreComponentsHandler, error) { - sovereignRunTypeCoreComponentsFactory := runType.NewSovereignRunTypeCoreComponentsFactory() + runTypeCoreComponents := runType.NewRunTypeCoreComponentsFactory(*snr.configs.EpochConfig) + sovereignRunTypeCoreComponentsFactory, err := runType.NewSovereignRunTypeCoreComponentsFactory(runTypeCoreComponents) + if err != nil { + return nil, err + } + managedRunTypeCoreComponents, err := runType.NewManagedRunTypeCoreComponents(sovereignRunTypeCoreComponentsFactory) if err != nil { return nil, err diff --git a/errors/errors.go b/errors/errors.go index 9dbda39b716..ba624dd9087 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -451,6 +451,9 @@ var ErrStateComponentsFactoryCreate = errors.New("stateComponentsFactory create // ErrRunTypeComponentsFactoryCreate signals that an error occured on runTypeComponentsFactory create var ErrRunTypeComponentsFactoryCreate = errors.New("runTypeComponentsFactory create failed") +// ErrRunTypeCoreComponentsFactoryCreate signals that an error occured on runTypeCoreComponentsFactory create +var ErrRunTypeCoreComponentsFactoryCreate = errors.New("runTypeCoreComponentsFactory create failed") + // ErrStatusComponentsFactoryCreate signals that an error occured on statusComponentsFactory create var ErrStatusComponentsFactoryCreate = errors.New("statusComponentsFactory create failed") diff --git a/factory/interface.go b/factory/interface.go index f81e153988f..4d88135840e 100644 --- a/factory/interface.go +++ b/factory/interface.go @@ -14,6 +14,8 @@ import ( "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" crypto "github.com/multiversx/mx-chain-crypto-go" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "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" @@ -66,7 +68,6 @@ import ( "github.com/multiversx/mx-chain-go/update" "github.com/multiversx/mx-chain-go/vm" "github.com/multiversx/mx-chain-go/vm/systemSmartContracts" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) // EpochStartNotifier defines which actions should be done for handling new epoch's events @@ -658,6 +659,7 @@ type RunTypeCoreComponentsHandler interface { type RunTypeCoreComponentsHolder interface { GenesisNodesSetupFactoryCreator() sharding.GenesisNodesSetupFactory RatingsDataFactoryCreator() rating.RatingsDataFactory + EnableEpochsHandler() common.EnableEpochsHandler Create() error Close() error CheckSubcomponents() error diff --git a/factory/runType/interface.go b/factory/runType/interface.go index 502dd02703c..84780aa6d62 100644 --- a/factory/runType/interface.go +++ b/factory/runType/interface.go @@ -7,6 +7,6 @@ type runTypeComponentsCreator interface { } type runTypeCoreComponentsCreator interface { - Create() *runTypeCoreComponents + Create() (*runTypeCoreComponents, error) IsInterfaceNil() bool } diff --git a/factory/runType/runTypeCoreComponents.go b/factory/runType/runTypeCoreComponents.go index 2de2f25fc93..d0dbef4a4e4 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" "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 + enableEpochsHandler common.EnableEpochsHandler } // Close does nothing diff --git a/factory/runType/runTypeCoreComponentsFactory.go b/factory/runType/runTypeCoreComponentsFactory.go index bf34c7ed37c..f90d4f2a00f 100644 --- a/factory/runType/runTypeCoreComponentsFactory.go +++ b/factory/runType/runTypeCoreComponentsFactory.go @@ -1,24 +1,39 @@ package runType import ( + "fmt" + + "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/process/rating" "github.com/multiversx/mx-chain-go/sharding" ) type runTypeCoreComponentsFactory struct { + epochConfig config.EpochConfig } // NewRunTypeCoreComponentsFactory will return a new instance of runTypeCoreComponentsFactory -func NewRunTypeCoreComponentsFactory() *runTypeCoreComponentsFactory { - return &runTypeCoreComponentsFactory{} +func NewRunTypeCoreComponentsFactory(epochConfig config.EpochConfig) *runTypeCoreComponentsFactory { + return &runTypeCoreComponentsFactory{ + epochConfig: epochConfig, + } } // Create will create the runType core components -func (rccf *runTypeCoreComponentsFactory) Create() *runTypeCoreComponents { +func (rccf *runTypeCoreComponentsFactory) Create() (*runTypeCoreComponents, error) { + epochNotifier := forking.NewGenericEpochNotifier() + enableEpochsHandler, err := enablers.NewEnableEpochsHandler(rccf.epochConfig.EnableEpochs, epochNotifier) + if err != nil { + return nil, fmt.Errorf("runTypeCoreComponentsFactory - NewEnableEpochsHandler failed: %w", err) + } + return &runTypeCoreComponents{ genesisNodesSetupFactory: sharding.NewGenesisNodesSetupFactory(), ratingsDataFactory: rating.NewRatingsDataFactory(), - } + enableEpochsHandler: enableEpochsHandler, + }, nil } // IsInterfaceNil returns true if there is no value under the interface diff --git a/factory/runType/runTypeCoreComponentsHandler.go b/factory/runType/runTypeCoreComponentsHandler.go index f9bc4b5331c..a2fd1460518 100644 --- a/factory/runType/runTypeCoreComponentsHandler.go +++ b/factory/runType/runTypeCoreComponentsHandler.go @@ -1,10 +1,12 @@ package runType import ( + "fmt" "sync" "github.com/multiversx/mx-chain-core-go/core/check" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/factory" "github.com/multiversx/mx-chain-go/process/rating" @@ -35,7 +37,10 @@ func NewManagedRunTypeCoreComponents(rcf runTypeCoreComponentsCreator) (*managed // Create will create the managed components func (mrcc *managedRunTypeCoreComponents) Create() error { - rtc := mrcc.factory.Create() + rtc, err := mrcc.factory.Create() + if err != nil { + return fmt.Errorf("%w: %v", errors.ErrRunTypeCoreComponentsFactoryCreate, err) + } mrcc.mutRunTypeCoreComponents.Lock() mrcc.runTypeCoreComponents = rtc @@ -52,6 +57,9 @@ func (mrcc *managedRunTypeCoreComponents) Close() error { if check.IfNil(mrcc.runTypeCoreComponents) { return nil } + if check.IfNil(mrcc.enableEpochsHandler) { + return errors.ErrNilEnableEpochsHandler + } err := mrcc.runTypeCoreComponents.Close() if err != nil { @@ -103,6 +111,18 @@ func (mrcc *managedRunTypeCoreComponents) RatingsDataFactoryCreator() rating.Rat return mrcc.runTypeCoreComponents.ratingsDataFactory } +// EnableEpochsHandler returns enable epochs handler +func (mrcc *managedRunTypeCoreComponents) EnableEpochsHandler() common.EnableEpochsHandler { + mrcc.mutRunTypeCoreComponents.RLock() + defer mrcc.mutRunTypeCoreComponents.RUnlock() + + if check.IfNil(mrcc.runTypeCoreComponents) { + return nil + } + + return mrcc.runTypeCoreComponents.enableEpochsHandler +} + // 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..a43b15a017f 100644 --- a/factory/runType/runTypeCoreComponentsHandler_test.go +++ b/factory/runType/runTypeCoreComponentsHandler_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/errors" "github.com/multiversx/mx-chain-go/factory" "github.com/multiversx/mx-chain-go/factory/runType" ) func createCoreComponents() (factory.RunTypeCoreComponentsHandler, error) { - rccf := runType.NewRunTypeCoreComponentsFactory() + rccf := runType.NewRunTypeCoreComponentsFactory(config.EpochConfig{}) return runType.NewManagedRunTypeCoreComponents(rccf) } @@ -24,7 +25,7 @@ func TestNewManagedRunTypeCoreComponents(t *testing.T) { require.True(t, managedRunTypeCoreComponents.IsInterfaceNil()) }) t.Run("should work", func(t *testing.T) { - rccf := runType.NewRunTypeCoreComponentsFactory() + rccf := runType.NewRunTypeCoreComponentsFactory(config.EpochConfig{}) managedRunTypeCoreComponents, err := runType.NewManagedRunTypeCoreComponents(rccf) require.NoError(t, err) require.False(t, managedRunTypeCoreComponents.IsInterfaceNil()) @@ -42,12 +43,14 @@ func TestManagedRunTypeCoreComponents_Create(t *testing.T) { require.Nil(t, managedRunTypeCoreComponents.GenesisNodesSetupFactoryCreator()) require.Nil(t, managedRunTypeCoreComponents.RatingsDataFactoryCreator()) + require.Nil(t, managedRunTypeCoreComponents.EnableEpochsHandler()) err = managedRunTypeCoreComponents.Create() require.NoError(t, err) require.NotNil(t, managedRunTypeCoreComponents.GenesisNodesSetupFactoryCreator()) require.NotNil(t, managedRunTypeCoreComponents.RatingsDataFactoryCreator()) + require.NotNil(t, managedRunTypeCoreComponents.EnableEpochsHandler()) require.Equal(t, factory.RunTypeCoreComponentsName, managedRunTypeCoreComponents.String()) require.NoError(t, managedRunTypeCoreComponents.Close()) diff --git a/factory/runType/runTypeCoreComponents_test.go b/factory/runType/runTypeCoreComponents_test.go index e37cc82000d..995c9991761 100644 --- a/factory/runType/runTypeCoreComponents_test.go +++ b/factory/runType/runTypeCoreComponents_test.go @@ -5,6 +5,7 @@ import ( "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/factory/runType" ) @@ -12,7 +13,7 @@ func TestNewRunTypeCoreComponentsFactory(t *testing.T) { t.Parallel() t.Run("should work", func(t *testing.T) { - rccf := runType.NewRunTypeCoreComponentsFactory() + rccf := runType.NewRunTypeCoreComponentsFactory(config.EpochConfig{}) require.NotNil(t, rccf) }) } @@ -20,20 +21,22 @@ func TestNewRunTypeCoreComponentsFactory(t *testing.T) { func TestRunTypeCoreComponentsFactory_Create(t *testing.T) { t.Parallel() - rccf := runType.NewRunTypeCoreComponentsFactory() + rccf := runType.NewRunTypeCoreComponentsFactory(config.EpochConfig{}) require.NotNil(t, rccf) - rcc := rccf.Create() + rcc, err := rccf.Create() + require.NoError(t, err) require.NotNil(t, rcc) } func TestRunTypeCoreComponentsFactory_Close(t *testing.T) { t.Parallel() - rccf := runType.NewRunTypeCoreComponentsFactory() + rccf := runType.NewRunTypeCoreComponentsFactory(config.EpochConfig{}) require.NotNil(t, rccf) - rcc := rccf.Create() + rcc, err := rccf.Create() + require.NoError(t, err) require.NotNil(t, rcc) require.NoError(t, rcc.Close()) diff --git a/factory/runType/sovereignRunTypeCoreComponents.go b/factory/runType/sovereignRunTypeCoreComponents.go index 8a9730d00f8..e1d82f12f2f 100644 --- a/factory/runType/sovereignRunTypeCoreComponents.go +++ b/factory/runType/sovereignRunTypeCoreComponents.go @@ -1,24 +1,45 @@ package runType import ( + "fmt" + + "github.com/multiversx/mx-chain-core-go/core/check" + + "github.com/multiversx/mx-chain-go/common/enablers" + "github.com/multiversx/mx-chain-go/common/forking" + errorsMx "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/process/rating" "github.com/multiversx/mx-chain-go/sharding" ) type sovereignRunTypeCoreComponentsFactory struct { + *runTypeCoreComponentsFactory } // NewSovereignRunTypeCoreComponentsFactory will return a new instance of sovereign runType core components factory -func NewSovereignRunTypeCoreComponentsFactory() *sovereignRunTypeCoreComponentsFactory { - return &sovereignRunTypeCoreComponentsFactory{} +func NewSovereignRunTypeCoreComponentsFactory(rtcc *runTypeCoreComponentsFactory) (*sovereignRunTypeCoreComponentsFactory, error) { + if check.IfNil(rtcc) { + return nil, errorsMx.ErrNilRunTypeCoreComponentsFactory + } + + return &sovereignRunTypeCoreComponentsFactory{ + runTypeCoreComponentsFactory: rtcc, + }, nil } // Create will return a new instance of runType core components -func (srccf *sovereignRunTypeCoreComponentsFactory) Create() *runTypeCoreComponents { +func (srccf *sovereignRunTypeCoreComponentsFactory) Create() (*runTypeCoreComponents, error) { + epochNotifier := forking.NewGenericEpochNotifier() + sovEnableEpochsHandler, err := enablers.NewSovereignEnableEpochsHandler(srccf.epochConfig.EnableEpochs, srccf.epochConfig.SovereignEnableEpochs, srccf.epochConfig.SovereignChainSpecificEnableEpochs, epochNotifier) + if err != nil { + return nil, fmt.Errorf("sovereignRunTypeCoreComponentsFactory - NewSovereignEnableEpochsHandler failed: %w", err) + } + return &runTypeCoreComponents{ genesisNodesSetupFactory: sharding.NewSovereignGenesisNodesSetupFactory(), ratingsDataFactory: rating.NewSovereignRatingsDataFactory(), - } + enableEpochsHandler: sovEnableEpochsHandler, + }, nil } // IsInterfaceNil returns true if there is no value under the interface diff --git a/factory/runType/sovereignRunTypeCoreComponents_test.go b/factory/runType/sovereignRunTypeCoreComponents_test.go index 650f2f3f33d..9baa81ddd3d 100644 --- a/factory/runType/sovereignRunTypeCoreComponents_test.go +++ b/factory/runType/sovereignRunTypeCoreComponents_test.go @@ -5,17 +5,29 @@ import ( "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/config" + errorsMx "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/factory/runType" ) func TestSovereignRunTypeCoreComponentsFactory_CreateAndClose(t *testing.T) { t.Parallel() - srccf := runType.NewSovereignRunTypeCoreComponentsFactory() - require.NotNil(t, srccf) + t.Run("nil run type core components factory", func(t *testing.T) { + srccf, err := runType.NewSovereignRunTypeCoreComponentsFactory(nil) + require.Nil(t, srccf) + require.ErrorIs(t, errorsMx.ErrNilRunTypeCoreComponentsFactory, err) + }) + t.Run("should work", func(t *testing.T) { + rccf := runType.NewRunTypeCoreComponentsFactory(config.EpochConfig{}) + srccf, err := runType.NewSovereignRunTypeCoreComponentsFactory(rccf) + require.NoError(t, err) + require.NotNil(t, srccf) - rcc := srccf.Create() - require.NotNil(t, rcc) + rcc, err := srccf.Create() + require.NoError(t, err) + require.NotNil(t, rcc) - require.NoError(t, rcc.Close()) + require.NoError(t, rcc.Close()) + }) } diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index f717967ffb7..5491601a851 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -65,7 +65,7 @@ type ArgsChainSimulator struct { ApiInterface components.APIConfigurator AlterConfigsFunction func(cfg *config.Configs) VmQueryDelayAfterStartInMs uint64 - CreateRunTypeCoreComponents func() (factory.RunTypeCoreComponentsHolder, error) + CreateRunTypeCoreComponents func(epochConfig config.EpochConfig) (factory.RunTypeCoreComponentsHolder, error) CreateIncomingHeaderSubscriber func(config *config.NotifierConfig, dataPool dataRetriever.PoolsHolder, mainChainNotarizationStartRound uint64, runTypeComponents factory.RunTypeComponentsHolder) (processing.IncomingHeaderSubscriber, error) CreateRunTypeComponents func(args runType.ArgsRunTypeComponents) (factory.RunTypeComponentsHolder, error) NodeFactory node.NodeFactory @@ -124,8 +124,8 @@ func NewBaseChainSimulator(args ArgsBaseChainSimulator) (*simulator, error) { func setSimulatorRunTypeArguments(args *ArgsChainSimulator) { if args.CreateRunTypeCoreComponents == nil { - args.CreateRunTypeCoreComponents = func() (factory.RunTypeCoreComponentsHolder, error) { - return createRunTypeCoreComponents() + args.CreateRunTypeCoreComponents = func(epochConfig config.EpochConfig) (factory.RunTypeCoreComponentsHolder, error) { + return createRunTypeCoreComponents(epochConfig) } } if args.CreateIncomingHeaderSubscriber == nil { @@ -146,8 +146,8 @@ func setSimulatorRunTypeArguments(args *ArgsChainSimulator) { } } -func createRunTypeCoreComponents() (factory.RunTypeCoreComponentsHolder, error) { - runTypeCoreComponentsFactory := runType.NewRunTypeCoreComponentsFactory() +func createRunTypeCoreComponents(epochConfig config.EpochConfig) (factory.RunTypeCoreComponentsHolder, error) { + runTypeCoreComponentsFactory := runType.NewRunTypeCoreComponentsFactory(epochConfig) managedRunTypeCoreComponents, err := runType.NewManagedRunTypeCoreComponents(runTypeCoreComponentsFactory) if err != nil { return nil, err @@ -269,22 +269,22 @@ func (s *simulator) createTestNode( outputConfigs configs.ArgsConfigsSimulator, args ArgsBaseChainSimulator, shardIDStr string, ) (process.NodeHandler, error) { argsTestOnlyProcessorNode := components.ArgsTestOnlyProcessingNode{ - Configs: outputConfigs.Configs, - ChanStopNodeProcess: s.chanStopNodeProcess, - SyncedBroadcastNetwork: s.syncedBroadcastNetwork, - NumShards: s.numOfShards, - GasScheduleFilename: outputConfigs.GasScheduleFilename, - ShardIDStr: shardIDStr, - APIInterface: args.ApiInterface, - BypassTxSignatureCheck: args.BypassTxSignatureCheck, - InitialRound: args.InitialRound, - InitialNonce: args.InitialNonce, - MinNodesPerShard: args.MinNodesPerShard, - ConsensusGroupSize: args.ConsensusGroupSize, - MinNodesMeta: args.MetaChainMinNodes, - MetaChainConsensusGroupSize: args.MetaChainConsensusGroupSize, - RoundDurationInMillis: args.RoundDurationInMillis, - VmQueryDelayAfterStartInMs: args.VmQueryDelayAfterStartInMs, + Configs: outputConfigs.Configs, + ChanStopNodeProcess: s.chanStopNodeProcess, + SyncedBroadcastNetwork: s.syncedBroadcastNetwork, + NumShards: s.numOfShards, + GasScheduleFilename: outputConfigs.GasScheduleFilename, + ShardIDStr: shardIDStr, + APIInterface: args.ApiInterface, + BypassTxSignatureCheck: args.BypassTxSignatureCheck, + InitialRound: args.InitialRound, + InitialNonce: args.InitialNonce, + MinNodesPerShard: args.MinNodesPerShard, + ConsensusGroupSize: args.ConsensusGroupSize, + MinNodesMeta: args.MetaChainMinNodes, + MetaChainConsensusGroupSize: args.MetaChainConsensusGroupSize, + RoundDurationInMillis: args.RoundDurationInMillis, + VmQueryDelayAfterStartInMs: args.VmQueryDelayAfterStartInMs, CreateRunTypeCoreComponents: args.CreateRunTypeCoreComponents, CreateIncomingHeaderSubscriber: args.CreateIncomingHeaderSubscriber, CreateRunTypeComponents: args.CreateRunTypeComponents, diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index 46b0d831713..f24bf79e3fe 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -37,7 +37,7 @@ import ( type ArgsTestOnlyProcessingNode struct { Configs config.Configs APIInterface APIConfigurator - CreateRunTypeCoreComponents func() (factory.RunTypeCoreComponentsHolder, error) + CreateRunTypeCoreComponents func(epochConfig config.EpochConfig) (factory.RunTypeCoreComponentsHolder, error) CreateIncomingHeaderSubscriber func(config *config.NotifierConfig, dataPool dataRetriever.PoolsHolder, mainChainNotarizationStartRound uint64, runTypeComponents factory.RunTypeComponentsHolder) (process.IncomingHeaderSubscriber, error) CreateRunTypeComponents func(args runType.ArgsRunTypeComponents) (factory.RunTypeComponentsHolder, error) NodeFactory node.NodeFactory @@ -96,7 +96,7 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces var err error instance.TransactionFeeHandler = postprocess.NewFeeAccumulator() - runTypeCoreComponents, err := args.CreateRunTypeCoreComponents() + runTypeCoreComponents, err := args.CreateRunTypeCoreComponents(*args.Configs.EpochConfig) if err != nil { return nil, err } diff --git a/node/nodeRunner.go b/node/nodeRunner.go index 79a5fd91d08..3136a284790 100644 --- a/node/nodeRunner.go +++ b/node/nodeRunner.go @@ -1570,7 +1570,7 @@ func (nr *nodeRunner) CreateManagedCryptoComponents( // CreateManagedRunTypeCoreComponents creates the managed run type core components func (nr *nodeRunner) CreateManagedRunTypeCoreComponents() (mainFactory.RunTypeCoreComponentsHandler, error) { - runTypeCoreComponentsFactory := runType.NewRunTypeCoreComponentsFactory() + runTypeCoreComponentsFactory := runType.NewRunTypeCoreComponentsFactory(*nr.configs.EpochConfig) managedRunTypeCoreComponents, err := runType.NewManagedRunTypeCoreComponents(runTypeCoreComponentsFactory) if err != nil { diff --git a/testscommon/components/components.go b/testscommon/components/components.go index 6bc286b3cc1..7366ffa9dce 100644 --- a/testscommon/components/components.go +++ b/testscommon/components/components.go @@ -83,7 +83,7 @@ type LoadKeysFunc func(string, int) ([]byte, string, error) // GetRunTypeCoreComponents - func GetRunTypeCoreComponents() factory.RunTypeCoreComponentsHolder { - runTypeCoreComponentsFactory := runType.NewRunTypeCoreComponentsFactory() + runTypeCoreComponentsFactory := runType.NewRunTypeCoreComponentsFactory(config.EpochConfig{}) managedRunTypeCoreComponents, err := runType.NewManagedRunTypeCoreComponents(runTypeCoreComponentsFactory) if err != nil { log.Error("getRunTypeCoreComponents NewManagedRunTypeCoreComponents", "error", err.Error()) @@ -99,7 +99,12 @@ func GetRunTypeCoreComponents() factory.RunTypeCoreComponentsHolder { // GetSovereignRunTypeCoreComponents - func GetSovereignRunTypeCoreComponents() factory.RunTypeCoreComponentsHolder { - sovRunTypeCoreComponentsFactory := runType.NewSovereignRunTypeCoreComponentsFactory() + runTypeCoreComponentsFactory := runType.NewRunTypeCoreComponentsFactory(config.EpochConfig{}) + sovRunTypeCoreComponentsFactory, err := runType.NewSovereignRunTypeCoreComponentsFactory(runTypeCoreComponentsFactory) + if err != nil { + log.Error("GetSovereignRunTypeCoreComponents.NewSovereignRunTypeCoreComponentsFactory", "error", err.Error()) + return nil + } managedRunTypeCoreComponents, err := runType.NewManagedRunTypeCoreComponents(sovRunTypeCoreComponentsFactory) if err != nil { log.Error("GetSovereignRunTypeCoreComponents.NewManagedRunTypeCoreComponents", "error", err.Error()) From cdf3af38335a50eb48c29e38fafd7f2263ea711c Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Fri, 22 Nov 2024 18:25:14 +0200 Subject: [PATCH 03/23] Revert "enable epoch handler in run type core components" This reverts commit 616fb58d20c189f9be659560dd2ba52290f8761d. --- cmd/sovereignnode/sovereignNodeRunner.go | 7 +--- errors/errors.go | 3 -- factory/interface.go | 4 +- factory/runType/interface.go | 2 +- factory/runType/runTypeCoreComponents.go | 2 - .../runType/runTypeCoreComponentsFactory.go | 23 ++-------- .../runType/runTypeCoreComponentsHandler.go | 22 +--------- .../runTypeCoreComponentsHandler_test.go | 7 +--- factory/runType/runTypeCoreComponents_test.go | 13 +++--- .../runType/sovereignRunTypeCoreComponents.go | 29 ++----------- .../sovereignRunTypeCoreComponents_test.go | 22 +++------- node/chainSimulator/chainSimulator.go | 42 +++++++++---------- .../components/testOnlyProcessingNode.go | 4 +- node/nodeRunner.go | 2 +- testscommon/components/components.go | 9 +--- 15 files changed, 50 insertions(+), 141 deletions(-) diff --git a/cmd/sovereignnode/sovereignNodeRunner.go b/cmd/sovereignnode/sovereignNodeRunner.go index 457ee6b3809..66d6c276467 100644 --- a/cmd/sovereignnode/sovereignNodeRunner.go +++ b/cmd/sovereignnode/sovereignNodeRunner.go @@ -1678,12 +1678,7 @@ func (snr *sovereignNodeRunner) CreateManagedCryptoComponents( // CreateManagedRunTypeCoreComponents creates the managed run type core components func (snr *sovereignNodeRunner) CreateManagedRunTypeCoreComponents() (mainFactory.RunTypeCoreComponentsHandler, error) { - runTypeCoreComponents := runType.NewRunTypeCoreComponentsFactory(*snr.configs.EpochConfig) - sovereignRunTypeCoreComponentsFactory, err := runType.NewSovereignRunTypeCoreComponentsFactory(runTypeCoreComponents) - if err != nil { - return nil, err - } - + sovereignRunTypeCoreComponentsFactory := runType.NewSovereignRunTypeCoreComponentsFactory() managedRunTypeCoreComponents, err := runType.NewManagedRunTypeCoreComponents(sovereignRunTypeCoreComponentsFactory) if err != nil { return nil, err diff --git a/errors/errors.go b/errors/errors.go index ba624dd9087..9dbda39b716 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -451,9 +451,6 @@ var ErrStateComponentsFactoryCreate = errors.New("stateComponentsFactory create // ErrRunTypeComponentsFactoryCreate signals that an error occured on runTypeComponentsFactory create var ErrRunTypeComponentsFactoryCreate = errors.New("runTypeComponentsFactory create failed") -// ErrRunTypeCoreComponentsFactoryCreate signals that an error occured on runTypeCoreComponentsFactory create -var ErrRunTypeCoreComponentsFactoryCreate = errors.New("runTypeCoreComponentsFactory create failed") - // ErrStatusComponentsFactoryCreate signals that an error occured on statusComponentsFactory create var ErrStatusComponentsFactoryCreate = errors.New("statusComponentsFactory create failed") diff --git a/factory/interface.go b/factory/interface.go index 4d88135840e..f81e153988f 100644 --- a/factory/interface.go +++ b/factory/interface.go @@ -14,8 +14,6 @@ import ( "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" crypto "github.com/multiversx/mx-chain-crypto-go" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" - "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" @@ -68,6 +66,7 @@ import ( "github.com/multiversx/mx-chain-go/update" "github.com/multiversx/mx-chain-go/vm" "github.com/multiversx/mx-chain-go/vm/systemSmartContracts" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) // EpochStartNotifier defines which actions should be done for handling new epoch's events @@ -659,7 +658,6 @@ type RunTypeCoreComponentsHandler interface { type RunTypeCoreComponentsHolder interface { GenesisNodesSetupFactoryCreator() sharding.GenesisNodesSetupFactory RatingsDataFactoryCreator() rating.RatingsDataFactory - EnableEpochsHandler() common.EnableEpochsHandler Create() error Close() error CheckSubcomponents() error diff --git a/factory/runType/interface.go b/factory/runType/interface.go index 84780aa6d62..502dd02703c 100644 --- a/factory/runType/interface.go +++ b/factory/runType/interface.go @@ -7,6 +7,6 @@ type runTypeComponentsCreator interface { } type runTypeCoreComponentsCreator interface { - Create() (*runTypeCoreComponents, error) + Create() *runTypeCoreComponents IsInterfaceNil() bool } diff --git a/factory/runType/runTypeCoreComponents.go b/factory/runType/runTypeCoreComponents.go index d0dbef4a4e4..2de2f25fc93 100644 --- a/factory/runType/runTypeCoreComponents.go +++ b/factory/runType/runTypeCoreComponents.go @@ -1,7 +1,6 @@ package runType import ( - "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/process/rating" "github.com/multiversx/mx-chain-go/sharding" ) @@ -9,7 +8,6 @@ import ( type runTypeCoreComponents struct { genesisNodesSetupFactory sharding.GenesisNodesSetupFactory ratingsDataFactory rating.RatingsDataFactory - enableEpochsHandler common.EnableEpochsHandler } // Close does nothing diff --git a/factory/runType/runTypeCoreComponentsFactory.go b/factory/runType/runTypeCoreComponentsFactory.go index f90d4f2a00f..bf34c7ed37c 100644 --- a/factory/runType/runTypeCoreComponentsFactory.go +++ b/factory/runType/runTypeCoreComponentsFactory.go @@ -1,39 +1,24 @@ package runType import ( - "fmt" - - "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/process/rating" "github.com/multiversx/mx-chain-go/sharding" ) type runTypeCoreComponentsFactory struct { - epochConfig config.EpochConfig } // NewRunTypeCoreComponentsFactory will return a new instance of runTypeCoreComponentsFactory -func NewRunTypeCoreComponentsFactory(epochConfig config.EpochConfig) *runTypeCoreComponentsFactory { - return &runTypeCoreComponentsFactory{ - epochConfig: epochConfig, - } +func NewRunTypeCoreComponentsFactory() *runTypeCoreComponentsFactory { + return &runTypeCoreComponentsFactory{} } // Create will create the runType core components -func (rccf *runTypeCoreComponentsFactory) Create() (*runTypeCoreComponents, error) { - epochNotifier := forking.NewGenericEpochNotifier() - enableEpochsHandler, err := enablers.NewEnableEpochsHandler(rccf.epochConfig.EnableEpochs, epochNotifier) - if err != nil { - return nil, fmt.Errorf("runTypeCoreComponentsFactory - NewEnableEpochsHandler failed: %w", err) - } - +func (rccf *runTypeCoreComponentsFactory) Create() *runTypeCoreComponents { return &runTypeCoreComponents{ genesisNodesSetupFactory: sharding.NewGenesisNodesSetupFactory(), ratingsDataFactory: rating.NewRatingsDataFactory(), - enableEpochsHandler: enableEpochsHandler, - }, nil + } } // IsInterfaceNil returns true if there is no value under the interface diff --git a/factory/runType/runTypeCoreComponentsHandler.go b/factory/runType/runTypeCoreComponentsHandler.go index a2fd1460518..f9bc4b5331c 100644 --- a/factory/runType/runTypeCoreComponentsHandler.go +++ b/factory/runType/runTypeCoreComponentsHandler.go @@ -1,12 +1,10 @@ package runType import ( - "fmt" "sync" "github.com/multiversx/mx-chain-core-go/core/check" - "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/factory" "github.com/multiversx/mx-chain-go/process/rating" @@ -37,10 +35,7 @@ func NewManagedRunTypeCoreComponents(rcf runTypeCoreComponentsCreator) (*managed // Create will create the managed components func (mrcc *managedRunTypeCoreComponents) Create() error { - rtc, err := mrcc.factory.Create() - if err != nil { - return fmt.Errorf("%w: %v", errors.ErrRunTypeCoreComponentsFactoryCreate, err) - } + rtc := mrcc.factory.Create() mrcc.mutRunTypeCoreComponents.Lock() mrcc.runTypeCoreComponents = rtc @@ -57,9 +52,6 @@ func (mrcc *managedRunTypeCoreComponents) Close() error { if check.IfNil(mrcc.runTypeCoreComponents) { return nil } - if check.IfNil(mrcc.enableEpochsHandler) { - return errors.ErrNilEnableEpochsHandler - } err := mrcc.runTypeCoreComponents.Close() if err != nil { @@ -111,18 +103,6 @@ func (mrcc *managedRunTypeCoreComponents) RatingsDataFactoryCreator() rating.Rat return mrcc.runTypeCoreComponents.ratingsDataFactory } -// EnableEpochsHandler returns enable epochs handler -func (mrcc *managedRunTypeCoreComponents) EnableEpochsHandler() common.EnableEpochsHandler { - mrcc.mutRunTypeCoreComponents.RLock() - defer mrcc.mutRunTypeCoreComponents.RUnlock() - - if check.IfNil(mrcc.runTypeCoreComponents) { - return nil - } - - return mrcc.runTypeCoreComponents.enableEpochsHandler -} - // 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 a43b15a017f..879014863ac 100644 --- a/factory/runType/runTypeCoreComponentsHandler_test.go +++ b/factory/runType/runTypeCoreComponentsHandler_test.go @@ -5,14 +5,13 @@ import ( "github.com/stretchr/testify/require" - "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/factory" "github.com/multiversx/mx-chain-go/factory/runType" ) func createCoreComponents() (factory.RunTypeCoreComponentsHandler, error) { - rccf := runType.NewRunTypeCoreComponentsFactory(config.EpochConfig{}) + rccf := runType.NewRunTypeCoreComponentsFactory() return runType.NewManagedRunTypeCoreComponents(rccf) } @@ -25,7 +24,7 @@ func TestNewManagedRunTypeCoreComponents(t *testing.T) { require.True(t, managedRunTypeCoreComponents.IsInterfaceNil()) }) t.Run("should work", func(t *testing.T) { - rccf := runType.NewRunTypeCoreComponentsFactory(config.EpochConfig{}) + rccf := runType.NewRunTypeCoreComponentsFactory() managedRunTypeCoreComponents, err := runType.NewManagedRunTypeCoreComponents(rccf) require.NoError(t, err) require.False(t, managedRunTypeCoreComponents.IsInterfaceNil()) @@ -43,14 +42,12 @@ func TestManagedRunTypeCoreComponents_Create(t *testing.T) { require.Nil(t, managedRunTypeCoreComponents.GenesisNodesSetupFactoryCreator()) require.Nil(t, managedRunTypeCoreComponents.RatingsDataFactoryCreator()) - require.Nil(t, managedRunTypeCoreComponents.EnableEpochsHandler()) err = managedRunTypeCoreComponents.Create() require.NoError(t, err) require.NotNil(t, managedRunTypeCoreComponents.GenesisNodesSetupFactoryCreator()) require.NotNil(t, managedRunTypeCoreComponents.RatingsDataFactoryCreator()) - require.NotNil(t, managedRunTypeCoreComponents.EnableEpochsHandler()) require.Equal(t, factory.RunTypeCoreComponentsName, managedRunTypeCoreComponents.String()) require.NoError(t, managedRunTypeCoreComponents.Close()) diff --git a/factory/runType/runTypeCoreComponents_test.go b/factory/runType/runTypeCoreComponents_test.go index 995c9991761..e37cc82000d 100644 --- a/factory/runType/runTypeCoreComponents_test.go +++ b/factory/runType/runTypeCoreComponents_test.go @@ -5,7 +5,6 @@ import ( "github.com/stretchr/testify/require" - "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/factory/runType" ) @@ -13,7 +12,7 @@ func TestNewRunTypeCoreComponentsFactory(t *testing.T) { t.Parallel() t.Run("should work", func(t *testing.T) { - rccf := runType.NewRunTypeCoreComponentsFactory(config.EpochConfig{}) + rccf := runType.NewRunTypeCoreComponentsFactory() require.NotNil(t, rccf) }) } @@ -21,22 +20,20 @@ func TestNewRunTypeCoreComponentsFactory(t *testing.T) { func TestRunTypeCoreComponentsFactory_Create(t *testing.T) { t.Parallel() - rccf := runType.NewRunTypeCoreComponentsFactory(config.EpochConfig{}) + rccf := runType.NewRunTypeCoreComponentsFactory() require.NotNil(t, rccf) - rcc, err := rccf.Create() - require.NoError(t, err) + rcc := rccf.Create() require.NotNil(t, rcc) } func TestRunTypeCoreComponentsFactory_Close(t *testing.T) { t.Parallel() - rccf := runType.NewRunTypeCoreComponentsFactory(config.EpochConfig{}) + rccf := runType.NewRunTypeCoreComponentsFactory() require.NotNil(t, rccf) - rcc, err := rccf.Create() - require.NoError(t, err) + rcc := rccf.Create() require.NotNil(t, rcc) require.NoError(t, rcc.Close()) diff --git a/factory/runType/sovereignRunTypeCoreComponents.go b/factory/runType/sovereignRunTypeCoreComponents.go index e1d82f12f2f..8a9730d00f8 100644 --- a/factory/runType/sovereignRunTypeCoreComponents.go +++ b/factory/runType/sovereignRunTypeCoreComponents.go @@ -1,45 +1,24 @@ package runType import ( - "fmt" - - "github.com/multiversx/mx-chain-core-go/core/check" - - "github.com/multiversx/mx-chain-go/common/enablers" - "github.com/multiversx/mx-chain-go/common/forking" - errorsMx "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/process/rating" "github.com/multiversx/mx-chain-go/sharding" ) type sovereignRunTypeCoreComponentsFactory struct { - *runTypeCoreComponentsFactory } // NewSovereignRunTypeCoreComponentsFactory will return a new instance of sovereign runType core components factory -func NewSovereignRunTypeCoreComponentsFactory(rtcc *runTypeCoreComponentsFactory) (*sovereignRunTypeCoreComponentsFactory, error) { - if check.IfNil(rtcc) { - return nil, errorsMx.ErrNilRunTypeCoreComponentsFactory - } - - return &sovereignRunTypeCoreComponentsFactory{ - runTypeCoreComponentsFactory: rtcc, - }, nil +func NewSovereignRunTypeCoreComponentsFactory() *sovereignRunTypeCoreComponentsFactory { + return &sovereignRunTypeCoreComponentsFactory{} } // Create will return a new instance of runType core components -func (srccf *sovereignRunTypeCoreComponentsFactory) Create() (*runTypeCoreComponents, error) { - epochNotifier := forking.NewGenericEpochNotifier() - sovEnableEpochsHandler, err := enablers.NewSovereignEnableEpochsHandler(srccf.epochConfig.EnableEpochs, srccf.epochConfig.SovereignEnableEpochs, srccf.epochConfig.SovereignChainSpecificEnableEpochs, epochNotifier) - if err != nil { - return nil, fmt.Errorf("sovereignRunTypeCoreComponentsFactory - NewSovereignEnableEpochsHandler failed: %w", err) - } - +func (srccf *sovereignRunTypeCoreComponentsFactory) Create() *runTypeCoreComponents { return &runTypeCoreComponents{ genesisNodesSetupFactory: sharding.NewSovereignGenesisNodesSetupFactory(), ratingsDataFactory: rating.NewSovereignRatingsDataFactory(), - enableEpochsHandler: sovEnableEpochsHandler, - }, nil + } } // IsInterfaceNil returns true if there is no value under the interface diff --git a/factory/runType/sovereignRunTypeCoreComponents_test.go b/factory/runType/sovereignRunTypeCoreComponents_test.go index 9baa81ddd3d..650f2f3f33d 100644 --- a/factory/runType/sovereignRunTypeCoreComponents_test.go +++ b/factory/runType/sovereignRunTypeCoreComponents_test.go @@ -5,29 +5,17 @@ import ( "github.com/stretchr/testify/require" - "github.com/multiversx/mx-chain-go/config" - errorsMx "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/factory/runType" ) func TestSovereignRunTypeCoreComponentsFactory_CreateAndClose(t *testing.T) { t.Parallel() - t.Run("nil run type core components factory", func(t *testing.T) { - srccf, err := runType.NewSovereignRunTypeCoreComponentsFactory(nil) - require.Nil(t, srccf) - require.ErrorIs(t, errorsMx.ErrNilRunTypeCoreComponentsFactory, err) - }) - t.Run("should work", func(t *testing.T) { - rccf := runType.NewRunTypeCoreComponentsFactory(config.EpochConfig{}) - srccf, err := runType.NewSovereignRunTypeCoreComponentsFactory(rccf) - require.NoError(t, err) - require.NotNil(t, srccf) + srccf := runType.NewSovereignRunTypeCoreComponentsFactory() + require.NotNil(t, srccf) - rcc, err := srccf.Create() - require.NoError(t, err) - require.NotNil(t, rcc) + rcc := srccf.Create() + require.NotNil(t, rcc) - require.NoError(t, rcc.Close()) - }) + require.NoError(t, rcc.Close()) } diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index 5491601a851..f717967ffb7 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -65,7 +65,7 @@ type ArgsChainSimulator struct { ApiInterface components.APIConfigurator AlterConfigsFunction func(cfg *config.Configs) VmQueryDelayAfterStartInMs uint64 - CreateRunTypeCoreComponents func(epochConfig config.EpochConfig) (factory.RunTypeCoreComponentsHolder, error) + CreateRunTypeCoreComponents func() (factory.RunTypeCoreComponentsHolder, error) CreateIncomingHeaderSubscriber func(config *config.NotifierConfig, dataPool dataRetriever.PoolsHolder, mainChainNotarizationStartRound uint64, runTypeComponents factory.RunTypeComponentsHolder) (processing.IncomingHeaderSubscriber, error) CreateRunTypeComponents func(args runType.ArgsRunTypeComponents) (factory.RunTypeComponentsHolder, error) NodeFactory node.NodeFactory @@ -124,8 +124,8 @@ func NewBaseChainSimulator(args ArgsBaseChainSimulator) (*simulator, error) { func setSimulatorRunTypeArguments(args *ArgsChainSimulator) { if args.CreateRunTypeCoreComponents == nil { - args.CreateRunTypeCoreComponents = func(epochConfig config.EpochConfig) (factory.RunTypeCoreComponentsHolder, error) { - return createRunTypeCoreComponents(epochConfig) + args.CreateRunTypeCoreComponents = func() (factory.RunTypeCoreComponentsHolder, error) { + return createRunTypeCoreComponents() } } if args.CreateIncomingHeaderSubscriber == nil { @@ -146,8 +146,8 @@ func setSimulatorRunTypeArguments(args *ArgsChainSimulator) { } } -func createRunTypeCoreComponents(epochConfig config.EpochConfig) (factory.RunTypeCoreComponentsHolder, error) { - runTypeCoreComponentsFactory := runType.NewRunTypeCoreComponentsFactory(epochConfig) +func createRunTypeCoreComponents() (factory.RunTypeCoreComponentsHolder, error) { + runTypeCoreComponentsFactory := runType.NewRunTypeCoreComponentsFactory() managedRunTypeCoreComponents, err := runType.NewManagedRunTypeCoreComponents(runTypeCoreComponentsFactory) if err != nil { return nil, err @@ -269,22 +269,22 @@ func (s *simulator) createTestNode( outputConfigs configs.ArgsConfigsSimulator, args ArgsBaseChainSimulator, shardIDStr string, ) (process.NodeHandler, error) { argsTestOnlyProcessorNode := components.ArgsTestOnlyProcessingNode{ - Configs: outputConfigs.Configs, - ChanStopNodeProcess: s.chanStopNodeProcess, - SyncedBroadcastNetwork: s.syncedBroadcastNetwork, - NumShards: s.numOfShards, - GasScheduleFilename: outputConfigs.GasScheduleFilename, - ShardIDStr: shardIDStr, - APIInterface: args.ApiInterface, - BypassTxSignatureCheck: args.BypassTxSignatureCheck, - InitialRound: args.InitialRound, - InitialNonce: args.InitialNonce, - MinNodesPerShard: args.MinNodesPerShard, - ConsensusGroupSize: args.ConsensusGroupSize, - MinNodesMeta: args.MetaChainMinNodes, - MetaChainConsensusGroupSize: args.MetaChainConsensusGroupSize, - RoundDurationInMillis: args.RoundDurationInMillis, - VmQueryDelayAfterStartInMs: args.VmQueryDelayAfterStartInMs, + Configs: outputConfigs.Configs, + ChanStopNodeProcess: s.chanStopNodeProcess, + SyncedBroadcastNetwork: s.syncedBroadcastNetwork, + NumShards: s.numOfShards, + GasScheduleFilename: outputConfigs.GasScheduleFilename, + ShardIDStr: shardIDStr, + APIInterface: args.ApiInterface, + BypassTxSignatureCheck: args.BypassTxSignatureCheck, + InitialRound: args.InitialRound, + InitialNonce: args.InitialNonce, + MinNodesPerShard: args.MinNodesPerShard, + ConsensusGroupSize: args.ConsensusGroupSize, + MinNodesMeta: args.MetaChainMinNodes, + MetaChainConsensusGroupSize: args.MetaChainConsensusGroupSize, + RoundDurationInMillis: args.RoundDurationInMillis, + VmQueryDelayAfterStartInMs: args.VmQueryDelayAfterStartInMs, CreateRunTypeCoreComponents: args.CreateRunTypeCoreComponents, CreateIncomingHeaderSubscriber: args.CreateIncomingHeaderSubscriber, CreateRunTypeComponents: args.CreateRunTypeComponents, diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index f24bf79e3fe..46b0d831713 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -37,7 +37,7 @@ import ( type ArgsTestOnlyProcessingNode struct { Configs config.Configs APIInterface APIConfigurator - CreateRunTypeCoreComponents func(epochConfig config.EpochConfig) (factory.RunTypeCoreComponentsHolder, error) + CreateRunTypeCoreComponents func() (factory.RunTypeCoreComponentsHolder, error) CreateIncomingHeaderSubscriber func(config *config.NotifierConfig, dataPool dataRetriever.PoolsHolder, mainChainNotarizationStartRound uint64, runTypeComponents factory.RunTypeComponentsHolder) (process.IncomingHeaderSubscriber, error) CreateRunTypeComponents func(args runType.ArgsRunTypeComponents) (factory.RunTypeComponentsHolder, error) NodeFactory node.NodeFactory @@ -96,7 +96,7 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces var err error instance.TransactionFeeHandler = postprocess.NewFeeAccumulator() - runTypeCoreComponents, err := args.CreateRunTypeCoreComponents(*args.Configs.EpochConfig) + runTypeCoreComponents, err := args.CreateRunTypeCoreComponents() if err != nil { return nil, err } diff --git a/node/nodeRunner.go b/node/nodeRunner.go index 3136a284790..79a5fd91d08 100644 --- a/node/nodeRunner.go +++ b/node/nodeRunner.go @@ -1570,7 +1570,7 @@ func (nr *nodeRunner) CreateManagedCryptoComponents( // CreateManagedRunTypeCoreComponents creates the managed run type core components func (nr *nodeRunner) CreateManagedRunTypeCoreComponents() (mainFactory.RunTypeCoreComponentsHandler, error) { - runTypeCoreComponentsFactory := runType.NewRunTypeCoreComponentsFactory(*nr.configs.EpochConfig) + runTypeCoreComponentsFactory := runType.NewRunTypeCoreComponentsFactory() managedRunTypeCoreComponents, err := runType.NewManagedRunTypeCoreComponents(runTypeCoreComponentsFactory) if err != nil { diff --git a/testscommon/components/components.go b/testscommon/components/components.go index 7366ffa9dce..6bc286b3cc1 100644 --- a/testscommon/components/components.go +++ b/testscommon/components/components.go @@ -83,7 +83,7 @@ type LoadKeysFunc func(string, int) ([]byte, string, error) // GetRunTypeCoreComponents - func GetRunTypeCoreComponents() factory.RunTypeCoreComponentsHolder { - runTypeCoreComponentsFactory := runType.NewRunTypeCoreComponentsFactory(config.EpochConfig{}) + runTypeCoreComponentsFactory := runType.NewRunTypeCoreComponentsFactory() managedRunTypeCoreComponents, err := runType.NewManagedRunTypeCoreComponents(runTypeCoreComponentsFactory) if err != nil { log.Error("getRunTypeCoreComponents NewManagedRunTypeCoreComponents", "error", err.Error()) @@ -99,12 +99,7 @@ func GetRunTypeCoreComponents() factory.RunTypeCoreComponentsHolder { // GetSovereignRunTypeCoreComponents - func GetSovereignRunTypeCoreComponents() factory.RunTypeCoreComponentsHolder { - runTypeCoreComponentsFactory := runType.NewRunTypeCoreComponentsFactory(config.EpochConfig{}) - sovRunTypeCoreComponentsFactory, err := runType.NewSovereignRunTypeCoreComponentsFactory(runTypeCoreComponentsFactory) - if err != nil { - log.Error("GetSovereignRunTypeCoreComponents.NewSovereignRunTypeCoreComponentsFactory", "error", err.Error()) - return nil - } + sovRunTypeCoreComponentsFactory := runType.NewSovereignRunTypeCoreComponentsFactory() managedRunTypeCoreComponents, err := runType.NewManagedRunTypeCoreComponents(sovRunTypeCoreComponentsFactory) if err != nil { log.Error("GetSovereignRunTypeCoreComponents.NewManagedRunTypeCoreComponents", "error", err.Error()) From 1ecbf3ac79a33374ff5a5a72054bbf252b95e5ab Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Mon, 25 Nov 2024 15:06:09 +0200 Subject: [PATCH 04/23] sovereign enable epoch handler in components --- .../sovereignChainSimulator_test.go | 18 ++-- cmd/sovereignnode/config/enableEpochs.toml | 102 +++++++++--------- cmd/sovereignnode/sovereignNodeRunner.go | 4 + common/enablers/enableEpochsFactory.go | 22 ++++ common/enablers/errors.go | 3 + common/enablers/interface.go | 13 +++ .../enablers/sovereignEnableEpochsFactory.go | 23 ++++ factory/core/coreComponents.go | 11 +- factory/core/coreComponents_test.go | 11 +- factory/interface.go | 5 +- factory/processing/processComponents.go | 7 ++ .../processComponentsHandler_test.go | 11 +- factory/processing/processComponents_test.go | 7 +- factory/runType/runTypeCoreComponents.go | 2 + .../runType/runTypeCoreComponentsFactory.go | 2 + .../runType/runTypeCoreComponentsHandler.go | 16 +++ .../runTypeCoreComponentsHandler_test.go | 2 + .../runType/sovereignRunTypeCoreComponents.go | 2 + genesis/process/argGenesisBlockCreator.go | 3 + genesis/process/genesisBlockCreator.go | 18 ++-- genesis/process/metaGenesisBlockCreator.go | 54 +++++----- genesis/process/shardGenesisBlockCreator.go | 71 ++++++------ .../process/sovereignGenesisBlockCreator.go | 21 ++-- .../consensusComponents_test.go | 1 + .../heartbeatComponents_test.go | 1 + .../processComponents_test.go | 1 + .../statusComponents/statusComponents_test.go | 1 + .../realcomponents/processorRunner.go | 51 ++++++--- .../components/coreComponents.go | 12 +-- .../components/coreComponents_test.go | 2 +- .../components/processComponents.go | 3 + .../components/testOnlyProcessingNode.go | 3 +- node/nodeRunner.go | 4 + testscommon/components/components.go | 4 +- 34 files changed, 331 insertions(+), 180 deletions(-) create mode 100644 common/enablers/enableEpochsFactory.go create mode 100644 common/enablers/interface.go create mode 100644 common/enablers/sovereignEnableEpochsFactory.go diff --git a/cmd/sovereignnode/chainSimulator/sovereignChainSimulator_test.go b/cmd/sovereignnode/chainSimulator/sovereignChainSimulator_test.go index 4715334f191..4f1397b7657 100644 --- a/cmd/sovereignnode/chainSimulator/sovereignChainSimulator_test.go +++ b/cmd/sovereignnode/chainSimulator/sovereignChainSimulator_test.go @@ -4,13 +4,14 @@ import ( "testing" "time" + "github.com/multiversx/mx-chain-core-go/core" + logger "github.com/multiversx/mx-chain-logger-go" + "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 +58,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) @@ -69,6 +73,8 @@ func TestChainSimulator_GenerateBlocksShouldWork(t *testing.T) { time.Sleep(time.Second) + logger.SetLogLevel("*:TRACE") + err = chainSimulator.GenerateBlocks(50) require.Nil(t, err) } diff --git a/cmd/sovereignnode/config/enableEpochs.toml b/cmd/sovereignnode/config/enableEpochs.toml index 5d765af378c..a062bc06eb1 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,33 @@ # 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 # 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 # 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 @@ -111,13 +111,13 @@ 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 +126,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 +168,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 +177,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,7 +256,7 @@ [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] diff --git a/cmd/sovereignnode/sovereignNodeRunner.go b/cmd/sovereignnode/sovereignNodeRunner.go index 53fe17cea58..3d657998df8 100644 --- a/cmd/sovereignnode/sovereignNodeRunner.go +++ b/cmd/sovereignnode/sovereignNodeRunner.go @@ -442,6 +442,7 @@ func (snr *sovereignNodeRunner) executeOneComponentCreationCycle( managedProcessComponents, err := snr.CreateManagedProcessComponents( managedRunTypeComponents, + managedRunTypeCoreComponents, managedCoreComponents, managedCryptoComponents, managedNetworkComponents, @@ -1289,6 +1290,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, @@ -1381,6 +1383,7 @@ func (snr *sovereignNodeRunner) CreateManagedProcessComponents( FlagsConfig: *configs.FlagsConfig, TxExecutionOrderHandler: ordering.NewOrderedCollection(), RunTypeComponents: runTypeComponents, + RunTypeCoreComponents: runTypeCoreComponents, IncomingHeaderSubscriber: incomingHeaderHandler, } processComponentsFactory, err := processComp.NewProcessComponentsFactory(processArgs) @@ -1594,6 +1597,7 @@ func (snr *sovereignNodeRunner) CreateManagedCoreComponents( ChanStopNodeProcess: chanStopNodeProcess, GenesisNodesSetupFactory: runTypeCoreComponents.GenesisNodesSetupFactoryCreator(), RatingsDataFactory: runTypeCoreComponents.RatingsDataFactoryCreator(), + EnableEpochsFactory: runTypeCoreComponents.EnableEpochsFactoryCreator(), } coreComponentsFactory, err := coreComp.NewCoreComponentsFactory(coreArgs) diff --git a/common/enablers/enableEpochsFactory.go b/common/enablers/enableEpochsFactory.go new file mode 100644 index 00000000000..1f097ec5e68 --- /dev/null +++ b/common/enablers/enableEpochsFactory.go @@ -0,0 +1,22 @@ +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{} + +func NewEnableEpochsFactory() EnableEpochsFactory { + return &enableEpochsFactory{} +} + +func (eef *enableEpochsFactory) CreateEnableEpochsHandler(epochConfig config.EpochConfig, epochNotifier process.EpochNotifier) (common.EnableEpochsHandler, error) { + return NewEnableEpochsHandler(epochConfig.EnableEpochs, epochNotifier) +} + +// IsInterfaceNil checks if the underlying pointer is nil +func (eef *enableEpochsFactory) IsInterfaceNil() bool { + return eef == nil +} diff --git a/common/enablers/errors.go b/common/enablers/errors.go index 388a8ad96bd..fec33addec4 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") diff --git a/common/enablers/interface.go b/common/enablers/interface.go new file mode 100644 index 00000000000..d44e00373ce --- /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(epochConfig config.EpochConfig, 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..cc0ff5f846b --- /dev/null +++ b/common/enablers/sovereignEnableEpochsFactory.go @@ -0,0 +1,23 @@ +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{} + +func NewSovereignEnableEpochsFactory() EnableEpochsFactory { + return &sovereignEnableEpochsFactory{} +} + +func (seef *sovereignEnableEpochsFactory) CreateEnableEpochsHandler(epochConfig config.EpochConfig, epochNotifier process.EpochNotifier) (common.EnableEpochsHandler, error) { + return NewSovereignEnableEpochsHandler(epochConfig.EnableEpochs, epochConfig.SovereignEnableEpochs, epochConfig.SovereignChainSpecificEnableEpochs, + epochNotifier) +} + +// IsInterfaceNil checks if the underlying pointer is nil +func (seef *sovereignEnableEpochsFactory) IsInterfaceNil() bool { + return seef == nil +} diff --git a/factory/core/coreComponents.go b/factory/core/coreComponents.go index 76472e8bdbc..58127ed328c 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,7 +40,6 @@ 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") @@ -57,6 +58,7 @@ type CoreComponentsFactoryArgs struct { ChanStopNodeProcess chan endProcess.ArgEndProcess GenesisNodesSetupFactory sharding.GenesisNodesSetupFactory RatingsDataFactory rating.RatingsDataFactory + EnableEpochsFactory enablers.EnableEpochsFactory } // coreComponentsFactory is responsible for creating the core components @@ -73,6 +75,7 @@ type coreComponentsFactory struct { chanStopNodeProcess chan endProcess.ArgEndProcess genesisNodesSetupFactory sharding.GenesisNodesSetupFactory ratingsDataFactory rating.RatingsDataFactory + enableEpochsFactory enablers.EnableEpochsFactory } // coreComponents is the DTO used for core components @@ -121,6 +124,9 @@ func NewCoreComponentsFactory(args CoreComponentsFactoryArgs) (*coreComponentsFa if check.IfNil(args.RatingsDataFactory) { return nil, errors.ErrNilRatingsDataFactory } + if check.IfNil(args.EnableEpochsFactory) { + return nil, enablers.ErrNilEnableEpochsFactory + } return &coreComponentsFactory{ config: args.Config, @@ -135,6 +141,7 @@ func NewCoreComponentsFactory(args CoreComponentsFactoryArgs) (*coreComponentsFa nodesFilename: args.NodesFilename, genesisNodesSetupFactory: args.GenesisNodesSetupFactory, ratingsDataFactory: args.RatingsDataFactory, + enableEpochsFactory: args.EnableEpochsFactory, }, nil } @@ -252,7 +259,7 @@ func (ccf *coreComponentsFactory) Create() (*coreComponents, error) { } epochNotifier := forking.NewGenericEpochNotifier() - enableEpochsHandler, err := enablers.NewEnableEpochsHandler(ccf.epochConfig.EnableEpochs, epochNotifier) + enableEpochsHandler, err := ccf.enableEpochsFactory.CreateEnableEpochsHandler(ccf.epochConfig, epochNotifier) if err != nil { return nil, err } diff --git a/factory/core/coreComponents_test.go b/factory/core/coreComponents_test.go index 071664d0431..18725226135 100644 --- a/factory/core/coreComponents_test.go +++ b/factory/core/coreComponents_test.go @@ -4,12 +4,14 @@ 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" coreComp "github.com/multiversx/mx-chain-go/factory/core" "github.com/multiversx/mx-chain-go/state" componentsMock "github.com/multiversx/mx-chain-go/testscommon/components" - "github.com/stretchr/testify/require" ) func TestNewCoreComponentsFactory(t *testing.T) { @@ -35,6 +37,13 @@ func TestNewCoreComponentsFactory(t *testing.T) { 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() + args.EnableEpochsFactory = nil + ccf, err := coreComp.NewCoreComponentsFactory(args) + require.Nil(t, ccf) + require.Equal(t, enablers.ErrNilEnableEpochsFactory, err) + }) } func TestCoreComponentsFactory_CreateCoreComponentsNoHasherConfigShouldErr(t *testing.T) { diff --git a/factory/interface.go b/factory/interface.go index f81e153988f..6761f4ea4f7 100644 --- a/factory/interface.go +++ b/factory/interface.go @@ -14,9 +14,12 @@ import ( "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" crypto "github.com/multiversx/mx-chain-crypto-go" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "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" @@ -66,7 +69,6 @@ import ( "github.com/multiversx/mx-chain-go/update" "github.com/multiversx/mx-chain-go/vm" "github.com/multiversx/mx-chain-go/vm/systemSmartContracts" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) // EpochStartNotifier defines which actions should be done for handling new epoch's events @@ -658,6 +660,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 b904fb98594..3597fdb0ebd 100644 --- a/factory/processing/processComponents.go +++ b/factory/processing/processComponents.go @@ -161,6 +161,7 @@ type ProcessComponentsFactoryArgs struct { StatusComponents factory.StatusComponentsHolder StatusCoreComponents factory.StatusCoreComponentsHolder RunTypeComponents factory.RunTypeComponentsHolder + RunTypeCoreComponents factory.RunTypeCoreComponentsHolder TxExecutionOrderHandler common.TxExecutionOrderHandler GenesisNonce uint64 @@ -204,6 +205,7 @@ type processComponentsFactory struct { statusCoreComponents factory.StatusCoreComponentsHolder txExecutionOrderHandler common.TxExecutionOrderHandler runTypeComponents factory.RunTypeComponentsHolder + runTypeCoreComponents factory.RunTypeCoreComponentsHolder genesisNonce uint64 genesisRound uint64 @@ -249,6 +251,7 @@ func NewProcessComponentsFactory(args ProcessComponentsFactoryArgs) (*processCom genesisRound: args.GenesisRound, roundConfig: args.RoundConfig, runTypeComponents: args.RunTypeComponents, + runTypeCoreComponents: args.RunTypeCoreComponents, incomingHeaderSubscriber: args.IncomingHeaderSubscriber, auctionListSelectorAPI: disabled.NewDisabledAuctionListSelector(), stakingDataProviderAPI: disabled.NewDisabledStakingDataProvider(), @@ -878,6 +881,7 @@ func (pcf *processComponentsFactory) generateGenesisHeadersAndApplyInitialBalanc GenesisNonce: pcf.genesisNonce, GenesisRound: pcf.genesisRound, RunTypeComponents: pcf.runTypeComponents, + EnableEpochsFactory: pcf.runTypeCoreComponents.EnableEpochsFactoryCreator(), DNSV2Addresses: pcf.config.BuiltInFunctions.DNSV2Addresses, // TODO: We should only pass the whole config instead of passing sub-configs as above Config: pcf.config, @@ -2116,6 +2120,9 @@ func checkProcessComponentsArgs(args ProcessComponentsFactoryArgs) error { if check.IfNil(args.RunTypeComponents.ExportHandlerFactoryCreator()) { return fmt.Errorf("%s: %w", baseErrMessage, errorsMx.ErrNilExportHandlerFactoryCreator) } + if check.IfNil(args.RunTypeCoreComponents.EnableEpochsFactoryCreator()) { + return fmt.Errorf("%s: %w", baseErrMessage, errorsMx.ErrNilRunTypeCoreComponents) + } 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 ba66bbe6225..e0743dd3047 100644 --- a/factory/processing/processComponents_test.go +++ b/factory/processing/processComponents_test.go @@ -85,14 +85,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 +282,7 @@ func createProcessComponentsFactoryArgs(runTypeComponents *mainFactoryMocks.RunT }, } args.RunTypeComponents = runTypeComponents + args.RunTypeCoreComponents = runTypeCoreComponents return args } 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..8943f521230 100644 --- a/factory/runType/sovereignRunTypeCoreComponents.go +++ b/factory/runType/sovereignRunTypeCoreComponents.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 (srccf *sovereignRunTypeCoreComponentsFactory) Create() *runTypeCoreCompone return &runTypeCoreComponents{ genesisNodesSetupFactory: sharding.NewSovereignGenesisNodesSetupFactory(), ratingsDataFactory: rating.NewSovereignRatingsDataFactory(), + enableEpochsFactory: enablers.NewSovereignEnableEpochsFactory(), } } diff --git a/genesis/process/argGenesisBlockCreator.go b/genesis/process/argGenesisBlockCreator.go index 19927792476..e2234691f3b 100644 --- a/genesis/process/argGenesisBlockCreator.go +++ b/genesis/process/argGenesisBlockCreator.go @@ -9,7 +9,9 @@ import ( "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" 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" @@ -96,6 +98,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 ecabc6104b9..abffff26def 100644 --- a/genesis/process/genesisBlockCreator.go +++ b/genesis/process/genesisBlockCreator.go @@ -11,9 +11,10 @@ import ( "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/block" - "github.com/multiversx/mx-chain-go/factory/vm" 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" @@ -234,6 +235,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 } @@ -261,7 +265,7 @@ func mustDoGenesisProcess(arg ArgsGenesisBlockCreator) bool { } func (gbc *genesisBlockCreator) createEmptyGenesisBlocks() (map[uint32]data.HeaderHandler, error) { - err := gbc.computeInitialDNSAddresses(createGenesisConfig(gbc.arg.EpochConfig.EnableEpochs)) + err := gbc.computeInitialDNSAddresses(createGenesisConfig(gbc.arg.EpochConfig)) if err != nil { return nil, err } @@ -305,7 +309,7 @@ func (gbc *genesisBlockCreator) CreateGenesisBlocks() (map[uint32]data.HeaderHan return nil, err } - err = gbc.computeInitialDNSAddresses(gbc.arg.EpochConfig.EnableEpochs) + err = gbc.computeInitialDNSAddresses(gbc.arg.EpochConfig) if err != nil { return nil, err } @@ -446,19 +450,19 @@ func (gbc *genesisBlockCreator) createHeaders(args *headerCreatorArgs) (map[uint return genesisBlocks, nil } -func (gbc *genesisBlockCreator) computeInitialDNSAddresses(enableEpochsConfig config.EnableEpochs) error { +func (gbc *genesisBlockCreator) computeInitialDNSAddresses(epochsConfig config.EpochConfig) error { isForCurrentShard := func([]byte) bool { // after hardfork we are interested only in the smart contract addresses, as they are already deployed return true } initialAddresses := intermediate.GenerateInitialPublicKeys(genesis.InitialDNSAddress, isForCurrentShard) - return gbc.computeDNSAddresses(enableEpochsConfig, initialAddresses) + return gbc.computeDNSAddresses(epochsConfig, initialAddresses) } // in case of hardfork initial smart contracts deployment is not called as they are all imported from previous state func (gbc *genesisBlockCreator) computeDNSAddresses( - enableEpochsConfig config.EnableEpochs, + epochsConfig config.EpochConfig, initialAddresses [][]byte, ) error { var dnsSC genesis.InitialSmartContractHandler @@ -477,7 +481,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(epochsConfig, epochNotifier) if err != nil { return err } diff --git a/genesis/process/metaGenesisBlockCreator.go b/genesis/process/metaGenesisBlockCreator.go index 0b327f813f3..86a62b8293b 100644 --- a/genesis/process/metaGenesisBlockCreator.go +++ b/genesis/process/metaGenesisBlockCreator.go @@ -73,7 +73,7 @@ func CreateMetaGenesisBlock( processors, err := createProcessorsForMetaGenesisBlock( arg, - createGenesisConfig(arg.EpochConfig.EnableEpochs), + createGenesisConfig(arg.EpochConfig), createGenesisRoundConfig(arg.RoundConfig), ) if err != nil { @@ -222,7 +222,7 @@ func createArgsMetaBlockCreatorAfterHardFork( ) (hardForkProcess.ArgsNewMetaBlockCreatorAfterHardFork, error) { tmpArg := arg tmpArg.Accounts = arg.importHandler.GetAccountsDBForShard(core.MetachainShardId) - processors, err := createProcessorsForMetaGenesisBlock(tmpArg, arg.EpochConfig.EnableEpochs, arg.RoundConfig) + processors, err := createProcessorsForMetaGenesisBlock(tmpArg, arg.EpochConfig, arg.RoundConfig) if err != nil { return hardForkProcess.ArgsNewMetaBlockCreatorAfterHardFork{}, err } @@ -301,13 +301,13 @@ func saveGenesisMetaToStorage( return nil } -func createProcessorsForMetaGenesisBlock(arg ArgsGenesisBlockCreator, enableEpochsConfig config.EnableEpochs, roundConfig config.RoundConfig) (*genesisProcessors, error) { +func createProcessorsForMetaGenesisBlock(arg ArgsGenesisBlockCreator, epochsConfig config.EpochConfig, roundConfig config.RoundConfig) (*genesisProcessors, error) { epochNotifier := forking.NewGenericEpochNotifier() temporaryMetaHeader := &block.MetaBlock{ Epoch: arg.StartEpochNum, TimeStamp: arg.GenesisTime, } - enableEpochsHandler, err := enablers.NewEnableEpochsHandler(enableEpochsConfig, epochNotifier) + enableEpochsHandler, err := arg.EnableEpochsFactory.CreateEnableEpochsHandler(epochsConfig, 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..769ce68ecd4 100644 --- a/genesis/process/shardGenesisBlockCreator.go +++ b/genesis/process/shardGenesisBlockCreator.go @@ -11,10 +11,11 @@ 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" + shardData "github.com/multiversx/mx-chain-go/process/factory/shard/data" + "github.com/multiversx/mx-chain-go/common" disabledCommon "github.com/multiversx/mx-chain-go/common/disabled" "github.com/multiversx/mx-chain-go/common/enablers" @@ -57,19 +58,19 @@ type deployedScMetrics struct { numOtherTypes int } -func createGenesisConfig(providedEnableEpochs config.EnableEpochs) config.EnableEpochs { - clonedConfig := providedEnableEpochs - clonedConfig.BuiltInFunctionsEnableEpoch = 0 - clonedConfig.PenalizedTooMuchGasEnableEpoch = unreachableEpoch - clonedConfig.MaxNodesChangeEnableEpoch = []config.MaxNodesChangeConfig{ +func createGenesisConfig(providedEpochsConfig config.EpochConfig) config.EpochConfig { + clonedConfig := providedEpochsConfig + clonedConfig.EnableEpochs.BuiltInFunctionsEnableEpoch = 0 + clonedConfig.EnableEpochs.PenalizedTooMuchGasEnableEpoch = unreachableEpoch + clonedConfig.EnableEpochs.MaxNodesChangeEnableEpoch = []config.MaxNodesChangeConfig{ { EpochEnable: unreachableEpoch, MaxNumNodes: 0, NodesToShufflePerShard: 0, }, } - clonedConfig.StakeEnableEpoch = unreachableEpoch // we need to specifically disable this, we have exceptions in the staking system SC - clonedConfig.DoubleKeyProtectionEnableEpoch = 0 + clonedConfig.EnableEpochs.StakeEnableEpoch = unreachableEpoch // we need to specifically disable this, we have exceptions in the staking system SC + clonedConfig.EnableEpochs.DoubleKeyProtectionEnableEpoch = 0 return clonedConfig } @@ -92,7 +93,7 @@ func CreateShardGenesisBlock( } processors, err := createProcessorsForShardGenesisBlock( - arg, createGenesisConfig(arg.EpochConfig.EnableEpochs), + arg, createGenesisConfig(arg.EpochConfig), createGenesisRoundConfig(arg.RoundConfig), ) if err != nil { @@ -277,7 +278,7 @@ func createArgsShardBlockCreatorAfterHardFork( ) (hardForkProcess.ArgsNewShardBlockCreatorAfterHardFork, error) { tmpArg := arg tmpArg.Accounts = arg.importHandler.GetAccountsDBForShard(arg.ShardCoordinator.SelfId()) - processors, err := createProcessorsForShardGenesisBlock(tmpArg, arg.EpochConfig.EnableEpochs, arg.RoundConfig) + processors, err := createProcessorsForShardGenesisBlock(tmpArg, arg.EpochConfig, arg.RoundConfig) if err != nil { return hardForkProcess.ArgsNewShardBlockCreatorAfterHardFork{}, err } @@ -357,10 +358,10 @@ func setBalanceToTrie(arg ArgsGenesisBlockCreator, accnt genesis.InitialAccountH return arg.Accounts.SaveAccount(account) } -func createProcessorsForShardGenesisBlock(arg ArgsGenesisBlockCreator, enableEpochsConfig config.EnableEpochs, roundConfig config.RoundConfig) (*genesisProcessors, error) { +func createProcessorsForShardGenesisBlock(arg ArgsGenesisBlockCreator, epochsConfig config.EpochConfig, 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(epochsConfig, epochNotifier) if err != nil { return nil, err } @@ -536,29 +537,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 be3b44c82eb..ca8fbb299c9 100644 --- a/genesis/process/sovereignGenesisBlockCreator.go +++ b/genesis/process/sovereignGenesisBlockCreator.go @@ -11,10 +11,11 @@ import ( "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-core-go/marshal" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/process/factory" "github.com/multiversx/mx-chain-go/state" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/factory/addressDecoder" @@ -51,7 +52,7 @@ func (gbc *sovereignGenesisBlockCreator) CreateGenesisBlocks() (map[uint32]data. return gbc.createSovereignEmptyGenesisBlocks() } - err = gbc.computeSovereignDNSAddresses(gbc.arg.EpochConfig.EnableEpochs) + err = gbc.computeSovereignDNSAddresses(gbc.arg.EpochConfig) if err != nil { return nil, err } @@ -87,7 +88,7 @@ func (gbc *sovereignGenesisBlockCreator) initGenesisAccounts() error { } func (gbc *sovereignGenesisBlockCreator) createSovereignEmptyGenesisBlocks() (map[uint32]data.HeaderHandler, error) { - err := gbc.computeSovereignDNSAddresses(createSovereignGenesisConfig(gbc.arg.EpochConfig.EnableEpochs)) + err := gbc.computeSovereignDNSAddresses(createGenesisConfig(gbc.arg.EpochConfig)) if err != nil { return nil, err } @@ -108,21 +109,13 @@ func (gbc *sovereignGenesisBlockCreator) createSovereignEmptyGenesisBlocks() (ma return mapEmptyGenesisBlocks, nil } -func createSovereignGenesisConfig(providedEnableEpochs config.EnableEpochs) config.EnableEpochs { - cfg := createGenesisConfig(providedEnableEpochs) - cfg.ESDTMultiTransferEnableEpoch = 0 - cfg.StakeEnableEpoch = 0 - cfg.PenalizedTooMuchGasEnableEpoch = 0 - return cfg -} - -func (gbc *sovereignGenesisBlockCreator) computeSovereignDNSAddresses(enableEpochsConfig config.EnableEpochs) error { +func (gbc *sovereignGenesisBlockCreator) computeSovereignDNSAddresses(epochsConfig config.EpochConfig) error { initialAddresses, err := addressDecoder.DecodeAddresses(gbc.arg.Core.AddressPubKeyConverter(), gbc.arg.DNSV2Addresses) if err != nil { return err } - return gbc.computeDNSAddresses(enableEpochsConfig, initialAddresses) + return gbc.computeDNSAddresses(epochsConfig, initialAddresses) } func (gbc *sovereignGenesisBlockCreator) createSovereignHeaders(args *headerCreatorArgs) (map[uint32]data.HeaderHandler, error) { @@ -235,7 +228,7 @@ func createSovereignShardGenesisBlock( arg ArgsGenesisBlockCreator, nodesListSplitter genesis.NodesListSplitter, ) (data.HeaderHandler, [][]byte, *genesis.IndexingData, error) { - sovereignGenesisConfig := createSovereignGenesisConfig(arg.EpochConfig.EnableEpochs) + sovereignGenesisConfig := createGenesisConfig(arg.EpochConfig) shardProcessors, err := createProcessorsForShardGenesisBlock(arg, sovereignGenesisConfig, createGenesisRoundConfig(arg.RoundConfig)) if err != nil { return nil, nil, nil, err 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/realcomponents/processorRunner.go b/integrationTests/realcomponents/processorRunner.go index 8598765e4eb..d724e5d51ba 100644 --- a/integrationTests/realcomponents/processorRunner.go +++ b/integrationTests/realcomponents/processorRunner.go @@ -31,8 +31,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" @@ -49,19 +47,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 @@ -80,6 +79,7 @@ func (pr *ProcessorRunner) createComponents(tb testing.TB) { pr.createCoreComponents(tb) pr.createCryptoComponents(tb) pr.createRunTypeComponents(tb) + pr.createRunTypeCoreComponents(tb) pr.createStatusCoreComponents(tb) pr.createNetworkComponents(tb) pr.createBootstrapComponents(tb) @@ -89,6 +89,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) @@ -124,8 +139,9 @@ func (pr *ProcessorRunner) createCoreComponents(tb testing.TB) { NodesFilename: pr.Config.ConfigurationPathsHolder.Nodes, WorkingDirectory: pr.Config.FlagsConfig.WorkingDir, ChanStopNodeProcess: make(chan endProcess.ArgEndProcess), - GenesisNodesSetupFactory: sharding.NewGenesisNodesSetupFactory(), - RatingsDataFactory: rating.NewRatingsDataFactory(), + GenesisNodesSetupFactory: pr.RunTypeCoreComponents.GenesisNodesSetupFactoryCreator(), + RatingsDataFactory: pr.RunTypeCoreComponents.RatingsDataFactoryCreator(), + EnableEpochsFactory: pr.RunTypeCoreComponents.EnableEpochsFactoryCreator(), } coreFactory, err := factoryCore.NewCoreComponentsFactory(argsCore) require.Nil(tb, err) @@ -453,6 +469,7 @@ func (pr *ProcessorRunner) createProcessComponents(tb testing.TB) { StatusCoreComponents: pr.StatusCoreComponents, TxExecutionOrderHandler: txExecutionOrderHandler, RunTypeComponents: pr.RunTypeComponents, + RunTypeCoreComponents: pr.RunTypeCoreComponents, } processFactory, err := factoryProcessing.NewProcessComponentsFactory(argsProcess) diff --git a/node/chainSimulator/components/coreComponents.go b/node/chainSimulator/components/coreComponents.go index b966809825a..5b882521ccc 100644 --- a/node/chainSimulator/components/coreComponents.go +++ b/node/chainSimulator/components/coreComponents.go @@ -79,7 +79,7 @@ type coreComponentsHolder struct { // ArgsCoreComponentsHolder will hold arguments needed for the core components holder type ArgsCoreComponentsHolder struct { Config config.Config - EnableEpochsConfig config.EnableEpochs + EpochsConfig config.EpochConfig RoundsConfig config.RoundConfig EconomicsConfig config.EconomicsConfig RatingConfig config.RatingsConfig @@ -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.EpochsConfig, instance.epochNotifier) if err != nil { return nil, err } @@ -210,9 +206,9 @@ func CreateCoreComponents(args ArgsCoreComponentsHolder) (*coreComponentsHolder, Hysteresis: 0, Adaptivity: false, ShuffleBetweenShards: true, - MaxNodesEnableConfig: args.EnableEpochsConfig.MaxNodesChangeEnableEpoch, + MaxNodesEnableConfig: args.EpochsConfig.EnableEpochs.MaxNodesChangeEnableEpoch, EnableEpochsHandler: instance.enableEpochsHandler, - EnableEpochs: args.EnableEpochsConfig, + EnableEpochs: args.EpochsConfig.EnableEpochs, }) if err != nil { return nil, err diff --git a/node/chainSimulator/components/coreComponents_test.go b/node/chainSimulator/components/coreComponents_test.go index 350b18c50bb..4f5177a2c05 100644 --- a/node/chainSimulator/components/coreComponents_test.go +++ b/node/chainSimulator/components/coreComponents_test.go @@ -46,7 +46,7 @@ func createArgsCoreComponentsHolder() ArgsCoreComponentsHolder { PublicKeyToListenFrom: "41378f754e2c7b2745208c3ed21b151d297acdc84c3aca00b9e292cf28ec2d444771070157ea7760ed83c26f4fed387d0077e00b563a95825dac2cbc349fc0025ccf774e37b0a98ad9724d30e90f8c29b4091ccb738ed9ffc0573df776ee9ea30b3c038b55e532760ea4a8f152f2a52848020e5cee1cc537f2c2323399723081", }, }, - EnableEpochsConfig: config.EnableEpochs{}, + EpochsConfig: config.EpochConfig{}, RoundsConfig: config.RoundConfig{ RoundActivations: map[string]config.ActivationRoundByName{ "DisableAsyncCallV1": { diff --git a/node/chainSimulator/components/processComponents.go b/node/chainSimulator/components/processComponents.go index 9fceafc625d..557a9a434cb 100644 --- a/node/chainSimulator/components/processComponents.go +++ b/node/chainSimulator/components/processComponents.go @@ -7,6 +7,7 @@ import ( "time" "github.com/multiversx/mx-chain-core-go/core/partitioning" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/forking" "github.com/multiversx/mx-chain-go/common/ordering" @@ -43,6 +44,7 @@ type ArgsProcessComponentsHolder struct { StatusCoreComponents factory.StatusCoreComponentsHolder NodesCoordinator nodesCoordinator.NodesCoordinator RunTypeComponents factory.RunTypeComponentsHolder + RunTypeCoreComponents factory.RunTypeCoreComponentsHolder IncomingHeaderSubscriber process.IncomingHeaderSubscriber Configs config.Configs @@ -196,6 +198,7 @@ func CreateProcessComponents(args ArgsProcessComponentsHolder) (*processComponen GenesisNonce: args.GenesisNonce, GenesisRound: args.GenesisRound, RunTypeComponents: args.RunTypeComponents, + RunTypeCoreComponents: args.RunTypeCoreComponents, IncomingHeaderSubscriber: args.IncomingHeaderSubscriber, } processComponentsFactory, err := processComp.NewProcessComponentsFactory(processArgs) diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index e306b732795..d864dd45194 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -103,7 +103,7 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces instance.CoreComponentsHolder, err = CreateCoreComponents(ArgsCoreComponentsHolder{ Config: *args.Configs.GeneralConfig, - EnableEpochsConfig: args.Configs.EpochConfig.EnableEpochs, + EpochsConfig: *args.Configs.EpochConfig, RoundsConfig: *args.Configs.RoundConfig, EconomicsConfig: *args.Configs.EconomicsConfig, ChanStopNodeProcess: args.ChanStopNodeProcess, @@ -244,6 +244,7 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces GenesisNonce: args.InitialNonce, GenesisRound: uint64(args.InitialRound), RunTypeComponents: instance.RunTypeComponents, + RunTypeCoreComponents: runTypeCoreComponents, IncomingHeaderSubscriber: instance.IncomingHeaderSubscriber, }) if err != nil { diff --git a/node/nodeRunner.go b/node/nodeRunner.go index 79a5fd91d08..24a0e7d9ca1 100644 --- a/node/nodeRunner.go +++ b/node/nodeRunner.go @@ -444,6 +444,7 @@ func (nr *nodeRunner) executeOneComponentCreationCycle( managedStatusComponents, managedStatusCoreComponents, managedRunTypeComponents, + managedRunTypeCoreComponents, gasScheduleNotifier, nodesCoordinatorInstance, ) @@ -1180,6 +1181,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) { @@ -1266,6 +1268,7 @@ func (nr *nodeRunner) CreateManagedProcessComponents( FlagsConfig: *configs.FlagsConfig, TxExecutionOrderHandler: txExecutionOrderHandler, RunTypeComponents: runTypeComponents, + RunTypeCoreComponents: runTypeCoreComponents, } processComponentsFactory, err := processComp.NewProcessComponentsFactory(processArgs) if err != nil { @@ -1478,6 +1481,7 @@ func (nr *nodeRunner) CreateManagedCoreComponents( ChanStopNodeProcess: chanStopNodeProcess, GenesisNodesSetupFactory: runTypeCoreComponents.GenesisNodesSetupFactoryCreator(), RatingsDataFactory: runTypeCoreComponents.RatingsDataFactoryCreator(), + EnableEpochsFactory: runTypeCoreComponents.EnableEpochsFactoryCreator(), } coreComponentsFactory, err := coreComp.NewCoreComponentsFactory(coreArgs) diff --git a/testscommon/components/components.go b/testscommon/components/components.go index 6bc286b3cc1..275d5055cc8 100644 --- a/testscommon/components/components.go +++ b/testscommon/components/components.go @@ -145,6 +145,7 @@ func GetCoreArgs() coreComp.CoreComponentsFactoryArgs { }, GenesisNodesSetupFactory: runTypeCoreComponents.GenesisNodesSetupFactoryCreator(), RatingsDataFactory: runTypeCoreComponents.RatingsDataFactoryCreator(), + EnableEpochsFactory: runTypeCoreComponents.EnableEpochsFactoryCreator(), } } @@ -689,8 +690,8 @@ func GetProcessArgs( }, nil }, } - args.RunTypeComponents = runTypeComponents + args.RunTypeCoreComponents = GetRunTypeCoreComponents() return args } @@ -745,6 +746,7 @@ func GetSovereignProcessArgs( processArgs.StatusCoreComponents = statusCoreComponents processArgs.IncomingHeaderSubscriber = &sovereign.IncomingHeaderSubscriberStub{} processArgs.RunTypeComponents = runTypeComponents + processArgs.RunTypeCoreComponents = GetSovereignRunTypeCoreComponents() return processArgs } From 39dd1383c76a62e12b552fc043b667af68b329b3 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Mon, 25 Nov 2024 15:13:49 +0200 Subject: [PATCH 05/23] fixes and unit test files --- common/enablers/enableEpochsFactory.go | 2 ++ common/enablers/enableEpochsFactory_test.go | 22 +++++++++++++++++++ .../enablers/sovereignEnableEpochsFactory.go | 2 ++ .../sovereignEnableEpochsFactory_test.go | 22 +++++++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 common/enablers/enableEpochsFactory_test.go create mode 100644 common/enablers/sovereignEnableEpochsFactory_test.go diff --git a/common/enablers/enableEpochsFactory.go b/common/enablers/enableEpochsFactory.go index 1f097ec5e68..ea7ea40d041 100644 --- a/common/enablers/enableEpochsFactory.go +++ b/common/enablers/enableEpochsFactory.go @@ -8,10 +8,12 @@ import ( 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(epochConfig config.EpochConfig, epochNotifier process.EpochNotifier) (common.EnableEpochsHandler, error) { return NewEnableEpochsHandler(epochConfig.EnableEpochs, epochNotifier) } diff --git a/common/enablers/enableEpochsFactory_test.go b/common/enablers/enableEpochsFactory_test.go new file mode 100644 index 00000000000..4330145be68 --- /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.EpochConfig{}, &epochNotifier.EpochNotifierStub{}) + require.Nil(t, err) + require.NotNil(t, eeh) + require.IsType(t, &enableEpochsHandler{}, eeh) +} diff --git a/common/enablers/sovereignEnableEpochsFactory.go b/common/enablers/sovereignEnableEpochsFactory.go index cc0ff5f846b..1c1a3c22bad 100644 --- a/common/enablers/sovereignEnableEpochsFactory.go +++ b/common/enablers/sovereignEnableEpochsFactory.go @@ -8,10 +8,12 @@ import ( type sovereignEnableEpochsFactory struct{} +// NewSovereignEnableEpochsFactory creates an enable epochs factory for sovereign chain func NewSovereignEnableEpochsFactory() EnableEpochsFactory { return &sovereignEnableEpochsFactory{} } +// CreateEnableEpochsHandler creates an enable epochs handler for sovereign chain func (seef *sovereignEnableEpochsFactory) CreateEnableEpochsHandler(epochConfig config.EpochConfig, epochNotifier process.EpochNotifier) (common.EnableEpochsHandler, error) { return NewSovereignEnableEpochsHandler(epochConfig.EnableEpochs, epochConfig.SovereignEnableEpochs, epochConfig.SovereignChainSpecificEnableEpochs, epochNotifier) diff --git a/common/enablers/sovereignEnableEpochsFactory_test.go b/common/enablers/sovereignEnableEpochsFactory_test.go new file mode 100644 index 00000000000..4921f9e5f47 --- /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() + require.False(t, factory.IsInterfaceNil()) + + eeh, err := factory.CreateEnableEpochsHandler(config.EpochConfig{}, &epochNotifier.EpochNotifierStub{}) + require.Nil(t, err) + require.NotNil(t, eeh) + require.IsType(t, &sovereignEnableEpochsHandler{}, eeh) +} From 24f419a1eeb33b824311f5c8a3b2006e8a422770 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Tue, 26 Nov 2024 14:03:31 +0200 Subject: [PATCH 06/23] mocks and other changes --- genesis/mock/genesisNodesSetupFactoryMock.go | 24 +++++++ genesis/process/genesisBlockCreator_test.go | 8 ++- genesis/process/shardGenesisBlockCreator.go | 3 +- .../process/sovereignGenesisBlockCreator.go | 7 +- testscommon/common/enableEpochsFactoryMock.go | 27 ++++++++ .../genesisMocks/runTypeCoreComponentsStub.go | 66 +++++++++++++++++++ .../mainFactoryMocks/runTypeComponentStub.go | 2 +- testscommon/ratingsDataFactoryMock.go | 25 +++++++ update/mock/nodesSetupHandlerStub.go | 40 +++++++++++ 9 files changed, 192 insertions(+), 10 deletions(-) create mode 100644 genesis/mock/genesisNodesSetupFactoryMock.go create mode 100644 testscommon/common/enableEpochsFactoryMock.go create mode 100644 testscommon/genesisMocks/runTypeCoreComponentsStub.go create mode 100644 testscommon/ratingsDataFactoryMock.go 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/genesisBlockCreator_test.go b/genesis/process/genesisBlockCreator_test.go index fe489d3aee2..221b58d0560 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.NewRunTypeCoreComponentsStub(), 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 @@ -701,7 +703,7 @@ func TestGenesisBlockCreator_CreateGenesisBlockAfterHardForkShouldCreateSCResult ) hardForkGbc, err := NewGenesisBlockCreator(newArgs) assert.Nil(t, err) - err = hardForkGbc.computeInitialDNSAddresses(gbc.arg.EpochConfig.EnableEpochs) + err = hardForkGbc.computeInitialDNSAddresses(gbc.arg.EpochConfig) assert.Nil(t, err) mapAfterHardForkAddresses, err := newArgs.SmartContractParser.GetDeployedSCAddresses(genesis.DNSType) diff --git a/genesis/process/shardGenesisBlockCreator.go b/genesis/process/shardGenesisBlockCreator.go index 769ce68ecd4..4e4415cc437 100644 --- a/genesis/process/shardGenesisBlockCreator.go +++ b/genesis/process/shardGenesisBlockCreator.go @@ -14,8 +14,6 @@ import ( logger "github.com/multiversx/mx-chain-logger-go" "github.com/multiversx/mx-chain-vm-common-go/parsers" - shardData "github.com/multiversx/mx-chain-go/process/factory/shard/data" - "github.com/multiversx/mx-chain-go/common" disabledCommon "github.com/multiversx/mx-chain-go/common/disabled" "github.com/multiversx/mx-chain-go/common/enablers" @@ -31,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" diff --git a/genesis/process/sovereignGenesisBlockCreator.go b/genesis/process/sovereignGenesisBlockCreator.go index ca8fbb299c9..ba83022bf62 100644 --- a/genesis/process/sovereignGenesisBlockCreator.go +++ b/genesis/process/sovereignGenesisBlockCreator.go @@ -13,15 +13,14 @@ import ( "github.com/multiversx/mx-chain-core-go/marshal" vmcommon "github.com/multiversx/mx-chain-vm-common-go" - "github.com/multiversx/mx-chain-go/dataRetriever" - "github.com/multiversx/mx-chain-go/process/factory" - "github.com/multiversx/mx-chain-go/state" - "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/factory/addressDecoder" "github.com/multiversx/mx-chain-go/genesis" genesisCommon "github.com/multiversx/mx-chain-go/genesis/process/common" "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/process/factory" + "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/vm" ) 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/genesisMocks/runTypeCoreComponentsStub.go b/testscommon/genesisMocks/runTypeCoreComponentsStub.go new file mode 100644 index 00000000000..9bedc62e64c --- /dev/null +++ b/testscommon/genesisMocks/runTypeCoreComponentsStub.go @@ -0,0 +1,66 @@ +package genesisMocks + +import ( + "github.com/multiversx/mx-chain-go/common/enablers" + 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" + commonMocks "github.com/multiversx/mx-chain-go/testscommon/common" +) + +// 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: &commonMocks.EnableEpochsFactoryMock{}, + } +} + +// 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 cf905b5a1d4..86d11ba755f 100644 --- a/testscommon/mainFactoryMocks/runTypeComponentStub.go +++ b/testscommon/mainFactoryMocks/runTypeComponentStub.go @@ -165,7 +165,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..14f167ae8a2 100644 --- a/update/mock/nodesSetupHandlerStub.go +++ b/update/mock/nodesSetupHandlerStub.go @@ -150,6 +150,46 @@ func (g *GenesisNodesSetupHandlerStub) MinNumberOfNodes() uint32 { return 1 } +func (g *GenesisNodesSetupHandlerStub) AllInitialNodes() []nodesCoordinator.GenesisNodeInfoHandler { + //TODO implement me + panic("implement me") +} + +func (g *GenesisNodesSetupHandlerStub) InitialNodesPubKeys() map[uint32][]string { + //TODO implement me + panic("implement me") +} + +func (g *GenesisNodesSetupHandlerStub) GetShardIDForPubKey(pubkey []byte) (uint32, error) { + //TODO implement me + panic("implement me") +} + +func (g *GenesisNodesSetupHandlerStub) InitialEligibleNodesPubKeysForShard(shardId uint32) ([]string, error) { + //TODO implement me + panic("implement me") +} + +func (g *GenesisNodesSetupHandlerStub) SetStartTime(startTime int64) { + //TODO implement me + panic("implement me") +} + +func (g *GenesisNodesSetupHandlerStub) MinNumberOfNodesWithHysteresis() uint32 { + //TODO implement me + panic("implement me") +} + +func (g *GenesisNodesSetupHandlerStub) MinShardHysteresisNodes() uint32 { + //TODO implement me + panic("implement me") +} + +func (g *GenesisNodesSetupHandlerStub) MinMetaHysteresisNodes() uint32 { + //TODO implement me + panic("implement me") +} + // IsInterfaceNil - func (g *GenesisNodesSetupHandlerStub) IsInterfaceNil() bool { return g == nil From a0726b2cc9a9765f93443bdfeb8d8fa791a37a6b Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Tue, 26 Nov 2024 14:53:33 +0200 Subject: [PATCH 07/23] unit test fixes --- genesis/process/genesisBlockCreator_test.go | 2 +- .../genesisMocks/runTypeCoreComponentsStub.go | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/genesis/process/genesisBlockCreator_test.go b/genesis/process/genesisBlockCreator_test.go index 221b58d0560..faae06983fe 100644 --- a/genesis/process/genesisBlockCreator_test.go +++ b/genesis/process/genesisBlockCreator_test.go @@ -67,7 +67,7 @@ func createSovereignMockArgument( initialNodes genesis.InitialNodesHandler, entireSupply *big.Int, ) ArgsGenesisBlockCreator { - return createArgument(t, genesisFilename, initialNodes, entireSupply, genesisMocks.NewRunTypeCoreComponentsStub(), genesisMocks.NewSovereignRunTypeComponentsStub()) + return createArgument(t, genesisFilename, initialNodes, entireSupply, genesisMocks.NewSovereignRunTypeCoreComponentsStub(), genesisMocks.NewSovereignRunTypeComponentsStub()) } // TODO improve code coverage of this package diff --git a/testscommon/genesisMocks/runTypeCoreComponentsStub.go b/testscommon/genesisMocks/runTypeCoreComponentsStub.go index 9bedc62e64c..e0619550094 100644 --- a/testscommon/genesisMocks/runTypeCoreComponentsStub.go +++ b/testscommon/genesisMocks/runTypeCoreComponentsStub.go @@ -6,7 +6,6 @@ import ( "github.com/multiversx/mx-chain-go/process/rating" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/testscommon" - commonMocks "github.com/multiversx/mx-chain-go/testscommon/common" ) // RunTypeCoreComponentsStub - @@ -21,7 +20,16 @@ func NewRunTypeCoreComponentsStub() *RunTypeCoreComponentsStub { return &RunTypeCoreComponentsStub{ GenesisNodesSetupFactory: &genesisMocks.GenesisNodesSetupFactoryMock{}, RatingsDataFactory: &testscommon.RatingsDataFactoryMock{}, - EnableEpochsFactory: &commonMocks.EnableEpochsFactoryMock{}, + EnableEpochsFactory: enablers.NewEnableEpochsFactory(), + } +} + +// NewSovereignRunTypeCoreComponentsStub - +func NewSovereignRunTypeCoreComponentsStub() *RunTypeCoreComponentsStub { + return &RunTypeCoreComponentsStub{ + GenesisNodesSetupFactory: &genesisMocks.GenesisNodesSetupFactoryMock{}, + RatingsDataFactory: &testscommon.RatingsDataFactoryMock{}, + EnableEpochsFactory: enablers.NewSovereignEnableEpochsFactory(), } } From 35b4a1b6a34db1711a2d8916ec120e7cccad25ab Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Tue, 26 Nov 2024 16:22:16 +0200 Subject: [PATCH 08/23] fixes after running long tests --- integrationTests/multiShard/hardFork/hardFork_test.go | 5 ++++- integrationTests/testInitializer.go | 3 +++ integrationTests/testProcessorNode.go | 4 +++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/integrationTests/multiShard/hardFork/hardFork_test.go b/integrationTests/multiShard/hardFork/hardFork_test.go index b51087bfc78..7bee894f1a4 100644 --- a/integrationTests/multiShard/hardFork/hardFork_test.go +++ b/integrationTests/multiShard/hardFork/hardFork_test.go @@ -12,12 +12,14 @@ 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" + mxFactory "github.com/multiversx/mx-chain-go/factory" + "github.com/multiversx/mx-chain-go/common/statistics/disabled" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/dataRetriever" @@ -506,6 +508,7 @@ func hardForkImport( HistoryRepository: &dblookupext.HistoryRepositoryStub{}, TxExecutionOrderHandler: &commonMocks.TxExecutionOrderHandlerStub{}, RunTypeComponents: componentsMock.GetRunTypeComponents(), + EnableEpochsFactory: enablers.NewEnableEpochsFactory(), } genesisProcessor, err := process.NewGenesisBlockCreator(argsGenesis) 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 From 8277d4515d8af98c707e480642a43dbe899958ae Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Tue, 26 Nov 2024 17:55:00 +0200 Subject: [PATCH 09/23] fixes after running long tests --- integrationTests/realcomponents/processorRunner.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrationTests/realcomponents/processorRunner.go b/integrationTests/realcomponents/processorRunner.go index d724e5d51ba..fff87f7119f 100644 --- a/integrationTests/realcomponents/processorRunner.go +++ b/integrationTests/realcomponents/processorRunner.go @@ -76,10 +76,10 @@ 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) - pr.createRunTypeCoreComponents(tb) pr.createStatusCoreComponents(tb) pr.createNetworkComponents(tb) pr.createBootstrapComponents(tb) From 08aaac2d3e948dc9f193f821859af8f4aa891f80 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Wed, 27 Nov 2024 10:13:02 +0200 Subject: [PATCH 10/23] unit test fix --- node/chainSimulator/components/processComponents_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/node/chainSimulator/components/processComponents_test.go b/node/chainSimulator/components/processComponents_test.go index 50f28c2e8ef..fce0c1c404c 100644 --- a/node/chainSimulator/components/processComponents_test.go +++ b/node/chainSimulator/components/processComponents_test.go @@ -250,6 +250,7 @@ func createArgsProcessComponentsHolder() ArgsProcessComponentsHolder { args.StateComponents = components.GetStateComponents(args.CoreComponents, args.StatusCoreComponents) args.RunTypeComponents = runTypeComponents + args.RunTypeCoreComponents, _ = createRunTypeCoreComponents() return args } From 392e6463a9e605c1d95e17a4ec4d998748ad2c99 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Wed, 27 Nov 2024 14:52:21 +0200 Subject: [PATCH 11/23] fixes after self review --- .../chainSimulator/sovereignChainSimulator_test.go | 3 --- cmd/sovereignnode/sovereignNodeRunner.go | 6 +++--- factory/processing/processComponents.go | 13 +++++++------ factory/processing/processComponents_test.go | 12 +++++++++++- genesis/process/genesisBlockCreator.go | 3 +-- integrationTests/realcomponents/processorRunner.go | 2 +- node/chainSimulator/components/processComponents.go | 8 ++++---- node/nodeRunner.go | 2 +- testscommon/components/components.go | 4 ++-- 9 files changed, 30 insertions(+), 23 deletions(-) diff --git a/cmd/sovereignnode/chainSimulator/sovereignChainSimulator_test.go b/cmd/sovereignnode/chainSimulator/sovereignChainSimulator_test.go index 4f1397b7657..b5f68cff53b 100644 --- a/cmd/sovereignnode/chainSimulator/sovereignChainSimulator_test.go +++ b/cmd/sovereignnode/chainSimulator/sovereignChainSimulator_test.go @@ -5,7 +5,6 @@ import ( "time" "github.com/multiversx/mx-chain-core-go/core" - logger "github.com/multiversx/mx-chain-logger-go" "github.com/stretchr/testify/require" chainSimulatorCommon "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" @@ -73,8 +72,6 @@ func TestChainSimulator_GenerateBlocksShouldWork(t *testing.T) { time.Sleep(time.Second) - logger.SetLogLevel("*:TRACE") - err = chainSimulator.GenerateBlocks(50) require.Nil(t, err) } diff --git a/cmd/sovereignnode/sovereignNodeRunner.go b/cmd/sovereignnode/sovereignNodeRunner.go index 3d657998df8..7d2c7e59b3b 100644 --- a/cmd/sovereignnode/sovereignNodeRunner.go +++ b/cmd/sovereignnode/sovereignNodeRunner.go @@ -23,8 +23,6 @@ import ( "github.com/multiversx/mx-chain-core-go/core/throttler" "github.com/multiversx/mx-chain-core-go/data/endProcess" outportCore "github.com/multiversx/mx-chain-core-go/data/outport" - "github.com/multiversx/mx-chain-go/process/block/sovereign/incomingHeader" - "github.com/multiversx/mx-chain-go/sovereignnode/notifier" logger "github.com/multiversx/mx-chain-logger-go" "github.com/multiversx/mx-chain-sovereign-bridge-go/cert" factoryBridge "github.com/multiversx/mx-chain-sovereign-bridge-go/client" @@ -70,9 +68,11 @@ import ( trieIteratorsFactory "github.com/multiversx/mx-chain-go/node/trieIterators/factory" "github.com/multiversx/mx-chain-go/outport" "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/process/block/sovereign/incomingHeader" "github.com/multiversx/mx-chain-go/process/interceptors" "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" sovereignConfig "github.com/multiversx/mx-chain-go/sovereignnode/config" + "github.com/multiversx/mx-chain-go/sovereignnode/notifier" sovRunType "github.com/multiversx/mx-chain-go/sovereignnode/runType" "github.com/multiversx/mx-chain-go/state/syncer" "github.com/multiversx/mx-chain-go/storage/cache" @@ -1383,7 +1383,7 @@ func (snr *sovereignNodeRunner) CreateManagedProcessComponents( FlagsConfig: *configs.FlagsConfig, TxExecutionOrderHandler: ordering.NewOrderedCollection(), RunTypeComponents: runTypeComponents, - RunTypeCoreComponents: runTypeCoreComponents, + EnableEpochsFactory: runTypeCoreComponents.EnableEpochsFactoryCreator(), IncomingHeaderSubscriber: incomingHeaderHandler, } processComponentsFactory, err := processComp.NewProcessComponentsFactory(processArgs) diff --git a/factory/processing/processComponents.go b/factory/processing/processComponents.go index 3597fdb0ebd..eece734cef9 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" @@ -161,8 +162,8 @@ type ProcessComponentsFactoryArgs struct { StatusComponents factory.StatusComponentsHolder StatusCoreComponents factory.StatusCoreComponentsHolder RunTypeComponents factory.RunTypeComponentsHolder - RunTypeCoreComponents factory.RunTypeCoreComponentsHolder TxExecutionOrderHandler common.TxExecutionOrderHandler + EnableEpochsFactory enablers.EnableEpochsFactory GenesisNonce uint64 GenesisRound uint64 @@ -205,7 +206,7 @@ type processComponentsFactory struct { statusCoreComponents factory.StatusCoreComponentsHolder txExecutionOrderHandler common.TxExecutionOrderHandler runTypeComponents factory.RunTypeComponentsHolder - runTypeCoreComponents factory.RunTypeCoreComponentsHolder + enableEpochsFactory enablers.EnableEpochsFactory genesisNonce uint64 genesisRound uint64 @@ -251,7 +252,7 @@ func NewProcessComponentsFactory(args ProcessComponentsFactoryArgs) (*processCom genesisRound: args.GenesisRound, roundConfig: args.RoundConfig, runTypeComponents: args.RunTypeComponents, - runTypeCoreComponents: args.RunTypeCoreComponents, + enableEpochsFactory: args.EnableEpochsFactory, incomingHeaderSubscriber: args.IncomingHeaderSubscriber, auctionListSelectorAPI: disabled.NewDisabledAuctionListSelector(), stakingDataProviderAPI: disabled.NewDisabledStakingDataProvider(), @@ -881,7 +882,7 @@ func (pcf *processComponentsFactory) generateGenesisHeadersAndApplyInitialBalanc GenesisNonce: pcf.genesisNonce, GenesisRound: pcf.genesisRound, RunTypeComponents: pcf.runTypeComponents, - EnableEpochsFactory: pcf.runTypeCoreComponents.EnableEpochsFactoryCreator(), + 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, @@ -2120,8 +2121,8 @@ func checkProcessComponentsArgs(args ProcessComponentsFactoryArgs) error { if check.IfNil(args.RunTypeComponents.ExportHandlerFactoryCreator()) { return fmt.Errorf("%s: %w", baseErrMessage, errorsMx.ErrNilExportHandlerFactoryCreator) } - if check.IfNil(args.RunTypeCoreComponents.EnableEpochsFactoryCreator()) { - return fmt.Errorf("%s: %w", baseErrMessage, errorsMx.ErrNilRunTypeCoreComponents) + if check.IfNil(args.EnableEpochsFactory) { + return fmt.Errorf("%s: %w", baseErrMessage, enablers.ErrNilEnableEpochsFactory) } return nil diff --git a/factory/processing/processComponents_test.go b/factory/processing/processComponents_test.go index e0743dd3047..c5b8cf4d7a5 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" @@ -282,7 +283,7 @@ func createProcessComponentsFactoryArgs(runTypeCoreComponents runType.RunTypeCor }, } args.RunTypeComponents = runTypeComponents - args.RunTypeCoreComponents = runTypeCoreComponents + args.EnableEpochsFactory = runTypeCoreComponents.EnableEpochsFactoryCreator() return args } @@ -1061,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("should work", func(t *testing.T) { t.Parallel() diff --git a/genesis/process/genesisBlockCreator.go b/genesis/process/genesisBlockCreator.go index abffff26def..32fadb1a47a 100644 --- a/genesis/process/genesisBlockCreator.go +++ b/genesis/process/genesisBlockCreator.go @@ -13,8 +13,6 @@ 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" @@ -22,6 +20,7 @@ import ( "github.com/multiversx/mx-chain-go/dataRetriever/blockchain" "github.com/multiversx/mx-chain-go/errors" factoryBlock "github.com/multiversx/mx-chain-go/factory/block" + "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" diff --git a/integrationTests/realcomponents/processorRunner.go b/integrationTests/realcomponents/processorRunner.go index fff87f7119f..e3ec5e5e4a2 100644 --- a/integrationTests/realcomponents/processorRunner.go +++ b/integrationTests/realcomponents/processorRunner.go @@ -469,7 +469,7 @@ func (pr *ProcessorRunner) createProcessComponents(tb testing.TB) { StatusCoreComponents: pr.StatusCoreComponents, TxExecutionOrderHandler: txExecutionOrderHandler, RunTypeComponents: pr.RunTypeComponents, - RunTypeCoreComponents: pr.RunTypeCoreComponents, + EnableEpochsFactory: pr.RunTypeCoreComponents.EnableEpochsFactoryCreator(), } processFactory, err := factoryProcessing.NewProcessComponentsFactory(argsProcess) diff --git a/node/chainSimulator/components/processComponents.go b/node/chainSimulator/components/processComponents.go index 557a9a434cb..474f0674a08 100644 --- a/node/chainSimulator/components/processComponents.go +++ b/node/chainSimulator/components/processComponents.go @@ -7,8 +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" @@ -28,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 @@ -44,7 +44,7 @@ type ArgsProcessComponentsHolder struct { StatusCoreComponents factory.StatusCoreComponentsHolder NodesCoordinator nodesCoordinator.NodesCoordinator RunTypeComponents factory.RunTypeComponentsHolder - RunTypeCoreComponents factory.RunTypeCoreComponentsHolder + EnableEpochsFactory enablers.EnableEpochsFactory IncomingHeaderSubscriber process.IncomingHeaderSubscriber Configs config.Configs @@ -198,7 +198,7 @@ func CreateProcessComponents(args ArgsProcessComponentsHolder) (*processComponen GenesisNonce: args.GenesisNonce, GenesisRound: args.GenesisRound, RunTypeComponents: args.RunTypeComponents, - RunTypeCoreComponents: args.RunTypeCoreComponents, + EnableEpochsFactory: args.EnableEpochsFactory, IncomingHeaderSubscriber: args.IncomingHeaderSubscriber, } processComponentsFactory, err := processComp.NewProcessComponentsFactory(processArgs) diff --git a/node/nodeRunner.go b/node/nodeRunner.go index 24a0e7d9ca1..979537c2194 100644 --- a/node/nodeRunner.go +++ b/node/nodeRunner.go @@ -1268,7 +1268,7 @@ func (nr *nodeRunner) CreateManagedProcessComponents( FlagsConfig: *configs.FlagsConfig, TxExecutionOrderHandler: txExecutionOrderHandler, RunTypeComponents: runTypeComponents, - RunTypeCoreComponents: runTypeCoreComponents, + EnableEpochsFactory: runTypeCoreComponents.EnableEpochsFactoryCreator(), } processComponentsFactory, err := processComp.NewProcessComponentsFactory(processArgs) if err != nil { diff --git a/testscommon/components/components.go b/testscommon/components/components.go index 275d5055cc8..ae6bcd95592 100644 --- a/testscommon/components/components.go +++ b/testscommon/components/components.go @@ -691,7 +691,7 @@ func GetProcessArgs( }, } args.RunTypeComponents = runTypeComponents - args.RunTypeCoreComponents = GetRunTypeCoreComponents() + args.EnableEpochsFactory = GetRunTypeCoreComponents().EnableEpochsFactoryCreator() return args } @@ -746,7 +746,7 @@ func GetSovereignProcessArgs( processArgs.StatusCoreComponents = statusCoreComponents processArgs.IncomingHeaderSubscriber = &sovereign.IncomingHeaderSubscriberStub{} processArgs.RunTypeComponents = runTypeComponents - processArgs.RunTypeCoreComponents = GetSovereignRunTypeCoreComponents() + processArgs.EnableEpochsFactory = GetSovereignRunTypeCoreComponents().EnableEpochsFactoryCreator() return processArgs } From 3ecac02c2e236c4c39df21b1e4ba3ca4aa68aa2d Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Wed, 27 Nov 2024 14:56:33 +0200 Subject: [PATCH 12/23] fixes after self review --- integrationTests/multiShard/hardFork/hardFork_test.go | 3 +-- node/chainSimulator/components/processComponents_test.go | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/integrationTests/multiShard/hardFork/hardFork_test.go b/integrationTests/multiShard/hardFork/hardFork_test.go index 7bee894f1a4..f07a53544cd 100644 --- a/integrationTests/multiShard/hardFork/hardFork_test.go +++ b/integrationTests/multiShard/hardFork/hardFork_test.go @@ -18,11 +18,10 @@ import ( "github.com/stretchr/testify/require" "github.com/multiversx/mx-chain-go/common/enablers" - mxFactory "github.com/multiversx/mx-chain-go/factory" - "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" diff --git a/node/chainSimulator/components/processComponents_test.go b/node/chainSimulator/components/processComponents_test.go index fce0c1c404c..12ce95b9f51 100644 --- a/node/chainSimulator/components/processComponents_test.go +++ b/node/chainSimulator/components/processComponents_test.go @@ -247,10 +247,11 @@ func createArgsProcessComponentsHolder() ArgsProcessComponentsHolder { InitialAccounts: initialAccounts, } runTypeComponents, _ := createRunTypeComponents(argsRunType) + runTypeCoreComponents, _ := createRunTypeCoreComponents() args.StateComponents = components.GetStateComponents(args.CoreComponents, args.StatusCoreComponents) args.RunTypeComponents = runTypeComponents - args.RunTypeCoreComponents, _ = createRunTypeCoreComponents() + args.EnableEpochsFactory = runTypeCoreComponents.EnableEpochsFactoryCreator() return args } From 5c8327fa7317f51cd2773787609b77671bdfd51f Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Wed, 27 Nov 2024 14:58:11 +0200 Subject: [PATCH 13/23] fixes after self review --- node/chainSimulator/components/testOnlyProcessingNode.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index d864dd45194..5760f524b94 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -244,7 +244,7 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces GenesisNonce: args.InitialNonce, GenesisRound: uint64(args.InitialRound), RunTypeComponents: instance.RunTypeComponents, - RunTypeCoreComponents: runTypeCoreComponents, + EnableEpochsFactory: runTypeCoreComponents.EnableEpochsFactoryCreator(), IncomingHeaderSubscriber: instance.IncomingHeaderSubscriber, }) if err != nil { From 7a8922fdcbccb15841987af214c498fe8fb1deba Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Thu, 28 Nov 2024 10:24:59 +0200 Subject: [PATCH 14/23] fix sovereign genesis block creator --- genesis/process/sovereignGenesisBlockCreator.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/genesis/process/sovereignGenesisBlockCreator.go b/genesis/process/sovereignGenesisBlockCreator.go index ba83022bf62..14820492779 100644 --- a/genesis/process/sovereignGenesisBlockCreator.go +++ b/genesis/process/sovereignGenesisBlockCreator.go @@ -87,7 +87,7 @@ func (gbc *sovereignGenesisBlockCreator) initGenesisAccounts() error { } func (gbc *sovereignGenesisBlockCreator) createSovereignEmptyGenesisBlocks() (map[uint32]data.HeaderHandler, error) { - err := gbc.computeSovereignDNSAddresses(createGenesisConfig(gbc.arg.EpochConfig)) + err := gbc.computeSovereignDNSAddresses(createSovereignGenesisConfig(gbc.arg.EpochConfig)) if err != nil { return nil, err } @@ -108,6 +108,10 @@ func (gbc *sovereignGenesisBlockCreator) createSovereignEmptyGenesisBlocks() (ma return mapEmptyGenesisBlocks, nil } +func createSovereignGenesisConfig(providedEpochsConfig config.EpochConfig) config.EpochConfig { + return providedEpochsConfig +} + func (gbc *sovereignGenesisBlockCreator) computeSovereignDNSAddresses(epochsConfig config.EpochConfig) error { initialAddresses, err := addressDecoder.DecodeAddresses(gbc.arg.Core.AddressPubKeyConverter(), gbc.arg.DNSV2Addresses) if err != nil { @@ -227,7 +231,7 @@ func createSovereignShardGenesisBlock( arg ArgsGenesisBlockCreator, nodesListSplitter genesis.NodesListSplitter, ) (data.HeaderHandler, [][]byte, *genesis.IndexingData, error) { - sovereignGenesisConfig := createGenesisConfig(arg.EpochConfig) + sovereignGenesisConfig := createSovereignGenesisConfig(arg.EpochConfig) shardProcessors, err := createProcessorsForShardGenesisBlock(arg, sovereignGenesisConfig, createGenesisRoundConfig(arg.RoundConfig)) if err != nil { return nil, nil, nil, err From 368e17ad1f5c831b5ac3a4172798cdae48fab7c7 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Thu, 28 Nov 2024 10:44:51 +0200 Subject: [PATCH 15/23] nodes setup mock updated --- update/mock/nodesSetupHandlerStub.go | 98 +++++++++++++++++++--------- 1 file changed, 68 insertions(+), 30 deletions(-) diff --git a/update/mock/nodesSetupHandlerStub.go b/update/mock/nodesSetupHandlerStub.go index 14f167ae8a2..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,44 +158,74 @@ func (g *GenesisNodesSetupHandlerStub) MinNumberOfNodes() uint32 { return 1 } +// AllInitialNodes - func (g *GenesisNodesSetupHandlerStub) AllInitialNodes() []nodesCoordinator.GenesisNodeInfoHandler { - //TODO implement me - panic("implement me") + if g.AllInitialNodesCalled != nil { + return g.AllInitialNodesCalled() + } + + return nil } +// InitialNodesPubKeys - func (g *GenesisNodesSetupHandlerStub) InitialNodesPubKeys() map[uint32][]string { - //TODO implement me - panic("implement me") + if g.InitialNodesPubKeysCalled != nil { + return g.InitialNodesPubKeysCalled() + } + + return nil } +// GetShardIDForPubKey - func (g *GenesisNodesSetupHandlerStub) GetShardIDForPubKey(pubkey []byte) (uint32, error) { - //TODO implement me - panic("implement me") + if g.GetShardIDForPubKeyCalled != nil { + return g.GetShardIDForPubKeyCalled(pubkey) + } + + return 0, nil } +// InitialEligibleNodesPubKeysForShard - func (g *GenesisNodesSetupHandlerStub) InitialEligibleNodesPubKeysForShard(shardId uint32) ([]string, error) { - //TODO implement me - panic("implement me") + if g.InitialEligibleNodesPubKeysForShardCalled != nil { + return g.InitialEligibleNodesPubKeysForShardCalled(shardId) + } + + return nil, nil } +// SetStartTime - func (g *GenesisNodesSetupHandlerStub) SetStartTime(startTime int64) { - //TODO implement me - panic("implement me") + if g.SetStartTimeCalled != nil { + g.SetStartTimeCalled(startTime) + } } +// MinNumberOfNodesWithHysteresis - func (g *GenesisNodesSetupHandlerStub) MinNumberOfNodesWithHysteresis() uint32 { - //TODO implement me - panic("implement me") + if g.MinNumberOfNodesWithHysteresisCalled != nil { + return g.MinNumberOfNodesWithHysteresisCalled() + } + + return 0 } +// MinShardHysteresisNodes - func (g *GenesisNodesSetupHandlerStub) MinShardHysteresisNodes() uint32 { - //TODO implement me - panic("implement me") + if g.MinShardHysteresisNodesCalled != nil { + return g.MinShardHysteresisNodesCalled() + } + + return 0 } +// MinMetaHysteresisNodes - func (g *GenesisNodesSetupHandlerStub) MinMetaHysteresisNodes() uint32 { - //TODO implement me - panic("implement me") + if g.MinMetaHysteresisNodesCalled != nil { + return g.MinMetaHysteresisNodesCalled() + } + + return 0 } // IsInterfaceNil - From caba123de0d2b1d276417e7a4d66bbe513b70432 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Fri, 6 Dec 2024 15:26:38 +0200 Subject: [PATCH 16/23] refactor the implementation --- .../chainSimulator/sovereignChainSimulator.go | 12 +++++++--- cmd/sovereignnode/config/common.go | 12 ++++++++++ cmd/sovereignnode/config/config.go | 1 + cmd/sovereignnode/main.go | 15 ++++++++++--- common/enablers/enableEpochsFactory.go | 4 ++-- common/enablers/enableEpochsFactory_test.go | 2 +- common/enablers/errors.go | 2 +- common/enablers/interface.go | 2 +- .../enablers/sovereignEnableEpochsFactory.go | 15 ++++++++----- .../sovereignEnableEpochsFactory_test.go | 4 ++-- .../enablers/sovereignEnableEpochsHandler.go | 7 +++--- .../sovereignEnableEpochsHandler_test.go | 4 ++-- config/epochConfig.go | 12 ++-------- config/sovereignEpochConfig.go | 13 +++++++++++ factory/core/coreComponents.go | 2 +- .../runType/sovereignRunTypeCoreComponents.go | 10 ++++++--- .../sovereignRunTypeCoreComponents_test.go | 3 ++- genesis/process/genesisBlockCreator.go | 12 +++++----- genesis/process/genesisBlockCreator_test.go | 2 +- genesis/process/metaGenesisBlockCreator.go | 8 +++---- genesis/process/shardGenesisBlockCreator.go | 22 +++++++++---------- .../process/sovereignGenesisBlockCreator.go | 14 ++++++------ .../components/coreComponents.go | 8 +++---- .../components/coreComponents_test.go | 2 +- .../components/testOnlyProcessingNode.go | 2 +- testscommon/components/components.go | 2 +- .../genesisMocks/runTypeCoreComponentsStub.go | 3 ++- 27 files changed, 118 insertions(+), 77 deletions(-) create mode 100644 config/sovereignEpochConfig.go diff --git a/cmd/sovereignnode/chainSimulator/sovereignChainSimulator.go b/cmd/sovereignnode/chainSimulator/sovereignChainSimulator.go index a7cbc539e23..63f07ad7080 100644 --- a/cmd/sovereignnode/chainSimulator/sovereignChainSimulator.go +++ b/cmd/sovereignnode/chainSimulator/sovereignChainSimulator.go @@ -52,7 +52,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) @@ -85,17 +85,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/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/main.go b/cmd/sovereignnode/main.go index 82187eedf68..6c32338de52 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", "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/common/enablers/enableEpochsFactory.go b/common/enablers/enableEpochsFactory.go index ea7ea40d041..38f5961e55a 100644 --- a/common/enablers/enableEpochsFactory.go +++ b/common/enablers/enableEpochsFactory.go @@ -14,8 +14,8 @@ func NewEnableEpochsFactory() EnableEpochsFactory { } // CreateEnableEpochsHandler creates an enable epochs handler for regular chain -func (eef *enableEpochsFactory) CreateEnableEpochsHandler(epochConfig config.EpochConfig, epochNotifier process.EpochNotifier) (common.EnableEpochsHandler, error) { - return NewEnableEpochsHandler(epochConfig.EnableEpochs, epochNotifier) +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 diff --git a/common/enablers/enableEpochsFactory_test.go b/common/enablers/enableEpochsFactory_test.go index 4330145be68..bc3bc346b3d 100644 --- a/common/enablers/enableEpochsFactory_test.go +++ b/common/enablers/enableEpochsFactory_test.go @@ -15,7 +15,7 @@ func TestEnableEpochsFactory_CreateEnableEpochsHandler(t *testing.T) { factory := NewEnableEpochsFactory() require.False(t, factory.IsInterfaceNil()) - eeh, err := factory.CreateEnableEpochsHandler(config.EpochConfig{}, &epochNotifier.EpochNotifierStub{}) + 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 fec33addec4..6772f09fefb 100644 --- a/common/enablers/errors.go +++ b/common/enablers/errors.go @@ -5,4 +5,4 @@ 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") +var ErrNilEnableEpochsFactory = errors.New("nil enable epochs factory has been provided") diff --git a/common/enablers/interface.go b/common/enablers/interface.go index d44e00373ce..7ab2d0301b4 100644 --- a/common/enablers/interface.go +++ b/common/enablers/interface.go @@ -8,6 +8,6 @@ import ( // EnableEpochsFactory defines enable epochs handler factory behavior type EnableEpochsFactory interface { - CreateEnableEpochsHandler(epochConfig config.EpochConfig, epochNotifier process.EpochNotifier) (common.EnableEpochsHandler, error) + CreateEnableEpochsHandler(enableEpochs config.EnableEpochs, epochNotifier process.EpochNotifier) (common.EnableEpochsHandler, error) IsInterfaceNil() bool } diff --git a/common/enablers/sovereignEnableEpochsFactory.go b/common/enablers/sovereignEnableEpochsFactory.go index 1c1a3c22bad..6afb31b2e50 100644 --- a/common/enablers/sovereignEnableEpochsFactory.go +++ b/common/enablers/sovereignEnableEpochsFactory.go @@ -6,17 +6,20 @@ import ( "github.com/multiversx/mx-chain-go/process" ) -type sovereignEnableEpochsFactory struct{} +type sovereignEnableEpochsFactory struct { + sovereignEpochConfig config.SovereignEpochConfig +} // NewSovereignEnableEpochsFactory creates an enable epochs factory for sovereign chain -func NewSovereignEnableEpochsFactory() EnableEpochsFactory { - return &sovereignEnableEpochsFactory{} +func NewSovereignEnableEpochsFactory(sovereignEpochConfig config.SovereignEpochConfig) EnableEpochsFactory { + return &sovereignEnableEpochsFactory{ + sovereignEpochConfig: sovereignEpochConfig, + } } // CreateEnableEpochsHandler creates an enable epochs handler for sovereign chain -func (seef *sovereignEnableEpochsFactory) CreateEnableEpochsHandler(epochConfig config.EpochConfig, epochNotifier process.EpochNotifier) (common.EnableEpochsHandler, error) { - return NewSovereignEnableEpochsHandler(epochConfig.EnableEpochs, epochConfig.SovereignEnableEpochs, epochConfig.SovereignChainSpecificEnableEpochs, - epochNotifier) +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 diff --git a/common/enablers/sovereignEnableEpochsFactory_test.go b/common/enablers/sovereignEnableEpochsFactory_test.go index 4921f9e5f47..692fecd9916 100644 --- a/common/enablers/sovereignEnableEpochsFactory_test.go +++ b/common/enablers/sovereignEnableEpochsFactory_test.go @@ -12,10 +12,10 @@ import ( func TestSovereignEnableEpochsFactory_CreateEnableEpochsHandler(t *testing.T) { t.Parallel() - factory := NewSovereignEnableEpochsFactory() + factory := NewSovereignEnableEpochsFactory(config.SovereignEpochConfig{}) require.False(t, factory.IsInterfaceNil()) - eeh, err := factory.CreateEnableEpochsHandler(config.EpochConfig{}, &epochNotifier.EpochNotifierStub{}) + 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 index 115a1d379b6..dca0387446e 100644 --- a/common/enablers/sovereignEnableEpochsHandler.go +++ b/common/enablers/sovereignEnableEpochsHandler.go @@ -17,8 +17,7 @@ type sovereignEnableEpochsHandler struct { // NewSovereignEnableEpochsHandler creates a new instance of sovereign enable epochs handler func NewSovereignEnableEpochsHandler( enableEpochsConfig config.EnableEpochs, - sovereignEnableEpochsConfig config.SovereignEnableEpochs, - sovereignChainSpecificEnableEpochsConfig config.SovereignChainSpecificEnableEpochs, + sovereignEpochConfig config.SovereignEpochConfig, epochNotifier process.EpochNotifier, ) (*sovereignEnableEpochsHandler, error) { if check.IfNil(epochNotifier) { @@ -29,8 +28,8 @@ func NewSovereignEnableEpochsHandler( enableEpochsHandler: &enableEpochsHandler{ enableEpochsConfig: enableEpochsConfig, }, - sovereignEnableEpochsConfig: sovereignEnableEpochsConfig, - sovereignChainSpecificEnableEpochsConfig: sovereignChainSpecificEnableEpochsConfig, + sovereignEnableEpochsConfig: sovereignEpochConfig.SovereignEnableEpochs, + sovereignChainSpecificEnableEpochsConfig: sovereignEpochConfig.SovereignChainSpecificEnableEpochs, } sovHandler.createAllFlagsMap() diff --git a/common/enablers/sovereignEnableEpochsHandler_test.go b/common/enablers/sovereignEnableEpochsHandler_test.go index 1c90a13ade6..7c564f50e8d 100644 --- a/common/enablers/sovereignEnableEpochsHandler_test.go +++ b/common/enablers/sovereignEnableEpochsHandler_test.go @@ -18,7 +18,7 @@ func TestNewSovereignEnableEpochsHandler(t *testing.T) { t.Run("nil epoch notifier should error", func(t *testing.T) { t.Parallel() - sovHandler, err := NewSovereignEnableEpochsHandler(createEnableEpochsConfig(), config.SovereignEnableEpochs{}, config.SovereignChainSpecificEnableEpochs{}, nil) + sovHandler, err := NewSovereignEnableEpochsHandler(createEnableEpochsConfig(), config.SovereignEpochConfig{}, nil) require.Equal(t, process.ErrNilEpochNotifier, err) require.True(t, sovHandler.IsInterfaceNil()) }) @@ -26,7 +26,7 @@ func TestNewSovereignEnableEpochsHandler(t *testing.T) { t.Parallel() wasCalled := false - sovHandler, err := NewSovereignEnableEpochsHandler(createEnableEpochsConfig(), config.SovereignEnableEpochs{}, config.SovereignChainSpecificEnableEpochs{}, &epochNotifier.EpochNotifierStub{ + sovHandler, err := NewSovereignEnableEpochsHandler(createEnableEpochsConfig(), config.SovereignEpochConfig{}, &epochNotifier.EpochNotifierStub{ RegisterNotifyHandlerCalled: func(handler vmcommon.EpochSubscriberHandler) { wasCalled = true }, diff --git a/config/epochConfig.go b/config/epochConfig.go index d52b9860410..0fc78e95853 100644 --- a/config/epochConfig.go +++ b/config/epochConfig.go @@ -2,10 +2,8 @@ package config // EpochConfig will hold epoch configurations type EpochConfig struct { - EnableEpochs EnableEpochs - SovereignEnableEpochs SovereignEnableEpochs - SovereignChainSpecificEnableEpochs SovereignChainSpecificEnableEpochs - GasSchedule GasScheduleConfig + EnableEpochs EnableEpochs + GasSchedule GasScheduleConfig } // GasScheduleConfig represents the versioning config area for the gas schedule toml @@ -128,12 +126,6 @@ type EnableEpochs struct { BLSMultiSignerEnableEpoch []MultiSignerConfig } -// 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{} - // GasScheduleByEpochs represents a gas schedule toml entry that will be applied from the provided epoch type GasScheduleByEpochs struct { StartEpoch uint32 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/factory/core/coreComponents.go b/factory/core/coreComponents.go index 58127ed328c..3228ea20285 100644 --- a/factory/core/coreComponents.go +++ b/factory/core/coreComponents.go @@ -259,7 +259,7 @@ func (ccf *coreComponentsFactory) Create() (*coreComponents, error) { } epochNotifier := forking.NewGenericEpochNotifier() - enableEpochsHandler, err := ccf.enableEpochsFactory.CreateEnableEpochsHandler(ccf.epochConfig, epochNotifier) + enableEpochsHandler, err := ccf.enableEpochsFactory.CreateEnableEpochsHandler(ccf.epochConfig.EnableEpochs, epochNotifier) if err != nil { return nil, err } diff --git a/factory/runType/sovereignRunTypeCoreComponents.go b/factory/runType/sovereignRunTypeCoreComponents.go index 8943f521230..a14023472bf 100644 --- a/factory/runType/sovereignRunTypeCoreComponents.go +++ b/factory/runType/sovereignRunTypeCoreComponents.go @@ -2,16 +2,20 @@ 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 @@ -19,7 +23,7 @@ func (srccf *sovereignRunTypeCoreComponentsFactory) Create() *runTypeCoreCompone return &runTypeCoreComponents{ genesisNodesSetupFactory: sharding.NewSovereignGenesisNodesSetupFactory(), ratingsDataFactory: rating.NewSovereignRatingsDataFactory(), - enableEpochsFactory: enablers.NewSovereignEnableEpochsFactory(), + 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/process/genesisBlockCreator.go b/genesis/process/genesisBlockCreator.go index 32fadb1a47a..1207c3176eb 100644 --- a/genesis/process/genesisBlockCreator.go +++ b/genesis/process/genesisBlockCreator.go @@ -264,7 +264,7 @@ func mustDoGenesisProcess(arg ArgsGenesisBlockCreator) bool { } func (gbc *genesisBlockCreator) createEmptyGenesisBlocks() (map[uint32]data.HeaderHandler, error) { - err := gbc.computeInitialDNSAddresses(createGenesisConfig(gbc.arg.EpochConfig)) + err := gbc.computeInitialDNSAddresses(createGenesisConfig(gbc.arg.EpochConfig.EnableEpochs)) if err != nil { return nil, err } @@ -308,7 +308,7 @@ func (gbc *genesisBlockCreator) CreateGenesisBlocks() (map[uint32]data.HeaderHan return nil, err } - err = gbc.computeInitialDNSAddresses(gbc.arg.EpochConfig) + err = gbc.computeInitialDNSAddresses(gbc.arg.EpochConfig.EnableEpochs) if err != nil { return nil, err } @@ -449,19 +449,19 @@ func (gbc *genesisBlockCreator) createHeaders(args *headerCreatorArgs) (map[uint return genesisBlocks, nil } -func (gbc *genesisBlockCreator) computeInitialDNSAddresses(epochsConfig config.EpochConfig) error { +func (gbc *genesisBlockCreator) computeInitialDNSAddresses(enableEpochsConfig config.EnableEpochs) error { isForCurrentShard := func([]byte) bool { // after hardfork we are interested only in the smart contract addresses, as they are already deployed return true } initialAddresses := intermediate.GenerateInitialPublicKeys(genesis.InitialDNSAddress, isForCurrentShard) - return gbc.computeDNSAddresses(epochsConfig, initialAddresses) + return gbc.computeDNSAddresses(enableEpochsConfig, initialAddresses) } // in case of hardfork initial smart contracts deployment is not called as they are all imported from previous state func (gbc *genesisBlockCreator) computeDNSAddresses( - epochsConfig config.EpochConfig, + enableEpochsConfig config.EnableEpochs, initialAddresses [][]byte, ) error { var dnsSC genesis.InitialSmartContractHandler @@ -480,7 +480,7 @@ func (gbc *genesisBlockCreator) computeDNSAddresses( Epoch: gbc.arg.StartEpochNum, TimeStamp: gbc.arg.GenesisTime, } - enableEpochsHandler, err := gbc.arg.EnableEpochsFactory.CreateEnableEpochsHandler(epochsConfig, 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 faae06983fe..0b80dc82a0a 100644 --- a/genesis/process/genesisBlockCreator_test.go +++ b/genesis/process/genesisBlockCreator_test.go @@ -703,7 +703,7 @@ func TestGenesisBlockCreator_CreateGenesisBlockAfterHardForkShouldCreateSCResult ) hardForkGbc, err := NewGenesisBlockCreator(newArgs) assert.Nil(t, err) - err = hardForkGbc.computeInitialDNSAddresses(gbc.arg.EpochConfig) + err = hardForkGbc.computeInitialDNSAddresses(gbc.arg.EpochConfig.EnableEpochs) assert.Nil(t, err) mapAfterHardForkAddresses, err := newArgs.SmartContractParser.GetDeployedSCAddresses(genesis.DNSType) diff --git a/genesis/process/metaGenesisBlockCreator.go b/genesis/process/metaGenesisBlockCreator.go index 86a62b8293b..401b5dbb8d1 100644 --- a/genesis/process/metaGenesisBlockCreator.go +++ b/genesis/process/metaGenesisBlockCreator.go @@ -73,7 +73,7 @@ func CreateMetaGenesisBlock( processors, err := createProcessorsForMetaGenesisBlock( arg, - createGenesisConfig(arg.EpochConfig), + createGenesisConfig(arg.EpochConfig.EnableEpochs), createGenesisRoundConfig(arg.RoundConfig), ) if err != nil { @@ -222,7 +222,7 @@ func createArgsMetaBlockCreatorAfterHardFork( ) (hardForkProcess.ArgsNewMetaBlockCreatorAfterHardFork, error) { tmpArg := arg tmpArg.Accounts = arg.importHandler.GetAccountsDBForShard(core.MetachainShardId) - processors, err := createProcessorsForMetaGenesisBlock(tmpArg, arg.EpochConfig, arg.RoundConfig) + processors, err := createProcessorsForMetaGenesisBlock(tmpArg, arg.EpochConfig.EnableEpochs, arg.RoundConfig) if err != nil { return hardForkProcess.ArgsNewMetaBlockCreatorAfterHardFork{}, err } @@ -301,13 +301,13 @@ func saveGenesisMetaToStorage( return nil } -func createProcessorsForMetaGenesisBlock(arg ArgsGenesisBlockCreator, epochsConfig config.EpochConfig, roundConfig config.RoundConfig) (*genesisProcessors, error) { +func createProcessorsForMetaGenesisBlock(arg ArgsGenesisBlockCreator, enableEpochsConfig config.EnableEpochs, roundConfig config.RoundConfig) (*genesisProcessors, error) { epochNotifier := forking.NewGenericEpochNotifier() temporaryMetaHeader := &block.MetaBlock{ Epoch: arg.StartEpochNum, TimeStamp: arg.GenesisTime, } - enableEpochsHandler, err := arg.EnableEpochsFactory.CreateEnableEpochsHandler(epochsConfig, epochNotifier) + enableEpochsHandler, err := arg.EnableEpochsFactory.CreateEnableEpochsHandler(enableEpochsConfig, epochNotifier) if err != nil { return nil, err } diff --git a/genesis/process/shardGenesisBlockCreator.go b/genesis/process/shardGenesisBlockCreator.go index 4e4415cc437..5ba349e4a10 100644 --- a/genesis/process/shardGenesisBlockCreator.go +++ b/genesis/process/shardGenesisBlockCreator.go @@ -57,19 +57,19 @@ type deployedScMetrics struct { numOtherTypes int } -func createGenesisConfig(providedEpochsConfig config.EpochConfig) config.EpochConfig { - clonedConfig := providedEpochsConfig - clonedConfig.EnableEpochs.BuiltInFunctionsEnableEpoch = 0 - clonedConfig.EnableEpochs.PenalizedTooMuchGasEnableEpoch = unreachableEpoch - clonedConfig.EnableEpochs.MaxNodesChangeEnableEpoch = []config.MaxNodesChangeConfig{ +func createGenesisConfig(providedEnableEpochs config.EnableEpochs) config.EnableEpochs { + clonedConfig := providedEnableEpochs + clonedConfig.BuiltInFunctionsEnableEpoch = 0 + clonedConfig.PenalizedTooMuchGasEnableEpoch = unreachableEpoch + clonedConfig.MaxNodesChangeEnableEpoch = []config.MaxNodesChangeConfig{ { EpochEnable: unreachableEpoch, MaxNumNodes: 0, NodesToShufflePerShard: 0, }, } - clonedConfig.EnableEpochs.StakeEnableEpoch = unreachableEpoch // we need to specifically disable this, we have exceptions in the staking system SC - clonedConfig.EnableEpochs.DoubleKeyProtectionEnableEpoch = 0 + clonedConfig.StakeEnableEpoch = unreachableEpoch // we need to specifically disable this, we have exceptions in the staking system SC + clonedConfig.DoubleKeyProtectionEnableEpoch = 0 return clonedConfig } @@ -92,7 +92,7 @@ func CreateShardGenesisBlock( } processors, err := createProcessorsForShardGenesisBlock( - arg, createGenesisConfig(arg.EpochConfig), + arg, createGenesisConfig(arg.EpochConfig.EnableEpochs), createGenesisRoundConfig(arg.RoundConfig), ) if err != nil { @@ -277,7 +277,7 @@ func createArgsShardBlockCreatorAfterHardFork( ) (hardForkProcess.ArgsNewShardBlockCreatorAfterHardFork, error) { tmpArg := arg tmpArg.Accounts = arg.importHandler.GetAccountsDBForShard(arg.ShardCoordinator.SelfId()) - processors, err := createProcessorsForShardGenesisBlock(tmpArg, arg.EpochConfig, arg.RoundConfig) + processors, err := createProcessorsForShardGenesisBlock(tmpArg, arg.EpochConfig.EnableEpochs, arg.RoundConfig) if err != nil { return hardForkProcess.ArgsNewShardBlockCreatorAfterHardFork{}, err } @@ -357,10 +357,10 @@ func setBalanceToTrie(arg ArgsGenesisBlockCreator, accnt genesis.InitialAccountH return arg.Accounts.SaveAccount(account) } -func createProcessorsForShardGenesisBlock(arg ArgsGenesisBlockCreator, epochsConfig config.EpochConfig, roundConfig config.RoundConfig) (*genesisProcessors, error) { +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 := arg.EnableEpochsFactory.CreateEnableEpochsHandler(epochsConfig, epochNotifier) + enableEpochsHandler, err := arg.EnableEpochsFactory.CreateEnableEpochsHandler(enableEpochsConfig, epochNotifier) if err != nil { return nil, err } diff --git a/genesis/process/sovereignGenesisBlockCreator.go b/genesis/process/sovereignGenesisBlockCreator.go index 14820492779..c26ecc2e890 100644 --- a/genesis/process/sovereignGenesisBlockCreator.go +++ b/genesis/process/sovereignGenesisBlockCreator.go @@ -51,7 +51,7 @@ func (gbc *sovereignGenesisBlockCreator) CreateGenesisBlocks() (map[uint32]data. return gbc.createSovereignEmptyGenesisBlocks() } - err = gbc.computeSovereignDNSAddresses(gbc.arg.EpochConfig) + err = gbc.computeSovereignDNSAddresses(gbc.arg.EpochConfig.EnableEpochs) if err != nil { return nil, err } @@ -87,7 +87,7 @@ func (gbc *sovereignGenesisBlockCreator) initGenesisAccounts() error { } func (gbc *sovereignGenesisBlockCreator) createSovereignEmptyGenesisBlocks() (map[uint32]data.HeaderHandler, error) { - err := gbc.computeSovereignDNSAddresses(createSovereignGenesisConfig(gbc.arg.EpochConfig)) + err := gbc.computeSovereignDNSAddresses(createSovereignGenesisConfig(gbc.arg.EpochConfig.EnableEpochs)) if err != nil { return nil, err } @@ -108,17 +108,17 @@ func (gbc *sovereignGenesisBlockCreator) createSovereignEmptyGenesisBlocks() (ma return mapEmptyGenesisBlocks, nil } -func createSovereignGenesisConfig(providedEpochsConfig config.EpochConfig) config.EpochConfig { - return providedEpochsConfig +func createSovereignGenesisConfig(providedEnableEpochs config.EnableEpochs) config.EnableEpochs { + return providedEnableEpochs } -func (gbc *sovereignGenesisBlockCreator) computeSovereignDNSAddresses(epochsConfig config.EpochConfig) error { +func (gbc *sovereignGenesisBlockCreator) computeSovereignDNSAddresses(enableEpochsConfig config.EnableEpochs) error { initialAddresses, err := addressDecoder.DecodeAddresses(gbc.arg.Core.AddressPubKeyConverter(), gbc.arg.DNSV2Addresses) if err != nil { return err } - return gbc.computeDNSAddresses(epochsConfig, initialAddresses) + return gbc.computeDNSAddresses(enableEpochsConfig, initialAddresses) } func (gbc *sovereignGenesisBlockCreator) createSovereignHeaders(args *headerCreatorArgs) (map[uint32]data.HeaderHandler, error) { @@ -231,7 +231,7 @@ func createSovereignShardGenesisBlock( arg ArgsGenesisBlockCreator, nodesListSplitter genesis.NodesListSplitter, ) (data.HeaderHandler, [][]byte, *genesis.IndexingData, error) { - sovereignGenesisConfig := createSovereignGenesisConfig(arg.EpochConfig) + sovereignGenesisConfig := createSovereignGenesisConfig(arg.EpochConfig.EnableEpochs) shardProcessors, err := createProcessorsForShardGenesisBlock(arg, sovereignGenesisConfig, createGenesisRoundConfig(arg.RoundConfig)) if err != nil { return nil, nil, nil, err diff --git a/node/chainSimulator/components/coreComponents.go b/node/chainSimulator/components/coreComponents.go index 5b882521ccc..7d6760fa0e4 100644 --- a/node/chainSimulator/components/coreComponents.go +++ b/node/chainSimulator/components/coreComponents.go @@ -79,7 +79,7 @@ type coreComponentsHolder struct { // ArgsCoreComponentsHolder will hold arguments needed for the core components holder type ArgsCoreComponentsHolder struct { Config config.Config - EpochsConfig config.EpochConfig + EnableEpochsConfig config.EnableEpochs RoundsConfig config.RoundConfig EconomicsConfig config.EconomicsConfig RatingConfig config.RatingsConfig @@ -165,7 +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 = args.RunTypeCoreComponents.EnableEpochsFactoryCreator().CreateEnableEpochsHandler(args.EpochsConfig, instance.epochNotifier) + instance.enableEpochsHandler, err = args.RunTypeCoreComponents.EnableEpochsFactoryCreator().CreateEnableEpochsHandler(args.EnableEpochsConfig, instance.epochNotifier) if err != nil { return nil, err } @@ -206,9 +206,9 @@ func CreateCoreComponents(args ArgsCoreComponentsHolder) (*coreComponentsHolder, Hysteresis: 0, Adaptivity: false, ShuffleBetweenShards: true, - MaxNodesEnableConfig: args.EpochsConfig.EnableEpochs.MaxNodesChangeEnableEpoch, + MaxNodesEnableConfig: args.EnableEpochsConfig.MaxNodesChangeEnableEpoch, EnableEpochsHandler: instance.enableEpochsHandler, - EnableEpochs: args.EpochsConfig.EnableEpochs, + EnableEpochs: args.EnableEpochsConfig, }) if err != nil { return nil, err diff --git a/node/chainSimulator/components/coreComponents_test.go b/node/chainSimulator/components/coreComponents_test.go index 4f5177a2c05..350b18c50bb 100644 --- a/node/chainSimulator/components/coreComponents_test.go +++ b/node/chainSimulator/components/coreComponents_test.go @@ -46,7 +46,7 @@ func createArgsCoreComponentsHolder() ArgsCoreComponentsHolder { PublicKeyToListenFrom: "41378f754e2c7b2745208c3ed21b151d297acdc84c3aca00b9e292cf28ec2d444771070157ea7760ed83c26f4fed387d0077e00b563a95825dac2cbc349fc0025ccf774e37b0a98ad9724d30e90f8c29b4091ccb738ed9ffc0573df776ee9ea30b3c038b55e532760ea4a8f152f2a52848020e5cee1cc537f2c2323399723081", }, }, - EpochsConfig: config.EpochConfig{}, + EnableEpochsConfig: config.EnableEpochs{}, RoundsConfig: config.RoundConfig{ RoundActivations: map[string]config.ActivationRoundByName{ "DisableAsyncCallV1": { diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index 5760f524b94..81d7aa2e5f0 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -103,7 +103,7 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces instance.CoreComponentsHolder, err = CreateCoreComponents(ArgsCoreComponentsHolder{ Config: *args.Configs.GeneralConfig, - EpochsConfig: *args.Configs.EpochConfig, + EnableEpochsConfig: args.Configs.EpochConfig.EnableEpochs, RoundsConfig: *args.Configs.RoundConfig, EconomicsConfig: *args.Configs.EconomicsConfig, ChanStopNodeProcess: args.ChanStopNodeProcess, diff --git a/testscommon/components/components.go b/testscommon/components/components.go index ae6bcd95592..3bbc90829cb 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()) diff --git a/testscommon/genesisMocks/runTypeCoreComponentsStub.go b/testscommon/genesisMocks/runTypeCoreComponentsStub.go index e0619550094..4b81d0b7c80 100644 --- a/testscommon/genesisMocks/runTypeCoreComponentsStub.go +++ b/testscommon/genesisMocks/runTypeCoreComponentsStub.go @@ -2,6 +2,7 @@ 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" @@ -29,7 +30,7 @@ func NewSovereignRunTypeCoreComponentsStub() *RunTypeCoreComponentsStub { return &RunTypeCoreComponentsStub{ GenesisNodesSetupFactory: &genesisMocks.GenesisNodesSetupFactoryMock{}, RatingsDataFactory: &testscommon.RatingsDataFactoryMock{}, - EnableEpochsFactory: enablers.NewSovereignEnableEpochsFactory(), + EnableEpochsFactory: enablers.NewSovereignEnableEpochsFactory(config.SovereignEpochConfig{}), } } From b8fd2f8844ef81cd4a64632fddc55eac77e6831f Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Mon, 9 Dec 2024 12:34:14 +0200 Subject: [PATCH 17/23] fixes after review --- cmd/sovereignnode/sovereignNodeRunner.go | 26 +++--- factory/core/coreComponents.go | 88 ++++++++----------- factory/core/coreComponents_test.go | 21 +---- .../realcomponents/processorRunner.go | 24 +++-- node/nodeRunner.go | 24 +++-- testscommon/components/components.go | 7 +- 6 files changed, 77 insertions(+), 113 deletions(-) diff --git a/cmd/sovereignnode/sovereignNodeRunner.go b/cmd/sovereignnode/sovereignNodeRunner.go index 1e21ca282a8..233b58b3397 100644 --- a/cmd/sovereignnode/sovereignNodeRunner.go +++ b/cmd/sovereignnode/sovereignNodeRunner.go @@ -1581,19 +1581,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(), - EnableEpochsFactory: runTypeCoreComponents.EnableEpochsFactoryCreator(), + 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) @@ -1686,7 +1684,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/factory/core/coreComponents.go b/factory/core/coreComponents.go index 3228ea20285..0c43dae67f4 100644 --- a/factory/core/coreComponents.go +++ b/factory/core/coreComponents.go @@ -46,36 +46,32 @@ 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 - EnableEpochsFactory enablers.EnableEpochsFactory + 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 - enableEpochsFactory enablers.EnableEpochsFactory + 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 @@ -118,30 +114,22 @@ 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.RatingsDataFactory) { - return nil, errors.ErrNilRatingsDataFactory - } - if check.IfNil(args.EnableEpochsFactory) { - return nil, enablers.ErrNilEnableEpochsFactory + if check.IfNil(args.RunTypeCoreComponents) { + return nil, errors.ErrNilRunTypeCoreComponents } 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, - enableEpochsFactory: args.EnableEpochsFactory, + 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 } @@ -198,7 +186,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, @@ -259,7 +247,7 @@ func (ccf *coreComponentsFactory) Create() (*coreComponents, error) { } epochNotifier := forking.NewGenericEpochNotifier() - enableEpochsHandler, err := ccf.enableEpochsFactory.CreateEnableEpochsHandler(ccf.epochConfig.EnableEpochs, epochNotifier) + enableEpochsHandler, err := ccf.runTypeCoreComponents.EnableEpochsFactoryCreator().CreateEnableEpochsHandler(ccf.epochConfig.EnableEpochs, epochNotifier) if err != nil { return nil, err } @@ -294,7 +282,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 18725226135..fc02bc6cda4 100644 --- a/factory/core/coreComponents_test.go +++ b/factory/core/coreComponents_test.go @@ -6,7 +6,6 @@ import ( "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" coreComp "github.com/multiversx/mx-chain-go/factory/core" @@ -23,26 +22,12 @@ func TestNewCoreComponentsFactory(t *testing.T) { require.NotNil(t, ccf) require.Nil(t, err) }) - t.Run("nil genesis nodes setup factory, should return error", func(t *testing.T) { + t.Run("nil run type core components, should return error", func(t *testing.T) { args := componentsMock.GetCoreArgs() - args.GenesisNodesSetupFactory = nil + args.RunTypeCoreComponents = nil ccf, err := coreComp.NewCoreComponentsFactory(args) require.Nil(t, ccf) - require.Equal(t, errorsMx.ErrNilNodesSetupFactory, err) - }) - t.Run("nil ratings data factory, should return error", func(t *testing.T) { - args := componentsMock.GetCoreArgs() - args.RatingsDataFactory = nil - 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() - args.EnableEpochsFactory = nil - ccf, err := coreComp.NewCoreComponentsFactory(args) - require.Nil(t, ccf) - require.Equal(t, enablers.ErrNilEnableEpochsFactory, err) + require.Equal(t, errorsMx.ErrNilRunTypeCoreComponents, err) }) } diff --git a/integrationTests/realcomponents/processorRunner.go b/integrationTests/realcomponents/processorRunner.go index e3ec5e5e4a2..507ff2e4862 100644 --- a/integrationTests/realcomponents/processorRunner.go +++ b/integrationTests/realcomponents/processorRunner.go @@ -129,19 +129,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: pr.RunTypeCoreComponents.GenesisNodesSetupFactoryCreator(), - RatingsDataFactory: pr.RunTypeCoreComponents.RatingsDataFactoryCreator(), - EnableEpochsFactory: pr.RunTypeCoreComponents.EnableEpochsFactoryCreator(), + 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) diff --git a/node/nodeRunner.go b/node/nodeRunner.go index a30ca623cc3..ed7e5aa8ed2 100644 --- a/node/nodeRunner.go +++ b/node/nodeRunner.go @@ -1465,19 +1465,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(), - EnableEpochsFactory: runTypeCoreComponents.EnableEpochsFactoryCreator(), + 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/testscommon/components/components.go b/testscommon/components/components.go index f429cc163c1..8cddace2e98 100644 --- a/testscommon/components/components.go +++ b/testscommon/components/components.go @@ -143,9 +143,7 @@ func GetCoreArgs() coreComp.CoreComponentsFactoryArgs { }, }, }, - GenesisNodesSetupFactory: runTypeCoreComponents.GenesisNodesSetupFactoryCreator(), - RatingsDataFactory: runTypeCoreComponents.RatingsDataFactoryCreator(), - EnableEpochsFactory: runTypeCoreComponents.EnableEpochsFactoryCreator(), + RunTypeCoreComponents: runTypeCoreComponents, } } @@ -343,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) } From bcbce0e8e4760c362689fb0827de11fb7e836bff Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Mon, 9 Dec 2024 12:37:33 +0200 Subject: [PATCH 18/23] fixes after review --- common/enablers/sovereignEnableEpochsHandler.go | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/common/enablers/sovereignEnableEpochsHandler.go b/common/enablers/sovereignEnableEpochsHandler.go index dca0387446e..cf3eea637c4 100644 --- a/common/enablers/sovereignEnableEpochsHandler.go +++ b/common/enablers/sovereignEnableEpochsHandler.go @@ -1,7 +1,6 @@ package enablers import ( - "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-go/config" @@ -46,19 +45,13 @@ func (sovHandler *sovereignEnableEpochsHandler) createAllFlagsMap() { } func (sovHandler *sovereignEnableEpochsHandler) addSovereignFlags() { - sovereignFlags := map[core.EnableEpochFlag]flagHandler{} - - for key, value := range sovereignFlags { - sovHandler.enableEpochsHandler.allFlagsDefined[key] = value - } + // 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() { - sovereignChainSpecificFlags := map[core.EnableEpochFlag]flagHandler{} - - for key, value := range sovereignChainSpecificFlags { - sovHandler.enableEpochsHandler.allFlagsDefined[key] = value - } + // 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 From 739d48e587e674f180561783ec519cf34e310f4e Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Wed, 11 Dec 2024 15:43:50 +0200 Subject: [PATCH 19/23] added missing checks --- factory/core/coreComponents.go | 9 +++++++ factory/core/coreComponents_test.go | 39 +++++++++++++++++++++++++++++ sharding/errors.go | 3 +++ 3 files changed, 51 insertions(+) diff --git a/factory/core/coreComponents.go b/factory/core/coreComponents.go index 0c43dae67f4..43dd2906b92 100644 --- a/factory/core/coreComponents.go +++ b/factory/core/coreComponents.go @@ -117,6 +117,15 @@ func NewCoreComponentsFactory(args CoreComponentsFactoryArgs) (*coreComponentsFa if check.IfNil(args.RunTypeCoreComponents) { return nil, errors.ErrNilRunTypeCoreComponents } + 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, diff --git a/factory/core/coreComponents_test.go b/factory/core/coreComponents_test.go index fc02bc6cda4..c119627f27d 100644 --- a/factory/core/coreComponents_test.go +++ b/factory/core/coreComponents_test.go @@ -6,11 +6,15 @@ import ( "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/multiversx/mx-chain-go/testscommon/genesisMocks" ) func TestNewCoreComponentsFactory(t *testing.T) { @@ -29,6 +33,41 @@ func TestNewCoreComponentsFactory(t *testing.T) { 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() + rtCoreMock := getRunTypeCoreComponentsMock(componentsMock.GetRunTypeCoreComponents()) + rtCoreMock.GenesisNodesSetupFactory = nil + args.RunTypeCoreComponents = rtCoreMock + ccf, err := coreComp.NewCoreComponentsFactory(args) + require.Nil(t, ccf) + require.Equal(t, sharding.ErrNilGenesisNodesSetupFactory, err) + }) + t.Run("nil ratings data factory, should return error", func(t *testing.T) { + args := componentsMock.GetCoreArgs() + 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/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") From 2cc653bb07fdfe090c6877d008631629c7ec5718 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Wed, 11 Dec 2024 15:48:04 +0200 Subject: [PATCH 20/23] extra comment --- cmd/sovereignnode/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/sovereignnode/main.go b/cmd/sovereignnode/main.go index 6c32338de52..a202fe0b71b 100644 --- a/cmd/sovereignnode/main.go +++ b/cmd/sovereignnode/main.go @@ -245,7 +245,7 @@ func readConfigs(ctx *cli.Context, log logger.Logger) (*sovereignConfig.Sovereig if err != nil { return nil, err } - log.Debug("config", "file", configurationPaths.Epoch) + log.Debug("config sovereign", "file", configurationPaths.Epoch) sovereignExtraConfig.OutGoingBridgeCertificate = config.OutGoingBridgeCertificate{ CertificatePath: ctx.GlobalString(sovereignBridgeCertificateFile.Name), From 4a767ebf45fe2536c82a579f28096b33db663e2d Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Wed, 11 Dec 2024 16:05:39 +0200 Subject: [PATCH 21/23] all flags with epoch 0 --- cmd/sovereignnode/config/enableEpochs.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/sovereignnode/config/enableEpochs.toml b/cmd/sovereignnode/config/enableEpochs.toml index a062bc06eb1..30061772b7a 100644 --- a/cmd/sovereignnode/config/enableEpochs.toml +++ b/cmd/sovereignnode/config/enableEpochs.toml @@ -74,7 +74,7 @@ # 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 = 0 @@ -92,7 +92,7 @@ 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. @@ -108,7 +108,7 @@ ESDTTransferRoleEnableEpoch = 0 # BuiltInFunctionOnMetaEnableEpoch represents the epoch when built in function processing on metachain is enabled - BuiltInFunctionOnMetaEnableEpoch = 1000000 + BuiltInFunctionOnMetaEnableEpoch = 0 # ComputeRewardCheckpointEnableEpoch represents the epoch when compute rewards checkpoint epoch is enabled ComputeRewardCheckpointEnableEpoch = 0 From 2c0776e16cef3139f1c06202f9218bd422e1146d Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Wed, 11 Dec 2024 16:22:30 +0200 Subject: [PATCH 22/23] sovereign epoch config unit test --- config/tomlConfig_test.go | 87 ++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 34 deletions(-) diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index e3a63c47734..1d66b1fac52 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,22 @@ 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) +} From a3798d0197d47132edb484160d1f0f3619451d07 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Fri, 13 Dec 2024 15:10:21 +0200 Subject: [PATCH 23/23] fix testing component --- testscommon/components/components.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/testscommon/components/components.go b/testscommon/components/components.go index 617dd4ffd48..ec360d4dd0d 100644 --- a/testscommon/components/components.go +++ b/testscommon/components/components.go @@ -1228,6 +1228,7 @@ func GetRunTypeComponents() factory.RunTypeComponentsHolder { // GetRunTypeComponentsWithCoreComp - func GetRunTypeComponentsWithCoreComp(coreComponents factory.CoreComponentsHolder) factory.RunTypeComponentsHolder { + generalCfg := GetGeneralConfig() args := runType.ArgsRunTypeComponents{ CoreComponents: coreComponents, CryptoComponents: &mockCoreComp.CryptoComponentsStub{ @@ -1240,6 +1241,7 @@ func GetRunTypeComponentsWithCoreComp(coreComponents factory.CoreComponentsHolde GenesisMintingSenderAddress: "erd17rc0pu8s7rc0pu8s7rc0pu8s7rc0pu8s7rc0pu8s7rc0pu8s7rcqqkhty3", }, }, + GeneralConfig: &generalCfg, }, InitialAccounts: createAccounts(), }