From 6d2094936d69aa2d0f8b159da2ea6901e366a027 Mon Sep 17 00:00:00 2001 From: Iuga Mihai Date: Fri, 15 Sep 2023 16:15:25 +0300 Subject: [PATCH 1/2] bootstrap components --- node/chainSimulator/bootstrapComponents.go | 124 ++++++++++++++++++ node/chainSimulator/coreComponents.go | 7 +- node/chainSimulator/testOnlyProcessingNode.go | 30 ++++- .../testOnlyProcessingNode_test.go | 11 +- 4 files changed, 162 insertions(+), 10 deletions(-) create mode 100644 node/chainSimulator/bootstrapComponents.go diff --git a/node/chainSimulator/bootstrapComponents.go b/node/chainSimulator/bootstrapComponents.go new file mode 100644 index 00000000000..c9f8bdcce08 --- /dev/null +++ b/node/chainSimulator/bootstrapComponents.go @@ -0,0 +1,124 @@ +package chainSimulator + +import ( + "fmt" + + "github.com/multiversx/mx-chain-core-go/core" + nodeFactory "github.com/multiversx/mx-chain-go/cmd/node/factory" + "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/factory" + bootstrapComp "github.com/multiversx/mx-chain-go/factory/bootstrap" + "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/sharding" +) + +type ArgsBootstrapComponentsHolder struct { + CoreComponents factory.CoreComponentsHolder + CryptoComponents factory.CryptoComponentsHolder + NetworkComponents factory.NetworkComponentsHolder + StatusCoreComponents factory.StatusCoreComponentsHolder + WorkingDir string + FlagsConfig config.ContextFlagsConfig + ImportDBConfig config.ImportDbConfig + PrefsConfig config.Preferences + Config config.Config +} + +type bootstrapComponentsHolder struct { + epochStartBootstrapper factory.EpochStartBootstrapper + epochBootstrapParams factory.BootstrapParamsHolder + nodeType core.NodeType + shardCoordinator sharding.Coordinator + versionedHeaderFactory nodeFactory.VersionedHeaderFactory + headerVersionHandler nodeFactory.HeaderVersionHandler + headerIntegrityVerifier nodeFactory.HeaderIntegrityVerifierHandler + guardedAccountHandler process.GuardedAccountHandler +} + +// CreateBootstrapComponentHolder will create a new instance of bootstrap components holder +func CreateBootstrapComponentHolder(args ArgsBootstrapComponentsHolder) (factory.BootstrapComponentsHolder, error) { + instance := &bootstrapComponentsHolder{} + + bootstrapComponentsFactoryArgs := bootstrapComp.BootstrapComponentsFactoryArgs{ + Config: args.Config, + PrefConfig: args.PrefsConfig, + ImportDbConfig: args.ImportDBConfig, + FlagsConfig: args.FlagsConfig, + WorkingDir: args.WorkingDir, + CoreComponents: args.CoreComponents, + CryptoComponents: args.CryptoComponents, + NetworkComponents: args.NetworkComponents, + StatusCoreComponents: args.StatusCoreComponents, + } + + bootstrapComponentsFactory, err := bootstrapComp.NewBootstrapComponentsFactory(bootstrapComponentsFactoryArgs) + if err != nil { + return nil, fmt.Errorf("NewBootstrapComponentsFactory failed: %w", err) + } + + managedBootstrapComponents, err := bootstrapComp.NewManagedBootstrapComponents(bootstrapComponentsFactory) + if err != nil { + return nil, err + } + + err = managedBootstrapComponents.Create() + if err != nil { + return nil, err + } + + instance.epochStartBootstrapper = managedBootstrapComponents.EpochStartBootstrapper() + instance.epochBootstrapParams = managedBootstrapComponents.EpochBootstrapParams() + instance.nodeType = managedBootstrapComponents.NodeType() + instance.shardCoordinator = managedBootstrapComponents.ShardCoordinator() + instance.versionedHeaderFactory = managedBootstrapComponents.VersionedHeaderFactory() + instance.headerVersionHandler = managedBootstrapComponents.HeaderVersionHandler() + instance.headerIntegrityVerifier = managedBootstrapComponents.HeaderIntegrityVerifier() + instance.guardedAccountHandler = managedBootstrapComponents.GuardedAccountHandler() + + return instance, nil +} + +// EpochStartBootstrapper will return the epoch start bootstrapper +func (b *bootstrapComponentsHolder) EpochStartBootstrapper() factory.EpochStartBootstrapper { + return b.epochStartBootstrapper +} + +// EpochBootstrapParams will return the epoch bootstrap params +func (b *bootstrapComponentsHolder) EpochBootstrapParams() factory.BootstrapParamsHolder { + return b.epochBootstrapParams +} + +// NodeType will return the node type +func (b *bootstrapComponentsHolder) NodeType() core.NodeType { + return b.nodeType +} + +// ShardCoordinator will return the shardCoordinator +func (b *bootstrapComponentsHolder) ShardCoordinator() sharding.Coordinator { + return b.shardCoordinator +} + +// VersionedHeaderFactory will return the versioned header factory +func (b *bootstrapComponentsHolder) VersionedHeaderFactory() nodeFactory.VersionedHeaderFactory { + return b.versionedHeaderFactory +} + +// HeaderVersionHandler will return header version handler +func (b *bootstrapComponentsHolder) HeaderVersionHandler() nodeFactory.HeaderVersionHandler { + return b.headerVersionHandler +} + +// HeaderIntegrityVerifier will return header integrity verifier +func (b *bootstrapComponentsHolder) HeaderIntegrityVerifier() nodeFactory.HeaderIntegrityVerifierHandler { + return b.headerIntegrityVerifier +} + +// GuardedAccountHandler will return guarded account handler +func (b *bootstrapComponentsHolder) GuardedAccountHandler() process.GuardedAccountHandler { + return b.guardedAccountHandler +} + +// IsInterfaceNil returns true if there is no value under the interface +func (b *bootstrapComponentsHolder) IsInterfaceNil() bool { + return b == nil +} diff --git a/node/chainSimulator/coreComponents.go b/node/chainSimulator/coreComponents.go index 4fd8ba9d9e1..339ae33d666 100644 --- a/node/chainSimulator/coreComponents.go +++ b/node/chainSimulator/coreComponents.go @@ -35,6 +35,7 @@ import ( "github.com/multiversx/mx-chain-go/storage" storageFactory "github.com/multiversx/mx-chain-go/storage/factory" "github.com/multiversx/mx-chain-go/testscommon" + "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" ) type coreComponentsHolder struct { @@ -136,7 +137,7 @@ func CreateCoreComponentsHolder(args ArgsCoreComponentsHolder) (factory.CoreComp instance.alarmScheduler = &mock.AlarmSchedulerStub{} instance.syncTimer = &testscommon.SyncTimerStub{} // TODO discuss with Iulian about the round handler - //instance.roundHandler + instance.roundHandler = &testscommon.RoundHandlerMock{} instance.wasmVMChangeLocker = &sync.RWMutex{} instance.txVersionChecker = versioning.NewTxVersionChecker(args.Config.GeneralSettings.MinTransactionVersion) @@ -188,14 +189,14 @@ func CreateCoreComponentsHolder(args ArgsCoreComponentsHolder) (factory.CoreComp // TODO check if we need this instance.ratingsData = nil - instance.rater = nil + instance.rater = &testscommon.RaterMock{} instance.genesisNodesSetup, err = sharding.NewNodesSetup(args.NodesSetupPath, instance.addressPubKeyConverter, instance.validatorPubKeyConverter, args.NumShards) if err != nil { return nil, err } // TODO check if we need nodes shuffler - instance.nodesShuffler = nil + instance.nodesShuffler = &shardingMocks.NodeShufflerMock{} instance.roundNotifier = forking.NewGenericRoundNotifier() instance.enableRoundsHandler, err = enablers.NewEnableRoundsHandler(args.RoundsConfig, instance.roundNotifier) diff --git a/node/chainSimulator/testOnlyProcessingNode.go b/node/chainSimulator/testOnlyProcessingNode.go index 93920b6d4bd..fb31cd7b048 100644 --- a/node/chainSimulator/testOnlyProcessingNode.go +++ b/node/chainSimulator/testOnlyProcessingNode.go @@ -24,6 +24,8 @@ type ArgsTestOnlyProcessingNode struct { EconomicsConfig config.EconomicsConfig RoundsConfig config.RoundConfig PreferencesConfig config.Preferences + ImportDBConfig config.ImportDbConfig + ContextFlagsConfig config.ContextFlagsConfig ChanStopNodeProcess chan endProcess.ArgEndProcess SyncedBroadcastNetwork SyncedBroadcastNetworkHandler GasScheduleFilename string @@ -35,12 +37,13 @@ type ArgsTestOnlyProcessingNode struct { } type testOnlyProcessingNode struct { - CoreComponentsHolder factory.CoreComponentsHolder - StatusCoreComponents factory.StatusCoreComponentsHolder - StateComponentsHolder factory.StateComponentsHolder - StatusComponentsHolder factory.StatusComponentsHolder - CryptoComponentsHolder factory.CryptoComponentsHolder - NetworkComponentsHolder factory.NetworkComponentsHolder + CoreComponentsHolder factory.CoreComponentsHolder + StatusCoreComponents factory.StatusCoreComponentsHolder + StateComponentsHolder factory.StateComponentsHolder + StatusComponentsHolder factory.StatusComponentsHolder + CryptoComponentsHolder factory.CryptoComponentsHolder + NetworkComponentsHolder factory.NetworkComponentsHolder + BootstrapComponentsHolder factory.BootstrapComponentsHolder ChainHandler chainData.ChainHandler ShardCoordinator sharding.Coordinator @@ -118,6 +121,21 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces return nil, err } + instance.BootstrapComponentsHolder, err = CreateBootstrapComponentHolder(ArgsBootstrapComponentsHolder{ + CoreComponents: instance.CoreComponentsHolder, + CryptoComponents: instance.CryptoComponentsHolder, + NetworkComponents: instance.NetworkComponentsHolder, + StatusCoreComponents: instance.StatusCoreComponents, + WorkingDir: args.WorkingDir, + FlagsConfig: args.ContextFlagsConfig, + ImportDBConfig: args.ImportDBConfig, + PrefsConfig: args.PreferencesConfig, + Config: args.Config, + }) + if err != nil { + return nil, err + } + err = instance.createDataPool(args) if err != nil { return nil, err diff --git a/node/chainSimulator/testOnlyProcessingNode_test.go b/node/chainSimulator/testOnlyProcessingNode_test.go index d9114cb1ca6..1fdad961c81 100644 --- a/node/chainSimulator/testOnlyProcessingNode_test.go +++ b/node/chainSimulator/testOnlyProcessingNode_test.go @@ -1,6 +1,7 @@ package chainSimulator import ( + "os" "testing" "github.com/multiversx/mx-chain-go/config" @@ -30,8 +31,12 @@ func createMockArgsTestOnlyProcessingNode(t *testing.T) ArgsTestOnlyProcessingNo err = LoadConfigFromFile(pathForPrefsConfig, &prefsConfig) assert.Nil(t, err) + workingDir, err := os.Getwd() + assert.Nil(t, err) + return ArgsTestOnlyProcessingNode{ - Config: mainConfig, + Config: mainConfig, + WorkingDir: workingDir, EnableEpochsConfig: config.EnableEpochs{ BLSMultiSignerEnableEpoch: []config.MultiSignerConfig{ {EnableEpoch: 0, Type: "KOSK"}, @@ -52,6 +57,10 @@ func createMockArgsTestOnlyProcessingNode(t *testing.T) ArgsTestOnlyProcessingNo ValidatorPemFile: validatorPemFile, PreferencesConfig: prefsConfig, SyncedBroadcastNetwork: NewSyncedBroadcastNetwork(), + ImportDBConfig: config.ImportDbConfig{}, + ContextFlagsConfig: config.ContextFlagsConfig{ + WorkingDir: workingDir, + }, } } From 7701a262c28a3a12a130f3426c236c85351d5a8e Mon Sep 17 00:00:00 2001 From: Iuga Mihai Date: Tue, 19 Sep 2023 09:00:13 +0300 Subject: [PATCH 2/2] fixes after review --- node/chainSimulator/bootstrapComponents.go | 1 + node/chainSimulator/testOnlyProcessingNode_test.go | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/node/chainSimulator/bootstrapComponents.go b/node/chainSimulator/bootstrapComponents.go index c9f8bdcce08..3cbd144dc50 100644 --- a/node/chainSimulator/bootstrapComponents.go +++ b/node/chainSimulator/bootstrapComponents.go @@ -12,6 +12,7 @@ import ( "github.com/multiversx/mx-chain-go/sharding" ) +// ArgsBootstrapComponentsHolder will hold the components needed for the bootstrap components holders type ArgsBootstrapComponentsHolder struct { CoreComponents factory.CoreComponentsHolder CryptoComponents factory.CryptoComponentsHolder diff --git a/node/chainSimulator/testOnlyProcessingNode_test.go b/node/chainSimulator/testOnlyProcessingNode_test.go index 1fdad961c81..829d6fb681a 100644 --- a/node/chainSimulator/testOnlyProcessingNode_test.go +++ b/node/chainSimulator/testOnlyProcessingNode_test.go @@ -1,7 +1,6 @@ package chainSimulator import ( - "os" "testing" "github.com/multiversx/mx-chain-go/config" @@ -31,8 +30,7 @@ func createMockArgsTestOnlyProcessingNode(t *testing.T) ArgsTestOnlyProcessingNo err = LoadConfigFromFile(pathForPrefsConfig, &prefsConfig) assert.Nil(t, err) - workingDir, err := os.Getwd() - assert.Nil(t, err) + workingDir := t.TempDir() return ArgsTestOnlyProcessingNode{ Config: mainConfig,