-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5584 from multiversx/bootstrap-components
Bootstrap components
- Loading branch information
Showing
4 changed files
with
161 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters