Skip to content

Commit

Permalink
Merge branch 'rc/v1.7.0' into more_chainSimulator_tests_p2
Browse files Browse the repository at this point in the history
  • Loading branch information
sstanculeanu authored Feb 23, 2024
2 parents 6b87cba + d3489af commit 4493a69
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 10 deletions.
1 change: 1 addition & 0 deletions cmd/node/config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,7 @@
Type = "json"

[EpochStartConfig]
GenesisEpoch = 0
MinRoundsBetweenEpochs = 20
RoundsPerEpoch = 200
# Min and Max ShuffledOutRestartThreshold represents the minimum and maximum duration of an epoch (in percentage) after a node which
Expand Down
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ type EpochStartConfig struct {
MinNumConnectedPeersToStart int
MinNumOfPeersToConsiderBlockValid int
ExtraDelayForRequestBlockInfoInMilliseconds int
GenesisEpoch uint32
}

// BlockSizeThrottleConfig will hold the configuration for adaptive block size throttle
Expand Down
1 change: 1 addition & 0 deletions epochStart/bootstrap/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ func NewEpochStartBootstrap(args ArgsEpochStartBootstrap) (*epochStartBootstrap,
nodeProcessingMode: args.NodeProcessingMode,
nodeOperationMode: common.NormalOperation,
stateStatsHandler: args.StateStatsHandler,
startEpoch: args.GeneralConfig.EpochStartConfig.GenesisEpoch,
}

if epochStartProvider.prefsConfig.FullArchive {
Expand Down
2 changes: 1 addition & 1 deletion epochStart/metachain/epochStartData.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (e *epochStartData) getShardDataFromEpochStartData(
}

epochStartIdentifier := core.EpochStartIdentifier(prevEpoch)
if prevEpoch == 0 {
if prevEpoch == e.genesisEpoch {
return lastMetaHash, []byte(epochStartIdentifier), nil
}

Expand Down
11 changes: 11 additions & 0 deletions factory/processing/processComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ type ProcessComponentsFactoryArgs struct {
StatusComponents factory.StatusComponentsHolder
StatusCoreComponents factory.StatusCoreComponentsHolder
TxExecutionOrderHandler common.TxExecutionOrderHandler

GenesisNonce uint64
GenesisRound uint64
}

type processComponentsFactory struct {
Expand Down Expand Up @@ -196,6 +199,9 @@ type processComponentsFactory struct {
statusComponents factory.StatusComponentsHolder
statusCoreComponents factory.StatusCoreComponentsHolder
txExecutionOrderHandler common.TxExecutionOrderHandler

genesisNonce uint64
genesisRound uint64
}

// NewProcessComponentsFactory will return a new instance of processComponentsFactory
Expand Down Expand Up @@ -232,6 +238,8 @@ func NewProcessComponentsFactory(args ProcessComponentsFactoryArgs) (*processCom
statusCoreComponents: args.StatusCoreComponents,
flagsConfig: args.FlagsConfig,
txExecutionOrderHandler: args.TxExecutionOrderHandler,
genesisNonce: args.GenesisNonce,
genesisRound: args.GenesisRound,
}, nil
}

Expand Down Expand Up @@ -888,6 +896,9 @@ func (pcf *processComponentsFactory) generateGenesisHeadersAndApplyInitialBalanc
GenesisNodePrice: genesisNodePrice,
GenesisString: pcf.config.GeneralSettings.GenesisString,
TxExecutionOrderHandler: pcf.txExecutionOrderHandler,
GenesisEpoch: pcf.config.EpochStartConfig.GenesisEpoch,
GenesisNonce: pcf.genesisNonce,
GenesisRound: pcf.genesisRound,
}

gbc, err := processGenesis.NewGenesisBlockCreator(arg)
Expand Down
3 changes: 3 additions & 0 deletions genesis/process/argGenesisBlockCreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ type dataComponentsHandler interface {
// ArgsGenesisBlockCreator holds the arguments which are needed to create a genesis block
type ArgsGenesisBlockCreator struct {
GenesisTime uint64
GenesisNonce uint64
GenesisRound uint64
StartEpochNum uint32
GenesisEpoch uint32
Data dataComponentsHandler
Core coreComponentsHandler
Accounts state.AccountsAdapter
Expand Down
4 changes: 2 additions & 2 deletions genesis/process/genesisBlockCreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func getGenesisBlocksRoundNonceEpoch(arg ArgsGenesisBlockCreator) (uint64, uint6
if arg.HardForkConfig.AfterHardFork {
return arg.HardForkConfig.StartRound, arg.HardForkConfig.StartNonce, arg.HardForkConfig.StartEpoch
}
return 0, 0, 0
return arg.GenesisRound, arg.GenesisNonce, arg.GenesisEpoch
}

func (gbc *genesisBlockCreator) createHardForkImportHandler() error {
Expand Down Expand Up @@ -212,7 +212,7 @@ func checkArgumentsForBlockCreator(arg ArgsGenesisBlockCreator) error {
}

func mustDoGenesisProcess(arg ArgsGenesisBlockCreator) bool {
genesisEpoch := uint32(0)
genesisEpoch := arg.GenesisEpoch
if arg.HardForkConfig.AfterHardFork {
genesisEpoch = arg.HardForkConfig.StartEpoch
}
Expand Down
4 changes: 4 additions & 0 deletions node/chainSimulator/chainSimulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ type ArgsChainSimulator struct {
MetaChainMinNodes uint32
GenesisTimestamp int64
InitialRound int64
InitialEpoch uint32
InitialNonce uint64
RoundDurationInMillis uint64
RoundsPerEpoch core.OptionalUint64
ApiInterface components.APIConfigurator
Expand Down Expand Up @@ -76,6 +78,7 @@ func (s *simulator) createChainHandlers(args ArgsChainSimulator) error {
MinNodesPerShard: args.MinNodesPerShard,
MetaChainMinNodes: args.MetaChainMinNodes,
RoundsPerEpoch: args.RoundsPerEpoch,
InitialEpoch: args.InitialEpoch,
})
if err != nil {
return err
Expand Down Expand Up @@ -133,6 +136,7 @@ func (s *simulator) createTestNode(
APIInterface: args.ApiInterface,
BypassTxSignatureCheck: args.BypassTxSignatureCheck,
InitialRound: args.InitialRound,
InitialNonce: args.InitialNonce,
MinNodesPerShard: args.MinNodesPerShard,
MinNodesMeta: args.MetaChainMinNodes,
}
Expand Down
17 changes: 11 additions & 6 deletions node/chainSimulator/chainSimulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,23 @@ func TestChainSimulator_GenerateBlocksShouldWork(t *testing.T) {
NumOfShards: 3,
GenesisTimestamp: startTime,
RoundDurationInMillis: roundDurationInMillis,
RoundsPerEpoch: core.OptionalUint64{},
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 1,
MetaChainMinNodes: 1,
InitialRound: 200000000,
RoundsPerEpoch: core.OptionalUint64{
HasValue: true,
Value: 20,
},
ApiInterface: api.NewNoApiInterface(),
MinNodesPerShard: 1,
MetaChainMinNodes: 1,
InitialRound: 200000000,
InitialEpoch: 100,
InitialNonce: 100,
})
require.Nil(t, err)
require.NotNil(t, chainSimulator)

time.Sleep(time.Second)

err = chainSimulator.GenerateBlocks(30)
err = chainSimulator.GenerateBlocks(50)
require.Nil(t, err)

err = chainSimulator.Close()
Expand Down
4 changes: 3 additions & 1 deletion node/chainSimulator/components/manualRoundHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type manualRoundHandler struct {
index int64
genesisTimeStamp int64
roundDuration time.Duration
initialRound int64
}

// NewManualRoundHandler returns a manual round handler instance
Expand All @@ -17,6 +18,7 @@ func NewManualRoundHandler(genesisTimeStamp int64, roundDuration time.Duration,
genesisTimeStamp: genesisTimeStamp,
roundDuration: roundDuration,
index: initialRound,
initialRound: initialRound,
}
}

Expand Down Expand Up @@ -44,7 +46,7 @@ func (handler *manualRoundHandler) TimeStamp() time.Time {
rounds := atomic.LoadInt64(&handler.index)
timeFromGenesis := handler.roundDuration * time.Duration(rounds)
timestamp := time.Unix(handler.genesisTimeStamp, 0).Add(timeFromGenesis)

timestamp = time.Unix(timestamp.Unix()-int64(handler.roundDuration.Seconds())*handler.initialRound, 0)
return timestamp
}

Expand Down
5 changes: 5 additions & 0 deletions node/chainSimulator/components/processComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ type ArgsProcessComponentsHolder struct {
Config config.Config
EconomicsConfig config.EconomicsConfig
SystemSCConfig config.SystemSmartContractsConfig

GenesisNonce uint64
GenesisRound uint64
}

type processComponentsHolder struct {
Expand Down Expand Up @@ -203,6 +206,8 @@ func CreateProcessComponents(args ArgsProcessComponentsHolder) (*processComponen
HistoryRepo: historyRepository,
FlagsConfig: args.FlagsConfig,
TxExecutionOrderHandler: txExecutionOrderHandler,
GenesisNonce: args.GenesisNonce,
GenesisRound: args.GenesisRound,
}
processComponentsFactory, err := processComp.NewProcessComponentsFactory(processArgs)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions node/chainSimulator/components/testOnlyProcessingNode.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type ArgsTestOnlyProcessingNode struct {
SyncedBroadcastNetwork SyncedBroadcastNetworkHandler

InitialRound int64
InitialNonce uint64
GasScheduleFilename string
NumShards uint32
ShardIDStr string
Expand Down Expand Up @@ -205,6 +206,8 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces
ConfigurationPathsHolder: *args.Configs.ConfigurationPathsHolder,
NodesCoordinator: instance.NodesCoordinator,
DataComponents: instance.DataComponentsHolder,
GenesisNonce: args.InitialNonce,
GenesisRound: uint64(args.InitialRound),
})
if err != nil {
return nil, err
Expand Down
3 changes: 3 additions & 0 deletions node/chainSimulator/configs/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type ArgsChainSimulatorConfigs struct {
TempDir string
MinNodesPerShard uint32
MetaChainMinNodes uint32
InitialEpoch uint32
RoundsPerEpoch core.OptionalUint64
}

Expand Down Expand Up @@ -117,6 +118,8 @@ func CreateChainSimulatorConfigs(args ArgsChainSimulatorConfigs) (*ArgsConfigsSi
configs.GeneralConfig.DbLookupExtensions.Enabled = true

configs.GeneralConfig.EpochStartConfig.ExtraDelayForRequestBlockInfoInMilliseconds = 1
configs.GeneralConfig.EpochStartConfig.GenesisEpoch = args.InitialEpoch
configs.EpochConfig.EnableEpochs.StakingV2EnableEpoch = args.InitialEpoch + 1

if args.RoundsPerEpoch.HasValue {
configs.GeneralConfig.EpochStartConfig.RoundsPerEpoch = int64(args.RoundsPerEpoch.Value)
Expand Down
2 changes: 2 additions & 0 deletions node/chainSimulator/process/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ func (creator *blocksCreator) getPreviousHeaderData() (nonce, round uint64, prev
prevHash = creator.nodeHandler.GetChainHandler().GetGenesisHeaderHash()
prevRandSeed = creator.nodeHandler.GetChainHandler().GetGenesisHeader().GetRandSeed()
round = uint64(creator.nodeHandler.GetCoreComponents().RoundHandler().Index()) - 1
epoch = creator.nodeHandler.GetChainHandler().GetGenesisHeader().GetEpoch()
nonce = creator.nodeHandler.GetChainHandler().GetGenesisHeader().GetNonce()

return
}
Expand Down

0 comments on commit 4493a69

Please sign in to comment.