diff --git a/cmd/node/config/config.toml b/cmd/node/config/config.toml index 3bf2f0b0cf2..b6c11452a64 100644 --- a/cmd/node/config/config.toml +++ b/cmd/node/config/config.toml @@ -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 diff --git a/config/config.go b/config/config.go index f2454a6e52f..472378d49fd 100644 --- a/config/config.go +++ b/config/config.go @@ -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 diff --git a/epochStart/bootstrap/process.go b/epochStart/bootstrap/process.go index d2c0aa199ae..0055fa8995a 100644 --- a/epochStart/bootstrap/process.go +++ b/epochStart/bootstrap/process.go @@ -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 { diff --git a/epochStart/metachain/epochStartData.go b/epochStart/metachain/epochStartData.go index 1c6bd30516e..1a67b3a3692 100644 --- a/epochStart/metachain/epochStartData.go +++ b/epochStart/metachain/epochStartData.go @@ -289,7 +289,7 @@ func (e *epochStartData) getShardDataFromEpochStartData( } epochStartIdentifier := core.EpochStartIdentifier(prevEpoch) - if prevEpoch == 0 { + if prevEpoch == e.genesisEpoch { return lastMetaHash, []byte(epochStartIdentifier), nil } diff --git a/factory/processing/processComponents.go b/factory/processing/processComponents.go index 9b0dcf43ee8..8f116c4b9b6 100644 --- a/factory/processing/processComponents.go +++ b/factory/processing/processComponents.go @@ -162,6 +162,9 @@ type ProcessComponentsFactoryArgs struct { StatusComponents factory.StatusComponentsHolder StatusCoreComponents factory.StatusCoreComponentsHolder TxExecutionOrderHandler common.TxExecutionOrderHandler + + GenesisNonce uint64 + GenesisRound uint64 } type processComponentsFactory struct { @@ -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 @@ -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 } @@ -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) diff --git a/genesis/process/argGenesisBlockCreator.go b/genesis/process/argGenesisBlockCreator.go index e4374b7f6f0..05b8e130a20 100644 --- a/genesis/process/argGenesisBlockCreator.go +++ b/genesis/process/argGenesisBlockCreator.go @@ -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 diff --git a/genesis/process/genesisBlockCreator.go b/genesis/process/genesisBlockCreator.go index 2e9b14d7db3..c4ec16e5871 100644 --- a/genesis/process/genesisBlockCreator.go +++ b/genesis/process/genesisBlockCreator.go @@ -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 { @@ -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 } diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index dcd09ce4b65..663a503423a 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -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 @@ -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 @@ -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, } diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index 17eebfc81d7..a986221c17c 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -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() diff --git a/node/chainSimulator/components/manualRoundHandler.go b/node/chainSimulator/components/manualRoundHandler.go index 3639bf23752..479cf63a1f5 100644 --- a/node/chainSimulator/components/manualRoundHandler.go +++ b/node/chainSimulator/components/manualRoundHandler.go @@ -9,6 +9,7 @@ type manualRoundHandler struct { index int64 genesisTimeStamp int64 roundDuration time.Duration + initialRound int64 } // NewManualRoundHandler returns a manual round handler instance @@ -17,6 +18,7 @@ func NewManualRoundHandler(genesisTimeStamp int64, roundDuration time.Duration, genesisTimeStamp: genesisTimeStamp, roundDuration: roundDuration, index: initialRound, + initialRound: initialRound, } } @@ -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 } diff --git a/node/chainSimulator/components/processComponents.go b/node/chainSimulator/components/processComponents.go index 2fd615f1583..2e990a622a2 100644 --- a/node/chainSimulator/components/processComponents.go +++ b/node/chainSimulator/components/processComponents.go @@ -49,6 +49,9 @@ type ArgsProcessComponentsHolder struct { Config config.Config EconomicsConfig config.EconomicsConfig SystemSCConfig config.SystemSmartContractsConfig + + GenesisNonce uint64 + GenesisRound uint64 } type processComponentsHolder struct { @@ -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 { diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index 8fe8fdaf6b6..43abc6e8076 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -39,6 +39,7 @@ type ArgsTestOnlyProcessingNode struct { SyncedBroadcastNetwork SyncedBroadcastNetworkHandler InitialRound int64 + InitialNonce uint64 GasScheduleFilename string NumShards uint32 ShardIDStr string @@ -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 diff --git a/node/chainSimulator/configs/configs.go b/node/chainSimulator/configs/configs.go index 63aa3adc48b..6c94475af36 100644 --- a/node/chainSimulator/configs/configs.go +++ b/node/chainSimulator/configs/configs.go @@ -47,6 +47,7 @@ type ArgsChainSimulatorConfigs struct { TempDir string MinNodesPerShard uint32 MetaChainMinNodes uint32 + InitialEpoch uint32 RoundsPerEpoch core.OptionalUint64 } @@ -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) diff --git a/node/chainSimulator/process/processor.go b/node/chainSimulator/process/processor.go index bca5b6ac2a1..49029c63083 100644 --- a/node/chainSimulator/process/processor.go +++ b/node/chainSimulator/process/processor.go @@ -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 }