From 892749f1762219543ad525efe7d8faf4ebebea5f Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 18 Jun 2024 14:24:45 +0300 Subject: [PATCH 01/18] add max gas higher factory accepted to economics toml --- cmd/node/config/economics.toml | 6 +++--- config/economicsConfig.go | 1 + config/tomlConfig_test.go | 11 +++++++---- genesis/process/disabled/feeHandler.go | 13 +++++++++---- integrationTests/testProcessorNode.go | 1 + integrationTests/vm/testInitializer.go | 7 ++++--- integrationTests/vm/wasm/utils.go | 1 + .../components/coreComponents_test.go | 1 + process/economics/economicsData.go | 11 +++++++++++ process/economics/economicsData_test.go | 6 ++++++ process/economics/gasConfigHandler.go | 15 +++++++++++++++ process/economics/testEconomicsData.go | 5 +++++ process/errors.go | 3 +++ .../factory/metachain/vmContainerFactory_test.go | 1 + process/interface.go | 10 ++++++++++ process/peer/process_test.go | 1 + process/smartContract/process_test.go | 1 + process/smartContract/processorV2/processV2.go | 10 +++++++--- process/smartContract/processorV2/process_test.go | 11 +++++++---- testscommon/components/configs.go | 1 + testscommon/economicsConfig.go | 1 + .../economicsmocks/economicsDataHandlerStub.go | 9 +++++++++ testscommon/stakingcommon/stakingCommon.go | 1 + 23 files changed, 106 insertions(+), 21 deletions(-) diff --git a/cmd/node/config/economics.toml b/cmd/node/config/economics.toml index f0bac97a055..b29c91978fc 100644 --- a/cmd/node/config/economics.toml +++ b/cmd/node/config/economics.toml @@ -39,9 +39,9 @@ [FeeSettings] GasLimitSettings = [ - {EnableEpoch = 0, MaxGasLimitPerBlock = "1500000000", MaxGasLimitPerMiniBlock = "1500000000", MaxGasLimitPerMetaBlock = "15000000000", MaxGasLimitPerMetaMiniBlock = "15000000000", MaxGasLimitPerTx = "1500000000", MinGasLimit = "50000", ExtraGasLimitGuardedTx = "50000"}, - {EnableEpoch = 1, MaxGasLimitPerBlock = "1500000000", MaxGasLimitPerMiniBlock = "250000000", MaxGasLimitPerMetaBlock = "15000000000", MaxGasLimitPerMetaMiniBlock = "250000000", MaxGasLimitPerTx = "600000000", MinGasLimit = "50000", ExtraGasLimitGuardedTx = "50000"}, - {EnableEpoch = 2, MaxGasLimitPerBlock = "1500000000", MaxGasLimitPerMiniBlock = "250000000", MaxGasLimitPerMetaBlock = "15000000000", MaxGasLimitPerMetaMiniBlock = "250000000", MaxGasLimitPerTx = "600000000", MinGasLimit = "50000", ExtraGasLimitGuardedTx = "50000"}, + {EnableEpoch = 0, MaxGasLimitPerBlock = "1500000000", MaxGasLimitPerMiniBlock = "1500000000", MaxGasLimitPerMetaBlock = "15000000000", MaxGasLimitPerMetaMiniBlock = "15000000000", MaxGasLimitPerTx = "1500000000", MinGasLimit = "50000", ExtraGasLimitGuardedTx = "50000", MaxGasHigherFactorAccepted = "10"}, + {EnableEpoch = 1, MaxGasLimitPerBlock = "1500000000", MaxGasLimitPerMiniBlock = "250000000", MaxGasLimitPerMetaBlock = "15000000000", MaxGasLimitPerMetaMiniBlock = "250000000", MaxGasLimitPerTx = "600000000", MinGasLimit = "50000", ExtraGasLimitGuardedTx = "50000", MaxGasHigherFactorAccepted = "10"}, + {EnableEpoch = 2, MaxGasLimitPerBlock = "1500000000", MaxGasLimitPerMiniBlock = "250000000", MaxGasLimitPerMetaBlock = "15000000000", MaxGasLimitPerMetaMiniBlock = "250000000", MaxGasLimitPerTx = "600000000", MinGasLimit = "50000", ExtraGasLimitGuardedTx = "50000", MaxGasHigherFactorAccepted = "10"}, ] MinGasPrice = "1000000000" #will yield min tx fee of 0.00005 eGLD GasPriceModifier = 0.01 diff --git a/config/economicsConfig.go b/config/economicsConfig.go index 35c67d92469..4d33b87f548 100644 --- a/config/economicsConfig.go +++ b/config/economicsConfig.go @@ -41,6 +41,7 @@ type GasLimitSetting struct { MaxGasLimitPerTx string MinGasLimit string ExtraGasLimitGuardedTx string + MaxGasHigherFactorAccepted string } // FeeSettings will hold economics fee settings diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index 97232f39f41..ab0b5fe4eec 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -271,7 +271,9 @@ func TestTomlEconomicsParser(t *testing.T) { minGasLimit := "18446744073709551615" extraGasLimitGuardedTx := "50000" maxGasPriceSetGuardian := "1234567" + maxGasHigherFactorAccepted := "10" protocolSustainabilityAddress := "erd1932eft30w753xyvme8d49qejgkjc09n5e49w4mwdjtm0neld797su0dlxp" + denomination := 18 cfgEconomicsExpected := EconomicsConfig{ @@ -299,9 +301,10 @@ func TestTomlEconomicsParser(t *testing.T) { FeeSettings: FeeSettings{ GasLimitSettings: []GasLimitSetting{ { - MaxGasLimitPerBlock: maxGasLimitPerBlock, - MinGasLimit: minGasLimit, - ExtraGasLimitGuardedTx: extraGasLimitGuardedTx, + MaxGasLimitPerBlock: maxGasLimitPerBlock, + MinGasLimit: minGasLimit, + ExtraGasLimitGuardedTx: extraGasLimitGuardedTx, + MaxGasHigherFactorAccepted: maxGasHigherFactorAccepted, }, }, MinGasPrice: minGasPrice, @@ -328,7 +331,7 @@ func TestTomlEconomicsParser(t *testing.T) { ProtocolSustainabilityAddress = "` + protocolSustainabilityAddress + `" [FeeSettings] - GasLimitSettings = [{EnableEpoch = 0, MaxGasLimitPerBlock = "` + maxGasLimitPerBlock + `", MaxGasLimitPerMiniBlock = "", MaxGasLimitPerMetaBlock = "", MaxGasLimitPerMetaMiniBlock = "", MaxGasLimitPerTx = "", MinGasLimit = "` + minGasLimit + `", ExtraGasLimitGuardedTx = "` + extraGasLimitGuardedTx + `"}] + GasLimitSettings = [{EnableEpoch = 0, MaxGasLimitPerBlock = "` + maxGasLimitPerBlock + `", MaxGasLimitPerMiniBlock = "", MaxGasLimitPerMetaBlock = "", MaxGasLimitPerMetaMiniBlock = "", MaxGasLimitPerTx = "", MinGasLimit = "` + minGasLimit + `", ExtraGasLimitGuardedTx = "` + extraGasLimitGuardedTx + `", MaxGasHigherFactorAccepted = "` + maxGasHigherFactorAccepted + `"}] MinGasPrice = "` + minGasPrice + `" MaxGasPriceSetGuardian = "` + maxGasPriceSetGuardian + `" ` diff --git a/genesis/process/disabled/feeHandler.go b/genesis/process/disabled/feeHandler.go index 1fc34bbc2b5..df171e3d37c 100644 --- a/genesis/process/disabled/feeHandler.go +++ b/genesis/process/disabled/feeHandler.go @@ -72,6 +72,11 @@ func (fh *FeeHandler) MaxGasLimitPerMiniBlockForSafeCrossShard() uint64 { return math.MaxUint64 } +// MaxGasHigherFactorAccepted returns 10 +func (fh *FeeHandler) MaxGasHigherFactorAccepted() uint64 { + return 10 +} + // MaxGasLimitPerTx returns max uint64 func (fh *FeeHandler) MaxGasLimitPerTx() uint64 { return math.MaxUint64 @@ -164,22 +169,22 @@ func (fh *FeeHandler) ComputeTxFeeBasedOnGasUsed(_ data.TransactionWithFeeHandle } // ComputeTxFeeInEpoch returns 0 -func (fh *FeeHandler) ComputeTxFeeInEpoch(tx data.TransactionWithFeeHandler, epoch uint32) *big.Int { +func (fh *FeeHandler) ComputeTxFeeInEpoch(_ data.TransactionWithFeeHandler, _ uint32) *big.Int { return big.NewInt(0) } // ComputeGasLimitInEpoch returns 0 -func (fh *FeeHandler) ComputeGasLimitInEpoch(tx data.TransactionWithFeeHandler, epoch uint32) uint64 { +func (fh *FeeHandler) ComputeGasLimitInEpoch(_ data.TransactionWithFeeHandler, _ uint32) uint64 { return 0 } // ComputeGasUsedAndFeeBasedOnRefundValueInEpoch returns 0 -func (fh *FeeHandler) ComputeGasUsedAndFeeBasedOnRefundValueInEpoch(tx data.TransactionWithFeeHandler, refundValue *big.Int, epoch uint32) (uint64, *big.Int) { +func (fh *FeeHandler) ComputeGasUsedAndFeeBasedOnRefundValueInEpoch(_ data.TransactionWithFeeHandler, _ *big.Int, _ uint32) (uint64, *big.Int) { return 0, big.NewInt(0) } // ComputeTxFeeBasedOnGasUsedInEpoch returns 0 -func (fh *FeeHandler) ComputeTxFeeBasedOnGasUsedInEpoch(tx data.TransactionWithFeeHandler, gasUsed uint64, epoch uint32) *big.Int { +func (fh *FeeHandler) ComputeTxFeeBasedOnGasUsedInEpoch(_ data.TransactionWithFeeHandler, _ uint64, _ uint32) *big.Int { return big.NewInt(0) } diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index a7468de8485..cdfcd6f903f 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -1151,6 +1151,7 @@ func createDefaultEconomicsConfig() *config.EconomicsConfig { MaxGasLimitPerTx: maxGasLimitPerBlock, MinGasLimit: minGasLimit, ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, }, MinGasPrice: minGasPrice, diff --git a/integrationTests/vm/testInitializer.go b/integrationTests/vm/testInitializer.go index 4ffd57197ca..f1f14abbdda 100644 --- a/integrationTests/vm/testInitializer.go +++ b/integrationTests/vm/testInitializer.go @@ -126,7 +126,7 @@ type VMTestContext struct { TxFeeHandler process.TransactionFeeHandler ShardCoordinator sharding.Coordinator ScForwarder process.IntermediateTransactionHandler - EconomicsData process.EconomicsDataHandler + EconomicsData process.CompleteEconomicsDataHandler Marshalizer marshal.Marshalizer GasSchedule core.GasScheduleNotifier VMConfiguration *config.VirtualMachineConfig @@ -317,7 +317,7 @@ func CreateAccount(accnts state.AccountsAdapter, pubKey []byte, nonce uint64, ba return hashCreated, nil } -func createEconomicsData(enableEpochsConfig config.EnableEpochs) (process.EconomicsDataHandler, error) { +func createEconomicsData(enableEpochsConfig config.EnableEpochs) (process.CompleteEconomicsDataHandler, error) { maxGasLimitPerBlock := strconv.FormatUint(math.MaxUint64, 10) minGasPrice := strconv.FormatUint(1, 10) minGasLimit := strconv.FormatUint(1, 10) @@ -359,6 +359,7 @@ func createEconomicsData(enableEpochsConfig config.EnableEpochs) (process.Econom MaxGasLimitPerTx: maxGasLimitPerBlock, MinGasLimit: minGasLimit, ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, }, MinGasPrice: minGasPrice, @@ -806,7 +807,7 @@ type ResultsCreateTxProcessor struct { TxProc process.TransactionProcessor SCProc scrCommon.TestSmartContractProcessor IntermediateTxProc process.IntermediateTransactionHandler - EconomicsHandler process.EconomicsDataHandler + EconomicsHandler process.CompleteEconomicsDataHandler CostHandler external.TransactionEvaluator TxLogProc process.TransactionLogProcessor } diff --git a/integrationTests/vm/wasm/utils.go b/integrationTests/vm/wasm/utils.go index bfe7b4b7ca9..61402910679 100644 --- a/integrationTests/vm/wasm/utils.go +++ b/integrationTests/vm/wasm/utils.go @@ -242,6 +242,7 @@ func (context *TestContext) initFeeHandlers() { MaxGasLimitPerTx: maxGasLimitPerBlock, MinGasLimit: minGasLimit, ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, }, MinGasPrice: minGasPrice, diff --git a/node/chainSimulator/components/coreComponents_test.go b/node/chainSimulator/components/coreComponents_test.go index f8fc663fa64..3b250384781 100644 --- a/node/chainSimulator/components/coreComponents_test.go +++ b/node/chainSimulator/components/coreComponents_test.go @@ -73,6 +73,7 @@ func createArgsCoreComponentsHolder() ArgsCoreComponentsHolder { MaxGasLimitPerTx: "10000000000", MinGasLimit: "10", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, }, GasPriceModifier: 0.01, diff --git a/process/economics/economicsData.go b/process/economics/economicsData.go index 5b7ce045237..ed8a7a5aa99 100644 --- a/process/economics/economicsData.go +++ b/process/economics/economicsData.go @@ -400,6 +400,17 @@ func (ed *economicsData) MaxGasLimitPerBlockForSafeCrossShard() uint64 { return ed.MaxGasLimitPerBlockForSafeCrossShardInEpoch(currentEpoch) } +// MaxGasHigherFactorAccepted returns maximum gas higher factor accepted +func (ed *economicsData) MaxGasHigherFactorAccepted() uint64 { + currentEpoch := ed.enableEpochsHandler.GetCurrentEpoch() + return ed.MaxGasHigherFactorAcceptedInEpoch(currentEpoch) +} + +// MaxGasHigherFactorAcceptedInEpoch returns maximum gas higher factor accepted for epoch +func (ed *economicsData) MaxGasHigherFactorAcceptedInEpoch(epoch uint32) uint64 { + return ed.getGasHigherFactorAccepted(epoch) +} + // MaxGasLimitPerBlockForSafeCrossShardInEpoch returns maximum gas limit per block for safe cross shard in a specific epoch func (ed *economicsData) MaxGasLimitPerBlockForSafeCrossShardInEpoch(epoch uint32) uint64 { return ed.getMaxGasLimitPerBlockForSafeCrossShard(epoch) diff --git a/process/economics/economicsData_test.go b/process/economics/economicsData_test.go index 1f2c913a826..f144158d87b 100644 --- a/process/economics/economicsData_test.go +++ b/process/economics/economicsData_test.go @@ -64,6 +64,7 @@ func feeSettingsDummy(gasModifier float64) config.FeeSettings { MaxGasLimitPerTx: "100000", MinGasLimit: "500", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, }, MinGasPrice: "18446744073709551615", @@ -84,6 +85,7 @@ func feeSettingsReal() config.FeeSettings { MaxGasLimitPerTx: "1500000000", MinGasLimit: "50000", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, }, MinGasPrice: "1000000000", @@ -716,6 +718,7 @@ func TestEconomicsData_ConfirmedGasLimitSettingsChangeOrderedConfigs(t *testing. MaxGasLimitPerTx: "1500000000", MinGasLimit: "50000", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, { EnableEpoch: 2, @@ -726,6 +729,7 @@ func TestEconomicsData_ConfirmedGasLimitSettingsChangeOrderedConfigs(t *testing. MaxGasLimitPerTx: "500000000", MinGasLimit: "50000", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, } @@ -800,6 +804,7 @@ func TestEconomicsData_ConfirmedGasLimitSettingsChangeUnOrderedConfigs(t *testin MaxGasLimitPerTx: "500000000", MinGasLimit: "50000", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, { EnableEpoch: 0, @@ -810,6 +815,7 @@ func TestEconomicsData_ConfirmedGasLimitSettingsChangeUnOrderedConfigs(t *testin MaxGasLimitPerTx: "1500000000", MinGasLimit: "50000", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, } diff --git a/process/economics/gasConfigHandler.go b/process/economics/gasConfigHandler.go index 02fcc3cece6..2955160b1c8 100644 --- a/process/economics/gasConfigHandler.go +++ b/process/economics/gasConfigHandler.go @@ -26,6 +26,7 @@ type gasConfig struct { maxGasLimitPerTx uint64 minGasLimit uint64 extraGasLimitGuardedTx uint64 + maxGasHigherFactorAccepted uint64 } type gasConfigHandler struct { @@ -113,6 +114,12 @@ func (handler *gasConfigHandler) getMaxGasLimitPerMiniBlock(epoch uint32) uint64 return gc.maxGasLimitPerMiniBlock } +// getMaxGasLimitPerMiniBlock returns max gas limit per mini block in a specific epoch +func (handler *gasConfigHandler) getGasHigherFactorAccepted(epoch uint32) uint64 { + gc := handler.getGasConfigForEpoch(epoch) + return gc.maxGasHigherFactorAccepted +} + // getMaxGasLimitPerBlockForSafeCrossShard returns maximum gas limit per block for safe cross shard in a specific epoch func (handler *gasConfigHandler) getMaxGasLimitPerBlockForSafeCrossShard(epoch uint32) uint64 { gc := handler.getGasConfigForEpoch(epoch) @@ -225,6 +232,11 @@ func checkAndParseGasLimitSettings(gasLimitSetting config.GasLimitSetting) (*gas return nil, fmt.Errorf("%w for epoch %d", process.ErrInvalidExtraGasLimitGuardedTx, gasLimitSetting.EnableEpoch) } + gc.maxGasHigherFactorAccepted, err = strconv.ParseUint(gasLimitSetting.MaxGasHigherFactorAccepted, conversionBase, bitConversionSize) + if err != nil { + return nil, fmt.Errorf("%w for epoch %d", process.ErrInvalidMaxGasHigherFactorAccepted, gasLimitSetting.EnableEpoch) + } + if gc.maxGasLimitPerBlock < gc.minGasLimit { return nil, fmt.Errorf("%w: maxGasLimitPerBlock = %d minGasLimit = %d in epoch %d", process.ErrInvalidMaxGasLimitPerBlock, gc.maxGasLimitPerBlock, gc.minGasLimit, gasLimitSetting.EnableEpoch) } @@ -240,6 +252,9 @@ func checkAndParseGasLimitSettings(gasLimitSetting config.GasLimitSetting) (*gas if gc.maxGasLimitPerTx < gc.minGasLimit { return nil, fmt.Errorf("%w: maxGasLimitPerTx = %d minGasLimit = %d in epoch %d", process.ErrInvalidMaxGasLimitPerTx, gc.maxGasLimitPerTx, gc.minGasLimit, gasLimitSetting.EnableEpoch) } + if gc.maxGasHigherFactorAccepted < 1 { + return nil, fmt.Errorf("%w for epoch %d, it is set to 0", process.ErrInvalidMaxGasHigherFactorAccepted, gasLimitSetting.EnableEpoch) + } return gc, nil } diff --git a/process/economics/testEconomicsData.go b/process/economics/testEconomicsData.go index 7e60812d1df..556cedb3ef6 100644 --- a/process/economics/testEconomicsData.go +++ b/process/economics/testEconomicsData.go @@ -68,6 +68,11 @@ func (ted *TestEconomicsData) SetMaxInflationRate(maximumInflation float64) { ted.yearSettings[0].MaximumInflation = maximumInflation } +// MaxGasHigherFactorAccepted returns 10 +func (ted *TestEconomicsData) MaxGasHigherFactorAccepted() uint64 { + return 10 +} + // SetStatusHandler returns nil func (ted *TestEconomicsData) SetStatusHandler(_ core.AppStatusHandler) error { return nil diff --git a/process/errors.go b/process/errors.go index 83e8095dcb3..8fd231731bf 100644 --- a/process/errors.go +++ b/process/errors.go @@ -534,6 +534,9 @@ var ErrInvalidExtraGasLimitGuardedTx = errors.New("invalid extra gas limit for g // ErrInvalidMaxGasPriceSetGuardian signals that an invalid maximum gas price has been provided in the config file var ErrInvalidMaxGasPriceSetGuardian = errors.New("invalid maximum gas price for set guardian") +// ErrInvalidMaxGasHigherFactorAccepted signals that an invalid gas factor has been provided in the config file +var ErrInvalidMaxGasHigherFactorAccepted = errors.New("invalid gas higher factor accepted") + // ErrGuardianSignatureNotExpected signals that the guardian signature is not expected var ErrGuardianSignatureNotExpected = errors.New("guardian signature not expected") diff --git a/process/factory/metachain/vmContainerFactory_test.go b/process/factory/metachain/vmContainerFactory_test.go index ff542213ef4..95d0fc05610 100644 --- a/process/factory/metachain/vmContainerFactory_test.go +++ b/process/factory/metachain/vmContainerFactory_test.go @@ -312,6 +312,7 @@ func TestVmContainerFactory_Create(t *testing.T) { MaxGasLimitPerTx: "10000000000", MinGasLimit: "10", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, }, MinGasPrice: "10", diff --git a/process/interface.go b/process/interface.go index 69b1b139e89..26094127611 100644 --- a/process/interface.go +++ b/process/interface.go @@ -716,6 +716,7 @@ type TxGasHandler interface { // FeeHandler is able to perform some economics calculation on a provided transaction type FeeHandler interface { feeHandler + MaxGasHigherFactorAccepted() uint64 IsInterfaceNil() bool } @@ -727,6 +728,15 @@ type EconomicsDataHandler interface { IsInterfaceNil() bool } +// CompleteEconomicsDataHandler provides some economics related computation and read access to economics data +type CompleteEconomicsDataHandler interface { + rewardsHandler + feeHandler + MaxGasHigherFactorAccepted() uint64 + SetStatusHandler(statusHandler core.AppStatusHandler) error + IsInterfaceNil() bool +} + // SmartContractToProtocolHandler is able to translate data from smart contract state into protocol changes type SmartContractToProtocolHandler interface { UpdateProtocol(body *block.Body, nonce uint64) error diff --git a/process/peer/process_test.go b/process/peer/process_test.go index d4c85a5601f..3df1a8f5505 100644 --- a/process/peer/process_test.go +++ b/process/peer/process_test.go @@ -94,6 +94,7 @@ func createMockArguments() peer.ArgValidatorStatisticsProcessor { MaxGasLimitPerTx: "10000000", MinGasLimit: "10", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, }, MinGasPrice: "10", diff --git a/process/smartContract/process_test.go b/process/smartContract/process_test.go index c53c7ef83c9..1bbd2c2b404 100644 --- a/process/smartContract/process_test.go +++ b/process/smartContract/process_test.go @@ -4231,6 +4231,7 @@ func createRealEconomicsDataArgs() *economics.ArgsNewEconomicsData { MaxGasLimitPerTx: "1500000000", MinGasLimit: "50000", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, }, GasPerDataByte: "1500", diff --git a/process/smartContract/processorV2/processV2.go b/process/smartContract/processorV2/processV2.go index 126433c6dee..46634a936c2 100644 --- a/process/smartContract/processorV2/processV2.go +++ b/process/smartContract/processorV2/processV2.go @@ -2093,7 +2093,7 @@ func (sc *scProcessor) penalizeUserIfNeeded( return } - isTooMuchProvided := isTooMuchGasProvided(gasProvidedForProcessing, vmOutput.GasRemaining) + isTooMuchProvided := isTooMuchGasProvided(gasProvidedForProcessing, vmOutput.GasRemaining, sc.economicsFee) if !isTooMuchProvided { return } @@ -2122,13 +2122,17 @@ func (sc *scProcessor) penalizeUserIfNeeded( vmOutput.GasRemaining = 0 } -func isTooMuchGasProvided(gasProvided uint64, gasRemained uint64) bool { +func isTooMuchGasProvided( + gasProvided uint64, + gasRemained uint64, + economicsFee process.FeeHandler, +) bool { if gasProvided <= gasRemained { return false } gasUsed := gasProvided - gasRemained - return gasProvided > gasUsed*process.MaxGasFeeHigherFactorAccepted + return gasProvided > gasUsed*economicsFee.MaxGasHigherFactorAccepted() } func (sc *scProcessor) createSCRsWhenError( diff --git a/process/smartContract/processorV2/process_test.go b/process/smartContract/processorV2/process_test.go index eedea17f1ad..fdc2342ec56 100644 --- a/process/smartContract/processorV2/process_test.go +++ b/process/smartContract/processorV2/process_test.go @@ -3437,16 +3437,18 @@ func TestScProcessor_isTooMuchGasProvidedShouldWork(t *testing.T) { gasProvided := uint64(100) maxGasToRemain := gasProvided - (gasProvided / process.MaxGasFeeHigherFactorAccepted) - isTooMuchGas := isTooMuchGasProvided(gasProvided, gasProvided) + economicsHandler := &economicsmocks.EconomicsHandlerStub{} + + isTooMuchGas := isTooMuchGasProvided(gasProvided, gasProvided, economicsHandler) assert.False(t, isTooMuchGas) - isTooMuchGas = isTooMuchGasProvided(gasProvided, maxGasToRemain-1) + isTooMuchGas = isTooMuchGasProvided(gasProvided, maxGasToRemain-1, economicsHandler) assert.False(t, isTooMuchGas) - isTooMuchGas = isTooMuchGasProvided(gasProvided, maxGasToRemain) + isTooMuchGas = isTooMuchGasProvided(gasProvided, maxGasToRemain, economicsHandler) assert.False(t, isTooMuchGas) - isTooMuchGas = isTooMuchGasProvided(gasProvided, maxGasToRemain+1) + isTooMuchGas = isTooMuchGasProvided(gasProvided, maxGasToRemain+1, economicsHandler) assert.True(t, isTooMuchGas) } @@ -4168,6 +4170,7 @@ func createRealEconomicsDataArgs() *economics.ArgsNewEconomicsData { MaxGasLimitPerTx: "1500000000", MinGasLimit: "50000", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, }, GasPerDataByte: "1500", diff --git a/testscommon/components/configs.go b/testscommon/components/configs.go index f86a5ae59cc..12598af042c 100644 --- a/testscommon/components/configs.go +++ b/testscommon/components/configs.go @@ -249,6 +249,7 @@ func CreateDummyEconomicsConfig() config.EconomicsConfig { MaxGasLimitPerTx: "1500000000", MinGasLimit: "50000", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, }, MinGasPrice: "1000000000", diff --git a/testscommon/economicsConfig.go b/testscommon/economicsConfig.go index 59ec0088240..aae732d7446 100644 --- a/testscommon/economicsConfig.go +++ b/testscommon/economicsConfig.go @@ -39,6 +39,7 @@ func GetEconomicsConfig() config.EconomicsConfig { MaxGasLimitPerTx: "600000000", MinGasLimit: "50000", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, }, MinGasPrice: "1000000000", diff --git a/testscommon/economicsmocks/economicsDataHandlerStub.go b/testscommon/economicsmocks/economicsDataHandlerStub.go index b6cf36f4491..49c9545d529 100644 --- a/testscommon/economicsmocks/economicsDataHandlerStub.go +++ b/testscommon/economicsmocks/economicsDataHandlerStub.go @@ -30,6 +30,7 @@ type EconomicsHandlerStub struct { MinGasLimitCalled func() uint64 ExtraGasLimitGuardedTxCalled func() uint64 MaxGasPriceSetGuardianCalled func() uint64 + MaxGasHigherFactorAcceptedCalled func() uint64 GenesisTotalSupplyCalled func() *big.Int ComputeFeeForProcessingCalled func(tx data.TransactionWithFeeHandler, gasToUse uint64) *big.Int RewardsTopUpGradientPointCalled func() *big.Int @@ -201,6 +202,14 @@ func (e *EconomicsHandlerStub) MaxGasLimitPerMiniBlockForSafeCrossShard() uint64 return 1000000 } +// MaxGasHigherFactorAccepted - +func (e *EconomicsHandlerStub) MaxGasHigherFactorAccepted() uint64 { + if e.MaxGasHigherFactorAcceptedCalled != nil { + return e.MaxGasHigherFactorAcceptedCalled() + } + return 10 +} + // MaxGasLimitPerTx - func (e *EconomicsHandlerStub) MaxGasLimitPerTx() uint64 { if e.MaxGasLimitPerTxCalled != nil { diff --git a/testscommon/stakingcommon/stakingCommon.go b/testscommon/stakingcommon/stakingCommon.go index 1af9b441b9c..bdad4a47bde 100644 --- a/testscommon/stakingcommon/stakingCommon.go +++ b/testscommon/stakingcommon/stakingCommon.go @@ -266,6 +266,7 @@ func CreateEconomicsData() process.EconomicsDataHandler { MaxGasLimitPerTx: maxGasLimitPerBlock, MinGasLimit: minGasLimit, ExtraGasLimitGuardedTx: maxGasLimitPerBlock, + MaxGasHigherFactorAccepted: "10", }, }, MinGasPrice: minGasPrice, From 9382c6cdf244bca37642453d37b3278b1a111af9 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 18 Jun 2024 14:47:24 +0300 Subject: [PATCH 02/18] adding tests --- process/economics/economicsData_test.go | 30 +++++++++++++++++++ .../smartContract/processorV2/process_test.go | 25 ++++++++++++++-- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/process/economics/economicsData_test.go b/process/economics/economicsData_test.go index f144158d87b..f97dec2104e 100644 --- a/process/economics/economicsData_test.go +++ b/process/economics/economicsData_test.go @@ -391,6 +391,36 @@ func TestNewEconomicsData_InvalidExtraGasLimitGuardedTxShouldErr(t *testing.T) { } } +func TestNewEconomicsData_InvalidMaxGasHigherFactorAccepted(t *testing.T) { + t.Parallel() + + args := createArgsForEconomicsData(1) + badExtraMaxGasHigherFactorAccepted := []string{ + "-1", + "-100000000000000000000", + "badValue", + "", + "#########", + "11112S", + "1111O0000", + "10ERD", + } + + for _, gasLimitGuardedTx := range badExtraMaxGasHigherFactorAccepted { + args.Economics.FeeSettings.GasLimitSettings[0].MaxGasHigherFactorAccepted = gasLimitGuardedTx + _, err := economics.NewEconomicsData(args) + assert.True(t, errors.Is(err, process.ErrInvalidMaxGasHigherFactorAccepted)) + } + + args.Economics.FeeSettings.GasLimitSettings[0].MaxGasHigherFactorAccepted = "0" + _, err := economics.NewEconomicsData(args) + assert.True(t, errors.Is(err, process.ErrInvalidMaxGasHigherFactorAccepted)) + + args.Economics.FeeSettings.GasLimitSettings[0].MaxGasHigherFactorAccepted = "2" + _, err = economics.NewEconomicsData(args) + assert.Nil(t, err) +} + func TestNewEconomicsData_MaxGasLimitPerBlockLowerThanMinGasLimitShouldErr(t *testing.T) { t.Parallel() diff --git a/process/smartContract/processorV2/process_test.go b/process/smartContract/processorV2/process_test.go index fdc2342ec56..b2931e4e941 100644 --- a/process/smartContract/processorV2/process_test.go +++ b/process/smartContract/processorV2/process_test.go @@ -3434,11 +3434,11 @@ func TestScProcessor_penalizeUserIfNeededShouldWork(t *testing.T) { func TestScProcessor_isTooMuchGasProvidedShouldWork(t *testing.T) { t.Parallel() - gasProvided := uint64(100) - maxGasToRemain := gasProvided - (gasProvided / process.MaxGasFeeHigherFactorAccepted) - economicsHandler := &economicsmocks.EconomicsHandlerStub{} + gasProvided := uint64(100) + maxGasToRemain := gasProvided - (gasProvided / economicsHandler.MaxGasHigherFactorAccepted()) + isTooMuchGas := isTooMuchGasProvided(gasProvided, gasProvided, economicsHandler) assert.False(t, isTooMuchGas) @@ -3450,6 +3450,25 @@ func TestScProcessor_isTooMuchGasProvidedShouldWork(t *testing.T) { isTooMuchGas = isTooMuchGasProvided(gasProvided, maxGasToRemain+1, economicsHandler) assert.True(t, isTooMuchGas) + + economicsHandler.MaxGasHigherFactorAcceptedCalled = func() uint64 { + return 2 + } + + maxGasToRemain = gasProvided - (gasProvided / economicsHandler.MaxGasHigherFactorAccepted()) + + isTooMuchGas = isTooMuchGasProvided(gasProvided, gasProvided, economicsHandler) + assert.False(t, isTooMuchGas) + + isTooMuchGas = isTooMuchGasProvided(gasProvided, maxGasToRemain-1, economicsHandler) + assert.False(t, isTooMuchGas) + + isTooMuchGas = isTooMuchGasProvided(gasProvided, maxGasToRemain, economicsHandler) + assert.False(t, isTooMuchGas) + + isTooMuchGas = isTooMuchGasProvided(gasProvided, maxGasToRemain+1, economicsHandler) + assert.True(t, isTooMuchGas) + } func TestSCProcessor_createSCRWhenError(t *testing.T) { From ec0edab776ff5126fed5b12d9798b7d80d3ea3b0 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 18 Jun 2024 15:11:49 +0300 Subject: [PATCH 03/18] adding tests --- go.sum | 6 ------ integrationTests/vm/testInitializer.go | 6 +++--- process/interface.go | 11 +---------- testscommon/economicsmocks/economicsHandlerMock.go | 9 +++++++++ 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/go.sum b/go.sum index a98f8ba06c2..990794e0d27 100644 --- a/go.sum +++ b/go.sum @@ -129,7 +129,6 @@ github.com/gizak/termui/v3 v3.1.0 h1:ZZmVDgwHl7gR7elfKf1xc4IudXZ5qqfDh4wExk4Iajc github.com/gizak/termui/v3 v3.1.0/go.mod h1:bXQEBkJpzxUAKf0+xq9MSWAvWZlE7c+aidmyFlkYTrY= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= -github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -262,7 +261,6 @@ github.com/jbenet/goprocess v0.1.4/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZl github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= -github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= @@ -270,7 +268,6 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19/go.mod h1:hY+WOq6m2FpbvyrI93sMaypsttvaIL5nhVR92dTMUcQ= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= @@ -402,8 +399,6 @@ github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00/go.mod h1:pnIIfWopbDMQ1EW5Ddc6KDMqv8Qtx+hxbH9rorHpCyo= github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f h1:yd/G8iPBGOEAwbaS8zndJpO6bQk7Tk72ZhmlqRasThI= github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f/go.mod h1:E6nfj9EQzGxWDGM3Dn6eZWRC3qFy1G8IqOsYsBOcgWw= -github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240509103544-247ce5639c7a h1:7M+jXVlnl43zd2NuimL1KnAVAdpUr/QoHqG0TUKoyaM= -github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240509103544-247ce5639c7a/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo= github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240529093845-2a375eef5cc1 h1:C6NQcbfusGkhWP2FNvzafX2w7lKGSzZIius/fM5Gm3c= github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240529093845-2a375eef5cc1/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo= github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1 h1:5/h1i7Xd/JH9CiO3ZqvzAjdze+mAbar5sWkh2UqfLgI= @@ -418,7 +413,6 @@ github.com/multiversx/mx-components-big-int v1.0.0 h1:Wkr8lSzK2nDqixOrrBa47VNuqd github.com/multiversx/mx-components-big-int v1.0.0/go.mod h1:maIEMgHlNE2u78JaDD0oLzri+ShgU4okHfzP3LWGdQM= github.com/multiversx/protobuf v1.3.2 h1:RaNkxvGTGbA0lMcnHAN24qE1G1i+Xs5yHA6MDvQ4mSM= github.com/multiversx/protobuf v1.3.2/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= -github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo= github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM= github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d h1:x3S6kxmy49zXVVyhcnrFqxvNVCBPb2KZ9hV2RBdS840= diff --git a/integrationTests/vm/testInitializer.go b/integrationTests/vm/testInitializer.go index f1f14abbdda..cafdda755a2 100644 --- a/integrationTests/vm/testInitializer.go +++ b/integrationTests/vm/testInitializer.go @@ -126,7 +126,7 @@ type VMTestContext struct { TxFeeHandler process.TransactionFeeHandler ShardCoordinator sharding.Coordinator ScForwarder process.IntermediateTransactionHandler - EconomicsData process.CompleteEconomicsDataHandler + EconomicsData process.EconomicsDataHandler Marshalizer marshal.Marshalizer GasSchedule core.GasScheduleNotifier VMConfiguration *config.VirtualMachineConfig @@ -317,7 +317,7 @@ func CreateAccount(accnts state.AccountsAdapter, pubKey []byte, nonce uint64, ba return hashCreated, nil } -func createEconomicsData(enableEpochsConfig config.EnableEpochs) (process.CompleteEconomicsDataHandler, error) { +func createEconomicsData(enableEpochsConfig config.EnableEpochs) (process.EconomicsDataHandler, error) { maxGasLimitPerBlock := strconv.FormatUint(math.MaxUint64, 10) minGasPrice := strconv.FormatUint(1, 10) minGasLimit := strconv.FormatUint(1, 10) @@ -807,7 +807,7 @@ type ResultsCreateTxProcessor struct { TxProc process.TransactionProcessor SCProc scrCommon.TestSmartContractProcessor IntermediateTxProc process.IntermediateTransactionHandler - EconomicsHandler process.CompleteEconomicsDataHandler + EconomicsHandler process.EconomicsDataHandler CostHandler external.TransactionEvaluator TxLogProc process.TransactionLogProcessor } diff --git a/process/interface.go b/process/interface.go index 26094127611..911ab25105c 100644 --- a/process/interface.go +++ b/process/interface.go @@ -698,6 +698,7 @@ type feeHandler interface { ComputeGasLimitInEpoch(tx data.TransactionWithFeeHandler, epoch uint32) uint64 ComputeGasUsedAndFeeBasedOnRefundValueInEpoch(tx data.TransactionWithFeeHandler, refundValue *big.Int, epoch uint32) (uint64, *big.Int) ComputeTxFeeBasedOnGasUsedInEpoch(tx data.TransactionWithFeeHandler, gasUsed uint64, epoch uint32) *big.Int + MaxGasHigherFactorAccepted() uint64 } // TxGasHandler handles a transaction gas and gas cost @@ -716,7 +717,6 @@ type TxGasHandler interface { // FeeHandler is able to perform some economics calculation on a provided transaction type FeeHandler interface { feeHandler - MaxGasHigherFactorAccepted() uint64 IsInterfaceNil() bool } @@ -728,15 +728,6 @@ type EconomicsDataHandler interface { IsInterfaceNil() bool } -// CompleteEconomicsDataHandler provides some economics related computation and read access to economics data -type CompleteEconomicsDataHandler interface { - rewardsHandler - feeHandler - MaxGasHigherFactorAccepted() uint64 - SetStatusHandler(statusHandler core.AppStatusHandler) error - IsInterfaceNil() bool -} - // SmartContractToProtocolHandler is able to translate data from smart contract state into protocol changes type SmartContractToProtocolHandler interface { UpdateProtocol(body *block.Body, nonce uint64) error diff --git a/testscommon/economicsmocks/economicsHandlerMock.go b/testscommon/economicsmocks/economicsHandlerMock.go index 88a54c90e72..0e8f0001b06 100644 --- a/testscommon/economicsmocks/economicsHandlerMock.go +++ b/testscommon/economicsmocks/economicsHandlerMock.go @@ -30,6 +30,7 @@ type EconomicsHandlerMock struct { DeveloperPercentageCalled func() float64 MinGasPriceCalled func() uint64 GasPerDataByteCalled func() uint64 + MaxGasHigherFactorAcceptedCalled func() uint64 RewardsTopUpGradientPointCalled func() *big.Int RewardsTopUpFactorCalled func() float64 ComputeFeeForProcessingCalled func(tx data.TransactionWithFeeHandler, gasToUse uint64) *big.Int @@ -335,6 +336,14 @@ func (ehm *EconomicsHandlerMock) ComputeTxFeeBasedOnGasUsedInEpoch(tx data.Trans return nil } +// MaxGasHigherFactorAccepted - +func (ehm *EconomicsHandlerMock) MaxGasHigherFactorAccepted() uint64 { + if ehm.MaxGasHigherFactorAcceptedCalled != nil { + return ehm.MaxGasHigherFactorAcceptedCalled() + } + return 10 +} + // IsInterfaceNil returns true if there is no value under the interface func (ehm *EconomicsHandlerMock) IsInterfaceNil() bool { return ehm == nil From e6f889452b2018a93800cc2612476f4b5a0a78af Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 18 Jun 2024 15:46:38 +0300 Subject: [PATCH 04/18] adding tests --- process/economics/export_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/process/economics/export_test.go b/process/economics/export_test.go index f466b60301e..fac481d4086 100644 --- a/process/economics/export_test.go +++ b/process/economics/export_test.go @@ -37,6 +37,7 @@ func (ed *economicsData) GetGasLimitSetting(epoch uint32) *config.GasLimitSettin gasLimitSetting.MaxGasLimitPerTx = strconv.FormatUint(cfg.maxGasLimitPerTx, 10) gasLimitSetting.MinGasLimit = strconv.FormatUint(cfg.minGasLimit, 10) gasLimitSetting.ExtraGasLimitGuardedTx = strconv.FormatUint(cfg.extraGasLimitGuardedTx, 10) + gasLimitSetting.MaxGasHigherFactorAccepted = strconv.FormatUint(cfg.maxGasHigherFactorAccepted, 10) return gasLimitSetting } From 716d67dcc01be05e097cf980c69821257ab7eb7d Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 20 Jun 2024 12:02:50 +0300 Subject: [PATCH 05/18] activate in new epoch --- cmd/node/config/economics.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/node/config/economics.toml b/cmd/node/config/economics.toml index b29c91978fc..f34d9ed57f3 100644 --- a/cmd/node/config/economics.toml +++ b/cmd/node/config/economics.toml @@ -42,6 +42,7 @@ {EnableEpoch = 0, MaxGasLimitPerBlock = "1500000000", MaxGasLimitPerMiniBlock = "1500000000", MaxGasLimitPerMetaBlock = "15000000000", MaxGasLimitPerMetaMiniBlock = "15000000000", MaxGasLimitPerTx = "1500000000", MinGasLimit = "50000", ExtraGasLimitGuardedTx = "50000", MaxGasHigherFactorAccepted = "10"}, {EnableEpoch = 1, MaxGasLimitPerBlock = "1500000000", MaxGasLimitPerMiniBlock = "250000000", MaxGasLimitPerMetaBlock = "15000000000", MaxGasLimitPerMetaMiniBlock = "250000000", MaxGasLimitPerTx = "600000000", MinGasLimit = "50000", ExtraGasLimitGuardedTx = "50000", MaxGasHigherFactorAccepted = "10"}, {EnableEpoch = 2, MaxGasLimitPerBlock = "1500000000", MaxGasLimitPerMiniBlock = "250000000", MaxGasLimitPerMetaBlock = "15000000000", MaxGasLimitPerMetaMiniBlock = "250000000", MaxGasLimitPerTx = "600000000", MinGasLimit = "50000", ExtraGasLimitGuardedTx = "50000", MaxGasHigherFactorAccepted = "10"}, + {EnableEpoch = 3, MaxGasLimitPerBlock = "1500000000", MaxGasLimitPerMiniBlock = "250000000", MaxGasLimitPerMetaBlock = "15000000000", MaxGasLimitPerMetaMiniBlock = "250000000", MaxGasLimitPerTx = "600000000", MinGasLimit = "50000", ExtraGasLimitGuardedTx = "50000", MaxGasHigherFactorAccepted = "2"}, ] MinGasPrice = "1000000000" #will yield min tx fee of 0.00005 eGLD GasPriceModifier = 0.01 From edfc0a076a3b9eee63be21289710a9076d1a5633 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Mon, 12 Aug 2024 16:57:13 +0300 Subject: [PATCH 06/18] fix linter issue --- integrationTests/chainSimulator/vm/esdtImprovements_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index d8e5c065a45..438660658f3 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -2343,7 +2343,6 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { []byte(core.ESDTRoleNFTUpdate), } tx = setSpecialRoleTx(nonce, addrs[1].Bytes, addrs[0].Bytes, tokenID, roles) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) From e67616d1a4e8fa970787404bde4379f12b91d9bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Thu, 3 Oct 2024 17:36:08 +0300 Subject: [PATCH 07/18] Optimize GitHub workflows. --- .github/workflows/build_and_test.yml | 2 +- .github/workflows/create_release.yml | 6 +++--- .github/workflows/docker-keygenerator.yaml | 4 +--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index d552db889c7..8f8985811cc 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -9,7 +9,7 @@ jobs: build: strategy: matrix: - runs-on: [ubuntu-latest, macos-13, macos-13-xlarge] + runs-on: [ubuntu-latest, macos-latest] runs-on: ${{ matrix.runs-on }} name: Build steps: diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index fe74d301325..bac2bab26b7 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -15,7 +15,7 @@ jobs: build: strategy: matrix: - runs-on: [ubuntu-latest, macos-13, macos-13-xlarge] + runs-on: [ubuntu-latest] runs-on: ${{ matrix.runs-on }} name: Build steps: @@ -129,7 +129,7 @@ jobs: zip -r -j ${ARCHIVE} ${BUILD_DIR} - name: Save artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ${{ env.ARCHIVE }} path: ${{ env.ARCHIVE }} @@ -145,7 +145,7 @@ jobs: # https://docs.github.com/en/free-pro-team@latest/actions/guides/storing-workflow-data-as-artifacts#downloading-or-deleting-artifacts # A directory for each artifact is created using its name - name: Download all workflow run artifacts - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4 with: path: assets diff --git a/.github/workflows/docker-keygenerator.yaml b/.github/workflows/docker-keygenerator.yaml index 5e4d9d44a32..c3cca7fc279 100644 --- a/.github/workflows/docker-keygenerator.yaml +++ b/.github/workflows/docker-keygenerator.yaml @@ -2,7 +2,6 @@ name: Build & push keygenerator docker image on: workflow_dispatch: - pull_request: jobs: build-docker-image: @@ -19,7 +18,6 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Log into Docker Hub - if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} @@ -32,5 +30,5 @@ jobs: context: . file: ./docker/keygenerator/Dockerfile platforms: linux/amd64,linux/arm64 - push: ${{ github.event_name != 'pull_request' }} + push: true tags: multiversx/chain-keygenerator:latest From 35bfe149d3c9067f54a1d6e5de98f9c783650260 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Mon, 4 Nov 2024 14:37:01 +0200 Subject: [PATCH 08/18] merges --- go.sum | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/go.sum b/go.sum index 990794e0d27..4de240abdf8 100644 --- a/go.sum +++ b/go.sum @@ -385,30 +385,30 @@ github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/n github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUYwbO0993uPI= github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= -github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e h1:Tsmwhu+UleE+l3buPuqXSKTqfu5FbPmzQ4MjMoUvCWA= -github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e/go.mod h1:2yXl18wUbuV3cRZr7VHxM1xo73kTaC1WUcu2kx8R034= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240508071047-fefea5737840 h1:2mCrTUmbbA+Xv4UifZY9xptrGjcJBcJ2wavSb4FwejU= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240508071047-fefea5737840/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= -github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df h1:clihfi78bMEOWk/qw6WA4uQbCM2e2NGliqswLAvw19k= -github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df/go.mod h1:gtJYB4rR21KBSqJlazn+2z6f9gFSqQP3KvAgL7Qgxw4= -github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240514103357-929ece92ef86 h1:rw+u7qv0HO+7lRddCzfciqDcAWL9/fl2LQqU8AmVtdU= -github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240514103357-929ece92ef86/go.mod h1:UDKRXmxsSyPeAcjLUfGeYkAtYp424PIYkL82kzFYobM= -github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 h1:g9t410dqjcb7UUptbVd/H6Ua12sEzWU4v7VplyNvRZ0= -github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57/go.mod h1:cY6CIXpndW5g5PTPn4WzPwka/UBEf+mgw+PSY5pHGAU= -github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 h1:hFEcbGBtXu8UyB9BMhmAIH2R8BtV/NOq/rsxespLCN8= -github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00/go.mod h1:pnIIfWopbDMQ1EW5Ddc6KDMqv8Qtx+hxbH9rorHpCyo= -github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f h1:yd/G8iPBGOEAwbaS8zndJpO6bQk7Tk72ZhmlqRasThI= -github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f/go.mod h1:E6nfj9EQzGxWDGM3Dn6eZWRC3qFy1G8IqOsYsBOcgWw= -github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240529093845-2a375eef5cc1 h1:C6NQcbfusGkhWP2FNvzafX2w7lKGSzZIius/fM5Gm3c= -github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240529093845-2a375eef5cc1/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo= -github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1 h1:5/h1i7Xd/JH9CiO3ZqvzAjdze+mAbar5sWkh2UqfLgI= -github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1/go.mod h1:N3Oa8QeeHlSip4nbESQpVSLgi/WxtgIwvqfXIZm6gDs= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b h1:puYO0lUyPGA5kZqsiDjGa+daDGQwj9xFs0S5urhZjU8= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b/go.mod h1:SY95hGdAIc8YCGb4uNSy1ux8V8qQbF1ReZJDwQ6AqEo= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240509104009-598a37ff36b9 h1:rrkgAS58jRXc6LThPHY5fm3AnFoUa0VUiYkH5czdlYg= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240509104009-598a37ff36b9/go.mod h1:TiOTsz2kxHadU0It7okOwcynyNPePXzjyl7lnpGLlUQ= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98-0.20240509104102-2a6a709b4041 h1:k0xkmCrJiQzsWk4ZM3oNQ31lheiDvd1qQnNwnyuZzXU= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98-0.20240509104102-2a6a709b4041/go.mod h1:XeZNaDMV0hbDlm3JtW0Hj3mCWKaB/XecQlCzEjiK5L8= +github.com/multiversx/mx-chain-communication-go v1.1.1-0.20241021133229-d0833256e3ec h1:KwpeVZXSHzic8DV9zaJZmaBgDNIIpSdbGz4Q+9fZyiI= +github.com/multiversx/mx-chain-communication-go v1.1.1-0.20241021133229-d0833256e3ec/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= +github.com/multiversx/mx-chain-core-go v1.2.23-0.20241018134424-75bab2a9058c h1:hPCfMSj2vd9xNkARNxB1b3b9k8taFb+Xfja+WK97jno= +github.com/multiversx/mx-chain-core-go v1.2.23-0.20241018134424-75bab2a9058c/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= +github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4= +github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018130218-f48c7282690b h1:GYvm0yGkdQ3OCfNqnyIQNzAzydN3cES8noJZ3eZHN1A= +github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018130218-f48c7282690b/go.mod h1:oGcRK2E3Syv6vRTszWrrb/TqD8akq0yeoMr1wPPiTO4= +github.com/multiversx/mx-chain-logger-go v1.0.15 h1:HlNdK8etyJyL9NQ+6mIXyKPEBo+wRqOwi3n+m2QIHXc= +github.com/multiversx/mx-chain-logger-go v1.0.15/go.mod h1:t3PRKaWB1M+i6gUfD27KXgzLJJC+mAQiN+FLlL1yoGQ= +github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFzHeruelESfpTlf460= +github.com/multiversx/mx-chain-scenario-go v1.4.4/go.mod h1:kI+TWR3oIEgUkbwkHCPo2CQ3VjIge+ezGTibiSGwMxo= +github.com/multiversx/mx-chain-storage-go v1.0.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1Xmo9DcAUECND2obLs= +github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= +github.com/multiversx/mx-chain-vm-common-go v1.5.16 h1:g1SqYjxl7K66Y1O/q6tvDJ37fzpzlxCSfRzSm/woQQY= +github.com/multiversx/mx-chain-vm-common-go v1.5.16/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= +github.com/multiversx/mx-chain-vm-go v1.5.37 h1:Iy3KCvM+DOq1f9UPA7uYK/rI3ZbBOXc2CVNO2/vm5zw= +github.com/multiversx/mx-chain-vm-go v1.5.37/go.mod h1:nzLrWeXvfxCIiwj5uNBZq3d7stkXyeY+Fktfr4tTaiY= +github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= +github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI= +github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc= +github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69/go.mod h1:msY3zaS+K+R10ypqQs/jke6xdNAJzS38PGIaeJj2zhg= +github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 h1:/fYx4ClVPU48pTKh2qk4QVlve0xjjDpvzOakjFUtXJ8= +github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98/go.mod h1:4vqG8bSmufZx263DMrmr8OLbO6q6//VPC4W9PxZLB5Q= github.com/multiversx/mx-components-big-int v1.0.0 h1:Wkr8lSzK2nDqixOrrBa47VNuqdhV1m/aJhaP1EMaiS8= github.com/multiversx/mx-components-big-int v1.0.0/go.mod h1:maIEMgHlNE2u78JaDD0oLzri+ShgU4okHfzP3LWGdQM= github.com/multiversx/protobuf v1.3.2 h1:RaNkxvGTGbA0lMcnHAN24qE1G1i+Xs5yHA6MDvQ4mSM= From 93a819853081a2c13c1995cad3bc4dbae3fb143f Mon Sep 17 00:00:00 2001 From: robertsasu Date: Mon, 11 Nov 2024 10:31:48 +0200 Subject: [PATCH 09/18] fixing tests --- .../chainSimulator/staking/stakingProvider/delegation_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index 423faa3fbab..bcc63c71d28 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go @@ -34,7 +34,7 @@ import ( var log = logger.GetOrCreate("stakingProvider") const gasLimitForConvertOperation = 510_000_000 -const gasLimitForDelegationContractCreationOperation = 500_000_000 +const gasLimitForDelegationContractCreationOperation = 100_000_000 const gasLimitForAddNodesOperation = 500_000_000 const gasLimitForUndelegateOperation = 500_000_000 const gasLimitForMergeOperation = 600_000_000 From 0b6485b716c3366e4f46f43a829399f671d50a76 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Mon, 11 Nov 2024 12:01:24 +0200 Subject: [PATCH 10/18] fixing tests --- .../chainSimulator/relayedTx/relayedTx_test.go | 4 ++-- .../staking/stake/stakeAndUnStake_test.go | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index f7c0f74649b..69d7d505143 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -96,7 +96,7 @@ func testFixRelayedMoveBalanceWithChainSimulatorScCall( require.NoError(t, err) // send relayed tx, fix still not active - innerTx = generateTransaction(owner.Bytes, 2, scAddressBytes, big.NewInt(0), txDataAdd, 3000000) + innerTx = generateTransaction(owner.Bytes, 2, scAddressBytes, big.NewInt(0), txDataAdd, 1230000) marshalledTx, err = json.Marshal(innerTx) require.NoError(t, err) txData = []byte("relayedTx@" + hex.EncodeToString(marshalledTx)) @@ -119,7 +119,7 @@ func testFixRelayedMoveBalanceWithChainSimulatorScCall( require.NoError(t, err) // send relayed tx after fix - innerTx = generateTransaction(owner.Bytes, 3, scAddressBytes, big.NewInt(0), txDataAdd, 3000000) + innerTx = generateTransaction(owner.Bytes, 3, scAddressBytes, big.NewInt(0), txDataAdd, 1500000) marshalledTx, err = json.Marshal(innerTx) require.NoError(t, err) txData = []byte("relayedTx@" + hex.EncodeToString(marshalledTx)) diff --git a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index acb0c7537ed..53509154985 100644 --- a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go @@ -1884,7 +1884,7 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, require.Nil(t, err) require.NotNil(t, unStakeTx) - unStakeTxFee, _ := big.NewInt(0).SetString(unStakeTx.Fee, 10) + unStakeTxFee1, _ := big.NewInt(0).SetString(unStakeTx.Fee, 10) testEpoch := targetEpoch + 1 err = cs.GenerateBlocksUntilEpochIsReached(testEpoch) @@ -1898,6 +1898,8 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, require.Nil(t, err) require.NotNil(t, unStakeTx) + unStakeTxFee2, _ := big.NewInt(0).SetString(unStakeTx.Fee, 10) + testEpoch++ err = cs.GenerateBlocksUntilEpochIsReached(testEpoch) require.Nil(t, err) @@ -1910,6 +1912,8 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, require.Nil(t, err) require.NotNil(t, unStakeTx) + unStakeTxFee3, _ := big.NewInt(0).SetString(unStakeTx.Fee, 10) + testEpoch++ err = cs.GenerateBlocksUntilEpochIsReached(testEpoch) require.Nil(t, err) @@ -1977,9 +1981,9 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, txsFee.Add(txsFee, stakeTxFee) txsFee.Add(txsFee, unBondTxFee) - txsFee.Add(txsFee, unStakeTxFee) - txsFee.Add(txsFee, unStakeTxFee) - txsFee.Add(txsFee, unStakeTxFee) + txsFee.Add(txsFee, unStakeTxFee1) + txsFee.Add(txsFee, unStakeTxFee2) + txsFee.Add(txsFee, unStakeTxFee3) balanceAfterUnbonding.Add(balanceAfterUnbonding, txsFee) From 065db180a5c528b4b8ef704bb78b54c8a0520d6d Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 15 Nov 2024 10:39:02 +0200 Subject: [PATCH 11/18] heart beats in chain simulator --- cmd/node/config/external.toml | 4 +-- node/chainSimulator/chainSimulator_test.go | 6 +++++ node/chainSimulator/components/nodeFacade.go | 26 ++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/cmd/node/config/external.toml b/cmd/node/config/external.toml index 6fbbbb195c6..73bc78bae55 100644 --- a/cmd/node/config/external.toml +++ b/cmd/node/config/external.toml @@ -12,8 +12,8 @@ Username = "" Password = "" # EnabledIndexes represents a slice of indexes that will be enabled for indexing. Full list is: - # ["rating", "transactions", "blocks", "validators", "miniblocks", "rounds", "accounts", "accountshistory", "receipts", "scresults", "accountsesdt", "accountsesdthistory", "epochinfo", "scdeploys", "tokens", "tags", "logs", "delegators", "operations", "esdts"] - EnabledIndexes = ["rating", "transactions", "blocks", "validators", "miniblocks", "rounds", "accounts", "accountshistory", "receipts", "scresults", "accountsesdt", "accountsesdthistory", "epochinfo", "scdeploys", "tokens", "tags", "logs", "delegators", "operations", "esdts"] + # ["rating", "transactions", "blocks", "validators", "miniblocks", "rounds", "accounts", "accountshistory", "receipts", "scresults", "accountsesdt", "accountsesdthistory", "epochinfo", "scdeploys", "tokens", "tags", "logs", "delegators", "operations", "esdts", "events"] + EnabledIndexes = ["rating", "transactions", "blocks", "validators", "miniblocks", "rounds", "accounts", "accountshistory", "receipts", "scresults", "accountsesdt", "accountsesdthistory", "epochinfo", "scdeploys", "tokens", "tags", "logs", "delegators", "operations", "esdts", "events"] # EventNotifierConnector defines settings needed to configure and launch the event notifier component # HTTP event notifier connector integration will be DEPRECATED in the following iterations diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index 18f54ccbfe9..fde143eb3e5 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -83,6 +83,12 @@ func TestChainSimulator_GenerateBlocksShouldWork(t *testing.T) { require.Nil(t, err) require.NotNil(t, chainSimulator) + time.Sleep(time.Second) + + heartBeats, err := chainSimulator.GetNodeHandler(0).GetFacadeHandler().GetHeartbeats() + require.Nil(t, err) + require.Equal(t, 1, len(heartBeats)) + defer chainSimulator.Close() time.Sleep(time.Second) diff --git a/node/chainSimulator/components/nodeFacade.go b/node/chainSimulator/components/nodeFacade.go index d62814fdf03..44dd39b2999 100644 --- a/node/chainSimulator/components/nodeFacade.go +++ b/node/chainSimulator/components/nodeFacade.go @@ -3,6 +3,7 @@ package components import ( "errors" "fmt" + "github.com/multiversx/mx-chain-go/factory/heartbeat" "strconv" "time" @@ -73,6 +74,30 @@ func (node *testOnlyProcessingNode) createFacade(configs config.Configs, apiInte flagsConfig := configs.FlagsConfig + heartBeatComponentsFactory, err := heartbeat.NewHeartbeatV2ComponentsFactory(heartbeat.ArgHeartbeatV2ComponentsFactory{ + Config: *configs.GeneralConfig, + Prefs: *configs.PreferencesConfig, + BaseVersion: "1", + AppVersion: "1", + BootstrapComponents: node.BootstrapComponentsHolder, + CoreComponents: node.CoreComponentsHolder, + DataComponents: node.DataComponentsHolder, + NetworkComponents: node.NetworkComponentsHolder, + CryptoComponents: node.CryptoComponentsHolder, + ProcessComponents: node.ProcessComponentsHolder, + StatusCoreComponents: node.StatusCoreComponents, + }) + + managedHeartbeatV2Components, err := heartbeat.NewManagedHeartbeatV2Components(heartBeatComponentsFactory) + if err != nil { + return err + } + + err = managedHeartbeatV2Components.Create() + if err != nil { + return err + } + nd, err := nodePack.NewNode( nodePack.WithStatusCoreComponents(node.StatusCoreComponents), nodePack.WithCoreComponents(node.CoreComponentsHolder), @@ -95,6 +120,7 @@ func (node *testOnlyProcessingNode) createFacade(configs config.Configs, apiInte nodePack.WithNodeStopChannel(node.CoreComponentsHolder.ChanStopNodeProcess()), nodePack.WithImportMode(configs.ImportDbConfig.IsImportDBMode), nodePack.WithESDTNFTStorageHandler(node.ProcessComponentsHolder.ESDTDataStorageHandlerForAPI()), + nodePack.WithHeartbeatV2Components(managedHeartbeatV2Components), ) if err != nil { return errors.New("error creating node: " + err.Error()) From 38d41ac23dc64a3d55670e3885577854d5568761 Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 15 Nov 2024 10:39:28 +0200 Subject: [PATCH 12/18] fix imports --- node/chainSimulator/components/nodeFacade.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/chainSimulator/components/nodeFacade.go b/node/chainSimulator/components/nodeFacade.go index 44dd39b2999..14218befefa 100644 --- a/node/chainSimulator/components/nodeFacade.go +++ b/node/chainSimulator/components/nodeFacade.go @@ -3,7 +3,6 @@ package components import ( "errors" "fmt" - "github.com/multiversx/mx-chain-go/factory/heartbeat" "strconv" "time" @@ -14,6 +13,7 @@ import ( "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/facade" apiComp "github.com/multiversx/mx-chain-go/factory/api" + "github.com/multiversx/mx-chain-go/factory/heartbeat" nodePack "github.com/multiversx/mx-chain-go/node" "github.com/multiversx/mx-chain-go/node/metrics" "github.com/multiversx/mx-chain-go/process/mock" From c1bcc7e03d1420c5e42f27000ab54d883039cc60 Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 15 Nov 2024 11:47:47 +0200 Subject: [PATCH 13/18] index validators chain simulator --- .../components/statusComponents.go | 53 ++++++++++++++++--- .../components/testOnlyProcessingNode.go | 7 ++- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/node/chainSimulator/components/statusComponents.go b/node/chainSimulator/components/statusComponents.go index be094472fc1..ab62c86581f 100644 --- a/node/chainSimulator/components/statusComponents.go +++ b/node/chainSimulator/components/statusComponents.go @@ -3,6 +3,12 @@ package components import ( "context" "fmt" + nodeData "github.com/multiversx/mx-chain-core-go/data" + outportCore "github.com/multiversx/mx-chain-core-go/data/outport" + "github.com/multiversx/mx-chain-go/epochStart" + "github.com/multiversx/mx-chain-go/epochStart/notifier" + "github.com/multiversx/mx-chain-go/factory" + "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "sync" "time" @@ -17,7 +23,7 @@ import ( "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" + outportFactory "github.com/multiversx/mx-chain-go/outport/factory" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/testscommon" ) @@ -32,10 +38,11 @@ type statusComponentsHolder struct { statusPollingIntervalSec int cancelFunc func() mutex sync.RWMutex + nodesCoordinator nodesCoordinator.NodesCoordinator } // CreateStatusComponents will create a new instance of status components holder -func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandler, statusPollingIntervalSec int, external config.ExternalConfig, coreComponents process.CoreComponentsHolder) (*statusComponentsHolder, error) { +func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandler, statusPollingIntervalSec int, external config.ExternalConfig, coreComponents factory.CoreComponentsHandler) (*statusComponentsHolder, error) { if check.IfNil(appStatusHandler) { return nil, core.ErrNilAppStatusHandler } @@ -51,12 +58,12 @@ func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandl if err != nil { return nil, err } - instance.outportHandler, err = factory.CreateOutport(&factory.OutportFactoryArgs{ + instance.outportHandler, err = outportFactory.CreateOutport(&outportFactory.OutportFactoryArgs{ IsImportDB: false, ShardID: shardID, RetrialInterval: time.Second, HostDriversArgs: hostDriverArgs, - EventNotifierFactoryArgs: &factory.EventNotifierFactoryArgs{}, + EventNotifierFactoryArgs: &outportFactory.EventNotifierFactoryArgs{}, ElasticIndexerFactoryArgs: makeElasticIndexerArgs(external, coreComponents), }) if err != nil { @@ -65,13 +72,45 @@ func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandl instance.softwareVersionChecker = &mock.SoftwareVersionCheckerMock{} instance.managedPeerMonitor = &testscommon.ManagedPeersMonitorStub{} + if shardID == core.MetachainShardId { + coreComponents.EpochStartNotifierWithConfirm().RegisterHandler(instance.epochStartEventHandler()) + } + instance.collectClosableComponents() return instance, nil } -func makeHostDriversArgs(external config.ExternalConfig) ([]factory.ArgsHostDriverFactory, error) { - argsHostDriverFactorySlice := make([]factory.ArgsHostDriverFactory, 0, len(external.HostDriversConfig)) +// SetNodesCoordinator will set the nodes coordinator +func (s *statusComponentsHolder) SetNodesCoordinator(nodesCoordinator nodesCoordinator.NodesCoordinator) { + s.mutex.Lock() + s.nodesCoordinator = nodesCoordinator + s.mutex.Unlock() +} + +func (s *statusComponentsHolder) epochStartEventHandler() epochStart.ActionHandler { + subscribeHandler := notifier.NewHandlerForEpochStart(func(hdr nodeData.HeaderHandler) { + currentEpoch := hdr.GetEpoch() + validatorsPubKeys, err := s.nodesCoordinator.GetAllEligibleValidatorsPublicKeys(currentEpoch) + if err != nil { + log.Warn("s.nodesCoordinator.GetAllEligibleValidatorPublicKeys for current epoch failed", + "epoch", currentEpoch, + "error", err.Error()) + } + + s.outportHandler.SaveValidatorsPubKeys(&outportCore.ValidatorsPubKeys{ + ShardID: hdr.GetShardID(), + ShardValidatorsPubKeys: outportCore.ConvertPubKeys(validatorsPubKeys), + Epoch: currentEpoch, + }) + + }, func(_ nodeData.HeaderHandler) {}, common.IndexerOrder) + + return subscribeHandler +} + +func makeHostDriversArgs(external config.ExternalConfig) ([]outportFactory.ArgsHostDriverFactory, error) { + argsHostDriverFactorySlice := make([]outportFactory.ArgsHostDriverFactory, 0, len(external.HostDriversConfig)) for idx := 0; idx < len(external.HostDriversConfig); idx++ { hostConfig := external.HostDriversConfig[idx] if !hostConfig.Enabled { @@ -83,7 +122,7 @@ func makeHostDriversArgs(external config.ExternalConfig) ([]factory.ArgsHostDriv return argsHostDriverFactorySlice, err } - argsHostDriverFactorySlice = append(argsHostDriverFactorySlice, factory.ArgsHostDriverFactory{ + argsHostDriverFactorySlice = append(argsHostDriverFactorySlice, outportFactory.ArgsHostDriverFactory{ Marshaller: marshaller, HostConfig: hostConfig, }) diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index 28256c4820f..6f90485993c 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -148,7 +148,8 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces } selfShardID := instance.GetShardCoordinator().SelfId() - instance.StatusComponentsHolder, err = CreateStatusComponents( + + statusComponentsH, err := CreateStatusComponents( selfShardID, instance.StatusCoreComponents.AppStatusHandler(), args.Configs.GeneralConfig.GeneralSettings.StatusPollingIntervalSec, @@ -159,6 +160,8 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces return nil, err } + instance.StatusComponentsHolder = statusComponentsH + err = instance.createBlockChain(selfShardID) if err != nil { return nil, err @@ -184,6 +187,8 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces return nil, err } + statusComponentsH.SetNodesCoordinator(instance.NodesCoordinator) + instance.DataComponentsHolder, err = CreateDataComponents(ArgsDataComponentsHolder{ Chain: instance.ChainHandler, StorageService: instance.StoreService, From 2c33cdf89e251c72591f767f44e08fe8e4536571 Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 15 Nov 2024 11:48:15 +0200 Subject: [PATCH 14/18] imports --- node/chainSimulator/components/statusComponents.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/node/chainSimulator/components/statusComponents.go b/node/chainSimulator/components/statusComponents.go index ab62c86581f..ab561e25c2c 100644 --- a/node/chainSimulator/components/statusComponents.go +++ b/node/chainSimulator/components/statusComponents.go @@ -3,28 +3,28 @@ package components import ( "context" "fmt" - nodeData "github.com/multiversx/mx-chain-core-go/data" - outportCore "github.com/multiversx/mx-chain-core-go/data/outport" - "github.com/multiversx/mx-chain-go/epochStart" - "github.com/multiversx/mx-chain-go/epochStart/notifier" - "github.com/multiversx/mx-chain-go/factory" - "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "sync" "time" "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" + nodeData "github.com/multiversx/mx-chain-core-go/data" + outportCore "github.com/multiversx/mx-chain-core-go/data/outport" factoryMarshalizer "github.com/multiversx/mx-chain-core-go/marshal/factory" indexerFactory "github.com/multiversx/mx-chain-es-indexer-go/process/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/epochStart" + "github.com/multiversx/mx-chain-go/epochStart/notifier" "github.com/multiversx/mx-chain-go/errors" + "github.com/multiversx/mx-chain-go/factory" "github.com/multiversx/mx-chain-go/integrationTests/mock" "github.com/multiversx/mx-chain-go/outport" outportFactory "github.com/multiversx/mx-chain-go/outport/factory" "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "github.com/multiversx/mx-chain-go/testscommon" ) From 860f20d5f8f2794a994b202f6ed262fcf854ccf2 Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 15 Nov 2024 12:26:04 +0200 Subject: [PATCH 15/18] fix linter --- node/chainSimulator/components/nodeFacade.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/node/chainSimulator/components/nodeFacade.go b/node/chainSimulator/components/nodeFacade.go index 14218befefa..4d0af7def23 100644 --- a/node/chainSimulator/components/nodeFacade.go +++ b/node/chainSimulator/components/nodeFacade.go @@ -87,6 +87,9 @@ func (node *testOnlyProcessingNode) createFacade(configs config.Configs, apiInte ProcessComponents: node.ProcessComponentsHolder, StatusCoreComponents: node.StatusCoreComponents, }) + if err != nil { + return err + } managedHeartbeatV2Components, err := heartbeat.NewManagedHeartbeatV2Components(heartBeatComponentsFactory) if err != nil { From a97147f97d05234653cd560e398c3896d569884d Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 19 Nov 2024 16:48:03 +0200 Subject: [PATCH 16/18] chain simulator heartbeat --- .../vm/esdtImprovements_test.go | 20 +++++-- node/chainSimulator/chainSimulator.go | 11 ++-- node/chainSimulator/chainSimulator_test.go | 12 ++--- .../components/heartbeat/heartBeat.go | 52 +++++++++++++++++++ .../components/heartbeat/monitor.go | 39 ++++++++++++++ node/chainSimulator/components/nodeFacade.go | 31 +++-------- .../components/testOnlyProcessingNode.go | 3 +- node/chainSimulator/process/interface.go | 7 +++ node/chainSimulator/process/processor.go | 38 +++++++++++++- node/chainSimulator/process/processor_test.go | 33 ++++++------ 10 files changed, 188 insertions(+), 58 deletions(-) create mode 100644 node/chainSimulator/components/heartbeat/heartBeat.go create mode 100644 node/chainSimulator/components/heartbeat/monitor.go diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index e0f23f1ce8c..8361feb4fee 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -3868,7 +3868,9 @@ func TestChainSimulator_CheckRolesWhichHasToBeSingular(t *testing.T) { } func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } baseIssuingCost := "1000" cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) @@ -4237,7 +4239,9 @@ func transferSpecialRoleToAddr( } func TestChainSimulator_dynamicNFT_mergeMetaDataFromMultipleUpdates(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } baseIssuingCost := "1000" cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) @@ -4385,7 +4389,9 @@ func TestChainSimulator_dynamicNFT_mergeMetaDataFromMultipleUpdates(t *testing.T } func TestChainSimulator_dynamicNFT_changeMetaDataForOneNFTShouldNotChangeOtherNonces(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } baseIssuingCost := "1000" cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) @@ -4498,7 +4504,9 @@ func TestChainSimulator_dynamicNFT_changeMetaDataForOneNFTShouldNotChangeOtherNo } func TestChainSimulator_dynamicNFT_updateBeforeCreateOnSameAccountShouldOverwrite(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } baseIssuingCost := "1000" cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) @@ -4595,7 +4603,9 @@ func TestChainSimulator_dynamicNFT_updateBeforeCreateOnSameAccountShouldOverwrit } func TestChainSimulator_dynamicNFT_updateBeforeCreateOnDifferentAccountsShouldMergeMetaDataWhenTransferred(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } baseIssuingCost := "1000" cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index 742d040c8c8..b8edc491eda 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -11,7 +11,9 @@ import ( "time" "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/factory" "github.com/multiversx/mx-chain-go/node/chainSimulator/components" + "github.com/multiversx/mx-chain-go/node/chainSimulator/components/heartbeat" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" chainSimulatorErrors "github.com/multiversx/mx-chain-go/node/chainSimulator/errors" @@ -130,18 +132,20 @@ func (s *simulator) createChainHandlers(args ArgsBaseChainSimulator) error { return err } + monitor := heartbeat.NewHeartbeatMonitor() + for idx := -1; idx < int(args.NumOfShards); idx++ { shardIDStr := fmt.Sprintf("%d", idx) if idx == -1 { shardIDStr = "metachain" } - node, errCreate := s.createTestNode(*outputConfigs, args, shardIDStr) + node, errCreate := s.createTestNode(*outputConfigs, args, shardIDStr, monitor) if errCreate != nil { return errCreate } - chainHandler, errCreate := process.NewBlocksCreator(node) + chainHandler, errCreate := process.NewBlocksCreator(node, monitor) if errCreate != nil { return errCreate } @@ -195,7 +199,7 @@ func computeStartTimeBaseOnInitialRound(args ArgsChainSimulator) int64 { } func (s *simulator) createTestNode( - outputConfigs configs.ArgsConfigsSimulator, args ArgsBaseChainSimulator, shardIDStr string, + outputConfigs configs.ArgsConfigsSimulator, args ArgsBaseChainSimulator, shardIDStr string, monitor factory.HeartbeatV2Monitor, ) (process.NodeHandler, error) { argsTestOnlyProcessorNode := components.ArgsTestOnlyProcessingNode{ Configs: outputConfigs.Configs, @@ -214,6 +218,7 @@ func (s *simulator) createTestNode( MetaChainConsensusGroupSize: args.MetaChainConsensusGroupSize, RoundDurationInMillis: args.RoundDurationInMillis, VmQueryDelayAfterStartInMs: args.VmQueryDelayAfterStartInMs, + Monitor: monitor, } return components.NewTestOnlyProcessingNode(argsTestOnlyProcessorNode) diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index fde143eb3e5..2ba89205afe 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -82,19 +82,17 @@ func TestChainSimulator_GenerateBlocksShouldWork(t *testing.T) { }) require.Nil(t, err) require.NotNil(t, chainSimulator) - - time.Sleep(time.Second) - - heartBeats, err := chainSimulator.GetNodeHandler(0).GetFacadeHandler().GetHeartbeats() - require.Nil(t, err) - require.Equal(t, 1, len(heartBeats)) - defer chainSimulator.Close() time.Sleep(time.Second) err = chainSimulator.GenerateBlocks(50) require.Nil(t, err) + + heartBeats, err := chainSimulator.GetNodeHandler(0).GetFacadeHandler().GetHeartbeats() + require.Nil(t, err) + require.Equal(t, 4, len(heartBeats)) + } func TestChainSimulator_GenerateBlocksAndEpochChangeShouldWork(t *testing.T) { diff --git a/node/chainSimulator/components/heartbeat/heartBeat.go b/node/chainSimulator/components/heartbeat/heartBeat.go new file mode 100644 index 00000000000..ffdd53b6961 --- /dev/null +++ b/node/chainSimulator/components/heartbeat/heartBeat.go @@ -0,0 +1,52 @@ +package heartbeat + +import ( + "github.com/multiversx/mx-chain-core-go/core/check" + "github.com/multiversx/mx-chain-go/factory" + "github.com/multiversx/mx-chain-go/heartbeat" +) + +type heartBeatComponents struct { + monitor factory.HeartbeatV2Monitor +} + +// NewSyncedHeartbeatComponents will create a new instance of heartbeat components +func NewSyncedHeartbeatComponents(monitor factory.HeartbeatV2Monitor) (factory.HeartbeatV2ComponentsHandler, error) { + if check.IfNil(monitor) { + return nil, heartbeat.ErrNilHeartbeatMonitor + } + + return &heartBeatComponents{ + monitor: monitor, + }, nil +} + +// Create will do nothing +func (h *heartBeatComponents) Create() error { + return nil +} + +// Close will do nothing +func (h *heartBeatComponents) Close() error { + return nil +} + +// CheckSubcomponents will do nothing +func (h *heartBeatComponents) CheckSubcomponents() error { + return nil +} + +// String will return a string +func (h *heartBeatComponents) String() string { + return "heartBeat" +} + +// Monitor will return the monitor +func (h *heartBeatComponents) Monitor() factory.HeartbeatV2Monitor { + return h.monitor +} + +// IsInterfaceNil returns true if there is no value under the interface +func (h *heartBeatComponents) IsInterfaceNil() bool { + return h == nil +} diff --git a/node/chainSimulator/components/heartbeat/monitor.go b/node/chainSimulator/components/heartbeat/monitor.go new file mode 100644 index 00000000000..9fda1a369f8 --- /dev/null +++ b/node/chainSimulator/components/heartbeat/monitor.go @@ -0,0 +1,39 @@ +package heartbeat + +import ( + "sync" + + "github.com/multiversx/mx-chain-go/heartbeat/data" +) + +type heartbeatMonitor struct { + heartbeats []data.PubKeyHeartbeat + mutex sync.RWMutex +} + +// NewHeartbeatMonitor will create a new instance of heartbeat monitor +func NewHeartbeatMonitor() *heartbeatMonitor { + return &heartbeatMonitor{ + heartbeats: make([]data.PubKeyHeartbeat, 0), + } +} + +// GetHeartbeats will return the heartbeats +func (hm *heartbeatMonitor) GetHeartbeats() []data.PubKeyHeartbeat { + hm.mutex.RLock() + defer hm.mutex.RUnlock() + + return hm.heartbeats +} + +// SetHeartbeats will set the provided heartbeats +func (hm *heartbeatMonitor) SetHeartbeats(heartbeats []data.PubKeyHeartbeat) { + hm.mutex.Lock() + hm.heartbeats = heartbeats + hm.mutex.Unlock() +} + +// IsInterfaceNil returns true if there is no value under the interface +func (hm *heartbeatMonitor) IsInterfaceNil() bool { + return nil == hm +} diff --git a/node/chainSimulator/components/nodeFacade.go b/node/chainSimulator/components/nodeFacade.go index 4d0af7def23..f1bacb11b96 100644 --- a/node/chainSimulator/components/nodeFacade.go +++ b/node/chainSimulator/components/nodeFacade.go @@ -3,6 +3,8 @@ package components import ( "errors" "fmt" + "github.com/multiversx/mx-chain-go/factory" + heartbeat2 "github.com/multiversx/mx-chain-go/node/chainSimulator/components/heartbeat" "strconv" "time" @@ -13,13 +15,12 @@ import ( "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/facade" apiComp "github.com/multiversx/mx-chain-go/factory/api" - "github.com/multiversx/mx-chain-go/factory/heartbeat" nodePack "github.com/multiversx/mx-chain-go/node" "github.com/multiversx/mx-chain-go/node/metrics" "github.com/multiversx/mx-chain-go/process/mock" ) -func (node *testOnlyProcessingNode) createFacade(configs config.Configs, apiInterface APIConfigurator, vmQueryDelayAfterStartInMs uint64) error { +func (node *testOnlyProcessingNode) createFacade(configs config.Configs, apiInterface APIConfigurator, vmQueryDelayAfterStartInMs uint64, monitor factory.HeartbeatV2Monitor) error { log.Debug("creating api resolver structure") err := node.createMetrics(configs) @@ -74,32 +75,12 @@ func (node *testOnlyProcessingNode) createFacade(configs config.Configs, apiInte flagsConfig := configs.FlagsConfig - heartBeatComponentsFactory, err := heartbeat.NewHeartbeatV2ComponentsFactory(heartbeat.ArgHeartbeatV2ComponentsFactory{ - Config: *configs.GeneralConfig, - Prefs: *configs.PreferencesConfig, - BaseVersion: "1", - AppVersion: "1", - BootstrapComponents: node.BootstrapComponentsHolder, - CoreComponents: node.CoreComponentsHolder, - DataComponents: node.DataComponentsHolder, - NetworkComponents: node.NetworkComponentsHolder, - CryptoComponents: node.CryptoComponentsHolder, - ProcessComponents: node.ProcessComponentsHolder, - StatusCoreComponents: node.StatusCoreComponents, - }) + heartbeatComponents, err := heartbeat2.NewSyncedHeartbeatComponents(monitor) if err != nil { return err } - managedHeartbeatV2Components, err := heartbeat.NewManagedHeartbeatV2Components(heartBeatComponentsFactory) - if err != nil { - return err - } - - err = managedHeartbeatV2Components.Create() - if err != nil { - return err - } + node.closeHandler.AddComponent(heartbeatComponents) nd, err := nodePack.NewNode( nodePack.WithStatusCoreComponents(node.StatusCoreComponents), @@ -123,7 +104,7 @@ func (node *testOnlyProcessingNode) createFacade(configs config.Configs, apiInte nodePack.WithNodeStopChannel(node.CoreComponentsHolder.ChanStopNodeProcess()), nodePack.WithImportMode(configs.ImportDbConfig.IsImportDBMode), nodePack.WithESDTNFTStorageHandler(node.ProcessComponentsHolder.ESDTDataStorageHandlerForAPI()), - nodePack.WithHeartbeatV2Components(managedHeartbeatV2Components), + nodePack.WithHeartbeatV2Components(heartbeatComponents), ) if err != nil { return errors.New("error creating node: " + err.Error()) diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index 6f90485993c..8bc542f432c 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -37,6 +37,7 @@ type ArgsTestOnlyProcessingNode struct { ChanStopNodeProcess chan endProcess.ArgEndProcess SyncedBroadcastNetwork SyncedBroadcastNetworkHandler + Monitor factory.HeartbeatV2Monitor InitialRound int64 InitialNonce uint64 @@ -240,7 +241,7 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces return nil, err } - err = instance.createFacade(args.Configs, args.APIInterface, args.VmQueryDelayAfterStartInMs) + err = instance.createFacade(args.Configs, args.APIInterface, args.VmQueryDelayAfterStartInMs, args.Monitor) if err != nil { return nil, err } diff --git a/node/chainSimulator/process/interface.go b/node/chainSimulator/process/interface.go index 47f937fb97c..7ae2f07517e 100644 --- a/node/chainSimulator/process/interface.go +++ b/node/chainSimulator/process/interface.go @@ -5,6 +5,7 @@ import ( "github.com/multiversx/mx-chain-go/api/shared" "github.com/multiversx/mx-chain-go/consensus" "github.com/multiversx/mx-chain-go/factory" + "github.com/multiversx/mx-chain-go/heartbeat/data" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" "github.com/multiversx/mx-chain-go/sharding" ) @@ -28,3 +29,9 @@ type NodeHandler interface { Close() error IsInterfaceNil() bool } + +// HeartbeatMonitorWithSet defines what a heartbeat monitor with set should be able to do +type HeartbeatMonitorWithSet interface { + SetHeartbeats(heartbeats []data.PubKeyHeartbeat) + IsInterfaceNil() bool +} diff --git a/node/chainSimulator/process/processor.go b/node/chainSimulator/process/processor.go index d8f225bfde8..1c9819e27f0 100644 --- a/node/chainSimulator/process/processor.go +++ b/node/chainSimulator/process/processor.go @@ -1,10 +1,13 @@ package process import ( + "time" + "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/consensus/spos" + heartbeatData "github.com/multiversx/mx-chain-go/heartbeat/data" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" logger "github.com/multiversx/mx-chain-logger-go" ) @@ -17,16 +20,18 @@ type manualRoundHandler interface { type blocksCreator struct { nodeHandler NodeHandler + monitor HeartbeatMonitorWithSet } // NewBlocksCreator will create a new instance of blocksCreator -func NewBlocksCreator(nodeHandler NodeHandler) (*blocksCreator, error) { +func NewBlocksCreator(nodeHandler NodeHandler, monitor HeartbeatMonitorWithSet) (*blocksCreator, error) { if check.IfNil(nodeHandler) { return nil, ErrNilNodeHandler } return &blocksCreator{ nodeHandler: nodeHandler, + monitor: monitor, }, nil } @@ -123,6 +128,11 @@ func (creator *blocksCreator) CreateNewBlock() error { return err } + err = creator.setHeartBeat(header) + if err != nil { + return err + } + miniBlocks, transactions, err := bp.MarshalizedDataToBroadcast(header, block) if err != nil { return err @@ -141,6 +151,32 @@ func (creator *blocksCreator) CreateNewBlock() error { return creator.nodeHandler.GetBroadcastMessenger().BroadcastTransactions(transactions, blsKey.PubKey()) } +func (creator *blocksCreator) setHeartBeat(header data.HeaderHandler) error { + if !header.IsStartOfEpochBlock() { + return nil + } + + validators := creator.nodeHandler.GetProcessComponents().ValidatorsProvider().GetLatestValidators() + + var heartbeats []heartbeatData.PubKeyHeartbeat + for key, validator := range validators { + heartbeats = append(heartbeats, heartbeatData.PubKeyHeartbeat{ + PublicKey: key, + TimeStamp: time.Now(), + IsActive: true, + NumInstances: 1, + ComputedShardID: creator.nodeHandler.GetShardCoordinator().SelfId(), + ReceivedShardID: validator.ShardId, + }) + } + + if len(heartbeats) > 0 { + creator.monitor.SetHeartbeats(heartbeats) + } + + return nil +} + func (creator *blocksCreator) getPreviousHeaderData() (nonce, round uint64, prevHash, prevRandSeed []byte, epoch uint32) { currentHeader := creator.nodeHandler.GetChainHandler().GetCurrentBlockHeader() diff --git a/node/chainSimulator/process/processor_test.go b/node/chainSimulator/process/processor_test.go index 80ffd568134..84a93eea028 100644 --- a/node/chainSimulator/process/processor_test.go +++ b/node/chainSimulator/process/processor_test.go @@ -14,6 +14,7 @@ import ( mockConsensus "github.com/multiversx/mx-chain-go/consensus/mock" "github.com/multiversx/mx-chain-go/factory" "github.com/multiversx/mx-chain-go/integrationTests/mock" + "github.com/multiversx/mx-chain-go/node/chainSimulator/components/heartbeat" chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/sharding" @@ -35,14 +36,14 @@ func TestNewBlocksCreator(t *testing.T) { t.Run("nil node handler should error", func(t *testing.T) { t.Parallel() - creator, err := chainSimulatorProcess.NewBlocksCreator(nil) + creator, err := chainSimulatorProcess.NewBlocksCreator(nil, heartbeat.NewHeartbeatMonitor()) require.Equal(t, chainSimulatorProcess.ErrNilNodeHandler, err) require.Nil(t, creator) }) t.Run("should work", func(t *testing.T) { t.Parallel() - creator, err := chainSimulatorProcess.NewBlocksCreator(&chainSimulator.NodeHandlerMock{}) + creator, err := chainSimulatorProcess.NewBlocksCreator(&chainSimulator.NodeHandlerMock{}, heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) require.NotNil(t, creator) }) @@ -51,10 +52,10 @@ func TestNewBlocksCreator(t *testing.T) { func TestBlocksCreator_IsInterfaceNil(t *testing.T) { t.Parallel() - creator, _ := chainSimulatorProcess.NewBlocksCreator(nil) + creator, _ := chainSimulatorProcess.NewBlocksCreator(nil, heartbeat.NewHeartbeatMonitor()) require.True(t, creator.IsInterfaceNil()) - creator, _ = chainSimulatorProcess.NewBlocksCreator(&chainSimulator.NodeHandlerMock{}) + creator, _ = chainSimulatorProcess.NewBlocksCreator(&chainSimulator.NodeHandlerMock{}, heartbeat.NewHeartbeatMonitor()) require.False(t, creator.IsInterfaceNil()) } @@ -86,7 +87,7 @@ func TestBlocksCreator_IncrementRound(t *testing.T) { } }, } - creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler) + creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler, heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) creator.IncrementRound() @@ -119,7 +120,7 @@ func TestBlocksCreator_CreateNewBlock(t *testing.T) { } } - creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler) + creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler, heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) err = creator.CreateNewBlock() @@ -227,7 +228,7 @@ func TestBlocksCreator_CreateNewBlock(t *testing.T) { }, } } - creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler) + creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler, heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) err = creator.CreateNewBlock() @@ -246,7 +247,7 @@ func TestBlocksCreator_CreateNewBlock(t *testing.T) { }, } } - creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler) + creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler, heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) err = creator.CreateNewBlock() @@ -267,7 +268,7 @@ func TestBlocksCreator_CreateNewBlock(t *testing.T) { }, } } - creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler) + creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler, heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) err = creator.CreateNewBlock() @@ -319,7 +320,7 @@ func TestBlocksCreator_CreateNewBlock(t *testing.T) { }, } } - creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler) + creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler, heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) err = creator.CreateNewBlock() @@ -340,7 +341,7 @@ func TestBlocksCreator_CreateNewBlock(t *testing.T) { }, } } - creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler) + creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler, heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) err = creator.CreateNewBlock() @@ -361,7 +362,7 @@ func TestBlocksCreator_CreateNewBlock(t *testing.T) { }, } } - creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler) + creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler, heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) err = creator.CreateNewBlock() @@ -382,7 +383,7 @@ func TestBlocksCreator_CreateNewBlock(t *testing.T) { }, } } - creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler) + creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler, heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) err = creator.CreateNewBlock() @@ -521,7 +522,7 @@ func TestBlocksCreator_CreateNewBlock(t *testing.T) { }, } } - creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler) + creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler, heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) err = creator.CreateNewBlock() @@ -530,7 +531,7 @@ func TestBlocksCreator_CreateNewBlock(t *testing.T) { t.Run("should work", func(t *testing.T) { t.Parallel() - creator, err := chainSimulatorProcess.NewBlocksCreator(getNodeHandler()) + creator, err := chainSimulatorProcess.NewBlocksCreator(getNodeHandler(), heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) err = creator.CreateNewBlock() @@ -547,7 +548,7 @@ func testCreateNewBlock(t *testing.T, blockProcess process.BlockProcessor, expec NodesCoord: nc, } } - creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler) + creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler, heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) err = creator.CreateNewBlock() From ba15dcb20411be069c88882f1cc00b03472c4705 Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 19 Nov 2024 16:50:05 +0200 Subject: [PATCH 17/18] fixes --- node/chainSimulator/components/testOnlyProcessingNode_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/node/chainSimulator/components/testOnlyProcessingNode_test.go b/node/chainSimulator/components/testOnlyProcessingNode_test.go index c363ca8019c..801c11585e9 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode_test.go +++ b/node/chainSimulator/components/testOnlyProcessingNode_test.go @@ -2,6 +2,7 @@ package components import ( "errors" + "github.com/multiversx/mx-chain-go/node/chainSimulator/components/heartbeat" "math/big" "strings" "testing" @@ -44,6 +45,7 @@ func createMockArgsTestOnlyProcessingNode(t *testing.T) ArgsTestOnlyProcessingNo SyncedBroadcastNetwork: NewSyncedBroadcastNetwork(), ChanStopNodeProcess: make(chan endProcess.ArgEndProcess), APIInterface: api.NewNoApiInterface(), + Monitor: heartbeat.NewHeartbeatMonitor(), ShardIDStr: "0", RoundDurationInMillis: 6000, MinNodesMeta: 1, From 5e01a062b7d170b871aece1113ad83ea1bc9c7c1 Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 20 Nov 2024 10:27:07 +0200 Subject: [PATCH 18/18] fixes after review --- node/chainSimulator/components/nodeFacade.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/node/chainSimulator/components/nodeFacade.go b/node/chainSimulator/components/nodeFacade.go index f1bacb11b96..24bdc3d1ada 100644 --- a/node/chainSimulator/components/nodeFacade.go +++ b/node/chainSimulator/components/nodeFacade.go @@ -3,8 +3,6 @@ package components import ( "errors" "fmt" - "github.com/multiversx/mx-chain-go/factory" - heartbeat2 "github.com/multiversx/mx-chain-go/node/chainSimulator/components/heartbeat" "strconv" "time" @@ -14,8 +12,10 @@ import ( "github.com/multiversx/mx-chain-go/common/forking" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/facade" + "github.com/multiversx/mx-chain-go/factory" apiComp "github.com/multiversx/mx-chain-go/factory/api" nodePack "github.com/multiversx/mx-chain-go/node" + simulatorHeartbeat "github.com/multiversx/mx-chain-go/node/chainSimulator/components/heartbeat" "github.com/multiversx/mx-chain-go/node/metrics" "github.com/multiversx/mx-chain-go/process/mock" ) @@ -75,7 +75,7 @@ func (node *testOnlyProcessingNode) createFacade(configs config.Configs, apiInte flagsConfig := configs.FlagsConfig - heartbeatComponents, err := heartbeat2.NewSyncedHeartbeatComponents(monitor) + heartbeatComponents, err := simulatorHeartbeat.NewSyncedHeartbeatComponents(monitor) if err != nil { return err }