Skip to content

Commit

Permalink
Merge pull request #5584 from multiversx/bootstrap-components
Browse files Browse the repository at this point in the history
Bootstrap components
  • Loading branch information
miiu96 authored Sep 19, 2023
2 parents 03cff0d + 7701a26 commit b770ff2
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 10 deletions.
125 changes: 125 additions & 0 deletions node/chainSimulator/bootstrapComponents.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
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"
)

// ArgsBootstrapComponentsHolder will hold the components needed for the bootstrap components holders
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
}
7 changes: 4 additions & 3 deletions node/chainSimulator/coreComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
30 changes: 24 additions & 6 deletions node/chainSimulator/testOnlyProcessingNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion node/chainSimulator/testOnlyProcessingNode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ func createMockArgsTestOnlyProcessingNode(t *testing.T) ArgsTestOnlyProcessingNo
err = LoadConfigFromFile(pathForPrefsConfig, &prefsConfig)
assert.Nil(t, err)

workingDir := t.TempDir()

return ArgsTestOnlyProcessingNode{
Config: mainConfig,
Config: mainConfig,
WorkingDir: workingDir,
EnableEpochsConfig: config.EnableEpochs{
BLSMultiSignerEnableEpoch: []config.MultiSignerConfig{
{EnableEpoch: 0, Type: "KOSK"},
Expand All @@ -52,6 +55,10 @@ func createMockArgsTestOnlyProcessingNode(t *testing.T) ArgsTestOnlyProcessingNo
ValidatorPemFile: validatorPemFile,
PreferencesConfig: prefsConfig,
SyncedBroadcastNetwork: NewSyncedBroadcastNetwork(),
ImportDBConfig: config.ImportDbConfig{},
ContextFlagsConfig: config.ContextFlagsConfig{
WorkingDir: workingDir,
},
}
}

Expand Down

0 comments on commit b770ff2

Please sign in to comment.