Skip to content

Commit

Permalink
Merge pull request #6061 from multiversx/host-driver-option-chain-sim…
Browse files Browse the repository at this point in the history
…ulator

Host driver option chain simulator
  • Loading branch information
iulianpascalau committed Apr 3, 2024
2 parents fd7b7da + 06f8e33 commit 1bb58ac
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 13 deletions.
41 changes: 36 additions & 5 deletions node/chainSimulator/components/statusComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import (
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/core/appStatusPolling"
"github.com/multiversx/mx-chain-core-go/core/check"
outportCfg "github.com/multiversx/mx-chain-core-go/data/outport"
factoryMarshalizer "github.com/multiversx/mx-chain-core-go/marshal/factory"
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/common/statistics"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/errors"
"github.com/multiversx/mx-chain-go/integrationTests/mock"
"github.com/multiversx/mx-chain-go/outport"
"github.com/multiversx/mx-chain-go/outport/factory"
"github.com/multiversx/mx-chain-go/process"
"github.com/multiversx/mx-chain-go/testscommon"
)
Expand All @@ -32,7 +34,7 @@ type statusComponentsHolder struct {
}

// CreateStatusComponents will create a new instance of status components holder
func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandler, statusPollingIntervalSec int) (*statusComponentsHolder, error) {
func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandler, statusPollingIntervalSec int, external config.ExternalConfig) (*statusComponentsHolder, error) {
if check.IfNil(appStatusHandler) {
return nil, core.ErrNilAppStatusHandler
}
Expand All @@ -44,9 +46,16 @@ func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandl
statusPollingIntervalSec: statusPollingIntervalSec,
}

// TODO add drivers to index data
instance.outportHandler, err = outport.NewOutport(100*time.Millisecond, outportCfg.OutportConfig{
ShardID: shardID,
hostDriverArgs, err := makeHostDriversArgs(external)
if err != nil {
return nil, err
}
instance.outportHandler, err = factory.CreateOutport(&factory.OutportFactoryArgs{
IsImportDB: false,
ShardID: shardID,
RetrialInterval: time.Second,
HostDriversArgs: hostDriverArgs,
EventNotifierFactoryArgs: &factory.EventNotifierFactoryArgs{},
})
if err != nil {
return nil, err
Expand All @@ -59,6 +68,28 @@ func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandl
return instance, nil
}

func makeHostDriversArgs(external config.ExternalConfig) ([]factory.ArgsHostDriverFactory, error) {
argsHostDriverFactorySlice := make([]factory.ArgsHostDriverFactory, 0, len(external.HostDriversConfig))
for idx := 0; idx < len(external.HostDriversConfig); idx++ {
hostConfig := external.HostDriversConfig[idx]
if !hostConfig.Enabled {
continue
}

marshaller, err := factoryMarshalizer.NewMarshalizer(hostConfig.MarshallerType)
if err != nil {
return argsHostDriverFactorySlice, err
}

argsHostDriverFactorySlice = append(argsHostDriverFactorySlice, factory.ArgsHostDriverFactory{
Marshaller: marshaller,
HostConfig: hostConfig,
})
}

return argsHostDriverFactorySlice, nil
}

// OutportHandler will return the outport handler
func (s *statusComponentsHolder) OutportHandler() outport.OutportHandler {
return s.outportHandler
Expand Down
17 changes: 9 additions & 8 deletions node/chainSimulator/components/statusComponents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/core/atomic"
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/config"
mxErrors "github.com/multiversx/mx-chain-go/errors"
"github.com/multiversx/mx-chain-go/integrationTests/mock"
"github.com/multiversx/mx-chain-go/process"
Expand All @@ -20,7 +21,7 @@ func TestCreateStatusComponents(t *testing.T) {
t.Run("should work", func(t *testing.T) {
t.Parallel()

comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5)
comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{})
require.NoError(t, err)
require.NotNil(t, comp)

Expand All @@ -30,7 +31,7 @@ func TestCreateStatusComponents(t *testing.T) {
t.Run("nil app status handler should error", func(t *testing.T) {
t.Parallel()

comp, err := CreateStatusComponents(0, nil, 5)
comp, err := CreateStatusComponents(0, nil, 5, config.ExternalConfig{})
require.Equal(t, core.ErrNilAppStatusHandler, err)
require.Nil(t, comp)
})
Expand All @@ -42,15 +43,15 @@ func TestStatusComponentsHolder_IsInterfaceNil(t *testing.T) {
var comp *statusComponentsHolder
require.True(t, comp.IsInterfaceNil())

comp, _ = CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5)
comp, _ = CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{})
require.False(t, comp.IsInterfaceNil())
require.Nil(t, comp.Close())
}

func TestStatusComponentsHolder_Getters(t *testing.T) {
t.Parallel()

comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5)
comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{})
require.NoError(t, err)

require.NotNil(t, comp.OutportHandler())
Expand All @@ -64,7 +65,7 @@ func TestStatusComponentsHolder_Getters(t *testing.T) {
func TestStatusComponentsHolder_SetForkDetector(t *testing.T) {
t.Parallel()

comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5)
comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{})
require.NoError(t, err)

err = comp.SetForkDetector(nil)
Expand All @@ -82,7 +83,7 @@ func TestStatusComponentsHolder_StartPolling(t *testing.T) {
t.Run("nil fork detector should error", func(t *testing.T) {
t.Parallel()

comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5)
comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{})
require.NoError(t, err)

err = comp.StartPolling()
Expand All @@ -91,7 +92,7 @@ func TestStatusComponentsHolder_StartPolling(t *testing.T) {
t.Run("NewAppStatusPolling failure should error", func(t *testing.T) {
t.Parallel()

comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 0)
comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 0, config.ExternalConfig{})
require.NoError(t, err)

err = comp.SetForkDetector(&mock.ForkDetectorStub{})
Expand All @@ -113,7 +114,7 @@ func TestStatusComponentsHolder_StartPolling(t *testing.T) {
wasSetUInt64ValueCalled.SetValue(true)
},
}
comp, err := CreateStatusComponents(0, appStatusHandler, providedStatusPollingIntervalSec)
comp, err := CreateStatusComponents(0, appStatusHandler, providedStatusPollingIntervalSec, config.ExternalConfig{})
require.NoError(t, err)

forkDetector := &mock.ForkDetectorStub{
Expand Down
9 changes: 9 additions & 0 deletions node/chainSimulator/components/testOnlyProcessingNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces
selfShardID,
instance.StatusCoreComponents.AppStatusHandler(),
args.Configs.GeneralConfig.GeneralSettings.StatusPollingIntervalSec,
*args.Configs.ExternalConfig,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -284,6 +285,14 @@ func (node *testOnlyProcessingNode) createNodesCoordinator(pref config.Preferenc
return err
}

shardID := node.BootstrapComponentsHolder.ShardCoordinator().SelfId()
shardIDStr := fmt.Sprintf("%d", shardID)
if shardID == core.MetachainShardId {
shardIDStr = "metachain"
}

pref.DestinationShardAsObserver = shardIDStr

node.NodesCoordinator, err = bootstrapComp.CreateNodesCoordinator(
nodesShufflerOut,
node.CoreComponentsHolder.GenesisNodesSetup(),
Expand Down

0 comments on commit 1bb58ac

Please sign in to comment.