Skip to content

Commit

Permalink
- more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
iulianpascalau committed Nov 8, 2023
1 parent 9d7c7e7 commit b308a29
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 108 deletions.
2 changes: 1 addition & 1 deletion integrationTests/realcomponents/processorRunner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestNewProcessorRunnerAndClose(t *testing.T) {
t.Skip("this is not a short test")
}

cfg, err := testscommon.CreateTestConfigs("../../cmd/node/config")
cfg, err := testscommon.CreateTestConfigs(t.TempDir(), "../../cmd/node/config")
require.Nil(t, err)

pr := NewProcessorRunner(t, *cfg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestTransactionSimulationComponentConstructionOnMetachain(t *testing.T) {
t.Skip("this is not a short test")
}

cfg, err := testscommon.CreateTestConfigs("../../../cmd/node/config")
cfg, err := testscommon.CreateTestConfigs(t.TempDir(), "../../../cmd/node/config")
require.Nil(t, err)

cfg.EpochConfig.EnableEpochs.ESDTEnableEpoch = 0
Expand Down Expand Up @@ -74,7 +74,7 @@ func TestTransactionSimulationComponentConstructionOnShard(t *testing.T) {
t.Skip("this is not a short test")
}

cfg, err := testscommon.CreateTestConfigs("../../../cmd/node/config")
cfg, err := testscommon.CreateTestConfigs(t.TempDir(), "../../../cmd/node/config")
require.Nil(t, err)

cfg.EpochConfig.EnableEpochs.SCDeployEnableEpoch = 0
Expand Down
30 changes: 10 additions & 20 deletions node/chainSimulator/chainSimulator.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package chainSimulator

import (
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/data/endProcess"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/node/chainSimulator/components"
Expand All @@ -19,6 +18,7 @@ type simulator struct {

// NewChainSimulator will create a new instance of simulator
func NewChainSimulator(
tempDir string,
numOfShards uint32,
pathToInitialConfig string,
genesisTimestamp int64,
Expand All @@ -33,7 +33,7 @@ func NewChainSimulator(
chanStopNodeProcess: make(chan endProcess.ArgEndProcess),
}

err := instance.createChainHandlers(numOfShards, pathToInitialConfig, genesisTimestamp, roundDurationInMillis)
err := instance.createChainHandlers(tempDir, numOfShards, pathToInitialConfig, genesisTimestamp, roundDurationInMillis)
if err != nil {
return nil, err
}
Expand All @@ -42,6 +42,7 @@ func NewChainSimulator(
}

func (s *simulator) createChainHandlers(
tempDir string,
numOfShards uint32,
originalConfigPath string,
genesisTimestamp int64,
Expand All @@ -54,38 +55,28 @@ func (s *simulator) createChainHandlers(
GenesisAddressWithBalance: testdata.GenesisAddressWithBalance,
GenesisTimeStamp: genesisTimestamp,
RoundDurationInMillis: roundDurationInMillis,
TempDir: tempDir,
})
if err != nil {
return err
}

blsKey := outputConfigs.ValidatorsPublicKeys[core.MetachainShardId]
metaChainHandler, err := s.createChainHandler(core.MetachainShardId, outputConfigs.Configs, 0, outputConfigs.GasScheduleFilename, blsKey)
if err != nil {
return err
}

s.nodes = append(s.nodes, metaChainHandler)

for idx := uint32(0); idx < numOfShards; idx++ {
blsKey = outputConfigs.ValidatorsPublicKeys[idx+1]
shardChainHandler, errS := s.createChainHandler(idx, outputConfigs.Configs, int(idx)+1, outputConfigs.GasScheduleFilename, blsKey)
if errS != nil {
return errS
for idx := range outputConfigs.ValidatorsPrivateKeys {
chainHandler, errCreate := s.createChainHandler(outputConfigs.Configs, idx, outputConfigs.GasScheduleFilename)
if errCreate != nil {
return errCreate
}

s.nodes = append(s.nodes, shardChainHandler)
s.nodes = append(s.nodes, chainHandler)
}

return nil
}

func (s *simulator) createChainHandler(
shardID uint32,
configs *config.Configs,
skIndex int,
gasScheduleFilename string,
blsKeyBytes []byte,
) (ChainHandler, error) {
args := components.ArgsTestOnlyProcessingNode{
Config: *configs.GeneralConfig,
Expand All @@ -101,7 +92,6 @@ func (s *simulator) createChainHandler(
SyncedBroadcastNetwork: s.syncedBroadcastNetwork,
NumShards: s.numOfShards,
GasScheduleFilename: gasScheduleFilename,
ShardID: shardID,
SkIndex: skIndex,
}

Expand All @@ -110,7 +100,7 @@ func (s *simulator) createChainHandler(
return nil, err
}

return process.NewBlocksCreator(testNode, blsKeyBytes)
return process.NewBlocksCreator(testNode)
}

// GenerateBlocks will generate the provided number of blocks
Expand Down
4 changes: 2 additions & 2 deletions node/chainSimulator/chainSimulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
func TestNewChainSimulator(t *testing.T) {
startTime := time.Now().Unix()
roundDurationInMillis := uint64(6000)
chainSimulator, err := NewChainSimulator(3, defaultPathToInitialConfig, startTime, roundDurationInMillis)
chainSimulator, err := NewChainSimulator(t.TempDir(), 3, defaultPathToInitialConfig, startTime, roundDurationInMillis)
require.Nil(t, err)
require.NotNil(t, chainSimulator)
defer chainSimulator.Stop()
Expand All @@ -25,7 +25,7 @@ func TestNewChainSimulator(t *testing.T) {
func TestChainSimulator_GenerateBlocksShouldWork(t *testing.T) {
startTime := time.Now().Unix()
roundDurationInMillis := uint64(6000)
chainSimulator, err := NewChainSimulator(3, defaultPathToInitialConfig, startTime, roundDurationInMillis)
chainSimulator, err := NewChainSimulator(t.TempDir(), 3, defaultPathToInitialConfig, startTime, roundDurationInMillis)
require.Nil(t, err)
require.NotNil(t, chainSimulator)
defer chainSimulator.Stop()
Expand Down
73 changes: 30 additions & 43 deletions node/chainSimulator/components/testOnlyProcessingNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ type ArgsTestOnlyProcessingNode struct {
SyncedBroadcastNetwork SyncedBroadcastNetworkHandler

GasScheduleFilename string

NumShards uint32
ShardID uint32
SkIndex int
NumShards uint32
SkIndex int
}

type testOnlyProcessingNode struct {
Expand All @@ -55,7 +53,6 @@ type testOnlyProcessingNode struct {

NodesCoordinator nodesCoordinator.NodesCoordinator
ChainHandler chainData.ChainHandler
ShardCoordinator sharding.Coordinator
ArgumentsParser process.ArgumentsParser
TransactionFeeHandler process.TransactionFeeHandler
StoreService dataRetriever.StorageService
Expand All @@ -71,7 +68,9 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces
ArgumentsParser: smartContract.NewArgumentParser(),
StoreService: CreateStore(args.NumShards),
}
err := instance.createBasicComponents(args.NumShards, args.ShardID)

var err error
instance.TransactionFeeHandler, err = postprocess.NewFeeAccumulator()
if err != nil {
return nil, err
}
Expand All @@ -96,25 +95,6 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces
return nil, err
}

err = instance.createBlockChain(args.ShardID)
if err != nil {
return nil, err
}

instance.StateComponentsHolder, err = CreateStateComponents(ArgsStateComponents{
Config: args.Config,
CoreComponents: instance.CoreComponentsHolder,
StatusCore: instance.StatusCoreComponents,
StoreService: instance.StoreService,
ChainHandler: instance.ChainHandler,
})
if err != nil {
return nil, err
}
instance.StatusComponentsHolder, err = CreateStatusComponentsHolder(args.ShardID)
if err != nil {
return nil, err
}
instance.CryptoComponentsHolder, err = CreateCryptoComponentsHolder(ArgsCryptoComponentsHolder{
Config: args.Config,
EnableEpochsConfig: args.EpochConfig.EnableEpochs,
Expand Down Expand Up @@ -147,6 +127,28 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces
return nil, err
}

selfShardID := instance.GetShardCoordinator().SelfId()
instance.StatusComponentsHolder, err = CreateStatusComponentsHolder(selfShardID)
if err != nil {
return nil, err
}

err = instance.createBlockChain(selfShardID)
if err != nil {
return nil, err
}

instance.StateComponentsHolder, err = CreateStateComponents(ArgsStateComponents{
Config: args.Config,
CoreComponents: instance.CoreComponentsHolder,
StatusCore: instance.StatusCoreComponents,
StoreService: instance.StoreService,
ChainHandler: instance.ChainHandler,
})
if err != nil {
return nil, err
}

err = instance.createDataPool(args)
if err != nil {
return nil, err
Expand Down Expand Up @@ -197,21 +199,6 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces
return instance, nil
}

func (node *testOnlyProcessingNode) createBasicComponents(numShards, selfShardID uint32) error {
var err error

node.TransactionFeeHandler, err = postprocess.NewFeeAccumulator()
if err != nil {
return err
}
node.ShardCoordinator, err = sharding.NewMultiShardCoordinator(numShards, selfShardID)
if err != nil {
return err
}

return nil
}

func (node *testOnlyProcessingNode) createBlockChain(selfShardID uint32) error {
var err error
if selfShardID == core.MetachainShardId {
Expand All @@ -229,7 +216,7 @@ func (node *testOnlyProcessingNode) createDataPool(args ArgsTestOnlyProcessingNo
argsDataPool := dataRetrieverFactory.ArgsDataPool{
Config: &args.Config,
EconomicsData: node.CoreComponentsHolder.EconomicsData(),
ShardCoordinator: node.ShardCoordinator,
ShardCoordinator: node.BootstrapComponentsHolder.ShardCoordinator(),
Marshalizer: node.CoreComponentsHolder.InternalMarshalizer(),
PathManager: node.CoreComponentsHolder.PathHandler(),
}
Expand Down Expand Up @@ -265,7 +252,7 @@ func (node *testOnlyProcessingNode) createNodesCoordinator(pref config.Preferenc
node.CoreComponentsHolder.Rater(),
bootstrapStorer,
node.CoreComponentsHolder.NodesShuffler(),
node.ShardCoordinator.SelfId(),
node.BootstrapComponentsHolder.ShardCoordinator().SelfId(),
node.BootstrapComponentsHolder.EpochBootstrapParams(),
node.BootstrapComponentsHolder.EpochBootstrapParams().Epoch(),
node.CoreComponentsHolder.ChanStopNodeProcess(),
Expand Down Expand Up @@ -313,7 +300,7 @@ func (node *testOnlyProcessingNode) GetBroadcastMessenger() consensus.BroadcastM

// GetShardCoordinator will return the shard coordinator
func (node *testOnlyProcessingNode) GetShardCoordinator() sharding.Coordinator {
return node.ShardCoordinator
return node.BootstrapComponentsHolder.ShardCoordinator()
}

// GetCryptoComponents will return the crypto components
Expand Down
10 changes: 0 additions & 10 deletions node/chainSimulator/components/testOnlyProcessingNode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ func createMockArgsTestOnlyProcessingNode(t *testing.T) ArgsTestOnlyProcessingNo
EconomicsConfig: economicsConfig,
GasScheduleFilename: gasScheduleName,
NumShards: 3,
ShardID: 0,
PreferencesConfig: prefsConfig,
SyncedBroadcastNetwork: NewSyncedBroadcastNetwork(),
ImportDBConfig: config.ImportDbConfig{},
Expand All @@ -86,15 +85,6 @@ func createMockArgsTestOnlyProcessingNode(t *testing.T) ArgsTestOnlyProcessingNo
func TestNewTestOnlyProcessingNode(t *testing.T) {
t.Parallel()

t.Run("invalid shard configuration should error", func(t *testing.T) {
t.Parallel()

args := createMockArgsTestOnlyProcessingNode(t)
args.ShardID = args.NumShards
node, err := NewTestOnlyProcessingNode(args)
assert.NotNil(t, err)
assert.Nil(t, node)
})
t.Run("should work", func(t *testing.T) {
if testing.Short() {
t.Skip("cannot run with -race -short; requires Wasm VM fix")
Expand Down
18 changes: 2 additions & 16 deletions node/chainSimulator/configs/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ type ArgsChainSimulatorConfigs struct {
GenesisAddressWithBalance string
GenesisTimeStamp int64
RoundDurationInMillis uint64
TempDir string
}

// ArgsConfigsSimulator holds the configs for the chain simulator
type ArgsConfigsSimulator struct {
GasScheduleFilename string
Configs *config.Configs
ValidatorsPrivateKeys []crypto.PrivateKey
ValidatorsPublicKeys map[uint32][]byte
}

// CreateChainSimulatorConfigs will create the chain simulator configs
func CreateChainSimulatorConfigs(args ArgsChainSimulatorConfigs) (*ArgsConfigsSimulator, error) {
configs, err := testscommon.CreateTestConfigs(args.OriginalConfigsPath)
configs, err := testscommon.CreateTestConfigs(args.TempDir, args.OriginalConfigsPath)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -119,24 +119,10 @@ func CreateChainSimulatorConfigs(args ArgsChainSimulatorConfigs) (*ArgsConfigsSi
// enable db lookup extension
configs.GeneralConfig.DbLookupExtensions.Enabled = true

publicKeysBytes := make(map[uint32][]byte)
publicKeysBytes[core.MetachainShardId], err = publicKeys[0].ToByteArray()
if err != nil {
return nil, err
}

for idx := uint32(1); idx < uint32(len(publicKeys)); idx++ {
publicKeysBytes[idx], err = publicKeys[idx].ToByteArray()
if err != nil {
return nil, err
}
}

return &ArgsConfigsSimulator{
Configs: configs,
ValidatorsPrivateKeys: privateKeys,
GasScheduleFilename: gasScheduleName,
ValidatorsPublicKeys: publicKeysBytes,
}, nil
}

Expand Down
1 change: 1 addition & 0 deletions node/chainSimulator/configs/configs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func TestNewProcessorRunnerChainArguments(t *testing.T) {
GenesisAddressWithBalance: "erd1rhrm20mmf2pugzxc3twlu3fa264hxeefnglsy4ads4dpccs9s3jsg6qdrz",
RoundDurationInMillis: 6000,
GenesisTimeStamp: 0,
TempDir: t.TempDir(),
})
require.Nil(t, err)

Expand Down

0 comments on commit b308a29

Please sign in to comment.