Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chain_simulator] Enable http server option #5699

Merged
merged 8 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 17 additions & 2 deletions node/chainSimulator/chainSimulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func NewChainSimulator(
genesisTimestamp int64,
roundDurationInMillis uint64,
roundsPerEpoch core.OptionalUint64,
enableHttpServer bool,
) (*simulator, error) {
syncedBroadcastNetwork := components.NewSyncedBroadcastNetwork()

Expand All @@ -42,7 +43,7 @@ func NewChainSimulator(
chanStopNodeProcess: make(chan endProcess.ArgEndProcess),
}

err := instance.createChainHandlers(tempDir, numOfShards, pathToInitialConfig, genesisTimestamp, roundDurationInMillis, roundsPerEpoch)
err := instance.createChainHandlers(tempDir, numOfShards, pathToInitialConfig, genesisTimestamp, roundDurationInMillis, roundsPerEpoch, enableHttpServer)
if err != nil {
return nil, err
}
Expand All @@ -57,6 +58,7 @@ func (s *simulator) createChainHandlers(
genesisTimestamp int64,
roundDurationInMillis uint64,
roundsPerEpoch core.OptionalUint64,
enableHttpServer bool,
) error {
outputConfigs, err := configs.CreateChainSimulatorConfigs(configs.ArgsChainSimulatorConfigs{
NumOfShards: numOfShards,
Expand All @@ -76,7 +78,7 @@ func (s *simulator) createChainHandlers(
}

for idx := range outputConfigs.ValidatorsPrivateKeys {
node, errCreate := s.createTestNode(outputConfigs.Configs, idx, outputConfigs.GasScheduleFilename)
node, errCreate := s.createTestNode(outputConfigs.Configs, idx, outputConfigs.GasScheduleFilename, enableHttpServer)
if errCreate != nil {
return errCreate
}
Expand Down Expand Up @@ -106,8 +108,10 @@ func (s *simulator) createTestNode(
configs *config.Configs,
skIndex int,
gasScheduleFilename string,
enableHttpServer bool,
) (process.NodeHandler, error) {
args := components.ArgsTestOnlyProcessingNode{
Configs: *configs,
Config: *configs.GeneralConfig,
EpochConfig: *configs.EpochConfig,
EconomicsConfig: *configs.EconomicsConfig,
Expand All @@ -122,6 +126,7 @@ func (s *simulator) createTestNode(
NumShards: s.numOfShards,
GasScheduleFilename: gasScheduleFilename,
SkIndex: skIndex,
EnableHTTPServer: enableHttpServer,
}

return components.NewTestOnlyProcessingNode(args)
Expand Down Expand Up @@ -161,6 +166,16 @@ func (s *simulator) GetNodeHandler(shardID uint32) process.NodeHandler {
return s.nodes[shardID]
}

// GetRestAPIInterfaces will return a map with the rest api interfaces for every node
func (s *simulator) GetRestAPIInterfaces() map[uint32]string {
resMap := make(map[uint32]string)
for shardID, node := range s.nodes {
resMap[shardID] = node.GetFacadeHandler().RestApiInterface()
}

return resMap
}

// Close will stop and close the simulator
func (s *simulator) Close() error {
var errorStrings []string
Expand Down
8 changes: 5 additions & 3 deletions node/chainSimulator/chainSimulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const (
func TestNewChainSimulator(t *testing.T) {
startTime := time.Now().Unix()
roundDurationInMillis := uint64(6000)
chainSimulator, err := NewChainSimulator(t.TempDir(), 3, defaultPathToInitialConfig, startTime, roundDurationInMillis, core.OptionalUint64{})
chainSimulator, err := NewChainSimulator(t.TempDir(), 3, defaultPathToInitialConfig, startTime, roundDurationInMillis, core.OptionalUint64{}, false)
require.Nil(t, err)
require.NotNil(t, chainSimulator)

Expand All @@ -31,7 +31,7 @@ func TestNewChainSimulator(t *testing.T) {
func TestChainSimulator_GenerateBlocksShouldWork(t *testing.T) {
startTime := time.Now().Unix()
roundDurationInMillis := uint64(6000)
chainSimulator, err := NewChainSimulator(t.TempDir(), 3, defaultPathToInitialConfig, startTime, roundDurationInMillis, core.OptionalUint64{})
chainSimulator, err := NewChainSimulator(t.TempDir(), 3, defaultPathToInitialConfig, startTime, roundDurationInMillis, core.OptionalUint64{}, false)
require.Nil(t, err)
require.NotNil(t, chainSimulator)

Expand All @@ -51,7 +51,7 @@ func TestChainSimulator_GenerateBlocksAndEpochChangeShouldWork(t *testing.T) {
HasValue: true,
Value: 20,
}
chainSimulator, err := NewChainSimulator(t.TempDir(), 3, defaultPathToInitialConfig, startTime, roundDurationInMillis, roundsPerEpoch)
chainSimulator, err := NewChainSimulator(t.TempDir(), 3, defaultPathToInitialConfig, startTime, roundDurationInMillis, roundsPerEpoch, false)
require.Nil(t, err)
require.NotNil(t, chainSimulator)

Expand All @@ -72,6 +72,8 @@ func TestChainSimulator_GenerateBlocksAndEpochChangeShouldWork(t *testing.T) {
assert.True(t, accountAfterRewards.GetBalance().Cmp(initialAccount.GetBalance()) > 0,
fmt.Sprintf("initial balance %s, balance after rewards %s", initialAccount.GetBalance().String(), accountAfterRewards.GetBalance().String()))

fmt.Println(chainSimulator.GetRestAPIInterfaces())

err = chainSimulator.Close()
assert.Nil(t, err)
}
17 changes: 16 additions & 1 deletion node/chainSimulator/components/bootstrapComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type bootstrapComponentsHolder struct {
}

// CreateBootstrapComponentHolder will create a new instance of bootstrap components holder
func CreateBootstrapComponentHolder(args ArgsBootstrapComponentsHolder) (factory.BootstrapComponentsHolder, error) {
func CreateBootstrapComponentHolder(args ArgsBootstrapComponentsHolder) (factory.BootstrapComponentsHandler, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename to CreateBootstrapComponents and remove the inner closeHandler declaration & usage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed

instance := &bootstrapComponentsHolder{
closeHandler: NewCloseHandler(),
}
Expand Down Expand Up @@ -137,3 +137,18 @@ func (b *bootstrapComponentsHolder) Close() error {
func (b *bootstrapComponentsHolder) IsInterfaceNil() bool {
return b == nil
}

// Create will do nothing
func (b *bootstrapComponentsHolder) Create() error {
return nil
}

// CheckSubcomponents will do nothing
func (b *bootstrapComponentsHolder) CheckSubcomponents() error {
return nil
}

// String will do nothing
func (b *bootstrapComponentsHolder) String() string {
return ""
}
17 changes: 16 additions & 1 deletion node/chainSimulator/components/coreComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type ArgsCoreComponentsHolder struct {
}

// CreateCoreComponentsHolder will create a new instance of factory.CoreComponentsHolder
func CreateCoreComponentsHolder(args ArgsCoreComponentsHolder) (factory.CoreComponentsHolder, error) {
func CreateCoreComponentsHolder(args ArgsCoreComponentsHolder) (factory.CoreComponentsHandler, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename to CreateCoreComponents and remove the inner closeHandler declaration & usage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed

var err error
instance := &coreComponentsHolder{
closeHandler: NewCloseHandler(),
Expand Down Expand Up @@ -433,3 +433,18 @@ func (c *coreComponentsHolder) Close() error {
func (c *coreComponentsHolder) IsInterfaceNil() bool {
return c == nil
}

// Create will do nothing
func (c *coreComponentsHolder) Create() error {
return nil
}

// CheckSubcomponents will do nothing
func (c *coreComponentsHolder) CheckSubcomponents() error {
return nil
}

// String will do nothing
func (c *coreComponentsHolder) String() string {
return ""
}
22 changes: 21 additions & 1 deletion node/chainSimulator/components/cryptoComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type cryptoComponentsHolder struct {
}

// CreateCryptoComponentsHolder will create a new instance of cryptoComponentsHolder
func CreateCryptoComponentsHolder(args ArgsCryptoComponentsHolder) (factory.CryptoComponentsHolder, error) {
func CreateCryptoComponentsHolder(args ArgsCryptoComponentsHolder) (factory.CryptoComponentsHandler, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename to CreateCryptoComponents

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed

instance := &cryptoComponentsHolder{}

cryptoComponentsHandlerArgs := cryptoComp.CryptoComponentsFactoryArgs{
Expand Down Expand Up @@ -237,3 +237,23 @@ func (c *cryptoComponentsHolder) Clone() interface{} {
func (c *cryptoComponentsHolder) IsInterfaceNil() bool {
return c == nil
}

// Create will do nothing
func (c *cryptoComponentsHolder) Create() error {
return nil
}

// CheckSubcomponents will do nothing
func (c *cryptoComponentsHolder) CheckSubcomponents() error {
return nil
}

// String will do nothing
func (c *cryptoComponentsHolder) String() string {
return ""
}

// Close will do nothing
func (c *cryptoComponentsHolder) Close() error {
return nil
}
17 changes: 16 additions & 1 deletion node/chainSimulator/components/dataComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type dataComponentsHolder struct {
}

// CreateDataComponentsHolder will create the data components holder
func CreateDataComponentsHolder(args ArgsDataComponentsHolder) (factory.DataComponentsHolder, error) {
func CreateDataComponentsHolder(args ArgsDataComponentsHolder) (factory.DataComponentsHandler, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename to CreateDataComponents and remove the inner closeHandler declaration & usage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed

miniBlockStorer, err := args.StorageService.GetStorer(dataRetriever.MiniBlockUnit)
if err != nil {
return nil, err
Expand Down Expand Up @@ -106,3 +106,18 @@ func (d *dataComponentsHolder) Close() error {
func (d *dataComponentsHolder) IsInterfaceNil() bool {
return d == nil
}

// Create will do nothing
func (d *dataComponentsHolder) Create() error {
return nil
}

// CheckSubcomponents will do nothing
func (d *dataComponentsHolder) CheckSubcomponents() error {
return nil
}

// String will do nothing
func (d *dataComponentsHolder) String() string {
return ""
}
17 changes: 16 additions & 1 deletion node/chainSimulator/components/networkComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type networkComponentsHolder struct {
}

// CreateNetworkComponentsHolder creates a new networkComponentsHolder instance
func CreateNetworkComponentsHolder(network SyncedBroadcastNetworkHandler) (*networkComponentsHolder, error) {
func CreateNetworkComponentsHolder(network SyncedBroadcastNetworkHandler) (factory.NetworkComponentsHandler, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename to CreateNetworkComponents and remove the inner closeHandler declaration & usage

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

messenger, err := NewSyncedMessenger(network)
if err != nil {
return nil, err
Expand Down Expand Up @@ -125,3 +125,18 @@ func (holder *networkComponentsHolder) Close() error {
func (holder *networkComponentsHolder) IsInterfaceNil() bool {
return holder == nil
}

// Create will do nothing
func (holder *networkComponentsHolder) Create() error {
return nil
}

// CheckSubcomponents will do nothing
func (holder *networkComponentsHolder) CheckSubcomponents() error {
return nil
}

// String will do nothing
func (holder *networkComponentsHolder) String() string {
return ""
}