From 18e8d700d2bec46c3aaef4999ebc625cd24e5212 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 8 Sep 2023 15:06:17 +0300 Subject: [PATCH 001/503] new flag for relayed v3 --- cmd/node/config/enableEpochs.toml | 3 + common/constants.go | 3 + common/enablers/enableEpochsHandler.go | 1 + common/enablers/enableEpochsHandler_test.go | 4 + common/enablers/epochFlags.go | 9 ++- common/interface.go | 1 + config/epochConfig.go | 1 + config/tomlConfig_test.go | 81 ++++++++++--------- genesis/process/shardGenesisBlockCreator.go | 1 + go.mod | 2 +- go.sum | 4 +- integrationTests/testProcessorNode.go | 1 + node/metrics/metrics.go | 1 + node/metrics/metrics_test.go | 2 + sharding/mock/enableEpochsHandlerMock.go | 5 ++ .../enableEpochsHandlerStub.go | 9 +++ 16 files changed, 85 insertions(+), 43 deletions(-) diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index a24d2dc1187..415ca4be7ad 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -278,6 +278,9 @@ # ScToScLogEventEnableEpoch represents the epoch when the sc to sc log event feature is enabled ScToScLogEventEnableEpoch = 3 + # RelayedTransactionsV3EnableEpoch represents the epoch when the relayed transactions V3 will be enabled + RelayedTransactionsV3EnableEpoch = 3 + # BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers BLSMultiSignerEnableEpoch = [ { EnableEpoch = 0, Type = "no-KOSK" }, diff --git a/common/constants.go b/common/constants.go index 2fc64ab0756..c1205fd3f1e 100644 --- a/common/constants.go +++ b/common/constants.go @@ -476,6 +476,9 @@ const ( // MetricRelayedTransactionsV2EnableEpoch represents the epoch when the relayed transactions v2 is enabled MetricRelayedTransactionsV2EnableEpoch = "erd_relayed_transactions_v2_enable_epoch" + // MetricRelayedTransactionsV3EnableEpoch represents the epoch when the relayed transactions v3 is enabled + MetricRelayedTransactionsV3EnableEpoch = "erd_relayed_transactions_v3_enable_epoch" + // MetricUnbondTokensV2EnableEpoch represents the epoch when the unbond tokens v2 is applied MetricUnbondTokensV2EnableEpoch = "erd_unbond_tokens_v2_enable_epoch" diff --git a/common/enablers/enableEpochsHandler.go b/common/enablers/enableEpochsHandler.go index 6c1f2d3f59c..63106ea68c7 100644 --- a/common/enablers/enableEpochsHandler.go +++ b/common/enablers/enableEpochsHandler.go @@ -130,6 +130,7 @@ func (handler *enableEpochsHandler) EpochConfirmed(epoch uint32, _ uint64) { handler.setFlagValue(epoch >= handler.enableEpochsConfig.FixDelegationChangeOwnerOnAccountEnableEpoch, handler.fixDelegationChangeOwnerOnAccountFlag, "fixDelegationChangeOwnerOnAccountFlag", epoch, handler.enableEpochsConfig.FixDelegationChangeOwnerOnAccountEnableEpoch) handler.setFlagValue(epoch >= handler.enableEpochsConfig.SCProcessorV2EnableEpoch, handler.scProcessorV2Flag, "scProcessorV2Flag", epoch, handler.enableEpochsConfig.SCProcessorV2EnableEpoch) handler.setFlagValue(epoch >= handler.enableEpochsConfig.DynamicGasCostForDataTrieStorageLoadEnableEpoch, handler.dynamicGasCostForDataTrieStorageLoadFlag, "dynamicGasCostForDataTrieStorageLoadFlag", epoch, handler.enableEpochsConfig.DynamicGasCostForDataTrieStorageLoadEnableEpoch) + handler.setFlagValue(epoch >= handler.enableEpochsConfig.RelayedTransactionsV3EnableEpoch, handler.relayedTransactionsV3Flag, "relayedTransactionsV3Flag", epoch, handler.enableEpochsConfig.RelayedTransactionsV3EnableEpoch) } func (handler *enableEpochsHandler) setFlagValue(value bool, flag *atomic.Flag, flagName string, epoch uint32, flagEpoch uint32) { diff --git a/common/enablers/enableEpochsHandler_test.go b/common/enablers/enableEpochsHandler_test.go index 4f6ff04ec9b..487eb8502e0 100644 --- a/common/enablers/enableEpochsHandler_test.go +++ b/common/enablers/enableEpochsHandler_test.go @@ -104,6 +104,7 @@ func createEnableEpochsConfig() config.EnableEpochs { FixDelegationChangeOwnerOnAccountEnableEpoch: 87, DeterministicSortOnValidatorsInfoEnableEpoch: 79, ScToScLogEventEnableEpoch: 88, + RelayedTransactionsV3EnableEpoch: 89, } } @@ -247,6 +248,7 @@ func TestNewEnableEpochsHandler_EpochConfirmed(t *testing.T) { assert.True(t, handler.IsTransferToMetaFlagEnabled()) assert.True(t, handler.IsESDTNFTImprovementV1FlagEnabled()) assert.True(t, handler.FixDelegationChangeOwnerOnAccountEnabled()) + assert.True(t, handler.IsRelayedTransactionsV3FlagEnabled()) }) t.Run("flags with == condition should not be set, the ones with >= should be set", func(t *testing.T) { t.Parallel() @@ -366,6 +368,7 @@ func TestNewEnableEpochsHandler_EpochConfirmed(t *testing.T) { assert.True(t, handler.IsTransferToMetaFlagEnabled()) assert.True(t, handler.IsESDTNFTImprovementV1FlagEnabled()) assert.True(t, handler.FixDelegationChangeOwnerOnAccountEnabled()) + assert.True(t, handler.IsRelayedTransactionsV3FlagEnabled()) }) t.Run("flags with < should be set", func(t *testing.T) { t.Parallel() @@ -480,6 +483,7 @@ func TestNewEnableEpochsHandler_EpochConfirmed(t *testing.T) { assert.False(t, handler.IsTransferToMetaFlagEnabled()) assert.False(t, handler.IsESDTNFTImprovementV1FlagEnabled()) assert.False(t, handler.FixDelegationChangeOwnerOnAccountEnabled()) + assert.False(t, handler.IsRelayedTransactionsV3FlagEnabled()) }) } diff --git a/common/enablers/epochFlags.go b/common/enablers/epochFlags.go index 411ab6b15d6..923dcb615da 100644 --- a/common/enablers/epochFlags.go +++ b/common/enablers/epochFlags.go @@ -102,6 +102,7 @@ type epochFlagsHolder struct { autoBalanceDataTriesFlag *atomic.Flag fixDelegationChangeOwnerOnAccountFlag *atomic.Flag dynamicGasCostForDataTrieStorageLoadFlag *atomic.Flag + relayedTransactionsV3Flag *atomic.Flag } func newEpochFlagsHolder() *epochFlagsHolder { @@ -203,6 +204,7 @@ func newEpochFlagsHolder() *epochFlagsHolder { autoBalanceDataTriesFlag: &atomic.Flag{}, fixDelegationChangeOwnerOnAccountFlag: &atomic.Flag{}, dynamicGasCostForDataTrieStorageLoadFlag: &atomic.Flag{}, + relayedTransactionsV3Flag: &atomic.Flag{}, } } @@ -694,7 +696,7 @@ func (holder *epochFlagsHolder) IsSetGuardianEnabled() bool { return holder.setGuardianFlag.IsSet() } -// IsScToScLogEventFlagEnabled returns true if scToScLogEventFlag is enabled +// IsScToScEventLogEnabled returns true if scToScLogEventFlag is enabled func (holder *epochFlagsHolder) IsScToScEventLogEnabled() bool { return holder.scToScLogEventFlag.IsSet() } @@ -739,6 +741,11 @@ func (holder *epochFlagsHolder) FixDelegationChangeOwnerOnAccountEnabled() bool return holder.fixDelegationChangeOwnerOnAccountFlag.IsSet() } +// IsRelayedTransactionsV3FlagEnabled returns true if relayedTransactionsV3Flag is enabled +func (holder *epochFlagsHolder) IsRelayedTransactionsV3FlagEnabled() bool { + return holder.relayedTransactionsV3Flag.IsSet() +} + // IsDynamicGasCostForDataTrieStorageLoadEnabled returns true if dynamicGasCostForDataTrieStorageLoadFlag is enabled func (holder *epochFlagsHolder) IsDynamicGasCostForDataTrieStorageLoadEnabled() bool { return holder.dynamicGasCostForDataTrieStorageLoadFlag.IsSet() diff --git a/common/interface.go b/common/interface.go index aa8e6da2f25..bf3f36726c3 100644 --- a/common/interface.go +++ b/common/interface.go @@ -395,6 +395,7 @@ type EnableEpochsHandler interface { IsAutoBalanceDataTriesEnabled() bool IsDynamicGasCostForDataTrieStorageLoadEnabled() bool FixDelegationChangeOwnerOnAccountEnabled() bool + IsRelayedTransactionsV3FlagEnabled() bool IsInterfaceNil() bool } diff --git a/config/epochConfig.go b/config/epochConfig.go index 029929d7edb..72763f95c73 100644 --- a/config/epochConfig.go +++ b/config/epochConfig.go @@ -105,6 +105,7 @@ type EnableEpochs struct { ConsistentTokensValuesLengthCheckEnableEpoch uint32 FixDelegationChangeOwnerOnAccountEnableEpoch uint32 DynamicGasCostForDataTrieStorageLoadEnableEpoch uint32 + RelayedTransactionsV3EnableEpoch uint32 BLSMultiSignerEnableEpoch []MultiSignerConfig } diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index 372dfbdc844..aefb06fa03d 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -817,6 +817,9 @@ func TestEnableEpochConfig(t *testing.T) { # ScToScLogEventEnableEpoch represents the epoch when the sc to sc log event feature is enabled ScToScLogEventEnableEpoch = 88 + # RelayedTransactionsV3EnableEpoch represents the epoch when the relayed transactions V3 will be enabled + RelayedTransactionsV3EnableEpoch = 89 + # MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MaxNodesChangeEnableEpoch = [ { EpochEnable = 44, MaxNumNodes = 2169, NodesToShufflePerShard = 80 }, @@ -837,37 +840,35 @@ func TestEnableEpochConfig(t *testing.T) { expectedCfg := EpochConfig{ EnableEpochs: EnableEpochs{ - SCDeployEnableEpoch: 1, - BuiltInFunctionsEnableEpoch: 2, - RelayedTransactionsEnableEpoch: 3, - PenalizedTooMuchGasEnableEpoch: 4, - SwitchJailWaitingEnableEpoch: 5, - BelowSignedThresholdEnableEpoch: 6, - SwitchHysteresisForMinNodesEnableEpoch: 7, - TransactionSignedWithTxHashEnableEpoch: 8, - MetaProtectionEnableEpoch: 9, - AheadOfTimeGasUsageEnableEpoch: 10, - GasPriceModifierEnableEpoch: 11, - RepairCallbackEnableEpoch: 12, - BlockGasAndFeesReCheckEnableEpoch: 13, - BalanceWaitingListsEnableEpoch: 14, - ReturnDataToLastTransferEnableEpoch: 15, - SenderInOutTransferEnableEpoch: 16, - StakeEnableEpoch: 17, - StakingV2EnableEpoch: 18, - - DoubleKeyProtectionEnableEpoch: 19, - ESDTEnableEpoch: 20, - GovernanceEnableEpoch: 21, - DelegationManagerEnableEpoch: 22, - DelegationSmartContractEnableEpoch: 23, - CorrectLastUnjailedEnableEpoch: 24, - - RelayedTransactionsV2EnableEpoch: 25, - UnbondTokensV2EnableEpoch: 26, - SaveJailedAlwaysEnableEpoch: 27, - ReDelegateBelowMinCheckEnableEpoch: 28, ValidatorToDelegationEnableEpoch: 29, - + SCDeployEnableEpoch: 1, + BuiltInFunctionsEnableEpoch: 2, + RelayedTransactionsEnableEpoch: 3, + PenalizedTooMuchGasEnableEpoch: 4, + SwitchJailWaitingEnableEpoch: 5, + BelowSignedThresholdEnableEpoch: 6, + SwitchHysteresisForMinNodesEnableEpoch: 7, + TransactionSignedWithTxHashEnableEpoch: 8, + MetaProtectionEnableEpoch: 9, + AheadOfTimeGasUsageEnableEpoch: 10, + GasPriceModifierEnableEpoch: 11, + RepairCallbackEnableEpoch: 12, + BlockGasAndFeesReCheckEnableEpoch: 13, + BalanceWaitingListsEnableEpoch: 14, + ReturnDataToLastTransferEnableEpoch: 15, + SenderInOutTransferEnableEpoch: 16, + StakeEnableEpoch: 17, + StakingV2EnableEpoch: 18, + DoubleKeyProtectionEnableEpoch: 19, + ESDTEnableEpoch: 20, + GovernanceEnableEpoch: 21, + DelegationManagerEnableEpoch: 22, + DelegationSmartContractEnableEpoch: 23, + CorrectLastUnjailedEnableEpoch: 24, + RelayedTransactionsV2EnableEpoch: 25, + UnbondTokensV2EnableEpoch: 26, + SaveJailedAlwaysEnableEpoch: 27, + ReDelegateBelowMinCheckEnableEpoch: 28, + ValidatorToDelegationEnableEpoch: 29, WaitingListFixEnableEpoch: 30, IncrementSCRNonceInMultiTransferEnableEpoch: 31, ESDTMultiTransferEnableEpoch: 32, @@ -895,12 +896,12 @@ func TestEnableEpochConfig(t *testing.T) { StorageAPICostOptimizationEnableEpoch: 54, TransformToMultiShardCreateEnableEpoch: 55, ESDTRegisterAndSetAllRolesEnableEpoch: 56, - ScheduledMiniBlocksEnableEpoch: 57, - CorrectJailedNotUnstakedEmptyQueueEpoch: 58, - DoNotReturnOldBlockInBlockchainHookEnableEpoch: 59, - AddFailedRelayedTxToInvalidMBsDisableEpoch: 60, - SCRSizeInvariantOnBuiltInResultEnableEpoch: 61, - CheckCorrectTokenIDForTransferRoleEnableEpoch: 62, + ScheduledMiniBlocksEnableEpoch: 57, + CorrectJailedNotUnstakedEmptyQueueEpoch: 58, + DoNotReturnOldBlockInBlockchainHookEnableEpoch: 59, + AddFailedRelayedTxToInvalidMBsDisableEpoch: 60, + SCRSizeInvariantOnBuiltInResultEnableEpoch: 61, + CheckCorrectTokenIDForTransferRoleEnableEpoch: 62, DisableExecByCallerEnableEpoch: 63, RefactorContextEnableEpoch: 64, FailExecutionOnEveryAPIErrorEnableEpoch: 65, @@ -910,7 +911,8 @@ func TestEnableEpochConfig(t *testing.T) { ESDTMetadataContinuousCleanupEnableEpoch: 69, MiniBlockPartialExecutionEnableEpoch: 70, FixAsyncCallBackArgsListEnableEpoch: 71, - FixOldTokenLiquidityEnableEpoch: 72,RuntimeMemStoreLimitEnableEpoch: 73, + FixOldTokenLiquidityEnableEpoch: 72, + RuntimeMemStoreLimitEnableEpoch: 73, SetSenderInEeiOutputTransferEnableEpoch: 74, RefactorPeersMiniBlocksEnableEpoch: 75, MaxBlockchainHookCountersEnableEpoch: 76, @@ -926,6 +928,7 @@ func TestEnableEpochConfig(t *testing.T) { ConsistentTokensValuesLengthCheckEnableEpoch: 86, FixDelegationChangeOwnerOnAccountEnableEpoch: 87, ScToScLogEventEnableEpoch: 88, + RelayedTransactionsV3EnableEpoch: 89, MaxNodesChangeEnableEpoch: []MaxNodesChangeConfig{ { EpochEnable: 44, @@ -938,7 +941,7 @@ func TestEnableEpochConfig(t *testing.T) { NodesToShufflePerShard: 80, }, }, - DeterministicSortOnValidatorsInfoEnableEpoch: 66, + DeterministicSortOnValidatorsInfoEnableEpoch: 66, DynamicGasCostForDataTrieStorageLoadEnableEpoch: 64, BLSMultiSignerEnableEpoch: []MultiSignerConfig{ { diff --git a/genesis/process/shardGenesisBlockCreator.go b/genesis/process/shardGenesisBlockCreator.go index 9fef8f05569..a59dbe0ec01 100644 --- a/genesis/process/shardGenesisBlockCreator.go +++ b/genesis/process/shardGenesisBlockCreator.go @@ -149,6 +149,7 @@ func createGenesisConfig() config.EnableEpochs { BLSMultiSignerEnableEpoch: blsMultiSignerEnableEpoch, SetGuardianEnableEpoch: unreachableEpoch, ScToScLogEventEnableEpoch: unreachableEpoch, + RelayedTransactionsV3EnableEpoch: unreachableEpoch, } } diff --git a/go.mod b/go.mod index 8d662778eea..cc3a4b87821 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.6 - github.com/multiversx/mx-chain-core-go v1.2.15 + github.com/multiversx/mx-chain-core-go v1.2.17-0.20230908115059-6ac41d9be0a3 github.com/multiversx/mx-chain-crypto-go v1.2.8 github.com/multiversx/mx-chain-es-indexer-go v1.4.11 github.com/multiversx/mx-chain-logger-go v1.0.13 diff --git a/go.sum b/go.sum index 5ba18f4d2c3..b06538e9266 100644 --- a/go.sum +++ b/go.sum @@ -378,8 +378,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.6 h1:f2bizRoVuJXBWc32px7pCuzMx4Pgi2tKhUt8BkFV1Fg= github.com/multiversx/mx-chain-communication-go v1.0.6/go.mod h1:+oaUowpq+SqrEmAsMPGwhz44g7L81loWb6AiNQU9Ms4= -github.com/multiversx/mx-chain-core-go v1.2.15 h1:2qbcGP9yHi9CFeLF9xTDnDPJjvafvTmwEkitfI0wWME= -github.com/multiversx/mx-chain-core-go v1.2.15/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84= +github.com/multiversx/mx-chain-core-go v1.2.17-0.20230908115059-6ac41d9be0a3 h1:L0csEjkqW/sopOti02NSLMFYgz4f7aW78iQjxRcYLsM= +github.com/multiversx/mx-chain-core-go v1.2.17-0.20230908115059-6ac41d9be0a3/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84= github.com/multiversx/mx-chain-crypto-go v1.2.8 h1:wOgVlUaO5X4L8iEbFjcQcL8SZvv6WZ7LqH73BiRPhxU= github.com/multiversx/mx-chain-crypto-go v1.2.8/go.mod h1:fkaWKp1rbQN9wPKya5jeoRyC+c/SyN/NfggreyeBw+8= github.com/multiversx/mx-chain-es-indexer-go v1.4.11 h1:fL/PdXaUXMt7S12gRvTZKs2dhVOVFm24wUcNTiCYKvM= diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index 99d47fa1fd4..05fdd194e5b 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -3233,6 +3233,7 @@ func CreateEnableEpochsConfig() config.EnableEpochs { MiniBlockPartialExecutionEnableEpoch: UnreachableEpoch, RefactorPeersMiniBlocksEnableEpoch: UnreachableEpoch, SCProcessorV2EnableEpoch: UnreachableEpoch, + RelayedTransactionsV3EnableEpoch: UnreachableEpoch, } } diff --git a/node/metrics/metrics.go b/node/metrics/metrics.go index b9fbae4a2fc..69865832859 100644 --- a/node/metrics/metrics.go +++ b/node/metrics/metrics.go @@ -116,6 +116,7 @@ func InitConfigMetrics( appStatusHandler.SetUInt64Value(common.MetricReturnDataToLastTransferEnableEpoch, uint64(enableEpochs.ReturnDataToLastTransferEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricSenderInOutTransferEnableEpoch, uint64(enableEpochs.SenderInOutTransferEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricRelayedTransactionsV2EnableEpoch, uint64(enableEpochs.RelayedTransactionsV2EnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricRelayedTransactionsV3EnableEpoch, uint64(enableEpochs.RelayedTransactionsV3EnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricUnbondTokensV2EnableEpoch, uint64(enableEpochs.UnbondTokensV2EnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricSaveJailedAlwaysEnableEpoch, uint64(enableEpochs.SaveJailedAlwaysEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricValidatorToDelegationEnableEpoch, uint64(enableEpochs.ValidatorToDelegationEnableEpoch)) diff --git a/node/metrics/metrics_test.go b/node/metrics/metrics_test.go index 54bd966474a..ea5a45ae827 100644 --- a/node/metrics/metrics_test.go +++ b/node/metrics/metrics_test.go @@ -138,6 +138,7 @@ func TestInitConfigMetrics(t *testing.T) { WaitingListFixEnableEpoch: 35, SetGuardianEnableEpoch: 36, ScToScLogEventEnableEpoch: 37, + RelayedTransactionsV3EnableEpoch: 38, MaxNodesChangeEnableEpoch: []config.MaxNodesChangeConfig{ { EpochEnable: 0, @@ -193,6 +194,7 @@ func TestInitConfigMetrics(t *testing.T) { "erd_max_nodes_change_enable_epoch0_nodes_to_shuffle_per_shard": uint32(2), "erd_set_guardian_feature_enable_epoch": uint32(36), "erd_set_sc_to_sc_log_event_enable_epoch": uint32(37), + "erd_relayed_transactions_v3_enable_epoch": uint32(38), } economicsConfig := config.EconomicsConfig{ diff --git a/sharding/mock/enableEpochsHandlerMock.go b/sharding/mock/enableEpochsHandlerMock.go index 1c1c09e3168..f0db31772f9 100644 --- a/sharding/mock/enableEpochsHandlerMock.go +++ b/sharding/mock/enableEpochsHandlerMock.go @@ -628,6 +628,11 @@ func (mock *EnableEpochsHandlerMock) IsDynamicGasCostForDataTrieStorageLoadEnabl return false } +// IsRelayedTransactionsV3FlagEnabled - +func (mock *EnableEpochsHandlerMock) IsRelayedTransactionsV3FlagEnabled() bool { + return false +} + // IsInterfaceNil returns true if there is no value under the interface func (mock *EnableEpochsHandlerMock) IsInterfaceNil() bool { return mock == nil diff --git a/testscommon/enableEpochsHandlerMock/enableEpochsHandlerStub.go b/testscommon/enableEpochsHandlerMock/enableEpochsHandlerStub.go index 6ee0df49d73..83acdd39030 100644 --- a/testscommon/enableEpochsHandlerMock/enableEpochsHandlerStub.go +++ b/testscommon/enableEpochsHandlerMock/enableEpochsHandlerStub.go @@ -129,6 +129,7 @@ type EnableEpochsHandlerStub struct { IsAutoBalanceDataTriesEnabledField bool FixDelegationChangeOwnerOnAccountEnabledField bool IsDynamicGasCostForDataTrieStorageLoadEnabledField bool + IsRelayedTransactionsV3FlagEnabledField bool } // ResetPenalizedTooMuchGasFlag - @@ -1122,6 +1123,14 @@ func (stub *EnableEpochsHandlerStub) FixDelegationChangeOwnerOnAccountEnabled() return stub.FixDelegationChangeOwnerOnAccountEnabledField } +// IsRelayedTransactionsV3FlagEnabled - +func (stub *EnableEpochsHandlerStub) IsRelayedTransactionsV3FlagEnabled() bool { + stub.RLock() + defer stub.RUnlock() + + return stub.IsRelayedTransactionsV3FlagEnabledField +} + // IsInterfaceNil - func (stub *EnableEpochsHandlerStub) IsInterfaceNil() bool { return stub == nil From 96203d78eda3815f7a834d05a2cc0a27b8bd3973 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 8 Sep 2023 15:22:28 +0300 Subject: [PATCH 002/503] updaet mx-chain-core-go --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index cc3a4b87821..c23ed536bfa 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.6 - github.com/multiversx/mx-chain-core-go v1.2.17-0.20230908115059-6ac41d9be0a3 + github.com/multiversx/mx-chain-core-go v1.2.17-0.20230908122056-b0fb32803ee5 github.com/multiversx/mx-chain-crypto-go v1.2.8 github.com/multiversx/mx-chain-es-indexer-go v1.4.11 github.com/multiversx/mx-chain-logger-go v1.0.13 diff --git a/go.sum b/go.sum index b06538e9266..08060584723 100644 --- a/go.sum +++ b/go.sum @@ -378,8 +378,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.6 h1:f2bizRoVuJXBWc32px7pCuzMx4Pgi2tKhUt8BkFV1Fg= github.com/multiversx/mx-chain-communication-go v1.0.6/go.mod h1:+oaUowpq+SqrEmAsMPGwhz44g7L81loWb6AiNQU9Ms4= -github.com/multiversx/mx-chain-core-go v1.2.17-0.20230908115059-6ac41d9be0a3 h1:L0csEjkqW/sopOti02NSLMFYgz4f7aW78iQjxRcYLsM= -github.com/multiversx/mx-chain-core-go v1.2.17-0.20230908115059-6ac41d9be0a3/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84= +github.com/multiversx/mx-chain-core-go v1.2.17-0.20230908122056-b0fb32803ee5 h1:6+/JGirOcH4jT0l1PC5kRLqBt00qSdjgGsQ+GOMyY1M= +github.com/multiversx/mx-chain-core-go v1.2.17-0.20230908122056-b0fb32803ee5/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84= github.com/multiversx/mx-chain-crypto-go v1.2.8 h1:wOgVlUaO5X4L8iEbFjcQcL8SZvv6WZ7LqH73BiRPhxU= github.com/multiversx/mx-chain-crypto-go v1.2.8/go.mod h1:fkaWKp1rbQN9wPKya5jeoRyC+c/SyN/NfggreyeBw+8= github.com/multiversx/mx-chain-es-indexer-go v1.4.11 h1:fL/PdXaUXMt7S12gRvTZKs2dhVOVFm24wUcNTiCYKvM= From a777fac344b11634ea61688bc4bc08ea52e186b8 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 20 Sep 2023 14:44:44 +0300 Subject: [PATCH 003/503] added implementation on processing and interceptor + integration tests + refactor on relayed tests --- api/groups/transactionGroup.go | 5 + go.mod | 2 +- go.sum | 4 +- .../multiShard/relayedTx/common.go | 52 ++ .../multiShard/relayedTx/relayedTxV2_test.go | 104 ---- .../multiShard/relayedTx/relayedTx_test.go | 573 ++++++++++-------- integrationTests/testProcessorNode.go | 1 + node/external/dtos.go | 1 + node/node.go | 30 +- node/node_test.go | 1 + process/constants.go | 2 + process/coordinator/transactionType.go | 13 + process/coordinator/transactionType_test.go | 26 + process/errors.go | 12 + process/transaction/interceptedTransaction.go | 57 +- .../interceptedTransaction_test.go | 74 +++ process/transaction/shardProcess.go | 48 ++ process/transaction/shardProcess_test.go | 186 +++++- 18 files changed, 778 insertions(+), 413 deletions(-) delete mode 100644 integrationTests/multiShard/relayedTx/relayedTxV2_test.go diff --git a/api/groups/transactionGroup.go b/api/groups/transactionGroup.go index 26567186343..abf798a8ab3 100644 --- a/api/groups/transactionGroup.go +++ b/api/groups/transactionGroup.go @@ -176,6 +176,7 @@ type SendTxRequest struct { Options uint32 `json:"options,omitempty"` GuardianAddr string `json:"guardian,omitempty"` GuardianSignature string `json:"guardianSignature,omitempty"` + InnerTransaction []byte `json:"innerTransaction,omitempty"` } // TxResponse represents the structure on which the response will be validated against @@ -233,6 +234,7 @@ func (tg *transactionGroup) simulateTransaction(c *gin.Context) { Options: gtx.Options, Guardian: gtx.GuardianAddr, GuardianSigHex: gtx.GuardianSignature, + InnerTransaction: gtx.InnerTransaction, } start := time.Now() tx, txHash, err := tg.getFacade().CreateTransaction(txArgs) @@ -323,6 +325,7 @@ func (tg *transactionGroup) sendTransaction(c *gin.Context) { Options: gtx.Options, Guardian: gtx.GuardianAddr, GuardianSigHex: gtx.GuardianSignature, + InnerTransaction: gtx.InnerTransaction, } start := time.Now() tx, txHash, err := tg.getFacade().CreateTransaction(txArgs) @@ -421,6 +424,7 @@ func (tg *transactionGroup) sendMultipleTransactions(c *gin.Context) { Options: receivedTx.Options, Guardian: receivedTx.GuardianAddr, GuardianSigHex: receivedTx.GuardianSignature, + InnerTransaction: receivedTx.InnerTransaction, } tx, txHash, err = tg.getFacade().CreateTransaction(txArgs) logging.LogAPIActionDurationIfNeeded(start, "API call: CreateTransaction") @@ -550,6 +554,7 @@ func (tg *transactionGroup) computeTransactionGasLimit(c *gin.Context) { Options: gtx.Options, Guardian: gtx.GuardianAddr, GuardianSigHex: gtx.GuardianSignature, + InnerTransaction: gtx.InnerTransaction, } start := time.Now() tx, _, err := tg.getFacade().CreateTransaction(txArgs) diff --git a/go.mod b/go.mod index c23ed536bfa..d61b73b2348 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.6 - github.com/multiversx/mx-chain-core-go v1.2.17-0.20230908122056-b0fb32803ee5 + github.com/multiversx/mx-chain-core-go v1.2.17-0.20230920100104-d7df5756e9e9 github.com/multiversx/mx-chain-crypto-go v1.2.8 github.com/multiversx/mx-chain-es-indexer-go v1.4.11 github.com/multiversx/mx-chain-logger-go v1.0.13 diff --git a/go.sum b/go.sum index 08060584723..2e7468bb086 100644 --- a/go.sum +++ b/go.sum @@ -378,8 +378,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.6 h1:f2bizRoVuJXBWc32px7pCuzMx4Pgi2tKhUt8BkFV1Fg= github.com/multiversx/mx-chain-communication-go v1.0.6/go.mod h1:+oaUowpq+SqrEmAsMPGwhz44g7L81loWb6AiNQU9Ms4= -github.com/multiversx/mx-chain-core-go v1.2.17-0.20230908122056-b0fb32803ee5 h1:6+/JGirOcH4jT0l1PC5kRLqBt00qSdjgGsQ+GOMyY1M= -github.com/multiversx/mx-chain-core-go v1.2.17-0.20230908122056-b0fb32803ee5/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84= +github.com/multiversx/mx-chain-core-go v1.2.17-0.20230920100104-d7df5756e9e9 h1:a24ecGgx10TSst2HErE4lcxe6NNsAI1OPMyQEMfdHrs= +github.com/multiversx/mx-chain-core-go v1.2.17-0.20230920100104-d7df5756e9e9/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84= github.com/multiversx/mx-chain-crypto-go v1.2.8 h1:wOgVlUaO5X4L8iEbFjcQcL8SZvv6WZ7LqH73BiRPhxU= github.com/multiversx/mx-chain-crypto-go v1.2.8/go.mod h1:fkaWKp1rbQN9wPKya5jeoRyC+c/SyN/NfggreyeBw+8= github.com/multiversx/mx-chain-es-indexer-go v1.4.11 h1:fL/PdXaUXMt7S12gRvTZKs2dhVOVFm24wUcNTiCYKvM= diff --git a/integrationTests/multiShard/relayedTx/common.go b/integrationTests/multiShard/relayedTx/common.go index f875dbb6f8b..766b8e11995 100644 --- a/integrationTests/multiShard/relayedTx/common.go +++ b/integrationTests/multiShard/relayedTx/common.go @@ -96,6 +96,29 @@ func CreateAndSendRelayedAndUserTxV2( return relayedTx } +// CreateAndSendRelayedAndUserTxV3 will create and send a relayed user transaction for relayed v3 +func CreateAndSendRelayedAndUserTxV3( + nodes []*integrationTests.TestProcessorNode, + relayer *integrationTests.TestWalletAccount, + player *integrationTests.TestWalletAccount, + rcvAddr []byte, + value *big.Int, + gasLimit uint64, + txData []byte, +) *transaction.Transaction { + txDispatcherNode := getNodeWithinSameShardAsPlayer(nodes, relayer.Address) + + userTx := createUserTx(player, rcvAddr, value, gasLimit, txData) + relayedTx := createRelayedTxV3(txDispatcherNode.EconomicsData, relayer, userTx) + + _, err := txDispatcherNode.SendTransaction(relayedTx) + if err != nil { + fmt.Println(err.Error()) + } + + return relayedTx +} + func createUserTx( player *integrationTests.TestWalletAccount, rcvAddr []byte, @@ -180,6 +203,35 @@ func createRelayedTxV2( return tx } +func createRelayedTxV3( + economicsFee process.FeeHandler, + relayer *integrationTests.TestWalletAccount, + userTx *transaction.Transaction, +) *transaction.Transaction { + tx := &transaction.Transaction{ + Nonce: relayer.Nonce, + Value: big.NewInt(0).Set(userTx.Value), + RcvAddr: userTx.SndAddr, + SndAddr: relayer.Address, + GasPrice: integrationTests.MinTxGasPrice, + Data: []byte(""), + ChainID: userTx.ChainID, + Version: userTx.Version, + } + gasLimit := economicsFee.ComputeGasLimit(tx) + tx.GasLimit = userTx.GasLimit + gasLimit + + tx.InnerTransaction, _ = integrationTests.TestTxSignMarshalizer.Marshal(userTx) + txBuff, _ := tx.GetDataForSigning(integrationTests.TestAddressPubkeyConverter, integrationTests.TestTxSignMarshalizer, integrationTests.TestTxSignHasher) + tx.Signature, _ = relayer.SingleSigner.Sign(relayer.SkTxSign, txBuff) + relayer.Nonce++ + txFee := economicsFee.ComputeTxFee(tx) + relayer.Balance.Sub(relayer.Balance, txFee) + relayer.Balance.Sub(relayer.Balance, tx.Value) + + return tx +} + func createAndSendSimpleTransaction( nodes []*integrationTests.TestProcessorNode, player *integrationTests.TestWalletAccount, diff --git a/integrationTests/multiShard/relayedTx/relayedTxV2_test.go b/integrationTests/multiShard/relayedTx/relayedTxV2_test.go deleted file mode 100644 index 9e23eeac1aa..00000000000 --- a/integrationTests/multiShard/relayedTx/relayedTxV2_test.go +++ /dev/null @@ -1,104 +0,0 @@ -package relayedTx - -import ( - "encoding/hex" - "math/big" - "testing" - "time" - - "github.com/multiversx/mx-chain-core-go/data/transaction" - "github.com/multiversx/mx-chain-go/integrationTests" - "github.com/multiversx/mx-chain-go/integrationTests/vm/wasm" - vmFactory "github.com/multiversx/mx-chain-go/process/factory" - "github.com/stretchr/testify/assert" -) - -func TestRelayedTransactionV2InMultiShardEnvironmentWithSmartContractTX(t *testing.T) { - if testing.Short() { - t.Skip("this is not a short test") - } - - nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest() - defer func() { - for _, n := range nodes { - n.Close() - } - }() - - sendValue := big.NewInt(5) - round := uint64(0) - nonce := uint64(0) - round = integrationTests.IncrementAndPrintRound(round) - nonce++ - - receiverAddress1 := []byte("12345678901234567890123456789012") - receiverAddress2 := []byte("12345678901234567890123456789011") - - ownerNode := nodes[0] - initialSupply := "00" + hex.EncodeToString(big.NewInt(100000000000).Bytes()) - scCode := wasm.GetSCCode("../../vm/wasm/testdata/erc20-c-03/wrc20_wasm.wasm") - scAddress, _ := ownerNode.BlockchainHook.NewAddress(ownerNode.OwnAccount.Address, ownerNode.OwnAccount.Nonce, vmFactory.WasmVirtualMachine) - - integrationTests.CreateAndSendTransactionWithGasLimit( - nodes[0], - big.NewInt(0), - 20000, - make([]byte, 32), - []byte(wasm.CreateDeployTxData(scCode)+"@"+initialSupply), - integrationTests.ChainID, - integrationTests.MinTransactionVersion, - ) - - transferTokenVMGas := uint64(7200) - transferTokenBaseGas := ownerNode.EconomicsData.ComputeGasLimit(&transaction.Transaction{Data: []byte("transferToken@" + hex.EncodeToString(receiverAddress1) + "@00" + hex.EncodeToString(sendValue.Bytes()))}) - transferTokenFullGas := transferTokenBaseGas + transferTokenVMGas - - initialTokenSupply := big.NewInt(1000000000) - initialPlusForGas := uint64(1000) - for _, player := range players { - integrationTests.CreateAndSendTransactionWithGasLimit( - ownerNode, - big.NewInt(0), - transferTokenFullGas+initialPlusForGas, - scAddress, - []byte("transferToken@"+hex.EncodeToString(player.Address)+"@00"+hex.EncodeToString(initialTokenSupply.Bytes())), - integrationTests.ChainID, - integrationTests.MinTransactionVersion, - ) - } - time.Sleep(time.Second) - - nrRoundsToTest := int64(5) - for i := int64(0); i < nrRoundsToTest; i++ { - round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) - integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) - - for _, player := range players { - _ = CreateAndSendRelayedAndUserTxV2(nodes, relayer, player, scAddress, big.NewInt(0), - transferTokenFullGas, []byte("transferToken@"+hex.EncodeToString(receiverAddress1)+"@00"+hex.EncodeToString(sendValue.Bytes()))) - _ = CreateAndSendRelayedAndUserTxV2(nodes, relayer, player, scAddress, big.NewInt(0), - transferTokenFullGas, []byte("transferToken@"+hex.EncodeToString(receiverAddress2)+"@00"+hex.EncodeToString(sendValue.Bytes()))) - } - - time.Sleep(integrationTests.StepDelay) - } - - roundToPropagateMultiShard := int64(20) - for i := int64(0); i <= roundToPropagateMultiShard; i++ { - round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) - integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) - } - - time.Sleep(time.Second) - - finalBalance := big.NewInt(0).Mul(big.NewInt(int64(len(players))), big.NewInt(nrRoundsToTest)) - finalBalance.Mul(finalBalance, sendValue) - - checkSCBalance(t, ownerNode, scAddress, receiverAddress1, finalBalance) - checkSCBalance(t, ownerNode, scAddress, receiverAddress1, finalBalance) - - checkPlayerBalances(t, nodes, players) - - userAcc := GetUserAccount(nodes, relayer.Address) - assert.Equal(t, 1, userAcc.GetBalance().Cmp(relayer.Balance)) -} diff --git a/integrationTests/multiShard/relayedTx/relayedTx_test.go b/integrationTests/multiShard/relayedTx/relayedTx_test.go index acbdeb9b367..bb5e63422f1 100644 --- a/integrationTests/multiShard/relayedTx/relayedTx_test.go +++ b/integrationTests/multiShard/relayedTx/relayedTx_test.go @@ -21,331 +21,372 @@ import ( "github.com/stretchr/testify/require" ) +type createAndSendRelayedAndUserTxFuncType = func([]*integrationTests.TestProcessorNode, *integrationTests.TestWalletAccount, *integrationTests.TestWalletAccount, []byte, *big.Int, uint64, []byte) *transaction.Transaction + func TestRelayedTransactionInMultiShardEnvironmentWithNormalTx(t *testing.T) { - if testing.Short() { - t.Skip("this is not a short test") - } + t.Run("relayed v1", testRelayedTransactionInMultiShardEnvironmentWithNormalTx(CreateAndSendRelayedAndUserTx)) + t.Run("relayed v3", testRelayedTransactionInMultiShardEnvironmentWithNormalTx(CreateAndSendRelayedAndUserTxV3)) +} - nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest() - defer func() { - for _, n := range nodes { - n.Close() - } - }() +func TestRelayedTransactionInMultiShardEnvironmentWithSmartContractTX(t *testing.T) { + t.Run("relayed v1", testRelayedTransactionInMultiShardEnvironmentWithSmartContractTX(CreateAndSendRelayedAndUserTx)) + t.Run("relayed v2", testRelayedTransactionInMultiShardEnvironmentWithSmartContractTX(CreateAndSendRelayedAndUserTxV2)) + t.Run("relayed v3", testRelayedTransactionInMultiShardEnvironmentWithSmartContractTX(CreateAndSendRelayedAndUserTxV3)) +} - sendValue := big.NewInt(5) - round := uint64(0) - nonce := uint64(0) - round = integrationTests.IncrementAndPrintRound(round) - nonce++ +func TestRelayedTransactionInMultiShardEnvironmentWithESDTTX(t *testing.T) { + t.Run("relayed v1", testRelayedTransactionInMultiShardEnvironmentWithESDTTX(CreateAndSendRelayedAndUserTx)) + t.Run("relayed v2", testRelayedTransactionInMultiShardEnvironmentWithESDTTX(CreateAndSendRelayedAndUserTxV2)) + t.Run("relayed v3", testRelayedTransactionInMultiShardEnvironmentWithESDTTX(CreateAndSendRelayedAndUserTxV3)) +} - receiverAddress1 := []byte("12345678901234567890123456789012") - receiverAddress2 := []byte("12345678901234567890123456789011") +func TestRelayedTransactionInMultiShardEnvironmentWithAttestationContract(t *testing.T) { + t.Run("relayed v1", testRelayedTransactionInMultiShardEnvironmentWithAttestationContract(CreateAndSendRelayedAndUserTx)) + t.Run("relayed v3", testRelayedTransactionInMultiShardEnvironmentWithAttestationContract(CreateAndSendRelayedAndUserTxV3)) +} - nrRoundsToTest := int64(5) - for i := int64(0); i < nrRoundsToTest; i++ { - for _, player := range players { - _ = CreateAndSendRelayedAndUserTx(nodes, relayer, player, receiverAddress1, sendValue, integrationTests.MinTxGasLimit, []byte("")) - _ = CreateAndSendRelayedAndUserTx(nodes, relayer, player, receiverAddress2, sendValue, integrationTests.MinTxGasLimit, []byte("")) +func testRelayedTransactionInMultiShardEnvironmentWithNormalTx( + createAndSendRelayedAndUserTxFunc createAndSendRelayedAndUserTxFuncType, +) func(t *testing.T) { + return func(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") } - round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) - integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) + nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest() + defer func() { + for _, n := range nodes { + n.Close() + } + }() + + sendValue := big.NewInt(5) + round := uint64(0) + nonce := uint64(0) + round = integrationTests.IncrementAndPrintRound(round) + nonce++ + + receiverAddress1 := []byte("12345678901234567890123456789012") + receiverAddress2 := []byte("12345678901234567890123456789011") + + nrRoundsToTest := int64(5) + for i := int64(0); i < nrRoundsToTest; i++ { + for _, player := range players { + _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, receiverAddress1, sendValue, integrationTests.MinTxGasLimit, []byte("")) + _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, receiverAddress2, sendValue, integrationTests.MinTxGasLimit, []byte("")) + } + + round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) + integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) + + time.Sleep(integrationTests.StepDelay) + } - time.Sleep(integrationTests.StepDelay) - } + roundToPropagateMultiShard := int64(20) + for i := int64(0); i <= roundToPropagateMultiShard; i++ { + round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) + integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) + } - roundToPropagateMultiShard := int64(20) - for i := int64(0); i <= roundToPropagateMultiShard; i++ { - round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) - integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) + time.Sleep(time.Second) + receiver1 := GetUserAccount(nodes, receiverAddress1) + receiver2 := GetUserAccount(nodes, receiverAddress2) + + finalBalance := big.NewInt(0).Mul(big.NewInt(int64(len(players))), big.NewInt(nrRoundsToTest)) + finalBalance.Mul(finalBalance, sendValue) + assert.Equal(t, receiver1.GetBalance().Cmp(finalBalance), 0) + assert.Equal(t, receiver2.GetBalance().Cmp(finalBalance), 0) + + players = append(players, relayer) + checkPlayerBalances(t, nodes, players) } +} - time.Sleep(time.Second) - receiver1 := GetUserAccount(nodes, receiverAddress1) - receiver2 := GetUserAccount(nodes, receiverAddress2) +func testRelayedTransactionInMultiShardEnvironmentWithSmartContractTX( + createAndSendRelayedAndUserTxFunc createAndSendRelayedAndUserTxFuncType, +) func(t *testing.T) { + return func(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } - finalBalance := big.NewInt(0).Mul(big.NewInt(int64(len(players))), big.NewInt(nrRoundsToTest)) - finalBalance.Mul(finalBalance, sendValue) - assert.Equal(t, receiver1.GetBalance().Cmp(finalBalance), 0) - assert.Equal(t, receiver2.GetBalance().Cmp(finalBalance), 0) + nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest() + defer func() { + for _, n := range nodes { + n.Close() + } + }() - players = append(players, relayer) - checkPlayerBalances(t, nodes, players) -} + sendValue := big.NewInt(5) + round := uint64(0) + nonce := uint64(0) + round = integrationTests.IncrementAndPrintRound(round) + nonce++ -func TestRelayedTransactionInMultiShardEnvironmentWithSmartContractTX(t *testing.T) { - if testing.Short() { - t.Skip("this is not a short test") - } + receiverAddress1 := []byte("12345678901234567890123456789012") + receiverAddress2 := []byte("12345678901234567890123456789011") + + ownerNode := nodes[0] + initialSupply := "00" + hex.EncodeToString(big.NewInt(100000000000).Bytes()) + scCode := wasm.GetSCCode("../../vm/wasm/testdata/erc20-c-03/wrc20_wasm.wasm") + scAddress, _ := ownerNode.BlockchainHook.NewAddress(ownerNode.OwnAccount.Address, ownerNode.OwnAccount.Nonce, vmFactory.WasmVirtualMachine) - nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest() - defer func() { - for _, n := range nodes { - n.Close() - } - }() - - sendValue := big.NewInt(5) - round := uint64(0) - nonce := uint64(0) - round = integrationTests.IncrementAndPrintRound(round) - nonce++ - - receiverAddress1 := []byte("12345678901234567890123456789012") - receiverAddress2 := []byte("12345678901234567890123456789011") - - ownerNode := nodes[0] - initialSupply := "00" + hex.EncodeToString(big.NewInt(100000000000).Bytes()) - scCode := wasm.GetSCCode("../../vm/wasm/testdata/erc20-c-03/wrc20_wasm.wasm") - scAddress, _ := ownerNode.BlockchainHook.NewAddress(ownerNode.OwnAccount.Address, ownerNode.OwnAccount.Nonce, vmFactory.WasmVirtualMachine) - - integrationTests.CreateAndSendTransactionWithGasLimit( - nodes[0], - big.NewInt(0), - 20000, - make([]byte, 32), - []byte(wasm.CreateDeployTxData(scCode)+"@"+initialSupply), - integrationTests.ChainID, - integrationTests.MinTransactionVersion, - ) - - transferTokenVMGas := uint64(7200) - transferTokenBaseGas := ownerNode.EconomicsData.ComputeGasLimit(&transaction.Transaction{Data: []byte("transferToken@" + hex.EncodeToString(receiverAddress1) + "@00" + hex.EncodeToString(sendValue.Bytes()))}) - transferTokenFullGas := transferTokenBaseGas + transferTokenVMGas - - initialTokenSupply := big.NewInt(1000000000) - initialPlusForGas := uint64(1000) - for _, player := range players { integrationTests.CreateAndSendTransactionWithGasLimit( - ownerNode, + nodes[0], big.NewInt(0), - transferTokenFullGas+initialPlusForGas, - scAddress, - []byte("transferToken@"+hex.EncodeToString(player.Address)+"@00"+hex.EncodeToString(initialTokenSupply.Bytes())), + 20000, + make([]byte, 32), + []byte(wasm.CreateDeployTxData(scCode)+"@"+initialSupply), integrationTests.ChainID, integrationTests.MinTransactionVersion, ) - } - time.Sleep(time.Second) - nrRoundsToTest := int64(5) - for i := int64(0); i < nrRoundsToTest; i++ { - round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) - integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) + transferTokenVMGas := uint64(7200) + transferTokenBaseGas := ownerNode.EconomicsData.ComputeGasLimit(&transaction.Transaction{Data: []byte("transferToken@" + hex.EncodeToString(receiverAddress1) + "@00" + hex.EncodeToString(sendValue.Bytes()))}) + transferTokenFullGas := transferTokenBaseGas + transferTokenVMGas + initialTokenSupply := big.NewInt(1000000000) + initialPlusForGas := uint64(1000) for _, player := range players { - _ = CreateAndSendRelayedAndUserTx(nodes, relayer, player, scAddress, big.NewInt(0), - transferTokenFullGas, []byte("transferToken@"+hex.EncodeToString(receiverAddress1)+"@00"+hex.EncodeToString(sendValue.Bytes()))) - _ = CreateAndSendRelayedAndUserTx(nodes, relayer, player, scAddress, big.NewInt(0), - transferTokenFullGas, []byte("transferToken@"+hex.EncodeToString(receiverAddress2)+"@00"+hex.EncodeToString(sendValue.Bytes()))) + integrationTests.CreateAndSendTransactionWithGasLimit( + ownerNode, + big.NewInt(0), + transferTokenFullGas+initialPlusForGas, + scAddress, + []byte("transferToken@"+hex.EncodeToString(player.Address)+"@00"+hex.EncodeToString(initialTokenSupply.Bytes())), + integrationTests.ChainID, + integrationTests.MinTransactionVersion, + ) } + time.Sleep(time.Second) - time.Sleep(integrationTests.StepDelay) - } + nrRoundsToTest := int64(5) + for i := int64(0); i < nrRoundsToTest; i++ { + round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) + integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) - roundToPropagateMultiShard := int64(20) - for i := int64(0); i <= roundToPropagateMultiShard; i++ { - round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) - integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) - } + for _, player := range players { + _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, scAddress, big.NewInt(0), + transferTokenFullGas, []byte("transferToken@"+hex.EncodeToString(receiverAddress1)+"@00"+hex.EncodeToString(sendValue.Bytes()))) + _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, scAddress, big.NewInt(0), + transferTokenFullGas, []byte("transferToken@"+hex.EncodeToString(receiverAddress2)+"@00"+hex.EncodeToString(sendValue.Bytes()))) + } - time.Sleep(time.Second) + time.Sleep(integrationTests.StepDelay) + } - finalBalance := big.NewInt(0).Mul(big.NewInt(int64(len(players))), big.NewInt(nrRoundsToTest)) - finalBalance.Mul(finalBalance, sendValue) + roundToPropagateMultiShard := int64(20) + for i := int64(0); i <= roundToPropagateMultiShard; i++ { + round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) + integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) + } - checkSCBalance(t, ownerNode, scAddress, receiverAddress1, finalBalance) - checkSCBalance(t, ownerNode, scAddress, receiverAddress1, finalBalance) + time.Sleep(time.Second) - checkPlayerBalances(t, nodes, players) + finalBalance := big.NewInt(0).Mul(big.NewInt(int64(len(players))), big.NewInt(nrRoundsToTest)) + finalBalance.Mul(finalBalance, sendValue) - userAcc := GetUserAccount(nodes, relayer.Address) - assert.Equal(t, userAcc.GetBalance().Cmp(relayer.Balance), 1) -} + checkSCBalance(t, ownerNode, scAddress, receiverAddress1, finalBalance) + checkSCBalance(t, ownerNode, scAddress, receiverAddress1, finalBalance) -func TestRelayedTransactionInMultiShardEnvironmentWithESDTTX(t *testing.T) { - if testing.Short() { - t.Skip("this is not a short test") + checkPlayerBalances(t, nodes, players) + + userAcc := GetUserAccount(nodes, relayer.Address) + assert.Equal(t, 1, userAcc.GetBalance().Cmp(relayer.Balance)) } +} - nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest() - defer func() { - for _, n := range nodes { - n.Close() +func testRelayedTransactionInMultiShardEnvironmentWithESDTTX( + createAndSendRelayedAndUserTxFunc createAndSendRelayedAndUserTxFuncType, +) func(t *testing.T) { + return func(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") } - }() - - sendValue := big.NewInt(5) - round := uint64(0) - nonce := uint64(0) - round = integrationTests.IncrementAndPrintRound(round) - nonce++ - - receiverAddress1 := []byte("12345678901234567890123456789012") - receiverAddress2 := []byte("12345678901234567890123456789011") - - // ------- send token issue - issuePrice := big.NewInt(1000) - initalSupply := big.NewInt(10000000000) - tokenIssuer := nodes[0] - txData := "issue" + - "@" + hex.EncodeToString([]byte("robertWhyNot")) + - "@" + hex.EncodeToString([]byte("RBT")) + - "@" + hex.EncodeToString(initalSupply.Bytes()) + - "@" + hex.EncodeToString([]byte{6}) - integrationTests.CreateAndSendTransaction(tokenIssuer, nodes, issuePrice, vm.ESDTSCAddress, txData, core.MinMetaTxExtraGasCost) - - time.Sleep(time.Second) - nrRoundsToPropagateMultiShard := int64(10) - for i := int64(0); i < nrRoundsToPropagateMultiShard; i++ { - round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) - integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) - time.Sleep(integrationTests.StepDelay) - } - time.Sleep(time.Second) - tokenIdenfitifer := string(integrationTests.GetTokenIdentifier(nodes, []byte("RBT"))) - CheckAddressHasTokens(t, tokenIssuer.OwnAccount.Address, nodes, tokenIdenfitifer, initalSupply) + nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest() + defer func() { + for _, n := range nodes { + n.Close() + } + }() + + sendValue := big.NewInt(5) + round := uint64(0) + nonce := uint64(0) + round = integrationTests.IncrementAndPrintRound(round) + nonce++ + + receiverAddress1 := []byte("12345678901234567890123456789012") + receiverAddress2 := []byte("12345678901234567890123456789011") + + // ------- send token issue + issuePrice := big.NewInt(1000) + initalSupply := big.NewInt(10000000000) + tokenIssuer := nodes[0] + txData := "issue" + + "@" + hex.EncodeToString([]byte("robertWhyNot")) + + "@" + hex.EncodeToString([]byte("RBT")) + + "@" + hex.EncodeToString(initalSupply.Bytes()) + + "@" + hex.EncodeToString([]byte{6}) + integrationTests.CreateAndSendTransaction(tokenIssuer, nodes, issuePrice, vm.ESDTSCAddress, txData, core.MinMetaTxExtraGasCost) + + time.Sleep(time.Second) + nrRoundsToPropagateMultiShard := int64(10) + for i := int64(0); i < nrRoundsToPropagateMultiShard; i++ { + round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) + integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) + time.Sleep(integrationTests.StepDelay) + } + time.Sleep(time.Second) - // ------ send tx to players - valueToTopUp := big.NewInt(100000000) - txData = core.BuiltInFunctionESDTTransfer + "@" + hex.EncodeToString([]byte(tokenIdenfitifer)) + "@" + hex.EncodeToString(valueToTopUp.Bytes()) - for _, player := range players { - integrationTests.CreateAndSendTransaction(tokenIssuer, nodes, big.NewInt(0), player.Address, txData, integrationTests.AdditionalGasLimit) - } + tokenIdenfitifer := string(integrationTests.GetTokenIdentifier(nodes, []byte("RBT"))) + CheckAddressHasTokens(t, tokenIssuer.OwnAccount.Address, nodes, tokenIdenfitifer, initalSupply) - time.Sleep(time.Second) - for i := int64(0); i < nrRoundsToPropagateMultiShard; i++ { - round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) - integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) - time.Sleep(integrationTests.StepDelay) - } - time.Sleep(time.Second) - - txData = core.BuiltInFunctionESDTTransfer + "@" + hex.EncodeToString([]byte(tokenIdenfitifer)) + "@" + hex.EncodeToString(sendValue.Bytes()) - transferTokenESDTGas := uint64(1) - transferTokenBaseGas := tokenIssuer.EconomicsData.ComputeGasLimit(&transaction.Transaction{Data: []byte(txData)}) - transferTokenFullGas := transferTokenBaseGas + transferTokenESDTGas + uint64(100) // use more gas to simulate gas refund - nrRoundsToTest := int64(5) - for i := int64(0); i < nrRoundsToTest; i++ { + // ------ send tx to players + valueToTopUp := big.NewInt(100000000) + txData = core.BuiltInFunctionESDTTransfer + "@" + hex.EncodeToString([]byte(tokenIdenfitifer)) + "@" + hex.EncodeToString(valueToTopUp.Bytes()) for _, player := range players { - _ = CreateAndSendRelayedAndUserTx(nodes, relayer, player, receiverAddress1, big.NewInt(0), transferTokenFullGas, []byte(txData)) - _ = CreateAndSendRelayedAndUserTx(nodes, relayer, player, receiverAddress2, big.NewInt(0), transferTokenFullGas, []byte(txData)) + integrationTests.CreateAndSendTransaction(tokenIssuer, nodes, big.NewInt(0), player.Address, txData, integrationTests.AdditionalGasLimit) } - round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) - integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) + time.Sleep(time.Second) + for i := int64(0); i < nrRoundsToPropagateMultiShard; i++ { + round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) + integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) + time.Sleep(integrationTests.StepDelay) + } + time.Sleep(time.Second) + + txData = core.BuiltInFunctionESDTTransfer + "@" + hex.EncodeToString([]byte(tokenIdenfitifer)) + "@" + hex.EncodeToString(sendValue.Bytes()) + transferTokenESDTGas := uint64(1) + transferTokenBaseGas := tokenIssuer.EconomicsData.ComputeGasLimit(&transaction.Transaction{Data: []byte(txData)}) + transferTokenFullGas := transferTokenBaseGas + transferTokenESDTGas + uint64(100) // use more gas to simulate gas refund + nrRoundsToTest := int64(5) + for i := int64(0); i < nrRoundsToTest; i++ { + for _, player := range players { + _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, receiverAddress1, big.NewInt(0), transferTokenFullGas, []byte(txData)) + _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, receiverAddress2, big.NewInt(0), transferTokenFullGas, []byte(txData)) + } + + round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) + integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) + + time.Sleep(integrationTests.StepDelay) + } - time.Sleep(integrationTests.StepDelay) - } + nrRoundsToPropagateMultiShard = int64(20) + for i := int64(0); i <= nrRoundsToPropagateMultiShard; i++ { + round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) + integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) + } - nrRoundsToPropagateMultiShard = int64(20) - for i := int64(0); i <= nrRoundsToPropagateMultiShard; i++ { - round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) - integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) + time.Sleep(time.Second) + finalBalance := big.NewInt(0).Mul(big.NewInt(int64(len(players))), big.NewInt(nrRoundsToTest)) + finalBalance.Mul(finalBalance, sendValue) + CheckAddressHasTokens(t, receiverAddress1, nodes, tokenIdenfitifer, finalBalance) + CheckAddressHasTokens(t, receiverAddress2, nodes, tokenIdenfitifer, finalBalance) + + players = append(players, relayer) + checkPlayerBalances(t, nodes, players) } +} - time.Sleep(time.Second) - finalBalance := big.NewInt(0).Mul(big.NewInt(int64(len(players))), big.NewInt(nrRoundsToTest)) - finalBalance.Mul(finalBalance, sendValue) - CheckAddressHasTokens(t, receiverAddress1, nodes, tokenIdenfitifer, finalBalance) - CheckAddressHasTokens(t, receiverAddress2, nodes, tokenIdenfitifer, finalBalance) +func testRelayedTransactionInMultiShardEnvironmentWithAttestationContract( + createAndSendRelayedAndUserTxFunc createAndSendRelayedAndUserTxFuncType, +) func(t *testing.T) { + return func(t *testing.T) { - players = append(players, relayer) - checkPlayerBalances(t, nodes, players) -} + if testing.Short() { + t.Skip("this is not a short test") + } -func TestRelayedTransactionInMultiShardEnvironmentWithAttestationContract(t *testing.T) { - if testing.Short() { - t.Skip("this is not a short test") - } + nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest() + defer func() { + for _, n := range nodes { + n.Close() + } + }() - nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest() - defer func() { - for _, n := range nodes { - n.Close() + for _, node := range nodes { + node.EconomicsData.SetMaxGasLimitPerBlock(1500000000) } - }() - for _, node := range nodes { - node.EconomicsData.SetMaxGasLimitPerBlock(1500000000) - } + round := uint64(0) + nonce := uint64(0) + round = integrationTests.IncrementAndPrintRound(round) + nonce++ - round := uint64(0) - nonce := uint64(0) - round = integrationTests.IncrementAndPrintRound(round) - nonce++ - - ownerNode := nodes[0] - scCode := wasm.GetSCCode("attestation.wasm") - scAddress, _ := ownerNode.BlockchainHook.NewAddress(ownerNode.OwnAccount.Address, ownerNode.OwnAccount.Nonce, vmFactory.WasmVirtualMachine) - - registerValue := big.NewInt(100) - integrationTests.CreateAndSendTransactionWithGasLimit( - nodes[0], - big.NewInt(0), - 200000, - make([]byte, 32), - []byte(wasm.CreateDeployTxData(scCode)+"@"+hex.EncodeToString(registerValue.Bytes())+"@"+hex.EncodeToString(relayer.Address)+"@"+"ababab"), - integrationTests.ChainID, - integrationTests.MinTransactionVersion, - ) - time.Sleep(time.Second) - - registerVMGas := uint64(100000) - savePublicInfoVMGas := uint64(100000) - attestVMGas := uint64(100000) - - round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) - integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) - - uniqueIDs := make([]string, len(players)) - for i, player := range players { - uniqueIDs[i] = core.UniqueIdentifier() - _ = CreateAndSendRelayedAndUserTx(nodes, relayer, player, scAddress, registerValue, - registerVMGas, []byte("register@"+hex.EncodeToString([]byte(uniqueIDs[i])))) - } - time.Sleep(time.Second) + ownerNode := nodes[0] + scCode := wasm.GetSCCode("attestation.wasm") + scAddress, _ := ownerNode.BlockchainHook.NewAddress(ownerNode.OwnAccount.Address, ownerNode.OwnAccount.Nonce, vmFactory.WasmVirtualMachine) - nrRoundsToPropagateMultiShard := int64(10) - for i := int64(0); i <= nrRoundsToPropagateMultiShard; i++ { - round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) - integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) - } + registerValue := big.NewInt(100) + integrationTests.CreateAndSendTransactionWithGasLimit( + nodes[0], + big.NewInt(0), + 200000, + make([]byte, 32), + []byte(wasm.CreateDeployTxData(scCode)+"@"+hex.EncodeToString(registerValue.Bytes())+"@"+hex.EncodeToString(relayer.Address)+"@"+"ababab"), + integrationTests.ChainID, + integrationTests.MinTransactionVersion, + ) + time.Sleep(time.Second) - cryptoHook := hooks.NewVMCryptoHook() - privateInfos := make([]string, len(players)) - for i := range players { - privateInfos[i] = core.UniqueIdentifier() - publicInfo, _ := cryptoHook.Keccak256([]byte(privateInfos[i])) - createAndSendSimpleTransaction(nodes, relayer, scAddress, big.NewInt(0), savePublicInfoVMGas, - []byte("savePublicInfo@"+hex.EncodeToString([]byte(uniqueIDs[i]))+"@"+hex.EncodeToString(publicInfo))) - } - time.Sleep(time.Second) + registerVMGas := uint64(100000) + savePublicInfoVMGas := uint64(100000) + attestVMGas := uint64(100000) - nrRoundsToPropagate := int64(5) - for i := int64(0); i <= nrRoundsToPropagate; i++ { round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) - } - for i, player := range players { - _ = CreateAndSendRelayedAndUserTx(nodes, relayer, player, scAddress, big.NewInt(0), attestVMGas, - []byte("attest@"+hex.EncodeToString([]byte(uniqueIDs[i]))+"@"+hex.EncodeToString([]byte(privateInfos[i])))) - _ = CreateAndSendRelayedAndUserTx(nodes, relayer, player, scAddress, registerValue, - registerVMGas, []byte("register@"+hex.EncodeToString([]byte(uniqueIDs[i])))) - } - time.Sleep(time.Second) + uniqueIDs := make([]string, len(players)) + for i, player := range players { + uniqueIDs[i] = core.UniqueIdentifier() + _ = CreateAndSendRelayedAndUserTx(nodes, relayer, player, scAddress, registerValue, + registerVMGas, []byte("register@"+hex.EncodeToString([]byte(uniqueIDs[i])))) + } + time.Sleep(time.Second) - nrRoundsToPropagateMultiShard = int64(20) - for i := int64(0); i <= nrRoundsToPropagateMultiShard; i++ { - round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) - integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) - } + nrRoundsToPropagateMultiShard := int64(10) + for i := int64(0); i <= nrRoundsToPropagateMultiShard; i++ { + round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) + integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) + } + + cryptoHook := hooks.NewVMCryptoHook() + privateInfos := make([]string, len(players)) + for i := range players { + privateInfos[i] = core.UniqueIdentifier() + publicInfo, _ := cryptoHook.Keccak256([]byte(privateInfos[i])) + createAndSendSimpleTransaction(nodes, relayer, scAddress, big.NewInt(0), savePublicInfoVMGas, + []byte("savePublicInfo@"+hex.EncodeToString([]byte(uniqueIDs[i]))+"@"+hex.EncodeToString(publicInfo))) + } + time.Sleep(time.Second) + + nrRoundsToPropagate := int64(5) + for i := int64(0); i <= nrRoundsToPropagate; i++ { + round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) + integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) + } - for i, player := range players { - checkAttestedPublicKeys(t, ownerNode, scAddress, []byte(uniqueIDs[i]), player.Address) + for i, player := range players { + _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, scAddress, big.NewInt(0), attestVMGas, + []byte("attest@"+hex.EncodeToString([]byte(uniqueIDs[i]))+"@"+hex.EncodeToString([]byte(privateInfos[i])))) + _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, scAddress, registerValue, + registerVMGas, []byte("register@"+hex.EncodeToString([]byte(uniqueIDs[i])))) + } + time.Sleep(time.Second) + + nrRoundsToPropagateMultiShard = int64(20) + for i := int64(0); i <= nrRoundsToPropagateMultiShard; i++ { + round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) + integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) + } + + for i, player := range players { + checkAttestedPublicKeys(t, ownerNode, scAddress, []byte(uniqueIDs[i]), player.Address) + } } } diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index 05fdd194e5b..2c4793f9c37 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -2586,6 +2586,7 @@ func (tpn *TestProcessorNode) SendTransaction(tx *dataTransaction.Transaction) ( Options: tx.Options, Guardian: guardianAddress, GuardianSigHex: hex.EncodeToString(tx.GuardianSignature), + InnerTransaction: tx.InnerTransaction, } tx, txHash, err := tpn.Node.CreateTransaction(createTxArgs) if err != nil { diff --git a/node/external/dtos.go b/node/external/dtos.go index f884d8d32c9..e8e43e784a0 100644 --- a/node/external/dtos.go +++ b/node/external/dtos.go @@ -17,4 +17,5 @@ type ArgsCreateTransaction struct { Options uint32 Guardian string GuardianSigHex string + InnerTransaction []byte } diff --git a/node/node.go b/node/node.go index e02f84be2cb..969c865b6c7 100644 --- a/node/node.go +++ b/node/node.go @@ -54,7 +54,8 @@ var log = logger.GetOrCreate("node") var _ facade.NodeHandler = (*Node)(nil) // Option represents a functional configuration parameter that can operate -// over the None struct. +// +// over the None struct. type Option func(*Node) error type filter interface { @@ -869,19 +870,20 @@ func (n *Node) CreateTransaction(txArgs *external.ArgsCreateTransaction) (*trans } tx := &transaction.Transaction{ - Nonce: txArgs.Nonce, - Value: valAsBigInt, - RcvAddr: receiverAddress, - RcvUserName: txArgs.ReceiverUsername, - SndAddr: senderAddress, - SndUserName: txArgs.SenderUsername, - GasPrice: txArgs.GasPrice, - GasLimit: txArgs.GasLimit, - Data: txArgs.DataField, - Signature: signatureBytes, - ChainID: []byte(txArgs.ChainID), - Version: txArgs.Version, - Options: txArgs.Options, + Nonce: txArgs.Nonce, + Value: valAsBigInt, + RcvAddr: receiverAddress, + RcvUserName: txArgs.ReceiverUsername, + SndAddr: senderAddress, + SndUserName: txArgs.SenderUsername, + GasPrice: txArgs.GasPrice, + GasLimit: txArgs.GasLimit, + Data: txArgs.DataField, + Signature: signatureBytes, + ChainID: []byte(txArgs.ChainID), + Version: txArgs.Version, + Options: txArgs.Options, + InnerTransaction: txArgs.InnerTransaction, } if len(txArgs.Guardian) > 0 { diff --git a/node/node_test.go b/node/node_test.go index 7a86514150b..b59ade01fc6 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -1862,6 +1862,7 @@ func getDefaultTransactionArgs() *external.ArgsCreateTransaction { Options: 0, Guardian: "", GuardianSigHex: "", + InnerTransaction: nil, } } diff --git a/process/constants.go b/process/constants.go index f75e7b882ee..4930f427615 100644 --- a/process/constants.go +++ b/process/constants.go @@ -36,6 +36,8 @@ const ( RelayedTx // RelayedTxV2 defines the ID of a slim relayed transaction version RelayedTxV2 + // RelayedTxV3 defines the ID of a relayed v3 transaction + RelayedTxV3 // RewardTx defines ID of a reward transaction RewardTx // InvalidTransaction defines unknown transaction type diff --git a/process/coordinator/transactionType.go b/process/coordinator/transactionType.go index 05ce1065748..071846e9ce1 100644 --- a/process/coordinator/transactionType.go +++ b/process/coordinator/transactionType.go @@ -85,6 +85,10 @@ func (tth *txTypeHandler) ComputeTransactionType(tx data.TransactionHandler) (pr return process.InvalidTransaction, process.InvalidTransaction } + if tth.isRelayedTransactionV3(tx) { + return process.RelayedTxV3, process.RelayedTxV3 + } + if len(tx.GetData()) == 0 { return process.MoveBalance, process.MoveBalance } @@ -185,6 +189,15 @@ func (tth *txTypeHandler) isRelayedTransactionV2(functionName string) bool { return functionName == core.RelayedTransactionV2 } +func (tth *txTypeHandler) isRelayedTransactionV3(tx data.TransactionHandler) bool { + rtx, ok := tx.(data.RelayedV3TransactionHandler) + if !ok { + return false + } + + return len(rtx.GetInnerTransaction()) > 0 +} + func (tth *txTypeHandler) isDestAddressEmpty(tx data.TransactionHandler) bool { isEmptyAddress := bytes.Equal(tx.GetRcvAddr(), make([]byte, tth.pubkeyConv.Len())) return isEmptyAddress diff --git a/process/coordinator/transactionType_test.go b/process/coordinator/transactionType_test.go index b1e6450a041..48ddc97efdd 100644 --- a/process/coordinator/transactionType_test.go +++ b/process/coordinator/transactionType_test.go @@ -444,6 +444,32 @@ func TestTxTypeHandler_ComputeTransactionTypeRelayedV2Func(t *testing.T) { assert.Equal(t, process.RelayedTxV2, txTypeCross) } +func TestTxTypeHandler_ComputeTransactionTypeRelayedV3(t *testing.T) { + t.Parallel() + + tx := &transaction.Transaction{} + tx.Nonce = 0 + tx.SndAddr = []byte("000") + tx.RcvAddr = []byte("001") + tx.Value = big.NewInt(45) + tx.InnerTransaction = []byte("some inner tx") + + arg := createMockArguments() + arg.PubkeyConverter = &testscommon.PubkeyConverterStub{ + LenCalled: func() int { + return len(tx.RcvAddr) + }, + } + tth, err := NewTxTypeHandler(arg) + + assert.NotNil(t, tth) + assert.Nil(t, err) + + txTypeIn, txTypeCross := tth.ComputeTransactionType(tx) + assert.Equal(t, process.RelayedTxV3, txTypeIn) + assert.Equal(t, process.RelayedTxV3, txTypeCross) +} + func TestTxTypeHandler_ComputeTransactionTypeForSCRCallBack(t *testing.T) { t.Parallel() diff --git a/process/errors.go b/process/errors.go index 3df1eb3bcf2..96df6c37124 100644 --- a/process/errors.go +++ b/process/errors.go @@ -1223,3 +1223,15 @@ var ErrNilManagedPeersHolder = errors.New("nil managed peers holder") // ErrNilStorageService signals that a nil storage service has been provided var ErrNilStorageService = errors.New("nil storage service") + +// ErrRelayedV3GasPriceMismatch signals that relayed v3 gas price is not equal with inner tx +var ErrRelayedV3GasPriceMismatch = errors.New("relayed v3 gas price mismatch") + +// ErrRelayedTxV3BeneficiaryDoesNotMatchReceiver signals that an invalid address was provided in the relayed tx v3 +var ErrRelayedTxV3BeneficiaryDoesNotMatchReceiver = errors.New("invalid address in relayed tx v3") + +// ErrRelayedTxV3Disabled signals that the v3 version of relayed tx is disabled +var ErrRelayedTxV3Disabled = errors.New("relayed tx v3 is disabled") + +// ErrRelayedTxV3GasLimitLowerThanInnerTx signals that the relayed tx v3 has a lower gas limit than one of the inner txs +var ErrRelayedTxV3GasLimitLowerThanInnerTx = errors.New("relayed tx v3 gas limit should be less than inner tx") diff --git a/process/transaction/interceptedTransaction.go b/process/transaction/interceptedTransaction.go index 0aedf837d09..6e2584bb78e 100644 --- a/process/transaction/interceptedTransaction.go +++ b/process/transaction/interceptedTransaction.go @@ -199,51 +199,62 @@ func (inTx *InterceptedTransaction) CheckValidity() error { return err } + err = inTx.verifyIfRelayedTxV3(inTx.tx) + if err != nil { + return err + } + inTx.whiteListerVerifiedTxs.Add([][]byte{inTx.Hash()}) } return nil } -func isRelayedTx(funcName string) bool { - return core.RelayedTransaction == funcName || core.RelayedTransactionV2 == funcName +func isRelayedTx(funcName string, innerTx []byte) bool { + return core.RelayedTransaction == funcName || + core.RelayedTransactionV2 == funcName || + len(innerTx) > 0 } -func (inTx *InterceptedTransaction) verifyIfRelayedTxV2(tx *transaction.Transaction) error { - funcName, userTxArgs, err := inTx.argsParser.ParseCallData(string(tx.Data)) - if err != nil { - return nil - } - if core.RelayedTransactionV2 != funcName { +func (inTx *InterceptedTransaction) verifyIfRelayedTxV3(tx *transaction.Transaction) error { + if len(tx.InnerTransaction) == 0 { return nil } - userTx, err := createRelayedV2(tx, userTxArgs) + innerTx := &transaction.Transaction{} + err := inTx.signMarshalizer.Unmarshal(innerTx, tx.InnerTransaction) if err != nil { return err } - err = inTx.verifySig(userTx) + err = inTx.integrity(innerTx) if err != nil { return fmt.Errorf("inner transaction: %w", err) } - err = inTx.VerifyGuardianSig(userTx) + err = inTx.verifyUserTx(innerTx) if err != nil { return fmt.Errorf("inner transaction: %w", err) } - funcName, _, err = inTx.argsParser.ParseCallData(string(userTx.Data)) + return nil +} + +func (inTx *InterceptedTransaction) verifyIfRelayedTxV2(tx *transaction.Transaction) error { + funcName, userTxArgs, err := inTx.argsParser.ParseCallData(string(tx.Data)) if err != nil { return nil } + if core.RelayedTransactionV2 != funcName { + return nil + } - // recursive relayed transactions are not allowed - if isRelayedTx(funcName) { - return process.ErrRecursiveRelayedTxIsNotAllowed + userTx, err := createRelayedV2(tx, userTxArgs) + if err != nil { + return err } - return nil + return inTx.verifyUserTx(userTx) } func (inTx *InterceptedTransaction) verifyIfRelayedTx(tx *transaction.Transaction) error { @@ -273,7 +284,11 @@ func (inTx *InterceptedTransaction) verifyIfRelayedTx(tx *transaction.Transactio return fmt.Errorf("inner transaction: %w", err) } - err = inTx.verifySig(userTx) + return inTx.verifyUserTx(userTx) +} + +func (inTx *InterceptedTransaction) verifyUserTx(userTx *transaction.Transaction) error { + err := inTx.verifySig(userTx) if err != nil { return fmt.Errorf("inner transaction: %w", err) } @@ -283,17 +298,13 @@ func (inTx *InterceptedTransaction) verifyIfRelayedTx(tx *transaction.Transactio return fmt.Errorf("inner transaction: %w", err) } - if len(userTx.Data) == 0 { - return nil - } - - funcName, _, err = inTx.argsParser.ParseCallData(string(userTx.Data)) + funcName, _, err := inTx.argsParser.ParseCallData(string(userTx.Data)) if err != nil { return nil } // recursive relayed transactions are not allowed - if isRelayedTx(funcName) { + if isRelayedTx(funcName, userTx.InnerTransaction) { return process.ErrRecursiveRelayedTxIsNotAllowed } diff --git a/process/transaction/interceptedTransaction_test.go b/process/transaction/interceptedTransaction_test.go index b2aa2e81526..bd4145e9e08 100644 --- a/process/transaction/interceptedTransaction_test.go +++ b/process/transaction/interceptedTransaction_test.go @@ -1497,6 +1497,80 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV2(t *testing.T) { assert.Nil(t, err) } +func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { + t.Parallel() + + minTxVersion := uint32(1) + chainID := []byte("chain") + innerTx := &dataTransaction.Transaction{ + Nonce: 1, + Value: big.NewInt(2), + Data: []byte("data inner tx 1"), + GasLimit: 3, + GasPrice: 4, + RcvAddr: recvAddress, + SndAddr: senderAddress, + Signature: sigOk, + ChainID: chainID, + Version: minTxVersion, + } + marshaller := &mock.MarshalizerMock{} + innerTxBuff, err := marshaller.Marshal(innerTx) + assert.Nil(t, err) + + tx := &dataTransaction.Transaction{ + Nonce: 1, + Value: big.NewInt(0), + GasLimit: 10, + GasPrice: 4, + RcvAddr: recvAddress, + SndAddr: senderAddress, + Signature: sigOk, + ChainID: chainID, + Version: minTxVersion, + InnerTransaction: innerTxBuff, + } + txi, _ := createInterceptedTxFromPlainTxWithArgParser(tx) + err = txi.CheckValidity() + assert.Nil(t, err) + + innerTx.Signature = nil + tx.InnerTransaction, err = marshaller.Marshal(innerTx) + assert.Nil(t, err) + txi, _ = createInterceptedTxFromPlainTxWithArgParser(tx) + err = txi.CheckValidity() + assert.NotNil(t, err) + + innerTx.Signature = sigBad + tx.InnerTransaction, err = marshaller.Marshal(innerTx) + assert.Nil(t, err) + txi, _ = createInterceptedTxFromPlainTxWithArgParser(tx) + err = txi.CheckValidity() + assert.NotNil(t, err) + + innerTx2 := &dataTransaction.Transaction{ + Nonce: 2, + Value: big.NewInt(3), + Data: []byte("data inner tx 2"), + GasLimit: 3, + GasPrice: 4, + RcvAddr: recvAddress, + SndAddr: senderAddress, + Signature: sigOk, + ChainID: chainID, + Version: minTxVersion, + } + innerTx2Buff, err := marshaller.Marshal(innerTx2) + assert.Nil(t, err) + innerTx.InnerTransaction, err = marshaller.Marshal(innerTx2Buff) + assert.Nil(t, err) + tx.InnerTransaction, err = marshaller.Marshal(innerTx) + assert.Nil(t, err) + txi, _ = createInterceptedTxFromPlainTxWithArgParser(tx) + err = txi.CheckValidity() + assert.NotNil(t, err) +} + // ------- IsInterfaceNil func TestInterceptedTransaction_IsInterfaceNil(t *testing.T) { t.Parallel() diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index ea8eb375c56..1f4d57b1fe4 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -228,6 +228,8 @@ func (txProc *txProcessor) ProcessTransaction(tx *transaction.Transaction) (vmco return txProc.processRelayedTx(tx, acntSnd, acntDst) case process.RelayedTxV2: return txProc.processRelayedTxV2(tx, acntSnd, acntDst) + case process.RelayedTxV3: + return txProc.processRelayedTxV3(tx, acntSnd, acntDst) } return vmcommon.UserError, txProc.executingFailedTransaction(tx, acntSnd, process.ErrWrongTransaction) @@ -612,6 +614,34 @@ func (txProc *txProcessor) addFeeAndValueToDest(acntDst state.UserAccountHandler return txProc.accounts.SaveAccount(acntDst) } +func (txProc *txProcessor) processRelayedTxV3( + tx *transaction.Transaction, + relayerAcnt, acntDst state.UserAccountHandler, +) (vmcommon.ReturnCode, error) { + if !txProc.enableEpochsHandler.IsRelayedTransactionsV3FlagEnabled() { + return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedTxV3Disabled) + } + + innerTx := &transaction.Transaction{} + innerTxBuff := tx.GetInnerTransaction() + err := txProc.signMarshalizer.Unmarshal(innerTx, innerTxBuff) + if err != nil { + return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, err) + } + + if !bytes.Equal(tx.RcvAddr, innerTx.SndAddr) { + return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedTxV3BeneficiaryDoesNotMatchReceiver) + } + if tx.GasPrice != innerTx.GasPrice { + return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedV3GasPriceMismatch) + } + if tx.GasLimit < innerTx.GasLimit { + return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedTxV3GasLimitLowerThanInnerTx) + } + + return txProc.finishExecutionOfRelayedTx(relayerAcnt, acntDst, tx, innerTx) +} + func (txProc *txProcessor) processRelayedTxV2( tx *transaction.Transaction, relayerAcnt, acntDst state.UserAccountHandler, @@ -693,6 +723,24 @@ func (txProc *txProcessor) computeRelayedTxFees(tx *transaction.Transaction) rel return computedFees } +func (txProc *txProcessor) computeRelayedV3TxFees(tx *transaction.Transaction, innerTxs []*transaction.Transaction) relayedFees { + relayerFee := txProc.economicsFee.ComputeMoveBalanceFee(tx) + totalFee := big.NewInt(0) + for _, innerTx := range innerTxs { + innerFee := txProc.economicsFee.ComputeTxFee(innerTx) + totalFee.Add(totalFee, innerFee) + } + remainingFee := big.NewInt(0).Sub(totalFee, relayerFee) + + computedFees := relayedFees{ + totalFee: totalFee, + remainingFee: remainingFee, + relayerFee: relayerFee, + } + + return computedFees +} + func (txProc *txProcessor) removeValueAndConsumedFeeFromUser( userTx *transaction.Transaction, relayedTxValue *big.Int, diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index b17c99e3f0b..0cd26fa73b5 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -90,9 +90,9 @@ func createArgsForTxProcessor() txproc.ArgsNewTxProcessor { EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{ IsPenalizedTooMuchGasFlagEnabledField: true, }, - GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, - TxVersionChecker: &testscommon.TxVersionCheckerStub{}, - TxLogsProcessor: &mock.TxLogsProcessorStub{}, + GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, + TxVersionChecker: &testscommon.TxVersionCheckerStub{}, + TxLogsProcessor: &mock.TxLogsProcessorStub{}, EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, } return args @@ -2019,6 +2019,186 @@ func TestTxProcessor_ProcessRelayedTransactionV2(t *testing.T) { assert.Equal(t, vmcommon.Ok, returnCode) } +func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { + t.Parallel() + + marshaller := &mock.MarshalizerMock{} + + userAddr := []byte("user") + tx := &transaction.Transaction{} + tx.Nonce = 0 + tx.SndAddr = []byte("sSRC") + tx.RcvAddr = userAddr + tx.Value = big.NewInt(0) + tx.GasPrice = 1 + tx.GasLimit = 4 + + userTx := &transaction.Transaction{} + userTx.Nonce = 0 + userTx.SndAddr = userAddr + userTx.RcvAddr = []byte("sDST") + userTx.Value = big.NewInt(0) + userTx.Data = []byte("execute@param1") + userTx.GasPrice = 1 + userTx.GasLimit = 2 + + tx.InnerTransaction, _ = marshaller.Marshal(userTx) + + t.Run("flag not active should error", func(t *testing.T) { + t.Parallel() + + pubKeyConverter := testscommon.NewPubkeyConverterMock(4) + acntSrc := createUserAcc(tx.SndAddr) + _ = acntSrc.AddToBalance(big.NewInt(100)) + acntDst := createUserAcc(tx.RcvAddr) + _ = acntDst.AddToBalance(big.NewInt(10)) + + acntFinal := createUserAcc(userTx.RcvAddr) + _ = acntFinal.AddToBalance(big.NewInt(10)) + + adb := &stateMock.AccountsStub{} + adb.LoadAccountCalled = func(address []byte) (vmcommon.AccountHandler, error) { + if bytes.Equal(address, tx.SndAddr) { + return acntSrc, nil + } + if bytes.Equal(address, tx.RcvAddr) { + return acntDst, nil + } + if bytes.Equal(address, userTx.RcvAddr) { + return acntFinal, nil + } + + return nil, errors.New("failure") + } + + scProcessorMock := &testscommon.SCProcessorMock{} + shardC, _ := sharding.NewMultiShardCoordinator(1, 0) + esdtTransferParser, _ := parsers.NewESDTTransferParser(marshaller) + argTxTypeHandler := coordinator.ArgNewTxTypeHandler{ + PubkeyConverter: pubKeyConverter, + ShardCoordinator: shardC, + BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), + ArgumentParser: parsers.NewCallArgsParser(), + ESDTTransferParser: esdtTransferParser, + EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{ + IsESDTMetadataContinuousCleanupFlagEnabledField: true, + }, + } + txTypeHandler, _ := coordinator.NewTxTypeHandler(argTxTypeHandler) + + args := createArgsForTxProcessor() + args.Accounts = adb + args.ScProcessor = scProcessorMock + args.ShardCoordinator = shardC + args.TxTypeHandler = txTypeHandler + args.PubkeyConv = pubKeyConverter + args.ArgsParser = smartContract.NewArgumentParser() + args.EnableEpochsHandler = &enableEpochsHandlerMock.EnableEpochsHandlerStub{} + execTx, _ := txproc.NewTxProcessor(args) + + returnCode, err := execTx.ProcessTransaction(tx) + assert.Equal(t, process.ErrFailedTransaction, err) + assert.Equal(t, vmcommon.UserError, returnCode) + }) + t.Run("dummy inner txs on relayed tx should error", func(t *testing.T) { + t.Parallel() + + txCopy := *tx + txCopy.InnerTransaction = []byte("dummy") + testProcessRelayedTransactionV3(t, &txCopy, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) + }) + t.Run("different sender on inner tx should error", func(t *testing.T) { + t.Parallel() + + txCopy := *tx + txCopy.RcvAddr = userTx.RcvAddr + testProcessRelayedTransactionV3(t, &txCopy, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) + }) + t.Run("different gas price on inner tx should error", func(t *testing.T) { + t.Parallel() + + txCopy := *tx + txCopy.GasPrice = userTx.GasPrice + 1 + testProcessRelayedTransactionV3(t, &txCopy, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) + }) + t.Run("higher gas limit on inner tx should error", func(t *testing.T) { + t.Parallel() + + txCopy := *tx + txCopy.GasLimit = userTx.GasLimit - 1 + testProcessRelayedTransactionV3(t, &txCopy, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) + }) + t.Run("should work", func(t *testing.T) { + t.Parallel() + testProcessRelayedTransactionV3(t, tx, userTx.RcvAddr, nil, vmcommon.Ok) + }) +} + +func testProcessRelayedTransactionV3( + t *testing.T, + tx *transaction.Transaction, + finalRcvr []byte, + expectedErr error, + expectedCode vmcommon.ReturnCode, +) { + pubKeyConverter := testscommon.NewPubkeyConverterMock(4) + marshaller := &mock.MarshalizerMock{} + + acntSrc := createUserAcc(tx.SndAddr) + _ = acntSrc.AddToBalance(big.NewInt(100)) + acntDst := createUserAcc(tx.RcvAddr) + _ = acntDst.AddToBalance(big.NewInt(10)) + + acntFinal := createUserAcc(finalRcvr) + _ = acntFinal.AddToBalance(big.NewInt(10)) + + adb := &stateMock.AccountsStub{} + adb.LoadAccountCalled = func(address []byte) (vmcommon.AccountHandler, error) { + if bytes.Equal(address, tx.SndAddr) { + return acntSrc, nil + } + if bytes.Equal(address, tx.RcvAddr) { + return acntDst, nil + } + if bytes.Equal(address, finalRcvr) { + return acntFinal, nil + } + + return nil, errors.New("failure") + } + + scProcessorMock := &testscommon.SCProcessorMock{} + shardC, _ := sharding.NewMultiShardCoordinator(1, 0) + esdtTransferParser, _ := parsers.NewESDTTransferParser(marshaller) + argTxTypeHandler := coordinator.ArgNewTxTypeHandler{ + PubkeyConverter: pubKeyConverter, + ShardCoordinator: shardC, + BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), + ArgumentParser: parsers.NewCallArgsParser(), + ESDTTransferParser: esdtTransferParser, + EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{ + IsESDTMetadataContinuousCleanupFlagEnabledField: true, + }, + } + txTypeHandler, _ := coordinator.NewTxTypeHandler(argTxTypeHandler) + + args := createArgsForTxProcessor() + args.Accounts = adb + args.ScProcessor = scProcessorMock + args.ShardCoordinator = shardC + args.TxTypeHandler = txTypeHandler + args.PubkeyConv = pubKeyConverter + args.ArgsParser = smartContract.NewArgumentParser() + args.EnableEpochsHandler = &enableEpochsHandlerMock.EnableEpochsHandlerStub{ + IsRelayedTransactionsV3FlagEnabledField: true, + } + execTx, _ := txproc.NewTxProcessor(args) + + returnCode, err := execTx.ProcessTransaction(tx) + assert.Equal(t, expectedErr, err) + assert.Equal(t, expectedCode, returnCode) +} + func TestTxProcessor_ProcessRelayedTransaction(t *testing.T) { t.Parallel() From 8d4b90a5370770ab627db14aad0c6b9c164686af Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 20 Sep 2023 14:59:29 +0300 Subject: [PATCH 004/503] removed unused method --- process/transaction/shardProcess.go | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 1f4d57b1fe4..1c6ab8898cc 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -723,24 +723,6 @@ func (txProc *txProcessor) computeRelayedTxFees(tx *transaction.Transaction) rel return computedFees } -func (txProc *txProcessor) computeRelayedV3TxFees(tx *transaction.Transaction, innerTxs []*transaction.Transaction) relayedFees { - relayerFee := txProc.economicsFee.ComputeMoveBalanceFee(tx) - totalFee := big.NewInt(0) - for _, innerTx := range innerTxs { - innerFee := txProc.economicsFee.ComputeTxFee(innerTx) - totalFee.Add(totalFee, innerFee) - } - remainingFee := big.NewInt(0).Sub(totalFee, relayerFee) - - computedFees := relayedFees{ - totalFee: totalFee, - remainingFee: remainingFee, - relayerFee: relayerFee, - } - - return computedFees -} - func (txProc *txProcessor) removeValueAndConsumedFeeFromUser( userTx *transaction.Transaction, relayedTxValue *big.Int, From 124541c054c0247e890e7e5f6285f0fc22df935f Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 22 Sep 2023 20:04:25 +0300 Subject: [PATCH 005/503] finished implementation + fixed all tests --- api/groups/transactionGroup.go | 208 +++++++++--------- .../txpool/memorytests/memory_test.go | 14 +- go.mod | 2 +- go.sum | 4 +- .../multiShard/relayedTx/common.go | 48 ++-- .../relayedTx/edgecases/edgecases_test.go | 14 +- .../multiShard/relayedTx/relayedTx_test.go | 16 +- node/external/dtos.go | 5 +- node/node.go | 7 + process/block/preprocess/gasComputation.go | 2 +- process/constants.go | 2 + process/coordinator/transactionType.go | 9 +- process/coordinator/transactionType_test.go | 2 +- process/errors.go | 12 +- process/transaction/interceptedTransaction.go | 18 +- .../interceptedTransaction_test.go | 52 ++--- process/transaction/shardProcess.go | 23 +- process/transaction/shardProcess_test.go | 32 ++- .../transactionEvaluator.go | 2 +- 19 files changed, 278 insertions(+), 194 deletions(-) diff --git a/api/groups/transactionGroup.go b/api/groups/transactionGroup.go index abf798a8ab3..00c45b23f4f 100644 --- a/api/groups/transactionGroup.go +++ b/api/groups/transactionGroup.go @@ -161,22 +161,23 @@ type MultipleTxRequest struct { // SendTxRequest represents the structure that maps and validates user input for publishing a new transaction type SendTxRequest struct { - Sender string `form:"sender" json:"sender"` - Receiver string `form:"receiver" json:"receiver"` - SenderUsername []byte `json:"senderUsername,omitempty"` - ReceiverUsername []byte `json:"receiverUsername,omitempty"` - Value string `form:"value" json:"value"` - Data []byte `form:"data" json:"data"` - Nonce uint64 `form:"nonce" json:"nonce"` - GasPrice uint64 `form:"gasPrice" json:"gasPrice"` - GasLimit uint64 `form:"gasLimit" json:"gasLimit"` - Signature string `form:"signature" json:"signature"` - ChainID string `form:"chainID" json:"chainID"` - Version uint32 `form:"version" json:"version"` - Options uint32 `json:"options,omitempty"` - GuardianAddr string `json:"guardian,omitempty"` - GuardianSignature string `json:"guardianSignature,omitempty"` - InnerTransaction []byte `json:"innerTransaction,omitempty"` + Sender string `form:"sender" json:"sender"` + Receiver string `form:"receiver" json:"receiver"` + SenderUsername []byte `json:"senderUsername,omitempty"` + ReceiverUsername []byte `json:"receiverUsername,omitempty"` + Value string `form:"value" json:"value"` + Data []byte `form:"data" json:"data"` + Nonce uint64 `form:"nonce" json:"nonce"` + GasPrice uint64 `form:"gasPrice" json:"gasPrice"` + GasLimit uint64 `form:"gasLimit" json:"gasLimit"` + Signature string `form:"signature" json:"signature"` + ChainID string `form:"chainID" json:"chainID"` + Version uint32 `form:"version" json:"version"` + Options uint32 `json:"options,omitempty"` + GuardianAddr string `json:"guardian,omitempty"` + GuardianSignature string `json:"guardianSignature,omitempty"` + Relayer string `json:"relayer,omitempty"` + InnerTransaction *SendTxRequest `json:"innerTransaction,omitempty"` } // TxResponse represents the structure on which the response will be validated against @@ -218,28 +219,23 @@ func (tg *transactionGroup) simulateTransaction(c *gin.Context) { return } - txArgs := &external.ArgsCreateTransaction{ - Nonce: gtx.Nonce, - Value: gtx.Value, - Receiver: gtx.Receiver, - ReceiverUsername: gtx.ReceiverUsername, - Sender: gtx.Sender, - SenderUsername: gtx.SenderUsername, - GasPrice: gtx.GasPrice, - GasLimit: gtx.GasLimit, - DataField: gtx.Data, - SignatureHex: gtx.Signature, - ChainID: gtx.ChainID, - Version: gtx.Version, - Options: gtx.Options, - Guardian: gtx.GuardianAddr, - GuardianSigHex: gtx.GuardianSignature, - InnerTransaction: gtx.InnerTransaction, + var innerTx *transaction.Transaction + if gtx.InnerTransaction != nil { + innerTx, _, err = tg.createTransaction(gtx.InnerTransaction, nil) + if err != nil { + c.JSON( + http.StatusBadRequest, + shared.GenericAPIResponse{ + Data: nil, + Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), err.Error()), + Code: shared.ReturnCodeRequestError, + }, + ) + return + } } - start := time.Now() - tx, txHash, err := tg.getFacade().CreateTransaction(txArgs) - logging.LogAPIActionDurationIfNeeded(start, "API call: CreateTransaction") + tx, txHash, err := tg.createTransaction(>x, innerTx) if err != nil { c.JSON( http.StatusBadRequest, @@ -252,7 +248,7 @@ func (tg *transactionGroup) simulateTransaction(c *gin.Context) { return } - start = time.Now() + start := time.Now() err = tg.getFacade().ValidateTransactionForSimulation(tx, checkSignature) logging.LogAPIActionDurationIfNeeded(start, "API call: ValidateTransactionForSimulation") if err != nil { @@ -309,27 +305,23 @@ func (tg *transactionGroup) sendTransaction(c *gin.Context) { return } - txArgs := &external.ArgsCreateTransaction{ - Nonce: gtx.Nonce, - Value: gtx.Value, - Receiver: gtx.Receiver, - ReceiverUsername: gtx.ReceiverUsername, - Sender: gtx.Sender, - SenderUsername: gtx.SenderUsername, - GasPrice: gtx.GasPrice, - GasLimit: gtx.GasLimit, - DataField: gtx.Data, - SignatureHex: gtx.Signature, - ChainID: gtx.ChainID, - Version: gtx.Version, - Options: gtx.Options, - Guardian: gtx.GuardianAddr, - GuardianSigHex: gtx.GuardianSignature, - InnerTransaction: gtx.InnerTransaction, + var innerTx *transaction.Transaction + if gtx.InnerTransaction != nil { + innerTx, _, err = tg.createTransaction(gtx.InnerTransaction, nil) + if err != nil { + c.JSON( + http.StatusBadRequest, + shared.GenericAPIResponse{ + Data: nil, + Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), err.Error()), + Code: shared.ReturnCodeRequestError, + }, + ) + return + } } - start := time.Now() - tx, txHash, err := tg.getFacade().CreateTransaction(txArgs) - logging.LogAPIActionDurationIfNeeded(start, "API call: CreateTransaction") + + tx, txHash, err := tg.createTransaction(>x, innerTx) if err != nil { c.JSON( http.StatusBadRequest, @@ -342,7 +334,7 @@ func (tg *transactionGroup) sendTransaction(c *gin.Context) { return } - start = time.Now() + start := time.Now() err = tg.getFacade().ValidateTransaction(tx) logging.LogAPIActionDurationIfNeeded(start, "API call: ValidateTransaction") if err != nil { @@ -408,26 +400,23 @@ func (tg *transactionGroup) sendMultipleTransactions(c *gin.Context) { var start time.Time txsHashes := make(map[int]string) for idx, receivedTx := range gtx { - txArgs := &external.ArgsCreateTransaction{ - Nonce: receivedTx.Nonce, - Value: receivedTx.Value, - Receiver: receivedTx.Receiver, - ReceiverUsername: receivedTx.ReceiverUsername, - Sender: receivedTx.Sender, - SenderUsername: receivedTx.SenderUsername, - GasPrice: receivedTx.GasPrice, - GasLimit: receivedTx.GasLimit, - DataField: receivedTx.Data, - SignatureHex: receivedTx.Signature, - ChainID: receivedTx.ChainID, - Version: receivedTx.Version, - Options: receivedTx.Options, - Guardian: receivedTx.GuardianAddr, - GuardianSigHex: receivedTx.GuardianSignature, - InnerTransaction: receivedTx.InnerTransaction, + var innerTx *transaction.Transaction + if receivedTx.InnerTransaction != nil { + innerTx, _, err = tg.createTransaction(receivedTx.InnerTransaction, nil) + if err != nil { + c.JSON( + http.StatusBadRequest, + shared.GenericAPIResponse{ + Data: nil, + Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), err.Error()), + Code: shared.ReturnCodeRequestError, + }, + ) + return + } } - tx, txHash, err = tg.getFacade().CreateTransaction(txArgs) - logging.LogAPIActionDurationIfNeeded(start, "API call: CreateTransaction") + + tx, txHash, err = tg.createTransaction(&receivedTx, innerTx) if err != nil { continue } @@ -538,27 +527,23 @@ func (tg *transactionGroup) computeTransactionGasLimit(c *gin.Context) { return } - txArgs := &external.ArgsCreateTransaction{ - Nonce: gtx.Nonce, - Value: gtx.Value, - Receiver: gtx.Receiver, - ReceiverUsername: gtx.ReceiverUsername, - Sender: gtx.Sender, - SenderUsername: gtx.SenderUsername, - GasPrice: gtx.GasPrice, - GasLimit: gtx.GasLimit, - DataField: gtx.Data, - SignatureHex: gtx.Signature, - ChainID: gtx.ChainID, - Version: gtx.Version, - Options: gtx.Options, - Guardian: gtx.GuardianAddr, - GuardianSigHex: gtx.GuardianSignature, - InnerTransaction: gtx.InnerTransaction, + var innerTx *transaction.Transaction + if gtx.InnerTransaction != nil { + innerTx, _, err = tg.createTransaction(gtx.InnerTransaction, nil) + if err != nil { + c.JSON( + http.StatusInternalServerError, + shared.GenericAPIResponse{ + Data: nil, + Error: err.Error(), + Code: shared.ReturnCodeInternalError, + }, + ) + return + } } - start := time.Now() - tx, _, err := tg.getFacade().CreateTransaction(txArgs) - logging.LogAPIActionDurationIfNeeded(start, "API call: CreateTransaction") + + tx, _, err := tg.createTransaction(>x, innerTx) if err != nil { c.JSON( http.StatusInternalServerError, @@ -571,7 +556,7 @@ func (tg *transactionGroup) computeTransactionGasLimit(c *gin.Context) { return } - start = time.Now() + start := time.Now() cost, err := tg.getFacade().ComputeTransactionGasLimit(tx) logging.LogAPIActionDurationIfNeeded(start, "API call: ComputeTransactionGasLimit") if err != nil { @@ -768,6 +753,33 @@ func (tg *transactionGroup) getTransactionsPoolNonceGapsForSender(sender string, ) } +func (tg *transactionGroup) createTransaction(receivedTx *SendTxRequest, innerTx *transaction.Transaction) (*transaction.Transaction, []byte, error) { + txArgs := &external.ArgsCreateTransaction{ + Nonce: receivedTx.Nonce, + Value: receivedTx.Value, + Receiver: receivedTx.Receiver, + ReceiverUsername: receivedTx.ReceiverUsername, + Sender: receivedTx.Sender, + SenderUsername: receivedTx.SenderUsername, + GasPrice: receivedTx.GasPrice, + GasLimit: receivedTx.GasLimit, + DataField: receivedTx.Data, + SignatureHex: receivedTx.Signature, + ChainID: receivedTx.ChainID, + Version: receivedTx.Version, + Options: receivedTx.Options, + Guardian: receivedTx.GuardianAddr, + GuardianSigHex: receivedTx.GuardianSignature, + Relayer: receivedTx.Relayer, + InnerTransaction: innerTx, + } + start := time.Now() + tx, txHash, err := tg.getFacade().CreateTransaction(txArgs) + logging.LogAPIActionDurationIfNeeded(start, "API call: CreateTransaction") + + return tx, txHash, err +} + func validateQuery(sender, fields string, lastNonce, nonceGaps bool) error { if fields != "" && lastNonce { return errors.ErrFetchingLatestNonceCannotIncludeFields diff --git a/dataRetriever/txpool/memorytests/memory_test.go b/dataRetriever/txpool/memorytests/memory_test.go index d2d48fbbcd5..91201e1a036 100644 --- a/dataRetriever/txpool/memorytests/memory_test.go +++ b/dataRetriever/txpool/memorytests/memory_test.go @@ -36,17 +36,17 @@ func TestShardedTxPool_MemoryFootprint(t *testing.T) { journals = append(journals, runScenario(t, newScenario(200, 1, core.MegabyteSize, "0"), memoryAssertion{200, 200}, memoryAssertion{0, 1})) journals = append(journals, runScenario(t, newScenario(10, 1000, 20480, "0"), memoryAssertion{190, 205}, memoryAssertion{1, 4})) journals = append(journals, runScenario(t, newScenario(10000, 1, 1024, "0"), memoryAssertion{10, 16}, memoryAssertion{4, 10})) - journals = append(journals, runScenario(t, newScenario(1, 60000, 256, "0"), memoryAssertion{30, 36}, memoryAssertion{10, 16})) - journals = append(journals, runScenario(t, newScenario(10, 10000, 100, "0"), memoryAssertion{36, 46}, memoryAssertion{16, 24})) + journals = append(journals, runScenario(t, newScenario(1, 60000, 256, "0"), memoryAssertion{30, 38}, memoryAssertion{10, 16})) + journals = append(journals, runScenario(t, newScenario(10, 10000, 100, "0"), memoryAssertion{36, 50}, memoryAssertion{16, 24})) journals = append(journals, runScenario(t, newScenario(100000, 1, 1024, "0"), memoryAssertion{120, 136}, memoryAssertion{56, 60})) // With larger memory footprint - journals = append(journals, runScenario(t, newScenario(100000, 3, 650, "0"), memoryAssertion{290, 320}, memoryAssertion{95, 120})) - journals = append(journals, runScenario(t, newScenario(150000, 2, 650, "0"), memoryAssertion{290, 320}, memoryAssertion{120, 140})) - journals = append(journals, runScenario(t, newScenario(300000, 1, 650, "0"), memoryAssertion{290, 320}, memoryAssertion{170, 190})) - journals = append(journals, runScenario(t, newScenario(30, 10000, 650, "0"), memoryAssertion{290, 320}, memoryAssertion{60, 75})) - journals = append(journals, runScenario(t, newScenario(300, 1000, 650, "0"), memoryAssertion{290, 320}, memoryAssertion{60, 80})) + journals = append(journals, runScenario(t, newScenario(100000, 3, 650, "0"), memoryAssertion{290, 330}, memoryAssertion{95, 120})) + journals = append(journals, runScenario(t, newScenario(150000, 2, 650, "0"), memoryAssertion{290, 330}, memoryAssertion{120, 140})) + journals = append(journals, runScenario(t, newScenario(300000, 1, 650, "0"), memoryAssertion{290, 330}, memoryAssertion{170, 190})) + journals = append(journals, runScenario(t, newScenario(30, 10000, 650, "0"), memoryAssertion{290, 330}, memoryAssertion{60, 75})) + journals = append(journals, runScenario(t, newScenario(300, 1000, 650, "0"), memoryAssertion{290, 330}, memoryAssertion{60, 80})) // Scenarios where destination == me diff --git a/go.mod b/go.mod index e66c01f2dd1..7a80d09852d 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.6 - github.com/multiversx/mx-chain-core-go v1.2.17-0.20230920100104-d7df5756e9e9 + github.com/multiversx/mx-chain-core-go v1.2.17-0.20230921082011-48fd7cc48186 github.com/multiversx/mx-chain-crypto-go v1.2.8 github.com/multiversx/mx-chain-es-indexer-go v1.4.12 github.com/multiversx/mx-chain-logger-go v1.0.13 diff --git a/go.sum b/go.sum index 109c08cf09b..8205d8a137f 100644 --- a/go.sum +++ b/go.sum @@ -386,8 +386,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.6 h1:f2bizRoVuJXBWc32px7pCuzMx4Pgi2tKhUt8BkFV1Fg= github.com/multiversx/mx-chain-communication-go v1.0.6/go.mod h1:+oaUowpq+SqrEmAsMPGwhz44g7L81loWb6AiNQU9Ms4= -github.com/multiversx/mx-chain-core-go v1.2.17-0.20230920100104-d7df5756e9e9 h1:a24ecGgx10TSst2HErE4lcxe6NNsAI1OPMyQEMfdHrs= -github.com/multiversx/mx-chain-core-go v1.2.17-0.20230920100104-d7df5756e9e9/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84= +github.com/multiversx/mx-chain-core-go v1.2.17-0.20230921082011-48fd7cc48186 h1:SJ2AwkXg4pxDAKk9YO8f6WEUGaUWKtcx8018J39ht90= +github.com/multiversx/mx-chain-core-go v1.2.17-0.20230921082011-48fd7cc48186/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84= github.com/multiversx/mx-chain-crypto-go v1.2.8 h1:wOgVlUaO5X4L8iEbFjcQcL8SZvv6WZ7LqH73BiRPhxU= github.com/multiversx/mx-chain-crypto-go v1.2.8/go.mod h1:fkaWKp1rbQN9wPKya5jeoRyC+c/SyN/NfggreyeBw+8= github.com/multiversx/mx-chain-es-indexer-go v1.4.12 h1:KpKcflrXEFXRjWOSIjytNgvSsxl9J/YvyhvoDQR9Pto= diff --git a/integrationTests/multiShard/relayedTx/common.go b/integrationTests/multiShard/relayedTx/common.go index 766b8e11995..ba5f7659f7c 100644 --- a/integrationTests/multiShard/relayedTx/common.go +++ b/integrationTests/multiShard/relayedTx/common.go @@ -62,7 +62,7 @@ func CreateAndSendRelayedAndUserTx( ) *transaction.Transaction { txDispatcherNode := getNodeWithinSameShardAsPlayer(nodes, relayer.Address) - userTx := createUserTx(player, rcvAddr, value, gasLimit, txData) + userTx := createUserTx(player, rcvAddr, value, gasLimit, txData, nil) relayedTx := createRelayedTx(txDispatcherNode.EconomicsData, relayer, userTx) _, err := txDispatcherNode.SendTransaction(relayedTx) @@ -85,7 +85,7 @@ func CreateAndSendRelayedAndUserTxV2( ) *transaction.Transaction { txDispatcherNode := getNodeWithinSameShardAsPlayer(nodes, relayer.Address) - userTx := createUserTx(player, rcvAddr, value, 0, txData) + userTx := createUserTx(player, rcvAddr, value, 0, txData, nil) relayedTx := createRelayedTxV2(txDispatcherNode.EconomicsData, relayer, userTx, gasLimit) _, err := txDispatcherNode.SendTransaction(relayedTx) @@ -108,7 +108,7 @@ func CreateAndSendRelayedAndUserTxV3( ) *transaction.Transaction { txDispatcherNode := getNodeWithinSameShardAsPlayer(nodes, relayer.Address) - userTx := createUserTx(player, rcvAddr, value, gasLimit, txData) + userTx := createUserTx(player, rcvAddr, value, gasLimit, txData, relayer.Address) relayedTx := createRelayedTxV3(txDispatcherNode.EconomicsData, relayer, userTx) _, err := txDispatcherNode.SendTransaction(relayedTx) @@ -125,17 +125,19 @@ func createUserTx( value *big.Int, gasLimit uint64, txData []byte, + relayerAddress []byte, ) *transaction.Transaction { tx := &transaction.Transaction{ - Nonce: player.Nonce, - Value: big.NewInt(0).Set(value), - RcvAddr: rcvAddr, - SndAddr: player.Address, - GasPrice: integrationTests.MinTxGasPrice, - GasLimit: gasLimit, - Data: txData, - ChainID: integrationTests.ChainID, - Version: integrationTests.MinTransactionVersion, + Nonce: player.Nonce, + Value: big.NewInt(0).Set(value), + RcvAddr: rcvAddr, + SndAddr: player.Address, + GasPrice: integrationTests.MinTxGasPrice, + GasLimit: gasLimit, + Data: txData, + ChainID: integrationTests.ChainID, + Version: integrationTests.MinTransactionVersion, + RelayedAddr: relayerAddress, } txBuff, _ := tx.GetDataForSigning(integrationTests.TestAddressPubkeyConverter, integrationTests.TestTxSignMarshalizer, integrationTests.TestTxSignHasher) tx.Signature, _ = player.SingleSigner.Sign(player.SkTxSign, txBuff) @@ -153,7 +155,7 @@ func createRelayedTx( txData := core.RelayedTransaction + "@" + hex.EncodeToString(userTxMarshaled) tx := &transaction.Transaction{ Nonce: relayer.Nonce, - Value: big.NewInt(0).Set(userTx.Value), + Value: big.NewInt(0), RcvAddr: userTx.SndAddr, SndAddr: relayer.Address, GasPrice: integrationTests.MinTxGasPrice, @@ -209,19 +211,19 @@ func createRelayedTxV3( userTx *transaction.Transaction, ) *transaction.Transaction { tx := &transaction.Transaction{ - Nonce: relayer.Nonce, - Value: big.NewInt(0).Set(userTx.Value), - RcvAddr: userTx.SndAddr, - SndAddr: relayer.Address, - GasPrice: integrationTests.MinTxGasPrice, - Data: []byte(""), - ChainID: userTx.ChainID, - Version: userTx.Version, + Nonce: relayer.Nonce, + Value: big.NewInt(0), + RcvAddr: userTx.SndAddr, + SndAddr: relayer.Address, + GasPrice: integrationTests.MinTxGasPrice, + Data: []byte(""), + ChainID: userTx.ChainID, + Version: userTx.Version, + InnerTransaction: userTx, } gasLimit := economicsFee.ComputeGasLimit(tx) tx.GasLimit = userTx.GasLimit + gasLimit - tx.InnerTransaction, _ = integrationTests.TestTxSignMarshalizer.Marshal(userTx) txBuff, _ := tx.GetDataForSigning(integrationTests.TestAddressPubkeyConverter, integrationTests.TestTxSignMarshalizer, integrationTests.TestTxSignHasher) tx.Signature, _ = relayer.SingleSigner.Sign(relayer.SkTxSign, txBuff) relayer.Nonce++ @@ -242,7 +244,7 @@ func createAndSendSimpleTransaction( ) { txDispatcherNode := getNodeWithinSameShardAsPlayer(nodes, player.Address) - userTx := createUserTx(player, rcvAddr, value, gasLimit, txData) + userTx := createUserTx(player, rcvAddr, value, gasLimit, txData, nil) _, err := txDispatcherNode.SendTransaction(userTx) if err != nil { fmt.Println(err.Error()) diff --git a/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go b/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go index 246a81fbe15..a392d12c86a 100644 --- a/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go +++ b/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go @@ -100,10 +100,18 @@ func TestRelayedTransactionInMultiShardEnvironmentWithNormalTxButWithTooMuchGas( additionalGasLimit := uint64(100000) tooMuchGasLimit := integrationTests.MinTxGasLimit + additionalGasLimit nrRoundsToTest := int64(5) + + txsSentEachRound := big.NewInt(2) // 2 relayed txs each round + txsSentPerPlayer := big.NewInt(0).Mul(txsSentEachRound, big.NewInt(nrRoundsToTest)) + initialPlayerFunds := big.NewInt(0).Mul(sendValue, txsSentPerPlayer) + integrationTests.MintAllPlayers(nodes, players, initialPlayerFunds) + for i := int64(0); i < nrRoundsToTest; i++ { for _, player := range players { _ = relayedTx.CreateAndSendRelayedAndUserTx(nodes, relayer, player, receiverAddress1, sendValue, tooMuchGasLimit, []byte("")) + player.Balance.Sub(player.Balance, sendValue) _ = relayedTx.CreateAndSendRelayedAndUserTx(nodes, relayer, player, receiverAddress2, sendValue, tooMuchGasLimit, []byte("")) + player.Balance.Sub(player.Balance, sendValue) } round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) @@ -124,8 +132,8 @@ func TestRelayedTransactionInMultiShardEnvironmentWithNormalTxButWithTooMuchGas( finalBalance := big.NewInt(0).Mul(big.NewInt(int64(len(players))), big.NewInt(nrRoundsToTest)) finalBalance.Mul(finalBalance, sendValue) - assert.Equal(t, receiver1.GetBalance().Cmp(finalBalance), 0) - assert.Equal(t, receiver2.GetBalance().Cmp(finalBalance), 0) + assert.Equal(t, 0, receiver1.GetBalance().Cmp(finalBalance)) + assert.Equal(t, 0, receiver2.GetBalance().Cmp(finalBalance)) players = append(players, relayer) checkPlayerBalancesWithPenalization(t, nodes, players) @@ -139,7 +147,7 @@ func checkPlayerBalancesWithPenalization( for i := 0; i < len(players); i++ { userAcc := relayedTx.GetUserAccount(nodes, players[i].Address) - assert.Equal(t, userAcc.GetBalance().Cmp(players[i].Balance), 0) + assert.Equal(t, 0, userAcc.GetBalance().Cmp(players[i].Balance)) assert.Equal(t, userAcc.GetNonce(), players[i].Nonce) } } diff --git a/integrationTests/multiShard/relayedTx/relayedTx_test.go b/integrationTests/multiShard/relayedTx/relayedTx_test.go index bb5e63422f1..bd3c268dac2 100644 --- a/integrationTests/multiShard/relayedTx/relayedTx_test.go +++ b/integrationTests/multiShard/relayedTx/relayedTx_test.go @@ -70,10 +70,18 @@ func testRelayedTransactionInMultiShardEnvironmentWithNormalTx( receiverAddress2 := []byte("12345678901234567890123456789011") nrRoundsToTest := int64(5) + + txsSentEachRound := big.NewInt(2) // 2 relayed txs each round + txsSentPerPlayer := big.NewInt(0).Mul(txsSentEachRound, big.NewInt(nrRoundsToTest)) + initialPlayerFunds := big.NewInt(0).Mul(sendValue, txsSentPerPlayer) + integrationTests.MintAllPlayers(nodes, players, initialPlayerFunds) + for i := int64(0); i < nrRoundsToTest; i++ { for _, player := range players { _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, receiverAddress1, sendValue, integrationTests.MinTxGasLimit, []byte("")) + player.Balance.Sub(player.Balance, sendValue) _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, receiverAddress2, sendValue, integrationTests.MinTxGasLimit, []byte("")) + player.Balance.Sub(player.Balance, sendValue) } round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) @@ -340,10 +348,12 @@ func testRelayedTransactionInMultiShardEnvironmentWithAttestationContract( round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) + integrationTests.MintAllPlayers(nodes, players, registerValue) + uniqueIDs := make([]string, len(players)) for i, player := range players { uniqueIDs[i] = core.UniqueIdentifier() - _ = CreateAndSendRelayedAndUserTx(nodes, relayer, player, scAddress, registerValue, + _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, scAddress, registerValue, registerVMGas, []byte("register@"+hex.EncodeToString([]byte(uniqueIDs[i])))) } time.Sleep(time.Second) @@ -370,6 +380,8 @@ func testRelayedTransactionInMultiShardEnvironmentWithAttestationContract( integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) } + integrationTests.MintAllPlayers(nodes, players, registerValue) + for i, player := range players { _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, scAddress, big.NewInt(0), attestVMGas, []byte("attest@"+hex.EncodeToString([]byte(uniqueIDs[i]))+"@"+hex.EncodeToString([]byte(privateInfos[i])))) @@ -426,7 +438,7 @@ func checkPlayerBalances( players []*integrationTests.TestWalletAccount) { for _, player := range players { userAcc := GetUserAccount(nodes, player.Address) - assert.Equal(t, userAcc.GetBalance().Cmp(player.Balance), 0) + assert.Equal(t, 0, userAcc.GetBalance().Cmp(player.Balance)) assert.Equal(t, userAcc.GetNonce(), player.Nonce) } } diff --git a/node/external/dtos.go b/node/external/dtos.go index e8e43e784a0..b01dfbd19ff 100644 --- a/node/external/dtos.go +++ b/node/external/dtos.go @@ -1,5 +1,7 @@ package external +import "github.com/multiversx/mx-chain-core-go/data/transaction" + // ArgsCreateTransaction defines arguments for creating a transaction type ArgsCreateTransaction struct { Nonce uint64 @@ -17,5 +19,6 @@ type ArgsCreateTransaction struct { Options uint32 Guardian string GuardianSigHex string - InnerTransaction []byte + Relayer string + InnerTransaction *transaction.Transaction } diff --git a/node/node.go b/node/node.go index 969c865b6c7..ce26a149f60 100644 --- a/node/node.go +++ b/node/node.go @@ -893,6 +893,13 @@ func (n *Node) CreateTransaction(txArgs *external.ArgsCreateTransaction) (*trans } } + if len(txArgs.Relayer) > 0 { + tx.RelayedAddr, err = addrPubKeyConverter.Decode(txArgs.Relayer) + if err != nil { + return nil, nil, errors.New("could not create relayer address from provided param") + } + } + var txHash []byte txHash, err = core.CalculateHash(n.coreComponents.InternalMarshalizer(), n.coreComponents.Hasher(), tx) if err != nil { diff --git a/process/block/preprocess/gasComputation.go b/process/block/preprocess/gasComputation.go index 083c88d8cf5..9fb2e2937a5 100644 --- a/process/block/preprocess/gasComputation.go +++ b/process/block/preprocess/gasComputation.go @@ -420,7 +420,7 @@ func (gc *gasComputation) computeGasProvidedByTxV1( } func (gc *gasComputation) isRelayedTx(txType process.TransactionType) bool { - return txType == process.RelayedTx || txType == process.RelayedTxV2 + return txType == process.RelayedTx || txType == process.RelayedTxV2 || txType == process.RelayedTxV3 } // IsInterfaceNil returns true if there is no value under the interface diff --git a/process/constants.go b/process/constants.go index 4930f427615..44101f50b7c 100644 --- a/process/constants.go +++ b/process/constants.go @@ -58,6 +58,8 @@ func (transactionType TransactionType) String() string { return "RelayedTx" case RelayedTxV2: return "RelayedTxV2" + case RelayedTxV3: + return "RelayedTxV3" case RewardTx: return "RewardTx" case InvalidTransaction: diff --git a/process/coordinator/transactionType.go b/process/coordinator/transactionType.go index 071846e9ce1..834db6633f9 100644 --- a/process/coordinator/transactionType.go +++ b/process/coordinator/transactionType.go @@ -7,6 +7,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/smartContractResult" + "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-core-go/data/vm" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/process" @@ -16,6 +17,10 @@ import ( var _ process.TxTypeHandler = (*txTypeHandler)(nil) +type relayedV3TransactionHandler interface { + GetInnerTransaction() *transaction.Transaction +} + type txTypeHandler struct { pubkeyConv core.PubkeyConverter shardCoordinator sharding.Coordinator @@ -190,12 +195,12 @@ func (tth *txTypeHandler) isRelayedTransactionV2(functionName string) bool { } func (tth *txTypeHandler) isRelayedTransactionV3(tx data.TransactionHandler) bool { - rtx, ok := tx.(data.RelayedV3TransactionHandler) + rtx, ok := tx.(relayedV3TransactionHandler) if !ok { return false } - return len(rtx.GetInnerTransaction()) > 0 + return rtx.GetInnerTransaction() != nil } func (tth *txTypeHandler) isDestAddressEmpty(tx data.TransactionHandler) bool { diff --git a/process/coordinator/transactionType_test.go b/process/coordinator/transactionType_test.go index 48ddc97efdd..6f0683a9298 100644 --- a/process/coordinator/transactionType_test.go +++ b/process/coordinator/transactionType_test.go @@ -452,7 +452,7 @@ func TestTxTypeHandler_ComputeTransactionTypeRelayedV3(t *testing.T) { tx.SndAddr = []byte("000") tx.RcvAddr = []byte("001") tx.Value = big.NewInt(45) - tx.InnerTransaction = []byte("some inner tx") + tx.InnerTransaction = &transaction.Transaction{Nonce: 1} arg := createMockArguments() arg.PubkeyConverter = &testscommon.PubkeyConverterStub{ diff --git a/process/errors.go b/process/errors.go index 96df6c37124..b148d65091b 100644 --- a/process/errors.go +++ b/process/errors.go @@ -1225,7 +1225,7 @@ var ErrNilManagedPeersHolder = errors.New("nil managed peers holder") var ErrNilStorageService = errors.New("nil storage service") // ErrRelayedV3GasPriceMismatch signals that relayed v3 gas price is not equal with inner tx -var ErrRelayedV3GasPriceMismatch = errors.New("relayed v3 gas price mismatch") +var ErrRelayedV3GasPriceMismatch = errors.New("relayed tx v3 gas price mismatch") // ErrRelayedTxV3BeneficiaryDoesNotMatchReceiver signals that an invalid address was provided in the relayed tx v3 var ErrRelayedTxV3BeneficiaryDoesNotMatchReceiver = errors.New("invalid address in relayed tx v3") @@ -1233,5 +1233,11 @@ var ErrRelayedTxV3BeneficiaryDoesNotMatchReceiver = errors.New("invalid address // ErrRelayedTxV3Disabled signals that the v3 version of relayed tx is disabled var ErrRelayedTxV3Disabled = errors.New("relayed tx v3 is disabled") -// ErrRelayedTxV3GasLimitLowerThanInnerTx signals that the relayed tx v3 has a lower gas limit than one of the inner txs -var ErrRelayedTxV3GasLimitLowerThanInnerTx = errors.New("relayed tx v3 gas limit should be less than inner tx") +// ErrRelayedTxV3ZeroVal signals that the v3 version of relayed tx should be created with 0 as value +var ErrRelayedTxV3ZeroVal = errors.New("relayed tx v3 value should be 0") + +// ErrRelayedTxV3EmptyRelayer signals that the inner tx of the relayed v3 does not have a relayer address set +var ErrRelayedTxV3EmptyRelayer = errors.New("empty relayer on inner tx of relayed tx v3") + +// ErrRelayedTxV3GasLimitMismatch signals that relayed tx v3 gas limit is higher than user tx gas limit +var ErrRelayedTxV3GasLimitMismatch = errors.New("relayed tx v3 gas limit mismatch") diff --git a/process/transaction/interceptedTransaction.go b/process/transaction/interceptedTransaction.go index 6e2584bb78e..dbf9775e23f 100644 --- a/process/transaction/interceptedTransaction.go +++ b/process/transaction/interceptedTransaction.go @@ -210,24 +210,26 @@ func (inTx *InterceptedTransaction) CheckValidity() error { return nil } -func isRelayedTx(funcName string, innerTx []byte) bool { +func isRelayedTx(funcName string, innerTx *transaction.Transaction) bool { return core.RelayedTransaction == funcName || core.RelayedTransactionV2 == funcName || - len(innerTx) > 0 + innerTx != nil } func (inTx *InterceptedTransaction) verifyIfRelayedTxV3(tx *transaction.Transaction) error { - if len(tx.InnerTransaction) == 0 { + if tx.InnerTransaction == nil { return nil } - innerTx := &transaction.Transaction{} - err := inTx.signMarshalizer.Unmarshal(innerTx, tx.InnerTransaction) - if err != nil { - return err + innerTx := tx.InnerTransaction + if !bytes.Equal(innerTx.SndAddr, tx.RcvAddr) { + return process.ErrRelayedTxV3BeneficiaryDoesNotMatchReceiver + } + if len(innerTx.RelayedAddr) == 0 { + return process.ErrRelayedTxV3EmptyRelayer } - err = inTx.integrity(innerTx) + err := inTx.integrity(innerTx) if err != nil { return fmt.Errorf("inner transaction: %w", err) } diff --git a/process/transaction/interceptedTransaction_test.go b/process/transaction/interceptedTransaction_test.go index bd4145e9e08..26251f5613e 100644 --- a/process/transaction/interceptedTransaction_test.go +++ b/process/transaction/interceptedTransaction_test.go @@ -1503,20 +1503,18 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { minTxVersion := uint32(1) chainID := []byte("chain") innerTx := &dataTransaction.Transaction{ - Nonce: 1, - Value: big.NewInt(2), - Data: []byte("data inner tx 1"), - GasLimit: 3, - GasPrice: 4, - RcvAddr: recvAddress, - SndAddr: senderAddress, - Signature: sigOk, - ChainID: chainID, - Version: minTxVersion, + Nonce: 1, + Value: big.NewInt(2), + Data: []byte("data inner tx 1"), + GasLimit: 3, + GasPrice: 4, + RcvAddr: []byte("34567890123456789012345678901234"), + SndAddr: recvAddress, + Signature: sigOk, + ChainID: chainID, + Version: minTxVersion, + RelayedAddr: senderAddress, } - marshaller := &mock.MarshalizerMock{} - innerTxBuff, err := marshaller.Marshal(innerTx) - assert.Nil(t, err) tx := &dataTransaction.Transaction{ Nonce: 1, @@ -1528,22 +1526,30 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { Signature: sigOk, ChainID: chainID, Version: minTxVersion, - InnerTransaction: innerTxBuff, + InnerTransaction: innerTx, } txi, _ := createInterceptedTxFromPlainTxWithArgParser(tx) - err = txi.CheckValidity() + err := txi.CheckValidity() assert.Nil(t, err) + innerTx.RelayedAddr = nil + txi, _ = createInterceptedTxFromPlainTxWithArgParser(tx) + err = txi.CheckValidity() + assert.Equal(t, process.ErrRelayedTxV3EmptyRelayer, err) + innerTx.RelayedAddr = senderAddress + + innerTx.SndAddr = []byte("34567890123456789012345678901234") + txi, _ = createInterceptedTxFromPlainTxWithArgParser(tx) + err = txi.CheckValidity() + assert.Equal(t, process.ErrRelayedTxV3BeneficiaryDoesNotMatchReceiver, err) + innerTx.SndAddr = recvAddress + innerTx.Signature = nil - tx.InnerTransaction, err = marshaller.Marshal(innerTx) - assert.Nil(t, err) txi, _ = createInterceptedTxFromPlainTxWithArgParser(tx) err = txi.CheckValidity() assert.NotNil(t, err) innerTx.Signature = sigBad - tx.InnerTransaction, err = marshaller.Marshal(innerTx) - assert.Nil(t, err) txi, _ = createInterceptedTxFromPlainTxWithArgParser(tx) err = txi.CheckValidity() assert.NotNil(t, err) @@ -1560,12 +1566,8 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { ChainID: chainID, Version: minTxVersion, } - innerTx2Buff, err := marshaller.Marshal(innerTx2) - assert.Nil(t, err) - innerTx.InnerTransaction, err = marshaller.Marshal(innerTx2Buff) - assert.Nil(t, err) - tx.InnerTransaction, err = marshaller.Marshal(innerTx) - assert.Nil(t, err) + innerTx.InnerTransaction = innerTx2 + tx.InnerTransaction = innerTx txi, _ = createInterceptedTxFromPlainTxWithArgParser(tx) err = txi.CheckValidity() assert.NotNil(t, err) diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 1c6ab8898cc..c0a23ca8fb1 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -621,25 +621,26 @@ func (txProc *txProcessor) processRelayedTxV3( if !txProc.enableEpochsHandler.IsRelayedTransactionsV3FlagEnabled() { return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedTxV3Disabled) } - - innerTx := &transaction.Transaction{} - innerTxBuff := tx.GetInnerTransaction() - err := txProc.signMarshalizer.Unmarshal(innerTx, innerTxBuff) - if err != nil { - return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, err) + if tx.GetValue().Cmp(big.NewInt(0)) != 0 { + return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedTxV3ZeroVal) } - if !bytes.Equal(tx.RcvAddr, innerTx.SndAddr) { + userTx := tx.GetInnerTransaction() + if !bytes.Equal(tx.RcvAddr, userTx.SndAddr) { return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedTxV3BeneficiaryDoesNotMatchReceiver) } - if tx.GasPrice != innerTx.GasPrice { + if len(userTx.RelayedAddr) == 0 { + return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedTxV3EmptyRelayer) + } + if tx.GasPrice != userTx.GasPrice { return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedV3GasPriceMismatch) } - if tx.GasLimit < innerTx.GasLimit { - return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedTxV3GasLimitLowerThanInnerTx) + remainingGasLimit := tx.GasLimit - txProc.economicsFee.ComputeGasLimit(tx) + if userTx.GasLimit != remainingGasLimit { + return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedTxV3GasLimitMismatch) } - return txProc.finishExecutionOfRelayedTx(relayerAcnt, acntDst, tx, innerTx) + return txProc.finishExecutionOfRelayedTx(relayerAcnt, acntDst, tx, userTx) } func (txProc *txProcessor) processRelayedTxV2( diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index 0cd26fa73b5..e3702ec1e9b 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -2031,7 +2031,7 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { tx.RcvAddr = userAddr tx.Value = big.NewInt(0) tx.GasPrice = 1 - tx.GasLimit = 4 + tx.GasLimit = 8 userTx := &transaction.Transaction{} userTx.Nonce = 0 @@ -2040,9 +2040,10 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { userTx.Value = big.NewInt(0) userTx.Data = []byte("execute@param1") userTx.GasPrice = 1 - userTx.GasLimit = 2 + userTx.GasLimit = 4 + userTx.RelayedAddr = tx.SndAddr - tx.InnerTransaction, _ = marshaller.Marshal(userTx) + tx.InnerTransaction = userTx t.Run("flag not active should error", func(t *testing.T) { t.Parallel() @@ -2100,11 +2101,11 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { assert.Equal(t, process.ErrFailedTransaction, err) assert.Equal(t, vmcommon.UserError, returnCode) }) - t.Run("dummy inner txs on relayed tx should error", func(t *testing.T) { + t.Run("value on relayed tx should error", func(t *testing.T) { t.Parallel() txCopy := *tx - txCopy.InnerTransaction = []byte("dummy") + txCopy.Value = big.NewInt(1) testProcessRelayedTransactionV3(t, &txCopy, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) }) t.Run("different sender on inner tx should error", func(t *testing.T) { @@ -2114,6 +2115,15 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { txCopy.RcvAddr = userTx.RcvAddr testProcessRelayedTransactionV3(t, &txCopy, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) }) + t.Run("empty relayer on inner tx should error", func(t *testing.T) { + t.Parallel() + + txCopy := *tx + userTxCopy := *userTx + userTxCopy.RelayedAddr = nil + txCopy.InnerTransaction = &userTxCopy + testProcessRelayedTransactionV3(t, &txCopy, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) + }) t.Run("different gas price on inner tx should error", func(t *testing.T) { t.Parallel() @@ -2192,6 +2202,18 @@ func testProcessRelayedTransactionV3( args.EnableEpochsHandler = &enableEpochsHandlerMock.EnableEpochsHandlerStub{ IsRelayedTransactionsV3FlagEnabledField: true, } + args.EconomicsFee = &economicsmocks.EconomicsHandlerMock{ + ComputeTxFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { + return big.NewInt(4) + }, + ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { + return big.NewInt(4) + }, + ComputeGasLimitCalled: func(tx data.TransactionWithFeeHandler) uint64 { + return 4 + }, + } + execTx, _ := txproc.NewTxProcessor(args) returnCode, err := execTx.ProcessTransaction(tx) diff --git a/process/transactionEvaluator/transactionEvaluator.go b/process/transactionEvaluator/transactionEvaluator.go index b20652774d0..73ed39cd3f0 100644 --- a/process/transactionEvaluator/transactionEvaluator.go +++ b/process/transactionEvaluator/transactionEvaluator.go @@ -103,7 +103,7 @@ func (ate *apiTransactionEvaluator) ComputeTransactionGasLimit(tx *transaction.T switch txTypeOnSender { case process.SCDeployment, process.SCInvoking, process.BuiltInFunctionCall, process.MoveBalance: return ate.simulateTransactionCost(tx, txTypeOnSender) - case process.RelayedTx, process.RelayedTxV2: + case process.RelayedTx, process.RelayedTxV2, process.RelayedTxV3: // TODO implement in the next PR return &transaction.CostResponse{ GasUnits: 0, From 1608e1320e0297fbf6adb15092b8d51a442c2072 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 25 Sep 2023 12:24:25 +0300 Subject: [PATCH 006/503] fixed typo after self review --- go.mod | 2 +- go.sum | 4 +-- .../multiShard/relayedTx/common.go | 2 +- node/node.go | 2 +- process/transaction/interceptedTransaction.go | 7 ++++- .../interceptedTransaction_test.go | 31 +++++++++++++++++-- process/transaction/shardProcess.go | 2 +- process/transaction/shardProcess_test.go | 4 +-- 8 files changed, 42 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 7a80d09852d..96b0d69e866 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.6 - github.com/multiversx/mx-chain-core-go v1.2.17-0.20230921082011-48fd7cc48186 + github.com/multiversx/mx-chain-core-go v1.2.17-0.20230925091936-1e73b4f43019 github.com/multiversx/mx-chain-crypto-go v1.2.8 github.com/multiversx/mx-chain-es-indexer-go v1.4.12 github.com/multiversx/mx-chain-logger-go v1.0.13 diff --git a/go.sum b/go.sum index 8205d8a137f..cebea383858 100644 --- a/go.sum +++ b/go.sum @@ -386,8 +386,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.6 h1:f2bizRoVuJXBWc32px7pCuzMx4Pgi2tKhUt8BkFV1Fg= github.com/multiversx/mx-chain-communication-go v1.0.6/go.mod h1:+oaUowpq+SqrEmAsMPGwhz44g7L81loWb6AiNQU9Ms4= -github.com/multiversx/mx-chain-core-go v1.2.17-0.20230921082011-48fd7cc48186 h1:SJ2AwkXg4pxDAKk9YO8f6WEUGaUWKtcx8018J39ht90= -github.com/multiversx/mx-chain-core-go v1.2.17-0.20230921082011-48fd7cc48186/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84= +github.com/multiversx/mx-chain-core-go v1.2.17-0.20230925091936-1e73b4f43019 h1:TkdlJSqX12sF+lb0nzo8qZppEPSDbYjyIITPVAMAws4= +github.com/multiversx/mx-chain-core-go v1.2.17-0.20230925091936-1e73b4f43019/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84= github.com/multiversx/mx-chain-crypto-go v1.2.8 h1:wOgVlUaO5X4L8iEbFjcQcL8SZvv6WZ7LqH73BiRPhxU= github.com/multiversx/mx-chain-crypto-go v1.2.8/go.mod h1:fkaWKp1rbQN9wPKya5jeoRyC+c/SyN/NfggreyeBw+8= github.com/multiversx/mx-chain-es-indexer-go v1.4.12 h1:KpKcflrXEFXRjWOSIjytNgvSsxl9J/YvyhvoDQR9Pto= diff --git a/integrationTests/multiShard/relayedTx/common.go b/integrationTests/multiShard/relayedTx/common.go index ba5f7659f7c..0d8af34b244 100644 --- a/integrationTests/multiShard/relayedTx/common.go +++ b/integrationTests/multiShard/relayedTx/common.go @@ -137,7 +137,7 @@ func createUserTx( Data: txData, ChainID: integrationTests.ChainID, Version: integrationTests.MinTransactionVersion, - RelayedAddr: relayerAddress, + RelayerAddr: relayerAddress, } txBuff, _ := tx.GetDataForSigning(integrationTests.TestAddressPubkeyConverter, integrationTests.TestTxSignMarshalizer, integrationTests.TestTxSignHasher) tx.Signature, _ = player.SingleSigner.Sign(player.SkTxSign, txBuff) diff --git a/node/node.go b/node/node.go index ce26a149f60..b9a504d0914 100644 --- a/node/node.go +++ b/node/node.go @@ -894,7 +894,7 @@ func (n *Node) CreateTransaction(txArgs *external.ArgsCreateTransaction) (*trans } if len(txArgs.Relayer) > 0 { - tx.RelayedAddr, err = addrPubKeyConverter.Decode(txArgs.Relayer) + tx.RelayerAddr, err = addrPubKeyConverter.Decode(txArgs.Relayer) if err != nil { return nil, nil, errors.New("could not create relayer address from provided param") } diff --git a/process/transaction/interceptedTransaction.go b/process/transaction/interceptedTransaction.go index dbf9775e23f..4ab39f4f7bc 100644 --- a/process/transaction/interceptedTransaction.go +++ b/process/transaction/interceptedTransaction.go @@ -225,7 +225,7 @@ func (inTx *InterceptedTransaction) verifyIfRelayedTxV3(tx *transaction.Transact if !bytes.Equal(innerTx.SndAddr, tx.RcvAddr) { return process.ErrRelayedTxV3BeneficiaryDoesNotMatchReceiver } - if len(innerTx.RelayedAddr) == 0 { + if len(innerTx.RelayerAddr) == 0 { return process.ErrRelayedTxV3EmptyRelayer } @@ -487,6 +487,11 @@ func (inTx *InterceptedTransaction) Fee() *big.Int { return inTx.feeHandler.ComputeTxFee(inTx.tx) } +// RelayerAddress returns the relayer address from transaction +func (inTx *InterceptedTransaction) RelayerAddress() []byte { + return inTx.tx.RelayerAddr +} + // Type returns the type of this intercepted data func (inTx *InterceptedTransaction) Type() string { return "intercepted tx" diff --git a/process/transaction/interceptedTransaction_test.go b/process/transaction/interceptedTransaction_test.go index 26251f5613e..fda79c3bf34 100644 --- a/process/transaction/interceptedTransaction_test.go +++ b/process/transaction/interceptedTransaction_test.go @@ -1274,6 +1274,31 @@ func TestInterceptedTransaction_GetSenderAddress(t *testing.T) { assert.NotNil(t, result) } +func TestInterceptedTransaction_GetRelayerAddress(t *testing.T) { + t.Parallel() + + relayerAddr := []byte("34567890123456789012345678901234") + minTxVersion := uint32(1) + chainID := []byte("chain") + tx := &dataTransaction.Transaction{ + Nonce: 0, + Value: big.NewInt(2), + Data: []byte("data"), + GasLimit: 3, + GasPrice: 4, + RcvAddr: recvAddress, + SndAddr: senderAddress, + Signature: sigOk, + ChainID: chainID, + Version: minTxVersion, + RelayerAddr: relayerAddr, + } + + txi, _ := createInterceptedTxFromPlainTx(tx, createFreeTxFeeHandler(), chainID, minTxVersion) + result := txi.RelayerAddress() + assert.Equal(t, relayerAddr, result) +} + func TestInterceptedTransaction_CheckValiditySecondTimeDoesNotVerifySig(t *testing.T) { t.Parallel() @@ -1513,7 +1538,7 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { Signature: sigOk, ChainID: chainID, Version: minTxVersion, - RelayedAddr: senderAddress, + RelayerAddr: senderAddress, } tx := &dataTransaction.Transaction{ @@ -1532,11 +1557,11 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { err := txi.CheckValidity() assert.Nil(t, err) - innerTx.RelayedAddr = nil + innerTx.RelayerAddr = nil txi, _ = createInterceptedTxFromPlainTxWithArgParser(tx) err = txi.CheckValidity() assert.Equal(t, process.ErrRelayedTxV3EmptyRelayer, err) - innerTx.RelayedAddr = senderAddress + innerTx.RelayerAddr = senderAddress innerTx.SndAddr = []byte("34567890123456789012345678901234") txi, _ = createInterceptedTxFromPlainTxWithArgParser(tx) diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index c0a23ca8fb1..9eff6c3b122 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -629,7 +629,7 @@ func (txProc *txProcessor) processRelayedTxV3( if !bytes.Equal(tx.RcvAddr, userTx.SndAddr) { return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedTxV3BeneficiaryDoesNotMatchReceiver) } - if len(userTx.RelayedAddr) == 0 { + if len(userTx.RelayerAddr) == 0 { return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedTxV3EmptyRelayer) } if tx.GasPrice != userTx.GasPrice { diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index e3702ec1e9b..b5ead7aca4c 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -2041,7 +2041,7 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { userTx.Data = []byte("execute@param1") userTx.GasPrice = 1 userTx.GasLimit = 4 - userTx.RelayedAddr = tx.SndAddr + userTx.RelayerAddr = tx.SndAddr tx.InnerTransaction = userTx @@ -2120,7 +2120,7 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { txCopy := *tx userTxCopy := *userTx - userTxCopy.RelayedAddr = nil + userTxCopy.RelayerAddr = nil txCopy.InnerTransaction = &userTxCopy testProcessRelayedTransactionV3(t, &txCopy, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) }) From ad459c0f0e43dba85c1f5c50b42a9e02625ba05a Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 25 Sep 2023 12:41:16 +0300 Subject: [PATCH 007/503] added skip for user tx in tx validator balance check --- process/dataValidators/txValidator.go | 12 +++ process/dataValidators/txValidator_test.go | 88 +++++++++++++++++----- 2 files changed, 81 insertions(+), 19 deletions(-) diff --git a/process/dataValidators/txValidator.go b/process/dataValidators/txValidator.go index 9c72be1d89a..1f68840ccb0 100644 --- a/process/dataValidators/txValidator.go +++ b/process/dataValidators/txValidator.go @@ -5,6 +5,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" + "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/state" @@ -16,6 +17,11 @@ var _ process.TxValidator = (*txValidator)(nil) var log = logger.GetOrCreate("process/dataValidators") +type relayedV3TransactionHandler interface { + GetInnerTransaction() *transaction.Transaction + GetRelayerAddr() []byte +} + // txValidator represents a tx handler validator that doesn't check the validity of provided txHandler type txValidator struct { accounts state.AccountsAdapter @@ -115,6 +121,12 @@ func (txv *txValidator) getSenderUserAccount( } func (txv *txValidator) checkBalance(interceptedTx process.InterceptedTransactionHandler, account state.UserAccountHandler) error { + rTx, ok := interceptedTx.Transaction().(relayedV3TransactionHandler) + if ok && len(rTx.GetRelayerAddr()) > 0 { + // early return if this is a user tx of relayed v3, no need to check balance + return nil + } + accountBalance := account.GetBalance() txFee := interceptedTx.Fee() if accountBalance.Cmp(txFee) < 0 { diff --git a/process/dataValidators/txValidator_test.go b/process/dataValidators/txValidator_test.go index 551b18928d1..bf2eed2d1e7 100644 --- a/process/dataValidators/txValidator_test.go +++ b/process/dataValidators/txValidator_test.go @@ -390,26 +390,76 @@ func TestTxValidator_CheckTxValidityWrongAccountTypeShouldReturnFalse(t *testing func TestTxValidator_CheckTxValidityTxIsOkShouldReturnTrue(t *testing.T) { t.Parallel() - accountNonce := uint64(0) - accountBalance := big.NewInt(10) - adb := getAccAdapter(accountNonce, accountBalance) - shardCoordinator := createMockCoordinator("_", 0) - maxNonceDeltaAllowed := 100 - txValidator, _ := dataValidators.NewTxValidator( - adb, - shardCoordinator, - &testscommon.WhiteListHandlerStub{}, - testscommon.NewPubkeyConverterMock(32), - &testscommon.TxVersionCheckerStub{}, - maxNonceDeltaAllowed, - ) - - addressMock := []byte("address") - currentShard := uint32(0) - txValidatorHandler := getInterceptedTxHandler(currentShard, currentShard, 1, addressMock, big.NewInt(0)) + t.Run("regular tx should work", func(t *testing.T) { + t.Parallel() + + accountNonce := uint64(0) + accountBalance := big.NewInt(10) + adb := getAccAdapter(accountNonce, accountBalance) + shardCoordinator := createMockCoordinator("_", 0) + maxNonceDeltaAllowed := 100 + txValidator, _ := dataValidators.NewTxValidator( + adb, + shardCoordinator, + &testscommon.WhiteListHandlerStub{}, + testscommon.NewPubkeyConverterMock(32), + &testscommon.TxVersionCheckerStub{}, + maxNonceDeltaAllowed, + ) + + addressMock := []byte("address") + currentShard := uint32(0) + txValidatorHandler := getInterceptedTxHandler(currentShard, currentShard, 1, addressMock, big.NewInt(0)) + + result := txValidator.CheckTxValidity(txValidatorHandler) + assert.Nil(t, result) + }) + t.Run("user tx should work and skip balance checks", func(t *testing.T) { + t.Parallel() + + accountNonce := uint64(0) + accountBalance := big.NewInt(10) + adb := getAccAdapter(accountNonce, accountBalance) + shardCoordinator := createMockCoordinator("_", 0) + maxNonceDeltaAllowed := 100 + txValidator, _ := dataValidators.NewTxValidator( + adb, + shardCoordinator, + &testscommon.WhiteListHandlerStub{}, + testscommon.NewPubkeyConverterMock(32), + &testscommon.TxVersionCheckerStub{}, + maxNonceDeltaAllowed, + ) + + addressMock := []byte("address") + currentShard := uint32(0) + interceptedTx := &mock.InterceptedTxHandlerStub{ + SenderShardIdCalled: func() uint32 { + return currentShard + }, + ReceiverShardIdCalled: func() uint32 { + return currentShard + }, + NonceCalled: func() uint64 { + return 1 + }, + SenderAddressCalled: func() []byte { + return addressMock + }, + FeeCalled: func() *big.Int { + assert.Fail(t, "should have not been called") + return big.NewInt(0) + }, + TransactionCalled: func() data.TransactionHandler { + return &transaction.Transaction{ + RelayerAddr: []byte("relayer"), + } + }, + } - result := txValidator.CheckTxValidity(txValidatorHandler) - assert.Nil(t, result) + result := txValidator.CheckTxValidity(interceptedTx) + assert.Nil(t, result) + }) } func Test_getTxData(t *testing.T) { From f379f31be63c09fecd724f88133313a0abf20273 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 26 Sep 2023 13:18:05 +0300 Subject: [PATCH 008/503] fixes after first review --- go.mod | 2 +- go.sum | 4 +- node/node.go | 4 +- process/coordinator/transactionType.go | 12 +-- .../factory/interceptedTxDataFactory.go | 1 + process/transaction/interceptedTransaction.go | 10 +++ .../interceptedTransaction_test.go | 82 +++++++++++++++++++ 7 files changed, 99 insertions(+), 16 deletions(-) diff --git a/go.mod b/go.mod index 96b0d69e866..b5d80d077f6 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.6 - github.com/multiversx/mx-chain-core-go v1.2.17-0.20230925091936-1e73b4f43019 + github.com/multiversx/mx-chain-core-go v1.2.17-0.20230926094053-ab2114ef6c28 github.com/multiversx/mx-chain-crypto-go v1.2.8 github.com/multiversx/mx-chain-es-indexer-go v1.4.12 github.com/multiversx/mx-chain-logger-go v1.0.13 diff --git a/go.sum b/go.sum index cebea383858..89d9560785f 100644 --- a/go.sum +++ b/go.sum @@ -386,8 +386,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.6 h1:f2bizRoVuJXBWc32px7pCuzMx4Pgi2tKhUt8BkFV1Fg= github.com/multiversx/mx-chain-communication-go v1.0.6/go.mod h1:+oaUowpq+SqrEmAsMPGwhz44g7L81loWb6AiNQU9Ms4= -github.com/multiversx/mx-chain-core-go v1.2.17-0.20230925091936-1e73b4f43019 h1:TkdlJSqX12sF+lb0nzo8qZppEPSDbYjyIITPVAMAws4= -github.com/multiversx/mx-chain-core-go v1.2.17-0.20230925091936-1e73b4f43019/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84= +github.com/multiversx/mx-chain-core-go v1.2.17-0.20230926094053-ab2114ef6c28 h1:A8FP1f4Hga+Gd8zl9iDHY8wyanhQ6VFsuQgyQ5nCfi0= +github.com/multiversx/mx-chain-core-go v1.2.17-0.20230926094053-ab2114ef6c28/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84= github.com/multiversx/mx-chain-crypto-go v1.2.8 h1:wOgVlUaO5X4L8iEbFjcQcL8SZvv6WZ7LqH73BiRPhxU= github.com/multiversx/mx-chain-crypto-go v1.2.8/go.mod h1:fkaWKp1rbQN9wPKya5jeoRyC+c/SyN/NfggreyeBw+8= github.com/multiversx/mx-chain-es-indexer-go v1.4.12 h1:KpKcflrXEFXRjWOSIjytNgvSsxl9J/YvyhvoDQR9Pto= diff --git a/node/node.go b/node/node.go index b9a504d0914..85e49270495 100644 --- a/node/node.go +++ b/node/node.go @@ -54,8 +54,7 @@ var log = logger.GetOrCreate("node") var _ facade.NodeHandler = (*Node)(nil) // Option represents a functional configuration parameter that can operate -// -// over the None struct. +// over the None struct. type Option func(*Node) error type filter interface { @@ -777,6 +776,7 @@ func (n *Node) commonTransactionValidation( enableSignWithTxHash, n.coreComponents.TxSignHasher(), n.coreComponents.TxVersionChecker(), + n.coreComponents.EnableEpochsHandler(), ) if err != nil { return nil, nil, err diff --git a/process/coordinator/transactionType.go b/process/coordinator/transactionType.go index 834db6633f9..b7eb90d2b84 100644 --- a/process/coordinator/transactionType.go +++ b/process/coordinator/transactionType.go @@ -7,7 +7,6 @@ import ( "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/smartContractResult" - "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-core-go/data/vm" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/process" @@ -17,10 +16,6 @@ import ( var _ process.TxTypeHandler = (*txTypeHandler)(nil) -type relayedV3TransactionHandler interface { - GetInnerTransaction() *transaction.Transaction -} - type txTypeHandler struct { pubkeyConv core.PubkeyConverter shardCoordinator sharding.Coordinator @@ -195,12 +190,7 @@ func (tth *txTypeHandler) isRelayedTransactionV2(functionName string) bool { } func (tth *txTypeHandler) isRelayedTransactionV3(tx data.TransactionHandler) bool { - rtx, ok := tx.(relayedV3TransactionHandler) - if !ok { - return false - } - - return rtx.GetInnerTransaction() != nil + return !check.IfNil(tx.GetUserTransaction()) } func (tth *txTypeHandler) isDestAddressEmpty(tx data.TransactionHandler) bool { diff --git a/process/interceptors/factory/interceptedTxDataFactory.go b/process/interceptors/factory/interceptedTxDataFactory.go index b35debbc061..0add95ac08f 100644 --- a/process/interceptors/factory/interceptedTxDataFactory.go +++ b/process/interceptors/factory/interceptedTxDataFactory.go @@ -130,6 +130,7 @@ func (itdf *interceptedTxDataFactory) Create(buff []byte) (process.InterceptedDa itdf.enableEpochsHandler.IsTransactionSignedWithTxHashFlagEnabled(), itdf.txSignHasher, itdf.txVersionChecker, + itdf.enableEpochsHandler, ) } diff --git a/process/transaction/interceptedTransaction.go b/process/transaction/interceptedTransaction.go index 4ab39f4f7bc..6c9c2b6bd68 100644 --- a/process/transaction/interceptedTransaction.go +++ b/process/transaction/interceptedTransaction.go @@ -13,6 +13,7 @@ import ( "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" "github.com/multiversx/mx-chain-crypto-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/sharding" logger "github.com/multiversx/mx-chain-logger-go" @@ -42,6 +43,7 @@ type InterceptedTransaction struct { sndShard uint32 isForCurrentShard bool enableSignedTxWithHash bool + enableEpochsHandler common.EnableEpochsHandler } // NewInterceptedTransaction returns a new instance of InterceptedTransaction @@ -61,6 +63,7 @@ func NewInterceptedTransaction( enableSignedTxWithHash bool, txSignHasher hashing.Hasher, txVersionChecker process.TxVersionCheckerHandler, + enableEpochsHandler common.EnableEpochsHandler, ) (*InterceptedTransaction, error) { if txBuff == nil { @@ -105,6 +108,9 @@ func NewInterceptedTransaction( if check.IfNil(txVersionChecker) { return nil, process.ErrNilTransactionVersionChecker } + if check.IfNil(enableEpochsHandler) { + return nil, process.ErrNilEnableEpochsHandler + } tx, err := createTx(protoMarshalizer, txBuff) if err != nil { @@ -127,6 +133,7 @@ func NewInterceptedTransaction( enableSignedTxWithHash: enableSignedTxWithHash, txVersionChecker: txVersionChecker, txSignHasher: txSignHasher, + enableEpochsHandler: enableEpochsHandler, } err = inTx.processFields(txBuff) @@ -220,6 +227,9 @@ func (inTx *InterceptedTransaction) verifyIfRelayedTxV3(tx *transaction.Transact if tx.InnerTransaction == nil { return nil } + if !inTx.enableEpochsHandler.IsRelayedTransactionsV3FlagEnabled() { + return process.ErrRelayedTxV3Disabled + } innerTx := tx.InnerTransaction if !bytes.Equal(innerTx.SndAddr, tx.RcvAddr) { diff --git a/process/transaction/interceptedTransaction_test.go b/process/transaction/interceptedTransaction_test.go index fda79c3bf34..cc47cc146da 100644 --- a/process/transaction/interceptedTransaction_test.go +++ b/process/transaction/interceptedTransaction_test.go @@ -21,6 +21,7 @@ import ( "github.com/multiversx/mx-chain-go/process/transaction" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/economicsmocks" + "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" logger "github.com/multiversx/mx-chain-logger-go" @@ -113,6 +114,7 @@ func createInterceptedTxWithTxFeeHandlerAndVersionChecker(tx *dataTransaction.Tr false, &hashingMocks.HasherMock{}, txVerChecker, + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ) } @@ -156,6 +158,7 @@ func createInterceptedTxFromPlainTx(tx *dataTransaction.Transaction, txFeeHandle false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(minTxVersion), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ) } @@ -199,6 +202,9 @@ func createInterceptedTxFromPlainTxWithArgParser(tx *dataTransaction.Transaction false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(tx.Version), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{ + IsRelayedTransactionsV3FlagEnabledField: true, + }, ) } @@ -223,6 +229,7 @@ func TestNewInterceptedTransaction_NilBufferShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ) assert.Nil(t, txi) @@ -248,6 +255,7 @@ func TestNewInterceptedTransaction_NilArgsParser(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ) assert.Nil(t, txi) @@ -273,6 +281,7 @@ func TestNewInterceptedTransaction_NilVersionChecker(t *testing.T) { false, &hashingMocks.HasherMock{}, nil, + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ) assert.Nil(t, txi) @@ -298,6 +307,7 @@ func TestNewInterceptedTransaction_NilMarshalizerShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ) assert.Nil(t, txi) @@ -323,6 +333,7 @@ func TestNewInterceptedTransaction_NilSignMarshalizerShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ) assert.Nil(t, txi) @@ -348,6 +359,7 @@ func TestNewInterceptedTransaction_NilHasherShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ) assert.Nil(t, txi) @@ -373,6 +385,7 @@ func TestNewInterceptedTransaction_NilKeyGenShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ) assert.Nil(t, txi) @@ -398,6 +411,7 @@ func TestNewInterceptedTransaction_NilSignerShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ) assert.Nil(t, txi) @@ -423,6 +437,7 @@ func TestNewInterceptedTransaction_NilPubkeyConverterShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ) assert.Nil(t, txi) @@ -448,6 +463,7 @@ func TestNewInterceptedTransaction_NilCoordinatorShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ) assert.Nil(t, txi) @@ -473,6 +489,7 @@ func TestNewInterceptedTransaction_NilFeeHandlerShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ) assert.Nil(t, txi) @@ -498,6 +515,7 @@ func TestNewInterceptedTransaction_NilWhiteListerVerifiedTxsShouldErr(t *testing false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ) assert.Nil(t, txi) @@ -523,6 +541,7 @@ func TestNewInterceptedTransaction_InvalidChainIDShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ) assert.Nil(t, txi) @@ -548,12 +567,39 @@ func TestNewInterceptedTransaction_NilTxSignHasherShouldErr(t *testing.T) { false, nil, versioning.NewTxVersionChecker(1), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ) assert.Nil(t, txi) assert.Equal(t, process.ErrNilHasher, err) } +func TestNewInterceptedTransaction_NilEnableEpochsHandlerShouldErr(t *testing.T) { + t.Parallel() + + txi, err := transaction.NewInterceptedTransaction( + make([]byte, 0), + &mock.MarshalizerMock{}, + &mock.MarshalizerMock{}, + &hashingMocks.HasherMock{}, + &mock.SingleSignKeyGenMock{}, + &mock.SignerMock{}, + createMockPubKeyConverter(), + mock.NewOneShardCoordinatorMock(), + &economicsmocks.EconomicsHandlerStub{}, + &testscommon.WhiteListHandlerStub{}, + &mock.ArgumentParserMock{}, + []byte("chainID"), + false, + &hashingMocks.HasherMock{}, + versioning.NewTxVersionChecker(1), + nil, + ) + + assert.Nil(t, txi) + assert.Equal(t, process.ErrNilEnableEpochsHandler, err) +} + func TestNewInterceptedTransaction_UnmarshalingTxFailsShouldErr(t *testing.T) { t.Parallel() @@ -579,6 +625,7 @@ func TestNewInterceptedTransaction_UnmarshalingTxFailsShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ) assert.Nil(t, txi) @@ -1049,6 +1096,7 @@ func TestInterceptedTransaction_CheckValiditySignedWithHashButNotEnabled(t *test false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(minTxVersion), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ) err := txi.CheckValidity() @@ -1109,6 +1157,7 @@ func TestInterceptedTransaction_CheckValiditySignedWithHashShouldWork(t *testing true, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(minTxVersion), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ) err := txi.CheckValidity() @@ -1194,6 +1243,7 @@ func TestInterceptedTransaction_ScTxDeployRecvShardIdShouldBeSendersShardId(t *t false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(minTxVersion), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ) assert.Nil(t, err) @@ -1358,6 +1408,7 @@ func TestInterceptedTransaction_CheckValiditySecondTimeDoesNotVerifySig(t *testi false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(minTxVersion), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ) require.Nil(t, err) @@ -1596,6 +1647,35 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { txi, _ = createInterceptedTxFromPlainTxWithArgParser(tx) err = txi.CheckValidity() assert.NotNil(t, err) + + marshalizer := &mock.MarshalizerMock{} + txBuff, _ := marshalizer.Marshal(tx) + txi, _ = transaction.NewInterceptedTransaction( + txBuff, + marshalizer, + marshalizer, + &hashingMocks.HasherMock{}, + createKeyGenMock(), + createDummySigner(), + &testscommon.PubkeyConverterStub{ + LenCalled: func() int { + return 32 + }, + }, + mock.NewMultipleShardsCoordinatorMock(), + createFreeTxFeeHandler(), + &testscommon.WhiteListHandlerStub{}, + &mock.ArgumentParserMock{}, + tx.ChainID, + false, + &hashingMocks.HasherMock{}, + versioning.NewTxVersionChecker(0), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + ) + + assert.NotNil(t, txi) + err = txi.CheckValidity() + assert.Equal(t, process.ErrRelayedTxV3Disabled, err) } // ------- IsInterfaceNil @@ -1727,6 +1807,7 @@ func TestInterceptedTransaction_Fee(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(0), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ) assert.Equal(t, big.NewInt(0), txin.Fee()) @@ -1770,6 +1851,7 @@ func TestInterceptedTransaction_String(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(0), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ) expectedFormat := fmt.Sprintf( From 81603cc781a6a26e365a039951262c73c32130d0 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 26 Sep 2023 13:24:10 +0300 Subject: [PATCH 009/503] fixed failing tests --- node/node_test.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/node/node_test.go b/node/node_test.go index b59ade01fc6..889c4814bb8 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -5070,18 +5070,19 @@ func getDefaultCoreComponents() *nodeMockFactory.CoreComponentsMock { MinTransactionVersionCalled: func() uint32 { return 1 }, - WDTimer: &testscommon.WatchdogMock{}, - Alarm: &testscommon.AlarmSchedulerStub{}, - NtpTimer: &testscommon.SyncTimerStub{}, - RoundHandlerField: &testscommon.RoundHandlerMock{}, - EconomicsHandler: &economicsmocks.EconomicsHandlerMock{}, - APIEconomicsHandler: &economicsmocks.EconomicsHandlerMock{}, - RatingsConfig: &testscommon.RatingsInfoMock{}, - RatingHandler: &testscommon.RaterMock{}, - NodesConfig: &testscommon.NodesSetupStub{}, - StartTime: time.Time{}, - EpochChangeNotifier: &epochNotifier.EpochNotifierStub{}, - TxVersionCheckHandler: versioning.NewTxVersionChecker(0), + WDTimer: &testscommon.WatchdogMock{}, + Alarm: &testscommon.AlarmSchedulerStub{}, + NtpTimer: &testscommon.SyncTimerStub{}, + RoundHandlerField: &testscommon.RoundHandlerMock{}, + EconomicsHandler: &economicsmocks.EconomicsHandlerMock{}, + APIEconomicsHandler: &economicsmocks.EconomicsHandlerMock{}, + RatingsConfig: &testscommon.RatingsInfoMock{}, + RatingHandler: &testscommon.RaterMock{}, + NodesConfig: &testscommon.NodesSetupStub{}, + StartTime: time.Time{}, + EpochChangeNotifier: &epochNotifier.EpochNotifierStub{}, + TxVersionCheckHandler: versioning.NewTxVersionChecker(0), + EnableEpochsHandlerField: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, } } From 34f868d8305393e1f050b0b7be388a8f437adbc8 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 4 Oct 2023 16:44:48 +0300 Subject: [PATCH 010/503] added separate fee handling for inner tx of type move balance --- cmd/node/config/enableEpochs.toml | 3 ++ common/constants.go | 3 ++ common/enablers/enableEpochsHandler.go | 1 + common/enablers/enableEpochsHandler_test.go | 4 ++ common/enablers/epochFlags.go | 7 +++ common/interface.go | 1 + config/epochConfig.go | 1 + config/tomlConfig_test.go | 4 ++ genesis/process/shardGenesisBlockCreator.go | 1 + .../multiShard/relayedTx/common.go | 40 ++++++++++----- .../relayedTx/edgecases/edgecases_test.go | 31 ++++++++---- .../multiShard/relayedTx/relayedTx_test.go | 30 +++++++----- .../multiShard/smartContract/dns/dns_test.go | 2 +- integrationTests/testProcessorNode.go | 1 + .../vm/txsFee/guardAccount_test.go | 21 ++++---- .../multiShard/relayedMoveBalance_test.go | 49 ++++++++++++------- .../vm/txsFee/relayedMoveBalance_test.go | 32 ++++++------ node/metrics/metrics.go | 1 + node/metrics/metrics_test.go | 2 + process/transaction/baseProcess.go | 11 ++++- process/transaction/export_test.go | 19 +++++-- process/transaction/metaProcess.go | 5 +- process/transaction/shardProcess.go | 37 ++++++++++++-- process/transaction/shardProcess_test.go | 21 ++++---- sharding/mock/enableEpochsHandlerMock.go | 5 ++ .../enableEpochsHandlerStub.go | 9 ++++ 26 files changed, 238 insertions(+), 103 deletions(-) diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index 415ca4be7ad..30a7ea43716 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -281,6 +281,9 @@ # RelayedTransactionsV3EnableEpoch represents the epoch when the relayed transactions V3 will be enabled RelayedTransactionsV3EnableEpoch = 3 + # FixRelayedMoveBalanceEnableEpoch represents the epoch when the fix for relayed for move balance will be enabled + FixRelayedMoveBalanceEnableEpoch = 3 + # BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers BLSMultiSignerEnableEpoch = [ { EnableEpoch = 0, Type = "no-KOSK" }, diff --git a/common/constants.go b/common/constants.go index c1205fd3f1e..31f7b5f5e36 100644 --- a/common/constants.go +++ b/common/constants.go @@ -479,6 +479,9 @@ const ( // MetricRelayedTransactionsV3EnableEpoch represents the epoch when the relayed transactions v3 is enabled MetricRelayedTransactionsV3EnableEpoch = "erd_relayed_transactions_v3_enable_epoch" + // MetricFixRelayedMoveBalanceEnableEpoch represents the epoch when the fix for relayed move balance is enabled + MetricFixRelayedMoveBalanceEnableEpoch = "erd_fix_relayed_move_balance_enable_epoch" + // MetricUnbondTokensV2EnableEpoch represents the epoch when the unbond tokens v2 is applied MetricUnbondTokensV2EnableEpoch = "erd_unbond_tokens_v2_enable_epoch" diff --git a/common/enablers/enableEpochsHandler.go b/common/enablers/enableEpochsHandler.go index 63106ea68c7..3700ed9693b 100644 --- a/common/enablers/enableEpochsHandler.go +++ b/common/enablers/enableEpochsHandler.go @@ -131,6 +131,7 @@ func (handler *enableEpochsHandler) EpochConfirmed(epoch uint32, _ uint64) { handler.setFlagValue(epoch >= handler.enableEpochsConfig.SCProcessorV2EnableEpoch, handler.scProcessorV2Flag, "scProcessorV2Flag", epoch, handler.enableEpochsConfig.SCProcessorV2EnableEpoch) handler.setFlagValue(epoch >= handler.enableEpochsConfig.DynamicGasCostForDataTrieStorageLoadEnableEpoch, handler.dynamicGasCostForDataTrieStorageLoadFlag, "dynamicGasCostForDataTrieStorageLoadFlag", epoch, handler.enableEpochsConfig.DynamicGasCostForDataTrieStorageLoadEnableEpoch) handler.setFlagValue(epoch >= handler.enableEpochsConfig.RelayedTransactionsV3EnableEpoch, handler.relayedTransactionsV3Flag, "relayedTransactionsV3Flag", epoch, handler.enableEpochsConfig.RelayedTransactionsV3EnableEpoch) + handler.setFlagValue(epoch >= handler.enableEpochsConfig.FixRelayedMoveBalanceEnableEpoch, handler.fixRelayedMoveBalanceFlag, "fixRelayedMoveBalanceFlag", epoch, handler.enableEpochsConfig.FixRelayedMoveBalanceEnableEpoch) } func (handler *enableEpochsHandler) setFlagValue(value bool, flag *atomic.Flag, flagName string, epoch uint32, flagEpoch uint32) { diff --git a/common/enablers/enableEpochsHandler_test.go b/common/enablers/enableEpochsHandler_test.go index 487eb8502e0..2be7d3dd896 100644 --- a/common/enablers/enableEpochsHandler_test.go +++ b/common/enablers/enableEpochsHandler_test.go @@ -105,6 +105,7 @@ func createEnableEpochsConfig() config.EnableEpochs { DeterministicSortOnValidatorsInfoEnableEpoch: 79, ScToScLogEventEnableEpoch: 88, RelayedTransactionsV3EnableEpoch: 89, + FixRelayedMoveBalanceEnableEpoch: 90, } } @@ -249,6 +250,7 @@ func TestNewEnableEpochsHandler_EpochConfirmed(t *testing.T) { assert.True(t, handler.IsESDTNFTImprovementV1FlagEnabled()) assert.True(t, handler.FixDelegationChangeOwnerOnAccountEnabled()) assert.True(t, handler.IsRelayedTransactionsV3FlagEnabled()) + assert.True(t, handler.IsFixRelayedMoveBalanceFlagEnabled()) }) t.Run("flags with == condition should not be set, the ones with >= should be set", func(t *testing.T) { t.Parallel() @@ -369,6 +371,7 @@ func TestNewEnableEpochsHandler_EpochConfirmed(t *testing.T) { assert.True(t, handler.IsESDTNFTImprovementV1FlagEnabled()) assert.True(t, handler.FixDelegationChangeOwnerOnAccountEnabled()) assert.True(t, handler.IsRelayedTransactionsV3FlagEnabled()) + assert.True(t, handler.IsFixRelayedMoveBalanceFlagEnabled()) }) t.Run("flags with < should be set", func(t *testing.T) { t.Parallel() @@ -484,6 +487,7 @@ func TestNewEnableEpochsHandler_EpochConfirmed(t *testing.T) { assert.False(t, handler.IsESDTNFTImprovementV1FlagEnabled()) assert.False(t, handler.FixDelegationChangeOwnerOnAccountEnabled()) assert.False(t, handler.IsRelayedTransactionsV3FlagEnabled()) + assert.False(t, handler.IsFixRelayedMoveBalanceFlagEnabled()) }) } diff --git a/common/enablers/epochFlags.go b/common/enablers/epochFlags.go index 923dcb615da..e8b8cf5a0d6 100644 --- a/common/enablers/epochFlags.go +++ b/common/enablers/epochFlags.go @@ -103,6 +103,7 @@ type epochFlagsHolder struct { fixDelegationChangeOwnerOnAccountFlag *atomic.Flag dynamicGasCostForDataTrieStorageLoadFlag *atomic.Flag relayedTransactionsV3Flag *atomic.Flag + fixRelayedMoveBalanceFlag *atomic.Flag } func newEpochFlagsHolder() *epochFlagsHolder { @@ -205,6 +206,7 @@ func newEpochFlagsHolder() *epochFlagsHolder { fixDelegationChangeOwnerOnAccountFlag: &atomic.Flag{}, dynamicGasCostForDataTrieStorageLoadFlag: &atomic.Flag{}, relayedTransactionsV3Flag: &atomic.Flag{}, + fixRelayedMoveBalanceFlag: &atomic.Flag{}, } } @@ -746,6 +748,11 @@ func (holder *epochFlagsHolder) IsRelayedTransactionsV3FlagEnabled() bool { return holder.relayedTransactionsV3Flag.IsSet() } +// IsFixRelayedMoveBalanceFlagEnabled returns true if fixRelayedMoveBalanceFlag is enabled +func (holder *epochFlagsHolder) IsFixRelayedMoveBalanceFlagEnabled() bool { + return holder.fixRelayedMoveBalanceFlag.IsSet() +} + // IsDynamicGasCostForDataTrieStorageLoadEnabled returns true if dynamicGasCostForDataTrieStorageLoadFlag is enabled func (holder *epochFlagsHolder) IsDynamicGasCostForDataTrieStorageLoadEnabled() bool { return holder.dynamicGasCostForDataTrieStorageLoadFlag.IsSet() diff --git a/common/interface.go b/common/interface.go index bf3f36726c3..c1ed62d03ec 100644 --- a/common/interface.go +++ b/common/interface.go @@ -396,6 +396,7 @@ type EnableEpochsHandler interface { IsDynamicGasCostForDataTrieStorageLoadEnabled() bool FixDelegationChangeOwnerOnAccountEnabled() bool IsRelayedTransactionsV3FlagEnabled() bool + IsFixRelayedMoveBalanceFlagEnabled() bool IsInterfaceNil() bool } diff --git a/config/epochConfig.go b/config/epochConfig.go index 72763f95c73..7c196c1e7bb 100644 --- a/config/epochConfig.go +++ b/config/epochConfig.go @@ -106,6 +106,7 @@ type EnableEpochs struct { FixDelegationChangeOwnerOnAccountEnableEpoch uint32 DynamicGasCostForDataTrieStorageLoadEnableEpoch uint32 RelayedTransactionsV3EnableEpoch uint32 + FixRelayedMoveBalanceEnableEpoch uint32 BLSMultiSignerEnableEpoch []MultiSignerConfig } diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index aefb06fa03d..1e8410a99ee 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -820,6 +820,9 @@ func TestEnableEpochConfig(t *testing.T) { # RelayedTransactionsV3EnableEpoch represents the epoch when the relayed transactions V3 will be enabled RelayedTransactionsV3EnableEpoch = 89 + # FixRelayedMoveBalanceEnableEpoch represents the epoch when the fix for relayed for move balance will be enabled + FixRelayedMoveBalanceEnableEpoch = 90 + # MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MaxNodesChangeEnableEpoch = [ { EpochEnable = 44, MaxNumNodes = 2169, NodesToShufflePerShard = 80 }, @@ -929,6 +932,7 @@ func TestEnableEpochConfig(t *testing.T) { FixDelegationChangeOwnerOnAccountEnableEpoch: 87, ScToScLogEventEnableEpoch: 88, RelayedTransactionsV3EnableEpoch: 89, + FixRelayedMoveBalanceEnableEpoch: 90, MaxNodesChangeEnableEpoch: []MaxNodesChangeConfig{ { EpochEnable: 44, diff --git a/genesis/process/shardGenesisBlockCreator.go b/genesis/process/shardGenesisBlockCreator.go index a59dbe0ec01..e6ec6592b22 100644 --- a/genesis/process/shardGenesisBlockCreator.go +++ b/genesis/process/shardGenesisBlockCreator.go @@ -150,6 +150,7 @@ func createGenesisConfig() config.EnableEpochs { SetGuardianEnableEpoch: unreachableEpoch, ScToScLogEventEnableEpoch: unreachableEpoch, RelayedTransactionsV3EnableEpoch: unreachableEpoch, + FixRelayedMoveBalanceEnableEpoch: unreachableEpoch, } } diff --git a/integrationTests/multiShard/relayedTx/common.go b/integrationTests/multiShard/relayedTx/common.go index 0d8af34b244..27537b1556b 100644 --- a/integrationTests/multiShard/relayedTx/common.go +++ b/integrationTests/multiShard/relayedTx/common.go @@ -59,7 +59,7 @@ func CreateAndSendRelayedAndUserTx( value *big.Int, gasLimit uint64, txData []byte, -) *transaction.Transaction { +) (*transaction.Transaction, *transaction.Transaction) { txDispatcherNode := getNodeWithinSameShardAsPlayer(nodes, relayer.Address) userTx := createUserTx(player, rcvAddr, value, gasLimit, txData, nil) @@ -70,7 +70,7 @@ func CreateAndSendRelayedAndUserTx( fmt.Println(err.Error()) } - return relayedTx + return relayedTx, userTx } // CreateAndSendRelayedAndUserTxV2 will create and send a relayed user transaction for relayed v2 @@ -82,7 +82,7 @@ func CreateAndSendRelayedAndUserTxV2( value *big.Int, gasLimit uint64, txData []byte, -) *transaction.Transaction { +) (*transaction.Transaction, *transaction.Transaction) { txDispatcherNode := getNodeWithinSameShardAsPlayer(nodes, relayer.Address) userTx := createUserTx(player, rcvAddr, value, 0, txData, nil) @@ -93,7 +93,7 @@ func CreateAndSendRelayedAndUserTxV2( fmt.Println(err.Error()) } - return relayedTx + return relayedTx, userTx } // CreateAndSendRelayedAndUserTxV3 will create and send a relayed user transaction for relayed v3 @@ -105,7 +105,7 @@ func CreateAndSendRelayedAndUserTxV3( value *big.Int, gasLimit uint64, txData []byte, -) *transaction.Transaction { +) (*transaction.Transaction, *transaction.Transaction) { txDispatcherNode := getNodeWithinSameShardAsPlayer(nodes, relayer.Address) userTx := createUserTx(player, rcvAddr, value, gasLimit, txData, relayer.Address) @@ -116,7 +116,7 @@ func CreateAndSendRelayedAndUserTxV3( fmt.Println(err.Error()) } - return relayedTx + return relayedTx, userTx } func createUserTx( @@ -142,6 +142,7 @@ func createUserTx( txBuff, _ := tx.GetDataForSigning(integrationTests.TestAddressPubkeyConverter, integrationTests.TestTxSignMarshalizer, integrationTests.TestTxSignHasher) tx.Signature, _ = player.SingleSigner.Sign(player.SkTxSign, txBuff) player.Nonce++ + player.Balance.Sub(player.Balance, value) return tx } @@ -169,10 +170,11 @@ func createRelayedTx( txBuff, _ := tx.GetDataForSigning(integrationTests.TestAddressPubkeyConverter, integrationTests.TestTxSignMarshalizer, integrationTests.TestTxSignHasher) tx.Signature, _ = relayer.SingleSigner.Sign(relayer.SkTxSign, txBuff) relayer.Nonce++ - txFee := economicsFee.ComputeTxFee(tx) - relayer.Balance.Sub(relayer.Balance, txFee) + relayer.Balance.Sub(relayer.Balance, tx.Value) + subFeesFromRelayer(tx, userTx, economicsFee, relayer) + return tx } @@ -198,10 +200,11 @@ func createRelayedTxV2( txBuff, _ := tx.GetDataForSigning(integrationTests.TestAddressPubkeyConverter, integrationTests.TestTxSignMarshalizer, integrationTests.TestTxSignHasher) tx.Signature, _ = relayer.SingleSigner.Sign(relayer.SkTxSign, txBuff) relayer.Nonce++ - txFee := economicsFee.ComputeTxFee(tx) - relayer.Balance.Sub(relayer.Balance, txFee) + relayer.Balance.Sub(relayer.Balance, tx.Value) + subFeesFromRelayer(tx, userTx, economicsFee, relayer) + return tx } @@ -227,10 +230,11 @@ func createRelayedTxV3( txBuff, _ := tx.GetDataForSigning(integrationTests.TestAddressPubkeyConverter, integrationTests.TestTxSignMarshalizer, integrationTests.TestTxSignHasher) tx.Signature, _ = relayer.SingleSigner.Sign(relayer.SkTxSign, txBuff) relayer.Nonce++ - txFee := economicsFee.ComputeTxFee(tx) - relayer.Balance.Sub(relayer.Balance, txFee) + relayer.Balance.Sub(relayer.Balance, tx.Value) + subFeesFromRelayer(tx, userTx, economicsFee, relayer) + return tx } @@ -286,3 +290,15 @@ func GetUserAccount( } return nil } +func subFeesFromRelayer(tx, userTx *transaction.Transaction, economicsFee process.FeeHandler, relayer *integrationTests.TestWalletAccount) { + if len(userTx.Data) == 0 { // move balance + relayerFee := economicsFee.ComputeMoveBalanceFee(tx) + relayer.Balance.Sub(relayer.Balance, relayerFee) + + userFee := economicsFee.ComputeMoveBalanceFee(userTx) + relayer.Balance.Sub(relayer.Balance, userFee) + } else { + totalFee := economicsFee.ComputeTxFee(tx) + relayer.Balance.Sub(relayer.Balance, totalFee) + } +} diff --git a/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go b/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go index a392d12c86a..560d4ed3449 100644 --- a/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go +++ b/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go @@ -6,8 +6,10 @@ import ( "time" "github.com/multiversx/mx-chain-core-go/core/check" + "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/integrationTests" "github.com/multiversx/mx-chain-go/integrationTests/multiShard/relayedTx" + "github.com/multiversx/mx-chain-go/process" "github.com/stretchr/testify/assert" ) @@ -38,12 +40,10 @@ func TestRelayedTransactionInMultiShardEnvironmentWithNormalTxButWrongNonceShoul for i := int64(0); i < nrRoundsToTest; i++ { for _, player := range players { player.Nonce += 1 - relayerTx := relayedTx.CreateAndSendRelayedAndUserTx(nodes, relayer, player, receiverAddress1, sendValue, integrationTests.MinTxGasLimit, []byte("")) - totalFee := nodes[0].EconomicsData.ComputeTxFee(relayerTx) - totalFees.Add(totalFees, totalFee) - relayerTx = relayedTx.CreateAndSendRelayedAndUserTx(nodes, relayer, player, receiverAddress2, sendValue, integrationTests.MinTxGasLimit, []byte("")) - totalFee = nodes[0].EconomicsData.ComputeTxFee(relayerTx) - totalFees.Add(totalFees, totalFee) + relayerTx, userTx := relayedTx.CreateAndSendRelayedAndUserTx(nodes, relayer, player, receiverAddress1, sendValue, integrationTests.MinTxGasLimit, []byte("")) + appendFeeToTotalFees(relayerTx, userTx, nodes[0].EconomicsData, totalFees) + relayerTx, userTx = relayedTx.CreateAndSendRelayedAndUserTx(nodes, relayer, player, receiverAddress2, sendValue, integrationTests.MinTxGasLimit, []byte("")) + appendFeeToTotalFees(relayerTx, userTx, nodes[0].EconomicsData, totalFees) } round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) @@ -108,10 +108,8 @@ func TestRelayedTransactionInMultiShardEnvironmentWithNormalTxButWithTooMuchGas( for i := int64(0); i < nrRoundsToTest; i++ { for _, player := range players { - _ = relayedTx.CreateAndSendRelayedAndUserTx(nodes, relayer, player, receiverAddress1, sendValue, tooMuchGasLimit, []byte("")) - player.Balance.Sub(player.Balance, sendValue) - _ = relayedTx.CreateAndSendRelayedAndUserTx(nodes, relayer, player, receiverAddress2, sendValue, tooMuchGasLimit, []byte("")) - player.Balance.Sub(player.Balance, sendValue) + _, _ = relayedTx.CreateAndSendRelayedAndUserTx(nodes, relayer, player, receiverAddress1, sendValue, tooMuchGasLimit, []byte("")) + _, _ = relayedTx.CreateAndSendRelayedAndUserTx(nodes, relayer, player, receiverAddress2, sendValue, tooMuchGasLimit, []byte("")) } round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) @@ -151,3 +149,16 @@ func checkPlayerBalancesWithPenalization( assert.Equal(t, userAcc.GetNonce(), players[i].Nonce) } } + +func appendFeeToTotalFees(relayerTx, userTx *transaction.Transaction, economicsData process.EconomicsDataHandler, totalFees *big.Int) { + if len(userTx.Data) == 0 { // move balance + relayerFee := economicsData.ComputeMoveBalanceFee(relayerTx) + totalFees.Add(totalFees, relayerFee) + + userFee := economicsData.ComputeMoveBalanceFee(userTx) + totalFees.Add(totalFees, userFee) + } else { + totalFee := economicsData.ComputeTxFee(relayerTx) + totalFees.Add(totalFees, totalFee) + } +} diff --git a/integrationTests/multiShard/relayedTx/relayedTx_test.go b/integrationTests/multiShard/relayedTx/relayedTx_test.go index bd3c268dac2..3f58ce897a4 100644 --- a/integrationTests/multiShard/relayedTx/relayedTx_test.go +++ b/integrationTests/multiShard/relayedTx/relayedTx_test.go @@ -21,7 +21,15 @@ import ( "github.com/stretchr/testify/require" ) -type createAndSendRelayedAndUserTxFuncType = func([]*integrationTests.TestProcessorNode, *integrationTests.TestWalletAccount, *integrationTests.TestWalletAccount, []byte, *big.Int, uint64, []byte) *transaction.Transaction +type createAndSendRelayedAndUserTxFuncType = func( + nodes []*integrationTests.TestProcessorNode, + relayer *integrationTests.TestWalletAccount, + player *integrationTests.TestWalletAccount, + rcvAddr []byte, + value *big.Int, + gasLimit uint64, + txData []byte, +) (*transaction.Transaction, *transaction.Transaction) func TestRelayedTransactionInMultiShardEnvironmentWithNormalTx(t *testing.T) { t.Run("relayed v1", testRelayedTransactionInMultiShardEnvironmentWithNormalTx(CreateAndSendRelayedAndUserTx)) @@ -78,10 +86,8 @@ func testRelayedTransactionInMultiShardEnvironmentWithNormalTx( for i := int64(0); i < nrRoundsToTest; i++ { for _, player := range players { - _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, receiverAddress1, sendValue, integrationTests.MinTxGasLimit, []byte("")) - player.Balance.Sub(player.Balance, sendValue) - _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, receiverAddress2, sendValue, integrationTests.MinTxGasLimit, []byte("")) - player.Balance.Sub(player.Balance, sendValue) + _, _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, receiverAddress1, sendValue, integrationTests.MinTxGasLimit, []byte("")) + _, _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, receiverAddress2, sendValue, integrationTests.MinTxGasLimit, []byte("")) } round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) @@ -174,9 +180,9 @@ func testRelayedTransactionInMultiShardEnvironmentWithSmartContractTX( integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) for _, player := range players { - _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, scAddress, big.NewInt(0), + _, _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, scAddress, big.NewInt(0), transferTokenFullGas, []byte("transferToken@"+hex.EncodeToString(receiverAddress1)+"@00"+hex.EncodeToString(sendValue.Bytes()))) - _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, scAddress, big.NewInt(0), + _, _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, scAddress, big.NewInt(0), transferTokenFullGas, []byte("transferToken@"+hex.EncodeToString(receiverAddress2)+"@00"+hex.EncodeToString(sendValue.Bytes()))) } @@ -273,8 +279,8 @@ func testRelayedTransactionInMultiShardEnvironmentWithESDTTX( nrRoundsToTest := int64(5) for i := int64(0); i < nrRoundsToTest; i++ { for _, player := range players { - _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, receiverAddress1, big.NewInt(0), transferTokenFullGas, []byte(txData)) - _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, receiverAddress2, big.NewInt(0), transferTokenFullGas, []byte(txData)) + _, _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, receiverAddress1, big.NewInt(0), transferTokenFullGas, []byte(txData)) + _, _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, receiverAddress2, big.NewInt(0), transferTokenFullGas, []byte(txData)) } round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) @@ -353,7 +359,7 @@ func testRelayedTransactionInMultiShardEnvironmentWithAttestationContract( uniqueIDs := make([]string, len(players)) for i, player := range players { uniqueIDs[i] = core.UniqueIdentifier() - _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, scAddress, registerValue, + _, _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, scAddress, registerValue, registerVMGas, []byte("register@"+hex.EncodeToString([]byte(uniqueIDs[i])))) } time.Sleep(time.Second) @@ -383,9 +389,9 @@ func testRelayedTransactionInMultiShardEnvironmentWithAttestationContract( integrationTests.MintAllPlayers(nodes, players, registerValue) for i, player := range players { - _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, scAddress, big.NewInt(0), attestVMGas, + _, _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, scAddress, big.NewInt(0), attestVMGas, []byte("attest@"+hex.EncodeToString([]byte(uniqueIDs[i]))+"@"+hex.EncodeToString([]byte(privateInfos[i])))) - _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, scAddress, registerValue, + _, _ = createAndSendRelayedAndUserTxFunc(nodes, relayer, player, scAddress, registerValue, registerVMGas, []byte("register@"+hex.EncodeToString([]byte(uniqueIDs[i])))) } time.Sleep(time.Second) diff --git a/integrationTests/multiShard/smartContract/dns/dns_test.go b/integrationTests/multiShard/smartContract/dns/dns_test.go index 4265eba8515..bfa317ee3f4 100644 --- a/integrationTests/multiShard/smartContract/dns/dns_test.go +++ b/integrationTests/multiShard/smartContract/dns/dns_test.go @@ -202,7 +202,7 @@ func sendRegisterUserNameAsRelayedTx( for i, player := range players { userName := generateNewUserName() scAddress := selectDNSAddressFromUserName(sortedDNSAddresses, userName) - _ = relayedTx.CreateAndSendRelayedAndUserTx(nodes, relayer, player, []byte(scAddress), dnsRegisterValue, + _, _ = relayedTx.CreateAndSendRelayedAndUserTx(nodes, relayer, player, []byte(scAddress), dnsRegisterValue, gasLimit, []byte("register@"+hex.EncodeToString([]byte(userName)))) userNames[i] = userName } diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index 2c4793f9c37..616321c6f59 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -3235,6 +3235,7 @@ func CreateEnableEpochsConfig() config.EnableEpochs { RefactorPeersMiniBlocksEnableEpoch: UnreachableEpoch, SCProcessorV2EnableEpoch: UnreachableEpoch, RelayedTransactionsV3EnableEpoch: UnreachableEpoch, + FixRelayedMoveBalanceEnableEpoch: UnreachableEpoch, } } diff --git a/integrationTests/vm/txsFee/guardAccount_test.go b/integrationTests/vm/txsFee/guardAccount_test.go index 2baa497f991..dbc45f8514b 100644 --- a/integrationTests/vm/txsFee/guardAccount_test.go +++ b/integrationTests/vm/txsFee/guardAccount_test.go @@ -962,7 +962,7 @@ func TestGuardAccounts_RelayedTransactionV1(t *testing.T) { alice, david, gasPrice, - transferGas+guardianSigVerificationGas, + 1+guardianSigVerificationGas, make([]byte, 0)) userTx.GuardianAddr = bob @@ -970,7 +970,7 @@ func TestGuardAccounts_RelayedTransactionV1(t *testing.T) { userTx.Version = txWithOptionVersion rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := 1 + transferGas + guardianSigVerificationGas + uint64(len(rtxData)) + rTxGasLimit := 1 + guardianSigVerificationGas + 1 + uint64(len(rtxData)) rtx := vm.CreateTransaction(getNonce(testContext, charlie), big.NewInt(0), charlie, alice, gasPrice, rTxGasLimit, rtxData) returnCode, err = testContext.TxProcessor.ProcessTransaction(rtx) require.Nil(t, err) @@ -1001,13 +1001,13 @@ func TestGuardAccounts_RelayedTransactionV1(t *testing.T) { alice, david, gasPrice, - transferGas+guardianSigVerificationGas, + 1, make([]byte, 0)) userTx.Version = txWithOptionVersion rtxData = integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit = 1 + transferGas + guardianSigVerificationGas + uint64(len(rtxData)) + rTxGasLimit = 1 + 1 + uint64(len(rtxData)) rtx = vm.CreateTransaction(getNonce(testContext, charlie), big.NewInt(0), charlie, alice, gasPrice, rTxGasLimit, rtxData) returnCode, err = testContext.TxProcessor.ProcessTransaction(rtx) require.Nil(t, err) @@ -1076,14 +1076,14 @@ func TestGuardAccounts_RelayedTransactionV2(t *testing.T) { testContext.CleanIntermediateTransactions(t) // step 3 - charlie sends a relayed transaction v1 on the behalf of alice - // 3.1 cosigned transaction should work + // 3.1 cosigned transaction should not work userTx := vm.CreateTransaction( getNonce(testContext, alice), transferValue, alice, david, gasPrice, - transferGas+guardianSigVerificationGas, + 1+guardianSigVerificationGas, make([]byte, 0)) userTx.GuardianAddr = bob @@ -1091,7 +1091,7 @@ func TestGuardAccounts_RelayedTransactionV2(t *testing.T) { userTx.Version = txWithOptionVersion rtxData := integrationTests.PrepareRelayedTxDataV2(userTx) - rTxGasLimit := 1 + transferGas + guardianSigVerificationGas + uint64(len(rtxData)) + rTxGasLimit := 1 + guardianSigVerificationGas + 1 + uint64(len(rtxData)) rtx := vm.CreateTransaction(getNonce(testContext, charlie), big.NewInt(0), charlie, alice, gasPrice, rTxGasLimit, rtxData) returnCode, err = testContext.TxProcessor.ProcessTransaction(rtx) require.Nil(t, err) @@ -1110,7 +1110,8 @@ func TestGuardAccounts_RelayedTransactionV2(t *testing.T) { assert.Equal(t, aliceCurrentBalance, getBalance(testContext, alice)) bobExpectedBalance := big.NewInt(0).Set(initialMint) assert.Equal(t, bobExpectedBalance, getBalance(testContext, bob)) - charlieExpectedBalance := big.NewInt(0).Sub(initialMint, big.NewInt(int64(rTxGasLimit*gasPrice))) + charlieConsumed := 1 + 1 + uint64(len(rtxData)) + charlieExpectedBalance := big.NewInt(0).Sub(initialMint, big.NewInt(int64(charlieConsumed*gasPrice))) assert.Equal(t, charlieExpectedBalance, getBalance(testContext, charlie)) assert.Equal(t, initialMint, getBalance(testContext, david)) @@ -1124,13 +1125,13 @@ func TestGuardAccounts_RelayedTransactionV2(t *testing.T) { alice, david, gasPrice, - transferGas+guardianSigVerificationGas, + 1, make([]byte, 0)) userTx.Version = txWithOptionVersion rtxData = integrationTests.PrepareRelayedTxDataV2(userTx) - rTxGasLimit = 1 + transferGas + guardianSigVerificationGas + uint64(len(rtxData)) + rTxGasLimit = 1 + 1 + uint64(len(rtxData)) rtx = vm.CreateTransaction(getNonce(testContext, charlie), big.NewInt(0), charlie, alice, gasPrice, rTxGasLimit, rtxData) returnCode, err = testContext.TxProcessor.ProcessTransaction(rtx) require.Nil(t, err) diff --git a/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go b/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go index 2dd36161143..8c8078633a9 100644 --- a/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go +++ b/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go @@ -33,11 +33,14 @@ func TestRelayedMoveBalanceRelayerShard0InnerTxSenderAndReceiverShard1ShouldWork gasPrice := uint64(10) gasLimit := uint64(100) + _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, big.NewInt(100)) + _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(3000)) + userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, rcvAddr, gasPrice, gasLimit, []byte("aaaa")) rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, userTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) + rTxGasLimit := gasLimit + 1 + uint64(len(rtxData)) + rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) require.Equal(t, vmcommon.Ok, retCode) @@ -54,7 +57,7 @@ func TestRelayedMoveBalanceRelayerShard0InnerTxSenderAndReceiverShard1ShouldWork // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(1000), accumulatedFees) + require.Equal(t, big.NewInt(50), accumulatedFees) } func TestRelayedMoveBalanceRelayerAndInnerTxSenderShard0ReceiverShard1(t *testing.T) { @@ -82,8 +85,8 @@ func TestRelayedMoveBalanceRelayerAndInnerTxSenderShard0ReceiverShard1(t *testin userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, scAddrBytes, gasPrice, gasLimit, nil) rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, userTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) + rTxGasLimit := gasLimit + 1 + uint64(len(rtxData)) + rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) require.Equal(t, vmcommon.UserError, retCode) @@ -99,7 +102,7 @@ func TestRelayedMoveBalanceRelayerAndInnerTxSenderShard0ReceiverShard1(t *testin // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(1000), accumulatedFees) + require.Equal(t, big.NewInt(10), accumulatedFees) } func TestRelayedMoveBalanceExecuteOnSourceAndDestination(t *testing.T) { @@ -129,12 +132,13 @@ func TestRelayedMoveBalanceExecuteOnSourceAndDestination(t *testing.T) { gasLimit := uint64(100) _, _ = vm.CreateAccount(testContextSource.Accounts, relayerAddr, 0, big.NewInt(100000)) + _, _ = vm.CreateAccount(testContextSource.Accounts, sndAddr, 0, big.NewInt(100)) userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, scAddrBytes, gasPrice, gasLimit, nil) rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, userTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) + rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) // execute on source shard retCode, err := testContextSource.TxProcessor.ProcessTransaction(rtx) @@ -142,7 +146,8 @@ func TestRelayedMoveBalanceExecuteOnSourceAndDestination(t *testing.T) { require.Nil(t, err) // check relayed balance - utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, big.NewInt(97270)) + // 100000 - rTxFee(164)*gasPrice(10) - gasLimitForMoveInner(1)*gasPrice(10) = 98360 + utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, big.NewInt(98360)) // check accumulated fees accumulatedFees := testContextSource.TxFeeHandler.GetAccumulatedFees() @@ -163,7 +168,7 @@ func TestRelayedMoveBalanceExecuteOnSourceAndDestination(t *testing.T) { // check accumulated fees accumulatedFees = testContextDst.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(1000), accumulatedFees) + require.Equal(t, big.NewInt(10), accumulatedFees) } func TestRelayedMoveBalanceExecuteOnSourceAndDestinationRelayerAndInnerTxSenderShard0InnerTxReceiverShard1ShouldWork(t *testing.T) { @@ -191,12 +196,13 @@ func TestRelayedMoveBalanceExecuteOnSourceAndDestinationRelayerAndInnerTxSenderS gasLimit := uint64(100) _, _ = vm.CreateAccount(testContextSource.Accounts, relayerAddr, 0, big.NewInt(100000)) + _, _ = vm.CreateAccount(testContextSource.Accounts, sndAddr, 0, big.NewInt(100)) userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, rcvAddr, gasPrice, gasLimit, nil) rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, userTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) + rTxGasLimit := gasLimit + 1 + uint64(len(rtxData)) + rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) // execute on source shard retCode, err := testContextSource.TxProcessor.ProcessTransaction(rtx) @@ -204,13 +210,14 @@ func TestRelayedMoveBalanceExecuteOnSourceAndDestinationRelayerAndInnerTxSenderS require.Nil(t, err) // check relayed balance - utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, big.NewInt(97270)) + // 100000 - rTxFee(164)*gasPrice(10) - gasLimitForMoveInner(1)*gasPrice(10) = 98360 + utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, big.NewInt(98360)) // check inner tx sender utils.TestAccount(t, testContextSource.Accounts, sndAddr, 1, big.NewInt(0)) // check accumulated fees accumulatedFees := testContextSource.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(2630), accumulatedFees) + require.Equal(t, big.NewInt(1640), accumulatedFees) // get scr for destination shard txs := testContextSource.GetIntermediateTransactions(t) @@ -251,12 +258,13 @@ func TestRelayedMoveBalanceRelayerAndInnerTxReceiverShard0SenderShard1(t *testin gasLimit := uint64(100) _, _ = vm.CreateAccount(testContextSource.Accounts, relayerAddr, 0, big.NewInt(100000)) + _, _ = vm.CreateAccount(testContextDst.Accounts, sndAddr, 0, big.NewInt(100)) innerTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, rcvAddr, gasPrice, gasLimit, nil) rtxData := integrationTests.PrepareRelayedTxDataV1(innerTx) rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, innerTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) + rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) // execute on relayer shard retCode, err := testContextSource.TxProcessor.ProcessTransaction(rtx) @@ -264,7 +272,8 @@ func TestRelayedMoveBalanceRelayerAndInnerTxReceiverShard0SenderShard1(t *testin require.Nil(t, err) // check relayed balance - utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, big.NewInt(97270)) + // 100000 - rTxFee(164)*gasPrice(10) - gasLimitForMoveInner(1)*gasPrice(10) = 98360 + utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, big.NewInt(98360)) // check inner Tx receiver innerTxSenderAccount, err := testContextSource.Accounts.GetExistingAccount(sndAddr) @@ -285,7 +294,7 @@ func TestRelayedMoveBalanceRelayerAndInnerTxReceiverShard0SenderShard1(t *testin // check accumulated fees accumulatedFees = testContextDst.TxFeeHandler.GetAccumulatedFees() - expectedAccFees = big.NewInt(1000) + expectedAccFees = big.NewInt(10) require.Equal(t, expectedAccFees, accumulatedFees) txs := testContextDst.GetIntermediateTransactions(t) @@ -327,12 +336,13 @@ func TestMoveBalanceRelayerShard0InnerTxSenderShard1InnerTxReceiverShard2ShouldW gasLimit := uint64(100) _, _ = vm.CreateAccount(testContextRelayer.Accounts, relayerAddr, 0, big.NewInt(100000)) + _, _ = vm.CreateAccount(testContextInnerSource.Accounts, sndAddr, 0, big.NewInt(100)) innerTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, rcvAddr, gasPrice, gasLimit, nil) rtxData := integrationTests.PrepareRelayedTxDataV1(innerTx) rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, innerTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) + rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) // execute on relayer shard retCode, err := testContextRelayer.TxProcessor.ProcessTransaction(rtx) @@ -340,7 +350,8 @@ func TestMoveBalanceRelayerShard0InnerTxSenderShard1InnerTxReceiverShard2ShouldW require.Nil(t, err) // check relayed balance - utils.TestAccount(t, testContextRelayer.Accounts, relayerAddr, 1, big.NewInt(97270)) + // 100000 - rTxFee(164)*gasPrice(10) - gasLimitForMoveInner(1)*gasPrice(10) = 98360 + utils.TestAccount(t, testContextRelayer.Accounts, relayerAddr, 1, big.NewInt(98360)) // check inner Tx receiver innerTxSenderAccount, err := testContextRelayer.Accounts.GetExistingAccount(sndAddr) @@ -361,7 +372,7 @@ func TestMoveBalanceRelayerShard0InnerTxSenderShard1InnerTxReceiverShard2ShouldW // check accumulated fees accumulatedFees = testContextInnerSource.TxFeeHandler.GetAccumulatedFees() - expectedAccFees = big.NewInt(1000) + expectedAccFees = big.NewInt(10) require.Equal(t, expectedAccFees, accumulatedFees) // execute on inner tx receiver shard diff --git a/integrationTests/vm/txsFee/relayedMoveBalance_test.go b/integrationTests/vm/txsFee/relayedMoveBalance_test.go index 2c7e230941d..ecab2f87b85 100644 --- a/integrationTests/vm/txsFee/relayedMoveBalance_test.go +++ b/integrationTests/vm/txsFee/relayedMoveBalance_test.go @@ -28,7 +28,7 @@ func TestRelayedMoveBalanceShouldWork(t *testing.T) { rcvAddr := []byte("12345678901234567890123456789022") senderNonce := uint64(0) - senderBalance := big.NewInt(0) + senderBalance := big.NewInt(100) gasLimit := uint64(100) _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, senderBalance) @@ -38,8 +38,8 @@ func TestRelayedMoveBalanceShouldWork(t *testing.T) { userTx := vm.CreateTransaction(senderNonce, big.NewInt(100), sndAddr, rcvAddr, gasPrice, gasLimit, []byte("aaaa")) rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, userTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) + rTxGasLimit := gasLimit + 1 + uint64(len(rtxData)) + rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) require.Equal(t, vmcommon.Ok, retCode) @@ -49,8 +49,8 @@ func TestRelayedMoveBalanceShouldWork(t *testing.T) { require.Nil(t, err) // check relayer balance - // 3000 - value(100) - gasLimit(275)*gasPrice(10) = 2850 - expectedBalanceRelayer := big.NewInt(150) + // 3000 - rTxFee(175)*gasPrice(10) + gasLimitForMoveInner(5)*gasPrice(10) = 1200 + expectedBalanceRelayer := big.NewInt(1200) vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) // check balance inner tx sender @@ -61,7 +61,7 @@ func TestRelayedMoveBalanceShouldWork(t *testing.T) { // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(2750), accumulatedFees) + require.Equal(t, big.NewInt(1800), accumulatedFees) } func TestRelayedMoveBalanceInvalidGasLimitShouldConsumeGas(t *testing.T) { @@ -80,7 +80,7 @@ func TestRelayedMoveBalanceInvalidGasLimitShouldConsumeGas(t *testing.T) { rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) rTxGasLimit := 2 + userTx.GasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, userTx.Value, relayerAddr, sndAddr, 1, rTxGasLimit, rtxData) + rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, 1, rTxGasLimit, rtxData) _, err = testContext.TxProcessor.ProcessTransaction(rtx) require.Equal(t, process.ErrFailedTransaction, err) @@ -105,14 +105,14 @@ func TestRelayedMoveBalanceInvalidUserTxShouldConsumeGas(t *testing.T) { sndAddr := []byte("12345678901234567890123456789012") rcvAddr := []byte("12345678901234567890123456789022") - _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, big.NewInt(0)) + _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, big.NewInt(100)) userTx := vm.CreateTransaction(1, big.NewInt(100), sndAddr, rcvAddr, 1, 100, []byte("aaaa")) _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(3000)) rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) rTxGasLimit := 1 + userTx.GasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, userTx.Value, relayerAddr, sndAddr, 1, rTxGasLimit, rtxData) + rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, 1, rTxGasLimit, rtxData) retcode, _ := testContext.TxProcessor.ProcessTransaction(rtx) require.Equal(t, vmcommon.UserError, retcode) @@ -120,12 +120,13 @@ func TestRelayedMoveBalanceInvalidUserTxShouldConsumeGas(t *testing.T) { _, err = testContext.Accounts.Commit() require.Nil(t, err) - expectedBalanceRelayer := big.NewInt(2721) + // 3000 - rTxFee(179)*gasPrice(10) - gasLimitForMoveInner(5)*gasPrice(10) = 2821 + expectedBalanceRelayer := big.NewInt(2816) vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(279), accumulatedFees) + require.Equal(t, big.NewInt(184), accumulatedFees) } func TestRelayedMoveBalanceInvalidUserTxValueShouldConsumeGas(t *testing.T) { @@ -139,14 +140,14 @@ func TestRelayedMoveBalanceInvalidUserTxValueShouldConsumeGas(t *testing.T) { sndAddr := []byte("12345678901234567890123456789012") rcvAddr := []byte("12345678901234567890123456789022") - _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, big.NewInt(0)) + _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, big.NewInt(100)) userTx := vm.CreateTransaction(0, big.NewInt(150), sndAddr, rcvAddr, 1, 100, []byte("aaaa")) _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(3000)) rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) rTxGasLimit := 1 + userTx.GasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, big.NewInt(100), relayerAddr, sndAddr, 1, rTxGasLimit, rtxData) + rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, 1, rTxGasLimit, rtxData) retCode, _ := testContext.TxProcessor.ProcessTransaction(rtx) require.Equal(t, vmcommon.UserError, retCode) @@ -154,12 +155,13 @@ func TestRelayedMoveBalanceInvalidUserTxValueShouldConsumeGas(t *testing.T) { _, err = testContext.Accounts.Commit() require.Nil(t, err) - expectedBalanceRelayer := big.NewInt(2725) + // 3000 - rTxFee(175)*gasPrice(10) - gasLimitForMoveInner(5)*gasPrice(10) = 2820 + expectedBalanceRelayer := big.NewInt(2820) vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(275), accumulatedFees) + require.Equal(t, big.NewInt(180), accumulatedFees) } func TestRelayedMoveBalanceHigherNonce(t *testing.T) { diff --git a/node/metrics/metrics.go b/node/metrics/metrics.go index 69865832859..9f0fac7fe81 100644 --- a/node/metrics/metrics.go +++ b/node/metrics/metrics.go @@ -117,6 +117,7 @@ func InitConfigMetrics( appStatusHandler.SetUInt64Value(common.MetricSenderInOutTransferEnableEpoch, uint64(enableEpochs.SenderInOutTransferEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricRelayedTransactionsV2EnableEpoch, uint64(enableEpochs.RelayedTransactionsV2EnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricRelayedTransactionsV3EnableEpoch, uint64(enableEpochs.RelayedTransactionsV3EnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricFixRelayedMoveBalanceEnableEpoch, uint64(enableEpochs.FixRelayedMoveBalanceEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricUnbondTokensV2EnableEpoch, uint64(enableEpochs.UnbondTokensV2EnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricSaveJailedAlwaysEnableEpoch, uint64(enableEpochs.SaveJailedAlwaysEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricValidatorToDelegationEnableEpoch, uint64(enableEpochs.ValidatorToDelegationEnableEpoch)) diff --git a/node/metrics/metrics_test.go b/node/metrics/metrics_test.go index ea5a45ae827..530bdbeb4c7 100644 --- a/node/metrics/metrics_test.go +++ b/node/metrics/metrics_test.go @@ -139,6 +139,7 @@ func TestInitConfigMetrics(t *testing.T) { SetGuardianEnableEpoch: 36, ScToScLogEventEnableEpoch: 37, RelayedTransactionsV3EnableEpoch: 38, + FixRelayedMoveBalanceEnableEpoch: 39, MaxNodesChangeEnableEpoch: []config.MaxNodesChangeConfig{ { EpochEnable: 0, @@ -195,6 +196,7 @@ func TestInitConfigMetrics(t *testing.T) { "erd_set_guardian_feature_enable_epoch": uint32(36), "erd_set_sc_to_sc_log_event_enable_epoch": uint32(37), "erd_relayed_transactions_v3_enable_epoch": uint32(38), + "erd_fix_relayed_move_balance_enable_epoch": uint32(39), } economicsConfig := config.EconomicsConfig{ diff --git a/process/transaction/baseProcess.go b/process/transaction/baseProcess.go index 7f2fe6d4b16..d446034ae1d 100644 --- a/process/transaction/baseProcess.go +++ b/process/transaction/baseProcess.go @@ -117,6 +117,7 @@ func (txProc *baseTxProcessor) checkTxValues( tx *transaction.Transaction, acntSnd, acntDst state.UserAccountHandler, isUserTxOfRelayed bool, + txType process.TransactionType, ) error { err := txProc.verifyGuardian(tx, acntSnd) if err != nil { @@ -145,7 +146,13 @@ func (txProc *baseTxProcessor) checkTxValues( if tx.GasLimit < txProc.economicsFee.ComputeGasLimit(tx) { return process.ErrNotEnoughGasInUserTx } - txFee = txProc.economicsFee.ComputeFeeForProcessing(tx, tx.GasLimit) + shouldConsiderMoveBalanceFee := txType == process.MoveBalance && + txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() + if shouldConsiderMoveBalanceFee { + txFee = txProc.economicsFee.ComputeMoveBalanceFee(tx) + } else { + txFee = txProc.economicsFee.ComputeFeeForProcessing(tx, tx.GasLimit) + } } else { txFee = txProc.economicsFee.ComputeTxFee(tx) } @@ -217,7 +224,7 @@ func (txProc *baseTxProcessor) VerifyTransaction(tx *transaction.Transaction) er return err } - return txProc.checkTxValues(tx, senderAccount, receiverAccount, false) + return txProc.checkTxValues(tx, senderAccount, receiverAccount, false, process.MoveBalance) } // Setting a guardian is allowed with regular transactions on a guarded account diff --git a/process/transaction/export_test.go b/process/transaction/export_test.go index a10b1e2e50c..8e110b78cfa 100644 --- a/process/transaction/export_test.go +++ b/process/transaction/export_test.go @@ -13,19 +13,23 @@ import ( type TxProcessor *txProcessor +// GetAccounts calls the un-exported method getAccounts func (txProc *txProcessor) GetAccounts(adrSrc, adrDst []byte, ) (acntSrc, acntDst state.UserAccountHandler, err error) { return txProc.getAccounts(adrSrc, adrDst) } -func (txProc *txProcessor) CheckTxValues(tx *transaction.Transaction, acntSnd, acntDst state.UserAccountHandler, isUserTxOfRelayed bool) error { - return txProc.checkTxValues(tx, acntSnd, acntDst, isUserTxOfRelayed) +// CheckTxValues calls the un-exported method checkTxValues +func (txProc *txProcessor) CheckTxValues(tx *transaction.Transaction, acntSnd, acntDst state.UserAccountHandler, isUserTxOfRelayed bool, destTxType process.TransactionType) error { + return txProc.checkTxValues(tx, acntSnd, acntDst, isUserTxOfRelayed, destTxType) } +// IncreaseNonce calls IncreaseNonce on the provided account func (txProc *txProcessor) IncreaseNonce(acntSrc state.UserAccountHandler) { acntSrc.IncreaseNonce(1) } +// ProcessTxFee calls the un-exported method processTxFee func (txProc *txProcessor) ProcessTxFee( tx *transaction.Transaction, acntSnd, acntDst state.UserAccountHandler, @@ -35,14 +39,17 @@ func (txProc *txProcessor) ProcessTxFee( return txProc.processTxFee(tx, acntSnd, acntDst, txType, isUserTxOfRelayed) } +// SetWhitelistHandler sets the un-exported field whiteListerVerifiedTxs func (inTx *InterceptedTransaction) SetWhitelistHandler(handler process.WhiteListHandler) { inTx.whiteListerVerifiedTxs = handler } +// IsCrossTxFromMe calls the un-exported method isCrossTxFromMe func (txProc *baseTxProcessor) IsCrossTxFromMe(adrSrc, adrDst []byte) bool { return txProc.isCrossTxFromMe(adrSrc, adrDst) } +// ProcessUserTx calls the un-exported method processUserTx func (txProc *txProcessor) ProcessUserTx( originalTx *transaction.Transaction, userTx *transaction.Transaction, @@ -53,6 +60,7 @@ func (txProc *txProcessor) ProcessUserTx( return txProc.processUserTx(originalTx, userTx, relayedTxValue, relayedNonce, txHash) } +// ProcessMoveBalanceCostRelayedUserTx calls the un-exported method processMoveBalanceCostRelayedUserTx func (txProc *txProcessor) ProcessMoveBalanceCostRelayedUserTx( userTx *transaction.Transaction, userScr *smartContractResult.SmartContractResult, @@ -62,6 +70,7 @@ func (txProc *txProcessor) ProcessMoveBalanceCostRelayedUserTx( return txProc.processMoveBalanceCostRelayedUserTx(userTx, userScr, userAcc, originalTxHash) } +// ExecuteFailedRelayedTransaction calls the un-exported method executeFailedRelayedUserTx func (txProc *txProcessor) ExecuteFailedRelayedTransaction( userTx *transaction.Transaction, relayerAdr []byte, @@ -81,20 +90,22 @@ func (txProc *txProcessor) ExecuteFailedRelayedTransaction( errorMsg) } +// CheckMaxGasPrice calls the un-exported method checkMaxGasPrice func (inTx *InterceptedTransaction) CheckMaxGasPrice() error { return inTx.checkMaxGasPrice() } +// VerifyGuardian calls the un-exported method verifyGuardian func (txProc *txProcessor) VerifyGuardian(tx *transaction.Transaction, account state.UserAccountHandler) error { return txProc.verifyGuardian(tx, account) } -// ShouldIncreaseNonce - +// ShouldIncreaseNonce calls the un-exported method shouldIncreaseNonce func (txProc *txProcessor) ShouldIncreaseNonce(executionErr error) bool { return txProc.shouldIncreaseNonce(executionErr) } -// AddNonExecutableLog - +// AddNonExecutableLog calls the un-exported method addNonExecutableLog func (txProc *txProcessor) AddNonExecutableLog(executionErr error, originalTxHash []byte, originalTx data.TransactionHandler) error { return txProc.addNonExecutableLog(executionErr, originalTxHash, originalTx) } diff --git a/process/transaction/metaProcess.go b/process/transaction/metaProcess.go index 51f2c721552..cd88c64f387 100644 --- a/process/transaction/metaProcess.go +++ b/process/transaction/metaProcess.go @@ -118,7 +118,8 @@ func (txProc *metaTxProcessor) ProcessTransaction(tx *transaction.Transaction) ( txProc.pubkeyConv, ) - err = txProc.checkTxValues(tx, acntSnd, acntDst, false) + txType, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(tx) + err = txProc.checkTxValues(tx, acntSnd, acntDst, false, dstShardTxType) if err != nil { if errors.Is(err, process.ErrUserNameDoesNotMatchInCrossShardTx) { errProcessIfErr := txProc.processIfTxErrorCrossShard(tx, err.Error()) @@ -130,8 +131,6 @@ func (txProc *metaTxProcessor) ProcessTransaction(tx *transaction.Transaction) ( return 0, err } - txType, _ := txProc.txTypeHandler.ComputeTransactionType(tx) - switch txType { case process.SCDeployment: return txProc.processSCDeployment(tx, tx.SndAddr) diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 9eff6c3b122..c30af641b5e 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -185,7 +185,7 @@ func (txProc *txProcessor) ProcessTransaction(tx *transaction.Transaction) (vmco ) txType, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(tx) - err = txProc.checkTxValues(tx, acntSnd, acntDst, false) + err = txProc.checkTxValues(tx, acntSnd, acntDst, false, dstShardTxType) if err != nil { if errors.Is(err, process.ErrInsufficientFunds) { receiptErr := txProc.executingFailedTransaction(tx, acntSnd, err) @@ -377,6 +377,11 @@ func (txProc *txProcessor) processTxFee( if isUserTxOfRelayed { totalCost := txProc.economicsFee.ComputeFeeForProcessing(tx, tx.GasLimit) + shouldConsiderMoveBalanceFee := dstShardTxType == process.MoveBalance && + txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() + if shouldConsiderMoveBalanceFee { + totalCost = txProc.economicsFee.ComputeMoveBalanceFee(tx) + } err := acntSnd.SubFromBalance(totalCost) if err != nil { return nil, nil, err @@ -548,7 +553,7 @@ func (txProc *txProcessor) finishExecutionOfRelayedTx( tx *transaction.Transaction, userTx *transaction.Transaction, ) (vmcommon.ReturnCode, error) { - computedFees := txProc.computeRelayedTxFees(tx) + computedFees := txProc.computeRelayedTxFees(tx, userTx) txHash, err := txProc.processTxAtRelayer(relayerAcnt, computedFees.totalFee, computedFees.relayerFee, tx) if err != nil { return 0, err @@ -710,9 +715,18 @@ func (txProc *txProcessor) processRelayedTx( return txProc.finishExecutionOfRelayedTx(relayerAcnt, acntDst, tx, userTx) } -func (txProc *txProcessor) computeRelayedTxFees(tx *transaction.Transaction) relayedFees { +func (txProc *txProcessor) computeRelayedTxFees(tx, userTx *transaction.Transaction) relayedFees { relayerFee := txProc.economicsFee.ComputeMoveBalanceFee(tx) - totalFee := txProc.economicsFee.ComputeTxFee(tx) + totalFee := big.NewInt(0) + _, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(userTx) + shouldConsiderMoveBalanceFee := dstShardTxType == process.MoveBalance && + txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() + if shouldConsiderMoveBalanceFee { + userFee := txProc.economicsFee.ComputeMoveBalanceFee(userTx) + totalFee = totalFee.Add(relayerFee, userFee) + } else { + totalFee = txProc.economicsFee.ComputeTxFee(tx) + } remainingFee := big.NewInt(0).Sub(totalFee, relayerFee) computedFees := relayedFees{ @@ -744,6 +758,12 @@ func (txProc *txProcessor) removeValueAndConsumedFeeFromUser( } consumedFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, userTx.GasLimit) + _, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(userTx) + shouldConsiderMoveBalanceFee := dstShardTxType == process.MoveBalance && + txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() + if shouldConsiderMoveBalanceFee { + consumedFee = txProc.economicsFee.ComputeMoveBalanceFee(userTx) + } err = userAcnt.SubFromBalance(consumedFee) if err != nil { return err @@ -818,7 +838,7 @@ func (txProc *txProcessor) processUserTx( relayerAdr := originalTx.SndAddr txType, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(userTx) - err = txProc.checkTxValues(userTx, acntSnd, acntDst, true) + err = txProc.checkTxValues(userTx, acntSnd, acntDst, true, dstShardTxType) if err != nil { errRemove := txProc.removeValueAndConsumedFeeFromUser(userTx, relayedTxValue, originalTxHash, originalTx, err) if errRemove != nil { @@ -995,6 +1015,13 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( totalFee.Sub(totalFee, moveBalanceUserFee) } + _, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(userTx) + shouldConsiderMoveBalanceFee := dstShardTxType == process.MoveBalance && + txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() + if shouldConsiderMoveBalanceFee { + totalFee = txProc.economicsFee.ComputeMoveBalanceFee(userTx) + } + txProc.txFeeHandler.ProcessTransactionFee(totalFee, big.NewInt(0), originalTxHash) if !check.IfNil(relayerAcnt) { diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index b5ead7aca4c..1ac39686ded 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -88,7 +88,8 @@ func createArgsForTxProcessor() txproc.ArgsNewTxProcessor { ArgsParser: &mock.ArgumentParserMock{}, ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsPenalizedTooMuchGasFlagEnabledField: true, + IsPenalizedTooMuchGasFlagEnabledField: true, + IsFixRelayedMoveBalanceFlagEnabledField: true, }, GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, TxVersionChecker: &testscommon.TxVersionCheckerStub{}, @@ -481,7 +482,7 @@ func TestTxProcessor_CheckTxValuesHigherNonceShouldErr(t *testing.T) { acnt1.IncreaseNonce(6) - err := execTx.CheckTxValues(&transaction.Transaction{Nonce: 7}, acnt1, nil, false) + err := execTx.CheckTxValues(&transaction.Transaction{Nonce: 7}, acnt1, nil, false, process.InvalidTransaction) assert.Equal(t, process.ErrHigherNonceInTransaction, err) } @@ -495,7 +496,7 @@ func TestTxProcessor_CheckTxValuesLowerNonceShouldErr(t *testing.T) { acnt1.IncreaseNonce(6) - err := execTx.CheckTxValues(&transaction.Transaction{Nonce: 5}, acnt1, nil, false) + err := execTx.CheckTxValues(&transaction.Transaction{Nonce: 5}, acnt1, nil, false, process.InvalidTransaction) assert.Equal(t, process.ErrLowerNonceInTransaction, err) } @@ -509,7 +510,7 @@ func TestTxProcessor_CheckTxValuesInsufficientFundsShouldErr(t *testing.T) { _ = acnt1.AddToBalance(big.NewInt(67)) - err := execTx.CheckTxValues(&transaction.Transaction{Value: big.NewInt(68)}, acnt1, nil, false) + err := execTx.CheckTxValues(&transaction.Transaction{Value: big.NewInt(68)}, acnt1, nil, false, process.InvalidTransaction) assert.Equal(t, process.ErrInsufficientFunds, err) } @@ -529,7 +530,7 @@ func TestTxProcessor_CheckTxValuesMismatchedSenderUsernamesShouldErr(t *testing. SndUserName: []byte("notCorrect"), } - err := execTx.CheckTxValues(tx, senderAcc, nil, false) + err := execTx.CheckTxValues(tx, senderAcc, nil, false, process.InvalidTransaction) assert.Equal(t, process.ErrUserNameDoesNotMatch, err) } @@ -549,7 +550,7 @@ func TestTxProcessor_CheckTxValuesMismatchedReceiverUsernamesShouldErr(t *testin RcvUserName: []byte("notCorrect"), } - err := execTx.CheckTxValues(tx, nil, receiverAcc, false) + err := execTx.CheckTxValues(tx, nil, receiverAcc, false, process.InvalidTransaction) assert.Equal(t, process.ErrUserNameDoesNotMatchInCrossShardTx, err) } @@ -574,7 +575,7 @@ func TestTxProcessor_CheckTxValuesCorrectUserNamesShouldWork(t *testing.T) { RcvUserName: recvAcc.GetUserName(), } - err := execTx.CheckTxValues(tx, senderAcc, recvAcc, false) + err := execTx.CheckTxValues(tx, senderAcc, recvAcc, false, process.InvalidTransaction) assert.Nil(t, err) } @@ -588,7 +589,7 @@ func TestTxProcessor_CheckTxValuesOkValsShouldErr(t *testing.T) { _ = acnt1.AddToBalance(big.NewInt(67)) - err := execTx.CheckTxValues(&transaction.Transaction{Value: big.NewInt(67)}, acnt1, nil, false) + err := execTx.CheckTxValues(&transaction.Transaction{Value: big.NewInt(67)}, acnt1, nil, false, process.MoveBalance) assert.Nil(t, err) } @@ -1456,8 +1457,8 @@ func TestTxProcessor_ProcessTxFeeMoveBalanceUserTx(t *testing.T) { cost, totalCost, err := execTx.ProcessTxFee(tx, acntSnd, nil, process.MoveBalance, true) assert.Nil(t, err) - assert.True(t, cost.Cmp(processingFee) == 0) - assert.True(t, totalCost.Cmp(processingFee) == 0) + assert.True(t, cost.Cmp(moveBalanceFee) == 0) + assert.True(t, totalCost.Cmp(moveBalanceFee) == 0) } func TestTxProcessor_ProcessTxFeeSCInvokeUserTx(t *testing.T) { diff --git a/sharding/mock/enableEpochsHandlerMock.go b/sharding/mock/enableEpochsHandlerMock.go index f0db31772f9..3cf8bb5392d 100644 --- a/sharding/mock/enableEpochsHandlerMock.go +++ b/sharding/mock/enableEpochsHandlerMock.go @@ -633,6 +633,11 @@ func (mock *EnableEpochsHandlerMock) IsRelayedTransactionsV3FlagEnabled() bool { return false } +// IsFixRelayedMoveBalanceFlagEnabled - +func (mock *EnableEpochsHandlerMock) IsFixRelayedMoveBalanceFlagEnabled() bool { + return false +} + // IsInterfaceNil returns true if there is no value under the interface func (mock *EnableEpochsHandlerMock) IsInterfaceNil() bool { return mock == nil diff --git a/testscommon/enableEpochsHandlerMock/enableEpochsHandlerStub.go b/testscommon/enableEpochsHandlerMock/enableEpochsHandlerStub.go index 83acdd39030..39dc8a79fb7 100644 --- a/testscommon/enableEpochsHandlerMock/enableEpochsHandlerStub.go +++ b/testscommon/enableEpochsHandlerMock/enableEpochsHandlerStub.go @@ -130,6 +130,7 @@ type EnableEpochsHandlerStub struct { FixDelegationChangeOwnerOnAccountEnabledField bool IsDynamicGasCostForDataTrieStorageLoadEnabledField bool IsRelayedTransactionsV3FlagEnabledField bool + IsFixRelayedMoveBalanceFlagEnabledField bool } // ResetPenalizedTooMuchGasFlag - @@ -1131,6 +1132,14 @@ func (stub *EnableEpochsHandlerStub) IsRelayedTransactionsV3FlagEnabled() bool { return stub.IsRelayedTransactionsV3FlagEnabledField } +// IsFixRelayedMoveBalanceFlagEnabled - +func (stub *EnableEpochsHandlerStub) IsFixRelayedMoveBalanceFlagEnabled() bool { + stub.RLock() + defer stub.RUnlock() + + return stub.IsFixRelayedMoveBalanceFlagEnabledField +} + // IsInterfaceNil - func (stub *EnableEpochsHandlerStub) IsInterfaceNil() bool { return stub == nil From bd43a1576379e402bbf7d67cf183f2ad205b1980 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 5 Oct 2023 17:57:09 +0300 Subject: [PATCH 011/503] fixes after review --- .../interceptedTransaction_test.go | 173 +++++++++++------- process/transaction/shardProcess_test.go | 2 +- 2 files changed, 108 insertions(+), 67 deletions(-) diff --git a/process/transaction/interceptedTransaction_test.go b/process/transaction/interceptedTransaction_test.go index cc47cc146da..98edab980cc 100644 --- a/process/transaction/interceptedTransaction_test.go +++ b/process/transaction/interceptedTransaction_test.go @@ -1604,78 +1604,119 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { Version: minTxVersion, InnerTransaction: innerTx, } - txi, _ := createInterceptedTxFromPlainTxWithArgParser(tx) - err := txi.CheckValidity() - assert.Nil(t, err) - innerTx.RelayerAddr = nil - txi, _ = createInterceptedTxFromPlainTxWithArgParser(tx) - err = txi.CheckValidity() - assert.Equal(t, process.ErrRelayedTxV3EmptyRelayer, err) - innerTx.RelayerAddr = senderAddress - - innerTx.SndAddr = []byte("34567890123456789012345678901234") - txi, _ = createInterceptedTxFromPlainTxWithArgParser(tx) - err = txi.CheckValidity() - assert.Equal(t, process.ErrRelayedTxV3BeneficiaryDoesNotMatchReceiver, err) - innerTx.SndAddr = recvAddress + t.Run("should work", func(t *testing.T) { + t.Parallel() - innerTx.Signature = nil - txi, _ = createInterceptedTxFromPlainTxWithArgParser(tx) - err = txi.CheckValidity() - assert.NotNil(t, err) + txCopy := *tx + txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) + err := txi.CheckValidity() + assert.Nil(t, err) + }) + t.Run("empty relayer on inner tx address should error", func(t *testing.T) { + t.Parallel() - innerTx.Signature = sigBad - txi, _ = createInterceptedTxFromPlainTxWithArgParser(tx) - err = txi.CheckValidity() - assert.NotNil(t, err) + txCopy := *tx + innerTxCopy := *innerTx + innerTxCopy.RelayerAddr = nil + txCopy.InnerTransaction = &innerTxCopy - innerTx2 := &dataTransaction.Transaction{ - Nonce: 2, - Value: big.NewInt(3), - Data: []byte("data inner tx 2"), - GasLimit: 3, - GasPrice: 4, - RcvAddr: recvAddress, - SndAddr: senderAddress, - Signature: sigOk, - ChainID: chainID, - Version: minTxVersion, - } - innerTx.InnerTransaction = innerTx2 - tx.InnerTransaction = innerTx - txi, _ = createInterceptedTxFromPlainTxWithArgParser(tx) - err = txi.CheckValidity() - assert.NotNil(t, err) + txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) + err := txi.CheckValidity() + assert.Equal(t, process.ErrRelayedTxV3EmptyRelayer, err) + }) + t.Run("different sender on inner tx should error", func(t *testing.T) { + t.Parallel() + + txCopy := *tx + innerTxCopy := *innerTx + innerTxCopy.SndAddr = []byte("34567890123456789012345678901234") + txCopy.InnerTransaction = &innerTxCopy + txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) + err := txi.CheckValidity() + assert.Equal(t, process.ErrRelayedTxV3BeneficiaryDoesNotMatchReceiver, err) + }) + t.Run("empty signature on inner tx should error", func(t *testing.T) { + t.Parallel() + + txCopy := *tx + innerTxCopy := *innerTx + innerTxCopy.Signature = nil + txCopy.InnerTransaction = &innerTxCopy + txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) + err := txi.CheckValidity() + assert.NotNil(t, err) + }) + t.Run("bad signature on inner tx should error", func(t *testing.T) { + t.Parallel() + + txCopy := *tx + innerTxCopy := *innerTx + innerTxCopy.Signature = sigBad + txCopy.InnerTransaction = &innerTxCopy + txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) + err := txi.CheckValidity() + assert.NotNil(t, err) + }) + t.Run("inner tx on inner tx(recursive) should error", func(t *testing.T) { + t.Parallel() + + txCopy := *tx + innerTxCopy := *innerTx + txCopy.InnerTransaction = &innerTxCopy + innerTx2 := &dataTransaction.Transaction{ + Nonce: 2, + Value: big.NewInt(3), + Data: []byte("data inner tx 2"), + GasLimit: 3, + GasPrice: 4, + RcvAddr: recvAddress, + SndAddr: senderAddress, + Signature: sigOk, + ChainID: chainID, + Version: minTxVersion, + } + innerTxCopy.InnerTransaction = innerTx2 + txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) + err := txi.CheckValidity() + assert.NotNil(t, err) + }) - marshalizer := &mock.MarshalizerMock{} - txBuff, _ := marshalizer.Marshal(tx) - txi, _ = transaction.NewInterceptedTransaction( - txBuff, - marshalizer, - marshalizer, - &hashingMocks.HasherMock{}, - createKeyGenMock(), - createDummySigner(), - &testscommon.PubkeyConverterStub{ - LenCalled: func() int { - return 32 + t.Run("relayed v3 not enabled yet should error", func(t *testing.T) { + t.Parallel() + + txCopy := *tx + innerTxCopy := *innerTx + txCopy.InnerTransaction = &innerTxCopy + marshalizer := &mock.MarshalizerMock{} + txBuff, _ := marshalizer.Marshal(&txCopy) + txi, _ := transaction.NewInterceptedTransaction( + txBuff, + marshalizer, + marshalizer, + &hashingMocks.HasherMock{}, + createKeyGenMock(), + createDummySigner(), + &testscommon.PubkeyConverterStub{ + LenCalled: func() int { + return 32 + }, }, - }, - mock.NewMultipleShardsCoordinatorMock(), - createFreeTxFeeHandler(), - &testscommon.WhiteListHandlerStub{}, - &mock.ArgumentParserMock{}, - tx.ChainID, - false, - &hashingMocks.HasherMock{}, - versioning.NewTxVersionChecker(0), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - ) - - assert.NotNil(t, txi) - err = txi.CheckValidity() - assert.Equal(t, process.ErrRelayedTxV3Disabled, err) + mock.NewMultipleShardsCoordinatorMock(), + createFreeTxFeeHandler(), + &testscommon.WhiteListHandlerStub{}, + &mock.ArgumentParserMock{}, + txCopy.ChainID, + false, + &hashingMocks.HasherMock{}, + versioning.NewTxVersionChecker(0), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + ) + + assert.NotNil(t, txi) + err := txi.CheckValidity() + assert.Equal(t, process.ErrRelayedTxV3Disabled, err) + }) } // ------- IsInterfaceNil diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index b5ead7aca4c..d32de0340ff 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -2101,7 +2101,7 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { assert.Equal(t, process.ErrFailedTransaction, err) assert.Equal(t, vmcommon.UserError, returnCode) }) - t.Run("value on relayed tx should error", func(t *testing.T) { + t.Run("value on parent tx should error", func(t *testing.T) { t.Parallel() txCopy := *tx From 075b7464dc528ba6bc8e9f400aec968f6b6b5c2b Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 6 Oct 2023 11:19:42 +0300 Subject: [PATCH 012/503] further fixes after review.. added check for inner tx relayer address to be the same with parent tx sender and removed skip for balance check as it is not needed anymore --- node/external/transactionAPI/unmarshaller.go | 8 ++++++++ process/dataValidators/txValidator.go | 12 ------------ process/errors.go | 3 +++ process/transaction/interceptedTransaction.go | 3 +++ process/transaction/interceptedTransaction_test.go | 14 +++++++++++++- process/transaction/shardProcess.go | 3 +++ process/transaction/shardProcess_test.go | 9 +++++++++ 7 files changed, 39 insertions(+), 13 deletions(-) diff --git a/node/external/transactionAPI/unmarshaller.go b/node/external/transactionAPI/unmarshaller.go index c9526217f4f..197f4d53a46 100644 --- a/node/external/transactionAPI/unmarshaller.go +++ b/node/external/transactionAPI/unmarshaller.go @@ -133,6 +133,10 @@ func (tu *txUnmarshaller) prepareNormalTx(tx *transaction.Transaction) *transact apiTx.GuardianSignature = hex.EncodeToString(tx.GuardianSignature) } + if len(tx.RelayerAddr) > 0 { + apiTx.RelayerAddress = tu.addressPubKeyConverter.SilentEncode(tx.RelayerAddr, log) + } + return apiTx } @@ -163,6 +167,10 @@ func (tu *txUnmarshaller) prepareInvalidTx(tx *transaction.Transaction) *transac apiTx.GuardianSignature = hex.EncodeToString(tx.GuardianSignature) } + if len(tx.RelayerAddr) > 0 { + apiTx.RelayerAddress = tu.addressPubKeyConverter.SilentEncode(tx.RelayerAddr, log) + } + return apiTx } diff --git a/process/dataValidators/txValidator.go b/process/dataValidators/txValidator.go index 1f68840ccb0..9c72be1d89a 100644 --- a/process/dataValidators/txValidator.go +++ b/process/dataValidators/txValidator.go @@ -5,7 +5,6 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" - "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/state" @@ -17,11 +16,6 @@ var _ process.TxValidator = (*txValidator)(nil) var log = logger.GetOrCreate("process/dataValidators") -type relayedV3TransactionHandler interface { - GetInnerTransaction() *transaction.Transaction - GetRelayerAddr() []byte -} - // txValidator represents a tx handler validator that doesn't check the validity of provided txHandler type txValidator struct { accounts state.AccountsAdapter @@ -121,12 +115,6 @@ func (txv *txValidator) getSenderUserAccount( } func (txv *txValidator) checkBalance(interceptedTx process.InterceptedTransactionHandler, account state.UserAccountHandler) error { - rTx, ok := interceptedTx.Transaction().(relayedV3TransactionHandler) - if ok && len(rTx.GetRelayerAddr()) > 0 { - // early return if this is a user tx of relayed v3, no need to check balance - return nil - } - accountBalance := account.GetBalance() txFee := interceptedTx.Fee() if accountBalance.Cmp(txFee) < 0 { diff --git a/process/errors.go b/process/errors.go index b148d65091b..ae5aba75beb 100644 --- a/process/errors.go +++ b/process/errors.go @@ -1239,5 +1239,8 @@ var ErrRelayedTxV3ZeroVal = errors.New("relayed tx v3 value should be 0") // ErrRelayedTxV3EmptyRelayer signals that the inner tx of the relayed v3 does not have a relayer address set var ErrRelayedTxV3EmptyRelayer = errors.New("empty relayer on inner tx of relayed tx v3") +// ErrRelayedTxV3RelayerMismatch signals that the relayer address of the inner tx does not match the real relayer +var ErrRelayedTxV3RelayerMismatch = errors.New("relayed tx v3 relayer mismatch") + // ErrRelayedTxV3GasLimitMismatch signals that relayed tx v3 gas limit is higher than user tx gas limit var ErrRelayedTxV3GasLimitMismatch = errors.New("relayed tx v3 gas limit mismatch") diff --git a/process/transaction/interceptedTransaction.go b/process/transaction/interceptedTransaction.go index 6c9c2b6bd68..3957313a6c1 100644 --- a/process/transaction/interceptedTransaction.go +++ b/process/transaction/interceptedTransaction.go @@ -238,6 +238,9 @@ func (inTx *InterceptedTransaction) verifyIfRelayedTxV3(tx *transaction.Transact if len(innerTx.RelayerAddr) == 0 { return process.ErrRelayedTxV3EmptyRelayer } + if !bytes.Equal(innerTx.RelayerAddr, tx.SndAddr) { + return process.ErrRelayedTxV3RelayerMismatch + } err := inTx.integrity(innerTx) if err != nil { diff --git a/process/transaction/interceptedTransaction_test.go b/process/transaction/interceptedTransaction_test.go index 98edab980cc..61b207098c5 100644 --- a/process/transaction/interceptedTransaction_test.go +++ b/process/transaction/interceptedTransaction_test.go @@ -1613,7 +1613,7 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { err := txi.CheckValidity() assert.Nil(t, err) }) - t.Run("empty relayer on inner tx address should error", func(t *testing.T) { + t.Run("empty relayer on inner tx should error", func(t *testing.T) { t.Parallel() txCopy := *tx @@ -1625,6 +1625,18 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { err := txi.CheckValidity() assert.Equal(t, process.ErrRelayedTxV3EmptyRelayer, err) }) + t.Run("different relayer on inner tx should error", func(t *testing.T) { + t.Parallel() + + txCopy := *tx + innerTxCopy := *innerTx + innerTxCopy.RelayerAddr = []byte("34567890123456789012345678901234") + txCopy.InnerTransaction = &innerTxCopy + + txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) + err := txi.CheckValidity() + assert.Equal(t, process.ErrRelayedTxV3RelayerMismatch, err) + }) t.Run("different sender on inner tx should error", func(t *testing.T) { t.Parallel() diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 9eff6c3b122..a2bb7a835c8 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -632,6 +632,9 @@ func (txProc *txProcessor) processRelayedTxV3( if len(userTx.RelayerAddr) == 0 { return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedTxV3EmptyRelayer) } + if !bytes.Equal(userTx.RelayerAddr, tx.SndAddr) { + return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedTxV3RelayerMismatch) + } if tx.GasPrice != userTx.GasPrice { return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedV3GasPriceMismatch) } diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index d32de0340ff..113707395e2 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -2124,6 +2124,15 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { txCopy.InnerTransaction = &userTxCopy testProcessRelayedTransactionV3(t, &txCopy, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) }) + t.Run("different relayer on inner tx should error", func(t *testing.T) { + t.Parallel() + + txCopy := *tx + userTxCopy := *userTx + userTxCopy.RelayerAddr = []byte("other") + txCopy.InnerTransaction = &userTxCopy + testProcessRelayedTransactionV3(t, &txCopy, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) + }) t.Run("different gas price on inner tx should error", func(t *testing.T) { t.Parallel() From ca23f1b3c9146155fd68e42e55cc31509a176e23 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 6 Oct 2023 11:45:01 +0300 Subject: [PATCH 013/503] added extra check for relayer address on interceptor + fixed tests --- process/dataValidators/txValidator_test.go | 88 ++++--------------- process/transaction/interceptedTransaction.go | 4 + .../interceptedTransaction_test.go | 27 ++++++ 3 files changed, 50 insertions(+), 69 deletions(-) diff --git a/process/dataValidators/txValidator_test.go b/process/dataValidators/txValidator_test.go index bf2eed2d1e7..551b18928d1 100644 --- a/process/dataValidators/txValidator_test.go +++ b/process/dataValidators/txValidator_test.go @@ -390,76 +390,26 @@ func TestTxValidator_CheckTxValidityWrongAccountTypeShouldReturnFalse(t *testing func TestTxValidator_CheckTxValidityTxIsOkShouldReturnTrue(t *testing.T) { t.Parallel() - t.Run("regular tx should work", func(t *testing.T) { - t.Parallel() - - accountNonce := uint64(0) - accountBalance := big.NewInt(10) - adb := getAccAdapter(accountNonce, accountBalance) - shardCoordinator := createMockCoordinator("_", 0) - maxNonceDeltaAllowed := 100 - txValidator, _ := dataValidators.NewTxValidator( - adb, - shardCoordinator, - &testscommon.WhiteListHandlerStub{}, - testscommon.NewPubkeyConverterMock(32), - &testscommon.TxVersionCheckerStub{}, - maxNonceDeltaAllowed, - ) - - addressMock := []byte("address") - currentShard := uint32(0) - txValidatorHandler := getInterceptedTxHandler(currentShard, currentShard, 1, addressMock, big.NewInt(0)) - - result := txValidator.CheckTxValidity(txValidatorHandler) - assert.Nil(t, result) - }) - t.Run("user tx should work and skip balance checks", func(t *testing.T) { - t.Parallel() - - accountNonce := uint64(0) - accountBalance := big.NewInt(10) - adb := getAccAdapter(accountNonce, accountBalance) - shardCoordinator := createMockCoordinator("_", 0) - maxNonceDeltaAllowed := 100 - txValidator, _ := dataValidators.NewTxValidator( - adb, - shardCoordinator, - &testscommon.WhiteListHandlerStub{}, - testscommon.NewPubkeyConverterMock(32), - &testscommon.TxVersionCheckerStub{}, - maxNonceDeltaAllowed, - ) - - addressMock := []byte("address") - currentShard := uint32(0) - interceptedTx := &mock.InterceptedTxHandlerStub{ - SenderShardIdCalled: func() uint32 { - return currentShard - }, - ReceiverShardIdCalled: func() uint32 { - return currentShard - }, - NonceCalled: func() uint64 { - return 1 - }, - SenderAddressCalled: func() []byte { - return addressMock - }, - FeeCalled: func() *big.Int { - assert.Fail(t, "should have not been called") - return big.NewInt(0) - }, - TransactionCalled: func() data.TransactionHandler { - return &transaction.Transaction{ - RelayerAddr: []byte("relayer"), - } - }, - } + accountNonce := uint64(0) + accountBalance := big.NewInt(10) + adb := getAccAdapter(accountNonce, accountBalance) + shardCoordinator := createMockCoordinator("_", 0) + maxNonceDeltaAllowed := 100 + txValidator, _ := dataValidators.NewTxValidator( + adb, + shardCoordinator, + &testscommon.WhiteListHandlerStub{}, + testscommon.NewPubkeyConverterMock(32), + &testscommon.TxVersionCheckerStub{}, + maxNonceDeltaAllowed, + ) - result := txValidator.CheckTxValidity(interceptedTx) - assert.Nil(t, result) - }) + addressMock := []byte("address") + currentShard := uint32(0) + txValidatorHandler := getInterceptedTxHandler(currentShard, currentShard, 1, addressMock, big.NewInt(0)) + + result := txValidator.CheckTxValidity(txValidatorHandler) + assert.Nil(t, result) } func Test_getTxData(t *testing.T) { diff --git a/process/transaction/interceptedTransaction.go b/process/transaction/interceptedTransaction.go index 3957313a6c1..f824f2d917b 100644 --- a/process/transaction/interceptedTransaction.go +++ b/process/transaction/interceptedTransaction.go @@ -211,6 +211,10 @@ func (inTx *InterceptedTransaction) CheckValidity() error { return err } + if len(inTx.tx.RelayerAddr) > 0 { + return fmt.Errorf("%w, relayer address found on transaction", process.ErrWrongTransaction) + } + inTx.whiteListerVerifiedTxs.Add([][]byte{inTx.Hash()}) } diff --git a/process/transaction/interceptedTransaction_test.go b/process/transaction/interceptedTransaction_test.go index 61b207098c5..225908578c3 100644 --- a/process/transaction/interceptedTransaction_test.go +++ b/process/transaction/interceptedTransaction_test.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "math/big" + "strings" "testing" "github.com/multiversx/mx-chain-core-go/core" @@ -1042,6 +1043,32 @@ func TestInterceptedTransaction_CheckValidityOkValsShouldWork(t *testing.T) { assert.Nil(t, err) } +func TestInterceptedTransaction_CheckValidityRelayerAddressShouldError(t *testing.T) { + t.Parallel() + + minTxVersion := uint32(1) + chainID := []byte("chain") + tx := &dataTransaction.Transaction{ + Nonce: 1, + Value: big.NewInt(2), + Data: []byte("data"), + GasLimit: 3, + GasPrice: 4, + RcvAddr: recvAddress, + SndAddr: senderAddress, + Signature: sigOk, + ChainID: chainID, + Version: minTxVersion, + RelayerAddr: []byte("45678901234567890123456789012345"), + } + txi, _ := createInterceptedTxFromPlainTx(tx, createFreeTxFeeHandler(), chainID, minTxVersion) + + err := txi.CheckValidity() + + assert.True(t, errors.Is(err, process.ErrWrongTransaction)) + assert.True(t, strings.Contains(err.Error(), "relayer address found on transaction")) +} + func TestInterceptedTransaction_CheckValiditySignedWithHashButNotEnabled(t *testing.T) { t.Parallel() From a3014e614d03b3d90d5dbf6b55004aa98b01c339 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 26 Oct 2023 18:08:21 +0300 Subject: [PATCH 014/503] fixes after review --- integrationTests/multiShard/relayedTx/common.go | 3 ++- .../multiShard/relayedTx/edgecases/edgecases_test.go | 2 +- process/transaction/baseProcess.go | 2 +- process/transaction/shardProcess.go | 6 +++--- process/transaction/shardProcess_test.go | 3 +++ 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/integrationTests/multiShard/relayedTx/common.go b/integrationTests/multiShard/relayedTx/common.go index 27537b1556b..979b8d62a64 100644 --- a/integrationTests/multiShard/relayedTx/common.go +++ b/integrationTests/multiShard/relayedTx/common.go @@ -290,12 +290,13 @@ func GetUserAccount( } return nil } + func subFeesFromRelayer(tx, userTx *transaction.Transaction, economicsFee process.FeeHandler, relayer *integrationTests.TestWalletAccount) { if len(userTx.Data) == 0 { // move balance relayerFee := economicsFee.ComputeMoveBalanceFee(tx) relayer.Balance.Sub(relayer.Balance, relayerFee) - userFee := economicsFee.ComputeMoveBalanceFee(userTx) + userFee := economicsFee.ComputeTxFee(userTx) relayer.Balance.Sub(relayer.Balance, userFee) } else { totalFee := economicsFee.ComputeTxFee(tx) diff --git a/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go b/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go index 560d4ed3449..b8ef1e58a7b 100644 --- a/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go +++ b/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go @@ -155,7 +155,7 @@ func appendFeeToTotalFees(relayerTx, userTx *transaction.Transaction, economicsD relayerFee := economicsData.ComputeMoveBalanceFee(relayerTx) totalFees.Add(totalFees, relayerFee) - userFee := economicsData.ComputeMoveBalanceFee(userTx) + userFee := economicsData.ComputeTxFee(userTx) totalFees.Add(totalFees, userFee) } else { totalFee := economicsData.ComputeTxFee(relayerTx) diff --git a/process/transaction/baseProcess.go b/process/transaction/baseProcess.go index d446034ae1d..3fba7e8906f 100644 --- a/process/transaction/baseProcess.go +++ b/process/transaction/baseProcess.go @@ -149,7 +149,7 @@ func (txProc *baseTxProcessor) checkTxValues( shouldConsiderMoveBalanceFee := txType == process.MoveBalance && txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() if shouldConsiderMoveBalanceFee { - txFee = txProc.economicsFee.ComputeMoveBalanceFee(tx) + txFee = txProc.economicsFee.ComputeTxFee(tx) } else { txFee = txProc.economicsFee.ComputeFeeForProcessing(tx, tx.GasLimit) } diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 8ef68553112..d968d9cee72 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -380,7 +380,7 @@ func (txProc *txProcessor) processTxFee( shouldConsiderMoveBalanceFee := dstShardTxType == process.MoveBalance && txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() if shouldConsiderMoveBalanceFee { - totalCost = txProc.economicsFee.ComputeMoveBalanceFee(tx) + totalCost = txProc.economicsFee.ComputeTxFee(tx) } err := acntSnd.SubFromBalance(totalCost) if err != nil { @@ -725,7 +725,7 @@ func (txProc *txProcessor) computeRelayedTxFees(tx, userTx *transaction.Transact shouldConsiderMoveBalanceFee := dstShardTxType == process.MoveBalance && txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() if shouldConsiderMoveBalanceFee { - userFee := txProc.economicsFee.ComputeMoveBalanceFee(userTx) + userFee := txProc.economicsFee.ComputeTxFee(userTx) totalFee = totalFee.Add(relayerFee, userFee) } else { totalFee = txProc.economicsFee.ComputeTxFee(tx) @@ -765,7 +765,7 @@ func (txProc *txProcessor) removeValueAndConsumedFeeFromUser( shouldConsiderMoveBalanceFee := dstShardTxType == process.MoveBalance && txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() if shouldConsiderMoveBalanceFee { - consumedFee = txProc.economicsFee.ComputeMoveBalanceFee(userTx) + consumedFee = txProc.economicsFee.ComputeTxFee(userTx) } err = userAcnt.SubFromBalance(consumedFee) if err != nil { diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index bd8b3aa9317..9559a4a57aa 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -1440,6 +1440,9 @@ func TestTxProcessor_ProcessTxFeeMoveBalanceUserTx(t *testing.T) { ComputeFeeForProcessingCalled: func(tx data.TransactionWithFeeHandler, gasToUse uint64) *big.Int { return processingFee }, + ComputeTxFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { + return moveBalanceFee + }, } execTx, _ := txproc.NewTxProcessor(args) From ff9f169d6b9d0c2a067949713af9b83ea244db0a Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 27 Oct 2023 13:41:20 +0300 Subject: [PATCH 015/503] fix tests --- .../vm/txsFee/guardAccount_test.go | 2 +- .../multiShard/relayedMoveBalance_test.go | 28 +++++++++---------- .../vm/txsFee/relayedMoveBalance_test.go | 18 ++++++------ process/transaction/shardProcess.go | 2 +- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/integrationTests/vm/txsFee/guardAccount_test.go b/integrationTests/vm/txsFee/guardAccount_test.go index dbc45f8514b..34be91505e7 100644 --- a/integrationTests/vm/txsFee/guardAccount_test.go +++ b/integrationTests/vm/txsFee/guardAccount_test.go @@ -1110,7 +1110,7 @@ func TestGuardAccounts_RelayedTransactionV2(t *testing.T) { assert.Equal(t, aliceCurrentBalance, getBalance(testContext, alice)) bobExpectedBalance := big.NewInt(0).Set(initialMint) assert.Equal(t, bobExpectedBalance, getBalance(testContext, bob)) - charlieConsumed := 1 + 1 + uint64(len(rtxData)) + charlieConsumed := 1 + guardianSigVerificationGas + 1 + uint64(len(rtxData)) charlieExpectedBalance := big.NewInt(0).Sub(initialMint, big.NewInt(int64(charlieConsumed*gasPrice))) assert.Equal(t, charlieExpectedBalance, getBalance(testContext, charlie)) assert.Equal(t, initialMint, getBalance(testContext, david)) diff --git a/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go b/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go index 8c8078633a9..490fb061234 100644 --- a/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go +++ b/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go @@ -57,7 +57,7 @@ func TestRelayedMoveBalanceRelayerShard0InnerTxSenderAndReceiverShard1ShouldWork // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(50), accumulatedFees) + require.Equal(t, big.NewInt(1000), accumulatedFees) } func TestRelayedMoveBalanceRelayerAndInnerTxSenderShard0ReceiverShard1(t *testing.T) { @@ -102,7 +102,7 @@ func TestRelayedMoveBalanceRelayerAndInnerTxSenderShard0ReceiverShard1(t *testin // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(10), accumulatedFees) + require.Equal(t, big.NewInt(1000), accumulatedFees) } func TestRelayedMoveBalanceExecuteOnSourceAndDestination(t *testing.T) { @@ -146,8 +146,8 @@ func TestRelayedMoveBalanceExecuteOnSourceAndDestination(t *testing.T) { require.Nil(t, err) // check relayed balance - // 100000 - rTxFee(164)*gasPrice(10) - gasLimitForMoveInner(1)*gasPrice(10) = 98360 - utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, big.NewInt(98360)) + // 100000 - rTxFee(163)*gasPrice(10) - txFeeInner(1000) = 97370 + utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, big.NewInt(97370)) // check accumulated fees accumulatedFees := testContextSource.TxFeeHandler.GetAccumulatedFees() @@ -168,7 +168,7 @@ func TestRelayedMoveBalanceExecuteOnSourceAndDestination(t *testing.T) { // check accumulated fees accumulatedFees = testContextDst.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(10), accumulatedFees) + require.Equal(t, big.NewInt(1000), accumulatedFees) } func TestRelayedMoveBalanceExecuteOnSourceAndDestinationRelayerAndInnerTxSenderShard0InnerTxReceiverShard1ShouldWork(t *testing.T) { @@ -210,14 +210,14 @@ func TestRelayedMoveBalanceExecuteOnSourceAndDestinationRelayerAndInnerTxSenderS require.Nil(t, err) // check relayed balance - // 100000 - rTxFee(164)*gasPrice(10) - gasLimitForMoveInner(1)*gasPrice(10) = 98360 - utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, big.NewInt(98360)) + // 100000 - rTxFee(163)*gasPrice(10) - innerTxFee(1000) = 97370 + utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, big.NewInt(97370)) // check inner tx sender utils.TestAccount(t, testContextSource.Accounts, sndAddr, 1, big.NewInt(0)) // check accumulated fees accumulatedFees := testContextSource.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(1640), accumulatedFees) + require.Equal(t, big.NewInt(2630), accumulatedFees) // get scr for destination shard txs := testContextSource.GetIntermediateTransactions(t) @@ -272,8 +272,8 @@ func TestRelayedMoveBalanceRelayerAndInnerTxReceiverShard0SenderShard1(t *testin require.Nil(t, err) // check relayed balance - // 100000 - rTxFee(164)*gasPrice(10) - gasLimitForMoveInner(1)*gasPrice(10) = 98360 - utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, big.NewInt(98360)) + // 100000 - rTxFee(163)*gasPrice(10) - innerTxFee(1000) = 97370 + utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, big.NewInt(97370)) // check inner Tx receiver innerTxSenderAccount, err := testContextSource.Accounts.GetExistingAccount(sndAddr) @@ -294,7 +294,7 @@ func TestRelayedMoveBalanceRelayerAndInnerTxReceiverShard0SenderShard1(t *testin // check accumulated fees accumulatedFees = testContextDst.TxFeeHandler.GetAccumulatedFees() - expectedAccFees = big.NewInt(10) + expectedAccFees = big.NewInt(1000) require.Equal(t, expectedAccFees, accumulatedFees) txs := testContextDst.GetIntermediateTransactions(t) @@ -350,8 +350,8 @@ func TestMoveBalanceRelayerShard0InnerTxSenderShard1InnerTxReceiverShard2ShouldW require.Nil(t, err) // check relayed balance - // 100000 - rTxFee(164)*gasPrice(10) - gasLimitForMoveInner(1)*gasPrice(10) = 98360 - utils.TestAccount(t, testContextRelayer.Accounts, relayerAddr, 1, big.NewInt(98360)) + // 100000 - rTxFee(164)*gasPrice(10) - innerTxFee(1000) = 97370 + utils.TestAccount(t, testContextRelayer.Accounts, relayerAddr, 1, big.NewInt(97370)) // check inner Tx receiver innerTxSenderAccount, err := testContextRelayer.Accounts.GetExistingAccount(sndAddr) @@ -372,7 +372,7 @@ func TestMoveBalanceRelayerShard0InnerTxSenderShard1InnerTxReceiverShard2ShouldW // check accumulated fees accumulatedFees = testContextInnerSource.TxFeeHandler.GetAccumulatedFees() - expectedAccFees = big.NewInt(10) + expectedAccFees = big.NewInt(1000) require.Equal(t, expectedAccFees, accumulatedFees) // execute on inner tx receiver shard diff --git a/integrationTests/vm/txsFee/relayedMoveBalance_test.go b/integrationTests/vm/txsFee/relayedMoveBalance_test.go index ecab2f87b85..3cb95091537 100644 --- a/integrationTests/vm/txsFee/relayedMoveBalance_test.go +++ b/integrationTests/vm/txsFee/relayedMoveBalance_test.go @@ -49,8 +49,8 @@ func TestRelayedMoveBalanceShouldWork(t *testing.T) { require.Nil(t, err) // check relayer balance - // 3000 - rTxFee(175)*gasPrice(10) + gasLimitForMoveInner(5)*gasPrice(10) = 1200 - expectedBalanceRelayer := big.NewInt(1200) + // 3000 - rTxFee(175)*gasPrice(10) + txFeeInner(1000) = 2750 + expectedBalanceRelayer := big.NewInt(250) vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) // check balance inner tx sender @@ -61,7 +61,7 @@ func TestRelayedMoveBalanceShouldWork(t *testing.T) { // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(1800), accumulatedFees) + require.Equal(t, big.NewInt(2750), accumulatedFees) } func TestRelayedMoveBalanceInvalidGasLimitShouldConsumeGas(t *testing.T) { @@ -120,13 +120,13 @@ func TestRelayedMoveBalanceInvalidUserTxShouldConsumeGas(t *testing.T) { _, err = testContext.Accounts.Commit() require.Nil(t, err) - // 3000 - rTxFee(179)*gasPrice(10) - gasLimitForMoveInner(5)*gasPrice(10) = 2821 - expectedBalanceRelayer := big.NewInt(2816) + // 3000 - rTxFee(179)*gasPrice(1) - innerTxFee(100) = 2721 + expectedBalanceRelayer := big.NewInt(2721) vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(184), accumulatedFees) + require.Equal(t, big.NewInt(279), accumulatedFees) } func TestRelayedMoveBalanceInvalidUserTxValueShouldConsumeGas(t *testing.T) { @@ -155,13 +155,13 @@ func TestRelayedMoveBalanceInvalidUserTxValueShouldConsumeGas(t *testing.T) { _, err = testContext.Accounts.Commit() require.Nil(t, err) - // 3000 - rTxFee(175)*gasPrice(10) - gasLimitForMoveInner(5)*gasPrice(10) = 2820 - expectedBalanceRelayer := big.NewInt(2820) + // 3000 - rTxFee(175)*gasPrice(1) - innerTxFee(100) = 2750 + expectedBalanceRelayer := big.NewInt(2725) vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(180), accumulatedFees) + require.Equal(t, big.NewInt(275), accumulatedFees) } func TestRelayedMoveBalanceHigherNonce(t *testing.T) { diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index d968d9cee72..88afd9d2239 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -1022,7 +1022,7 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( shouldConsiderMoveBalanceFee := dstShardTxType == process.MoveBalance && txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() if shouldConsiderMoveBalanceFee { - totalFee = txProc.economicsFee.ComputeMoveBalanceFee(userTx) + totalFee = txProc.economicsFee.ComputeTxFee(userTx) } txProc.txFeeHandler.ProcessTransactionFee(totalFee, big.NewInt(0), originalTxHash) From f8861b4fe4f1e8d7c0628d9293ac01b80104dc73 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Mon, 30 Oct 2023 16:12:08 +0200 Subject: [PATCH 016/503] added tokenType call for every token creation, and added update function which can be called by anyone. --- cmd/node/config/enableEpochs.toml | 3 + common/enablers/enableEpochsHandler.go | 1 + common/enablers/epochFlags.go | 7 ++ common/interface.go | 1 + config/epochConfig.go | 1 + config/tomlConfig_test.go | 4 + sharding/mock/enableEpochsHandlerMock.go | 5 ++ .../enableEpochsHandlerStub.go | 8 ++ vm/systemSmartContracts/esdt.go | 85 +++++++++++++++++-- 9 files changed, 108 insertions(+), 7 deletions(-) diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index 57172298c3e..d6adc15577f 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -284,6 +284,9 @@ # ChangeOwnerAddressCrossShardThroughSCEnableEpoch represents the epoch when the change owner address built in function will work also through a smart contract call cross shard ChangeOwnerAddressCrossShardThroughSCEnableEpoch = 3 + # DynamicESDTEnableEpoch represents the epoch when dynamic NFT feature is enabled + DynamicESDTEnableEpoch = 4 + # BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers BLSMultiSignerEnableEpoch = [ { EnableEpoch = 0, Type = "no-KOSK" }, diff --git a/common/enablers/enableEpochsHandler.go b/common/enablers/enableEpochsHandler.go index 7e5ea0bc18e..f57641454f2 100644 --- a/common/enablers/enableEpochsHandler.go +++ b/common/enablers/enableEpochsHandler.go @@ -132,6 +132,7 @@ func (handler *enableEpochsHandler) EpochConfirmed(epoch uint32, _ uint64) { handler.setFlagValue(epoch >= handler.enableEpochsConfig.DynamicGasCostForDataTrieStorageLoadEnableEpoch, handler.dynamicGasCostForDataTrieStorageLoadFlag, "dynamicGasCostForDataTrieStorageLoadFlag", epoch, handler.enableEpochsConfig.DynamicGasCostForDataTrieStorageLoadEnableEpoch) handler.setFlagValue(epoch >= handler.enableEpochsConfig.NFTStopCreateEnableEpoch, handler.nftStopCreateFlag, "nftStopCreateFlag", epoch, handler.enableEpochsConfig.NFTStopCreateEnableEpoch) handler.setFlagValue(epoch >= handler.enableEpochsConfig.ChangeOwnerAddressCrossShardThroughSCEnableEpoch, handler.changeOwnerAddressCrossShardThroughSCFlag, "changeOwnerAddressCrossShardThroughSCFlag", epoch, handler.enableEpochsConfig.ChangeOwnerAddressCrossShardThroughSCEnableEpoch) + handler.setFlagValue(epoch >= handler.enableEpochsConfig.DynamicESDTEnableEpoch, handler.dynamicESDTFlag, "dynamicESDTFlag", epoch, handler.enableEpochsConfig.DynamicESDTEnableEpoch) } func (handler *enableEpochsHandler) setFlagValue(value bool, flag *atomic.Flag, flagName string, epoch uint32, flagEpoch uint32) { diff --git a/common/enablers/epochFlags.go b/common/enablers/epochFlags.go index 2b0ca8d884c..7a7932c3aee 100644 --- a/common/enablers/epochFlags.go +++ b/common/enablers/epochFlags.go @@ -104,6 +104,7 @@ type epochFlagsHolder struct { dynamicGasCostForDataTrieStorageLoadFlag *atomic.Flag nftStopCreateFlag *atomic.Flag changeOwnerAddressCrossShardThroughSCFlag *atomic.Flag + dynamicESDTFlag *atomic.Flag } func newEpochFlagsHolder() *epochFlagsHolder { @@ -207,6 +208,7 @@ func newEpochFlagsHolder() *epochFlagsHolder { dynamicGasCostForDataTrieStorageLoadFlag: &atomic.Flag{}, nftStopCreateFlag: &atomic.Flag{}, changeOwnerAddressCrossShardThroughSCFlag: &atomic.Flag{}, + dynamicESDTFlag: &atomic.Flag{}, } } @@ -757,3 +759,8 @@ func (holder *epochFlagsHolder) NFTStopCreateEnabled() bool { func (holder *epochFlagsHolder) IsChangeOwnerAddressCrossShardThroughSCEnabled() bool { return holder.changeOwnerAddressCrossShardThroughSCFlag.IsSet() } + +// DynamicESDTEnabled return true if the dynamicESDTFlag is enabled +func (holder *epochFlagsHolder) DynamicESDTEnabled() bool { + return holder.dynamicESDTFlag.IsSet() +} diff --git a/common/interface.go b/common/interface.go index 52cdce6aefe..989807e06ad 100644 --- a/common/interface.go +++ b/common/interface.go @@ -397,6 +397,7 @@ type EnableEpochsHandler interface { FixDelegationChangeOwnerOnAccountEnabled() bool NFTStopCreateEnabled() bool IsChangeOwnerAddressCrossShardThroughSCEnabled() bool + DynamicESDTEnabled() bool IsInterfaceNil() bool } diff --git a/config/epochConfig.go b/config/epochConfig.go index bbdfe39284e..b18df32c1bd 100644 --- a/config/epochConfig.go +++ b/config/epochConfig.go @@ -107,6 +107,7 @@ type EnableEpochs struct { DynamicGasCostForDataTrieStorageLoadEnableEpoch uint32 NFTStopCreateEnableEpoch uint32 ChangeOwnerAddressCrossShardThroughSCEnableEpoch uint32 + DynamicESDTEnableEpoch uint32 BLSMultiSignerEnableEpoch []MultiSignerConfig } diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index a844be408c0..5e9588e38f9 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -831,6 +831,9 @@ func TestEnableEpochConfig(t *testing.T) { # ChangeOwnerAddressCrossShardThroughSCEnableEpoch represents the epoch when the change owner address built in function will work also through a smart contract call cross shard ChangeOwnerAddressCrossShardThroughSCEnableEpoch = 90 + # DynamicESDTEnableEpoch represents the epoch when dynamic NFT feature is enabled + DynamicESDTEnableEpoch = 91 + # MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MaxNodesChangeEnableEpoch = [ { EpochEnable = 44, MaxNumNodes = 2169, NodesToShufflePerShard = 80 }, @@ -941,6 +944,7 @@ func TestEnableEpochConfig(t *testing.T) { ScToScLogEventEnableEpoch: 88, NFTStopCreateEnableEpoch: 89, ChangeOwnerAddressCrossShardThroughSCEnableEpoch: 90, + DynamicESDTEnableEpoch: 91, MaxNodesChangeEnableEpoch: []MaxNodesChangeConfig{ { EpochEnable: 44, diff --git a/sharding/mock/enableEpochsHandlerMock.go b/sharding/mock/enableEpochsHandlerMock.go index d5e925262d6..2a38cd500ee 100644 --- a/sharding/mock/enableEpochsHandlerMock.go +++ b/sharding/mock/enableEpochsHandlerMock.go @@ -14,6 +14,11 @@ func (mock *EnableEpochsHandlerMock) IsChangeOwnerAddressCrossShardThroughSCEnab return false } +// DynamicESDTEnabled - +func (mock *EnableEpochsHandlerMock) DynamicESDTEnabled() bool { + return false +} + // BlockGasAndFeesReCheckEnableEpoch returns 0 func (mock *EnableEpochsHandlerMock) BlockGasAndFeesReCheckEnableEpoch() uint32 { return 0 diff --git a/testscommon/enableEpochsHandlerMock/enableEpochsHandlerStub.go b/testscommon/enableEpochsHandlerMock/enableEpochsHandlerStub.go index 8b8cb4e0b40..423e4bdc6ec 100644 --- a/testscommon/enableEpochsHandlerMock/enableEpochsHandlerStub.go +++ b/testscommon/enableEpochsHandlerMock/enableEpochsHandlerStub.go @@ -133,6 +133,7 @@ type EnableEpochsHandlerStub struct { IsDynamicGasCostForDataTrieStorageLoadEnabledField bool IsNFTStopCreateEnabledField bool IsChangeOwnerAddressCrossShardThroughSCEnabledField bool + DynamicESDTEnabledField bool } // ResetPenalizedTooMuchGasFlag - @@ -1142,6 +1143,13 @@ func (stub *EnableEpochsHandlerStub) IsChangeOwnerAddressCrossShardThroughSCEnab return stub.IsChangeOwnerAddressCrossShardThroughSCEnabledField } +func (stub *EnableEpochsHandlerStub) DynamicESDTEnabled() bool { + stub.RLock() + defer stub.RUnlock() + + return stub.DynamicESDTEnabledField +} + // IsInterfaceNil - func (stub *EnableEpochsHandlerStub) IsInterfaceNil() bool { return stub == nil diff --git a/vm/systemSmartContracts/esdt.go b/vm/systemSmartContracts/esdt.go index c5ceb002f66..2bd2287ee8d 100644 --- a/vm/systemSmartContracts/esdt.go +++ b/vm/systemSmartContracts/esdt.go @@ -44,6 +44,8 @@ const upgradeProperties = "upgradeProperties" const conversionBase = 10 const metaESDT = "MetaESDT" +const nonFungibleV2 = "NonFungibleESDTV2" +const ESDTSetTokenType = "ESDTSetTokenType" type esdt struct { eei vm.SystemEI @@ -197,6 +199,8 @@ func (e *esdt) Execute(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { return e.unsetBurnRoleGlobally(args) case "sendAllTransferRoleAddresses": return e.sendAllTransferRoleAddresses(args) + case "updateTokenID": + return e.updateTokenID(args) } e.eei.AddReturnMessage("invalid method to call") @@ -326,6 +330,11 @@ func (e *esdt) registerNonFungible(args *vmcommon.ContractCallInput) vmcommon.Re return vmcommon.UserError } + tokenType := []byte(core.NonFungibleESDT) + if e.enableEpochsHandler.DynamicESDTEnabled() { + tokenType = []byte(nonFungibleV2) + } + tokenIdentifier, _, err := e.createNewToken( args.CallerAddr, args.Arguments[0], @@ -333,7 +342,7 @@ func (e *esdt) registerNonFungible(args *vmcommon.ContractCallInput) vmcommon.Re big.NewInt(0), 0, args.Arguments[2:], - []byte(core.NonFungibleESDT)) + tokenType) if err != nil { e.eei.AddReturnMessage(err.Error()) return vmcommon.UserError @@ -343,7 +352,7 @@ func (e *esdt) registerNonFungible(args *vmcommon.ContractCallInput) vmcommon.Re logEntry := &vmcommon.LogEntry{ Identifier: []byte(args.Function), Address: args.CallerAddr, - Topics: [][]byte{tokenIdentifier, args.Arguments[0], args.Arguments[1], []byte(core.NonFungibleESDT), big.NewInt(0).Bytes()}, + Topics: [][]byte{tokenIdentifier, args.Arguments[0], args.Arguments[1], tokenType, big.NewInt(0).Bytes()}, } e.eei.AddLogEntry(logEntry) @@ -449,7 +458,7 @@ func (e *esdt) registerAndSetRoles(args *vmcommon.ContractCallInput) vmcommon.Re e.eei.AddReturnMessage("arguments length mismatch") return vmcommon.UserError } - isWithDecimals, tokenType, err := getTokenType(args.Arguments[2]) + isWithDecimals, tokenType, err := e.getTokenType(args.Arguments[2]) if err != nil { e.eei.AddReturnMessage(err.Error()) return vmcommon.UserError @@ -517,7 +526,7 @@ func (e *esdt) registerAndSetRoles(args *vmcommon.ContractCallInput) vmcommon.Re func getAllRolesForTokenType(tokenType string) ([][]byte, error) { switch tokenType { - case core.NonFungibleESDT: + case core.NonFungibleESDT, nonFungibleV2: return [][]byte{[]byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleNFTBurn), []byte(core.ESDTRoleNFTUpdateAttributes), []byte(core.ESDTRoleNFTAddURI)}, nil case core.SemiFungibleESDT, metaESDT: return [][]byte{[]byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleNFTBurn), []byte(core.ESDTRoleNFTAddQuantity)}, nil @@ -528,10 +537,13 @@ func getAllRolesForTokenType(tokenType string) ([][]byte, error) { return nil, vm.ErrInvalidArgument } -func getTokenType(compressed []byte) (bool, []byte, error) { +func (e *esdt) getTokenType(compressed []byte) (bool, []byte, error) { // TODO: might extract the compressed constants to core, alongside metaESDT switch string(compressed) { case "NFT": + if e.enableEpochsHandler.DynamicESDTEnabled() { + return false, []byte(nonFungibleV2), nil + } return false, []byte(core.NonFungibleESDT), nil case "SFT": return false, []byte(core.SemiFungibleESDT), nil @@ -587,6 +599,8 @@ func (e *esdt) changeSFTToMetaESDT(args *vmcommon.ContractCallInput) vmcommon.Re } e.eei.AddLogEntry(logEntry) + e.sendTokenTypeToSystemAccounts(args.CallerAddr, args.Arguments[0], token) + return vmcommon.Ok } @@ -622,6 +636,7 @@ func (e *esdt) createNewToken( Upgradable: true, CanAddSpecialRoles: true, } + err = e.upgradeProperties(tokenIdentifier, newESDTToken, properties, true, owner) if err != nil { return nil, nil, err @@ -633,6 +648,8 @@ func (e *esdt) createNewToken( return nil, nil, err } + e.sendTokenTypeToSystemAccounts(owner, tokenIdentifier, newESDTToken) + return tokenIdentifier, newESDTToken, nil } @@ -1339,7 +1356,7 @@ func (e *esdt) getSpecialRoles(args *vmcommon.ContractCallInput) vmcommon.Return return vmcommon.Ok } -func (e *esdt) basicOwnershipChecks(args *vmcommon.ContractCallInput) (*ESDTDataV2, vmcommon.ReturnCode) { +func (e *esdt) getTokenInfoAfterInputChecks(args *vmcommon.ContractCallInput) (*ESDTDataV2, vmcommon.ReturnCode) { if args.CallValue.Cmp(zero) != 0 { e.eei.AddReturnMessage("callValue must be 0") return nil, vmcommon.OutOfFunds @@ -1358,6 +1375,15 @@ func (e *esdt) basicOwnershipChecks(args *vmcommon.ContractCallInput) (*ESDTData e.eei.AddReturnMessage(err.Error()) return nil, vmcommon.UserError } + + return token, vmcommon.Ok +} + +func (e *esdt) basicOwnershipChecks(args *vmcommon.ContractCallInput) (*ESDTDataV2, vmcommon.ReturnCode) { + token, returnCode := e.getTokenInfoAfterInputChecks(args) + if returnCode != vmcommon.Ok { + return nil, returnCode + } if !bytes.Equal(token.OwnerAddress, args.CallerAddr) { e.eei.AddReturnMessage("can be called by owner only") return nil, vmcommon.UserError @@ -1559,7 +1585,7 @@ func (e *esdt) checkSpecialRolesAccordingToTokenType(args [][]byte, token *ESDTD switch string(token.TokenType) { case core.FungibleESDT: return validateRoles(args, e.isSpecialRoleValidForFungible) - case core.NonFungibleESDT: + case core.NonFungibleESDT, nonFungibleV2: return validateRoles(args, e.isSpecialRoleValidForNonFungible) case core.SemiFungibleESDT: return validateRoles(args, e.isSpecialRoleValidForSemiFungible) @@ -2050,6 +2076,51 @@ func (e *esdt) stopNFTCreateForever(args *vmcommon.ContractCallInput) vmcommon.R return vmcommon.Ok } +func (e *esdt) updateTokenID(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { + if !e.enableEpochsHandler.DynamicESDTEnabled() { + e.eei.AddReturnMessage("invalid method to call") + return vmcommon.FunctionNotFound + } + if len(args.Arguments) != 1 { + e.eei.AddReturnMessage("invalid number of arguments, wanted 1") + return vmcommon.FunctionWrongSignature + } + token, returnCode := e.getTokenInfoAfterInputChecks(args) + if returnCode != vmcommon.Ok { + return returnCode + } + + tokenID := args.Arguments[0] + if bytes.Equal(token.TokenType, []byte(core.NonFungibleESDT)) { + token.TokenType = []byte(nonFungibleV2) + err := e.saveToken(tokenID, token) + if err != nil { + e.eei.AddReturnMessage(err.Error()) + return vmcommon.UserError + } + } + + return vmcommon.Ok +} + +func (e *esdt) sendTokenTypeToSystemAccounts(caller []byte, tokenID []byte, token *ESDTDataV2) { + if !e.enableEpochsHandler.DynamicESDTEnabled() { + return + } + + builtInFunc := ESDTSetTokenType + esdtTransferData := builtInFunc + "@" + hex.EncodeToString(tokenID) + "@" + hex.EncodeToString(token.TokenType) + e.eei.SendGlobalSettingToAll(e.eSDTSCAddress, []byte(esdtTransferData)) + + logEntry := &vmcommon.LogEntry{ + Identifier: []byte(builtInFunc), + Address: caller, + Topics: [][]byte{tokenID, token.TokenType}, + Data: nil, + } + e.eei.AddLogEntry(logEntry) +} + func (e *esdt) sendRoleChangeData(tokenID []byte, destination []byte, roles [][]byte, builtInFunc string) error { esdtSetRoleData := builtInFunc + "@" + hex.EncodeToString(tokenID) for _, arg := range roles { From 828e69da6130852d628e4a269bc8c924a4fba045 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 31 Oct 2023 11:28:01 +0200 Subject: [PATCH 017/503] further fixes after review + proper fee fix --- .../multiShard/relayedTx/common.go | 17 +- .../relayedTx/edgecases/edgecases_test.go | 17 +- .../vm/txsFee/guardAccount_test.go | 11 +- .../multiShard/relayedMoveBalance_test.go | 678 ++++++++++-------- .../vm/txsFee/relayedBuiltInFunctions_test.go | 151 ++-- .../vm/txsFee/relayedESDT_test.go | 144 ++-- .../vm/txsFee/relayedMoveBalance_test.go | 8 +- .../vm/txsFee/relayedScCalls_test.go | 309 ++++---- .../vm/txsFee/relayedScDeploy_test.go | 251 ++++--- process/transaction/baseProcess.go | 7 +- process/transaction/export_test.go | 4 +- process/transaction/metaProcess.go | 5 +- process/transaction/shardProcess.go | 36 +- process/transaction/shardProcess_test.go | 25 +- 14 files changed, 917 insertions(+), 746 deletions(-) diff --git a/integrationTests/multiShard/relayedTx/common.go b/integrationTests/multiShard/relayedTx/common.go index 979b8d62a64..b3e9da00bb4 100644 --- a/integrationTests/multiShard/relayedTx/common.go +++ b/integrationTests/multiShard/relayedTx/common.go @@ -292,14 +292,13 @@ func GetUserAccount( } func subFeesFromRelayer(tx, userTx *transaction.Transaction, economicsFee process.FeeHandler, relayer *integrationTests.TestWalletAccount) { - if len(userTx.Data) == 0 { // move balance - relayerFee := economicsFee.ComputeMoveBalanceFee(tx) - relayer.Balance.Sub(relayer.Balance, relayerFee) - - userFee := economicsFee.ComputeTxFee(userTx) - relayer.Balance.Sub(relayer.Balance, userFee) - } else { - totalFee := economicsFee.ComputeTxFee(tx) - relayer.Balance.Sub(relayer.Balance, totalFee) + relayerFee := economicsFee.ComputeMoveBalanceFee(tx) + relayer.Balance.Sub(relayer.Balance, relayerFee) + + userTxCopy := *userTx + if userTxCopy.GasLimit == 0 { // relayed v2 + userTxCopy.GasLimit = tx.GasLimit - economicsFee.ComputeGasLimit(tx) } + userFee := economicsFee.ComputeTxFee(&userTxCopy) + relayer.Balance.Sub(relayer.Balance, userFee) } diff --git a/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go b/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go index b8ef1e58a7b..6adf254433b 100644 --- a/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go +++ b/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go @@ -151,14 +151,13 @@ func checkPlayerBalancesWithPenalization( } func appendFeeToTotalFees(relayerTx, userTx *transaction.Transaction, economicsData process.EconomicsDataHandler, totalFees *big.Int) { - if len(userTx.Data) == 0 { // move balance - relayerFee := economicsData.ComputeMoveBalanceFee(relayerTx) - totalFees.Add(totalFees, relayerFee) - - userFee := economicsData.ComputeTxFee(userTx) - totalFees.Add(totalFees, userFee) - } else { - totalFee := economicsData.ComputeTxFee(relayerTx) - totalFees.Add(totalFees, totalFee) + relayerFee := economicsData.ComputeMoveBalanceFee(relayerTx) + totalFees.Add(totalFees, relayerFee) + + userTxCopy := *userTx + if userTxCopy.GasLimit == 0 { // relayed v2 + userTxCopy.GasLimit = relayerTx.GasLimit - economicsData.ComputeGasLimit(relayerTx) } + userFee := economicsData.ComputeTxFee(&userTxCopy) + totalFees.Add(totalFees, userFee) } diff --git a/integrationTests/vm/txsFee/guardAccount_test.go b/integrationTests/vm/txsFee/guardAccount_test.go index 34be91505e7..60cfb5e0b27 100644 --- a/integrationTests/vm/txsFee/guardAccount_test.go +++ b/integrationTests/vm/txsFee/guardAccount_test.go @@ -38,6 +38,7 @@ const guardAccountGas = uint64(250000) const unGuardAccountGas = uint64(250000) const setGuardianGas = uint64(250000) const transferGas = uint64(1000) +const minGasLimit = uint64(1) var ( alice = []byte("alice-12345678901234567890123456") @@ -970,7 +971,7 @@ func TestGuardAccounts_RelayedTransactionV1(t *testing.T) { userTx.Version = txWithOptionVersion rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := 1 + guardianSigVerificationGas + 1 + uint64(len(rtxData)) + rTxGasLimit := minGasLimit + guardianSigVerificationGas + minGasLimit + uint64(len(rtxData)) rtx := vm.CreateTransaction(getNonce(testContext, charlie), big.NewInt(0), charlie, alice, gasPrice, rTxGasLimit, rtxData) returnCode, err = testContext.TxProcessor.ProcessTransaction(rtx) require.Nil(t, err) @@ -1007,7 +1008,7 @@ func TestGuardAccounts_RelayedTransactionV1(t *testing.T) { userTx.Version = txWithOptionVersion rtxData = integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit = 1 + 1 + uint64(len(rtxData)) + rTxGasLimit = minGasLimit + minGasLimit + uint64(len(rtxData)) rtx = vm.CreateTransaction(getNonce(testContext, charlie), big.NewInt(0), charlie, alice, gasPrice, rTxGasLimit, rtxData) returnCode, err = testContext.TxProcessor.ProcessTransaction(rtx) require.Nil(t, err) @@ -1091,7 +1092,7 @@ func TestGuardAccounts_RelayedTransactionV2(t *testing.T) { userTx.Version = txWithOptionVersion rtxData := integrationTests.PrepareRelayedTxDataV2(userTx) - rTxGasLimit := 1 + guardianSigVerificationGas + 1 + uint64(len(rtxData)) + rTxGasLimit := minGasLimit + guardianSigVerificationGas + minGasLimit + uint64(len(rtxData)) rtx := vm.CreateTransaction(getNonce(testContext, charlie), big.NewInt(0), charlie, alice, gasPrice, rTxGasLimit, rtxData) returnCode, err = testContext.TxProcessor.ProcessTransaction(rtx) require.Nil(t, err) @@ -1110,7 +1111,7 @@ func TestGuardAccounts_RelayedTransactionV2(t *testing.T) { assert.Equal(t, aliceCurrentBalance, getBalance(testContext, alice)) bobExpectedBalance := big.NewInt(0).Set(initialMint) assert.Equal(t, bobExpectedBalance, getBalance(testContext, bob)) - charlieConsumed := 1 + guardianSigVerificationGas + 1 + uint64(len(rtxData)) + charlieConsumed := minGasLimit + guardianSigVerificationGas + minGasLimit + uint64(len(rtxData)) charlieExpectedBalance := big.NewInt(0).Sub(initialMint, big.NewInt(int64(charlieConsumed*gasPrice))) assert.Equal(t, charlieExpectedBalance, getBalance(testContext, charlie)) assert.Equal(t, initialMint, getBalance(testContext, david)) @@ -1131,7 +1132,7 @@ func TestGuardAccounts_RelayedTransactionV2(t *testing.T) { userTx.Version = txWithOptionVersion rtxData = integrationTests.PrepareRelayedTxDataV2(userTx) - rTxGasLimit = 1 + 1 + uint64(len(rtxData)) + rTxGasLimit = minGasLimit + minGasLimit + uint64(len(rtxData)) rtx = vm.CreateTransaction(getNonce(testContext, charlie), big.NewInt(0), charlie, alice, gasPrice, rTxGasLimit, rtxData) returnCode, err = testContext.TxProcessor.ProcessTransaction(rtx) require.Nil(t, err) diff --git a/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go b/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go index 490fb061234..61503fd28b2 100644 --- a/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go +++ b/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go @@ -13,374 +13,440 @@ import ( "github.com/stretchr/testify/require" ) +const minGasLimit = uint64(1) + func TestRelayedMoveBalanceRelayerShard0InnerTxSenderAndReceiverShard1ShouldWork(t *testing.T) { - testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) - require.Nil(t, err) - defer testContext.Close() + t.Run("before relayed move balance fix", testRelayedMoveBalanceRelayerShard0InnerTxSenderAndReceiverShard1ShouldWork(integrationTests.UnreachableEpoch)) + t.Run("after relayed move balance fix", testRelayedMoveBalanceRelayerShard0InnerTxSenderAndReceiverShard1ShouldWork(0)) +} - relayerAddr := []byte("12345678901234567890123456789030") - shardID := testContext.ShardCoordinator.ComputeId(relayerAddr) - require.Equal(t, uint32(0), shardID) +func testRelayedMoveBalanceRelayerShard0InnerTxSenderAndReceiverShard1ShouldWork(relayedFixActivationEpoch uint32) func(t *testing.T) { + return func(t *testing.T) { + testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ + RelayedNonceFixEnableEpoch: relayedFixActivationEpoch, + }) + require.Nil(t, err) + defer testContext.Close() - sndAddr := []byte("12345678901234567890123456789011") - shardID = testContext.ShardCoordinator.ComputeId(sndAddr) - require.Equal(t, uint32(1), shardID) + relayerAddr := []byte("12345678901234567890123456789030") + shardID := testContext.ShardCoordinator.ComputeId(relayerAddr) + require.Equal(t, uint32(0), shardID) - rcvAddr := []byte("12345678901234567890123456789021") - shardID = testContext.ShardCoordinator.ComputeId(rcvAddr) - require.Equal(t, uint32(1), shardID) + sndAddr := []byte("12345678901234567890123456789011") + shardID = testContext.ShardCoordinator.ComputeId(sndAddr) + require.Equal(t, uint32(1), shardID) - gasPrice := uint64(10) - gasLimit := uint64(100) + rcvAddr := []byte("12345678901234567890123456789021") + shardID = testContext.ShardCoordinator.ComputeId(rcvAddr) + require.Equal(t, uint32(1), shardID) - _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, big.NewInt(100)) - _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(3000)) + gasPrice := uint64(10) + gasLimit := uint64(100) - userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, rcvAddr, gasPrice, gasLimit, []byte("aaaa")) + _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, big.NewInt(100)) + _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(3000)) - rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := gasLimit + 1 + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) + userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, rcvAddr, gasPrice, gasLimit, []byte("aaaa")) - retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) - require.Equal(t, vmcommon.Ok, retCode) - require.Nil(t, err) + rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) + rTxGasLimit := gasLimit + minGasLimit + uint64(len(rtxData)) + rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) - _, err = testContext.Accounts.Commit() - require.Nil(t, err) + retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) - // check balance inner tx sender - utils.TestAccount(t, testContext.Accounts, sndAddr, 1, big.NewInt(0)) + _, err = testContext.Accounts.Commit() + require.Nil(t, err) - // check balance inner tx receiver - utils.TestAccount(t, testContext.Accounts, rcvAddr, 0, big.NewInt(100)) + // check balance inner tx sender + utils.TestAccount(t, testContext.Accounts, sndAddr, 1, big.NewInt(0)) - // check accumulated fees - accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(1000), accumulatedFees) + // check balance inner tx receiver + utils.TestAccount(t, testContext.Accounts, rcvAddr, 0, big.NewInt(100)) + + // check accumulated fees + accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() + require.Equal(t, big.NewInt(1000), accumulatedFees) + } } func TestRelayedMoveBalanceRelayerAndInnerTxSenderShard0ReceiverShard1(t *testing.T) { - testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) - require.Nil(t, err) - defer testContext.Close() - - relayerAddr := []byte("12345678901234567890123456789030") - shardID := testContext.ShardCoordinator.ComputeId(relayerAddr) - require.Equal(t, uint32(0), shardID) - - sndAddr := []byte("12345678901234567890123456789011") - shardID = testContext.ShardCoordinator.ComputeId(sndAddr) - require.Equal(t, uint32(1), shardID) - - scAddress := "00000000000000000000dbb53e4b23392b0d6f36cce32deb2d623e9625ab3132" - scAddrBytes, _ := hex.DecodeString(scAddress) - scAddrBytes[31] = 1 - shardID = testContext.ShardCoordinator.ComputeId(scAddrBytes) - require.Equal(t, uint32(1), shardID) - - gasPrice := uint64(10) - gasLimit := uint64(100) - - userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, scAddrBytes, gasPrice, gasLimit, nil) - - rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := gasLimit + 1 + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) - - retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) - require.Equal(t, vmcommon.UserError, retCode) - require.Nil(t, err) - - _, err = testContext.Accounts.Commit() - require.Nil(t, err) - - // check inner tx receiver - account, err := testContext.Accounts.GetExistingAccount(scAddrBytes) - require.Nil(t, account) - require.NotNil(t, err) + t.Run("before relayed move balance fix", testRelayedMoveBalanceRelayerAndInnerTxSenderShard0ReceiverShard1(integrationTests.UnreachableEpoch)) + t.Run("after relayed move balance fix", testRelayedMoveBalanceRelayerAndInnerTxSenderShard0ReceiverShard1(0)) +} - // check accumulated fees - accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(1000), accumulatedFees) +func testRelayedMoveBalanceRelayerAndInnerTxSenderShard0ReceiverShard1(relayedFixActivationEpoch uint32) func(t *testing.T) { + return func(t *testing.T) { + testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ + RelayedNonceFixEnableEpoch: relayedFixActivationEpoch, + }) + require.Nil(t, err) + defer testContext.Close() + + relayerAddr := []byte("12345678901234567890123456789030") + shardID := testContext.ShardCoordinator.ComputeId(relayerAddr) + require.Equal(t, uint32(0), shardID) + + sndAddr := []byte("12345678901234567890123456789011") + shardID = testContext.ShardCoordinator.ComputeId(sndAddr) + require.Equal(t, uint32(1), shardID) + + scAddress := "00000000000000000000dbb53e4b23392b0d6f36cce32deb2d623e9625ab3132" + scAddrBytes, _ := hex.DecodeString(scAddress) + scAddrBytes[31] = 1 + shardID = testContext.ShardCoordinator.ComputeId(scAddrBytes) + require.Equal(t, uint32(1), shardID) + + gasPrice := uint64(10) + gasLimit := uint64(100) + + userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, scAddrBytes, gasPrice, gasLimit, nil) + + rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) + rTxGasLimit := gasLimit + minGasLimit + uint64(len(rtxData)) + rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) + + retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) + require.Equal(t, vmcommon.UserError, retCode) + require.Nil(t, err) + + _, err = testContext.Accounts.Commit() + require.Nil(t, err) + + // check inner tx receiver + account, err := testContext.Accounts.GetExistingAccount(scAddrBytes) + require.Nil(t, account) + require.NotNil(t, err) + + // check accumulated fees + accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() + require.Equal(t, big.NewInt(1000), accumulatedFees) + } } func TestRelayedMoveBalanceExecuteOnSourceAndDestination(t *testing.T) { - testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) - require.Nil(t, err) - defer testContextSource.Close() - - testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) - require.Nil(t, err) - defer testContextDst.Close() - - relayerAddr := []byte("12345678901234567890123456789030") - shardID := testContextSource.ShardCoordinator.ComputeId(relayerAddr) - require.Equal(t, uint32(0), shardID) - - sndAddr := []byte("12345678901234567890123456789011") - shardID = testContextSource.ShardCoordinator.ComputeId(sndAddr) - require.Equal(t, uint32(1), shardID) - - scAddress := "00000000000000000000dbb53e4b23392b0d6f36cce32deb2d623e9625ab3132" - scAddrBytes, _ := hex.DecodeString(scAddress) - scAddrBytes[31] = 1 - shardID = testContextSource.ShardCoordinator.ComputeId(scAddrBytes) - require.Equal(t, uint32(1), shardID) - - gasPrice := uint64(10) - gasLimit := uint64(100) - - _, _ = vm.CreateAccount(testContextSource.Accounts, relayerAddr, 0, big.NewInt(100000)) - _, _ = vm.CreateAccount(testContextSource.Accounts, sndAddr, 0, big.NewInt(100)) - - userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, scAddrBytes, gasPrice, gasLimit, nil) - - rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) - - // execute on source shard - retCode, err := testContextSource.TxProcessor.ProcessTransaction(rtx) - require.Equal(t, vmcommon.Ok, retCode) - require.Nil(t, err) - - // check relayed balance - // 100000 - rTxFee(163)*gasPrice(10) - txFeeInner(1000) = 97370 - utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, big.NewInt(97370)) - - // check accumulated fees - accumulatedFees := testContextSource.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(1630), accumulatedFees) - - // execute on destination shard - retCode, err = testContextDst.TxProcessor.ProcessTransaction(rtx) - require.Equal(t, vmcommon.UserError, retCode) - require.Nil(t, err) - - _, err = testContextDst.Accounts.Commit() - require.Nil(t, err) - - // check inner tx receiver - account, err := testContextDst.Accounts.GetExistingAccount(scAddrBytes) - require.Nil(t, account) - require.NotNil(t, err) + t.Run("before relayed move balance fix", testRelayedMoveBalanceExecuteOnSourceAndDestination(integrationTests.UnreachableEpoch)) + t.Run("after relayed move balance fix", testRelayedMoveBalanceExecuteOnSourceAndDestination(0)) +} - // check accumulated fees - accumulatedFees = testContextDst.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(1000), accumulatedFees) +func testRelayedMoveBalanceExecuteOnSourceAndDestination(relayedFixActivationEpoch uint32) func(t *testing.T) { + return func(t *testing.T) { + testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{ + FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + }) + require.Nil(t, err) + defer testContextSource.Close() + + testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ + FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + }) + require.Nil(t, err) + defer testContextDst.Close() + + relayerAddr := []byte("12345678901234567890123456789030") + shardID := testContextSource.ShardCoordinator.ComputeId(relayerAddr) + require.Equal(t, uint32(0), shardID) + + sndAddr := []byte("12345678901234567890123456789011") + shardID = testContextSource.ShardCoordinator.ComputeId(sndAddr) + require.Equal(t, uint32(1), shardID) + + scAddress := "00000000000000000000dbb53e4b23392b0d6f36cce32deb2d623e9625ab3132" + scAddrBytes, _ := hex.DecodeString(scAddress) + scAddrBytes[31] = 1 + shardID = testContextSource.ShardCoordinator.ComputeId(scAddrBytes) + require.Equal(t, uint32(1), shardID) + + gasPrice := uint64(10) + gasLimit := uint64(100) + + _, _ = vm.CreateAccount(testContextSource.Accounts, relayerAddr, 0, big.NewInt(100000)) + _, _ = vm.CreateAccount(testContextSource.Accounts, sndAddr, 0, big.NewInt(100)) + + userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, scAddrBytes, gasPrice, gasLimit, nil) + + rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) + rTxGasLimit := minGasLimit + gasLimit + uint64(len(rtxData)) + rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) + + // execute on source shard + retCode, err := testContextSource.TxProcessor.ProcessTransaction(rtx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) + + // check relayed balance + // 100000 - rTxFee(163)*gasPrice(10) - txFeeInner(1000) = 97370 + utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, big.NewInt(97370)) + + // check accumulated fees + accumulatedFees := testContextSource.TxFeeHandler.GetAccumulatedFees() + require.Equal(t, big.NewInt(1630), accumulatedFees) + + // execute on destination shard + retCode, err = testContextDst.TxProcessor.ProcessTransaction(rtx) + require.Equal(t, vmcommon.UserError, retCode) + require.Nil(t, err) + + _, err = testContextDst.Accounts.Commit() + require.Nil(t, err) + + // check inner tx receiver + account, err := testContextDst.Accounts.GetExistingAccount(scAddrBytes) + require.Nil(t, account) + require.NotNil(t, err) + + // check accumulated fees + accumulatedFees = testContextDst.TxFeeHandler.GetAccumulatedFees() + require.Equal(t, big.NewInt(1000), accumulatedFees) + } } func TestRelayedMoveBalanceExecuteOnSourceAndDestinationRelayerAndInnerTxSenderShard0InnerTxReceiverShard1ShouldWork(t *testing.T) { - testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) - require.Nil(t, err) - defer testContextSource.Close() + t.Run("before relayed move balance fix", testRelayedMoveBalanceExecuteOnSourceAndDestinationRelayerAndInnerTxSenderShard0InnerTxReceiverShard1ShouldWork(integrationTests.UnreachableEpoch)) + t.Run("after relayed move balance fix", testRelayedMoveBalanceExecuteOnSourceAndDestinationRelayerAndInnerTxSenderShard0InnerTxReceiverShard1ShouldWork(0)) +} + +func testRelayedMoveBalanceExecuteOnSourceAndDestinationRelayerAndInnerTxSenderShard0InnerTxReceiverShard1ShouldWork(relayedFixActivationEpoch uint32) func(t *testing.T) { + return func(t *testing.T) { + testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{ + FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + }) + require.Nil(t, err) + defer testContextSource.Close() - testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) - require.Nil(t, err) - defer testContextDst.Close() + testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ + FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + }) + require.Nil(t, err) + defer testContextDst.Close() - relayerAddr := []byte("12345678901234567890123456789030") - shardID := testContextSource.ShardCoordinator.ComputeId(relayerAddr) - require.Equal(t, uint32(0), shardID) + relayerAddr := []byte("12345678901234567890123456789030") + shardID := testContextSource.ShardCoordinator.ComputeId(relayerAddr) + require.Equal(t, uint32(0), shardID) - sndAddr := []byte("12345678901234567890123456789010") - shardID = testContextSource.ShardCoordinator.ComputeId(sndAddr) - require.Equal(t, uint32(0), shardID) + sndAddr := []byte("12345678901234567890123456789010") + shardID = testContextSource.ShardCoordinator.ComputeId(sndAddr) + require.Equal(t, uint32(0), shardID) - rcvAddr := []byte("12345678901234567890123456789011") - shardID = testContextSource.ShardCoordinator.ComputeId(rcvAddr) - require.Equal(t, uint32(1), shardID) + rcvAddr := []byte("12345678901234567890123456789011") + shardID = testContextSource.ShardCoordinator.ComputeId(rcvAddr) + require.Equal(t, uint32(1), shardID) - gasPrice := uint64(10) - gasLimit := uint64(100) + gasPrice := uint64(10) + gasLimit := uint64(100) - _, _ = vm.CreateAccount(testContextSource.Accounts, relayerAddr, 0, big.NewInt(100000)) - _, _ = vm.CreateAccount(testContextSource.Accounts, sndAddr, 0, big.NewInt(100)) + _, _ = vm.CreateAccount(testContextSource.Accounts, relayerAddr, 0, big.NewInt(100000)) + _, _ = vm.CreateAccount(testContextSource.Accounts, sndAddr, 0, big.NewInt(100)) - userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, rcvAddr, gasPrice, gasLimit, nil) + userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, rcvAddr, gasPrice, gasLimit, nil) - rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := gasLimit + 1 + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) + rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) + rTxGasLimit := gasLimit + minGasLimit + uint64(len(rtxData)) + rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) - // execute on source shard - retCode, err := testContextSource.TxProcessor.ProcessTransaction(rtx) - require.Equal(t, vmcommon.Ok, retCode) - require.Nil(t, err) + // execute on source shard + retCode, err := testContextSource.TxProcessor.ProcessTransaction(rtx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) - // check relayed balance - // 100000 - rTxFee(163)*gasPrice(10) - innerTxFee(1000) = 97370 - utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, big.NewInt(97370)) - // check inner tx sender - utils.TestAccount(t, testContextSource.Accounts, sndAddr, 1, big.NewInt(0)) + // check relayed balance + // 100000 - rTxFee(163)*gasPrice(10) - innerTxFee(1000) = 97370 + utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, big.NewInt(97370)) + // check inner tx sender + utils.TestAccount(t, testContextSource.Accounts, sndAddr, 1, big.NewInt(0)) - // check accumulated fees - accumulatedFees := testContextSource.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(2630), accumulatedFees) + // check accumulated fees + accumulatedFees := testContextSource.TxFeeHandler.GetAccumulatedFees() + require.Equal(t, big.NewInt(2630), accumulatedFees) - // get scr for destination shard - txs := testContextSource.GetIntermediateTransactions(t) - scr := txs[0] + // get scr for destination shard + txs := testContextSource.GetIntermediateTransactions(t) + scr := txs[0] - utils.ProcessSCRResult(t, testContextDst, scr, vmcommon.Ok, nil) + utils.ProcessSCRResult(t, testContextDst, scr, vmcommon.Ok, nil) - // check balance receiver - utils.TestAccount(t, testContextDst.Accounts, rcvAddr, 0, big.NewInt(100)) + // check balance receiver + utils.TestAccount(t, testContextDst.Accounts, rcvAddr, 0, big.NewInt(100)) - // check accumulated fess - accumulatedFees = testContextDst.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(0), accumulatedFees) + // check accumulated fess + accumulatedFees = testContextDst.TxFeeHandler.GetAccumulatedFees() + require.Equal(t, big.NewInt(0), accumulatedFees) + } } func TestRelayedMoveBalanceRelayerAndInnerTxReceiverShard0SenderShard1(t *testing.T) { - testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) - require.Nil(t, err) - defer testContextSource.Close() + t.Run("before relayed move balance fix", testRelayedMoveBalanceRelayerAndInnerTxReceiverShard0SenderShard1(integrationTests.UnreachableEpoch)) + t.Run("after relayed move balance fix", testRelayedMoveBalanceRelayerAndInnerTxReceiverShard0SenderShard1(0)) +} + +func testRelayedMoveBalanceRelayerAndInnerTxReceiverShard0SenderShard1(relayedFixActivationEpoch uint32) func(t *testing.T) { + return func(t *testing.T) { + testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{ + FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + }) + require.Nil(t, err) + defer testContextSource.Close() - testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) - require.Nil(t, err) - defer testContextDst.Close() + testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ + FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + }) + require.Nil(t, err) + defer testContextDst.Close() - relayerAddr := []byte("12345678901234567890123456789030") - shardID := testContextSource.ShardCoordinator.ComputeId(relayerAddr) - require.Equal(t, uint32(0), shardID) + relayerAddr := []byte("12345678901234567890123456789030") + shardID := testContextSource.ShardCoordinator.ComputeId(relayerAddr) + require.Equal(t, uint32(0), shardID) - sndAddr := []byte("12345678901234567890123456789011") - shardID = testContextSource.ShardCoordinator.ComputeId(sndAddr) - require.Equal(t, uint32(1), shardID) + sndAddr := []byte("12345678901234567890123456789011") + shardID = testContextSource.ShardCoordinator.ComputeId(sndAddr) + require.Equal(t, uint32(1), shardID) - rcvAddr := []byte("12345678901234567890123456789010") - shardID = testContextSource.ShardCoordinator.ComputeId(rcvAddr) - require.Equal(t, uint32(0), shardID) + rcvAddr := []byte("12345678901234567890123456789010") + shardID = testContextSource.ShardCoordinator.ComputeId(rcvAddr) + require.Equal(t, uint32(0), shardID) - gasPrice := uint64(10) - gasLimit := uint64(100) + gasPrice := uint64(10) + gasLimit := uint64(100) - _, _ = vm.CreateAccount(testContextSource.Accounts, relayerAddr, 0, big.NewInt(100000)) - _, _ = vm.CreateAccount(testContextDst.Accounts, sndAddr, 0, big.NewInt(100)) + _, _ = vm.CreateAccount(testContextSource.Accounts, relayerAddr, 0, big.NewInt(100000)) + _, _ = vm.CreateAccount(testContextDst.Accounts, sndAddr, 0, big.NewInt(100)) - innerTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, rcvAddr, gasPrice, gasLimit, nil) + innerTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, rcvAddr, gasPrice, gasLimit, nil) - rtxData := integrationTests.PrepareRelayedTxDataV1(innerTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) + rtxData := integrationTests.PrepareRelayedTxDataV1(innerTx) + rTxGasLimit := minGasLimit + gasLimit + uint64(len(rtxData)) + rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) - // execute on relayer shard - retCode, err := testContextSource.TxProcessor.ProcessTransaction(rtx) - require.Equal(t, vmcommon.Ok, retCode) - require.Nil(t, err) + // execute on relayer shard + retCode, err := testContextSource.TxProcessor.ProcessTransaction(rtx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) - // check relayed balance - // 100000 - rTxFee(163)*gasPrice(10) - innerTxFee(1000) = 97370 - utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, big.NewInt(97370)) + // check relayed balance + // 100000 - rTxFee(163)*gasPrice(10) - innerTxFee(1000) = 97370 + utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, big.NewInt(97370)) - // check inner Tx receiver - innerTxSenderAccount, err := testContextSource.Accounts.GetExistingAccount(sndAddr) - require.Nil(t, innerTxSenderAccount) - require.NotNil(t, err) + // check inner Tx receiver + innerTxSenderAccount, err := testContextSource.Accounts.GetExistingAccount(sndAddr) + require.Nil(t, innerTxSenderAccount) + require.NotNil(t, err) - // check accumulated fees - accumulatedFees := testContextSource.TxFeeHandler.GetAccumulatedFees() - expectedAccFees := big.NewInt(1630) - require.Equal(t, expectedAccFees, accumulatedFees) + // check accumulated fees + accumulatedFees := testContextSource.TxFeeHandler.GetAccumulatedFees() + expectedAccFees := big.NewInt(1630) + require.Equal(t, expectedAccFees, accumulatedFees) - // execute on destination shard - retCode, err = testContextDst.TxProcessor.ProcessTransaction(rtx) - require.Equal(t, vmcommon.Ok, retCode) - require.Nil(t, err) + // execute on destination shard + retCode, err = testContextDst.TxProcessor.ProcessTransaction(rtx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) - utils.TestAccount(t, testContextDst.Accounts, sndAddr, 1, big.NewInt(0)) + utils.TestAccount(t, testContextDst.Accounts, sndAddr, 1, big.NewInt(0)) - // check accumulated fees - accumulatedFees = testContextDst.TxFeeHandler.GetAccumulatedFees() - expectedAccFees = big.NewInt(1000) - require.Equal(t, expectedAccFees, accumulatedFees) + // check accumulated fees + accumulatedFees = testContextDst.TxFeeHandler.GetAccumulatedFees() + expectedAccFees = big.NewInt(1000) + require.Equal(t, expectedAccFees, accumulatedFees) - txs := testContextDst.GetIntermediateTransactions(t) - scr := txs[0] + txs := testContextDst.GetIntermediateTransactions(t) + scr := txs[0] - // execute generated SCR from shard1 on shard 0 - utils.ProcessSCRResult(t, testContextSource, scr, vmcommon.Ok, nil) + // execute generated SCR from shard1 on shard 0 + utils.ProcessSCRResult(t, testContextSource, scr, vmcommon.Ok, nil) - // check receiver balance - utils.TestAccount(t, testContextSource.Accounts, rcvAddr, 0, big.NewInt(100)) + // check receiver balance + utils.TestAccount(t, testContextSource.Accounts, rcvAddr, 0, big.NewInt(100)) + } } func TestMoveBalanceRelayerShard0InnerTxSenderShard1InnerTxReceiverShard2ShouldWork(t *testing.T) { - testContextRelayer, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) - require.Nil(t, err) - defer testContextRelayer.Close() - - testContextInnerSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) - require.Nil(t, err) - defer testContextInnerSource.Close() - - testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{}) - require.Nil(t, err) - defer testContextDst.Close() - - relayerAddr := []byte("12345678901234567890123456789030") - shardID := testContextRelayer.ShardCoordinator.ComputeId(relayerAddr) - require.Equal(t, uint32(0), shardID) - - sndAddr := []byte("12345678901234567890123456789011") - shardID = testContextRelayer.ShardCoordinator.ComputeId(sndAddr) - require.Equal(t, uint32(1), shardID) - - rcvAddr := []byte("12345678901234567890123456789012") - shardID = testContextRelayer.ShardCoordinator.ComputeId(rcvAddr) - require.Equal(t, uint32(2), shardID) - - gasPrice := uint64(10) - gasLimit := uint64(100) - - _, _ = vm.CreateAccount(testContextRelayer.Accounts, relayerAddr, 0, big.NewInt(100000)) - _, _ = vm.CreateAccount(testContextInnerSource.Accounts, sndAddr, 0, big.NewInt(100)) - - innerTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, rcvAddr, gasPrice, gasLimit, nil) - - rtxData := integrationTests.PrepareRelayedTxDataV1(innerTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) - - // execute on relayer shard - retCode, err := testContextRelayer.TxProcessor.ProcessTransaction(rtx) - require.Equal(t, vmcommon.Ok, retCode) - require.Nil(t, err) - - // check relayed balance - // 100000 - rTxFee(164)*gasPrice(10) - innerTxFee(1000) = 97370 - utils.TestAccount(t, testContextRelayer.Accounts, relayerAddr, 1, big.NewInt(97370)) - - // check inner Tx receiver - innerTxSenderAccount, err := testContextRelayer.Accounts.GetExistingAccount(sndAddr) - require.Nil(t, innerTxSenderAccount) - require.NotNil(t, err) - - // check accumulated fees - accumulatedFees := testContextRelayer.TxFeeHandler.GetAccumulatedFees() - expectedAccFees := big.NewInt(1630) - require.Equal(t, expectedAccFees, accumulatedFees) - - // execute on inner tx sender shard - retCode, err = testContextInnerSource.TxProcessor.ProcessTransaction(rtx) - require.Equal(t, vmcommon.Ok, retCode) - require.Nil(t, err) - - utils.TestAccount(t, testContextInnerSource.Accounts, sndAddr, 1, big.NewInt(0)) - - // check accumulated fees - accumulatedFees = testContextInnerSource.TxFeeHandler.GetAccumulatedFees() - expectedAccFees = big.NewInt(1000) - require.Equal(t, expectedAccFees, accumulatedFees) - - // execute on inner tx receiver shard - txs := testContextInnerSource.GetIntermediateTransactions(t) - scr := txs[0] - - utils.ProcessSCRResult(t, testContextDst, scr, vmcommon.Ok, nil) + t.Run("before relayed move balance fix", testMoveBalanceRelayerShard0InnerTxSenderShard1InnerTxReceiverShard2ShouldWork(integrationTests.UnreachableEpoch)) + t.Run("after relayed move balance fix", testMoveBalanceRelayerShard0InnerTxSenderShard1InnerTxReceiverShard2ShouldWork(0)) +} - // check receiver balance - utils.TestAccount(t, testContextDst.Accounts, rcvAddr, 0, big.NewInt(100)) +func testMoveBalanceRelayerShard0InnerTxSenderShard1InnerTxReceiverShard2ShouldWork(relayedFixActivationEpoch uint32) func(t *testing.T) { + return func(t *testing.T) { + testContextRelayer, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{ + FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + }) + require.Nil(t, err) + defer testContextRelayer.Close() + + testContextInnerSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ + FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + }) + require.Nil(t, err) + defer testContextInnerSource.Close() + + testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{ + FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + }) + require.Nil(t, err) + defer testContextDst.Close() + + relayerAddr := []byte("12345678901234567890123456789030") + shardID := testContextRelayer.ShardCoordinator.ComputeId(relayerAddr) + require.Equal(t, uint32(0), shardID) + + sndAddr := []byte("12345678901234567890123456789011") + shardID = testContextRelayer.ShardCoordinator.ComputeId(sndAddr) + require.Equal(t, uint32(1), shardID) + + rcvAddr := []byte("12345678901234567890123456789012") + shardID = testContextRelayer.ShardCoordinator.ComputeId(rcvAddr) + require.Equal(t, uint32(2), shardID) + + gasPrice := uint64(10) + gasLimit := uint64(100) + + _, _ = vm.CreateAccount(testContextRelayer.Accounts, relayerAddr, 0, big.NewInt(100000)) + _, _ = vm.CreateAccount(testContextInnerSource.Accounts, sndAddr, 0, big.NewInt(100)) + + innerTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, rcvAddr, gasPrice, gasLimit, nil) + + rtxData := integrationTests.PrepareRelayedTxDataV1(innerTx) + rTxGasLimit := minGasLimit + gasLimit + uint64(len(rtxData)) + rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) + + // execute on relayer shard + retCode, err := testContextRelayer.TxProcessor.ProcessTransaction(rtx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) + + // check relayed balance + // 100000 - rTxFee(164)*gasPrice(10) - innerTxFee(1000) = 97370 + utils.TestAccount(t, testContextRelayer.Accounts, relayerAddr, 1, big.NewInt(97370)) + + // check inner Tx receiver + innerTxSenderAccount, err := testContextRelayer.Accounts.GetExistingAccount(sndAddr) + require.Nil(t, innerTxSenderAccount) + require.NotNil(t, err) + + // check accumulated fees + accumulatedFees := testContextRelayer.TxFeeHandler.GetAccumulatedFees() + expectedAccFees := big.NewInt(1630) + require.Equal(t, expectedAccFees, accumulatedFees) + + // execute on inner tx sender shard + retCode, err = testContextInnerSource.TxProcessor.ProcessTransaction(rtx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) + + utils.TestAccount(t, testContextInnerSource.Accounts, sndAddr, 1, big.NewInt(0)) + + // check accumulated fees + accumulatedFees = testContextInnerSource.TxFeeHandler.GetAccumulatedFees() + expectedAccFees = big.NewInt(1000) + require.Equal(t, expectedAccFees, accumulatedFees) + + // execute on inner tx receiver shard + txs := testContextInnerSource.GetIntermediateTransactions(t) + scr := txs[0] + + utils.ProcessSCRResult(t, testContextDst, scr, vmcommon.Ok, nil) + + // check receiver balance + utils.TestAccount(t, testContextDst.Accounts, rcvAddr, 0, big.NewInt(100)) + } } diff --git a/integrationTests/vm/txsFee/relayedBuiltInFunctions_test.go b/integrationTests/vm/txsFee/relayedBuiltInFunctions_test.go index dd82f276e27..e590dbde879 100644 --- a/integrationTests/vm/txsFee/relayedBuiltInFunctions_test.go +++ b/integrationTests/vm/txsFee/relayedBuiltInFunctions_test.go @@ -20,97 +20,114 @@ import ( ) func TestRelayedBuildInFunctionChangeOwnerCallShouldWork(t *testing.T) { - testContext, err := vm.CreatePreparedTxProcessorWithVMs( - config.EnableEpochs{ - PenalizedTooMuchGasEnableEpoch: integrationTests.UnreachableEpoch, - }) - require.Nil(t, err) - defer testContext.Close() + t.Run("before relayed move balance fix", testRelayedBuildInFunctionChangeOwnerCallShouldWork(integrationTests.UnreachableEpoch)) + t.Run("after relayed move balance fix", testRelayedBuildInFunctionChangeOwnerCallShouldWork(0)) +} - scAddress, owner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") - testContext.TxFeeHandler.CreateBlockStarted(getZeroGasAndFees()) - utils.CleanAccumulatedIntermediateTransactions(t, testContext) +func testRelayedBuildInFunctionChangeOwnerCallShouldWork(relayedFixActivationEpoch uint32) func(t *testing.T) { + return func(t *testing.T) { + testContext, err := vm.CreatePreparedTxProcessorWithVMs( + config.EnableEpochs{ + PenalizedTooMuchGasEnableEpoch: integrationTests.UnreachableEpoch, + FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + }) + require.Nil(t, err) + defer testContext.Close() - relayerAddr := []byte("12345678901234567890123456789033") - newOwner := []byte("12345678901234567890123456789112") - gasLimit := uint64(1000) + scAddress, owner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + testContext.TxFeeHandler.CreateBlockStarted(getZeroGasAndFees()) + utils.CleanAccumulatedIntermediateTransactions(t, testContext) - txData := []byte(core.BuiltInFunctionChangeOwnerAddress + "@" + hex.EncodeToString(newOwner)) - innerTx := vm.CreateTransaction(1, big.NewInt(0), owner, scAddress, gasPrice, gasLimit, txData) + relayerAddr := []byte("12345678901234567890123456789033") + newOwner := []byte("12345678901234567890123456789112") + gasLimit := uint64(1000) - _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(30000)) + txData := []byte(core.BuiltInFunctionChangeOwnerAddress + "@" + hex.EncodeToString(newOwner)) + innerTx := vm.CreateTransaction(1, big.NewInt(0), owner, scAddress, gasPrice, gasLimit, txData) - rtxData := integrationTests.PrepareRelayedTxDataV1(innerTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, innerTx.Value, relayerAddr, owner, gasPrice, rTxGasLimit, rtxData) + _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(30000)) - retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) - require.Equal(t, vmcommon.Ok, retCode) - require.Nil(t, err) + rtxData := integrationTests.PrepareRelayedTxDataV1(innerTx) + rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rtx := vm.CreateTransaction(0, innerTx.Value, relayerAddr, owner, gasPrice, rTxGasLimit, rtxData) - _, err = testContext.Accounts.Commit() - require.Nil(t, err) + retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) - utils.CheckOwnerAddr(t, testContext, scAddress, newOwner) + _, err = testContext.Accounts.Commit() + require.Nil(t, err) - expectedBalanceRelayer := big.NewInt(16610) - vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) + utils.CheckOwnerAddr(t, testContext, scAddress, newOwner) - expectedBalance := big.NewInt(88100) - vm.TestAccount(t, testContext.Accounts, owner, 2, expectedBalance) + expectedBalanceRelayer := big.NewInt(16610) + vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) - // check accumulated fees - accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(13390), accumulatedFees) + expectedBalance := big.NewInt(88100) + vm.TestAccount(t, testContext.Accounts, owner, 2, expectedBalance) - developerFees := testContext.TxFeeHandler.GetDeveloperFees() - require.Equal(t, big.NewInt(915), developerFees) + // check accumulated fees + accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() + require.Equal(t, big.NewInt(13390), accumulatedFees) + + developerFees := testContext.TxFeeHandler.GetDeveloperFees() + require.Equal(t, big.NewInt(915), developerFees) + } } func TestRelayedBuildInFunctionChangeOwnerCallWrongOwnerShouldConsumeGas(t *testing.T) { - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) - require.Nil(t, err) - defer testContext.Close() + t.Run("before relayed move balance fix", testRelayedBuildInFunctionChangeOwnerCallWrongOwnerShouldConsumeGas(integrationTests.UnreachableEpoch)) + t.Run("after relayed move balance fix", testRelayedBuildInFunctionChangeOwnerCallWrongOwnerShouldConsumeGas(0)) +} - scAddress, owner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") - testContext.TxFeeHandler.CreateBlockStarted(getZeroGasAndFees()) - utils.CleanAccumulatedIntermediateTransactions(t, testContext) +func testRelayedBuildInFunctionChangeOwnerCallWrongOwnerShouldConsumeGas(relayedFixActivationEpoch uint32) func(t *testing.T) { + return func(t *testing.T) { + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ + FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + }) + require.Nil(t, err) + defer testContext.Close() - relayerAddr := []byte("12345678901234567890123456789033") - sndAddr := []byte("12345678901234567890123456789113") - newOwner := []byte("12345678901234567890123456789112") - gasLimit := uint64(1000) + scAddress, owner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + testContext.TxFeeHandler.CreateBlockStarted(getZeroGasAndFees()) + utils.CleanAccumulatedIntermediateTransactions(t, testContext) - txData := []byte(core.BuiltInFunctionChangeOwnerAddress + "@" + hex.EncodeToString(newOwner)) - innerTx := vm.CreateTransaction(1, big.NewInt(0), sndAddr, scAddress, gasPrice, gasLimit, txData) + relayerAddr := []byte("12345678901234567890123456789033") + sndAddr := []byte("12345678901234567890123456789113") + newOwner := []byte("12345678901234567890123456789112") + gasLimit := uint64(1000) - _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(30000)) + txData := []byte(core.BuiltInFunctionChangeOwnerAddress + "@" + hex.EncodeToString(newOwner)) + innerTx := vm.CreateTransaction(1, big.NewInt(0), sndAddr, scAddress, gasPrice, gasLimit, txData) - rtxData := integrationTests.PrepareRelayedTxDataV1(innerTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, innerTx.Value, relayerAddr, owner, gasPrice, rTxGasLimit, rtxData) + _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(30000)) - retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) - require.Equal(t, vmcommon.UserError, retCode) - require.Equal(t, process.ErrFailedTransaction, err) + rtxData := integrationTests.PrepareRelayedTxDataV1(innerTx) + rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rtx := vm.CreateTransaction(0, innerTx.Value, relayerAddr, owner, gasPrice, rTxGasLimit, rtxData) - _, err = testContext.Accounts.Commit() - require.Nil(t, err) + retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) + require.Equal(t, vmcommon.UserError, retCode) + require.Equal(t, process.ErrFailedTransaction, err) - utils.CheckOwnerAddr(t, testContext, scAddress, owner) + _, err = testContext.Accounts.Commit() + require.Nil(t, err) - expectedBalanceRelayer := big.NewInt(16610) - vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) + utils.CheckOwnerAddr(t, testContext, scAddress, owner) - expectedBalance := big.NewInt(88100) - vm.TestAccount(t, testContext.Accounts, owner, 1, expectedBalance) + expectedBalanceRelayer := big.NewInt(16610) + vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) - // check accumulated fees - accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(13390), accumulatedFees) + expectedBalance := big.NewInt(88100) + vm.TestAccount(t, testContext.Accounts, owner, 1, expectedBalance) - developerFees := testContext.TxFeeHandler.GetDeveloperFees() - require.Equal(t, big.NewInt(0), developerFees) + // check accumulated fees + accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() + require.Equal(t, big.NewInt(13390), accumulatedFees) + + developerFees := testContext.TxFeeHandler.GetDeveloperFees() + require.Equal(t, big.NewInt(0), developerFees) + } } func TestRelayedBuildInFunctionChangeOwnerInvalidAddressShouldConsumeGas(t *testing.T) { @@ -161,13 +178,15 @@ func TestRelayedBuildInFunctionChangeOwnerCallInsufficientGasLimitShouldConsumeG t.Run("nonce fix is disabled, should increase the sender's nonce", func(t *testing.T) { testRelayedBuildInFunctionChangeOwnerCallInsufficientGasLimitShouldConsumeGas(t, config.EnableEpochs{ - RelayedNonceFixEnableEpoch: 1000, + RelayedNonceFixEnableEpoch: 1000, + FixRelayedMoveBalanceEnableEpoch: 1000, }) }) t.Run("nonce fix is enabled, should still increase the sender's nonce", func(t *testing.T) { testRelayedBuildInFunctionChangeOwnerCallInsufficientGasLimitShouldConsumeGas(t, config.EnableEpochs{ - RelayedNonceFixEnableEpoch: 0, + RelayedNonceFixEnableEpoch: 0, + FixRelayedMoveBalanceEnableEpoch: 1000, }) }) } diff --git a/integrationTests/vm/txsFee/relayedESDT_test.go b/integrationTests/vm/txsFee/relayedESDT_test.go index eba6eedb384..7f6354223d0 100644 --- a/integrationTests/vm/txsFee/relayedESDT_test.go +++ b/integrationTests/vm/txsFee/relayedESDT_test.go @@ -17,91 +17,109 @@ import ( ) func TestRelayedESDTTransferShouldWork(t *testing.T) { - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) - require.Nil(t, err) - defer testContext.Close() + t.Run("before relayed move balance fix", testRelayedESDTTransferShouldWork(integrationTests.UnreachableEpoch)) + t.Run("after relayed move balance fix", testRelayedESDTTransferShouldWork(0)) +} + +func testRelayedESDTTransferShouldWork(relayedFixActivationEpoch uint32) func(t *testing.T) { + return func(t *testing.T) { + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ + FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + }) + require.Nil(t, err) + defer testContext.Close() - relayerAddr := []byte("12345678901234567890123456789033") - sndAddr := []byte("12345678901234567890123456789012") - rcvAddr := []byte("12345678901234567890123456789022") + relayerAddr := []byte("12345678901234567890123456789033") + sndAddr := []byte("12345678901234567890123456789012") + rcvAddr := []byte("12345678901234567890123456789022") - relayerBalance := big.NewInt(10000000) - localEsdtBalance := big.NewInt(100000000) - token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), token, 0, localEsdtBalance) - _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, relayerBalance) + relayerBalance := big.NewInt(10000000) + localEsdtBalance := big.NewInt(100000000) + token := []byte("miiutoken") + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), token, 0, localEsdtBalance) + _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, relayerBalance) - gasLimit := uint64(40) - innerTx := utils.CreateESDTTransferTx(0, sndAddr, rcvAddr, token, big.NewInt(100), gasPrice, gasLimit) + gasLimit := uint64(40) + innerTx := utils.CreateESDTTransferTx(0, sndAddr, rcvAddr, token, big.NewInt(100), gasPrice, gasLimit) - rtxData := integrationTests.PrepareRelayedTxDataV1(innerTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, innerTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) + rtxData := integrationTests.PrepareRelayedTxDataV1(innerTx) + rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rtx := vm.CreateTransaction(0, innerTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) - retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) - require.Equal(t, vmcommon.Ok, retCode) - require.Nil(t, err) + retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) - _, err = testContext.Accounts.Commit() - require.Nil(t, err) + _, err = testContext.Accounts.Commit() + require.Nil(t, err) - expectedBalanceSnd := big.NewInt(99999900) - utils.CheckESDTBalance(t, testContext, sndAddr, token, expectedBalanceSnd) + expectedBalanceSnd := big.NewInt(99999900) + utils.CheckESDTBalance(t, testContext, sndAddr, token, expectedBalanceSnd) - expectedReceiverBalance := big.NewInt(100) - utils.CheckESDTBalance(t, testContext, rcvAddr, token, expectedReceiverBalance) + expectedReceiverBalance := big.NewInt(100) + utils.CheckESDTBalance(t, testContext, rcvAddr, token, expectedReceiverBalance) - expectedEGLDBalance := big.NewInt(0) - utils.TestAccount(t, testContext.Accounts, sndAddr, 1, expectedEGLDBalance) + expectedEGLDBalance := big.NewInt(0) + utils.TestAccount(t, testContext.Accounts, sndAddr, 1, expectedEGLDBalance) - utils.TestAccount(t, testContext.Accounts, relayerAddr, 1, big.NewInt(9997290)) + utils.TestAccount(t, testContext.Accounts, relayerAddr, 1, big.NewInt(9997290)) + + // check accumulated fees + accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() + require.Equal(t, big.NewInt(2710), accumulatedFees) + } +} - // check accumulated fees - accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(2710), accumulatedFees) +func TestRelayedESTTransferNotEnoughESTValueShouldConsumeGas(t *testing.T) { + t.Run("before relayed move balance fix", testRelayedESTTransferNotEnoughESTValueShouldConsumeGas(integrationTests.UnreachableEpoch)) + t.Run("after relayed move balance fix", testRelayedESTTransferNotEnoughESTValueShouldConsumeGas(0)) } -func TestTestRelayedESTTransferNotEnoughESTValueShouldConsumeGas(t *testing.T) { - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) - require.Nil(t, err) - defer testContext.Close() +func testRelayedESTTransferNotEnoughESTValueShouldConsumeGas(relayedFixActivationEpoch uint32) func(t *testing.T) { + return func(t *testing.T) { + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ + FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + }) + require.Nil(t, err) + defer testContext.Close() - relayerAddr := []byte("12345678901234567890123456789033") - sndAddr := []byte("12345678901234567890123456789012") - rcvAddr := []byte("12345678901234567890123456789022") + relayerAddr := []byte("12345678901234567890123456789033") + sndAddr := []byte("12345678901234567890123456789012") + rcvAddr := []byte("12345678901234567890123456789022") - relayerBalance := big.NewInt(10000000) - localEsdtBalance := big.NewInt(100000000) - token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), token, 0, localEsdtBalance) - _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, relayerBalance) + relayerBalance := big.NewInt(10000000) + localEsdtBalance := big.NewInt(100000000) + token := []byte("miiutoken") + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), token, 0, localEsdtBalance) + _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, relayerBalance) - gasLimit := uint64(40) - innerTx := utils.CreateESDTTransferTx(0, sndAddr, rcvAddr, token, big.NewInt(100000001), gasPrice, gasLimit) + gasLimit := uint64(42) + innerTx := utils.CreateESDTTransferTx(0, sndAddr, rcvAddr, token, big.NewInt(100000001), gasPrice, gasLimit) - rtxData := integrationTests.PrepareRelayedTxDataV1(innerTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, innerTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) + rtxData := integrationTests.PrepareRelayedTxDataV1(innerTx) + rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rtx := vm.CreateTransaction(0, innerTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) - retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) - require.Equal(t, vmcommon.UserError, retCode) - require.Nil(t, err) + retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) + require.Equal(t, vmcommon.ExecutionFailed, retCode) + require.Nil(t, err) - _, err = testContext.Accounts.Commit() - require.Nil(t, err) + _, err = testContext.Accounts.Commit() + require.Nil(t, err) - expectedBalanceSnd := big.NewInt(100000000) - utils.CheckESDTBalance(t, testContext, sndAddr, token, expectedBalanceSnd) + expectedBalanceSnd := big.NewInt(100000000) + utils.CheckESDTBalance(t, testContext, sndAddr, token, expectedBalanceSnd) - expectedReceiverBalance := big.NewInt(0) - utils.CheckESDTBalance(t, testContext, rcvAddr, token, expectedReceiverBalance) + expectedReceiverBalance := big.NewInt(0) + utils.CheckESDTBalance(t, testContext, rcvAddr, token, expectedReceiverBalance) - expectedEGLDBalance := big.NewInt(0) - utils.TestAccount(t, testContext.Accounts, sndAddr, 1, expectedEGLDBalance) + expectedEGLDBalance := big.NewInt(0) + utils.TestAccount(t, testContext.Accounts, sndAddr, 1, expectedEGLDBalance) - utils.TestAccount(t, testContext.Accounts, relayerAddr, 1, big.NewInt(9997130)) + utils.TestAccount(t, testContext.Accounts, relayerAddr, 1, big.NewInt(9997110)) - // check accumulated fees - accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(2870), accumulatedFees) + // check accumulated fees + accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() + require.Equal(t, big.NewInt(2890), accumulatedFees) + } } diff --git a/integrationTests/vm/txsFee/relayedMoveBalance_test.go b/integrationTests/vm/txsFee/relayedMoveBalance_test.go index 3cb95091537..39ced8dec59 100644 --- a/integrationTests/vm/txsFee/relayedMoveBalance_test.go +++ b/integrationTests/vm/txsFee/relayedMoveBalance_test.go @@ -38,7 +38,7 @@ func TestRelayedMoveBalanceShouldWork(t *testing.T) { userTx := vm.CreateTransaction(senderNonce, big.NewInt(100), sndAddr, rcvAddr, gasPrice, gasLimit, []byte("aaaa")) rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := gasLimit + 1 + uint64(len(rtxData)) + rTxGasLimit := gasLimit + minGasLimit + uint64(len(rtxData)) rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) @@ -111,7 +111,7 @@ func TestRelayedMoveBalanceInvalidUserTxShouldConsumeGas(t *testing.T) { _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(3000)) rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := 1 + userTx.GasLimit + uint64(len(rtxData)) + rTxGasLimit := minGasLimit + userTx.GasLimit + uint64(len(rtxData)) rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, 1, rTxGasLimit, rtxData) retcode, _ := testContext.TxProcessor.ProcessTransaction(rtx) @@ -146,7 +146,7 @@ func TestRelayedMoveBalanceInvalidUserTxValueShouldConsumeGas(t *testing.T) { _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(3000)) rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := 1 + userTx.GasLimit + uint64(len(rtxData)) + rTxGasLimit := minGasLimit + userTx.GasLimit + uint64(len(rtxData)) rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, 1, rTxGasLimit, rtxData) retCode, _ := testContext.TxProcessor.ProcessTransaction(rtx) @@ -331,7 +331,7 @@ func executeRelayedTransaction( ) { testContext.TxsLogsProcessor.Clean() relayerAccount := getAccount(tb, testContext, relayerAddress) - gasLimit := 1 + userTx.GasLimit + uint64(len(userTxPrepared)) + gasLimit := minGasLimit + userTx.GasLimit + uint64(len(userTxPrepared)) relayedTx := vm.CreateTransaction(relayerAccount.GetNonce(), value, relayerAddress, senderAddress, 1, gasLimit, userTxPrepared) retCode, _ := testContext.TxProcessor.ProcessTransaction(relayedTx) diff --git a/integrationTests/vm/txsFee/relayedScCalls_test.go b/integrationTests/vm/txsFee/relayedScCalls_test.go index d5e0e46179e..c67ff0e84c7 100644 --- a/integrationTests/vm/txsFee/relayedScCalls_test.go +++ b/integrationTests/vm/txsFee/relayedScCalls_test.go @@ -19,202 +19,245 @@ import ( ) func TestRelayedScCallShouldWork(t *testing.T) { - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ - DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, - }) - require.Nil(t, err) - defer testContext.Close() + t.Run("before relayed fix", testRelayedScCallShouldWork(integrationTests.UnreachableEpoch)) + t.Run("after relayed fix", testRelayedScCallShouldWork(0)) +} - scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") - utils.CleanAccumulatedIntermediateTransactions(t, testContext) +func testRelayedScCallShouldWork(relayedFixActivationEpoch uint32) func(t *testing.T) { + return func(t *testing.T) { + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ + DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, + FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + }) + require.Nil(t, err) + defer testContext.Close() - relayerAddr := []byte("12345678901234567890123456789033") - sndAddr := []byte("12345678901234567890123456789112") - gasLimit := uint64(1000) + scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + utils.CleanAccumulatedIntermediateTransactions(t, testContext) - _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, big.NewInt(0)) - _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(30000)) + relayerAddr := []byte("12345678901234567890123456789033") + sndAddr := []byte("12345678901234567890123456789112") + gasLimit := uint64(1000) - userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, scAddress, gasPrice, gasLimit, []byte("increment")) + _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, big.NewInt(0)) + _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(30000)) - rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, userTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) + userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, scAddress, gasPrice, gasLimit, []byte("increment")) - retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) - require.Equal(t, vmcommon.Ok, retCode) - require.Nil(t, err) + rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) + rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rtx := vm.CreateTransaction(0, userTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) - _, err = testContext.Accounts.Commit() - require.Nil(t, err) + retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) - ret := vm.GetIntValueFromSC(nil, testContext.Accounts, scAddress, "get") - require.Equal(t, big.NewInt(2), ret) + _, err = testContext.Accounts.Commit() + require.Nil(t, err) - expectedBalance := big.NewInt(23850) - vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalance) + ret := vm.GetIntValueFromSC(nil, testContext.Accounts, scAddress, "get") + require.Equal(t, big.NewInt(2), ret) - // check accumulated fees - accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(17950), accumulatedFees) + expectedBalance := big.NewInt(23850) + vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalance) - developerFees := testContext.TxFeeHandler.GetDeveloperFees() - require.Equal(t, big.NewInt(807), developerFees) + // check accumulated fees + accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() + require.Equal(t, big.NewInt(17950), accumulatedFees) + + developerFees := testContext.TxFeeHandler.GetDeveloperFees() + require.Equal(t, big.NewInt(807), developerFees) + } } func TestRelayedScCallContractNotFoundShouldConsumeGas(t *testing.T) { - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) - require.Nil(t, err) - defer testContext.Close() + t.Run("before relayed fix", testRelayedScCallContractNotFoundShouldConsumeGas(integrationTests.UnreachableEpoch)) + t.Run("after relayed fix", testRelayedScCallContractNotFoundShouldConsumeGas(0)) +} + +func testRelayedScCallContractNotFoundShouldConsumeGas(relayedFixActivationEpoch uint32) func(t *testing.T) { + return func(t *testing.T) { + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ + FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + }) + require.Nil(t, err) + defer testContext.Close() - scAddress := "00000000000000000500dbb53e4b23392b0d6f36cce32deb2d623e9625ab3132" - scAddrBytes, _ := hex.DecodeString(scAddress) + scAddress := "00000000000000000500dbb53e4b23392b0d6f36cce32deb2d623e9625ab3132" + scAddrBytes, _ := hex.DecodeString(scAddress) - relayerAddr := []byte("12345678901234567890123456789033") - sndAddr := []byte("12345678901234567890123456789112") - gasLimit := uint64(1000) + relayerAddr := []byte("12345678901234567890123456789033") + sndAddr := []byte("12345678901234567890123456789112") + gasLimit := uint64(1000) - _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, big.NewInt(0)) - _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(30000)) + _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, big.NewInt(0)) + _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(30000)) - userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, scAddrBytes, gasPrice, gasLimit, []byte("increment")) + userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, scAddrBytes, gasPrice, gasLimit, []byte("increment")) - rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, userTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) + rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) + rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rtx := vm.CreateTransaction(0, userTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) - retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) - require.Equal(t, vmcommon.UserError, retCode) - require.Nil(t, err) + retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) + require.Equal(t, vmcommon.UserError, retCode) + require.Nil(t, err) - _, err = testContext.Accounts.Commit() - require.Nil(t, err) + _, err = testContext.Accounts.Commit() + require.Nil(t, err) - expectedBalance := big.NewInt(18130) - vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalance) + expectedBalance := big.NewInt(18130) + vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalance) - // check accumulated fees - accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(11870), accumulatedFees) + // check accumulated fees + accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() + require.Equal(t, big.NewInt(11870), accumulatedFees) - developerFees := testContext.TxFeeHandler.GetDeveloperFees() - require.Equal(t, big.NewInt(0), developerFees) + developerFees := testContext.TxFeeHandler.GetDeveloperFees() + require.Equal(t, big.NewInt(0), developerFees) + } } func TestRelayedScCallInvalidMethodShouldConsumeGas(t *testing.T) { - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) - require.Nil(t, err) - defer testContext.Close() + t.Run("before relayed fix", testRelayedScCallInvalidMethodShouldConsumeGas(integrationTests.UnreachableEpoch)) + t.Run("after relayed fix", testRelayedScCallInvalidMethodShouldConsumeGas(0)) +} - scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") - utils.CleanAccumulatedIntermediateTransactions(t, testContext) +func testRelayedScCallInvalidMethodShouldConsumeGas(relayedFixActivationEpoch uint32) func(t *testing.T) { + return func(t *testing.T) { + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ + RelayedNonceFixEnableEpoch: relayedFixActivationEpoch, + }) + require.Nil(t, err) + defer testContext.Close() - relayerAddr := []byte("12345678901234567890123456789033") - sndAddr := []byte("12345678901234567890123456789112") - gasLimit := uint64(1000) + scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + utils.CleanAccumulatedIntermediateTransactions(t, testContext) - _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, big.NewInt(0)) - _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(30000)) + relayerAddr := []byte("12345678901234567890123456789033") + sndAddr := []byte("12345678901234567890123456789112") + gasLimit := uint64(1000) - userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, scAddress, gasPrice, gasLimit, []byte("invalidMethod")) + _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, big.NewInt(0)) + _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(30000)) - rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, userTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) + userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, scAddress, gasPrice, gasLimit, []byte("invalidMethod")) - retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) - require.Equal(t, vmcommon.UserError, retCode) - require.Nil(t, err) + rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) + rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rtx := vm.CreateTransaction(0, userTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) - _, err = testContext.Accounts.Commit() - require.Nil(t, err) + retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) + require.Equal(t, vmcommon.UserError, retCode) + require.Nil(t, err) - expectedBalance := big.NewInt(18050) - vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalance) + _, err = testContext.Accounts.Commit() + require.Nil(t, err) - // check accumulated fees - accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(23850), accumulatedFees) + expectedBalance := big.NewInt(18050) + vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalance) - developerFees := testContext.TxFeeHandler.GetDeveloperFees() - require.Equal(t, big.NewInt(399), developerFees) + // check accumulated fees + accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() + require.Equal(t, big.NewInt(23850), accumulatedFees) + + developerFees := testContext.TxFeeHandler.GetDeveloperFees() + require.Equal(t, big.NewInt(399), developerFees) + } } func TestRelayedScCallInsufficientGasLimitShouldConsumeGas(t *testing.T) { - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) - require.Nil(t, err) - defer testContext.Close() + t.Run("before relayed fix", testRelayedScCallInsufficientGasLimitShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(28100), big.NewInt(13800))) + t.Run("after relayed fix", testRelayedScCallInsufficientGasLimitShouldConsumeGas(0, big.NewInt(28050), big.NewInt(13850))) +} - scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") - utils.CleanAccumulatedIntermediateTransactions(t, testContext) +func testRelayedScCallInsufficientGasLimitShouldConsumeGas(relayedFixActivationEpoch uint32, expectedBalance *big.Int, expectedAccumulatedFees *big.Int) func(t *testing.T) { + return func(t *testing.T) { + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ + FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + }) + require.Nil(t, err) + defer testContext.Close() - relayerAddr := []byte("12345678901234567890123456789033") - sndAddr := []byte("12345678901234567890123456789112") - gasLimit := uint64(5) + scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + utils.CleanAccumulatedIntermediateTransactions(t, testContext) - _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, big.NewInt(0)) - _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(30000)) + relayerAddr := []byte("12345678901234567890123456789033") + sndAddr := []byte("12345678901234567890123456789112") + gasLimit := uint64(5) - userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, scAddress, gasPrice, gasLimit, []byte("increment")) + _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, big.NewInt(0)) + _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(30000)) - rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, userTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) + userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, scAddress, gasPrice, gasLimit, []byte("increment")) - retCode, _ := testContext.TxProcessor.ProcessTransaction(rtx) - require.Equal(t, vmcommon.UserError, retCode) + rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) + rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rtx := vm.CreateTransaction(0, userTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) - _, err = testContext.Accounts.Commit() - require.Nil(t, err) + retCode, _ := testContext.TxProcessor.ProcessTransaction(rtx) + require.Equal(t, vmcommon.UserError, retCode) + + _, err = testContext.Accounts.Commit() + require.Nil(t, err) - expectedBalance := big.NewInt(28100) - vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalance) + vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalance) - // check accumulated fees - accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(13800), accumulatedFees) + // check accumulated fees + accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() + require.Equal(t, expectedAccumulatedFees, accumulatedFees) - developerFees := testContext.TxFeeHandler.GetDeveloperFees() - require.Equal(t, big.NewInt(399), developerFees) + developerFees := testContext.TxFeeHandler.GetDeveloperFees() + require.Equal(t, big.NewInt(399), developerFees) + } } func TestRelayedScCallOutOfGasShouldConsumeGas(t *testing.T) { - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) - require.Nil(t, err) - defer testContext.Close() + t.Run("before relayed fix", testRelayedScCallOutOfGasShouldConsumeGas(integrationTests.UnreachableEpoch)) + t.Run("after relayed fix", testRelayedScCallOutOfGasShouldConsumeGas(0)) +} - scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") - utils.CleanAccumulatedIntermediateTransactions(t, testContext) +func testRelayedScCallOutOfGasShouldConsumeGas(relayedFixActivationEpoch uint32) func(t *testing.T) { + return func(t *testing.T) { + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ + RelayedNonceFixEnableEpoch: relayedFixActivationEpoch, + }) + require.Nil(t, err) + defer testContext.Close() - relayerAddr := []byte("12345678901234567890123456789033") - sndAddr := []byte("12345678901234567890123456789112") - gasLimit := uint64(20) + scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + utils.CleanAccumulatedIntermediateTransactions(t, testContext) - _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, big.NewInt(0)) - _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(30000)) + relayerAddr := []byte("12345678901234567890123456789033") + sndAddr := []byte("12345678901234567890123456789112") + gasLimit := uint64(20) - userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, scAddress, gasPrice, gasLimit, []byte("increment")) + _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, big.NewInt(0)) + _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(30000)) - rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, userTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) + userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, scAddress, gasPrice, gasLimit, []byte("increment")) - retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) - require.Equal(t, vmcommon.UserError, retCode) - require.Nil(t, err) + rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) + rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rtx := vm.CreateTransaction(0, userTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) - _, err = testContext.Accounts.Commit() - require.Nil(t, err) + retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) + require.Equal(t, vmcommon.UserError, retCode) + require.Nil(t, err) + + _, err = testContext.Accounts.Commit() + require.Nil(t, err) - expectedBalance := big.NewInt(27950) - vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalance) + expectedBalance := big.NewInt(27950) + vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalance) - // check accumulated fees - accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(13950), accumulatedFees) + // check accumulated fees + accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() + require.Equal(t, big.NewInt(13950), accumulatedFees) - developerFees := testContext.TxFeeHandler.GetDeveloperFees() - require.Equal(t, big.NewInt(399), developerFees) + developerFees := testContext.TxFeeHandler.GetDeveloperFees() + require.Equal(t, big.NewInt(399), developerFees) + } } func TestRelayedDeployInvalidContractShouldIncrementNonceOnSender(t *testing.T) { diff --git a/integrationTests/vm/txsFee/relayedScDeploy_test.go b/integrationTests/vm/txsFee/relayedScDeploy_test.go index a1c8601ea07..d5a10037ef8 100644 --- a/integrationTests/vm/txsFee/relayedScDeploy_test.go +++ b/integrationTests/vm/txsFee/relayedScDeploy_test.go @@ -17,161 +17,196 @@ import ( ) func TestRelayedScDeployShouldWork(t *testing.T) { - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) - require.Nil(t, err) - defer testContext.Close() + t.Run("before relayed fix", testRelayedScDeployShouldWork(integrationTests.UnreachableEpoch)) + t.Run("after relayed fix", testRelayedScDeployShouldWork(0)) +} + +func testRelayedScDeployShouldWork(relayedFixActivationEpoch uint32) func(t *testing.T) { + return func(t *testing.T) { + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ + FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + }) + require.Nil(t, err) + defer testContext.Close() - relayerAddr := []byte("12345678901234567890123456789033") - sndAddr := []byte("12345678901234567890123456789012") + relayerAddr := []byte("12345678901234567890123456789033") + sndAddr := []byte("12345678901234567890123456789012") - senderNonce := uint64(0) - senderBalance := big.NewInt(0) - gasLimit := uint64(1000) + senderNonce := uint64(0) + senderBalance := big.NewInt(0) + gasLimit := uint64(1000) - _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, senderBalance) - _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(50000)) + _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, senderBalance) + _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(50000)) - scCode := wasm.GetSCCode("../wasm/testdata/misc/fib_wasm/output/fib_wasm.wasm") - userTx := vm.CreateTransaction(senderNonce, big.NewInt(0), sndAddr, vm.CreateEmptyAddress(), gasPrice, gasLimit, []byte(wasm.CreateDeployTxData(scCode))) + scCode := wasm.GetSCCode("../wasm/testdata/misc/fib_wasm/output/fib_wasm.wasm") + userTx := vm.CreateTransaction(senderNonce, big.NewInt(0), sndAddr, vm.CreateEmptyAddress(), gasPrice, gasLimit, []byte(wasm.CreateDeployTxData(scCode))) - rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) + rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) + rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) - retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) - require.Equal(t, vmcommon.Ok, retCode) - require.Nil(t, err) + retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) - _, err = testContext.Accounts.Commit() - require.Nil(t, err) + _, err = testContext.Accounts.Commit() + require.Nil(t, err) - expectedBalanceRelayer := big.NewInt(28440) - vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) + expectedBalanceRelayer := big.NewInt(28440) + vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) - // check balance inner tx sender - vm.TestAccount(t, testContext.Accounts, sndAddr, 1, big.NewInt(0)) + // check balance inner tx sender + vm.TestAccount(t, testContext.Accounts, sndAddr, 1, big.NewInt(0)) - // check accumulated fees - accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(21560), accumulatedFees) + // check accumulated fees + accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() + require.Equal(t, big.NewInt(21560), accumulatedFees) + } } func TestRelayedScDeployInvalidCodeShouldConsumeGas(t *testing.T) { - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) - require.Nil(t, err) - defer testContext.Close() + t.Run("before relayed fix", testRelayedScDeployInvalidCodeShouldConsumeGas(integrationTests.UnreachableEpoch)) + t.Run("after relayed fix", testRelayedScDeployInvalidCodeShouldConsumeGas(0)) +} + +func testRelayedScDeployInvalidCodeShouldConsumeGas(relayedFixActivationEpoch uint32) func(t *testing.T) { + return func(t *testing.T) { + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ + FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + }) + require.Nil(t, err) + defer testContext.Close() - relayerAddr := []byte("12345678901234567890123456789033") - sndAddr := []byte("12345678901234567890123456789012") + relayerAddr := []byte("12345678901234567890123456789033") + sndAddr := []byte("12345678901234567890123456789012") - senderNonce := uint64(0) - senderBalance := big.NewInt(0) - gasLimit := uint64(500) + senderNonce := uint64(0) + senderBalance := big.NewInt(0) + gasLimit := uint64(574) - _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, senderBalance) - _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(50000)) + _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, senderBalance) + _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(50000)) - scCode := wasm.GetSCCode("../wasm/testdata/misc/fib_wasm/output/fib_wasm.wasm") - scCodeBytes := []byte(wasm.CreateDeployTxData(scCode)) - scCodeBytes = append(scCodeBytes, []byte("aaaaa")...) - userTx := vm.CreateTransaction(senderNonce, big.NewInt(0), sndAddr, vm.CreateEmptyAddress(), gasPrice, gasLimit, scCodeBytes) + scCode := wasm.GetSCCode("../wasm/testdata/misc/fib_wasm/output/fib_wasm.wasm") + scCodeBytes := []byte(wasm.CreateDeployTxData(scCode)) + scCodeBytes = append(scCodeBytes, []byte("aaaaa")...) + userTx := vm.CreateTransaction(senderNonce, big.NewInt(0), sndAddr, vm.CreateEmptyAddress(), gasPrice, gasLimit, scCodeBytes) - rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) + rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) + rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) - retCode, _ := testContext.TxProcessor.ProcessTransaction(rtx) - require.Equal(t, vmcommon.UserError, retCode) + retCode, _ := testContext.TxProcessor.ProcessTransaction(rtx) + require.Equal(t, vmcommon.UserError, retCode) - _, err = testContext.Accounts.Commit() - require.Nil(t, err) + _, err = testContext.Accounts.Commit() + require.Nil(t, err) - expectedBalanceRelayer := big.NewInt(31830) - vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) + expectedBalanceRelayer := big.NewInt(31090) + vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) - // check balance inner tx sender - vm.TestAccount(t, testContext.Accounts, sndAddr, 1, big.NewInt(0)) + // check balance inner tx sender + vm.TestAccount(t, testContext.Accounts, sndAddr, 1, big.NewInt(0)) - // check accumulated fees - accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(18170), accumulatedFees) + // check accumulated fees + accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() + require.Equal(t, big.NewInt(18910), accumulatedFees) + } } func TestRelayedScDeployInsufficientGasLimitShouldConsumeGas(t *testing.T) { - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) - require.Nil(t, err) - defer testContext.Close() + t.Run("before relayed fix", testRelayedScDeployInsufficientGasLimitShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(31930), big.NewInt(18070))) + t.Run("after relayed fix", testRelayedScDeployInsufficientGasLimitShouldConsumeGas(0, big.NewInt(31240), big.NewInt(18760))) +} + +func testRelayedScDeployInsufficientGasLimitShouldConsumeGas(relayedFixActivationEpoch uint32, expectedBalance *big.Int, expectedAccumulatedFees *big.Int) func(t *testing.T) { + return func(t *testing.T) { + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ + FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + }) + require.Nil(t, err) + defer testContext.Close() - relayerAddr := []byte("12345678901234567890123456789033") - sndAddr := []byte("12345678901234567890123456789012") + relayerAddr := []byte("12345678901234567890123456789033") + sndAddr := []byte("12345678901234567890123456789012") - senderNonce := uint64(0) - senderBalance := big.NewInt(0) - gasLimit := uint64(500) + senderNonce := uint64(0) + senderBalance := big.NewInt(0) + gasLimit := uint64(500) - _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, senderBalance) - _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(50000)) + _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, senderBalance) + _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(50000)) - scCode := wasm.GetSCCode("../wasm/testdata/misc/fib_wasm/output/fib_wasm.wasm") - userTx := vm.CreateTransaction(senderNonce, big.NewInt(0), sndAddr, vm.CreateEmptyAddress(), gasPrice, gasLimit, []byte(wasm.CreateDeployTxData(scCode))) + scCode := wasm.GetSCCode("../wasm/testdata/misc/fib_wasm/output/fib_wasm.wasm") + userTx := vm.CreateTransaction(senderNonce, big.NewInt(0), sndAddr, vm.CreateEmptyAddress(), gasPrice, gasLimit, []byte(wasm.CreateDeployTxData(scCode))) - rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) + rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) + rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) - retCode, _ := testContext.TxProcessor.ProcessTransaction(rtx) - require.Equal(t, vmcommon.UserError, retCode) + retCode, _ := testContext.TxProcessor.ProcessTransaction(rtx) + require.Equal(t, vmcommon.UserError, retCode) - _, err = testContext.Accounts.Commit() - require.Nil(t, err) + _, err = testContext.Accounts.Commit() + require.Nil(t, err) - expectedBalanceRelayer := big.NewInt(31930) - vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) + vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalance) - // check balance inner tx sender - vm.TestAccount(t, testContext.Accounts, sndAddr, 1, big.NewInt(0)) + // check balance inner tx sender + vm.TestAccount(t, testContext.Accounts, sndAddr, 1, big.NewInt(0)) - // check accumulated fees - accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(18070), accumulatedFees) + // check accumulated fees + accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() + require.Equal(t, expectedAccumulatedFees, accumulatedFees) + } } func TestRelayedScDeployOutOfGasShouldConsumeGas(t *testing.T) { - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) - require.Nil(t, err) - defer testContext.Close() + t.Run("before relayed fix", testRelayedScDeployOutOfGasShouldConsumeGas(integrationTests.UnreachableEpoch)) + t.Run("after relayed fix", testRelayedScDeployOutOfGasShouldConsumeGas(0)) +} + +func testRelayedScDeployOutOfGasShouldConsumeGas(relayedFixActivationEpoch uint32) func(t *testing.T) { + return func(t *testing.T) { + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ + FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + }) + require.Nil(t, err) + defer testContext.Close() - relayerAddr := []byte("12345678901234567890123456789033") - sndAddr := []byte("12345678901234567890123456789012") + relayerAddr := []byte("12345678901234567890123456789033") + sndAddr := []byte("12345678901234567890123456789012") - senderNonce := uint64(0) - senderBalance := big.NewInt(0) - gasLimit := uint64(570) + senderNonce := uint64(0) + senderBalance := big.NewInt(0) + gasLimit := uint64(570) - _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, senderBalance) - _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(50000)) + _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, senderBalance) + _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(50000)) - scCode := wasm.GetSCCode("../wasm/testdata/misc/fib_wasm/output/fib_wasm.wasm") - userTx := vm.CreateTransaction(senderNonce, big.NewInt(0), sndAddr, vm.CreateEmptyAddress(), gasPrice, gasLimit, []byte(wasm.CreateDeployTxData(scCode))) + scCode := wasm.GetSCCode("../wasm/testdata/misc/fib_wasm/output/fib_wasm.wasm") + userTx := vm.CreateTransaction(senderNonce, big.NewInt(0), sndAddr, vm.CreateEmptyAddress(), gasPrice, gasLimit, []byte(wasm.CreateDeployTxData(scCode))) - rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) - rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) + rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) + rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rtx := vm.CreateTransaction(0, big.NewInt(0), relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) - code, err := testContext.TxProcessor.ProcessTransaction(rtx) - require.Equal(t, vmcommon.UserError, code) - require.Nil(t, err) + code, err := testContext.TxProcessor.ProcessTransaction(rtx) + require.Equal(t, vmcommon.UserError, code) + require.Nil(t, err) - _, err = testContext.Accounts.Commit() - require.Nil(t, err) + _, err = testContext.Accounts.Commit() + require.Nil(t, err) - expectedBalanceRelayer := big.NewInt(31230) - vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) + expectedBalanceRelayer := big.NewInt(31230) + vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) - // check balance inner tx sender - vm.TestAccount(t, testContext.Accounts, sndAddr, 1, big.NewInt(0)) + // check balance inner tx sender + vm.TestAccount(t, testContext.Accounts, sndAddr, 1, big.NewInt(0)) - // check accumulated fees - accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(18770), accumulatedFees) + // check accumulated fees + accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() + require.Equal(t, big.NewInt(18770), accumulatedFees) + } } diff --git a/process/transaction/baseProcess.go b/process/transaction/baseProcess.go index 3fba7e8906f..cf4f22ff2f2 100644 --- a/process/transaction/baseProcess.go +++ b/process/transaction/baseProcess.go @@ -117,7 +117,6 @@ func (txProc *baseTxProcessor) checkTxValues( tx *transaction.Transaction, acntSnd, acntDst state.UserAccountHandler, isUserTxOfRelayed bool, - txType process.TransactionType, ) error { err := txProc.verifyGuardian(tx, acntSnd) if err != nil { @@ -146,9 +145,7 @@ func (txProc *baseTxProcessor) checkTxValues( if tx.GasLimit < txProc.economicsFee.ComputeGasLimit(tx) { return process.ErrNotEnoughGasInUserTx } - shouldConsiderMoveBalanceFee := txType == process.MoveBalance && - txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() - if shouldConsiderMoveBalanceFee { + if txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() { txFee = txProc.economicsFee.ComputeTxFee(tx) } else { txFee = txProc.economicsFee.ComputeFeeForProcessing(tx, tx.GasLimit) @@ -224,7 +221,7 @@ func (txProc *baseTxProcessor) VerifyTransaction(tx *transaction.Transaction) er return err } - return txProc.checkTxValues(tx, senderAccount, receiverAccount, false, process.MoveBalance) + return txProc.checkTxValues(tx, senderAccount, receiverAccount, false) } // Setting a guardian is allowed with regular transactions on a guarded account diff --git a/process/transaction/export_test.go b/process/transaction/export_test.go index 8e110b78cfa..0a20721872c 100644 --- a/process/transaction/export_test.go +++ b/process/transaction/export_test.go @@ -20,8 +20,8 @@ func (txProc *txProcessor) GetAccounts(adrSrc, adrDst []byte, } // CheckTxValues calls the un-exported method checkTxValues -func (txProc *txProcessor) CheckTxValues(tx *transaction.Transaction, acntSnd, acntDst state.UserAccountHandler, isUserTxOfRelayed bool, destTxType process.TransactionType) error { - return txProc.checkTxValues(tx, acntSnd, acntDst, isUserTxOfRelayed, destTxType) +func (txProc *txProcessor) CheckTxValues(tx *transaction.Transaction, acntSnd, acntDst state.UserAccountHandler, isUserTxOfRelayed bool) error { + return txProc.checkTxValues(tx, acntSnd, acntDst, isUserTxOfRelayed) } // IncreaseNonce calls IncreaseNonce on the provided account diff --git a/process/transaction/metaProcess.go b/process/transaction/metaProcess.go index cd88c64f387..51f2c721552 100644 --- a/process/transaction/metaProcess.go +++ b/process/transaction/metaProcess.go @@ -118,8 +118,7 @@ func (txProc *metaTxProcessor) ProcessTransaction(tx *transaction.Transaction) ( txProc.pubkeyConv, ) - txType, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(tx) - err = txProc.checkTxValues(tx, acntSnd, acntDst, false, dstShardTxType) + err = txProc.checkTxValues(tx, acntSnd, acntDst, false) if err != nil { if errors.Is(err, process.ErrUserNameDoesNotMatchInCrossShardTx) { errProcessIfErr := txProc.processIfTxErrorCrossShard(tx, err.Error()) @@ -131,6 +130,8 @@ func (txProc *metaTxProcessor) ProcessTransaction(tx *transaction.Transaction) ( return 0, err } + txType, _ := txProc.txTypeHandler.ComputeTransactionType(tx) + switch txType { case process.SCDeployment: return txProc.processSCDeployment(tx, tx.SndAddr) diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 88afd9d2239..764192b81ba 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -185,7 +185,7 @@ func (txProc *txProcessor) ProcessTransaction(tx *transaction.Transaction) (vmco ) txType, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(tx) - err = txProc.checkTxValues(tx, acntSnd, acntDst, false, dstShardTxType) + err = txProc.checkTxValues(tx, acntSnd, acntDst, false) if err != nil { if errors.Is(err, process.ErrInsufficientFunds) { receiptErr := txProc.executingFailedTransaction(tx, acntSnd, err) @@ -377,9 +377,7 @@ func (txProc *txProcessor) processTxFee( if isUserTxOfRelayed { totalCost := txProc.economicsFee.ComputeFeeForProcessing(tx, tx.GasLimit) - shouldConsiderMoveBalanceFee := dstShardTxType == process.MoveBalance && - txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() - if shouldConsiderMoveBalanceFee { + if txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() { totalCost = txProc.economicsFee.ComputeTxFee(tx) } err := acntSnd.SubFromBalance(totalCost) @@ -720,15 +718,10 @@ func (txProc *txProcessor) processRelayedTx( func (txProc *txProcessor) computeRelayedTxFees(tx, userTx *transaction.Transaction) relayedFees { relayerFee := txProc.economicsFee.ComputeMoveBalanceFee(tx) - totalFee := big.NewInt(0) - _, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(userTx) - shouldConsiderMoveBalanceFee := dstShardTxType == process.MoveBalance && - txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() - if shouldConsiderMoveBalanceFee { + totalFee := txProc.economicsFee.ComputeTxFee(tx) + if txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() { userFee := txProc.economicsFee.ComputeTxFee(userTx) totalFee = totalFee.Add(relayerFee, userFee) - } else { - totalFee = txProc.economicsFee.ComputeTxFee(tx) } remainingFee := big.NewInt(0).Sub(totalFee, relayerFee) @@ -761,10 +754,7 @@ func (txProc *txProcessor) removeValueAndConsumedFeeFromUser( } consumedFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, userTx.GasLimit) - _, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(userTx) - shouldConsiderMoveBalanceFee := dstShardTxType == process.MoveBalance && - txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() - if shouldConsiderMoveBalanceFee { + if txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() { consumedFee = txProc.economicsFee.ComputeTxFee(userTx) } err = userAcnt.SubFromBalance(consumedFee) @@ -810,6 +800,9 @@ func (txProc *txProcessor) processMoveBalanceCostRelayedUserTx( ) error { moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(userTx) moveBalanceUserFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, moveBalanceGasLimit) + if txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() { + moveBalanceUserFee = txProc.economicsFee.ComputeMoveBalanceFee(userTx) + } userScrHash, err := core.CalculateHash(txProc.marshalizer, txProc.hasher, userScr) if err != nil { @@ -841,7 +834,7 @@ func (txProc *txProcessor) processUserTx( relayerAdr := originalTx.SndAddr txType, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(userTx) - err = txProc.checkTxValues(userTx, acntSnd, acntDst, true, dstShardTxType) + err = txProc.checkTxValues(userTx, acntSnd, acntDst, true) if err != nil { errRemove := txProc.removeValueAndConsumedFeeFromUser(userTx, relayedTxValue, originalTxHash, originalTx, err) if errRemove != nil { @@ -1011,6 +1004,10 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( } totalFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, userTx.GasLimit) + if txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() { + totalFee = txProc.economicsFee.ComputeTxFee(userTx) + } + senderShardID := txProc.shardCoordinator.ComputeId(userTx.SndAddr) if senderShardID != txProc.shardCoordinator.SelfId() { moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(userTx) @@ -1018,13 +1015,6 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( totalFee.Sub(totalFee, moveBalanceUserFee) } - _, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(userTx) - shouldConsiderMoveBalanceFee := dstShardTxType == process.MoveBalance && - txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() - if shouldConsiderMoveBalanceFee { - totalFee = txProc.economicsFee.ComputeTxFee(userTx) - } - txProc.txFeeHandler.ProcessTransactionFee(totalFee, big.NewInt(0), originalTxHash) if !check.IfNil(relayerAcnt) { diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index 9559a4a57aa..e02551b83d3 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -482,7 +482,7 @@ func TestTxProcessor_CheckTxValuesHigherNonceShouldErr(t *testing.T) { acnt1.IncreaseNonce(6) - err := execTx.CheckTxValues(&transaction.Transaction{Nonce: 7}, acnt1, nil, false, process.InvalidTransaction) + err := execTx.CheckTxValues(&transaction.Transaction{Nonce: 7}, acnt1, nil, false) assert.Equal(t, process.ErrHigherNonceInTransaction, err) } @@ -496,7 +496,7 @@ func TestTxProcessor_CheckTxValuesLowerNonceShouldErr(t *testing.T) { acnt1.IncreaseNonce(6) - err := execTx.CheckTxValues(&transaction.Transaction{Nonce: 5}, acnt1, nil, false, process.InvalidTransaction) + err := execTx.CheckTxValues(&transaction.Transaction{Nonce: 5}, acnt1, nil, false) assert.Equal(t, process.ErrLowerNonceInTransaction, err) } @@ -510,7 +510,7 @@ func TestTxProcessor_CheckTxValuesInsufficientFundsShouldErr(t *testing.T) { _ = acnt1.AddToBalance(big.NewInt(67)) - err := execTx.CheckTxValues(&transaction.Transaction{Value: big.NewInt(68)}, acnt1, nil, false, process.InvalidTransaction) + err := execTx.CheckTxValues(&transaction.Transaction{Value: big.NewInt(68)}, acnt1, nil, false) assert.Equal(t, process.ErrInsufficientFunds, err) } @@ -530,7 +530,7 @@ func TestTxProcessor_CheckTxValuesMismatchedSenderUsernamesShouldErr(t *testing. SndUserName: []byte("notCorrect"), } - err := execTx.CheckTxValues(tx, senderAcc, nil, false, process.InvalidTransaction) + err := execTx.CheckTxValues(tx, senderAcc, nil, false) assert.Equal(t, process.ErrUserNameDoesNotMatch, err) } @@ -550,7 +550,7 @@ func TestTxProcessor_CheckTxValuesMismatchedReceiverUsernamesShouldErr(t *testin RcvUserName: []byte("notCorrect"), } - err := execTx.CheckTxValues(tx, nil, receiverAcc, false, process.InvalidTransaction) + err := execTx.CheckTxValues(tx, nil, receiverAcc, false) assert.Equal(t, process.ErrUserNameDoesNotMatchInCrossShardTx, err) } @@ -575,7 +575,7 @@ func TestTxProcessor_CheckTxValuesCorrectUserNamesShouldWork(t *testing.T) { RcvUserName: recvAcc.GetUserName(), } - err := execTx.CheckTxValues(tx, senderAcc, recvAcc, false, process.InvalidTransaction) + err := execTx.CheckTxValues(tx, senderAcc, recvAcc, false) assert.Nil(t, err) } @@ -589,7 +589,7 @@ func TestTxProcessor_CheckTxValuesOkValsShouldErr(t *testing.T) { _ = acnt1.AddToBalance(big.NewInt(67)) - err := execTx.CheckTxValues(&transaction.Transaction{Value: big.NewInt(67)}, acnt1, nil, false, process.MoveBalance) + err := execTx.CheckTxValues(&transaction.Transaction{Value: big.NewInt(67)}, acnt1, nil, false) assert.Nil(t, err) } @@ -1472,6 +1472,9 @@ func TestTxProcessor_ProcessTxFeeSCInvokeUserTx(t *testing.T) { negMoveBalanceFee := big.NewInt(0).Neg(moveBalanceFee) gasPerByte := uint64(1) args := createArgsForTxProcessor() + args.EnableEpochsHandler = &enableEpochsHandlerMock.EnableEpochsHandlerStub{ + IsPenalizedTooMuchGasFlagEnabledField: true, + } args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { return moveBalanceFee @@ -2857,12 +2860,12 @@ func TestTxProcessor_ConsumeMoveBalanceWithUserTx(t *testing.T) { args := createArgsForTxProcessor() args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ - ComputeFeeForProcessingCalled: func(tx data.TransactionWithFeeHandler, gasToUse uint64) *big.Int { - return big.NewInt(1) - }, ComputeTxFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { return big.NewInt(150) }, + ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { + return big.NewInt(1) + }, } args.TxFeeHandler = &mock.FeeAccumulatorStub{ ProcessTransactionFeeCalled: func(cost *big.Int, devFee *big.Int, hash []byte) { @@ -2884,7 +2887,7 @@ func TestTxProcessor_ConsumeMoveBalanceWithUserTx(t *testing.T) { err := execTx.ProcessMoveBalanceCostRelayedUserTx(userTx, &smartContractResult.SmartContractResult{}, acntSrc, originalTxHash) assert.Nil(t, err) - assert.Equal(t, acntSrc.GetBalance(), big.NewInt(99)) + assert.Equal(t, big.NewInt(99), acntSrc.GetBalance()) } func TestTxProcessor_IsCrossTxFromMeShouldWork(t *testing.T) { From 9f76f8056173b784f4de0bf250a3b94773f86120 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 31 Oct 2023 12:00:19 +0200 Subject: [PATCH 018/503] fixed tests when running with race --- integrationTests/vm/txsFee/guardAccount_test.go | 1 - integrationTests/vm/txsFee/moveBalance_test.go | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/integrationTests/vm/txsFee/guardAccount_test.go b/integrationTests/vm/txsFee/guardAccount_test.go index 60cfb5e0b27..edce650481f 100644 --- a/integrationTests/vm/txsFee/guardAccount_test.go +++ b/integrationTests/vm/txsFee/guardAccount_test.go @@ -38,7 +38,6 @@ const guardAccountGas = uint64(250000) const unGuardAccountGas = uint64(250000) const setGuardianGas = uint64(250000) const transferGas = uint64(1000) -const minGasLimit = uint64(1) var ( alice = []byte("alice-12345678901234567890123456") diff --git a/integrationTests/vm/txsFee/moveBalance_test.go b/integrationTests/vm/txsFee/moveBalance_test.go index 78646813825..db0ca8371ec 100644 --- a/integrationTests/vm/txsFee/moveBalance_test.go +++ b/integrationTests/vm/txsFee/moveBalance_test.go @@ -17,6 +17,7 @@ import ( ) const gasPrice = uint64(10) +const minGasLimit = uint64(1) // minGasPrice = 1, gasPerDataByte = 1, minGasLimit = 1 func TestMoveBalanceSelfShouldWorkAndConsumeTxFee(t *testing.T) { From 7bd13b2165f190f226fcbb9a7f54f435573c1ae5 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 31 Oct 2023 14:58:02 +0200 Subject: [PATCH 019/503] added test --- vm/systemSmartContracts/esdt_test.go | 47 ++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/vm/systemSmartContracts/esdt_test.go b/vm/systemSmartContracts/esdt_test.go index b3d0f5b698e..e9607afce0c 100644 --- a/vm/systemSmartContracts/esdt_test.go +++ b/vm/systemSmartContracts/esdt_test.go @@ -4450,3 +4450,50 @@ func TestEsdt_SetNFTCreateRoleAfterStopNFTCreateShouldNotWork(t *testing.T) { output = e.Execute(vmInput) assert.Equal(t, vmcommon.Ok, output) } + +func TestEsdt_UpdateTokenType(t *testing.T) { + t.Parallel() + + args := createMockArgumentsForESDT() + enableEpochsHandler, _ := args.EnableEpochsHandler.(*enableEpochsHandlerMock.EnableEpochsHandlerStub) + eei := createDefaultEei() + args.Eei = eei + + owner := bytes.Repeat([]byte{1}, 32) + tokenName := []byte("TOKEN-ABABAB") + tokensMap := map[string][]byte{} + marshalizedData, _ := args.Marshalizer.Marshal(ESDTDataV2{ + TokenName: tokenName, + OwnerAddress: owner, + CanPause: true, + IsPaused: true, + TokenType: []byte(core.NonFungibleESDT), + CanAddSpecialRoles: true, + }) + tokensMap[string(tokenName)] = marshalizedData + eei.storageUpdate[string(eei.scAddress)] = tokensMap + + e, _ := NewESDTSmartContract(args) + + vmInput := getDefaultVmInputForFunc("setSpecialRole", [][]byte{tokenName, owner, []byte(core.ESDTRoleNFTCreate)}) + vmInput.CallerAddr = owner + output := e.Execute(vmInput) + assert.Equal(t, vmcommon.Ok, output) + + vmInput = getDefaultVmInputForFunc("stopNFTCreate", [][]byte{tokenName}) + vmInput.CallerAddr = owner + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.Ok, output) + + vmInput = getDefaultVmInputForFunc("setSpecialRole", [][]byte{tokenName, owner, []byte(core.ESDTRoleNFTCreate)}) + vmInput.CallerAddr = owner + enableEpochsHandler.IsNFTStopCreateEnabledField = true + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.UserError, output) + assert.True(t, strings.Contains(eei.returnMessage, "cannot add NFT create role as NFT creation was stopped")) + + enableEpochsHandler.IsNFTStopCreateEnabledField = false + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.Ok, output) +} From b5ff7d0ade3410024d221d4f5f4097b5283cfafe Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 2 Nov 2023 15:26:29 +0200 Subject: [PATCH 020/503] implementation of new roles and dynamic NFTs --- vm/systemSmartContracts/esdt.go | 231 +++++++++++++++++++++++++++++++- 1 file changed, 226 insertions(+), 5 deletions(-) diff --git a/vm/systemSmartContracts/esdt.go b/vm/systemSmartContracts/esdt.go index 2bd2287ee8d..1b561cf1858 100644 --- a/vm/systemSmartContracts/esdt.go +++ b/vm/systemSmartContracts/esdt.go @@ -43,10 +43,21 @@ const canCreateMultiShard = "canCreateMultiShard" const upgradeProperties = "upgradeProperties" const conversionBase = 10 + const metaESDT = "MetaESDT" const nonFungibleV2 = "NonFungibleESDTV2" const ESDTSetTokenType = "ESDTSetTokenType" +const dynamic = "dynamic" +const dynamicNFT = dynamic + nonFungibleV2 +const dynamicSFT = dynamic + core.SemiFungibleESDT +const dynamicMetaESDT = dynamic + metaESDT + +const ESDTRoleSetNewURI = "ESDTRoleSetNewURI" +const ESDTRoleModifyRoyalties = "ESDTRoleModifyRoyalties" +const ESDTRoleModifyCreator = "ESDTRoleModifyCreator" +const ESDTRoleNFTRecreate = "ESDTRoleNFTRecreate" + type esdt struct { eei vm.SystemEI gasCost vm.GasCost @@ -201,6 +212,10 @@ func (e *esdt) Execute(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { return e.sendAllTransferRoleAddresses(args) case "updateTokenID": return e.updateTokenID(args) + case "registerDynamic": + return e.registerDynamic(args) + case "registerAndSetAllRolesDynamic": + return e.registerAndSetAllRolesDynamic(args) } e.eei.AddReturnMessage("invalid method to call") @@ -443,7 +458,7 @@ func (e *esdt) registerMetaESDT(args *vmcommon.ContractCallInput) vmcommon.Retur return vmcommon.Ok } -// arguments list: tokenName, tickerID prefix, type of token, numDecimals, numGlobalSettings, listGlobalSettings, list(address, special roles) +// arguments list: tokenName, tickerID prefix, type of token, numDecimals, numGlobalSettings, listGlobalSettings func (e *esdt) registerAndSetRoles(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { if !e.enableEpochsHandler.IsESDTRegisterAndSetAllRolesFlagEnabled() { e.eei.AddReturnMessage("invalid method to call") @@ -491,7 +506,7 @@ func (e *esdt) registerAndSetRoles(args *vmcommon.ContractCallInput) vmcommon.Re return vmcommon.UserError } - allRoles, err := getAllRolesForTokenType(string(tokenType)) + allRoles, err := e.getAllRolesForTokenType(string(tokenType)) if err != nil { e.eei.AddReturnMessage(err.Error()) return vmcommon.UserError @@ -524,14 +539,24 @@ func (e *esdt) registerAndSetRoles(args *vmcommon.ContractCallInput) vmcommon.Re return vmcommon.Ok } -func getAllRolesForTokenType(tokenType string) ([][]byte, error) { +func (e *esdt) getAllRolesForTokenType(tokenType string) ([][]byte, error) { switch tokenType { - case core.NonFungibleESDT, nonFungibleV2: - return [][]byte{[]byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleNFTBurn), []byte(core.ESDTRoleNFTUpdateAttributes), []byte(core.ESDTRoleNFTAddURI)}, nil + case core.NonFungibleESDT, nonFungibleV2, dynamicNFT: + nftRoles := [][]byte{[]byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleNFTBurn), []byte(core.ESDTRoleNFTUpdateAttributes), []byte(core.ESDTRoleNFTAddURI)} + if e.enableEpochsHandler.DynamicESDTEnabled() { + nftRoles = append(nftRoles, [][]byte{[]byte(ESDTRoleNFTRecreate), []byte(ESDTRoleModifyCreator), []byte(ESDTRoleModifyRoyalties), []byte(ESDTRoleSetNewURI)}...) + } + + return nftRoles, nil case core.SemiFungibleESDT, metaESDT: return [][]byte{[]byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleNFTBurn), []byte(core.ESDTRoleNFTAddQuantity)}, nil case core.FungibleESDT: return [][]byte{[]byte(core.ESDTRoleLocalMint), []byte(core.ESDTRoleLocalBurn)}, nil + case dynamicSFT, dynamicMetaESDT: + dynamicRoles := [][]byte{[]byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleNFTBurn), []byte(core.ESDTRoleNFTAddQuantity), []byte(core.ESDTRoleNFTUpdateAttributes), []byte(core.ESDTRoleNFTAddURI)} + dynamicRoles = append(dynamicRoles, [][]byte{[]byte(ESDTRoleNFTRecreate), []byte(ESDTRoleModifyCreator), []byte(ESDTRoleModifyRoyalties), []byte(ESDTRoleSetNewURI)}...) + + return dynamicRoles, nil } return nil, vm.ErrInvalidArgument @@ -1576,11 +1601,70 @@ func (e *esdt) isSpecialRoleValidForNonFungible(argument string) error { return nil } return vm.ErrInvalidArgument + case ESDTRoleSetNewURI: + if e.enableEpochsHandler.DynamicESDTEnabled() { + return nil + } + return vm.ErrInvalidArgument + case ESDTRoleModifyCreator: + if e.enableEpochsHandler.DynamicESDTEnabled() { + return nil + } + return vm.ErrInvalidArgument + case ESDTRoleModifyRoyalties: + if e.enableEpochsHandler.DynamicESDTEnabled() { + return nil + } + return vm.ErrInvalidArgument + case ESDTRoleNFTRecreate: + if e.enableEpochsHandler.DynamicESDTEnabled() { + return nil + } + return vm.ErrInvalidArgument + default: + return vm.ErrInvalidArgument + } +} + +func (e *esdt) isSpecialRoleValidForDynamicNFT(argument string) error { + switch argument { + case core.ESDTRoleNFTBurn: + return nil + case core.ESDTRoleNFTCreate: + return nil + case core.ESDTRoleTransfer: + return nil + case core.ESDTRoleNFTUpdateAttributes: + return nil + case core.ESDTRoleNFTAddURI: + return nil + case ESDTRoleSetNewURI: + return nil + case ESDTRoleModifyCreator: + return nil + case ESDTRoleModifyRoyalties: + return nil + case ESDTRoleNFTRecreate: + return nil default: return vm.ErrInvalidArgument } } +func (e *esdt) isSpecialRoleValidForDynamicSFT(argument string) error { + err := e.isSpecialRoleValidForDynamicNFT(argument) + if err == nil { + return nil + } + + switch argument { + case core.ESDTRoleNFTAddQuantity: + return nil + } + + return vm.ErrInvalidArgument +} + func (e *esdt) checkSpecialRolesAccordingToTokenType(args [][]byte, token *ESDTDataV2) error { switch string(token.TokenType) { case core.FungibleESDT: @@ -1594,6 +1678,10 @@ func (e *esdt) checkSpecialRolesAccordingToTokenType(args [][]byte, token *ESDTD if isCheckMetaESDTOnRolesFlagEnabled { return validateRoles(args, e.isSpecialRoleValidForSemiFungible) } + case dynamicNFT: + return validateRoles(args, e.isSpecialRoleValidForDynamicNFT) + case dynamicSFT, dynamicMetaESDT: + return validateRoles(args, e.isSpecialRoleValidForDynamicSFT) } return nil } @@ -1659,6 +1747,36 @@ func (e *esdt) changeToMultiShardCreate(args *vmcommon.ContractCallInput) vmcomm return vmcommon.Ok } +func isDynamicTokenType(tokenType []byte) bool { + prefixLength := len(dynamic) + if len(tokenType) < prefixLength { + return false + } + + return bytes.Equal(tokenType[:prefixLength], []byte(dynamic)) +} + +func (e *esdt) checkRolesForDynamicTokens( + token *ESDTDataV2, + roles [][]byte, +) vmcommon.ReturnCode { + if !isDynamicTokenType(token.TokenType) { + return vmcommon.Ok + } + + rolesWhichHasToBeSingular := []string{core.ESDTRoleNFTCreate, core.ESDTRoleNFTUpdateAttributes, core.ESDTRoleNFTAddURI, + ESDTRoleSetNewURI, ESDTRoleModifyCreator, ESDTRoleModifyRoyalties, ESDTRoleNFTRecreate} + + for _, role := range rolesWhichHasToBeSingular { + if checkIfDefinedRoleExistsInArgsAndToken(roles, token, []byte(role)) { + e.eei.AddReturnMessage(role + " already exists") + return vmcommon.UserError + } + } + + return vmcommon.Ok +} + func (e *esdt) setRolesForTokenAndAddress( token *ESDTDataV2, address []byte, @@ -1686,6 +1804,11 @@ func (e *esdt) setRolesForTokenAndAddress( return nil, vmcommon.UserError } + returnCode := e.checkRolesForDynamicTokens(token, roles) + if returnCode != vmcommon.Ok { + return nil, returnCode + } + transferRoleExists := checkIfDefinedRoleExistsInArgsAndToken(roles, token, []byte(core.ESDTRoleTransfer)) esdtRole, isNew := getRolesForAddress(token, address) @@ -2103,6 +2226,104 @@ func (e *esdt) updateTokenID(args *vmcommon.ContractCallInput) vmcommon.ReturnCo return vmcommon.Ok } +func (e *esdt) createDynamicToken(args *vmcommon.ContractCallInput) ([]byte, *ESDTDataV2, vmcommon.ReturnCode) { + if !e.enableEpochsHandler.DynamicESDTEnabled() { + e.eei.AddReturnMessage("invalid method to call") + return nil, nil, vmcommon.UserError + } + returnCode := e.checkBasicCreateArguments(args) + if returnCode != vmcommon.Ok { + return nil, nil, returnCode + } + if len(args.Arguments) < 3 { + e.eei.AddReturnMessage("not enough arguments") + return nil, nil, vmcommon.UserError + } + + isWithDecimals, tokenType, err := e.getTokenType(args.Arguments[2]) + if err != nil { + e.eei.AddReturnMessage(err.Error()) + return nil, nil, vmcommon.UserError + } + + propertiesStart := 3 + numOfDecimals := uint32(0) + if isWithDecimals { + propertiesStart++ + numOfDecimals = uint32(big.NewInt(0).SetBytes(args.Arguments[3]).Uint64()) + if numOfDecimals < minNumberOfDecimals || numOfDecimals > maxNumberOfDecimals { + e.eei.AddReturnMessage(fmt.Errorf("%w, minimum: %d, maximum: %d, provided: %d", + vm.ErrInvalidNumberOfDecimals, + minNumberOfDecimals, + maxNumberOfDecimals, + numOfDecimals, + ).Error()) + return nil, nil, vmcommon.UserError + } + } + + dynamicTokenType := append([]byte(dynamic), tokenType...) + + tokenIdentifier, token, err := e.createNewToken( + args.CallerAddr, + args.Arguments[0], + args.Arguments[1], + big.NewInt(0), + numOfDecimals, + args.Arguments[propertiesStart:], + dynamicTokenType) + if err != nil { + e.eei.AddReturnMessage(err.Error()) + return nil, nil, vmcommon.UserError + } + + logEntry := &vmcommon.LogEntry{ + Identifier: []byte(args.Function), + Address: args.CallerAddr, + Topics: [][]byte{tokenIdentifier, args.Arguments[0], args.Arguments[1], dynamicTokenType, big.NewInt(int64(numOfDecimals)).Bytes()}, + } + e.eei.Finish(tokenIdentifier) + e.eei.AddLogEntry(logEntry) + + return tokenIdentifier, token, vmcommon.Ok +} + +func (e *esdt) registerDynamic(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { + _, _, returnCode := e.createDynamicToken(args) + return returnCode +} + +func (e *esdt) registerAndSetAllRolesDynamic(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { + tokenIdentifier, token, returnCode := e.createDynamicToken(args) + if returnCode != vmcommon.Ok { + return returnCode + } + + allRoles, err := e.getAllRolesForTokenType(string(token.TokenType)) + if err != nil { + e.eei.AddReturnMessage(err.Error()) + return vmcommon.UserError + } + + properties, returnCode := e.setRolesForTokenAndAddress(token, args.CallerAddr, allRoles) + if returnCode != vmcommon.Ok { + return returnCode + } + + returnCode = e.prepareAndSendRoleChangeData(tokenIdentifier, args.CallerAddr, allRoles, properties) + if returnCode != vmcommon.Ok { + return returnCode + } + + err = e.saveToken(tokenIdentifier, token) + if err != nil { + e.eei.AddReturnMessage(err.Error()) + return vmcommon.UserError + } + + return vmcommon.Ok +} + func (e *esdt) sendTokenTypeToSystemAccounts(caller []byte, tokenID []byte, token *ESDTDataV2) { if !e.enableEpochsHandler.DynamicESDTEnabled() { return From 6447aabe7d3105a8c12faadea1bda72480f9bc10 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Fri, 3 Nov 2023 10:32:13 +0200 Subject: [PATCH 021/503] implementation of new roles and dynamic NFTs --- vm/errors.go | 6 +-- vm/systemSmartContracts/esdt.go | 76 +++++++++++++++++++++++++++++++-- 2 files changed, 76 insertions(+), 6 deletions(-) diff --git a/vm/errors.go b/vm/errors.go index 341c26e49ad..4a3cae31b04 100644 --- a/vm/errors.go +++ b/vm/errors.go @@ -31,9 +31,6 @@ var ErrInputCallerAddrIsNil = errors.New("input called address for system smart // ErrInputRecipientAddrIsNil signals that input recipient address for system smart contract is nil var ErrInputRecipientAddrIsNil = errors.New("input recipient address for system smart contract is nil") -// ErrInputAsyncParamsMissing signals that input does not contain async params -var ErrInputAsyncParamsMissing = errors.New("input does not contain async params") - // ErrNilBlockchainHook signals that blockchain hook is nil var ErrNilBlockchainHook = errors.New("blockchain hook is nil") @@ -267,3 +264,6 @@ var ErrWrongNewOwnerAddress = errors.New("wrong new owner address") // ErrInternalErrorWhileSettingNewOwner signals that an error occurred when setting the new contract owner var ErrInternalErrorWhileSettingNewOwner = errors.New("internal error when setting new contract owner") + +// ErrCannotChangeToDynamic signals that tokenID cannot be change to type dynamic +var ErrCannotChangeToDynamic = errors.New("cannot change to dynamic because of duplicated roles") diff --git a/vm/systemSmartContracts/esdt.go b/vm/systemSmartContracts/esdt.go index 1b561cf1858..a85c34c8f7b 100644 --- a/vm/systemSmartContracts/esdt.go +++ b/vm/systemSmartContracts/esdt.go @@ -216,6 +216,8 @@ func (e *esdt) Execute(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { return e.registerDynamic(args) case "registerAndSetAllRolesDynamic": return e.registerAndSetAllRolesDynamic(args) + case "changeToDynamic": + return e.changeToDynamic(args) } e.eei.AddReturnMessage("invalid method to call") @@ -1756,6 +1758,11 @@ func isDynamicTokenType(tokenType []byte) bool { return bytes.Equal(tokenType[:prefixLength], []byte(dynamic)) } +func rolesForDynamicWhichHasToBeSingular() []string { + return []string{core.ESDTRoleNFTCreate, core.ESDTRoleNFTUpdateAttributes, core.ESDTRoleNFTAddURI, + ESDTRoleSetNewURI, ESDTRoleModifyCreator, ESDTRoleModifyRoyalties, ESDTRoleNFTRecreate} +} + func (e *esdt) checkRolesForDynamicTokens( token *ESDTDataV2, roles [][]byte, @@ -1764,9 +1771,7 @@ func (e *esdt) checkRolesForDynamicTokens( return vmcommon.Ok } - rolesWhichHasToBeSingular := []string{core.ESDTRoleNFTCreate, core.ESDTRoleNFTUpdateAttributes, core.ESDTRoleNFTAddURI, - ESDTRoleSetNewURI, ESDTRoleModifyCreator, ESDTRoleModifyRoyalties, ESDTRoleNFTRecreate} - + rolesWhichHasToBeSingular := rolesForDynamicWhichHasToBeSingular() for _, role := range rolesWhichHasToBeSingular { if checkIfDefinedRoleExistsInArgsAndToken(roles, token, []byte(role)) { e.eei.AddReturnMessage(role + " already exists") @@ -2324,6 +2329,71 @@ func (e *esdt) registerAndSetAllRolesDynamic(args *vmcommon.ContractCallInput) v return vmcommon.Ok } +func (e *esdt) checkRolesAreCompatibleToChangeToDynamic(token *ESDTDataV2) error { + mapOfRoles := make(map[string]uint32) + + for _, esdtRole := range token.SpecialRoles { + for _, role := range esdtRole.Roles { + mapOfRoles[string(role)]++ + } + } + + rolesWithHaveToBeSingular := rolesForDynamicWhichHasToBeSingular() + for _, role := range rolesWithHaveToBeSingular { + if mapOfRoles[role] > 1 { + return vm.ErrCannotChangeToDynamic + } + } + + return nil +} + +func (e *esdt) changeToDynamic(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { + if !e.enableEpochsHandler.DynamicESDTEnabled() { + e.eei.AddReturnMessage("invalid method to call") + return vmcommon.UserError + } + + token, returnCode := e.basicOwnershipChecks(args) + if returnCode != vmcommon.Ok { + return returnCode + } + + if bytes.Equal(token.TokenType, []byte(core.FungibleESDT)) { + e.eei.AddReturnMessage("cannot change fungible tokens to dynamic") + return vmcommon.UserError + } + if isDynamicTokenType(token.TokenType) { + e.eei.AddReturnMessage("tokenID is already dynamic") + return vmcommon.UserError + } + + err := e.checkRolesAreCompatibleToChangeToDynamic(token) + if err != nil { + e.eei.AddReturnMessage(err.Error()) + return vmcommon.UserError + } + + token.TokenType = append([]byte(dynamic), token.TokenType...) + + err = e.saveToken(args.Arguments[0], token) + if err != nil { + e.eei.AddReturnMessage(err.Error()) + return vmcommon.UserError + } + + logEntry := &vmcommon.LogEntry{ + Identifier: []byte(args.Function), + Address: args.CallerAddr, + Topics: [][]byte{args.Arguments[0], token.TokenName, token.TickerName, token.TokenType}, + } + e.eei.AddLogEntry(logEntry) + + e.sendTokenTypeToSystemAccounts(args.CallerAddr, args.Arguments[0], token) + + return vmcommon.Ok +} + func (e *esdt) sendTokenTypeToSystemAccounts(caller []byte, tokenID []byte, token *ESDTDataV2) { if !e.enableEpochsHandler.DynamicESDTEnabled() { return From 08f62697a49cf9c77f45339ee66bd2b12cb6c5c6 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 7 Nov 2023 11:09:25 +0200 Subject: [PATCH 022/503] fixes after review. --- common/enablers/epochFlags.go | 2 +- vm/systemSmartContracts/esdt.go | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/common/enablers/epochFlags.go b/common/enablers/epochFlags.go index 7a7932c3aee..23482ea587e 100644 --- a/common/enablers/epochFlags.go +++ b/common/enablers/epochFlags.go @@ -760,7 +760,7 @@ func (holder *epochFlagsHolder) IsChangeOwnerAddressCrossShardThroughSCEnabled() return holder.changeOwnerAddressCrossShardThroughSCFlag.IsSet() } -// DynamicESDTEnabled return true if the dynamicESDTFlag is enabled +// DynamicESDTEnabled returns true if the dynamicESDTFlag is enabled func (holder *epochFlagsHolder) DynamicESDTEnabled() bool { return holder.dynamicESDTFlag.IsSet() } diff --git a/vm/systemSmartContracts/esdt.go b/vm/systemSmartContracts/esdt.go index a85c34c8f7b..c8e304cd75a 100644 --- a/vm/systemSmartContracts/esdt.go +++ b/vm/systemSmartContracts/esdt.go @@ -44,18 +44,28 @@ const upgradeProperties = "upgradeProperties" const conversionBase = 10 +// TODO move to core-go const metaESDT = "MetaESDT" const nonFungibleV2 = "NonFungibleESDTV2" -const ESDTSetTokenType = "ESDTSetTokenType" const dynamic = "dynamic" const dynamicNFT = dynamic + nonFungibleV2 const dynamicSFT = dynamic + core.SemiFungibleESDT const dynamicMetaESDT = dynamic + metaESDT +// ESDTSetTokenType represents the builtin function name to set token type +const ESDTSetTokenType = "ESDTSetTokenType" + +// ESDTRoleSetNewURI represents the role which can rewrite the URI in the token metadata const ESDTRoleSetNewURI = "ESDTRoleSetNewURI" + +// ESDTRoleModifyRoyalties represents the role which can rewrite the royalties of a token const ESDTRoleModifyRoyalties = "ESDTRoleModifyRoyalties" + +// ESDTRoleModifyCreator represents the role which can rewrite the creator in the token metadata const ESDTRoleModifyCreator = "ESDTRoleModifyCreator" + +// ESDTRoleNFTRecreate represents the role which can recreate the token metadata const ESDTRoleNFTRecreate = "ESDTRoleNFTRecreate" type esdt struct { @@ -1659,8 +1669,7 @@ func (e *esdt) isSpecialRoleValidForDynamicSFT(argument string) error { return nil } - switch argument { - case core.ESDTRoleNFTAddQuantity: + if argument == core.ESDTRoleNFTAddQuantity { return nil } @@ -2341,7 +2350,7 @@ func (e *esdt) checkRolesAreCompatibleToChangeToDynamic(token *ESDTDataV2) error rolesWithHaveToBeSingular := rolesForDynamicWhichHasToBeSingular() for _, role := range rolesWithHaveToBeSingular { if mapOfRoles[role] > 1 { - return vm.ErrCannotChangeToDynamic + return fmt.Errorf("%w, role %s was found multiple times", vm.ErrCannotChangeToDynamic, role) } } From 368d2e160866883aa62dec2e90605800d996ddb8 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 9 Nov 2023 16:32:22 +0200 Subject: [PATCH 023/503] added multitude of unit tests --- vm/systemSmartContracts/esdt.go | 12 +- vm/systemSmartContracts/esdt_test.go | 282 +++++++++++++++++++++++++++ 2 files changed, 292 insertions(+), 2 deletions(-) diff --git a/vm/systemSmartContracts/esdt.go b/vm/systemSmartContracts/esdt.go index c8e304cd75a..2a6e34fa1a9 100644 --- a/vm/systemSmartContracts/esdt.go +++ b/vm/systemSmartContracts/esdt.go @@ -2237,13 +2237,16 @@ func (e *esdt) updateTokenID(args *vmcommon.ContractCallInput) vmcommon.ReturnCo } } + // TODO allow this to be called only once + e.sendTokenTypeToSystemAccounts(args.CallerAddr, args.Arguments[0], token) + return vmcommon.Ok } func (e *esdt) createDynamicToken(args *vmcommon.ContractCallInput) ([]byte, *ESDTDataV2, vmcommon.ReturnCode) { if !e.enableEpochsHandler.DynamicESDTEnabled() { e.eei.AddReturnMessage("invalid method to call") - return nil, nil, vmcommon.UserError + return nil, nil, vmcommon.FunctionNotFound } returnCode := e.checkBasicCreateArguments(args) if returnCode != vmcommon.Ok { @@ -2264,6 +2267,11 @@ func (e *esdt) createDynamicToken(args *vmcommon.ContractCallInput) ([]byte, *ES numOfDecimals := uint32(0) if isWithDecimals { propertiesStart++ + if len(args.Arguments) < propertiesStart { + e.eei.AddReturnMessage("not enough arguments") + return nil, nil, vmcommon.UserError + } + numOfDecimals = uint32(big.NewInt(0).SetBytes(args.Arguments[3]).Uint64()) if numOfDecimals < minNumberOfDecimals || numOfDecimals > maxNumberOfDecimals { e.eei.AddReturnMessage(fmt.Errorf("%w, minimum: %d, maximum: %d, provided: %d", @@ -2360,7 +2368,7 @@ func (e *esdt) checkRolesAreCompatibleToChangeToDynamic(token *ESDTDataV2) error func (e *esdt) changeToDynamic(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { if !e.enableEpochsHandler.DynamicESDTEnabled() { e.eei.AddReturnMessage("invalid method to call") - return vmcommon.UserError + return vmcommon.FunctionNotFound } token, returnCode := e.basicOwnershipChecks(args) diff --git a/vm/systemSmartContracts/esdt_test.go b/vm/systemSmartContracts/esdt_test.go index e9607afce0c..9c43acc35fd 100644 --- a/vm/systemSmartContracts/esdt_test.go +++ b/vm/systemSmartContracts/esdt_test.go @@ -4497,3 +4497,285 @@ func TestEsdt_UpdateTokenType(t *testing.T) { output = e.Execute(vmInput) assert.Equal(t, vmcommon.Ok, output) } + +func TestEsdt_ExecuteChangeToMultiShardCreate(t *testing.T) { + t.Parallel() + + args := createMockArgumentsForESDT() + eei := createDefaultEei() + args.Eei = eei + e, _ := NewESDTSmartContract(args) + + vmInput := getDefaultVmInputForFunc("changeToMultiShardCreate", nil) + + eei.returnMessage = "" + eei.gasRemaining = 9999 + output := e.Execute(vmInput) + assert.Equal(t, vmcommon.UserError, output) + assert.Equal(t, eei.returnMessage, "invalid number of arguments") + + vmInput.Arguments = [][]byte{[]byte("tokenName")} + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.UserError, output) + assert.True(t, strings.Contains(eei.returnMessage, "no ticker with given name")) + + esdtData := &ESDTDataV2{TokenType: []byte(core.NonFungibleESDT), OwnerAddress: vmInput.CallerAddr} + _ = e.saveToken(vmInput.Arguments[0], esdtData) + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.UserError, output) + assert.True(t, strings.Contains(eei.returnMessage, "cannot add special roles")) + + esdtData.CanAddSpecialRoles = true + esdtData.CanCreateMultiShard = true + _ = e.saveToken(vmInput.Arguments[0], esdtData) + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.UserError, output) + assert.True(t, strings.Contains(eei.returnMessage, "it is already multi shard create")) + + esdtData.CanCreateMultiShard = false + _ = e.saveToken(vmInput.Arguments[0], esdtData) + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.UserError, output) + assert.True(t, strings.Contains(eei.returnMessage, "element was not found")) + + esdtData.SpecialRoles = append(esdtData.SpecialRoles, &ESDTRoles{Address: vmInput.CallerAddr, Roles: [][]byte{[]byte(core.ESDTRoleNFTCreate)}}) + _ = e.saveToken(vmInput.Arguments[0], esdtData) + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.Ok, output) +} + +func TestEsdt_UpdateTokenID(t *testing.T) { + t.Parallel() + + args := createMockArgumentsForESDT() + eei := createDefaultEei() + args.Eei = eei + enableEpochsHandler, _ := args.EnableEpochsHandler.(*enableEpochsHandlerMock.EnableEpochsHandlerStub) + e, _ := NewESDTSmartContract(args) + + vmInput := getDefaultVmInputForFunc("updateTokenID", nil) + + enableEpochsHandler.DynamicESDTEnabledField = false + eei.returnMessage = "" + eei.gasRemaining = 9999 + output := e.Execute(vmInput) + assert.Equal(t, vmcommon.FunctionNotFound, output) + assert.Equal(t, eei.returnMessage, "invalid method to call") + + eei.returnMessage = "" + eei.gasRemaining = 9999 + enableEpochsHandler.DynamicESDTEnabledField = true + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.FunctionWrongSignature, output) + assert.Equal(t, eei.returnMessage, "invalid number of arguments, wanted 1") + + vmInput.Arguments = [][]byte{[]byte("tokenName")} + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.UserError, output) + assert.True(t, strings.Contains(eei.returnMessage, "no ticker with given name")) + + esdtData := &ESDTDataV2{TokenType: []byte(core.NonFungibleESDT), OwnerAddress: vmInput.CallerAddr} + _ = e.saveToken(vmInput.Arguments[0], esdtData) + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.Ok, output) + + esdtData, _ = e.getExistingToken(vmInput.Arguments[0]) + assert.Equal(t, esdtData.TokenType, []byte(nonFungibleV2)) +} + +func TestEsdt_RegisterDynamic(t *testing.T) { + t.Parallel() + + args := createMockArgumentsForESDT() + eei := createDefaultEei() + args.Eei = eei + enableEpochsHandler, _ := args.EnableEpochsHandler.(*enableEpochsHandlerMock.EnableEpochsHandlerStub) + e, _ := NewESDTSmartContract(args) + + vmInput := getDefaultVmInputForFunc("registerDynamic", nil) + + enableEpochsHandler.DynamicESDTEnabledField = false + eei.returnMessage = "" + eei.gasRemaining = 9999 + output := e.Execute(vmInput) + assert.Equal(t, vmcommon.FunctionNotFound, output) + assert.Equal(t, eei.returnMessage, "invalid method to call") + + eei.returnMessage = "" + eei.gasRemaining = 9999 + enableEpochsHandler.DynamicESDTEnabledField = true + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.UserError, output) + assert.Equal(t, eei.returnMessage, "not enough arguments") + + vmInput.Arguments = [][]byte{[]byte("tokenName")} + vmInput.CallValue = big.NewInt(0).Set(e.baseIssuingCost) + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.UserError, output) + assert.True(t, strings.Contains(eei.returnMessage, "not enough arguments")) + + vmInput.Arguments = [][]byte{[]byte("tokenName"), []byte("ABABAB"), []byte("WRONGTYPE")} + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.UserError, output) + assert.True(t, strings.Contains(eei.returnMessage, "invalid argument")) + + vmInput.Arguments = [][]byte{[]byte("tokenName"), []byte("ABABAB"), []byte("META")} + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.UserError, output) + assert.True(t, strings.Contains(eei.returnMessage, "not enough arguments")) + + decimals := big.NewInt(20) + vmInput.Arguments = [][]byte{[]byte("tokenName"), []byte("ABABAB"), []byte("META"), decimals.Bytes()} + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.UserError, output) + + decimals = big.NewInt(10) + vmInput.Arguments = [][]byte{[]byte("tokenName"), []byte("ABABAB"), []byte("META"), decimals.Bytes(), []byte("wrongextra")} + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.UserError, output) + + vmInput.Arguments = [][]byte{[]byte("tokenName"), []byte("ABABAB"), []byte("META"), decimals.Bytes()} + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.Ok, output) +} + +func TestEsdt_RegisterAndSetAllRolesDynamic(t *testing.T) { + t.Parallel() + + args := createMockArgumentsForESDT() + eei := createDefaultEei() + args.Eei = eei + enableEpochsHandler, _ := args.EnableEpochsHandler.(*enableEpochsHandlerMock.EnableEpochsHandlerStub) + e, _ := NewESDTSmartContract(args) + + vmInput := getDefaultVmInputForFunc("registerAndSetAllRolesDynamic", nil) + + enableEpochsHandler.DynamicESDTEnabledField = false + eei.returnMessage = "" + eei.gasRemaining = 9999 + output := e.Execute(vmInput) + assert.Equal(t, vmcommon.FunctionNotFound, output) + assert.Equal(t, eei.returnMessage, "invalid method to call") + + eei.returnMessage = "" + eei.gasRemaining = 9999 + enableEpochsHandler.DynamicESDTEnabledField = true + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.UserError, output) + assert.Equal(t, eei.returnMessage, "not enough arguments") + + vmInput.Arguments = [][]byte{[]byte("tokenName")} + vmInput.CallValue = big.NewInt(0).Set(e.baseIssuingCost) + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.UserError, output) + assert.True(t, strings.Contains(eei.returnMessage, "not enough arguments")) + + vmInput.Arguments = [][]byte{[]byte("tokenName"), []byte("ABABAB"), []byte("WRONGTYPE")} + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.UserError, output) + assert.True(t, strings.Contains(eei.returnMessage, "invalid argument")) + + vmInput.Arguments = [][]byte{[]byte("tokenName"), []byte("ABABAB"), []byte("META")} + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.UserError, output) + assert.True(t, strings.Contains(eei.returnMessage, "not enough arguments")) + + decimals := big.NewInt(20) + vmInput.Arguments = [][]byte{[]byte("tokenName"), []byte("ABABAB"), []byte("META"), decimals.Bytes()} + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.UserError, output) + + decimals = big.NewInt(10) + vmInput.Arguments = [][]byte{[]byte("tokenName"), []byte("ABABAB"), []byte("META"), decimals.Bytes(), []byte("wrongextra")} + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.UserError, output) + + vmInput.Arguments = [][]byte{[]byte("tokenName"), []byte("ABABAB"), []byte("META"), decimals.Bytes()} + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.Ok, output) +} + +func TestEsdt_ChangeToDynamic(t *testing.T) { + t.Parallel() + + args := createMockArgumentsForESDT() + eei := createDefaultEei() + args.Eei = eei + enableEpochsHandler, _ := args.EnableEpochsHandler.(*enableEpochsHandlerMock.EnableEpochsHandlerStub) + e, _ := NewESDTSmartContract(args) + + vmInput := getDefaultVmInputForFunc("changeToDynamic", nil) + + enableEpochsHandler.DynamicESDTEnabledField = false + eei.returnMessage = "" + eei.gasRemaining = 9999 + output := e.Execute(vmInput) + assert.Equal(t, vmcommon.FunctionNotFound, output) + assert.Equal(t, eei.returnMessage, "invalid method to call") + + eei.returnMessage = "" + eei.gasRemaining = 9999 + enableEpochsHandler.DynamicESDTEnabledField = true + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.UserError, output) + assert.Equal(t, eei.returnMessage, "not enough arguments") + + vmInput.Arguments = [][]byte{[]byte("tokenName")} + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.UserError, output) + assert.True(t, strings.Contains(eei.returnMessage, "no ticker with given name")) + + esdtData := &ESDTDataV2{TokenType: []byte(core.FungibleESDT), OwnerAddress: vmInput.CallerAddr} + _ = e.saveToken(vmInput.Arguments[0], esdtData) + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.UserError, output) + assert.True(t, strings.Contains(eei.returnMessage, "cannot change fungible tokens to dynamic")) + + esdtData.TokenType = []byte(dynamicMetaESDT) + _ = e.saveToken(vmInput.Arguments[0], esdtData) + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.UserError, output) + assert.True(t, strings.Contains(eei.returnMessage, "tokenID is already dynamic")) + + esdtData.TokenType = []byte(metaESDT) + esdtData.SpecialRoles = append(esdtData.SpecialRoles, &ESDTRoles{Address: vmInput.CallerAddr, Roles: [][]byte{[]byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleNFTUpdateAttributes)}}) + esdtData.SpecialRoles = append(esdtData.SpecialRoles, &ESDTRoles{Address: bytes.Repeat([]byte{2}, 32), Roles: [][]byte{[]byte(core.ESDTRoleNFTUpdateAttributes)}}) + + _ = e.saveToken(vmInput.Arguments[0], esdtData) + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.UserError, output) + fmt.Println(eei.returnMessage) + assert.True(t, strings.Contains(eei.returnMessage, vm.ErrCannotChangeToDynamic.Error())) + + esdtData.SpecialRoles[1] = &ESDTRoles{Address: bytes.Repeat([]byte{2}, 32), Roles: [][]byte{[]byte(ESDTRoleNFTRecreate)}} + _ = e.saveToken(vmInput.Arguments[0], esdtData) + eei.returnMessage = "" + output = e.Execute(vmInput) + assert.Equal(t, vmcommon.Ok, output) + + esdtData, _ = e.getExistingToken(vmInput.Arguments[0]) + assert.True(t, strings.Contains(string(esdtData.TokenType), dynamic)) +} From 04256d34f8805bbc665273d1cec93780147e23ed Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 9 Nov 2023 16:41:28 +0200 Subject: [PATCH 024/503] fixes after merge --- common/constants.go | 1 + common/enablers/enableEpochsHandler.go | 6 ++++++ vm/systemSmartContracts/esdt.go | 22 +++++++++++----------- vm/systemSmartContracts/esdt_test.go | 20 ++++++++++---------- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/common/constants.go b/common/constants.go index 2d41dd873b5..e35f3d79d72 100644 --- a/common/constants.go +++ b/common/constants.go @@ -994,5 +994,6 @@ const ( BalanceWaitingListsFlag core.EnableEpochFlag = "BalanceWaitingListsFlag" WaitingListFixFlag core.EnableEpochFlag = "WaitingListFixFlag" NFTStopCreateFlag core.EnableEpochFlag = "NFTStopCreateFlag" + DynamicESDTFlag core.EnableEpochFlag = "DynamicESDTFlag" // all new flags must be added to createAllFlagsMap method, as part of enableEpochsHandler allFlagsDefined ) diff --git a/common/enablers/enableEpochsHandler.go b/common/enablers/enableEpochsHandler.go index 234f1076f2c..9a2222f6816 100644 --- a/common/enablers/enableEpochsHandler.go +++ b/common/enablers/enableEpochsHandler.go @@ -683,6 +683,12 @@ func (handler *enableEpochsHandler) createAllFlagsMap() { }, activationEpoch: handler.enableEpochsConfig.NFTStopCreateEnableEpoch, }, + common.DynamicESDTFlag: { + isActiveInEpoch: func(epoch uint32) bool { + return epoch >= handler.enableEpochsConfig.NFTStopCreateEnableEpoch + }, + activationEpoch: handler.enableEpochsConfig.NFTStopCreateEnableEpoch, + }, } } diff --git a/vm/systemSmartContracts/esdt.go b/vm/systemSmartContracts/esdt.go index 9d8ee9e4ed4..eae5a796f81 100644 --- a/vm/systemSmartContracts/esdt.go +++ b/vm/systemSmartContracts/esdt.go @@ -378,7 +378,7 @@ func (e *esdt) registerNonFungible(args *vmcommon.ContractCallInput) vmcommon.Re } tokenType := []byte(core.NonFungibleESDT) - if e.enableEpochsHandler.DynamicESDTEnabled() { + if e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) { tokenType = []byte(nonFungibleV2) } @@ -575,7 +575,7 @@ func (e *esdt) getAllRolesForTokenType(tokenType string) ([][]byte, error) { switch tokenType { case core.NonFungibleESDT, nonFungibleV2, dynamicNFT: nftRoles := [][]byte{[]byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleNFTBurn), []byte(core.ESDTRoleNFTUpdateAttributes), []byte(core.ESDTRoleNFTAddURI)} - if e.enableEpochsHandler.DynamicESDTEnabled() { + if e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) { nftRoles = append(nftRoles, [][]byte{[]byte(ESDTRoleNFTRecreate), []byte(ESDTRoleModifyCreator), []byte(ESDTRoleModifyRoyalties), []byte(ESDTRoleSetNewURI)}...) } @@ -598,7 +598,7 @@ func (e *esdt) getTokenType(compressed []byte) (bool, []byte, error) { // TODO: might extract the compressed constants to core, alongside metaESDT switch string(compressed) { case "NFT": - if e.enableEpochsHandler.DynamicESDTEnabled() { + if e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) { return false, []byte(nonFungibleV2), nil } return false, []byte(core.NonFungibleESDT), nil @@ -1624,22 +1624,22 @@ func (e *esdt) isSpecialRoleValidForNonFungible(argument string) error { } return vm.ErrInvalidArgument case ESDTRoleSetNewURI: - if e.enableEpochsHandler.DynamicESDTEnabled() { + if e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) { return nil } return vm.ErrInvalidArgument case ESDTRoleModifyCreator: - if e.enableEpochsHandler.DynamicESDTEnabled() { + if e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) { return nil } return vm.ErrInvalidArgument case ESDTRoleModifyRoyalties: - if e.enableEpochsHandler.DynamicESDTEnabled() { + if e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) { return nil } return vm.ErrInvalidArgument case ESDTRoleNFTRecreate: - if e.enableEpochsHandler.DynamicESDTEnabled() { + if e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) { return nil } return vm.ErrInvalidArgument @@ -2224,7 +2224,7 @@ func (e *esdt) stopNFTCreateForever(args *vmcommon.ContractCallInput) vmcommon.R } func (e *esdt) updateTokenID(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { - if !e.enableEpochsHandler.DynamicESDTEnabled() { + if !e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) { e.eei.AddReturnMessage("invalid method to call") return vmcommon.FunctionNotFound } @@ -2254,7 +2254,7 @@ func (e *esdt) updateTokenID(args *vmcommon.ContractCallInput) vmcommon.ReturnCo } func (e *esdt) createDynamicToken(args *vmcommon.ContractCallInput) ([]byte, *ESDTDataV2, vmcommon.ReturnCode) { - if !e.enableEpochsHandler.DynamicESDTEnabled() { + if !e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) { e.eei.AddReturnMessage("invalid method to call") return nil, nil, vmcommon.FunctionNotFound } @@ -2376,7 +2376,7 @@ func (e *esdt) checkRolesAreCompatibleToChangeToDynamic(token *ESDTDataV2) error } func (e *esdt) changeToDynamic(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { - if !e.enableEpochsHandler.DynamicESDTEnabled() { + if !e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) { e.eei.AddReturnMessage("invalid method to call") return vmcommon.FunctionNotFound } @@ -2422,7 +2422,7 @@ func (e *esdt) changeToDynamic(args *vmcommon.ContractCallInput) vmcommon.Return } func (e *esdt) sendTokenTypeToSystemAccounts(caller []byte, tokenID []byte, token *ESDTDataV2) { - if !e.enableEpochsHandler.DynamicESDTEnabled() { + if !e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) { return } diff --git a/vm/systemSmartContracts/esdt_test.go b/vm/systemSmartContracts/esdt_test.go index 9edc8583df3..d5d3ef8ca7e 100644 --- a/vm/systemSmartContracts/esdt_test.go +++ b/vm/systemSmartContracts/esdt_test.go @@ -4497,12 +4497,12 @@ func TestEsdt_UpdateTokenType(t *testing.T) { vmInput = getDefaultVmInputForFunc("setSpecialRole", [][]byte{tokenName, owner, []byte(core.ESDTRoleNFTCreate)}) vmInput.CallerAddr = owner - enableEpochsHandler.IsNFTStopCreateEnabledField = true + enableEpochsHandler.AddActiveFlags(common.NFTStopCreateFlag) output = e.Execute(vmInput) assert.Equal(t, vmcommon.UserError, output) assert.True(t, strings.Contains(eei.returnMessage, "cannot add NFT create role as NFT creation was stopped")) - enableEpochsHandler.IsNFTStopCreateEnabledField = false + enableEpochsHandler.RemoveActiveFlags(common.NFTStopCreateFlag) eei.returnMessage = "" output = e.Execute(vmInput) assert.Equal(t, vmcommon.Ok, output) @@ -4570,7 +4570,7 @@ func TestEsdt_UpdateTokenID(t *testing.T) { vmInput := getDefaultVmInputForFunc("updateTokenID", nil) - enableEpochsHandler.DynamicESDTEnabledField = false + enableEpochsHandler.RemoveActiveFlags(common.DynamicESDTFlag) eei.returnMessage = "" eei.gasRemaining = 9999 output := e.Execute(vmInput) @@ -4579,7 +4579,7 @@ func TestEsdt_UpdateTokenID(t *testing.T) { eei.returnMessage = "" eei.gasRemaining = 9999 - enableEpochsHandler.DynamicESDTEnabledField = true + enableEpochsHandler.AddActiveFlags(common.DynamicESDTFlag) output = e.Execute(vmInput) assert.Equal(t, vmcommon.FunctionWrongSignature, output) assert.Equal(t, eei.returnMessage, "invalid number of arguments, wanted 1") @@ -4611,7 +4611,7 @@ func TestEsdt_RegisterDynamic(t *testing.T) { vmInput := getDefaultVmInputForFunc("registerDynamic", nil) - enableEpochsHandler.DynamicESDTEnabledField = false + enableEpochsHandler.RemoveActiveFlags(common.DynamicESDTFlag) eei.returnMessage = "" eei.gasRemaining = 9999 output := e.Execute(vmInput) @@ -4620,7 +4620,7 @@ func TestEsdt_RegisterDynamic(t *testing.T) { eei.returnMessage = "" eei.gasRemaining = 9999 - enableEpochsHandler.DynamicESDTEnabledField = true + enableEpochsHandler.AddActiveFlags(common.DynamicESDTFlag) output = e.Execute(vmInput) assert.Equal(t, vmcommon.UserError, output) assert.Equal(t, eei.returnMessage, "not enough arguments") @@ -4673,7 +4673,7 @@ func TestEsdt_RegisterAndSetAllRolesDynamic(t *testing.T) { vmInput := getDefaultVmInputForFunc("registerAndSetAllRolesDynamic", nil) - enableEpochsHandler.DynamicESDTEnabledField = false + enableEpochsHandler.RemoveActiveFlags(common.DynamicESDTFlag) eei.returnMessage = "" eei.gasRemaining = 9999 output := e.Execute(vmInput) @@ -4682,7 +4682,7 @@ func TestEsdt_RegisterAndSetAllRolesDynamic(t *testing.T) { eei.returnMessage = "" eei.gasRemaining = 9999 - enableEpochsHandler.DynamicESDTEnabledField = true + enableEpochsHandler.AddActiveFlags(common.DynamicESDTFlag) output = e.Execute(vmInput) assert.Equal(t, vmcommon.UserError, output) assert.Equal(t, eei.returnMessage, "not enough arguments") @@ -4735,7 +4735,7 @@ func TestEsdt_ChangeToDynamic(t *testing.T) { vmInput := getDefaultVmInputForFunc("changeToDynamic", nil) - enableEpochsHandler.DynamicESDTEnabledField = false + enableEpochsHandler.RemoveActiveFlags(common.DynamicESDTFlag) eei.returnMessage = "" eei.gasRemaining = 9999 output := e.Execute(vmInput) @@ -4744,7 +4744,7 @@ func TestEsdt_ChangeToDynamic(t *testing.T) { eei.returnMessage = "" eei.gasRemaining = 9999 - enableEpochsHandler.DynamicESDTEnabledField = true + enableEpochsHandler.AddActiveFlags(common.DynamicESDTFlag) output = e.Execute(vmInput) assert.Equal(t, vmcommon.UserError, output) assert.Equal(t, eei.returnMessage, "not enough arguments") From a938728d2109b2e768f8b41863b50ec1a2a0ae06 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Fri, 10 Nov 2023 12:13:05 +0200 Subject: [PATCH 025/503] fixes after review --- vm/systemSmartContracts/esdt.go | 1 + 1 file changed, 1 insertion(+) diff --git a/vm/systemSmartContracts/esdt.go b/vm/systemSmartContracts/esdt.go index eae5a796f81..a558ce1f9d2 100644 --- a/vm/systemSmartContracts/esdt.go +++ b/vm/systemSmartContracts/esdt.go @@ -123,6 +123,7 @@ func NewESDTSmartContract(args ArgsNewESDTSmartContract) (*esdt, error) { common.MetaESDTSetFlag, common.ESDTNFTCreateOnMultiShardFlag, common.NFTStopCreateFlag, + common.DynamicESDTFlag, }) if err != nil { return nil, err From 21fd96a453d2062076919bdd427dac6d24699a38 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 13 Nov 2023 10:19:06 +0200 Subject: [PATCH 026/503] fixes after review --- integrationTests/vm/txsFee/guardAccount_test.go | 4 ++-- .../vm/txsFee/relayedBuiltInFunctions_test.go | 12 ++++++------ integrationTests/vm/txsFee/relayedESDT_test.go | 4 ++-- integrationTests/vm/txsFee/relayedScCalls_test.go | 12 ++++++------ 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/integrationTests/vm/txsFee/guardAccount_test.go b/integrationTests/vm/txsFee/guardAccount_test.go index edce650481f..2334d8899cb 100644 --- a/integrationTests/vm/txsFee/guardAccount_test.go +++ b/integrationTests/vm/txsFee/guardAccount_test.go @@ -1001,7 +1001,7 @@ func TestGuardAccounts_RelayedTransactionV1(t *testing.T) { alice, david, gasPrice, - 1, + minGasLimit, make([]byte, 0)) userTx.Version = txWithOptionVersion @@ -1125,7 +1125,7 @@ func TestGuardAccounts_RelayedTransactionV2(t *testing.T) { alice, david, gasPrice, - 1, + minGasLimit, make([]byte, 0)) userTx.Version = txWithOptionVersion diff --git a/integrationTests/vm/txsFee/relayedBuiltInFunctions_test.go b/integrationTests/vm/txsFee/relayedBuiltInFunctions_test.go index e590dbde879..5232d1d7ecf 100644 --- a/integrationTests/vm/txsFee/relayedBuiltInFunctions_test.go +++ b/integrationTests/vm/txsFee/relayedBuiltInFunctions_test.go @@ -48,7 +48,7 @@ func testRelayedBuildInFunctionChangeOwnerCallShouldWork(relayedFixActivationEpo _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(30000)) rtxData := integrationTests.PrepareRelayedTxDataV1(innerTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rTxGasLimit := minGasLimit + gasLimit + uint64(len(rtxData)) rtx := vm.CreateTransaction(0, innerTx.Value, relayerAddr, owner, gasPrice, rTxGasLimit, rtxData) retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) @@ -103,7 +103,7 @@ func testRelayedBuildInFunctionChangeOwnerCallWrongOwnerShouldConsumeGas(relayed _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(30000)) rtxData := integrationTests.PrepareRelayedTxDataV1(innerTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rTxGasLimit := minGasLimit + gasLimit + uint64(len(rtxData)) rtx := vm.CreateTransaction(0, innerTx.Value, relayerAddr, owner, gasPrice, rTxGasLimit, rtxData) retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) @@ -149,7 +149,7 @@ func TestRelayedBuildInFunctionChangeOwnerInvalidAddressShouldConsumeGas(t *test _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(30000)) rtxData := integrationTests.PrepareRelayedTxDataV1(innerTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rTxGasLimit := minGasLimit + gasLimit + uint64(len(rtxData)) rtx := vm.CreateTransaction(0, innerTx.Value, relayerAddr, owner, gasPrice, rTxGasLimit, rtxData) retCode, _ := testContext.TxProcessor.ProcessTransaction(rtx) @@ -213,7 +213,7 @@ func testRelayedBuildInFunctionChangeOwnerCallInsufficientGasLimitShouldConsumeG _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(30000)) rtxData := integrationTests.PrepareRelayedTxDataV1(innerTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rTxGasLimit := minGasLimit + gasLimit + uint64(len(rtxData)) rtx := vm.CreateTransaction(0, innerTx.Value, relayerAddr, owner, gasPrice, rTxGasLimit, rtxData) retCode, _ := testContext.TxProcessor.ProcessTransaction(rtx) @@ -251,13 +251,13 @@ func TestRelayedBuildInFunctionChangeOwnerCallOutOfGasShouldConsumeGas(t *testin newOwner := []byte("12345678901234567890123456789112") txData := []byte(core.BuiltInFunctionChangeOwnerAddress + "@" + hex.EncodeToString(newOwner)) - gasLimit := uint64(len(txData) + 1) + gasLimit := uint64(len(txData)) + minGasLimit innerTx := vm.CreateTransaction(1, big.NewInt(0), owner, scAddress, gasPrice, gasLimit, txData) _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(30000)) rtxData := integrationTests.PrepareRelayedTxDataV1(innerTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rTxGasLimit := minGasLimit + gasLimit + uint64(len(rtxData)) rtx := vm.CreateTransaction(0, innerTx.Value, relayerAddr, owner, gasPrice, rTxGasLimit, rtxData) retCode, _ := testContext.TxProcessor.ProcessTransaction(rtx) diff --git a/integrationTests/vm/txsFee/relayedESDT_test.go b/integrationTests/vm/txsFee/relayedESDT_test.go index 7f6354223d0..c9774550788 100644 --- a/integrationTests/vm/txsFee/relayedESDT_test.go +++ b/integrationTests/vm/txsFee/relayedESDT_test.go @@ -43,7 +43,7 @@ func testRelayedESDTTransferShouldWork(relayedFixActivationEpoch uint32) func(t innerTx := utils.CreateESDTTransferTx(0, sndAddr, rcvAddr, token, big.NewInt(100), gasPrice, gasLimit) rtxData := integrationTests.PrepareRelayedTxDataV1(innerTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rTxGasLimit := minGasLimit + gasLimit + uint64(len(rtxData)) rtx := vm.CreateTransaction(0, innerTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) @@ -97,7 +97,7 @@ func testRelayedESTTransferNotEnoughESTValueShouldConsumeGas(relayedFixActivatio innerTx := utils.CreateESDTTransferTx(0, sndAddr, rcvAddr, token, big.NewInt(100000001), gasPrice, gasLimit) rtxData := integrationTests.PrepareRelayedTxDataV1(innerTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rTxGasLimit := minGasLimit + gasLimit + uint64(len(rtxData)) rtx := vm.CreateTransaction(0, innerTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) diff --git a/integrationTests/vm/txsFee/relayedScCalls_test.go b/integrationTests/vm/txsFee/relayedScCalls_test.go index c67ff0e84c7..73c11e462af 100644 --- a/integrationTests/vm/txsFee/relayedScCalls_test.go +++ b/integrationTests/vm/txsFee/relayedScCalls_test.go @@ -45,7 +45,7 @@ func testRelayedScCallShouldWork(relayedFixActivationEpoch uint32) func(t *testi userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, scAddress, gasPrice, gasLimit, []byte("increment")) rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rTxGasLimit := minGasLimit + gasLimit + uint64(len(rtxData)) rtx := vm.CreateTransaction(0, userTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) @@ -96,7 +96,7 @@ func testRelayedScCallContractNotFoundShouldConsumeGas(relayedFixActivationEpoch userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, scAddrBytes, gasPrice, gasLimit, []byte("increment")) rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rTxGasLimit := minGasLimit + gasLimit + uint64(len(rtxData)) rtx := vm.CreateTransaction(0, userTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) @@ -144,7 +144,7 @@ func testRelayedScCallInvalidMethodShouldConsumeGas(relayedFixActivationEpoch ui userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, scAddress, gasPrice, gasLimit, []byte("invalidMethod")) rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rTxGasLimit := minGasLimit + gasLimit + uint64(len(rtxData)) rtx := vm.CreateTransaction(0, userTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) @@ -192,7 +192,7 @@ func testRelayedScCallInsufficientGasLimitShouldConsumeGas(relayedFixActivationE userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, scAddress, gasPrice, gasLimit, []byte("increment")) rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rTxGasLimit := minGasLimit + gasLimit + uint64(len(rtxData)) rtx := vm.CreateTransaction(0, userTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) retCode, _ := testContext.TxProcessor.ProcessTransaction(rtx) @@ -238,7 +238,7 @@ func testRelayedScCallOutOfGasShouldConsumeGas(relayedFixActivationEpoch uint32) userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, scAddress, gasPrice, gasLimit, []byte("increment")) rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rTxGasLimit := minGasLimit + gasLimit + uint64(len(rtxData)) rtx := vm.CreateTransaction(0, userTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) @@ -317,7 +317,7 @@ func testRelayedDeployInvalidContractShouldIncrementNonceOnSender( userTx := vm.CreateTransaction(senderNonce, big.NewInt(100), senderAddr, emptyAddress, gasPrice, gasLimit, nil) rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) - rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) + rTxGasLimit := minGasLimit + gasLimit + uint64(len(rtxData)) rtx := vm.CreateTransaction(0, userTx.Value, relayerAddr, senderAddr, gasPrice, rTxGasLimit, rtxData) retCode, err := testContext.TxProcessor.ProcessTransaction(rtx) From 7508eb9a1afac1982369cc1fd8b050e959d14186 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 27 Nov 2023 16:20:00 +0200 Subject: [PATCH 027/503] fixes after merge --- api/groups/transactionGroup.go | 6 +- common/constants.go | 2 + common/enablers/enableEpochsHandler.go | 12 + common/enablers/enableEpochsHandler_test.go | 8 +- go.mod | 2 +- go.sum | 4 +- .../multiShard/relayedTx/relayedTx_test.go | 2 +- process/transaction/baseProcess.go | 2 +- process/transaction/interceptedTransaction.go | 2 +- .../interceptedTransaction_test.go | 5 +- process/transaction/shardProcess.go | 12 +- process/transaction/shardProcess_test.go | 205 +++++++----------- 12 files changed, 120 insertions(+), 142 deletions(-) diff --git a/api/groups/transactionGroup.go b/api/groups/transactionGroup.go index 4d893d76c3f..c33a730a21f 100644 --- a/api/groups/transactionGroup.go +++ b/api/groups/transactionGroup.go @@ -284,7 +284,7 @@ func (tg *transactionGroup) sendTransaction(c *gin.Context) { } } - tx, txHash, err := tg.createTransaction(>x, innerTx) + tx, txHash, err := tg.createTransaction(&ftx, innerTx) if err != nil { c.JSON( http.StatusBadRequest, @@ -362,7 +362,7 @@ func (tg *transactionGroup) sendMultipleTransactions(c *gin.Context) { var start time.Time txsHashes := make(map[int]string) - for idx, receivedTx := range ftx { + for idx, receivedTx := range ftxs { var innerTx *transaction.Transaction if receivedTx.InnerTransaction != nil { innerTx, _, err = tg.createTransaction(receivedTx.InnerTransaction, nil) @@ -716,7 +716,7 @@ func (tg *transactionGroup) getTransactionsPoolNonceGapsForSender(sender string, ) } -func (tg *transactionGroup) createTransaction(receivedTx *transaction.Transaction, innerTx *transaction.Transaction) (*transaction.Transaction, []byte, error) { +func (tg *transactionGroup) createTransaction(receivedTx *transaction.FrontendTransaction, innerTx *transaction.Transaction) (*transaction.Transaction, []byte, error) { txArgs := &external.ArgsCreateTransaction{ Nonce: receivedTx.Nonce, Value: receivedTx.Value, diff --git a/common/constants.go b/common/constants.go index 5466698c2f0..0ee68b0ab0e 100644 --- a/common/constants.go +++ b/common/constants.go @@ -1002,5 +1002,7 @@ const ( NFTStopCreateFlag core.EnableEpochFlag = "NFTStopCreateFlag" FixGasRemainingForSaveKeyValueFlag core.EnableEpochFlag = "FixGasRemainingForSaveKeyValueFlag" IsChangeOwnerAddressCrossShardThroughSCFlag core.EnableEpochFlag = "IsChangeOwnerAddressCrossShardThroughSCFlag" + RelayedTransactionsV3Flag core.EnableEpochFlag = "RelayedTransactionsV3Flag" + FixRelayedMoveBalanceFlag core.EnableEpochFlag = "FixRelayedMoveBalanceFlag" // all new flags must be added to createAllFlagsMap method, as part of enableEpochsHandler allFlagsDefined ) diff --git a/common/enablers/enableEpochsHandler.go b/common/enablers/enableEpochsHandler.go index e5ab0f06100..34e295070d1 100644 --- a/common/enablers/enableEpochsHandler.go +++ b/common/enablers/enableEpochsHandler.go @@ -695,6 +695,18 @@ func (handler *enableEpochsHandler) createAllFlagsMap() { }, activationEpoch: handler.enableEpochsConfig.ChangeOwnerAddressCrossShardThroughSCEnableEpoch, }, + common.RelayedTransactionsV3Flag: { + isActiveInEpoch: func(epoch uint32) bool { + return epoch >= handler.enableEpochsConfig.RelayedTransactionsV3EnableEpoch + }, + activationEpoch: handler.enableEpochsConfig.RelayedTransactionsV3EnableEpoch, + }, + common.FixRelayedMoveBalanceFlag: { + isActiveInEpoch: func(epoch uint32) bool { + return epoch >= handler.enableEpochsConfig.FixRelayedMoveBalanceEnableEpoch + }, + activationEpoch: handler.enableEpochsConfig.FixRelayedMoveBalanceEnableEpoch, + }, } } diff --git a/common/enablers/enableEpochsHandler_test.go b/common/enablers/enableEpochsHandler_test.go index 5c73802dd06..70bf816a843 100644 --- a/common/enablers/enableEpochsHandler_test.go +++ b/common/enablers/enableEpochsHandler_test.go @@ -110,8 +110,8 @@ func createEnableEpochsConfig() config.EnableEpochs { NFTStopCreateEnableEpoch: 92, FixGasRemainingForSaveKeyValueBuiltinFunctionEnableEpoch: 93, ChangeOwnerAddressCrossShardThroughSCEnableEpoch: 94, - RelayedTransactionsV3EnableEpoch: 95, - FixRelayedMoveBalanceEnableEpoch: 96, + RelayedTransactionsV3EnableEpoch: 95, + FixRelayedMoveBalanceEnableEpoch: 96, } } @@ -299,6 +299,8 @@ func TestEnableEpochsHandler_IsFlagEnabled(t *testing.T) { require.True(t, handler.IsFlagEnabled(common.NFTStopCreateFlag)) require.True(t, handler.IsFlagEnabled(common.FixGasRemainingForSaveKeyValueFlag)) require.True(t, handler.IsFlagEnabled(common.IsChangeOwnerAddressCrossShardThroughSCFlag)) + require.True(t, handler.IsFlagEnabled(common.RelayedTransactionsV3Flag)) + require.True(t, handler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag)) } func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) { @@ -409,6 +411,8 @@ func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) { require.Equal(t, cfg.NFTStopCreateEnableEpoch, handler.GetActivationEpoch(common.NFTStopCreateFlag)) require.Equal(t, cfg.ChangeOwnerAddressCrossShardThroughSCEnableEpoch, handler.GetActivationEpoch(common.IsChangeOwnerAddressCrossShardThroughSCFlag)) require.Equal(t, cfg.FixGasRemainingForSaveKeyValueBuiltinFunctionEnableEpoch, handler.GetActivationEpoch(common.FixGasRemainingForSaveKeyValueFlag)) + require.Equal(t, cfg.RelayedTransactionsV3EnableEpoch, handler.GetActivationEpoch(common.RelayedTransactionsV3Flag)) + require.Equal(t, cfg.FixRelayedMoveBalanceEnableEpoch, handler.GetActivationEpoch(common.FixRelayedMoveBalanceFlag)) } func TestEnableEpochsHandler_IsInterfaceNil(t *testing.T) { diff --git a/go.mod b/go.mod index ac69da44db2..06a64a42c3c 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.13-0.20231123141403-12ed9f47ae5c - github.com/multiversx/mx-chain-core-go v1.2.19-0.20231123115253-158315dc4238 + github.com/multiversx/mx-chain-core-go v1.2.19-0.20231127124152-e81c07284cac github.com/multiversx/mx-chain-crypto-go v1.2.8 github.com/multiversx/mx-chain-es-indexer-go v1.4.13 github.com/multiversx/mx-chain-logger-go v1.0.13 diff --git a/go.sum b/go.sum index 4a4205eb4df..44597e8d142 100644 --- a/go.sum +++ b/go.sum @@ -386,8 +386,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20231123141403-12ed9f47ae5c h1:fejaUXnqi4/8a+6WKUUenCx5suDY20F1lORkkK9DlmA= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20231123141403-12ed9f47ae5c/go.mod h1:bluGVwF0rJU2ig+iKNiMnEunObDjMuxFsjOOxLUg9Qg= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20231123115253-158315dc4238 h1:nlDelmQou2635GW2YACZMAHTc+cRxBvtHE0dRQuVC0U= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20231123115253-158315dc4238/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84= +github.com/multiversx/mx-chain-core-go v1.2.19-0.20231127124152-e81c07284cac h1:k4gyvfXgqM0p+PVILzJyG8JSaU28HI0u0PiTq3u8pvo= +github.com/multiversx/mx-chain-core-go v1.2.19-0.20231127124152-e81c07284cac/go.mod h1:BILOGHUOIG5dNNX8cgkzCNfDaVtoYrJRYcPnpxRMH84= github.com/multiversx/mx-chain-crypto-go v1.2.8 h1:wOgVlUaO5X4L8iEbFjcQcL8SZvv6WZ7LqH73BiRPhxU= github.com/multiversx/mx-chain-crypto-go v1.2.8/go.mod h1:fkaWKp1rbQN9wPKya5jeoRyC+c/SyN/NfggreyeBw+8= github.com/multiversx/mx-chain-es-indexer-go v1.4.13 h1:3Ayaw9bSpeNOF+Z3L/11MN1rIJH8Rc6dqtt+o4Wfdno= diff --git a/integrationTests/multiShard/relayedTx/relayedTx_test.go b/integrationTests/multiShard/relayedTx/relayedTx_test.go index 3f58ce897a4..3d367ae7d72 100644 --- a/integrationTests/multiShard/relayedTx/relayedTx_test.go +++ b/integrationTests/multiShard/relayedTx/relayedTx_test.go @@ -323,7 +323,7 @@ func testRelayedTransactionInMultiShardEnvironmentWithAttestationContract( }() for _, node := range nodes { - node.EconomicsData.SetMaxGasLimitPerBlock(1500000000) + node.EconomicsData.SetMaxGasLimitPerBlock(1500000000, 0) } round := uint64(0) diff --git a/process/transaction/baseProcess.go b/process/transaction/baseProcess.go index ed75040a8c7..4280ae54941 100644 --- a/process/transaction/baseProcess.go +++ b/process/transaction/baseProcess.go @@ -145,7 +145,7 @@ func (txProc *baseTxProcessor) checkTxValues( if tx.GasLimit < txProc.economicsFee.ComputeGasLimit(tx) { return process.ErrNotEnoughGasInUserTx } - if txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() { + if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { txFee = txProc.economicsFee.ComputeTxFee(tx) } else { txFee = txProc.economicsFee.ComputeFeeForProcessing(tx, tx.GasLimit) diff --git a/process/transaction/interceptedTransaction.go b/process/transaction/interceptedTransaction.go index f824f2d917b..3ce45229ff9 100644 --- a/process/transaction/interceptedTransaction.go +++ b/process/transaction/interceptedTransaction.go @@ -231,7 +231,7 @@ func (inTx *InterceptedTransaction) verifyIfRelayedTxV3(tx *transaction.Transact if tx.InnerTransaction == nil { return nil } - if !inTx.enableEpochsHandler.IsRelayedTransactionsV3FlagEnabled() { + if !inTx.enableEpochsHandler.IsFlagEnabled(common.RelayedTransactionsV3Flag) { return process.ErrRelayedTxV3Disabled } diff --git a/process/transaction/interceptedTransaction_test.go b/process/transaction/interceptedTransaction_test.go index 225908578c3..b9233580a20 100644 --- a/process/transaction/interceptedTransaction_test.go +++ b/process/transaction/interceptedTransaction_test.go @@ -15,6 +15,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data" dataTransaction "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-crypto-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/interceptors" "github.com/multiversx/mx-chain-go/process/mock" @@ -203,9 +204,7 @@ func createInterceptedTxFromPlainTxWithArgParser(tx *dataTransaction.Transaction false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(tx.Version), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsRelayedTransactionsV3FlagEnabledField: true, - }, + enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV3Flag), ) } diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 99ab70baac1..4cebba235c1 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -388,7 +388,7 @@ func (txProc *txProcessor) processTxFee( if isUserTxOfRelayed { totalCost := txProc.economicsFee.ComputeFeeForProcessing(tx, tx.GasLimit) - if txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() { + if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { totalCost = txProc.economicsFee.ComputeTxFee(tx) } err := acntSnd.SubFromBalance(totalCost) @@ -633,7 +633,7 @@ func (txProc *txProcessor) processRelayedTxV3( tx *transaction.Transaction, relayerAcnt, acntDst state.UserAccountHandler, ) (vmcommon.ReturnCode, error) { - if !txProc.enableEpochsHandler.IsRelayedTransactionsV3FlagEnabled() { + if !txProc.enableEpochsHandler.IsFlagEnabled(common.RelayedTransactionsV3Flag) { return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedTxV3Disabled) } if tx.GetValue().Cmp(big.NewInt(0)) != 0 { @@ -731,7 +731,7 @@ func (txProc *txProcessor) processRelayedTx( func (txProc *txProcessor) computeRelayedTxFees(tx, userTx *transaction.Transaction) relayedFees { relayerFee := txProc.economicsFee.ComputeMoveBalanceFee(tx) totalFee := txProc.economicsFee.ComputeTxFee(tx) - if txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() { + if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { userFee := txProc.economicsFee.ComputeTxFee(userTx) totalFee = totalFee.Add(relayerFee, userFee) } @@ -766,7 +766,7 @@ func (txProc *txProcessor) removeValueAndConsumedFeeFromUser( } consumedFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, userTx.GasLimit) - if txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() { + if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { consumedFee = txProc.economicsFee.ComputeTxFee(userTx) } err = userAcnt.SubFromBalance(consumedFee) @@ -812,7 +812,7 @@ func (txProc *txProcessor) processMoveBalanceCostRelayedUserTx( ) error { moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(userTx) moveBalanceUserFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, moveBalanceGasLimit) - if txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() { + if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { moveBalanceUserFee = txProc.economicsFee.ComputeMoveBalanceFee(userTx) } @@ -1016,7 +1016,7 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( } totalFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, userTx.GasLimit) - if txProc.enableEpochsHandler.IsFixRelayedMoveBalanceFlagEnabled() { + if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { totalFee = txProc.economicsFee.ComputeTxFee(userTx) } diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index 196dd6736e6..23483c6bb69 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -74,24 +74,21 @@ func createAccountStub(sndAddr, rcvAddr []byte, func createArgsForTxProcessor() txproc.ArgsNewTxProcessor { args := txproc.ArgsNewTxProcessor{ - Accounts: &stateMock.AccountsStub{}, - Hasher: &hashingMocks.HasherMock{}, - PubkeyConv: createMockPubKeyConverter(), - Marshalizer: &mock.MarshalizerMock{}, - SignMarshalizer: &mock.MarshalizerMock{}, - ShardCoordinator: mock.NewOneShardCoordinatorMock(), - ScProcessor: &testscommon.SCProcessorMock{}, - TxFeeHandler: &mock.FeeAccumulatorStub{}, - TxTypeHandler: &testscommon.TxTypeHandlerMock{}, - EconomicsFee: feeHandlerMock(), - ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, - BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, - ArgsParser: &mock.ArgumentParserMock{}, - ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, - EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsPenalizedTooMuchGasFlagEnabledField: true, - IsFixRelayedMoveBalanceFlagEnabledField: true, - }, + Accounts: &stateMock.AccountsStub{}, + Hasher: &hashingMocks.HasherMock{}, + PubkeyConv: createMockPubKeyConverter(), + Marshalizer: &mock.MarshalizerMock{}, + SignMarshalizer: &mock.MarshalizerMock{}, + ShardCoordinator: mock.NewOneShardCoordinatorMock(), + ScProcessor: &testscommon.SCProcessorMock{}, + TxFeeHandler: &mock.FeeAccumulatorStub{}, + TxTypeHandler: &testscommon.TxTypeHandlerMock{}, + EconomicsFee: feeHandlerMock(), + ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, + BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, + ArgsParser: &mock.ArgumentParserMock{}, + ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.PenalizedTooMuchGasFlag, common.FixRelayedMoveBalanceFlag), GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, TxVersionChecker: &testscommon.TxVersionCheckerStub{}, TxLogsProcessor: &mock.TxLogsProcessorStub{}, @@ -1281,14 +1278,12 @@ func TestTxProcessor_ProcessTransactionScTxShouldNotBeCalledWhenAdrDstIsNotInNod esdtTransferParser, _ := parsers.NewESDTTransferParser(&mock.MarshalizerMock{}) argsTxTypeHandler := coordinator.ArgNewTxTypeHandler{ - PubkeyConverter: testscommon.NewPubkeyConverterMock(32), - ShardCoordinator: shardCoordinator, - BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), - ArgumentParser: parsers.NewCallArgsParser(), - ESDTTransferParser: esdtTransferParser, - EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsESDTMetadataContinuousCleanupFlagEnabledField: true, - }, + PubkeyConverter: testscommon.NewPubkeyConverterMock(32), + ShardCoordinator: shardCoordinator, + BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), + ArgumentParser: parsers.NewCallArgsParser(), + ESDTTransferParser: esdtTransferParser, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.ESDTMetadataContinuousCleanupFlag), } computeType, _ := coordinator.NewTxTypeHandler(argsTxTypeHandler) @@ -1484,9 +1479,7 @@ func TestTxProcessor_ProcessTxFeeSCInvokeUserTx(t *testing.T) { negMoveBalanceFee := big.NewInt(0).Neg(moveBalanceFee) gasPerByte := uint64(1) args := createArgsForTxProcessor() - args.EnableEpochsHandler = &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsPenalizedTooMuchGasFlagEnabledField: true, - } + args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.PenalizedTooMuchGasFlag) args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { return moveBalanceFee @@ -1560,9 +1553,7 @@ func TestTxProcessor_ProcessTransactionShouldReturnErrForInvalidMetaTx(t *testin return process.MoveBalance, process.MoveBalance }, } - args.EnableEpochsHandler = &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsMetaProtectionFlagEnabledField: true, - } + args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.MetaProtectionFlag) execTx, _ := txproc.NewTxProcessor(args) _, err := execTx.ProcessTransaction(&tx) @@ -1675,14 +1666,12 @@ func TestTxProcessor_ProcessRelayedTransactionV2NotActiveShouldErr(t *testing.T) esdtTransferParser, _ := parsers.NewESDTTransferParser(&mock.MarshalizerMock{}) argTxTypeHandler := coordinator.ArgNewTxTypeHandler{ - PubkeyConverter: pubKeyConverter, - ShardCoordinator: shardC, - BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), - ArgumentParser: parsers.NewCallArgsParser(), - ESDTTransferParser: esdtTransferParser, - EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsESDTMetadataContinuousCleanupFlagEnabledField: true, - }, + PubkeyConverter: pubKeyConverter, + ShardCoordinator: shardC, + BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), + ArgumentParser: parsers.NewCallArgsParser(), + ESDTTransferParser: esdtTransferParser, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.ESDTMetadataContinuousCleanupFlag), } txTypeHandler, _ := coordinator.NewTxTypeHandler(argTxTypeHandler) @@ -1757,14 +1746,12 @@ func TestTxProcessor_ProcessRelayedTransactionV2WithValueShouldErr(t *testing.T) esdtTransferParser, _ := parsers.NewESDTTransferParser(&mock.MarshalizerMock{}) argTxTypeHandler := coordinator.ArgNewTxTypeHandler{ - PubkeyConverter: pubKeyConverter, - ShardCoordinator: shardC, - BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), - ArgumentParser: parsers.NewCallArgsParser(), - ESDTTransferParser: esdtTransferParser, - EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsESDTMetadataContinuousCleanupFlagEnabledField: true, - }, + PubkeyConverter: pubKeyConverter, + ShardCoordinator: shardC, + BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), + ArgumentParser: parsers.NewCallArgsParser(), + ESDTTransferParser: esdtTransferParser, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.ESDTMetadataContinuousCleanupFlag), } txTypeHandler, _ := coordinator.NewTxTypeHandler(argTxTypeHandler) @@ -1839,14 +1826,12 @@ func TestTxProcessor_ProcessRelayedTransactionV2ArgsParserShouldErr(t *testing.T esdtTransferParser, _ := parsers.NewESDTTransferParser(&mock.MarshalizerMock{}) argTxTypeHandler := coordinator.ArgNewTxTypeHandler{ - PubkeyConverter: pubKeyConverter, - ShardCoordinator: shardC, - BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), - ArgumentParser: parsers.NewCallArgsParser(), - ESDTTransferParser: esdtTransferParser, - EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsESDTMetadataContinuousCleanupFlagEnabledField: true, - }, + PubkeyConverter: pubKeyConverter, + ShardCoordinator: shardC, + BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), + ArgumentParser: parsers.NewCallArgsParser(), + ESDTTransferParser: esdtTransferParser, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.ESDTMetadataContinuousCleanupFlag), } txTypeHandler, _ := coordinator.NewTxTypeHandler(argTxTypeHandler) @@ -1928,14 +1913,12 @@ func TestTxProcessor_ProcessRelayedTransactionV2InvalidParamCountShouldErr(t *te esdtTransferParser, _ := parsers.NewESDTTransferParser(&mock.MarshalizerMock{}) argTxTypeHandler := coordinator.ArgNewTxTypeHandler{ - PubkeyConverter: pubKeyConverter, - ShardCoordinator: shardC, - BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), - ArgumentParser: parsers.NewCallArgsParser(), - ESDTTransferParser: esdtTransferParser, - EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsESDTMetadataContinuousCleanupFlagEnabledField: true, - }, + PubkeyConverter: pubKeyConverter, + ShardCoordinator: shardC, + BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), + ArgumentParser: parsers.NewCallArgsParser(), + ESDTTransferParser: esdtTransferParser, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.ESDTMetadataContinuousCleanupFlag), } txTypeHandler, _ := coordinator.NewTxTypeHandler(argTxTypeHandler) @@ -2010,14 +1993,12 @@ func TestTxProcessor_ProcessRelayedTransactionV2(t *testing.T) { esdtTransferParser, _ := parsers.NewESDTTransferParser(&mock.MarshalizerMock{}) argTxTypeHandler := coordinator.ArgNewTxTypeHandler{ - PubkeyConverter: pubKeyConverter, - ShardCoordinator: shardC, - BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), - ArgumentParser: parsers.NewCallArgsParser(), - ESDTTransferParser: esdtTransferParser, - EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsESDTMetadataContinuousCleanupFlagEnabledField: true, - }, + PubkeyConverter: pubKeyConverter, + ShardCoordinator: shardC, + BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), + ArgumentParser: parsers.NewCallArgsParser(), + ESDTTransferParser: esdtTransferParser, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.ESDTMetadataContinuousCleanupFlag), } txTypeHandler, _ := coordinator.NewTxTypeHandler(argTxTypeHandler) @@ -2028,9 +2009,7 @@ func TestTxProcessor_ProcessRelayedTransactionV2(t *testing.T) { args.TxTypeHandler = txTypeHandler args.PubkeyConv = pubKeyConverter args.ArgsParser = smartContract.NewArgumentParser() - args.EnableEpochsHandler = &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsRelayedTransactionsV2FlagEnabledField: true, - } + args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV2Flag) execTx, _ := txproc.NewTxProcessor(args) returnCode, err := execTx.ProcessTransaction(&tx) @@ -2095,14 +2074,12 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { shardC, _ := sharding.NewMultiShardCoordinator(1, 0) esdtTransferParser, _ := parsers.NewESDTTransferParser(marshaller) argTxTypeHandler := coordinator.ArgNewTxTypeHandler{ - PubkeyConverter: pubKeyConverter, - ShardCoordinator: shardC, - BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), - ArgumentParser: parsers.NewCallArgsParser(), - ESDTTransferParser: esdtTransferParser, - EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsESDTMetadataContinuousCleanupFlagEnabledField: true, - }, + PubkeyConverter: pubKeyConverter, + ShardCoordinator: shardC, + BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), + ArgumentParser: parsers.NewCallArgsParser(), + ESDTTransferParser: esdtTransferParser, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.ESDTMetadataContinuousCleanupFlag), } txTypeHandler, _ := coordinator.NewTxTypeHandler(argTxTypeHandler) @@ -2209,14 +2186,12 @@ func testProcessRelayedTransactionV3( shardC, _ := sharding.NewMultiShardCoordinator(1, 0) esdtTransferParser, _ := parsers.NewESDTTransferParser(marshaller) argTxTypeHandler := coordinator.ArgNewTxTypeHandler{ - PubkeyConverter: pubKeyConverter, - ShardCoordinator: shardC, - BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), - ArgumentParser: parsers.NewCallArgsParser(), - ESDTTransferParser: esdtTransferParser, - EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsESDTMetadataContinuousCleanupFlagEnabledField: true, - }, + PubkeyConverter: pubKeyConverter, + ShardCoordinator: shardC, + BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), + ArgumentParser: parsers.NewCallArgsParser(), + ESDTTransferParser: esdtTransferParser, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.ESDTMetadataContinuousCleanupFlag), } txTypeHandler, _ := coordinator.NewTxTypeHandler(argTxTypeHandler) @@ -2227,9 +2202,7 @@ func testProcessRelayedTransactionV3( args.TxTypeHandler = txTypeHandler args.PubkeyConv = pubKeyConverter args.ArgsParser = smartContract.NewArgumentParser() - args.EnableEpochsHandler = &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsRelayedTransactionsV3FlagEnabledField: true, - } + args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV3Flag) args.EconomicsFee = &economicsmocks.EconomicsHandlerMock{ ComputeTxFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { return big.NewInt(4) @@ -2301,14 +2274,12 @@ func TestTxProcessor_ProcessRelayedTransaction(t *testing.T) { esdtTransferParser, _ := parsers.NewESDTTransferParser(&mock.MarshalizerMock{}) argTxTypeHandler := coordinator.ArgNewTxTypeHandler{ - PubkeyConverter: pubKeyConverter, - ShardCoordinator: shardC, - BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), - ArgumentParser: parsers.NewCallArgsParser(), - ESDTTransferParser: esdtTransferParser, - EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsESDTMetadataContinuousCleanupFlagEnabledField: true, - }, + PubkeyConverter: pubKeyConverter, + ShardCoordinator: shardC, + BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), + ArgumentParser: parsers.NewCallArgsParser(), + ESDTTransferParser: esdtTransferParser, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.ESDTMetadataContinuousCleanupFlag), } txTypeHandler, _ := coordinator.NewTxTypeHandler(argTxTypeHandler) @@ -2319,9 +2290,7 @@ func TestTxProcessor_ProcessRelayedTransaction(t *testing.T) { args.TxTypeHandler = txTypeHandler args.PubkeyConv = pubKeyConverter args.ArgsParser = smartContract.NewArgumentParser() - args.EnableEpochsHandler = &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsRelayedTransactionsFlagEnabledField: true, - } + args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsFlag) execTx, _ := txproc.NewTxProcessor(args) returnCode, err := execTx.ProcessTransaction(&tx) @@ -2834,14 +2803,12 @@ func TestTxProcessor_ProcessRelayedTransactionDisabled(t *testing.T) { esdtTransferParser, _ := parsers.NewESDTTransferParser(&mock.MarshalizerMock{}) argTxTypeHandler := coordinator.ArgNewTxTypeHandler{ - PubkeyConverter: pubKeyConverter, - ShardCoordinator: shardC, - BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), - ArgumentParser: parsers.NewCallArgsParser(), - ESDTTransferParser: esdtTransferParser, - EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsESDTMetadataContinuousCleanupFlagEnabledField: true, - }, + PubkeyConverter: pubKeyConverter, + ShardCoordinator: shardC, + BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), + ArgumentParser: parsers.NewCallArgsParser(), + ESDTTransferParser: esdtTransferParser, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.ESDTMetadataContinuousCleanupFlag), } txTypeHandler, _ := coordinator.NewTxTypeHandler(argTxTypeHandler) @@ -3454,18 +3421,14 @@ func TestTxProcessor_shouldIncreaseNonce(t *testing.T) { t.Run("fix not enabled, should return true", func(t *testing.T) { args := createArgsForTxProcessor() - args.EnableEpochsHandler = &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsRelayedNonceFixEnabledField: false, - } + args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedNonceFixFlag) txProc, _ := txproc.NewTxProcessor(args) assert.True(t, txProc.ShouldIncreaseNonce(nil)) }) t.Run("fix enabled, different errors should return true", func(t *testing.T) { args := createArgsForTxProcessor() - args.EnableEpochsHandler = &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsRelayedNonceFixEnabledField: true, - } + args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedNonceFixFlag) txProc, _ := txproc.NewTxProcessor(args) assert.True(t, txProc.ShouldIncreaseNonce(nil)) @@ -3474,9 +3437,7 @@ func TestTxProcessor_shouldIncreaseNonce(t *testing.T) { }) t.Run("fix enabled, errors for an un-executable transaction should return false", func(t *testing.T) { args := createArgsForTxProcessor() - args.EnableEpochsHandler = &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsRelayedNonceFixEnabledField: true, - } + args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedNonceFixFlag) txProc, _ := txproc.NewTxProcessor(args) assert.False(t, txProc.ShouldIncreaseNonce(process.ErrLowerNonceInTransaction)) From 8b59d06b717d5dfa609931f6ef4363eb5b6111f0 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 27 Nov 2023 16:41:45 +0200 Subject: [PATCH 028/503] more fixes after merge --- process/transaction/metaProcess.go | 3 ++- process/transaction/shardProcess.go | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/process/transaction/metaProcess.go b/process/transaction/metaProcess.go index 83274dda551..850e23409f1 100644 --- a/process/transaction/metaProcess.go +++ b/process/transaction/metaProcess.go @@ -67,6 +67,7 @@ func NewMetaTxProcessor(args ArgsNewMetaTxProcessor) (*metaTxProcessor, error) { common.PenalizedTooMuchGasFlag, common.BuiltInFunctionOnMetaFlag, common.ESDTFlag, + common.FixRelayedMoveBalanceFlag, }) if err != nil { return nil, err @@ -100,7 +101,7 @@ func NewMetaTxProcessor(args ArgsNewMetaTxProcessor) (*metaTxProcessor, error) { return txProc, nil } -// ProcessTransaction modifies the account states in respect with the transaction data +// ProcessTransaction modifies the account states in re`spect with the transaction data func (txProc *metaTxProcessor) ProcessTransaction(tx *transaction.Transaction) (vmcommon.ReturnCode, error) { if check.IfNil(tx) { return 0, process.ErrNilTransaction diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 4cebba235c1..da1ea63baf3 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -128,6 +128,8 @@ func NewTxProcessor(args ArgsNewTxProcessor) (*txProcessor, error) { common.RelayedTransactionsFlag, common.RelayedTransactionsV2Flag, common.RelayedNonceFixFlag, + common.RelayedTransactionsV3Flag, + common.FixRelayedMoveBalanceFlag, }) if err != nil { return nil, err From 5527e7b3b78c34f2daac8d106ca90a542bf025a8 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 27 Nov 2023 17:07:11 +0200 Subject: [PATCH 029/503] fix after review --- process/transaction/metaProcess.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/process/transaction/metaProcess.go b/process/transaction/metaProcess.go index 850e23409f1..f1ed14e97ce 100644 --- a/process/transaction/metaProcess.go +++ b/process/transaction/metaProcess.go @@ -101,7 +101,7 @@ func NewMetaTxProcessor(args ArgsNewMetaTxProcessor) (*metaTxProcessor, error) { return txProc, nil } -// ProcessTransaction modifies the account states in re`spect with the transaction data +// ProcessTransaction modifies the account states in respect with the transaction data func (txProc *metaTxProcessor) ProcessTransaction(tx *transaction.Transaction) (vmcommon.ReturnCode, error) { if check.IfNil(tx) { return 0, process.ErrNilTransaction From 0a781ee73e2ad0e845f3f316b9c2243cfae168f9 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 3 Jan 2024 21:38:56 +0200 Subject: [PATCH 030/503] use create with retries in persister factory --- dataRetriever/factory/dataPoolFactory.go | 2 +- epochStart/metachain/systemSCs_test.go | 2 +- go.mod | 2 +- go.sum | 6 ++++++ storage/factory/openStorage.go | 20 ++------------------ storage/factory/persisterFactory.go | 22 ++++++++++++++++++++++ storage/interface.go | 1 + storage/storageunit/storageunit.go | 8 -------- storage/storageunit/storageunit_test.go | 4 ++-- testscommon/dataRetriever/poolFactory.go | 2 +- 10 files changed, 37 insertions(+), 32 deletions(-) diff --git a/dataRetriever/factory/dataPoolFactory.go b/dataRetriever/factory/dataPoolFactory.go index 0033d14f686..82ac3416be2 100644 --- a/dataRetriever/factory/dataPoolFactory.go +++ b/dataRetriever/factory/dataPoolFactory.go @@ -194,7 +194,7 @@ func createTrieSyncDB(args ArgsDataPool) (storage.Persister, error) { path = filePath } - db, err := storageunit.NewDB(persisterFactory, path) + db, err := persisterFactory.CreateWithRetries(path) if err != nil { return nil, fmt.Errorf("%w while creating the db for the trie nodes", err) } diff --git a/epochStart/metachain/systemSCs_test.go b/epochStart/metachain/systemSCs_test.go index a519e77e7f7..bdf66c5694c 100644 --- a/epochStart/metachain/systemSCs_test.go +++ b/epochStart/metachain/systemSCs_test.go @@ -92,7 +92,7 @@ func createPhysicalUnit(t *testing.T) (storage.Storer, string) { assert.Nil(t, err) cache, _ := storageunit.NewCache(cacheConfig) - persist, _ := storageunit.NewDB(persisterFactory, dir) + persist, _ := persisterFactory.CreateWithRetries(dir) unit, _ := storageunit.NewStorageUnit(cache, persist) return unit, dir diff --git a/go.mod b/go.mod index 9f27d2e1ffd..9b6c7159b39 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/multiversx/mx-chain-es-indexer-go v1.4.18-0.20231228064619-e3b0caf29058 github.com/multiversx/mx-chain-logger-go v1.0.14-0.20231215125130-a3bed6e76040 github.com/multiversx/mx-chain-scenario-go v1.2.2-0.20231129113427-ad3056f45296 - github.com/multiversx/mx-chain-storage-go v1.0.15-0.20231213110622-e222ba96a9f4 + github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240103193554-5ad54212812d github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20231228070003-ae14e1e0adfa github.com/multiversx/mx-chain-vm-go v1.5.23-0.20231228064104-964359cb8dd3 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.65-0.20231228071026-eed2cb19c216 diff --git a/go.sum b/go.sum index 0375c025713..aebf8ac5ff3 100644 --- a/go.sum +++ b/go.sum @@ -128,6 +128,7 @@ 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= @@ -260,6 +261,7 @@ 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= @@ -267,6 +269,7 @@ 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= @@ -398,6 +401,8 @@ github.com/multiversx/mx-chain-scenario-go v1.2.2-0.20231129113427-ad3056f45296 github.com/multiversx/mx-chain-scenario-go v1.2.2-0.20231129113427-ad3056f45296/go.mod h1:WocyahfHCC3oGILEVdRe7I4/+q/TLCORoTo1X4wGmF4= github.com/multiversx/mx-chain-storage-go v1.0.15-0.20231213110622-e222ba96a9f4 h1:2RJ6T31pLN75l4xfhTicGZ+gVOPMxSGPip+O1XYVYac= github.com/multiversx/mx-chain-storage-go v1.0.15-0.20231213110622-e222ba96a9f4/go.mod h1:ioCT2oHQ+TyHQYpgjxzlUdy7dCdv56+w5HnBg9z96eY= +github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240103193554-5ad54212812d h1:mNf2qlDGSNp6yd4rSJBT93vGseuqraj8/jWWXm1ro+k= +github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240103193554-5ad54212812d/go.mod h1:ioCT2oHQ+TyHQYpgjxzlUdy7dCdv56+w5HnBg9z96eY= github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20231228070003-ae14e1e0adfa h1:xdDeUC4yOfiUwctkYioYMjjigBZoZo5RZq1e5WoCVRs= github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20231228070003-ae14e1e0adfa/go.mod h1:7jjGRykSfLeMs6iQdszlE0lGK2xp9/cctiVdeKbQLLM= github.com/multiversx/mx-chain-vm-go v1.5.23-0.20231228064104-964359cb8dd3 h1:qfzeTPI2oSgxnw52KiVWc2fHMem6FZIkX1Azwy64098= @@ -412,6 +417,7 @@ 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/storage/factory/openStorage.go b/storage/factory/openStorage.go index 80dae5bc39c..eacb57a8a79 100644 --- a/storage/factory/openStorage.go +++ b/storage/factory/openStorage.go @@ -3,7 +3,6 @@ package factory import ( "fmt" "path/filepath" - "time" "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-go/config" @@ -74,7 +73,7 @@ func (o *openStorageUnits) GetMostRecentStorageUnit(dbConfig config.DBConfig) (s persisterPath := o.getPersisterPath(pathWithoutShard, mostRecentShard, dbConfig) - persister, err := createDB(persisterFactory, persisterPath) + persister, err := persisterFactory.CreateWithRetries(persisterPath) if err != nil { return nil, err } @@ -118,7 +117,7 @@ func (o *openStorageUnits) OpenDB(dbConfig config.DBConfig, shardID uint32, epoc return nil, err } - persister, err := createDB(persisterFactory, persisterPath) + persister, err := persisterFactory.CreateWithRetries(persisterPath) if err != nil { return nil, err } @@ -131,21 +130,6 @@ func (o *openStorageUnits) OpenDB(dbConfig config.DBConfig, shardID uint32, epoc return storageunit.NewStorageUnit(lruCache, persister) } -func createDB(persisterFactory *PersisterFactory, persisterPath string) (storage.Persister, error) { - var persister storage.Persister - var err error - for i := 0; i < storage.MaxRetriesToCreateDB; i++ { - persister, err = persisterFactory.Create(persisterPath) - if err == nil { - return persister, nil - } - log.Warn("Create Persister failed", "path", persisterPath, "error", err) - //TODO: extract this in a parameter and inject it - time.Sleep(storage.SleepTimeBetweenCreateDBRetries) - } - return nil, err -} - func (o *openStorageUnits) getMostUpToDateDirectory( dbConfig config.DBConfig, pathWithoutShard string, diff --git a/storage/factory/persisterFactory.go b/storage/factory/persisterFactory.go index a1305ec2184..a657dc7a0d6 100644 --- a/storage/factory/persisterFactory.go +++ b/storage/factory/persisterFactory.go @@ -1,6 +1,8 @@ package factory import ( + "time" + "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/storage/disabled" @@ -22,6 +24,26 @@ func NewPersisterFactory(dbConfigHandler storage.DBConfigHandler) (*PersisterFac }, nil } +// CreateWithRetries will return a new instance of a DB with a given path +// It will try to create db multiple times +func (pf *PersisterFactory) CreateWithRetries(path string) (storage.Persister, error) { + var persister storage.Persister + var err error + + for i := 0; i < storage.MaxRetriesToCreateDB; i++ { + persister, err = pf.Create(path) + if err == nil { + return persister, nil + } + log.Warn("Create Persister failed", "path", path, "error", err) + + // TODO: extract this in a parameter and inject it + time.Sleep(storage.SleepTimeBetweenCreateDBRetries) + } + + return nil, err +} + // Create will return a new instance of a DB with a given path func (pf *PersisterFactory) Create(path string) (storage.Persister, error) { if len(path) == 0 { diff --git a/storage/interface.go b/storage/interface.go index 328eb86c4ed..5dd61cfad1d 100644 --- a/storage/interface.go +++ b/storage/interface.go @@ -211,6 +211,7 @@ type ManagedPeersHolder interface { // PersisterFactoryHandler defines the behaviour of a component which is able to create persisters type PersisterFactoryHandler interface { Create(path string) (Persister, error) + CreateWithRetries(path string) (Persister, error) IsInterfaceNil() bool } diff --git a/storage/storageunit/storageunit.go b/storage/storageunit/storageunit.go index 4e1605efaa7..2a9e390b725 100644 --- a/storage/storageunit/storageunit.go +++ b/storage/storageunit/storageunit.go @@ -14,9 +14,6 @@ type Unit = storageUnit.Unit // CacheConfig holds the configurable elements of a cache type CacheConfig = storageUnit.CacheConfig -// ArgDB is a structure that is used to create a new storage.Persister implementation -type ArgDB = storageUnit.ArgDB - // DBConfig holds the configurable elements of a database type DBConfig = storageUnit.DBConfig @@ -43,11 +40,6 @@ func NewCache(config CacheConfig) (storage.Cacher, error) { return storageUnit.NewCache(config) } -// NewDB creates a new database from database config -func NewDB(persisterFactory storage.PersisterFactoryHandler, path string) (storage.Persister, error) { - return storageUnit.NewDB(persisterFactory, path) -} - // NewStorageUnitFromConf creates a new storage unit from a storage unit config func NewStorageUnitFromConf(cacheConf CacheConfig, dbConf DBConfig, persisterFactory storage.PersisterFactoryHandler) (*Unit, error) { return storageUnit.NewStorageUnitFromConf(cacheConf, dbConf, persisterFactory) diff --git a/storage/storageunit/storageunit_test.go b/storage/storageunit/storageunit_test.go index 34affcb569f..44d862e6bdc 100644 --- a/storage/storageunit/storageunit_test.go +++ b/storage/storageunit/storageunit_test.go @@ -91,7 +91,7 @@ func TestNewDB(t *testing.T) { persisterFactory, err := factory.NewPersisterFactory(dbConfigHandler) assert.Nil(t, err) - db, err := storageunit.NewDB(persisterFactory, path) + db, err := persisterFactory.CreateWithRetries(path) assert.True(t, check.IfNil(db)) assert.Equal(t, common.ErrNotSupportedDBType, err) }) @@ -111,7 +111,7 @@ func TestNewDB(t *testing.T) { persisterFactory, err := factory.NewPersisterFactory(dbConfigHandler) assert.Nil(t, err) - db, err := storageunit.NewDB(persisterFactory, path) + db, err := persisterFactory.CreateWithRetries(path) assert.False(t, check.IfNil(db)) assert.Nil(t, err) _ = db.Close() diff --git a/testscommon/dataRetriever/poolFactory.go b/testscommon/dataRetriever/poolFactory.go index 77bdeb610a7..9d12403893b 100644 --- a/testscommon/dataRetriever/poolFactory.go +++ b/testscommon/dataRetriever/poolFactory.go @@ -102,7 +102,7 @@ func CreatePoolsHolder(numShards uint32, selfShard uint32) dataRetriever.PoolsHo persisterFactory, err := storageFactory.NewPersisterFactory(dbConfigHandler) panicIfError("Create persister factory", err) - persister, err := storageunit.NewDB(persisterFactory, tempDir) + persister, err := persisterFactory.CreateWithRetries(tempDir) panicIfError("Create trieSync DB", err) tnf := factory.NewTrieNodeFactory() From 9b0d7c8801b085f38ae7636ea52fa3e64157c448 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 3 Jan 2024 22:17:13 +0200 Subject: [PATCH 031/503] refactor persister factory --- dataRetriever/factory/dataPoolFactory.go | 3 +- epochStart/metachain/systemSCs_test.go | 3 +- genesis/process/genesisBlockCreator.go | 3 +- .../vm/wasm/delegation/testRunner.go | 3 +- process/smartContract/hooks/blockChainHook.go | 3 +- storage/factory/openStorage.go | 6 ++-- storage/factory/persisterFactory.go | 24 +++++++------- storage/factory/persisterFactory_test.go | 30 +++++------------ storage/factory/storageServiceFactory.go | 33 +++++++------------ storage/latestData/latestDataProvider.go | 3 +- .../pruning/fullHistoryPruningStorer_test.go | 17 ++++------ storage/pruning/pruningStorer_test.go | 17 ++++------ storage/storageunit/storageunit_test.go | 12 +++---- testscommon/dataRetriever/poolFactory.go | 3 +- testscommon/integrationtests/factory.go | 3 +- update/factory/dataTrieFactory.go | 3 +- update/factory/exportHandlerFactory.go | 3 +- 17 files changed, 61 insertions(+), 108 deletions(-) diff --git a/dataRetriever/factory/dataPoolFactory.go b/dataRetriever/factory/dataPoolFactory.go index 82ac3416be2..8d3ae50bdb0 100644 --- a/dataRetriever/factory/dataPoolFactory.go +++ b/dataRetriever/factory/dataPoolFactory.go @@ -179,8 +179,7 @@ func createTrieSyncDB(args ArgsDataPool) (storage.Persister, error) { shardId := core.GetShardIDString(args.ShardCoordinator.SelfId()) path := args.PathManager.PathForStatic(shardId, mainConfig.TrieSyncStorage.DB.FilePath) - dbConfigHandler := factory.NewDBConfigHandler(mainConfig.TrieSyncStorage.DB) - persisterFactory, err := factory.NewPersisterFactory(dbConfigHandler) + persisterFactory, err := factory.NewPersisterFactory(mainConfig.TrieSyncStorage.DB) if err != nil { return nil, err } diff --git a/epochStart/metachain/systemSCs_test.go b/epochStart/metachain/systemSCs_test.go index bdf66c5694c..f74f9238db9 100644 --- a/epochStart/metachain/systemSCs_test.go +++ b/epochStart/metachain/systemSCs_test.go @@ -87,8 +87,7 @@ func createPhysicalUnit(t *testing.T) (storage.Storer, string) { MaxOpenFiles: 10, } - dbConfigHandler := storageFactory.NewDBConfigHandler(dbConfig) - persisterFactory, err := storageFactory.NewPersisterFactory(dbConfigHandler) + persisterFactory, err := storageFactory.NewPersisterFactory(dbConfig) assert.Nil(t, err) cache, _ := storageunit.NewCache(cacheConfig) diff --git a/genesis/process/genesisBlockCreator.go b/genesis/process/genesisBlockCreator.go index 2e9b14d7db3..d3fecd2f2d1 100644 --- a/genesis/process/genesisBlockCreator.go +++ b/genesis/process/genesisBlockCreator.go @@ -131,8 +131,7 @@ func createStorer(storageConfig config.StorageConfig, folder string) (storage.St dbConfig := factory.GetDBFromConfig(storageConfig.DB) dbConfig.FilePath = path.Join(folder, storageConfig.DB.FilePath) - dbConfigHandler := factory.NewDBConfigHandler(storageConfig.DB) - persisterFactory, err := factory.NewPersisterFactory(dbConfigHandler) + persisterFactory, err := factory.NewPersisterFactory(storageConfig.DB) if err != nil { return nil, err } diff --git a/integrationTests/vm/wasm/delegation/testRunner.go b/integrationTests/vm/wasm/delegation/testRunner.go index 343f3dace0f..e7bcb516b45 100644 --- a/integrationTests/vm/wasm/delegation/testRunner.go +++ b/integrationTests/vm/wasm/delegation/testRunner.go @@ -53,8 +53,7 @@ func RunDelegationStressTest( MaxBatchSize: 45000, MaxOpenFiles: 10, } - dbConfigHandler := factory.NewDBConfigHandler(dbConfig) - persisterFactory, err := factory.NewPersisterFactory(dbConfigHandler) + persisterFactory, err := factory.NewPersisterFactory(dbConfig) if err != nil { return nil, err } diff --git a/process/smartContract/hooks/blockChainHook.go b/process/smartContract/hooks/blockChainHook.go index 827d08da435..18d0dac3d7f 100644 --- a/process/smartContract/hooks/blockChainHook.go +++ b/process/smartContract/hooks/blockChainHook.go @@ -826,8 +826,7 @@ func (bh *BlockChainHookImpl) makeCompiledSCStorage() error { dbConfig := factory.GetDBFromConfig(bh.configSCStorage.DB) dbConfig.FilePath = path.Join(bh.workingDir, defaultCompiledSCPath, bh.configSCStorage.DB.FilePath) - dbConfigHandler := factory.NewDBConfigHandler(bh.configSCStorage.DB) - persisterFactory, err := factory.NewPersisterFactory(dbConfigHandler) + persisterFactory, err := factory.NewPersisterFactory(bh.configSCStorage.DB) if err != nil { return err } diff --git a/storage/factory/openStorage.go b/storage/factory/openStorage.go index eacb57a8a79..0effada6f04 100644 --- a/storage/factory/openStorage.go +++ b/storage/factory/openStorage.go @@ -55,8 +55,7 @@ func (o *openStorageUnits) GetMostRecentStorageUnit(dbConfig config.DBConfig) (s return nil, err } - dbConfigHandler := NewDBConfigHandler(dbConfig) - persisterFactory, err := NewPersisterFactory(dbConfigHandler) + persisterFactory, err := NewPersisterFactory(dbConfig) if err != nil { return nil, err } @@ -111,8 +110,7 @@ func (o *openStorageUnits) OpenDB(dbConfig config.DBConfig, shardID uint32, epoc parentDir := o.latestStorageDataProvider.GetParentDirectory() pathWithoutShard := o.getPathWithoutShard(parentDir, epoch) persisterPath := o.getPersisterPath(pathWithoutShard, fmt.Sprintf("%d", shardID), dbConfig) - dbConfigHandler := NewDBConfigHandler(dbConfig) - persisterFactory, err := NewPersisterFactory(dbConfigHandler) + persisterFactory, err := NewPersisterFactory(dbConfig) if err != nil { return nil, err } diff --git a/storage/factory/persisterFactory.go b/storage/factory/persisterFactory.go index a657dc7a0d6..2c40b2fc328 100644 --- a/storage/factory/persisterFactory.go +++ b/storage/factory/persisterFactory.go @@ -3,30 +3,28 @@ package factory import ( "time" - "github.com/multiversx/mx-chain-core-go/core/check" + "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/storage/disabled" ) -// PersisterFactory is the factory which will handle creating new databases -type PersisterFactory struct { +// persisterFactory is the factory which will handle creating new databases +type persisterFactory struct { dbConfigHandler storage.DBConfigHandler } -// NewPersisterFactory will return a new instance of a PersisterFactory -func NewPersisterFactory(dbConfigHandler storage.DBConfigHandler) (*PersisterFactory, error) { - if check.IfNil(dbConfigHandler) { - return nil, storage.ErrNilDBConfigHandler - } +// NewPersisterFactory will return a new instance of persister factory +func NewPersisterFactory(config config.DBConfig) (*persisterFactory, error) { + dbConfigHandler := NewDBConfigHandler(config) - return &PersisterFactory{ + return &persisterFactory{ dbConfigHandler: dbConfigHandler, }, nil } // CreateWithRetries will return a new instance of a DB with a given path // It will try to create db multiple times -func (pf *PersisterFactory) CreateWithRetries(path string) (storage.Persister, error) { +func (pf *persisterFactory) CreateWithRetries(path string) (storage.Persister, error) { var persister storage.Persister var err error @@ -45,7 +43,7 @@ func (pf *PersisterFactory) CreateWithRetries(path string) (storage.Persister, e } // Create will return a new instance of a DB with a given path -func (pf *PersisterFactory) Create(path string) (storage.Persister, error) { +func (pf *persisterFactory) Create(path string) (storage.Persister, error) { if len(path) == 0 { return nil, storage.ErrInvalidFilePath } @@ -71,11 +69,11 @@ func (pf *PersisterFactory) Create(path string) (storage.Persister, error) { } // CreateDisabled will return a new disabled persister -func (pf *PersisterFactory) CreateDisabled() storage.Persister { +func (pf *persisterFactory) CreateDisabled() storage.Persister { return disabled.NewErrorDisabledPersister() } // IsInterfaceNil returns true if there is no value under the interface -func (pf *PersisterFactory) IsInterfaceNil() bool { +func (pf *persisterFactory) IsInterfaceNil() bool { return pf == nil } diff --git a/storage/factory/persisterFactory_test.go b/storage/factory/persisterFactory_test.go index 208542a665b..860331a22bc 100644 --- a/storage/factory/persisterFactory_test.go +++ b/storage/factory/persisterFactory_test.go @@ -15,8 +15,7 @@ import ( func TestNewPersisterFactory(t *testing.T) { t.Parallel() - dbConfigHandler := factory.NewDBConfigHandler(createDefaultDBConfig()) - pf, err := factory.NewPersisterFactory(dbConfigHandler) + pf, err := factory.NewPersisterFactory(createDefaultDBConfig()) require.NotNil(t, pf) require.Nil(t, err) } @@ -27,8 +26,7 @@ func TestPersisterFactory_Create(t *testing.T) { t.Run("invalid file path, should fail", func(t *testing.T) { t.Parallel() - dbConfigHandler := factory.NewDBConfigHandler(createDefaultDBConfig()) - pf, _ := factory.NewPersisterFactory(dbConfigHandler) + pf, _ := factory.NewPersisterFactory(createDefaultDBConfig()) p, err := pf.Create("") require.Nil(t, p) @@ -38,8 +36,7 @@ func TestPersisterFactory_Create(t *testing.T) { t.Run("should work", func(t *testing.T) { t.Parallel() - dbConfigHandler := factory.NewDBConfigHandler(createDefaultDBConfig()) - pf, _ := factory.NewPersisterFactory(dbConfigHandler) + pf, _ := factory.NewPersisterFactory(createDefaultDBConfig()) dir := t.TempDir() @@ -57,8 +54,7 @@ func TestPersisterFactory_Create_ConfigSaveToFilePath(t *testing.T) { dbConfig := createDefaultBasePersisterConfig() dbConfig.Type = string(storageunit.LvlDB) - dbConfigHandler := factory.NewDBConfigHandler(dbConfig) - pf, _ := factory.NewPersisterFactory(dbConfigHandler) + pf, _ := factory.NewPersisterFactory(dbConfig) dir := t.TempDir() path := dir + "storer/" @@ -77,8 +73,7 @@ func TestPersisterFactory_Create_ConfigSaveToFilePath(t *testing.T) { dbConfig := createDefaultBasePersisterConfig() dbConfig.Type = string(storageunit.LvlDBSerial) - dbConfigHandler := factory.NewDBConfigHandler(dbConfig) - pf, _ := factory.NewPersisterFactory(dbConfigHandler) + pf, _ := factory.NewPersisterFactory(dbConfig) dir := t.TempDir() path := dir + "storer/" @@ -97,8 +92,7 @@ func TestPersisterFactory_Create_ConfigSaveToFilePath(t *testing.T) { dbConfig := createDefaultBasePersisterConfig() dbConfig.Type = string(storageunit.MemoryDB) - dbConfigHandler := factory.NewDBConfigHandler(dbConfig) - pf, _ := factory.NewPersisterFactory(dbConfigHandler) + pf, _ := factory.NewPersisterFactory(dbConfig) dir := t.TempDir() path := dir + "storer/" @@ -117,8 +111,7 @@ func TestPersisterFactory_Create_ConfigSaveToFilePath(t *testing.T) { dbConfig := createDefaultBasePersisterConfig() dbConfig.Type = string(storageunit.MemoryDB) - dbConfigHandler := factory.NewDBConfigHandler(dbConfig) - pf, _ := factory.NewPersisterFactory(dbConfigHandler) + pf, _ := factory.NewPersisterFactory(dbConfig) dir := t.TempDir() path := dir + "storer/" @@ -135,8 +128,7 @@ func TestPersisterFactory_Create_ConfigSaveToFilePath(t *testing.T) { func TestPersisterFactory_CreateDisabled(t *testing.T) { t.Parallel() - dbConfigHandler := factory.NewDBConfigHandler(createDefaultDBConfig()) - factoryInstance, err := factory.NewPersisterFactory(dbConfigHandler) + factoryInstance, err := factory.NewPersisterFactory(createDefaultDBConfig()) require.Nil(t, err) persisterInstance := factoryInstance.CreateDisabled() @@ -147,10 +139,6 @@ func TestPersisterFactory_CreateDisabled(t *testing.T) { func TestPersisterFactory_IsInterfaceNil(t *testing.T) { t.Parallel() - var pf *factory.PersisterFactory - require.True(t, pf.IsInterfaceNil()) - - dbConfigHandler := factory.NewDBConfigHandler(createDefaultDBConfig()) - pf, _ = factory.NewPersisterFactory(dbConfigHandler) + pf, _ := factory.NewPersisterFactory(createDefaultDBConfig()) require.False(t, pf.IsInterfaceNil()) } diff --git a/storage/factory/storageServiceFactory.go b/storage/factory/storageServiceFactory.go index 0b213f02dea..11a01432192 100644 --- a/storage/factory/storageServiceFactory.go +++ b/storage/factory/storageServiceFactory.go @@ -224,8 +224,7 @@ func (psf *StorageServiceFactory) createAndAddBaseStorageUnits( dbPath := psf.pathManager.PathForStatic(shardID, psf.generalConfig.MetaHdrNonceHashStorage.DB.FilePath) metaHdrHashNonceUnitConfig.FilePath = dbPath - dbConfigHandler := NewDBConfigHandler(psf.generalConfig.MetaHdrNonceHashStorage.DB) - metaHdrHashNoncePersisterCreator, err := NewPersisterFactory(dbConfigHandler) + metaHdrHashNoncePersisterCreator, err := NewPersisterFactory(psf.generalConfig.MetaHdrNonceHashStorage.DB) if err != nil { return err } @@ -261,8 +260,7 @@ func (psf *StorageServiceFactory) createAndAddBaseStorageUnits( dbPath = psf.pathManager.PathForStatic(shardId, psf.generalConfig.StatusMetricsStorage.DB.FilePath) statusMetricsDbConfig.FilePath = dbPath - dbConfigHandler = NewDBConfigHandler(psf.generalConfig.StatusMetricsStorage.DB) - statusMetricsPersisterCreator, err := NewPersisterFactory(dbConfigHandler) + statusMetricsPersisterCreator, err := NewPersisterFactory(psf.generalConfig.StatusMetricsStorage.DB) if err != nil { return err } @@ -304,8 +302,7 @@ func (psf *StorageServiceFactory) CreateForShard() (dataRetriever.StorageService dbPath := psf.pathManager.PathForStatic(shardID, psf.generalConfig.ShardHdrNonceHashStorage.DB.FilePath) + shardID shardHdrHashNonceConfig.FilePath = dbPath - dbConfigHandler := NewDBConfigHandler(psf.generalConfig.ShardHdrNonceHashStorage.DB) - shardHdrHashNoncePersisterCreator, err := NewPersisterFactory(dbConfigHandler) + shardHdrHashNoncePersisterCreator, err := NewPersisterFactory(psf.generalConfig.ShardHdrNonceHashStorage.DB) if err != nil { return nil, err } @@ -384,8 +381,7 @@ func (psf *StorageServiceFactory) CreateForMeta() (dataRetriever.StorageService, dbPath := psf.pathManager.PathForStatic(shardID, psf.generalConfig.ShardHdrNonceHashStorage.DB.FilePath) + fmt.Sprintf("%d", i) shardHdrHashNonceConfig.FilePath = dbPath - dbConfigHandler := NewDBConfigHandler(psf.generalConfig.ShardHdrNonceHashStorage.DB) - shardHdrHashNoncePersisterCreator, err := NewPersisterFactory(dbConfigHandler) + shardHdrHashNoncePersisterCreator, err := NewPersisterFactory(psf.generalConfig.ShardHdrNonceHashStorage.DB) if err != nil { return nil, err } @@ -526,8 +522,7 @@ func (psf *StorageServiceFactory) setUpDbLookupExtensions(chainStorer *dataRetri miniblockHashByTxHashDbConfig.FilePath = psf.pathManager.PathForStatic(shardID, miniblockHashByTxHashConfig.DB.FilePath) miniblockHashByTxHashCacherConfig := GetCacherFromConfig(miniblockHashByTxHashConfig.Cache) - dbConfigHandler := NewDBConfigHandler(miniblockHashByTxHashConfig.DB) - miniblockHashByTxHashPersisterCreator, err := NewPersisterFactory(dbConfigHandler) + miniblockHashByTxHashPersisterCreator, err := NewPersisterFactory(miniblockHashByTxHashConfig.DB) if err != nil { return err } @@ -549,8 +544,7 @@ func (psf *StorageServiceFactory) setUpDbLookupExtensions(chainStorer *dataRetri blockHashByRoundDBConfig.FilePath = psf.pathManager.PathForStatic(shardID, blockHashByRoundConfig.DB.FilePath) blockHashByRoundCacherConfig := GetCacherFromConfig(blockHashByRoundConfig.Cache) - dbConfigHandler = NewDBConfigHandler(blockHashByRoundConfig.DB) - blockHashByRoundPersisterCreator, err := NewPersisterFactory(dbConfigHandler) + blockHashByRoundPersisterCreator, err := NewPersisterFactory(blockHashByRoundConfig.DB) if err != nil { return err } @@ -572,8 +566,7 @@ func (psf *StorageServiceFactory) setUpDbLookupExtensions(chainStorer *dataRetri epochByHashDbConfig.FilePath = psf.pathManager.PathForStatic(shardID, epochByHashConfig.DB.FilePath) epochByHashCacherConfig := GetCacherFromConfig(epochByHashConfig.Cache) - dbConfigHandler = NewDBConfigHandler(epochByHashConfig.DB) - epochByHashPersisterCreator, err := NewPersisterFactory(dbConfigHandler) + epochByHashPersisterCreator, err := NewPersisterFactory(epochByHashConfig.DB) if err != nil { return err } @@ -622,8 +615,7 @@ func (psf *StorageServiceFactory) createEsdtSuppliesUnit(shardIDStr string) (sto esdtSuppliesDbConfig.FilePath = psf.pathManager.PathForStatic(shardIDStr, esdtSuppliesConfig.DB.FilePath) esdtSuppliesCacherConfig := GetCacherFromConfig(esdtSuppliesConfig.Cache) - dbConfigHandler := NewDBConfigHandler(esdtSuppliesConfig.DB) - esdtSuppliesPersisterCreator, err := NewPersisterFactory(dbConfigHandler) + esdtSuppliesPersisterCreator, err := NewPersisterFactory(esdtSuppliesConfig.DB) if err != nil { return nil, err } @@ -648,8 +640,7 @@ func (psf *StorageServiceFactory) createPruningStorerArgs( NumOfActivePersisters: numOfActivePersisters, } - dbConfigHandler := NewDBConfigHandler(storageConfig.DB) - persisterFactory, err := NewPersisterFactory(dbConfigHandler) + persisterFactory, err := NewPersisterFactory(storageConfig.DB) if err != nil { return pruning.StorerArgs{}, err } @@ -685,8 +676,7 @@ func (psf *StorageServiceFactory) createTrieEpochRootHashStorerIfNeeded() (stora dbPath := psf.pathManager.PathForStatic(shardId, psf.generalConfig.TrieEpochRootHashStorage.DB.FilePath) trieEpochRootHashDbConfig.FilePath = dbPath - dbConfigHandler := NewDBConfigHandler(psf.generalConfig.TrieEpochRootHashStorage.DB) - esdtSuppliesPersisterCreator, err := NewPersisterFactory(dbConfigHandler) + esdtSuppliesPersisterCreator, err := NewPersisterFactory(psf.generalConfig.TrieEpochRootHashStorage.DB) if err != nil { return nil, err } @@ -711,8 +701,7 @@ func (psf *StorageServiceFactory) createTriePersister( dbPath := psf.pathManager.PathForStatic(shardID, storageConfig.DB.FilePath) trieDBConfig.FilePath = dbPath - dbConfigHandler := NewDBConfigHandler(storageConfig.DB) - persisterFactory, err := NewPersisterFactory(dbConfigHandler) + persisterFactory, err := NewPersisterFactory(storageConfig.DB) if err != nil { return nil, err } diff --git a/storage/latestData/latestDataProvider.go b/storage/latestData/latestDataProvider.go index df6ea7e2418..2b894627de3 100644 --- a/storage/latestData/latestDataProvider.go +++ b/storage/latestData/latestDataProvider.go @@ -132,8 +132,7 @@ func (ldp *latestDataProvider) getEpochDirs() ([]string, error) { } func (ldp *latestDataProvider) getLastEpochAndRoundFromStorage(parentDir string, lastEpoch uint32) (storage.LatestDataFromStorage, error) { - dbConfigHandler := factory.NewDBConfigHandler(ldp.generalConfig.BootstrapStorage.DB) - persisterFactory, err := factory.NewPersisterFactory(dbConfigHandler) + persisterFactory, err := factory.NewPersisterFactory(ldp.generalConfig.BootstrapStorage.DB) if err != nil { return storage.LatestDataFromStorage{}, err } diff --git a/storage/pruning/fullHistoryPruningStorer_test.go b/storage/pruning/fullHistoryPruningStorer_test.go index c83fc5fae34..0e0d43877e8 100644 --- a/storage/pruning/fullHistoryPruningStorer_test.go +++ b/storage/pruning/fullHistoryPruningStorer_test.go @@ -294,16 +294,13 @@ func TestFullHistoryPruningStorer_ConcurrentOperations(t *testing.T) { fmt.Println(testDir) args := getDefaultArgs() - dbConfigHandler := factory.NewDBConfigHandler( - config.DBConfig{ - FilePath: filepath.Join(testDir, dbName), - Type: "LvlDBSerial", - MaxBatchSize: 100, - MaxOpenFiles: 10, - BatchDelaySeconds: 2, - }, - ) - persisterFactory, err := factory.NewPersisterFactory(dbConfigHandler) + persisterFactory, err := factory.NewPersisterFactory(config.DBConfig{ + FilePath: filepath.Join(testDir, dbName), + Type: "LvlDBSerial", + MaxBatchSize: 100, + MaxOpenFiles: 10, + BatchDelaySeconds: 2, + }) require.Nil(t, err) args.PersisterFactory = persisterFactory diff --git a/storage/pruning/pruningStorer_test.go b/storage/pruning/pruningStorer_test.go index 29c3765e2d8..248cc53cda2 100644 --- a/storage/pruning/pruningStorer_test.go +++ b/storage/pruning/pruningStorer_test.go @@ -1053,16 +1053,13 @@ func TestPruningStorer_ConcurrentOperations(t *testing.T) { fmt.Println(testDir) args := getDefaultArgs() - dbConfigHandler := factory.NewDBConfigHandler( - config.DBConfig{ - FilePath: filepath.Join(testDir, dbName), - Type: "LvlDBSerial", - MaxBatchSize: 100, - MaxOpenFiles: 10, - BatchDelaySeconds: 2, - }, - ) - persisterFactory, err := factory.NewPersisterFactory(dbConfigHandler) + persisterFactory, err := factory.NewPersisterFactory(config.DBConfig{ + FilePath: filepath.Join(testDir, dbName), + Type: "LvlDBSerial", + MaxBatchSize: 100, + MaxOpenFiles: 10, + BatchDelaySeconds: 2, + }) require.Nil(t, err) args.PersisterFactory = persisterFactory diff --git a/storage/storageunit/storageunit_test.go b/storage/storageunit/storageunit_test.go index 44d862e6bdc..0652f25b33c 100644 --- a/storage/storageunit/storageunit_test.go +++ b/storage/storageunit/storageunit_test.go @@ -87,8 +87,7 @@ func TestNewDB(t *testing.T) { MaxOpenFiles: 10, } - dbConfigHandler := factory.NewDBConfigHandler(dbConfig) - persisterFactory, err := factory.NewPersisterFactory(dbConfigHandler) + persisterFactory, err := factory.NewPersisterFactory(dbConfig) assert.Nil(t, err) db, err := persisterFactory.CreateWithRetries(path) @@ -107,8 +106,7 @@ func TestNewDB(t *testing.T) { MaxOpenFiles: 10, } - dbConfigHandler := factory.NewDBConfigHandler(dbConfig) - persisterFactory, err := factory.NewPersisterFactory(dbConfigHandler) + persisterFactory, err := factory.NewPersisterFactory(dbConfig) assert.Nil(t, err) db, err := persisterFactory.CreateWithRetries(path) @@ -144,8 +142,7 @@ func TestNewStorageUnitFromConf(t *testing.T) { MaxBatchSize: dbConfig.MaxBatchSize, MaxOpenFiles: dbConfig.MaxOpenFiles, } - dbConfigHandler := factory.NewDBConfigHandler(dbConf) - persisterFactory, err := factory.NewPersisterFactory(dbConfigHandler) + persisterFactory, err := factory.NewPersisterFactory(dbConf) assert.Nil(t, err) unit, err := storageunit.NewStorageUnitFromConf(cacheConfig, dbConfig, persisterFactory) @@ -166,8 +163,7 @@ func TestNewStorageUnitFromConf(t *testing.T) { MaxBatchSize: dbConfig.MaxBatchSize, MaxOpenFiles: dbConfig.MaxOpenFiles, } - dbConfigHandler := factory.NewDBConfigHandler(dbConf) - persisterFactory, err := factory.NewPersisterFactory(dbConfigHandler) + persisterFactory, err := factory.NewPersisterFactory(dbConf) assert.Nil(t, err) unit, err := storageunit.NewStorageUnitFromConf(cacheConfig, dbConfig, persisterFactory) diff --git a/testscommon/dataRetriever/poolFactory.go b/testscommon/dataRetriever/poolFactory.go index 9d12403893b..a8f4374e800 100644 --- a/testscommon/dataRetriever/poolFactory.go +++ b/testscommon/dataRetriever/poolFactory.go @@ -98,8 +98,7 @@ func CreatePoolsHolder(numShards uint32, selfShard uint32) dataRetriever.PoolsHo MaxOpenFiles: 10, } - dbConfigHandler := storageFactory.NewDBConfigHandler(dbConfig) - persisterFactory, err := storageFactory.NewPersisterFactory(dbConfigHandler) + persisterFactory, err := storageFactory.NewPersisterFactory(dbConfig) panicIfError("Create persister factory", err) persister, err := persisterFactory.CreateWithRetries(tempDir) diff --git a/testscommon/integrationtests/factory.go b/testscommon/integrationtests/factory.go index 4d2f9ad02d8..9acfa7c5e10 100644 --- a/testscommon/integrationtests/factory.go +++ b/testscommon/integrationtests/factory.go @@ -62,8 +62,7 @@ func CreateStorer(parentDir string) storage.Storer { MaxBatchSize: 45000, MaxOpenFiles: 10, } - dbConfigHandler := factory.NewDBConfigHandler(dbConfig) - persisterFactory, err := factory.NewPersisterFactory(dbConfigHandler) + persisterFactory, err := factory.NewPersisterFactory(dbConfig) if err != nil { return nil } diff --git a/update/factory/dataTrieFactory.go b/update/factory/dataTrieFactory.go index f9491350693..dcd83da1bd7 100644 --- a/update/factory/dataTrieFactory.go +++ b/update/factory/dataTrieFactory.go @@ -67,8 +67,7 @@ func NewDataTrieFactory(args ArgsNewDataTrieFactory) (*dataTrieFactory, error) { dbConfig := storageFactory.GetDBFromConfig(args.StorageConfig.DB) dbConfig.FilePath = path.Join(args.SyncFolder, args.StorageConfig.DB.FilePath) - dbConfigHandler := factory.NewDBConfigHandler(args.StorageConfig.DB) - persisterFactory, err := factory.NewPersisterFactory(dbConfigHandler) + persisterFactory, err := factory.NewPersisterFactory(args.StorageConfig.DB) if err != nil { return nil, err } diff --git a/update/factory/exportHandlerFactory.go b/update/factory/exportHandlerFactory.go index 8dd429345bb..c13f25f3f5a 100644 --- a/update/factory/exportHandlerFactory.go +++ b/update/factory/exportHandlerFactory.go @@ -608,8 +608,7 @@ func createStorer(storageConfig config.StorageConfig, folder string) (storage.St dbConfig := storageFactory.GetDBFromConfig(storageConfig.DB) dbConfig.FilePath = path.Join(folder, storageConfig.DB.FilePath) - dbConfigHandler := storageFactory.NewDBConfigHandler(storageConfig.DB) - persisterFactory, err := storageFactory.NewPersisterFactory(dbConfigHandler) + persisterFactory, err := storageFactory.NewPersisterFactory(storageConfig.DB) if err != nil { return nil, err } From b8f8c5e3908576deb3696ac915192bbb0f69fd53 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 4 Jan 2024 13:13:10 +0200 Subject: [PATCH 032/503] separate function for static storer creation --- storage/factory/storageServiceFactory.go | 211 ++++++----------------- 1 file changed, 50 insertions(+), 161 deletions(-) diff --git a/storage/factory/storageServiceFactory.go b/storage/factory/storageServiceFactory.go index 11a01432192..902b101675b 100644 --- a/storage/factory/storageServiceFactory.go +++ b/storage/factory/storageServiceFactory.go @@ -27,6 +27,7 @@ var log = logger.GetOrCreate("storage/factory") const ( minimumNumberOfActivePersisters = 1 minimumNumberOfEpochsToKeep = 2 + emptyDBPathSuffix = "" ) // StorageServiceType defines the type of StorageService @@ -131,11 +132,8 @@ func checkArgs(args StorageServiceFactoryArgs) error { return nil } -// TODO: refactor this function, split it into multiple ones -func (psf *StorageServiceFactory) createAndAddBaseStorageUnits( +func (psf *StorageServiceFactory) createAndAddTxStorageUnits( store dataRetriever.StorageService, - customDatabaseRemover storage.CustomDatabaseRemoverHandler, - shardID string, ) error { disabledCustomDatabaseRemover := disabled.NewDisabledCustomDatabaseRemover() @@ -179,6 +177,21 @@ func (psf *StorageServiceFactory) createAndAddBaseStorageUnits( } store.AddStorer(dataRetriever.ReceiptsUnit, receiptsUnit) + return nil +} + +func (psf *StorageServiceFactory) createAndAddBaseStorageUnits( + store dataRetriever.StorageService, + customDatabaseRemover storage.CustomDatabaseRemoverHandler, + shardID string, +) error { + disabledCustomDatabaseRemover := disabled.NewDisabledCustomDatabaseRemover() + + err := psf.createAndAddTxStorageUnits(store) + if err != nil { + return err + } + scheduledSCRsUnitArgs, err := psf.createPruningStorerArgs(psf.generalConfig.ScheduledSCRsStorage, disabledCustomDatabaseRemover) if err != nil { return err @@ -219,21 +232,7 @@ func (psf *StorageServiceFactory) createAndAddBaseStorageUnits( } store.AddStorer(dataRetriever.MetaBlockUnit, metaBlockUnit) - // metaHdrHashNonce is static - metaHdrHashNonceUnitConfig := GetDBFromConfig(psf.generalConfig.MetaHdrNonceHashStorage.DB) - dbPath := psf.pathManager.PathForStatic(shardID, psf.generalConfig.MetaHdrNonceHashStorage.DB.FilePath) - metaHdrHashNonceUnitConfig.FilePath = dbPath - - metaHdrHashNoncePersisterCreator, err := NewPersisterFactory(psf.generalConfig.MetaHdrNonceHashStorage.DB) - if err != nil { - return err - } - - metaHdrHashNonceUnit, err := storageunit.NewStorageUnitFromConf( - GetCacherFromConfig(psf.generalConfig.MetaHdrNonceHashStorage.Cache), - metaHdrHashNonceUnitConfig, - metaHdrHashNoncePersisterCreator, - ) + metaHdrHashNonceUnit, err := psf.createStaticStorageUnit(psf.generalConfig.MetaHdrNonceHashStorage, shardID, emptyDBPathSuffix) if err != nil { return fmt.Errorf("%w for MetaHdrNonceHashStorage", err) } @@ -255,21 +254,8 @@ func (psf *StorageServiceFactory) createAndAddBaseStorageUnits( } store.AddStorer(dataRetriever.UserAccountsUnit, userAccountsUnit) - statusMetricsDbConfig := GetDBFromConfig(psf.generalConfig.StatusMetricsStorage.DB) shardId := core.GetShardIDString(psf.shardCoordinator.SelfId()) - dbPath = psf.pathManager.PathForStatic(shardId, psf.generalConfig.StatusMetricsStorage.DB.FilePath) - statusMetricsDbConfig.FilePath = dbPath - - statusMetricsPersisterCreator, err := NewPersisterFactory(psf.generalConfig.StatusMetricsStorage.DB) - if err != nil { - return err - } - - statusMetricsStorageUnit, err := storageunit.NewStorageUnitFromConf( - GetCacherFromConfig(psf.generalConfig.StatusMetricsStorage.Cache), - statusMetricsDbConfig, - statusMetricsPersisterCreator, - ) + statusMetricsStorageUnit, err := psf.createStaticStorageUnit(psf.generalConfig.StatusMetricsStorage, shardId, emptyDBPathSuffix) if err != nil { return fmt.Errorf("%w for StatusMetricsStorage", err) } @@ -284,6 +270,27 @@ func (psf *StorageServiceFactory) createAndAddBaseStorageUnits( return nil } +func (psf *StorageServiceFactory) createStaticStorageUnit( + storageConf config.StorageConfig, + shardID string, + dbPathSuffix string, +) (*storageunit.Unit, error) { + storageUnitDBConf := GetDBFromConfig(storageConf.DB) + dbPath := psf.pathManager.PathForStatic(shardID, storageConf.DB.FilePath) + dbPathSuffix + storageUnitDBConf.FilePath = dbPath + + persisterCreator, err := NewPersisterFactory(storageConf.DB) + if err != nil { + return nil, err + } + + return storageunit.NewStorageUnitFromConf( + GetCacherFromConfig(storageConf.Cache), + storageUnitDBConf, + persisterCreator, + ) +} + // CreateForShard will return the storage service which contains all storers needed for a shard func (psf *StorageServiceFactory) CreateForShard() (dataRetriever.StorageService, error) { // TODO: if there will be a differentiation between the creation or opening of a DB, the DBs could be destroyed on a defer @@ -296,22 +303,8 @@ func (psf *StorageServiceFactory) CreateForShard() (dataRetriever.StorageService } shardID := core.GetShardIDString(psf.shardCoordinator.SelfId()) - - // shardHdrHashNonce storer is static - shardHdrHashNonceConfig := GetDBFromConfig(psf.generalConfig.ShardHdrNonceHashStorage.DB) - dbPath := psf.pathManager.PathForStatic(shardID, psf.generalConfig.ShardHdrNonceHashStorage.DB.FilePath) + shardID - shardHdrHashNonceConfig.FilePath = dbPath - - shardHdrHashNoncePersisterCreator, err := NewPersisterFactory(psf.generalConfig.ShardHdrNonceHashStorage.DB) - if err != nil { - return nil, err - } - - shardHdrHashNonceUnit, err := storageunit.NewStorageUnitFromConf( - GetCacherFromConfig(psf.generalConfig.ShardHdrNonceHashStorage.Cache), - shardHdrHashNonceConfig, - shardHdrHashNoncePersisterCreator, - ) + dbPathSuffix := shardID + shardHdrHashNonceUnit, err := psf.createStaticStorageUnit(psf.generalConfig.ShardHdrNonceHashStorage, shardID, dbPathSuffix) if err != nil { return nil, fmt.Errorf("%w for ShardHdrNonceHashStorage", err) } @@ -376,21 +369,8 @@ func (psf *StorageServiceFactory) CreateForMeta() (dataRetriever.StorageService, shardHdrHashNonceUnits := make([]*storageunit.Unit, psf.shardCoordinator.NumberOfShards()) for i := uint32(0); i < psf.shardCoordinator.NumberOfShards(); i++ { - shardHdrHashNonceConfig := GetDBFromConfig(psf.generalConfig.ShardHdrNonceHashStorage.DB) shardID = core.GetShardIDString(core.MetachainShardId) - dbPath := psf.pathManager.PathForStatic(shardID, psf.generalConfig.ShardHdrNonceHashStorage.DB.FilePath) + fmt.Sprintf("%d", i) - shardHdrHashNonceConfig.FilePath = dbPath - - shardHdrHashNoncePersisterCreator, err := NewPersisterFactory(psf.generalConfig.ShardHdrNonceHashStorage.DB) - if err != nil { - return nil, err - } - - shardHdrHashNonceUnits[i], err = storageunit.NewStorageUnitFromConf( - GetCacherFromConfig(psf.generalConfig.ShardHdrNonceHashStorage.Cache), - shardHdrHashNonceConfig, - shardHdrHashNoncePersisterCreator, - ) + shardHdrHashNonceUnits[i], err = psf.createStaticStorageUnit(psf.generalConfig.ShardHdrNonceHashStorage, shardID, fmt.Sprintf("%d", i)) if err != nil { return nil, fmt.Errorf("%w for ShardHdrNonceHashStorage on shard %d", err, i) } @@ -516,66 +496,21 @@ func (psf *StorageServiceFactory) setUpDbLookupExtensions(chainStorer *dataRetri chainStorer.AddStorer(dataRetriever.MiniblocksMetadataUnit, miniblocksMetadataPruningStorer) - // Create the miniblocksHashByTxHash (STATIC) storer - miniblockHashByTxHashConfig := psf.generalConfig.DbLookupExtensions.MiniblockHashByTxHashStorageConfig - miniblockHashByTxHashDbConfig := GetDBFromConfig(miniblockHashByTxHashConfig.DB) - miniblockHashByTxHashDbConfig.FilePath = psf.pathManager.PathForStatic(shardID, miniblockHashByTxHashConfig.DB.FilePath) - miniblockHashByTxHashCacherConfig := GetCacherFromConfig(miniblockHashByTxHashConfig.Cache) - - miniblockHashByTxHashPersisterCreator, err := NewPersisterFactory(miniblockHashByTxHashConfig.DB) - if err != nil { - return err - } - - miniblockHashByTxHashUnit, err := storageunit.NewStorageUnitFromConf( - miniblockHashByTxHashCacherConfig, - miniblockHashByTxHashDbConfig, - miniblockHashByTxHashPersisterCreator, - ) + miniblockHashByTxHashUnit, err := psf.createStaticStorageUnit(psf.generalConfig.DbLookupExtensions.MiniblockHashByTxHashStorageConfig, shardID, emptyDBPathSuffix) if err != nil { return fmt.Errorf("%w for DbLookupExtensions.MiniblockHashByTxHashStorageConfig", err) } chainStorer.AddStorer(dataRetriever.MiniblockHashByTxHashUnit, miniblockHashByTxHashUnit) - // Create the blockHashByRound (STATIC) storer - blockHashByRoundConfig := psf.generalConfig.DbLookupExtensions.RoundHashStorageConfig - blockHashByRoundDBConfig := GetDBFromConfig(blockHashByRoundConfig.DB) - blockHashByRoundDBConfig.FilePath = psf.pathManager.PathForStatic(shardID, blockHashByRoundConfig.DB.FilePath) - blockHashByRoundCacherConfig := GetCacherFromConfig(blockHashByRoundConfig.Cache) - - blockHashByRoundPersisterCreator, err := NewPersisterFactory(blockHashByRoundConfig.DB) - if err != nil { - return err - } - - blockHashByRoundUnit, err := storageunit.NewStorageUnitFromConf( - blockHashByRoundCacherConfig, - blockHashByRoundDBConfig, - blockHashByRoundPersisterCreator, - ) + blockHashByRoundUnit, err := psf.createStaticStorageUnit(psf.generalConfig.DbLookupExtensions.RoundHashStorageConfig, shardID, emptyDBPathSuffix) if err != nil { return fmt.Errorf("%w for DbLookupExtensions.RoundHashStorageConfig", err) } chainStorer.AddStorer(dataRetriever.RoundHdrHashDataUnit, blockHashByRoundUnit) - // Create the epochByHash (STATIC) storer - epochByHashConfig := psf.generalConfig.DbLookupExtensions.EpochByHashStorageConfig - epochByHashDbConfig := GetDBFromConfig(epochByHashConfig.DB) - epochByHashDbConfig.FilePath = psf.pathManager.PathForStatic(shardID, epochByHashConfig.DB.FilePath) - epochByHashCacherConfig := GetCacherFromConfig(epochByHashConfig.Cache) - - epochByHashPersisterCreator, err := NewPersisterFactory(epochByHashConfig.DB) - if err != nil { - return err - } - - epochByHashUnit, err := storageunit.NewStorageUnitFromConf( - epochByHashCacherConfig, - epochByHashDbConfig, - epochByHashPersisterCreator, - ) + epochByHashUnit, err := psf.createStaticStorageUnit(psf.generalConfig.DbLookupExtensions.EpochByHashStorageConfig, shardID, emptyDBPathSuffix) if err != nil { return fmt.Errorf("%w for DbLookupExtensions.EpochByHashStorageConfig", err) } @@ -586,7 +521,7 @@ func (psf *StorageServiceFactory) setUpDbLookupExtensions(chainStorer *dataRetri } func (psf *StorageServiceFactory) setUpEsdtSuppliesStorer(chainStorer *dataRetriever.ChainStorer, shardIDStr string) error { - esdtSuppliesUnit, err := psf.createEsdtSuppliesUnit(shardIDStr) + esdtSuppliesUnit, err := psf.createStaticStorageUnit(psf.generalConfig.DbLookupExtensions.ESDTSuppliesStorageConfig, shardIDStr, emptyDBPathSuffix) if err != nil { return fmt.Errorf("%w for DbLookupExtensions.ESDTSuppliesStorageConfig", err) } @@ -599,7 +534,7 @@ func (psf *StorageServiceFactory) setUpEsdtSuppliesStorer(chainStorer *dataRetri } time.Sleep(time.Second) // making sure the unit was properly closed and destroyed - esdtSuppliesUnit, err = psf.createEsdtSuppliesUnit(shardIDStr) + esdtSuppliesUnit, err = psf.createStaticStorageUnit(psf.generalConfig.DbLookupExtensions.ESDTSuppliesStorageConfig, shardIDStr, emptyDBPathSuffix) if err != nil { return err } @@ -609,22 +544,6 @@ func (psf *StorageServiceFactory) setUpEsdtSuppliesStorer(chainStorer *dataRetri return nil } -func (psf *StorageServiceFactory) createEsdtSuppliesUnit(shardIDStr string) (storage.Storer, error) { - esdtSuppliesConfig := psf.generalConfig.DbLookupExtensions.ESDTSuppliesStorageConfig - esdtSuppliesDbConfig := GetDBFromConfig(esdtSuppliesConfig.DB) - esdtSuppliesDbConfig.FilePath = psf.pathManager.PathForStatic(shardIDStr, esdtSuppliesConfig.DB.FilePath) - esdtSuppliesCacherConfig := GetCacherFromConfig(esdtSuppliesConfig.Cache) - - esdtSuppliesPersisterCreator, err := NewPersisterFactory(esdtSuppliesConfig.DB) - if err != nil { - return nil, err - } - - return storageunit.NewStorageUnitFromConf( - esdtSuppliesCacherConfig, esdtSuppliesDbConfig, - esdtSuppliesPersisterCreator) -} - func (psf *StorageServiceFactory) createPruningStorerArgs( storageConfig config.StorageConfig, customDatabaseRemover storage.CustomDatabaseRemoverHandler, @@ -671,21 +590,8 @@ func (psf *StorageServiceFactory) createTrieEpochRootHashStorerIfNeeded() (stora return storageunit.NewNilStorer(), nil } - trieEpochRootHashDbConfig := GetDBFromConfig(psf.generalConfig.TrieEpochRootHashStorage.DB) shardId := core.GetShardIDString(psf.shardCoordinator.SelfId()) - dbPath := psf.pathManager.PathForStatic(shardId, psf.generalConfig.TrieEpochRootHashStorage.DB.FilePath) - trieEpochRootHashDbConfig.FilePath = dbPath - - esdtSuppliesPersisterCreator, err := NewPersisterFactory(psf.generalConfig.TrieEpochRootHashStorage.DB) - if err != nil { - return nil, err - } - - trieEpochRootHashStorageUnit, err := storageunit.NewStorageUnitFromConf( - GetCacherFromConfig(psf.generalConfig.TrieEpochRootHashStorage.Cache), - trieEpochRootHashDbConfig, - esdtSuppliesPersisterCreator, - ) + trieEpochRootHashStorageUnit, err := psf.createStaticStorageUnit(psf.generalConfig.TrieEpochRootHashStorage, shardId, emptyDBPathSuffix) if err != nil { return nil, fmt.Errorf("%w for TrieEpochRootHashStorage", err) } @@ -696,25 +602,8 @@ func (psf *StorageServiceFactory) createTrieEpochRootHashStorerIfNeeded() (stora func (psf *StorageServiceFactory) createTriePersister( storageConfig config.StorageConfig, ) (storage.Storer, error) { - trieDBConfig := GetDBFromConfig(storageConfig.DB) shardID := core.GetShardIDString(psf.shardCoordinator.SelfId()) - dbPath := psf.pathManager.PathForStatic(shardID, storageConfig.DB.FilePath) - trieDBConfig.FilePath = dbPath - - persisterFactory, err := NewPersisterFactory(storageConfig.DB) - if err != nil { - return nil, err - } - - trieUnit, err := storageunit.NewStorageUnitFromConf( - GetCacherFromConfig(storageConfig.Cache), - trieDBConfig, - persisterFactory) - if err != nil { - return nil, err - } - - return trieUnit, nil + return psf.createStaticStorageUnit(storageConfig, shardID, emptyDBPathSuffix) } func (psf *StorageServiceFactory) createTriePruningPersister(arg pruning.StorerArgs) (storage.Storer, error) { From 01e7a29c3582a3380fc624e66798b353acc0ffb3 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Fri, 5 Jan 2024 11:37:28 +0200 Subject: [PATCH 033/503] fix after merge --- config/tomlConfig_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index 3c8fd3aece3..dea94c2b679 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -840,7 +840,7 @@ func TestEnableEpochConfig(t *testing.T) { FixGasRemainingForSaveKeyValueBuiltinFunctionEnableEpoch = 91 # DynamicESDTEnableEpoch represents the epoch when dynamic NFT feature is enabled - DynamicESDTEnableEpoch = 91 + DynamicESDTEnableEpoch = 92 # MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MaxNodesChangeEnableEpoch = [ From 96b2181d538a749a9d970824469a915bbd3a1ade Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Fri, 5 Jan 2024 12:02:12 +0200 Subject: [PATCH 034/503] enableEpochsHandler small fix --- common/enablers/enableEpochsHandler.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/enablers/enableEpochsHandler.go b/common/enablers/enableEpochsHandler.go index 762cf0a08e9..e5d495717f8 100644 --- a/common/enablers/enableEpochsHandler.go +++ b/common/enablers/enableEpochsHandler.go @@ -697,9 +697,9 @@ func (handler *enableEpochsHandler) createAllFlagsMap() { }, common.DynamicESDTFlag: { isActiveInEpoch: func(epoch uint32) bool { - return epoch >= handler.enableEpochsConfig.NFTStopCreateEnableEpoch + return epoch >= handler.enableEpochsConfig.DynamicESDTEnableEpoch }, - activationEpoch: handler.enableEpochsConfig.NFTStopCreateEnableEpoch, + activationEpoch: handler.enableEpochsConfig.DynamicESDTEnableEpoch, }, } } From 8d05dfee905cad49e46034b50fd1d3d01401e57c Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Mon, 8 Jan 2024 10:59:07 +0200 Subject: [PATCH 035/503] integrate vm-common-go and core-go --- .../config/gasSchedules/gasScheduleV1.toml | 5 ++++ .../config/gasSchedules/gasScheduleV2.toml | 5 ++++ .../config/gasSchedules/gasScheduleV3.toml | 5 ++++ .../config/gasSchedules/gasScheduleV4.toml | 5 ++++ .../config/gasSchedules/gasScheduleV5.toml | 5 ++++ .../config/gasSchedules/gasScheduleV6.toml | 5 ++++ .../config/gasSchedules/gasScheduleV7.toml | 5 ++++ common/constants.go | 2 +- factory/disabled/globalSettingsHandler.go | 20 +++++++++++++ genesis/process/disabled/disabled_test.go | 2 +- .../disabled/simpleNFTStorageHandler.go | 4 +-- go.mod | 6 ++-- go.sum | 12 ++++---- .../vm/esdt/process/esdtProcess_test.go | 2 +- .../builtInFunctions/factory_test.go | 7 ++++- process/smartContract/hooks/blockChainHook.go | 2 +- testscommon/esdtStorageHandlerStub.go | 30 +++++++++++++++---- testscommon/simpleNFTStorageHandlerStub.go | 4 +-- vm/systemSmartContracts/defaults/gasMap.go | 5 ++++ 19 files changed, 108 insertions(+), 23 deletions(-) diff --git a/cmd/node/config/gasSchedules/gasScheduleV1.toml b/cmd/node/config/gasSchedules/gasScheduleV1.toml index 52175a228ee..74ace962f97 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV1.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV1.toml @@ -15,6 +15,11 @@ ESDTNFTAddUri = 500000 ESDTNFTUpdateAttributes = 500000 ESDTNFTMultiTransfer = 1000000 + ESDTModifyRoyalties = 500000 + ESDTModifyCreator = 500000 + ESDTNFTRecreate = 1000000 + ESDTNFTUpdate = 1000000 + ESDTNFTSetNewURIs = 500000 SetGuardian = 250000 GuardAccount = 250000 UnGuardAccount = 250000 diff --git a/cmd/node/config/gasSchedules/gasScheduleV2.toml b/cmd/node/config/gasSchedules/gasScheduleV2.toml index 38157aebf7a..8a75c1aad5c 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV2.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV2.toml @@ -15,6 +15,11 @@ ESDTNFTAddUri = 500000 ESDTNFTUpdateAttributes = 500000 ESDTNFTMultiTransfer = 1000000 + ESDTModifyRoyalties = 500000 + ESDTModifyCreator = 500000 + ESDTNFTRecreate = 1000000 + ESDTNFTUpdate = 1000000 + ESDTNFTSetNewURIs = 500000 SetGuardian = 250000 GuardAccount = 250000 UnGuardAccount = 250000 diff --git a/cmd/node/config/gasSchedules/gasScheduleV3.toml b/cmd/node/config/gasSchedules/gasScheduleV3.toml index 3767f02833b..49590fb0459 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV3.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV3.toml @@ -15,6 +15,11 @@ ESDTNFTAddUri = 500000 ESDTNFTUpdateAttributes = 500000 ESDTNFTMultiTransfer = 1000000 + ESDTModifyRoyalties = 500000 + ESDTModifyCreator = 500000 + ESDTNFTRecreate = 1000000 + ESDTNFTUpdate = 1000000 + ESDTNFTSetNewURIs = 500000 SetGuardian = 250000 GuardAccount = 250000 UnGuardAccount = 250000 diff --git a/cmd/node/config/gasSchedules/gasScheduleV4.toml b/cmd/node/config/gasSchedules/gasScheduleV4.toml index f7d8e3a0a1f..5b4542b05a8 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV4.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV4.toml @@ -15,6 +15,11 @@ ESDTNFTAddUri = 50000 ESDTNFTUpdateAttributes = 50000 ESDTNFTMultiTransfer = 200000 + ESDTModifyRoyalties = 500000 + ESDTModifyCreator = 500000 + ESDTNFTRecreate = 1000000 + ESDTNFTUpdate = 1000000 + ESDTNFTSetNewURIs = 500000 SetGuardian = 250000 GuardAccount = 250000 UnGuardAccount = 250000 diff --git a/cmd/node/config/gasSchedules/gasScheduleV5.toml b/cmd/node/config/gasSchedules/gasScheduleV5.toml index 9e2b3ae7d2a..30c967750d4 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV5.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV5.toml @@ -15,6 +15,11 @@ ESDTNFTAddUri = 50000 ESDTNFTUpdateAttributes = 50000 ESDTNFTMultiTransfer = 200000 + ESDTModifyRoyalties = 500000 + ESDTModifyCreator = 500000 + ESDTNFTRecreate = 1000000 + ESDTNFTUpdate = 1000000 + ESDTNFTSetNewURIs = 500000 SetGuardian = 250000 GuardAccount = 250000 UnGuardAccount = 250000 diff --git a/cmd/node/config/gasSchedules/gasScheduleV6.toml b/cmd/node/config/gasSchedules/gasScheduleV6.toml index 82c658a151a..d91cb12e75c 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV6.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV6.toml @@ -15,6 +15,11 @@ ESDTNFTAddUri = 50000 ESDTNFTUpdateAttributes = 50000 ESDTNFTMultiTransfer = 200000 + ESDTModifyRoyalties = 500000 + ESDTModifyCreator = 500000 + ESDTNFTRecreate = 1000000 + ESDTNFTUpdate = 1000000 + ESDTNFTSetNewURIs = 500000 SetGuardian = 250000 GuardAccount = 250000 UnGuardAccount = 250000 diff --git a/cmd/node/config/gasSchedules/gasScheduleV7.toml b/cmd/node/config/gasSchedules/gasScheduleV7.toml index f3930be81a1..0ecf7ec4bea 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV7.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV7.toml @@ -16,6 +16,11 @@ ESDTNFTUpdateAttributes = 50000 ESDTNFTMultiTransfer = 200000 MultiESDTNFTTransfer = 200000 # should be the same value with the ESDTNFTMultiTransfer + ESDTModifyRoyalties = 500000 + ESDTModifyCreator = 500000 + ESDTNFTRecreate = 1000000 + ESDTNFTUpdate = 1000000 + ESDTNFTSetNewURIs = 500000 SetGuardian = 250000 GuardAccount = 250000 UnGuardAccount = 250000 diff --git a/common/constants.go b/common/constants.go index ae902d18455..08e9b26fd3b 100644 --- a/common/constants.go +++ b/common/constants.go @@ -999,6 +999,6 @@ const ( NFTStopCreateFlag core.EnableEpochFlag = "NFTStopCreateFlag" FixGasRemainingForSaveKeyValueFlag core.EnableEpochFlag = "FixGasRemainingForSaveKeyValueFlag" IsChangeOwnerAddressCrossShardThroughSCFlag core.EnableEpochFlag = "IsChangeOwnerAddressCrossShardThroughSCFlag" - DynamicESDTFlag core.EnableEpochFlag = "DynamicESDTFlag" + DynamicESDTFlag core.EnableEpochFlag = "DynamicEsdtFlag" // all new flags must be added to createAllFlagsMap method, as part of enableEpochsHandler allFlagsDefined ) diff --git a/factory/disabled/globalSettingsHandler.go b/factory/disabled/globalSettingsHandler.go index 6a950fd17b2..4990c1032fb 100644 --- a/factory/disabled/globalSettingsHandler.go +++ b/factory/disabled/globalSettingsHandler.go @@ -7,6 +7,26 @@ func NewDisabledGlobalSettingHandler() *disabledGlobalSettingsHandler { return &disabledGlobalSettingsHandler{} } +// IsBurnForAll returns false as this is a disabled component +func (d *disabledGlobalSettingsHandler) IsBurnForAll(_ []byte) bool { + return false +} + +// IsSenderOrDestinationWithTransferRole returns false as this is a disabled component +func (d *disabledGlobalSettingsHandler) IsSenderOrDestinationWithTransferRole(_, _, _ []byte) bool { + return false +} + +// GetTokenType returns 0 as this is a disabled component +func (d *disabledGlobalSettingsHandler) GetTokenType(_ []byte) (uint32, error) { + return 0, nil +} + +// SetTokenType does nothing as this is a disabled component +func (d *disabledGlobalSettingsHandler) SetTokenType(_ []byte, _ uint32) error { + return nil +} + // IsPaused returns false as this is a disabled component func (d *disabledGlobalSettingsHandler) IsPaused(_ []byte) bool { return false diff --git a/genesis/process/disabled/disabled_test.go b/genesis/process/disabled/disabled_test.go index 746ac02b57f..487a17c5af3 100644 --- a/genesis/process/disabled/disabled_test.go +++ b/genesis/process/disabled/disabled_test.go @@ -294,7 +294,7 @@ func TestSimpleNFTStorage(t *testing.T) { require.Equal(t, &esdt.ESDigitalToken{Value: big.NewInt(0)}, token) require.True(t, ok) require.Nil(t, err) - require.Nil(t, handler.SaveNFTMetaDataToSystemAccount(nil)) + require.Nil(t, handler.SaveNFTMetaData(nil)) require.False(t, handler.IsInterfaceNil()) } diff --git a/genesis/process/disabled/simpleNFTStorageHandler.go b/genesis/process/disabled/simpleNFTStorageHandler.go index 46534d07b56..d954a4fdd15 100644 --- a/genesis/process/disabled/simpleNFTStorageHandler.go +++ b/genesis/process/disabled/simpleNFTStorageHandler.go @@ -17,8 +17,8 @@ func (s *SimpleNFTStorage) GetESDTNFTTokenOnDestination(_ vmcommon.UserAccountHa return &esdt.ESDigitalToken{Value: big.NewInt(0)}, true, nil } -// SaveNFTMetaDataToSystemAccount is disabled -func (s *SimpleNFTStorage) SaveNFTMetaDataToSystemAccount(_ data.TransactionHandler) error { +// SaveNFTMetaData is disabled +func (s *SimpleNFTStorage) SaveNFTMetaData(_ data.TransactionHandler) error { return nil } diff --git a/go.mod b/go.mod index 9f27d2e1ffd..5765b631da5 100644 --- a/go.mod +++ b/go.mod @@ -14,14 +14,14 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.13-0.20231129114230-d280af707381 - github.com/multiversx/mx-chain-core-go v1.2.19-0.20231214115026-a1e7279b14f1 + github.com/multiversx/mx-chain-core-go v1.2.19-0.20240105094030-b25d8b81919f github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231129101537-ef355850e34b github.com/multiversx/mx-chain-es-indexer-go v1.4.18-0.20231228064619-e3b0caf29058 github.com/multiversx/mx-chain-logger-go v1.0.14-0.20231215125130-a3bed6e76040 github.com/multiversx/mx-chain-scenario-go v1.2.2-0.20231129113427-ad3056f45296 github.com/multiversx/mx-chain-storage-go v1.0.15-0.20231213110622-e222ba96a9f4 - github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20231228070003-ae14e1e0adfa - github.com/multiversx/mx-chain-vm-go v1.5.23-0.20231228064104-964359cb8dd3 + github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20240105114227-1a61e5ae314f + github.com/multiversx/mx-chain-vm-go v1.5.23-0.20240105130527-2449f64b670c github.com/multiversx/mx-chain-vm-v1_2-go v1.2.65-0.20231228071026-eed2cb19c216 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.66-0.20231228071108-6b89bcebab14 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.92-0.20231228071246-c1b45eae5955 diff --git a/go.sum b/go.sum index 0375c025713..0811d720615 100644 --- a/go.sum +++ b/go.sum @@ -386,8 +386,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20231129114230-d280af707381 h1:M4JNeubA+zq7NaH2LP5YsWUVeKn9hNL+HgSw2kqwWUc= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20231129114230-d280af707381/go.mod h1:n4E8BWIV0g3AcNGe1gf+vcjUC8A2QCJ4ARQSbiUDGrI= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20231214115026-a1e7279b14f1 h1:8rz1ZpRAsWVxSEBy7PJIUStQMKiHs3I4mvpRmHUpsbI= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20231214115026-a1e7279b14f1/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.19-0.20240105094030-b25d8b81919f h1:Ki7amU7Bw8yT2Hjx8Z/9Q96TEl3jI86XN3Hs53WGXzM= +github.com/multiversx/mx-chain-core-go v1.2.19-0.20240105094030-b25d8b81919f/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231129101537-ef355850e34b h1:TIE6it719ZIW0E1bFgPAgE+U3zPSkPfAloFYEIeOL3U= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231129101537-ef355850e34b/go.mod h1:Ap6p7QZFtwPlb++OvCG+85BfuZ+bLP/JtQp6EwjWJsI= github.com/multiversx/mx-chain-es-indexer-go v1.4.18-0.20231228064619-e3b0caf29058 h1:6XH7ua4vUqhbE4NMzs8K63b7A/9KMO4H8XZfYjyy778= @@ -398,10 +398,10 @@ github.com/multiversx/mx-chain-scenario-go v1.2.2-0.20231129113427-ad3056f45296 github.com/multiversx/mx-chain-scenario-go v1.2.2-0.20231129113427-ad3056f45296/go.mod h1:WocyahfHCC3oGILEVdRe7I4/+q/TLCORoTo1X4wGmF4= github.com/multiversx/mx-chain-storage-go v1.0.15-0.20231213110622-e222ba96a9f4 h1:2RJ6T31pLN75l4xfhTicGZ+gVOPMxSGPip+O1XYVYac= github.com/multiversx/mx-chain-storage-go v1.0.15-0.20231213110622-e222ba96a9f4/go.mod h1:ioCT2oHQ+TyHQYpgjxzlUdy7dCdv56+w5HnBg9z96eY= -github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20231228070003-ae14e1e0adfa h1:xdDeUC4yOfiUwctkYioYMjjigBZoZo5RZq1e5WoCVRs= -github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20231228070003-ae14e1e0adfa/go.mod h1:7jjGRykSfLeMs6iQdszlE0lGK2xp9/cctiVdeKbQLLM= -github.com/multiversx/mx-chain-vm-go v1.5.23-0.20231228064104-964359cb8dd3 h1:qfzeTPI2oSgxnw52KiVWc2fHMem6FZIkX1Azwy64098= -github.com/multiversx/mx-chain-vm-go v1.5.23-0.20231228064104-964359cb8dd3/go.mod h1:4kcpwq70UB3Clnc6Q0krGA8hgQ26JTQpmCP+4y5aiV0= +github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20240105114227-1a61e5ae314f h1:5SWqjdla1dN7W3ZN4nxxstpdG/AAnnjkhS610KqKa6U= +github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20240105114227-1a61e5ae314f/go.mod h1:Ffw0k3D4Q1SzwPwgWW+IZMr9TxhM7I6PnB5Cuf96Tm8= +github.com/multiversx/mx-chain-vm-go v1.5.23-0.20240105130527-2449f64b670c h1:Wy88j2BpOreciJ9zr52sWsEUzflYKGIkzymTtSsl4YE= +github.com/multiversx/mx-chain-vm-go v1.5.23-0.20240105130527-2449f64b670c/go.mod h1:yYYsJNMoDcs+WswhLg/0oHBcrNe2zZKllbcvWH9XeOw= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.65-0.20231228071026-eed2cb19c216 h1:CDSn4hgiGwoOSSLmajgOvjdoRxfJSXjEu/CfXiqihwo= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.65-0.20231228071026-eed2cb19c216/go.mod h1:h87SKR/p66XP0Er2Mx2KfjzS6mLmW6l3tDWyO1oNr94= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.66-0.20231228071108-6b89bcebab14 h1:7r2zQiAfqGjN7U8j5obXIoRSh+vnoupBhxBgQGUA2ck= diff --git a/integrationTests/vm/esdt/process/esdtProcess_test.go b/integrationTests/vm/esdt/process/esdtProcess_test.go index cee94a6132b..470280c2f81 100644 --- a/integrationTests/vm/esdt/process/esdtProcess_test.go +++ b/integrationTests/vm/esdt/process/esdtProcess_test.go @@ -375,7 +375,7 @@ func TestESDTIssueFromASmartContractSimulated(t *testing.T) { interimProc, _ := metaNode.InterimProcContainer.Get(block.SmartContractResultBlock) mapCreatedSCRs := interimProc.GetAllCurrentFinishedTxs() - require.Equal(t, len(mapCreatedSCRs), 2) + require.Equal(t, len(mapCreatedSCRs), 3) foundTransfer := false for _, addedSCR := range mapCreatedSCRs { foundTransfer = foundTransfer || strings.Contains(string(addedSCR.GetData()), core.BuiltInFunctionESDTTransfer) diff --git a/process/smartContract/builtInFunctions/factory_test.go b/process/smartContract/builtInFunctions/factory_test.go index abf71000038..81f62c7085a 100644 --- a/process/smartContract/builtInFunctions/factory_test.go +++ b/process/smartContract/builtInFunctions/factory_test.go @@ -88,6 +88,11 @@ func fillGasMapBuiltInCosts(value uint64) map[string]uint64 { gasMap["ESDTNFTAddUri"] = value gasMap["ESDTNFTUpdateAttributes"] = value gasMap["ESDTNFTMultiTransfer"] = value + gasMap["ESDTModifyRoyalties"] = value + gasMap["ESDTModifyCreator"] = value + gasMap["ESDTNFTRecreate"] = value + gasMap["ESDTNFTUpdate"] = value + gasMap["ESDTNFTSetNewURIs"] = value gasMap["SetGuardian"] = value gasMap["GuardAccount"] = value gasMap["TrieLoadPerNode"] = value @@ -168,7 +173,7 @@ func TestCreateBuiltInFunctionContainer(t *testing.T) { args := createMockArguments() builtInFuncFactory, err := CreateBuiltInFunctionsFactory(args) assert.Nil(t, err) - assert.Equal(t, 36, len(builtInFuncFactory.BuiltInFunctionContainer().Keys())) + assert.Equal(t, 42, len(builtInFuncFactory.BuiltInFunctionContainer().Keys())) err = builtInFuncFactory.SetPayableHandler(&testscommon.BlockChainHookStub{}) assert.Nil(t, err) diff --git a/process/smartContract/hooks/blockChainHook.go b/process/smartContract/hooks/blockChainHook.go index 827d08da435..8a2df4dfad8 100644 --- a/process/smartContract/hooks/blockChainHook.go +++ b/process/smartContract/hooks/blockChainHook.go @@ -525,7 +525,7 @@ func (bh *BlockChainHookImpl) processMaxBuiltInCounters(input *vmcommon.Contract // SaveNFTMetaDataToSystemAccount will save NFT meta-data to system account for the given transaction func (bh *BlockChainHookImpl) SaveNFTMetaDataToSystemAccount(tx data.TransactionHandler) error { - return bh.nftStorageHandler.SaveNFTMetaDataToSystemAccount(tx) + return bh.nftStorageHandler.SaveNFTMetaData(tx) } // GetShardOfAddress is the hook that returns the shard of a given address diff --git a/testscommon/esdtStorageHandlerStub.go b/testscommon/esdtStorageHandlerStub.go index 781e2b33fcc..f41c0fb382a 100644 --- a/testscommon/esdtStorageHandlerStub.go +++ b/testscommon/esdtStorageHandlerStub.go @@ -15,8 +15,28 @@ type EsdtStorageHandlerStub struct { GetESDTNFTTokenOnDestinationCalled func(acnt vmcommon.UserAccountHandler, esdtTokenKey []byte, nonce uint64) (*esdt.ESDigitalToken, bool, error) GetESDTNFTTokenOnDestinationWithCustomSystemAccountCalled func(accnt vmcommon.UserAccountHandler, esdtTokenKey []byte, nonce uint64, systemAccount vmcommon.UserAccountHandler) (*esdt.ESDigitalToken, bool, error) WasAlreadySentToDestinationShardAndUpdateStateCalled func(tickerID []byte, nonce uint64, dstAddress []byte) (bool, error) - SaveNFTMetaDataToSystemAccountCalled func(tx data.TransactionHandler) error + SaveNFTMetaDataCalled func(tx data.TransactionHandler) error AddToLiquiditySystemAccCalled func(esdtTokenKey []byte, nonce uint64, transferValue *big.Int) error + SaveMetaDataToSystemAccountCalled func(tokenKey []byte, nonce uint64, esdtData *esdt.ESDigitalToken) error + GetMetaDataFromSystemAccountCalled func(bytes []byte, u uint64) (*esdt.MetaData, error) +} + +// SaveMetaDataToSystemAccount - +func (e *EsdtStorageHandlerStub) SaveMetaDataToSystemAccount(tokenKey []byte, nonce uint64, esdtData *esdt.ESDigitalToken) error { + if e.SaveMetaDataToSystemAccountCalled != nil { + return e.SaveMetaDataToSystemAccountCalled(tokenKey, nonce, esdtData) + } + + return nil +} + +// GetMetaDataFromSystemAccount - +func (e *EsdtStorageHandlerStub) GetMetaDataFromSystemAccount(bytes []byte, u uint64) (*esdt.MetaData, error) { + if e.GetMetaDataFromSystemAccountCalled != nil { + return e.GetMetaDataFromSystemAccountCalled(bytes, u) + } + + return nil, nil } // SaveESDTNFTToken - @@ -64,10 +84,10 @@ func (e *EsdtStorageHandlerStub) WasAlreadySentToDestinationShardAndUpdateState( return false, nil } -// SaveNFTMetaDataToSystemAccount - -func (e *EsdtStorageHandlerStub) SaveNFTMetaDataToSystemAccount(tx data.TransactionHandler) error { - if e.SaveNFTMetaDataToSystemAccountCalled != nil { - return e.SaveNFTMetaDataToSystemAccountCalled(tx) +// SaveNFTMetaData - +func (e *EsdtStorageHandlerStub) SaveNFTMetaData(tx data.TransactionHandler) error { + if e.SaveNFTMetaDataCalled != nil { + return e.SaveNFTMetaDataCalled(tx) } return nil diff --git a/testscommon/simpleNFTStorageHandlerStub.go b/testscommon/simpleNFTStorageHandlerStub.go index 7e5fdcf1d8c..d12aabc9f4c 100644 --- a/testscommon/simpleNFTStorageHandlerStub.go +++ b/testscommon/simpleNFTStorageHandlerStub.go @@ -22,8 +22,8 @@ func (s *SimpleNFTStorageHandlerStub) GetESDTNFTTokenOnDestination(accnt vmcommo return &esdt.ESDigitalToken{Value: big.NewInt(0)}, true, nil } -// SaveNFTMetaDataToSystemAccount - -func (s *SimpleNFTStorageHandlerStub) SaveNFTMetaDataToSystemAccount(tx data.TransactionHandler) error { +// SaveNFTMetaData - +func (s *SimpleNFTStorageHandlerStub) SaveNFTMetaData(tx data.TransactionHandler) error { if s.SaveNFTMetaDataToSystemAccountCalled != nil { return s.SaveNFTMetaDataToSystemAccountCalled(tx) } diff --git a/vm/systemSmartContracts/defaults/gasMap.go b/vm/systemSmartContracts/defaults/gasMap.go index 822b61b3651..27f3fcc5973 100644 --- a/vm/systemSmartContracts/defaults/gasMap.go +++ b/vm/systemSmartContracts/defaults/gasMap.go @@ -47,6 +47,11 @@ func FillGasMapBuiltInCosts(value uint64) map[string]uint64 { gasMap["ESDTNFTAddUri"] = value gasMap["ESDTNFTUpdateAttributes"] = value gasMap["ESDTNFTMultiTransfer"] = value + gasMap["ESDTModifyRoyalties"] = value + gasMap["ESDTModifyCreator"] = value + gasMap["ESDTNFTRecreate"] = value + gasMap["ESDTNFTUpdate"] = value + gasMap["ESDTNFTSetNewURIs"] = value gasMap["SetGuardian"] = value gasMap["GuardAccount"] = value gasMap["UnGuardAccount"] = value From 312669f5221b96c1acb2b95012424e1a33321b86 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Mon, 8 Jan 2024 16:14:00 +0200 Subject: [PATCH 036/503] fix nft liquidity --- go.mod | 2 +- go.sum | 4 +- testscommon/esdtStorageHandlerStub.go | 6 +- vm/systemSmartContracts/esdt.go | 86 ++++++++++----------------- vm/systemSmartContracts/esdt_test.go | 20 +++---- 5 files changed, 47 insertions(+), 71 deletions(-) diff --git a/go.mod b/go.mod index 5765b631da5..3fef883e6f7 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/multiversx/mx-chain-logger-go v1.0.14-0.20231215125130-a3bed6e76040 github.com/multiversx/mx-chain-scenario-go v1.2.2-0.20231129113427-ad3056f45296 github.com/multiversx/mx-chain-storage-go v1.0.15-0.20231213110622-e222ba96a9f4 - github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20240105114227-1a61e5ae314f + github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20240108121115-031146aa432e github.com/multiversx/mx-chain-vm-go v1.5.23-0.20240105130527-2449f64b670c github.com/multiversx/mx-chain-vm-v1_2-go v1.2.65-0.20231228071026-eed2cb19c216 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.66-0.20231228071108-6b89bcebab14 diff --git a/go.sum b/go.sum index 0811d720615..efd53f6aa73 100644 --- a/go.sum +++ b/go.sum @@ -398,8 +398,8 @@ github.com/multiversx/mx-chain-scenario-go v1.2.2-0.20231129113427-ad3056f45296 github.com/multiversx/mx-chain-scenario-go v1.2.2-0.20231129113427-ad3056f45296/go.mod h1:WocyahfHCC3oGILEVdRe7I4/+q/TLCORoTo1X4wGmF4= github.com/multiversx/mx-chain-storage-go v1.0.15-0.20231213110622-e222ba96a9f4 h1:2RJ6T31pLN75l4xfhTicGZ+gVOPMxSGPip+O1XYVYac= github.com/multiversx/mx-chain-storage-go v1.0.15-0.20231213110622-e222ba96a9f4/go.mod h1:ioCT2oHQ+TyHQYpgjxzlUdy7dCdv56+w5HnBg9z96eY= -github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20240105114227-1a61e5ae314f h1:5SWqjdla1dN7W3ZN4nxxstpdG/AAnnjkhS610KqKa6U= -github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20240105114227-1a61e5ae314f/go.mod h1:Ffw0k3D4Q1SzwPwgWW+IZMr9TxhM7I6PnB5Cuf96Tm8= +github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20240108121115-031146aa432e h1:S+wqm2+poGUtxg8kOVrumFASZQNgFZdxcC7FZY9AwEI= +github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20240108121115-031146aa432e/go.mod h1:Ffw0k3D4Q1SzwPwgWW+IZMr9TxhM7I6PnB5Cuf96Tm8= github.com/multiversx/mx-chain-vm-go v1.5.23-0.20240105130527-2449f64b670c h1:Wy88j2BpOreciJ9zr52sWsEUzflYKGIkzymTtSsl4YE= github.com/multiversx/mx-chain-vm-go v1.5.23-0.20240105130527-2449f64b670c/go.mod h1:yYYsJNMoDcs+WswhLg/0oHBcrNe2zZKllbcvWH9XeOw= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.65-0.20231228071026-eed2cb19c216 h1:CDSn4hgiGwoOSSLmajgOvjdoRxfJSXjEu/CfXiqihwo= diff --git a/testscommon/esdtStorageHandlerStub.go b/testscommon/esdtStorageHandlerStub.go index f41c0fb382a..1a1af038e4e 100644 --- a/testscommon/esdtStorageHandlerStub.go +++ b/testscommon/esdtStorageHandlerStub.go @@ -16,7 +16,7 @@ type EsdtStorageHandlerStub struct { GetESDTNFTTokenOnDestinationWithCustomSystemAccountCalled func(accnt vmcommon.UserAccountHandler, esdtTokenKey []byte, nonce uint64, systemAccount vmcommon.UserAccountHandler) (*esdt.ESDigitalToken, bool, error) WasAlreadySentToDestinationShardAndUpdateStateCalled func(tickerID []byte, nonce uint64, dstAddress []byte) (bool, error) SaveNFTMetaDataCalled func(tx data.TransactionHandler) error - AddToLiquiditySystemAccCalled func(esdtTokenKey []byte, nonce uint64, transferValue *big.Int) error + AddToLiquiditySystemAccCalled func(esdtTokenKey []byte, tokenType uint32, nonce uint64, transferValue *big.Int) error SaveMetaDataToSystemAccountCalled func(tokenKey []byte, nonce uint64, esdtData *esdt.ESDigitalToken) error GetMetaDataFromSystemAccountCalled func(bytes []byte, u uint64) (*esdt.MetaData, error) } @@ -94,9 +94,9 @@ func (e *EsdtStorageHandlerStub) SaveNFTMetaData(tx data.TransactionHandler) err } // AddToLiquiditySystemAcc - -func (e *EsdtStorageHandlerStub) AddToLiquiditySystemAcc(esdtTokenKey []byte, nonce uint64, transferValue *big.Int) error { +func (e *EsdtStorageHandlerStub) AddToLiquiditySystemAcc(esdtTokenKey []byte, tokenType uint32, nonce uint64, transferValue *big.Int) error { if e.AddToLiquiditySystemAccCalled != nil { - return e.AddToLiquiditySystemAccCalled(esdtTokenKey, nonce, transferValue) + return e.AddToLiquiditySystemAccCalled(esdtTokenKey, tokenType, nonce, transferValue) } return nil diff --git a/vm/systemSmartContracts/esdt.go b/vm/systemSmartContracts/esdt.go index cff0f1e62b8..5c8137739d2 100644 --- a/vm/systemSmartContracts/esdt.go +++ b/vm/systemSmartContracts/esdt.go @@ -44,30 +44,6 @@ const upgradeProperties = "upgradeProperties" const conversionBase = 10 -// TODO move to core-go -const metaESDT = "MetaESDT" -const nonFungibleV2 = "NonFungibleESDTV2" - -const dynamic = "dynamic" -const dynamicNFT = dynamic + nonFungibleV2 -const dynamicSFT = dynamic + core.SemiFungibleESDT -const dynamicMetaESDT = dynamic + metaESDT - -// ESDTSetTokenType represents the builtin function name to set token type -const ESDTSetTokenType = "ESDTSetTokenType" - -// ESDTRoleSetNewURI represents the role which can rewrite the URI in the token metadata -const ESDTRoleSetNewURI = "ESDTRoleSetNewURI" - -// ESDTRoleModifyRoyalties represents the role which can rewrite the royalties of a token -const ESDTRoleModifyRoyalties = "ESDTRoleModifyRoyalties" - -// ESDTRoleModifyCreator represents the role which can rewrite the creator in the token metadata -const ESDTRoleModifyCreator = "ESDTRoleModifyCreator" - -// ESDTRoleNFTRecreate represents the role which can recreate the token metadata -const ESDTRoleNFTRecreate = "ESDTRoleNFTRecreate" - type esdt struct { eei vm.SystemEI gasCost vm.GasCost @@ -380,7 +356,7 @@ func (e *esdt) registerNonFungible(args *vmcommon.ContractCallInput) vmcommon.Re tokenType := []byte(core.NonFungibleESDT) if e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) { - tokenType = []byte(nonFungibleV2) + tokenType = []byte(core.NonFungibleESDTv2) } tokenIdentifier, _, err := e.createNewToken( @@ -473,7 +449,7 @@ func (e *esdt) registerMetaESDT(args *vmcommon.ContractCallInput) vmcommon.Retur big.NewInt(0), numOfDecimals, args.Arguments[3:], - []byte(metaESDT)) + []byte(core.MetaESDT)) if err != nil { e.eei.AddReturnMessage(err.Error()) return vmcommon.UserError @@ -484,7 +460,7 @@ func (e *esdt) registerMetaESDT(args *vmcommon.ContractCallInput) vmcommon.Retur logEntry := &vmcommon.LogEntry{ Identifier: []byte(args.Function), Address: args.CallerAddr, - Topics: [][]byte{tokenIdentifier, args.Arguments[0], args.Arguments[1], []byte(metaESDT), big.NewInt(int64(numOfDecimals)).Bytes()}, + Topics: [][]byte{tokenIdentifier, args.Arguments[0], args.Arguments[1], []byte(core.MetaESDT), big.NewInt(int64(numOfDecimals)).Bytes()}, } e.eei.AddLogEntry(logEntry) @@ -574,20 +550,20 @@ func (e *esdt) registerAndSetRoles(args *vmcommon.ContractCallInput) vmcommon.Re func (e *esdt) getAllRolesForTokenType(tokenType string) ([][]byte, error) { switch tokenType { - case core.NonFungibleESDT, nonFungibleV2, dynamicNFT: + case core.NonFungibleESDT, core.NonFungibleESDTv2, core.DynamicNFTESDT: nftRoles := [][]byte{[]byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleNFTBurn), []byte(core.ESDTRoleNFTUpdateAttributes), []byte(core.ESDTRoleNFTAddURI)} if e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) { - nftRoles = append(nftRoles, [][]byte{[]byte(ESDTRoleNFTRecreate), []byte(ESDTRoleModifyCreator), []byte(ESDTRoleModifyRoyalties), []byte(ESDTRoleSetNewURI)}...) + nftRoles = append(nftRoles, [][]byte{[]byte(core.ESDTRoleNFTRecreate), []byte(core.ESDTRoleModifyCreator), []byte(core.ESDTRoleModifyRoyalties), []byte(core.ESDTRoleSetNewURI)}...) } return nftRoles, nil - case core.SemiFungibleESDT, metaESDT: + case core.SemiFungibleESDT, core.MetaESDT: return [][]byte{[]byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleNFTBurn), []byte(core.ESDTRoleNFTAddQuantity)}, nil case core.FungibleESDT: return [][]byte{[]byte(core.ESDTRoleLocalMint), []byte(core.ESDTRoleLocalBurn)}, nil - case dynamicSFT, dynamicMetaESDT: + case core.DynamicSFTESDT, core.DynamicMetaESDT: dynamicRoles := [][]byte{[]byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleNFTBurn), []byte(core.ESDTRoleNFTAddQuantity), []byte(core.ESDTRoleNFTUpdateAttributes), []byte(core.ESDTRoleNFTAddURI)} - dynamicRoles = append(dynamicRoles, [][]byte{[]byte(ESDTRoleNFTRecreate), []byte(ESDTRoleModifyCreator), []byte(ESDTRoleModifyRoyalties), []byte(ESDTRoleSetNewURI)}...) + dynamicRoles = append(dynamicRoles, [][]byte{[]byte(core.ESDTRoleNFTRecreate), []byte(core.ESDTRoleModifyCreator), []byte(core.ESDTRoleModifyRoyalties), []byte(core.ESDTRoleSetNewURI)}...) return dynamicRoles, nil } @@ -600,13 +576,13 @@ func (e *esdt) getTokenType(compressed []byte) (bool, []byte, error) { switch string(compressed) { case "NFT": if e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) { - return false, []byte(nonFungibleV2), nil + return false, []byte(core.NonFungibleESDTv2), nil } return false, []byte(core.NonFungibleESDT), nil case "SFT": return false, []byte(core.SemiFungibleESDT), nil case "META": - return true, []byte(metaESDT), nil + return true, []byte(core.MetaESDT), nil case "FNG": return true, []byte(core.FungibleESDT), nil } @@ -642,7 +618,7 @@ func (e *esdt) changeSFTToMetaESDT(args *vmcommon.ContractCallInput) vmcommon.Re return vmcommon.UserError } - token.TokenType = []byte(metaESDT) + token.TokenType = []byte(core.MetaESDT) token.NumDecimals = numOfDecimals err := e.saveToken(args.Arguments[0], token) if err != nil { @@ -653,7 +629,7 @@ func (e *esdt) changeSFTToMetaESDT(args *vmcommon.ContractCallInput) vmcommon.Re logEntry := &vmcommon.LogEntry{ Identifier: []byte(args.Function), Address: args.CallerAddr, - Topics: [][]byte{args.Arguments[0], token.TokenName, token.TickerName, []byte(metaESDT), args.Arguments[1]}, + Topics: [][]byte{args.Arguments[0], token.TokenName, token.TickerName, []byte(core.MetaESDT), args.Arguments[1]}, } e.eei.AddLogEntry(logEntry) @@ -1638,22 +1614,22 @@ func (e *esdt) isSpecialRoleValidForNonFungible(argument string) error { return nil } return vm.ErrInvalidArgument - case ESDTRoleSetNewURI: + case core.ESDTRoleSetNewURI: if e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) { return nil } return vm.ErrInvalidArgument - case ESDTRoleModifyCreator: + case core.ESDTRoleModifyCreator: if e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) { return nil } return vm.ErrInvalidArgument - case ESDTRoleModifyRoyalties: + case core.ESDTRoleModifyRoyalties: if e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) { return nil } return vm.ErrInvalidArgument - case ESDTRoleNFTRecreate: + case core.ESDTRoleNFTRecreate: if e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) { return nil } @@ -1675,13 +1651,13 @@ func (e *esdt) isSpecialRoleValidForDynamicNFT(argument string) error { return nil case core.ESDTRoleNFTAddURI: return nil - case ESDTRoleSetNewURI: + case core.ESDTRoleSetNewURI: return nil - case ESDTRoleModifyCreator: + case core.ESDTRoleModifyCreator: return nil - case ESDTRoleModifyRoyalties: + case core.ESDTRoleModifyRoyalties: return nil - case ESDTRoleNFTRecreate: + case core.ESDTRoleNFTRecreate: return nil default: return vm.ErrInvalidArgument @@ -1705,18 +1681,18 @@ func (e *esdt) checkSpecialRolesAccordingToTokenType(args [][]byte, token *ESDTD switch string(token.TokenType) { case core.FungibleESDT: return validateRoles(args, e.isSpecialRoleValidForFungible) - case core.NonFungibleESDT, nonFungibleV2: + case core.NonFungibleESDT, core.NonFungibleESDTv2: return validateRoles(args, e.isSpecialRoleValidForNonFungible) case core.SemiFungibleESDT: return validateRoles(args, e.isSpecialRoleValidForSemiFungible) - case metaESDT: + case core.MetaESDT: isCheckMetaESDTOnRolesFlagEnabled := e.enableEpochsHandler.IsFlagEnabled(common.ManagedCryptoAPIsFlag) if isCheckMetaESDTOnRolesFlagEnabled { return validateRoles(args, e.isSpecialRoleValidForSemiFungible) } - case dynamicNFT: + case core.DynamicNFTESDT: return validateRoles(args, e.isSpecialRoleValidForDynamicNFT) - case dynamicSFT, dynamicMetaESDT: + case core.DynamicSFTESDT, core.DynamicMetaESDT: return validateRoles(args, e.isSpecialRoleValidForDynamicSFT) } return nil @@ -1784,17 +1760,17 @@ func (e *esdt) changeToMultiShardCreate(args *vmcommon.ContractCallInput) vmcomm } func isDynamicTokenType(tokenType []byte) bool { - prefixLength := len(dynamic) + prefixLength := len(core.Dynamic) if len(tokenType) < prefixLength { return false } - return bytes.Equal(tokenType[:prefixLength], []byte(dynamic)) + return bytes.Equal(tokenType[:prefixLength], []byte(core.Dynamic)) } func rolesForDynamicWhichHasToBeSingular() []string { return []string{core.ESDTRoleNFTCreate, core.ESDTRoleNFTUpdateAttributes, core.ESDTRoleNFTAddURI, - ESDTRoleSetNewURI, ESDTRoleModifyCreator, ESDTRoleModifyRoyalties, ESDTRoleNFTRecreate} + core.ESDTRoleSetNewURI, core.ESDTRoleModifyCreator, core.ESDTRoleModifyRoyalties, core.ESDTRoleNFTRecreate} } func (e *esdt) checkRolesForDynamicTokens( @@ -2254,7 +2230,7 @@ func (e *esdt) updateTokenID(args *vmcommon.ContractCallInput) vmcommon.ReturnCo tokenID := args.Arguments[0] if bytes.Equal(token.TokenType, []byte(core.NonFungibleESDT)) { - token.TokenType = []byte(nonFungibleV2) + token.TokenType = []byte(core.NonFungibleESDTv2) err := e.saveToken(tokenID, token) if err != nil { e.eei.AddReturnMessage(err.Error()) @@ -2309,7 +2285,7 @@ func (e *esdt) createDynamicToken(args *vmcommon.ContractCallInput) ([]byte, *ES } } - dynamicTokenType := append([]byte(dynamic), tokenType...) + dynamicTokenType := append([]byte(core.Dynamic), tokenType...) tokenIdentifier, token, err := e.createNewToken( args.CallerAddr, @@ -2416,7 +2392,7 @@ func (e *esdt) changeToDynamic(args *vmcommon.ContractCallInput) vmcommon.Return return vmcommon.UserError } - token.TokenType = append([]byte(dynamic), token.TokenType...) + token.TokenType = append([]byte(core.Dynamic), token.TokenType...) err = e.saveToken(args.Arguments[0], token) if err != nil { @@ -2441,7 +2417,7 @@ func (e *esdt) sendTokenTypeToSystemAccounts(caller []byte, tokenID []byte, toke return } - builtInFunc := ESDTSetTokenType + builtInFunc := core.ESDTSetTokenType esdtTransferData := builtInFunc + "@" + hex.EncodeToString(tokenID) + "@" + hex.EncodeToString(token.TokenType) e.eei.SendGlobalSettingToAll(e.eSDTSCAddress, []byte(esdtTransferData)) diff --git a/vm/systemSmartContracts/esdt_test.go b/vm/systemSmartContracts/esdt_test.go index d5d3ef8ca7e..9a6e94d4c8c 100644 --- a/vm/systemSmartContracts/esdt_test.go +++ b/vm/systemSmartContracts/esdt_test.go @@ -4068,7 +4068,7 @@ func TestEsdt_ExecuteChangeSFTToMetaESDT(t *testing.T) { token, _ := e.getExistingToken(vmInput.Arguments[0]) assert.Equal(t, token.NumDecimals, uint32(10)) - assert.Equal(t, token.TokenType, []byte(metaESDT)) + assert.Equal(t, token.TokenType, []byte(core.MetaESDT)) } func TestEsdt_ExecuteIssueSFTAndChangeSFTToMetaESDT(t *testing.T) { @@ -4102,7 +4102,7 @@ func TestEsdt_ExecuteIssueSFTAndChangeSFTToMetaESDT(t *testing.T) { token, _ = e.getExistingToken(fullTicker) assert.Equal(t, token.NumDecimals, uint32(10)) - assert.Equal(t, token.TokenType, []byte(metaESDT)) + assert.Equal(t, token.TokenType, []byte(core.MetaESDT)) output = e.Execute(vmInput) assert.Equal(t, vmcommon.UserError, output) @@ -4236,7 +4236,7 @@ func TestEsdt_ExecuteRegisterAndSetMetaESDTShouldSetType(t *testing.T) { registerAndSetAllRolesWithTypeCheck(t, []byte("NFT"), []byte(core.NonFungibleESDT)) registerAndSetAllRolesWithTypeCheck(t, []byte("SFT"), []byte(core.SemiFungibleESDT)) - registerAndSetAllRolesWithTypeCheck(t, []byte("META"), []byte(metaESDT)) + registerAndSetAllRolesWithTypeCheck(t, []byte("META"), []byte(core.MetaESDT)) registerAndSetAllRolesWithTypeCheck(t, []byte("FNG"), []byte(core.FungibleESDT)) } @@ -4406,11 +4406,11 @@ func TestEsdt_CheckRolesOnMetaESDT(t *testing.T) { args.Eei = eei e, _ := NewESDTSmartContract(args) - err := e.checkSpecialRolesAccordingToTokenType([][]byte{[]byte("random")}, &ESDTDataV2{TokenType: []byte(metaESDT)}) + err := e.checkSpecialRolesAccordingToTokenType([][]byte{[]byte("random")}, &ESDTDataV2{TokenType: []byte(core.MetaESDT)}) assert.Nil(t, err) enableEpochsHandler.AddActiveFlags(common.ManagedCryptoAPIsFlag) - err = e.checkSpecialRolesAccordingToTokenType([][]byte{[]byte("random")}, &ESDTDataV2{TokenType: []byte(metaESDT)}) + err = e.checkSpecialRolesAccordingToTokenType([][]byte{[]byte("random")}, &ESDTDataV2{TokenType: []byte(core.MetaESDT)}) assert.Equal(t, err, vm.ErrInvalidArgument) } @@ -4597,7 +4597,7 @@ func TestEsdt_UpdateTokenID(t *testing.T) { assert.Equal(t, vmcommon.Ok, output) esdtData, _ = e.getExistingToken(vmInput.Arguments[0]) - assert.Equal(t, esdtData.TokenType, []byte(nonFungibleV2)) + assert.Equal(t, esdtData.TokenType, []byte(core.NonFungibleESDTv2)) } func TestEsdt_RegisterDynamic(t *testing.T) { @@ -4762,14 +4762,14 @@ func TestEsdt_ChangeToDynamic(t *testing.T) { assert.Equal(t, vmcommon.UserError, output) assert.True(t, strings.Contains(eei.returnMessage, "cannot change fungible tokens to dynamic")) - esdtData.TokenType = []byte(dynamicMetaESDT) + esdtData.TokenType = []byte(core.DynamicMetaESDT) _ = e.saveToken(vmInput.Arguments[0], esdtData) eei.returnMessage = "" output = e.Execute(vmInput) assert.Equal(t, vmcommon.UserError, output) assert.True(t, strings.Contains(eei.returnMessage, "tokenID is already dynamic")) - esdtData.TokenType = []byte(metaESDT) + esdtData.TokenType = []byte(core.MetaESDT) esdtData.SpecialRoles = append(esdtData.SpecialRoles, &ESDTRoles{Address: vmInput.CallerAddr, Roles: [][]byte{[]byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleNFTUpdateAttributes)}}) esdtData.SpecialRoles = append(esdtData.SpecialRoles, &ESDTRoles{Address: bytes.Repeat([]byte{2}, 32), Roles: [][]byte{[]byte(core.ESDTRoleNFTUpdateAttributes)}}) @@ -4780,12 +4780,12 @@ func TestEsdt_ChangeToDynamic(t *testing.T) { fmt.Println(eei.returnMessage) assert.True(t, strings.Contains(eei.returnMessage, vm.ErrCannotChangeToDynamic.Error())) - esdtData.SpecialRoles[1] = &ESDTRoles{Address: bytes.Repeat([]byte{2}, 32), Roles: [][]byte{[]byte(ESDTRoleNFTRecreate)}} + esdtData.SpecialRoles[1] = &ESDTRoles{Address: bytes.Repeat([]byte{2}, 32), Roles: [][]byte{[]byte(core.ESDTRoleNFTRecreate)}} _ = e.saveToken(vmInput.Arguments[0], esdtData) eei.returnMessage = "" output = e.Execute(vmInput) assert.Equal(t, vmcommon.Ok, output) esdtData, _ = e.getExistingToken(vmInput.Arguments[0]) - assert.True(t, strings.Contains(string(esdtData.TokenType), dynamic)) + assert.True(t, strings.Contains(string(esdtData.TokenType), core.Dynamic)) } From 6f0041d9de1069a2260bdfc2c94af9a4cee20044 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 10 Jan 2024 17:56:11 +0200 Subject: [PATCH 037/503] persister factory in core components --- config/config.go | 12 +++++-- dataRetriever/factory/dataPoolFactory.go | 3 +- epochStart/bootstrap/process.go | 1 + epochStart/bootstrap/storageProcess.go | 1 + epochStart/metachain/systemSCs_test.go | 5 +-- errors/errors.go | 3 ++ factory/api/apiResolverFactory.go | 1 + factory/core/coreComponents.go | 7 ++++ factory/core/coreComponentsHandler.go | 15 +++++++++ factory/data/dataComponents.go | 1 + factory/interface.go | 8 +++++ genesis/process/argGenesisBlockCreator.go | 2 ++ genesis/process/genesisBlockCreator.go | 8 ++--- integrationTests/mock/coreComponentsStub.go | 6 ++++ integrationTests/testProcessorNode.go | 1 + .../vm/wasm/delegation/testRunner.go | 5 +-- process/interface.go | 1 + process/smartContract/hooks/blockChainHook.go | 10 +++++- storage/database/db.go | 2 +- storage/factory/openStorage.go | 11 +++++-- storage/factory/persisterCreator.go | 1 - storage/factory/persisterFactory.go | 32 +++++++++++++++---- storage/factory/persisterFactory_test.go | 26 +++++++++++++++ storage/factory/storageServiceFactory.go | 10 ++++-- storage/interface.go | 10 ++++-- storage/latestData/latestDataProvider.go | 10 ++++-- storage/storageunit/storageunit.go | 2 +- testscommon/dataRetriever/poolFactory.go | 3 +- testscommon/integrationtests/factory.go | 4 ++- testscommon/storage/common.go | 11 +++++++ update/factory/dataTrieFactory.go | 9 ++++-- update/factory/exportHandlerFactory.go | 8 ++--- 32 files changed, 191 insertions(+), 38 deletions(-) create mode 100644 testscommon/storage/common.go diff --git a/config/config.go b/config/config.go index 5c489635269..fca35d0be0d 100644 --- a/config/config.go +++ b/config/config.go @@ -222,9 +222,10 @@ type Config struct { Requesters RequesterConfig VMOutputCacher CacheConfig - PeersRatingConfig PeersRatingConfig - PoolsCleanersConfig PoolsCleanersConfig - Redundancy RedundancyConfig + PeersRatingConfig PeersRatingConfig + PoolsCleanersConfig PoolsCleanersConfig + Redundancy RedundancyConfig + PersisterCreatorConfig PersisterCreatorConfig } // PeersRatingConfig will hold settings related to peers rating @@ -630,3 +631,8 @@ type PoolsCleanersConfig struct { type RedundancyConfig struct { MaxRoundsOfInactivityAccepted int } + +type PersisterCreatorConfig struct { + MaxRetriesToCreateDB uint32 + SleepTimeBetweenRetriesInSec uint32 +} diff --git a/dataRetriever/factory/dataPoolFactory.go b/dataRetriever/factory/dataPoolFactory.go index 8d3ae50bdb0..771575c984c 100644 --- a/dataRetriever/factory/dataPoolFactory.go +++ b/dataRetriever/factory/dataPoolFactory.go @@ -39,6 +39,7 @@ type ArgsDataPool struct { ShardCoordinator sharding.Coordinator Marshalizer marshal.Marshalizer PathManager storage.PathManagerHandler + PersisterFactory storage.PersisterFactoryHandler } // NewDataPoolFromConfig will return a new instance of a PoolsHolder @@ -179,7 +180,7 @@ func createTrieSyncDB(args ArgsDataPool) (storage.Persister, error) { shardId := core.GetShardIDString(args.ShardCoordinator.SelfId()) path := args.PathManager.PathForStatic(shardId, mainConfig.TrieSyncStorage.DB.FilePath) - persisterFactory, err := factory.NewPersisterFactory(mainConfig.TrieSyncStorage.DB) + persisterFactory, err := args.PersisterFactory.CreatePersisterHandler(mainConfig.TrieSyncStorage.DB) if err != nil { return nil, err } diff --git a/epochStart/bootstrap/process.go b/epochStart/bootstrap/process.go index 7c9e5820c48..f4f9e5948cc 100644 --- a/epochStart/bootstrap/process.go +++ b/epochStart/bootstrap/process.go @@ -354,6 +354,7 @@ func (e *epochStartBootstrap) Bootstrap() (Parameters, error) { ShardCoordinator: e.shardCoordinator, Marshalizer: e.coreComponentsHolder.InternalMarshalizer(), PathManager: e.coreComponentsHolder.PathHandler(), + PersisterFactory: e.coreComponentsHolder.PersisterFactory(), }, ) if err != nil { diff --git a/epochStart/bootstrap/storageProcess.go b/epochStart/bootstrap/storageProcess.go index 92679d045a2..2bfe2f087ea 100644 --- a/epochStart/bootstrap/storageProcess.go +++ b/epochStart/bootstrap/storageProcess.go @@ -109,6 +109,7 @@ func (sesb *storageEpochStartBootstrap) Bootstrap() (Parameters, error) { ShardCoordinator: sesb.shardCoordinator, Marshalizer: sesb.coreComponentsHolder.InternalMarshalizer(), PathManager: sesb.coreComponentsHolder.PathHandler(), + PersisterFactory: sesb.coreComponentsHolder.PersisterFactory(), }, ) if err != nil { diff --git a/epochStart/metachain/systemSCs_test.go b/epochStart/metachain/systemSCs_test.go index f74f9238db9..112f3becc2e 100644 --- a/epochStart/metachain/systemSCs_test.go +++ b/epochStart/metachain/systemSCs_test.go @@ -41,7 +41,6 @@ import ( "github.com/multiversx/mx-chain-go/state/storagePruningManager" "github.com/multiversx/mx-chain-go/state/storagePruningManager/evictionWaitingList" "github.com/multiversx/mx-chain-go/storage" - storageFactory "github.com/multiversx/mx-chain-go/storage/factory" "github.com/multiversx/mx-chain-go/storage/storageunit" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/cryptoMocks" @@ -87,7 +86,8 @@ func createPhysicalUnit(t *testing.T) (storage.Storer, string) { MaxOpenFiles: 10, } - persisterFactory, err := storageFactory.NewPersisterFactory(dbConfig) + pfh := storageMock.NewPersisterFactory() + persisterFactory, err := pfh.CreatePersisterHandler(dbConfig) assert.Nil(t, err) cache, _ := storageunit.NewCache(cacheConfig) @@ -988,6 +988,7 @@ func createFullArgumentsForSystemSCProcessing(enableEpochsConfig config.EnableEp GasSchedule: gasScheduleNotifier, Counter: &testscommon.BlockChainHookCounterStub{}, MissingTrieNodesNotifier: &testscommon.MissingTrieNodesNotifierStub{}, + PersisterFactory: storageMock.NewPersisterFactory(), } blockChainHookImpl, _ := hooks.NewBlockChainHookImpl(argsHook) diff --git a/errors/errors.go b/errors/errors.go index 81f547d8bea..a94c3648a87 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -232,6 +232,9 @@ var ErrNilMessenger = errors.New("nil messenger") // ErrNilMiniBlocksProvider signals a nil miniBlocks provider var ErrNilMiniBlocksProvider = errors.New("nil miniBlocks provider") +// ErrNilPersisterFactory signals a nil persister factory +var ErrNilPersisterFactory = errors.New("nil persister factory") + // ErrNilMultiSigner signals that a nil multi-signer was provided var ErrNilMultiSigner = errors.New("nil multi signer") diff --git a/factory/api/apiResolverFactory.go b/factory/api/apiResolverFactory.go index ed3610ca42d..68fe7e90d65 100644 --- a/factory/api/apiResolverFactory.go +++ b/factory/api/apiResolverFactory.go @@ -387,6 +387,7 @@ func createScQueryElement( GasSchedule: args.gasScheduleNotifier, Counter: counters.NewDisabledCounter(), MissingTrieNodesNotifier: syncer.NewMissingTrieNodesNotifier(), + PersisterFactory: args.coreComponents.PersisterFactory(), } var apiBlockchain data.ChainHandler diff --git a/factory/core/coreComponents.go b/factory/core/coreComponents.go index f04afe47d61..8cf6e2e2266 100644 --- a/factory/core/coreComponents.go +++ b/factory/core/coreComponents.go @@ -108,6 +108,7 @@ type coreComponents struct { processStatusHandler common.ProcessStatusHandler hardforkTriggerPubKey []byte enableEpochsHandler common.EnableEpochsHandler + persisterFactory storage.PersisterFactoryHandler } // NewCoreComponentsFactory initializes the factory which is responsible to creating core components @@ -332,6 +333,11 @@ func (ccf *coreComponentsFactory) Create() (*coreComponents, error) { return nil, err } + persisterFactory := storageFactory.NewPersisterFactoryHandler( + ccf.config.PersisterCreatorConfig.MaxRetriesToCreateDB, + ccf.config.PersisterCreatorConfig.SleepTimeBetweenRetriesInSec, + ) + return &coreComponents{ hasher: hasher, txSignHasher: txSignHasher, @@ -367,6 +373,7 @@ func (ccf *coreComponentsFactory) Create() (*coreComponents, error) { processStatusHandler: statusHandler.NewProcessStatusHandler(), hardforkTriggerPubKey: pubKeyBytes, enableEpochsHandler: enableEpochsHandler, + persisterFactory: persisterFactory, }, nil } diff --git a/factory/core/coreComponentsHandler.go b/factory/core/coreComponentsHandler.go index b10c378023e..017ef09404b 100644 --- a/factory/core/coreComponentsHandler.go +++ b/factory/core/coreComponentsHandler.go @@ -155,6 +155,9 @@ func (mcc *managedCoreComponents) CheckSubcomponents() error { if mcc.minTransactionVersion == 0 { return errors.ErrInvalidTransactionVersion } + if check.IfNil(mcc.persisterFactory) { + return errors.ErrNilPersisterFactory + } return nil } @@ -581,6 +584,18 @@ func (mcc *managedCoreComponents) EnableEpochsHandler() common.EnableEpochsHandl return mcc.coreComponents.enableEpochsHandler } +// PersisterFactory returns the persister factory component +func (mcc *managedCoreComponents) PersisterFactory() storage.PersisterFactoryHandler { + mcc.mutCoreComponents.RLock() + defer mcc.mutCoreComponents.RUnlock() + + if mcc.coreComponents == nil { + return nil + } + + return mcc.coreComponents.persisterFactory +} + // IsInterfaceNil returns true if there is no value under the interface func (mcc *managedCoreComponents) IsInterfaceNil() bool { return mcc == nil diff --git a/factory/data/dataComponents.go b/factory/data/dataComponents.go index 4e0d72282b1..c39ad9838b5 100644 --- a/factory/data/dataComponents.go +++ b/factory/data/dataComponents.go @@ -104,6 +104,7 @@ func (dcf *dataComponentsFactory) Create() (*dataComponents, error) { ShardCoordinator: dcf.shardCoordinator, Marshalizer: dcf.core.InternalMarshalizer(), PathManager: dcf.core.PathHandler(), + PersisterFactory: dcf.core.PersisterFactory(), } datapool, err = dataRetrieverFactory.NewDataPoolFromConfig(dataPoolArgs) if err != nil { diff --git a/factory/interface.go b/factory/interface.go index 2498cc916c4..53171e5546a 100644 --- a/factory/interface.go +++ b/factory/interface.go @@ -18,6 +18,7 @@ import ( "github.com/multiversx/mx-chain-go/common" cryptoCommon "github.com/multiversx/mx-chain-go/common/crypto" "github.com/multiversx/mx-chain-go/common/statistics" + "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/consensus" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/dblookupext" @@ -134,6 +135,7 @@ type CoreComponentsHolder interface { ProcessStatusHandler() common.ProcessStatusHandler HardforkTriggerPubKey() []byte EnableEpochsHandler() common.EnableEpochsHandler + PersisterFactory() storage.PersisterFactoryHandler IsInterfaceNil() bool } @@ -213,6 +215,12 @@ type MiniBlockProvider interface { IsInterfaceNil() bool } +// PersisterFactoryHandler defines the behaviour of a component which is able to create persisters +type PersisterFactoryHandler interface { + CreatePersisterHandler(config config.DBConfig) (storage.PersisterCreator, error) + IsInterfaceNil() bool +} + // DataComponentsHolder holds the data components type DataComponentsHolder interface { Blockchain() data.ChainHandler diff --git a/genesis/process/argGenesisBlockCreator.go b/genesis/process/argGenesisBlockCreator.go index e4374b7f6f0..5b1021937e5 100644 --- a/genesis/process/argGenesisBlockCreator.go +++ b/genesis/process/argGenesisBlockCreator.go @@ -17,6 +17,7 @@ import ( "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/state" + "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/update" ) @@ -29,6 +30,7 @@ type coreComponentsHandler interface { TxVersionChecker() process.TxVersionCheckerHandler ChainID() string EnableEpochsHandler() common.EnableEpochsHandler + PersisterFactory() storage.PersisterFactoryHandler IsInterfaceNil() bool } diff --git a/genesis/process/genesisBlockCreator.go b/genesis/process/genesisBlockCreator.go index d3fecd2f2d1..306459bacfe 100644 --- a/genesis/process/genesisBlockCreator.go +++ b/genesis/process/genesisBlockCreator.go @@ -89,11 +89,11 @@ func (gbc *genesisBlockCreator) createHardForkImportHandler() error { importFolder := filepath.Join(gbc.arg.WorkingDir, gbc.arg.HardForkConfig.ImportFolder) // TODO remove duplicate code found in update/factory/exportHandlerFactory.go - keysStorer, err := createStorer(gbc.arg.HardForkConfig.ImportKeysStorageConfig, importFolder) + keysStorer, err := gbc.createStorer(gbc.arg.HardForkConfig.ImportKeysStorageConfig, importFolder) if err != nil { return fmt.Errorf("%w while creating keys storer", err) } - keysVals, err := createStorer(gbc.arg.HardForkConfig.ImportStateStorageConfig, importFolder) + keysVals, err := gbc.createStorer(gbc.arg.HardForkConfig.ImportStateStorageConfig, importFolder) if err != nil { return fmt.Errorf("%w while creating keys-values storer", err) } @@ -127,11 +127,11 @@ func (gbc *genesisBlockCreator) createHardForkImportHandler() error { return nil } -func createStorer(storageConfig config.StorageConfig, folder string) (storage.Storer, error) { +func (gbc *genesisBlockCreator) createStorer(storageConfig config.StorageConfig, folder string) (storage.Storer, error) { dbConfig := factory.GetDBFromConfig(storageConfig.DB) dbConfig.FilePath = path.Join(folder, storageConfig.DB.FilePath) - persisterFactory, err := factory.NewPersisterFactory(storageConfig.DB) + persisterFactory, err := gbc.arg.Core.PersisterFactory().CreatePersisterHandler(storageConfig.DB) if err != nil { return nil, err } diff --git a/integrationTests/mock/coreComponentsStub.go b/integrationTests/mock/coreComponentsStub.go index dca3f5a1fa6..3d22927b68a 100644 --- a/integrationTests/mock/coreComponentsStub.go +++ b/integrationTests/mock/coreComponentsStub.go @@ -54,6 +54,7 @@ type CoreComponentsStub struct { ProcessStatusHandlerInternal common.ProcessStatusHandler HardforkTriggerPubKeyField []byte EnableEpochsHandlerField common.EnableEpochsHandler + PersisterFactoryField storage.PersisterFactoryHandler } // Create - @@ -259,6 +260,11 @@ func (ccs *CoreComponentsStub) EnableEpochsHandler() common.EnableEpochsHandler return ccs.EnableEpochsHandlerField } +// PersisterFactory - +func (ccs *CoreComponentsStub) PersisterFactory() storage.PersisterFactoryHandler { + return ccs.PersisterFactoryField +} + // IsInterfaceNil - func (ccs *CoreComponentsStub) IsInterfaceNil() bool { return ccs == nil diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index 5b59fedb896..8005c927ffb 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -3259,6 +3259,7 @@ func GetDefaultCoreComponents() *mock.CoreComponentsStub { TxVersionCheckField: versioning.NewTxVersionChecker(MinTransactionVersion), ProcessStatusHandlerInternal: &testscommon.ProcessStatusHandlerStub{}, EnableEpochsHandlerField: enableEpochsHandler, + PersisterFactoryField: storageStubs.NewPersisterFactory(), } } diff --git a/integrationTests/vm/wasm/delegation/testRunner.go b/integrationTests/vm/wasm/delegation/testRunner.go index e7bcb516b45..10ba746d95b 100644 --- a/integrationTests/vm/wasm/delegation/testRunner.go +++ b/integrationTests/vm/wasm/delegation/testRunner.go @@ -16,8 +16,8 @@ import ( "github.com/multiversx/mx-chain-go/integrationTests/vm/wasm" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/state" - "github.com/multiversx/mx-chain-go/storage/factory" "github.com/multiversx/mx-chain-go/storage/storageunit" + "github.com/multiversx/mx-chain-go/testscommon/storage" systemVm "github.com/multiversx/mx-chain-go/vm" logger "github.com/multiversx/mx-chain-logger-go" vmcommon "github.com/multiversx/mx-chain-vm-common-go" @@ -53,7 +53,8 @@ func RunDelegationStressTest( MaxBatchSize: 45000, MaxOpenFiles: 10, } - persisterFactory, err := factory.NewPersisterFactory(dbConfig) + pfh := storage.NewPersisterFactory() + persisterFactory, err := pfh.CreatePersisterHandler(dbConfig) if err != nil { return nil, err } diff --git a/process/interface.go b/process/interface.go index ee86ee3302c..682365d3543 100644 --- a/process/interface.go +++ b/process/interface.go @@ -1183,6 +1183,7 @@ type CoreComponentsHolder interface { ProcessStatusHandler() common.ProcessStatusHandler HardforkTriggerPubKey() []byte EnableEpochsHandler() common.EnableEpochsHandler + PersisterFactory() storage.PersisterFactoryHandler IsInterfaceNil() bool } diff --git a/process/smartContract/hooks/blockChainHook.go b/process/smartContract/hooks/blockChainHook.go index 18d0dac3d7f..a26f046fd1e 100644 --- a/process/smartContract/hooks/blockChainHook.go +++ b/process/smartContract/hooks/blockChainHook.go @@ -21,6 +21,7 @@ import ( "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/dataRetriever" + "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/factory/containers" "github.com/multiversx/mx-chain-go/process/smartContract/scrCommon" @@ -64,6 +65,7 @@ type ArgBlockChainHook struct { GasSchedule core.GasScheduleNotifier Counter BlockChainHookCounter MissingTrieNodesNotifier common.MissingTrieNodesNotifier + PersisterFactory storage.PersisterFactoryHandler } // BlockChainHookImpl is a wrapper over AccountsAdapter that satisfy vmcommon.BlockchainHook interface @@ -81,6 +83,7 @@ type BlockChainHookImpl struct { globalSettingsHandler vmcommon.ESDTGlobalSettingsHandler enableEpochsHandler common.EnableEpochsHandler counter BlockChainHookCounter + persisterFactory storage.PersisterFactoryHandler mutCurrentHdr sync.RWMutex currentHdr data.HeaderHandler @@ -126,6 +129,7 @@ func NewBlockChainHookImpl( gasSchedule: args.GasSchedule, counter: args.Counter, missingTrieNodesNotifier: args.MissingTrieNodesNotifier, + persisterFactory: args.PersisterFactory, } err = blockChainHookImpl.makeCompiledSCStorage() @@ -217,6 +221,10 @@ func checkForNil(args ArgBlockChainHook) error { if check.IfNil(args.MissingTrieNodesNotifier) { return ErrNilMissingTrieNodesNotifier } + if check.IfNil(args.PersisterFactory) { + return errors.ErrNilPersisterFactory + } + return nil } @@ -826,7 +834,7 @@ func (bh *BlockChainHookImpl) makeCompiledSCStorage() error { dbConfig := factory.GetDBFromConfig(bh.configSCStorage.DB) dbConfig.FilePath = path.Join(bh.workingDir, defaultCompiledSCPath, bh.configSCStorage.DB.FilePath) - persisterFactory, err := factory.NewPersisterFactory(bh.configSCStorage.DB) + persisterFactory, err := bh.persisterFactory.CreatePersisterHandler(bh.configSCStorage.DB) if err != nil { return err } diff --git a/storage/database/db.go b/storage/database/db.go index 7e677ed954c..aa4b910fe08 100644 --- a/storage/database/db.go +++ b/storage/database/db.go @@ -39,6 +39,6 @@ func NewShardIDProvider(numShards int32) (storage.ShardIDProvider, error) { } // NewShardedPersister is a constructor for sharded persister based on provided db type -func NewShardedPersister(path string, persisterCreator storage.PersisterCreator, idPersister storage.ShardIDProvider) (s storage.Persister, err error) { +func NewShardedPersister(path string, persisterCreator storage.BasePersisterCreator, idPersister storage.ShardIDProvider) (s storage.Persister, err error) { return sharded.NewShardedPersister(path, persisterCreator, idPersister) } diff --git a/storage/factory/openStorage.go b/storage/factory/openStorage.go index 0effada6f04..263fefdd3e2 100644 --- a/storage/factory/openStorage.go +++ b/storage/factory/openStorage.go @@ -6,6 +6,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/process/block/bootstrapStorage" "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/storage/cache" @@ -18,6 +19,7 @@ const cacheSize = 10 type ArgsNewOpenStorageUnits struct { BootstrapDataProvider BootstrapDataProviderHandler LatestStorageDataProvider storage.LatestStorageDataProviderHandler + PersisterFactory storage.PersisterFactoryHandler DefaultEpochString string DefaultShardString string } @@ -25,6 +27,7 @@ type ArgsNewOpenStorageUnits struct { type openStorageUnits struct { bootstrapDataProvider BootstrapDataProviderHandler latestStorageDataProvider storage.LatestStorageDataProviderHandler + persisterFactory storage.PersisterFactoryHandler defaultEpochString string defaultShardString string } @@ -37,12 +40,16 @@ func NewStorageUnitOpenHandler(args ArgsNewOpenStorageUnits) (*openStorageUnits, if check.IfNil(args.LatestStorageDataProvider) { return nil, storage.ErrNilLatestStorageDataProvider } + if check.IfNil(args.PersisterFactory) { + return nil, errors.ErrNilPersisterFactory + } o := &openStorageUnits{ defaultEpochString: args.DefaultEpochString, defaultShardString: args.DefaultShardString, bootstrapDataProvider: args.BootstrapDataProvider, latestStorageDataProvider: args.LatestStorageDataProvider, + persisterFactory: args.PersisterFactory, } return o, nil @@ -55,7 +62,7 @@ func (o *openStorageUnits) GetMostRecentStorageUnit(dbConfig config.DBConfig) (s return nil, err } - persisterFactory, err := NewPersisterFactory(dbConfig) + persisterFactory, err := o.persisterFactory.CreatePersisterHandler(dbConfig) if err != nil { return nil, err } @@ -110,7 +117,7 @@ func (o *openStorageUnits) OpenDB(dbConfig config.DBConfig, shardID uint32, epoc parentDir := o.latestStorageDataProvider.GetParentDirectory() pathWithoutShard := o.getPathWithoutShard(parentDir, epoch) persisterPath := o.getPersisterPath(pathWithoutShard, fmt.Sprintf("%d", shardID), dbConfig) - persisterFactory, err := NewPersisterFactory(dbConfig) + persisterFactory, err := o.persisterFactory.CreatePersisterHandler(dbConfig) if err != nil { return nil, err } diff --git a/storage/factory/persisterCreator.go b/storage/factory/persisterCreator.go index 1357fc37ae4..9c0a87bebf8 100644 --- a/storage/factory/persisterCreator.go +++ b/storage/factory/persisterCreator.go @@ -31,7 +31,6 @@ func newPersisterCreator(config config.DBConfig) *persisterCreator { } // Create will create the persister for the provided path -// TODO: refactor to use max tries mechanism func (pc *persisterCreator) Create(path string) (storage.Persister, error) { if len(path) == 0 { return nil, storage.ErrInvalidFilePath diff --git a/storage/factory/persisterFactory.go b/storage/factory/persisterFactory.go index 2c40b2fc328..a0cfc679382 100644 --- a/storage/factory/persisterFactory.go +++ b/storage/factory/persisterFactory.go @@ -8,20 +8,40 @@ import ( "github.com/multiversx/mx-chain-go/storage/disabled" ) -// persisterFactory is the factory which will handle creating new databases -type persisterFactory struct { - dbConfigHandler storage.DBConfigHandler +type persisterFactoryHandler struct { + maxRetriesToCreateDB uint32 + sleepTimeBetweenRetriesInSec uint32 +} + +func NewPersisterFactoryHandler(maxRetries, sleepTime uint32) *persisterFactoryHandler { + return &persisterFactoryHandler{ + maxRetriesToCreateDB: maxRetries, + sleepTimeBetweenRetriesInSec: sleepTime, + } } -// NewPersisterFactory will return a new instance of persister factory -func NewPersisterFactory(config config.DBConfig) (*persisterFactory, error) { +func (pfh *persisterFactoryHandler) CreatePersisterHandler(config config.DBConfig) (storage.PersisterCreator, error) { dbConfigHandler := NewDBConfigHandler(config) return &persisterFactory{ - dbConfigHandler: dbConfigHandler, + dbConfigHandler: dbConfigHandler, + maxRetriesToCreateDB: pfh.maxRetriesToCreateDB, + sleepTimeBetweenRetriesInSec: pfh.sleepTimeBetweenRetriesInSec, }, nil } +// IsInterfaceNil returns true if there is no value under the interface +func (pfh *persisterFactoryHandler) IsInterfaceNil() bool { + return pfh == nil +} + +// persisterFactory is the factory which will handle creating new databases +type persisterFactory struct { + maxRetriesToCreateDB uint32 + sleepTimeBetweenRetriesInSec uint32 + dbConfigHandler storage.DBConfigHandler +} + // CreateWithRetries will return a new instance of a DB with a given path // It will try to create db multiple times func (pf *persisterFactory) CreateWithRetries(path string) (storage.Persister, error) { diff --git a/storage/factory/persisterFactory_test.go b/storage/factory/persisterFactory_test.go index 860331a22bc..145bdd4a844 100644 --- a/storage/factory/persisterFactory_test.go +++ b/storage/factory/persisterFactory_test.go @@ -46,6 +46,32 @@ func TestPersisterFactory_Create(t *testing.T) { }) } +func TestPersisterFactory_CreateWithRetries(t *testing.T) { + t.Parallel() + + t.Run("invalid file path, should fail", func(t *testing.T) { + t.Parallel() + + pf, _ := factory.NewPersisterFactory(createDefaultDBConfig()) + + p, err := pf.CreateWithRetries("") + require.Nil(t, p) + require.Equal(t, storage.ErrInvalidFilePath, err) + }) + + t.Run("should work", func(t *testing.T) { + t.Parallel() + + pf, _ := factory.NewPersisterFactory(createDefaultDBConfig()) + + dir := t.TempDir() + + p, err := pf.CreateWithRetries(dir) + require.NotNil(t, p) + require.Nil(t, err) + }) +} + func TestPersisterFactory_Create_ConfigSaveToFilePath(t *testing.T) { t.Parallel() diff --git a/storage/factory/storageServiceFactory.go b/storage/factory/storageServiceFactory.go index 902b101675b..0519e33fe03 100644 --- a/storage/factory/storageServiceFactory.go +++ b/storage/factory/storageServiceFactory.go @@ -56,6 +56,7 @@ type StorageServiceFactory struct { snapshotsEnabled bool repopulateTokensSupplies bool stateStatsHandler common.StateStatisticsHandler + persisterFactory storage.PersisterFactoryHandler } // StorageServiceFactoryArgs holds the arguments needed for creating a new storage service factory @@ -73,6 +74,7 @@ type StorageServiceFactoryArgs struct { NodeProcessingMode common.NodeProcessingMode RepopulateTokensSupplies bool StateStatsHandler common.StateStatisticsHandler + PersisterFactory storage.PersisterFactoryHandler } // NewStorageServiceFactory will return a new instance of StorageServiceFactory @@ -109,6 +111,7 @@ func NewStorageServiceFactory(args StorageServiceFactoryArgs) (*StorageServiceFa snapshotsEnabled: args.Config.StateTriesConfig.SnapshotsEnabled, repopulateTokensSupplies: args.RepopulateTokensSupplies, stateStatsHandler: args.StateStatsHandler, + persisterFactory: args.PersisterFactory, }, nil } @@ -128,6 +131,9 @@ func checkArgs(args StorageServiceFactoryArgs) error { if check.IfNil(args.StateStatsHandler) { return statistics.ErrNilStateStatsHandler } + if check.IfNil(args.PersisterFactory) { + return storage.ErrNilPersisterFactory + } return nil } @@ -279,7 +285,7 @@ func (psf *StorageServiceFactory) createStaticStorageUnit( dbPath := psf.pathManager.PathForStatic(shardID, storageConf.DB.FilePath) + dbPathSuffix storageUnitDBConf.FilePath = dbPath - persisterCreator, err := NewPersisterFactory(storageConf.DB) + persisterCreator, err := psf.persisterFactory.CreatePersisterHandler(storageConf.DB) if err != nil { return nil, err } @@ -559,7 +565,7 @@ func (psf *StorageServiceFactory) createPruningStorerArgs( NumOfActivePersisters: numOfActivePersisters, } - persisterFactory, err := NewPersisterFactory(storageConfig.DB) + persisterFactory, err := psf.persisterFactory.CreatePersisterHandler(storageConfig.DB) if err != nil { return pruning.StorerArgs{}, err } diff --git a/storage/interface.go b/storage/interface.go index 5dd61cfad1d..c70970a630f 100644 --- a/storage/interface.go +++ b/storage/interface.go @@ -192,8 +192,8 @@ type ShardIDProvider interface { IsInterfaceNil() bool } -// PersisterCreator defines the behavour of a component which is able to create a persister -type PersisterCreator = types.PersisterCreator +// BasePersisterCreator defines the behavour of a component which is able to create a persister +type BasePersisterCreator = types.PersisterCreator // DBConfigHandler defines the behaviour of a component that will handle db config type DBConfigHandler interface { @@ -210,8 +210,14 @@ type ManagedPeersHolder interface { // PersisterFactoryHandler defines the behaviour of a component which is able to create persisters type PersisterFactoryHandler interface { + CreatePersisterHandler(config config.DBConfig) (PersisterCreator, error) + IsInterfaceNil() bool +} + +type PersisterCreator interface { Create(path string) (Persister, error) CreateWithRetries(path string) (Persister, error) + CreateDisabled() Persister IsInterfaceNil() bool } diff --git a/storage/latestData/latestDataProvider.go b/storage/latestData/latestDataProvider.go index 2b894627de3..204c8610751 100644 --- a/storage/latestData/latestDataProvider.go +++ b/storage/latestData/latestDataProvider.go @@ -31,6 +31,7 @@ type ArgsLatestDataProvider struct { GeneralConfig config.Config BootstrapDataProvider factory.BootstrapDataProviderHandler DirectoryReader storage.DirectoryReaderHandler + PersisterFactory storage.PersisterFactoryHandler ParentDir string DefaultEpochString string DefaultShardString string @@ -47,6 +48,7 @@ type latestDataProvider struct { generalConfig config.Config bootstrapDataProvider factory.BootstrapDataProviderHandler directoryReader storage.DirectoryReaderHandler + persisterFactory storage.PersisterFactoryHandler parentDir string defaultEpochString string defaultShardString string @@ -60,6 +62,9 @@ func NewLatestDataProvider(args ArgsLatestDataProvider) (*latestDataProvider, er if check.IfNil(args.BootstrapDataProvider) { return nil, storage.ErrNilBootstrapDataProvider } + if check.IfNil(args.PersisterFactory) { + return nil, storage.ErrNilPersisterFactory + } return &latestDataProvider{ generalConfig: args.GeneralConfig, @@ -68,6 +73,7 @@ func NewLatestDataProvider(args ArgsLatestDataProvider) (*latestDataProvider, er defaultShardString: args.DefaultShardString, defaultEpochString: args.DefaultEpochString, bootstrapDataProvider: args.BootstrapDataProvider, + persisterFactory: args.PersisterFactory, }, nil } @@ -132,7 +138,7 @@ func (ldp *latestDataProvider) getEpochDirs() ([]string, error) { } func (ldp *latestDataProvider) getLastEpochAndRoundFromStorage(parentDir string, lastEpoch uint32) (storage.LatestDataFromStorage, error) { - persisterFactory, err := factory.NewPersisterFactory(ldp.generalConfig.BootstrapStorage.DB) + persisterCreator, err := ldp.persisterFactory.CreatePersisterHandler(ldp.generalConfig.BootstrapStorage.DB) if err != nil { return storage.LatestDataFromStorage{}, err } @@ -158,7 +164,7 @@ func (ldp *latestDataProvider) getLastEpochAndRoundFromStorage(parentDir string, ldp.generalConfig.BootstrapStorage.DB.FilePath, ) - shardData := ldp.loadDataForShard(highestRoundInStoredShards, shardIdStr, persisterFactory, persisterPath) + shardData := ldp.loadDataForShard(highestRoundInStoredShards, shardIdStr, persisterCreator, persisterPath) if shardData.successful { epochStartRound = shardData.epochStartRound highestRoundInStoredShards = shardData.bootstrapData.LastRound diff --git a/storage/storageunit/storageunit.go b/storage/storageunit/storageunit.go index 2a9e390b725..1c33cf9e414 100644 --- a/storage/storageunit/storageunit.go +++ b/storage/storageunit/storageunit.go @@ -41,7 +41,7 @@ func NewCache(config CacheConfig) (storage.Cacher, error) { } // NewStorageUnitFromConf creates a new storage unit from a storage unit config -func NewStorageUnitFromConf(cacheConf CacheConfig, dbConf DBConfig, persisterFactory storage.PersisterFactoryHandler) (*Unit, error) { +func NewStorageUnitFromConf(cacheConf CacheConfig, dbConf DBConfig, persisterFactory storage.PersisterCreator) (*Unit, error) { return storageUnit.NewStorageUnitFromConf(cacheConf, dbConf, persisterFactory) } diff --git a/testscommon/dataRetriever/poolFactory.go b/testscommon/dataRetriever/poolFactory.go index a8f4374e800..f82be7a6844 100644 --- a/testscommon/dataRetriever/poolFactory.go +++ b/testscommon/dataRetriever/poolFactory.go @@ -98,7 +98,8 @@ func CreatePoolsHolder(numShards uint32, selfShard uint32) dataRetriever.PoolsHo MaxOpenFiles: 10, } - persisterFactory, err := storageFactory.NewPersisterFactory(dbConfig) + pfh := storageFactory.NewPersisterFactoryHandler(10, 1) + persisterFactory, err := pfh.CreatePersisterHandler(dbConfig) panicIfError("Create persister factory", err) persister, err := persisterFactory.CreateWithRetries(tempDir) diff --git a/testscommon/integrationtests/factory.go b/testscommon/integrationtests/factory.go index 9acfa7c5e10..1705a209ad4 100644 --- a/testscommon/integrationtests/factory.go +++ b/testscommon/integrationtests/factory.go @@ -62,7 +62,9 @@ func CreateStorer(parentDir string) storage.Storer { MaxBatchSize: 45000, MaxOpenFiles: 10, } - persisterFactory, err := factory.NewPersisterFactory(dbConfig) + + pfh := factory.NewPersisterFactoryHandler(10, 1) + persisterFactory, err := pfh.CreatePersisterHandler(dbConfig) if err != nil { return nil } diff --git a/testscommon/storage/common.go b/testscommon/storage/common.go new file mode 100644 index 00000000000..b1b275e7966 --- /dev/null +++ b/testscommon/storage/common.go @@ -0,0 +1,11 @@ +package storage + +import ( + "github.com/multiversx/mx-chain-go/storage" + "github.com/multiversx/mx-chain-go/storage/factory" +) + +// NewPersisterFactory - +func NewPersisterFactory() storage.PersisterFactoryHandler { + return factory.NewPersisterFactoryHandler(2, 1) +} diff --git a/update/factory/dataTrieFactory.go b/update/factory/dataTrieFactory.go index dcd83da1bd7..e9f3118c8b8 100644 --- a/update/factory/dataTrieFactory.go +++ b/update/factory/dataTrieFactory.go @@ -12,9 +12,10 @@ import ( "github.com/multiversx/mx-chain-go/common/statistics" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/dataRetriever" + "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/state" - "github.com/multiversx/mx-chain-go/storage/factory" + "github.com/multiversx/mx-chain-go/storage" storageFactory "github.com/multiversx/mx-chain-go/storage/factory" "github.com/multiversx/mx-chain-go/storage/storageunit" "github.com/multiversx/mx-chain-go/trie" @@ -31,6 +32,7 @@ type ArgsNewDataTrieFactory struct { ShardCoordinator sharding.Coordinator EnableEpochsHandler common.EnableEpochsHandler StateStatsCollector common.StateStatisticsHandler + PersisterFactory storage.PersisterFactoryHandler MaxTrieLevelInMemory uint } @@ -63,11 +65,14 @@ func NewDataTrieFactory(args ArgsNewDataTrieFactory) (*dataTrieFactory, error) { if check.IfNil(args.StateStatsCollector) { return nil, statistics.ErrNilStateStatsHandler } + if check.IfNil(args.PersisterFactory) { + return nil, errors.ErrNilPersisterFactory + } dbConfig := storageFactory.GetDBFromConfig(args.StorageConfig.DB) dbConfig.FilePath = path.Join(args.SyncFolder, args.StorageConfig.DB.FilePath) - persisterFactory, err := factory.NewPersisterFactory(args.StorageConfig.DB) + persisterFactory, err := args.PersisterFactory.CreatePersisterHandler(args.StorageConfig.DB) if err != nil { return nil, err } diff --git a/update/factory/exportHandlerFactory.go b/update/factory/exportHandlerFactory.go index c13f25f3f5a..f6be26c5d09 100644 --- a/update/factory/exportHandlerFactory.go +++ b/update/factory/exportHandlerFactory.go @@ -501,11 +501,11 @@ func (e *exportHandlerFactory) Create() (update.ExportHandler, error) { } }() - keysStorer, err = createStorer(e.exportStateKeysConfig, e.exportFolder) + keysStorer, err = e.createStorer(e.exportStateKeysConfig, e.exportFolder) if err != nil { return nil, fmt.Errorf("%w while creating keys storer", err) } - keysVals, err = createStorer(e.exportStateStorageConfig, e.exportFolder) + keysVals, err = e.createStorer(e.exportStateStorageConfig, e.exportFolder) if err != nil { return nil, fmt.Errorf("%w while creating keys-values storer", err) } @@ -604,11 +604,11 @@ func (e *exportHandlerFactory) createInterceptors() error { return nil } -func createStorer(storageConfig config.StorageConfig, folder string) (storage.Storer, error) { +func (e *exportHandlerFactory) createStorer(storageConfig config.StorageConfig, folder string) (storage.Storer, error) { dbConfig := storageFactory.GetDBFromConfig(storageConfig.DB) dbConfig.FilePath = path.Join(folder, storageConfig.DB.FilePath) - persisterFactory, err := storageFactory.NewPersisterFactory(storageConfig.DB) + persisterFactory, err := e.coreComponents.PersisterFactory().CreatePersisterHandler(storageConfig.DB) if err != nil { return nil, err } From 753ba8bf334b7abf3062e925bb026be97f7b186f Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 10 Jan 2024 21:52:17 +0200 Subject: [PATCH 038/503] fix unit tests --- dataRetriever/factory/dataPoolFactory_test.go | 2 ++ epochStart/bootstrap/metaStorageHandler.go | 2 ++ .../bootstrap/metaStorageHandler_test.go | 12 ++++++++ epochStart/bootstrap/process.go | 3 ++ epochStart/bootstrap/process_test.go | 1 + epochStart/bootstrap/shardStorageHandler.go | 2 ++ .../bootstrap/shardStorageHandler_test.go | 23 +++++++++++++++ epochStart/metachain/systemSCs_test.go | 5 ++-- epochStart/mock/coreComponentsMock.go | 6 ++++ factory/bootstrap/bootstrapComponents.go | 3 ++ factory/data/dataComponents.go | 1 + factory/processing/blockProcessorCreator.go | 2 ++ factory/processing/processComponents.go | 1 + genesis/process/genesisBlockCreator.go | 1 + genesis/process/metaGenesisBlockCreator.go | 1 + genesis/process/shardGenesisBlockCreator.go | 1 + .../startInEpoch/startInEpoch_test.go | 1 + integrationTests/testProcessorNode.go | 6 +++- integrationTests/vm/testInitializer.go | 5 ++++ .../vm/wasm/delegation/testRunner.go | 4 +-- integrationTests/vm/wasm/utils.go | 2 ++ .../hooks/blockChainHook_test.go | 2 ++ storage/factory/openStorage_test.go | 1 + storage/factory/persisterFactory_test.go | 28 +++++++++++-------- storage/factory/storageServiceFactory_test.go | 1 + storage/latestData/latestDataProvider_test.go | 2 ++ .../pruning/fullHistoryPruningStorer_test.go | 3 +- storage/pruning/pruningStorer_test.go | 5 ++-- storage/storageunit/storageunit_test.go | 18 ++++++++---- testscommon/{storage => persister}/common.go | 2 +- 30 files changed, 120 insertions(+), 26 deletions(-) rename testscommon/{storage => persister}/common.go (93%) diff --git a/dataRetriever/factory/dataPoolFactory_test.go b/dataRetriever/factory/dataPoolFactory_test.go index c9ae8b60c43..b40d025463f 100644 --- a/dataRetriever/factory/dataPoolFactory_test.go +++ b/dataRetriever/factory/dataPoolFactory_test.go @@ -10,6 +10,7 @@ import ( "github.com/multiversx/mx-chain-go/dataRetriever/dataPool/headersCache" "github.com/multiversx/mx-chain-go/dataRetriever/mock" "github.com/multiversx/mx-chain-go/storage" + "github.com/multiversx/mx-chain-go/storage/factory" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/economicsmocks" "github.com/stretchr/testify/require" @@ -159,5 +160,6 @@ func getGoodArgs() ArgsDataPool { ShardCoordinator: mock.NewMultipleShardsCoordinatorMock(), Marshalizer: &mock.MarshalizerMock{}, PathManager: &testscommon.PathManagerStub{}, + PersisterFactory: factory.NewPersisterFactoryHandler(2, 1), } } diff --git a/epochStart/bootstrap/metaStorageHandler.go b/epochStart/bootstrap/metaStorageHandler.go index 65e7e9c9237..3c159443f91 100644 --- a/epochStart/bootstrap/metaStorageHandler.go +++ b/epochStart/bootstrap/metaStorageHandler.go @@ -39,6 +39,7 @@ func NewMetaStorageHandler( nodeProcessingMode common.NodeProcessingMode, managedPeersHolder common.ManagedPeersHolder, stateStatsHandler common.StateStatisticsHandler, + persisterFactory storage.PersisterFactoryHandler, ) (*metaStorageHandler, error) { epochStartNotifier := &disabled.EpochStartNotifier{} storageFactory, err := factory.NewStorageServiceFactory( @@ -56,6 +57,7 @@ func NewMetaStorageHandler( RepopulateTokensSupplies: false, // tokens supplies cannot be repopulated at this time ManagedPeersHolder: managedPeersHolder, StateStatsHandler: stateStatsHandler, + PersisterFactory: persisterFactory, }, ) if err != nil { diff --git a/epochStart/bootstrap/metaStorageHandler_test.go b/epochStart/bootstrap/metaStorageHandler_test.go index 4fee7dee5b5..24e053e9bae 100644 --- a/epochStart/bootstrap/metaStorageHandler_test.go +++ b/epochStart/bootstrap/metaStorageHandler_test.go @@ -17,6 +17,7 @@ import ( "github.com/multiversx/mx-chain-go/epochStart/mock" "github.com/multiversx/mx-chain-go/process/block/bootstrapStorage" "github.com/multiversx/mx-chain-go/storage" + "github.com/multiversx/mx-chain-go/storage/factory" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/nodeTypeProviderMock" @@ -25,6 +26,10 @@ import ( "github.com/stretchr/testify/require" ) +func newPersisterFactory() storage.PersisterFactoryHandler { + return factory.NewPersisterFactoryHandler(2, 1) +} + func TestNewMetaStorageHandler_InvalidConfigErr(t *testing.T) { gCfg := config.Config{} prefsConfig := config.PreferencesConfig{} @@ -49,6 +54,7 @@ func TestNewMetaStorageHandler_InvalidConfigErr(t *testing.T) { common.Normal, managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) assert.True(t, check.IfNil(mtStrHandler)) assert.NotNil(t, err) @@ -81,6 +87,7 @@ func TestNewMetaStorageHandler_CreateForMetaErr(t *testing.T) { common.Normal, managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) assert.False(t, check.IfNil(mtStrHandler)) assert.Nil(t, err) @@ -114,6 +121,7 @@ func TestMetaStorageHandler_saveLastHeader(t *testing.T) { common.Normal, managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) header := &block.MetaBlock{Nonce: 0} @@ -156,6 +164,7 @@ func TestMetaStorageHandler_saveLastCrossNotarizedHeaders(t *testing.T) { common.Normal, managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) hdr1 := &block.Header{Nonce: 1} @@ -204,6 +213,7 @@ func TestMetaStorageHandler_saveTriggerRegistry(t *testing.T) { common.Normal, managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) components := &ComponentsNeededForBootstrap{ @@ -243,6 +253,7 @@ func TestMetaStorageHandler_saveDataToStorage(t *testing.T) { common.Normal, managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) components := &ComponentsNeededForBootstrap{ @@ -299,6 +310,7 @@ func testMetaWithMissingStorer(missingUnit dataRetriever.UnitType, atCallNumber common.Normal, managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) counter := 0 mtStrHandler.storageService = &storageStubs.ChainStorerStub{ diff --git a/epochStart/bootstrap/process.go b/epochStart/bootstrap/process.go index f4f9e5948cc..a9cce4f31a7 100644 --- a/epochStart/bootstrap/process.go +++ b/epochStart/bootstrap/process.go @@ -798,6 +798,7 @@ func (e *epochStartBootstrap) requestAndProcessForMeta(peerMiniBlocks []*block.M e.nodeProcessingMode, e.cryptoComponentsHolder.ManagedPeersHolder(), e.stateStatsHandler, + e.coreComponentsHolder.PersisterFactory(), ) if err != nil { return err @@ -968,6 +969,7 @@ func (e *epochStartBootstrap) requestAndProcessForShard(peerMiniBlocks []*block. e.nodeProcessingMode, e.cryptoComponentsHolder.ManagedPeersHolder(), e.stateStatsHandler, + e.coreComponentsHolder.PersisterFactory(), ) if err != nil { return err @@ -1156,6 +1158,7 @@ func (e *epochStartBootstrap) createStorageService( RepopulateTokensSupplies: e.flagsConfig.RepopulateTokensSupplies, ManagedPeersHolder: e.cryptoComponentsHolder.ManagedPeersHolder(), StateStatsHandler: e.stateStatsHandler, + PersisterFactory: e.coreComponentsHolder.PersisterFactory(), }) if err != nil { return nil, err diff --git a/epochStart/bootstrap/process_test.go b/epochStart/bootstrap/process_test.go index d95d97282d5..e70384832b1 100644 --- a/epochStart/bootstrap/process_test.go +++ b/epochStart/bootstrap/process_test.go @@ -86,6 +86,7 @@ func createComponentsForEpochStart() (*mock.CoreComponentsMock, *mock.CryptoComp ProcessStatusHandlerInstance: &testscommon.ProcessStatusHandlerStub{}, HardforkTriggerPubKeyField: []byte("provided hardfork pub key"), EnableEpochsHandlerField: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + PersisterFactoryField: newPersisterFactory(), }, &mock.CryptoComponentsMock{ PubKey: &cryptoMocks.PublicKeyStub{}, diff --git a/epochStart/bootstrap/shardStorageHandler.go b/epochStart/bootstrap/shardStorageHandler.go index 881aedf74c2..d140801f3d0 100644 --- a/epochStart/bootstrap/shardStorageHandler.go +++ b/epochStart/bootstrap/shardStorageHandler.go @@ -43,6 +43,7 @@ func NewShardStorageHandler( nodeProcessingMode common.NodeProcessingMode, managedPeersHolder common.ManagedPeersHolder, stateStatsHandler common.StateStatisticsHandler, + persisterFactory storage.PersisterFactoryHandler, ) (*shardStorageHandler, error) { epochStartNotifier := &disabled.EpochStartNotifier{} storageFactory, err := factory.NewStorageServiceFactory( @@ -60,6 +61,7 @@ func NewShardStorageHandler( RepopulateTokensSupplies: false, // tokens supplies cannot be repopulated at this time ManagedPeersHolder: managedPeersHolder, StateStatsHandler: stateStatsHandler, + PersisterFactory: persisterFactory, }, ) if err != nil { diff --git a/epochStart/bootstrap/shardStorageHandler_test.go b/epochStart/bootstrap/shardStorageHandler_test.go index b27f13df28b..ff27032add8 100644 --- a/epochStart/bootstrap/shardStorageHandler_test.go +++ b/epochStart/bootstrap/shardStorageHandler_test.go @@ -55,6 +55,7 @@ func TestNewShardStorageHandler_ShouldWork(t *testing.T) { args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) assert.False(t, check.IfNil(shardStorage)) @@ -80,6 +81,7 @@ func TestShardStorageHandler_SaveDataToStorageShardDataNotFound(t *testing.T) { args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) components := &ComponentsNeededForBootstrap{ @@ -111,6 +113,7 @@ func TestShardStorageHandler_SaveDataToStorageMissingHeader(t *testing.T) { args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) components := &ComponentsNeededForBootstrap{ @@ -165,6 +168,7 @@ func testShardWithMissingStorer(missingUnit dataRetriever.UnitType, atCallNumber args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) shardStorage.storageService = &storageStubs.ChainStorerStub{ GetStorerCalled: func(unitType dataRetriever.UnitType) (storage.Storer, error) { @@ -220,6 +224,7 @@ func TestShardStorageHandler_SaveDataToStorage(t *testing.T) { args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) hash1 := []byte("hash1") @@ -332,6 +337,7 @@ func TestShardStorageHandler_getCrossProcessedMiniBlockHeadersDestMe(t *testing. args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) shardHeader := &block.Header{ Nonce: 100, @@ -365,6 +371,7 @@ func TestShardStorageHandler_getProcessedAndPendingMiniBlocksWithScheduledErrorG args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) meta := &block.MetaBlock{ Nonce: 100, @@ -396,6 +403,7 @@ func TestShardStorageHandler_getProcessedAndPendingMiniBlocksWithScheduledNoSche args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) scenario := createPendingAndProcessedMiniBlocksScenario() @@ -424,6 +432,7 @@ func TestShardStorageHandler_getProcessedAndPendingMiniBlocksWithScheduledWrongH args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) scenario := createPendingAndProcessedMiniBlocksScenario() @@ -459,6 +468,7 @@ func TestShardStorageHandler_getProcessedAndPendingMiniBlocksWithScheduled(t *te args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) scenario := createPendingAndProcessedMiniBlocksScenario() processedMiniBlocks, pendingMiniBlocks, err := shardStorage.getProcessedAndPendingMiniBlocksWithScheduled(scenario.metaBlock, scenario.headers, scenario.shardHeader, true) @@ -640,6 +650,7 @@ func TestShardStorageHandler_getProcessedAndPendingMiniBlocksErrorGettingEpochSt args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) meta := &block.MetaBlock{ Nonce: 100, @@ -676,6 +687,7 @@ func TestShardStorageHandler_getProcessedAndPendingMiniBlocksMissingHeader(t *te args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) meta := &block.MetaBlock{ Nonce: 100, @@ -715,6 +727,7 @@ func TestShardStorageHandler_getProcessedAndPendingMiniBlocksWrongHeader(t *test args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) lastFinishedHeaders := createDefaultEpochStartShardData([]byte(lastFinishedMetaBlockHash), []byte("headerHash")) lastFinishedHeaders[0].FirstPendingMetaBlock = []byte(firstPendingMeta) @@ -759,6 +772,7 @@ func TestShardStorageHandler_getProcessedAndPendingMiniBlocksNilMetaBlock(t *tes args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) lastFinishedHeaders := createDefaultEpochStartShardData([]byte(lastFinishedMetaBlockHash), []byte("headerHash")) lastFinishedHeaders[0].FirstPendingMetaBlock = []byte(firstPendingMeta) @@ -805,6 +819,7 @@ func TestShardStorageHandler_getProcessedAndPendingMiniBlocksNoProcessedNoPendin args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) lastFinishedHeaders := createDefaultEpochStartShardData([]byte(lastFinishedMetaBlockHash), []byte("headerHash")) lastFinishedHeaders[0].FirstPendingMetaBlock = []byte(firstPendingMeta) @@ -847,6 +862,7 @@ func TestShardStorageHandler_getProcessedAndPendingMiniBlocksWithProcessedAndPen args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) scenario := createPendingAndProcessedMiniBlocksScenario() processedMiniBlocks, pendingMiniBlocks, firstPendingMetaBlockHash, err := shardStorage.getProcessedAndPendingMiniBlocks(scenario.metaBlock, scenario.headers) @@ -878,6 +894,7 @@ func TestShardStorageHandler_saveLastCrossNotarizedHeadersWithoutScheduledGetSha args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) headers := map[string]data.HeaderHandler{} @@ -912,6 +929,7 @@ func TestShardStorageHandler_saveLastCrossNotarizedHeadersWithoutScheduledMissin args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) shard0HeaderHash := "shard0 header hash" lastFinishedMetaBlock := "last finished meta block" @@ -954,6 +972,7 @@ func TestShardStorageHandler_saveLastCrossNotarizedHeadersWithoutScheduledWrongT args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) shard0HeaderHash := "shard0 header hash" lastFinishedMetaBlock := "last finished meta block" @@ -1003,6 +1022,7 @@ func TestShardStorageHandler_saveLastCrossNotarizedHeadersWithoutScheduledErrorW args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) shard0HeaderHash := "shard0 header hash" lastFinishedMetaBlock := "last finished meta block" @@ -1047,6 +1067,7 @@ func TestShardStorageHandler_saveLastCrossNotarizedHeadersWithoutScheduled(t *te args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) shard0HeaderHash := "shard0 header hash" lastFinishedMetaBlock := "last finished meta block" @@ -1096,6 +1117,7 @@ func TestShardStorageHandler_saveLastCrossNotarizedHeadersWithScheduledErrorUpda args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) shard0HeaderHash := "shard0 header hash" lastFinishedMetaBlock := "last finished meta block" @@ -1139,6 +1161,7 @@ func TestShardStorageHandler_saveLastCrossNotarizedHeadersWithScheduled(t *testi args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), + newPersisterFactory(), ) shard0HeaderHash := "shard0 header hash" lastFinishedMetaBlock := "last finished meta block" diff --git a/epochStart/metachain/systemSCs_test.go b/epochStart/metachain/systemSCs_test.go index 112f3becc2e..2e86bf27bd8 100644 --- a/epochStart/metachain/systemSCs_test.go +++ b/epochStart/metachain/systemSCs_test.go @@ -47,6 +47,7 @@ import ( dataRetrieverMock "github.com/multiversx/mx-chain-go/testscommon/dataRetriever" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" + "github.com/multiversx/mx-chain-go/testscommon/persister" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" statusHandlerMock "github.com/multiversx/mx-chain-go/testscommon/statusHandler" storageMock "github.com/multiversx/mx-chain-go/testscommon/storage" @@ -86,7 +87,7 @@ func createPhysicalUnit(t *testing.T) (storage.Storer, string) { MaxOpenFiles: 10, } - pfh := storageMock.NewPersisterFactory() + pfh := persister.NewPersisterFactory() persisterFactory, err := pfh.CreatePersisterHandler(dbConfig) assert.Nil(t, err) @@ -988,7 +989,7 @@ func createFullArgumentsForSystemSCProcessing(enableEpochsConfig config.EnableEp GasSchedule: gasScheduleNotifier, Counter: &testscommon.BlockChainHookCounterStub{}, MissingTrieNodesNotifier: &testscommon.MissingTrieNodesNotifierStub{}, - PersisterFactory: storageMock.NewPersisterFactory(), + PersisterFactory: persister.NewPersisterFactory(), } blockChainHookImpl, _ := hooks.NewBlockChainHookImpl(argsHook) diff --git a/epochStart/mock/coreComponentsMock.go b/epochStart/mock/coreComponentsMock.go index b2f0003d842..a9eaa75c4be 100644 --- a/epochStart/mock/coreComponentsMock.go +++ b/epochStart/mock/coreComponentsMock.go @@ -34,6 +34,7 @@ type CoreComponentsMock struct { NodeTypeProviderField core.NodeTypeProviderHandler ProcessStatusHandlerInstance common.ProcessStatusHandler HardforkTriggerPubKeyField []byte + PersisterFactoryField storage.PersisterFactoryHandler mutCore sync.RWMutex } @@ -155,6 +156,11 @@ func (ccm *CoreComponentsMock) HardforkTriggerPubKey() []byte { return ccm.HardforkTriggerPubKeyField } +// PersisterFactory - +func (ccm *CoreComponentsMock) PersisterFactory() storage.PersisterFactoryHandler { + return ccm.PersisterFactoryField +} + // IsInterfaceNil - func (ccm *CoreComponentsMock) IsInterfaceNil() bool { return ccm == nil diff --git a/factory/bootstrap/bootstrapComponents.go b/factory/bootstrap/bootstrapComponents.go index 988b72764e0..8472896bef3 100644 --- a/factory/bootstrap/bootstrapComponents.go +++ b/factory/bootstrap/bootstrapComponents.go @@ -165,6 +165,7 @@ func (bcf *bootstrapComponentsFactory) Create() (*bootstrapComponents, error) { unitOpener, err := createUnitOpener( bootstrapDataProvider, latestStorageDataProvider, + bcf.coreComponents.PersisterFactory(), storage.DefaultEpochString, storage.DefaultShardString, ) @@ -337,12 +338,14 @@ func createLatestStorageDataProvider( func createUnitOpener( bootstrapDataProvider storageFactory.BootstrapDataProviderHandler, latestDataFromStorageProvider storage.LatestStorageDataProviderHandler, + persisterFactory storage.PersisterFactoryHandler, defaultEpochString string, defaultShardString string, ) (storage.UnitOpenerHandler, error) { argsStorageUnitOpener := storageFactory.ArgsNewOpenStorageUnits{ BootstrapDataProvider: bootstrapDataProvider, LatestStorageDataProvider: latestDataFromStorageProvider, + PersisterFactory: persisterFactory, DefaultEpochString: defaultEpochString, DefaultShardString: defaultShardString, } diff --git a/factory/data/dataComponents.go b/factory/data/dataComponents.go index c39ad9838b5..3b65a531282 100644 --- a/factory/data/dataComponents.go +++ b/factory/data/dataComponents.go @@ -175,6 +175,7 @@ func (dcf *dataComponentsFactory) createDataStoreFromConfig() (dataRetriever.Sto RepopulateTokensSupplies: dcf.flagsConfig.RepopulateTokensSupplies, ManagedPeersHolder: dcf.crypto.ManagedPeersHolder(), StateStatsHandler: dcf.statusCore.StateStatsHandler(), + PersisterFactory: dcf.core.PersisterFactory(), }) if err != nil { return nil, err diff --git a/factory/processing/blockProcessorCreator.go b/factory/processing/blockProcessorCreator.go index 7bccd5d8af0..873f28c7028 100644 --- a/factory/processing/blockProcessorCreator.go +++ b/factory/processing/blockProcessorCreator.go @@ -995,6 +995,7 @@ func (pcf *processComponentsFactory) createVMFactoryShard( GasSchedule: pcf.gasSchedule, Counter: counter, MissingTrieNodesNotifier: notifier, + PersisterFactory: pcf.coreData.PersisterFactory(), } blockChainHookImpl, err := hooks.NewBlockChainHookImpl(argsHook) @@ -1046,6 +1047,7 @@ func (pcf *processComponentsFactory) createVMFactoryMeta( GasSchedule: pcf.gasSchedule, Counter: counters.NewDisabledCounter(), MissingTrieNodesNotifier: syncer.NewMissingTrieNodesNotifier(), + PersisterFactory: pcf.coreData.PersisterFactory(), } blockChainHookImpl, err := hooks.NewBlockChainHookImpl(argsHook) diff --git a/factory/processing/processComponents.go b/factory/processing/processComponents.go index 7ec9e8d9078..8c5b3384de8 100644 --- a/factory/processing/processComponents.go +++ b/factory/processing/processComponents.go @@ -1530,6 +1530,7 @@ func (pcf *processComponentsFactory) newStorageRequesters() (dataRetriever.Reque RepopulateTokensSupplies: pcf.flagsConfig.RepopulateTokensSupplies, ManagedPeersHolder: pcf.crypto.ManagedPeersHolder(), StateStatsHandler: pcf.statusCoreComponents.StateStatsHandler(), + PersisterFactory: pcf.coreData.PersisterFactory(), }, ) if err != nil { diff --git a/genesis/process/genesisBlockCreator.go b/genesis/process/genesisBlockCreator.go index 306459bacfe..c595c039b0a 100644 --- a/genesis/process/genesisBlockCreator.go +++ b/genesis/process/genesisBlockCreator.go @@ -452,6 +452,7 @@ func (gbc *genesisBlockCreator) computeDNSAddresses(enableEpochsConfig config.En GasSchedule: gbc.arg.GasSchedule, Counter: counters.NewDisabledCounter(), MissingTrieNodesNotifier: syncer.NewMissingTrieNodesNotifier(), + PersisterFactory: gbc.arg.Core.PersisterFactory(), } blockChainHook, err := hooks.NewBlockChainHookImpl(argsHook) if err != nil { diff --git a/genesis/process/metaGenesisBlockCreator.go b/genesis/process/metaGenesisBlockCreator.go index 40b5f606241..dfda9343faa 100644 --- a/genesis/process/metaGenesisBlockCreator.go +++ b/genesis/process/metaGenesisBlockCreator.go @@ -333,6 +333,7 @@ func createProcessorsForMetaGenesisBlock(arg ArgsGenesisBlockCreator, enableEpoc GasSchedule: arg.GasSchedule, Counter: counters.NewDisabledCounter(), MissingTrieNodesNotifier: syncer.NewMissingTrieNodesNotifier(), + PersisterFactory: arg.Core.PersisterFactory(), } pubKeyVerifier, err := disabled.NewMessageSignVerifier(arg.BlockSignKeyGen) diff --git a/genesis/process/shardGenesisBlockCreator.go b/genesis/process/shardGenesisBlockCreator.go index 9fef8f05569..b5a5fe44173 100644 --- a/genesis/process/shardGenesisBlockCreator.go +++ b/genesis/process/shardGenesisBlockCreator.go @@ -451,6 +451,7 @@ func createProcessorsForShardGenesisBlock(arg ArgsGenesisBlockCreator, enableEpo GasSchedule: arg.GasSchedule, Counter: counters.NewDisabledCounter(), MissingTrieNodesNotifier: syncer.NewMissingTrieNodesNotifier(), + PersisterFactory: arg.Core.PersisterFactory(), } esdtTransferParser, err := parsers.NewESDTTransferParser(arg.Core.InternalMarshalizer()) if err != nil { diff --git a/integrationTests/multiShard/endOfEpoch/startInEpoch/startInEpoch_test.go b/integrationTests/multiShard/endOfEpoch/startInEpoch/startInEpoch_test.go index 8ce1b1a72ec..dbda0db689c 100644 --- a/integrationTests/multiShard/endOfEpoch/startInEpoch/startInEpoch_test.go +++ b/integrationTests/multiShard/endOfEpoch/startInEpoch/startInEpoch_test.go @@ -296,6 +296,7 @@ func testNodeStartsInEpoch(t *testing.T, shardID uint32, expectedHighestRound ui NodeProcessingMode: common.Normal, ManagedPeersHolder: &testscommon.ManagedPeersHolderStub{}, StateStatsHandler: disabled.NewStateStatistics(), + PersisterFactory: coreComponents.PersisterFactoryField, }, ) assert.NoError(t, err) diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index 8005c927ffb..8871654dd8d 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -114,6 +114,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/mainFactoryMocks" "github.com/multiversx/mx-chain-go/testscommon/outport" "github.com/multiversx/mx-chain-go/testscommon/p2pmocks" + "github.com/multiversx/mx-chain-go/testscommon/persister" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" statusHandlerMock "github.com/multiversx/mx-chain-go/testscommon/statusHandler" @@ -887,6 +888,7 @@ func (tpn *TestProcessorNode) createFullSCQueryService(gasMap map[string]map[str GasSchedule: gasSchedule, Counter: counters.NewDisabledCounter(), MissingTrieNodesNotifier: &testscommon.MissingTrieNodesNotifierStub{}, + PersisterFactory: persister.NewPersisterFactory(), } var apiBlockchain data.ChainHandler @@ -1619,6 +1621,7 @@ func (tpn *TestProcessorNode) initInnerProcessors(gasMap map[string]map[string]u GasSchedule: gasSchedule, Counter: counter, MissingTrieNodesNotifier: &testscommon.MissingTrieNodesNotifierStub{}, + PersisterFactory: persister.NewPersisterFactory(), } maxGasLimitPerBlock := uint64(0xFFFFFFFFFFFFFFFF) @@ -1845,6 +1848,7 @@ func (tpn *TestProcessorNode) initMetaInnerProcessors(gasMap map[string]map[stri GasSchedule: gasSchedule, Counter: counters.NewDisabledCounter(), MissingTrieNodesNotifier: &testscommon.MissingTrieNodesNotifierStub{}, + PersisterFactory: persister.NewPersisterFactory(), } var signVerifier vm.MessageSignVerifier @@ -3259,7 +3263,7 @@ func GetDefaultCoreComponents() *mock.CoreComponentsStub { TxVersionCheckField: versioning.NewTxVersionChecker(MinTransactionVersion), ProcessStatusHandlerInternal: &testscommon.ProcessStatusHandlerStub{}, EnableEpochsHandlerField: enableEpochsHandler, - PersisterFactoryField: storageStubs.NewPersisterFactory(), + PersisterFactoryField: persister.NewPersisterFactory(), } } diff --git a/integrationTests/vm/testInitializer.go b/integrationTests/vm/testInitializer.go index 0c9fa15b273..c414d4c25b9 100644 --- a/integrationTests/vm/testInitializer.go +++ b/integrationTests/vm/testInitializer.go @@ -61,6 +61,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" "github.com/multiversx/mx-chain-go/testscommon/integrationtests" + "github.com/multiversx/mx-chain-go/testscommon/persister" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" "github.com/multiversx/mx-chain-go/testscommon/txDataBuilder" @@ -420,6 +421,7 @@ func CreateTxProcessorWithOneSCExecutorMockVM( GasSchedule: gasScheduleNotifier, Counter: &testscommon.BlockChainHookCounterStub{}, MissingTrieNodesNotifier: &testscommon.MissingTrieNodesNotifierStub{}, + PersisterFactory: persister.NewPersisterFactory(), } blockChainHook, _ := hooks.NewBlockChainHookImpl(args) @@ -528,6 +530,7 @@ func CreateOneSCExecutorMockVM(accnts state.AccountsAdapter) vmcommon.VMExecutio GasSchedule: CreateMockGasScheduleNotifier(), Counter: &testscommon.BlockChainHookCounterStub{}, MissingTrieNodesNotifier: &testscommon.MissingTrieNodesNotifierStub{}, + PersisterFactory: persister.NewPersisterFactory(), } blockChainHook, _ := hooks.NewBlockChainHookImpl(args) vm, _ := mock.NewOneSCExecutorMockVM(blockChainHook, integrationtests.TestHasher) @@ -599,6 +602,7 @@ func CreateVMAndBlockchainHookAndDataPool( GasSchedule: gasSchedule, Counter: counter, MissingTrieNodesNotifier: &testscommon.MissingTrieNodesNotifierStub{}, + PersisterFactory: persister.NewPersisterFactory(), } maxGasLimitPerBlock := uint64(0xFFFFFFFFFFFFFFFF) @@ -688,6 +692,7 @@ func CreateVMAndBlockchainHookMeta( GasSchedule: gasSchedule, Counter: &testscommon.BlockChainHookCounterStub{}, MissingTrieNodesNotifier: &testscommon.MissingTrieNodesNotifierStub{}, + PersisterFactory: persister.NewPersisterFactory(), } economicsData, err := createEconomicsData(config.EnableEpochs{}) diff --git a/integrationTests/vm/wasm/delegation/testRunner.go b/integrationTests/vm/wasm/delegation/testRunner.go index 10ba746d95b..ccbdb64dbe7 100644 --- a/integrationTests/vm/wasm/delegation/testRunner.go +++ b/integrationTests/vm/wasm/delegation/testRunner.go @@ -17,7 +17,7 @@ import ( "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/storage/storageunit" - "github.com/multiversx/mx-chain-go/testscommon/storage" + "github.com/multiversx/mx-chain-go/testscommon/persister" systemVm "github.com/multiversx/mx-chain-go/vm" logger "github.com/multiversx/mx-chain-logger-go" vmcommon "github.com/multiversx/mx-chain-vm-common-go" @@ -53,7 +53,7 @@ func RunDelegationStressTest( MaxBatchSize: 45000, MaxOpenFiles: 10, } - pfh := storage.NewPersisterFactory() + pfh := persister.NewPersisterFactory() persisterFactory, err := pfh.CreatePersisterHandler(dbConfig) if err != nil { return nil, err diff --git a/integrationTests/vm/wasm/utils.go b/integrationTests/vm/wasm/utils.go index e58d3e25c7b..ca29bf29730 100644 --- a/integrationTests/vm/wasm/utils.go +++ b/integrationTests/vm/wasm/utils.go @@ -52,6 +52,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/guardianMocks" "github.com/multiversx/mx-chain-go/testscommon/integrationtests" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" + "github.com/multiversx/mx-chain-go/testscommon/persister" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" "github.com/multiversx/mx-chain-go/vm/systemSmartContracts/defaults" vmcommon "github.com/multiversx/mx-chain-vm-common-go" @@ -311,6 +312,7 @@ func (context *TestContext) initVMAndBlockchainHook() { GasSchedule: gasSchedule, Counter: &testscommon.BlockChainHookCounterStub{}, MissingTrieNodesNotifier: &testscommon.MissingTrieNodesNotifierStub{}, + PersisterFactory: persister.NewPersisterFactory(), } vmFactoryConfig := config.VirtualMachineConfig{ diff --git a/process/smartContract/hooks/blockChainHook_test.go b/process/smartContract/hooks/blockChainHook_test.go index 92636c1baf0..bbf51b10421 100644 --- a/process/smartContract/hooks/blockChainHook_test.go +++ b/process/smartContract/hooks/blockChainHook_test.go @@ -30,6 +30,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" + "github.com/multiversx/mx-chain-go/testscommon/persister" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" "github.com/multiversx/mx-chain-go/testscommon/trie" @@ -69,6 +70,7 @@ func createMockBlockChainHookArgs() hooks.ArgBlockChainHook { GasSchedule: testscommon.NewGasScheduleNotifierMock(make(map[string]map[string]uint64)), Counter: &testscommon.BlockChainHookCounterStub{}, MissingTrieNodesNotifier: &testscommon.MissingTrieNodesNotifierStub{}, + PersisterFactory: persister.NewPersisterFactory(), } return arguments } diff --git a/storage/factory/openStorage_test.go b/storage/factory/openStorage_test.go index 1a1273df5f4..c0b526d14a9 100644 --- a/storage/factory/openStorage_test.go +++ b/storage/factory/openStorage_test.go @@ -18,6 +18,7 @@ func createMockArgsOpenStorageUnits() ArgsNewOpenStorageUnits { return ArgsNewOpenStorageUnits{ BootstrapDataProvider: &mock.BootStrapDataProviderStub{}, LatestStorageDataProvider: &mock.LatestStorageDataProviderStub{}, + PersisterFactory: NewPersisterFactoryHandler(2, 1), DefaultEpochString: "Epoch", DefaultShardString: "Shard", } diff --git a/storage/factory/persisterFactory_test.go b/storage/factory/persisterFactory_test.go index 145bdd4a844..42b4bb9e3ec 100644 --- a/storage/factory/persisterFactory_test.go +++ b/storage/factory/persisterFactory_test.go @@ -5,6 +5,7 @@ import ( "os" "testing" + "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/storage/factory" "github.com/multiversx/mx-chain-go/storage/storageunit" @@ -12,10 +13,15 @@ import ( "github.com/stretchr/testify/require" ) +func createPersisterFactory(config config.DBConfig) (storage.PersisterCreator, error) { + pfh := factory.NewPersisterFactoryHandler(2, 1) + return pfh.CreatePersisterHandler(config) +} + func TestNewPersisterFactory(t *testing.T) { t.Parallel() - pf, err := factory.NewPersisterFactory(createDefaultDBConfig()) + pf, err := createPersisterFactory(createDefaultDBConfig()) require.NotNil(t, pf) require.Nil(t, err) } @@ -26,7 +32,7 @@ func TestPersisterFactory_Create(t *testing.T) { t.Run("invalid file path, should fail", func(t *testing.T) { t.Parallel() - pf, _ := factory.NewPersisterFactory(createDefaultDBConfig()) + pf, _ := createPersisterFactory(createDefaultDBConfig()) p, err := pf.Create("") require.Nil(t, p) @@ -36,7 +42,7 @@ func TestPersisterFactory_Create(t *testing.T) { t.Run("should work", func(t *testing.T) { t.Parallel() - pf, _ := factory.NewPersisterFactory(createDefaultDBConfig()) + pf, _ := createPersisterFactory(createDefaultDBConfig()) dir := t.TempDir() @@ -52,7 +58,7 @@ func TestPersisterFactory_CreateWithRetries(t *testing.T) { t.Run("invalid file path, should fail", func(t *testing.T) { t.Parallel() - pf, _ := factory.NewPersisterFactory(createDefaultDBConfig()) + pf, _ := createPersisterFactory(createDefaultDBConfig()) p, err := pf.CreateWithRetries("") require.Nil(t, p) @@ -62,7 +68,7 @@ func TestPersisterFactory_CreateWithRetries(t *testing.T) { t.Run("should work", func(t *testing.T) { t.Parallel() - pf, _ := factory.NewPersisterFactory(createDefaultDBConfig()) + pf, _ := createPersisterFactory(createDefaultDBConfig()) dir := t.TempDir() @@ -80,7 +86,7 @@ func TestPersisterFactory_Create_ConfigSaveToFilePath(t *testing.T) { dbConfig := createDefaultBasePersisterConfig() dbConfig.Type = string(storageunit.LvlDB) - pf, _ := factory.NewPersisterFactory(dbConfig) + pf, _ := createPersisterFactory(dbConfig) dir := t.TempDir() path := dir + "storer/" @@ -99,7 +105,7 @@ func TestPersisterFactory_Create_ConfigSaveToFilePath(t *testing.T) { dbConfig := createDefaultBasePersisterConfig() dbConfig.Type = string(storageunit.LvlDBSerial) - pf, _ := factory.NewPersisterFactory(dbConfig) + pf, _ := createPersisterFactory(dbConfig) dir := t.TempDir() path := dir + "storer/" @@ -118,7 +124,7 @@ func TestPersisterFactory_Create_ConfigSaveToFilePath(t *testing.T) { dbConfig := createDefaultBasePersisterConfig() dbConfig.Type = string(storageunit.MemoryDB) - pf, _ := factory.NewPersisterFactory(dbConfig) + pf, _ := createPersisterFactory(dbConfig) dir := t.TempDir() path := dir + "storer/" @@ -137,7 +143,7 @@ func TestPersisterFactory_Create_ConfigSaveToFilePath(t *testing.T) { dbConfig := createDefaultBasePersisterConfig() dbConfig.Type = string(storageunit.MemoryDB) - pf, _ := factory.NewPersisterFactory(dbConfig) + pf, _ := createPersisterFactory(dbConfig) dir := t.TempDir() path := dir + "storer/" @@ -154,7 +160,7 @@ func TestPersisterFactory_Create_ConfigSaveToFilePath(t *testing.T) { func TestPersisterFactory_CreateDisabled(t *testing.T) { t.Parallel() - factoryInstance, err := factory.NewPersisterFactory(createDefaultDBConfig()) + factoryInstance, err := createPersisterFactory(createDefaultDBConfig()) require.Nil(t, err) persisterInstance := factoryInstance.CreateDisabled() @@ -165,6 +171,6 @@ func TestPersisterFactory_CreateDisabled(t *testing.T) { func TestPersisterFactory_IsInterfaceNil(t *testing.T) { t.Parallel() - pf, _ := factory.NewPersisterFactory(createDefaultDBConfig()) + pf, _ := createPersisterFactory(createDefaultDBConfig()) require.False(t, pf.IsInterfaceNil()) } diff --git a/storage/factory/storageServiceFactory_test.go b/storage/factory/storageServiceFactory_test.go index 310ecb89a5a..2363a7e2149 100644 --- a/storage/factory/storageServiceFactory_test.go +++ b/storage/factory/storageServiceFactory_test.go @@ -76,6 +76,7 @@ func createMockArgument(t *testing.T) StorageServiceFactoryArgs { CreateTrieEpochRootHashStorer: true, ManagedPeersHolder: &testscommon.ManagedPeersHolderStub{}, StateStatsHandler: disabledStatistics.NewStateStatistics(), + PersisterFactory: NewPersisterFactoryHandler(2, 1), } } diff --git a/storage/latestData/latestDataProvider_test.go b/storage/latestData/latestDataProvider_test.go index e2d4c561ae0..c50e30b680e 100644 --- a/storage/latestData/latestDataProvider_test.go +++ b/storage/latestData/latestDataProvider_test.go @@ -14,6 +14,7 @@ import ( "github.com/multiversx/mx-chain-go/process/block/bootstrapStorage" "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/storage/mock" + "github.com/multiversx/mx-chain-go/testscommon/persister" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -152,6 +153,7 @@ func getLatestDataProviderArgs() ArgsLatestDataProvider { GeneralConfig: config.Config{}, BootstrapDataProvider: &mock.BootStrapDataProviderStub{}, DirectoryReader: &mock.DirectoryReaderStub{}, + PersisterFactory: persister.NewPersisterFactory(), ParentDir: "db", DefaultEpochString: "Epoch", DefaultShardString: "Shard", diff --git a/storage/pruning/fullHistoryPruningStorer_test.go b/storage/pruning/fullHistoryPruningStorer_test.go index 0e0d43877e8..b3e58a09bd7 100644 --- a/storage/pruning/fullHistoryPruningStorer_test.go +++ b/storage/pruning/fullHistoryPruningStorer_test.go @@ -294,7 +294,8 @@ func TestFullHistoryPruningStorer_ConcurrentOperations(t *testing.T) { fmt.Println(testDir) args := getDefaultArgs() - persisterFactory, err := factory.NewPersisterFactory(config.DBConfig{ + pfh := factory.NewPersisterFactoryHandler(2, 1) + persisterFactory, err := pfh.CreatePersisterHandler(config.DBConfig{ FilePath: filepath.Join(testDir, dbName), Type: "LvlDBSerial", MaxBatchSize: 100, diff --git a/storage/pruning/pruningStorer_test.go b/storage/pruning/pruningStorer_test.go index 248cc53cda2..925f7710400 100644 --- a/storage/pruning/pruningStorer_test.go +++ b/storage/pruning/pruningStorer_test.go @@ -22,12 +22,12 @@ import ( "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/storage/database" "github.com/multiversx/mx-chain-go/storage/directoryhandler" - "github.com/multiversx/mx-chain-go/storage/factory" "github.com/multiversx/mx-chain-go/storage/mock" "github.com/multiversx/mx-chain-go/storage/pathmanager" "github.com/multiversx/mx-chain-go/storage/pruning" "github.com/multiversx/mx-chain-go/storage/storageunit" "github.com/multiversx/mx-chain-go/testscommon" + "github.com/multiversx/mx-chain-go/testscommon/persister" logger "github.com/multiversx/mx-chain-logger-go" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -1053,7 +1053,8 @@ func TestPruningStorer_ConcurrentOperations(t *testing.T) { fmt.Println(testDir) args := getDefaultArgs() - persisterFactory, err := factory.NewPersisterFactory(config.DBConfig{ + pfh := persister.NewPersisterFactory() + persisterFactory, err := pfh.CreatePersisterHandler(config.DBConfig{ FilePath: filepath.Join(testDir, dbName), Type: "LvlDBSerial", MaxBatchSize: 100, diff --git a/storage/storageunit/storageunit_test.go b/storage/storageunit/storageunit_test.go index 0652f25b33c..4871231a737 100644 --- a/storage/storageunit/storageunit_test.go +++ b/storage/storageunit/storageunit_test.go @@ -6,16 +6,22 @@ import ( "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/storage/factory" "github.com/multiversx/mx-chain-go/storage/mock" "github.com/multiversx/mx-chain-go/storage/storageunit" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" - "github.com/multiversx/mx-chain-go/testscommon/storage" + storageMock "github.com/multiversx/mx-chain-go/testscommon/storage" "github.com/multiversx/mx-chain-storage-go/common" "github.com/stretchr/testify/assert" ) +func createPersisterFactory(config config.DBConfig) (storage.PersisterCreator, error) { + pfh := factory.NewPersisterFactoryHandler(2, 1) + return pfh.CreatePersisterHandler(config) +} + func TestNewStorageUnit(t *testing.T) { t.Parallel() @@ -87,7 +93,7 @@ func TestNewDB(t *testing.T) { MaxOpenFiles: 10, } - persisterFactory, err := factory.NewPersisterFactory(dbConfig) + persisterFactory, err := createPersisterFactory(dbConfig) assert.Nil(t, err) db, err := persisterFactory.CreateWithRetries(path) @@ -106,7 +112,7 @@ func TestNewDB(t *testing.T) { MaxOpenFiles: 10, } - persisterFactory, err := factory.NewPersisterFactory(dbConfig) + persisterFactory, err := createPersisterFactory(dbConfig) assert.Nil(t, err) db, err := persisterFactory.CreateWithRetries(path) @@ -142,7 +148,7 @@ func TestNewStorageUnitFromConf(t *testing.T) { MaxBatchSize: dbConfig.MaxBatchSize, MaxOpenFiles: dbConfig.MaxOpenFiles, } - persisterFactory, err := factory.NewPersisterFactory(dbConf) + persisterFactory, err := createPersisterFactory(dbConf) assert.Nil(t, err) unit, err := storageunit.NewStorageUnitFromConf(cacheConfig, dbConfig, persisterFactory) @@ -163,7 +169,7 @@ func TestNewStorageUnitFromConf(t *testing.T) { MaxBatchSize: dbConfig.MaxBatchSize, MaxOpenFiles: dbConfig.MaxOpenFiles, } - persisterFactory, err := factory.NewPersisterFactory(dbConf) + persisterFactory, err := createPersisterFactory(dbConf) assert.Nil(t, err) unit, err := storageunit.NewStorageUnitFromConf(cacheConfig, dbConfig, persisterFactory) @@ -185,7 +191,7 @@ func TestNewStorageCacherAdapter(t *testing.T) { cacher := &mock.AdaptedSizedLruCacheStub{} db := &mock.PersisterStub{} - storedDataFactory := &storage.StoredDataFactoryStub{} + storedDataFactory := &storageMock.StoredDataFactoryStub{} marshaller := &marshallerMock.MarshalizerStub{} t.Run("nil parameter should error", func(t *testing.T) { diff --git a/testscommon/storage/common.go b/testscommon/persister/common.go similarity index 93% rename from testscommon/storage/common.go rename to testscommon/persister/common.go index b1b275e7966..c0d3eb141d0 100644 --- a/testscommon/storage/common.go +++ b/testscommon/persister/common.go @@ -1,4 +1,4 @@ -package storage +package persister import ( "github.com/multiversx/mx-chain-go/storage" From 45f676f3355e35d75f8e948b3dcec69e9b6c9ee9 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 11 Jan 2024 15:05:11 +0200 Subject: [PATCH 039/503] remove unused constants --- factory/mock/coreComponentsMock.go | 6 ++++++ storage/constants.go | 10 ---------- storage/factory/persisterFactory.go | 17 ++++++++--------- testscommon/factory/coreComponentsHolderStub.go | 10 ++++++++++ 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/factory/mock/coreComponentsMock.go b/factory/mock/coreComponentsMock.go index 0393f44c4a1..43e8571543b 100644 --- a/factory/mock/coreComponentsMock.go +++ b/factory/mock/coreComponentsMock.go @@ -56,6 +56,7 @@ type CoreComponentsMock struct { ProcessStatusHandlerInternal common.ProcessStatusHandler HardforkTriggerPubKeyField []byte EnableEpochsHandlerField common.EnableEpochsHandler + PersisterFactoryField storage.PersisterFactoryHandler } // InternalMarshalizer - @@ -246,6 +247,11 @@ func (ccm *CoreComponentsMock) EnableEpochsHandler() common.EnableEpochsHandler return ccm.EnableEpochsHandlerField } +// PersisterFactory - +func (ccm *CoreComponentsMock) PersisterFactory() storage.PersisterFactoryHandler { + return ccm.PersisterFactoryField +} + // IsInterfaceNil - func (ccm *CoreComponentsMock) IsInterfaceNil() bool { return ccm == nil diff --git a/storage/constants.go b/storage/constants.go index b78021138c7..8760b546377 100644 --- a/storage/constants.go +++ b/storage/constants.go @@ -1,15 +1,5 @@ package storage -import ( - "github.com/multiversx/mx-chain-storage-go/storageUnit" -) - -// MaxRetriesToCreateDB represents the maximum number of times to try to create DB if it failed -const MaxRetriesToCreateDB = storageUnit.MaxRetriesToCreateDB - -// SleepTimeBetweenCreateDBRetries represents the number of seconds to sleep between DB creates -const SleepTimeBetweenCreateDBRetries = storageUnit.SleepTimeBetweenCreateDBRetries - // PathShardPlaceholder represents the placeholder for the shard ID in paths const PathShardPlaceholder = "[S]" diff --git a/storage/factory/persisterFactory.go b/storage/factory/persisterFactory.go index a0cfc679382..a8af4acd499 100644 --- a/storage/factory/persisterFactory.go +++ b/storage/factory/persisterFactory.go @@ -24,9 +24,9 @@ func (pfh *persisterFactoryHandler) CreatePersisterHandler(config config.DBConfi dbConfigHandler := NewDBConfigHandler(config) return &persisterFactory{ - dbConfigHandler: dbConfigHandler, - maxRetriesToCreateDB: pfh.maxRetriesToCreateDB, - sleepTimeBetweenRetriesInSec: pfh.sleepTimeBetweenRetriesInSec, + dbConfigHandler: dbConfigHandler, + maxRetriesToCreateDB: pfh.maxRetriesToCreateDB, + sleepTimeBetweenRetries: time.Second * time.Duration(pfh.sleepTimeBetweenRetriesInSec), }, nil } @@ -37,9 +37,9 @@ func (pfh *persisterFactoryHandler) IsInterfaceNil() bool { // persisterFactory is the factory which will handle creating new databases type persisterFactory struct { - maxRetriesToCreateDB uint32 - sleepTimeBetweenRetriesInSec uint32 - dbConfigHandler storage.DBConfigHandler + maxRetriesToCreateDB uint32 + sleepTimeBetweenRetries time.Duration + dbConfigHandler storage.DBConfigHandler } // CreateWithRetries will return a new instance of a DB with a given path @@ -48,15 +48,14 @@ func (pf *persisterFactory) CreateWithRetries(path string) (storage.Persister, e var persister storage.Persister var err error - for i := 0; i < storage.MaxRetriesToCreateDB; i++ { + for i := uint32(0); i < pf.maxRetriesToCreateDB; i++ { persister, err = pf.Create(path) if err == nil { return persister, nil } log.Warn("Create Persister failed", "path", path, "error", err) - // TODO: extract this in a parameter and inject it - time.Sleep(storage.SleepTimeBetweenCreateDBRetries) + time.Sleep(pf.sleepTimeBetweenRetries) } return nil, err diff --git a/testscommon/factory/coreComponentsHolderStub.go b/testscommon/factory/coreComponentsHolderStub.go index d26a12c33e2..6dc9cbf43d5 100644 --- a/testscommon/factory/coreComponentsHolderStub.go +++ b/testscommon/factory/coreComponentsHolderStub.go @@ -55,6 +55,7 @@ type CoreComponentsHolderStub struct { HardforkTriggerPubKeyCalled func() []byte EnableEpochsHandlerCalled func() common.EnableEpochsHandler RoundNotifierCalled func() process.RoundNotifier + PersisterFactoryCalled func() storage.PersisterFactoryHandler } // NewCoreComponentsHolderStubFromRealComponent - @@ -95,6 +96,7 @@ func NewCoreComponentsHolderStubFromRealComponent(coreComponents factory.CoreCom HardforkTriggerPubKeyCalled: coreComponents.HardforkTriggerPubKey, EnableEpochsHandlerCalled: coreComponents.EnableEpochsHandler, RoundNotifierCalled: coreComponents.RoundNotifier, + PersisterFactoryCalled: coreComponents.PersisterFactory, } } @@ -378,6 +380,14 @@ func (stub *CoreComponentsHolderStub) RoundNotifier() process.RoundNotifier { return nil } +// PersisterFactory - +func (stub *CoreComponentsHolderStub) PersisterFactory() storage.PersisterFactoryHandler { + if stub.PersisterFactoryCalled != nil { + return stub.PersisterFactoryCalled() + } + return nil +} + // IsInterfaceNil - func (stub *CoreComponentsHolderStub) IsInterfaceNil() bool { return stub == nil From 74c9cf3c0b4e493447db2d2858fad5cc5aac0e83 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Fri, 12 Jan 2024 12:18:34 +0200 Subject: [PATCH 040/503] Revert "remove unused constants" This reverts commit 45f676f3355e35d75f8e948b3dcec69e9b6c9ee9. --- factory/mock/coreComponentsMock.go | 6 ------ storage/constants.go | 10 ++++++++++ storage/factory/persisterFactory.go | 17 +++++++++-------- testscommon/factory/coreComponentsHolderStub.go | 10 ---------- 4 files changed, 19 insertions(+), 24 deletions(-) diff --git a/factory/mock/coreComponentsMock.go b/factory/mock/coreComponentsMock.go index 43e8571543b..0393f44c4a1 100644 --- a/factory/mock/coreComponentsMock.go +++ b/factory/mock/coreComponentsMock.go @@ -56,7 +56,6 @@ type CoreComponentsMock struct { ProcessStatusHandlerInternal common.ProcessStatusHandler HardforkTriggerPubKeyField []byte EnableEpochsHandlerField common.EnableEpochsHandler - PersisterFactoryField storage.PersisterFactoryHandler } // InternalMarshalizer - @@ -247,11 +246,6 @@ func (ccm *CoreComponentsMock) EnableEpochsHandler() common.EnableEpochsHandler return ccm.EnableEpochsHandlerField } -// PersisterFactory - -func (ccm *CoreComponentsMock) PersisterFactory() storage.PersisterFactoryHandler { - return ccm.PersisterFactoryField -} - // IsInterfaceNil - func (ccm *CoreComponentsMock) IsInterfaceNil() bool { return ccm == nil diff --git a/storage/constants.go b/storage/constants.go index 8760b546377..b78021138c7 100644 --- a/storage/constants.go +++ b/storage/constants.go @@ -1,5 +1,15 @@ package storage +import ( + "github.com/multiversx/mx-chain-storage-go/storageUnit" +) + +// MaxRetriesToCreateDB represents the maximum number of times to try to create DB if it failed +const MaxRetriesToCreateDB = storageUnit.MaxRetriesToCreateDB + +// SleepTimeBetweenCreateDBRetries represents the number of seconds to sleep between DB creates +const SleepTimeBetweenCreateDBRetries = storageUnit.SleepTimeBetweenCreateDBRetries + // PathShardPlaceholder represents the placeholder for the shard ID in paths const PathShardPlaceholder = "[S]" diff --git a/storage/factory/persisterFactory.go b/storage/factory/persisterFactory.go index a8af4acd499..a0cfc679382 100644 --- a/storage/factory/persisterFactory.go +++ b/storage/factory/persisterFactory.go @@ -24,9 +24,9 @@ func (pfh *persisterFactoryHandler) CreatePersisterHandler(config config.DBConfi dbConfigHandler := NewDBConfigHandler(config) return &persisterFactory{ - dbConfigHandler: dbConfigHandler, - maxRetriesToCreateDB: pfh.maxRetriesToCreateDB, - sleepTimeBetweenRetries: time.Second * time.Duration(pfh.sleepTimeBetweenRetriesInSec), + dbConfigHandler: dbConfigHandler, + maxRetriesToCreateDB: pfh.maxRetriesToCreateDB, + sleepTimeBetweenRetriesInSec: pfh.sleepTimeBetweenRetriesInSec, }, nil } @@ -37,9 +37,9 @@ func (pfh *persisterFactoryHandler) IsInterfaceNil() bool { // persisterFactory is the factory which will handle creating new databases type persisterFactory struct { - maxRetriesToCreateDB uint32 - sleepTimeBetweenRetries time.Duration - dbConfigHandler storage.DBConfigHandler + maxRetriesToCreateDB uint32 + sleepTimeBetweenRetriesInSec uint32 + dbConfigHandler storage.DBConfigHandler } // CreateWithRetries will return a new instance of a DB with a given path @@ -48,14 +48,15 @@ func (pf *persisterFactory) CreateWithRetries(path string) (storage.Persister, e var persister storage.Persister var err error - for i := uint32(0); i < pf.maxRetriesToCreateDB; i++ { + for i := 0; i < storage.MaxRetriesToCreateDB; i++ { persister, err = pf.Create(path) if err == nil { return persister, nil } log.Warn("Create Persister failed", "path", path, "error", err) - time.Sleep(pf.sleepTimeBetweenRetries) + // TODO: extract this in a parameter and inject it + time.Sleep(storage.SleepTimeBetweenCreateDBRetries) } return nil, err diff --git a/testscommon/factory/coreComponentsHolderStub.go b/testscommon/factory/coreComponentsHolderStub.go index 6dc9cbf43d5..d26a12c33e2 100644 --- a/testscommon/factory/coreComponentsHolderStub.go +++ b/testscommon/factory/coreComponentsHolderStub.go @@ -55,7 +55,6 @@ type CoreComponentsHolderStub struct { HardforkTriggerPubKeyCalled func() []byte EnableEpochsHandlerCalled func() common.EnableEpochsHandler RoundNotifierCalled func() process.RoundNotifier - PersisterFactoryCalled func() storage.PersisterFactoryHandler } // NewCoreComponentsHolderStubFromRealComponent - @@ -96,7 +95,6 @@ func NewCoreComponentsHolderStubFromRealComponent(coreComponents factory.CoreCom HardforkTriggerPubKeyCalled: coreComponents.HardforkTriggerPubKey, EnableEpochsHandlerCalled: coreComponents.EnableEpochsHandler, RoundNotifierCalled: coreComponents.RoundNotifier, - PersisterFactoryCalled: coreComponents.PersisterFactory, } } @@ -380,14 +378,6 @@ func (stub *CoreComponentsHolderStub) RoundNotifier() process.RoundNotifier { return nil } -// PersisterFactory - -func (stub *CoreComponentsHolderStub) PersisterFactory() storage.PersisterFactoryHandler { - if stub.PersisterFactoryCalled != nil { - return stub.PersisterFactoryCalled() - } - return nil -} - // IsInterfaceNil - func (stub *CoreComponentsHolderStub) IsInterfaceNil() bool { return stub == nil From a49e0d102d57ba74d0c0c7db76fab3c29ea9aa0a Mon Sep 17 00:00:00 2001 From: ssd04 Date: Fri, 12 Jan 2024 12:18:42 +0200 Subject: [PATCH 041/503] Revert "fix unit tests" This reverts commit 753ba8bf334b7abf3062e925bb026be97f7b186f. --- dataRetriever/factory/dataPoolFactory_test.go | 2 -- epochStart/bootstrap/metaStorageHandler.go | 2 -- .../bootstrap/metaStorageHandler_test.go | 12 -------- epochStart/bootstrap/process.go | 3 -- epochStart/bootstrap/process_test.go | 1 - epochStart/bootstrap/shardStorageHandler.go | 2 -- .../bootstrap/shardStorageHandler_test.go | 23 --------------- epochStart/metachain/systemSCs_test.go | 5 ++-- epochStart/mock/coreComponentsMock.go | 6 ---- factory/bootstrap/bootstrapComponents.go | 3 -- factory/data/dataComponents.go | 1 - factory/processing/blockProcessorCreator.go | 2 -- factory/processing/processComponents.go | 1 - genesis/process/genesisBlockCreator.go | 1 - genesis/process/metaGenesisBlockCreator.go | 1 - genesis/process/shardGenesisBlockCreator.go | 1 - .../startInEpoch/startInEpoch_test.go | 1 - integrationTests/testProcessorNode.go | 6 +--- integrationTests/vm/testInitializer.go | 5 ---- .../vm/wasm/delegation/testRunner.go | 4 +-- integrationTests/vm/wasm/utils.go | 2 -- .../hooks/blockChainHook_test.go | 2 -- storage/factory/openStorage_test.go | 1 - storage/factory/persisterFactory_test.go | 28 ++++++++----------- storage/factory/storageServiceFactory_test.go | 1 - storage/latestData/latestDataProvider_test.go | 2 -- .../pruning/fullHistoryPruningStorer_test.go | 3 +- storage/pruning/pruningStorer_test.go | 5 ++-- storage/storageunit/storageunit_test.go | 18 ++++-------- testscommon/{persister => storage}/common.go | 2 +- 30 files changed, 26 insertions(+), 120 deletions(-) rename testscommon/{persister => storage}/common.go (93%) diff --git a/dataRetriever/factory/dataPoolFactory_test.go b/dataRetriever/factory/dataPoolFactory_test.go index b40d025463f..c9ae8b60c43 100644 --- a/dataRetriever/factory/dataPoolFactory_test.go +++ b/dataRetriever/factory/dataPoolFactory_test.go @@ -10,7 +10,6 @@ import ( "github.com/multiversx/mx-chain-go/dataRetriever/dataPool/headersCache" "github.com/multiversx/mx-chain-go/dataRetriever/mock" "github.com/multiversx/mx-chain-go/storage" - "github.com/multiversx/mx-chain-go/storage/factory" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/economicsmocks" "github.com/stretchr/testify/require" @@ -160,6 +159,5 @@ func getGoodArgs() ArgsDataPool { ShardCoordinator: mock.NewMultipleShardsCoordinatorMock(), Marshalizer: &mock.MarshalizerMock{}, PathManager: &testscommon.PathManagerStub{}, - PersisterFactory: factory.NewPersisterFactoryHandler(2, 1), } } diff --git a/epochStart/bootstrap/metaStorageHandler.go b/epochStart/bootstrap/metaStorageHandler.go index 3c159443f91..65e7e9c9237 100644 --- a/epochStart/bootstrap/metaStorageHandler.go +++ b/epochStart/bootstrap/metaStorageHandler.go @@ -39,7 +39,6 @@ func NewMetaStorageHandler( nodeProcessingMode common.NodeProcessingMode, managedPeersHolder common.ManagedPeersHolder, stateStatsHandler common.StateStatisticsHandler, - persisterFactory storage.PersisterFactoryHandler, ) (*metaStorageHandler, error) { epochStartNotifier := &disabled.EpochStartNotifier{} storageFactory, err := factory.NewStorageServiceFactory( @@ -57,7 +56,6 @@ func NewMetaStorageHandler( RepopulateTokensSupplies: false, // tokens supplies cannot be repopulated at this time ManagedPeersHolder: managedPeersHolder, StateStatsHandler: stateStatsHandler, - PersisterFactory: persisterFactory, }, ) if err != nil { diff --git a/epochStart/bootstrap/metaStorageHandler_test.go b/epochStart/bootstrap/metaStorageHandler_test.go index 24e053e9bae..4fee7dee5b5 100644 --- a/epochStart/bootstrap/metaStorageHandler_test.go +++ b/epochStart/bootstrap/metaStorageHandler_test.go @@ -17,7 +17,6 @@ import ( "github.com/multiversx/mx-chain-go/epochStart/mock" "github.com/multiversx/mx-chain-go/process/block/bootstrapStorage" "github.com/multiversx/mx-chain-go/storage" - "github.com/multiversx/mx-chain-go/storage/factory" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/nodeTypeProviderMock" @@ -26,10 +25,6 @@ import ( "github.com/stretchr/testify/require" ) -func newPersisterFactory() storage.PersisterFactoryHandler { - return factory.NewPersisterFactoryHandler(2, 1) -} - func TestNewMetaStorageHandler_InvalidConfigErr(t *testing.T) { gCfg := config.Config{} prefsConfig := config.PreferencesConfig{} @@ -54,7 +49,6 @@ func TestNewMetaStorageHandler_InvalidConfigErr(t *testing.T) { common.Normal, managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) assert.True(t, check.IfNil(mtStrHandler)) assert.NotNil(t, err) @@ -87,7 +81,6 @@ func TestNewMetaStorageHandler_CreateForMetaErr(t *testing.T) { common.Normal, managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) assert.False(t, check.IfNil(mtStrHandler)) assert.Nil(t, err) @@ -121,7 +114,6 @@ func TestMetaStorageHandler_saveLastHeader(t *testing.T) { common.Normal, managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) header := &block.MetaBlock{Nonce: 0} @@ -164,7 +156,6 @@ func TestMetaStorageHandler_saveLastCrossNotarizedHeaders(t *testing.T) { common.Normal, managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) hdr1 := &block.Header{Nonce: 1} @@ -213,7 +204,6 @@ func TestMetaStorageHandler_saveTriggerRegistry(t *testing.T) { common.Normal, managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) components := &ComponentsNeededForBootstrap{ @@ -253,7 +243,6 @@ func TestMetaStorageHandler_saveDataToStorage(t *testing.T) { common.Normal, managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) components := &ComponentsNeededForBootstrap{ @@ -310,7 +299,6 @@ func testMetaWithMissingStorer(missingUnit dataRetriever.UnitType, atCallNumber common.Normal, managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) counter := 0 mtStrHandler.storageService = &storageStubs.ChainStorerStub{ diff --git a/epochStart/bootstrap/process.go b/epochStart/bootstrap/process.go index a9cce4f31a7..f4f9e5948cc 100644 --- a/epochStart/bootstrap/process.go +++ b/epochStart/bootstrap/process.go @@ -798,7 +798,6 @@ func (e *epochStartBootstrap) requestAndProcessForMeta(peerMiniBlocks []*block.M e.nodeProcessingMode, e.cryptoComponentsHolder.ManagedPeersHolder(), e.stateStatsHandler, - e.coreComponentsHolder.PersisterFactory(), ) if err != nil { return err @@ -969,7 +968,6 @@ func (e *epochStartBootstrap) requestAndProcessForShard(peerMiniBlocks []*block. e.nodeProcessingMode, e.cryptoComponentsHolder.ManagedPeersHolder(), e.stateStatsHandler, - e.coreComponentsHolder.PersisterFactory(), ) if err != nil { return err @@ -1158,7 +1156,6 @@ func (e *epochStartBootstrap) createStorageService( RepopulateTokensSupplies: e.flagsConfig.RepopulateTokensSupplies, ManagedPeersHolder: e.cryptoComponentsHolder.ManagedPeersHolder(), StateStatsHandler: e.stateStatsHandler, - PersisterFactory: e.coreComponentsHolder.PersisterFactory(), }) if err != nil { return nil, err diff --git a/epochStart/bootstrap/process_test.go b/epochStart/bootstrap/process_test.go index e70384832b1..d95d97282d5 100644 --- a/epochStart/bootstrap/process_test.go +++ b/epochStart/bootstrap/process_test.go @@ -86,7 +86,6 @@ func createComponentsForEpochStart() (*mock.CoreComponentsMock, *mock.CryptoComp ProcessStatusHandlerInstance: &testscommon.ProcessStatusHandlerStub{}, HardforkTriggerPubKeyField: []byte("provided hardfork pub key"), EnableEpochsHandlerField: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - PersisterFactoryField: newPersisterFactory(), }, &mock.CryptoComponentsMock{ PubKey: &cryptoMocks.PublicKeyStub{}, diff --git a/epochStart/bootstrap/shardStorageHandler.go b/epochStart/bootstrap/shardStorageHandler.go index d140801f3d0..881aedf74c2 100644 --- a/epochStart/bootstrap/shardStorageHandler.go +++ b/epochStart/bootstrap/shardStorageHandler.go @@ -43,7 +43,6 @@ func NewShardStorageHandler( nodeProcessingMode common.NodeProcessingMode, managedPeersHolder common.ManagedPeersHolder, stateStatsHandler common.StateStatisticsHandler, - persisterFactory storage.PersisterFactoryHandler, ) (*shardStorageHandler, error) { epochStartNotifier := &disabled.EpochStartNotifier{} storageFactory, err := factory.NewStorageServiceFactory( @@ -61,7 +60,6 @@ func NewShardStorageHandler( RepopulateTokensSupplies: false, // tokens supplies cannot be repopulated at this time ManagedPeersHolder: managedPeersHolder, StateStatsHandler: stateStatsHandler, - PersisterFactory: persisterFactory, }, ) if err != nil { diff --git a/epochStart/bootstrap/shardStorageHandler_test.go b/epochStart/bootstrap/shardStorageHandler_test.go index ff27032add8..b27f13df28b 100644 --- a/epochStart/bootstrap/shardStorageHandler_test.go +++ b/epochStart/bootstrap/shardStorageHandler_test.go @@ -55,7 +55,6 @@ func TestNewShardStorageHandler_ShouldWork(t *testing.T) { args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) assert.False(t, check.IfNil(shardStorage)) @@ -81,7 +80,6 @@ func TestShardStorageHandler_SaveDataToStorageShardDataNotFound(t *testing.T) { args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) components := &ComponentsNeededForBootstrap{ @@ -113,7 +111,6 @@ func TestShardStorageHandler_SaveDataToStorageMissingHeader(t *testing.T) { args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) components := &ComponentsNeededForBootstrap{ @@ -168,7 +165,6 @@ func testShardWithMissingStorer(missingUnit dataRetriever.UnitType, atCallNumber args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) shardStorage.storageService = &storageStubs.ChainStorerStub{ GetStorerCalled: func(unitType dataRetriever.UnitType) (storage.Storer, error) { @@ -224,7 +220,6 @@ func TestShardStorageHandler_SaveDataToStorage(t *testing.T) { args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) hash1 := []byte("hash1") @@ -337,7 +332,6 @@ func TestShardStorageHandler_getCrossProcessedMiniBlockHeadersDestMe(t *testing. args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) shardHeader := &block.Header{ Nonce: 100, @@ -371,7 +365,6 @@ func TestShardStorageHandler_getProcessedAndPendingMiniBlocksWithScheduledErrorG args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) meta := &block.MetaBlock{ Nonce: 100, @@ -403,7 +396,6 @@ func TestShardStorageHandler_getProcessedAndPendingMiniBlocksWithScheduledNoSche args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) scenario := createPendingAndProcessedMiniBlocksScenario() @@ -432,7 +424,6 @@ func TestShardStorageHandler_getProcessedAndPendingMiniBlocksWithScheduledWrongH args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) scenario := createPendingAndProcessedMiniBlocksScenario() @@ -468,7 +459,6 @@ func TestShardStorageHandler_getProcessedAndPendingMiniBlocksWithScheduled(t *te args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) scenario := createPendingAndProcessedMiniBlocksScenario() processedMiniBlocks, pendingMiniBlocks, err := shardStorage.getProcessedAndPendingMiniBlocksWithScheduled(scenario.metaBlock, scenario.headers, scenario.shardHeader, true) @@ -650,7 +640,6 @@ func TestShardStorageHandler_getProcessedAndPendingMiniBlocksErrorGettingEpochSt args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) meta := &block.MetaBlock{ Nonce: 100, @@ -687,7 +676,6 @@ func TestShardStorageHandler_getProcessedAndPendingMiniBlocksMissingHeader(t *te args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) meta := &block.MetaBlock{ Nonce: 100, @@ -727,7 +715,6 @@ func TestShardStorageHandler_getProcessedAndPendingMiniBlocksWrongHeader(t *test args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) lastFinishedHeaders := createDefaultEpochStartShardData([]byte(lastFinishedMetaBlockHash), []byte("headerHash")) lastFinishedHeaders[0].FirstPendingMetaBlock = []byte(firstPendingMeta) @@ -772,7 +759,6 @@ func TestShardStorageHandler_getProcessedAndPendingMiniBlocksNilMetaBlock(t *tes args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) lastFinishedHeaders := createDefaultEpochStartShardData([]byte(lastFinishedMetaBlockHash), []byte("headerHash")) lastFinishedHeaders[0].FirstPendingMetaBlock = []byte(firstPendingMeta) @@ -819,7 +805,6 @@ func TestShardStorageHandler_getProcessedAndPendingMiniBlocksNoProcessedNoPendin args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) lastFinishedHeaders := createDefaultEpochStartShardData([]byte(lastFinishedMetaBlockHash), []byte("headerHash")) lastFinishedHeaders[0].FirstPendingMetaBlock = []byte(firstPendingMeta) @@ -862,7 +847,6 @@ func TestShardStorageHandler_getProcessedAndPendingMiniBlocksWithProcessedAndPen args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) scenario := createPendingAndProcessedMiniBlocksScenario() processedMiniBlocks, pendingMiniBlocks, firstPendingMetaBlockHash, err := shardStorage.getProcessedAndPendingMiniBlocks(scenario.metaBlock, scenario.headers) @@ -894,7 +878,6 @@ func TestShardStorageHandler_saveLastCrossNotarizedHeadersWithoutScheduledGetSha args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) headers := map[string]data.HeaderHandler{} @@ -929,7 +912,6 @@ func TestShardStorageHandler_saveLastCrossNotarizedHeadersWithoutScheduledMissin args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) shard0HeaderHash := "shard0 header hash" lastFinishedMetaBlock := "last finished meta block" @@ -972,7 +954,6 @@ func TestShardStorageHandler_saveLastCrossNotarizedHeadersWithoutScheduledWrongT args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) shard0HeaderHash := "shard0 header hash" lastFinishedMetaBlock := "last finished meta block" @@ -1022,7 +1003,6 @@ func TestShardStorageHandler_saveLastCrossNotarizedHeadersWithoutScheduledErrorW args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) shard0HeaderHash := "shard0 header hash" lastFinishedMetaBlock := "last finished meta block" @@ -1067,7 +1047,6 @@ func TestShardStorageHandler_saveLastCrossNotarizedHeadersWithoutScheduled(t *te args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) shard0HeaderHash := "shard0 header hash" lastFinishedMetaBlock := "last finished meta block" @@ -1117,7 +1096,6 @@ func TestShardStorageHandler_saveLastCrossNotarizedHeadersWithScheduledErrorUpda args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) shard0HeaderHash := "shard0 header hash" lastFinishedMetaBlock := "last finished meta block" @@ -1161,7 +1139,6 @@ func TestShardStorageHandler_saveLastCrossNotarizedHeadersWithScheduled(t *testi args.nodeProcessingMode, args.managedPeersHolder, disabled.NewStateStatistics(), - newPersisterFactory(), ) shard0HeaderHash := "shard0 header hash" lastFinishedMetaBlock := "last finished meta block" diff --git a/epochStart/metachain/systemSCs_test.go b/epochStart/metachain/systemSCs_test.go index 2e86bf27bd8..112f3becc2e 100644 --- a/epochStart/metachain/systemSCs_test.go +++ b/epochStart/metachain/systemSCs_test.go @@ -47,7 +47,6 @@ import ( dataRetrieverMock "github.com/multiversx/mx-chain-go/testscommon/dataRetriever" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" - "github.com/multiversx/mx-chain-go/testscommon/persister" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" statusHandlerMock "github.com/multiversx/mx-chain-go/testscommon/statusHandler" storageMock "github.com/multiversx/mx-chain-go/testscommon/storage" @@ -87,7 +86,7 @@ func createPhysicalUnit(t *testing.T) (storage.Storer, string) { MaxOpenFiles: 10, } - pfh := persister.NewPersisterFactory() + pfh := storageMock.NewPersisterFactory() persisterFactory, err := pfh.CreatePersisterHandler(dbConfig) assert.Nil(t, err) @@ -989,7 +988,7 @@ func createFullArgumentsForSystemSCProcessing(enableEpochsConfig config.EnableEp GasSchedule: gasScheduleNotifier, Counter: &testscommon.BlockChainHookCounterStub{}, MissingTrieNodesNotifier: &testscommon.MissingTrieNodesNotifierStub{}, - PersisterFactory: persister.NewPersisterFactory(), + PersisterFactory: storageMock.NewPersisterFactory(), } blockChainHookImpl, _ := hooks.NewBlockChainHookImpl(argsHook) diff --git a/epochStart/mock/coreComponentsMock.go b/epochStart/mock/coreComponentsMock.go index a9eaa75c4be..b2f0003d842 100644 --- a/epochStart/mock/coreComponentsMock.go +++ b/epochStart/mock/coreComponentsMock.go @@ -34,7 +34,6 @@ type CoreComponentsMock struct { NodeTypeProviderField core.NodeTypeProviderHandler ProcessStatusHandlerInstance common.ProcessStatusHandler HardforkTriggerPubKeyField []byte - PersisterFactoryField storage.PersisterFactoryHandler mutCore sync.RWMutex } @@ -156,11 +155,6 @@ func (ccm *CoreComponentsMock) HardforkTriggerPubKey() []byte { return ccm.HardforkTriggerPubKeyField } -// PersisterFactory - -func (ccm *CoreComponentsMock) PersisterFactory() storage.PersisterFactoryHandler { - return ccm.PersisterFactoryField -} - // IsInterfaceNil - func (ccm *CoreComponentsMock) IsInterfaceNil() bool { return ccm == nil diff --git a/factory/bootstrap/bootstrapComponents.go b/factory/bootstrap/bootstrapComponents.go index 8472896bef3..988b72764e0 100644 --- a/factory/bootstrap/bootstrapComponents.go +++ b/factory/bootstrap/bootstrapComponents.go @@ -165,7 +165,6 @@ func (bcf *bootstrapComponentsFactory) Create() (*bootstrapComponents, error) { unitOpener, err := createUnitOpener( bootstrapDataProvider, latestStorageDataProvider, - bcf.coreComponents.PersisterFactory(), storage.DefaultEpochString, storage.DefaultShardString, ) @@ -338,14 +337,12 @@ func createLatestStorageDataProvider( func createUnitOpener( bootstrapDataProvider storageFactory.BootstrapDataProviderHandler, latestDataFromStorageProvider storage.LatestStorageDataProviderHandler, - persisterFactory storage.PersisterFactoryHandler, defaultEpochString string, defaultShardString string, ) (storage.UnitOpenerHandler, error) { argsStorageUnitOpener := storageFactory.ArgsNewOpenStorageUnits{ BootstrapDataProvider: bootstrapDataProvider, LatestStorageDataProvider: latestDataFromStorageProvider, - PersisterFactory: persisterFactory, DefaultEpochString: defaultEpochString, DefaultShardString: defaultShardString, } diff --git a/factory/data/dataComponents.go b/factory/data/dataComponents.go index 3b65a531282..c39ad9838b5 100644 --- a/factory/data/dataComponents.go +++ b/factory/data/dataComponents.go @@ -175,7 +175,6 @@ func (dcf *dataComponentsFactory) createDataStoreFromConfig() (dataRetriever.Sto RepopulateTokensSupplies: dcf.flagsConfig.RepopulateTokensSupplies, ManagedPeersHolder: dcf.crypto.ManagedPeersHolder(), StateStatsHandler: dcf.statusCore.StateStatsHandler(), - PersisterFactory: dcf.core.PersisterFactory(), }) if err != nil { return nil, err diff --git a/factory/processing/blockProcessorCreator.go b/factory/processing/blockProcessorCreator.go index 873f28c7028..7bccd5d8af0 100644 --- a/factory/processing/blockProcessorCreator.go +++ b/factory/processing/blockProcessorCreator.go @@ -995,7 +995,6 @@ func (pcf *processComponentsFactory) createVMFactoryShard( GasSchedule: pcf.gasSchedule, Counter: counter, MissingTrieNodesNotifier: notifier, - PersisterFactory: pcf.coreData.PersisterFactory(), } blockChainHookImpl, err := hooks.NewBlockChainHookImpl(argsHook) @@ -1047,7 +1046,6 @@ func (pcf *processComponentsFactory) createVMFactoryMeta( GasSchedule: pcf.gasSchedule, Counter: counters.NewDisabledCounter(), MissingTrieNodesNotifier: syncer.NewMissingTrieNodesNotifier(), - PersisterFactory: pcf.coreData.PersisterFactory(), } blockChainHookImpl, err := hooks.NewBlockChainHookImpl(argsHook) diff --git a/factory/processing/processComponents.go b/factory/processing/processComponents.go index 8c5b3384de8..7ec9e8d9078 100644 --- a/factory/processing/processComponents.go +++ b/factory/processing/processComponents.go @@ -1530,7 +1530,6 @@ func (pcf *processComponentsFactory) newStorageRequesters() (dataRetriever.Reque RepopulateTokensSupplies: pcf.flagsConfig.RepopulateTokensSupplies, ManagedPeersHolder: pcf.crypto.ManagedPeersHolder(), StateStatsHandler: pcf.statusCoreComponents.StateStatsHandler(), - PersisterFactory: pcf.coreData.PersisterFactory(), }, ) if err != nil { diff --git a/genesis/process/genesisBlockCreator.go b/genesis/process/genesisBlockCreator.go index c595c039b0a..306459bacfe 100644 --- a/genesis/process/genesisBlockCreator.go +++ b/genesis/process/genesisBlockCreator.go @@ -452,7 +452,6 @@ func (gbc *genesisBlockCreator) computeDNSAddresses(enableEpochsConfig config.En GasSchedule: gbc.arg.GasSchedule, Counter: counters.NewDisabledCounter(), MissingTrieNodesNotifier: syncer.NewMissingTrieNodesNotifier(), - PersisterFactory: gbc.arg.Core.PersisterFactory(), } blockChainHook, err := hooks.NewBlockChainHookImpl(argsHook) if err != nil { diff --git a/genesis/process/metaGenesisBlockCreator.go b/genesis/process/metaGenesisBlockCreator.go index dfda9343faa..40b5f606241 100644 --- a/genesis/process/metaGenesisBlockCreator.go +++ b/genesis/process/metaGenesisBlockCreator.go @@ -333,7 +333,6 @@ func createProcessorsForMetaGenesisBlock(arg ArgsGenesisBlockCreator, enableEpoc GasSchedule: arg.GasSchedule, Counter: counters.NewDisabledCounter(), MissingTrieNodesNotifier: syncer.NewMissingTrieNodesNotifier(), - PersisterFactory: arg.Core.PersisterFactory(), } pubKeyVerifier, err := disabled.NewMessageSignVerifier(arg.BlockSignKeyGen) diff --git a/genesis/process/shardGenesisBlockCreator.go b/genesis/process/shardGenesisBlockCreator.go index b5a5fe44173..9fef8f05569 100644 --- a/genesis/process/shardGenesisBlockCreator.go +++ b/genesis/process/shardGenesisBlockCreator.go @@ -451,7 +451,6 @@ func createProcessorsForShardGenesisBlock(arg ArgsGenesisBlockCreator, enableEpo GasSchedule: arg.GasSchedule, Counter: counters.NewDisabledCounter(), MissingTrieNodesNotifier: syncer.NewMissingTrieNodesNotifier(), - PersisterFactory: arg.Core.PersisterFactory(), } esdtTransferParser, err := parsers.NewESDTTransferParser(arg.Core.InternalMarshalizer()) if err != nil { diff --git a/integrationTests/multiShard/endOfEpoch/startInEpoch/startInEpoch_test.go b/integrationTests/multiShard/endOfEpoch/startInEpoch/startInEpoch_test.go index dbda0db689c..8ce1b1a72ec 100644 --- a/integrationTests/multiShard/endOfEpoch/startInEpoch/startInEpoch_test.go +++ b/integrationTests/multiShard/endOfEpoch/startInEpoch/startInEpoch_test.go @@ -296,7 +296,6 @@ func testNodeStartsInEpoch(t *testing.T, shardID uint32, expectedHighestRound ui NodeProcessingMode: common.Normal, ManagedPeersHolder: &testscommon.ManagedPeersHolderStub{}, StateStatsHandler: disabled.NewStateStatistics(), - PersisterFactory: coreComponents.PersisterFactoryField, }, ) assert.NoError(t, err) diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index 8871654dd8d..8005c927ffb 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -114,7 +114,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/mainFactoryMocks" "github.com/multiversx/mx-chain-go/testscommon/outport" "github.com/multiversx/mx-chain-go/testscommon/p2pmocks" - "github.com/multiversx/mx-chain-go/testscommon/persister" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" statusHandlerMock "github.com/multiversx/mx-chain-go/testscommon/statusHandler" @@ -888,7 +887,6 @@ func (tpn *TestProcessorNode) createFullSCQueryService(gasMap map[string]map[str GasSchedule: gasSchedule, Counter: counters.NewDisabledCounter(), MissingTrieNodesNotifier: &testscommon.MissingTrieNodesNotifierStub{}, - PersisterFactory: persister.NewPersisterFactory(), } var apiBlockchain data.ChainHandler @@ -1621,7 +1619,6 @@ func (tpn *TestProcessorNode) initInnerProcessors(gasMap map[string]map[string]u GasSchedule: gasSchedule, Counter: counter, MissingTrieNodesNotifier: &testscommon.MissingTrieNodesNotifierStub{}, - PersisterFactory: persister.NewPersisterFactory(), } maxGasLimitPerBlock := uint64(0xFFFFFFFFFFFFFFFF) @@ -1848,7 +1845,6 @@ func (tpn *TestProcessorNode) initMetaInnerProcessors(gasMap map[string]map[stri GasSchedule: gasSchedule, Counter: counters.NewDisabledCounter(), MissingTrieNodesNotifier: &testscommon.MissingTrieNodesNotifierStub{}, - PersisterFactory: persister.NewPersisterFactory(), } var signVerifier vm.MessageSignVerifier @@ -3263,7 +3259,7 @@ func GetDefaultCoreComponents() *mock.CoreComponentsStub { TxVersionCheckField: versioning.NewTxVersionChecker(MinTransactionVersion), ProcessStatusHandlerInternal: &testscommon.ProcessStatusHandlerStub{}, EnableEpochsHandlerField: enableEpochsHandler, - PersisterFactoryField: persister.NewPersisterFactory(), + PersisterFactoryField: storageStubs.NewPersisterFactory(), } } diff --git a/integrationTests/vm/testInitializer.go b/integrationTests/vm/testInitializer.go index c414d4c25b9..0c9fa15b273 100644 --- a/integrationTests/vm/testInitializer.go +++ b/integrationTests/vm/testInitializer.go @@ -61,7 +61,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" "github.com/multiversx/mx-chain-go/testscommon/integrationtests" - "github.com/multiversx/mx-chain-go/testscommon/persister" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" "github.com/multiversx/mx-chain-go/testscommon/txDataBuilder" @@ -421,7 +420,6 @@ func CreateTxProcessorWithOneSCExecutorMockVM( GasSchedule: gasScheduleNotifier, Counter: &testscommon.BlockChainHookCounterStub{}, MissingTrieNodesNotifier: &testscommon.MissingTrieNodesNotifierStub{}, - PersisterFactory: persister.NewPersisterFactory(), } blockChainHook, _ := hooks.NewBlockChainHookImpl(args) @@ -530,7 +528,6 @@ func CreateOneSCExecutorMockVM(accnts state.AccountsAdapter) vmcommon.VMExecutio GasSchedule: CreateMockGasScheduleNotifier(), Counter: &testscommon.BlockChainHookCounterStub{}, MissingTrieNodesNotifier: &testscommon.MissingTrieNodesNotifierStub{}, - PersisterFactory: persister.NewPersisterFactory(), } blockChainHook, _ := hooks.NewBlockChainHookImpl(args) vm, _ := mock.NewOneSCExecutorMockVM(blockChainHook, integrationtests.TestHasher) @@ -602,7 +599,6 @@ func CreateVMAndBlockchainHookAndDataPool( GasSchedule: gasSchedule, Counter: counter, MissingTrieNodesNotifier: &testscommon.MissingTrieNodesNotifierStub{}, - PersisterFactory: persister.NewPersisterFactory(), } maxGasLimitPerBlock := uint64(0xFFFFFFFFFFFFFFFF) @@ -692,7 +688,6 @@ func CreateVMAndBlockchainHookMeta( GasSchedule: gasSchedule, Counter: &testscommon.BlockChainHookCounterStub{}, MissingTrieNodesNotifier: &testscommon.MissingTrieNodesNotifierStub{}, - PersisterFactory: persister.NewPersisterFactory(), } economicsData, err := createEconomicsData(config.EnableEpochs{}) diff --git a/integrationTests/vm/wasm/delegation/testRunner.go b/integrationTests/vm/wasm/delegation/testRunner.go index ccbdb64dbe7..10ba746d95b 100644 --- a/integrationTests/vm/wasm/delegation/testRunner.go +++ b/integrationTests/vm/wasm/delegation/testRunner.go @@ -17,7 +17,7 @@ import ( "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/storage/storageunit" - "github.com/multiversx/mx-chain-go/testscommon/persister" + "github.com/multiversx/mx-chain-go/testscommon/storage" systemVm "github.com/multiversx/mx-chain-go/vm" logger "github.com/multiversx/mx-chain-logger-go" vmcommon "github.com/multiversx/mx-chain-vm-common-go" @@ -53,7 +53,7 @@ func RunDelegationStressTest( MaxBatchSize: 45000, MaxOpenFiles: 10, } - pfh := persister.NewPersisterFactory() + pfh := storage.NewPersisterFactory() persisterFactory, err := pfh.CreatePersisterHandler(dbConfig) if err != nil { return nil, err diff --git a/integrationTests/vm/wasm/utils.go b/integrationTests/vm/wasm/utils.go index ca29bf29730..e58d3e25c7b 100644 --- a/integrationTests/vm/wasm/utils.go +++ b/integrationTests/vm/wasm/utils.go @@ -52,7 +52,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/guardianMocks" "github.com/multiversx/mx-chain-go/testscommon/integrationtests" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" - "github.com/multiversx/mx-chain-go/testscommon/persister" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" "github.com/multiversx/mx-chain-go/vm/systemSmartContracts/defaults" vmcommon "github.com/multiversx/mx-chain-vm-common-go" @@ -312,7 +311,6 @@ func (context *TestContext) initVMAndBlockchainHook() { GasSchedule: gasSchedule, Counter: &testscommon.BlockChainHookCounterStub{}, MissingTrieNodesNotifier: &testscommon.MissingTrieNodesNotifierStub{}, - PersisterFactory: persister.NewPersisterFactory(), } vmFactoryConfig := config.VirtualMachineConfig{ diff --git a/process/smartContract/hooks/blockChainHook_test.go b/process/smartContract/hooks/blockChainHook_test.go index bbf51b10421..92636c1baf0 100644 --- a/process/smartContract/hooks/blockChainHook_test.go +++ b/process/smartContract/hooks/blockChainHook_test.go @@ -30,7 +30,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" - "github.com/multiversx/mx-chain-go/testscommon/persister" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" "github.com/multiversx/mx-chain-go/testscommon/trie" @@ -70,7 +69,6 @@ func createMockBlockChainHookArgs() hooks.ArgBlockChainHook { GasSchedule: testscommon.NewGasScheduleNotifierMock(make(map[string]map[string]uint64)), Counter: &testscommon.BlockChainHookCounterStub{}, MissingTrieNodesNotifier: &testscommon.MissingTrieNodesNotifierStub{}, - PersisterFactory: persister.NewPersisterFactory(), } return arguments } diff --git a/storage/factory/openStorage_test.go b/storage/factory/openStorage_test.go index c0b526d14a9..1a1273df5f4 100644 --- a/storage/factory/openStorage_test.go +++ b/storage/factory/openStorage_test.go @@ -18,7 +18,6 @@ func createMockArgsOpenStorageUnits() ArgsNewOpenStorageUnits { return ArgsNewOpenStorageUnits{ BootstrapDataProvider: &mock.BootStrapDataProviderStub{}, LatestStorageDataProvider: &mock.LatestStorageDataProviderStub{}, - PersisterFactory: NewPersisterFactoryHandler(2, 1), DefaultEpochString: "Epoch", DefaultShardString: "Shard", } diff --git a/storage/factory/persisterFactory_test.go b/storage/factory/persisterFactory_test.go index 42b4bb9e3ec..145bdd4a844 100644 --- a/storage/factory/persisterFactory_test.go +++ b/storage/factory/persisterFactory_test.go @@ -5,7 +5,6 @@ import ( "os" "testing" - "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/storage/factory" "github.com/multiversx/mx-chain-go/storage/storageunit" @@ -13,15 +12,10 @@ import ( "github.com/stretchr/testify/require" ) -func createPersisterFactory(config config.DBConfig) (storage.PersisterCreator, error) { - pfh := factory.NewPersisterFactoryHandler(2, 1) - return pfh.CreatePersisterHandler(config) -} - func TestNewPersisterFactory(t *testing.T) { t.Parallel() - pf, err := createPersisterFactory(createDefaultDBConfig()) + pf, err := factory.NewPersisterFactory(createDefaultDBConfig()) require.NotNil(t, pf) require.Nil(t, err) } @@ -32,7 +26,7 @@ func TestPersisterFactory_Create(t *testing.T) { t.Run("invalid file path, should fail", func(t *testing.T) { t.Parallel() - pf, _ := createPersisterFactory(createDefaultDBConfig()) + pf, _ := factory.NewPersisterFactory(createDefaultDBConfig()) p, err := pf.Create("") require.Nil(t, p) @@ -42,7 +36,7 @@ func TestPersisterFactory_Create(t *testing.T) { t.Run("should work", func(t *testing.T) { t.Parallel() - pf, _ := createPersisterFactory(createDefaultDBConfig()) + pf, _ := factory.NewPersisterFactory(createDefaultDBConfig()) dir := t.TempDir() @@ -58,7 +52,7 @@ func TestPersisterFactory_CreateWithRetries(t *testing.T) { t.Run("invalid file path, should fail", func(t *testing.T) { t.Parallel() - pf, _ := createPersisterFactory(createDefaultDBConfig()) + pf, _ := factory.NewPersisterFactory(createDefaultDBConfig()) p, err := pf.CreateWithRetries("") require.Nil(t, p) @@ -68,7 +62,7 @@ func TestPersisterFactory_CreateWithRetries(t *testing.T) { t.Run("should work", func(t *testing.T) { t.Parallel() - pf, _ := createPersisterFactory(createDefaultDBConfig()) + pf, _ := factory.NewPersisterFactory(createDefaultDBConfig()) dir := t.TempDir() @@ -86,7 +80,7 @@ func TestPersisterFactory_Create_ConfigSaveToFilePath(t *testing.T) { dbConfig := createDefaultBasePersisterConfig() dbConfig.Type = string(storageunit.LvlDB) - pf, _ := createPersisterFactory(dbConfig) + pf, _ := factory.NewPersisterFactory(dbConfig) dir := t.TempDir() path := dir + "storer/" @@ -105,7 +99,7 @@ func TestPersisterFactory_Create_ConfigSaveToFilePath(t *testing.T) { dbConfig := createDefaultBasePersisterConfig() dbConfig.Type = string(storageunit.LvlDBSerial) - pf, _ := createPersisterFactory(dbConfig) + pf, _ := factory.NewPersisterFactory(dbConfig) dir := t.TempDir() path := dir + "storer/" @@ -124,7 +118,7 @@ func TestPersisterFactory_Create_ConfigSaveToFilePath(t *testing.T) { dbConfig := createDefaultBasePersisterConfig() dbConfig.Type = string(storageunit.MemoryDB) - pf, _ := createPersisterFactory(dbConfig) + pf, _ := factory.NewPersisterFactory(dbConfig) dir := t.TempDir() path := dir + "storer/" @@ -143,7 +137,7 @@ func TestPersisterFactory_Create_ConfigSaveToFilePath(t *testing.T) { dbConfig := createDefaultBasePersisterConfig() dbConfig.Type = string(storageunit.MemoryDB) - pf, _ := createPersisterFactory(dbConfig) + pf, _ := factory.NewPersisterFactory(dbConfig) dir := t.TempDir() path := dir + "storer/" @@ -160,7 +154,7 @@ func TestPersisterFactory_Create_ConfigSaveToFilePath(t *testing.T) { func TestPersisterFactory_CreateDisabled(t *testing.T) { t.Parallel() - factoryInstance, err := createPersisterFactory(createDefaultDBConfig()) + factoryInstance, err := factory.NewPersisterFactory(createDefaultDBConfig()) require.Nil(t, err) persisterInstance := factoryInstance.CreateDisabled() @@ -171,6 +165,6 @@ func TestPersisterFactory_CreateDisabled(t *testing.T) { func TestPersisterFactory_IsInterfaceNil(t *testing.T) { t.Parallel() - pf, _ := createPersisterFactory(createDefaultDBConfig()) + pf, _ := factory.NewPersisterFactory(createDefaultDBConfig()) require.False(t, pf.IsInterfaceNil()) } diff --git a/storage/factory/storageServiceFactory_test.go b/storage/factory/storageServiceFactory_test.go index 2363a7e2149..310ecb89a5a 100644 --- a/storage/factory/storageServiceFactory_test.go +++ b/storage/factory/storageServiceFactory_test.go @@ -76,7 +76,6 @@ func createMockArgument(t *testing.T) StorageServiceFactoryArgs { CreateTrieEpochRootHashStorer: true, ManagedPeersHolder: &testscommon.ManagedPeersHolderStub{}, StateStatsHandler: disabledStatistics.NewStateStatistics(), - PersisterFactory: NewPersisterFactoryHandler(2, 1), } } diff --git a/storage/latestData/latestDataProvider_test.go b/storage/latestData/latestDataProvider_test.go index c50e30b680e..e2d4c561ae0 100644 --- a/storage/latestData/latestDataProvider_test.go +++ b/storage/latestData/latestDataProvider_test.go @@ -14,7 +14,6 @@ import ( "github.com/multiversx/mx-chain-go/process/block/bootstrapStorage" "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/storage/mock" - "github.com/multiversx/mx-chain-go/testscommon/persister" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -153,7 +152,6 @@ func getLatestDataProviderArgs() ArgsLatestDataProvider { GeneralConfig: config.Config{}, BootstrapDataProvider: &mock.BootStrapDataProviderStub{}, DirectoryReader: &mock.DirectoryReaderStub{}, - PersisterFactory: persister.NewPersisterFactory(), ParentDir: "db", DefaultEpochString: "Epoch", DefaultShardString: "Shard", diff --git a/storage/pruning/fullHistoryPruningStorer_test.go b/storage/pruning/fullHistoryPruningStorer_test.go index b3e58a09bd7..0e0d43877e8 100644 --- a/storage/pruning/fullHistoryPruningStorer_test.go +++ b/storage/pruning/fullHistoryPruningStorer_test.go @@ -294,8 +294,7 @@ func TestFullHistoryPruningStorer_ConcurrentOperations(t *testing.T) { fmt.Println(testDir) args := getDefaultArgs() - pfh := factory.NewPersisterFactoryHandler(2, 1) - persisterFactory, err := pfh.CreatePersisterHandler(config.DBConfig{ + persisterFactory, err := factory.NewPersisterFactory(config.DBConfig{ FilePath: filepath.Join(testDir, dbName), Type: "LvlDBSerial", MaxBatchSize: 100, diff --git a/storage/pruning/pruningStorer_test.go b/storage/pruning/pruningStorer_test.go index 925f7710400..248cc53cda2 100644 --- a/storage/pruning/pruningStorer_test.go +++ b/storage/pruning/pruningStorer_test.go @@ -22,12 +22,12 @@ import ( "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/storage/database" "github.com/multiversx/mx-chain-go/storage/directoryhandler" + "github.com/multiversx/mx-chain-go/storage/factory" "github.com/multiversx/mx-chain-go/storage/mock" "github.com/multiversx/mx-chain-go/storage/pathmanager" "github.com/multiversx/mx-chain-go/storage/pruning" "github.com/multiversx/mx-chain-go/storage/storageunit" "github.com/multiversx/mx-chain-go/testscommon" - "github.com/multiversx/mx-chain-go/testscommon/persister" logger "github.com/multiversx/mx-chain-logger-go" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -1053,8 +1053,7 @@ func TestPruningStorer_ConcurrentOperations(t *testing.T) { fmt.Println(testDir) args := getDefaultArgs() - pfh := persister.NewPersisterFactory() - persisterFactory, err := pfh.CreatePersisterHandler(config.DBConfig{ + persisterFactory, err := factory.NewPersisterFactory(config.DBConfig{ FilePath: filepath.Join(testDir, dbName), Type: "LvlDBSerial", MaxBatchSize: 100, diff --git a/storage/storageunit/storageunit_test.go b/storage/storageunit/storageunit_test.go index 4871231a737..0652f25b33c 100644 --- a/storage/storageunit/storageunit_test.go +++ b/storage/storageunit/storageunit_test.go @@ -6,22 +6,16 @@ import ( "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-go/config" - "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/storage/factory" "github.com/multiversx/mx-chain-go/storage/mock" "github.com/multiversx/mx-chain-go/storage/storageunit" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" - storageMock "github.com/multiversx/mx-chain-go/testscommon/storage" + "github.com/multiversx/mx-chain-go/testscommon/storage" "github.com/multiversx/mx-chain-storage-go/common" "github.com/stretchr/testify/assert" ) -func createPersisterFactory(config config.DBConfig) (storage.PersisterCreator, error) { - pfh := factory.NewPersisterFactoryHandler(2, 1) - return pfh.CreatePersisterHandler(config) -} - func TestNewStorageUnit(t *testing.T) { t.Parallel() @@ -93,7 +87,7 @@ func TestNewDB(t *testing.T) { MaxOpenFiles: 10, } - persisterFactory, err := createPersisterFactory(dbConfig) + persisterFactory, err := factory.NewPersisterFactory(dbConfig) assert.Nil(t, err) db, err := persisterFactory.CreateWithRetries(path) @@ -112,7 +106,7 @@ func TestNewDB(t *testing.T) { MaxOpenFiles: 10, } - persisterFactory, err := createPersisterFactory(dbConfig) + persisterFactory, err := factory.NewPersisterFactory(dbConfig) assert.Nil(t, err) db, err := persisterFactory.CreateWithRetries(path) @@ -148,7 +142,7 @@ func TestNewStorageUnitFromConf(t *testing.T) { MaxBatchSize: dbConfig.MaxBatchSize, MaxOpenFiles: dbConfig.MaxOpenFiles, } - persisterFactory, err := createPersisterFactory(dbConf) + persisterFactory, err := factory.NewPersisterFactory(dbConf) assert.Nil(t, err) unit, err := storageunit.NewStorageUnitFromConf(cacheConfig, dbConfig, persisterFactory) @@ -169,7 +163,7 @@ func TestNewStorageUnitFromConf(t *testing.T) { MaxBatchSize: dbConfig.MaxBatchSize, MaxOpenFiles: dbConfig.MaxOpenFiles, } - persisterFactory, err := createPersisterFactory(dbConf) + persisterFactory, err := factory.NewPersisterFactory(dbConf) assert.Nil(t, err) unit, err := storageunit.NewStorageUnitFromConf(cacheConfig, dbConfig, persisterFactory) @@ -191,7 +185,7 @@ func TestNewStorageCacherAdapter(t *testing.T) { cacher := &mock.AdaptedSizedLruCacheStub{} db := &mock.PersisterStub{} - storedDataFactory := &storageMock.StoredDataFactoryStub{} + storedDataFactory := &storage.StoredDataFactoryStub{} marshaller := &marshallerMock.MarshalizerStub{} t.Run("nil parameter should error", func(t *testing.T) { diff --git a/testscommon/persister/common.go b/testscommon/storage/common.go similarity index 93% rename from testscommon/persister/common.go rename to testscommon/storage/common.go index c0d3eb141d0..b1b275e7966 100644 --- a/testscommon/persister/common.go +++ b/testscommon/storage/common.go @@ -1,4 +1,4 @@ -package persister +package storage import ( "github.com/multiversx/mx-chain-go/storage" From 58baed5f82323c68da408c93aeb33dda4157b6d8 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Fri, 12 Jan 2024 12:19:29 +0200 Subject: [PATCH 042/503] Revert "persister factory in core components" This reverts commit 6f0041d9de1069a2260bdfc2c94af9a4cee20044. --- config/config.go | 12 ++----- dataRetriever/factory/dataPoolFactory.go | 3 +- epochStart/bootstrap/process.go | 1 - epochStart/bootstrap/storageProcess.go | 1 - epochStart/metachain/systemSCs_test.go | 5 ++- errors/errors.go | 3 -- factory/api/apiResolverFactory.go | 1 - factory/core/coreComponents.go | 7 ---- factory/core/coreComponentsHandler.go | 15 --------- factory/data/dataComponents.go | 1 - factory/interface.go | 8 ----- genesis/process/argGenesisBlockCreator.go | 2 -- genesis/process/genesisBlockCreator.go | 8 ++--- integrationTests/mock/coreComponentsStub.go | 6 ---- integrationTests/testProcessorNode.go | 1 - .../vm/wasm/delegation/testRunner.go | 5 ++- process/interface.go | 1 - process/smartContract/hooks/blockChainHook.go | 10 +----- storage/database/db.go | 2 +- storage/factory/openStorage.go | 11 ++----- storage/factory/persisterCreator.go | 1 + storage/factory/persisterFactory.go | 32 ++++--------------- storage/factory/persisterFactory_test.go | 26 --------------- storage/factory/storageServiceFactory.go | 10 ++---- storage/interface.go | 10 ++---- storage/latestData/latestDataProvider.go | 10 ++---- storage/storageunit/storageunit.go | 2 +- testscommon/dataRetriever/poolFactory.go | 3 +- testscommon/integrationtests/factory.go | 4 +-- testscommon/storage/common.go | 11 ------- update/factory/dataTrieFactory.go | 9 ++---- update/factory/exportHandlerFactory.go | 8 ++--- 32 files changed, 38 insertions(+), 191 deletions(-) delete mode 100644 testscommon/storage/common.go diff --git a/config/config.go b/config/config.go index fca35d0be0d..5c489635269 100644 --- a/config/config.go +++ b/config/config.go @@ -222,10 +222,9 @@ type Config struct { Requesters RequesterConfig VMOutputCacher CacheConfig - PeersRatingConfig PeersRatingConfig - PoolsCleanersConfig PoolsCleanersConfig - Redundancy RedundancyConfig - PersisterCreatorConfig PersisterCreatorConfig + PeersRatingConfig PeersRatingConfig + PoolsCleanersConfig PoolsCleanersConfig + Redundancy RedundancyConfig } // PeersRatingConfig will hold settings related to peers rating @@ -631,8 +630,3 @@ type PoolsCleanersConfig struct { type RedundancyConfig struct { MaxRoundsOfInactivityAccepted int } - -type PersisterCreatorConfig struct { - MaxRetriesToCreateDB uint32 - SleepTimeBetweenRetriesInSec uint32 -} diff --git a/dataRetriever/factory/dataPoolFactory.go b/dataRetriever/factory/dataPoolFactory.go index 771575c984c..8d3ae50bdb0 100644 --- a/dataRetriever/factory/dataPoolFactory.go +++ b/dataRetriever/factory/dataPoolFactory.go @@ -39,7 +39,6 @@ type ArgsDataPool struct { ShardCoordinator sharding.Coordinator Marshalizer marshal.Marshalizer PathManager storage.PathManagerHandler - PersisterFactory storage.PersisterFactoryHandler } // NewDataPoolFromConfig will return a new instance of a PoolsHolder @@ -180,7 +179,7 @@ func createTrieSyncDB(args ArgsDataPool) (storage.Persister, error) { shardId := core.GetShardIDString(args.ShardCoordinator.SelfId()) path := args.PathManager.PathForStatic(shardId, mainConfig.TrieSyncStorage.DB.FilePath) - persisterFactory, err := args.PersisterFactory.CreatePersisterHandler(mainConfig.TrieSyncStorage.DB) + persisterFactory, err := factory.NewPersisterFactory(mainConfig.TrieSyncStorage.DB) if err != nil { return nil, err } diff --git a/epochStart/bootstrap/process.go b/epochStart/bootstrap/process.go index f4f9e5948cc..7c9e5820c48 100644 --- a/epochStart/bootstrap/process.go +++ b/epochStart/bootstrap/process.go @@ -354,7 +354,6 @@ func (e *epochStartBootstrap) Bootstrap() (Parameters, error) { ShardCoordinator: e.shardCoordinator, Marshalizer: e.coreComponentsHolder.InternalMarshalizer(), PathManager: e.coreComponentsHolder.PathHandler(), - PersisterFactory: e.coreComponentsHolder.PersisterFactory(), }, ) if err != nil { diff --git a/epochStart/bootstrap/storageProcess.go b/epochStart/bootstrap/storageProcess.go index 2bfe2f087ea..92679d045a2 100644 --- a/epochStart/bootstrap/storageProcess.go +++ b/epochStart/bootstrap/storageProcess.go @@ -109,7 +109,6 @@ func (sesb *storageEpochStartBootstrap) Bootstrap() (Parameters, error) { ShardCoordinator: sesb.shardCoordinator, Marshalizer: sesb.coreComponentsHolder.InternalMarshalizer(), PathManager: sesb.coreComponentsHolder.PathHandler(), - PersisterFactory: sesb.coreComponentsHolder.PersisterFactory(), }, ) if err != nil { diff --git a/epochStart/metachain/systemSCs_test.go b/epochStart/metachain/systemSCs_test.go index 112f3becc2e..f74f9238db9 100644 --- a/epochStart/metachain/systemSCs_test.go +++ b/epochStart/metachain/systemSCs_test.go @@ -41,6 +41,7 @@ import ( "github.com/multiversx/mx-chain-go/state/storagePruningManager" "github.com/multiversx/mx-chain-go/state/storagePruningManager/evictionWaitingList" "github.com/multiversx/mx-chain-go/storage" + storageFactory "github.com/multiversx/mx-chain-go/storage/factory" "github.com/multiversx/mx-chain-go/storage/storageunit" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/cryptoMocks" @@ -86,8 +87,7 @@ func createPhysicalUnit(t *testing.T) (storage.Storer, string) { MaxOpenFiles: 10, } - pfh := storageMock.NewPersisterFactory() - persisterFactory, err := pfh.CreatePersisterHandler(dbConfig) + persisterFactory, err := storageFactory.NewPersisterFactory(dbConfig) assert.Nil(t, err) cache, _ := storageunit.NewCache(cacheConfig) @@ -988,7 +988,6 @@ func createFullArgumentsForSystemSCProcessing(enableEpochsConfig config.EnableEp GasSchedule: gasScheduleNotifier, Counter: &testscommon.BlockChainHookCounterStub{}, MissingTrieNodesNotifier: &testscommon.MissingTrieNodesNotifierStub{}, - PersisterFactory: storageMock.NewPersisterFactory(), } blockChainHookImpl, _ := hooks.NewBlockChainHookImpl(argsHook) diff --git a/errors/errors.go b/errors/errors.go index a94c3648a87..81f547d8bea 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -232,9 +232,6 @@ var ErrNilMessenger = errors.New("nil messenger") // ErrNilMiniBlocksProvider signals a nil miniBlocks provider var ErrNilMiniBlocksProvider = errors.New("nil miniBlocks provider") -// ErrNilPersisterFactory signals a nil persister factory -var ErrNilPersisterFactory = errors.New("nil persister factory") - // ErrNilMultiSigner signals that a nil multi-signer was provided var ErrNilMultiSigner = errors.New("nil multi signer") diff --git a/factory/api/apiResolverFactory.go b/factory/api/apiResolverFactory.go index 68fe7e90d65..ed3610ca42d 100644 --- a/factory/api/apiResolverFactory.go +++ b/factory/api/apiResolverFactory.go @@ -387,7 +387,6 @@ func createScQueryElement( GasSchedule: args.gasScheduleNotifier, Counter: counters.NewDisabledCounter(), MissingTrieNodesNotifier: syncer.NewMissingTrieNodesNotifier(), - PersisterFactory: args.coreComponents.PersisterFactory(), } var apiBlockchain data.ChainHandler diff --git a/factory/core/coreComponents.go b/factory/core/coreComponents.go index 8cf6e2e2266..f04afe47d61 100644 --- a/factory/core/coreComponents.go +++ b/factory/core/coreComponents.go @@ -108,7 +108,6 @@ type coreComponents struct { processStatusHandler common.ProcessStatusHandler hardforkTriggerPubKey []byte enableEpochsHandler common.EnableEpochsHandler - persisterFactory storage.PersisterFactoryHandler } // NewCoreComponentsFactory initializes the factory which is responsible to creating core components @@ -333,11 +332,6 @@ func (ccf *coreComponentsFactory) Create() (*coreComponents, error) { return nil, err } - persisterFactory := storageFactory.NewPersisterFactoryHandler( - ccf.config.PersisterCreatorConfig.MaxRetriesToCreateDB, - ccf.config.PersisterCreatorConfig.SleepTimeBetweenRetriesInSec, - ) - return &coreComponents{ hasher: hasher, txSignHasher: txSignHasher, @@ -373,7 +367,6 @@ func (ccf *coreComponentsFactory) Create() (*coreComponents, error) { processStatusHandler: statusHandler.NewProcessStatusHandler(), hardforkTriggerPubKey: pubKeyBytes, enableEpochsHandler: enableEpochsHandler, - persisterFactory: persisterFactory, }, nil } diff --git a/factory/core/coreComponentsHandler.go b/factory/core/coreComponentsHandler.go index 017ef09404b..b10c378023e 100644 --- a/factory/core/coreComponentsHandler.go +++ b/factory/core/coreComponentsHandler.go @@ -155,9 +155,6 @@ func (mcc *managedCoreComponents) CheckSubcomponents() error { if mcc.minTransactionVersion == 0 { return errors.ErrInvalidTransactionVersion } - if check.IfNil(mcc.persisterFactory) { - return errors.ErrNilPersisterFactory - } return nil } @@ -584,18 +581,6 @@ func (mcc *managedCoreComponents) EnableEpochsHandler() common.EnableEpochsHandl return mcc.coreComponents.enableEpochsHandler } -// PersisterFactory returns the persister factory component -func (mcc *managedCoreComponents) PersisterFactory() storage.PersisterFactoryHandler { - mcc.mutCoreComponents.RLock() - defer mcc.mutCoreComponents.RUnlock() - - if mcc.coreComponents == nil { - return nil - } - - return mcc.coreComponents.persisterFactory -} - // IsInterfaceNil returns true if there is no value under the interface func (mcc *managedCoreComponents) IsInterfaceNil() bool { return mcc == nil diff --git a/factory/data/dataComponents.go b/factory/data/dataComponents.go index c39ad9838b5..4e0d72282b1 100644 --- a/factory/data/dataComponents.go +++ b/factory/data/dataComponents.go @@ -104,7 +104,6 @@ func (dcf *dataComponentsFactory) Create() (*dataComponents, error) { ShardCoordinator: dcf.shardCoordinator, Marshalizer: dcf.core.InternalMarshalizer(), PathManager: dcf.core.PathHandler(), - PersisterFactory: dcf.core.PersisterFactory(), } datapool, err = dataRetrieverFactory.NewDataPoolFromConfig(dataPoolArgs) if err != nil { diff --git a/factory/interface.go b/factory/interface.go index 53171e5546a..2498cc916c4 100644 --- a/factory/interface.go +++ b/factory/interface.go @@ -18,7 +18,6 @@ import ( "github.com/multiversx/mx-chain-go/common" cryptoCommon "github.com/multiversx/mx-chain-go/common/crypto" "github.com/multiversx/mx-chain-go/common/statistics" - "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/consensus" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/dblookupext" @@ -135,7 +134,6 @@ type CoreComponentsHolder interface { ProcessStatusHandler() common.ProcessStatusHandler HardforkTriggerPubKey() []byte EnableEpochsHandler() common.EnableEpochsHandler - PersisterFactory() storage.PersisterFactoryHandler IsInterfaceNil() bool } @@ -215,12 +213,6 @@ type MiniBlockProvider interface { IsInterfaceNil() bool } -// PersisterFactoryHandler defines the behaviour of a component which is able to create persisters -type PersisterFactoryHandler interface { - CreatePersisterHandler(config config.DBConfig) (storage.PersisterCreator, error) - IsInterfaceNil() bool -} - // DataComponentsHolder holds the data components type DataComponentsHolder interface { Blockchain() data.ChainHandler diff --git a/genesis/process/argGenesisBlockCreator.go b/genesis/process/argGenesisBlockCreator.go index 5b1021937e5..e4374b7f6f0 100644 --- a/genesis/process/argGenesisBlockCreator.go +++ b/genesis/process/argGenesisBlockCreator.go @@ -17,7 +17,6 @@ import ( "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/state" - "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/update" ) @@ -30,7 +29,6 @@ type coreComponentsHandler interface { TxVersionChecker() process.TxVersionCheckerHandler ChainID() string EnableEpochsHandler() common.EnableEpochsHandler - PersisterFactory() storage.PersisterFactoryHandler IsInterfaceNil() bool } diff --git a/genesis/process/genesisBlockCreator.go b/genesis/process/genesisBlockCreator.go index 306459bacfe..d3fecd2f2d1 100644 --- a/genesis/process/genesisBlockCreator.go +++ b/genesis/process/genesisBlockCreator.go @@ -89,11 +89,11 @@ func (gbc *genesisBlockCreator) createHardForkImportHandler() error { importFolder := filepath.Join(gbc.arg.WorkingDir, gbc.arg.HardForkConfig.ImportFolder) // TODO remove duplicate code found in update/factory/exportHandlerFactory.go - keysStorer, err := gbc.createStorer(gbc.arg.HardForkConfig.ImportKeysStorageConfig, importFolder) + keysStorer, err := createStorer(gbc.arg.HardForkConfig.ImportKeysStorageConfig, importFolder) if err != nil { return fmt.Errorf("%w while creating keys storer", err) } - keysVals, err := gbc.createStorer(gbc.arg.HardForkConfig.ImportStateStorageConfig, importFolder) + keysVals, err := createStorer(gbc.arg.HardForkConfig.ImportStateStorageConfig, importFolder) if err != nil { return fmt.Errorf("%w while creating keys-values storer", err) } @@ -127,11 +127,11 @@ func (gbc *genesisBlockCreator) createHardForkImportHandler() error { return nil } -func (gbc *genesisBlockCreator) createStorer(storageConfig config.StorageConfig, folder string) (storage.Storer, error) { +func createStorer(storageConfig config.StorageConfig, folder string) (storage.Storer, error) { dbConfig := factory.GetDBFromConfig(storageConfig.DB) dbConfig.FilePath = path.Join(folder, storageConfig.DB.FilePath) - persisterFactory, err := gbc.arg.Core.PersisterFactory().CreatePersisterHandler(storageConfig.DB) + persisterFactory, err := factory.NewPersisterFactory(storageConfig.DB) if err != nil { return nil, err } diff --git a/integrationTests/mock/coreComponentsStub.go b/integrationTests/mock/coreComponentsStub.go index 3d22927b68a..dca3f5a1fa6 100644 --- a/integrationTests/mock/coreComponentsStub.go +++ b/integrationTests/mock/coreComponentsStub.go @@ -54,7 +54,6 @@ type CoreComponentsStub struct { ProcessStatusHandlerInternal common.ProcessStatusHandler HardforkTriggerPubKeyField []byte EnableEpochsHandlerField common.EnableEpochsHandler - PersisterFactoryField storage.PersisterFactoryHandler } // Create - @@ -260,11 +259,6 @@ func (ccs *CoreComponentsStub) EnableEpochsHandler() common.EnableEpochsHandler return ccs.EnableEpochsHandlerField } -// PersisterFactory - -func (ccs *CoreComponentsStub) PersisterFactory() storage.PersisterFactoryHandler { - return ccs.PersisterFactoryField -} - // IsInterfaceNil - func (ccs *CoreComponentsStub) IsInterfaceNil() bool { return ccs == nil diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index 8005c927ffb..5b59fedb896 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -3259,7 +3259,6 @@ func GetDefaultCoreComponents() *mock.CoreComponentsStub { TxVersionCheckField: versioning.NewTxVersionChecker(MinTransactionVersion), ProcessStatusHandlerInternal: &testscommon.ProcessStatusHandlerStub{}, EnableEpochsHandlerField: enableEpochsHandler, - PersisterFactoryField: storageStubs.NewPersisterFactory(), } } diff --git a/integrationTests/vm/wasm/delegation/testRunner.go b/integrationTests/vm/wasm/delegation/testRunner.go index 10ba746d95b..e7bcb516b45 100644 --- a/integrationTests/vm/wasm/delegation/testRunner.go +++ b/integrationTests/vm/wasm/delegation/testRunner.go @@ -16,8 +16,8 @@ import ( "github.com/multiversx/mx-chain-go/integrationTests/vm/wasm" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/state" + "github.com/multiversx/mx-chain-go/storage/factory" "github.com/multiversx/mx-chain-go/storage/storageunit" - "github.com/multiversx/mx-chain-go/testscommon/storage" systemVm "github.com/multiversx/mx-chain-go/vm" logger "github.com/multiversx/mx-chain-logger-go" vmcommon "github.com/multiversx/mx-chain-vm-common-go" @@ -53,8 +53,7 @@ func RunDelegationStressTest( MaxBatchSize: 45000, MaxOpenFiles: 10, } - pfh := storage.NewPersisterFactory() - persisterFactory, err := pfh.CreatePersisterHandler(dbConfig) + persisterFactory, err := factory.NewPersisterFactory(dbConfig) if err != nil { return nil, err } diff --git a/process/interface.go b/process/interface.go index 682365d3543..ee86ee3302c 100644 --- a/process/interface.go +++ b/process/interface.go @@ -1183,7 +1183,6 @@ type CoreComponentsHolder interface { ProcessStatusHandler() common.ProcessStatusHandler HardforkTriggerPubKey() []byte EnableEpochsHandler() common.EnableEpochsHandler - PersisterFactory() storage.PersisterFactoryHandler IsInterfaceNil() bool } diff --git a/process/smartContract/hooks/blockChainHook.go b/process/smartContract/hooks/blockChainHook.go index a26f046fd1e..18d0dac3d7f 100644 --- a/process/smartContract/hooks/blockChainHook.go +++ b/process/smartContract/hooks/blockChainHook.go @@ -21,7 +21,6 @@ import ( "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/dataRetriever" - "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/factory/containers" "github.com/multiversx/mx-chain-go/process/smartContract/scrCommon" @@ -65,7 +64,6 @@ type ArgBlockChainHook struct { GasSchedule core.GasScheduleNotifier Counter BlockChainHookCounter MissingTrieNodesNotifier common.MissingTrieNodesNotifier - PersisterFactory storage.PersisterFactoryHandler } // BlockChainHookImpl is a wrapper over AccountsAdapter that satisfy vmcommon.BlockchainHook interface @@ -83,7 +81,6 @@ type BlockChainHookImpl struct { globalSettingsHandler vmcommon.ESDTGlobalSettingsHandler enableEpochsHandler common.EnableEpochsHandler counter BlockChainHookCounter - persisterFactory storage.PersisterFactoryHandler mutCurrentHdr sync.RWMutex currentHdr data.HeaderHandler @@ -129,7 +126,6 @@ func NewBlockChainHookImpl( gasSchedule: args.GasSchedule, counter: args.Counter, missingTrieNodesNotifier: args.MissingTrieNodesNotifier, - persisterFactory: args.PersisterFactory, } err = blockChainHookImpl.makeCompiledSCStorage() @@ -221,10 +217,6 @@ func checkForNil(args ArgBlockChainHook) error { if check.IfNil(args.MissingTrieNodesNotifier) { return ErrNilMissingTrieNodesNotifier } - if check.IfNil(args.PersisterFactory) { - return errors.ErrNilPersisterFactory - } - return nil } @@ -834,7 +826,7 @@ func (bh *BlockChainHookImpl) makeCompiledSCStorage() error { dbConfig := factory.GetDBFromConfig(bh.configSCStorage.DB) dbConfig.FilePath = path.Join(bh.workingDir, defaultCompiledSCPath, bh.configSCStorage.DB.FilePath) - persisterFactory, err := bh.persisterFactory.CreatePersisterHandler(bh.configSCStorage.DB) + persisterFactory, err := factory.NewPersisterFactory(bh.configSCStorage.DB) if err != nil { return err } diff --git a/storage/database/db.go b/storage/database/db.go index aa4b910fe08..7e677ed954c 100644 --- a/storage/database/db.go +++ b/storage/database/db.go @@ -39,6 +39,6 @@ func NewShardIDProvider(numShards int32) (storage.ShardIDProvider, error) { } // NewShardedPersister is a constructor for sharded persister based on provided db type -func NewShardedPersister(path string, persisterCreator storage.BasePersisterCreator, idPersister storage.ShardIDProvider) (s storage.Persister, err error) { +func NewShardedPersister(path string, persisterCreator storage.PersisterCreator, idPersister storage.ShardIDProvider) (s storage.Persister, err error) { return sharded.NewShardedPersister(path, persisterCreator, idPersister) } diff --git a/storage/factory/openStorage.go b/storage/factory/openStorage.go index 263fefdd3e2..0effada6f04 100644 --- a/storage/factory/openStorage.go +++ b/storage/factory/openStorage.go @@ -6,7 +6,6 @@ import ( "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-go/config" - "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/process/block/bootstrapStorage" "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/storage/cache" @@ -19,7 +18,6 @@ const cacheSize = 10 type ArgsNewOpenStorageUnits struct { BootstrapDataProvider BootstrapDataProviderHandler LatestStorageDataProvider storage.LatestStorageDataProviderHandler - PersisterFactory storage.PersisterFactoryHandler DefaultEpochString string DefaultShardString string } @@ -27,7 +25,6 @@ type ArgsNewOpenStorageUnits struct { type openStorageUnits struct { bootstrapDataProvider BootstrapDataProviderHandler latestStorageDataProvider storage.LatestStorageDataProviderHandler - persisterFactory storage.PersisterFactoryHandler defaultEpochString string defaultShardString string } @@ -40,16 +37,12 @@ func NewStorageUnitOpenHandler(args ArgsNewOpenStorageUnits) (*openStorageUnits, if check.IfNil(args.LatestStorageDataProvider) { return nil, storage.ErrNilLatestStorageDataProvider } - if check.IfNil(args.PersisterFactory) { - return nil, errors.ErrNilPersisterFactory - } o := &openStorageUnits{ defaultEpochString: args.DefaultEpochString, defaultShardString: args.DefaultShardString, bootstrapDataProvider: args.BootstrapDataProvider, latestStorageDataProvider: args.LatestStorageDataProvider, - persisterFactory: args.PersisterFactory, } return o, nil @@ -62,7 +55,7 @@ func (o *openStorageUnits) GetMostRecentStorageUnit(dbConfig config.DBConfig) (s return nil, err } - persisterFactory, err := o.persisterFactory.CreatePersisterHandler(dbConfig) + persisterFactory, err := NewPersisterFactory(dbConfig) if err != nil { return nil, err } @@ -117,7 +110,7 @@ func (o *openStorageUnits) OpenDB(dbConfig config.DBConfig, shardID uint32, epoc parentDir := o.latestStorageDataProvider.GetParentDirectory() pathWithoutShard := o.getPathWithoutShard(parentDir, epoch) persisterPath := o.getPersisterPath(pathWithoutShard, fmt.Sprintf("%d", shardID), dbConfig) - persisterFactory, err := o.persisterFactory.CreatePersisterHandler(dbConfig) + persisterFactory, err := NewPersisterFactory(dbConfig) if err != nil { return nil, err } diff --git a/storage/factory/persisterCreator.go b/storage/factory/persisterCreator.go index 9c0a87bebf8..1357fc37ae4 100644 --- a/storage/factory/persisterCreator.go +++ b/storage/factory/persisterCreator.go @@ -31,6 +31,7 @@ func newPersisterCreator(config config.DBConfig) *persisterCreator { } // Create will create the persister for the provided path +// TODO: refactor to use max tries mechanism func (pc *persisterCreator) Create(path string) (storage.Persister, error) { if len(path) == 0 { return nil, storage.ErrInvalidFilePath diff --git a/storage/factory/persisterFactory.go b/storage/factory/persisterFactory.go index a0cfc679382..2c40b2fc328 100644 --- a/storage/factory/persisterFactory.go +++ b/storage/factory/persisterFactory.go @@ -8,40 +8,20 @@ import ( "github.com/multiversx/mx-chain-go/storage/disabled" ) -type persisterFactoryHandler struct { - maxRetriesToCreateDB uint32 - sleepTimeBetweenRetriesInSec uint32 -} - -func NewPersisterFactoryHandler(maxRetries, sleepTime uint32) *persisterFactoryHandler { - return &persisterFactoryHandler{ - maxRetriesToCreateDB: maxRetries, - sleepTimeBetweenRetriesInSec: sleepTime, - } +// persisterFactory is the factory which will handle creating new databases +type persisterFactory struct { + dbConfigHandler storage.DBConfigHandler } -func (pfh *persisterFactoryHandler) CreatePersisterHandler(config config.DBConfig) (storage.PersisterCreator, error) { +// NewPersisterFactory will return a new instance of persister factory +func NewPersisterFactory(config config.DBConfig) (*persisterFactory, error) { dbConfigHandler := NewDBConfigHandler(config) return &persisterFactory{ - dbConfigHandler: dbConfigHandler, - maxRetriesToCreateDB: pfh.maxRetriesToCreateDB, - sleepTimeBetweenRetriesInSec: pfh.sleepTimeBetweenRetriesInSec, + dbConfigHandler: dbConfigHandler, }, nil } -// IsInterfaceNil returns true if there is no value under the interface -func (pfh *persisterFactoryHandler) IsInterfaceNil() bool { - return pfh == nil -} - -// persisterFactory is the factory which will handle creating new databases -type persisterFactory struct { - maxRetriesToCreateDB uint32 - sleepTimeBetweenRetriesInSec uint32 - dbConfigHandler storage.DBConfigHandler -} - // CreateWithRetries will return a new instance of a DB with a given path // It will try to create db multiple times func (pf *persisterFactory) CreateWithRetries(path string) (storage.Persister, error) { diff --git a/storage/factory/persisterFactory_test.go b/storage/factory/persisterFactory_test.go index 145bdd4a844..860331a22bc 100644 --- a/storage/factory/persisterFactory_test.go +++ b/storage/factory/persisterFactory_test.go @@ -46,32 +46,6 @@ func TestPersisterFactory_Create(t *testing.T) { }) } -func TestPersisterFactory_CreateWithRetries(t *testing.T) { - t.Parallel() - - t.Run("invalid file path, should fail", func(t *testing.T) { - t.Parallel() - - pf, _ := factory.NewPersisterFactory(createDefaultDBConfig()) - - p, err := pf.CreateWithRetries("") - require.Nil(t, p) - require.Equal(t, storage.ErrInvalidFilePath, err) - }) - - t.Run("should work", func(t *testing.T) { - t.Parallel() - - pf, _ := factory.NewPersisterFactory(createDefaultDBConfig()) - - dir := t.TempDir() - - p, err := pf.CreateWithRetries(dir) - require.NotNil(t, p) - require.Nil(t, err) - }) -} - func TestPersisterFactory_Create_ConfigSaveToFilePath(t *testing.T) { t.Parallel() diff --git a/storage/factory/storageServiceFactory.go b/storage/factory/storageServiceFactory.go index 0519e33fe03..902b101675b 100644 --- a/storage/factory/storageServiceFactory.go +++ b/storage/factory/storageServiceFactory.go @@ -56,7 +56,6 @@ type StorageServiceFactory struct { snapshotsEnabled bool repopulateTokensSupplies bool stateStatsHandler common.StateStatisticsHandler - persisterFactory storage.PersisterFactoryHandler } // StorageServiceFactoryArgs holds the arguments needed for creating a new storage service factory @@ -74,7 +73,6 @@ type StorageServiceFactoryArgs struct { NodeProcessingMode common.NodeProcessingMode RepopulateTokensSupplies bool StateStatsHandler common.StateStatisticsHandler - PersisterFactory storage.PersisterFactoryHandler } // NewStorageServiceFactory will return a new instance of StorageServiceFactory @@ -111,7 +109,6 @@ func NewStorageServiceFactory(args StorageServiceFactoryArgs) (*StorageServiceFa snapshotsEnabled: args.Config.StateTriesConfig.SnapshotsEnabled, repopulateTokensSupplies: args.RepopulateTokensSupplies, stateStatsHandler: args.StateStatsHandler, - persisterFactory: args.PersisterFactory, }, nil } @@ -131,9 +128,6 @@ func checkArgs(args StorageServiceFactoryArgs) error { if check.IfNil(args.StateStatsHandler) { return statistics.ErrNilStateStatsHandler } - if check.IfNil(args.PersisterFactory) { - return storage.ErrNilPersisterFactory - } return nil } @@ -285,7 +279,7 @@ func (psf *StorageServiceFactory) createStaticStorageUnit( dbPath := psf.pathManager.PathForStatic(shardID, storageConf.DB.FilePath) + dbPathSuffix storageUnitDBConf.FilePath = dbPath - persisterCreator, err := psf.persisterFactory.CreatePersisterHandler(storageConf.DB) + persisterCreator, err := NewPersisterFactory(storageConf.DB) if err != nil { return nil, err } @@ -565,7 +559,7 @@ func (psf *StorageServiceFactory) createPruningStorerArgs( NumOfActivePersisters: numOfActivePersisters, } - persisterFactory, err := psf.persisterFactory.CreatePersisterHandler(storageConfig.DB) + persisterFactory, err := NewPersisterFactory(storageConfig.DB) if err != nil { return pruning.StorerArgs{}, err } diff --git a/storage/interface.go b/storage/interface.go index c70970a630f..5dd61cfad1d 100644 --- a/storage/interface.go +++ b/storage/interface.go @@ -192,8 +192,8 @@ type ShardIDProvider interface { IsInterfaceNil() bool } -// BasePersisterCreator defines the behavour of a component which is able to create a persister -type BasePersisterCreator = types.PersisterCreator +// PersisterCreator defines the behavour of a component which is able to create a persister +type PersisterCreator = types.PersisterCreator // DBConfigHandler defines the behaviour of a component that will handle db config type DBConfigHandler interface { @@ -210,14 +210,8 @@ type ManagedPeersHolder interface { // PersisterFactoryHandler defines the behaviour of a component which is able to create persisters type PersisterFactoryHandler interface { - CreatePersisterHandler(config config.DBConfig) (PersisterCreator, error) - IsInterfaceNil() bool -} - -type PersisterCreator interface { Create(path string) (Persister, error) CreateWithRetries(path string) (Persister, error) - CreateDisabled() Persister IsInterfaceNil() bool } diff --git a/storage/latestData/latestDataProvider.go b/storage/latestData/latestDataProvider.go index 204c8610751..2b894627de3 100644 --- a/storage/latestData/latestDataProvider.go +++ b/storage/latestData/latestDataProvider.go @@ -31,7 +31,6 @@ type ArgsLatestDataProvider struct { GeneralConfig config.Config BootstrapDataProvider factory.BootstrapDataProviderHandler DirectoryReader storage.DirectoryReaderHandler - PersisterFactory storage.PersisterFactoryHandler ParentDir string DefaultEpochString string DefaultShardString string @@ -48,7 +47,6 @@ type latestDataProvider struct { generalConfig config.Config bootstrapDataProvider factory.BootstrapDataProviderHandler directoryReader storage.DirectoryReaderHandler - persisterFactory storage.PersisterFactoryHandler parentDir string defaultEpochString string defaultShardString string @@ -62,9 +60,6 @@ func NewLatestDataProvider(args ArgsLatestDataProvider) (*latestDataProvider, er if check.IfNil(args.BootstrapDataProvider) { return nil, storage.ErrNilBootstrapDataProvider } - if check.IfNil(args.PersisterFactory) { - return nil, storage.ErrNilPersisterFactory - } return &latestDataProvider{ generalConfig: args.GeneralConfig, @@ -73,7 +68,6 @@ func NewLatestDataProvider(args ArgsLatestDataProvider) (*latestDataProvider, er defaultShardString: args.DefaultShardString, defaultEpochString: args.DefaultEpochString, bootstrapDataProvider: args.BootstrapDataProvider, - persisterFactory: args.PersisterFactory, }, nil } @@ -138,7 +132,7 @@ func (ldp *latestDataProvider) getEpochDirs() ([]string, error) { } func (ldp *latestDataProvider) getLastEpochAndRoundFromStorage(parentDir string, lastEpoch uint32) (storage.LatestDataFromStorage, error) { - persisterCreator, err := ldp.persisterFactory.CreatePersisterHandler(ldp.generalConfig.BootstrapStorage.DB) + persisterFactory, err := factory.NewPersisterFactory(ldp.generalConfig.BootstrapStorage.DB) if err != nil { return storage.LatestDataFromStorage{}, err } @@ -164,7 +158,7 @@ func (ldp *latestDataProvider) getLastEpochAndRoundFromStorage(parentDir string, ldp.generalConfig.BootstrapStorage.DB.FilePath, ) - shardData := ldp.loadDataForShard(highestRoundInStoredShards, shardIdStr, persisterCreator, persisterPath) + shardData := ldp.loadDataForShard(highestRoundInStoredShards, shardIdStr, persisterFactory, persisterPath) if shardData.successful { epochStartRound = shardData.epochStartRound highestRoundInStoredShards = shardData.bootstrapData.LastRound diff --git a/storage/storageunit/storageunit.go b/storage/storageunit/storageunit.go index 1c33cf9e414..2a9e390b725 100644 --- a/storage/storageunit/storageunit.go +++ b/storage/storageunit/storageunit.go @@ -41,7 +41,7 @@ func NewCache(config CacheConfig) (storage.Cacher, error) { } // NewStorageUnitFromConf creates a new storage unit from a storage unit config -func NewStorageUnitFromConf(cacheConf CacheConfig, dbConf DBConfig, persisterFactory storage.PersisterCreator) (*Unit, error) { +func NewStorageUnitFromConf(cacheConf CacheConfig, dbConf DBConfig, persisterFactory storage.PersisterFactoryHandler) (*Unit, error) { return storageUnit.NewStorageUnitFromConf(cacheConf, dbConf, persisterFactory) } diff --git a/testscommon/dataRetriever/poolFactory.go b/testscommon/dataRetriever/poolFactory.go index f82be7a6844..a8f4374e800 100644 --- a/testscommon/dataRetriever/poolFactory.go +++ b/testscommon/dataRetriever/poolFactory.go @@ -98,8 +98,7 @@ func CreatePoolsHolder(numShards uint32, selfShard uint32) dataRetriever.PoolsHo MaxOpenFiles: 10, } - pfh := storageFactory.NewPersisterFactoryHandler(10, 1) - persisterFactory, err := pfh.CreatePersisterHandler(dbConfig) + persisterFactory, err := storageFactory.NewPersisterFactory(dbConfig) panicIfError("Create persister factory", err) persister, err := persisterFactory.CreateWithRetries(tempDir) diff --git a/testscommon/integrationtests/factory.go b/testscommon/integrationtests/factory.go index 1705a209ad4..9acfa7c5e10 100644 --- a/testscommon/integrationtests/factory.go +++ b/testscommon/integrationtests/factory.go @@ -62,9 +62,7 @@ func CreateStorer(parentDir string) storage.Storer { MaxBatchSize: 45000, MaxOpenFiles: 10, } - - pfh := factory.NewPersisterFactoryHandler(10, 1) - persisterFactory, err := pfh.CreatePersisterHandler(dbConfig) + persisterFactory, err := factory.NewPersisterFactory(dbConfig) if err != nil { return nil } diff --git a/testscommon/storage/common.go b/testscommon/storage/common.go deleted file mode 100644 index b1b275e7966..00000000000 --- a/testscommon/storage/common.go +++ /dev/null @@ -1,11 +0,0 @@ -package storage - -import ( - "github.com/multiversx/mx-chain-go/storage" - "github.com/multiversx/mx-chain-go/storage/factory" -) - -// NewPersisterFactory - -func NewPersisterFactory() storage.PersisterFactoryHandler { - return factory.NewPersisterFactoryHandler(2, 1) -} diff --git a/update/factory/dataTrieFactory.go b/update/factory/dataTrieFactory.go index e9f3118c8b8..dcd83da1bd7 100644 --- a/update/factory/dataTrieFactory.go +++ b/update/factory/dataTrieFactory.go @@ -12,10 +12,9 @@ import ( "github.com/multiversx/mx-chain-go/common/statistics" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/dataRetriever" - "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/state" - "github.com/multiversx/mx-chain-go/storage" + "github.com/multiversx/mx-chain-go/storage/factory" storageFactory "github.com/multiversx/mx-chain-go/storage/factory" "github.com/multiversx/mx-chain-go/storage/storageunit" "github.com/multiversx/mx-chain-go/trie" @@ -32,7 +31,6 @@ type ArgsNewDataTrieFactory struct { ShardCoordinator sharding.Coordinator EnableEpochsHandler common.EnableEpochsHandler StateStatsCollector common.StateStatisticsHandler - PersisterFactory storage.PersisterFactoryHandler MaxTrieLevelInMemory uint } @@ -65,14 +63,11 @@ func NewDataTrieFactory(args ArgsNewDataTrieFactory) (*dataTrieFactory, error) { if check.IfNil(args.StateStatsCollector) { return nil, statistics.ErrNilStateStatsHandler } - if check.IfNil(args.PersisterFactory) { - return nil, errors.ErrNilPersisterFactory - } dbConfig := storageFactory.GetDBFromConfig(args.StorageConfig.DB) dbConfig.FilePath = path.Join(args.SyncFolder, args.StorageConfig.DB.FilePath) - persisterFactory, err := args.PersisterFactory.CreatePersisterHandler(args.StorageConfig.DB) + persisterFactory, err := factory.NewPersisterFactory(args.StorageConfig.DB) if err != nil { return nil, err } diff --git a/update/factory/exportHandlerFactory.go b/update/factory/exportHandlerFactory.go index f6be26c5d09..c13f25f3f5a 100644 --- a/update/factory/exportHandlerFactory.go +++ b/update/factory/exportHandlerFactory.go @@ -501,11 +501,11 @@ func (e *exportHandlerFactory) Create() (update.ExportHandler, error) { } }() - keysStorer, err = e.createStorer(e.exportStateKeysConfig, e.exportFolder) + keysStorer, err = createStorer(e.exportStateKeysConfig, e.exportFolder) if err != nil { return nil, fmt.Errorf("%w while creating keys storer", err) } - keysVals, err = e.createStorer(e.exportStateStorageConfig, e.exportFolder) + keysVals, err = createStorer(e.exportStateStorageConfig, e.exportFolder) if err != nil { return nil, fmt.Errorf("%w while creating keys-values storer", err) } @@ -604,11 +604,11 @@ func (e *exportHandlerFactory) createInterceptors() error { return nil } -func (e *exportHandlerFactory) createStorer(storageConfig config.StorageConfig, folder string) (storage.Storer, error) { +func createStorer(storageConfig config.StorageConfig, folder string) (storage.Storer, error) { dbConfig := storageFactory.GetDBFromConfig(storageConfig.DB) dbConfig.FilePath = path.Join(folder, storageConfig.DB.FilePath) - persisterFactory, err := e.coreComponents.PersisterFactory().CreatePersisterHandler(storageConfig.DB) + persisterFactory, err := storageFactory.NewPersisterFactory(storageConfig.DB) if err != nil { return nil, err } From 8d0d1cc5790fe294f2a7432e51744fdd0e3aa510 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Wed, 17 Jan 2024 20:35:04 +0200 Subject: [PATCH 043/503] config file overriding with struct values, improved error messages, fixed tests --- common/reflectcommon/structFieldsUpdate.go | 261 +++++++++++++++--- .../reflectcommon/structFieldsUpdate_test.go | 38 +-- .../configOverriding_test.go | 68 ++++- config/prefsConfig.go | 2 +- 4 files changed, 300 insertions(+), 69 deletions(-) diff --git a/common/reflectcommon/structFieldsUpdate.go b/common/reflectcommon/structFieldsUpdate.go index 6f07d68e7a6..594db1bbd36 100644 --- a/common/reflectcommon/structFieldsUpdate.go +++ b/common/reflectcommon/structFieldsUpdate.go @@ -2,8 +2,8 @@ package reflectcommon import ( "fmt" + "math" "reflect" - "strconv" "strings" "github.com/multiversx/mx-chain-core-go/core/check" @@ -33,7 +33,7 @@ func getReflectValue(original reflect.Value, fieldName string) (value reflect.Va // the structure must be of type pointer, otherwise an error will be returned. All the fields or inner structures MUST be exported // the path must be in the form of InnerStruct.InnerStruct2.Field // newValue must have the same type as the old value, otherwise an error will be returned. Currently, this function does not support slices or maps -func AdaptStructureValueBasedOnPath(structure interface{}, path string, newValue string) (err error) { +func AdaptStructureValueBasedOnPath(structure interface{}, path string, newValue interface{}) (err error) { defer func() { r := recover() if r != nil { @@ -72,76 +72,245 @@ func AdaptStructureValueBasedOnPath(structure interface{}, path string, newValue return trySetTheNewValue(&value, newValue) } -func trySetTheNewValue(value *reflect.Value, newValue string) error { +func trySetTheNewValue(value *reflect.Value, newValue interface{}) error { valueKind := value.Kind() errFunc := func() error { - return fmt.Errorf("cannot cast field <%s> to kind <%s>", newValue, valueKind) + return fmt.Errorf("cannot cast value '%s' of type <%s> to kind <%s>", newValue, reflect.TypeOf(newValue), valueKind) } switch valueKind { case reflect.Invalid: return errFunc() case reflect.Bool: - boolVal, err := strconv.ParseBool(newValue) - if err != nil { - return fmt.Errorf("%w: %s", errFunc(), err.Error()) + boolVal, err := newValue.(bool) + if !err { + return errFunc() } - value.Set(reflect.ValueOf(boolVal)) - case reflect.Int: - intVal, err := strconv.ParseInt(newValue, 10, 64) - if err != nil { - return fmt.Errorf("%w: %s", errFunc(), err.Error()) + value.SetBool(boolVal) + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + reflectVal := reflect.ValueOf(newValue) + if !reflectVal.Type().ConvertibleTo(value.Type()) { + return errFunc() + } + //Check if the newValue fits inside the signed int value + if !fitsWithinSignedIntegerRange(reflectVal, value.Type()) { + return fmt.Errorf("value '%s' does not fit within the range of <%s>", reflectVal, value.Type()) } - value.Set(reflect.ValueOf(int(intVal))) - case reflect.Int32: - int32Val, err := strconv.ParseInt(newValue, 10, 32) - if err != nil { - return fmt.Errorf("%w: %s", errFunc(), err.Error()) + convertedValue := reflectVal.Convert(value.Type()) + value.Set(convertedValue) + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + reflectVal := reflect.ValueOf(newValue) + if !reflectVal.Type().ConvertibleTo(value.Type()) { + return errFunc() + } + //Check if the newValue fits inside the unsigned int value + if !fitsWithinUnsignedIntegerRange(reflectVal, value.Type()) { + return fmt.Errorf("value '%s' does not fit within the range of %s", reflectVal, value.Type()) } - value.Set(reflect.ValueOf(int32(int32Val))) - case reflect.Int64: - int64Val, err := strconv.ParseInt(newValue, 10, 64) - if err != nil { - return fmt.Errorf("%w: %s", errFunc(), err.Error()) + convertedValue := reflectVal.Convert(value.Type()) + value.Set(convertedValue) + case reflect.Float32, reflect.Float64: + reflectVal := reflect.ValueOf(newValue) + if !reflectVal.Type().ConvertibleTo(value.Type()) { + return errFunc() + } + //Check if the newValue fits inside the unsigned int value + if !fitsWithinFloatRange(reflectVal, value.Type()) { + return fmt.Errorf("value '%s' does not fit within the range of %s", reflectVal, value.Type()) } - value.Set(reflect.ValueOf(int64Val)) - case reflect.Uint32: - uint32Val, err := strconv.ParseUint(newValue, 10, 32) - if err != nil { - return fmt.Errorf("%w: %s", errFunc(), err.Error()) + convertedValue := reflectVal.Convert(value.Type()) + value.Set(convertedValue) + case reflect.String: + strVal, err := newValue.(string) + if !err { + return errFunc() } - value.Set(reflect.ValueOf(uint32(uint32Val))) - case reflect.Uint64: - uint64Val, err := strconv.ParseUint(newValue, 10, 64) + value.SetString(strVal) + case reflect.Slice: + return trySetSliceValue(value, newValue) + case reflect.Struct: + structVal := reflect.ValueOf(newValue) + + return trySetStructValue(value, structVal) + default: + return fmt.Errorf("unsupported type <%s> when trying to set the value <%s>", valueKind, newValue) + } + return nil +} + +func trySetSliceValue(value *reflect.Value, newValue interface{}) error { + sliceVal := reflect.ValueOf(newValue) + newSlice := reflect.MakeSlice(value.Type(), sliceVal.Len(), sliceVal.Len()) + + for i := 0; i < sliceVal.Len(); i++ { + item := sliceVal.Index(i) + newItem := reflect.New(value.Type().Elem()).Elem() + + err := trySetStructValue(&newItem, item) if err != nil { - return fmt.Errorf("%w: %s", errFunc(), err.Error()) + return err } - value.Set(reflect.ValueOf(uint64Val)) - case reflect.Float32: - float32Val, err := strconv.ParseFloat(newValue, 32) - if err != nil { - return fmt.Errorf("%w: %s", errFunc(), err.Error()) + newSlice.Index(i).Set(newItem) + } + + value.Set(newSlice) + + return nil +} + +func trySetStructValue(value *reflect.Value, newValue reflect.Value) error { + switch newValue.Kind() { + case reflect.Invalid: + return fmt.Errorf("invalid newValue kind <%s>", newValue.Kind()) + case reflect.Map: // overwrite with value read from toml file + return updateStructFromMap(value, newValue) + case reflect.Struct: // overwrite with go struct + return updateStructFromStruct(value, newValue) + default: + return fmt.Errorf("unsupported type <%s> when trying to set the value of type <%s>", newValue.Kind(), value.Kind()) + } +} + +func updateStructFromMap(value *reflect.Value, newValue reflect.Value) error { + for _, key := range newValue.MapKeys() { + fieldName := key.String() + field := value.FieldByName(fieldName) + + if field.IsValid() && field.CanSet() { + err := trySetTheNewValue(&field, newValue.MapIndex(key).Interface()) + if err != nil { + return err + } + } else { + return fmt.Errorf("field <%s> not found or cannot be set", fieldName) } + } - value.Set(reflect.ValueOf(float32(float32Val))) - case reflect.Float64: - float64Val, err := strconv.ParseFloat(newValue, 32) - if err != nil { - return fmt.Errorf("%w: %s", errFunc(), err.Error()) + return nil +} + +func updateStructFromStruct(value *reflect.Value, newValue reflect.Value) error { + for i := 0; i < newValue.NumField(); i++ { + fieldName := newValue.Type().Field(i).Name + field := value.FieldByName(fieldName) + + if field.IsValid() && field.CanSet() { + err := trySetTheNewValue(&field, newValue.Field(i).Interface()) + if err != nil { + return err + } + } else { + return fmt.Errorf("field <%s> not found or cannot be set", fieldName) } + } - value.Set(reflect.ValueOf(float64Val)) - case reflect.String: - value.Set(reflect.ValueOf(newValue)) + return nil +} + +func fitsWithinSignedIntegerRange(value reflect.Value, targetType reflect.Type) bool { + min := getMinInt(targetType) + max := getMaxInt(targetType) + + switch value.Kind() { + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + return value.Int() >= min && value.Int() <= max + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + return value.Uint() <= uint64(max) default: - return fmt.Errorf("unsupported type <%s> when trying to set the value <%s>", valueKind, newValue) + return false + } +} + +func fitsWithinUnsignedIntegerRange(value reflect.Value, targetType reflect.Type) bool { + max := getMaxUint(targetType) + + switch value.Kind() { + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + return value.Int() >= 0 && uint64(value.Int()) <= max + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + return value.Uint() <= math.MaxUint + default: + return false + } +} + +func fitsWithinFloatRange(value reflect.Value, targetType reflect.Type) bool { + min := getMinFloat(targetType) + max := getMaxFloat(targetType) + + return value.Float() >= min && value.Float() <= max +} + +func getMinInt(targetType reflect.Type) int64 { + switch targetType.Kind() { + case reflect.Int, reflect.Int64: + return math.MinInt64 + case reflect.Int8: + return int64(math.MinInt8) + case reflect.Int16: + return int64(math.MinInt16) + case reflect.Int32: + return int64(math.MinInt32) + default: + return 0 + } +} + +func getMaxInt(targetType reflect.Type) int64 { + switch targetType.Kind() { + case reflect.Int, reflect.Int64: + return math.MaxInt64 + case reflect.Int8: + return int64(math.MaxInt8) + case reflect.Int16: + return int64(math.MaxInt16) + case reflect.Int32: + return int64(math.MaxInt32) + default: + return 0 + } +} + +func getMaxUint(targetType reflect.Type) uint64 { + switch targetType.Kind() { + case reflect.Uint, reflect.Uint64: + return math.MaxUint64 + case reflect.Uint8: + return uint64(math.MaxUint8) + case reflect.Uint16: + return uint64(math.MaxUint16) + case reflect.Uint32: + return uint64(math.MaxUint32) + default: + return 0 + } +} + +func getMinFloat(targetType reflect.Type) float64 { + switch targetType.Kind() { + case reflect.Float32: + return math.SmallestNonzeroFloat32 + case reflect.Float64: + return math.SmallestNonzeroFloat64 + default: + return 0 + } +} + +func getMaxFloat(targetType reflect.Type) float64 { + switch targetType.Kind() { + case reflect.Float32: + return math.MaxFloat32 + case reflect.Float64: + return math.MaxFloat64 + default: + return 0 } - return nil } diff --git a/common/reflectcommon/structFieldsUpdate_test.go b/common/reflectcommon/structFieldsUpdate_test.go index bc7083e885e..ccbdb64d8e2 100644 --- a/common/reflectcommon/structFieldsUpdate_test.go +++ b/common/reflectcommon/structFieldsUpdate_test.go @@ -77,7 +77,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.ErrorContains(t, err, "unsupported type when trying to set the value ") + require.ErrorContains(t, err, "unsupported type when trying to set the value of type ") }) t.Run("should error when setting invalid uint32", func(t *testing.T) { @@ -90,7 +90,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.ErrorContains(t, err, "cannot cast field to kind ") + require.ErrorContains(t, err, "cannot cast value 'invalid uint32' of type to kind ") }) t.Run("should error when setting invalid uint64", func(t *testing.T) { @@ -103,7 +103,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.ErrorContains(t, err, "cannot cast field to kind ") + require.ErrorContains(t, err, "cannot cast value 'invalid uint64' of type to kind ") }) t.Run("should error when setting invalid float32", func(t *testing.T) { @@ -116,7 +116,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.ErrorContains(t, err, "cannot cast field to kind ") + require.ErrorContains(t, err, "cannot cast value 'invalid float32' of type to kind ") }) t.Run("should error when setting invalid float64", func(t *testing.T) { @@ -129,7 +129,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.ErrorContains(t, err, "cannot cast field to kind ") + require.ErrorContains(t, err, "cannot cast value 'invalid float64' of type to kind ") }) t.Run("should error when setting invalid int64", func(t *testing.T) { @@ -142,7 +142,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.ErrorContains(t, err, "cannot cast field to kind ") + require.ErrorContains(t, err, "cannot cast value 'invalid int64' of type to kind ") }) t.Run("should error when setting invalid int64", func(t *testing.T) { @@ -155,7 +155,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.ErrorContains(t, err, "cannot cast field to kind ") + require.ErrorContains(t, err, "cannot cast value 'invalid int64' of type to kind ") }) t.Run("should error when setting invalid int", func(t *testing.T) { @@ -168,7 +168,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.ErrorContains(t, err, "cannot cast field to kind ") + require.ErrorContains(t, err, "cannot cast value 'invalid int' of type to kind ") }) t.Run("should error when setting invalid bool", func(t *testing.T) { @@ -181,7 +181,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.ErrorContains(t, err, "cannot cast field to kind ") + require.ErrorContains(t, err, "cannot cast value 'invalid bool' of type to kind ") }) t.Run("should error if the field is un-settable / unexported", func(t *testing.T) { @@ -279,7 +279,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { cfg := &config.Config{} cfg.StoragePruning.FullArchiveNumActivePersisters = 37 - err := AdaptStructureValueBasedOnPath(cfg, path, fmt.Sprintf("%d", expectedNewValue)) + err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) require.NoError(t, err) require.Equal(t, expectedNewValue, cfg.StoragePruning.FullArchiveNumActivePersisters) @@ -293,7 +293,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { cfg := &config.Config{} cfg.HeartbeatV2.MinPeersThreshold = 37.0 - err := AdaptStructureValueBasedOnPath(cfg, path, fmt.Sprintf("%f", expectedNewValue)) + err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) require.NoError(t, err) require.Equal(t, expectedNewValue, cfg.HeartbeatV2.MinPeersThreshold) @@ -307,7 +307,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { cfg := &config.Config{} cfg.HeartbeatV2.PeerAuthenticationTimeThresholdBetweenSends = 37.0 - err := AdaptStructureValueBasedOnPath(cfg, path, fmt.Sprintf("%f", expectedNewValue)) + err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) require.NoError(t, err) require.Equal(t, expectedNewValue, cfg.HeartbeatV2.PeerAuthenticationTimeThresholdBetweenSends) @@ -321,7 +321,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { cfg := &config.Config{} cfg.Debug.InterceptorResolver.DebugLineExpiration = 37 - err := AdaptStructureValueBasedOnPath(cfg, path, fmt.Sprintf("%d", expectedNewValue)) + err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) require.NoError(t, err) require.Equal(t, expectedNewValue, cfg.Debug.InterceptorResolver.DebugLineExpiration) @@ -335,7 +335,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { cfg := &config.Config{} cfg.Hardfork.GenesisTime = 37 - err := AdaptStructureValueBasedOnPath(cfg, path, fmt.Sprintf("%d", expectedNewValue)) + err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) require.NoError(t, err) require.Equal(t, expectedNewValue, cfg.Hardfork.GenesisTime) @@ -349,7 +349,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { cfg := &config.Config{} cfg.TrieSyncStorage.SizeInBytes = 37 - err := AdaptStructureValueBasedOnPath(cfg, path, fmt.Sprintf("%d", expectedNewValue)) + err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) require.NoError(t, err) require.Equal(t, expectedNewValue, cfg.TrieSyncStorage.SizeInBytes) @@ -362,7 +362,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { cfg := &config.Config{} cfg.StoragePruning.AccountsTrieCleanOldEpochsData = false - err := AdaptStructureValueBasedOnPath(cfg, path, fmt.Sprintf("%v", true)) + err := AdaptStructureValueBasedOnPath(cfg, path, true) require.NoError(t, err) require.True(t, cfg.StoragePruning.AccountsTrieCleanOldEpochsData) @@ -376,7 +376,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { cfg.StoragePruning.FullArchiveNumActivePersisters = uint32(50) expectedNewValue := uint32(37) - err := AdaptStructureValueBasedOnPath(cfg, path, fmt.Sprintf("%d", expectedNewValue)) + err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) require.NoError(t, err) require.Equal(t, expectedNewValue, cfg.StoragePruning.FullArchiveNumActivePersisters) @@ -390,7 +390,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { cfg.Antiflood.NumConcurrentResolverJobs = int32(50) expectedNewValue := int32(37) - err := AdaptStructureValueBasedOnPath(cfg, path, fmt.Sprintf("%d", expectedNewValue)) + err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) require.NoError(t, err) require.Equal(t, expectedNewValue, cfg.Antiflood.NumConcurrentResolverJobs) @@ -418,7 +418,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { cfg.Hardfork.ExportKeysStorageConfig.DB.MaxBatchSize = 10 expectedNewValue := 37 - err := AdaptStructureValueBasedOnPath(cfg, path, fmt.Sprintf("%d", expectedNewValue)) + err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) require.NoError(t, err) require.Equal(t, expectedNewValue, cfg.Hardfork.ExportKeysStorageConfig.DB.MaxBatchSize) diff --git a/config/overridableConfig/configOverriding_test.go b/config/overridableConfig/configOverriding_test.go index b15cf8e5c5c..89fd5557cca 100644 --- a/config/overridableConfig/configOverriding_test.go +++ b/config/overridableConfig/configOverriding_test.go @@ -3,6 +3,7 @@ package overridableConfig import ( "testing" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" p2pConfig "github.com/multiversx/mx-chain-go/p2p/config" "github.com/stretchr/testify/require" @@ -47,7 +48,7 @@ func TestOverrideConfigValues(t *testing.T) { configs := &config.Configs{MainP2pConfig: &p2pConfig.P2PConfig{Sharding: p2pConfig.ShardingConfig{TargetPeerCount: 5}}} - err := OverrideConfigValues([]config.OverridableConfig{{Path: "Sharding.TargetPeerCount", Value: "37", File: "p2p.toml"}}, configs) + err := OverrideConfigValues([]config.OverridableConfig{{Path: "Sharding.TargetPeerCount", Value: uint32(37), File: "p2p.toml"}}, configs) require.NoError(t, err) require.Equal(t, uint32(37), configs.MainP2pConfig.Sharding.TargetPeerCount) }) @@ -57,7 +58,7 @@ func TestOverrideConfigValues(t *testing.T) { configs := &config.Configs{FullArchiveP2pConfig: &p2pConfig.P2PConfig{Sharding: p2pConfig.ShardingConfig{TargetPeerCount: 5}}} - err := OverrideConfigValues([]config.OverridableConfig{{Path: "Sharding.TargetPeerCount", Value: "37", File: "fullArchiveP2P.toml"}}, configs) + err := OverrideConfigValues([]config.OverridableConfig{{Path: "Sharding.TargetPeerCount", Value: uint32(37), File: "fullArchiveP2P.toml"}}, configs) require.NoError(t, err) require.Equal(t, uint32(37), configs.FullArchiveP2pConfig.Sharding.TargetPeerCount) }) @@ -77,8 +78,69 @@ func TestOverrideConfigValues(t *testing.T) { configs := &config.Configs{EpochConfig: &config.EpochConfig{EnableEpochs: config.EnableEpochs{ESDTMetadataContinuousCleanupEnableEpoch: 5}}} - err := OverrideConfigValues([]config.OverridableConfig{{Path: "EnableEpochs.ESDTMetadataContinuousCleanupEnableEpoch", Value: "37", File: "enableEpochs.toml"}}, configs) + err := OverrideConfigValues([]config.OverridableConfig{{Path: "EnableEpochs.ESDTMetadataContinuousCleanupEnableEpoch", Value: uint32(37), File: "enableEpochs.toml"}}, configs) require.NoError(t, err) require.Equal(t, uint32(37), configs.EpochConfig.EnableEpochs.ESDTMetadataContinuousCleanupEnableEpoch) }) + + t.Run("prefs from file should work for config.toml", func(t *testing.T) { + t.Parallel() + + generalConfig, err := common.LoadMainConfig("../../cmd/node/config/prefs.toml") + if err != nil { + require.NoError(t, err) + } + + preferencesConfig, err := common.LoadPreferencesConfig("../../cmd/node/config/prefs.toml") + if err != nil { + require.NoError(t, err) + } + + require.NotNil(t, preferencesConfig.Preferences.OverridableConfigTomlValues) + + configs := &config.Configs{ + GeneralConfig: generalConfig, + } + + errCfgOverride := OverrideConfigValues(preferencesConfig.Preferences.OverridableConfigTomlValues, configs) + if errCfgOverride != nil { + require.NoError(t, errCfgOverride) + } + + require.Equal(t, len(configs.GeneralConfig.VirtualMachine.Execution.WasmVMVersions), 1) + require.Equal(t, configs.GeneralConfig.VirtualMachine.Execution.WasmVMVersions[0].StartEpoch, uint32(0)) + require.Equal(t, configs.GeneralConfig.VirtualMachine.Execution.WasmVMVersions[0].Version, "1.5") + + require.Equal(t, len(configs.GeneralConfig.VirtualMachine.Querying.WasmVMVersions), 1) + require.Equal(t, configs.GeneralConfig.VirtualMachine.Querying.WasmVMVersions[0].StartEpoch, uint32(0)) + require.Equal(t, configs.GeneralConfig.VirtualMachine.Querying.WasmVMVersions[0].Version, "1.5") + }) + + t.Run("go struct should work for config.toml", func(t *testing.T) { + t.Parallel() + + configs := &config.Configs{ + GeneralConfig: &config.Config{ + VirtualMachine: config.VirtualMachineServicesConfig{ + Execution: config.VirtualMachineConfig{ + WasmVMVersions: []config.WasmVMVersionByEpoch{ + {StartEpoch: 0, Version: "1.3"}, + {StartEpoch: 1, Version: "1.4"}, + {StartEpoch: 2, Version: "1.5"}, + }, + }, + }, + }, + } + require.Equal(t, len(configs.GeneralConfig.VirtualMachine.Execution.WasmVMVersions), 3) + + newWasmVMVersion := []config.WasmVMVersionByEpoch{ + {StartEpoch: 0, Version: "1.5"}, + } + + err := OverrideConfigValues([]config.OverridableConfig{{Path: "VirtualMachine.Execution.WasmVMVersions", Value: newWasmVMVersion, File: "config.toml"}}, configs) + require.NoError(t, err) + require.Equal(t, len(configs.GeneralConfig.VirtualMachine.Execution.WasmVMVersions), 1) + require.Equal(t, newWasmVMVersion, configs.GeneralConfig.VirtualMachine.Execution.WasmVMVersions) + }) } diff --git a/config/prefsConfig.go b/config/prefsConfig.go index 34861d647e8..2659e592364 100644 --- a/config/prefsConfig.go +++ b/config/prefsConfig.go @@ -23,7 +23,7 @@ type PreferencesConfig struct { type OverridableConfig struct { File string Path string - Value string + Value interface{} } // BlockProcessingCutoffConfig holds the configuration for the block processing cutoff From 6caa59bbba05a6b55416b99bfd2fc475b8790b63 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Thu, 18 Jan 2024 15:04:29 +0200 Subject: [PATCH 044/503] testing data and tests for overwrite structs --- common/reflectcommon/structFieldsUpdate.go | 8 +- .../reflectcommon/structFieldsUpdate_test.go | 551 ++++++++++++++++++ .../configOverriding_test.go | 36 +- testscommon/toml/config.go | 127 ++++ testscommon/toml/config.toml | 49 ++ testscommon/toml/overwrite.toml | 35 ++ testscommon/toml/overwriteConfig.go | 7 + 7 files changed, 774 insertions(+), 39 deletions(-) create mode 100644 testscommon/toml/config.go create mode 100644 testscommon/toml/config.toml create mode 100644 testscommon/toml/overwrite.toml create mode 100644 testscommon/toml/overwriteConfig.go diff --git a/common/reflectcommon/structFieldsUpdate.go b/common/reflectcommon/structFieldsUpdate.go index 594db1bbd36..5b0ab131592 100644 --- a/common/reflectcommon/structFieldsUpdate.go +++ b/common/reflectcommon/structFieldsUpdate.go @@ -108,7 +108,7 @@ func trySetTheNewValue(value *reflect.Value, newValue interface{}) error { } //Check if the newValue fits inside the unsigned int value if !fitsWithinUnsignedIntegerRange(reflectVal, value.Type()) { - return fmt.Errorf("value '%s' does not fit within the range of %s", reflectVal, value.Type()) + return fmt.Errorf("value '%s' does not fit within the range of <%s>", reflectVal, value.Type()) } convertedValue := reflectVal.Convert(value.Type()) @@ -120,7 +120,7 @@ func trySetTheNewValue(value *reflect.Value, newValue interface{}) error { } //Check if the newValue fits inside the unsigned int value if !fitsWithinFloatRange(reflectVal, value.Type()) { - return fmt.Errorf("value '%s' does not fit within the range of %s", reflectVal, value.Type()) + return fmt.Errorf("value '%s' does not fit within the range of <%s>", reflectVal, value.Type()) } convertedValue := reflectVal.Convert(value.Type()) @@ -296,9 +296,9 @@ func getMaxUint(targetType reflect.Type) uint64 { func getMinFloat(targetType reflect.Type) float64 { switch targetType.Kind() { case reflect.Float32: - return math.SmallestNonzeroFloat32 + return -math.MaxFloat32 case reflect.Float64: - return math.SmallestNonzeroFloat64 + return -math.MaxFloat64 default: return 0 } diff --git a/common/reflectcommon/structFieldsUpdate_test.go b/common/reflectcommon/structFieldsUpdate_test.go index ccbdb64d8e2..217c43f66c3 100644 --- a/common/reflectcommon/structFieldsUpdate_test.go +++ b/common/reflectcommon/structFieldsUpdate_test.go @@ -4,7 +4,9 @@ import ( "fmt" "testing" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/testscommon/toml" "github.com/stretchr/testify/require" ) @@ -423,6 +425,555 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { require.Equal(t, expectedNewValue, cfg.Hardfork.ExportKeysStorageConfig.DB.MaxBatchSize) }) + + t.Run("should work and override int8 value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigI8.Int8.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[0].Value) + require.NoError(t, err) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[0].Value, int64(testConfig.Int8.Value)) + }) + + t.Run("should error int8 value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigI8.Int8.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[1].Value) + require.NotNil(t, err) + require.ErrorContains(t, err, "value '%!s(int64=128)' does not fit within the range of ") + }) + + t.Run("should work and override int8 negative value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigI8.Int8.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[2].Value) + require.NoError(t, err) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[2].Value, int64(testConfig.Int8.Value)) + }) + + t.Run("should error int8 negative value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigI8.Int8.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[3].Value) + require.NotNil(t, err) + require.ErrorContains(t, err, "value '%!s(int64=-129)' does not fit within the range of ") + }) + + t.Run("should work and override int16 value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigI16.Int16.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[4].Value) + require.NoError(t, err) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[4].Value, int64(testConfig.Int16.Value)) + }) + + t.Run("should error int16 value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigI16.Int16.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[5].Value) + require.NotNil(t, err) + require.ErrorContains(t, err, "value '%!s(int64=32768)' does not fit within the range of ") + }) + + t.Run("should work and override int16 negative value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigI16.Int16.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[6].Value) + require.NoError(t, err) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[6].Value, int64(testConfig.Int16.Value)) + }) + + t.Run("should error int16 negative value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigI16.Int16.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[7].Value) + require.NotNil(t, err) + require.ErrorContains(t, err, "value '%!s(int64=-32769)' does not fit within the range of ") + }) + + t.Run("should work and override int32 value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigI32.Int32.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[8].Value) + require.NoError(t, err) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[8].Value, int64(testConfig.Int32.Value)) + }) + + t.Run("should error int32 value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigI32.Int32.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[9].Value) + require.NotNil(t, err) + require.ErrorContains(t, err, "value '%!s(int64=2147483648)' does not fit within the range of ") + }) + + t.Run("should work and override int32 negative value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigI32.Int32.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[10].Value) + require.NoError(t, err) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[10].Value, int64(testConfig.Int32.Value)) + }) + + t.Run("should error int32 negative value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigI32.Int32.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[11].Value) + require.NotNil(t, err) + require.ErrorContains(t, err, "value '%!s(int64=-2147483649)' does not fit within the range of ") + }) + + t.Run("should work and override int64 value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigI64.Int64.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[12].Value) + require.NoError(t, err) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[12].Value, int64(testConfig.Int64.Value)) + }) + + t.Run("should work and override int64 negative value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigI64.Int64.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[13].Value) + require.NoError(t, err) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[13].Value, int64(testConfig.Int64.Value)) + }) + + t.Run("should work and override uint8 value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigU8.Uint8.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[14].Value) + require.NoError(t, err) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[14].Value, int64(testConfig.Uint8.Value)) + }) + + t.Run("should error uint8 value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigU8.Uint8.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[15].Value) + require.NotNil(t, err) + require.ErrorContains(t, err, "value '%!s(int64=256)' does not fit within the range of ") + }) + + t.Run("should error uint8 negative value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigU8.Uint8.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[16].Value) + require.NotNil(t, err) + require.ErrorContains(t, err, "value '%!s(int64=-256)' does not fit within the range of ") + }) + + t.Run("should work and override uint16 value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigU16.Uint16.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[17].Value) + require.NoError(t, err) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[17].Value, int64(testConfig.Uint16.Value)) + }) + + t.Run("should error uint16 value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigU16.Uint16.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[18].Value) + require.NotNil(t, err) + require.ErrorContains(t, err, "value '%!s(int64=65536)' does not fit within the range of ") + }) + + t.Run("should error uint16 negative value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigU16.Uint16.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[19].Value) + require.NotNil(t, err) + require.ErrorContains(t, err, "value '%!s(int64=-65536)' does not fit within the range of ") + }) + + t.Run("should work and override uint32 value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigU32.Uint32.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[20].Value) + require.NoError(t, err) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[20].Value, int64(testConfig.Uint32.Value)) + }) + + t.Run("should error uint32 value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigU32.Uint32.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[21].Value) + require.NotNil(t, err) + require.ErrorContains(t, err, "value '%!s(int64=4294967296)' does not fit within the range of ") + }) + + t.Run("should error uint32 negative value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigU32.Uint32.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[22].Value) + require.NotNil(t, err) + require.ErrorContains(t, err, "value '%!s(int64=-4294967296)' does not fit within the range of ") + }) + + t.Run("should work and override uint64 value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigU64.Uint64.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[23].Value) + require.NoError(t, err) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[23].Value, int64(testConfig.Uint64.Value)) + }) + + t.Run("should error uint64 negative value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigU64.Uint64.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[24].Value) + require.ErrorContains(t, err, "value '%!s(int64=-9223372036854775808)' does not fit within the range of ") + }) + + t.Run("should work and override float32 value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigF32.Float32.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[25].Value) + require.NoError(t, err) + require.Equal(t, testConfig.Float32.Value, float32(3.4)) + }) + + t.Run("should error float32 value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigF32.Float32.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[26].Value) + require.NotNil(t, err) + require.ErrorContains(t, err, "value '%!s(float64=3.4e+39)' does not fit within the range of ") + }) + + t.Run("should work and override float32 negative value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigF32.Float32.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[27].Value) + require.NoError(t, err) + require.Equal(t, testConfig.Float32.Value, float32(-3.4)) + }) + + t.Run("should error float32 negative value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigF32.Float32.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[28].Value) + require.NotNil(t, err) + require.ErrorContains(t, err, "value '%!s(float64=-3.4e+40)' does not fit within the range of ") + }) + + t.Run("should work and override float64 value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigF64.Float64.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[29].Value) + require.NoError(t, err) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[29].Value, testConfig.Float64.Value) + }) + + t.Run("should work and override float64 negative value", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigF64.Float64.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[30].Value) + require.NoError(t, err) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[30].Value, testConfig.Float64.Value) + }) + + t.Run("should work and override struct", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigStruct.ConfigStruct.Description" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[31].Value) + require.NoError(t, err) + require.Equal(t, testConfig.TestConfigStruct.ConfigStruct.Description.Number, uint32(11)) + }) + + t.Run("should work and override nested struct", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigNestedStruct.ConfigNestedStruct" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[32].Value) + require.NoError(t, err) + require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Text, "Overwritten text") + require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.Public, false) + require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription[0].Text, "Overwritten Text1") + }) + +} + +func loadTestConfig(filepath string) (*toml.Config, error) { + cfg := &toml.Config{} + err := core.LoadTomlFile(cfg, filepath) + if err != nil { + return nil, err + } + + return cfg, nil +} +func loadOverrideConfig(filepath string) (*toml.OverrideConfig, error) { + cfg := &toml.OverrideConfig{} + err := core.LoadTomlFile(cfg, filepath) + if err != nil { + return nil, err + } + + return cfg, nil } func BenchmarkAdaptStructureValueBasedOnPath(b *testing.B) { diff --git a/config/overridableConfig/configOverriding_test.go b/config/overridableConfig/configOverriding_test.go index 89fd5557cca..a884a879bf0 100644 --- a/config/overridableConfig/configOverriding_test.go +++ b/config/overridableConfig/configOverriding_test.go @@ -3,7 +3,6 @@ package overridableConfig import ( "testing" - "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" p2pConfig "github.com/multiversx/mx-chain-go/p2p/config" "github.com/stretchr/testify/require" @@ -83,40 +82,7 @@ func TestOverrideConfigValues(t *testing.T) { require.Equal(t, uint32(37), configs.EpochConfig.EnableEpochs.ESDTMetadataContinuousCleanupEnableEpoch) }) - t.Run("prefs from file should work for config.toml", func(t *testing.T) { - t.Parallel() - - generalConfig, err := common.LoadMainConfig("../../cmd/node/config/prefs.toml") - if err != nil { - require.NoError(t, err) - } - - preferencesConfig, err := common.LoadPreferencesConfig("../../cmd/node/config/prefs.toml") - if err != nil { - require.NoError(t, err) - } - - require.NotNil(t, preferencesConfig.Preferences.OverridableConfigTomlValues) - - configs := &config.Configs{ - GeneralConfig: generalConfig, - } - - errCfgOverride := OverrideConfigValues(preferencesConfig.Preferences.OverridableConfigTomlValues, configs) - if errCfgOverride != nil { - require.NoError(t, errCfgOverride) - } - - require.Equal(t, len(configs.GeneralConfig.VirtualMachine.Execution.WasmVMVersions), 1) - require.Equal(t, configs.GeneralConfig.VirtualMachine.Execution.WasmVMVersions[0].StartEpoch, uint32(0)) - require.Equal(t, configs.GeneralConfig.VirtualMachine.Execution.WasmVMVersions[0].Version, "1.5") - - require.Equal(t, len(configs.GeneralConfig.VirtualMachine.Querying.WasmVMVersions), 1) - require.Equal(t, configs.GeneralConfig.VirtualMachine.Querying.WasmVMVersions[0].StartEpoch, uint32(0)) - require.Equal(t, configs.GeneralConfig.VirtualMachine.Querying.WasmVMVersions[0].Version, "1.5") - }) - - t.Run("go struct should work for config.toml", func(t *testing.T) { + t.Run("should work for go struct overwrite", func(t *testing.T) { t.Parallel() configs := &config.Configs{ diff --git a/testscommon/toml/config.go b/testscommon/toml/config.go new file mode 100644 index 00000000000..105cdc0131e --- /dev/null +++ b/testscommon/toml/config.go @@ -0,0 +1,127 @@ +package toml + +type Config struct { + TestConfigI8 + TestConfigI16 + TestConfigI32 + TestConfigI64 + TestConfigU8 + TestConfigU16 + TestConfigU32 + TestConfigU64 + TestConfigF32 + TestConfigF64 + TestConfigStruct + TestConfigNestedStruct +} + +type TestConfigI8 struct { + Int8 Int8 +} + +type Int8 struct { + Value int8 +} + +type TestConfigI16 struct { + Int16 +} + +type Int16 struct { + Value int16 +} + +type TestConfigI32 struct { + Int32 +} + +type Int32 struct { + Value int32 +} + +type TestConfigI64 struct { + Int64 +} + +type Int64 struct { + Value int64 +} + +type TestConfigU8 struct { + Uint8 +} + +type Uint8 struct { + Value uint8 +} + +type TestConfigU16 struct { + Uint16 +} + +type Uint16 struct { + Value uint16 +} + +type TestConfigU32 struct { + Uint32 +} + +type Uint32 struct { + Value uint32 +} + +type TestConfigU64 struct { + Uint64 +} + +type Uint64 struct { + Value uint64 +} + +type TestConfigF32 struct { + Float32 +} + +type Float32 struct { + Value float32 +} + +type TestConfigF64 struct { + Float64 +} + +type Float64 struct { + Value float64 +} + +type TestConfigStruct struct { + ConfigStruct +} + +type ConfigStruct struct { + Title string + Description +} + +type Description struct { + Number uint32 +} + +type TestConfigNestedStruct struct { + ConfigNestedStruct +} + +type ConfigNestedStruct struct { + Text string + Message +} + +type Message struct { + Public bool + MessageDescription []MessageDescription +} + +type MessageDescription struct { + Text string +} diff --git a/testscommon/toml/config.toml b/testscommon/toml/config.toml new file mode 100644 index 00000000000..0c134ec2da0 --- /dev/null +++ b/testscommon/toml/config.toml @@ -0,0 +1,49 @@ +[TestConfigI8] + [TestConfigI8.Int8] + Value = -8 + +[TestConfigI16] + [TestConfigI16.Int16] + Value = -16 + +[TestConfigI32] + [TestConfigI8.Int32] + Value = -32 + +[TestConfigI64] + [TestConfigI64.Int64] + Value = -64 + +[TestConfigU8] + [TestConfigU8.Uint8] + Value = 8 + +[TestConfigU16] + [TestConfigU16.Uint16] + Value = 16 + +[TestConfigU32] + [TestConfigU32.Uint32] + Value = 32 + +[TestConfigU64] + [TestConfigU64.Uint64] + Value = 64 + +[TestConfigF32] + [TestConfigF32.Float32] + Value = -32.32 + +[TestConfigF64] + [TestConfigF64.Float64] + Value = 64.64 + +[TestConfigStruct] + [TestConfigStruct.ConfigStruct] + Title = "Config Struct" + Description = { Number = 32 } + +[TestConfigNestedStruct] + [TestConfigNestedStruct.ConfigNestedStruct] + Text = "Config Nested Struct" + Mesage = { Public = true, MessageDescription = [{ Text = "Text1" }, { Text = "Text2"}] } diff --git a/testscommon/toml/overwrite.toml b/testscommon/toml/overwrite.toml new file mode 100644 index 00000000000..26b0e4bdb4b --- /dev/null +++ b/testscommon/toml/overwrite.toml @@ -0,0 +1,35 @@ +OverridableConfigTomlValues = [ + { File = "config.toml", Path = "TestConfigI8.Int8", Value = 127 }, + { File = "config.toml", Path = "TestConfigI8.Int8", Value = 128 }, + { File = "config.toml", Path = "TestConfigI8.Int8", Value = -128 }, + { File = "config.toml", Path = "TestConfigI8.Int8", Value = -129 }, + { File = "config.toml", Path = "TestConfigI16.Int16", Value = 32767 }, + { File = "config.toml", Path = "TestConfigI16.Int16", Value = 32768 }, + { File = "config.toml", Path = "TestConfigI16.Int16", Value = -32768 }, + { File = "config.toml", Path = "TestConfigI16.Int16", Value = -32769 }, + { File = "config.toml", Path = "TestConfigI32.Int32", Value = 2147483647 }, + { File = "config.toml", Path = "TestConfigI32.Int32", Value = 2147483648 }, + { File = "config.toml", Path = "TestConfigI32.Int32", Value = -2147483648 }, + { File = "config.toml", Path = "TestConfigI32.Int32", Value = -2147483649 }, + { File = "config.toml", Path = "TestConfigI32.Int64", Value = 9223372036854775807 }, + { File = "config.toml", Path = "TestConfigI32.Int64", Value = -9223372036854775808 }, + { File = "config.toml", Path = "TestConfigU8.Uint8", Value = 255 }, + { File = "config.toml", Path = "TestConfigU8.Uint8", Value = 256 }, + { File = "config.toml", Path = "TestConfigU8.Uint8", Value = -256 }, + { File = "config.toml", Path = "TestConfigU16.Uint16", Value = 65535 }, + { File = "config.toml", Path = "TestConfigU16.Uint16", Value = 65536 }, + { File = "config.toml", Path = "TestConfigU16.Uint16", Value = -65536 }, + { File = "config.toml", Path = "TestConfigU32.Uint32", Value = 4294967295 }, + { File = "config.toml", Path = "TestConfigU32.Uint32", Value = 4294967296 }, + { File = "config.toml", Path = "TestConfigU32.Uint32", Value = -4294967296 }, + { File = "config.toml", Path = "TestConfigU64.Uint64", Value = 9223372036854775807 }, + { File = "config.toml", Path = "TestConfigU64.Uint64", Value = -9223372036854775808 }, + { File = "config.toml", Path = "TestConfigF32.Float32", Value = 3.4 }, + { File = "config.toml", Path = "TestConfigF32.Float32", Value = 3.4e+39 }, + { File = "config.toml", Path = "TestConfigF32.Float32", Value = -3.4 }, + { File = "config.toml", Path = "TestConfigF32.Float32", Value = -3.4e+40 }, + { File = "config.toml", Path = "TestConfigF64.Float64", Value = 1.7e+308 }, + { File = "config.toml", Path = "TestConfigF64.Float64", Value = -1.7e+308 }, + { File = "config.toml", Path = "TestConfigStruct.ConfigStruct", Value = { Number = 11 } }, + { File = "config.toml", Path = "TestConfigNestedStruct.ConfigNestedStruct.Message", Value = { Text = "Overwritten text", Message = { Public = false, MessageDescription = [{ Text = "Overwritten Text1" }] } } }, +] \ No newline at end of file diff --git a/testscommon/toml/overwriteConfig.go b/testscommon/toml/overwriteConfig.go new file mode 100644 index 00000000000..2d59a176b19 --- /dev/null +++ b/testscommon/toml/overwriteConfig.go @@ -0,0 +1,7 @@ +package toml + +import "github.com/multiversx/mx-chain-go/config" + +type OverrideConfig struct { + OverridableConfigTomlValues []config.OverridableConfig +} From d612da45aba8ccbe1dfc2214f0e5dd4f77912419 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Mon, 22 Jan 2024 12:10:23 +0200 Subject: [PATCH 045/503] more unit tests --- common/reflectcommon/structFieldsUpdate.go | 192 +++++++++++------ .../reflectcommon/structFieldsUpdate_test.go | 198 ++++++++++++++---- testscommon/toml/config.go | 4 + testscommon/toml/overwrite.toml | 4 +- 4 files changed, 295 insertions(+), 103 deletions(-) diff --git a/common/reflectcommon/structFieldsUpdate.go b/common/reflectcommon/structFieldsUpdate.go index 5b0ab131592..cb701168c86 100644 --- a/common/reflectcommon/structFieldsUpdate.go +++ b/common/reflectcommon/structFieldsUpdate.go @@ -76,58 +76,43 @@ func trySetTheNewValue(value *reflect.Value, newValue interface{}) error { valueKind := value.Kind() errFunc := func() error { - return fmt.Errorf("cannot cast value '%s' of type <%s> to kind <%s>", newValue, reflect.TypeOf(newValue), valueKind) + return fmt.Errorf("unable to cast value '%v' of type <%s> to type <%s>", newValue, reflect.TypeOf(newValue), valueKind) } switch valueKind { case reflect.Invalid: return errFunc() case reflect.Bool: - boolVal, err := newValue.(bool) - if !err { + boolVal, ok := newValue.(bool) + if !ok { return errFunc() } value.SetBool(boolVal) case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - reflectVal := reflect.ValueOf(newValue) - if !reflectVal.Type().ConvertibleTo(value.Type()) { + intVal, ok := convertToSignedInteger(value, newValue) + if !ok { return errFunc() } - //Check if the newValue fits inside the signed int value - if !fitsWithinSignedIntegerRange(reflectVal, value.Type()) { - return fmt.Errorf("value '%s' does not fit within the range of <%s>", reflectVal, value.Type()) - } - convertedValue := reflectVal.Convert(value.Type()) - value.Set(convertedValue) + value.Set(*intVal) case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: - reflectVal := reflect.ValueOf(newValue) - if !reflectVal.Type().ConvertibleTo(value.Type()) { + uintVal, ok := convertToUnsignedInteger(value, newValue) + if !ok { return errFunc() } - //Check if the newValue fits inside the unsigned int value - if !fitsWithinUnsignedIntegerRange(reflectVal, value.Type()) { - return fmt.Errorf("value '%s' does not fit within the range of <%s>", reflectVal, value.Type()) - } - convertedValue := reflectVal.Convert(value.Type()) - value.Set(convertedValue) + value.Set(*uintVal) case reflect.Float32, reflect.Float64: - reflectVal := reflect.ValueOf(newValue) - if !reflectVal.Type().ConvertibleTo(value.Type()) { + floatVal, ok := convertToFloat(value, newValue) + if !ok { return errFunc() } - //Check if the newValue fits inside the unsigned int value - if !fitsWithinFloatRange(reflectVal, value.Type()) { - return fmt.Errorf("value '%s' does not fit within the range of <%s>", reflectVal, value.Type()) - } - convertedValue := reflectVal.Convert(value.Type()) - value.Set(convertedValue) + value.Set(*floatVal) case reflect.String: - strVal, err := newValue.(string) - if !err { + strVal, ok := newValue.(string) + if !ok { return errFunc() } @@ -168,7 +153,7 @@ func trySetSliceValue(value *reflect.Value, newValue interface{}) error { func trySetStructValue(value *reflect.Value, newValue reflect.Value) error { switch newValue.Kind() { case reflect.Invalid: - return fmt.Errorf("invalid newValue kind <%s>", newValue.Kind()) + return fmt.Errorf("invalid new value kind") case reflect.Map: // overwrite with value read from toml file return updateStructFromMap(value, newValue) case reflect.Struct: // overwrite with go struct @@ -214,103 +199,182 @@ func updateStructFromStruct(value *reflect.Value, newValue reflect.Value) error return nil } +func convertToSignedInteger(value *reflect.Value, newValue interface{}) (*reflect.Value, bool) { + var reflectVal = reflect.ValueOf(newValue) + + if !isIntegerType(reflectVal.Type()) { + return nil, false + } + + if !fitsWithinSignedIntegerRange(reflectVal, value.Type()) { + return nil, false + } + + convertedVal := reflectVal.Convert(value.Type()) + return &convertedVal, true +} + +func convertToUnsignedInteger(value *reflect.Value, newValue interface{}) (*reflect.Value, bool) { + var reflectVal = reflect.ValueOf(newValue) + + if !isIntegerType(reflectVal.Type()) { + return nil, false + } + + if !fitsWithinUnsignedIntegerRange(reflectVal, value.Type()) { + return nil, false + } + + convertedVal := reflectVal.Convert(value.Type()) + return &convertedVal, true +} + +func isIntegerType(value reflect.Type) bool { + switch value.Kind() { + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, + reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + return true + default: + return false + } +} + func fitsWithinSignedIntegerRange(value reflect.Value, targetType reflect.Type) bool { - min := getMinInt(targetType) - max := getMaxInt(targetType) + min, err := getMinInt(targetType) + if err != nil { + return false + } + max, err := getMaxInt(targetType) + if err != nil { + return false + } switch value.Kind() { case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: return value.Int() >= min && value.Int() <= max case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: return value.Uint() <= uint64(max) - default: - return false } + + return false } func fitsWithinUnsignedIntegerRange(value reflect.Value, targetType reflect.Type) bool { - max := getMaxUint(targetType) + max, err := getMaxUint(targetType) + if err != nil { + return false + } switch value.Kind() { case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: return value.Int() >= 0 && uint64(value.Int()) <= max case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: - return value.Uint() <= math.MaxUint + return value.Uint() <= max + } + + return false +} + +func convertToFloat(value *reflect.Value, newValue interface{}) (*reflect.Value, bool) { + var reflectVal = reflect.ValueOf(newValue) + + if !isFloatType(reflectVal.Type()) { + return nil, false + } + + if !fitsWithinFloatRange(reflectVal, value.Type()) { + return nil, false + } + + convertedVal := reflectVal.Convert(value.Type()) + return &convertedVal, true +} + +func isFloatType(value reflect.Type) bool { + switch value.Kind() { + case reflect.Float32, reflect.Float64: + return true default: return false } } func fitsWithinFloatRange(value reflect.Value, targetType reflect.Type) bool { - min := getMinFloat(targetType) - max := getMaxFloat(targetType) + min, err := getMinFloat(targetType) + if err != nil { + return false + } + max, err := getMaxFloat(targetType) + if err != nil { + return false + } return value.Float() >= min && value.Float() <= max } -func getMinInt(targetType reflect.Type) int64 { +func getMinInt(targetType reflect.Type) (int64, error) { switch targetType.Kind() { case reflect.Int, reflect.Int64: - return math.MinInt64 + return math.MinInt64, nil case reflect.Int8: - return int64(math.MinInt8) + return int64(math.MinInt8), nil case reflect.Int16: - return int64(math.MinInt16) + return int64(math.MinInt16), nil case reflect.Int32: - return int64(math.MinInt32) + return int64(math.MinInt32), nil default: - return 0 + return 0, fmt.Errorf("target type is not integer") } } -func getMaxInt(targetType reflect.Type) int64 { +func getMaxInt(targetType reflect.Type) (int64, error) { switch targetType.Kind() { case reflect.Int, reflect.Int64: - return math.MaxInt64 + return math.MaxInt64, nil case reflect.Int8: - return int64(math.MaxInt8) + return int64(math.MaxInt8), nil case reflect.Int16: - return int64(math.MaxInt16) + return int64(math.MaxInt16), nil case reflect.Int32: - return int64(math.MaxInt32) + return int64(math.MaxInt32), nil default: - return 0 + return 0, fmt.Errorf("target type is not integer") } } -func getMaxUint(targetType reflect.Type) uint64 { +func getMaxUint(targetType reflect.Type) (uint64, error) { switch targetType.Kind() { case reflect.Uint, reflect.Uint64: - return math.MaxUint64 + return math.MaxUint64, nil case reflect.Uint8: - return uint64(math.MaxUint8) + return uint64(math.MaxUint8), nil case reflect.Uint16: - return uint64(math.MaxUint16) + return uint64(math.MaxUint16), nil case reflect.Uint32: - return uint64(math.MaxUint32) + return uint64(math.MaxUint32), nil default: - return 0 + return 0, fmt.Errorf("taget type is not unsigned integer") } } -func getMinFloat(targetType reflect.Type) float64 { +func getMinFloat(targetType reflect.Type) (float64, error) { switch targetType.Kind() { case reflect.Float32: - return -math.MaxFloat32 + return -math.MaxFloat32, nil case reflect.Float64: - return -math.MaxFloat64 + return -math.MaxFloat64, nil default: - return 0 + return 0, fmt.Errorf("target type is not float") } } -func getMaxFloat(targetType reflect.Type) float64 { +func getMaxFloat(targetType reflect.Type) (float64, error) { switch targetType.Kind() { case reflect.Float32: - return math.MaxFloat32 + return math.MaxFloat32, nil case reflect.Float64: - return math.MaxFloat64 + return math.MaxFloat64, nil default: - return 0 + return 0, fmt.Errorf("target type is not float") } } diff --git a/common/reflectcommon/structFieldsUpdate_test.go b/common/reflectcommon/structFieldsUpdate_test.go index 217c43f66c3..dfcf5685c2d 100644 --- a/common/reflectcommon/structFieldsUpdate_test.go +++ b/common/reflectcommon/structFieldsUpdate_test.go @@ -70,7 +70,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { require.Equal(t, "invalid structure name: FilePath2", err.Error()) }) - t.Run("should error when setting on unsupported type", func(t *testing.T) { + t.Run("should error when setting unsupported type on struct", func(t *testing.T) { t.Parallel() path := "TrieSyncStorage.DB" @@ -79,7 +79,18 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.ErrorContains(t, err, "unsupported type when trying to set the value of type ") + require.Equal(t, err.Error(), "unsupported type when trying to set the value of type ") + }) + + t.Run("should error when setting invalid type on struct", func(t *testing.T) { + t.Parallel() + + path := "TrieSyncStorage.DB" + cfg := &config.Config{} + + err := AdaptStructureValueBasedOnPath(cfg, path, nil) + + require.Equal(t, err.Error(), "invalid new value kind") }) t.Run("should error when setting invalid uint32", func(t *testing.T) { @@ -92,7 +103,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.ErrorContains(t, err, "cannot cast value 'invalid uint32' of type to kind ") + require.Equal(t, err.Error(), "unable to cast value 'invalid uint32' of type to type ") }) t.Run("should error when setting invalid uint64", func(t *testing.T) { @@ -105,7 +116,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.ErrorContains(t, err, "cannot cast value 'invalid uint64' of type to kind ") + require.Equal(t, err.Error(), "unable to cast value 'invalid uint64' of type to type ") }) t.Run("should error when setting invalid float32", func(t *testing.T) { @@ -118,7 +129,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.ErrorContains(t, err, "cannot cast value 'invalid float32' of type to kind ") + require.Equal(t, err.Error(), "unable to cast value 'invalid float32' of type to type ") }) t.Run("should error when setting invalid float64", func(t *testing.T) { @@ -131,20 +142,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.ErrorContains(t, err, "cannot cast value 'invalid float64' of type to kind ") - }) - - t.Run("should error when setting invalid int64", func(t *testing.T) { - t.Parallel() - - path := "HeartbeatV2.HeartbeatExpiryTimespanInSec" - expectedNewValue := "invalid int64" - cfg := &config.Config{} - cfg.HeartbeatV2.HeartbeatExpiryTimespanInSec = 37 - - err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - - require.ErrorContains(t, err, "cannot cast value 'invalid int64' of type to kind ") + require.Equal(t, err.Error(), "unable to cast value 'invalid float64' of type to type ") }) t.Run("should error when setting invalid int64", func(t *testing.T) { @@ -157,7 +155,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.ErrorContains(t, err, "cannot cast value 'invalid int64' of type to kind ") + require.Equal(t, err.Error(), "unable to cast value 'invalid int64' of type to type ") }) t.Run("should error when setting invalid int", func(t *testing.T) { @@ -170,7 +168,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.ErrorContains(t, err, "cannot cast value 'invalid int' of type to kind ") + require.Equal(t, err.Error(), "unable to cast value 'invalid int' of type to type ") }) t.Run("should error when setting invalid bool", func(t *testing.T) { @@ -183,7 +181,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.ErrorContains(t, err, "cannot cast value 'invalid bool' of type to kind ") + require.Equal(t, err.Error(), "unable to cast value 'invalid bool' of type to type ") }) t.Run("should error if the field is un-settable / unexported", func(t *testing.T) { @@ -426,6 +424,18 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { require.Equal(t, expectedNewValue, cfg.Hardfork.ExportKeysStorageConfig.DB.MaxBatchSize) }) + t.Run("should error if setting int into string", func(t *testing.T) { + t.Parallel() + + path := "GeneralSettings.ChainID" + cfg := &config.Config{} + cfg.GeneralSettings.ChainID = "D" + expectedNewValue := 1 + + err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) + require.Equal(t, err.Error(), "unable to cast value '1' of type to type ") + }) + t.Run("should work and override int8 value", func(t *testing.T) { t.Parallel() @@ -455,7 +465,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[1].Value) require.NotNil(t, err) - require.ErrorContains(t, err, "value '%!s(int64=128)' does not fit within the range of ") + require.Equal(t, err.Error(), "unable to cast value '128' of type to type ") }) t.Run("should work and override int8 negative value", func(t *testing.T) { @@ -487,7 +497,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[3].Value) require.NotNil(t, err) - require.ErrorContains(t, err, "value '%!s(int64=-129)' does not fit within the range of ") + require.Equal(t, err.Error(), "unable to cast value '-129' of type to type ") }) t.Run("should work and override int16 value", func(t *testing.T) { @@ -519,7 +529,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[5].Value) require.NotNil(t, err) - require.ErrorContains(t, err, "value '%!s(int64=32768)' does not fit within the range of ") + require.Equal(t, err.Error(), "unable to cast value '32768' of type to type ") }) t.Run("should work and override int16 negative value", func(t *testing.T) { @@ -551,7 +561,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[7].Value) require.NotNil(t, err) - require.ErrorContains(t, err, "value '%!s(int64=-32769)' does not fit within the range of ") + require.Equal(t, err.Error(), "unable to cast value '-32769' of type to type ") }) t.Run("should work and override int32 value", func(t *testing.T) { @@ -583,7 +593,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[9].Value) require.NotNil(t, err) - require.ErrorContains(t, err, "value '%!s(int64=2147483648)' does not fit within the range of ") + require.Equal(t, err.Error(), "unable to cast value '2147483648' of type to type ") }) t.Run("should work and override int32 negative value", func(t *testing.T) { @@ -615,7 +625,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[11].Value) require.NotNil(t, err) - require.ErrorContains(t, err, "value '%!s(int64=-2147483649)' does not fit within the range of ") + require.Equal(t, err.Error(), "unable to cast value '-2147483649' of type to type ") }) t.Run("should work and override int64 value", func(t *testing.T) { @@ -679,7 +689,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[15].Value) require.NotNil(t, err) - require.ErrorContains(t, err, "value '%!s(int64=256)' does not fit within the range of ") + require.Equal(t, err.Error(), "unable to cast value '256' of type to type ") }) t.Run("should error uint8 negative value", func(t *testing.T) { @@ -695,7 +705,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[16].Value) require.NotNil(t, err) - require.ErrorContains(t, err, "value '%!s(int64=-256)' does not fit within the range of ") + require.Equal(t, err.Error(), "unable to cast value '-256' of type to type ") }) t.Run("should work and override uint16 value", func(t *testing.T) { @@ -727,7 +737,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[18].Value) require.NotNil(t, err) - require.ErrorContains(t, err, "value '%!s(int64=65536)' does not fit within the range of ") + require.Equal(t, err.Error(), "unable to cast value '65536' of type to type ") }) t.Run("should error uint16 negative value", func(t *testing.T) { @@ -743,7 +753,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[19].Value) require.NotNil(t, err) - require.ErrorContains(t, err, "value '%!s(int64=-65536)' does not fit within the range of ") + require.Equal(t, err.Error(), "unable to cast value '-65536' of type to type ") }) t.Run("should work and override uint32 value", func(t *testing.T) { @@ -775,7 +785,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[21].Value) require.NotNil(t, err) - require.ErrorContains(t, err, "value '%!s(int64=4294967296)' does not fit within the range of ") + require.Equal(t, err.Error(), "unable to cast value '4294967296' of type to type ") }) t.Run("should error uint32 negative value", func(t *testing.T) { @@ -791,7 +801,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[22].Value) require.NotNil(t, err) - require.ErrorContains(t, err, "value '%!s(int64=-4294967296)' does not fit within the range of ") + require.Equal(t, err.Error(), "unable to cast value '-4294967296' of type to type ") }) t.Run("should work and override uint64 value", func(t *testing.T) { @@ -822,7 +832,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { path := "TestConfigU64.Uint64.Value" err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[24].Value) - require.ErrorContains(t, err, "value '%!s(int64=-9223372036854775808)' does not fit within the range of ") + require.Equal(t, err.Error(), "unable to cast value '-9223372036854775808' of type to type ") }) t.Run("should work and override float32 value", func(t *testing.T) { @@ -854,7 +864,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[26].Value) require.NotNil(t, err) - require.ErrorContains(t, err, "value '%!s(float64=3.4e+39)' does not fit within the range of ") + require.Equal(t, err.Error(), "unable to cast value '3.4e+39' of type to type ") }) t.Run("should work and override float32 negative value", func(t *testing.T) { @@ -886,7 +896,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[28].Value) require.NotNil(t, err) - require.ErrorContains(t, err, "value '%!s(float64=-3.4e+40)' does not fit within the range of ") + require.Equal(t, err.Error(), "unable to cast value '-3.4e+40' of type to type ") }) t.Run("should work and override float64 value", func(t *testing.T) { @@ -937,6 +947,21 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { require.Equal(t, testConfig.TestConfigStruct.ConfigStruct.Description.Number, uint32(11)) }) + t.Run("should error with field not found", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigStruct.ConfigStruct.Description" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[32].Value) + require.Equal(t, err.Error(), "field not found or cannot be set") + }) + t.Run("should work and override nested struct", func(t *testing.T) { t.Parallel() @@ -948,13 +973,110 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { path := "TestConfigNestedStruct.ConfigNestedStruct" - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[32].Value) + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[33].Value) require.NoError(t, err) require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Text, "Overwritten text") require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.Public, false) require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription[0].Text, "Overwritten Text1") }) + t.Run("should work and override nested struct", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigNestedStruct.ConfigNestedStruct" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[33].Value) + require.NoError(t, err) + require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Text, "Overwritten text") + require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.Public, false) + require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription[0].Text, "Overwritten Text1") + }) + + t.Run("should work on slice and override map", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[34].Value) + require.NoError(t, err) + require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription[0].Text, "Overwritten Text1") + require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription[1].Text, "Overwritten Text2") + }) + + t.Run("should error on slice when override int", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + path := "TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription" + + err = AdaptStructureValueBasedOnPath(testConfig, path, 10) + require.Equal(t, err.Error(), "reflect: call of reflect.Value.Len on int Value") + }) + + t.Run("should error on slice when override different type", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + path := "TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription" + + var newValue = []int{10, 20} + + err = AdaptStructureValueBasedOnPath(testConfig, path, newValue) + require.Equal(t, err.Error(), "unsupported type when trying to set the value of type ") + }) + + t.Run("should error on slice when override different struct", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + path := "TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription" + + var newValue = []toml.MessageDescriptionInts{ + {Value: 10}, + {Value: 20}, + } + + err = AdaptStructureValueBasedOnPath(testConfig, path, newValue) + require.Equal(t, err.Error(), "field not found or cannot be set") + }) + + t.Run("should work on slice and override struct", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + path := "TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription" + + var newValue = []toml.MessageDescription{ + {Text: "Text 1"}, + {Text: "Text 2"}, + } + + err = AdaptStructureValueBasedOnPath(testConfig, path, newValue) + require.NoError(t, err) + require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription[0].Text, "Text 1") + require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription[1].Text, "Text 2") + }) + } func loadTestConfig(filepath string) (*toml.Config, error) { diff --git a/testscommon/toml/config.go b/testscommon/toml/config.go index 105cdc0131e..00be307fe00 100644 --- a/testscommon/toml/config.go +++ b/testscommon/toml/config.go @@ -125,3 +125,7 @@ type Message struct { type MessageDescription struct { Text string } + +type MessageDescriptionInts struct { + Value int +} diff --git a/testscommon/toml/overwrite.toml b/testscommon/toml/overwrite.toml index 26b0e4bdb4b..527c22004a0 100644 --- a/testscommon/toml/overwrite.toml +++ b/testscommon/toml/overwrite.toml @@ -31,5 +31,7 @@ OverridableConfigTomlValues = [ { File = "config.toml", Path = "TestConfigF64.Float64", Value = 1.7e+308 }, { File = "config.toml", Path = "TestConfigF64.Float64", Value = -1.7e+308 }, { File = "config.toml", Path = "TestConfigStruct.ConfigStruct", Value = { Number = 11 } }, - { File = "config.toml", Path = "TestConfigNestedStruct.ConfigNestedStruct.Message", Value = { Text = "Overwritten text", Message = { Public = false, MessageDescription = [{ Text = "Overwritten Text1" }] } } }, + { File = "config.toml", Path = "TestConfigStruct.ConfigStruct", Value = { Nr = 222 } }, + { File = "config.toml", Path = "TestConfigNestedStruct.ConfigNestedStruct", Value = { Text = "Overwritten text", Message = { Public = false, MessageDescription = [{ Text = "Overwritten Text1" }] } } }, + { File = "config.toml", Path = "TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription", Value = [{ Text = "Overwritten Text1" }, { Text = "Overwritten Text2" }] }, ] \ No newline at end of file From 883b421535812728394f9338a24e9e730a2f5119 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Mon, 22 Jan 2024 13:28:18 +0200 Subject: [PATCH 046/503] more unit tests --- common/reflectcommon/export_test.go | 52 ++++++++ common/reflectcommon/structFieldsUpdate.go | 32 +++-- .../reflectcommon/structFieldsUpdate_test.go | 116 +++++++++++++++++- testscommon/toml/config.go | 13 +- testscommon/toml/config.toml | 3 + testscommon/toml/overwrite.toml | 5 +- 6 files changed, 198 insertions(+), 23 deletions(-) create mode 100644 common/reflectcommon/export_test.go diff --git a/common/reflectcommon/export_test.go b/common/reflectcommon/export_test.go new file mode 100644 index 00000000000..10857ae97ed --- /dev/null +++ b/common/reflectcommon/export_test.go @@ -0,0 +1,52 @@ +package reflectcommon + +import "reflect" + +func FitsWithinSignedIntegerRange(value reflect.Value, targetType reflect.Type) bool { + min, err := getMinInt(targetType) + if err != nil { + return false + } + max, err := getMaxInt(targetType) + if err != nil { + return false + } + + switch value.Kind() { + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + return value.Int() >= min && value.Int() <= max + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + return value.Uint() <= uint64(max) + } + + return false +} + +func FitsWithinUnsignedIntegerRange(value reflect.Value, targetType reflect.Type) bool { + max, err := getMaxUint(targetType) + if err != nil { + return false + } + + switch value.Kind() { + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + return value.Int() >= 0 && uint64(value.Int()) <= max + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + return value.Uint() <= max + } + + return false +} + +func FitsWithinFloatRange(value reflect.Value, targetType reflect.Type) bool { + min, err := getMinFloat(targetType) + if err != nil { + return false + } + max, err := getMaxFloat(targetType) + if err != nil { + return false + } + + return value.Float() >= min && value.Float() <= max +} diff --git a/common/reflectcommon/structFieldsUpdate.go b/common/reflectcommon/structFieldsUpdate.go index cb701168c86..2ce66da4c61 100644 --- a/common/reflectcommon/structFieldsUpdate.go +++ b/common/reflectcommon/structFieldsUpdate.go @@ -124,7 +124,7 @@ func trySetTheNewValue(value *reflect.Value, newValue interface{}) error { return trySetStructValue(value, structVal) default: - return fmt.Errorf("unsupported type <%s> when trying to set the value <%s>", valueKind, newValue) + return fmt.Errorf("unsupported type <%s> when trying to set the value '%v' of type <%s>", valueKind, newValue, reflect.TypeOf(newValue)) } return nil } @@ -314,14 +314,16 @@ func fitsWithinFloatRange(value reflect.Value, targetType reflect.Type) bool { func getMinInt(targetType reflect.Type) (int64, error) { switch targetType.Kind() { - case reflect.Int, reflect.Int64: + case reflect.Int: + return math.MinInt, nil + case reflect.Int64: return math.MinInt64, nil case reflect.Int8: - return int64(math.MinInt8), nil + return math.MinInt8, nil case reflect.Int16: - return int64(math.MinInt16), nil + return math.MinInt16, nil case reflect.Int32: - return int64(math.MinInt32), nil + return math.MinInt32, nil default: return 0, fmt.Errorf("target type is not integer") } @@ -329,14 +331,16 @@ func getMinInt(targetType reflect.Type) (int64, error) { func getMaxInt(targetType reflect.Type) (int64, error) { switch targetType.Kind() { - case reflect.Int, reflect.Int64: + case reflect.Int: + return math.MaxInt, nil + case reflect.Int64: return math.MaxInt64, nil case reflect.Int8: - return int64(math.MaxInt8), nil + return math.MaxInt8, nil case reflect.Int16: - return int64(math.MaxInt16), nil + return math.MaxInt16, nil case reflect.Int32: - return int64(math.MaxInt32), nil + return math.MaxInt32, nil default: return 0, fmt.Errorf("target type is not integer") } @@ -344,14 +348,16 @@ func getMaxInt(targetType reflect.Type) (int64, error) { func getMaxUint(targetType reflect.Type) (uint64, error) { switch targetType.Kind() { - case reflect.Uint, reflect.Uint64: + case reflect.Uint: + return math.MaxUint, nil + case reflect.Uint64: return math.MaxUint64, nil case reflect.Uint8: - return uint64(math.MaxUint8), nil + return math.MaxUint8, nil case reflect.Uint16: - return uint64(math.MaxUint16), nil + return math.MaxUint16, nil case reflect.Uint32: - return uint64(math.MaxUint32), nil + return math.MaxUint32, nil default: return 0, fmt.Errorf("taget type is not unsigned integer") } diff --git a/common/reflectcommon/structFieldsUpdate_test.go b/common/reflectcommon/structFieldsUpdate_test.go index dfcf5685c2d..f40fd7b1259 100644 --- a/common/reflectcommon/structFieldsUpdate_test.go +++ b/common/reflectcommon/structFieldsUpdate_test.go @@ -2,6 +2,7 @@ package reflectcommon import ( "fmt" + "reflect" "testing" "github.com/multiversx/mx-chain-core-go/core" @@ -436,6 +437,77 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { require.Equal(t, err.Error(), "unable to cast value '1' of type to type ") }) + t.Run("should error for unsupported type", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + expectedNewValue := make(map[string]int) + expectedNewValue["first"] = 1 + expectedNewValue["second"] = 2 + + path := "TestMap.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, expectedNewValue) + require.Equal(t, err.Error(), "unsupported type when trying to set the value 'map[first:1 second:2]' of type ") + }) + + t.Run("should error fit signed for target type not int", func(t *testing.T) { + t.Parallel() + + newValue := 10 + reflectNewValue := reflect.ValueOf(newValue) + targetType := reflect.TypeOf("string") + + res := FitsWithinSignedIntegerRange(reflectNewValue, targetType) + require.False(t, res) + }) + + t.Run("should error fit signed for value not int and target type int", func(t *testing.T) { + t.Parallel() + + newValue := "value" + reflectNewValue := reflect.ValueOf(newValue) + targetType := reflect.TypeOf(10) + + res := FitsWithinSignedIntegerRange(reflectNewValue, targetType) + require.False(t, res) + }) + + t.Run("should error fit unsigned for target type not uint", func(t *testing.T) { + t.Parallel() + + newValue := uint(10) + reflectNewValue := reflect.ValueOf(newValue) + targetType := reflect.TypeOf("string") + + res := FitsWithinUnsignedIntegerRange(reflectNewValue, targetType) + require.False(t, res) + }) + + t.Run("should error fit unsigned for value not uint and target type uint", func(t *testing.T) { + t.Parallel() + + newValue := "value" + reflectNewValue := reflect.ValueOf(newValue) + targetType := reflect.TypeOf(uint(10)) + + res := FitsWithinUnsignedIntegerRange(reflectNewValue, targetType) + require.False(t, res) + }) + + t.Run("should error fit float for target type not float", func(t *testing.T) { + t.Parallel() + + newValue := float32(10) + reflectNewValue := reflect.ValueOf(newValue) + targetType := reflect.TypeOf("string") + + res := FitsWithinFloatRange(reflectNewValue, targetType) + require.False(t, res) + }) + t.Run("should work and override int8 value", func(t *testing.T) { t.Parallel() @@ -962,6 +1034,21 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { require.Equal(t, err.Error(), "field not found or cannot be set") }) + t.Run("should error with different types", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + path := "TestConfigStruct.ConfigStruct.Description" + + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[33].Value) + require.Equal(t, err.Error(), "unable to cast value '11' of type to type ") + }) + t.Run("should work and override nested struct", func(t *testing.T) { t.Parallel() @@ -973,7 +1060,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { path := "TestConfigNestedStruct.ConfigNestedStruct" - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[33].Value) + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[34].Value) require.NoError(t, err) require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Text, "Overwritten text") require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.Public, false) @@ -991,7 +1078,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { path := "TestConfigNestedStruct.ConfigNestedStruct" - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[33].Value) + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[34].Value) require.NoError(t, err) require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Text, "Overwritten text") require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.Public, false) @@ -1009,7 +1096,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { path := "TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription" - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[34].Value) + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[35].Value) require.NoError(t, err) require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription[0].Text, "Overwritten Text1") require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription[1].Text, "Overwritten Text2") @@ -1049,15 +1136,32 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { path := "TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription" - var newValue = []toml.MessageDescriptionInts{ - {Value: 10}, - {Value: 20}, + var newValue = []toml.MessageDescriptionOtherName{ + {Value: "10"}, + {Value: "20"}, } err = AdaptStructureValueBasedOnPath(testConfig, path, newValue) require.Equal(t, err.Error(), "field not found or cannot be set") }) + t.Run("should error on slice when override different struct types", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + path := "TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription" + + var newValue = []toml.MessageDescriptionOtherType{ + {Text: 10}, + {Text: 20}, + } + + err = AdaptStructureValueBasedOnPath(testConfig, path, newValue) + require.Equal(t, err.Error(), "unable to cast value '10' of type to type ") + }) + t.Run("should work on slice and override struct", func(t *testing.T) { t.Parallel() diff --git a/testscommon/toml/config.go b/testscommon/toml/config.go index 00be307fe00..40585b7c21a 100644 --- a/testscommon/toml/config.go +++ b/testscommon/toml/config.go @@ -13,6 +13,7 @@ type Config struct { TestConfigF64 TestConfigStruct TestConfigNestedStruct + TestMap } type TestConfigI8 struct { @@ -126,6 +127,14 @@ type MessageDescription struct { Text string } -type MessageDescriptionInts struct { - Value int +type MessageDescriptionOtherType struct { + Text int +} + +type MessageDescriptionOtherName struct { + Value string +} + +type TestMap struct { + Value map[string]int } diff --git a/testscommon/toml/config.toml b/testscommon/toml/config.toml index 0c134ec2da0..465a274f147 100644 --- a/testscommon/toml/config.toml +++ b/testscommon/toml/config.toml @@ -47,3 +47,6 @@ [TestConfigNestedStruct.ConfigNestedStruct] Text = "Config Nested Struct" Mesage = { Public = true, MessageDescription = [{ Text = "Text1" }, { Text = "Text2"}] } + +[TestMap] + Value = { "key" = 0 } \ No newline at end of file diff --git a/testscommon/toml/overwrite.toml b/testscommon/toml/overwrite.toml index 527c22004a0..b025b16a8e7 100644 --- a/testscommon/toml/overwrite.toml +++ b/testscommon/toml/overwrite.toml @@ -30,8 +30,9 @@ OverridableConfigTomlValues = [ { File = "config.toml", Path = "TestConfigF32.Float32", Value = -3.4e+40 }, { File = "config.toml", Path = "TestConfigF64.Float64", Value = 1.7e+308 }, { File = "config.toml", Path = "TestConfigF64.Float64", Value = -1.7e+308 }, - { File = "config.toml", Path = "TestConfigStruct.ConfigStruct", Value = { Number = 11 } }, - { File = "config.toml", Path = "TestConfigStruct.ConfigStruct", Value = { Nr = 222 } }, + { File = "config.toml", Path = "TestConfigStruct.ConfigStruct.Description", Value = { Number = 11 } }, + { File = "config.toml", Path = "TestConfigStruct.ConfigStruct.Description", Value = { Nr = 222 } }, + { File = "config.toml", Path = "TestConfigStruct.ConfigStruct.Description", Value = { Number = "11" } }, { File = "config.toml", Path = "TestConfigNestedStruct.ConfigNestedStruct", Value = { Text = "Overwritten text", Message = { Public = false, MessageDescription = [{ Text = "Overwritten Text1" }] } } }, { File = "config.toml", Path = "TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription", Value = [{ Text = "Overwritten Text1" }, { Text = "Overwritten Text2" }] }, ] \ No newline at end of file From 74037f12e1907e96706895191a57409ff9a2f0ca Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Mon, 22 Jan 2024 13:38:39 +0200 Subject: [PATCH 047/503] tests fixes --- common/reflectcommon/export_test.go | 43 ++--------------------------- testscommon/toml/config.toml | 2 +- testscommon/toml/overwrite.toml | 2 +- 3 files changed, 5 insertions(+), 42 deletions(-) diff --git a/common/reflectcommon/export_test.go b/common/reflectcommon/export_test.go index 10857ae97ed..84b35ba2aa0 100644 --- a/common/reflectcommon/export_test.go +++ b/common/reflectcommon/export_test.go @@ -3,50 +3,13 @@ package reflectcommon import "reflect" func FitsWithinSignedIntegerRange(value reflect.Value, targetType reflect.Type) bool { - min, err := getMinInt(targetType) - if err != nil { - return false - } - max, err := getMaxInt(targetType) - if err != nil { - return false - } - - switch value.Kind() { - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - return value.Int() >= min && value.Int() <= max - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: - return value.Uint() <= uint64(max) - } - - return false + return fitsWithinSignedIntegerRange(value, targetType) } func FitsWithinUnsignedIntegerRange(value reflect.Value, targetType reflect.Type) bool { - max, err := getMaxUint(targetType) - if err != nil { - return false - } - - switch value.Kind() { - case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - return value.Int() >= 0 && uint64(value.Int()) <= max - case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: - return value.Uint() <= max - } - - return false + return fitsWithinUnsignedIntegerRange(value, targetType) } func FitsWithinFloatRange(value reflect.Value, targetType reflect.Type) bool { - min, err := getMinFloat(targetType) - if err != nil { - return false - } - max, err := getMaxFloat(targetType) - if err != nil { - return false - } - - return value.Float() >= min && value.Float() <= max + return fitsWithinFloatRange(value, targetType) } diff --git a/testscommon/toml/config.toml b/testscommon/toml/config.toml index 465a274f147..af54141fe5f 100644 --- a/testscommon/toml/config.toml +++ b/testscommon/toml/config.toml @@ -49,4 +49,4 @@ Mesage = { Public = true, MessageDescription = [{ Text = "Text1" }, { Text = "Text2"}] } [TestMap] - Value = { "key" = 0 } \ No newline at end of file + Value = { "key" = 0 } diff --git a/testscommon/toml/overwrite.toml b/testscommon/toml/overwrite.toml index b025b16a8e7..5d1e6690caf 100644 --- a/testscommon/toml/overwrite.toml +++ b/testscommon/toml/overwrite.toml @@ -35,4 +35,4 @@ OverridableConfigTomlValues = [ { File = "config.toml", Path = "TestConfigStruct.ConfigStruct.Description", Value = { Number = "11" } }, { File = "config.toml", Path = "TestConfigNestedStruct.ConfigNestedStruct", Value = { Text = "Overwritten text", Message = { Public = false, MessageDescription = [{ Text = "Overwritten Text1" }] } } }, { File = "config.toml", Path = "TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription", Value = [{ Text = "Overwritten Text1" }, { Text = "Overwritten Text2" }] }, -] \ No newline at end of file +] From 1e152b85f0291d5f2064456ea860bc62950c72c2 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Mon, 22 Jan 2024 14:26:29 +0200 Subject: [PATCH 048/503] tests fixes --- common/reflectcommon/structFieldsUpdate.go | 18 ++++++------------ .../reflectcommon/structFieldsUpdate_test.go | 19 +++++++++++++++++-- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/common/reflectcommon/structFieldsUpdate.go b/common/reflectcommon/structFieldsUpdate.go index 2ce66da4c61..94ad6002c07 100644 --- a/common/reflectcommon/structFieldsUpdate.go +++ b/common/reflectcommon/structFieldsUpdate.go @@ -240,12 +240,9 @@ func isIntegerType(value reflect.Type) bool { } func fitsWithinSignedIntegerRange(value reflect.Value, targetType reflect.Type) bool { - min, err := getMinInt(targetType) - if err != nil { - return false - } - max, err := getMaxInt(targetType) - if err != nil { + min, errMin := getMinInt(targetType) + max, errMax := getMaxInt(targetType) + if errMin != nil || errMax != nil { return false } @@ -300,12 +297,9 @@ func isFloatType(value reflect.Type) bool { } func fitsWithinFloatRange(value reflect.Value, targetType reflect.Type) bool { - min, err := getMinFloat(targetType) - if err != nil { - return false - } - max, err := getMaxFloat(targetType) - if err != nil { + min, errMin := getMinFloat(targetType) + max, errMax := getMaxFloat(targetType) + if errMin != nil || errMax != nil { return false } diff --git a/common/reflectcommon/structFieldsUpdate_test.go b/common/reflectcommon/structFieldsUpdate_test.go index f40fd7b1259..a73e42ab8b0 100644 --- a/common/reflectcommon/structFieldsUpdate_test.go +++ b/common/reflectcommon/structFieldsUpdate_test.go @@ -647,9 +647,24 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { path := "TestConfigI32.Int32.Value" - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[8].Value) + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[17].Value) + require.NoError(t, err) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[17].Value, int64(testConfig.Int32.Value)) + }) + + t.Run("should work and override int32 value with uint16", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + expectedNewValue := uint16(10) + + path := "TestConfigI32.Int32.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, expectedNewValue) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[8].Value, int64(testConfig.Int32.Value)) + require.Equal(t, int32(expectedNewValue), testConfig.Int32.Value) }) t.Run("should error int32 value", func(t *testing.T) { From 22f1181d884b1eb0719e81b48a0836f9519e4dc1 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Fri, 26 Jan 2024 11:56:43 +0200 Subject: [PATCH 049/503] fixes after review --- common/reflectcommon/export_test.go | 3 + .../reflectcommon/structFieldsUpdate_test.go | 152 +++++++++--------- testscommon/toml/config.go | 31 ++++ testscommon/toml/overwriteConfig.go | 1 + 4 files changed, 110 insertions(+), 77 deletions(-) diff --git a/common/reflectcommon/export_test.go b/common/reflectcommon/export_test.go index 84b35ba2aa0..473dc1b6fc7 100644 --- a/common/reflectcommon/export_test.go +++ b/common/reflectcommon/export_test.go @@ -2,14 +2,17 @@ package reflectcommon import "reflect" +// FitsWithinSignedIntegerRange - func FitsWithinSignedIntegerRange(value reflect.Value, targetType reflect.Type) bool { return fitsWithinSignedIntegerRange(value, targetType) } +// FitsWithinUnsignedIntegerRange - func FitsWithinUnsignedIntegerRange(value reflect.Value, targetType reflect.Type) bool { return fitsWithinUnsignedIntegerRange(value, targetType) } +// FitsWithinFloatRange - func FitsWithinFloatRange(value reflect.Value, targetType reflect.Type) bool { return fitsWithinFloatRange(value, targetType) } diff --git a/common/reflectcommon/structFieldsUpdate_test.go b/common/reflectcommon/structFieldsUpdate_test.go index a73e42ab8b0..d2145ca8fa0 100644 --- a/common/reflectcommon/structFieldsUpdate_test.go +++ b/common/reflectcommon/structFieldsUpdate_test.go @@ -80,7 +80,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.Equal(t, err.Error(), "unsupported type when trying to set the value of type ") + require.Equal(t, "unsupported type when trying to set the value of type ", err.Error()) }) t.Run("should error when setting invalid type on struct", func(t *testing.T) { @@ -91,7 +91,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, nil) - require.Equal(t, err.Error(), "invalid new value kind") + require.Equal(t, "invalid new value kind", err.Error()) }) t.Run("should error when setting invalid uint32", func(t *testing.T) { @@ -104,7 +104,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.Equal(t, err.Error(), "unable to cast value 'invalid uint32' of type to type ") + require.Equal(t, "unable to cast value 'invalid uint32' of type to type ", err.Error()) }) t.Run("should error when setting invalid uint64", func(t *testing.T) { @@ -117,7 +117,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.Equal(t, err.Error(), "unable to cast value 'invalid uint64' of type to type ") + require.Equal(t, "unable to cast value 'invalid uint64' of type to type ", err.Error()) }) t.Run("should error when setting invalid float32", func(t *testing.T) { @@ -130,7 +130,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.Equal(t, err.Error(), "unable to cast value 'invalid float32' of type to type ") + require.Equal(t, "unable to cast value 'invalid float32' of type to type ", err.Error()) }) t.Run("should error when setting invalid float64", func(t *testing.T) { @@ -143,7 +143,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.Equal(t, err.Error(), "unable to cast value 'invalid float64' of type to type ") + require.Equal(t, "unable to cast value 'invalid float64' of type to type ", err.Error()) }) t.Run("should error when setting invalid int64", func(t *testing.T) { @@ -156,7 +156,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.Equal(t, err.Error(), "unable to cast value 'invalid int64' of type to type ") + require.Equal(t, "unable to cast value 'invalid int64' of type to type ", err.Error()) }) t.Run("should error when setting invalid int", func(t *testing.T) { @@ -169,7 +169,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.Equal(t, err.Error(), "unable to cast value 'invalid int' of type to type ") + require.Equal(t, "unable to cast value 'invalid int' of type to type ", err.Error()) }) t.Run("should error when setting invalid bool", func(t *testing.T) { @@ -182,7 +182,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.Equal(t, err.Error(), "unable to cast value 'invalid bool' of type to type ") + require.Equal(t, "unable to cast value 'invalid bool' of type to type ", err.Error()) }) t.Run("should error if the field is un-settable / unexported", func(t *testing.T) { @@ -434,7 +434,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { expectedNewValue := 1 err := AdaptStructureValueBasedOnPath(cfg, path, expectedNewValue) - require.Equal(t, err.Error(), "unable to cast value '1' of type to type ") + require.Equal(t, "unable to cast value '1' of type to type ", err.Error()) }) t.Run("should error for unsupported type", func(t *testing.T) { @@ -450,14 +450,14 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { path := "TestMap.Value" err = AdaptStructureValueBasedOnPath(testConfig, path, expectedNewValue) - require.Equal(t, err.Error(), "unsupported type when trying to set the value 'map[first:1 second:2]' of type ") + require.Equal(t, "unsupported type when trying to set the value 'map[first:1 second:2]' of type ", err.Error()) }) t.Run("should error fit signed for target type not int", func(t *testing.T) { t.Parallel() - newValue := 10 - reflectNewValue := reflect.ValueOf(newValue) + expectedNewValue := 10 + reflectNewValue := reflect.ValueOf(expectedNewValue) targetType := reflect.TypeOf("string") res := FitsWithinSignedIntegerRange(reflectNewValue, targetType) @@ -467,8 +467,8 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { t.Run("should error fit signed for value not int and target type int", func(t *testing.T) { t.Parallel() - newValue := "value" - reflectNewValue := reflect.ValueOf(newValue) + expectedNewValue := "value" + reflectNewValue := reflect.ValueOf(expectedNewValue) targetType := reflect.TypeOf(10) res := FitsWithinSignedIntegerRange(reflectNewValue, targetType) @@ -478,8 +478,8 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { t.Run("should error fit unsigned for target type not uint", func(t *testing.T) { t.Parallel() - newValue := uint(10) - reflectNewValue := reflect.ValueOf(newValue) + expectedNewValue := uint(10) + reflectNewValue := reflect.ValueOf(expectedNewValue) targetType := reflect.TypeOf("string") res := FitsWithinUnsignedIntegerRange(reflectNewValue, targetType) @@ -489,8 +489,8 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { t.Run("should error fit unsigned for value not uint and target type uint", func(t *testing.T) { t.Parallel() - newValue := "value" - reflectNewValue := reflect.ValueOf(newValue) + expectedNewValue := "value" + reflectNewValue := reflect.ValueOf(expectedNewValue) targetType := reflect.TypeOf(uint(10)) res := FitsWithinUnsignedIntegerRange(reflectNewValue, targetType) @@ -500,8 +500,8 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { t.Run("should error fit float for target type not float", func(t *testing.T) { t.Parallel() - newValue := float32(10) - reflectNewValue := reflect.ValueOf(newValue) + expectedNewValue := float32(10) + reflectNewValue := reflect.ValueOf(expectedNewValue) targetType := reflect.TypeOf("string") res := FitsWithinFloatRange(reflectNewValue, targetType) @@ -537,7 +537,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[1].Value) require.NotNil(t, err) - require.Equal(t, err.Error(), "unable to cast value '128' of type to type ") + require.Equal(t, "unable to cast value '128' of type to type ", err.Error()) }) t.Run("should work and override int8 negative value", func(t *testing.T) { @@ -569,7 +569,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[3].Value) require.NotNil(t, err) - require.Equal(t, err.Error(), "unable to cast value '-129' of type to type ") + require.Equal(t, "unable to cast value '-129' of type to type ", err.Error()) }) t.Run("should work and override int16 value", func(t *testing.T) { @@ -601,7 +601,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[5].Value) require.NotNil(t, err) - require.Equal(t, err.Error(), "unable to cast value '32768' of type to type ") + require.Equal(t, "unable to cast value '32768' of type to type ", err.Error()) }) t.Run("should work and override int16 negative value", func(t *testing.T) { @@ -633,7 +633,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[7].Value) require.NotNil(t, err) - require.Equal(t, err.Error(), "unable to cast value '-32769' of type to type ") + require.Equal(t, "unable to cast value '-32769' of type to type ", err.Error()) }) t.Run("should work and override int32 value", func(t *testing.T) { @@ -680,7 +680,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[9].Value) require.NotNil(t, err) - require.Equal(t, err.Error(), "unable to cast value '2147483648' of type to type ") + require.Equal(t, "unable to cast value '2147483648' of type to type ", err.Error()) }) t.Run("should work and override int32 negative value", func(t *testing.T) { @@ -712,7 +712,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[11].Value) require.NotNil(t, err) - require.Equal(t, err.Error(), "unable to cast value '-2147483649' of type to type ") + require.Equal(t, "unable to cast value '-2147483649' of type to type ", err.Error()) }) t.Run("should work and override int64 value", func(t *testing.T) { @@ -776,7 +776,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[15].Value) require.NotNil(t, err) - require.Equal(t, err.Error(), "unable to cast value '256' of type to type ") + require.Equal(t, "unable to cast value '256' of type to type ", err.Error()) }) t.Run("should error uint8 negative value", func(t *testing.T) { @@ -792,7 +792,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[16].Value) require.NotNil(t, err) - require.Equal(t, err.Error(), "unable to cast value '-256' of type to type ") + require.Equal(t, "unable to cast value '-256' of type to type ", err.Error()) }) t.Run("should work and override uint16 value", func(t *testing.T) { @@ -824,7 +824,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[18].Value) require.NotNil(t, err) - require.Equal(t, err.Error(), "unable to cast value '65536' of type to type ") + require.Equal(t, "unable to cast value '65536' of type to type ", err.Error()) }) t.Run("should error uint16 negative value", func(t *testing.T) { @@ -840,7 +840,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[19].Value) require.NotNil(t, err) - require.Equal(t, err.Error(), "unable to cast value '-65536' of type to type ") + require.Equal(t, "unable to cast value '-65536' of type to type ", err.Error()) }) t.Run("should work and override uint32 value", func(t *testing.T) { @@ -872,7 +872,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[21].Value) require.NotNil(t, err) - require.Equal(t, err.Error(), "unable to cast value '4294967296' of type to type ") + require.Equal(t, "unable to cast value '4294967296' of type to type ", err.Error()) }) t.Run("should error uint32 negative value", func(t *testing.T) { @@ -888,7 +888,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[22].Value) require.NotNil(t, err) - require.Equal(t, err.Error(), "unable to cast value '-4294967296' of type to type ") + require.Equal(t, "unable to cast value '-4294967296' of type to type ", err.Error()) }) t.Run("should work and override uint64 value", func(t *testing.T) { @@ -919,7 +919,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { path := "TestConfigU64.Uint64.Value" err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[24].Value) - require.Equal(t, err.Error(), "unable to cast value '-9223372036854775808' of type to type ") + require.Equal(t, "unable to cast value '-9223372036854775808' of type to type ", err.Error()) }) t.Run("should work and override float32 value", func(t *testing.T) { @@ -935,7 +935,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[25].Value) require.NoError(t, err) - require.Equal(t, testConfig.Float32.Value, float32(3.4)) + require.Equal(t, float32(3.4), testConfig.Float32.Value) }) t.Run("should error float32 value", func(t *testing.T) { @@ -951,7 +951,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[26].Value) require.NotNil(t, err) - require.Equal(t, err.Error(), "unable to cast value '3.4e+39' of type to type ") + require.Equal(t, "unable to cast value '3.4e+39' of type to type ", err.Error()) }) t.Run("should work and override float32 negative value", func(t *testing.T) { @@ -967,7 +967,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[27].Value) require.NoError(t, err) - require.Equal(t, testConfig.Float32.Value, float32(-3.4)) + require.Equal(t, float32(-3.4), testConfig.Float32.Value) }) t.Run("should error float32 negative value", func(t *testing.T) { @@ -983,7 +983,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[28].Value) require.NotNil(t, err) - require.Equal(t, err.Error(), "unable to cast value '-3.4e+40' of type to type ") + require.Equal(t, "unable to cast value '-3.4e+40' of type to type ", err.Error()) }) t.Run("should work and override float64 value", func(t *testing.T) { @@ -1029,9 +1029,13 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { path := "TestConfigStruct.ConfigStruct.Description" + expectedNewValue := toml.Description{ + Number: 11, + } + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[31].Value) require.NoError(t, err) - require.Equal(t, testConfig.TestConfigStruct.ConfigStruct.Description.Number, uint32(11)) + require.Equal(t, expectedNewValue, testConfig.TestConfigStruct.ConfigStruct.Description) }) t.Run("should error with field not found", func(t *testing.T) { @@ -1046,7 +1050,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { path := "TestConfigStruct.ConfigStruct.Description" err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[32].Value) - require.Equal(t, err.Error(), "field not found or cannot be set") + require.Equal(t, "field not found or cannot be set", err.Error()) }) t.Run("should error with different types", func(t *testing.T) { @@ -1061,7 +1065,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { path := "TestConfigStruct.ConfigStruct.Description" err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[33].Value) - require.Equal(t, err.Error(), "unable to cast value '11' of type to type ") + require.Equal(t, "unable to cast value '11' of type to type ", err.Error()) }) t.Run("should work and override nested struct", func(t *testing.T) { @@ -1075,29 +1079,19 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { path := "TestConfigNestedStruct.ConfigNestedStruct" - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[34].Value) - require.NoError(t, err) - require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Text, "Overwritten text") - require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.Public, false) - require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription[0].Text, "Overwritten Text1") - }) - - t.Run("should work and override nested struct", func(t *testing.T) { - t.Parallel() - - testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") - require.NoError(t, err) - - overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") - require.NoError(t, err) - - path := "TestConfigNestedStruct.ConfigNestedStruct" + expectedNewValue := toml.ConfigNestedStruct{ + Text: "Overwritten text", + Message: toml.Message{ + Public: false, + MessageDescription: []toml.MessageDescription{ + {Text: "Overwritten Text1"}, + }, + }, + } err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[34].Value) require.NoError(t, err) - require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Text, "Overwritten text") - require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.Public, false) - require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription[0].Text, "Overwritten Text1") + require.Equal(t, expectedNewValue, testConfig.TestConfigNestedStruct.ConfigNestedStruct) }) t.Run("should work on slice and override map", func(t *testing.T) { @@ -1111,10 +1105,14 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { path := "TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription" + expectedNewValue := []toml.MessageDescription{ + {Text: "Overwritten Text1"}, + {Text: "Overwritten Text2"}, + } + err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[35].Value) require.NoError(t, err) - require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription[0].Text, "Overwritten Text1") - require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription[1].Text, "Overwritten Text2") + require.Equal(t, expectedNewValue, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription) }) t.Run("should error on slice when override int", func(t *testing.T) { @@ -1126,7 +1124,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { path := "TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription" err = AdaptStructureValueBasedOnPath(testConfig, path, 10) - require.Equal(t, err.Error(), "reflect: call of reflect.Value.Len on int Value") + require.Equal(t, "reflect: call of reflect.Value.Len on int Value", err.Error()) }) t.Run("should error on slice when override different type", func(t *testing.T) { @@ -1137,10 +1135,10 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { path := "TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription" - var newValue = []int{10, 20} + expectedNewValue := []int{10, 20} - err = AdaptStructureValueBasedOnPath(testConfig, path, newValue) - require.Equal(t, err.Error(), "unsupported type when trying to set the value of type ") + err = AdaptStructureValueBasedOnPath(testConfig, path, expectedNewValue) + require.Equal(t, "unsupported type when trying to set the value of type ", err.Error()) }) t.Run("should error on slice when override different struct", func(t *testing.T) { @@ -1151,13 +1149,13 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { path := "TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription" - var newValue = []toml.MessageDescriptionOtherName{ + var expectedNewValue = []toml.MessageDescriptionOtherName{ {Value: "10"}, {Value: "20"}, } - err = AdaptStructureValueBasedOnPath(testConfig, path, newValue) - require.Equal(t, err.Error(), "field not found or cannot be set") + err = AdaptStructureValueBasedOnPath(testConfig, path, expectedNewValue) + require.Equal(t, "field not found or cannot be set", err.Error()) }) t.Run("should error on slice when override different struct types", func(t *testing.T) { @@ -1168,13 +1166,13 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { path := "TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription" - var newValue = []toml.MessageDescriptionOtherType{ + var expectedNewValue = []toml.MessageDescriptionOtherType{ {Text: 10}, {Text: 20}, } - err = AdaptStructureValueBasedOnPath(testConfig, path, newValue) - require.Equal(t, err.Error(), "unable to cast value '10' of type to type ") + err = AdaptStructureValueBasedOnPath(testConfig, path, expectedNewValue) + require.Equal(t, "unable to cast value '10' of type to type ", err.Error()) }) t.Run("should work on slice and override struct", func(t *testing.T) { @@ -1185,15 +1183,14 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { path := "TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription" - var newValue = []toml.MessageDescription{ + var expectedNewValue = []toml.MessageDescription{ {Text: "Text 1"}, {Text: "Text 2"}, } - err = AdaptStructureValueBasedOnPath(testConfig, path, newValue) + err = AdaptStructureValueBasedOnPath(testConfig, path, expectedNewValue) require.NoError(t, err) - require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription[0].Text, "Text 1") - require.Equal(t, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription[1].Text, "Text 2") + require.Equal(t, expectedNewValue, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription) }) } @@ -1207,6 +1204,7 @@ func loadTestConfig(filepath string) (*toml.Config, error) { return cfg, nil } + func loadOverrideConfig(filepath string) (*toml.OverrideConfig, error) { cfg := &toml.OverrideConfig{} err := core.LoadTomlFile(cfg, filepath) diff --git a/testscommon/toml/config.go b/testscommon/toml/config.go index 40585b7c21a..47a45839be0 100644 --- a/testscommon/toml/config.go +++ b/testscommon/toml/config.go @@ -1,5 +1,6 @@ package toml +// Config will hold the testing configuration parameters type Config struct { TestConfigI8 TestConfigI16 @@ -16,125 +17,155 @@ type Config struct { TestMap } +// TestConfigI8 will hold an int8 value for testing type TestConfigI8 struct { Int8 Int8 } +// Int8 will hold the value type Int8 struct { Value int8 } +// TestConfigI16 will hold an int16 value for testing type TestConfigI16 struct { Int16 } +// Int16 will hold the value type Int16 struct { Value int16 } +// TestConfigI32 will hold an int32 value for testing type TestConfigI32 struct { Int32 } +// Int32 will hold the value type Int32 struct { Value int32 } +// TestConfigI64 will hold an int64 value for testing type TestConfigI64 struct { Int64 } +// Int64 will hold the value type Int64 struct { Value int64 } +// TestConfigU8 will hold an uint8 value for testing type TestConfigU8 struct { Uint8 } +// Uint8 will hold the value type Uint8 struct { Value uint8 } +// TestConfigU16 will hold an uint16 value for testing type TestConfigU16 struct { Uint16 } +// Uint16 will hold the value type Uint16 struct { Value uint16 } +// TestConfigU32 will hold an uint32 value for testing type TestConfigU32 struct { Uint32 } +// Uint32 will hold the value type Uint32 struct { Value uint32 } +// TestConfigU64 will hold an uint64 value for testing type TestConfigU64 struct { Uint64 } +// Uint64 will hold the value type Uint64 struct { Value uint64 } +// TestConfigF32 will hold a float32 value for testing type TestConfigF32 struct { Float32 } +// Float32 will hold the value type Float32 struct { Value float32 } +// TestConfigF64 will hold a float64 value for testing type TestConfigF64 struct { Float64 } +// Float64 will hold the value type Float64 struct { Value float64 } +// TestConfigStruct will hold a configuration struct for testing type TestConfigStruct struct { ConfigStruct } +// ConfigStruct will hold a struct for testing type ConfigStruct struct { Title string Description } +// Description will hold the number type Description struct { Number uint32 } +// TestConfigNestedStruct will hold a configuration with nested struct for testing type TestConfigNestedStruct struct { ConfigNestedStruct } +// ConfigNestedStruct will hold a nested struct for testing type ConfigNestedStruct struct { Text string Message } +// Message will hold some details type Message struct { Public bool MessageDescription []MessageDescription } +// MessageDescription will hold the text type MessageDescription struct { Text string } +// MessageDescriptionOtherType will hold the text as integer type MessageDescriptionOtherType struct { Text int } +// MessageDescriptionOtherName will hold the value type MessageDescriptionOtherName struct { Value string } +// TestMap will hold a map for testing type TestMap struct { Value map[string]int } diff --git a/testscommon/toml/overwriteConfig.go b/testscommon/toml/overwriteConfig.go index 2d59a176b19..68deb6f9dd5 100644 --- a/testscommon/toml/overwriteConfig.go +++ b/testscommon/toml/overwriteConfig.go @@ -2,6 +2,7 @@ package toml import "github.com/multiversx/mx-chain-go/config" +// OverrideConfig holds an array of configs to be overridden type OverrideConfig struct { OverridableConfigTomlValues []config.OverridableConfig } From da58e7e4192b5049e4b92d5753da278949c06810 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 30 Jan 2024 11:13:01 +0200 Subject: [PATCH 050/503] fixes after merge --- common/constants.go | 3 +++ go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/common/constants.go b/common/constants.go index 3ef5d2ddf61..c948ad42ebd 100644 --- a/common/constants.go +++ b/common/constants.go @@ -309,6 +309,9 @@ const MetricRedundancyLevel = "erd_redundancy_level" // MetricRedundancyIsMainActive is the metric that specifies data about the redundancy main machine const MetricRedundancyIsMainActive = "erd_redundancy_is_main_active" +// MetricRedundancyStepInReason is the metric that specifies why the back-up machine stepped in +const MetricRedundancyStepInReason = "erd_redundancy_step_in_reason" + // MetricValueNA represents the value to be used when a metric is not available/applicable const MetricValueNA = "N/A" diff --git a/go.mod b/go.mod index 8c0a458138f..aecc7fe9e45 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad - github.com/multiversx/mx-chain-core-go v1.2.19-0.20240129082057-a76d0c995cf2 + github.com/multiversx/mx-chain-core-go v1.2.19-0.20240130090709-ad9518226391 github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c diff --git a/go.sum b/go.sum index 11cb5b9a820..bb9ddab77d7 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad h1:izxTyKCxvT7z2mhXCWAZibSxwRVgLmq/kDovs4Nx/6Y= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad/go.mod h1:n4E8BWIV0g3AcNGe1gf+vcjUC8A2QCJ4ARQSbiUDGrI= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20240129082057-a76d0c995cf2 h1:pFh9bwOTRgW173aHqA8Bmax+jYzLnRyXqRvi5alF7V4= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20240129082057-a76d0c995cf2/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.19-0.20240130090709-ad9518226391 h1:4W3CWqDxo38cDnRSXKkLmFxxzHk0JQJEuP0k463Kn9s= +github.com/multiversx/mx-chain-core-go v1.2.19-0.20240130090709-ad9518226391/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 h1:beVIhs5ysylwNplQ/bZ0h5DoDlqKNWgpWE/NMHHNmAw= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479/go.mod h1:Ap6p7QZFtwPlb++OvCG+85BfuZ+bLP/JtQp6EwjWJsI= github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a h1:mOMUhbsjTq7n5oAv4KkVnL67ngS0+wkqmkiv1XJfBIY= From a98f493a268f395e5ad5d989dc37320faca510d3 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Tue, 30 Jan 2024 15:43:17 +0200 Subject: [PATCH 051/503] update go mod --- go.mod | 6 +++--- go.sum | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 8c0a458138f..1012f7a5de0 100644 --- a/go.mod +++ b/go.mod @@ -15,14 +15,14 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad - github.com/multiversx/mx-chain-core-go v1.2.19-0.20240129082057-a76d0c995cf2 + github.com/multiversx/mx-chain-core-go v1.2.19-0.20240130114525-969a1a41a404 github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c github.com/multiversx/mx-chain-scenario-go v1.3.1-0.20240129145446-ca4fba98f6d1 github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240129144933-b1c0d642d7f8 - github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240129145149-4fe61574f566 - github.com/multiversx/mx-chain-vm-go v1.5.27-0.20240129150501-7c828af05c83 + github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240130120052-d8425c5cc419 + github.com/multiversx/mx-chain-vm-go v1.5.27-0.20240130132826-bcb98ba529aa github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240129145751-f814f5525edb github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240129150004-536a22d9c618 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.95-0.20240129150215-43996b664ada diff --git a/go.sum b/go.sum index 11cb5b9a820..3bbc0942584 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad h1:izxTyKCxvT7z2mhXCWAZibSxwRVgLmq/kDovs4Nx/6Y= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad/go.mod h1:n4E8BWIV0g3AcNGe1gf+vcjUC8A2QCJ4ARQSbiUDGrI= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20240129082057-a76d0c995cf2 h1:pFh9bwOTRgW173aHqA8Bmax+jYzLnRyXqRvi5alF7V4= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20240129082057-a76d0c995cf2/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.19-0.20240130114525-969a1a41a404 h1:6abf4zfA/L2KQM7twd2guVmYPiXWG83yfJUHwuRz/tg= +github.com/multiversx/mx-chain-core-go v1.2.19-0.20240130114525-969a1a41a404/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 h1:beVIhs5ysylwNplQ/bZ0h5DoDlqKNWgpWE/NMHHNmAw= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479/go.mod h1:Ap6p7QZFtwPlb++OvCG+85BfuZ+bLP/JtQp6EwjWJsI= github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a h1:mOMUhbsjTq7n5oAv4KkVnL67ngS0+wkqmkiv1XJfBIY= @@ -399,10 +399,10 @@ github.com/multiversx/mx-chain-scenario-go v1.3.1-0.20240129145446-ca4fba98f6d1 github.com/multiversx/mx-chain-scenario-go v1.3.1-0.20240129145446-ca4fba98f6d1/go.mod h1:ndk45i9J9McuCJpTcgiaK4ocd0yhnBBCPrlFwO6GRcs= github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240129144933-b1c0d642d7f8 h1:/EYv/HGX0OKbeNFt667J0yZRtuJiZH0lEK8YtobuH/c= github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240129144933-b1c0d642d7f8/go.mod h1:zl1A6teNe39T8yhdZlkX3ckm5aLYrMIJJZ6Ord1E71M= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240129145149-4fe61574f566 h1:zImJa/r6B5L2OLWbKTn5io53U11PPGDla12H2OaJ9y0= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240129145149-4fe61574f566/go.mod h1:OUyhCFqZKqUk1uaPsenyPDwO1830SlHNDU7Q7b6CBVI= -github.com/multiversx/mx-chain-vm-go v1.5.27-0.20240129150501-7c828af05c83 h1:G/d9aplnwP/9MrLE3gcANEpGfn5e8ZZufijPv2XVUfw= -github.com/multiversx/mx-chain-vm-go v1.5.27-0.20240129150501-7c828af05c83/go.mod h1:64dTd60QUGWx5W3eU28IOfpqAWApWqB/Z7mJHmuQfXo= +github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240130120052-d8425c5cc419 h1:XfXy9Dw9L3QMycCxCRpJZ4hM6gdzkI/yYxUNLFQeRTE= +github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240130120052-d8425c5cc419/go.mod h1:aOuG7j+RoifbyJNzmCeY2yT3y0zUTpW2LQoq8giUTwk= +github.com/multiversx/mx-chain-vm-go v1.5.27-0.20240130132826-bcb98ba529aa h1:8rnHHuDgy/kVlBt0wmUnPsw9M+xGqcgGY4pK0qf09jg= +github.com/multiversx/mx-chain-vm-go v1.5.27-0.20240130132826-bcb98ba529aa/go.mod h1:lQKIRqU6tIKTDoBNkZKTMDTduiAGm/hOA/tTEKLqVd4= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240129145751-f814f5525edb h1:UtiY8X73llF9OLtGb2CM7Xewae1chvPjLc8B+ZmDLjw= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240129145751-f814f5525edb/go.mod h1:8uugq3HUeDiE6G4AS3F8/B3zA1Pabzbl7SSD6Cebwz8= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240129150004-536a22d9c618 h1:1uMlT5TjiHUlx81fEH/WQANWlY0PjF3opMlW+E3L3GI= From 9a9001e734e1cc382767970ebdc9f35c96c47be4 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Tue, 30 Jan 2024 16:02:38 +0200 Subject: [PATCH 052/503] add missing check in unit test --- common/enablers/enableEpochsHandler_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/enablers/enableEpochsHandler_test.go b/common/enablers/enableEpochsHandler_test.go index 973f586986d..c31f240436a 100644 --- a/common/enablers/enableEpochsHandler_test.go +++ b/common/enablers/enableEpochsHandler_test.go @@ -111,6 +111,7 @@ func createEnableEpochsConfig() config.EnableEpochs { FixGasRemainingForSaveKeyValueBuiltinFunctionEnableEpoch: 93, ChangeOwnerAddressCrossShardThroughSCEnableEpoch: 94, CurrentRandomnessOnSortingEnableEpoch: 95, + DynamicESDTEnableEpoch: 96, } } @@ -300,6 +301,7 @@ func TestEnableEpochsHandler_IsFlagEnabled(t *testing.T) { require.True(t, handler.IsFlagEnabled(common.FixGasRemainingForSaveKeyValueFlag)) require.True(t, handler.IsFlagEnabled(common.IsChangeOwnerAddressCrossShardThroughSCFlag)) require.True(t, handler.IsFlagEnabled(common.CurrentRandomnessOnSortingFlag)) + require.True(t, handler.IsFlagEnabled(common.DynamicESDTFlag)) } func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) { @@ -412,6 +414,7 @@ func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) { require.Equal(t, cfg.ChangeOwnerAddressCrossShardThroughSCEnableEpoch, handler.GetActivationEpoch(common.IsChangeOwnerAddressCrossShardThroughSCFlag)) require.Equal(t, cfg.FixGasRemainingForSaveKeyValueBuiltinFunctionEnableEpoch, handler.GetActivationEpoch(common.FixGasRemainingForSaveKeyValueFlag)) require.Equal(t, cfg.CurrentRandomnessOnSortingEnableEpoch, handler.GetActivationEpoch(common.CurrentRandomnessOnSortingFlag)) + require.Equal(t, cfg.DynamicESDTEnableEpoch, handler.GetActivationEpoch(common.DynamicESDTFlag)) } func TestEnableEpochsHandler_IsInterfaceNil(t *testing.T) { From bce29e1a3934e1290577703d9dffde9ccdee2388 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Wed, 31 Jan 2024 11:07:15 +0200 Subject: [PATCH 053/503] more examples in prefs toml --- cmd/node/config/prefs.toml | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/cmd/node/config/prefs.toml b/cmd/node/config/prefs.toml index 98d5c02557f..375254c33f3 100644 --- a/cmd/node/config/prefs.toml +++ b/cmd/node/config/prefs.toml @@ -38,17 +38,21 @@ # so that certain config values need to remain the same during upgrades. # (for example, an Elasticsearch user wants external.toml->ElasticSearchConnector.Enabled to remain true all the time during upgrades, while the default # configuration of the node has the false value) - # The Path indicates what value to change, while Value represents the new value in string format. The node operator must make sure - # to follow the same type of the original value (ex: uint32: "37", float32: "37.0", bool: "true") - # File represents the file name that holds the configuration. Currently, the supported files are: config.toml, external.toml, p2p.toml and enableEpochs.toml + # The Path indicates what value to change, while Value represents the new value. The node operator must make sure + # to follow the same type of the original value (ex: uint32: 37, float32: 37.0, bool: true) + # Also, the Value can be a struct (ex: { StartEpoch = 0, Version = "1.5" }) or an array (ex: [{ StartEpoch = 0, Version = "1.4" }, { StartEpoch = 1, Version = "1.5" }]) + # File represents the file name that holds the configuration. Currently, the supported files are: config.toml, external.toml, p2p.toml, enableEpochs.toml and fullArchiveP2P.toml # ------------------------------- # Un-comment and update the following section in order to enable config values overloading # ------------------------------- # OverridableConfigTomlValues = [ - # { File = "config.toml", Path = "StoragePruning.NumEpochsToKeep", Value = "4" }, - # { File = "config.toml", Path = "MiniBlocksStorage.Cache.Name", Value = "MiniBlocksStorage" }, - # { File = "external.toml", Path = "ElasticSearchConnector.Enabled", Value = "true" } - #] + # { File = "config.toml", Path = "StoragePruning.NumEpochsToKeep", Value = 4 }, + # { File = "config.toml", Path = "MiniBlocksStorage.Cache.Name", Value = "MiniBlocksStorage" }, + # { File = "external.toml", Path = "ElasticSearchConnector.Enabled", Value = true }, + # { File = "external.toml", Path = "HostDriversConfig", Value = [ + # { Enabled = false, URL = "127.0.0.1:22111" }, + # ] }, + # ] # BlockProcessingCutoff can be used to stop processing blocks at a certain round, nonce or epoch. # This can be useful for snapshotting different stuff and also for debugging purposes. From 9444cd1375bf72d7e0215da90c75247adbcdc03e Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Wed, 31 Jan 2024 15:19:09 +0200 Subject: [PATCH 054/503] - added the possibility to define more protocol IDs for p2p networks --- cmd/node/config/fullArchiveP2P.toml | 9 ++++++--- cmd/node/config/p2p.toml | 9 ++++++--- cmd/seednode/config/p2p.toml | 9 ++++++--- config/tomlConfig_test.go | 13 ++++++++++--- go.mod | 2 +- go.sum | 4 ++-- .../networkSharding-hbv2/networkSharding_test.go | 2 +- integrationTests/testInitializer.go | 2 +- testscommon/components/components.go | 2 +- 9 files changed, 34 insertions(+), 18 deletions(-) diff --git a/cmd/node/config/fullArchiveP2P.toml b/cmd/node/config/fullArchiveP2P.toml index 0dd790a83f6..01fbeb79789 100644 --- a/cmd/node/config/fullArchiveP2P.toml +++ b/cmd/node/config/fullArchiveP2P.toml @@ -48,9 +48,12 @@ # RefreshIntervalInSec represents the time in seconds between querying for new peers RefreshIntervalInSec = 10 - # ProtocolID represents the protocol that this node will advertize to other peers - # To connect to other nodes, those nodes should have the same ProtocolID string - ProtocolID = "/erd/kad/1.0.0" + # ProtocolIDs represents the protocols that this node will advertize to other peers + # To connect to other nodes, those nodes should have at least on common protocol string + ProtocolIDs = [ + "/erd/kad/1.0.0", + "mvx-full-archive", + ] # InitialPeerList represents the list of strings of some known nodes that will bootstrap this node # The address will be in a self-describing addressing format. diff --git a/cmd/node/config/p2p.toml b/cmd/node/config/p2p.toml index 62d30fd19f7..2fd4eeca66a 100644 --- a/cmd/node/config/p2p.toml +++ b/cmd/node/config/p2p.toml @@ -48,9 +48,12 @@ # RefreshIntervalInSec represents the time in seconds between querying for new peers RefreshIntervalInSec = 10 - # ProtocolID represents the protocol that this node will advertize to other peers - # To connect to other nodes, those nodes should have the same ProtocolID string - ProtocolID = "/erd/kad/1.0.0" + # ProtocolIDs represents the protocols that this node will advertize to other peers + # To connect to other nodes, those nodes should have at least on common protocol string + ProtocolIDs = [ + "/erd/kad/1.0.0", + "mvx-main", + ] # InitialPeerList represents the list of strings of some known nodes that will bootstrap this node # The address will be in a self-describing addressing format. diff --git a/cmd/seednode/config/p2p.toml b/cmd/seednode/config/p2p.toml index 2c1a92717c9..5ca9fa33c94 100644 --- a/cmd/seednode/config/p2p.toml +++ b/cmd/seednode/config/p2p.toml @@ -47,9 +47,12 @@ #RefreshIntervalInSec represents the time in seconds between querying for new peers RefreshIntervalInSec = 10 - #ProtocolID represents the protocol that this node will advertize to other peers - #To connect to other nodes, those nodes should have the same ProtocolID string - ProtocolID = "/erd/kad/1.0.0" + # ProtocolIDs represents the protocols that this node will advertize to other peers + # To connect to other nodes, those nodes should have at least on common protocol string + ProtocolIDs = [ + "/erd/kad/1.0.0", + "mvx-main", + ] #InitialPeerList represents the list of strings of some known nodes that will bootstrap this node #The address will be in a self-describing addressing format. diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index 4b75c03300d..c4043d71652 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -472,7 +472,8 @@ func TestAPIRoutesToml(t *testing.T) { func TestP2pConfig(t *testing.T) { initialPeersList := "/ip4/127.0.0.1/tcp/9999/p2p/16Uiu2HAkw5SNNtSvH1zJiQ6Gc3WoGNSxiyNueRKe6fuAuh57G3Bk" - protocolID := "test protocol id" + protocolID1 := "test protocol id 1" + protocolID2 := "test protocol id 2" shardingType := "ListSharder" port := "37373-38383" @@ -498,7 +499,13 @@ func TestP2pConfig(t *testing.T) { Enabled = false Type = "" RefreshIntervalInSec = 0 - ProtocolID = "` + protocolID + `" + + # ProtocolIDs represents the protocols that this node will advertize to other peers + # To connect to other nodes, those nodes should have at least on common protocol string + ProtocolIDs = [ + "` + protocolID1 + `", + "` + protocolID2 + `", + ] InitialPeerList = ["` + initialPeersList + `"] #kademlia's routing table bucket size @@ -536,7 +543,7 @@ func TestP2pConfig(t *testing.T) { }, }, KadDhtPeerDiscovery: p2pConfig.KadDhtPeerDiscoveryConfig{ - ProtocolID: protocolID, + ProtocolIDs: []string{protocolID1, protocolID2}, InitialPeerList: []string{initialPeersList}, }, Sharding: p2pConfig.ShardingConfig{ diff --git a/go.mod b/go.mod index 8c0a458138f..69c8b07ca2d 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,7 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 - github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad + github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126150131-2ac5bc749b40 github.com/multiversx/mx-chain-core-go v1.2.19-0.20240129082057-a76d0c995cf2 github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a diff --git a/go.sum b/go.sum index 11cb5b9a820..5835957d880 100644 --- a/go.sum +++ b/go.sum @@ -385,8 +385,8 @@ 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.13-0.20240126121117-627adccf10ad h1:izxTyKCxvT7z2mhXCWAZibSxwRVgLmq/kDovs4Nx/6Y= -github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad/go.mod h1:n4E8BWIV0g3AcNGe1gf+vcjUC8A2QCJ4ARQSbiUDGrI= +github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126150131-2ac5bc749b40 h1:bMFxkbb1EOQs0+JMM0G0/Kv9v4Jjjla5MSVhVk6scTA= +github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126150131-2ac5bc749b40/go.mod h1:n4E8BWIV0g3AcNGe1gf+vcjUC8A2QCJ4ARQSbiUDGrI= github.com/multiversx/mx-chain-core-go v1.2.19-0.20240129082057-a76d0c995cf2 h1:pFh9bwOTRgW173aHqA8Bmax+jYzLnRyXqRvi5alF7V4= github.com/multiversx/mx-chain-core-go v1.2.19-0.20240129082057-a76d0c995cf2/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 h1:beVIhs5ysylwNplQ/bZ0h5DoDlqKNWgpWE/NMHHNmAw= diff --git a/integrationTests/p2p/networkSharding-hbv2/networkSharding_test.go b/integrationTests/p2p/networkSharding-hbv2/networkSharding_test.go index c11c73838c5..b458b3f779f 100644 --- a/integrationTests/p2p/networkSharding-hbv2/networkSharding_test.go +++ b/integrationTests/p2p/networkSharding-hbv2/networkSharding_test.go @@ -31,7 +31,7 @@ func createDefaultConfig() p2pConfig.P2PConfig { Type: "optimized", RefreshIntervalInSec: 1, RoutingTableRefreshIntervalInSec: 1, - ProtocolID: "/erd/kad/1.0.0", + ProtocolIDs: []string{"/erd/kad/1.0.0"}, InitialPeerList: nil, BucketSize: 100, }, diff --git a/integrationTests/testInitializer.go b/integrationTests/testInitializer.go index 27a4d310d8a..9ba3d5d25a3 100644 --- a/integrationTests/testInitializer.go +++ b/integrationTests/testInitializer.go @@ -153,7 +153,7 @@ func createP2PConfig(initialPeerList []string) p2pConfig.P2PConfig { Enabled: true, Type: "optimized", RefreshIntervalInSec: 2, - ProtocolID: "/erd/kad/1.0.0", + ProtocolIDs: []string{"/erd/kad/1.0.0"}, InitialPeerList: initialPeerList, BucketSize: 100, RoutingTableRefreshIntervalInSec: 100, diff --git a/testscommon/components/components.go b/testscommon/components/components.go index cc4ec1b03ab..bd65895bab1 100644 --- a/testscommon/components/components.go +++ b/testscommon/components/components.go @@ -257,7 +257,7 @@ func GetNetworkFactoryArgs() networkComp.NetworkComponentsFactoryArgs { Enabled: false, Type: "optimized", RefreshIntervalInSec: 10, - ProtocolID: "erd/kad/1.0.0", + ProtocolIDs: []string{"erd/kad/1.0.0"}, InitialPeerList: []string{"peer0", "peer1"}, BucketSize: 10, RoutingTableRefreshIntervalInSec: 5, From 88f2fb20745d40cc178c23a4422d9df0bec2f706 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Wed, 31 Jan 2024 16:09:44 +0200 Subject: [PATCH 055/503] add integration tests --- integrationTests/vm/txsFee/common.go | 157 ++++++++++++++++++ .../vm/txsFee/esdtMetaDataRecreate_test.go | 99 +++++++++++ .../vm/txsFee/esdtMetaDataUpdate_test.go | 100 +++++++++++ .../vm/txsFee/esdtModifyCreator_test.go | 97 +++++++++++ .../vm/txsFee/esdtModifyRoyalties_test.go | 92 ++++++++++ .../vm/txsFee/esdtSetNewURIs_test.go | 95 +++++++++++ .../vm/txsFee/moveBalance_test.go | 2 - 7 files changed, 640 insertions(+), 2 deletions(-) create mode 100644 integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go create mode 100644 integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go create mode 100644 integrationTests/vm/txsFee/esdtModifyCreator_test.go create mode 100644 integrationTests/vm/txsFee/esdtModifyRoyalties_test.go create mode 100644 integrationTests/vm/txsFee/esdtSetNewURIs_test.go diff --git a/integrationTests/vm/txsFee/common.go b/integrationTests/vm/txsFee/common.go index 02e69b5260d..5e5fab10e1c 100644 --- a/integrationTests/vm/txsFee/common.go +++ b/integrationTests/vm/txsFee/common.go @@ -1,14 +1,153 @@ package txsFee import ( + "bytes" + "encoding/hex" + "math/big" "testing" + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/esdt" + "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/integrationTests/vm" "github.com/multiversx/mx-chain-go/state" "github.com/stretchr/testify/require" ) +const gasPrice = uint64(10) + +type metaData struct { + tokenId []byte + nonce []byte + name []byte + royalties []byte + hash []byte + attributes []byte + uris [][]byte +} + +func getDefaultMetaData() *metaData { + return &metaData{ + tokenId: []byte(hex.EncodeToString([]byte("tokenId"))), + nonce: []byte(hex.EncodeToString(big.NewInt(0).Bytes())), + name: []byte(hex.EncodeToString([]byte("name"))), + royalties: []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + hash: []byte(hex.EncodeToString([]byte("hash"))), + attributes: []byte(hex.EncodeToString([]byte("attributes"))), + uris: [][]byte{[]byte(hex.EncodeToString([]byte("uri1"))), []byte(hex.EncodeToString([]byte("uri2"))), []byte(hex.EncodeToString([]byte("uri3")))}, + } +} + +func getMetaDataFromAcc(t *testing.T, testContext *vm.VMTestContext, accWithMetaData []byte, token []byte) *esdt.MetaData { + account, err := testContext.Accounts.LoadAccount(accWithMetaData) + require.Nil(t, err) + userAccount, ok := account.(state.UserAccountHandler) + require.True(t, ok) + + key := append(token, big.NewInt(0).SetUint64(1).Bytes()...) + esdtDataBytes, _, err := userAccount.RetrieveValue(key) + require.Nil(t, err) + esdtData := &esdt.ESDigitalToken{} + err = testContext.Marshalizer.Unmarshal(esdtData, esdtDataBytes) + require.Nil(t, err) + + return esdtData.TokenMetaData +} + +func checkMetaData(t *testing.T, testContext *vm.VMTestContext, accWithMetaData []byte, token []byte, expectedMetaData *metaData) { + retrievedMetaData := getMetaDataFromAcc(t, testContext, accWithMetaData, token) + + require.Equal(t, expectedMetaData.nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) + require.Equal(t, expectedMetaData.name, []byte(hex.EncodeToString(retrievedMetaData.Name))) + require.Equal(t, expectedMetaData.royalties, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Royalties)).Bytes()))) + require.Equal(t, expectedMetaData.hash, []byte(hex.EncodeToString(retrievedMetaData.Hash))) + for i, uri := range expectedMetaData.uris { + require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) + } + require.Equal(t, expectedMetaData.attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) +} + +func getDynamicTokenTypes() []string { + return []string{ + core.DynamicNFTESDT, + core.DynamicSFTESDT, + core.DynamicMetaESDT, + } +} + +func getTokenTypes() []string { + return []string{ + core.FungibleESDT, + core.NonFungibleESDT, + core.NonFungibleESDTv2, + core.MetaESDT, + core.SemiFungibleESDT, + core.DynamicNFTESDT, + core.DynamicSFTESDT, + core.DynamicMetaESDT, + } +} + +func createTokenTx( + sndAddr []byte, + rcvAddr []byte, + gasLimit uint64, + quantity int64, + metaData *metaData, +) *transaction.Transaction { + txDataField := bytes.Join( + [][]byte{ + []byte(core.BuiltInFunctionESDTNFTCreate), + metaData.tokenId, + []byte(hex.EncodeToString(big.NewInt(quantity).Bytes())), // quantity + metaData.name, + metaData.royalties, + metaData.hash, + metaData.attributes, + []byte(hex.EncodeToString([]byte("uri"))), + }, + []byte("@"), + ) + + return &transaction.Transaction{ + Nonce: 0, + SndAddr: sndAddr, + RcvAddr: rcvAddr, + GasLimit: gasLimit, + GasPrice: gasPrice, + Data: txDataField, + Value: big.NewInt(0), + } +} + +func setTokenTypeTx( + sndAddr []byte, + gasLimit uint64, + tokenId []byte, + tokenType string, +) *transaction.Transaction { + txDataField := bytes.Join( + [][]byte{ + []byte(core.ESDTSetTokenType), + []byte(hex.EncodeToString(tokenId)), + []byte(hex.EncodeToString([]byte(tokenType))), + }, + []byte("@"), + ) + + return &transaction.Transaction{ + Nonce: 0, + SndAddr: sndAddr, + RcvAddr: core.SystemAccountAddress, + GasLimit: gasLimit, + GasPrice: gasPrice, + + Data: txDataField, + Value: big.NewInt(0), + } +} + func getAccount(tb testing.TB, testContext *vm.VMTestContext, scAddress []byte) state.UserAccountHandler { scAcc, err := testContext.Accounts.LoadAccount(scAddress) require.Nil(tb, err) @@ -25,3 +164,21 @@ func getAccountDataTrie(tb testing.TB, testContext *vm.VMTestContext, address [] return dataTrieInstance } + +func createAccWithBalance(t *testing.T, accnts state.AccountsAdapter, pubKey []byte, egldValue *big.Int) { + account, err := accnts.LoadAccount(pubKey) + require.Nil(t, err) + + userAccount, ok := account.(state.UserAccountHandler) + require.True(t, ok) + + userAccount.IncreaseNonce(0) + err = userAccount.AddToBalance(egldValue) + require.Nil(t, err) + + err = accnts.SaveAccount(userAccount) + require.Nil(t, err) + + _, err = accnts.Commit() + require.Nil(t, err) +} diff --git a/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go b/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go new file mode 100644 index 00000000000..ac0a7902f14 --- /dev/null +++ b/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go @@ -0,0 +1,99 @@ +package txsFee + +import ( + "bytes" + "encoding/hex" + "math/big" + "testing" + + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/integrationTests/vm" + "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/stretchr/testify/require" +) + +func TestESDTMetaDataRecreate(t *testing.T) { + tokenTypes := getDynamicTokenTypes() + for _, tokenType := range tokenTypes { + testName := "metaDataRecreate for " + tokenType + t.Run(testName, func(t *testing.T) { + runEsdtMetaDataRecreateTest(t, tokenType) + }) + } +} + +func runEsdtMetaDataRecreateTest(t *testing.T, tokenType string) { + sndAddr := []byte("12345678901234567890123456789012") + token := []byte("tokenId") + roles := [][]byte{[]byte(core.ESDTMetaDataRecreate), []byte(core.ESDTRoleNFTCreate)} + baseEsdtKeyPrefix := core.ProtectedKeyPrefix + core.ESDTKeyIdentifier + key := append([]byte(baseEsdtKeyPrefix), token...) + + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + require.Nil(t, err) + defer testContext.Close() + + createAccWithBalance(t, testContext.Accounts, sndAddr, big.NewInt(100000000)) + createAccWithBalance(t, testContext.Accounts, core.ESDTSCAddress, big.NewInt(100000000)) + utils.SetESDTRoles(t, testContext.Accounts, sndAddr, token, roles) + + tx := setTokenTypeTx(core.ESDTSCAddress, 100000, token, tokenType) + retCode, err := testContext.TxProcessor.ProcessTransaction(tx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) + + defaultMetaData := getDefaultMetaData() + tx = createTokenTx(sndAddr, sndAddr, 100000, 1, defaultMetaData) + retCode, err = testContext.TxProcessor.ProcessTransaction(tx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) + + // TODO change default metadata + defaultMetaData.nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + tx = esdtMetaDataRecreateTx(sndAddr, sndAddr, 100000, defaultMetaData) + retCode, err = testContext.TxProcessor.ProcessTransaction(tx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) + + _, err = testContext.Accounts.Commit() + require.Nil(t, err) + + checkMetaData(t, testContext, core.SystemAccountAddress, key, defaultMetaData) +} + +func esdtMetaDataRecreateTx( + sndAddr []byte, + rcvAddr []byte, + gasLimit uint64, + metaData *metaData, +) *transaction.Transaction { + txDataField := bytes.Join( + [][]byte{ + []byte(core.ESDTMetaDataRecreate), + metaData.tokenId, + metaData.nonce, + metaData.name, + metaData.royalties, + metaData.hash, + metaData.attributes, + metaData.uris[0], + metaData.uris[1], + metaData.uris[2], + }, + []byte("@"), + ) + + return &transaction.Transaction{ + Nonce: 1, + SndAddr: sndAddr, + RcvAddr: rcvAddr, + GasLimit: gasLimit, + GasPrice: gasPrice, + + Data: txDataField, + Value: big.NewInt(0), + } +} diff --git a/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go b/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go new file mode 100644 index 00000000000..33aece1aacc --- /dev/null +++ b/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go @@ -0,0 +1,100 @@ +package txsFee + +import ( + "bytes" + "encoding/hex" + "math/big" + "testing" + + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/integrationTests/vm" + "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/stretchr/testify/require" +) + +func TestESDTMetaDataUpdate(t *testing.T) { + tokenTypes := getDynamicTokenTypes() + for _, tokenType := range tokenTypes { + testName := "metaDataUpdate for " + tokenType + t.Run(testName, func(t *testing.T) { + runEsdtMetaDataUpdateTest(t, tokenType) + }) + } +} + +func runEsdtMetaDataUpdateTest(t *testing.T, tokenType string) { + sndAddr := []byte("12345678901234567890123456789012") + token := []byte("tokenId") + roles := [][]byte{[]byte(core.ESDTRoleNFTUpdate), []byte(core.ESDTRoleNFTCreate)} + baseEsdtKeyPrefix := core.ProtectedKeyPrefix + core.ESDTKeyIdentifier + key := append([]byte(baseEsdtKeyPrefix), token...) + + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + require.Nil(t, err) + defer testContext.Close() + + createAccWithBalance(t, testContext.Accounts, sndAddr, big.NewInt(100000000)) + createAccWithBalance(t, testContext.Accounts, core.ESDTSCAddress, big.NewInt(100000000)) + utils.SetESDTRoles(t, testContext.Accounts, sndAddr, token, roles) + + tx := setTokenTypeTx(core.ESDTSCAddress, 100000, token, tokenType) + retCode, err := testContext.TxProcessor.ProcessTransaction(tx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) + + defaultMetaData := getDefaultMetaData() + tx = createTokenTx(sndAddr, sndAddr, 100000, 1, defaultMetaData) + retCode, err = testContext.TxProcessor.ProcessTransaction(tx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) + + // TODO change default metadata + defaultMetaData.nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + defaultMetaData.name = []byte(hex.EncodeToString([]byte("newName"))) + defaultMetaData.hash = []byte(hex.EncodeToString([]byte("newHash"))) + defaultMetaData.uris = [][]byte{defaultMetaData.uris[1]} + tx = esdtMetaDataUpdateTx(sndAddr, sndAddr, 100000, defaultMetaData) + retCode, err = testContext.TxProcessor.ProcessTransaction(tx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) + + _, err = testContext.Accounts.Commit() + require.Nil(t, err) + + checkMetaData(t, testContext, core.SystemAccountAddress, key, defaultMetaData) +} + +func esdtMetaDataUpdateTx( + sndAddr []byte, + rcvAddr []byte, + gasLimit uint64, + metaData *metaData, +) *transaction.Transaction { + txDataField := bytes.Join( + [][]byte{ + []byte(core.ESDTMetaDataUpdate), + metaData.tokenId, + metaData.nonce, + metaData.name, + metaData.royalties, + metaData.hash, + metaData.attributes, + metaData.uris[0], + }, + []byte("@"), + ) + + return &transaction.Transaction{ + Nonce: 1, + SndAddr: sndAddr, + RcvAddr: rcvAddr, + GasLimit: gasLimit, + GasPrice: gasPrice, + + Data: txDataField, + Value: big.NewInt(0), + } +} diff --git a/integrationTests/vm/txsFee/esdtModifyCreator_test.go b/integrationTests/vm/txsFee/esdtModifyCreator_test.go new file mode 100644 index 00000000000..f800268602b --- /dev/null +++ b/integrationTests/vm/txsFee/esdtModifyCreator_test.go @@ -0,0 +1,97 @@ +package txsFee + +import ( + "bytes" + "encoding/hex" + "math/big" + "testing" + + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/integrationTests/vm" + "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/stretchr/testify/require" +) + +func TestESDTModifyCreator(t *testing.T) { + tokenTypes := getDynamicTokenTypes() + for _, tokenType := range tokenTypes { + esdtType, _ := core.ConvertESDTTypeToUint32(tokenType) + if !core.IsDynamicESDT(esdtType) { + continue + } + testName := "esdtModifyCreator for " + tokenType + t.Run(testName, func(t *testing.T) { + runEsdtModifyCreatorTest(t, tokenType) + }) + } +} + +func runEsdtModifyCreatorTest(t *testing.T, tokenType string) { + newCreator := []byte("12345678901234567890123456789012") + creatorAddr := []byte("12345678901234567890123456789013") + token := []byte("tokenId") + baseEsdtKeyPrefix := core.ProtectedKeyPrefix + core.ESDTKeyIdentifier + key := append([]byte(baseEsdtKeyPrefix), token...) + + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + require.Nil(t, err) + defer testContext.Close() + + createAccWithBalance(t, testContext.Accounts, newCreator, big.NewInt(100000000)) + createAccWithBalance(t, testContext.Accounts, creatorAddr, big.NewInt(100000000)) + createAccWithBalance(t, testContext.Accounts, core.ESDTSCAddress, big.NewInt(100000000)) + utils.SetESDTRoles(t, testContext.Accounts, creatorAddr, token, [][]byte{[]byte(core.ESDTRoleNFTCreate)}) + utils.SetESDTRoles(t, testContext.Accounts, newCreator, token, [][]byte{[]byte(core.ESDTRoleModifyCreator)}) + + tx := setTokenTypeTx(core.ESDTSCAddress, 100000, token, tokenType) + retCode, err := testContext.TxProcessor.ProcessTransaction(tx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) + + defaultMetaData := getDefaultMetaData() + defaultMetaData.nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + tx = createTokenTx(creatorAddr, creatorAddr, 100000, 1, defaultMetaData) + retCode, err = testContext.TxProcessor.ProcessTransaction(tx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) + + tx = esdtModifyCreatorTx(newCreator, newCreator, 100000, defaultMetaData) + retCode, err = testContext.TxProcessor.ProcessTransaction(tx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) + + _, err = testContext.Accounts.Commit() + require.Nil(t, err) + + retrievedMetaData := getMetaDataFromAcc(t, testContext, core.SystemAccountAddress, key) + require.Equal(t, newCreator, retrievedMetaData.Creator) +} + +func esdtModifyCreatorTx( + sndAddr []byte, + rcvAddr []byte, + gasLimit uint64, + metaData *metaData, +) *transaction.Transaction { + txDataField := bytes.Join( + [][]byte{ + []byte(core.ESDTModifyCreator), + metaData.tokenId, + metaData.nonce, + }, + []byte("@"), + ) + return &transaction.Transaction{ + Nonce: 0, + SndAddr: sndAddr, + RcvAddr: rcvAddr, + GasLimit: gasLimit, + GasPrice: gasPrice, + + Data: txDataField, + Value: big.NewInt(0), + } +} diff --git a/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go b/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go new file mode 100644 index 00000000000..aa13bdf3ef6 --- /dev/null +++ b/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go @@ -0,0 +1,92 @@ +package txsFee + +import ( + "bytes" + "encoding/hex" + "math/big" + "testing" + + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/integrationTests/vm" + "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/stretchr/testify/require" +) + +func TestESDTModifyRoyalties(t *testing.T) { + tokenTypes := getDynamicTokenTypes() + for _, tokenType := range tokenTypes { + testName := "esdtModifyRoyalties for " + tokenType + t.Run(testName, func(t *testing.T) { + runEsdtModifyRoyaltiesTest(t, tokenType) + }) + } +} + +func runEsdtModifyRoyaltiesTest(t *testing.T, tokenType string) { + creatorAddr := []byte("12345678901234567890123456789013") + token := []byte("tokenId") + baseEsdtKeyPrefix := core.ProtectedKeyPrefix + core.ESDTKeyIdentifier + key := append([]byte(baseEsdtKeyPrefix), token...) + + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + require.Nil(t, err) + defer testContext.Close() + + createAccWithBalance(t, testContext.Accounts, creatorAddr, big.NewInt(100000000)) + createAccWithBalance(t, testContext.Accounts, core.ESDTSCAddress, big.NewInt(100000000)) + utils.SetESDTRoles(t, testContext.Accounts, creatorAddr, token, [][]byte{[]byte(core.ESDTRoleModifyRoyalties), []byte(core.ESDTRoleNFTCreate)}) + + tx := setTokenTypeTx(core.ESDTSCAddress, 100000, token, tokenType) + retCode, err := testContext.TxProcessor.ProcessTransaction(tx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) + + defaultMetaData := getDefaultMetaData() + tx = createTokenTx(creatorAddr, creatorAddr, 100000, 1, defaultMetaData) + retCode, err = testContext.TxProcessor.ProcessTransaction(tx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) + + defaultMetaData.nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + defaultMetaData.royalties = []byte(hex.EncodeToString(big.NewInt(20).Bytes())) + tx = esdtModifyRoyaltiesTx(creatorAddr, creatorAddr, 100000, defaultMetaData) + retCode, err = testContext.TxProcessor.ProcessTransaction(tx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) + + _, err = testContext.Accounts.Commit() + require.Nil(t, err) + + retrievedMetaData := getMetaDataFromAcc(t, testContext, core.SystemAccountAddress, key) + require.Equal(t, uint32(big.NewInt(20).Uint64()), retrievedMetaData.Royalties) +} + +func esdtModifyRoyaltiesTx( + sndAddr []byte, + rcvAddr []byte, + gasLimit uint64, + metaData *metaData, +) *transaction.Transaction { + txDataField := bytes.Join( + [][]byte{ + []byte(core.ESDTModifyRoyalties), + metaData.tokenId, + metaData.nonce, + metaData.royalties, + }, + []byte("@"), + ) + return &transaction.Transaction{ + Nonce: 1, + SndAddr: sndAddr, + RcvAddr: rcvAddr, + GasLimit: gasLimit, + GasPrice: gasPrice, + + Data: txDataField, + Value: big.NewInt(0), + } +} diff --git a/integrationTests/vm/txsFee/esdtSetNewURIs_test.go b/integrationTests/vm/txsFee/esdtSetNewURIs_test.go new file mode 100644 index 00000000000..d7b89d5445b --- /dev/null +++ b/integrationTests/vm/txsFee/esdtSetNewURIs_test.go @@ -0,0 +1,95 @@ +package txsFee + +import ( + "bytes" + "encoding/hex" + "math/big" + "testing" + + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/integrationTests/vm" + "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/stretchr/testify/require" +) + +func TestESDTSetNewURIs(t *testing.T) { + tokenTypes := getDynamicTokenTypes() + for _, tokenType := range tokenTypes { + testName := "ESDTsetNewURIs for " + tokenType + t.Run(testName, func(t *testing.T) { + runEsdtSetNewURIsTest(t, tokenType) + }) + } +} + +func runEsdtSetNewURIsTest(t *testing.T, tokenType string) { + sndAddr := []byte("12345678901234567890123456789012") + token := []byte("tokenId") + roles := [][]byte{[]byte(core.ESDTRoleSetNewURI), []byte(core.ESDTRoleNFTCreate)} + baseEsdtKeyPrefix := core.ProtectedKeyPrefix + core.ESDTKeyIdentifier + key := append([]byte(baseEsdtKeyPrefix), token...) + + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + require.Nil(t, err) + defer testContext.Close() + + createAccWithBalance(t, testContext.Accounts, sndAddr, big.NewInt(100000000)) + createAccWithBalance(t, testContext.Accounts, core.ESDTSCAddress, big.NewInt(100000000)) + utils.SetESDTRoles(t, testContext.Accounts, sndAddr, token, roles) + + tx := setTokenTypeTx(core.ESDTSCAddress, 100000, token, tokenType) + retCode, err := testContext.TxProcessor.ProcessTransaction(tx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) + + defaultMetaData := getDefaultMetaData() + tx = createTokenTx(sndAddr, sndAddr, 100000, 1, defaultMetaData) + retCode, err = testContext.TxProcessor.ProcessTransaction(tx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) + + defaultMetaData.uris = [][]byte{[]byte(hex.EncodeToString([]byte("newUri1"))), []byte(hex.EncodeToString([]byte("newUri2")))} + defaultMetaData.nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + tx = esdtSetNewUrisTx(sndAddr, sndAddr, 100000, defaultMetaData) + retCode, err = testContext.TxProcessor.ProcessTransaction(tx) + require.Equal(t, vmcommon.Ok, retCode) + require.Nil(t, err) + + _, err = testContext.Accounts.Commit() + require.Nil(t, err) + + retrievedMetaData := getMetaDataFromAcc(t, testContext, core.SystemAccountAddress, key) + require.Equal(t, [][]byte{[]byte("newUri1"), []byte("newUri2")}, retrievedMetaData.URIs) +} + +func esdtSetNewUrisTx( + sndAddr []byte, + rcvAddr []byte, + gasLimit uint64, + metaData *metaData, +) *transaction.Transaction { + txDataField := bytes.Join( + [][]byte{ + []byte(core.ESDTSetNewURIs), + metaData.tokenId, + metaData.nonce, + metaData.uris[0], + metaData.uris[1], + }, + []byte("@"), + ) + + return &transaction.Transaction{ + Nonce: 1, + SndAddr: sndAddr, + RcvAddr: rcvAddr, + GasLimit: gasLimit, + GasPrice: gasPrice, + + Data: txDataField, + Value: big.NewInt(0), + } +} diff --git a/integrationTests/vm/txsFee/moveBalance_test.go b/integrationTests/vm/txsFee/moveBalance_test.go index 78646813825..8a119084cff 100644 --- a/integrationTests/vm/txsFee/moveBalance_test.go +++ b/integrationTests/vm/txsFee/moveBalance_test.go @@ -16,8 +16,6 @@ import ( "github.com/stretchr/testify/require" ) -const gasPrice = uint64(10) - // minGasPrice = 1, gasPerDataByte = 1, minGasLimit = 1 func TestMoveBalanceSelfShouldWorkAndConsumeTxFee(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) From be0224b5fe8ed7cd2b59f83eb9dc9e9cae2479dd Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Wed, 31 Jan 2024 16:19:54 +0200 Subject: [PATCH 056/503] linter fix --- integrationTests/vm/txsFee/common.go | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/integrationTests/vm/txsFee/common.go b/integrationTests/vm/txsFee/common.go index 5e5fab10e1c..8d94f929382 100644 --- a/integrationTests/vm/txsFee/common.go +++ b/integrationTests/vm/txsFee/common.go @@ -76,19 +76,6 @@ func getDynamicTokenTypes() []string { } } -func getTokenTypes() []string { - return []string{ - core.FungibleESDT, - core.NonFungibleESDT, - core.NonFungibleESDTv2, - core.MetaESDT, - core.SemiFungibleESDT, - core.DynamicNFTESDT, - core.DynamicSFTESDT, - core.DynamicMetaESDT, - } -} - func createTokenTx( sndAddr []byte, rcvAddr []byte, From 922d528d203bf8369c66fbb393460cf065c9d262 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 31 Jan 2024 16:54:40 +0200 Subject: [PATCH 057/503] integrate factory from storage --- go.mod | 2 +- go.sum | 2 ++ storage/constants.go | 6 ++-- storage/factory/persisterCreator.go | 19 +++++----- storage/factory/persisterFactory_test.go | 38 ++++++++++++++++++++ storage/storageunit/constants.go | 16 +++++---- storage/storageunit/storageunit.go | 38 ++++++++++++++++---- storage/storageunit/storageunit_test.go | 44 ------------------------ 8 files changed, 94 insertions(+), 71 deletions(-) diff --git a/go.mod b/go.mod index 9b6c7159b39..7655e0f331e 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/multiversx/mx-chain-es-indexer-go v1.4.18-0.20231228064619-e3b0caf29058 github.com/multiversx/mx-chain-logger-go v1.0.14-0.20231215125130-a3bed6e76040 github.com/multiversx/mx-chain-scenario-go v1.2.2-0.20231129113427-ad3056f45296 - github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240103193554-5ad54212812d + github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240131142608-5c126467749c github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20231228070003-ae14e1e0adfa github.com/multiversx/mx-chain-vm-go v1.5.23-0.20231228064104-964359cb8dd3 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.65-0.20231228071026-eed2cb19c216 diff --git a/go.sum b/go.sum index aebf8ac5ff3..64e35192dc1 100644 --- a/go.sum +++ b/go.sum @@ -403,6 +403,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15-0.20231213110622-e222ba96a9f4 github.com/multiversx/mx-chain-storage-go v1.0.15-0.20231213110622-e222ba96a9f4/go.mod h1:ioCT2oHQ+TyHQYpgjxzlUdy7dCdv56+w5HnBg9z96eY= github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240103193554-5ad54212812d h1:mNf2qlDGSNp6yd4rSJBT93vGseuqraj8/jWWXm1ro+k= github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240103193554-5ad54212812d/go.mod h1:ioCT2oHQ+TyHQYpgjxzlUdy7dCdv56+w5HnBg9z96eY= +github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240131142608-5c126467749c h1:Fr0PM4Kh33QqTHyIqzRQqx049zNvmeKKSCxCFfB/JK4= +github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240131142608-5c126467749c/go.mod h1:ioCT2oHQ+TyHQYpgjxzlUdy7dCdv56+w5HnBg9z96eY= github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20231228070003-ae14e1e0adfa h1:xdDeUC4yOfiUwctkYioYMjjigBZoZo5RZq1e5WoCVRs= github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20231228070003-ae14e1e0adfa/go.mod h1:7jjGRykSfLeMs6iQdszlE0lGK2xp9/cctiVdeKbQLLM= github.com/multiversx/mx-chain-vm-go v1.5.23-0.20231228064104-964359cb8dd3 h1:qfzeTPI2oSgxnw52KiVWc2fHMem6FZIkX1Azwy64098= diff --git a/storage/constants.go b/storage/constants.go index b78021138c7..9cd37571521 100644 --- a/storage/constants.go +++ b/storage/constants.go @@ -1,14 +1,14 @@ package storage import ( - "github.com/multiversx/mx-chain-storage-go/storageUnit" + "github.com/multiversx/mx-chain-storage-go/common" ) // MaxRetriesToCreateDB represents the maximum number of times to try to create DB if it failed -const MaxRetriesToCreateDB = storageUnit.MaxRetriesToCreateDB +const MaxRetriesToCreateDB = common.MaxRetriesToCreateDB // SleepTimeBetweenCreateDBRetries represents the number of seconds to sleep between DB creates -const SleepTimeBetweenCreateDBRetries = storageUnit.SleepTimeBetweenCreateDBRetries +const SleepTimeBetweenCreateDBRetries = common.SleepTimeBetweenCreateDBRetries // PathShardPlaceholder represents the placeholder for the shard ID in paths const PathShardPlaceholder = "[S]" diff --git a/storage/factory/persisterCreator.go b/storage/factory/persisterCreator.go index 1357fc37ae4..13398c38a5c 100644 --- a/storage/factory/persisterCreator.go +++ b/storage/factory/persisterCreator.go @@ -5,6 +5,7 @@ import ( "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/storage/database" "github.com/multiversx/mx-chain-go/storage/storageunit" + "github.com/multiversx/mx-chain-storage-go/factory" ) const minNumShards = 2 @@ -51,16 +52,16 @@ func (pc *persisterCreator) Create(path string) (storage.Persister, error) { // CreateBasePersister will create base the persister for the provided path func (pc *persisterCreator) CreateBasePersister(path string) (storage.Persister, error) { var dbType = storageunit.DBType(pc.dbType) - switch dbType { - case storageunit.LvlDB: - return database.NewLevelDB(path, pc.batchDelaySeconds, pc.maxBatchSize, pc.maxOpenFiles) - case storageunit.LvlDBSerial: - return database.NewSerialDB(path, pc.batchDelaySeconds, pc.maxBatchSize, pc.maxOpenFiles) - case storageunit.MemoryDB: - return database.NewMemDB(), nil - default: - return nil, storage.ErrNotSupportedDBType + + argsDB := factory.ArgDB{ + DBType: dbType, + Path: path, + BatchDelaySeconds: pc.batchDelaySeconds, + MaxBatchSize: pc.maxBatchSize, + MaxOpenFiles: pc.maxOpenFiles, } + + return storageunit.NewDB(argsDB) } func (pc *persisterCreator) createShardIDProvider() (storage.ShardIDProvider, error) { diff --git a/storage/factory/persisterFactory_test.go b/storage/factory/persisterFactory_test.go index 860331a22bc..7dd1f987510 100644 --- a/storage/factory/persisterFactory_test.go +++ b/storage/factory/persisterFactory_test.go @@ -3,11 +3,14 @@ package factory_test import ( "fmt" "os" + "path" "testing" + "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/storage/factory" "github.com/multiversx/mx-chain-go/storage/storageunit" + "github.com/multiversx/mx-chain-storage-go/common" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -46,6 +49,41 @@ func TestPersisterFactory_Create(t *testing.T) { }) } +func TestPersisterFactory_CreateWithRetries(t *testing.T) { + t.Parallel() + + t.Run("wrong config should error", func(t *testing.T) { + t.Parallel() + + path := "TEST" + dbConfig := createDefaultDBConfig() + dbConfig.Type = "invalid type" + + persisterFactory, err := factory.NewPersisterFactory(dbConfig) + assert.Nil(t, err) + + db, err := persisterFactory.CreateWithRetries(path) + assert.True(t, check.IfNil(db)) + assert.Equal(t, common.ErrNotSupportedDBType, err) + }) + + t.Run("should work", func(t *testing.T) { + t.Parallel() + + path := path.Join(t.TempDir(), "TEST") + dbConfig := createDefaultDBConfig() + dbConfig.FilePath = path + + persisterFactory, err := factory.NewPersisterFactory(dbConfig) + assert.Nil(t, err) + + db, err := persisterFactory.CreateWithRetries(path) + assert.False(t, check.IfNil(db)) + assert.Nil(t, err) + _ = db.Close() + }) +} + func TestPersisterFactory_Create_ConfigSaveToFilePath(t *testing.T) { t.Parallel() diff --git a/storage/storageunit/constants.go b/storage/storageunit/constants.go index 0e128af8123..022715dbcb7 100644 --- a/storage/storageunit/constants.go +++ b/storage/storageunit/constants.go @@ -1,25 +1,27 @@ package storageunit -import "github.com/multiversx/mx-chain-storage-go/storageUnit" +import ( + "github.com/multiversx/mx-chain-storage-go/common" +) const ( // LRUCache defines a cache identifier with least-recently-used eviction mechanism - LRUCache = storageUnit.LRUCache + LRUCache = common.LRUCache // SizeLRUCache defines a cache identifier with least-recently-used eviction mechanism and fixed size in bytes - SizeLRUCache = storageUnit.SizeLRUCache + SizeLRUCache = common.SizeLRUCache ) // DB types that are currently supported const ( // LvlDB represents a levelDB storage identifier - LvlDB = storageUnit.LvlDB + LvlDB = common.LvlDB // LvlDBSerial represents a levelDB storage with serialized operations identifier - LvlDBSerial = storageUnit.LvlDBSerial + LvlDBSerial = common.LvlDBSerial // MemoryDB represents an in memory storage identifier - MemoryDB = storageUnit.MemoryDB + MemoryDB = common.MemoryDB ) // Shard id provider types that are currently supported const ( - BinarySplit = storageUnit.BinarySplit + BinarySplit = common.BinarySplit ) diff --git a/storage/storageunit/storageunit.go b/storage/storageunit/storageunit.go index 2a9e390b725..c1944777920 100644 --- a/storage/storageunit/storageunit.go +++ b/storage/storageunit/storageunit.go @@ -3,6 +3,8 @@ package storageunit import ( "github.com/multiversx/mx-chain-core-go/marshal" "github.com/multiversx/mx-chain-go/storage" + "github.com/multiversx/mx-chain-storage-go/common" + "github.com/multiversx/mx-chain-storage-go/factory" "github.com/multiversx/mx-chain-storage-go/storageCacherAdapter" "github.com/multiversx/mx-chain-storage-go/storageUnit" ) @@ -12,22 +14,25 @@ import ( type Unit = storageUnit.Unit // CacheConfig holds the configurable elements of a cache -type CacheConfig = storageUnit.CacheConfig +type CacheConfig = common.CacheConfig // DBConfig holds the configurable elements of a database -type DBConfig = storageUnit.DBConfig +type DBConfig = common.DBConfig // NilStorer resembles a disabled implementation of the Storer interface type NilStorer = storageUnit.NilStorer // CacheType represents the type of the supported caches -type CacheType = storageUnit.CacheType +type CacheType = common.CacheType // DBType represents the type of the supported databases -type DBType = storageUnit.DBType +type DBType = common.DBType // ShardIDProviderType represents the type of the supported shard id providers -type ShardIDProviderType = storageUnit.ShardIDProviderType +type ShardIDProviderType = common.ShardIDProviderType + +// ArgDB is a structure that is used to create a new storage.Persister implementation +type ArgDB = factory.ArgDB // NewStorageUnit is the constructor for the storage unit, creating a new storage unit // from the given cacher and persister. @@ -37,12 +42,31 @@ func NewStorageUnit(c storage.Cacher, p storage.Persister) (*Unit, error) { // NewCache creates a new cache from a cache config func NewCache(config CacheConfig) (storage.Cacher, error) { - return storageUnit.NewCache(config) + return factory.NewCache(config) +} + +// NewDB creates a new database from database config +func NewDB(args ArgDB) (storage.Persister, error) { + return factory.NewDB(args) } // NewStorageUnitFromConf creates a new storage unit from a storage unit config func NewStorageUnitFromConf(cacheConf CacheConfig, dbConf DBConfig, persisterFactory storage.PersisterFactoryHandler) (*Unit, error) { - return storageUnit.NewStorageUnitFromConf(cacheConf, dbConf, persisterFactory) + if dbConf.MaxBatchSize > int(cacheConf.Capacity) { + return nil, common.ErrCacheSizeIsLowerThanBatchSize + } + + cache, err := NewCache(cacheConf) + if err != nil { + return nil, err + } + + db, err := persisterFactory.CreateWithRetries(dbConf.FilePath) + if err != nil { + return nil, err + } + + return NewStorageUnit(cache, db) } // NewNilStorer will return a nil storer diff --git a/storage/storageunit/storageunit_test.go b/storage/storageunit/storageunit_test.go index 0652f25b33c..da4aea63b33 100644 --- a/storage/storageunit/storageunit_test.go +++ b/storage/storageunit/storageunit_test.go @@ -72,50 +72,6 @@ func TestNewCache(t *testing.T) { }) } -func TestNewDB(t *testing.T) { - t.Parallel() - - t.Run("wrong config should error", func(t *testing.T) { - t.Parallel() - - path := "TEST" - dbConfig := config.DBConfig{ - FilePath: path, - Type: "invalid type", - BatchDelaySeconds: 5, - MaxBatchSize: 10, - MaxOpenFiles: 10, - } - - persisterFactory, err := factory.NewPersisterFactory(dbConfig) - assert.Nil(t, err) - - db, err := persisterFactory.CreateWithRetries(path) - assert.True(t, check.IfNil(db)) - assert.Equal(t, common.ErrNotSupportedDBType, err) - }) - t.Run("should work", func(t *testing.T) { - t.Parallel() - - path := path.Join(t.TempDir(), "TEST") - dbConfig := config.DBConfig{ - FilePath: path, - Type: "LvlDBSerial", - BatchDelaySeconds: 5, - MaxBatchSize: 10, - MaxOpenFiles: 10, - } - - persisterFactory, err := factory.NewPersisterFactory(dbConfig) - assert.Nil(t, err) - - db, err := persisterFactory.CreateWithRetries(path) - assert.False(t, check.IfNil(db)) - assert.Nil(t, err) - _ = db.Close() - }) -} - func TestNewStorageUnitFromConf(t *testing.T) { t.Parallel() From 6b309c844999bca6967fe8ece9a0921a5f2fa1db Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Thu, 1 Feb 2024 11:56:18 +0200 Subject: [PATCH 058/503] - fixed typos --- cmd/node/config/fullArchiveP2P.toml | 4 ++-- cmd/node/config/p2p.toml | 4 ++-- cmd/seednode/config/p2p.toml | 4 ++-- config/tomlConfig_test.go | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/node/config/fullArchiveP2P.toml b/cmd/node/config/fullArchiveP2P.toml index 01fbeb79789..41dd8c3f39f 100644 --- a/cmd/node/config/fullArchiveP2P.toml +++ b/cmd/node/config/fullArchiveP2P.toml @@ -48,8 +48,8 @@ # RefreshIntervalInSec represents the time in seconds between querying for new peers RefreshIntervalInSec = 10 - # ProtocolIDs represents the protocols that this node will advertize to other peers - # To connect to other nodes, those nodes should have at least on common protocol string + # ProtocolIDs represents the protocols that this node will advertise to other peers + # To connect to other nodes, those nodes should have at least one common protocol string ProtocolIDs = [ "/erd/kad/1.0.0", "mvx-full-archive", diff --git a/cmd/node/config/p2p.toml b/cmd/node/config/p2p.toml index 2fd4eeca66a..6cb2fbc88cc 100644 --- a/cmd/node/config/p2p.toml +++ b/cmd/node/config/p2p.toml @@ -48,8 +48,8 @@ # RefreshIntervalInSec represents the time in seconds between querying for new peers RefreshIntervalInSec = 10 - # ProtocolIDs represents the protocols that this node will advertize to other peers - # To connect to other nodes, those nodes should have at least on common protocol string + # ProtocolIDs represents the protocols that this node will advertise to other peers + # To connect to other nodes, those nodes should have at least one common protocol string ProtocolIDs = [ "/erd/kad/1.0.0", "mvx-main", diff --git a/cmd/seednode/config/p2p.toml b/cmd/seednode/config/p2p.toml index 5ca9fa33c94..cd98c9e6798 100644 --- a/cmd/seednode/config/p2p.toml +++ b/cmd/seednode/config/p2p.toml @@ -47,8 +47,8 @@ #RefreshIntervalInSec represents the time in seconds between querying for new peers RefreshIntervalInSec = 10 - # ProtocolIDs represents the protocols that this node will advertize to other peers - # To connect to other nodes, those nodes should have at least on common protocol string + # ProtocolIDs represents the protocols that this node will advertise to other peers + # To connect to other nodes, those nodes should have at least one common protocol string ProtocolIDs = [ "/erd/kad/1.0.0", "mvx-main", diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index c4043d71652..9edd7de61e3 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -500,8 +500,8 @@ func TestP2pConfig(t *testing.T) { Type = "" RefreshIntervalInSec = 0 - # ProtocolIDs represents the protocols that this node will advertize to other peers - # To connect to other nodes, those nodes should have at least on common protocol string + # ProtocolIDs represents the protocols that this node will advertise to other peers + # To connect to other nodes, those nodes should have at least one common protocol string ProtocolIDs = [ "` + protocolID1 + `", "` + protocolID2 + `", From b4379e3b8aeb09c0de4561b5fbecbf9a731b0cbe Mon Sep 17 00:00:00 2001 From: dragosrebegea Date: Mon, 12 Feb 2024 18:13:49 +0200 Subject: [PATCH 059/503] MX-15168: MaxDelegationCap tests --- .../chainSimulator/staking/delegation_test.go | 365 +++++++++++++++++- 1 file changed, 359 insertions(+), 6 deletions(-) diff --git a/integrationTests/chainSimulator/staking/delegation_test.go b/integrationTests/chainSimulator/staking/delegation_test.go index 8bf2ca1e1d5..625d1759426 100644 --- a/integrationTests/chainSimulator/staking/delegation_test.go +++ b/integrationTests/chainSimulator/staking/delegation_test.go @@ -48,10 +48,10 @@ const maxCap = "00" // no cap const serviceFee = "0ea1" // 37.45% const walletAddressBytesLen = 32 -var stakeValue = big.NewInt(0).Mul(oneEGLD, big.NewInt(1250)) // 1250 EGLD var zeroValue = big.NewInt(0) var oneEGLD = big.NewInt(1000000000000000000) var minimumStakeValue = big.NewInt(0).Mul(oneEGLD, big.NewInt(2500)) +var minimumCreateDelegationStakeValue = big.NewInt(0).Mul(oneEGLD, big.NewInt(1250)) // Test description // Test that delegation contract created with MakeNewContractFromValidatorData works properly @@ -317,7 +317,7 @@ func testBLSKeyIsInQueueOrAuction(t *testing.T, metachainNode chainSimulatorProc require.Nil(t, err) statistics, err := metachainNode.GetFacadeHandler().ValidatorStatisticsApi() require.Nil(t, err) - assert.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, address)) + require.Zero(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, address))) activationEpoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step1Flag) if activationEpoch <= metachainNode.GetCoreComponents().EnableEpochsHandler().GetCurrentEpoch() { @@ -355,8 +355,8 @@ func testBLSKeyIsInAuction( require.Equal(t, actionListSize, len(auctionList)) if actionListSize != 0 { - require.Equal(t, 1, len(auctionList[0].Nodes)) - require.Equal(t, topUpInAuctionList.String(), auctionList[0].TopUpPerNode) + require.Equal(t, 1, len(auctionList[0].Nodes)) + require.Equal(t, topUpInAuctionList.String(), auctionList[0].TopUpPerNode) } // in staking ph 4 we should find the key in the validators statics @@ -566,6 +566,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat err = cs.SetStateMultiple(addresses) require.Nil(t, err) + stakeValue := big.NewInt(0).Set(minimumCreateDelegationStakeValue) // 1250 EGLD // Step 3: Create a new delegation contract maxDelegationCap := big.NewInt(0).Mul(oneEGLD, big.NewInt(51000)) // 51000 EGLD cap serviceFee := big.NewInt(100) // 100 as service fee @@ -678,7 +679,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Equal(t, 0, len(unStakedKeys)) // Make block finalized - err = cs.GenerateBlocks(1) + err = cs.GenerateBlocks(2) // allow the metachain to finalize the block that contains the staking of the node require.Nil(t, err) testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationContractAddressBytes, blsKeys[0], expectedTopUp, 1) @@ -697,7 +698,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) - require.Equal(t, expectedTopUp.String(), getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes).String()) + require.Zero(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes))) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator1Bytes}) require.Nil(t, err) @@ -750,6 +751,358 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Equal(t, blsKeys[0], hex.EncodeToString(unStakedKeys[0])) } +func TestChainSimulator_MaxDelegationCap(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 30, + } + + // Test scenario done in staking 3.5 phase (staking v4 is not active) + // 1. Add a new validator private key in the multi key handler + // 2. Set the initial state for the owner and the 3 delegators + // 3. Create a new delegation contract with 1250 egld + // 4. Add node to the delegation contract + // 5. Delegate from user A 1250 EGLD each, check the topup is 2500 + // 6. Delegate from user B 501 EGLD each, check it fails + // 7. Stake node, check the topup is 0, check the node is staked + // 8. Delegate from user B 501 EGLD each, check it fails + // 9. Delegate from user B 500 EGLD each, check the topup is 500 + // 10. Delegate from user B 20 EGLD each, check it fails + t.Run("staking ph 4 is not active", func(t *testing.T) { + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 + cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 + cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 102 + + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 102 + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + testChainSimulatorMaxDelegationCap(t, cs, 1) + }) + + // Test scenario done in staking v4 phase step 1 + // 1. Add a new validator private key in the multi key handler + // 2. Set the initial state for the owner and the 3 delegators + // 3. Create a new delegation contract with 1250 egld + // 4. Add node to the delegation contract + // 5. Delegate from user A 1250 EGLD each, check the topup is 2500 + // 6. Delegate from user B 501 EGLD each, check it fails + // 7. Stake node, check the topup is 0, check the node is staked, check the node is in action list + // 8. Delegate from user B 501 EGLD each, check it fails + // 9. Delegate from user B 500 EGLD each, check the topup is 500 + // 10. Delegate from user B 20 EGLD each, check it fails + t.Run("staking ph 4 step 1 is active", func(t *testing.T) { + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 + cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 + cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 4 + + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 4 + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + testChainSimulatorMaxDelegationCap(t, cs, 2) + }) + + // Test scenario done in staking v4 phase step 2 + // 1. Add a new validator private key in the multi key handler + // 2. Set the initial state for the owner and the 3 delegators + // 3. Create a new delegation contract with 1250 egld + // 4. Add node to the delegation contract + // 5. Delegate from user A 1250 EGLD each, check the topup is 2500 + // 6. Delegate from user B 501 EGLD each, check it fails + // 7. Stake node, check the topup is 0, check the node is staked, check the node is in action list + // 8. Delegate from user B 501 EGLD each, check it fails + // 9. Delegate from user B 500 EGLD each, check the topup is 500 + // 10. Delegate from user B 20 EGLD each, check it fails + t.Run("staking ph 4 step 2 is active", func(t *testing.T) { + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 + cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 + cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 4 + + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 4 + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + testChainSimulatorMaxDelegationCap(t, cs, 3) + }) + + // Test scenario done in staking v4 phase step 3 + // 1. Add a new validator private key in the multi key handler + // 2. Set the initial state for the owner and the 3 delegators + // 3. Create a new delegation contract with 1250 egld + // 4. Add node to the delegation contract + // 5. Delegate from user A 1250 EGLD each, check the topup is 2500 + // 6. Delegate from user B 501 EGLD each, check it fails + // 7. Stake node, check the topup is 0, check the node is staked, check the node is in action list + // 8. Delegate from user B 501 EGLD each, check it fails + // 9. Delegate from user B 500 EGLD each, check the topup is 500 + // 10. Delegate from user B 20 EGLD each, check it fails + t.Run("staking ph 4 step 3 is active", func(t *testing.T) { + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 + cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 + cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 4 + + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 4 + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + testChainSimulatorMaxDelegationCap(t, cs, 4) + }) + +} + +func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, targetEpoch int32) { + err := cs.GenerateBlocksUntilEpochIsReached(targetEpoch) + require.Nil(t, err) + metachainNode := cs.GetNodeHandler(core.MetachainShardId) + + // Create new validator owner and delegators with initial funds + validatorOwnerBytes := generateWalletAddressBytes() + validatorOwner, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(validatorOwnerBytes) + delegatorABytes := generateWalletAddressBytes() + delegatorA, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(delegatorABytes) + delegatorBBytes := generateWalletAddressBytes() + delegatorB, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(delegatorBBytes) + delegatorCBytes := generateWalletAddressBytes() + delegatorC, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(delegatorCBytes) + initialFunds := big.NewInt(0).Mul(oneEGLD, big.NewInt(10000)) // 10000 EGLD for each + addresses := []*dtos.AddressState{ + {Address: validatorOwner, Balance: initialFunds.String()}, + {Address: delegatorA, Balance: initialFunds.String()}, + {Address: delegatorB, Balance: initialFunds.String()}, + {Address: delegatorC, Balance: initialFunds.String()}, + } + err = cs.SetStateMultiple(addresses) + require.Nil(t, err) + + // Step 3: Create a new delegation contract + stakeValue := big.NewInt(0).Set(minimumCreateDelegationStakeValue) // 1250 EGLD + maxDelegationCap := big.NewInt(0).Mul(oneEGLD, big.NewInt(3000)) // 3000 EGLD cap + serviceFee := big.NewInt(100) // 100 as service fee + txCreateDelegationContract := generateTransaction(validatorOwnerBytes, 0, vm.DelegationManagerSCAddress, stakeValue, + fmt.Sprintf("createNewDelegationContract@%s@%s", hex.EncodeToString(maxDelegationCap.Bytes()), hex.EncodeToString(serviceFee.Bytes())), + gasLimitForDelegationContractCreationOperation) + createDelegationContractTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txCreateDelegationContract, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, createDelegationContractTx) + + output, err := executeQuery(cs, core.MetachainShardId, vm.DelegationManagerSCAddress, "getAllContractAddresses", nil) + require.Nil(t, err) + delegationContractAddress := output.ReturnData[0] + + // Step 2: Add validator nodes to the delegation contract + // This step requires generating BLS keys for validators, signing messages, and sending the "addNodes" transaction. + // Add checks to verify nodes are added successfully. + validatorSecretKeysBytes, blsKeys, err := chainSimulator.GenerateBlsPrivateKeys(1) + require.Nil(t, err) + err = cs.AddValidatorKeys(validatorSecretKeysBytes) + require.Nil(t, err) + + signatures := getSignatures(delegationContractAddress, validatorSecretKeysBytes) + txAddNodes := generateTransaction(validatorOwnerBytes, 1, delegationContractAddress, zeroValue, addNodesTxData(blsKeys, signatures), gasLimitForAddNodesOperation) + addNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txAddNodes, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, addNodesTx) + + expectedTopUp := big.NewInt(0).Set(stakeValue) + expectedTotalStaked := big.NewInt(0).Set(stakeValue) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) + require.Nil(t, err) + require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddress)) + + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{validatorOwnerBytes}) + require.Nil(t, err) + require.Equal(t, stakeValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + + // Step 3: Perform delegation operations + tx1delegatorA := generateTransaction(delegatorABytes, 0, delegationContractAddress, stakeValue, "delegate", gasLimitForDelegate) + delegatorATx1, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx1delegatorA, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, delegatorATx1) + + expectedTopUp = expectedTopUp.Add(expectedTopUp, stakeValue) + expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, stakeValue) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) + require.Nil(t, err) + require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddress)) + + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorABytes}) + require.Nil(t, err) + require.Equal(t, stakeValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + + delegateValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(501)) // 501 EGLD + tx1delegatorB := generateTransaction(delegatorBBytes, 0, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) + delegatorBTx1, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx1delegatorB, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, delegatorBTx1) + assert.Equal(t, delegatorBTx1.SmartContractResults[0].ReturnMessage, "total delegation cap reached") + + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) + require.Nil(t, err) + require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddress)) + + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorBBytes}) + require.Nil(t, err) + require.Zero(t, len(output.ReturnData)) + require.Equal(t, "view function works only for existing delegators", output.ReturnMessage) + + // Step 4: Perform stakeNodes + + txStakeNodes := generateTransaction(validatorOwnerBytes, 2, delegationContractAddress, zeroValue, fmt.Sprintf("stakeNodes@%s", blsKeys[0]), gasLimitForDelegate) + stakeNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStakeNodes, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, stakeNodesTx) + + expectedTopUp = expectedTopUp.Sub(expectedTopUp, stakeValue) + expectedTopUp = expectedTopUp.Sub(expectedTopUp, stakeValue) + require.Zero(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, delegationContractAddress))) + + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getAllNodeStates", nil) + require.Nil(t, err) + stakedKeys, notStakedKeys, unStakedKeys := getNodesFromContract(output.ReturnData) + require.Equal(t, 1, len(stakedKeys)) + require.Equal(t, blsKeys[0], hex.EncodeToString(stakedKeys[0])) + require.Equal(t, 0, len(notStakedKeys)) + require.Equal(t, 0, len(unStakedKeys)) + + err = cs.GenerateBlocks(50) // allow the metachain to finalize the block that contains the staking of the node + require.Nil(t, err) + + testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationContractAddress, blsKeys[0], expectedTopUp, 1) + + tx2delegatorB := generateTransaction(delegatorBBytes, 1, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) + delegatorBTx2, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx2delegatorB, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, delegatorBTx2) + assert.Equal(t, delegatorBTx2.SmartContractResults[0].ReturnMessage, "total delegation cap reached") + + // check the tx failed + + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) + require.Nil(t, err) + require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Zero(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, delegationContractAddress))) + + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorBBytes}) + require.Nil(t, err) + require.Zero(t, len(output.ReturnData)) + require.Equal(t, "view function works only for existing delegators", output.ReturnMessage) + + delegateValue = delegateValue.Sub(delegateValue, oneEGLD) // 500 EGLD + tx3delegatorB := generateTransaction(delegatorBBytes, 2, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) + delegatorBTx3, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx3delegatorB, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, delegatorBTx3) + + expectedTopUp = expectedTopUp.Add(expectedTopUp, delegateValue) + expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, delegateValue) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) + require.Nil(t, err) + require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddress)) + + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorBBytes}) + require.Nil(t, err) + require.Equal(t, delegateValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + + delegateValue = big.NewInt(0).Mul(oneEGLD, big.NewInt(20)) // 20 EGLD + txDelegate3 := generateTransaction(delegatorCBytes, 0, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) + delegatorCTx1, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate3, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, delegatorCTx1) + assert.Equal(t, delegatorBTx2.SmartContractResults[0].ReturnMessage, "total delegation cap reached") + + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) + require.Nil(t, err) + require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddress)) + + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorCBytes}) + require.Nil(t, err) + require.Zero(t, len(output.ReturnData)) + require.Equal(t, "view function works only for existing delegators", output.ReturnMessage) +} + func generateWalletAddressBytes() []byte { buff := make([]byte, walletAddressBytesLen) _, _ = rand.Read(buff) From febf7443b33efc56e2bfcae9929d720b2b826453 Mon Sep 17 00:00:00 2001 From: dragosrebegea Date: Tue, 13 Feb 2024 12:23:36 +0200 Subject: [PATCH 060/503] MX-15168: fix tests --- .../chainSimulator/staking/delegation_test.go | 47 ++++++++++++------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/integrationTests/chainSimulator/staking/delegation_test.go b/integrationTests/chainSimulator/staking/delegation_test.go index 625d1759426..70ac03a195c 100644 --- a/integrationTests/chainSimulator/staking/delegation_test.go +++ b/integrationTests/chainSimulator/staking/delegation_test.go @@ -260,7 +260,7 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi err = cs.GenerateBlocks(2) // allow the metachain to finalize the block that contains the staking of the node assert.Nil(t, err) - testBLSKeyIsInQueueOrAuction(t, metachainNode, validatorOwner.Bytes, blsKeys[0], addedStakedValue, 1) + testBLSKeyIsInQueueOrAuction(t, metachainNode, validatorOwner.Bytes, blsKeys[0], addedStakedValue) log.Info("Step 4. Execute the MakeNewContractFromValidatorData transaction and test that the key is on queue / auction list and the correct topup") txDataField = fmt.Sprintf("makeNewContractFromValidatorData@%s@%s", maxCap, serviceFee) @@ -276,7 +276,7 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi err = metachainNode.GetProcessComponents().ValidatorsProvider().ForceUpdate() require.Nil(t, err) - testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], addedStakedValue, 1) + testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], addedStakedValue) log.Info("Step 5. Execute 2 delegation operations of 100 EGLD each, check the topup is 700") delegateValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(100)) @@ -291,7 +291,7 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi require.NotNil(t, delegate2Tx) expectedTopUp := big.NewInt(0).Mul(oneEGLD, big.NewInt(700)) - testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], expectedTopUp, 1) + testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], expectedTopUp) log.Info("6. Execute 2 unDelegate operations of 100 EGLD each, check the topup is back to 500") unDelegateValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(100)) @@ -308,10 +308,10 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi require.NotNil(t, unDelegate2Tx) expectedTopUp = big.NewInt(0).Mul(oneEGLD, big.NewInt(500)) - testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], expectedTopUp, 1) + testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], expectedTopUp) } -func testBLSKeyIsInQueueOrAuction(t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, address []byte, blsKey string, expectedTopUp *big.Int, actionListSize int) { +func testBLSKeyIsInQueueOrAuction(t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, address []byte, blsKey string, expectedTopUp *big.Int) { decodedBLSKey, _ := hex.DecodeString(blsKey) err := metachainNode.GetProcessComponents().ValidatorsProvider().ForceUpdate() require.Nil(t, err) @@ -321,7 +321,7 @@ func testBLSKeyIsInQueueOrAuction(t *testing.T, metachainNode chainSimulatorProc activationEpoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step1Flag) if activationEpoch <= metachainNode.GetCoreComponents().EnableEpochsHandler().GetCurrentEpoch() { - testBLSKeyIsInAuction(t, metachainNode, decodedBLSKey, blsKey, expectedTopUp, actionListSize, statistics) + testBLSKeyIsInAuction(t, metachainNode, address, decodedBLSKey, blsKey, expectedTopUp, statistics) return } @@ -334,10 +334,10 @@ func testBLSKeyIsInQueueOrAuction(t *testing.T, metachainNode chainSimulatorProc func testBLSKeyIsInAuction( t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, + address []byte, blsKeyBytes []byte, blsKey string, topUpInAuctionList *big.Int, - actionListSize int, validatorStatistics map[string]*validator.ValidatorStatistics, ) { require.Equal(t, stakedStatus, getBLSKeyStatus(t, metachainNode, blsKeyBytes)) @@ -347,17 +347,30 @@ func testBLSKeyIsInAuction( auctionList, err := metachainNode.GetProcessComponents().ValidatorsProvider().GetAuctionList() require.Nil(t, err) + expectedNodesInWaitingList := 1 + expectedActionListOwnersSize := 1 currentEpoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetCurrentEpoch() - if metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step2Flag) <= currentEpoch { + if currentEpoch == metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step2Flag) { // starting from phase 2, we have the shuffled out nodes from the previous epoch in the action list - actionListSize += 1 + expectedActionListOwnersSize += 1 + expectedNodesInWaitingList += 8 + } + if currentEpoch == metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step3Flag) { + // starting from phase 2, we have the shuffled out nodes from the previous epoch in the action list + expectedActionListOwnersSize += 1 + expectedNodesInWaitingList += 4 } - require.Equal(t, actionListSize, len(auctionList)) - if actionListSize != 0 { - require.Equal(t, 1, len(auctionList[0].Nodes)) - require.Equal(t, topUpInAuctionList.String(), auctionList[0].TopUpPerNode) + require.Equal(t, expectedActionListOwnersSize, len(auctionList)) + nodesInWaitingList := 0 + addressBech32 := metachainNode.GetCoreComponents().AddressPubKeyConverter().SilentEncode(address, log) + for i := 0; i < len(auctionList); i++ { + nodesInWaitingList += len(auctionList[i].Nodes) + if auctionList[i].Owner == addressBech32 { + require.Equal(t, topUpInAuctionList.String(), auctionList[i].TopUpPerNode) + } } + require.Equal(t, expectedNodesInWaitingList, nodesInWaitingList) // in staking ph 4 we should find the key in the validators statics validatorInfo, found := validatorStatistics[blsKey] @@ -682,7 +695,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat err = cs.GenerateBlocks(2) // allow the metachain to finalize the block that contains the staking of the node require.Nil(t, err) - testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationContractAddressBytes, blsKeys[0], expectedTopUp, 1) + testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationContractAddressBytes, blsKeys[0], expectedTopUp) // Step 5: Perform unDelegate from 1 user // The nodes should remain in the staked state @@ -713,7 +726,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Equal(t, 0, len(unStakedKeys)) // Step 6: Perform unDelegate from last user - // The nodes should remain in the unStaked state + // The nodes should change to unStaked state // The total active stake should be reduced by the amount undelegated txUndelegate2 := generateTransaction(delegator2Bytes, 1, delegationContractAddressBytes, zeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(stakeValue.Bytes())), gasLimitForUndelegateOperation) @@ -1045,10 +1058,10 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati require.Equal(t, 0, len(notStakedKeys)) require.Equal(t, 0, len(unStakedKeys)) - err = cs.GenerateBlocks(50) // allow the metachain to finalize the block that contains the staking of the node + err = cs.GenerateBlocks(2) // allow the metachain to finalize the block that contains the staking of the node require.Nil(t, err) - testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationContractAddress, blsKeys[0], expectedTopUp, 1) + testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationContractAddress, blsKeys[0], expectedTopUp) tx2delegatorB := generateTransaction(delegatorBBytes, 1, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) delegatorBTx2, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx2delegatorB, maxNumOfBlockToGenerateWhenExecutingTx) From 31f50f4c06316f5f9819487106f07d3e2aec06f0 Mon Sep 17 00:00:00 2001 From: dragosrebegea Date: Tue, 13 Feb 2024 17:06:22 +0200 Subject: [PATCH 061/503] MX-15168: fixes after review --- .../chainSimulator/staking/delegation_test.go | 250 ++++++++---------- 1 file changed, 113 insertions(+), 137 deletions(-) diff --git a/integrationTests/chainSimulator/staking/delegation_test.go b/integrationTests/chainSimulator/staking/delegation_test.go index f9b800dce3d..f90d1f987e2 100644 --- a/integrationTests/chainSimulator/staking/delegation_test.go +++ b/integrationTests/chainSimulator/staking/delegation_test.go @@ -1,7 +1,6 @@ package staking import ( - "crypto/rand" "encoding/hex" "fmt" "math/big" @@ -22,7 +21,6 @@ import ( "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" - "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/vm" @@ -46,7 +44,6 @@ const auctionStatus = "auction" const okReturnCode = "ok" const maxCap = "00" // no cap const serviceFee = "0ea1" // 37.45% -const walletAddressBytesLen = 32 var zeroValue = big.NewInt(0) var oneEGLD = big.NewInt(1000000000000000000) @@ -317,7 +314,7 @@ func testBLSKeyIsInQueueOrAuction(t *testing.T, metachainNode chainSimulatorProc require.Nil(t, err) statistics, err := metachainNode.GetFacadeHandler().ValidatorStatisticsApi() require.Nil(t, err) - require.Zero(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, address))) + require.True(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, address)) == 0) activationEpoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step1Flag) if activationEpoch <= metachainNode.GetCoreComponents().EnableEpochsHandler().GetCurrentEpoch() { @@ -347,30 +344,33 @@ func testBLSKeyIsInAuction( auctionList, err := metachainNode.GetProcessComponents().ValidatorsProvider().GetAuctionList() require.Nil(t, err) - expectedNodesInWaitingList := 1 - expectedActionListOwnersSize := 1 + expectedNodesInAuctionList := 1 + expectedAuctionListOwnersSize := 1 currentEpoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetCurrentEpoch() if currentEpoch == metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step2Flag) { // starting from phase 2, we have the shuffled out nodes from the previous epoch in the action list - expectedActionListOwnersSize += 1 - expectedNodesInWaitingList += 8 + expectedAuctionListOwnersSize += 1 + expectedNodesInAuctionList += 8 } - if currentEpoch == metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step3Flag) { + if currentEpoch >= metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step3Flag) { // starting from phase 2, we have the shuffled out nodes from the previous epoch in the action list - expectedActionListOwnersSize += 1 - expectedNodesInWaitingList += 4 + expectedAuctionListOwnersSize += 1 + expectedNodesInAuctionList += 4 } - require.Equal(t, expectedActionListOwnersSize, len(auctionList)) - nodesInWaitingList := 0 + require.Equal(t, expectedAuctionListOwnersSize, len(auctionList)) + nodesInAuctionList := 0 addressBech32 := metachainNode.GetCoreComponents().AddressPubKeyConverter().SilentEncode(address, log) + ownerFound := false for i := 0; i < len(auctionList); i++ { - nodesInWaitingList += len(auctionList[i].Nodes) + nodesInAuctionList += len(auctionList[i].Nodes) if auctionList[i].Owner == addressBech32 { + ownerFound = true require.Equal(t, topUpInAuctionList.String(), auctionList[i].TopUpPerNode) } } - require.Equal(t, expectedNodesInWaitingList, nodesInWaitingList) + require.True(t, ownerFound) + require.Equal(t, expectedNodesInAuctionList, nodesInAuctionList) // in staking ph 4 we should find the key in the validators statics validatorInfo, found := validatorStatistics[blsKey] @@ -563,28 +563,19 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Nil(t, err) metachainNode := cs.GetNodeHandler(core.MetachainShardId) - // Create new validator owner and delegators with initial funds - validatorOwnerBytes := generateWalletAddressBytes() - validatorOwner, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(validatorOwnerBytes) - delegator1Bytes := generateWalletAddressBytes() - delegator1, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(delegator1Bytes) - delegator2Bytes := generateWalletAddressBytes() - delegator2, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(delegator2Bytes) initialFunds := big.NewInt(0).Mul(oneEGLD, big.NewInt(10000)) // 10000 EGLD for each - addresses := []*dtos.AddressState{ - {Address: validatorOwner, Balance: initialFunds.String()}, - {Address: delegator1, Balance: initialFunds.String()}, - {Address: delegator2, Balance: initialFunds.String()}, - } - err = cs.SetStateMultiple(addresses) + validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, initialFunds) + require.Nil(t, err) + + delegator1, err := cs.GenerateAndMintWalletAddress(core.AllShardId, initialFunds) + require.Nil(t, err) + + delegator2, err := cs.GenerateAndMintWalletAddress(core.AllShardId, initialFunds) require.Nil(t, err) - stakeValue := big.NewInt(0).Set(minimumCreateDelegationStakeValue) // 1250 EGLD - // Step 3: Create a new delegation contract maxDelegationCap := big.NewInt(0).Mul(oneEGLD, big.NewInt(51000)) // 51000 EGLD cap - serviceFee := big.NewInt(100) // 100 as service fee - txCreateDelegationContract := generateTransaction(validatorOwnerBytes, 0, vm.DelegationManagerSCAddress, stakeValue, - fmt.Sprintf("createNewDelegationContract@%s@%s", hex.EncodeToString(maxDelegationCap.Bytes()), hex.EncodeToString(serviceFee.Bytes())), + txCreateDelegationContract := generateTransaction(validatorOwner.Bytes, 0, vm.DelegationManagerSCAddress, minimumCreateDelegationStakeValue, + fmt.Sprintf("createNewDelegationContract@%s@%s", hex.EncodeToString(maxDelegationCap.Bytes()), serviceFee), gasLimitForDelegationContractCreationOperation) createDelegationContractTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txCreateDelegationContract, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -615,7 +606,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Nil(t, err) signatures := getSignatures(delegationContractAddressBytes, validatorSecretKeysBytes) - txAddNodes := generateTransaction(validatorOwnerBytes, 1, delegationContractAddressBytes, zeroValue, addNodesTxData(blsKeys, signatures), gasLimitForAddNodesOperation) + txAddNodes := generateTransaction(validatorOwner.Bytes, 1, delegationContractAddressBytes, zeroValue, addNodesTxData(blsKeys, signatures), gasLimitForAddNodesOperation) addNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txAddNodes, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, addNodesTx) @@ -628,59 +619,58 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Equal(t, blsKeys[0], hex.EncodeToString(notStakedKeys[0])) require.Equal(t, 0, len(unStakedKeys)) - expectedTopUp := big.NewInt(0).Set(stakeValue) - expectedTotalStaked := big.NewInt(0).Set(stakeValue) + expectedTopUp := big.NewInt(0).Set(minimumCreateDelegationStakeValue) + expectedTotalStaked := big.NewInt(0).Set(minimumCreateDelegationStakeValue) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{validatorOwnerBytes}) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{validatorOwner.Bytes}) require.Nil(t, err) - require.Equal(t, stakeValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, minimumCreateDelegationStakeValue, big.NewInt(0).SetBytes(output.ReturnData[0])) // Step 3: Perform delegation operations - txDelegate1 := generateTransaction(delegator1Bytes, 0, delegationContractAddressBytes, stakeValue, "delegate", gasLimitForDelegate) + txDelegate1 := generateTransaction(delegator1.Bytes, 0, delegationContractAddressBytes, minimumCreateDelegationStakeValue, "delegate", gasLimitForDelegate) delegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate1, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegate1Tx) - expectedTopUp = expectedTopUp.Add(expectedTopUp, stakeValue) - expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, stakeValue) + expectedTopUp = expectedTopUp.Add(expectedTopUp, minimumCreateDelegationStakeValue) + expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, minimumCreateDelegationStakeValue) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator1Bytes}) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator1.Bytes}) require.Nil(t, err) - require.Equal(t, stakeValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, minimumCreateDelegationStakeValue, big.NewInt(0).SetBytes(output.ReturnData[0])) - txDelegate2 := generateTransaction(delegator2Bytes, 0, delegationContractAddressBytes, stakeValue, "delegate", gasLimitForDelegate) + txDelegate2 := generateTransaction(delegator2.Bytes, 0, delegationContractAddressBytes, minimumCreateDelegationStakeValue, "delegate", gasLimitForDelegate) delegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate2, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegate2Tx) - expectedTopUp = expectedTopUp.Add(expectedTopUp, stakeValue) - expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, stakeValue) + expectedTopUp = expectedTopUp.Add(expectedTopUp, minimumCreateDelegationStakeValue) + expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, minimumCreateDelegationStakeValue) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator2Bytes}) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator2.Bytes}) require.Nil(t, err) - require.Equal(t, stakeValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, minimumCreateDelegationStakeValue, big.NewInt(0).SetBytes(output.ReturnData[0])) // Step 4: Perform stakeNodes - txStakeNodes := generateTransaction(validatorOwnerBytes, 2, delegationContractAddressBytes, zeroValue, fmt.Sprintf("stakeNodes@%s", blsKeys[0]), gasLimitForStakeOperation) + txStakeNodes := generateTransaction(validatorOwner.Bytes, 2, delegationContractAddressBytes, zeroValue, fmt.Sprintf("stakeNodes@%s", blsKeys[0]), gasLimitForStakeOperation) stakeNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStakeNodes, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeNodesTx) - expectedTopUp = expectedTopUp.Sub(expectedTopUp, stakeValue) - expectedTopUp = expectedTopUp.Sub(expectedTopUp, stakeValue) + expectedTopUp = big.NewInt(0).Set(minimumCreateDelegationStakeValue) require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getAllNodeStates", nil) @@ -701,19 +691,19 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat // The nodes should remain in the staked state // The total active stake should be reduced by the amount undelegated - txUndelegate1 := generateTransaction(delegator1Bytes, 1, delegationContractAddressBytes, zeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(stakeValue.Bytes())), gasLimitForUndelegateOperation) + txUndelegate1 := generateTransaction(delegator1.Bytes, 1, delegationContractAddressBytes, zeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(minimumCreateDelegationStakeValue.Bytes())), gasLimitForUndelegateOperation) undelegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUndelegate1, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, undelegate1Tx) - expectedTopUp = expectedTopUp.Sub(expectedTopUp, stakeValue) - expectedTotalStaked = expectedTotalStaked.Sub(expectedTotalStaked, stakeValue) + expectedTopUp = expectedTopUp.Sub(expectedTopUp, minimumCreateDelegationStakeValue) + expectedTotalStaked = expectedTotalStaked.Sub(expectedTotalStaked, minimumCreateDelegationStakeValue) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) - require.Zero(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes))) + require.True(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) == 0) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator1Bytes}) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator1.Bytes}) require.Nil(t, err) require.Equal(t, zeroValue, big.NewInt(0).SetBytes(output.ReturnData[0])) @@ -729,7 +719,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat // The nodes should change to unStaked state // The total active stake should be reduced by the amount undelegated - txUndelegate2 := generateTransaction(delegator2Bytes, 1, delegationContractAddressBytes, zeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(stakeValue.Bytes())), gasLimitForUndelegateOperation) + txUndelegate2 := generateTransaction(delegator2.Bytes, 1, delegationContractAddressBytes, zeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(minimumCreateDelegationStakeValue.Bytes())), gasLimitForUndelegateOperation) undelegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUndelegate2, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, undelegate2Tx) @@ -739,7 +729,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Equal(t, "1250000000000000000000", big.NewInt(0).SetBytes(output.ReturnData[0]).String()) require.Equal(t, zeroValue, getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator2Bytes}) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator2.Bytes}) require.Nil(t, err) require.Equal(t, "0", big.NewInt(0).SetBytes(output.ReturnData[0]).String()) @@ -778,14 +768,14 @@ func TestChainSimulator_MaxDelegationCap(t *testing.T) { // Test scenario done in staking 3.5 phase (staking v4 is not active) // 1. Add a new validator private key in the multi key handler // 2. Set the initial state for the owner and the 3 delegators - // 3. Create a new delegation contract with 1250 egld + // 3. Create a new delegation contract with 1250 egld and maximum delegation cap of 3000 EGLD // 4. Add node to the delegation contract - // 5. Delegate from user A 1250 EGLD each, check the topup is 2500 - // 6. Delegate from user B 501 EGLD each, check it fails + // 5. Delegate from user A 1250 EGLD, check the topup is 2500 + // 6. Delegate from user B 501 EGLD, check it fails // 7. Stake node, check the topup is 0, check the node is staked - // 8. Delegate from user B 501 EGLD each, check it fails - // 9. Delegate from user B 500 EGLD each, check the topup is 500 - // 10. Delegate from user B 20 EGLD each, check it fails + // 8. Delegate from user B 501 EGLD, check it fails + // 9. Delegate from user B 500 EGLD, check the topup is 500 + // 10. Delegate from user B 20 EGLD, check it fails t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ BypassTxSignatureCheck: false, @@ -819,14 +809,14 @@ func TestChainSimulator_MaxDelegationCap(t *testing.T) { // Test scenario done in staking v4 phase step 1 // 1. Add a new validator private key in the multi key handler // 2. Set the initial state for the owner and the 3 delegators - // 3. Create a new delegation contract with 1250 egld + // 3. Create a new delegation contract with 1250 egld and maximum delegation cap of 3000 EGLD // 4. Add node to the delegation contract - // 5. Delegate from user A 1250 EGLD each, check the topup is 2500 - // 6. Delegate from user B 501 EGLD each, check it fails + // 5. Delegate from user A 1250 EGLD, check the topup is 2500 + // 6. Delegate from user B 501 EGLD, check it fails // 7. Stake node, check the topup is 0, check the node is staked, check the node is in action list - // 8. Delegate from user B 501 EGLD each, check it fails - // 9. Delegate from user B 500 EGLD each, check the topup is 500 - // 10. Delegate from user B 20 EGLD each, check it fails + // 8. Delegate from user B 501 EGLD, check it fails + // 9. Delegate from user B 500 EGLD, check the topup is 500 + // 10. Delegate from user B 20 EGLD, check it fails t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ BypassTxSignatureCheck: false, @@ -860,14 +850,14 @@ func TestChainSimulator_MaxDelegationCap(t *testing.T) { // Test scenario done in staking v4 phase step 2 // 1. Add a new validator private key in the multi key handler // 2. Set the initial state for the owner and the 3 delegators - // 3. Create a new delegation contract with 1250 egld + // 3. Create a new delegation contract with 1250 egld and maximum delegation cap of 3000 EGLD // 4. Add node to the delegation contract - // 5. Delegate from user A 1250 EGLD each, check the topup is 2500 - // 6. Delegate from user B 501 EGLD each, check it fails + // 5. Delegate from user A 1250 EGLD, check the topup is 2500 + // 6. Delegate from user B 501 EGLD, check it fails // 7. Stake node, check the topup is 0, check the node is staked, check the node is in action list - // 8. Delegate from user B 501 EGLD each, check it fails - // 9. Delegate from user B 500 EGLD each, check the topup is 500 - // 10. Delegate from user B 20 EGLD each, check it fails + // 8. Delegate from user B 501 EGLD, check it fails + // 9. Delegate from user B 500 EGLD, check the topup is 500 + // 10. Delegate from user B 20 EGLD, check it fails t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ BypassTxSignatureCheck: false, @@ -903,12 +893,12 @@ func TestChainSimulator_MaxDelegationCap(t *testing.T) { // 2. Set the initial state for the owner and the 3 delegators // 3. Create a new delegation contract with 1250 egld // 4. Add node to the delegation contract - // 5. Delegate from user A 1250 EGLD each, check the topup is 2500 - // 6. Delegate from user B 501 EGLD each, check it fails + // 5. Delegate from user A 1250 EGLD, check the topup is 2500 + // 6. Delegate from user B 501 EGLD, check it fails // 7. Stake node, check the topup is 0, check the node is staked, check the node is in action list - // 8. Delegate from user B 501 EGLD each, check it fails - // 9. Delegate from user B 500 EGLD each, check the topup is 500 - // 10. Delegate from user B 20 EGLD each, check it fails + // 8. Delegate from user B 501 EGLD, check it fails + // 9. Delegate from user B 500 EGLD, check the topup is 500 + // 10. Delegate from user B 20 EGLD, check it fails t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ BypassTxSignatureCheck: false, @@ -946,31 +936,24 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati require.Nil(t, err) metachainNode := cs.GetNodeHandler(core.MetachainShardId) - // Create new validator owner and delegators with initial funds - validatorOwnerBytes := generateWalletAddressBytes() - validatorOwner, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(validatorOwnerBytes) - delegatorABytes := generateWalletAddressBytes() - delegatorA, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(delegatorABytes) - delegatorBBytes := generateWalletAddressBytes() - delegatorB, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(delegatorBBytes) - delegatorCBytes := generateWalletAddressBytes() - delegatorC, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(delegatorCBytes) initialFunds := big.NewInt(0).Mul(oneEGLD, big.NewInt(10000)) // 10000 EGLD for each - addresses := []*dtos.AddressState{ - {Address: validatorOwner, Balance: initialFunds.String()}, - {Address: delegatorA, Balance: initialFunds.String()}, - {Address: delegatorB, Balance: initialFunds.String()}, - {Address: delegatorC, Balance: initialFunds.String()}, - } - err = cs.SetStateMultiple(addresses) + validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, initialFunds) + require.Nil(t, err) + + delegatorA, err := cs.GenerateAndMintWalletAddress(core.AllShardId, initialFunds) + require.Nil(t, err) + + delegatorB, err := cs.GenerateAndMintWalletAddress(core.AllShardId, initialFunds) + require.Nil(t, err) + + delegatorC, err := cs.GenerateAndMintWalletAddress(core.AllShardId, initialFunds) require.Nil(t, err) // Step 3: Create a new delegation contract - stakeValue := big.NewInt(0).Set(minimumCreateDelegationStakeValue) // 1250 EGLD - maxDelegationCap := big.NewInt(0).Mul(oneEGLD, big.NewInt(3000)) // 3000 EGLD cap - serviceFee := big.NewInt(100) // 100 as service fee - txCreateDelegationContract := generateTransaction(validatorOwnerBytes, 0, vm.DelegationManagerSCAddress, stakeValue, - fmt.Sprintf("createNewDelegationContract@%s@%s", hex.EncodeToString(maxDelegationCap.Bytes()), hex.EncodeToString(serviceFee.Bytes())), + + maxDelegationCap := big.NewInt(0).Mul(oneEGLD, big.NewInt(3000)) // 3000 EGLD cap + txCreateDelegationContract := generateTransaction(validatorOwner.Bytes, 0, vm.DelegationManagerSCAddress, minimumCreateDelegationStakeValue, + fmt.Sprintf("createNewDelegationContract@%s@%s", hex.EncodeToString(maxDelegationCap.Bytes()), serviceFee), gasLimitForDelegationContractCreationOperation) createDelegationContractTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txCreateDelegationContract, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -989,66 +972,66 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati require.Nil(t, err) signatures := getSignatures(delegationContractAddress, validatorSecretKeysBytes) - txAddNodes := generateTransaction(validatorOwnerBytes, 1, delegationContractAddress, zeroValue, addNodesTxData(blsKeys, signatures), gasLimitForAddNodesOperation) + txAddNodes := generateTransaction(validatorOwner.Bytes, 1, delegationContractAddress, zeroValue, addNodesTxData(blsKeys, signatures), gasLimitForAddNodesOperation) addNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txAddNodes, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, addNodesTx) - expectedTopUp := big.NewInt(0).Set(stakeValue) - expectedTotalStaked := big.NewInt(0).Set(stakeValue) + expectedTopUp := big.NewInt(0).Set(minimumCreateDelegationStakeValue) + expectedTotalStaked := big.NewInt(0).Set(minimumCreateDelegationStakeValue) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddress)) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{validatorOwnerBytes}) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{validatorOwner.Bytes}) require.Nil(t, err) - require.Equal(t, stakeValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, minimumCreateDelegationStakeValue, big.NewInt(0).SetBytes(output.ReturnData[0])) // Step 3: Perform delegation operations - tx1delegatorA := generateTransaction(delegatorABytes, 0, delegationContractAddress, stakeValue, "delegate", gasLimitForDelegate) + tx1delegatorA := generateTransaction(delegatorA.Bytes, 0, delegationContractAddress, minimumCreateDelegationStakeValue, "delegate", gasLimitForDelegate) delegatorATx1, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx1delegatorA, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegatorATx1) - expectedTopUp = expectedTopUp.Add(expectedTopUp, stakeValue) - expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, stakeValue) + expectedTopUp = expectedTopUp.Add(expectedTopUp, minimumCreateDelegationStakeValue) + expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, minimumCreateDelegationStakeValue) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddress)) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorABytes}) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorA.Bytes}) require.Nil(t, err) - require.Equal(t, stakeValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, minimumCreateDelegationStakeValue, big.NewInt(0).SetBytes(output.ReturnData[0])) delegateValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(501)) // 501 EGLD - tx1delegatorB := generateTransaction(delegatorBBytes, 0, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) + tx1delegatorB := generateTransaction(delegatorB.Bytes, 0, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) delegatorBTx1, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx1delegatorB, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegatorBTx1) - assert.Equal(t, delegatorBTx1.SmartContractResults[0].ReturnMessage, "total delegation cap reached") + require.Equal(t, delegatorBTx1.SmartContractResults[0].ReturnMessage, "total delegation cap reached") output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddress)) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorBBytes}) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorB.Bytes}) require.Nil(t, err) require.Zero(t, len(output.ReturnData)) require.Equal(t, "view function works only for existing delegators", output.ReturnMessage) // Step 4: Perform stakeNodes - txStakeNodes := generateTransaction(validatorOwnerBytes, 2, delegationContractAddress, zeroValue, fmt.Sprintf("stakeNodes@%s", blsKeys[0]), gasLimitForDelegate) + txStakeNodes := generateTransaction(validatorOwner.Bytes, 2, delegationContractAddress, zeroValue, fmt.Sprintf("stakeNodes@%s", blsKeys[0]), gasLimitForDelegate) stakeNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStakeNodes, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeNodesTx) - expectedTopUp = expectedTopUp.Sub(expectedTopUp, stakeValue) - expectedTopUp = expectedTopUp.Sub(expectedTopUp, stakeValue) - require.Zero(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, delegationContractAddress))) + expectedTopUp = expectedTopUp.Sub(expectedTopUp, minimumCreateDelegationStakeValue) + expectedTopUp = expectedTopUp.Sub(expectedTopUp, minimumCreateDelegationStakeValue) + require.True(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, delegationContractAddress)) == 0) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getAllNodeStates", nil) require.Nil(t, err) @@ -1063,26 +1046,26 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationContractAddress, blsKeys[0], expectedTopUp) - tx2delegatorB := generateTransaction(delegatorBBytes, 1, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) + tx2delegatorB := generateTransaction(delegatorB.Bytes, 1, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) delegatorBTx2, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx2delegatorB, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegatorBTx2) - assert.Equal(t, delegatorBTx2.SmartContractResults[0].ReturnMessage, "total delegation cap reached") + require.Equal(t, delegatorBTx2.SmartContractResults[0].ReturnMessage, "total delegation cap reached") // check the tx failed output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) - require.Zero(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, delegationContractAddress))) + require.True(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, delegationContractAddress)) == 0) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorBBytes}) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorB.Bytes}) require.Nil(t, err) require.Zero(t, len(output.ReturnData)) require.Equal(t, "view function works only for existing delegators", output.ReturnMessage) - delegateValue = delegateValue.Sub(delegateValue, oneEGLD) // 500 EGLD - tx3delegatorB := generateTransaction(delegatorBBytes, 2, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) + delegateValue = big.NewInt(0).Mul(oneEGLD, big.NewInt(500)) // 500 EGLD + tx3delegatorB := generateTransaction(delegatorB.Bytes, 2, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) delegatorBTx3, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx3delegatorB, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegatorBTx3) @@ -1094,35 +1077,28 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddress)) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorBBytes}) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorB.Bytes}) require.Nil(t, err) require.Equal(t, delegateValue, big.NewInt(0).SetBytes(output.ReturnData[0])) delegateValue = big.NewInt(0).Mul(oneEGLD, big.NewInt(20)) // 20 EGLD - txDelegate3 := generateTransaction(delegatorCBytes, 0, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) - delegatorCTx1, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate3, maxNumOfBlockToGenerateWhenExecutingTx) + tx1DelegatorC := generateTransaction(delegatorC.Bytes, 0, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) + delegatorCTx1, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx1DelegatorC, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegatorCTx1) - assert.Equal(t, delegatorBTx2.SmartContractResults[0].ReturnMessage, "total delegation cap reached") + require.Equal(t, delegatorBTx2.SmartContractResults[0].ReturnMessage, "total delegation cap reached") output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddress)) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorCBytes}) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorC.Bytes}) require.Nil(t, err) require.Zero(t, len(output.ReturnData)) require.Equal(t, "view function works only for existing delegators", output.ReturnMessage) } -func generateWalletAddressBytes() []byte { - buff := make([]byte, walletAddressBytesLen) - _, _ = rand.Read(buff) - - return buff -} - func executeQuery(cs chainSimulatorIntegrationTests.ChainSimulator, shardID uint32, scAddress []byte, funcName string, args [][]byte) (*dataVm.VMOutputApi, error) { output, _, err := cs.GetNodeHandler(shardID).GetFacadeHandler().ExecuteSCQuery(&process.SCQuery{ ScAddress: scAddress, From 679a823615f60cc123830e91c9ab34cbeea137f1 Mon Sep 17 00:00:00 2001 From: dragosrebegea Date: Tue, 13 Feb 2024 18:05:23 +0200 Subject: [PATCH 062/503] MX-15168: fixes after review --- .../chainSimulator/staking/delegation_test.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/integrationTests/chainSimulator/staking/delegation_test.go b/integrationTests/chainSimulator/staking/delegation_test.go index f90d1f987e2..62854a79e15 100644 --- a/integrationTests/chainSimulator/staking/delegation_test.go +++ b/integrationTests/chainSimulator/staking/delegation_test.go @@ -314,7 +314,7 @@ func testBLSKeyIsInQueueOrAuction(t *testing.T, metachainNode chainSimulatorProc require.Nil(t, err) statistics, err := metachainNode.GetFacadeHandler().ValidatorStatisticsApi() require.Nil(t, err) - require.True(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, address)) == 0) + require.Equal(t, expectedTopUp.String(), getBLSTopUpValue(t, metachainNode, address).String()) activationEpoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step1Flag) if activationEpoch <= metachainNode.GetCoreComponents().EnableEpochsHandler().GetCurrentEpoch() { @@ -701,7 +701,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) - require.True(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) == 0) + require.Equal(t, expectedTopUp.String(), getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes).String()) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator1.Bytes}) require.Nil(t, err) @@ -1029,9 +1029,7 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati require.Nil(t, err) require.NotNil(t, stakeNodesTx) - expectedTopUp = expectedTopUp.Sub(expectedTopUp, minimumCreateDelegationStakeValue) - expectedTopUp = expectedTopUp.Sub(expectedTopUp, minimumCreateDelegationStakeValue) - require.True(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, delegationContractAddress)) == 0) + require.Equal(t, zeroValue.String(), getBLSTopUpValue(t, metachainNode, delegationContractAddress).String()) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getAllNodeStates", nil) require.Nil(t, err) @@ -1044,7 +1042,7 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati err = cs.GenerateBlocks(2) // allow the metachain to finalize the block that contains the staking of the node require.Nil(t, err) - testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationContractAddress, blsKeys[0], expectedTopUp) + testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationContractAddress, blsKeys[0], zeroValue) tx2delegatorB := generateTransaction(delegatorB.Bytes, 1, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) delegatorBTx2, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx2delegatorB, maxNumOfBlockToGenerateWhenExecutingTx) @@ -1057,7 +1055,7 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) - require.True(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, delegationContractAddress)) == 0) + require.Equal(t, zeroValue.String(), getBLSTopUpValue(t, metachainNode, delegationContractAddress).String()) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorB.Bytes}) require.Nil(t, err) @@ -1070,7 +1068,7 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati require.Nil(t, err) require.NotNil(t, delegatorBTx3) - expectedTopUp = expectedTopUp.Add(expectedTopUp, delegateValue) + expectedTopUp = big.NewInt(0).Set(delegateValue) expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, delegateValue) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) require.Nil(t, err) From c593c5b55c99c234834974ceee5ca0b846070926 Mon Sep 17 00:00:00 2001 From: Rebegea Dragos-Alexandru <42241923+dragos-rebegea@users.noreply.github.com> Date: Wed, 14 Feb 2024 15:51:55 +0200 Subject: [PATCH 063/503] Update integrationTests/chainSimulator/staking/delegation_test.go Co-authored-by: mariusmihaic <82832880+mariusmihaic@users.noreply.github.com> --- integrationTests/chainSimulator/staking/delegation_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrationTests/chainSimulator/staking/delegation_test.go b/integrationTests/chainSimulator/staking/delegation_test.go index 62854a79e15..45f6e841c8a 100644 --- a/integrationTests/chainSimulator/staking/delegation_test.go +++ b/integrationTests/chainSimulator/staking/delegation_test.go @@ -348,7 +348,7 @@ func testBLSKeyIsInAuction( expectedAuctionListOwnersSize := 1 currentEpoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetCurrentEpoch() if currentEpoch == metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step2Flag) { - // starting from phase 2, we have the shuffled out nodes from the previous epoch in the action list + // starting from step 2, we have the shuffled out nodes from the previous epoch in the action list expectedAuctionListOwnersSize += 1 expectedNodesInAuctionList += 8 } From f979dc1cacefee47dfa8709c1e59e563ddba91c2 Mon Sep 17 00:00:00 2001 From: Rebegea Dragos-Alexandru <42241923+dragos-rebegea@users.noreply.github.com> Date: Wed, 14 Feb 2024 15:52:03 +0200 Subject: [PATCH 064/503] Update integrationTests/chainSimulator/staking/delegation_test.go Co-authored-by: mariusmihaic <82832880+mariusmihaic@users.noreply.github.com> --- integrationTests/chainSimulator/staking/delegation_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrationTests/chainSimulator/staking/delegation_test.go b/integrationTests/chainSimulator/staking/delegation_test.go index 45f6e841c8a..e46cf5a08a2 100644 --- a/integrationTests/chainSimulator/staking/delegation_test.go +++ b/integrationTests/chainSimulator/staking/delegation_test.go @@ -353,7 +353,7 @@ func testBLSKeyIsInAuction( expectedNodesInAuctionList += 8 } if currentEpoch >= metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step3Flag) { - // starting from phase 2, we have the shuffled out nodes from the previous epoch in the action list + // starting from step 3, we have the shuffled out nodes from the previous epoch in the action list expectedAuctionListOwnersSize += 1 expectedNodesInAuctionList += 4 } From 45dd9dba37c8711411ceb52d179a4e943dfd4e1b Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 19 Feb 2024 18:41:57 +0200 Subject: [PATCH 065/503] added api check for recursive relayed v3 + fixed interceptor --- api/errors/errors.go | 3 + api/groups/transactionGroup.go | 36 +++++++++++ api/groups/transactionGroup_test.go | 62 +++++++++++++++++++ process/transaction/interceptedTransaction.go | 37 +++++++---- 4 files changed, 125 insertions(+), 13 deletions(-) diff --git a/api/errors/errors.go b/api/errors/errors.go index b01cec657ca..30cfb923bbd 100644 --- a/api/errors/errors.go +++ b/api/errors/errors.go @@ -174,3 +174,6 @@ var ErrGetWaitingManagedKeys = errors.New("error getting the waiting managed key // ErrGetWaitingEpochsLeftForPublicKey signals that an error occurred while getting the waiting epochs left for public key var ErrGetWaitingEpochsLeftForPublicKey = errors.New("error getting the waiting epochs left for public key") + +// ErrRecursiveRelayedTxIsNotAllowed signals that recursive relayed tx is not allowed +var ErrRecursiveRelayedTxIsNotAllowed = errors.New("recursive relayed tx is not allowed") diff --git a/api/groups/transactionGroup.go b/api/groups/transactionGroup.go index c33a730a21f..fdf6aca6caf 100644 --- a/api/groups/transactionGroup.go +++ b/api/groups/transactionGroup.go @@ -184,6 +184,18 @@ func (tg *transactionGroup) simulateTransaction(c *gin.Context) { var innerTx *transaction.Transaction if ftx.InnerTransaction != nil { + if ftx.InnerTransaction.InnerTransaction != nil { + c.JSON( + http.StatusBadRequest, + shared.GenericAPIResponse{ + Data: nil, + Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), errors.ErrRecursiveRelayedTxIsNotAllowed.Error()), + Code: shared.ReturnCodeRequestError, + }, + ) + return + } + innerTx, _, err = tg.createTransaction(ftx.InnerTransaction, nil) if err != nil { c.JSON( @@ -270,6 +282,18 @@ func (tg *transactionGroup) sendTransaction(c *gin.Context) { var innerTx *transaction.Transaction if ftx.InnerTransaction != nil { + if ftx.InnerTransaction.InnerTransaction != nil { + c.JSON( + http.StatusBadRequest, + shared.GenericAPIResponse{ + Data: nil, + Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), errors.ErrRecursiveRelayedTxIsNotAllowed.Error()), + Code: shared.ReturnCodeRequestError, + }, + ) + return + } + innerTx, _, err = tg.createTransaction(ftx.InnerTransaction, nil) if err != nil { c.JSON( @@ -492,6 +516,18 @@ func (tg *transactionGroup) computeTransactionGasLimit(c *gin.Context) { var innerTx *transaction.Transaction if ftx.InnerTransaction != nil { + if ftx.InnerTransaction.InnerTransaction != nil { + c.JSON( + http.StatusBadRequest, + shared.GenericAPIResponse{ + Data: nil, + Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), errors.ErrRecursiveRelayedTxIsNotAllowed.Error()), + Code: shared.ReturnCodeRequestError, + }, + ) + return + } + innerTx, _, err = tg.createTransaction(ftx.InnerTransaction, nil) if err != nil { c.JSON( diff --git a/api/groups/transactionGroup_test.go b/api/groups/transactionGroup_test.go index 1f8f6bffbd4..98a3089a7c4 100644 --- a/api/groups/transactionGroup_test.go +++ b/api/groups/transactionGroup_test.go @@ -312,6 +312,7 @@ func TestTransactionGroup_sendTransaction(t *testing.T) { expectedErr, ) }) + t.Run("recursive relayed v3 should error", testRecursiveRelayedV3("/transaction/send")) t.Run("should work", func(t *testing.T) { t.Parallel() @@ -520,6 +521,7 @@ func TestTransactionGroup_computeTransactionGasLimit(t *testing.T) { expectedErr, ) }) + t.Run("recursive relayed v3 should error", testRecursiveRelayedV3("/transaction/cost")) t.Run("should work", func(t *testing.T) { t.Parallel() @@ -640,6 +642,7 @@ func TestTransactionGroup_simulateTransaction(t *testing.T) { expectedErr, ) }) + t.Run("recursive relayed v3 should error", testRecursiveRelayedV3("/transaction/simulate")) t.Run("should work", func(t *testing.T) { t.Parallel() @@ -1127,3 +1130,62 @@ func getTransactionRoutesConfig() config.ApiRoutesConfig { }, } } + +func testRecursiveRelayedV3(url string) func(t *testing.T) { + return func(t *testing.T) { + t.Parallel() + + facade := &mock.FacadeStub{ + CreateTransactionHandler: func(txArgs *external.ArgsCreateTransaction) (*dataTx.Transaction, []byte, error) { + txHash, _ := hex.DecodeString(hexTxHash) + return nil, txHash, nil + }, + SendBulkTransactionsHandler: func(txs []*dataTx.Transaction) (u uint64, err error) { + return 1, nil + }, + ValidateTransactionHandler: func(tx *dataTx.Transaction) error { + return nil + }, + } + + userTx1 := fmt.Sprintf(`{"nonce": %d, "sender":"%s", "receiver":"%s", "value":"%s", "signature":"%s"}`, + nonce, + sender, + receiver, + value, + signature, + ) + userTx2 := fmt.Sprintf(`{"nonce": %d, "sender":"%s", "receiver":"%s", "value":"%s", "signature":"%s", "innerTransaction":%s}`, + nonce, + sender, + receiver, + value, + signature, + userTx1, + ) + tx := fmt.Sprintf(`{"nonce": %d, "sender":"%s", "receiver":"%s", "value":"%s", "signature":"%s", "innerTransaction":%s}`, + nonce, + sender, + receiver, + value, + signature, + userTx2, + ) + + transactionGroup, err := groups.NewTransactionGroup(facade) + require.NoError(t, err) + + ws := startWebServer(transactionGroup, "transaction", getTransactionRoutesConfig()) + + req, _ := http.NewRequest("POST", url, bytes.NewBuffer([]byte(tx))) + resp := httptest.NewRecorder() + ws.ServeHTTP(resp, req) + + txResp := shared.GenericAPIResponse{} + loadResponse(resp.Body, &txResp) + + assert.Equal(t, http.StatusBadRequest, resp.Code) + assert.True(t, strings.Contains(txResp.Error, apiErrors.ErrRecursiveRelayedTxIsNotAllowed.Error())) + assert.Empty(t, txResp.Data) + } +} diff --git a/process/transaction/interceptedTransaction.go b/process/transaction/interceptedTransaction.go index 3ce45229ff9..6bc2cc050ab 100644 --- a/process/transaction/interceptedTransaction.go +++ b/process/transaction/interceptedTransaction.go @@ -221,10 +221,30 @@ func (inTx *InterceptedTransaction) CheckValidity() error { return nil } -func isRelayedTx(funcName string, innerTx *transaction.Transaction) bool { +func (inTx *InterceptedTransaction) checkRecursiveRelayed(userTxData []byte, innerTx *transaction.Transaction) error { + if isRelayedV3(innerTx) { + return process.ErrRecursiveRelayedTxIsNotAllowed + } + + funcName, _, err := inTx.argsParser.ParseCallData(string(userTxData)) + if err != nil { + return nil + } + + if isRelayedTx(funcName) { + return process.ErrRecursiveRelayedTxIsNotAllowed + } + + return nil +} + +func isRelayedTx(funcName string) bool { return core.RelayedTransaction == funcName || - core.RelayedTransactionV2 == funcName || - innerTx != nil + core.RelayedTransactionV2 == funcName +} + +func isRelayedV3(innerTx *transaction.Transaction) bool { + return innerTx != nil } func (inTx *InterceptedTransaction) verifyIfRelayedTxV3(tx *transaction.Transaction) error { @@ -317,17 +337,8 @@ func (inTx *InterceptedTransaction) verifyUserTx(userTx *transaction.Transaction return fmt.Errorf("inner transaction: %w", err) } - funcName, _, err := inTx.argsParser.ParseCallData(string(userTx.Data)) - if err != nil { - return nil - } - // recursive relayed transactions are not allowed - if isRelayedTx(funcName, userTx.InnerTransaction) { - return process.ErrRecursiveRelayedTxIsNotAllowed - } - - return nil + return inTx.checkRecursiveRelayed(userTx.Data, userTx.InnerTransaction) } func (inTx *InterceptedTransaction) processFields(txBuff []byte) error { From 142392127993dbe8f6adad64f6d6d924424d0ab1 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 19 Feb 2024 18:46:49 +0200 Subject: [PATCH 066/503] updated tests to make sure the previous issue is avoided --- process/transaction/interceptedTransaction_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/process/transaction/interceptedTransaction_test.go b/process/transaction/interceptedTransaction_test.go index b9233580a20..8117952cab3 100644 --- a/process/transaction/interceptedTransaction_test.go +++ b/process/transaction/interceptedTransaction_test.go @@ -1705,7 +1705,7 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { innerTx2 := &dataTransaction.Transaction{ Nonce: 2, Value: big.NewInt(3), - Data: []byte("data inner tx 2"), + Data: []byte(""), GasLimit: 3, GasPrice: 4, RcvAddr: recvAddress, From 142781c887125d7cde917ebfd442f487f786f6fa Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 20 Feb 2024 17:39:33 +0200 Subject: [PATCH 067/503] moved the check for recursive relayed before sig check on inner tx --- process/transaction/interceptedTransaction.go | 10 +++++++--- process/transaction/interceptedTransaction_test.go | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/process/transaction/interceptedTransaction.go b/process/transaction/interceptedTransaction.go index 6bc2cc050ab..157d68cc7e3 100644 --- a/process/transaction/interceptedTransaction.go +++ b/process/transaction/interceptedTransaction.go @@ -327,7 +327,12 @@ func (inTx *InterceptedTransaction) verifyIfRelayedTx(tx *transaction.Transactio } func (inTx *InterceptedTransaction) verifyUserTx(userTx *transaction.Transaction) error { - err := inTx.verifySig(userTx) + // recursive relayed transactions are not allowed + err := inTx.checkRecursiveRelayed(userTx.Data, userTx.InnerTransaction) + if err != nil { + return fmt.Errorf("inner transaction: %w", err) + } + err = inTx.verifySig(userTx) if err != nil { return fmt.Errorf("inner transaction: %w", err) } @@ -337,8 +342,7 @@ func (inTx *InterceptedTransaction) verifyUserTx(userTx *transaction.Transaction return fmt.Errorf("inner transaction: %w", err) } - // recursive relayed transactions are not allowed - return inTx.checkRecursiveRelayed(userTx.Data, userTx.InnerTransaction) + return nil } func (inTx *InterceptedTransaction) processFields(txBuff []byte) error { diff --git a/process/transaction/interceptedTransaction_test.go b/process/transaction/interceptedTransaction_test.go index 8117952cab3..86b9a0c4b2b 100644 --- a/process/transaction/interceptedTransaction_test.go +++ b/process/transaction/interceptedTransaction_test.go @@ -1528,7 +1528,8 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTx(t *testing.T) { tx.Data = []byte(core.RelayedTransaction + "@" + hex.EncodeToString(userTxData)) txi, _ = createInterceptedTxFromPlainTxWithArgParser(tx) err = txi.CheckValidity() - assert.Equal(t, process.ErrRecursiveRelayedTxIsNotAllowed, err) + assert.True(t, strings.Contains(err.Error(), process.ErrRecursiveRelayedTxIsNotAllowed.Error())) + assert.Contains(t, err.Error(), "inner transaction") } func TestInterceptedTransaction_CheckValidityOfRelayedTxV2(t *testing.T) { @@ -1589,7 +1590,8 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV2(t *testing.T) { tx.Data = []byte(core.RelayedTransactionV2 + "@" + hex.EncodeToString(userTx.RcvAddr) + "@" + hex.EncodeToString(big.NewInt(0).SetUint64(userTx.Nonce).Bytes()) + "@" + hex.EncodeToString([]byte(core.RelayedTransaction)) + "@" + hex.EncodeToString(userTx.Signature)) txi, _ = createInterceptedTxFromPlainTxWithArgParser(tx) err = txi.CheckValidity() - assert.Equal(t, process.ErrRecursiveRelayedTxIsNotAllowed, err) + assert.True(t, strings.Contains(err.Error(), process.ErrRecursiveRelayedTxIsNotAllowed.Error())) + assert.Contains(t, err.Error(), "inner transaction") userTx.Signature = sigOk userTx.SndAddr = []byte("otherAddress") From 3e19e997bca789ae4b67ff6d44d9013425ad5584 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 22 Feb 2024 16:24:22 +0200 Subject: [PATCH 068/503] update to latest storage version --- go.mod | 2 +- go.sum | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index 7655e0f331e..21c90f5a30d 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/multiversx/mx-chain-es-indexer-go v1.4.18-0.20231228064619-e3b0caf29058 github.com/multiversx/mx-chain-logger-go v1.0.14-0.20231215125130-a3bed6e76040 github.com/multiversx/mx-chain-scenario-go v1.2.2-0.20231129113427-ad3056f45296 - github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240131142608-5c126467749c + github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240222125646-f6bcc32e44f5 github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20231228070003-ae14e1e0adfa github.com/multiversx/mx-chain-vm-go v1.5.23-0.20231228064104-964359cb8dd3 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.65-0.20231228071026-eed2cb19c216 diff --git a/go.sum b/go.sum index 64e35192dc1..dbb93cd21e7 100644 --- a/go.sum +++ b/go.sum @@ -128,7 +128,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= @@ -261,7 +260,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= @@ -269,7 +267,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= @@ -399,12 +396,8 @@ github.com/multiversx/mx-chain-logger-go v1.0.14-0.20231215125130-a3bed6e76040 h github.com/multiversx/mx-chain-logger-go v1.0.14-0.20231215125130-a3bed6e76040/go.mod h1:fH/fR/GEBsDjPkBoZDVJMoYo2HhlA7++DP6QfITJ1N8= github.com/multiversx/mx-chain-scenario-go v1.2.2-0.20231129113427-ad3056f45296 h1:jDGGEubkiTJfEFcbErUYCYM2Z6wKapgZyGaICScpynk= github.com/multiversx/mx-chain-scenario-go v1.2.2-0.20231129113427-ad3056f45296/go.mod h1:WocyahfHCC3oGILEVdRe7I4/+q/TLCORoTo1X4wGmF4= -github.com/multiversx/mx-chain-storage-go v1.0.15-0.20231213110622-e222ba96a9f4 h1:2RJ6T31pLN75l4xfhTicGZ+gVOPMxSGPip+O1XYVYac= -github.com/multiversx/mx-chain-storage-go v1.0.15-0.20231213110622-e222ba96a9f4/go.mod h1:ioCT2oHQ+TyHQYpgjxzlUdy7dCdv56+w5HnBg9z96eY= -github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240103193554-5ad54212812d h1:mNf2qlDGSNp6yd4rSJBT93vGseuqraj8/jWWXm1ro+k= -github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240103193554-5ad54212812d/go.mod h1:ioCT2oHQ+TyHQYpgjxzlUdy7dCdv56+w5HnBg9z96eY= -github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240131142608-5c126467749c h1:Fr0PM4Kh33QqTHyIqzRQqx049zNvmeKKSCxCFfB/JK4= -github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240131142608-5c126467749c/go.mod h1:ioCT2oHQ+TyHQYpgjxzlUdy7dCdv56+w5HnBg9z96eY= +github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240222125646-f6bcc32e44f5 h1:3S21hIYIG/J9dLgMSDh6eOikLO9zyHfLbxYG/aax4X4= +github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240222125646-f6bcc32e44f5/go.mod h1:ioCT2oHQ+TyHQYpgjxzlUdy7dCdv56+w5HnBg9z96eY= github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20231228070003-ae14e1e0adfa h1:xdDeUC4yOfiUwctkYioYMjjigBZoZo5RZq1e5WoCVRs= github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20231228070003-ae14e1e0adfa/go.mod h1:7jjGRykSfLeMs6iQdszlE0lGK2xp9/cctiVdeKbQLLM= github.com/multiversx/mx-chain-vm-go v1.5.23-0.20231228064104-964359cb8dd3 h1:qfzeTPI2oSgxnw52KiVWc2fHMem6FZIkX1Azwy64098= @@ -419,7 +412,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= From 685b3ebcbc83029084e5159c8745baec3bc0bb5b Mon Sep 17 00:00:00 2001 From: ssd04 Date: Sun, 25 Feb 2024 21:03:26 +0200 Subject: [PATCH 069/503] use tmp as file path flag in persister creator --- storage/factory/dbConfigHandler.go | 28 +++----------- storage/factory/export_test.go | 5 +++ storage/factory/persisterCreator.go | 49 ++++++++++++++---------- storage/factory/persisterCreator_test.go | 32 ++++++++++++++++ 4 files changed, 72 insertions(+), 42 deletions(-) diff --git a/storage/factory/dbConfigHandler.go b/storage/factory/dbConfigHandler.go index 5dc426ad441..7c361164173 100644 --- a/storage/factory/dbConfigHandler.go +++ b/storage/factory/dbConfigHandler.go @@ -14,26 +14,17 @@ const ( defaultBatchDelaySeconds = 2 defaultMaxBatchSize = 100 defaultMaxOpenFiles = 10 + defaultUseTmpAsFilePath = false ) type dbConfigHandler struct { - dbType string - batchDelaySeconds int - maxBatchSize int - maxOpenFiles int - shardIDProviderType string - numShards int32 + conf config.DBConfig } // NewDBConfigHandler will create a new db config handler instance func NewDBConfigHandler(config config.DBConfig) *dbConfigHandler { return &dbConfigHandler{ - dbType: config.Type, - batchDelaySeconds: config.BatchDelaySeconds, - maxBatchSize: config.MaxBatchSize, - maxOpenFiles: config.MaxOpenFiles, - shardIDProviderType: config.ShardIDProviderType, - numShards: config.NumShards, + conf: config, } } @@ -53,23 +44,16 @@ func (dh *dbConfigHandler) GetDBConfig(path string) (*config.DBConfig, error) { BatchDelaySeconds: defaultBatchDelaySeconds, MaxBatchSize: defaultMaxBatchSize, MaxOpenFiles: defaultMaxOpenFiles, + UseTmpAsFilePath: defaultUseTmpAsFilePath, } log.Debug("GetDBConfig: loaded default db config") return dbConfig, nil } - dbConfig := &config.DBConfig{ - Type: dh.dbType, - BatchDelaySeconds: dh.batchDelaySeconds, - MaxBatchSize: dh.maxBatchSize, - MaxOpenFiles: dh.maxOpenFiles, - ShardIDProviderType: dh.shardIDProviderType, - NumShards: dh.numShards, - } - log.Debug("GetDBConfig: loaded db config from main config file") - return dbConfig, nil + + return &dh.conf, nil } // SaveDBConfigToFilePath will save the provided db config to specified path diff --git a/storage/factory/export_test.go b/storage/factory/export_test.go index 4b5ac54baac..b3cf78960c4 100644 --- a/storage/factory/export_test.go +++ b/storage/factory/export_test.go @@ -29,3 +29,8 @@ func NewPersisterCreator(config config.DBConfig) *persisterCreator { func (pc *persisterCreator) CreateShardIDProvider() (storage.ShardIDProvider, error) { return pc.createShardIDProvider() } + +// GetTmpFilePath - +func GetTmpFilePath(path string) (string, error) { + return getTmpFilePath(path) +} diff --git a/storage/factory/persisterCreator.go b/storage/factory/persisterCreator.go index 13398c38a5c..90a4d9d3391 100644 --- a/storage/factory/persisterCreator.go +++ b/storage/factory/persisterCreator.go @@ -1,6 +1,9 @@ package factory import ( + "os" + "strings" + "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/storage/database" @@ -12,33 +15,31 @@ const minNumShards = 2 // persisterCreator is the factory which will handle creating new persisters type persisterCreator struct { - dbType string - batchDelaySeconds int - maxBatchSize int - maxOpenFiles int - shardIDProviderType string - numShards int32 + conf config.DBConfig } func newPersisterCreator(config config.DBConfig) *persisterCreator { return &persisterCreator{ - dbType: config.Type, - batchDelaySeconds: config.BatchDelaySeconds, - maxBatchSize: config.MaxBatchSize, - maxOpenFiles: config.MaxOpenFiles, - shardIDProviderType: config.ShardIDProviderType, - numShards: config.NumShards, + conf: config, } } // Create will create the persister for the provided path -// TODO: refactor to use max tries mechanism func (pc *persisterCreator) Create(path string) (storage.Persister, error) { if len(path) == 0 { return nil, storage.ErrInvalidFilePath } - if pc.numShards < minNumShards { + if pc.conf.UseTmpAsFilePath { + filePath, err := getTmpFilePath(path) + if err != nil { + return nil, err + } + + path = filePath + } + + if pc.conf.NumShards < minNumShards { return pc.CreateBasePersister(path) } @@ -49,25 +50,33 @@ func (pc *persisterCreator) Create(path string) (storage.Persister, error) { return database.NewShardedPersister(path, pc, shardIDProvider) } +func getTmpFilePath(path string) (string, error) { + pathItems := strings.Split(path, "/") + + lastItem := pathItems[len(pathItems)-1] + + return os.MkdirTemp("", lastItem) +} + // CreateBasePersister will create base the persister for the provided path func (pc *persisterCreator) CreateBasePersister(path string) (storage.Persister, error) { - var dbType = storageunit.DBType(pc.dbType) + var dbType = storageunit.DBType(pc.conf.Type) argsDB := factory.ArgDB{ DBType: dbType, Path: path, - BatchDelaySeconds: pc.batchDelaySeconds, - MaxBatchSize: pc.maxBatchSize, - MaxOpenFiles: pc.maxOpenFiles, + BatchDelaySeconds: pc.conf.BatchDelaySeconds, + MaxBatchSize: pc.conf.MaxBatchSize, + MaxOpenFiles: pc.conf.MaxOpenFiles, } return storageunit.NewDB(argsDB) } func (pc *persisterCreator) createShardIDProvider() (storage.ShardIDProvider, error) { - switch storageunit.ShardIDProviderType(pc.shardIDProviderType) { + switch storageunit.ShardIDProviderType(pc.conf.ShardIDProviderType) { case storageunit.BinarySplit: - return database.NewShardIDProvider(pc.numShards) + return database.NewShardIDProvider(pc.conf.NumShards) default: return nil, storage.ErrNotSupportedShardIDProviderType } diff --git a/storage/factory/persisterCreator_test.go b/storage/factory/persisterCreator_test.go index a0fdef7e1ef..ae706d0badb 100644 --- a/storage/factory/persisterCreator_test.go +++ b/storage/factory/persisterCreator_test.go @@ -38,6 +38,19 @@ func TestPersisterCreator_Create(t *testing.T) { require.Equal(t, storage.ErrInvalidFilePath, err) }) + t.Run("use tmp as file path", func(t *testing.T) { + t.Parallel() + + conf := createDefaultDBConfig() + conf.UseTmpAsFilePath = true + + pc := factory.NewPersisterCreator(conf) + + p, err := pc.Create("path1") + require.Nil(t, err) + require.NotNil(t, p) + }) + t.Run("should create non sharded persister", func(t *testing.T) { t.Parallel() @@ -153,3 +166,22 @@ func TestPersisterCreator_CreateShardIDProvider(t *testing.T) { assert.True(t, strings.Contains(fmt.Sprintf("%T", p), "*sharded.shardIDProvider")) }) } + +func TestGetTmpFilePath(t *testing.T) { + t.Parallel() + + tmpBasePath := "/tmp/" + + path, err := factory.GetTmpFilePath("aaaa/bbbb/cccc") + require.Nil(t, err) + require.True(t, strings.HasPrefix(path, tmpBasePath+"cccc")) + + path, _ = factory.GetTmpFilePath("aaaa") + require.True(t, strings.HasPrefix(path, tmpBasePath+"aaaa")) + + path, _ = factory.GetTmpFilePath("") + require.True(t, strings.HasPrefix(path, tmpBasePath+"")) + + path, _ = factory.GetTmpFilePath("/") + require.True(t, strings.HasPrefix(path, tmpBasePath+"")) +} From 4b0c94c625bacc37c7bc896326962577ae56a3b2 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Sun, 25 Feb 2024 21:21:06 +0200 Subject: [PATCH 070/503] remove tmp filepath check --- dataRetriever/factory/dataPoolFactory.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/dataRetriever/factory/dataPoolFactory.go b/dataRetriever/factory/dataPoolFactory.go index 8d3ae50bdb0..6e1415ddfd8 100644 --- a/dataRetriever/factory/dataPoolFactory.go +++ b/dataRetriever/factory/dataPoolFactory.go @@ -2,7 +2,6 @@ package factory import ( "fmt" - "os" "time" "github.com/multiversx/mx-chain-core-go/core" @@ -184,15 +183,6 @@ func createTrieSyncDB(args ArgsDataPool) (storage.Persister, error) { return nil, err } - if mainConfig.TrieSyncStorage.DB.UseTmpAsFilePath { - filePath, errTempDir := os.MkdirTemp("", "trieSyncStorage") - if errTempDir != nil { - return nil, errTempDir - } - - path = filePath - } - db, err := persisterFactory.CreateWithRetries(path) if err != nil { return nil, fmt.Errorf("%w while creating the db for the trie nodes", err) From d6c8730bbbb96c3f5f2260fc82951a025445c223 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 27 Feb 2024 14:20:45 +0200 Subject: [PATCH 071/503] fix tmp path unit test --- storage/factory/persisterCreator_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/storage/factory/persisterCreator_test.go b/storage/factory/persisterCreator_test.go index ae706d0badb..67ba907b829 100644 --- a/storage/factory/persisterCreator_test.go +++ b/storage/factory/persisterCreator_test.go @@ -174,14 +174,14 @@ func TestGetTmpFilePath(t *testing.T) { path, err := factory.GetTmpFilePath("aaaa/bbbb/cccc") require.Nil(t, err) - require.True(t, strings.HasPrefix(path, tmpBasePath+"cccc")) + require.True(t, strings.Contains(path, tmpBasePath+"cccc")) path, _ = factory.GetTmpFilePath("aaaa") - require.True(t, strings.HasPrefix(path, tmpBasePath+"aaaa")) + require.True(t, strings.Contains(path, tmpBasePath+"aaaa")) path, _ = factory.GetTmpFilePath("") - require.True(t, strings.HasPrefix(path, tmpBasePath+"")) + require.True(t, strings.Contains(path, tmpBasePath+"")) path, _ = factory.GetTmpFilePath("/") - require.True(t, strings.HasPrefix(path, tmpBasePath+"")) + require.True(t, strings.Contains(path, tmpBasePath+"")) } From c73f9a87a244fe766a8e41c8390cffbffd7a639c Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 27 Feb 2024 15:04:54 +0200 Subject: [PATCH 072/503] fix tmp path unit test --- storage/factory/persisterCreator_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/storage/factory/persisterCreator_test.go b/storage/factory/persisterCreator_test.go index 67ba907b829..e108a077d5f 100644 --- a/storage/factory/persisterCreator_test.go +++ b/storage/factory/persisterCreator_test.go @@ -2,6 +2,7 @@ package factory_test import ( "fmt" + "os" "strings" "testing" @@ -170,7 +171,8 @@ func TestPersisterCreator_CreateShardIDProvider(t *testing.T) { func TestGetTmpFilePath(t *testing.T) { t.Parallel() - tmpBasePath := "/tmp/" + tmpDir := os.TempDir() + tmpBasePath := tmpDir + "/" path, err := factory.GetTmpFilePath("aaaa/bbbb/cccc") require.Nil(t, err) From 263a1c3f4de137edaab3f405a0b9d4288b6f2c77 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 28 Feb 2024 12:11:21 +0200 Subject: [PATCH 073/503] tmp path - more unit tests --- storage/factory/export_test.go | 4 +-- storage/factory/persisterCreator.go | 7 +++-- storage/factory/persisterCreator_test.go | 37 +++++++++++++++++------- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/storage/factory/export_test.go b/storage/factory/export_test.go index b3cf78960c4..3a93f266bdb 100644 --- a/storage/factory/export_test.go +++ b/storage/factory/export_test.go @@ -31,6 +31,6 @@ func (pc *persisterCreator) CreateShardIDProvider() (storage.ShardIDProvider, er } // GetTmpFilePath - -func GetTmpFilePath(path string) (string, error) { - return getTmpFilePath(path) +func GetTmpFilePath(path string, pathSeparator string) (string, error) { + return getTmpFilePath(path, pathSeparator) } diff --git a/storage/factory/persisterCreator.go b/storage/factory/persisterCreator.go index 90a4d9d3391..9b77bfe08dd 100644 --- a/storage/factory/persisterCreator.go +++ b/storage/factory/persisterCreator.go @@ -12,6 +12,7 @@ import ( ) const minNumShards = 2 +const pathSeparator = "/" // persisterCreator is the factory which will handle creating new persisters type persisterCreator struct { @@ -31,7 +32,7 @@ func (pc *persisterCreator) Create(path string) (storage.Persister, error) { } if pc.conf.UseTmpAsFilePath { - filePath, err := getTmpFilePath(path) + filePath, err := getTmpFilePath(path, pathSeparator) if err != nil { return nil, err } @@ -50,8 +51,8 @@ func (pc *persisterCreator) Create(path string) (storage.Persister, error) { return database.NewShardedPersister(path, pc, shardIDProvider) } -func getTmpFilePath(path string) (string, error) { - pathItems := strings.Split(path, "/") +func getTmpFilePath(path string, pathSeparator string) (string, error) { + pathItems := strings.Split(path, pathSeparator) lastItem := pathItems[len(pathItems)-1] diff --git a/storage/factory/persisterCreator_test.go b/storage/factory/persisterCreator_test.go index e108a077d5f..4d5677d8981 100644 --- a/storage/factory/persisterCreator_test.go +++ b/storage/factory/persisterCreator_test.go @@ -171,19 +171,34 @@ func TestPersisterCreator_CreateShardIDProvider(t *testing.T) { func TestGetTmpFilePath(t *testing.T) { t.Parallel() - tmpDir := os.TempDir() - tmpBasePath := tmpDir + "/" + t.Run("invalid path separator, should fail", func(t *testing.T) { + t.Parallel() - path, err := factory.GetTmpFilePath("aaaa/bbbb/cccc") - require.Nil(t, err) - require.True(t, strings.Contains(path, tmpBasePath+"cccc")) + invalidPathSeparator := "," + path, err := factory.GetTmpFilePath("aaaa/bbbb/cccc", invalidPathSeparator) + require.NotNil(t, err) + require.Equal(t, "", path) + }) - path, _ = factory.GetTmpFilePath("aaaa") - require.True(t, strings.Contains(path, tmpBasePath+"aaaa")) + t.Run("should work", func(t *testing.T) { + t.Parallel() - path, _ = factory.GetTmpFilePath("") - require.True(t, strings.Contains(path, tmpBasePath+"")) + pathSeparator := "/" - path, _ = factory.GetTmpFilePath("/") - require.True(t, strings.Contains(path, tmpBasePath+"")) + tmpDir := os.TempDir() + tmpBasePath := tmpDir + pathSeparator + + path, err := factory.GetTmpFilePath("aaaa/bbbb/cccc", pathSeparator) + require.Nil(t, err) + require.True(t, strings.Contains(path, tmpBasePath+"cccc")) + + path, _ = factory.GetTmpFilePath("aaaa", pathSeparator) + require.True(t, strings.Contains(path, tmpBasePath+"aaaa")) + + path, _ = factory.GetTmpFilePath("", pathSeparator) + require.True(t, strings.Contains(path, tmpBasePath+"")) + + path, _ = factory.GetTmpFilePath("/", pathSeparator) + require.True(t, strings.Contains(path, tmpBasePath+"")) + }) } From 94743e7f3cf5e16a57ff6bed8d880e70316b7911 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 28 Feb 2024 15:25:29 +0200 Subject: [PATCH 074/503] use path package --- storage/factory/export_test.go | 4 +-- storage/factory/persisterCreator.go | 13 ++++----- storage/factory/persisterCreator_test.go | 37 ++++++++---------------- 3 files changed, 19 insertions(+), 35 deletions(-) diff --git a/storage/factory/export_test.go b/storage/factory/export_test.go index 3a93f266bdb..b3cf78960c4 100644 --- a/storage/factory/export_test.go +++ b/storage/factory/export_test.go @@ -31,6 +31,6 @@ func (pc *persisterCreator) CreateShardIDProvider() (storage.ShardIDProvider, er } // GetTmpFilePath - -func GetTmpFilePath(path string, pathSeparator string) (string, error) { - return getTmpFilePath(path, pathSeparator) +func GetTmpFilePath(path string) (string, error) { + return getTmpFilePath(path) } diff --git a/storage/factory/persisterCreator.go b/storage/factory/persisterCreator.go index 9b77bfe08dd..87313546fcb 100644 --- a/storage/factory/persisterCreator.go +++ b/storage/factory/persisterCreator.go @@ -2,7 +2,7 @@ package factory import ( "os" - "strings" + "path" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/storage" @@ -32,7 +32,7 @@ func (pc *persisterCreator) Create(path string) (storage.Persister, error) { } if pc.conf.UseTmpAsFilePath { - filePath, err := getTmpFilePath(path, pathSeparator) + filePath, err := getTmpFilePath(path) if err != nil { return nil, err } @@ -51,12 +51,9 @@ func (pc *persisterCreator) Create(path string) (storage.Persister, error) { return database.NewShardedPersister(path, pc, shardIDProvider) } -func getTmpFilePath(path string, pathSeparator string) (string, error) { - pathItems := strings.Split(path, pathSeparator) - - lastItem := pathItems[len(pathItems)-1] - - return os.MkdirTemp("", lastItem) +func getTmpFilePath(p string) (string, error) { + _, file := path.Split(p) + return os.MkdirTemp("", file) } // CreateBasePersister will create base the persister for the provided path diff --git a/storage/factory/persisterCreator_test.go b/storage/factory/persisterCreator_test.go index 4d5677d8981..303cfcb395e 100644 --- a/storage/factory/persisterCreator_test.go +++ b/storage/factory/persisterCreator_test.go @@ -171,34 +171,21 @@ func TestPersisterCreator_CreateShardIDProvider(t *testing.T) { func TestGetTmpFilePath(t *testing.T) { t.Parallel() - t.Run("invalid path separator, should fail", func(t *testing.T) { - t.Parallel() - - invalidPathSeparator := "," - path, err := factory.GetTmpFilePath("aaaa/bbbb/cccc", invalidPathSeparator) - require.NotNil(t, err) - require.Equal(t, "", path) - }) - - t.Run("should work", func(t *testing.T) { - t.Parallel() - - pathSeparator := "/" + pathSeparator := "/" - tmpDir := os.TempDir() - tmpBasePath := tmpDir + pathSeparator + tmpDir := os.TempDir() + tmpBasePath := tmpDir + pathSeparator - path, err := factory.GetTmpFilePath("aaaa/bbbb/cccc", pathSeparator) - require.Nil(t, err) - require.True(t, strings.Contains(path, tmpBasePath+"cccc")) + path, err := factory.GetTmpFilePath("aaaa/bbbb/cccc") + require.Nil(t, err) + require.True(t, strings.Contains(path, tmpBasePath+"cccc")) - path, _ = factory.GetTmpFilePath("aaaa", pathSeparator) - require.True(t, strings.Contains(path, tmpBasePath+"aaaa")) + path, _ = factory.GetTmpFilePath("aaaa") + require.True(t, strings.Contains(path, tmpBasePath+"aaaa")) - path, _ = factory.GetTmpFilePath("", pathSeparator) - require.True(t, strings.Contains(path, tmpBasePath+"")) + path, _ = factory.GetTmpFilePath("") + require.True(t, strings.Contains(path, tmpBasePath+"")) - path, _ = factory.GetTmpFilePath("/", pathSeparator) - require.True(t, strings.Contains(path, tmpBasePath+"")) - }) + path, _ = factory.GetTmpFilePath("/") + require.True(t, strings.Contains(path, tmpBasePath+"")) } From 69baeea347cf2c91756d8465a5a78ca02a6f7641 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 28 Feb 2024 16:19:28 +0200 Subject: [PATCH 075/503] move tmp file path check into persister factory --- storage/factory/persisterCreator.go | 17 ------- storage/factory/persisterCreator_test.go | 23 --------- storage/factory/persisterFactory.go | 16 ++++++ storage/factory/persisterFactory_test.go | 64 ++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 40 deletions(-) diff --git a/storage/factory/persisterCreator.go b/storage/factory/persisterCreator.go index 87313546fcb..f5ec50be685 100644 --- a/storage/factory/persisterCreator.go +++ b/storage/factory/persisterCreator.go @@ -1,9 +1,6 @@ package factory import ( - "os" - "path" - "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/storage/database" @@ -31,15 +28,6 @@ func (pc *persisterCreator) Create(path string) (storage.Persister, error) { return nil, storage.ErrInvalidFilePath } - if pc.conf.UseTmpAsFilePath { - filePath, err := getTmpFilePath(path) - if err != nil { - return nil, err - } - - path = filePath - } - if pc.conf.NumShards < minNumShards { return pc.CreateBasePersister(path) } @@ -51,11 +39,6 @@ func (pc *persisterCreator) Create(path string) (storage.Persister, error) { return database.NewShardedPersister(path, pc, shardIDProvider) } -func getTmpFilePath(p string) (string, error) { - _, file := path.Split(p) - return os.MkdirTemp("", file) -} - // CreateBasePersister will create base the persister for the provided path func (pc *persisterCreator) CreateBasePersister(path string) (storage.Persister, error) { var dbType = storageunit.DBType(pc.conf.Type) diff --git a/storage/factory/persisterCreator_test.go b/storage/factory/persisterCreator_test.go index 303cfcb395e..b1a4cc63796 100644 --- a/storage/factory/persisterCreator_test.go +++ b/storage/factory/persisterCreator_test.go @@ -2,7 +2,6 @@ package factory_test import ( "fmt" - "os" "strings" "testing" @@ -167,25 +166,3 @@ func TestPersisterCreator_CreateShardIDProvider(t *testing.T) { assert.True(t, strings.Contains(fmt.Sprintf("%T", p), "*sharded.shardIDProvider")) }) } - -func TestGetTmpFilePath(t *testing.T) { - t.Parallel() - - pathSeparator := "/" - - tmpDir := os.TempDir() - tmpBasePath := tmpDir + pathSeparator - - path, err := factory.GetTmpFilePath("aaaa/bbbb/cccc") - require.Nil(t, err) - require.True(t, strings.Contains(path, tmpBasePath+"cccc")) - - path, _ = factory.GetTmpFilePath("aaaa") - require.True(t, strings.Contains(path, tmpBasePath+"aaaa")) - - path, _ = factory.GetTmpFilePath("") - require.True(t, strings.Contains(path, tmpBasePath+"")) - - path, _ = factory.GetTmpFilePath("/") - require.True(t, strings.Contains(path, tmpBasePath+"")) -} diff --git a/storage/factory/persisterFactory.go b/storage/factory/persisterFactory.go index 2c40b2fc328..321ddf59118 100644 --- a/storage/factory/persisterFactory.go +++ b/storage/factory/persisterFactory.go @@ -1,6 +1,8 @@ package factory import ( + "os" + "path" "time" "github.com/multiversx/mx-chain-go/config" @@ -53,6 +55,15 @@ func (pf *persisterFactory) Create(path string) (storage.Persister, error) { return nil, err } + if dbConfig.UseTmpAsFilePath { + filePath, err := getTmpFilePath(path) + if err != nil { + return nil, err + } + + path = filePath + } + pc := newPersisterCreator(*dbConfig) persister, err := pc.Create(path) @@ -73,6 +84,11 @@ func (pf *persisterFactory) CreateDisabled() storage.Persister { return disabled.NewErrorDisabledPersister() } +func getTmpFilePath(p string) (string, error) { + _, file := path.Split(p) + return os.MkdirTemp("", file) +} + // IsInterfaceNil returns true if there is no value under the interface func (pf *persisterFactory) IsInterfaceNil() bool { return pf == nil diff --git a/storage/factory/persisterFactory_test.go b/storage/factory/persisterFactory_test.go index 7dd1f987510..3d9f71b818f 100644 --- a/storage/factory/persisterFactory_test.go +++ b/storage/factory/persisterFactory_test.go @@ -2,8 +2,11 @@ package factory_test import ( "fmt" + "io/fs" "os" "path" + "path/filepath" + "strings" "testing" "github.com/multiversx/mx-chain-core-go/core/check" @@ -36,6 +39,28 @@ func TestPersisterFactory_Create(t *testing.T) { require.Equal(t, storage.ErrInvalidFilePath, err) }) + t.Run("with tmp file path, should work", func(t *testing.T) { + t.Parallel() + + conf := createDefaultDBConfig() + conf.UseTmpAsFilePath = true + + pf, _ := factory.NewPersisterFactory(conf) + + dir := t.TempDir() + + p, err := pf.Create(dir) + require.NotNil(t, p) + require.Nil(t, err) + + // config.toml will be created in tmp path, but cannot be easily checked since + // the file path is not created deterministically + + // should not find in the dir created initially. + _, err = os.Stat(dir + "/config.toml") + require.Error(t, err) + }) + t.Run("should work", func(t *testing.T) { t.Parallel() @@ -46,9 +71,26 @@ func TestPersisterFactory_Create(t *testing.T) { p, err := pf.Create(dir) require.NotNil(t, p) require.Nil(t, err) + + // check config.toml file exists + _, err = os.Stat(dir + "/config.toml") + require.Nil(t, err) }) } +func glob(root string) []string { + var files []string + + filepath.WalkDir(root, func(s string, d fs.DirEntry, e error) error { + if filepath.Ext(s) == ".toml" { + files = append(files, s) + } + return nil + }) + + return files +} + func TestPersisterFactory_CreateWithRetries(t *testing.T) { t.Parallel() @@ -180,3 +222,25 @@ func TestPersisterFactory_IsInterfaceNil(t *testing.T) { pf, _ := factory.NewPersisterFactory(createDefaultDBConfig()) require.False(t, pf.IsInterfaceNil()) } + +func TestGetTmpFilePath(t *testing.T) { + t.Parallel() + + pathSeparator := "/" + + tmpDir := os.TempDir() + tmpBasePath := tmpDir + pathSeparator + + path, err := factory.GetTmpFilePath("aaaa/bbbb/cccc") + require.Nil(t, err) + require.True(t, strings.Contains(path, tmpBasePath+"cccc")) + + path, _ = factory.GetTmpFilePath("aaaa") + require.True(t, strings.Contains(path, tmpBasePath+"aaaa")) + + path, _ = factory.GetTmpFilePath("") + require.True(t, strings.Contains(path, tmpBasePath+"")) + + path, _ = factory.GetTmpFilePath("/") + require.True(t, strings.Contains(path, tmpBasePath+"")) +} From a91e9d0e5959bf2011e61be0b682e6a38bf35143 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 28 Feb 2024 16:24:39 +0200 Subject: [PATCH 076/503] fix linter issue --- storage/factory/persisterFactory_test.go | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/storage/factory/persisterFactory_test.go b/storage/factory/persisterFactory_test.go index 3d9f71b818f..cb7e15b1e47 100644 --- a/storage/factory/persisterFactory_test.go +++ b/storage/factory/persisterFactory_test.go @@ -2,10 +2,8 @@ package factory_test import ( "fmt" - "io/fs" "os" "path" - "path/filepath" "strings" "testing" @@ -78,19 +76,6 @@ func TestPersisterFactory_Create(t *testing.T) { }) } -func glob(root string) []string { - var files []string - - filepath.WalkDir(root, func(s string, d fs.DirEntry, e error) error { - if filepath.Ext(s) == ".toml" { - files = append(files, s) - } - return nil - }) - - return files -} - func TestPersisterFactory_CreateWithRetries(t *testing.T) { t.Parallel() From 2e88a8f06774048d170bd48bd3b47c06a9396e2f Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 28 Feb 2024 16:28:58 +0200 Subject: [PATCH 077/503] fix linter issue --- storage/factory/persisterCreator.go | 1 - 1 file changed, 1 deletion(-) diff --git a/storage/factory/persisterCreator.go b/storage/factory/persisterCreator.go index f5ec50be685..0d17287815e 100644 --- a/storage/factory/persisterCreator.go +++ b/storage/factory/persisterCreator.go @@ -9,7 +9,6 @@ import ( ) const minNumShards = 2 -const pathSeparator = "/" // persisterCreator is the factory which will handle creating new persisters type persisterCreator struct { From b059f21935356b935d2ad9f8cac783c473678ae3 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 29 Feb 2024 13:15:54 +0200 Subject: [PATCH 078/503] fixes after merge --- go.mod | 17 +- go.sum | 31 +--- storage/factory/dbConfigHandler.go | 36 +---- storage/factory/storageServiceFactory.go | 193 ----------------------- 4 files changed, 9 insertions(+), 268 deletions(-) diff --git a/go.mod b/go.mod index 9181074cf15..3881fd83c4e 100644 --- a/go.mod +++ b/go.mod @@ -14,33 +14,18 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 -<<<<<<< HEAD - github.com/multiversx/mx-chain-communication-go v1.0.13-0.20231129114230-d280af707381 - github.com/multiversx/mx-chain-core-go v1.2.19-0.20231214115026-a1e7279b14f1 - github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231129101537-ef355850e34b - github.com/multiversx/mx-chain-es-indexer-go v1.4.18-0.20231228064619-e3b0caf29058 - github.com/multiversx/mx-chain-logger-go v1.0.14-0.20231215125130-a3bed6e76040 - github.com/multiversx/mx-chain-scenario-go v1.2.2-0.20231129113427-ad3056f45296 - github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240222125646-f6bcc32e44f5 - github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20231228070003-ae14e1e0adfa - github.com/multiversx/mx-chain-vm-go v1.5.23-0.20231228064104-964359cb8dd3 - github.com/multiversx/mx-chain-vm-v1_2-go v1.2.65-0.20231228071026-eed2cb19c216 - github.com/multiversx/mx-chain-vm-v1_3-go v1.3.66-0.20231228071108-6b89bcebab14 - github.com/multiversx/mx-chain-vm-v1_4-go v1.4.92-0.20231228071246-c1b45eae5955 -======= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126150131-2ac5bc749b40 github.com/multiversx/mx-chain-core-go v1.2.19-0.20240129082057-a76d0c995cf2 github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c github.com/multiversx/mx-chain-scenario-go v1.3.1-0.20240129145446-ca4fba98f6d1 - github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240129144933-b1c0d642d7f8 + github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240222125646-f6bcc32e44f5 github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240129145149-4fe61574f566 github.com/multiversx/mx-chain-vm-go v1.5.27-0.20240129150501-7c828af05c83 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240129145751-f814f5525edb github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240129150004-536a22d9c618 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.95-0.20240129150215-43996b664ada ->>>>>>> rc/v1.7.next1 github.com/pelletier/go-toml v1.9.3 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.14.0 diff --git a/go.sum b/go.sum index ed41708b24c..a098a080762 100644 --- a/go.sum +++ b/go.sum @@ -385,32 +385,6 @@ 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= -<<<<<<< HEAD -github.com/multiversx/mx-chain-communication-go v1.0.13-0.20231129114230-d280af707381 h1:M4JNeubA+zq7NaH2LP5YsWUVeKn9hNL+HgSw2kqwWUc= -github.com/multiversx/mx-chain-communication-go v1.0.13-0.20231129114230-d280af707381/go.mod h1:n4E8BWIV0g3AcNGe1gf+vcjUC8A2QCJ4ARQSbiUDGrI= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20231214115026-a1e7279b14f1 h1:8rz1ZpRAsWVxSEBy7PJIUStQMKiHs3I4mvpRmHUpsbI= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20231214115026-a1e7279b14f1/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= -github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231129101537-ef355850e34b h1:TIE6it719ZIW0E1bFgPAgE+U3zPSkPfAloFYEIeOL3U= -github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231129101537-ef355850e34b/go.mod h1:Ap6p7QZFtwPlb++OvCG+85BfuZ+bLP/JtQp6EwjWJsI= -github.com/multiversx/mx-chain-es-indexer-go v1.4.18-0.20231228064619-e3b0caf29058 h1:6XH7ua4vUqhbE4NMzs8K63b7A/9KMO4H8XZfYjyy778= -github.com/multiversx/mx-chain-es-indexer-go v1.4.18-0.20231228064619-e3b0caf29058/go.mod h1:9BzrDTbIjruFXN6YcDOBsnOP0cUHhQobRUlmNOwkDME= -github.com/multiversx/mx-chain-logger-go v1.0.14-0.20231215125130-a3bed6e76040 h1:rsEflKFn5StRh0ADxElUkI/9wZV0Lbig+b0671LmjTk= -github.com/multiversx/mx-chain-logger-go v1.0.14-0.20231215125130-a3bed6e76040/go.mod h1:fH/fR/GEBsDjPkBoZDVJMoYo2HhlA7++DP6QfITJ1N8= -github.com/multiversx/mx-chain-scenario-go v1.2.2-0.20231129113427-ad3056f45296 h1:jDGGEubkiTJfEFcbErUYCYM2Z6wKapgZyGaICScpynk= -github.com/multiversx/mx-chain-scenario-go v1.2.2-0.20231129113427-ad3056f45296/go.mod h1:WocyahfHCC3oGILEVdRe7I4/+q/TLCORoTo1X4wGmF4= -github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240222125646-f6bcc32e44f5 h1:3S21hIYIG/J9dLgMSDh6eOikLO9zyHfLbxYG/aax4X4= -github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240222125646-f6bcc32e44f5/go.mod h1:ioCT2oHQ+TyHQYpgjxzlUdy7dCdv56+w5HnBg9z96eY= -github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20231228070003-ae14e1e0adfa h1:xdDeUC4yOfiUwctkYioYMjjigBZoZo5RZq1e5WoCVRs= -github.com/multiversx/mx-chain-vm-common-go v1.5.10-0.20231228070003-ae14e1e0adfa/go.mod h1:7jjGRykSfLeMs6iQdszlE0lGK2xp9/cctiVdeKbQLLM= -github.com/multiversx/mx-chain-vm-go v1.5.23-0.20231228064104-964359cb8dd3 h1:qfzeTPI2oSgxnw52KiVWc2fHMem6FZIkX1Azwy64098= -github.com/multiversx/mx-chain-vm-go v1.5.23-0.20231228064104-964359cb8dd3/go.mod h1:4kcpwq70UB3Clnc6Q0krGA8hgQ26JTQpmCP+4y5aiV0= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.65-0.20231228071026-eed2cb19c216 h1:CDSn4hgiGwoOSSLmajgOvjdoRxfJSXjEu/CfXiqihwo= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.65-0.20231228071026-eed2cb19c216/go.mod h1:h87SKR/p66XP0Er2Mx2KfjzS6mLmW6l3tDWyO1oNr94= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.66-0.20231228071108-6b89bcebab14 h1:7r2zQiAfqGjN7U8j5obXIoRSh+vnoupBhxBgQGUA2ck= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.66-0.20231228071108-6b89bcebab14/go.mod h1:MnpQOi/P4K744ZJl8pQksulsHazmN6YRzJ4amgtZ0OQ= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.92-0.20231228071246-c1b45eae5955 h1:5b0+UeSbcyh+9z9x/6Nql3cYwaNWzTwj+KIfH4YaASs= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.92-0.20231228071246-c1b45eae5955/go.mod h1:+DLltGV0h3/H9bJaz01JyeapKNki3Rh4o5VGpjd2ZNc= -======= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126150131-2ac5bc749b40 h1:bMFxkbb1EOQs0+JMM0G0/Kv9v4Jjjla5MSVhVk6scTA= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126150131-2ac5bc749b40/go.mod h1:n4E8BWIV0g3AcNGe1gf+vcjUC8A2QCJ4ARQSbiUDGrI= github.com/multiversx/mx-chain-core-go v1.2.19-0.20240129082057-a76d0c995cf2 h1:pFh9bwOTRgW173aHqA8Bmax+jYzLnRyXqRvi5alF7V4= @@ -423,8 +397,8 @@ github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c h github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c/go.mod h1:fH/fR/GEBsDjPkBoZDVJMoYo2HhlA7++DP6QfITJ1N8= github.com/multiversx/mx-chain-scenario-go v1.3.1-0.20240129145446-ca4fba98f6d1 h1:hkeHftnhRuJoT5FrfF97gEtb5aY351SWEjZPaTb6D+Y= github.com/multiversx/mx-chain-scenario-go v1.3.1-0.20240129145446-ca4fba98f6d1/go.mod h1:ndk45i9J9McuCJpTcgiaK4ocd0yhnBBCPrlFwO6GRcs= -github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240129144933-b1c0d642d7f8 h1:/EYv/HGX0OKbeNFt667J0yZRtuJiZH0lEK8YtobuH/c= -github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240129144933-b1c0d642d7f8/go.mod h1:zl1A6teNe39T8yhdZlkX3ckm5aLYrMIJJZ6Ord1E71M= +github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240222125646-f6bcc32e44f5 h1:3S21hIYIG/J9dLgMSDh6eOikLO9zyHfLbxYG/aax4X4= +github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240222125646-f6bcc32e44f5/go.mod h1:ioCT2oHQ+TyHQYpgjxzlUdy7dCdv56+w5HnBg9z96eY= github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240129145149-4fe61574f566 h1:zImJa/r6B5L2OLWbKTn5io53U11PPGDla12H2OaJ9y0= github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240129145149-4fe61574f566/go.mod h1:OUyhCFqZKqUk1uaPsenyPDwO1830SlHNDU7Q7b6CBVI= github.com/multiversx/mx-chain-vm-go v1.5.27-0.20240129150501-7c828af05c83 h1:G/d9aplnwP/9MrLE3gcANEpGfn5e8ZZufijPv2XVUfw= @@ -435,7 +409,6 @@ github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240129150004-536a22d9c618 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240129150004-536a22d9c618/go.mod h1:4uezxguZiX42kUaYMK/x46LLbgpYqn/iQXbcGM7zdM0= github.com/multiversx/mx-chain-vm-v1_4-go v1.4.95-0.20240129150215-43996b664ada h1:NZLV2QmNPW+QTefuAhC24sOuGbOsAQEXzfv2CWoRJKc= github.com/multiversx/mx-chain-vm-v1_4-go v1.4.95-0.20240129150215-43996b664ada/go.mod h1:tCjtWeBEZCfjEjlBcgLIRDGJbVmdV8dsmG6ydtiUtSo= ->>>>>>> rc/v1.7.next1 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= diff --git a/storage/factory/dbConfigHandler.go b/storage/factory/dbConfigHandler.go index 471412cde3d..2c4ec2330e5 100644 --- a/storage/factory/dbConfigHandler.go +++ b/storage/factory/dbConfigHandler.go @@ -11,21 +11,16 @@ import ( ) const ( -<<<<<<< HEAD dbConfigFileName = "config.toml" defaultType = "LvlDBSerial" defaultBatchDelaySeconds = 2 defaultMaxBatchSize = 100 defaultMaxOpenFiles = 10 defaultUseTmpAsFilePath = false -======= - dbConfigFileName = "config.toml" - defaultType = "LvlDBSerial" ) var ( errInvalidConfiguration = errors.New("invalid configuration") ->>>>>>> rc/v1.7.next1 ) type dbConfigHandler struct { @@ -55,16 +50,10 @@ func (dh *dbConfigHandler) GetDBConfig(path string) (*config.DBConfig, error) { if !empty { dbConfig := &config.DBConfig{ Type: defaultType, -<<<<<<< HEAD - BatchDelaySeconds: defaultBatchDelaySeconds, - MaxBatchSize: defaultMaxBatchSize, - MaxOpenFiles: defaultMaxOpenFiles, - UseTmpAsFilePath: defaultUseTmpAsFilePath, -======= - BatchDelaySeconds: dh.batchDelaySeconds, - MaxBatchSize: dh.maxBatchSize, - MaxOpenFiles: dh.maxOpenFiles, ->>>>>>> rc/v1.7.next1 + BatchDelaySeconds: dh.conf.BatchDelaySeconds, + MaxBatchSize: dh.conf.MaxBatchSize, + MaxOpenFiles: dh.conf.MaxOpenFiles, + UseTmpAsFilePath: dh.conf.UseTmpAsFilePath, } log.Debug("GetDBConfig: loaded default db config", @@ -74,26 +63,13 @@ func (dh *dbConfigHandler) GetDBConfig(path string) (*config.DBConfig, error) { return dbConfig, nil } -<<<<<<< HEAD - log.Debug("GetDBConfig: loaded db config from main config file") - return &dh.conf, nil -======= - dbConfig := &config.DBConfig{ - Type: dh.dbType, - BatchDelaySeconds: dh.batchDelaySeconds, - MaxBatchSize: dh.maxBatchSize, - MaxOpenFiles: dh.maxOpenFiles, - ShardIDProviderType: dh.shardIDProviderType, - NumShards: dh.numShards, - } log.Debug("GetDBConfig: loaded db config from main config file", - "configuration", fmt.Sprintf("%+v", dbConfig), + "configuration", fmt.Sprintf("%+v", dh.conf), ) - return dbConfig, nil ->>>>>>> rc/v1.7.next1 + return &dh.conf, nil } func readCorrectConfigurationFromToml(dbConfig *config.DBConfig, filePath string) error { diff --git a/storage/factory/storageServiceFactory.go b/storage/factory/storageServiceFactory.go index 64deec47fd0..c153e6b2cc8 100644 --- a/storage/factory/storageServiceFactory.go +++ b/storage/factory/storageServiceFactory.go @@ -235,26 +235,7 @@ func (psf *StorageServiceFactory) createAndAddBaseStorageUnits( } store.AddStorer(dataRetriever.MetaBlockUnit, metaBlockUnit) -<<<<<<< HEAD metaHdrHashNonceUnit, err := psf.createStaticStorageUnit(psf.generalConfig.MetaHdrNonceHashStorage, shardID, emptyDBPathSuffix) -======= - // metaHdrHashNonce is static - metaHdrHashNonceUnitConfig := GetDBFromConfig(psf.generalConfig.MetaHdrNonceHashStorage.DB) - dbPath := psf.pathManager.PathForStatic(shardID, psf.generalConfig.MetaHdrNonceHashStorage.DB.FilePath) - metaHdrHashNonceUnitConfig.FilePath = dbPath - - dbConfigHandlerInstance := NewDBConfigHandler(psf.generalConfig.MetaHdrNonceHashStorage.DB) - metaHdrHashNoncePersisterCreator, err := NewPersisterFactory(dbConfigHandlerInstance) - if err != nil { - return err - } - - metaHdrHashNonceUnit, err := storageunit.NewStorageUnitFromConf( - GetCacherFromConfig(psf.generalConfig.MetaHdrNonceHashStorage.Cache), - metaHdrHashNonceUnitConfig, - metaHdrHashNoncePersisterCreator, - ) ->>>>>>> rc/v1.7.next1 if err != nil { return fmt.Errorf("%w for MetaHdrNonceHashStorage", err) } @@ -277,24 +258,7 @@ func (psf *StorageServiceFactory) createAndAddBaseStorageUnits( store.AddStorer(dataRetriever.UserAccountsUnit, userAccountsUnit) shardId := core.GetShardIDString(psf.shardCoordinator.SelfId()) -<<<<<<< HEAD statusMetricsStorageUnit, err := psf.createStaticStorageUnit(psf.generalConfig.StatusMetricsStorage, shardId, emptyDBPathSuffix) -======= - dbPath = psf.pathManager.PathForStatic(shardId, psf.generalConfig.StatusMetricsStorage.DB.FilePath) - statusMetricsDbConfig.FilePath = dbPath - - dbConfigHandlerInstance = NewDBConfigHandler(psf.generalConfig.StatusMetricsStorage.DB) - statusMetricsPersisterCreator, err := NewPersisterFactory(dbConfigHandlerInstance) - if err != nil { - return err - } - - statusMetricsStorageUnit, err := storageunit.NewStorageUnitFromConf( - GetCacherFromConfig(psf.generalConfig.StatusMetricsStorage.Cache), - statusMetricsDbConfig, - statusMetricsPersisterCreator, - ) ->>>>>>> rc/v1.7.next1 if err != nil { return fmt.Errorf("%w for StatusMetricsStorage", err) } @@ -342,28 +306,8 @@ func (psf *StorageServiceFactory) CreateForShard() (dataRetriever.StorageService } shardID := core.GetShardIDString(psf.shardCoordinator.SelfId()) -<<<<<<< HEAD dbPathSuffix := shardID shardHdrHashNonceUnit, err := psf.createStaticStorageUnit(psf.generalConfig.ShardHdrNonceHashStorage, shardID, dbPathSuffix) -======= - - // shardHdrHashNonce storer is static - shardHdrHashNonceConfig := GetDBFromConfig(psf.generalConfig.ShardHdrNonceHashStorage.DB) - dbPath := psf.pathManager.PathForStatic(shardID, psf.generalConfig.ShardHdrNonceHashStorage.DB.FilePath) + shardID - shardHdrHashNonceConfig.FilePath = dbPath - - dbConfigHandlerInstance := NewDBConfigHandler(psf.generalConfig.ShardHdrNonceHashStorage.DB) - shardHdrHashNoncePersisterCreator, err := NewPersisterFactory(dbConfigHandlerInstance) - if err != nil { - return nil, err - } - - shardHdrHashNonceUnit, err := storageunit.NewStorageUnitFromConf( - GetCacherFromConfig(psf.generalConfig.ShardHdrNonceHashStorage.Cache), - shardHdrHashNonceConfig, - shardHdrHashNoncePersisterCreator, - ) ->>>>>>> rc/v1.7.next1 if err != nil { return nil, fmt.Errorf("%w for ShardHdrNonceHashStorage", err) } @@ -429,28 +373,9 @@ func (psf *StorageServiceFactory) CreateForMeta() (dataRetriever.StorageService, shardHdrHashNonceUnits := make([]*storageunit.Unit, psf.shardCoordinator.NumberOfShards()) for i := uint32(0); i < psf.shardCoordinator.NumberOfShards(); i++ { shardID = core.GetShardIDString(core.MetachainShardId) -<<<<<<< HEAD shardHdrHashNonceUnits[i], err = psf.createStaticStorageUnit(psf.generalConfig.ShardHdrNonceHashStorage, shardID, fmt.Sprintf("%d", i)) if err != nil { return nil, fmt.Errorf("%w for ShardHdrNonceHashStorage on shard %d", err, i) -======= - dbPath := psf.pathManager.PathForStatic(shardID, psf.generalConfig.ShardHdrNonceHashStorage.DB.FilePath) + fmt.Sprintf("%d", i) - shardHdrHashNonceConfig.FilePath = dbPath - - dbConfigHandlerInstance := NewDBConfigHandler(psf.generalConfig.ShardHdrNonceHashStorage.DB) - shardHdrHashNoncePersisterCreator, errLoop := NewPersisterFactory(dbConfigHandlerInstance) - if errLoop != nil { - return nil, errLoop - } - - shardHdrHashNonceUnits[i], errLoop = storageunit.NewStorageUnitFromConf( - GetCacherFromConfig(psf.generalConfig.ShardHdrNonceHashStorage.Cache), - shardHdrHashNonceConfig, - shardHdrHashNoncePersisterCreator, - ) - if errLoop != nil { - return nil, fmt.Errorf("%w for ShardHdrNonceHashStorage on shard %d", errLoop, i) ->>>>>>> rc/v1.7.next1 } } @@ -578,81 +503,21 @@ func (psf *StorageServiceFactory) setUpDbLookupExtensions(chainStorer *dataRetri chainStorer.AddStorer(dataRetriever.MiniblocksMetadataUnit, miniblocksMetadataPruningStorer) -<<<<<<< HEAD miniblockHashByTxHashUnit, err := psf.createStaticStorageUnit(psf.generalConfig.DbLookupExtensions.MiniblockHashByTxHashStorageConfig, shardID, emptyDBPathSuffix) -======= - // Create the miniblocksHashByTxHash (STATIC) storer - miniblockHashByTxHashConfig := psf.generalConfig.DbLookupExtensions.MiniblockHashByTxHashStorageConfig - miniblockHashByTxHashDbConfig := GetDBFromConfig(miniblockHashByTxHashConfig.DB) - miniblockHashByTxHashDbConfig.FilePath = psf.pathManager.PathForStatic(shardID, miniblockHashByTxHashConfig.DB.FilePath) - miniblockHashByTxHashCacherConfig := GetCacherFromConfig(miniblockHashByTxHashConfig.Cache) - - dbConfigHandlerInstance := NewDBConfigHandler(miniblockHashByTxHashConfig.DB) - miniblockHashByTxHashPersisterCreator, err := NewPersisterFactory(dbConfigHandlerInstance) - if err != nil { - return err - } - - miniblockHashByTxHashUnit, err := storageunit.NewStorageUnitFromConf( - miniblockHashByTxHashCacherConfig, - miniblockHashByTxHashDbConfig, - miniblockHashByTxHashPersisterCreator, - ) ->>>>>>> rc/v1.7.next1 if err != nil { return fmt.Errorf("%w for DbLookupExtensions.MiniblockHashByTxHashStorageConfig", err) } chainStorer.AddStorer(dataRetriever.MiniblockHashByTxHashUnit, miniblockHashByTxHashUnit) -<<<<<<< HEAD blockHashByRoundUnit, err := psf.createStaticStorageUnit(psf.generalConfig.DbLookupExtensions.RoundHashStorageConfig, shardID, emptyDBPathSuffix) -======= - // Create the blockHashByRound (STATIC) storer - blockHashByRoundConfig := psf.generalConfig.DbLookupExtensions.RoundHashStorageConfig - blockHashByRoundDBConfig := GetDBFromConfig(blockHashByRoundConfig.DB) - blockHashByRoundDBConfig.FilePath = psf.pathManager.PathForStatic(shardID, blockHashByRoundConfig.DB.FilePath) - blockHashByRoundCacherConfig := GetCacherFromConfig(blockHashByRoundConfig.Cache) - - dbConfigHandlerInstance = NewDBConfigHandler(blockHashByRoundConfig.DB) - blockHashByRoundPersisterCreator, err := NewPersisterFactory(dbConfigHandlerInstance) - if err != nil { - return err - } - - blockHashByRoundUnit, err := storageunit.NewStorageUnitFromConf( - blockHashByRoundCacherConfig, - blockHashByRoundDBConfig, - blockHashByRoundPersisterCreator, - ) ->>>>>>> rc/v1.7.next1 if err != nil { return fmt.Errorf("%w for DbLookupExtensions.RoundHashStorageConfig", err) } chainStorer.AddStorer(dataRetriever.RoundHdrHashDataUnit, blockHashByRoundUnit) -<<<<<<< HEAD epochByHashUnit, err := psf.createStaticStorageUnit(psf.generalConfig.DbLookupExtensions.EpochByHashStorageConfig, shardID, emptyDBPathSuffix) -======= - // Create the epochByHash (STATIC) storer - epochByHashConfig := psf.generalConfig.DbLookupExtensions.EpochByHashStorageConfig - epochByHashDbConfig := GetDBFromConfig(epochByHashConfig.DB) - epochByHashDbConfig.FilePath = psf.pathManager.PathForStatic(shardID, epochByHashConfig.DB.FilePath) - epochByHashCacherConfig := GetCacherFromConfig(epochByHashConfig.Cache) - - dbConfigHandlerInstance = NewDBConfigHandler(epochByHashConfig.DB) - epochByHashPersisterCreator, err := NewPersisterFactory(dbConfigHandlerInstance) - if err != nil { - return err - } - - epochByHashUnit, err := storageunit.NewStorageUnitFromConf( - epochByHashCacherConfig, - epochByHashDbConfig, - epochByHashPersisterCreator, - ) ->>>>>>> rc/v1.7.next1 if err != nil { return fmt.Errorf("%w for DbLookupExtensions.EpochByHashStorageConfig", err) } @@ -686,26 +551,6 @@ func (psf *StorageServiceFactory) setUpEsdtSuppliesStorer(chainStorer *dataRetri return nil } -<<<<<<< HEAD -======= -func (psf *StorageServiceFactory) createEsdtSuppliesUnit(shardIDStr string) (storage.Storer, error) { - esdtSuppliesConfig := psf.generalConfig.DbLookupExtensions.ESDTSuppliesStorageConfig - esdtSuppliesDbConfig := GetDBFromConfig(esdtSuppliesConfig.DB) - esdtSuppliesDbConfig.FilePath = psf.pathManager.PathForStatic(shardIDStr, esdtSuppliesConfig.DB.FilePath) - esdtSuppliesCacherConfig := GetCacherFromConfig(esdtSuppliesConfig.Cache) - - dbConfigHandlerInstance := NewDBConfigHandler(esdtSuppliesConfig.DB) - esdtSuppliesPersisterCreator, err := NewPersisterFactory(dbConfigHandlerInstance) - if err != nil { - return nil, err - } - - return storageunit.NewStorageUnitFromConf( - esdtSuppliesCacherConfig, esdtSuppliesDbConfig, - esdtSuppliesPersisterCreator) -} - ->>>>>>> rc/v1.7.next1 func (psf *StorageServiceFactory) createPruningStorerArgs( storageConfig config.StorageConfig, customDatabaseRemover storage.CustomDatabaseRemoverHandler, @@ -721,12 +566,7 @@ func (psf *StorageServiceFactory) createPruningStorerArgs( NumOfActivePersisters: numOfActivePersisters, } -<<<<<<< HEAD persisterFactory, err := NewPersisterFactory(storageConfig.DB) -======= - dbConfigHandlerInstance := NewDBConfigHandler(storageConfig.DB) - persisterFactory, err := NewPersisterFactory(dbConfigHandlerInstance) ->>>>>>> rc/v1.7.next1 if err != nil { return pruning.StorerArgs{}, err } @@ -758,24 +598,7 @@ func (psf *StorageServiceFactory) createTrieEpochRootHashStorerIfNeeded() (stora } shardId := core.GetShardIDString(psf.shardCoordinator.SelfId()) -<<<<<<< HEAD trieEpochRootHashStorageUnit, err := psf.createStaticStorageUnit(psf.generalConfig.TrieEpochRootHashStorage, shardId, emptyDBPathSuffix) -======= - dbPath := psf.pathManager.PathForStatic(shardId, psf.generalConfig.TrieEpochRootHashStorage.DB.FilePath) - trieEpochRootHashDbConfig.FilePath = dbPath - - dbConfigHandlerInstance := NewDBConfigHandler(psf.generalConfig.TrieEpochRootHashStorage.DB) - esdtSuppliesPersisterCreator, err := NewPersisterFactory(dbConfigHandlerInstance) - if err != nil { - return nil, err - } - - trieEpochRootHashStorageUnit, err := storageunit.NewStorageUnitFromConf( - GetCacherFromConfig(psf.generalConfig.TrieEpochRootHashStorage.Cache), - trieEpochRootHashDbConfig, - esdtSuppliesPersisterCreator, - ) ->>>>>>> rc/v1.7.next1 if err != nil { return nil, fmt.Errorf("%w for TrieEpochRootHashStorage", err) } @@ -787,23 +610,7 @@ func (psf *StorageServiceFactory) createTriePersister( storageConfig config.StorageConfig, ) (storage.Storer, error) { shardID := core.GetShardIDString(psf.shardCoordinator.SelfId()) -<<<<<<< HEAD return psf.createStaticStorageUnit(storageConfig, shardID, emptyDBPathSuffix) -======= - dbPath := psf.pathManager.PathForStatic(shardID, storageConfig.DB.FilePath) - trieDBConfig.FilePath = dbPath - - dbConfigHandlerInstance := NewDBConfigHandler(storageConfig.DB) - persisterFactory, err := NewPersisterFactory(dbConfigHandlerInstance) - if err != nil { - return nil, err - } - - return storageunit.NewStorageUnitFromConf( - GetCacherFromConfig(storageConfig.Cache), - trieDBConfig, - persisterFactory) ->>>>>>> rc/v1.7.next1 } func (psf *StorageServiceFactory) createTriePruningPersister(arg pruning.StorerArgs) (storage.Storer, error) { From 0742145329ebcd80cbec6707320711924bdde142 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 29 Feb 2024 13:58:59 +0200 Subject: [PATCH 079/503] fixes after merge --- storage/factory/dbConfigHandler.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/storage/factory/dbConfigHandler.go b/storage/factory/dbConfigHandler.go index 2c4ec2330e5..468c42a2ee7 100644 --- a/storage/factory/dbConfigHandler.go +++ b/storage/factory/dbConfigHandler.go @@ -63,8 +63,6 @@ func (dh *dbConfigHandler) GetDBConfig(path string) (*config.DBConfig, error) { return dbConfig, nil } - return &dh.conf, nil - log.Debug("GetDBConfig: loaded db config from main config file", "configuration", fmt.Sprintf("%+v", dh.conf), ) From d84ab5941bcb71060bfe95336f73f2ffddba858e Mon Sep 17 00:00:00 2001 From: ssd04 Date: Mon, 4 Mar 2024 16:12:12 +0200 Subject: [PATCH 080/503] update storage version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 3881fd83c4e..c1e098d9c7d 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c github.com/multiversx/mx-chain-scenario-go v1.3.1-0.20240129145446-ca4fba98f6d1 - github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240222125646-f6bcc32e44f5 + github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240304133242-faaf1d20b087 github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240129145149-4fe61574f566 github.com/multiversx/mx-chain-vm-go v1.5.27-0.20240129150501-7c828af05c83 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240129145751-f814f5525edb diff --git a/go.sum b/go.sum index a098a080762..c8be913281d 100644 --- a/go.sum +++ b/go.sum @@ -397,8 +397,8 @@ github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c h github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c/go.mod h1:fH/fR/GEBsDjPkBoZDVJMoYo2HhlA7++DP6QfITJ1N8= github.com/multiversx/mx-chain-scenario-go v1.3.1-0.20240129145446-ca4fba98f6d1 h1:hkeHftnhRuJoT5FrfF97gEtb5aY351SWEjZPaTb6D+Y= github.com/multiversx/mx-chain-scenario-go v1.3.1-0.20240129145446-ca4fba98f6d1/go.mod h1:ndk45i9J9McuCJpTcgiaK4ocd0yhnBBCPrlFwO6GRcs= -github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240222125646-f6bcc32e44f5 h1:3S21hIYIG/J9dLgMSDh6eOikLO9zyHfLbxYG/aax4X4= -github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240222125646-f6bcc32e44f5/go.mod h1:ioCT2oHQ+TyHQYpgjxzlUdy7dCdv56+w5HnBg9z96eY= +github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240304133242-faaf1d20b087 h1:liZ6PL4Audkpkx4vCBngGzC48VZUpjjZd+p2mgarrt0= +github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240304133242-faaf1d20b087/go.mod h1:zl1A6teNe39T8yhdZlkX3ckm5aLYrMIJJZ6Ord1E71M= github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240129145149-4fe61574f566 h1:zImJa/r6B5L2OLWbKTn5io53U11PPGDla12H2OaJ9y0= github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240129145149-4fe61574f566/go.mod h1:OUyhCFqZKqUk1uaPsenyPDwO1830SlHNDU7Q7b6CBVI= github.com/multiversx/mx-chain-vm-go v1.5.27-0.20240129150501-7c828af05c83 h1:G/d9aplnwP/9MrLE3gcANEpGfn5e8ZZufijPv2XVUfw= From 0a10cab9d60b66c2ea4980dedd2403acb95e645d Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Wed, 6 Mar 2024 11:52:36 +0200 Subject: [PATCH 081/503] merge RecreateTrie and RecreateTrieFromEpoch --- common/holders/rootHashHolder.go | 11 ++- common/holders/rootHashHolder_test.go | 4 +- common/interface.go | 3 +- .../disabled/disabledAccountsAdapter.go | 7 +- genesis/process/metaGenesisBlockCreator.go | 4 +- genesis/process/shardGenesisBlockCreator.go | 4 +- .../benchmarks/loadFromTrie_test.go | 5 +- .../state/stateTrie/stateTrie_test.go | 41 +++++------ .../state/stateTrieSync/stateTrieSync_test.go | 9 +-- .../vm/wasm/wasmvm/wasmVM_test.go | 3 +- node/node_test.go | 58 ++++++++-------- .../delegatedListProcessor_test.go | 4 +- .../directStakedListProcessor_test.go | 4 +- .../stakeValuesProcessor_test.go | 12 ++-- process/block/baseProcess_test.go | 2 +- process/block/metablock.go | 4 +- process/block/metablock_test.go | 5 +- process/block/shardblock.go | 5 +- process/peer/process.go | 9 ++- process/smartContract/scQueryService.go | 10 ++- process/smartContract/scQueryService_test.go | 60 ++++++++-------- process/sync/metablock_test.go | 4 +- process/sync/shardblock_test.go | 4 +- .../simulationAccountsDB.go | 7 +- .../simulationAccountsDB_test.go | 2 +- state/accountsDB.go | 28 ++++---- state/accountsDBApi.go | 15 ++-- state/accountsDBApiWithHistory.go | 9 +-- state/accountsDBApiWithHistory_test.go | 21 +++--- state/accountsDBApi_test.go | 48 ++++++------- state/accountsDB_test.go | 68 +++++++++---------- state/interface.go | 6 +- state/peerAccountsDB_test.go | 2 +- .../storagePruningManager_test.go | 3 +- state/syncer/baseAccountsSyncer.go | 4 +- state/trackableDataTrie/trackableDataTrie.go | 4 +- .../trackableDataTrie_test.go | 2 +- testscommon/state/accountsAdapterStub.go | 16 +---- testscommon/trie/trieStub.go | 16 +---- trie/depthFirstSync_test.go | 5 +- trie/doubleListSync_test.go | 5 +- trie/extensionNode_test.go | 3 +- trie/patriciaMerkleTrie.go | 9 +-- trie/patriciaMerkleTrie_test.go | 58 ++++++---------- 44 files changed, 284 insertions(+), 319 deletions(-) diff --git a/common/holders/rootHashHolder.go b/common/holders/rootHashHolder.go index 68f2a295a1b..47be1787feb 100644 --- a/common/holders/rootHashHolder.go +++ b/common/holders/rootHashHolder.go @@ -1,6 +1,7 @@ package holders import ( + "encoding/hex" "fmt" "github.com/multiversx/mx-chain-core-go/core" @@ -19,6 +20,14 @@ func NewRootHashHolder(rootHash []byte, epoch core.OptionalUint32) *rootHashHold } } +// NewDefaultRootHashesHolder creates a rootHashHolder without an epoch set +func NewDefaultRootHashesHolder(rootHash []byte) *rootHashHolder { + return &rootHashHolder{ + rootHash: rootHash, + epoch: core.OptionalUint32{}, + } +} + // NewRootHashHolderAsEmpty creates an empty rootHashHolder func NewRootHashHolderAsEmpty() *rootHashHolder { return &rootHashHolder{ @@ -39,7 +48,7 @@ func (holder *rootHashHolder) GetEpoch() core.OptionalUint32 { // String returns rootHashesHolder as a string func (holder *rootHashHolder) String() string { - return fmt.Sprintf("root hash %s, epoch %v, has value %v", holder.rootHash, holder.epoch.Value, holder.epoch.HasValue) + return fmt.Sprintf("root hash %s, epoch %v, has value %v", hex.EncodeToString(holder.rootHash), holder.epoch.Value, holder.epoch.HasValue) } // IsInterfaceNil returns true if there is no value under the interface diff --git a/common/holders/rootHashHolder_test.go b/common/holders/rootHashHolder_test.go index 645e73c0551..07e50675d29 100644 --- a/common/holders/rootHashHolder_test.go +++ b/common/holders/rootHashHolder_test.go @@ -1,6 +1,7 @@ package holders import ( + "encoding/hex" "testing" "github.com/multiversx/mx-chain-core-go/core" @@ -32,7 +33,8 @@ func TestNewRootHashHolder_String(t *testing.T) { HasValue: true, }, ) - expectedString := "root hash rootHash, epoch 5, has value true" + hexRootHash := hex.EncodeToString([]byte("rootHash")) + expectedString := "root hash " + hexRootHash + ", epoch 5, has value true" assert.Equal(t, expectedString, holder.String()) } diff --git a/common/interface.go b/common/interface.go index 2e14c33730e..3ec5a6fe516 100644 --- a/common/interface.go +++ b/common/interface.go @@ -42,8 +42,7 @@ type Trie interface { Delete(key []byte) error RootHash() ([]byte, error) Commit() error - Recreate(root []byte) (Trie, error) - RecreateFromEpoch(options RootHashHolder) (Trie, error) + Recreate(options RootHashHolder) (Trie, error) String() string GetObsoleteHashes() [][]byte GetDirtyHashes() (ModifiedHashes, error) diff --git a/epochStart/bootstrap/disabled/disabledAccountsAdapter.go b/epochStart/bootstrap/disabled/disabledAccountsAdapter.go index 61e06df194d..bcd5b566b39 100644 --- a/epochStart/bootstrap/disabled/disabledAccountsAdapter.go +++ b/epochStart/bootstrap/disabled/disabledAccountsAdapter.go @@ -86,12 +86,7 @@ func (a *accountsAdapter) RootHash() ([]byte, error) { } // RecreateTrie - -func (a *accountsAdapter) RecreateTrie(_ []byte) error { - return nil -} - -// RecreateTrieFromEpoch - -func (a *accountsAdapter) RecreateTrieFromEpoch(_ common.RootHashHolder) error { +func (a *accountsAdapter) RecreateTrie(_ common.RootHashHolder) error { return nil } diff --git a/genesis/process/metaGenesisBlockCreator.go b/genesis/process/metaGenesisBlockCreator.go index 40b5f606241..395110f066a 100644 --- a/genesis/process/metaGenesisBlockCreator.go +++ b/genesis/process/metaGenesisBlockCreator.go @@ -19,6 +19,7 @@ import ( disabledCommon "github.com/multiversx/mx-chain-go/common/disabled" "github.com/multiversx/mx-chain-go/common/enablers" "github.com/multiversx/mx-chain-go/common/forking" + "github.com/multiversx/mx-chain-go/common/holders" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/dataRetriever/blockchain" @@ -189,7 +190,8 @@ func createMetaGenesisBlockAfterHardFork( return nil, nil, nil, process.ErrWrongTypeAssertion } - err = arg.Accounts.RecreateTrie(hdrHandler.GetRootHash()) + rootHashHolder := holders.NewDefaultRootHashesHolder(hdrHandler.GetRootHash()) + err = arg.Accounts.RecreateTrie(rootHashHolder) if err != nil { return nil, nil, nil, err } diff --git a/genesis/process/shardGenesisBlockCreator.go b/genesis/process/shardGenesisBlockCreator.go index 9fef8f05569..c203ae1daba 100644 --- a/genesis/process/shardGenesisBlockCreator.go +++ b/genesis/process/shardGenesisBlockCreator.go @@ -16,6 +16,7 @@ import ( disabledCommon "github.com/multiversx/mx-chain-go/common/disabled" "github.com/multiversx/mx-chain-go/common/enablers" "github.com/multiversx/mx-chain-go/common/forking" + "github.com/multiversx/mx-chain-go/common/holders" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/dataRetriever/blockchain" "github.com/multiversx/mx-chain-go/genesis" @@ -297,7 +298,8 @@ func createShardGenesisBlockAfterHardFork( return nil, nil, nil, err } - err = arg.Accounts.RecreateTrie(hdrHandler.GetRootHash()) + rootHashHolder := holders.NewDefaultRootHashesHolder(hdrHandler.GetRootHash()) + err = arg.Accounts.RecreateTrie(rootHashHolder) if err != nil { return nil, nil, nil, err } diff --git a/integrationTests/benchmarks/loadFromTrie_test.go b/integrationTests/benchmarks/loadFromTrie_test.go index 470f722e899..e31ff52e603 100644 --- a/integrationTests/benchmarks/loadFromTrie_test.go +++ b/integrationTests/benchmarks/loadFromTrie_test.go @@ -9,6 +9,7 @@ import ( "github.com/multiversx/mx-chain-core-go/hashing/blake2b" "github.com/multiversx/mx-chain-core-go/marshal" "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/common/holders" "github.com/multiversx/mx-chain-go/integrationTests" "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/storage/database" @@ -63,7 +64,7 @@ func testTrieLoadTime(t *testing.T, numChildrenPerBranch int, numTries int, maxT func timeTrieRecreate(tries []*keyForTrie, depth int) { startTime := time.Now() for j := range tries { - _, _ = tries[j].tr.Recreate(tries[j].key) + _, _ = tries[j].tr.Recreate(holders.NewDefaultRootHashesHolder(tries[j].key)) } duration := time.Since(startTime) fmt.Printf("trie with depth %d, duration %d \n", depth, duration.Nanoseconds()/int64(len(tries))) @@ -100,7 +101,7 @@ func generateTriesWithMaxDepth( key := insertKeysIntoTrie(t, tr, numTrieLevels, numChildrenPerBranch) rootHash, _ := tr.RootHash() - collapsedTrie, _ := tr.Recreate(rootHash) + collapsedTrie, _ := tr.Recreate(holders.NewDefaultRootHashesHolder(rootHash)) if numTrieLevels == 1 { key = rootHash diff --git a/integrationTests/state/stateTrie/stateTrie_test.go b/integrationTests/state/stateTrie/stateTrie_test.go index 3bc5184767b..048eef52b8c 100644 --- a/integrationTests/state/stateTrie/stateTrie_test.go +++ b/integrationTests/state/stateTrie/stateTrie_test.go @@ -26,6 +26,7 @@ import ( crypto "github.com/multiversx/mx-chain-crypto-go" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/errChan" + "github.com/multiversx/mx-chain-go/common/holders" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/epochStart" @@ -241,7 +242,7 @@ func TestAccountsDB_CommitTwoOkAccountsShouldWork(t *testing.T) { // reloading a new trie to test if data is inside rootHash, err = adb.RootHash() require.Nil(t, err) - err = adb.RecreateTrie(rootHash) + err = adb.RecreateTrie(holders.NewDefaultRootHashesHolder(rootHash)) require.Nil(t, err) // checking state1 @@ -278,7 +279,7 @@ func TestTrieDB_RecreateFromStorageShouldWork(t *testing.T) { err := tr1.Commit() require.Nil(t, err) - tr2, err := tr1.Recreate(h1) + tr2, err := tr1.Recreate(holders.NewDefaultRootHashesHolder(h1)) require.Nil(t, err) valRecov, _, err := tr2.Get(key) @@ -328,7 +329,7 @@ func TestAccountsDB_CommitTwoOkAccountsWithRecreationFromStorageShouldWork(t *te fmt.Printf("data committed! Root: %v\n", base64.StdEncoding.EncodeToString(rootHash)) // reloading a new trie to test if data is inside - err = adb.RecreateTrie(h) + err = adb.RecreateTrie(holders.NewDefaultRootHashesHolder(h)) require.Nil(t, err) // checking state1 @@ -1028,7 +1029,7 @@ func BenchmarkCreateOneMillionAccounts(b *testing.B) { rootHash, err := adb.RootHash() require.Nil(b, err) - _ = adb.RecreateTrie(rootHash) + _ = adb.RecreateTrie(holders.NewDefaultRootHashesHolder(rootHash)) fmt.Println("Completely collapsed trie") createAndExecTxs(b, addr, nrTxs, nrOfAccounts, txVal, adb) } @@ -1158,7 +1159,7 @@ func TestTrieDbPruning_GetAccountAfterPruning(t *testing.T) { rootHash2, _ := adb.Commit() adb.PruneTrie(rootHash1, state.OldRoot, state.NewPruningHandler(state.EnableDataRemoval)) - err := adb.RecreateTrie(rootHash2) + err := adb.RecreateTrie(holders.NewDefaultRootHashesHolder(rootHash2)) require.Nil(t, err) acc, err := adb.GetExistingAccount(address1) require.NotNil(t, acc) @@ -1205,7 +1206,7 @@ func TestAccountsDB_RecreateTrieInvalidatesDataTriesCache(t *testing.T) { err = adb.RevertToSnapshot(0) require.Nil(t, err) - err = adb.RecreateTrie(rootHash) + err = adb.RecreateTrie(holders.NewDefaultRootHashesHolder(rootHash)) require.Nil(t, err) acc1, _ = adb.LoadAccount(address1) state1 = acc1.(state.UserAccountHandler) @@ -1250,7 +1251,7 @@ func TestTrieDbPruning_GetDataTrieTrackerAfterPruning(t *testing.T) { newRootHash, _ := adb.Commit() adb.PruneTrie(oldRootHash, state.OldRoot, state.NewPruningHandler(state.EnableDataRemoval)) - err := adb.RecreateTrie(newRootHash) + err := adb.RecreateTrie(holders.NewDefaultRootHashesHolder(newRootHash)) require.Nil(t, err) acc, err := adb.GetExistingAccount(address1) require.NotNil(t, acc) @@ -1271,7 +1272,7 @@ func TestTrieDbPruning_GetDataTrieTrackerAfterPruning(t *testing.T) { func collapseTrie(state state.UserAccountHandler, t *testing.T) { stateRootHash := state.GetRootHash() stateTrie := state.DataTrie().(common.Trie) - stateNewTrie, _ := stateTrie.Recreate(stateRootHash) + stateNewTrie, _ := stateTrie.Recreate(holders.NewDefaultRootHashesHolder(stateRootHash)) require.NotNil(t, stateNewTrie) state.SetDataTrie(stateNewTrie) @@ -1364,7 +1365,7 @@ func TestRollbackBlockAndCheckThatPruningIsCancelledOnAccountsTrie(t *testing.T) if !bytes.Equal(rootHash, rootHashOfRollbackedBlock) { time.Sleep(time.Second * 6) - err = shardNode.AccntState.RecreateTrie(rootHashOfRollbackedBlock) + err = shardNode.AccntState.RecreateTrie(holders.NewDefaultRootHashesHolder(rootHashOfRollbackedBlock)) require.True(t, strings.Contains(err.Error(), trie.ErrKeyNotFound.Error())) } @@ -1382,7 +1383,7 @@ func TestRollbackBlockAndCheckThatPruningIsCancelledOnAccountsTrie(t *testing.T) ) time.Sleep(time.Second * 5) - err = shardNode.AccntState.RecreateTrie(rootHashOfFirstBlock) + err = shardNode.AccntState.RecreateTrie(holders.NewDefaultRootHashesHolder(rootHashOfFirstBlock)) require.Nil(t, err) require.Equal(t, uint64(11), nodes[0].BlockChain.GetCurrentBlockHeader().GetNonce()) require.Equal(t, uint64(12), nodes[1].BlockChain.GetCurrentBlockHeader().GetNonce()) @@ -1445,7 +1446,7 @@ func TestRollbackBlockWithSameRootHashAsPreviousAndCheckThatPruningIsNotDone(t * require.Equal(t, uint64(1), nodes[0].BlockChain.GetCurrentBlockHeader().GetNonce()) require.Equal(t, uint64(2), nodes[1].BlockChain.GetCurrentBlockHeader().GetNonce()) - err := shardNode.AccntState.RecreateTrie(rootHashOfFirstBlock) + err := shardNode.AccntState.RecreateTrie(holders.NewDefaultRootHashesHolder(rootHashOfFirstBlock)) require.Nil(t, err) } @@ -1525,7 +1526,7 @@ func TestTriePruningWhenBlockIsFinal(t *testing.T) { require.Equal(t, uint64(17), nodes[0].BlockChain.GetCurrentBlockHeader().GetNonce()) require.Equal(t, uint64(17), nodes[1].BlockChain.GetCurrentBlockHeader().GetNonce()) - err := shardNode.AccntState.RecreateTrie(rootHashOfFirstBlock) + err := shardNode.AccntState.RecreateTrie(holders.NewDefaultRootHashesHolder(rootHashOfFirstBlock)) require.True(t, strings.Contains(err.Error(), trie.ErrKeyNotFound.Error())) } @@ -1673,12 +1674,12 @@ func checkTrieCanBeRecreated(tb testing.TB, node *integrationTests.TestProcessor stateTrie := node.TrieContainer.Get([]byte(dataRetriever.UserAccountsUnit.String())) roothash := node.BlockChain.GetCurrentBlockRootHash() - tr, err := stateTrie.Recreate(roothash) + tr, err := stateTrie.Recreate(holders.NewDefaultRootHashesHolder(roothash)) require.Nil(tb, err) require.NotNil(tb, tr) _, _, finalRoothash := node.BlockChain.GetFinalBlockInfo() - tr, err = stateTrie.Recreate(finalRoothash) + tr, err = stateTrie.Recreate(holders.NewDefaultRootHashesHolder(finalRoothash)) require.Nil(tb, err) require.NotNil(tb, tr) @@ -1690,7 +1691,7 @@ func checkTrieCanBeRecreated(tb testing.TB, node *integrationTests.TestProcessor err = integrationTests.TestMarshalizer.Unmarshal(hdr, hdrBytes) require.Nil(tb, err) - tr, err = stateTrie.Recreate(hdr.GetRootHash()) + tr, err = stateTrie.Recreate(holders.NewDefaultRootHashesHolder(hdr.GetRootHash())) require.Nil(tb, err) require.NotNil(tb, tr) } @@ -1852,14 +1853,14 @@ func testNodeStateCheckpointSnapshotAndPruning( stateTrie := node.TrieContainer.Get([]byte(dataRetriever.UserAccountsUnit.String())) assert.Equal(t, 6, len(checkpointsRootHashes)) for i := range checkpointsRootHashes { - tr, err := stateTrie.Recreate(checkpointsRootHashes[i]) + tr, err := stateTrie.Recreate(holders.NewDefaultRootHashesHolder(checkpointsRootHashes[i])) require.Nil(t, err) require.NotNil(t, tr) } assert.Equal(t, 1, len(snapshotsRootHashes)) for i := range snapshotsRootHashes { - tr, err := stateTrie.Recreate(snapshotsRootHashes[i]) + tr, err := stateTrie.Recreate(holders.NewDefaultRootHashesHolder(snapshotsRootHashes[i])) require.Nil(t, err) require.NotNil(t, tr) } @@ -1867,7 +1868,7 @@ func testNodeStateCheckpointSnapshotAndPruning( assert.Equal(t, 1, len(prunedRootHashes)) // if pruning is called for a root hash in a different epoch than the commit, then recreate trie should work for i := 0; i < len(prunedRootHashes)-1; i++ { - tr, err := stateTrie.Recreate(prunedRootHashes[i]) + tr, err := stateTrie.Recreate(holders.NewDefaultRootHashesHolder(prunedRootHashes[i])) require.Nil(t, tr) require.NotNil(t, err) } @@ -2179,10 +2180,10 @@ func checkDataTrieConsistency( for i, rootHash := range dataTriesRootHashes { _, ok := removedAccounts[i] if ok { - err := adb.RecreateTrie(rootHash) + err := adb.RecreateTrie(holders.NewDefaultRootHashesHolder(rootHash)) assert.NotNil(t, err) } else { - err := adb.RecreateTrie(rootHash) + err := adb.RecreateTrie(holders.NewDefaultRootHashesHolder(rootHash)) require.Nil(t, err) } } diff --git a/integrationTests/state/stateTrieSync/stateTrieSync_test.go b/integrationTests/state/stateTrieSync/stateTrieSync_test.go index 8bfbd584a70..74362efac08 100644 --- a/integrationTests/state/stateTrieSync/stateTrieSync_test.go +++ b/integrationTests/state/stateTrieSync/stateTrieSync_test.go @@ -12,6 +12,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core/throttler" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/errChan" + "github.com/multiversx/mx-chain-go/common/holders" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/epochStart/notifier" "github.com/multiversx/mx-chain-go/integrationTests" @@ -135,7 +136,7 @@ func testNodeRequestInterceptTrieNodesWithMessenger(t *testing.T, version int) { assert.Nil(t, err) cancel() - requesterTrie, err = requesterTrie.Recreate(rootHash) + requesterTrie, err = requesterTrie.Recreate(holders.NewDefaultRootHashesHolder(rootHash)) require.Nil(t, err) newRootHash, _ := requesterTrie.RootHash() @@ -351,7 +352,7 @@ func testMultipleDataTriesSync(t *testing.T, numAccounts int, numDataTrieLeaves err = userAccSyncer.SyncAccounts(rootHash, storageMarker.NewDisabledStorageMarker()) assert.Nil(t, err) - _ = nRequester.AccntState.RecreateTrie(rootHash) + _ = nRequester.AccntState.RecreateTrie(holders.NewDefaultRootHashesHolder(rootHash)) newRootHash, _ := nRequester.AccntState.RootHash() assert.NotEqual(t, nilRootHash, newRootHash) @@ -501,7 +502,7 @@ func testSyncMissingSnapshotNodes(t *testing.T, version int) { for sw.IsSnapshotInProgress() { time.Sleep(time.Millisecond * 100) } - _ = nRequester.AccntState.RecreateTrie(rootHash) + _ = nRequester.AccntState.RecreateTrie(holders.NewDefaultRootHashesHolder(rootHash)) newRootHash, _ := nRequester.AccntState.RootHash() assert.NotEqual(t, nilRootHash, newRootHash) @@ -537,7 +538,7 @@ func copyPartialState(t *testing.T, sourceNode, destinationNode *integrationTest func getDataTriesHashes(t *testing.T, tr common.Trie, dataTriesRootHashes [][]byte) [][]byte { hashes := make([][]byte, 0) for _, rh := range dataTriesRootHashes { - dt, err := tr.Recreate(rh) + dt, err := tr.Recreate(holders.NewDefaultRootHashesHolder(rh)) assert.Nil(t, err) dtHashes, err := dt.GetAllHashes() diff --git a/integrationTests/vm/wasm/wasmvm/wasmVM_test.go b/integrationTests/vm/wasm/wasmvm/wasmVM_test.go index 9df0d4e22b5..b9df8f2a40e 100644 --- a/integrationTests/vm/wasm/wasmvm/wasmVM_test.go +++ b/integrationTests/vm/wasm/wasmvm/wasmVM_test.go @@ -7,6 +7,7 @@ package wasmvm import ( "encoding/hex" "fmt" + "github.com/multiversx/mx-chain-go/common/holders" "math" "math/big" "testing" @@ -805,7 +806,7 @@ func TestAndCatchTrieError(t *testing.T) { log.Info("finished a set - commit and recreate trie", "index", i) if i%10 == 5 { testContext.Accounts.PruneTrie(extraNewRootHash, state.NewRoot, state.NewPruningHandler(state.EnableDataRemoval)) - _ = testContext.Accounts.RecreateTrie(rootHash) + _ = testContext.Accounts.RecreateTrie(holders.NewDefaultRootHashesHolder(rootHash)) continue } diff --git a/node/node_test.go b/node/node_test.go index d341df93636..822722edc09 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -112,7 +112,7 @@ func getAccAdapter(balance *big.Int) *stateMock.AccountsStub { return acc, nil } - accDB.RecreateTrieCalled = func(_ []byte) error { + accDB.RecreateTrieCalled = func(_ common.RootHashHolder) error { return nil } @@ -236,7 +236,7 @@ func TestNode_GetBalanceAccNotFoundShouldReturnEmpty(t *testing.T) { GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { return nil, nil, state.NewErrAccountNotFoundAtBlock(dummyBlockInfo.forProcessing()) }, - RecreateTrieCalled: func(_ []byte) error { + RecreateTrieCalled: func(_ common.RootHashHolder) error { return nil }, } @@ -338,7 +338,7 @@ func TestNode_GetCodeHashAccNotFoundShouldReturnEmpty(t *testing.T) { GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { return nil, nil, state.NewErrAccountNotFoundAtBlock(dummyBlockInfo.forProcessing()) }, - RecreateTrieCalled: func(_ []byte) error { + RecreateTrieCalled: func(_ common.RootHashHolder) error { return nil }, } @@ -409,7 +409,7 @@ func TestNode_GetKeyValuePairsAccNotFoundShouldReturnEmpty(t *testing.T) { GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { return nil, nil, state.NewErrAccountNotFoundAtBlock(dummyBlockInfo.forProcessing()) }, - RecreateTrieCalled: func(_ []byte) error { + RecreateTrieCalled: func(_ common.RootHashHolder) error { return nil }, } @@ -474,7 +474,7 @@ func TestNode_GetKeyValuePairs(t *testing.T) { accDB.GetAccountWithBlockInfoCalled = func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { return acc, nil, nil } - accDB.RecreateTrieCalled = func(rootHash []byte) error { + accDB.RecreateTrieCalled = func(rootHash common.RootHashHolder) error { return nil } @@ -534,7 +534,7 @@ func TestNode_GetKeyValuePairs_GetAllLeavesShouldFail(t *testing.T) { accDB.GetAccountWithBlockInfoCalled = func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { return acc, nil, nil } - accDB.RecreateTrieCalled = func(rootHash []byte) error { + accDB.RecreateTrieCalled = func(rootHash common.RootHashHolder) error { return nil } @@ -588,7 +588,7 @@ func TestNode_GetKeyValuePairsContextShouldTimeout(t *testing.T) { accDB.GetAccountWithBlockInfoCalled = func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { return acc, nil, nil } - accDB.RecreateTrieCalled = func(rootHash []byte) error { + accDB.RecreateTrieCalled = func(rootHash common.RootHashHolder) error { return nil } @@ -627,7 +627,7 @@ func TestNode_GetValueForKeyAccNotFoundShouldReturnEmpty(t *testing.T) { GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { return nil, nil, state.NewErrAccountNotFoundAtBlock(dummyBlockInfo.forProcessing()) }, - RecreateTrieCalled: func(_ []byte) error { + RecreateTrieCalled: func(_ common.RootHashHolder) error { return nil }, } @@ -670,7 +670,7 @@ func TestNode_GetValueForKey(t *testing.T) { GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { return acc, nil, nil }, - RecreateTrieCalled: func(_ []byte) error { + RecreateTrieCalled: func(_ common.RootHashHolder) error { return nil }, } @@ -709,7 +709,7 @@ func TestNode_GetESDTDataAccNotFoundShouldReturnEmpty(t *testing.T) { GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { return nil, nil, state.NewErrAccountNotFoundAtBlock(dummyBlockInfo.forProcessing()) }, - RecreateTrieCalled: func(_ []byte) error { + RecreateTrieCalled: func(_ common.RootHashHolder) error { return nil }, } @@ -752,7 +752,7 @@ func TestNode_GetESDTData(t *testing.T) { GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { return acc, nil, nil }, - RecreateTrieCalled: func(_ []byte) error { + RecreateTrieCalled: func(_ common.RootHashHolder) error { return nil }, } @@ -807,7 +807,7 @@ func TestNode_GetESDTDataForNFT(t *testing.T) { GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { return acc, nil, nil }, - RecreateTrieCalled: func(_ []byte) error { + RecreateTrieCalled: func(_ common.RootHashHolder) error { return nil }, } @@ -867,7 +867,7 @@ func TestNode_GetAllESDTTokens(t *testing.T) { }) accDB := &stateMock.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, } @@ -924,7 +924,7 @@ func TestNode_GetAllESDTTokens_GetAllLeavesShouldFail(t *testing.T) { }) accDB := &stateMock.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, } @@ -980,7 +980,7 @@ func TestNode_GetAllESDTTokensContextShouldTimeout(t *testing.T) { }) accDB := &stateMock.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, } @@ -1023,7 +1023,7 @@ func TestNode_GetAllESDTsAccNotFoundShouldReturnEmpty(t *testing.T) { GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { return nil, nil, state.NewErrAccountNotFoundAtBlock(dummyBlockInfo.forProcessing()) }, - RecreateTrieCalled: func(_ []byte) error { + RecreateTrieCalled: func(_ common.RootHashHolder) error { return nil }, } @@ -1114,7 +1114,7 @@ func TestNode_GetAllESDTTokensShouldReturnEsdtAndFormattedNft(t *testing.T) { }) accDB := &stateMock.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, } @@ -1198,7 +1198,7 @@ func TestNode_GetAllIssuedESDTs(t *testing.T) { }) accDB := &stateMock.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, } @@ -1284,7 +1284,7 @@ func TestNode_GetESDTsWithRole(t *testing.T) { }) accDB := &stateMock.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, } @@ -1363,7 +1363,7 @@ func TestNode_GetESDTsRoles(t *testing.T) { }) accDB := &stateMock.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, } @@ -1429,7 +1429,7 @@ func TestNode_GetNFTTokenIDsRegisteredByAddress(t *testing.T) { ) accDB := &stateMock.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, } @@ -1486,7 +1486,7 @@ func TestNode_GetNFTTokenIDsRegisteredByAddressContextShouldTimeout(t *testing.T ) accDB := &stateMock.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, } @@ -3368,7 +3368,7 @@ func TestNode_GetAccountAccNotFoundShouldReturnEmpty(t *testing.T) { GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { return nil, nil, state.NewErrAccountNotFoundAtBlock(dummyBlockInfo.forProcessing()) }, - RecreateTrieCalled: func(_ []byte) error { + RecreateTrieCalled: func(_ common.RootHashHolder) error { return nil }, } @@ -3415,7 +3415,7 @@ func TestNode_GetAccountAccountExistsShouldReturn(t *testing.T) { GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { return accnt, nil, nil }, - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, } @@ -4057,7 +4057,7 @@ func TestNode_getProofErrWhenComputingProof(t *testing.T) { }, }, nil }, - RecreateTrieCalled: func(_ []byte) error { + RecreateTrieCalled: func(_ common.RootHashHolder) error { return nil }, } @@ -4743,7 +4743,7 @@ func TestNode_GetGuardianData(t *testing.T) { GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { return testAccount, nil, nil }, - RecreateTrieCalled: func(_ []byte) error { + RecreateTrieCalled: func(_ common.RootHashHolder) error { return nil }, } @@ -4784,7 +4784,7 @@ func TestNode_GetGuardianData(t *testing.T) { GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { return testAccount, nil, nil }, - RecreateTrieCalled: func(_ []byte) error { + RecreateTrieCalled: func(_ common.RootHashHolder) error { return nil }, } @@ -4812,7 +4812,7 @@ func TestNode_GetGuardianData(t *testing.T) { GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { return nil, nil, state.NewErrAccountNotFoundAtBlock(providedBlockInfo) }, - RecreateTrieCalled: func(_ []byte) error { + RecreateTrieCalled: func(_ common.RootHashHolder) error { return nil }, } @@ -4930,7 +4930,7 @@ func TestNode_GetGuardianData(t *testing.T) { GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { return acc, nil, nil }, - RecreateTrieCalled: func(_ []byte) error { + RecreateTrieCalled: func(_ common.RootHashHolder) error { return nil }, } diff --git a/node/trieIterators/delegatedListProcessor_test.go b/node/trieIterators/delegatedListProcessor_test.go index 4718349dcf7..2a92b3a2d9f 100644 --- a/node/trieIterators/delegatedListProcessor_test.go +++ b/node/trieIterators/delegatedListProcessor_test.go @@ -118,7 +118,7 @@ func TestDelegatedListProc_GetDelegatorsListContextShouldTimeout(t *testing.T) { GetExistingAccountCalled: func(addressContainer []byte) (vmcommon.AccountHandler, error) { return createScAccount(addressContainer, delegators, addressContainer, time.Second), nil }, - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, } @@ -165,7 +165,7 @@ func TestDelegatedListProc_GetDelegatorsListShouldWork(t *testing.T) { GetExistingAccountCalled: func(addressContainer []byte) (vmcommon.AccountHandler, error) { return createScAccount(addressContainer, delegators, addressContainer, 0), nil }, - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, } diff --git a/node/trieIterators/directStakedListProcessor_test.go b/node/trieIterators/directStakedListProcessor_test.go index 552ce65d218..07495736455 100644 --- a/node/trieIterators/directStakedListProcessor_test.go +++ b/node/trieIterators/directStakedListProcessor_test.go @@ -73,7 +73,7 @@ func TestDirectStakedListProc_GetDelegatorsListContextShouldTimeout(t *testing.T GetExistingAccountCalled: func(addressContainer []byte) (vmcommon.AccountHandler, error) { return createScAccount(addressContainer, validators, addressContainer, time.Second), nil }, - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, } @@ -117,7 +117,7 @@ func TestDirectStakedListProc_GetDelegatorsListShouldWork(t *testing.T) { GetExistingAccountCalled: func(addressContainer []byte) (vmcommon.AccountHandler, error) { return createScAccount(addressContainer, validators, addressContainer, 0), nil }, - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, } diff --git a/node/trieIterators/stakeValuesProcessor_test.go b/node/trieIterators/stakeValuesProcessor_test.go index 43c991ff6d7..fa3bc870cdf 100644 --- a/node/trieIterators/stakeValuesProcessor_test.go +++ b/node/trieIterators/stakeValuesProcessor_test.go @@ -121,7 +121,7 @@ func TestTotalStakedValueProcessor_GetTotalStakedValue_CannotGetAccount(t *testi expectedErr := errors.New("expected error") arg := createMockArgs() arg.Accounts.AccountsAdapter = &stateMock.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, GetExistingAccountCalled: func(addressContainer []byte) (vmcommon.AccountHandler, error) { @@ -162,7 +162,7 @@ func TestTotalStakedValueProcessor_GetTotalStakedValue_CannotCastAccount(t *test GetExistingAccountCalled: func(addressContainer []byte) (vmcommon.AccountHandler, error) { return nil, nil }, - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, } @@ -189,7 +189,7 @@ func TestTotalStakedValueProcessor_GetTotalStakedValue_CannotGetRootHash(t *test GetExistingAccountCalled: func(addressContainer []byte) (vmcommon.AccountHandler, error) { return acc, nil }, - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, } @@ -221,7 +221,7 @@ func TestTotalStakedValueProcessor_GetTotalStakedValue_ContextShouldTimeout(t *t GetExistingAccountCalled: func(addressContainer []byte) (vmcommon.AccountHandler, error) { return acc, nil }, - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, } @@ -256,7 +256,7 @@ func TestTotalStakedValueProcessor_GetTotalStakedValue_CannotGetAllLeaves(t *tes GetExistingAccountCalled: func(addressContainer []byte) (vmcommon.AccountHandler, error) { return acc, nil }, - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, } @@ -327,7 +327,7 @@ func TestTotalStakedValueProcessor_GetTotalStakedValue(t *testing.T) { GetExistingAccountCalled: func(addressContainer []byte) (vmcommon.AccountHandler, error) { return acc, nil }, - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, } diff --git a/process/block/baseProcess_test.go b/process/block/baseProcess_test.go index 2921d29caaa..9e39fdf53e6 100644 --- a/process/block/baseProcess_test.go +++ b/process/block/baseProcess_test.go @@ -1029,7 +1029,7 @@ func TestBaseProcessor_RevertStateRecreateTrieFailsShouldErr(t *testing.T) { expectedErr := errors.New("err") arguments := CreateMockArguments(createComponentHolderMocks()) arguments.AccountsDB[state.UserAccountsState] = &stateMock.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return expectedErr }, } diff --git a/process/block/metablock.go b/process/block/metablock.go index 86126bc2c29..05c3587ada6 100644 --- a/process/block/metablock.go +++ b/process/block/metablock.go @@ -14,6 +14,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/data/headerVersionData" "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/common/holders" "github.com/multiversx/mx-chain-go/dataRetriever" processOutport "github.com/multiversx/mx-chain-go/outport/process" "github.com/multiversx/mx-chain-go/process" @@ -1582,7 +1583,8 @@ func (mp *metaProcessor) commitEpochStart(header *block.MetaBlock, body *block.B // RevertStateToBlock recreates the state tries to the root hashes indicated by the provided root hash and header func (mp *metaProcessor) RevertStateToBlock(header data.HeaderHandler, rootHash []byte) error { - err := mp.accountsDB[state.UserAccountsState].RecreateTrie(rootHash) + rootHashHolder := holders.NewDefaultRootHashesHolder(rootHash) + err := mp.accountsDB[state.UserAccountsState].RecreateTrie(rootHashHolder) if err != nil { log.Debug("recreate trie with error for header", "nonce", header.GetNonce(), diff --git a/process/block/metablock_test.go b/process/block/metablock_test.go index 30051e3d582..9b4b9dd004d 100644 --- a/process/block/metablock_test.go +++ b/process/block/metablock_test.go @@ -13,6 +13,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core/atomic" "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/block" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/dataRetriever/blockchain" "github.com/multiversx/mx-chain-go/process" @@ -1203,7 +1204,7 @@ func TestMetaProcessor_RevertStateRevertPeerStateFailsShouldErr(t *testing.T) { arguments := createMockMetaArguments(coreComponents, dataComponents, bootstrapComponents, statusComponents) arguments.AccountsDB[state.UserAccountsState] = &stateMock.AccountsStub{} arguments.AccountsDB[state.UserAccountsState] = &stateMock.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, } @@ -1231,7 +1232,7 @@ func TestMetaProcessor_RevertStateShouldWork(t *testing.T) { arguments := createMockMetaArguments(coreComponents, dataComponents, bootstrapComponents, statusComponents) arguments.AccountsDB[state.UserAccountsState] = &stateMock.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { recreateTrieWasCalled = true return nil }, diff --git a/process/block/shardblock.go b/process/block/shardblock.go index 8da3e4a07c1..4527caaf5c9 100644 --- a/process/block/shardblock.go +++ b/process/block/shardblock.go @@ -12,6 +12,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/data/headerVersionData" "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/common/holders" "github.com/multiversx/mx-chain-go/dataRetriever" processOutport "github.com/multiversx/mx-chain-go/outport/process" "github.com/multiversx/mx-chain-go/process" @@ -402,8 +403,8 @@ func (sp *shardProcessor) requestEpochStartInfo(header data.ShardHeaderHandler, // RevertStateToBlock recreates the state tries to the root hashes indicated by the provided root hash and header func (sp *shardProcessor) RevertStateToBlock(header data.HeaderHandler, rootHash []byte) error { - - err := sp.accountsDB[state.UserAccountsState].RecreateTrie(rootHash) + rootHashHolder := holders.NewDefaultRootHashesHolder(rootHash) + err := sp.accountsDB[state.UserAccountsState].RecreateTrie(rootHashHolder) if err != nil { log.Debug("recreate trie with error for header", "nonce", header.GetNonce(), diff --git a/process/peer/process.go b/process/peer/process.go index 2de1efce03f..4f818798c2e 100644 --- a/process/peer/process.go +++ b/process/peer/process.go @@ -15,6 +15,7 @@ import ( "github.com/multiversx/mx-chain-core-go/marshal" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/errChan" + "github.com/multiversx/mx-chain-go/common/holders" "github.com/multiversx/mx-chain-go/common/validatorInfo" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/process" @@ -80,7 +81,8 @@ type validatorStatistics struct { } // NewValidatorStatisticsProcessor instantiates a new validatorStatistics structure responsible for keeping account of -// each validator actions in the consensus process +// +// each validator actions in the consensus process func NewValidatorStatisticsProcessor(arguments ArgValidatorStatisticsProcessor) (*validatorStatistics, error) { if check.IfNil(arguments.PeerAdapter) { return nil, process.ErrNilPeerAccountsAdapter @@ -864,9 +866,10 @@ func (vs *validatorStatistics) decreaseForConsensusValidators( } // RevertPeerState takes the current and previous headers and undos the peer state -// for all of the consensus members +// for all of the consensus members func (vs *validatorStatistics) RevertPeerState(header data.MetaHeaderHandler) error { - return vs.peerAdapter.RecreateTrie(header.GetValidatorStatsRootHash()) + rootHashHolder := holders.NewDefaultRootHashesHolder(header.GetValidatorStatsRootHash()) + return vs.peerAdapter.RecreateTrie(rootHashHolder) } func (vs *validatorStatistics) updateShardDataPeerState( diff --git a/process/smartContract/scQueryService.go b/process/smartContract/scQueryService.go index 10a5be173da..232b97fc66f 100644 --- a/process/smartContract/scQueryService.go +++ b/process/smartContract/scQueryService.go @@ -258,15 +258,13 @@ func (service *SCQueryService) recreateTrie(blockRootHash []byte, blockHeader da accountsAdapter := service.blockChainHook.GetAccountsAdapter() + rootHashHolder := holders.NewDefaultRootHashesHolder(blockRootHash) if service.isInHistoricalBalancesMode { - logQueryService.Trace("calling RecreateTrieFromEpoch", "block", blockHeader.GetNonce(), "rootHash", blockRootHash) - holder := holders.NewRootHashHolder(blockRootHash, core.OptionalUint32{Value: blockHeader.GetEpoch(), HasValue: true}) - - return accountsAdapter.RecreateTrieFromEpoch(holder) + rootHashHolder = holders.NewRootHashHolder(blockRootHash, core.OptionalUint32{Value: blockHeader.GetEpoch(), HasValue: true}) } - logQueryService.Trace("calling RecreateTrie", "block", blockHeader.GetNonce(), "rootHash", blockRootHash) - return accountsAdapter.RecreateTrie(blockRootHash) + logQueryService.Trace("calling RecreateTrie", "block", blockHeader.GetNonce(), "rootHashHolder", rootHashHolder) + return accountsAdapter.RecreateTrie(rootHashHolder) } func (service *SCQueryService) getCurrentEpoch() uint32 { diff --git a/process/smartContract/scQueryService_test.go b/process/smartContract/scQueryService_test.go index d71542a8aaa..4889dc87ac5 100644 --- a/process/smartContract/scQueryService_test.go +++ b/process/smartContract/scQueryService_test.go @@ -40,7 +40,7 @@ func createMockArgumentsForSCQuery() ArgsNewSCQueryService { BlockChainHook: &testscommon.BlockChainHookStub{ GetAccountsAdapterCalled: func() state.AccountsAdapter { return &stateMocks.AccountsStub{ - RecreateTrieFromEpochCalled: func(options common.RootHashHolder) error { + RecreateTrieCalled: func(options common.RootHashHolder) error { return nil }, } @@ -438,15 +438,15 @@ func TestExecuteQuery_ShouldReceiveQueryCorrectly(t *testing.T) { recreateTrieFromEpochWasCalled := false providedAccountsAdapter := &stateMocks.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(options common.RootHashHolder) error { + if options.GetEpoch().HasValue { + recreateTrieFromEpochWasCalled = true + assert.Equal(t, providedRootHash, options.GetRootHash()) + return nil + } recreateTrieWasCalled = true return nil }, - RecreateTrieFromEpochCalled: func(options common.RootHashHolder) error { - recreateTrieFromEpochWasCalled = true - assert.Equal(t, providedRootHash, options.GetRootHash()) - return nil - }, } argsNewSCQuery.BlockChainHook = &testscommon.BlockChainHookStub{ GetAccountsAdapterCalled: func() state.AccountsAdapter { @@ -534,13 +534,13 @@ func TestExecuteQuery_ShouldReceiveQueryCorrectly(t *testing.T) { recreateTrieFromEpochWasCalled := false providedAccountsAdapter := &stateMocks.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(options common.RootHashHolder) error { + if options.GetEpoch().HasValue { + recreateTrieFromEpochWasCalled = true + assert.Equal(t, providedRootHash, options.GetRootHash()) + return nil + } recreateTrieWasCalled = true - assert.Equal(t, providedRootHash, rootHash) - return nil - }, - RecreateTrieFromEpochCalled: func(options common.RootHashHolder) error { - recreateTrieFromEpochWasCalled = true return nil }, } @@ -583,7 +583,7 @@ func TestSCQueryService_RecreateTrie(t *testing.T) { argsNewSCQuery.BlockChainHook = &testscommon.BlockChainHookStub{ GetAccountsAdapterCalled: func() state.AccountsAdapter { return &stateMocks.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { require.Fail(t, "should not be called") return nil }, @@ -611,17 +611,17 @@ func TestSCQueryService_RecreateTrie(t *testing.T) { argsNewSCQuery.BlockChainHook = &testscommon.BlockChainHookStub{ GetAccountsAdapterCalled: func() state.AccountsAdapter { return &stateMocks.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(options common.RootHashHolder) error { + if options.GetEpoch().HasValue { + recreateTrieWasCalled = false + recreateTrieFromEpochWasCalled = true + + assert.Equal(t, testRootHash, options.GetRootHash()) + return nil + } recreateTrieWasCalled = true recreateTrieFromEpochWasCalled = false - assert.Equal(t, testRootHash, rootHash) - return nil - }, - RecreateTrieFromEpochCalled: func(options common.RootHashHolder) error { - recreateTrieWasCalled = false - recreateTrieFromEpochWasCalled = true - assert.Equal(t, testRootHash, options.GetRootHash()) return nil }, @@ -653,17 +653,17 @@ func TestSCQueryService_RecreateTrie(t *testing.T) { argsNewSCQuery.BlockChainHook = &testscommon.BlockChainHookStub{ GetAccountsAdapterCalled: func() state.AccountsAdapter { return &stateMocks.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(options common.RootHashHolder) error { + if options.GetEpoch().HasValue { + recreateTrieWasCalled = false + recreateTrieFromEpochWasCalled = true + + assert.Equal(t, testRootHash, options.GetRootHash()) + return nil + } recreateTrieWasCalled = true recreateTrieFromEpochWasCalled = false - assert.Equal(t, testRootHash, rootHash) - return nil - }, - RecreateTrieFromEpochCalled: func(options common.RootHashHolder) error { - recreateTrieWasCalled = false - recreateTrieFromEpochWasCalled = true - assert.Equal(t, testRootHash, options.GetRootHash()) return nil }, diff --git a/process/sync/metablock_test.go b/process/sync/metablock_test.go index fff94e55389..6d183fbf821 100644 --- a/process/sync/metablock_test.go +++ b/process/sync/metablock_test.go @@ -1379,7 +1379,7 @@ func TestMetaBootstrap_RollBackIsEmptyCallRollBackOneBlockOkValsShouldWork(t *te } args.ForkDetector = createForkDetector(currentHdrNonce, currentHdrHash, remFlags) args.Accounts = &stateMock.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, } @@ -1520,7 +1520,7 @@ func TestMetaBootstrap_RollBackIsEmptyCallRollBackOneBlockToGenesisShouldWork(t } args.ForkDetector = createForkDetector(currentHdrNonce, currentHdrHash, remFlags) args.Accounts = &stateMock.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, } diff --git a/process/sync/shardblock_test.go b/process/sync/shardblock_test.go index 8abfd29e6bc..070b926df0f 100644 --- a/process/sync/shardblock_test.go +++ b/process/sync/shardblock_test.go @@ -1525,7 +1525,7 @@ func TestBootstrap_RollBackIsEmptyCallRollBackOneBlockOkValsShouldWork(t *testin } args.ForkDetector = createForkDetector(currentHdrNonce, currentHdrHash, remFlags) args.Accounts = &stateMock.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, } @@ -1668,7 +1668,7 @@ func TestBootstrap_RollbackIsEmptyCallRollBackOneBlockToGenesisShouldWork(t *tes } args.ForkDetector = createForkDetector(currentHdrNonce, currentHdrHash, remFlags) args.Accounts = &stateMock.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return nil }, } diff --git a/process/transactionEvaluator/simulationAccountsDB.go b/process/transactionEvaluator/simulationAccountsDB.go index 25af794e196..8ba32e95801 100644 --- a/process/transactionEvaluator/simulationAccountsDB.go +++ b/process/transactionEvaluator/simulationAccountsDB.go @@ -121,12 +121,7 @@ func (r *simulationAccountsDB) RootHash() ([]byte, error) { } // RecreateTrie won't do anything as write operations are disabled on this component -func (r *simulationAccountsDB) RecreateTrie(_ []byte) error { - return nil -} - -// RecreateTrieFromEpoch won't do anything as write operations are disabled on this component -func (r *simulationAccountsDB) RecreateTrieFromEpoch(_ common.RootHashHolder) error { +func (r *simulationAccountsDB) RecreateTrie(_ common.RootHashHolder) error { return nil } diff --git a/process/transactionEvaluator/simulationAccountsDB_test.go b/process/transactionEvaluator/simulationAccountsDB_test.go index 7bb474269f3..fa709a51637 100644 --- a/process/transactionEvaluator/simulationAccountsDB_test.go +++ b/process/transactionEvaluator/simulationAccountsDB_test.go @@ -52,7 +52,7 @@ func TestReadOnlyAccountsDB_WriteOperationsShouldNotCalled(t *testing.T) { t.Errorf(failErrMsg) return nil }, - RecreateTrieCalled: func(_ []byte) error { + RecreateTrieCalled: func(_ common.RootHashHolder) error { t.Errorf(failErrMsg) return nil }, diff --git a/state/accountsDB.go b/state/accountsDB.go index bc41d151da1..598f4e8e341 100644 --- a/state/accountsDB.go +++ b/state/accountsDB.go @@ -461,7 +461,8 @@ func (adb *AccountsDB) loadDataTrieConcurrentSafe(accountHandler baseAccountHand return nil } - dataTrie, err := mainTrie.Recreate(accountHandler.GetRootHash()) + rootHashHolder := holders.NewDefaultRootHashesHolder(accountHandler.GetRootHash()) + dataTrie, err := mainTrie.Recreate(rootHashHolder) if err != nil { return fmt.Errorf("trie was not found for hash, rootHash = %s, err = %w", hex.EncodeToString(accountHandler.GetRootHash()), err) } @@ -586,7 +587,8 @@ func (adb *AccountsDB) removeDataTrie(baseAcc baseAccountHandler) error { return nil } - dataTrie, err := adb.mainTrie.Recreate(rootHash) + rootHashHolder := holders.NewDefaultRootHashesHolder(rootHash) + dataTrie, err := adb.mainTrie.Recreate(rootHashHolder) if err != nil { return err } @@ -775,7 +777,7 @@ func (adb *AccountsDB) RevertToSnapshot(snapshot int) error { if snapshot == 0 { log.Trace("revert snapshot to adb.lastRootHash", "hash", adb.lastRootHash) - return adb.recreateTrie(holders.NewRootHashHolder(adb.lastRootHash, core.OptionalUint32{})) + return adb.recreateTrie(holders.NewDefaultRootHashesHolder(adb.lastRootHash)) } for i := len(adb.entries) - 1; i >= snapshot; i-- { @@ -934,13 +936,8 @@ func (adb *AccountsDB) RootHash() ([]byte, error) { return rootHash, err } -// RecreateTrie is used to reload the trie based on an existing rootHash -func (adb *AccountsDB) RecreateTrie(rootHash []byte) error { - return adb.RecreateTrieFromEpoch(holders.NewRootHashHolder(rootHash, core.OptionalUint32{})) -} - -// RecreateTrieFromEpoch is used to reload the trie based on the provided options -func (adb *AccountsDB) RecreateTrieFromEpoch(options common.RootHashHolder) error { +// RecreateTrie is used to reload the trie based on the provided options +func (adb *AccountsDB) RecreateTrie(options common.RootHashHolder) error { adb.mutOp.Lock() defer adb.mutOp.Unlock() @@ -962,7 +959,7 @@ func (adb *AccountsDB) recreateTrie(options common.RootHashHolder) error { adb.obsoleteDataTrieHashes = make(map[string][][]byte) adb.dataTries.Reset() adb.entries = make([]JournalEntry, 0) - newTrie, err := adb.mainTrie.RecreateFromEpoch(options) + newTrie, err := adb.mainTrie.Recreate(options) if err != nil { return err } @@ -1008,7 +1005,8 @@ func (adb *AccountsDB) RecreateAllTries(rootHash []byte) (map[string]common.Trie userAccountRootHash := userAccount.GetRootHash() if len(userAccountRootHash) > 0 { - dataTrie, errRecreate := mainTrie.Recreate(userAccountRootHash) + rootHashHolder := holders.NewDefaultRootHashesHolder(userAccountRootHash) + dataTrie, errRecreate := mainTrie.Recreate(rootHashHolder) if errRecreate != nil { return nil, errRecreate } @@ -1046,7 +1044,8 @@ func getUserAccountFromBytes(accountFactory AccountFactory, marshaller marshal.M } func (adb *AccountsDB) recreateMainTrie(rootHash []byte) (map[string]common.Trie, error) { - recreatedTrie, err := adb.getMainTrie().Recreate(rootHash) + rootHashHolder := holders.NewDefaultRootHashesHolder(rootHash) + recreatedTrie, err := adb.getMainTrie().Recreate(rootHashHolder) if err != nil { return nil, err } @@ -1059,7 +1058,8 @@ func (adb *AccountsDB) recreateMainTrie(rootHash []byte) (map[string]common.Trie // GetTrie returns the trie that has the given rootHash func (adb *AccountsDB) GetTrie(rootHash []byte) (common.Trie, error) { - return adb.getMainTrie().Recreate(rootHash) + rootHashHolder := holders.NewDefaultRootHashesHolder(rootHash) + return adb.getMainTrie().Recreate(rootHashHolder) } // Journalize adds a new object to entries list. diff --git a/state/accountsDBApi.go b/state/accountsDBApi.go index 791bfc658df..b9408d1cd1e 100644 --- a/state/accountsDBApi.go +++ b/state/accountsDBApi.go @@ -63,7 +63,8 @@ func (accountsDB *accountsDBApi) doRecreateTrieWithBlockInfo(newBlockInfo common return currentBlockInfo, nil } - err := accountsDB.innerAccountsAdapter.RecreateTrie(newBlockInfo.GetRootHash()) + rootHashHolder := holders.NewDefaultRootHashesHolder(newBlockInfo.GetRootHash()) + err := accountsDB.innerAccountsAdapter.RecreateTrie(rootHashHolder) if err != nil { accountsDB.blockInfo = nil return nil, err @@ -164,14 +165,8 @@ func (accountsDB *accountsDBApi) RootHash() ([]byte, error) { return blockInfo.GetRootHash(), nil } -// RecreateTrie is used to reload the trie based on an existing rootHash -func (accountsDB *accountsDBApi) RecreateTrie(rootHash []byte) error { - _, err := accountsDB.doRecreateTrieWithBlockInfo(holders.NewBlockInfo([]byte{}, 0, rootHash)) - return err -} - -// RecreateTrieFromEpoch is a not permitted operation in this implementation and thus, will return an error -func (accountsDB *accountsDBApi) RecreateTrieFromEpoch(options common.RootHashHolder) error { +// RecreateTrie is a not permitted operation in this implementation and thus, will return an error +func (accountsDB *accountsDBApi) RecreateTrie(options common.RootHashHolder) error { accountsDB.mutRecreatedTrieBlockInfo.Lock() defer accountsDB.mutRecreatedTrieBlockInfo.Unlock() @@ -184,7 +179,7 @@ func (accountsDB *accountsDBApi) RecreateTrieFromEpoch(options common.RootHashHo return nil } - err := accountsDB.innerAccountsAdapter.RecreateTrieFromEpoch(options) + err := accountsDB.innerAccountsAdapter.RecreateTrie(options) if err != nil { accountsDB.blockInfo = nil return err diff --git a/state/accountsDBApiWithHistory.go b/state/accountsDBApiWithHistory.go index 97d698e0b68..8870dac094b 100644 --- a/state/accountsDBApiWithHistory.go +++ b/state/accountsDBApiWithHistory.go @@ -94,12 +94,7 @@ func (accountsDB *accountsDBApiWithHistory) RootHash() ([]byte, error) { } // RecreateTrie is a not permitted operation in this implementation and thus, will return an error -func (accountsDB *accountsDBApiWithHistory) RecreateTrie(_ []byte) error { - return ErrOperationNotPermitted -} - -// RecreateTrieFromEpoch is a not permitted operation in this implementation and thus, will return an error -func (accountsDB *accountsDBApiWithHistory) RecreateTrieFromEpoch(_ common.RootHashHolder) error { +func (accountsDB *accountsDBApiWithHistory) RecreateTrie(_ common.RootHashHolder) error { return ErrOperationNotPermitted } @@ -232,7 +227,7 @@ func (accountsDB *accountsDBApiWithHistory) shouldRecreateTrieUnprotected(rootHa } func (accountsDB *accountsDBApiWithHistory) recreateTrieUnprotected(options common.RootHashHolder) error { - err := accountsDB.innerAccountsAdapter.RecreateTrieFromEpoch(options) + err := accountsDB.innerAccountsAdapter.RecreateTrie(options) if err != nil { return err } diff --git a/state/accountsDBApiWithHistory_test.go b/state/accountsDBApiWithHistory_test.go index beb7ad371bb..982f822092a 100644 --- a/state/accountsDBApiWithHistory_test.go +++ b/state/accountsDBApiWithHistory_test.go @@ -8,7 +8,6 @@ import ( "sync" "testing" - "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/atomic" "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-go/common" @@ -100,14 +99,14 @@ func TestAccountsDBApiWithHistory_NotPermittedOrNotImplementedOperationsDoNotPan func TestAccountsDBApiWithHistory_GetAccountWithBlockInfo(t *testing.T) { rootHash := []byte("rootHash") - options := holders.NewRootHashHolder(rootHash, core.OptionalUint32{}) + options := holders.NewDefaultRootHashesHolder(rootHash) arbitraryError := errors.New("arbitrary error") t.Run("recreate trie fails", func(t *testing.T) { expectedErr := errors.New("expected error") accountsAdapter := &mockState.AccountsStub{ - RecreateTrieFromEpochCalled: func(_ common.RootHashHolder) error { + RecreateTrieCalled: func(_ common.RootHashHolder) error { return expectedErr }, } @@ -123,7 +122,7 @@ func TestAccountsDBApiWithHistory_GetAccountWithBlockInfo(t *testing.T) { var recreatedRootHash []byte accountsAdapter := &mockState.AccountsStub{ - RecreateTrieFromEpochCalled: func(options common.RootHashHolder) error { + RecreateTrieCalled: func(options common.RootHashHolder) error { recreatedRootHash = options.GetRootHash() return nil }, @@ -148,7 +147,7 @@ func TestAccountsDBApiWithHistory_GetAccountWithBlockInfo(t *testing.T) { var recreatedRootHash []byte accountsAdapter := &mockState.AccountsStub{ - RecreateTrieFromEpochCalled: func(options common.RootHashHolder) error { + RecreateTrieCalled: func(options common.RootHashHolder) error { recreatedRootHash = options.GetRootHash() return nil }, @@ -169,7 +168,7 @@ func TestAccountsDBApiWithHistory_GetAccountWithBlockInfo(t *testing.T) { var recreatedRootHash []byte accountsAdapter := &mockState.AccountsStub{ - RecreateTrieFromEpochCalled: func(options common.RootHashHolder) error { + RecreateTrieCalled: func(options common.RootHashHolder) error { recreatedRootHash = options.GetRootHash() return nil }, @@ -190,13 +189,13 @@ func TestAccountsDBApiWithHistory_GetAccountWithBlockInfo(t *testing.T) { func TestAccountsDBApiWithHistory_GetCodeWithBlockInfo(t *testing.T) { contractCodeHash := []byte("codeHash") rootHash := []byte("rootHash") - options := holders.NewRootHashHolder(rootHash, core.OptionalUint32{}) + options := holders.NewDefaultRootHashesHolder(rootHash) t.Run("recreate trie fails", func(t *testing.T) { expectedErr := errors.New("expected error") accountsAdapter := &mockState.AccountsStub{ - RecreateTrieFromEpochCalled: func(_ common.RootHashHolder) error { + RecreateTrieCalled: func(_ common.RootHashHolder) error { return expectedErr }, } @@ -212,7 +211,7 @@ func TestAccountsDBApiWithHistory_GetCodeWithBlockInfo(t *testing.T) { var recreatedRootHash []byte accountsAdapter := &mockState.AccountsStub{ - RecreateTrieFromEpochCalled: func(options common.RootHashHolder) error { + RecreateTrieCalled: func(options common.RootHashHolder) error { recreatedRootHash = options.GetRootHash() return nil }, @@ -250,7 +249,7 @@ func TestAccountsDBApiWithHistory_GetAccountWithBlockInfoWhenHighConcurrency(t * var dummyAccountMutex sync.RWMutex accountsAdapter := &mockState.AccountsStub{ - RecreateTrieFromEpochCalled: func(options common.RootHashHolder) error { + RecreateTrieCalled: func(options common.RootHashHolder) error { rootHash := options.GetRootHash() dummyAccountMutex.Lock() @@ -284,7 +283,7 @@ func TestAccountsDBApiWithHistory_GetAccountWithBlockInfoWhenHighConcurrency(t * go func(rootHashAsInt int) { rootHashAsString := fmt.Sprintf("%d", rootHashAsInt) rootHash := []byte(rootHashAsString) - options := holders.NewRootHashHolder(rootHash, core.OptionalUint32{}) + options := holders.NewDefaultRootHashesHolder(rootHash) account, blockInfo, _ := accountsApiWithHistory.GetAccountWithBlockInfo([]byte("address"), options) userAccount := account.(state.UserAccountHandler) diff --git a/state/accountsDBApi_test.go b/state/accountsDBApi_test.go index 1a22366ab06..fd56c05bedb 100644 --- a/state/accountsDBApi_test.go +++ b/state/accountsDBApi_test.go @@ -71,7 +71,7 @@ func TestAccountsDBAPi_recreateTrieIfNecessary(t *testing.T) { t.Parallel() accountsAdapter := &mockState.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { require.Fail(t, "should have not called RecreateAllTriesCalled") return nil @@ -109,7 +109,7 @@ func TestAccountsDBAPi_recreateTrieIfNecessary(t *testing.T) { t.Parallel() accountsAdapter := &mockState.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { require.Fail(t, "should have not called RecreateAllTriesCalled") return nil @@ -126,7 +126,7 @@ func TestAccountsDBAPi_recreateTrieIfNecessary(t *testing.T) { oldRootHash := []byte("old root hash") accountsAdapter := &mockState.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { assert.Equal(t, rootHash, rootHash) return nil @@ -146,7 +146,7 @@ func TestAccountsDBAPi_recreateTrieIfNecessary(t *testing.T) { oldRootHash := []byte("old root hash") accountsAdapter := &mockState.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { assert.Equal(t, rootHash, rootHash) return expectedErr @@ -169,7 +169,7 @@ func TestAccountsDBAPi_doRecreateTrieWhenReEntranceHappened(t *testing.T) { targetRootHash := []byte("root hash") numCalled := 0 accountsAdapter := &mockState.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { numCalled++ return nil }, @@ -215,13 +215,13 @@ func TestAccountsDBApi_RecreateTrie(t *testing.T) { wasCalled := false accountsApi, _ := state.NewAccountsDBApi(&mockState.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { wasCalled = true return nil }, }, createBlockInfoProviderStub(dummyRootHash)) - err := accountsApi.RecreateTrie(nil) + err := accountsApi.RecreateTrie(holders.NewDefaultRootHashesHolder([]byte{})) assert.NoError(t, err) assert.True(t, wasCalled) } @@ -231,14 +231,14 @@ func TestAccountsDBApi_RecreateTrieFromEpoch(t *testing.T) { t.Run("should error if the roothash holder is nil", func(t *testing.T) { accountsApi, _ := state.NewAccountsDBApi(&mockState.AccountsStub{ - RecreateTrieFromEpochCalled: func(options common.RootHashHolder) error { + RecreateTrieCalled: func(options common.RootHashHolder) error { assert.Fail(t, "should have not called accountsApi.RecreateTrieFromEpochCalled") return nil }, }, createBlockInfoProviderStub(dummyRootHash)) - err := accountsApi.RecreateTrieFromEpoch(nil) + err := accountsApi.RecreateTrie(nil) assert.Equal(t, trie.ErrNilRootHashHolder, err) }) t.Run("should work", func(t *testing.T) { @@ -246,7 +246,7 @@ func TestAccountsDBApi_RecreateTrieFromEpoch(t *testing.T) { rootHash := []byte("root hash") epoch := core.OptionalUint32{Value: 37, HasValue: true} accountsApi, _ := state.NewAccountsDBApi(&mockState.AccountsStub{ - RecreateTrieFromEpochCalled: func(options common.RootHashHolder) error { + RecreateTrieCalled: func(options common.RootHashHolder) error { wasCalled = true assert.Equal(t, rootHash, options.GetRootHash()) assert.Equal(t, epoch, options.GetEpoch()) @@ -255,7 +255,7 @@ func TestAccountsDBApi_RecreateTrieFromEpoch(t *testing.T) { }, createBlockInfoProviderStub(dummyRootHash)) holder := holders.NewRootHashHolder(rootHash, epoch) - err := accountsApi.RecreateTrieFromEpoch(holder) + err := accountsApi.RecreateTrie(holder) assert.NoError(t, err) assert.True(t, wasCalled) }) @@ -289,7 +289,7 @@ func TestAccountsDBApi_SimpleProxyMethodsShouldWork(t *testing.T) { closeCalled := false getTrieCalled := false accountsAdapter := &mockState.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { require.Fail(t, "should have not called RecreateTrieCalled") return nil @@ -336,7 +336,7 @@ func TestAccountsDBApi_GetExistingAccount(t *testing.T) { t.Parallel() accountsAdapter := &mockState.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return expectedErr }, GetExistingAccountCalled: func(addressContainer []byte) (vmcommon.AccountHandler, error) { @@ -355,7 +355,7 @@ func TestAccountsDBApi_GetExistingAccount(t *testing.T) { recreateTrieCalled := false accountsAdapter := &mockState.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { recreateTrieCalled = true return nil }, @@ -380,7 +380,7 @@ func TestAccountsDBApi_GetAccountFromBytes(t *testing.T) { t.Parallel() accountsAdapter := &mockState.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return expectedErr }, GetAccountFromBytesCalled: func(address []byte, accountBytes []byte) (vmcommon.AccountHandler, error) { @@ -399,7 +399,7 @@ func TestAccountsDBApi_GetAccountFromBytes(t *testing.T) { recreateTrieCalled := false accountsAdapter := &mockState.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { recreateTrieCalled = true return nil }, @@ -424,7 +424,7 @@ func TestAccountsDBApi_LoadAccount(t *testing.T) { t.Parallel() accountsAdapter := &mockState.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return expectedErr }, LoadAccountCalled: func(address []byte) (vmcommon.AccountHandler, error) { @@ -443,7 +443,7 @@ func TestAccountsDBApi_LoadAccount(t *testing.T) { recreateTrieCalled := false accountsAdapter := &mockState.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { recreateTrieCalled = true return nil }, @@ -468,7 +468,7 @@ func TestAccountsDBApi_GetCode(t *testing.T) { t.Parallel() accountsAdapter := &mockState.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return expectedErr }, GetCodeCalled: func(codeHash []byte) []byte { @@ -487,7 +487,7 @@ func TestAccountsDBApi_GetCode(t *testing.T) { providedCode := []byte("code") recreateTrieCalled := false accountsAdapter := &mockState.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { recreateTrieCalled = true return nil }, @@ -511,7 +511,7 @@ func TestAccountsDBApi_GetAllLeaves(t *testing.T) { t.Parallel() accountsAdapter := &mockState.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { return expectedErr }, GetAllLeavesCalled: func(_ *common.TrieIteratorChannels, _ context.Context, _ []byte, _ common.TrieLeafParser) error { @@ -530,7 +530,7 @@ func TestAccountsDBApi_GetAllLeaves(t *testing.T) { providedChan := &common.TrieIteratorChannels{LeavesChan: make(chan core.KeyValueHolder)} recreateTrieCalled := false accountsAdapter := &mockState.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { recreateTrieCalled = true return nil }, @@ -555,13 +555,13 @@ func TestAccountsDBApi_GetAccountWithBlockInfoWhenHighConcurrency(t *testing.T) var currentBlockInfoMutex sync.RWMutex accountsAdapter := &mockState.AccountsStub{ - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(rootHash common.RootHashHolder) error { dummyAccountMutex.Lock() defer dummyAccountMutex.Unlock() // When a trie is recreated, we "add" to it a single account, // having the balance correlated with the trie rootHash (for the sake of the test, for easier assertions). - dummyAccount = createDummyAccountWithBalanceBytes(rootHash) + dummyAccount = createDummyAccountWithBalanceBytes(rootHash.GetRootHash()) return nil }, GetExistingAccountCalled: func(addressContainer []byte) (vmcommon.AccountHandler, error) { diff --git a/state/accountsDB_test.go b/state/accountsDB_test.go index 95785e9c231..fda69b8cfcf 100644 --- a/state/accountsDB_test.go +++ b/state/accountsDB_test.go @@ -510,7 +510,7 @@ func TestAccountsDB_LoadAccountExistingShouldLoadDataTrie(t *testing.T) { } return nil, 0, nil }, - RecreateCalled: func(root []byte) (d common.Trie, err error) { + RecreateCalled: func(holder common.RootHashHolder) (d common.Trie, err error) { return dataTrie, nil }, GetStorageManagerCalled: func() common.StorageManager { @@ -588,7 +588,7 @@ func TestAccountsDB_GetExistingAccountFoundShouldRetAccount(t *testing.T) { } return nil, 0, nil }, - RecreateCalled: func(root []byte) (d common.Trie, err error) { + RecreateCalled: func(root common.RootHashHolder) (d common.Trie, err error) { return dataTrie, nil }, GetStorageManagerCalled: func() common.StorageManager { @@ -811,8 +811,8 @@ func TestAccountsDB_LoadDataWithSomeValuesShouldWork(t *testing.T) { account := generateAccount() mockTrie := &trieMock.TrieStub{ - RecreateCalled: func(root []byte) (trie common.Trie, e error) { - if !bytes.Equal(root, rootHash) { + RecreateCalled: func(root common.RootHashHolder) (trie common.Trie, e error) { + if !bytes.Equal(root.GetRootHash(), rootHash) { return nil, errors.New("bad root hash") } @@ -856,7 +856,7 @@ func TestAccountsDB_CommitShouldCallCommitFromTrie(t *testing.T) { GetCalled: func(_ []byte) ([]byte, uint32, error) { return serializedAccount, 0, nil }, - RecreateCalled: func(root []byte) (trie common.Trie, err error) { + RecreateCalled: func(root common.RootHashHolder) (trie common.Trie, err error) { return &trieMock.TrieStub{ GetCalled: func(_ []byte) ([]byte, uint32, error) { return []byte("doge"), 0, nil @@ -904,14 +904,14 @@ func TestAccountsDB_RecreateTrieMalfunctionTrieShouldErr(t *testing.T) { return &storageManager.StorageManagerStub{} }, } - trieStub.RecreateFromEpochCalled = func(_ common.RootHashHolder) (tree common.Trie, e error) { + trieStub.RecreateCalled = func(_ common.RootHashHolder) (tree common.Trie, e error) { wasCalled = true return nil, errExpected } adb := generateAccountDBFromTrie(trieStub) - err := adb.RecreateTrie(nil) + err := adb.RecreateTrie(holders.NewDefaultRootHashesHolder([]byte{})) assert.Equal(t, errExpected, err) assert.True(t, wasCalled) } @@ -926,13 +926,13 @@ func TestAccountsDB_RecreateTrieOutputsNilTrieShouldErr(t *testing.T) { return &storageManager.StorageManagerStub{} }, } - trieStub.RecreateFromEpochCalled = func(_ common.RootHashHolder) (tree common.Trie, e error) { + trieStub.RecreateCalled = func(_ common.RootHashHolder) (tree common.Trie, e error) { wasCalled = true return nil, nil } adb := generateAccountDBFromTrie(&trieStub) - err := adb.RecreateTrie(nil) + err := adb.RecreateTrie(holders.NewDefaultRootHashesHolder([]byte{})) assert.Equal(t, state.ErrNilTrie, err) assert.True(t, wasCalled) @@ -948,14 +948,14 @@ func TestAccountsDB_RecreateTrieOkValsShouldWork(t *testing.T) { GetStorageManagerCalled: func() common.StorageManager { return &storageManager.StorageManagerStub{} }, - RecreateFromEpochCalled: func(_ common.RootHashHolder) (common.Trie, error) { + RecreateCalled: func(_ common.RootHashHolder) (common.Trie, error) { wasCalled = true return &trieMock.TrieStub{}, nil }, } adb := generateAccountDBFromTrie(&trieStub) - err := adb.RecreateTrie(nil) + err := adb.RecreateTrie(holders.NewDefaultRootHashesHolder([]byte{})) assert.Nil(t, err) assert.True(t, wasCalled) @@ -1466,7 +1466,7 @@ func TestAccountsDB_RecreateTrieInvalidatesJournalEntries(t *testing.T) { _ = adb.SaveAccount(acc) assert.Equal(t, 5, adb.JournalLen()) - err := adb.RecreateTrie(rootHash) + err := adb.RecreateTrie(holders.NewDefaultRootHashesHolder(rootHash)) assert.Nil(t, err) assert.Equal(t, 0, adb.JournalLen()) } @@ -1985,7 +1985,7 @@ func TestAccountsDB_PruningAndPruningCancellingOnTrieRollback(t *testing.T) { } for i := 0; i < len(rootHashes); i++ { - _, err := tr.Recreate(rootHashes[i]) + _, err := tr.Recreate(holders.NewDefaultRootHashesHolder(rootHashes[i])) assert.Nil(t, err) } @@ -1994,7 +1994,7 @@ func TestAccountsDB_PruningAndPruningCancellingOnTrieRollback(t *testing.T) { finalizeTrieState(t, 2, tr, adb, rootHashes) rollbackTrieState(t, 3, tr, adb, rootHashes) - _, err := tr.Recreate(rootHashes[2]) + _, err := tr.Recreate(holders.NewDefaultRootHashesHolder(rootHashes[2])) assert.Nil(t, err) } @@ -2003,7 +2003,7 @@ func finalizeTrieState(t *testing.T, index int, tr common.Trie, adb state.Accoun adb.CancelPrune(rootHashes[index], state.NewRoot) time.Sleep(trieDbOperationDelay) - _, err := tr.Recreate(rootHashes[index-1]) + _, err := tr.Recreate(holders.NewDefaultRootHashesHolder(rootHashes[index-1])) assert.NotNil(t, err) } @@ -2012,7 +2012,7 @@ func rollbackTrieState(t *testing.T, index int, tr common.Trie, adb state.Accoun adb.CancelPrune(rootHashes[index-1], state.OldRoot) time.Sleep(trieDbOperationDelay) - _, err := tr.Recreate(rootHashes[index]) + _, err := tr.Recreate(holders.NewDefaultRootHashesHolder(rootHashes[index])) assert.NotNil(t, err) } @@ -2398,7 +2398,7 @@ func TestAccountsDB_RecreateAllTries(t *testing.T) { return nil }, - RecreateCalled: func(root []byte) (common.Trie, error) { + RecreateCalled: func(root common.RootHashHolder) (common.Trie, error) { return &trieMock.TrieStub{}, nil }, } @@ -2426,7 +2426,7 @@ func TestAccountsDB_RecreateAllTries(t *testing.T) { return nil }, - RecreateCalled: func(root []byte) (common.Trie, error) { + RecreateCalled: func(root common.RootHashHolder) (common.Trie, error) { return &trieMock.TrieStub{}, nil }, } @@ -2595,8 +2595,8 @@ func TestAccountsDB_GetAccountFromBytes(t *testing.T) { }, } args.Trie = &trieMock.TrieStub{ - RecreateCalled: func(root []byte) (common.Trie, error) { - assert.Equal(t, rootHash, root) + RecreateCalled: func(root common.RootHashHolder) (common.Trie, error) { + assert.Equal(t, rootHash, root.GetRootHash()) return &trieMock.TrieStub{}, nil }, } @@ -2625,7 +2625,7 @@ func TestAccountsDB_GetAccountFromBytesShouldLoadDataTrie(t *testing.T) { } return nil, 0, nil }, - RecreateCalled: func(root []byte) (d common.Trie, err error) { + RecreateCalled: func(root common.RootHashHolder) (d common.Trie, err error) { return dataTrie, nil }, GetStorageManagerCalled: func() common.StorageManager { @@ -3168,7 +3168,7 @@ func testAccountMethodsConcurrency( assert.Nil(t, err) for i := 0; i < numOperations; i++ { go func(idx int) { - switch idx % 23 { + switch idx % 22 { case 0: _, _ = adb.GetExistingAccount(addresses[idx]) case 1: @@ -3192,28 +3192,26 @@ func testAccountMethodsConcurrency( case 10: _, _ = adb.RootHash() case 11: - _ = adb.RecreateTrie(rootHash) + _ = adb.RecreateTrie(holders.NewDefaultRootHashesHolder(rootHash)) case 12: - _ = adb.RecreateTrieFromEpoch(holders.NewRootHashHolder(rootHash, core.OptionalUint32{})) - case 13: adb.PruneTrie(rootHash, state.OldRoot, state.NewPruningHandler(state.DisableDataRemoval)) - case 14: + case 13: adb.CancelPrune(rootHash, state.NewRoot) - case 15: + case 14: adb.SnapshotState(rootHash, 0) - case 16: + case 15: adb.SetStateCheckpoint(rootHash) - case 17: + case 16: _ = adb.IsPruningEnabled() - case 18: + case 17: _ = adb.GetAllLeaves(&common.TrieIteratorChannels{}, context.Background(), rootHash, parsers.NewMainTrieLeafParser()) - case 19: + case 18: _, _ = adb.RecreateAllTries(rootHash) - case 20: + case 19: _, _ = adb.GetTrie(rootHash) - case 21: + case 20: _ = adb.GetStackDebugFirstEntry() - case 22: + case 21: _ = adb.SetSyncer(&mock.AccountsDBSyncerStub{}) } wg.Done() @@ -3306,7 +3304,7 @@ func testAccountLoadInParallel( case 1: _, _ = adb.GetExistingAccount(addresses[idx]) case 2: - _ = adb.RecreateTrie(rootHash) + _ = adb.RecreateTrie(holders.NewDefaultRootHashesHolder(rootHash)) } }(i) } diff --git a/state/interface.go b/state/interface.go index 56dd0e1b8c4..646b5bed38a 100644 --- a/state/interface.go +++ b/state/interface.go @@ -37,8 +37,7 @@ type AccountsAdapter interface { RevertToSnapshot(snapshot int) error GetCode(codeHash []byte) []byte RootHash() ([]byte, error) - RecreateTrie(rootHash []byte) error - RecreateTrieFromEpoch(options common.RootHashHolder) error + RecreateTrie(options common.RootHashHolder) error PruneTrie(rootHash []byte, identifier TriePruningIdentifier, handler PruningHandler) CancelPrune(rootHash []byte, identifier TriePruningIdentifier) SnapshotState(rootHash []byte, epoch uint32) @@ -183,7 +182,8 @@ type DataTrie interface { } // PeerAccountHandler models a peer state account, which can journalize a normal account's data -// with some extra features like signing statistics or rating information +// +// with some extra features like signing statistics or rating information type PeerAccountHandler interface { SetBLSPublicKey([]byte) error GetRewardAddress() []byte diff --git a/state/peerAccountsDB_test.go b/state/peerAccountsDB_test.go index 65beb8432dd..2e2076f4a0b 100644 --- a/state/peerAccountsDB_test.go +++ b/state/peerAccountsDB_test.go @@ -187,7 +187,7 @@ func TestNewPeerAccountsDB_RecreateAllTries(t *testing.T) { GetStorageManagerCalled: func() common.StorageManager { return &storageManager.StorageManagerStub{} }, - RecreateCalled: func(_ []byte) (common.Trie, error) { + RecreateCalled: func(_ common.RootHashHolder) (common.Trie, error) { recreateCalled = true return nil, nil }, diff --git a/state/storagePruningManager/storagePruningManager_test.go b/state/storagePruningManager/storagePruningManager_test.go index 104a198becd..338535fd0b7 100644 --- a/state/storagePruningManager/storagePruningManager_test.go +++ b/state/storagePruningManager/storagePruningManager_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/common/holders" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/state/factory" @@ -212,7 +213,7 @@ func TestAccountsDB_PruneAfterCancelPruneShouldFail(t *testing.T) { spm.CancelPrune(rootHash, state.OldRoot, trieStorage) spm.PruneTrie(rootHash, state.OldRoot, trieStorage, state.NewPruningHandler(state.EnableDataRemoval)) - newTr, err := tr.Recreate(rootHash) + newTr, err := tr.Recreate(holders.NewDefaultRootHashesHolder(rootHash)) assert.Nil(t, err) assert.NotNil(t, newTr) } diff --git a/state/syncer/baseAccountsSyncer.go b/state/syncer/baseAccountsSyncer.go index a01f1155fed..452534a1d92 100644 --- a/state/syncer/baseAccountsSyncer.go +++ b/state/syncer/baseAccountsSyncer.go @@ -3,6 +3,7 @@ package syncer import ( "context" "fmt" + "github.com/multiversx/mx-chain-go/common/holders" "sync" "sync/atomic" "time" @@ -224,7 +225,8 @@ func (b *baseAccountsSyncer) GetSyncedTries() map[string]common.Trie { var recreatedTrie common.Trie clonedMap := make(map[string]common.Trie, len(b.dataTries)) for key := range b.dataTries { - recreatedTrie, err = dataTrie.Recreate([]byte(key)) + rootHashHolder := holders.NewDefaultRootHashesHolder([]byte(key)) + recreatedTrie, err = dataTrie.Recreate(rootHashHolder) if err != nil { log.Warn("error recreating trie in baseAccountsSyncer.GetSyncedTries", "roothash", []byte(key), "error", err) diff --git a/state/trackableDataTrie/trackableDataTrie.go b/state/trackableDataTrie/trackableDataTrie.go index 8a2fe8812ef..08131e22899 100644 --- a/state/trackableDataTrie/trackableDataTrie.go +++ b/state/trackableDataTrie/trackableDataTrie.go @@ -2,6 +2,7 @@ package trackableDataTrie import ( "fmt" + "github.com/multiversx/mx-chain-go/common/holders" "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" @@ -208,7 +209,8 @@ func (tdt *trackableDataTrie) SaveDirtyData(mainTrie common.Trie) ([]core.TrieDa } if check.IfNil(tdt.tr) { - newDataTrie, err := mainTrie.Recreate(make([]byte, 0)) + emptyRootHash := holders.NewDefaultRootHashesHolder(make([]byte, 0)) + newDataTrie, err := mainTrie.Recreate(emptyRootHash) if err != nil { return nil, err } diff --git a/state/trackableDataTrie/trackableDataTrie_test.go b/state/trackableDataTrie/trackableDataTrie_test.go index 42f6ebc4189..5c67328dd38 100644 --- a/state/trackableDataTrie/trackableDataTrie_test.go +++ b/state/trackableDataTrie/trackableDataTrie_test.go @@ -345,7 +345,7 @@ func TestTrackableDataTrie_SaveDirtyData(t *testing.T) { recreateCalled := false trie := &trieMock.TrieStub{ - RecreateCalled: func(root []byte) (common.Trie, error) { + RecreateCalled: func(root common.RootHashHolder) (common.Trie, error) { recreateCalled = true return &trieMock.TrieStub{ GetCalled: func(_ []byte) ([]byte, uint32, error) { diff --git a/testscommon/state/accountsAdapterStub.go b/testscommon/state/accountsAdapterStub.go index c5cf9f74535..f20d6401d9e 100644 --- a/testscommon/state/accountsAdapterStub.go +++ b/testscommon/state/accountsAdapterStub.go @@ -23,8 +23,7 @@ type AccountsStub struct { JournalLenCalled func() int RevertToSnapshotCalled func(snapshot int) error RootHashCalled func() ([]byte, error) - RecreateTrieCalled func(rootHash []byte) error - RecreateTrieFromEpochCalled func(options common.RootHashHolder) error + RecreateTrieCalled func(options common.RootHashHolder) error PruneTrieCalled func(rootHash []byte, identifier state.TriePruningIdentifier, handler state.PruningHandler) CancelPruneCalled func(rootHash []byte, identifier state.TriePruningIdentifier) SnapshotStateCalled func(rootHash []byte, epoch uint32) @@ -177,18 +176,9 @@ func (as *AccountsStub) RootHash() ([]byte, error) { } // RecreateTrie - -func (as *AccountsStub) RecreateTrie(rootHash []byte) error { +func (as *AccountsStub) RecreateTrie(options common.RootHashHolder) error { if as.RecreateTrieCalled != nil { - return as.RecreateTrieCalled(rootHash) - } - - return errNotImplemented -} - -// RecreateTrieFromEpoch - -func (as *AccountsStub) RecreateTrieFromEpoch(options common.RootHashHolder) error { - if as.RecreateTrieFromEpochCalled != nil { - return as.RecreateTrieFromEpochCalled(options) + return as.RecreateTrieCalled(options) } return errNotImplemented diff --git a/testscommon/trie/trieStub.go b/testscommon/trie/trieStub.go index 81c90867e92..30e0ba6066e 100644 --- a/testscommon/trie/trieStub.go +++ b/testscommon/trie/trieStub.go @@ -19,8 +19,7 @@ type TrieStub struct { DeleteCalled func(key []byte) error RootCalled func() ([]byte, error) CommitCalled func() error - RecreateCalled func(root []byte) (common.Trie, error) - RecreateFromEpochCalled func(options common.RootHashHolder) (common.Trie, error) + RecreateCalled func(options common.RootHashHolder) (common.Trie, error) GetObsoleteHashesCalled func() [][]byte AppendToOldHashesCalled func([][]byte) GetSerializedNodesCalled func([]byte, uint64) ([][]byte, uint64, error) @@ -136,18 +135,9 @@ func (ts *TrieStub) Commit() error { } // Recreate - -func (ts *TrieStub) Recreate(root []byte) (common.Trie, error) { +func (ts *TrieStub) Recreate(options common.RootHashHolder) (common.Trie, error) { if ts.RecreateCalled != nil { - return ts.RecreateCalled(root) - } - - return nil, errNotImplemented -} - -// RecreateFromEpoch - -func (ts *TrieStub) RecreateFromEpoch(options common.RootHashHolder) (common.Trie, error) { - if ts.RecreateFromEpochCalled != nil { - return ts.RecreateFromEpochCalled(options) + return ts.RecreateCalled(options) } return nil, errNotImplemented diff --git a/trie/depthFirstSync_test.go b/trie/depthFirstSync_test.go index 456c1b1f3e8..409c618a2c6 100644 --- a/trie/depthFirstSync_test.go +++ b/trie/depthFirstSync_test.go @@ -11,6 +11,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/common/holders" "github.com/multiversx/mx-chain-go/storage" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -121,7 +122,7 @@ func TestDepthFirstTrieSyncer_StartSyncingNewTrieShouldWork(t *testing.T) { tsm, _ := arg.DB.(*trieStorageManager) db, _ := tsm.mainStorer.(storage.Persister) trie, _ := createInMemoryTrieFromDB(db) - trie, _ = trie.Recreate(roothash) + trie, _ = trie.Recreate(holders.NewDefaultRootHashesHolder(roothash)) require.False(t, check.IfNil(trie)) var val []byte @@ -198,7 +199,7 @@ func TestDepthFirstTrieSyncer_StartSyncingPartiallyFilledTrieShouldWork(t *testi tsm, _ := arg.DB.(*trieStorageManager) db, _ := tsm.mainStorer.(storage.Persister) trie, _ := createInMemoryTrieFromDB(db) - trie, _ = trie.Recreate(roothash) + trie, _ = trie.Recreate(holders.NewDefaultRootHashesHolder(roothash)) require.False(t, check.IfNil(trie)) var val []byte diff --git a/trie/doubleListSync_test.go b/trie/doubleListSync_test.go index 65197f171fc..94113a25fd0 100644 --- a/trie/doubleListSync_test.go +++ b/trie/doubleListSync_test.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "fmt" + "github.com/multiversx/mx-chain-go/common/holders" "sync" "testing" "time" @@ -213,7 +214,7 @@ func TestDoubleListTrieSyncer_StartSyncingNewTrieShouldWork(t *testing.T) { tsm, _ := arg.DB.(*trieStorageManager) db, _ := tsm.mainStorer.(storage.Persister) trie, _ := createInMemoryTrieFromDB(db) - trie, _ = trie.Recreate(roothash) + trie, _ = trie.Recreate(holders.NewDefaultRootHashesHolder(roothash)) require.False(t, check.IfNil(trie)) var val []byte @@ -290,7 +291,7 @@ func TestDoubleListTrieSyncer_StartSyncingPartiallyFilledTrieShouldWork(t *testi tsm, _ := arg.DB.(*trieStorageManager) db, _ := tsm.mainStorer.(storage.Persister) trie, _ := createInMemoryTrieFromDB(db) - trie, _ = trie.Recreate(roothash) + trie, _ = trie.Recreate(holders.NewDefaultRootHashesHolder(roothash)) require.False(t, check.IfNil(trie)) var val []byte diff --git a/trie/extensionNode_test.go b/trie/extensionNode_test.go index ac243f3aaff..02030e9d772 100644 --- a/trie/extensionNode_test.go +++ b/trie/extensionNode_test.go @@ -9,6 +9,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/common/holders" "github.com/multiversx/mx-chain-go/storage/cache" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" @@ -732,7 +733,7 @@ func TestExtensionNode_reduceNodeCollapsedNode(t *testing.T) { tr := initTrie() _ = tr.Commit() rootHash, _ := tr.RootHash() - collapsedTrie, _ := tr.Recreate(rootHash) + collapsedTrie, _ := tr.Recreate(holders.NewDefaultRootHashesHolder(rootHash)) err := collapsedTrie.Delete([]byte("doe")) assert.Nil(t, err) diff --git a/trie/patriciaMerkleTrie.go b/trie/patriciaMerkleTrie.go index 0f875999bd1..70df549011f 100644 --- a/trie/patriciaMerkleTrie.go +++ b/trie/patriciaMerkleTrie.go @@ -269,13 +269,8 @@ func (tr *patriciaMerkleTrie) Commit() error { return nil } -// Recreate returns a new trie that has the given root hash and database -func (tr *patriciaMerkleTrie) Recreate(root []byte) (common.Trie, error) { - return tr.recreate(root, tr.trieStorage) -} - -// RecreateFromEpoch returns a new trie, given the options -func (tr *patriciaMerkleTrie) RecreateFromEpoch(options common.RootHashHolder) (common.Trie, error) { +// Recreate returns a new trie, given the options +func (tr *patriciaMerkleTrie) Recreate(options common.RootHashHolder) (common.Trie, error) { if check.IfNil(options) { return nil, ErrNilRootHashHolder } diff --git a/trie/patriciaMerkleTrie_test.go b/trie/patriciaMerkleTrie_test.go index 501539a3e54..7969a952ee2 100644 --- a/trie/patriciaMerkleTrie_test.go +++ b/trie/patriciaMerkleTrie_test.go @@ -389,27 +389,12 @@ func TestPatriciaMerkleTree_DeleteNotPresent(t *testing.T) { func TestPatriciaMerkleTrie_Recreate(t *testing.T) { t.Parallel() - tr := initTrie() - rootHash, _ := tr.RootHash() - _ = tr.Commit() - - newTr, err := tr.Recreate(rootHash) - assert.Nil(t, err) - assert.NotNil(t, newTr) - - root, _ := newTr.RootHash() - assert.Equal(t, rootHash, root) -} - -func TestPatriciaMerkleTrie_RecreateFromEpoch(t *testing.T) { - t.Parallel() - t.Run("nil options", func(t *testing.T) { t.Parallel() tr := initTrie() - newTr, err := tr.RecreateFromEpoch(nil) + newTr, err := tr.Recreate(nil) assert.Nil(t, newTr) assert.Equal(t, trie.ErrNilRootHashHolder, err) }) @@ -421,8 +406,8 @@ func TestPatriciaMerkleTrie_RecreateFromEpoch(t *testing.T) { rootHash, _ := tr.RootHash() _ = tr.Commit() - rootHashHolder := holders.NewRootHashHolder(rootHash, core.OptionalUint32{}) - newTr, err := tr.RecreateFromEpoch(rootHashHolder) + rootHashHolder := holders.NewDefaultRootHashesHolder(rootHash) + newTr, err := tr.Recreate(rootHashHolder) assert.Nil(t, err) assert.True(t, trie.IsBaseTrieStorageManager(newTr.GetStorageManager())) @@ -440,7 +425,7 @@ func TestPatriciaMerkleTrie_RecreateFromEpoch(t *testing.T) { HasValue: true, } rootHashHolder := holders.NewRootHashHolder(rootHash, optionalUint32) - newTr, err := tr.RecreateFromEpoch(rootHashHolder) + newTr, err := tr.Recreate(rootHashHolder) assert.Nil(t, err) assert.True(t, trie.IsTrieStorageManagerInEpoch(newTr.GetStorageManager())) @@ -452,7 +437,7 @@ func TestPatriciaMerkleTrie_RecreateWithInvalidRootHash(t *testing.T) { tr := initTrie() - newTr, err := tr.Recreate(nil) + newTr, err := tr.Recreate(holders.NewDefaultRootHashesHolder([]byte{})) assert.Nil(t, err) root, _ := newTr.RootHash() assert.Equal(t, emptyTrieHash, root) @@ -994,7 +979,7 @@ func TestPatriciaMerkleTrie_ConcurrentOperations(t *testing.T) { numOperations := 1000 wg := sync.WaitGroup{} wg.Add(numOperations) - numFunctions := 19 + numFunctions := 18 initialRootHash, _ := tr.RootHash() @@ -1020,31 +1005,28 @@ func TestPatriciaMerkleTrie_ConcurrentOperations(t *testing.T) { err := tr.Commit() assert.Nil(t, err) case 5: - _, err := tr.Recreate(initialRootHash) - assert.Nil(t, err) - case 6: epoch := core.OptionalUint32{ Value: 3, HasValue: true, } rootHashHolder := holders.NewRootHashHolder(initialRootHash, epoch) - _, err := tr.RecreateFromEpoch(rootHashHolder) + _, err := tr.Recreate(rootHashHolder) assert.Nil(t, err) - case 7: + case 6: _ = tr.String() - case 8: + case 7: _ = tr.GetObsoleteHashes() - case 9: + case 8: _, err := tr.GetDirtyHashes() assert.Nil(t, err) - case 10: + case 9: _, err := tr.GetSerializedNode(initialRootHash) assert.Nil(t, err) - case 11: + case 10: size1KB := uint64(1024 * 1024) _, _, err := tr.GetSerializedNodes(initialRootHash, size1KB) assert.Nil(t, err) - case 12: + case 11: trieIteratorChannels := &common.TrieIteratorChannels{ LeavesChan: make(chan core.KeyValueHolder, 1000), ErrChan: errChan.NewErrChanWrapper(), @@ -1058,20 +1040,20 @@ func TestPatriciaMerkleTrie_ConcurrentOperations(t *testing.T) { parsers.NewMainTrieLeafParser(), ) assert.Nil(t, err) - case 13: + case 12: _, err := tr.GetAllHashes() assert.Nil(t, err) - case 14: + case 13: _, _, _ = tr.GetProof(initialRootHash) // this might error due to concurrent operations that change the roothash - case 15: + case 14: // extremely hard to compute an existing hash due to concurrent changes. _, _ = tr.VerifyProof([]byte("dog"), []byte("puppy"), [][]byte{[]byte("proof1")}) // this might error due to concurrent operations that change the roothash - case 16: + case 15: sm := tr.GetStorageManager() assert.NotNil(t, sm) - case 17: + case 16: _ = tr.GetOldRoot() - case 18: + case 17: trieStatsHandler := tr.(common.TrieStats) _, err := trieStatsHandler.GetTrieStats("address", initialRootHash) assert.Nil(t, err) @@ -1401,7 +1383,7 @@ func TestPatriciaMerkleTrie_CollectLeavesForMigration(t *testing.T) { addDefaultDataToTrie(tr) _ = tr.Commit() rootHash, _ := tr.RootHash() - collapsedTrie, _ := tr.Recreate(rootHash) + collapsedTrie, _ := tr.Recreate(holders.NewDefaultRootHashesHolder(rootHash)) dtr := collapsedTrie.(dataTrie) dtm := &trieMock.DataTrieMigratorStub{ ConsumeStorageLoadGasCalled: func() bool { From d055cae508b93b73e106a9d63753be03718359db Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Wed, 6 Mar 2024 12:35:50 +0200 Subject: [PATCH 082/503] sort imports --- integrationTests/vm/wasm/wasmvm/wasmVM_test.go | 2 +- state/syncer/baseAccountsSyncer.go | 2 +- state/trackableDataTrie/trackableDataTrie.go | 2 +- trie/doubleListSync_test.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/integrationTests/vm/wasm/wasmvm/wasmVM_test.go b/integrationTests/vm/wasm/wasmvm/wasmVM_test.go index b9df8f2a40e..abb475535c8 100644 --- a/integrationTests/vm/wasm/wasmvm/wasmVM_test.go +++ b/integrationTests/vm/wasm/wasmvm/wasmVM_test.go @@ -7,7 +7,6 @@ package wasmvm import ( "encoding/hex" "fmt" - "github.com/multiversx/mx-chain-go/common/holders" "math" "math/big" "testing" @@ -19,6 +18,7 @@ import ( "github.com/multiversx/mx-chain-core-go/hashing/sha256" "github.com/multiversx/mx-chain-core-go/marshal" "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/common/holders" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests" "github.com/multiversx/mx-chain-go/integrationTests/mock" diff --git a/state/syncer/baseAccountsSyncer.go b/state/syncer/baseAccountsSyncer.go index 8ff8e87bef8..3cee93d7325 100644 --- a/state/syncer/baseAccountsSyncer.go +++ b/state/syncer/baseAccountsSyncer.go @@ -3,7 +3,6 @@ package syncer import ( "context" "fmt" - "github.com/multiversx/mx-chain-go/common/holders" "sync" "sync/atomic" "time" @@ -13,6 +12,7 @@ import ( "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/common/holders" "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/trie" diff --git a/state/trackableDataTrie/trackableDataTrie.go b/state/trackableDataTrie/trackableDataTrie.go index 3341377975e..5808e3833e2 100644 --- a/state/trackableDataTrie/trackableDataTrie.go +++ b/state/trackableDataTrie/trackableDataTrie.go @@ -2,7 +2,6 @@ package trackableDataTrie import ( "fmt" - "github.com/multiversx/mx-chain-go/common/holders" "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" @@ -10,6 +9,7 @@ import ( "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/common/holders" errorsCommon "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/state/dataTrieValue" diff --git a/trie/doubleListSync_test.go b/trie/doubleListSync_test.go index b4d8d3a52ce..8e631237cc6 100644 --- a/trie/doubleListSync_test.go +++ b/trie/doubleListSync_test.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "fmt" - "github.com/multiversx/mx-chain-go/common/holders" "sync" "testing" "time" @@ -12,6 +11,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/common/holders" "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/storage/storageunit" "github.com/multiversx/mx-chain-go/testscommon" From 449b4e65b5fbfa72f7d83747093c415173380393 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 6 Mar 2024 15:23:45 +0200 Subject: [PATCH 083/503] new go mod --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 5adfabce1ce..e40d1fc8231 100644 --- a/go.mod +++ b/go.mod @@ -15,14 +15,14 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126150131-2ac5bc749b40 - github.com/multiversx/mx-chain-core-go v1.2.19-0.20240129082057-a76d0c995cf2 + github.com/multiversx/mx-chain-core-go v1.2.19-0.20240130114525-969a1a41a404 github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c - github.com/multiversx/mx-chain-scenario-go v1.3.1-0.20240129145446-ca4fba98f6d1 + github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240129144933-b1c0d642d7f8 - github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240130120052-d8425c5cc419 - github.com/multiversx/mx-chain-vm-go v1.5.27-0.20240130132826-bcb98ba529aa + github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240306131831-1434bb74eb3b + github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240306131314-329c0fcd5ce1 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240129145751-f814f5525edb github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240129150004-536a22d9c618 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.95-0.20240129150215-43996b664ada diff --git a/go.sum b/go.sum index 3bbc0942584..73cfe26209c 100644 --- a/go.sum +++ b/go.sum @@ -385,8 +385,8 @@ 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.13-0.20240126121117-627adccf10ad h1:izxTyKCxvT7z2mhXCWAZibSxwRVgLmq/kDovs4Nx/6Y= -github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad/go.mod h1:n4E8BWIV0g3AcNGe1gf+vcjUC8A2QCJ4ARQSbiUDGrI= +github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126150131-2ac5bc749b40 h1:bMFxkbb1EOQs0+JMM0G0/Kv9v4Jjjla5MSVhVk6scTA= +github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126150131-2ac5bc749b40/go.mod h1:n4E8BWIV0g3AcNGe1gf+vcjUC8A2QCJ4ARQSbiUDGrI= github.com/multiversx/mx-chain-core-go v1.2.19-0.20240130114525-969a1a41a404 h1:6abf4zfA/L2KQM7twd2guVmYPiXWG83yfJUHwuRz/tg= github.com/multiversx/mx-chain-core-go v1.2.19-0.20240130114525-969a1a41a404/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 h1:beVIhs5ysylwNplQ/bZ0h5DoDlqKNWgpWE/NMHHNmAw= @@ -395,14 +395,14 @@ github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d3 github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a/go.mod h1:3aSGRJNvfUuPQkZUGHWuF11rPPxphsKGuAuIB+eD3is= github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c h1:QIUOn8FgNRa5cir4BCWHZi/Qcr6Gg0eGNhns4+jy6+k= github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c/go.mod h1:fH/fR/GEBsDjPkBoZDVJMoYo2HhlA7++DP6QfITJ1N8= -github.com/multiversx/mx-chain-scenario-go v1.3.1-0.20240129145446-ca4fba98f6d1 h1:hkeHftnhRuJoT5FrfF97gEtb5aY351SWEjZPaTb6D+Y= -github.com/multiversx/mx-chain-scenario-go v1.3.1-0.20240129145446-ca4fba98f6d1/go.mod h1:ndk45i9J9McuCJpTcgiaK4ocd0yhnBBCPrlFwO6GRcs= +github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 h1:ydzN3f+Y7H0InXuxAcNUSyVc+omNYL8uYtLqVzqaaX4= +github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157/go.mod h1:ndk45i9J9McuCJpTcgiaK4ocd0yhnBBCPrlFwO6GRcs= github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240129144933-b1c0d642d7f8 h1:/EYv/HGX0OKbeNFt667J0yZRtuJiZH0lEK8YtobuH/c= github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240129144933-b1c0d642d7f8/go.mod h1:zl1A6teNe39T8yhdZlkX3ckm5aLYrMIJJZ6Ord1E71M= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240130120052-d8425c5cc419 h1:XfXy9Dw9L3QMycCxCRpJZ4hM6gdzkI/yYxUNLFQeRTE= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240130120052-d8425c5cc419/go.mod h1:aOuG7j+RoifbyJNzmCeY2yT3y0zUTpW2LQoq8giUTwk= -github.com/multiversx/mx-chain-vm-go v1.5.27-0.20240130132826-bcb98ba529aa h1:8rnHHuDgy/kVlBt0wmUnPsw9M+xGqcgGY4pK0qf09jg= -github.com/multiversx/mx-chain-vm-go v1.5.27-0.20240130132826-bcb98ba529aa/go.mod h1:lQKIRqU6tIKTDoBNkZKTMDTduiAGm/hOA/tTEKLqVd4= +github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240306131831-1434bb74eb3b h1:sAmYVMXS9pe7q7+D1Zet4DYECgCuUIVcgEippTUqI3s= +github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240306131831-1434bb74eb3b/go.mod h1:aOuG7j+RoifbyJNzmCeY2yT3y0zUTpW2LQoq8giUTwk= +github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240306131314-329c0fcd5ce1 h1:nTI2TKn1CatNJDh6pmqTvtWSTI8xq96lN+ylZJ4pJYQ= +github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240306131314-329c0fcd5ce1/go.mod h1:nG0NywN7JMXckwXn17qTVLaIklZiWOX+vQxrXML5gpU= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240129145751-f814f5525edb h1:UtiY8X73llF9OLtGb2CM7Xewae1chvPjLc8B+ZmDLjw= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240129145751-f814f5525edb/go.mod h1:8uugq3HUeDiE6G4AS3F8/B3zA1Pabzbl7SSD6Cebwz8= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240129150004-536a22d9c618 h1:1uMlT5TjiHUlx81fEH/WQANWlY0PjF3opMlW+E3L3GI= From 9e4f7041d58f81e6327aa2ce345d81a7045005c1 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 6 Mar 2024 15:39:09 +0200 Subject: [PATCH 084/503] new go mod --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e40d1fc8231..4652af67770 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240129144933-b1c0d642d7f8 - github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240306131831-1434bb74eb3b + github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240306133710-91798f2f9baa github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240306131314-329c0fcd5ce1 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240129145751-f814f5525edb github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240129150004-536a22d9c618 diff --git a/go.sum b/go.sum index 73cfe26209c..8363b441c57 100644 --- a/go.sum +++ b/go.sum @@ -399,8 +399,8 @@ github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157/go.mod h1:ndk45i9J9McuCJpTcgiaK4ocd0yhnBBCPrlFwO6GRcs= github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240129144933-b1c0d642d7f8 h1:/EYv/HGX0OKbeNFt667J0yZRtuJiZH0lEK8YtobuH/c= github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240129144933-b1c0d642d7f8/go.mod h1:zl1A6teNe39T8yhdZlkX3ckm5aLYrMIJJZ6Ord1E71M= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240306131831-1434bb74eb3b h1:sAmYVMXS9pe7q7+D1Zet4DYECgCuUIVcgEippTUqI3s= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240306131831-1434bb74eb3b/go.mod h1:aOuG7j+RoifbyJNzmCeY2yT3y0zUTpW2LQoq8giUTwk= +github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240306133710-91798f2f9baa h1:lBvEkooZE6xIZiPc9TTNkgN3pz+qbmuGvcW0Hcc/Ir8= +github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240306133710-91798f2f9baa/go.mod h1:aOuG7j+RoifbyJNzmCeY2yT3y0zUTpW2LQoq8giUTwk= github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240306131314-329c0fcd5ce1 h1:nTI2TKn1CatNJDh6pmqTvtWSTI8xq96lN+ylZJ4pJYQ= github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240306131314-329c0fcd5ce1/go.mod h1:nG0NywN7JMXckwXn17qTVLaIklZiWOX+vQxrXML5gpU= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240129145751-f814f5525edb h1:UtiY8X73llF9OLtGb2CM7Xewae1chvPjLc8B+ZmDLjw= From 93b3c9d4b4615296c598100a6b1917432785899f Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 11 Mar 2024 17:01:02 +0200 Subject: [PATCH 085/503] added guardian as field on the transaction/pool by-sender request --- .../transactionAPI/apiTransactionProcessor.go | 11 +++++++++-- node/external/transactionAPI/fieldsHandler.go | 3 +++ node/external/transactionAPI/fieldsHandler_test.go | 3 ++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/node/external/transactionAPI/apiTransactionProcessor.go b/node/external/transactionAPI/apiTransactionProcessor.go index 404cc8eba8d..313a86f381c 100644 --- a/node/external/transactionAPI/apiTransactionProcessor.go +++ b/node/external/transactionAPI/apiTransactionProcessor.go @@ -8,6 +8,7 @@ import ( "time" "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/block" rewardTxData "github.com/multiversx/mx-chain-core-go/data/rewardTx" "github.com/multiversx/mx-chain-core-go/data/smartContractResult" @@ -319,11 +320,11 @@ func (atp *apiTransactionProcessor) extractRequestedTxInfo(wrappedTx *txcache.Wr } if requestedFieldsHandler.HasSender { - tx.TxFields[senderField], _ = atp.addressPubKeyConverter.Encode(wrappedTx.Tx.GetSndAddr()) + tx.TxFields[senderField] = atp.addressPubKeyConverter.SilentEncode(wrappedTx.Tx.GetSndAddr(), log) } if requestedFieldsHandler.HasReceiver { - tx.TxFields[receiverField], _ = atp.addressPubKeyConverter.Encode(wrappedTx.Tx.GetRcvAddr()) + tx.TxFields[receiverField] = atp.addressPubKeyConverter.SilentEncode(wrappedTx.Tx.GetRcvAddr(), log) } if requestedFieldsHandler.HasGasLimit { @@ -341,6 +342,12 @@ func (atp *apiTransactionProcessor) extractRequestedTxInfo(wrappedTx *txcache.Wr if requestedFieldsHandler.HasValue { tx.TxFields[valueField] = getTxValue(wrappedTx) } + if requestedFieldsHandler.HasGuardian { + guardedTx, isGuardedTx := wrappedTx.Tx.(data.GuardedTransactionHandler) + if isGuardedTx { + tx.TxFields[guardianField] = atp.addressPubKeyConverter.SilentEncode(guardedTx.GetGuardianAddr(), log) + } + } return tx } diff --git a/node/external/transactionAPI/fieldsHandler.go b/node/external/transactionAPI/fieldsHandler.go index 43ea27d473a..d79c5167d29 100644 --- a/node/external/transactionAPI/fieldsHandler.go +++ b/node/external/transactionAPI/fieldsHandler.go @@ -14,6 +14,7 @@ const ( rcvUsernameField = "receiverusername" dataField = "data" valueField = "value" + guardianField = "guardian" ) type fieldsHandler struct { @@ -25,6 +26,7 @@ type fieldsHandler struct { HasRcvUsername bool HasData bool HasValue bool + HasGuardian bool } func newFieldsHandler(parameters string) fieldsHandler { @@ -38,6 +40,7 @@ func newFieldsHandler(parameters string) fieldsHandler { HasRcvUsername: strings.Contains(parameters, rcvUsernameField), HasData: strings.Contains(parameters, dataField), HasValue: strings.Contains(parameters, valueField), + HasGuardian: strings.Contains(parameters, guardianField), } return ph } diff --git a/node/external/transactionAPI/fieldsHandler_test.go b/node/external/transactionAPI/fieldsHandler_test.go index 0948483fd11..398b868fc21 100644 --- a/node/external/transactionAPI/fieldsHandler_test.go +++ b/node/external/transactionAPI/fieldsHandler_test.go @@ -12,7 +12,7 @@ func Test_newFieldsHandler(t *testing.T) { fh := newFieldsHandler("") require.Equal(t, fieldsHandler{}, fh) - fh = newFieldsHandler("nOnCe,sender,receiver,gasLimit,GASprice,receiverusername,data,value") + fh = newFieldsHandler("nOnCe,sender,receiver,gasLimit,GASprice,receiverusername,data,value,guardian") expectedPH := fieldsHandler{ HasNonce: true, HasSender: true, @@ -22,6 +22,7 @@ func Test_newFieldsHandler(t *testing.T) { HasRcvUsername: true, HasData: true, HasValue: true, + HasGuardian: true, } require.Equal(t, expectedPH, fh) } From 8be1556f84a71e76fe5e64cb76102aeb73c69ca5 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 11 Mar 2024 20:49:07 +0200 Subject: [PATCH 086/503] added more fields + wild card --- api/groups/transactionGroup.go | 4 + .../transactionAPI/apiTransactionProcessor.go | 27 ++++++ .../apiTransactionProcessor_test.go | 2 +- node/external/transactionAPI/fieldsHandler.go | 88 +++++++++++++------ .../transactionAPI/fieldsHandler_test.go | 27 +++--- 5 files changed, 109 insertions(+), 39 deletions(-) diff --git a/api/groups/transactionGroup.go b/api/groups/transactionGroup.go index c2b47bf7a87..3c62221d121 100644 --- a/api/groups/transactionGroup.go +++ b/api/groups/transactionGroup.go @@ -745,6 +745,10 @@ func validateQuery(sender, fields string, lastNonce, nonceGaps bool) error { return errors.ErrEmptySenderToGetNonceGaps } + if fields == "*" { + return nil + } + if fields != "" { return validateFields(fields) } diff --git a/node/external/transactionAPI/apiTransactionProcessor.go b/node/external/transactionAPI/apiTransactionProcessor.go index 313a86f381c..eda6f5e422f 100644 --- a/node/external/transactionAPI/apiTransactionProcessor.go +++ b/node/external/transactionAPI/apiTransactionProcessor.go @@ -330,18 +330,38 @@ func (atp *apiTransactionProcessor) extractRequestedTxInfo(wrappedTx *txcache.Wr if requestedFieldsHandler.HasGasLimit { tx.TxFields[gasLimitField] = wrappedTx.Tx.GetGasLimit() } + if requestedFieldsHandler.HasGasPrice { tx.TxFields[gasPriceField] = wrappedTx.Tx.GetGasPrice() } + if requestedFieldsHandler.HasRcvUsername { tx.TxFields[rcvUsernameField] = wrappedTx.Tx.GetRcvUserName() } + if requestedFieldsHandler.HasData { tx.TxFields[dataField] = wrappedTx.Tx.GetData() } + if requestedFieldsHandler.HasValue { tx.TxFields[valueField] = getTxValue(wrappedTx) } + + if requestedFieldsHandler.HasSenderShardID { + tx.TxFields[senderShardID] = wrappedTx.SenderShardID + } + + if requestedFieldsHandler.HasReceiverShardID { + tx.TxFields[receiverShardID] = wrappedTx.ReceiverShardID + } + + if requestedFieldsHandler.HasSignature { + castedTx, hasSignature := wrappedTx.Tx.(data.GuardedTransactionHandler) + if hasSignature { + tx.TxFields[signatureField] = hex.EncodeToString(castedTx.GetSignature()) + } + } + if requestedFieldsHandler.HasGuardian { guardedTx, isGuardedTx := wrappedTx.Tx.(data.GuardedTransactionHandler) if isGuardedTx { @@ -349,6 +369,13 @@ func (atp *apiTransactionProcessor) extractRequestedTxInfo(wrappedTx *txcache.Wr } } + if requestedFieldsHandler.HasGuardianSignature { + guardedTx, isGuardedTx := wrappedTx.Tx.(data.GuardedTransactionHandler) + if isGuardedTx { + tx.TxFields[guardianSignatureField] = hex.EncodeToString(guardedTx.GetGuardianSignature()) + } + } + return tx } diff --git a/node/external/transactionAPI/apiTransactionProcessor_test.go b/node/external/transactionAPI/apiTransactionProcessor_test.go index f7d90c8f15b..7d86a1610c5 100644 --- a/node/external/transactionAPI/apiTransactionProcessor_test.go +++ b/node/external/transactionAPI/apiTransactionProcessor_test.go @@ -825,7 +825,7 @@ func TestApiTransactionProcessor_GetTransactionsPoolForSender(t *testing.T) { require.NoError(t, err) require.NotNil(t, atp) - res, err := atp.GetTransactionsPoolForSender(sender, "sender,value") + res, err := atp.GetTransactionsPoolForSender(sender, "*") require.NoError(t, err) expectedHashes := []string{hex.EncodeToString(txHash0), hex.EncodeToString(txHash1), hex.EncodeToString(txHash2), hex.EncodeToString(txHash3), hex.EncodeToString(txHash4)} expectedValues := []string{"100001", "100002", "100003", "100004", "100005"} diff --git a/node/external/transactionAPI/fieldsHandler.go b/node/external/transactionAPI/fieldsHandler.go index d79c5167d29..411141d271d 100644 --- a/node/external/transactionAPI/fieldsHandler.go +++ b/node/external/transactionAPI/fieldsHandler.go @@ -5,42 +5,74 @@ import ( ) const ( - hashField = "hash" - nonceField = "nonce" - senderField = "sender" - receiverField = "receiver" - gasLimitField = "gaslimit" - gasPriceField = "gasprice" - rcvUsernameField = "receiverusername" - dataField = "data" - valueField = "value" - guardianField = "guardian" + hashField = "hash" + nonceField = "nonce" + senderField = "sender" + receiverField = "receiver" + gasLimitField = "gaslimit" + gasPriceField = "gasprice" + rcvUsernameField = "receiverusername" + dataField = "data" + valueField = "value" + signatureField = "signature" + guardianField = "guardian" + guardianSignatureField = "guardiansignature" + senderShardID = "sendershard" + receiverShardID = "receivershard" + wildCard = "*" + + separator = "," ) type fieldsHandler struct { - HasNonce bool - HasSender bool - HasReceiver bool - HasGasLimit bool - HasGasPrice bool - HasRcvUsername bool - HasData bool - HasValue bool - HasGuardian bool + HasNonce bool + HasSender bool + HasReceiver bool + HasGasLimit bool + HasGasPrice bool + HasRcvUsername bool + HasData bool + HasValue bool + HasSignature bool + HasSenderShardID bool + HasReceiverShardID bool + HasGuardian bool + HasGuardianSignature bool } func newFieldsHandler(parameters string) fieldsHandler { parameters = strings.ToLower(parameters) + parametersMap := sliceToMap(strings.Split(parameters, separator)) ph := fieldsHandler{ - HasNonce: strings.Contains(parameters, nonceField), - HasSender: strings.Contains(parameters, senderField), - HasReceiver: strings.Contains(parameters, receiverField), - HasGasLimit: strings.Contains(parameters, gasLimitField), - HasGasPrice: strings.Contains(parameters, gasPriceField), - HasRcvUsername: strings.Contains(parameters, rcvUsernameField), - HasData: strings.Contains(parameters, dataField), - HasValue: strings.Contains(parameters, valueField), - HasGuardian: strings.Contains(parameters, guardianField), + HasNonce: shouldConsiderField(parametersMap, nonceField), + HasSender: shouldConsiderField(parametersMap, senderField), + HasReceiver: shouldConsiderField(parametersMap, receiverField), + HasGasLimit: shouldConsiderField(parametersMap, gasLimitField), + HasGasPrice: shouldConsiderField(parametersMap, gasPriceField), + HasRcvUsername: shouldConsiderField(parametersMap, rcvUsernameField), + HasData: shouldConsiderField(parametersMap, dataField), + HasValue: shouldConsiderField(parametersMap, valueField), + HasSignature: shouldConsiderField(parametersMap, signatureField), + HasSenderShardID: shouldConsiderField(parametersMap, senderShardID), + HasReceiverShardID: shouldConsiderField(parametersMap, receiverShardID), + HasGuardian: shouldConsiderField(parametersMap, guardianField), + HasGuardianSignature: shouldConsiderField(parametersMap, guardianSignatureField), } return ph } + +func shouldConsiderField(parametersMap map[string]struct{}, field string) bool { + _, has := parametersMap[field] + _, hasWildCard := parametersMap[wildCard] + + return has || hasWildCard +} + +func sliceToMap(providedSlice []string) map[string]struct{} { + result := make(map[string]struct{}, len(providedSlice)) + for _, entry := range providedSlice { + result[entry] = struct{}{} + } + + return result +} diff --git a/node/external/transactionAPI/fieldsHandler_test.go b/node/external/transactionAPI/fieldsHandler_test.go index 398b868fc21..1a2d68ce85a 100644 --- a/node/external/transactionAPI/fieldsHandler_test.go +++ b/node/external/transactionAPI/fieldsHandler_test.go @@ -12,17 +12,24 @@ func Test_newFieldsHandler(t *testing.T) { fh := newFieldsHandler("") require.Equal(t, fieldsHandler{}, fh) - fh = newFieldsHandler("nOnCe,sender,receiver,gasLimit,GASprice,receiverusername,data,value,guardian") + fh = newFieldsHandler("nOnCe,sender,receiver,gasLimit,GASprice,receiverusername,data,value,signature,guardian,guardiansignature,sendershard,receivershard") expectedPH := fieldsHandler{ - HasNonce: true, - HasSender: true, - HasReceiver: true, - HasGasLimit: true, - HasGasPrice: true, - HasRcvUsername: true, - HasData: true, - HasValue: true, - HasGuardian: true, + HasNonce: true, + HasSender: true, + HasReceiver: true, + HasGasLimit: true, + HasGasPrice: true, + HasRcvUsername: true, + HasData: true, + HasValue: true, + HasSignature: true, + HasSenderShardID: true, + HasReceiverShardID: true, + HasGuardian: true, + HasGuardianSignature: true, } require.Equal(t, expectedPH, fh) + + fh = newFieldsHandler("*") + require.Equal(t, expectedPH, fh) } From 4040b050b3bf65522ea18ebc848424665cb98ed7 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 11 Mar 2024 20:51:12 +0200 Subject: [PATCH 087/503] more tests --- api/groups/transactionGroup_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/groups/transactionGroup_test.go b/api/groups/transactionGroup_test.go index 1f8f6bffbd4..22085956fe9 100644 --- a/api/groups/transactionGroup_test.go +++ b/api/groups/transactionGroup_test.go @@ -704,6 +704,7 @@ func TestTransactionGroup_getTransactionsPool(t *testing.T) { t.Run("fields + nonce gaps", testTxPoolWithInvalidQuery("?fields=sender,receiver&nonce-gaps=true", apiErrors.ErrFetchingNonceGapsCannotIncludeFields)) t.Run("fields has spaces", testTxPoolWithInvalidQuery("?fields=sender ,receiver", apiErrors.ErrInvalidFields)) t.Run("fields has numbers", testTxPoolWithInvalidQuery("?fields=sender1", apiErrors.ErrInvalidFields)) + t.Run("fields + wild card", testTxPoolWithInvalidQuery("?fields=sender,receiver,*", apiErrors.ErrInvalidFields)) t.Run("GetTransactionsPool error should error", func(t *testing.T) { t.Parallel() @@ -816,8 +817,7 @@ func TestTransactionGroup_getTransactionsPool(t *testing.T) { t.Parallel() expectedSender := "sender" - providedFields := "sender,receiver" - query := "?by-sender=" + expectedSender + "&fields=" + providedFields + query := "?by-sender=" + expectedSender + "&fields=*" expectedResp := &common.TransactionsPoolForSenderApiResponse{ Transactions: []common.Transaction{ { From c07e4f280c462b9c823d9693766d142107a0d2b5 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 11 Mar 2024 21:00:25 +0200 Subject: [PATCH 088/503] improvement after review --- node/external/transactionAPI/fieldsHandler.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/node/external/transactionAPI/fieldsHandler.go b/node/external/transactionAPI/fieldsHandler.go index 411141d271d..d996d329751 100644 --- a/node/external/transactionAPI/fieldsHandler.go +++ b/node/external/transactionAPI/fieldsHandler.go @@ -62,10 +62,13 @@ func newFieldsHandler(parameters string) fieldsHandler { } func shouldConsiderField(parametersMap map[string]struct{}, field string) bool { - _, has := parametersMap[field] _, hasWildCard := parametersMap[wildCard] + if hasWildCard { + return true + } - return has || hasWildCard + _, has := parametersMap[field] + return has } func sliceToMap(providedSlice []string) map[string]struct{} { From 81f35e40edbcfe6e720208b82aed7091fe4c9201 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 12 Mar 2024 10:58:54 +0200 Subject: [PATCH 089/503] fixes after second review --- .../transactionAPI/apiTransactionProcessor.go | 83 ++++++------------- node/external/transactionAPI/fieldsHandler.go | 47 ++++------- .../transactionAPI/fieldsHandler_test.go | 29 +++---- 3 files changed, 52 insertions(+), 107 deletions(-) diff --git a/node/external/transactionAPI/apiTransactionProcessor.go b/node/external/transactionAPI/apiTransactionProcessor.go index eda6f5e422f..1b4867f0b39 100644 --- a/node/external/transactionAPI/apiTransactionProcessor.go +++ b/node/external/transactionAPI/apiTransactionProcessor.go @@ -309,74 +309,43 @@ func (atp *apiTransactionProcessor) getUnsignedTransactionsFromPool(requestedFie } func (atp *apiTransactionProcessor) extractRequestedTxInfo(wrappedTx *txcache.WrappedTransaction, requestedFieldsHandler fieldsHandler) common.Transaction { + fieldGetters := atp.getFieldGettersForTx(wrappedTx) tx := common.Transaction{ TxFields: make(map[string]interface{}), } - tx.TxFields[hashField] = hex.EncodeToString(wrappedTx.TxHash) - - if requestedFieldsHandler.HasNonce { - tx.TxFields[nonceField] = wrappedTx.Tx.GetNonce() - } - - if requestedFieldsHandler.HasSender { - tx.TxFields[senderField] = atp.addressPubKeyConverter.SilentEncode(wrappedTx.Tx.GetSndAddr(), log) - } - - if requestedFieldsHandler.HasReceiver { - tx.TxFields[receiverField] = atp.addressPubKeyConverter.SilentEncode(wrappedTx.Tx.GetRcvAddr(), log) - } - - if requestedFieldsHandler.HasGasLimit { - tx.TxFields[gasLimitField] = wrappedTx.Tx.GetGasLimit() - } - - if requestedFieldsHandler.HasGasPrice { - tx.TxFields[gasPriceField] = wrappedTx.Tx.GetGasPrice() - } - - if requestedFieldsHandler.HasRcvUsername { - tx.TxFields[rcvUsernameField] = wrappedTx.Tx.GetRcvUserName() - } - - if requestedFieldsHandler.HasData { - tx.TxFields[dataField] = wrappedTx.Tx.GetData() - } - - if requestedFieldsHandler.HasValue { - tx.TxFields[valueField] = getTxValue(wrappedTx) - } - - if requestedFieldsHandler.HasSenderShardID { - tx.TxFields[senderShardID] = wrappedTx.SenderShardID - } - - if requestedFieldsHandler.HasReceiverShardID { - tx.TxFields[receiverShardID] = wrappedTx.ReceiverShardID - } - - if requestedFieldsHandler.HasSignature { - castedTx, hasSignature := wrappedTx.Tx.(data.GuardedTransactionHandler) - if hasSignature { - tx.TxFields[signatureField] = hex.EncodeToString(castedTx.GetSignature()) + for field, getter := range fieldGetters { + if requestedFieldsHandler.IsFieldSet(field) { + tx.TxFields[field] = getter() } } - if requestedFieldsHandler.HasGuardian { - guardedTx, isGuardedTx := wrappedTx.Tx.(data.GuardedTransactionHandler) - if isGuardedTx { - tx.TxFields[guardianField] = atp.addressPubKeyConverter.SilentEncode(guardedTx.GetGuardianAddr(), log) - } + return tx +} + +func (atp *apiTransactionProcessor) getFieldGettersForTx(wrappedTx *txcache.WrappedTransaction) map[string]func() interface{} { + var fieldGetters = map[string]func() interface{}{ + hashField: func() interface{} { return hex.EncodeToString(wrappedTx.TxHash) }, + nonceField: func() interface{} { return wrappedTx.Tx.GetNonce() }, + senderField: func() interface{} { return atp.addressPubKeyConverter.SilentEncode(wrappedTx.Tx.GetSndAddr(), log) }, + receiverField: func() interface{} { return atp.addressPubKeyConverter.SilentEncode(wrappedTx.Tx.GetRcvAddr(), log) }, + gasLimitField: func() interface{} { return wrappedTx.Tx.GetGasLimit() }, + gasPriceField: func() interface{} { return wrappedTx.Tx.GetGasPrice() }, + rcvUsernameField: func() interface{} { return wrappedTx.Tx.GetRcvUserName() }, + dataField: func() interface{} { return wrappedTx.Tx.GetData() }, + valueField: func() interface{} { return getTxValue(wrappedTx) }, + senderShardID: func() interface{} { return wrappedTx.SenderShardID }, + receiverShardID: func() interface{} { return wrappedTx.ReceiverShardID }, } - if requestedFieldsHandler.HasGuardianSignature { - guardedTx, isGuardedTx := wrappedTx.Tx.(data.GuardedTransactionHandler) - if isGuardedTx { - tx.TxFields[guardianSignatureField] = hex.EncodeToString(guardedTx.GetGuardianSignature()) - } + guardedTx, isGuardedTx := wrappedTx.Tx.(data.GuardedTransactionHandler) + if isGuardedTx { + fieldGetters[signatureField] = func() interface{} { return hex.EncodeToString(guardedTx.GetSignature()) } + fieldGetters[guardianField] = func() interface{} { return atp.addressPubKeyConverter.SilentEncode(guardedTx.GetGuardianAddr(), log) } + fieldGetters[guardianSignatureField] = func() interface{} { return hex.EncodeToString(guardedTx.GetGuardianSignature()) } } - return tx + return fieldGetters } func (atp *apiTransactionProcessor) fetchTxsForSender(sender string, senderShard uint32) []*txcache.WrappedTransaction { diff --git a/node/external/transactionAPI/fieldsHandler.go b/node/external/transactionAPI/fieldsHandler.go index d996d329751..4f837968cb7 100644 --- a/node/external/transactionAPI/fieldsHandler.go +++ b/node/external/transactionAPI/fieldsHandler.go @@ -25,49 +25,32 @@ const ( ) type fieldsHandler struct { - HasNonce bool - HasSender bool - HasReceiver bool - HasGasLimit bool - HasGasPrice bool - HasRcvUsername bool - HasData bool - HasValue bool - HasSignature bool - HasSenderShardID bool - HasReceiverShardID bool - HasGuardian bool - HasGuardianSignature bool + fieldsMap map[string]struct{} } func newFieldsHandler(parameters string) fieldsHandler { + if len(parameters) == 0 { + return fieldsHandler{ + fieldsMap: map[string]struct{}{ + hashField: {}, // hash should always be returned + }, + } + } + parameters = strings.ToLower(parameters) - parametersMap := sliceToMap(strings.Split(parameters, separator)) - ph := fieldsHandler{ - HasNonce: shouldConsiderField(parametersMap, nonceField), - HasSender: shouldConsiderField(parametersMap, senderField), - HasReceiver: shouldConsiderField(parametersMap, receiverField), - HasGasLimit: shouldConsiderField(parametersMap, gasLimitField), - HasGasPrice: shouldConsiderField(parametersMap, gasPriceField), - HasRcvUsername: shouldConsiderField(parametersMap, rcvUsernameField), - HasData: shouldConsiderField(parametersMap, dataField), - HasValue: shouldConsiderField(parametersMap, valueField), - HasSignature: shouldConsiderField(parametersMap, signatureField), - HasSenderShardID: shouldConsiderField(parametersMap, senderShardID), - HasReceiverShardID: shouldConsiderField(parametersMap, receiverShardID), - HasGuardian: shouldConsiderField(parametersMap, guardianField), - HasGuardianSignature: shouldConsiderField(parametersMap, guardianSignatureField), + return fieldsHandler{ + fieldsMap: sliceToMap(strings.Split(parameters, separator)), } - return ph } -func shouldConsiderField(parametersMap map[string]struct{}, field string) bool { - _, hasWildCard := parametersMap[wildCard] +// IsFieldSet returns true if the provided field is set +func (handler *fieldsHandler) IsFieldSet(field string) bool { + _, hasWildCard := handler.fieldsMap[wildCard] if hasWildCard { return true } - _, has := parametersMap[field] + _, has := handler.fieldsMap[strings.ToLower(field)] return has } diff --git a/node/external/transactionAPI/fieldsHandler_test.go b/node/external/transactionAPI/fieldsHandler_test.go index 1a2d68ce85a..65c5e76bbaf 100644 --- a/node/external/transactionAPI/fieldsHandler_test.go +++ b/node/external/transactionAPI/fieldsHandler_test.go @@ -1,6 +1,8 @@ package transactionAPI import ( + "fmt" + "strings" "testing" "github.com/stretchr/testify/require" @@ -10,26 +12,17 @@ func Test_newFieldsHandler(t *testing.T) { t.Parallel() fh := newFieldsHandler("") - require.Equal(t, fieldsHandler{}, fh) + require.Equal(t, fieldsHandler{make(map[string]struct{})}, fh) - fh = newFieldsHandler("nOnCe,sender,receiver,gasLimit,GASprice,receiverusername,data,value,signature,guardian,guardiansignature,sendershard,receivershard") - expectedPH := fieldsHandler{ - HasNonce: true, - HasSender: true, - HasReceiver: true, - HasGasLimit: true, - HasGasPrice: true, - HasRcvUsername: true, - HasData: true, - HasValue: true, - HasSignature: true, - HasSenderShardID: true, - HasReceiverShardID: true, - HasGuardian: true, - HasGuardianSignature: true, + providedFields := "nOnCe,sender,receiver,gasLimit,GASprice,receiverusername,data,value,signature,guardian,guardiansignature,sendershard,receivershard" + splitFields := strings.Split(providedFields, separator) + fh = newFieldsHandler(providedFields) + for _, field := range splitFields { + require.True(t, fh.IsFieldSet(field), fmt.Sprintf("field %s is not set", field)) } - require.Equal(t, expectedPH, fh) fh = newFieldsHandler("*") - require.Equal(t, expectedPH, fh) + for _, field := range splitFields { + require.True(t, fh.IsFieldSet(field)) + } } From caa2b9079595a87257627a23f9526a4aadad739f Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 12 Mar 2024 12:27:51 +0200 Subject: [PATCH 090/503] fix tests --- node/external/transactionAPI/fieldsHandler_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/external/transactionAPI/fieldsHandler_test.go b/node/external/transactionAPI/fieldsHandler_test.go index 65c5e76bbaf..fab3b3a41d9 100644 --- a/node/external/transactionAPI/fieldsHandler_test.go +++ b/node/external/transactionAPI/fieldsHandler_test.go @@ -12,7 +12,7 @@ func Test_newFieldsHandler(t *testing.T) { t.Parallel() fh := newFieldsHandler("") - require.Equal(t, fieldsHandler{make(map[string]struct{})}, fh) + require.Equal(t, fieldsHandler{map[string]struct{}{hashField: {}}}, fh) providedFields := "nOnCe,sender,receiver,gasLimit,GASprice,receiverusername,data,value,signature,guardian,guardiansignature,sendershard,receivershard" splitFields := strings.Split(providedFields, separator) From 6d6332cb673eb7b7f435e0911e92bc87b4513b84 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 13 Mar 2024 11:08:09 +0200 Subject: [PATCH 091/503] fixes after review --- .../transactionAPI/apiTransactionProcessor.go | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/node/external/transactionAPI/apiTransactionProcessor.go b/node/external/transactionAPI/apiTransactionProcessor.go index 1b4867f0b39..b12aa9ac86f 100644 --- a/node/external/transactionAPI/apiTransactionProcessor.go +++ b/node/external/transactionAPI/apiTransactionProcessor.go @@ -314,35 +314,35 @@ func (atp *apiTransactionProcessor) extractRequestedTxInfo(wrappedTx *txcache.Wr TxFields: make(map[string]interface{}), } - for field, getter := range fieldGetters { + for field, value := range fieldGetters { if requestedFieldsHandler.IsFieldSet(field) { - tx.TxFields[field] = getter() + tx.TxFields[field] = value } } return tx } -func (atp *apiTransactionProcessor) getFieldGettersForTx(wrappedTx *txcache.WrappedTransaction) map[string]func() interface{} { - var fieldGetters = map[string]func() interface{}{ - hashField: func() interface{} { return hex.EncodeToString(wrappedTx.TxHash) }, - nonceField: func() interface{} { return wrappedTx.Tx.GetNonce() }, - senderField: func() interface{} { return atp.addressPubKeyConverter.SilentEncode(wrappedTx.Tx.GetSndAddr(), log) }, - receiverField: func() interface{} { return atp.addressPubKeyConverter.SilentEncode(wrappedTx.Tx.GetRcvAddr(), log) }, - gasLimitField: func() interface{} { return wrappedTx.Tx.GetGasLimit() }, - gasPriceField: func() interface{} { return wrappedTx.Tx.GetGasPrice() }, - rcvUsernameField: func() interface{} { return wrappedTx.Tx.GetRcvUserName() }, - dataField: func() interface{} { return wrappedTx.Tx.GetData() }, - valueField: func() interface{} { return getTxValue(wrappedTx) }, - senderShardID: func() interface{} { return wrappedTx.SenderShardID }, - receiverShardID: func() interface{} { return wrappedTx.ReceiverShardID }, +func (atp *apiTransactionProcessor) getFieldGettersForTx(wrappedTx *txcache.WrappedTransaction) map[string]interface{} { + var fieldGetters = map[string]interface{}{ + hashField: hex.EncodeToString(wrappedTx.TxHash), + nonceField: wrappedTx.Tx.GetNonce(), + senderField: atp.addressPubKeyConverter.SilentEncode(wrappedTx.Tx.GetSndAddr(), log), + receiverField: atp.addressPubKeyConverter.SilentEncode(wrappedTx.Tx.GetRcvAddr(), log), + gasLimitField: wrappedTx.Tx.GetGasLimit(), + gasPriceField: wrappedTx.Tx.GetGasPrice(), + rcvUsernameField: wrappedTx.Tx.GetRcvUserName(), + dataField: wrappedTx.Tx.GetData(), + valueField: getTxValue(wrappedTx), + senderShardID: wrappedTx.SenderShardID, + receiverShardID: wrappedTx.ReceiverShardID, } guardedTx, isGuardedTx := wrappedTx.Tx.(data.GuardedTransactionHandler) if isGuardedTx { - fieldGetters[signatureField] = func() interface{} { return hex.EncodeToString(guardedTx.GetSignature()) } - fieldGetters[guardianField] = func() interface{} { return atp.addressPubKeyConverter.SilentEncode(guardedTx.GetGuardianAddr(), log) } - fieldGetters[guardianSignatureField] = func() interface{} { return hex.EncodeToString(guardedTx.GetGuardianSignature()) } + fieldGetters[signatureField] = hex.EncodeToString(guardedTx.GetSignature()) + fieldGetters[guardianField] = atp.addressPubKeyConverter.SilentEncode(guardedTx.GetGuardianAddr(), log) + fieldGetters[guardianSignatureField] = hex.EncodeToString(guardedTx.GetGuardianSignature()) } return fieldGetters From e7a18fadd2f07eb20807ea2a020f010590ad1c07 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 13 Mar 2024 20:13:45 +0200 Subject: [PATCH 092/503] remove all nodes from queue on the activation of staking v4. no tests were changed yet. --- epochStart/metachain/systemSCs.go | 29 +++++++++- vm/systemSmartContracts/staking.go | 2 + vm/systemSmartContracts/stakingWaitingList.go | 54 +++++++++++++++++++ 3 files changed, 83 insertions(+), 2 deletions(-) diff --git a/epochStart/metachain/systemSCs.go b/epochStart/metachain/systemSCs.go index a0bd2a3402d..b43055aba3a 100644 --- a/epochStart/metachain/systemSCs.go +++ b/epochStart/metachain/systemSCs.go @@ -2,7 +2,6 @@ package metachain import ( "fmt" - "math" "math/big" "github.com/multiversx/mx-chain-core-go/core" @@ -139,7 +138,7 @@ func (s *systemSCProcessor) processWithNewFlags( } if s.enableEpochsHandler.IsFlagEnabled(common.StakingV4Step1Flag) { - err := s.stakeNodesFromQueue(validatorsInfoMap, math.MaxUint32, header.GetNonce(), common.AuctionList) + err := s.unStakeAllNodesFromQueue() if err != nil { return err } @@ -170,6 +169,32 @@ func (s *systemSCProcessor) processWithNewFlags( return nil } +func (s *systemSCProcessor) unStakeAllNodesFromQueue() error { + vmInput := &vmcommon.ContractCallInput{ + VMInput: vmcommon.VMInput{ + CallerAddr: vm.EndOfEpochAddress, + CallValue: big.NewInt(0), + Arguments: [][]byte{}, + }, + RecipientAddr: vm.StakingSCAddress, + Function: "unStakeAllNodesFromQueue", + } + vmOutput, errRun := s.systemVM.RunSmartContractCall(vmInput) + if errRun != nil { + return fmt.Errorf("%w when unStaking all nodes from waiting list", errRun) + } + if vmOutput.ReturnCode != vmcommon.Ok { + return fmt.Errorf("got return code %s when unStaking all nodes from waiting list", vmOutput.ReturnCode) + } + + err := s.processSCOutputAccounts(vmOutput) + if err != nil { + return err + } + + return nil +} + func (s *systemSCProcessor) unStakeNodesWithNotEnoughFundsWithStakingV4( validatorsInfoMap state.ShardValidatorsInfoMapHandler, epoch uint32, diff --git a/vm/systemSmartContracts/staking.go b/vm/systemSmartContracts/staking.go index d450ef73f75..a1597d2cedb 100644 --- a/vm/systemSmartContracts/staking.go +++ b/vm/systemSmartContracts/staking.go @@ -209,6 +209,8 @@ func (s *stakingSC) Execute(args *vmcommon.ContractCallInput) vmcommon.ReturnCod return s.fixWaitingListQueueSize(args) case "addMissingNodeToQueue": return s.addMissingNodeToQueue(args) + case "unStakeAllNodesFromQueue": + return s.unStakeAllNodesFromQueue(args) } return vmcommon.UserError diff --git a/vm/systemSmartContracts/stakingWaitingList.go b/vm/systemSmartContracts/stakingWaitingList.go index 16d979a6a86..279b5a7db0c 100644 --- a/vm/systemSmartContracts/stakingWaitingList.go +++ b/vm/systemSmartContracts/stakingWaitingList.go @@ -801,6 +801,60 @@ func (s *stakingSC) stakeNodesFromQueue(args *vmcommon.ContractCallInput) vmcomm return vmcommon.Ok } +func (s *stakingSC) unStakeAllNodesFromQueue(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { + if !s.enableEpochsHandler.IsFlagEnabled(common.StakingV4Step1Flag) { + s.eei.AddReturnMessage("invalid method to call") + return vmcommon.UserError + } + if !bytes.Equal(args.CallerAddr, s.endOfEpochAccessAddr) { + s.eei.AddReturnMessage("stake nodes from waiting list can be called by endOfEpochAccess address only") + return vmcommon.UserError + } + if len(args.Arguments) != 0 { + s.eei.AddReturnMessage("number of arguments must be equal to 0") + return vmcommon.UserError + } + + waitingListData, err := s.getFirstElementsFromWaitingList(math.MaxUint32) + if err != nil { + s.eei.AddReturnMessage(err.Error()) + return vmcommon.UserError + } + if len(waitingListData.blsKeys) == 0 { + s.eei.AddReturnMessage("no nodes in queue") + return vmcommon.Ok + } + + nodePriceToUse := big.NewInt(0).Set(s.minNodePrice) + if s.enableEpochsHandler.IsFlagEnabled(common.CorrectLastUnJailedFlag) { + nodePriceToUse.Set(s.stakeValue) + } + + for i, blsKey := range waitingListData.blsKeys { + registrationData := waitingListData.stakedDataList[i] + + registrationData.Staked = false + registrationData.UnStakedEpoch = s.eei.BlockChainHook().CurrentEpoch() + registrationData.UnStakedNonce = s.eei.BlockChainHook().CurrentNonce() + registrationData.Waiting = false + + err = s.saveStakingData(blsKey, registrationData) + if err != nil { + s.eei.AddReturnMessage("cannot save staking data: error " + err.Error()) + return vmcommon.UserError + } + + // delete element from waiting list + inWaitingListKey := createWaitingListKey(blsKey) + s.eei.SetStorage(inWaitingListKey, nil) + } + + // delete waiting list head element + s.eei.SetStorage([]byte(waitingListHeadKey), nil) + + return vmcommon.Ok +} + func (s *stakingSC) cleanAdditionalQueue(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { if !s.enableEpochsHandler.IsFlagEnabled(common.CorrectLastUnJailedFlag) { s.eei.AddReturnMessage("invalid method to call") From a8ce97c2068647f46b138befed9fbc9a33a96fc2 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Wed, 13 Mar 2024 23:45:29 +0200 Subject: [PATCH 093/503] - fixed linter issue --- process/smartContract/scQueryService.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/process/smartContract/scQueryService.go b/process/smartContract/scQueryService.go index 10a5be173da..ec6ad67e87c 100644 --- a/process/smartContract/scQueryService.go +++ b/process/smartContract/scQueryService.go @@ -269,15 +269,6 @@ func (service *SCQueryService) recreateTrie(blockRootHash []byte, blockHeader da return accountsAdapter.RecreateTrie(blockRootHash) } -func (service *SCQueryService) getCurrentEpoch() uint32 { - header := service.mainBlockChain.GetCurrentBlockHeader() - if check.IfNil(header) { - return 0 - } - - return header.GetEpoch() -} - // TODO: extract duplicated code with nodeBlocks.go func (service *SCQueryService) extractBlockHeaderAndRootHash(query *process.SCQuery) (data.HeaderHandler, []byte, error) { if len(query.BlockHash) > 0 { From 41d8908ed6265d8aad1a37b338f81718477da4b3 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Tue, 27 Feb 2024 17:57:48 +0200 Subject: [PATCH 094/503] added script to create local-testnet with docker. --- .github/workflows/build_local_tesnet.yml | 54 ++++++ docker/node/Dockerfile | 4 +- scripts/docker-testnet/clean.sh | 16 ++ scripts/docker-testnet/helpers.sh | 153 +++++++++++++++++ scripts/docker-testnet/start.sh | 38 +++++ scripts/docker-testnet/variables.sh | 199 +++++++++++++++++++++++ 6 files changed, 461 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/build_local_tesnet.yml create mode 100755 scripts/docker-testnet/clean.sh create mode 100755 scripts/docker-testnet/helpers.sh create mode 100755 scripts/docker-testnet/start.sh create mode 100644 scripts/docker-testnet/variables.sh diff --git a/.github/workflows/build_local_tesnet.yml b/.github/workflows/build_local_tesnet.yml new file mode 100644 index 00000000000..edd77fe9026 --- /dev/null +++ b/.github/workflows/build_local_tesnet.yml @@ -0,0 +1,54 @@ +name: Build local testnet + +on: + pull_request: + branches: [ master, rc/* ] + types: [opened, ready_for_review] + push: + workflow_dispatch: + +jobs: + build: + strategy: + matrix: + runs-on: [ubuntu-latest] + runs-on: ${{ matrix.runs-on }} + name: Build + steps: + - name: Set up Go 1.20.7 + uses: actions/setup-go@v3 + with: + go-version: 1.20.7 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + + - name: Check out mx-deploy-go + uses: actions/checkout@v4 + with: + repository: multiversx/mx-chain-deploy-go + path: mx-chain-deploy-go + + - name: Check out mx-chain-proxy-go + uses: actions/checkout@v4 + with: + repository: multiversx/mx-chain-proxy-go + path: mx-chain-proxy-go + + - name: Build images + run: | + docker build -f docker/node/Dockerfile . -t node:dev + docker build -f docker/seednode/Dockerfile . -t seednode:dev + + - name: Start localnet + id: generate-config + run: | + cd ${GITHUB_WORKSPACE}/scripts/docker-testnet + export TESTNETDIR=${GITHUB_WORKSPACE}/docker-testnet + export CI_RUN=1 + ./start.sh + echo "Check everything is alright. Remove once confirmed" + docker ps + sleep 1m + curl http://localhost:7950 diff --git a/docker/node/Dockerfile b/docker/node/Dockerfile index cf6a8955c76..2513f789dc8 100644 --- a/docker/node/Dockerfile +++ b/docker/node/Dockerfile @@ -10,12 +10,10 @@ RUN go build -v -ldflags="-X main.appVersion=$(git describe --tags --long --dirt RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-v | sort -n | tail -n -1| awk -F '/' '{print$3}'| sed 's/ /@/g')/wasmer/libwasmer_linux_amd64.so /lib/libwasmer_linux_amd64.so RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-go | sort -n | tail -n -1| awk -F '/' '{print$3}'| sed 's/ /@/g')/wasmer2/libvmexeccapi.so /lib/libvmexeccapi.so -WORKDIR /go/mx-chain-go/cmd/node - # ===== SECOND STAGE ====== FROM ubuntu:22.04 RUN apt-get update && apt-get upgrade -y -COPY --from=builder "/go/mx-chain-go/cmd/node" "/go/mx-chain-go/cmd/node/" +COPY --from=builder "/go/mx-chain-go/cmd/node/node" "/go/mx-chain-go/cmd/node/" COPY --from=builder "/lib/libwasmer_linux_amd64.so" "/lib/libwasmer_linux_amd64.so" COPY --from=builder "/lib/libvmexeccapi.so" "/lib/libvmexeccapi.so" WORKDIR /go/mx-chain-go/cmd/node/ diff --git a/scripts/docker-testnet/clean.sh b/scripts/docker-testnet/clean.sh new file mode 100755 index 00000000000..a872ed57f13 --- /dev/null +++ b/scripts/docker-testnet/clean.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +# Delete the entire testnet folder, which includes configuration, executables and logs. + +export MULTIVERSXTESTNETSCRIPTSDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +source "$MULTIVERSXTESTNETSCRIPTSDIR/variables.sh" + +echo "Stopping all containers..." +docker stop $(docker ps -a -q) + +echo "Removing all containers..." +docker container prune -f + +echo "Removing $TESTNETDIR..." +rm -rf $TESTNETDIR diff --git a/scripts/docker-testnet/helpers.sh b/scripts/docker-testnet/helpers.sh new file mode 100755 index 00000000000..c7967c8c408 --- /dev/null +++ b/scripts/docker-testnet/helpers.sh @@ -0,0 +1,153 @@ +#!/usr/bin/env bash + +startSeedNode() { + docker run -d --name seednode -v ${TESTNETDIR}/seednode/config:/go/mx-chain-go/cmd/seednode/config seednode:dev \ + --rest-api-interface=0.0.0.0:10000 +} + +startObservers() { + local observerIdx=0 + # Example for loop with injected variables in Bash + for ((i = 0; i < SHARDCOUNT; i++)); do + for ((j = 0; j < SHARD_OBSERVERCOUNT; j++)); do + # Your commands or code to be executed in each iteration + KEY_INDEX=$((TOTAL_NODECOUNT - observerIdx - 1)) + + docker run -d --name "observer${observerIdx}" \ + -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ + node:dev \ + --destination-shard-as-observer $i \ + --rest-api-interface=0.0.0.0:10200 \ + --config ./config/config_observer.toml \ + --sk-index=${KEY_INDEX} \ + + ((observerIdx++)) || true + done + done + + for ((i = 0; i < META_OBSERVERCOUNT; i++)); do + KEY_INDEX=$((TOTAL_NODECOUNT - observerIdx - 1)) + + docker run -d --name "observer${observerIdx}" \ + -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ + node:dev \ + --destination-shard-as-observer "metachain" \ + --rest-api-interface=0.0.0.0:10200 \ + --config ./config/config_observer.toml \ + --sk-index=${KEY_INDEX} \ + + ((observerIdx++)) || true + done +} + +startValidators() { + validatorIdx=0 + # Example for loop with injected variables in Bash + for ((i = 0; i < SHARDCOUNT; i++)); do + for ((j = 0; j < SHARD_VALIDATORCOUNT; j++)); do + + docker run -d --name "validator${validatorIdx}" \ + -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ + node:dev \ + --rest-api-interface=0.0.0.0:10200 \ + --config ./config/config_validator.toml \ + --sk-index=${validatorIdx} \ + + ((validatorIdx++)) || true + done + done + + for ((i = 0; i < META_VALIDATORCOUNT; i++)); do + docker run -d --name "validator${validatorIdx}" \ + -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ + node:dev \ + --rest-api-interface=0.0.0.0:10200 \ + --config ./config/config_observer.toml \ + --sk-index=${validatorIdx} \ + + ((validatorIdx++)) || true + done +} + +updateProxyConfigDocker() { + pushd $TESTNETDIR/proxy/config + cp config.toml config_edit.toml + + # Truncate config.toml before the [[Observers]] list + sed -i -n '/\[\[Observers\]\]/q;p' config_edit.toml + + if [ "$SHARD_OBSERVERCOUNT" -le 0 ]; then + generateProxyValidatorListDocker config_edit.toml + else + generateProxyObserverListDocker config_edit.toml + fi + + cp config_edit.toml config.toml + rm config_edit.toml + + echo "Updated configuration for the Proxy." + popd +} + +generateProxyObserverListDocker() { + IP_BIT=3 + OUTPUTFILE=$! + + + for ((i = 0; i < SHARDCOUNT; i++)); do + for ((j = 0; j < SHARD_OBSERVERCOUNT; j++)); do + + echo "[[Observers]]" >> config_edit.toml + echo " ShardId = $i" >> config_edit.toml + echo " Address = \"http://172.17.0.${IP_BIT}:10200\"" >> config_edit.toml + echo ""$'\n' >> config_edit.toml + + (( IP_BIT++ )) + done + done + + for META_OBSERVER in $(seq $META_OBSERVERCOUNT); do + echo "[[Observers]]" >> config_edit.toml + echo " ShardId = $METASHARD_ID" >> config_edit.toml + echo " Address = \"http://172.17.0.${IP_BIT}:10200\"" >> config_edit.toml + echo ""$'\n' >> config_edit.toml + + (( IP_BIT++ )) + done +} + +generateProxyValidatorListDocker() { + IP_BIT=3 + OUTPUTFILE=$! + + + for ((i = 0; i < SHARDCOUNT; i++)); do + for ((j = 0; j < SHARD_VALIDATORCOUNT; j++)); do + + echo "[[Observers]]" >> config_edit.toml + echo " ShardId = $i" >> config_edit.toml + echo " Address = \"http://172.17.0.${IP_BIT}:10200\"" >> config_edit.toml + echo " Type = \"Validator\"" >> config_edit.toml + echo ""$'\n' >> config_edit.toml + + (( IP_BIT++ )) + done + done + + for META_OBSERVER in $(seq $META_VALIDATORCOUNT); do + echo "[[Observers]]" >> config_edit.toml + echo " ShardId = $METASHARD_ID" >> config_edit.toml + echo " Address = \"http://172.17.0.${IP_BIT}:10200\"" >> config_edit.toml + echo " Type = \"Validator\"" >> config_edit.toml + echo ""$'\n' >> config_edit.toml + + (( IP_BIT++ )) + done +} + +startProxyDocker() { + docker run -d --name "proxy" \ + -p $PORT_PROXY:8080 \ + -v $TESTNETDIR/proxy/config:/mx-chain-proxy-go/cmd/proxy/config \ + multiversx/chain-proxy:v1.1.45-sp4 +} diff --git a/scripts/docker-testnet/start.sh b/scripts/docker-testnet/start.sh new file mode 100755 index 00000000000..0181ac3c3a9 --- /dev/null +++ b/scripts/docker-testnet/start.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +set -e + +export DOCKERTESTNETDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +MULTIVERSXTESTNETSCRIPTSDIR="$(dirname "$DOCKERTESTNETDIR")/testnet" + +source "$DOCKERTESTNETDIR/variables.sh" +source "$DOCKERTESTNETDIR/helpers.sh" +source "$MULTIVERSXTESTNETSCRIPTSDIR/include/config.sh" +source "$MULTIVERSXTESTNETSCRIPTSDIR/include/build.sh" + +prepareFolders + +buildConfigGenerator + +generateConfig + +copyConfig + +copySeednodeConfig +updateSeednodeConfig + +copyNodeConfig +updateNodeConfig + +startSeedNode +startObservers +startValidators + +if [ $USE_PROXY -eq 1 ]; then + prepareFolders_Proxy + copyProxyConfig + updateProxyConfigDocker + startProxyDocker +fi + diff --git a/scripts/docker-testnet/variables.sh b/scripts/docker-testnet/variables.sh new file mode 100644 index 00000000000..f4afd395c41 --- /dev/null +++ b/scripts/docker-testnet/variables.sh @@ -0,0 +1,199 @@ +# These paths must be absolute + +# METASHARD_ID will be used to identify a shard ID as metachain +export METASHARD_ID=4294967295 + +# Path to mx-chain-go. Determined automatically. Do not change. +export MULTIVERSXDIR=$(dirname $(dirname $MULTIVERSXTESTNETSCRIPTSDIR)) + +# Enable the MultiversX Proxy. Note that this is a private repository +# (mx-chain-proxy-go). +export USE_PROXY=1 + +# Enable the MultiversX Transaction Generator. Note that this is a private +# repository (mx-chain-txgen-go). +export USE_TXGEN=0 + +# Path where the testnet will be instantiated. This folder is assumed to not +# exist, but it doesn't matter if it already does. It will be created if not, +# anyway. +export TESTNETDIR="$HOME/MultiversX/testnet" + + +# Path to mx-chain-deploy-go, branch: master. Default: near mx-chain-go. + +if [[ -n $CI_RUN ]]; then + export CONFIGGENERATORDIR="$(dirname $MULTIVERSXDIR)/mx-chain-go/mx-chain-deploy-go/cmd/filegen" +else + export CONFIGGENERATORDIR="$(dirname $MULTIVERSXDIR)/mx-chain-deploy-go/cmd/filegen" +fi + +export CONFIGGENERATOR="$CONFIGGENERATORDIR/filegen" # Leave unchanged. +export CONFIGGENERATOROUTPUTDIR="output" + +# Path to the executable node. Leave unchanged unless well justified. +export NODEDIR="$MULTIVERSXDIR/cmd/node" +export NODE="$NODEDIR/node" # Leave unchanged + +# Path to the executable seednode. Leave unchanged unless well justified. +export SEEDNODEDIR="$MULTIVERSXDIR/cmd/seednode" +export SEEDNODE="$SEEDNODEDIR/seednode" # Leave unchanged. + +# Niceness value of the Seednode, Observer Nodes and Validator Nodes. Leave +# blank to not adjust niceness. +export NODE_NICENESS=10 + +# Start a watcher daemon for each validator node, which restarts the node if it +# is suffled out of its shard. +export NODE_WATCHER=0 + +# Delays after running executables. +export SEEDNODE_DELAY=5 +export GENESIS_DELAY=30 +export HARDFORK_DELAY=900 #15 minutes enough to take export and gracefully close +export NODE_DELAY=60 + +export GENESIS_STAKE_TYPE="direct" #'delegated' or 'direct' as in direct stake + +#if set to 1, each observer will turn off the antiflooding capability, allowing spam in our network +export OBSERVERS_ANTIFLOOD_DISABLE=0 + +# Shard structure +export SHARDCOUNT=2 +export SHARD_VALIDATORCOUNT=3 +export SHARD_OBSERVERCOUNT=1 +export SHARD_CONSENSUS_SIZE=3 + +# Metashard structure +export META_VALIDATORCOUNT=3 +export META_OBSERVERCOUNT=1 +export META_CONSENSUS_SIZE=$META_VALIDATORCOUNT + +# MULTI_KEY_NODES if set to 1, one observer will be generated on each shard that will handle all generated keys +export MULTI_KEY_NODES=0 + +# EXTRA_KEYS if set to 1, extra keys will be added to the generated keys +export EXTRA_KEYS=1 + +# ALWAYS_NEW_CHAINID will generate a fresh new chain ID each time start.sh/config.sh is called +export ALWAYS_NEW_CHAINID=1 + +# ROUNDS_PER_EPOCH represents the number of rounds per epoch. If set to 0, it won't override the node's config +export ROUNDS_PER_EPOCH=0 + +# HYSTERESIS defines the hysteresis value for number of nodes in shard +export HYSTERESIS=0.0 + +# ALWAYS_NEW_APP_VERSION will set a new version each time the node will be compiled +export ALWAYS_NEW_APP_VERSION=0 + +# ALWAYS_UPDATE_CONFIGS will re-generate configs (toml + json) each time ./start.sh +# Set this variable to 0 when testing bootstrap from storage or other edge cases where you do not want a fresh new config +# each time. +export ALWAYS_UPDATE_CONFIGS=1 + +# IP of the seednode +export SEEDNODE_IP="172.17.0.2" + +# Ports used by the Nodes +export PORT_SEEDNODE="9999" +export PORT_ORIGIN_OBSERVER="21100" +export PORT_ORIGIN_OBSERVER_REST="10000" +export PORT_ORIGIN_VALIDATOR="21500" +export PORT_ORIGIN_VALIDATOR_REST="9500" + +# UI configuration profiles + +# Use tmux or not. If set to 1, only 2 terminal windows will be opened, and +# tmux will be used to display the running executables using split windows. +# Recommended. Tmux needs to be installed. +export USETMUX=1 + +# Log level for the logger in the Node. +export LOGLEVEL="*:INFO" + + +if [ "$TESTNETMODE" == "debug" ]; then + LOGLEVEL="*:DEBUG,api:INFO" +fi + +if [ "$TESTNETMODE" == "trace" ]; then + LOGLEVEL="*:TRACE" +fi + +######################################################################## +# Proxy configuration + +# Path to mx-chain-proxy-go, branch: master. Default: near mx-chain-go. +if [[ -n $CI_RUN ]]; then + export PROXYDIR="$(dirname $MULTIVERSXDIR)/mx-chain-go/mx-chain-proxy-go/cmd/proxy" +else + export PROXYDIR="$(dirname $MULTIVERSXDIR)/mx-chain-proxy-go/cmd/proxy" +fi +export PROXY=$PROXYDIR/proxy # Leave unchanged. + +export PORT_PROXY="7950" +export PROXY_DELAY=10 + + + +######################################################################## +# TxGen configuration + +# Path to mx-chain-txgen-go. Default: near mx-chain-go. +export TXGENDIR="$(dirname $MULTIVERSXDIR)/mx-chain-txgen-go/cmd/txgen" +export TXGEN=$TXGENDIR/txgen # Leave unchanged. + +export PORT_TXGEN="7951" + +export TXGEN_SCENARIOS_LINE='Scenarios = ["basic", "erc20", "esdt"]' + +# Number of accounts to be generated by txgen +export NUMACCOUNTS="250" + +# Whether txgen should regenerate its accounts when starting, or not. +# Recommended value is 1, but 0 is useful to run the txgen a second time, to +# continue a testing session on the same accounts. +export TXGEN_REGENERATE_ACCOUNTS=0 + +# COPY_BACK_CONFIGS when set to 1 will copy back the configs and keys to the ./cmd/node/config directory +# in order to have a node in the IDE that can run a node in debug mode but in the same network with the rest of the nodes +# this option greatly helps the debugging process when running a small system test +export COPY_BACK_CONFIGS=0 +# SKIP_VALIDATOR_IDX when setting a value greater than -1 will not launch the validator with the provided index +export SKIP_VALIDATOR_IDX=-1 +# SKIP_OBSERVER_IDX when setting a value greater than -1 will not launch the observer with the provided index +export SKIP_OBSERVER_IDX=-1 + +# USE_HARDFORK will prepare the nodes to run the hardfork process, if needed +export USE_HARDFORK=1 + +# Load local overrides, .gitignored +LOCAL_OVERRIDES="$MULTIVERSXTESTNETSCRIPTSDIR/local.sh" +if [ -f "$LOCAL_OVERRIDES" ]; then + source "$MULTIVERSXTESTNETSCRIPTSDIR/local.sh" +fi + +# Leave unchanged. +let "total_observer_count = $SHARD_OBSERVERCOUNT * $SHARDCOUNT + $META_OBSERVERCOUNT" +export TOTAL_OBSERVERCOUNT=$total_observer_count + +# to enable the full archive feature on the observers, please use the --full-archive flag +export EXTRA_OBSERVERS_FLAGS="-operation-mode db-lookup-extension" + +if [[ $MULTI_KEY_NODES -eq 1 ]]; then + EXTRA_OBSERVERS_FLAGS="--no-key" +fi + +# Leave unchanged. +let "total_node_count = $SHARD_VALIDATORCOUNT * $SHARDCOUNT + $META_VALIDATORCOUNT + $TOTAL_OBSERVERCOUNT" +export TOTAL_NODECOUNT=$total_node_count + +# VALIDATOR_KEY_PEM_FILE is the pem file name when running single key mode, with all nodes' keys +export VALIDATOR_KEY_PEM_FILE="validatorKey.pem" + +# MULTI_KEY_PEM_FILE is the pem file name when running multi key mode, with all managed +export MULTI_KEY_PEM_FILE="allValidatorsKeys.pem" + +# EXTRA_KEY_PEM_FILE is the pem file name when running multi key mode, with all extra managed +export EXTRA_KEY_PEM_FILE="extraValidatorsKeys.pem" From 29367f37e3a771c6286d88bfad909e9b86c0009b Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 14 Mar 2024 10:14:32 +0200 Subject: [PATCH 095/503] remove CI to build local testnet. --- .github/workflows/build_local_tesnet.yml | 54 ------------------------ 1 file changed, 54 deletions(-) delete mode 100644 .github/workflows/build_local_tesnet.yml diff --git a/.github/workflows/build_local_tesnet.yml b/.github/workflows/build_local_tesnet.yml deleted file mode 100644 index edd77fe9026..00000000000 --- a/.github/workflows/build_local_tesnet.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: Build local testnet - -on: - pull_request: - branches: [ master, rc/* ] - types: [opened, ready_for_review] - push: - workflow_dispatch: - -jobs: - build: - strategy: - matrix: - runs-on: [ubuntu-latest] - runs-on: ${{ matrix.runs-on }} - name: Build - steps: - - name: Set up Go 1.20.7 - uses: actions/setup-go@v3 - with: - go-version: 1.20.7 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v4 - - - name: Check out mx-deploy-go - uses: actions/checkout@v4 - with: - repository: multiversx/mx-chain-deploy-go - path: mx-chain-deploy-go - - - name: Check out mx-chain-proxy-go - uses: actions/checkout@v4 - with: - repository: multiversx/mx-chain-proxy-go - path: mx-chain-proxy-go - - - name: Build images - run: | - docker build -f docker/node/Dockerfile . -t node:dev - docker build -f docker/seednode/Dockerfile . -t seednode:dev - - - name: Start localnet - id: generate-config - run: | - cd ${GITHUB_WORKSPACE}/scripts/docker-testnet - export TESTNETDIR=${GITHUB_WORKSPACE}/docker-testnet - export CI_RUN=1 - ./start.sh - echo "Check everything is alright. Remove once confirmed" - docker ps - sleep 1m - curl http://localhost:7950 From d13ca146479cb5cd380551753719eac2bdf3796b Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 14 Mar 2024 10:49:05 +0200 Subject: [PATCH 096/503] cosmetic changes. --- scripts/docker-testnet/{helpers.sh => functions.sh} | 3 +-- scripts/docker-testnet/start.sh | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) rename scripts/docker-testnet/{helpers.sh => functions.sh} (98%) diff --git a/scripts/docker-testnet/helpers.sh b/scripts/docker-testnet/functions.sh similarity index 98% rename from scripts/docker-testnet/helpers.sh rename to scripts/docker-testnet/functions.sh index c7967c8c408..d16c7977866 100755 --- a/scripts/docker-testnet/helpers.sh +++ b/scripts/docker-testnet/functions.sh @@ -82,8 +82,7 @@ updateProxyConfigDocker() { generateProxyObserverListDocker config_edit.toml fi - cp config_edit.toml config.toml - rm config_edit.toml + mv config_edit.toml config.toml echo "Updated configuration for the Proxy." popd diff --git a/scripts/docker-testnet/start.sh b/scripts/docker-testnet/start.sh index 0181ac3c3a9..1a9e2f84fc7 100755 --- a/scripts/docker-testnet/start.sh +++ b/scripts/docker-testnet/start.sh @@ -7,7 +7,7 @@ export DOCKERTESTNETDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>& MULTIVERSXTESTNETSCRIPTSDIR="$(dirname "$DOCKERTESTNETDIR")/testnet" source "$DOCKERTESTNETDIR/variables.sh" -source "$DOCKERTESTNETDIR/helpers.sh" +source "$DOCKERTESTNETDIR/functions.sh" source "$MULTIVERSXTESTNETSCRIPTSDIR/include/config.sh" source "$MULTIVERSXTESTNETSCRIPTSDIR/include/build.sh" From 42d2b78cff3452f2a807ce740aba860c2d8c4def Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 14 Mar 2024 10:52:54 +0200 Subject: [PATCH 097/503] added build.sh --- scripts/docker-testnet/build.sh | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 scripts/docker-testnet/build.sh diff --git a/scripts/docker-testnet/build.sh b/scripts/docker-testnet/build.sh new file mode 100644 index 00000000000..5ca3246742d --- /dev/null +++ b/scripts/docker-testnet/build.sh @@ -0,0 +1,5 @@ +pushd ../.. + +docker build -f docker/seednode/Dockerfile . -t seednode:dev + +ocker build -f docker/node/Dockerfile . -t node:dev \ No newline at end of file From a77aef731abc837e63982f172e13afbe9ee1cd9f Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 14 Mar 2024 10:58:02 +0200 Subject: [PATCH 098/503] fixed typo. --- scripts/docker-testnet/build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/docker-testnet/build.sh b/scripts/docker-testnet/build.sh index 5ca3246742d..34fdbc5b717 100644 --- a/scripts/docker-testnet/build.sh +++ b/scripts/docker-testnet/build.sh @@ -2,4 +2,4 @@ pushd ../.. docker build -f docker/seednode/Dockerfile . -t seednode:dev -ocker build -f docker/node/Dockerfile . -t node:dev \ No newline at end of file +docker build -f docker/node/Dockerfile . -t node:dev \ No newline at end of file From b8cf3725dbdf887ced035b1f6046080fc7670f5e Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 14 Mar 2024 11:10:33 +0200 Subject: [PATCH 099/503] added execution permissions on build.sh --- scripts/docker-testnet/build.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/docker-testnet/build.sh diff --git a/scripts/docker-testnet/build.sh b/scripts/docker-testnet/build.sh old mode 100644 new mode 100755 From 4f5330331dcf6358f1ff1e99133a0fb02243760c Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 14 Mar 2024 13:13:46 +0200 Subject: [PATCH 100/503] changed containers name for better visibility. --- scripts/docker-testnet/build.sh | 3 +- scripts/docker-testnet/functions.sh | 48 ++++++++++++++++++++--------- scripts/docker-testnet/start.sh | 2 ++ 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/scripts/docker-testnet/build.sh b/scripts/docker-testnet/build.sh index 34fdbc5b717..605db92580a 100755 --- a/scripts/docker-testnet/build.sh +++ b/scripts/docker-testnet/build.sh @@ -2,4 +2,5 @@ pushd ../.. docker build -f docker/seednode/Dockerfile . -t seednode:dev -docker build -f docker/node/Dockerfile . -t node:dev \ No newline at end of file +docker build -f docker/node/Dockerfile . -t node:dev + diff --git a/scripts/docker-testnet/functions.sh b/scripts/docker-testnet/functions.sh index d16c7977866..601707218ef 100755 --- a/scripts/docker-testnet/functions.sh +++ b/scripts/docker-testnet/functions.sh @@ -1,5 +1,18 @@ #!/usr/bin/env bash +IP_BIT=3 + +cloneRepositories() { + if [[ -n $CI_RUN ]]; then + echo "Repositories have been cloned in the CI" + else + cd $(dirname $MULTIVERSXDIR) + + git clone git@github.com:multiversx/mx-chain-deploy-go.git || true + git clone git@github.com:multiversx/mx-chain-proxy-go.git || true + fi +} + startSeedNode() { docker run -d --name seednode -v ${TESTNETDIR}/seednode/config:/go/mx-chain-go/cmd/seednode/config seednode:dev \ --rest-api-interface=0.0.0.0:10000 @@ -13,14 +26,17 @@ startObservers() { # Your commands or code to be executed in each iteration KEY_INDEX=$((TOTAL_NODECOUNT - observerIdx - 1)) - docker run -d --name "observer${observerIdx}" \ + docker run -d --name "observer${observerIdx}-172.17.0.${IP_BIT}-10200-shard${i}" \ -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ node:dev \ --destination-shard-as-observer $i \ --rest-api-interface=0.0.0.0:10200 \ --config ./config/config_observer.toml \ --sk-index=${KEY_INDEX} \ + $EXTRA_OBSERVERS_FLAGS + + (( IP_BIT++ )) ((observerIdx++)) || true done done @@ -28,14 +44,16 @@ startObservers() { for ((i = 0; i < META_OBSERVERCOUNT; i++)); do KEY_INDEX=$((TOTAL_NODECOUNT - observerIdx - 1)) - docker run -d --name "observer${observerIdx}" \ + docker run -d --name "observer${observerIdx}-172.17.0.${IP_BIT}-10200-metachain" \ -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ node:dev \ --destination-shard-as-observer "metachain" \ --rest-api-interface=0.0.0.0:10200 \ --config ./config/config_observer.toml \ --sk-index=${KEY_INDEX} \ + $EXTRA_OBSERVERS_FLAGS + (( IP_BIT++ )) ((observerIdx++)) || true done } @@ -46,25 +64,27 @@ startValidators() { for ((i = 0; i < SHARDCOUNT; i++)); do for ((j = 0; j < SHARD_VALIDATORCOUNT; j++)); do - docker run -d --name "validator${validatorIdx}" \ + docker run -d --name "validator${validatorIdx}-172.17.0.${IP_BIT}-10200-shard${i}" \ -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ node:dev \ --rest-api-interface=0.0.0.0:10200 \ --config ./config/config_validator.toml \ --sk-index=${validatorIdx} \ + (( IP_BIT++ )) ((validatorIdx++)) || true done done for ((i = 0; i < META_VALIDATORCOUNT; i++)); do - docker run -d --name "validator${validatorIdx}" \ + docker run -d --name "validator${validatorIdx}-172.17.0.${IP_BIT}-10200-metachain" \ -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ node:dev \ --rest-api-interface=0.0.0.0:10200 \ --config ./config/config_observer.toml \ --sk-index=${validatorIdx} \ + (( IP_BIT++ )) ((validatorIdx++)) || true done } @@ -89,7 +109,7 @@ updateProxyConfigDocker() { } generateProxyObserverListDocker() { - IP_BIT=3 + local ipBit=3 OUTPUTFILE=$! @@ -98,25 +118,25 @@ generateProxyObserverListDocker() { echo "[[Observers]]" >> config_edit.toml echo " ShardId = $i" >> config_edit.toml - echo " Address = \"http://172.17.0.${IP_BIT}:10200\"" >> config_edit.toml + echo " Address = \"http://172.17.0.${ipBit}:10200\"" >> config_edit.toml echo ""$'\n' >> config_edit.toml - (( IP_BIT++ )) + (( ipBit++ )) || true done done for META_OBSERVER in $(seq $META_OBSERVERCOUNT); do echo "[[Observers]]" >> config_edit.toml echo " ShardId = $METASHARD_ID" >> config_edit.toml - echo " Address = \"http://172.17.0.${IP_BIT}:10200\"" >> config_edit.toml + echo " Address = \"http://172.17.0.${ipBit}:10200\"" >> config_edit.toml echo ""$'\n' >> config_edit.toml - (( IP_BIT++ )) + (( ipBit++ )) || true done } generateProxyValidatorListDocker() { - IP_BIT=3 + local ipBit=3 OUTPUTFILE=$! @@ -125,22 +145,22 @@ generateProxyValidatorListDocker() { echo "[[Observers]]" >> config_edit.toml echo " ShardId = $i" >> config_edit.toml - echo " Address = \"http://172.17.0.${IP_BIT}:10200\"" >> config_edit.toml + echo " Address = \"http://172.17.0.${ipBit}:10200\"" >> config_edit.toml echo " Type = \"Validator\"" >> config_edit.toml echo ""$'\n' >> config_edit.toml - (( IP_BIT++ )) + (( ipBit++ )) || true done done for META_OBSERVER in $(seq $META_VALIDATORCOUNT); do echo "[[Observers]]" >> config_edit.toml echo " ShardId = $METASHARD_ID" >> config_edit.toml - echo " Address = \"http://172.17.0.${IP_BIT}:10200\"" >> config_edit.toml + echo " Address = \"http://172.17.0.${ipBit}:10200\"" >> config_edit.toml echo " Type = \"Validator\"" >> config_edit.toml echo ""$'\n' >> config_edit.toml - (( IP_BIT++ )) + (( ipBit++ )) || true done } diff --git a/scripts/docker-testnet/start.sh b/scripts/docker-testnet/start.sh index 1a9e2f84fc7..02e107c4229 100755 --- a/scripts/docker-testnet/start.sh +++ b/scripts/docker-testnet/start.sh @@ -11,6 +11,8 @@ source "$DOCKERTESTNETDIR/functions.sh" source "$MULTIVERSXTESTNETSCRIPTSDIR/include/config.sh" source "$MULTIVERSXTESTNETSCRIPTSDIR/include/build.sh" +cloneRepositories + prepareFolders buildConfigGenerator From f93e5d8273c588aa5dbafc5f0c8dc0b3e6073964 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 14 Mar 2024 14:08:06 +0200 Subject: [PATCH 101/503] fix after review --- epochStart/metachain/systemSCs.go | 11 +- vm/systemSmartContracts/stakingWaitingList.go | 6 - vm/systemSmartContracts/staking_test.go | 155 ++++++++++++++++++ 3 files changed, 158 insertions(+), 14 deletions(-) diff --git a/epochStart/metachain/systemSCs.go b/epochStart/metachain/systemSCs.go index b43055aba3a..229a41d5710 100644 --- a/epochStart/metachain/systemSCs.go +++ b/epochStart/metachain/systemSCs.go @@ -181,18 +181,13 @@ func (s *systemSCProcessor) unStakeAllNodesFromQueue() error { } vmOutput, errRun := s.systemVM.RunSmartContractCall(vmInput) if errRun != nil { - return fmt.Errorf("%w when unStaking all nodes from waiting list", errRun) + return fmt.Errorf("%w when unStaking all nodes from staking queue", errRun) } if vmOutput.ReturnCode != vmcommon.Ok { - return fmt.Errorf("got return code %s when unStaking all nodes from waiting list", vmOutput.ReturnCode) + return fmt.Errorf("got return code %s when unStaking all nodes from staking queue", vmOutput.ReturnCode) } - err := s.processSCOutputAccounts(vmOutput) - if err != nil { - return err - } - - return nil + return s.processSCOutputAccounts(vmOutput) } func (s *systemSCProcessor) unStakeNodesWithNotEnoughFundsWithStakingV4( diff --git a/vm/systemSmartContracts/stakingWaitingList.go b/vm/systemSmartContracts/stakingWaitingList.go index 279b5a7db0c..49cb6e85e9a 100644 --- a/vm/systemSmartContracts/stakingWaitingList.go +++ b/vm/systemSmartContracts/stakingWaitingList.go @@ -821,15 +821,9 @@ func (s *stakingSC) unStakeAllNodesFromQueue(args *vmcommon.ContractCallInput) v return vmcommon.UserError } if len(waitingListData.blsKeys) == 0 { - s.eei.AddReturnMessage("no nodes in queue") return vmcommon.Ok } - nodePriceToUse := big.NewInt(0).Set(s.minNodePrice) - if s.enableEpochsHandler.IsFlagEnabled(common.CorrectLastUnJailedFlag) { - nodePriceToUse.Set(s.stakeValue) - } - for i, blsKey := range waitingListData.blsKeys { registrationData := waitingListData.stakedDataList[i] diff --git a/vm/systemSmartContracts/staking_test.go b/vm/systemSmartContracts/staking_test.go index c5419dddd20..ab1853cc71d 100644 --- a/vm/systemSmartContracts/staking_test.go +++ b/vm/systemSmartContracts/staking_test.go @@ -3591,3 +3591,158 @@ func TestStakingSc_fixMissingNodeAddAsLast(t *testing.T) { assert.Equal(t, len(waitingListData.blsKeys), 4) assert.Equal(t, waitingListData.blsKeys[3], blsKey) } + +func TestStakingSC_UnStakeAllFromQueueErrors(t *testing.T) { + t.Parallel() + + blockChainHook := &mock.BlockChainHookStub{} + blockChainHook.GetStorageDataCalled = func(accountsAddress []byte, index []byte) ([]byte, uint32, error) { + return nil, 0, nil + } + + eei := createDefaultEei() + eei.blockChainHook = blockChainHook + eei.SetSCAddress([]byte("addr")) + + stakingAccessAddress := vm.ValidatorSCAddress + args := createMockStakingScArguments() + args.StakingAccessAddr = stakingAccessAddress + args.StakingSCConfig.MaxNumberOfNodesForStake = 1 + enableEpochsHandler, _ := args.EnableEpochsHandler.(*enableEpochsHandlerMock.EnableEpochsHandlerStub) + + args.Eei = eei + args.StakingSCConfig.UnBondPeriod = 100 + sc, _ := NewStakingSmartContract(args) + + vmInput := CreateVmContractCallInput() + vmInput.Function = "unStakeAllNodesFromQueue" + + returnCode := sc.Execute(vmInput) + require.Equal(t, returnCode, vmcommon.UserError) + require.Equal(t, eei.returnMessage, "invalid method to call") + + eei.returnMessage = "" + enableEpochsHandler.AddActiveFlags(common.StakingV4Step1Flag) + returnCode = sc.Execute(vmInput) + require.Equal(t, returnCode, vmcommon.UserError) + require.Equal(t, eei.returnMessage, "stake nodes from waiting list can be called by endOfEpochAccess address only") + + eei.returnMessage = "" + vmInput.CallerAddr = vm.EndOfEpochAddress + vmInput.Arguments = [][]byte{{1}} + returnCode = sc.Execute(vmInput) + require.Equal(t, returnCode, vmcommon.UserError) + require.Equal(t, eei.returnMessage, "number of arguments must be equal to 0") + + vmInput.Arguments = [][]byte{} + returnCode = sc.Execute(vmInput) + require.Equal(t, returnCode, vmcommon.Ok) +} + +func TestStakingSc_UnStakeAllFromQueue(t *testing.T) { + t.Parallel() + + blockChainHook := &mock.BlockChainHookStub{} + blockChainHook.GetStorageDataCalled = func(accountsAddress []byte, index []byte) ([]byte, uint32, error) { + return nil, 0, nil + } + + eei := createDefaultEei() + eei.blockChainHook = blockChainHook + eei.SetSCAddress([]byte("addr")) + + stakingAccessAddress := vm.ValidatorSCAddress + args := createMockStakingScArguments() + args.StakingAccessAddr = stakingAccessAddress + args.StakingSCConfig.MaxNumberOfNodesForStake = 1 + enableEpochsHandler, _ := args.EnableEpochsHandler.(*enableEpochsHandlerMock.EnableEpochsHandlerStub) + enableEpochsHandler.AddActiveFlags(common.StakingV4Step1Flag) + args.Eei = eei + args.StakingSCConfig.UnBondPeriod = 100 + stakingSmartContract, _ := NewStakingSmartContract(args) + + stakerAddress := []byte("stakerAddr") + + blockChainHook.CurrentNonceCalled = func() uint64 { + return 1 + } + + // do stake should work + doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("firsstKey")) + doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("secondKey")) + doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("thirdKeyy")) + doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("fourthKey")) + + waitingReturn := doGetWaitingListRegisterNonceAndRewardAddress(t, stakingSmartContract, eei) + assert.Equal(t, len(waitingReturn), 9) + + arguments := CreateVmContractCallInput() + validatorData := &ValidatorDataV2{ + TotalStakeValue: big.NewInt(200), + TotalUnstaked: big.NewInt(0), + RewardAddress: stakerAddress, + BlsPubKeys: [][]byte{[]byte("firsstKey"), []byte("secondKey"), []byte("thirdKeyy"), []byte("fourthKey")}, + } + marshaledData, _ := stakingSmartContract.marshalizer.Marshal(validatorData) + eei.SetStorageForAddress(vm.ValidatorSCAddress, stakerAddress, marshaledData) + + currentOutPutIndex := len(eei.output) + + arguments.Function = "unStakeAllNodesFromQueue" + retCode := stakingSmartContract.Execute(arguments) + assert.Equal(t, retCode, vmcommon.Ok) + + // nothing to stake - as not enough funds - one remains in waiting queue + assert.Equal(t, currentOutPutIndex, len(eei.output)) + + cleanAdditionalInput := CreateVmContractCallInput() + cleanAdditionalInput.Function = "cleanAdditionalQueue" + cleanAdditionalInput.CallerAddr = args.EndOfEpochAccessAddr + retCode = stakingSmartContract.Execute(cleanAdditionalInput) + assert.Equal(t, retCode, vmcommon.Ok) + + newHead, _ := stakingSmartContract.getWaitingListHead() + assert.Equal(t, uint32(1), newHead.Length) + + doGetStatus(t, stakingSmartContract, eei, []byte("secondKey"), "queued") + + newMaxNodes = int64(1) + arguments = CreateVmContractCallInput() + arguments.Function = "updateConfigMaxNodes" + arguments.CallerAddr = args.EndOfEpochAccessAddr + arguments.Arguments = [][]byte{big.NewInt(0).SetInt64(newMaxNodes).Bytes()} + retCode = stakingSmartContract.Execute(arguments) + assert.Equal(t, retCode, vmcommon.Ok) + + // stake them again - as they were deleted from waiting list + doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("thirdKeyy")) + doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("fourthKey")) + + validatorData = &ValidatorDataV2{ + TotalStakeValue: big.NewInt(400), + } + marshaledData, _ = stakingSmartContract.marshalizer.Marshal(validatorData) + eei.SetStorageForAddress(vm.ValidatorSCAddress, stakerAddress, marshaledData) + + newMaxNodes = int64(100) + arguments.Arguments = [][]byte{big.NewInt(0).SetInt64(newMaxNodes).Bytes()} + retCode = stakingSmartContract.Execute(arguments) + assert.Equal(t, retCode, vmcommon.Ok) + + currentOutPutIndex = len(eei.output) + arguments.Function = "stakeNodesFromQueue" + retCode = stakingSmartContract.Execute(arguments) + assert.Equal(t, retCode, vmcommon.Ok) + + for i := currentOutPutIndex; i < len(eei.output); i += 2 { + checkIsStaked(t, stakingSmartContract, arguments.CallerAddr, eei.output[i], vmcommon.Ok) + } + assert.Equal(t, 6, len(eei.output)-currentOutPutIndex) + stakingConfig := stakingSmartContract.getConfig() + assert.Equal(t, stakingConfig.StakedNodes, int64(4)) + + retCode = stakingSmartContract.Execute(cleanAdditionalInput) + assert.Equal(t, retCode, vmcommon.Ok) + newHead, _ = stakingSmartContract.getWaitingListHead() + assert.Equal(t, uint32(0), newHead.Length) +} From c2f8310d73ed952ceb1d045791491df777abfded Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 14 Mar 2024 14:13:21 +0200 Subject: [PATCH 102/503] starting unit tests --- vm/systemSmartContracts/staking_test.go | 46 ++----------------------- 1 file changed, 2 insertions(+), 44 deletions(-) diff --git a/vm/systemSmartContracts/staking_test.go b/vm/systemSmartContracts/staking_test.go index ab1853cc71d..c3dd1cd19d0 100644 --- a/vm/systemSmartContracts/staking_test.go +++ b/vm/systemSmartContracts/staking_test.go @@ -3673,8 +3673,8 @@ func TestStakingSc_UnStakeAllFromQueue(t *testing.T) { doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("thirdKeyy")) doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("fourthKey")) - waitingReturn := doGetWaitingListRegisterNonceAndRewardAddress(t, stakingSmartContract, eei) - assert.Equal(t, len(waitingReturn), 9) + waitingListHead, _ := stakingSmartContract.getWaitingListHead() + require.Equal(t, waitingListHead.Length, 3) arguments := CreateVmContractCallInput() validatorData := &ValidatorDataV2{ @@ -3692,43 +3692,6 @@ func TestStakingSc_UnStakeAllFromQueue(t *testing.T) { retCode := stakingSmartContract.Execute(arguments) assert.Equal(t, retCode, vmcommon.Ok) - // nothing to stake - as not enough funds - one remains in waiting queue - assert.Equal(t, currentOutPutIndex, len(eei.output)) - - cleanAdditionalInput := CreateVmContractCallInput() - cleanAdditionalInput.Function = "cleanAdditionalQueue" - cleanAdditionalInput.CallerAddr = args.EndOfEpochAccessAddr - retCode = stakingSmartContract.Execute(cleanAdditionalInput) - assert.Equal(t, retCode, vmcommon.Ok) - - newHead, _ := stakingSmartContract.getWaitingListHead() - assert.Equal(t, uint32(1), newHead.Length) - - doGetStatus(t, stakingSmartContract, eei, []byte("secondKey"), "queued") - - newMaxNodes = int64(1) - arguments = CreateVmContractCallInput() - arguments.Function = "updateConfigMaxNodes" - arguments.CallerAddr = args.EndOfEpochAccessAddr - arguments.Arguments = [][]byte{big.NewInt(0).SetInt64(newMaxNodes).Bytes()} - retCode = stakingSmartContract.Execute(arguments) - assert.Equal(t, retCode, vmcommon.Ok) - - // stake them again - as they were deleted from waiting list - doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("thirdKeyy")) - doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("fourthKey")) - - validatorData = &ValidatorDataV2{ - TotalStakeValue: big.NewInt(400), - } - marshaledData, _ = stakingSmartContract.marshalizer.Marshal(validatorData) - eei.SetStorageForAddress(vm.ValidatorSCAddress, stakerAddress, marshaledData) - - newMaxNodes = int64(100) - arguments.Arguments = [][]byte{big.NewInt(0).SetInt64(newMaxNodes).Bytes()} - retCode = stakingSmartContract.Execute(arguments) - assert.Equal(t, retCode, vmcommon.Ok) - currentOutPutIndex = len(eei.output) arguments.Function = "stakeNodesFromQueue" retCode = stakingSmartContract.Execute(arguments) @@ -3740,9 +3703,4 @@ func TestStakingSc_UnStakeAllFromQueue(t *testing.T) { assert.Equal(t, 6, len(eei.output)-currentOutPutIndex) stakingConfig := stakingSmartContract.getConfig() assert.Equal(t, stakingConfig.StakedNodes, int64(4)) - - retCode = stakingSmartContract.Execute(cleanAdditionalInput) - assert.Equal(t, retCode, vmcommon.Ok) - newHead, _ = stakingSmartContract.getWaitingListHead() - assert.Equal(t, uint32(0), newHead.Length) } From b9cab5ca67d010a44042a7be7c4648f104a0cfb2 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Thu, 14 Mar 2024 15:06:22 +0200 Subject: [PATCH 103/503] - duplicated code reduction - fixed unit tests - fixed integration tests --- .../chainSimulator/staking/jail_test.go | 7 +-- .../staking/simpleStake_test.go | 22 +++++++- vm/systemSmartContracts/staking.go | 5 ++ vm/systemSmartContracts/stakingWaitingList.go | 12 ++--- vm/systemSmartContracts/staking_test.go | 51 +++++-------------- 5 files changed, 45 insertions(+), 52 deletions(-) diff --git a/integrationTests/chainSimulator/staking/jail_test.go b/integrationTests/chainSimulator/staking/jail_test.go index c2e6b13e9d1..185365912b1 100644 --- a/integrationTests/chainSimulator/staking/jail_test.go +++ b/integrationTests/chainSimulator/staking/jail_test.go @@ -9,6 +9,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator" @@ -145,7 +146,7 @@ func testChainSimulatorJailAndUnJail(t *testing.T, targetEpoch int32, nodeStatus // Add a new node and wait until the node get jailed // Add a second node to take the place of the jailed node // UnJail the first node --> should go in queue -// Activate staking v4 step 1 --> node should be moved from queue to auction list +// Activate staking v4 step 1 --> node should be unstaked as the queue is cleaned up // Internal test scenario #2 func TestChainSimulator_FromQueueToAuctionList(t *testing.T) { @@ -241,9 +242,9 @@ func TestChainSimulator_FromQueueToAuctionList(t *testing.T) { require.Nil(t, err) status = getBLSKeyStatus(t, metachainNode, decodedBLSKey0) - require.Equal(t, "staked", status) + require.Equal(t, unStakedStatus, status) - checkValidatorStatus(t, cs, blsKeys[0], "auction") + checkValidatorStatus(t, cs, blsKeys[0], string(common.InactiveList)) } func checkValidatorStatus(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, blsKey string, expectedStatus string) { diff --git a/integrationTests/chainSimulator/staking/simpleStake_test.go b/integrationTests/chainSimulator/staking/simpleStake_test.go index 6439e14d623..f81635ec2b7 100644 --- a/integrationTests/chainSimulator/staking/simpleStake_test.go +++ b/integrationTests/chainSimulator/staking/simpleStake_test.go @@ -139,8 +139,9 @@ func testChainSimulatorSimpleStake(t *testing.T, targetEpoch int32, nodesStatus // - 2 nodes to shuffle per shard // - max num nodes config for stakingV4 step3 = 24 (being downsized from previously 32 nodes) // Steps: -// 1. Stake 1 node and check that in stakingV4 step1 it is found in auction -// 2. From stakingV4 step2 onwards, check that api returns 8 qualified + 1 unqualified nodes +// 1. Stake 1 node and check that in stakingV4 step1 it is unstaked +// 2. Re-stake the node to enter the auction list +// 3. From stakingV4 step2 onwards, check that api returns 8 qualified + 1 unqualified nodes func TestChainSimulator_StakingV4Step2APICalls(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") @@ -211,6 +212,23 @@ func TestChainSimulator_StakingV4Step2APICalls(t *testing.T) { require.Nil(t, err) auctionList, err := metachainNode.GetProcessComponents().ValidatorsProvider().GetAuctionList() require.Nil(t, err) + require.Empty(t, auctionList) + + // re-stake the node + txDataField = fmt.Sprintf("reStakeUnStakedNodes@%s", blsKeys[0]) + txReStake := generateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, big.NewInt(0), txDataField, gasLimitForStakeOperation) + reStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txReStake, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, reStakeTx) + + err = cs.GenerateBlocks(2) + require.Nil(t, err) + + // after the re-stake process, the node should be in auction list + err = metachainNode.GetProcessComponents().ValidatorsProvider().ForceUpdate() + require.Nil(t, err) + auctionList, err = metachainNode.GetProcessComponents().ValidatorsProvider().GetAuctionList() + require.Nil(t, err) require.Equal(t, []*common.AuctionListValidatorAPIResponse{ { Owner: validatorOwner.Bech32, diff --git a/vm/systemSmartContracts/staking.go b/vm/systemSmartContracts/staking.go index a1597d2cedb..7acfb492d15 100644 --- a/vm/systemSmartContracts/staking.go +++ b/vm/systemSmartContracts/staking.go @@ -649,6 +649,11 @@ func (s *stakingSC) tryUnStake(key []byte, registrationData *StakedDataV2_0) vmc } s.removeFromStakedNodes() + + return s.doUnStake(key, registrationData) +} + +func (s *stakingSC) doUnStake(key []byte, registrationData *StakedDataV2_0) vmcommon.ReturnCode { registrationData.Staked = false registrationData.UnStakedEpoch = s.eei.BlockChainHook().CurrentEpoch() registrationData.UnStakedNonce = s.eei.BlockChainHook().CurrentNonce() diff --git a/vm/systemSmartContracts/stakingWaitingList.go b/vm/systemSmartContracts/stakingWaitingList.go index 49cb6e85e9a..e1d0ff00cb4 100644 --- a/vm/systemSmartContracts/stakingWaitingList.go +++ b/vm/systemSmartContracts/stakingWaitingList.go @@ -827,15 +827,9 @@ func (s *stakingSC) unStakeAllNodesFromQueue(args *vmcommon.ContractCallInput) v for i, blsKey := range waitingListData.blsKeys { registrationData := waitingListData.stakedDataList[i] - registrationData.Staked = false - registrationData.UnStakedEpoch = s.eei.BlockChainHook().CurrentEpoch() - registrationData.UnStakedNonce = s.eei.BlockChainHook().CurrentNonce() - registrationData.Waiting = false - - err = s.saveStakingData(blsKey, registrationData) - if err != nil { - s.eei.AddReturnMessage("cannot save staking data: error " + err.Error()) - return vmcommon.UserError + result := s.doUnStake(blsKey, registrationData) + if result != vmcommon.Ok { + return result } // delete element from waiting list diff --git a/vm/systemSmartContracts/staking_test.go b/vm/systemSmartContracts/staking_test.go index ab1853cc71d..6459cf948c9 100644 --- a/vm/systemSmartContracts/staking_test.go +++ b/vm/systemSmartContracts/staking_test.go @@ -3224,7 +3224,7 @@ func doGetStatus(t *testing.T, sc *stakingSC, eei *vmContext, blsKey []byte, exp assert.Equal(t, vmcommon.Ok, retCode) lastOutput := eei.output[len(eei.output)-1] - assert.True(t, bytes.Equal(lastOutput, []byte(expectedStatus))) + assert.Equal(t, expectedStatus, string(lastOutput)) } func doGetWaitingListSize(t *testing.T, sc *stakingSC, eei *vmContext, expectedSize int) { @@ -3628,11 +3628,11 @@ func TestStakingSC_UnStakeAllFromQueueErrors(t *testing.T) { require.Equal(t, eei.returnMessage, "stake nodes from waiting list can be called by endOfEpochAccess address only") eei.returnMessage = "" - vmInput.CallerAddr = vm.EndOfEpochAddress + vmInput.CallerAddr = []byte("endOfEpoch") vmInput.Arguments = [][]byte{{1}} returnCode = sc.Execute(vmInput) require.Equal(t, returnCode, vmcommon.UserError) - require.Equal(t, eei.returnMessage, "number of arguments must be equal to 0") + require.Equal(t, "number of arguments must be equal to 0", eei.returnMessage) vmInput.Arguments = [][]byte{} returnCode = sc.Execute(vmInput) @@ -3668,9 +3668,9 @@ func TestStakingSc_UnStakeAllFromQueue(t *testing.T) { } // do stake should work - doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("firsstKey")) + doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("firstKey ")) doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("secondKey")) - doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("thirdKeyy")) + doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("thirdKey ")) doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("fourthKey")) waitingReturn := doGetWaitingListRegisterNonceAndRewardAddress(t, stakingSmartContract, eei) @@ -3681,8 +3681,9 @@ func TestStakingSc_UnStakeAllFromQueue(t *testing.T) { TotalStakeValue: big.NewInt(200), TotalUnstaked: big.NewInt(0), RewardAddress: stakerAddress, - BlsPubKeys: [][]byte{[]byte("firsstKey"), []byte("secondKey"), []byte("thirdKeyy"), []byte("fourthKey")}, + BlsPubKeys: [][]byte{[]byte("firstKey "), []byte("secondKey"), []byte("thirdKey "), []byte("fourthKey")}, } + arguments.CallerAddr = []byte("endOfEpoch") marshaledData, _ := stakingSmartContract.marshalizer.Marshal(validatorData) eei.SetStorageForAddress(vm.ValidatorSCAddress, stakerAddress, marshaledData) @@ -3702,20 +3703,12 @@ func TestStakingSc_UnStakeAllFromQueue(t *testing.T) { assert.Equal(t, retCode, vmcommon.Ok) newHead, _ := stakingSmartContract.getWaitingListHead() - assert.Equal(t, uint32(1), newHead.Length) + assert.Equal(t, uint32(0), newHead.Length) // no entries in the queue list - doGetStatus(t, stakingSmartContract, eei, []byte("secondKey"), "queued") - - newMaxNodes = int64(1) - arguments = CreateVmContractCallInput() - arguments.Function = "updateConfigMaxNodes" - arguments.CallerAddr = args.EndOfEpochAccessAddr - arguments.Arguments = [][]byte{big.NewInt(0).SetInt64(newMaxNodes).Bytes()} - retCode = stakingSmartContract.Execute(arguments) - assert.Equal(t, retCode, vmcommon.Ok) + doGetStatus(t, stakingSmartContract, eei, []byte("secondKey"), "unStaked") // stake them again - as they were deleted from waiting list - doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("thirdKeyy")) + doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("thirdKey ")) doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("fourthKey")) validatorData = &ValidatorDataV2{ @@ -3724,25 +3717,7 @@ func TestStakingSc_UnStakeAllFromQueue(t *testing.T) { marshaledData, _ = stakingSmartContract.marshalizer.Marshal(validatorData) eei.SetStorageForAddress(vm.ValidatorSCAddress, stakerAddress, marshaledData) - newMaxNodes = int64(100) - arguments.Arguments = [][]byte{big.NewInt(0).SetInt64(newMaxNodes).Bytes()} - retCode = stakingSmartContract.Execute(arguments) - assert.Equal(t, retCode, vmcommon.Ok) - - currentOutPutIndex = len(eei.output) - arguments.Function = "stakeNodesFromQueue" - retCode = stakingSmartContract.Execute(arguments) - assert.Equal(t, retCode, vmcommon.Ok) - - for i := currentOutPutIndex; i < len(eei.output); i += 2 { - checkIsStaked(t, stakingSmartContract, arguments.CallerAddr, eei.output[i], vmcommon.Ok) - } - assert.Equal(t, 6, len(eei.output)-currentOutPutIndex) - stakingConfig := stakingSmartContract.getConfig() - assert.Equal(t, stakingConfig.StakedNodes, int64(4)) - - retCode = stakingSmartContract.Execute(cleanAdditionalInput) - assert.Equal(t, retCode, vmcommon.Ok) - newHead, _ = stakingSmartContract.getWaitingListHead() - assert.Equal(t, uint32(0), newHead.Length) + // surprisingly, the queue works again as we did not activate the staking v4 + doGetStatus(t, stakingSmartContract, eei, []byte("thirdKey "), "queued") + doGetStatus(t, stakingSmartContract, eei, []byte("fourthKey"), "queued") } From 259dd4f9a3278b9e6103006dfd15ff48057c272b Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Thu, 14 Mar 2024 15:16:33 +0200 Subject: [PATCH 104/503] - fixed test --- vm/systemSmartContracts/staking_test.go | 36 ++++++++++++++++++------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/vm/systemSmartContracts/staking_test.go b/vm/systemSmartContracts/staking_test.go index ce6629dd2fd..6459cf948c9 100644 --- a/vm/systemSmartContracts/staking_test.go +++ b/vm/systemSmartContracts/staking_test.go @@ -3673,8 +3673,8 @@ func TestStakingSc_UnStakeAllFromQueue(t *testing.T) { doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("thirdKey ")) doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("fourthKey")) - waitingListHead, _ := stakingSmartContract.getWaitingListHead() - require.Equal(t, waitingListHead.Length, 3) + waitingReturn := doGetWaitingListRegisterNonceAndRewardAddress(t, stakingSmartContract, eei) + assert.Equal(t, len(waitingReturn), 9) arguments := CreateVmContractCallInput() validatorData := &ValidatorDataV2{ @@ -3693,15 +3693,31 @@ func TestStakingSc_UnStakeAllFromQueue(t *testing.T) { retCode := stakingSmartContract.Execute(arguments) assert.Equal(t, retCode, vmcommon.Ok) - currentOutPutIndex = len(eei.output) - arguments.Function = "stakeNodesFromQueue" - retCode = stakingSmartContract.Execute(arguments) + // nothing to stake - as not enough funds - one remains in waiting queue + assert.Equal(t, currentOutPutIndex, len(eei.output)) + + cleanAdditionalInput := CreateVmContractCallInput() + cleanAdditionalInput.Function = "cleanAdditionalQueue" + cleanAdditionalInput.CallerAddr = args.EndOfEpochAccessAddr + retCode = stakingSmartContract.Execute(cleanAdditionalInput) assert.Equal(t, retCode, vmcommon.Ok) - for i := currentOutPutIndex; i < len(eei.output); i += 2 { - checkIsStaked(t, stakingSmartContract, arguments.CallerAddr, eei.output[i], vmcommon.Ok) + newHead, _ := stakingSmartContract.getWaitingListHead() + assert.Equal(t, uint32(0), newHead.Length) // no entries in the queue list + + doGetStatus(t, stakingSmartContract, eei, []byte("secondKey"), "unStaked") + + // stake them again - as they were deleted from waiting list + doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("thirdKey ")) + doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("fourthKey")) + + validatorData = &ValidatorDataV2{ + TotalStakeValue: big.NewInt(400), } - assert.Equal(t, 6, len(eei.output)-currentOutPutIndex) - stakingConfig := stakingSmartContract.getConfig() - assert.Equal(t, stakingConfig.StakedNodes, int64(4)) + marshaledData, _ = stakingSmartContract.marshalizer.Marshal(validatorData) + eei.SetStorageForAddress(vm.ValidatorSCAddress, stakerAddress, marshaledData) + + // surprisingly, the queue works again as we did not activate the staking v4 + doGetStatus(t, stakingSmartContract, eei, []byte("thirdKey "), "queued") + doGetStatus(t, stakingSmartContract, eei, []byte("fourthKey"), "queued") } From 90f14fbbcb86e63f8502b590b550e2f332a5db30 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 14 Mar 2024 15:58:17 +0200 Subject: [PATCH 105/503] starting unit tests --- vm/systemSmartContracts/staking_test.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/vm/systemSmartContracts/staking_test.go b/vm/systemSmartContracts/staking_test.go index c3dd1cd19d0..5f5b7ad7b15 100644 --- a/vm/systemSmartContracts/staking_test.go +++ b/vm/systemSmartContracts/staking_test.go @@ -3692,10 +3692,7 @@ func TestStakingSc_UnStakeAllFromQueue(t *testing.T) { retCode := stakingSmartContract.Execute(arguments) assert.Equal(t, retCode, vmcommon.Ok) - currentOutPutIndex = len(eei.output) - arguments.Function = "stakeNodesFromQueue" - retCode = stakingSmartContract.Execute(arguments) - assert.Equal(t, retCode, vmcommon.Ok) + assert.Equal(t, eei.GetStorage([]byte(waitingListHeadKey)), nil) for i := currentOutPutIndex; i < len(eei.output); i += 2 { checkIsStaked(t, stakingSmartContract, arguments.CallerAddr, eei.output[i], vmcommon.Ok) From 8e6e6f185e958c86d807771c940109128786dbc9 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Thu, 14 Mar 2024 16:03:28 +0200 Subject: [PATCH 106/503] - uniformized the calling methods for integration tests --- genesis/process/genesisBlockCreator_test.go | 10 +- .../vm/delegation/changeOwner_test.go | 6 +- .../vm/delegation/delegationMulti_test.go | 10 +- .../vm/delegation/delegationScenarios_test.go | 58 ++++++- .../vm/delegation/delegation_test.go | 2 - .../esdtLocalFunsSC_MockContracts_test.go | 2 - .../esdt/localFuncs/esdtLocalFunsSC_test.go | 25 +-- .../vm/esdt/multisign/esdtMultisign_test.go | 2 - .../vm/esdt/nft/esdtNFT/esdtNft_test.go | 6 +- .../vm/esdt/nft/esdtNFTSCs/esdtNFTSCs_test.go | 2 - .../vm/esdt/process/esdtProcess_test.go | 133 +--------------- .../vm/esdt/roles/esdtRoles_test.go | 2 - .../vm/txsFee/asyncCall_multi_test.go | 30 +++- integrationTests/vm/txsFee/asyncCall_test.go | 21 +-- integrationTests/vm/txsFee/asyncESDT_test.go | 36 ++++- .../vm/txsFee/builtInFunctions_test.go | 8 +- integrationTests/vm/txsFee/dns_test.go | 17 +- .../vm/txsFee/dynamicGasCost_test.go | 8 +- .../vm/txsFee/guardAccount_test.go | 28 +++- .../vm/txsFee/migrateDataTrie_test.go | 8 +- .../vm/txsFee/multiShard/asyncCall_test.go | 7 +- .../vm/txsFee/multiShard/asyncESDT_test.go | 12 +- .../txsFee/multiShard/relayedScDeploy_test.go | 6 +- .../multiShard/relayedTxScCalls_test.go | 12 +- .../scCallWithValueTransfer_test.go | 10 +- .../vm/txsFee/multiShard/scCalls_test.go | 12 +- .../vm/txsFee/relayedAsyncCall_test.go | 8 +- .../vm/txsFee/relayedAsyncESDT_test.go | 16 +- .../vm/txsFee/relayedBuiltInFunctions_test.go | 24 ++- integrationTests/vm/txsFee/relayedDns_test.go | 8 +- .../vm/txsFee/relayedESDT_test.go | 12 +- .../vm/txsFee/relayedScCalls_test.go | 28 +++- .../vm/txsFee/relayedScDeploy_test.go | 20 ++- integrationTests/vm/txsFee/scCalls_test.go | 44 +++++- integrationTests/vm/txsFee/scDeploy_test.go | 20 ++- .../vm/wasm/badcontracts/badcontracts_test.go | 5 +- .../delegation/delegationSimulation_test.go | 2 - .../vm/wasm/delegation/delegation_test.go | 5 +- integrationTests/vm/wasm/erc20/erc20_test.go | 5 +- .../vm/wasm/queries/queries_test.go | 4 - .../vm/wasm/transfers/transfers_test.go | 6 +- .../vm/wasm/upgrades/upgrades_test.go | 28 +++- .../vm/wasm/wasmer/wasmer_test.go | 20 ++- .../wasmvm/executeViaBlockchainhook_test.go | 5 +- .../vm/wasm/wasmvm/gasSchedule_test.go | 147 +++++++++++++++++- .../vm/wasm/wasmvm/versionswitch/vm_test.go | 4 - .../wasmvm/versionswitch_revert/vm_test.go | 4 - .../wasmvm/versionswitch_vmquery/vm_test.go | 4 - .../vm/wasm/wasmvm/wasmVM_test.go | 51 +++++- node/nodeRunner_test.go | 18 ++- 50 files changed, 644 insertions(+), 317 deletions(-) diff --git a/genesis/process/genesisBlockCreator_test.go b/genesis/process/genesisBlockCreator_test.go index 7553025f369..2ccea85ef14 100644 --- a/genesis/process/genesisBlockCreator_test.go +++ b/genesis/process/genesisBlockCreator_test.go @@ -180,7 +180,7 @@ func createMockArgument( SCDeployEnableEpoch: unreachableEpoch, CleanUpInformativeSCRsEnableEpoch: unreachableEpoch, SCProcessorV2EnableEpoch: unreachableEpoch, - StakeLimitsEnableEpoch: 10, + StakeLimitsEnableEpoch: 10, }, }, RoundConfig: testscommon.GetDefaultRoundsConfig(), @@ -897,9 +897,9 @@ func TestCreateArgsGenesisBlockCreator_ShouldWorkAndCreateEmpty(t *testing.T) { blocks, err := gbc.CreateGenesisBlocks() assert.Nil(t, err) assert.Equal(t, 3, len(blocks)) - for _, block := range blocks { - assert.Zero(t, block.GetNonce()) - assert.Zero(t, block.GetRound()) - assert.Zero(t, block.GetEpoch()) + for _, blockInstance := range blocks { + assert.Zero(t, blockInstance.GetNonce()) + assert.Zero(t, blockInstance.GetRound()) + assert.Zero(t, blockInstance.GetEpoch()) } } diff --git a/integrationTests/vm/delegation/changeOwner_test.go b/integrationTests/vm/delegation/changeOwner_test.go index 2b23993882d..c634452ea9c 100644 --- a/integrationTests/vm/delegation/changeOwner_test.go +++ b/integrationTests/vm/delegation/changeOwner_test.go @@ -1,5 +1,3 @@ -//go:build !race - package delegation import ( @@ -23,6 +21,10 @@ var ( ) func TestDelegationChangeOwnerOnAccountHandler(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + t.Run("fix flag not activated, should not save - backwards compatibility", func(t *testing.T) { _, _, userAccount := testDelegationChangeOwnerOnAccountHandler(t, 1) diff --git a/integrationTests/vm/delegation/delegationMulti_test.go b/integrationTests/vm/delegation/delegationMulti_test.go index 90d307c741d..b0eef67dcaa 100644 --- a/integrationTests/vm/delegation/delegationMulti_test.go +++ b/integrationTests/vm/delegation/delegationMulti_test.go @@ -1,5 +1,3 @@ -//go:build !race - package delegation import ( @@ -19,6 +17,10 @@ import ( ) func TestDelegationSystemClaimMulti(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + tpn := integrationTests.NewTestProcessorNode(integrationTests.ArgTestProcessorNode{ MaxShards: 1, NodeShardId: core.MetachainShardId, @@ -127,6 +129,10 @@ func TestDelegationSystemClaimMulti(t *testing.T) { } func TestDelegationSystemRedelegateMulti(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + tpn := integrationTests.NewTestProcessorNode(integrationTests.ArgTestProcessorNode{ MaxShards: 1, NodeShardId: core.MetachainShardId, diff --git a/integrationTests/vm/delegation/delegationScenarios_test.go b/integrationTests/vm/delegation/delegationScenarios_test.go index e1d58b12d6d..4b9dbd07fba 100644 --- a/integrationTests/vm/delegation/delegationScenarios_test.go +++ b/integrationTests/vm/delegation/delegationScenarios_test.go @@ -1,5 +1,3 @@ -//go:build !race - package delegation import ( @@ -32,6 +30,10 @@ import ( ) func TestDelegationSystemNodesOperationsTestBackwardComp(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + tpn := integrationTests.NewTestProcessorNode(integrationTests.ArgTestProcessorNode{ MaxShards: 1, NodeShardId: core.MetachainShardId, @@ -82,6 +84,10 @@ func TestDelegationSystemNodesOperationsTestBackwardComp(t *testing.T) { } func TestDelegationSystemNodesOperations(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + tpn := integrationTests.NewTestProcessorNode(integrationTests.ArgTestProcessorNode{ MaxShards: 1, NodeShardId: core.MetachainShardId, @@ -163,6 +169,10 @@ func TestDelegationSystemNodesOperations(t *testing.T) { } func TestDelegationSystemReStakeNodes(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + tpn := integrationTests.NewTestProcessorNode(integrationTests.ArgTestProcessorNode{ MaxShards: 1, NodeShardId: core.MetachainShardId, @@ -230,6 +240,10 @@ func TestDelegationSystemReStakeNodes(t *testing.T) { } func TestDelegationChangeConfig(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + tpn := integrationTests.NewTestProcessorNode(integrationTests.ArgTestProcessorNode{ MaxShards: 1, NodeShardId: core.MetachainShardId, @@ -288,6 +302,10 @@ func TestDelegationChangeConfig(t *testing.T) { } func TestDelegationSystemDelegateUnDelegateFromTopUpWithdraw(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + tpn := integrationTests.NewTestProcessorNode(integrationTests.ArgTestProcessorNode{ MaxShards: 1, NodeShardId: core.MetachainShardId, @@ -348,6 +366,10 @@ func TestDelegationSystemDelegateUnDelegateFromTopUpWithdraw(t *testing.T) { } func TestDelegationSystemDelegateUnDelegateOnlyPartOfDelegation(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + tpn := integrationTests.NewTestProcessorNode(integrationTests.ArgTestProcessorNode{ MaxShards: 1, NodeShardId: core.MetachainShardId, @@ -409,6 +431,10 @@ func TestDelegationSystemDelegateUnDelegateOnlyPartOfDelegation(t *testing.T) { } func TestDelegationSystemMultipleDelegationContractsAndSameBlsKeysShouldNotWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + tpn := integrationTests.NewTestProcessorNode(integrationTests.ArgTestProcessorNode{ MaxShards: 1, NodeShardId: core.MetachainShardId, @@ -483,6 +509,10 @@ func TestDelegationSystemMultipleDelegationContractsAndSameBlsKeysShouldNotWork( } func TestDelegationSystemMultipleDelegationContractsAndSameDelegators(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + tpn := integrationTests.NewTestProcessorNode(integrationTests.ArgTestProcessorNode{ MaxShards: 1, NodeShardId: core.MetachainShardId, @@ -551,6 +581,10 @@ func TestDelegationSystemMultipleDelegationContractsAndSameDelegators(t *testing } func TestDelegationRewardsComputationAfterChangeServiceFee(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + tpn := integrationTests.NewTestProcessorNode(integrationTests.ArgTestProcessorNode{ MaxShards: 1, NodeShardId: core.MetachainShardId, @@ -655,6 +689,10 @@ func TestDelegationRewardsComputationAfterChangeServiceFee(t *testing.T) { } func TestDelegationUnJail(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + tpn := integrationTests.NewTestProcessorNode(integrationTests.ArgTestProcessorNode{ MaxShards: 1, NodeShardId: core.MetachainShardId, @@ -718,6 +756,10 @@ func TestDelegationUnJail(t *testing.T) { } func TestDelegationSystemDelegateSameUsersAFewTimes(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + tpn := integrationTests.NewTestProcessorNode(integrationTests.ArgTestProcessorNode{ MaxShards: 1, NodeShardId: core.MetachainShardId, @@ -779,6 +821,10 @@ func TestDelegationSystemDelegateSameUsersAFewTimes(t *testing.T) { } func TestDelegationSystemMultipleDelegationContractsAndSameDelegatorsClaimRewardsMultipleTimeUndelegateClaimRewardsMultipleTime(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + tpn := integrationTests.NewTestProcessorNode(integrationTests.ArgTestProcessorNode{ MaxShards: 1, NodeShardId: core.MetachainShardId, @@ -931,6 +977,10 @@ func TestDelegationSystemMultipleDelegationContractsAndSameDelegatorsClaimReward } func TestDelegationSystemDelegateUnDelegateReceiveRewardsWhenAllIsUndelegated(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + tpn := integrationTests.NewTestProcessorNode(integrationTests.ArgTestProcessorNode{ MaxShards: 1, NodeShardId: core.MetachainShardId, @@ -1069,6 +1119,10 @@ func TestDelegationSystemDelegateUnDelegateReceiveRewardsWhenAllIsUndelegated(t } func TestDelegationSystemCleanUpContract(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + tpn := integrationTests.NewTestProcessorNode(integrationTests.ArgTestProcessorNode{ MaxShards: 1, NodeShardId: core.MetachainShardId, diff --git a/integrationTests/vm/delegation/delegation_test.go b/integrationTests/vm/delegation/delegation_test.go index 65ff98aab2f..9bae5235076 100644 --- a/integrationTests/vm/delegation/delegation_test.go +++ b/integrationTests/vm/delegation/delegation_test.go @@ -1,5 +1,3 @@ -//go:build !race - package delegation import ( diff --git a/integrationTests/vm/esdt/localFuncs/esdtLocalFunsSC_MockContracts_test.go b/integrationTests/vm/esdt/localFuncs/esdtLocalFunsSC_MockContracts_test.go index e5abb053058..c088215b3c0 100644 --- a/integrationTests/vm/esdt/localFuncs/esdtLocalFunsSC_MockContracts_test.go +++ b/integrationTests/vm/esdt/localFuncs/esdtLocalFunsSC_MockContracts_test.go @@ -1,5 +1,3 @@ -//go:build !race - package localFuncs import ( diff --git a/integrationTests/vm/esdt/localFuncs/esdtLocalFunsSC_test.go b/integrationTests/vm/esdt/localFuncs/esdtLocalFunsSC_test.go index c5e9da76d9b..742531fb801 100644 --- a/integrationTests/vm/esdt/localFuncs/esdtLocalFunsSC_test.go +++ b/integrationTests/vm/esdt/localFuncs/esdtLocalFunsSC_test.go @@ -1,5 +1,3 @@ -//go:build !race - package localFuncs import ( @@ -265,17 +263,22 @@ func TestESDTSetTransferRoles(t *testing.T) { } func TestESDTSetTransferRolesForwardAsyncCallFailsIntra(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testESDTWithTransferRoleAndForwarder(t, 1) } func TestESDTSetTransferRolesForwardAsyncCallFailsCross(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testESDTWithTransferRoleAndForwarder(t, 2) } func testESDTWithTransferRoleAndForwarder(t *testing.T, numShards int) { - if testing.Short() { - t.Skip("this is not a short test") - } nodes, idxProposers := esdtCommon.CreateNodesAndPrepareBalances(numShards) defer func() { @@ -325,18 +328,22 @@ func testESDTWithTransferRoleAndForwarder(t *testing.T, numShards int) { } func TestAsyncCallsAndCallBacksArgumentsIntra(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testAsyncCallAndCallBacksArguments(t, 1) } func TestAsyncCallsAndCallBacksArgumentsCross(t *testing.T) { - testAsyncCallAndCallBacksArguments(t, 2) -} - -func testAsyncCallAndCallBacksArguments(t *testing.T, numShards int) { if testing.Short() { t.Skip("this is not a short test") } + testAsyncCallAndCallBacksArguments(t, 2) +} + +func testAsyncCallAndCallBacksArguments(t *testing.T, numShards int) { nodes, idxProposers := esdtCommon.CreateNodesAndPrepareBalances(numShards) defer func() { for _, n := range nodes { diff --git a/integrationTests/vm/esdt/multisign/esdtMultisign_test.go b/integrationTests/vm/esdt/multisign/esdtMultisign_test.go index 42b2bcacbdc..2beb0fa319c 100644 --- a/integrationTests/vm/esdt/multisign/esdtMultisign_test.go +++ b/integrationTests/vm/esdt/multisign/esdtMultisign_test.go @@ -1,5 +1,3 @@ -//go:build !race - package multisign import ( diff --git a/integrationTests/vm/esdt/nft/esdtNFT/esdtNft_test.go b/integrationTests/vm/esdt/nft/esdtNFT/esdtNft_test.go index 99138f77ce5..a1db92372bd 100644 --- a/integrationTests/vm/esdt/nft/esdtNFT/esdtNft_test.go +++ b/integrationTests/vm/esdt/nft/esdtNFT/esdtNft_test.go @@ -1,5 +1,3 @@ -//go:build !race - package esdtNFT import ( @@ -908,6 +906,10 @@ func testESDTSemiFungibleTokenTransferRole(t *testing.T, numOfShards int) { } func TestESDTSFTWithEnhancedTransferRole(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + nodesPerShard := 2 numMetachainNodes := 2 numOfShards := 3 diff --git a/integrationTests/vm/esdt/nft/esdtNFTSCs/esdtNFTSCs_test.go b/integrationTests/vm/esdt/nft/esdtNFTSCs/esdtNFTSCs_test.go index 8f62294a776..534c1c7435e 100644 --- a/integrationTests/vm/esdt/nft/esdtNFTSCs/esdtNFTSCs_test.go +++ b/integrationTests/vm/esdt/nft/esdtNFTSCs/esdtNFTSCs_test.go @@ -1,5 +1,3 @@ -//go:build !race - package esdtNFTSCs import ( diff --git a/integrationTests/vm/esdt/process/esdtProcess_test.go b/integrationTests/vm/esdt/process/esdtProcess_test.go index d580847067a..113ea36a8f4 100644 --- a/integrationTests/vm/esdt/process/esdtProcess_test.go +++ b/integrationTests/vm/esdt/process/esdtProcess_test.go @@ -1,5 +1,3 @@ -//go:build !race - package process import ( @@ -331,6 +329,10 @@ func TestESDTIssueAndSelfTransferShouldNotChangeBalance(t *testing.T) { } func TestESDTIssueFromASmartContractSimulated(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + metaNode := integrationTests.NewTestProcessorNode(integrationTests.ArgTestProcessorNode{ MaxShards: 1, NodeShardId: core.MetachainShardId, @@ -876,133 +878,6 @@ func TestCallbackPaymentEgld(t *testing.T) { }) } -func TestScCallsScWithEsdtCrossShard(t *testing.T) { - t.Skip("test is not ready yet") - - numOfShards := 2 - nodesPerShard := 2 - numMetachainNodes := 2 - - nodes := integrationTests.CreateNodes( - numOfShards, - nodesPerShard, - numMetachainNodes, - ) - - idxProposers := make([]int, numOfShards+1) - for i := 0; i < numOfShards; i++ { - idxProposers[i] = i * nodesPerShard - } - idxProposers[numOfShards] = numOfShards * nodesPerShard - - integrationTests.DisplayAndStartNodes(nodes) - - defer func() { - for _, n := range nodes { - n.Close() - } - }() - - initialVal := big.NewInt(10000000000) - integrationTests.MintAllNodes(nodes, initialVal) - - round := uint64(0) - nonce := uint64(0) - round = integrationTests.IncrementAndPrintRound(round) - nonce++ - - // send token issue - - initialSupply := int64(10000000000) - ticker := "TCK" - esdtCommon.IssueTestToken(nodes, initialSupply, ticker) - tokenIssuer := nodes[0] - - time.Sleep(time.Second) - nrRoundsToPropagateMultiShard := 12 - nonce, round = integrationTests.WaitOperationToBeDone(t, nodes, nrRoundsToPropagateMultiShard, nonce, round, idxProposers) - time.Sleep(time.Second) - - tokenIdentifier := string(integrationTests.GetTokenIdentifier(nodes, []byte(ticker))) - esdtCommon.CheckAddressHasTokens(t, tokenIssuer.OwnAccount.Address, nodes, []byte(tokenIdentifier), 0, initialSupply) - - // deploy the smart contracts - - vaultCode := wasm.GetSCCode("../testdata/vault.wasm") - secondScAddress, _ := tokenIssuer.BlockchainHook.NewAddress(tokenIssuer.OwnAccount.Address, tokenIssuer.OwnAccount.Nonce, vmFactory.WasmVirtualMachine) - - integrationTests.CreateAndSendTransaction( - nodes[0], - nodes, - big.NewInt(0), - testVm.CreateEmptyAddress(), - wasm.CreateDeployTxData(vaultCode), - integrationTests.AdditionalGasLimit, - ) - - nonce, round = integrationTests.WaitOperationToBeDone(t, nodes, 4, nonce, round, idxProposers) - _, err := nodes[0].AccntState.GetExistingAccount(secondScAddress) - require.Nil(t, err) - - forwarderCode := wasm.GetSCCode("../testdata/forwarder-raw.wasm") - forwarder, _ := nodes[2].BlockchainHook.NewAddress(nodes[2].OwnAccount.Address, nodes[2].OwnAccount.Nonce, vmFactory.WasmVirtualMachine) - integrationTests.CreateAndSendTransaction( - nodes[2], - nodes, - big.NewInt(0), - testVm.CreateEmptyAddress(), - wasm.CreateDeployTxData(forwarderCode), - integrationTests.AdditionalGasLimit, - ) - - nonce, round = integrationTests.WaitOperationToBeDone(t, nodes, 4, nonce, round, idxProposers) - _, err = nodes[2].AccntState.GetExistingAccount(forwarder) - require.Nil(t, err) - - txData := txDataBuilder.NewBuilder() - - // call forwarder with esdt, and the forwarder automatically calls second sc - valueToSendToSc := int64(1000) - txData.Clear().TransferESDT(tokenIdentifier, valueToSendToSc) - txData.Str("forward_async_call_half_payment").Bytes(secondScAddress).Str("accept_funds") - integrationTests.CreateAndSendTransaction(tokenIssuer, nodes, big.NewInt(0), forwarder, txData.ToString(), integrationTests.AdditionalGasLimit) - - time.Sleep(time.Second) - nonce, round = integrationTests.WaitOperationToBeDone(t, nodes, nrRoundsToPropagateMultiShard, nonce, round, idxProposers) - time.Sleep(time.Second) - - esdtCommon.CheckAddressHasTokens(t, tokenIssuer.OwnAccount.Address, nodes, []byte(tokenIdentifier), 0, initialSupply-valueToSendToSc) - esdtCommon.CheckAddressHasTokens(t, forwarder, nodes, []byte(tokenIdentifier), 0, valueToSendToSc/2) - esdtCommon.CheckAddressHasTokens(t, secondScAddress, nodes, []byte(tokenIdentifier), 0, valueToSendToSc/2) - - esdtCommon.CheckNumCallBacks(t, forwarder, nodes, 1) - esdtCommon.CheckForwarderRawSavedCallbackArgs(t, forwarder, nodes, 1, vmcommon.Ok, [][]byte{}) - esdtCommon.CheckForwarderRawSavedCallbackPayments(t, forwarder, nodes, []*esdtCommon.ForwarderRawSavedPaymentInfo{}) - - // call forwarder to ask the second one to send it back some esdt - valueToRequest := valueToSendToSc / 4 - txData.Clear().Func("forward_async_call").Bytes(secondScAddress) - txData.Str("retrieve_funds").Str(tokenIdentifier).Int64(0).Int64(valueToRequest) - integrationTests.CreateAndSendTransaction(tokenIssuer, nodes, big.NewInt(0), forwarder, txData.ToString(), integrationTests.AdditionalGasLimit) - - time.Sleep(time.Second) - _, _ = integrationTests.WaitOperationToBeDone(t, nodes, nrRoundsToPropagateMultiShard, nonce, round, idxProposers) - time.Sleep(time.Second) - - esdtCommon.CheckAddressHasTokens(t, forwarder, nodes, []byte(tokenIdentifier), 0, valueToSendToSc*3/4) - esdtCommon.CheckAddressHasTokens(t, secondScAddress, nodes, []byte(tokenIdentifier), 0, valueToSendToSc/4) - - esdtCommon.CheckNumCallBacks(t, forwarder, nodes, 2) - esdtCommon.CheckForwarderRawSavedCallbackArgs(t, forwarder, nodes, 2, vmcommon.Ok, [][]byte{}) - esdtCommon.CheckForwarderRawSavedCallbackPayments(t, forwarder, nodes, []*esdtCommon.ForwarderRawSavedPaymentInfo{ - { - TokenId: "EGLD", - Nonce: 0, - Payment: big.NewInt(valueToSendToSc), - }, - }) -} - func TestScCallsScWithEsdtIntraShard_SecondScRefusesPayment(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") diff --git a/integrationTests/vm/esdt/roles/esdtRoles_test.go b/integrationTests/vm/esdt/roles/esdtRoles_test.go index aa2834062c4..5c117ed4edd 100644 --- a/integrationTests/vm/esdt/roles/esdtRoles_test.go +++ b/integrationTests/vm/esdt/roles/esdtRoles_test.go @@ -1,5 +1,3 @@ -//go:build !race - package roles import ( diff --git a/integrationTests/vm/txsFee/asyncCall_multi_test.go b/integrationTests/vm/txsFee/asyncCall_multi_test.go index 289f440efa3..61886be4da3 100644 --- a/integrationTests/vm/txsFee/asyncCall_multi_test.go +++ b/integrationTests/vm/txsFee/asyncCall_multi_test.go @@ -1,5 +1,3 @@ -//go:build !race - package txsFee import ( @@ -23,6 +21,10 @@ var egldBalance = big.NewInt(50000000000) var esdtBalance = big.NewInt(100) func TestAsyncCallLegacy(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -66,6 +68,10 @@ func TestAsyncCallLegacy(t *testing.T) { } func TestAsyncCallMulti(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -113,6 +119,10 @@ func TestAsyncCallMulti(t *testing.T) { } func TestAsyncCallTransferAndExecute(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -164,6 +174,10 @@ func TestAsyncCallTransferAndExecute(t *testing.T) { } func TestAsyncCallTransferESDTAndExecute_Success(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + numberOfCallsFromParent := 3 numberOfBackTransfers := 2 transferESDTAndExecute(t, numberOfCallsFromParent, numberOfBackTransfers) @@ -280,6 +294,10 @@ func deployForwarderAndTestContract( } func TestAsyncCallMulti_CrossShard(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContextFirstContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) require.Nil(t, err) defer testContextFirstContract.Close() @@ -366,6 +384,10 @@ func TestAsyncCallMulti_CrossShard(t *testing.T) { } func TestAsyncCallTransferAndExecute_CrossShard(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + childShard, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) require.Nil(t, err) defer childShard.Close() @@ -448,6 +470,10 @@ func TestAsyncCallTransferAndExecute_CrossShard(t *testing.T) { } func TestAsyncCallTransferESDTAndExecute_CrossShard_Success(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + numberOfCallsFromParent := 3 numberOfBackTransfers := 2 transferESDTAndExecuteCrossShard(t, numberOfCallsFromParent, numberOfBackTransfers) diff --git a/integrationTests/vm/txsFee/asyncCall_test.go b/integrationTests/vm/txsFee/asyncCall_test.go index 78030ff6b39..19a966e2fa8 100644 --- a/integrationTests/vm/txsFee/asyncCall_test.go +++ b/integrationTests/vm/txsFee/asyncCall_test.go @@ -1,14 +1,9 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package txsFee import ( "encoding/hex" "fmt" "math/big" - "runtime" "strings" "testing" @@ -34,6 +29,10 @@ import ( const upgradeContractFunction = "upgradeContract" func TestAsyncCallShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -86,6 +85,10 @@ func TestAsyncCallShouldWork(t *testing.T) { } func TestMinterContractWithAsyncCalls(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMsAndCustomGasSchedule(config.EnableEpochs{}, func(gasMap wasmConfig.GasScheduleMap) { // if `MaxBuiltInCallsPerTx` is 200 test will fail gasMap[common.MaxPerTransaction]["MaxBuiltInCallsPerTx"] = 199 @@ -142,8 +145,8 @@ func TestMinterContractWithAsyncCalls(t *testing.T) { } func TestAsyncCallsOnInitFunctionOnUpgrade(t *testing.T) { - if runtime.GOARCH == "arm64" { - t.Skip("skipping test on arm64") + if testing.Short() { + t.Skip("this is not a short test") } firstContractCode := wasm.GetSCCode("./testdata/first/output/first.wasm") @@ -281,8 +284,8 @@ func testAsyncCallsOnInitFunctionOnUpgrade( } func TestAsyncCallsOnInitFunctionOnDeploy(t *testing.T) { - if runtime.GOARCH == "arm64" { - t.Skip("skipping test on arm64") + if testing.Short() { + t.Skip("this is not a short test") } firstSCCode := wasm.GetSCCode("./testdata/first/output/first.wasm") diff --git a/integrationTests/vm/txsFee/asyncESDT_test.go b/integrationTests/vm/txsFee/asyncESDT_test.go index 2c2dfce4c71..289926f96db 100644 --- a/integrationTests/vm/txsFee/asyncESDT_test.go +++ b/integrationTests/vm/txsFee/asyncESDT_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package txsFee import ( @@ -25,6 +21,10 @@ import ( ) func TestAsyncESDTCallShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, }) @@ -79,6 +79,10 @@ func TestAsyncESDTCallShouldWork(t *testing.T) { } func TestAsyncESDTCallSecondScRefusesPayment(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -132,6 +136,10 @@ func TestAsyncESDTCallSecondScRefusesPayment(t *testing.T) { } func TestAsyncESDTCallsOutOfGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -184,6 +192,10 @@ func TestAsyncESDTCallsOutOfGas(t *testing.T) { } func TestAsyncMultiTransferOnCallback(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, }) @@ -279,6 +291,10 @@ func TestAsyncMultiTransferOnCallback(t *testing.T) { } func TestAsyncMultiTransferOnCallAndOnCallback(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -379,6 +395,10 @@ func TestAsyncMultiTransferOnCallAndOnCallback(t *testing.T) { } func TestSendNFTToContractWith0Function(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -428,6 +448,10 @@ func TestSendNFTToContractWith0Function(t *testing.T) { } func TestSendNFTToContractWith0FunctionNonPayable(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -478,6 +502,10 @@ func TestSendNFTToContractWith0FunctionNonPayable(t *testing.T) { } func TestAsyncESDTCallForThirdContractShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/builtInFunctions_test.go b/integrationTests/vm/txsFee/builtInFunctions_test.go index 3f5bec54e51..8bd8c80db0f 100644 --- a/integrationTests/vm/txsFee/builtInFunctions_test.go +++ b/integrationTests/vm/txsFee/builtInFunctions_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package txsFee import ( @@ -28,6 +24,10 @@ import ( ) func TestBuildInFunctionChangeOwnerCallShouldWorkV1(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs( config.EnableEpochs{ PenalizedTooMuchGasEnableEpoch: integrationTests.UnreachableEpoch, diff --git a/integrationTests/vm/txsFee/dns_test.go b/integrationTests/vm/txsFee/dns_test.go index 6a2b9315162..a859341d1d4 100644 --- a/integrationTests/vm/txsFee/dns_test.go +++ b/integrationTests/vm/txsFee/dns_test.go @@ -1,14 +1,9 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package txsFee import ( "encoding/hex" "fmt" "math/big" - "runtime" "testing" "unicode/utf8" @@ -30,6 +25,10 @@ import ( const returnOkData = "@6f6b" func TestDeployDNSContract_TestRegisterAndResolveAndSendTxWithSndAndRcvUserName(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ DynamicGasCostForDataTrieStorageLoadEnableEpoch: 10, }) @@ -117,8 +116,8 @@ func TestDeployDNSContract_TestRegisterAndResolveAndSendTxWithSndAndRcvUserName( // relayer address is in shard 2, creates a transaction on the behalf of the user from shard 2, that will call the DNS contract // from shard 1. func TestDeployDNSContract_TestGasWhenSaveUsernameFailsCrossShardBackwardsCompatibility(t *testing.T) { - if runtime.GOARCH == "arm64" { - t.Skip("skipping test on arm64") + if testing.Short() { + t.Skip("this is not a short test") } enableEpochs := config.EnableEpochs{ @@ -197,6 +196,10 @@ func TestDeployDNSContract_TestGasWhenSaveUsernameFailsCrossShardBackwardsCompat } func TestDeployDNSContract_TestGasWhenSaveUsernameAfterDNSv2IsActivated(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContextForDNSContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, }) diff --git a/integrationTests/vm/txsFee/dynamicGasCost_test.go b/integrationTests/vm/txsFee/dynamicGasCost_test.go index a8c8a8eb9eb..e1fca367f3f 100644 --- a/integrationTests/vm/txsFee/dynamicGasCost_test.go +++ b/integrationTests/vm/txsFee/dynamicGasCost_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package txsFee import ( @@ -23,6 +19,10 @@ import ( ) func TestDynamicGasCostForDataTrieStorageLoad(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + enableEpochs := config.EnableEpochs{ DynamicGasCostForDataTrieStorageLoadEnableEpoch: 0, } diff --git a/integrationTests/vm/txsFee/guardAccount_test.go b/integrationTests/vm/txsFee/guardAccount_test.go index 58542a72e79..6ccde4df164 100644 --- a/integrationTests/vm/txsFee/guardAccount_test.go +++ b/integrationTests/vm/txsFee/guardAccount_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package txsFee import ( @@ -350,6 +346,10 @@ func setNewEpochOnContext(testContext *vm.VMTestContext, epoch uint32) { } func TestGuardAccount_ShouldErrorIfInstantSetIsDoneOnANotProtectedAccount(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext := prepareTestContextForGuardedAccounts(t) defer testContext.Close() @@ -367,6 +367,10 @@ func TestGuardAccount_ShouldErrorIfInstantSetIsDoneOnANotProtectedAccount(t *tes } func TestGuardAccount_ShouldSetGuardianOnANotProtectedAccount(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext := prepareTestContextForGuardedAccounts(t) defer testContext.Close() @@ -467,6 +471,10 @@ func TestGuardAccount_ShouldSetGuardianOnANotProtectedAccount(t *testing.T) { } func TestGuardAccount_SendingFundsWhileProtectedAndNotProtected(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext := prepareTestContextForGuardedAccounts(t) defer testContext.Close() @@ -592,6 +600,10 @@ func TestGuardAccount_SendingFundsWhileProtectedAndNotProtected(t *testing.T) { // 14. alice un-guards the accounts immediately using a cosigned transaction and then sends a guarded transaction -> should error // 14.1 alice sends unguarded transaction -> should work func TestGuardAccount_Scenario1(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext := prepareTestContextForGuardedAccounts(t) defer testContext.Close() @@ -916,6 +928,10 @@ func TestGuardAccount_Scenario1(t *testing.T) { // 3.1 cosigned transaction should work // 3.2 single signed transaction should not work func TestGuardAccounts_RelayedTransactionV1(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext := prepareTestContextForGuardedAccounts(t) defer testContext.Close() @@ -1036,6 +1052,10 @@ func TestGuardAccounts_RelayedTransactionV1(t *testing.T) { // 3.1 cosigned transaction should not work // 3.2 single signed transaction should not work func TestGuardAccounts_RelayedTransactionV2(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext := prepareTestContextForGuardedAccounts(t) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/migrateDataTrie_test.go b/integrationTests/vm/txsFee/migrateDataTrie_test.go index 9c62a4f30fd..02eecc0e1c3 100644 --- a/integrationTests/vm/txsFee/migrateDataTrie_test.go +++ b/integrationTests/vm/txsFee/migrateDataTrie_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package txsFee import ( @@ -31,7 +27,9 @@ type dataTrie interface { } func TestMigrateDataTrieBuiltInFunc(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } enableEpochs := config.EnableEpochs{ AutoBalanceDataTriesEnableEpoch: 0, diff --git a/integrationTests/vm/txsFee/multiShard/asyncCall_test.go b/integrationTests/vm/txsFee/multiShard/asyncCall_test.go index e799fd3efc6..9a0297de698 100644 --- a/integrationTests/vm/txsFee/multiShard/asyncCall_test.go +++ b/integrationTests/vm/txsFee/multiShard/asyncCall_test.go @@ -1,5 +1,3 @@ -//go:build !race - package multiShard import ( @@ -17,9 +15,8 @@ import ( ) func TestAsyncCallShouldWork(t *testing.T) { - // TODO reinstate test after Wasm VM pointer fix if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") + t.Skip("this is not a short test") } enableEpochs := config.EnableEpochs{ @@ -119,7 +116,7 @@ func TestAsyncCallShouldWork(t *testing.T) { func TestAsyncCallDisabled(t *testing.T) { if testing.Short() { - t.Skip("cannot run with -race -short; requires Arwen fix") + t.Skip("this is not a short test") } enableEpochs := config.EnableEpochs{ diff --git a/integrationTests/vm/txsFee/multiShard/asyncESDT_test.go b/integrationTests/vm/txsFee/multiShard/asyncESDT_test.go index 114859ac5bf..e7d78430350 100644 --- a/integrationTests/vm/txsFee/multiShard/asyncESDT_test.go +++ b/integrationTests/vm/txsFee/multiShard/asyncESDT_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package multiShard import ( @@ -18,6 +14,10 @@ import ( ) func TestAsyncESDTTransferWithSCCallShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + enableEpochs := config.EnableEpochs{ DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, } @@ -130,6 +130,10 @@ func TestAsyncESDTTransferWithSCCallShouldWork(t *testing.T) { } func TestAsyncESDTTransferWithSCCallSecondContractAnotherToken(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + enableEpochs := config.EnableEpochs{ DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, } diff --git a/integrationTests/vm/txsFee/multiShard/relayedScDeploy_test.go b/integrationTests/vm/txsFee/multiShard/relayedScDeploy_test.go index 499fbe5c6ee..7700c55b0f4 100644 --- a/integrationTests/vm/txsFee/multiShard/relayedScDeploy_test.go +++ b/integrationTests/vm/txsFee/multiShard/relayedScDeploy_test.go @@ -1,5 +1,3 @@ -//go:build !race - package multiShard import ( @@ -16,6 +14,10 @@ import ( ) func TestRelayedSCDeployShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContextRelayer, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{}) require.Nil(t, err) defer testContextRelayer.Close() diff --git a/integrationTests/vm/txsFee/multiShard/relayedTxScCalls_test.go b/integrationTests/vm/txsFee/multiShard/relayedTxScCalls_test.go index 8e0229fef08..4e0f0d983fa 100644 --- a/integrationTests/vm/txsFee/multiShard/relayedTxScCalls_test.go +++ b/integrationTests/vm/txsFee/multiShard/relayedTxScCalls_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package multiShard import ( @@ -27,6 +23,10 @@ import ( // 4. Execute SCR with the smart contract call on shard 1 // 5. Execute SCR with refund on relayer shard (shard 2) func TestRelayedTxScCallMultiShardShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + enableEpochs := config.EnableEpochs{ DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, } @@ -136,6 +136,10 @@ func TestRelayedTxScCallMultiShardShouldWork(t *testing.T) { } func TestRelayedTxScCallMultiShardFailOnInnerTxDst(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContextRelayer, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{}) require.Nil(t, err) defer testContextRelayer.Close() diff --git a/integrationTests/vm/txsFee/multiShard/scCallWithValueTransfer_test.go b/integrationTests/vm/txsFee/multiShard/scCallWithValueTransfer_test.go index bcb14308bab..8f66a649a3b 100644 --- a/integrationTests/vm/txsFee/multiShard/scCallWithValueTransfer_test.go +++ b/integrationTests/vm/txsFee/multiShard/scCallWithValueTransfer_test.go @@ -1,5 +1,3 @@ -//go:build !race - package multiShard import ( @@ -16,10 +14,18 @@ import ( ) func TestDeployContractAndTransferValueSCProcessorV1(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testDeployContractAndTransferValue(t, 1000) } func TestDeployContractAndTransferValueSCProcessorV2(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testDeployContractAndTransferValue(t, 0) } diff --git a/integrationTests/vm/txsFee/multiShard/scCalls_test.go b/integrationTests/vm/txsFee/multiShard/scCalls_test.go index 42e1dc824c1..1338e280c65 100644 --- a/integrationTests/vm/txsFee/multiShard/scCalls_test.go +++ b/integrationTests/vm/txsFee/multiShard/scCalls_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package multiShard import ( @@ -17,6 +13,10 @@ import ( ) func TestScCallExecuteOnSourceAndDstShardShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + enableEpochs := config.EnableEpochs{ DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, } @@ -97,6 +97,10 @@ func TestScCallExecuteOnSourceAndDstShardShouldWork(t *testing.T) { } func TestScCallExecuteOnSourceAndDstShardInvalidOnDst(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) require.Nil(t, err) defer testContextSource.Close() diff --git a/integrationTests/vm/txsFee/relayedAsyncCall_test.go b/integrationTests/vm/txsFee/relayedAsyncCall_test.go index b782f318432..d98a440b648 100644 --- a/integrationTests/vm/txsFee/relayedAsyncCall_test.go +++ b/integrationTests/vm/txsFee/relayedAsyncCall_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package txsFee import ( @@ -19,6 +15,10 @@ import ( ) func TestRelayedAsyncCallShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + senderAddr := []byte("12345678901234567890123456789011") t.Run("nonce fix is disabled, should increase the sender's nonce", func(t *testing.T) { diff --git a/integrationTests/vm/txsFee/relayedAsyncESDT_test.go b/integrationTests/vm/txsFee/relayedAsyncESDT_test.go index 061a884b268..5e3ca24d999 100644 --- a/integrationTests/vm/txsFee/relayedAsyncESDT_test.go +++ b/integrationTests/vm/txsFee/relayedAsyncESDT_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package txsFee import ( @@ -18,6 +14,10 @@ import ( ) func TestRelayedAsyncESDTCallShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, }) @@ -78,6 +78,10 @@ func TestRelayedAsyncESDTCallShouldWork(t *testing.T) { } func TestRelayedAsyncESDTCall_InvalidCallFirstContract(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -136,6 +140,10 @@ func TestRelayedAsyncESDTCall_InvalidCallFirstContract(t *testing.T) { } func TestRelayedAsyncESDTCall_InvalidOutOfGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/relayedBuiltInFunctions_test.go b/integrationTests/vm/txsFee/relayedBuiltInFunctions_test.go index dd82f276e27..115dc545244 100644 --- a/integrationTests/vm/txsFee/relayedBuiltInFunctions_test.go +++ b/integrationTests/vm/txsFee/relayedBuiltInFunctions_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package txsFee import ( @@ -20,6 +16,10 @@ import ( ) func TestRelayedBuildInFunctionChangeOwnerCallShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs( config.EnableEpochs{ PenalizedTooMuchGasEnableEpoch: integrationTests.UnreachableEpoch, @@ -68,6 +68,10 @@ func TestRelayedBuildInFunctionChangeOwnerCallShouldWork(t *testing.T) { } func TestRelayedBuildInFunctionChangeOwnerCallWrongOwnerShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -114,6 +118,10 @@ func TestRelayedBuildInFunctionChangeOwnerCallWrongOwnerShouldConsumeGas(t *test } func TestRelayedBuildInFunctionChangeOwnerInvalidAddressShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -158,6 +166,10 @@ func TestRelayedBuildInFunctionChangeOwnerInvalidAddressShouldConsumeGas(t *test } func TestRelayedBuildInFunctionChangeOwnerCallInsufficientGasLimitShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + t.Run("nonce fix is disabled, should increase the sender's nonce", func(t *testing.T) { testRelayedBuildInFunctionChangeOwnerCallInsufficientGasLimitShouldConsumeGas(t, config.EnableEpochs{ @@ -220,6 +232,10 @@ func testRelayedBuildInFunctionChangeOwnerCallInsufficientGasLimitShouldConsumeG } func TestRelayedBuildInFunctionChangeOwnerCallOutOfGasShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/relayedDns_test.go b/integrationTests/vm/txsFee/relayedDns_test.go index e71c02622f1..54c70be0ee8 100644 --- a/integrationTests/vm/txsFee/relayedDns_test.go +++ b/integrationTests/vm/txsFee/relayedDns_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package txsFee import ( @@ -18,6 +14,10 @@ import ( ) func TestRelayedTxDnsTransaction_ShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/relayedESDT_test.go b/integrationTests/vm/txsFee/relayedESDT_test.go index eba6eedb384..c9837fb7075 100644 --- a/integrationTests/vm/txsFee/relayedESDT_test.go +++ b/integrationTests/vm/txsFee/relayedESDT_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package txsFee import ( @@ -17,6 +13,10 @@ import ( ) func TestRelayedESDTTransferShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -62,6 +62,10 @@ func TestRelayedESDTTransferShouldWork(t *testing.T) { } func TestTestRelayedESTTransferNotEnoughESTValueShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/relayedScCalls_test.go b/integrationTests/vm/txsFee/relayedScCalls_test.go index d5e0e46179e..36febda356e 100644 --- a/integrationTests/vm/txsFee/relayedScCalls_test.go +++ b/integrationTests/vm/txsFee/relayedScCalls_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package txsFee import ( @@ -19,6 +15,10 @@ import ( ) func TestRelayedScCallShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, }) @@ -63,6 +63,10 @@ func TestRelayedScCallShouldWork(t *testing.T) { } func TestRelayedScCallContractNotFoundShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -102,6 +106,10 @@ func TestRelayedScCallContractNotFoundShouldConsumeGas(t *testing.T) { } func TestRelayedScCallInvalidMethodShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -141,6 +149,10 @@ func TestRelayedScCallInvalidMethodShouldConsumeGas(t *testing.T) { } func TestRelayedScCallInsufficientGasLimitShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -179,6 +191,10 @@ func TestRelayedScCallInsufficientGasLimitShouldConsumeGas(t *testing.T) { } func TestRelayedScCallOutOfGasShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -218,6 +234,10 @@ func TestRelayedScCallOutOfGasShouldConsumeGas(t *testing.T) { } func TestRelayedDeployInvalidContractShouldIncrementNonceOnSender(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + senderAddr := []byte("12345678901234567890123456789011") t.Run("nonce fix is disabled, should increase the sender's nonce if inner tx has correct nonce", func(t *testing.T) { diff --git a/integrationTests/vm/txsFee/relayedScDeploy_test.go b/integrationTests/vm/txsFee/relayedScDeploy_test.go index 8a8f7f52d8c..15d6d677b44 100644 --- a/integrationTests/vm/txsFee/relayedScDeploy_test.go +++ b/integrationTests/vm/txsFee/relayedScDeploy_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package txsFee import ( @@ -17,6 +13,10 @@ import ( ) func TestRelayedScDeployShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -57,6 +57,10 @@ func TestRelayedScDeployShouldWork(t *testing.T) { } func TestRelayedScDeployInvalidCodeShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -98,6 +102,10 @@ func TestRelayedScDeployInvalidCodeShouldConsumeGas(t *testing.T) { } func TestRelayedScDeployInsufficientGasLimitShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -137,6 +145,10 @@ func TestRelayedScDeployInsufficientGasLimitShouldConsumeGas(t *testing.T) { } func TestRelayedScDeployOutOfGasShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/scCalls_test.go b/integrationTests/vm/txsFee/scCalls_test.go index a4529d959a2..2a523825f96 100644 --- a/integrationTests/vm/txsFee/scCalls_test.go +++ b/integrationTests/vm/txsFee/scCalls_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package txsFee import ( @@ -90,6 +86,10 @@ func prepareTestContextForEpoch836(tb testing.TB) (*vm.VMTestContext, []byte) { } func TestScCallShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, }) @@ -134,6 +134,10 @@ func TestScCallShouldWork(t *testing.T) { } func TestScCallContractNotFoundShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -163,6 +167,10 @@ func TestScCallContractNotFoundShouldConsumeGas(t *testing.T) { } func TestScCallInvalidMethodToCallShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -196,6 +204,10 @@ func TestScCallInvalidMethodToCallShouldConsumeGas(t *testing.T) { } func TestScCallInsufficientGasLimitShouldNotConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -230,6 +242,10 @@ func TestScCallInsufficientGasLimitShouldNotConsumeGas(t *testing.T) { } func TestScCallOutOfGasShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -263,6 +279,10 @@ func TestScCallOutOfGasShouldConsumeGas(t *testing.T) { } func TestScCallAndGasChangeShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, }) @@ -308,6 +328,10 @@ func TestScCallAndGasChangeShouldWork(t *testing.T) { } func TestESDTScCallAndGasChangeShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -418,6 +442,10 @@ func prepareTestContextForEpoch460(tb testing.TB) (*vm.VMTestContext, []byte) { } func TestScCallBuyNFT_OneFailedTxAndOneOkTx(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, scAddress := prepareTestContextForEpoch460(t) defer testContext.Close() @@ -487,6 +515,10 @@ func TestScCallBuyNFT_OneFailedTxAndOneOkTx(t *testing.T) { } func TestScCallBuyNFT_TwoOkTxs(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, scAddress := prepareTestContextForEpoch460(t) defer testContext.Close() @@ -556,6 +588,10 @@ func TestScCallBuyNFT_TwoOkTxs(t *testing.T) { } func TestScCallDistributeStakingRewards_ShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, scAddress := prepareTestContextForEpoch836(t) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/scDeploy_test.go b/integrationTests/vm/txsFee/scDeploy_test.go index 875fde2fe58..8410bcf4917 100644 --- a/integrationTests/vm/txsFee/scDeploy_test.go +++ b/integrationTests/vm/txsFee/scDeploy_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package txsFee import ( @@ -17,6 +13,10 @@ import ( ) func TestScDeployShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -48,6 +48,10 @@ func TestScDeployShouldWork(t *testing.T) { } func TestScDeployInvalidContractCodeShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -80,6 +84,10 @@ func TestScDeployInvalidContractCodeShouldConsumeGas(t *testing.T) { } func TestScDeployInsufficientGasLimitShouldNotConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -111,6 +119,10 @@ func TestScDeployInsufficientGasLimitShouldNotConsumeGas(t *testing.T) { } func TestScDeployOutOfGasShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/wasm/badcontracts/badcontracts_test.go b/integrationTests/vm/wasm/badcontracts/badcontracts_test.go index e4b3b1b7ab7..ccf211853b8 100644 --- a/integrationTests/vm/wasm/badcontracts/badcontracts_test.go +++ b/integrationTests/vm/wasm/badcontracts/badcontracts_test.go @@ -1,5 +1,3 @@ -//go:build !race - package badcontracts import ( @@ -11,9 +9,8 @@ import ( ) func Test_Bad_C_NoPanic(t *testing.T) { - // TODO reinstate test after Wasm VM pointer fix if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") + t.Skip("this is not a short test") } context := wasm.SetupTestContext(t) diff --git a/integrationTests/vm/wasm/delegation/delegationSimulation_test.go b/integrationTests/vm/wasm/delegation/delegationSimulation_test.go index be67b8d32b1..55be9681586 100644 --- a/integrationTests/vm/wasm/delegation/delegationSimulation_test.go +++ b/integrationTests/vm/wasm/delegation/delegationSimulation_test.go @@ -1,5 +1,3 @@ -//go:build !race - package delegation import ( diff --git a/integrationTests/vm/wasm/delegation/delegation_test.go b/integrationTests/vm/wasm/delegation/delegation_test.go index 9f4d3501c1c..9e9f394122f 100644 --- a/integrationTests/vm/wasm/delegation/delegation_test.go +++ b/integrationTests/vm/wasm/delegation/delegation_test.go @@ -1,5 +1,3 @@ -//go:build !race - package delegation import ( @@ -33,9 +31,8 @@ var NewBalanceBig = wasm.NewBalanceBig var RequireAlmostEquals = wasm.RequireAlmostEquals func TestDelegation_Claims(t *testing.T) { - // TODO reinstate test after Wasm VM pointer fix if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") + t.Skip("this is not a short test") } context := wasm.SetupTestContext(t) diff --git a/integrationTests/vm/wasm/erc20/erc20_test.go b/integrationTests/vm/wasm/erc20/erc20_test.go index 7eed879eb50..ef4f45bf02c 100644 --- a/integrationTests/vm/wasm/erc20/erc20_test.go +++ b/integrationTests/vm/wasm/erc20/erc20_test.go @@ -1,5 +1,3 @@ -//go:build !race - package erc20 import ( @@ -10,9 +8,8 @@ import ( ) func Test_C_001(t *testing.T) { - // TODO reinstate test after Wasm VM pointer fix if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") + t.Skip("this is not a short test") } context := wasm.SetupTestContext(t) diff --git a/integrationTests/vm/wasm/queries/queries_test.go b/integrationTests/vm/wasm/queries/queries_test.go index 7c51f04b325..e83170e6e0b 100644 --- a/integrationTests/vm/wasm/queries/queries_test.go +++ b/integrationTests/vm/wasm/queries/queries_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package queries import ( diff --git a/integrationTests/vm/wasm/transfers/transfers_test.go b/integrationTests/vm/wasm/transfers/transfers_test.go index 98e0a416a89..63e4b120f02 100644 --- a/integrationTests/vm/wasm/transfers/transfers_test.go +++ b/integrationTests/vm/wasm/transfers/transfers_test.go @@ -1,5 +1,3 @@ -//go:build !race - package transfers import ( @@ -13,6 +11,10 @@ import ( ) func TestTransfers_DuplicatedTransferValueEvents(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + context := wasm.SetupTestContext(t) defer context.Close() diff --git a/integrationTests/vm/wasm/upgrades/upgrades_test.go b/integrationTests/vm/wasm/upgrades/upgrades_test.go index 514507b0c04..4a01b67a4ec 100644 --- a/integrationTests/vm/wasm/upgrades/upgrades_test.go +++ b/integrationTests/vm/wasm/upgrades/upgrades_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package upgrades import ( @@ -19,6 +15,10 @@ import ( ) func TestUpgrades_Hello(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + context := wasm.SetupTestContext(t) defer context.Close() @@ -43,6 +43,10 @@ func TestUpgrades_Hello(t *testing.T) { } func TestUpgrades_HelloDoesNotUpgradeWhenNotUpgradeable(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + context := wasm.SetupTestContext(t) defer context.Close() @@ -61,6 +65,10 @@ func TestUpgrades_HelloDoesNotUpgradeWhenNotUpgradeable(t *testing.T) { } func TestUpgrades_HelloUpgradesToNotUpgradeable(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + context := wasm.SetupTestContext(t) defer context.Close() @@ -86,6 +94,10 @@ func TestUpgrades_HelloUpgradesToNotUpgradeable(t *testing.T) { } func TestUpgrades_ParentAndChildContracts(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + context := wasm.SetupTestContext(t) defer context.Close() @@ -125,6 +137,10 @@ func TestUpgrades_ParentAndChildContracts(t *testing.T) { } func TestUpgrades_HelloCannotBeUpgradedByNonOwner(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + context := wasm.SetupTestContext(t) defer context.Close() @@ -145,6 +161,10 @@ func TestUpgrades_HelloCannotBeUpgradedByNonOwner(t *testing.T) { } func TestUpgrades_CounterCannotBeUpgradedByNonOwner(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + context := wasm.SetupTestContext(t) defer context.Close() diff --git a/integrationTests/vm/wasm/wasmer/wasmer_test.go b/integrationTests/vm/wasm/wasmer/wasmer_test.go index f73bceae6b5..d7eeb9260a4 100644 --- a/integrationTests/vm/wasm/wasmer/wasmer_test.go +++ b/integrationTests/vm/wasm/wasmer/wasmer_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package wasmer import ( @@ -21,6 +17,10 @@ import ( var ownerAddressBytes = []byte("12345678901234567890123456789012") func TestAllowNonFloatingPointSC(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + wasmvm, scAddress := deploy(t, "../testdata/floating_point/non_fp.wasm") defer closeVM(wasmvm) @@ -37,6 +37,10 @@ func TestAllowNonFloatingPointSC(t *testing.T) { } func TestDisallowFloatingPointSC(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + wasmvm, scAddress := deploy(t, "../testdata/floating_point/fp.wasm") defer closeVM(wasmvm) @@ -53,6 +57,10 @@ func TestDisallowFloatingPointSC(t *testing.T) { } func TestSCAbortExecution_DontAbort(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + wasmvm, scAddress := deploy(t, "../testdata/misc/test_abort/test_abort.wasm") defer closeVM(wasmvm) @@ -74,6 +82,10 @@ func TestSCAbortExecution_DontAbort(t *testing.T) { } func TestSCAbortExecution_Abort(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + wasmvm, scAddress := deploy(t, "../testdata/misc/test_abort/test_abort.wasm") defer closeVM(wasmvm) diff --git a/integrationTests/vm/wasm/wasmvm/executeViaBlockchainhook_test.go b/integrationTests/vm/wasm/wasmvm/executeViaBlockchainhook_test.go index e36c4bb744d..9d12746bff5 100644 --- a/integrationTests/vm/wasm/wasmvm/executeViaBlockchainhook_test.go +++ b/integrationTests/vm/wasm/wasmvm/executeViaBlockchainhook_test.go @@ -1,5 +1,3 @@ -//go:build !race - package wasmvm import ( @@ -17,6 +15,9 @@ import ( ) func TestExecuteOnDestCtx_BlockchainHook(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } net := integrationTests.NewTestNetworkSized(t, 1, 1, 1) net.Start() diff --git a/integrationTests/vm/wasm/wasmvm/gasSchedule_test.go b/integrationTests/vm/wasm/wasmvm/gasSchedule_test.go index 496a31c0c06..735fbdc2ac3 100644 --- a/integrationTests/vm/wasm/wasmvm/gasSchedule_test.go +++ b/integrationTests/vm/wasm/wasmvm/gasSchedule_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package wasmvm import ( @@ -17,22 +13,37 @@ import ( ) func Benchmark_VmDeployWithFibbonacciAndExecute(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/misc/fib_wasm/output/fib_wasm.wasm", 32, "_main", nil, b.N, nil) } func Benchmark_searchingForPanic(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } for i := 0; i < 10; i++ { runWASMVMBenchmark(b, "../testdata/misc/fib_wasm/output/fib_wasm.wasm", 100, "_main", nil, b.N, nil) } } func Test_searchingForPanic(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + for i := 0; i < 10; i++ { runWASMVMBenchmark(t, "../testdata/misc/fib_wasm/output/fib_wasm.wasm", 100, "_main", nil, 1, nil) } } func Benchmark_VmDeployWithBadContractAndExecute(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + gasSchedule, _ := common.LoadGasScheduleConfig("../../../../cmd/node/config/gasSchedules/gasScheduleV4.toml") result, err := RunTest("../testdata/misc/bad.wasm", 0, "bigLoop", nil, b.N, gasSchedule, 1500000000) @@ -47,6 +58,10 @@ func Benchmark_VmDeployWithBadContractAndExecute(b *testing.B) { } func Benchmark_VmDeployWithBadContractAndExecute2(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + gasSchedule, _ := common.LoadGasScheduleConfig("../../../../cmd/node/config/gasSchedules/gasScheduleV4.toml") arg, _ := hex.DecodeString("012c") @@ -62,100 +77,196 @@ func Benchmark_VmDeployWithBadContractAndExecute2(b *testing.B) { } func Benchmark_VmDeployWithCPUCalculateAndExecute(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/misc/cpucalculate_wasm/output/cpucalculate.wasm", 8000, "cpuCalculate", nil, b.N, nil) } func Benchmark_VmDeployWithStringConcatAndExecute(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/misc/stringconcat_wasm/stringconcat_wasm.wasm", 10000, "_main", nil, b.N, nil) } func Benchmark_TestStore100(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/storage100/output/storage100.wasm", 0, "store100", nil, b.N, nil) } func Benchmark_TestStorageBigIntNew(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/c-api-tests/bigInt/output/cApiTest.wasm", 0, "bigIntNewTest", nil, b.N, nil) } func Benchmark_TestBigIntGetUnSignedBytes(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/c-api-tests/bigInt/output/cApiTest.wasm", 0, "bigIntGetUnsignedBytesTest", nil, b.N, nil) } func Benchmark_TestBigIntAdd(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/c-api-tests/bigInt/output/cApiTest.wasm", 0, "bigIntAddTest", nil, b.N, nil) } func Benchmark_TestBigIntMul(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/c-api-tests/bigInt/output/cApiTest.wasm", 0, "bigIntMulTest", nil, b.N, nil) } func Benchmark_TestBigIntMul25(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/c-api-tests/bigInt/output/cApiTest.wasm", 0, "bigIntMul25Test", nil, b.N, nil) } func Benchmark_TestBigIntMul32(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/c-api-tests/bigInt/output/cApiTest.wasm", 0, "bigIntMul32Test", nil, b.N, nil) } func Benchmark_TestBigIntTDiv(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/c-api-tests/bigInt/output/cApiTest.wasm", 0, "bigIntTDivTest", nil, b.N, nil) } func Benchmark_TestBigIntTMod(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/c-api-tests/bigInt/output/cApiTest.wasm", 0, "bigIntTModTest", nil, b.N, nil) } func Benchmark_TestBigIntEDiv(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/c-api-tests/bigInt/output/cApiTest.wasm", 0, "bigIntEDivTest", nil, b.N, nil) } func Benchmark_TestBigIntEMod(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/c-api-tests/bigInt/output/cApiTest.wasm", 0, "bigIntEModTest", nil, b.N, nil) } func Benchmark_TestBigIntShr(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/c-api-tests/bigInt/output/cApiTest.wasm", 0, "bigIntShrTest", nil, b.N, nil) } func Benchmark_TestBigIntSetup(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/c-api-tests/bigInt/output/cApiTest.wasm", 0, "bigIntInitSetup", nil, b.N, nil) } func Benchmark_TestCryptoSHA256(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/c-api-tests/crypto/output/cryptoTest.wasm", 0, "sha256Test", nil, b.N, nil) } func Benchmark_TestCryptoKeccak256(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/c-api-tests/crypto/output/cryptoTest.wasm", 0, "keccak256Test", nil, b.N, nil) } func Benchmark_TestCryptoRipMed160(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/c-api-tests/crypto/output/cryptoTest.wasm", 0, "ripemd160Test", nil, b.N, nil) } func Benchmark_TestCryptoBLS(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/c-api-tests/crypto/output/cryptoTest.wasm", 0, "verifyBLSTest", nil, b.N, nil) } func Benchmark_TestCryptoVerifyED25519(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/c-api-tests/crypto/output/cryptoTest.wasm", 0, "verifyEd25519Test", nil, b.N, nil) } func Benchmark_TestCryptoSecp256k1UnCompressed(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/c-api-tests/crypto/output/cryptoTest.wasm", 0, "verifySecp256k1UncompressedKeyTest", nil, b.N, nil) } func Benchmark_TestCryptoSecp256k1Compressed(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/c-api-tests/crypto/output/cryptoTest.wasm", 0, "verifySecp256k1CompressedKeyTest", nil, b.N, nil) } func Benchmark_TestEllipticCurveInitialVariablesAndCalls(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/c-api-tests/ecBenchmark/output/ecBenchmark.wasm", 0, "initialVariablesAndCallsTest", nil, b.N, nil) } // elliptic curves func Benchmark_TestEllipticCurve(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + testEllipticCurve(b, "p224Add") testEllipticCurve(b, "p256Add") testEllipticCurve(b, "p384Add") @@ -191,21 +302,37 @@ func Benchmark_TestEllipticCurve(b *testing.B) { } func Benchmark_TestEllipticCurveScalarMultP224(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + gasSchedule, _ := common.LoadGasScheduleConfig(integrationTests.GasSchedulePath) runWASMVMBenchmark(b, "../testdata/c-api-tests/ecBenchmark/output/ecBenchmark.wasm", 0, "p224ScalarMultEcTest", getNumberOfRepsAndScalarLengthArgs(10), b.N, gasSchedule) } func Benchmark_TestEllipticCurveScalarMultP256(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + gasSchedule, _ := common.LoadGasScheduleConfig(integrationTests.GasSchedulePath) runWASMVMBenchmark(b, "../testdata/c-api-tests/ecBenchmark/output/ecBenchmark.wasm", 0, "p256ScalarMultEcTest", getNumberOfRepsAndScalarLengthArgs(10), b.N, gasSchedule) } func Benchmark_TestEllipticCurveScalarMultP384(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + gasSchedule, _ := common.LoadGasScheduleConfig(integrationTests.GasSchedulePath) runWASMVMBenchmark(b, "../testdata/c-api-tests/ecBenchmark/output/ecBenchmark.wasm", 0, "p384ScalarMultEcTest", getNumberOfRepsAndScalarLengthArgs(10), b.N, gasSchedule) } func Benchmark_TestEllipticCurveScalarMultP521(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + gasSchedule, _ := common.LoadGasScheduleConfig(integrationTests.GasSchedulePath) runWASMVMBenchmark(b, "../testdata/c-api-tests/ecBenchmark/output/ecBenchmark.wasm", 0, "p521ScalarMultEcTest", getNumberOfRepsAndScalarLengthArgs(10), b.N, gasSchedule) } @@ -216,10 +343,18 @@ func testEllipticCurve(b *testing.B, function string) { } func Benchmark_TestCryptoDoNothing(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + runWASMVMBenchmark(b, "../testdata/c-api-tests/crypto/output/cryptoTest.wasm", 0, "doNothing", nil, b.N, nil) } func Benchmark_TestStorageRust(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + gasSchedule, _ := common.LoadGasScheduleConfig(integrationTests.GasSchedulePath) buff := make([]byte, 100) _, _ = rand.Read(buff) @@ -228,6 +363,10 @@ func Benchmark_TestStorageRust(b *testing.B) { } func TestGasModel(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + gasSchedule, _ := common.LoadGasScheduleConfig(integrationTests.GasSchedulePath) totalOp := uint64(0) diff --git a/integrationTests/vm/wasm/wasmvm/versionswitch/vm_test.go b/integrationTests/vm/wasm/wasmvm/versionswitch/vm_test.go index 45565934c77..e69b329162e 100644 --- a/integrationTests/vm/wasm/wasmvm/versionswitch/vm_test.go +++ b/integrationTests/vm/wasm/wasmvm/versionswitch/vm_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package versionswitch import ( diff --git a/integrationTests/vm/wasm/wasmvm/versionswitch_revert/vm_test.go b/integrationTests/vm/wasm/wasmvm/versionswitch_revert/vm_test.go index dac92a24a75..9563bc24615 100644 --- a/integrationTests/vm/wasm/wasmvm/versionswitch_revert/vm_test.go +++ b/integrationTests/vm/wasm/wasmvm/versionswitch_revert/vm_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package versionswitch_revert import ( diff --git a/integrationTests/vm/wasm/wasmvm/versionswitch_vmquery/vm_test.go b/integrationTests/vm/wasm/wasmvm/versionswitch_vmquery/vm_test.go index 4af3688e4fa..52cf2ccb190 100644 --- a/integrationTests/vm/wasm/wasmvm/versionswitch_vmquery/vm_test.go +++ b/integrationTests/vm/wasm/wasmvm/versionswitch_vmquery/vm_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package versionswitch_vmquery import ( diff --git a/integrationTests/vm/wasm/wasmvm/wasmVM_test.go b/integrationTests/vm/wasm/wasmvm/wasmVM_test.go index 9df0d4e22b5..53ace932675 100644 --- a/integrationTests/vm/wasm/wasmvm/wasmVM_test.go +++ b/integrationTests/vm/wasm/wasmvm/wasmVM_test.go @@ -1,7 +1,3 @@ -//go:build !race - -// TODO remove build condition above to allow -race -short, after Wasm VM fix - package wasmvm import ( @@ -46,6 +42,10 @@ import ( var log = logger.GetOrCreate("wasmVMtest") func TestVmDeployWithTransferAndGasShouldDeploySCCode(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + senderAddressBytes := []byte("12345678901234567890123456789012") senderNonce := uint64(0) senderBalance := big.NewInt(100000000) @@ -92,6 +92,10 @@ func TestVmDeployWithTransferAndGasShouldDeploySCCode(t *testing.T) { } func TestVmSCDeployFactory(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + senderAddressBytes := []byte("12345678901234567890123456789012") senderNonce := uint64(0) senderBalance := big.NewInt(100000000) @@ -148,6 +152,10 @@ func TestVmSCDeployFactory(t *testing.T) { } func TestSCMoveBalanceBeforeSCDeployV1(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + ownerAddressBytes := []byte("12345678901234567890123456789012") ownerNonce := uint64(0) ownerBalance := big.NewInt(100000000) @@ -228,6 +236,10 @@ func TestSCMoveBalanceBeforeSCDeployV1(t *testing.T) { } func TestSCMoveBalanceBeforeSCDeploy(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + ownerAddressBytes := []byte("12345678901234567890123456789012") ownerNonce := uint64(0) ownerBalance := big.NewInt(100000000) @@ -307,6 +319,10 @@ func TestSCMoveBalanceBeforeSCDeploy(t *testing.T) { } func TestWASMMetering(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + ownerAddressBytes := []byte("12345678901234567890123456789012") ownerNonce := uint64(11) ownerBalance := big.NewInt(0xfffffffffffffff) @@ -408,6 +424,7 @@ func TestMultipleTimesERC20RustBigIntInBatches(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } + gasSchedule, _ := common.LoadGasScheduleConfig(integrationTests.GasSchedulePath) durations, err := DeployAndExecuteERC20WithBigInt(3, 1000, gasSchedule, "../testdata/erc20-c-03/rust-simple-erc20.wasm", "transfer") require.Nil(t, err) @@ -446,6 +463,10 @@ func displayBenchmarksResults(durations []time.Duration) { } func TestDeployERC20WithNotEnoughGasShouldReturnOutOfGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + gasSchedule, _ := common.LoadGasScheduleConfig(integrationTests.GasSchedulePath) ownerAddressBytes := []byte("12345678901234567890123456789011") ownerNonce := uint64(11) @@ -480,8 +501,7 @@ func TestDeployERC20WithNotEnoughGasShouldReturnOutOfGas(t *testing.T) { } func TestJournalizingAndTimeToProcessChange(t *testing.T) { - // Only a test to benchmark jurnalizing and getting data from trie - t.Skip() + t.Skip("Only a test to benchmark jurnalizing and getting data from trie") numRun := 1000 ownerAddressBytes := []byte("12345678901234567890123456789011") @@ -577,8 +597,7 @@ func TestJournalizingAndTimeToProcessChange(t *testing.T) { } func TestExecuteTransactionAndTimeToProcessChange(t *testing.T) { - // Only a test to benchmark transaction processing - t.Skip() + t.Skip("Only a test to benchmark transaction processing") testMarshalizer := &marshal.JsonMarshalizer{} testHasher := sha256.NewSha256() @@ -817,6 +836,10 @@ func TestAndCatchTrieError(t *testing.T) { } func TestCommunityContract_InShard(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + zero := big.NewInt(0) transferEGLD := big.NewInt(42) @@ -859,6 +882,10 @@ func TestCommunityContract_InShard(t *testing.T) { } func TestCommunityContract_CrossShard(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + zero := big.NewInt(0) transferEGLD := big.NewInt(42) @@ -904,6 +931,10 @@ func TestCommunityContract_CrossShard(t *testing.T) { } func TestCommunityContract_CrossShard_TxProcessor(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + // Scenario: // 1. Deploy FunderSC on shard 0, owned by funderOwner // 2. Deploy ParentSC on shard 1, owned by parentOwner; deployment needs address of FunderSC @@ -1018,6 +1049,10 @@ func TestCommunityContract_CrossShard_TxProcessor(t *testing.T) { } func TestDeployDNSV2SetDeleteUserNames(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + senderAddressBytes, _ := vm.TestAddressPubkeyConverter.Decode(vm.DNSV2DeployerAddress) senderNonce := uint64(0) senderBalance := big.NewInt(100000000) diff --git a/node/nodeRunner_test.go b/node/nodeRunner_test.go index bb20b16fc47..5d0e9a7666c 100644 --- a/node/nodeRunner_test.go +++ b/node/nodeRunner_test.go @@ -1,5 +1,3 @@ -//go:build !race - package node import ( @@ -22,7 +20,9 @@ import ( const originalConfigsPath = "../cmd/node/config" func TestNewNodeRunner(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } t.Run("nil configs should error", func(t *testing.T) { t.Parallel() @@ -45,7 +45,9 @@ func TestNewNodeRunner(t *testing.T) { } func TestNodeRunner_StartAndCloseNodeUsingSIGINT(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } configs, err := testscommon.CreateTestConfigs(t.TempDir(), originalConfigsPath) require.Nil(t, err) @@ -76,7 +78,9 @@ func TestNodeRunner_StartAndCloseNodeUsingSIGINT(t *testing.T) { } func TestCopyDirectory(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } file1Name := "file1.toml" file1Contents := []byte("file1") @@ -134,7 +138,9 @@ func TestCopyDirectory(t *testing.T) { } func TestWaitForSignal(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } closedCalled := make(map[string]struct{}) healthServiceClosableComponent := &mock.CloserStub{ From 5b75a43ef78043ecc1ab540fbe267d93c70df02c Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 14 Mar 2024 16:22:10 +0200 Subject: [PATCH 107/503] fixed tests --- vm/systemSmartContracts/staking_test.go | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/vm/systemSmartContracts/staking_test.go b/vm/systemSmartContracts/staking_test.go index 8b147bec549..53d78208cf1 100644 --- a/vm/systemSmartContracts/staking_test.go +++ b/vm/systemSmartContracts/staking_test.go @@ -3656,7 +3656,6 @@ func TestStakingSc_UnStakeAllFromQueue(t *testing.T) { args.StakingAccessAddr = stakingAccessAddress args.StakingSCConfig.MaxNumberOfNodesForStake = 1 enableEpochsHandler, _ := args.EnableEpochsHandler.(*enableEpochsHandlerMock.EnableEpochsHandlerStub) - enableEpochsHandler.AddActiveFlags(common.StakingV4Step1Flag) args.Eei = eei args.StakingSCConfig.UnBondPeriod = 100 stakingSmartContract, _ := NewStakingSmartContract(args) @@ -3678,23 +3677,22 @@ func TestStakingSc_UnStakeAllFromQueue(t *testing.T) { arguments := CreateVmContractCallInput() validatorData := &ValidatorDataV2{ - TotalStakeValue: big.NewInt(200), + TotalStakeValue: big.NewInt(400), TotalUnstaked: big.NewInt(0), RewardAddress: stakerAddress, BlsPubKeys: [][]byte{[]byte("firstKey "), []byte("secondKey"), []byte("thirdKey "), []byte("fourthKey")}, } - arguments.CallerAddr = []byte("endOfEpoch") + arguments.CallerAddr = stakingSmartContract.endOfEpochAccessAddr marshaledData, _ := stakingSmartContract.marshalizer.Marshal(validatorData) eei.SetStorageForAddress(vm.ValidatorSCAddress, stakerAddress, marshaledData) - currentOutPutIndex := len(eei.output) - + enableEpochsHandler.AddActiveFlags(common.StakingV4Step1Flag) + enableEpochsHandler.AddActiveFlags(common.StakingV4StartedFlag) arguments.Function = "unStakeAllNodesFromQueue" retCode := stakingSmartContract.Execute(arguments) assert.Equal(t, retCode, vmcommon.Ok) - assert.Equal(t, eei.GetStorage([]byte(waitingListHeadKey)), nil) - + assert.Equal(t, len(eei.GetStorage([]byte(waitingListHeadKey))), 0) newHead, _ := stakingSmartContract.getWaitingListHead() assert.Equal(t, uint32(0), newHead.Length) // no entries in the queue list @@ -3704,13 +3702,7 @@ func TestStakingSc_UnStakeAllFromQueue(t *testing.T) { doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("thirdKey ")) doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("fourthKey")) - validatorData = &ValidatorDataV2{ - TotalStakeValue: big.NewInt(400), - } - marshaledData, _ = stakingSmartContract.marshalizer.Marshal(validatorData) - eei.SetStorageForAddress(vm.ValidatorSCAddress, stakerAddress, marshaledData) - // surprisingly, the queue works again as we did not activate the staking v4 - doGetStatus(t, stakingSmartContract, eei, []byte("thirdKey "), "queued") - doGetStatus(t, stakingSmartContract, eei, []byte("fourthKey"), "queued") + doGetStatus(t, stakingSmartContract, eei, []byte("thirdKey "), "staked") + doGetStatus(t, stakingSmartContract, eei, []byte("fourthKey"), "staked") } From 6cade7f6c671fc4e2820e98922ece3af5d3b0afc Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 14 Mar 2024 16:38:34 +0200 Subject: [PATCH 108/503] fixed tests --- epochStart/metachain/systemSCs_test.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/epochStart/metachain/systemSCs_test.go b/epochStart/metachain/systemSCs_test.go index d9426d2d34b..7826c461d36 100644 --- a/epochStart/metachain/systemSCs_test.go +++ b/epochStart/metachain/systemSCs_test.go @@ -2053,14 +2053,6 @@ func TestSystemSCProcessor_ProcessSystemSmartContractStakingV4Init(t *testing.T) 0: { createValidatorInfo(owner1ListPubKeysStaked[0], common.EligibleList, "", 0, owner1), createValidatorInfo(owner1ListPubKeysStaked[1], common.WaitingList, "", 0, owner1), - createValidatorInfo(owner1ListPubKeysWaiting[0], common.AuctionList, "", 0, owner1), - createValidatorInfo(owner1ListPubKeysWaiting[1], common.AuctionList, "", 0, owner1), - createValidatorInfo(owner1ListPubKeysWaiting[2], common.AuctionList, "", 0, owner1), - - createValidatorInfo(owner2ListPubKeysWaiting[0], common.AuctionList, "", 0, owner2), - - createValidatorInfo(owner3ListPubKeysWaiting[0], common.AuctionList, "", 0, owner3), - createValidatorInfo(owner3ListPubKeysWaiting[1], common.AuctionList, "", 0, owner3), }, 1: { createValidatorInfo(owner2ListPubKeysStaked[0], common.EligibleList, "", 1, owner2), From 0f84d9890bfaf365d5554379a78d4a345e02930f Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Thu, 14 Mar 2024 16:57:31 +0200 Subject: [PATCH 109/503] - more skipped tests --- factory/status/statusComponents_test.go | 9 ++--- genesis/process/genesisBlockCreator_test.go | 2 -- integrationTests/api/transaction_test.go | 4 +++ .../benchmarks/loadFromTrie_test.go | 4 +++ .../staking/simpleStake_test.go | 4 +++ .../dataComponents/dataComponents_test.go | 4 +++ .../frontend/wallet/txInterception_test.go | 12 +++++++ .../node/getAccount/getAccount_test.go | 8 +++-- .../networkSharding_test.go | 8 ++--- .../singleShard/smartContract/dns_test.go | 3 +- .../state/genesisState/genesisState_test.go | 8 +++-- .../stateExecTransaction_test.go | 5 +-- .../state/stateTrieSync/stateTrieSync_test.go | 8 +++++ .../vm/mockVM/vmDeploy/vmDeploy_test.go | 16 +++++++++ .../vm/mockVM/vmGet/vmGet_test.go | 4 +++ .../vmRunContract/vmRunContract_test.go | 16 +++++++++ integrationTests/vm/staking/stakingV4_test.go | 36 ++++++++++++++----- .../vm/txsFee/apiTransactionEvaluator_test.go | 12 +++---- .../vm/txsFee/backwardsCompatibility_test.go | 12 +++++++ .../vm/txsFee/builtInFunctions_test.go | 32 +++++++++++++++++ .../vm/txsFee/esdtLocalBurn_test.go | 12 +++++++ .../vm/txsFee/esdtLocalMint_test.go | 8 +++++ integrationTests/vm/txsFee/esdt_test.go | 16 +++++++++ .../vm/txsFee/moveBalance_test.go | 28 +++++++++++++++ .../vm/txsFee/multiESDTTransfer_test.go | 8 +++++ .../asyncCallWithChangeOwner_test.go | 2 +- .../multiShard/builtInFunctions_test.go | 2 +- .../txsFee/multiShard/esdtLiquidity_test.go | 12 +++++++ .../vm/txsFee/multiShard/esdt_test.go | 8 +++++ .../vm/txsFee/multiShard/moveBalance_test.go | 16 +++++++-- .../multiShard/nftTransferUpdate_test.go | 4 +++ .../relayedBuiltInFunctions_test.go | 3 +- .../multiShard/relayedMoveBalance_test.go | 24 +++++++++++++ .../vm/txsFee/relayedMoveBalance_test.go | 28 +++++++++++++++ .../vm/txsFee/validatorSC_test.go | 20 +++++++++++ .../vm/wasm/badcontracts/badcontracts_test.go | 20 +++++++++++ .../vm/wasm/wasmvm/asyncMockContracts_test.go | 11 ++++-- .../vm/wasm/wasmvm/deployment/deploy_test.go | 2 +- .../vm/wasm/wasmvm/deployment/upgrade_test.go | 2 +- .../adder/converterAdder_test.go | 8 +++++ .../converterEllipticCurves_test.go | 8 +++++ .../scenariosTests/mex/converterMex_test.go | 8 +++++ .../components/processComponents_test.go | 21 +++-------- .../components/testOnlyProcessingNode_test.go | 23 ++++++------ .../factory/shard/vmContainerFactory_test.go | 8 ++--- 45 files changed, 429 insertions(+), 80 deletions(-) diff --git a/factory/status/statusComponents_test.go b/factory/status/statusComponents_test.go index 3e1c0f8ba53..2b7c3e59379 100644 --- a/factory/status/statusComponents_test.go +++ b/factory/status/statusComponents_test.go @@ -2,7 +2,6 @@ package status_test import ( "errors" - "runtime" "testing" "github.com/multiversx/mx-chain-communication-go/websocket/data" @@ -136,7 +135,9 @@ func TestNewStatusComponentsFactory(t *testing.T) { } func TestStatusComponentsFactory_Create(t *testing.T) { - // no t.Parallel for these tests as they create real components + if testing.Short() { + t.Skip("this is not a short test") + } t.Run("NewSoftwareVersionFactory fails should return error", func(t *testing.T) { args := createMockStatusComponentsFactoryArgs() @@ -188,10 +189,6 @@ func TestStatusComponentsFactory_Create(t *testing.T) { require.Nil(t, sc) }) t.Run("should work", func(t *testing.T) { - if runtime.GOOS == "darwin" && runtime.GOARCH == "amd64" { - t.Skip("skipping test on darwin amd64") - } - shardCoordinator := mock.NewMultiShardsCoordinatorMock(2) shardCoordinator.SelfIDCalled = func() uint32 { return core.MetachainShardId // coverage diff --git a/genesis/process/genesisBlockCreator_test.go b/genesis/process/genesisBlockCreator_test.go index 2ccea85ef14..68c93b87f51 100644 --- a/genesis/process/genesisBlockCreator_test.go +++ b/genesis/process/genesisBlockCreator_test.go @@ -1,7 +1,5 @@ //go:build !race -// TODO reinstate test after Wasm VM pointer fix - package process import ( diff --git a/integrationTests/api/transaction_test.go b/integrationTests/api/transaction_test.go index c4267676343..2ecb27b850c 100644 --- a/integrationTests/api/transaction_test.go +++ b/integrationTests/api/transaction_test.go @@ -14,6 +14,10 @@ import ( ) func TestTransactionGroup(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + node := integrationTests.NewTestProcessorNodeWithTestWebServer(3, 0, 0) testTransactionGasCostWithMissingFields(t, node) diff --git a/integrationTests/benchmarks/loadFromTrie_test.go b/integrationTests/benchmarks/loadFromTrie_test.go index c3c7a99f573..576326bbc0d 100644 --- a/integrationTests/benchmarks/loadFromTrie_test.go +++ b/integrationTests/benchmarks/loadFromTrie_test.go @@ -32,6 +32,10 @@ func TestTrieLoadTime(t *testing.T) { } func TestTrieLoadTimeForOneLevel(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + numTrieLevels := 1 numTries := 10000 numChildrenPerBranch := 8 diff --git a/integrationTests/chainSimulator/staking/simpleStake_test.go b/integrationTests/chainSimulator/staking/simpleStake_test.go index 6439e14d623..735a0bde4b2 100644 --- a/integrationTests/chainSimulator/staking/simpleStake_test.go +++ b/integrationTests/chainSimulator/staking/simpleStake_test.go @@ -28,6 +28,10 @@ import ( // // Internal test scenario #3 func TestChainSimulator_SimpleStake(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + t.Run("staking ph 4 is not active", func(t *testing.T) { testChainSimulatorSimpleStake(t, 1, "queued") }) diff --git a/integrationTests/factory/dataComponents/dataComponents_test.go b/integrationTests/factory/dataComponents/dataComponents_test.go index 9ebc4a49fc5..c28a41c6543 100644 --- a/integrationTests/factory/dataComponents/dataComponents_test.go +++ b/integrationTests/factory/dataComponents/dataComponents_test.go @@ -13,6 +13,10 @@ import ( ) func TestDataComponents_Create_Close_ShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + time.Sleep(time.Second * 4) gc := goroutines.NewGoCounter(goroutines.TestsRelevantGoRoutines) diff --git a/integrationTests/frontend/wallet/txInterception_test.go b/integrationTests/frontend/wallet/txInterception_test.go index 1cb60ea8a46..1eeacc61f94 100644 --- a/integrationTests/frontend/wallet/txInterception_test.go +++ b/integrationTests/frontend/wallet/txInterception_test.go @@ -15,6 +15,10 @@ import ( const mintingValue = "100000000" func TestInterceptedTxWithoutDataField(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + value := big.NewInt(0) value.SetString("999", 10) @@ -35,6 +39,10 @@ func TestInterceptedTxWithoutDataField(t *testing.T) { } func TestInterceptedTxWithDataField(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + value := big.NewInt(0) value.SetString("999", 10) @@ -55,6 +63,10 @@ func TestInterceptedTxWithDataField(t *testing.T) { } func TestInterceptedTxWithSigningOverTxHash(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + value := big.NewInt(0) value.SetString("1000000000000000000", 10) diff --git a/integrationTests/node/getAccount/getAccount_test.go b/integrationTests/node/getAccount/getAccount_test.go index 16fa37909c3..487c8b1a15a 100644 --- a/integrationTests/node/getAccount/getAccount_test.go +++ b/integrationTests/node/getAccount/getAccount_test.go @@ -31,7 +31,9 @@ func createAccountsRepository(accDB state.AccountsAdapter, blockchain chainData. } func TestNode_GetAccountAccountDoesNotExistsShouldRetEmpty(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } trieStorage, _ := integrationTests.CreateTrieStorageManager(testscommon.CreateMemUnit()) accDB, _ := integrationTests.CreateAccountsDB(0, trieStorage) @@ -67,7 +69,9 @@ func TestNode_GetAccountAccountDoesNotExistsShouldRetEmpty(t *testing.T) { } func TestNode_GetAccountAccountExistsShouldReturn(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } testNonce := uint64(7) testBalance := big.NewInt(100) diff --git a/integrationTests/p2p/networkSharding-hbv2/networkSharding_test.go b/integrationTests/p2p/networkSharding-hbv2/networkSharding_test.go index c11c73838c5..94f26831173 100644 --- a/integrationTests/p2p/networkSharding-hbv2/networkSharding_test.go +++ b/integrationTests/p2p/networkSharding-hbv2/networkSharding_test.go @@ -39,6 +39,10 @@ func createDefaultConfig() p2pConfig.P2PConfig { } func TestConnectionsInNetworkShardingWithShardingWithLists(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + p2pCfg := createDefaultConfig() p2pCfg.Sharding = p2pConfig.ShardingConfig{ TargetPeerCount: 12, @@ -54,10 +58,6 @@ func TestConnectionsInNetworkShardingWithShardingWithLists(t *testing.T) { } func testConnectionsInNetworkSharding(t *testing.T, p2pConfig p2pConfig.P2PConfig) { - if testing.Short() { - t.Skip("this is not a short test") - } - nodesPerShard := 8 numMetaNodes := 8 numObserversOnShard := 2 diff --git a/integrationTests/singleShard/smartContract/dns_test.go b/integrationTests/singleShard/smartContract/dns_test.go index 94319e2ef7a..bdfd26da827 100644 --- a/integrationTests/singleShard/smartContract/dns_test.go +++ b/integrationTests/singleShard/smartContract/dns_test.go @@ -13,9 +13,8 @@ import ( ) func TestDNS_Register(t *testing.T) { - // TODO reinstate test after Wasm VM pointer fix if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") + t.Skip("this is not a short test") } expectedDNSAddress := []byte{0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 180, 108, 178, 102, 195, 67, 184, 127, 204, 159, 104, 123, 190, 33, 224, 91, 255, 244, 118, 95, 24, 217} diff --git a/integrationTests/state/genesisState/genesisState_test.go b/integrationTests/state/genesisState/genesisState_test.go index 306980f2ce6..811ae1a4901 100644 --- a/integrationTests/state/genesisState/genesisState_test.go +++ b/integrationTests/state/genesisState/genesisState_test.go @@ -70,7 +70,9 @@ func TestCreationOfTheGenesisState(t *testing.T) { } func TestExtensionNodeToBranchEdgeCaseSet1(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } tr1 := integrationTests.CreateNewDefaultTrie() tr2 := integrationTests.CreateNewDefaultTrie() @@ -105,7 +107,9 @@ func TestExtensionNodeToBranchEdgeCaseSet1(t *testing.T) { } func TestExtensionNodeToBranchEdgeCaseSet2(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } tr1 := integrationTests.CreateNewDefaultTrie() tr2 := integrationTests.CreateNewDefaultTrie() diff --git a/integrationTests/state/stateExecTransaction/stateExecTransaction_test.go b/integrationTests/state/stateExecTransaction/stateExecTransaction_test.go index c97b9ad52b6..f79e0ff22cc 100644 --- a/integrationTests/state/stateExecTransaction/stateExecTransaction_test.go +++ b/integrationTests/state/stateExecTransaction/stateExecTransaction_test.go @@ -52,7 +52,9 @@ func TestExecTransaction_SelfTransactionShouldWork(t *testing.T) { } func TestExecTransaction_SelfTransactionWithRevertShouldWork(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } trieStorage, _ := integrationTests.CreateTrieStorageManager(integrationTests.CreateMemUnit()) accnts, _ := integrationTests.CreateAccountsDB(0, trieStorage) @@ -182,7 +184,6 @@ func TestExecTransaction_MoreTransactionsMoreIterationsWithRevertShouldWork(t *t if testing.Short() { t.Skip("this is not a short test") } - t.Parallel() trieStorage, _ := integrationTests.CreateTrieStorageManager(integrationTests.CreateMemUnit()) accnts, _ := integrationTests.CreateAccountsDB(0, trieStorage) diff --git a/integrationTests/state/stateTrieSync/stateTrieSync_test.go b/integrationTests/state/stateTrieSync/stateTrieSync_test.go index 8bfbd584a70..4833c99f4fe 100644 --- a/integrationTests/state/stateTrieSync/stateTrieSync_test.go +++ b/integrationTests/state/stateTrieSync/stateTrieSync_test.go @@ -59,6 +59,10 @@ func createTestProcessorNodeAndTrieStorage( } func TestNode_RequestInterceptTrieNodesWithMessenger(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + t.Run("test with double lists version", func(t *testing.T) { testNodeRequestInterceptTrieNodesWithMessenger(t, 2) }) @@ -180,6 +184,10 @@ func printStatistics(ctx context.Context, stats common.SizeSyncStatisticsHandler } func TestNode_RequestInterceptTrieNodesWithMessengerNotSyncingShouldErr(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + t.Run("test with double lists version", func(t *testing.T) { testNodeRequestInterceptTrieNodesWithMessengerNotSyncingShouldErr(t, 2) }) diff --git a/integrationTests/vm/mockVM/vmDeploy/vmDeploy_test.go b/integrationTests/vm/mockVM/vmDeploy/vmDeploy_test.go index 4390a3eff47..1a53d3ce4e9 100644 --- a/integrationTests/vm/mockVM/vmDeploy/vmDeploy_test.go +++ b/integrationTests/vm/mockVM/vmDeploy/vmDeploy_test.go @@ -15,6 +15,10 @@ import ( ) func TestVmDeployWithoutTransferShouldDeploySCCode(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + vmOpGas := uint64(1) senderAddressBytes := []byte("12345678901234567890123456789012") senderNonce := uint64(11) @@ -70,6 +74,10 @@ func TestVmDeployWithoutTransferShouldDeploySCCode(t *testing.T) { } func TestVmDeployWithTransferShouldDeploySCCode(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + vmOpGas := uint64(1) senderAddressBytes := []byte("12345678901234567890123456789012") senderNonce := uint64(11) @@ -124,6 +132,10 @@ func TestVmDeployWithTransferShouldDeploySCCode(t *testing.T) { } func TestVmDeployWithTransferAndGasShouldDeploySCCode(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + vmOpGas := uint64(1) senderAddressBytes := []byte("12345678901234567890123456789012") senderNonce := uint64(11) @@ -181,6 +193,10 @@ func TestVmDeployWithTransferAndGasShouldDeploySCCode(t *testing.T) { } func TestVMDeployWithTransferWithInsufficientGasShouldReturnErr(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + vmOpGas := uint64(1000) senderAddressBytes := []byte("12345678901234567890123456789012") senderNonce := uint64(11) diff --git a/integrationTests/vm/mockVM/vmGet/vmGet_test.go b/integrationTests/vm/mockVM/vmGet/vmGet_test.go index bd818df6884..5083c44a276 100644 --- a/integrationTests/vm/mockVM/vmGet/vmGet_test.go +++ b/integrationTests/vm/mockVM/vmGet/vmGet_test.go @@ -29,6 +29,10 @@ import ( ) func TestVmGetShouldReturnValue(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + accnts, destinationAddressBytes, expectedValueForVar := deploySmartContract(t) mockVM := vm.CreateOneSCExecutorMockVM(accnts) diff --git a/integrationTests/vm/mockVM/vmRunContract/vmRunContract_test.go b/integrationTests/vm/mockVM/vmRunContract/vmRunContract_test.go index 00f8ef20610..af7d0e33e47 100644 --- a/integrationTests/vm/mockVM/vmRunContract/vmRunContract_test.go +++ b/integrationTests/vm/mockVM/vmRunContract/vmRunContract_test.go @@ -19,6 +19,10 @@ import ( // TODO add integration and unit tests with generating and broadcasting transaction with empty recv address func TestRunSCWithoutTransferShouldRunSCCode(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + vmOpGas := uint64(1) senderAddressBytes := []byte("12345678901234567890123456789012") senderNonce := uint64(11) @@ -89,6 +93,10 @@ func TestRunSCWithoutTransferShouldRunSCCode(t *testing.T) { } func TestRunSCWithTransferShouldRunSCCode(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + vmOpGas := uint64(1) senderAddressBytes := []byte("12345678901234567890123456789012") senderNonce := uint64(11) @@ -160,6 +168,10 @@ func TestRunSCWithTransferShouldRunSCCode(t *testing.T) { } func TestRunWithTransferAndGasShouldRunSCCode(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + vmOpGas := uint64(1) senderAddressBytes := []byte("12345678901234567890123456789012") senderNonce := uint64(11) @@ -231,6 +243,10 @@ func TestRunWithTransferAndGasShouldRunSCCode(t *testing.T) { } func TestRunWithTransferWithInsufficientGasShouldReturnErr(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + vmOpGas := uint64(1) senderAddressBytes := []byte("12345678901234567890123456789012") senderNonce := uint64(11) diff --git a/integrationTests/vm/staking/stakingV4_test.go b/integrationTests/vm/staking/stakingV4_test.go index 45cc1bcd85e..6471ec72d3e 100644 --- a/integrationTests/vm/staking/stakingV4_test.go +++ b/integrationTests/vm/staking/stakingV4_test.go @@ -175,7 +175,9 @@ func checkStakingV4EpochChangeFlow( } func TestStakingV4(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } numOfMetaNodes := uint32(400) numOfShards := uint32(3) @@ -271,7 +273,9 @@ func TestStakingV4(t *testing.T) { } func TestStakingV4MetaProcessor_ProcessMultipleNodesWithSameSetupExpectSameRootHash(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } numOfMetaNodes := uint32(6) numOfShards := uint32(3) @@ -318,7 +322,9 @@ func TestStakingV4MetaProcessor_ProcessMultipleNodesWithSameSetupExpectSameRootH } func TestStakingV4_UnStakeNodesWithNotEnoughFunds(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } pubKeys := generateAddresses(0, 20) @@ -476,7 +482,9 @@ func TestStakingV4_UnStakeNodesWithNotEnoughFunds(t *testing.T) { } func TestStakingV4_StakeNewNodes(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } pubKeys := generateAddresses(0, 20) @@ -617,7 +625,9 @@ func TestStakingV4_StakeNewNodes(t *testing.T) { } func TestStakingV4_UnStakeNodes(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } pubKeys := generateAddresses(0, 20) @@ -812,7 +822,9 @@ func TestStakingV4_UnStakeNodes(t *testing.T) { } func TestStakingV4_JailAndUnJailNodes(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } pubKeys := generateAddresses(0, 20) @@ -969,7 +981,9 @@ func TestStakingV4_JailAndUnJailNodes(t *testing.T) { } func TestStakingV4_DifferentEdgeCasesWithNotEnoughNodesInWaitingShouldSendShuffledToToWaiting(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } pubKeys := generateAddresses(0, 20) @@ -1184,7 +1198,9 @@ func TestStakingV4_DifferentEdgeCasesWithNotEnoughNodesInWaitingShouldSendShuffl } func TestStakingV4_NewlyStakedNodesInStakingV4Step2ShouldBeSentToWaitingIfListIsTooLow(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } pubKeys := generateAddresses(0, 20) @@ -1323,7 +1339,9 @@ func TestStakingV4_NewlyStakedNodesInStakingV4Step2ShouldBeSentToWaitingIfListIs } func TestStakingV4_LeavingNodesEdgeCases(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } pubKeys := generateAddresses(0, 20) diff --git a/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go b/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go index e5b6661d02e..6c3f6844403 100644 --- a/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go +++ b/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go @@ -27,7 +27,7 @@ func getZeroGasAndFees() scheduled.GasAndFees { func TestSCCallCostTransactionCost(t *testing.T) { if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") + t.Skip("this is not a short test") } testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ @@ -54,7 +54,7 @@ func TestSCCallCostTransactionCost(t *testing.T) { func TestScDeployTransactionCost(t *testing.T) { if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") + t.Skip("this is not a short test") } testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) @@ -74,7 +74,7 @@ func TestScDeployTransactionCost(t *testing.T) { func TestAsyncCallsTransactionCost(t *testing.T) { if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") + t.Skip("this is not a short test") } testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) @@ -105,7 +105,7 @@ func TestAsyncCallsTransactionCost(t *testing.T) { func TestBuiltInFunctionTransactionCost(t *testing.T) { if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") + t.Skip("this is not a short test") } testContext, err := vm.CreatePreparedTxProcessorWithVMs( @@ -131,7 +131,7 @@ func TestBuiltInFunctionTransactionCost(t *testing.T) { func TestESDTTransfer(t *testing.T) { if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") + t.Skip("this is not a short test") } testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) @@ -154,7 +154,7 @@ func TestESDTTransfer(t *testing.T) { func TestAsyncESDTTransfer(t *testing.T) { if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") + t.Skip("this is not a short test") } testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ diff --git a/integrationTests/vm/txsFee/backwardsCompatibility_test.go b/integrationTests/vm/txsFee/backwardsCompatibility_test.go index 94735de21a5..2b160d342cd 100644 --- a/integrationTests/vm/txsFee/backwardsCompatibility_test.go +++ b/integrationTests/vm/txsFee/backwardsCompatibility_test.go @@ -17,6 +17,10 @@ import ( // minGasPrice = 1, gasPerDataByte = 1, minGasLimit = 1 func TestMoveBalanceSelfShouldWorkAndConsumeTxFeeWhenAllFlagsAreDisabled(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ PenalizedTooMuchGasEnableEpoch: 100, SCDeployEnableEpoch: 100, @@ -57,6 +61,10 @@ func TestMoveBalanceSelfShouldWorkAndConsumeTxFeeWhenAllFlagsAreDisabled(t *test // minGasPrice = 1, gasPerDataByte = 1, minGasLimit = 1 func TestMoveBalanceAllFlagsDisabledLessBalanceThanGasLimitMulGasPrice(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ PenalizedTooMuchGasEnableEpoch: integrationTests.UnreachableEpoch, BuiltInFunctionsEnableEpoch: integrationTests.UnreachableEpoch, @@ -80,6 +88,10 @@ func TestMoveBalanceAllFlagsDisabledLessBalanceThanGasLimitMulGasPrice(t *testin } func TestMoveBalanceSelfShouldWorkAndConsumeTxFeeWhenSomeFlagsAreDisabled(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs( config.EnableEpochs{ PenalizedTooMuchGasEnableEpoch: 0, diff --git a/integrationTests/vm/txsFee/builtInFunctions_test.go b/integrationTests/vm/txsFee/builtInFunctions_test.go index 8bd8c80db0f..5f0ae16ebc3 100644 --- a/integrationTests/vm/txsFee/builtInFunctions_test.go +++ b/integrationTests/vm/txsFee/builtInFunctions_test.go @@ -66,6 +66,10 @@ func TestBuildInFunctionChangeOwnerCallShouldWorkV1(t *testing.T) { } func TestBuildInFunctionChangeOwnerCallShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs( config.EnableEpochs{ PenalizedTooMuchGasEnableEpoch: integrationTests.UnreachableEpoch, @@ -103,6 +107,10 @@ func TestBuildInFunctionChangeOwnerCallShouldWork(t *testing.T) { } func TestBuildInFunctionChangeOwnerCallWrongOwnerShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -140,6 +148,10 @@ func TestBuildInFunctionChangeOwnerCallWrongOwnerShouldConsumeGas(t *testing.T) } func TestBuildInFunctionChangeOwnerInvalidAddressShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -174,6 +186,10 @@ func TestBuildInFunctionChangeOwnerInvalidAddressShouldConsumeGas(t *testing.T) } func TestBuildInFunctionChangeOwnerCallInsufficientGasLimitShouldNotConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -210,6 +226,10 @@ func TestBuildInFunctionChangeOwnerCallInsufficientGasLimitShouldNotConsumeGas(t } func TestBuildInFunctionChangeOwnerOutOfGasShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -245,6 +265,10 @@ func TestBuildInFunctionChangeOwnerOutOfGasShouldConsumeGas(t *testing.T) { } func TestBuildInFunctionSaveKeyValue_WrongDestination(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + shardCoord, _ := sharding.NewMultiShardCoordinator(2, 0) testContext, err := vm.CreatePreparedTxProcessorWithVMsWithShardCoordinator( @@ -280,6 +304,10 @@ func TestBuildInFunctionSaveKeyValue_WrongDestination(t *testing.T) { } func TestBuildInFunctionSaveKeyValue_NotEnoughGasFor3rdSave(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + shardCoord, _ := sharding.NewMultiShardCoordinator(2, 0) testContext, err := vm.CreatePreparedTxProcessorWithVMsWithShardCoordinator( @@ -308,6 +336,10 @@ func TestBuildInFunctionSaveKeyValue_NotEnoughGasFor3rdSave(t *testing.T) { } func TestBuildInFunctionSaveKeyValue_NotEnoughGasForTheSameKeyValue(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + shardCoord, _ := sharding.NewMultiShardCoordinator(2, 0) gasScheduleNotifier := vm.CreateMockGasScheduleNotifier() diff --git a/integrationTests/vm/txsFee/esdtLocalBurn_test.go b/integrationTests/vm/txsFee/esdtLocalBurn_test.go index c76957928a5..29c4fc26320 100644 --- a/integrationTests/vm/txsFee/esdtLocalBurn_test.go +++ b/integrationTests/vm/txsFee/esdtLocalBurn_test.go @@ -14,6 +14,10 @@ import ( ) func TestESDTLocalBurnShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -44,6 +48,10 @@ func TestESDTLocalBurnShouldWork(t *testing.T) { } func TestESDTLocalBurnMoreThanTotalBalanceShouldErr(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -74,6 +82,10 @@ func TestESDTLocalBurnMoreThanTotalBalanceShouldErr(t *testing.T) { } func TestESDTLocalBurnNotAllowedShouldErr(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/esdtLocalMint_test.go b/integrationTests/vm/txsFee/esdtLocalMint_test.go index 491d9102372..f2104f4c341 100644 --- a/integrationTests/vm/txsFee/esdtLocalMint_test.go +++ b/integrationTests/vm/txsFee/esdtLocalMint_test.go @@ -14,6 +14,10 @@ import ( ) func TestESDTLocalMintShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -44,6 +48,10 @@ func TestESDTLocalMintShouldWork(t *testing.T) { } func TestESDTLocalMintNotAllowedShouldErr(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/esdt_test.go b/integrationTests/vm/txsFee/esdt_test.go index da865619d4e..07871a87750 100644 --- a/integrationTests/vm/txsFee/esdt_test.go +++ b/integrationTests/vm/txsFee/esdt_test.go @@ -18,6 +18,10 @@ import ( ) func TestESDTTransferShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -54,6 +58,10 @@ func TestESDTTransferShouldWork(t *testing.T) { } func TestESDTTransferShouldWorkToMuchGasShouldConsumeAllGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -90,6 +98,10 @@ func TestESDTTransferShouldWorkToMuchGasShouldConsumeAllGas(t *testing.T) { } func TestESDTTransferInvalidESDTValueShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -126,6 +138,10 @@ func TestESDTTransferInvalidESDTValueShouldConsumeGas(t *testing.T) { } func TestESDTTransferCallBackOnErrorShouldNotGenerateSCRsFurther(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + shardC, _ := sharding.NewMultiShardCoordinator(2, 0) testContext, err := vm.CreatePreparedTxProcessorWithVMsWithShardCoordinator(config.EnableEpochs{}, shardC) require.Nil(t, err) diff --git a/integrationTests/vm/txsFee/moveBalance_test.go b/integrationTests/vm/txsFee/moveBalance_test.go index 78646813825..848494b0396 100644 --- a/integrationTests/vm/txsFee/moveBalance_test.go +++ b/integrationTests/vm/txsFee/moveBalance_test.go @@ -20,6 +20,10 @@ const gasPrice = uint64(10) // minGasPrice = 1, gasPerDataByte = 1, minGasLimit = 1 func TestMoveBalanceSelfShouldWorkAndConsumeTxFee(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -55,6 +59,10 @@ func TestMoveBalanceSelfShouldWorkAndConsumeTxFee(t *testing.T) { // minGasPrice = 1, gasPerDataByte = 1, minGasLimit = 1 func TestMoveBalanceAllFlagsEnabledLessBalanceThanGasLimitMulGasPrice(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -72,6 +80,10 @@ func TestMoveBalanceAllFlagsEnabledLessBalanceThanGasLimitMulGasPrice(t *testing } func TestMoveBalanceShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -112,6 +124,10 @@ func TestMoveBalanceShouldWork(t *testing.T) { } func TestMoveBalanceInvalidHasGasButNoValueShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -141,6 +157,10 @@ func TestMoveBalanceInvalidHasGasButNoValueShouldConsumeGas(t *testing.T) { } func TestMoveBalanceHigherNonceShouldNotConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -171,6 +191,10 @@ func TestMoveBalanceHigherNonceShouldNotConsumeGas(t *testing.T) { } func TestMoveBalanceMoreGasThanGasLimitPerMiniBlockForSafeCrossShard(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -202,6 +226,10 @@ func TestMoveBalanceMoreGasThanGasLimitPerMiniBlockForSafeCrossShard(t *testing. } func TestMoveBalanceInvalidUserNames(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/multiESDTTransfer_test.go b/integrationTests/vm/txsFee/multiESDTTransfer_test.go index d9457da31c5..c85a1a2bc1b 100644 --- a/integrationTests/vm/txsFee/multiESDTTransfer_test.go +++ b/integrationTests/vm/txsFee/multiESDTTransfer_test.go @@ -15,6 +15,10 @@ import ( ) func TestMultiESDTTransferShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -69,6 +73,10 @@ func TestMultiESDTTransferShouldWork(t *testing.T) { } func TestMultiESDTTransferFailsBecauseOfMaxLimit(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMsAndCustomGasSchedule(config.EnableEpochs{}, func(gasMap wasmConfig.GasScheduleMap) { gasMap[common.MaxPerTransaction]["MaxNumberOfTransfersPerTx"] = 1 diff --git a/integrationTests/vm/txsFee/multiShard/asyncCallWithChangeOwner_test.go b/integrationTests/vm/txsFee/multiShard/asyncCallWithChangeOwner_test.go index aac3723f294..28130046e11 100644 --- a/integrationTests/vm/txsFee/multiShard/asyncCallWithChangeOwner_test.go +++ b/integrationTests/vm/txsFee/multiShard/asyncCallWithChangeOwner_test.go @@ -17,7 +17,7 @@ import ( func TestDoChangeOwnerCrossShardFromAContract(t *testing.T) { if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") + t.Skip("this is not a short test") } enableEpochs := config.EnableEpochs{ diff --git a/integrationTests/vm/txsFee/multiShard/builtInFunctions_test.go b/integrationTests/vm/txsFee/multiShard/builtInFunctions_test.go index ea14882730b..dc6172eeef8 100644 --- a/integrationTests/vm/txsFee/multiShard/builtInFunctions_test.go +++ b/integrationTests/vm/txsFee/multiShard/builtInFunctions_test.go @@ -33,7 +33,7 @@ func getZeroGasAndFees() scheduled.GasAndFees { // 4. Execute SCR from context destination on context source ( the new owner will receive the developer rewards) func TestBuiltInFunctionExecuteOnSourceAndDestinationShouldWork(t *testing.T) { if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") + t.Skip("this is not a short test") } testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard( diff --git a/integrationTests/vm/txsFee/multiShard/esdtLiquidity_test.go b/integrationTests/vm/txsFee/multiShard/esdtLiquidity_test.go index a18a62003e3..036c17d9cef 100644 --- a/integrationTests/vm/txsFee/multiShard/esdtLiquidity_test.go +++ b/integrationTests/vm/txsFee/multiShard/esdtLiquidity_test.go @@ -18,6 +18,10 @@ import ( ) func TestSystemAccountLiquidityAfterCrossShardTransferAndBurn(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + tokenID := []byte("MYNFT") sh0Addr := []byte("12345678901234567890123456789010") sh1Addr := []byte("12345678901234567890123456789011") @@ -66,6 +70,10 @@ func TestSystemAccountLiquidityAfterCrossShardTransferAndBurn(t *testing.T) { } func TestSystemAccountLiquidityAfterNFTWipe(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + tokenID := []byte("MYNFT-0a0a0a") sh0Addr := bytes.Repeat([]byte{1}, 31) sh0Addr = append(sh0Addr, 0) @@ -112,6 +120,10 @@ func TestSystemAccountLiquidityAfterNFTWipe(t *testing.T) { } func TestSystemAccountLiquidityAfterSFTWipe(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + tokenID := []byte("MYSFT-0a0a0a") sh0Addr := bytes.Repeat([]byte{1}, 31) sh0Addr = append(sh0Addr, 0) diff --git a/integrationTests/vm/txsFee/multiShard/esdt_test.go b/integrationTests/vm/txsFee/multiShard/esdt_test.go index f224b528ef6..8f978daee1c 100644 --- a/integrationTests/vm/txsFee/multiShard/esdt_test.go +++ b/integrationTests/vm/txsFee/multiShard/esdt_test.go @@ -16,6 +16,10 @@ import ( ) func TestESDTTransferShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -46,6 +50,10 @@ func TestESDTTransferShouldWork(t *testing.T) { } func TestMultiESDTNFTTransferViaRelayedV2(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + tokenID1 := []byte("MYNFT1") tokenID2 := []byte("MYNFT2") sh0Addr := []byte("12345678901234567890123456789010") diff --git a/integrationTests/vm/txsFee/multiShard/moveBalance_test.go b/integrationTests/vm/txsFee/multiShard/moveBalance_test.go index 41e404d4af7..8c5f6bd6015 100644 --- a/integrationTests/vm/txsFee/multiShard/moveBalance_test.go +++ b/integrationTests/vm/txsFee/multiShard/moveBalance_test.go @@ -14,6 +14,10 @@ import ( ) func TestMoveBalanceShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -49,7 +53,9 @@ func TestMoveBalanceShouldWork(t *testing.T) { } func TestMoveBalanceContractAddressDataFieldNilShouldConsumeGas(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) require.Nil(t, err) @@ -89,7 +95,9 @@ func TestMoveBalanceContractAddressDataFieldNilShouldConsumeGas(t *testing.T) { } func TestMoveBalanceContractAddressDataFieldNotNilShouldConsumeGas(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) require.Nil(t, err) @@ -129,6 +137,10 @@ func TestMoveBalanceContractAddressDataFieldNotNilShouldConsumeGas(t *testing.T) } func TestMoveBalanceExecuteOneSourceAndDestinationShard(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) require.Nil(t, err) defer testContextSource.Close() diff --git a/integrationTests/vm/txsFee/multiShard/nftTransferUpdate_test.go b/integrationTests/vm/txsFee/multiShard/nftTransferUpdate_test.go index 3a0b19b0b24..1fdd2f6f78f 100644 --- a/integrationTests/vm/txsFee/multiShard/nftTransferUpdate_test.go +++ b/integrationTests/vm/txsFee/multiShard/nftTransferUpdate_test.go @@ -15,6 +15,10 @@ import ( ) func TestNFTTransferAndUpdateOnOldTypeToken(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + enableEpochs := config.EnableEpochs{ CheckCorrectTokenIDForTransferRoleEnableEpoch: 3, DisableExecByCallerEnableEpoch: 3, diff --git a/integrationTests/vm/txsFee/multiShard/relayedBuiltInFunctions_test.go b/integrationTests/vm/txsFee/multiShard/relayedBuiltInFunctions_test.go index a97a5bfd7fe..e987d4dbc74 100644 --- a/integrationTests/vm/txsFee/multiShard/relayedBuiltInFunctions_test.go +++ b/integrationTests/vm/txsFee/multiShard/relayedBuiltInFunctions_test.go @@ -15,9 +15,8 @@ import ( ) func TestRelayedBuiltInFunctionExecuteOnRelayerAndDstShardShouldWork(t *testing.T) { - // TODO reinstate test after Wasm VM pointer fix if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") + t.Skip("this is not a short test") } testContextRelayer, err := vm.CreatePreparedTxProcessorWithVMsMultiShard( diff --git a/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go b/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go index 2dd36161143..aa206c591b4 100644 --- a/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go +++ b/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go @@ -14,6 +14,10 @@ import ( ) func TestRelayedMoveBalanceRelayerShard0InnerTxSenderAndReceiverShard1ShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -58,6 +62,10 @@ func TestRelayedMoveBalanceRelayerShard0InnerTxSenderAndReceiverShard1ShouldWork } func TestRelayedMoveBalanceRelayerAndInnerTxSenderShard0ReceiverShard1(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -103,6 +111,10 @@ func TestRelayedMoveBalanceRelayerAndInnerTxSenderShard0ReceiverShard1(t *testin } func TestRelayedMoveBalanceExecuteOnSourceAndDestination(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) require.Nil(t, err) defer testContextSource.Close() @@ -167,6 +179,10 @@ func TestRelayedMoveBalanceExecuteOnSourceAndDestination(t *testing.T) { } func TestRelayedMoveBalanceExecuteOnSourceAndDestinationRelayerAndInnerTxSenderShard0InnerTxReceiverShard1ShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) require.Nil(t, err) defer testContextSource.Close() @@ -227,6 +243,10 @@ func TestRelayedMoveBalanceExecuteOnSourceAndDestinationRelayerAndInnerTxSenderS } func TestRelayedMoveBalanceRelayerAndInnerTxReceiverShard0SenderShard1(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) require.Nil(t, err) defer testContextSource.Close() @@ -299,6 +319,10 @@ func TestRelayedMoveBalanceRelayerAndInnerTxReceiverShard0SenderShard1(t *testin } func TestMoveBalanceRelayerShard0InnerTxSenderShard1InnerTxReceiverShard2ShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContextRelayer, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) require.Nil(t, err) defer testContextRelayer.Close() diff --git a/integrationTests/vm/txsFee/relayedMoveBalance_test.go b/integrationTests/vm/txsFee/relayedMoveBalance_test.go index 2c7e230941d..accdffbfb4e 100644 --- a/integrationTests/vm/txsFee/relayedMoveBalance_test.go +++ b/integrationTests/vm/txsFee/relayedMoveBalance_test.go @@ -19,6 +19,10 @@ import ( ) func TestRelayedMoveBalanceShouldWork(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -65,6 +69,10 @@ func TestRelayedMoveBalanceShouldWork(t *testing.T) { } func TestRelayedMoveBalanceInvalidGasLimitShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -97,6 +105,10 @@ func TestRelayedMoveBalanceInvalidGasLimitShouldConsumeGas(t *testing.T) { } func TestRelayedMoveBalanceInvalidUserTxShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -129,6 +141,10 @@ func TestRelayedMoveBalanceInvalidUserTxShouldConsumeGas(t *testing.T) { } func TestRelayedMoveBalanceInvalidUserTxValueShouldConsumeGas(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ RelayedNonceFixEnableEpoch: 1, }) @@ -163,6 +179,10 @@ func TestRelayedMoveBalanceInvalidUserTxValueShouldConsumeGas(t *testing.T) { } func TestRelayedMoveBalanceHigherNonce(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ RelayedNonceFixEnableEpoch: 1, }) @@ -215,6 +235,10 @@ func TestRelayedMoveBalanceHigherNonce(t *testing.T) { } func TestRelayedMoveBalanceLowerNonce(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ RelayedNonceFixEnableEpoch: 1, }) @@ -267,6 +291,10 @@ func TestRelayedMoveBalanceLowerNonce(t *testing.T) { } func TestRelayedMoveBalanceHigherNonceWithActivatedFixCrossShard(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + enableEpochs := config.EnableEpochs{ RelayedNonceFixEnableEpoch: 0, } diff --git a/integrationTests/vm/txsFee/validatorSC_test.go b/integrationTests/vm/txsFee/validatorSC_test.go index ca4ff9271de..6de545c5c93 100644 --- a/integrationTests/vm/txsFee/validatorSC_test.go +++ b/integrationTests/vm/txsFee/validatorSC_test.go @@ -50,6 +50,10 @@ func saveDelegationManagerConfig(testContext *vm.VMTestContext) { } func TestValidatorsSC_DoStakePutInQueueUnStakeAndUnBondShouldRefund(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContextMeta, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(core.MetachainShardId, config.EnableEpochs{}) require.Nil(t, err) @@ -106,6 +110,10 @@ func checkReturnLog(t *testing.T, testContextMeta *vm.VMTestContext, subStr stri } func TestValidatorsSC_DoStakePutInQueueUnStakeAndUnBondTokensShouldRefund(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContextMeta, err := vm.CreatePreparedTxProcessorWithVMsMultiShard( core.MetachainShardId, config.EnableEpochs{ @@ -142,6 +150,10 @@ func TestValidatorsSC_DoStakePutInQueueUnStakeAndUnBondTokensShouldRefund(t *tes } func TestValidatorsSC_DoStakeWithTopUpValueTryToUnStakeTokensAndUnBondTokens(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + argUnbondTokensV1 := config.EnableEpochs{ UnbondTokensV2EnableEpoch: 20000, StakingV4Step1EnableEpoch: stakingV4Step1EnableEpoch, @@ -185,6 +197,10 @@ func testValidatorsSCDoStakeWithTopUpValueTryToUnStakeTokensAndUnBondTokens(t *t } func TestValidatorsSC_ToStakePutInQueueUnStakeAndUnBondShouldRefundUnBondTokens(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContextMeta, err := vm.CreatePreparedTxProcessorWithVMsMultiShard( core.MetachainShardId, config.EnableEpochs{ @@ -237,6 +253,10 @@ func TestValidatorsSC_ToStakePutInQueueUnStakeAndUnBondShouldRefundUnBondTokens( } func TestValidatorsSC_ToStakePutInQueueUnStakeNodesAndUnBondNodesShouldRefund(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testContextMeta, err := vm.CreatePreparedTxProcessorWithVMsMultiShard( core.MetachainShardId, config.EnableEpochs{ diff --git a/integrationTests/vm/wasm/badcontracts/badcontracts_test.go b/integrationTests/vm/wasm/badcontracts/badcontracts_test.go index ccf211853b8..3ccd475e739 100644 --- a/integrationTests/vm/wasm/badcontracts/badcontracts_test.go +++ b/integrationTests/vm/wasm/badcontracts/badcontracts_test.go @@ -50,6 +50,10 @@ func Test_Bad_C_NoPanic(t *testing.T) { } func Test_Empty_C_NoPanic(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + context := wasm.SetupTestContext(t) defer context.Close() @@ -60,6 +64,10 @@ func Test_Empty_C_NoPanic(t *testing.T) { } func Test_Corrupt_NoPanic(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + context := wasm.SetupTestContext(t) defer context.Close() @@ -70,6 +78,10 @@ func Test_Corrupt_NoPanic(t *testing.T) { } func Test_NoMemoryDeclaration_NoPanic(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + context := wasm.SetupTestContext(t) defer context.Close() @@ -80,6 +92,10 @@ func Test_NoMemoryDeclaration_NoPanic(t *testing.T) { } func Test_BadFunctionNames_NoPanic(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + context := wasm.SetupTestContext(t) defer context.Close() @@ -88,6 +104,10 @@ func Test_BadFunctionNames_NoPanic(t *testing.T) { } func Test_BadReservedFunctions(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + context := wasm.SetupTestContext(t) defer context.Close() diff --git a/integrationTests/vm/wasm/wasmvm/asyncMockContracts_test.go b/integrationTests/vm/wasm/wasmvm/asyncMockContracts_test.go index 393ef51f5de..f7a3eece169 100644 --- a/integrationTests/vm/wasm/wasmvm/asyncMockContracts_test.go +++ b/integrationTests/vm/wasm/wasmvm/asyncMockContracts_test.go @@ -59,17 +59,22 @@ func TestMockContract_AsyncLegacy_InShard(t *testing.T) { } func TestMockContract_AsyncLegacy_CrossShard(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testMockContract_CrossShard(t, LegacyAsyncCallType) } func TestMockContract_NewAsync_CrossShard(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + testMockContract_CrossShard(t, NewAsyncCallType) } func testMockContract_CrossShard(t *testing.T, asyncCallType []byte) { - if testing.Short() { - t.Skip("this is not a short test") - } transferEGLD := big.NewInt(42) numberOfShards := 2 diff --git a/integrationTests/vm/wasm/wasmvm/deployment/deploy_test.go b/integrationTests/vm/wasm/wasmvm/deployment/deploy_test.go index a4cfb755b76..a57599d2866 100644 --- a/integrationTests/vm/wasm/wasmvm/deployment/deploy_test.go +++ b/integrationTests/vm/wasm/wasmvm/deployment/deploy_test.go @@ -22,7 +22,7 @@ var senderBalance = big.NewInt(1000000000000) func TestScDeployShouldManageCorrectlyTheCodeMetadata(t *testing.T) { if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") + t.Skip("this is not a short test") } testContext, err := vm.CreatePreparedTxProcessorAndAccountsWithVMs( diff --git a/integrationTests/vm/wasm/wasmvm/deployment/upgrade_test.go b/integrationTests/vm/wasm/wasmvm/deployment/upgrade_test.go index 6d52f68acf2..22d2fc48a3f 100644 --- a/integrationTests/vm/wasm/wasmvm/deployment/upgrade_test.go +++ b/integrationTests/vm/wasm/wasmvm/deployment/upgrade_test.go @@ -20,7 +20,7 @@ const gasLimit = uint64(10000000) func TestScUpgradeShouldManageCorrectlyTheCodeMetadata(t *testing.T) { if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") + t.Skip("this is not a short test") } testContext, err := vm.CreatePreparedTxProcessorAndAccountsWithVMs( diff --git a/integrationTests/vm/wasm/wasmvm/scenariosConverter/scenariosTests/adder/converterAdder_test.go b/integrationTests/vm/wasm/wasmvm/scenariosConverter/scenariosTests/adder/converterAdder_test.go index b5d99257277..bf0fc2436fa 100644 --- a/integrationTests/vm/wasm/wasmvm/scenariosConverter/scenariosTests/adder/converterAdder_test.go +++ b/integrationTests/vm/wasm/wasmvm/scenariosConverter/scenariosTests/adder/converterAdder_test.go @@ -7,9 +7,17 @@ import ( ) func TestScenariosConverter_AdderWithExternalSteps(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + mc.CheckConverter(t, "./adder_with_external_steps.scen.json") } func Benchmark_ScenariosConverter_AdderWithExternalSteps(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + mc.BenchmarkScenariosSpecificTx(b, "./adder_with_external_steps.scen.json") } diff --git a/integrationTests/vm/wasm/wasmvm/scenariosConverter/scenariosTests/ecBenchmarks/converterEllipticCurves_test.go b/integrationTests/vm/wasm/wasmvm/scenariosConverter/scenariosTests/ecBenchmarks/converterEllipticCurves_test.go index 1978b6c0794..1f7b260e707 100644 --- a/integrationTests/vm/wasm/wasmvm/scenariosConverter/scenariosTests/ecBenchmarks/converterEllipticCurves_test.go +++ b/integrationTests/vm/wasm/wasmvm/scenariosConverter/scenariosTests/ecBenchmarks/converterEllipticCurves_test.go @@ -7,9 +7,17 @@ import ( ) func TestScenariosConverter_EllipticCurves(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + mc.CheckConverter(t, "./elliptic_curves.scen.json") } func Benchmark_ScenariosConverter_EllipticCurves(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + mc.BenchmarkScenariosSpecificTx(b, "./elliptic_curves.scen.json") } diff --git a/integrationTests/vm/wasm/wasmvm/scenariosConverter/scenariosTests/mex/converterMex_test.go b/integrationTests/vm/wasm/wasmvm/scenariosConverter/scenariosTests/mex/converterMex_test.go index bff4906aca6..c1719095a24 100644 --- a/integrationTests/vm/wasm/wasmvm/scenariosConverter/scenariosTests/mex/converterMex_test.go +++ b/integrationTests/vm/wasm/wasmvm/scenariosConverter/scenariosTests/mex/converterMex_test.go @@ -7,8 +7,16 @@ import ( ) func TestScenariosConverter_MexState(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + mc.CheckConverter(t, "./swap_fixed_input.scen.json") } func Benchmark_ScenariosConverter_SwapFixedInput(b *testing.B) { + if testing.Short() { + b.Skip("this is not a short benchmark") + } + mc.BenchmarkScenariosSpecificTx(b, "./swap_fixed_input.scen.json") } diff --git a/node/chainSimulator/components/processComponents_test.go b/node/chainSimulator/components/processComponents_test.go index 89010da5fd5..4628bbc4f66 100644 --- a/node/chainSimulator/components/processComponents_test.go +++ b/node/chainSimulator/components/processComponents_test.go @@ -236,16 +236,11 @@ func createArgsProcessComponentsHolder() ArgsProcessComponentsHolder { } func TestCreateProcessComponents(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } t.Run("should work", func(t *testing.T) { - // TODO reinstate test after Wasm VM pointer fix - if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") - } - - t.Parallel() - comp, err := CreateProcessComponents(createArgsProcessComponentsHolder()) require.NoError(t, err) require.NotNil(t, comp) @@ -351,13 +346,10 @@ func TestCreateProcessComponents(t *testing.T) { } func TestProcessComponentsHolder_IsInterfaceNil(t *testing.T) { - // TODO reinstate test after Wasm VM pointer fix if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") + t.Skip("this is not a short test") } - t.Parallel() - var comp *processComponentsHolder require.True(t, comp.IsInterfaceNil()) @@ -367,13 +359,10 @@ func TestProcessComponentsHolder_IsInterfaceNil(t *testing.T) { } func TestProcessComponentsHolder_Getters(t *testing.T) { - // TODO reinstate test after Wasm VM pointer fix if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") + t.Skip("this is not a short test") } - t.Parallel() - comp, err := CreateProcessComponents(createArgsProcessComponentsHolder()) require.NoError(t, err) diff --git a/node/chainSimulator/components/testOnlyProcessingNode_test.go b/node/chainSimulator/components/testOnlyProcessingNode_test.go index c48a8456086..5924663217b 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode_test.go +++ b/node/chainSimulator/components/testOnlyProcessingNode_test.go @@ -3,7 +3,6 @@ package components import ( "errors" "math/big" - "runtime" "strings" "testing" "time" @@ -50,8 +49,8 @@ func createMockArgsTestOnlyProcessingNode(t *testing.T) ArgsTestOnlyProcessingNo } func TestNewTestOnlyProcessingNode(t *testing.T) { - if runtime.GOARCH == "arm64" { - t.Skip("skipping test on arm64") + if testing.Short() { + t.Skip("this is not a short test") } t.Run("should work", func(t *testing.T) { @@ -140,9 +139,8 @@ func TestNewTestOnlyProcessingNode(t *testing.T) { } func TestTestOnlyProcessingNode_SetKeyValueForAddress(t *testing.T) { - // TODO reinstate test after Wasm VM pointer fix if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") + t.Skip("this is not a short test") } goodKeyValueMap := map[string]string{ @@ -252,9 +250,8 @@ func TestTestOnlyProcessingNode_SetKeyValueForAddress(t *testing.T) { } func TestTestOnlyProcessingNode_SetStateForAddress(t *testing.T) { - // TODO reinstate test after Wasm VM pointer fix if testing.Short() { - t.Skip("cannot run with -race -short; requires Wasm VM fix") + t.Skip("this is not a short test") } node, err := NewTestOnlyProcessingNode(createMockArgsTestOnlyProcessingNode(t)) @@ -419,8 +416,8 @@ func TestTestOnlyProcessingNode_SetStateForAddress(t *testing.T) { } func TestTestOnlyProcessingNode_IsInterfaceNil(t *testing.T) { - if runtime.GOARCH == "arm64" { - t.Skip("skipping test on arm64") + if testing.Short() { + t.Skip("this is not a short test") } var node *testOnlyProcessingNode @@ -431,8 +428,8 @@ func TestTestOnlyProcessingNode_IsInterfaceNil(t *testing.T) { } func TestTestOnlyProcessingNode_Close(t *testing.T) { - if runtime.GOARCH == "arm64" { - t.Skip("skipping test on arm64") + if testing.Short() { + t.Skip("this is not a short test") } node, err := NewTestOnlyProcessingNode(createMockArgsTestOnlyProcessingNode(t)) @@ -442,8 +439,8 @@ func TestTestOnlyProcessingNode_Close(t *testing.T) { } func TestTestOnlyProcessingNode_Getters(t *testing.T) { - if runtime.GOARCH == "arm64" { - t.Skip("skipping test on arm64") + if testing.Short() { + t.Skip("this is not a short test") } node := &testOnlyProcessingNode{} diff --git a/process/factory/shard/vmContainerFactory_test.go b/process/factory/shard/vmContainerFactory_test.go index ac0a2dd6608..a6d7184bd77 100644 --- a/process/factory/shard/vmContainerFactory_test.go +++ b/process/factory/shard/vmContainerFactory_test.go @@ -129,8 +129,6 @@ func TestNewVMContainerFactory_NilBlockChainHookShouldErr(t *testing.T) { } func TestNewVMContainerFactory_NilHasherShouldErr(t *testing.T) { - t.Parallel() - args := createMockVMAccountsArguments() args.Hasher = nil vmf, err := NewVMContainerFactory(args) @@ -140,7 +138,9 @@ func TestNewVMContainerFactory_NilHasherShouldErr(t *testing.T) { } func TestNewVMContainerFactory_OkValues(t *testing.T) { - t.Parallel() + if runtime.GOARCH == "arm64" { + t.Skip("skipping test on arm64") + } args := createMockVMAccountsArguments() vmf, err := NewVMContainerFactory(args) @@ -155,8 +155,6 @@ func TestVmContainerFactory_Create(t *testing.T) { t.Skip("skipping test on arm64") } - t.Parallel() - args := createMockVMAccountsArguments() vmf, _ := NewVMContainerFactory(args) require.NotNil(t, vmf) From f484a82901c7798e67283932a3933a8e354ef514 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Thu, 14 Mar 2024 20:22:54 +0200 Subject: [PATCH 110/503] - fixed some tests --- integrationTests/vm/staking/stakingV4_test.go | 79 +++++++++++-------- .../testMetaProcessorWithCustomNodesConfig.go | 55 +++++++++++++ 2 files changed, 102 insertions(+), 32 deletions(-) diff --git a/integrationTests/vm/staking/stakingV4_test.go b/integrationTests/vm/staking/stakingV4_test.go index 45cc1bcd85e..be77eb44036 100644 --- a/integrationTests/vm/staking/stakingV4_test.go +++ b/integrationTests/vm/staking/stakingV4_test.go @@ -216,9 +216,15 @@ func TestStakingV4(t *testing.T) { require.Len(t, getAllPubKeys(nodesConfigStakingV4Step1.waiting), totalWaiting) require.Empty(t, nodesConfigStakingV4Step1.queue) require.Empty(t, nodesConfigStakingV4Step1.shuffledOut) + // the queue should be empty + requireSameSliceDifferentOrder(t, make([][]byte, 0), nodesConfigStakingV4Step1.auction) + + // 3. re-stake the node nodes that were in the queue + node.ProcessReStake(t, initialNodes.queue) + nodesConfigStakingV4Step1 = node.NodesConfig requireSameSliceDifferentOrder(t, initialNodes.queue, nodesConfigStakingV4Step1.auction) - // 3. Check config after first staking v4 epoch, WITHOUT distribution from auction -> waiting + // 4. Check config after first staking v4 epoch, WITHOUT distribution from auction -> waiting node.Process(t, 6) nodesConfigStakingV4Step2 := node.NodesConfig require.Len(t, getAllPubKeys(nodesConfigStakingV4Step2.eligible), totalEligible) // 1600 @@ -323,7 +329,7 @@ func TestStakingV4_UnStakeNodesWithNotEnoughFunds(t *testing.T) { pubKeys := generateAddresses(0, 20) // Owner1 has 8 nodes, but enough stake for just 7 nodes. At the end of the epoch(staking v4 init), - // the last node from staking queue should be unStaked + // all node from the queue should be unstaked owner1 := "owner1" owner1Stats := &OwnerStats{ EligibleBlsKeys: map[uint32][][]byte{ @@ -431,18 +437,25 @@ func TestStakingV4_UnStakeNodesWithNotEnoughFunds(t *testing.T) { // Owner1 will have the second node from queue removed, before adding all the nodes to auction list queue = remove(queue, owner1StakingQueue[1]) require.Empty(t, currNodesConfig.queue) - require.Len(t, currNodesConfig.auction, 4) - requireSameSliceDifferentOrder(t, currNodesConfig.auction, queue) + // all nodes from the queue should be unstaked and the auction list should be empty + requireSameSliceDifferentOrder(t, currNodesConfig.auction, make([][]byte, 0)) // Owner2 will have one of the nodes in waiting list removed require.Len(t, getAllPubKeys(currNodesConfig.leaving), 1) requireSliceContainsNumOfElements(t, getAllPubKeys(currNodesConfig.leaving), getAllPubKeys(owner2Stats.WaitingBlsKeys), 1) - // Owner1 will unStake some EGLD => at the end of next epoch, he should have the other node from queue(now auction list) removed + // Owner1 will unStake some EGLD => at the end of next epoch, he should not be able to restake all the nodes unStake(t, []byte(owner1), node.AccountsAdapter, node.Marshaller, big.NewInt(0.1*nodePrice)) - // 3. Check config in epoch = staking v4 - node.Process(t, 5) + // 3. re-stake the nodes that were in the queue + queue = remove(queue, owner1StakingQueue[0]) + node.ProcessReStake(t, queue) + currNodesConfig = node.NodesConfig + require.Len(t, currNodesConfig.auction, 3) + requireSameSliceDifferentOrder(t, currNodesConfig.auction, queue) + + // 4. Check config in epoch = staking v4 + node.Process(t, 4) currNodesConfig = node.NodesConfig require.Len(t, getAllPubKeys(currNodesConfig.eligible), 6) require.Len(t, getAllPubKeys(currNodesConfig.waiting), 3) @@ -455,19 +468,16 @@ func TestStakingV4_UnStakeNodesWithNotEnoughFunds(t *testing.T) { require.Len(t, currNodesConfig.waiting[0], 2) require.Len(t, currNodesConfig.shuffledOut[0], 1) - // Owner1 will have the last node from auction list removed - queue = remove(queue, owner1StakingQueue[0]) require.Len(t, currNodesConfig.auction, 3) requireSameSliceDifferentOrder(t, currNodesConfig.auction, queue) - require.Len(t, getAllPubKeys(currNodesConfig.leaving), 1) - require.Equal(t, getAllPubKeys(currNodesConfig.leaving)[0], owner1StakingQueue[0]) + require.Len(t, getAllPubKeys(currNodesConfig.leaving), 0) // Owner3 will unStake EGLD => he will have negative top-up at the selection time => one of his nodes will be unStaked. // His other node should not have been selected => remains in auction. // Meanwhile, owner4 had never unStaked EGLD => his node from auction list will be distributed to waiting unStake(t, []byte(owner3), node.AccountsAdapter, node.Marshaller, big.NewInt(2*nodePrice)) - // 4. Check config in epoch = staking v4 step3 + // 5. Check config in epoch = staking v4 step3 node.Process(t, 5) currNodesConfig = node.NodesConfig requireSliceContainsNumOfElements(t, getAllPubKeys(currNodesConfig.leaving), owner3StakingQueue, 1) @@ -584,8 +594,9 @@ func TestStakingV4_StakeNewNodes(t *testing.T) { queue = append(queue, newNodes1[newOwner1].BLSKeys...) require.Empty(t, currNodesConfig.queue) require.Empty(t, currNodesConfig.leaving) - require.Len(t, currNodesConfig.auction, 5) - requireSameSliceDifferentOrder(t, currNodesConfig.auction, queue) + require.Len(t, currNodesConfig.auction, 1) // queue nodes were not automatically moved to auction, they were unstaked + auction := [][]byte{newNodes1[newOwner1].BLSKeys[0]} + requireSameSliceDifferentOrder(t, currNodesConfig.auction, auction) // NewOwner2 stakes 2 node with top up = 2*node price; should be sent to auction list newOwner2 := "newOwner2" @@ -599,9 +610,9 @@ func TestStakingV4_StakeNewNodes(t *testing.T) { node.Process(t, 4) node.ProcessStake(t, newNodes2) currNodesConfig = node.NodesConfig - queue = append(queue, newNodes2[newOwner2].BLSKeys...) + auction = append(auction, newNodes2[newOwner2].BLSKeys...) require.Empty(t, currNodesConfig.queue) - requireSliceContainsNumOfElements(t, currNodesConfig.auction, queue, 7) + requireSliceContainsNumOfElements(t, currNodesConfig.auction, auction, 3) // 3. Epoch = staking v4 step3 // Only the new 2 owners + owner3 had enough top up to be distributed to waiting. @@ -611,9 +622,6 @@ func TestStakingV4_StakeNewNodes(t *testing.T) { require.Empty(t, currNodesConfig.queue) requireMapContains(t, currNodesConfig.waiting, newNodes1[newOwner1].BLSKeys) requireMapContains(t, currNodesConfig.waiting, newNodes2[newOwner2].BLSKeys) - requireMapContains(t, currNodesConfig.waiting, owner3StakingQueue) - requireSliceContains(t, currNodesConfig.auction, owner1StakingQueue) - requireSliceContains(t, currNodesConfig.auction, newNodes0[newOwner0].BLSKeys) } func TestStakingV4_UnStakeNodes(t *testing.T) { @@ -726,11 +734,16 @@ func TestStakingV4_UnStakeNodes(t *testing.T) { // Owner2's node from waiting list which was unStaked in previous epoch is now leaving require.Len(t, currNodesConfig.leaving, 1) require.Equal(t, owner2Stats.WaitingBlsKeys[core.MetachainShardId][0], currNodesConfig.leaving[core.MetachainShardId][0]) - require.Len(t, currNodesConfig.auction, 5) - // All nodes from queue have been moved to auction + require.Len(t, currNodesConfig.auction, 0) // no nodes from queue were moved to auction list + // All nodes from queue have been unstaked, the auction list is empty + requireSameSliceDifferentOrder(t, make([][]byte, 0), currNodesConfig.auction) + + // 2.1 restake the nodes that were on the queue + node.ProcessReStake(t, queue) + currNodesConfig = node.NodesConfig requireSameSliceDifferentOrder(t, queue, currNodesConfig.auction) - // 2.1 Owner3 unStakes one of his nodes from auction + // 2.2 Owner3 unStakes one of his nodes from auction node.ProcessUnStake(t, map[string][][]byte{ owner3: {owner3StakingQueue[1]}, }) @@ -743,7 +756,7 @@ func TestStakingV4_UnStakeNodes(t *testing.T) { require.Empty(t, currNodesConfig.queue) require.Empty(t, currNodesConfig.new) - // 2.2 Owner1 unStakes 2 nodes: one from auction + one active + // 2.3 Owner1 unStakes 2 nodes: one from auction + one active node.ProcessUnStake(t, map[string][][]byte{ owner1: {owner1StakingQueue[1], owner1Stats.WaitingBlsKeys[0][0]}, }) @@ -908,23 +921,23 @@ func TestStakingV4_JailAndUnJailNodes(t *testing.T) { currNodesConfig = node.NodesConfig requireMapContains(t, currNodesConfig.leaving, jailedNodes) requireMapContains(t, currNodesConfig.waiting, unJailedNodes) - requireSameSliceDifferentOrder(t, currNodesConfig.auction, queue) + requireSameSliceDifferentOrder(t, currNodesConfig.auction, make([][]byte, 0)) require.Len(t, getAllPubKeys(currNodesConfig.eligible), 4) require.Len(t, getAllPubKeys(currNodesConfig.waiting), 4) require.Empty(t, currNodesConfig.queue) - // 2.1 Epoch = stakingV4Step1; unJail one of the jailed nodes and expect it is sent to auction - node.ProcessUnJail(t, jailedNodes[:1]) + // 2.1 re-stake the nodes that were in the queue + // but first, we need to unjail the nodes + node.ProcessUnJail(t, jailedNodes) + node.ProcessReStake(t, queue) currNodesConfig = node.NodesConfig - queue = append(queue, jailedNodes[0]) + queue = append(queue, jailedNodes...) require.Empty(t, currNodesConfig.queue) requireSameSliceDifferentOrder(t, currNodesConfig.auction, queue) - // 3. Epoch = stakingV4Step2; unJail the other jailed node and expect it is sent to auction - node.Process(t, 4) - node.ProcessUnJail(t, jailedNodes[1:]) + // 3. Epoch = stakingV4Step2 + node.Process(t, 2) currNodesConfig = node.NodesConfig - queue = append(queue, jailedNodes[1]) queue = append(queue, getAllPubKeys(currNodesConfig.shuffledOut)...) require.Empty(t, currNodesConfig.queue) requireSameSliceDifferentOrder(t, currNodesConfig.auction, queue) @@ -933,9 +946,11 @@ func TestStakingV4_JailAndUnJailNodes(t *testing.T) { newJailed := getAllPubKeys(currNodesConfig.waiting)[:1] node.ProcessJail(t, newJailed) + // TODO fix the test below this point + return // 4. Epoch = stakingV4Step3; // 4.1 Expect jailed node from waiting list is now leaving - node.Process(t, 4) + node.Process(t, 5) currNodesConfig = node.NodesConfig requireMapContains(t, currNodesConfig.leaving, newJailed) requireSliceContainsNumOfElements(t, currNodesConfig.auction, newJailed, 0) diff --git a/integrationTests/vm/staking/testMetaProcessorWithCustomNodesConfig.go b/integrationTests/vm/staking/testMetaProcessorWithCustomNodesConfig.go index a966a499454..841a2b77b43 100644 --- a/integrationTests/vm/staking/testMetaProcessorWithCustomNodesConfig.go +++ b/integrationTests/vm/staking/testMetaProcessorWithCustomNodesConfig.go @@ -124,6 +124,60 @@ func (tmp *TestMetaProcessor) doStake( return tmp.runSC(t, arguments) } +// ProcessReStake will create a block containing mini blocks with re-staking txs using provided nodes. +// Block will be committed + call to validator system sc will be made to stake all nodes +func (tmp *TestMetaProcessor) ProcessReStake(t *testing.T, blsKeys [][]byte) { + header := tmp.createNewHeader(t, tmp.currentRound) + tmp.BlockChainHook.SetCurrentHeader(header) + + txHashes := make([][]byte, 0) + for _, blsKey := range blsKeys { + scrs := tmp.doReStake(t, blsKey) + txHashes = append(txHashes, tmp.addTxsToCacher(scrs)...) + } + + tmp.commitBlockTxs(t, txHashes, header) +} + +func (tmp *TestMetaProcessor) doReStake( + t *testing.T, + blsKey []byte, +) map[string]*smartContractResult.SmartContractResult { + owner := tmp.getOwnerOfBLSKey(t, blsKey) + + arguments := &vmcommon.ContractCallInput{ + VMInput: vmcommon.VMInput{ + CallerAddr: owner, + Arguments: [][]byte{blsKey}, + CallValue: big.NewInt(0), + GasProvided: 10, + }, + RecipientAddr: vm.ValidatorSCAddress, + Function: "reStakeUnStakedNodes", + } + + return tmp.runSC(t, arguments) +} + +func (tmp *TestMetaProcessor) getOwnerOfBLSKey(t *testing.T, blsKey []byte) []byte { + arguments := &vmcommon.ContractCallInput{ + VMInput: vmcommon.VMInput{ + CallerAddr: vm.ValidatorSCAddress, + Arguments: [][]byte{blsKey}, + CallValue: big.NewInt(0), + GasProvided: 10, + }, + RecipientAddr: vm.StakingSCAddress, + Function: "getOwner", + } + + vmOutput, err := tmp.SystemVM.RunSmartContractCall(arguments) + require.Nil(t, err) + require.Equal(t, vmcommon.Ok, vmOutput.ReturnCode) + + return vmOutput.ReturnData[0] +} + func createStakeArgs(blsKeys [][]byte) [][]byte { numBLSKeys := int64(len(blsKeys)) numBLSKeysBytes := big.NewInt(numBLSKeys).Bytes() @@ -215,6 +269,7 @@ func (tmp *TestMetaProcessor) ProcessUnJail(t *testing.T, blsKeys [][]byte) { tmp.commitBlockTxs(t, txHashes, header) } +// ClearStoredMbs clears the stored miniblocks func (tmp *TestMetaProcessor) ClearStoredMbs() { txCoordMock, _ := tmp.TxCoordinator.(*testscommon.TransactionCoordinatorMock) txCoordMock.ClearStoredMbs() From 273c826ee2ea08d8e9dd4355138d032a8815eb03 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Fri, 15 Mar 2024 12:15:34 +0200 Subject: [PATCH 111/503] - fixed chain simulator's seldom failing tests --- node/chainSimulator/configs/configs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/chainSimulator/configs/configs.go b/node/chainSimulator/configs/configs.go index c354791d248..fda5351e154 100644 --- a/node/chainSimulator/configs/configs.go +++ b/node/chainSimulator/configs/configs.go @@ -92,7 +92,7 @@ func CreateChainSimulatorConfigs(args ArgsChainSimulatorConfigs) (*ArgsConfigsSi return nil, err } - configs.ConfigurationPathsHolder.AllValidatorKeys = path.Join(args.OriginalConfigsPath, allValidatorsPemFileName) + configs.ConfigurationPathsHolder.AllValidatorKeys = path.Join(args.TempDir, allValidatorsPemFileName) err = generateValidatorsPem(configs.ConfigurationPathsHolder.AllValidatorKeys, publicKeys, privateKeys) if err != nil { return nil, err From f94623c5253e4e12976f5cbfd7342f1c5be6b4a7 Mon Sep 17 00:00:00 2001 From: MariusC Date: Fri, 15 Mar 2024 13:54:46 +0200 Subject: [PATCH 112/503] FIX: Unit test --- integrationTests/vm/staking/stakingV4_test.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/integrationTests/vm/staking/stakingV4_test.go b/integrationTests/vm/staking/stakingV4_test.go index be77eb44036..6f48fce66a5 100644 --- a/integrationTests/vm/staking/stakingV4_test.go +++ b/integrationTests/vm/staking/stakingV4_test.go @@ -936,7 +936,7 @@ func TestStakingV4_JailAndUnJailNodes(t *testing.T) { requireSameSliceDifferentOrder(t, currNodesConfig.auction, queue) // 3. Epoch = stakingV4Step2 - node.Process(t, 2) + node.Process(t, 1) currNodesConfig = node.NodesConfig queue = append(queue, getAllPubKeys(currNodesConfig.shuffledOut)...) require.Empty(t, currNodesConfig.queue) @@ -946,11 +946,9 @@ func TestStakingV4_JailAndUnJailNodes(t *testing.T) { newJailed := getAllPubKeys(currNodesConfig.waiting)[:1] node.ProcessJail(t, newJailed) - // TODO fix the test below this point - return // 4. Epoch = stakingV4Step3; // 4.1 Expect jailed node from waiting list is now leaving - node.Process(t, 5) + node.Process(t, 4) currNodesConfig = node.NodesConfig requireMapContains(t, currNodesConfig.leaving, newJailed) requireSliceContainsNumOfElements(t, currNodesConfig.auction, newJailed, 0) @@ -963,7 +961,7 @@ func TestStakingV4_JailAndUnJailNodes(t *testing.T) { require.Empty(t, currNodesConfig.queue) // 5. Epoch is now after whole staking v4 chain is activated - node.Process(t, 4) + node.Process(t, 3) currNodesConfig = node.NodesConfig queue = currNodesConfig.auction newJailed = queue[:1] From d790058ab5638c99cb6d961c7bb7f93edb93afbc Mon Sep 17 00:00:00 2001 From: MariusC Date: Fri, 15 Mar 2024 14:14:02 +0200 Subject: [PATCH 113/503] FIX: Tests --- integrationTests/vm/staking/stakingV4_test.go | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/integrationTests/vm/staking/stakingV4_test.go b/integrationTests/vm/staking/stakingV4_test.go index 6f48fce66a5..e3f8af89edd 100644 --- a/integrationTests/vm/staking/stakingV4_test.go +++ b/integrationTests/vm/staking/stakingV4_test.go @@ -216,8 +216,7 @@ func TestStakingV4(t *testing.T) { require.Len(t, getAllPubKeys(nodesConfigStakingV4Step1.waiting), totalWaiting) require.Empty(t, nodesConfigStakingV4Step1.queue) require.Empty(t, nodesConfigStakingV4Step1.shuffledOut) - // the queue should be empty - requireSameSliceDifferentOrder(t, make([][]byte, 0), nodesConfigStakingV4Step1.auction) + require.Empty(t, nodesConfigStakingV4Step1.auction) // the queue should be empty // 3. re-stake the node nodes that were in the queue node.ProcessReStake(t, initialNodes.queue) @@ -329,7 +328,7 @@ func TestStakingV4_UnStakeNodesWithNotEnoughFunds(t *testing.T) { pubKeys := generateAddresses(0, 20) // Owner1 has 8 nodes, but enough stake for just 7 nodes. At the end of the epoch(staking v4 init), - // all node from the queue should be unstaked + // his last node from staking queue should be unStaked owner1 := "owner1" owner1Stats := &OwnerStats{ EligibleBlsKeys: map[uint32][][]byte{ @@ -437,14 +436,13 @@ func TestStakingV4_UnStakeNodesWithNotEnoughFunds(t *testing.T) { // Owner1 will have the second node from queue removed, before adding all the nodes to auction list queue = remove(queue, owner1StakingQueue[1]) require.Empty(t, currNodesConfig.queue) - // all nodes from the queue should be unstaked and the auction list should be empty - requireSameSliceDifferentOrder(t, currNodesConfig.auction, make([][]byte, 0)) + require.Empty(t, currNodesConfig.auction) // all nodes from the queue should be unStaked and the auction list should be empty // Owner2 will have one of the nodes in waiting list removed require.Len(t, getAllPubKeys(currNodesConfig.leaving), 1) requireSliceContainsNumOfElements(t, getAllPubKeys(currNodesConfig.leaving), getAllPubKeys(owner2Stats.WaitingBlsKeys), 1) - // Owner1 will unStake some EGLD => at the end of next epoch, he should not be able to restake all the nodes + // Owner1 will unStake some EGLD => at the end of next epoch, he should not be able to reStake all the nodes unStake(t, []byte(owner1), node.AccountsAdapter, node.Marshaller, big.NewInt(0.1*nodePrice)) // 3. re-stake the nodes that were in the queue @@ -590,13 +588,13 @@ func TestStakingV4_StakeNewNodes(t *testing.T) { // 2. Check config after staking v4 init when a new node is staked node.Process(t, 4) node.ProcessStake(t, newNodes1) + node.ProcessReStake(t, queue) currNodesConfig = node.NodesConfig queue = append(queue, newNodes1[newOwner1].BLSKeys...) require.Empty(t, currNodesConfig.queue) require.Empty(t, currNodesConfig.leaving) - require.Len(t, currNodesConfig.auction, 1) // queue nodes were not automatically moved to auction, they were unstaked - auction := [][]byte{newNodes1[newOwner1].BLSKeys[0]} - requireSameSliceDifferentOrder(t, currNodesConfig.auction, auction) + require.Len(t, currNodesConfig.auction, 5) + requireSameSliceDifferentOrder(t, currNodesConfig.auction, queue) // NewOwner2 stakes 2 node with top up = 2*node price; should be sent to auction list newOwner2 := "newOwner2" @@ -610,9 +608,9 @@ func TestStakingV4_StakeNewNodes(t *testing.T) { node.Process(t, 4) node.ProcessStake(t, newNodes2) currNodesConfig = node.NodesConfig - auction = append(auction, newNodes2[newOwner2].BLSKeys...) + queue = append(queue, newNodes2[newOwner2].BLSKeys...) require.Empty(t, currNodesConfig.queue) - requireSliceContainsNumOfElements(t, currNodesConfig.auction, auction, 3) + requireSliceContainsNumOfElements(t, currNodesConfig.auction, queue, 7) // 3. Epoch = staking v4 step3 // Only the new 2 owners + owner3 had enough top up to be distributed to waiting. @@ -622,6 +620,9 @@ func TestStakingV4_StakeNewNodes(t *testing.T) { require.Empty(t, currNodesConfig.queue) requireMapContains(t, currNodesConfig.waiting, newNodes1[newOwner1].BLSKeys) requireMapContains(t, currNodesConfig.waiting, newNodes2[newOwner2].BLSKeys) + requireMapContains(t, currNodesConfig.waiting, owner3StakingQueue) + requireSliceContains(t, currNodesConfig.auction, owner1StakingQueue) + requireSliceContains(t, currNodesConfig.auction, newNodes0[newOwner0].BLSKeys) } func TestStakingV4_UnStakeNodes(t *testing.T) { From b5e8ac8d1246337e49adc1de155abcccf128eb1c Mon Sep 17 00:00:00 2001 From: MariusC Date: Fri, 15 Mar 2024 14:37:36 +0200 Subject: [PATCH 114/503] FIX: Tests --- integrationTests/vm/staking/stakingV4_test.go | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/integrationTests/vm/staking/stakingV4_test.go b/integrationTests/vm/staking/stakingV4_test.go index e3f8af89edd..0d7a67e0053 100644 --- a/integrationTests/vm/staking/stakingV4_test.go +++ b/integrationTests/vm/staking/stakingV4_test.go @@ -99,6 +99,18 @@ func getIntersection(slice1, slice2 [][]byte) [][]byte { return ret } +func getAllPubKeysFromConfig(nodesCfg nodesConfig) [][]byte { + allPubKeys := getAllPubKeys(nodesCfg.eligible) + allPubKeys = append(allPubKeys, getAllPubKeys(nodesCfg.waiting)...) + allPubKeys = append(allPubKeys, getAllPubKeys(nodesCfg.leaving)...) + allPubKeys = append(allPubKeys, getAllPubKeys(nodesCfg.shuffledOut)...) + allPubKeys = append(allPubKeys, nodesCfg.queue...) + allPubKeys = append(allPubKeys, nodesCfg.auction...) + allPubKeys = append(allPubKeys, nodesCfg.new...) + + return allPubKeys +} + func unStake(t *testing.T, owner []byte, accountsDB state.AccountsAdapter, marshaller marshal.Marshalizer, stake *big.Int) { validatorSC := stakingcommon.LoadUserAccount(accountsDB, vm.ValidatorSCAddress) ownerStoredData, _, err := validatorSC.RetrieveValue(owner) @@ -445,7 +457,7 @@ func TestStakingV4_UnStakeNodesWithNotEnoughFunds(t *testing.T) { // Owner1 will unStake some EGLD => at the end of next epoch, he should not be able to reStake all the nodes unStake(t, []byte(owner1), node.AccountsAdapter, node.Marshaller, big.NewInt(0.1*nodePrice)) - // 3. re-stake the nodes that were in the queue + // 3. ReStake the nodes that were in the queue queue = remove(queue, owner1StakingQueue[0]) node.ProcessReStake(t, queue) currNodesConfig = node.NodesConfig @@ -469,6 +481,8 @@ func TestStakingV4_UnStakeNodesWithNotEnoughFunds(t *testing.T) { require.Len(t, currNodesConfig.auction, 3) requireSameSliceDifferentOrder(t, currNodesConfig.auction, queue) require.Len(t, getAllPubKeys(currNodesConfig.leaving), 0) + // There are no more unStaked nodes left from owner1 because of insufficient funds + requireSliceContainsNumOfElements(t, getAllPubKeysFromConfig(currNodesConfig), owner1StakingQueue, 0) // Owner3 will unStake EGLD => he will have negative top-up at the selection time => one of his nodes will be unStaked. // His other node should not have been selected => remains in auction. @@ -735,9 +749,7 @@ func TestStakingV4_UnStakeNodes(t *testing.T) { // Owner2's node from waiting list which was unStaked in previous epoch is now leaving require.Len(t, currNodesConfig.leaving, 1) require.Equal(t, owner2Stats.WaitingBlsKeys[core.MetachainShardId][0], currNodesConfig.leaving[core.MetachainShardId][0]) - require.Len(t, currNodesConfig.auction, 0) // no nodes from queue were moved to auction list - // All nodes from queue have been unstaked, the auction list is empty - requireSameSliceDifferentOrder(t, make([][]byte, 0), currNodesConfig.auction) + require.Empty(t, currNodesConfig.auction) // all nodes from queue have been unStaked, the auction list is empty // 2.1 restake the nodes that were on the queue node.ProcessReStake(t, queue) @@ -927,8 +939,8 @@ func TestStakingV4_JailAndUnJailNodes(t *testing.T) { require.Len(t, getAllPubKeys(currNodesConfig.waiting), 4) require.Empty(t, currNodesConfig.queue) - // 2.1 re-stake the nodes that were in the queue - // but first, we need to unjail the nodes + // 2.1 ReStake the nodes that were in the queue + // but first, we need to unJail the nodes node.ProcessUnJail(t, jailedNodes) node.ProcessReStake(t, queue) currNodesConfig = node.NodesConfig @@ -1490,9 +1502,7 @@ func TestStakingV4_LeavingNodesEdgeCases(t *testing.T) { // Fast-forward multiple epochs and check that newOwner1's forced nodes from previous epochs left node.Process(t, 20) currNodesConfig = node.NodesConfig - allCurrentNodesInSystem := append(getAllPubKeys(currNodesConfig.eligible), getAllPubKeys(currNodesConfig.waiting)...) - allCurrentNodesInSystem = append(allCurrentNodesInSystem, getAllPubKeys(currNodesConfig.leaving)...) - allCurrentNodesInSystem = append(allCurrentNodesInSystem, currNodesConfig.auction...) + allCurrentNodesInSystem := getAllPubKeysFromConfig(currNodesConfig) owner1LeftNodes := getIntersection(owner1NodesThatAreStillForcedToRemain, allCurrentNodesInSystem) require.Zero(t, len(owner1LeftNodes)) } From 092ef5505ff27d0b3091981a07de45db1c7f3a95 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 15 Mar 2024 17:20:13 +0200 Subject: [PATCH 115/503] removed hardcoded ips and added dedicated network for docker local-testnet. --- scripts/docker-testnet/clean.sh | 3 ++ scripts/docker-testnet/functions.sh | 66 ++++++++++++++++++++--------- scripts/docker-testnet/start.sh | 3 ++ scripts/docker-testnet/variables.sh | 16 +++++-- 4 files changed, 63 insertions(+), 25 deletions(-) mode change 100644 => 100755 scripts/docker-testnet/variables.sh diff --git a/scripts/docker-testnet/clean.sh b/scripts/docker-testnet/clean.sh index a872ed57f13..b0dd59a6961 100755 --- a/scripts/docker-testnet/clean.sh +++ b/scripts/docker-testnet/clean.sh @@ -12,5 +12,8 @@ docker stop $(docker ps -a -q) echo "Removing all containers..." docker container prune -f +echo "Removing network..." +docker network rm ${DOCKER_NETWORK_NAME} + echo "Removing $TESTNETDIR..." rm -rf $TESTNETDIR diff --git a/scripts/docker-testnet/functions.sh b/scripts/docker-testnet/functions.sh index 601707218ef..3a6be5003a8 100755 --- a/scripts/docker-testnet/functions.sh +++ b/scripts/docker-testnet/functions.sh @@ -1,6 +1,9 @@ #!/usr/bin/env bash -IP_BIT=3 +# Starts from 3, if the DOCKER_NETWORK_SUBNET ends with a 0. The first IP address is reserved for the gateway and the +# second one is allocated to the seednode. Therefore the counting starts from 3. If you modify the DOCKER_NETWORK_SUBNET +# variable, make sure to change this one accordingly too. +IP_HOST_BYTE=3 cloneRepositories() { if [[ -n $CI_RUN ]]; then @@ -13,8 +16,18 @@ cloneRepositories() { fi } +createDockerNetwork() { + docker network create -d bridge --subnet=${DOCKER_NETWORK_SUBNET} ${DOCKER_NETWORK_NAME} + + # this variable is used to keep track of the allocated IP addresses in the network, by removing the last byte + # of the DOCKER_NETWORK_SUBNET. One can consider this the host network address without the last byte at the end. + export NETWORK_ADDRESS=$(echo "$DOCKER_NETWORK_SUBNET" | rev | cut -d. -f2- | rev) +} + startSeedNode() { - docker run -d --name seednode -v ${TESTNETDIR}/seednode/config:/go/mx-chain-go/cmd/seednode/config seednode:dev \ + docker run -d --name seednode -v ${TESTNETDIR}/seednode/config:/go/mx-chain-go/cmd/seednode/config \ + --network ${DOCKER_NETWORK_NAME} \ + seednode:dev \ --rest-api-interface=0.0.0.0:10000 } @@ -26,8 +39,9 @@ startObservers() { # Your commands or code to be executed in each iteration KEY_INDEX=$((TOTAL_NODECOUNT - observerIdx - 1)) - docker run -d --name "observer${observerIdx}-172.17.0.${IP_BIT}-10200-shard${i}" \ + docker run -d --name "observer${observerIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-shard${i}" \ -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ + --network ${DOCKER_NETWORK_NAME} \ node:dev \ --destination-shard-as-observer $i \ --rest-api-interface=0.0.0.0:10200 \ @@ -36,7 +50,7 @@ startObservers() { $EXTRA_OBSERVERS_FLAGS - (( IP_BIT++ )) + (( IP_HOST_BYTE++ )) ((observerIdx++)) || true done done @@ -44,8 +58,9 @@ startObservers() { for ((i = 0; i < META_OBSERVERCOUNT; i++)); do KEY_INDEX=$((TOTAL_NODECOUNT - observerIdx - 1)) - docker run -d --name "observer${observerIdx}-172.17.0.${IP_BIT}-10200-metachain" \ + docker run -d --name "observer${observerIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-metachain" \ -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ + --network ${DOCKER_NETWORK_NAME} \ node:dev \ --destination-shard-as-observer "metachain" \ --rest-api-interface=0.0.0.0:10200 \ @@ -53,7 +68,7 @@ startObservers() { --sk-index=${KEY_INDEX} \ $EXTRA_OBSERVERS_FLAGS - (( IP_BIT++ )) + (( IP_HOST_BYTE++ )) ((observerIdx++)) || true done } @@ -64,27 +79,29 @@ startValidators() { for ((i = 0; i < SHARDCOUNT; i++)); do for ((j = 0; j < SHARD_VALIDATORCOUNT; j++)); do - docker run -d --name "validator${validatorIdx}-172.17.0.${IP_BIT}-10200-shard${i}" \ + docker run -d --name "validator${validatorIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-shard${i}" \ -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ + --network ${DOCKER_NETWORK_NAME} \ node:dev \ --rest-api-interface=0.0.0.0:10200 \ --config ./config/config_validator.toml \ --sk-index=${validatorIdx} \ - (( IP_BIT++ )) + (( IP_HOST_BYTE++ )) ((validatorIdx++)) || true done done for ((i = 0; i < META_VALIDATORCOUNT; i++)); do - docker run -d --name "validator${validatorIdx}-172.17.0.${IP_BIT}-10200-metachain" \ + docker run -d --name "validator${validatorIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-metachain" \ -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ + --network ${DOCKER_NETWORK_NAME} \ node:dev \ --rest-api-interface=0.0.0.0:10200 \ --config ./config/config_observer.toml \ --sk-index=${validatorIdx} \ - (( IP_BIT++ )) + (( IP_HOST_BYTE++ )) ((validatorIdx++)) || true done } @@ -109,7 +126,7 @@ updateProxyConfigDocker() { } generateProxyObserverListDocker() { - local ipBit=3 + local ipByte=3 OUTPUTFILE=$! @@ -118,25 +135,25 @@ generateProxyObserverListDocker() { echo "[[Observers]]" >> config_edit.toml echo " ShardId = $i" >> config_edit.toml - echo " Address = \"http://172.17.0.${ipBit}:10200\"" >> config_edit.toml + echo " Address = \"http://${NETWORK_ADDRESS}.${ipByte}:10200\"" >> config_edit.toml echo ""$'\n' >> config_edit.toml - (( ipBit++ )) || true + (( ipByte++ )) || true done done for META_OBSERVER in $(seq $META_OBSERVERCOUNT); do echo "[[Observers]]" >> config_edit.toml echo " ShardId = $METASHARD_ID" >> config_edit.toml - echo " Address = \"http://172.17.0.${ipBit}:10200\"" >> config_edit.toml + echo " Address = \"http://${NETWORK_ADDRESS}.${ipByte}:10200\"" >> config_edit.toml echo ""$'\n' >> config_edit.toml - (( ipBit++ )) || true + (( ipByte++ )) || true done } generateProxyValidatorListDocker() { - local ipBit=3 + local ipByte=3 OUTPUTFILE=$! @@ -145,28 +162,35 @@ generateProxyValidatorListDocker() { echo "[[Observers]]" >> config_edit.toml echo " ShardId = $i" >> config_edit.toml - echo " Address = \"http://172.17.0.${ipBit}:10200\"" >> config_edit.toml + echo " Address = \"http://${NETWORK_ADDRESS}.${ipByte}:10200\"" >> config_edit.toml echo " Type = \"Validator\"" >> config_edit.toml echo ""$'\n' >> config_edit.toml - (( ipBit++ )) || true + (( ipByte++ )) || true done done for META_OBSERVER in $(seq $META_VALIDATORCOUNT); do echo "[[Observers]]" >> config_edit.toml echo " ShardId = $METASHARD_ID" >> config_edit.toml - echo " Address = \"http://172.17.0.${ipBit}:10200\"" >> config_edit.toml + echo " Address = \"http://${NETWORK_ADDRESS}.${ipByte}:10200\"" >> config_edit.toml echo " Type = \"Validator\"" >> config_edit.toml echo ""$'\n' >> config_edit.toml - (( ipBit++ )) || true + (( ipByte++ )) || true done } +buildProxyImage() { + pushd ${PROXYDIR} + cd ../.. + docker build -f docker/Dockerfile . -t proxy:dev +} + startProxyDocker() { docker run -d --name "proxy" \ -p $PORT_PROXY:8080 \ -v $TESTNETDIR/proxy/config:/mx-chain-proxy-go/cmd/proxy/config \ - multiversx/chain-proxy:v1.1.45-sp4 + --network ${DOCKER_NETWORK_NAME} \ + proxy:dev } diff --git a/scripts/docker-testnet/start.sh b/scripts/docker-testnet/start.sh index 02e107c4229..c32d7ac0523 100755 --- a/scripts/docker-testnet/start.sh +++ b/scripts/docker-testnet/start.sh @@ -27,11 +27,14 @@ updateSeednodeConfig copyNodeConfig updateNodeConfig +createDockerNetwork + startSeedNode startObservers startValidators if [ $USE_PROXY -eq 1 ]; then + buildProxyImage prepareFolders_Proxy copyProxyConfig updateProxyConfigDocker diff --git a/scripts/docker-testnet/variables.sh b/scripts/docker-testnet/variables.sh old mode 100644 new mode 100755 index f4afd395c41..69c0e90d195 --- a/scripts/docker-testnet/variables.sh +++ b/scripts/docker-testnet/variables.sh @@ -1,5 +1,14 @@ # These paths must be absolute +######################################################################## +# Docker network configuration + +# Don't change the subnet, unless you know what you are doing. Prone to errors. +export DOCKER_NETWORK_SUBNET="172.18.0.0/24" +export DOCKER_NETWORK_NAME="local-testnet" +######################################################################## + + # METASHARD_ID will be used to identify a shard ID as metachain export METASHARD_ID=4294967295 @@ -92,8 +101,9 @@ export ALWAYS_NEW_APP_VERSION=0 # each time. export ALWAYS_UPDATE_CONFIGS=1 -# IP of the seednode -export SEEDNODE_IP="172.17.0.2" +# IP of the seednode. This should be the first IP allocated in the local testnet network. If you modify the default +# DOCKER_NETWORK_SUBNET, you will need to edit this one accordingly too. +export SEEDNODE_IP="$(echo "$DOCKER_NETWORK_SUBNET" | rev | cut -d. -f2- | rev).2" # Ports used by the Nodes export PORT_SEEDNODE="9999" @@ -135,8 +145,6 @@ export PROXY=$PROXYDIR/proxy # Leave unchanged. export PORT_PROXY="7950" export PROXY_DELAY=10 - - ######################################################################## # TxGen configuration From 01e02fd0d49f7e3ba58972c0435b03fd2a4a48b4 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Fri, 15 Mar 2024 17:20:51 +0200 Subject: [PATCH 116/503] Removed executable permissions for variables.sh --- scripts/docker-testnet/variables.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 scripts/docker-testnet/variables.sh diff --git a/scripts/docker-testnet/variables.sh b/scripts/docker-testnet/variables.sh old mode 100755 new mode 100644 From 24c1ac41b0c374b0ab58a82e9d2e210f2f9a6878 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 18 Mar 2024 10:33:43 +0200 Subject: [PATCH 117/503] fixes after review. --- scripts/docker-testnet/build.sh | 6 ++- scripts/docker-testnet/clean.sh | 14 ++++-- scripts/docker-testnet/functions.sh | 69 +++++++++++++++-------------- scripts/docker-testnet/start.sh | 2 +- scripts/docker-testnet/variables.sh | 46 ++++++++----------- 5 files changed, 69 insertions(+), 68 deletions(-) diff --git a/scripts/docker-testnet/build.sh b/scripts/docker-testnet/build.sh index 605db92580a..5bc11887fce 100755 --- a/scripts/docker-testnet/build.sh +++ b/scripts/docker-testnet/build.sh @@ -1,4 +1,8 @@ -pushd ../.. +#!/usr/bin/env bash + +set -eux + +cd ${MULTIVERSXDIR} docker build -f docker/seednode/Dockerfile . -t seednode:dev diff --git a/scripts/docker-testnet/clean.sh b/scripts/docker-testnet/clean.sh index b0dd59a6961..b8cfe1ea2d7 100755 --- a/scripts/docker-testnet/clean.sh +++ b/scripts/docker-testnet/clean.sh @@ -1,16 +1,22 @@ #!/usr/bin/env bash +set -eux + # Delete the entire testnet folder, which includes configuration, executables and logs. export MULTIVERSXTESTNETSCRIPTSDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" source "$MULTIVERSXTESTNETSCRIPTSDIR/variables.sh" -echo "Stopping all containers..." -docker stop $(docker ps -a -q) +# Get the IDs of containers attached to the network +CONTAINER_IDS=$(docker network inspect -f '{{range .Containers}}{{.Name}} {{end}}' "$DOCKER_NETWORK_NAME") -echo "Removing all containers..." -docker container prune -f +# Stop each container +echo "Removing containers..." +for CONTAINER_ID in $CONTAINER_IDS; do + docker stop "$CONTAINER_ID" + docker rm "$CONTAINER_ID" +done echo "Removing network..." docker network rm ${DOCKER_NETWORK_NAME} diff --git a/scripts/docker-testnet/functions.sh b/scripts/docker-testnet/functions.sh index 3a6be5003a8..0a79c8de751 100755 --- a/scripts/docker-testnet/functions.sh +++ b/scripts/docker-testnet/functions.sh @@ -6,14 +6,18 @@ IP_HOST_BYTE=3 cloneRepositories() { - if [[ -n $CI_RUN ]]; then - echo "Repositories have been cloned in the CI" - else - cd $(dirname $MULTIVERSXDIR) - - git clone git@github.com:multiversx/mx-chain-deploy-go.git || true - git clone git@github.com:multiversx/mx-chain-proxy-go.git || true - fi + cd $(dirname $MULTIVERSXDIR) + + git clone git@github.com:multiversx/mx-chain-deploy-go.git || true + git clone git@github.com:multiversx/mx-chain-proxy-go.git || true +} + +buildNodeImages() { + cd $MULTIVERSXDIR + + docker build -f docker/seednode/Dockerfile . -t seednode:dev + + docker build -f docker/node/Dockerfile . -t node:dev } createDockerNetwork() { @@ -25,10 +29,11 @@ createDockerNetwork() { } startSeedNode() { - docker run -d --name seednode -v ${TESTNETDIR}/seednode/config:/go/mx-chain-go/cmd/seednode/config \ - --network ${DOCKER_NETWORK_NAME} \ - seednode:dev \ - --rest-api-interface=0.0.0.0:10000 + docker run -d --name seednode \ + -v ${TESTNETDIR}/seednode/config:/go/mx-chain-go/cmd/seednode/config \ + --network ${DOCKER_NETWORK_NAME} \ + seednode:dev \ + --rest-api-interface=0.0.0.0:10000 } startObservers() { @@ -40,14 +45,14 @@ startObservers() { KEY_INDEX=$((TOTAL_NODECOUNT - observerIdx - 1)) docker run -d --name "observer${observerIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-shard${i}" \ - -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ - --network ${DOCKER_NETWORK_NAME} \ - node:dev \ - --destination-shard-as-observer $i \ - --rest-api-interface=0.0.0.0:10200 \ - --config ./config/config_observer.toml \ - --sk-index=${KEY_INDEX} \ - $EXTRA_OBSERVERS_FLAGS + -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ + --network ${DOCKER_NETWORK_NAME} \ + node:dev \ + --destination-shard-as-observer $i \ + --rest-api-interface=0.0.0.0:10200 \ + --config ./config/config_observer.toml \ + --sk-index=${KEY_INDEX} \ + $EXTRA_OBSERVERS_FLAGS (( IP_HOST_BYTE++ )) @@ -80,12 +85,12 @@ startValidators() { for ((j = 0; j < SHARD_VALIDATORCOUNT; j++)); do docker run -d --name "validator${validatorIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-shard${i}" \ - -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ - --network ${DOCKER_NETWORK_NAME} \ - node:dev \ - --rest-api-interface=0.0.0.0:10200 \ - --config ./config/config_validator.toml \ - --sk-index=${validatorIdx} \ + -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ + --network ${DOCKER_NETWORK_NAME} \ + node:dev \ + --rest-api-interface=0.0.0.0:10200 \ + --config ./config/config_validator.toml \ + --sk-index=${validatorIdx} \ (( IP_HOST_BYTE++ )) ((validatorIdx++)) || true @@ -127,8 +132,6 @@ updateProxyConfigDocker() { generateProxyObserverListDocker() { local ipByte=3 - OUTPUTFILE=$! - for ((i = 0; i < SHARDCOUNT; i++)); do for ((j = 0; j < SHARD_OBSERVERCOUNT; j++)); do @@ -154,8 +157,6 @@ generateProxyObserverListDocker() { generateProxyValidatorListDocker() { local ipByte=3 - OUTPUTFILE=$! - for ((i = 0; i < SHARDCOUNT; i++)); do for ((j = 0; j < SHARD_VALIDATORCOUNT; j++)); do @@ -189,8 +190,8 @@ buildProxyImage() { startProxyDocker() { docker run -d --name "proxy" \ - -p $PORT_PROXY:8080 \ - -v $TESTNETDIR/proxy/config:/mx-chain-proxy-go/cmd/proxy/config \ - --network ${DOCKER_NETWORK_NAME} \ - proxy:dev + -v $TESTNETDIR/proxy/config:/mx-chain-proxy-go/cmd/proxy/config \ + --network ${DOCKER_NETWORK_NAME} \ + -p $PORT_PROXY:8080 \ + proxy:dev } diff --git a/scripts/docker-testnet/start.sh b/scripts/docker-testnet/start.sh index c32d7ac0523..c96f071251d 100755 --- a/scripts/docker-testnet/start.sh +++ b/scripts/docker-testnet/start.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -e +set -eux export DOCKERTESTNETDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" diff --git a/scripts/docker-testnet/variables.sh b/scripts/docker-testnet/variables.sh index 69c0e90d195..90ef56a4fa4 100644 --- a/scripts/docker-testnet/variables.sh +++ b/scripts/docker-testnet/variables.sh @@ -28,14 +28,8 @@ export USE_TXGEN=0 # anyway. export TESTNETDIR="$HOME/MultiversX/testnet" - # Path to mx-chain-deploy-go, branch: master. Default: near mx-chain-go. - -if [[ -n $CI_RUN ]]; then - export CONFIGGENERATORDIR="$(dirname $MULTIVERSXDIR)/mx-chain-go/mx-chain-deploy-go/cmd/filegen" -else - export CONFIGGENERATORDIR="$(dirname $MULTIVERSXDIR)/mx-chain-deploy-go/cmd/filegen" -fi +export CONFIGGENERATORDIR="$(dirname $MULTIVERSXDIR)/mx-chain-deploy-go/cmd/filegen" export CONFIGGENERATOR="$CONFIGGENERATORDIR/filegen" # Leave unchanged. export CONFIGGENERATOROUTPUTDIR="output" @@ -114,32 +108,28 @@ export PORT_ORIGIN_VALIDATOR_REST="9500" # UI configuration profiles -# Use tmux or not. If set to 1, only 2 terminal windows will be opened, and -# tmux will be used to display the running executables using split windows. -# Recommended. Tmux needs to be installed. -export USETMUX=1 - -# Log level for the logger in the Node. -export LOGLEVEL="*:INFO" - - -if [ "$TESTNETMODE" == "debug" ]; then - LOGLEVEL="*:DEBUG,api:INFO" -fi - -if [ "$TESTNETMODE" == "trace" ]; then - LOGLEVEL="*:TRACE" -fi +## Use tmux or not. If set to 1, only 2 terminal windows will be opened, and +## tmux will be used to display the running executables using split windows. +## Recommended. Tmux needs to be installed. +#export USETMUX=1 +# +## Log level for the logger in the Node. +#export LOGLEVEL="*:INFO" +# +# +#if [ "$TESTNETMODE" == "debug" ]; then +# LOGLEVEL="*:DEBUG,api:INFO" +#fi +# +#if [ "$TESTNETMODE" == "trace" ]; then +# LOGLEVEL="*:TRACE" +#fi ######################################################################## # Proxy configuration # Path to mx-chain-proxy-go, branch: master. Default: near mx-chain-go. -if [[ -n $CI_RUN ]]; then - export PROXYDIR="$(dirname $MULTIVERSXDIR)/mx-chain-go/mx-chain-proxy-go/cmd/proxy" -else - export PROXYDIR="$(dirname $MULTIVERSXDIR)/mx-chain-proxy-go/cmd/proxy" -fi +export PROXYDIR="$(dirname $MULTIVERSXDIR)/mx-chain-proxy-go/cmd/proxy" export PROXY=$PROXYDIR/proxy # Leave unchanged. export PORT_PROXY="7950" From ecd2a344db1d23d4b5349babc2676a02a739ef03 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 18 Mar 2024 10:39:22 +0200 Subject: [PATCH 118/503] Added README.md --- scripts/docker-testnet/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 scripts/docker-testnet/README.md diff --git a/scripts/docker-testnet/README.md b/scripts/docker-testnet/README.md new file mode 100644 index 00000000000..630393774eb --- /dev/null +++ b/scripts/docker-testnet/README.md @@ -0,0 +1,10 @@ +# Setting up a local-testnet with Docker + +First and foremost, one needs to build the **seednode** & **node** images. Hence, the **_build.sh_** +script is provided. This can be done, by invoking the script or building the images manually. + +``` +./build.sh # (Optional) Can be ignored if you already have the images stored in the local registry. +./start.sh # Will start the local-testnet. +./clean.sh # Will stop and remove the containers related to the local-testnet. +``` \ No newline at end of file From 9bf2d7cfa0c679be8a7e90dd4e0ababa8b565165 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Mon, 18 Mar 2024 12:57:04 +0200 Subject: [PATCH 119/503] cosmetic changes. --- scripts/docker-testnet/build.sh | 2 +- scripts/docker-testnet/variables.sh | 19 ------------------- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/scripts/docker-testnet/build.sh b/scripts/docker-testnet/build.sh index 5bc11887fce..22babc04c84 100755 --- a/scripts/docker-testnet/build.sh +++ b/scripts/docker-testnet/build.sh @@ -2,7 +2,7 @@ set -eux -cd ${MULTIVERSXDIR} +pushd ../.. docker build -f docker/seednode/Dockerfile . -t seednode:dev diff --git a/scripts/docker-testnet/variables.sh b/scripts/docker-testnet/variables.sh index 90ef56a4fa4..dfd45bc7b5a 100644 --- a/scripts/docker-testnet/variables.sh +++ b/scripts/docker-testnet/variables.sh @@ -106,25 +106,6 @@ export PORT_ORIGIN_OBSERVER_REST="10000" export PORT_ORIGIN_VALIDATOR="21500" export PORT_ORIGIN_VALIDATOR_REST="9500" -# UI configuration profiles - -## Use tmux or not. If set to 1, only 2 terminal windows will be opened, and -## tmux will be used to display the running executables using split windows. -## Recommended. Tmux needs to be installed. -#export USETMUX=1 -# -## Log level for the logger in the Node. -#export LOGLEVEL="*:INFO" -# -# -#if [ "$TESTNETMODE" == "debug" ]; then -# LOGLEVEL="*:DEBUG,api:INFO" -#fi -# -#if [ "$TESTNETMODE" == "trace" ]; then -# LOGLEVEL="*:TRACE" -#fi - ######################################################################## # Proxy configuration From d0d9ece837e72ae8bc47d2e4a322c66620d7bbe7 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Tue, 19 Mar 2024 11:56:40 +0200 Subject: [PATCH 120/503] - set enable epoch --- cmd/node/config/enableEpochs.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index 10e51b24a86..482b30b0329 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -288,7 +288,8 @@ CurrentRandomnessOnSortingEnableEpoch = 4 # StakeLimitsEnableEpoch represents the epoch when stake limits on validators are enabled - StakeLimitsEnableEpoch = 5 + # Should have the same value as StakingV4Step1EnableEpoch that triggers the automatic unstake operations for the queue nodes + StakeLimitsEnableEpoch = 4 # StakingV4Step1EnableEpoch represents the epoch when staking v4 is initialized. This is the epoch in which # all nodes from staking queue are moved in the auction list From 9cf69bdb916e6cc16ccf5ee39f590de7be815f80 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Tue, 19 Mar 2024 12:00:56 +0200 Subject: [PATCH 121/503] - renamed a test --- integrationTests/chainSimulator/staking/delegation_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrationTests/chainSimulator/staking/delegation_test.go b/integrationTests/chainSimulator/staking/delegation_test.go index b7e2e628d98..b0edfd662b5 100644 --- a/integrationTests/chainSimulator/staking/delegation_test.go +++ b/integrationTests/chainSimulator/staking/delegation_test.go @@ -649,7 +649,7 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith2StakingContracts(t * // 9. Unbond the 2 nodes (that were un staked) // Internal test scenario #85 -func TestWIP(t *testing.T) { +func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnstakeAndUnbond(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } From b55004a046de738ce7626e44956269eaa8418e6a Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Tue, 19 Mar 2024 14:22:12 +0200 Subject: [PATCH 122/503] - fixed tests --- .../chainSimulator/staking/delegation_test.go | 14 ++++++ .../staking/stakeAndUnStake_test.go | 45 ++++++++++++------- node/chainSimulator/configs/configs.go | 2 + 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/integrationTests/chainSimulator/staking/delegation_test.go b/integrationTests/chainSimulator/staking/delegation_test.go index b0edfd662b5..1ed12f29fd9 100644 --- a/integrationTests/chainSimulator/staking/delegation_test.go +++ b/integrationTests/chainSimulator/staking/delegation_test.go @@ -675,6 +675,7 @@ func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta NumNodesWaitingListMeta: 3, NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 102 @@ -705,12 +706,14 @@ func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta NumNodesWaitingListMeta: 3, NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 4 cfg.EpochConfig.EnableEpochs.AlwaysMergeContextsInEEIEnableEpoch = 1 cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 4 + cfg.SystemSCConfig.StakingSystemSCConfig.NodeLimitPercentage = 1 }, }) require.Nil(t, err) @@ -735,12 +738,14 @@ func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta NumNodesWaitingListMeta: 3, NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 4 cfg.EpochConfig.EnableEpochs.AlwaysMergeContextsInEEIEnableEpoch = 1 cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 4 + cfg.SystemSCConfig.StakingSystemSCConfig.NodeLimitPercentage = 1 }, }) require.Nil(t, err) @@ -765,12 +770,14 @@ func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta NumNodesWaitingListMeta: 3, NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 4 cfg.EpochConfig.EnableEpochs.AlwaysMergeContextsInEEIEnableEpoch = 1 cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 4 + cfg.SystemSCConfig.StakingSystemSCConfig.NodeLimitPercentage = 1 }, }) require.Nil(t, err) @@ -1500,6 +1507,7 @@ func TestChainSimulator_MergeDelegation(t *testing.T) { NumNodesWaitingListMeta: 3, NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 102 @@ -1530,11 +1538,13 @@ func TestChainSimulator_MergeDelegation(t *testing.T) { NumNodesWaitingListMeta: 3, NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 4 cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 4 + cfg.SystemSCConfig.StakingSystemSCConfig.NodeLimitPercentage = 1 }, }) require.Nil(t, err) @@ -1560,11 +1570,13 @@ func TestChainSimulator_MergeDelegation(t *testing.T) { NumNodesWaitingListMeta: 3, NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 4 cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 4 + cfg.SystemSCConfig.StakingSystemSCConfig.NodeLimitPercentage = 1 }, }) require.Nil(t, err) @@ -1590,11 +1602,13 @@ func TestChainSimulator_MergeDelegation(t *testing.T) { NumNodesWaitingListMeta: 3, NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 4 cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 4 + cfg.SystemSCConfig.StakingSystemSCConfig.NodeLimitPercentage = 1 }, }) require.Nil(t, err) diff --git a/integrationTests/chainSimulator/staking/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stakeAndUnStake_test.go index 34ab9c44f78..b4c3fb6cf70 100644 --- a/integrationTests/chainSimulator/staking/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stakeAndUnStake_test.go @@ -677,6 +677,7 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation(t *testi NumNodesWaitingListMeta: 3, NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 102 @@ -707,11 +708,13 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation(t *testi NumNodesWaitingListMeta: 3, NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 4 cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 4 + cfg.SystemSCConfig.StakingSystemSCConfig.NodeLimitPercentage = 1 }, }) require.Nil(t, err) @@ -737,11 +740,13 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation(t *testi NumNodesWaitingListMeta: 3, NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 4 cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 4 + cfg.SystemSCConfig.StakingSystemSCConfig.NodeLimitPercentage = 1 }, }) require.Nil(t, err) @@ -767,11 +772,13 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation(t *testi NumNodesWaitingListMeta: 3, NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 4 cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 4 + cfg.SystemSCConfig.StakingSystemSCConfig.NodeLimitPercentage = 1 }, }) require.Nil(t, err) @@ -810,7 +817,7 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivation(t *testing.T, cs err = cs.GenerateBlocks(2) // allow the metachain to finalize the block that contains the staking of the node require.Nil(t, err) - testBLSKeyStaked(t, cs, metachainNode, blsKeys[0], targetEpoch) + testBLSKeyStaked(t, metachainNode, blsKeys[0]) stakeValue = big.NewInt(0).Set(minimumStakeValue) txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], mockBLSSignature) @@ -822,7 +829,7 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivation(t *testing.T, cs err = cs.GenerateBlocks(2) // allow the metachain to finalize the block that contains the staking of the node require.Nil(t, err) - testBLSKeyStaked(t, cs, metachainNode, blsKeys[1], targetEpoch) + testBLSKeyStaked(t, metachainNode, blsKeys[1]) log.Info("Step 1. Check the stake amount for the owner of the staked nodes") checkExpectedStakedValue(t, metachainNode, validatorOwner.Bytes, 5000) @@ -891,9 +898,8 @@ func checkOneOfTheNodesIsUnstaked(t *testing.T, } func testBLSKeyStaked(t *testing.T, - cs chainSimulatorIntegrationTests.ChainSimulator, metachainNode chainSimulatorProcess.NodeHandler, - blsKey string, targetEpoch int32, + blsKey string, ) { decodedBLSKey, _ := hex.DecodeString(blsKey) err := metachainNode.GetProcessComponents().ValidatorsProvider().ForceUpdate() @@ -952,6 +958,7 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation_WithReac NumNodesWaitingListMeta: 3, NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 102 @@ -982,11 +989,13 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation_WithReac NumNodesWaitingListMeta: 3, NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 4 cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 4 + cfg.SystemSCConfig.StakingSystemSCConfig.NodeLimitPercentage = 1 }, }) require.Nil(t, err) @@ -1012,11 +1021,13 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation_WithReac NumNodesWaitingListMeta: 3, NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 4 cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 4 + cfg.SystemSCConfig.StakingSystemSCConfig.NodeLimitPercentage = 1 }, }) require.Nil(t, err) @@ -1042,11 +1053,13 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation_WithReac NumNodesWaitingListMeta: 3, NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 4 cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 4 + cfg.SystemSCConfig.StakingSystemSCConfig.NodeLimitPercentage = 1 }, }) require.Nil(t, err) @@ -1085,7 +1098,7 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivationAndReactivation(t err = cs.GenerateBlocks(2) // allow the metachain to finalize the block that contains the staking of the node require.Nil(t, err) - testBLSKeyStaked(t, cs, metachainNode, blsKeys[0], targetEpoch) + testBLSKeyStaked(t, metachainNode, blsKeys[0]) stakeValue = big.NewInt(0).Set(minimumStakeValue) txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], mockBLSSignature) @@ -1097,7 +1110,7 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivationAndReactivation(t err = cs.GenerateBlocks(2) // allow the metachain to finalize the block that contains the staking of the node require.Nil(t, err) - testBLSKeyStaked(t, cs, metachainNode, blsKeys[1], targetEpoch) + testBLSKeyStaked(t, metachainNode, blsKeys[1]) log.Info("Step 1. Check the stake amount for the owner of the staked nodes") checkExpectedStakedValue(t, metachainNode, validatorOwner.Bytes, 5000) @@ -1144,8 +1157,8 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivationAndReactivation(t err = cs.GenerateBlocksUntilEpochIsReached(targetEpoch + 1) require.Nil(t, err) - testBLSKeyStaked(t, cs, metachainNode, blsKeys[0], targetEpoch) - testBLSKeyStaked(t, cs, metachainNode, blsKeys[1], targetEpoch) + testBLSKeyStaked(t, metachainNode, blsKeys[0]) + testBLSKeyStaked(t, metachainNode, blsKeys[1]) } // Test description: @@ -1315,7 +1328,7 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsBeforeUnbonding(t *testi err = cs.GenerateBlocks(2) // allow the metachain to finalize the block that contains the staking of the node require.Nil(t, err) - testBLSKeyStaked(t, cs, metachainNode, blsKeys[0], targetEpoch) + testBLSKeyStaked(t, metachainNode, blsKeys[0]) shardIDValidatorOwner := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(validatorOwner.Bytes) accountValidatorOwner, _, err := cs.GetNodeHandler(shardIDValidatorOwner).GetFacadeHandler().GetAccount(validatorOwner.Bech32, coreAPI.AccountQueryOptions{}) @@ -1336,7 +1349,7 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsBeforeUnbonding(t *testi require.Nil(t, err) // check bls key is still staked - testBLSKeyStaked(t, cs, metachainNode, blsKeys[0], targetEpoch) + testBLSKeyStaked(t, metachainNode, blsKeys[0]) txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) txUnBond := generateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForUnBond) @@ -1549,7 +1562,7 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInFirstEpoch(t *testing. err = cs.GenerateBlocks(2) // allow the metachain to finalize the block that contains the staking of the node require.Nil(t, err) - testBLSKeyStaked(t, cs, metachainNode, blsKeys[0], targetEpoch) + testBLSKeyStaked(t, metachainNode, blsKeys[0]) shardIDValidatorOwner := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(validatorOwner.Bytes) accountValidatorOwner, _, err := cs.GetNodeHandler(shardIDValidatorOwner).GetFacadeHandler().GetAccount(validatorOwner.Bech32, coreAPI.AccountQueryOptions{}) @@ -1568,7 +1581,7 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInFirstEpoch(t *testing. require.Nil(t, err) // check bls key is still staked - testBLSKeyStaked(t, cs, metachainNode, blsKeys[0], targetEpoch) + testBLSKeyStaked(t, metachainNode, blsKeys[0]) scQuery := &process.SCQuery{ ScAddress: vm.ValidatorSCAddress, @@ -1822,7 +1835,7 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, err = cs.GenerateBlocks(2) require.Nil(t, err) - testBLSKeyStaked(t, cs, metachainNode, blsKeys[0], targetEpoch) + testBLSKeyStaked(t, metachainNode, blsKeys[0]) shardIDValidatorOwner := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(validatorOwner.Bytes) accountValidatorOwner, _, err := cs.GetNodeHandler(shardIDValidatorOwner).GetFacadeHandler().GetAccount(validatorOwner.Bech32, coreAPI.AccountQueryOptions{}) @@ -1871,7 +1884,7 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, require.Nil(t, err) // check bls key is still staked - testBLSKeyStaked(t, cs, metachainNode, blsKeys[0], targetEpoch) + testBLSKeyStaked(t, metachainNode, blsKeys[0]) scQuery := &process.SCQuery{ ScAddress: vm.ValidatorSCAddress, @@ -2178,7 +2191,7 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs err = cs.GenerateBlocks(2) require.Nil(t, err) - testBLSKeyStaked(t, cs, metachainNode, blsKeys[0], targetEpoch) + testBLSKeyStaked(t, metachainNode, blsKeys[0]) shardIDValidatorOwner := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(validatorOwner.Bytes) accountValidatorOwner, _, err := cs.GetNodeHandler(shardIDValidatorOwner).GetFacadeHandler().GetAccount(validatorOwner.Bech32, coreAPI.AccountQueryOptions{}) @@ -2215,7 +2228,7 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs require.NotNil(t, unStakeTx) // check bls key is still staked - testBLSKeyStaked(t, cs, metachainNode, blsKeys[0], targetEpoch) + testBLSKeyStaked(t, metachainNode, blsKeys[0]) scQuery := &process.SCQuery{ ScAddress: vm.ValidatorSCAddress, diff --git a/node/chainSimulator/configs/configs.go b/node/chainSimulator/configs/configs.go index f2a6e452296..731f8078eef 100644 --- a/node/chainSimulator/configs/configs.go +++ b/node/chainSimulator/configs/configs.go @@ -168,12 +168,14 @@ func SetQuickJailRatingConfig(cfg *config.Configs) { // - Step 2 activation epoch // - Step 3 activation epoch func SetStakingV4ActivationEpochs(cfg *config.Configs, initialEpoch uint32) { + cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = initialEpoch cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = initialEpoch cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = initialEpoch + 1 cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = initialEpoch + 2 // Set the MaxNodesChange enable epoch for index 2 cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = initialEpoch + 2 + cfg.SystemSCConfig.StakingSystemSCConfig.NodeLimitPercentage = 1 } func generateGenesisFile(args ArgsChainSimulatorConfigs, configs *config.Configs) (*dtos.InitialWalletKeys, error) { From 7a9b96a68f8b8a4b1fbb8e0dd03384b22b32f1b1 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Wed, 20 Mar 2024 13:35:00 +0200 Subject: [PATCH 123/503] - added more files in the overridable configs options --- cmd/node/config/prefs.toml | 3 +- config/overridableConfig/configOverriding.go | 43 +++++++++++--- .../configOverriding_test.go | 56 ++++++++++++++++++- 3 files changed, 92 insertions(+), 10 deletions(-) diff --git a/cmd/node/config/prefs.toml b/cmd/node/config/prefs.toml index 42e16624ab8..47a439222d0 100644 --- a/cmd/node/config/prefs.toml +++ b/cmd/node/config/prefs.toml @@ -40,7 +40,8 @@ # configuration of the node has the false value) # The Path indicates what value to change, while Value represents the new value in string format. The node operator must make sure # to follow the same type of the original value (ex: uint32: "37", float32: "37.0", bool: "true") - # File represents the file name that holds the configuration. Currently, the supported files are: config.toml, external.toml, p2p.toml and enableEpochs.toml + # File represents the file name that holds the configuration. Currently, the supported files are: + # api.toml, config.toml, economics.toml, enableEpochs.toml, enableRounds.toml, external.toml, fullArchiveP2P.toml, p2p.toml, ratings.toml, systemSmartContractsConfig.toml # ------------------------------- # Un-comment and update the following section in order to enable config values overloading # ------------------------------- diff --git a/config/overridableConfig/configOverriding.go b/config/overridableConfig/configOverriding.go index 7e9f3a153de..84b823738fe 100644 --- a/config/overridableConfig/configOverriding.go +++ b/config/overridableConfig/configOverriding.go @@ -10,16 +10,32 @@ import ( ) const ( + apiTomlFile = "api.toml" configTomlFile = "config.toml" + economicsTomlFile = "economics.toml" enableEpochsTomlFile = "enableEpochs.toml" - p2pTomlFile = "p2p.toml" - fullArchiveP2PTomlFile = "fullArchiveP2P.toml" + enableRoundsTomlFile = "enableRounds.toml" externalTomlFile = "external.toml" + fullArchiveP2PTomlFile = "fullArchiveP2P.toml" + p2pTomlFile = "p2p.toml" + ratingsTomlFile = "ratings.toml" + systemSCTomlFile = "systemSmartContractsConfig.toml" ) var ( - availableConfigFilesForOverriding = []string{configTomlFile, enableEpochsTomlFile, p2pTomlFile, externalTomlFile} - log = logger.GetOrCreate("config") + availableConfigFilesForOverriding = []string{ + apiTomlFile, + configTomlFile, + economicsTomlFile, + enableEpochsTomlFile, + enableRoundsTomlFile, + externalTomlFile, + fullArchiveP2PTomlFile, + p2pTomlFile, + ratingsTomlFile, + systemSCTomlFile, + } + log = logger.GetOrCreate("config") ) // OverrideConfigValues will override config values for the specified configurations @@ -27,16 +43,27 @@ func OverrideConfigValues(newConfigs []config.OverridableConfig, configs *config var err error for _, newConfig := range newConfigs { switch newConfig.File { + case apiTomlFile: + err = reflectcommon.AdaptStructureValueBasedOnPath(configs.ApiRoutesConfig, newConfig.Path, newConfig.Value) case configTomlFile: err = reflectcommon.AdaptStructureValueBasedOnPath(configs.GeneralConfig, newConfig.Path, newConfig.Value) + case economicsTomlFile: + err = reflectcommon.AdaptStructureValueBasedOnPath(configs.EconomicsConfig, newConfig.Path, newConfig.Value) case enableEpochsTomlFile: err = reflectcommon.AdaptStructureValueBasedOnPath(configs.EpochConfig, newConfig.Path, newConfig.Value) - case p2pTomlFile: - err = reflectcommon.AdaptStructureValueBasedOnPath(configs.MainP2pConfig, newConfig.Path, newConfig.Value) - case fullArchiveP2PTomlFile: - err = reflectcommon.AdaptStructureValueBasedOnPath(configs.FullArchiveP2pConfig, newConfig.Path, newConfig.Value) + case enableRoundsTomlFile: + err = reflectcommon.AdaptStructureValueBasedOnPath(configs.RoundConfig, newConfig.Path, newConfig.Value) case externalTomlFile: err = reflectcommon.AdaptStructureValueBasedOnPath(configs.ExternalConfig, newConfig.Path, newConfig.Value) + case fullArchiveP2PTomlFile: + err = reflectcommon.AdaptStructureValueBasedOnPath(configs.FullArchiveP2pConfig, newConfig.Path, newConfig.Value) + case p2pTomlFile: + err = reflectcommon.AdaptStructureValueBasedOnPath(configs.MainP2pConfig, newConfig.Path, newConfig.Value) + case ratingsTomlFile: + err = reflectcommon.AdaptStructureValueBasedOnPath(configs.RatingsConfig, newConfig.Path, newConfig.Value) + case systemSCTomlFile: + err = reflectcommon.AdaptStructureValueBasedOnPath(configs.SystemSCConfig, newConfig.Path, newConfig.Value) + default: err = fmt.Errorf("invalid config file <%s>. Available options are %s", newConfig.File, strings.Join(availableConfigFilesForOverriding, ",")) } diff --git a/config/overridableConfig/configOverriding_test.go b/config/overridableConfig/configOverriding_test.go index b15cf8e5c5c..c6cac7bef94 100644 --- a/config/overridableConfig/configOverriding_test.go +++ b/config/overridableConfig/configOverriding_test.go @@ -22,7 +22,8 @@ func TestOverrideConfigValues(t *testing.T) { t.Parallel() err := OverrideConfigValues([]config.OverridableConfig{{File: "invalid.toml"}}, &config.Configs{}) - require.Equal(t, "invalid config file . Available options are config.toml,enableEpochs.toml,p2p.toml,external.toml", err.Error()) + availableOptionsString := "api.toml,config.toml,economics.toml,enableEpochs.toml,enableRounds.toml,external.toml,fullArchiveP2P.toml,p2p.toml,ratings.toml,systemSmartContractsConfig.toml" + require.Equal(t, "invalid config file . Available options are "+availableOptionsString, err.Error()) }) t.Run("nil config, should error", func(t *testing.T) { @@ -81,4 +82,57 @@ func TestOverrideConfigValues(t *testing.T) { require.NoError(t, err) require.Equal(t, uint32(37), configs.EpochConfig.EnableEpochs.ESDTMetadataContinuousCleanupEnableEpoch) }) + + t.Run("should work for api.toml", func(t *testing.T) { + t.Parallel() + + configs := &config.Configs{ApiRoutesConfig: &config.ApiRoutesConfig{}} + + err := OverrideConfigValues([]config.OverridableConfig{{Path: "Logging.LoggingEnabled", Value: "true", File: "api.toml"}}, configs) + require.NoError(t, err) + require.True(t, configs.ApiRoutesConfig.Logging.LoggingEnabled) + }) + + t.Run("should work for economics.toml", func(t *testing.T) { + t.Parallel() + + configs := &config.Configs{EconomicsConfig: &config.EconomicsConfig{}} + + err := OverrideConfigValues([]config.OverridableConfig{{Path: "GlobalSettings.GenesisTotalSupply", Value: "37", File: "economics.toml"}}, configs) + require.NoError(t, err) + require.Equal(t, "37", configs.EconomicsConfig.GlobalSettings.GenesisTotalSupply) + }) + + t.Run("should work for enableRounds.toml", func(t *testing.T) { + // TODO: fix this test + t.Skip("skipped, as this test requires the fix from this PR: https://github.com/multiversx/mx-chain-go/pull/5851") + + t.Parallel() + + configs := &config.Configs{RoundConfig: &config.RoundConfig{}} + + err := OverrideConfigValues([]config.OverridableConfig{{Path: "RoundActivations.DisableAsyncCallV1.Round", Value: "37", File: "enableRounds.toml"}}, configs) + require.NoError(t, err) + require.Equal(t, uint32(37), configs.RoundConfig.RoundActivations["DisableAsyncCallV1"]) + }) + + t.Run("should work for ratings.toml", func(t *testing.T) { + t.Parallel() + + configs := &config.Configs{RatingsConfig: &config.RatingsConfig{}} + + err := OverrideConfigValues([]config.OverridableConfig{{Path: "General.StartRating", Value: "37", File: "ratings.toml"}}, configs) + require.NoError(t, err) + require.Equal(t, uint32(37), configs.RatingsConfig.General.StartRating) + }) + + t.Run("should work for systemSmartContractsConfig.toml", func(t *testing.T) { + t.Parallel() + + configs := &config.Configs{SystemSCConfig: &config.SystemSmartContractsConfig{}} + + err := OverrideConfigValues([]config.OverridableConfig{{Path: "StakingSystemSCConfig.UnBondPeriod", Value: "37", File: "systemSmartContractsConfig.toml"}}, configs) + require.NoError(t, err) + require.Equal(t, uint64(37), configs.SystemSCConfig.StakingSystemSCConfig.UnBondPeriod) + }) } From 96adb1fb233a6ebbc75a2efac1518ddf321e6e7b Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Wed, 20 Mar 2024 16:06:47 +0200 Subject: [PATCH 124/503] Added publish ports argument and formatting changes. --- scripts/docker-testnet/functions.sh | 152 +++++++++++++++++----------- scripts/docker-testnet/variables.sh | 8 ++ 2 files changed, 101 insertions(+), 59 deletions(-) diff --git a/scripts/docker-testnet/functions.sh b/scripts/docker-testnet/functions.sh index 0a79c8de751..c075793030a 100755 --- a/scripts/docker-testnet/functions.sh +++ b/scripts/docker-testnet/functions.sh @@ -29,105 +29,139 @@ createDockerNetwork() { } startSeedNode() { + local publishPortArgs="" + if [[ "$DOCKER_PUBLISH_PORTS" -gt 0 ]]; then + publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10000" + (( DOCKER_PUBLISH_PORT_RANGE++ )) + fi + docker run -d --name seednode \ -v ${TESTNETDIR}/seednode/config:/go/mx-chain-go/cmd/seednode/config \ --network ${DOCKER_NETWORK_NAME} \ + $publishPortArgs \ seednode:dev \ --rest-api-interface=0.0.0.0:10000 } startObservers() { - local observerIdx=0 - # Example for loop with injected variables in Bash - for ((i = 0; i < SHARDCOUNT; i++)); do - for ((j = 0; j < SHARD_OBSERVERCOUNT; j++)); do - # Your commands or code to be executed in each iteration + local observerIdx=0 + local publishPortArgs="" + + # Example for loop with injected variables in Bash + for ((i = 0; i < SHARDCOUNT; i++)); do + for ((j = 0; j < SHARD_OBSERVERCOUNT; j++)); do + # Your commands or code to be executed in each iteration + KEY_INDEX=$((TOTAL_NODECOUNT - observerIdx - 1)) + + if [[ "$DOCKER_PUBLISH_PORTS" -gt 0 ]]; then + publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10000" + fi + + docker run -d --name "observer${observerIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-shard${i}" \ + -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ + --network ${DOCKER_NETWORK_NAME} \ + $publishPortArgs \ + node:dev \ + --destination-shard-as-observer $i \ + --rest-api-interface=0.0.0.0:10200 \ + --config ./config/config_observer.toml \ + --sk-index=${KEY_INDEX} \ + $EXTRA_OBSERVERS_FLAGS + + + (( IP_HOST_BYTE++ )) + (( DOCKER_PUBLISH_PORT_RANGE++ )) + ((observerIdx++)) || true + done + done + + for ((i = 0; i < META_OBSERVERCOUNT; i++)); do KEY_INDEX=$((TOTAL_NODECOUNT - observerIdx - 1)) - docker run -d --name "observer${observerIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-shard${i}" \ + if [[ "$DOCKER_PUBLISH_PORTS" -gt 0 ]]; then + publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10000" + fi + + docker run -d --name "observer${observerIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-metachain" \ -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ --network ${DOCKER_NETWORK_NAME} \ + $publishPortArgs \ node:dev \ - --destination-shard-as-observer $i \ + --destination-shard-as-observer "metachain" \ --rest-api-interface=0.0.0.0:10200 \ --config ./config/config_observer.toml \ --sk-index=${KEY_INDEX} \ $EXTRA_OBSERVERS_FLAGS - (( IP_HOST_BYTE++ )) + (( DOCKER_PUBLISH_PORT_RANGE++ )) ((observerIdx++)) || true - done - done - - for ((i = 0; i < META_OBSERVERCOUNT; i++)); do - KEY_INDEX=$((TOTAL_NODECOUNT - observerIdx - 1)) - - docker run -d --name "observer${observerIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-metachain" \ - -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ - --network ${DOCKER_NETWORK_NAME} \ - node:dev \ - --destination-shard-as-observer "metachain" \ - --rest-api-interface=0.0.0.0:10200 \ - --config ./config/config_observer.toml \ - --sk-index=${KEY_INDEX} \ - $EXTRA_OBSERVERS_FLAGS - - (( IP_HOST_BYTE++ )) - ((observerIdx++)) || true - done + done } startValidators() { - validatorIdx=0 - # Example for loop with injected variables in Bash - for ((i = 0; i < SHARDCOUNT; i++)); do - for ((j = 0; j < SHARD_VALIDATORCOUNT; j++)); do + local validatorIdx=0 + local publishPortArgs="" + # Example for loop with injected variables in Bash + for ((i = 0; i < SHARDCOUNT; i++)); do + for ((j = 0; j < SHARD_VALIDATORCOUNT; j++)); do + + if [[ "$DOCKER_PUBLISH_PORTS" -gt 0 ]]; then + publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10000" + fi + + docker run -d --name "validator${validatorIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-shard${i}" \ + -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ + --network ${DOCKER_NETWORK_NAME} \ + $publishPortArgs \ + node:dev \ + --rest-api-interface=0.0.0.0:10200 \ + --config ./config/config_validator.toml \ + --sk-index=${validatorIdx} \ + + (( IP_HOST_BYTE++ )) + (( DOCKER_PUBLISH_PORT_RANGE++ )) + ((validatorIdx++)) || true + done + done - docker run -d --name "validator${validatorIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-shard${i}" \ - -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ - --network ${DOCKER_NETWORK_NAME} \ - node:dev \ - --rest-api-interface=0.0.0.0:10200 \ - --config ./config/config_validator.toml \ - --sk-index=${validatorIdx} \ + for ((i = 0; i < META_VALIDATORCOUNT; i++)); do - (( IP_HOST_BYTE++ )) - ((validatorIdx++)) || true - done - done + if [[ "$DOCKER_PUBLISH_PORTS" -gt 0 ]]; then + publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10000" + fi - for ((i = 0; i < META_VALIDATORCOUNT; i++)); do - docker run -d --name "validator${validatorIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-metachain" \ + docker run -d --name "validator${validatorIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-metachain" \ -v $TESTNETDIR/node/config:/go/mx-chain-go/cmd/node/config \ --network ${DOCKER_NETWORK_NAME} \ + $publishPortArgs \ node:dev \ --rest-api-interface=0.0.0.0:10200 \ --config ./config/config_observer.toml \ --sk-index=${validatorIdx} \ - (( IP_HOST_BYTE++ )) - ((validatorIdx++)) || true + (( IP_HOST_BYTE++ )) + (( DOCKER_PUBLISH_PORT_RANGE++ )) + ((validatorIdx++)) || true done } updateProxyConfigDocker() { - pushd $TESTNETDIR/proxy/config - cp config.toml config_edit.toml - - # Truncate config.toml before the [[Observers]] list - sed -i -n '/\[\[Observers\]\]/q;p' config_edit.toml + pushd $TESTNETDIR/proxy/config + cp config.toml config_edit.toml - if [ "$SHARD_OBSERVERCOUNT" -le 0 ]; then - generateProxyValidatorListDocker config_edit.toml - else - generateProxyObserverListDocker config_edit.toml - fi + # Truncate config.toml before the [[Observers]] list + sed -i -n '/\[\[Observers\]\]/q;p' config_edit.toml - mv config_edit.toml config.toml + if [ "$SHARD_OBSERVERCOUNT" -le 0 ]; then + generateProxyValidatorListDocker config_edit.toml + else + generateProxyObserverListDocker config_edit.toml + fi - echo "Updated configuration for the Proxy." - popd + mv config_edit.toml config.toml + echo "Updated configuration for the Proxy." + popd } generateProxyObserverListDocker() { diff --git a/scripts/docker-testnet/variables.sh b/scripts/docker-testnet/variables.sh index dfd45bc7b5a..bdcb26662fd 100644 --- a/scripts/docker-testnet/variables.sh +++ b/scripts/docker-testnet/variables.sh @@ -6,6 +6,14 @@ # Don't change the subnet, unless you know what you are doing. Prone to errors. export DOCKER_NETWORK_SUBNET="172.18.0.0/24" export DOCKER_NETWORK_NAME="local-testnet" + +# By default ports won't be published. If set to 1, all containers will port-forward to host network. +export DOCKER_PUBLISH_PORTS=1 + +if [[ "$DOCKER_PUBLISH_PORTS" -gt 0 ]]; then + export DOCKER_PUBLISH_PORT_RANGE=30000 +fi + ######################################################################## From e3cd364ed9baa52af57f6364b2fbd42298c3d99c Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Wed, 20 Mar 2024 16:52:34 +0200 Subject: [PATCH 125/503] Added start/stop mechanism along with comsetic changes. --- scripts/docker-testnet/README.md | 6 +++- scripts/docker-testnet/setup.sh | 43 +++++++++++++++++++++++++++++ scripts/docker-testnet/start.sh | 47 ++++++++------------------------ scripts/docker-testnet/stop.sh | 21 ++++++++++++++ 4 files changed, 80 insertions(+), 37 deletions(-) create mode 100755 scripts/docker-testnet/setup.sh create mode 100755 scripts/docker-testnet/stop.sh diff --git a/scripts/docker-testnet/README.md b/scripts/docker-testnet/README.md index 630393774eb..04b4de89631 100644 --- a/scripts/docker-testnet/README.md +++ b/scripts/docker-testnet/README.md @@ -5,6 +5,10 @@ script is provided. This can be done, by invoking the script or building the ima ``` ./build.sh # (Optional) Can be ignored if you already have the images stored in the local registry. -./start.sh # Will start the local-testnet. +./setup.sh # Will setup the local-testnet. ./clean.sh # Will stop and remove the containers related to the local-testnet. + +Optionally +./stop.sh # Will stop all the containers in the local-testnet. +./start.sh # Will start all stopped containers from the initial local-testnet. ``` \ No newline at end of file diff --git a/scripts/docker-testnet/setup.sh b/scripts/docker-testnet/setup.sh new file mode 100755 index 00000000000..c96f071251d --- /dev/null +++ b/scripts/docker-testnet/setup.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +set -eux + +export DOCKERTESTNETDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +MULTIVERSXTESTNETSCRIPTSDIR="$(dirname "$DOCKERTESTNETDIR")/testnet" + +source "$DOCKERTESTNETDIR/variables.sh" +source "$DOCKERTESTNETDIR/functions.sh" +source "$MULTIVERSXTESTNETSCRIPTSDIR/include/config.sh" +source "$MULTIVERSXTESTNETSCRIPTSDIR/include/build.sh" + +cloneRepositories + +prepareFolders + +buildConfigGenerator + +generateConfig + +copyConfig + +copySeednodeConfig +updateSeednodeConfig + +copyNodeConfig +updateNodeConfig + +createDockerNetwork + +startSeedNode +startObservers +startValidators + +if [ $USE_PROXY -eq 1 ]; then + buildProxyImage + prepareFolders_Proxy + copyProxyConfig + updateProxyConfigDocker + startProxyDocker +fi + diff --git a/scripts/docker-testnet/start.sh b/scripts/docker-testnet/start.sh index c96f071251d..1bf10af1840 100755 --- a/scripts/docker-testnet/start.sh +++ b/scripts/docker-testnet/start.sh @@ -2,42 +2,17 @@ set -eux -export DOCKERTESTNETDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +file_path="./tmp/stopped_containers" -MULTIVERSXTESTNETSCRIPTSDIR="$(dirname "$DOCKERTESTNETDIR")/testnet" - -source "$DOCKERTESTNETDIR/variables.sh" -source "$DOCKERTESTNETDIR/functions.sh" -source "$MULTIVERSXTESTNETSCRIPTSDIR/include/config.sh" -source "$MULTIVERSXTESTNETSCRIPTSDIR/include/build.sh" - -cloneRepositories - -prepareFolders - -buildConfigGenerator - -generateConfig - -copyConfig - -copySeednodeConfig -updateSeednodeConfig - -copyNodeConfig -updateNodeConfig - -createDockerNetwork - -startSeedNode -startObservers -startValidators - -if [ $USE_PROXY -eq 1 ]; then - buildProxyImage - prepareFolders_Proxy - copyProxyConfig - updateProxyConfigDocker - startProxyDocker +# Check if the file exists +if [ ! -f "$file_path" ]; then + echo "File $file_path not found." + exit 1 fi +# Read the file line by line +while IFS= read -r line; do + docker start $line +done < "$file_path" + +rmdir ./tmp \ No newline at end of file diff --git a/scripts/docker-testnet/stop.sh b/scripts/docker-testnet/stop.sh new file mode 100755 index 00000000000..89486f82044 --- /dev/null +++ b/scripts/docker-testnet/stop.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +set -eux + +# Delete the entire testnet folder, which includes configuration, executables and logs. + +export MULTIVERSXTESTNETSCRIPTSDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +source "$MULTIVERSXTESTNETSCRIPTSDIR/variables.sh" + +# Get the IDs of containers attached to the network +export CONTAINER_IDS=$(docker network inspect -f '{{range $k, $v := .Containers}}{{printf "%s\n" $k}}{{end}}' "$DOCKER_NETWORK_NAME") + +mkdir -p ./tmp + +# Stop each container +echo "Stopping containers..." +for CONTAINER_ID in $CONTAINER_IDS; do + docker stop "$CONTAINER_ID" + echo "$CONTAINER_ID" >> ./tmp/stopped_containers +done \ No newline at end of file From d3cf4f8692199f7c3026615e9bfbd87a079e7c8f Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Wed, 20 Mar 2024 17:18:18 +0200 Subject: [PATCH 126/503] Fixed paths. --- scripts/docker-testnet/build.sh | 8 +++++++- scripts/docker-testnet/start.sh | 6 ++++-- scripts/docker-testnet/stop.sh | 4 ++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/scripts/docker-testnet/build.sh b/scripts/docker-testnet/build.sh index 22babc04c84..0b038e17e4b 100755 --- a/scripts/docker-testnet/build.sh +++ b/scripts/docker-testnet/build.sh @@ -2,7 +2,13 @@ set -eux -pushd ../.. +export DOCKERTESTNETDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +MULTIVERSXTESTNETSCRIPTSDIR="$(dirname "$DOCKERTESTNETDIR")/testnet" + +source "$DOCKERTESTNETDIR/variables.sh" + +cd ${MULTIVERSXDIR} docker build -f docker/seednode/Dockerfile . -t seednode:dev diff --git a/scripts/docker-testnet/start.sh b/scripts/docker-testnet/start.sh index 1bf10af1840..f68e49d62d4 100755 --- a/scripts/docker-testnet/start.sh +++ b/scripts/docker-testnet/start.sh @@ -2,7 +2,9 @@ set -eux -file_path="./tmp/stopped_containers" +export DOCKERTESTNETDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" + +file_path="${DOCKERTESTNETDIR}/tmp/stopped_containers" # Check if the file exists if [ ! -f "$file_path" ]; then @@ -15,4 +17,4 @@ while IFS= read -r line; do docker start $line done < "$file_path" -rmdir ./tmp \ No newline at end of file +rm -rf "${DOCKERTESTNETDIR}/tmp" \ No newline at end of file diff --git a/scripts/docker-testnet/stop.sh b/scripts/docker-testnet/stop.sh index 89486f82044..6c5054570dc 100755 --- a/scripts/docker-testnet/stop.sh +++ b/scripts/docker-testnet/stop.sh @@ -11,11 +11,11 @@ source "$MULTIVERSXTESTNETSCRIPTSDIR/variables.sh" # Get the IDs of containers attached to the network export CONTAINER_IDS=$(docker network inspect -f '{{range $k, $v := .Containers}}{{printf "%s\n" $k}}{{end}}' "$DOCKER_NETWORK_NAME") -mkdir -p ./tmp +mkdir -p "$MULTIVERSXTESTNETSCRIPTSDIR/tmp" # Stop each container echo "Stopping containers..." for CONTAINER_ID in $CONTAINER_IDS; do docker stop "$CONTAINER_ID" - echo "$CONTAINER_ID" >> ./tmp/stopped_containers + echo "$CONTAINER_ID" >> "$MULTIVERSXTESTNETSCRIPTSDIR/tmp/stopped_containers" done \ No newline at end of file From a9975e61799f78e8576aada839980f062cdf66bb Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Wed, 20 Mar 2024 21:00:32 +0200 Subject: [PATCH 127/503] - fixed the configs changes in chain simulator --- .../chainSimulator/staking/jail_test.go | 4 ++-- .../staking/stakeAndUnStake_test.go | 10 ++++++---- node/chainSimulator/configs/configs.go | 20 ++++++++++++------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/integrationTests/chainSimulator/staking/jail_test.go b/integrationTests/chainSimulator/staking/jail_test.go index 185365912b1..2802ff94e8a 100644 --- a/integrationTests/chainSimulator/staking/jail_test.go +++ b/integrationTests/chainSimulator/staking/jail_test.go @@ -77,7 +77,7 @@ func testChainSimulatorJailAndUnJail(t *testing.T, targetEpoch int32, nodeStatus AlterConfigsFunction: func(cfg *config.Configs) { configs.SetStakingV4ActivationEpochs(cfg, stakingV4JailUnJailStep1EnableEpoch) newNumNodes := cfg.SystemSCConfig.StakingSystemSCConfig.MaxNumberOfNodesForStake + 8 // 8 nodes until new nodes will be placed on queue - configs.SetMaxNumberOfNodesInConfigs(cfg, newNumNodes, numOfShards) + configs.SetMaxNumberOfNodesInConfigs(cfg, uint32(newNumNodes), 0, numOfShards) configs.SetQuickJailRatingConfig(cfg) }, }) @@ -179,7 +179,7 @@ func TestChainSimulator_FromQueueToAuctionList(t *testing.T) { configs.SetQuickJailRatingConfig(cfg) newNumNodes := cfg.SystemSCConfig.StakingSystemSCConfig.MaxNumberOfNodesForStake + 1 - configs.SetMaxNumberOfNodesInConfigs(cfg, newNumNodes, numOfShards) + configs.SetMaxNumberOfNodesInConfigs(cfg, uint32(newNumNodes), 0, numOfShards) }, }) require.Nil(t, err) diff --git a/integrationTests/chainSimulator/staking/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stakeAndUnStake_test.go index b4c3fb6cf70..9ac5b86be20 100644 --- a/integrationTests/chainSimulator/staking/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stakeAndUnStake_test.go @@ -69,7 +69,7 @@ func TestChainSimulator_AddValidatorKey(t *testing.T) { NumNodesWaitingListShard: 0, AlterConfigsFunction: func(cfg *config.Configs) { newNumNodes := cfg.SystemSCConfig.StakingSystemSCConfig.MaxNumberOfNodesForStake + 8 // 8 nodes until new nodes will be placed on queue - configs.SetMaxNumberOfNodesInConfigs(cfg, newNumNodes, numOfShards) + configs.SetMaxNumberOfNodesInConfigs(cfg, uint32(newNumNodes), 0, numOfShards) }, }) require.Nil(t, err) @@ -200,8 +200,10 @@ func TestChainSimulator_AddANewValidatorAfterStakingV4(t *testing.T) { AlterConfigsFunction: func(cfg *config.Configs) { cfg.SystemSCConfig.StakingSystemSCConfig.NodeLimitPercentage = 1 cfg.GeneralConfig.ValidatorStatistics.CacheRefreshIntervalInSec = 1 - newNumNodes := cfg.SystemSCConfig.StakingSystemSCConfig.MaxNumberOfNodesForStake + 8 // 8 nodes until new nodes will be placed on queue - configs.SetMaxNumberOfNodesInConfigs(cfg, newNumNodes, numOfShards) + eligibleNodes := cfg.SystemSCConfig.StakingSystemSCConfig.MaxNumberOfNodesForStake + // 8 nodes until new nodes will be placed on queue + waitingNodes := uint32(8) + configs.SetMaxNumberOfNodesInConfigs(cfg, uint32(eligibleNodes), waitingNodes, numOfShards) }, }) require.Nil(t, err) @@ -328,7 +330,7 @@ func testStakeUnStakeUnBond(t *testing.T, targetEpoch int32) { cfg.SystemSCConfig.StakingSystemSCConfig.UnBondPeriod = 1 cfg.SystemSCConfig.StakingSystemSCConfig.UnBondPeriodInEpochs = 1 newNumNodes := cfg.SystemSCConfig.StakingSystemSCConfig.MaxNumberOfNodesForStake + 10 - configs.SetMaxNumberOfNodesInConfigs(cfg, newNumNodes, numOfShards) + configs.SetMaxNumberOfNodesInConfigs(cfg, uint32(newNumNodes), 0, numOfShards) }, }) require.Nil(t, err) diff --git a/node/chainSimulator/configs/configs.go b/node/chainSimulator/configs/configs.go index 731f8078eef..3334f470fa3 100644 --- a/node/chainSimulator/configs/configs.go +++ b/node/chainSimulator/configs/configs.go @@ -103,10 +103,10 @@ func CreateChainSimulatorConfigs(args ArgsChainSimulatorConfigs) (*ArgsConfigsSi configs.GeneralConfig.SmartContractsStorageForSCQuery.DB.Type = string(storageunit.MemoryDB) configs.GeneralConfig.SmartContractsStorageSimulate.DB.Type = string(storageunit.MemoryDB) - maxNumNodes := uint64((args.MinNodesPerShard+args.NumNodesWaitingListShard)*args.NumOfShards) + - uint64(args.MetaChainMinNodes+args.NumNodesWaitingListMeta) + eligibleNodes := args.MinNodesPerShard*args.NumOfShards + args.MetaChainMinNodes + waitingNodes := args.NumNodesWaitingListShard*args.NumOfShards + args.NumNodesWaitingListMeta - SetMaxNumberOfNodesInConfigs(configs, maxNumNodes, args.NumOfShards) + SetMaxNumberOfNodesInConfigs(configs, eligibleNodes, waitingNodes, args.NumOfShards) // set compatible trie configs configs.GeneralConfig.StateTriesConfig.SnapshotsEnabled = false @@ -141,17 +141,23 @@ func CreateChainSimulatorConfigs(args ArgsChainSimulatorConfigs) (*ArgsConfigsSi } // SetMaxNumberOfNodesInConfigs will correctly set the max number of nodes in configs -func SetMaxNumberOfNodesInConfigs(cfg *config.Configs, maxNumNodes uint64, numOfShards uint32) { - cfg.SystemSCConfig.StakingSystemSCConfig.MaxNumberOfNodesForStake = maxNumNodes +func SetMaxNumberOfNodesInConfigs(cfg *config.Configs, eligibleNodes uint32, waitingNodes uint32, numOfShards uint32) { + cfg.SystemSCConfig.StakingSystemSCConfig.MaxNumberOfNodesForStake = uint64(eligibleNodes + waitingNodes) numMaxNumNodesEnableEpochs := len(cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch) for idx := 0; idx < numMaxNumNodesEnableEpochs-1; idx++ { - cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[idx].MaxNumNodes = uint32(maxNumNodes) + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[idx].MaxNumNodes = eligibleNodes + waitingNodes } cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[numMaxNumNodesEnableEpochs-1].EpochEnable = cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch prevEntry := cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[numMaxNumNodesEnableEpochs-2] cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[numMaxNumNodesEnableEpochs-1].NodesToShufflePerShard = prevEntry.NodesToShufflePerShard - cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[numMaxNumNodesEnableEpochs-1].MaxNumNodes = prevEntry.MaxNumNodes - (numOfShards+1)*prevEntry.NodesToShufflePerShard + + stakingV4NumNodes := eligibleNodes + waitingNodes + if stakingV4NumNodes-(numOfShards+1)*prevEntry.NodesToShufflePerShard >= eligibleNodes { + // prevent the case in which we are decreasing the eligible number of nodes because we are working with 0 waiting list size + stakingV4NumNodes -= (numOfShards + 1) * prevEntry.NodesToShufflePerShard + } + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[numMaxNumNodesEnableEpochs-1].MaxNumNodes = stakingV4NumNodes } // SetQuickJailRatingConfig will set the rating config in a way that leads to rapid jailing of a node From 71d48d403494bbade60c7c4eb564eb5cb17ed310 Mon Sep 17 00:00:00 2001 From: Alexander Cristurean Date: Thu, 21 Mar 2024 09:59:26 +0200 Subject: [PATCH 128/503] fixed ports for nodes. --- scripts/docker-testnet/functions.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/docker-testnet/functions.sh b/scripts/docker-testnet/functions.sh index c075793030a..74d39bf71dc 100755 --- a/scripts/docker-testnet/functions.sh +++ b/scripts/docker-testnet/functions.sh @@ -54,7 +54,7 @@ startObservers() { KEY_INDEX=$((TOTAL_NODECOUNT - observerIdx - 1)) if [[ "$DOCKER_PUBLISH_PORTS" -gt 0 ]]; then - publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10000" + publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10200" fi docker run -d --name "observer${observerIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-shard${i}" \ @@ -79,7 +79,7 @@ startObservers() { KEY_INDEX=$((TOTAL_NODECOUNT - observerIdx - 1)) if [[ "$DOCKER_PUBLISH_PORTS" -gt 0 ]]; then - publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10000" + publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10200" fi docker run -d --name "observer${observerIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-metachain" \ @@ -107,7 +107,7 @@ startValidators() { for ((j = 0; j < SHARD_VALIDATORCOUNT; j++)); do if [[ "$DOCKER_PUBLISH_PORTS" -gt 0 ]]; then - publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10000" + publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10200" fi docker run -d --name "validator${validatorIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-shard${i}" \ @@ -128,7 +128,7 @@ startValidators() { for ((i = 0; i < META_VALIDATORCOUNT; i++)); do if [[ "$DOCKER_PUBLISH_PORTS" -gt 0 ]]; then - publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10000" + publishPortArgs="-p $DOCKER_PUBLISH_PORT_RANGE:10200" fi docker run -d --name "validator${validatorIdx}-${NETWORK_ADDRESS}.${IP_HOST_BYTE}-10200-metachain" \ From 8c50313934ecf13cd2fd9c20a20252e8801c278b Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 21 Mar 2024 17:39:12 +0200 Subject: [PATCH 129/503] updated deps after merge for rc/v1.7.next1 --- go.mod | 18 +++++++++--------- go.sum | 36 ++++++++++++++++++------------------ 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/go.mod b/go.mod index 86225522dcc..b81398f22e4 100644 --- a/go.mod +++ b/go.mod @@ -14,18 +14,18 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 - github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad - github.com/multiversx/mx-chain-core-go v1.2.19-0.20240222081523-011c96ab2548 + github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240321151517-2fffad77c605 + github.com/multiversx/mx-chain-core-go v1.2.19-0.20240321150532-5960a8922b18 github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 - github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a + github.com/multiversx/mx-chain-es-indexer-go v1.4.20-0.20240228094052-28a36809b9b8 github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 - github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240129144933-b1c0d642d7f8 - github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240305123516-2231c71162a2 - github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240307121727-b8d371971d9a - github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240308085208-3b5a4ab4dd34 - github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240308082903-132f9002736b - github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240308082831-f05004a05b35 + github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474 + github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240321152012-f18c2869d6b4 + github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240321153018-3e5a88ba7368 + github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240321152247-79521988c8e6 + github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240321152532-45da5eabdc38 + github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240321152756-16110ce9d968 github.com/pelletier/go-toml v1.9.3 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.14.0 diff --git a/go.sum b/go.sum index f12ab723392..52bca6ef1b6 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.13-0.20240126121117-627adccf10ad h1:izxTyKCxvT7z2mhXCWAZibSxwRVgLmq/kDovs4Nx/6Y= -github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad/go.mod h1:n4E8BWIV0g3AcNGe1gf+vcjUC8A2QCJ4ARQSbiUDGrI= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20240222081523-011c96ab2548 h1:WQoVgQG9YWiYM5Q3MmnbnxeoQkfHr63iFJZScFYsMxk= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20240222081523-011c96ab2548/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240321151517-2fffad77c605 h1:WYPdDmxL5rk9O6wUYVW4Fpw/QtwkWiIzFHeH2F5Zap4= +github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240321151517-2fffad77c605/go.mod h1:wUM/1NFfgeTjovQMaaXghynwXgOyoPchMquu2wnCHz8= +github.com/multiversx/mx-chain-core-go v1.2.19-0.20240321150532-5960a8922b18 h1:hytqre8g+NIHsq/Kxl/lwIykHna57Gv+E38tt4K5A9I= +github.com/multiversx/mx-chain-core-go v1.2.19-0.20240321150532-5960a8922b18/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 h1:beVIhs5ysylwNplQ/bZ0h5DoDlqKNWgpWE/NMHHNmAw= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479/go.mod h1:Ap6p7QZFtwPlb++OvCG+85BfuZ+bLP/JtQp6EwjWJsI= -github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a h1:mOMUhbsjTq7n5oAv4KkVnL67ngS0+wkqmkiv1XJfBIY= -github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a/go.mod h1:3aSGRJNvfUuPQkZUGHWuF11rPPxphsKGuAuIB+eD3is= +github.com/multiversx/mx-chain-es-indexer-go v1.4.20-0.20240228094052-28a36809b9b8 h1:z9ePQGALhPCs9Fv7cQsnsScbEq8KuOJ9xrJEEEOiHyI= +github.com/multiversx/mx-chain-es-indexer-go v1.4.20-0.20240228094052-28a36809b9b8/go.mod h1:3aSGRJNvfUuPQkZUGHWuF11rPPxphsKGuAuIB+eD3is= github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c h1:QIUOn8FgNRa5cir4BCWHZi/Qcr6Gg0eGNhns4+jy6+k= github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c/go.mod h1:fH/fR/GEBsDjPkBoZDVJMoYo2HhlA7++DP6QfITJ1N8= github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 h1:ydzN3f+Y7H0InXuxAcNUSyVc+omNYL8uYtLqVzqaaX4= github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157/go.mod h1:ndk45i9J9McuCJpTcgiaK4ocd0yhnBBCPrlFwO6GRcs= -github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240129144933-b1c0d642d7f8 h1:/EYv/HGX0OKbeNFt667J0yZRtuJiZH0lEK8YtobuH/c= -github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240129144933-b1c0d642d7f8/go.mod h1:zl1A6teNe39T8yhdZlkX3ckm5aLYrMIJJZ6Ord1E71M= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240305123516-2231c71162a2 h1:sBH1Zf5jdMqS+1LDfXBmsIdmol8CFloPzjDCtmBZGEc= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240305123516-2231c71162a2/go.mod h1:OUyhCFqZKqUk1uaPsenyPDwO1830SlHNDU7Q7b6CBVI= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240307121727-b8d371971d9a h1:QvIC6R5sf0koeSwAs+Ye8J+CjNkAdaosTMSNTVBB8sA= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240307121727-b8d371971d9a/go.mod h1:Xs0xFsPv+c1p8pwurLV7VBS7bEpIN/0jZrCwXVU26zw= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240308085208-3b5a4ab4dd34 h1:aLJhYiDBtWW4yjizhvQgTU00KfkK3oL3GnEh7pVUPRs= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240308085208-3b5a4ab4dd34/go.mod h1:8uugq3HUeDiE6G4AS3F8/B3zA1Pabzbl7SSD6Cebwz8= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240308082903-132f9002736b h1:iDDarqnGFZBXxqpaPWp8ePOqhG5G3DeAoopGgRLteu0= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240308082903-132f9002736b/go.mod h1:4uezxguZiX42kUaYMK/x46LLbgpYqn/iQXbcGM7zdM0= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240308082831-f05004a05b35 h1:yRfY/Mj1CXPoGd21F3y84cqBIKsktSgPuxz/5a7FA3w= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240308082831-f05004a05b35/go.mod h1:Nvanb5BZVhqnFFlWUtn7PQ/GIsl72zPVcMEw/ZvYiQA= +github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474 h1:x65Su8ojHwA+NICp9DrSVGLDDcAlW04DafkqCHY1QPE= +github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474/go.mod h1:hnc6H4D5Ge1haRAQ6QHTXhyh+CT2DRiNJ0U0HQYI3DY= +github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240321152012-f18c2869d6b4 h1:Xq8R5eRcZDTPYYK7boM2x71XRDifdtP+rgQQhvmJLbg= +github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240321152012-f18c2869d6b4/go.mod h1:JqhuZPrx9bAKagTefUXq9y2fhLdCJstnppq2JKAUvFI= +github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240321153018-3e5a88ba7368 h1:DP48O3jSAG6IgwJsCffORfFKPWRgbPRCzc0Xt00C/C0= +github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240321153018-3e5a88ba7368/go.mod h1:BTnxVk/6RUSwUr6iFgDMPWHIibVQBe5wsFO1v+sEFig= +github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240321152247-79521988c8e6 h1:7HqUo9YmpsfN/y9px6RmzREJm5O6ZzP9NqvFSrHTw24= +github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240321152247-79521988c8e6/go.mod h1:H2H/zoskiZC0lEokq9qMFVxRkB0RWVDPLjHbG/NrGUU= +github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240321152532-45da5eabdc38 h1:SAKjOByxXkZ5Sys5O4IkrrSGCKLoPvD+cCJJEvbev4w= +github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240321152532-45da5eabdc38/go.mod h1:3dhvJ5/SgEMKAaIYHAOzo3nmOmJik/DDXaQW21PUno4= +github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240321152756-16110ce9d968 h1:14A3e5rqaXXXOFGC0DjOWtGFiVLx20TNghsaja0u4E0= +github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240321152756-16110ce9d968/go.mod h1:XJt8jbyLtP1+pPSzQmHwQG45hH/qazz1H+Xk2wasfTs= 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 6d93fee1ff73f6c7910026010a8178e7cb9a4040 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 21 Mar 2024 18:28:10 +0200 Subject: [PATCH 130/503] fixed test failing on mac --- storage/factory/persisterFactory_test.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/storage/factory/persisterFactory_test.go b/storage/factory/persisterFactory_test.go index cb7e15b1e47..babf32f660d 100644 --- a/storage/factory/persisterFactory_test.go +++ b/storage/factory/persisterFactory_test.go @@ -214,18 +214,18 @@ func TestGetTmpFilePath(t *testing.T) { pathSeparator := "/" tmpDir := os.TempDir() - tmpBasePath := tmpDir + pathSeparator + tmpBasePath := path.Join(tmpDir, pathSeparator) - path, err := factory.GetTmpFilePath("aaaa/bbbb/cccc") + tmpPath, err := factory.GetTmpFilePath("aaaa/bbbb/cccc") require.Nil(t, err) - require.True(t, strings.Contains(path, tmpBasePath+"cccc")) + require.True(t, strings.Contains(tmpPath, path.Join(tmpBasePath, "cccc"))) - path, _ = factory.GetTmpFilePath("aaaa") - require.True(t, strings.Contains(path, tmpBasePath+"aaaa")) + tmpPath, _ = factory.GetTmpFilePath("aaaa") + require.True(t, strings.Contains(tmpPath, path.Join(tmpBasePath, "aaaa"))) - path, _ = factory.GetTmpFilePath("") - require.True(t, strings.Contains(path, tmpBasePath+"")) + tmpPath, _ = factory.GetTmpFilePath("") + require.True(t, strings.Contains(tmpPath, path.Join(tmpBasePath, ""))) - path, _ = factory.GetTmpFilePath("/") - require.True(t, strings.Contains(path, tmpBasePath+"")) + tmpPath, _ = factory.GetTmpFilePath("/") + require.True(t, strings.Contains(tmpPath, path.Join(tmpBasePath, ""))) } From 2a34318133579fb6cfdb74a74bcb3821e129eba3 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 22 Mar 2024 13:46:26 +0200 Subject: [PATCH 131/503] updated mx-chain-core-go for feat/relayedV3 --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index b81398f22e4..50d869b03dd 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240321151517-2fffad77c605 - github.com/multiversx/mx-chain-core-go v1.2.19-0.20240321150532-5960a8922b18 + github.com/multiversx/mx-chain-core-go v1.2.19-0.20240322114245-95b7c293302d github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 github.com/multiversx/mx-chain-es-indexer-go v1.4.20-0.20240228094052-28a36809b9b8 github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c diff --git a/go.sum b/go.sum index 52bca6ef1b6..8e22702d4e9 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240321151517-2fffad77c605 h1:WYPdDmxL5rk9O6wUYVW4Fpw/QtwkWiIzFHeH2F5Zap4= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240321151517-2fffad77c605/go.mod h1:wUM/1NFfgeTjovQMaaXghynwXgOyoPchMquu2wnCHz8= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20240321150532-5960a8922b18 h1:hytqre8g+NIHsq/Kxl/lwIykHna57Gv+E38tt4K5A9I= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20240321150532-5960a8922b18/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.19-0.20240322114245-95b7c293302d h1:qTIgNTQ+8+hMXI9CN8yAzrkpro8gKvmdrsXNpTz2mIs= +github.com/multiversx/mx-chain-core-go v1.2.19-0.20240322114245-95b7c293302d/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 h1:beVIhs5ysylwNplQ/bZ0h5DoDlqKNWgpWE/NMHHNmAw= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479/go.mod h1:Ap6p7QZFtwPlb++OvCG+85BfuZ+bLP/JtQp6EwjWJsI= github.com/multiversx/mx-chain-es-indexer-go v1.4.20-0.20240228094052-28a36809b9b8 h1:z9ePQGALhPCs9Fv7cQsnsScbEq8KuOJ9xrJEEEOiHyI= From e7dac66bf179e3f4669970c9336bd9a9767c5426 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Fri, 22 Mar 2024 14:35:17 +0200 Subject: [PATCH 132/503] - exposed function ForceResetValidatorStatisticsCache in the chain simulator --- integrationTests/chainSimulator/interface.go | 1 + .../chainSimulator/staking/delegation_test.go | 2 +- integrationTests/chainSimulator/staking/jail_test.go | 2 +- .../chainSimulator/staking/simpleStake_test.go | 4 ++-- .../chainSimulator/staking/stakeAndUnStake_test.go | 4 ++-- node/chainSimulator/chainSimulator.go | 10 ++++++++++ 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/integrationTests/chainSimulator/interface.go b/integrationTests/chainSimulator/interface.go index 6d66b9d62c0..eff1aac7874 100644 --- a/integrationTests/chainSimulator/interface.go +++ b/integrationTests/chainSimulator/interface.go @@ -21,4 +21,5 @@ type ChainSimulator interface { GenerateAndMintWalletAddress(targetShardID uint32, value *big.Int) (dtos.WalletAddress, error) GetInitialWalletKeys() *dtos.InitialWalletKeys GetAccount(address dtos.WalletAddress) (api.AccountResponse, error) + ForceResetValidatorStatisticsCache() error } diff --git a/integrationTests/chainSimulator/staking/delegation_test.go b/integrationTests/chainSimulator/staking/delegation_test.go index 1ed12f29fd9..baa138f4430 100644 --- a/integrationTests/chainSimulator/staking/delegation_test.go +++ b/integrationTests/chainSimulator/staking/delegation_test.go @@ -277,7 +277,7 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi delegationAddressBech32 := metachainNode.GetCoreComponents().AddressPubKeyConverter().SilentEncode(delegationAddress, log) log.Info("generated delegation address", "address", delegationAddressBech32) - err = metachainNode.GetProcessComponents().ValidatorsProvider().ForceUpdate() + err = cs.ForceResetValidatorStatisticsCache() require.Nil(t, err) testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], addedStakedValue, 1) diff --git a/integrationTests/chainSimulator/staking/jail_test.go b/integrationTests/chainSimulator/staking/jail_test.go index 2802ff94e8a..4251ece6bf4 100644 --- a/integrationTests/chainSimulator/staking/jail_test.go +++ b/integrationTests/chainSimulator/staking/jail_test.go @@ -248,7 +248,7 @@ func TestChainSimulator_FromQueueToAuctionList(t *testing.T) { } func checkValidatorStatus(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, blsKey string, expectedStatus string) { - err := cs.GetNodeHandler(core.MetachainShardId).GetProcessComponents().ValidatorsProvider().ForceUpdate() + err := cs.ForceResetValidatorStatisticsCache() require.Nil(t, err) validatorsStatistics, err := cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ValidatorStatisticsApi() diff --git a/integrationTests/chainSimulator/staking/simpleStake_test.go b/integrationTests/chainSimulator/staking/simpleStake_test.go index f738b2c7ff6..83039942189 100644 --- a/integrationTests/chainSimulator/staking/simpleStake_test.go +++ b/integrationTests/chainSimulator/staking/simpleStake_test.go @@ -212,7 +212,7 @@ func TestChainSimulator_StakingV4Step2APICalls(t *testing.T) { require.Nil(t, err) // In step 1, only the previously staked node should be in auction list - err = metachainNode.GetProcessComponents().ValidatorsProvider().ForceUpdate() + err = cs.ForceResetValidatorStatisticsCache() require.Nil(t, err) auctionList, err := metachainNode.GetProcessComponents().ValidatorsProvider().GetAuctionList() require.Nil(t, err) @@ -229,7 +229,7 @@ func TestChainSimulator_StakingV4Step2APICalls(t *testing.T) { require.Nil(t, err) // after the re-stake process, the node should be in auction list - err = metachainNode.GetProcessComponents().ValidatorsProvider().ForceUpdate() + err = cs.ForceResetValidatorStatisticsCache() require.Nil(t, err) auctionList, err = metachainNode.GetProcessComponents().ValidatorsProvider().GetAuctionList() require.Nil(t, err) diff --git a/integrationTests/chainSimulator/staking/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stakeAndUnStake_test.go index 9ac5b86be20..0e91ef2a2c5 100644 --- a/integrationTests/chainSimulator/staking/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stakeAndUnStake_test.go @@ -152,7 +152,7 @@ func TestChainSimulator_AddValidatorKey(t *testing.T) { require.Nil(t, err) metachainNode := cs.GetNodeHandler(core.MetachainShardId) - err = metachainNode.GetProcessComponents().ValidatorsProvider().ForceUpdate() + err = cs.ForceResetValidatorStatisticsCache() require.Nil(t, err) validatorStatistics, err := metachainNode.GetFacadeHandler().ValidatorStatisticsApi() require.Nil(t, err) @@ -264,7 +264,7 @@ func TestChainSimulator_AddANewValidatorAfterStakingV4(t *testing.T) { require.Nil(t, err) metachainNode := cs.GetNodeHandler(core.MetachainShardId) - err = metachainNode.GetProcessComponents().ValidatorsProvider().ForceUpdate() + err = cs.ForceResetValidatorStatisticsCache() require.Nil(t, err) results, err := metachainNode.GetFacadeHandler().AuctionListApi() require.Nil(t, err) diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index a5292d72e40..8bffcb6c63a 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -212,6 +212,16 @@ func (s *simulator) GenerateBlocksUntilEpochIsReached(targetEpoch int32) error { return fmt.Errorf("exceeded rounds to generate blocks") } +// ForceResetValidatorStatisticsCache will force the reset of the cache used for the validators statistics endpoint +func (s *simulator) ForceResetValidatorStatisticsCache() error { + metachainNode := s.GetNodeHandler(core.MetachainShardId) + if check.IfNil(metachainNode) { + return errNilMetachainNode + } + + return metachainNode.GetProcessComponents().ValidatorsProvider().ForceUpdate() +} + func (s *simulator) isTargetEpochReached(targetEpoch int32) (bool, error) { metachainNode := s.nodes[core.MetachainShardId] metachainEpoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetCurrentEpoch() From 2afa2568370fd7c818e561316f6596fca4d42d25 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 22 Mar 2024 15:10:12 +0200 Subject: [PATCH 133/503] updated txFee tests to use old values --- .../vm/txsFee/relayedScDeploy_test.go | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/integrationTests/vm/txsFee/relayedScDeploy_test.go b/integrationTests/vm/txsFee/relayedScDeploy_test.go index 1f0a049dc7c..bfd4b3851f1 100644 --- a/integrationTests/vm/txsFee/relayedScDeploy_test.go +++ b/integrationTests/vm/txsFee/relayedScDeploy_test.go @@ -34,7 +34,7 @@ func testRelayedScDeployShouldWork(relayedFixActivationEpoch uint32) func(t *tes senderNonce := uint64(0) senderBalance := big.NewInt(0) - gasLimit := uint64(1000) + gasLimit := uint64(2000) _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, senderBalance) _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(50000)) @@ -53,7 +53,7 @@ func testRelayedScDeployShouldWork(relayedFixActivationEpoch uint32) func(t *tes _, err = testContext.Accounts.Commit() require.Nil(t, err) - expectedBalanceRelayer := big.NewInt(28440) + expectedBalanceRelayer := big.NewInt(2530) vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) // check balance inner tx sender @@ -61,7 +61,7 @@ func testRelayedScDeployShouldWork(relayedFixActivationEpoch uint32) func(t *tes // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(21560), accumulatedFees) + require.Equal(t, big.NewInt(47470), accumulatedFees) } } @@ -70,11 +70,11 @@ func TestRelayedScDeployInvalidCodeShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - t.Run("before relayed fix", testRelayedScDeployInvalidCodeShouldConsumeGas(integrationTests.UnreachableEpoch)) - t.Run("after relayed fix", testRelayedScDeployInvalidCodeShouldConsumeGas(0)) + t.Run("before relayed fix", testRelayedScDeployInvalidCodeShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(17030), big.NewInt(32970))) + t.Run("after relayed fix", testRelayedScDeployInvalidCodeShouldConsumeGas(0, big.NewInt(8890), big.NewInt(41110))) } -func testRelayedScDeployInvalidCodeShouldConsumeGas(relayedFixActivationEpoch uint32) func(t *testing.T) { +func testRelayedScDeployInvalidCodeShouldConsumeGas(relayedFixActivationEpoch uint32, expectedBalance *big.Int, expectedAccumulatedFees *big.Int) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, @@ -87,7 +87,7 @@ func testRelayedScDeployInvalidCodeShouldConsumeGas(relayedFixActivationEpoch ui senderNonce := uint64(0) senderBalance := big.NewInt(0) - gasLimit := uint64(574) + gasLimit := uint64(500) _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, senderBalance) _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(50000)) @@ -107,15 +107,14 @@ func testRelayedScDeployInvalidCodeShouldConsumeGas(relayedFixActivationEpoch ui _, err = testContext.Accounts.Commit() require.Nil(t, err) - expectedBalanceRelayer := big.NewInt(31090) - vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) + vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalance) // check balance inner tx sender vm.TestAccount(t, testContext.Accounts, sndAddr, 1, big.NewInt(0)) // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(18910), accumulatedFees) + require.Equal(t, expectedAccumulatedFees, accumulatedFees) } } @@ -124,8 +123,8 @@ func TestRelayedScDeployInsufficientGasLimitShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - t.Run("before relayed fix", testRelayedScDeployInsufficientGasLimitShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(31930), big.NewInt(18070))) - t.Run("after relayed fix", testRelayedScDeployInsufficientGasLimitShouldConsumeGas(0, big.NewInt(31240), big.NewInt(18760))) + t.Run("before relayed fix", testRelayedScDeployInsufficientGasLimitShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(17130), big.NewInt(32870))) + t.Run("after relayed fix", testRelayedScDeployInsufficientGasLimitShouldConsumeGas(0, big.NewInt(9040), big.NewInt(40960))) } func testRelayedScDeployInsufficientGasLimitShouldConsumeGas(relayedFixActivationEpoch uint32, expectedBalance *big.Int, expectedAccumulatedFees *big.Int) func(t *testing.T) { @@ -175,11 +174,11 @@ func TestRelayedScDeployOutOfGasShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - t.Run("before relayed fix", testRelayedScDeployOutOfGasShouldConsumeGas(integrationTests.UnreachableEpoch)) - t.Run("after relayed fix", testRelayedScDeployOutOfGasShouldConsumeGas(0)) + t.Run("before relayed fix", testRelayedScDeployOutOfGasShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(16430), big.NewInt(33570))) + t.Run("after relayed fix", testRelayedScDeployOutOfGasShouldConsumeGas(0, big.NewInt(9040), big.NewInt(40960))) } -func testRelayedScDeployOutOfGasShouldConsumeGas(relayedFixActivationEpoch uint32) func(t *testing.T) { +func testRelayedScDeployOutOfGasShouldConsumeGas(relayedFixActivationEpoch uint32, expectedBalance *big.Int, expectedAccumulatedFees *big.Int) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, @@ -211,14 +210,13 @@ func testRelayedScDeployOutOfGasShouldConsumeGas(relayedFixActivationEpoch uint3 _, err = testContext.Accounts.Commit() require.Nil(t, err) - expectedBalanceRelayer := big.NewInt(31230) - vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) + vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalance) // check balance inner tx sender vm.TestAccount(t, testContext.Accounts, sndAddr, 1, big.NewInt(0)) // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(18770), accumulatedFees) + require.Equal(t, expectedAccumulatedFees, accumulatedFees) } } From f81d1df14b0b4a1f840d368b210849c65ece925c Mon Sep 17 00:00:00 2001 From: Iuga Mihai Date: Fri, 22 Mar 2024 16:19:42 +0200 Subject: [PATCH 134/503] enable host driver chain simulator --- .../components/statusComponents.go | 41 ++++++++++++++++--- .../components/statusComponents_test.go | 17 ++++---- .../components/testOnlyProcessingNode.go | 1 + 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/node/chainSimulator/components/statusComponents.go b/node/chainSimulator/components/statusComponents.go index 65f9dbb7667..67738499216 100644 --- a/node/chainSimulator/components/statusComponents.go +++ b/node/chainSimulator/components/statusComponents.go @@ -9,12 +9,14 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/appStatusPolling" "github.com/multiversx/mx-chain-core-go/core/check" - outportCfg "github.com/multiversx/mx-chain-core-go/data/outport" + factoryMarshalizer "github.com/multiversx/mx-chain-core-go/marshal/factory" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/statistics" + "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/integrationTests/mock" "github.com/multiversx/mx-chain-go/outport" + "github.com/multiversx/mx-chain-go/outport/factory" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/testscommon" ) @@ -32,7 +34,7 @@ type statusComponentsHolder struct { } // CreateStatusComponents will create a new instance of status components holder -func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandler, statusPollingIntervalSec int) (*statusComponentsHolder, error) { +func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandler, statusPollingIntervalSec int, external config.ExternalConfig) (*statusComponentsHolder, error) { if check.IfNil(appStatusHandler) { return nil, core.ErrNilAppStatusHandler } @@ -44,9 +46,16 @@ func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandl statusPollingIntervalSec: statusPollingIntervalSec, } - // TODO add drivers to index data - instance.outportHandler, err = outport.NewOutport(100*time.Millisecond, outportCfg.OutportConfig{ - ShardID: shardID, + hostDriverArgs, err := makeHostDriversArgs(external) + if err != nil { + return nil, err + } + instance.outportHandler, err = factory.CreateOutport(&factory.OutportFactoryArgs{ + IsImportDB: false, + ShardID: shardID, + RetrialInterval: 100 * time.Millisecond, + HostDriversArgs: hostDriverArgs, + EventNotifierFactoryArgs: &factory.EventNotifierFactoryArgs{}, }) if err != nil { return nil, err @@ -59,6 +68,28 @@ func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandl return instance, nil } +func makeHostDriversArgs(external config.ExternalConfig) ([]factory.ArgsHostDriverFactory, error) { + argsHostDriverFactorySlice := make([]factory.ArgsHostDriverFactory, 0, len(external.HostDriversConfig)) + for idx := 0; idx < len(external.HostDriversConfig); idx++ { + hostConfig := external.HostDriversConfig[idx] + if !hostConfig.Enabled { + continue + } + + marshaller, err := factoryMarshalizer.NewMarshalizer(hostConfig.MarshallerType) + if err != nil { + return argsHostDriverFactorySlice, err + } + + argsHostDriverFactorySlice = append(argsHostDriverFactorySlice, factory.ArgsHostDriverFactory{ + Marshaller: marshaller, + HostConfig: hostConfig, + }) + } + + return argsHostDriverFactorySlice, nil +} + // OutportHandler will return the outport handler func (s *statusComponentsHolder) OutportHandler() outport.OutportHandler { return s.outportHandler diff --git a/node/chainSimulator/components/statusComponents_test.go b/node/chainSimulator/components/statusComponents_test.go index 0e83e435003..b6e2e296fbb 100644 --- a/node/chainSimulator/components/statusComponents_test.go +++ b/node/chainSimulator/components/statusComponents_test.go @@ -7,6 +7,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/atomic" "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/config" mxErrors "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/integrationTests/mock" "github.com/multiversx/mx-chain-go/process" @@ -20,7 +21,7 @@ func TestCreateStatusComponents(t *testing.T) { t.Run("should work", func(t *testing.T) { t.Parallel() - comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5) + comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{}) require.NoError(t, err) require.NotNil(t, comp) @@ -30,7 +31,7 @@ func TestCreateStatusComponents(t *testing.T) { t.Run("nil app status handler should error", func(t *testing.T) { t.Parallel() - comp, err := CreateStatusComponents(0, nil, 5) + comp, err := CreateStatusComponents(0, nil, 5, config.ExternalConfig{}) require.Equal(t, core.ErrNilAppStatusHandler, err) require.Nil(t, comp) }) @@ -42,7 +43,7 @@ func TestStatusComponentsHolder_IsInterfaceNil(t *testing.T) { var comp *statusComponentsHolder require.True(t, comp.IsInterfaceNil()) - comp, _ = CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5) + comp, _ = CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{}) require.False(t, comp.IsInterfaceNil()) require.Nil(t, comp.Close()) } @@ -50,7 +51,7 @@ func TestStatusComponentsHolder_IsInterfaceNil(t *testing.T) { func TestStatusComponentsHolder_Getters(t *testing.T) { t.Parallel() - comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5) + comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{}) require.NoError(t, err) require.NotNil(t, comp.OutportHandler()) @@ -64,7 +65,7 @@ func TestStatusComponentsHolder_Getters(t *testing.T) { func TestStatusComponentsHolder_SetForkDetector(t *testing.T) { t.Parallel() - comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5) + comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{}) require.NoError(t, err) err = comp.SetForkDetector(nil) @@ -82,7 +83,7 @@ func TestStatusComponentsHolder_StartPolling(t *testing.T) { t.Run("nil fork detector should error", func(t *testing.T) { t.Parallel() - comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5) + comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{}) require.NoError(t, err) err = comp.StartPolling() @@ -91,7 +92,7 @@ func TestStatusComponentsHolder_StartPolling(t *testing.T) { t.Run("NewAppStatusPolling failure should error", func(t *testing.T) { t.Parallel() - comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 0) + comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 0, config.ExternalConfig{}) require.NoError(t, err) err = comp.SetForkDetector(&mock.ForkDetectorStub{}) @@ -113,7 +114,7 @@ func TestStatusComponentsHolder_StartPolling(t *testing.T) { wasSetUInt64ValueCalled.SetValue(true) }, } - comp, err := CreateStatusComponents(0, appStatusHandler, providedStatusPollingIntervalSec) + comp, err := CreateStatusComponents(0, appStatusHandler, providedStatusPollingIntervalSec, config.ExternalConfig{}) require.NoError(t, err) forkDetector := &mock.ForkDetectorStub{ diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index 07c8561c73f..ff1466ffba8 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -146,6 +146,7 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces selfShardID, instance.StatusCoreComponents.AppStatusHandler(), args.Configs.GeneralConfig.GeneralSettings.StatusPollingIntervalSec, + *args.Configs.ExternalConfig, ) if err != nil { return nil, err From 3994d89ba5c5c91df92b9750a4159103180e084d Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 27 Mar 2024 13:48:35 +0200 Subject: [PATCH 135/503] updated dependencies --- go.mod | 24 ++++++++++++------------ go.sum | 48 ++++++++++++++++++++++++------------------------ 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/go.mod b/go.mod index 86225522dcc..d441c0f17eb 100644 --- a/go.mod +++ b/go.mod @@ -14,18 +14,18 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 - github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad - github.com/multiversx/mx-chain-core-go v1.2.19-0.20240222081523-011c96ab2548 - github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 - github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a - github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c - github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 - github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240129144933-b1c0d642d7f8 - github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240305123516-2231c71162a2 - github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240307121727-b8d371971d9a - github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240308085208-3b5a4ab4dd34 - github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240308082903-132f9002736b - github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240308082831-f05004a05b35 + github.com/multiversx/mx-chain-communication-go v1.0.13 + github.com/multiversx/mx-chain-core-go v1.2.19 + github.com/multiversx/mx-chain-crypto-go v1.2.10 + github.com/multiversx/mx-chain-es-indexer-go v1.4.19 + github.com/multiversx/mx-chain-logger-go v1.0.14 + github.com/multiversx/mx-chain-scenario-go v1.4.3 + github.com/multiversx/mx-chain-storage-go v1.0.15 + github.com/multiversx/mx-chain-vm-common-go v1.5.12 + github.com/multiversx/mx-chain-vm-go v1.5.28 + github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66 + github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67 + github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96 github.com/pelletier/go-toml v1.9.3 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.14.0 diff --git a/go.sum b/go.sum index f12ab723392..8089a226704 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.13-0.20240126121117-627adccf10ad h1:izxTyKCxvT7z2mhXCWAZibSxwRVgLmq/kDovs4Nx/6Y= -github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240126121117-627adccf10ad/go.mod h1:n4E8BWIV0g3AcNGe1gf+vcjUC8A2QCJ4ARQSbiUDGrI= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20240222081523-011c96ab2548 h1:WQoVgQG9YWiYM5Q3MmnbnxeoQkfHr63iFJZScFYsMxk= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20240222081523-011c96ab2548/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= -github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 h1:beVIhs5ysylwNplQ/bZ0h5DoDlqKNWgpWE/NMHHNmAw= -github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479/go.mod h1:Ap6p7QZFtwPlb++OvCG+85BfuZ+bLP/JtQp6EwjWJsI= -github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a h1:mOMUhbsjTq7n5oAv4KkVnL67ngS0+wkqmkiv1XJfBIY= -github.com/multiversx/mx-chain-es-indexer-go v1.4.19-0.20240129150813-a772c480d33a/go.mod h1:3aSGRJNvfUuPQkZUGHWuF11rPPxphsKGuAuIB+eD3is= -github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c h1:QIUOn8FgNRa5cir4BCWHZi/Qcr6Gg0eGNhns4+jy6+k= -github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c/go.mod h1:fH/fR/GEBsDjPkBoZDVJMoYo2HhlA7++DP6QfITJ1N8= -github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 h1:ydzN3f+Y7H0InXuxAcNUSyVc+omNYL8uYtLqVzqaaX4= -github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157/go.mod h1:ndk45i9J9McuCJpTcgiaK4ocd0yhnBBCPrlFwO6GRcs= -github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240129144933-b1c0d642d7f8 h1:/EYv/HGX0OKbeNFt667J0yZRtuJiZH0lEK8YtobuH/c= -github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240129144933-b1c0d642d7f8/go.mod h1:zl1A6teNe39T8yhdZlkX3ckm5aLYrMIJJZ6Ord1E71M= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240305123516-2231c71162a2 h1:sBH1Zf5jdMqS+1LDfXBmsIdmol8CFloPzjDCtmBZGEc= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240305123516-2231c71162a2/go.mod h1:OUyhCFqZKqUk1uaPsenyPDwO1830SlHNDU7Q7b6CBVI= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240307121727-b8d371971d9a h1:QvIC6R5sf0koeSwAs+Ye8J+CjNkAdaosTMSNTVBB8sA= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240307121727-b8d371971d9a/go.mod h1:Xs0xFsPv+c1p8pwurLV7VBS7bEpIN/0jZrCwXVU26zw= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240308085208-3b5a4ab4dd34 h1:aLJhYiDBtWW4yjizhvQgTU00KfkK3oL3GnEh7pVUPRs= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240308085208-3b5a4ab4dd34/go.mod h1:8uugq3HUeDiE6G4AS3F8/B3zA1Pabzbl7SSD6Cebwz8= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240308082903-132f9002736b h1:iDDarqnGFZBXxqpaPWp8ePOqhG5G3DeAoopGgRLteu0= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240308082903-132f9002736b/go.mod h1:4uezxguZiX42kUaYMK/x46LLbgpYqn/iQXbcGM7zdM0= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240308082831-f05004a05b35 h1:yRfY/Mj1CXPoGd21F3y84cqBIKsktSgPuxz/5a7FA3w= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240308082831-f05004a05b35/go.mod h1:Nvanb5BZVhqnFFlWUtn7PQ/GIsl72zPVcMEw/ZvYiQA= +github.com/multiversx/mx-chain-communication-go v1.0.13 h1:Iou1fB3VAZMl9ghFULHjsAa3m+voKrrW7ESviKI1QRQ= +github.com/multiversx/mx-chain-communication-go v1.0.13/go.mod h1:WY3tQP1Vrb822ZsuQU+ICd8+rgC7Op6eKb0I00Sav8k= +github.com/multiversx/mx-chain-core-go v1.2.19 h1:2BaVHkB0tro3cjs5ay2pmLup1loCV0e1p9jV5QW0xqc= +github.com/multiversx/mx-chain-core-go v1.2.19/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-crypto-go v1.2.10 h1:wFfTPh0kmfoMDu4iKVRWOB5N6jJwMmgxyymqoA/U5CY= +github.com/multiversx/mx-chain-crypto-go v1.2.10/go.mod h1:Ap6p7QZFtwPlb++OvCG+85BfuZ+bLP/JtQp6EwjWJsI= +github.com/multiversx/mx-chain-es-indexer-go v1.4.19 h1:nuyqW5fsm22Wl0lNZNW1WviGGpAZhdgaKwi9XcTJisA= +github.com/multiversx/mx-chain-es-indexer-go v1.4.19/go.mod h1:maraR9xXcfi0lLifhGMc+DVHpw1IOPX/c89HVckF1Js= +github.com/multiversx/mx-chain-logger-go v1.0.14 h1:PRMpAvXE7Nec2d//QNmbYfKVHMomOKmcN4UXurQWX9o= +github.com/multiversx/mx-chain-logger-go v1.0.14/go.mod h1:bDfHSdwqIimn7Gp8w+SH5KlDuGzJ//nlyEANAaTSc3o= +github.com/multiversx/mx-chain-scenario-go v1.4.3 h1:9xeVB8TOsolXS4YEr1CZ/VZr5Qk0X+nde8nRGnxJICo= +github.com/multiversx/mx-chain-scenario-go v1.4.3/go.mod h1:Bd7/Xs3mWM6pX/REHK5dfpf3MUfjMZ7li09cfCxg2ac= +github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdReD/tKBJj10JbxXvaE= +github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= +github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= +github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= +github.com/multiversx/mx-chain-vm-go v1.5.28 h1:iJ8aUF1GZ6KSfvwogOpck+dfAywn+nL3n2B0yzK4nis= +github.com/multiversx/mx-chain-vm-go v1.5.28/go.mod h1:5yiy54xE54u6jYOn7yLfgYtwl9oYf+WZDpCPi7/P7SI= +github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66 h1:Of6I3lWp0P0F5hmw3aqvtgqFK5N9yjqdAuncM2aM1kg= +github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66/go.mod h1:YSB5/GnMklBPGBdk4bMTGD0DN1sPPUybE1sFCyaMVN8= +github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67 h1:A8uVD0KqaVUISws7eqb6u3VGe1keMuZtOXAb+zwx/+0= +github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67/go.mod h1:/qrbL58Jb/hbN8uyf9a4DVjC36lEfkzroI5MiSPPDSY= +github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96 h1:h+s8CMizwP1C99+oveNllzDsqjtI2LTzdfMOfs4q5yw= +github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96/go.mod h1:QiERt54tiyMlECVbHXyB+22aSOIJyseedjJdnufRPA8= 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 720648adb135f0bb0e212ea52b279f0e7511d4a7 Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 27 Mar 2024 14:01:39 +0200 Subject: [PATCH 136/503] fix test processor node --- node/chainSimulator/components/testOnlyProcessingNode.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index ff1466ffba8..e08f4fc1367 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -285,6 +285,14 @@ func (node *testOnlyProcessingNode) createNodesCoordinator(pref config.Preferenc return err } + shardID := node.BootstrapComponentsHolder.ShardCoordinator().SelfId() + shardIDStr := fmt.Sprintf("%d", shardID) + if shardID == core.MetachainShardId { + shardIDStr = "metachain" + } + + pref.DestinationShardAsObserver = shardIDStr + node.NodesCoordinator, err = bootstrapComp.CreateNodesCoordinator( nodesShufflerOut, node.CoreComponentsHolder.GenesisNodesSetup(), From 600a1bce9eb3577ddee0255ff3553add652a3902 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 27 Mar 2024 14:26:52 +0200 Subject: [PATCH 137/503] updated dependencies 2 --- go.mod | 12 ++++++------ go.sum | 24 ++++++++++++------------ 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index d441c0f17eb..c8c982dc127 100644 --- a/go.mod +++ b/go.mod @@ -14,18 +14,18 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 - github.com/multiversx/mx-chain-communication-go v1.0.13 + github.com/multiversx/mx-chain-communication-go v1.0.14 github.com/multiversx/mx-chain-core-go v1.2.19 - github.com/multiversx/mx-chain-crypto-go v1.2.10 + github.com/multiversx/mx-chain-crypto-go v1.2.11 github.com/multiversx/mx-chain-es-indexer-go v1.4.19 github.com/multiversx/mx-chain-logger-go v1.0.14 github.com/multiversx/mx-chain-scenario-go v1.4.3 github.com/multiversx/mx-chain-storage-go v1.0.15 github.com/multiversx/mx-chain-vm-common-go v1.5.12 - github.com/multiversx/mx-chain-vm-go v1.5.28 - github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66 - github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67 - github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96 + github.com/multiversx/mx-chain-vm-go v1.5.29 + github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 + github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 + github.com/multiversx/mx-chain-vm-v1_4-go v1.4.97 github.com/pelletier/go-toml v1.9.3 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.14.0 diff --git a/go.sum b/go.sum index 8089a226704..9067c3ebf3b 100644 --- a/go.sum +++ b/go.sum @@ -385,12 +385,12 @@ 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.13 h1:Iou1fB3VAZMl9ghFULHjsAa3m+voKrrW7ESviKI1QRQ= -github.com/multiversx/mx-chain-communication-go v1.0.13/go.mod h1:WY3tQP1Vrb822ZsuQU+ICd8+rgC7Op6eKb0I00Sav8k= +github.com/multiversx/mx-chain-communication-go v1.0.14 h1:YhAUDjBBpc5h5W0A7LHLXUMIMeCgwgGvkqfAPbFqsno= +github.com/multiversx/mx-chain-communication-go v1.0.14/go.mod h1:qYCqgk0h+YpcTA84jHIpCBy6UShRwmXzHSCcdfwNrkw= github.com/multiversx/mx-chain-core-go v1.2.19 h1:2BaVHkB0tro3cjs5ay2pmLup1loCV0e1p9jV5QW0xqc= github.com/multiversx/mx-chain-core-go v1.2.19/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= -github.com/multiversx/mx-chain-crypto-go v1.2.10 h1:wFfTPh0kmfoMDu4iKVRWOB5N6jJwMmgxyymqoA/U5CY= -github.com/multiversx/mx-chain-crypto-go v1.2.10/go.mod h1:Ap6p7QZFtwPlb++OvCG+85BfuZ+bLP/JtQp6EwjWJsI= +github.com/multiversx/mx-chain-crypto-go v1.2.11 h1:MNPJoiTJA5/tedYrI0N22OorbsKDESWG0SF8MCJwcJI= +github.com/multiversx/mx-chain-crypto-go v1.2.11/go.mod h1:pcZutPdfLiAFytzCU3LxU3s8cXkvpNqquyitFSfoF3o= github.com/multiversx/mx-chain-es-indexer-go v1.4.19 h1:nuyqW5fsm22Wl0lNZNW1WviGGpAZhdgaKwi9XcTJisA= github.com/multiversx/mx-chain-es-indexer-go v1.4.19/go.mod h1:maraR9xXcfi0lLifhGMc+DVHpw1IOPX/c89HVckF1Js= github.com/multiversx/mx-chain-logger-go v1.0.14 h1:PRMpAvXE7Nec2d//QNmbYfKVHMomOKmcN4UXurQWX9o= @@ -401,14 +401,14 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go v1.5.28 h1:iJ8aUF1GZ6KSfvwogOpck+dfAywn+nL3n2B0yzK4nis= -github.com/multiversx/mx-chain-vm-go v1.5.28/go.mod h1:5yiy54xE54u6jYOn7yLfgYtwl9oYf+WZDpCPi7/P7SI= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66 h1:Of6I3lWp0P0F5hmw3aqvtgqFK5N9yjqdAuncM2aM1kg= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66/go.mod h1:YSB5/GnMklBPGBdk4bMTGD0DN1sPPUybE1sFCyaMVN8= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67 h1:A8uVD0KqaVUISws7eqb6u3VGe1keMuZtOXAb+zwx/+0= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67/go.mod h1:/qrbL58Jb/hbN8uyf9a4DVjC36lEfkzroI5MiSPPDSY= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96 h1:h+s8CMizwP1C99+oveNllzDsqjtI2LTzdfMOfs4q5yw= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96/go.mod h1:QiERt54tiyMlECVbHXyB+22aSOIJyseedjJdnufRPA8= +github.com/multiversx/mx-chain-vm-go v1.5.29 h1:Ovz5/WM9KbD3YKRafdKI4RwtsNN36AGeNw81LZAhE70= +github.com/multiversx/mx-chain-vm-go v1.5.29/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= +github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= +github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= +github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68/go.mod h1:sIXRCenIR6FJtr3X/gDc60N6+v99Ai4hDsn6R5TKGnk= +github.com/multiversx/mx-chain-vm-v1_4-go v1.4.97 h1:fbYYqollxbIArcrC161Z9Qh5yJGW0Ax60m83Gz8+H1w= +github.com/multiversx/mx-chain-vm-v1_4-go v1.4.97/go.mod h1:56WJQio8SzOt3vWibaNkuGpqLlmTOGUSJqs3wMK69zw= 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 99ac996965c56874c913c001d5d929e0e959d63d Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 27 Mar 2024 15:40:46 +0200 Subject: [PATCH 138/503] updated indexer --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c8c982dc127..aafbc51ec02 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/multiversx/mx-chain-communication-go v1.0.14 github.com/multiversx/mx-chain-core-go v1.2.19 github.com/multiversx/mx-chain-crypto-go v1.2.11 - github.com/multiversx/mx-chain-es-indexer-go v1.4.19 + github.com/multiversx/mx-chain-es-indexer-go v1.4.21 github.com/multiversx/mx-chain-logger-go v1.0.14 github.com/multiversx/mx-chain-scenario-go v1.4.3 github.com/multiversx/mx-chain-storage-go v1.0.15 diff --git a/go.sum b/go.sum index 9067c3ebf3b..09c6f9ea503 100644 --- a/go.sum +++ b/go.sum @@ -391,8 +391,8 @@ github.com/multiversx/mx-chain-core-go v1.2.19 h1:2BaVHkB0tro3cjs5ay2pmLup1loCV0 github.com/multiversx/mx-chain-core-go v1.2.19/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.11 h1:MNPJoiTJA5/tedYrI0N22OorbsKDESWG0SF8MCJwcJI= github.com/multiversx/mx-chain-crypto-go v1.2.11/go.mod h1:pcZutPdfLiAFytzCU3LxU3s8cXkvpNqquyitFSfoF3o= -github.com/multiversx/mx-chain-es-indexer-go v1.4.19 h1:nuyqW5fsm22Wl0lNZNW1WviGGpAZhdgaKwi9XcTJisA= -github.com/multiversx/mx-chain-es-indexer-go v1.4.19/go.mod h1:maraR9xXcfi0lLifhGMc+DVHpw1IOPX/c89HVckF1Js= +github.com/multiversx/mx-chain-es-indexer-go v1.4.21 h1:rzxXCkgOsqj67GRYtqzKuf9XgHwnZLTZhU90Ck3VbrE= +github.com/multiversx/mx-chain-es-indexer-go v1.4.21/go.mod h1:V9xxOBkfV7GjN4K5SODaOetoGVpQm4snibMVPCjL0Kk= github.com/multiversx/mx-chain-logger-go v1.0.14 h1:PRMpAvXE7Nec2d//QNmbYfKVHMomOKmcN4UXurQWX9o= github.com/multiversx/mx-chain-logger-go v1.0.14/go.mod h1:bDfHSdwqIimn7Gp8w+SH5KlDuGzJ//nlyEANAaTSc3o= github.com/multiversx/mx-chain-scenario-go v1.4.3 h1:9xeVB8TOsolXS4YEr1CZ/VZr5Qk0X+nde8nRGnxJICo= From e06b2d577e92a7e0163d673db5519261938abffc Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 27 Mar 2024 16:23:47 +0200 Subject: [PATCH 139/503] small fix --- node/chainSimulator/components/statusComponents.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/chainSimulator/components/statusComponents.go b/node/chainSimulator/components/statusComponents.go index 67738499216..fa0027ca967 100644 --- a/node/chainSimulator/components/statusComponents.go +++ b/node/chainSimulator/components/statusComponents.go @@ -53,7 +53,7 @@ func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandl instance.outportHandler, err = factory.CreateOutport(&factory.OutportFactoryArgs{ IsImportDB: false, ShardID: shardID, - RetrialInterval: 100 * time.Millisecond, + RetrialInterval: time.Second, HostDriversArgs: hostDriverArgs, EventNotifierFactoryArgs: &factory.EventNotifierFactoryArgs{}, }) From 9ff5a6970be5438cb06aaf4a0db48b9a04e45582 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Thu, 28 Mar 2024 12:11:47 +0200 Subject: [PATCH 140/503] update go mod --- go.mod | 6 +++--- go.sum | 12 ++++++------ testscommon/esdtStorageHandlerStub.go | 6 +++--- vm/systemSmartContracts/esdt.go | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/go.mod b/go.mod index b81398f22e4..9de88775caa 100644 --- a/go.mod +++ b/go.mod @@ -15,14 +15,14 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240321151517-2fffad77c605 - github.com/multiversx/mx-chain-core-go v1.2.19-0.20240321150532-5960a8922b18 + github.com/multiversx/mx-chain-core-go v1.2.20-0.20240328090024-e88291d59ace github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 github.com/multiversx/mx-chain-es-indexer-go v1.4.20-0.20240228094052-28a36809b9b8 github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474 - github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240321152012-f18c2869d6b4 - github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240321153018-3e5a88ba7368 + github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240328091908-c46c76dac779 + github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240328092329-b5f2c7c059eb github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240321152247-79521988c8e6 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240321152532-45da5eabdc38 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240321152756-16110ce9d968 diff --git a/go.sum b/go.sum index 52bca6ef1b6..96da81e0efb 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240321151517-2fffad77c605 h1:WYPdDmxL5rk9O6wUYVW4Fpw/QtwkWiIzFHeH2F5Zap4= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240321151517-2fffad77c605/go.mod h1:wUM/1NFfgeTjovQMaaXghynwXgOyoPchMquu2wnCHz8= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20240321150532-5960a8922b18 h1:hytqre8g+NIHsq/Kxl/lwIykHna57Gv+E38tt4K5A9I= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20240321150532-5960a8922b18/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.20-0.20240328090024-e88291d59ace h1:sCXg0IlWmi0k5mC3BmUVCKVrxatGRQKGmqVS/froLDw= +github.com/multiversx/mx-chain-core-go v1.2.20-0.20240328090024-e88291d59ace/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 h1:beVIhs5ysylwNplQ/bZ0h5DoDlqKNWgpWE/NMHHNmAw= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479/go.mod h1:Ap6p7QZFtwPlb++OvCG+85BfuZ+bLP/JtQp6EwjWJsI= github.com/multiversx/mx-chain-es-indexer-go v1.4.20-0.20240228094052-28a36809b9b8 h1:z9ePQGALhPCs9Fv7cQsnsScbEq8KuOJ9xrJEEEOiHyI= @@ -399,10 +399,10 @@ github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157/go.mod h1:ndk45i9J9McuCJpTcgiaK4ocd0yhnBBCPrlFwO6GRcs= github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474 h1:x65Su8ojHwA+NICp9DrSVGLDDcAlW04DafkqCHY1QPE= github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474/go.mod h1:hnc6H4D5Ge1haRAQ6QHTXhyh+CT2DRiNJ0U0HQYI3DY= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240321152012-f18c2869d6b4 h1:Xq8R5eRcZDTPYYK7boM2x71XRDifdtP+rgQQhvmJLbg= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240321152012-f18c2869d6b4/go.mod h1:JqhuZPrx9bAKagTefUXq9y2fhLdCJstnppq2JKAUvFI= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240321153018-3e5a88ba7368 h1:DP48O3jSAG6IgwJsCffORfFKPWRgbPRCzc0Xt00C/C0= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240321153018-3e5a88ba7368/go.mod h1:BTnxVk/6RUSwUr6iFgDMPWHIibVQBe5wsFO1v+sEFig= +github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240328091908-c46c76dac779 h1:FSgAtNcml8kWdIEn8MxCfPkZ8ZE/wIFNKI5TZLEfcT0= +github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240328091908-c46c76dac779/go.mod h1:G6daPJC6bFsvAw45RPMCRi2rP+8LjFxa8G+3alHuJow= +github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240328092329-b5f2c7c059eb h1:0WvWXqzliYS1yKW+6uTxZGMjQd08IQNPzlNNxxyNWHM= +github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240328092329-b5f2c7c059eb/go.mod h1:mZNRILxq51LVqwqE9jMJyDHgmy9W3x7otOGuFjOm82Q= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240321152247-79521988c8e6 h1:7HqUo9YmpsfN/y9px6RmzREJm5O6ZzP9NqvFSrHTw24= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240321152247-79521988c8e6/go.mod h1:H2H/zoskiZC0lEokq9qMFVxRkB0RWVDPLjHbG/NrGUU= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240321152532-45da5eabdc38 h1:SAKjOByxXkZ5Sys5O4IkrrSGCKLoPvD+cCJJEvbev4w= diff --git a/testscommon/esdtStorageHandlerStub.go b/testscommon/esdtStorageHandlerStub.go index 1a1af038e4e..47825717409 100644 --- a/testscommon/esdtStorageHandlerStub.go +++ b/testscommon/esdtStorageHandlerStub.go @@ -16,7 +16,7 @@ type EsdtStorageHandlerStub struct { GetESDTNFTTokenOnDestinationWithCustomSystemAccountCalled func(accnt vmcommon.UserAccountHandler, esdtTokenKey []byte, nonce uint64, systemAccount vmcommon.UserAccountHandler) (*esdt.ESDigitalToken, bool, error) WasAlreadySentToDestinationShardAndUpdateStateCalled func(tickerID []byte, nonce uint64, dstAddress []byte) (bool, error) SaveNFTMetaDataCalled func(tx data.TransactionHandler) error - AddToLiquiditySystemAccCalled func(esdtTokenKey []byte, tokenType uint32, nonce uint64, transferValue *big.Int) error + AddToLiquiditySystemAccCalled func(esdtTokenKey []byte, tokenType uint32, nonce uint64, transferValue *big.Int, keepMetadataOnZeroLiquidity bool) error SaveMetaDataToSystemAccountCalled func(tokenKey []byte, nonce uint64, esdtData *esdt.ESDigitalToken) error GetMetaDataFromSystemAccountCalled func(bytes []byte, u uint64) (*esdt.MetaData, error) } @@ -94,9 +94,9 @@ func (e *EsdtStorageHandlerStub) SaveNFTMetaData(tx data.TransactionHandler) err } // AddToLiquiditySystemAcc - -func (e *EsdtStorageHandlerStub) AddToLiquiditySystemAcc(esdtTokenKey []byte, tokenType uint32, nonce uint64, transferValue *big.Int) error { +func (e *EsdtStorageHandlerStub) AddToLiquiditySystemAcc(esdtTokenKey []byte, tokenType uint32, nonce uint64, transferValue *big.Int, keepMetadataOnZeroLiquidity bool) error { if e.AddToLiquiditySystemAccCalled != nil { - return e.AddToLiquiditySystemAccCalled(esdtTokenKey, tokenType, nonce, transferValue) + return e.AddToLiquiditySystemAccCalled(esdtTokenKey, tokenType, nonce, transferValue, keepMetadataOnZeroLiquidity) } return nil diff --git a/vm/systemSmartContracts/esdt.go b/vm/systemSmartContracts/esdt.go index dbf4a56db1e..7d8fe4bba10 100644 --- a/vm/systemSmartContracts/esdt.go +++ b/vm/systemSmartContracts/esdt.go @@ -2391,7 +2391,7 @@ func (e *esdt) sendTokenTypeToSystemAccounts(caller []byte, tokenID []byte, toke builtInFunc := core.ESDTSetTokenType esdtTransferData := builtInFunc + "@" + hex.EncodeToString(tokenID) + "@" + hex.EncodeToString(token.TokenType) - e.eei.SendGlobalSettingToAll(e.eSDTSCAddress, []byte(esdtTransferData)) + e.eei.SendGlobalSettingToAll(e.esdtSCAddress, []byte(esdtTransferData)) logEntry := &vmcommon.LogEntry{ Identifier: []byte(builtInFunc), From 99c9793df2e82c06f614ac83cae71de7ccf3afca Mon Sep 17 00:00:00 2001 From: robertsasu Date: Fri, 29 Mar 2024 10:35:24 +0200 Subject: [PATCH 141/503] fixed unstaked list on delegation when nodes are unstaked from queue --- vm/systemSmartContracts/delegation.go | 3 +- vm/systemSmartContracts/eei.go | 4 +++ vm/systemSmartContracts/stakingWaitingList.go | 34 +++++++++++++++++++ 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/vm/systemSmartContracts/delegation.go b/vm/systemSmartContracts/delegation.go index ac33ba81da2..ab5c97cfce0 100644 --- a/vm/systemSmartContracts/delegation.go +++ b/vm/systemSmartContracts/delegation.go @@ -2322,7 +2322,8 @@ func (d *delegation) deleteDelegatorIfNeeded(address []byte, delegator *Delegato } func (d *delegation) unStakeAtEndOfEpoch(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { - if !bytes.Equal(args.CallerAddr, d.endOfEpochAddr) { + if !bytes.Equal(args.CallerAddr, d.endOfEpochAddr) && + !bytes.Equal(args.CallerAddr, d.stakingSCAddr) { d.eei.AddReturnMessage("can be called by end of epoch address only") return vmcommon.UserError } diff --git a/vm/systemSmartContracts/eei.go b/vm/systemSmartContracts/eei.go index 55f554d11b0..3f251a6cca4 100644 --- a/vm/systemSmartContracts/eei.go +++ b/vm/systemSmartContracts/eei.go @@ -144,6 +144,8 @@ func (host *vmContext) GetStorageFromAddress(address []byte, key []byte) []byte if value, isInMap := storageAdrMap[string(key)]; isInMap { return value } + } else { + storageAdrMap = make(map[string][]byte) } data, _, err := host.blockChainHook.GetStorageData(address, key) @@ -151,6 +153,8 @@ func (host *vmContext) GetStorageFromAddress(address []byte, key []byte) []byte return nil } + storageAdrMap[string(key)] = data + return data } diff --git a/vm/systemSmartContracts/stakingWaitingList.go b/vm/systemSmartContracts/stakingWaitingList.go index e1d0ff00cb4..1ab917a9269 100644 --- a/vm/systemSmartContracts/stakingWaitingList.go +++ b/vm/systemSmartContracts/stakingWaitingList.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/hex" "fmt" + "github.com/multiversx/mx-chain-core-go/core" "math" "math/big" "strconv" @@ -824,6 +825,8 @@ func (s *stakingSC) unStakeAllNodesFromQueue(args *vmcommon.ContractCallInput) v return vmcommon.Ok } + orderedListOwners := make([]string, 0) + mapOwnerKeys := make(map[string][][]byte) for i, blsKey := range waitingListData.blsKeys { registrationData := waitingListData.stakedDataList[i] @@ -835,11 +838,42 @@ func (s *stakingSC) unStakeAllNodesFromQueue(args *vmcommon.ContractCallInput) v // delete element from waiting list inWaitingListKey := createWaitingListKey(blsKey) s.eei.SetStorage(inWaitingListKey, nil) + + ownerAddr := string(registrationData.OwnerAddress) + _, exists := mapOwnerKeys[ownerAddr] + if !exists { + mapOwnerKeys[ownerAddr] = make([][]byte, 0) + orderedListOwners = append(orderedListOwners, ownerAddr) + } + + mapOwnerKeys[ownerAddr] = append(mapOwnerKeys[ownerAddr], blsKey) } // delete waiting list head element s.eei.SetStorage([]byte(waitingListHeadKey), nil) + // call unStakeAtEndOfEpoch from the delegation contracts to compute the new unStaked list + for _, owner := range orderedListOwners { + listOfKeys := mapOwnerKeys[owner] + + if s.eei.BlockChainHook().GetShardOfAddress([]byte(owner)) != core.MetachainShardId { + continue + } + + unStakeCall := "unStakeAtEndOfEpoch" + for _, key := range listOfKeys { + unStakeCall += "@" + hex.EncodeToString(key) + } + vmOutput, err := s.eei.ExecuteOnDestContext([]byte(owner), args.RecipientAddr, big.NewInt(0), []byte(unStakeCall)) + if err != nil { + s.eei.AddReturnMessage(err.Error()) + return vmcommon.UserError + } + if vmOutput.ReturnCode != vmcommon.Ok { + return vmOutput.ReturnCode + } + } + return vmcommon.Ok } From 60782049181eb301a5ba08a8db8383f58e8ac8c9 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Fri, 29 Mar 2024 11:59:51 +0200 Subject: [PATCH 142/503] fixed unstaked list on delegation when nodes are unstaked from queue --- vm/systemSmartContracts/stakingWaitingList.go | 27 +++-- vm/systemSmartContracts/staking_test.go | 104 ++++++++++++++++++ 2 files changed, 122 insertions(+), 9 deletions(-) diff --git a/vm/systemSmartContracts/stakingWaitingList.go b/vm/systemSmartContracts/stakingWaitingList.go index 1ab917a9269..e08b16b3cde 100644 --- a/vm/systemSmartContracts/stakingWaitingList.go +++ b/vm/systemSmartContracts/stakingWaitingList.go @@ -4,11 +4,11 @@ import ( "bytes" "encoding/hex" "fmt" - "github.com/multiversx/mx-chain-core-go/core" "math" "math/big" "strconv" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/vm" vmcommon "github.com/multiversx/mx-chain-vm-common-go" @@ -829,7 +829,6 @@ func (s *stakingSC) unStakeAllNodesFromQueue(args *vmcommon.ContractCallInput) v mapOwnerKeys := make(map[string][][]byte) for i, blsKey := range waitingListData.blsKeys { registrationData := waitingListData.stakedDataList[i] - result := s.doUnStake(blsKey, registrationData) if result != vmcommon.Ok { return result @@ -864,19 +863,29 @@ func (s *stakingSC) unStakeAllNodesFromQueue(args *vmcommon.ContractCallInput) v for _, key := range listOfKeys { unStakeCall += "@" + hex.EncodeToString(key) } - vmOutput, err := s.eei.ExecuteOnDestContext([]byte(owner), args.RecipientAddr, big.NewInt(0), []byte(unStakeCall)) - if err != nil { - s.eei.AddReturnMessage(err.Error()) - return vmcommon.UserError - } - if vmOutput.ReturnCode != vmcommon.Ok { - return vmOutput.ReturnCode + returnCode := s.executeOnStakeAtEndOfEpoch([]byte(owner), listOfKeys, args.RecipientAddr) + if returnCode != vmcommon.Ok { + return returnCode } } return vmcommon.Ok } +func (s *stakingSC) executeOnStakeAtEndOfEpoch(destinationAddress []byte, listOfKeys [][]byte, senderAddress []byte) vmcommon.ReturnCode { + unStakeCall := "unStakeAtEndOfEpoch" + for _, key := range listOfKeys { + unStakeCall += "@" + hex.EncodeToString(key) + } + vmOutput, err := s.eei.ExecuteOnDestContext(destinationAddress, senderAddress, big.NewInt(0), []byte(unStakeCall)) + if err != nil { + s.eei.AddReturnMessage(err.Error()) + return vmcommon.UserError + } + + return vmOutput.ReturnCode +} + func (s *stakingSC) cleanAdditionalQueue(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { if !s.enableEpochsHandler.IsFlagEnabled(common.CorrectLastUnJailedFlag) { s.eei.AddReturnMessage("invalid method to call") diff --git a/vm/systemSmartContracts/staking_test.go b/vm/systemSmartContracts/staking_test.go index 53d78208cf1..68bc5c0b7f8 100644 --- a/vm/systemSmartContracts/staking_test.go +++ b/vm/systemSmartContracts/staking_test.go @@ -3706,3 +3706,107 @@ func TestStakingSc_UnStakeAllFromQueue(t *testing.T) { doGetStatus(t, stakingSmartContract, eei, []byte("thirdKey "), "staked") doGetStatus(t, stakingSmartContract, eei, []byte("fourthKey"), "staked") } + +func TestStakingSc_UnStakeAllFromQueueWithDelegationContracts(t *testing.T) { + t.Parallel() + + blockChainHook := &mock.BlockChainHookStub{} + blockChainHook.GetStorageDataCalled = func(accountsAddress []byte, index []byte) ([]byte, uint32, error) { + return nil, 0, nil + } + blockChainHook.GetShardOfAddressCalled = func(address []byte) uint32 { + return core.MetachainShardId + } + + eei := createDefaultEei() + eei.blockChainHook = blockChainHook + eei.SetSCAddress([]byte("addr")) + + delegationSC, _ := createDelegationContractAndEEI() + delegationSC.eei = eei + + systemSCContainerStub := &mock.SystemSCContainerStub{GetCalled: func(key []byte) (vm.SystemSmartContract, error) { + return delegationSC, nil + }} + _ = eei.SetSystemSCContainer(systemSCContainerStub) + + stakingAccessAddress := vm.ValidatorSCAddress + args := createMockStakingScArguments() + args.StakingAccessAddr = stakingAccessAddress + args.StakingSCConfig.MaxNumberOfNodesForStake = 1 + enableEpochsHandler, _ := args.EnableEpochsHandler.(*enableEpochsHandlerMock.EnableEpochsHandlerStub) + args.Eei = eei + args.StakingSCConfig.UnBondPeriod = 100 + stakingSmartContract, _ := NewStakingSmartContract(args) + + stakerAddress := []byte("stakerAddr") + + blockChainHook.CurrentNonceCalled = func() uint64 { + return 1 + } + + enableEpochsHandler.AddActiveFlags(common.StakingV2Flag) + enableEpochsHandler.AddActiveFlags(common.StakeFlag) + + // do stake should work + doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("firstKey ")) + doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("secondKey")) + doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("thirdKey ")) + doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("fourthKey")) + + waitingReturn := doGetWaitingListRegisterNonceAndRewardAddress(t, stakingSmartContract, eei) + assert.Equal(t, len(waitingReturn), 9) + + dStatus := &DelegationContractStatus{ + StakedKeys: make([]*NodesData, 4), + NotStakedKeys: nil, + UnStakedKeys: nil, + NumUsers: 0, + } + dStatus.StakedKeys[0] = &NodesData{BLSKey: []byte("firstKey ")} + dStatus.StakedKeys[1] = &NodesData{BLSKey: []byte("secondKey")} + dStatus.StakedKeys[2] = &NodesData{BLSKey: []byte("thirdKey ")} + dStatus.StakedKeys[3] = &NodesData{BLSKey: []byte("fourthKey")} + + marshaledData, _ := delegationSC.marshalizer.Marshal(dStatus) + eei.SetStorageForAddress(stakerAddress, []byte(delegationStatusKey), marshaledData) + + arguments := CreateVmContractCallInput() + arguments.RecipientAddr = vm.StakingSCAddress + validatorData := &ValidatorDataV2{ + TotalStakeValue: big.NewInt(400), + TotalUnstaked: big.NewInt(0), + RewardAddress: stakerAddress, + BlsPubKeys: [][]byte{[]byte("firstKey "), []byte("secondKey"), []byte("thirdKey "), []byte("fourthKey")}, + } + arguments.CallerAddr = stakingSmartContract.endOfEpochAccessAddr + marshaledData, _ = stakingSmartContract.marshalizer.Marshal(validatorData) + eei.SetStorageForAddress(vm.ValidatorSCAddress, stakerAddress, marshaledData) + + enableEpochsHandler.AddActiveFlags(common.StakingV4Step1Flag) + enableEpochsHandler.AddActiveFlags(common.StakingV4StartedFlag) + + arguments.Function = "unStakeAllNodesFromQueue" + retCode := stakingSmartContract.Execute(arguments) + fmt.Println(eei.returnMessage) + assert.Equal(t, retCode, vmcommon.Ok) + + assert.Equal(t, len(eei.GetStorage([]byte(waitingListHeadKey))), 0) + newHead, _ := stakingSmartContract.getWaitingListHead() + assert.Equal(t, uint32(0), newHead.Length) // no entries in the queue list + + marshaledData = eei.GetStorageFromAddress(stakerAddress, []byte(delegationStatusKey)) + _ = stakingSmartContract.marshalizer.Unmarshal(dStatus, marshaledData) + assert.Equal(t, len(dStatus.UnStakedKeys), 3) + assert.Equal(t, len(dStatus.StakedKeys), 1) + + doGetStatus(t, stakingSmartContract, eei, []byte("secondKey"), "unStaked") + + // stake them again - as they were deleted from waiting list + doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("thirdKey ")) + doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("fourthKey")) + + // surprisingly, the queue works again as we did not activate the staking v4 + doGetStatus(t, stakingSmartContract, eei, []byte("thirdKey "), "staked") + doGetStatus(t, stakingSmartContract, eei, []byte("fourthKey"), "staked") +} From 1e79ea7f4614cae0a0dfefdf3b4d2c1821f6cb6a Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 29 Mar 2024 14:19:16 +0200 Subject: [PATCH 143/503] staking provider with node scenario --- .../stakingProviderWithNodesinQueue_test.go | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go diff --git a/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go b/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go new file mode 100644 index 00000000000..6bf887840c1 --- /dev/null +++ b/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go @@ -0,0 +1,130 @@ +package staking + +import ( + "encoding/hex" + "fmt" + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/node/chainSimulator" + "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" + "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" + "github.com/multiversx/mx-chain-go/vm" + "github.com/stretchr/testify/require" + "math/big" + "testing" + "time" +) + +func TestStakingProviderWithNodes(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + stakingV4ActivationEpoch := uint32(2) + + t.Run("staking ph 4 step 1 active", func(t *testing.T) { + testStakingProviderWithNodesReStakeUnStaked(t, stakingV4ActivationEpoch) + }) + + t.Run("staking ph 4 step 2 active", func(t *testing.T) { + testStakingProviderWithNodesReStakeUnStaked(t, stakingV4ActivationEpoch+1) + }) + + t.Run("staking ph 4 step 3 active", func(t *testing.T) { + testStakingProviderWithNodesReStakeUnStaked(t, stakingV4ActivationEpoch+2) + }) +} + +func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4ActivationEpoch uint32) { + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, + AlterConfigsFunction: func(cfg *config.Configs) { + configs.SetStakingV4ActivationEpochs(cfg, stakingV4ActivationEpoch) + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + defer cs.Close() + + mintValue := big.NewInt(0).Mul(big.NewInt(5000), oneEGLD) + validatorOwner, err := cs.GenerateAndMintWalletAddress(0, mintValue) + require.Nil(t, err) + require.Nil(t, err) + + err = cs.GenerateBlocksUntilEpochIsReached(1) + require.Nil(t, err) + + // create delegation contract + stakeValue, _ := big.NewInt(0).SetString("4250000000000000000000", 10) + dataField := "createNewDelegationContract@00@0ea1" + txStake := generateTransaction(validatorOwner.Bytes, getNonce(t, cs, validatorOwner), vm.DelegationManagerSCAddress, stakeValue, dataField, 80_000_000) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, stakeTx) + + delegationAddress := stakeTx.Logs.Events[2].Address + delegationAddressBytes, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Decode(delegationAddress) + + // add nodes in queue + _, blsKeys, err := chainSimulator.GenerateBlsPrivateKeys(1) + require.Nil(t, err) + + txDataFieldAddNodes := fmt.Sprintf("addNodes@%s@%s", blsKeys[0], mockBLSSignature+"02") + ownerNonce := getNonce(t, cs, validatorOwner) + txAddNodes := generateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), txDataFieldAddNodes, gasLimitForStakeOperation) + addNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txAddNodes, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, addNodesTx) + + txDataFieldStakeNodes := fmt.Sprintf("stakeNodes@%s", blsKeys[0]) + ownerNonce = getNonce(t, cs, validatorOwner) + txStakeNodes := generateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), txDataFieldStakeNodes, gasLimitForStakeOperation) + + stakeNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStakeNodes}, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.Equal(t, 1, len(stakeNodesTxs)) + + metachainNode := cs.GetNodeHandler(core.MetachainShardId) + decodedBLSKey0, _ := hex.DecodeString(blsKeys[0]) + status := getBLSKeyStatus(t, metachainNode, decodedBLSKey0) + require.Equal(t, "queued", status) + + // activate staking v4 + err = cs.GenerateBlocksUntilEpochIsReached(int32(stakingV4ActivationEpoch)) + require.Nil(t, err) + + status = getBLSKeyStatus(t, metachainNode, decodedBLSKey0) + require.Equal(t, "unStaked", status) + + ownerNonce = getNonce(t, cs, validatorOwner) + reStakeTxData := fmt.Sprintf("reStakeUnStakedNodes@%s", blsKeys[0]) + reStakeNodes := generateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), reStakeTxData, gasLimitForStakeOperation) + reStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(reStakeNodes, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, reStakeTx) + + status = getBLSKeyStatus(t, metachainNode, decodedBLSKey0) + require.Equal(t, "staked", status) + + err = cs.GenerateBlocks(20) + + checkValidatorStatus(t, cs, blsKeys[0], "auction") +} From bb090cebe542f89d152764b7709f30a358d41456 Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 29 Mar 2024 14:21:20 +0200 Subject: [PATCH 144/503] fix linter --- .../staking/stakingProviderWithNodesinQueue_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go b/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go index 6bf887840c1..db417bbee1f 100644 --- a/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go +++ b/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go @@ -125,6 +125,7 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati require.Equal(t, "staked", status) err = cs.GenerateBlocks(20) + require.Nil(t, err) checkValidatorStatus(t, cs, blsKeys[0], "auction") } From 1f2fae1e7239aed9d6a392db483124724623e669 Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 29 Mar 2024 14:37:58 +0200 Subject: [PATCH 145/503] fixes after review --- .../staking/stakingProviderWithNodesinQueue_test.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go b/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go index db417bbee1f..57377c47bd6 100644 --- a/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go +++ b/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go @@ -3,6 +3,10 @@ package staking import ( "encoding/hex" "fmt" + "math/big" + "testing" + "time" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" @@ -11,9 +15,6 @@ import ( "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/vm" "github.com/stretchr/testify/require" - "math/big" - "testing" - "time" ) func TestStakingProviderWithNodes(t *testing.T) { @@ -124,6 +125,10 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati status = getBLSKeyStatus(t, metachainNode, decodedBLSKey0) require.Equal(t, "staked", status) + result := getAllNodeStates(t, metachainNode, delegationAddressBytes) + require.NotNil(t, result) + require.Equal(t, "staked", result[blsKeys[0]]) + err = cs.GenerateBlocks(20) require.Nil(t, err) From 028f6a379467d28fb0f79870fe8cb93b111f1386 Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 29 Mar 2024 14:41:15 +0200 Subject: [PATCH 146/503] extra check --- .../staking/stakingProviderWithNodesinQueue_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go b/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go index 57377c47bd6..af50d56c821 100644 --- a/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go +++ b/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go @@ -115,6 +115,10 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati status = getBLSKeyStatus(t, metachainNode, decodedBLSKey0) require.Equal(t, "unStaked", status) + result := getAllNodeStates(t, metachainNode, delegationAddressBytes) + require.NotNil(t, result) + require.Equal(t, "unStaked", result[blsKeys[0]]) + ownerNonce = getNonce(t, cs, validatorOwner) reStakeTxData := fmt.Sprintf("reStakeUnStakedNodes@%s", blsKeys[0]) reStakeNodes := generateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), reStakeTxData, gasLimitForStakeOperation) @@ -125,7 +129,7 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati status = getBLSKeyStatus(t, metachainNode, decodedBLSKey0) require.Equal(t, "staked", status) - result := getAllNodeStates(t, metachainNode, delegationAddressBytes) + result = getAllNodeStates(t, metachainNode, delegationAddressBytes) require.NotNil(t, result) require.Equal(t, "staked", result[blsKeys[0]]) From c227dd5091341af24887b610a4b4eefcdeaed878 Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 2 Apr 2024 12:13:50 +0300 Subject: [PATCH 147/503] extend unit test and fixes --- vm/systemSmartContracts/staking_test.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/vm/systemSmartContracts/staking_test.go b/vm/systemSmartContracts/staking_test.go index 68bc5c0b7f8..fb92a574945 100644 --- a/vm/systemSmartContracts/staking_test.go +++ b/vm/systemSmartContracts/staking_test.go @@ -3755,7 +3755,7 @@ func TestStakingSc_UnStakeAllFromQueueWithDelegationContracts(t *testing.T) { doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("fourthKey")) waitingReturn := doGetWaitingListRegisterNonceAndRewardAddress(t, stakingSmartContract, eei) - assert.Equal(t, len(waitingReturn), 9) + requireSliceContains(t, waitingReturn, [][]byte{[]byte("secondKey"), []byte("thirdKey "), []byte("fourthKey")}) dStatus := &DelegationContractStatus{ StakedKeys: make([]*NodesData, 4), @@ -3801,12 +3801,19 @@ func TestStakingSc_UnStakeAllFromQueueWithDelegationContracts(t *testing.T) { assert.Equal(t, len(dStatus.StakedKeys), 1) doGetStatus(t, stakingSmartContract, eei, []byte("secondKey"), "unStaked") + doGetStatus(t, stakingSmartContract, eei, []byte("thirdKey "), "unStaked") + doGetStatus(t, stakingSmartContract, eei, []byte("fourthKey"), "unStaked") // stake them again - as they were deleted from waiting list doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("thirdKey ")) doStake(t, stakingSmartContract, stakingAccessAddress, stakerAddress, []byte("fourthKey")) - // surprisingly, the queue works again as we did not activate the staking v4 doGetStatus(t, stakingSmartContract, eei, []byte("thirdKey "), "staked") doGetStatus(t, stakingSmartContract, eei, []byte("fourthKey"), "staked") } + +func requireSliceContains(t *testing.T, s1, s2 [][]byte) { + for _, elemInS2 := range s2 { + require.Contains(t, s1, elemInS2) + } +} From b0e9ead8fbdd42a047f3835194d0c601ebcc2bed Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 2 Apr 2024 13:04:50 +0300 Subject: [PATCH 148/503] extend unit test and fixes --- .../chainSimulator/staking/helpers.go | 112 ++++++ .../staking/{ => jail}/jail_test.go | 66 ++-- .../staking/{ => stake}/simpleStake_test.go | 43 +-- .../{ => stake}/stakeAndUnStake_test.go | 282 +++++++-------- .../{ => stakingProvider}/delegation_test.go | 324 +++++++----------- .../stakingProviderWithNodesinQueue_test.go | 46 +-- 6 files changed, 454 insertions(+), 419 deletions(-) create mode 100644 integrationTests/chainSimulator/staking/helpers.go rename integrationTests/chainSimulator/staking/{ => jail}/jail_test.go (74%) rename integrationTests/chainSimulator/staking/{ => stake}/simpleStake_test.go (83%) rename integrationTests/chainSimulator/staking/{ => stake}/stakeAndUnStake_test.go (87%) rename integrationTests/chainSimulator/staking/{ => stakingProvider}/delegation_test.go (84%) rename integrationTests/chainSimulator/staking/{ => stakingProvider}/stakingProviderWithNodesinQueue_test.go (68%) diff --git a/integrationTests/chainSimulator/staking/helpers.go b/integrationTests/chainSimulator/staking/helpers.go new file mode 100644 index 00000000000..550e227a7f2 --- /dev/null +++ b/integrationTests/chainSimulator/staking/helpers.go @@ -0,0 +1,112 @@ +package staking + +import ( + "encoding/hex" + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/transaction" + chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" + "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" + "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" + chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" + "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/vm" + "github.com/stretchr/testify/require" + "math/big" + "testing" +) + +const ( + minGasPrice = 1000000000 + txVersion = 1 + mockTxSignature = "sig" + + OkReturnCode = "ok" + UnStakedStatus = "unStaked" + MockBLSSignature = "010101" + GasLimitForStakeOperation = 50_000_000 + GasLimitForUnBond = 12_000_000 + MaxNumOfBlockToGenerateWhenExecutingTx = 7 + + QueuedStatus = "queued" + StakedStatus = "staked" + NotStakedStatus = "notStaked" + AuctionStatus = "auction" +) + +var InitialDelegationValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(1250)) +var ZeroValue = big.NewInt(0) + +var MinimumStakeValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(2500)) +var OneEGLD = big.NewInt(1000000000000000000) + +func GetNonce(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, address dtos.WalletAddress) uint64 { + account, err := cs.GetAccount(address) + require.Nil(t, err) + + return account.Nonce +} + +func GenerateTransaction(sender []byte, nonce uint64, receiver []byte, value *big.Int, data string, gasLimit uint64) *transaction.Transaction { + return &transaction.Transaction{ + Nonce: nonce, + Value: value, + SndAddr: sender, + RcvAddr: receiver, + Data: []byte(data), + GasLimit: gasLimit, + GasPrice: minGasPrice, + ChainID: []byte(configs.ChainID), + Version: txVersion, + Signature: []byte(mockTxSignature), + } +} + +func GetBLSKeyStatus(t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, blsKey []byte) string { + scQuery := &process.SCQuery{ + ScAddress: vm.StakingSCAddress, + FuncName: "getBLSKeyStatus", + CallerAddr: vm.StakingSCAddress, + CallValue: big.NewInt(0), + Arguments: [][]byte{blsKey}, + } + result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) + require.Nil(t, err) + require.Equal(t, OkReturnCode, result.ReturnCode) + + return string(result.ReturnData[0]) +} + +func GetAllNodeStates(t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, address []byte) map[string]string { + scQuery := &process.SCQuery{ + ScAddress: address, + FuncName: "getAllNodeStates", + CallerAddr: vm.StakingSCAddress, + CallValue: big.NewInt(0), + } + result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) + require.Nil(t, err) + require.Equal(t, OkReturnCode, result.ReturnCode) + + m := make(map[string]string) + status := "" + for _, resultData := range result.ReturnData { + if len(resultData) != 96 { + // not a BLS key + status = string(resultData) + continue + } + + m[hex.EncodeToString(resultData)] = status + } + + return m +} + +func CheckValidatorStatus(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, blsKey string, expectedStatus string) { + err := cs.ForceResetValidatorStatisticsCache() + require.Nil(t, err) + + validatorsStatistics, err := cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ValidatorStatisticsApi() + require.Nil(t, err) + require.Equal(t, expectedStatus, validatorsStatistics[blsKey].ValidatorStatus) +} diff --git a/integrationTests/chainSimulator/staking/jail_test.go b/integrationTests/chainSimulator/staking/jail/jail_test.go similarity index 74% rename from integrationTests/chainSimulator/staking/jail_test.go rename to integrationTests/chainSimulator/staking/jail/jail_test.go index 4251ece6bf4..c16d3c60df2 100644 --- a/integrationTests/chainSimulator/staking/jail_test.go +++ b/integrationTests/chainSimulator/staking/jail/jail_test.go @@ -1,8 +1,9 @@ -package staking +package jail import ( "encoding/hex" "fmt" + "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "math/big" "testing" "time" @@ -11,7 +12,6 @@ import ( "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" - chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" @@ -21,6 +21,7 @@ import ( const ( stakingV4JailUnJailStep1EnableEpoch = 5 + defaultPathToInitialConfig = "../../../../cmd/node/config/" epochWhenNodeIsJailed = 4 ) @@ -92,13 +93,13 @@ func testChainSimulatorJailAndUnJail(t *testing.T, targetEpoch int32, nodeStatus _, blsKeys, err := chainSimulator.GenerateBlsPrivateKeys(1) require.Nil(t, err) - mintValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(3000)) + mintValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(3000)) walletAddress, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, minimumStakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -107,18 +108,18 @@ func testChainSimulatorJailAndUnJail(t *testing.T, targetEpoch int32, nodeStatus require.Nil(t, err) decodedBLSKey, _ := hex.DecodeString(blsKeys[0]) - status := getBLSKeyStatus(t, metachainNode, decodedBLSKey) + status := staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey) require.Equal(t, "jailed", status) // do an unjail transaction unJailValue, _ := big.NewInt(0).SetString("2500000000000000000", 10) txUnJailDataField := fmt.Sprintf("unJail@%s", blsKeys[0]) - txUnJail := generateTransaction(walletAddress.Bytes, 1, vm.ValidatorSCAddress, unJailValue, txUnJailDataField, gasLimitForStakeOperation) + txUnJail := staking.GenerateTransaction(walletAddress.Bytes, 1, vm.ValidatorSCAddress, unJailValue, txUnJailDataField, staking.GasLimitForStakeOperation) err = cs.GenerateBlocksUntilEpochIsReached(targetEpoch) require.Nil(t, err) - unJailTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnJail, maxNumOfBlockToGenerateWhenExecutingTx) + unJailTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnJail, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unJailTx) require.Equal(t, transaction.TxStatusSuccess, unJailTx.Status) @@ -126,20 +127,20 @@ func testChainSimulatorJailAndUnJail(t *testing.T, targetEpoch int32, nodeStatus err = cs.GenerateBlocks(1) require.Nil(t, err) - status = getBLSKeyStatus(t, metachainNode, decodedBLSKey) + status = staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey) require.Equal(t, "staked", status) - checkValidatorStatus(t, cs, blsKeys[0], nodeStatusAfterUnJail) + staking.CheckValidatorStatus(t, cs, blsKeys[0], nodeStatusAfterUnJail) err = cs.GenerateBlocksUntilEpochIsReached(targetEpoch + 1) require.Nil(t, err) - checkValidatorStatus(t, cs, blsKeys[0], "waiting") + staking.CheckValidatorStatus(t, cs, blsKeys[0], "waiting") err = cs.GenerateBlocksUntilEpochIsReached(targetEpoch + 2) require.Nil(t, err) - checkValidatorStatus(t, cs, blsKeys[0], "eligible") + staking.CheckValidatorStatus(t, cs, blsKeys[0], "eligible") } // Test description @@ -196,13 +197,13 @@ func TestChainSimulator_FromQueueToAuctionList(t *testing.T) { err = cs.AddValidatorKeys([][]byte{privateKeys[1]}) require.Nil(t, err) - mintValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(6000)) + mintValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(6000)) walletAddress, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, minimumStakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -211,47 +212,38 @@ func TestChainSimulator_FromQueueToAuctionList(t *testing.T) { require.Nil(t, err) decodedBLSKey0, _ := hex.DecodeString(blsKeys[0]) - status := getBLSKeyStatus(t, metachainNode, decodedBLSKey0) + status := staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey0) require.Equal(t, "jailed", status) // add one more node - txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], mockBLSSignature) - txStake = generateTransaction(walletAddress.Bytes, 1, vm.ValidatorSCAddress, minimumStakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], staking.MockBLSSignature) + txStake = staking.GenerateTransaction(walletAddress.Bytes, 1, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) decodedBLSKey1, _ := hex.DecodeString(blsKeys[1]) - status = getBLSKeyStatus(t, metachainNode, decodedBLSKey1) + status = staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey1) require.Equal(t, "staked", status) // unJail the first node unJailValue, _ := big.NewInt(0).SetString("2500000000000000000", 10) txUnJailDataField := fmt.Sprintf("unJail@%s", blsKeys[0]) - txUnJail := generateTransaction(walletAddress.Bytes, 2, vm.ValidatorSCAddress, unJailValue, txUnJailDataField, gasLimitForStakeOperation) + txUnJail := staking.GenerateTransaction(walletAddress.Bytes, 2, vm.ValidatorSCAddress, unJailValue, txUnJailDataField, staking.GasLimitForStakeOperation) - unJailTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnJail, maxNumOfBlockToGenerateWhenExecutingTx) + unJailTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnJail, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unJailTx) require.Equal(t, transaction.TxStatusSuccess, unJailTx.Status) - status = getBLSKeyStatus(t, metachainNode, decodedBLSKey0) + status = staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey0) require.Equal(t, "queued", status) err = cs.GenerateBlocksUntilEpochIsReached(stakingV4JailUnJailStep1EnableEpoch) require.Nil(t, err) - status = getBLSKeyStatus(t, metachainNode, decodedBLSKey0) - require.Equal(t, unStakedStatus, status) + status = staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey0) + require.Equal(t, staking.UnStakedStatus, status) - checkValidatorStatus(t, cs, blsKeys[0], string(common.InactiveList)) -} - -func checkValidatorStatus(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, blsKey string, expectedStatus string) { - err := cs.ForceResetValidatorStatisticsCache() - require.Nil(t, err) - - validatorsStatistics, err := cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ValidatorStatisticsApi() - require.Nil(t, err) - require.Equal(t, expectedStatus, validatorsStatistics[blsKey].ValidatorStatus) + staking.CheckValidatorStatus(t, cs, blsKeys[0], string(common.InactiveList)) } diff --git a/integrationTests/chainSimulator/staking/simpleStake_test.go b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go similarity index 83% rename from integrationTests/chainSimulator/staking/simpleStake_test.go rename to integrationTests/chainSimulator/staking/stake/simpleStake_test.go index 83039942189..4bbaa1ef74c 100644 --- a/integrationTests/chainSimulator/staking/simpleStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go @@ -1,8 +1,9 @@ -package staking +package stake import ( "encoding/hex" "fmt" + "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "math/big" "testing" "time" @@ -83,7 +84,7 @@ func testChainSimulatorSimpleStake(t *testing.T, targetEpoch int32, nodesStatus require.NotNil(t, cs) defer cs.Close() - mintValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(3000)) + mintValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(3000)) wallet1, err := cs.GenerateAndMintWalletAddress(0, mintValue) require.Nil(t, err) wallet2, err := cs.GenerateAndMintWalletAddress(0, mintValue) @@ -97,18 +98,18 @@ func testChainSimulatorSimpleStake(t *testing.T, targetEpoch int32, nodesStatus err = cs.GenerateBlocksUntilEpochIsReached(targetEpoch) require.Nil(t, err) - dataFieldTx1 := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - tx1Value := big.NewInt(0).Mul(big.NewInt(2499), oneEGLD) - tx1 := generateTransaction(wallet1.Bytes, 0, vm.ValidatorSCAddress, tx1Value, dataFieldTx1, gasLimitForStakeOperation) + dataFieldTx1 := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + tx1Value := big.NewInt(0).Mul(big.NewInt(2499), staking.OneEGLD) + tx1 := staking.GenerateTransaction(wallet1.Bytes, 0, vm.ValidatorSCAddress, tx1Value, dataFieldTx1, staking.GasLimitForStakeOperation) - dataFieldTx2 := fmt.Sprintf("stake@01@%s@%s", blsKeys[1], mockBLSSignature) - tx2 := generateTransaction(wallet3.Bytes, 0, vm.ValidatorSCAddress, minimumStakeValue, dataFieldTx2, gasLimitForStakeOperation) + dataFieldTx2 := fmt.Sprintf("stake@01@%s@%s", blsKeys[1], staking.MockBLSSignature) + tx2 := staking.GenerateTransaction(wallet3.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, dataFieldTx2, staking.GasLimitForStakeOperation) - dataFieldTx3 := fmt.Sprintf("stake@01@%s@%s", blsKeys[2], mockBLSSignature) - tx3Value := big.NewInt(0).Mul(big.NewInt(2501), oneEGLD) - tx3 := generateTransaction(wallet2.Bytes, 0, vm.ValidatorSCAddress, tx3Value, dataFieldTx3, gasLimitForStakeOperation) + dataFieldTx3 := fmt.Sprintf("stake@01@%s@%s", blsKeys[2], staking.MockBLSSignature) + tx3Value := big.NewInt(0).Mul(big.NewInt(2501), staking.OneEGLD) + tx3 := staking.GenerateTransaction(wallet2.Bytes, 0, vm.ValidatorSCAddress, tx3Value, dataFieldTx3, staking.GasLimitForStakeOperation) - results, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{tx1, tx2, tx3}, maxNumOfBlockToGenerateWhenExecutingTx) + results, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{tx1, tx2, tx3}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.Equal(t, 3, len(results)) require.NotNil(t, results) @@ -123,16 +124,16 @@ func testChainSimulatorSimpleStake(t *testing.T, targetEpoch int32, nodesStatus bls1, _ := hex.DecodeString(blsKeys[1]) bls2, _ := hex.DecodeString(blsKeys[2]) - blsKeyStatus := getBLSKeyStatus(t, metachainNode, bls1) + blsKeyStatus := staking.GetBLSKeyStatus(t, metachainNode, bls1) require.Equal(t, nodesStatus, blsKeyStatus) - blsKeyStatus = getBLSKeyStatus(t, metachainNode, bls2) + blsKeyStatus = staking.GetBLSKeyStatus(t, metachainNode, bls2) require.Equal(t, nodesStatus, blsKeyStatus) } else { // tx2 -- validator should be in queue - checkValidatorStatus(t, cs, blsKeys[1], nodesStatus) + staking.CheckValidatorStatus(t, cs, blsKeys[1], nodesStatus) // tx3 -- validator should be in queue - checkValidatorStatus(t, cs, blsKeys[2], nodesStatus) + staking.CheckValidatorStatus(t, cs, blsKeys[2], nodesStatus) } } @@ -194,14 +195,14 @@ func TestChainSimulator_StakingV4Step2APICalls(t *testing.T) { err = cs.AddValidatorKeys(privateKey) require.Nil(t, err) - mintValue := big.NewInt(0).Add(minimumStakeValue, oneEGLD) + mintValue := big.NewInt(0).Add(staking.MinimumStakeValue, staking.OneEGLD) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) // Stake a new validator that should end up in auction in step 1 - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, minimumStakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -220,8 +221,8 @@ func TestChainSimulator_StakingV4Step2APICalls(t *testing.T) { // re-stake the node txDataField = fmt.Sprintf("reStakeUnStakedNodes@%s", blsKeys[0]) - txReStake := generateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, big.NewInt(0), txDataField, gasLimitForStakeOperation) - reStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txReStake, maxNumOfBlockToGenerateWhenExecutingTx) + txReStake := staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, big.NewInt(0), txDataField, staking.GasLimitForStakeOperation) + reStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txReStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, reStakeTx) diff --git a/integrationTests/chainSimulator/staking/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go similarity index 87% rename from integrationTests/chainSimulator/staking/stakeAndUnStake_test.go rename to integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index 0e91ef2a2c5..712f7ed5824 100644 --- a/integrationTests/chainSimulator/staking/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go @@ -1,8 +1,9 @@ -package staking +package stake import ( "encoding/hex" "fmt" + "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "math/big" "testing" "time" @@ -26,8 +27,7 @@ import ( ) const ( - defaultPathToInitialConfig = "../../../cmd/node/config/" - maxNumOfBlockToGenerateWhenExecutingTx = 7 + defaultPathToInitialConfig = "../../../../cmd/node/config/" ) var log = logger.GetOrCreate("integrationTests/chainSimulator") @@ -115,7 +115,7 @@ func TestChainSimulator_AddValidatorKey(t *testing.T) { ChainID: []byte(configs.ChainID), Version: 1, } - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -144,7 +144,7 @@ func TestChainSimulator_AddValidatorKey(t *testing.T) { ChainID: []byte(configs.ChainID), Version: 1, } - _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) // Step 6 --- generate 8 epochs to get rewards @@ -256,7 +256,7 @@ func TestChainSimulator_AddANewValidatorAfterStakingV4(t *testing.T) { Version: 1, } - txFromNetwork, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + txFromNetwork, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txFromNetwork) @@ -346,43 +346,43 @@ func testStakeUnStakeUnBond(t *testing.T, targetEpoch int32) { err = cs.AddValidatorKeys(privateKeys) require.Nil(t, err) - mintValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(2600)) + mintValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(2600)) walletAddressShardID := uint32(0) walletAddress, err := cs.GenerateAndMintWalletAddress(walletAddressShardID, mintValue) require.Nil(t, err) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, minimumStakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) metachainNode := cs.GetNodeHandler(core.MetachainShardId) bls0, _ := hex.DecodeString(blsKeys[0]) - blsKeyStatus := getBLSKeyStatus(t, metachainNode, bls0) + blsKeyStatus := staking.GetBLSKeyStatus(t, metachainNode, bls0) require.Equal(t, "staked", blsKeyStatus) // do unStake - txUnStake := generateTransaction(walletAddress.Bytes, 1, vm.ValidatorSCAddress, zeroValue, fmt.Sprintf("unStake@%s", blsKeys[0]), gasLimitForStakeOperation) - unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, maxNumOfBlockToGenerateWhenExecutingTx) + txUnStake := staking.GenerateTransaction(walletAddress.Bytes, 1, vm.ValidatorSCAddress, staking.ZeroValue, fmt.Sprintf("unStake@%s", blsKeys[0]), staking.GasLimitForStakeOperation) + unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) - blsKeyStatus = getBLSKeyStatus(t, metachainNode, bls0) + blsKeyStatus = staking.GetBLSKeyStatus(t, metachainNode, bls0) require.Equal(t, "unStaked", blsKeyStatus) err = cs.GenerateBlocksUntilEpochIsReached(targetEpoch + 1) require.Nil(t, err) // do unBond - txUnBond := generateTransaction(walletAddress.Bytes, 2, vm.ValidatorSCAddress, zeroValue, fmt.Sprintf("unBondNodes@%s", blsKeys[0]), gasLimitForStakeOperation) - unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, maxNumOfBlockToGenerateWhenExecutingTx) + txUnBond := staking.GenerateTransaction(walletAddress.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, fmt.Sprintf("unBondNodes@%s", blsKeys[0]), staking.GasLimitForStakeOperation) + unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) // do claim - txClaim := generateTransaction(walletAddress.Bytes, 3, vm.ValidatorSCAddress, zeroValue, "unBondTokens", gasLimitForStakeOperation) - claimTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txClaim, maxNumOfBlockToGenerateWhenExecutingTx) + txClaim := staking.GenerateTransaction(walletAddress.Bytes, 3, vm.ValidatorSCAddress, staking.ZeroValue, "unBondTokens", staking.GasLimitForStakeOperation) + claimTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txClaim, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, claimTx) @@ -393,7 +393,7 @@ func testStakeUnStakeUnBond(t *testing.T, targetEpoch int32) { walletAccount, _, err := cs.GetNodeHandler(walletAddressShardID).GetFacadeHandler().GetAccount(walletAddress.Bech32, coreAPI.AccountQueryOptions{}) require.Nil(t, err) walletBalanceBig, _ := big.NewInt(0).SetString(walletAccount.Balance, 10) - require.True(t, walletBalanceBig.Cmp(minimumStakeValue) > 0) + require.True(t, walletBalanceBig.Cmp(staking.MinimumStakeValue) > 0) } func checkTotalQualified(t *testing.T, auctionList []*common.AuctionListValidatorAPIResponse, expected int) { @@ -576,25 +576,25 @@ func testChainSimulatorDirectStakedNodesStakingFunds(t *testing.T, cs chainSimul metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(5010) - mintValue = mintValue.Mul(oneEGLD, mintValue) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Set(minimumStakeValue) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + stakeValue := big.NewInt(0).Set(staking.MinimumStakeValue) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) err = cs.GenerateBlocks(2) // allow the metachain to finalize the block that contains the staking of the node require.Nil(t, err) - stakeValue = big.NewInt(0).Set(minimumStakeValue) - txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], mockBLSSignature) - txStake = generateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + stakeValue = big.NewInt(0).Set(staking.MinimumStakeValue) + txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], staking.MockBLSSignature) + txStake = staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -606,10 +606,10 @@ func testChainSimulatorDirectStakedNodesStakingFunds(t *testing.T, cs chainSimul log.Info("Step 2. Create from the owner of the staked nodes a tx to stake 1 EGLD") - stakeValue = big.NewInt(0).Mul(oneEGLD, big.NewInt(1)) - txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake = generateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + stakeValue = big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(1)) + txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake = staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -624,7 +624,7 @@ func checkExpectedStakedValue(t *testing.T, metachainNode chainSimulatorProcess. totalStaked := getTotalStaked(t, metachainNode, blsKey) expectedStaked := big.NewInt(expectedValue) - expectedStaked = expectedStaked.Mul(oneEGLD, expectedStaked) + expectedStaked = expectedStaked.Mul(staking.OneEGLD, expectedStaked) require.Equal(t, expectedStaked.String(), string(totalStaked)) } @@ -638,7 +638,7 @@ func getTotalStaked(t *testing.T, metachainNode chainSimulatorProcess.NodeHandle } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) + require.Equal(t, staking.OkReturnCode, result.ReturnCode) return result.ReturnData[0] } @@ -804,15 +804,15 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivation(t *testing.T, cs metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(5010) - mintValue = mintValue.Mul(oneEGLD, mintValue) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Set(minimumStakeValue) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + stakeValue := big.NewInt(0).Set(staking.MinimumStakeValue) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -821,10 +821,10 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivation(t *testing.T, cs testBLSKeyStaked(t, metachainNode, blsKeys[0]) - stakeValue = big.NewInt(0).Set(minimumStakeValue) - txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], mockBLSSignature) - txStake = generateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + stakeValue = big.NewInt(0).Set(staking.MinimumStakeValue) + txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], staking.MockBLSSignature) + txStake = staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -839,10 +839,10 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivation(t *testing.T, cs log.Info("Step 2. Create from the owner of staked nodes a transaction to unstake 10 EGLD and send it to the network") unStakeValue := big.NewInt(10) - unStakeValue = unStakeValue.Mul(oneEGLD, unStakeValue) + unStakeValue = unStakeValue.Mul(staking.OneEGLD, unStakeValue) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue.Bytes())) - txUnStake := generateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForStakeOperation) - unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, maxNumOfBlockToGenerateWhenExecutingTx) + txUnStake := staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -855,7 +855,7 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivation(t *testing.T, cs unStakedTokensAmount := getUnStakedTokensList(t, metachainNode, validatorOwner.Bytes) expectedUnStaked := big.NewInt(10) - expectedUnStaked = expectedUnStaked.Mul(oneEGLD, expectedUnStaked) + expectedUnStaked = expectedUnStaked.Mul(staking.OneEGLD, expectedUnStaked) require.Equal(t, expectedUnStaked.String(), big.NewInt(0).SetBytes(unStakedTokensAmount).String()) log.Info("Step 4. Wait for change of epoch and check the outcome") @@ -875,7 +875,7 @@ func getUnStakedTokensList(t *testing.T, metachainNode chainSimulatorProcess.Nod } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) + require.Equal(t, staking.OkReturnCode, result.ReturnCode) return result.ReturnData[0] } @@ -885,16 +885,16 @@ func checkOneOfTheNodesIsUnstaked(t *testing.T, blsKeys []string, ) { decodedBLSKey0, _ := hex.DecodeString(blsKeys[0]) - keyStatus0 := getBLSKeyStatus(t, metachainNode, decodedBLSKey0) + keyStatus0 := staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey0) log.Info("Key info", "key", blsKeys[0], "status", keyStatus0) - isNotStaked0 := keyStatus0 == unStakedStatus + isNotStaked0 := keyStatus0 == staking.UnStakedStatus decodedBLSKey1, _ := hex.DecodeString(blsKeys[1]) - keyStatus1 := getBLSKeyStatus(t, metachainNode, decodedBLSKey1) + keyStatus1 := staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey1) log.Info("Key info", "key", blsKeys[1], "status", keyStatus1) - isNotStaked1 := keyStatus1 == unStakedStatus + isNotStaked1 := keyStatus1 == staking.UnStakedStatus require.True(t, isNotStaked0 != isNotStaked1) } @@ -912,14 +912,14 @@ func testBLSKeyStaked(t *testing.T, activationEpoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step1Flag) if activationEpoch <= metachainNode.GetCoreComponents().EnableEpochsHandler().GetCurrentEpoch() { - require.Equal(t, stakedStatus, getBLSKeyStatus(t, metachainNode, decodedBLSKey)) + require.Equal(t, staking.StakedStatus, staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey)) return } // in staking ph 2/3.5 we do not find the bls key on the validator statistics _, found := validatorStatistics[blsKey] require.False(t, found) - require.Equal(t, queuedStatus, getBLSKeyStatus(t, metachainNode, decodedBLSKey)) + require.Equal(t, staking.QueuedStatus, staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey)) } // Test description: @@ -1085,15 +1085,15 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivationAndReactivation(t metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(6000) - mintValue = mintValue.Mul(oneEGLD, mintValue) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Set(minimumStakeValue) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + stakeValue := big.NewInt(0).Set(staking.MinimumStakeValue) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1102,10 +1102,10 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivationAndReactivation(t testBLSKeyStaked(t, metachainNode, blsKeys[0]) - stakeValue = big.NewInt(0).Set(minimumStakeValue) - txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], mockBLSSignature) - txStake = generateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + stakeValue = big.NewInt(0).Set(staking.MinimumStakeValue) + txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], staking.MockBLSSignature) + txStake = staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1120,10 +1120,10 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivationAndReactivation(t log.Info("Step 2. Create from the owner of staked nodes a transaction to unstake 10 EGLD and send it to the network") unStakeValue := big.NewInt(10) - unStakeValue = unStakeValue.Mul(oneEGLD, unStakeValue) + unStakeValue = unStakeValue.Mul(staking.OneEGLD, unStakeValue) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue.Bytes())) - txUnStake := generateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForStakeOperation) - unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, maxNumOfBlockToGenerateWhenExecutingTx) + txUnStake := staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -1136,16 +1136,16 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivationAndReactivation(t unStakedTokensAmount := getUnStakedTokensList(t, metachainNode, validatorOwner.Bytes) expectedUnStaked := big.NewInt(10) - expectedUnStaked = expectedUnStaked.Mul(oneEGLD, expectedUnStaked) + expectedUnStaked = expectedUnStaked.Mul(staking.OneEGLD, expectedUnStaked) require.Equal(t, expectedUnStaked.String(), big.NewInt(0).SetBytes(unStakedTokensAmount).String()) log.Info("Step 4. Create from the owner of staked nodes a transaction to stake 10 EGLD and send it to the network") newStakeValue := big.NewInt(10) - newStakeValue = newStakeValue.Mul(oneEGLD, newStakeValue) - txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake = generateTransaction(validatorOwner.Bytes, 3, vm.ValidatorSCAddress, newStakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + newStakeValue = newStakeValue.Mul(staking.OneEGLD, newStakeValue) + txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake = staking.GenerateTransaction(validatorOwner.Bytes, 3, vm.ValidatorSCAddress, newStakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1315,15 +1315,15 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsBeforeUnbonding(t *testi metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(10000) - mintValue = mintValue.Mul(oneEGLD, mintValue) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(2600)) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + stakeValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(2600)) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1340,10 +1340,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsBeforeUnbonding(t *testi log.Info("Step 1. Create from the owner of staked nodes a transaction to withdraw the unstaked funds") unStakeValue := big.NewInt(10) - unStakeValue = unStakeValue.Mul(oneEGLD, unStakeValue) + unStakeValue = unStakeValue.Mul(staking.OneEGLD, unStakeValue) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue.Bytes())) - txUnStake := generateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForStakeOperation) - unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, maxNumOfBlockToGenerateWhenExecutingTx) + txUnStake := staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -1354,8 +1354,8 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsBeforeUnbonding(t *testi testBLSKeyStaked(t, metachainNode, blsKeys[0]) txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) - txUnBond := generateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForUnBond) - unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, maxNumOfBlockToGenerateWhenExecutingTx) + txUnBond := staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForUnBond) + unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) @@ -1373,10 +1373,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsBeforeUnbonding(t *testi } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) + require.Equal(t, staking.OkReturnCode, result.ReturnCode) expectedUnStaked := big.NewInt(10) - expectedUnStaked = expectedUnStaked.Mul(oneEGLD, expectedUnStaked) + expectedUnStaked = expectedUnStaked.Mul(staking.OneEGLD, expectedUnStaked) require.Equal(t, expectedUnStaked.String(), big.NewInt(0).SetBytes(result.ReturnData[0]).String()) // the owner balance should decrease only with the txs fee @@ -1549,15 +1549,15 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInFirstEpoch(t *testing. metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(10000) - mintValue = mintValue.Mul(oneEGLD, mintValue) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(2600)) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + stakeValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(2600)) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1572,10 +1572,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInFirstEpoch(t *testing. balanceBeforeUnbonding, _ := big.NewInt(0).SetString(accountValidatorOwner.Balance, 10) unStakeValue := big.NewInt(10) - unStakeValue = unStakeValue.Mul(oneEGLD, unStakeValue) + unStakeValue = unStakeValue.Mul(staking.OneEGLD, unStakeValue) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue.Bytes())) - txUnStake := generateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForStakeOperation) - unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, maxNumOfBlockToGenerateWhenExecutingTx) + txUnStake := staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -1594,10 +1594,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInFirstEpoch(t *testing. } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) + require.Equal(t, staking.OkReturnCode, result.ReturnCode) expectedUnStaked := big.NewInt(10) - expectedUnStaked = expectedUnStaked.Mul(oneEGLD, expectedUnStaked) + expectedUnStaked = expectedUnStaked.Mul(staking.OneEGLD, expectedUnStaked) require.Equal(t, expectedUnStaked.String(), big.NewInt(0).SetBytes(result.ReturnData[0]).String()) log.Info("Step 1. Wait for the unbonding epoch to start") @@ -1608,8 +1608,8 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInFirstEpoch(t *testing. log.Info("Step 2. Create from the owner of staked nodes a transaction to withdraw the unstaked funds") txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) - txUnBond := generateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForUnBond) - unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, maxNumOfBlockToGenerateWhenExecutingTx) + txUnBond := staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForUnBond) + unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) @@ -1627,10 +1627,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInFirstEpoch(t *testing. } result, _, err = metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) + require.Equal(t, staking.OkReturnCode, result.ReturnCode) expectedStaked := big.NewInt(2590) - expectedStaked = expectedStaked.Mul(oneEGLD, expectedStaked) + expectedStaked = expectedStaked.Mul(staking.OneEGLD, expectedStaked) require.Equal(t, expectedStaked.String(), string(result.ReturnData[0])) // the owner balance should increase with the (10 EGLD - tx fee) @@ -1820,15 +1820,15 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(2700) - mintValue = mintValue.Mul(oneEGLD, mintValue) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(2600)) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + stakeValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(2600)) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1848,10 +1848,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, log.Info("Step 2. Send the transactions in consecutive epochs, one TX in each epoch.") unStakeValue1 := big.NewInt(11) - unStakeValue1 = unStakeValue1.Mul(oneEGLD, unStakeValue1) + unStakeValue1 = unStakeValue1.Mul(staking.OneEGLD, unStakeValue1) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue1.Bytes())) - txUnStake := generateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForStakeOperation) - unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, maxNumOfBlockToGenerateWhenExecutingTx) + txUnStake := staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -1862,10 +1862,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, require.Nil(t, err) unStakeValue2 := big.NewInt(12) - unStakeValue2 = unStakeValue2.Mul(oneEGLD, unStakeValue2) + unStakeValue2 = unStakeValue2.Mul(staking.OneEGLD, unStakeValue2) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue2.Bytes())) - txUnStake = generateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForStakeOperation) - unStakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, maxNumOfBlockToGenerateWhenExecutingTx) + txUnStake = staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + unStakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -1874,10 +1874,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, require.Nil(t, err) unStakeValue3 := big.NewInt(13) - unStakeValue3 = unStakeValue3.Mul(oneEGLD, unStakeValue3) + unStakeValue3 = unStakeValue3.Mul(staking.OneEGLD, unStakeValue3) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue3.Bytes())) - txUnStake = generateTransaction(validatorOwner.Bytes, 3, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForStakeOperation) - unStakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, maxNumOfBlockToGenerateWhenExecutingTx) + txUnStake = staking.GenerateTransaction(validatorOwner.Bytes, 3, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + unStakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -1897,10 +1897,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) + require.Equal(t, staking.OkReturnCode, result.ReturnCode) expectedUnStaked := big.NewInt(11) - expectedUnStaked = expectedUnStaked.Mul(oneEGLD, expectedUnStaked) + expectedUnStaked = expectedUnStaked.Mul(staking.OneEGLD, expectedUnStaked) require.Equal(t, expectedUnStaked.String(), big.NewInt(0).SetBytes(result.ReturnData[0]).String()) scQuery = &process.SCQuery{ @@ -1912,10 +1912,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, } result, _, err = metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) + require.Equal(t, staking.OkReturnCode, result.ReturnCode) expectedStaked := big.NewInt(2600 - 11 - 12 - 13) - expectedStaked = expectedStaked.Mul(oneEGLD, expectedStaked) + expectedStaked = expectedStaked.Mul(staking.OneEGLD, expectedStaked) require.Equal(t, expectedStaked.String(), string(result.ReturnData[0])) log.Info("Step 3. Wait for the unbonding epoch to start") @@ -1927,8 +1927,8 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, log.Info("Step 4.1. Create from the owner of staked nodes a transaction to withdraw the unstaked funds") txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) - txUnBond := generateTransaction(validatorOwner.Bytes, 4, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForUnBond) - unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, maxNumOfBlockToGenerateWhenExecutingTx) + txUnBond := staking.GenerateTransaction(validatorOwner.Bytes, 4, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForUnBond) + unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) @@ -1963,8 +1963,8 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, require.Nil(t, err) txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) - txUnBond = generateTransaction(validatorOwner.Bytes, 5, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForUnBond) - unBondTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, maxNumOfBlockToGenerateWhenExecutingTx) + txUnBond = staking.GenerateTransaction(validatorOwner.Bytes, 5, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForUnBond) + unBondTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) @@ -1991,8 +1991,8 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, require.Nil(t, err) txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) - txUnBond = generateTransaction(validatorOwner.Bytes, 6, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForUnBond) - unBondTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, maxNumOfBlockToGenerateWhenExecutingTx) + txUnBond = staking.GenerateTransaction(validatorOwner.Bytes, 6, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForUnBond) + unBondTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) @@ -2176,15 +2176,15 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(2700) - mintValue = mintValue.Mul(oneEGLD, mintValue) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(2600)) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + stakeValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(2600)) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -2204,28 +2204,28 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs log.Info("Step 2. Send the transactions in consecutively in same epoch.") unStakeValue1 := big.NewInt(11) - unStakeValue1 = unStakeValue1.Mul(oneEGLD, unStakeValue1) + unStakeValue1 = unStakeValue1.Mul(staking.OneEGLD, unStakeValue1) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue1.Bytes())) - txUnStake := generateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForStakeOperation) - unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, maxNumOfBlockToGenerateWhenExecutingTx) + txUnStake := staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) unStakeTxFee, _ := big.NewInt(0).SetString(unStakeTx.Fee, 10) unStakeValue2 := big.NewInt(12) - unStakeValue2 = unStakeValue2.Mul(oneEGLD, unStakeValue2) + unStakeValue2 = unStakeValue2.Mul(staking.OneEGLD, unStakeValue2) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue2.Bytes())) - txUnStake = generateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForStakeOperation) - unStakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, maxNumOfBlockToGenerateWhenExecutingTx) + txUnStake = staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + unStakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) unStakeValue3 := big.NewInt(13) - unStakeValue3 = unStakeValue3.Mul(oneEGLD, unStakeValue3) + unStakeValue3 = unStakeValue3.Mul(staking.OneEGLD, unStakeValue3) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue3.Bytes())) - txUnStake = generateTransaction(validatorOwner.Bytes, 3, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForStakeOperation) - unStakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, maxNumOfBlockToGenerateWhenExecutingTx) + txUnStake = staking.GenerateTransaction(validatorOwner.Bytes, 3, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + unStakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -2241,10 +2241,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) + require.Equal(t, staking.OkReturnCode, result.ReturnCode) expectedUnStaked := big.NewInt(11 + 12 + 13) - expectedUnStaked = expectedUnStaked.Mul(oneEGLD, expectedUnStaked) + expectedUnStaked = expectedUnStaked.Mul(staking.OneEGLD, expectedUnStaked) require.Equal(t, expectedUnStaked.String(), big.NewInt(0).SetBytes(result.ReturnData[0]).String()) scQuery = &process.SCQuery{ @@ -2256,10 +2256,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs } result, _, err = metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) + require.Equal(t, staking.OkReturnCode, result.ReturnCode) expectedStaked := big.NewInt(2600 - 11 - 12 - 13) - expectedStaked = expectedStaked.Mul(oneEGLD, expectedStaked) + expectedStaked = expectedStaked.Mul(staking.OneEGLD, expectedStaked) require.Equal(t, expectedStaked.String(), string(result.ReturnData[0])) log.Info("Step 3. Wait for the unbonding epoch to start") @@ -2271,8 +2271,8 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs log.Info("Step 4.1. Create from the owner of staked nodes a transaction to withdraw the unstaked funds") txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) - txUnBond := generateTransaction(validatorOwner.Bytes, 4, vm.ValidatorSCAddress, zeroValue, txDataField, gasLimitForUnBond) - unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, maxNumOfBlockToGenerateWhenExecutingTx) + txUnBond := staking.GenerateTransaction(validatorOwner.Bytes, 4, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForUnBond) + unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) diff --git a/integrationTests/chainSimulator/staking/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go similarity index 84% rename from integrationTests/chainSimulator/staking/delegation_test.go rename to integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index baa138f4430..4b2354eb0fe 100644 --- a/integrationTests/chainSimulator/staking/delegation_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go @@ -1,9 +1,11 @@ -package staking +package stakingProvider import ( "crypto/rand" "encoding/hex" "fmt" + "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" + logger "github.com/multiversx/mx-chain-logger-go" "math/big" "strings" "testing" @@ -21,7 +23,6 @@ import ( chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" - "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/process" @@ -30,33 +31,19 @@ import ( "github.com/stretchr/testify/require" ) -const mockBLSSignature = "010101" -const gasLimitForStakeOperation = 50_000_000 +var log = logger.GetOrCreate("stakingProvider") + const gasLimitForConvertOperation = 510_000_000 const gasLimitForDelegationContractCreationOperation = 500_000_000 const gasLimitForAddNodesOperation = 500_000_000 const gasLimitForUndelegateOperation = 500_000_000 const gasLimitForMergeOperation = 600_000_000 const gasLimitForDelegate = 12_000_000 -const gasLimitForUnBond = 12_000_000 -const minGasPrice = 1000000000 -const txVersion = 1 -const mockTxSignature = "sig" -const queuedStatus = "queued" -const stakedStatus = "staked" -const notStakedStatus = "notStaked" -const unStakedStatus = "unStaked" -const auctionStatus = "auction" -const okReturnCode = "ok" + const maxCap = "00" // no cap const hexServiceFee = "0ea1" // 37.45% const walletAddressBytesLen = 32 -var initialDelegationValue = big.NewInt(0).Mul(oneEGLD, big.NewInt(1250)) -var zeroValue = big.NewInt(0) -var oneEGLD = big.NewInt(1000000000000000000) -var minimumStakeValue = big.NewInt(0).Mul(oneEGLD, big.NewInt(2500)) - // Test description: // Test that delegation contract created with MakeNewContractFromValidatorData works properly // Also check that delegate and undelegate works properly and the top-up remain the same if every delegator undelegates. @@ -237,7 +224,7 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi log.Info("Step 2. Set the initial state for the owner and the 2 delegators") mintValue := big.NewInt(3010) - mintValue = mintValue.Mul(oneEGLD, mintValue) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) @@ -252,12 +239,12 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi "newValidatorOwner", validatorOwner.Bech32, "delegator1", delegator1.Bech32, "delegator2", delegator2.Bech32) log.Info("Step 3. Do a stake transaction for the validator key and test that the new key is on queue / auction list and the correct topup") - stakeValue := big.NewInt(0).Set(minimumStakeValue) - addedStakedValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(500)) + stakeValue := big.NewInt(0).Set(staking.MinimumStakeValue) + addedStakedValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(500)) stakeValue.Add(stakeValue, addedStakedValue) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -268,8 +255,8 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi log.Info("Step 4. Execute the MakeNewContractFromValidatorData transaction and test that the key is on queue / auction list and the correct topup") txDataField = fmt.Sprintf("makeNewContractFromValidatorData@%s@%s", maxCap, hexServiceFee) - txConvert := generateTransaction(validatorOwner.Bytes, 1, vm.DelegationManagerSCAddress, zeroValue, txDataField, gasLimitForConvertOperation) - convertTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txConvert, maxNumOfBlockToGenerateWhenExecutingTx) + txConvert := staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.DelegationManagerSCAddress, staking.ZeroValue, txDataField, gasLimitForConvertOperation) + convertTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txConvert, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, convertTx) @@ -283,35 +270,35 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], addedStakedValue, 1) log.Info("Step 5. Execute 2 delegation operations of 100 EGLD each, check the topup is 700") - delegateValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(100)) - txDelegate1 := generateTransaction(delegator1.Bytes, 0, delegationAddress, delegateValue, "delegate", gasLimitForDelegate) - delegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate1, maxNumOfBlockToGenerateWhenExecutingTx) + delegateValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(100)) + txDelegate1 := staking.GenerateTransaction(delegator1.Bytes, 0, delegationAddress, delegateValue, "delegate", gasLimitForDelegate) + delegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate1, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegate1Tx) - txDelegate2 := generateTransaction(delegator2.Bytes, 0, delegationAddress, delegateValue, "delegate", gasLimitForDelegate) - delegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate2, maxNumOfBlockToGenerateWhenExecutingTx) + txDelegate2 := staking.GenerateTransaction(delegator2.Bytes, 0, delegationAddress, delegateValue, "delegate", gasLimitForDelegate) + delegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate2, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegate2Tx) - expectedTopUp := big.NewInt(0).Mul(oneEGLD, big.NewInt(700)) + expectedTopUp := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(700)) testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], expectedTopUp, 1) log.Info("6. Execute 2 unDelegate operations of 100 EGLD each, check the topup is back to 500") - unDelegateValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(100)) + unDelegateValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(100)) txDataField = fmt.Sprintf("unDelegate@%s", hex.EncodeToString(unDelegateValue.Bytes())) - txUnDelegate1 := generateTransaction(delegator1.Bytes, 1, delegationAddress, zeroValue, txDataField, gasLimitForDelegate) - unDelegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnDelegate1, maxNumOfBlockToGenerateWhenExecutingTx) + txUnDelegate1 := staking.GenerateTransaction(delegator1.Bytes, 1, delegationAddress, staking.ZeroValue, txDataField, gasLimitForDelegate) + unDelegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnDelegate1, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unDelegate1Tx) txDataField = fmt.Sprintf("unDelegate@%s", hex.EncodeToString(unDelegateValue.Bytes())) - txUnDelegate2 := generateTransaction(delegator2.Bytes, 1, delegationAddress, zeroValue, txDataField, gasLimitForDelegate) - unDelegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnDelegate2, maxNumOfBlockToGenerateWhenExecutingTx) + txUnDelegate2 := staking.GenerateTransaction(delegator2.Bytes, 1, delegationAddress, staking.ZeroValue, txDataField, gasLimitForDelegate) + unDelegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnDelegate2, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unDelegate2Tx) - expectedTopUp = big.NewInt(0).Mul(oneEGLD, big.NewInt(500)) + expectedTopUp = big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(500)) testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], expectedTopUp, 1) } @@ -332,7 +319,7 @@ func testBLSKeyIsInQueueOrAuction(t *testing.T, metachainNode chainSimulatorProc // in staking ph 2/3.5 we do not find the bls key on the validator statistics _, found := statistics[blsKey] require.False(t, found) - require.Equal(t, queuedStatus, getBLSKeyStatus(t, metachainNode, decodedBLSKey)) + require.Equal(t, staking.QueuedStatus, staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey)) } func testBLSKeyIsInAuction( @@ -346,7 +333,7 @@ func testBLSKeyIsInAuction( numNodes int, owner []byte, ) { - require.Equal(t, stakedStatus, getBLSKeyStatus(t, metachainNode, blsKeyBytes)) + require.Equal(t, staking.StakedStatus, staking.GetBLSKeyStatus(t, metachainNode, blsKeyBytes)) err := metachainNode.GetProcessComponents().ValidatorsProvider().ForceUpdate() require.Nil(t, err) @@ -387,7 +374,7 @@ func testBLSKeyIsInAuction( // in staking ph 4 we should find the key in the validators statics validatorInfo, found := validatorStatistics[blsKey] require.True(t, found) - require.Equal(t, auctionStatus, validatorInfo.ValidatorStatus) + require.Equal(t, staking.AuctionStatus, validatorInfo.ValidatorStatus) } func testBLSKeysAreInQueueOrAuction(t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, address []byte, blsKeys []string, totalTopUp *big.Int, actionListSize int) { @@ -411,7 +398,7 @@ func testBLSKeysAreInQueueOrAuction(t *testing.T, metachainNode chainSimulatorPr // in staking ph 2/3.5 we do not find the bls key on the validator statistics _, found := statistics[blsKey] require.False(t, found) - require.Equal(t, queuedStatus, getBLSKeyStatus(t, metachainNode, decodedBLSKey)) + require.Equal(t, staking.QueuedStatus, staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey)) } } @@ -567,7 +554,7 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith2StakingContracts(t * log.Info("Step 2. Set the initial state for 2 owners") mintValue := big.NewInt(3010) - mintValue = mintValue.Mul(oneEGLD, mintValue) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) validatorOwnerA, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) @@ -580,15 +567,15 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith2StakingContracts(t * log.Info("Step 3. Do 2 stake transactions and test that the new keys are on queue / auction list and have the correct topup") - topupA := big.NewInt(0).Mul(oneEGLD, big.NewInt(100)) - stakeValueA := big.NewInt(0).Add(minimumStakeValue, topupA) + topupA := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(100)) + stakeValueA := big.NewInt(0).Add(staking.MinimumStakeValue, topupA) txStakeA := generateStakeTransaction(t, cs, validatorOwnerA, blsKeys[0], stakeValueA) - topupB := big.NewInt(0).Mul(oneEGLD, big.NewInt(200)) - stakeValueB := big.NewInt(0).Add(minimumStakeValue, topupB) + topupB := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(200)) + stakeValueB := big.NewInt(0).Add(staking.MinimumStakeValue, topupB) txStakeB := generateStakeTransaction(t, cs, validatorOwnerB, blsKeys[1], stakeValueB) - stakeTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStakeA, txStakeB}, maxNumOfBlockToGenerateWhenExecutingTx) + stakeTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStakeA, txStakeB}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.Equal(t, 2, len(stakeTxs)) @@ -603,7 +590,7 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith2StakingContracts(t * txConvertA := generateConvertToStakingProviderTransaction(t, cs, validatorOwnerA) txConvertB := generateConvertToStakingProviderTransaction(t, cs, validatorOwnerB) - convertTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txConvertA, txConvertB}, maxNumOfBlockToGenerateWhenExecutingTx) + convertTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txConvertA, txConvertB}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.Equal(t, 2, len(convertTxs)) @@ -689,7 +676,7 @@ func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta defer cs.Close() // unbond succeeded because the nodes were on queue - testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnstakeAndUnbond(t, cs, 1, notStakedStatus) + testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnstakeAndUnbond(t, cs, 1, staking.NotStakedStatus) }) t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ @@ -721,7 +708,7 @@ func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta defer cs.Close() - testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnstakeAndUnbond(t, cs, 2, unStakedStatus) + testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnstakeAndUnbond(t, cs, 2, staking.UnStakedStatus) }) t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ @@ -753,7 +740,7 @@ func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta defer cs.Close() - testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnstakeAndUnbond(t, cs, 3, unStakedStatus) + testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnstakeAndUnbond(t, cs, 3, staking.UnStakedStatus) }) t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ @@ -785,7 +772,7 @@ func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta defer cs.Close() - testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnstakeAndUnbond(t, cs, 4, unStakedStatus) + testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnstakeAndUnbond(t, cs, 4, staking.UnStakedStatus) }) } @@ -808,7 +795,7 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta log.Info("Step 2. Set the initial state for 1 owner and 1 delegator") mintValue := big.NewInt(10001) - mintValue = mintValue.Mul(oneEGLD, mintValue) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) owner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) @@ -821,11 +808,11 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta log.Info("Step 3. Do a stake transaction and test that the new key is on queue / auction list and has the correct topup") - topup := big.NewInt(0).Mul(oneEGLD, big.NewInt(99)) - stakeValue := big.NewInt(0).Add(minimumStakeValue, topup) + topup := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(99)) + stakeValue := big.NewInt(0).Add(staking.MinimumStakeValue, topup) txStake := generateStakeTransaction(t, cs, owner, blsKeys[0], stakeValue) - stakeTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStake}, maxNumOfBlockToGenerateWhenExecutingTx) + stakeTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStake}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.Equal(t, 1, len(stakeTxs)) @@ -838,7 +825,7 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta txConvert := generateConvertToStakingProviderTransaction(t, cs, owner) - convertTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txConvert}, maxNumOfBlockToGenerateWhenExecutingTx) + convertTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txConvert}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.Equal(t, 1, len(convertTxs)) @@ -850,30 +837,30 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], topup, 1) log.Info("Step 5. Add 2 nodes in the staking contract") - txDataFieldAddNodes := fmt.Sprintf("addNodes@%s@%s@%s@%s", blsKeys[1], mockBLSSignature+"02", blsKeys[2], mockBLSSignature+"03") - ownerNonce := getNonce(t, cs, owner) - txAddNodes := generateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldAddNodes, gasLimitForStakeOperation) + txDataFieldAddNodes := fmt.Sprintf("addNodes@%s@%s@%s@%s", blsKeys[1], staking.MockBLSSignature+"02", blsKeys[2], staking.MockBLSSignature+"03") + ownerNonce := staking.GetNonce(t, cs, owner) + txAddNodes := staking.GenerateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldAddNodes, staking.GasLimitForStakeOperation) - addNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txAddNodes}, maxNumOfBlockToGenerateWhenExecutingTx) + addNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txAddNodes}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.Equal(t, 1, len(addNodesTxs)) log.Info("Step 6. Delegate 5000 EGLD to the contract") - delegateValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(5000)) + delegateValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(5000)) txDataFieldDelegate := "delegate" - delegatorNonce := getNonce(t, cs, delegator) - txDelegate := generateTransaction(delegator.Bytes, delegatorNonce, delegationAddress, delegateValue, txDataFieldDelegate, gasLimitForStakeOperation) + delegatorNonce := staking.GetNonce(t, cs, delegator) + txDelegate := staking.GenerateTransaction(delegator.Bytes, delegatorNonce, delegationAddress, delegateValue, txDataFieldDelegate, staking.GasLimitForStakeOperation) - delegateTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txDelegate}, maxNumOfBlockToGenerateWhenExecutingTx) + delegateTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txDelegate}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.Equal(t, 1, len(delegateTxs)) log.Info("Step 7. Stake the 2 nodes") txDataFieldStakeNodes := fmt.Sprintf("stakeNodes@%s@%s", blsKeys[1], blsKeys[2]) - ownerNonce = getNonce(t, cs, owner) - txStakeNodes := generateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldStakeNodes, gasLimitForStakeOperation) + ownerNonce = staking.GetNonce(t, cs, owner) + txStakeNodes := staking.GenerateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldStakeNodes, staking.GasLimitForStakeOperation) - stakeNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStakeNodes}, maxNumOfBlockToGenerateWhenExecutingTx) + stakeNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStakeNodes}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.Equal(t, 1, len(stakeNodesTxs)) @@ -886,10 +873,10 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta log.Info("Step 8. UnStake 2 nodes (latest staked)") txDataFieldUnStakeNodes := fmt.Sprintf("unStakeNodes@%s@%s", blsKeys[1], blsKeys[2]) - ownerNonce = getNonce(t, cs, owner) - txUnStakeNodes := generateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldUnStakeNodes, gasLimitForStakeOperation) + ownerNonce = staking.GetNonce(t, cs, owner) + txUnStakeNodes := staking.GenerateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldUnStakeNodes, staking.GasLimitForStakeOperation) - unStakeNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txUnStakeNodes}, maxNumOfBlockToGenerateWhenExecutingTx) + unStakeNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txUnStakeNodes}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.Equal(t, 1, len(unStakeNodesTxs)) @@ -904,58 +891,25 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta log.Info("Step 9. Unbond the 2 nodes (that were un staked)") txDataFieldUnBondNodes := fmt.Sprintf("unBondNodes@%s@%s", blsKeys[1], blsKeys[2]) - ownerNonce = getNonce(t, cs, owner) - txUnBondNodes := generateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldUnBondNodes, gasLimitForStakeOperation) + ownerNonce = staking.GetNonce(t, cs, owner) + txUnBondNodes := staking.GenerateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldUnBondNodes, staking.GasLimitForStakeOperation) - unBondNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txUnBondNodes}, maxNumOfBlockToGenerateWhenExecutingTx) + unBondNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txUnBondNodes}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.Equal(t, 1, len(unBondNodesTxs)) err = cs.GenerateBlocks(2) // allow the metachain to finalize the block that contains the staking of the nodes assert.Nil(t, err) - keyStatus := getAllNodeStates(t, metachainNode, delegationAddress) + keyStatus := staking.GetAllNodeStates(t, metachainNode, delegationAddress) require.Equal(t, len(blsKeys), len(keyStatus)) // key[0] should be staked - require.Equal(t, stakedStatus, keyStatus[blsKeys[0]]) + require.Equal(t, staking.StakedStatus, keyStatus[blsKeys[0]]) // key[1] and key[2] should be unstaked (unbond was not executed) require.Equal(t, nodesStatusAfterUnBondTx, keyStatus[blsKeys[1]]) require.Equal(t, nodesStatusAfterUnBondTx, keyStatus[blsKeys[2]]) } -func getNonce(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, address dtos.WalletAddress) uint64 { - account, err := cs.GetAccount(address) - require.Nil(t, err) - - return account.Nonce -} - -func getAllNodeStates(t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, address []byte) map[string]string { - scQuery := &process.SCQuery{ - ScAddress: address, - FuncName: "getAllNodeStates", - CallerAddr: vm.StakingSCAddress, - CallValue: big.NewInt(0), - } - result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) - require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) - - m := make(map[string]string) - status := "" - for _, resultData := range result.ReturnData { - if len(resultData) != 96 { - // not a BLS key - status = string(resultData) - continue - } - - m[hex.EncodeToString(resultData)] = status - } - - return m -} - func generateStakeTransaction( t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, @@ -966,8 +920,8 @@ func generateStakeTransaction( account, err := cs.GetAccount(owner) require.Nil(t, err) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeyHex, mockBLSSignature) - return generateTransaction(owner.Bytes, account.Nonce, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeyHex, staking.MockBLSSignature) + return staking.GenerateTransaction(owner.Bytes, account.Nonce, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) } func generateConvertToStakingProviderTransaction( @@ -979,7 +933,7 @@ func generateConvertToStakingProviderTransaction( require.Nil(t, err) txDataField := fmt.Sprintf("makeNewContractFromValidatorData@%s@%s", maxCap, hexServiceFee) - return generateTransaction(owner.Bytes, account.Nonce, vm.DelegationManagerSCAddress, zeroValue, txDataField, gasLimitForConvertOperation) + return staking.GenerateTransaction(owner.Bytes, account.Nonce, vm.DelegationManagerSCAddress, staking.ZeroValue, txDataField, gasLimitForConvertOperation) } // Test description @@ -1174,7 +1128,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat delegator1, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(delegator1Bytes) delegator2Bytes := generateWalletAddressBytes() delegator2, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(delegator2Bytes) - initialFunds := big.NewInt(0).Mul(oneEGLD, big.NewInt(10000)) // 10000 EGLD for each + initialFunds := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(10000)) // 10000 EGLD for each addresses := []*dtos.AddressState{ {Address: validatorOwner, Balance: initialFunds.String()}, {Address: delegator1, Balance: initialFunds.String()}, @@ -1184,11 +1138,11 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Nil(t, err) // Step 3: Create a new delegation contract - maxDelegationCap := big.NewInt(0).Mul(oneEGLD, big.NewInt(51000)) // 51000 EGLD cap - txCreateDelegationContract := generateTransaction(validatorOwnerBytes, 0, vm.DelegationManagerSCAddress, initialDelegationValue, + maxDelegationCap := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(51000)) // 51000 EGLD cap + txCreateDelegationContract := staking.GenerateTransaction(validatorOwnerBytes, 0, vm.DelegationManagerSCAddress, staking.InitialDelegationValue, fmt.Sprintf("createNewDelegationContract@%s@%s", hex.EncodeToString(maxDelegationCap.Bytes()), hexServiceFee), gasLimitForDelegationContractCreationOperation) - createDelegationContractTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txCreateDelegationContract, maxNumOfBlockToGenerateWhenExecutingTx) + createDelegationContractTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txCreateDelegationContract, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, createDelegationContractTx) @@ -1217,12 +1171,12 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Nil(t, err) signatures := getSignatures(delegationContractAddressBytes, validatorSecretKeysBytes) - txAddNodes := generateTransaction(validatorOwnerBytes, 1, delegationContractAddressBytes, zeroValue, addNodesTxData(blsKeys, signatures), gasLimitForAddNodesOperation) - addNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txAddNodes, maxNumOfBlockToGenerateWhenExecutingTx) + txAddNodes := staking.GenerateTransaction(validatorOwnerBytes, 1, delegationContractAddressBytes, staking.ZeroValue, addNodesTxData(blsKeys, signatures), gasLimitForAddNodesOperation) + addNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txAddNodes, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, addNodesTx) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getAllNodeStates", nil) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "GetAllNodeStates", nil) require.Nil(t, err) stakedKeys, notStakedKeys, unStakedKeys := getNodesFromContract(output.ReturnData) require.Equal(t, 0, len(stakedKeys)) @@ -1230,8 +1184,8 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Equal(t, blsKeys[0], hex.EncodeToString(notStakedKeys[0])) require.Equal(t, 0, len(unStakedKeys)) - expectedTopUp := big.NewInt(0).Set(initialDelegationValue) - expectedTotalStaked := big.NewInt(0).Set(initialDelegationValue) + expectedTopUp := big.NewInt(0).Set(staking.InitialDelegationValue) + expectedTotalStaked := big.NewInt(0).Set(staking.InitialDelegationValue) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) @@ -1239,16 +1193,16 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{validatorOwnerBytes}) require.Nil(t, err) - require.Equal(t, initialDelegationValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, staking.InitialDelegationValue, big.NewInt(0).SetBytes(output.ReturnData[0])) // Step 3: Perform delegation operations - txDelegate1 := generateTransaction(delegator1Bytes, 0, delegationContractAddressBytes, initialDelegationValue, "delegate", gasLimitForDelegate) - delegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate1, maxNumOfBlockToGenerateWhenExecutingTx) + txDelegate1 := staking.GenerateTransaction(delegator1Bytes, 0, delegationContractAddressBytes, staking.InitialDelegationValue, "delegate", gasLimitForDelegate) + delegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate1, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegate1Tx) - expectedTopUp = expectedTopUp.Add(expectedTopUp, initialDelegationValue) - expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, initialDelegationValue) + expectedTopUp = expectedTopUp.Add(expectedTopUp, staking.InitialDelegationValue) + expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, staking.InitialDelegationValue) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) @@ -1256,15 +1210,15 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator1Bytes}) require.Nil(t, err) - require.Equal(t, initialDelegationValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, staking.InitialDelegationValue, big.NewInt(0).SetBytes(output.ReturnData[0])) - txDelegate2 := generateTransaction(delegator2Bytes, 0, delegationContractAddressBytes, initialDelegationValue, "delegate", gasLimitForDelegate) - delegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate2, maxNumOfBlockToGenerateWhenExecutingTx) + txDelegate2 := staking.GenerateTransaction(delegator2Bytes, 0, delegationContractAddressBytes, staking.InitialDelegationValue, "delegate", gasLimitForDelegate) + delegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate2, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegate2Tx) - expectedTopUp = expectedTopUp.Add(expectedTopUp, initialDelegationValue) - expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, initialDelegationValue) + expectedTopUp = expectedTopUp.Add(expectedTopUp, staking.InitialDelegationValue) + expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, staking.InitialDelegationValue) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) @@ -1272,20 +1226,20 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator2Bytes}) require.Nil(t, err) - require.Equal(t, initialDelegationValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, staking.InitialDelegationValue, big.NewInt(0).SetBytes(output.ReturnData[0])) // Step 4: Perform stakeNodes - txStakeNodes := generateTransaction(validatorOwnerBytes, 2, delegationContractAddressBytes, zeroValue, fmt.Sprintf("stakeNodes@%s", blsKeys[0]), gasLimitForStakeOperation) - stakeNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStakeNodes, maxNumOfBlockToGenerateWhenExecutingTx) + txStakeNodes := staking.GenerateTransaction(validatorOwnerBytes, 2, delegationContractAddressBytes, staking.ZeroValue, fmt.Sprintf("stakeNodes@%s", blsKeys[0]), staking.GasLimitForStakeOperation) + stakeNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStakeNodes, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeNodesTx) - expectedTopUp = expectedTopUp.Sub(expectedTopUp, initialDelegationValue) - expectedTopUp = expectedTopUp.Sub(expectedTopUp, initialDelegationValue) + expectedTopUp = expectedTopUp.Sub(expectedTopUp, staking.InitialDelegationValue) + expectedTopUp = expectedTopUp.Sub(expectedTopUp, staking.InitialDelegationValue) require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getAllNodeStates", nil) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "GetAllNodeStates", nil) require.Nil(t, err) stakedKeys, notStakedKeys, unStakedKeys = getNodesFromContract(output.ReturnData) require.Equal(t, 1, len(stakedKeys)) @@ -1303,13 +1257,13 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat // The nodes should remain in the staked state // The total active stake should be reduced by the amount undelegated - txUndelegate1 := generateTransaction(delegator1Bytes, 1, delegationContractAddressBytes, zeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(initialDelegationValue.Bytes())), gasLimitForUndelegateOperation) - undelegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUndelegate1, maxNumOfBlockToGenerateWhenExecutingTx) + txUndelegate1 := staking.GenerateTransaction(delegator1Bytes, 1, delegationContractAddressBytes, staking.ZeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(staking.InitialDelegationValue.Bytes())), gasLimitForUndelegateOperation) + undelegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUndelegate1, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, undelegate1Tx) - expectedTopUp = expectedTopUp.Sub(expectedTopUp, initialDelegationValue) - expectedTotalStaked = expectedTotalStaked.Sub(expectedTotalStaked, initialDelegationValue) + expectedTopUp = expectedTopUp.Sub(expectedTopUp, staking.InitialDelegationValue) + expectedTotalStaked = expectedTotalStaked.Sub(expectedTotalStaked, staking.InitialDelegationValue) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) @@ -1317,9 +1271,9 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator1Bytes}) require.Nil(t, err) - require.Equal(t, zeroValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, staking.ZeroValue, big.NewInt(0).SetBytes(output.ReturnData[0])) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getAllNodeStates", nil) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "GetAllNodeStates", nil) require.Nil(t, err) stakedKeys, notStakedKeys, unStakedKeys = getNodesFromContract(output.ReturnData) require.Equal(t, 1, len(stakedKeys)) @@ -1331,22 +1285,22 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat // The nodes should remain in the unStaked state // The total active stake should be reduced by the amount undelegated - txUndelegate2 := generateTransaction(delegator2Bytes, 1, delegationContractAddressBytes, zeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(initialDelegationValue.Bytes())), gasLimitForUndelegateOperation) - undelegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUndelegate2, maxNumOfBlockToGenerateWhenExecutingTx) + txUndelegate2 := staking.GenerateTransaction(delegator2Bytes, 1, delegationContractAddressBytes, staking.ZeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(staking.InitialDelegationValue.Bytes())), gasLimitForUndelegateOperation) + undelegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUndelegate2, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, undelegate2Tx) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, "1250000000000000000000", big.NewInt(0).SetBytes(output.ReturnData[0]).String()) - require.Equal(t, zeroValue, getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) + require.Equal(t, staking.ZeroValue, getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator2Bytes}) require.Nil(t, err) require.Equal(t, "0", big.NewInt(0).SetBytes(output.ReturnData[0]).String()) // still staked until epoch change - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getAllNodeStates", nil) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "GetAllNodeStates", nil) require.Nil(t, err) stakedKeys, notStakedKeys, unStakedKeys = getNodesFromContract(output.ReturnData) require.Equal(t, 1, len(stakedKeys)) @@ -1357,7 +1311,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat err = cs.GenerateBlocksUntilEpochIsReached(targetEpoch + 1) require.Nil(t, err) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getAllNodeStates", nil) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "GetAllNodeStates", nil) require.Nil(t, err) stakedKeys, notStakedKeys, unStakedKeys = getNodesFromContract(output.ReturnData) require.Equal(t, 0, len(stakedKeys)) @@ -1420,21 +1374,6 @@ func getNodesFromContract(returnData [][]byte) ([][]byte, [][]byte, [][]byte) { return stakedKeys, notStakedKeys, unStakedKeys } -func getBLSKeyStatus(t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, blsKey []byte) string { - scQuery := &process.SCQuery{ - ScAddress: vm.StakingSCAddress, - FuncName: "getBLSKeyStatus", - CallerAddr: vm.StakingSCAddress, - CallValue: big.NewInt(0), - Arguments: [][]byte{blsKey}, - } - result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) - require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) - - return string(result.ReturnData[0]) -} - func getBLSTopUpValue(t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, address []byte) *big.Int { scQuery := &process.SCQuery{ ScAddress: vm.ValidatorSCAddress, @@ -1445,7 +1384,7 @@ func getBLSTopUpValue(t *testing.T, metachainNode chainSimulatorProcess.NodeHand } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) + require.Equal(t, staking.OkReturnCode, result.ReturnCode) if len(result.ReturnData[0]) == 0 { return big.NewInt(0) @@ -1454,21 +1393,6 @@ func getBLSTopUpValue(t *testing.T, metachainNode chainSimulatorProcess.NodeHand return big.NewInt(0).SetBytes(result.ReturnData[0]) } -func generateTransaction(sender []byte, nonce uint64, receiver []byte, value *big.Int, data string, gasLimit uint64) *transaction.Transaction { - return &transaction.Transaction{ - Nonce: nonce, - Value: value, - SndAddr: sender, - RcvAddr: receiver, - Data: []byte(data), - GasLimit: gasLimit, - GasPrice: minGasPrice, - ChainID: []byte(configs.ChainID), - Version: txVersion, - Signature: []byte(mockTxSignature), - } -} - // Test description: // Test that merging delegation with whiteListForMerge and mergeValidatorToDelegationWithWhitelist contracts still works properly // Test that their topups will merge too and will be used by auction list computing. @@ -1632,7 +1556,7 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(3000) - mintValue = mintValue.Mul(oneEGLD, mintValue) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) validatorA, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) @@ -1641,12 +1565,12 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat require.Nil(t, err) log.Info("Step 1. User A: - stake 1 node to have 100 egld more than minimum stake value") - stakeValue := big.NewInt(0).Set(minimumStakeValue) - addedStakedValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(100)) + stakeValue := big.NewInt(0).Set(staking.MinimumStakeValue) + addedStakedValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(100)) stakeValue.Add(stakeValue, addedStakedValue) - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], mockBLSSignature) - txStake := generateTransaction(validatorA.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(validatorA.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1658,8 +1582,8 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat log.Info("Step 2. Execute MakeNewContractFromValidatorData for User A") txDataField = fmt.Sprintf("makeNewContractFromValidatorData@%s@%s", maxCap, hexServiceFee) - txConvert := generateTransaction(validatorA.Bytes, 1, vm.DelegationManagerSCAddress, zeroValue, txDataField, gasLimitForConvertOperation) - convertTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txConvert, maxNumOfBlockToGenerateWhenExecutingTx) + txConvert := staking.GenerateTransaction(validatorA.Bytes, 1, vm.DelegationManagerSCAddress, staking.ZeroValue, txDataField, gasLimitForConvertOperation) + convertTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txConvert, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, convertTx) @@ -1671,12 +1595,12 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], addedStakedValue, 1) log.Info("Step 3. User B: - stake 1 node to have 100 egld more") - stakeValue = big.NewInt(0).Set(minimumStakeValue) - addedStakedValue = big.NewInt(0).Mul(oneEGLD, big.NewInt(100)) + stakeValue = big.NewInt(0).Set(staking.MinimumStakeValue) + addedStakedValue = big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(100)) stakeValue.Add(stakeValue, addedStakedValue) - txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], mockBLSSignature) - txStake = generateTransaction(validatorB.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, gasLimitForStakeOperation) - stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], staking.MockBLSSignature) + txStake = staking.GenerateTransaction(validatorB.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1694,8 +1618,8 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat log.Info("Step 4. User A : whitelistForMerge@addressB") txDataField = fmt.Sprintf("whitelistForMerge@%s", hex.EncodeToString(validatorB.Bytes)) - whitelistForMerge := generateTransaction(validatorA.Bytes, 2, delegationAddress, zeroValue, txDataField, gasLimitForDelegate) - whitelistForMergeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(whitelistForMerge, maxNumOfBlockToGenerateWhenExecutingTx) + whitelistForMerge := staking.GenerateTransaction(validatorA.Bytes, 2, delegationAddress, staking.ZeroValue, txDataField, gasLimitForDelegate) + whitelistForMergeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(whitelistForMerge, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, whitelistForMergeTx) @@ -1705,8 +1629,8 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat log.Info("Step 5. User A : mergeValidatorToDelegationWithWhitelist") txDataField = fmt.Sprintf("mergeValidatorToDelegationWithWhitelist@%s", hex.EncodeToString(delegationAddress)) - txConvert = generateTransaction(validatorB.Bytes, 1, vm.DelegationManagerSCAddress, zeroValue, txDataField, gasLimitForMergeOperation) - convertTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txConvert, maxNumOfBlockToGenerateWhenExecutingTx) + txConvert = staking.GenerateTransaction(validatorB.Bytes, 1, vm.DelegationManagerSCAddress, staking.ZeroValue, txDataField, gasLimitForMergeOperation) + convertTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txConvert, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, convertTx) @@ -1719,7 +1643,7 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat decodedBLSKey1, _ = hex.DecodeString(blsKeys[1]) require.Equal(t, delegationAddress, getBLSKeyOwner(t, metachainNode, decodedBLSKey1)) - expectedTopUpValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(200)) + expectedTopUpValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(200)) require.Equal(t, expectedTopUpValue, getBLSTopUpValue(t, metachainNode, delegationAddress)) } @@ -1733,7 +1657,7 @@ func getBLSKeyOwner(t *testing.T, metachainNode chainSimulatorProcess.NodeHandle } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, okReturnCode, result.ReturnCode) + require.Equal(t, staking.OkReturnCode, result.ReturnCode) return result.ReturnData[0] } diff --git a/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go b/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go similarity index 68% rename from integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go rename to integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go index af50d56c821..1b197493ef4 100644 --- a/integrationTests/chainSimulator/staking/stakingProviderWithNodesinQueue_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go @@ -1,8 +1,10 @@ -package staking +package stakingProvider import ( "encoding/hex" "fmt" + "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" + "math/big" "testing" "time" @@ -17,6 +19,10 @@ import ( "github.com/stretchr/testify/require" ) +const ( + defaultPathToInitialConfig = "../../../../cmd/node/config/" +) + func TestStakingProviderWithNodes(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") @@ -65,7 +71,7 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati require.NotNil(t, cs) defer cs.Close() - mintValue := big.NewInt(0).Mul(big.NewInt(5000), oneEGLD) + mintValue := big.NewInt(0).Mul(big.NewInt(5000), staking.OneEGLD) validatorOwner, err := cs.GenerateAndMintWalletAddress(0, mintValue) require.Nil(t, err) require.Nil(t, err) @@ -76,8 +82,8 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati // create delegation contract stakeValue, _ := big.NewInt(0).SetString("4250000000000000000000", 10) dataField := "createNewDelegationContract@00@0ea1" - txStake := generateTransaction(validatorOwner.Bytes, getNonce(t, cs, validatorOwner), vm.DelegationManagerSCAddress, stakeValue, dataField, 80_000_000) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, maxNumOfBlockToGenerateWhenExecutingTx) + txStake := staking.GenerateTransaction(validatorOwner.Bytes, staking.GetNonce(t, cs, validatorOwner), vm.DelegationManagerSCAddress, stakeValue, dataField, 80_000_000) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -88,53 +94,53 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati _, blsKeys, err := chainSimulator.GenerateBlsPrivateKeys(1) require.Nil(t, err) - txDataFieldAddNodes := fmt.Sprintf("addNodes@%s@%s", blsKeys[0], mockBLSSignature+"02") - ownerNonce := getNonce(t, cs, validatorOwner) - txAddNodes := generateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), txDataFieldAddNodes, gasLimitForStakeOperation) - addNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txAddNodes, maxNumOfBlockToGenerateWhenExecutingTx) + txDataFieldAddNodes := fmt.Sprintf("addNodes@%s@%s", blsKeys[0], staking.MockBLSSignature+"02") + ownerNonce := staking.GetNonce(t, cs, validatorOwner) + txAddNodes := staking.GenerateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), txDataFieldAddNodes, staking.GasLimitForStakeOperation) + addNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txAddNodes, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, addNodesTx) txDataFieldStakeNodes := fmt.Sprintf("stakeNodes@%s", blsKeys[0]) - ownerNonce = getNonce(t, cs, validatorOwner) - txStakeNodes := generateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), txDataFieldStakeNodes, gasLimitForStakeOperation) + ownerNonce = staking.GetNonce(t, cs, validatorOwner) + txStakeNodes := staking.GenerateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), txDataFieldStakeNodes, staking.GasLimitForStakeOperation) - stakeNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStakeNodes}, maxNumOfBlockToGenerateWhenExecutingTx) + stakeNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStakeNodes}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.Equal(t, 1, len(stakeNodesTxs)) metachainNode := cs.GetNodeHandler(core.MetachainShardId) decodedBLSKey0, _ := hex.DecodeString(blsKeys[0]) - status := getBLSKeyStatus(t, metachainNode, decodedBLSKey0) + status := staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey0) require.Equal(t, "queued", status) // activate staking v4 err = cs.GenerateBlocksUntilEpochIsReached(int32(stakingV4ActivationEpoch)) require.Nil(t, err) - status = getBLSKeyStatus(t, metachainNode, decodedBLSKey0) + status = staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey0) require.Equal(t, "unStaked", status) - result := getAllNodeStates(t, metachainNode, delegationAddressBytes) + result := staking.GetAllNodeStates(t, metachainNode, delegationAddressBytes) require.NotNil(t, result) require.Equal(t, "unStaked", result[blsKeys[0]]) - ownerNonce = getNonce(t, cs, validatorOwner) + ownerNonce = staking.GetNonce(t, cs, validatorOwner) reStakeTxData := fmt.Sprintf("reStakeUnStakedNodes@%s", blsKeys[0]) - reStakeNodes := generateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), reStakeTxData, gasLimitForStakeOperation) - reStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(reStakeNodes, maxNumOfBlockToGenerateWhenExecutingTx) + reStakeNodes := staking.GenerateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), reStakeTxData, staking.GasLimitForStakeOperation) + reStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(reStakeNodes, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, reStakeTx) - status = getBLSKeyStatus(t, metachainNode, decodedBLSKey0) + status = staking.GetBLSKeyStatus(t, metachainNode, decodedBLSKey0) require.Equal(t, "staked", status) - result = getAllNodeStates(t, metachainNode, delegationAddressBytes) + result = staking.GetAllNodeStates(t, metachainNode, delegationAddressBytes) require.NotNil(t, result) require.Equal(t, "staked", result[blsKeys[0]]) err = cs.GenerateBlocks(20) require.Nil(t, err) - checkValidatorStatus(t, cs, blsKeys[0], "auction") + staking.CheckValidatorStatus(t, cs, blsKeys[0], "auction") } From 5b6ccb927cb6aa21314e1915081409f02f9acd79 Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 2 Apr 2024 13:21:13 +0300 Subject: [PATCH 149/503] fix test --- .../staking/stakingProvider/delegation_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index 4b2354eb0fe..4b44f2077e2 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go @@ -1176,7 +1176,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Nil(t, err) require.NotNil(t, addNodesTx) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "GetAllNodeStates", nil) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getAllNodeStates", nil) require.Nil(t, err) stakedKeys, notStakedKeys, unStakedKeys := getNodesFromContract(output.ReturnData) require.Equal(t, 0, len(stakedKeys)) @@ -1239,7 +1239,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat expectedTopUp = expectedTopUp.Sub(expectedTopUp, staking.InitialDelegationValue) require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "GetAllNodeStates", nil) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getAllNodeStates", nil) require.Nil(t, err) stakedKeys, notStakedKeys, unStakedKeys = getNodesFromContract(output.ReturnData) require.Equal(t, 1, len(stakedKeys)) @@ -1273,7 +1273,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Nil(t, err) require.Equal(t, staking.ZeroValue, big.NewInt(0).SetBytes(output.ReturnData[0])) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "GetAllNodeStates", nil) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getAllNodeStates", nil) require.Nil(t, err) stakedKeys, notStakedKeys, unStakedKeys = getNodesFromContract(output.ReturnData) require.Equal(t, 1, len(stakedKeys)) @@ -1300,7 +1300,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Equal(t, "0", big.NewInt(0).SetBytes(output.ReturnData[0]).String()) // still staked until epoch change - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "GetAllNodeStates", nil) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getAllNodeStates", nil) require.Nil(t, err) stakedKeys, notStakedKeys, unStakedKeys = getNodesFromContract(output.ReturnData) require.Equal(t, 1, len(stakedKeys)) @@ -1311,7 +1311,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat err = cs.GenerateBlocksUntilEpochIsReached(targetEpoch + 1) require.Nil(t, err) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "GetAllNodeStates", nil) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getAllNodeStates", nil) require.Nil(t, err) stakedKeys, notStakedKeys, unStakedKeys = getNodesFromContract(output.ReturnData) require.Equal(t, 0, len(stakedKeys)) From d9ef2e90306e215cb4db88754d1747cce049f2e6 Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 2 Apr 2024 13:37:40 +0300 Subject: [PATCH 150/503] fixes --- .../chainSimulator/staking/helpers.go | 21 ++++++++++++------- .../chainSimulator/staking/jail/jail_test.go | 3 ++- .../staking/stake/simpleStake_test.go | 2 +- .../staking/stake/stakeAndUnStake_test.go | 2 +- .../stakingProvider/delegation_test.go | 2 +- .../stakingProviderWithNodesinQueue_test.go | 3 +-- 6 files changed, 20 insertions(+), 13 deletions(-) diff --git a/integrationTests/chainSimulator/staking/helpers.go b/integrationTests/chainSimulator/staking/helpers.go index 550e227a7f2..ed42733f5a4 100644 --- a/integrationTests/chainSimulator/staking/helpers.go +++ b/integrationTests/chainSimulator/staking/helpers.go @@ -2,6 +2,9 @@ package staking import ( "encoding/hex" + "math/big" + "testing" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/transaction" chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" @@ -11,8 +14,6 @@ import ( "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/vm" "github.com/stretchr/testify/require" - "math/big" - "testing" ) const ( @@ -33,12 +34,14 @@ const ( AuctionStatus = "auction" ) -var InitialDelegationValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(1250)) -var ZeroValue = big.NewInt(0) - -var MinimumStakeValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(2500)) -var OneEGLD = big.NewInt(1000000000000000000) +var ( + ZeroValue = big.NewInt(0) + InitialDelegationValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(1250)) + MinimumStakeValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(2500)) + OneEGLD = big.NewInt(1000000000000000000) +) +// GetNonce will return the nonce of the provided address func GetNonce(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, address dtos.WalletAddress) uint64 { account, err := cs.GetAccount(address) require.Nil(t, err) @@ -46,6 +49,7 @@ func GetNonce(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, ad return account.Nonce } +// GenerateTransaction will generate a transaction based on input data func GenerateTransaction(sender []byte, nonce uint64, receiver []byte, value *big.Int, data string, gasLimit uint64) *transaction.Transaction { return &transaction.Transaction{ Nonce: nonce, @@ -61,6 +65,7 @@ func GenerateTransaction(sender []byte, nonce uint64, receiver []byte, value *bi } } +// GetBLSKeyStatus will return the bls key status func GetBLSKeyStatus(t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, blsKey []byte) string { scQuery := &process.SCQuery{ ScAddress: vm.StakingSCAddress, @@ -76,6 +81,7 @@ func GetBLSKeyStatus(t *testing.T, metachainNode chainSimulatorProcess.NodeHandl return string(result.ReturnData[0]) } +// GetAllNodeStates will return the status of all the nodes that belong to the provided address func GetAllNodeStates(t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, address []byte) map[string]string { scQuery := &process.SCQuery{ ScAddress: address, @@ -102,6 +108,7 @@ func GetAllNodeStates(t *testing.T, metachainNode chainSimulatorProcess.NodeHand return m } +// CheckValidatorStatus will compare the status of the provided bls key with the provided expected status func CheckValidatorStatus(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, blsKey string, expectedStatus string) { err := cs.ForceResetValidatorStatisticsCache() require.Nil(t, err) diff --git a/integrationTests/chainSimulator/staking/jail/jail_test.go b/integrationTests/chainSimulator/staking/jail/jail_test.go index c16d3c60df2..496db236d2c 100644 --- a/integrationTests/chainSimulator/staking/jail/jail_test.go +++ b/integrationTests/chainSimulator/staking/jail/jail_test.go @@ -3,7 +3,7 @@ package jail import ( "encoding/hex" "fmt" - "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" + "math/big" "testing" "time" @@ -12,6 +12,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" diff --git a/integrationTests/chainSimulator/staking/stake/simpleStake_test.go b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go index 4bbaa1ef74c..a4f63e44f28 100644 --- a/integrationTests/chainSimulator/staking/stake/simpleStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go @@ -3,7 +3,6 @@ package stake import ( "encoding/hex" "fmt" - "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "math/big" "testing" "time" @@ -12,6 +11,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" diff --git a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index 712f7ed5824..2b2246df713 100644 --- a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go @@ -3,7 +3,6 @@ package stake import ( "encoding/hex" "fmt" - "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "math/big" "testing" "time" @@ -15,6 +14,7 @@ import ( "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" + "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" diff --git a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index 4b44f2077e2..3c7edc79fee 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go @@ -4,7 +4,6 @@ import ( "crypto/rand" "encoding/hex" "fmt" - "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" logger "github.com/multiversx/mx-chain-logger-go" "math/big" "strings" @@ -21,6 +20,7 @@ import ( "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" + "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" diff --git a/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go b/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go index 1b197493ef4..99cc7a66518 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go @@ -3,8 +3,6 @@ package stakingProvider import ( "encoding/hex" "fmt" - "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" - "math/big" "testing" "time" @@ -12,6 +10,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" From 7b5677b67274a1efb124c8433f39ceac030bc58a Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 3 Apr 2024 09:15:39 +0300 Subject: [PATCH 151/503] fixes after review --- .../staking/{helpers.go => common.go} | 26 +++++++++++++------ .../stakingProvider/delegation_test.go | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) rename integrationTests/chainSimulator/staking/{helpers.go => common.go} (79%) diff --git a/integrationTests/chainSimulator/staking/helpers.go b/integrationTests/chainSimulator/staking/common.go similarity index 79% rename from integrationTests/chainSimulator/staking/helpers.go rename to integrationTests/chainSimulator/staking/common.go index ed42733f5a4..d358c0c966d 100644 --- a/integrationTests/chainSimulator/staking/helpers.go +++ b/integrationTests/chainSimulator/staking/common.go @@ -21,17 +21,27 @@ const ( txVersion = 1 mockTxSignature = "sig" - OkReturnCode = "ok" - UnStakedStatus = "unStaked" - MockBLSSignature = "010101" - GasLimitForStakeOperation = 50_000_000 - GasLimitForUnBond = 12_000_000 + // OkReturnCode the const for the ok return code + OkReturnCode = "ok" + // MockBLSSignature the const for a mocked bls signature + MockBLSSignature = "010101" + // GasLimitForStakeOperation the const for the gas limit value for the stake operation + GasLimitForStakeOperation = 50_000_000 + // GasLimitForUnBond the const for the gas limit value for the unBond operation + GasLimitForUnBond = 12_000_000 + // MaxNumOfBlockToGenerateWhenExecutingTx the const for the maximum number of block to generate when execute a transaction MaxNumOfBlockToGenerateWhenExecutingTx = 7 - QueuedStatus = "queued" - StakedStatus = "staked" + // QueuedStatus the const for the queued status of a validators + QueuedStatus = "queued" + // StakedStatus the const for the staked status of a validators + StakedStatus = "staked" + // NotStakedStatus the const for the notStaked status of a validators NotStakedStatus = "notStaked" - AuctionStatus = "auction" + // AuctionStatus the const for the action status of a validators + AuctionStatus = "auction" + // UnStakedStatus the const for the unStaked status of a validators + UnStakedStatus = "unStaked" ) var ( diff --git a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index 3c7edc79fee..653ab74f031 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go @@ -4,7 +4,6 @@ import ( "crypto/rand" "encoding/hex" "fmt" - logger "github.com/multiversx/mx-chain-logger-go" "math/big" "strings" "testing" @@ -27,6 +26,7 @@ import ( chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/vm" + logger "github.com/multiversx/mx-chain-logger-go" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) From 669f0e715e96d55eb143964dbcf0ac3b48e83826 Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 3 Apr 2024 10:35:28 +0300 Subject: [PATCH 152/503] missing comments --- integrationTests/chainSimulator/staking/common.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/integrationTests/chainSimulator/staking/common.go b/integrationTests/chainSimulator/staking/common.go index d358c0c966d..a8500a05995 100644 --- a/integrationTests/chainSimulator/staking/common.go +++ b/integrationTests/chainSimulator/staking/common.go @@ -45,10 +45,14 @@ const ( ) var ( - ZeroValue = big.NewInt(0) + // ZeroValue the variable for the zero big int + ZeroValue = big.NewInt(0) + // OneEGLD the variable for one egld value + OneEGLD = big.NewInt(1000000000000000000) + //InitialDelegationValue the variable for the initial delegation value InitialDelegationValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(1250)) - MinimumStakeValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(2500)) - OneEGLD = big.NewInt(1000000000000000000) + // MinimumStakeValue the variable for the minimum stake value + MinimumStakeValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(2500)) ) // GetNonce will return the nonce of the provided address From 56b13a8cd384359d8051c5f9d5087330f60574ae Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Wed, 3 Apr 2024 15:23:38 +0300 Subject: [PATCH 153/503] - fixed backwards compatibility problem --- vm/systemSmartContracts/eei.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/vm/systemSmartContracts/eei.go b/vm/systemSmartContracts/eei.go index 3f251a6cca4..55f554d11b0 100644 --- a/vm/systemSmartContracts/eei.go +++ b/vm/systemSmartContracts/eei.go @@ -144,8 +144,6 @@ func (host *vmContext) GetStorageFromAddress(address []byte, key []byte) []byte if value, isInMap := storageAdrMap[string(key)]; isInMap { return value } - } else { - storageAdrMap = make(map[string][]byte) } data, _, err := host.blockChainHook.GetStorageData(address, key) @@ -153,8 +151,6 @@ func (host *vmContext) GetStorageFromAddress(address []byte, key []byte) []byte return nil } - storageAdrMap[string(key)] = data - return data } From eb9bd6557424c2afc2c2c99f41eea4ab63dea7f3 Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Thu, 4 Apr 2024 15:37:32 +0300 Subject: [PATCH 154/503] fix backwards compatibility issues in legacySystemSCs --- epochStart/metachain/legacySystemSCs.go | 34 ++++++++++++++++++------- state/interface.go | 5 +++- state/validatorsInfoMap.go | 31 ++++++++++++++-------- 3 files changed, 49 insertions(+), 21 deletions(-) diff --git a/epochStart/metachain/legacySystemSCs.go b/epochStart/metachain/legacySystemSCs.go index 327a5ab88e5..c95b77547c4 100644 --- a/epochStart/metachain/legacySystemSCs.go +++ b/epochStart/metachain/legacySystemSCs.go @@ -14,6 +14,8 @@ import ( "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/marshal" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/errChan" vInfo "github.com/multiversx/mx-chain-go/common/validatorInfo" @@ -24,7 +26,6 @@ import ( "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/vm" "github.com/multiversx/mx-chain-go/vm/systemSmartContracts" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) type legacySystemSCProcessor struct { @@ -288,9 +289,10 @@ func (s *legacySystemSCProcessor) unStakeNodesWithNotEnoughFunds( continue } + stakingV4Enabled := s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) validatorLeaving := validatorInfo.ShallowClone() - validatorLeaving.SetListAndIndex(string(common.LeavingList), validatorLeaving.GetIndex(), s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag)) - err = validatorsInfoMap.Replace(validatorInfo, validatorLeaving) + validatorLeaving.SetListAndIndex(string(common.LeavingList), validatorLeaving.GetIndex(), stakingV4Enabled) + err = s.replaceValidators(validatorInfo, validatorLeaving, validatorsInfoMap) if err != nil { return 0, err } @@ -302,7 +304,9 @@ func (s *legacySystemSCProcessor) unStakeNodesWithNotEnoughFunds( } nodesToStakeFromQueue := uint32(len(nodesToUnStake)) - nodesToStakeFromQueue -= nodesUnStakedFromAdditionalQueue + if s.enableEpochsHandler.IsFlagEnabled(common.CorrectLastUnJailedFlag) { + nodesToStakeFromQueue -= nodesUnStakedFromAdditionalQueue + } log.Debug("stake nodes from waiting list", "num", nodesToStakeFromQueue) return nodesToStakeFromQueue, nil @@ -720,10 +724,8 @@ func (s *legacySystemSCProcessor) stakingToValidatorStatistics( } if !isNew { - err = validatorsInfoMap.Delete(jailedValidator) - if err != nil { - return nil, err - } + // the new validator is deleted from the staking queue, not the jailed validator + validatorsInfoMap.DeleteKey(blsPubKey, account.GetShardId()) } account.SetListAndIndex(jailedValidator.GetShardId(), string(common.NewList), uint32(stakingData.StakedNonce), s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag)) @@ -752,7 +754,7 @@ func (s *legacySystemSCProcessor) stakingToValidatorStatistics( } newValidatorInfo := s.validatorInfoCreator.PeerAccountToValidatorInfo(account) - err = validatorsInfoMap.Replace(jailedValidator, newValidatorInfo) + err = s.replaceValidators(jailedValidator, newValidatorInfo, validatorsInfoMap) if err != nil { return nil, err } @@ -760,6 +762,20 @@ func (s *legacySystemSCProcessor) stakingToValidatorStatistics( return blsPubKey, nil } +func (s *legacySystemSCProcessor) replaceValidators( + old state.ValidatorInfoHandler, + new state.ValidatorInfoHandler, + validatorsInfoMap state.ShardValidatorsInfoMapHandler, +) error { + stakingV4Enabled := s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) + if stakingV4Enabled { + return validatorsInfoMap.Replace(old, new) + } + + validatorsInfoMap.ReplaceValidatorByKey(old.GetPublicKey(), new, old.GetShardId()) + return nil +} + func isValidator(validator state.ValidatorInfoHandler) bool { return validator.GetList() == string(common.WaitingList) || validator.GetList() == string(common.EligibleList) } diff --git a/state/interface.go b/state/interface.go index bf515803346..59275bb0e57 100644 --- a/state/interface.go +++ b/state/interface.go @@ -6,8 +6,9 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/api" - "github.com/multiversx/mx-chain-go/common" vmcommon "github.com/multiversx/mx-chain-vm-common-go" + + "github.com/multiversx/mx-chain-go/common" ) // AccountFactory creates an account of different types @@ -292,7 +293,9 @@ type ShardValidatorsInfoMapHandler interface { Add(validator ValidatorInfoHandler) error Delete(validator ValidatorInfoHandler) error + DeleteKey(blsKey []byte, shardID uint32) Replace(old ValidatorInfoHandler, new ValidatorInfoHandler) error + ReplaceValidatorByKey(oldBlsKey []byte, new ValidatorInfoHandler, shardID uint32) SetValidatorsInShard(shardID uint32, validators []ValidatorInfoHandler) error } diff --git a/state/validatorsInfoMap.go b/state/validatorsInfoMap.go index e6c492d9d39..80199d45e6a 100644 --- a/state/validatorsInfoMap.go +++ b/state/validatorsInfoMap.go @@ -106,21 +106,26 @@ func (vi *shardValidatorsInfoMap) Replace(old ValidatorInfoHandler, new Validato "with new validator", hex.EncodeToString(new.GetPublicKey()), "shard", new.GetShardId(), "list", new.GetList(), ) + vi.ReplaceValidatorByKey(old.GetPublicKey(), new, shardID) + + return fmt.Errorf("old %w: %s when trying to replace it with %s", + ErrValidatorNotFound, + hex.EncodeToString(old.GetPublicKey()), + hex.EncodeToString(new.GetPublicKey()), + ) +} + +// ReplaceValidatorByKey will replace an existing ValidatorInfoHandler with a new one, based on the provided blsKey for the old record. +func (vi *shardValidatorsInfoMap) ReplaceValidatorByKey(oldBlsKey []byte, new ValidatorInfoHandler, shardID uint32) { vi.mutex.Lock() defer vi.mutex.Unlock() for idx, validator := range vi.valInfoMap[shardID] { - if bytes.Equal(validator.GetPublicKey(), old.GetPublicKey()) { + if bytes.Equal(validator.GetPublicKey(), oldBlsKey) { vi.valInfoMap[shardID][idx] = new - return nil + break } } - - return fmt.Errorf("old %w: %s when trying to replace it with %s", - ErrValidatorNotFound, - hex.EncodeToString(old.GetPublicKey()), - hex.EncodeToString(new.GetPublicKey()), - ) } // SetValidatorsInShard resets all validators saved in a specific shard with the provided []ValidatorInfoHandler. @@ -160,11 +165,17 @@ func (vi *shardValidatorsInfoMap) Delete(validator ValidatorInfoHandler) error { } shardID := validator.GetShardId() + vi.DeleteKey(validator.GetPublicKey(), shardID) + return nil +} + +// DeleteKey will delete the provided blsKey from the internally stored map, if found. +func (vi *shardValidatorsInfoMap) DeleteKey(blsKey []byte, shardID uint32) { vi.mutex.Lock() defer vi.mutex.Unlock() for index, validatorInfo := range vi.valInfoMap[shardID] { - if bytes.Equal(validatorInfo.GetPublicKey(), validator.GetPublicKey()) { + if bytes.Equal(validatorInfo.GetPublicKey(), blsKey) { length := len(vi.valInfoMap[shardID]) vi.valInfoMap[shardID][index] = vi.valInfoMap[shardID][length-1] vi.valInfoMap[shardID][length-1] = nil @@ -172,6 +183,4 @@ func (vi *shardValidatorsInfoMap) Delete(validator ValidatorInfoHandler) error { break } } - - return nil } From 4a4000fca3d6cb729b4cf784f82de6df7a83892b Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Thu, 4 Apr 2024 16:03:30 +0300 Subject: [PATCH 155/503] only return error if not replaced --- epochStart/metachain/legacySystemSCs.go | 2 +- state/interface.go | 2 +- state/validatorsInfoMap.go | 10 +++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/epochStart/metachain/legacySystemSCs.go b/epochStart/metachain/legacySystemSCs.go index c95b77547c4..4173a3cfc59 100644 --- a/epochStart/metachain/legacySystemSCs.go +++ b/epochStart/metachain/legacySystemSCs.go @@ -772,7 +772,7 @@ func (s *legacySystemSCProcessor) replaceValidators( return validatorsInfoMap.Replace(old, new) } - validatorsInfoMap.ReplaceValidatorByKey(old.GetPublicKey(), new, old.GetShardId()) + _ = validatorsInfoMap.ReplaceValidatorByKey(old.GetPublicKey(), new, old.GetShardId()) return nil } diff --git a/state/interface.go b/state/interface.go index 59275bb0e57..842260cff28 100644 --- a/state/interface.go +++ b/state/interface.go @@ -295,7 +295,7 @@ type ShardValidatorsInfoMapHandler interface { Delete(validator ValidatorInfoHandler) error DeleteKey(blsKey []byte, shardID uint32) Replace(old ValidatorInfoHandler, new ValidatorInfoHandler) error - ReplaceValidatorByKey(oldBlsKey []byte, new ValidatorInfoHandler, shardID uint32) + ReplaceValidatorByKey(oldBlsKey []byte, new ValidatorInfoHandler, shardID uint32) bool SetValidatorsInShard(shardID uint32, validators []ValidatorInfoHandler) error } diff --git a/state/validatorsInfoMap.go b/state/validatorsInfoMap.go index 80199d45e6a..76e543c4394 100644 --- a/state/validatorsInfoMap.go +++ b/state/validatorsInfoMap.go @@ -106,7 +106,10 @@ func (vi *shardValidatorsInfoMap) Replace(old ValidatorInfoHandler, new Validato "with new validator", hex.EncodeToString(new.GetPublicKey()), "shard", new.GetShardId(), "list", new.GetList(), ) - vi.ReplaceValidatorByKey(old.GetPublicKey(), new, shardID) + found := vi.ReplaceValidatorByKey(old.GetPublicKey(), new, shardID) + if found { + return nil + } return fmt.Errorf("old %w: %s when trying to replace it with %s", ErrValidatorNotFound, @@ -116,16 +119,17 @@ func (vi *shardValidatorsInfoMap) Replace(old ValidatorInfoHandler, new Validato } // ReplaceValidatorByKey will replace an existing ValidatorInfoHandler with a new one, based on the provided blsKey for the old record. -func (vi *shardValidatorsInfoMap) ReplaceValidatorByKey(oldBlsKey []byte, new ValidatorInfoHandler, shardID uint32) { +func (vi *shardValidatorsInfoMap) ReplaceValidatorByKey(oldBlsKey []byte, new ValidatorInfoHandler, shardID uint32) bool { vi.mutex.Lock() defer vi.mutex.Unlock() for idx, validator := range vi.valInfoMap[shardID] { if bytes.Equal(validator.GetPublicKey(), oldBlsKey) { vi.valInfoMap[shardID][idx] = new - break + return true } } + return false } // SetValidatorsInShard resets all validators saved in a specific shard with the provided []ValidatorInfoHandler. From e932f1b3386e00a15107bd58519f328062a43432 Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Thu, 4 Apr 2024 16:07:39 +0300 Subject: [PATCH 156/503] rename local variable --- state/validatorsInfoMap.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/state/validatorsInfoMap.go b/state/validatorsInfoMap.go index 76e543c4394..d72d1b17996 100644 --- a/state/validatorsInfoMap.go +++ b/state/validatorsInfoMap.go @@ -106,8 +106,8 @@ func (vi *shardValidatorsInfoMap) Replace(old ValidatorInfoHandler, new Validato "with new validator", hex.EncodeToString(new.GetPublicKey()), "shard", new.GetShardId(), "list", new.GetList(), ) - found := vi.ReplaceValidatorByKey(old.GetPublicKey(), new, shardID) - if found { + replaced := vi.ReplaceValidatorByKey(old.GetPublicKey(), new, shardID) + if replaced { return nil } From bd41b675cd97acae0e0f5ab8a060d7178376238d Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 8 Apr 2024 10:46:18 +0300 Subject: [PATCH 157/503] - added block timestamp + scripts update for the round duration --- common/constants.go | 3 +++ dataRetriever/blockchain/blockchain.go | 1 + dataRetriever/blockchain/metachain.go | 1 + node/metrics/metrics.go | 1 + node/metrics/metrics_test.go | 1 + scripts/testnet/include/config.sh | 3 ++- scripts/testnet/variables.sh | 2 ++ statusHandler/persister/persistentHandler.go | 1 + statusHandler/statusMetricsProvider.go | 1 + statusHandler/statusMetricsProvider_test.go | 4 ++++ 10 files changed, 17 insertions(+), 1 deletion(-) diff --git a/common/constants.go b/common/constants.go index 5d4e15e9fc5..0476f1aa5e5 100644 --- a/common/constants.go +++ b/common/constants.go @@ -100,6 +100,9 @@ const MetricCurrentRound = "erd_current_round" // MetricNonce is the metric for monitoring the nonce of a node const MetricNonce = "erd_nonce" +// MetricBlockTimestamp is the metric for monitoring the timestamp of the last synchronized block +const MetricBlockTimestamp = "erd_block_timestamp" + // MetricProbableHighestNonce is the metric for monitoring the max speculative nonce received by the node by listening on the network const MetricProbableHighestNonce = "erd_probable_highest_nonce" diff --git a/dataRetriever/blockchain/blockchain.go b/dataRetriever/blockchain/blockchain.go index bf18ad64402..f8d011e5a08 100644 --- a/dataRetriever/blockchain/blockchain.go +++ b/dataRetriever/blockchain/blockchain.go @@ -69,6 +69,7 @@ func (bc *blockChain) SetCurrentBlockHeaderAndRootHash(header data.HeaderHandler bc.appStatusHandler.SetUInt64Value(common.MetricNonce, h.GetNonce()) bc.appStatusHandler.SetUInt64Value(common.MetricSynchronizedRound, h.GetRound()) + bc.appStatusHandler.SetUInt64Value(common.MetricBlockTimestamp, h.GetTimeStamp()) bc.mut.Lock() bc.currentBlockHeader = h.ShallowClone() diff --git a/dataRetriever/blockchain/metachain.go b/dataRetriever/blockchain/metachain.go index 179b1b84b0a..0ef4b1247c2 100644 --- a/dataRetriever/blockchain/metachain.go +++ b/dataRetriever/blockchain/metachain.go @@ -71,6 +71,7 @@ func (mc *metaChain) SetCurrentBlockHeaderAndRootHash(header data.HeaderHandler, mc.appStatusHandler.SetUInt64Value(common.MetricNonce, currHead.Nonce) mc.appStatusHandler.SetUInt64Value(common.MetricSynchronizedRound, currHead.Round) + mc.appStatusHandler.SetUInt64Value(common.MetricBlockTimestamp, currHead.GetTimeStamp()) mc.mut.Lock() mc.currentBlockHeader = currHead.ShallowClone() diff --git a/node/metrics/metrics.go b/node/metrics/metrics.go index ca2cd4e910a..94c61a4aeb0 100644 --- a/node/metrics/metrics.go +++ b/node/metrics/metrics.go @@ -30,6 +30,7 @@ func InitBaseMetrics(appStatusHandler core.AppStatusHandler) error { appStatusHandler.SetUInt64Value(common.MetricSynchronizedRound, initUint) appStatusHandler.SetUInt64Value(common.MetricNonce, initUint) + appStatusHandler.SetUInt64Value(common.MetricBlockTimestamp, initUint) appStatusHandler.SetUInt64Value(common.MetricCountConsensus, initUint) appStatusHandler.SetUInt64Value(common.MetricCountLeader, initUint) appStatusHandler.SetUInt64Value(common.MetricCountAcceptedBlocks, initUint) diff --git a/node/metrics/metrics_test.go b/node/metrics/metrics_test.go index 7da1a582626..f10707c64f0 100644 --- a/node/metrics/metrics_test.go +++ b/node/metrics/metrics_test.go @@ -23,6 +23,7 @@ func TestInitBaseMetrics(t *testing.T) { expectedKeys := []string{ common.MetricSynchronizedRound, common.MetricNonce, + common.MetricBlockTimestamp, common.MetricCountConsensus, common.MetricCountLeader, common.MetricCountAcceptedBlocks, diff --git a/scripts/testnet/include/config.sh b/scripts/testnet/include/config.sh index 8fa1d11b3db..25f836a84b7 100644 --- a/scripts/testnet/include/config.sh +++ b/scripts/testnet/include/config.sh @@ -20,7 +20,8 @@ generateConfig() { -num-of-observers-in-metachain $TMP_META_OBSERVERCOUNT \ -metachain-consensus-group-size $META_CONSENSUS_SIZE \ -stake-type $GENESIS_STAKE_TYPE \ - -hysteresis $HYSTERESIS + -hysteresis $HYSTERESIS \ + -round-duration $ROUND_DURATION_IN_MS popd } diff --git a/scripts/testnet/variables.sh b/scripts/testnet/variables.sh index f3fb44c5866..c5a5b013523 100644 --- a/scripts/testnet/variables.sh +++ b/scripts/testnet/variables.sh @@ -62,6 +62,8 @@ export META_VALIDATORCOUNT=3 export META_OBSERVERCOUNT=1 export META_CONSENSUS_SIZE=$META_VALIDATORCOUNT +export ROUND_DURATION_IN_MS=6000 + # MULTI_KEY_NODES if set to 1, one observer will be generated on each shard that will handle all generated keys export MULTI_KEY_NODES=0 diff --git a/statusHandler/persister/persistentHandler.go b/statusHandler/persister/persistentHandler.go index b2d9c750082..93561363247 100644 --- a/statusHandler/persister/persistentHandler.go +++ b/statusHandler/persister/persistentHandler.go @@ -58,6 +58,7 @@ func (psh *PersistentStatusHandler) initMap() { psh.persistentMetrics.Store(common.MetricNumProcessedTxs, initUint) psh.persistentMetrics.Store(common.MetricNumShardHeadersProcessed, initUint) psh.persistentMetrics.Store(common.MetricNonce, initUint) + psh.persistentMetrics.Store(common.MetricBlockTimestamp, initUint) psh.persistentMetrics.Store(common.MetricCurrentRound, initUint) psh.persistentMetrics.Store(common.MetricNonceAtEpochStart, initUint) psh.persistentMetrics.Store(common.MetricRoundAtEpochStart, initUint) diff --git a/statusHandler/statusMetricsProvider.go b/statusHandler/statusMetricsProvider.go index 99f15ad1bf6..d0f841468b8 100644 --- a/statusHandler/statusMetricsProvider.go +++ b/statusHandler/statusMetricsProvider.go @@ -340,6 +340,7 @@ func (sm *statusMetrics) saveUint64NetworkMetricsInMap(networkMetrics map[string currentNonce := sm.uint64Metrics[common.MetricNonce] nonceAtEpochStart := sm.uint64Metrics[common.MetricNonceAtEpochStart] networkMetrics[common.MetricNonce] = currentNonce + networkMetrics[common.MetricBlockTimestamp] = sm.uint64Metrics[common.MetricBlockTimestamp] networkMetrics[common.MetricHighestFinalBlock] = sm.uint64Metrics[common.MetricHighestFinalBlock] networkMetrics[common.MetricCurrentRound] = currentRound networkMetrics[common.MetricRoundAtEpochStart] = roundNumberAtEpochStart diff --git a/statusHandler/statusMetricsProvider_test.go b/statusHandler/statusMetricsProvider_test.go index 5572b1754f8..fbf74ad26fc 100644 --- a/statusHandler/statusMetricsProvider_test.go +++ b/statusHandler/statusMetricsProvider_test.go @@ -231,6 +231,7 @@ func TestStatusMetrics_NetworkMetrics(t *testing.T) { sm.SetUInt64Value(common.MetricCurrentRound, 200) sm.SetUInt64Value(common.MetricRoundAtEpochStart, 100) sm.SetUInt64Value(common.MetricNonce, 180) + sm.SetUInt64Value(common.MetricBlockTimestamp, 18000) sm.SetUInt64Value(common.MetricHighestFinalBlock, 181) sm.SetUInt64Value(common.MetricNonceAtEpochStart, 95) sm.SetUInt64Value(common.MetricEpochNumber, 1) @@ -240,6 +241,7 @@ func TestStatusMetrics_NetworkMetrics(t *testing.T) { "erd_current_round": uint64(200), "erd_round_at_epoch_start": uint64(100), "erd_nonce": uint64(180), + "erd_block_timestamp": uint64(18000), "erd_highest_final_nonce": uint64(181), "erd_nonce_at_epoch_start": uint64(95), "erd_epoch_number": uint64(1), @@ -270,6 +272,7 @@ func TestStatusMetrics_StatusMetricsMapWithoutP2P(t *testing.T) { sm.SetUInt64Value(common.MetricCurrentRound, 100) sm.SetUInt64Value(common.MetricRoundAtEpochStart, 200) sm.SetUInt64Value(common.MetricNonce, 300) + sm.SetUInt64Value(common.MetricBlockTimestamp, 30000) sm.SetStringValue(common.MetricAppVersion, "400") sm.SetUInt64Value(common.MetricRoundsPassedInCurrentEpoch, 95) sm.SetUInt64Value(common.MetricNoncesPassedInCurrentEpoch, 1) @@ -281,6 +284,7 @@ func TestStatusMetrics_StatusMetricsMapWithoutP2P(t *testing.T) { require.Equal(t, uint64(100), res[common.MetricCurrentRound]) require.Equal(t, uint64(200), res[common.MetricRoundAtEpochStart]) require.Equal(t, uint64(300), res[common.MetricNonce]) + require.Equal(t, uint64(30000), res[common.MetricBlockTimestamp]) require.Equal(t, "400", res[common.MetricAppVersion]) require.NotContains(t, res, common.MetricRoundsPassedInCurrentEpoch) require.NotContains(t, res, common.MetricNoncesPassedInCurrentEpoch) From 760a76735951c1d55a9f033cace5b415ec312a08 Mon Sep 17 00:00:00 2001 From: MariusC Date: Mon, 8 Apr 2024 16:14:17 +0300 Subject: [PATCH 158/503] FIX: Possible backwards incompatibilities fixes --- epochStart/metachain/legacySystemSCs.go | 28 ++++++++++++++++++------- epochStart/metachain/systemSCs_test.go | 4 ++++ state/interface.go | 1 + state/validatorsInfoMap.go | 8 +++++++ 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/epochStart/metachain/legacySystemSCs.go b/epochStart/metachain/legacySystemSCs.go index 4173a3cfc59..6b434eb209e 100644 --- a/epochStart/metachain/legacySystemSCs.go +++ b/epochStart/metachain/legacySystemSCs.go @@ -432,7 +432,7 @@ func (s *legacySystemSCProcessor) fillStakingDataForNonEligible(validatorsInfoMa } if deleteCalled { - err := validatorsInfoMap.SetValidatorsInShard(shId, newList) + err := s.setValidatorsInShard(validatorsInfoMap, shId, newList) if err != nil { return err } @@ -442,6 +442,19 @@ func (s *legacySystemSCProcessor) fillStakingDataForNonEligible(validatorsInfoMa return nil } +func (s *legacySystemSCProcessor) setValidatorsInShard( + validatorsInfoMap state.ShardValidatorsInfoMapHandler, + shardID uint32, + validators []state.ValidatorInfoHandler, +) error { + if s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) { + return validatorsInfoMap.SetValidatorsInShard(shardID, validators) + } + + validatorsInfoMap.SetValidatorsInShardUnsafe(shardID, validators) + return nil +} + func (s *legacySystemSCProcessor) prepareStakingDataForEligibleNodes(validatorsInfoMap state.ShardValidatorsInfoMapHandler) error { eligibleNodes, err := getEligibleNodeKeys(validatorsInfoMap) if err != nil { @@ -589,6 +602,12 @@ func (s *legacySystemSCProcessor) updateMaxNodes(validatorsInfoMap state.ShardVa return err } + if !s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) { + if maxNumberOfNodes < prevMaxNumberOfNodes { + return epochStart.ErrInvalidMaxNumberOfNodes + } + } + if s.enableEpochsHandler.IsFlagEnabled(common.StakingQueueFlag) { sw.Start("stakeNodesFromQueue") err = s.stakeNodesFromQueue(validatorsInfoMap, maxNumberOfNodes-prevMaxNumberOfNodes, nonce, common.NewList) @@ -1223,11 +1242,6 @@ func (s *legacySystemSCProcessor) addNewlyStakedNodesToValidatorTrie( return err } - err = peerAcc.SetBLSPublicKey(blsKey) - if err != nil { - return err - } - peerAcc.SetListAndIndex(peerAcc.GetShardId(), string(list), uint32(nonce), s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag)) peerAcc.SetTempRating(s.startRating) peerAcc.SetUnStakedEpoch(common.DefaultUnstakedEpoch) @@ -1281,7 +1295,7 @@ func (s *legacySystemSCProcessor) extractConfigFromESDTContract() ([][]byte, err CallerAddr: s.endOfEpochCallerAddress, Arguments: [][]byte{}, CallValue: big.NewInt(0), - GasProvided: math.MaxUint64, + GasProvided: math.MaxInt64, }, Function: "getContractConfig", RecipientAddr: vm.ESDTSCAddress, diff --git a/epochStart/metachain/systemSCs_test.go b/epochStart/metachain/systemSCs_test.go index 7826c461d36..0dc9eb82b23 100644 --- a/epochStart/metachain/systemSCs_test.go +++ b/epochStart/metachain/systemSCs_test.go @@ -2326,6 +2326,10 @@ func TestSystemSCProcessor_LegacyEpochConfirmedCorrectMaxNumNodesAfterNodeRestar args.EpochNotifier.CheckEpoch(&block.Header{Epoch: 6, Nonce: 6}) require.True(t, s.flagChangeMaxNodesEnabled.IsSet()) err = s.processLegacy(validatorsInfoMap, 6, 6) + require.Equal(t, epochStart.ErrInvalidMaxNumberOfNodes, err) + + args.EnableEpochsHandler.(*enableEpochsHandlerMock.EnableEpochsHandlerStub).AddActiveFlags(common.StakingV4StartedFlag) + err = s.processLegacy(validatorsInfoMap, 6, 6) require.Nil(t, err) require.Equal(t, nodesConfigEpoch6.MaxNumNodes, s.maxNodes) diff --git a/state/interface.go b/state/interface.go index 842260cff28..6a6c098ade5 100644 --- a/state/interface.go +++ b/state/interface.go @@ -297,6 +297,7 @@ type ShardValidatorsInfoMapHandler interface { Replace(old ValidatorInfoHandler, new ValidatorInfoHandler) error ReplaceValidatorByKey(oldBlsKey []byte, new ValidatorInfoHandler, shardID uint32) bool SetValidatorsInShard(shardID uint32, validators []ValidatorInfoHandler) error + SetValidatorsInShardUnsafe(shardID uint32, validators []ValidatorInfoHandler) } // ValidatorInfoHandler defines which data shall a validator info hold. diff --git a/state/validatorsInfoMap.go b/state/validatorsInfoMap.go index d72d1b17996..27100745e02 100644 --- a/state/validatorsInfoMap.go +++ b/state/validatorsInfoMap.go @@ -161,6 +161,14 @@ func (vi *shardValidatorsInfoMap) SetValidatorsInShard(shardID uint32, validator return nil } +// SetValidatorsInShardUnsafe resets all validators saved in a specific shard with the provided ones. +// It does not check that provided validators are in the same shard as provided shard id. +func (vi *shardValidatorsInfoMap) SetValidatorsInShardUnsafe(shardID uint32, validators []ValidatorInfoHandler) { + vi.mutex.Lock() + vi.valInfoMap[shardID] = validators + vi.mutex.Unlock() +} + // Delete will delete the provided validator from the internally stored map, if found. // The validators slice at the corresponding shardID key will be re-sliced, without reordering func (vi *shardValidatorsInfoMap) Delete(validator ValidatorInfoHandler) error { From df4da690356735b9d80dd01415ef22b26e13d81c Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Wed, 10 Apr 2024 14:26:59 +0300 Subject: [PATCH 159/503] fixes after review --- epochStart/metachain/legacySystemSCs.go | 10 +++------- state/interface.go | 2 +- state/validatorsInfoMap.go | 6 +++--- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/epochStart/metachain/legacySystemSCs.go b/epochStart/metachain/legacySystemSCs.go index 4173a3cfc59..02107c1c950 100644 --- a/epochStart/metachain/legacySystemSCs.go +++ b/epochStart/metachain/legacySystemSCs.go @@ -293,9 +293,7 @@ func (s *legacySystemSCProcessor) unStakeNodesWithNotEnoughFunds( validatorLeaving := validatorInfo.ShallowClone() validatorLeaving.SetListAndIndex(string(common.LeavingList), validatorLeaving.GetIndex(), stakingV4Enabled) err = s.replaceValidators(validatorInfo, validatorLeaving, validatorsInfoMap) - if err != nil { - return 0, err - } + log.LogIfError(err) } err = s.updateDelegationContracts(mapOwnersKeys) @@ -725,7 +723,7 @@ func (s *legacySystemSCProcessor) stakingToValidatorStatistics( if !isNew { // the new validator is deleted from the staking queue, not the jailed validator - validatorsInfoMap.DeleteKey(blsPubKey, account.GetShardId()) + validatorsInfoMap.DeleteByKey(blsPubKey, account.GetShardId()) } account.SetListAndIndex(jailedValidator.GetShardId(), string(common.NewList), uint32(stakingData.StakedNonce), s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag)) @@ -755,9 +753,7 @@ func (s *legacySystemSCProcessor) stakingToValidatorStatistics( newValidatorInfo := s.validatorInfoCreator.PeerAccountToValidatorInfo(account) err = s.replaceValidators(jailedValidator, newValidatorInfo, validatorsInfoMap) - if err != nil { - return nil, err - } + log.LogIfError(err) return blsPubKey, nil } diff --git a/state/interface.go b/state/interface.go index 842260cff28..8a8c18a18c7 100644 --- a/state/interface.go +++ b/state/interface.go @@ -293,7 +293,7 @@ type ShardValidatorsInfoMapHandler interface { Add(validator ValidatorInfoHandler) error Delete(validator ValidatorInfoHandler) error - DeleteKey(blsKey []byte, shardID uint32) + DeleteByKey(blsKey []byte, shardID uint32) Replace(old ValidatorInfoHandler, new ValidatorInfoHandler) error ReplaceValidatorByKey(oldBlsKey []byte, new ValidatorInfoHandler, shardID uint32) bool SetValidatorsInShard(shardID uint32, validators []ValidatorInfoHandler) error diff --git a/state/validatorsInfoMap.go b/state/validatorsInfoMap.go index d72d1b17996..9069bf4a01d 100644 --- a/state/validatorsInfoMap.go +++ b/state/validatorsInfoMap.go @@ -169,12 +169,12 @@ func (vi *shardValidatorsInfoMap) Delete(validator ValidatorInfoHandler) error { } shardID := validator.GetShardId() - vi.DeleteKey(validator.GetPublicKey(), shardID) + vi.DeleteByKey(validator.GetPublicKey(), shardID) return nil } -// DeleteKey will delete the provided blsKey from the internally stored map, if found. -func (vi *shardValidatorsInfoMap) DeleteKey(blsKey []byte, shardID uint32) { +// DeleteByKey will delete the provided blsKey from the internally stored map, if found. +func (vi *shardValidatorsInfoMap) DeleteByKey(blsKey []byte, shardID uint32) { vi.mutex.Lock() defer vi.mutex.Unlock() From c655353a7298c99e2d4800c4d7c02ab9c81b53bf Mon Sep 17 00:00:00 2001 From: MariusC Date: Thu, 11 Apr 2024 10:53:18 +0300 Subject: [PATCH 160/503] FEAT: Extra safety measure checks --- epochStart/metachain/legacySystemSCs.go | 40 ++++++++++++++----------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/epochStart/metachain/legacySystemSCs.go b/epochStart/metachain/legacySystemSCs.go index aa9ff71c3fe..3247cb2dff1 100644 --- a/epochStart/metachain/legacySystemSCs.go +++ b/epochStart/metachain/legacySystemSCs.go @@ -292,8 +292,7 @@ func (s *legacySystemSCProcessor) unStakeNodesWithNotEnoughFunds( stakingV4Enabled := s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) validatorLeaving := validatorInfo.ShallowClone() validatorLeaving.SetListAndIndex(string(common.LeavingList), validatorLeaving.GetIndex(), stakingV4Enabled) - err = s.replaceValidators(validatorInfo, validatorLeaving, validatorsInfoMap) - log.LogIfError(err) + s.replaceValidators(validatorInfo, validatorLeaving, validatorsInfoMap) } err = s.updateDelegationContracts(mapOwnersKeys) @@ -430,10 +429,7 @@ func (s *legacySystemSCProcessor) fillStakingDataForNonEligible(validatorsInfoMa } if deleteCalled { - err := s.setValidatorsInShard(validatorsInfoMap, shId, newList) - if err != nil { - return err - } + s.setValidatorsInShard(validatorsInfoMap, shId, newList) } } @@ -444,13 +440,15 @@ func (s *legacySystemSCProcessor) setValidatorsInShard( validatorsInfoMap state.ShardValidatorsInfoMapHandler, shardID uint32, validators []state.ValidatorInfoHandler, -) error { - if s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) { - return validatorsInfoMap.SetValidatorsInShard(shardID, validators) +) { + err := validatorsInfoMap.SetValidatorsInShard(shardID, validators) + if err == nil { + return } + // this should never happen, but replace them anyway, as in old legacy code + log.Error("legacySystemSCProcessor.setValidatorsInShard", "error", err) validatorsInfoMap.SetValidatorsInShardUnsafe(shardID, validators) - return nil } func (s *legacySystemSCProcessor) prepareStakingDataForEligibleNodes(validatorsInfoMap state.ShardValidatorsInfoMapHandler) error { @@ -771,8 +769,7 @@ func (s *legacySystemSCProcessor) stakingToValidatorStatistics( } newValidatorInfo := s.validatorInfoCreator.PeerAccountToValidatorInfo(account) - err = s.replaceValidators(jailedValidator, newValidatorInfo, validatorsInfoMap) - log.LogIfError(err) + s.replaceValidators(jailedValidator, newValidatorInfo, validatorsInfoMap) return blsPubKey, nil } @@ -781,14 +778,21 @@ func (s *legacySystemSCProcessor) replaceValidators( old state.ValidatorInfoHandler, new state.ValidatorInfoHandler, validatorsInfoMap state.ShardValidatorsInfoMapHandler, -) error { - stakingV4Enabled := s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) - if stakingV4Enabled { - return validatorsInfoMap.Replace(old, new) +) { + // legacy code + if !s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) { + _ = validatorsInfoMap.ReplaceValidatorByKey(old.GetPublicKey(), new, old.GetShardId()) + return } - _ = validatorsInfoMap.ReplaceValidatorByKey(old.GetPublicKey(), new, old.GetShardId()) - return nil + // try with new code which does extra validity checks. + // if this also fails, do legacy code + if err := validatorsInfoMap.Replace(old, new); err != nil { + log.Error("legacySystemSCProcessor.replaceValidators", "error", err) + + replaced := validatorsInfoMap.ReplaceValidatorByKey(old.GetPublicKey(), new, old.GetShardId()) + log.Debug("legacySystemSCProcessor.replaceValidators", "old", old.GetPublicKey(), "new", new.GetPublicKey(), "was replace successful", replaced) + } } func isValidator(validator state.ValidatorInfoHandler) bool { From e9c876a35df758403ca5583d37b18e27d4e5ec7f Mon Sep 17 00:00:00 2001 From: MariusC Date: Thu, 11 Apr 2024 13:18:31 +0300 Subject: [PATCH 161/503] FEAT: Distribute to waiting from auction based on leaving nodes --- epochStart/dtos.go | 7 +++ epochStart/interface.go | 1 + epochStart/metachain/auctionListSelector.go | 37 ++++++++++++- epochStart/metachain/stakingDataProvider.go | 54 +++++++++++++++++++ .../stakingcommon/stakingDataProviderStub.go | 8 +++ 5 files changed, 106 insertions(+), 1 deletion(-) diff --git a/epochStart/dtos.go b/epochStart/dtos.go index ea5aa95f626..ecac1a4217f 100644 --- a/epochStart/dtos.go +++ b/epochStart/dtos.go @@ -15,3 +15,10 @@ type OwnerData struct { AuctionList []state.ValidatorInfoHandler Qualified bool } + +// ValidatorStatsInEpoch holds validator stats in an epoch +type ValidatorStatsInEpoch struct { + Eligible map[uint32]int + Waiting map[uint32]int + Leaving map[uint32]int +} diff --git a/epochStart/interface.go b/epochStart/interface.go index 06f04c11117..37df49df292 100644 --- a/epochStart/interface.go +++ b/epochStart/interface.go @@ -159,6 +159,7 @@ type StakingDataProvider interface { ComputeUnQualifiedNodes(validatorInfos state.ShardValidatorsInfoMapHandler) ([][]byte, map[string][][]byte, error) GetBlsKeyOwner(blsKey []byte) (string, error) GetNumOfValidatorsInCurrentEpoch() uint32 + GetCurrentEpochValidatorStats() ValidatorStatsInEpoch GetOwnersData() map[string]*OwnerData Clean() IsInterfaceNil() bool diff --git a/epochStart/metachain/auctionListSelector.go b/epochStart/metachain/auctionListSelector.go index 4b7c353a180..9d77a4f8bb6 100644 --- a/epochStart/metachain/auctionListSelector.go +++ b/epochStart/metachain/auctionListSelector.go @@ -198,7 +198,7 @@ func (als *auctionListSelector) SelectNodesFromAuctionList( currNodesConfig := als.nodesConfigProvider.GetCurrentNodesConfig() currNumOfValidators := als.stakingDataProvider.GetNumOfValidatorsInCurrentEpoch() - numOfShuffledNodes := currNodesConfig.NodesToShufflePerShard * (als.shardCoordinator.NumberOfShards() + 1) + numOfShuffledNodes := als.computeNumShuffledNodes(currNodesConfig) numOfValidatorsAfterShuffling, err := safeSub(currNumOfValidators, numOfShuffledNodes) if err != nil { log.Warn(fmt.Sprintf("auctionListSelector.SelectNodesFromAuctionList: %v when trying to compute numOfValidatorsAfterShuffling = %v - %v (currNumOfValidators - numOfShuffledNodes)", @@ -272,6 +272,41 @@ func isInAuction(validator state.ValidatorInfoHandler) bool { return validator.GetList() == string(common.AuctionList) } +func (als *auctionListSelector) computeNumShuffledNodes(currNodesConfig config.MaxNodesChangeConfig) uint32 { + numNodesToShufflePerShard := currNodesConfig.NodesToShufflePerShard + numShuffledOut := numNodesToShufflePerShard * (als.shardCoordinator.NumberOfShards() + 1) + epochStats := als.stakingDataProvider.GetCurrentEpochValidatorStats() + + actuallyNumLeaving := uint32(0) + for shardID := uint32(0); shardID < als.shardCoordinator.NumberOfShards(); shardID++ { + actuallyNumLeaving += computeActuallyNumLeaving(shardID, epochStats, numNodesToShufflePerShard) + } + + actuallyNumLeaving += computeActuallyNumLeaving(core.MetachainShardId, epochStats, numNodesToShufflePerShard) + + finalShuffledOut, err := safeSub(numShuffledOut, actuallyNumLeaving) + if err != nil { + log.Error("auctionListSelector.computeNumShuffledNodes", "error", err) + return numShuffledOut + } + + return finalShuffledOut +} + +func computeActuallyNumLeaving(shardID uint32, epochStats epochStart.ValidatorStatsInEpoch, numNodesToShuffledPerShard uint32) uint32 { + numLeavingInShard := uint32(epochStats.Leaving[shardID]) + numActiveInShard := uint32(epochStats.Waiting[shardID] + epochStats.Eligible[shardID]) + + log.Debug("auctionListSelector.computeActuallyNumLeaving", + "shardID", shardID, "numLeavingInShard", numLeavingInShard, "numActiveInShard", numActiveInShard) + + if numLeavingInShard < numNodesToShuffledPerShard && numActiveInShard > numLeavingInShard { + return numLeavingInShard + } + + return 0 +} + // TODO: Move this in elrond-go-core func safeSub(a, b uint32) (uint32, error) { if a < b { diff --git a/epochStart/metachain/stakingDataProvider.go b/epochStart/metachain/stakingDataProvider.go index 722a838193f..00c559bc6ad 100644 --- a/epochStart/metachain/stakingDataProvider.go +++ b/epochStart/metachain/stakingDataProvider.go @@ -46,6 +46,7 @@ type stakingDataProvider struct { minNodePrice *big.Int numOfValidatorsInCurrEpoch uint32 enableEpochsHandler common.EnableEpochsHandler + validatorStatsInEpoch epochStart.ValidatorStatsInEpoch } // StakingDataProviderArgs is a struct placeholder for all arguments required to create a NewStakingDataProvider @@ -77,6 +78,11 @@ func NewStakingDataProvider(args StakingDataProviderArgs) (*stakingDataProvider, totalEligibleStake: big.NewInt(0), totalEligibleTopUpStake: big.NewInt(0), enableEpochsHandler: args.EnableEpochsHandler, + validatorStatsInEpoch: epochStart.ValidatorStatsInEpoch{ + Eligible: make(map[uint32]int), + Waiting: make(map[uint32]int), + Leaving: make(map[uint32]int), + }, } return sdp, nil @@ -89,6 +95,11 @@ func (sdp *stakingDataProvider) Clean() { sdp.totalEligibleStake.SetInt64(0) sdp.totalEligibleTopUpStake.SetInt64(0) sdp.numOfValidatorsInCurrEpoch = 0 + sdp.validatorStatsInEpoch = epochStart.ValidatorStatsInEpoch{ + Eligible: make(map[uint32]int), + Waiting: make(map[uint32]int), + Leaving: make(map[uint32]int), + } sdp.mutStakingData.Unlock() } @@ -200,6 +211,7 @@ func (sdp *stakingDataProvider) getAndFillOwnerStats(validator state.ValidatorIn sdp.numOfValidatorsInCurrEpoch++ } + sdp.updateEpochStats(validator) return ownerData, nil } @@ -532,6 +544,48 @@ func (sdp *stakingDataProvider) GetNumOfValidatorsInCurrentEpoch() uint32 { return sdp.numOfValidatorsInCurrEpoch } +func (sdp *stakingDataProvider) updateEpochStats(validator state.ValidatorInfoHandler) { + validatorCurrentList := common.PeerType(validator.GetList()) + shardID := validator.GetShardId() + + if validatorCurrentList == common.EligibleList { + sdp.validatorStatsInEpoch.Eligible[shardID]++ + return + } + + if validatorCurrentList == common.WaitingList { + sdp.validatorStatsInEpoch.Waiting[shardID]++ + return + } + + validatorPreviousList := common.PeerType(validator.GetPreviousList()) + if sdp.isValidatorLeaving(validatorCurrentList, validatorPreviousList) { + sdp.validatorStatsInEpoch.Leaving[shardID]++ + } +} + +func (sdp *stakingDataProvider) isValidatorLeaving(validatorCurrentList, validatorPreviousList common.PeerType) bool { + if validatorCurrentList != common.LeavingList { + return false + } + + // If no previous list is set, means that staking v4 is not activated or node is leaving right before activation + // and this node will be considered as eligible by the nodes coordinator with legacy bug. + // Otherwise, it will have it set, and we should check its previous list in the current epoch + if len(validatorPreviousList) == 0 || validatorPreviousList == common.EligibleList || validatorPreviousList == common.WaitingList { + return true + } + + return false +} + +func (sdp *stakingDataProvider) GetCurrentEpochValidatorStats() epochStart.ValidatorStatsInEpoch { + sdp.mutStakingData.RLock() + defer sdp.mutStakingData.RUnlock() + + return sdp.validatorStatsInEpoch +} + // IsInterfaceNil return true if underlying object is nil func (sdp *stakingDataProvider) IsInterfaceNil() bool { return sdp == nil diff --git a/testscommon/stakingcommon/stakingDataProviderStub.go b/testscommon/stakingcommon/stakingDataProviderStub.go index dc2b990c20c..b6b356cc1e7 100644 --- a/testscommon/stakingcommon/stakingDataProviderStub.go +++ b/testscommon/stakingcommon/stakingDataProviderStub.go @@ -88,6 +88,14 @@ func (sdps *StakingDataProviderStub) GetNumOfValidatorsInCurrentEpoch() uint32 { return 0 } +func (sdps *StakingDataProviderStub) GetCurrentEpochValidatorStats() epochStart.ValidatorStatsInEpoch { + return epochStart.ValidatorStatsInEpoch{ + Eligible: map[uint32]int{}, + Waiting: map[uint32]int{}, + Leaving: map[uint32]int{}, + } +} + // GetOwnersData - func (sdps *StakingDataProviderStub) GetOwnersData() map[string]*epochStart.OwnerData { if sdps.GetOwnersDataCalled != nil { From d7b665d094e82e7ef8fa211a0bb851947cd9ef20 Mon Sep 17 00:00:00 2001 From: MariusC Date: Thu, 11 Apr 2024 16:24:59 +0300 Subject: [PATCH 162/503] FEAT: Test + compute forced to stay --- epochStart/metachain/auctionListSelector.go | 41 +++-- epochStart/metachain/systemSCs_test.go | 4 +- integrationTests/vm/staking/stakingV4_test.go | 163 ++++++++++++++++++ 3 files changed, 192 insertions(+), 16 deletions(-) diff --git a/epochStart/metachain/auctionListSelector.go b/epochStart/metachain/auctionListSelector.go index 9d77a4f8bb6..7737dba8fc8 100644 --- a/epochStart/metachain/auctionListSelector.go +++ b/epochStart/metachain/auctionListSelector.go @@ -198,7 +198,7 @@ func (als *auctionListSelector) SelectNodesFromAuctionList( currNodesConfig := als.nodesConfigProvider.GetCurrentNodesConfig() currNumOfValidators := als.stakingDataProvider.GetNumOfValidatorsInCurrentEpoch() - numOfShuffledNodes := als.computeNumShuffledNodes(currNodesConfig) + numOfShuffledNodes, numForcedToStay := als.computeNumShuffledNodes(currNodesConfig) numOfValidatorsAfterShuffling, err := safeSub(currNumOfValidators, numOfShuffledNodes) if err != nil { log.Warn(fmt.Sprintf("auctionListSelector.SelectNodesFromAuctionList: %v when trying to compute numOfValidatorsAfterShuffling = %v - %v (currNumOfValidators - numOfShuffledNodes)", @@ -210,12 +210,12 @@ func (als *auctionListSelector) SelectNodesFromAuctionList( } maxNumNodes := currNodesConfig.MaxNumNodes - availableSlots, err := safeSub(maxNumNodes, numOfValidatorsAfterShuffling) + availableSlots, err := safeSub(maxNumNodes, numOfValidatorsAfterShuffling+numForcedToStay) if availableSlots == 0 || err != nil { - log.Info(fmt.Sprintf("auctionListSelector.SelectNodesFromAuctionList: %v or zero value when trying to compute availableSlots = %v - %v (maxNodes - numOfValidatorsAfterShuffling); skip selecting nodes from auction list", + log.Info(fmt.Sprintf("auctionListSelector.SelectNodesFromAuctionList: %v or zero value when trying to compute availableSlots = %v - %v (maxNodes - numOfValidatorsAfterShuffling+numForcedToStay); skip selecting nodes from auction list", err, maxNumNodes, - numOfValidatorsAfterShuffling, + numOfValidatorsAfterShuffling+numForcedToStay, )) return nil } @@ -224,9 +224,10 @@ func (als *auctionListSelector) SelectNodesFromAuctionList( "max nodes", maxNumNodes, "current number of validators", currNumOfValidators, "num of nodes which will be shuffled out", numOfShuffledNodes, + "num forced to stay", numForcedToStay, "num of validators after shuffling", numOfValidatorsAfterShuffling, "auction list size", auctionListSize, - fmt.Sprintf("available slots (%v - %v)", maxNumNodes, numOfValidatorsAfterShuffling), availableSlots, + fmt.Sprintf("available slots (%v - %v)", maxNumNodes, numOfValidatorsAfterShuffling+numForcedToStay), availableSlots, ) als.auctionListDisplayer.DisplayOwnersData(ownersData) @@ -272,39 +273,51 @@ func isInAuction(validator state.ValidatorInfoHandler) bool { return validator.GetList() == string(common.AuctionList) } -func (als *auctionListSelector) computeNumShuffledNodes(currNodesConfig config.MaxNodesChangeConfig) uint32 { +func (als *auctionListSelector) computeNumShuffledNodes(currNodesConfig config.MaxNodesChangeConfig) (uint32, uint32) { numNodesToShufflePerShard := currNodesConfig.NodesToShufflePerShard numShuffledOut := numNodesToShufflePerShard * (als.shardCoordinator.NumberOfShards() + 1) epochStats := als.stakingDataProvider.GetCurrentEpochValidatorStats() actuallyNumLeaving := uint32(0) + forcedToStay := uint32(0) for shardID := uint32(0); shardID < als.shardCoordinator.NumberOfShards(); shardID++ { - actuallyNumLeaving += computeActuallyNumLeaving(shardID, epochStats, numNodesToShufflePerShard) + leavingInShard, forcedToStayInShard := computeActuallyNumLeaving(shardID, epochStats, numNodesToShufflePerShard) + actuallyNumLeaving += leavingInShard + forcedToStay += forcedToStayInShard } - actuallyNumLeaving += computeActuallyNumLeaving(core.MetachainShardId, epochStats, numNodesToShufflePerShard) + leavingInShard, forcedToStayInShard := computeActuallyNumLeaving(core.MetachainShardId, epochStats, numNodesToShufflePerShard) + actuallyNumLeaving += leavingInShard + forcedToStay += forcedToStayInShard finalShuffledOut, err := safeSub(numShuffledOut, actuallyNumLeaving) if err != nil { log.Error("auctionListSelector.computeNumShuffledNodes", "error", err) - return numShuffledOut + return numShuffledOut, 0 } - return finalShuffledOut + return finalShuffledOut, forcedToStay } -func computeActuallyNumLeaving(shardID uint32, epochStats epochStart.ValidatorStatsInEpoch, numNodesToShuffledPerShard uint32) uint32 { +func computeActuallyNumLeaving(shardID uint32, epochStats epochStart.ValidatorStatsInEpoch, numNodesToShuffledPerShard uint32) (uint32, uint32) { numLeavingInShard := uint32(epochStats.Leaving[shardID]) numActiveInShard := uint32(epochStats.Waiting[shardID] + epochStats.Eligible[shardID]) - log.Debug("auctionListSelector.computeActuallyNumLeaving", + log.Info("auctionListSelector.computeActuallyNumLeaving", "shardID", shardID, "numLeavingInShard", numLeavingInShard, "numActiveInShard", numActiveInShard) + actuallyleaving := uint32(0) + forcedToStay := uint32(0) if numLeavingInShard < numNodesToShuffledPerShard && numActiveInShard > numLeavingInShard { - return numLeavingInShard + actuallyleaving = numLeavingInShard } - return 0 + if numLeavingInShard > numNodesToShuffledPerShard { + actuallyleaving = numNodesToShuffledPerShard + forcedToStay = numLeavingInShard - numNodesToShuffledPerShard + } + + return actuallyleaving, forcedToStay } // TODO: Move this in elrond-go-core diff --git a/epochStart/metachain/systemSCs_test.go b/epochStart/metachain/systemSCs_test.go index 0dc9eb82b23..c2000e16c60 100644 --- a/epochStart/metachain/systemSCs_test.go +++ b/epochStart/metachain/systemSCs_test.go @@ -2093,7 +2093,7 @@ func TestSystemSCProcessor_ProcessSystemSmartContractStakingV4Enabled(t *testing t.Parallel() args, _ := createFullArgumentsForSystemSCProcessing(config.EnableEpochs{}, testscommon.CreateMemUnit()) - nodesConfigProvider, _ := notifier.NewNodesConfigProvider(args.EpochNotifier, []config.MaxNodesChangeConfig{{MaxNumNodes: 8}}) + nodesConfigProvider, _ := notifier.NewNodesConfigProvider(args.EpochNotifier, []config.MaxNodesChangeConfig{{MaxNumNodes: 9}}) auctionCfg := config.SoftAuctionConfig{ TopUpStep: "10", @@ -2179,7 +2179,7 @@ func TestSystemSCProcessor_ProcessSystemSmartContractStakingV4Enabled(t *testing will not participate in auction selection - owner6 does not have enough stake for 2 nodes => one of his auction nodes(pubKey14) will be unStaked at the end of the epoch => his other auction node(pubKey15) will not participate in auction selection - - MaxNumNodes = 8 + - MaxNumNodes = 9 - EligibleBlsKeys = 5 (pubKey0, pubKey1, pubKey3, pubKe13, pubKey17) - QualifiedAuctionBlsKeys = 7 (pubKey2, pubKey4, pubKey5, pubKey7, pubKey9, pubKey10, pubKey11) We can only select (MaxNumNodes - EligibleBlsKeys = 3) bls keys from AuctionList to be added to NewList diff --git a/integrationTests/vm/staking/stakingV4_test.go b/integrationTests/vm/staking/stakingV4_test.go index 67b1f19ab03..3b139c40b29 100644 --- a/integrationTests/vm/staking/stakingV4_test.go +++ b/integrationTests/vm/staking/stakingV4_test.go @@ -1524,3 +1524,166 @@ func TestStakingV4_LeavingNodesEdgeCases(t *testing.T) { owner1LeftNodes := getIntersection(owner1NodesThatAreStillForcedToRemain, allCurrentNodesInSystem) require.Zero(t, len(owner1LeftNodes)) } + +// TODO if necessary: +// - test with limit (unstake exactly 80 per shard) +// - unstake more nodes when waiting lists are pretty empty + +func TestStakingV4LeavingNodesShouldDistributeToWaitingOnlyNecessaryNodes(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + numOfMetaNodes := uint32(400) + numOfShards := uint32(3) + numOfEligibleNodesPerShard := uint32(400) + numOfWaitingNodesPerShard := uint32(400) + numOfNodesToShufflePerShard := uint32(80) + shardConsensusGroupSize := 266 + metaConsensusGroupSize := 266 + numOfNodesInStakingQueue := uint32(80) + + totalEligible := int(numOfEligibleNodesPerShard*numOfShards) + int(numOfMetaNodes) // 1600 + totalWaiting := int(numOfWaitingNodesPerShard*numOfShards) + int(numOfMetaNodes) // 1600 + + node := NewTestMetaProcessor( + numOfMetaNodes, + numOfShards, + numOfEligibleNodesPerShard, + numOfWaitingNodesPerShard, + numOfNodesToShufflePerShard, + shardConsensusGroupSize, + metaConsensusGroupSize, + numOfNodesInStakingQueue, + ) + node.EpochStartTrigger.SetRoundsPerEpoch(4) + + // 1. Check initial config is correct + initialNodes := node.NodesConfig + require.Len(t, getAllPubKeys(initialNodes.eligible), totalEligible) + require.Len(t, getAllPubKeys(initialNodes.waiting), totalWaiting) + require.Len(t, initialNodes.queue, int(numOfNodesInStakingQueue)) + require.Empty(t, initialNodes.shuffledOut) + require.Empty(t, initialNodes.auction) + + // 2. Check config after staking v4 initialization + node.Process(t, 5) + nodesConfigStakingV4Step1 := node.NodesConfig + require.Len(t, getAllPubKeys(nodesConfigStakingV4Step1.eligible), totalEligible) + require.Len(t, getAllPubKeys(nodesConfigStakingV4Step1.waiting), totalWaiting) + require.Empty(t, nodesConfigStakingV4Step1.queue) + require.Empty(t, nodesConfigStakingV4Step1.shuffledOut) + require.Empty(t, nodesConfigStakingV4Step1.auction) // the queue should be empty + + // 3. re-stake the node nodes that were in the queue + node.ProcessReStake(t, initialNodes.queue) + nodesConfigStakingV4Step1 = node.NodesConfig + requireSameSliceDifferentOrder(t, initialNodes.queue, nodesConfigStakingV4Step1.auction) + + node.Process(t, 10) + + epochs := 0 + prevConfig := node.NodesConfig + numOfSelectedNodesFromAuction := 320 // 320, since we will always fill shuffled out nodes with this config + numOfUnselectedNodesFromAuction := 80 // 80 = 400 from queue - 320 + numOfShuffledOut := 80 * 4 // 80 per shard + meta + for epochs < 4 { + node.Process(t, 5) + newNodeConfig := node.NodesConfig + + require.Len(t, getAllPubKeys(newNodeConfig.eligible), totalEligible) // 1600 + require.Len(t, getAllPubKeys(newNodeConfig.waiting), 1280) // 1280 + require.Len(t, getAllPubKeys(newNodeConfig.shuffledOut), 320) // 320 + require.Len(t, newNodeConfig.auction, 400) // 400 + require.Empty(t, newNodeConfig.queue) + require.Empty(t, newNodeConfig.leaving) + + checkStakingV4EpochChangeFlow(t, newNodeConfig, prevConfig, numOfShuffledOut, numOfUnselectedNodesFromAuction, numOfSelectedNodesFromAuction) + prevConfig = newNodeConfig + epochs++ + } + + // UnStake: + // - 46 from waiting + eligible ( 13 waiting + 36 eligible) + // - 11 from auction + currNodesCfg := node.NodesConfig + nodesToUnstakeFromAuction := currNodesCfg.auction[:11] + + nodesToUnstakeFromWaiting := append(currNodesCfg.waiting[0][:3], currNodesCfg.waiting[1][:3]...) + nodesToUnstakeFromWaiting = append(nodesToUnstakeFromWaiting, currNodesCfg.waiting[2][:3]...) + nodesToUnstakeFromWaiting = append(nodesToUnstakeFromWaiting, currNodesCfg.waiting[core.MetachainShardId][:4]...) + + nodesToUnstakeFromEligible := append(currNodesCfg.eligible[0][:8], currNodesCfg.eligible[1][:8]...) + nodesToUnstakeFromEligible = append(nodesToUnstakeFromEligible, currNodesCfg.eligible[2][:8]...) + nodesToUnstakeFromEligible = append(nodesToUnstakeFromEligible, currNodesCfg.eligible[core.MetachainShardId][:9]...) + + nodesToUnstake := getAllNodesToUnStake(nodesToUnstakeFromAuction, nodesToUnstakeFromWaiting, nodesToUnstakeFromEligible) + + prevConfig = currNodesCfg + node.ProcessUnStake(t, nodesToUnstake) + node.Process(t, 5) + currNodesCfg = node.NodesConfig + + require.Len(t, getAllPubKeys(currNodesCfg.leaving), 57) // 11 auction + 46 active (13 waiting + 36 eligible) + require.Len(t, getAllPubKeys(currNodesCfg.shuffledOut), 274) // 320 - 46 active + require.Len(t, currNodesCfg.auction, 343) // 400 initial - 57 leaving + requireSliceContainsNumOfElements(t, getAllPubKeys(currNodesCfg.waiting), prevConfig.auction, 320) // 320 selected + requireSliceContainsNumOfElements(t, currNodesCfg.auction, prevConfig.auction, 69) // 69 unselected + + nodesToUnstakeFromAuction = make([][]byte, 0) + nodesToUnstakeFromWaiting = make([][]byte, 0) + nodesToUnstakeFromEligible = make([][]byte, 0) + + prevConfig = currNodesCfg + // UnStake: + // - 224 from waiting + eligible ( 13 waiting + 36 eligible), but unbalanced: + // -> unStake 100 from waiting shard=meta => will force to stay = 100 from meta + // -> unStake 90 from eligible shard=2 => will force to stay = 90 from shard 2 + // - 11 from auction + nodesToUnstakeFromAuction = currNodesCfg.auction[:11] + nodesToUnstakeFromWaiting = append(currNodesCfg.waiting[0][:3], currNodesCfg.waiting[1][:3]...) + nodesToUnstakeFromWaiting = append(nodesToUnstakeFromWaiting, currNodesCfg.waiting[2][:3]...) + nodesToUnstakeFromWaiting = append(nodesToUnstakeFromWaiting, currNodesCfg.waiting[core.MetachainShardId][:100]...) + + nodesToUnstakeFromEligible = append(currNodesCfg.eligible[0][:8], currNodesCfg.eligible[1][:8]...) + nodesToUnstakeFromEligible = append(nodesToUnstakeFromEligible, currNodesCfg.eligible[2][:90]...) + nodesToUnstakeFromEligible = append(nodesToUnstakeFromEligible, currNodesCfg.eligible[core.MetachainShardId][:9]...) + + nodesToUnstake = getAllNodesToUnStake(nodesToUnstakeFromAuction, nodesToUnstakeFromWaiting, nodesToUnstakeFromEligible) + node.ProcessUnStake(t, nodesToUnstake) + node.Process(t, 5) + currNodesCfg = node.NodesConfig + + // Leaving: + // - 11 auction + // - shard 0 = 11 + // - shard 1 = 11 + // - shard 2 = 80 (there were 93 unStakes, but only 80 will be leaving, rest 13 will be forced to stay) + // - shard meta = 80 (there were 109 unStakes, but only 80 will be leaving, rest 29 will be forced to stay) + // Therefore we will have in total actually leaving = 193 (11 + 11 + 11 + 80 + 80) + // We should see a log in selector like this: + // auctionListSelector.SelectNodesFromAuctionList max nodes = 2880 current number of validators = 2656 num of nodes which will be shuffled out = 138 num forced to stay = 42 num of validators after shuffling = 2518 auction list size = 332 available slots (2880 - 2560) = 320 + require.Len(t, getAllPubKeys(currNodesCfg.leaving), 193) + require.Len(t, getAllPubKeys(currNodesCfg.shuffledOut), 138) // 69 from shard0 + shard from shard1, rest will not be shuffled + require.Len(t, currNodesCfg.auction, 150) // 138 shuffled out + 12 unselected + requireSliceContainsNumOfElements(t, getAllPubKeys(currNodesCfg.waiting), prevConfig.auction, 320) // 320 selected + requireSliceContainsNumOfElements(t, currNodesCfg.auction, prevConfig.auction, 12) // 12 unselected +} + +func getAllNodesToUnStake(nodesToUnStakeFromAuction, nodesToUnStakeFromWaiting, nodesToUnStakeFromEligible [][]byte) map[string][][]byte { + ret := make(map[string][][]byte) + + for _, nodeToUnstake := range nodesToUnStakeFromAuction { + ret[string(nodeToUnstake)] = [][]byte{nodeToUnstake} + } + + for _, nodeToUnstake := range nodesToUnStakeFromWaiting { + ret[string(nodeToUnstake)] = [][]byte{nodeToUnstake} + } + + for _, nodeToUnstake := range nodesToUnStakeFromEligible { + ret[string(nodeToUnstake)] = [][]byte{nodeToUnstake} + } + + return ret +} From f8151b193d479b93ff487b5df94a47dbe7a4d9eb Mon Sep 17 00:00:00 2001 From: MariusC Date: Fri, 12 Apr 2024 11:35:32 +0300 Subject: [PATCH 163/503] CLN: AddNewValidator to trie --- epochStart/metachain/legacySystemSCs.go | 28 +++++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/epochStart/metachain/legacySystemSCs.go b/epochStart/metachain/legacySystemSCs.go index 3247cb2dff1..2abe8a993fb 100644 --- a/epochStart/metachain/legacySystemSCs.go +++ b/epochStart/metachain/legacySystemSCs.go @@ -1262,22 +1262,32 @@ func (s *legacySystemSCProcessor) addNewlyStakedNodesToValidatorTrie( AccumulatedFees: big.NewInt(0), } - existingValidator := validatorsInfoMap.GetValidator(validatorInfo.GetPublicKey()) - // This fix is not be backwards incompatible - if !check.IfNil(existingValidator) && s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) { - err = validatorsInfoMap.Delete(existingValidator) - if err != nil { - return err - } + err = s.addNewValidator(validatorsInfoMap, validatorInfo) + if err != nil { + return err } + } - err = validatorsInfoMap.Add(validatorInfo) + return nil +} + +func (s *legacySystemSCProcessor) addNewValidator( + validatorsInfoMap state.ShardValidatorsInfoMapHandler, + validatorInfo state.ValidatorInfoHandler, +) error { + if !s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) { + return validatorsInfoMap.Add(validatorInfo) + } + + existingValidator := validatorsInfoMap.GetValidator(validatorInfo.GetPublicKey()) + if !check.IfNil(existingValidator) { + err := validatorsInfoMap.Delete(existingValidator) if err != nil { return err } } - return nil + return validatorsInfoMap.Add(validatorInfo) } func (s *legacySystemSCProcessor) initESDT() error { From 5afe305f43530adfb5bf98a31a6fa37f4dc467ae Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Fri, 12 Apr 2024 12:13:48 +0300 Subject: [PATCH 164/503] fix after merge --- cmd/node/config/prefs.toml | 4 ++-- config/overridableConfig/configOverriding_test.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/node/config/prefs.toml b/cmd/node/config/prefs.toml index 42e16508608..8f3a2343a79 100644 --- a/cmd/node/config/prefs.toml +++ b/cmd/node/config/prefs.toml @@ -38,8 +38,8 @@ # so that certain config values need to remain the same during upgrades. # (for example, an Elasticsearch user wants external.toml->ElasticSearchConnector.Enabled to remain true all the time during upgrades, while the default # configuration of the node has the false value) - # The Path indicates what value to change, while Value represents the new value in string format. The node operator must make sure - # to follow the same type of the original value (ex: uint32: "37", float32: "37.0", bool: "true") + # The Path indicates what value to change, while Value represents the new value. The node operator must make sure + # to follow the same type of the original value (ex: uint32: 37, float32: 37.0, bool: true) # Also, the Value can be a struct (ex: { StartEpoch = 0, Version = "1.5" }) or an array (ex: [{ StartEpoch = 0, Version = "1.4" }, { StartEpoch = 1, Version = "1.5" }]) # File represents the file name that holds the configuration. Currently, the supported files are: # api.toml, config.toml, economics.toml, enableEpochs.toml, enableRounds.toml, external.toml, fullArchiveP2P.toml, p2p.toml, ratings.toml, systemSmartContractsConfig.toml diff --git a/config/overridableConfig/configOverriding_test.go b/config/overridableConfig/configOverriding_test.go index a15a1b6a4ad..5e23a2bacda 100644 --- a/config/overridableConfig/configOverriding_test.go +++ b/config/overridableConfig/configOverriding_test.go @@ -88,7 +88,7 @@ func TestOverrideConfigValues(t *testing.T) { configs := &config.Configs{ApiRoutesConfig: &config.ApiRoutesConfig{}} - err := OverrideConfigValues([]config.OverridableConfig{{Path: "Logging.LoggingEnabled", Value: "true", File: "api.toml"}}, configs) + err := OverrideConfigValues([]config.OverridableConfig{{Path: "Logging.LoggingEnabled", Value: true, File: "api.toml"}}, configs) require.NoError(t, err) require.True(t, configs.ApiRoutesConfig.Logging.LoggingEnabled) }) @@ -121,7 +121,7 @@ func TestOverrideConfigValues(t *testing.T) { configs := &config.Configs{RatingsConfig: &config.RatingsConfig{}} - err := OverrideConfigValues([]config.OverridableConfig{{Path: "General.StartRating", Value: "37", File: "ratings.toml"}}, configs) + err := OverrideConfigValues([]config.OverridableConfig{{Path: "General.StartRating", Value: 37, File: "ratings.toml"}}, configs) require.NoError(t, err) require.Equal(t, uint32(37), configs.RatingsConfig.General.StartRating) }) @@ -131,7 +131,7 @@ func TestOverrideConfigValues(t *testing.T) { configs := &config.Configs{SystemSCConfig: &config.SystemSmartContractsConfig{}} - err := OverrideConfigValues([]config.OverridableConfig{{Path: "StakingSystemSCConfig.UnBondPeriod", Value: "37", File: "systemSmartContractsConfig.toml"}}, configs) + err := OverrideConfigValues([]config.OverridableConfig{{Path: "StakingSystemSCConfig.UnBondPeriod", Value: 37, File: "systemSmartContractsConfig.toml"}}, configs) require.NoError(t, err) require.Equal(t, uint64(37), configs.SystemSCConfig.StakingSystemSCConfig.UnBondPeriod) }) From 86445c954e5a290a68bca997dad69c2026e2bda4 Mon Sep 17 00:00:00 2001 From: MariusC Date: Fri, 12 Apr 2024 13:21:02 +0300 Subject: [PATCH 165/503] CLN: auctionListSelector.go --- epochStart/metachain/auctionListSelector.go | 38 +++++++++++-------- integrationTests/vm/staking/stakingV4_test.go | 1 + 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/epochStart/metachain/auctionListSelector.go b/epochStart/metachain/auctionListSelector.go index 7737dba8fc8..becbfd8409d 100644 --- a/epochStart/metachain/auctionListSelector.go +++ b/epochStart/metachain/auctionListSelector.go @@ -210,12 +210,13 @@ func (als *auctionListSelector) SelectNodesFromAuctionList( } maxNumNodes := currNodesConfig.MaxNumNodes - availableSlots, err := safeSub(maxNumNodes, numOfValidatorsAfterShuffling+numForcedToStay) + numValidatorsAfterShufflingWithForcedToStay := numOfValidatorsAfterShuffling + numForcedToStay + availableSlots, err := safeSub(maxNumNodes, numValidatorsAfterShufflingWithForcedToStay) if availableSlots == 0 || err != nil { log.Info(fmt.Sprintf("auctionListSelector.SelectNodesFromAuctionList: %v or zero value when trying to compute availableSlots = %v - %v (maxNodes - numOfValidatorsAfterShuffling+numForcedToStay); skip selecting nodes from auction list", err, maxNumNodes, - numOfValidatorsAfterShuffling+numForcedToStay, + numValidatorsAfterShufflingWithForcedToStay, )) return nil } @@ -225,9 +226,9 @@ func (als *auctionListSelector) SelectNodesFromAuctionList( "current number of validators", currNumOfValidators, "num of nodes which will be shuffled out", numOfShuffledNodes, "num forced to stay", numForcedToStay, - "num of validators after shuffling", numOfValidatorsAfterShuffling, + "num of validators after shuffling with forced to stay", numValidatorsAfterShufflingWithForcedToStay, "auction list size", auctionListSize, - fmt.Sprintf("available slots (%v - %v)", maxNumNodes, numOfValidatorsAfterShuffling+numForcedToStay), availableSlots, + fmt.Sprintf("available slots (%v - %v)", maxNumNodes, numValidatorsAfterShufflingWithForcedToStay), availableSlots, ) als.auctionListDisplayer.DisplayOwnersData(ownersData) @@ -275,25 +276,27 @@ func isInAuction(validator state.ValidatorInfoHandler) bool { func (als *auctionListSelector) computeNumShuffledNodes(currNodesConfig config.MaxNodesChangeConfig) (uint32, uint32) { numNodesToShufflePerShard := currNodesConfig.NodesToShufflePerShard - numShuffledOut := numNodesToShufflePerShard * (als.shardCoordinator.NumberOfShards() + 1) + numTotalToShuffleOut := numNodesToShufflePerShard * (als.shardCoordinator.NumberOfShards() + 1) epochStats := als.stakingDataProvider.GetCurrentEpochValidatorStats() actuallyNumLeaving := uint32(0) forcedToStay := uint32(0) + for shardID := uint32(0); shardID < als.shardCoordinator.NumberOfShards(); shardID++ { leavingInShard, forcedToStayInShard := computeActuallyNumLeaving(shardID, epochStats, numNodesToShufflePerShard) actuallyNumLeaving += leavingInShard forcedToStay += forcedToStayInShard } - leavingInShard, forcedToStayInShard := computeActuallyNumLeaving(core.MetachainShardId, epochStats, numNodesToShufflePerShard) - actuallyNumLeaving += leavingInShard - forcedToStay += forcedToStayInShard + leavingInMeta, forcedToStayInMeta := computeActuallyNumLeaving(core.MetachainShardId, epochStats, numNodesToShufflePerShard) + actuallyNumLeaving += leavingInMeta + forcedToStay += forcedToStayInMeta - finalShuffledOut, err := safeSub(numShuffledOut, actuallyNumLeaving) + finalShuffledOut, err := safeSub(numTotalToShuffleOut, actuallyNumLeaving) if err != nil { - log.Error("auctionListSelector.computeNumShuffledNodes", "error", err) - return numShuffledOut, 0 + log.Error("auctionListSelector.computeNumShuffledNodes error computing finalShuffledOut, returning default values", + "error", err, "numTotalToShuffleOut", numTotalToShuffleOut, "actuallyNumLeaving", actuallyNumLeaving) + return numTotalToShuffleOut, 0 } return finalShuffledOut, forcedToStay @@ -303,21 +306,24 @@ func computeActuallyNumLeaving(shardID uint32, epochStats epochStart.ValidatorSt numLeavingInShard := uint32(epochStats.Leaving[shardID]) numActiveInShard := uint32(epochStats.Waiting[shardID] + epochStats.Eligible[shardID]) - log.Info("auctionListSelector.computeActuallyNumLeaving", + log.Debug("auctionListSelector.computeActuallyNumLeaving computing", "shardID", shardID, "numLeavingInShard", numLeavingInShard, "numActiveInShard", numActiveInShard) - actuallyleaving := uint32(0) + actuallyLeaving := uint32(0) forcedToStay := uint32(0) if numLeavingInShard < numNodesToShuffledPerShard && numActiveInShard > numLeavingInShard { - actuallyleaving = numLeavingInShard + actuallyLeaving = numLeavingInShard } if numLeavingInShard > numNodesToShuffledPerShard { - actuallyleaving = numNodesToShuffledPerShard + actuallyLeaving = numNodesToShuffledPerShard forcedToStay = numLeavingInShard - numNodesToShuffledPerShard } - return actuallyleaving, forcedToStay + log.Debug("auctionListSelector.computeActuallyNumLeaving computed", + "actuallyLeaving", actuallyLeaving, "forcedToStay", forcedToStay) + + return actuallyLeaving, forcedToStay } // TODO: Move this in elrond-go-core diff --git a/integrationTests/vm/staking/stakingV4_test.go b/integrationTests/vm/staking/stakingV4_test.go index 3b139c40b29..f7cd6d698d8 100644 --- a/integrationTests/vm/staking/stakingV4_test.go +++ b/integrationTests/vm/staking/stakingV4_test.go @@ -1528,6 +1528,7 @@ func TestStakingV4_LeavingNodesEdgeCases(t *testing.T) { // TODO if necessary: // - test with limit (unstake exactly 80 per shard) // - unstake more nodes when waiting lists are pretty empty +// - chain simulator api calls func TestStakingV4LeavingNodesShouldDistributeToWaitingOnlyNecessaryNodes(t *testing.T) { if testing.Short() { From ec0a7251a631c5283b8c85a9b877a9edb58d0bcc Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Fri, 12 Apr 2024 13:23:07 +0300 Subject: [PATCH 166/503] golangci-lint fix --- .github/workflows/golangci-lint.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 611fadc3d08..47044a12169 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -5,6 +5,8 @@ on: - master pull_request: branches: [ master, feat/*, rc/* ] + workflow_dispatch: + branches: [ master, feat/*, rc/* ] permissions: contents: read From d9412ac23f8d1dca2e27a3ee93c5754e99f76fac Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Fri, 12 Apr 2024 13:28:56 +0300 Subject: [PATCH 167/503] small fix --- .github/workflows/golangci-lint.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 47044a12169..1cc46af26c8 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -6,7 +6,6 @@ on: pull_request: branches: [ master, feat/*, rc/* ] workflow_dispatch: - branches: [ master, feat/*, rc/* ] permissions: contents: read From a3207449ccfdb5c8da793a47d3b1f6d69f988cf5 Mon Sep 17 00:00:00 2001 From: MariusC Date: Fri, 12 Apr 2024 15:09:20 +0300 Subject: [PATCH 168/503] FEAT: Integration tests with more leaving than to shuffle --- epochStart/metachain/auctionListSelector.go | 2 +- epochStart/metachain/stakingDataProvider.go | 9 +- integrationTests/vm/staking/stakingV4_test.go | 178 ++++++++++++++---- .../testMetaProcessorWithCustomNodesConfig.go | 2 +- .../stakingcommon/stakingDataProviderStub.go | 1 + 5 files changed, 146 insertions(+), 46 deletions(-) diff --git a/epochStart/metachain/auctionListSelector.go b/epochStart/metachain/auctionListSelector.go index becbfd8409d..96c65e4a579 100644 --- a/epochStart/metachain/auctionListSelector.go +++ b/epochStart/metachain/auctionListSelector.go @@ -311,7 +311,7 @@ func computeActuallyNumLeaving(shardID uint32, epochStats epochStart.ValidatorSt actuallyLeaving := uint32(0) forcedToStay := uint32(0) - if numLeavingInShard < numNodesToShuffledPerShard && numActiveInShard > numLeavingInShard { + if numLeavingInShard <= numNodesToShuffledPerShard && numActiveInShard > numLeavingInShard { actuallyLeaving = numLeavingInShard } diff --git a/epochStart/metachain/stakingDataProvider.go b/epochStart/metachain/stakingDataProvider.go index 00c559bc6ad..b655fbe1b16 100644 --- a/epochStart/metachain/stakingDataProvider.go +++ b/epochStart/metachain/stakingDataProvider.go @@ -570,15 +570,12 @@ func (sdp *stakingDataProvider) isValidatorLeaving(validatorCurrentList, validat } // If no previous list is set, means that staking v4 is not activated or node is leaving right before activation - // and this node will be considered as eligible by the nodes coordinator with legacy bug. + // and this node will be considered as eligible by the nodes coordinator with old code. // Otherwise, it will have it set, and we should check its previous list in the current epoch - if len(validatorPreviousList) == 0 || validatorPreviousList == common.EligibleList || validatorPreviousList == common.WaitingList { - return true - } - - return false + return len(validatorPreviousList) == 0 || validatorPreviousList == common.EligibleList || validatorPreviousList == common.WaitingList } +// GetCurrentEpochValidatorStats returns the current epoch validator stats func (sdp *stakingDataProvider) GetCurrentEpochValidatorStats() epochStart.ValidatorStatsInEpoch { sdp.mutStakingData.RLock() defer sdp.mutStakingData.RUnlock() diff --git a/integrationTests/vm/staking/stakingV4_test.go b/integrationTests/vm/staking/stakingV4_test.go index f7cd6d698d8..b6a351ed7f7 100644 --- a/integrationTests/vm/staking/stakingV4_test.go +++ b/integrationTests/vm/staking/stakingV4_test.go @@ -186,6 +186,22 @@ func checkStakingV4EpochChangeFlow( requireSliceContainsNumOfElements(t, getAllPubKeys(currNodesConfig.waiting), prevNodesConfig.auction, numOfSelectedNodesFromAuction) } +func getAllOwnerNodesMap(nodeGroups ...[][]byte) map[string][][]byte { + ret := make(map[string][][]byte) + + for _, nodes := range nodeGroups { + addNodesToMap(nodes, ret) + } + + return ret +} + +func addNodesToMap(nodes [][]byte, allOwnerNodes map[string][][]byte) { + for _, node := range nodes { + allOwnerNodes[string(node)] = [][]byte{node} + } +} + func TestStakingV4(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") @@ -1581,14 +1597,14 @@ func TestStakingV4LeavingNodesShouldDistributeToWaitingOnlyNecessaryNodes(t *tes nodesConfigStakingV4Step1 = node.NodesConfig requireSameSliceDifferentOrder(t, initialNodes.queue, nodesConfigStakingV4Step1.auction) + // Reach step 3 and check normal flow node.Process(t, 10) - epochs := 0 prevConfig := node.NodesConfig numOfSelectedNodesFromAuction := 320 // 320, since we will always fill shuffled out nodes with this config numOfUnselectedNodesFromAuction := 80 // 80 = 400 from queue - 320 numOfShuffledOut := 80 * 4 // 80 per shard + meta - for epochs < 4 { + for epochs < 3 { node.Process(t, 5) newNodeConfig := node.NodesConfig @@ -1608,20 +1624,20 @@ func TestStakingV4LeavingNodesShouldDistributeToWaitingOnlyNecessaryNodes(t *tes // - 46 from waiting + eligible ( 13 waiting + 36 eligible) // - 11 from auction currNodesCfg := node.NodesConfig - nodesToUnstakeFromAuction := currNodesCfg.auction[:11] + nodesToUnStakeFromAuction := currNodesCfg.auction[:11] - nodesToUnstakeFromWaiting := append(currNodesCfg.waiting[0][:3], currNodesCfg.waiting[1][:3]...) - nodesToUnstakeFromWaiting = append(nodesToUnstakeFromWaiting, currNodesCfg.waiting[2][:3]...) - nodesToUnstakeFromWaiting = append(nodesToUnstakeFromWaiting, currNodesCfg.waiting[core.MetachainShardId][:4]...) + nodesToUnStakeFromWaiting := append(currNodesCfg.waiting[0][:3], currNodesCfg.waiting[1][:3]...) + nodesToUnStakeFromWaiting = append(nodesToUnStakeFromWaiting, currNodesCfg.waiting[2][:3]...) + nodesToUnStakeFromWaiting = append(nodesToUnStakeFromWaiting, currNodesCfg.waiting[core.MetachainShardId][:4]...) - nodesToUnstakeFromEligible := append(currNodesCfg.eligible[0][:8], currNodesCfg.eligible[1][:8]...) - nodesToUnstakeFromEligible = append(nodesToUnstakeFromEligible, currNodesCfg.eligible[2][:8]...) - nodesToUnstakeFromEligible = append(nodesToUnstakeFromEligible, currNodesCfg.eligible[core.MetachainShardId][:9]...) + nodesToUnStakeFromEligible := append(currNodesCfg.eligible[0][:8], currNodesCfg.eligible[1][:8]...) + nodesToUnStakeFromEligible = append(nodesToUnStakeFromEligible, currNodesCfg.eligible[2][:8]...) + nodesToUnStakeFromEligible = append(nodesToUnStakeFromEligible, currNodesCfg.eligible[core.MetachainShardId][:9]...) - nodesToUnstake := getAllNodesToUnStake(nodesToUnstakeFromAuction, nodesToUnstakeFromWaiting, nodesToUnstakeFromEligible) + nodesToUnStake := getAllOwnerNodesMap(nodesToUnStakeFromAuction, nodesToUnStakeFromWaiting, nodesToUnStakeFromEligible) prevConfig = currNodesCfg - node.ProcessUnStake(t, nodesToUnstake) + node.ProcessUnStake(t, nodesToUnStake) node.Process(t, 5) currNodesCfg = node.NodesConfig @@ -1631,28 +1647,28 @@ func TestStakingV4LeavingNodesShouldDistributeToWaitingOnlyNecessaryNodes(t *tes requireSliceContainsNumOfElements(t, getAllPubKeys(currNodesCfg.waiting), prevConfig.auction, 320) // 320 selected requireSliceContainsNumOfElements(t, currNodesCfg.auction, prevConfig.auction, 69) // 69 unselected - nodesToUnstakeFromAuction = make([][]byte, 0) - nodesToUnstakeFromWaiting = make([][]byte, 0) - nodesToUnstakeFromEligible = make([][]byte, 0) + nodesToUnStakeFromAuction = make([][]byte, 0) + nodesToUnStakeFromWaiting = make([][]byte, 0) + nodesToUnStakeFromEligible = make([][]byte, 0) prevConfig = currNodesCfg // UnStake: // - 224 from waiting + eligible ( 13 waiting + 36 eligible), but unbalanced: - // -> unStake 100 from waiting shard=meta => will force to stay = 100 from meta - // -> unStake 90 from eligible shard=2 => will force to stay = 90 from shard 2 + // -> unStake 100 from waiting shard=meta + // -> unStake 90 from eligible shard=2 // - 11 from auction - nodesToUnstakeFromAuction = currNodesCfg.auction[:11] - nodesToUnstakeFromWaiting = append(currNodesCfg.waiting[0][:3], currNodesCfg.waiting[1][:3]...) - nodesToUnstakeFromWaiting = append(nodesToUnstakeFromWaiting, currNodesCfg.waiting[2][:3]...) - nodesToUnstakeFromWaiting = append(nodesToUnstakeFromWaiting, currNodesCfg.waiting[core.MetachainShardId][:100]...) + nodesToUnStakeFromAuction = currNodesCfg.auction[:11] + nodesToUnStakeFromWaiting = append(currNodesCfg.waiting[0][:3], currNodesCfg.waiting[1][:3]...) + nodesToUnStakeFromWaiting = append(nodesToUnStakeFromWaiting, currNodesCfg.waiting[2][:3]...) + nodesToUnStakeFromWaiting = append(nodesToUnStakeFromWaiting, currNodesCfg.waiting[core.MetachainShardId][:100]...) - nodesToUnstakeFromEligible = append(currNodesCfg.eligible[0][:8], currNodesCfg.eligible[1][:8]...) - nodesToUnstakeFromEligible = append(nodesToUnstakeFromEligible, currNodesCfg.eligible[2][:90]...) - nodesToUnstakeFromEligible = append(nodesToUnstakeFromEligible, currNodesCfg.eligible[core.MetachainShardId][:9]...) + nodesToUnStakeFromEligible = append(currNodesCfg.eligible[0][:8], currNodesCfg.eligible[1][:8]...) + nodesToUnStakeFromEligible = append(nodesToUnStakeFromEligible, currNodesCfg.eligible[2][:90]...) + nodesToUnStakeFromEligible = append(nodesToUnStakeFromEligible, currNodesCfg.eligible[core.MetachainShardId][:9]...) - nodesToUnstake = getAllNodesToUnStake(nodesToUnstakeFromAuction, nodesToUnstakeFromWaiting, nodesToUnstakeFromEligible) - node.ProcessUnStake(t, nodesToUnstake) - node.Process(t, 5) + nodesToUnStake = getAllOwnerNodesMap(nodesToUnStakeFromAuction, nodesToUnStakeFromWaiting, nodesToUnStakeFromEligible) + node.ProcessUnStake(t, nodesToUnStake) + node.Process(t, 4) currNodesCfg = node.NodesConfig // Leaving: @@ -1671,20 +1687,106 @@ func TestStakingV4LeavingNodesShouldDistributeToWaitingOnlyNecessaryNodes(t *tes requireSliceContainsNumOfElements(t, currNodesCfg.auction, prevConfig.auction, 12) // 12 unselected } -func getAllNodesToUnStake(nodesToUnStakeFromAuction, nodesToUnStakeFromWaiting, nodesToUnStakeFromEligible [][]byte) map[string][][]byte { - ret := make(map[string][][]byte) - - for _, nodeToUnstake := range nodesToUnStakeFromAuction { - ret[string(nodeToUnstake)] = [][]byte{nodeToUnstake} +func TestStakingV4MoreLeavingNodesThanToShufflePerShard(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") } - for _, nodeToUnstake := range nodesToUnStakeFromWaiting { - ret[string(nodeToUnstake)] = [][]byte{nodeToUnstake} - } + numOfMetaNodes := uint32(400) + numOfShards := uint32(3) + numOfEligibleNodesPerShard := uint32(400) + numOfWaitingNodesPerShard := uint32(400) + numOfNodesToShufflePerShard := uint32(80) + shardConsensusGroupSize := 266 + metaConsensusGroupSize := 266 + numOfNodesInStakingQueue := uint32(80) - for _, nodeToUnstake := range nodesToUnStakeFromEligible { - ret[string(nodeToUnstake)] = [][]byte{nodeToUnstake} - } + totalEligible := int(numOfEligibleNodesPerShard*numOfShards) + int(numOfMetaNodes) // 1600 + totalWaiting := int(numOfWaitingNodesPerShard*numOfShards) + int(numOfMetaNodes) // 1600 - return ret + node := NewTestMetaProcessor( + numOfMetaNodes, + numOfShards, + numOfEligibleNodesPerShard, + numOfWaitingNodesPerShard, + numOfNodesToShufflePerShard, + shardConsensusGroupSize, + metaConsensusGroupSize, + numOfNodesInStakingQueue, + ) + node.EpochStartTrigger.SetRoundsPerEpoch(4) + + // 1. Check initial config is correct + initialNodes := node.NodesConfig + require.Len(t, getAllPubKeys(initialNodes.eligible), totalEligible) + require.Len(t, getAllPubKeys(initialNodes.waiting), totalWaiting) + require.Len(t, initialNodes.queue, int(numOfNodesInStakingQueue)) + require.Empty(t, initialNodes.shuffledOut) + require.Empty(t, initialNodes.auction) + + // 2. Check config after staking v4 initialization + node.Process(t, 5) + nodesConfigStakingV4Step1 := node.NodesConfig + require.Len(t, getAllPubKeys(nodesConfigStakingV4Step1.eligible), totalEligible) + require.Len(t, getAllPubKeys(nodesConfigStakingV4Step1.waiting), totalWaiting) + require.Empty(t, nodesConfigStakingV4Step1.queue) + require.Empty(t, nodesConfigStakingV4Step1.shuffledOut) + require.Empty(t, nodesConfigStakingV4Step1.auction) // the queue should be empty + + // 3. re-stake the node nodes that were in the queue + node.ProcessReStake(t, initialNodes.queue) + nodesConfigStakingV4Step1 = node.NodesConfig + requireSameSliceDifferentOrder(t, initialNodes.queue, nodesConfigStakingV4Step1.auction) + + // Reach step 3 + node.Process(t, 10) + + // UnStake 100 nodes from each shard: + // - shard 0: 100 waiting + // - shard 1: 50 waiting + 50 eligible + // - shard 2: 20 waiting + 80 eligible + // - shard meta: 100 eligible + currNodesCfg := node.NodesConfig + + nodesToUnStakeFromWaiting := currNodesCfg.waiting[0][:100] + nodesToUnStakeFromWaiting = append(nodesToUnStakeFromWaiting, currNodesCfg.waiting[1][:50]...) + nodesToUnStakeFromWaiting = append(nodesToUnStakeFromWaiting, currNodesCfg.waiting[2][:20]...) + + nodesToUnStakeFromEligible := currNodesCfg.eligible[1][:50] + nodesToUnStakeFromEligible = append(nodesToUnStakeFromEligible, currNodesCfg.eligible[2][:80]...) + nodesToUnStakeFromEligible = append(nodesToUnStakeFromEligible, currNodesCfg.eligible[core.MetachainShardId][:100]...) + + nodesToUnStake := getAllOwnerNodesMap(nodesToUnStakeFromWaiting, nodesToUnStakeFromEligible) + + prevConfig := currNodesCfg + node.ProcessUnStake(t, nodesToUnStake) + node.Process(t, 4) + currNodesCfg = node.NodesConfig + + require.Len(t, getAllPubKeys(currNodesCfg.leaving), 320) // we unStaked 400, but only allowed 320 to leave + require.Len(t, getAllPubKeys(currNodesCfg.shuffledOut), 0) // no shuffled out, since 80 per shard were leaving + require.Len(t, currNodesCfg.auction, 80) // 400 initial - 320 selected + requireSliceContainsNumOfElements(t, getAllPubKeys(currNodesCfg.waiting), prevConfig.auction, 320) // 320 selected + requireSliceContainsNumOfElements(t, currNodesCfg.auction, prevConfig.auction, 80) // 80 unselected + + // Add 400 new nodes in the system and fast-forward + node.ProcessStake(t, map[string]*NodesRegisterData{ + "ownerX": { + BLSKeys: generateAddresses(99999, 400), + TotalStake: big.NewInt(nodePrice * 400), + }, + }) + node.Process(t, 10) + + // UnStake exactly 80 nodes + prevConfig = node.NodesConfig + nodesToUnStake = getAllOwnerNodesMap(node.NodesConfig.eligible[1][:80]) + node.ProcessUnStake(t, nodesToUnStake) + node.Process(t, 4) + + currNodesCfg = node.NodesConfig + require.Len(t, getAllPubKeys(currNodesCfg.leaving), 80) // 320 - 80 leaving + require.Len(t, getAllPubKeys(currNodesCfg.shuffledOut), 240) // 240 shuffled out + requireSliceContainsNumOfElements(t, getAllPubKeys(currNodesCfg.waiting), prevConfig.auction, 320) // 320 selected + requireSliceContainsNumOfElements(t, currNodesCfg.auction, prevConfig.auction, 80) // 80 unselected } diff --git a/integrationTests/vm/staking/testMetaProcessorWithCustomNodesConfig.go b/integrationTests/vm/staking/testMetaProcessorWithCustomNodesConfig.go index 841a2b77b43..f9e9da84a8d 100644 --- a/integrationTests/vm/staking/testMetaProcessorWithCustomNodesConfig.go +++ b/integrationTests/vm/staking/testMetaProcessorWithCustomNodesConfig.go @@ -115,7 +115,7 @@ func (tmp *TestMetaProcessor) doStake( CallerAddr: owner, Arguments: createStakeArgs(registerData.BLSKeys), CallValue: registerData.TotalStake, - GasProvided: 10, + GasProvided: 400, }, RecipientAddr: vm.ValidatorSCAddress, Function: "stake", diff --git a/testscommon/stakingcommon/stakingDataProviderStub.go b/testscommon/stakingcommon/stakingDataProviderStub.go index b6b356cc1e7..27ec1a550e2 100644 --- a/testscommon/stakingcommon/stakingDataProviderStub.go +++ b/testscommon/stakingcommon/stakingDataProviderStub.go @@ -88,6 +88,7 @@ func (sdps *StakingDataProviderStub) GetNumOfValidatorsInCurrentEpoch() uint32 { return 0 } +// GetCurrentEpochValidatorStats - func (sdps *StakingDataProviderStub) GetCurrentEpochValidatorStats() epochStart.ValidatorStatsInEpoch { return epochStart.ValidatorStatsInEpoch{ Eligible: map[uint32]int{}, From ddd8cdb791e650bd67a27e4df8dcce2330c396df Mon Sep 17 00:00:00 2001 From: MariusC Date: Fri, 12 Apr 2024 16:31:27 +0300 Subject: [PATCH 169/503] FEAT: Integration tests chain simulator with leaving active nodes --- integrationTests/chainSimulator/interface.go | 2 + .../staking/stake/stakeAndUnStake_test.go | 163 ++++++++++++++++++ 2 files changed, 165 insertions(+) diff --git a/integrationTests/chainSimulator/interface.go b/integrationTests/chainSimulator/interface.go index eff1aac7874..759858a69c5 100644 --- a/integrationTests/chainSimulator/interface.go +++ b/integrationTests/chainSimulator/interface.go @@ -5,6 +5,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data/api" "github.com/multiversx/mx-chain-core-go/data/transaction" + crypto "github.com/multiversx/mx-chain-crypto-go" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" "github.com/multiversx/mx-chain-go/node/chainSimulator/process" ) @@ -22,4 +23,5 @@ type ChainSimulator interface { GetInitialWalletKeys() *dtos.InitialWalletKeys GetAccount(address dtos.WalletAddress) (api.AccountResponse, error) ForceResetValidatorStatisticsCache() error + GetValidatorPrivateKeys() []crypto.PrivateKey } diff --git a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index 2b2246df713..57a8df77cec 100644 --- a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go @@ -4,6 +4,7 @@ import ( "encoding/hex" "fmt" "math/big" + "strings" "testing" "time" @@ -2302,3 +2303,165 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs require.Equal(t, 1, balanceAfterUnbonding.Cmp(balanceBeforeUnbonding)) } + +// Test that if we unStake one active node(waiting/eligible), the number of qualified nodes will remain the same +// Nodes configuration at genesis consisting of a total of 32 nodes, distributed on 3 shards + meta: +// - 4 eligible nodes/shard +// - 4 waiting nodes/shard +// - 2 nodes to shuffle per shard +// - max num nodes config for stakingV4 step3 = 24 (being downsized from previously 32 nodes) +// - with this config, we should always select 8 nodes from auction list +// We will add one extra node, so auction list size = 9, but will always select 8. Even if we unStake one active node, +// we should still only select 8 nodes. +func TestChainSimulator_UnStakeOneActiveNodeAndCheckAPIAuctionList(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 30, + } + + stakingV4Step1Epoch := uint32(2) + stakingV4Step2Epoch := uint32(3) + stakingV4Step3Epoch := uint32(4) + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 4, + MetaChainMinNodes: 4, + NumNodesWaitingListMeta: 4, + NumNodesWaitingListShard: 4, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = stakingV4Step1Epoch + cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = stakingV4Step2Epoch + cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = stakingV4Step3Epoch + + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[1].MaxNumNodes = 32 + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[1].NodesToShufflePerShard = 2 + + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = stakingV4Step3Epoch + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].MaxNumNodes = 24 + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].NodesToShufflePerShard = 2 + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + err = cs.GenerateBlocksUntilEpochIsReached(int32(stakingV4Step3Epoch + 1)) + require.Nil(t, err) + + metachainNode := cs.GetNodeHandler(core.MetachainShardId) + + numQualified, numUnQualified := getNumQualifiedAndUnqualified(t, metachainNode) + require.Equal(t, 8, numQualified) + require.Equal(t, 0, numUnQualified) + + stakeOneNode(t, cs) + + numQualified, numUnQualified = getNumQualifiedAndUnqualified(t, metachainNode) + require.Equal(t, 8, numQualified) + require.Equal(t, 1, numUnQualified) + + unStakeOneActiveNode(t, cs) + + numQualified, numUnQualified = getNumQualifiedAndUnqualified(t, metachainNode) + require.Equal(t, 8, numQualified) + require.Equal(t, 1, numUnQualified) +} + +func stakeOneNode(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator) { + privateKey, blsKeys, err := chainSimulator.GenerateBlsPrivateKeys(1) + require.Nil(t, err) + err = cs.AddValidatorKeys(privateKey) + require.Nil(t, err) + + mintValue := big.NewInt(0).Add(staking.MinimumStakeValue, staking.OneEGLD) + validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) + require.Nil(t, err) + + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, stakeTx) + + require.Nil(t, cs.GenerateBlocks(1)) +} + +func unStakeOneActiveNode(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator) { + err := cs.ForceResetValidatorStatisticsCache() + require.Nil(t, err) + + validators, err := cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ValidatorStatisticsApi() + require.Nil(t, err) + + idx := 0 + keyToUnStake := make([]byte, 0) + numKeys := len(cs.GetValidatorPrivateKeys()) + for idx = 0; idx < numKeys; idx++ { + keyToUnStake, err = cs.GetValidatorPrivateKeys()[idx].GeneratePublic().ToByteArray() + require.Nil(t, err) + + apiValidator, found := validators[hex.EncodeToString(keyToUnStake)] + require.True(t, found) + + validatorStatus := apiValidator.ValidatorStatus + if validatorStatus == "waiting" || validatorStatus == "eligible" { + log.Info("found active key to unStake", "index", idx, "bls key", keyToUnStake, "list", validatorStatus) + break + } + + if idx == numKeys-1 { + require.Fail(t, "did not find key to unStake") + } + } + + rcv := "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqplllst77y4l" + rcvAddrBytes, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Decode(rcv) + + validatorWallet := cs.GetInitialWalletKeys().StakeWallets[idx].Address + shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(validatorWallet.Bytes) + initialAccount, _, err := cs.GetNodeHandler(shardID).GetFacadeHandler().GetAccount(validatorWallet.Bech32, coreAPI.AccountQueryOptions{}) + + require.Nil(t, err) + tx := &transaction.Transaction{ + Nonce: initialAccount.Nonce, + Value: big.NewInt(0), + SndAddr: validatorWallet.Bytes, + RcvAddr: rcvAddrBytes, + Data: []byte(fmt.Sprintf("unStake@%s", hex.EncodeToString(keyToUnStake))), + GasLimit: 50_000_000, + GasPrice: 1000000000, + Signature: []byte("dummy"), + ChainID: []byte(configs.ChainID), + Version: 1, + } + _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + + err = cs.GenerateBlocks(1) + require.Nil(t, err) + + err = cs.ForceResetValidatorStatisticsCache() + require.Nil(t, err) + validators, err = cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ValidatorStatisticsApi() + require.Nil(t, err) + + apiValidator, found := validators[hex.EncodeToString(keyToUnStake)] + require.True(t, found) + require.True(t, strings.Contains(apiValidator.ValidatorStatus, "leaving")) +} From 4626f801f8f7fb6b8cc8c22aa7b7ccb56a45d6df Mon Sep 17 00:00:00 2001 From: MariusC Date: Fri, 12 Apr 2024 17:23:57 +0300 Subject: [PATCH 170/503] CLN: Comm --- integrationTests/vm/staking/stakingV4_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/integrationTests/vm/staking/stakingV4_test.go b/integrationTests/vm/staking/stakingV4_test.go index b6a351ed7f7..f927ddadfe3 100644 --- a/integrationTests/vm/staking/stakingV4_test.go +++ b/integrationTests/vm/staking/stakingV4_test.go @@ -1541,11 +1541,6 @@ func TestStakingV4_LeavingNodesEdgeCases(t *testing.T) { require.Zero(t, len(owner1LeftNodes)) } -// TODO if necessary: -// - test with limit (unstake exactly 80 per shard) -// - unstake more nodes when waiting lists are pretty empty -// - chain simulator api calls - func TestStakingV4LeavingNodesShouldDistributeToWaitingOnlyNecessaryNodes(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") From e1d0f11464dc3bdae9b63a57861052a61ec79283 Mon Sep 17 00:00:00 2001 From: MariusC Date: Fri, 12 Apr 2024 17:31:43 +0300 Subject: [PATCH 171/503] FIX: Remove StakingQueueEnabled flag --- common/constants.go | 1 - common/enablers/enableEpochsHandler.go | 6 ----- common/enablers/enableEpochsHandler_test.go | 9 -------- epochStart/metachain/legacySystemSCs.go | 25 +++++++++++---------- epochStart/metachain/systemSCs.go | 1 - 5 files changed, 13 insertions(+), 29 deletions(-) diff --git a/common/constants.go b/common/constants.go index 0476f1aa5e5..16c77a5d147 100644 --- a/common/constants.go +++ b/common/constants.go @@ -1011,7 +1011,6 @@ const ( StakingV4Step1Flag core.EnableEpochFlag = "StakingV4Step1Flag" StakingV4Step2Flag core.EnableEpochFlag = "StakingV4Step2Flag" StakingV4Step3Flag core.EnableEpochFlag = "StakingV4Step3Flag" - StakingQueueFlag core.EnableEpochFlag = "StakingQueueFlag" StakingV4StartedFlag core.EnableEpochFlag = "StakingV4StartedFlag" AlwaysMergeContextsInEEIFlag core.EnableEpochFlag = "AlwaysMergeContextsInEEIFlag" // all new flags must be added to createAllFlagsMap method, as part of enableEpochsHandler allFlagsDefined diff --git a/common/enablers/enableEpochsHandler.go b/common/enablers/enableEpochsHandler.go index d560a432462..f64dbf99ea5 100644 --- a/common/enablers/enableEpochsHandler.go +++ b/common/enablers/enableEpochsHandler.go @@ -713,12 +713,6 @@ func (handler *enableEpochsHandler) createAllFlagsMap() { }, activationEpoch: handler.enableEpochsConfig.StakingV4Step3EnableEpoch, }, - common.StakingQueueFlag: { - isActiveInEpoch: func(epoch uint32) bool { - return epoch < handler.enableEpochsConfig.StakingV4Step1EnableEpoch - }, - activationEpoch: handler.enableEpochsConfig.StakingV4Step1EnableEpoch, - }, common.StakingV4StartedFlag: { isActiveInEpoch: func(epoch uint32) bool { return epoch >= handler.enableEpochsConfig.StakingV4Step1EnableEpoch diff --git a/common/enablers/enableEpochsHandler_test.go b/common/enablers/enableEpochsHandler_test.go index c91f65b805a..4155b15dfbb 100644 --- a/common/enablers/enableEpochsHandler_test.go +++ b/common/enablers/enableEpochsHandler_test.go @@ -192,13 +192,6 @@ func TestEnableEpochsHandler_IsFlagEnabled(t *testing.T) { handler.EpochConfirmed(cfg.SetGuardianEnableEpoch+1, 0) require.True(t, handler.IsFlagEnabled(common.SetGuardianFlag)) - handler.EpochConfirmed(cfg.StakingV4Step1EnableEpoch-1, 0) - require.True(t, handler.IsFlagEnabled(common.StakingQueueFlag)) - handler.EpochConfirmed(cfg.StakingV4Step1EnableEpoch, 0) - require.False(t, handler.IsFlagEnabled(common.StakingQueueFlag)) - handler.EpochConfirmed(cfg.StakingV4Step1EnableEpoch+1, 0) - require.False(t, handler.IsFlagEnabled(common.StakingQueueFlag)) - handler.EpochConfirmed(cfg.StakingV4Step1EnableEpoch-1, 0) require.False(t, handler.IsFlagEnabled(common.StakingV4StartedFlag)) handler.EpochConfirmed(cfg.StakingV4Step1EnableEpoch, 0) @@ -318,7 +311,6 @@ func TestEnableEpochsHandler_IsFlagEnabled(t *testing.T) { require.False(t, handler.IsFlagEnabled(common.StakingV4Step1Flag)) require.True(t, handler.IsFlagEnabled(common.StakingV4Step2Flag)) require.True(t, handler.IsFlagEnabled(common.StakingV4Step3Flag)) - require.False(t, handler.IsFlagEnabled(common.StakingQueueFlag)) require.True(t, handler.IsFlagEnabled(common.StakingV4StartedFlag)) require.True(t, handler.IsFlagEnabled(common.AlwaysMergeContextsInEEIFlag)) } @@ -434,7 +426,6 @@ func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) { require.Equal(t, cfg.StakingV4Step1EnableEpoch, handler.GetActivationEpoch(common.StakingV4Step1Flag)) require.Equal(t, cfg.StakingV4Step2EnableEpoch, handler.GetActivationEpoch(common.StakingV4Step2Flag)) require.Equal(t, cfg.StakingV4Step3EnableEpoch, handler.GetActivationEpoch(common.StakingV4Step3Flag)) - require.Equal(t, cfg.StakingV4Step1EnableEpoch, handler.GetActivationEpoch(common.StakingQueueFlag)) require.Equal(t, cfg.StakingV4Step1EnableEpoch, handler.GetActivationEpoch(common.StakingV4StartedFlag)) require.Equal(t, cfg.AlwaysMergeContextsInEEIEnableEpoch, handler.GetActivationEpoch(common.AlwaysMergeContextsInEEIFlag)) } diff --git a/epochStart/metachain/legacySystemSCs.go b/epochStart/metachain/legacySystemSCs.go index 2abe8a993fb..677cbcb682b 100644 --- a/epochStart/metachain/legacySystemSCs.go +++ b/epochStart/metachain/legacySystemSCs.go @@ -207,7 +207,7 @@ func (s *legacySystemSCProcessor) processLegacy( return err } - if s.enableEpochsHandler.IsFlagEnabled(common.StakingQueueFlag) { + if !s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) { err = s.stakeNodesFromQueue(validatorsInfoMap, numUnStaked, nonce, common.NewList) if err != nil { return err @@ -598,20 +598,21 @@ func (s *legacySystemSCProcessor) updateMaxNodes(validatorsInfoMap state.ShardVa return err } - if !s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) { - if maxNumberOfNodes < prevMaxNumberOfNodes { - return epochStart.ErrInvalidMaxNumberOfNodes - } + if s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) { + return nil } - if s.enableEpochsHandler.IsFlagEnabled(common.StakingQueueFlag) { - sw.Start("stakeNodesFromQueue") - err = s.stakeNodesFromQueue(validatorsInfoMap, maxNumberOfNodes-prevMaxNumberOfNodes, nonce, common.NewList) - sw.Stop("stakeNodesFromQueue") - if err != nil { - return err - } + if maxNumberOfNodes < prevMaxNumberOfNodes { + return epochStart.ErrInvalidMaxNumberOfNodes } + + sw.Start("stakeNodesFromQueue") + err = s.stakeNodesFromQueue(validatorsInfoMap, maxNumberOfNodes-prevMaxNumberOfNodes, nonce, common.NewList) + sw.Stop("stakeNodesFromQueue") + if err != nil { + return err + } + return nil } diff --git a/epochStart/metachain/systemSCs.go b/epochStart/metachain/systemSCs.go index 229a41d5710..96cba60251b 100644 --- a/epochStart/metachain/systemSCs.go +++ b/epochStart/metachain/systemSCs.go @@ -78,7 +78,6 @@ func NewSystemSCProcessor(args ArgsNewEpochStartSystemSCProcessing) (*systemSCPr common.SaveJailedAlwaysFlag, common.StakingV4Step1Flag, common.StakingV4Step2Flag, - common.StakingQueueFlag, common.StakingV4StartedFlag, common.DelegationSmartContractFlagInSpecificEpochOnly, common.GovernanceFlagInSpecificEpochOnly, From a67343ddd00bba279ae921ae98a9165ccce15692 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Fri, 12 Apr 2024 18:00:58 +0300 Subject: [PATCH 172/503] added map support for over writable configs --- common/reflectcommon/structFieldsUpdate.go | 21 +++++++ .../reflectcommon/structFieldsUpdate_test.go | 55 ++++++++++++++++++- .../configOverriding_test.go | 10 ++-- testscommon/toml/config.go | 6 ++ 4 files changed, 84 insertions(+), 8 deletions(-) diff --git a/common/reflectcommon/structFieldsUpdate.go b/common/reflectcommon/structFieldsUpdate.go index 94ad6002c07..66434365179 100644 --- a/common/reflectcommon/structFieldsUpdate.go +++ b/common/reflectcommon/structFieldsUpdate.go @@ -123,6 +123,10 @@ func trySetTheNewValue(value *reflect.Value, newValue interface{}) error { structVal := reflect.ValueOf(newValue) return trySetStructValue(value, structVal) + case reflect.Map: + mapValue := reflect.ValueOf(newValue) + + return tryUpdateMapValue(value, mapValue) default: return fmt.Errorf("unsupported type <%s> when trying to set the value '%v' of type <%s>", valueKind, newValue, reflect.TypeOf(newValue)) } @@ -163,6 +167,23 @@ func trySetStructValue(value *reflect.Value, newValue reflect.Value) error { } } +func tryUpdateMapValue(value *reflect.Value, newValue reflect.Value) error { + if value.IsNil() { + value.Set(reflect.MakeMap(value.Type())) + } + + switch newValue.Kind() { + case reflect.Map: + for _, key := range newValue.MapKeys() { + value.SetMapIndex(key, newValue.MapIndex(key)) + } + default: + return fmt.Errorf("unsupported type <%s> when trying to add value in type <%s>", newValue.Kind(), value.Kind()) + } + + return nil +} + func updateStructFromMap(value *reflect.Value, newValue reflect.Value) error { for _, key := range newValue.MapKeys() { fieldName := key.String() diff --git a/common/reflectcommon/structFieldsUpdate_test.go b/common/reflectcommon/structFieldsUpdate_test.go index d2145ca8fa0..e59695598f4 100644 --- a/common/reflectcommon/structFieldsUpdate_test.go +++ b/common/reflectcommon/structFieldsUpdate_test.go @@ -5,9 +5,10 @@ import ( "reflect" "testing" - "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/testscommon/toml" + + "github.com/multiversx/mx-chain-core-go/core" "github.com/stretchr/testify/require" ) @@ -447,10 +448,10 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { expectedNewValue["first"] = 1 expectedNewValue["second"] = 2 - path := "TestMap.Value" + path := "TestInterface.Value" err = AdaptStructureValueBasedOnPath(testConfig, path, expectedNewValue) - require.Equal(t, "unsupported type when trying to set the value 'map[first:1 second:2]' of type ", err.Error()) + require.Equal(t, "unsupported type when trying to set the value 'map[first:1 second:2]' of type ", err.Error()) }) t.Run("should error fit signed for target type not int", func(t *testing.T) { @@ -1193,6 +1194,54 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { require.Equal(t, expectedNewValue, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription) }) + t.Run("should work on map and override existing value in map", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + expectedNewValue := make(map[string]int) + expectedNewValue["key"] = 100 + + path := "TestMap.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, expectedNewValue) + require.NoError(t, err) + require.Equal(t, 1, len(testConfig.TestMap.Value)) + require.Equal(t, testConfig.TestMap.Value["key"], 100) + }) + + t.Run("should work on map and insert values in map", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + expectedNewValue := make(map[string]int) + expectedNewValue["first"] = 1 + expectedNewValue["second"] = 2 + + path := "TestMap.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, expectedNewValue) + require.NoError(t, err) + require.Equal(t, 3, len(testConfig.TestMap.Value)) + }) + + t.Run("should error on map when override anything else other than map", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + expectedNewValue := 1 + + path := "TestMap.Value" + + err = AdaptStructureValueBasedOnPath(testConfig, path, expectedNewValue) + require.Equal(t, "unsupported type when trying to add value in type ", err.Error()) + }) + } func loadTestConfig(filepath string) (*toml.Config, error) { diff --git a/config/overridableConfig/configOverriding_test.go b/config/overridableConfig/configOverriding_test.go index 5e23a2bacda..9f187a8a501 100644 --- a/config/overridableConfig/configOverriding_test.go +++ b/config/overridableConfig/configOverriding_test.go @@ -5,6 +5,7 @@ import ( "github.com/multiversx/mx-chain-go/config" p2pConfig "github.com/multiversx/mx-chain-go/p2p/config" + "github.com/stretchr/testify/require" ) @@ -104,16 +105,15 @@ func TestOverrideConfigValues(t *testing.T) { }) t.Run("should work for enableRounds.toml", func(t *testing.T) { - // TODO: fix this test - t.Skip("skipped, as this test requires the fix from this PR: https://github.com/multiversx/mx-chain-go/pull/5851") - t.Parallel() configs := &config.Configs{RoundConfig: &config.RoundConfig{}} + value := make(map[string]config.ActivationRoundByName) + value["DisableAsyncCallV1"] = config.ActivationRoundByName{Round: "37"} - err := OverrideConfigValues([]config.OverridableConfig{{Path: "RoundActivations.DisableAsyncCallV1.Round", Value: "37", File: "enableRounds.toml"}}, configs) + err := OverrideConfigValues([]config.OverridableConfig{{Path: "RoundActivations", Value: value, File: "enableRounds.toml"}}, configs) require.NoError(t, err) - require.Equal(t, uint32(37), configs.RoundConfig.RoundActivations["DisableAsyncCallV1"]) + require.Equal(t, "37", configs.RoundConfig.RoundActivations["DisableAsyncCallV1"].Round) }) t.Run("should work for ratings.toml", func(t *testing.T) { diff --git a/testscommon/toml/config.go b/testscommon/toml/config.go index 47a45839be0..16ec8a7fdd4 100644 --- a/testscommon/toml/config.go +++ b/testscommon/toml/config.go @@ -15,6 +15,7 @@ type Config struct { TestConfigStruct TestConfigNestedStruct TestMap + TestInterface } // TestConfigI8 will hold an int8 value for testing @@ -169,3 +170,8 @@ type MessageDescriptionOtherName struct { type TestMap struct { Value map[string]int } + +// TestInterface will hold an interface for testing +type TestInterface struct { + Value interface{} +} From 18610880bd2d83655b2dc4391bbd018b19c7d655 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Mon, 15 Apr 2024 14:42:49 +0300 Subject: [PATCH 173/503] Integration tests for the new events for "claim developer rewards". --- go.mod | 2 +- go.sum | 4 +- .../developerRewards/developerRewards_test.go | 71 ++++++++++ .../developer-rewards/developer_rewards.c | 133 ++++++++++++++++++ .../developer_rewards.export | 7 + .../output/developer_rewards.wasm | Bin 0 -> 1171 bytes integrationTests/vm/wasm/utils.go | 16 ++- 7 files changed, 225 insertions(+), 8 deletions(-) create mode 100644 integrationTests/vm/wasm/developerRewards/developerRewards_test.go create mode 100644 integrationTests/vm/wasm/testdata/developer-rewards/developer_rewards.c create mode 100644 integrationTests/vm/wasm/testdata/developer-rewards/developer_rewards.export create mode 100755 integrationTests/vm/wasm/testdata/developer-rewards/output/developer_rewards.wasm diff --git a/go.mod b/go.mod index 9de88775caa..36abca09af5 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474 - github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240328091908-c46c76dac779 + github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240411132244-adf842b5e09e github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240328092329-b5f2c7c059eb github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240321152247-79521988c8e6 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240321152532-45da5eabdc38 diff --git a/go.sum b/go.sum index 96da81e0efb..69efd4b6287 100644 --- a/go.sum +++ b/go.sum @@ -399,8 +399,8 @@ github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157/go.mod h1:ndk45i9J9McuCJpTcgiaK4ocd0yhnBBCPrlFwO6GRcs= github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474 h1:x65Su8ojHwA+NICp9DrSVGLDDcAlW04DafkqCHY1QPE= github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474/go.mod h1:hnc6H4D5Ge1haRAQ6QHTXhyh+CT2DRiNJ0U0HQYI3DY= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240328091908-c46c76dac779 h1:FSgAtNcml8kWdIEn8MxCfPkZ8ZE/wIFNKI5TZLEfcT0= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240328091908-c46c76dac779/go.mod h1:G6daPJC6bFsvAw45RPMCRi2rP+8LjFxa8G+3alHuJow= +github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240411132244-adf842b5e09e h1:SJmm+Lkxdj/eJ4t/CCcvhZCZtg2A1ieVoJV5FJooFKA= +github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240411132244-adf842b5e09e/go.mod h1:G6daPJC6bFsvAw45RPMCRi2rP+8LjFxa8G+3alHuJow= github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240328092329-b5f2c7c059eb h1:0WvWXqzliYS1yKW+6uTxZGMjQd08IQNPzlNNxxyNWHM= github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240328092329-b5f2c7c059eb/go.mod h1:mZNRILxq51LVqwqE9jMJyDHgmy9W3x7otOGuFjOm82Q= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240321152247-79521988c8e6 h1:7HqUo9YmpsfN/y9px6RmzREJm5O6ZzP9NqvFSrHTw24= diff --git a/integrationTests/vm/wasm/developerRewards/developerRewards_test.go b/integrationTests/vm/wasm/developerRewards/developerRewards_test.go new file mode 100644 index 00000000000..356ffc29db5 --- /dev/null +++ b/integrationTests/vm/wasm/developerRewards/developerRewards_test.go @@ -0,0 +1,71 @@ +package transfers + +import ( + "math/big" + "testing" + + "github.com/multiversx/mx-chain-go/integrationTests/vm/wasm" + "github.com/stretchr/testify/require" +) + +func TestClaimDeveloperRewards(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + context := wasm.SetupTestContext(t) + defer context.Close() + + err := context.DeploySC("../testdata/developer-rewards/output/developer_rewards.wasm", "") + require.Nil(t, err) + + t.Run("rewards for user", func(t *testing.T) { + contractAddress := context.ScAddress + + err = context.ExecuteSC(&context.Owner, "doSomething") + require.Nil(t, err) + + ownerBalanceBefore := context.GetAccountBalance(&context.Owner).Uint64() + reward := context.GetAccount(contractAddress).GetDeveloperReward().Uint64() + + err = context.ExecuteSC(&context.Owner, "ClaimDeveloperRewards") + require.Nil(t, err) + + ownerBalanceAfter := context.GetAccountBalance(&context.Owner).Uint64() + require.Equal(t, ownerBalanceBefore-context.LastConsumedFee+reward, ownerBalanceAfter) + + events := context.LastLogs[0].GetLogEvents() + require.Equal(t, "ClaimDeveloperRewards", string(events[0].GetIdentifier())) + require.Equal(t, big.NewInt(0).SetUint64(reward).Bytes(), events[0].GetTopics()[0]) + require.Equal(t, context.Owner.Address, events[0].GetTopics()[1]) + }) + + t.Run("rewards for contract", func(t *testing.T) { + parentContractAddress := context.ScAddress + + err = context.ExecuteSC(&context.Owner, "deployChild") + require.Nil(t, err) + + chilContractdAddress := context.QuerySCBytes("getChildAddress", [][]byte{}) + require.NotNil(t, chilContractdAddress) + + context.ScAddress = chilContractdAddress + err = context.ExecuteSC(&context.Owner, "doSomething") + require.Nil(t, err) + + contractBalanceBefore := context.GetAccount(parentContractAddress).GetBalance().Uint64() + reward := context.GetAccount(chilContractdAddress).GetDeveloperReward().Uint64() + + context.ScAddress = parentContractAddress + err = context.ExecuteSC(&context.Owner, "claimDeveloperRewardsOnChild") + require.Nil(t, err) + + contractBalanceAfter := context.GetAccount(parentContractAddress).GetBalance().Uint64() + require.Equal(t, contractBalanceBefore+reward, contractBalanceAfter) + + events := context.LastLogs[0].GetLogEvents() + require.Equal(t, "ClaimDeveloperRewards", string(events[0].GetIdentifier())) + require.Equal(t, big.NewInt(0).SetUint64(reward).Bytes(), events[0].GetTopics()[0]) + require.Equal(t, parentContractAddress, events[0].GetTopics()[1]) + }) +} diff --git a/integrationTests/vm/wasm/testdata/developer-rewards/developer_rewards.c b/integrationTests/vm/wasm/testdata/developer-rewards/developer_rewards.c new file mode 100644 index 00000000000..194c5d68c1d --- /dev/null +++ b/integrationTests/vm/wasm/testdata/developer-rewards/developer_rewards.c @@ -0,0 +1,133 @@ +typedef unsigned char byte; +typedef unsigned int i32; +typedef unsigned long long i64; + +void getSCAddress(byte *address); +int storageStore(byte *key, int keyLength, byte *data, int dataLength); +int storageLoad(byte *key, int keyLength, byte *data); +void finish(byte *data, int length); + +int deployFromSourceContract( + long long gas, + byte *value, + byte *sourceContractAddress, + byte *codeMetadata, + byte *newAddress, + int numInitArgs, + byte *initArgLengths, + byte *initArgs); + +i32 createAsyncCall( + byte *destination, + byte *value, + byte *data, + int dataLength, + byte *success, + int successLength, + byte *error, + int errorLength, + long long gas, + long long extraGasForCallback); + +static const i32 ADDRESS_LENGTH = 32; + +byte zero32_red[32] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +byte zero32_green[32] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +byte zero32_blue[32] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + +// E.g. can hold up to 64 addresses. +byte zero2048_red[2048] = {0}; +byte zero2048_green[2048] = {0}; +byte zero2048_blue[2048] = {0}; + +byte zeroEGLD[] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + +byte codeMetadataUpgradeableReadable[2] = {5, 0}; + +byte emptyArguments[0] = {}; +int emptyArgumentsLengths[0] = {}; +int gasLimitDeploySelf = 20000000; +int gasLimitUpgradeChild = 20000000; +int gasLimitClaimDeveloperRewards = 6000000; + +byte functionNameClaimDeveloperRewards[] = "ClaimDeveloperRewards"; +byte functionNameDoSomething[] = "doSomething"; +byte storageKeyChildAddress[] = "child"; +byte something[] = "something"; + +void init() +{ +} + +void upgrade() +{ +} + +void doSomething() +{ + finish(something, sizeof(something) - 1); +} + +void deployChild() +{ + byte *selfAddress = zero32_red; + byte *newAddress = zero32_blue; + + getSCAddress(selfAddress); + + deployFromSourceContract( + gasLimitDeploySelf, + zeroEGLD, + selfAddress, + codeMetadataUpgradeableReadable, + newAddress, + 0, + (byte *)emptyArgumentsLengths, + emptyArguments); + + storageStore(storageKeyChildAddress, sizeof(storageKeyChildAddress) - 1, newAddress, ADDRESS_LENGTH); +} + +void getChildAddress() +{ + byte *childAddress = zero32_red; + storageLoad(storageKeyChildAddress, sizeof(storageKeyChildAddress) - 1, childAddress); + finish(childAddress, ADDRESS_LENGTH); +} + +void callChild() +{ + byte *childAddress = zero32_red; + storageLoad(storageKeyChildAddress, sizeof(storageKeyChildAddress) - 1, childAddress); + + createAsyncCall( + childAddress, + zeroEGLD, + functionNameDoSomething, + sizeof(functionNameDoSomething) - 1, + 0, + 0, + 0, + 0, + 15000000, + 0); +} + +void claimDeveloperRewardsOnChild() +{ + byte *childAddress = zero32_red; + storageLoad(storageKeyChildAddress, sizeof(storageKeyChildAddress) - 1, childAddress); + + createAsyncCall( + childAddress, + zeroEGLD, + functionNameClaimDeveloperRewards, + sizeof(functionNameClaimDeveloperRewards) - 1, + 0, + 0, + 0, + 0, + gasLimitClaimDeveloperRewards, + 0); +} diff --git a/integrationTests/vm/wasm/testdata/developer-rewards/developer_rewards.export b/integrationTests/vm/wasm/testdata/developer-rewards/developer_rewards.export new file mode 100644 index 00000000000..79d27c49542 --- /dev/null +++ b/integrationTests/vm/wasm/testdata/developer-rewards/developer_rewards.export @@ -0,0 +1,7 @@ +init +upgrade +doSomething +deployChild +getChildAddress +callChild +claimDeveloperRewardsOnChild diff --git a/integrationTests/vm/wasm/testdata/developer-rewards/output/developer_rewards.wasm b/integrationTests/vm/wasm/testdata/developer-rewards/output/developer_rewards.wasm new file mode 100755 index 0000000000000000000000000000000000000000..7aa8bd7d7a66c26b1aba23f9568f6600e429aed8 GIT binary patch literal 1171 zcmcIkJ#Q015S`uozCFih=R*i6W(7qW3YzpABP1jwBwW(u$9doyKl!AtWJ*{SUW_IVjr`dy~m@)uhJKi3zD%fK*{dr{u ztM=@AMbThm z_Oru$pnKV@%#%S0yg5;nS)L4apNs~pc8R6yX_lm5*Piwu*GZ{WaWWh9lF0-d%lBL} z9E$;WeO58`<=hrt>AO=s&GHitHX$p)^$rh)d6H`IM4I)psV?_NvmyAxAnWaqCMg7M zg5E4w=)+(@rA$=Z9ZZtZ^pQT&lk7m}&-HPVr^U0G2}j{?$Fra<>UoFpN_{(9EI@(^ zBtt+JFKAHgC$oZz&0E#I#z6_ONq8kW^81Zb{b Date: Mon, 15 Apr 2024 14:59:19 +0300 Subject: [PATCH 174/503] Improve tests. --- .../developerRewards/developerRewards_test.go | 27 +++++++++++------- .../developer-rewards/developer_rewards.c | 27 +----------------- .../developer_rewards.export | 1 - .../output/developer_rewards.wasm | Bin 1171 -> 973 bytes 4 files changed, 18 insertions(+), 37 deletions(-) diff --git a/integrationTests/vm/wasm/developerRewards/developerRewards_test.go b/integrationTests/vm/wasm/developerRewards/developerRewards_test.go index 356ffc29db5..a23493abc9f 100644 --- a/integrationTests/vm/wasm/developerRewards/developerRewards_test.go +++ b/integrationTests/vm/wasm/developerRewards/developerRewards_test.go @@ -1,7 +1,6 @@ package transfers import ( - "math/big" "testing" "github.com/multiversx/mx-chain-go/integrationTests/vm/wasm" @@ -13,20 +12,22 @@ func TestClaimDeveloperRewards(t *testing.T) { t.Skip("this is not a short test") } - context := wasm.SetupTestContext(t) - defer context.Close() - - err := context.DeploySC("../testdata/developer-rewards/output/developer_rewards.wasm", "") - require.Nil(t, err) + wasmPath := "../testdata/developer-rewards/output/developer_rewards.wasm" t.Run("rewards for user", func(t *testing.T) { + context := wasm.SetupTestContext(t) + defer context.Close() + + err := context.DeploySC(wasmPath, "") + require.Nil(t, err) contractAddress := context.ScAddress err = context.ExecuteSC(&context.Owner, "doSomething") require.Nil(t, err) ownerBalanceBefore := context.GetAccountBalance(&context.Owner).Uint64() - reward := context.GetAccount(contractAddress).GetDeveloperReward().Uint64() + rewardBig := context.GetAccount(contractAddress).GetDeveloperReward() + reward := rewardBig.Uint64() err = context.ExecuteSC(&context.Owner, "ClaimDeveloperRewards") require.Nil(t, err) @@ -36,11 +37,16 @@ func TestClaimDeveloperRewards(t *testing.T) { events := context.LastLogs[0].GetLogEvents() require.Equal(t, "ClaimDeveloperRewards", string(events[0].GetIdentifier())) - require.Equal(t, big.NewInt(0).SetUint64(reward).Bytes(), events[0].GetTopics()[0]) + require.Equal(t, rewardBig.Bytes(), events[0].GetTopics()[0]) require.Equal(t, context.Owner.Address, events[0].GetTopics()[1]) }) t.Run("rewards for contract", func(t *testing.T) { + context := wasm.SetupTestContext(t) + defer context.Close() + + err := context.DeploySC(wasmPath, "") + require.Nil(t, err) parentContractAddress := context.ScAddress err = context.ExecuteSC(&context.Owner, "deployChild") @@ -54,7 +60,8 @@ func TestClaimDeveloperRewards(t *testing.T) { require.Nil(t, err) contractBalanceBefore := context.GetAccount(parentContractAddress).GetBalance().Uint64() - reward := context.GetAccount(chilContractdAddress).GetDeveloperReward().Uint64() + rewardBig := context.GetAccount(chilContractdAddress).GetDeveloperReward() + reward := rewardBig.Uint64() context.ScAddress = parentContractAddress err = context.ExecuteSC(&context.Owner, "claimDeveloperRewardsOnChild") @@ -65,7 +72,7 @@ func TestClaimDeveloperRewards(t *testing.T) { events := context.LastLogs[0].GetLogEvents() require.Equal(t, "ClaimDeveloperRewards", string(events[0].GetIdentifier())) - require.Equal(t, big.NewInt(0).SetUint64(reward).Bytes(), events[0].GetTopics()[0]) + require.Equal(t, rewardBig.Bytes(), events[0].GetTopics()[0]) require.Equal(t, parentContractAddress, events[0].GetTopics()[1]) }) } diff --git a/integrationTests/vm/wasm/testdata/developer-rewards/developer_rewards.c b/integrationTests/vm/wasm/testdata/developer-rewards/developer_rewards.c index 194c5d68c1d..a5d3d70d891 100644 --- a/integrationTests/vm/wasm/testdata/developer-rewards/developer_rewards.c +++ b/integrationTests/vm/wasm/testdata/developer-rewards/developer_rewards.c @@ -33,12 +33,6 @@ static const i32 ADDRESS_LENGTH = 32; byte zero32_red[32] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; byte zero32_green[32] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; -byte zero32_blue[32] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - -// E.g. can hold up to 64 addresses. -byte zero2048_red[2048] = {0}; -byte zero2048_green[2048] = {0}; -byte zero2048_blue[2048] = {0}; byte zeroEGLD[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; @@ -48,7 +42,6 @@ byte codeMetadataUpgradeableReadable[2] = {5, 0}; byte emptyArguments[0] = {}; int emptyArgumentsLengths[0] = {}; int gasLimitDeploySelf = 20000000; -int gasLimitUpgradeChild = 20000000; int gasLimitClaimDeveloperRewards = 6000000; byte functionNameClaimDeveloperRewards[] = "ClaimDeveloperRewards"; @@ -72,7 +65,7 @@ void doSomething() void deployChild() { byte *selfAddress = zero32_red; - byte *newAddress = zero32_blue; + byte *newAddress = zero32_green; getSCAddress(selfAddress); @@ -96,24 +89,6 @@ void getChildAddress() finish(childAddress, ADDRESS_LENGTH); } -void callChild() -{ - byte *childAddress = zero32_red; - storageLoad(storageKeyChildAddress, sizeof(storageKeyChildAddress) - 1, childAddress); - - createAsyncCall( - childAddress, - zeroEGLD, - functionNameDoSomething, - sizeof(functionNameDoSomething) - 1, - 0, - 0, - 0, - 0, - 15000000, - 0); -} - void claimDeveloperRewardsOnChild() { byte *childAddress = zero32_red; diff --git a/integrationTests/vm/wasm/testdata/developer-rewards/developer_rewards.export b/integrationTests/vm/wasm/testdata/developer-rewards/developer_rewards.export index 79d27c49542..b71813a510f 100644 --- a/integrationTests/vm/wasm/testdata/developer-rewards/developer_rewards.export +++ b/integrationTests/vm/wasm/testdata/developer-rewards/developer_rewards.export @@ -3,5 +3,4 @@ upgrade doSomething deployChild getChildAddress -callChild claimDeveloperRewardsOnChild diff --git a/integrationTests/vm/wasm/testdata/developer-rewards/output/developer_rewards.wasm b/integrationTests/vm/wasm/testdata/developer-rewards/output/developer_rewards.wasm index 7aa8bd7d7a66c26b1aba23f9568f6600e429aed8..7d8df93e210f88c939641fcb41aaf4a0c0666071 100755 GIT binary patch delta 193 zcmbQtd6s>`J}GuK2w-JqWME?BV610!T+qqF&7Q$N@utUQT}C-!Zmu&dY|IS&+#oE? z$W-sRW^x>(wZMUnh6V;jW(6h%W-}%p#|M*FGCIpPbbxryp9Ztd_eO+V*HK^ zCUY{WGA^5}&lJRXVDbiLQ6PH;ljGzzW=$l%{N$(15{wO#|1o=W*fKIWHgIs8O%7yH W6G+a;%t>J=&d*IP$;ix0X8-^!1u~`p delta 367 zcmX@hKACgEK4}hiHV9y4W@KPu<6x|3bllL%!p&a7G4X~64`*^>PL6X%W=;wN_hbb| zIbj~IpRDZ64E)?6EX~MN@3>=fAfvUwg^q>>21RBCCIx0QCLYHRljkrx%TDM73Gz5L zfF*ey85H?|hJ(cT9XCw=!>G!*X|fVikT|Ml1ttw99z_<%O_O<;pj}wC;uL8RQhXSVpmjX8w@+j~M zv^D_UB;_ce$Om*kUzQ@j0{`SAOon)@GH0AH*@fAg!;_K0v4MlzY4UVtHJOzB;QZXw Ql8nr}bcSSbm=(kM03gU!D*ylh From d920fb87dedc083202de964c04de2b8cdce6db78 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 15 Apr 2024 15:46:43 +0300 Subject: [PATCH 175/503] added draft implementation of relayed tx v3 with multiple inner transactions + fixes on handling fee --- api/groups/transactionGroup.go | 240 +++++++----- api/groups/transactionGroup_test.go | 4 +- .../epochStartInterceptorsContainerFactory.go | 2 + errors/errors.go | 3 + factory/interface.go | 1 + factory/mock/processComponentsStub.go | 6 + factory/processing/blockProcessorCreator.go | 42 +- .../processing/blockProcessorCreator_test.go | 2 + factory/processing/export_test.go | 6 +- factory/processing/processComponents.go | 24 +- .../processing/processComponentsHandler.go | 15 + .../txSimulatorProcessComponents.go | 47 +-- .../txSimulatorProcessComponents_test.go | 7 +- genesis/process/argGenesisBlockCreator.go | 1 + genesis/process/genesisBlockCreator_test.go | 2 + genesis/process/shardGenesisBlockCreator.go | 39 +- go.mod | 2 +- go.sum | 4 +- .../mock/processComponentsStub.go | 6 + .../multiShard/hardFork/hardFork_test.go | 2 + .../multiShard/relayedTx/common.go | 18 +- .../multiShard/relayedTx/relayedTx_test.go | 128 ++++++ integrationTests/testHeartbeatNode.go | 2 + integrationTests/testInitializer.go | 22 +- integrationTests/testProcessorNode.go | 83 ++-- integrationTests/vm/testInitializer.go | 79 ++-- integrationTests/vm/wasm/utils.go | 40 +- .../vm/wasm/wasmvm/wasmVM_test.go | 36 +- .../components/processComponents.go | 7 + node/external/dtos.go | 34 +- node/node.go | 29 +- node/node_test.go | 58 +-- process/coordinator/transactionType.go | 2 +- process/coordinator/transactionType_test.go | 2 +- process/disabled/relayedTxV3Processor.go | 35 ++ process/errors.go | 19 +- process/factory/interceptorscontainer/args.go | 1 + .../metaInterceptorsContainerFactory.go | 1 + .../metaInterceptorsContainerFactory_test.go | 2 + .../shardInterceptorsContainerFactory.go | 1 + .../shardInterceptorsContainerFactory_test.go | 2 + .../factory/argInterceptedDataFactory.go | 1 + .../interceptedMetaHeaderDataFactory_test.go | 2 + .../factory/interceptedTxDataFactory.go | 3 + process/interface.go | 8 + process/transaction/baseProcess.go | 6 +- process/transaction/export_test.go | 3 +- process/transaction/interceptedTransaction.go | 51 +-- .../interceptedTransaction_test.go | 96 ++++- process/transaction/relayedTxV3Processor.go | 134 +++++++ process/transaction/shardProcess.go | 370 ++++++++++++++---- process/transaction/shardProcess_test.go | 105 ++--- testscommon/components/default.go | 4 +- .../processMocks/relayedTxV3ProcessorMock.go | 43 ++ update/factory/exportHandlerFactory.go | 2 + update/factory/fullSyncInterceptors.go | 2 + 56 files changed, 1340 insertions(+), 546 deletions(-) create mode 100644 process/disabled/relayedTxV3Processor.go create mode 100644 process/transaction/relayedTxV3Processor.go create mode 100644 testscommon/processMocks/relayedTxV3ProcessorMock.go diff --git a/api/groups/transactionGroup.go b/api/groups/transactionGroup.go index 873ff25bde4..f1bb3d9033b 100644 --- a/api/groups/transactionGroup.go +++ b/api/groups/transactionGroup.go @@ -182,35 +182,42 @@ func (tg *transactionGroup) simulateTransaction(c *gin.Context) { return } - var innerTx *transaction.Transaction - if ftx.InnerTransaction != nil { - if ftx.InnerTransaction.InnerTransaction != nil { - c.JSON( - http.StatusBadRequest, - shared.GenericAPIResponse{ - Data: nil, - Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), errors.ErrRecursiveRelayedTxIsNotAllowed.Error()), - Code: shared.ReturnCodeRequestError, - }, - ) - return - } + innerTxs := make([]*transaction.Transaction, 0, len(ftx.InnerTransactions)) + if len(ftx.InnerTransactions) != 0 { + for _, innerTx := range ftx.InnerTransactions { + if len(innerTx.InnerTransactions) != 0 { + c.JSON( + http.StatusBadRequest, + shared.GenericAPIResponse{ + Data: nil, + Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), errors.ErrRecursiveRelayedTxIsNotAllowed.Error()), + Code: shared.ReturnCodeRequestError, + }, + ) + return + } - innerTx, _, err = tg.createTransaction(ftx.InnerTransaction, nil) - if err != nil { - c.JSON( - http.StatusBadRequest, - shared.GenericAPIResponse{ - Data: nil, - Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), err.Error()), - Code: shared.ReturnCodeRequestError, - }, - ) - return + newInnerTx, _, err := tg.createTransaction(innerTx, nil) + if err != nil { + c.JSON( + http.StatusBadRequest, + shared.GenericAPIResponse{ + Data: nil, + Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), err.Error()), + Code: shared.ReturnCodeRequestError, + }, + ) + return + } + + innerTxs = append(innerTxs, newInnerTx) } } - tx, txHash, err := tg.createTransaction(&ftx, innerTx) + if len(innerTxs) == 0 { + innerTxs = nil + } + tx, txHash, err := tg.createTransaction(&ftx, innerTxs) if err != nil { c.JSON( http.StatusBadRequest, @@ -280,35 +287,42 @@ func (tg *transactionGroup) sendTransaction(c *gin.Context) { return } - var innerTx *transaction.Transaction - if ftx.InnerTransaction != nil { - if ftx.InnerTransaction.InnerTransaction != nil { - c.JSON( - http.StatusBadRequest, - shared.GenericAPIResponse{ - Data: nil, - Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), errors.ErrRecursiveRelayedTxIsNotAllowed.Error()), - Code: shared.ReturnCodeRequestError, - }, - ) - return - } + innerTxs := make([]*transaction.Transaction, 0, len(ftx.InnerTransactions)) + if len(ftx.InnerTransactions) != 0 { + for _, innerTx := range ftx.InnerTransactions { + if len(innerTx.InnerTransactions) != 0 { + c.JSON( + http.StatusBadRequest, + shared.GenericAPIResponse{ + Data: nil, + Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), errors.ErrRecursiveRelayedTxIsNotAllowed.Error()), + Code: shared.ReturnCodeRequestError, + }, + ) + return + } - innerTx, _, err = tg.createTransaction(ftx.InnerTransaction, nil) - if err != nil { - c.JSON( - http.StatusBadRequest, - shared.GenericAPIResponse{ - Data: nil, - Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), err.Error()), - Code: shared.ReturnCodeRequestError, - }, - ) - return + newInnerTx, _, err := tg.createTransaction(innerTx, nil) + if err != nil { + c.JSON( + http.StatusBadRequest, + shared.GenericAPIResponse{ + Data: nil, + Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), err.Error()), + Code: shared.ReturnCodeRequestError, + }, + ) + return + } + + innerTxs = append(innerTxs, newInnerTx) } } - tx, txHash, err := tg.createTransaction(&ftx, innerTx) + if len(innerTxs) == 0 { + innerTxs = nil + } + tx, txHash, err := tg.createTransaction(&ftx, innerTxs) if err != nil { c.JSON( http.StatusBadRequest, @@ -387,23 +401,28 @@ func (tg *transactionGroup) sendMultipleTransactions(c *gin.Context) { var start time.Time txsHashes := make(map[int]string) for idx, receivedTx := range ftxs { - var innerTx *transaction.Transaction - if receivedTx.InnerTransaction != nil { - innerTx, _, err = tg.createTransaction(receivedTx.InnerTransaction, nil) - if err != nil { - c.JSON( - http.StatusBadRequest, - shared.GenericAPIResponse{ - Data: nil, - Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), err.Error()), - Code: shared.ReturnCodeRequestError, - }, - ) - return + innerTxs := make([]*transaction.Transaction, 0, len(receivedTx.InnerTransactions)) + if len(receivedTx.InnerTransactions) != 0 { + for _, innerTx := range receivedTx.InnerTransactions { + if len(innerTx.InnerTransactions) != 0 { + // if one of the inner txs is invalid, break the loop and move to the next transaction received + break + } + + newInnerTx, _, err := tg.createTransaction(innerTx, nil) + if err != nil { + // if one of the inner txs is invalid, break the loop and move to the next transaction received + break + } + + innerTxs = append(innerTxs, newInnerTx) } } - tx, txHash, err = tg.createTransaction(&receivedTx, innerTx) + if len(innerTxs) == 0 { + innerTxs = nil + } + tx, txHash, err = tg.createTransaction(&receivedTx, innerTxs) if err != nil { continue } @@ -514,35 +533,42 @@ func (tg *transactionGroup) computeTransactionGasLimit(c *gin.Context) { return } - var innerTx *transaction.Transaction - if ftx.InnerTransaction != nil { - if ftx.InnerTransaction.InnerTransaction != nil { - c.JSON( - http.StatusBadRequest, - shared.GenericAPIResponse{ - Data: nil, - Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), errors.ErrRecursiveRelayedTxIsNotAllowed.Error()), - Code: shared.ReturnCodeRequestError, - }, - ) - return - } + innerTxs := make([]*transaction.Transaction, 0, len(ftx.InnerTransactions)) + if len(ftx.InnerTransactions) != 0 { + for _, innerTx := range ftx.InnerTransactions { + if len(innerTx.InnerTransactions) != 0 { + c.JSON( + http.StatusBadRequest, + shared.GenericAPIResponse{ + Data: nil, + Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), errors.ErrRecursiveRelayedTxIsNotAllowed.Error()), + Code: shared.ReturnCodeRequestError, + }, + ) + return + } - innerTx, _, err = tg.createTransaction(ftx.InnerTransaction, nil) - if err != nil { - c.JSON( - http.StatusInternalServerError, - shared.GenericAPIResponse{ - Data: nil, - Error: err.Error(), - Code: shared.ReturnCodeInternalError, - }, - ) - return + newInnerTx, _, err := tg.createTransaction(innerTx, nil) + if err != nil { + c.JSON( + http.StatusBadRequest, + shared.GenericAPIResponse{ + Data: nil, + Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), err.Error()), + Code: shared.ReturnCodeRequestError, + }, + ) + return + } + + innerTxs = append(innerTxs, newInnerTx) } } - tx, _, err := tg.createTransaction(&ftx, innerTx) + if len(innerTxs) == 0 { + innerTxs = nil + } + tx, _, err := tg.createTransaction(&ftx, innerTxs) if err != nil { c.JSON( http.StatusInternalServerError, @@ -752,25 +778,25 @@ func (tg *transactionGroup) getTransactionsPoolNonceGapsForSender(sender string, ) } -func (tg *transactionGroup) createTransaction(receivedTx *transaction.FrontendTransaction, innerTx *transaction.Transaction) (*transaction.Transaction, []byte, error) { +func (tg *transactionGroup) createTransaction(receivedTx *transaction.FrontendTransaction, innerTxs []*transaction.Transaction) (*transaction.Transaction, []byte, error) { txArgs := &external.ArgsCreateTransaction{ - Nonce: receivedTx.Nonce, - Value: receivedTx.Value, - Receiver: receivedTx.Receiver, - ReceiverUsername: receivedTx.ReceiverUsername, - Sender: receivedTx.Sender, - SenderUsername: receivedTx.SenderUsername, - GasPrice: receivedTx.GasPrice, - GasLimit: receivedTx.GasLimit, - DataField: receivedTx.Data, - SignatureHex: receivedTx.Signature, - ChainID: receivedTx.ChainID, - Version: receivedTx.Version, - Options: receivedTx.Options, - Guardian: receivedTx.GuardianAddr, - GuardianSigHex: receivedTx.GuardianSignature, - Relayer: receivedTx.Relayer, - InnerTransaction: innerTx, + Nonce: receivedTx.Nonce, + Value: receivedTx.Value, + Receiver: receivedTx.Receiver, + ReceiverUsername: receivedTx.ReceiverUsername, + Sender: receivedTx.Sender, + SenderUsername: receivedTx.SenderUsername, + GasPrice: receivedTx.GasPrice, + GasLimit: receivedTx.GasLimit, + DataField: receivedTx.Data, + SignatureHex: receivedTx.Signature, + ChainID: receivedTx.ChainID, + Version: receivedTx.Version, + Options: receivedTx.Options, + Guardian: receivedTx.GuardianAddr, + GuardianSigHex: receivedTx.GuardianSignature, + Relayer: receivedTx.Relayer, + InnerTransactions: innerTxs, } start := time.Now() tx, txHash, err := tg.getFacade().CreateTransaction(txArgs) diff --git a/api/groups/transactionGroup_test.go b/api/groups/transactionGroup_test.go index 9d49a2966d0..f183dd30b4c 100644 --- a/api/groups/transactionGroup_test.go +++ b/api/groups/transactionGroup_test.go @@ -1155,7 +1155,7 @@ func testRecursiveRelayedV3(url string) func(t *testing.T) { value, signature, ) - userTx2 := fmt.Sprintf(`{"nonce": %d, "sender":"%s", "receiver":"%s", "value":"%s", "signature":"%s", "innerTransaction":%s}`, + userTx2 := fmt.Sprintf(`{"nonce": %d, "sender":"%s", "receiver":"%s", "value":"%s", "signature":"%s", "innerTransactions":[%s]}`, nonce, sender, receiver, @@ -1163,7 +1163,7 @@ func testRecursiveRelayedV3(url string) func(t *testing.T) { signature, userTx1, ) - tx := fmt.Sprintf(`{"nonce": %d, "sender":"%s", "receiver":"%s", "value":"%s", "signature":"%s", "innerTransaction":%s}`, + tx := fmt.Sprintf(`{"nonce": %d, "sender":"%s", "receiver":"%s", "value":"%s", "signature":"%s", "innerTransactions":[%s]}`, nonce, sender, receiver, diff --git a/epochStart/bootstrap/factory/epochStartInterceptorsContainerFactory.go b/epochStart/bootstrap/factory/epochStartInterceptorsContainerFactory.go index d659989896b..0ebf8417d7b 100644 --- a/epochStart/bootstrap/factory/epochStartInterceptorsContainerFactory.go +++ b/epochStart/bootstrap/factory/epochStartInterceptorsContainerFactory.go @@ -14,6 +14,7 @@ import ( disabledFactory "github.com/multiversx/mx-chain-go/factory/disabled" disabledGenesis "github.com/multiversx/mx-chain-go/genesis/process/disabled" "github.com/multiversx/mx-chain-go/process" + processDisabled "github.com/multiversx/mx-chain-go/process/disabled" "github.com/multiversx/mx-chain-go/process/factory/interceptorscontainer" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/storage/cache" @@ -108,6 +109,7 @@ func NewEpochStartInterceptorsContainer(args ArgsEpochStartInterceptorContainer) FullArchivePeerShardMapper: fullArchivePeerShardMapper, HardforkTrigger: hardforkTrigger, NodeOperationMode: args.NodeOperationMode, + RelayedTxV3Processor: processDisabled.NewRelayedTxV3Processor(), } interceptorsContainerFactory, err := interceptorscontainer.NewMetaInterceptorsContainerFactory(containerFactoryArgs) diff --git a/errors/errors.go b/errors/errors.go index 771c65adc07..39aabb248c5 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -595,3 +595,6 @@ var ErrInvalidNodeOperationMode = errors.New("invalid node operation mode") // ErrNilSentSignatureTracker defines the error for setting a nil SentSignatureTracker var ErrNilSentSignatureTracker = errors.New("nil sent signature tracker") + +// ErrNilRelayedTxV3Processor signals that a nil relayed tx v3 processor has been provided +var ErrNilRelayedTxV3Processor = errors.New("nil relayed tx v3 processor") diff --git a/factory/interface.go b/factory/interface.go index ede9f39089b..5fdcce82703 100644 --- a/factory/interface.go +++ b/factory/interface.go @@ -310,6 +310,7 @@ type ProcessComponentsHolder interface { AccountsParser() genesis.AccountsParser ReceiptsRepository() ReceiptsRepository SentSignaturesTracker() process.SentSignaturesTracker + RelayedTxV3Processor() process.RelayedTxV3Processor IsInterfaceNil() bool } diff --git a/factory/mock/processComponentsStub.go b/factory/mock/processComponentsStub.go index e646958281c..4d3f51ed563 100644 --- a/factory/mock/processComponentsStub.go +++ b/factory/mock/processComponentsStub.go @@ -57,6 +57,7 @@ type ProcessComponentsMock struct { AccountsParserInternal genesis.AccountsParser ReceiptsRepositoryInternal factory.ReceiptsRepository SentSignaturesTrackerInternal process.SentSignaturesTracker + RelayedTxV3ProcessorField process.RelayedTxV3Processor } // Create - @@ -284,6 +285,11 @@ func (pcm *ProcessComponentsMock) SentSignaturesTracker() process.SentSignatures return pcm.SentSignaturesTrackerInternal } +// RelayedTxV3Processor - +func (pcm *ProcessComponentsMock) RelayedTxV3Processor() process.RelayedTxV3Processor { + return pcm.RelayedTxV3ProcessorField +} + // IsInterfaceNil - func (pcm *ProcessComponentsMock) IsInterfaceNil() bool { return pcm == nil diff --git a/factory/processing/blockProcessorCreator.go b/factory/processing/blockProcessorCreator.go index 7db9e20cf7d..145df63e54c 100644 --- a/factory/processing/blockProcessorCreator.go +++ b/factory/processing/blockProcessorCreator.go @@ -68,6 +68,7 @@ func (pcf *processComponentsFactory) newBlockProcessor( blockCutoffProcessingHandler cutoff.BlockProcessingCutoffHandler, missingTrieNodesNotifier common.MissingTrieNodesNotifier, sentSignaturesTracker process.SentSignaturesTracker, + relayedTxV3Processor process.RelayedTxV3Processor, ) (*blockProcessorAndVmFactories, error) { shardCoordinator := pcf.bootstrapComponents.ShardCoordinator() if shardCoordinator.SelfId() < shardCoordinator.NumberOfShards() { @@ -86,6 +87,7 @@ func (pcf *processComponentsFactory) newBlockProcessor( blockCutoffProcessingHandler, missingTrieNodesNotifier, sentSignaturesTracker, + relayedTxV3Processor, ) } if shardCoordinator.SelfId() == core.MetachainShardId { @@ -127,6 +129,7 @@ func (pcf *processComponentsFactory) newShardBlockProcessor( blockProcessingCutoffHandler cutoff.BlockProcessingCutoffHandler, missingTrieNodesNotifier common.MissingTrieNodesNotifier, sentSignaturesTracker process.SentSignaturesTracker, + relayedTxV3Processor process.RelayedTxV3Processor, ) (*blockProcessorAndVmFactories, error) { argsParser := smartContract.NewArgumentParser() @@ -273,25 +276,26 @@ func (pcf *processComponentsFactory) newShardBlockProcessor( } argsNewTxProcessor := transaction.ArgsNewTxProcessor{ - Accounts: pcf.state.AccountsAdapter(), - Hasher: pcf.coreData.Hasher(), - PubkeyConv: pcf.coreData.AddressPubKeyConverter(), - Marshalizer: pcf.coreData.InternalMarshalizer(), - SignMarshalizer: pcf.coreData.TxMarshalizer(), - ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), - ScProcessor: scProcessorProxy, - TxFeeHandler: txFeeHandler, - TxTypeHandler: txTypeHandler, - EconomicsFee: pcf.coreData.EconomicsData(), - ReceiptForwarder: receiptTxInterim, - BadTxForwarder: badTxInterim, - ArgsParser: argsParser, - ScrForwarder: scForwarder, - EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), - EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), - GuardianChecker: pcf.bootstrapComponents.GuardedAccountHandler(), - TxVersionChecker: pcf.coreData.TxVersionChecker(), - TxLogsProcessor: pcf.txLogsProcessor, + Accounts: pcf.state.AccountsAdapter(), + Hasher: pcf.coreData.Hasher(), + PubkeyConv: pcf.coreData.AddressPubKeyConverter(), + Marshalizer: pcf.coreData.InternalMarshalizer(), + SignMarshalizer: pcf.coreData.TxMarshalizer(), + ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), + ScProcessor: scProcessorProxy, + TxFeeHandler: txFeeHandler, + TxTypeHandler: txTypeHandler, + EconomicsFee: pcf.coreData.EconomicsData(), + ReceiptForwarder: receiptTxInterim, + BadTxForwarder: badTxInterim, + ArgsParser: argsParser, + ScrForwarder: scForwarder, + EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), + EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), + GuardianChecker: pcf.bootstrapComponents.GuardedAccountHandler(), + TxVersionChecker: pcf.coreData.TxVersionChecker(), + TxLogsProcessor: pcf.txLogsProcessor, + RelayedTxV3Processor: relayedTxV3Processor, } transactionProcessor, err := transaction.NewTxProcessor(argsNewTxProcessor) if err != nil { diff --git a/factory/processing/blockProcessorCreator_test.go b/factory/processing/blockProcessorCreator_test.go index 3ecc3432f9e..2d7d1c56dfd 100644 --- a/factory/processing/blockProcessorCreator_test.go +++ b/factory/processing/blockProcessorCreator_test.go @@ -56,6 +56,7 @@ func Test_newBlockProcessorCreatorForShard(t *testing.T) { &testscommon.BlockProcessingCutoffStub{}, &testscommon.MissingTrieNodesNotifierStub{}, &testscommon.SentSignatureTrackerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) require.NoError(t, err) @@ -182,6 +183,7 @@ func Test_newBlockProcessorCreatorForMeta(t *testing.T) { &testscommon.BlockProcessingCutoffStub{}, &testscommon.MissingTrieNodesNotifierStub{}, &testscommon.SentSignatureTrackerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) require.NoError(t, err) diff --git a/factory/processing/export_test.go b/factory/processing/export_test.go index 50c5123634c..a4fa2e74137 100644 --- a/factory/processing/export_test.go +++ b/factory/processing/export_test.go @@ -25,6 +25,7 @@ func (pcf *processComponentsFactory) NewBlockProcessor( blockProcessingCutoff cutoff.BlockProcessingCutoffHandler, missingTrieNodesNotifier common.MissingTrieNodesNotifier, sentSignaturesTracker process.SentSignaturesTracker, + relayedV3TxProcessor process.RelayedTxV3Processor, ) (process.BlockProcessor, error) { blockProcessorComponents, err := pcf.newBlockProcessor( requestHandler, @@ -42,6 +43,7 @@ func (pcf *processComponentsFactory) NewBlockProcessor( blockProcessingCutoff, missingTrieNodesNotifier, sentSignaturesTracker, + relayedV3TxProcessor, ) if err != nil { return nil, err @@ -51,6 +53,6 @@ func (pcf *processComponentsFactory) NewBlockProcessor( } // CreateAPITransactionEvaluator - -func (pcf *processComponentsFactory) CreateAPITransactionEvaluator() (factory.TransactionEvaluator, process.VirtualMachinesContainerFactory, error) { - return pcf.createAPITransactionEvaluator() +func (pcf *processComponentsFactory) CreateAPITransactionEvaluator(relayedV3TxProcessor process.RelayedTxV3Processor) (factory.TransactionEvaluator, process.VirtualMachinesContainerFactory, error) { + return pcf.createAPITransactionEvaluator(relayedV3TxProcessor) } diff --git a/factory/processing/processComponents.go b/factory/processing/processComponents.go index 72d75c69dc3..6cd922e9429 100644 --- a/factory/processing/processComponents.go +++ b/factory/processing/processComponents.go @@ -59,6 +59,7 @@ import ( "github.com/multiversx/mx-chain-go/process/smartContract" "github.com/multiversx/mx-chain-go/process/sync" "github.com/multiversx/mx-chain-go/process/track" + "github.com/multiversx/mx-chain-go/process/transaction" "github.com/multiversx/mx-chain-go/process/transactionLog" "github.com/multiversx/mx-chain-go/process/txsSender" "github.com/multiversx/mx-chain-go/redundancy" @@ -131,6 +132,7 @@ type processComponents struct { accountsParser genesis.AccountsParser receiptsRepository mainFactory.ReceiptsRepository sentSignaturesTracker process.SentSignaturesTracker + relayedTxV3Processor process.RelayedTxV3Processor } // ProcessComponentsFactoryArgs holds the arguments needed to create a process components factory @@ -376,8 +378,13 @@ func (pcf *processComponentsFactory) Create() (*processComponents, error) { return nil, err } + relayedTxV3Processor, err := transaction.NewRelayedTxV3Processor(pcf.coreData.EconomicsData(), pcf.bootstrapComponents.ShardCoordinator()) + if err != nil { + return nil, err + } + pcf.txLogsProcessor = txLogsProcessor - genesisBlocks, initialTxs, err := pcf.generateGenesisHeadersAndApplyInitialBalances() + genesisBlocks, initialTxs, err := pcf.generateGenesisHeadersAndApplyInitialBalances(relayedTxV3Processor) if err != nil { return nil, err } @@ -522,6 +529,7 @@ func (pcf *processComponentsFactory) Create() (*processComponents, error) { mainPeerShardMapper, fullArchivePeerShardMapper, hardforkTrigger, + relayedTxV3Processor, ) if err != nil { return nil, err @@ -618,6 +626,7 @@ func (pcf *processComponentsFactory) Create() (*processComponents, error) { blockCutoffProcessingHandler, pcf.state.MissingTrieNodesNotifier(), sentSignaturesTracker, + relayedTxV3Processor, ) if err != nil { return nil, err @@ -707,7 +716,7 @@ func (pcf *processComponentsFactory) Create() (*processComponents, error) { return nil, err } - apiTransactionEvaluator, vmFactoryForTxSimulate, err := pcf.createAPITransactionEvaluator() + apiTransactionEvaluator, vmFactoryForTxSimulate, err := pcf.createAPITransactionEvaluator(relayedTxV3Processor) if err != nil { return nil, fmt.Errorf("%w when assembling components for the transactions simulator processor", err) } @@ -759,6 +768,7 @@ func (pcf *processComponentsFactory) Create() (*processComponents, error) { accountsParser: pcf.accountsParser, receiptsRepository: receiptsRepository, sentSignaturesTracker: sentSignaturesTracker, + relayedTxV3Processor: relayedTxV3Processor, }, nil } @@ -871,7 +881,7 @@ func (pcf *processComponentsFactory) newEpochStartTrigger(requestHandler epochSt return nil, errors.New("error creating new start of epoch trigger because of invalid shard id") } -func (pcf *processComponentsFactory) generateGenesisHeadersAndApplyInitialBalances() (map[uint32]data.HeaderHandler, map[uint32]*genesis.IndexingData, error) { +func (pcf *processComponentsFactory) generateGenesisHeadersAndApplyInitialBalances(relayedTxV3Processor process.RelayedTxV3Processor) (map[uint32]data.HeaderHandler, map[uint32]*genesis.IndexingData, error) { genesisVmConfig := pcf.config.VirtualMachine.Execution conversionBase := 10 genesisNodePrice, ok := big.NewInt(0).SetString(pcf.systemSCConfig.StakingSystemSCConfig.GenesisNodePrice, conversionBase) @@ -908,6 +918,7 @@ func (pcf *processComponentsFactory) generateGenesisHeadersAndApplyInitialBalanc GenesisEpoch: pcf.config.EpochStartConfig.GenesisEpoch, GenesisNonce: pcf.genesisNonce, GenesisRound: pcf.genesisRound, + RelayedTxV3Processor: relayedTxV3Processor, } gbc, err := processGenesis.NewGenesisBlockCreator(arg) @@ -1490,6 +1501,7 @@ func (pcf *processComponentsFactory) newInterceptorContainerFactory( mainPeerShardMapper *networksharding.PeerShardMapper, fullArchivePeerShardMapper *networksharding.PeerShardMapper, hardforkTrigger factory.HardforkTrigger, + relayedTxV3Processor process.RelayedTxV3Processor, ) (process.InterceptorsContainerFactory, process.TimeCacher, error) { nodeOperationMode := common.NormalOperation if pcf.prefConfigs.Preferences.FullArchive { @@ -1508,6 +1520,7 @@ func (pcf *processComponentsFactory) newInterceptorContainerFactory( fullArchivePeerShardMapper, hardforkTrigger, nodeOperationMode, + relayedTxV3Processor, ) } if shardCoordinator.SelfId() == core.MetachainShardId { @@ -1521,6 +1534,7 @@ func (pcf *processComponentsFactory) newInterceptorContainerFactory( fullArchivePeerShardMapper, hardforkTrigger, nodeOperationMode, + relayedTxV3Processor, ) } @@ -1660,6 +1674,7 @@ func (pcf *processComponentsFactory) newShardInterceptorContainerFactory( fullArchivePeerShardMapper *networksharding.PeerShardMapper, hardforkTrigger factory.HardforkTrigger, nodeOperationMode common.NodeOperation, + relayedTxV3Processor process.RelayedTxV3Processor, ) (process.InterceptorsContainerFactory, process.TimeCacher, error) { headerBlackList := cache.NewTimeCache(timeSpanForBadHeaders) shardInterceptorsContainerFactoryArgs := interceptorscontainer.CommonInterceptorsContainerFactoryArgs{ @@ -1693,6 +1708,7 @@ func (pcf *processComponentsFactory) newShardInterceptorContainerFactory( FullArchivePeerShardMapper: fullArchivePeerShardMapper, HardforkTrigger: hardforkTrigger, NodeOperationMode: nodeOperationMode, + RelayedTxV3Processor: relayedTxV3Processor, } interceptorContainerFactory, err := interceptorscontainer.NewShardInterceptorsContainerFactory(shardInterceptorsContainerFactoryArgs) @@ -1713,6 +1729,7 @@ func (pcf *processComponentsFactory) newMetaInterceptorContainerFactory( fullArchivePeerShardMapper *networksharding.PeerShardMapper, hardforkTrigger factory.HardforkTrigger, nodeOperationMode common.NodeOperation, + relayedTxV3Processor process.RelayedTxV3Processor, ) (process.InterceptorsContainerFactory, process.TimeCacher, error) { headerBlackList := cache.NewTimeCache(timeSpanForBadHeaders) metaInterceptorsContainerFactoryArgs := interceptorscontainer.CommonInterceptorsContainerFactoryArgs{ @@ -1746,6 +1763,7 @@ func (pcf *processComponentsFactory) newMetaInterceptorContainerFactory( FullArchivePeerShardMapper: fullArchivePeerShardMapper, HardforkTrigger: hardforkTrigger, NodeOperationMode: nodeOperationMode, + RelayedTxV3Processor: relayedTxV3Processor, } interceptorContainerFactory, err := interceptorscontainer.NewMetaInterceptorsContainerFactory(metaInterceptorsContainerFactoryArgs) diff --git a/factory/processing/processComponentsHandler.go b/factory/processing/processComponentsHandler.go index a5b71ca3b28..875216102c6 100644 --- a/factory/processing/processComponentsHandler.go +++ b/factory/processing/processComponentsHandler.go @@ -177,6 +177,9 @@ func (m *managedProcessComponents) CheckSubcomponents() error { if check.IfNil(m.processComponents.sentSignaturesTracker) { return errors.ErrNilSentSignatureTracker } + if check.IfNil(m.processComponents.relayedTxV3Processor) { + return errors.ErrNilRelayedTxV3Processor + } return nil } @@ -673,6 +676,18 @@ func (m *managedProcessComponents) SentSignaturesTracker() process.SentSignature return m.processComponents.sentSignaturesTracker } +// RelayedTxV3Processor returns the relayed tx v3 processor +func (m *managedProcessComponents) RelayedTxV3Processor() process.RelayedTxV3Processor { + m.mutProcessComponents.RLock() + defer m.mutProcessComponents.RUnlock() + + if m.processComponents == nil { + return nil + } + + return m.processComponents.relayedTxV3Processor +} + // IsInterfaceNil returns true if the interface is nil func (m *managedProcessComponents) IsInterfaceNil() bool { return m == nil diff --git a/factory/processing/txSimulatorProcessComponents.go b/factory/processing/txSimulatorProcessComponents.go index 257a46af1a5..09c94e4d6e9 100644 --- a/factory/processing/txSimulatorProcessComponents.go +++ b/factory/processing/txSimulatorProcessComponents.go @@ -27,7 +27,7 @@ import ( datafield "github.com/multiversx/mx-chain-vm-common-go/parsers/dataField" ) -func (pcf *processComponentsFactory) createAPITransactionEvaluator() (factory.TransactionEvaluator, process.VirtualMachinesContainerFactory, error) { +func (pcf *processComponentsFactory) createAPITransactionEvaluator(relayedTxV3Processor process.RelayedTxV3Processor) (factory.TransactionEvaluator, process.VirtualMachinesContainerFactory, error) { simulationAccountsDB, err := transactionEvaluator.NewSimulationAccountsDB(pcf.state.AccountsAdapterAPI()) if err != nil { return nil, nil, err @@ -47,7 +47,7 @@ func (pcf *processComponentsFactory) createAPITransactionEvaluator() (factory.Tr return nil, nil, err } - txSimulatorProcessorArgs, vmContainerFactory, txTypeHandler, err := pcf.createArgsTxSimulatorProcessor(simulationAccountsDB, vmOutputCacher, txLogsProcessor) + txSimulatorProcessorArgs, vmContainerFactory, txTypeHandler, err := pcf.createArgsTxSimulatorProcessor(simulationAccountsDB, vmOutputCacher, txLogsProcessor, relayedTxV3Processor) if err != nil { return nil, nil, err } @@ -89,12 +89,13 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessor( accountsAdapter state.AccountsAdapter, vmOutputCacher storage.Cacher, txLogsProcessor process.TransactionLogProcessor, + relayedTxV3Processor process.RelayedTxV3Processor, ) (transactionEvaluator.ArgsTxSimulator, process.VirtualMachinesContainerFactory, process.TxTypeHandler, error) { shardID := pcf.bootstrapComponents.ShardCoordinator().SelfId() if shardID == core.MetachainShardId { return pcf.createArgsTxSimulatorProcessorForMeta(accountsAdapter, vmOutputCacher, txLogsProcessor) } else { - return pcf.createArgsTxSimulatorProcessorShard(accountsAdapter, vmOutputCacher, txLogsProcessor) + return pcf.createArgsTxSimulatorProcessorShard(accountsAdapter, vmOutputCacher, txLogsProcessor, relayedTxV3Processor) } } @@ -249,6 +250,7 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessorShard( accountsAdapter state.AccountsAdapter, vmOutputCacher storage.Cacher, txLogsProcessor process.TransactionLogProcessor, + relayedTxV3Processor process.RelayedTxV3Processor, ) (transactionEvaluator.ArgsTxSimulator, process.VirtualMachinesContainerFactory, process.TxTypeHandler, error) { args := transactionEvaluator.ArgsTxSimulator{} @@ -377,25 +379,26 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessorShard( } argsTxProcessor := transaction.ArgsNewTxProcessor{ - Accounts: accountsAdapter, - Hasher: pcf.coreData.Hasher(), - PubkeyConv: pcf.coreData.AddressPubKeyConverter(), - Marshalizer: pcf.coreData.InternalMarshalizer(), - SignMarshalizer: pcf.coreData.TxMarshalizer(), - ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), - ScProcessor: scProcessor, - TxFeeHandler: txFeeHandler, - TxTypeHandler: txTypeHandler, - EconomicsFee: pcf.coreData.EconomicsData(), - ReceiptForwarder: receiptTxInterim, - BadTxForwarder: badTxInterim, - ArgsParser: argsParser, - ScrForwarder: scForwarder, - EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), - EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), - TxVersionChecker: pcf.coreData.TxVersionChecker(), - GuardianChecker: pcf.bootstrapComponents.GuardedAccountHandler(), - TxLogsProcessor: txLogsProcessor, + Accounts: accountsAdapter, + Hasher: pcf.coreData.Hasher(), + PubkeyConv: pcf.coreData.AddressPubKeyConverter(), + Marshalizer: pcf.coreData.InternalMarshalizer(), + SignMarshalizer: pcf.coreData.TxMarshalizer(), + ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), + ScProcessor: scProcessor, + TxFeeHandler: txFeeHandler, + TxTypeHandler: txTypeHandler, + EconomicsFee: pcf.coreData.EconomicsData(), + ReceiptForwarder: receiptTxInterim, + BadTxForwarder: badTxInterim, + ArgsParser: argsParser, + ScrForwarder: scForwarder, + EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), + EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), + TxVersionChecker: pcf.coreData.TxVersionChecker(), + GuardianChecker: pcf.bootstrapComponents.GuardedAccountHandler(), + TxLogsProcessor: txLogsProcessor, + RelayedTxV3Processor: relayedTxV3Processor, } txProcessor, err := transaction.NewTxProcessor(argsTxProcessor) diff --git a/factory/processing/txSimulatorProcessComponents_test.go b/factory/processing/txSimulatorProcessComponents_test.go index aad848600d8..37944768bfe 100644 --- a/factory/processing/txSimulatorProcessComponents_test.go +++ b/factory/processing/txSimulatorProcessComponents_test.go @@ -8,6 +8,7 @@ import ( "github.com/multiversx/mx-chain-go/factory/processing" "github.com/multiversx/mx-chain-go/process/mock" "github.com/multiversx/mx-chain-go/testscommon/components" + "github.com/multiversx/mx-chain-go/testscommon/processMocks" "github.com/stretchr/testify/assert" ) @@ -26,7 +27,7 @@ func TestManagedProcessComponents_createAPITransactionEvaluator(t *testing.T) { processArgs.Config.VMOutputCacher.Type = "invalid" pcf, _ := processing.NewProcessComponentsFactory(processArgs) - apiTransactionEvaluator, vmContainerFactory, err := pcf.CreateAPITransactionEvaluator() + apiTransactionEvaluator, vmContainerFactory, err := pcf.CreateAPITransactionEvaluator(&processMocks.RelayedTxV3ProcessorMock{}) assert.NotNil(t, err) assert.True(t, check.IfNil(apiTransactionEvaluator)) assert.True(t, check.IfNil(vmContainerFactory)) @@ -36,7 +37,7 @@ func TestManagedProcessComponents_createAPITransactionEvaluator(t *testing.T) { processArgs := components.GetProcessComponentsFactoryArgs(shardCoordinatorForShardID2) pcf, _ := processing.NewProcessComponentsFactory(processArgs) - apiTransactionEvaluator, vmContainerFactory, err := pcf.CreateAPITransactionEvaluator() + apiTransactionEvaluator, vmContainerFactory, err := pcf.CreateAPITransactionEvaluator(&processMocks.RelayedTxV3ProcessorMock{}) assert.Nil(t, err) assert.False(t, check.IfNil(apiTransactionEvaluator)) assert.False(t, check.IfNil(vmContainerFactory)) @@ -45,7 +46,7 @@ func TestManagedProcessComponents_createAPITransactionEvaluator(t *testing.T) { processArgs := components.GetProcessComponentsFactoryArgs(shardCoordinatorForMetachain) pcf, _ := processing.NewProcessComponentsFactory(processArgs) - apiTransactionEvaluator, vmContainerFactory, err := pcf.CreateAPITransactionEvaluator() + apiTransactionEvaluator, vmContainerFactory, err := pcf.CreateAPITransactionEvaluator(&processMocks.RelayedTxV3ProcessorMock{}) assert.Nil(t, err) assert.False(t, check.IfNil(apiTransactionEvaluator)) assert.False(t, check.IfNil(vmContainerFactory)) diff --git a/genesis/process/argGenesisBlockCreator.go b/genesis/process/argGenesisBlockCreator.go index 19b5fc9adcc..1904dfb09e4 100644 --- a/genesis/process/argGenesisBlockCreator.go +++ b/genesis/process/argGenesisBlockCreator.go @@ -70,6 +70,7 @@ type ArgsGenesisBlockCreator struct { BlockSignKeyGen crypto.KeyGenerator HistoryRepository dblookupext.HistoryRepository TxExecutionOrderHandler common.TxExecutionOrderHandler + RelayedTxV3Processor process.RelayedTxV3Processor GenesisNodePrice *big.Int GenesisString string diff --git a/genesis/process/genesisBlockCreator_test.go b/genesis/process/genesisBlockCreator_test.go index 68c93b87f51..02a03104d86 100644 --- a/genesis/process/genesisBlockCreator_test.go +++ b/genesis/process/genesisBlockCreator_test.go @@ -34,6 +34,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/genericMocks" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" + "github.com/multiversx/mx-chain-go/testscommon/processMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" storageCommon "github.com/multiversx/mx-chain-go/testscommon/storage" "github.com/multiversx/mx-chain-go/trie" @@ -190,6 +191,7 @@ func createMockArgument( return &block.Header{} }, }, + RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, } arg.ShardCoordinator = &mock.ShardCoordinatorMock{ diff --git a/genesis/process/shardGenesisBlockCreator.go b/genesis/process/shardGenesisBlockCreator.go index 3c7e47070c7..672fdebca9b 100644 --- a/genesis/process/shardGenesisBlockCreator.go +++ b/genesis/process/shardGenesisBlockCreator.go @@ -541,25 +541,26 @@ func createProcessorsForShardGenesisBlock(arg ArgsGenesisBlockCreator, enableEpo } argsNewTxProcessor := transaction.ArgsNewTxProcessor{ - Accounts: arg.Accounts, - Hasher: arg.Core.Hasher(), - PubkeyConv: arg.Core.AddressPubKeyConverter(), - Marshalizer: arg.Core.InternalMarshalizer(), - SignMarshalizer: arg.Core.TxMarshalizer(), - ShardCoordinator: arg.ShardCoordinator, - ScProcessor: scProcessorProxy, - TxFeeHandler: genesisFeeHandler, - TxTypeHandler: txTypeHandler, - EconomicsFee: genesisFeeHandler, - ReceiptForwarder: receiptTxInterim, - BadTxForwarder: badTxInterim, - ArgsParser: smartContract.NewArgumentParser(), - ScrForwarder: scForwarder, - EnableRoundsHandler: enableRoundsHandler, - EnableEpochsHandler: enableEpochsHandler, - TxVersionChecker: arg.Core.TxVersionChecker(), - GuardianChecker: disabledGuardian.NewDisabledGuardedAccountHandler(), - TxLogsProcessor: arg.TxLogsProcessor, + Accounts: arg.Accounts, + Hasher: arg.Core.Hasher(), + PubkeyConv: arg.Core.AddressPubKeyConverter(), + Marshalizer: arg.Core.InternalMarshalizer(), + SignMarshalizer: arg.Core.TxMarshalizer(), + ShardCoordinator: arg.ShardCoordinator, + ScProcessor: scProcessorProxy, + TxFeeHandler: genesisFeeHandler, + TxTypeHandler: txTypeHandler, + EconomicsFee: genesisFeeHandler, + ReceiptForwarder: receiptTxInterim, + BadTxForwarder: badTxInterim, + ArgsParser: smartContract.NewArgumentParser(), + ScrForwarder: scForwarder, + EnableRoundsHandler: enableRoundsHandler, + EnableEpochsHandler: enableEpochsHandler, + TxVersionChecker: arg.Core.TxVersionChecker(), + GuardianChecker: disabledGuardian.NewDisabledGuardedAccountHandler(), + TxLogsProcessor: arg.TxLogsProcessor, + RelayedTxV3Processor: arg.RelayedTxV3Processor, } transactionProcessor, err := transaction.NewTxProcessor(argsNewTxProcessor) if err != nil { diff --git a/go.mod b/go.mod index 50d869b03dd..901a438f4cc 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240321151517-2fffad77c605 - github.com/multiversx/mx-chain-core-go v1.2.19-0.20240322114245-95b7c293302d + github.com/multiversx/mx-chain-core-go v1.2.20-0.20240404181342-48e2da52259e github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 github.com/multiversx/mx-chain-es-indexer-go v1.4.20-0.20240228094052-28a36809b9b8 github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c diff --git a/go.sum b/go.sum index 8e22702d4e9..786bda74100 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240321151517-2fffad77c605 h1:WYPdDmxL5rk9O6wUYVW4Fpw/QtwkWiIzFHeH2F5Zap4= github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240321151517-2fffad77c605/go.mod h1:wUM/1NFfgeTjovQMaaXghynwXgOyoPchMquu2wnCHz8= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20240322114245-95b7c293302d h1:qTIgNTQ+8+hMXI9CN8yAzrkpro8gKvmdrsXNpTz2mIs= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20240322114245-95b7c293302d/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.20-0.20240404181342-48e2da52259e h1:MseWlrUS8b8RhJ6JUqQBpYeYylmyoWqom+bvn3Cl/U4= +github.com/multiversx/mx-chain-core-go v1.2.20-0.20240404181342-48e2da52259e/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 h1:beVIhs5ysylwNplQ/bZ0h5DoDlqKNWgpWE/NMHHNmAw= github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479/go.mod h1:Ap6p7QZFtwPlb++OvCG+85BfuZ+bLP/JtQp6EwjWJsI= github.com/multiversx/mx-chain-es-indexer-go v1.4.20-0.20240228094052-28a36809b9b8 h1:z9ePQGALhPCs9Fv7cQsnsScbEq8KuOJ9xrJEEEOiHyI= diff --git a/integrationTests/mock/processComponentsStub.go b/integrationTests/mock/processComponentsStub.go index e0407b5d6f9..e0619131343 100644 --- a/integrationTests/mock/processComponentsStub.go +++ b/integrationTests/mock/processComponentsStub.go @@ -60,6 +60,7 @@ type ProcessComponentsStub struct { ReceiptsRepositoryInternal factory.ReceiptsRepository ESDTDataStorageHandlerForAPIInternal vmcommon.ESDTNFTStorageHandler SentSignaturesTrackerInternal process.SentSignaturesTracker + RelayedTxV3ProcessorField process.RelayedTxV3Processor } // Create - @@ -296,6 +297,11 @@ func (pcs *ProcessComponentsStub) SentSignaturesTracker() process.SentSignatures return pcs.SentSignaturesTrackerInternal } +// RelayedTxV3Processor - +func (pcs *ProcessComponentsStub) RelayedTxV3Processor() process.RelayedTxV3Processor { + return pcs.RelayedTxV3ProcessorField +} + // IsInterfaceNil - func (pcs *ProcessComponentsStub) IsInterfaceNil() bool { return pcs == nil diff --git a/integrationTests/multiShard/hardFork/hardFork_test.go b/integrationTests/multiShard/hardFork/hardFork_test.go index 6686aa5b5c2..72682f7d382 100644 --- a/integrationTests/multiShard/hardFork/hardFork_test.go +++ b/integrationTests/multiShard/hardFork/hardFork_test.go @@ -28,6 +28,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" factoryTests "github.com/multiversx/mx-chain-go/testscommon/factory" "github.com/multiversx/mx-chain-go/testscommon/genesisMocks" + "github.com/multiversx/mx-chain-go/testscommon/processMocks" "github.com/multiversx/mx-chain-go/testscommon/statusHandler" "github.com/multiversx/mx-chain-go/update/factory" "github.com/multiversx/mx-chain-go/vm/systemSmartContracts/defaults" @@ -502,6 +503,7 @@ func hardForkImport( HeaderVersionConfigs: testscommon.GetDefaultHeaderVersionConfig(), HistoryRepository: &dblookupext.HistoryRepositoryStub{}, TxExecutionOrderHandler: &commonMocks.TxExecutionOrderHandlerStub{}, + RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, } genesisProcessor, err := process.NewGenesisBlockCreator(argsGenesis) diff --git a/integrationTests/multiShard/relayedTx/common.go b/integrationTests/multiShard/relayedTx/common.go index b3e9da00bb4..2e1ba08bac5 100644 --- a/integrationTests/multiShard/relayedTx/common.go +++ b/integrationTests/multiShard/relayedTx/common.go @@ -214,15 +214,15 @@ func createRelayedTxV3( userTx *transaction.Transaction, ) *transaction.Transaction { tx := &transaction.Transaction{ - Nonce: relayer.Nonce, - Value: big.NewInt(0), - RcvAddr: userTx.SndAddr, - SndAddr: relayer.Address, - GasPrice: integrationTests.MinTxGasPrice, - Data: []byte(""), - ChainID: userTx.ChainID, - Version: userTx.Version, - InnerTransaction: userTx, + Nonce: relayer.Nonce, + Value: big.NewInt(0), + RcvAddr: relayer.Address, + SndAddr: relayer.Address, + GasPrice: integrationTests.MinTxGasPrice, + Data: []byte(""), + ChainID: userTx.ChainID, + Version: userTx.Version, + InnerTransactions: []*transaction.Transaction{userTx}, } gasLimit := economicsFee.ComputeGasLimit(tx) tx.GasLimit = userTx.GasLimit + gasLimit diff --git a/integrationTests/multiShard/relayedTx/relayedTx_test.go b/integrationTests/multiShard/relayedTx/relayedTx_test.go index 3d367ae7d72..207ab540688 100644 --- a/integrationTests/multiShard/relayedTx/relayedTx_test.go +++ b/integrationTests/multiShard/relayedTx/relayedTx_test.go @@ -9,8 +9,12 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/esdt" "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests" "github.com/multiversx/mx-chain-go/integrationTests/vm/wasm" + "github.com/multiversx/mx-chain-go/node/chainSimulator" + "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" + "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/process" vmFactory "github.com/multiversx/mx-chain-go/process/factory" "github.com/multiversx/mx-chain-go/process/smartContract/hooks" @@ -21,6 +25,18 @@ import ( "github.com/stretchr/testify/require" ) +const ( + defaultPathToInitialConfig = "../../../cmd/node/config/" + minGasPrice = 1_000_000_000 + minGasLimit = 50_000 + txVersion = 2 + mockTxSignature = "sig" + maxNumOfBlocksToGenerateWhenExecutingTx = 10 + numOfBlocksToWaitForCrossShardSCR = 5 +) + +var oneEGLD = big.NewInt(1000000000000000000) + type createAndSendRelayedAndUserTxFuncType = func( nodes []*integrationTests.TestProcessorNode, relayer *integrationTests.TestWalletAccount, @@ -31,6 +47,118 @@ type createAndSendRelayedAndUserTxFuncType = func( txData []byte, ) (*transaction.Transaction, *transaction.Transaction) +func TestRelayedTransactionInMultiShardEnvironmanetWithChainSimulator(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 30, + } + + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.RelayedTransactionsV3EnableEpoch = 1 + cfg.EpochConfig.EnableEpochs.FixRelayedMoveBalanceEnableEpoch = 1 + }, + }) + require.NoError(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + err = cs.GenerateBlocksUntilEpochIsReached(1) + require.NoError(t, err) + + initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(10)) + relayer, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + sender, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + receiver, err := cs.GenerateAndMintWalletAddress(1, big.NewInt(0)) + require.NoError(t, err) + + innerTx := generateTransaction(sender.Bytes, 0, receiver.Bytes, oneEGLD, "", minGasLimit) + innerTx.RelayerAddr = relayer.Bytes + + sender2, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + receiver2, err := cs.GenerateAndMintWalletAddress(0, big.NewInt(0)) + require.NoError(t, err) + + innerTx2 := generateTransaction(sender2.Bytes, 0, receiver2.Bytes, oneEGLD, "", minGasLimit) + innerTx2.RelayerAddr = relayer.Bytes + + innerTx3 := generateTransaction(sender.Bytes, 1, receiver2.Bytes, oneEGLD, "", minGasLimit) + innerTx3.RelayerAddr = relayer.Bytes + + innerTxs := []*transaction.Transaction{innerTx, innerTx2, innerTx3} + + relayedTxGasLimit := minGasLimit * 5 + relayedTx := generateTransaction(relayer.Bytes, 0, relayer.Bytes, big.NewInt(0), "", uint64(relayedTxGasLimit)) + relayedTx.InnerTransactions = innerTxs + + _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + // generate few more blocks for the cross shard scr to be done + err = cs.GenerateBlocks(numOfBlocksToWaitForCrossShardSCR) + require.NoError(t, err) + + relayerAccount, err := cs.GetAccount(relayer) + require.NoError(t, err) + expectedRelayerFee := big.NewInt(int64(minGasPrice * relayedTxGasLimit)) + assert.Equal(t, big.NewInt(0).Sub(initialBalance, expectedRelayerFee).String(), relayerAccount.Balance) + + senderAccount, err := cs.GetAccount(sender) + require.NoError(t, err) + assert.Equal(t, big.NewInt(0).Sub(initialBalance, big.NewInt(0).Mul(oneEGLD, big.NewInt(2))).String(), senderAccount.Balance) + + sender2Account, err := cs.GetAccount(sender2) + require.NoError(t, err) + assert.Equal(t, big.NewInt(0).Sub(initialBalance, oneEGLD).String(), sender2Account.Balance) + + receiverAccount, err := cs.GetAccount(receiver) + require.NoError(t, err) + assert.Equal(t, oneEGLD.String(), receiverAccount.Balance) + + receiver2Account, err := cs.GetAccount(receiver2) + require.NoError(t, err) + assert.Equal(t, big.NewInt(0).Mul(oneEGLD, big.NewInt(2)).String(), receiver2Account.Balance) +} + +func generateTransaction(sender []byte, nonce uint64, receiver []byte, value *big.Int, data string, gasLimit uint64) *transaction.Transaction { + return &transaction.Transaction{ + Nonce: nonce, + Value: value, + SndAddr: sender, + RcvAddr: receiver, + Data: []byte(data), + GasLimit: gasLimit, + GasPrice: minGasPrice, + ChainID: []byte(configs.ChainID), + Version: txVersion, + Signature: []byte(mockTxSignature), + } +} + func TestRelayedTransactionInMultiShardEnvironmentWithNormalTx(t *testing.T) { t.Run("relayed v1", testRelayedTransactionInMultiShardEnvironmentWithNormalTx(CreateAndSendRelayedAndUserTx)) t.Run("relayed v3", testRelayedTransactionInMultiShardEnvironmentWithNormalTx(CreateAndSendRelayedAndUserTxV3)) diff --git a/integrationTests/testHeartbeatNode.go b/integrationTests/testHeartbeatNode.go index 1ba488b9e12..43b2ac576a0 100644 --- a/integrationTests/testHeartbeatNode.go +++ b/integrationTests/testHeartbeatNode.go @@ -54,6 +54,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/genesisMocks" "github.com/multiversx/mx-chain-go/testscommon/nodeTypeProviderMock" "github.com/multiversx/mx-chain-go/testscommon/p2pmocks" + "github.com/multiversx/mx-chain-go/testscommon/processMocks" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" trieMock "github.com/multiversx/mx-chain-go/testscommon/trie" vic "github.com/multiversx/mx-chain-go/testscommon/validatorInfoCacher" @@ -626,6 +627,7 @@ func (thn *TestHeartbeatNode) initInterceptors() { SignaturesHandler: &processMock.SignaturesHandlerStub{}, HeartbeatExpiryTimespanInSec: thn.heartbeatExpiryTimespanInSec, PeerID: thn.MainMessenger.ID(), + RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, } thn.createPeerAuthInterceptor(argsFactory) diff --git a/integrationTests/testInitializer.go b/integrationTests/testInitializer.go index ca2ed8dcd25..94e2e3fd7d5 100644 --- a/integrationTests/testInitializer.go +++ b/integrationTests/testInitializer.go @@ -69,6 +69,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/guardianMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" "github.com/multiversx/mx-chain-go/testscommon/p2pmocks" + "github.com/multiversx/mx-chain-go/testscommon/processMocks" "github.com/multiversx/mx-chain-go/testscommon/stakingcommon" testStorage "github.com/multiversx/mx-chain-go/testscommon/state" statusHandlerMock "github.com/multiversx/mx-chain-go/testscommon/statusHandler" @@ -742,6 +743,7 @@ func CreateFullGenesisBlocks( HeaderVersionConfigs: testscommon.GetDefaultHeaderVersionConfig(), HistoryRepository: &dblookupext.HistoryRepositoryStub{}, TxExecutionOrderHandler: &commonMocks.TxExecutionOrderHandlerStub{}, + RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, } genesisProcessor, _ := genesisProcess.NewGenesisBlockCreator(argsGenesis) @@ -857,6 +859,7 @@ func CreateGenesisMetaBlock( HeaderVersionConfigs: testscommon.GetDefaultHeaderVersionConfig(), HistoryRepository: &dblookupext.HistoryRepositoryStub{}, TxExecutionOrderHandler: &commonMocks.TxExecutionOrderHandlerStub{}, + RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, } if shardCoordinator.SelfId() != core.MetachainShardId { @@ -1053,15 +1056,16 @@ func CreateSimpleTxProcessor(accnts state.AccountsAdapter) process.TransactionPr return fee }, }, - ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, - BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, - ArgsParser: smartContract.NewArgumentParser(), - ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, - EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, - EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - TxVersionChecker: &testscommon.TxVersionCheckerStub{}, - GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, - TxLogsProcessor: &mock.TxLogsProcessorStub{}, + ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, + BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, + ArgsParser: smartContract.NewArgumentParser(), + ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, + EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, + EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + TxVersionChecker: &testscommon.TxVersionCheckerStub{}, + GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, + TxLogsProcessor: &mock.TxLogsProcessorStub{}, + RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, } txProcessor, _ := txProc.NewTxProcessor(argsNewTxProcessor) diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index 5cfb5aa6d6d..16940b5d628 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -114,6 +114,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/mainFactoryMocks" "github.com/multiversx/mx-chain-go/testscommon/outport" "github.com/multiversx/mx-chain-go/testscommon/p2pmocks" + "github.com/multiversx/mx-chain-go/testscommon/processMocks" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" "github.com/multiversx/mx-chain-go/testscommon/stakingcommon" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" @@ -1286,6 +1287,8 @@ func (tpn *TestProcessorNode) initInterceptors(heartbeatPk string) { cryptoComponents.BlKeyGen = tpn.OwnAccount.KeygenBlockSign cryptoComponents.TxKeyGen = tpn.OwnAccount.KeygenTxSign + relayedV3TxProcessor, _ := transaction.NewRelayedTxV3Processor(tpn.EconomicsData, tpn.ShardCoordinator) + if tpn.ShardCoordinator.SelfId() == core.MetachainShardId { argsEpochStart := &metachain.ArgsNewMetaEpochStartTrigger{ GenesisTime: tpn.RoundHandler.TimeStamp(), @@ -1338,6 +1341,7 @@ func (tpn *TestProcessorNode) initInterceptors(heartbeatPk string) { FullArchivePeerShardMapper: tpn.FullArchivePeerShardMapper, HardforkTrigger: tpn.HardforkTrigger, NodeOperationMode: tpn.NodeOperationMode, + RelayedTxV3Processor: relayedV3TxProcessor, } interceptorContainerFactory, _ := interceptorscontainer.NewMetaInterceptorsContainerFactory(metaInterceptorContainerFactoryArgs) @@ -1406,6 +1410,7 @@ func (tpn *TestProcessorNode) initInterceptors(heartbeatPk string) { FullArchivePeerShardMapper: tpn.FullArchivePeerShardMapper, HardforkTrigger: tpn.HardforkTrigger, NodeOperationMode: tpn.NodeOperationMode, + RelayedTxV3Processor: relayedV3TxProcessor, } interceptorContainerFactory, _ := interceptorscontainer.NewShardInterceptorsContainerFactory(shardIntereptorContainerFactoryArgs) @@ -1714,27 +1719,30 @@ func (tpn *TestProcessorNode) initInnerProcessors(gasMap map[string]map[string]u tpn.ScProcessor, _ = processProxy.NewTestSmartContractProcessorProxy(argsNewScProcessor, tpn.EpochNotifier) + relayedV3TxProcessor, _ := transaction.NewRelayedTxV3Processor(tpn.EconomicsData, tpn.ShardCoordinator) + receiptsHandler, _ := tpn.InterimProcContainer.Get(dataBlock.ReceiptBlock) argsNewTxProcessor := transaction.ArgsNewTxProcessor{ - Accounts: tpn.AccntState, - Hasher: TestHasher, - PubkeyConv: TestAddressPubkeyConverter, - Marshalizer: TestMarshalizer, - SignMarshalizer: TestTxSignMarshalizer, - ShardCoordinator: tpn.ShardCoordinator, - ScProcessor: tpn.ScProcessor, - TxFeeHandler: tpn.FeeAccumulator, - TxTypeHandler: txTypeHandler, - EconomicsFee: tpn.EconomicsData, - ReceiptForwarder: receiptsHandler, - BadTxForwarder: badBlocksHandler, - ArgsParser: tpn.ArgsParser, - ScrForwarder: tpn.ScrForwarder, - EnableRoundsHandler: tpn.EnableRoundsHandler, - EnableEpochsHandler: tpn.EnableEpochsHandler, - GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, - TxVersionChecker: &testscommon.TxVersionCheckerStub{}, - TxLogsProcessor: tpn.TransactionLogProcessor, + Accounts: tpn.AccntState, + Hasher: TestHasher, + PubkeyConv: TestAddressPubkeyConverter, + Marshalizer: TestMarshalizer, + SignMarshalizer: TestTxSignMarshalizer, + ShardCoordinator: tpn.ShardCoordinator, + ScProcessor: tpn.ScProcessor, + TxFeeHandler: tpn.FeeAccumulator, + TxTypeHandler: txTypeHandler, + EconomicsFee: tpn.EconomicsData, + ReceiptForwarder: receiptsHandler, + BadTxForwarder: badBlocksHandler, + ArgsParser: tpn.ArgsParser, + ScrForwarder: tpn.ScrForwarder, + EnableRoundsHandler: tpn.EnableRoundsHandler, + EnableEpochsHandler: tpn.EnableEpochsHandler, + GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, + TxVersionChecker: &testscommon.TxVersionCheckerStub{}, + TxLogsProcessor: tpn.TransactionLogProcessor, + RelayedTxV3Processor: relayedV3TxProcessor, } tpn.TxProcessor, _ = transaction.NewTxProcessor(argsNewTxProcessor) scheduledSCRsStorer, _ := tpn.Storage.GetStorer(dataRetriever.ScheduledSCRsUnit) @@ -2591,22 +2599,22 @@ func (tpn *TestProcessorNode) SendTransaction(tx *dataTransaction.Transaction) ( guardianAddress = TestAddressPubkeyConverter.SilentEncode(tx.GuardianAddr, log) } createTxArgs := &external.ArgsCreateTransaction{ - Nonce: tx.Nonce, - Value: tx.Value.String(), - Receiver: encodedRcvAddr, - ReceiverUsername: nil, - Sender: encodedSndAddr, - SenderUsername: nil, - GasPrice: tx.GasPrice, - GasLimit: tx.GasLimit, - DataField: tx.Data, - SignatureHex: hex.EncodeToString(tx.Signature), - ChainID: string(tx.ChainID), - Version: tx.Version, - Options: tx.Options, - Guardian: guardianAddress, - GuardianSigHex: hex.EncodeToString(tx.GuardianSignature), - InnerTransaction: tx.InnerTransaction, + Nonce: tx.Nonce, + Value: tx.Value.String(), + Receiver: encodedRcvAddr, + ReceiverUsername: nil, + Sender: encodedSndAddr, + SenderUsername: nil, + GasPrice: tx.GasPrice, + GasLimit: tx.GasLimit, + DataField: tx.Data, + SignatureHex: hex.EncodeToString(tx.Signature), + ChainID: string(tx.ChainID), + Version: tx.Version, + Options: tx.Options, + Guardian: guardianAddress, + GuardianSigHex: hex.EncodeToString(tx.GuardianSignature), + InnerTransactions: tx.InnerTransactions, } tx, txHash, err := tpn.Node.CreateTransaction(createTxArgs) if err != nil { @@ -3339,6 +3347,11 @@ func GetDefaultProcessComponents() *mock.ProcessComponentsStub { CurrentEpochProviderInternal: &testscommon.CurrentEpochProviderStub{}, HistoryRepositoryInternal: &dblookupextMock.HistoryRepositoryStub{}, HardforkTriggerField: &testscommon.HardforkTriggerStub{}, + RelayedTxV3ProcessorField: &processMocks.RelayedTxV3ProcessorMock{ + CheckRelayedTxCalled: func(tx *dataTransaction.Transaction) error { + return nil + }, + }, } } diff --git a/integrationTests/vm/testInitializer.go b/integrationTests/vm/testInitializer.go index 7d44d945e14..1e6e3f4ca23 100644 --- a/integrationTests/vm/testInitializer.go +++ b/integrationTests/vm/testInitializer.go @@ -62,6 +62,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" "github.com/multiversx/mx-chain-go/testscommon/genesisMocks" "github.com/multiversx/mx-chain-go/testscommon/integrationtests" + "github.com/multiversx/mx-chain-go/testscommon/processMocks" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" "github.com/multiversx/mx-chain-go/testscommon/txDataBuilder" @@ -476,25 +477,26 @@ func CreateTxProcessorWithOneSCExecutorMockVM( } argsNewTxProcessor := transaction.ArgsNewTxProcessor{ - Accounts: accnts, - Hasher: integrationtests.TestHasher, - PubkeyConv: pubkeyConv, - Marshalizer: integrationtests.TestMarshalizer, - SignMarshalizer: integrationtests.TestMarshalizer, - ShardCoordinator: mock.NewMultiShardsCoordinatorMock(2), - ScProcessor: scProcessor, - TxFeeHandler: &testscommon.UnsignedTxHandlerStub{}, - TxTypeHandler: txTypeHandler, - EconomicsFee: economicsData, - ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, - BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, - ArgsParser: smartContract.NewArgumentParser(), - ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, - EnableRoundsHandler: enableRoundsHandler, - EnableEpochsHandler: enableEpochsHandler, - TxVersionChecker: versioning.NewTxVersionChecker(minTransactionVersion), - GuardianChecker: guardedAccountHandler, - TxLogsProcessor: &mock.TxLogsProcessorStub{}, + Accounts: accnts, + Hasher: integrationtests.TestHasher, + PubkeyConv: pubkeyConv, + Marshalizer: integrationtests.TestMarshalizer, + SignMarshalizer: integrationtests.TestMarshalizer, + ShardCoordinator: mock.NewMultiShardsCoordinatorMock(2), + ScProcessor: scProcessor, + TxFeeHandler: &testscommon.UnsignedTxHandlerStub{}, + TxTypeHandler: txTypeHandler, + EconomicsFee: economicsData, + ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, + BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, + ArgsParser: smartContract.NewArgumentParser(), + ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, + EnableRoundsHandler: enableRoundsHandler, + EnableEpochsHandler: enableEpochsHandler, + TxVersionChecker: versioning.NewTxVersionChecker(minTransactionVersion), + GuardianChecker: guardedAccountHandler, + TxLogsProcessor: &mock.TxLogsProcessorStub{}, + RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, } return transaction.NewTxProcessor(argsNewTxProcessor) @@ -889,25 +891,26 @@ func CreateTxProcessorWithOneSCExecutorWithVMs( scProcessorProxy, _ := processProxy.NewTestSmartContractProcessorProxy(argsNewSCProcessor, epochNotifierInstance) argsNewTxProcessor := transaction.ArgsNewTxProcessor{ - Accounts: accnts, - Hasher: integrationtests.TestHasher, - PubkeyConv: pubkeyConv, - Marshalizer: integrationtests.TestMarshalizer, - SignMarshalizer: integrationtests.TestMarshalizer, - ShardCoordinator: shardCoordinator, - ScProcessor: scProcessorProxy, - TxFeeHandler: feeAccumulator, - TxTypeHandler: txTypeHandler, - EconomicsFee: economicsData, - ReceiptForwarder: intermediateTxHandler, - BadTxForwarder: intermediateTxHandler, - ArgsParser: smartContract.NewArgumentParser(), - ScrForwarder: intermediateTxHandler, - EnableRoundsHandler: enableRoundsHandler, - EnableEpochsHandler: enableEpochsHandler, - TxVersionChecker: versioning.NewTxVersionChecker(minTransactionVersion), - GuardianChecker: guardianChecker, - TxLogsProcessor: logProc, + Accounts: accnts, + Hasher: integrationtests.TestHasher, + PubkeyConv: pubkeyConv, + Marshalizer: integrationtests.TestMarshalizer, + SignMarshalizer: integrationtests.TestMarshalizer, + ShardCoordinator: shardCoordinator, + ScProcessor: scProcessorProxy, + TxFeeHandler: feeAccumulator, + TxTypeHandler: txTypeHandler, + EconomicsFee: economicsData, + ReceiptForwarder: intermediateTxHandler, + BadTxForwarder: intermediateTxHandler, + ArgsParser: smartContract.NewArgumentParser(), + ScrForwarder: intermediateTxHandler, + EnableRoundsHandler: enableRoundsHandler, + EnableEpochsHandler: enableEpochsHandler, + TxVersionChecker: versioning.NewTxVersionChecker(minTransactionVersion), + GuardianChecker: guardianChecker, + TxLogsProcessor: logProc, + RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, } txProcessor, err := transaction.NewTxProcessor(argsNewTxProcessor) if err != nil { diff --git a/integrationTests/vm/wasm/utils.go b/integrationTests/vm/wasm/utils.go index d4f4207662d..bc93a151485 100644 --- a/integrationTests/vm/wasm/utils.go +++ b/integrationTests/vm/wasm/utils.go @@ -53,6 +53,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/guardianMocks" "github.com/multiversx/mx-chain-go/testscommon/integrationtests" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" + "github.com/multiversx/mx-chain-go/testscommon/processMocks" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" "github.com/multiversx/mx-chain-go/vm/systemSmartContracts/defaults" vmcommon "github.com/multiversx/mx-chain-vm-common-go" @@ -401,25 +402,26 @@ func (context *TestContext) initTxProcessorWithOneSCExecutorWithVMs() { require.Nil(context.T, err) argsNewTxProcessor := processTransaction.ArgsNewTxProcessor{ - Accounts: context.Accounts, - Hasher: hasher, - PubkeyConv: pkConverter, - Marshalizer: marshalizer, - SignMarshalizer: marshalizer, - ShardCoordinator: oneShardCoordinator, - ScProcessor: context.ScProcessor, - TxFeeHandler: context.UnsignexTxHandler, - TxTypeHandler: txTypeHandler, - EconomicsFee: context.EconomicsFee, - ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, - BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, - ArgsParser: smartContract.NewArgumentParser(), - ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, - EnableRoundsHandler: context.EnableRoundsHandler, - EnableEpochsHandler: context.EnableEpochsHandler, - TxVersionChecker: &testscommon.TxVersionCheckerStub{}, - GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, - TxLogsProcessor: context.TxLogsProcessor, + Accounts: context.Accounts, + Hasher: hasher, + PubkeyConv: pkConverter, + Marshalizer: marshalizer, + SignMarshalizer: marshalizer, + ShardCoordinator: oneShardCoordinator, + ScProcessor: context.ScProcessor, + TxFeeHandler: context.UnsignexTxHandler, + TxTypeHandler: txTypeHandler, + EconomicsFee: context.EconomicsFee, + ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, + BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, + ArgsParser: smartContract.NewArgumentParser(), + ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, + EnableRoundsHandler: context.EnableRoundsHandler, + EnableEpochsHandler: context.EnableEpochsHandler, + TxVersionChecker: &testscommon.TxVersionCheckerStub{}, + GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, + TxLogsProcessor: context.TxLogsProcessor, + RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, } context.TxProcessor, err = processTransaction.NewTxProcessor(argsNewTxProcessor) diff --git a/integrationTests/vm/wasm/wasmvm/wasmVM_test.go b/integrationTests/vm/wasm/wasmvm/wasmVM_test.go index 53ace932675..37084d225c4 100644 --- a/integrationTests/vm/wasm/wasmvm/wasmVM_test.go +++ b/integrationTests/vm/wasm/wasmvm/wasmVM_test.go @@ -30,6 +30,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/economicsmocks" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/integrationtests" + "github.com/multiversx/mx-chain-go/testscommon/processMocks" logger "github.com/multiversx/mx-chain-logger-go" vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/multiversx/mx-chain-vm-common-go/builtInFunctions" @@ -628,23 +629,24 @@ func TestExecuteTransactionAndTimeToProcessChange(t *testing.T) { _, _ = vm.CreateAccount(accnts, ownerAddressBytes, ownerNonce, ownerBalance) argsNewTxProcessor := processTransaction.ArgsNewTxProcessor{ - Accounts: accnts, - Hasher: testHasher, - PubkeyConv: pubkeyConv, - Marshalizer: testMarshalizer, - SignMarshalizer: testMarshalizer, - ShardCoordinator: shardCoordinator, - ScProcessor: &testscommon.SCProcessorMock{}, - TxFeeHandler: &testscommon.UnsignedTxHandlerStub{}, - TxTypeHandler: txTypeHandler, - EconomicsFee: &economicsmocks.EconomicsHandlerStub{}, - ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, - BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, - ArgsParser: smartContract.NewArgumentParser(), - ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, - EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, - EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - TxLogsProcessor: &mock.TxLogsProcessorStub{}, + Accounts: accnts, + Hasher: testHasher, + PubkeyConv: pubkeyConv, + Marshalizer: testMarshalizer, + SignMarshalizer: testMarshalizer, + ShardCoordinator: shardCoordinator, + ScProcessor: &testscommon.SCProcessorMock{}, + TxFeeHandler: &testscommon.UnsignedTxHandlerStub{}, + TxTypeHandler: txTypeHandler, + EconomicsFee: &economicsmocks.EconomicsHandlerStub{}, + ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, + BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, + ArgsParser: smartContract.NewArgumentParser(), + ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, + EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, + EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + TxLogsProcessor: &mock.TxLogsProcessorStub{}, + RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, } txProc, _ := processTransaction.NewTxProcessor(argsNewTxProcessor) diff --git a/node/chainSimulator/components/processComponents.go b/node/chainSimulator/components/processComponents.go index efa7af79c10..9d0f861e624 100644 --- a/node/chainSimulator/components/processComponents.go +++ b/node/chainSimulator/components/processComponents.go @@ -98,6 +98,7 @@ type processComponentsHolder struct { esdtDataStorageHandlerForAPI vmcommon.ESDTNFTStorageHandler accountsParser genesis.AccountsParser sentSignatureTracker process.SentSignaturesTracker + relayedTxV3Processor process.RelayedTxV3Processor managedProcessComponentsCloser io.Closer } @@ -270,6 +271,7 @@ func CreateProcessComponents(args ArgsProcessComponentsHolder) (*processComponen esdtDataStorageHandlerForAPI: managedProcessComponents.ESDTDataStorageHandlerForAPI(), accountsParser: managedProcessComponents.AccountsParser(), sentSignatureTracker: managedProcessComponents.SentSignaturesTracker(), + relayedTxV3Processor: managedProcessComponents.RelayedTxV3Processor(), managedProcessComponentsCloser: managedProcessComponents, } @@ -481,6 +483,11 @@ func (p *processComponentsHolder) ReceiptsRepository() factory.ReceiptsRepositor return p.receiptsRepository } +// RelayedTxV3Processor returns the relayed tx v3 processor +func (p *processComponentsHolder) RelayedTxV3Processor() process.RelayedTxV3Processor { + return p.relayedTxV3Processor +} + // Close will call the Close methods on all inner components func (p *processComponentsHolder) Close() error { return p.managedProcessComponentsCloser.Close() diff --git a/node/external/dtos.go b/node/external/dtos.go index b01dfbd19ff..12a6b153c46 100644 --- a/node/external/dtos.go +++ b/node/external/dtos.go @@ -4,21 +4,21 @@ import "github.com/multiversx/mx-chain-core-go/data/transaction" // ArgsCreateTransaction defines arguments for creating a transaction type ArgsCreateTransaction struct { - Nonce uint64 - Value string - Receiver string - ReceiverUsername []byte - Sender string - SenderUsername []byte - GasPrice uint64 - GasLimit uint64 - DataField []byte - SignatureHex string - ChainID string - Version uint32 - Options uint32 - Guardian string - GuardianSigHex string - Relayer string - InnerTransaction *transaction.Transaction + Nonce uint64 + Value string + Receiver string + ReceiverUsername []byte + Sender string + SenderUsername []byte + GasPrice uint64 + GasLimit uint64 + DataField []byte + SignatureHex string + ChainID string + Version uint32 + Options uint32 + Guardian string + GuardianSigHex string + Relayer string + InnerTransactions []*transaction.Transaction } diff --git a/node/node.go b/node/node.go index 176e7abfbd5..d1d31879812 100644 --- a/node/node.go +++ b/node/node.go @@ -785,6 +785,7 @@ func (n *Node) commonTransactionValidation( n.coreComponents.TxSignHasher(), n.coreComponents.TxVersionChecker(), n.coreComponents.EnableEpochsHandler(), + n.processComponents.RelayedTxV3Processor(), ) if err != nil { return nil, nil, err @@ -878,20 +879,20 @@ func (n *Node) CreateTransaction(txArgs *external.ArgsCreateTransaction) (*trans } tx := &transaction.Transaction{ - Nonce: txArgs.Nonce, - Value: valAsBigInt, - RcvAddr: receiverAddress, - RcvUserName: txArgs.ReceiverUsername, - SndAddr: senderAddress, - SndUserName: txArgs.SenderUsername, - GasPrice: txArgs.GasPrice, - GasLimit: txArgs.GasLimit, - Data: txArgs.DataField, - Signature: signatureBytes, - ChainID: []byte(txArgs.ChainID), - Version: txArgs.Version, - Options: txArgs.Options, - InnerTransaction: txArgs.InnerTransaction, + Nonce: txArgs.Nonce, + Value: valAsBigInt, + RcvAddr: receiverAddress, + RcvUserName: txArgs.ReceiverUsername, + SndAddr: senderAddress, + SndUserName: txArgs.SenderUsername, + GasPrice: txArgs.GasPrice, + GasLimit: txArgs.GasLimit, + Data: txArgs.DataField, + Signature: signatureBytes, + ChainID: []byte(txArgs.ChainID), + Version: txArgs.Version, + Options: txArgs.Options, + InnerTransactions: txArgs.InnerTransactions, } if len(txArgs.Guardian) > 0 { diff --git a/node/node_test.go b/node/node_test.go index 7c4bba7223f..652b2672062 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -61,6 +61,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/mainFactoryMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" "github.com/multiversx/mx-chain-go/testscommon/p2pmocks" + "github.com/multiversx/mx-chain-go/testscommon/processMocks" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" "github.com/multiversx/mx-chain-go/testscommon/stakingcommon" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" @@ -1850,22 +1851,22 @@ func TestGenerateTransaction_CorrectParamsShouldNotError(t *testing.T) { func getDefaultTransactionArgs() *external.ArgsCreateTransaction { return &external.ArgsCreateTransaction{ - Nonce: uint64(0), - Value: new(big.Int).SetInt64(10).String(), - Receiver: "rcv", - ReceiverUsername: []byte("rcvrUsername"), - Sender: "snd", - SenderUsername: []byte("sndrUsername"), - GasPrice: uint64(10), - GasLimit: uint64(20), - DataField: []byte("-"), - SignatureHex: hex.EncodeToString(bytes.Repeat([]byte{0}, 10)), - ChainID: "chainID", - Version: 1, - Options: 0, - Guardian: "", - GuardianSigHex: "", - InnerTransaction: nil, + Nonce: uint64(0), + Value: new(big.Int).SetInt64(10).String(), + Receiver: "rcv", + ReceiverUsername: []byte("rcvrUsername"), + Sender: "snd", + SenderUsername: []byte("sndrUsername"), + GasPrice: uint64(10), + GasLimit: uint64(20), + DataField: []byte("-"), + SignatureHex: hex.EncodeToString(bytes.Repeat([]byte{0}, 10)), + ChainID: "chainID", + Version: 1, + Options: 0, + Guardian: "", + GuardianSigHex: "", + InnerTransactions: nil, } } @@ -5093,18 +5094,18 @@ func getDefaultCoreComponents() *nodeMockFactory.CoreComponentsMock { MinTransactionVersionCalled: func() uint32 { return 1 }, - WDTimer: &testscommon.WatchdogMock{}, - Alarm: &testscommon.AlarmSchedulerStub{}, - NtpTimer: &testscommon.SyncTimerStub{}, - RoundHandlerField: &testscommon.RoundHandlerMock{}, - EconomicsHandler: &economicsmocks.EconomicsHandlerMock{}, - APIEconomicsHandler: &economicsmocks.EconomicsHandlerMock{}, - RatingsConfig: &testscommon.RatingsInfoMock{}, - RatingHandler: &testscommon.RaterMock{}, - NodesConfig: &genesisMocks.NodesSetupStub{}, - StartTime: time.Time{}, - EpochChangeNotifier: &epochNotifier.EpochNotifierStub{}, - TxVersionCheckHandler: versioning.NewTxVersionChecker(0), + WDTimer: &testscommon.WatchdogMock{}, + Alarm: &testscommon.AlarmSchedulerStub{}, + NtpTimer: &testscommon.SyncTimerStub{}, + RoundHandlerField: &testscommon.RoundHandlerMock{}, + EconomicsHandler: &economicsmocks.EconomicsHandlerMock{}, + APIEconomicsHandler: &economicsmocks.EconomicsHandlerMock{}, + RatingsConfig: &testscommon.RatingsInfoMock{}, + RatingHandler: &testscommon.RaterMock{}, + NodesConfig: &genesisMocks.NodesSetupStub{}, + StartTime: time.Time{}, + EpochChangeNotifier: &epochNotifier.EpochNotifierStub{}, + TxVersionCheckHandler: versioning.NewTxVersionChecker(0), EnableEpochsHandlerField: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, } } @@ -5141,6 +5142,7 @@ func getDefaultProcessComponents() *factoryMock.ProcessComponentsMock { TxsSenderHandlerField: &txsSenderMock.TxsSenderHandlerMock{}, ScheduledTxsExecutionHandlerInternal: &testscommon.ScheduledTxsExecutionStub{}, HistoryRepositoryInternal: &dblookupext.HistoryRepositoryStub{}, + RelayedTxV3ProcessorField: &processMocks.RelayedTxV3ProcessorMock{}, } } diff --git a/process/coordinator/transactionType.go b/process/coordinator/transactionType.go index 1e2d8d2d10f..d754da2c34d 100644 --- a/process/coordinator/transactionType.go +++ b/process/coordinator/transactionType.go @@ -196,7 +196,7 @@ func (tth *txTypeHandler) isRelayedTransactionV2(functionName string) bool { } func (tth *txTypeHandler) isRelayedTransactionV3(tx data.TransactionHandler) bool { - return !check.IfNil(tx.GetUserTransaction()) + return len(tx.GetUserTransactions()) != 0 } func (tth *txTypeHandler) isDestAddressEmpty(tx data.TransactionHandler) bool { diff --git a/process/coordinator/transactionType_test.go b/process/coordinator/transactionType_test.go index 5603a2839e3..9739075d847 100644 --- a/process/coordinator/transactionType_test.go +++ b/process/coordinator/transactionType_test.go @@ -474,7 +474,7 @@ func TestTxTypeHandler_ComputeTransactionTypeRelayedV3(t *testing.T) { tx.SndAddr = []byte("000") tx.RcvAddr = []byte("001") tx.Value = big.NewInt(45) - tx.InnerTransaction = &transaction.Transaction{Nonce: 1} + tx.InnerTransactions = []*transaction.Transaction{{Nonce: 1}} arg := createMockArguments() arg.PubkeyConverter = &testscommon.PubkeyConverterStub{ diff --git a/process/disabled/relayedTxV3Processor.go b/process/disabled/relayedTxV3Processor.go new file mode 100644 index 00000000000..5c9fdd2943f --- /dev/null +++ b/process/disabled/relayedTxV3Processor.go @@ -0,0 +1,35 @@ +package disabled + +import ( + "math/big" + + "github.com/multiversx/mx-chain-core-go/data/transaction" +) + +type relayedTxV3Processor struct { +} + +// NewRelayedTxV3Processor returns a new instance of disabled relayedTxV3Processor +func NewRelayedTxV3Processor() *relayedTxV3Processor { + return &relayedTxV3Processor{} +} + +// CheckRelayedTx returns nil as it is disabled +func (proc *relayedTxV3Processor) CheckRelayedTx(_ *transaction.Transaction) error { + return nil +} + +// ComputeRelayedTxFees returns 0, 0 as it is disabled +func (proc *relayedTxV3Processor) ComputeRelayedTxFees(_ *transaction.Transaction) (*big.Int, *big.Int) { + return big.NewInt(0), big.NewInt(0) +} + +// GetUniqueSendersRequiredFeesMap returns an empty map as it is disabled +func (proc *relayedTxV3Processor) GetUniqueSendersRequiredFeesMap(_ []*transaction.Transaction) map[string]*big.Int { + return make(map[string]*big.Int) +} + +// IsInterfaceNil returns true if there is no value under the interface +func (proc *relayedTxV3Processor) IsInterfaceNil() bool { + return proc == nil +} diff --git a/process/errors.go b/process/errors.go index dae35c3e97d..107a04246ca 100644 --- a/process/errors.go +++ b/process/errors.go @@ -1230,8 +1230,8 @@ var ErrNilSentSignatureTracker = errors.New("nil sent signature tracker") // ErrRelayedV3GasPriceMismatch signals that relayed v3 gas price is not equal with inner tx var ErrRelayedV3GasPriceMismatch = errors.New("relayed tx v3 gas price mismatch") -// ErrRelayedTxV3BeneficiaryDoesNotMatchReceiver signals that an invalid address was provided in the relayed tx v3 -var ErrRelayedTxV3BeneficiaryDoesNotMatchReceiver = errors.New("invalid address in relayed tx v3") +// ErrRelayedTxV3SenderDoesNotMatchReceiver signals that the sender of relayed tx v3 does not match the receiver +var ErrRelayedTxV3SenderDoesNotMatchReceiver = errors.New("relayed tx v3 sender does not match receiver") // ErrRelayedTxV3Disabled signals that the v3 version of relayed tx is disabled var ErrRelayedTxV3Disabled = errors.New("relayed tx v3 is disabled") @@ -1247,3 +1247,18 @@ var ErrRelayedTxV3RelayerMismatch = errors.New("relayed tx v3 relayer mismatch") // ErrRelayedTxV3GasLimitMismatch signals that relayed tx v3 gas limit is higher than user tx gas limit var ErrRelayedTxV3GasLimitMismatch = errors.New("relayed tx v3 gas limit mismatch") + +// ErrSubsequentInnerTransactionFailed signals that one of the following inner transactions failed +var ErrSubsequentInnerTransactionFailed = errors.New("subsequent inner transaction failed") + +// ErrInvalidInnerTransactions signals that one or more inner transactions were invalid +var ErrInvalidInnerTransactions = errors.New("invalid inner transactions") + +// ErrNilRelayedTxV3Processor signals that a nil relayed tx v3 processor has been provided +var ErrNilRelayedTxV3Processor = errors.New("nil relayed tx v3 processor") + +// ErrRelayedTxV3SenderShardMismatch signals that the sender from inner transaction is from a different shard than relayer +var ErrRelayedTxV3SenderShardMismatch = errors.New("sender shard mismatch") + +// ErrNilRelayerAccount signals that a nil relayer accouont has been provided +var ErrNilRelayerAccount = errors.New("nil relayer account") diff --git a/process/factory/interceptorscontainer/args.go b/process/factory/interceptorscontainer/args.go index 294e66290b3..0d224b031ad 100644 --- a/process/factory/interceptorscontainer/args.go +++ b/process/factory/interceptorscontainer/args.go @@ -43,4 +43,5 @@ type CommonInterceptorsContainerFactoryArgs struct { FullArchivePeerShardMapper process.PeerShardMapper HardforkTrigger heartbeat.HardforkTrigger NodeOperationMode common.NodeOperation + RelayedTxV3Processor process.RelayedTxV3Processor } diff --git a/process/factory/interceptorscontainer/metaInterceptorsContainerFactory.go b/process/factory/interceptorscontainer/metaInterceptorsContainerFactory.go index 38d3e460bce..31a4344b771 100644 --- a/process/factory/interceptorscontainer/metaInterceptorsContainerFactory.go +++ b/process/factory/interceptorscontainer/metaInterceptorsContainerFactory.go @@ -99,6 +99,7 @@ func NewMetaInterceptorsContainerFactory( SignaturesHandler: args.SignaturesHandler, HeartbeatExpiryTimespanInSec: args.HeartbeatExpiryTimespanInSec, PeerID: args.MainMessenger.ID(), + RelayedTxV3Processor: args.RelayedTxV3Processor, } base := &baseInterceptorsContainerFactory{ diff --git a/process/factory/interceptorscontainer/metaInterceptorsContainerFactory_test.go b/process/factory/interceptorscontainer/metaInterceptorsContainerFactory_test.go index c8ed20b5fad..3964342133a 100644 --- a/process/factory/interceptorscontainer/metaInterceptorsContainerFactory_test.go +++ b/process/factory/interceptorscontainer/metaInterceptorsContainerFactory_test.go @@ -18,6 +18,7 @@ import ( dataRetrieverMock "github.com/multiversx/mx-chain-go/testscommon/dataRetriever" "github.com/multiversx/mx-chain-go/testscommon/economicsmocks" "github.com/multiversx/mx-chain-go/testscommon/p2pmocks" + "github.com/multiversx/mx-chain-go/testscommon/processMocks" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" @@ -707,5 +708,6 @@ func getArgumentsMeta( FullArchivePeerShardMapper: &p2pmocks.NetworkShardingCollectorStub{}, HardforkTrigger: &testscommon.HardforkTriggerStub{}, NodeOperationMode: common.NormalOperation, + RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, } } diff --git a/process/factory/interceptorscontainer/shardInterceptorsContainerFactory.go b/process/factory/interceptorscontainer/shardInterceptorsContainerFactory.go index beef288c54c..26224fbc152 100644 --- a/process/factory/interceptorscontainer/shardInterceptorsContainerFactory.go +++ b/process/factory/interceptorscontainer/shardInterceptorsContainerFactory.go @@ -98,6 +98,7 @@ func NewShardInterceptorsContainerFactory( SignaturesHandler: args.SignaturesHandler, HeartbeatExpiryTimespanInSec: args.HeartbeatExpiryTimespanInSec, PeerID: args.MainMessenger.ID(), + RelayedTxV3Processor: args.RelayedTxV3Processor, } base := &baseInterceptorsContainerFactory{ diff --git a/process/factory/interceptorscontainer/shardInterceptorsContainerFactory_test.go b/process/factory/interceptorscontainer/shardInterceptorsContainerFactory_test.go index 24472c24f32..cf787a684a2 100644 --- a/process/factory/interceptorscontainer/shardInterceptorsContainerFactory_test.go +++ b/process/factory/interceptorscontainer/shardInterceptorsContainerFactory_test.go @@ -22,6 +22,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/p2pmocks" + "github.com/multiversx/mx-chain-go/testscommon/processMocks" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" @@ -732,5 +733,6 @@ func getArgumentsShard( MainPeerShardMapper: &p2pmocks.NetworkShardingCollectorStub{}, FullArchivePeerShardMapper: &p2pmocks.NetworkShardingCollectorStub{}, HardforkTrigger: &testscommon.HardforkTriggerStub{}, + RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, } } diff --git a/process/interceptors/factory/argInterceptedDataFactory.go b/process/interceptors/factory/argInterceptedDataFactory.go index 37701a92f7a..36ab4968375 100644 --- a/process/interceptors/factory/argInterceptedDataFactory.go +++ b/process/interceptors/factory/argInterceptedDataFactory.go @@ -57,4 +57,5 @@ type ArgInterceptedDataFactory struct { SignaturesHandler process.SignaturesHandler HeartbeatExpiryTimespanInSec int64 PeerID core.PeerID + RelayedTxV3Processor process.RelayedTxV3Processor } diff --git a/process/interceptors/factory/interceptedMetaHeaderDataFactory_test.go b/process/interceptors/factory/interceptedMetaHeaderDataFactory_test.go index 0912de698c1..edbc59757da 100644 --- a/process/interceptors/factory/interceptedMetaHeaderDataFactory_test.go +++ b/process/interceptors/factory/interceptedMetaHeaderDataFactory_test.go @@ -20,6 +20,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" + testProcessMocks "github.com/multiversx/mx-chain-go/testscommon/processMocks" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" "github.com/stretchr/testify/assert" ) @@ -106,6 +107,7 @@ func createMockArgument( SignaturesHandler: &processMocks.SignaturesHandlerStub{}, HeartbeatExpiryTimespanInSec: 30, PeerID: "pid", + RelayedTxV3Processor: &testProcessMocks.RelayedTxV3ProcessorMock{}, } } diff --git a/process/interceptors/factory/interceptedTxDataFactory.go b/process/interceptors/factory/interceptedTxDataFactory.go index 0e1a568ad53..e2dc86e599c 100644 --- a/process/interceptors/factory/interceptedTxDataFactory.go +++ b/process/interceptors/factory/interceptedTxDataFactory.go @@ -31,6 +31,7 @@ type interceptedTxDataFactory struct { txSignHasher hashing.Hasher txVersionChecker process.TxVersionCheckerHandler enableEpochsHandler common.EnableEpochsHandler + relayedTxV3Processor process.RelayedTxV3Processor } // NewInterceptedTxDataFactory creates an instance of interceptedTxDataFactory @@ -107,6 +108,7 @@ func NewInterceptedTxDataFactory(argument *ArgInterceptedDataFactory) (*intercep txSignHasher: argument.CoreComponents.TxSignHasher(), txVersionChecker: argument.CoreComponents.TxVersionChecker(), enableEpochsHandler: argument.CoreComponents.EnableEpochsHandler(), + relayedTxV3Processor: argument.RelayedTxV3Processor, } return itdf, nil @@ -131,6 +133,7 @@ func (itdf *interceptedTxDataFactory) Create(buff []byte) (process.InterceptedDa itdf.txSignHasher, itdf.txVersionChecker, itdf.enableEpochsHandler, + itdf.relayedTxV3Processor, ) } diff --git a/process/interface.go b/process/interface.go index 69b1b139e89..7003d0c632d 100644 --- a/process/interface.go +++ b/process/interface.go @@ -1358,3 +1358,11 @@ type SentSignaturesTracker interface { ResetCountersForManagedBlockSigner(signerPk []byte) IsInterfaceNil() bool } + +// RelayedTxV3Processor defines a component able to check and process relayed transactions v3 +type RelayedTxV3Processor interface { + CheckRelayedTx(tx *transaction.Transaction) error + ComputeRelayedTxFees(tx *transaction.Transaction) (*big.Int, *big.Int) + GetUniqueSendersRequiredFeesMap(innerTxs []*transaction.Transaction) map[string]*big.Int + IsInterfaceNil() bool +} diff --git a/process/transaction/baseProcess.go b/process/transaction/baseProcess.go index 4280ae54941..24e581031fa 100644 --- a/process/transaction/baseProcess.go +++ b/process/transaction/baseProcess.go @@ -146,7 +146,11 @@ func (txProc *baseTxProcessor) checkTxValues( return process.ErrNotEnoughGasInUserTx } if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { - txFee = txProc.economicsFee.ComputeTxFee(tx) + moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(tx) + gasToUse := tx.GetGasLimit() - moveBalanceGasLimit + moveBalanceUserFee := txProc.economicsFee.ComputeMoveBalanceFee(tx) + processingUserFee := txProc.economicsFee.ComputeFeeForProcessing(tx, gasToUse) + txFee = big.NewInt(0).Add(moveBalanceUserFee, processingUserFee) } else { txFee = txProc.economicsFee.ComputeFeeForProcessing(tx, tx.GasLimit) } diff --git a/process/transaction/export_test.go b/process/transaction/export_test.go index 0a20721872c..a8279814c64 100644 --- a/process/transaction/export_test.go +++ b/process/transaction/export_test.go @@ -55,9 +55,8 @@ func (txProc *txProcessor) ProcessUserTx( userTx *transaction.Transaction, relayedTxValue *big.Int, relayedNonce uint64, - txHash []byte, ) (vmcommon.ReturnCode, error) { - return txProc.processUserTx(originalTx, userTx, relayedTxValue, relayedNonce, txHash) + return txProc.processUserTx(originalTx, userTx, relayedTxValue, relayedNonce) } // ProcessMoveBalanceCostRelayedUserTx calls the un-exported method processMoveBalanceCostRelayedUserTx diff --git a/process/transaction/interceptedTransaction.go b/process/transaction/interceptedTransaction.go index 157d68cc7e3..11b7d219bc6 100644 --- a/process/transaction/interceptedTransaction.go +++ b/process/transaction/interceptedTransaction.go @@ -44,6 +44,7 @@ type InterceptedTransaction struct { isForCurrentShard bool enableSignedTxWithHash bool enableEpochsHandler common.EnableEpochsHandler + relayedTxV3Processor process.RelayedTxV3Processor } // NewInterceptedTransaction returns a new instance of InterceptedTransaction @@ -64,6 +65,7 @@ func NewInterceptedTransaction( txSignHasher hashing.Hasher, txVersionChecker process.TxVersionCheckerHandler, enableEpochsHandler common.EnableEpochsHandler, + relayedTxV3Processor process.RelayedTxV3Processor, ) (*InterceptedTransaction, error) { if txBuff == nil { @@ -111,6 +113,9 @@ func NewInterceptedTransaction( if check.IfNil(enableEpochsHandler) { return nil, process.ErrNilEnableEpochsHandler } + if check.IfNil(relayedTxV3Processor) { + return nil, process.ErrNilRelayedTxV3Processor + } tx, err := createTx(protoMarshalizer, txBuff) if err != nil { @@ -134,6 +139,7 @@ func NewInterceptedTransaction( txVersionChecker: txVersionChecker, txSignHasher: txSignHasher, enableEpochsHandler: enableEpochsHandler, + relayedTxV3Processor: relayedTxV3Processor, } err = inTx.processFields(txBuff) @@ -221,8 +227,8 @@ func (inTx *InterceptedTransaction) CheckValidity() error { return nil } -func (inTx *InterceptedTransaction) checkRecursiveRelayed(userTxData []byte, innerTx *transaction.Transaction) error { - if isRelayedV3(innerTx) { +func (inTx *InterceptedTransaction) checkRecursiveRelayed(userTxData []byte, innerTxs []*transaction.Transaction) error { + if isRelayedV3(innerTxs) { return process.ErrRecursiveRelayedTxIsNotAllowed } @@ -243,37 +249,36 @@ func isRelayedTx(funcName string) bool { core.RelayedTransactionV2 == funcName } -func isRelayedV3(innerTx *transaction.Transaction) bool { - return innerTx != nil +func isRelayedV3(innerTxs []*transaction.Transaction) bool { + return len(innerTxs) > 0 } func (inTx *InterceptedTransaction) verifyIfRelayedTxV3(tx *transaction.Transaction) error { - if tx.InnerTransaction == nil { + if len(tx.InnerTransactions) == 0 { return nil } if !inTx.enableEpochsHandler.IsFlagEnabled(common.RelayedTransactionsV3Flag) { return process.ErrRelayedTxV3Disabled } - - innerTx := tx.InnerTransaction - if !bytes.Equal(innerTx.SndAddr, tx.RcvAddr) { - return process.ErrRelayedTxV3BeneficiaryDoesNotMatchReceiver - } - if len(innerTx.RelayerAddr) == 0 { - return process.ErrRelayedTxV3EmptyRelayer - } - if !bytes.Equal(innerTx.RelayerAddr, tx.SndAddr) { - return process.ErrRelayedTxV3RelayerMismatch - } - - err := inTx.integrity(innerTx) + err := inTx.relayedTxV3Processor.CheckRelayedTx(tx) if err != nil { - return fmt.Errorf("inner transaction: %w", err) + return err } - err = inTx.verifyUserTx(innerTx) - if err != nil { - return fmt.Errorf("inner transaction: %w", err) + return inTx.verifyInnerTransactions(tx) +} + +func (inTx *InterceptedTransaction) verifyInnerTransactions(tx *transaction.Transaction) error { + for _, innerTx := range tx.InnerTransactions { + err := inTx.integrity(innerTx) + if err != nil { + return fmt.Errorf("inner transaction: %w", err) + } + + err = inTx.verifyUserTx(innerTx) + if err != nil { + return fmt.Errorf("inner transaction: %w", err) + } } return nil @@ -328,7 +333,7 @@ func (inTx *InterceptedTransaction) verifyIfRelayedTx(tx *transaction.Transactio func (inTx *InterceptedTransaction) verifyUserTx(userTx *transaction.Transaction) error { // recursive relayed transactions are not allowed - err := inTx.checkRecursiveRelayed(userTx.Data, userTx.InnerTransaction) + err := inTx.checkRecursiveRelayed(userTx.Data, userTx.InnerTransactions) if err != nil { return fmt.Errorf("inner transaction: %w", err) } diff --git a/process/transaction/interceptedTransaction_test.go b/process/transaction/interceptedTransaction_test.go index 86b9a0c4b2b..b87882023bf 100644 --- a/process/transaction/interceptedTransaction_test.go +++ b/process/transaction/interceptedTransaction_test.go @@ -26,6 +26,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" + "github.com/multiversx/mx-chain-go/testscommon/processMocks" logger "github.com/multiversx/mx-chain-logger-go" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -117,6 +118,7 @@ func createInterceptedTxWithTxFeeHandlerAndVersionChecker(tx *dataTransaction.Tr &hashingMocks.HasherMock{}, txVerChecker, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) } @@ -161,6 +163,7 @@ func createInterceptedTxFromPlainTx(tx *dataTransaction.Transaction, txFeeHandle &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(minTxVersion), &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) } @@ -205,6 +208,7 @@ func createInterceptedTxFromPlainTxWithArgParser(tx *dataTransaction.Transaction &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(tx.Version), enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV3Flag), + &processMocks.RelayedTxV3ProcessorMock{}, ) } @@ -230,6 +234,7 @@ func TestNewInterceptedTransaction_NilBufferShouldErr(t *testing.T) { &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -256,6 +261,7 @@ func TestNewInterceptedTransaction_NilArgsParser(t *testing.T) { &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -282,6 +288,7 @@ func TestNewInterceptedTransaction_NilVersionChecker(t *testing.T) { &hashingMocks.HasherMock{}, nil, &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -308,6 +315,7 @@ func TestNewInterceptedTransaction_NilMarshalizerShouldErr(t *testing.T) { &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -334,6 +342,7 @@ func TestNewInterceptedTransaction_NilSignMarshalizerShouldErr(t *testing.T) { &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -360,6 +369,7 @@ func TestNewInterceptedTransaction_NilHasherShouldErr(t *testing.T) { &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -386,6 +396,7 @@ func TestNewInterceptedTransaction_NilKeyGenShouldErr(t *testing.T) { &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -412,6 +423,7 @@ func TestNewInterceptedTransaction_NilSignerShouldErr(t *testing.T) { &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -438,6 +450,7 @@ func TestNewInterceptedTransaction_NilPubkeyConverterShouldErr(t *testing.T) { &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -464,6 +477,7 @@ func TestNewInterceptedTransaction_NilCoordinatorShouldErr(t *testing.T) { &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -490,6 +504,7 @@ func TestNewInterceptedTransaction_NilFeeHandlerShouldErr(t *testing.T) { &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -516,6 +531,7 @@ func TestNewInterceptedTransaction_NilWhiteListerVerifiedTxsShouldErr(t *testing &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -542,6 +558,7 @@ func TestNewInterceptedTransaction_InvalidChainIDShouldErr(t *testing.T) { &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -568,6 +585,7 @@ func TestNewInterceptedTransaction_NilTxSignHasherShouldErr(t *testing.T) { nil, versioning.NewTxVersionChecker(1), &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -594,12 +612,40 @@ func TestNewInterceptedTransaction_NilEnableEpochsHandlerShouldErr(t *testing.T) &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), nil, + &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) assert.Equal(t, process.ErrNilEnableEpochsHandler, err) } +func TestNewInterceptedTransaction_NilRelayedV3ProcessorShouldErr(t *testing.T) { + t.Parallel() + + txi, err := transaction.NewInterceptedTransaction( + make([]byte, 0), + &mock.MarshalizerMock{}, + &mock.MarshalizerMock{}, + &hashingMocks.HasherMock{}, + &mock.SingleSignKeyGenMock{}, + &mock.SignerMock{}, + createMockPubKeyConverter(), + mock.NewOneShardCoordinatorMock(), + &economicsmocks.EconomicsHandlerStub{}, + &testscommon.WhiteListHandlerStub{}, + &mock.ArgumentParserMock{}, + []byte("chainID"), + false, + &hashingMocks.HasherMock{}, + versioning.NewTxVersionChecker(1), + &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + nil, + ) + + assert.Nil(t, txi) + assert.Equal(t, process.ErrNilRelayedTxV3Processor, err) +} + func TestNewInterceptedTransaction_UnmarshalingTxFailsShouldErr(t *testing.T) { t.Parallel() @@ -626,6 +672,7 @@ func TestNewInterceptedTransaction_UnmarshalingTxFailsShouldErr(t *testing.T) { &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -1123,6 +1170,7 @@ func TestInterceptedTransaction_CheckValiditySignedWithHashButNotEnabled(t *test &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(minTxVersion), &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) err := txi.CheckValidity() @@ -1184,6 +1232,7 @@ func TestInterceptedTransaction_CheckValiditySignedWithHashShouldWork(t *testing &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(minTxVersion), &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) err := txi.CheckValidity() @@ -1270,6 +1319,7 @@ func TestInterceptedTransaction_ScTxDeployRecvShardIdShouldBeSendersShardId(t *t &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(minTxVersion), &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, err) @@ -1435,6 +1485,7 @@ func TestInterceptedTransaction_CheckValiditySecondTimeDoesNotVerifySig(t *testi &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(minTxVersion), &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) require.Nil(t, err) @@ -1621,16 +1672,16 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { } tx := &dataTransaction.Transaction{ - Nonce: 1, - Value: big.NewInt(0), - GasLimit: 10, - GasPrice: 4, - RcvAddr: recvAddress, - SndAddr: senderAddress, - Signature: sigOk, - ChainID: chainID, - Version: minTxVersion, - InnerTransaction: innerTx, + Nonce: 1, + Value: big.NewInt(0), + GasLimit: 10, + GasPrice: 4, + RcvAddr: senderAddress, + SndAddr: senderAddress, + Signature: sigOk, + ChainID: chainID, + Version: minTxVersion, + InnerTransactions: []*dataTransaction.Transaction{innerTx}, } t.Run("should work", func(t *testing.T) { @@ -1647,7 +1698,7 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { txCopy := *tx innerTxCopy := *innerTx innerTxCopy.RelayerAddr = nil - txCopy.InnerTransaction = &innerTxCopy + txCopy.InnerTransactions = []*dataTransaction.Transaction{&innerTxCopy} txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) err := txi.CheckValidity() @@ -1659,22 +1710,22 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { txCopy := *tx innerTxCopy := *innerTx innerTxCopy.RelayerAddr = []byte("34567890123456789012345678901234") - txCopy.InnerTransaction = &innerTxCopy + txCopy.InnerTransactions = []*dataTransaction.Transaction{&innerTxCopy} txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) err := txi.CheckValidity() assert.Equal(t, process.ErrRelayedTxV3RelayerMismatch, err) }) - t.Run("different sender on inner tx should error", func(t *testing.T) { + t.Run("different sender than receiver should error", func(t *testing.T) { t.Parallel() txCopy := *tx innerTxCopy := *innerTx - innerTxCopy.SndAddr = []byte("34567890123456789012345678901234") - txCopy.InnerTransaction = &innerTxCopy + txCopy.RcvAddr = []byte("34567890123456789012345678901234") + txCopy.InnerTransactions = []*dataTransaction.Transaction{&innerTxCopy} txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) err := txi.CheckValidity() - assert.Equal(t, process.ErrRelayedTxV3BeneficiaryDoesNotMatchReceiver, err) + assert.Equal(t, process.ErrRelayedTxV3SenderDoesNotMatchReceiver, err) }) t.Run("empty signature on inner tx should error", func(t *testing.T) { t.Parallel() @@ -1682,7 +1733,7 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { txCopy := *tx innerTxCopy := *innerTx innerTxCopy.Signature = nil - txCopy.InnerTransaction = &innerTxCopy + txCopy.InnerTransactions = []*dataTransaction.Transaction{&innerTxCopy} txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) err := txi.CheckValidity() assert.NotNil(t, err) @@ -1693,7 +1744,7 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { txCopy := *tx innerTxCopy := *innerTx innerTxCopy.Signature = sigBad - txCopy.InnerTransaction = &innerTxCopy + txCopy.InnerTransactions = []*dataTransaction.Transaction{&innerTxCopy} txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) err := txi.CheckValidity() assert.NotNil(t, err) @@ -1703,7 +1754,7 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { txCopy := *tx innerTxCopy := *innerTx - txCopy.InnerTransaction = &innerTxCopy + txCopy.InnerTransactions = []*dataTransaction.Transaction{&innerTxCopy} innerTx2 := &dataTransaction.Transaction{ Nonce: 2, Value: big.NewInt(3), @@ -1716,7 +1767,7 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { ChainID: chainID, Version: minTxVersion, } - innerTxCopy.InnerTransaction = innerTx2 + innerTxCopy.InnerTransactions = []*dataTransaction.Transaction{innerTx2} txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) err := txi.CheckValidity() assert.NotNil(t, err) @@ -1727,7 +1778,7 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { txCopy := *tx innerTxCopy := *innerTx - txCopy.InnerTransaction = &innerTxCopy + txCopy.InnerTransactions = []*dataTransaction.Transaction{&innerTxCopy} marshalizer := &mock.MarshalizerMock{} txBuff, _ := marshalizer.Marshal(&txCopy) txi, _ := transaction.NewInterceptedTransaction( @@ -1751,6 +1802,7 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(0), &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) assert.NotNil(t, txi) @@ -1889,6 +1941,7 @@ func TestInterceptedTransaction_Fee(t *testing.T) { &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(0), &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Equal(t, big.NewInt(0), txin.Fee()) @@ -1933,6 +1986,7 @@ func TestInterceptedTransaction_String(t *testing.T) { &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(0), &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + &processMocks.RelayedTxV3ProcessorMock{}, ) expectedFormat := fmt.Sprintf( diff --git a/process/transaction/relayedTxV3Processor.go b/process/transaction/relayedTxV3Processor.go new file mode 100644 index 00000000000..1574ce41a86 --- /dev/null +++ b/process/transaction/relayedTxV3Processor.go @@ -0,0 +1,134 @@ +package transaction + +import ( + "bytes" + "math/big" + + "github.com/multiversx/mx-chain-core-go/core/check" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/sharding" +) + +type relayedTxV3Processor struct { + economicsFee process.FeeHandler + shardCoordinator sharding.Coordinator +} + +// NewRelayedTxV3Processor returns a new instance of relayedTxV3Processor +func NewRelayedTxV3Processor(economicsFee process.FeeHandler, shardCoordinator sharding.Coordinator) (*relayedTxV3Processor, error) { + if check.IfNil(economicsFee) { + return nil, process.ErrNilEconomicsFeeHandler + } + if check.IfNil(shardCoordinator) { + return nil, process.ErrNilShardCoordinator + } + + return &relayedTxV3Processor{ + economicsFee: economicsFee, + shardCoordinator: shardCoordinator, + }, nil +} + +// CheckRelayedTx checks the relayed transaction and its inner transactions +func (proc *relayedTxV3Processor) CheckRelayedTx(tx *transaction.Transaction) error { + if tx.GetValue().Cmp(big.NewInt(0)) != 0 { + return process.ErrRelayedTxV3ZeroVal + } + if !bytes.Equal(tx.RcvAddr, tx.SndAddr) { + return process.ErrRelayedTxV3SenderDoesNotMatchReceiver + } + if tx.GasLimit < proc.computeRelayedTxMinGasLimit(tx) { + return process.ErrRelayedTxV3GasLimitMismatch + } + + innerTxs := tx.InnerTransactions + for _, innerTx := range innerTxs { + if len(innerTx.RelayerAddr) == 0 { + return process.ErrRelayedTxV3EmptyRelayer + } + if !bytes.Equal(innerTx.RelayerAddr, tx.SndAddr) { + return process.ErrRelayedTxV3RelayerMismatch + } + if tx.GasPrice != innerTx.GasPrice { + return process.ErrRelayedV3GasPriceMismatch + } + + senderShard := proc.shardCoordinator.ComputeId(innerTx.SndAddr) + relayerShard := proc.shardCoordinator.ComputeId(innerTx.RelayerAddr) + if senderShard != relayerShard { + return process.ErrRelayedTxV3SenderShardMismatch + } + } + + return nil +} + +// ComputeRelayedTxFees returns the both the total fee for the entire relayed tx and the relayed only fee +func (proc *relayedTxV3Processor) ComputeRelayedTxFees(tx *transaction.Transaction) (*big.Int, *big.Int) { + relayerMoveBalanceFee := proc.economicsFee.ComputeMoveBalanceFee(tx) + uniqueSenders := proc.GetUniqueSendersRequiredFeesMap(tx.InnerTransactions) + + relayerFee := big.NewInt(0).Mul(relayerMoveBalanceFee, big.NewInt(int64(len(uniqueSenders)))) + + totalFee := big.NewInt(0) + for _, fee := range uniqueSenders { + totalFee.Add(totalFee, fee) + } + totalFee.Add(totalFee, relayerFee) + + return relayerFee, totalFee +} + +// GetUniqueSendersRequiredFeesMap returns the map of unique inner transactions senders and the required fees for all transactions +func (proc *relayedTxV3Processor) GetUniqueSendersRequiredFeesMap(innerTxs []*transaction.Transaction) map[string]*big.Int { + uniqueSendersMap := make(map[string]*big.Int) + for _, innerTx := range innerTxs { + senderStr := string(innerTx.SndAddr) + _, exists := uniqueSendersMap[senderStr] + if !exists { + uniqueSendersMap[senderStr] = big.NewInt(0) + } + + gasToUse := innerTx.GetGasLimit() - proc.economicsFee.ComputeGasLimit(innerTx) + moveBalanceUserFee := proc.economicsFee.ComputeMoveBalanceFee(innerTx) + processingUserFee := proc.economicsFee.ComputeFeeForProcessing(innerTx, gasToUse) + innerTxFee := big.NewInt(0).Add(moveBalanceUserFee, processingUserFee) + + uniqueSendersMap[senderStr].Add(uniqueSendersMap[senderStr], innerTxFee) + } + + return uniqueSendersMap +} + +func (proc *relayedTxV3Processor) computeRelayedTxMinGasLimit(tx *transaction.Transaction) uint64 { + relayedTxGasLimit := proc.economicsFee.ComputeGasLimit(tx) + uniqueSenders := proc.getUniqueSendersRequiredGasLimitsMap(tx.InnerTransactions) + + totalGasLimit := relayedTxGasLimit * uint64(len(uniqueSenders)) + for _, gasLimit := range uniqueSenders { + totalGasLimit += gasLimit + } + + return totalGasLimit +} + +func (proc *relayedTxV3Processor) getUniqueSendersRequiredGasLimitsMap(innerTxs []*transaction.Transaction) map[string]uint64 { + uniqueSendersMap := make(map[string]uint64) + for _, innerTx := range innerTxs { + senderStr := string(innerTx.SndAddr) + _, exists := uniqueSendersMap[senderStr] + if !exists { + uniqueSendersMap[senderStr] = 0 + } + + uniqueSendersMap[senderStr] += innerTx.GasLimit + } + + return uniqueSendersMap +} + +// IsInterfaceNil returns true if there is no value under the interface +func (proc *relayedTxV3Processor) IsInterfaceNil() bool { + return proc == nil +} diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index da1ea63baf3..3d50cea16a5 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -37,38 +37,40 @@ type relayedFees struct { // txProcessor implements TransactionProcessor interface and can modify account states according to a transaction type txProcessor struct { *baseTxProcessor - txFeeHandler process.TransactionFeeHandler - txTypeHandler process.TxTypeHandler - receiptForwarder process.IntermediateTransactionHandler - badTxForwarder process.IntermediateTransactionHandler - argsParser process.ArgumentsParser - scrForwarder process.IntermediateTransactionHandler - signMarshalizer marshal.Marshalizer - enableEpochsHandler common.EnableEpochsHandler - txLogsProcessor process.TransactionLogProcessor + txFeeHandler process.TransactionFeeHandler + txTypeHandler process.TxTypeHandler + receiptForwarder process.IntermediateTransactionHandler + badTxForwarder process.IntermediateTransactionHandler + argsParser process.ArgumentsParser + scrForwarder process.IntermediateTransactionHandler + signMarshalizer marshal.Marshalizer + enableEpochsHandler common.EnableEpochsHandler + txLogsProcessor process.TransactionLogProcessor + relayedTxV3Processor process.RelayedTxV3Processor } // ArgsNewTxProcessor defines the arguments needed for new tx processor type ArgsNewTxProcessor struct { - Accounts state.AccountsAdapter - Hasher hashing.Hasher - PubkeyConv core.PubkeyConverter - Marshalizer marshal.Marshalizer - SignMarshalizer marshal.Marshalizer - ShardCoordinator sharding.Coordinator - ScProcessor process.SmartContractProcessor - TxFeeHandler process.TransactionFeeHandler - TxTypeHandler process.TxTypeHandler - EconomicsFee process.FeeHandler - ReceiptForwarder process.IntermediateTransactionHandler - BadTxForwarder process.IntermediateTransactionHandler - ArgsParser process.ArgumentsParser - ScrForwarder process.IntermediateTransactionHandler - EnableRoundsHandler process.EnableRoundsHandler - EnableEpochsHandler common.EnableEpochsHandler - TxVersionChecker process.TxVersionCheckerHandler - GuardianChecker process.GuardianChecker - TxLogsProcessor process.TransactionLogProcessor + Accounts state.AccountsAdapter + Hasher hashing.Hasher + PubkeyConv core.PubkeyConverter + Marshalizer marshal.Marshalizer + SignMarshalizer marshal.Marshalizer + ShardCoordinator sharding.Coordinator + ScProcessor process.SmartContractProcessor + TxFeeHandler process.TransactionFeeHandler + TxTypeHandler process.TxTypeHandler + EconomicsFee process.FeeHandler + ReceiptForwarder process.IntermediateTransactionHandler + BadTxForwarder process.IntermediateTransactionHandler + ArgsParser process.ArgumentsParser + ScrForwarder process.IntermediateTransactionHandler + EnableRoundsHandler process.EnableRoundsHandler + EnableEpochsHandler common.EnableEpochsHandler + TxVersionChecker process.TxVersionCheckerHandler + GuardianChecker process.GuardianChecker + TxLogsProcessor process.TransactionLogProcessor + RelayedTxV3Processor process.RelayedTxV3Processor } // NewTxProcessor creates a new txProcessor engine @@ -143,6 +145,9 @@ func NewTxProcessor(args ArgsNewTxProcessor) (*txProcessor, error) { if check.IfNil(args.TxLogsProcessor) { return nil, process.ErrNilTxLogsProcessor } + if check.IfNil(args.RelayedTxV3Processor) { + return nil, process.ErrNilRelayedTxV3Processor + } baseTxProcess := &baseTxProcessor{ accounts: args.Accounts, @@ -158,16 +163,17 @@ func NewTxProcessor(args ArgsNewTxProcessor) (*txProcessor, error) { } txProc := &txProcessor{ - baseTxProcessor: baseTxProcess, - txFeeHandler: args.TxFeeHandler, - txTypeHandler: args.TxTypeHandler, - receiptForwarder: args.ReceiptForwarder, - badTxForwarder: args.BadTxForwarder, - argsParser: args.ArgsParser, - scrForwarder: args.ScrForwarder, - signMarshalizer: args.SignMarshalizer, - enableEpochsHandler: args.EnableEpochsHandler, - txLogsProcessor: args.TxLogsProcessor, + baseTxProcessor: baseTxProcess, + txFeeHandler: args.TxFeeHandler, + txTypeHandler: args.TxTypeHandler, + receiptForwarder: args.ReceiptForwarder, + badTxForwarder: args.BadTxForwarder, + argsParser: args.ArgsParser, + scrForwarder: args.ScrForwarder, + signMarshalizer: args.SignMarshalizer, + enableEpochsHandler: args.EnableEpochsHandler, + txLogsProcessor: args.TxLogsProcessor, + relayedTxV3Processor: args.RelayedTxV3Processor, } return txProc, nil @@ -242,7 +248,7 @@ func (txProc *txProcessor) ProcessTransaction(tx *transaction.Transaction) (vmco case process.RelayedTxV2: return txProc.processRelayedTxV2(tx, acntSnd, acntDst) case process.RelayedTxV3: - return txProc.processRelayedTxV3(tx, acntSnd, acntDst) + return txProc.processRelayedTxV3(tx, acntSnd) } return vmcommon.UserError, txProc.executingFailedTransaction(tx, acntSnd, process.ErrWrongTransaction) @@ -298,7 +304,14 @@ func (txProc *txProcessor) executingFailedTransaction( return nil } - txFee := txProc.economicsFee.ComputeTxFee(tx) + txFee := txProc.economicsFee.ComputeFeeForProcessing(tx, tx.GasLimit) + if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { + moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(tx) + gasToUse := tx.GetGasLimit() - moveBalanceGasLimit + moveBalanceUserFee := txProc.economicsFee.ComputeMoveBalanceFee(tx) + processingUserFee := txProc.economicsFee.ComputeFeeForProcessing(tx, gasToUse) + txFee = big.NewInt(0).Add(moveBalanceUserFee, processingUserFee) + } err := acntSnd.SubFromBalance(txFee) if err != nil { return err @@ -391,7 +404,11 @@ func (txProc *txProcessor) processTxFee( if isUserTxOfRelayed { totalCost := txProc.economicsFee.ComputeFeeForProcessing(tx, tx.GasLimit) if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { - totalCost = txProc.economicsFee.ComputeTxFee(tx) + moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(tx) + gasToUse := tx.GetGasLimit() - moveBalanceGasLimit + moveBalanceUserFee := txProc.economicsFee.ComputeMoveBalanceFee(tx) + processingUserFee := txProc.economicsFee.ComputeFeeForProcessing(tx, gasToUse) + totalCost = big.NewInt(0).Add(moveBalanceUserFee, processingUserFee) } err := acntSnd.SubFromBalance(totalCost) if err != nil { @@ -566,7 +583,7 @@ func (txProc *txProcessor) finishExecutionOfRelayedTx( userTx *transaction.Transaction, ) (vmcommon.ReturnCode, error) { computedFees := txProc.computeRelayedTxFees(tx, userTx) - txHash, err := txProc.processTxAtRelayer(relayerAcnt, computedFees.totalFee, computedFees.relayerFee, tx) + err := txProc.processTxAtRelayer(relayerAcnt, computedFees.totalFee, computedFees.relayerFee, tx) if err != nil { return 0, err } @@ -580,7 +597,7 @@ func (txProc *txProcessor) finishExecutionOfRelayedTx( return 0, err } - return txProc.processUserTx(tx, userTx, tx.Value, tx.Nonce, txHash) + return txProc.processUserTx(tx, userTx, tx.Value, tx.Nonce) } func (txProc *txProcessor) processTxAtRelayer( @@ -588,33 +605,33 @@ func (txProc *txProcessor) processTxAtRelayer( totalFee *big.Int, relayerFee *big.Int, tx *transaction.Transaction, -) ([]byte, error) { - txHash, err := core.CalculateHash(txProc.marshalizer, txProc.hasher, tx) - if err != nil { - return nil, err - } - +) error { if !check.IfNil(relayerAcnt) { - err = relayerAcnt.SubFromBalance(tx.GetValue()) + err := relayerAcnt.SubFromBalance(tx.GetValue()) if err != nil { - return nil, err + return err } err = relayerAcnt.SubFromBalance(totalFee) if err != nil { - return nil, err + return err } relayerAcnt.IncreaseNonce(1) err = txProc.accounts.SaveAccount(relayerAcnt) if err != nil { - return nil, err + return err + } + + txHash, err := core.CalculateHash(txProc.marshalizer, txProc.hasher, tx) + if err != nil { + return err } txProc.txFeeHandler.ProcessTransactionFee(relayerFee, big.NewInt(0), txHash) } - return txHash, nil + return nil } func (txProc *txProcessor) addFeeAndValueToDest(acntDst state.UserAccountHandler, tx *transaction.Transaction, remainingFee *big.Int) error { @@ -633,34 +650,116 @@ func (txProc *txProcessor) addFeeAndValueToDest(acntDst state.UserAccountHandler func (txProc *txProcessor) processRelayedTxV3( tx *transaction.Transaction, - relayerAcnt, acntDst state.UserAccountHandler, + relayerAcnt state.UserAccountHandler, ) (vmcommon.ReturnCode, error) { if !txProc.enableEpochsHandler.IsFlagEnabled(common.RelayedTransactionsV3Flag) { return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedTxV3Disabled) } - if tx.GetValue().Cmp(big.NewInt(0)) != 0 { - return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedTxV3ZeroVal) + if check.IfNil(relayerAcnt) { + return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrNilRelayerAccount) + } + err := txProc.relayedTxV3Processor.CheckRelayedTx(tx) + if err != nil { + return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, err) } - userTx := tx.GetInnerTransaction() - if !bytes.Equal(tx.RcvAddr, userTx.SndAddr) { - return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedTxV3BeneficiaryDoesNotMatchReceiver) + // process fees on both relayer and sender + sendersBalancesSnapshot, err := txProc.processInnerTxsFeesAfterSnapshot(tx, relayerAcnt) + if err != nil { + txProc.resetBalancesToSnapshot(sendersBalancesSnapshot) + return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, err) } - if len(userTx.RelayerAddr) == 0 { - return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedTxV3EmptyRelayer) + + innerTxs := tx.GetInnerTransactions() + + var innerTxRetCode vmcommon.ReturnCode + var innerTxErr error + executedUserTxs := make([]*transaction.Transaction, 0) + for _, innerTx := range innerTxs { + innerTxRetCode, innerTxErr = txProc.finishExecutionOfInnerTx(tx, innerTx) + if innerTxErr != nil || innerTxRetCode != vmcommon.Ok { + break + } + + executedUserTxs = append(executedUserTxs, innerTx) } - if !bytes.Equal(userTx.RelayerAddr, tx.SndAddr) { - return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedTxV3RelayerMismatch) + + allUserTxsSucceeded := len(executedUserTxs) == len(innerTxs) && innerTxErr == nil && innerTxRetCode == vmcommon.Ok + // if all user transactions were executed, return success + if allUserTxsSucceeded { + return vmcommon.Ok, nil } - if tx.GasPrice != userTx.GasPrice { - return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedV3GasPriceMismatch) + + defer func() { + // reset all senders to the snapshot took before starting the execution + txProc.resetBalancesToSnapshot(sendersBalancesSnapshot) + }() + + // if the first one failed, return last error + // the current transaction should have been already reverted + if len(executedUserTxs) == 0 { + return innerTxRetCode, innerTxErr } - remainingGasLimit := tx.GasLimit - txProc.economicsFee.ComputeGasLimit(tx) - if userTx.GasLimit != remainingGasLimit { - return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedTxV3GasLimitMismatch) + + originalTxHash, err := core.CalculateHash(txProc.marshalizer, txProc.hasher, tx) + if err != nil { + return vmcommon.UserError, err } - return txProc.finishExecutionOfRelayedTx(relayerAcnt, acntDst, tx, userTx) + defer func() { + executedHashed := make([][]byte, 0) + for _, executedUserTx := range executedUserTxs { + txHash, errHash := core.CalculateHash(txProc.marshalizer, txProc.hasher, executedUserTx) + if errHash != nil { + continue + } + executedHashed = append(executedHashed, txHash) + } + + txProc.txFeeHandler.RevertFees(executedHashed) + }() + + // if one or more user transactions were executed before one of them failed, revert all, including the fees transferred + // the current transaction should have been already reverted + var lastErr error + revertedTxsCnt := 0 + for _, executedUserTx := range executedUserTxs { + errRemove := txProc.removeValueAndConsumedFeeFromUser(executedUserTx, tx.Value, originalTxHash, tx, process.ErrSubsequentInnerTransactionFailed) + if errRemove != nil { + lastErr = errRemove + continue + } + + revertedTxsCnt++ + } + + if lastErr != nil { + log.Warn("failed to revert all previous executed inner transactions, last error = %w, "+ + "total transactions = %d, num of transactions reverted = %d", + lastErr, + len(executedUserTxs), + revertedTxsCnt) + + return vmcommon.UserError, lastErr + } + + return vmcommon.UserError, process.ErrInvalidInnerTransactions +} + +func (txProc *txProcessor) finishExecutionOfInnerTx( + tx *transaction.Transaction, + innerTx *transaction.Transaction, +) (vmcommon.ReturnCode, error) { + acntSnd, err := txProc.getAccountFromAddress(innerTx.SndAddr) + if err != nil { + return vmcommon.UserError, err + } + + if check.IfNil(acntSnd) { + return vmcommon.Ok, nil + } + + return txProc.processUserTx(tx, innerTx, tx.Value, tx.Nonce) } func (txProc *txProcessor) processRelayedTxV2( @@ -734,7 +833,12 @@ func (txProc *txProcessor) computeRelayedTxFees(tx, userTx *transaction.Transact relayerFee := txProc.economicsFee.ComputeMoveBalanceFee(tx) totalFee := txProc.economicsFee.ComputeTxFee(tx) if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { - userFee := txProc.economicsFee.ComputeTxFee(userTx) + moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(userTx) + gasToUse := userTx.GetGasLimit() - moveBalanceGasLimit + moveBalanceUserFee := txProc.economicsFee.ComputeMoveBalanceFee(userTx) + processingUserFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, gasToUse) + userFee := big.NewInt(0).Add(moveBalanceUserFee, processingUserFee) + totalFee = totalFee.Add(relayerFee, userFee) } remainingFee := big.NewInt(0).Sub(totalFee, relayerFee) @@ -769,7 +873,11 @@ func (txProc *txProcessor) removeValueAndConsumedFeeFromUser( consumedFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, userTx.GasLimit) if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { - consumedFee = txProc.economicsFee.ComputeTxFee(userTx) + moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(userTx) + gasToUse := userTx.GetGasLimit() - moveBalanceGasLimit + moveBalanceUserFee := txProc.economicsFee.ComputeMoveBalanceFee(userTx) + processingUserFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, gasToUse) + consumedFee = big.NewInt(0).Add(moveBalanceUserFee, processingUserFee) } err = userAcnt.SubFromBalance(consumedFee) if err != nil { @@ -815,7 +923,10 @@ func (txProc *txProcessor) processMoveBalanceCostRelayedUserTx( moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(userTx) moveBalanceUserFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, moveBalanceGasLimit) if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { + gasToUse := userTx.GetGasLimit() - moveBalanceGasLimit moveBalanceUserFee = txProc.economicsFee.ComputeMoveBalanceFee(userTx) + processingUserFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, gasToUse) + moveBalanceUserFee = moveBalanceUserFee.Add(moveBalanceUserFee, processingUserFee) } userScrHash, err := core.CalculateHash(txProc.marshalizer, txProc.hasher, userScr) @@ -832,7 +943,6 @@ func (txProc *txProcessor) processUserTx( userTx *transaction.Transaction, relayedTxValue *big.Int, relayedNonce uint64, - txHash []byte, ) (vmcommon.ReturnCode, error) { acntSnd, acntDst, err := txProc.getAccounts(userTx.SndAddr, userTx.RcvAddr) @@ -860,11 +970,11 @@ func (txProc *txProcessor) processUserTx( relayedTxValue, relayedNonce, originalTx, - txHash, + originalTxHash, err.Error()) } - scrFromTx, err := txProc.makeSCRFromUserTx(userTx, relayerAdr, relayedTxValue, txHash) + scrFromTx, err := txProc.makeSCRFromUserTx(userTx, relayerAdr, relayedTxValue, originalTxHash, false) if err != nil { return 0, err } @@ -906,7 +1016,7 @@ func (txProc *txProcessor) processUserTx( relayedTxValue, relayedNonce, originalTx, - txHash, + originalTxHash, err.Error()) } @@ -917,7 +1027,7 @@ func (txProc *txProcessor) processUserTx( relayedTxValue, relayedNonce, originalTx, - txHash, + originalTxHash, err.Error()) } @@ -963,10 +1073,15 @@ func (txProc *txProcessor) makeSCRFromUserTx( relayerAdr []byte, relayedTxValue *big.Int, txHash []byte, + isRevertSCR bool, ) (*smartContractResult.SmartContractResult, error) { + scrValue := tx.Value + if isRevertSCR { + scrValue = big.NewInt(0).Neg(tx.Value) + } scr := &smartContractResult.SmartContractResult{ Nonce: tx.Nonce, - Value: tx.Value, + Value: scrValue, RcvAddr: tx.RcvAddr, SndAddr: tx.SndAddr, RelayerAddr: relayerAdr, @@ -1018,15 +1133,22 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( } totalFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, userTx.GasLimit) + moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(userTx) + gasToUse := userTx.GetGasLimit() - moveBalanceGasLimit + processingUserFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, gasToUse) if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { - totalFee = txProc.economicsFee.ComputeTxFee(userTx) + moveBalanceUserFee := txProc.economicsFee.ComputeMoveBalanceFee(userTx) + totalFee = big.NewInt(0).Add(moveBalanceUserFee, processingUserFee) } senderShardID := txProc.shardCoordinator.ComputeId(userTx.SndAddr) if senderShardID != txProc.shardCoordinator.SelfId() { - moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(userTx) - moveBalanceUserFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, moveBalanceGasLimit) - totalFee.Sub(totalFee, moveBalanceUserFee) + if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { + totalFee.Sub(totalFee, processingUserFee) + } else { + moveBalanceUserFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, moveBalanceGasLimit) + totalFee.Sub(totalFee, moveBalanceUserFee) + } } txProc.txFeeHandler.ProcessTransactionFee(totalFee, big.NewInt(0), originalTxHash) @@ -1071,6 +1193,90 @@ func isNonExecutableError(executionErr error) bool { errors.Is(executionErr, process.ErrTransactionNotExecutable) } +func (txProc *txProcessor) processInnerTxsFeesAfterSnapshot(tx *transaction.Transaction, relayerAcnt state.UserAccountHandler) (map[state.UserAccountHandler]*big.Int, error) { + relayerFee, totalFee := txProc.relayedTxV3Processor.ComputeRelayedTxFees(tx) + err := txProc.processTxAtRelayer(relayerAcnt, totalFee, relayerFee, tx) + if err != nil { + return make(map[state.UserAccountHandler]*big.Int), err + } + + uniqueSendersMap := txProc.relayedTxV3Processor.GetUniqueSendersRequiredFeesMap(tx.InnerTransactions) + uniqueSendersSlice := mapToSlice(uniqueSendersMap) + sendersBalancesSnapshot := make(map[state.UserAccountHandler]*big.Int, len(uniqueSendersMap)) + var lastTransferErr error + for _, uniqueSender := range uniqueSendersSlice { + totalFeesForSender := uniqueSendersMap[uniqueSender] + senderAcnt, prevBalanceForSender, err := txProc.addFeesToDest([]byte(uniqueSender), totalFeesForSender) + if err != nil { + lastTransferErr = err + break + } + + sendersBalancesSnapshot[senderAcnt] = prevBalanceForSender + } + + // if one error occurred, revert all transfers that succeeded and return error + //if lastTransferErr != nil { + // for i := 0; i < lastIdx; i++ { + // uniqueSender := uniqueSendersSlice[i] + // totalFessSentForSender := uniqueSendersMap[uniqueSender] + // _, _, err = txProc.addFeesToDest([]byte(uniqueSender), big.NewInt(0).Neg(totalFessSentForSender)) + // if err != nil { + // log.Warn("could not revert the fees transferred from relayer to sender", + // "sender", txProc.pubkeyConv.SilentEncode([]byte(uniqueSender), log), + // "relayer", txProc.pubkeyConv.SilentEncode(relayerAcnt.AddressBytes(), log)) + // } + // } + //} + + return sendersBalancesSnapshot, lastTransferErr +} + +func (txProc *txProcessor) addFeesToDest(dstAddr []byte, feesForAllInnerTxs *big.Int) (state.UserAccountHandler, *big.Int, error) { + acntDst, err := txProc.getAccountFromAddress(dstAddr) + if err != nil { + return nil, nil, err + } + + if check.IfNil(acntDst) { + return nil, nil, nil + } + + prevBalance := acntDst.GetBalance() + err = acntDst.AddToBalance(feesForAllInnerTxs) + if err != nil { + return nil, nil, err + } + + return acntDst, prevBalance, txProc.accounts.SaveAccount(acntDst) +} + +func (txProc *txProcessor) resetBalancesToSnapshot(snapshot map[state.UserAccountHandler]*big.Int) { + for acnt, prevBalance := range snapshot { + currentBalance := acnt.GetBalance() + diff := big.NewInt(0).Sub(currentBalance, prevBalance) + err := acnt.SubFromBalance(diff) + if err != nil { + log.Warn("could not reset sender to snapshot", "sender", txProc.pubkeyConv.SilentEncode(acnt.AddressBytes(), log)) + continue + } + + err = txProc.accounts.SaveAccount(acnt) + if err != nil { + log.Warn("could not save account while resetting sender to snapshot", "sender", txProc.pubkeyConv.SilentEncode(acnt.AddressBytes(), log)) + } + } +} + +func mapToSlice(initialMap map[string]*big.Int) []string { + newSlice := make([]string, 0, len(initialMap)) + for mapKey := range initialMap { + newSlice = append(newSlice, mapKey) + } + + return newSlice +} + // IsInterfaceNil returns true if there is no value under the interface func (txProc *txProcessor) IsInterfaceNil() bool { return txProc == nil diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index 23483c6bb69..a58e3080b1f 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -26,6 +26,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/guardianMocks" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" + "github.com/multiversx/mx-chain-go/testscommon/processMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" "github.com/multiversx/mx-chain-go/vm" vmcommon "github.com/multiversx/mx-chain-vm-common-go" @@ -74,25 +75,26 @@ func createAccountStub(sndAddr, rcvAddr []byte, func createArgsForTxProcessor() txproc.ArgsNewTxProcessor { args := txproc.ArgsNewTxProcessor{ - Accounts: &stateMock.AccountsStub{}, - Hasher: &hashingMocks.HasherMock{}, - PubkeyConv: createMockPubKeyConverter(), - Marshalizer: &mock.MarshalizerMock{}, - SignMarshalizer: &mock.MarshalizerMock{}, - ShardCoordinator: mock.NewOneShardCoordinatorMock(), - ScProcessor: &testscommon.SCProcessorMock{}, - TxFeeHandler: &mock.FeeAccumulatorStub{}, - TxTypeHandler: &testscommon.TxTypeHandlerMock{}, - EconomicsFee: feeHandlerMock(), - ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, - BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, - ArgsParser: &mock.ArgumentParserMock{}, - ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, - EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.PenalizedTooMuchGasFlag, common.FixRelayedMoveBalanceFlag), - GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, - TxVersionChecker: &testscommon.TxVersionCheckerStub{}, - TxLogsProcessor: &mock.TxLogsProcessorStub{}, - EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, + Accounts: &stateMock.AccountsStub{}, + Hasher: &hashingMocks.HasherMock{}, + PubkeyConv: createMockPubKeyConverter(), + Marshalizer: &mock.MarshalizerMock{}, + SignMarshalizer: &mock.MarshalizerMock{}, + ShardCoordinator: mock.NewOneShardCoordinatorMock(), + ScProcessor: &testscommon.SCProcessorMock{}, + TxFeeHandler: &mock.FeeAccumulatorStub{}, + TxTypeHandler: &testscommon.TxTypeHandlerMock{}, + EconomicsFee: feeHandlerMock(), + ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, + BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, + ArgsParser: &mock.ArgumentParserMock{}, + ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.PenalizedTooMuchGasFlag, common.FixRelayedMoveBalanceFlag), + GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, + TxVersionChecker: &testscommon.TxVersionCheckerStub{}, + TxLogsProcessor: &mock.TxLogsProcessorStub{}, + EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, + RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, } return args } @@ -302,6 +304,17 @@ func TestNewTxProcessor_NilEnableRoundsHandlerShouldErr(t *testing.T) { assert.Nil(t, txProc) } +func TestNewTxProcessor_NilRelayedTxV3ProcessorShouldErr(t *testing.T) { + t.Parallel() + + args := createArgsForTxProcessor() + args.RelayedTxV3Processor = nil + txProc, err := txproc.NewTxProcessor(args) + + assert.Equal(t, process.ErrNilRelayedTxV3Processor, err) + assert.Nil(t, txProc) +} + func TestNewTxProcessor_OkValsShouldWork(t *testing.T) { t.Parallel() @@ -2026,7 +2039,7 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { tx := &transaction.Transaction{} tx.Nonce = 0 tx.SndAddr = []byte("sSRC") - tx.RcvAddr = userAddr + tx.RcvAddr = []byte("sSRC") tx.Value = big.NewInt(0) tx.GasPrice = 1 tx.GasLimit = 8 @@ -2041,7 +2054,7 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { userTx.GasLimit = 4 userTx.RelayerAddr = tx.SndAddr - tx.InnerTransaction = userTx + tx.InnerTransactions = []*transaction.Transaction{userTx} t.Run("flag not active should error", func(t *testing.T) { t.Parallel() @@ -2102,14 +2115,14 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { txCopy := *tx txCopy.Value = big.NewInt(1) - testProcessRelayedTransactionV3(t, &txCopy, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) + testProcessRelayedTransactionV3(t, &txCopy, userTx.SndAddr, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) }) - t.Run("different sender on inner tx should error", func(t *testing.T) { + t.Run("different receiver on tx should error", func(t *testing.T) { t.Parallel() txCopy := *tx - txCopy.RcvAddr = userTx.RcvAddr - testProcessRelayedTransactionV3(t, &txCopy, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) + txCopy.RcvAddr = userTx.SndAddr + testProcessRelayedTransactionV3(t, &txCopy, userTx.SndAddr, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) }) t.Run("empty relayer on inner tx should error", func(t *testing.T) { t.Parallel() @@ -2117,8 +2130,8 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { txCopy := *tx userTxCopy := *userTx userTxCopy.RelayerAddr = nil - txCopy.InnerTransaction = &userTxCopy - testProcessRelayedTransactionV3(t, &txCopy, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) + txCopy.InnerTransactions = []*transaction.Transaction{&userTxCopy} + testProcessRelayedTransactionV3(t, &txCopy, userTx.SndAddr, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) }) t.Run("different relayer on inner tx should error", func(t *testing.T) { t.Parallel() @@ -2126,32 +2139,33 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { txCopy := *tx userTxCopy := *userTx userTxCopy.RelayerAddr = []byte("other") - txCopy.InnerTransaction = &userTxCopy - testProcessRelayedTransactionV3(t, &txCopy, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) + txCopy.InnerTransactions = []*transaction.Transaction{&userTxCopy} + testProcessRelayedTransactionV3(t, &txCopy, userTx.SndAddr, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) }) t.Run("different gas price on inner tx should error", func(t *testing.T) { t.Parallel() txCopy := *tx txCopy.GasPrice = userTx.GasPrice + 1 - testProcessRelayedTransactionV3(t, &txCopy, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) + testProcessRelayedTransactionV3(t, &txCopy, userTx.SndAddr, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) }) t.Run("higher gas limit on inner tx should error", func(t *testing.T) { t.Parallel() txCopy := *tx txCopy.GasLimit = userTx.GasLimit - 1 - testProcessRelayedTransactionV3(t, &txCopy, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) + testProcessRelayedTransactionV3(t, &txCopy, userTx.SndAddr, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) }) t.Run("should work", func(t *testing.T) { t.Parallel() - testProcessRelayedTransactionV3(t, tx, userTx.RcvAddr, nil, vmcommon.Ok) + testProcessRelayedTransactionV3(t, tx, userTx.SndAddr, userTx.RcvAddr, nil, vmcommon.Ok) }) } func testProcessRelayedTransactionV3( t *testing.T, tx *transaction.Transaction, + innerSender []byte, finalRcvr []byte, expectedErr error, expectedCode vmcommon.ReturnCode, @@ -2166,6 +2180,8 @@ func testProcessRelayedTransactionV3( acntFinal := createUserAcc(finalRcvr) _ = acntFinal.AddToBalance(big.NewInt(10)) + acntInnerSender := createUserAcc(innerSender) + _ = acntInnerSender.AddToBalance(big.NewInt(10)) adb := &stateMock.AccountsStub{} adb.LoadAccountCalled = func(address []byte) (vmcommon.AccountHandler, error) { @@ -2178,6 +2194,9 @@ func testProcessRelayedTransactionV3( if bytes.Equal(address, finalRcvr) { return acntFinal, nil } + if bytes.Equal(address, innerSender) { + return acntInnerSender, nil + } return nil, errors.New("failure") } @@ -2214,6 +2233,7 @@ func testProcessRelayedTransactionV3( return 4 }, } + args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(args.EconomicsFee, args.ShardCoordinator) execTx, _ := txproc.NewTxProcessor(args) @@ -2941,8 +2961,7 @@ func TestTxProcessor_ProcessUserTxOfTypeRelayedShouldError(t *testing.T) { execTx, _ := txproc.NewTxProcessor(args) - txHash, _ := core.CalculateHash(args.Marshalizer, args.Hasher, tx) - returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce, txHash) + returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce) assert.Nil(t, err) assert.Equal(t, vmcommon.UserError, returnCode) } @@ -3005,8 +3024,7 @@ func TestTxProcessor_ProcessUserTxOfTypeMoveBalanceShouldWork(t *testing.T) { execTx, _ := txproc.NewTxProcessor(args) - txHash, _ := core.CalculateHash(args.Marshalizer, args.Hasher, tx) - returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce, txHash) + returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce) assert.Nil(t, err) assert.Equal(t, vmcommon.Ok, returnCode) } @@ -3069,8 +3087,7 @@ func TestTxProcessor_ProcessUserTxOfTypeSCDeploymentShouldWork(t *testing.T) { execTx, _ := txproc.NewTxProcessor(args) - txHash, _ := core.CalculateHash(args.Marshalizer, args.Hasher, tx) - returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce, txHash) + returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce) assert.Nil(t, err) assert.Equal(t, vmcommon.Ok, returnCode) } @@ -3133,8 +3150,7 @@ func TestTxProcessor_ProcessUserTxOfTypeSCInvokingShouldWork(t *testing.T) { execTx, _ := txproc.NewTxProcessor(args) - txHash, _ := core.CalculateHash(args.Marshalizer, args.Hasher, tx) - returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce, txHash) + returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce) assert.Nil(t, err) assert.Equal(t, vmcommon.Ok, returnCode) } @@ -3197,8 +3213,7 @@ func TestTxProcessor_ProcessUserTxOfTypeBuiltInFunctionCallShouldWork(t *testing execTx, _ := txproc.NewTxProcessor(args) - txHash, _ := core.CalculateHash(args.Marshalizer, args.Hasher, tx) - returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce, txHash) + returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce) assert.Nil(t, err) assert.Equal(t, vmcommon.Ok, returnCode) } @@ -3265,8 +3280,7 @@ func TestTxProcessor_ProcessUserTxErrNotPayableShouldFailRelayTx(t *testing.T) { execTx, _ := txproc.NewTxProcessor(args) - txHash, _ := core.CalculateHash(args.Marshalizer, args.Hasher, tx) - returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce, txHash) + returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce) assert.Nil(t, err) assert.Equal(t, vmcommon.UserError, returnCode) } @@ -3335,8 +3349,7 @@ func TestTxProcessor_ProcessUserTxFailedBuiltInFunctionCall(t *testing.T) { execTx, _ := txproc.NewTxProcessor(args) - txHash, _ := core.CalculateHash(args.Marshalizer, args.Hasher, tx) - returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce, txHash) + returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce) assert.Nil(t, err) assert.Equal(t, vmcommon.ExecutionFailed, returnCode) } diff --git a/testscommon/components/default.go b/testscommon/components/default.go index 514b8355407..8e1942037dd 100644 --- a/testscommon/components/default.go +++ b/testscommon/components/default.go @@ -20,6 +20,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" "github.com/multiversx/mx-chain-go/testscommon/nodeTypeProviderMock" "github.com/multiversx/mx-chain-go/testscommon/p2pmocks" + "github.com/multiversx/mx-chain-go/testscommon/processMocks" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" "github.com/multiversx/mx-chain-go/testscommon/stakingcommon" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" @@ -156,6 +157,7 @@ func GetDefaultProcessComponents(shardCoordinator sharding.Coordinator) *mock.Pr return &mock.PrivateKeyStub{} }, }, - HardforkTriggerField: &testscommon.HardforkTriggerStub{}, + HardforkTriggerField: &testscommon.HardforkTriggerStub{}, + RelayedTxV3ProcessorField: &processMocks.RelayedTxV3ProcessorMock{}, } } diff --git a/testscommon/processMocks/relayedTxV3ProcessorMock.go b/testscommon/processMocks/relayedTxV3ProcessorMock.go new file mode 100644 index 00000000000..2d2a0655f36 --- /dev/null +++ b/testscommon/processMocks/relayedTxV3ProcessorMock.go @@ -0,0 +1,43 @@ +package processMocks + +import ( + "math/big" + + "github.com/multiversx/mx-chain-core-go/data/transaction" +) + +// RelayedTxV3ProcessorMock - +type RelayedTxV3ProcessorMock struct { + ComputeRelayedTxFeesCalled func(tx *transaction.Transaction) (*big.Int, *big.Int) + GetUniqueSendersRequiredFeesMapCalled func(innerTxs []*transaction.Transaction) map[string]*big.Int + CheckRelayedTxCalled func(tx *transaction.Transaction) error +} + +// ComputeRelayedTxFees - +func (mock *RelayedTxV3ProcessorMock) ComputeRelayedTxFees(tx *transaction.Transaction) (*big.Int, *big.Int) { + if mock.ComputeRelayedTxFeesCalled != nil { + return mock.ComputeRelayedTxFeesCalled(tx) + } + return nil, nil +} + +// GetUniqueSendersRequiredFeesMap - +func (mock *RelayedTxV3ProcessorMock) GetUniqueSendersRequiredFeesMap(innerTxs []*transaction.Transaction) map[string]*big.Int { + if mock.GetUniqueSendersRequiredFeesMapCalled != nil { + return mock.GetUniqueSendersRequiredFeesMapCalled(innerTxs) + } + return nil +} + +// CheckRelayedTx - +func (mock *RelayedTxV3ProcessorMock) CheckRelayedTx(tx *transaction.Transaction) error { + if mock.CheckRelayedTxCalled != nil { + return mock.CheckRelayedTxCalled(tx) + } + return nil +} + +// IsInterfaceNil - +func (mock *RelayedTxV3ProcessorMock) IsInterfaceNil() bool { + return mock == nil +} diff --git a/update/factory/exportHandlerFactory.go b/update/factory/exportHandlerFactory.go index c13f25f3f5a..a8ed95f4ceb 100644 --- a/update/factory/exportHandlerFactory.go +++ b/update/factory/exportHandlerFactory.go @@ -18,6 +18,7 @@ import ( mxFactory "github.com/multiversx/mx-chain-go/factory" "github.com/multiversx/mx-chain-go/genesis/process/disabled" "github.com/multiversx/mx-chain-go/process" + processDisabled "github.com/multiversx/mx-chain-go/process/disabled" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "github.com/multiversx/mx-chain-go/state" @@ -588,6 +589,7 @@ func (e *exportHandlerFactory) createInterceptors() error { FullArchiveInterceptorsContainer: e.fullArchiveInterceptorsContainer, AntifloodHandler: e.networkComponents.InputAntiFloodHandler(), NodeOperationMode: e.nodeOperationMode, + RelayedTxV3Processor: processDisabled.NewRelayedTxV3Processor(), } fullSyncInterceptors, err := NewFullSyncInterceptorsContainerFactory(argsInterceptors) if err != nil { diff --git a/update/factory/fullSyncInterceptors.go b/update/factory/fullSyncInterceptors.go index 0fe0298c4d6..67d5a86a503 100644 --- a/update/factory/fullSyncInterceptors.go +++ b/update/factory/fullSyncInterceptors.go @@ -75,6 +75,7 @@ type ArgsNewFullSyncInterceptorsContainerFactory struct { FullArchiveInterceptorsContainer process.InterceptorsContainer AntifloodHandler process.P2PAntifloodHandler NodeOperationMode common.NodeOperation + RelayedTxV3Processor process.RelayedTxV3Processor } // NewFullSyncInterceptorsContainerFactory is responsible for creating a new interceptors factory object @@ -145,6 +146,7 @@ func NewFullSyncInterceptorsContainerFactory( EpochStartTrigger: args.EpochStartTrigger, WhiteListerVerifiedTxs: args.WhiteListerVerifiedTxs, ArgsParser: smartContract.NewArgumentParser(), + RelayedTxV3Processor: args.RelayedTxV3Processor, } icf := &fullSyncInterceptorsContainerFactory{ From dd31caae2a6aa864bdde674c3cccb77c7b431a57 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 15 Apr 2024 16:00:39 +0300 Subject: [PATCH 176/503] removed commented code --- process/transaction/shardProcess.go | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 3d50cea16a5..efa6e0a14e9 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -1215,20 +1215,6 @@ func (txProc *txProcessor) processInnerTxsFeesAfterSnapshot(tx *transaction.Tran sendersBalancesSnapshot[senderAcnt] = prevBalanceForSender } - // if one error occurred, revert all transfers that succeeded and return error - //if lastTransferErr != nil { - // for i := 0; i < lastIdx; i++ { - // uniqueSender := uniqueSendersSlice[i] - // totalFessSentForSender := uniqueSendersMap[uniqueSender] - // _, _, err = txProc.addFeesToDest([]byte(uniqueSender), big.NewInt(0).Neg(totalFessSentForSender)) - // if err != nil { - // log.Warn("could not revert the fees transferred from relayer to sender", - // "sender", txProc.pubkeyConv.SilentEncode([]byte(uniqueSender), log), - // "relayer", txProc.pubkeyConv.SilentEncode(relayerAcnt.AddressBytes(), log)) - // } - // } - //} - return sendersBalancesSnapshot, lastTransferErr } From 5258bf0881dc2da18de677db74856a72ab31e708 Mon Sep 17 00:00:00 2001 From: MariusC Date: Tue, 16 Apr 2024 11:05:58 +0300 Subject: [PATCH 177/503] CLN: Test + fix linter --- integrationTests/vm/staking/stakingV4_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/integrationTests/vm/staking/stakingV4_test.go b/integrationTests/vm/staking/stakingV4_test.go index f927ddadfe3..077c87c407b 100644 --- a/integrationTests/vm/staking/stakingV4_test.go +++ b/integrationTests/vm/staking/stakingV4_test.go @@ -1641,10 +1641,8 @@ func TestStakingV4LeavingNodesShouldDistributeToWaitingOnlyNecessaryNodes(t *tes require.Len(t, currNodesCfg.auction, 343) // 400 initial - 57 leaving requireSliceContainsNumOfElements(t, getAllPubKeys(currNodesCfg.waiting), prevConfig.auction, 320) // 320 selected requireSliceContainsNumOfElements(t, currNodesCfg.auction, prevConfig.auction, 69) // 69 unselected - - nodesToUnStakeFromAuction = make([][]byte, 0) - nodesToUnStakeFromWaiting = make([][]byte, 0) - nodesToUnStakeFromEligible = make([][]byte, 0) + require.Len(t, getAllPubKeys(currNodesCfg.eligible), 1600) + require.Len(t, getAllPubKeys(currNodesCfg.waiting), 1280) prevConfig = currNodesCfg // UnStake: @@ -1680,6 +1678,8 @@ func TestStakingV4LeavingNodesShouldDistributeToWaitingOnlyNecessaryNodes(t *tes require.Len(t, currNodesCfg.auction, 150) // 138 shuffled out + 12 unselected requireSliceContainsNumOfElements(t, getAllPubKeys(currNodesCfg.waiting), prevConfig.auction, 320) // 320 selected requireSliceContainsNumOfElements(t, currNodesCfg.auction, prevConfig.auction, 12) // 12 unselected + require.Len(t, getAllPubKeys(currNodesCfg.eligible), 1600) + require.Len(t, getAllPubKeys(currNodesCfg.waiting), 1280) } func TestStakingV4MoreLeavingNodesThanToShufflePerShard(t *testing.T) { @@ -1763,6 +1763,8 @@ func TestStakingV4MoreLeavingNodesThanToShufflePerShard(t *testing.T) { require.Len(t, currNodesCfg.auction, 80) // 400 initial - 320 selected requireSliceContainsNumOfElements(t, getAllPubKeys(currNodesCfg.waiting), prevConfig.auction, 320) // 320 selected requireSliceContainsNumOfElements(t, currNodesCfg.auction, prevConfig.auction, 80) // 80 unselected + require.Len(t, getAllPubKeys(currNodesCfg.eligible), 1600) + require.Len(t, getAllPubKeys(currNodesCfg.waiting), 1280) // Add 400 new nodes in the system and fast-forward node.ProcessStake(t, map[string]*NodesRegisterData{ @@ -1784,4 +1786,6 @@ func TestStakingV4MoreLeavingNodesThanToShufflePerShard(t *testing.T) { require.Len(t, getAllPubKeys(currNodesCfg.shuffledOut), 240) // 240 shuffled out requireSliceContainsNumOfElements(t, getAllPubKeys(currNodesCfg.waiting), prevConfig.auction, 320) // 320 selected requireSliceContainsNumOfElements(t, currNodesCfg.auction, prevConfig.auction, 80) // 80 unselected + require.Len(t, getAllPubKeys(currNodesCfg.eligible), 1600) + require.Len(t, getAllPubKeys(currNodesCfg.waiting), 1280) } From 10411000c3fd12ceba2da7dcabc180b9d38a3f7e Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Tue, 16 Apr 2024 18:59:13 +0300 Subject: [PATCH 178/503] over writable map fixes --- common/reflectcommon/structFieldsUpdate.go | 10 +- .../reflectcommon/structFieldsUpdate_test.go | 242 ++++++++---------- testscommon/toml/config.go | 27 +- testscommon/toml/config.toml | 5 +- testscommon/toml/overwrite.toml | 64 ++--- 5 files changed, 163 insertions(+), 185 deletions(-) diff --git a/common/reflectcommon/structFieldsUpdate.go b/common/reflectcommon/structFieldsUpdate.go index 66434365179..be8671eff4f 100644 --- a/common/reflectcommon/structFieldsUpdate.go +++ b/common/reflectcommon/structFieldsUpdate.go @@ -175,7 +175,15 @@ func tryUpdateMapValue(value *reflect.Value, newValue reflect.Value) error { switch newValue.Kind() { case reflect.Map: for _, key := range newValue.MapKeys() { - value.SetMapIndex(key, newValue.MapIndex(key)) + item := newValue.MapIndex(key) + newItem := reflect.New(value.Type().Elem()).Elem() + + err := trySetTheNewValue(&newItem, item.Interface()) + if err != nil { + return err + } + + value.SetMapIndex(key, newItem) } default: return fmt.Errorf("unsupported type <%s> when trying to add value in type <%s>", newValue.Kind(), value.Kind()) diff --git a/common/reflectcommon/structFieldsUpdate_test.go b/common/reflectcommon/structFieldsUpdate_test.go index e59695598f4..44d3ae7d694 100644 --- a/common/reflectcommon/structFieldsUpdate_test.go +++ b/common/reflectcommon/structFieldsUpdate_test.go @@ -518,11 +518,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI8.Int8.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[0].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[0].Path, overrideConfig.OverridableConfigTomlValues[0].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[0].Value, int64(testConfig.Int8.Value)) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[0].Value, int64(testConfig.Int8.Number)) }) t.Run("should error int8 value", func(t *testing.T) { @@ -534,9 +532,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI8.Int8.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[1].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[1].Path, overrideConfig.OverridableConfigTomlValues[1].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '128' of type to type ", err.Error()) }) @@ -550,11 +546,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI8.Int8.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[2].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[2].Path, overrideConfig.OverridableConfigTomlValues[2].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[2].Value, int64(testConfig.Int8.Value)) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[2].Value, int64(testConfig.Int8.Number)) }) t.Run("should error int8 negative value", func(t *testing.T) { @@ -566,9 +560,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI8.Int8.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[3].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[3].Path, overrideConfig.OverridableConfigTomlValues[3].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '-129' of type to type ", err.Error()) }) @@ -582,11 +574,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI16.Int16.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[4].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[4].Path, overrideConfig.OverridableConfigTomlValues[4].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[4].Value, int64(testConfig.Int16.Value)) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[4].Value, int64(testConfig.Int16.Number)) }) t.Run("should error int16 value", func(t *testing.T) { @@ -598,9 +588,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI16.Int16.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[5].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[5].Path, overrideConfig.OverridableConfigTomlValues[5].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '32768' of type to type ", err.Error()) }) @@ -614,11 +602,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI16.Int16.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[6].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[6].Path, overrideConfig.OverridableConfigTomlValues[6].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[6].Value, int64(testConfig.Int16.Value)) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[6].Value, int64(testConfig.Int16.Number)) }) t.Run("should error int16 negative value", func(t *testing.T) { @@ -630,9 +616,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI16.Int16.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[7].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[7].Path, overrideConfig.OverridableConfigTomlValues[7].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '-32769' of type to type ", err.Error()) }) @@ -646,11 +630,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI32.Int32.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[17].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[8].Path, overrideConfig.OverridableConfigTomlValues[8].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[17].Value, int64(testConfig.Int32.Value)) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[8].Value, int64(testConfig.Int32.Number)) }) t.Run("should work and override int32 value with uint16", func(t *testing.T) { @@ -661,11 +643,11 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { expectedNewValue := uint16(10) - path := "TestConfigI32.Int32.Value" + path := "TestConfigI32.Int32.Number" err = AdaptStructureValueBasedOnPath(testConfig, path, expectedNewValue) require.NoError(t, err) - require.Equal(t, int32(expectedNewValue), testConfig.Int32.Value) + require.Equal(t, int32(expectedNewValue), testConfig.Int32.Number) }) t.Run("should error int32 value", func(t *testing.T) { @@ -677,9 +659,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI32.Int32.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[9].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[9].Path, overrideConfig.OverridableConfigTomlValues[9].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '2147483648' of type to type ", err.Error()) }) @@ -693,11 +673,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI32.Int32.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[10].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[10].Path, overrideConfig.OverridableConfigTomlValues[10].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[10].Value, int64(testConfig.Int32.Value)) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[10].Value, int64(testConfig.Int32.Number)) }) t.Run("should error int32 negative value", func(t *testing.T) { @@ -709,9 +687,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI32.Int32.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[11].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[11].Path, overrideConfig.OverridableConfigTomlValues[11].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '-2147483649' of type to type ", err.Error()) }) @@ -725,11 +701,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI64.Int64.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[12].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[12].Path, overrideConfig.OverridableConfigTomlValues[12].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[12].Value, int64(testConfig.Int64.Value)) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[12].Value, int64(testConfig.Int64.Number)) }) t.Run("should work and override int64 negative value", func(t *testing.T) { @@ -741,11 +715,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI64.Int64.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[13].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[13].Path, overrideConfig.OverridableConfigTomlValues[13].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[13].Value, int64(testConfig.Int64.Value)) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[13].Value, int64(testConfig.Int64.Number)) }) t.Run("should work and override uint8 value", func(t *testing.T) { @@ -757,11 +729,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigU8.Uint8.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[14].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[14].Path, overrideConfig.OverridableConfigTomlValues[14].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[14].Value, int64(testConfig.Uint8.Value)) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[14].Value, int64(testConfig.Uint8.Number)) }) t.Run("should error uint8 value", func(t *testing.T) { @@ -773,9 +743,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigU8.Uint8.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[15].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[15].Path, overrideConfig.OverridableConfigTomlValues[15].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '256' of type to type ", err.Error()) }) @@ -789,9 +757,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigU8.Uint8.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[16].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[16].Path, overrideConfig.OverridableConfigTomlValues[16].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '-256' of type to type ", err.Error()) }) @@ -805,11 +771,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigU16.Uint16.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[17].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[17].Path, overrideConfig.OverridableConfigTomlValues[17].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[17].Value, int64(testConfig.Uint16.Value)) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[17].Value, int64(testConfig.Uint16.Number)) }) t.Run("should error uint16 value", func(t *testing.T) { @@ -821,9 +785,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigU16.Uint16.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[18].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[18].Path, overrideConfig.OverridableConfigTomlValues[18].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '65536' of type to type ", err.Error()) }) @@ -837,9 +799,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigU16.Uint16.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[19].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[19].Path, overrideConfig.OverridableConfigTomlValues[19].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '-65536' of type to type ", err.Error()) }) @@ -853,11 +813,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigU32.Uint32.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[20].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[20].Path, overrideConfig.OverridableConfigTomlValues[20].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[20].Value, int64(testConfig.Uint32.Value)) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[20].Value, int64(testConfig.Uint32.Number)) }) t.Run("should error uint32 value", func(t *testing.T) { @@ -869,9 +827,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigU32.Uint32.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[21].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[21].Path, overrideConfig.OverridableConfigTomlValues[21].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '4294967296' of type to type ", err.Error()) }) @@ -885,9 +841,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigU32.Uint32.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[22].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[22].Path, overrideConfig.OverridableConfigTomlValues[22].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '-4294967296' of type to type ", err.Error()) }) @@ -901,11 +855,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigU64.Uint64.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[23].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[23].Path, overrideConfig.OverridableConfigTomlValues[23].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[23].Value, int64(testConfig.Uint64.Value)) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[23].Value, int64(testConfig.Uint64.Number)) }) t.Run("should error uint64 negative value", func(t *testing.T) { @@ -917,9 +869,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigU64.Uint64.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[24].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[24].Path, overrideConfig.OverridableConfigTomlValues[24].Value) require.Equal(t, "unable to cast value '-9223372036854775808' of type to type ", err.Error()) }) @@ -932,11 +882,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigF32.Float32.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[25].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[25].Path, overrideConfig.OverridableConfigTomlValues[25].Value) require.NoError(t, err) - require.Equal(t, float32(3.4), testConfig.Float32.Value) + require.Equal(t, float32(3.4), testConfig.Float32.Number) }) t.Run("should error float32 value", func(t *testing.T) { @@ -948,9 +896,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigF32.Float32.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[26].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[26].Path, overrideConfig.OverridableConfigTomlValues[26].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '3.4e+39' of type to type ", err.Error()) }) @@ -964,11 +910,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigF32.Float32.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[27].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[27].Path, overrideConfig.OverridableConfigTomlValues[27].Value) require.NoError(t, err) - require.Equal(t, float32(-3.4), testConfig.Float32.Value) + require.Equal(t, float32(-3.4), testConfig.Float32.Number) }) t.Run("should error float32 negative value", func(t *testing.T) { @@ -980,9 +924,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigF32.Float32.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[28].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[28].Path, overrideConfig.OverridableConfigTomlValues[28].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '-3.4e+40' of type to type ", err.Error()) }) @@ -996,11 +938,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigF64.Float64.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[29].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[29].Path, overrideConfig.OverridableConfigTomlValues[29].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[29].Value, testConfig.Float64.Value) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[29].Value, testConfig.Float64.Number) }) t.Run("should work and override float64 negative value", func(t *testing.T) { @@ -1012,11 +952,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigF64.Float64.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[30].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[30].Path, overrideConfig.OverridableConfigTomlValues[30].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[30].Value, testConfig.Float64.Value) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[30].Value, testConfig.Float64.Number) }) t.Run("should work and override struct", func(t *testing.T) { @@ -1028,13 +966,11 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigStruct.ConfigStruct.Description" - expectedNewValue := toml.Description{ Number: 11, } - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[31].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[31].Path, overrideConfig.OverridableConfigTomlValues[31].Value) require.NoError(t, err) require.Equal(t, expectedNewValue, testConfig.TestConfigStruct.ConfigStruct.Description) }) @@ -1048,9 +984,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigStruct.ConfigStruct.Description" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[32].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[32].Path, overrideConfig.OverridableConfigTomlValues[32].Value) require.Equal(t, "field not found or cannot be set", err.Error()) }) @@ -1063,9 +997,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigStruct.ConfigStruct.Description" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[33].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[33].Path, overrideConfig.OverridableConfigTomlValues[33].Value) require.Equal(t, "unable to cast value '11' of type to type ", err.Error()) }) @@ -1078,8 +1010,6 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigNestedStruct.ConfigNestedStruct" - expectedNewValue := toml.ConfigNestedStruct{ Text: "Overwritten text", Message: toml.Message{ @@ -1090,7 +1020,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { }, } - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[34].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[34].Path, overrideConfig.OverridableConfigTomlValues[34].Value) require.NoError(t, err) require.Equal(t, expectedNewValue, testConfig.TestConfigNestedStruct.ConfigNestedStruct) }) @@ -1104,14 +1034,12 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription" - expectedNewValue := []toml.MessageDescription{ {Text: "Overwritten Text1"}, {Text: "Overwritten Text2"}, } - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[35].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[35].Path, overrideConfig.OverridableConfigTomlValues[35].Value) require.NoError(t, err) require.Equal(t, expectedNewValue, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription) }) @@ -1194,38 +1122,72 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { require.Equal(t, expectedNewValue, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription) }) - t.Run("should work on map and override existing value in map", func(t *testing.T) { + t.Run("should work on map, override and insert from config", func(t *testing.T) { t.Parallel() testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") require.NoError(t, err) - expectedNewValue := make(map[string]int) - expectedNewValue["key"] = 100 + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) - path := "TestMap.Value" + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[36].Path, overrideConfig.OverridableConfigTomlValues[36].Value) + require.NoError(t, err) + require.Equal(t, 2, len(testConfig.TestMap.Map)) + require.Equal(t, 10, testConfig.TestMap.Map["Key1"].Number) + require.Equal(t, 11, testConfig.TestMap.Map["Key2"].Number) + }) - err = AdaptStructureValueBasedOnPath(testConfig, path, expectedNewValue) + t.Run("should work on map and insert from config", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[37].Path, overrideConfig.OverridableConfigTomlValues[37].Value) require.NoError(t, err) - require.Equal(t, 1, len(testConfig.TestMap.Value)) - require.Equal(t, testConfig.TestMap.Value["key"], 100) + require.Equal(t, 3, len(testConfig.TestMap.Map)) + require.Equal(t, 999, testConfig.TestMap.Map["Key1"].Number) + require.Equal(t, 2, testConfig.TestMap.Map["Key2"].Number) + require.Equal(t, 3, testConfig.TestMap.Map["Key3"].Number) }) - t.Run("should work on map and insert values in map", func(t *testing.T) { + t.Run("should work on map, override and insert values in map", func(t *testing.T) { t.Parallel() testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") require.NoError(t, err) - expectedNewValue := make(map[string]int) - expectedNewValue["first"] = 1 - expectedNewValue["second"] = 2 + expectedNewValue := make(map[string]toml.MapValues) + expectedNewValue["Key1"] = toml.MapValues{Number: 100} + expectedNewValue["Key2"] = toml.MapValues{Number: 200} - path := "TestMap.Value" + path := "TestMap.Map" err = AdaptStructureValueBasedOnPath(testConfig, path, expectedNewValue) require.NoError(t, err) - require.Equal(t, 3, len(testConfig.TestMap.Value)) + require.Equal(t, 2, len(testConfig.TestMap.Map)) + require.Equal(t, 100, testConfig.TestMap.Map["Key1"].Number) + require.Equal(t, 200, testConfig.TestMap.Map["Key2"].Number) + }) + + t.Run("should error on map when override different map", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + expectedNewValue := make(map[string]toml.MessageDescription) + expectedNewValue["Key1"] = toml.MessageDescription{Text: "A"} + expectedNewValue["Key2"] = toml.MessageDescription{Text: "B"} + + path := "TestMap.Map" + + err = AdaptStructureValueBasedOnPath(testConfig, path, expectedNewValue) + require.Equal(t, "field not found or cannot be set", err.Error()) }) t.Run("should error on map when override anything else other than map", func(t *testing.T) { @@ -1236,7 +1198,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { expectedNewValue := 1 - path := "TestMap.Value" + path := "TestMap.Map" err = AdaptStructureValueBasedOnPath(testConfig, path, expectedNewValue) require.Equal(t, "unsupported type when trying to add value in type ", err.Error()) diff --git a/testscommon/toml/config.go b/testscommon/toml/config.go index 16ec8a7fdd4..56cfeb1f0ad 100644 --- a/testscommon/toml/config.go +++ b/testscommon/toml/config.go @@ -25,7 +25,7 @@ type TestConfigI8 struct { // Int8 will hold the value type Int8 struct { - Value int8 + Number int8 } // TestConfigI16 will hold an int16 value for testing @@ -35,7 +35,7 @@ type TestConfigI16 struct { // Int16 will hold the value type Int16 struct { - Value int16 + Number int16 } // TestConfigI32 will hold an int32 value for testing @@ -45,7 +45,7 @@ type TestConfigI32 struct { // Int32 will hold the value type Int32 struct { - Value int32 + Number int32 } // TestConfigI64 will hold an int64 value for testing @@ -55,7 +55,7 @@ type TestConfigI64 struct { // Int64 will hold the value type Int64 struct { - Value int64 + Number int64 } // TestConfigU8 will hold an uint8 value for testing @@ -65,7 +65,7 @@ type TestConfigU8 struct { // Uint8 will hold the value type Uint8 struct { - Value uint8 + Number uint8 } // TestConfigU16 will hold an uint16 value for testing @@ -75,7 +75,7 @@ type TestConfigU16 struct { // Uint16 will hold the value type Uint16 struct { - Value uint16 + Number uint16 } // TestConfigU32 will hold an uint32 value for testing @@ -85,7 +85,7 @@ type TestConfigU32 struct { // Uint32 will hold the value type Uint32 struct { - Value uint32 + Number uint32 } // TestConfigU64 will hold an uint64 value for testing @@ -95,7 +95,7 @@ type TestConfigU64 struct { // Uint64 will hold the value type Uint64 struct { - Value uint64 + Number uint64 } // TestConfigF32 will hold a float32 value for testing @@ -105,7 +105,7 @@ type TestConfigF32 struct { // Float32 will hold the value type Float32 struct { - Value float32 + Number float32 } // TestConfigF64 will hold a float64 value for testing @@ -115,7 +115,7 @@ type TestConfigF64 struct { // Float64 will hold the value type Float64 struct { - Value float64 + Number float64 } // TestConfigStruct will hold a configuration struct for testing @@ -168,7 +168,12 @@ type MessageDescriptionOtherName struct { // TestMap will hold a map for testing type TestMap struct { - Value map[string]int + Map map[string]MapValues +} + +// MapValues will hold a value for map +type MapValues struct { + Number int } // TestInterface will hold an interface for testing diff --git a/testscommon/toml/config.toml b/testscommon/toml/config.toml index af54141fe5f..91512d5e664 100644 --- a/testscommon/toml/config.toml +++ b/testscommon/toml/config.toml @@ -48,5 +48,6 @@ Text = "Config Nested Struct" Mesage = { Public = true, MessageDescription = [{ Text = "Text1" }, { Text = "Text2"}] } -[TestMap] - Value = { "key" = 0 } +[Map] + [Map.Key1] + Number = 999 diff --git a/testscommon/toml/overwrite.toml b/testscommon/toml/overwrite.toml index 5d1e6690caf..63f74b7828c 100644 --- a/testscommon/toml/overwrite.toml +++ b/testscommon/toml/overwrite.toml @@ -1,38 +1,40 @@ OverridableConfigTomlValues = [ - { File = "config.toml", Path = "TestConfigI8.Int8", Value = 127 }, - { File = "config.toml", Path = "TestConfigI8.Int8", Value = 128 }, - { File = "config.toml", Path = "TestConfigI8.Int8", Value = -128 }, - { File = "config.toml", Path = "TestConfigI8.Int8", Value = -129 }, - { File = "config.toml", Path = "TestConfigI16.Int16", Value = 32767 }, - { File = "config.toml", Path = "TestConfigI16.Int16", Value = 32768 }, - { File = "config.toml", Path = "TestConfigI16.Int16", Value = -32768 }, - { File = "config.toml", Path = "TestConfigI16.Int16", Value = -32769 }, - { File = "config.toml", Path = "TestConfigI32.Int32", Value = 2147483647 }, - { File = "config.toml", Path = "TestConfigI32.Int32", Value = 2147483648 }, - { File = "config.toml", Path = "TestConfigI32.Int32", Value = -2147483648 }, - { File = "config.toml", Path = "TestConfigI32.Int32", Value = -2147483649 }, - { File = "config.toml", Path = "TestConfigI32.Int64", Value = 9223372036854775807 }, - { File = "config.toml", Path = "TestConfigI32.Int64", Value = -9223372036854775808 }, - { File = "config.toml", Path = "TestConfigU8.Uint8", Value = 255 }, - { File = "config.toml", Path = "TestConfigU8.Uint8", Value = 256 }, - { File = "config.toml", Path = "TestConfigU8.Uint8", Value = -256 }, - { File = "config.toml", Path = "TestConfigU16.Uint16", Value = 65535 }, - { File = "config.toml", Path = "TestConfigU16.Uint16", Value = 65536 }, - { File = "config.toml", Path = "TestConfigU16.Uint16", Value = -65536 }, - { File = "config.toml", Path = "TestConfigU32.Uint32", Value = 4294967295 }, - { File = "config.toml", Path = "TestConfigU32.Uint32", Value = 4294967296 }, - { File = "config.toml", Path = "TestConfigU32.Uint32", Value = -4294967296 }, - { File = "config.toml", Path = "TestConfigU64.Uint64", Value = 9223372036854775807 }, - { File = "config.toml", Path = "TestConfigU64.Uint64", Value = -9223372036854775808 }, - { File = "config.toml", Path = "TestConfigF32.Float32", Value = 3.4 }, - { File = "config.toml", Path = "TestConfigF32.Float32", Value = 3.4e+39 }, - { File = "config.toml", Path = "TestConfigF32.Float32", Value = -3.4 }, - { File = "config.toml", Path = "TestConfigF32.Float32", Value = -3.4e+40 }, - { File = "config.toml", Path = "TestConfigF64.Float64", Value = 1.7e+308 }, - { File = "config.toml", Path = "TestConfigF64.Float64", Value = -1.7e+308 }, + { File = "config.toml", Path = "TestConfigI8.Int8.Number", Value = 127 }, + { File = "config.toml", Path = "TestConfigI8.Int8.Number", Value = 128 }, + { File = "config.toml", Path = "TestConfigI8.Int8.Number", Value = -128 }, + { File = "config.toml", Path = "TestConfigI8.Int8.Number", Value = -129 }, + { File = "config.toml", Path = "TestConfigI16.Int16.Number", Value = 32767 }, + { File = "config.toml", Path = "TestConfigI16.Int16.Number", Value = 32768 }, + { File = "config.toml", Path = "TestConfigI16.Int16.Number", Value = -32768 }, + { File = "config.toml", Path = "TestConfigI16.Int16.Number", Value = -32769 }, + { File = "config.toml", Path = "TestConfigI32.Int32.Number", Value = 2147483647 }, + { File = "config.toml", Path = "TestConfigI32.Int32.Number", Value = 2147483648 }, + { File = "config.toml", Path = "TestConfigI32.Int32.Number", Value = -2147483648 }, + { File = "config.toml", Path = "TestConfigI32.Int32.Number", Value = -2147483649 }, + { File = "config.toml", Path = "TestConfigI64.Int64.Number", Value = 9223372036854775807 }, + { File = "config.toml", Path = "TestConfigI64.Int64.Number", Value = -9223372036854775808 }, + { File = "config.toml", Path = "TestConfigU8.Uint8.Number", Value = 255 }, + { File = "config.toml", Path = "TestConfigU8.Uint8.Number", Value = 256 }, + { File = "config.toml", Path = "TestConfigU8.Uint8.Number", Value = -256 }, + { File = "config.toml", Path = "TestConfigU16.Uint16.Number", Value = 65535 }, + { File = "config.toml", Path = "TestConfigU16.Uint16.Number", Value = 65536 }, + { File = "config.toml", Path = "TestConfigU16.Uint16.Number", Value = -65536 }, + { File = "config.toml", Path = "TestConfigU32.Uint32.Number", Value = 4294967295 }, + { File = "config.toml", Path = "TestConfigU32.Uint32.Number", Value = 4294967296 }, + { File = "config.toml", Path = "TestConfigU32.Uint32.Number", Value = -4294967296 }, + { File = "config.toml", Path = "TestConfigU64.Uint64.Number", Value = 9223372036854775807 }, + { File = "config.toml", Path = "TestConfigU64.Uint64.Number", Value = -9223372036854775808 }, + { File = "config.toml", Path = "TestConfigF32.Float32.Number", Value = 3.4 }, + { File = "config.toml", Path = "TestConfigF32.Float32.Number", Value = 3.4e+39 }, + { File = "config.toml", Path = "TestConfigF32.Float32.Number", Value = -3.4 }, + { File = "config.toml", Path = "TestConfigF32.Float32.Number", Value = -3.4e+40 }, + { File = "config.toml", Path = "TestConfigF64.Float64.Number", Value = 1.7e+308 }, + { File = "config.toml", Path = "TestConfigF64.Float64.Number", Value = -1.7e+308 }, { File = "config.toml", Path = "TestConfigStruct.ConfigStruct.Description", Value = { Number = 11 } }, { File = "config.toml", Path = "TestConfigStruct.ConfigStruct.Description", Value = { Nr = 222 } }, { File = "config.toml", Path = "TestConfigStruct.ConfigStruct.Description", Value = { Number = "11" } }, { File = "config.toml", Path = "TestConfigNestedStruct.ConfigNestedStruct", Value = { Text = "Overwritten text", Message = { Public = false, MessageDescription = [{ Text = "Overwritten Text1" }] } } }, { File = "config.toml", Path = "TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription", Value = [{ Text = "Overwritten Text1" }, { Text = "Overwritten Text2" }] }, + { File = "config.toml", Path = "TestMap.Map", Value = { "Key1" = { Number = 10 }, "Key2" = { Number = 11 } } }, + { File = "config.toml", Path = "TestMap.Map", Value = { "Key2" = { Number = 2 }, "Key3" = { Number = 3 } } }, ] From 652ef7ae5e8e7d1a874ed12e1ed180349c777a09 Mon Sep 17 00:00:00 2001 From: radu chis Date: Fri, 19 Apr 2024 12:09:12 +0300 Subject: [PATCH 179/503] update x/crypto to v0.22.0 --- go.mod | 8 ++++---- go.sum | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index aafbc51ec02..c7ef33c791d 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( github.com/shirou/gopsutil v3.21.11+incompatible github.com/stretchr/testify v1.8.4 github.com/urfave/cli v1.22.10 - golang.org/x/crypto v0.10.0 + golang.org/x/crypto v0.22.0 gopkg.in/go-playground/validator.v8 v8.18.2 ) @@ -175,10 +175,10 @@ require ( golang.org/x/arch v0.3.0 // indirect golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect golang.org/x/mod v0.10.0 // indirect - golang.org/x/net v0.11.0 // indirect + golang.org/x/net v0.21.0 // indirect golang.org/x/sync v0.2.0 // indirect - golang.org/x/sys v0.10.0 // indirect - golang.org/x/text v0.10.0 // indirect + golang.org/x/sys v0.19.0 // indirect + golang.org/x/text v0.14.0 // indirect golang.org/x/tools v0.9.1 // indirect gonum.org/v1/gonum v0.11.0 // indirect google.golang.org/protobuf v1.30.0 // indirect diff --git a/go.sum b/go.sum index 09c6f9ea503..813d0a8327a 100644 --- a/go.sum +++ b/go.sum @@ -129,6 +129,7 @@ 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= @@ -261,6 +262,7 @@ 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= @@ -268,6 +270,7 @@ 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= @@ -413,6 +416,7 @@ 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= @@ -626,6 +630,8 @@ golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM= golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I= +golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= +golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug= golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= @@ -670,6 +676,7 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU= golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -725,6 +732,7 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= @@ -740,6 +748,7 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58= golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= From 1030bcd997cdc1bca43defd05aea2941793de7f9 Mon Sep 17 00:00:00 2001 From: radu chis Date: Fri, 19 Apr 2024 10:48:37 +0300 Subject: [PATCH 180/503] add withKeys option on account --- api/groups/addressGroup.go | 1 + api/groups/addressGroupOptions.go | 6 ++ facade/interface.go | 2 +- facade/mock/nodeStub.go | 6 +- facade/nodeFacade.go | 14 +++- facade/nodeFacade_test.go | 14 ++-- go.mod | 2 +- go.sum | 4 +- .../node/getAccount/getAccount_test.go | 5 +- node/node.go | 34 +++++--- node/nodeLoadAccounts_test.go | 3 +- node/node_test.go | 79 +++++++++++++++++-- 12 files changed, 135 insertions(+), 35 deletions(-) diff --git a/api/groups/addressGroup.go b/api/groups/addressGroup.go index 1866c3bf022..da2adc0ab56 100644 --- a/api/groups/addressGroup.go +++ b/api/groups/addressGroup.go @@ -38,6 +38,7 @@ const ( urlParamBlockHash = "blockHash" urlParamBlockRootHash = "blockRootHash" urlParamHintEpoch = "hintEpoch" + urlParamWithKeys = "withKeys" ) // addressFacadeHandler defines the methods to be implemented by a facade for handling address requests diff --git a/api/groups/addressGroupOptions.go b/api/groups/addressGroupOptions.go index 5cd4fc6a11f..c3841f7e7fd 100644 --- a/api/groups/addressGroupOptions.go +++ b/api/groups/addressGroupOptions.go @@ -54,6 +54,11 @@ func parseAccountQueryOptions(c *gin.Context) (api.AccountQueryOptions, error) { return api.AccountQueryOptions{}, err } + withKeys, err := parseBoolUrlParam(c, urlParamWithKeys) + if err != nil { + return api.AccountQueryOptions{}, err + } + options := api.AccountQueryOptions{ OnFinalBlock: onFinalBlock, OnStartOfEpoch: onStartOfEpoch, @@ -61,6 +66,7 @@ func parseAccountQueryOptions(c *gin.Context) (api.AccountQueryOptions, error) { BlockHash: blockHash, BlockRootHash: blockRootHash, HintEpoch: hintEpoch, + WithKeys: withKeys, } return options, nil } diff --git a/facade/interface.go b/facade/interface.go index 07488622a96..b7deebb17e7 100644 --- a/facade/interface.go +++ b/facade/interface.go @@ -74,7 +74,7 @@ type NodeHandler interface { // GetAccount returns an accountResponse containing information // about the account correlated with provided address - GetAccount(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) + GetAccount(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) // GetCode returns the code for the given code hash GetCode(codeHash []byte, options api.AccountQueryOptions) ([]byte, api.BlockInfo) diff --git a/facade/mock/nodeStub.go b/facade/mock/nodeStub.go index 74c9cbea536..d03d847b151 100644 --- a/facade/mock/nodeStub.go +++ b/facade/mock/nodeStub.go @@ -25,7 +25,7 @@ type NodeStub struct { ValidateTransactionHandler func(tx *transaction.Transaction) error ValidateTransactionForSimulationCalled func(tx *transaction.Transaction, bypassSignature bool) error SendBulkTransactionsHandler func(txs []*transaction.Transaction) (uint64, error) - GetAccountCalled func(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) + GetAccountCalled func(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) GetCodeCalled func(codeHash []byte, options api.AccountQueryOptions) ([]byte, api.BlockInfo) GetCurrentPublicKeyHandler func() string GenerateAndSendBulkTransactionsHandler func(destination string, value *big.Int, nrTransactions uint64) error @@ -181,9 +181,9 @@ func (ns *NodeStub) SendBulkTransactions(txs []*transaction.Transaction) (uint64 } // GetAccount - -func (ns *NodeStub) GetAccount(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { +func (ns *NodeStub) GetAccount(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) { if ns.GetAccountCalled != nil { - return ns.GetAccountCalled(address, options) + return ns.GetAccountCalled(address, options, ctx) } return api.AccountResponse{}, api.BlockInfo{}, nil diff --git a/facade/nodeFacade.go b/facade/nodeFacade.go index 03dd77c76b7..4e328b5462a 100644 --- a/facade/nodeFacade.go +++ b/facade/nodeFacade.go @@ -321,7 +321,10 @@ func (nf *nodeFacade) GetLastPoolNonceForSender(sender string) (uint64, error) { // GetTransactionsPoolNonceGapsForSender will return the nonce gaps from pool for sender, if exists, that is to be returned on API calls func (nf *nodeFacade) GetTransactionsPoolNonceGapsForSender(sender string) (*common.TransactionsPoolNonceGapsForSenderApiResponse, error) { - accountResponse, _, err := nf.node.GetAccount(sender, apiData.AccountQueryOptions{}) + ctx, cancel := nf.getContextForApiTrieRangeOperations() + defer cancel() + + accountResponse, _, err := nf.node.GetAccount(sender, apiData.AccountQueryOptions{}, ctx) if err != nil { return &common.TransactionsPoolNonceGapsForSenderApiResponse{}, err } @@ -336,7 +339,10 @@ func (nf *nodeFacade) ComputeTransactionGasLimit(tx *transaction.Transaction) (* // GetAccount returns a response containing information about the account correlated with provided address func (nf *nodeFacade) GetAccount(address string, options apiData.AccountQueryOptions) (apiData.AccountResponse, apiData.BlockInfo, error) { - accountResponse, blockInfo, err := nf.node.GetAccount(address, options) + ctx, cancel := nf.getContextForApiTrieRangeOperations() + defer cancel() + + accountResponse, blockInfo, err := nf.node.GetAccount(address, options, ctx) if err != nil { return apiData.AccountResponse{}, apiData.BlockInfo{}, err } @@ -358,9 +364,11 @@ func (nf *nodeFacade) GetAccounts(addresses []string, options apiData.AccountQue response := make(map[string]*apiData.AccountResponse) var blockInfo apiData.BlockInfo + ctx, cancel := nf.getContextForApiTrieRangeOperations() + defer cancel() for _, address := range addresses { - accountResponse, blockInfoForAccount, err := nf.node.GetAccount(address, options) + accountResponse, blockInfoForAccount, err := nf.node.GetAccount(address, options, ctx) if err != nil { return nil, apiData.BlockInfo{}, err } diff --git a/facade/nodeFacade_test.go b/facade/nodeFacade_test.go index 21823b60b6e..f2eaff6025e 100644 --- a/facade/nodeFacade_test.go +++ b/facade/nodeFacade_test.go @@ -338,7 +338,7 @@ func TestNodeFacade_GetAccount(t *testing.T) { arg := createMockArguments() arg.Node = &mock.NodeStub{ - GetAccountCalled: func(_ string, _ api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { + GetAccountCalled: func(_ string, _ api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { return api.AccountResponse{}, api.BlockInfo{}, expectedErr }, } @@ -352,7 +352,7 @@ func TestNodeFacade_GetAccount(t *testing.T) { getAccountCalled := false node := &mock.NodeStub{} - node.GetAccountCalled = func(address string, _ api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { + node.GetAccountCalled = func(address string, _ api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { getAccountCalled = true return api.AccountResponse{}, api.BlockInfo{}, nil } @@ -387,7 +387,7 @@ func TestNodeFacade_GetAccounts(t *testing.T) { t.Parallel() node := &mock.NodeStub{} - node.GetAccountCalled = func(address string, _ api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { + node.GetAccountCalled = func(address string, _ api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { return api.AccountResponse{}, api.BlockInfo{}, expectedErr } @@ -407,7 +407,7 @@ func TestNodeFacade_GetAccounts(t *testing.T) { expectedAcount := api.AccountResponse{Address: "test"} node := &mock.NodeStub{} - node.GetAccountCalled = func(address string, _ api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { + node.GetAccountCalled = func(address string, _ api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { return expectedAcount, api.BlockInfo{}, nil } @@ -2008,7 +2008,7 @@ func TestNodeFacade_GetTransactionsPoolNonceGapsForSender(t *testing.T) { arg := createMockArguments() arg.Node = &mock.NodeStub{ - GetAccountCalled: func(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { + GetAccountCalled: func(address string, options api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { return api.AccountResponse{}, api.BlockInfo{}, expectedErr }, } @@ -2030,7 +2030,7 @@ func TestNodeFacade_GetTransactionsPoolNonceGapsForSender(t *testing.T) { arg := createMockArguments() arg.Node = &mock.NodeStub{ - GetAccountCalled: func(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { + GetAccountCalled: func(address string, options api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { return api.AccountResponse{}, api.BlockInfo{}, nil }, } @@ -2062,7 +2062,7 @@ func TestNodeFacade_GetTransactionsPoolNonceGapsForSender(t *testing.T) { } providedNonce := uint64(10) arg.Node = &mock.NodeStub{ - GetAccountCalled: func(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { + GetAccountCalled: func(address string, options api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { return api.AccountResponse{Nonce: providedNonce}, api.BlockInfo{}, nil }, } diff --git a/go.mod b/go.mod index aafbc51ec02..b5d8fd684c6 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.14 - github.com/multiversx/mx-chain-core-go v1.2.19 + github.com/multiversx/mx-chain-core-go v1.2.20-0.20240418121049-6970013b49d9 github.com/multiversx/mx-chain-crypto-go v1.2.11 github.com/multiversx/mx-chain-es-indexer-go v1.4.21 github.com/multiversx/mx-chain-logger-go v1.0.14 diff --git a/go.sum b/go.sum index 09c6f9ea503..64517c9b404 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.14 h1:YhAUDjBBpc5h5W0A7LHLXUMIMeCgwgGvkqfAPbFqsno= github.com/multiversx/mx-chain-communication-go v1.0.14/go.mod h1:qYCqgk0h+YpcTA84jHIpCBy6UShRwmXzHSCcdfwNrkw= -github.com/multiversx/mx-chain-core-go v1.2.19 h1:2BaVHkB0tro3cjs5ay2pmLup1loCV0e1p9jV5QW0xqc= -github.com/multiversx/mx-chain-core-go v1.2.19/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.20-0.20240418121049-6970013b49d9 h1:iUGEUzmxh2xrgaHS9Lq5CpnKGDsR02v9gEWroc/jbpA= +github.com/multiversx/mx-chain-core-go v1.2.20-0.20240418121049-6970013b49d9/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.11 h1:MNPJoiTJA5/tedYrI0N22OorbsKDESWG0SF8MCJwcJI= github.com/multiversx/mx-chain-crypto-go v1.2.11/go.mod h1:pcZutPdfLiAFytzCU3LxU3s8cXkvpNqquyitFSfoF3o= github.com/multiversx/mx-chain-es-indexer-go v1.4.21 h1:rzxXCkgOsqj67GRYtqzKuf9XgHwnZLTZhU90Ck3VbrE= diff --git a/integrationTests/node/getAccount/getAccount_test.go b/integrationTests/node/getAccount/getAccount_test.go index 487c8b1a15a..c48a1017a4e 100644 --- a/integrationTests/node/getAccount/getAccount_test.go +++ b/integrationTests/node/getAccount/getAccount_test.go @@ -1,6 +1,7 @@ package getAccount import ( + "context" "math/big" "testing" @@ -57,7 +58,7 @@ func TestNode_GetAccountAccountDoesNotExistsShouldRetEmpty(t *testing.T) { encodedAddress, err := integrationTests.TestAddressPubkeyConverter.Encode(integrationTests.CreateRandomBytes(32)) require.Nil(t, err) - recovAccnt, _, err := n.GetAccount(encodedAddress, api.AccountQueryOptions{}) + recovAccnt, _, err := n.GetAccount(encodedAddress, api.AccountQueryOptions{}, context.Background()) require.Nil(t, err) assert.Equal(t, uint64(0), recovAccnt.Nonce) @@ -99,7 +100,7 @@ func TestNode_GetAccountAccountExistsShouldReturn(t *testing.T) { testAddress, err := coreComponents.AddressPubKeyConverter().Encode(testPubkey) require.Nil(t, err) - recovAccnt, _, err := n.GetAccount(testAddress, api.AccountQueryOptions{}) + recovAccnt, _, err := n.GetAccount(testAddress, api.AccountQueryOptions{}, context.Background()) require.Nil(t, err) require.Equal(t, testNonce, recovAccnt.Nonce) diff --git a/node/node.go b/node/node.go index 978fd45dc99..29cea2671d6 100644 --- a/node/node.go +++ b/node/node.go @@ -291,13 +291,26 @@ func (n *Node) GetKeyValuePairs(address string, options api.AccountQueryOptions, return map[string]string{}, api.BlockInfo{}, nil } + mapToReturn, err := n.getKeys(userAccount, ctx) + if err != nil { + return nil, api.BlockInfo{}, err + } + + if common.IsContextDone(ctx) { + return nil, api.BlockInfo{}, ErrTrieOperationsTimeout + } + + return mapToReturn, blockInfo, nil +} + +func (n *Node) getKeys(userAccount state.UserAccountHandler, ctx context.Context) (map[string]string, error) { chLeaves := &common.TrieIteratorChannels{ LeavesChan: make(chan core.KeyValueHolder, common.TrieLeavesChannelDefaultCapacity), ErrChan: errChan.NewErrChanWrapper(), } - err = userAccount.GetAllLeaves(chLeaves, ctx) + err := userAccount.GetAllLeaves(chLeaves, ctx) if err != nil { - return nil, api.BlockInfo{}, err + return nil, err } mapToReturn := make(map[string]string) @@ -307,14 +320,9 @@ func (n *Node) GetKeyValuePairs(address string, options api.AccountQueryOptions, err = chLeaves.ErrChan.ReadFromChanNonBlocking() if err != nil { - return nil, api.BlockInfo{}, err - } - - if common.IsContextDone(ctx) { - return nil, api.BlockInfo{}, ErrTrieOperationsTimeout + return nil, err } - - return mapToReturn, blockInfo, nil + return mapToReturn, nil } // GetValueForKey will return the value for a key from a given account @@ -930,7 +938,7 @@ func (n *Node) setTxGuardianData(guardian string, guardianSigHex string, tx *tra } // GetAccount will return account details for a given address -func (n *Node) GetAccount(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { +func (n *Node) GetAccount(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) { account, blockInfo, err := n.loadUserAccountHandlerByAddress(address, options) if err != nil { adaptedBlockInfo, isEmptyAccount := extractBlockInfoIfNewAccount(err) @@ -954,6 +962,11 @@ func (n *Node) GetAccount(address string, options api.AccountQueryOptions) (api. } } + var keys map[string]string + if options.WithKeys { + keys, _ = n.getKeys(account, ctx) + } + return api.AccountResponse{ Address: address, Nonce: account.GetNonce(), @@ -964,6 +977,7 @@ func (n *Node) GetAccount(address string, options api.AccountQueryOptions) (api. CodeMetadata: account.GetCodeMetadata(), DeveloperReward: account.GetDeveloperReward().String(), OwnerAddress: ownerAddress, + Pairs: keys, }, blockInfo, nil } diff --git a/node/nodeLoadAccounts_test.go b/node/nodeLoadAccounts_test.go index e7e03c2d05b..7ef831bca0f 100644 --- a/node/nodeLoadAccounts_test.go +++ b/node/nodeLoadAccounts_test.go @@ -2,6 +2,7 @@ package node_test import ( "bytes" + "context" "errors" "math/big" "testing" @@ -45,7 +46,7 @@ func TestNode_GetAccountWithOptionsShouldWork(t *testing.T) { node.WithStateComponents(stateComponents), ) - account, blockInfo, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}) + account, blockInfo, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}, context.Background()) require.Nil(t, err) require.Equal(t, "100", account.Balance) require.Equal(t, uint64(1), blockInfo.Nonce) diff --git a/node/node_test.go b/node/node_test.go index 2cde11d08a0..d10f79b67be 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -3293,7 +3293,7 @@ func TestNode_GetAccountPubkeyConverterFailsShouldErr(t *testing.T) { node.WithCoreComponents(coreComponents), ) - recovAccnt, _, err := n.GetAccount(createDummyHexAddress(64), api.AccountQueryOptions{}) + recovAccnt, _, err := n.GetAccount(createDummyHexAddress(64), api.AccountQueryOptions{}, context.Background()) assert.Empty(t, recovAccnt) assert.ErrorIs(t, err, errExpected) @@ -3320,7 +3320,7 @@ func TestNode_GetAccountAccountDoesNotExistsShouldRetEmpty(t *testing.T) { node.WithStateComponents(stateComponents), ) - account, blockInfo, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}) + account, blockInfo, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}, context.Background()) require.Nil(t, err) require.Equal(t, uint64(0), account.Nonce) @@ -3355,7 +3355,7 @@ func TestNode_GetAccountAccountsRepositoryFailsShouldErr(t *testing.T) { node.WithStateComponents(stateComponents), ) - recovAccnt, _, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}) + recovAccnt, _, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}, context.Background()) assert.Empty(t, recovAccnt) assert.NotNil(t, err) @@ -3394,7 +3394,7 @@ func TestNode_GetAccountAccNotFoundShouldReturnEmpty(t *testing.T) { node.WithStateComponents(stateComponents), ) - acc, bInfo, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}) + acc, bInfo, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}, context.Background()) require.Nil(t, err) require.Equal(t, dummyBlockInfo.apiResult(), bInfo) require.Equal(t, api.AccountResponse{Address: testscommon.TestAddressAlice, Balance: "0", DeveloperReward: "0"}, acc) @@ -3436,7 +3436,7 @@ func TestNode_GetAccountAccountExistsShouldReturn(t *testing.T) { node.WithStateComponents(stateComponents), ) - recovAccnt, _, err := n.GetAccount(testscommon.TestAddressBob, api.AccountQueryOptions{}) + recovAccnt, _, err := n.GetAccount(testscommon.TestAddressBob, api.AccountQueryOptions{}, context.Background()) require.Nil(t, err) require.Equal(t, uint64(2), recovAccnt.Nonce) @@ -3447,6 +3447,75 @@ func TestNode_GetAccountAccountExistsShouldReturn(t *testing.T) { require.Equal(t, testscommon.TestAddressAlice, recovAccnt.OwnerAddress) } +func TestNode_GetAccountAccountWithKeysShouldReturn(t *testing.T) { + t.Parallel() + + accnt := createAcc(testscommon.TestPubKeyBob) + _ = accnt.AddToBalance(big.NewInt(1)) + + k1, v1 := []byte("key1"), []byte("value1") + k2, v2 := []byte("key2"), []byte("value2") + + accnt.SetDataTrie( + &trieMock.TrieStub{ + GetAllLeavesOnChannelCalled: func(leavesChannels *common.TrieIteratorChannels, ctx context.Context, rootHash []byte, _ common.KeyBuilder, tlp common.TrieLeafParser) error { + go func() { + suffix := append(k1, accnt.AddressBytes()...) + trieLeaf, _ := tlp.ParseLeaf(k1, append(v1, suffix...), core.NotSpecified) + leavesChannels.LeavesChan <- trieLeaf + + suffix = append(k2, accnt.AddressBytes()...) + trieLeaf2, _ := tlp.ParseLeaf(k2, append(v2, suffix...), core.NotSpecified) + leavesChannels.LeavesChan <- trieLeaf2 + + close(leavesChannels.LeavesChan) + leavesChannels.ErrChan.Close() + }() + + return nil + }, + RootCalled: func() ([]byte, error) { + return nil, nil + }, + }) + + accDB := &stateMock.AccountsStub{ + GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { + return accnt, nil, nil + }, + RecreateTrieCalled: func(rootHash []byte) error { + return nil + }, + } + + coreComponents := getDefaultCoreComponents() + dataComponents := getDefaultDataComponents() + stateComponents := getDefaultStateComponents() + args := state.ArgsAccountsRepository{ + FinalStateAccountsWrapper: accDB, + CurrentStateAccountsWrapper: accDB, + HistoricalStateAccountsWrapper: accDB, + } + stateComponents.AccountsRepo, _ = state.NewAccountsRepository(args) + n, _ := node.NewNode( + node.WithCoreComponents(coreComponents), + node.WithDataComponents(dataComponents), + node.WithStateComponents(stateComponents), + ) + + recovAccnt, _, err := n.GetAccount(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: false}, context.Background()) + require.Nil(t, err) + require.Nil(t, recovAccnt.Pairs) + + recovAccnt, _, err = n.GetAccount(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: true}, context.Background()) + + require.Nil(t, err) + require.NotNil(t, recovAccnt.Pairs) + require.Equal(t, 2, len(recovAccnt.Pairs)) + require.Equal(t, hex.EncodeToString(v1), recovAccnt.Pairs[hex.EncodeToString(k1)]) + require.Equal(t, hex.EncodeToString(v2), recovAccnt.Pairs[hex.EncodeToString(k2)]) +} + func TestNode_AppStatusHandlersShouldIncrement(t *testing.T) { t.Parallel() From ddb907c7b739905d778d7e4902affe2dbb07efa1 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Fri, 19 Apr 2024 16:59:05 +0300 Subject: [PATCH 181/503] - fixed the initialization of the chain simulator when working with 0 value activation epochs --- epochStart/metachain/legacySystemSCs.go | 3 +- errors/errors.go | 3 + .../disabled/epochStartSystemSCProcessor.go | 42 ++++++++++++++ factory/interface.go | 1 + factory/mock/processComponentsStub.go | 6 ++ factory/processing/blockProcessorCreator.go | 3 + .../processing/blockProcessorCreator_test.go | 7 ++- factory/processing/export_test.go | 6 +- factory/processing/processComponents.go | 2 + .../processing/processComponentsHandler.go | 15 +++++ .../processComponentsHandler_test.go | 2 + .../stakingProvider/delegation_test.go | 58 +++++++++++++++++++ .../mock/processComponentsStub.go | 6 ++ node/chainSimulator/chainSimulator.go | 33 +++++++++-- .../components/processComponents.go | 7 +++ .../components/processComponents_test.go | 1 + .../components/testOnlyProcessingNode.go | 5 ++ node/chainSimulator/process/interface.go | 1 + testscommon/chainSimulator/nodeHandlerMock.go | 9 +++ 19 files changed, 200 insertions(+), 10 deletions(-) create mode 100644 factory/disabled/epochStartSystemSCProcessor.go diff --git a/epochStart/metachain/legacySystemSCs.go b/epochStart/metachain/legacySystemSCs.go index 677cbcb682b..0db6a39916f 100644 --- a/epochStart/metachain/legacySystemSCs.go +++ b/epochStart/metachain/legacySystemSCs.go @@ -151,7 +151,8 @@ func (s *legacySystemSCProcessor) processLegacy( } } - if s.flagChangeMaxNodesEnabled.IsSet() { + // the updateMaxNodes call needs the StakingV2Flag functionality to be enabled. Otherwise, the call will error + if s.flagChangeMaxNodesEnabled.IsSet() && s.enableEpochsHandler.IsFlagEnabled(common.StakingV2Flag) { err := s.updateMaxNodes(validatorsInfoMap, nonce) if err != nil { return err diff --git a/errors/errors.go b/errors/errors.go index 771c65adc07..dd475327876 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -595,3 +595,6 @@ var ErrInvalidNodeOperationMode = errors.New("invalid node operation mode") // ErrNilSentSignatureTracker defines the error for setting a nil SentSignatureTracker var ErrNilSentSignatureTracker = errors.New("nil sent signature tracker") + +// ErrNilEpochSystemSCProcessor defines the error for setting a nil EpochSystemSCProcessor +var ErrNilEpochSystemSCProcessor = errors.New("nil epoch system SC processor") diff --git a/factory/disabled/epochStartSystemSCProcessor.go b/factory/disabled/epochStartSystemSCProcessor.go new file mode 100644 index 00000000000..7d9e8720a79 --- /dev/null +++ b/factory/disabled/epochStartSystemSCProcessor.go @@ -0,0 +1,42 @@ +package disabled + +import ( + "github.com/multiversx/mx-chain-core-go/data" + "github.com/multiversx/mx-chain-core-go/data/block" + "github.com/multiversx/mx-chain-go/epochStart" + "github.com/multiversx/mx-chain-go/state" +) + +type epochStartSystemSCProcessor struct { +} + +// NewDisabledEpochStartSystemSC creates a new disabled EpochStartSystemSCProcessor instance +func NewDisabledEpochStartSystemSC() *epochStartSystemSCProcessor { + return &epochStartSystemSCProcessor{} +} + +// ToggleUnStakeUnBond returns nil +func (e *epochStartSystemSCProcessor) ToggleUnStakeUnBond(_ bool) error { + return nil +} + +// ProcessSystemSmartContract returns nil +func (e *epochStartSystemSCProcessor) ProcessSystemSmartContract( + _ state.ShardValidatorsInfoMapHandler, + _ data.HeaderHandler, +) error { + return nil +} + +// ProcessDelegationRewards returns nil +func (e *epochStartSystemSCProcessor) ProcessDelegationRewards( + _ block.MiniBlockSlice, + _ epochStart.TransactionCacher, +) error { + return nil +} + +// IsInterfaceNil returns true if there is no value under the interface +func (e *epochStartSystemSCProcessor) IsInterfaceNil() bool { + return e == nil +} diff --git a/factory/interface.go b/factory/interface.go index ede9f39089b..0f1c237d0d9 100644 --- a/factory/interface.go +++ b/factory/interface.go @@ -310,6 +310,7 @@ type ProcessComponentsHolder interface { AccountsParser() genesis.AccountsParser ReceiptsRepository() ReceiptsRepository SentSignaturesTracker() process.SentSignaturesTracker + EpochSystemSCProcessor() process.EpochStartSystemSCProcessor IsInterfaceNil() bool } diff --git a/factory/mock/processComponentsStub.go b/factory/mock/processComponentsStub.go index e646958281c..32bbfaf2df3 100644 --- a/factory/mock/processComponentsStub.go +++ b/factory/mock/processComponentsStub.go @@ -57,6 +57,7 @@ type ProcessComponentsMock struct { AccountsParserInternal genesis.AccountsParser ReceiptsRepositoryInternal factory.ReceiptsRepository SentSignaturesTrackerInternal process.SentSignaturesTracker + EpochSystemSCProcessorInternal process.EpochStartSystemSCProcessor } // Create - @@ -284,6 +285,11 @@ func (pcm *ProcessComponentsMock) SentSignaturesTracker() process.SentSignatures return pcm.SentSignaturesTrackerInternal } +// EpochSystemSCProcessor - +func (pcm *ProcessComponentsMock) EpochSystemSCProcessor() process.EpochStartSystemSCProcessor { + return pcm.EpochSystemSCProcessorInternal +} + // IsInterfaceNil - func (pcm *ProcessComponentsMock) IsInterfaceNil() bool { return pcm == nil diff --git a/factory/processing/blockProcessorCreator.go b/factory/processing/blockProcessorCreator.go index 7db9e20cf7d..2cf54aaa955 100644 --- a/factory/processing/blockProcessorCreator.go +++ b/factory/processing/blockProcessorCreator.go @@ -50,6 +50,7 @@ import ( type blockProcessorAndVmFactories struct { blockProcessor process.BlockProcessor vmFactoryForProcessing process.VirtualMachinesContainerFactory + epochSystemSCProcessor process.EpochStartSystemSCProcessor } func (pcf *processComponentsFactory) newBlockProcessor( @@ -453,6 +454,7 @@ func (pcf *processComponentsFactory) newShardBlockProcessor( blockProcessorComponents := &blockProcessorAndVmFactories{ blockProcessor: blockProcessor, vmFactoryForProcessing: vmFactory, + epochSystemSCProcessor: factoryDisabled.NewDisabledEpochStartSystemSC(), } pcf.stakingDataProviderAPI = factoryDisabled.NewDisabledStakingDataProvider() @@ -982,6 +984,7 @@ func (pcf *processComponentsFactory) newMetaBlockProcessor( blockProcessorComponents := &blockProcessorAndVmFactories{ blockProcessor: metaProcessor, vmFactoryForProcessing: vmFactory, + epochSystemSCProcessor: epochStartSystemSCProcessor, } return blockProcessorComponents, nil diff --git a/factory/processing/blockProcessorCreator_test.go b/factory/processing/blockProcessorCreator_test.go index 3ecc3432f9e..099fec4a82d 100644 --- a/factory/processing/blockProcessorCreator_test.go +++ b/factory/processing/blockProcessorCreator_test.go @@ -1,6 +1,7 @@ package processing_test import ( + "fmt" "sync" "testing" @@ -40,7 +41,7 @@ func Test_newBlockProcessorCreatorForShard(t *testing.T) { _, err = pcf.Create() require.NoError(t, err) - bp, err := pcf.NewBlockProcessor( + bp, epochStartSCProc, err := pcf.NewBlockProcessor( &testscommon.RequestHandlerStub{}, &processMocks.ForkDetectorStub{}, &mock.EpochStartTriggerStub{}, @@ -60,6 +61,7 @@ func Test_newBlockProcessorCreatorForShard(t *testing.T) { require.NoError(t, err) require.NotNil(t, bp) + require.Equal(t, "*disabled.epochStartSystemSCProcessor", fmt.Sprintf("%T", epochStartSCProc)) } func Test_newBlockProcessorCreatorForMeta(t *testing.T) { @@ -166,7 +168,7 @@ func Test_newBlockProcessorCreatorForMeta(t *testing.T) { _, err = pcf.Create() require.NoError(t, err) - bp, err := pcf.NewBlockProcessor( + bp, epochStartSCProc, err := pcf.NewBlockProcessor( &testscommon.RequestHandlerStub{}, &processMocks.ForkDetectorStub{}, &mock.EpochStartTriggerStub{}, @@ -186,6 +188,7 @@ func Test_newBlockProcessorCreatorForMeta(t *testing.T) { require.NoError(t, err) require.NotNil(t, bp) + require.Equal(t, "*metachain.systemSCProcessor", fmt.Sprintf("%T", epochStartSCProc)) } func createAccountAdapter( diff --git a/factory/processing/export_test.go b/factory/processing/export_test.go index 50c5123634c..76e84d75fee 100644 --- a/factory/processing/export_test.go +++ b/factory/processing/export_test.go @@ -25,7 +25,7 @@ func (pcf *processComponentsFactory) NewBlockProcessor( blockProcessingCutoff cutoff.BlockProcessingCutoffHandler, missingTrieNodesNotifier common.MissingTrieNodesNotifier, sentSignaturesTracker process.SentSignaturesTracker, -) (process.BlockProcessor, error) { +) (process.BlockProcessor, process.EpochStartSystemSCProcessor, error) { blockProcessorComponents, err := pcf.newBlockProcessor( requestHandler, forkDetector, @@ -44,10 +44,10 @@ func (pcf *processComponentsFactory) NewBlockProcessor( sentSignaturesTracker, ) if err != nil { - return nil, err + return nil, nil, err } - return blockProcessorComponents.blockProcessor, nil + return blockProcessorComponents.blockProcessor, blockProcessorComponents.epochSystemSCProcessor, nil } // CreateAPITransactionEvaluator - diff --git a/factory/processing/processComponents.go b/factory/processing/processComponents.go index 72d75c69dc3..352343ce102 100644 --- a/factory/processing/processComponents.go +++ b/factory/processing/processComponents.go @@ -131,6 +131,7 @@ type processComponents struct { accountsParser genesis.AccountsParser receiptsRepository mainFactory.ReceiptsRepository sentSignaturesTracker process.SentSignaturesTracker + epochSystemSCProcessor process.EpochStartSystemSCProcessor } // ProcessComponentsFactoryArgs holds the arguments needed to create a process components factory @@ -751,6 +752,7 @@ func (pcf *processComponentsFactory) Create() (*processComponents, error) { currentEpochProvider: currentEpochProvider, vmFactoryForTxSimulator: vmFactoryForTxSimulate, vmFactoryForProcessing: blockProcessorComponents.vmFactoryForProcessing, + epochSystemSCProcessor: blockProcessorComponents.epochSystemSCProcessor, scheduledTxsExecutionHandler: scheduledTxsExecutionHandler, txsSender: txsSenderWithAccumulator, hardforkTrigger: hardforkTrigger, diff --git a/factory/processing/processComponentsHandler.go b/factory/processing/processComponentsHandler.go index a5b71ca3b28..28b3c4b0eed 100644 --- a/factory/processing/processComponentsHandler.go +++ b/factory/processing/processComponentsHandler.go @@ -177,6 +177,9 @@ func (m *managedProcessComponents) CheckSubcomponents() error { if check.IfNil(m.processComponents.sentSignaturesTracker) { return errors.ErrNilSentSignatureTracker } + if check.IfNil(m.processComponents.epochSystemSCProcessor) { + return errors.ErrNilEpochSystemSCProcessor + } return nil } @@ -673,6 +676,18 @@ func (m *managedProcessComponents) SentSignaturesTracker() process.SentSignature return m.processComponents.sentSignaturesTracker } +// EpochSystemSCProcessor returns the epoch start system SC processor +func (m *managedProcessComponents) EpochSystemSCProcessor() process.EpochStartSystemSCProcessor { + m.mutProcessComponents.RLock() + defer m.mutProcessComponents.RUnlock() + + if m.processComponents == nil { + return nil + } + + return m.processComponents.epochSystemSCProcessor +} + // IsInterfaceNil returns true if the interface is nil func (m *managedProcessComponents) IsInterfaceNil() bool { return m == nil diff --git a/factory/processing/processComponentsHandler_test.go b/factory/processing/processComponentsHandler_test.go index 36638afacfd..2aec3cb8c6e 100644 --- a/factory/processing/processComponentsHandler_test.go +++ b/factory/processing/processComponentsHandler_test.go @@ -93,6 +93,7 @@ func TestManagedProcessComponents_Create(t *testing.T) { require.True(t, check.IfNil(managedProcessComponents.FullArchivePeerShardMapper())) require.True(t, check.IfNil(managedProcessComponents.FullArchiveInterceptorsContainer())) require.True(t, check.IfNil(managedProcessComponents.SentSignaturesTracker())) + require.True(t, check.IfNil(managedProcessComponents.EpochSystemSCProcessor())) err := managedProcessComponents.Create() require.NoError(t, err) @@ -137,6 +138,7 @@ func TestManagedProcessComponents_Create(t *testing.T) { require.False(t, check.IfNil(managedProcessComponents.FullArchivePeerShardMapper())) require.False(t, check.IfNil(managedProcessComponents.FullArchiveInterceptorsContainer())) require.False(t, check.IfNil(managedProcessComponents.SentSignaturesTracker())) + require.False(t, check.IfNil(managedProcessComponents.EpochSystemSCProcessor())) require.Equal(t, factory.ProcessComponentsName, managedProcessComponents.String()) }) diff --git a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index 653ab74f031..e61166264bb 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go @@ -83,6 +83,13 @@ func TestChainSimulator_MakeNewContractFromValidatorData(t *testing.T) { NumNodesWaitingListMeta: 3, NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { + maxNodesChangeEnableEpoch := cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch + blsMultiSignerEnableEpoch := cfg.EpochConfig.EnableEpochs.BLSMultiSignerEnableEpoch + + cfg.EpochConfig.EnableEpochs = config.EnableEpochs{} + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch = maxNodesChangeEnableEpoch + cfg.EpochConfig.EnableEpochs.BLSMultiSignerEnableEpoch = blsMultiSignerEnableEpoch + cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 102 @@ -98,6 +105,57 @@ func TestChainSimulator_MakeNewContractFromValidatorData(t *testing.T) { testChainSimulatorMakeNewContractFromValidatorData(t, cs, 1) }) + // Test scenario done in staking 3.5 phase (staking v4 is not active) + // 1. Add a new validator private key in the multi key handler + // 2. Set the initial state for the owner and the 2 delegators + // 3. Do a stake transaction for the validator key and test that the new key is on queue and topup is 500 + // 4. Execute the MakeNewContractFromValidatorData transaction and test that the key is on queue and topup is 500 + // 5. Execute 2 delegation operations of 100 EGLD each, check the topup is 700 + // 6. Execute 2 unDelegate operations of 100 EGLD each, check the topup is back to 500 + t.Run("staking ph 4 is not active and all is done in epoch 0", func(t *testing.T) { + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, + AlterConfigsFunction: func(cfg *config.Configs) { + maxNodesChangeEnableEpoch := cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch + blsMultiSignerEnableEpoch := cfg.EpochConfig.EnableEpochs.BLSMultiSignerEnableEpoch + + // set all activation epoch values on 0 + cfg.EpochConfig.EnableEpochs = config.EnableEpochs{} + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch = maxNodesChangeEnableEpoch + cfg.EpochConfig.EnableEpochs.BLSMultiSignerEnableEpoch = blsMultiSignerEnableEpoch + + cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 + cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 + cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 102 + + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 102 + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + // we need a little time to enable the VM queries on the http server + time.Sleep(time.Second) + // also, propose a couple of blocks + err = cs.GenerateBlocks(3) + require.Nil(t, err) + + testChainSimulatorMakeNewContractFromValidatorData(t, cs, 0) + }) + // Test scenario done in staking v4 phase step 1 // 1. Add a new validator private key in the multi key handler // 2. Set the initial state for the owner and the 2 delegators diff --git a/integrationTests/mock/processComponentsStub.go b/integrationTests/mock/processComponentsStub.go index e0407b5d6f9..11d4f4ce69d 100644 --- a/integrationTests/mock/processComponentsStub.go +++ b/integrationTests/mock/processComponentsStub.go @@ -60,6 +60,7 @@ type ProcessComponentsStub struct { ReceiptsRepositoryInternal factory.ReceiptsRepository ESDTDataStorageHandlerForAPIInternal vmcommon.ESDTNFTStorageHandler SentSignaturesTrackerInternal process.SentSignaturesTracker + EpochSystemSCProcessorInternal process.EpochStartSystemSCProcessor } // Create - @@ -296,6 +297,11 @@ func (pcs *ProcessComponentsStub) SentSignaturesTracker() process.SentSignatures return pcs.SentSignaturesTrackerInternal } +// EpochSystemSCProcessor - +func (pcs *ProcessComponentsStub) EpochSystemSCProcessor() process.EpochStartSystemSCProcessor { + return pcs.EpochSystemSCProcessorInternal +} + // IsInterfaceNil - func (pcs *ProcessComponentsStub) IsInterfaceNil() bool { return pcs == nil diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index 8bffcb6c63a..4a0bfcb636e 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -130,6 +130,31 @@ func (s *simulator) createChainHandlers(args ArgsChainSimulator) error { shardID := node.GetShardCoordinator().SelfId() s.nodes[shardID] = node s.handlers = append(s.handlers, chainHandler) + + if node.GetShardCoordinator().SelfId() == core.MetachainShardId { + currentRootHash, errRootHash := node.GetProcessComponents().ValidatorsStatistics().RootHash() + if errRootHash != nil { + return errRootHash + } + + allValidatorsInfo, errGet := node.GetProcessComponents().ValidatorsStatistics().GetValidatorInfoForRootHash(currentRootHash) + if errRootHash != nil { + return errGet + } + + err = node.GetProcessComponents().EpochSystemSCProcessor().ProcessSystemSmartContract( + allValidatorsInfo, + node.GetDataComponents().Blockchain().GetGenesisHeader(), + ) + if err != nil { + return err + } + + _, err = node.GetStateComponents().AccountsAdapter().Commit() + if err != nil { + return err + } + } } s.initialWalletKeys = outputConfigs.InitialWallets @@ -411,17 +436,17 @@ func (s *simulator) SetStateMultiple(stateSlice []*dtos.AddressState) error { defer s.mutex.Unlock() addressConverter := s.nodes[core.MetachainShardId].GetCoreComponents().AddressPubKeyConverter() - for _, state := range stateSlice { - addressBytes, err := addressConverter.Decode(state.Address) + for _, stateValue := range stateSlice { + addressBytes, err := addressConverter.Decode(stateValue.Address) if err != nil { return err } if bytes.Equal(addressBytes, core.SystemAccountAddress) { - err = s.setStateSystemAccount(state) + err = s.setStateSystemAccount(stateValue) } else { shardID := sharding.ComputeShardID(addressBytes, s.numOfShards) - err = s.nodes[shardID].SetStateForAddress(addressBytes, state) + err = s.nodes[shardID].SetStateForAddress(addressBytes, stateValue) } if err != nil { return err diff --git a/node/chainSimulator/components/processComponents.go b/node/chainSimulator/components/processComponents.go index efa7af79c10..3bfd598f98d 100644 --- a/node/chainSimulator/components/processComponents.go +++ b/node/chainSimulator/components/processComponents.go @@ -98,6 +98,7 @@ type processComponentsHolder struct { esdtDataStorageHandlerForAPI vmcommon.ESDTNFTStorageHandler accountsParser genesis.AccountsParser sentSignatureTracker process.SentSignaturesTracker + epochStartSystemSCProcessor process.EpochStartSystemSCProcessor managedProcessComponentsCloser io.Closer } @@ -270,6 +271,7 @@ func CreateProcessComponents(args ArgsProcessComponentsHolder) (*processComponen esdtDataStorageHandlerForAPI: managedProcessComponents.ESDTDataStorageHandlerForAPI(), accountsParser: managedProcessComponents.AccountsParser(), sentSignatureTracker: managedProcessComponents.SentSignaturesTracker(), + epochStartSystemSCProcessor: managedProcessComponents.EpochSystemSCProcessor(), managedProcessComponentsCloser: managedProcessComponents, } @@ -481,6 +483,11 @@ func (p *processComponentsHolder) ReceiptsRepository() factory.ReceiptsRepositor return p.receiptsRepository } +// EpochSystemSCProcessor returns the epoch start system SC processor +func (p *processComponentsHolder) EpochSystemSCProcessor() process.EpochStartSystemSCProcessor { + return p.epochStartSystemSCProcessor +} + // Close will call the Close methods on all inner components func (p *processComponentsHolder) Close() error { return p.managedProcessComponentsCloser.Close() diff --git a/node/chainSimulator/components/processComponents_test.go b/node/chainSimulator/components/processComponents_test.go index 4628bbc4f66..efc5590e7f4 100644 --- a/node/chainSimulator/components/processComponents_test.go +++ b/node/chainSimulator/components/processComponents_test.go @@ -407,6 +407,7 @@ func TestProcessComponentsHolder_Getters(t *testing.T) { require.NotNil(t, comp.ESDTDataStorageHandlerForAPI()) require.NotNil(t, comp.AccountsParser()) require.NotNil(t, comp.ReceiptsRepository()) + require.NotNil(t, comp.EpochSystemSCProcessor()) require.Nil(t, comp.CheckSubcomponents()) require.Empty(t, comp.String()) diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index e08f4fc1367..7b375ae08cb 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -370,6 +370,11 @@ func (node *testOnlyProcessingNode) GetCoreComponents() factory.CoreComponentsHo return node.CoreComponentsHolder } +// GetDataComponents will return the data components +func (node *testOnlyProcessingNode) GetDataComponents() factory.DataComponentsHolder { + return node.DataComponentsHolder +} + // GetStateComponents will return the state components func (node *testOnlyProcessingNode) GetStateComponents() factory.StateComponentsHolder { return node.StateComponentsHolder diff --git a/node/chainSimulator/process/interface.go b/node/chainSimulator/process/interface.go index 6dc0b84fa02..ee54998dc7f 100644 --- a/node/chainSimulator/process/interface.go +++ b/node/chainSimulator/process/interface.go @@ -17,6 +17,7 @@ type NodeHandler interface { GetShardCoordinator() sharding.Coordinator GetCryptoComponents() factory.CryptoComponentsHolder GetCoreComponents() factory.CoreComponentsHolder + GetDataComponents() factory.DataComponentsHolder GetStateComponents() factory.StateComponentsHolder GetFacadeHandler() shared.FacadeHandler GetStatusCoreComponents() factory.StatusCoreComponentsHolder diff --git a/testscommon/chainSimulator/nodeHandlerMock.go b/testscommon/chainSimulator/nodeHandlerMock.go index 23941f914eb..52b72a17acc 100644 --- a/testscommon/chainSimulator/nodeHandlerMock.go +++ b/testscommon/chainSimulator/nodeHandlerMock.go @@ -17,6 +17,7 @@ type NodeHandlerMock struct { GetShardCoordinatorCalled func() sharding.Coordinator GetCryptoComponentsCalled func() factory.CryptoComponentsHolder GetCoreComponentsCalled func() factory.CoreComponentsHolder + GetDataComponentsCalled func() factory.DataComponentsHandler GetStateComponentsCalled func() factory.StateComponentsHolder GetFacadeHandlerCalled func() shared.FacadeHandler GetStatusCoreComponentsCalled func() factory.StatusCoreComponentsHolder @@ -73,6 +74,14 @@ func (mock *NodeHandlerMock) GetCoreComponents() factory.CoreComponentsHolder { return nil } +// GetDataComponents - +func (mock *NodeHandlerMock) GetDataComponents() factory.DataComponentsHolder { + if mock.GetDataComponentsCalled != nil { + return mock.GetDataComponentsCalled() + } + return nil +} + // GetStateComponents - func (mock *NodeHandlerMock) GetStateComponents() factory.StateComponentsHolder { if mock.GetStateComponentsCalled != nil { From bcd6efca6ce8150da9f5f895d06e80d59caf4d86 Mon Sep 17 00:00:00 2001 From: radu chis Date: Mon, 22 Apr 2024 15:33:18 +0300 Subject: [PATCH 182/503] refactored withKeys --- api/groups/addressGroup.go | 8 ++++ api/groups/addressGroupOptions.go | 7 +-- facade/interface.go | 6 ++- facade/mock/nodeStub.go | 16 +++++-- facade/nodeFacade.go | 36 +++++++++------ facade/nodeFacade_test.go | 14 +++--- go.mod | 2 +- go.sum | 4 +- .../node/getAccount/getAccount_test.go | 5 +-- node/node.go | 45 ++++++++++++++++++- node/nodeLoadAccounts_test.go | 3 +- node/node_test.go | 14 +++--- 12 files changed, 113 insertions(+), 47 deletions(-) diff --git a/api/groups/addressGroup.go b/api/groups/addressGroup.go index da2adc0ab56..a059d3a4388 100644 --- a/api/groups/addressGroup.go +++ b/api/groups/addressGroup.go @@ -186,6 +186,14 @@ func (ag *addressGroup) getAccount(c *gin.Context) { return } + withKeys, err := parseBoolUrlParam(c, urlParamWithKeys) + if err != nil { + shared.RespondWithValidationError(c, errors.ErrCouldNotGetAccount, err) + return + } + + options.WithKeys = withKeys + accountResponse, blockInfo, err := ag.getFacade().GetAccount(addr, options) if err != nil { shared.RespondWithInternalError(c, errors.ErrCouldNotGetAccount, err) diff --git a/api/groups/addressGroupOptions.go b/api/groups/addressGroupOptions.go index c3841f7e7fd..e21dc6d361a 100644 --- a/api/groups/addressGroupOptions.go +++ b/api/groups/addressGroupOptions.go @@ -54,11 +54,6 @@ func parseAccountQueryOptions(c *gin.Context) (api.AccountQueryOptions, error) { return api.AccountQueryOptions{}, err } - withKeys, err := parseBoolUrlParam(c, urlParamWithKeys) - if err != nil { - return api.AccountQueryOptions{}, err - } - options := api.AccountQueryOptions{ OnFinalBlock: onFinalBlock, OnStartOfEpoch: onStartOfEpoch, @@ -66,7 +61,7 @@ func parseAccountQueryOptions(c *gin.Context) (api.AccountQueryOptions, error) { BlockHash: blockHash, BlockRootHash: blockRootHash, HintEpoch: hintEpoch, - WithKeys: withKeys, + WithKeys: false, } return options, nil } diff --git a/facade/interface.go b/facade/interface.go index b7deebb17e7..e3be7b76cb0 100644 --- a/facade/interface.go +++ b/facade/interface.go @@ -74,7 +74,11 @@ type NodeHandler interface { // GetAccount returns an accountResponse containing information // about the account correlated with provided address - GetAccount(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) + GetAccount(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) + + // GetAccountWithKeys returns an accountResponse containing information + // about the account correlated with provided address and all keys + GetAccountWithKeys(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) // GetCode returns the code for the given code hash GetCode(codeHash []byte, options api.AccountQueryOptions) ([]byte, api.BlockInfo) diff --git a/facade/mock/nodeStub.go b/facade/mock/nodeStub.go index d03d847b151..1e779e0ebce 100644 --- a/facade/mock/nodeStub.go +++ b/facade/mock/nodeStub.go @@ -25,7 +25,8 @@ type NodeStub struct { ValidateTransactionHandler func(tx *transaction.Transaction) error ValidateTransactionForSimulationCalled func(tx *transaction.Transaction, bypassSignature bool) error SendBulkTransactionsHandler func(txs []*transaction.Transaction) (uint64, error) - GetAccountCalled func(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) + GetAccountCalled func(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) + GetAccountWithKeysCalled func(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) GetCodeCalled func(codeHash []byte, options api.AccountQueryOptions) ([]byte, api.BlockInfo) GetCurrentPublicKeyHandler func() string GenerateAndSendBulkTransactionsHandler func(destination string, value *big.Int, nrTransactions uint64) error @@ -181,9 +182,18 @@ func (ns *NodeStub) SendBulkTransactions(txs []*transaction.Transaction) (uint64 } // GetAccount - -func (ns *NodeStub) GetAccount(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) { +func (ns *NodeStub) GetAccount(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { if ns.GetAccountCalled != nil { - return ns.GetAccountCalled(address, options, ctx) + return ns.GetAccountCalled(address, options) + } + + return api.AccountResponse{}, api.BlockInfo{}, nil +} + +// GetAccountWithKeys - +func (ns *NodeStub) GetAccountWithKeys(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) { + if ns.GetAccountWithKeysCalled != nil { + return ns.GetAccountWithKeysCalled(address, options, ctx) } return api.AccountResponse{}, api.BlockInfo{}, nil diff --git a/facade/nodeFacade.go b/facade/nodeFacade.go index 4e328b5462a..8bc696b6adc 100644 --- a/facade/nodeFacade.go +++ b/facade/nodeFacade.go @@ -321,10 +321,7 @@ func (nf *nodeFacade) GetLastPoolNonceForSender(sender string) (uint64, error) { // GetTransactionsPoolNonceGapsForSender will return the nonce gaps from pool for sender, if exists, that is to be returned on API calls func (nf *nodeFacade) GetTransactionsPoolNonceGapsForSender(sender string) (*common.TransactionsPoolNonceGapsForSenderApiResponse, error) { - ctx, cancel := nf.getContextForApiTrieRangeOperations() - defer cancel() - - accountResponse, _, err := nf.node.GetAccount(sender, apiData.AccountQueryOptions{}, ctx) + accountResponse, _, err := nf.node.GetAccount(sender, apiData.AccountQueryOptions{}) if err != nil { return &common.TransactionsPoolNonceGapsForSenderApiResponse{}, err } @@ -339,10 +336,19 @@ func (nf *nodeFacade) ComputeTransactionGasLimit(tx *transaction.Transaction) (* // GetAccount returns a response containing information about the account correlated with provided address func (nf *nodeFacade) GetAccount(address string, options apiData.AccountQueryOptions) (apiData.AccountResponse, apiData.BlockInfo, error) { - ctx, cancel := nf.getContextForApiTrieRangeOperations() - defer cancel() + var accountResponse apiData.AccountResponse + var blockInfo apiData.BlockInfo + var err error + + if options.WithKeys { + ctx, cancel := nf.getContextForApiTrieRangeOperations() + defer cancel() + + accountResponse, blockInfo, err = nf.node.GetAccountWithKeys(address, options, ctx) + } else { + accountResponse, blockInfo, err = nf.node.GetAccount(address, options) + } - accountResponse, blockInfo, err := nf.node.GetAccount(address, options, ctx) if err != nil { return apiData.AccountResponse{}, apiData.BlockInfo{}, err } @@ -364,16 +370,20 @@ func (nf *nodeFacade) GetAccounts(addresses []string, options apiData.AccountQue response := make(map[string]*apiData.AccountResponse) var blockInfo apiData.BlockInfo - ctx, cancel := nf.getContextForApiTrieRangeOperations() - defer cancel() - for _, address := range addresses { - accountResponse, blockInfoForAccount, err := nf.node.GetAccount(address, options, ctx) + for i, address := range addresses { + accountResponse, blockInfoForAccount, err := nf.node.GetAccount(address, options) if err != nil { return nil, apiData.BlockInfo{}, err } - - blockInfo = blockInfoForAccount + // Use the first block info as the block info for the whole bulk + if i == 0 { + blockInfo = blockInfoForAccount + blockRootHash, errBlockRootHash := hex.DecodeString(blockInfoForAccount.RootHash) + if errBlockRootHash == nil { + options.BlockRootHash = blockRootHash + } + } codeHash := accountResponse.CodeHash code, _ := nf.node.GetCode(codeHash, options) diff --git a/facade/nodeFacade_test.go b/facade/nodeFacade_test.go index f2eaff6025e..21823b60b6e 100644 --- a/facade/nodeFacade_test.go +++ b/facade/nodeFacade_test.go @@ -338,7 +338,7 @@ func TestNodeFacade_GetAccount(t *testing.T) { arg := createMockArguments() arg.Node = &mock.NodeStub{ - GetAccountCalled: func(_ string, _ api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { + GetAccountCalled: func(_ string, _ api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { return api.AccountResponse{}, api.BlockInfo{}, expectedErr }, } @@ -352,7 +352,7 @@ func TestNodeFacade_GetAccount(t *testing.T) { getAccountCalled := false node := &mock.NodeStub{} - node.GetAccountCalled = func(address string, _ api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { + node.GetAccountCalled = func(address string, _ api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { getAccountCalled = true return api.AccountResponse{}, api.BlockInfo{}, nil } @@ -387,7 +387,7 @@ func TestNodeFacade_GetAccounts(t *testing.T) { t.Parallel() node := &mock.NodeStub{} - node.GetAccountCalled = func(address string, _ api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { + node.GetAccountCalled = func(address string, _ api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { return api.AccountResponse{}, api.BlockInfo{}, expectedErr } @@ -407,7 +407,7 @@ func TestNodeFacade_GetAccounts(t *testing.T) { expectedAcount := api.AccountResponse{Address: "test"} node := &mock.NodeStub{} - node.GetAccountCalled = func(address string, _ api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { + node.GetAccountCalled = func(address string, _ api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { return expectedAcount, api.BlockInfo{}, nil } @@ -2008,7 +2008,7 @@ func TestNodeFacade_GetTransactionsPoolNonceGapsForSender(t *testing.T) { arg := createMockArguments() arg.Node = &mock.NodeStub{ - GetAccountCalled: func(address string, options api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { + GetAccountCalled: func(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { return api.AccountResponse{}, api.BlockInfo{}, expectedErr }, } @@ -2030,7 +2030,7 @@ func TestNodeFacade_GetTransactionsPoolNonceGapsForSender(t *testing.T) { arg := createMockArguments() arg.Node = &mock.NodeStub{ - GetAccountCalled: func(address string, options api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { + GetAccountCalled: func(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { return api.AccountResponse{}, api.BlockInfo{}, nil }, } @@ -2062,7 +2062,7 @@ func TestNodeFacade_GetTransactionsPoolNonceGapsForSender(t *testing.T) { } providedNonce := uint64(10) arg.Node = &mock.NodeStub{ - GetAccountCalled: func(address string, options api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { + GetAccountCalled: func(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { return api.AccountResponse{Nonce: providedNonce}, api.BlockInfo{}, nil }, } diff --git a/go.mod b/go.mod index b5d8fd684c6..f8454ef4f3a 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.14 - github.com/multiversx/mx-chain-core-go v1.2.20-0.20240418121049-6970013b49d9 + github.com/multiversx/mx-chain-core-go v1.2.20 github.com/multiversx/mx-chain-crypto-go v1.2.11 github.com/multiversx/mx-chain-es-indexer-go v1.4.21 github.com/multiversx/mx-chain-logger-go v1.0.14 diff --git a/go.sum b/go.sum index 64517c9b404..03321b70303 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.14 h1:YhAUDjBBpc5h5W0A7LHLXUMIMeCgwgGvkqfAPbFqsno= github.com/multiversx/mx-chain-communication-go v1.0.14/go.mod h1:qYCqgk0h+YpcTA84jHIpCBy6UShRwmXzHSCcdfwNrkw= -github.com/multiversx/mx-chain-core-go v1.2.20-0.20240418121049-6970013b49d9 h1:iUGEUzmxh2xrgaHS9Lq5CpnKGDsR02v9gEWroc/jbpA= -github.com/multiversx/mx-chain-core-go v1.2.20-0.20240418121049-6970013b49d9/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.20 h1:jOQ10LxxUqECnuqUYeBBT6VoZcpJDdYgOvsSGtifDdI= +github.com/multiversx/mx-chain-core-go v1.2.20/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.11 h1:MNPJoiTJA5/tedYrI0N22OorbsKDESWG0SF8MCJwcJI= github.com/multiversx/mx-chain-crypto-go v1.2.11/go.mod h1:pcZutPdfLiAFytzCU3LxU3s8cXkvpNqquyitFSfoF3o= github.com/multiversx/mx-chain-es-indexer-go v1.4.21 h1:rzxXCkgOsqj67GRYtqzKuf9XgHwnZLTZhU90Ck3VbrE= diff --git a/integrationTests/node/getAccount/getAccount_test.go b/integrationTests/node/getAccount/getAccount_test.go index c48a1017a4e..487c8b1a15a 100644 --- a/integrationTests/node/getAccount/getAccount_test.go +++ b/integrationTests/node/getAccount/getAccount_test.go @@ -1,7 +1,6 @@ package getAccount import ( - "context" "math/big" "testing" @@ -58,7 +57,7 @@ func TestNode_GetAccountAccountDoesNotExistsShouldRetEmpty(t *testing.T) { encodedAddress, err := integrationTests.TestAddressPubkeyConverter.Encode(integrationTests.CreateRandomBytes(32)) require.Nil(t, err) - recovAccnt, _, err := n.GetAccount(encodedAddress, api.AccountQueryOptions{}, context.Background()) + recovAccnt, _, err := n.GetAccount(encodedAddress, api.AccountQueryOptions{}) require.Nil(t, err) assert.Equal(t, uint64(0), recovAccnt.Nonce) @@ -100,7 +99,7 @@ func TestNode_GetAccountAccountExistsShouldReturn(t *testing.T) { testAddress, err := coreComponents.AddressPubKeyConverter().Encode(testPubkey) require.Nil(t, err) - recovAccnt, _, err := n.GetAccount(testAddress, api.AccountQueryOptions{}, context.Background()) + recovAccnt, _, err := n.GetAccount(testAddress, api.AccountQueryOptions{}) require.Nil(t, err) require.Equal(t, testNonce, recovAccnt.Nonce) diff --git a/node/node.go b/node/node.go index 29cea2671d6..db2031a37ca 100644 --- a/node/node.go +++ b/node/node.go @@ -938,7 +938,45 @@ func (n *Node) setTxGuardianData(guardian string, guardianSigHex string, tx *tra } // GetAccount will return account details for a given address -func (n *Node) GetAccount(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) { +func (n *Node) GetAccount(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { + account, blockInfo, err := n.loadUserAccountHandlerByAddress(address, options) + if err != nil { + adaptedBlockInfo, isEmptyAccount := extractBlockInfoIfNewAccount(err) + if isEmptyAccount { + return api.AccountResponse{ + Address: address, + Balance: "0", + DeveloperReward: "0", + }, adaptedBlockInfo, nil + } + + return api.AccountResponse{}, api.BlockInfo{}, err + } + + ownerAddress := "" + if len(account.GetOwnerAddress()) > 0 { + addressPubkeyConverter := n.coreComponents.AddressPubKeyConverter() + ownerAddress, err = addressPubkeyConverter.Encode(account.GetOwnerAddress()) + if err != nil { + return api.AccountResponse{}, api.BlockInfo{}, err + } + } + + return api.AccountResponse{ + Address: address, + Nonce: account.GetNonce(), + Balance: account.GetBalance().String(), + Username: string(account.GetUserName()), + CodeHash: account.GetCodeHash(), + RootHash: account.GetRootHash(), + CodeMetadata: account.GetCodeMetadata(), + DeveloperReward: account.GetDeveloperReward().String(), + OwnerAddress: ownerAddress, + }, blockInfo, nil +} + +// GetAccountWithKeys will return account details for a given address including the keys +func (n *Node) GetAccountWithKeys(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) { account, blockInfo, err := n.loadUserAccountHandlerByAddress(address, options) if err != nil { adaptedBlockInfo, isEmptyAccount := extractBlockInfoIfNewAccount(err) @@ -964,7 +1002,10 @@ func (n *Node) GetAccount(address string, options api.AccountQueryOptions, ctx c var keys map[string]string if options.WithKeys { - keys, _ = n.getKeys(account, ctx) + keys, err = n.getKeys(account, ctx) + if err != nil { + return api.AccountResponse{}, api.BlockInfo{}, err + } } return api.AccountResponse{ diff --git a/node/nodeLoadAccounts_test.go b/node/nodeLoadAccounts_test.go index 7ef831bca0f..e7e03c2d05b 100644 --- a/node/nodeLoadAccounts_test.go +++ b/node/nodeLoadAccounts_test.go @@ -2,7 +2,6 @@ package node_test import ( "bytes" - "context" "errors" "math/big" "testing" @@ -46,7 +45,7 @@ func TestNode_GetAccountWithOptionsShouldWork(t *testing.T) { node.WithStateComponents(stateComponents), ) - account, blockInfo, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}, context.Background()) + account, blockInfo, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}) require.Nil(t, err) require.Equal(t, "100", account.Balance) require.Equal(t, uint64(1), blockInfo.Nonce) diff --git a/node/node_test.go b/node/node_test.go index d10f79b67be..dc8b012734e 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -3293,7 +3293,7 @@ func TestNode_GetAccountPubkeyConverterFailsShouldErr(t *testing.T) { node.WithCoreComponents(coreComponents), ) - recovAccnt, _, err := n.GetAccount(createDummyHexAddress(64), api.AccountQueryOptions{}, context.Background()) + recovAccnt, _, err := n.GetAccount(createDummyHexAddress(64), api.AccountQueryOptions{}) assert.Empty(t, recovAccnt) assert.ErrorIs(t, err, errExpected) @@ -3320,7 +3320,7 @@ func TestNode_GetAccountAccountDoesNotExistsShouldRetEmpty(t *testing.T) { node.WithStateComponents(stateComponents), ) - account, blockInfo, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}, context.Background()) + account, blockInfo, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}) require.Nil(t, err) require.Equal(t, uint64(0), account.Nonce) @@ -3355,7 +3355,7 @@ func TestNode_GetAccountAccountsRepositoryFailsShouldErr(t *testing.T) { node.WithStateComponents(stateComponents), ) - recovAccnt, _, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}, context.Background()) + recovAccnt, _, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}) assert.Empty(t, recovAccnt) assert.NotNil(t, err) @@ -3394,7 +3394,7 @@ func TestNode_GetAccountAccNotFoundShouldReturnEmpty(t *testing.T) { node.WithStateComponents(stateComponents), ) - acc, bInfo, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}, context.Background()) + acc, bInfo, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}) require.Nil(t, err) require.Equal(t, dummyBlockInfo.apiResult(), bInfo) require.Equal(t, api.AccountResponse{Address: testscommon.TestAddressAlice, Balance: "0", DeveloperReward: "0"}, acc) @@ -3436,7 +3436,7 @@ func TestNode_GetAccountAccountExistsShouldReturn(t *testing.T) { node.WithStateComponents(stateComponents), ) - recovAccnt, _, err := n.GetAccount(testscommon.TestAddressBob, api.AccountQueryOptions{}, context.Background()) + recovAccnt, _, err := n.GetAccount(testscommon.TestAddressBob, api.AccountQueryOptions{}) require.Nil(t, err) require.Equal(t, uint64(2), recovAccnt.Nonce) @@ -3503,11 +3503,11 @@ func TestNode_GetAccountAccountWithKeysShouldReturn(t *testing.T) { node.WithStateComponents(stateComponents), ) - recovAccnt, _, err := n.GetAccount(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: false}, context.Background()) + recovAccnt, _, err := n.GetAccountWithKeys(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: false}, context.Background()) require.Nil(t, err) require.Nil(t, recovAccnt.Pairs) - recovAccnt, _, err = n.GetAccount(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: true}, context.Background()) + recovAccnt, _, err = n.GetAccountWithKeys(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: true}, context.Background()) require.Nil(t, err) require.NotNil(t, recovAccnt.Pairs) From ec6236c52bb80ddf867cb59d12506e52a0dfa6db Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Tue, 23 Apr 2024 11:03:36 +0300 Subject: [PATCH 183/503] - added RemoveAccounts feature on the chain simulator --- node/chainSimulator/chainSimulator.go | 37 ++++++ node/chainSimulator/chainSimulator_test.go | 115 ++++++++++++++++++ .../components/testOnlyProcessingNode.go | 12 ++ node/chainSimulator/process/interface.go | 1 + testscommon/chainSimulator/nodeHandlerMock.go | 10 ++ 5 files changed, 175 insertions(+) diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index 4a0bfcb636e..d70921984e3 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -456,6 +456,32 @@ func (s *simulator) SetStateMultiple(stateSlice []*dtos.AddressState) error { return nil } +// RemoveAccounts will try to remove all accounts data for the addresses provided +func (s *simulator) RemoveAccounts(addresses []string) error { + s.mutex.Lock() + defer s.mutex.Unlock() + + addressConverter := s.nodes[core.MetachainShardId].GetCoreComponents().AddressPubKeyConverter() + for _, address := range addresses { + addressBytes, err := addressConverter.Decode(address) + if err != nil { + return err + } + + if bytes.Equal(addressBytes, core.SystemAccountAddress) { + err = s.removeAllSystemAccounts() + } else { + shardID := sharding.ComputeShardID(addressBytes, s.numOfShards) + err = s.nodes[shardID].RemoveAccount(addressBytes) + } + if err != nil { + return err + } + } + + return nil +} + // SendTxAndGenerateBlockTilTxIsExecuted will send the provided transaction and generate block until the transaction is executed func (s *simulator) SendTxAndGenerateBlockTilTxIsExecuted(txToSend *transaction.Transaction, maxNumOfBlocksToGenerateWhenExecutingTx int) (*transaction.ApiTransactionResult, error) { result, err := s.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txToSend}, maxNumOfBlocksToGenerateWhenExecutingTx) @@ -581,6 +607,17 @@ func (s *simulator) setStateSystemAccount(state *dtos.AddressState) error { return nil } +func (s *simulator) removeAllSystemAccounts() error { + for shard, node := range s.nodes { + err := node.RemoveAccount(core.SystemAccountAddress) + if err != nil { + return fmt.Errorf("%w for shard %d", err, shard) + } + } + + return nil +} + // GetAccount will fetch the account of the provided address func (s *simulator) GetAccount(address dtos.WalletAddress) (api.AccountResponse, error) { destinationShardID := s.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index 1a65b37ff78..e4092a16b9c 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -264,6 +264,121 @@ func TestChainSimulator_SetEntireState(t *testing.T) { require.Equal(t, accountState.RootHash, base64.StdEncoding.EncodeToString(account.RootHash)) } +func TestChainSimulator_SetEntireStateWithRemoval(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 1, + MetaChainMinNodes: 1, + }) + require.Nil(t, err) + require.NotNil(t, chainSimulator) + + defer chainSimulator.Close() + + // activate the auto balancing tries so the results will be the same + err = chainSimulator.GenerateBlocks(30) + require.Nil(t, err) + + balance := "431271308732096033771131" + contractAddress := "erd1qqqqqqqqqqqqqpgqmzzm05jeav6d5qvna0q2pmcllelkz8xddz3syjszx5" + accountState := &dtos.AddressState{ + Address: contractAddress, + Nonce: new(uint64), + Balance: balance, + Code: "0061736d010000000129086000006000017f60027f7f017f60027f7f0060017f0060037f7f7f017f60037f7f7f0060017f017f0290020b03656e7619626967496e74476574556e7369676e6564417267756d656e74000303656e760f6765744e756d417267756d656e7473000103656e760b7369676e616c4572726f72000303656e76126d42756666657253746f726167654c6f6164000203656e76176d427566666572546f426967496e74556e7369676e6564000203656e76196d42756666657246726f6d426967496e74556e7369676e6564000203656e76136d42756666657253746f7261676553746f7265000203656e760f6d4275666665725365744279746573000503656e760e636865636b4e6f5061796d656e74000003656e7614626967496e7446696e697368556e7369676e6564000403656e7609626967496e744164640006030b0a010104070301000000000503010003060f027f0041a080080b7f0041a080080b074607066d656d6f7279020004696e697400110667657453756d00120361646400130863616c6c4261636b00140a5f5f646174615f656e6403000b5f5f686561705f6261736503010aca010a0e01017f4100100c2200100020000b1901017f419c8008419c800828020041016b220036020020000b1400100120004604400f0b4180800841191002000b16002000100c220010031a2000100c220010041a20000b1401017f100c2202200110051a2000200210061a0b1301017f100c220041998008410310071a20000b1401017f10084101100d100b210010102000100f0b0e0010084100100d1010100e10090b2201037f10084101100d100b210110102202100e220020002001100a20022000100f0b0300010b0b2f0200418080080b1c77726f6e67206e756d626572206f6620617267756d656e747373756d00419c80080b049cffffff", + CodeHash: "n9EviPlHS6EV+3Xp0YqP28T0IUfeAFRFBIRC1Jw6pyU=", + RootHash: "eqIumOaMn7G5cNSViK3XHZIW/C392ehfHxOZkHGp+Gc=", // root hash with auto balancing enabled + CodeMetadata: "BQY=", + Owner: "erd1ss6u80ruas2phpmr82r42xnkd6rxy40g9jl69frppl4qez9w2jpsqj8x97", + DeveloperRewards: "5401004999998", + Keys: map[string]string{ + "73756d": "0a", + }, + } + + err = chainSimulator.SetStateMultiple([]*dtos.AddressState{accountState}) + require.Nil(t, err) + + err = chainSimulator.GenerateBlocks(2) + require.Nil(t, err) + + nodeHandler := chainSimulator.GetNodeHandler(1) + scAddress, _ := nodeHandler.GetCoreComponents().AddressPubKeyConverter().Decode(contractAddress) + res, _, err := nodeHandler.GetFacadeHandler().ExecuteSCQuery(&process.SCQuery{ + ScAddress: scAddress, + FuncName: "getSum", + CallerAddr: nil, + BlockNonce: core.OptionalUint64{}, + }) + require.Nil(t, err) + + counterValue := big.NewInt(0).SetBytes(res.ReturnData[0]).Int64() + require.Equal(t, 10, int(counterValue)) + + account, _, err := nodeHandler.GetFacadeHandler().GetAccount(contractAddress, coreAPI.AccountQueryOptions{}) + require.Nil(t, err) + require.Equal(t, accountState.Balance, account.Balance) + require.Equal(t, accountState.DeveloperRewards, account.DeveloperReward) + require.Equal(t, accountState.Code, account.Code) + require.Equal(t, accountState.CodeHash, base64.StdEncoding.EncodeToString(account.CodeHash)) + require.Equal(t, accountState.CodeMetadata, base64.StdEncoding.EncodeToString(account.CodeMetadata)) + require.Equal(t, accountState.Owner, account.OwnerAddress) + require.Equal(t, accountState.RootHash, base64.StdEncoding.EncodeToString(account.RootHash)) + + // Now we remove the account + err = chainSimulator.RemoveAccounts([]string{contractAddress}) + require.Nil(t, err) + + err = chainSimulator.GenerateBlocks(2) + require.Nil(t, err) + + account, _, err = nodeHandler.GetFacadeHandler().GetAccount(contractAddress, coreAPI.AccountQueryOptions{}) + require.Nil(t, err) + require.Equal(t, "0", account.Balance) + require.Equal(t, "0", account.DeveloperReward) + require.Equal(t, "", account.Code) + require.Equal(t, "", base64.StdEncoding.EncodeToString(account.CodeHash)) + require.Equal(t, "", base64.StdEncoding.EncodeToString(account.CodeMetadata)) + require.Equal(t, "", account.OwnerAddress) + require.Equal(t, "", base64.StdEncoding.EncodeToString(account.RootHash)) + + // Set the state again + err = chainSimulator.SetStateMultiple([]*dtos.AddressState{accountState}) + require.Nil(t, err) + + err = chainSimulator.GenerateBlocks(2) + require.Nil(t, err) + + account, _, err = nodeHandler.GetFacadeHandler().GetAccount(contractAddress, coreAPI.AccountQueryOptions{}) + require.Nil(t, err) + + require.Equal(t, accountState.Balance, account.Balance) + require.Equal(t, accountState.DeveloperRewards, account.DeveloperReward) + require.Equal(t, accountState.Code, account.Code) + require.Equal(t, accountState.CodeHash, base64.StdEncoding.EncodeToString(account.CodeHash)) + require.Equal(t, accountState.CodeMetadata, base64.StdEncoding.EncodeToString(account.CodeMetadata)) + require.Equal(t, accountState.Owner, account.OwnerAddress) + require.Equal(t, accountState.RootHash, base64.StdEncoding.EncodeToString(account.RootHash)) + +} + func TestChainSimulator_GetAccount(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index 7b375ae08cb..1aec0201e6c 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -491,6 +491,18 @@ func (node *testOnlyProcessingNode) SetStateForAddress(address []byte, addressSt return err } +// RemoveAccount will remove the account for the given address +func (node *testOnlyProcessingNode) RemoveAccount(address []byte) error { + accountsAdapter := node.StateComponentsHolder.AccountsAdapter() + err := accountsAdapter.RemoveAccount(address) + if err != nil { + return err + } + + _, err = accountsAdapter.Commit() + return err +} + func setNonceAndBalanceForAccount(userAccount state.UserAccountHandler, nonce *uint64, balance string) error { if nonce != nil { // set nonce to zero diff --git a/node/chainSimulator/process/interface.go b/node/chainSimulator/process/interface.go index ee54998dc7f..d7b0f15820e 100644 --- a/node/chainSimulator/process/interface.go +++ b/node/chainSimulator/process/interface.go @@ -23,6 +23,7 @@ type NodeHandler interface { GetStatusCoreComponents() factory.StatusCoreComponentsHolder SetKeyValueForAddress(addressBytes []byte, state map[string]string) error SetStateForAddress(address []byte, state *dtos.AddressState) error + RemoveAccount(address []byte) error Close() error IsInterfaceNil() bool } diff --git a/testscommon/chainSimulator/nodeHandlerMock.go b/testscommon/chainSimulator/nodeHandlerMock.go index 52b72a17acc..9e0a2ca4d3b 100644 --- a/testscommon/chainSimulator/nodeHandlerMock.go +++ b/testscommon/chainSimulator/nodeHandlerMock.go @@ -23,6 +23,7 @@ type NodeHandlerMock struct { GetStatusCoreComponentsCalled func() factory.StatusCoreComponentsHolder SetKeyValueForAddressCalled func(addressBytes []byte, state map[string]string) error SetStateForAddressCalled func(address []byte, state *dtos.AddressState) error + RemoveAccountCalled func(address []byte) error CloseCalled func() error } @@ -122,6 +123,15 @@ func (mock *NodeHandlerMock) SetStateForAddress(address []byte, state *dtos.Addr return nil } +// RemoveAccount - +func (mock *NodeHandlerMock) RemoveAccount(address []byte) error { + if mock.RemoveAccountCalled != nil { + return mock.RemoveAccountCalled(address) + } + + return nil +} + // Close - func (mock *NodeHandlerMock) Close() error { if mock.CloseCalled != nil { From 4cae25d8bdff39ef737874f72334ee83ddd60655 Mon Sep 17 00:00:00 2001 From: radu chis Date: Tue, 23 Apr 2024 11:12:34 +0300 Subject: [PATCH 184/503] added test for withKeys error --- api/groups/addressGroupOptions.go | 1 - node/node_test.go | 46 +++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/api/groups/addressGroupOptions.go b/api/groups/addressGroupOptions.go index e21dc6d361a..5cd4fc6a11f 100644 --- a/api/groups/addressGroupOptions.go +++ b/api/groups/addressGroupOptions.go @@ -61,7 +61,6 @@ func parseAccountQueryOptions(c *gin.Context) (api.AccountQueryOptions, error) { BlockHash: blockHash, BlockRootHash: blockRootHash, HintEpoch: hintEpoch, - WithKeys: false, } return options, nil } diff --git a/node/node_test.go b/node/node_test.go index dc8b012734e..71eba9f5467 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -3447,6 +3447,51 @@ func TestNode_GetAccountAccountExistsShouldReturn(t *testing.T) { require.Equal(t, testscommon.TestAddressAlice, recovAccnt.OwnerAddress) } +func TestNode_GetAccountAccountWithKeysErrorShouldErr(t *testing.T) { + accnt := createAcc(testscommon.TestPubKeyBob) + _ = accnt.AddToBalance(big.NewInt(1)) + expectedErr := errors.New("expected error") + accnt.SetDataTrie( + &trieMock.TrieStub{ + GetAllLeavesOnChannelCalled: func(leavesChannels *common.TrieIteratorChannels, ctx context.Context, rootHash []byte, _ common.KeyBuilder, tlp common.TrieLeafParser) error { + return expectedErr + }, + RootCalled: func() ([]byte, error) { + return nil, nil + }, + }) + + accDB := &stateMock.AccountsStub{ + GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { + return accnt, nil, nil + }, + RecreateTrieCalled: func(rootHash []byte) error { + return nil + }, + } + + coreComponents := getDefaultCoreComponents() + dataComponents := getDefaultDataComponents() + stateComponents := getDefaultStateComponents() + args := state.ArgsAccountsRepository{ + FinalStateAccountsWrapper: accDB, + CurrentStateAccountsWrapper: accDB, + HistoricalStateAccountsWrapper: accDB, + } + stateComponents.AccountsRepo, _ = state.NewAccountsRepository(args) + n, _ := node.NewNode( + node.WithCoreComponents(coreComponents), + node.WithDataComponents(dataComponents), + node.WithStateComponents(stateComponents), + ) + + recovAccnt, blockInfo, err := n.GetAccountWithKeys(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: true}, context.Background()) + + require.Equal(t, expectedErr, err) + require.Equal(t, api.AccountResponse{}, recovAccnt) + require.Equal(t, api.BlockInfo{}, blockInfo) +} + func TestNode_GetAccountAccountWithKeysShouldReturn(t *testing.T) { t.Parallel() @@ -3504,6 +3549,7 @@ func TestNode_GetAccountAccountWithKeysShouldReturn(t *testing.T) { ) recovAccnt, _, err := n.GetAccountWithKeys(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: false}, context.Background()) + require.Nil(t, err) require.Nil(t, recovAccnt.Pairs) From e4338c6574b0a120a002346c15f96c1ecd84d562 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Tue, 23 Apr 2024 11:55:40 +0300 Subject: [PATCH 185/503] - removed useless empty line --- node/chainSimulator/chainSimulator_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index e4092a16b9c..23bbb007f8b 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -376,7 +376,6 @@ func TestChainSimulator_SetEntireStateWithRemoval(t *testing.T) { require.Equal(t, accountState.CodeMetadata, base64.StdEncoding.EncodeToString(account.CodeMetadata)) require.Equal(t, accountState.Owner, account.OwnerAddress) require.Equal(t, accountState.RootHash, base64.StdEncoding.EncodeToString(account.RootHash)) - } func TestChainSimulator_GetAccount(t *testing.T) { From 5a774a56faf2d0cfc1c9f884834a9e4f9a34d7cf Mon Sep 17 00:00:00 2001 From: radu chis Date: Tue, 23 Apr 2024 13:16:01 +0300 Subject: [PATCH 186/503] fix after review --- facade/interface.go | 2 +- node/node.go | 116 +++++++++++++++++++++----------------------- node/node_test.go | 50 ++++++++----------- 3 files changed, 76 insertions(+), 92 deletions(-) diff --git a/facade/interface.go b/facade/interface.go index e3be7b76cb0..35f185874ed 100644 --- a/facade/interface.go +++ b/facade/interface.go @@ -77,7 +77,7 @@ type NodeHandler interface { GetAccount(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) // GetAccountWithKeys returns an accountResponse containing information - // about the account correlated with provided address and all keys + // about the account correlated with provided address and all keys GetAccountWithKeys(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) // GetCode returns the code for the given code hash diff --git a/node/node.go b/node/node.go index db2031a37ca..9cdf368c57e 100644 --- a/node/node.go +++ b/node/node.go @@ -62,6 +62,12 @@ type filter interface { filter(tokenIdentifier string, esdtData *systemSmartContracts.ESDTDataV2) bool } +type accountInfo struct { + account state.UserAccountHandler + block api.BlockInfo + accountResponse api.AccountResponse +} + // Node is a structure that holds all managed components type Node struct { initialNodesPubkeys map[uint32][]string @@ -939,87 +945,32 @@ func (n *Node) setTxGuardianData(guardian string, guardianSigHex string, tx *tra // GetAccount will return account details for a given address func (n *Node) GetAccount(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { - account, blockInfo, err := n.loadUserAccountHandlerByAddress(address, options) + accInfo, err := n.getAccountInfo(address, options) if err != nil { - adaptedBlockInfo, isEmptyAccount := extractBlockInfoIfNewAccount(err) - if isEmptyAccount { - return api.AccountResponse{ - Address: address, - Balance: "0", - DeveloperReward: "0", - }, adaptedBlockInfo, nil - } - return api.AccountResponse{}, api.BlockInfo{}, err } - ownerAddress := "" - if len(account.GetOwnerAddress()) > 0 { - addressPubkeyConverter := n.coreComponents.AddressPubKeyConverter() - ownerAddress, err = addressPubkeyConverter.Encode(account.GetOwnerAddress()) - if err != nil { - return api.AccountResponse{}, api.BlockInfo{}, err - } - } - - return api.AccountResponse{ - Address: address, - Nonce: account.GetNonce(), - Balance: account.GetBalance().String(), - Username: string(account.GetUserName()), - CodeHash: account.GetCodeHash(), - RootHash: account.GetRootHash(), - CodeMetadata: account.GetCodeMetadata(), - DeveloperReward: account.GetDeveloperReward().String(), - OwnerAddress: ownerAddress, - }, blockInfo, nil + return accInfo.accountResponse, accInfo.block, nil } // GetAccountWithKeys will return account details for a given address including the keys func (n *Node) GetAccountWithKeys(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) { - account, blockInfo, err := n.loadUserAccountHandlerByAddress(address, options) + accInfo, err := n.getAccountInfo(address, options) if err != nil { - adaptedBlockInfo, isEmptyAccount := extractBlockInfoIfNewAccount(err) - if isEmptyAccount { - return api.AccountResponse{ - Address: address, - Balance: "0", - DeveloperReward: "0", - }, adaptedBlockInfo, nil - } - return api.AccountResponse{}, api.BlockInfo{}, err } - ownerAddress := "" - if len(account.GetOwnerAddress()) > 0 { - addressPubkeyConverter := n.coreComponents.AddressPubKeyConverter() - ownerAddress, err = addressPubkeyConverter.Encode(account.GetOwnerAddress()) - if err != nil { - return api.AccountResponse{}, api.BlockInfo{}, err - } - } - var keys map[string]string if options.WithKeys { - keys, err = n.getKeys(account, ctx) + keys, err = n.getKeys(accInfo.account, ctx) if err != nil { return api.AccountResponse{}, api.BlockInfo{}, err } } - return api.AccountResponse{ - Address: address, - Nonce: account.GetNonce(), - Balance: account.GetBalance().String(), - Username: string(account.GetUserName()), - CodeHash: account.GetCodeHash(), - RootHash: account.GetRootHash(), - CodeMetadata: account.GetCodeMetadata(), - DeveloperReward: account.GetDeveloperReward().String(), - OwnerAddress: ownerAddress, - Pairs: keys, - }, blockInfo, nil + accInfo.accountResponse.Pairs = keys + + return accInfo.accountResponse, accInfo.block, nil } func extractBlockInfoIfNewAccount(err error) (api.BlockInfo, bool) { @@ -1039,6 +990,47 @@ func extractBlockInfoIfNewAccount(err error) (api.BlockInfo, bool) { return api.BlockInfo{}, false } +func (n *Node) getAccountInfo(address string, options api.AccountQueryOptions) (accountInfo, error) { + account, blockInfo, err := n.loadUserAccountHandlerByAddress(address, options) + if err != nil { + adaptedBlockInfo, isEmptyAccount := extractBlockInfoIfNewAccount(err) + if isEmptyAccount { + return accountInfo{ + accountResponse: api.AccountResponse{ + Address: address, + Balance: "0", + DeveloperReward: "0", + }, + block: adaptedBlockInfo}, err + } + } + + ownerAddress := "" + if len(account.GetOwnerAddress()) > 0 { + addressPubkeyConverter := n.coreComponents.AddressPubKeyConverter() + ownerAddress, err = addressPubkeyConverter.Encode(account.GetOwnerAddress()) + if err != nil { + return accountInfo{ + accountResponse: api.AccountResponse{}, + block: api.BlockInfo{}, + }, err + } + } + + return accountInfo{ + accountResponse: api.AccountResponse{ + Address: address, + Nonce: account.GetNonce(), + Balance: account.GetBalance().String(), + Username: string(account.GetUserName()), + CodeHash: account.GetCodeHash(), + RootHash: account.GetRootHash(), + CodeMetadata: account.GetCodeMetadata(), + DeveloperReward: account.GetDeveloperReward().String(), + OwnerAddress: ownerAddress, + }, block: blockInfo}, nil +} + // GetCode returns the code for the given code hash func (n *Node) GetCode(codeHash []byte, options api.AccountQueryOptions) ([]byte, api.BlockInfo) { return n.loadAccountCode(codeHash, options) diff --git a/node/node_test.go b/node/node_test.go index 71eba9f5467..f1740ada505 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -3447,7 +3447,7 @@ func TestNode_GetAccountAccountExistsShouldReturn(t *testing.T) { require.Equal(t, testscommon.TestAddressAlice, recovAccnt.OwnerAddress) } -func TestNode_GetAccountAccountWithKeysErrorShouldErr(t *testing.T) { +func TestNode_GetAccountAccountWithKeysErrorShouldFail(t *testing.T) { accnt := createAcc(testscommon.TestPubKeyBob) _ = accnt.AddToBalance(big.NewInt(1)) expectedErr := errors.New("expected error") @@ -3470,20 +3470,7 @@ func TestNode_GetAccountAccountWithKeysErrorShouldErr(t *testing.T) { }, } - coreComponents := getDefaultCoreComponents() - dataComponents := getDefaultDataComponents() - stateComponents := getDefaultStateComponents() - args := state.ArgsAccountsRepository{ - FinalStateAccountsWrapper: accDB, - CurrentStateAccountsWrapper: accDB, - HistoricalStateAccountsWrapper: accDB, - } - stateComponents.AccountsRepo, _ = state.NewAccountsRepository(args) - n, _ := node.NewNode( - node.WithCoreComponents(coreComponents), - node.WithDataComponents(dataComponents), - node.WithStateComponents(stateComponents), - ) + n := getNodeWithAccount(accDB) recovAccnt, blockInfo, err := n.GetAccountWithKeys(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: true}, context.Background()) @@ -3492,7 +3479,7 @@ func TestNode_GetAccountAccountWithKeysErrorShouldErr(t *testing.T) { require.Equal(t, api.BlockInfo{}, blockInfo) } -func TestNode_GetAccountAccountWithKeysShouldReturn(t *testing.T) { +func TestNode_GetAccountAccountWithKeysShouldWork(t *testing.T) { t.Parallel() accnt := createAcc(testscommon.TestPubKeyBob) @@ -3533,6 +3520,23 @@ func TestNode_GetAccountAccountWithKeysShouldReturn(t *testing.T) { }, } + n := getNodeWithAccount(accDB) + + recovAccnt, _, err := n.GetAccountWithKeys(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: false}, context.Background()) + + require.Nil(t, err) + require.Nil(t, recovAccnt.Pairs) + + recovAccnt, _, err = n.GetAccountWithKeys(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: true}, context.Background()) + + require.Nil(t, err) + require.NotNil(t, recovAccnt.Pairs) + require.Equal(t, 2, len(recovAccnt.Pairs)) + require.Equal(t, hex.EncodeToString(v1), recovAccnt.Pairs[hex.EncodeToString(k1)]) + require.Equal(t, hex.EncodeToString(v2), recovAccnt.Pairs[hex.EncodeToString(k2)]) +} + +func getNodeWithAccount(accDB *stateMock.AccountsStub) *node.Node { coreComponents := getDefaultCoreComponents() dataComponents := getDefaultDataComponents() stateComponents := getDefaultStateComponents() @@ -3547,19 +3551,7 @@ func TestNode_GetAccountAccountWithKeysShouldReturn(t *testing.T) { node.WithDataComponents(dataComponents), node.WithStateComponents(stateComponents), ) - - recovAccnt, _, err := n.GetAccountWithKeys(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: false}, context.Background()) - - require.Nil(t, err) - require.Nil(t, recovAccnt.Pairs) - - recovAccnt, _, err = n.GetAccountWithKeys(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: true}, context.Background()) - - require.Nil(t, err) - require.NotNil(t, recovAccnt.Pairs) - require.Equal(t, 2, len(recovAccnt.Pairs)) - require.Equal(t, hex.EncodeToString(v1), recovAccnt.Pairs[hex.EncodeToString(k1)]) - require.Equal(t, hex.EncodeToString(v2), recovAccnt.Pairs[hex.EncodeToString(k2)]) + return n } func TestNode_AppStatusHandlersShouldIncrement(t *testing.T) { From 3531379b72a2ac8e53fc39a39f03e1094d987fe4 Mon Sep 17 00:00:00 2001 From: radu chis Date: Tue, 23 Apr 2024 13:58:26 +0300 Subject: [PATCH 187/503] refactored and fixed test --- node/node.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/node/node.go b/node/node.go index 9cdf368c57e..992cba53768 100644 --- a/node/node.go +++ b/node/node.go @@ -1001,8 +1001,15 @@ func (n *Node) getAccountInfo(address string, options api.AccountQueryOptions) ( Balance: "0", DeveloperReward: "0", }, - block: adaptedBlockInfo}, err + block: adaptedBlockInfo, + account: account, + }, nil } + return accountInfo{ + accountResponse: api.AccountResponse{}, + block: api.BlockInfo{}, + account: nil, + }, err } ownerAddress := "" @@ -1013,6 +1020,7 @@ func (n *Node) getAccountInfo(address string, options api.AccountQueryOptions) ( return accountInfo{ accountResponse: api.AccountResponse{}, block: api.BlockInfo{}, + account: nil, }, err } } @@ -1028,7 +1036,10 @@ func (n *Node) getAccountInfo(address string, options api.AccountQueryOptions) ( CodeMetadata: account.GetCodeMetadata(), DeveloperReward: account.GetDeveloperReward().String(), OwnerAddress: ownerAddress, - }, block: blockInfo}, nil + }, + block: blockInfo, + account: account, + }, nil } // GetCode returns the code for the given code hash From 144a039becd418dbdfeba583adedd4c47b5a92a6 Mon Sep 17 00:00:00 2001 From: radu chis Date: Tue, 23 Apr 2024 14:39:03 +0300 Subject: [PATCH 188/503] downgraded to v0.21.0 --- go.mod | 2 +- go.sum | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index c7ef33c791d..c67839d751f 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( github.com/shirou/gopsutil v3.21.11+incompatible github.com/stretchr/testify v1.8.4 github.com/urfave/cli v1.22.10 - golang.org/x/crypto v0.22.0 + golang.org/x/crypto v0.21.0 gopkg.in/go-playground/validator.v8 v8.18.2 ) diff --git a/go.sum b/go.sum index 813d0a8327a..d1277df6ca3 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= @@ -416,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= @@ -628,10 +624,9 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM= golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I= -golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= -golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= +golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= +golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug= golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= @@ -674,8 +669,8 @@ golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU= golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= +golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -730,8 +725,8 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -746,8 +741,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58= golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= From 7111b29e1445d5ea2f2fe155a9d62d4b0efdcbbc Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 24 Apr 2024 11:03:36 +0300 Subject: [PATCH 189/503] flags and gasschedule --- cmd/node/config/enableEpochs.toml | 6 ++++++ cmd/node/config/gasSchedules/gasScheduleV1.toml | 3 +++ cmd/node/config/gasSchedules/gasScheduleV2.toml | 3 +++ cmd/node/config/gasSchedules/gasScheduleV3.toml | 3 +++ cmd/node/config/gasSchedules/gasScheduleV4.toml | 3 +++ cmd/node/config/gasSchedules/gasScheduleV5.toml | 3 +++ cmd/node/config/gasSchedules/gasScheduleV6.toml | 3 +++ cmd/node/config/gasSchedules/gasScheduleV7.toml | 3 +++ common/constants.go | 2 ++ common/enablers/enableEpochsHandler.go | 12 ++++++++++++ common/enablers/enableEpochsHandler_test.go | 4 ++++ config/epochConfig.go | 2 ++ config/tomlConfig_test.go | 8 ++++++++ go.mod | 4 ++-- go.sum | 8 ++++---- 15 files changed, 61 insertions(+), 6 deletions(-) diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index 29aaf825438..e1d1b14ddaf 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -308,6 +308,12 @@ # DynamicESDTEnableEpoch represents the epoch when dynamic NFT feature is enabled DynamicESDTEnableEpoch = 4 + # EGLDInMultiTransferEnableEpoch represents the epoch when EGLD in multitransfer is enabled + EGLDInMultiTransferEnableEpoch = 4 + + # CryptoAPIV2EnableEpoch represents the epoch when BLSMultiSig, Secp256r1 and other opcodes are enabled + CryptoAPIV2EnableEpoch = 4 + # BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers BLSMultiSignerEnableEpoch = [ { EnableEpoch = 0, Type = "no-KOSK" }, diff --git a/cmd/node/config/gasSchedules/gasScheduleV1.toml b/cmd/node/config/gasSchedules/gasScheduleV1.toml index 74ace962f97..5e715a2d466 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV1.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV1.toml @@ -211,6 +211,9 @@ UnmarshalCompressedECC = 270000 GenerateKeyECC = 7000000 EncodeDERSig = 10000000 + VerifySecp256r1 = 2000000 + VerifyBLSSignatureShare = 2000000 + VerifyBLSMultiSig = 2000000 [ManagedBufferAPICost] MBufferNew = 2000 diff --git a/cmd/node/config/gasSchedules/gasScheduleV2.toml b/cmd/node/config/gasSchedules/gasScheduleV2.toml index 8a75c1aad5c..e0d1c4e366e 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV2.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV2.toml @@ -211,6 +211,9 @@ UnmarshalCompressedECC = 270000 GenerateKeyECC = 7000000 EncodeDERSig = 10000000 + VerifySecp256r1 = 2000000 + VerifyBLSSignatureShare = 2000000 + VerifyBLSMultiSig = 2000000 [ManagedBufferAPICost] MBufferNew = 2000 diff --git a/cmd/node/config/gasSchedules/gasScheduleV3.toml b/cmd/node/config/gasSchedules/gasScheduleV3.toml index 49590fb0459..8c3a763363e 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV3.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV3.toml @@ -211,6 +211,9 @@ UnmarshalCompressedECC = 270000 GenerateKeyECC = 7000000 EncodeDERSig = 10000000 + VerifySecp256r1 = 2000000 + VerifyBLSSignatureShare = 2000000 + VerifyBLSMultiSig = 2000000 [ManagedBufferAPICost] MBufferNew = 2000 diff --git a/cmd/node/config/gasSchedules/gasScheduleV4.toml b/cmd/node/config/gasSchedules/gasScheduleV4.toml index 5b4542b05a8..4d178ff0fd5 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV4.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV4.toml @@ -211,6 +211,9 @@ UnmarshalCompressedECC = 270000 GenerateKeyECC = 7000000 EncodeDERSig = 10000000 + VerifySecp256r1 = 2000000 + VerifyBLSSignatureShare = 2000000 + VerifyBLSMultiSig = 2000000 [ManagedBufferAPICost] MBufferNew = 2000 diff --git a/cmd/node/config/gasSchedules/gasScheduleV5.toml b/cmd/node/config/gasSchedules/gasScheduleV5.toml index 30c967750d4..e5f5035bb17 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV5.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV5.toml @@ -211,6 +211,9 @@ UnmarshalCompressedECC = 270000 GenerateKeyECC = 7000000 EncodeDERSig = 10000000 + VerifySecp256r1 = 2000000 + VerifyBLSSignatureShare = 2000000 + VerifyBLSMultiSig = 2000000 [ManagedBufferAPICost] MBufferNew = 2000 diff --git a/cmd/node/config/gasSchedules/gasScheduleV6.toml b/cmd/node/config/gasSchedules/gasScheduleV6.toml index d91cb12e75c..f41c5002b85 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV6.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV6.toml @@ -211,6 +211,9 @@ UnmarshalCompressedECC = 270000 GenerateKeyECC = 7000000 EncodeDERSig = 10000000 + VerifySecp256r1 = 2000000 + VerifyBLSSignatureShare = 2000000 + VerifyBLSMultiSig = 2000000 [ManagedBufferAPICost] MBufferNew = 2000 diff --git a/cmd/node/config/gasSchedules/gasScheduleV7.toml b/cmd/node/config/gasSchedules/gasScheduleV7.toml index 0ecf7ec4bea..6b580c893cc 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV7.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV7.toml @@ -212,6 +212,9 @@ UnmarshalCompressedECC = 270000 GenerateKeyECC = 7000000 EncodeDERSig = 10000000 + VerifySecp256r1 = 2000000 + VerifyBLSSignatureShare = 2000000 + VerifyBLSMultiSig = 2000000 [ManagedBufferAPICost] MBufferNew = 2000 diff --git a/common/constants.go b/common/constants.go index 1a5a4af9022..98791f43fd8 100644 --- a/common/constants.go +++ b/common/constants.go @@ -1015,5 +1015,7 @@ const ( StakingV4StartedFlag core.EnableEpochFlag = "StakingV4StartedFlag" AlwaysMergeContextsInEEIFlag core.EnableEpochFlag = "AlwaysMergeContextsInEEIFlag" DynamicESDTFlag core.EnableEpochFlag = "DynamicEsdtFlag" + EGLDInESDTMultiTransferFlag core.EnableEpochFlag = "EGLDInESDTMultiTransferFlag" + CryptoAPIV2Flag core.EnableEpochFlag = "CryptoAPIV2Flag" // all new flags must be added to createAllFlagsMap method, as part of enableEpochsHandler allFlagsDefined ) diff --git a/common/enablers/enableEpochsHandler.go b/common/enablers/enableEpochsHandler.go index ea440d30b34..a6fb12b4128 100644 --- a/common/enablers/enableEpochsHandler.go +++ b/common/enablers/enableEpochsHandler.go @@ -737,6 +737,18 @@ func (handler *enableEpochsHandler) createAllFlagsMap() { }, activationEpoch: handler.enableEpochsConfig.DynamicESDTEnableEpoch, }, + common.EGLDInESDTMultiTransferFlag: { + isActiveInEpoch: func(epoch uint32) bool { + return epoch >= handler.enableEpochsConfig.EGLDInMultiTransferEnableEpoch + }, + activationEpoch: handler.enableEpochsConfig.EGLDInMultiTransferEnableEpoch, + }, + common.CryptoAPIV2Flag: { + isActiveInEpoch: func(epoch uint32) bool { + return epoch >= handler.enableEpochsConfig.CryptoAPIV2EnableEpoch + }, + activationEpoch: handler.enableEpochsConfig.CryptoAPIV2EnableEpoch, + }, } } diff --git a/common/enablers/enableEpochsHandler_test.go b/common/enablers/enableEpochsHandler_test.go index 89289ac628e..241ab0e691a 100644 --- a/common/enablers/enableEpochsHandler_test.go +++ b/common/enablers/enableEpochsHandler_test.go @@ -115,6 +115,8 @@ func createEnableEpochsConfig() config.EnableEpochs { StakingV4Step3EnableEpoch: 99, AlwaysMergeContextsInEEIEnableEpoch: 100, DynamicESDTEnableEpoch: 101, + EGLDInMultiTransferEnableEpoch: 102, + CryptoAPIV2EnableEpoch: 103, } } @@ -440,6 +442,8 @@ func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) { require.Equal(t, cfg.StakingV4Step1EnableEpoch, handler.GetActivationEpoch(common.StakingV4StartedFlag)) require.Equal(t, cfg.AlwaysMergeContextsInEEIEnableEpoch, handler.GetActivationEpoch(common.AlwaysMergeContextsInEEIFlag)) require.Equal(t, cfg.DynamicESDTEnableEpoch, handler.GetActivationEpoch(common.DynamicESDTFlag)) + require.Equal(t, cfg.EGLDInMultiTransferEnableEpoch, handler.GetActivationEpoch(common.EGLDInESDTMultiTransferFlag)) + require.Equal(t, cfg.CryptoAPIV2EnableEpoch, handler.GetActivationEpoch(common.CryptoAPIV2Flag)) } func TestEnableEpochsHandler_IsInterfaceNil(t *testing.T) { diff --git a/config/epochConfig.go b/config/epochConfig.go index f03492e1826..b29c3205efa 100644 --- a/config/epochConfig.go +++ b/config/epochConfig.go @@ -114,6 +114,8 @@ type EnableEpochs struct { StakingV4Step3EnableEpoch uint32 AlwaysMergeContextsInEEIEnableEpoch uint32 DynamicESDTEnableEpoch uint32 + EGLDInMultiTransferEnableEpoch uint32 + CryptoAPIV2EnableEpoch uint32 BLSMultiSignerEnableEpoch []MultiSignerConfig } diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index 0c48df9e40e..84aec699b7d 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -853,6 +853,12 @@ func TestEnableEpochConfig(t *testing.T) { # DynamicESDTEnableEpoch represents the epoch when dynamic NFT feature is enabled DynamicESDTEnableEpoch = 95 + # EGLDInMultiTransferEnableEpoch represents the epoch when EGLD in MultiTransfer is enabled + EGLDInMultiTransferEnableEpoch = 96 + + # CryptoAPIV2EnableEpoch represents the epoch when BLSMultiSig, Secp256r1 and other opcodes are enabled + CryptoAPIV2EnableEpoch = 97 + # MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MaxNodesChangeEnableEpoch = [ { EpochEnable = 44, MaxNumNodes = 2169, NodesToShufflePerShard = 80 }, @@ -966,6 +972,8 @@ func TestEnableEpochConfig(t *testing.T) { CurrentRandomnessOnSortingEnableEpoch: 93, AlwaysMergeContextsInEEIEnableEpoch: 94, DynamicESDTEnableEpoch: 95, + EGLDInMultiTransferEnableEpoch: 96, + CryptoAPIV2EnableEpoch: 97, MaxNodesChangeEnableEpoch: []MaxNodesChangeConfig{ { EpochEnable: 44, diff --git a/go.mod b/go.mod index 36abca09af5..f97add64dcc 100644 --- a/go.mod +++ b/go.mod @@ -21,8 +21,8 @@ require ( github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474 - github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240411132244-adf842b5e09e - github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240328092329-b5f2c7c059eb + github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240423121536-5130480c0f69 + github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240423121845-bfe3bf281a21 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240321152247-79521988c8e6 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240321152532-45da5eabdc38 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240321152756-16110ce9d968 diff --git a/go.sum b/go.sum index 69efd4b6287..2ae4bd22318 100644 --- a/go.sum +++ b/go.sum @@ -399,10 +399,10 @@ github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157/go.mod h1:ndk45i9J9McuCJpTcgiaK4ocd0yhnBBCPrlFwO6GRcs= github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474 h1:x65Su8ojHwA+NICp9DrSVGLDDcAlW04DafkqCHY1QPE= github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474/go.mod h1:hnc6H4D5Ge1haRAQ6QHTXhyh+CT2DRiNJ0U0HQYI3DY= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240411132244-adf842b5e09e h1:SJmm+Lkxdj/eJ4t/CCcvhZCZtg2A1ieVoJV5FJooFKA= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240411132244-adf842b5e09e/go.mod h1:G6daPJC6bFsvAw45RPMCRi2rP+8LjFxa8G+3alHuJow= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240328092329-b5f2c7c059eb h1:0WvWXqzliYS1yKW+6uTxZGMjQd08IQNPzlNNxxyNWHM= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240328092329-b5f2c7c059eb/go.mod h1:mZNRILxq51LVqwqE9jMJyDHgmy9W3x7otOGuFjOm82Q= +github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240423121536-5130480c0f69 h1:XxY0OBA7npOBj1GzeuzOwWhbCaDK2Gne6hnjLBJJiho= +github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240423121536-5130480c0f69/go.mod h1:G6daPJC6bFsvAw45RPMCRi2rP+8LjFxa8G+3alHuJow= +github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240423121845-bfe3bf281a21 h1:XJ9df6NqyLm9e+e2J8NI7wSfUYwF5HD1fL/0KKfViAo= +github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240423121845-bfe3bf281a21/go.mod h1:DyMusfHXRXyVYQmH2umBTZD5gm6p136EJNC6YI2l+kU= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240321152247-79521988c8e6 h1:7HqUo9YmpsfN/y9px6RmzREJm5O6ZzP9NqvFSrHTw24= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240321152247-79521988c8e6/go.mod h1:H2H/zoskiZC0lEokq9qMFVxRkB0RWVDPLjHbG/NrGUU= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240321152532-45da5eabdc38 h1:SAKjOByxXkZ5Sys5O4IkrrSGCKLoPvD+cCJJEvbev4w= From bc7267e78895e6ee3475e138975c01f1a9ec632a Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 24 Apr 2024 12:19:31 +0300 Subject: [PATCH 190/503] integration continues --- cmd/node/config/config.toml | 10 ++++++ config/config.go | 1 + config/tomlConfig_test.go | 9 ++++++ process/errors.go | 3 ++ process/factory/shard/vmContainerFactory.go | 31 +++++++++++++++++++ .../factory/shard/vmContainerFactory_test.go | 29 +++++++++++++++++ 6 files changed, 83 insertions(+) diff --git a/cmd/node/config/config.toml b/cmd/node/config/config.toml index b6c11452a64..1c69cf3238e 100644 --- a/cmd/node/config/config.toml +++ b/cmd/node/config/config.toml @@ -675,6 +675,11 @@ { StartEpoch = 0, Version = "v1.4" }, { StartEpoch = 1, Version = "v1.5" }, # TODO: set also the RoundActivations.DisableAsyncCallV1 accordingly ] + TransferAndExecuteByUserAddresses = [ # TODO: set real contract addresses + "erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe0", #shard 0 + "erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe1", #shard 1 + "erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe2", #shard 2 + ] [VirtualMachine.Querying] NumConcurrentVMs = 1 @@ -684,6 +689,11 @@ { StartEpoch = 0, Version = "v1.4" }, { StartEpoch = 1, Version = "v1.5" }, # TODO: set also the RoundActivations.DisableAsyncCallV1 accordingly ] + TransferAndExecuteByUserAddresses = [ # TODO: set real contract addresses + "erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe0", #shard 0 + "erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe1", #shard 1 + "erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe2", #shard 2 + ] [VirtualMachine.GasConfig] # The following values define the maximum amount of gas to be allocated for VM Queries coming from API diff --git a/config/config.go b/config/config.go index 472378d49fd..49ef257c341 100644 --- a/config/config.go +++ b/config/config.go @@ -413,6 +413,7 @@ type VirtualMachineConfig struct { WasmVMVersions []WasmVMVersionByEpoch TimeOutForSCExecutionInMilliseconds uint32 WasmerSIGSEGVPassthrough bool + TransferAndExecuteByUserAddresses []string } // WasmVMVersionByEpoch represents the Wasm VM version to be used starting with an epoch diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index 84aec699b7d..44a160e4582 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -102,6 +102,10 @@ func TestTomlParser(t *testing.T) { WasmVMVersions: wasmVMVersions, TimeOutForSCExecutionInMilliseconds: 10000, WasmerSIGSEGVPassthrough: true, + TransferAndExecuteByUserAddresses: []string{ + "erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe0", + "erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe1", + "erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe2"}, }, Querying: QueryVirtualMachineConfig{ NumConcurrentVMs: 16, @@ -199,6 +203,11 @@ func TestTomlParser(t *testing.T) { { StartEpoch = 12, Version = "v0.3" }, { StartEpoch = 88, Version = "v1.2" }, ] + TransferAndExecuteByUserAddresses = [ # TODO: set real contract addresses + "erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe0", #shard 0 + "erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe1", #shard 1 + "erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe2", #shard 2 + ] [VirtualMachine.Querying] NumConcurrentVMs = 16 diff --git a/process/errors.go b/process/errors.go index 207184f3cb7..174db37686c 100644 --- a/process/errors.go +++ b/process/errors.go @@ -1226,3 +1226,6 @@ var ErrInvalidAsyncArguments = errors.New("invalid arguments to process async/ca // ErrNilSentSignatureTracker defines the error for setting a nil SentSignatureTracker var ErrNilSentSignatureTracker = errors.New("nil sent signature tracker") + +// ErrTransferAndExecuteByUserAddressesIsNil signals that transfer and execute by user addresses are nil +var ErrTransferAndExecuteByUserAddressesIsNil = errors.New("transfer and execute by user addresses are nil") diff --git a/process/factory/shard/vmContainerFactory.go b/process/factory/shard/vmContainerFactory.go index 35c17f763a1..cdcd3bc4e6d 100644 --- a/process/factory/shard/vmContainerFactory.go +++ b/process/factory/shard/vmContainerFactory.go @@ -44,8 +44,13 @@ type vmContainerFactory struct { wasmVMChangeLocker common.Locker esdtTransferParser vmcommon.ESDTTransferParser hasher hashing.Hasher + pubKeyConverter core.PubkeyConverter + + mapOpcodeAddressIsAllowed map[string]map[string]struct{} } +const managedMultiTransferESDTNFTExecuteByUser = "managedMultiTransferESDTNFTExecuteByUser" + // ArgVMContainerFactory defines the arguments needed to the new VM factory type ArgVMContainerFactory struct { Config config.VirtualMachineConfig @@ -58,6 +63,7 @@ type ArgVMContainerFactory struct { BuiltInFunctions vmcommon.BuiltInFunctionContainer BlockChainHook process.BlockChainHookWithAccountsAdapter Hasher hashing.Hasher + PubKeyConverter core.PubkeyConverter } // NewVMContainerFactory is responsible for creating a new virtual machine factory object @@ -86,6 +92,9 @@ func NewVMContainerFactory(args ArgVMContainerFactory) (*vmContainerFactory, err if check.IfNil(args.Hasher) { return nil, process.ErrNilHasher } + if check.IfNil(args.PubKeyConverter) { + return nil, process.ErrNilPubkeyConverter + } cryptoHook := hooks.NewVMCryptoHook() @@ -102,6 +111,7 @@ func NewVMContainerFactory(args ArgVMContainerFactory) (*vmContainerFactory, err wasmVMChangeLocker: args.WasmVMChangeLocker, esdtTransferParser: args.ESDTTransferParser, hasher: args.Hasher, + pubKeyConverter: args.PubKeyConverter, } vmf.wasmVMVersions = args.Config.WasmVMVersions @@ -114,6 +124,26 @@ func NewVMContainerFactory(args ArgVMContainerFactory) (*vmContainerFactory, err return vmf, nil } +func (vmf *vmContainerFactory) createMapOpCodeAddressIsAllowed() error { + vmf.mapOpcodeAddressIsAllowed = make(map[string]map[string]struct{}) + + transferAndExecuteByUserAddresses := vmf.config.TransferAndExecuteByUserAddresses + if len(transferAndExecuteByUserAddresses) == 0 { + return process.ErrTransferAndExecuteByUserAddressesIsNil + } + + vmf.mapOpcodeAddressIsAllowed[managedMultiTransferESDTNFTExecuteByUser] = make(map[string]struct{}) + for _, address := range transferAndExecuteByUserAddresses { + decodedAddress, errDecode := vmf.pubKeyConverter.Decode(address) + if errDecode != nil { + return errDecode + } + vmf.mapOpcodeAddressIsAllowed[managedMultiTransferESDTNFTExecuteByUser][string(decodedAddress)] = struct{}{} + } + + return nil +} + func (vmf *vmContainerFactory) sortWasmVMVersions() { sort.Slice(vmf.wasmVMVersions, func(i, j int) bool { return vmf.wasmVMVersions[i].StartEpoch < vmf.wasmVMVersions[j].StartEpoch @@ -351,6 +381,7 @@ func (vmf *vmContainerFactory) createInProcessWasmVMV15() (vmcommon.VMExecutionH EpochNotifier: vmf.epochNotifier, EnableEpochsHandler: vmf.enableEpochsHandler, Hasher: vmf.hasher, + MapOpcodeAddressIsAllowed: vmf.mapOpcodeAddressIsAllowed, } return wasmVMHost15.NewVMHost(vmf.blockChainHook, hostParameters) diff --git a/process/factory/shard/vmContainerFactory_test.go b/process/factory/shard/vmContainerFactory_test.go index a6d7184bd77..96c7d5e3089 100644 --- a/process/factory/shard/vmContainerFactory_test.go +++ b/process/factory/shard/vmContainerFactory_test.go @@ -32,6 +32,7 @@ func makeVMConfig() config.VirtualMachineConfig { {StartEpoch: 12, Version: "v1.3"}, {StartEpoch: 14, Version: "v1.4"}, }, + TransferAndExecuteByUserAddresses: []string{"erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe3"}, } } @@ -48,6 +49,7 @@ func createMockVMAccountsArguments() ArgVMContainerFactory { BuiltInFunctions: vmcommonBuiltInFunctions.NewBuiltInFunctionContainer(), BlockChainHook: &testscommon.BlockChainHookStub{}, Hasher: &hashingMocks.HasherMock{}, + PubKeyConverter: testscommon.RealWorldBech32PubkeyConverter, } } @@ -137,6 +139,33 @@ func TestNewVMContainerFactory_NilHasherShouldErr(t *testing.T) { assert.Equal(t, process.ErrNilHasher, err) } +func TestNewVMContainerFactory_NilPubKeyConverterShouldErr(t *testing.T) { + args := createMockVMAccountsArguments() + args.PubKeyConverter = nil + vmf, err := NewVMContainerFactory(args) + + assert.Nil(t, vmf) + assert.Equal(t, process.ErrNilPubkeyConverter, err) +} + +func TestNewVMContainerFactory_EmptyOpcodeAddressListErr(t *testing.T) { + args := createMockVMAccountsArguments() + args.Config.TransferAndExecuteByUserAddresses = nil + vmf, err := NewVMContainerFactory(args) + + assert.Nil(t, vmf) + assert.Equal(t, process.ErrTransferAndExecuteByUserAddressesIsNil, err) +} + +func TestNewVMContainerFactory_WrongAddressErr(t *testing.T) { + args := createMockVMAccountsArguments() + args.Config.TransferAndExecuteByUserAddresses = []string{"just"} + vmf, err := NewVMContainerFactory(args) + + assert.Nil(t, vmf) + assert.Equal(t, process.ErrTransferAndExecuteByUserAddressesIsNil, err) +} + func TestNewVMContainerFactory_OkValues(t *testing.T) { if runtime.GOARCH == "arm64" { t.Skip("skipping test on arm64") From 967f1cbf2d146b1c34b4506419199a883f565049 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 24 Apr 2024 12:59:17 +0300 Subject: [PATCH 191/503] integration continues --- factory/api/apiResolverFactory.go | 1 + factory/processing/blockProcessorCreator.go | 1 + genesis/process/shardGenesisBlockCreator.go | 1 + integrationTests/testProcessorNode.go | 2 ++ integrationTests/vm/testInitializer.go | 2 ++ integrationTests/vm/wasm/utils.go | 1 + 6 files changed, 8 insertions(+) diff --git a/factory/api/apiResolverFactory.go b/factory/api/apiResolverFactory.go index 889be426869..dfefa56ff94 100644 --- a/factory/api/apiResolverFactory.go +++ b/factory/api/apiResolverFactory.go @@ -529,6 +529,7 @@ func createShardVmContainerFactory(args scQueryElementArgs, argsHook hooks.ArgBl WasmVMChangeLocker: args.coreComponents.WasmVMChangeLocker(), ESDTTransferParser: esdtTransferParser, Hasher: args.coreComponents.Hasher(), + PubKeyConverter: args.coreComponents.AddressPubKeyConverter(), } log.Debug("apiResolver: enable epoch for sc deploy", "epoch", args.epochConfig.EnableEpochs.SCDeployEnableEpoch) diff --git a/factory/processing/blockProcessorCreator.go b/factory/processing/blockProcessorCreator.go index 7db9e20cf7d..a15a7c20e92 100644 --- a/factory/processing/blockProcessorCreator.go +++ b/factory/processing/blockProcessorCreator.go @@ -1086,6 +1086,7 @@ func (pcf *processComponentsFactory) createVMFactoryShard( WasmVMChangeLocker: wasmVMChangeLocker, ESDTTransferParser: esdtTransferParser, Hasher: pcf.coreData.Hasher(), + PubKeyConverter: pcf.coreData.AddressPubKeyConverter(), } return shard.NewVMContainerFactory(argsNewVMFactory) diff --git a/genesis/process/shardGenesisBlockCreator.go b/genesis/process/shardGenesisBlockCreator.go index 730f196cc37..dcf6aac7a99 100644 --- a/genesis/process/shardGenesisBlockCreator.go +++ b/genesis/process/shardGenesisBlockCreator.go @@ -420,6 +420,7 @@ func createProcessorsForShardGenesisBlock(arg ArgsGenesisBlockCreator, enableEpo ESDTTransferParser: esdtTransferParser, BuiltInFunctions: argsHook.BuiltInFunctions, Hasher: arg.Core.Hasher(), + PubKeyConverter: arg.Core.AddressPubKeyConverter(), } vmFactoryImpl, err := shard.NewVMContainerFactory(argsNewVMFactory) if err != nil { diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index b52cc3585a8..6bd6b68c5f6 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -1002,6 +1002,7 @@ func (tpn *TestProcessorNode) createFullSCQueryService(gasMap map[string]map[str WasmVMChangeLocker: tpn.WasmVMChangeLocker, ESDTTransferParser: esdtTransferParser, Hasher: TestHasher, + PubKeyConverter: testPubkeyConverter, } vmFactory, _ = shard.NewVMContainerFactory(argsNewVMFactory) } @@ -1657,6 +1658,7 @@ func (tpn *TestProcessorNode) initInnerProcessors(gasMap map[string]map[string]u WasmVMChangeLocker: tpn.WasmVMChangeLocker, ESDTTransferParser: esdtTransferParser, Hasher: TestHasher, + PubKeyConverter: testPubkeyConverter, } vmFactory, _ := shard.NewVMContainerFactory(argsNewVMFactory) diff --git a/integrationTests/vm/testInitializer.go b/integrationTests/vm/testInitializer.go index 7d44d945e14..4ffd57197ca 100644 --- a/integrationTests/vm/testInitializer.go +++ b/integrationTests/vm/testInitializer.go @@ -609,6 +609,7 @@ func CreateVMAndBlockchainHookAndDataPool( WasmVMChangeLocker: wasmVMChangeLocker, ESDTTransferParser: esdtTransferParser, Hasher: integrationtests.TestHasher, + PubKeyConverter: pubkeyConv, } vmFactory, err := shard.NewVMContainerFactory(argsNewVMFactory) if err != nil { @@ -796,6 +797,7 @@ func CreateVMConfigWithVersion(version string) *config.VirtualMachineConfig { }, }, TimeOutForSCExecutionInMilliseconds: 10000, // 10 seconds + TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, } } diff --git a/integrationTests/vm/wasm/utils.go b/integrationTests/vm/wasm/utils.go index 5fa5f84ae6f..223d374dd0b 100644 --- a/integrationTests/vm/wasm/utils.go +++ b/integrationTests/vm/wasm/utils.go @@ -334,6 +334,7 @@ func (context *TestContext) initVMAndBlockchainHook() { WasmVMChangeLocker: context.WasmVMChangeLocker, ESDTTransferParser: esdtTransferParser, Hasher: hasher, + PubKeyConverter: pkConverter, } vmFactory, err := shard.NewVMContainerFactory(argsNewVMFactory) require.Nil(context.T, err) From c0628d32adba63cb21aba5c23497b6d9d914a193 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 24 Apr 2024 13:24:10 +0300 Subject: [PATCH 192/503] go mod --- go.mod | 6 +++--- go.sum | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index f97add64dcc..009647c0fb3 100644 --- a/go.mod +++ b/go.mod @@ -23,9 +23,9 @@ require ( github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474 github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240423121536-5130480c0f69 github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240423121845-bfe3bf281a21 - github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240321152247-79521988c8e6 - github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240321152532-45da5eabdc38 - github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240321152756-16110ce9d968 + github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240306144544-4b4bb881bf1b + github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240306144900-77c0ff774465 + github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240306143606-1569f3bd397b github.com/pelletier/go-toml v1.9.3 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.14.0 diff --git a/go.sum b/go.sum index 2ae4bd22318..9ab6b204d08 100644 --- a/go.sum +++ b/go.sum @@ -403,12 +403,12 @@ github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240423121536-5130480c0f6 github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240423121536-5130480c0f69/go.mod h1:G6daPJC6bFsvAw45RPMCRi2rP+8LjFxa8G+3alHuJow= github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240423121845-bfe3bf281a21 h1:XJ9df6NqyLm9e+e2J8NI7wSfUYwF5HD1fL/0KKfViAo= github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240423121845-bfe3bf281a21/go.mod h1:DyMusfHXRXyVYQmH2umBTZD5gm6p136EJNC6YI2l+kU= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240321152247-79521988c8e6 h1:7HqUo9YmpsfN/y9px6RmzREJm5O6ZzP9NqvFSrHTw24= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240321152247-79521988c8e6/go.mod h1:H2H/zoskiZC0lEokq9qMFVxRkB0RWVDPLjHbG/NrGUU= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240321152532-45da5eabdc38 h1:SAKjOByxXkZ5Sys5O4IkrrSGCKLoPvD+cCJJEvbev4w= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240321152532-45da5eabdc38/go.mod h1:3dhvJ5/SgEMKAaIYHAOzo3nmOmJik/DDXaQW21PUno4= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240321152756-16110ce9d968 h1:14A3e5rqaXXXOFGC0DjOWtGFiVLx20TNghsaja0u4E0= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240321152756-16110ce9d968/go.mod h1:XJt8jbyLtP1+pPSzQmHwQG45hH/qazz1H+Xk2wasfTs= +github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240306144544-4b4bb881bf1b h1:C5tZbCChIAFZcumxA80ygJCswTnxFXnhCTnnHaQvdW4= +github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240306144544-4b4bb881bf1b/go.mod h1:vUJBSSS7buq9Lri9/GH6d9ZkY3ypT1H3OwbLILaKdzA= +github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240306144900-77c0ff774465 h1:dQf+eMSSG7+Pd89WYOVdZlDIgV+mHgx7eVkTrUtQI2g= +github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240306144900-77c0ff774465/go.mod h1:6GInewWp3mHV46gDlmMZe2wqxAB/kQfUdMycHbXOKy8= +github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240306143606-1569f3bd397b h1:odRzgyC7DQVFg8S3s3qjY1bgna413yzt2acGY8U7VZ4= +github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240306143606-1569f3bd397b/go.mod h1:lsfNcdBPylrvzRBAfEWKiseggGQSpiKhlBA9FKO0v9E= 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 559ce9268ce6e1efc9d2e1544d6ce5911fd2ada8 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 24 Apr 2024 13:46:05 +0300 Subject: [PATCH 193/503] fixing tests --- integrationTests/testProcessorNode.go | 1 + process/factory/shard/vmContainerFactory.go | 5 +++++ process/factory/shard/vmContainerFactory_test.go | 2 +- testscommon/vmcommonMocks/userAccountStub.go | 9 +++++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index 6bd6b68c5f6..76a3f42c943 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -3498,6 +3498,7 @@ func getDefaultVMConfig() *config.VirtualMachineConfig { WasmVMVersions: []config.WasmVMVersionByEpoch{ {StartEpoch: 0, Version: "*"}, }, + TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, } } diff --git a/process/factory/shard/vmContainerFactory.go b/process/factory/shard/vmContainerFactory.go index cdcd3bc4e6d..d10cd0acb46 100644 --- a/process/factory/shard/vmContainerFactory.go +++ b/process/factory/shard/vmContainerFactory.go @@ -121,6 +121,11 @@ func NewVMContainerFactory(args ArgVMContainerFactory) (*vmContainerFactory, err return nil, err } + err = vmf.createMapOpCodeAddressIsAllowed() + if err != nil { + return nil, err + } + return vmf, nil } diff --git a/process/factory/shard/vmContainerFactory_test.go b/process/factory/shard/vmContainerFactory_test.go index 96c7d5e3089..1cbfc60e203 100644 --- a/process/factory/shard/vmContainerFactory_test.go +++ b/process/factory/shard/vmContainerFactory_test.go @@ -163,7 +163,7 @@ func TestNewVMContainerFactory_WrongAddressErr(t *testing.T) { vmf, err := NewVMContainerFactory(args) assert.Nil(t, vmf) - assert.Equal(t, process.ErrTransferAndExecuteByUserAddressesIsNil, err) + assert.Equal(t, err.Error(), "invalid bech32 string length 4") } func TestNewVMContainerFactory_OkValues(t *testing.T) { diff --git a/testscommon/vmcommonMocks/userAccountStub.go b/testscommon/vmcommonMocks/userAccountStub.go index 8f1eabf8a7f..57e88fe5378 100644 --- a/testscommon/vmcommonMocks/userAccountStub.go +++ b/testscommon/vmcommonMocks/userAccountStub.go @@ -14,6 +14,7 @@ type UserAccountStub struct { GetRootHashCalled func() []byte AccountDataHandlerCalled func() vmcommon.AccountDataHandler AddToBalanceCalled func(value *big.Int) error + SubFromBalanceCalled func(value *big.Int) error GetBalanceCalled func() *big.Int ClaimDeveloperRewardsCalled func([]byte) (*big.Int, error) GetDeveloperRewardCalled func() *big.Int @@ -74,6 +75,14 @@ func (uas *UserAccountStub) AddToBalance(value *big.Int) error { return nil } +// SubFromBalance - +func (uas *UserAccountStub) SubFromBalance(value *big.Int) error { + if uas.AddToBalanceCalled != nil { + return uas.SubFromBalanceCalled(value) + } + return nil +} + // GetBalance - func (uas *UserAccountStub) GetBalance() *big.Int { if uas.GetBalanceCalled != nil { From 5a5538e05332a16958af33cdb13c428fc8d5883c Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 24 Apr 2024 13:57:11 +0300 Subject: [PATCH 194/503] fixing tests --- factory/api/apiResolverFactory_test.go | 1 + genesis/process/genesisBlockCreator_test.go | 1 + integrationTests/multiShard/hardFork/hardFork_test.go | 1 + .../smartContract/polynetworkbridge/bridge_test.go | 5 ++++- integrationTests/testInitializer.go | 2 ++ integrationTests/vm/esdt/common.go | 1 + integrationTests/vm/esdt/process/esdtProcess_test.go | 5 ++++- integrationTests/vm/wasm/utils.go | 1 + integrationTests/vm/wasm/wasmvm/versionswitch/vm_test.go | 1 + .../vm/wasm/wasmvm/versionswitch_revert/vm_test.go | 1 + .../vm/wasm/wasmvm/versionswitch_vmquery/vm_test.go | 1 + node/customConfigsArm64_test.go | 1 + node/customConfigsDefault_test.go | 1 + testscommon/components/configs.go | 2 ++ testscommon/generalConfig.go | 2 ++ 15 files changed, 24 insertions(+), 2 deletions(-) diff --git a/factory/api/apiResolverFactory_test.go b/factory/api/apiResolverFactory_test.go index e929d66e701..c7da43d52f4 100644 --- a/factory/api/apiResolverFactory_test.go +++ b/factory/api/apiResolverFactory_test.go @@ -313,6 +313,7 @@ func createMockSCQueryElementArgs() api.SCQueryElementArgs { WasmVMVersions: []config.WasmVMVersionByEpoch{ {StartEpoch: 0, Version: "*"}, }, + TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, }, }, }, diff --git a/genesis/process/genesisBlockCreator_test.go b/genesis/process/genesisBlockCreator_test.go index 68c93b87f51..b7b788f0d37 100644 --- a/genesis/process/genesisBlockCreator_test.go +++ b/genesis/process/genesisBlockCreator_test.go @@ -92,6 +92,7 @@ func createMockArgument( WasmVMVersions: []config.WasmVMVersionByEpoch{ {StartEpoch: 0, Version: "*"}, }, + TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, }, HardForkConfig: config.HardforkConfig{ ImportKeysStorageConfig: config.StorageConfig{ diff --git a/integrationTests/multiShard/hardFork/hardFork_test.go b/integrationTests/multiShard/hardFork/hardFork_test.go index 6686aa5b5c2..7a1ad261e50 100644 --- a/integrationTests/multiShard/hardFork/hardFork_test.go +++ b/integrationTests/multiShard/hardFork/hardFork_test.go @@ -423,6 +423,7 @@ func hardForkImport( WasmVMVersions: []config.WasmVMVersionByEpoch{ {StartEpoch: 0, Version: "*"}, }, + TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, }, HardForkConfig: config.HardforkConfig{ ImportFolder: node.ExportFolder, diff --git a/integrationTests/multiShard/smartContract/polynetworkbridge/bridge_test.go b/integrationTests/multiShard/smartContract/polynetworkbridge/bridge_test.go index e09c0fe12c2..37b3aa7ef09 100644 --- a/integrationTests/multiShard/smartContract/polynetworkbridge/bridge_test.go +++ b/integrationTests/multiShard/smartContract/polynetworkbridge/bridge_test.go @@ -33,7 +33,10 @@ func TestBridgeSetupAndBurn(t *testing.T) { FixAsyncCallBackArgsListEnableEpoch: integrationTests.UnreachableEpoch, } arwenVersion := config.WasmVMVersionByEpoch{Version: "v1.4"} - vmConfig := &config.VirtualMachineConfig{WasmVMVersions: []config.WasmVMVersionByEpoch{arwenVersion}} + vmConfig := &config.VirtualMachineConfig{ + WasmVMVersions: []config.WasmVMVersionByEpoch{arwenVersion}, + TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, + } nodes := integrationTests.CreateNodesWithEnableEpochsAndVmConfig( numOfShards, nodesPerShard, diff --git a/integrationTests/testInitializer.go b/integrationTests/testInitializer.go index ca2ed8dcd25..462dd81b9a9 100644 --- a/integrationTests/testInitializer.go +++ b/integrationTests/testInitializer.go @@ -681,6 +681,7 @@ func CreateFullGenesisBlocks( WasmVMVersions: []config.WasmVMVersionByEpoch{ {StartEpoch: 0, Version: "*"}, }, + TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, }, TrieStorageManagers: trieStorageManagers, SystemSCConfig: config.SystemSmartContractsConfig{ @@ -797,6 +798,7 @@ func CreateGenesisMetaBlock( WasmVMVersions: []config.WasmVMVersionByEpoch{ {StartEpoch: 0, Version: "*"}, }, + TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, }, HardForkConfig: config.HardforkConfig{}, SystemSCConfig: config.SystemSmartContractsConfig{ diff --git a/integrationTests/vm/esdt/common.go b/integrationTests/vm/esdt/common.go index 2d04331a85f..9a813bdb6ad 100644 --- a/integrationTests/vm/esdt/common.go +++ b/integrationTests/vm/esdt/common.go @@ -194,6 +194,7 @@ func CreateNodesAndPrepareBalancesWithEpochsAndRoundsConfig(numOfShards int, ena WasmVMVersions: []config.WasmVMVersionByEpoch{ {StartEpoch: 0, Version: "*"}, }, + TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, }, ) diff --git a/integrationTests/vm/esdt/process/esdtProcess_test.go b/integrationTests/vm/esdt/process/esdtProcess_test.go index 5a1a2414fb3..4b4705500f2 100644 --- a/integrationTests/vm/esdt/process/esdtProcess_test.go +++ b/integrationTests/vm/esdt/process/esdtProcess_test.go @@ -1287,7 +1287,10 @@ func TestExecOnDestWithTokenTransferFromScAtoScBWithIntermediaryExecOnDest_NotEn FailExecutionOnEveryAPIErrorEnableEpoch: integrationTests.UnreachableEpoch, } arwenVersion := config.WasmVMVersionByEpoch{Version: "v1.4"} - vmConfig := &config.VirtualMachineConfig{WasmVMVersions: []config.WasmVMVersionByEpoch{arwenVersion}} + vmConfig := &config.VirtualMachineConfig{ + WasmVMVersions: []config.WasmVMVersionByEpoch{arwenVersion}, + TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, + } nodes := integrationTests.CreateNodesWithEnableEpochsAndVmConfig( numOfShards, nodesPerShard, diff --git a/integrationTests/vm/wasm/utils.go b/integrationTests/vm/wasm/utils.go index 223d374dd0b..bfe7b4b7ca9 100644 --- a/integrationTests/vm/wasm/utils.go +++ b/integrationTests/vm/wasm/utils.go @@ -319,6 +319,7 @@ func (context *TestContext) initVMAndBlockchainHook() { WasmVMVersions: []config.WasmVMVersionByEpoch{ {StartEpoch: 0, Version: "*"}, }, + TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, } esdtTransferParser, _ := parsers.NewESDTTransferParser(marshalizer) diff --git a/integrationTests/vm/wasm/wasmvm/versionswitch/vm_test.go b/integrationTests/vm/wasm/wasmvm/versionswitch/vm_test.go index e69b329162e..2361a44a6f1 100644 --- a/integrationTests/vm/wasm/wasmvm/versionswitch/vm_test.go +++ b/integrationTests/vm/wasm/wasmvm/versionswitch/vm_test.go @@ -36,6 +36,7 @@ func TestSCExecutionWithVMVersionSwitching(t *testing.T) { {StartEpoch: 15, Version: "v1.2"}, {StartEpoch: 16, Version: "v1.4"}, }, + TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, } gasSchedule, _ := common.LoadGasScheduleConfig(integrationTests.GasSchedulePath) diff --git a/integrationTests/vm/wasm/wasmvm/versionswitch_revert/vm_test.go b/integrationTests/vm/wasm/wasmvm/versionswitch_revert/vm_test.go index 9563bc24615..5004b6cc546 100644 --- a/integrationTests/vm/wasm/wasmvm/versionswitch_revert/vm_test.go +++ b/integrationTests/vm/wasm/wasmvm/versionswitch_revert/vm_test.go @@ -31,6 +31,7 @@ func TestSCExecutionWithVMVersionSwitchingEpochRevert(t *testing.T) { {StartEpoch: 10, Version: "v1.5"}, {StartEpoch: 11, Version: "v1.4"}, }, + TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, } gasSchedule, _ := common.LoadGasScheduleConfig(integrationTests.GasSchedulePath) diff --git a/integrationTests/vm/wasm/wasmvm/versionswitch_vmquery/vm_test.go b/integrationTests/vm/wasm/wasmvm/versionswitch_vmquery/vm_test.go index 52cf2ccb190..b6357216c4e 100644 --- a/integrationTests/vm/wasm/wasmvm/versionswitch_vmquery/vm_test.go +++ b/integrationTests/vm/wasm/wasmvm/versionswitch_vmquery/vm_test.go @@ -31,6 +31,7 @@ func TestSCExecutionWithVMVersionSwitchingEpochRevertAndVMQueries(t *testing.T) {StartEpoch: 8, Version: "v1.3"}, {StartEpoch: 9, Version: "v1.4"}, }, + TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, } gasSchedule, _ := common.LoadGasScheduleConfig(integrationTests.GasSchedulePath) diff --git a/node/customConfigsArm64_test.go b/node/customConfigsArm64_test.go index 925774a3318..5af9a729518 100644 --- a/node/customConfigsArm64_test.go +++ b/node/customConfigsArm64_test.go @@ -31,6 +31,7 @@ func TestApplyArchCustomConfigs(t *testing.T) { Version: "v1.5", }, }, + TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, TimeOutForSCExecutionInMilliseconds: 1, WasmerSIGSEGVPassthrough: true, } diff --git a/node/customConfigsDefault_test.go b/node/customConfigsDefault_test.go index 8f9e8eb6521..705959b78cc 100644 --- a/node/customConfigsDefault_test.go +++ b/node/customConfigsDefault_test.go @@ -31,6 +31,7 @@ func TestApplyArchCustomConfigs(t *testing.T) { Version: "v1.5", }, }, + TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, TimeOutForSCExecutionInMilliseconds: 1, WasmerSIGSEGVPassthrough: true, } diff --git a/testscommon/components/configs.go b/testscommon/components/configs.go index 96af9f41987..0fe56651851 100644 --- a/testscommon/components/configs.go +++ b/testscommon/components/configs.go @@ -75,12 +75,14 @@ func GetGeneralConfig() config.Config { WasmVMVersions: []config.WasmVMVersionByEpoch{ {StartEpoch: 0, Version: "v0.3"}, }, + TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, }, }, Execution: config.VirtualMachineConfig{ WasmVMVersions: []config.WasmVMVersionByEpoch{ {StartEpoch: 0, Version: "v0.3"}, }, + TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, }, GasConfig: config.VirtualMachineGasConfig{ ShardMaxGasPerVmQuery: 1_500_000_000, diff --git a/testscommon/generalConfig.go b/testscommon/generalConfig.go index 06814edb1f5..460a169a507 100644 --- a/testscommon/generalConfig.go +++ b/testscommon/generalConfig.go @@ -380,6 +380,7 @@ func GetGeneralConfig() config.Config { WasmVMVersions: []config.WasmVMVersionByEpoch{ {StartEpoch: 0, Version: "*"}, }, + TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, }, Querying: config.QueryVirtualMachineConfig{ NumConcurrentVMs: 1, @@ -387,6 +388,7 @@ func GetGeneralConfig() config.Config { WasmVMVersions: []config.WasmVMVersionByEpoch{ {StartEpoch: 0, Version: "*"}, }, + TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, }, }, }, From 1d51e21454000f962896d640663df82d0bb407ee Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 24 Apr 2024 14:06:09 +0300 Subject: [PATCH 195/503] fixing go mod --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 009647c0fb3..a174bce0e87 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474 github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240423121536-5130480c0f69 - github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240423121845-bfe3bf281a21 + github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240424110355-a970819f5a9d github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240306144544-4b4bb881bf1b github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240306144900-77c0ff774465 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240306143606-1569f3bd397b diff --git a/go.sum b/go.sum index 9ab6b204d08..a020f72d672 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474 github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474/go.mod h1:hnc6H4D5Ge1haRAQ6QHTXhyh+CT2DRiNJ0U0HQYI3DY= github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240423121536-5130480c0f69 h1:XxY0OBA7npOBj1GzeuzOwWhbCaDK2Gne6hnjLBJJiho= github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240423121536-5130480c0f69/go.mod h1:G6daPJC6bFsvAw45RPMCRi2rP+8LjFxa8G+3alHuJow= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240423121845-bfe3bf281a21 h1:XJ9df6NqyLm9e+e2J8NI7wSfUYwF5HD1fL/0KKfViAo= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240423121845-bfe3bf281a21/go.mod h1:DyMusfHXRXyVYQmH2umBTZD5gm6p136EJNC6YI2l+kU= +github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240424110355-a970819f5a9d h1:8CCcWHUKVVTRrePUhstggVCs+cEAkKTEX55R19Pz+lM= +github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240424110355-a970819f5a9d/go.mod h1:DyMusfHXRXyVYQmH2umBTZD5gm6p136EJNC6YI2l+kU= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240306144544-4b4bb881bf1b h1:C5tZbCChIAFZcumxA80ygJCswTnxFXnhCTnnHaQvdW4= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240306144544-4b4bb881bf1b/go.mod h1:vUJBSSS7buq9Lri9/GH6d9ZkY3ypT1H3OwbLILaKdzA= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240306144900-77c0ff774465 h1:dQf+eMSSG7+Pd89WYOVdZlDIgV+mHgx7eVkTrUtQI2g= From 323258c721db7dfa23c23815ffbf66e64bc8581b Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 24 Apr 2024 14:51:45 +0300 Subject: [PATCH 196/503] fixing go mod --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index a174bce0e87..dc31be25c23 100644 --- a/go.mod +++ b/go.mod @@ -21,11 +21,11 @@ require ( github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474 - github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240423121536-5130480c0f69 + github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240424111748-6dfa8aa14813 github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240424110355-a970819f5a9d - github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240306144544-4b4bb881bf1b - github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240306144900-77c0ff774465 - github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240306143606-1569f3bd397b + github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240424112443-1a66307bc44e + github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240424112610-ab7b9e5829bd + github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240424113019-3a7d2b215137 github.com/pelletier/go-toml v1.9.3 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.14.0 diff --git a/go.sum b/go.sum index a020f72d672..efaf414a29f 100644 --- a/go.sum +++ b/go.sum @@ -399,16 +399,16 @@ github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157/go.mod h1:ndk45i9J9McuCJpTcgiaK4ocd0yhnBBCPrlFwO6GRcs= github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474 h1:x65Su8ojHwA+NICp9DrSVGLDDcAlW04DafkqCHY1QPE= github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474/go.mod h1:hnc6H4D5Ge1haRAQ6QHTXhyh+CT2DRiNJ0U0HQYI3DY= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240423121536-5130480c0f69 h1:XxY0OBA7npOBj1GzeuzOwWhbCaDK2Gne6hnjLBJJiho= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240423121536-5130480c0f69/go.mod h1:G6daPJC6bFsvAw45RPMCRi2rP+8LjFxa8G+3alHuJow= +github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240424111748-6dfa8aa14813 h1:pjknvxvRG1fQ6Dc0ZjFkWBwDLfPn2DbtACIwTBwYIA8= +github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240424111748-6dfa8aa14813/go.mod h1:G6daPJC6bFsvAw45RPMCRi2rP+8LjFxa8G+3alHuJow= github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240424110355-a970819f5a9d h1:8CCcWHUKVVTRrePUhstggVCs+cEAkKTEX55R19Pz+lM= github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240424110355-a970819f5a9d/go.mod h1:DyMusfHXRXyVYQmH2umBTZD5gm6p136EJNC6YI2l+kU= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240306144544-4b4bb881bf1b h1:C5tZbCChIAFZcumxA80ygJCswTnxFXnhCTnnHaQvdW4= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240306144544-4b4bb881bf1b/go.mod h1:vUJBSSS7buq9Lri9/GH6d9ZkY3ypT1H3OwbLILaKdzA= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240306144900-77c0ff774465 h1:dQf+eMSSG7+Pd89WYOVdZlDIgV+mHgx7eVkTrUtQI2g= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240306144900-77c0ff774465/go.mod h1:6GInewWp3mHV46gDlmMZe2wqxAB/kQfUdMycHbXOKy8= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240306143606-1569f3bd397b h1:odRzgyC7DQVFg8S3s3qjY1bgna413yzt2acGY8U7VZ4= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240306143606-1569f3bd397b/go.mod h1:lsfNcdBPylrvzRBAfEWKiseggGQSpiKhlBA9FKO0v9E= +github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240424112443-1a66307bc44e h1:Yg5Bx9iuMBpe+MTbL+VTdINlQeqjqDFIAOE4A8sWamc= +github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240424112443-1a66307bc44e/go.mod h1:0hoqSWVXkNvg0iYWDpYQcLyCBwz0DPIrTVf3kAtXHwU= +github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240424112610-ab7b9e5829bd h1:uM2FFSLvdWT7V8xRCaP01roTINT3rfTXAaiWQ1yFhag= +github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240424112610-ab7b9e5829bd/go.mod h1:MgRH/vdAXmXQiRdmN/b7hTxmQfPVFbVDqAHKc6Z3064= +github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240424113019-3a7d2b215137 h1:JL0Nn39C6f9mWJ+16xaCbrWZcZ/+TkbBMKmPxf4IVKo= +github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240424113019-3a7d2b215137/go.mod h1:3i2JOOE0VYvZE4K9C0VLi8mM/bBrY0dyWu3f9aw8RZI= 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 3098003fb0f861d5e541f9329e4c014e7428be30 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 24 Apr 2024 15:37:47 +0300 Subject: [PATCH 197/503] fixing tests --- cmd/node/config/config.toml | 12 ++++-------- factory/api/apiResolverFactory_test.go | 7 ++++--- testscommon/components/configs.go | 12 ++++++++++-- testscommon/generalConfig.go | 12 ++++++++++-- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/cmd/node/config/config.toml b/cmd/node/config/config.toml index 1c69cf3238e..6e1205d5f7e 100644 --- a/cmd/node/config/config.toml +++ b/cmd/node/config/config.toml @@ -675,10 +675,8 @@ { StartEpoch = 0, Version = "v1.4" }, { StartEpoch = 1, Version = "v1.5" }, # TODO: set also the RoundActivations.DisableAsyncCallV1 accordingly ] - TransferAndExecuteByUserAddresses = [ # TODO: set real contract addresses - "erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe0", #shard 0 - "erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe1", #shard 1 - "erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe2", #shard 2 + TransferAndExecuteByUserAddresses = [ # TODO: set real contract addresses for all shards + "erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe3", #shard 0 ] [VirtualMachine.Querying] @@ -689,10 +687,8 @@ { StartEpoch = 0, Version = "v1.4" }, { StartEpoch = 1, Version = "v1.5" }, # TODO: set also the RoundActivations.DisableAsyncCallV1 accordingly ] - TransferAndExecuteByUserAddresses = [ # TODO: set real contract addresses - "erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe0", #shard 0 - "erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe1", #shard 1 - "erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe2", #shard 2 + TransferAndExecuteByUserAddresses = [ # TODO: set real contract addresses for all shards + "erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe3", ] [VirtualMachine.GasConfig] diff --git a/factory/api/apiResolverFactory_test.go b/factory/api/apiResolverFactory_test.go index c7da43d52f4..d5ab00af5b5 100644 --- a/factory/api/apiResolverFactory_test.go +++ b/factory/api/apiResolverFactory_test.go @@ -186,7 +186,8 @@ func TestCreateApiResolver(t *testing.T) { failingStepsInstance.addressPublicKeyConverterFailingStep = 3 apiResolver, err := api.CreateApiResolver(failingArgs) require.NotNil(t, err) - require.True(t, strings.Contains(strings.ToLower(err.Error()), "public key converter")) + fmt.Println(err.Error()) + require.True(t, strings.Contains(strings.ToLower(err.Error()), "key converter")) require.True(t, check.IfNil(apiResolver)) }) t.Run("createBuiltinFuncs fails should error", func(t *testing.T) { @@ -275,7 +276,7 @@ func TestCreateApiResolver(t *testing.T) { failingStepsInstance.addressPublicKeyConverterFailingStep = 10 apiResolver, err := api.CreateApiResolver(failingArgs) require.NotNil(t, err) - require.True(t, strings.Contains(strings.ToLower(err.Error()), "public key converter")) + require.True(t, strings.Contains(strings.ToLower(err.Error()), "key converter")) require.True(t, check.IfNil(apiResolver)) }) t.Run("should work", func(t *testing.T) { @@ -313,7 +314,7 @@ func createMockSCQueryElementArgs() api.SCQueryElementArgs { WasmVMVersions: []config.WasmVMVersionByEpoch{ {StartEpoch: 0, Version: "*"}, }, - TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, + TransferAndExecuteByUserAddresses: []string{"erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe3"}, }, }, }, diff --git a/testscommon/components/configs.go b/testscommon/components/configs.go index 0fe56651851..f86a5ae59cc 100644 --- a/testscommon/components/configs.go +++ b/testscommon/components/configs.go @@ -75,14 +75,22 @@ func GetGeneralConfig() config.Config { WasmVMVersions: []config.WasmVMVersionByEpoch{ {StartEpoch: 0, Version: "v0.3"}, }, - TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, + TransferAndExecuteByUserAddresses: []string{ + "erd1he8wwxn4az3j82p7wwqsdk794dm7hcrwny6f8dfegkfla34udx7qrf7xje", //shard 0 + "erd1fpkcgel4gcmh8zqqdt043yfcn5tyx8373kg6q2qmkxzu4dqamc0swts65c", //shard 1 + "erd1najnxxweyw6plhg8efql330nttrj6l5cf87wqsuym85s9ha0hmdqnqgenp", //shard 2 + }, }, }, Execution: config.VirtualMachineConfig{ WasmVMVersions: []config.WasmVMVersionByEpoch{ {StartEpoch: 0, Version: "v0.3"}, }, - TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, + TransferAndExecuteByUserAddresses: []string{ + "erd1he8wwxn4az3j82p7wwqsdk794dm7hcrwny6f8dfegkfla34udx7qrf7xje", //shard 0 + "erd1fpkcgel4gcmh8zqqdt043yfcn5tyx8373kg6q2qmkxzu4dqamc0swts65c", //shard 1 + "erd1najnxxweyw6plhg8efql330nttrj6l5cf87wqsuym85s9ha0hmdqnqgenp", //shard 2 + }, }, GasConfig: config.VirtualMachineGasConfig{ ShardMaxGasPerVmQuery: 1_500_000_000, diff --git a/testscommon/generalConfig.go b/testscommon/generalConfig.go index 460a169a507..1eea96a2bdb 100644 --- a/testscommon/generalConfig.go +++ b/testscommon/generalConfig.go @@ -380,7 +380,11 @@ func GetGeneralConfig() config.Config { WasmVMVersions: []config.WasmVMVersionByEpoch{ {StartEpoch: 0, Version: "*"}, }, - TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, + TransferAndExecuteByUserAddresses: []string{ + "erd1he8wwxn4az3j82p7wwqsdk794dm7hcrwny6f8dfegkfla34udx7qrf7xje", //shard 0 + "erd1fpkcgel4gcmh8zqqdt043yfcn5tyx8373kg6q2qmkxzu4dqamc0swts65c", //shard 1 + "erd1najnxxweyw6plhg8efql330nttrj6l5cf87wqsuym85s9ha0hmdqnqgenp", //shard 2 + }, }, Querying: config.QueryVirtualMachineConfig{ NumConcurrentVMs: 1, @@ -388,7 +392,11 @@ func GetGeneralConfig() config.Config { WasmVMVersions: []config.WasmVMVersionByEpoch{ {StartEpoch: 0, Version: "*"}, }, - TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, + TransferAndExecuteByUserAddresses: []string{ + "erd1he8wwxn4az3j82p7wwqsdk794dm7hcrwny6f8dfegkfla34udx7qrf7xje", //shard 0 + "erd1fpkcgel4gcmh8zqqdt043yfcn5tyx8373kg6q2qmkxzu4dqamc0swts65c", //shard 1 + "erd1najnxxweyw6plhg8efql330nttrj6l5cf87wqsuym85s9ha0hmdqnqgenp", //shard 2 + }, }, }, }, From 183514bc8c80130fc8f4fe23608eab9913c127f2 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 24 Apr 2024 16:07:42 +0300 Subject: [PATCH 198/503] fixing tests --- integrationTests/multiShard/hardFork/hardFork_test.go | 2 +- .../smartContract/polynetworkbridge/bridge_test.go | 2 +- integrationTests/testInitializer.go | 4 ++-- integrationTests/testProcessorNode.go | 6 +++--- integrationTests/vm/esdt/common.go | 2 +- integrationTests/vm/esdt/process/esdtProcess_test.go | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/integrationTests/multiShard/hardFork/hardFork_test.go b/integrationTests/multiShard/hardFork/hardFork_test.go index 7a1ad261e50..61dbada5251 100644 --- a/integrationTests/multiShard/hardFork/hardFork_test.go +++ b/integrationTests/multiShard/hardFork/hardFork_test.go @@ -423,7 +423,7 @@ func hardForkImport( WasmVMVersions: []config.WasmVMVersionByEpoch{ {StartEpoch: 0, Version: "*"}, }, - TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, + TransferAndExecuteByUserAddresses: []string{"erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe3"}, }, HardForkConfig: config.HardforkConfig{ ImportFolder: node.ExportFolder, diff --git a/integrationTests/multiShard/smartContract/polynetworkbridge/bridge_test.go b/integrationTests/multiShard/smartContract/polynetworkbridge/bridge_test.go index 37b3aa7ef09..b74acc3b392 100644 --- a/integrationTests/multiShard/smartContract/polynetworkbridge/bridge_test.go +++ b/integrationTests/multiShard/smartContract/polynetworkbridge/bridge_test.go @@ -35,7 +35,7 @@ func TestBridgeSetupAndBurn(t *testing.T) { arwenVersion := config.WasmVMVersionByEpoch{Version: "v1.4"} vmConfig := &config.VirtualMachineConfig{ WasmVMVersions: []config.WasmVMVersionByEpoch{arwenVersion}, - TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, + TransferAndExecuteByUserAddresses: []string{"erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe3"}, } nodes := integrationTests.CreateNodesWithEnableEpochsAndVmConfig( numOfShards, diff --git a/integrationTests/testInitializer.go b/integrationTests/testInitializer.go index 462dd81b9a9..a7c6cdac3c3 100644 --- a/integrationTests/testInitializer.go +++ b/integrationTests/testInitializer.go @@ -681,7 +681,7 @@ func CreateFullGenesisBlocks( WasmVMVersions: []config.WasmVMVersionByEpoch{ {StartEpoch: 0, Version: "*"}, }, - TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, + TransferAndExecuteByUserAddresses: []string{"erd1fpkcgel4gcmh8zqqdt043yfcn5tyx8373kg6q2qmkxzu4dqamc0swts65c"}, }, TrieStorageManagers: trieStorageManagers, SystemSCConfig: config.SystemSmartContractsConfig{ @@ -798,7 +798,7 @@ func CreateGenesisMetaBlock( WasmVMVersions: []config.WasmVMVersionByEpoch{ {StartEpoch: 0, Version: "*"}, }, - TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, + TransferAndExecuteByUserAddresses: []string{"erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe3"}, }, HardForkConfig: config.HardforkConfig{}, SystemSCConfig: config.SystemSmartContractsConfig{ diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index 76a3f42c943..a7468de8485 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -1002,7 +1002,7 @@ func (tpn *TestProcessorNode) createFullSCQueryService(gasMap map[string]map[str WasmVMChangeLocker: tpn.WasmVMChangeLocker, ESDTTransferParser: esdtTransferParser, Hasher: TestHasher, - PubKeyConverter: testPubkeyConverter, + PubKeyConverter: TestAddressPubkeyConverter, } vmFactory, _ = shard.NewVMContainerFactory(argsNewVMFactory) } @@ -1658,7 +1658,7 @@ func (tpn *TestProcessorNode) initInnerProcessors(gasMap map[string]map[string]u WasmVMChangeLocker: tpn.WasmVMChangeLocker, ESDTTransferParser: esdtTransferParser, Hasher: TestHasher, - PubKeyConverter: testPubkeyConverter, + PubKeyConverter: TestAddressPubkeyConverter, } vmFactory, _ := shard.NewVMContainerFactory(argsNewVMFactory) @@ -3498,7 +3498,7 @@ func getDefaultVMConfig() *config.VirtualMachineConfig { WasmVMVersions: []config.WasmVMVersionByEpoch{ {StartEpoch: 0, Version: "*"}, }, - TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, + TransferAndExecuteByUserAddresses: []string{"erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe3"}, } } diff --git a/integrationTests/vm/esdt/common.go b/integrationTests/vm/esdt/common.go index 9a813bdb6ad..0d3a798d592 100644 --- a/integrationTests/vm/esdt/common.go +++ b/integrationTests/vm/esdt/common.go @@ -194,7 +194,7 @@ func CreateNodesAndPrepareBalancesWithEpochsAndRoundsConfig(numOfShards int, ena WasmVMVersions: []config.WasmVMVersionByEpoch{ {StartEpoch: 0, Version: "*"}, }, - TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, + TransferAndExecuteByUserAddresses: []string{"erd1fpkcgel4gcmh8zqqdt043yfcn5tyx8373kg6q2qmkxzu4dqamc0swts65c"}, }, ) diff --git a/integrationTests/vm/esdt/process/esdtProcess_test.go b/integrationTests/vm/esdt/process/esdtProcess_test.go index 4b4705500f2..8fa9fd04101 100644 --- a/integrationTests/vm/esdt/process/esdtProcess_test.go +++ b/integrationTests/vm/esdt/process/esdtProcess_test.go @@ -1289,7 +1289,7 @@ func TestExecOnDestWithTokenTransferFromScAtoScBWithIntermediaryExecOnDest_NotEn arwenVersion := config.WasmVMVersionByEpoch{Version: "v1.4"} vmConfig := &config.VirtualMachineConfig{ WasmVMVersions: []config.WasmVMVersionByEpoch{arwenVersion}, - TransferAndExecuteByUserAddresses: []string{"3132333435363738393031323334353637383930313233343536373839303234"}, + TransferAndExecuteByUserAddresses: []string{"erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe3"}, } nodes := integrationTests.CreateNodesWithEnableEpochsAndVmConfig( numOfShards, From 5894e096c5b9b4e11cabcc01b4eba2bce136e071 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 25 Apr 2024 09:16:17 +0300 Subject: [PATCH 199/503] fixing tests --- go.mod | 2 +- go.sum | 4 ++-- .../multiShard/smartContract/scCallingSC_test.go | 2 ++ .../vm/txsFee/apiTransactionEvaluator_test.go | 12 ++++++------ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index dc31be25c23..5dbc58a2035 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474 github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240424111748-6dfa8aa14813 - github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240424110355-a970819f5a9d + github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240424134454-27f4efb28f47 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240424112443-1a66307bc44e github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240424112610-ab7b9e5829bd github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240424113019-3a7d2b215137 diff --git a/go.sum b/go.sum index efaf414a29f..51eb5a714a1 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474 github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474/go.mod h1:hnc6H4D5Ge1haRAQ6QHTXhyh+CT2DRiNJ0U0HQYI3DY= github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240424111748-6dfa8aa14813 h1:pjknvxvRG1fQ6Dc0ZjFkWBwDLfPn2DbtACIwTBwYIA8= github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240424111748-6dfa8aa14813/go.mod h1:G6daPJC6bFsvAw45RPMCRi2rP+8LjFxa8G+3alHuJow= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240424110355-a970819f5a9d h1:8CCcWHUKVVTRrePUhstggVCs+cEAkKTEX55R19Pz+lM= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240424110355-a970819f5a9d/go.mod h1:DyMusfHXRXyVYQmH2umBTZD5gm6p136EJNC6YI2l+kU= +github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240424134454-27f4efb28f47 h1:RGW/1czsPJtU10ojsOGWMpWLWENbbL6ruJ7kUZkT0Zo= +github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240424134454-27f4efb28f47/go.mod h1:DyMusfHXRXyVYQmH2umBTZD5gm6p136EJNC6YI2l+kU= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240424112443-1a66307bc44e h1:Yg5Bx9iuMBpe+MTbL+VTdINlQeqjqDFIAOE4A8sWamc= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240424112443-1a66307bc44e/go.mod h1:0hoqSWVXkNvg0iYWDpYQcLyCBwz0DPIrTVf3kAtXHwU= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240424112610-ab7b9e5829bd h1:uM2FFSLvdWT7V8xRCaP01roTINT3rfTXAaiWQ1yFhag= diff --git a/integrationTests/multiShard/smartContract/scCallingSC_test.go b/integrationTests/multiShard/smartContract/scCallingSC_test.go index 329b86de832..73ed54fb791 100644 --- a/integrationTests/multiShard/smartContract/scCallingSC_test.go +++ b/integrationTests/multiShard/smartContract/scCallingSC_test.go @@ -775,6 +775,7 @@ func TestSCCallingInCrossShardDelegation(t *testing.T) { require.True(t, bytes.Contains(vmOutputVersion.ReturnData[0], []byte("0.3."))) log.Info("SC deployed", "version", string(vmOutputVersion.ReturnData[0])) + logger.SetLogLevel("process/smartcontract:TRACE") nonce, round = integrationTests.WaitOperationToBeDone(t, nodes, 1, nonce, round, idxProposers) // set stake per node @@ -850,6 +851,7 @@ func TestSCCallingInCrossShardDelegation(t *testing.T) { FuncName: "getUserActiveStake", Arguments: [][]byte{delegateSCOwner}, } + vmOutput4, _, _ := shardNode.SCQueryService.ExecuteQuery(scQuery4) require.NotNil(t, vmOutput4) require.Equal(t, len(vmOutput4.ReturnData), 1) diff --git a/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go b/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go index 6c3f6844403..57ecec2bd7a 100644 --- a/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go +++ b/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go @@ -2,6 +2,7 @@ package txsFee import ( "encoding/hex" + "fmt" "math/big" "testing" @@ -30,9 +31,7 @@ func TestSCCallCostTransactionCost(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ - DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, - }) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) require.Nil(t, err) defer testContext.Close() @@ -40,8 +39,8 @@ func TestSCCallCostTransactionCost(t *testing.T) { utils.CleanAccumulatedIntermediateTransactions(t, testContext) sndAddr := []byte("12345678901234567890123456789112") - senderBalance := big.NewInt(100000) - gasLimit := uint64(1000) + senderBalance := big.NewInt(100000000000) + gasLimit := uint64(10000000) _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, senderBalance) @@ -49,7 +48,8 @@ func TestSCCallCostTransactionCost(t *testing.T) { res, err := testContext.TxCostHandler.ComputeTransactionGasLimit(tx) require.Nil(t, err) - require.Equal(t, uint64(418), res.GasUnits) + fmt.Println(res.GasUnits) + require.Equal(t, uint64(15704), res.GasUnits) } func TestScDeployTransactionCost(t *testing.T) { From 7ec4da7cf21da59153f10ed198a63c08f36e4607 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 25 Apr 2024 09:17:08 +0300 Subject: [PATCH 200/503] delete log --- integrationTests/multiShard/smartContract/scCallingSC_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/integrationTests/multiShard/smartContract/scCallingSC_test.go b/integrationTests/multiShard/smartContract/scCallingSC_test.go index 73ed54fb791..aee8eacfe5a 100644 --- a/integrationTests/multiShard/smartContract/scCallingSC_test.go +++ b/integrationTests/multiShard/smartContract/scCallingSC_test.go @@ -775,7 +775,6 @@ func TestSCCallingInCrossShardDelegation(t *testing.T) { require.True(t, bytes.Contains(vmOutputVersion.ReturnData[0], []byte("0.3."))) log.Info("SC deployed", "version", string(vmOutputVersion.ReturnData[0])) - logger.SetLogLevel("process/smartcontract:TRACE") nonce, round = integrationTests.WaitOperationToBeDone(t, nodes, 1, nonce, round, idxProposers) // set stake per node From bef659207acf334baa45b9b3925f86b2c9bb8c0a Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Thu, 25 Apr 2024 09:28:55 +0300 Subject: [PATCH 201/503] - fixed the genesis flag --- genesis/process/shardGenesisBlockCreator.go | 1 + 1 file changed, 1 insertion(+) diff --git a/genesis/process/shardGenesisBlockCreator.go b/genesis/process/shardGenesisBlockCreator.go index 3c7e47070c7..b984e3aa86f 100644 --- a/genesis/process/shardGenesisBlockCreator.go +++ b/genesis/process/shardGenesisBlockCreator.go @@ -65,6 +65,7 @@ func createGenesisConfig(providedEnableEpochs config.EnableEpochs) config.Enable NodesToShufflePerShard: 0, }, } + clonedConfig.StakeEnableEpoch = unreachableEpoch // we need to specifically disable this, we have exceptions in the staking system SC clonedConfig.DoubleKeyProtectionEnableEpoch = 0 return clonedConfig From 7149419bb9017fdfbd10f7f684887b371ff90f8d Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 25 Apr 2024 11:13:17 +0300 Subject: [PATCH 202/503] fixing tests --- integrationTests/multiShard/relayedTx/common.go | 2 +- .../multiShard/relayedTx/relayedTxV2_test.go | 6 +++--- .../multiShard/relayedTx/relayedTx_test.go | 14 +++++++------- .../multiShard/smartContract/scCallingSC_test.go | 2 +- integrationTests/vm/txsFee/scCalls_test.go | 12 ++++++------ 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/integrationTests/multiShard/relayedTx/common.go b/integrationTests/multiShard/relayedTx/common.go index f875dbb6f8b..33a5cedcc53 100644 --- a/integrationTests/multiShard/relayedTx/common.go +++ b/integrationTests/multiShard/relayedTx/common.go @@ -33,7 +33,7 @@ func CreateGeneralSetupForRelayTxTest() ([]*integrationTests.TestProcessorNode, integrationTests.DisplayAndStartNodes(nodes) - initialVal := big.NewInt(1000000000) + initialVal := big.NewInt(10000000000) integrationTests.MintAllNodes(nodes, initialVal) numPlayers := 5 diff --git a/integrationTests/multiShard/relayedTx/relayedTxV2_test.go b/integrationTests/multiShard/relayedTx/relayedTxV2_test.go index 9e23eeac1aa..0259a865f3f 100644 --- a/integrationTests/multiShard/relayedTx/relayedTxV2_test.go +++ b/integrationTests/multiShard/relayedTx/relayedTxV2_test.go @@ -42,19 +42,19 @@ func TestRelayedTransactionV2InMultiShardEnvironmentWithSmartContractTX(t *testi integrationTests.CreateAndSendTransactionWithGasLimit( nodes[0], big.NewInt(0), - 20000, + 2000000, make([]byte, 32), []byte(wasm.CreateDeployTxData(scCode)+"@"+initialSupply), integrationTests.ChainID, integrationTests.MinTransactionVersion, ) - transferTokenVMGas := uint64(7200) + transferTokenVMGas := uint64(720000) transferTokenBaseGas := ownerNode.EconomicsData.ComputeGasLimit(&transaction.Transaction{Data: []byte("transferToken@" + hex.EncodeToString(receiverAddress1) + "@00" + hex.EncodeToString(sendValue.Bytes()))}) transferTokenFullGas := transferTokenBaseGas + transferTokenVMGas initialTokenSupply := big.NewInt(1000000000) - initialPlusForGas := uint64(1000) + initialPlusForGas := uint64(100000) for _, player := range players { integrationTests.CreateAndSendTransactionWithGasLimit( ownerNode, diff --git a/integrationTests/multiShard/relayedTx/relayedTx_test.go b/integrationTests/multiShard/relayedTx/relayedTx_test.go index 9ca8c5a6d34..a78931a4f91 100644 --- a/integrationTests/multiShard/relayedTx/relayedTx_test.go +++ b/integrationTests/multiShard/relayedTx/relayedTx_test.go @@ -103,19 +103,19 @@ func TestRelayedTransactionInMultiShardEnvironmentWithSmartContractTX(t *testing integrationTests.CreateAndSendTransactionWithGasLimit( nodes[0], big.NewInt(0), - 20000, + 200000, make([]byte, 32), []byte(wasm.CreateDeployTxData(scCode)+"@"+initialSupply), integrationTests.ChainID, integrationTests.MinTransactionVersion, ) - transferTokenVMGas := uint64(7200) + transferTokenVMGas := uint64(720000) transferTokenBaseGas := ownerNode.EconomicsData.ComputeGasLimit(&transaction.Transaction{Data: []byte("transferToken@" + hex.EncodeToString(receiverAddress1) + "@00" + hex.EncodeToString(sendValue.Bytes()))}) transferTokenFullGas := transferTokenBaseGas + transferTokenVMGas initialTokenSupply := big.NewInt(1000000000) - initialPlusForGas := uint64(1000) + initialPlusForGas := uint64(100000) for _, player := range players { integrationTests.CreateAndSendTransactionWithGasLimit( ownerNode, @@ -285,7 +285,7 @@ func TestRelayedTransactionInMultiShardEnvironmentWithAttestationContract(t *tes integrationTests.CreateAndSendTransactionWithGasLimit( nodes[0], big.NewInt(0), - 200000, + 2000000, make([]byte, 32), []byte(wasm.CreateDeployTxData(scCode)+"@"+hex.EncodeToString(registerValue.Bytes())+"@"+hex.EncodeToString(relayer.Address)+"@"+"ababab"), integrationTests.ChainID, @@ -293,9 +293,9 @@ func TestRelayedTransactionInMultiShardEnvironmentWithAttestationContract(t *tes ) time.Sleep(time.Second) - registerVMGas := uint64(100000) - savePublicInfoVMGas := uint64(100000) - attestVMGas := uint64(100000) + registerVMGas := uint64(10000000) + savePublicInfoVMGas := uint64(10000000) + attestVMGas := uint64(10000000) round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) diff --git a/integrationTests/multiShard/smartContract/scCallingSC_test.go b/integrationTests/multiShard/smartContract/scCallingSC_test.go index aee8eacfe5a..52b24371d15 100644 --- a/integrationTests/multiShard/smartContract/scCallingSC_test.go +++ b/integrationTests/multiShard/smartContract/scCallingSC_test.go @@ -800,7 +800,7 @@ func TestSCCallingInCrossShardDelegation(t *testing.T) { // activate the delegation, this involves an async call to validatorSC stakeAllAvailableTxData := "stakeAllAvailable" - integrationTests.CreateAndSendTransaction(shardNode, nodes, big.NewInt(0), delegateSCAddress, stakeAllAvailableTxData, integrationTests.AdditionalGasLimit) + integrationTests.CreateAndSendTransaction(shardNode, nodes, big.NewInt(0), delegateSCAddress, stakeAllAvailableTxData, 2*integrationTests.AdditionalGasLimit) nonce, round = integrationTests.WaitOperationToBeDone(t, nodes, 1, nonce, round, idxProposers) diff --git a/integrationTests/vm/txsFee/scCalls_test.go b/integrationTests/vm/txsFee/scCalls_test.go index 2a523825f96..4a499c3b095 100644 --- a/integrationTests/vm/txsFee/scCalls_test.go +++ b/integrationTests/vm/txsFee/scCalls_test.go @@ -100,8 +100,8 @@ func TestScCallShouldWork(t *testing.T) { utils.CleanAccumulatedIntermediateTransactions(t, testContext) sndAddr := []byte("12345678901234567890123456789112") - senderBalance := big.NewInt(100000) - gasLimit := uint64(1000) + senderBalance := big.NewInt(1000000000) + gasLimit := uint64(100000) _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, senderBalance) @@ -109,7 +109,7 @@ func TestScCallShouldWork(t *testing.T) { tx := vm.CreateTransaction(idx, big.NewInt(0), sndAddr, scAddress, gasPrice, gasLimit, []byte("increment")) calculatedGasLimit := vm.ComputeGasLimit(nil, testContext, tx) - require.Equal(t, uint64(418), calculatedGasLimit) + require.Equal(t, uint64(15704), calculatedGasLimit) returnCode, errProcess := testContext.TxProcessor.ProcessTransaction(tx) require.Nil(t, errProcess) @@ -122,15 +122,15 @@ func TestScCallShouldWork(t *testing.T) { ret := vm.GetIntValueFromSC(nil, testContext.Accounts, scAddress, "get") require.Equal(t, big.NewInt(11), ret) - expectedBalance := big.NewInt(58200) + expectedBalance := big.NewInt(998429600) vm.TestAccount(t, testContext.Accounts, sndAddr, 10, expectedBalance) // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(53700), accumulatedFees) + require.Equal(t, big.NewInt(1582300), accumulatedFees) developerFees := testContext.TxFeeHandler.GetDeveloperFees() - require.Equal(t, big.NewInt(4479), developerFees) + require.Equal(t, big.NewInt(157339), developerFees) } func TestScCallContractNotFoundShouldConsumeGas(t *testing.T) { From 7de5a079a4c1c5141a3e49aa8a2bc29885989872 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 25 Apr 2024 11:55:34 +0300 Subject: [PATCH 203/503] fixing tests --- .../vm/txsFee/multiShard/asyncCall_test.go | 8 +++--- .../vm/txsFee/multiShard/asyncESDT_test.go | 18 ++++++------- .../multiShard/builtInFunctions_test.go | 26 +++++++++---------- .../multiShard/relayedTxScCalls_test.go | 16 ++++++------ .../vm/txsFee/multiShard/scCalls_test.go | 2 +- integrationTests/vm/txsFee/utils/utils.go | 6 ++--- .../vm/wasm/delegation/delegation_test.go | 4 +-- .../vm/wasm/upgrades/upgrades_test.go | 14 +++++----- 8 files changed, 47 insertions(+), 47 deletions(-) diff --git a/integrationTests/vm/txsFee/multiShard/asyncCall_test.go b/integrationTests/vm/txsFee/multiShard/asyncCall_test.go index 9a0297de698..e6e7fe5ce6e 100644 --- a/integrationTests/vm/txsFee/multiShard/asyncCall_test.go +++ b/integrationTests/vm/txsFee/multiShard/asyncCall_test.go @@ -97,8 +97,8 @@ func TestAsyncCallShouldWork(t *testing.T) { res := vm.GetIntValueFromSC(nil, testContextFirstContract.Accounts, firstScAddress, "numCalled") require.Equal(t, big.NewInt(1), res) - require.Equal(t, big.NewInt(5540), testContextFirstContract.TxFeeHandler.GetAccumulatedFees()) - require.Equal(t, big.NewInt(554), testContextFirstContract.TxFeeHandler.GetDeveloperFees()) + require.Equal(t, big.NewInt(158400), testContextFirstContract.TxFeeHandler.GetAccumulatedFees()) + require.Equal(t, big.NewInt(15840), testContextFirstContract.TxFeeHandler.GetDeveloperFees()) intermediateTxs = testContextFirstContract.GetIntermediateTransactions(t) require.NotNil(t, intermediateTxs) @@ -107,8 +107,8 @@ func TestAsyncCallShouldWork(t *testing.T) { scr = intermediateTxs[0] utils.ProcessSCRResult(t, testContextSecondContract, scr, vmcommon.Ok, nil) - require.Equal(t, big.NewInt(49990510), testContextSecondContract.TxFeeHandler.GetAccumulatedFees()) - require.Equal(t, big.NewInt(4999051), testContextSecondContract.TxFeeHandler.GetDeveloperFees()) + require.Equal(t, big.NewInt(49837650), testContextSecondContract.TxFeeHandler.GetAccumulatedFees()) + require.Equal(t, big.NewInt(4983765), testContextSecondContract.TxFeeHandler.GetDeveloperFees()) intermediateTxs = testContextSecondContract.GetIntermediateTransactions(t) require.NotNil(t, intermediateTxs) diff --git a/integrationTests/vm/txsFee/multiShard/asyncESDT_test.go b/integrationTests/vm/txsFee/multiShard/asyncESDT_test.go index e7d78430350..21a894662a7 100644 --- a/integrationTests/vm/txsFee/multiShard/asyncESDT_test.go +++ b/integrationTests/vm/txsFee/multiShard/asyncESDT_test.go @@ -98,10 +98,10 @@ func TestAsyncESDTTransferWithSCCallShouldWork(t *testing.T) { _, err = testContextSender.Accounts.Commit() require.Nil(t, err) - expectedAccumulatedFees = big.NewInt(189890) + expectedAccumulatedFees = big.NewInt(1146530) require.Equal(t, expectedAccumulatedFees, testContextFirstContract.TxFeeHandler.GetAccumulatedFees()) - developerFees := big.NewInt(18989) + developerFees := big.NewInt(114653) require.Equal(t, developerFees, testContextFirstContract.TxFeeHandler.GetDeveloperFees()) utils.CheckESDTBalance(t, testContextFirstContract, firstSCAddress, token, big.NewInt(2500)) @@ -115,10 +115,10 @@ func TestAsyncESDTTransferWithSCCallShouldWork(t *testing.T) { utils.CheckESDTBalance(t, testContextSecondContract, secondSCAddress, token, big.NewInt(2500)) - accumulatedFee := big.NewInt(62340) + accumulatedFee := big.NewInt(540660) require.Equal(t, accumulatedFee, testContextSecondContract.TxFeeHandler.GetAccumulatedFees()) - developerFees = big.NewInt(6234) + developerFees = big.NewInt(54066) require.Equal(t, developerFees, testContextSecondContract.TxFeeHandler.GetDeveloperFees()) intermediateTxs = testContextSecondContract.GetIntermediateTransactions(t) @@ -126,7 +126,7 @@ func TestAsyncESDTTransferWithSCCallShouldWork(t *testing.T) { utils.ProcessSCRResult(t, testContextFirstContract, intermediateTxs[1], vmcommon.Ok, nil) - require.Equal(t, big.NewInt(4936720), testContextFirstContract.TxFeeHandler.GetAccumulatedFees()) + require.Equal(t, big.NewInt(4458400), testContextFirstContract.TxFeeHandler.GetAccumulatedFees()) } func TestAsyncESDTTransferWithSCCallSecondContractAnotherToken(t *testing.T) { @@ -211,10 +211,10 @@ func TestAsyncESDTTransferWithSCCallSecondContractAnotherToken(t *testing.T) { _, err = testContextSender.Accounts.Commit() require.Nil(t, err) - expectedAccumulatedFees = big.NewInt(189890) + expectedAccumulatedFees = big.NewInt(1146530) require.Equal(t, expectedAccumulatedFees, testContextFirstContract.TxFeeHandler.GetAccumulatedFees()) - developerFees := big.NewInt(18989) + developerFees := big.NewInt(114653) require.Equal(t, developerFees, testContextFirstContract.TxFeeHandler.GetDeveloperFees()) utils.CheckESDTBalance(t, testContextFirstContract, firstSCAddress, token, big.NewInt(2500)) @@ -227,7 +227,7 @@ func TestAsyncESDTTransferWithSCCallSecondContractAnotherToken(t *testing.T) { utils.CheckESDTBalance(t, testContextSecondContract, secondSCAddress, token, big.NewInt(0)) - accumulatedFee := big.NewInt(3720770) + accumulatedFee := big.NewInt(2764130) require.Equal(t, accumulatedFee, testContextSecondContract.TxFeeHandler.GetAccumulatedFees()) developerFees = big.NewInt(0) @@ -238,5 +238,5 @@ func TestAsyncESDTTransferWithSCCallSecondContractAnotherToken(t *testing.T) { utils.ProcessSCRResult(t, testContextFirstContract, intermediateTxs[0], vmcommon.Ok, nil) - require.Equal(t, big.NewInt(1278290), testContextFirstContract.TxFeeHandler.GetAccumulatedFees()) + require.Equal(t, big.NewInt(2234930), testContextFirstContract.TxFeeHandler.GetAccumulatedFees()) } diff --git a/integrationTests/vm/txsFee/multiShard/builtInFunctions_test.go b/integrationTests/vm/txsFee/multiShard/builtInFunctions_test.go index dc6172eeef8..fd0232072c2 100644 --- a/integrationTests/vm/txsFee/multiShard/builtInFunctions_test.go +++ b/integrationTests/vm/txsFee/multiShard/builtInFunctions_test.go @@ -66,7 +66,7 @@ func TestBuiltInFunctionExecuteOnSourceAndDestinationShouldWork(t *testing.T) { require.Equal(t, uint32(0), testContextDst.ShardCoordinator.ComputeId(newOwner)) gasPrice := uint64(10) - gasLimit := uint64(1000) + gasLimit := uint64(100000) txData := []byte(core.BuiltInFunctionChangeOwnerAddress + "@" + hex.EncodeToString(newOwner)) tx := vm.CreateTransaction(1, big.NewInt(0), owner, scAddr, gasPrice, gasLimit, txData) @@ -80,7 +80,7 @@ func TestBuiltInFunctionExecuteOnSourceAndDestinationShouldWork(t *testing.T) { utils.CheckOwnerAddr(t, testContextDst, scAddr, newOwner) accumulatedFees := testContextDst.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(10000), accumulatedFees) + require.Equal(t, big.NewInt(1000000), accumulatedFees) utils.CleanAccumulatedIntermediateTransactions(t, testContextDst) @@ -93,8 +93,8 @@ func TestBuiltInFunctionExecuteOnSourceAndDestinationShouldWork(t *testing.T) { scUserAcc := scStateAcc.(state.UserAccountHandler) currentSCDevBalance := scUserAcc.GetDeveloperReward() - gasLimit = uint64(500) - _, _ = vm.CreateAccount(testContextDst.Accounts, sndAddr, 0, big.NewInt(10000)) + gasLimit = uint64(50000) + _, _ = vm.CreateAccount(testContextDst.Accounts, sndAddr, 0, big.NewInt(100000000)) tx = vm.CreateTransaction(0, big.NewInt(0), sndAddr, scAddr, gasPrice, gasLimit, []byte("increment")) retCode, err := testContextDst.TxProcessor.ProcessTransaction(tx) @@ -104,18 +104,18 @@ func TestBuiltInFunctionExecuteOnSourceAndDestinationShouldWork(t *testing.T) { _, err = testContextDst.Accounts.Commit() require.Nil(t, err) - expectedBalance := big.NewInt(6130) + expectedBalance := big.NewInt(99843270) vm.TestAccount(t, testContextDst.Accounts, sndAddr, 1, expectedBalance) accumulatedFees = testContextDst.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(13870), accumulatedFees) + require.Equal(t, big.NewInt(1156730), accumulatedFees) developerFees := testContextDst.TxFeeHandler.GetDeveloperFees() - require.Equal(t, big.NewInt(1292), developerFees) + require.Equal(t, big.NewInt(115578), developerFees) // call get developer rewards - gasLimit = 500 - _, _ = vm.CreateAccount(testContextSource.Accounts, newOwner, 0, big.NewInt(10000)) + gasLimit = 500000 + _, _ = vm.CreateAccount(testContextSource.Accounts, newOwner, 0, big.NewInt(10000000)) txData = []byte(core.BuiltInFunctionClaimDeveloperRewards) tx = vm.CreateTransaction(0, big.NewInt(0), newOwner, scAddr, gasPrice, gasLimit, txData) @@ -124,14 +124,14 @@ func TestBuiltInFunctionExecuteOnSourceAndDestinationShouldWork(t *testing.T) { require.Equal(t, vmcommon.Ok, retCode) require.Nil(t, err) - expectedBalance = big.NewInt(5000) + expectedBalance = big.NewInt(5000000) utils.TestAccount(t, testContextSource.Accounts, newOwner, 1, expectedBalance) accumulatedFees = testContextSource.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(5000), accumulatedFees) + require.Equal(t, big.NewInt(5000000), accumulatedFees) developerFees = testContextSource.TxFeeHandler.GetDeveloperFees() - require.Equal(t, big.NewInt(477), developerFees) + require.Equal(t, big.NewInt(499977), developerFees) utils.CleanAccumulatedIntermediateTransactions(t, testContextDst) @@ -145,7 +145,7 @@ func TestBuiltInFunctionExecuteOnSourceAndDestinationShouldWork(t *testing.T) { utils.ProcessSCRResult(t, testContextSource, scr, vmcommon.Ok, nil) - expectedBalance = big.NewInt(5001 + 376 + currentSCDevBalance.Int64()) + expectedBalance = big.NewInt(499977 + 4515686 + currentSCDevBalance.Int64()) utils.TestAccount(t, testContextSource.Accounts, newOwner, 1, expectedBalance) } diff --git a/integrationTests/vm/txsFee/multiShard/relayedTxScCalls_test.go b/integrationTests/vm/txsFee/multiShard/relayedTxScCalls_test.go index 4e0f0d983fa..bbab4208aa2 100644 --- a/integrationTests/vm/txsFee/multiShard/relayedTxScCalls_test.go +++ b/integrationTests/vm/txsFee/multiShard/relayedTxScCalls_test.go @@ -58,14 +58,14 @@ func TestRelayedTxScCallMultiShardShouldWork(t *testing.T) { require.Equal(t, uint32(2), testContextInnerDst.ShardCoordinator.ComputeId(relayerAddr)) gasPrice := uint64(10) - gasLimit := uint64(500) + gasLimit := uint64(50000) innerTx := vm.CreateTransaction(0, big.NewInt(0), sndAddr, scAddr, gasPrice, gasLimit, []byte("increment")) rtxData := integrationTests.PrepareRelayedTxDataV1(innerTx) rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) rtx := vm.CreateTransaction(0, innerTx.Value, relayerAddr, sndAddr, gasPrice, rTxGasLimit, rtxData) - _, _ = vm.CreateAccount(testContextRelayer.Accounts, relayerAddr, 0, big.NewInt(10000)) + _, _ = vm.CreateAccount(testContextRelayer.Accounts, relayerAddr, 0, big.NewInt(10000000)) // execute on relayer shard retCode, err := testContextRelayer.TxProcessor.ProcessTransaction(rtx) @@ -75,12 +75,12 @@ func TestRelayedTxScCallMultiShardShouldWork(t *testing.T) { _, err = testContextRelayer.Accounts.Commit() require.Nil(t, err) - expectedBalance := big.NewInt(3130) + expectedBalance := big.NewInt(9498110) utils.TestAccount(t, testContextRelayer.Accounts, relayerAddr, 1, expectedBalance) // check accumulated fees accumulatedFees := testContextRelayer.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(1870), accumulatedFees) + require.Equal(t, big.NewInt(1890), accumulatedFees) developerFees := testContextRelayer.TxFeeHandler.GetDeveloperFees() require.Equal(t, big.NewInt(0), developerFees) @@ -115,21 +115,21 @@ func TestRelayedTxScCallMultiShardShouldWork(t *testing.T) { // check accumulated fees dest accumulatedFees = testContextInnerDst.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(3770), accumulatedFees) + require.Equal(t, big.NewInt(156630), accumulatedFees) developerFees = testContextInnerDst.TxFeeHandler.GetDeveloperFees() - require.Equal(t, big.NewInt(377), developerFees) + require.Equal(t, big.NewInt(15663), developerFees) txs = testContextInnerDst.GetIntermediateTransactions(t) scr = txs[0] utils.ProcessSCRResult(t, testContextRelayer, scr, vmcommon.Ok, nil) - expectedBalance = big.NewInt(4260) + expectedBalance = big.NewInt(9841380) utils.TestAccount(t, testContextRelayer.Accounts, relayerAddr, 1, expectedBalance) // check accumulated fees accumulatedFees = testContextRelayer.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(1870), accumulatedFees) + require.Equal(t, big.NewInt(1890), accumulatedFees) developerFees = testContextRelayer.TxFeeHandler.GetDeveloperFees() require.Equal(t, big.NewInt(0), developerFees) diff --git a/integrationTests/vm/txsFee/multiShard/scCalls_test.go b/integrationTests/vm/txsFee/multiShard/scCalls_test.go index 1338e280c65..f8f652efe7b 100644 --- a/integrationTests/vm/txsFee/multiShard/scCalls_test.go +++ b/integrationTests/vm/txsFee/multiShard/scCalls_test.go @@ -42,7 +42,7 @@ func TestScCallExecuteOnSourceAndDstShardShouldWork(t *testing.T) { require.Equal(t, uint32(0), shardID) gasPrice := uint64(10) - gasLimit := uint64(500) + gasLimit := uint64(50000) _, _ = vm.CreateAccount(testContextSource.Accounts, sndAddr, 0, big.NewInt(10000)) diff --git a/integrationTests/vm/txsFee/utils/utils.go b/integrationTests/vm/txsFee/utils/utils.go index 40f91cbe1c9..3eea35a4833 100644 --- a/integrationTests/vm/txsFee/utils/utils.go +++ b/integrationTests/vm/txsFee/utils/utils.go @@ -38,7 +38,7 @@ func DoDeploy( testContext *vm.VMTestContext, pathToContract string, ) (scAddr []byte, owner []byte) { - return doDeployInternal(t, testContext, pathToContract, 88100, 11900, 399) + return doDeployInternal(t, testContext, pathToContract, 9988100, 11900, 399) } // DoDeployOldCounter - @@ -47,7 +47,7 @@ func DoDeployOldCounter( testContext *vm.VMTestContext, pathToContract string, ) (scAddr []byte, owner []byte) { - return doDeployInternal(t, testContext, pathToContract, 89030, 10970, 368) + return doDeployInternal(t, testContext, pathToContract, 9989030, 10970, 368) } func doDeployInternal( @@ -58,7 +58,7 @@ func doDeployInternal( ) (scAddr []byte, owner []byte) { owner = []byte("12345678901234567890123456789011") senderNonce := uint64(0) - senderBalance := big.NewInt(100000) + senderBalance := big.NewInt(10000000) gasPrice := uint64(10) gasLimit := uint64(2000) diff --git a/integrationTests/vm/wasm/delegation/delegation_test.go b/integrationTests/vm/wasm/delegation/delegation_test.go index 9e9f394122f..b921f4cfb0f 100644 --- a/integrationTests/vm/wasm/delegation/delegation_test.go +++ b/integrationTests/vm/wasm/delegation/delegation_test.go @@ -83,12 +83,12 @@ func TestDelegation_Claims(t *testing.T) { context.GasLimit = 30000000 err = context.ExecuteSC(&context.Alice, "claimRewards") require.Nil(t, err) - require.Equal(t, 8148760, int(context.LastConsumedFee)) + require.Equal(t, 8577123, int(context.LastConsumedFee)) RequireAlmostEquals(t, NewBalance(600), NewBalanceBig(context.GetAccountBalanceDelta(&context.Alice))) err = context.ExecuteSC(&context.Bob, "claimRewards") require.Nil(t, err) - require.Equal(t, 8059660, int(context.LastConsumedFee)) + require.Equal(t, 8420179, int(context.LastConsumedFee)) RequireAlmostEquals(t, NewBalance(400), NewBalanceBig(context.GetAccountBalanceDelta(&context.Bob))) err = context.ExecuteSC(&context.Carol, "claimRewards") diff --git a/integrationTests/vm/wasm/upgrades/upgrades_test.go b/integrationTests/vm/wasm/upgrades/upgrades_test.go index 4a01b67a4ec..c6313d65e73 100644 --- a/integrationTests/vm/wasm/upgrades/upgrades_test.go +++ b/integrationTests/vm/wasm/upgrades/upgrades_test.go @@ -207,7 +207,7 @@ func TestUpgrades_HelloTrialAndError(t *testing.T) { make([]byte, 32), big.NewInt(0), deployTxData, - 1000, + 100000, ) require.Nil(t, err) @@ -221,7 +221,7 @@ func TestUpgrades_HelloTrialAndError(t *testing.T) { scAddress, big.NewInt(0), upgradeTxData, - 1000, + 100000, ) require.Nil(t, err) @@ -234,7 +234,7 @@ func TestUpgrades_HelloTrialAndError(t *testing.T) { scAddress, big.NewInt(0), upgradeTxData, - 1000, + 100000, ) require.Nil(t, err) @@ -264,7 +264,7 @@ func TestUpgrades_CounterTrialAndError(t *testing.T) { make([]byte, 32), big.NewInt(0), deployTxData, - 1000, + 100000, ) require.Nil(t, err) @@ -278,7 +278,7 @@ func TestUpgrades_CounterTrialAndError(t *testing.T) { scAddress, big.NewInt(0), "increment", - 1000, + 100000, ) require.Nil(t, err) @@ -291,7 +291,7 @@ func TestUpgrades_CounterTrialAndError(t *testing.T) { scAddress, big.NewInt(0), upgradeTxData, - 1000, + 100000, ) require.Nil(t, err) @@ -304,7 +304,7 @@ func TestUpgrades_CounterTrialAndError(t *testing.T) { scAddress, big.NewInt(0), upgradeTxData, - 1000, + 100000, ) require.Nil(t, err) From ce1c718dc70a93f86d6838cf0066e3228adb367e Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 25 Apr 2024 12:58:28 +0300 Subject: [PATCH 204/503] fixing tests --- .../vm/esdt/multisign/esdtMultisign_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/integrationTests/vm/esdt/multisign/esdtMultisign_test.go b/integrationTests/vm/esdt/multisign/esdtMultisign_test.go index 2beb0fa319c..fd8e0b6fbb8 100644 --- a/integrationTests/vm/esdt/multisign/esdtMultisign_test.go +++ b/integrationTests/vm/esdt/multisign/esdtMultisign_test.go @@ -187,7 +187,7 @@ func deployMultisig(t *testing.T, nodes []*integrationTests.TestProcessorNode, o require.Nil(t, err) log.Info("multisign contract", "address", encodedMultisigContractAddress) - integrationTests.CreateAndSendTransaction(nodes[ownerIdx], nodes, big.NewInt(0), emptyAddress, txData, 100000) + integrationTests.CreateAndSendTransaction(nodes[ownerIdx], nodes, big.NewInt(0), emptyAddress, txData, 1000000) return multisigContractAddress } @@ -233,8 +233,8 @@ func proposeIssueTokenAndTransferFunds( params = append(params, tokenPropertiesParams...) txData := strings.Join(params, "@") - integrationTests.CreateAndSendTransaction(nodes[ownerIdx], nodes, big.NewInt(1000000), multisignContractAddress, "deposit", 100000) - integrationTests.CreateAndSendTransaction(nodes[ownerIdx], nodes, big.NewInt(0), multisignContractAddress, txData, 100000) + integrationTests.CreateAndSendTransaction(nodes[ownerIdx], nodes, big.NewInt(1000000), multisignContractAddress, "deposit", 1000000) + integrationTests.CreateAndSendTransaction(nodes[ownerIdx], nodes, big.NewInt(0), multisignContractAddress, txData, 1000000) } func getActionID(t *testing.T, nodes []*integrationTests.TestProcessorNode, multisignContractAddress []byte) []byte { @@ -284,7 +284,7 @@ func boardMembersSignActionID( } txData := strings.Join(params, "@") - integrationTests.CreateAndSendTransaction(node, nodes, big.NewInt(0), multisignContractAddress, txData, 100000) + integrationTests.CreateAndSendTransaction(node, nodes, big.NewInt(0), multisignContractAddress, txData, 1000000) } } @@ -327,5 +327,5 @@ func proposeTransferToken( params := append(multisigParams, esdtParams...) txData := strings.Join(params, "@") - integrationTests.CreateAndSendTransaction(nodes[ownerIdx], nodes, big.NewInt(0), multisignContractAddress, txData, 100000) + integrationTests.CreateAndSendTransaction(nodes[ownerIdx], nodes, big.NewInt(0), multisignContractAddress, txData, 1000000) } From 0157cb9157d612632e43b5ef620d73f682dc0fdb Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 25 Apr 2024 14:39:08 +0300 Subject: [PATCH 205/503] fixing more and more tests --- .../vm/txsFee/apiTransactionEvaluator_test.go | 3 ++- .../vm/txsFee/asyncCall_multi_test.go | 17 +++++------------ integrationTests/vm/txsFee/asyncESDT_test.go | 4 ++-- .../vm/txsFee/builtInFunctions_test.go | 10 +++++----- integrationTests/vm/txsFee/dns_test.go | 6 +++--- .../vm/txsFee/multiShard/scCalls_test.go | 15 ++++++--------- .../vm/txsFee/relayedAsyncESDT_test.go | 4 ++-- .../vm/txsFee/relayedBuiltInFunctions_test.go | 10 +++++----- .../vm/txsFee/relayedScCalls_test.go | 10 +++++----- integrationTests/vm/txsFee/scCalls_test.go | 2 +- 10 files changed, 36 insertions(+), 45 deletions(-) diff --git a/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go b/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go index 57ecec2bd7a..ac926d5849b 100644 --- a/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go +++ b/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go @@ -194,5 +194,6 @@ func TestAsyncESDTTransfer(t *testing.T) { res, err := testContext.TxCostHandler.ComputeTransactionGasLimit(tx) require.Nil(t, err) - require.Equal(t, uint64(34157), res.GasUnits) + fmt.Println(res.GasUnits) + require.Equal(t, uint64(177653), res.GasUnits) } diff --git a/integrationTests/vm/txsFee/asyncCall_multi_test.go b/integrationTests/vm/txsFee/asyncCall_multi_test.go index 61886be4da3..24cf1f14750 100644 --- a/integrationTests/vm/txsFee/asyncCall_multi_test.go +++ b/integrationTests/vm/txsFee/asyncCall_multi_test.go @@ -7,7 +7,6 @@ import ( "github.com/multiversx/mx-chain-core-go/data/scheduled" "github.com/multiversx/mx-chain-go/config" - "github.com/multiversx/mx-chain-go/integrationTests" "github.com/multiversx/mx-chain-go/integrationTests/vm" "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" "github.com/multiversx/mx-chain-go/state" @@ -480,21 +479,15 @@ func TestAsyncCallTransferESDTAndExecute_CrossShard_Success(t *testing.T) { } func transferESDTAndExecuteCrossShard(t *testing.T, numberOfCallsFromParent int, numberOfBackTransfers int) { - vaultShard, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{ - DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, - }) + vaultShard, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) require.Nil(t, err) defer vaultShard.Close() - forwarderShard, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ - DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, - }) + forwarderShard, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) require.Nil(t, err) defer forwarderShard.Close() - testContextSender, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{ - DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, - }) + testContextSender, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{}) require.Nil(t, err) defer testContextSender.Close() @@ -539,7 +532,7 @@ func transferESDTAndExecuteCrossShard(t *testing.T, numberOfCallsFromParent int, Clear(). Func("add_queued_call_transfer_esdt"). Bytes(vaultSCAddress). - Int64(50000). + Int64(500000). Bytes([]byte("retrieve_funds_promises")). Bytes(esdtToken). Int64(esdtToTransferFromParent). @@ -558,7 +551,7 @@ func transferESDTAndExecuteCrossShard(t *testing.T, numberOfCallsFromParent int, Clear(). Func("forward_queued_calls") - gasLimit = uint64(50000000) + gasLimit = uint64(100000000) sendTx(nonce, senderAddr, forwarderSCAddress, gasPrice, gasLimit, txBuilderRunQueue, forwarderShard, t) intermediateTxs := forwarderShard.GetIntermediateTransactions(t) diff --git a/integrationTests/vm/txsFee/asyncESDT_test.go b/integrationTests/vm/txsFee/asyncESDT_test.go index 289926f96db..4476a79511d 100644 --- a/integrationTests/vm/txsFee/asyncESDT_test.go +++ b/integrationTests/vm/txsFee/asyncESDT_test.go @@ -70,10 +70,10 @@ func TestAsyncESDTCallShouldWork(t *testing.T) { utils.CheckESDTBalance(t, testContext, firstSCAddress, token, big.NewInt(2500)) utils.CheckESDTBalance(t, testContext, secondSCAddress, token, big.NewInt(2500)) - expectedSenderBalance := big.NewInt(95000000) + expectedSenderBalance := big.NewInt(98223470) utils.TestAccount(t, testContext.Accounts, sndAddr, 1, expectedSenderBalance) - expectedAccumulatedFees := big.NewInt(5000000) + expectedAccumulatedFees := big.NewInt(1776530) accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() require.Equal(t, expectedAccumulatedFees, accumulatedFees) } diff --git a/integrationTests/vm/txsFee/builtInFunctions_test.go b/integrationTests/vm/txsFee/builtInFunctions_test.go index 5f0ae16ebc3..4ac02c62661 100644 --- a/integrationTests/vm/txsFee/builtInFunctions_test.go +++ b/integrationTests/vm/txsFee/builtInFunctions_test.go @@ -54,7 +54,7 @@ func TestBuildInFunctionChangeOwnerCallShouldWorkV1(t *testing.T) { utils.CheckOwnerAddr(t, testContext, scAddress, newOwner) - expectedBalance := big.NewInt(87250) + expectedBalance := big.NewInt(9987250) vm.TestAccount(t, testContext.Accounts, owner, 2, expectedBalance) // check accumulated fees @@ -95,7 +95,7 @@ func TestBuildInFunctionChangeOwnerCallShouldWork(t *testing.T) { utils.CheckOwnerAddr(t, testContext, scAddress, newOwner) - expectedBalance := big.NewInt(78100) + expectedBalance := big.NewInt(9978100) vm.TestAccount(t, testContext.Accounts, owner, 2, expectedBalance) // check accumulated fees @@ -174,7 +174,7 @@ func TestBuildInFunctionChangeOwnerInvalidAddressShouldConsumeGas(t *testing.T) utils.CheckOwnerAddr(t, testContext, scAddress, owner) - expectedBalance := big.NewInt(78100) + expectedBalance := big.NewInt(9978100) vm.TestAccount(t, testContext.Accounts, owner, 2, expectedBalance) // check accumulated fees @@ -214,7 +214,7 @@ func TestBuildInFunctionChangeOwnerCallInsufficientGasLimitShouldNotConsumeGas(t utils.CheckOwnerAddr(t, testContext, scAddress, owner) - expectedBalance := big.NewInt(99070) + expectedBalance := big.NewInt(9999070) vm.TestAccount(t, testContext.Accounts, owner, 2, expectedBalance) // check accumulated fees @@ -253,7 +253,7 @@ func TestBuildInFunctionChangeOwnerOutOfGasShouldConsumeGas(t *testing.T) { utils.CheckOwnerAddr(t, testContext, scAddress, owner) - expectedBalance := big.NewInt(87260) + expectedBalance := big.NewInt(9987260) vm.TestAccount(t, testContext.Accounts, owner, 2, expectedBalance) // check accumulated fees diff --git a/integrationTests/vm/txsFee/dns_test.go b/integrationTests/vm/txsFee/dns_test.go index a859341d1d4..f191a8ddcd3 100644 --- a/integrationTests/vm/txsFee/dns_test.go +++ b/integrationTests/vm/txsFee/dns_test.go @@ -56,13 +56,13 @@ func TestDeployDNSContract_TestRegisterAndResolveAndSendTxWithSndAndRcvUserName( require.Equal(t, vmcommon.Ok, retCode) require.Nil(t, err) - vm.TestAccount(t, testContext.Accounts, sndAddr, 1, big.NewInt(9721810)) + vm.TestAccount(t, testContext.Accounts, sndAddr, 1, big.NewInt(9263230)) // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(278190), accumulatedFees) + require.Equal(t, big.NewInt(736770), accumulatedFees) developerFees := testContext.TxFeeHandler.GetDeveloperFees() - require.Equal(t, big.NewInt(27775), developerFees) + require.Equal(t, big.NewInt(73677), developerFees) utils.CleanAccumulatedIntermediateTransactions(t, testContext) diff --git a/integrationTests/vm/txsFee/multiShard/scCalls_test.go b/integrationTests/vm/txsFee/multiShard/scCalls_test.go index f8f652efe7b..34aa049c7c4 100644 --- a/integrationTests/vm/txsFee/multiShard/scCalls_test.go +++ b/integrationTests/vm/txsFee/multiShard/scCalls_test.go @@ -5,7 +5,6 @@ import ( "testing" "github.com/multiversx/mx-chain-go/config" - "github.com/multiversx/mx-chain-go/integrationTests" "github.com/multiversx/mx-chain-go/integrationTests/vm" "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" vmcommon "github.com/multiversx/mx-chain-vm-common-go" @@ -17,9 +16,7 @@ func TestScCallExecuteOnSourceAndDstShardShouldWork(t *testing.T) { t.Skip("this is not a short test") } - enableEpochs := config.EnableEpochs{ - DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, - } + enableEpochs := config.EnableEpochs{} testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, enableEpochs) require.Nil(t, err) @@ -44,7 +41,7 @@ func TestScCallExecuteOnSourceAndDstShardShouldWork(t *testing.T) { gasPrice := uint64(10) gasLimit := uint64(50000) - _, _ = vm.CreateAccount(testContextSource.Accounts, sndAddr, 0, big.NewInt(10000)) + _, _ = vm.CreateAccount(testContextSource.Accounts, sndAddr, 0, big.NewInt(10000000)) tx := vm.CreateTransaction(0, big.NewInt(0), sndAddr, scAddr, gasPrice, gasLimit, []byte("increment")) @@ -56,7 +53,7 @@ func TestScCallExecuteOnSourceAndDstShardShouldWork(t *testing.T) { _, err = testContextSource.Accounts.Commit() require.Nil(t, err) - expectedBalance := big.NewInt(5000) + expectedBalance := big.NewInt(9500000) vm.TestAccount(t, testContextSource.Accounts, sndAddr, 1, expectedBalance) // check accumulated fees @@ -76,10 +73,10 @@ func TestScCallExecuteOnSourceAndDstShardShouldWork(t *testing.T) { // check accumulated fees dest accumulatedFees = testContextDst.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(3770), accumulatedFees) + require.Equal(t, big.NewInt(156630), accumulatedFees) developerFees = testContextDst.TxFeeHandler.GetDeveloperFees() - require.Equal(t, big.NewInt(377), developerFees) + require.Equal(t, big.NewInt(15663), developerFees) // execute sc result with gas refund txs := testContextDst.GetIntermediateTransactions(t) @@ -88,7 +85,7 @@ func TestScCallExecuteOnSourceAndDstShardShouldWork(t *testing.T) { utils.ProcessSCRResult(t, testContextSource, scr, vmcommon.Ok, nil) // check sender balance after refund - expectedBalance = big.NewInt(6130) + expectedBalance = big.NewInt(9843270) vm.TestAccount(t, testContextSource.Accounts, sndAddr, 1, expectedBalance) // check accumulated fees diff --git a/integrationTests/vm/txsFee/relayedAsyncESDT_test.go b/integrationTests/vm/txsFee/relayedAsyncESDT_test.go index 5e3ca24d999..204f8e4b885 100644 --- a/integrationTests/vm/txsFee/relayedAsyncESDT_test.go +++ b/integrationTests/vm/txsFee/relayedAsyncESDT_test.go @@ -69,10 +69,10 @@ func TestRelayedAsyncESDTCallShouldWork(t *testing.T) { utils.CheckESDTBalance(t, testContext, firstSCAddress, token, big.NewInt(2500)) utils.CheckESDTBalance(t, testContext, secondSCAddress, token, big.NewInt(2500)) - expectedSenderBalance := big.NewInt(94996430) + expectedSenderBalance := big.NewInt(98219900) utils.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedSenderBalance) - expectedAccumulatedFees := big.NewInt(5003570) + expectedAccumulatedFees := big.NewInt(1780100) accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() require.Equal(t, expectedAccumulatedFees, accumulatedFees) } diff --git a/integrationTests/vm/txsFee/relayedBuiltInFunctions_test.go b/integrationTests/vm/txsFee/relayedBuiltInFunctions_test.go index 115dc545244..93396ce5deb 100644 --- a/integrationTests/vm/txsFee/relayedBuiltInFunctions_test.go +++ b/integrationTests/vm/txsFee/relayedBuiltInFunctions_test.go @@ -56,7 +56,7 @@ func TestRelayedBuildInFunctionChangeOwnerCallShouldWork(t *testing.T) { expectedBalanceRelayer := big.NewInt(16610) vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) - expectedBalance := big.NewInt(88100) + expectedBalance := big.NewInt(9988100) vm.TestAccount(t, testContext.Accounts, owner, 2, expectedBalance) // check accumulated fees @@ -106,7 +106,7 @@ func TestRelayedBuildInFunctionChangeOwnerCallWrongOwnerShouldConsumeGas(t *test expectedBalanceRelayer := big.NewInt(16610) vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) - expectedBalance := big.NewInt(88100) + expectedBalance := big.NewInt(9988100) vm.TestAccount(t, testContext.Accounts, owner, 1, expectedBalance) // check accumulated fees @@ -154,7 +154,7 @@ func TestRelayedBuildInFunctionChangeOwnerInvalidAddressShouldConsumeGas(t *test expectedBalanceRelayer := big.NewInt(17330) vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) - expectedBalance := big.NewInt(88100) + expectedBalance := big.NewInt(9988100) vm.TestAccount(t, testContext.Accounts, owner, 2, expectedBalance) // check accumulated fees @@ -220,7 +220,7 @@ func testRelayedBuildInFunctionChangeOwnerCallInsufficientGasLimitShouldConsumeG expectedBalanceRelayer := big.NewInt(25810) vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) - expectedBalance := big.NewInt(88100) + expectedBalance := big.NewInt(9988100) vm.TestAccount(t, testContext.Accounts, owner, 2, expectedBalance) // check accumulated fees @@ -268,7 +268,7 @@ func TestRelayedBuildInFunctionChangeOwnerCallOutOfGasShouldConsumeGas(t *testin expectedBalanceRelayer := big.NewInt(25790) vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) - expectedBalance := big.NewInt(88100) + expectedBalance := big.NewInt(9988100) vm.TestAccount(t, testContext.Accounts, owner, 2, expectedBalance) // check accumulated fees diff --git a/integrationTests/vm/txsFee/relayedScCalls_test.go b/integrationTests/vm/txsFee/relayedScCalls_test.go index 36febda356e..7441d55541f 100644 --- a/integrationTests/vm/txsFee/relayedScCalls_test.go +++ b/integrationTests/vm/txsFee/relayedScCalls_test.go @@ -30,10 +30,10 @@ func TestRelayedScCallShouldWork(t *testing.T) { relayerAddr := []byte("12345678901234567890123456789033") sndAddr := []byte("12345678901234567890123456789112") - gasLimit := uint64(1000) + gasLimit := uint64(100000) _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, big.NewInt(0)) - _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(30000)) + _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(30000000)) userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, scAddress, gasPrice, gasLimit, []byte("increment")) @@ -51,15 +51,15 @@ func TestRelayedScCallShouldWork(t *testing.T) { ret := vm.GetIntValueFromSC(nil, testContext.Accounts, scAddress, "get") require.Equal(t, big.NewInt(2), ret) - expectedBalance := big.NewInt(23850) + expectedBalance := big.NewInt(29840970) vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalance) // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(17950), accumulatedFees) + require.Equal(t, big.NewInt(170830), accumulatedFees) developerFees := testContext.TxFeeHandler.GetDeveloperFees() - require.Equal(t, big.NewInt(807), developerFees) + require.Equal(t, big.NewInt(16093), developerFees) } func TestRelayedScCallContractNotFoundShouldConsumeGas(t *testing.T) { diff --git a/integrationTests/vm/txsFee/scCalls_test.go b/integrationTests/vm/txsFee/scCalls_test.go index 4a499c3b095..0c2262a9362 100644 --- a/integrationTests/vm/txsFee/scCalls_test.go +++ b/integrationTests/vm/txsFee/scCalls_test.go @@ -296,7 +296,7 @@ func TestScCallAndGasChangeShouldWork(t *testing.T) { sndAddr := []byte("12345678901234567890123456789112") senderBalance := big.NewInt(10000000) - gasLimit := uint64(1000) + gasLimit := uint64(100000) _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, senderBalance) numIterations := uint64(10) From e26260c87eb8fd324f3dc5f6318c62d35da686c8 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 25 Apr 2024 15:05:54 +0300 Subject: [PATCH 206/503] fixing more and more tests --- integrationTests/vm/txsFee/dns_test.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/integrationTests/vm/txsFee/dns_test.go b/integrationTests/vm/txsFee/dns_test.go index f191a8ddcd3..0ff3914d7a0 100644 --- a/integrationTests/vm/txsFee/dns_test.go +++ b/integrationTests/vm/txsFee/dns_test.go @@ -62,7 +62,7 @@ func TestDeployDNSContract_TestRegisterAndResolveAndSendTxWithSndAndRcvUserName( require.Equal(t, big.NewInt(736770), accumulatedFees) developerFees := testContext.TxFeeHandler.GetDeveloperFees() - require.Equal(t, big.NewInt(73677), developerFees) + require.Equal(t, big.NewInt(73633), developerFees) utils.CleanAccumulatedIntermediateTransactions(t, testContext) @@ -77,13 +77,13 @@ func TestDeployDNSContract_TestRegisterAndResolveAndSendTxWithSndAndRcvUserName( _, err = testContext.Accounts.Commit() require.Nil(t, err) - vm.TestAccount(t, testContext.Accounts, rcvAddr, 1, big.NewInt(9721810)) + vm.TestAccount(t, testContext.Accounts, rcvAddr, 1, big.NewInt(9263230)) // check accumulated fees accumulatedFees = testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(556380), accumulatedFees) + require.Equal(t, big.NewInt(1473540), accumulatedFees) developerFees = testContext.TxFeeHandler.GetDeveloperFees() - require.Equal(t, big.NewInt(55550), developerFees) + require.Equal(t, big.NewInt(147266), developerFees) ret := vm.GetVmOutput(nil, testContext.Accounts, scAddress, "resolve", userName) dnsUserNameAddr := ret.ReturnData[0] @@ -200,15 +200,11 @@ func TestDeployDNSContract_TestGasWhenSaveUsernameAfterDNSv2IsActivated(t *testi t.Skip("this is not a short test") } - testContextForDNSContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ - DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, - }) + testContextForDNSContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) require.Nil(t, err) defer testContextForDNSContract.Close() - testContextForRelayerAndUser, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{ - DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, - }) + testContextForRelayerAndUser, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{}) require.Nil(t, err) defer testContextForRelayerAndUser.Close() scAddress, _ := utils.DoDeployDNS(t, testContextForDNSContract, "../../multiShard/smartContract/dns/dns.wasm") @@ -274,7 +270,7 @@ func processRegisterThroughRelayedTxs(tb testing.TB, args argsProcessRegister) ( // generate the user transaction userTxData := []byte("register@" + hex.EncodeToString(args.username)) - userTxGasLimit := uint64(200000) + userTxGasLimit := uint64(2000000) userTx := vm.CreateTransaction( getNonce(args.testContextForRelayerAndUser, args.userAddress), big.NewInt(0), From 66e5d41623ac62825d0ce9858989c3e36472f266 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Thu, 25 Apr 2024 18:34:19 +0300 Subject: [PATCH 207/503] - fixed a chain simulator test --- node/chainSimulator/chainSimulator_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index 23bbb007f8b..8b32a8655e3 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -9,6 +9,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core" coreAPI "github.com/multiversx/mx-chain-core-go/data/api" "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" @@ -72,6 +73,12 @@ func TestChainSimulator_GenerateBlocksShouldWork(t *testing.T) { InitialRound: 200000000, InitialEpoch: 100, InitialNonce: 100, + AlterConfigsFunction: func(cfg *config.Configs) { + // we need to enable this as this test skips a lot of epoch activations events, and it will fail otherwise + // because the owner of a BLS key coming from genesis is not set + // (the owner is not set at genesis anymore because we do not enable the staking v2 in that phase) + cfg.EpochConfig.EnableEpochs.StakingV2EnableEpoch = 0 + }, }) require.Nil(t, err) require.NotNil(t, chainSimulator) From b7e2c6064fad3db946538e735709c02b8f733249 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Fri, 26 Apr 2024 17:09:33 +0300 Subject: [PATCH 208/503] new configurable parameters in chain simulator --- .../chainSimulator/staking/jail/jail_test.go | 50 +- .../staking/stake/simpleStake_test.go | 43 +- .../staking/stake/stakeAndUnStake_test.go | 807 ++++++++++-------- .../stakingProvider/delegation_test.go | 535 ++++++------ .../stakingProviderWithNodesinQueue_test.go | 31 +- node/chainSimulator/chainSimulator.go | 109 +-- node/chainSimulator/chainSimulator_test.go | 153 ++-- .../components/coreComponents.go | 36 +- .../components/testOnlyProcessingNode.go | 57 +- .../components/testOnlyProcessingNode_test.go | 19 +- node/chainSimulator/configs/configs.go | 46 +- node/chainSimulator/configs/configs_test.go | 17 +- 12 files changed, 1027 insertions(+), 876 deletions(-) diff --git a/integrationTests/chainSimulator/staking/jail/jail_test.go b/integrationTests/chainSimulator/staking/jail/jail_test.go index 496db236d2c..b92625f0f87 100644 --- a/integrationTests/chainSimulator/staking/jail/jail_test.go +++ b/integrationTests/chainSimulator/staking/jail/jail_test.go @@ -3,13 +3,10 @@ package jail import ( "encoding/hex" "fmt" - "math/big" "testing" "time" - "github.com/multiversx/mx-chain-core-go/core" - "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" @@ -17,6 +14,9 @@ import ( "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/vm" + + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/stretchr/testify/require" ) @@ -66,16 +66,18 @@ func testChainSimulatorJailAndUnJail(t *testing.T, targetEpoch int32, nodeStatus numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 2, - MetaChainMinNodes: 2, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 2, + MetaChainMinNodes: 2, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, AlterConfigsFunction: func(cfg *config.Configs) { configs.SetStakingV4ActivationEpochs(cfg, stakingV4JailUnJailStep1EnableEpoch) newNumNodes := cfg.SystemSCConfig.StakingSystemSCConfig.MaxNumberOfNodesForStake + 8 // 8 nodes until new nodes will be placed on queue @@ -166,16 +168,18 @@ func TestChainSimulator_FromQueueToAuctionList(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, AlterConfigsFunction: func(cfg *config.Configs) { configs.SetStakingV4ActivationEpochs(cfg, stakingV4JailUnJailStep1EnableEpoch) configs.SetQuickJailRatingConfig(cfg) diff --git a/integrationTests/chainSimulator/staking/stake/simpleStake_test.go b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go index a4f63e44f28..ca4076d02fb 100644 --- a/integrationTests/chainSimulator/staking/stake/simpleStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go @@ -7,8 +7,6 @@ import ( "testing" "time" - "github.com/multiversx/mx-chain-core-go/core" - "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" @@ -17,6 +15,9 @@ import ( "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/vm" + + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/stretchr/testify/require" ) @@ -64,18 +65,20 @@ func testChainSimulatorSimpleStake(t *testing.T, targetEpoch int32, nodesStatus numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { configs.SetStakingV4ActivationEpochs(cfg, 2) }, @@ -167,11 +170,13 @@ func TestChainSimulator_StakingV4Step2APICalls(t *testing.T) { HasValue: true, Value: 30, }, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 4, - MetaChainMinNodes: 4, - NumNodesWaitingListMeta: 4, - NumNodesWaitingListShard: 4, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 4, + MetaChainMinNodes: 4, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 4, + NumNodesWaitingListShard: 4, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = stakingV4Step1Epoch cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = stakingV4Step2Epoch diff --git a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index 2b2246df713..936bac46759 100644 --- a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go @@ -7,10 +7,6 @@ import ( "testing" "time" - "github.com/multiversx/mx-chain-core-go/core" - coreAPI "github.com/multiversx/mx-chain-core-go/data/api" - "github.com/multiversx/mx-chain-core-go/data/transaction" - "github.com/multiversx/mx-chain-core-go/data/validator" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" @@ -22,6 +18,11 @@ import ( chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/vm" + + "github.com/multiversx/mx-chain-core-go/core" + coreAPI "github.com/multiversx/mx-chain-core-go/data/api" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-core-go/data/validator" logger "github.com/multiversx/mx-chain-logger-go" "github.com/stretchr/testify/require" ) @@ -55,18 +56,20 @@ func TestChainSimulator_AddValidatorKey(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, AlterConfigsFunction: func(cfg *config.Configs) { newNumNodes := cfg.SystemSCConfig.StakingSystemSCConfig.MaxNumberOfNodesForStake + 8 // 8 nodes until new nodes will be placed on queue configs.SetMaxNumberOfNodesInConfigs(cfg, uint32(newNumNodes), 0, numOfShards) @@ -187,16 +190,18 @@ func TestChainSimulator_AddANewValidatorAfterStakingV4(t *testing.T) { } numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 100, - MetaChainMinNodes: 100, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 100, + MetaChainMinNodes: 100, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, AlterConfigsFunction: func(cfg *config.Configs) { cfg.SystemSCConfig.StakingSystemSCConfig.NodeLimitPercentage = 1 cfg.GeneralConfig.ValidatorStatistics.CacheRefreshIntervalInSec = 1 @@ -316,16 +321,18 @@ func testStakeUnStakeUnBond(t *testing.T, targetEpoch int32) { } numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, AlterConfigsFunction: func(cfg *config.Configs) { cfg.SystemSCConfig.StakingSystemSCConfig.UnBondPeriod = 1 cfg.SystemSCConfig.StakingSystemSCConfig.UnBondPeriodInEpochs = 1 @@ -444,18 +451,20 @@ func TestChainSimulator_DirectStakingNodes_StakeFunds(t *testing.T) { t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 @@ -474,18 +483,20 @@ func TestChainSimulator_DirectStakingNodes_StakeFunds(t *testing.T) { t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -504,18 +515,20 @@ func TestChainSimulator_DirectStakingNodes_StakeFunds(t *testing.T) { t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -534,18 +547,20 @@ func TestChainSimulator_DirectStakingNodes_StakeFunds(t *testing.T) { t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -666,18 +681,20 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation(t *testi t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 @@ -697,18 +714,20 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation(t *testi t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 @@ -729,18 +748,20 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation(t *testi t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 @@ -761,18 +782,20 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation(t *testi t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 @@ -947,18 +970,20 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation_WithReac t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 @@ -978,18 +1003,20 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation_WithReac t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 @@ -1010,18 +1037,20 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation_WithReac t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 @@ -1042,18 +1071,20 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation_WithReac t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 @@ -1184,18 +1215,20 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedFundsBeforeUnbonding( t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 @@ -1214,18 +1247,20 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedFundsBeforeUnbonding( t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1244,18 +1279,20 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedFundsBeforeUnbonding( t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1274,18 +1311,20 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedFundsBeforeUnbonding( t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1418,18 +1457,20 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInWithdrawEpoch(t *te t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 @@ -1448,18 +1489,20 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInWithdrawEpoch(t *te t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1478,18 +1521,20 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInWithdrawEpoch(t *te t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1508,18 +1553,20 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInWithdrawEpoch(t *te t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1681,18 +1728,20 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInBatches(t *testing. t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 @@ -1713,18 +1762,20 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInBatches(t *testing. t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1745,18 +1796,20 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInBatches(t *testing. t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1777,18 +1830,20 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInBatches(t *testing. t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -2037,18 +2092,20 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInEpoch(t *testing.T) t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 @@ -2069,18 +2126,20 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInEpoch(t *testing.T) t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -2101,18 +2160,20 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInEpoch(t *testing.T) t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -2133,18 +2194,20 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInEpoch(t *testing.T) t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 diff --git a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index 653ab74f031..6631c23330f 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go @@ -9,13 +9,6 @@ import ( "testing" "time" - "github.com/multiversx/mx-chain-core-go/core" - "github.com/multiversx/mx-chain-core-go/data/transaction" - "github.com/multiversx/mx-chain-core-go/data/validator" - dataVm "github.com/multiversx/mx-chain-core-go/data/vm" - "github.com/multiversx/mx-chain-crypto-go/signing" - "github.com/multiversx/mx-chain-crypto-go/signing/mcl" - mclsig "github.com/multiversx/mx-chain-crypto-go/signing/mcl/singlesig" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" @@ -26,6 +19,14 @@ import ( chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/vm" + + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-core-go/data/validator" + dataVm "github.com/multiversx/mx-chain-core-go/data/vm" + "github.com/multiversx/mx-chain-crypto-go/signing" + "github.com/multiversx/mx-chain-crypto-go/signing/mcl" + mclsig "github.com/multiversx/mx-chain-crypto-go/signing/mcl/singlesig" logger "github.com/multiversx/mx-chain-logger-go" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -70,18 +71,20 @@ func TestChainSimulator_MakeNewContractFromValidatorData(t *testing.T) { // 6. Execute 2 unDelegate operations of 100 EGLD each, check the topup is back to 500 t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 @@ -107,18 +110,20 @@ func TestChainSimulator_MakeNewContractFromValidatorData(t *testing.T) { // 6. Execute 2 unDelegate operations of 100 EGLD each, check the topup is back to 500 t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -144,18 +149,20 @@ func TestChainSimulator_MakeNewContractFromValidatorData(t *testing.T) { // 6. Execute 2 unDelegate operations of 100 EGLD each, check the topup is back to 500 t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -181,18 +188,20 @@ func TestChainSimulator_MakeNewContractFromValidatorData(t *testing.T) { // 6. Execute 2 unDelegate operations of 100 EGLD each, check the topup is back to 500 t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -424,18 +433,20 @@ func TestChainSimulator_MakeNewContractFromValidatorDataWith2StakingContracts(t t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 @@ -453,18 +464,20 @@ func TestChainSimulator_MakeNewContractFromValidatorDataWith2StakingContracts(t }) t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -482,18 +495,20 @@ func TestChainSimulator_MakeNewContractFromValidatorDataWith2StakingContracts(t }) t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -511,18 +526,20 @@ func TestChainSimulator_MakeNewContractFromValidatorDataWith2StakingContracts(t }) t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -649,18 +666,20 @@ func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 @@ -680,18 +699,20 @@ func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta }) t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 @@ -712,18 +733,20 @@ func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta }) t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 @@ -744,18 +767,20 @@ func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta }) t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 @@ -969,18 +994,20 @@ func TestChainSimulator_CreateNewDelegationContract(t *testing.T) { // 6. Check the node is unstaked in the next epoch t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 @@ -1008,18 +1035,20 @@ func TestChainSimulator_CreateNewDelegationContract(t *testing.T) { // 6. Check the node is unstaked in the next epoch t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1047,18 +1076,20 @@ func TestChainSimulator_CreateNewDelegationContract(t *testing.T) { // 6. Check the node is unstaked in the next epoch t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1086,18 +1117,20 @@ func TestChainSimulator_CreateNewDelegationContract(t *testing.T) { // 6. Check the node is unstaked in the next epoch t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1418,18 +1451,20 @@ func TestChainSimulator_MergeDelegation(t *testing.T) { t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 @@ -1449,18 +1484,20 @@ func TestChainSimulator_MergeDelegation(t *testing.T) { t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 @@ -1481,18 +1518,20 @@ func TestChainSimulator_MergeDelegation(t *testing.T) { t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 @@ -1513,18 +1552,20 @@ func TestChainSimulator_MergeDelegation(t *testing.T) { t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 diff --git a/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go b/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go index 99cc7a66518..649f807e6ce 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go @@ -7,14 +7,15 @@ import ( "testing" "time" - "github.com/multiversx/mx-chain-core-go/core" - "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/vm" + + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/stretchr/testify/require" ) @@ -50,18 +51,20 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati } cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { configs.SetStakingV4ActivationEpochs(cfg, stakingV4ActivationEpoch) }, diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index 8bffcb6c63a..98ad37b6a42 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -10,6 +10,13 @@ import ( "sync" "time" + "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/node/chainSimulator/components" + "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" + "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" + "github.com/multiversx/mx-chain-go/node/chainSimulator/process" + mxChainSharding "github.com/multiversx/mx-chain-go/sharding" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/core/sharding" @@ -19,12 +26,6 @@ import ( crypto "github.com/multiversx/mx-chain-crypto-go" "github.com/multiversx/mx-chain-crypto-go/signing" "github.com/multiversx/mx-chain-crypto-go/signing/mcl" - "github.com/multiversx/mx-chain-go/config" - "github.com/multiversx/mx-chain-go/node/chainSimulator/components" - "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" - "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" - "github.com/multiversx/mx-chain-go/node/chainSimulator/process" - mxChainSharding "github.com/multiversx/mx-chain-go/sharding" logger "github.com/multiversx/mx-chain-logger-go" ) @@ -40,22 +41,24 @@ type transactionWithResult struct { // ArgsChainSimulator holds the arguments needed to create a new instance of simulator type ArgsChainSimulator struct { - BypassTxSignatureCheck bool - TempDir string - PathToInitialConfig string - NumOfShards uint32 - MinNodesPerShard uint32 - MetaChainMinNodes uint32 - NumNodesWaitingListShard uint32 - NumNodesWaitingListMeta uint32 - GenesisTimestamp int64 - InitialRound int64 - InitialEpoch uint32 - InitialNonce uint64 - RoundDurationInMillis uint64 - RoundsPerEpoch core.OptionalUint64 - ApiInterface components.APIConfigurator - AlterConfigsFunction func(cfg *config.Configs) + BypassTxSignatureCheck bool + TempDir string + PathToInitialConfig string + NumOfShards uint32 + MinNodesPerShard uint32 + ConsensusGroupSize uint32 + MetaChainMinNodes uint32 + MetaChainConsensusGroupSize uint32 + NumNodesWaitingListShard uint32 + NumNodesWaitingListMeta uint32 + GenesisTimestamp int64 + InitialRound int64 + InitialEpoch uint32 + InitialNonce uint64 + RoundDurationInMillis uint64 + RoundsPerEpoch core.OptionalUint64 + ApiInterface components.APIConfigurator + AlterConfigsFunction func(cfg *config.Configs) } type simulator struct { @@ -72,10 +75,8 @@ type simulator struct { // NewChainSimulator will create a new instance of simulator func NewChainSimulator(args ArgsChainSimulator) (*simulator, error) { - syncedBroadcastNetwork := components.NewSyncedBroadcastNetwork() - instance := &simulator{ - syncedBroadcastNetwork: syncedBroadcastNetwork, + syncedBroadcastNetwork: components.NewSyncedBroadcastNetwork(), nodes: make(map[uint32]process.NodeHandler), handlers: make([]ChainHandler, 0, args.NumOfShards+1), numOfShards: args.NumOfShards, @@ -94,26 +95,28 @@ func NewChainSimulator(args ArgsChainSimulator) (*simulator, error) { func (s *simulator) createChainHandlers(args ArgsChainSimulator) error { outputConfigs, err := configs.CreateChainSimulatorConfigs(configs.ArgsChainSimulatorConfigs{ - NumOfShards: args.NumOfShards, - OriginalConfigsPath: args.PathToInitialConfig, - GenesisTimeStamp: computeStartTimeBaseOnInitialRound(args), - RoundDurationInMillis: args.RoundDurationInMillis, - TempDir: args.TempDir, - MinNodesPerShard: args.MinNodesPerShard, - MetaChainMinNodes: args.MetaChainMinNodes, - RoundsPerEpoch: args.RoundsPerEpoch, - InitialEpoch: args.InitialEpoch, - AlterConfigsFunction: args.AlterConfigsFunction, - NumNodesWaitingListShard: args.NumNodesWaitingListShard, - NumNodesWaitingListMeta: args.NumNodesWaitingListMeta, + NumOfShards: args.NumOfShards, + OriginalConfigsPath: args.PathToInitialConfig, + GenesisTimeStamp: computeStartTimeBaseOnInitialRound(args), + RoundDurationInMillis: args.RoundDurationInMillis, + TempDir: args.TempDir, + MinNodesPerShard: args.MinNodesPerShard, + ConsensusGroupSize: args.ConsensusGroupSize, + MetaChainMinNodes: args.MetaChainMinNodes, + MetaChainConsensusGroupSize: args.MetaChainConsensusGroupSize, + RoundsPerEpoch: args.RoundsPerEpoch, + InitialEpoch: args.InitialEpoch, + AlterConfigsFunction: args.AlterConfigsFunction, + NumNodesWaitingListShard: args.NumNodesWaitingListShard, + NumNodesWaitingListMeta: args.NumNodesWaitingListMeta, }) if err != nil { return err } for idx := 0; idx < int(args.NumOfShards)+1; idx++ { - shardIDStr := fmt.Sprintf("%d", idx-1) - if idx == 0 { + shardIDStr := fmt.Sprintf("%d", idx) + if idx == int(args.NumOfShards) { shardIDStr = "metachain" } @@ -154,19 +157,21 @@ func (s *simulator) createTestNode( outputConfigs configs.ArgsConfigsSimulator, args ArgsChainSimulator, shardIDStr string, ) (process.NodeHandler, error) { argsTestOnlyProcessorNode := components.ArgsTestOnlyProcessingNode{ - Configs: outputConfigs.Configs, - ChanStopNodeProcess: s.chanStopNodeProcess, - SyncedBroadcastNetwork: s.syncedBroadcastNetwork, - NumShards: s.numOfShards, - GasScheduleFilename: outputConfigs.GasScheduleFilename, - ShardIDStr: shardIDStr, - APIInterface: args.ApiInterface, - BypassTxSignatureCheck: args.BypassTxSignatureCheck, - InitialRound: args.InitialRound, - InitialNonce: args.InitialNonce, - MinNodesPerShard: args.MinNodesPerShard, - MinNodesMeta: args.MetaChainMinNodes, - RoundDurationInMillis: args.RoundDurationInMillis, + Configs: outputConfigs.Configs, + ChanStopNodeProcess: s.chanStopNodeProcess, + SyncedBroadcastNetwork: s.syncedBroadcastNetwork, + NumShards: s.numOfShards, + GasScheduleFilename: outputConfigs.GasScheduleFilename, + ShardIDStr: shardIDStr, + APIInterface: args.ApiInterface, + BypassTxSignatureCheck: args.BypassTxSignatureCheck, + InitialRound: args.InitialRound, + InitialNonce: args.InitialNonce, + MinNodesPerShard: args.MinNodesPerShard, + ConsensusGroupSize: args.ConsensusGroupSize, + MinNodesMeta: args.MetaChainMinNodes, + MetaChainConsensusGroupSize: args.MetaChainConsensusGroupSize, + RoundDurationInMillis: args.RoundDurationInMillis, } return components.NewTestOnlyProcessingNode(argsTestOnlyProcessorNode) diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index 1a65b37ff78..11e9fe2355a 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -6,13 +6,14 @@ import ( "testing" "time" - "github.com/multiversx/mx-chain-core-go/core" - coreAPI "github.com/multiversx/mx-chain-core-go/data/api" - "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" "github.com/multiversx/mx-chain-go/process" + + "github.com/multiversx/mx-chain-core-go/core" + coreAPI "github.com/multiversx/mx-chain-core-go/data/api" + "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -29,16 +30,18 @@ func TestNewChainSimulator(t *testing.T) { startTime := time.Now().Unix() roundDurationInMillis := uint64(6000) chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: core.OptionalUint64{}, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 1, - MetaChainMinNodes: 1, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: core.OptionalUint64{}, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 1, + MetaChainMinNodes: 1, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, }) require.Nil(t, err) require.NotNil(t, chainSimulator) @@ -66,12 +69,14 @@ func TestChainSimulator_GenerateBlocksShouldWork(t *testing.T) { HasValue: true, Value: 20, }, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 1, - MetaChainMinNodes: 1, - InitialRound: 200000000, - InitialEpoch: 100, - InitialNonce: 100, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 1, + MetaChainMinNodes: 1, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + InitialRound: 200000000, + InitialEpoch: 100, + InitialNonce: 100, }) require.Nil(t, err) require.NotNil(t, chainSimulator) @@ -96,16 +101,18 @@ func TestChainSimulator_GenerateBlocksAndEpochChangeShouldWork(t *testing.T) { Value: 20, } chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 100, - MetaChainMinNodes: 100, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 100, + MetaChainMinNodes: 100, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, }) require.Nil(t, err) require.NotNil(t, chainSimulator) @@ -153,16 +160,18 @@ func TestChainSimulator_SetState(t *testing.T) { Value: 20, } chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 1, - MetaChainMinNodes: 1, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 1, + MetaChainMinNodes: 1, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, }) require.Nil(t, err) require.NotNil(t, chainSimulator) @@ -199,16 +208,18 @@ func TestChainSimulator_SetEntireState(t *testing.T) { Value: 20, } chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 1, - MetaChainMinNodes: 1, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 1, + MetaChainMinNodes: 1, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, }) require.Nil(t, err) require.NotNil(t, chainSimulator) @@ -276,16 +287,18 @@ func TestChainSimulator_GetAccount(t *testing.T) { Value: 20, } chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 1, - MetaChainMinNodes: 1, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 1, + MetaChainMinNodes: 1, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, }) require.Nil(t, err) require.NotNil(t, chainSimulator) @@ -338,16 +351,18 @@ func TestSimulator_SendTransactions(t *testing.T) { Value: 20, } chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 1, - MetaChainMinNodes: 1, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 1, + MetaChainMinNodes: 1, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, }) require.Nil(t, err) require.NotNil(t, chainSimulator) diff --git a/node/chainSimulator/components/coreComponents.go b/node/chainSimulator/components/coreComponents.go index 08c7105e0ef..49a7269d74b 100644 --- a/node/chainSimulator/components/coreComponents.go +++ b/node/chainSimulator/components/coreComponents.go @@ -5,17 +5,6 @@ import ( "sync" "time" - "github.com/multiversx/mx-chain-core-go/core" - "github.com/multiversx/mx-chain-core-go/core/nodetype" - "github.com/multiversx/mx-chain-core-go/core/versioning" - "github.com/multiversx/mx-chain-core-go/core/watchdog" - "github.com/multiversx/mx-chain-core-go/data/endProcess" - "github.com/multiversx/mx-chain-core-go/data/typeConverters" - "github.com/multiversx/mx-chain-core-go/data/typeConverters/uint64ByteSlice" - "github.com/multiversx/mx-chain-core-go/hashing" - hashingFactory "github.com/multiversx/mx-chain-core-go/hashing/factory" - "github.com/multiversx/mx-chain-core-go/marshal" - marshalFactory "github.com/multiversx/mx-chain-core-go/marshal/factory" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/enablers" factoryPubKey "github.com/multiversx/mx-chain-go/common/factory" @@ -35,6 +24,18 @@ import ( "github.com/multiversx/mx-chain-go/storage" storageFactory "github.com/multiversx/mx-chain-go/storage/factory" "github.com/multiversx/mx-chain-go/testscommon" + + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/core/nodetype" + "github.com/multiversx/mx-chain-core-go/core/versioning" + "github.com/multiversx/mx-chain-core-go/core/watchdog" + "github.com/multiversx/mx-chain-core-go/data/endProcess" + "github.com/multiversx/mx-chain-core-go/data/typeConverters" + "github.com/multiversx/mx-chain-core-go/data/typeConverters/uint64ByteSlice" + "github.com/multiversx/mx-chain-core-go/hashing" + hashingFactory "github.com/multiversx/mx-chain-core-go/hashing/factory" + "github.com/multiversx/mx-chain-core-go/marshal" + marshalFactory "github.com/multiversx/mx-chain-core-go/marshal/factory" ) type coreComponentsHolder struct { @@ -89,9 +90,11 @@ type ArgsCoreComponentsHolder struct { NumShards uint32 WorkingDir string - MinNodesPerShard uint32 - MinNodesMeta uint32 - RoundDurationInMs uint64 + MinNodesPerShard uint32 + ConsensusGroupSize uint32 + MinNodesMeta uint32 + MetaChainConsensusGroupSize uint32 + RoundDurationInMs uint64 } // CreateCoreComponents will create a new instance of factory.CoreComponentsHolder @@ -178,11 +181,10 @@ func CreateCoreComponents(args ArgsCoreComponentsHolder) (*coreComponentsHolder, } instance.apiEconomicsData = instance.economicsData - // TODO fix this min nodes per shard to be configurable instance.ratingsData, err = rating.NewRatingsData(rating.RatingsDataArg{ Config: args.RatingConfig, - ShardConsensusSize: 1, - MetaConsensusSize: 1, + ShardConsensusSize: args.ConsensusGroupSize, + MetaConsensusSize: args.MetaChainConsensusGroupSize, ShardMinNodes: args.MinNodesPerShard, MetaMinNodes: args.MinNodesMeta, RoundDurationMiliseconds: args.RoundDurationInMs, diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index e08f4fc1367..154f7a347f4 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -7,9 +7,6 @@ import ( "fmt" "math/big" - "github.com/multiversx/mx-chain-core-go/core" - chainData "github.com/multiversx/mx-chain-core-go/data" - "github.com/multiversx/mx-chain-core-go/data/endProcess" "github.com/multiversx/mx-chain-go/api/shared" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/consensus" @@ -27,6 +24,10 @@ import ( "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "github.com/multiversx/mx-chain-go/state" + + "github.com/multiversx/mx-chain-core-go/core" + chainData "github.com/multiversx/mx-chain-core-go/data" + "github.com/multiversx/mx-chain-core-go/data/endProcess" ) // ArgsTestOnlyProcessingNode represents the DTO struct for the NewTestOnlyProcessingNode constructor function @@ -37,15 +38,17 @@ type ArgsTestOnlyProcessingNode struct { ChanStopNodeProcess chan endProcess.ArgEndProcess SyncedBroadcastNetwork SyncedBroadcastNetworkHandler - InitialRound int64 - InitialNonce uint64 - GasScheduleFilename string - NumShards uint32 - ShardIDStr string - BypassTxSignatureCheck bool - MinNodesPerShard uint32 - MinNodesMeta uint32 - RoundDurationInMillis uint64 + InitialRound int64 + InitialNonce uint64 + GasScheduleFilename string + NumShards uint32 + ShardIDStr string + BypassTxSignatureCheck bool + MinNodesPerShard uint32 + ConsensusGroupSize uint32 + MinNodesMeta uint32 + MetaChainConsensusGroupSize uint32 + RoundDurationInMillis uint64 } type testOnlyProcessingNode struct { @@ -84,20 +87,22 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces instance.TransactionFeeHandler = postprocess.NewFeeAccumulator() instance.CoreComponentsHolder, err = CreateCoreComponents(ArgsCoreComponentsHolder{ - Config: *args.Configs.GeneralConfig, - EnableEpochsConfig: args.Configs.EpochConfig.EnableEpochs, - RoundsConfig: *args.Configs.RoundConfig, - EconomicsConfig: *args.Configs.EconomicsConfig, - ChanStopNodeProcess: args.ChanStopNodeProcess, - NumShards: args.NumShards, - WorkingDir: args.Configs.FlagsConfig.WorkingDir, - GasScheduleFilename: args.GasScheduleFilename, - NodesSetupPath: args.Configs.ConfigurationPathsHolder.Nodes, - InitialRound: args.InitialRound, - MinNodesPerShard: args.MinNodesPerShard, - MinNodesMeta: args.MinNodesMeta, - RoundDurationInMs: args.RoundDurationInMillis, - RatingConfig: *args.Configs.RatingsConfig, + Config: *args.Configs.GeneralConfig, + EnableEpochsConfig: args.Configs.EpochConfig.EnableEpochs, + RoundsConfig: *args.Configs.RoundConfig, + EconomicsConfig: *args.Configs.EconomicsConfig, + ChanStopNodeProcess: args.ChanStopNodeProcess, + NumShards: args.NumShards, + WorkingDir: args.Configs.FlagsConfig.WorkingDir, + GasScheduleFilename: args.GasScheduleFilename, + NodesSetupPath: args.Configs.ConfigurationPathsHolder.Nodes, + InitialRound: args.InitialRound, + MinNodesPerShard: args.MinNodesPerShard, + ConsensusGroupSize: args.ConsensusGroupSize, + MinNodesMeta: args.MinNodesMeta, + MetaChainConsensusGroupSize: args.MetaChainConsensusGroupSize, + RoundDurationInMs: args.RoundDurationInMillis, + RatingConfig: *args.Configs.RatingsConfig, }) if err != nil { return nil, err diff --git a/node/chainSimulator/components/testOnlyProcessingNode_test.go b/node/chainSimulator/components/testOnlyProcessingNode_test.go index 5924663217b..e66d3fe4a50 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode_test.go +++ b/node/chainSimulator/components/testOnlyProcessingNode_test.go @@ -7,13 +7,14 @@ import ( "testing" "time" - "github.com/multiversx/mx-chain-core-go/data/endProcess" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" "github.com/multiversx/mx-chain-go/testscommon/factory" "github.com/multiversx/mx-chain-go/testscommon/state" + + "github.com/multiversx/mx-chain-core-go/data/endProcess" vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -23,13 +24,15 @@ var expectedErr = errors.New("expected error") func createMockArgsTestOnlyProcessingNode(t *testing.T) ArgsTestOnlyProcessingNode { outputConfigs, err := configs.CreateChainSimulatorConfigs(configs.ArgsChainSimulatorConfigs{ - NumOfShards: 3, - OriginalConfigsPath: "../../../cmd/node/config/", - GenesisTimeStamp: 0, - RoundDurationInMillis: 6000, - TempDir: t.TempDir(), - MinNodesPerShard: 1, - MetaChainMinNodes: 1, + NumOfShards: 3, + OriginalConfigsPath: "../../../cmd/node/config/", + GenesisTimeStamp: 0, + RoundDurationInMillis: 6000, + TempDir: t.TempDir(), + MinNodesPerShard: 1, + MetaChainMinNodes: 1, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, }) require.Nil(t, err) diff --git a/node/chainSimulator/configs/configs.go b/node/chainSimulator/configs/configs.go index 3334f470fa3..6f935f98dfe 100644 --- a/node/chainSimulator/configs/configs.go +++ b/node/chainSimulator/configs/configs.go @@ -11,13 +11,6 @@ import ( "strconv" "strings" - "github.com/multiversx/mx-chain-core-go/core" - "github.com/multiversx/mx-chain-core-go/core/pubkeyConverter" - shardingCore "github.com/multiversx/mx-chain-core-go/core/sharding" - crypto "github.com/multiversx/mx-chain-crypto-go" - "github.com/multiversx/mx-chain-crypto-go/signing" - "github.com/multiversx/mx-chain-crypto-go/signing/ed25519" - "github.com/multiversx/mx-chain-crypto-go/signing/mcl" "github.com/multiversx/mx-chain-go/common/factory" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/genesis/data" @@ -26,6 +19,14 @@ import ( "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/storage/storageunit" "github.com/multiversx/mx-chain-go/testscommon" + + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/core/pubkeyConverter" + shardingCore "github.com/multiversx/mx-chain-core-go/core/sharding" + crypto "github.com/multiversx/mx-chain-crypto-go" + "github.com/multiversx/mx-chain-crypto-go/signing" + "github.com/multiversx/mx-chain-crypto-go/signing/ed25519" + "github.com/multiversx/mx-chain-crypto-go/signing/mcl" ) var oneEgld = big.NewInt(1000000000000000000) @@ -40,18 +41,20 @@ const ( // ArgsChainSimulatorConfigs holds all the components needed to create the chain simulator configs type ArgsChainSimulatorConfigs struct { - NumOfShards uint32 - OriginalConfigsPath string - GenesisTimeStamp int64 - RoundDurationInMillis uint64 - TempDir string - MinNodesPerShard uint32 - MetaChainMinNodes uint32 - InitialEpoch uint32 - RoundsPerEpoch core.OptionalUint64 - NumNodesWaitingListShard uint32 - NumNodesWaitingListMeta uint32 - AlterConfigsFunction func(cfg *config.Configs) + NumOfShards uint32 + OriginalConfigsPath string + GenesisTimeStamp int64 + RoundDurationInMillis uint64 + TempDir string + MinNodesPerShard uint32 + ConsensusGroupSize uint32 + MetaChainMinNodes uint32 + MetaChainConsensusGroupSize uint32 + InitialEpoch uint32 + RoundsPerEpoch core.OptionalUint64 + NumNodesWaitingListShard uint32 + NumNodesWaitingListMeta uint32 + AlterConfigsFunction func(cfg *config.Configs) } // ArgsConfigsSimulator holds the configs for the chain simulator @@ -274,9 +277,8 @@ func generateValidatorsKeyAndUpdateFiles( nodes.RoundDuration = args.RoundDurationInMillis nodes.StartTime = args.GenesisTimeStamp - // TODO fix this to can be configurable - nodes.ConsensusGroupSize = 1 - nodes.MetaChainConsensusGroupSize = 1 + nodes.ConsensusGroupSize = args.ConsensusGroupSize + nodes.MetaChainConsensusGroupSize = args.MetaChainConsensusGroupSize nodes.Hysteresis = 0 nodes.MinNodesPerShard = args.MinNodesPerShard diff --git a/node/chainSimulator/configs/configs_test.go b/node/chainSimulator/configs/configs_test.go index 52da48ecda0..03e464c5f36 100644 --- a/node/chainSimulator/configs/configs_test.go +++ b/node/chainSimulator/configs/configs_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/multiversx/mx-chain-go/integrationTests/realcomponents" + "github.com/stretchr/testify/require" ) @@ -13,13 +14,15 @@ func TestNewProcessorRunnerChainArguments(t *testing.T) { } outputConfig, err := CreateChainSimulatorConfigs(ArgsChainSimulatorConfigs{ - NumOfShards: 3, - OriginalConfigsPath: "../../../cmd/node/config", - RoundDurationInMillis: 6000, - GenesisTimeStamp: 0, - TempDir: t.TempDir(), - MetaChainMinNodes: 1, - MinNodesPerShard: 1, + NumOfShards: 3, + OriginalConfigsPath: "../../../cmd/node/config", + RoundDurationInMillis: 6000, + GenesisTimeStamp: 0, + TempDir: t.TempDir(), + MetaChainMinNodes: 1, + MinNodesPerShard: 1, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, }) require.Nil(t, err) From 82b6666a2547423ddf7e06f2566d68b8b14e0211 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Mon, 29 Apr 2024 13:01:59 +0300 Subject: [PATCH 209/503] fixes after review --- cmd/node/config/enableEpochs.toml | 4 ++-- common/constants.go | 2 +- common/enablers/enableEpochsHandler.go | 6 +++--- common/enablers/enableEpochsHandler_test.go | 4 ++-- config/epochConfig.go | 2 +- config/tomlConfig_test.go | 8 ++++---- factory/api/apiResolverFactory_test.go | 1 - go.mod | 2 +- go.sum | 4 ++-- .../vm/txsFee/apiTransactionEvaluator_test.go | 3 --- process/errors.go | 4 ++-- process/factory/shard/vmContainerFactory.go | 2 +- process/factory/shard/vmContainerFactory_test.go | 2 +- 13 files changed, 20 insertions(+), 24 deletions(-) diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index e1d1b14ddaf..28ac8b1df1c 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -311,8 +311,8 @@ # EGLDInMultiTransferEnableEpoch represents the epoch when EGLD in multitransfer is enabled EGLDInMultiTransferEnableEpoch = 4 - # CryptoAPIV2EnableEpoch represents the epoch when BLSMultiSig, Secp256r1 and other opcodes are enabled - CryptoAPIV2EnableEpoch = 4 + # CryptoOpcodesV2EnableEpoch represents the epoch when BLSMultiSig, Secp256r1 and other opcodes are enabled + CryptoOpcodesV2EnableEpoch = 4 # BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers BLSMultiSignerEnableEpoch = [ diff --git a/common/constants.go b/common/constants.go index 98791f43fd8..ad94a01f954 100644 --- a/common/constants.go +++ b/common/constants.go @@ -1016,6 +1016,6 @@ const ( AlwaysMergeContextsInEEIFlag core.EnableEpochFlag = "AlwaysMergeContextsInEEIFlag" DynamicESDTFlag core.EnableEpochFlag = "DynamicEsdtFlag" EGLDInESDTMultiTransferFlag core.EnableEpochFlag = "EGLDInESDTMultiTransferFlag" - CryptoAPIV2Flag core.EnableEpochFlag = "CryptoAPIV2Flag" + CryptoOpcodesV2Flag core.EnableEpochFlag = "CryptoOpcodesV2Flag" // all new flags must be added to createAllFlagsMap method, as part of enableEpochsHandler allFlagsDefined ) diff --git a/common/enablers/enableEpochsHandler.go b/common/enablers/enableEpochsHandler.go index a6fb12b4128..473085c6d54 100644 --- a/common/enablers/enableEpochsHandler.go +++ b/common/enablers/enableEpochsHandler.go @@ -743,11 +743,11 @@ func (handler *enableEpochsHandler) createAllFlagsMap() { }, activationEpoch: handler.enableEpochsConfig.EGLDInMultiTransferEnableEpoch, }, - common.CryptoAPIV2Flag: { + common.CryptoOpcodesV2Flag: { isActiveInEpoch: func(epoch uint32) bool { - return epoch >= handler.enableEpochsConfig.CryptoAPIV2EnableEpoch + return epoch >= handler.enableEpochsConfig.CryptoOpcodesV2EnableEpoch }, - activationEpoch: handler.enableEpochsConfig.CryptoAPIV2EnableEpoch, + activationEpoch: handler.enableEpochsConfig.CryptoOpcodesV2EnableEpoch, }, } } diff --git a/common/enablers/enableEpochsHandler_test.go b/common/enablers/enableEpochsHandler_test.go index 241ab0e691a..b85078da668 100644 --- a/common/enablers/enableEpochsHandler_test.go +++ b/common/enablers/enableEpochsHandler_test.go @@ -116,7 +116,7 @@ func createEnableEpochsConfig() config.EnableEpochs { AlwaysMergeContextsInEEIEnableEpoch: 100, DynamicESDTEnableEpoch: 101, EGLDInMultiTransferEnableEpoch: 102, - CryptoAPIV2EnableEpoch: 103, + CryptoOpcodesV2EnableEpoch: 103, } } @@ -443,7 +443,7 @@ func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) { require.Equal(t, cfg.AlwaysMergeContextsInEEIEnableEpoch, handler.GetActivationEpoch(common.AlwaysMergeContextsInEEIFlag)) require.Equal(t, cfg.DynamicESDTEnableEpoch, handler.GetActivationEpoch(common.DynamicESDTFlag)) require.Equal(t, cfg.EGLDInMultiTransferEnableEpoch, handler.GetActivationEpoch(common.EGLDInESDTMultiTransferFlag)) - require.Equal(t, cfg.CryptoAPIV2EnableEpoch, handler.GetActivationEpoch(common.CryptoAPIV2Flag)) + require.Equal(t, cfg.CryptoOpcodesV2EnableEpoch, handler.GetActivationEpoch(common.CryptoOpcodesV2Flag)) } func TestEnableEpochsHandler_IsInterfaceNil(t *testing.T) { diff --git a/config/epochConfig.go b/config/epochConfig.go index b29c3205efa..5f5f4ff7a0e 100644 --- a/config/epochConfig.go +++ b/config/epochConfig.go @@ -115,7 +115,7 @@ type EnableEpochs struct { AlwaysMergeContextsInEEIEnableEpoch uint32 DynamicESDTEnableEpoch uint32 EGLDInMultiTransferEnableEpoch uint32 - CryptoAPIV2EnableEpoch uint32 + CryptoOpcodesV2EnableEpoch uint32 BLSMultiSignerEnableEpoch []MultiSignerConfig } diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index 44a160e4582..e3ddcf1bc0c 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -203,7 +203,7 @@ func TestTomlParser(t *testing.T) { { StartEpoch = 12, Version = "v0.3" }, { StartEpoch = 88, Version = "v1.2" }, ] - TransferAndExecuteByUserAddresses = [ # TODO: set real contract addresses + TransferAndExecuteByUserAddresses = [ "erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe0", #shard 0 "erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe1", #shard 1 "erd1qqqqqqqqqqqqqpgqr46jrxr6r2unaqh75ugd308dwx5vgnhwh47qtvepe2", #shard 2 @@ -865,8 +865,8 @@ func TestEnableEpochConfig(t *testing.T) { # EGLDInMultiTransferEnableEpoch represents the epoch when EGLD in MultiTransfer is enabled EGLDInMultiTransferEnableEpoch = 96 - # CryptoAPIV2EnableEpoch represents the epoch when BLSMultiSig, Secp256r1 and other opcodes are enabled - CryptoAPIV2EnableEpoch = 97 + # CryptoOpcodesV2EnableEpoch represents the epoch when BLSMultiSig, Secp256r1 and other opcodes are enabled + CryptoOpcodesV2EnableEpoch = 97 # MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MaxNodesChangeEnableEpoch = [ @@ -982,7 +982,7 @@ func TestEnableEpochConfig(t *testing.T) { AlwaysMergeContextsInEEIEnableEpoch: 94, DynamicESDTEnableEpoch: 95, EGLDInMultiTransferEnableEpoch: 96, - CryptoAPIV2EnableEpoch: 97, + CryptoOpcodesV2EnableEpoch: 97, MaxNodesChangeEnableEpoch: []MaxNodesChangeConfig{ { EpochEnable: 44, diff --git a/factory/api/apiResolverFactory_test.go b/factory/api/apiResolverFactory_test.go index d5ab00af5b5..6f0d1026304 100644 --- a/factory/api/apiResolverFactory_test.go +++ b/factory/api/apiResolverFactory_test.go @@ -186,7 +186,6 @@ func TestCreateApiResolver(t *testing.T) { failingStepsInstance.addressPublicKeyConverterFailingStep = 3 apiResolver, err := api.CreateApiResolver(failingArgs) require.NotNil(t, err) - fmt.Println(err.Error()) require.True(t, strings.Contains(strings.ToLower(err.Error()), "key converter")) require.True(t, check.IfNil(apiResolver)) }) diff --git a/go.mod b/go.mod index 5dbc58a2035..3bdbf023722 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474 github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240424111748-6dfa8aa14813 - github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240424134454-27f4efb28f47 + github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240429094120-31dea4df3221 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240424112443-1a66307bc44e github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240424112610-ab7b9e5829bd github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240424113019-3a7d2b215137 diff --git a/go.sum b/go.sum index 51eb5a714a1..a06d6c94a56 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474 github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474/go.mod h1:hnc6H4D5Ge1haRAQ6QHTXhyh+CT2DRiNJ0U0HQYI3DY= github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240424111748-6dfa8aa14813 h1:pjknvxvRG1fQ6Dc0ZjFkWBwDLfPn2DbtACIwTBwYIA8= github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240424111748-6dfa8aa14813/go.mod h1:G6daPJC6bFsvAw45RPMCRi2rP+8LjFxa8G+3alHuJow= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240424134454-27f4efb28f47 h1:RGW/1czsPJtU10ojsOGWMpWLWENbbL6ruJ7kUZkT0Zo= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240424134454-27f4efb28f47/go.mod h1:DyMusfHXRXyVYQmH2umBTZD5gm6p136EJNC6YI2l+kU= +github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240429094120-31dea4df3221 h1:lTJ26YdhQoANfWSfAX/fyZj6rv0vHcLUyxtZbpQn3nk= +github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240429094120-31dea4df3221/go.mod h1:DyMusfHXRXyVYQmH2umBTZD5gm6p136EJNC6YI2l+kU= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240424112443-1a66307bc44e h1:Yg5Bx9iuMBpe+MTbL+VTdINlQeqjqDFIAOE4A8sWamc= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240424112443-1a66307bc44e/go.mod h1:0hoqSWVXkNvg0iYWDpYQcLyCBwz0DPIrTVf3kAtXHwU= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240424112610-ab7b9e5829bd h1:uM2FFSLvdWT7V8xRCaP01roTINT3rfTXAaiWQ1yFhag= diff --git a/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go b/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go index ac926d5849b..56551737de5 100644 --- a/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go +++ b/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go @@ -2,7 +2,6 @@ package txsFee import ( "encoding/hex" - "fmt" "math/big" "testing" @@ -48,7 +47,6 @@ func TestSCCallCostTransactionCost(t *testing.T) { res, err := testContext.TxCostHandler.ComputeTransactionGasLimit(tx) require.Nil(t, err) - fmt.Println(res.GasUnits) require.Equal(t, uint64(15704), res.GasUnits) } @@ -194,6 +192,5 @@ func TestAsyncESDTTransfer(t *testing.T) { res, err := testContext.TxCostHandler.ComputeTransactionGasLimit(tx) require.Nil(t, err) - fmt.Println(res.GasUnits) require.Equal(t, uint64(177653), res.GasUnits) } diff --git a/process/errors.go b/process/errors.go index 174db37686c..83e8095dcb3 100644 --- a/process/errors.go +++ b/process/errors.go @@ -1227,5 +1227,5 @@ var ErrInvalidAsyncArguments = errors.New("invalid arguments to process async/ca // ErrNilSentSignatureTracker defines the error for setting a nil SentSignatureTracker var ErrNilSentSignatureTracker = errors.New("nil sent signature tracker") -// ErrTransferAndExecuteByUserAddressesIsNil signals that transfer and execute by user addresses are nil -var ErrTransferAndExecuteByUserAddressesIsNil = errors.New("transfer and execute by user addresses are nil") +// ErrTransferAndExecuteByUserAddressesAreNil signals that transfer and execute by user addresses are nil +var ErrTransferAndExecuteByUserAddressesAreNil = errors.New("transfer and execute by user addresses are nil") diff --git a/process/factory/shard/vmContainerFactory.go b/process/factory/shard/vmContainerFactory.go index d10cd0acb46..42e6ae3c98a 100644 --- a/process/factory/shard/vmContainerFactory.go +++ b/process/factory/shard/vmContainerFactory.go @@ -134,7 +134,7 @@ func (vmf *vmContainerFactory) createMapOpCodeAddressIsAllowed() error { transferAndExecuteByUserAddresses := vmf.config.TransferAndExecuteByUserAddresses if len(transferAndExecuteByUserAddresses) == 0 { - return process.ErrTransferAndExecuteByUserAddressesIsNil + return process.ErrTransferAndExecuteByUserAddressesAreNil } vmf.mapOpcodeAddressIsAllowed[managedMultiTransferESDTNFTExecuteByUser] = make(map[string]struct{}) diff --git a/process/factory/shard/vmContainerFactory_test.go b/process/factory/shard/vmContainerFactory_test.go index 1cbfc60e203..403f39775ab 100644 --- a/process/factory/shard/vmContainerFactory_test.go +++ b/process/factory/shard/vmContainerFactory_test.go @@ -154,7 +154,7 @@ func TestNewVMContainerFactory_EmptyOpcodeAddressListErr(t *testing.T) { vmf, err := NewVMContainerFactory(args) assert.Nil(t, vmf) - assert.Equal(t, process.ErrTransferAndExecuteByUserAddressesIsNil, err) + assert.Equal(t, process.ErrTransferAndExecuteByUserAddressesAreNil, err) } func TestNewVMContainerFactory_WrongAddressErr(t *testing.T) { From ccfbeee9733e86816985411742c51399d78f30c9 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Mon, 29 Apr 2024 14:44:58 +0300 Subject: [PATCH 210/503] fixes after review --- process/factory/shard/vmContainerFactory_test.go | 3 +++ testscommon/vmcommonMocks/userAccountStub.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/process/factory/shard/vmContainerFactory_test.go b/process/factory/shard/vmContainerFactory_test.go index 403f39775ab..1a4c72da3b0 100644 --- a/process/factory/shard/vmContainerFactory_test.go +++ b/process/factory/shard/vmContainerFactory_test.go @@ -204,6 +204,9 @@ func TestVmContainerFactory_Create(t *testing.T) { acc := vmf.BlockChainHookImpl() assert.NotNil(t, acc) + + assert.Equal(t, len(vmf.mapOpcodeAddressIsAllowed), 1) + assert.Equal(t, len(vmf.mapOpcodeAddressIsAllowed[managedMultiTransferESDTNFTExecuteByUser]), 1) } func TestVmContainerFactory_ResolveWasmVMVersion(t *testing.T) { diff --git a/testscommon/vmcommonMocks/userAccountStub.go b/testscommon/vmcommonMocks/userAccountStub.go index 57e88fe5378..5e2357c491b 100644 --- a/testscommon/vmcommonMocks/userAccountStub.go +++ b/testscommon/vmcommonMocks/userAccountStub.go @@ -77,7 +77,7 @@ func (uas *UserAccountStub) AddToBalance(value *big.Int) error { // SubFromBalance - func (uas *UserAccountStub) SubFromBalance(value *big.Int) error { - if uas.AddToBalanceCalled != nil { + if uas.SubFromBalanceCalled != nil { return uas.SubFromBalanceCalled(value) } return nil From 94adf0d7324924c2fdcc869aa3791133b1477ad8 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 30 Apr 2024 13:46:11 +0300 Subject: [PATCH 211/503] fixes after clarifications and tests --- .../txpool/memorytests/memory_test.go | 22 +++---- .../multiShard/relayedTx/common.go | 9 ++- .../relayedTx/edgecases/edgecases_test.go | 4 +- .../multiShard/relayedTx/relayedTx_test.go | 45 ++++++++----- .../vm/txsFee/relayedScCalls_test.go | 7 +- .../vm/txsFee/relayedScDeploy_test.go | 18 ++--- .../interceptedTransaction_test.go | 35 +++++++--- process/transaction/shardProcess.go | 65 ++----------------- process/transaction/shardProcess_test.go | 9 +-- 9 files changed, 95 insertions(+), 119 deletions(-) diff --git a/dataRetriever/txpool/memorytests/memory_test.go b/dataRetriever/txpool/memorytests/memory_test.go index 91201e1a036..a0484f016b8 100644 --- a/dataRetriever/txpool/memorytests/memory_test.go +++ b/dataRetriever/txpool/memorytests/memory_test.go @@ -36,25 +36,25 @@ func TestShardedTxPool_MemoryFootprint(t *testing.T) { journals = append(journals, runScenario(t, newScenario(200, 1, core.MegabyteSize, "0"), memoryAssertion{200, 200}, memoryAssertion{0, 1})) journals = append(journals, runScenario(t, newScenario(10, 1000, 20480, "0"), memoryAssertion{190, 205}, memoryAssertion{1, 4})) journals = append(journals, runScenario(t, newScenario(10000, 1, 1024, "0"), memoryAssertion{10, 16}, memoryAssertion{4, 10})) - journals = append(journals, runScenario(t, newScenario(1, 60000, 256, "0"), memoryAssertion{30, 38}, memoryAssertion{10, 16})) - journals = append(journals, runScenario(t, newScenario(10, 10000, 100, "0"), memoryAssertion{36, 50}, memoryAssertion{16, 24})) - journals = append(journals, runScenario(t, newScenario(100000, 1, 1024, "0"), memoryAssertion{120, 136}, memoryAssertion{56, 60})) + journals = append(journals, runScenario(t, newScenario(1, 60000, 256, "0"), memoryAssertion{30, 40}, memoryAssertion{10, 16})) + journals = append(journals, runScenario(t, newScenario(10, 10000, 100, "0"), memoryAssertion{36, 52}, memoryAssertion{16, 24})) + journals = append(journals, runScenario(t, newScenario(100000, 1, 1024, "0"), memoryAssertion{120, 138}, memoryAssertion{56, 60})) // With larger memory footprint - journals = append(journals, runScenario(t, newScenario(100000, 3, 650, "0"), memoryAssertion{290, 330}, memoryAssertion{95, 120})) - journals = append(journals, runScenario(t, newScenario(150000, 2, 650, "0"), memoryAssertion{290, 330}, memoryAssertion{120, 140})) - journals = append(journals, runScenario(t, newScenario(300000, 1, 650, "0"), memoryAssertion{290, 330}, memoryAssertion{170, 190})) - journals = append(journals, runScenario(t, newScenario(30, 10000, 650, "0"), memoryAssertion{290, 330}, memoryAssertion{60, 75})) - journals = append(journals, runScenario(t, newScenario(300, 1000, 650, "0"), memoryAssertion{290, 330}, memoryAssertion{60, 80})) + journals = append(journals, runScenario(t, newScenario(100000, 3, 650, "0"), memoryAssertion{290, 335}, memoryAssertion{95, 120})) + journals = append(journals, runScenario(t, newScenario(150000, 2, 650, "0"), memoryAssertion{290, 335}, memoryAssertion{120, 140})) + journals = append(journals, runScenario(t, newScenario(300000, 1, 650, "0"), memoryAssertion{290, 335}, memoryAssertion{170, 190})) + journals = append(journals, runScenario(t, newScenario(30, 10000, 650, "0"), memoryAssertion{290, 335}, memoryAssertion{60, 75})) + journals = append(journals, runScenario(t, newScenario(300, 1000, 650, "0"), memoryAssertion{290, 335}, memoryAssertion{60, 80})) // Scenarios where destination == me journals = append(journals, runScenario(t, newScenario(100, 1, core.MegabyteSize, "1_0"), memoryAssertion{90, 100}, memoryAssertion{0, 1})) journals = append(journals, runScenario(t, newScenario(10000, 1, 10240, "1_0"), memoryAssertion{96, 128}, memoryAssertion{0, 4})) - journals = append(journals, runScenario(t, newScenario(10, 10000, 1000, "1_0"), memoryAssertion{96, 136}, memoryAssertion{16, 25})) - journals = append(journals, runScenario(t, newScenario(150000, 1, 128, "1_0"), memoryAssertion{50, 75}, memoryAssertion{30, 40})) - journals = append(journals, runScenario(t, newScenario(1, 150000, 128, "1_0"), memoryAssertion{50, 75}, memoryAssertion{30, 40})) + journals = append(journals, runScenario(t, newScenario(10, 10000, 1000, "1_0"), memoryAssertion{96, 140}, memoryAssertion{16, 25})) + journals = append(journals, runScenario(t, newScenario(150000, 1, 128, "1_0"), memoryAssertion{50, 80}, memoryAssertion{30, 40})) + journals = append(journals, runScenario(t, newScenario(1, 150000, 128, "1_0"), memoryAssertion{50, 80}, memoryAssertion{30, 40})) for _, journal := range journals { journal.displayFootprintsSummary() diff --git a/integrationTests/multiShard/relayedTx/common.go b/integrationTests/multiShard/relayedTx/common.go index 2e1ba08bac5..7b871a52ce2 100644 --- a/integrationTests/multiShard/relayedTx/common.go +++ b/integrationTests/multiShard/relayedTx/common.go @@ -14,7 +14,7 @@ import ( ) // CreateGeneralSetupForRelayTxTest will create the general setup for relayed transactions -func CreateGeneralSetupForRelayTxTest() ([]*integrationTests.TestProcessorNode, []int, []*integrationTests.TestWalletAccount, *integrationTests.TestWalletAccount) { +func CreateGeneralSetupForRelayTxTest(relayedV3Test bool) ([]*integrationTests.TestProcessorNode, []int, []*integrationTests.TestWalletAccount, *integrationTests.TestWalletAccount) { numOfShards := 2 nodesPerShard := 2 numMetachainNodes := 1 @@ -36,15 +36,20 @@ func CreateGeneralSetupForRelayTxTest() ([]*integrationTests.TestProcessorNode, initialVal := big.NewInt(1000000000) integrationTests.MintAllNodes(nodes, initialVal) + relayerShard := uint32(0) numPlayers := 5 numShards := nodes[0].ShardCoordinator.NumberOfShards() players := make([]*integrationTests.TestWalletAccount, numPlayers) for i := 0; i < numPlayers; i++ { shardId := uint32(i) % numShards + // if the test is for relayed v3, force all senders to be in the same shard with the relayer + if relayedV3Test { + shardId = relayerShard + } players[i] = integrationTests.CreateTestWalletAccount(nodes[0].ShardCoordinator, shardId) } - relayerAccount := integrationTests.CreateTestWalletAccount(nodes[0].ShardCoordinator, 0) + relayerAccount := integrationTests.CreateTestWalletAccount(nodes[0].ShardCoordinator, relayerShard) integrationTests.MintAllPlayers(nodes, []*integrationTests.TestWalletAccount{relayerAccount}, initialVal) return nodes, idxProposers, players, relayerAccount diff --git a/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go b/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go index 6adf254433b..e2e6a3be043 100644 --- a/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go +++ b/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go @@ -18,7 +18,7 @@ func TestRelayedTransactionInMultiShardEnvironmentWithNormalTxButWrongNonceShoul t.Skip("this is not a short test") } - nodes, idxProposers, players, relayer := relayedTx.CreateGeneralSetupForRelayTxTest() + nodes, idxProposers, players, relayer := relayedTx.CreateGeneralSetupForRelayTxTest(false) defer func() { for _, n := range nodes { n.Close() @@ -81,7 +81,7 @@ func TestRelayedTransactionInMultiShardEnvironmentWithNormalTxButWithTooMuchGas( t.Skip("this is not a short test") } - nodes, idxProposers, players, relayer := relayedTx.CreateGeneralSetupForRelayTxTest() + nodes, idxProposers, players, relayer := relayedTx.CreateGeneralSetupForRelayTxTest(false) defer func() { for _, n := range nodes { n.Close() diff --git a/integrationTests/multiShard/relayedTx/relayedTx_test.go b/integrationTests/multiShard/relayedTx/relayedTx_test.go index 207ab540688..50c95e520aa 100644 --- a/integrationTests/multiShard/relayedTx/relayedTx_test.go +++ b/integrationTests/multiShard/relayedTx/relayedTx_test.go @@ -47,7 +47,7 @@ type createAndSendRelayedAndUserTxFuncType = func( txData []byte, ) (*transaction.Transaction, *transaction.Transaction) -func TestRelayedTransactionInMultiShardEnvironmanetWithChainSimulator(t *testing.T) { +func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } @@ -106,11 +106,17 @@ func TestRelayedTransactionInMultiShardEnvironmanetWithChainSimulator(t *testing innerTx2 := generateTransaction(sender2.Bytes, 0, receiver2.Bytes, oneEGLD, "", minGasLimit) innerTx2.RelayerAddr = relayer.Bytes + // innerTx3Failure should fail due to less gas limit + data := "gas limit is not enough" + innerTx3Failure := generateTransaction(sender.Bytes, 1, receiver2.Bytes, oneEGLD, data, minGasLimit) + innerTx3Failure.RelayerAddr = relayer.Bytes + innerTx3 := generateTransaction(sender.Bytes, 1, receiver2.Bytes, oneEGLD, "", minGasLimit) innerTx3.RelayerAddr = relayer.Bytes innerTxs := []*transaction.Transaction{innerTx, innerTx2, innerTx3} + // relayer will consume gas for 2 move balances for 2 different senders + the gas for each transaction that succeeds relayedTxGasLimit := minGasLimit * 5 relayedTx := generateTransaction(relayer.Bytes, 0, relayer.Bytes, big.NewInt(0), "", uint64(relayedTxGasLimit)) relayedTx.InnerTransactions = innerTxs @@ -118,13 +124,14 @@ func TestRelayedTransactionInMultiShardEnvironmanetWithChainSimulator(t *testing _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) require.NoError(t, err) - // generate few more blocks for the cross shard scr to be done + // generate few more blocks for the cross shard scrs to be done err = cs.GenerateBlocks(numOfBlocksToWaitForCrossShardSCR) require.NoError(t, err) relayerAccount, err := cs.GetAccount(relayer) require.NoError(t, err) - expectedRelayerFee := big.NewInt(int64(minGasPrice * relayedTxGasLimit)) + gasLimitForSucceededTxs := minGasLimit * 5 + expectedRelayerFee := big.NewInt(int64(minGasPrice * gasLimitForSucceededTxs)) assert.Equal(t, big.NewInt(0).Sub(initialBalance, expectedRelayerFee).String(), relayerAccount.Balance) senderAccount, err := cs.GetAccount(sender) @@ -160,36 +167,37 @@ func generateTransaction(sender []byte, nonce uint64, receiver []byte, value *bi } func TestRelayedTransactionInMultiShardEnvironmentWithNormalTx(t *testing.T) { - t.Run("relayed v1", testRelayedTransactionInMultiShardEnvironmentWithNormalTx(CreateAndSendRelayedAndUserTx)) - t.Run("relayed v3", testRelayedTransactionInMultiShardEnvironmentWithNormalTx(CreateAndSendRelayedAndUserTxV3)) + t.Run("relayed v1", testRelayedTransactionInMultiShardEnvironmentWithNormalTx(CreateAndSendRelayedAndUserTx, false)) + t.Run("relayed v3", testRelayedTransactionInMultiShardEnvironmentWithNormalTx(CreateAndSendRelayedAndUserTxV3, true)) } func TestRelayedTransactionInMultiShardEnvironmentWithSmartContractTX(t *testing.T) { - t.Run("relayed v1", testRelayedTransactionInMultiShardEnvironmentWithSmartContractTX(CreateAndSendRelayedAndUserTx)) - t.Run("relayed v2", testRelayedTransactionInMultiShardEnvironmentWithSmartContractTX(CreateAndSendRelayedAndUserTxV2)) - t.Run("relayed v3", testRelayedTransactionInMultiShardEnvironmentWithSmartContractTX(CreateAndSendRelayedAndUserTxV3)) + t.Run("relayed v1", testRelayedTransactionInMultiShardEnvironmentWithSmartContractTX(CreateAndSendRelayedAndUserTx, false)) + t.Run("relayed v2", testRelayedTransactionInMultiShardEnvironmentWithSmartContractTX(CreateAndSendRelayedAndUserTxV2, false)) + t.Run("relayed v3", testRelayedTransactionInMultiShardEnvironmentWithSmartContractTX(CreateAndSendRelayedAndUserTxV3, true)) } func TestRelayedTransactionInMultiShardEnvironmentWithESDTTX(t *testing.T) { - t.Run("relayed v1", testRelayedTransactionInMultiShardEnvironmentWithESDTTX(CreateAndSendRelayedAndUserTx)) - t.Run("relayed v2", testRelayedTransactionInMultiShardEnvironmentWithESDTTX(CreateAndSendRelayedAndUserTxV2)) - t.Run("relayed v3", testRelayedTransactionInMultiShardEnvironmentWithESDTTX(CreateAndSendRelayedAndUserTxV3)) + t.Run("relayed v1", testRelayedTransactionInMultiShardEnvironmentWithESDTTX(CreateAndSendRelayedAndUserTx, false)) + t.Run("relayed v2", testRelayedTransactionInMultiShardEnvironmentWithESDTTX(CreateAndSendRelayedAndUserTxV2, false)) + t.Run("relayed v3", testRelayedTransactionInMultiShardEnvironmentWithESDTTX(CreateAndSendRelayedAndUserTxV3, true)) } func TestRelayedTransactionInMultiShardEnvironmentWithAttestationContract(t *testing.T) { - t.Run("relayed v1", testRelayedTransactionInMultiShardEnvironmentWithAttestationContract(CreateAndSendRelayedAndUserTx)) - t.Run("relayed v3", testRelayedTransactionInMultiShardEnvironmentWithAttestationContract(CreateAndSendRelayedAndUserTxV3)) + t.Run("relayed v1", testRelayedTransactionInMultiShardEnvironmentWithAttestationContract(CreateAndSendRelayedAndUserTx, false)) + t.Run("relayed v3", testRelayedTransactionInMultiShardEnvironmentWithAttestationContract(CreateAndSendRelayedAndUserTxV3, true)) } func testRelayedTransactionInMultiShardEnvironmentWithNormalTx( createAndSendRelayedAndUserTxFunc createAndSendRelayedAndUserTxFuncType, + relayedV3Test bool, ) func(t *testing.T) { return func(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } - nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest() + nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest(relayedV3Test) defer func() { for _, n := range nodes { n.Close() @@ -246,13 +254,14 @@ func testRelayedTransactionInMultiShardEnvironmentWithNormalTx( func testRelayedTransactionInMultiShardEnvironmentWithSmartContractTX( createAndSendRelayedAndUserTxFunc createAndSendRelayedAndUserTxFuncType, + relayedV3Test bool, ) func(t *testing.T) { return func(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } - nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest() + nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest(relayedV3Test) defer func() { for _, n := range nodes { n.Close() @@ -340,13 +349,14 @@ func testRelayedTransactionInMultiShardEnvironmentWithSmartContractTX( func testRelayedTransactionInMultiShardEnvironmentWithESDTTX( createAndSendRelayedAndUserTxFunc createAndSendRelayedAndUserTxFuncType, + relayedV3Test bool, ) func(t *testing.T) { return func(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } - nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest() + nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest(relayedV3Test) defer func() { for _, n := range nodes { n.Close() @@ -436,6 +446,7 @@ func testRelayedTransactionInMultiShardEnvironmentWithESDTTX( func testRelayedTransactionInMultiShardEnvironmentWithAttestationContract( createAndSendRelayedAndUserTxFunc createAndSendRelayedAndUserTxFuncType, + relayedV3Test bool, ) func(t *testing.T) { return func(t *testing.T) { @@ -443,7 +454,7 @@ func testRelayedTransactionInMultiShardEnvironmentWithAttestationContract( t.Skip("this is not a short test") } - nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest() + nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest(relayedV3Test) defer func() { for _, n := range nodes { n.Close() diff --git a/integrationTests/vm/txsFee/relayedScCalls_test.go b/integrationTests/vm/txsFee/relayedScCalls_test.go index 8a007dadc23..e0681f49349 100644 --- a/integrationTests/vm/txsFee/relayedScCalls_test.go +++ b/integrationTests/vm/txsFee/relayedScCalls_test.go @@ -179,7 +179,7 @@ func TestRelayedScCallInsufficientGasLimitShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - t.Run("before relayed fix", testRelayedScCallInsufficientGasLimitShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(28100), big.NewInt(13800))) + t.Run("before relayed fix", testRelayedScCallInsufficientGasLimitShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(28050), big.NewInt(13850))) t.Run("after relayed fix", testRelayedScCallInsufficientGasLimitShouldConsumeGas(0, big.NewInt(28050), big.NewInt(13850))) } @@ -196,12 +196,13 @@ func testRelayedScCallInsufficientGasLimitShouldConsumeGas(relayedFixActivationE relayerAddr := []byte("12345678901234567890123456789033") sndAddr := []byte("12345678901234567890123456789112") - gasLimit := uint64(5) + data := "increment" + gasLimit := minGasLimit + uint64(len(data)) _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, big.NewInt(0)) _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(30000)) - userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, scAddress, gasPrice, gasLimit, []byte("increment")) + userTx := vm.CreateTransaction(0, big.NewInt(100), sndAddr, scAddress, gasPrice, gasLimit, []byte(data)) rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) rTxGasLimit := minGasLimit + gasLimit + uint64(len(rtxData)) diff --git a/integrationTests/vm/txsFee/relayedScDeploy_test.go b/integrationTests/vm/txsFee/relayedScDeploy_test.go index bfd4b3851f1..6c33afe8c44 100644 --- a/integrationTests/vm/txsFee/relayedScDeploy_test.go +++ b/integrationTests/vm/txsFee/relayedScDeploy_test.go @@ -70,7 +70,7 @@ func TestRelayedScDeployInvalidCodeShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - t.Run("before relayed fix", testRelayedScDeployInvalidCodeShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(17030), big.NewInt(32970))) + t.Run("before relayed fix", testRelayedScDeployInvalidCodeShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(8890), big.NewInt(41110))) t.Run("after relayed fix", testRelayedScDeployInvalidCodeShouldConsumeGas(0, big.NewInt(8890), big.NewInt(41110))) } @@ -87,7 +87,6 @@ func testRelayedScDeployInvalidCodeShouldConsumeGas(relayedFixActivationEpoch ui senderNonce := uint64(0) senderBalance := big.NewInt(0) - gasLimit := uint64(500) _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, senderBalance) _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(50000)) @@ -95,6 +94,7 @@ func testRelayedScDeployInvalidCodeShouldConsumeGas(relayedFixActivationEpoch ui scCode := wasm.GetSCCode("../wasm/testdata/misc/fib_wasm/output/fib_wasm.wasm") scCodeBytes := []byte(wasm.CreateDeployTxData(scCode)) scCodeBytes = append(scCodeBytes, []byte("aaaaa")...) + gasLimit := minGasLimit + uint64(len(scCodeBytes)) userTx := vm.CreateTransaction(senderNonce, big.NewInt(0), sndAddr, vm.CreateEmptyAddress(), gasPrice, gasLimit, scCodeBytes) rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) @@ -123,7 +123,7 @@ func TestRelayedScDeployInsufficientGasLimitShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - t.Run("before relayed fix", testRelayedScDeployInsufficientGasLimitShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(17130), big.NewInt(32870))) + t.Run("before relayed fix", testRelayedScDeployInsufficientGasLimitShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(9040), big.NewInt(40960))) t.Run("after relayed fix", testRelayedScDeployInsufficientGasLimitShouldConsumeGas(0, big.NewInt(9040), big.NewInt(40960))) } @@ -140,13 +140,14 @@ func testRelayedScDeployInsufficientGasLimitShouldConsumeGas(relayedFixActivatio senderNonce := uint64(0) senderBalance := big.NewInt(0) - gasLimit := uint64(500) _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, senderBalance) _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(50000)) scCode := wasm.GetSCCode("../wasm/testdata/misc/fib_wasm/output/fib_wasm.wasm") - userTx := vm.CreateTransaction(senderNonce, big.NewInt(0), sndAddr, vm.CreateEmptyAddress(), gasPrice, gasLimit, []byte(wasm.CreateDeployTxData(scCode))) + data := wasm.CreateDeployTxData(scCode) + gasLimit := minGasLimit + uint64(len(data)) + userTx := vm.CreateTransaction(senderNonce, big.NewInt(0), sndAddr, vm.CreateEmptyAddress(), gasPrice, gasLimit, []byte(data)) rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) @@ -174,7 +175,7 @@ func TestRelayedScDeployOutOfGasShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - t.Run("before relayed fix", testRelayedScDeployOutOfGasShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(16430), big.NewInt(33570))) + t.Run("before relayed fix", testRelayedScDeployOutOfGasShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(9040), big.NewInt(40960))) t.Run("after relayed fix", testRelayedScDeployOutOfGasShouldConsumeGas(0, big.NewInt(9040), big.NewInt(40960))) } @@ -191,13 +192,14 @@ func testRelayedScDeployOutOfGasShouldConsumeGas(relayedFixActivationEpoch uint3 senderNonce := uint64(0) senderBalance := big.NewInt(0) - gasLimit := uint64(570) _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, senderBalance) _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(50000)) scCode := wasm.GetSCCode("../wasm/testdata/misc/fib_wasm/output/fib_wasm.wasm") - userTx := vm.CreateTransaction(senderNonce, big.NewInt(0), sndAddr, vm.CreateEmptyAddress(), gasPrice, gasLimit, []byte(wasm.CreateDeployTxData(scCode))) + data := wasm.CreateDeployTxData(scCode) + gasLimit := minGasLimit + uint64(len(data)) + userTx := vm.CreateTransaction(senderNonce, big.NewInt(0), sndAddr, vm.CreateEmptyAddress(), gasPrice, gasLimit, []byte(data)) rtxData := integrationTests.PrepareRelayedTxDataV1(userTx) rTxGasLimit := 1 + gasLimit + uint64(len(rtxData)) diff --git a/process/transaction/interceptedTransaction_test.go b/process/transaction/interceptedTransaction_test.go index b87882023bf..e53f8221135 100644 --- a/process/transaction/interceptedTransaction_test.go +++ b/process/transaction/interceptedTransaction_test.go @@ -37,8 +37,10 @@ var errSignerMockVerifySigFails = errors.New("errSignerMockVerifySigFails") var senderShard = uint32(2) var recvShard = uint32(3) +var relayerShard = senderShard var senderAddress = []byte("12345678901234567890123456789012") var recvAddress = []byte("23456789012345678901234567890123") +var relayerAddress = []byte("34567890123456789012345678901234") var sigBad = []byte("bad-signature") var sigOk = []byte("signature") @@ -93,6 +95,9 @@ func createInterceptedTxWithTxFeeHandlerAndVersionChecker(tx *dataTransaction.Tr if bytes.Equal(address, recvAddress) { return recvShard } + if bytes.Equal(address, relayerAddress) { + return relayerShard + } return shardCoordinator.CurrentShard } @@ -138,6 +143,9 @@ func createInterceptedTxFromPlainTx(tx *dataTransaction.Transaction, txFeeHandle if bytes.Equal(address, recvAddress) { return recvShard } + if bytes.Equal(address, relayerAddress) { + return relayerShard + } return shardCoordinator.CurrentShard } @@ -183,10 +191,19 @@ func createInterceptedTxFromPlainTxWithArgParser(tx *dataTransaction.Transaction if bytes.Equal(address, recvAddress) { return recvShard } + if bytes.Equal(address, relayerAddress) { + return relayerShard + } return shardCoordinator.CurrentShard } + txFeeHandler := createFreeTxFeeHandler() + relayedTxV3Processor, err := transaction.NewRelayedTxV3Processor(txFeeHandler, shardCoordinator) + if err != nil { + return nil, err + } + return transaction.NewInterceptedTransaction( txBuff, marshalizer, @@ -200,7 +217,7 @@ func createInterceptedTxFromPlainTxWithArgParser(tx *dataTransaction.Transaction }, }, shardCoordinator, - createFreeTxFeeHandler(), + txFeeHandler, &testscommon.WhiteListHandlerStub{}, smartContract.NewArgumentParser(), tx.ChainID, @@ -208,7 +225,7 @@ func createInterceptedTxFromPlainTxWithArgParser(tx *dataTransaction.Transaction &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(tx.Version), enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV3Flag), - &processMocks.RelayedTxV3ProcessorMock{}, + relayedTxV3Processor, ) } @@ -1663,12 +1680,12 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { Data: []byte("data inner tx 1"), GasLimit: 3, GasPrice: 4, - RcvAddr: []byte("34567890123456789012345678901234"), - SndAddr: recvAddress, + RcvAddr: recvAddress, + SndAddr: senderAddress, Signature: sigOk, ChainID: chainID, Version: minTxVersion, - RelayerAddr: senderAddress, + RelayerAddr: relayerAddress, } tx := &dataTransaction.Transaction{ @@ -1676,8 +1693,8 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { Value: big.NewInt(0), GasLimit: 10, GasPrice: 4, - RcvAddr: senderAddress, - SndAddr: senderAddress, + RcvAddr: relayerAddress, + SndAddr: relayerAddress, Signature: sigOk, ChainID: chainID, Version: minTxVersion, @@ -1709,7 +1726,7 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { txCopy := *tx innerTxCopy := *innerTx - innerTxCopy.RelayerAddr = []byte("34567890123456789012345678901234") + innerTxCopy.RelayerAddr = recvAddress txCopy.InnerTransactions = []*dataTransaction.Transaction{&innerTxCopy} txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) @@ -1721,7 +1738,7 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { txCopy := *tx innerTxCopy := *innerTx - txCopy.RcvAddr = []byte("34567890123456789012345678901234") + txCopy.RcvAddr = recvAddress txCopy.InnerTransactions = []*dataTransaction.Transaction{&innerTxCopy} txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) err := txi.CheckValidity() diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index efa6e0a14e9..1581e9dba53 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -678,72 +678,18 @@ func (txProc *txProcessor) processRelayedTxV3( for _, innerTx := range innerTxs { innerTxRetCode, innerTxErr = txProc.finishExecutionOfInnerTx(tx, innerTx) if innerTxErr != nil || innerTxRetCode != vmcommon.Ok { - break + continue } executedUserTxs = append(executedUserTxs, innerTx) } allUserTxsSucceeded := len(executedUserTxs) == len(innerTxs) && innerTxErr == nil && innerTxRetCode == vmcommon.Ok - // if all user transactions were executed, return success - if allUserTxsSucceeded { - return vmcommon.Ok, nil - } - - defer func() { - // reset all senders to the snapshot took before starting the execution - txProc.resetBalancesToSnapshot(sendersBalancesSnapshot) - }() - - // if the first one failed, return last error - // the current transaction should have been already reverted - if len(executedUserTxs) == 0 { - return innerTxRetCode, innerTxErr + if !allUserTxsSucceeded { + log.Debug("failed to execute all inner transactions", "total", len(innerTxs), "executed transactions", len(executedUserTxs)) } - originalTxHash, err := core.CalculateHash(txProc.marshalizer, txProc.hasher, tx) - if err != nil { - return vmcommon.UserError, err - } - - defer func() { - executedHashed := make([][]byte, 0) - for _, executedUserTx := range executedUserTxs { - txHash, errHash := core.CalculateHash(txProc.marshalizer, txProc.hasher, executedUserTx) - if errHash != nil { - continue - } - executedHashed = append(executedHashed, txHash) - } - - txProc.txFeeHandler.RevertFees(executedHashed) - }() - - // if one or more user transactions were executed before one of them failed, revert all, including the fees transferred - // the current transaction should have been already reverted - var lastErr error - revertedTxsCnt := 0 - for _, executedUserTx := range executedUserTxs { - errRemove := txProc.removeValueAndConsumedFeeFromUser(executedUserTx, tx.Value, originalTxHash, tx, process.ErrSubsequentInnerTransactionFailed) - if errRemove != nil { - lastErr = errRemove - continue - } - - revertedTxsCnt++ - } - - if lastErr != nil { - log.Warn("failed to revert all previous executed inner transactions, last error = %w, "+ - "total transactions = %d, num of transactions reverted = %d", - lastErr, - len(executedUserTxs), - revertedTxsCnt) - - return vmcommon.UserError, lastErr - } - - return vmcommon.UserError, process.ErrInvalidInnerTransactions + return vmcommon.Ok, nil } func (txProc *txProcessor) finishExecutionOfInnerTx( @@ -923,10 +869,7 @@ func (txProc *txProcessor) processMoveBalanceCostRelayedUserTx( moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(userTx) moveBalanceUserFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, moveBalanceGasLimit) if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { - gasToUse := userTx.GetGasLimit() - moveBalanceGasLimit moveBalanceUserFee = txProc.economicsFee.ComputeMoveBalanceFee(userTx) - processingUserFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, gasToUse) - moveBalanceUserFee = moveBalanceUserFee.Add(moveBalanceUserFee, processingUserFee) } userScrHash, err := core.CalculateHash(txProc.marshalizer, txProc.hasher, userScr) diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index a58e3080b1f..0febe0796b7 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -1460,9 +1460,6 @@ func TestTxProcessor_ProcessTxFeeMoveBalanceUserTx(t *testing.T) { ComputeFeeForProcessingCalled: func(tx data.TransactionWithFeeHandler, gasToUse uint64) *big.Int { return processingFee }, - ComputeTxFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { - return moveBalanceFee - }, } execTx, _ := txproc.NewTxProcessor(args) @@ -1480,8 +1477,8 @@ func TestTxProcessor_ProcessTxFeeMoveBalanceUserTx(t *testing.T) { cost, totalCost, err := execTx.ProcessTxFee(tx, acntSnd, nil, process.MoveBalance, true) assert.Nil(t, err) - assert.True(t, cost.Cmp(moveBalanceFee) == 0) - assert.True(t, totalCost.Cmp(moveBalanceFee) == 0) + assert.True(t, cost.Cmp(big.NewInt(0).Add(moveBalanceFee, processingFee)) == 0) + assert.True(t, totalCost.Cmp(big.NewInt(0).Add(moveBalanceFee, processingFee)) == 0) } func TestTxProcessor_ProcessTxFeeSCInvokeUserTx(t *testing.T) { @@ -1619,7 +1616,7 @@ func TestTxProcessor_ProcessTransactionShouldTreatAsInvalidTxIfTxTypeIsWrong(t * _, err := execTx.ProcessTransaction(&tx) assert.Equal(t, err, process.ErrFailedTransaction) assert.Equal(t, uint64(1), acntSrc.GetNonce()) - assert.Equal(t, uint64(45), acntSrc.GetBalance().Uint64()) + assert.Equal(t, uint64(46), acntSrc.GetBalance().Uint64()) } func TestTxProcessor_ProcessRelayedTransactionV2NotActiveShouldErr(t *testing.T) { From c00c31fbf65593807f2748f8cb1dcc5be1180362 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 30 Apr 2024 16:03:02 +0300 Subject: [PATCH 212/503] tests are failing when running all together. separately they execute well. --- integrationTests/multiShard/relayedTx/relayedTxV2_test.go | 3 ++- integrationTests/multiShard/relayedTx/relayedTx_test.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/integrationTests/multiShard/relayedTx/relayedTxV2_test.go b/integrationTests/multiShard/relayedTx/relayedTxV2_test.go index 0259a865f3f..aa35951c3ea 100644 --- a/integrationTests/multiShard/relayedTx/relayedTxV2_test.go +++ b/integrationTests/multiShard/relayedTx/relayedTxV2_test.go @@ -82,8 +82,9 @@ func TestRelayedTransactionV2InMultiShardEnvironmentWithSmartContractTX(t *testi time.Sleep(integrationTests.StepDelay) } + time.Sleep(time.Second) - roundToPropagateMultiShard := int64(20) + roundToPropagateMultiShard := int64(25) for i := int64(0); i <= roundToPropagateMultiShard; i++ { round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) diff --git a/integrationTests/multiShard/relayedTx/relayedTx_test.go b/integrationTests/multiShard/relayedTx/relayedTx_test.go index a78931a4f91..43f713d5d09 100644 --- a/integrationTests/multiShard/relayedTx/relayedTx_test.go +++ b/integrationTests/multiShard/relayedTx/relayedTx_test.go @@ -143,8 +143,9 @@ func TestRelayedTransactionInMultiShardEnvironmentWithSmartContractTX(t *testing time.Sleep(integrationTests.StepDelay) } + time.Sleep(time.Second) - roundToPropagateMultiShard := int64(20) + roundToPropagateMultiShard := int64(25) for i := int64(0); i <= roundToPropagateMultiShard; i++ { round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) From f2e097da329a86b86e17a6e7943c8cca67bf12e1 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 30 Apr 2024 17:00:34 +0300 Subject: [PATCH 213/503] added extra tests and coverage --- .../processComponentsHandler_test.go | 2 + .../components/processComponents_test.go | 1 + .../transaction/relayedTxV3Processor_test.go | 213 ++++++++++++++++++ process/transaction/shardProcess_test.go | 190 +++++++++++++++- 4 files changed, 405 insertions(+), 1 deletion(-) create mode 100644 process/transaction/relayedTxV3Processor_test.go diff --git a/factory/processing/processComponentsHandler_test.go b/factory/processing/processComponentsHandler_test.go index 36638afacfd..1f9c0e3d29c 100644 --- a/factory/processing/processComponentsHandler_test.go +++ b/factory/processing/processComponentsHandler_test.go @@ -93,6 +93,7 @@ func TestManagedProcessComponents_Create(t *testing.T) { require.True(t, check.IfNil(managedProcessComponents.FullArchivePeerShardMapper())) require.True(t, check.IfNil(managedProcessComponents.FullArchiveInterceptorsContainer())) require.True(t, check.IfNil(managedProcessComponents.SentSignaturesTracker())) + require.True(t, check.IfNil(managedProcessComponents.RelayedTxV3Processor())) err := managedProcessComponents.Create() require.NoError(t, err) @@ -137,6 +138,7 @@ func TestManagedProcessComponents_Create(t *testing.T) { require.False(t, check.IfNil(managedProcessComponents.FullArchivePeerShardMapper())) require.False(t, check.IfNil(managedProcessComponents.FullArchiveInterceptorsContainer())) require.False(t, check.IfNil(managedProcessComponents.SentSignaturesTracker())) + require.False(t, check.IfNil(managedProcessComponents.RelayedTxV3Processor())) require.Equal(t, factory.ProcessComponentsName, managedProcessComponents.String()) }) diff --git a/node/chainSimulator/components/processComponents_test.go b/node/chainSimulator/components/processComponents_test.go index 4628bbc4f66..c3a031567f8 100644 --- a/node/chainSimulator/components/processComponents_test.go +++ b/node/chainSimulator/components/processComponents_test.go @@ -407,6 +407,7 @@ func TestProcessComponentsHolder_Getters(t *testing.T) { require.NotNil(t, comp.ESDTDataStorageHandlerForAPI()) require.NotNil(t, comp.AccountsParser()) require.NotNil(t, comp.ReceiptsRepository()) + require.NotNil(t, comp.RelayedTxV3Processor()) require.Nil(t, comp.CheckSubcomponents()) require.Empty(t, comp.String()) diff --git a/process/transaction/relayedTxV3Processor_test.go b/process/transaction/relayedTxV3Processor_test.go new file mode 100644 index 00000000000..6e83f4722c8 --- /dev/null +++ b/process/transaction/relayedTxV3Processor_test.go @@ -0,0 +1,213 @@ +package transaction_test + +import ( + "bytes" + "math/big" + "testing" + + "github.com/multiversx/mx-chain-core-go/data" + coreTransaction "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/process/transaction" + "github.com/multiversx/mx-chain-go/testscommon" + "github.com/multiversx/mx-chain-go/testscommon/economicsmocks" + "github.com/stretchr/testify/require" +) + +const minGasLimit = uint64(1) + +func getDefaultTx() *coreTransaction.Transaction { + return &coreTransaction.Transaction{ + Nonce: 0, + Value: big.NewInt(0), + RcvAddr: []byte("rel"), + SndAddr: []byte("rel"), + GasPrice: 1, + GasLimit: minGasLimit * 4, + InnerTransactions: []*coreTransaction.Transaction{ + { + Nonce: 0, + Value: big.NewInt(1), + RcvAddr: []byte("rcv1"), + SndAddr: []byte("snd1"), + GasPrice: 1, + GasLimit: minGasLimit, + RelayerAddr: []byte("rel"), + }, + { + Nonce: 0, + Value: big.NewInt(1), + RcvAddr: []byte("rcv1"), + SndAddr: []byte("snd2"), + GasPrice: 1, + GasLimit: minGasLimit, + RelayerAddr: []byte("rel"), + }, + }, + } +} + +func TestNewRelayedTxV3Processor(t *testing.T) { + t.Parallel() + + t.Run("nil economics fee should error", func(t *testing.T) { + t.Parallel() + + proc, err := transaction.NewRelayedTxV3Processor(nil, nil) + require.Nil(t, proc) + require.Equal(t, process.ErrNilEconomicsFeeHandler, err) + }) + t.Run("nil shard coordinator should error", func(t *testing.T) { + t.Parallel() + + proc, err := transaction.NewRelayedTxV3Processor(&economicsmocks.EconomicsHandlerStub{}, nil) + require.Nil(t, proc) + require.Equal(t, process.ErrNilShardCoordinator, err) + }) + t.Run("should work", func(t *testing.T) { + t.Parallel() + + proc, err := transaction.NewRelayedTxV3Processor(&economicsmocks.EconomicsHandlerStub{}, &testscommon.ShardsCoordinatorMock{}) + require.NoError(t, err) + require.NotNil(t, proc) + }) +} + +func TestRelayedTxV3Processor_IsInterfaceNil(t *testing.T) { + t.Parallel() + + proc, _ := transaction.NewRelayedTxV3Processor(nil, nil) + require.True(t, proc.IsInterfaceNil()) + + proc, _ = transaction.NewRelayedTxV3Processor(&economicsmocks.EconomicsHandlerStub{}, &testscommon.ShardsCoordinatorMock{}) + require.False(t, proc.IsInterfaceNil()) +} + +func TestRelayedTxV3Processor_CheckRelayedTx(t *testing.T) { + t.Parallel() + + t.Run("value on relayed tx should error", func(t *testing.T) { + t.Parallel() + + proc, err := transaction.NewRelayedTxV3Processor(&economicsmocks.EconomicsHandlerStub{}, &testscommon.ShardsCoordinatorMock{}) + require.NoError(t, err) + + tx := getDefaultTx() + tx.Value = big.NewInt(1) + + err = proc.CheckRelayedTx(tx) + require.Equal(t, process.ErrRelayedTxV3ZeroVal, err) + }) + t.Run("relayed tx not to self should error", func(t *testing.T) { + t.Parallel() + + proc, err := transaction.NewRelayedTxV3Processor(&economicsmocks.EconomicsHandlerStub{}, &testscommon.ShardsCoordinatorMock{}) + require.NoError(t, err) + + tx := getDefaultTx() + tx.RcvAddr = []byte("another rcv") + + err = proc.CheckRelayedTx(tx) + require.Equal(t, process.ErrRelayedTxV3SenderDoesNotMatchReceiver, err) + }) + t.Run("invalid gas limit should error", func(t *testing.T) { + t.Parallel() + + economicsFeeHandler := &economicsmocks.EconomicsHandlerStub{ + ComputeGasLimitCalled: func(tx data.TransactionWithFeeHandler) uint64 { + return minGasLimit + }, + } + proc, err := transaction.NewRelayedTxV3Processor(economicsFeeHandler, &testscommon.ShardsCoordinatorMock{}) + require.NoError(t, err) + + tx := getDefaultTx() + tx.GasLimit = minGasLimit + + err = proc.CheckRelayedTx(tx) + require.Equal(t, process.ErrRelayedTxV3GasLimitMismatch, err) + }) + t.Run("empty relayer on inner should error", func(t *testing.T) { + t.Parallel() + + proc, err := transaction.NewRelayedTxV3Processor(&economicsmocks.EconomicsHandlerStub{}, &testscommon.ShardsCoordinatorMock{}) + require.NoError(t, err) + + tx := getDefaultTx() + tx.InnerTransactions[0].RelayerAddr = []byte("") + + err = proc.CheckRelayedTx(tx) + require.Equal(t, process.ErrRelayedTxV3EmptyRelayer, err) + }) + t.Run("relayer mismatch on inner should error", func(t *testing.T) { + t.Parallel() + + proc, err := transaction.NewRelayedTxV3Processor(&economicsmocks.EconomicsHandlerStub{}, &testscommon.ShardsCoordinatorMock{}) + require.NoError(t, err) + + tx := getDefaultTx() + tx.InnerTransactions[0].RelayerAddr = []byte("another relayer") + + err = proc.CheckRelayedTx(tx) + require.Equal(t, process.ErrRelayedTxV3RelayerMismatch, err) + }) + t.Run("gas price mismatch on inner should error", func(t *testing.T) { + t.Parallel() + + proc, err := transaction.NewRelayedTxV3Processor(&economicsmocks.EconomicsHandlerStub{}, &testscommon.ShardsCoordinatorMock{}) + require.NoError(t, err) + + tx := getDefaultTx() + tx.InnerTransactions[0].GasPrice = tx.GasPrice + 1 + + err = proc.CheckRelayedTx(tx) + require.Equal(t, process.ErrRelayedV3GasPriceMismatch, err) + }) + t.Run("shard mismatch on inner should error", func(t *testing.T) { + t.Parallel() + + tx := getDefaultTx() + shardC := &testscommon.ShardsCoordinatorMock{ + ComputeIdCalled: func(address []byte) uint32 { + if bytes.Equal(address, tx.SndAddr) { + return 0 + } + + return 1 + }, + } + proc, err := transaction.NewRelayedTxV3Processor(&economicsmocks.EconomicsHandlerStub{}, shardC) + require.NoError(t, err) + + err = proc.CheckRelayedTx(tx) + require.Equal(t, process.ErrRelayedTxV3SenderShardMismatch, err) + }) + t.Run("should work", func(t *testing.T) { + t.Parallel() + + proc, err := transaction.NewRelayedTxV3Processor(&economicsmocks.EconomicsHandlerStub{}, &testscommon.ShardsCoordinatorMock{}) + require.NoError(t, err) + + tx := getDefaultTx() + err = proc.CheckRelayedTx(tx) + require.NoError(t, err) + }) +} + +func TestRelayedTxV3Processor_ComputeRelayedTxFees(t *testing.T) { + t.Parallel() + + economicsFeeHandler := &economicsmocks.EconomicsHandlerStub{ + ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { + return big.NewInt(int64(minGasLimit * tx.GetGasPrice())) + }, + } + proc, err := transaction.NewRelayedTxV3Processor(economicsFeeHandler, &testscommon.ShardsCoordinatorMock{}) + require.NoError(t, err) + + tx := getDefaultTx() + relayerFee, totalFee := proc.ComputeRelayedTxFees(tx) + expectedRelayerFee := big.NewInt(int64(2 * minGasLimit * tx.GetGasPrice())) // 2 move balance + require.Equal(t, expectedRelayerFee, relayerFee) + require.Equal(t, big.NewInt(int64(tx.GetGasLimit()*tx.GetGasPrice())), totalFee) +} diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index 0febe0796b7..e41c5849e3d 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -33,6 +33,7 @@ import ( "github.com/multiversx/mx-chain-vm-common-go/builtInFunctions" "github.com/multiversx/mx-chain-vm-common-go/parsers" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func generateRandomByteSlice(size int) []byte { @@ -304,6 +305,28 @@ func TestNewTxProcessor_NilEnableRoundsHandlerShouldErr(t *testing.T) { assert.Nil(t, txProc) } +func TestNewTxProcessor_NilTxVersionCheckerShouldErr(t *testing.T) { + t.Parallel() + + args := createArgsForTxProcessor() + args.TxVersionChecker = nil + txProc, err := txproc.NewTxProcessor(args) + + assert.Equal(t, process.ErrNilTransactionVersionChecker, err) + assert.Nil(t, txProc) +} + +func TestNewTxProcessor_NilGuardianCheckerShouldErr(t *testing.T) { + t.Parallel() + + args := createArgsForTxProcessor() + args.GuardianChecker = nil + txProc, err := txproc.NewTxProcessor(args) + + assert.Equal(t, process.ErrNilGuardianChecker, err) + assert.Nil(t, txProc) +} + func TestNewTxProcessor_NilRelayedTxV3ProcessorShouldErr(t *testing.T) { t.Parallel() @@ -2153,6 +2176,159 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { txCopy.GasLimit = userTx.GasLimit - 1 testProcessRelayedTransactionV3(t, &txCopy, userTx.SndAddr, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) }) + t.Run("failure to add fees on destination should revert to snapshot and should error", func(t *testing.T) { + t.Parallel() + + providedAddrFail := []byte("fail addr") + providedInitialBalance := big.NewInt(100) + pubKeyConverter := testscommon.NewPubkeyConverterMock(4) + + accounts := map[string]state.UserAccountHandler{} + adb := &stateMock.AccountsStub{} + adb.LoadAccountCalled = func(address []byte) (vmcommon.AccountHandler, error) { + if bytes.Equal(address, providedAddrFail) { + return &stateMock.UserAccountStub{ + AddToBalanceCalled: func(value *big.Int) error { + return errors.New("won't add to balance") + }, + }, nil + } + + acnt, exists := accounts[string(address)] + if !exists { + acnt = createUserAcc(address) + accounts[string(address)] = acnt + _ = acnt.AddToBalance(providedInitialBalance) + } + + return acnt, nil + } + + scProcessorMock := &testscommon.SCProcessorMock{} + shardC, _ := sharding.NewMultiShardCoordinator(1, 0) + esdtTransferParser, _ := parsers.NewESDTTransferParser(marshaller) + argTxTypeHandler := coordinator.ArgNewTxTypeHandler{ + PubkeyConverter: pubKeyConverter, + ShardCoordinator: shardC, + BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), + ArgumentParser: parsers.NewCallArgsParser(), + ESDTTransferParser: esdtTransferParser, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.ESDTMetadataContinuousCleanupFlag), + } + txTypeHandler, _ := coordinator.NewTxTypeHandler(argTxTypeHandler) + + args := createArgsForTxProcessor() + args.Accounts = adb + args.ScProcessor = scProcessorMock + args.ShardCoordinator = shardC + args.TxTypeHandler = txTypeHandler + args.PubkeyConv = pubKeyConverter + args.ArgsParser = smartContract.NewArgumentParser() + args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV3Flag, common.FixRelayedMoveBalanceFlag) + args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ + ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { + return big.NewInt(int64(tx.GetGasPrice() * tx.GetGasLimit())) + }, + } + args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(args.EconomicsFee, args.ShardCoordinator) + execTx, _ := txproc.NewTxProcessor(args) + + txCopy := *tx + innerTx1 := &transaction.Transaction{ + Nonce: 0, + Value: big.NewInt(10), + RcvAddr: []byte("sDST"), + SndAddr: []byte("sender inner tx 1"), + GasPrice: 1, + GasLimit: 1, + RelayerAddr: txCopy.SndAddr, + } + innerTx2 := &transaction.Transaction{ + Nonce: 1, + Value: big.NewInt(10), + RcvAddr: []byte("sDST"), + SndAddr: []byte("sender inner tx 2"), + GasPrice: 1, + GasLimit: 1, + RelayerAddr: txCopy.SndAddr, + } + innerTx3 := &transaction.Transaction{ + Nonce: 0, + Value: big.NewInt(10), + RcvAddr: []byte("sDST"), + SndAddr: providedAddrFail, + GasPrice: 1, + GasLimit: 1, + RelayerAddr: txCopy.SndAddr, + } + + txCopy.InnerTransactions = append(txCopy.InnerTransactions, innerTx1, innerTx2, innerTx3) + returnCode, err := execTx.ProcessTransaction(&txCopy) + assert.Equal(t, process.ErrFailedTransaction, err) + assert.Equal(t, vmcommon.UserError, returnCode) + + for _, acnt := range accounts { + if string(acnt.AddressBytes()) == "sSRC" { + continue + } + assert.Equal(t, providedInitialBalance, acnt.GetBalance()) + } + }) + t.Run("one inner fails should return success on relayed", func(t *testing.T) { + t.Parallel() + + providedInitialBalance := big.NewInt(100) + pubKeyConverter := testscommon.NewPubkeyConverterMock(4) + + accounts := map[string]state.UserAccountHandler{} + adb := &stateMock.AccountsStub{} + adb.LoadAccountCalled = func(address []byte) (vmcommon.AccountHandler, error) { + acnt, exists := accounts[string(address)] + if !exists { + acnt = createUserAcc(address) + accounts[string(address)] = acnt + _ = acnt.AddToBalance(providedInitialBalance) + } + + return acnt, nil + } + + scProcessorMock := &testscommon.SCProcessorMock{} + shardC, _ := sharding.NewMultiShardCoordinator(1, 0) + esdtTransferParser, _ := parsers.NewESDTTransferParser(marshaller) + argTxTypeHandler := coordinator.ArgNewTxTypeHandler{ + PubkeyConverter: pubKeyConverter, + ShardCoordinator: shardC, + BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), + ArgumentParser: parsers.NewCallArgsParser(), + ESDTTransferParser: esdtTransferParser, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.ESDTMetadataContinuousCleanupFlag), + } + txTypeHandler, _ := coordinator.NewTxTypeHandler(argTxTypeHandler) + + args := createArgsForTxProcessor() + args.Accounts = adb + args.ScProcessor = scProcessorMock + args.ShardCoordinator = shardC + args.TxTypeHandler = txTypeHandler + args.PubkeyConv = pubKeyConverter + args.ArgsParser = smartContract.NewArgumentParser() + args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV3Flag, common.FixRelayedMoveBalanceFlag) + args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ + ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { + return big.NewInt(int64(tx.GetGasPrice() * tx.GetGasLimit())) + }, + } + args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(args.EconomicsFee, args.ShardCoordinator) + execTx, _ := txproc.NewTxProcessor(args) + + txCopy := *tx + usertTxCopy := *userTx // same inner tx twice should fail second time + txCopy.InnerTransactions = append(txCopy.InnerTransactions, &usertTxCopy) + returnCode, err := execTx.ProcessTransaction(&txCopy) + assert.NoError(t, err) + assert.Equal(t, vmcommon.Ok, returnCode) + }) t.Run("should work", func(t *testing.T) { t.Parallel() testProcessRelayedTransactionV3(t, tx, userTx.SndAddr, userTx.RcvAddr, nil, vmcommon.Ok) @@ -2218,7 +2394,7 @@ func testProcessRelayedTransactionV3( args.TxTypeHandler = txTypeHandler args.PubkeyConv = pubKeyConverter args.ArgsParser = smartContract.NewArgumentParser() - args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV3Flag) + args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV3Flag, common.FixRelayedMoveBalanceFlag) args.EconomicsFee = &economicsmocks.EconomicsHandlerMock{ ComputeTxFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { return big.NewInt(4) @@ -3524,3 +3700,15 @@ func TestTxProcessor_AddNonExecutableLog(t *testing.T) { assert.Equal(t, 3, numLogsSaved) }) } + +func TestTxProcessor_IsInterfaceNil(t *testing.T) { + t.Parallel() + + args := createArgsForTxProcessor() + args.RelayedTxV3Processor = nil + proc, _ := txproc.NewTxProcessor(args) + require.True(t, proc.IsInterfaceNil()) + + proc, _ = txproc.NewTxProcessor(createArgsForTxProcessor()) + require.False(t, proc.IsInterfaceNil()) +} From 404c3d384137f2e2c87a8dfffe154b35e6403a70 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 2 May 2024 16:16:34 +0300 Subject: [PATCH 214/503] fixes after review part 1 + added limitation on the number of inner txs --- config/config.go | 7 ++ factory/processing/processComponents.go | 7 +- .../multiShard/relayedTx/common.go | 35 +++++++-- .../relayedTx/edgecases/edgecases_test.go | 4 +- .../multiShard/relayedTx/relayedTx_test.go | 16 +++- integrationTests/testProcessorNode.go | 12 ++- process/errors.go | 9 +-- process/transaction/baseProcess.go | 16 ++-- .../interceptedTransaction_test.go | 6 +- process/transaction/relayedTxV3Processor.go | 47 ++++++++--- .../transaction/relayedTxV3Processor_test.go | 77 +++++++++++++++---- process/transaction/shardProcess.go | 24 +----- process/transaction/shardProcess_test.go | 18 ++++- testscommon/generalConfig.go | 3 + 14 files changed, 204 insertions(+), 77 deletions(-) diff --git a/config/config.go b/config/config.go index 472378d49fd..9e6cede073b 100644 --- a/config/config.go +++ b/config/config.go @@ -228,6 +228,8 @@ type Config struct { PeersRatingConfig PeersRatingConfig PoolsCleanersConfig PoolsCleanersConfig Redundancy RedundancyConfig + + RelayedTransactionConfig RelayedTransactionConfig } // PeersRatingConfig will hold settings related to peers rating @@ -639,3 +641,8 @@ type PoolsCleanersConfig struct { type RedundancyConfig struct { MaxRoundsOfInactivityAccepted int } + +// RelayedTransactionConfig represents the config options to be used for relayed transactions +type RelayedTransactionConfig struct { + MaxTransactionsAllowed int +} diff --git a/factory/processing/processComponents.go b/factory/processing/processComponents.go index 6cd922e9429..8e9341fe078 100644 --- a/factory/processing/processComponents.go +++ b/factory/processing/processComponents.go @@ -378,7 +378,12 @@ func (pcf *processComponentsFactory) Create() (*processComponents, error) { return nil, err } - relayedTxV3Processor, err := transaction.NewRelayedTxV3Processor(pcf.coreData.EconomicsData(), pcf.bootstrapComponents.ShardCoordinator()) + argsRelayedTxV3Processor := transaction.ArgRelayedTxV3Processor{ + EconomicsFee: pcf.coreData.EconomicsData(), + ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), + MaxTransactionsAllowed: pcf.config.RelayedTransactionConfig.MaxTransactionsAllowed, + } + relayedTxV3Processor, err := transaction.NewRelayedTxV3Processor(argsRelayedTxV3Processor) if err != nil { return nil, err } diff --git a/integrationTests/multiShard/relayedTx/common.go b/integrationTests/multiShard/relayedTx/common.go index 7b871a52ce2..3702f6ed109 100644 --- a/integrationTests/multiShard/relayedTx/common.go +++ b/integrationTests/multiShard/relayedTx/common.go @@ -14,7 +14,26 @@ import ( ) // CreateGeneralSetupForRelayTxTest will create the general setup for relayed transactions -func CreateGeneralSetupForRelayTxTest(relayedV3Test bool) ([]*integrationTests.TestProcessorNode, []int, []*integrationTests.TestWalletAccount, *integrationTests.TestWalletAccount) { +func CreateGeneralSetupForRelayTxTest() ([]*integrationTests.TestProcessorNode, []int, []*integrationTests.TestWalletAccount, *integrationTests.TestWalletAccount) { + initialVal := big.NewInt(1000000000) + nodes, idxProposers := createAndMintNodes(initialVal) + + players, relayerAccount := createAndMintPlayers(false, nodes, initialVal) + + return nodes, idxProposers, players, relayerAccount +} + +// CreateGeneralSetupForRelayedV3TxTest will create the general setup for relayed transactions v3 +func CreateGeneralSetupForRelayedV3TxTest() ([]*integrationTests.TestProcessorNode, []int, []*integrationTests.TestWalletAccount, *integrationTests.TestWalletAccount) { + initialVal := big.NewInt(1000000000) + nodes, idxProposers := createAndMintNodes(initialVal) + + players, relayerAccount := createAndMintPlayers(true, nodes, initialVal) + + return nodes, idxProposers, players, relayerAccount +} + +func createAndMintNodes(initialVal *big.Int) ([]*integrationTests.TestProcessorNode, []int) { numOfShards := 2 nodesPerShard := 2 numMetachainNodes := 1 @@ -33,17 +52,23 @@ func CreateGeneralSetupForRelayTxTest(relayedV3Test bool) ([]*integrationTests.T integrationTests.DisplayAndStartNodes(nodes) - initialVal := big.NewInt(1000000000) integrationTests.MintAllNodes(nodes, initialVal) + return nodes, idxProposers +} + +func createAndMintPlayers( + intraShard bool, + nodes []*integrationTests.TestProcessorNode, + initialVal *big.Int, +) ([]*integrationTests.TestWalletAccount, *integrationTests.TestWalletAccount) { relayerShard := uint32(0) numPlayers := 5 numShards := nodes[0].ShardCoordinator.NumberOfShards() players := make([]*integrationTests.TestWalletAccount, numPlayers) for i := 0; i < numPlayers; i++ { shardId := uint32(i) % numShards - // if the test is for relayed v3, force all senders to be in the same shard with the relayer - if relayedV3Test { + if intraShard { shardId = relayerShard } players[i] = integrationTests.CreateTestWalletAccount(nodes[0].ShardCoordinator, shardId) @@ -52,7 +77,7 @@ func CreateGeneralSetupForRelayTxTest(relayedV3Test bool) ([]*integrationTests.T relayerAccount := integrationTests.CreateTestWalletAccount(nodes[0].ShardCoordinator, relayerShard) integrationTests.MintAllPlayers(nodes, []*integrationTests.TestWalletAccount{relayerAccount}, initialVal) - return nodes, idxProposers, players, relayerAccount + return players, relayerAccount } // CreateAndSendRelayedAndUserTx will create and send a relayed user transaction diff --git a/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go b/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go index e2e6a3be043..6adf254433b 100644 --- a/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go +++ b/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go @@ -18,7 +18,7 @@ func TestRelayedTransactionInMultiShardEnvironmentWithNormalTxButWrongNonceShoul t.Skip("this is not a short test") } - nodes, idxProposers, players, relayer := relayedTx.CreateGeneralSetupForRelayTxTest(false) + nodes, idxProposers, players, relayer := relayedTx.CreateGeneralSetupForRelayTxTest() defer func() { for _, n := range nodes { n.Close() @@ -81,7 +81,7 @@ func TestRelayedTransactionInMultiShardEnvironmentWithNormalTxButWithTooMuchGas( t.Skip("this is not a short test") } - nodes, idxProposers, players, relayer := relayedTx.CreateGeneralSetupForRelayTxTest(false) + nodes, idxProposers, players, relayer := relayedTx.CreateGeneralSetupForRelayTxTest() defer func() { for _, n := range nodes { n.Close() diff --git a/integrationTests/multiShard/relayedTx/relayedTx_test.go b/integrationTests/multiShard/relayedTx/relayedTx_test.go index 50c95e520aa..327b72ca77d 100644 --- a/integrationTests/multiShard/relayedTx/relayedTx_test.go +++ b/integrationTests/multiShard/relayedTx/relayedTx_test.go @@ -197,7 +197,7 @@ func testRelayedTransactionInMultiShardEnvironmentWithNormalTx( t.Skip("this is not a short test") } - nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest(relayedV3Test) + nodes, idxProposers, players, relayer := createSetupForTest(relayedV3Test) defer func() { for _, n := range nodes { n.Close() @@ -261,7 +261,7 @@ func testRelayedTransactionInMultiShardEnvironmentWithSmartContractTX( t.Skip("this is not a short test") } - nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest(relayedV3Test) + nodes, idxProposers, players, relayer := createSetupForTest(relayedV3Test) defer func() { for _, n := range nodes { n.Close() @@ -356,7 +356,7 @@ func testRelayedTransactionInMultiShardEnvironmentWithESDTTX( t.Skip("this is not a short test") } - nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest(relayedV3Test) + nodes, idxProposers, players, relayer := createSetupForTest(relayedV3Test) defer func() { for _, n := range nodes { n.Close() @@ -454,7 +454,7 @@ func testRelayedTransactionInMultiShardEnvironmentWithAttestationContract( t.Skip("this is not a short test") } - nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest(relayedV3Test) + nodes, idxProposers, players, relayer := createSetupForTest(relayedV3Test) defer func() { for _, n := range nodes { n.Close() @@ -547,6 +547,14 @@ func testRelayedTransactionInMultiShardEnvironmentWithAttestationContract( } } +func createSetupForTest(relayedV3Test bool) ([]*integrationTests.TestProcessorNode, []int, []*integrationTests.TestWalletAccount, *integrationTests.TestWalletAccount) { + if relayedV3Test { + return CreateGeneralSetupForRelayedV3TxTest() + } + + return CreateGeneralSetupForRelayTxTest() +} + func checkAttestedPublicKeys( t *testing.T, node *integrationTests.TestProcessorNode, diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index 16940b5d628..61985e4ac31 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -1287,7 +1287,11 @@ func (tpn *TestProcessorNode) initInterceptors(heartbeatPk string) { cryptoComponents.BlKeyGen = tpn.OwnAccount.KeygenBlockSign cryptoComponents.TxKeyGen = tpn.OwnAccount.KeygenTxSign - relayedV3TxProcessor, _ := transaction.NewRelayedTxV3Processor(tpn.EconomicsData, tpn.ShardCoordinator) + relayedV3TxProcessor, _ := transaction.NewRelayedTxV3Processor(transaction.ArgRelayedTxV3Processor{ + EconomicsFee: tpn.EconomicsData, + ShardCoordinator: tpn.ShardCoordinator, + MaxTransactionsAllowed: 10, + }) if tpn.ShardCoordinator.SelfId() == core.MetachainShardId { argsEpochStart := &metachain.ArgsNewMetaEpochStartTrigger{ @@ -1719,7 +1723,11 @@ func (tpn *TestProcessorNode) initInnerProcessors(gasMap map[string]map[string]u tpn.ScProcessor, _ = processProxy.NewTestSmartContractProcessorProxy(argsNewScProcessor, tpn.EpochNotifier) - relayedV3TxProcessor, _ := transaction.NewRelayedTxV3Processor(tpn.EconomicsData, tpn.ShardCoordinator) + relayedV3TxProcessor, _ := transaction.NewRelayedTxV3Processor(transaction.ArgRelayedTxV3Processor{ + EconomicsFee: tpn.EconomicsData, + ShardCoordinator: tpn.ShardCoordinator, + MaxTransactionsAllowed: 10, + }) receiptsHandler, _ := tpn.InterimProcContainer.Get(dataBlock.ReceiptBlock) argsNewTxProcessor := transaction.ArgsNewTxProcessor{ diff --git a/process/errors.go b/process/errors.go index 107a04246ca..1359f5ca12e 100644 --- a/process/errors.go +++ b/process/errors.go @@ -1248,12 +1248,6 @@ var ErrRelayedTxV3RelayerMismatch = errors.New("relayed tx v3 relayer mismatch") // ErrRelayedTxV3GasLimitMismatch signals that relayed tx v3 gas limit is higher than user tx gas limit var ErrRelayedTxV3GasLimitMismatch = errors.New("relayed tx v3 gas limit mismatch") -// ErrSubsequentInnerTransactionFailed signals that one of the following inner transactions failed -var ErrSubsequentInnerTransactionFailed = errors.New("subsequent inner transaction failed") - -// ErrInvalidInnerTransactions signals that one or more inner transactions were invalid -var ErrInvalidInnerTransactions = errors.New("invalid inner transactions") - // ErrNilRelayedTxV3Processor signals that a nil relayed tx v3 processor has been provided var ErrNilRelayedTxV3Processor = errors.New("nil relayed tx v3 processor") @@ -1262,3 +1256,6 @@ var ErrRelayedTxV3SenderShardMismatch = errors.New("sender shard mismatch") // ErrNilRelayerAccount signals that a nil relayer accouont has been provided var ErrNilRelayerAccount = errors.New("nil relayer account") + +// ErrRelayedTxV3TooManyInnerTransactions signals that too many inner transactions were provided +var ErrRelayedTxV3TooManyInnerTransactions = errors.New("too many inner transactions") diff --git a/process/transaction/baseProcess.go b/process/transaction/baseProcess.go index 24e581031fa..499ed04321c 100644 --- a/process/transaction/baseProcess.go +++ b/process/transaction/baseProcess.go @@ -146,11 +146,7 @@ func (txProc *baseTxProcessor) checkTxValues( return process.ErrNotEnoughGasInUserTx } if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { - moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(tx) - gasToUse := tx.GetGasLimit() - moveBalanceGasLimit - moveBalanceUserFee := txProc.economicsFee.ComputeMoveBalanceFee(tx) - processingUserFee := txProc.economicsFee.ComputeFeeForProcessing(tx, gasToUse) - txFee = big.NewInt(0).Add(moveBalanceUserFee, processingUserFee) + txFee = txProc.computeTxFeeAfterMoveBalanceFix(tx) } else { txFee = txProc.economicsFee.ComputeFeeForProcessing(tx, tx.GasLimit) } @@ -180,6 +176,16 @@ func (txProc *baseTxProcessor) checkTxValues( return nil } +func (txProc *baseTxProcessor) computeTxFeeAfterMoveBalanceFix(tx *transaction.Transaction) *big.Int { + moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(tx) + gasToUse := tx.GetGasLimit() - moveBalanceGasLimit + moveBalanceUserFee := txProc.economicsFee.ComputeMoveBalanceFee(tx) + processingUserFee := txProc.economicsFee.ComputeFeeForProcessing(tx, gasToUse) + txFee := big.NewInt(0).Add(moveBalanceUserFee, processingUserFee) + + return txFee +} + func (txProc *baseTxProcessor) checkUserNames(tx *transaction.Transaction, acntSnd, acntDst state.UserAccountHandler) error { isUserNameWrong := len(tx.SndUserName) > 0 && !check.IfNil(acntSnd) && !bytes.Equal(tx.SndUserName, acntSnd.GetUserName()) diff --git a/process/transaction/interceptedTransaction_test.go b/process/transaction/interceptedTransaction_test.go index e53f8221135..983028e3ae1 100644 --- a/process/transaction/interceptedTransaction_test.go +++ b/process/transaction/interceptedTransaction_test.go @@ -199,7 +199,11 @@ func createInterceptedTxFromPlainTxWithArgParser(tx *dataTransaction.Transaction } txFeeHandler := createFreeTxFeeHandler() - relayedTxV3Processor, err := transaction.NewRelayedTxV3Processor(txFeeHandler, shardCoordinator) + relayedTxV3Processor, err := transaction.NewRelayedTxV3Processor(transaction.ArgRelayedTxV3Processor{ + EconomicsFee: txFeeHandler, + ShardCoordinator: shardCoordinator, + MaxTransactionsAllowed: 10, + }) if err != nil { return nil, err } diff --git a/process/transaction/relayedTxV3Processor.go b/process/transaction/relayedTxV3Processor.go index 1574ce41a86..431af9e795c 100644 --- a/process/transaction/relayedTxV3Processor.go +++ b/process/transaction/relayedTxV3Processor.go @@ -2,6 +2,7 @@ package transaction import ( "bytes" + "fmt" "math/big" "github.com/multiversx/mx-chain-core-go/core/check" @@ -10,28 +11,52 @@ import ( "github.com/multiversx/mx-chain-go/sharding" ) +const minTransactionsAllowed = 1 + +type ArgRelayedTxV3Processor struct { + EconomicsFee process.FeeHandler + ShardCoordinator sharding.Coordinator + MaxTransactionsAllowed int +} + type relayedTxV3Processor struct { - economicsFee process.FeeHandler - shardCoordinator sharding.Coordinator + economicsFee process.FeeHandler + shardCoordinator sharding.Coordinator + maxTransactionsAllowed int } // NewRelayedTxV3Processor returns a new instance of relayedTxV3Processor -func NewRelayedTxV3Processor(economicsFee process.FeeHandler, shardCoordinator sharding.Coordinator) (*relayedTxV3Processor, error) { - if check.IfNil(economicsFee) { - return nil, process.ErrNilEconomicsFeeHandler - } - if check.IfNil(shardCoordinator) { - return nil, process.ErrNilShardCoordinator +func NewRelayedTxV3Processor(args ArgRelayedTxV3Processor) (*relayedTxV3Processor, error) { + err := checkArgs(args) + if err != nil { + return nil, err } - return &relayedTxV3Processor{ - economicsFee: economicsFee, - shardCoordinator: shardCoordinator, + economicsFee: args.EconomicsFee, + shardCoordinator: args.ShardCoordinator, + maxTransactionsAllowed: args.MaxTransactionsAllowed, }, nil } +func checkArgs(args ArgRelayedTxV3Processor) error { + if check.IfNil(args.EconomicsFee) { + return process.ErrNilEconomicsFeeHandler + } + if check.IfNil(args.ShardCoordinator) { + return process.ErrNilShardCoordinator + } + if args.MaxTransactionsAllowed < minTransactionsAllowed { + return fmt.Errorf("%w for MaxTransactionsAllowed, provided %d, min expected %d", process.ErrInvalidValue, args.MaxTransactionsAllowed, minTransactionsAllowed) + } + + return nil +} + // CheckRelayedTx checks the relayed transaction and its inner transactions func (proc *relayedTxV3Processor) CheckRelayedTx(tx *transaction.Transaction) error { + if len(tx.InnerTransactions) > proc.maxTransactionsAllowed { + return process.ErrRelayedTxV3TooManyInnerTransactions + } if tx.GetValue().Cmp(big.NewInt(0)) != 0 { return process.ErrRelayedTxV3ZeroVal } diff --git a/process/transaction/relayedTxV3Processor_test.go b/process/transaction/relayedTxV3Processor_test.go index 6e83f4722c8..ed0de081bb4 100644 --- a/process/transaction/relayedTxV3Processor_test.go +++ b/process/transaction/relayedTxV3Processor_test.go @@ -2,7 +2,9 @@ package transaction_test import ( "bytes" + "errors" "math/big" + "strings" "testing" "github.com/multiversx/mx-chain-core-go/data" @@ -47,27 +49,49 @@ func getDefaultTx() *coreTransaction.Transaction { } } +func createMockArgRelayedTxV3Processor() transaction.ArgRelayedTxV3Processor { + return transaction.ArgRelayedTxV3Processor{ + EconomicsFee: &economicsmocks.EconomicsHandlerStub{}, + ShardCoordinator: &testscommon.ShardsCoordinatorMock{}, + MaxTransactionsAllowed: 10, + } +} + func TestNewRelayedTxV3Processor(t *testing.T) { t.Parallel() t.Run("nil economics fee should error", func(t *testing.T) { t.Parallel() - proc, err := transaction.NewRelayedTxV3Processor(nil, nil) + args := createMockArgRelayedTxV3Processor() + args.EconomicsFee = nil + proc, err := transaction.NewRelayedTxV3Processor(args) require.Nil(t, proc) require.Equal(t, process.ErrNilEconomicsFeeHandler, err) }) t.Run("nil shard coordinator should error", func(t *testing.T) { t.Parallel() - proc, err := transaction.NewRelayedTxV3Processor(&economicsmocks.EconomicsHandlerStub{}, nil) + args := createMockArgRelayedTxV3Processor() + args.ShardCoordinator = nil + proc, err := transaction.NewRelayedTxV3Processor(args) require.Nil(t, proc) require.Equal(t, process.ErrNilShardCoordinator, err) }) + t.Run("invalid max transactions allowed should error", func(t *testing.T) { + t.Parallel() + + args := createMockArgRelayedTxV3Processor() + args.MaxTransactionsAllowed = 0 + proc, err := transaction.NewRelayedTxV3Processor(args) + require.Nil(t, proc) + require.True(t, errors.Is(err, process.ErrInvalidValue)) + require.True(t, strings.Contains(err.Error(), "MaxTransactionsAllowed")) + }) t.Run("should work", func(t *testing.T) { t.Parallel() - proc, err := transaction.NewRelayedTxV3Processor(&economicsmocks.EconomicsHandlerStub{}, &testscommon.ShardsCoordinatorMock{}) + proc, err := transaction.NewRelayedTxV3Processor(createMockArgRelayedTxV3Processor()) require.NoError(t, err) require.NotNil(t, proc) }) @@ -76,20 +100,36 @@ func TestNewRelayedTxV3Processor(t *testing.T) { func TestRelayedTxV3Processor_IsInterfaceNil(t *testing.T) { t.Parallel() - proc, _ := transaction.NewRelayedTxV3Processor(nil, nil) + args := createMockArgRelayedTxV3Processor() + args.EconomicsFee = nil + proc, _ := transaction.NewRelayedTxV3Processor(args) require.True(t, proc.IsInterfaceNil()) - proc, _ = transaction.NewRelayedTxV3Processor(&economicsmocks.EconomicsHandlerStub{}, &testscommon.ShardsCoordinatorMock{}) + proc, _ = transaction.NewRelayedTxV3Processor(createMockArgRelayedTxV3Processor()) require.False(t, proc.IsInterfaceNil()) } func TestRelayedTxV3Processor_CheckRelayedTx(t *testing.T) { t.Parallel() + t.Run("invalid num of inner txs should error", func(t *testing.T) { + t.Parallel() + + tx := getDefaultTx() + args := createMockArgRelayedTxV3Processor() + args.MaxTransactionsAllowed = len(tx.InnerTransactions) - 1 + proc, err := transaction.NewRelayedTxV3Processor(args) + require.NoError(t, err) + + tx.Value = big.NewInt(1) + + err = proc.CheckRelayedTx(tx) + require.Equal(t, process.ErrRelayedTxV3TooManyInnerTransactions, err) + }) t.Run("value on relayed tx should error", func(t *testing.T) { t.Parallel() - proc, err := transaction.NewRelayedTxV3Processor(&economicsmocks.EconomicsHandlerStub{}, &testscommon.ShardsCoordinatorMock{}) + proc, err := transaction.NewRelayedTxV3Processor(createMockArgRelayedTxV3Processor()) require.NoError(t, err) tx := getDefaultTx() @@ -101,7 +141,7 @@ func TestRelayedTxV3Processor_CheckRelayedTx(t *testing.T) { t.Run("relayed tx not to self should error", func(t *testing.T) { t.Parallel() - proc, err := transaction.NewRelayedTxV3Processor(&economicsmocks.EconomicsHandlerStub{}, &testscommon.ShardsCoordinatorMock{}) + proc, err := transaction.NewRelayedTxV3Processor(createMockArgRelayedTxV3Processor()) require.NoError(t, err) tx := getDefaultTx() @@ -113,12 +153,13 @@ func TestRelayedTxV3Processor_CheckRelayedTx(t *testing.T) { t.Run("invalid gas limit should error", func(t *testing.T) { t.Parallel() - economicsFeeHandler := &economicsmocks.EconomicsHandlerStub{ + args := createMockArgRelayedTxV3Processor() + args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ ComputeGasLimitCalled: func(tx data.TransactionWithFeeHandler) uint64 { return minGasLimit }, } - proc, err := transaction.NewRelayedTxV3Processor(economicsFeeHandler, &testscommon.ShardsCoordinatorMock{}) + proc, err := transaction.NewRelayedTxV3Processor(args) require.NoError(t, err) tx := getDefaultTx() @@ -130,7 +171,7 @@ func TestRelayedTxV3Processor_CheckRelayedTx(t *testing.T) { t.Run("empty relayer on inner should error", func(t *testing.T) { t.Parallel() - proc, err := transaction.NewRelayedTxV3Processor(&economicsmocks.EconomicsHandlerStub{}, &testscommon.ShardsCoordinatorMock{}) + proc, err := transaction.NewRelayedTxV3Processor(createMockArgRelayedTxV3Processor()) require.NoError(t, err) tx := getDefaultTx() @@ -142,7 +183,7 @@ func TestRelayedTxV3Processor_CheckRelayedTx(t *testing.T) { t.Run("relayer mismatch on inner should error", func(t *testing.T) { t.Parallel() - proc, err := transaction.NewRelayedTxV3Processor(&economicsmocks.EconomicsHandlerStub{}, &testscommon.ShardsCoordinatorMock{}) + proc, err := transaction.NewRelayedTxV3Processor(createMockArgRelayedTxV3Processor()) require.NoError(t, err) tx := getDefaultTx() @@ -154,7 +195,7 @@ func TestRelayedTxV3Processor_CheckRelayedTx(t *testing.T) { t.Run("gas price mismatch on inner should error", func(t *testing.T) { t.Parallel() - proc, err := transaction.NewRelayedTxV3Processor(&economicsmocks.EconomicsHandlerStub{}, &testscommon.ShardsCoordinatorMock{}) + proc, err := transaction.NewRelayedTxV3Processor(createMockArgRelayedTxV3Processor()) require.NoError(t, err) tx := getDefaultTx() @@ -167,7 +208,8 @@ func TestRelayedTxV3Processor_CheckRelayedTx(t *testing.T) { t.Parallel() tx := getDefaultTx() - shardC := &testscommon.ShardsCoordinatorMock{ + args := createMockArgRelayedTxV3Processor() + args.ShardCoordinator = &testscommon.ShardsCoordinatorMock{ ComputeIdCalled: func(address []byte) uint32 { if bytes.Equal(address, tx.SndAddr) { return 0 @@ -176,7 +218,7 @@ func TestRelayedTxV3Processor_CheckRelayedTx(t *testing.T) { return 1 }, } - proc, err := transaction.NewRelayedTxV3Processor(&economicsmocks.EconomicsHandlerStub{}, shardC) + proc, err := transaction.NewRelayedTxV3Processor(args) require.NoError(t, err) err = proc.CheckRelayedTx(tx) @@ -185,7 +227,7 @@ func TestRelayedTxV3Processor_CheckRelayedTx(t *testing.T) { t.Run("should work", func(t *testing.T) { t.Parallel() - proc, err := transaction.NewRelayedTxV3Processor(&economicsmocks.EconomicsHandlerStub{}, &testscommon.ShardsCoordinatorMock{}) + proc, err := transaction.NewRelayedTxV3Processor(createMockArgRelayedTxV3Processor()) require.NoError(t, err) tx := getDefaultTx() @@ -197,12 +239,13 @@ func TestRelayedTxV3Processor_CheckRelayedTx(t *testing.T) { func TestRelayedTxV3Processor_ComputeRelayedTxFees(t *testing.T) { t.Parallel() - economicsFeeHandler := &economicsmocks.EconomicsHandlerStub{ + args := createMockArgRelayedTxV3Processor() + args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { return big.NewInt(int64(minGasLimit * tx.GetGasPrice())) }, } - proc, err := transaction.NewRelayedTxV3Processor(economicsFeeHandler, &testscommon.ShardsCoordinatorMock{}) + proc, err := transaction.NewRelayedTxV3Processor(args) require.NoError(t, err) tx := getDefaultTx() diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 1581e9dba53..6ba43330db6 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -306,11 +306,7 @@ func (txProc *txProcessor) executingFailedTransaction( txFee := txProc.economicsFee.ComputeFeeForProcessing(tx, tx.GasLimit) if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { - moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(tx) - gasToUse := tx.GetGasLimit() - moveBalanceGasLimit - moveBalanceUserFee := txProc.economicsFee.ComputeMoveBalanceFee(tx) - processingUserFee := txProc.economicsFee.ComputeFeeForProcessing(tx, gasToUse) - txFee = big.NewInt(0).Add(moveBalanceUserFee, processingUserFee) + txFee = txProc.computeTxFeeAfterMoveBalanceFix(tx) } err := acntSnd.SubFromBalance(txFee) if err != nil { @@ -404,11 +400,7 @@ func (txProc *txProcessor) processTxFee( if isUserTxOfRelayed { totalCost := txProc.economicsFee.ComputeFeeForProcessing(tx, tx.GasLimit) if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { - moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(tx) - gasToUse := tx.GetGasLimit() - moveBalanceGasLimit - moveBalanceUserFee := txProc.economicsFee.ComputeMoveBalanceFee(tx) - processingUserFee := txProc.economicsFee.ComputeFeeForProcessing(tx, gasToUse) - totalCost = big.NewInt(0).Add(moveBalanceUserFee, processingUserFee) + totalCost = txProc.computeTxFeeAfterMoveBalanceFix(tx) } err := acntSnd.SubFromBalance(totalCost) if err != nil { @@ -779,11 +771,7 @@ func (txProc *txProcessor) computeRelayedTxFees(tx, userTx *transaction.Transact relayerFee := txProc.economicsFee.ComputeMoveBalanceFee(tx) totalFee := txProc.economicsFee.ComputeTxFee(tx) if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { - moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(userTx) - gasToUse := userTx.GetGasLimit() - moveBalanceGasLimit - moveBalanceUserFee := txProc.economicsFee.ComputeMoveBalanceFee(userTx) - processingUserFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, gasToUse) - userFee := big.NewInt(0).Add(moveBalanceUserFee, processingUserFee) + userFee := txProc.computeTxFeeAfterMoveBalanceFix(userTx) totalFee = totalFee.Add(relayerFee, userFee) } @@ -819,11 +807,7 @@ func (txProc *txProcessor) removeValueAndConsumedFeeFromUser( consumedFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, userTx.GasLimit) if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { - moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(userTx) - gasToUse := userTx.GetGasLimit() - moveBalanceGasLimit - moveBalanceUserFee := txProc.economicsFee.ComputeMoveBalanceFee(userTx) - processingUserFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, gasToUse) - consumedFee = big.NewInt(0).Add(moveBalanceUserFee, processingUserFee) + consumedFee = txProc.computeTxFeeAfterMoveBalanceFix(userTx) } err = userAcnt.SubFromBalance(consumedFee) if err != nil { diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index e41c5849e3d..71891f3a7ba 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -2230,7 +2230,11 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { return big.NewInt(int64(tx.GetGasPrice() * tx.GetGasLimit())) }, } - args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(args.EconomicsFee, args.ShardCoordinator) + args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(txproc.ArgRelayedTxV3Processor{ + EconomicsFee: args.EconomicsFee, + ShardCoordinator: args.ShardCoordinator, + MaxTransactionsAllowed: 10, + }) execTx, _ := txproc.NewTxProcessor(args) txCopy := *tx @@ -2319,7 +2323,11 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { return big.NewInt(int64(tx.GetGasPrice() * tx.GetGasLimit())) }, } - args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(args.EconomicsFee, args.ShardCoordinator) + args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(txproc.ArgRelayedTxV3Processor{ + EconomicsFee: args.EconomicsFee, + ShardCoordinator: args.ShardCoordinator, + MaxTransactionsAllowed: 10, + }) execTx, _ := txproc.NewTxProcessor(args) txCopy := *tx @@ -2406,7 +2414,11 @@ func testProcessRelayedTransactionV3( return 4 }, } - args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(args.EconomicsFee, args.ShardCoordinator) + args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(txproc.ArgRelayedTxV3Processor{ + EconomicsFee: args.EconomicsFee, + ShardCoordinator: args.ShardCoordinator, + MaxTransactionsAllowed: 10, + }) execTx, _ := txproc.NewTxProcessor(args) diff --git a/testscommon/generalConfig.go b/testscommon/generalConfig.go index 06814edb1f5..00eff4fe61b 100644 --- a/testscommon/generalConfig.go +++ b/testscommon/generalConfig.go @@ -419,6 +419,9 @@ func GetGeneralConfig() config.Config { ResourceStats: config.ResourceStatsConfig{ RefreshIntervalInSec: 1, }, + RelayedTransactionConfig: config.RelayedTransactionConfig{ + MaxTransactionsAllowed: 10, + }, } } From afbe7c5c24ce2c4abfc0879d97e53cbc8b1a6969 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 7 May 2024 13:58:14 +0300 Subject: [PATCH 215/503] fixes after review part 2 --- api/groups/transactionGroup.go | 12 +- .../multiShard/relayedTx/relayedTx_test.go | 7 +- process/disabled/relayedTxV3Processor.go | 5 - process/interface.go | 1 - process/transaction/baseProcess.go | 14 ++- process/transaction/relayedTxV3Processor.go | 50 ++------ process/transaction/shardProcess.go | 112 +++--------------- process/transaction/shardProcess_test.go | 26 ++-- .../processMocks/relayedTxV3ProcessorMock.go | 13 +- 9 files changed, 72 insertions(+), 168 deletions(-) diff --git a/api/groups/transactionGroup.go b/api/groups/transactionGroup.go index f1bb3d9033b..1d63c00c8a4 100644 --- a/api/groups/transactionGroup.go +++ b/api/groups/transactionGroup.go @@ -411,8 +411,16 @@ func (tg *transactionGroup) sendMultipleTransactions(c *gin.Context) { newInnerTx, _, err := tg.createTransaction(innerTx, nil) if err != nil { - // if one of the inner txs is invalid, break the loop and move to the next transaction received - break + // if one of the inner txs is invalid, return bad request + c.JSON( + http.StatusBadRequest, + shared.GenericAPIResponse{ + Data: nil, + Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), err.Error()), + Code: shared.ReturnCodeInternalError, + }, + ) + return } innerTxs = append(innerTxs, newInnerTx) diff --git a/integrationTests/multiShard/relayedTx/relayedTx_test.go b/integrationTests/multiShard/relayedTx/relayedTx_test.go index 327b72ca77d..bd6b292c24d 100644 --- a/integrationTests/multiShard/relayedTx/relayedTx_test.go +++ b/integrationTests/multiShard/relayedTx/relayedTx_test.go @@ -116,8 +116,8 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing. innerTxs := []*transaction.Transaction{innerTx, innerTx2, innerTx3} - // relayer will consume gas for 2 move balances for 2 different senders + the gas for each transaction that succeeds - relayedTxGasLimit := minGasLimit * 5 + // relayer will consume first a move balance for each inner tx, then the specific gas for each inner tx + relayedTxGasLimit := minGasLimit * (len(innerTxs) * 2) relayedTx := generateTransaction(relayer.Bytes, 0, relayer.Bytes, big.NewInt(0), "", uint64(relayedTxGasLimit)) relayedTx.InnerTransactions = innerTxs @@ -130,8 +130,7 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing. relayerAccount, err := cs.GetAccount(relayer) require.NoError(t, err) - gasLimitForSucceededTxs := minGasLimit * 5 - expectedRelayerFee := big.NewInt(int64(minGasPrice * gasLimitForSucceededTxs)) + expectedRelayerFee := big.NewInt(int64(minGasPrice * relayedTxGasLimit)) assert.Equal(t, big.NewInt(0).Sub(initialBalance, expectedRelayerFee).String(), relayerAccount.Balance) senderAccount, err := cs.GetAccount(sender) diff --git a/process/disabled/relayedTxV3Processor.go b/process/disabled/relayedTxV3Processor.go index 5c9fdd2943f..16f333263ff 100644 --- a/process/disabled/relayedTxV3Processor.go +++ b/process/disabled/relayedTxV3Processor.go @@ -24,11 +24,6 @@ func (proc *relayedTxV3Processor) ComputeRelayedTxFees(_ *transaction.Transactio return big.NewInt(0), big.NewInt(0) } -// GetUniqueSendersRequiredFeesMap returns an empty map as it is disabled -func (proc *relayedTxV3Processor) GetUniqueSendersRequiredFeesMap(_ []*transaction.Transaction) map[string]*big.Int { - return make(map[string]*big.Int) -} - // IsInterfaceNil returns true if there is no value under the interface func (proc *relayedTxV3Processor) IsInterfaceNil() bool { return proc == nil diff --git a/process/interface.go b/process/interface.go index 7003d0c632d..a4b6e2c957e 100644 --- a/process/interface.go +++ b/process/interface.go @@ -1363,6 +1363,5 @@ type SentSignaturesTracker interface { type RelayedTxV3Processor interface { CheckRelayedTx(tx *transaction.Transaction) error ComputeRelayedTxFees(tx *transaction.Transaction) (*big.Int, *big.Int) - GetUniqueSendersRequiredFeesMap(innerTxs []*transaction.Transaction) map[string]*big.Int IsInterfaceNil() bool } diff --git a/process/transaction/baseProcess.go b/process/transaction/baseProcess.go index 499ed04321c..8b951d844da 100644 --- a/process/transaction/baseProcess.go +++ b/process/transaction/baseProcess.go @@ -145,11 +145,7 @@ func (txProc *baseTxProcessor) checkTxValues( if tx.GasLimit < txProc.economicsFee.ComputeGasLimit(tx) { return process.ErrNotEnoughGasInUserTx } - if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { - txFee = txProc.computeTxFeeAfterMoveBalanceFix(tx) - } else { - txFee = txProc.economicsFee.ComputeFeeForProcessing(tx, tx.GasLimit) - } + txFee = txProc.computeTxFee(tx) } else { txFee = txProc.economicsFee.ComputeTxFee(tx) } @@ -176,6 +172,14 @@ func (txProc *baseTxProcessor) checkTxValues( return nil } +func (txProc *baseTxProcessor) computeTxFee(tx *transaction.Transaction) *big.Int { + if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { + return txProc.computeTxFeeAfterMoveBalanceFix(tx) + } + + return txProc.economicsFee.ComputeFeeForProcessing(tx, tx.GasLimit) +} + func (txProc *baseTxProcessor) computeTxFeeAfterMoveBalanceFix(tx *transaction.Transaction) *big.Int { moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(tx) gasToUse := tx.GetGasLimit() - moveBalanceGasLimit diff --git a/process/transaction/relayedTxV3Processor.go b/process/transaction/relayedTxV3Processor.go index 431af9e795c..e46db781cf6 100644 --- a/process/transaction/relayedTxV3Processor.go +++ b/process/transaction/relayedTxV3Processor.go @@ -13,6 +13,7 @@ import ( const minTransactionsAllowed = 1 +// ArgRelayedTxV3Processor is the DTO used to create a new instance of relayedTxV3Processor type ArgRelayedTxV3Processor struct { EconomicsFee process.FeeHandler ShardCoordinator sharding.Coordinator @@ -91,68 +92,41 @@ func (proc *relayedTxV3Processor) CheckRelayedTx(tx *transaction.Transaction) er // ComputeRelayedTxFees returns the both the total fee for the entire relayed tx and the relayed only fee func (proc *relayedTxV3Processor) ComputeRelayedTxFees(tx *transaction.Transaction) (*big.Int, *big.Int) { - relayerMoveBalanceFee := proc.economicsFee.ComputeMoveBalanceFee(tx) - uniqueSenders := proc.GetUniqueSendersRequiredFeesMap(tx.InnerTransactions) + feesForInnerTxs := proc.getTotalFeesRequiredForInnerTxs(tx.InnerTransactions) - relayerFee := big.NewInt(0).Mul(relayerMoveBalanceFee, big.NewInt(int64(len(uniqueSenders)))) + relayerMoveBalanceFee := proc.economicsFee.ComputeMoveBalanceFee(tx) + relayerFee := big.NewInt(0).Mul(relayerMoveBalanceFee, big.NewInt(int64(len(tx.InnerTransactions)))) - totalFee := big.NewInt(0) - for _, fee := range uniqueSenders { - totalFee.Add(totalFee, fee) - } - totalFee.Add(totalFee, relayerFee) + totalFee := big.NewInt(0).Add(relayerFee, feesForInnerTxs) return relayerFee, totalFee } -// GetUniqueSendersRequiredFeesMap returns the map of unique inner transactions senders and the required fees for all transactions -func (proc *relayedTxV3Processor) GetUniqueSendersRequiredFeesMap(innerTxs []*transaction.Transaction) map[string]*big.Int { - uniqueSendersMap := make(map[string]*big.Int) +func (proc *relayedTxV3Processor) getTotalFeesRequiredForInnerTxs(innerTxs []*transaction.Transaction) *big.Int { + totalFees := big.NewInt(0) for _, innerTx := range innerTxs { - senderStr := string(innerTx.SndAddr) - _, exists := uniqueSendersMap[senderStr] - if !exists { - uniqueSendersMap[senderStr] = big.NewInt(0) - } - gasToUse := innerTx.GetGasLimit() - proc.economicsFee.ComputeGasLimit(innerTx) moveBalanceUserFee := proc.economicsFee.ComputeMoveBalanceFee(innerTx) processingUserFee := proc.economicsFee.ComputeFeeForProcessing(innerTx, gasToUse) innerTxFee := big.NewInt(0).Add(moveBalanceUserFee, processingUserFee) - uniqueSendersMap[senderStr].Add(uniqueSendersMap[senderStr], innerTxFee) + totalFees.Add(totalFees, innerTxFee) } - return uniqueSendersMap + return totalFees } func (proc *relayedTxV3Processor) computeRelayedTxMinGasLimit(tx *transaction.Transaction) uint64 { relayedTxGasLimit := proc.economicsFee.ComputeGasLimit(tx) - uniqueSenders := proc.getUniqueSendersRequiredGasLimitsMap(tx.InnerTransactions) - totalGasLimit := relayedTxGasLimit * uint64(len(uniqueSenders)) - for _, gasLimit := range uniqueSenders { - totalGasLimit += gasLimit + totalGasLimit := relayedTxGasLimit * uint64(len(tx.InnerTransactions)) + for _, innerTx := range tx.InnerTransactions { + totalGasLimit += innerTx.GasLimit } return totalGasLimit } -func (proc *relayedTxV3Processor) getUniqueSendersRequiredGasLimitsMap(innerTxs []*transaction.Transaction) map[string]uint64 { - uniqueSendersMap := make(map[string]uint64) - for _, innerTx := range innerTxs { - senderStr := string(innerTx.SndAddr) - _, exists := uniqueSendersMap[senderStr] - if !exists { - uniqueSendersMap[senderStr] = 0 - } - - uniqueSendersMap[senderStr] += innerTx.GasLimit - } - - return uniqueSendersMap -} - // IsInterfaceNil returns true if there is no value under the interface func (proc *relayedTxV3Processor) IsInterfaceNil() bool { return proc == nil diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 6ba43330db6..da98908ce94 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -304,10 +304,7 @@ func (txProc *txProcessor) executingFailedTransaction( return nil } - txFee := txProc.economicsFee.ComputeFeeForProcessing(tx, tx.GasLimit) - if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { - txFee = txProc.computeTxFeeAfterMoveBalanceFix(tx) - } + txFee := txProc.computeTxFee(tx) err := acntSnd.SubFromBalance(txFee) if err != nil { return err @@ -398,10 +395,8 @@ func (txProc *txProcessor) processTxFee( } if isUserTxOfRelayed { - totalCost := txProc.economicsFee.ComputeFeeForProcessing(tx, tx.GasLimit) - if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { - totalCost = txProc.computeTxFeeAfterMoveBalanceFix(tx) - } + totalCost := txProc.computeTxFee(tx) + err := acntSnd.SubFromBalance(totalCost) if err != nil { return nil, nil, err @@ -656,10 +651,10 @@ func (txProc *txProcessor) processRelayedTxV3( } // process fees on both relayer and sender - sendersBalancesSnapshot, err := txProc.processInnerTxsFeesAfterSnapshot(tx, relayerAcnt) + relayerFee, totalFee := txProc.relayedTxV3Processor.ComputeRelayedTxFees(tx) + err = txProc.processTxAtRelayer(relayerAcnt, totalFee, relayerFee, tx) if err != nil { - txProc.resetBalancesToSnapshot(sendersBalancesSnapshot) - return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, err) + return 0, err } innerTxs := tx.GetInnerTransactions() @@ -678,7 +673,7 @@ func (txProc *txProcessor) processRelayedTxV3( allUserTxsSucceeded := len(executedUserTxs) == len(innerTxs) && innerTxErr == nil && innerTxRetCode == vmcommon.Ok if !allUserTxsSucceeded { - log.Debug("failed to execute all inner transactions", "total", len(innerTxs), "executed transactions", len(executedUserTxs)) + log.Trace("failed to execute all inner transactions", "total", len(innerTxs), "executed transactions", len(executedUserTxs)) } return vmcommon.Ok, nil @@ -694,7 +689,13 @@ func (txProc *txProcessor) finishExecutionOfInnerTx( } if check.IfNil(acntSnd) { - return vmcommon.Ok, nil + return vmcommon.UserError, process.ErrRelayedTxV3SenderShardMismatch + } + + txFee := txProc.computeTxFee(innerTx) + err = txProc.addFeeAndValueToDest(acntSnd, tx, txFee) + if err != nil { + return vmcommon.UserError, err } return txProc.processUserTx(tx, innerTx, tx.Value, tx.Nonce) @@ -805,10 +806,8 @@ func (txProc *txProcessor) removeValueAndConsumedFeeFromUser( return err } - consumedFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, userTx.GasLimit) - if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { - consumedFee = txProc.computeTxFeeAfterMoveBalanceFix(userTx) - } + consumedFee := txProc.computeTxFee(userTx) + err = userAcnt.SubFromBalance(consumedFee) if err != nil { return err @@ -901,7 +900,7 @@ func (txProc *txProcessor) processUserTx( err.Error()) } - scrFromTx, err := txProc.makeSCRFromUserTx(userTx, relayerAdr, relayedTxValue, originalTxHash, false) + scrFromTx, err := txProc.makeSCRFromUserTx(userTx, relayerAdr, relayedTxValue, originalTxHash) if err != nil { return 0, err } @@ -1000,15 +999,10 @@ func (txProc *txProcessor) makeSCRFromUserTx( relayerAdr []byte, relayedTxValue *big.Int, txHash []byte, - isRevertSCR bool, ) (*smartContractResult.SmartContractResult, error) { - scrValue := tx.Value - if isRevertSCR { - scrValue = big.NewInt(0).Neg(tx.Value) - } scr := &smartContractResult.SmartContractResult{ Nonce: tx.Nonce, - Value: scrValue, + Value: tx.Value, RcvAddr: tx.RcvAddr, SndAddr: tx.SndAddr, RelayerAddr: relayerAdr, @@ -1120,76 +1114,6 @@ func isNonExecutableError(executionErr error) bool { errors.Is(executionErr, process.ErrTransactionNotExecutable) } -func (txProc *txProcessor) processInnerTxsFeesAfterSnapshot(tx *transaction.Transaction, relayerAcnt state.UserAccountHandler) (map[state.UserAccountHandler]*big.Int, error) { - relayerFee, totalFee := txProc.relayedTxV3Processor.ComputeRelayedTxFees(tx) - err := txProc.processTxAtRelayer(relayerAcnt, totalFee, relayerFee, tx) - if err != nil { - return make(map[state.UserAccountHandler]*big.Int), err - } - - uniqueSendersMap := txProc.relayedTxV3Processor.GetUniqueSendersRequiredFeesMap(tx.InnerTransactions) - uniqueSendersSlice := mapToSlice(uniqueSendersMap) - sendersBalancesSnapshot := make(map[state.UserAccountHandler]*big.Int, len(uniqueSendersMap)) - var lastTransferErr error - for _, uniqueSender := range uniqueSendersSlice { - totalFeesForSender := uniqueSendersMap[uniqueSender] - senderAcnt, prevBalanceForSender, err := txProc.addFeesToDest([]byte(uniqueSender), totalFeesForSender) - if err != nil { - lastTransferErr = err - break - } - - sendersBalancesSnapshot[senderAcnt] = prevBalanceForSender - } - - return sendersBalancesSnapshot, lastTransferErr -} - -func (txProc *txProcessor) addFeesToDest(dstAddr []byte, feesForAllInnerTxs *big.Int) (state.UserAccountHandler, *big.Int, error) { - acntDst, err := txProc.getAccountFromAddress(dstAddr) - if err != nil { - return nil, nil, err - } - - if check.IfNil(acntDst) { - return nil, nil, nil - } - - prevBalance := acntDst.GetBalance() - err = acntDst.AddToBalance(feesForAllInnerTxs) - if err != nil { - return nil, nil, err - } - - return acntDst, prevBalance, txProc.accounts.SaveAccount(acntDst) -} - -func (txProc *txProcessor) resetBalancesToSnapshot(snapshot map[state.UserAccountHandler]*big.Int) { - for acnt, prevBalance := range snapshot { - currentBalance := acnt.GetBalance() - diff := big.NewInt(0).Sub(currentBalance, prevBalance) - err := acnt.SubFromBalance(diff) - if err != nil { - log.Warn("could not reset sender to snapshot", "sender", txProc.pubkeyConv.SilentEncode(acnt.AddressBytes(), log)) - continue - } - - err = txProc.accounts.SaveAccount(acnt) - if err != nil { - log.Warn("could not save account while resetting sender to snapshot", "sender", txProc.pubkeyConv.SilentEncode(acnt.AddressBytes(), log)) - } - } -} - -func mapToSlice(initialMap map[string]*big.Int) []string { - newSlice := make([]string, 0, len(initialMap)) - for mapKey := range initialMap { - newSlice = append(newSlice, mapKey) - } - - return newSlice -} - // IsInterfaceNil returns true if there is no value under the interface func (txProc *txProcessor) IsInterfaceNil() bool { return txProc == nil diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index 71891f3a7ba..b4e3771233b 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -2176,7 +2176,7 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { txCopy.GasLimit = userTx.GasLimit - 1 testProcessRelayedTransactionV3(t, &txCopy, userTx.SndAddr, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) }) - t.Run("failure to add fees on destination should revert to snapshot and should error", func(t *testing.T) { + t.Run("failure to add fees on destination should skip transaction and continue", func(t *testing.T) { t.Parallel() providedAddrFail := []byte("fail addr") @@ -2248,7 +2248,7 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { RelayerAddr: txCopy.SndAddr, } innerTx2 := &transaction.Transaction{ - Nonce: 1, + Nonce: 0, Value: big.NewInt(10), RcvAddr: []byte("sDST"), SndAddr: []byte("sender inner tx 2"), @@ -2266,16 +2266,26 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { RelayerAddr: txCopy.SndAddr, } - txCopy.InnerTransactions = append(txCopy.InnerTransactions, innerTx1, innerTx2, innerTx3) + txCopy.InnerTransactions = []*transaction.Transaction{innerTx1, innerTx2, innerTx3} returnCode, err := execTx.ProcessTransaction(&txCopy) - assert.Equal(t, process.ErrFailedTransaction, err) - assert.Equal(t, vmcommon.UserError, returnCode) + assert.NoError(t, err) + assert.Equal(t, vmcommon.Ok, returnCode) + expectedBalance := providedInitialBalance for _, acnt := range accounts { - if string(acnt.AddressBytes()) == "sSRC" { - continue + switch string(acnt.AddressBytes()) { + case "sSRC": + continue // relayer + case "sDST": + expectedBalance = big.NewInt(120) // 2 successful txs received + case "sender inner tx 1": + case "sender inner tx 2": + expectedBalance = big.NewInt(90) // one successful tx sent from each + default: + assert.Fail(t, "should not be other participants") } - assert.Equal(t, providedInitialBalance, acnt.GetBalance()) + + assert.Equal(t, expectedBalance, acnt.GetBalance(), fmt.Sprintf("checks failed for address: %s", string(acnt.AddressBytes()))) } }) t.Run("one inner fails should return success on relayed", func(t *testing.T) { diff --git a/testscommon/processMocks/relayedTxV3ProcessorMock.go b/testscommon/processMocks/relayedTxV3ProcessorMock.go index 2d2a0655f36..287adbb35a0 100644 --- a/testscommon/processMocks/relayedTxV3ProcessorMock.go +++ b/testscommon/processMocks/relayedTxV3ProcessorMock.go @@ -8,9 +8,8 @@ import ( // RelayedTxV3ProcessorMock - type RelayedTxV3ProcessorMock struct { - ComputeRelayedTxFeesCalled func(tx *transaction.Transaction) (*big.Int, *big.Int) - GetUniqueSendersRequiredFeesMapCalled func(innerTxs []*transaction.Transaction) map[string]*big.Int - CheckRelayedTxCalled func(tx *transaction.Transaction) error + ComputeRelayedTxFeesCalled func(tx *transaction.Transaction) (*big.Int, *big.Int) + CheckRelayedTxCalled func(tx *transaction.Transaction) error } // ComputeRelayedTxFees - @@ -21,14 +20,6 @@ func (mock *RelayedTxV3ProcessorMock) ComputeRelayedTxFees(tx *transaction.Trans return nil, nil } -// GetUniqueSendersRequiredFeesMap - -func (mock *RelayedTxV3ProcessorMock) GetUniqueSendersRequiredFeesMap(innerTxs []*transaction.Transaction) map[string]*big.Int { - if mock.GetUniqueSendersRequiredFeesMapCalled != nil { - return mock.GetUniqueSendersRequiredFeesMapCalled(innerTxs) - } - return nil -} - // CheckRelayedTx - func (mock *RelayedTxV3ProcessorMock) CheckRelayedTx(tx *transaction.Transaction) error { if mock.CheckRelayedTxCalled != nil { From d23be9c2f1246e0110d1880e8b96dddc151d2ef0 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 7 May 2024 15:26:03 +0300 Subject: [PATCH 216/503] fix tests --- process/transaction/shardProcess_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index b4e3771233b..59959a082b8 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -2278,8 +2278,7 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { continue // relayer case "sDST": expectedBalance = big.NewInt(120) // 2 successful txs received - case "sender inner tx 1": - case "sender inner tx 2": + case "sender inner tx 1", "sender inner tx 2": expectedBalance = big.NewInt(90) // one successful tx sent from each default: assert.Fail(t, "should not be other participants") From 6975c191f35c7d7edf310d54355111814d0154d8 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 8 May 2024 10:41:11 +0300 Subject: [PATCH 217/503] moved the test with chain simulator in the proper package --- .../relayedTx/relayedTx_test.go | 146 ++++++++++++++++++ .../multiShard/relayedTx/relayedTx_test.go | 134 ---------------- 2 files changed, 146 insertions(+), 134 deletions(-) create mode 100644 integrationTests/chainSimulator/relayedTx/relayedTx_test.go diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go new file mode 100644 index 00000000000..edd5eb245e7 --- /dev/null +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -0,0 +1,146 @@ +package relayedTx + +import ( + "math/big" + "testing" + "time" + + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/node/chainSimulator" + "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" + "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +const ( + defaultPathToInitialConfig = "../../../cmd/node/config/" + minGasPrice = 1_000_000_000 + minGasLimit = 50_000 + txVersion = 2 + mockTxSignature = "sig" + maxNumOfBlocksToGenerateWhenExecutingTx = 10 + numOfBlocksToWaitForCrossShardSCR = 5 +) + +var oneEGLD = big.NewInt(1000000000000000000) + +func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 30, + } + + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.RelayedTransactionsV3EnableEpoch = 1 + cfg.EpochConfig.EnableEpochs.FixRelayedMoveBalanceEnableEpoch = 1 + }, + }) + require.NoError(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + err = cs.GenerateBlocksUntilEpochIsReached(1) + require.NoError(t, err) + + initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(10)) + relayer, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + sender, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + receiver, err := cs.GenerateAndMintWalletAddress(1, big.NewInt(0)) + require.NoError(t, err) + + innerTx := generateTransaction(sender.Bytes, 0, receiver.Bytes, oneEGLD, "", minGasLimit) + innerTx.RelayerAddr = relayer.Bytes + + sender2, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + receiver2, err := cs.GenerateAndMintWalletAddress(0, big.NewInt(0)) + require.NoError(t, err) + + innerTx2 := generateTransaction(sender2.Bytes, 0, receiver2.Bytes, oneEGLD, "", minGasLimit) + innerTx2.RelayerAddr = relayer.Bytes + + // innerTx3Failure should fail due to less gas limit + data := "gas limit is not enough" + innerTx3Failure := generateTransaction(sender.Bytes, 1, receiver2.Bytes, oneEGLD, data, minGasLimit) + innerTx3Failure.RelayerAddr = relayer.Bytes + + innerTx3 := generateTransaction(sender.Bytes, 1, receiver2.Bytes, oneEGLD, "", minGasLimit) + innerTx3.RelayerAddr = relayer.Bytes + + innerTxs := []*transaction.Transaction{innerTx, innerTx2, innerTx3} + + // relayer will consume first a move balance for each inner tx, then the specific gas for each inner tx + relayedTxGasLimit := minGasLimit * (len(innerTxs) * 2) + relayedTx := generateTransaction(relayer.Bytes, 0, relayer.Bytes, big.NewInt(0), "", uint64(relayedTxGasLimit)) + relayedTx.InnerTransactions = innerTxs + + _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + // generate few more blocks for the cross shard scrs to be done + err = cs.GenerateBlocks(numOfBlocksToWaitForCrossShardSCR) + require.NoError(t, err) + + relayerAccount, err := cs.GetAccount(relayer) + require.NoError(t, err) + expectedRelayerFee := big.NewInt(int64(minGasPrice * relayedTxGasLimit)) + assert.Equal(t, big.NewInt(0).Sub(initialBalance, expectedRelayerFee).String(), relayerAccount.Balance) + + senderAccount, err := cs.GetAccount(sender) + require.NoError(t, err) + assert.Equal(t, big.NewInt(0).Sub(initialBalance, big.NewInt(0).Mul(oneEGLD, big.NewInt(2))).String(), senderAccount.Balance) + + sender2Account, err := cs.GetAccount(sender2) + require.NoError(t, err) + assert.Equal(t, big.NewInt(0).Sub(initialBalance, oneEGLD).String(), sender2Account.Balance) + + receiverAccount, err := cs.GetAccount(receiver) + require.NoError(t, err) + assert.Equal(t, oneEGLD.String(), receiverAccount.Balance) + + receiver2Account, err := cs.GetAccount(receiver2) + require.NoError(t, err) + assert.Equal(t, big.NewInt(0).Mul(oneEGLD, big.NewInt(2)).String(), receiver2Account.Balance) +} + +func generateTransaction(sender []byte, nonce uint64, receiver []byte, value *big.Int, data string, gasLimit uint64) *transaction.Transaction { + return &transaction.Transaction{ + Nonce: nonce, + Value: value, + SndAddr: sender, + RcvAddr: receiver, + Data: []byte(data), + GasLimit: gasLimit, + GasPrice: minGasPrice, + ChainID: []byte(configs.ChainID), + Version: txVersion, + Signature: []byte(mockTxSignature), + } +} diff --git a/integrationTests/multiShard/relayedTx/relayedTx_test.go b/integrationTests/multiShard/relayedTx/relayedTx_test.go index bd6b292c24d..8c6961087ca 100644 --- a/integrationTests/multiShard/relayedTx/relayedTx_test.go +++ b/integrationTests/multiShard/relayedTx/relayedTx_test.go @@ -9,12 +9,8 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/esdt" "github.com/multiversx/mx-chain-core-go/data/transaction" - "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests" "github.com/multiversx/mx-chain-go/integrationTests/vm/wasm" - "github.com/multiversx/mx-chain-go/node/chainSimulator" - "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" - "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/process" vmFactory "github.com/multiversx/mx-chain-go/process/factory" "github.com/multiversx/mx-chain-go/process/smartContract/hooks" @@ -25,18 +21,6 @@ import ( "github.com/stretchr/testify/require" ) -const ( - defaultPathToInitialConfig = "../../../cmd/node/config/" - minGasPrice = 1_000_000_000 - minGasLimit = 50_000 - txVersion = 2 - mockTxSignature = "sig" - maxNumOfBlocksToGenerateWhenExecutingTx = 10 - numOfBlocksToWaitForCrossShardSCR = 5 -) - -var oneEGLD = big.NewInt(1000000000000000000) - type createAndSendRelayedAndUserTxFuncType = func( nodes []*integrationTests.TestProcessorNode, relayer *integrationTests.TestWalletAccount, @@ -47,124 +31,6 @@ type createAndSendRelayedAndUserTxFuncType = func( txData []byte, ) (*transaction.Transaction, *transaction.Transaction) -func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing.T) { - if testing.Short() { - t.Skip("this is not a short test") - } - - roundDurationInMillis := uint64(6000) - roundsPerEpoch := core.OptionalUint64{ - HasValue: true, - Value: 30, - } - - cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, - AlterConfigsFunction: func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.RelayedTransactionsV3EnableEpoch = 1 - cfg.EpochConfig.EnableEpochs.FixRelayedMoveBalanceEnableEpoch = 1 - }, - }) - require.NoError(t, err) - require.NotNil(t, cs) - - defer cs.Close() - - err = cs.GenerateBlocksUntilEpochIsReached(1) - require.NoError(t, err) - - initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(10)) - relayer, err := cs.GenerateAndMintWalletAddress(0, initialBalance) - require.NoError(t, err) - - sender, err := cs.GenerateAndMintWalletAddress(0, initialBalance) - require.NoError(t, err) - - receiver, err := cs.GenerateAndMintWalletAddress(1, big.NewInt(0)) - require.NoError(t, err) - - innerTx := generateTransaction(sender.Bytes, 0, receiver.Bytes, oneEGLD, "", minGasLimit) - innerTx.RelayerAddr = relayer.Bytes - - sender2, err := cs.GenerateAndMintWalletAddress(0, initialBalance) - require.NoError(t, err) - - receiver2, err := cs.GenerateAndMintWalletAddress(0, big.NewInt(0)) - require.NoError(t, err) - - innerTx2 := generateTransaction(sender2.Bytes, 0, receiver2.Bytes, oneEGLD, "", minGasLimit) - innerTx2.RelayerAddr = relayer.Bytes - - // innerTx3Failure should fail due to less gas limit - data := "gas limit is not enough" - innerTx3Failure := generateTransaction(sender.Bytes, 1, receiver2.Bytes, oneEGLD, data, minGasLimit) - innerTx3Failure.RelayerAddr = relayer.Bytes - - innerTx3 := generateTransaction(sender.Bytes, 1, receiver2.Bytes, oneEGLD, "", minGasLimit) - innerTx3.RelayerAddr = relayer.Bytes - - innerTxs := []*transaction.Transaction{innerTx, innerTx2, innerTx3} - - // relayer will consume first a move balance for each inner tx, then the specific gas for each inner tx - relayedTxGasLimit := minGasLimit * (len(innerTxs) * 2) - relayedTx := generateTransaction(relayer.Bytes, 0, relayer.Bytes, big.NewInt(0), "", uint64(relayedTxGasLimit)) - relayedTx.InnerTransactions = innerTxs - - _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) - require.NoError(t, err) - - // generate few more blocks for the cross shard scrs to be done - err = cs.GenerateBlocks(numOfBlocksToWaitForCrossShardSCR) - require.NoError(t, err) - - relayerAccount, err := cs.GetAccount(relayer) - require.NoError(t, err) - expectedRelayerFee := big.NewInt(int64(minGasPrice * relayedTxGasLimit)) - assert.Equal(t, big.NewInt(0).Sub(initialBalance, expectedRelayerFee).String(), relayerAccount.Balance) - - senderAccount, err := cs.GetAccount(sender) - require.NoError(t, err) - assert.Equal(t, big.NewInt(0).Sub(initialBalance, big.NewInt(0).Mul(oneEGLD, big.NewInt(2))).String(), senderAccount.Balance) - - sender2Account, err := cs.GetAccount(sender2) - require.NoError(t, err) - assert.Equal(t, big.NewInt(0).Sub(initialBalance, oneEGLD).String(), sender2Account.Balance) - - receiverAccount, err := cs.GetAccount(receiver) - require.NoError(t, err) - assert.Equal(t, oneEGLD.String(), receiverAccount.Balance) - - receiver2Account, err := cs.GetAccount(receiver2) - require.NoError(t, err) - assert.Equal(t, big.NewInt(0).Mul(oneEGLD, big.NewInt(2)).String(), receiver2Account.Balance) -} - -func generateTransaction(sender []byte, nonce uint64, receiver []byte, value *big.Int, data string, gasLimit uint64) *transaction.Transaction { - return &transaction.Transaction{ - Nonce: nonce, - Value: value, - SndAddr: sender, - RcvAddr: receiver, - Data: []byte(data), - GasLimit: gasLimit, - GasPrice: minGasPrice, - ChainID: []byte(configs.ChainID), - Version: txVersion, - Signature: []byte(mockTxSignature), - } -} - func TestRelayedTransactionInMultiShardEnvironmentWithNormalTx(t *testing.T) { t.Run("relayed v1", testRelayedTransactionInMultiShardEnvironmentWithNormalTx(CreateAndSendRelayedAndUserTx, false)) t.Run("relayed v3", testRelayedTransactionInMultiShardEnvironmentWithNormalTx(CreateAndSendRelayedAndUserTxV3, true)) From 74f63b51619e137944cd99f3a1ef7a614cd21b4a Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Thu, 9 May 2024 10:37:58 +0300 Subject: [PATCH 218/503] other fixes --- node/chainSimulator/chainSimulator.go | 4 ++-- .../components/testOnlyProcessingNode_test.go | 16 +++++++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index 98ad37b6a42..b9efe1eeaf0 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -114,9 +114,9 @@ func (s *simulator) createChainHandlers(args ArgsChainSimulator) error { return err } - for idx := 0; idx < int(args.NumOfShards)+1; idx++ { + for idx := -1; idx < int(args.NumOfShards); idx++ { shardIDStr := fmt.Sprintf("%d", idx) - if idx == int(args.NumOfShards) { + if idx == -1 { shardIDStr = "metachain" } diff --git a/node/chainSimulator/components/testOnlyProcessingNode_test.go b/node/chainSimulator/components/testOnlyProcessingNode_test.go index e66d3fe4a50..b82864cd6ac 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode_test.go +++ b/node/chainSimulator/components/testOnlyProcessingNode_test.go @@ -41,13 +41,15 @@ func createMockArgsTestOnlyProcessingNode(t *testing.T) ArgsTestOnlyProcessingNo GasScheduleFilename: outputConfigs.GasScheduleFilename, NumShards: 3, - SyncedBroadcastNetwork: NewSyncedBroadcastNetwork(), - ChanStopNodeProcess: make(chan endProcess.ArgEndProcess), - APIInterface: api.NewNoApiInterface(), - ShardIDStr: "0", - RoundDurationInMillis: 6000, - MinNodesMeta: 1, - MinNodesPerShard: 1, + SyncedBroadcastNetwork: NewSyncedBroadcastNetwork(), + ChanStopNodeProcess: make(chan endProcess.ArgEndProcess), + APIInterface: api.NewNoApiInterface(), + ShardIDStr: "0", + RoundDurationInMillis: 6000, + MinNodesMeta: 1, + MinNodesPerShard: 1, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, } } From cc2f3a8f167f5ea4474c9b903d2b987e24b8c828 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Thu, 9 May 2024 10:57:26 +0300 Subject: [PATCH 219/503] unit tests fixes --- .../components/coreComponents_test.go | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/node/chainSimulator/components/coreComponents_test.go b/node/chainSimulator/components/coreComponents_test.go index 619eb9d3a2e..f8fc663fa64 100644 --- a/node/chainSimulator/components/coreComponents_test.go +++ b/node/chainSimulator/components/coreComponents_test.go @@ -5,8 +5,9 @@ import ( "testing" "github.com/multiversx/mx-chain-core-go/data/endProcess" - "github.com/multiversx/mx-chain-go/config" "github.com/stretchr/testify/require" + + "github.com/multiversx/mx-chain-go/config" ) func createArgsCoreComponentsHolder() ArgsCoreComponentsHolder { @@ -124,15 +125,17 @@ func createArgsCoreComponentsHolder() ArgsCoreComponentsHolder { }, }, }, - ChanStopNodeProcess: make(chan endProcess.ArgEndProcess), - InitialRound: 0, - NodesSetupPath: "../../../sharding/mock/testdata/nodesSetupMock.json", - GasScheduleFilename: "../../../cmd/node/config/gasSchedules/gasScheduleV7.toml", - NumShards: 3, - WorkingDir: ".", - MinNodesPerShard: 1, - MinNodesMeta: 1, - RoundDurationInMs: 6000, + ChanStopNodeProcess: make(chan endProcess.ArgEndProcess), + InitialRound: 0, + NodesSetupPath: "../../../sharding/mock/testdata/nodesSetupMock.json", + GasScheduleFilename: "../../../cmd/node/config/gasSchedules/gasScheduleV7.toml", + NumShards: 3, + WorkingDir: ".", + MinNodesPerShard: 1, + MinNodesMeta: 1, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + RoundDurationInMs: 6000, } } From 0ddca8874d012a4545713160716894bedfa26f64 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 9 May 2024 15:08:17 +0300 Subject: [PATCH 220/503] updated dependencies after merges + fixes --- .../heartbeat/heartbeatV2Components_test.go | 31 ------------ go.mod | 24 +++++----- go.sum | 48 +++++++++---------- .../components/syncedMessenger.go | 5 -- .../components/syncedMessenger_test.go | 1 - node/node_test.go | 4 +- p2p/disabled/networkMessenger.go | 5 -- p2p/interface.go | 3 -- p2p/mock/peerTopicNotifierStub.go | 20 -------- testscommon/p2pmocks/messengerStub.go | 10 ---- 10 files changed, 38 insertions(+), 113 deletions(-) delete mode 100644 p2p/mock/peerTopicNotifierStub.go diff --git a/factory/heartbeat/heartbeatV2Components_test.go b/factory/heartbeat/heartbeatV2Components_test.go index 6b5088cab5b..9a0eb3b14e3 100644 --- a/factory/heartbeat/heartbeatV2Components_test.go +++ b/factory/heartbeat/heartbeatV2Components_test.go @@ -11,7 +11,6 @@ import ( errorsMx "github.com/multiversx/mx-chain-go/errors" heartbeatComp "github.com/multiversx/mx-chain-go/factory/heartbeat" testsMocks "github.com/multiversx/mx-chain-go/integrationTests/mock" - "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/bootstrapMocks" @@ -473,36 +472,6 @@ func TestHeartbeatV2Components_Create(t *testing.T) { assert.Nil(t, hc) assert.Error(t, err) }) - t.Run("NewCrossShardPeerTopicNotifier fails should error", func(t *testing.T) { - t.Parallel() - - args := createMockHeartbeatV2ComponentsFactoryArgs() - processComp := args.ProcessComponents - cnt := 0 - args.ProcessComponents = &testsMocks.ProcessComponentsStub{ - NodesCoord: processComp.NodesCoordinator(), - EpochTrigger: processComp.EpochStartTrigger(), - EpochNotifier: processComp.EpochStartNotifier(), - NodeRedundancyHandlerInternal: processComp.NodeRedundancyHandler(), - HardforkTriggerField: processComp.HardforkTrigger(), - MainPeerMapper: processComp.PeerShardMapper(), - FullArchivePeerMapper: processComp.FullArchivePeerShardMapper(), - ShardCoordinatorCalled: func() sharding.Coordinator { - cnt++ - if cnt > 3 { - return nil - } - return processComp.ShardCoordinator() - }, - } - hcf, err := heartbeatComp.NewHeartbeatV2ComponentsFactory(args) - assert.NotNil(t, hcf) - assert.NoError(t, err) - - hc, err := hcf.Create() - assert.Nil(t, hc) - assert.Error(t, err) - }) t.Run("should work", func(t *testing.T) { t.Parallel() diff --git a/go.mod b/go.mod index 3bdbf023722..e70e37f4219 100644 --- a/go.mod +++ b/go.mod @@ -14,18 +14,18 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 - github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240321151517-2fffad77c605 - github.com/multiversx/mx-chain-core-go v1.2.20-0.20240328090024-e88291d59ace - github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 - github.com/multiversx/mx-chain-es-indexer-go v1.4.20-0.20240228094052-28a36809b9b8 - github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c - github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 - github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474 - github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240424111748-6dfa8aa14813 - github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240429094120-31dea4df3221 - github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240424112443-1a66307bc44e - github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240424112610-ab7b9e5829bd - github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240424113019-3a7d2b215137 + github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e + github.com/multiversx/mx-chain-core-go v1.2.21-0.20240508071047-fefea5737840 + github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df + github.com/multiversx/mx-chain-es-indexer-go v1.7.1-0.20240509104512-25512675833d + github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 + github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 + github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f + github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240509103544-247ce5639c7a + github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1 + github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b + github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240509104009-598a37ff36b9 + github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98-0.20240509104102-2a6a709b4041 github.com/pelletier/go-toml v1.9.3 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.14.0 diff --git a/go.sum b/go.sum index a06d6c94a56..185994c8e4f 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.13-0.20240321151517-2fffad77c605 h1:WYPdDmxL5rk9O6wUYVW4Fpw/QtwkWiIzFHeH2F5Zap4= -github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240321151517-2fffad77c605/go.mod h1:wUM/1NFfgeTjovQMaaXghynwXgOyoPchMquu2wnCHz8= -github.com/multiversx/mx-chain-core-go v1.2.20-0.20240328090024-e88291d59ace h1:sCXg0IlWmi0k5mC3BmUVCKVrxatGRQKGmqVS/froLDw= -github.com/multiversx/mx-chain-core-go v1.2.20-0.20240328090024-e88291d59ace/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= -github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 h1:beVIhs5ysylwNplQ/bZ0h5DoDlqKNWgpWE/NMHHNmAw= -github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479/go.mod h1:Ap6p7QZFtwPlb++OvCG+85BfuZ+bLP/JtQp6EwjWJsI= -github.com/multiversx/mx-chain-es-indexer-go v1.4.20-0.20240228094052-28a36809b9b8 h1:z9ePQGALhPCs9Fv7cQsnsScbEq8KuOJ9xrJEEEOiHyI= -github.com/multiversx/mx-chain-es-indexer-go v1.4.20-0.20240228094052-28a36809b9b8/go.mod h1:3aSGRJNvfUuPQkZUGHWuF11rPPxphsKGuAuIB+eD3is= -github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c h1:QIUOn8FgNRa5cir4BCWHZi/Qcr6Gg0eGNhns4+jy6+k= -github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c/go.mod h1:fH/fR/GEBsDjPkBoZDVJMoYo2HhlA7++DP6QfITJ1N8= -github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 h1:ydzN3f+Y7H0InXuxAcNUSyVc+omNYL8uYtLqVzqaaX4= -github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157/go.mod h1:ndk45i9J9McuCJpTcgiaK4ocd0yhnBBCPrlFwO6GRcs= -github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474 h1:x65Su8ojHwA+NICp9DrSVGLDDcAlW04DafkqCHY1QPE= -github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474/go.mod h1:hnc6H4D5Ge1haRAQ6QHTXhyh+CT2DRiNJ0U0HQYI3DY= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240424111748-6dfa8aa14813 h1:pjknvxvRG1fQ6Dc0ZjFkWBwDLfPn2DbtACIwTBwYIA8= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240424111748-6dfa8aa14813/go.mod h1:G6daPJC6bFsvAw45RPMCRi2rP+8LjFxa8G+3alHuJow= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240429094120-31dea4df3221 h1:lTJ26YdhQoANfWSfAX/fyZj6rv0vHcLUyxtZbpQn3nk= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240429094120-31dea4df3221/go.mod h1:DyMusfHXRXyVYQmH2umBTZD5gm6p136EJNC6YI2l+kU= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240424112443-1a66307bc44e h1:Yg5Bx9iuMBpe+MTbL+VTdINlQeqjqDFIAOE4A8sWamc= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240424112443-1a66307bc44e/go.mod h1:0hoqSWVXkNvg0iYWDpYQcLyCBwz0DPIrTVf3kAtXHwU= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240424112610-ab7b9e5829bd h1:uM2FFSLvdWT7V8xRCaP01roTINT3rfTXAaiWQ1yFhag= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240424112610-ab7b9e5829bd/go.mod h1:MgRH/vdAXmXQiRdmN/b7hTxmQfPVFbVDqAHKc6Z3064= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240424113019-3a7d2b215137 h1:JL0Nn39C6f9mWJ+16xaCbrWZcZ/+TkbBMKmPxf4IVKo= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240424113019-3a7d2b215137/go.mod h1:3i2JOOE0VYvZE4K9C0VLi8mM/bBrY0dyWu3f9aw8RZI= +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.1-0.20240509104512-25512675833d h1:GD1D8V0bE6hDLjrduSsMwQwwf6PMq2Zww7FYMfJsuiw= +github.com/multiversx/mx-chain-es-indexer-go v1.7.1-0.20240509104512-25512675833d/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.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-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-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= diff --git a/node/chainSimulator/components/syncedMessenger.go b/node/chainSimulator/components/syncedMessenger.go index d30ac85b409..cc437d02038 100644 --- a/node/chainSimulator/components/syncedMessenger.go +++ b/node/chainSimulator/components/syncedMessenger.go @@ -364,11 +364,6 @@ func (messenger *syncedMessenger) SignUsingPrivateKey(_ []byte, _ []byte) ([]byt return make([]byte, 0), nil } -// AddPeerTopicNotifier does nothing and returns nil -func (messenger *syncedMessenger) AddPeerTopicNotifier(_ p2p.PeerTopicNotifier) error { - return nil -} - // SetDebugger will set the provided debugger func (messenger *syncedMessenger) SetDebugger(_ p2p.Debugger) error { return nil diff --git a/node/chainSimulator/components/syncedMessenger_test.go b/node/chainSimulator/components/syncedMessenger_test.go index c0efd6f2942..c8c17918141 100644 --- a/node/chainSimulator/components/syncedMessenger_test.go +++ b/node/chainSimulator/components/syncedMessenger_test.go @@ -50,7 +50,6 @@ func TestSyncedMessenger_DisabledMethodsShouldNotPanic(t *testing.T) { messenger, _ := NewSyncedMessenger(NewSyncedBroadcastNetwork()) assert.Nil(t, messenger.Close()) - assert.Nil(t, messenger.AddPeerTopicNotifier(nil)) assert.Zero(t, messenger.Port()) assert.Nil(t, messenger.SetPeerDenialEvaluator(nil)) assert.Nil(t, messenger.SetThresholdMinConnectedPeers(0)) diff --git a/node/node_test.go b/node/node_test.go index 21c050974b1..d2c19011830 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -3465,7 +3465,7 @@ func TestNode_GetAccountAccountWithKeysErrorShouldFail(t *testing.T) { GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { return accnt, nil, nil }, - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(options common.RootHashHolder) error { return nil }, } @@ -3515,7 +3515,7 @@ func TestNode_GetAccountAccountWithKeysShouldWork(t *testing.T) { GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { return accnt, nil, nil }, - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(options common.RootHashHolder) error { return nil }, } diff --git a/p2p/disabled/networkMessenger.go b/p2p/disabled/networkMessenger.go index 1eb767d26c8..4f854d976bc 100644 --- a/p2p/disabled/networkMessenger.go +++ b/p2p/disabled/networkMessenger.go @@ -175,11 +175,6 @@ func (netMes *networkMessenger) SignUsingPrivateKey(_ []byte, _ []byte) ([]byte, return make([]byte, 0), nil } -// AddPeerTopicNotifier returns nil as it is disabled -func (netMes *networkMessenger) AddPeerTopicNotifier(_ p2p.PeerTopicNotifier) error { - return nil -} - // ProcessReceivedMessage returns nil as it is disabled func (netMes *networkMessenger) ProcessReceivedMessage(_ p2p.MessageP2P, _ core.PeerID, _ p2p.MessageHandler) error { return nil diff --git a/p2p/interface.go b/p2p/interface.go index dbdabc4248c..e2f7130c6ae 100644 --- a/p2p/interface.go +++ b/p2p/interface.go @@ -102,9 +102,6 @@ type PeersRatingHandler interface { // PeersRatingMonitor represents an entity able to provide peers ratings type PeersRatingMonitor = p2p.PeersRatingMonitor -// PeerTopicNotifier represents an entity able to handle new notifications on a new peer on a topic -type PeerTopicNotifier = p2p.PeerTopicNotifier - // P2PSigningHandler defines the behaviour of a component able to verify p2p message signature type P2PSigningHandler interface { Verify(message MessageP2P) error diff --git a/p2p/mock/peerTopicNotifierStub.go b/p2p/mock/peerTopicNotifierStub.go deleted file mode 100644 index bc1446ae819..00000000000 --- a/p2p/mock/peerTopicNotifierStub.go +++ /dev/null @@ -1,20 +0,0 @@ -package mock - -import "github.com/multiversx/mx-chain-core-go/core" - -// PeerTopicNotifierStub - -type PeerTopicNotifierStub struct { - NewPeerFoundCalled func(pid core.PeerID, topic string) -} - -// NewPeerFound - -func (stub *PeerTopicNotifierStub) NewPeerFound(pid core.PeerID, topic string) { - if stub.NewPeerFoundCalled != nil { - stub.NewPeerFoundCalled(pid, topic) - } -} - -// IsInterfaceNil - -func (stub *PeerTopicNotifierStub) IsInterfaceNil() bool { - return stub == nil -} diff --git a/testscommon/p2pmocks/messengerStub.go b/testscommon/p2pmocks/messengerStub.go index 77d058c71a1..c48c95b9868 100644 --- a/testscommon/p2pmocks/messengerStub.go +++ b/testscommon/p2pmocks/messengerStub.go @@ -40,7 +40,6 @@ type MessengerStub struct { WaitForConnectionsCalled func(maxWaitingTime time.Duration, minNumOfPeers uint32) SignCalled func(payload []byte) ([]byte, error) VerifyCalled func(payload []byte, pid core.PeerID, signature []byte) error - AddPeerTopicNotifierCalled func(notifier p2p.PeerTopicNotifier) error BroadcastUsingPrivateKeyCalled func(topic string, buff []byte, pid core.PeerID, skBytes []byte) BroadcastOnChannelUsingPrivateKeyCalled func(channel string, topic string, buff []byte, pid core.PeerID, skBytes []byte) SignUsingPrivateKeyCalled func(skBytes []byte, payload []byte) ([]byte, error) @@ -322,15 +321,6 @@ func (ms *MessengerStub) Verify(payload []byte, pid core.PeerID, signature []byt return nil } -// AddPeerTopicNotifier - -func (ms *MessengerStub) AddPeerTopicNotifier(notifier p2p.PeerTopicNotifier) error { - if ms.AddPeerTopicNotifierCalled != nil { - return ms.AddPeerTopicNotifierCalled(notifier) - } - - return nil -} - // BroadcastUsingPrivateKey - func (ms *MessengerStub) BroadcastUsingPrivateKey(topic string, buff []byte, pid core.PeerID, skBytes []byte) { if ms.BroadcastUsingPrivateKeyCalled != nil { From 0ac91d02eeaa6df28b5d7d790b184cf0b81a9701 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 13 May 2024 11:21:11 +0300 Subject: [PATCH 221/503] - aligned mainnet configs with mx-chain-go --- cmd/node/config/systemSmartContractsConfig.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/node/config/systemSmartContractsConfig.toml b/cmd/node/config/systemSmartContractsConfig.toml index 372cd0eba03..2ffc4da94c0 100644 --- a/cmd/node/config/systemSmartContractsConfig.toml +++ b/cmd/node/config/systemSmartContractsConfig.toml @@ -10,7 +10,7 @@ BleedPercentagePerRound = 0.00001 MaxNumberOfNodesForStake = 64 UnJailValue = "2500000000000000000" #0.1% of genesis node price - ActivateBLSPubKeyMessageVerification = false + ActivateBLSPubKeyMessageVerification = true StakeLimitPercentage = 1.0 #fraction of value 1 - 100%, for the time being no stake limit NodeLimitPercentage = 0.1 #fraction of value 0.1 - 10% @@ -35,7 +35,7 @@ [DelegationManagerSystemSCConfig] MinCreationDeposit = "1250000000000000000000" #1.25K eGLD - MinStakeAmount = "10000000000000000000" #10 eGLD + MinStakeAmount = "1000000000000000000" #1 eGLD ConfigChangeAddress = "erd1vxy22x0fj4zv6hktmydg8vpfh6euv02cz4yg0aaws6rrad5a5awqgqky80" #should use a multisign contract instead of a wallet address [DelegationSystemSCConfig] From c267fd1a5ff330e77789f61b778dd74c9578b334 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 13 May 2024 11:30:52 +0300 Subject: [PATCH 222/503] - compressed configs --- cmd/node/config/enableEpochs.toml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index 482b30b0329..d24e57df7e7 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -285,25 +285,25 @@ FixGasRemainingForSaveKeyValueBuiltinFunctionEnableEpoch = 1 # CurrentRandomnessOnSortingEnableEpoch represents the epoch when the current randomness on sorting is enabled - CurrentRandomnessOnSortingEnableEpoch = 4 + CurrentRandomnessOnSortingEnableEpoch = 1 # StakeLimitsEnableEpoch represents the epoch when stake limits on validators are enabled # Should have the same value as StakingV4Step1EnableEpoch that triggers the automatic unstake operations for the queue nodes - StakeLimitsEnableEpoch = 4 + StakeLimitsEnableEpoch = 1 # StakingV4Step1EnableEpoch represents the epoch when staking v4 is initialized. This is the epoch in which # all nodes from staking queue are moved in the auction list - StakingV4Step1EnableEpoch = 4 + StakingV4Step1EnableEpoch = 1 # StakingV4Step2EnableEpoch represents the epoch when staking v4 is enabled. Should have a greater value than StakingV4Step1EnableEpoch. # From this epoch, all shuffled out nodes are moved to auction nodes. No auction nodes selection is done yet. - StakingV4Step2EnableEpoch = 5 + StakingV4Step2EnableEpoch = 2 # StakingV4Step3EnableEpoch represents the epoch in which selected nodes from auction will be distributed to waiting list - StakingV4Step3EnableEpoch = 6 + StakingV4Step3EnableEpoch = 3 # AlwaysMergeContextsInEEIEnableEpoch represents the epoch in which the EEI will always merge the contexts - AlwaysMergeContextsInEEIEnableEpoch = 4 + AlwaysMergeContextsInEEIEnableEpoch = 1 # BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers BLSMultiSignerEnableEpoch = [ @@ -319,7 +319,7 @@ # - Enable epoch = StakingV4Step3EnableEpoch # - NodesToShufflePerShard = same as previous entry in MaxNodesChangeEnableEpoch # - MaxNumNodes = (MaxNumNodesFromPreviousEpochEnable - (numOfShards+1)*NodesToShufflePerShard) - { EpochEnable = 6, MaxNumNodes = 56, NodesToShufflePerShard = 2 }, + { EpochEnable = 3, MaxNumNodes = 56, NodesToShufflePerShard = 2 }, ] [GasSchedule] From 018804eac62b259aef7a9bc010a5c30b40483002 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Mon, 13 May 2024 11:51:33 +0300 Subject: [PATCH 223/503] fix args for the new unit test --- node/chainSimulator/chainSimulator_test.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index 32313f5cbc3..1929944d510 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -294,16 +294,18 @@ func TestChainSimulator_SetEntireStateWithRemoval(t *testing.T) { Value: 20, } chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 1, - MetaChainMinNodes: 1, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 1, + MetaChainMinNodes: 1, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, }) require.Nil(t, err) require.NotNil(t, chainSimulator) From 97b34d028b00ba7039596e3a06d72e13a6cb475f Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Mon, 13 May 2024 12:00:58 +0300 Subject: [PATCH 224/503] fix args for more chain simulator integration tests --- .../staking/stake/stakeAndUnStake_test.go | 26 ++-- .../stakingProvider/delegation_test.go | 130 ++++++++++-------- 2 files changed, 84 insertions(+), 72 deletions(-) diff --git a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index 5b25fcab308..4fede1dc0bc 100644 --- a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go @@ -2394,18 +2394,20 @@ func TestChainSimulator_UnStakeOneActiveNodeAndCheckAPIAuctionList(t *testing.T) numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 4, - MetaChainMinNodes: 4, - NumNodesWaitingListMeta: 4, - NumNodesWaitingListShard: 4, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 4, + MetaChainMinNodes: 4, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 4, + NumNodesWaitingListShard: 4, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = stakingV4Step1Epoch cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = stakingV4Step2Epoch diff --git a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index 36085dd3b23..6e7a189e513 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go @@ -115,18 +115,20 @@ func TestChainSimulator_MakeNewContractFromValidatorData(t *testing.T) { // 6. Execute 2 unDelegate operations of 100 EGLD each, check the topup is back to 500 t.Run("staking ph 4 is not active and all is done in epoch 0", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { maxNodesChangeEnableEpoch := cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch blsMultiSignerEnableEpoch := cfg.EpochConfig.EnableEpochs.BLSMultiSignerEnableEpoch @@ -1426,18 +1428,20 @@ func TestChainSimulator_MaxDelegationCap(t *testing.T) { // 10. Delegate from user B 20 EGLD, check it fails t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 @@ -1467,18 +1471,20 @@ func TestChainSimulator_MaxDelegationCap(t *testing.T) { // 10. Delegate from user B 20 EGLD, check it fails t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1508,18 +1514,20 @@ func TestChainSimulator_MaxDelegationCap(t *testing.T) { // 10. Delegate from user B 20 EGLD, check it fails t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1549,18 +1557,20 @@ func TestChainSimulator_MaxDelegationCap(t *testing.T) { // 10. Delegate from user B 20 EGLD, check it fails t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 From 68a95a1095cbc52f7d0da0ea0d3d875ebd94f9d1 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 13 May 2024 15:18:17 +0300 Subject: [PATCH 225/503] further fixes after review --- process/errors.go | 3 + process/transaction/export_test.go | 3 +- process/transaction/shardProcess.go | 99 +++++++++++++++++----- process/transaction/shardProcess_test.go | 103 +++++++++++++++++++++-- 4 files changed, 180 insertions(+), 28 deletions(-) diff --git a/process/errors.go b/process/errors.go index 1359f5ca12e..b63dd47c1e8 100644 --- a/process/errors.go +++ b/process/errors.go @@ -1259,3 +1259,6 @@ var ErrNilRelayerAccount = errors.New("nil relayer account") // ErrRelayedTxV3TooManyInnerTransactions signals that too many inner transactions were provided var ErrRelayedTxV3TooManyInnerTransactions = errors.New("too many inner transactions") + +// ErrConsumedFeesMismatch signals that the fees consumed from relayer do not match the inner transactions fees +var ErrConsumedFeesMismatch = errors.New("consumed fees mismatch") diff --git a/process/transaction/export_test.go b/process/transaction/export_test.go index a8279814c64..07ed7a91896 100644 --- a/process/transaction/export_test.go +++ b/process/transaction/export_test.go @@ -55,8 +55,9 @@ func (txProc *txProcessor) ProcessUserTx( userTx *transaction.Transaction, relayedTxValue *big.Int, relayedNonce uint64, + originalTxHash []byte, ) (vmcommon.ReturnCode, error) { - return txProc.processUserTx(originalTx, userTx, relayedTxValue, relayedNonce) + return txProc.processUserTx(originalTx, userTx, relayedTxValue, relayedNonce, originalTxHash) } // ProcessMoveBalanceCostRelayedUserTx calls the un-exported method processMoveBalanceCostRelayedUserTx diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index da98908ce94..2d8778a252b 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -579,12 +579,29 @@ func (txProc *txProcessor) finishExecutionOfRelayedTx( return vmcommon.Ok, nil } - err = txProc.addFeeAndValueToDest(acntDst, tx, computedFees.remainingFee) + err = txProc.addFeeAndValueToDest(acntDst, tx.Value, computedFees.remainingFee) if err != nil { return 0, err } - return txProc.processUserTx(tx, userTx, tx.Value, tx.Nonce) + originalTxHash, err := core.CalculateHash(txProc.marshalizer, txProc.hasher, tx) + if err != nil { + errRemove := txProc.removeValueAndConsumedFeeFromUser(userTx, tx.Value, originalTxHash, tx, err) + if errRemove != nil { + return vmcommon.UserError, errRemove + } + + return vmcommon.UserError, txProc.executeFailedRelayedUserTx( + userTx, + tx.SndAddr, + tx.Value, + tx.Nonce, + tx, + originalTxHash, + err.Error()) + } + + return txProc.processUserTx(tx, userTx, tx.Value, tx.Nonce, originalTxHash) } func (txProc *txProcessor) processTxAtRelayer( @@ -621,8 +638,8 @@ func (txProc *txProcessor) processTxAtRelayer( return nil } -func (txProc *txProcessor) addFeeAndValueToDest(acntDst state.UserAccountHandler, tx *transaction.Transaction, remainingFee *big.Int) error { - err := acntDst.AddToBalance(tx.GetValue()) +func (txProc *txProcessor) addFeeAndValueToDest(acntDst state.UserAccountHandler, txValue *big.Int, remainingFee *big.Int) error { + err := acntDst.AddToBalance(txValue) if err != nil { return err } @@ -650,6 +667,8 @@ func (txProc *txProcessor) processRelayedTxV3( return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, err) } + snapshot := txProc.accounts.JournalLen() + // process fees on both relayer and sender relayerFee, totalFee := txProc.relayedTxV3Processor.ComputeRelayedTxFees(tx) err = txProc.processTxAtRelayer(relayerAcnt, totalFee, relayerFee, tx) @@ -659,11 +678,19 @@ func (txProc *txProcessor) processRelayedTxV3( innerTxs := tx.GetInnerTransactions() + originalTxHash, err := core.CalculateHash(txProc.marshalizer, txProc.hasher, tx) + if err != nil { + return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, err) + } + var innerTxRetCode vmcommon.ReturnCode var innerTxErr error + innerTxFee := big.NewInt(0) + innerTxsTotalFees := big.NewInt(0) executedUserTxs := make([]*transaction.Transaction, 0) for _, innerTx := range innerTxs { - innerTxRetCode, innerTxErr = txProc.finishExecutionOfInnerTx(tx, innerTx) + innerTxFee, innerTxRetCode, innerTxErr = txProc.processInnerTx(tx, innerTx, originalTxHash) + innerTxsTotalFees.Add(innerTxsTotalFees, innerTxFee) if innerTxErr != nil || innerTxRetCode != vmcommon.Ok { continue } @@ -676,29 +703,68 @@ func (txProc *txProcessor) processRelayedTxV3( log.Trace("failed to execute all inner transactions", "total", len(innerTxs), "executed transactions", len(executedUserTxs)) } + expectedInnerTxsTotalFees := big.NewInt(0).Sub(totalFee, relayerFee) + if innerTxsTotalFees.Cmp(expectedInnerTxsTotalFees) != 0 { + log.Debug("reverting relayed transaction, total inner transactions fees mismatch", + "computed fee at relayer", expectedInnerTxsTotalFees.Uint64(), + "total inner fees", innerTxsTotalFees.Uint64()) + + errRevert := txProc.accounts.RevertToSnapshot(snapshot) + if errRevert != nil { + return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, errRevert) + } + + return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrConsumedFeesMismatch) + } + return vmcommon.Ok, nil } -func (txProc *txProcessor) finishExecutionOfInnerTx( +func (txProc *txProcessor) processInnerTx( tx *transaction.Transaction, innerTx *transaction.Transaction, -) (vmcommon.ReturnCode, error) { + originalTxHash []byte, +) (*big.Int, vmcommon.ReturnCode, error) { + + txFee := txProc.computeTxFee(innerTx) + acntSnd, err := txProc.getAccountFromAddress(innerTx.SndAddr) if err != nil { - return vmcommon.UserError, err + return txFee, vmcommon.UserError, txProc.executeFailedRelayedUserTx( + innerTx, + innerTx.RelayerAddr, + big.NewInt(0), + tx.Nonce, + tx, + originalTxHash, + err.Error()) } if check.IfNil(acntSnd) { - return vmcommon.UserError, process.ErrRelayedTxV3SenderShardMismatch + return txFee, vmcommon.UserError, txProc.executeFailedRelayedUserTx( + innerTx, + innerTx.RelayerAddr, + big.NewInt(0), + tx.Nonce, + tx, + originalTxHash, + process.ErrRelayedTxV3SenderShardMismatch.Error()) } - txFee := txProc.computeTxFee(innerTx) - err = txProc.addFeeAndValueToDest(acntSnd, tx, txFee) + err = txProc.addFeeAndValueToDest(acntSnd, big.NewInt(0), txFee) if err != nil { - return vmcommon.UserError, err + return txFee, vmcommon.UserError, txProc.executeFailedRelayedUserTx( + innerTx, + innerTx.RelayerAddr, + big.NewInt(0), + tx.Nonce, + tx, + originalTxHash, + err.Error()) } - return txProc.processUserTx(tx, innerTx, tx.Value, tx.Nonce) + result, err := txProc.processUserTx(tx, innerTx, tx.Value, tx.Nonce, originalTxHash) + return txFee, result, err } func (txProc *txProcessor) processRelayedTxV2( @@ -869,6 +935,7 @@ func (txProc *txProcessor) processUserTx( userTx *transaction.Transaction, relayedTxValue *big.Int, relayedNonce uint64, + originalTxHash []byte, ) (vmcommon.ReturnCode, error) { acntSnd, acntDst, err := txProc.getAccounts(userTx.SndAddr, userTx.RcvAddr) @@ -876,12 +943,6 @@ func (txProc *txProcessor) processUserTx( return 0, err } - var originalTxHash []byte - originalTxHash, err = core.CalculateHash(txProc.marshalizer, txProc.hasher, originalTx) - if err != nil { - return 0, err - } - relayerAdr := originalTx.SndAddr txType, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(userTx) err = txProc.checkTxValues(userTx, acntSnd, acntDst, true) diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index 59959a082b8..6114e57ee0b 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -36,6 +36,8 @@ import ( "github.com/stretchr/testify/require" ) +var txHash = []byte("hash") + func generateRandomByteSlice(size int) []byte { buff := make([]byte, size) _, _ = rand.Reader.Read(buff) @@ -2227,7 +2229,7 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV3Flag, common.FixRelayedMoveBalanceFlag) args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { - return big.NewInt(int64(tx.GetGasPrice() * tx.GetGasLimit())) + return big.NewInt(1) }, } args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(txproc.ArgRelayedTxV3Processor{ @@ -2346,6 +2348,91 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { assert.NoError(t, err) assert.Equal(t, vmcommon.Ok, returnCode) }) + t.Run("fees consumed mismatch should error", func(t *testing.T) { + t.Parallel() + + providedInitialBalance := big.NewInt(100) + pubKeyConverter := testscommon.NewPubkeyConverterMock(4) + + accounts := map[string]state.UserAccountHandler{} + adb := &stateMock.AccountsStub{} + adb.LoadAccountCalled = func(address []byte) (vmcommon.AccountHandler, error) { + acnt, exists := accounts[string(address)] + if !exists { + acnt = createUserAcc(address) + accounts[string(address)] = acnt + _ = acnt.AddToBalance(providedInitialBalance) + } + + return acnt, nil + } + wasRevertToSnapshotCalled := false + adb.RevertToSnapshotCalled = func(snapshot int) error { + wasRevertToSnapshotCalled = true + return nil + } + + scProcessorMock := &testscommon.SCProcessorMock{} + shardC, _ := sharding.NewMultiShardCoordinator(1, 0) + esdtTransferParser, _ := parsers.NewESDTTransferParser(marshaller) + argTxTypeHandler := coordinator.ArgNewTxTypeHandler{ + PubkeyConverter: pubKeyConverter, + ShardCoordinator: shardC, + BuiltInFunctions: builtInFunctions.NewBuiltInFunctionContainer(), + ArgumentParser: parsers.NewCallArgsParser(), + ESDTTransferParser: esdtTransferParser, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.ESDTMetadataContinuousCleanupFlag), + } + txTypeHandler, _ := coordinator.NewTxTypeHandler(argTxTypeHandler) + + args := createArgsForTxProcessor() + args.Accounts = adb + args.ScProcessor = scProcessorMock + args.ShardCoordinator = shardC + args.TxTypeHandler = txTypeHandler + args.PubkeyConv = pubKeyConverter + args.ArgsParser = smartContract.NewArgumentParser() + args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV3Flag, common.FixRelayedMoveBalanceFlag) + increasingFee := big.NewInt(0) + args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ + ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { + increasingFee.Add(increasingFee, big.NewInt(1)) + return increasingFee + }, + } + args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(txproc.ArgRelayedTxV3Processor{ + EconomicsFee: args.EconomicsFee, + ShardCoordinator: args.ShardCoordinator, + MaxTransactionsAllowed: 10, + }) + execTx, _ := txproc.NewTxProcessor(args) + + txCopy := *tx + innerTx1 := &transaction.Transaction{ + Nonce: 0, + Value: big.NewInt(10), + RcvAddr: []byte("sDST"), + SndAddr: []byte("sender inner tx 1"), + GasPrice: 1, + GasLimit: 1, + RelayerAddr: txCopy.SndAddr, + } + innerTx2 := &transaction.Transaction{ + Nonce: 0, + Value: big.NewInt(10), + RcvAddr: []byte("sDST"), + SndAddr: []byte("sender inner tx 2"), + GasPrice: 1, + GasLimit: 1, + RelayerAddr: txCopy.SndAddr, + } + + txCopy.InnerTransactions = []*transaction.Transaction{innerTx1, innerTx2} + returnCode, err := execTx.ProcessTransaction(&txCopy) + assert.Error(t, err) + assert.Equal(t, vmcommon.UserError, returnCode) + assert.True(t, wasRevertToSnapshotCalled) + }) t.Run("should work", func(t *testing.T) { t.Parallel() testProcessRelayedTransactionV3(t, tx, userTx.SndAddr, userTx.RcvAddr, nil, vmcommon.Ok) @@ -3155,7 +3242,7 @@ func TestTxProcessor_ProcessUserTxOfTypeRelayedShouldError(t *testing.T) { execTx, _ := txproc.NewTxProcessor(args) - returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce) + returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce, txHash) assert.Nil(t, err) assert.Equal(t, vmcommon.UserError, returnCode) } @@ -3218,7 +3305,7 @@ func TestTxProcessor_ProcessUserTxOfTypeMoveBalanceShouldWork(t *testing.T) { execTx, _ := txproc.NewTxProcessor(args) - returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce) + returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce, txHash) assert.Nil(t, err) assert.Equal(t, vmcommon.Ok, returnCode) } @@ -3281,7 +3368,7 @@ func TestTxProcessor_ProcessUserTxOfTypeSCDeploymentShouldWork(t *testing.T) { execTx, _ := txproc.NewTxProcessor(args) - returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce) + returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce, txHash) assert.Nil(t, err) assert.Equal(t, vmcommon.Ok, returnCode) } @@ -3344,7 +3431,7 @@ func TestTxProcessor_ProcessUserTxOfTypeSCInvokingShouldWork(t *testing.T) { execTx, _ := txproc.NewTxProcessor(args) - returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce) + returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce, txHash) assert.Nil(t, err) assert.Equal(t, vmcommon.Ok, returnCode) } @@ -3407,7 +3494,7 @@ func TestTxProcessor_ProcessUserTxOfTypeBuiltInFunctionCallShouldWork(t *testing execTx, _ := txproc.NewTxProcessor(args) - returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce) + returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce, txHash) assert.Nil(t, err) assert.Equal(t, vmcommon.Ok, returnCode) } @@ -3474,7 +3561,7 @@ func TestTxProcessor_ProcessUserTxErrNotPayableShouldFailRelayTx(t *testing.T) { execTx, _ := txproc.NewTxProcessor(args) - returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce) + returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce, txHash) assert.Nil(t, err) assert.Equal(t, vmcommon.UserError, returnCode) } @@ -3543,7 +3630,7 @@ func TestTxProcessor_ProcessUserTxFailedBuiltInFunctionCall(t *testing.T) { execTx, _ := txproc.NewTxProcessor(args) - returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce) + returnCode, err := execTx.ProcessUserTx(&tx, &userTx, tx.Value, tx.Nonce, txHash) assert.Nil(t, err) assert.Equal(t, vmcommon.ExecutionFailed, returnCode) } From 253f9200a8e7246221b4363b7cd3340060a90265 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 13 May 2024 15:24:30 +0300 Subject: [PATCH 226/503] fix linter --- process/transaction/shardProcess.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 2d8778a252b..0990335ee2a 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -685,7 +685,7 @@ func (txProc *txProcessor) processRelayedTxV3( var innerTxRetCode vmcommon.ReturnCode var innerTxErr error - innerTxFee := big.NewInt(0) + var innerTxFee *big.Int innerTxsTotalFees := big.NewInt(0) executedUserTxs := make([]*transaction.Transaction, 0) for _, innerTx := range innerTxs { From 1da2106c8453da22d26dc11d94fb1e363c873938 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 13 May 2024 19:44:28 +0300 Subject: [PATCH 227/503] improved integration test to check events as well --- .../relayedTx/relayedTx_test.go | 65 +++++++++++++++--- .../relayedTx/testData/egld-esdt-swap.wasm | Bin 0 -> 4607 bytes 2 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 integrationTests/chainSimulator/relayedTx/testData/egld-esdt-swap.wasm diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index edd5eb245e7..950f07f2b6b 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -1,13 +1,16 @@ package relayedTx import ( + "encoding/hex" "math/big" + "strings" "testing" "time" "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/integrationTests/vm/wasm" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" @@ -22,7 +25,6 @@ const ( txVersion = 2 mockTxSignature = "sig" maxNumOfBlocksToGenerateWhenExecutingTx = 10 - numOfBlocksToWaitForCrossShardSCR = 5 ) var oneEGLD = big.NewInt(1000000000000000000) @@ -64,7 +66,7 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing. err = cs.GenerateBlocksUntilEpochIsReached(1) require.NoError(t, err) - initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(10)) + initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(30000)) relayer, err := cs.GenerateAndMintWalletAddress(0, initialBalance) require.NoError(t, err) @@ -86,31 +88,58 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing. innerTx2 := generateTransaction(sender2.Bytes, 0, receiver2.Bytes, oneEGLD, "", minGasLimit) innerTx2.RelayerAddr = relayer.Bytes + pkConv := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter() + // innerTx3Failure should fail due to less gas limit - data := "gas limit is not enough" - innerTx3Failure := generateTransaction(sender.Bytes, 1, receiver2.Bytes, oneEGLD, data, minGasLimit) + // deploy a wrapper contract + owner, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + scCode := wasm.GetSCCode("testData/egld-esdt-swap.wasm") + params := []string{scCode, wasm.VMTypeHex, wasm.DummyCodeMetadataHex, hex.EncodeToString([]byte("WEGLD"))} + txDataDeploy := strings.Join(params, "@") + deployTx := generateTransaction(owner.Bytes, 0, make([]byte, 32), big.NewInt(0), txDataDeploy, 600000000) + + result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(deployTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + scAddress := result.Logs.Events[0].Address + scAddressBytes, _ := pkConv.Decode(scAddress) + + // try a wrap transaction which will fail as the contract is paused + txDataWrap := "wrapEgld" + gasLimit := 2300000 + innerTx3Failure := generateTransaction(owner.Bytes, 1, scAddressBytes, big.NewInt(1), txDataWrap, uint64(gasLimit)) innerTx3Failure.RelayerAddr = relayer.Bytes innerTx3 := generateTransaction(sender.Bytes, 1, receiver2.Bytes, oneEGLD, "", minGasLimit) innerTx3.RelayerAddr = relayer.Bytes - innerTxs := []*transaction.Transaction{innerTx, innerTx2, innerTx3} + innerTxs := []*transaction.Transaction{innerTx, innerTx2, innerTx3Failure, innerTx3} // relayer will consume first a move balance for each inner tx, then the specific gas for each inner tx - relayedTxGasLimit := minGasLimit * (len(innerTxs) * 2) - relayedTx := generateTransaction(relayer.Bytes, 0, relayer.Bytes, big.NewInt(0), "", uint64(relayedTxGasLimit)) + relayedTxGasLimit := uint64(minGasLimit) + for _, tx := range innerTxs { + relayedTxGasLimit += minGasLimit + tx.GasLimit + } + relayedTx := generateTransaction(relayer.Bytes, 0, relayer.Bytes, big.NewInt(0), "", relayedTxGasLimit) relayedTx.InnerTransactions = innerTxs - _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) + result, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) require.NoError(t, err) // generate few more blocks for the cross shard scrs to be done - err = cs.GenerateBlocks(numOfBlocksToWaitForCrossShardSCR) + err = cs.GenerateBlocks(maxNumOfBlocksToGenerateWhenExecutingTx) require.NoError(t, err) relayerAccount, err := cs.GetAccount(relayer) require.NoError(t, err) - expectedRelayerFee := big.NewInt(int64(minGasPrice * relayedTxGasLimit)) + economicsData := cs.GetNodeHandler(0).GetCoreComponents().EconomicsData() + relayerMoveBalanceFee := economicsData.ComputeMoveBalanceFee(relayedTx) + expectedRelayerFee := big.NewInt(0).Mul(relayerMoveBalanceFee, big.NewInt(int64(len(relayedTx.InnerTransactions)))) + for _, tx := range innerTxs { + expectedRelayerFee.Add(expectedRelayerFee, economicsData.ComputeTxFee(tx)) + } assert.Equal(t, big.NewInt(0).Sub(initialBalance, expectedRelayerFee).String(), relayerAccount.Balance) senderAccount, err := cs.GetAccount(sender) @@ -128,6 +157,22 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing. receiver2Account, err := cs.GetAccount(receiver2) require.NoError(t, err) assert.Equal(t, big.NewInt(0).Mul(oneEGLD, big.NewInt(2)).String(), receiver2Account.Balance) + + // check SCRs + shardC := cs.GetNodeHandler(0).GetShardCoordinator() + for _, scr := range result.SmartContractResults { + addr, err := pkConv.Decode(scr.RcvAddr) + require.NoError(t, err) + + senderShard := shardC.ComputeId(addr) + tx, err := cs.GetNodeHandler(senderShard).GetFacadeHandler().GetTransaction(scr.Hash, true) + require.NoError(t, err) + assert.Equal(t, transaction.TxStatusSuccess, tx.Status) + } + + // check log events + require.Equal(t, 3, len(result.Logs.Events)) + require.True(t, strings.Contains(string(result.Logs.Events[2].Data), "contract is paused")) } func generateTransaction(sender []byte, nonce uint64, receiver []byte, value *big.Int, data string, gasLimit uint64) *transaction.Transaction { diff --git a/integrationTests/chainSimulator/relayedTx/testData/egld-esdt-swap.wasm b/integrationTests/chainSimulator/relayedTx/testData/egld-esdt-swap.wasm new file mode 100644 index 0000000000000000000000000000000000000000..7244307f1ccb501e600b4483ca30f0099eb24764 GIT binary patch literal 4607 zcmai2O>i7X74GhtU9B{`(zC26_F74L*D`SeHcm)n`)X^X{P)2 z>-XOG{(4#>>~*9NLf$@jLx>x4AP0De8*0EKJjD%xfj8h0KQYM-2KVj2#~kE5X83U{ zSmNFHAq#&(-oIhFvPCNe>>?8))X&DA^`iK8&}(hQ;ch)ix{2_aGSR8^H#ehXHM%2m zOekdpv$q$;P2n+ZJfqcbxjA*hINXYw>*r0gnMA#wP|S8DBiHXnjeZ)f#TTMpdcGT{ z(cM%`FvnD5Hwxp|qqLvI7s50Y!l`uP&WF3ZQQ~AB%w(t!TbJW>IZB!T z&2YCLWm~qQbhY29uV1)+JqhC;Q1u+9DYs&ht$rtp(~LU(7}DCkH0p^lYh|{u9;J^^ z4`vT( zv-`kc$)^&EkTy1(x;s(48g?QlI|FvUv*&^^0k-9^w-RlpVv>ap>tG1d=ICP(hoMG5 zIS}i+EqHp$J9C<#Lih)ADkp?5rBcH8bJCZdlzHFJOHbvd$H#Lrms4mbqo157#ew`` zZy?P(?|dwRfiQplu6zH3-(w%jQoa*)y2(9Aglkgq`V7oo={9zvW_@e7ISlvu6Cl5p zgs6T?zs}e%H^ucrt9LEz_u#lUa(g@wZ;mI?%`8ja8tcc7`u0RWzJvWNRD7i{8h*9V zKoDwSV@G^#Vq>F;>fbEu^okb8#lvV23KYDr72uKG(_Y5!_T(s2>+ zpB5mLGP$I|)`i2Omq#Tf}N-ap0wG0BmEaVw+B`6B>ukU;;%rprRjJpMl zD%fJS$fuK4k3O%3+0q{CrIVB^Q=am{5$1Rw9<-0+N*K9Q6;P^0P{5-m=x|VE%_pmZ z#z1{~I4Qu8Q}n#QG!>Zl5EC=c%AXW8QTLZjpTqq`p7{whVzdfI zSy4q9FjgZOt@h}p3JAdFyr9?xCD>w3I9P@atFYmyFtk&Z^8!)@k@1(oBModX@?KMH z8=q>duxS49qmO=S*M<23V--{?L#3hiJOeG`F*NBCO!_BVZCx2WAqb{iv>@O8Hpqt= z%#jhhVGIEJ7v6G!*Oo`NDF{a}O(8|jelm6o!$WDpgxltwe|vU*J4u|u${AcNYh}#} zPOzU}sVH_Dor6p9dd~SunFnl&Z&5%8eKDBHqOy+6%JX}cw9OX9B^_JyAa~F3LcN-CEYfX^(?%kP%c>X8bZ6XELyDQ=n&g zJ4YJ&jw>I0H8lW(sFy_9Tham>IMXWF^MXLgYlU~eSMdN{wk^a!ErBTCMli7YAy`YQ zj5IMHG4N?RF9O3!V_gOJf57BPCXW*304EC1Ac0|jrtFgacg#9Vi?EF`vcqXc1n*1f zWjW;`ZYYxnwKMMmC@hiYp}fUO&B;@dYzJQ6lEN>Ca~W_vQ)p}1J|O_QUQ&Q^C^gUY z*#qsWZ^qY3oZ;Y6%vQlJ?e74qAJErP`uKw+UMPydwgE2FI<|0*S{x`5MT<0DwuMQC zUJjlDJi26l4zuV9BUad5QxHVwjO?K)0K8qBEeF@7k94XkI%mts*P`Ol$%^2_QbZM4 zN0(sr?^)Jt+3vFwjyJSCsaZ03>P$AK8Bp~$( zy^3CC4?UCZ-b%zv$9egGeO z=ssGaX->U{fj~No9pl}q`t3?i`y4*bMNVcU-&ujT%_DFk^I-Gkk_g~)sP%Us<(s#v z`F2Ghb8+%;YI-&>$R1=UW@!~|>J}pDGb_NNBB4|6Fm+rP0MP1#2ld!(tuV)#G@hc5 z3FHs613e_?v|!cT+!3x7l%iizFf?cP{10xV7z{!y@HMPdm@;OZgBeDZVN|wL3^7WJ zaVp?rl7#siAB6`|D@$AkwjI-z6JDrNE9?tgN=1YouR;Y43bjoObhVDWRK!lp(evC|C9T#=C?fdv zs1a96KKC`9qqDZpe~ISpC!#6QBKDn7OLPj$C=?*{xP>j-p2vNSu92i;)?^ktU;FVN z#kaum3W)3pu3=;qf17<4C(fVw=pgzWhJWYboE?6j)9EM=f2mZ?9hDj%QD}%SLZ$p~ z)N>GRQO~t0Lk(w*P|wi<$Bp>wkdOWncTqsLPN+zrW$K6rp)E z9&F`}js-2(dQO;`As_G7&VB50*AsliF!db1xl(pERt z&2H4waW~arqY>?;nkDHycmGPeUA-CI(c$p+%mm!!?(I|VB;9yR$NkRDDAC=`{e@P% z*H1NX*ab&@dF6tmbU_6lZs}Y27lFM8>t@vGHX|MJ|0d4rx2(vh*W~TEf?VzQQnpCr z4io8g8=y|Pm0pGa#lV-`eHh!}ZAgl{{jF^ckj>s2JAn0P2%~0pyVM;P4A(p&m+vf( xUw`b?W~0+>_IIPRcG7GNm9~1Yi!VldVccryZllpp5?qt)l_BuofB5j>e*jHK=`{cV literal 0 HcmV?d00001 From c91444b32e7a42f63813fcced36a3aa12ee4a488 Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Tue, 14 May 2024 13:00:01 +0300 Subject: [PATCH 228/503] cleanup proposal misses --- process/scToProtocol/stakingToPeer.go | 6 ++++-- state/interface.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/process/scToProtocol/stakingToPeer.go b/process/scToProtocol/stakingToPeer.go index e9b166b52ea..b0a0d973786 100644 --- a/process/scToProtocol/stakingToPeer.go +++ b/process/scToProtocol/stakingToPeer.go @@ -11,14 +11,15 @@ import ( "github.com/multiversx/mx-chain-core-go/data/smartContractResult" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + "github.com/multiversx/mx-chain-logger-go" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/vm" "github.com/multiversx/mx-chain-go/vm/systemSmartContracts" - "github.com/multiversx/mx-chain-logger-go" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) var _ process.SmartContractToProtocolHandler = (*stakingToPeer)(nil) @@ -341,6 +342,7 @@ func (stp *stakingToPeer) updatePeerState( if account.GetTempRating() < stp.unJailRating { log.Debug("node is unJailed, setting temp rating to start rating", "blsKey", blsPubKey) account.SetTempRating(stp.unJailRating) + account.SetConsecutiveProposerMisses(0) } isNewValidator := !isValidator && stakingData.Staked diff --git a/state/interface.go b/state/interface.go index d78c6e90997..a5766b6fffc 100644 --- a/state/interface.go +++ b/state/interface.go @@ -59,7 +59,7 @@ type PeerAccountHandler interface { GetTempRating() uint32 SetTempRating(uint32) GetConsecutiveProposerMisses() uint32 - SetConsecutiveProposerMisses(uint322 uint32) + SetConsecutiveProposerMisses(consecutiveMisses uint32) ResetAtNewEpoch() SetPreviousList(list string) vmcommon.AccountHandler From d2837628949cd4d93e36dd820b106421c0536e39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Tue, 14 May 2024 13:34:47 +0300 Subject: [PATCH 229/503] Adjust workflow runners (MacOS). --- .github/workflows/build_and_test.yml | 2 +- .github/workflows/create_release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 19fdaec07e0..b43adf3ef0e 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-latest, macos-13-xlarge] + runs-on: [ubuntu-latest, macos-13-xlarge] runs-on: ${{ matrix.runs-on }} name: Build steps: diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index ca13a9f0313..81fd087a704 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-latest, macos-13-xlarge] + runs-on: [ubuntu-latest, macos-13-xlarge] runs-on: ${{ matrix.runs-on }} name: Build steps: From 126424119bca114aedd2f25d4b994fe62180dc78 Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Tue, 14 May 2024 18:53:14 +0300 Subject: [PATCH 230/503] highlight nodes shuffled out to auction list --- .../disabled/disabledNodesCoordinator.go | 5 + process/peer/process.go | 5 +- process/peer/process_test.go | 14 +- sharding/nodesCoordinator/dtos.go | 1 + .../nodesCoordinator/hashValidatorShuffler.go | 2 + .../indexHashedNodesCoordinator.go | 25 +++- ...shedNodesCoordinatorRegistryWithAuction.go | 9 +- sharding/nodesCoordinator/interface.go | 8 +- .../nodesCoordinatorRegistryWithAuction.pb.go | 131 ++++++++++++------ .../nodesCoordinatorRegistryWithAuction.proto | 15 +- .../shardingMocks/nodesCoordinatorMock.go | 45 +++--- .../shardingMocks/nodesCoordinatorStub.go | 6 + 12 files changed, 187 insertions(+), 79 deletions(-) diff --git a/epochStart/bootstrap/disabled/disabledNodesCoordinator.go b/epochStart/bootstrap/disabled/disabledNodesCoordinator.go index efee420feec..f7c1502d0c4 100644 --- a/epochStart/bootstrap/disabled/disabledNodesCoordinator.go +++ b/epochStart/bootstrap/disabled/disabledNodesCoordinator.go @@ -54,6 +54,11 @@ func (n *nodesCoordinator) GetAllShuffledOutValidatorsPublicKeys(_ uint32) (map[ return nil, nil } +// GetShuffledOutToAuctionValidatorsPublicKeys - +func (n *nodesCoordinator) GetShuffledOutToAuctionValidatorsPublicKeys(_ uint32) (map[uint32][][]byte, error) { + return nil, nil +} + // GetConsensusValidatorsPublicKeys - func (n *nodesCoordinator) GetConsensusValidatorsPublicKeys(_ []byte, _ uint64, _ uint32, _ uint32) ([]string, error) { return nil, nil diff --git a/process/peer/process.go b/process/peer/process.go index 4c04de6a25d..579d4a16930 100644 --- a/process/peer/process.go +++ b/process/peer/process.go @@ -13,6 +13,8 @@ import ( "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/marshal" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/errChan" "github.com/multiversx/mx-chain-go/common/validatorInfo" @@ -23,7 +25,6 @@ import ( "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/state/accounts" "github.com/multiversx/mx-chain-go/state/parsers" - logger "github.com/multiversx/mx-chain-logger-go" ) var log = logger.GetOrCreate("process/peer") @@ -197,7 +198,7 @@ func (vs *validatorStatistics) saveNodesCoordinatorUpdates(epoch uint32) (bool, nodeForcedToRemain = nodeForcedToRemain || tmpNodeForcedToRemain if vs.enableEpochsHandler.IsFlagEnabled(common.StakingV4Step2Flag) { - nodesMap, err = vs.nodesCoordinator.GetAllShuffledOutValidatorsPublicKeys(epoch) + nodesMap, err = vs.nodesCoordinator.GetShuffledOutToAuctionValidatorsPublicKeys(epoch) if err != nil { return false, err } diff --git a/process/peer/process_test.go b/process/peer/process_test.go index 69adb3e936a..d4c85a5601f 100644 --- a/process/peer/process_test.go +++ b/process/peer/process_test.go @@ -14,6 +14,10 @@ import ( "github.com/multiversx/mx-chain-core-go/core/keyValStorage" "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/block" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/dataRetriever" @@ -33,9 +37,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) const ( @@ -2719,6 +2720,13 @@ func TestValidatorStatisticsProcessor_SaveNodesCoordinatorUpdatesWithStakingV4(t } return mapNodes, nil }, + GetShuffledOutToAuctionValidatorsPublicKeysCalled: func(epoch uint32) (map[uint32][][]byte, error) { + mapNodes := map[uint32][][]byte{ + 0: {pk1}, + core.MetachainShardId: {pk2}, + } + return mapNodes, nil + }, } stakingV4Step2EnableEpochCalledCt := 0 arguments.EnableEpochsHandler = &enableEpochsHandlerMock.EnableEpochsHandlerStub{ diff --git a/sharding/nodesCoordinator/dtos.go b/sharding/nodesCoordinator/dtos.go index ab54bdeb4fa..75c28194a6a 100644 --- a/sharding/nodesCoordinator/dtos.go +++ b/sharding/nodesCoordinator/dtos.go @@ -20,4 +20,5 @@ type ResUpdateNodes struct { ShuffledOut map[uint32][]Validator Leaving []Validator StillRemaining []Validator + LowWaitingList bool } diff --git a/sharding/nodesCoordinator/hashValidatorShuffler.go b/sharding/nodesCoordinator/hashValidatorShuffler.go index ceecc9ca352..7c54e132ffc 100644 --- a/sharding/nodesCoordinator/hashValidatorShuffler.go +++ b/sharding/nodesCoordinator/hashValidatorShuffler.go @@ -10,6 +10,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core/atomic" "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/hashing/sha256" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/epochStart" @@ -350,6 +351,7 @@ func shuffleNodes(arg shuffleNodesArg) (*ResUpdateNodes, error) { ShuffledOut: shuffledOutMap, Leaving: actualLeaving, StillRemaining: stillRemainingInLeaving, + LowWaitingList: lowWaitingList, }, nil } diff --git a/sharding/nodesCoordinator/indexHashedNodesCoordinator.go b/sharding/nodesCoordinator/indexHashedNodesCoordinator.go index f70bce06b04..4deb3f01bcd 100644 --- a/sharding/nodesCoordinator/indexHashedNodesCoordinator.go +++ b/sharding/nodesCoordinator/indexHashedNodesCoordinator.go @@ -15,11 +15,12 @@ import ( "github.com/multiversx/mx-chain-core-go/data/endProcess" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/epochStart" "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/storage" - logger "github.com/multiversx/mx-chain-logger-go" ) var _ NodesCoordinator = (*indexHashedNodesCoordinator)(nil) @@ -68,6 +69,7 @@ type epochNodesConfig struct { newList []Validator auctionList []Validator mutNodesMaps sync.RWMutex + lowWaitingList bool } type indexHashedNodesCoordinator struct { @@ -122,6 +124,7 @@ func NewIndexHashedNodesCoordinator(arguments ArgNodesCoordinator) (*indexHashed shuffledOutMap: make(map[uint32][]Validator), newList: make([]Validator, 0), auctionList: make([]Validator, 0), + lowWaitingList: false, } // todo: if not genesis, use previous randomness from start of epoch meta block @@ -546,6 +549,26 @@ func (ihnc *indexHashedNodesCoordinator) GetAllShuffledOutValidatorsPublicKeys(e return validatorsPubKeys, nil } +// GetShuffledOutToAuctionValidatorsPublicKeys will return shuffled out to auction validators public keys +func (ihnc *indexHashedNodesCoordinator) GetShuffledOutToAuctionValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error) { + validatorsPubKeys := make(map[uint32][][]byte) + + ihnc.mutNodesConfig.RLock() + nodesConfig, ok := ihnc.nodesConfig[epoch] + ihnc.mutNodesConfig.RUnlock() + + if !ok { + return nil, fmt.Errorf("%w epoch=%v", ErrEpochNodesConfigDoesNotExist, epoch) + } + + if nodesConfig.lowWaitingList { + // in case of low waiting list the nodes do not go through auction but directly to waiting + return validatorsPubKeys, nil + } + + return ihnc.GetAllShuffledOutValidatorsPublicKeys(epoch) +} + // GetValidatorsIndexes will return validators indexes for a block func (ihnc *indexHashedNodesCoordinator) GetValidatorsIndexes( publicKeys []string, diff --git a/sharding/nodesCoordinator/indexHashedNodesCoordinatorRegistryWithAuction.go b/sharding/nodesCoordinator/indexHashedNodesCoordinatorRegistryWithAuction.go index 261aa60aefc..76deba81eaa 100644 --- a/sharding/nodesCoordinator/indexHashedNodesCoordinatorRegistryWithAuction.go +++ b/sharding/nodesCoordinator/indexHashedNodesCoordinatorRegistryWithAuction.go @@ -29,10 +29,11 @@ func (ihnc *indexHashedNodesCoordinator) nodesCoordinatorToRegistryWithAuction() func epochNodesConfigToEpochValidatorsWithAuction(config *epochNodesConfig) *EpochValidatorsWithAuction { result := &EpochValidatorsWithAuction{ - Eligible: make(map[string]Validators, len(config.eligibleMap)), - Waiting: make(map[string]Validators, len(config.waitingMap)), - Leaving: make(map[string]Validators, len(config.leavingMap)), - ShuffledOut: make(map[string]Validators, len(config.shuffledOutMap)), + Eligible: make(map[string]Validators, len(config.eligibleMap)), + Waiting: make(map[string]Validators, len(config.waitingMap)), + Leaving: make(map[string]Validators, len(config.leavingMap)), + ShuffledOut: make(map[string]Validators, len(config.shuffledOutMap)), + LowWaitingList: config.lowWaitingList, } for k, v := range config.eligibleMap { diff --git a/sharding/nodesCoordinator/interface.go b/sharding/nodesCoordinator/interface.go index 68dfa9bbb15..b962c6fa50a 100644 --- a/sharding/nodesCoordinator/interface.go +++ b/sharding/nodesCoordinator/interface.go @@ -3,9 +3,10 @@ package nodesCoordinator import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-go/epochStart" "github.com/multiversx/mx-chain-go/state" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) // Validator defines a node that can be allocated to a shard for participation in a consensus group as validator @@ -48,6 +49,7 @@ type PublicKeysSelector interface { GetAllWaitingValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error) GetAllLeavingValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error) GetAllShuffledOutValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error) + GetShuffledOutToAuctionValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error) GetConsensusValidatorsPublicKeys(randomness []byte, round uint64, shardId uint32, epoch uint32) ([]string, error) GetOwnPublicKey() []byte } @@ -68,9 +70,9 @@ type NodesCoordinatorHelper interface { // ChanceComputer provides chance computation capabilities based on a rating type ChanceComputer interface { - //GetChance returns the chances for the rating + // GetChance returns the chances for the rating GetChance(uint32) uint32 - //IsInterfaceNil verifies if the interface is nil + // IsInterfaceNil verifies if the interface is nil IsInterfaceNil() bool } diff --git a/sharding/nodesCoordinator/nodesCoordinatorRegistryWithAuction.pb.go b/sharding/nodesCoordinator/nodesCoordinatorRegistryWithAuction.pb.go index 3c69dc78080..3fa0434075a 100644 --- a/sharding/nodesCoordinator/nodesCoordinatorRegistryWithAuction.pb.go +++ b/sharding/nodesCoordinator/nodesCoordinatorRegistryWithAuction.pb.go @@ -122,10 +122,11 @@ func (m *Validators) GetData() []*SerializableValidator { } type EpochValidatorsWithAuction struct { - Eligible map[string]Validators `protobuf:"bytes,1,rep,name=Eligible,proto3" json:"Eligible" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - Waiting map[string]Validators `protobuf:"bytes,2,rep,name=Waiting,proto3" json:"Waiting" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - Leaving map[string]Validators `protobuf:"bytes,3,rep,name=Leaving,proto3" json:"Leaving" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - ShuffledOut map[string]Validators `protobuf:"bytes,4,rep,name=ShuffledOut,proto3" json:"ShuffledOut" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Eligible map[string]Validators `protobuf:"bytes,1,rep,name=Eligible,proto3" json:"Eligible" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Waiting map[string]Validators `protobuf:"bytes,2,rep,name=Waiting,proto3" json:"Waiting" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Leaving map[string]Validators `protobuf:"bytes,3,rep,name=Leaving,proto3" json:"Leaving" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + ShuffledOut map[string]Validators `protobuf:"bytes,4,rep,name=ShuffledOut,proto3" json:"ShuffledOut" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + LowWaitingList bool `protobuf:"varint,5,opt,name=LowWaitingList,proto3" json:"LowWaitingList,omitempty"` } func (m *EpochValidatorsWithAuction) Reset() { *m = EpochValidatorsWithAuction{} } @@ -184,6 +185,13 @@ func (m *EpochValidatorsWithAuction) GetShuffledOut() map[string]Validators { return nil } +func (m *EpochValidatorsWithAuction) GetLowWaitingList() bool { + if m != nil { + return m.LowWaitingList + } + return false +} + type NodesCoordinatorRegistryWithAuction struct { CurrentEpoch uint32 `protobuf:"varint,1,opt,name=CurrentEpoch,proto3" json:"CurrentEpoch,omitempty"` EpochsConfigWithAuction map[string]*EpochValidatorsWithAuction `protobuf:"bytes,2,rep,name=EpochsConfigWithAuction,proto3" json:"EpochsConfigWithAuction,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` @@ -248,43 +256,44 @@ func init() { } var fileDescriptor_f04461c784f438d5 = []byte{ - // 561 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x94, 0x4f, 0x8f, 0xd2, 0x40, - 0x18, 0xc6, 0x3b, 0xb0, 0x80, 0xfb, 0x02, 0x09, 0x4e, 0x62, 0x6c, 0xc8, 0x66, 0xc0, 0x1a, 0x23, - 0x1e, 0x2c, 0x06, 0x0f, 0x1a, 0x0f, 0x26, 0x82, 0xc4, 0xf8, 0x0f, 0xdd, 0x6e, 0xe2, 0x26, 0x7b, - 0x6b, 0x61, 0x28, 0x13, 0xbb, 0x1d, 0x52, 0xa6, 0x1b, 0xf1, 0xa4, 0xf1, 0x0b, 0xf8, 0x31, 0x3c, - 0xf8, 0x11, 0xfc, 0x00, 0x7b, 0xe4, 0xc8, 0x89, 0x48, 0xb9, 0x18, 0x4e, 0xfb, 0x11, 0x0c, 0xd3, - 0xb2, 0x5b, 0x36, 0x8b, 0x6c, 0xb2, 0x9e, 0x98, 0x3e, 0x33, 0xcf, 0xef, 0x19, 0x1e, 0x5e, 0x0a, - 0xf7, 0x5c, 0xde, 0xa1, 0x83, 0x06, 0xe7, 0x5e, 0x87, 0xb9, 0xa6, 0xe0, 0x9e, 0x41, 0x6d, 0x36, - 0x10, 0xde, 0x70, 0x9f, 0x89, 0xde, 0x33, 0xbf, 0x2d, 0x18, 0x77, 0xf5, 0xbe, 0xc7, 0x05, 0xc7, - 0x29, 0xf9, 0x51, 0xbc, 0x6f, 0x33, 0xd1, 0xf3, 0x2d, 0xbd, 0xcd, 0x0f, 0xab, 0x36, 0xb7, 0x79, - 0x55, 0xca, 0x96, 0xdf, 0x95, 0x4f, 0xf2, 0x41, 0xae, 0x42, 0x97, 0xf6, 0x0d, 0xc1, 0x8d, 0x3d, - 0xea, 0x31, 0xd3, 0x61, 0x9f, 0x4d, 0xcb, 0xa1, 0x1f, 0x4c, 0x87, 0x75, 0x16, 0x41, 0x58, 0x83, - 0xf4, 0x7b, 0xdf, 0x7a, 0x4d, 0x87, 0x2a, 0x2a, 0xa3, 0x4a, 0xae, 0x0e, 0xf3, 0x49, 0x29, 0xdd, - 0x97, 0x8a, 0x11, 0xed, 0xe0, 0x3b, 0x90, 0x69, 0xf4, 0x4c, 0xb7, 0x4d, 0x07, 0x6a, 0xa2, 0x8c, - 0x2a, 0xf9, 0x7a, 0x76, 0x3e, 0x29, 0x65, 0xda, 0xa1, 0x64, 0x2c, 0xf7, 0x70, 0x09, 0x52, 0x2f, - 0xdd, 0x0e, 0xfd, 0xa4, 0x26, 0xe5, 0xa1, 0xed, 0xf9, 0xa4, 0x94, 0x62, 0x0b, 0xc1, 0x08, 0x75, - 0xed, 0x29, 0xc0, 0x69, 0xf0, 0x00, 0x3f, 0x80, 0xad, 0xe7, 0xa6, 0x30, 0x55, 0x54, 0x4e, 0x56, - 0xb2, 0xb5, 0x9d, 0xf0, 0xa6, 0xfa, 0x85, 0xb7, 0x34, 0xe4, 0x49, 0xed, 0x67, 0x0a, 0x8a, 0xcd, - 0x3e, 0x6f, 0xf7, 0xce, 0x28, 0xb1, 0x82, 0xf0, 0x2e, 0x5c, 0x6b, 0x3a, 0xcc, 0x66, 0x96, 0x43, - 0x23, 0x68, 0x35, 0x82, 0xae, 0x37, 0xe9, 0x4b, 0x47, 0xd3, 0x15, 0xde, 0xb0, 0xbe, 0x75, 0x3c, - 0x29, 0x29, 0xc6, 0x29, 0x06, 0xb7, 0x20, 0xb3, 0x6f, 0x32, 0xc1, 0x5c, 0x5b, 0x4d, 0x48, 0xa2, - 0xbe, 0x99, 0x18, 0x19, 0xe2, 0xc0, 0x25, 0x64, 0xc1, 0x7b, 0x43, 0xcd, 0xa3, 0x05, 0x2f, 0x79, - 0x59, 0x5e, 0x64, 0x58, 0xe1, 0x45, 0x1a, 0x3e, 0x80, 0xec, 0x5e, 0xcf, 0xef, 0x76, 0x1d, 0xda, - 0x79, 0xe7, 0x0b, 0x75, 0x4b, 0x32, 0x6b, 0x9b, 0x99, 0x31, 0x53, 0x9c, 0x1b, 0x87, 0x15, 0x5b, - 0x90, 0x5f, 0x29, 0x07, 0x17, 0x20, 0xf9, 0x31, 0x9a, 0x93, 0x6d, 0x63, 0xb1, 0xc4, 0x77, 0x21, - 0x75, 0x64, 0x3a, 0x3e, 0x95, 0x63, 0x91, 0xad, 0x5d, 0x8f, 0x82, 0xcf, 0x32, 0x8d, 0x70, 0xff, - 0x49, 0xe2, 0x31, 0x2a, 0xbe, 0x85, 0x5c, 0xbc, 0x9a, 0xff, 0x80, 0x8b, 0x37, 0x73, 0x55, 0xdc, - 0x2e, 0x14, 0xce, 0x97, 0x72, 0x45, 0xa4, 0xf6, 0x2b, 0x01, 0xb7, 0x5b, 0x9b, 0xff, 0xd8, 0x58, - 0x83, 0x5c, 0xc3, 0xf7, 0x3c, 0xea, 0x0a, 0xf9, 0x8b, 0xc9, 0xbc, 0xbc, 0xb1, 0xa2, 0xe1, 0xaf, - 0x08, 0x6e, 0xca, 0xd5, 0xa0, 0xc1, 0xdd, 0x2e, 0xb3, 0x63, 0xfe, 0x68, 0x32, 0x5f, 0x44, 0x77, - 0xb9, 0x44, 0xa2, 0xbe, 0x86, 0x24, 0xbf, 0xb5, 0xb1, 0x2e, 0xa7, 0x78, 0x08, 0x3b, 0xff, 0x32, - 0x5e, 0x50, 0xd7, 0xa3, 0xd5, 0xba, 0x6e, 0x6d, 0x1c, 0xcc, 0x58, 0x7d, 0xf5, 0x57, 0xa3, 0x29, - 0x51, 0xc6, 0x53, 0xa2, 0x9c, 0x4c, 0x09, 0xfa, 0x12, 0x10, 0xf4, 0x23, 0x20, 0xe8, 0x38, 0x20, - 0x68, 0x14, 0x10, 0x34, 0x0e, 0x08, 0xfa, 0x1d, 0x10, 0xf4, 0x27, 0x20, 0xca, 0x49, 0x40, 0xd0, - 0xf7, 0x19, 0x51, 0x46, 0x33, 0xa2, 0x8c, 0x67, 0x44, 0x39, 0x28, 0x9c, 0x7f, 0x9d, 0x5a, 0x69, - 0x19, 0xfc, 0xf0, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x45, 0x19, 0xc5, 0xc4, 0x69, 0x05, 0x00, - 0x00, + // 580 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x94, 0xc1, 0x8e, 0xd2, 0x40, + 0x18, 0xc7, 0x3b, 0x40, 0x61, 0x77, 0x00, 0x83, 0x93, 0x18, 0x1b, 0xb2, 0x19, 0xb0, 0x46, 0xc5, + 0x83, 0xc5, 0xe0, 0x41, 0xe3, 0xc1, 0x44, 0x90, 0x18, 0x15, 0xd1, 0xed, 0x26, 0x6e, 0xb2, 0xb7, + 0x16, 0x86, 0x32, 0xb1, 0xdb, 0x21, 0xed, 0x74, 0x15, 0x4f, 0x1a, 0x5f, 0xc0, 0xc7, 0xf0, 0x21, + 0x7c, 0x80, 0x3d, 0x72, 0xf0, 0xc0, 0x89, 0x48, 0xb9, 0x18, 0x4e, 0xfb, 0x08, 0x86, 0xa1, 0xec, + 0x16, 0xb2, 0xc8, 0x26, 0xbb, 0x27, 0x66, 0xfe, 0x33, 0xff, 0xdf, 0xf7, 0xf1, 0xef, 0x97, 0x81, + 0xf7, 0x1d, 0xd6, 0x26, 0x5e, 0x8d, 0x31, 0xb7, 0x4d, 0x1d, 0x83, 0x33, 0x57, 0x27, 0x16, 0xf5, + 0xb8, 0xdb, 0xdf, 0xa7, 0xbc, 0xfb, 0xdc, 0x6f, 0x71, 0xca, 0x1c, 0xad, 0xe7, 0x32, 0xce, 0x90, + 0x2c, 0x7e, 0xf2, 0x0f, 0x2c, 0xca, 0xbb, 0xbe, 0xa9, 0xb5, 0xd8, 0x61, 0xd9, 0x62, 0x16, 0x2b, + 0x0b, 0xd9, 0xf4, 0x3b, 0x62, 0x27, 0x36, 0x62, 0x35, 0x77, 0xa9, 0xdf, 0x01, 0xbc, 0xb1, 0x47, + 0x5c, 0x6a, 0xd8, 0xf4, 0x8b, 0x61, 0xda, 0xe4, 0x83, 0x61, 0xd3, 0xf6, 0xac, 0x10, 0x52, 0x61, + 0xf2, 0xbd, 0x6f, 0xbe, 0x21, 0x7d, 0x05, 0x14, 0x41, 0x29, 0x53, 0x85, 0xd3, 0x51, 0x21, 0xd9, + 0x13, 0x8a, 0x1e, 0x9e, 0xa0, 0x3b, 0x30, 0x55, 0xeb, 0x1a, 0x4e, 0x8b, 0x78, 0x4a, 0xac, 0x08, + 0x4a, 0xd9, 0x6a, 0x7a, 0x3a, 0x2a, 0xa4, 0x5a, 0x73, 0x49, 0x5f, 0x9c, 0xa1, 0x02, 0x94, 0x5f, + 0x39, 0x6d, 0xf2, 0x59, 0x89, 0x8b, 0x4b, 0xdb, 0xd3, 0x51, 0x41, 0xa6, 0x33, 0x41, 0x9f, 0xeb, + 0xea, 0x33, 0x08, 0x4f, 0x0b, 0x7b, 0xe8, 0x21, 0x4c, 0xbc, 0x30, 0xb8, 0xa1, 0x80, 0x62, 0xbc, + 0x94, 0xae, 0xec, 0xcc, 0x3b, 0xd5, 0xce, 0xed, 0x52, 0x17, 0x37, 0xd5, 0xdf, 0x32, 0xcc, 0xd7, + 0x7b, 0xac, 0xd5, 0x3d, 0xa3, 0x44, 0x02, 0x42, 0xbb, 0x70, 0xab, 0x6e, 0x53, 0x8b, 0x9a, 0x36, + 0x09, 0xa1, 0xe5, 0x10, 0xba, 0xde, 0xa4, 0x2d, 0x1c, 0x75, 0x87, 0xbb, 0xfd, 0x6a, 0xe2, 0x78, + 0x54, 0x90, 0xf4, 0x53, 0x0c, 0x6a, 0xc2, 0xd4, 0xbe, 0x41, 0x39, 0x75, 0x2c, 0x25, 0x26, 0x88, + 0xda, 0x66, 0x62, 0x68, 0x88, 0x02, 0x17, 0x90, 0x19, 0xaf, 0x41, 0x8c, 0xa3, 0x19, 0x2f, 0x7e, + 0x51, 0x5e, 0x68, 0x58, 0xe2, 0x85, 0x1a, 0x3a, 0x80, 0xe9, 0xbd, 0xae, 0xdf, 0xe9, 0xd8, 0xa4, + 0xfd, 0xce, 0xe7, 0x4a, 0x42, 0x30, 0x2b, 0x9b, 0x99, 0x11, 0x53, 0x94, 0x1b, 0x85, 0xa1, 0xbb, + 0xf0, 0x5a, 0x83, 0x7d, 0x0a, 0x3b, 0x6f, 0x50, 0x8f, 0x2b, 0x72, 0x11, 0x94, 0xb6, 0xf4, 0x15, + 0x35, 0xdf, 0x84, 0xd9, 0xa5, 0x10, 0x51, 0x0e, 0xc6, 0x3f, 0x86, 0xf3, 0xb4, 0xad, 0xcf, 0x96, + 0xe8, 0x1e, 0x94, 0x8f, 0x0c, 0xdb, 0x27, 0x62, 0x7c, 0xd2, 0x95, 0xeb, 0x61, 0x83, 0x67, 0xbd, + 0xe9, 0xf3, 0xf3, 0xa7, 0xb1, 0x27, 0x20, 0xff, 0x16, 0x66, 0xa2, 0x11, 0x5e, 0x01, 0x2e, 0x9a, + 0xe0, 0x65, 0x71, 0xbb, 0x30, 0xb7, 0x1a, 0xde, 0x25, 0x91, 0xea, 0xaf, 0x18, 0xbc, 0xdd, 0xdc, + 0xfc, 0x00, 0x20, 0x15, 0x66, 0x6a, 0xbe, 0xeb, 0x12, 0x87, 0x8b, 0x2f, 0x2b, 0xea, 0x65, 0xf5, + 0x25, 0x0d, 0x7d, 0x03, 0xf0, 0xa6, 0x58, 0x79, 0x35, 0xe6, 0x74, 0xa8, 0x15, 0xf1, 0x87, 0x13, + 0xfc, 0x32, 0xec, 0xe5, 0x02, 0x15, 0xb5, 0x35, 0x24, 0xf1, 0xaf, 0xf5, 0x75, 0x75, 0xf2, 0x87, + 0x70, 0xe7, 0x7f, 0xc6, 0x73, 0xe2, 0x7a, 0xbc, 0x1c, 0xd7, 0xad, 0x8d, 0x03, 0x1c, 0x89, 0xaf, + 0xfa, 0x7a, 0x30, 0xc6, 0xd2, 0x70, 0x8c, 0xa5, 0x93, 0x31, 0x06, 0x5f, 0x03, 0x0c, 0x7e, 0x06, + 0x18, 0x1c, 0x07, 0x18, 0x0c, 0x02, 0x0c, 0x86, 0x01, 0x06, 0x7f, 0x02, 0x0c, 0xfe, 0x06, 0x58, + 0x3a, 0x09, 0x30, 0xf8, 0x31, 0xc1, 0xd2, 0x60, 0x82, 0xa5, 0xe1, 0x04, 0x4b, 0x07, 0xb9, 0xd5, + 0x67, 0xd7, 0x4c, 0x8a, 0xc2, 0x8f, 0xfe, 0x05, 0x00, 0x00, 0xff, 0xff, 0x65, 0xa3, 0xf9, 0xfb, + 0x91, 0x05, 0x00, 0x00, } func (this *SerializableValidator) Equal(that interface{}) bool { @@ -405,6 +414,9 @@ func (this *EpochValidatorsWithAuction) Equal(that interface{}) bool { return false } } + if this.LowWaitingList != that1.LowWaitingList { + return false + } return true } func (this *NodesCoordinatorRegistryWithAuction) Equal(that interface{}) bool { @@ -467,7 +479,7 @@ func (this *EpochValidatorsWithAuction) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 8) + s := make([]string, 0, 9) s = append(s, "&nodesCoordinator.EpochValidatorsWithAuction{") keysForEligible := make([]string, 0, len(this.Eligible)) for k, _ := range this.Eligible { @@ -521,6 +533,7 @@ func (this *EpochValidatorsWithAuction) GoString() string { if this.ShuffledOut != nil { s = append(s, "ShuffledOut: "+mapStringForShuffledOut+",\n") } + s = append(s, "LowWaitingList: "+fmt.Sprintf("%#v", this.LowWaitingList)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -652,6 +665,16 @@ func (m *EpochValidatorsWithAuction) MarshalToSizedBuffer(dAtA []byte) (int, err _ = i var l int _ = l + if m.LowWaitingList { + i-- + if m.LowWaitingList { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x28 + } if len(m.ShuffledOut) > 0 { keysForShuffledOut := make([]string, 0, len(m.ShuffledOut)) for k := range m.ShuffledOut { @@ -917,6 +940,9 @@ func (m *EpochValidatorsWithAuction) Size() (n int) { n += mapEntrySize + 1 + sovNodesCoordinatorRegistryWithAuction(uint64(mapEntrySize)) } } + if m.LowWaitingList { + n += 2 + } return n } @@ -1027,6 +1053,7 @@ func (this *EpochValidatorsWithAuction) String() string { `Waiting:` + mapStringForWaiting + `,`, `Leaving:` + mapStringForLeaving + `,`, `ShuffledOut:` + mapStringForShuffledOut + `,`, + `LowWaitingList:` + fmt.Sprintf("%v", this.LowWaitingList) + `,`, `}`, }, "") return s @@ -1817,6 +1844,26 @@ func (m *EpochValidatorsWithAuction) Unmarshal(dAtA []byte) error { } m.ShuffledOut[mapkey] = *mapvalue iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field LowWaitingList", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNodesCoordinatorRegistryWithAuction + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.LowWaitingList = bool(v != 0) default: iNdEx = preIndex skippy, err := skipNodesCoordinatorRegistryWithAuction(dAtA[iNdEx:]) diff --git a/sharding/nodesCoordinator/nodesCoordinatorRegistryWithAuction.proto b/sharding/nodesCoordinator/nodesCoordinatorRegistryWithAuction.proto index 3ff1c90acb1..d4b3ef455bd 100644 --- a/sharding/nodesCoordinator/nodesCoordinatorRegistryWithAuction.proto +++ b/sharding/nodesCoordinator/nodesCoordinatorRegistryWithAuction.proto @@ -8,9 +8,9 @@ option (gogoproto.stable_marshaler_all) = true; import "github.com/gogo/protobuf/gogoproto/gogo.proto"; message SerializableValidator { - bytes PubKey = 1 [(gogoproto.jsontag) = "pubKey"]; + bytes PubKey = 1 [(gogoproto.jsontag) = "pubKey"]; uint32 Chances = 2 [(gogoproto.jsontag) = "chances"]; - uint32 Index = 3 [(gogoproto.jsontag) = "index"]; + uint32 Index = 3 [(gogoproto.jsontag) = "index"]; } message Validators { @@ -18,13 +18,14 @@ message Validators { } message EpochValidatorsWithAuction { - map Eligible = 1 [(gogoproto.nullable) = false]; - map Waiting = 2 [(gogoproto.nullable) = false]; - map Leaving = 3 [(gogoproto.nullable) = false]; - map ShuffledOut = 4 [(gogoproto.nullable) = false]; + map Eligible = 1 [(gogoproto.nullable) = false]; + map Waiting = 2 [(gogoproto.nullable) = false]; + map Leaving = 3 [(gogoproto.nullable) = false]; + map ShuffledOut = 4 [(gogoproto.nullable) = false]; + bool LowWaitingList = 5; } message NodesCoordinatorRegistryWithAuction { - uint32 CurrentEpoch = 1; + uint32 CurrentEpoch = 1; map EpochsConfigWithAuction = 2; } diff --git a/testscommon/shardingMocks/nodesCoordinatorMock.go b/testscommon/shardingMocks/nodesCoordinatorMock.go index 3ee80f88d3d..9f1b872e2ab 100644 --- a/testscommon/shardingMocks/nodesCoordinatorMock.go +++ b/testscommon/shardingMocks/nodesCoordinatorMock.go @@ -5,29 +5,31 @@ import ( "fmt" "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "github.com/multiversx/mx-chain-go/state" ) // NodesCoordinatorMock defines the behaviour of a struct able to do validator group selection type NodesCoordinatorMock struct { - Validators map[uint32][]nodesCoordinator.Validator - ShardConsensusSize uint32 - MetaConsensusSize uint32 - ShardId uint32 - NbShards uint32 - GetSelectedPublicKeysCalled func(selection []byte, shardId uint32, epoch uint32) (publicKeys []string, err error) - GetValidatorsPublicKeysCalled func(randomness []byte, round uint64, shardId uint32, epoch uint32) ([]string, error) - GetValidatorsRewardsAddressesCalled func(randomness []byte, round uint64, shardId uint32, epoch uint32) ([]string, error) - SetNodesPerShardsCalled func(nodes map[uint32][]nodesCoordinator.Validator, epoch uint32) error - ComputeValidatorsGroupCalled func(randomness []byte, round uint64, shardId uint32, epoch uint32) (validatorsGroup []nodesCoordinator.Validator, err error) - GetValidatorWithPublicKeyCalled func(publicKey []byte) (validator nodesCoordinator.Validator, shardId uint32, err error) - GetAllEligibleValidatorsPublicKeysCalled func(epoch uint32) (map[uint32][][]byte, error) - GetAllWaitingValidatorsPublicKeysCalled func() (map[uint32][][]byte, error) - ConsensusGroupSizeCalled func(uint32) int - GetValidatorsIndexesCalled func(publicKeys []string, epoch uint32) ([]uint64, error) - GetAllShuffledOutValidatorsPublicKeysCalled func(epoch uint32) (map[uint32][][]byte, error) - GetNumTotalEligibleCalled func() uint64 + Validators map[uint32][]nodesCoordinator.Validator + ShardConsensusSize uint32 + MetaConsensusSize uint32 + ShardId uint32 + NbShards uint32 + GetSelectedPublicKeysCalled func(selection []byte, shardId uint32, epoch uint32) (publicKeys []string, err error) + GetValidatorsPublicKeysCalled func(randomness []byte, round uint64, shardId uint32, epoch uint32) ([]string, error) + GetValidatorsRewardsAddressesCalled func(randomness []byte, round uint64, shardId uint32, epoch uint32) ([]string, error) + SetNodesPerShardsCalled func(nodes map[uint32][]nodesCoordinator.Validator, epoch uint32) error + ComputeValidatorsGroupCalled func(randomness []byte, round uint64, shardId uint32, epoch uint32) (validatorsGroup []nodesCoordinator.Validator, err error) + GetValidatorWithPublicKeyCalled func(publicKey []byte) (validator nodesCoordinator.Validator, shardId uint32, err error) + GetAllEligibleValidatorsPublicKeysCalled func(epoch uint32) (map[uint32][][]byte, error) + GetAllWaitingValidatorsPublicKeysCalled func() (map[uint32][][]byte, error) + ConsensusGroupSizeCalled func(uint32) int + GetValidatorsIndexesCalled func(publicKeys []string, epoch uint32) ([]uint64, error) + GetAllShuffledOutValidatorsPublicKeysCalled func(epoch uint32) (map[uint32][][]byte, error) + GetShuffledOutToAuctionValidatorsPublicKeysCalled func(epoch uint32) (map[uint32][][]byte, error) + GetNumTotalEligibleCalled func() uint64 } // NewNodesCoordinatorMock - @@ -110,6 +112,15 @@ func (ncm *NodesCoordinatorMock) GetAllShuffledOutValidatorsPublicKeys(epoch uin return nil, nil } +// GetShuffledOutToAuctionValidatorsPublicKeys - +func (ncm *NodesCoordinatorMock) GetShuffledOutToAuctionValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error) { + if ncm.GetShuffledOutToAuctionValidatorsPublicKeysCalled != nil { + return ncm.GetShuffledOutToAuctionValidatorsPublicKeysCalled(epoch) + } + + return nil, nil +} + // GetValidatorsIndexes - func (ncm *NodesCoordinatorMock) GetValidatorsIndexes(publicKeys []string, epoch uint32) ([]uint64, error) { if ncm.GetValidatorsIndexesCalled != nil { diff --git a/testscommon/shardingMocks/nodesCoordinatorStub.go b/testscommon/shardingMocks/nodesCoordinatorStub.go index 9f82a5256e5..a142f0509ed 100644 --- a/testscommon/shardingMocks/nodesCoordinatorStub.go +++ b/testscommon/shardingMocks/nodesCoordinatorStub.go @@ -2,6 +2,7 @@ package shardingMocks import ( "github.com/multiversx/mx-chain-core-go/data" + "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "github.com/multiversx/mx-chain-go/state" ) @@ -82,6 +83,11 @@ func (ncm *NodesCoordinatorStub) GetAllShuffledOutValidatorsPublicKeys(_ uint32) return nil, nil } +// GetShuffledOutToAuctionValidatorsPublicKeys - +func (ncm *NodesCoordinatorStub) GetShuffledOutToAuctionValidatorsPublicKeys(_ uint32) (map[uint32][][]byte, error) { + return nil, nil +} + // GetNumTotalEligible - func (ncm *NodesCoordinatorStub) GetNumTotalEligible() uint64 { if ncm.GetNumTotalEligibleCalled != nil { From 2bb0754624ee0f216878c5472a478242cb736ee4 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 15 May 2024 11:54:41 +0300 Subject: [PATCH 231/503] added missing config --- cmd/node/config/config.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/node/config/config.toml b/cmd/node/config/config.toml index b6c11452a64..f434fd3398d 100644 --- a/cmd/node/config/config.toml +++ b/cmd/node/config/config.toml @@ -940,3 +940,6 @@ # MaxRoundsOfInactivityAccepted defines the number of rounds missed by a main or higher level backup machine before # the current machine will take over and propose/sign blocks. Used in both single-key and multi-key modes. MaxRoundsOfInactivityAccepted = 3 + +[RelayedTransactionConfig] + MaxTransactionsAllowed = 50 From f79acdf7b24fdd18498772b39bc8ae360a3d64ff Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Wed, 15 May 2024 13:11:01 +0300 Subject: [PATCH 232/503] fix nodes config update after shuffling and add chain simulator scenario --- .../staking/stake/stakeAndUnStake_test.go | 113 +++++++++++++++++- .../indexHashedNodesCoordinator.go | 6 +- .../indexHashedNodesCoordinatorLite.go | 2 +- ...dexHashedNodesCoordinatorWithRater_test.go | 19 +-- .../indexHashedNodesCoordinator_test.go | 27 +++-- 5 files changed, 140 insertions(+), 27 deletions(-) diff --git a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index 57a8df77cec..c29f5cab9b0 100644 --- a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go @@ -12,6 +12,9 @@ import ( coreAPI "github.com/multiversx/mx-chain-core-go/data/api" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-core-go/data/validator" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" @@ -23,8 +26,6 @@ import ( chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/vm" - logger "github.com/multiversx/mx-chain-logger-go" - "github.com/stretchr/testify/require" ) const ( @@ -2383,6 +2384,114 @@ func TestChainSimulator_UnStakeOneActiveNodeAndCheckAPIAuctionList(t *testing.T) require.Equal(t, 1, numUnQualified) } +// Nodes configuration at genesis consisting of a total of 40 nodes, distributed on 3 shards + meta: +// - 4 eligible nodes/shard +// - 4 waiting nodes/shard +// - 2 nodes to shuffle per shard +// - max num nodes config for stakingV4 step3 = 32 (being downsized from previously 40 nodes) +// - with this config, we should always select max 8 nodes from auction list if there are > 40 nodes in the network +// This test will run with only 32 nodes and check that there are no nodes in the auction list, +// because of the lowWaitingList condition being triggered when in staking v4 +func TestChainSimulator_EdgeCaseLowWaitingList(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + stakingV4Step1Epoch := uint32(2) + stakingV4Step2Epoch := uint32(3) + stakingV4Step3Epoch := uint32(4) + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 4, + MetaChainMinNodes: 4, + NumNodesWaitingListMeta: 2, + NumNodesWaitingListShard: 2, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = stakingV4Step1Epoch + cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = stakingV4Step2Epoch + cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = stakingV4Step3Epoch + + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[1].MaxNumNodes = 40 + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[1].NodesToShufflePerShard = 2 + + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = stakingV4Step3Epoch + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].MaxNumNodes = 32 + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].NodesToShufflePerShard = 2 + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + epochToCheck := int32(stakingV4Step3Epoch + 1) + err = cs.GenerateBlocksUntilEpochIsReached(epochToCheck) + require.Nil(t, err) + + metachainNode := cs.GetNodeHandler(core.MetachainShardId) + numQualified, numUnQualified := getNumQualifiedAndUnqualified(t, metachainNode) + require.Equal(t, 0, numQualified) + require.Equal(t, 0, numUnQualified) + + // we always have 0 in auction list because of the lowWaitingList condition + epochToCheck += 1 + err = cs.GenerateBlocksUntilEpochIsReached(epochToCheck) + numQualified, numUnQualified = getNumQualifiedAndUnqualified(t, metachainNode) + require.Equal(t, 0, numQualified) + require.Equal(t, 0, numUnQualified) + + // stake 16 mode nodes, these will go to auction list + stakeNodes(t, cs, 16) + + epochToCheck += 1 + err = cs.GenerateBlocksUntilEpochIsReached(epochToCheck) + numQualified, numUnQualified = getNumQualifiedAndUnqualified(t, metachainNode) + // all the previously registered will be selected, as we have 24 nodes in eligible+waiting, 8 will shuffle out, + // but this time there will be not be lowWaitingList, as there are enough in auction, so we will end up with + // 24-8 = 16 nodes remaining + 16 from auction, to fill up all 32 positions + require.Equal(t, 16, numQualified) + require.Equal(t, 0, numUnQualified) +} + +func stakeNodes(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, numTxs int) { + txs := make([]*transaction.Transaction, numTxs) + for i := 0; i < numTxs; i++ { + privateKey, blsKeys, err := chainSimulator.GenerateBlsPrivateKeys(1) + require.Nil(t, err) + err = cs.AddValidatorKeys(privateKey) + require.Nil(t, err) + + mintValue := big.NewInt(0).Add(staking.MinimumStakeValue, staking.OneEGLD) + validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) + require.Nil(t, err) + + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txs[i] = staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + } + stakeTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted(txs, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, stakeTxs) + require.Len(t, stakeTxs, numTxs) + + require.Nil(t, cs.GenerateBlocks(1)) +} + func stakeOneNode(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator) { privateKey, blsKeys, err := chainSimulator.GenerateBlsPrivateKeys(1) require.Nil(t, err) diff --git a/sharding/nodesCoordinator/indexHashedNodesCoordinator.go b/sharding/nodesCoordinator/indexHashedNodesCoordinator.go index 4deb3f01bcd..4898f018010 100644 --- a/sharding/nodesCoordinator/indexHashedNodesCoordinator.go +++ b/sharding/nodesCoordinator/indexHashedNodesCoordinator.go @@ -159,7 +159,7 @@ func NewIndexHashedNodesCoordinator(arguments ArgNodesCoordinator) (*indexHashed ihnc.loadingFromDisk.Store(false) ihnc.nodesCoordinatorHelper = ihnc - err = ihnc.setNodesPerShards(arguments.EligibleNodes, arguments.WaitingNodes, nil, nil, arguments.Epoch) + err = ihnc.setNodesPerShards(arguments.EligibleNodes, arguments.WaitingNodes, nil, nil, arguments.Epoch, false) if err != nil { return nil, err } @@ -260,6 +260,7 @@ func (ihnc *indexHashedNodesCoordinator) setNodesPerShards( leaving map[uint32][]Validator, shuffledOut map[uint32][]Validator, epoch uint32, + lowWaitingList bool, ) error { ihnc.mutNodesConfig.Lock() defer ihnc.mutNodesConfig.Unlock() @@ -299,6 +300,7 @@ func (ihnc *indexHashedNodesCoordinator) setNodesPerShards( nodesConfig.waitingMap = waiting nodesConfig.leavingMap = leaving nodesConfig.shuffledOutMap = shuffledOut + nodesConfig.lowWaitingList = lowWaitingList nodesConfig.shardID, isCurrentNodeValidator = ihnc.computeShardForSelfPublicKey(nodesConfig) nodesConfig.selectors, err = ihnc.createSelectors(nodesConfig) if err != nil { @@ -685,7 +687,7 @@ func (ihnc *indexHashedNodesCoordinator) EpochStartPrepare(metaHdr data.HeaderHa resUpdateNodes.Leaving, ) - err = ihnc.setNodesPerShards(resUpdateNodes.Eligible, resUpdateNodes.Waiting, leavingNodesMap, resUpdateNodes.ShuffledOut, newEpoch) + err = ihnc.setNodesPerShards(resUpdateNodes.Eligible, resUpdateNodes.Waiting, leavingNodesMap, resUpdateNodes.ShuffledOut, newEpoch, resUpdateNodes.LowWaitingList) if err != nil { log.Error("set nodes per shard failed", "error", err.Error()) } diff --git a/sharding/nodesCoordinator/indexHashedNodesCoordinatorLite.go b/sharding/nodesCoordinator/indexHashedNodesCoordinatorLite.go index 3b80e8bdd23..b5b87781a73 100644 --- a/sharding/nodesCoordinator/indexHashedNodesCoordinatorLite.go +++ b/sharding/nodesCoordinator/indexHashedNodesCoordinatorLite.go @@ -41,7 +41,7 @@ func (ihnc *indexHashedNodesCoordinator) SetNodesConfigFromValidatorsInfo(epoch resUpdateNodes.Leaving, ) - err = ihnc.setNodesPerShards(resUpdateNodes.Eligible, resUpdateNodes.Waiting, leavingNodesMap, resUpdateNodes.ShuffledOut, epoch) + err = ihnc.setNodesPerShards(resUpdateNodes.Eligible, resUpdateNodes.Waiting, leavingNodesMap, resUpdateNodes.ShuffledOut, epoch, resUpdateNodes.LowWaitingList) if err != nil { return err } diff --git a/sharding/nodesCoordinator/indexHashedNodesCoordinatorWithRater_test.go b/sharding/nodesCoordinator/indexHashedNodesCoordinatorWithRater_test.go index 40286a0c135..a80006cceae 100644 --- a/sharding/nodesCoordinator/indexHashedNodesCoordinatorWithRater_test.go +++ b/sharding/nodesCoordinator/indexHashedNodesCoordinatorWithRater_test.go @@ -13,6 +13,9 @@ import ( "github.com/multiversx/mx-chain-core-go/data/endProcess" "github.com/multiversx/mx-chain-core-go/hashing/blake2b" "github.com/multiversx/mx-chain-core-go/hashing/sha256" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/sharding/mock" "github.com/multiversx/mx-chain-go/state" @@ -20,8 +23,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/nodeTypeProviderMock" vic "github.com/multiversx/mx-chain-go/testscommon/validatorInfoCacher" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestNewIndexHashedNodesCoordinatorWithRater_NilRaterShouldErr(t *testing.T) { @@ -48,14 +49,14 @@ func TestNewIndexHashedGroupSelectorWithRater_OkValsShouldWork(t *testing.T) { assert.Nil(t, err) } -//------- LoadEligibleList +// ------- LoadEligibleList func TestIndexHashedGroupSelectorWithRater_SetNilEligibleMapShouldErr(t *testing.T) { t.Parallel() waiting := createDummyNodesMap(2, 1, "waiting") nc, _ := NewIndexHashedNodesCoordinator(createArguments()) ihnc, _ := NewIndexHashedNodesCoordinatorWithRater(nc, &mock.RaterMock{}) - assert.Equal(t, ErrNilInputNodesMap, ihnc.setNodesPerShards(nil, waiting, nil, nil, 0)) + assert.Equal(t, ErrNilInputNodesMap, ihnc.setNodesPerShards(nil, waiting, nil, nil, 0, false)) } func TestIndexHashedGroupSelectorWithRater_OkValShouldWork(t *testing.T) { @@ -113,7 +114,7 @@ func TestIndexHashedGroupSelectorWithRater_OkValShouldWork(t *testing.T) { assert.Equal(t, eligibleMap[0], readEligible) } -//------- functionality tests +// ------- functionality tests func TestIndexHashedGroupSelectorWithRater_ComputeValidatorsGroup1ValidatorShouldNotCallGetRating(t *testing.T) { t.Parallel() @@ -149,7 +150,7 @@ func BenchmarkIndexHashedGroupSelectorWithRater_ComputeValidatorsGroup63of400(b consensusGroupSize := 63 list := make([]Validator, 0) - //generate 400 validators + // generate 400 validators for i := 0; i < 400; i++ { list = append(list, newValidatorMock([]byte("pk"+strconv.Itoa(i)), 1, defaultSelectionChances)) } @@ -219,7 +220,7 @@ func Test_ComputeValidatorsGroup63of400(t *testing.T) { shardSize := uint32(400) list := make([]Validator, 0) - //generate 400 validators + // generate 400 validators for i := uint32(0); i < shardSize; i++ { list = append(list, newValidatorMock([]byte(fmt.Sprintf("pk%v", i)), 1, defaultSelectionChances)) } @@ -785,7 +786,7 @@ func BenchmarkIndexHashedGroupSelectorWithRater_TestExpandList(b *testing.B) { } } - //a := []int{1, 2, 3, 4, 5, 6, 7, 8} + // a := []int{1, 2, 3, 4, 5, 6, 7, 8} rnd := rand.New(rand.NewSource(time.Now().UnixNano())) rnd.Shuffle(len(array), func(i, j int) { array[i], array[j] = array[j], array[i] }) m2 := runtime.MemStats{} @@ -820,7 +821,7 @@ func BenchmarkIndexHashedWithRaterGroupSelector_ComputeValidatorsGroup21of400(b consensusGroupSize := 21 list := make([]Validator, 0) - //generate 400 validators + // generate 400 validators for i := 0; i < 400; i++ { list = append(list, newValidatorMock([]byte("pk"+strconv.Itoa(i)), 1, defaultSelectionChances)) } diff --git a/sharding/nodesCoordinator/indexHashedNodesCoordinator_test.go b/sharding/nodesCoordinator/indexHashedNodesCoordinator_test.go index 5db65609f59..32cc2ca8326 100644 --- a/sharding/nodesCoordinator/indexHashedNodesCoordinator_test.go +++ b/sharding/nodesCoordinator/indexHashedNodesCoordinator_test.go @@ -20,6 +20,9 @@ import ( "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/hashing/sha256" "github.com/multiversx/mx-chain-core-go/marshal" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/dataRetriever/dataPool" "github.com/multiversx/mx-chain-go/epochStart" @@ -31,8 +34,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/nodeTypeProviderMock" vic "github.com/multiversx/mx-chain-go/testscommon/validatorInfoCacher" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) const stakingV4Epoch = 444 @@ -145,7 +146,7 @@ func validatorsPubKeys(validators []Validator) []string { return pKeys } -//------- NewIndexHashedNodesCoordinator +// ------- NewIndexHashedNodesCoordinator func TestNewIndexHashedNodesCoordinator_NilHasherShouldErr(t *testing.T) { t.Parallel() @@ -247,7 +248,7 @@ func TestNewIndexHashedGroupSelector_OkValsShouldWork(t *testing.T) { require.Nil(t, err) } -//------- LoadEligibleList +// ------- LoadEligibleList func TestIndexHashedNodesCoordinator_SetNilEligibleMapShouldErr(t *testing.T) { t.Parallel() @@ -256,7 +257,7 @@ func TestIndexHashedNodesCoordinator_SetNilEligibleMapShouldErr(t *testing.T) { arguments := createArguments() ihnc, _ := NewIndexHashedNodesCoordinator(arguments) - require.Equal(t, ErrNilInputNodesMap, ihnc.setNodesPerShards(nil, waitingMap, nil, nil, 0)) + require.Equal(t, ErrNilInputNodesMap, ihnc.setNodesPerShards(nil, waitingMap, nil, nil, 0, false)) } func TestIndexHashedNodesCoordinator_SetNilWaitingMapShouldErr(t *testing.T) { @@ -266,7 +267,7 @@ func TestIndexHashedNodesCoordinator_SetNilWaitingMapShouldErr(t *testing.T) { arguments := createArguments() ihnc, _ := NewIndexHashedNodesCoordinator(arguments) - require.Equal(t, ErrNilInputNodesMap, ihnc.setNodesPerShards(eligibleMap, nil, nil, nil, 0)) + require.Equal(t, ErrNilInputNodesMap, ihnc.setNodesPerShards(eligibleMap, nil, nil, nil, 0, false)) } func TestIndexHashedNodesCoordinator_OkValShouldWork(t *testing.T) { @@ -319,7 +320,7 @@ func TestIndexHashedNodesCoordinator_OkValShouldWork(t *testing.T) { require.Equal(t, eligibleMap[0], readEligible) } -//------- ComputeValidatorsGroup +// ------- ComputeValidatorsGroup func TestIndexHashedNodesCoordinator_NewCoordinatorGroup0SizeShouldErr(t *testing.T) { t.Parallel() @@ -401,7 +402,7 @@ func TestIndexHashedNodesCoordinator_ComputeValidatorsGroupInvalidShardIdShouldE require.Nil(t, list2) } -//------- functionality tests +// ------- functionality tests func TestIndexHashedNodesCoordinator_ComputeValidatorsGroup1ValidatorShouldReturnSame(t *testing.T) { t.Parallel() @@ -558,7 +559,7 @@ func TestIndexHashedNodesCoordinator_ComputeValidatorsGroup400of400For10BlocksMe mut := sync.Mutex{} - //consensusGroup := list[0:21] + // consensusGroup := list[0:21] cacheMap := make(map[string]interface{}) lruCache := &mock.NodesCoordinatorCacheMock{ PutCalled: func(key []byte, value interface{}, sizeInBytes int) (evicted bool) { @@ -1275,7 +1276,7 @@ func TestIndexHashedNodesCoordinator_setNodesPerShardsShouldTriggerWrongConfigur }, } - err = ihnc.setNodesPerShards(eligibleMap, map[uint32][]Validator{}, map[uint32][]Validator{}, map[uint32][]Validator{}, 2) + err = ihnc.setNodesPerShards(eligibleMap, map[uint32][]Validator{}, map[uint32][]Validator{}, map[uint32][]Validator{}, 2, false) require.NoError(t, err) value := <-chanStopNode @@ -1301,7 +1302,7 @@ func TestIndexHashedNodesCoordinator_setNodesPerShardsShouldNotTriggerWrongConfi }, } - err = ihnc.setNodesPerShards(eligibleMap, map[uint32][]Validator{}, map[uint32][]Validator{}, map[uint32][]Validator{}, 2) + err = ihnc.setNodesPerShards(eligibleMap, map[uint32][]Validator{}, map[uint32][]Validator{}, map[uint32][]Validator{}, 2, false) require.NoError(t, err) require.Empty(t, chanStopNode) @@ -1333,7 +1334,7 @@ func TestIndexHashedNodesCoordinator_setNodesPerShardsShouldSetNodeTypeValidator }, } - err = ihnc.setNodesPerShards(eligibleMap, map[uint32][]Validator{}, map[uint32][]Validator{}, map[uint32][]Validator{}, 2) + err = ihnc.setNodesPerShards(eligibleMap, map[uint32][]Validator{}, map[uint32][]Validator{}, map[uint32][]Validator{}, 2, false) require.NoError(t, err) require.True(t, setTypeWasCalled) require.Equal(t, core.NodeTypeValidator, nodeTypeResult) @@ -1365,7 +1366,7 @@ func TestIndexHashedNodesCoordinator_setNodesPerShardsShouldSetNodeTypeObserver( }, } - err = ihnc.setNodesPerShards(eligibleMap, map[uint32][]Validator{}, map[uint32][]Validator{}, map[uint32][]Validator{}, 2) + err = ihnc.setNodesPerShards(eligibleMap, map[uint32][]Validator{}, map[uint32][]Validator{}, map[uint32][]Validator{}, 2, false) require.NoError(t, err) require.True(t, setTypeWasCalled) require.Equal(t, core.NodeTypeObserver, nodeTypeResult) From 643030750d923256f74159f6f623964b03dc7c8e Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Wed, 15 May 2024 13:24:19 +0300 Subject: [PATCH 233/503] fix linter issues --- .../chainSimulator/staking/stake/stakeAndUnStake_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index c29f5cab9b0..d876545a124 100644 --- a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go @@ -2452,6 +2452,8 @@ func TestChainSimulator_EdgeCaseLowWaitingList(t *testing.T) { // we always have 0 in auction list because of the lowWaitingList condition epochToCheck += 1 err = cs.GenerateBlocksUntilEpochIsReached(epochToCheck) + require.Nil(t, err) + numQualified, numUnQualified = getNumQualifiedAndUnqualified(t, metachainNode) require.Equal(t, 0, numQualified) require.Equal(t, 0, numUnQualified) @@ -2461,6 +2463,8 @@ func TestChainSimulator_EdgeCaseLowWaitingList(t *testing.T) { epochToCheck += 1 err = cs.GenerateBlocksUntilEpochIsReached(epochToCheck) + require.Nil(t, err) + numQualified, numUnQualified = getNumQualifiedAndUnqualified(t, metachainNode) // all the previously registered will be selected, as we have 24 nodes in eligible+waiting, 8 will shuffle out, // but this time there will be not be lowWaitingList, as there are enough in auction, so we will end up with From b9c087e984f393dfefcc6881b805f94b20f76962 Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Wed, 15 May 2024 14:41:24 +0300 Subject: [PATCH 234/503] fix integration tests --- .../stakingProvider/delegation_test.go | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index ad238766068..3ee5971a502 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go @@ -15,6 +15,10 @@ import ( "github.com/multiversx/mx-chain-crypto-go/signing" "github.com/multiversx/mx-chain-crypto-go/signing/mcl" mclsig "github.com/multiversx/mx-chain-crypto-go/signing/mcl/singlesig" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" @@ -25,9 +29,6 @@ import ( chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/vm" - logger "github.com/multiversx/mx-chain-logger-go" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) var log = logger.GetOrCreate("stakingProvider") @@ -399,11 +400,25 @@ func testBLSKeyIsInAuction( currentEpoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetCurrentEpoch() if metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step2Flag) == currentEpoch { // starting from phase 2, we have the shuffled out nodes from the previous epoch in the action list - actionListSize += 8 + // if there is no lowWaitingList condition + shuffledToAuctionValPubKeys, err := metachainNode.GetProcessComponents().NodesCoordinator().GetShuffledOutToAuctionValidatorsPublicKeys(currentEpoch) + require.Nil(t, err) + + if len(shuffledToAuctionValPubKeys) > 0 { + // there are 2 nodes per shard shuffled out so 2 * 4 = 8 + actionListSize += 8 + } } if metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step3Flag) <= currentEpoch { // starting from phase 3, we have the shuffled out nodes from the previous epoch in the action list - actionListSize += 4 + // if there is no lowWaitingList condition + shuffledToAuctionValPubKeys, err := metachainNode.GetProcessComponents().NodesCoordinator().GetShuffledOutToAuctionValidatorsPublicKeys(currentEpoch) + require.Nil(t, err) + + if len(shuffledToAuctionValPubKeys) > 0 { + // there are 2 nodes per shard shuffled out so 2 * 4 = 8 + actionListSize += 8 + } } require.Equal(t, actionListSize, len(auctionList)) From 3a877d975dadbf9e28faa53dfc3f9140506c0542 Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Wed, 15 May 2024 14:46:01 +0300 Subject: [PATCH 235/503] simplify --- .../stakingProvider/delegation_test.go | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index 3ee5971a502..da3950818b7 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go @@ -398,23 +398,15 @@ func testBLSKeyIsInAuction( require.Nil(t, err) currentEpoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetCurrentEpoch() - if metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step2Flag) == currentEpoch { - // starting from phase 2, we have the shuffled out nodes from the previous epoch in the action list - // if there is no lowWaitingList condition - shuffledToAuctionValPubKeys, err := metachainNode.GetProcessComponents().NodesCoordinator().GetShuffledOutToAuctionValidatorsPublicKeys(currentEpoch) - require.Nil(t, err) - if len(shuffledToAuctionValPubKeys) > 0 { - // there are 2 nodes per shard shuffled out so 2 * 4 = 8 - actionListSize += 8 - } - } - if metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step3Flag) <= currentEpoch { - // starting from phase 3, we have the shuffled out nodes from the previous epoch in the action list - // if there is no lowWaitingList condition - shuffledToAuctionValPubKeys, err := metachainNode.GetProcessComponents().NodesCoordinator().GetShuffledOutToAuctionValidatorsPublicKeys(currentEpoch) - require.Nil(t, err) + shuffledToAuctionValPubKeys, err := metachainNode.GetProcessComponents().NodesCoordinator().GetShuffledOutToAuctionValidatorsPublicKeys(currentEpoch) + require.Nil(t, err) + stakingV4Step2Epoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step2Flag) + stakingV4Step3Epoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step3Flag) + if stakingV4Step2Epoch == currentEpoch || stakingV4Step3Epoch == currentEpoch { + // starting from phase 2, we have the shuffled out nodes from the previous epoch in the action list + // if there is no lowWaitingList condition if len(shuffledToAuctionValPubKeys) > 0 { // there are 2 nodes per shard shuffled out so 2 * 4 = 8 actionListSize += 8 From 5e31461c03d4e602faef74d66c342b390b81c682 Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Wed, 15 May 2024 15:27:05 +0300 Subject: [PATCH 236/503] simplify and add more constraints in integration test --- .../staking/stake/simpleStake_test.go | 21 ++--- .../staking/stake/stakeAndUnStake_test.go | 90 +++++++++++-------- 2 files changed, 62 insertions(+), 49 deletions(-) diff --git a/integrationTests/chainSimulator/staking/stake/simpleStake_test.go b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go index a4f63e44f28..9685ce78cc6 100644 --- a/integrationTests/chainSimulator/staking/stake/simpleStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go @@ -9,6 +9,8 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" @@ -17,7 +19,6 @@ import ( "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/vm" - "github.com/stretchr/testify/require" ) // Test scenarios @@ -261,30 +262,30 @@ func TestChainSimulator_StakingV4Step2APICalls(t *testing.T) { err = cs.GenerateBlocks(2) require.Nil(t, err) - numQualified, numUnQualified := getNumQualifiedAndUnqualified(t, metachainNode) - require.Equal(t, 8, numQualified) - require.Equal(t, 1, numUnQualified) + qualified, unQualified := getQualifiedAndUnqualifiedNodes(t, metachainNode) + require.Equal(t, 8, len(qualified)) + require.Equal(t, 1, len(unQualified)) } } -func getNumQualifiedAndUnqualified(t *testing.T, metachainNode process.NodeHandler) (int, int) { +func getQualifiedAndUnqualifiedNodes(t *testing.T, metachainNode process.NodeHandler) ([]string, []string) { err := metachainNode.GetProcessComponents().ValidatorsProvider().ForceUpdate() require.Nil(t, err) auctionList, err := metachainNode.GetProcessComponents().ValidatorsProvider().GetAuctionList() require.Nil(t, err) - numQualified := 0 - numUnQualified := 0 + qualified := make([]string, 0) + unQualified := make([]string, 0) for _, auctionOwnerData := range auctionList { for _, auctionNode := range auctionOwnerData.Nodes { if auctionNode.Qualified { - numQualified++ + qualified = append(qualified, auctionNode.BlsKey) } else { - numUnQualified++ + unQualified = append(unQualified, auctionNode.BlsKey) } } } - return numQualified, numUnQualified + return qualified, unQualified } diff --git a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index d876545a124..a46d800fe82 100644 --- a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go @@ -2367,21 +2367,21 @@ func TestChainSimulator_UnStakeOneActiveNodeAndCheckAPIAuctionList(t *testing.T) metachainNode := cs.GetNodeHandler(core.MetachainShardId) - numQualified, numUnQualified := getNumQualifiedAndUnqualified(t, metachainNode) - require.Equal(t, 8, numQualified) - require.Equal(t, 0, numUnQualified) + qualified, unQualified := getQualifiedAndUnqualifiedNodes(t, metachainNode) + require.Equal(t, 8, len(qualified)) + require.Equal(t, 0, len(unQualified)) stakeOneNode(t, cs) - numQualified, numUnQualified = getNumQualifiedAndUnqualified(t, metachainNode) - require.Equal(t, 8, numQualified) - require.Equal(t, 1, numUnQualified) + qualified, unQualified = getQualifiedAndUnqualifiedNodes(t, metachainNode) + require.Equal(t, 8, len(qualified)) + require.Equal(t, 1, len(unQualified)) unStakeOneActiveNode(t, cs) - numQualified, numUnQualified = getNumQualifiedAndUnqualified(t, metachainNode) - require.Equal(t, 8, numQualified) - require.Equal(t, 1, numUnQualified) + qualified, unQualified = getQualifiedAndUnqualifiedNodes(t, metachainNode) + require.Equal(t, 8, len(qualified)) + require.Equal(t, 1, len(unQualified)) } // Nodes configuration at genesis consisting of a total of 40 nodes, distributed on 3 shards + meta: @@ -2445,58 +2445,75 @@ func TestChainSimulator_EdgeCaseLowWaitingList(t *testing.T) { require.Nil(t, err) metachainNode := cs.GetNodeHandler(core.MetachainShardId) - numQualified, numUnQualified := getNumQualifiedAndUnqualified(t, metachainNode) - require.Equal(t, 0, numQualified) - require.Equal(t, 0, numUnQualified) + qualified, unQualified := getQualifiedAndUnqualifiedNodes(t, metachainNode) + require.Equal(t, 0, len(qualified)) + require.Equal(t, 0, len(unQualified)) // we always have 0 in auction list because of the lowWaitingList condition epochToCheck += 1 err = cs.GenerateBlocksUntilEpochIsReached(epochToCheck) require.Nil(t, err) - numQualified, numUnQualified = getNumQualifiedAndUnqualified(t, metachainNode) - require.Equal(t, 0, numQualified) - require.Equal(t, 0, numUnQualified) + qualified, unQualified = getQualifiedAndUnqualifiedNodes(t, metachainNode) + require.Equal(t, 0, len(qualified)) + require.Equal(t, 0, len(unQualified)) // stake 16 mode nodes, these will go to auction list - stakeNodes(t, cs, 16) + stakeNodes(t, cs, 17) epochToCheck += 1 err = cs.GenerateBlocksUntilEpochIsReached(epochToCheck) require.Nil(t, err) - numQualified, numUnQualified = getNumQualifiedAndUnqualified(t, metachainNode) + qualified, unQualified = getQualifiedAndUnqualifiedNodes(t, metachainNode) // all the previously registered will be selected, as we have 24 nodes in eligible+waiting, 8 will shuffle out, // but this time there will be not be lowWaitingList, as there are enough in auction, so we will end up with // 24-8 = 16 nodes remaining + 16 from auction, to fill up all 32 positions - require.Equal(t, 16, numQualified) - require.Equal(t, 0, numUnQualified) -} + require.Equal(t, 16, len(qualified)) + require.Equal(t, 1, len(unQualified)) -func stakeNodes(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, numTxs int) { - txs := make([]*transaction.Transaction, numTxs) - for i := 0; i < numTxs; i++ { - privateKey, blsKeys, err := chainSimulator.GenerateBlsPrivateKeys(1) - require.Nil(t, err) - err = cs.AddValidatorKeys(privateKey) - require.Nil(t, err) + shuffledOutNodesKeys, err := metachainNode.GetProcessComponents().NodesCoordinator().GetShuffledOutToAuctionValidatorsPublicKeys(uint32(epochToCheck)) + require.Nil(t, err) - mintValue := big.NewInt(0).Add(staking.MinimumStakeValue, staking.OneEGLD) - validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) - require.Nil(t, err) + checkKeysNotInMap(t, shuffledOutNodesKeys, qualified) + checkKeysNotInMap(t, shuffledOutNodesKeys, unQualified) +} - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txs[i] = staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) +func checkKeysNotInMap(t *testing.T, m map[uint32][][]byte, keys []string) { + for _, key := range keys { + for _, v := range m { + for _, k := range v { + mapKey := hex.EncodeToString(k) + require.NotEqual(t, key, mapKey) + } + } + } +} + +func stakeNodes(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, numNodesToStake int) { + txs := make([]*transaction.Transaction, numNodesToStake) + for i := 0; i < numNodesToStake; i++ { + txs[i] = createStakeTransaction(t, cs) } + stakeTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted(txs, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTxs) - require.Len(t, stakeTxs, numTxs) + require.Len(t, stakeTxs, numNodesToStake) require.Nil(t, cs.GenerateBlocks(1)) } func stakeOneNode(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator) { + txStake := createStakeTransaction(t, cs) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, stakeTx) + + require.Nil(t, cs.GenerateBlocks(1)) +} + +func createStakeTransaction(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator) *transaction.Transaction { privateKey, blsKeys, err := chainSimulator.GenerateBlsPrivateKeys(1) require.Nil(t, err) err = cs.AddValidatorKeys(privateKey) @@ -2507,12 +2524,7 @@ func stakeOneNode(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator require.Nil(t, err) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, stakeTx) - - require.Nil(t, cs.GenerateBlocks(1)) + return staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) } func unStakeOneActiveNode(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator) { From 637df8da91fe4fa9184467285f6558df78060660 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 15 May 2024 18:15:00 +0300 Subject: [PATCH 237/503] fix after merge + updated core-go --- go.mod | 2 +- go.sum | 4 ++-- integrationTests/vm/txsFee/common.go | 5 ++++- integrationTests/vm/txsFee/moveBalance_test.go | 3 --- integrationTests/vm/txsFee/relayedScCalls_test.go | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index e70e37f4219..ef7449e11ea 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e - github.com/multiversx/mx-chain-core-go v1.2.21-0.20240508071047-fefea5737840 + github.com/multiversx/mx-chain-core-go v1.2.21-0.20240515142419-21cfaa868d73 github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df github.com/multiversx/mx-chain-es-indexer-go v1.7.1-0.20240509104512-25512675833d github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 diff --git a/go.sum b/go.sum index 185994c8e4f..e1b12e2c8ba 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY 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-core-go v1.2.21-0.20240515142419-21cfaa868d73 h1:AyzXAdoTm/fF17ERrD/tle4QiZPy/waBaO7iTlxncYU= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240515142419-21cfaa868d73/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.1-0.20240509104512-25512675833d h1:GD1D8V0bE6hDLjrduSsMwQwwf6PMq2Zww7FYMfJsuiw= diff --git a/integrationTests/vm/txsFee/common.go b/integrationTests/vm/txsFee/common.go index 8d94f929382..da0ccb53a99 100644 --- a/integrationTests/vm/txsFee/common.go +++ b/integrationTests/vm/txsFee/common.go @@ -15,7 +15,10 @@ import ( "github.com/stretchr/testify/require" ) -const gasPrice = uint64(10) +const ( + gasPrice = uint64(10) + minGasLimit = uint64(1) +) type metaData struct { tokenId []byte diff --git a/integrationTests/vm/txsFee/moveBalance_test.go b/integrationTests/vm/txsFee/moveBalance_test.go index 0b3ad8d5913..28907f5a2c6 100644 --- a/integrationTests/vm/txsFee/moveBalance_test.go +++ b/integrationTests/vm/txsFee/moveBalance_test.go @@ -16,9 +16,6 @@ import ( "github.com/stretchr/testify/require" ) -const gasPrice = uint64(10) -const minGasLimit = uint64(1) - // minGasPrice = 1, gasPerDataByte = 1, minGasLimit = 1 func TestMoveBalanceSelfShouldWorkAndConsumeTxFee(t *testing.T) { if testing.Short() { diff --git a/integrationTests/vm/txsFee/relayedScCalls_test.go b/integrationTests/vm/txsFee/relayedScCalls_test.go index b6fc543b665..fefcfadb151 100644 --- a/integrationTests/vm/txsFee/relayedScCalls_test.go +++ b/integrationTests/vm/txsFee/relayedScCalls_test.go @@ -37,7 +37,7 @@ func testRelayedScCallShouldWork(relayedFixActivationEpoch uint32) func(t *testi relayerAddr := []byte("12345678901234567890123456789033") sndAddr := []byte("12345678901234567890123456789112") - gasLimit := uint64(9988100) + gasLimit := uint64(100000) _, _ = vm.CreateAccount(testContext.Accounts, sndAddr, 0, big.NewInt(0)) _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, big.NewInt(30000000)) From 3da7174402f68bd1f5aa854ec48697b4ab4907d9 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 16 May 2024 10:20:29 +0300 Subject: [PATCH 238/503] update-core-go after merge --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index ef7449e11ea..2dd782cc25c 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e - github.com/multiversx/mx-chain-core-go v1.2.21-0.20240515142419-21cfaa868d73 + github.com/multiversx/mx-chain-core-go v1.2.21-0.20240515142458-bb09ab417156 github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df github.com/multiversx/mx-chain-es-indexer-go v1.7.1-0.20240509104512-25512675833d github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 diff --git a/go.sum b/go.sum index e1b12e2c8ba..6cdd0173967 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY 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.20240515142419-21cfaa868d73 h1:AyzXAdoTm/fF17ERrD/tle4QiZPy/waBaO7iTlxncYU= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240515142419-21cfaa868d73/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240515142458-bb09ab417156 h1:Lzm7USVM1b6h1OsizXYjVOiqX9USwaOuNCegkcAlFJM= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240515142458-bb09ab417156/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.1-0.20240509104512-25512675833d h1:GD1D8V0bE6hDLjrduSsMwQwwf6PMq2Zww7FYMfJsuiw= From 9980a4fbfc5b3a3e3c82e2e7567085105b7d3a17 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 16 May 2024 10:40:53 +0300 Subject: [PATCH 239/503] fix simulator tests after merge --- integrationTests/chainSimulator/relayedTx/relayedTx_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index 950f07f2b6b..a12d9e6ca92 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -57,6 +57,8 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing. cfg.EpochConfig.EnableEpochs.RelayedTransactionsV3EnableEpoch = 1 cfg.EpochConfig.EnableEpochs.FixRelayedMoveBalanceEnableEpoch = 1 }, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, }) require.NoError(t, err) require.NotNil(t, cs) From 69c2cd2266ac85449986558415b83769f55e040b Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Thu, 16 May 2024 13:16:09 +0300 Subject: [PATCH 240/503] add key argument on AddIntermediateTransactions --- factory/disabled/txCoordinator.go | 3 +- .../intermediateTransactionHandlerMock.go | 6 +-- .../mock/transactionCoordinatorMock.go | 7 ++-- process/block/baseProcess.go | 5 ++- process/block/postprocess/basePostProcess.go | 11 +++-- .../block/postprocess/intermediateResults.go | 9 ++-- .../postprocess/intermediateResults_test.go | 41 ++++++++++--------- .../block/postprocess/oneMBPostProcessor.go | 5 ++- process/coordinator/process.go | 7 ++-- process/coordinator/process_test.go | 29 +++++++------ process/interface.go | 9 ++-- process/mock/intermProcessorStub.go | 6 +-- .../intermediateTransactionHandlerMock.go | 6 +-- process/smartContract/process.go | 17 ++++---- process/smartContract/process_test.go | 21 +++++----- .../smartContract/processorV2/processV2.go | 23 ++++++----- .../smartContract/processorV2/process_test.go | 23 ++++++----- process/transaction/shardProcess.go | 23 ++++++----- process/transaction/shardProcess_test.go | 23 ++++++----- testscommon/transactionCoordinatorMock.go | 7 ++-- update/mock/transactionCoordinatorMock.go | 7 ++-- 21 files changed, 156 insertions(+), 132 deletions(-) diff --git a/factory/disabled/txCoordinator.go b/factory/disabled/txCoordinator.go index e4ada3dc6ab..9d8002fb034 100644 --- a/factory/disabled/txCoordinator.go +++ b/factory/disabled/txCoordinator.go @@ -5,6 +5,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/block" + "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/block/processedMb" ) @@ -111,7 +112,7 @@ func (txCoordinator *TxCoordinator) VerifyCreatedMiniBlocks(_ data.HeaderHandler } // AddIntermediateTransactions does nothing as it is disabled -func (txCoordinator *TxCoordinator) AddIntermediateTransactions(_ map[block.Type][]data.TransactionHandler) error { +func (txCoordinator *TxCoordinator) AddIntermediateTransactions(_ map[block.Type][]data.TransactionHandler, _ []byte) error { return nil } diff --git a/integrationTests/mock/intermediateTransactionHandlerMock.go b/integrationTests/mock/intermediateTransactionHandlerMock.go index 77e60169ee7..df0e5d147d6 100644 --- a/integrationTests/mock/intermediateTransactionHandlerMock.go +++ b/integrationTests/mock/intermediateTransactionHandlerMock.go @@ -7,7 +7,7 @@ import ( // IntermediateTransactionHandlerMock - type IntermediateTransactionHandlerMock struct { - AddIntermediateTransactionsCalled func(txs []data.TransactionHandler) error + AddIntermediateTransactionsCalled func(txs []data.TransactionHandler, key []byte) error GetNumOfCrossInterMbsAndTxsCalled func() (int, int) CreateAllInterMiniBlocksCalled func() []*block.MiniBlock VerifyInterMiniBlocksCalled func(body *block.Body) error @@ -57,12 +57,12 @@ func (ith *IntermediateTransactionHandlerMock) CreateMarshalledData(txHashes [][ } // AddIntermediateTransactions - -func (ith *IntermediateTransactionHandlerMock) AddIntermediateTransactions(txs []data.TransactionHandler) error { +func (ith *IntermediateTransactionHandlerMock) AddIntermediateTransactions(txs []data.TransactionHandler, key []byte) error { if ith.AddIntermediateTransactionsCalled == nil { ith.intermediateTransactions = append(ith.intermediateTransactions, txs...) return nil } - return ith.AddIntermediateTransactionsCalled(txs) + return ith.AddIntermediateTransactionsCalled(txs, key) } // GetIntermediateTransactions - diff --git a/integrationTests/mock/transactionCoordinatorMock.go b/integrationTests/mock/transactionCoordinatorMock.go index d3671b1d77b..c002c52cc0f 100644 --- a/integrationTests/mock/transactionCoordinatorMock.go +++ b/integrationTests/mock/transactionCoordinatorMock.go @@ -5,6 +5,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/block" + "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/block/processedMb" ) @@ -29,7 +30,7 @@ type TransactionCoordinatorMock struct { VerifyCreatedBlockTransactionsCalled func(hdr data.HeaderHandler, body *block.Body) error CreatePostProcessMiniBlocksCalled func() block.MiniBlockSlice VerifyCreatedMiniBlocksCalled func(hdr data.HeaderHandler, body *block.Body) error - AddIntermediateTransactionsCalled func(mapSCRs map[block.Type][]data.TransactionHandler) error + AddIntermediateTransactionsCalled func(mapSCRs map[block.Type][]data.TransactionHandler, key []byte) error GetAllIntermediateTxsCalled func() map[block.Type]map[string]data.TransactionHandler AddTxsFromMiniBlocksCalled func(miniBlocks block.MiniBlockSlice) AddTransactionsCalled func(txHandlers []data.TransactionHandler, blockType block.Type) @@ -213,12 +214,12 @@ func (tcm *TransactionCoordinatorMock) VerifyCreatedMiniBlocks(hdr data.HeaderHa } // AddIntermediateTransactions - -func (tcm *TransactionCoordinatorMock) AddIntermediateTransactions(mapSCRs map[block.Type][]data.TransactionHandler) error { +func (tcm *TransactionCoordinatorMock) AddIntermediateTransactions(mapSCRs map[block.Type][]data.TransactionHandler, key []byte) error { if tcm.AddIntermediateTransactionsCalled == nil { return nil } - return tcm.AddIntermediateTransactionsCalled(mapSCRs) + return tcm.AddIntermediateTransactionsCalled(mapSCRs, key) } // GetAllIntermediateTxs - diff --git a/process/block/baseProcess.go b/process/block/baseProcess.go index b12aa6b2783..0e3c573b23d 100644 --- a/process/block/baseProcess.go +++ b/process/block/baseProcess.go @@ -20,6 +20,8 @@ import ( "github.com/multiversx/mx-chain-core-go/display" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + logger "github.com/multiversx/mx-chain-logger-go" + nodeFactory "github.com/multiversx/mx-chain-go/cmd/node/factory" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/errChan" @@ -42,7 +44,6 @@ import ( "github.com/multiversx/mx-chain-go/state/factory" "github.com/multiversx/mx-chain-go/state/parsers" "github.com/multiversx/mx-chain-go/storage/storageunit" - logger "github.com/multiversx/mx-chain-logger-go" ) var log = logger.GetOrCreate("process/block") @@ -576,7 +577,7 @@ func (bp *baseProcessor) createBlockStarted() error { bp.txCoordinator.CreateBlockStarted() bp.feeHandler.CreateBlockStarted(scheduledGasAndFees) - err := bp.txCoordinator.AddIntermediateTransactions(bp.scheduledTxsExecutionHandler.GetScheduledIntermediateTxs()) + err := bp.txCoordinator.AddIntermediateTransactions(bp.scheduledTxsExecutionHandler.GetScheduledIntermediateTxs(), nil) if err != nil { return err } diff --git a/process/block/postprocess/basePostProcess.go b/process/block/postprocess/basePostProcess.go index 058118dd88b..d7918bb34b8 100644 --- a/process/block/postprocess/basePostProcess.go +++ b/process/block/postprocess/basePostProcess.go @@ -9,10 +9,11 @@ import ( "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + "github.com/multiversx/mx-chain-logger-go" + "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/sharding" - "github.com/multiversx/mx-chain-logger-go" ) var _ process.DataMarshalizer = (*basePostProcessor)(nil) @@ -275,13 +276,17 @@ func (bpp *basePostProcessor) addIntermediateTxToResultsForBlock( txHash []byte, sndShardID uint32, rcvShardID uint32, + key []byte, ) { addScrShardInfo := &txShardInfo{receiverShardID: rcvShardID, senderShardID: sndShardID} scrInfo := &txInfo{tx: txHandler, txShardInfo: addScrShardInfo, index: bpp.index} bpp.index++ bpp.interResultsForBlock[string(txHash)] = scrInfo - for key := range bpp.mapProcessedResult { - bpp.mapProcessedResult[key] = append(bpp.mapProcessedResult[key], txHash) + value, ok := bpp.mapProcessedResult[string(key)] + if !ok { + return } + + bpp.mapProcessedResult[string(key)] = append(value, txHash) } diff --git a/process/block/postprocess/intermediateResults.go b/process/block/postprocess/intermediateResults.go index b10b99a03f8..77f90fc1033 100644 --- a/process/block/postprocess/intermediateResults.go +++ b/process/block/postprocess/intermediateResults.go @@ -12,11 +12,12 @@ import ( "github.com/multiversx/mx-chain-core-go/data/smartContractResult" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/sharding" - logger "github.com/multiversx/mx-chain-logger-go" ) var _ process.IntermediateTransactionHandler = (*intermediateResultsProcessor)(nil) @@ -237,7 +238,7 @@ func (irp *intermediateResultsProcessor) VerifyInterMiniBlocks(body *block.Body) } // AddIntermediateTransactions adds smart contract results from smart contract processing for cross-shard calls -func (irp *intermediateResultsProcessor) AddIntermediateTransactions(txs []data.TransactionHandler) error { +func (irp *intermediateResultsProcessor) AddIntermediateTransactions(txs []data.TransactionHandler, key []byte) error { irp.mutInterResultsForBlock.Lock() defer irp.mutInterResultsForBlock.Unlock() @@ -261,7 +262,7 @@ func (irp *intermediateResultsProcessor) AddIntermediateTransactions(txs []data. } if log.GetLevel() == logger.LogTrace { - //spew.Sdump is very useful when debugging errors like `receipts hash mismatch` + // spew.Sdump is very useful when debugging errors like `receipts hash mismatch` log.Trace("scr added", "txHash", addScr.PrevTxHash, "hash", scrHash, "nonce", addScr.Nonce, "gasLimit", addScr.GasLimit, "value", addScr.Value, "dump", spew.Sdump(addScr)) } @@ -269,7 +270,7 @@ func (irp *intermediateResultsProcessor) AddIntermediateTransactions(txs []data. sndShId, dstShId := irp.getShardIdsFromAddresses(addScr.SndAddr, addScr.RcvAddr) irp.executionOrderHandler.Add(scrHash) - irp.addIntermediateTxToResultsForBlock(addScr, scrHash, sndShId, dstShId) + irp.addIntermediateTxToResultsForBlock(addScr, scrHash, sndShId, dstShId, key) } return nil diff --git a/process/block/postprocess/intermediateResults_test.go b/process/block/postprocess/intermediateResults_test.go index b9a0a8e8f83..b2197451ca6 100644 --- a/process/block/postprocess/intermediateResults_test.go +++ b/process/block/postprocess/intermediateResults_test.go @@ -13,6 +13,9 @@ import ( "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/data/smartContractResult" "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/process" @@ -23,8 +26,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/storage" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) const maxGasLimitPerBlock = uint64(1500000000) @@ -198,7 +199,7 @@ func TestIntermediateResultsProcessor_AddIntermediateTransactions(t *testing.T) assert.NotNil(t, irp) assert.Nil(t, err) - err = irp.AddIntermediateTransactions(nil) + err = irp.AddIntermediateTransactions(nil, nil) assert.Nil(t, err) } @@ -216,7 +217,7 @@ func TestIntermediateResultsProcessor_AddIntermediateTransactionsWrongType(t *te txs := make([]data.TransactionHandler, 0) txs = append(txs, &transaction.Transaction{}) - err = irp.AddIntermediateTransactions(txs) + err = irp.AddIntermediateTransactions(txs, nil) assert.Equal(t, process.ErrWrongTypeAssertion, err) } @@ -242,7 +243,7 @@ func TestIntermediateResultsProcessor_AddIntermediateTransactionsNilSender(t *te shardC.ComputeIdCalled = func(address []byte) uint32 { return shardC.SelfId() } - err = irp.AddIntermediateTransactions(txs) + err = irp.AddIntermediateTransactions(txs, nil) assert.Equal(t, process.ErrNilSndAddr, err) } @@ -268,7 +269,7 @@ func TestIntermediateResultsProcessor_AddIntermediateTransactionsNilReceiver(t * shardC.ComputeIdCalled = func(address []byte) uint32 { return shardC.SelfId() } - err = irp.AddIntermediateTransactions(txs) + err = irp.AddIntermediateTransactions(txs, nil) assert.Equal(t, process.ErrNilRcvAddr, err) } @@ -303,7 +304,7 @@ func TestIntermediateResultsProcessor_AddIntermediateTransactionsShardIdMismatch txs = append(txs, scr) txs = append(txs, scr) - err = irp.AddIntermediateTransactions(txs) + err = irp.AddIntermediateTransactions(txs, nil) assert.Equal(t, process.ErrShardIdMissmatch, err) } @@ -329,14 +330,14 @@ func TestIntermediateResultsProcessor_AddIntermediateTransactionsNegativeValueIn shardC.ComputeIdCalled = func(address []byte) uint32 { return shardC.SelfId() } - err = irp.AddIntermediateTransactions(txs) + err = irp.AddIntermediateTransactions(txs, nil) assert.Nil(t, err) shardC.ComputeIdCalled = func(address []byte) uint32 { return shardC.SelfId() + 1 } - err = irp.AddIntermediateTransactions(txs) + err = irp.AddIntermediateTransactions(txs, nil) assert.Equal(t, process.ErrNegativeValue, err) } @@ -364,7 +365,7 @@ func TestIntermediateResultsProcessor_AddIntermediateTransactionsAddrGood(t *tes txs = append(txs, scr) txs = append(txs, scr) - err = irp.AddIntermediateTransactions(txs) + err = irp.AddIntermediateTransactions(txs, nil) assert.Nil(t, err) } @@ -397,7 +398,7 @@ func TestIntermediateResultsProcessor_AddIntermediateTransactionsAddAndRevert(t key := []byte("key") irp.InitProcessedResults(key) - err = irp.AddIntermediateTransactions(txs) + err = irp.AddIntermediateTransactions(txs, key) assert.Nil(t, err) irp.mutInterResultsForBlock.Lock() assert.Equal(t, len(irp.mapProcessedResult[string(key)]), len(txs)) @@ -460,7 +461,7 @@ func TestIntermediateResultsProcessor_CreateAllInterMiniBlocksNotCrossShard(t *t txs = append(txs, scr) txs = append(txs, scr) - err = irp.AddIntermediateTransactions(txs) + err = irp.AddIntermediateTransactions(txs, nil) assert.Nil(t, err) mbs := irp.CreateAllInterMiniBlocks() @@ -500,7 +501,7 @@ func TestIntermediateResultsProcessor_CreateAllInterMiniBlocksCrossShard(t *test txs = append(txs, &smartContractResult.SmartContractResult{SndAddr: snd, RcvAddr: []byte("recvaddr4"), Value: big.NewInt(0), PrevTxHash: []byte("txHash")}) txs = append(txs, &smartContractResult.SmartContractResult{SndAddr: snd, RcvAddr: []byte("recvaddr5"), Value: big.NewInt(0), PrevTxHash: []byte("txHash")}) - err = irp.AddIntermediateTransactions(txs) + err = irp.AddIntermediateTransactions(txs, nil) assert.Nil(t, err) mbs := irp.CreateAllInterMiniBlocks() @@ -545,7 +546,7 @@ func TestIntermediateResultsProcessor_GetNumOfCrossInterMbsAndTxsShouldWork(t *t txs = append(txs, &smartContractResult.SmartContractResult{Nonce: 8, SndAddr: snd, RcvAddr: []byte("3"), Value: big.NewInt(0), PrevTxHash: []byte("txHash")}) txs = append(txs, &smartContractResult.SmartContractResult{Nonce: 9, SndAddr: snd, RcvAddr: []byte("3"), Value: big.NewInt(0), PrevTxHash: []byte("txHash")}) - _ = irp.AddIntermediateTransactions(txs) + _ = irp.AddIntermediateTransactions(txs, nil) numMbs, numTxs := irp.GetNumOfCrossInterMbsAndTxs() assert.Equal(t, 3, numMbs) @@ -644,7 +645,7 @@ func TestIntermediateResultsProcessor_VerifyInterMiniBlocksBodyMiniBlockMissmatc txs = append(txs, &smartContractResult.SmartContractResult{SndAddr: snd, RcvAddr: []byte("recvaddr4"), Value: big.NewInt(0), PrevTxHash: []byte("txHash")}) txs = append(txs, &smartContractResult.SmartContractResult{SndAddr: snd, RcvAddr: []byte("recvaddr5"), Value: big.NewInt(0), PrevTxHash: []byte("txHash")}) - err = irp.AddIntermediateTransactions(txs) + err = irp.AddIntermediateTransactions(txs, nil) assert.Nil(t, err) err = irp.VerifyInterMiniBlocks(body) @@ -689,7 +690,7 @@ func TestIntermediateResultsProcessor_VerifyInterMiniBlocksBodyShouldPass(t *tes txs = append(txs, &smartContractResult.SmartContractResult{SndAddr: snd, RcvAddr: []byte("recvaddr4"), Value: big.NewInt(0), PrevTxHash: []byte("txHash")}) txs = append(txs, &smartContractResult.SmartContractResult{SndAddr: snd, RcvAddr: []byte("recvaddr5"), Value: big.NewInt(0), PrevTxHash: []byte("txHash")}) - err = irp.AddIntermediateTransactions(txs) + err = irp.AddIntermediateTransactions(txs, nil) assert.Nil(t, err) miniBlock := &block.MiniBlock{ @@ -763,7 +764,7 @@ func TestIntermediateResultsProcessor_SaveCurrentIntermediateTxToStorageShouldSa txs = append(txs, &smartContractResult.SmartContractResult{SndAddr: snd, RcvAddr: []byte("recvaddr4"), Value: big.NewInt(0), PrevTxHash: []byte("txHash")}) txs = append(txs, &smartContractResult.SmartContractResult{SndAddr: snd, RcvAddr: []byte("recvaddr5"), Value: big.NewInt(0), PrevTxHash: []byte("txHash")}) - err = irp.AddIntermediateTransactions(txs) + err = irp.AddIntermediateTransactions(txs, nil) assert.Nil(t, err) irp.SaveCurrentIntermediateTxToStorage() @@ -843,7 +844,7 @@ func TestIntermediateResultsProcessor_CreateMarshalizedData(t *testing.T) { currHash, _ = core.CalculateHash(marshalizer, hasher, txs[4]) txHashes = append(txHashes, currHash) - err = irp.AddIntermediateTransactions(txs) + err = irp.AddIntermediateTransactions(txs, nil) assert.Nil(t, err) mrsTxs, err := irp.CreateMarshalledData(txHashes) @@ -889,7 +890,7 @@ func TestIntermediateResultsProcessor_GetAllCurrentUsedTxs(t *testing.T) { txs = append(txs, &smartContractResult.SmartContractResult{SndAddr: snd, RcvAddr: snd, Nonce: 1, Value: big.NewInt(0), PrevTxHash: []byte("txHash")}) txs = append(txs, &smartContractResult.SmartContractResult{SndAddr: snd, RcvAddr: snd, Nonce: 2, Value: big.NewInt(0), PrevTxHash: []byte("txHash")}) - err = irp.AddIntermediateTransactions(txs) + err = irp.AddIntermediateTransactions(txs, nil) assert.Nil(t, err) usedTxs := irp.GetAllCurrentFinishedTxs() @@ -964,7 +965,7 @@ func TestIntermediateResultsProcessor_addIntermediateTxToResultsForBlock(t *test txHash := []byte("txHash") sndShardID := uint32(1) rcvShardID := uint32(2) - irp.addIntermediateTxToResultsForBlock(tx, txHash, sndShardID, rcvShardID) + irp.addIntermediateTxToResultsForBlock(tx, txHash, sndShardID, rcvShardID, key) require.Equal(t, 1, len(irp.interResultsForBlock)) require.Equal(t, 1, len(irp.mapProcessedResult)) diff --git a/process/block/postprocess/oneMBPostProcessor.go b/process/block/postprocess/oneMBPostProcessor.go index 5c68c3b194b..18668992a73 100644 --- a/process/block/postprocess/oneMBPostProcessor.go +++ b/process/block/postprocess/oneMBPostProcessor.go @@ -10,6 +10,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/sharding" @@ -143,7 +144,7 @@ func (opp *oneMBPostProcessor) VerifyInterMiniBlocks(body *block.Body) error { } // AddIntermediateTransactions adds receipts/bad transactions resulting from transaction processor -func (opp *oneMBPostProcessor) AddIntermediateTransactions(txs []data.TransactionHandler) error { +func (opp *oneMBPostProcessor) AddIntermediateTransactions(txs []data.TransactionHandler, key []byte) error { opp.mutInterResultsForBlock.Lock() defer opp.mutInterResultsForBlock.Unlock() @@ -155,7 +156,7 @@ func (opp *oneMBPostProcessor) AddIntermediateTransactions(txs []data.Transactio return err } - opp.addIntermediateTxToResultsForBlock(txs[i], txHash, selfId, selfId) + opp.addIntermediateTxToResultsForBlock(txs[i], txHash, selfId, selfId, key) } return nil diff --git a/process/coordinator/process.go b/process/coordinator/process.go index fad1906ef00..e8a698f6ac7 100644 --- a/process/coordinator/process.go +++ b/process/coordinator/process.go @@ -15,6 +15,8 @@ import ( "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/block/preprocess" @@ -24,7 +26,6 @@ import ( "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/storage/cache" - logger "github.com/multiversx/mx-chain-logger-go" ) var _ process.TransactionCoordinator = (*transactionCoordinator)(nil) @@ -1831,14 +1832,14 @@ func checkTransactionCoordinatorNilParameters(arguments ArgTransactionCoordinato } // AddIntermediateTransactions adds the given intermediate transactions -func (tc *transactionCoordinator) AddIntermediateTransactions(mapSCRs map[block.Type][]data.TransactionHandler) error { +func (tc *transactionCoordinator) AddIntermediateTransactions(mapSCRs map[block.Type][]data.TransactionHandler, key []byte) error { for blockType, scrs := range mapSCRs { interimProc := tc.getInterimProcessor(blockType) if check.IfNil(interimProc) { return process.ErrNilIntermediateProcessor } - err := interimProc.AddIntermediateTransactions(scrs) + err := interimProc.AddIntermediateTransactions(scrs, key) if err != nil { return err } diff --git a/process/coordinator/process_test.go b/process/coordinator/process_test.go index e23c8f8f1ec..d7045411ed7 100644 --- a/process/coordinator/process_test.go +++ b/process/coordinator/process_test.go @@ -21,6 +21,10 @@ import ( "github.com/multiversx/mx-chain-core-go/data/scheduled" "github.com/multiversx/mx-chain-core-go/data/smartContractResult" "github.com/multiversx/mx-chain-core-go/data/transaction" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/process" @@ -40,9 +44,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) const MaxGasLimitPerBlock = uint64(100000) @@ -751,24 +752,25 @@ func TestTransactionCoordinator_CreateMarshalizedDataWithTxsAndScr(t *testing.T) scrs := make([]data.TransactionHandler, 0) body := &block.Body{} body.MiniBlocks = append(body.MiniBlocks, createMiniBlockWithOneTx(0, 1, block.TxBlock, txHash)) + genericTxHash := []byte("txHash") - scr := &smartContractResult.SmartContractResult{SndAddr: []byte("snd"), RcvAddr: []byte("rcv"), Value: big.NewInt(99), PrevTxHash: []byte("txHash")} + scr := &smartContractResult.SmartContractResult{SndAddr: []byte("snd"), RcvAddr: []byte("rcv"), Value: big.NewInt(99), PrevTxHash: genericTxHash} scrHash, _ := core.CalculateHash(&mock.MarshalizerMock{}, &hashingMocks.HasherMock{}, scr) scrs = append(scrs, scr) body.MiniBlocks = append(body.MiniBlocks, createMiniBlockWithOneTx(0, 1, block.SmartContractResultBlock, scrHash)) - scr = &smartContractResult.SmartContractResult{SndAddr: []byte("snd"), RcvAddr: []byte("rcv"), Value: big.NewInt(199), PrevTxHash: []byte("txHash")} + scr = &smartContractResult.SmartContractResult{SndAddr: []byte("snd"), RcvAddr: []byte("rcv"), Value: big.NewInt(199), PrevTxHash: genericTxHash} scrHash, _ = core.CalculateHash(&mock.MarshalizerMock{}, &hashingMocks.HasherMock{}, scr) scrs = append(scrs, scr) body.MiniBlocks = append(body.MiniBlocks, createMiniBlockWithOneTx(0, 1, block.SmartContractResultBlock, scrHash)) - scr = &smartContractResult.SmartContractResult{SndAddr: []byte("snd"), RcvAddr: []byte("rcv"), Value: big.NewInt(299), PrevTxHash: []byte("txHash")} + scr = &smartContractResult.SmartContractResult{SndAddr: []byte("snd"), RcvAddr: []byte("rcv"), Value: big.NewInt(299), PrevTxHash: genericTxHash} scrHash, _ = core.CalculateHash(&mock.MarshalizerMock{}, &hashingMocks.HasherMock{}, scr) scrs = append(scrs, scr) body.MiniBlocks = append(body.MiniBlocks, createMiniBlockWithOneTx(0, 1, block.SmartContractResultBlock, scrHash)) scrInterimProc, _ := interimContainer.Get(block.SmartContractResultBlock) - _ = scrInterimProc.AddIntermediateTransactions(scrs) + _ = scrInterimProc.AddIntermediateTransactions(scrs, genericTxHash) mrTxs := tc.CreateMarshalizedData(body) assert.Equal(t, 1, len(mrTxs)) @@ -2342,7 +2344,8 @@ func TestTransactionCoordinator_VerifyCreatedBlockTransactionsOk(t *testing.T) { tx, _ := tdp.UnsignedTransactions().SearchFirstData(scrHash) txs := make([]data.TransactionHandler, 0) txs = append(txs, tx.(data.TransactionHandler)) - err = interProc.AddIntermediateTransactions(txs) + txHash, _ := core.CalculateHash(&mock.MarshalizerMock{}, &hashingMocks.HasherMock{}, tx) + err = interProc.AddIntermediateTransactions(txs, txHash) assert.Nil(t, err) body := &block.Body{MiniBlocks: []*block.MiniBlock{{Type: block.SmartContractResultBlock, ReceiverShardID: shardCoordinator.SelfId() + 1, TxHashes: [][]byte{scrHash}}}} @@ -4183,7 +4186,7 @@ func TestTransactionCoordinator_AddIntermediateTransactions(t *testing.T) { }, } - err := tc.AddIntermediateTransactions(mapSCRs) + err := tc.AddIntermediateTransactions(mapSCRs, nil) assert.Equal(t, process.ErrNilIntermediateProcessor, err) }) @@ -4195,7 +4198,7 @@ func TestTransactionCoordinator_AddIntermediateTransactions(t *testing.T) { expectedErr := errors.New("expected err") tc.keysInterimProcs = append(tc.keysInterimProcs, block.SmartContractResultBlock) tc.interimProcessors[block.SmartContractResultBlock] = &mock.IntermediateTransactionHandlerMock{ - AddIntermediateTransactionsCalled: func(txs []data.TransactionHandler) error { + AddIntermediateTransactionsCalled: func(txs []data.TransactionHandler, key []byte) error { return expectedErr }, } @@ -4208,7 +4211,7 @@ func TestTransactionCoordinator_AddIntermediateTransactions(t *testing.T) { }, } - err := tc.AddIntermediateTransactions(mapSCRs) + err := tc.AddIntermediateTransactions(mapSCRs, nil) assert.Equal(t, expectedErr, err) }) @@ -4225,7 +4228,7 @@ func TestTransactionCoordinator_AddIntermediateTransactions(t *testing.T) { tc.keysInterimProcs = append(tc.keysInterimProcs, block.SmartContractResultBlock) tc.interimProcessors[block.SmartContractResultBlock] = &mock.IntermediateTransactionHandlerMock{ - AddIntermediateTransactionsCalled: func(txs []data.TransactionHandler) error { + AddIntermediateTransactionsCalled: func(txs []data.TransactionHandler, key []byte) error { assert.Equal(t, expectedTxs, txs) return nil }, @@ -4239,7 +4242,7 @@ func TestTransactionCoordinator_AddIntermediateTransactions(t *testing.T) { }, } - err := tc.AddIntermediateTransactions(mapSCRs) + err := tc.AddIntermediateTransactions(mapSCRs, nil) assert.Nil(t, err) }) } diff --git a/process/interface.go b/process/interface.go index 69b1b139e89..5ae735f4027 100644 --- a/process/interface.go +++ b/process/interface.go @@ -20,6 +20,9 @@ import ( "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" crypto "github.com/multiversx/mx-chain-crypto-go" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-vm-common-go/parsers" + "github.com/multiversx/mx-chain-go/common" cryptoCommon "github.com/multiversx/mx-chain-go/common/crypto" "github.com/multiversx/mx-chain-go/epochStart" @@ -30,8 +33,6 @@ import ( "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/storage" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" - "github.com/multiversx/mx-chain-vm-common-go/parsers" ) // TransactionProcessor is the main interface for transaction execution engine @@ -170,7 +171,7 @@ type TransactionCoordinator interface { VerifyCreatedBlockTransactions(hdr data.HeaderHandler, body *block.Body) error GetCreatedInShardMiniBlocks() []*block.MiniBlock VerifyCreatedMiniBlocks(hdr data.HeaderHandler, body *block.Body) error - AddIntermediateTransactions(mapSCRs map[block.Type][]data.TransactionHandler) error + AddIntermediateTransactions(mapSCRs map[block.Type][]data.TransactionHandler, key []byte) error GetAllIntermediateTxs() map[block.Type]map[string]data.TransactionHandler AddTxsFromMiniBlocks(miniBlocks block.MiniBlockSlice) AddTransactions(txHandlers []data.TransactionHandler, blockType block.Type) @@ -190,7 +191,7 @@ type SmartContractProcessor interface { // IntermediateTransactionHandler handles transactions which are not resolved in only one step type IntermediateTransactionHandler interface { - AddIntermediateTransactions(txs []data.TransactionHandler) error + AddIntermediateTransactions(txs []data.TransactionHandler, key []byte) error GetNumOfCrossInterMbsAndTxs() (int, int) CreateAllInterMiniBlocks() []*block.MiniBlock VerifyInterMiniBlocks(body *block.Body) error diff --git a/process/mock/intermProcessorStub.go b/process/mock/intermProcessorStub.go index 3909bfd83fc..aa405a69799 100644 --- a/process/mock/intermProcessorStub.go +++ b/process/mock/intermProcessorStub.go @@ -7,7 +7,7 @@ import ( // IntermediateTransactionHandlerStub - type IntermediateTransactionHandlerStub struct { - AddIntermediateTransactionsCalled func(txs []data.TransactionHandler) error + AddIntermediateTransactionsCalled func(txs []data.TransactionHandler, key []byte) error GetNumOfCrossInterMbsAndTxsCalled func() (int, int) CreateAllInterMiniBlocksCalled func() []*block.MiniBlock VerifyInterMiniBlocksCalled func(body *block.Body) error @@ -44,12 +44,12 @@ func (ith *IntermediateTransactionHandlerStub) CreateMarshalledData(txHashes [][ } // AddIntermediateTransactions - -func (ith *IntermediateTransactionHandlerStub) AddIntermediateTransactions(txs []data.TransactionHandler) error { +func (ith *IntermediateTransactionHandlerStub) AddIntermediateTransactions(txs []data.TransactionHandler, key []byte) error { if ith.AddIntermediateTransactionsCalled == nil { ith.intermediateTransactions = append(ith.intermediateTransactions, txs...) return nil } - return ith.AddIntermediateTransactionsCalled(txs) + return ith.AddIntermediateTransactionsCalled(txs, key) } // GetIntermediateTransactions - diff --git a/process/mock/intermediateTransactionHandlerMock.go b/process/mock/intermediateTransactionHandlerMock.go index a7d0a5b3be6..4a68fb3d2f4 100644 --- a/process/mock/intermediateTransactionHandlerMock.go +++ b/process/mock/intermediateTransactionHandlerMock.go @@ -7,7 +7,7 @@ import ( // IntermediateTransactionHandlerMock - type IntermediateTransactionHandlerMock struct { - AddIntermediateTransactionsCalled func(txs []data.TransactionHandler) error + AddIntermediateTransactionsCalled func(txs []data.TransactionHandler, key []byte) error GetNumOfCrossInterMbsAndTxsCalled func() (int, int) CreateAllInterMiniBlocksCalled func() []*block.MiniBlock VerifyInterMiniBlocksCalled func(body *block.Body) error @@ -45,12 +45,12 @@ func (ith *IntermediateTransactionHandlerMock) CreateMarshalledData(txHashes [][ } // AddIntermediateTransactions - -func (ith *IntermediateTransactionHandlerMock) AddIntermediateTransactions(txs []data.TransactionHandler) error { +func (ith *IntermediateTransactionHandlerMock) AddIntermediateTransactions(txs []data.TransactionHandler, key []byte) error { if ith.AddIntermediateTransactionsCalled == nil { ith.intermediateTransactions = append(ith.intermediateTransactions, txs...) return nil } - return ith.AddIntermediateTransactionsCalled(txs) + return ith.AddIntermediateTransactionsCalled(txs, key) } // GetIntermediateTransactions - diff --git a/process/smartContract/process.go b/process/smartContract/process.go index 7bd0c9a2f52..25031dcbf4a 100644 --- a/process/smartContract/process.go +++ b/process/smartContract/process.go @@ -18,6 +18,10 @@ import ( vmData "github.com/multiversx/mx-chain-core-go/data/vm" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + logger "github.com/multiversx/mx-chain-logger-go" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-vm-common-go/parsers" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/smartContract/scrCommon" @@ -25,9 +29,6 @@ import ( "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/vm" - logger "github.com/multiversx/mx-chain-logger-go" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" - "github.com/multiversx/mx-chain-vm-common-go/parsers" ) var _ process.SmartContractResultProcessor = (*scProcessor)(nil) @@ -535,7 +536,7 @@ func (sc *scProcessor) finishSCExecution( return 0, err } - err = sc.scrForwarder.AddIntermediateTransactions(finalResults) + err = sc.scrForwarder.AddIntermediateTransactions(finalResults, txHash) if err != nil { log.Error("AddIntermediateTransactions error", "error", err.Error()) return 0, err @@ -868,7 +869,7 @@ func (sc *scProcessor) resolveFailedTransaction( } if _, ok := tx.(*transaction.Transaction); ok { - err = sc.badTxForwarder.AddIntermediateTransactions([]data.TransactionHandler{tx}) + err = sc.badTxForwarder.AddIntermediateTransactions([]data.TransactionHandler{tx}, txHash) if err != nil { return err } @@ -1436,7 +1437,7 @@ func (sc *scProcessor) processIfErrorWithAddedLogs( userErrorLog := createNewLogFromSCRIfError(scrIfError) if !sc.enableEpochsHandler.IsFlagEnabled(common.CleanUpInformativeSCRsFlag) || !sc.isInformativeTxHandler(scrIfError) { - err = sc.scrForwarder.AddIntermediateTransactions([]data.TransactionHandler{scrIfError}) + err = sc.scrForwarder.AddIntermediateTransactions([]data.TransactionHandler{scrIfError}, txHash) if err != nil { return err } @@ -1575,7 +1576,7 @@ func (sc *scProcessor) processForRelayerWhenError( } if !sc.enableEpochsHandler.IsFlagEnabled(common.CleanUpInformativeSCRsFlag) || scrForRelayer.Value.Cmp(zero) > 0 { - err = sc.scrForwarder.AddIntermediateTransactions([]data.TransactionHandler{scrForRelayer}) + err = sc.scrForwarder.AddIntermediateTransactions([]data.TransactionHandler{scrForRelayer}, txHash) if err != nil { return nil, err } @@ -1813,7 +1814,7 @@ func (sc *scProcessor) doDeploySmartContract( return 0, err } - err = sc.scrForwarder.AddIntermediateTransactions(finalResults) + err = sc.scrForwarder.AddIntermediateTransactions(finalResults, txHash) if err != nil { log.Debug("AddIntermediate Transaction error", "error", err.Error()) return 0, err diff --git a/process/smartContract/process_test.go b/process/smartContract/process_test.go index c53c7ef83c9..eb80ea63322 100644 --- a/process/smartContract/process_test.go +++ b/process/smartContract/process_test.go @@ -13,6 +13,13 @@ import ( "github.com/multiversx/mx-chain-core-go/data/smartContractResult" "github.com/multiversx/mx-chain-core-go/data/transaction" vmData "github.com/multiversx/mx-chain-core-go/data/vm" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-vm-common-go/builtInFunctions" + "github.com/multiversx/mx-chain-vm-common-go/parsers" + "github.com/pkg/errors" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/enablers" "github.com/multiversx/mx-chain-go/common/forking" @@ -35,12 +42,6 @@ import ( stateMock "github.com/multiversx/mx-chain-go/testscommon/state" "github.com/multiversx/mx-chain-go/testscommon/trie" "github.com/multiversx/mx-chain-go/testscommon/vmcommonMocks" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" - "github.com/multiversx/mx-chain-vm-common-go/builtInFunctions" - "github.com/multiversx/mx-chain-vm-common-go/parsers" - "github.com/pkg/errors" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) const setGuardianCost = 250000 @@ -631,13 +632,13 @@ func TestScProcessor_BuiltInCallSmartContractSenderFailed(t *testing.T) { scrAdded := false badTxAdded := false arguments.BadTxForwarder = &mock.IntermediateTransactionHandlerMock{ - AddIntermediateTransactionsCalled: func(txs []data.TransactionHandler) error { + AddIntermediateTransactionsCalled: func(txs []data.TransactionHandler, key []byte) error { badTxAdded = true return nil }, } arguments.ScrForwarder = &mock.IntermediateTransactionHandlerMock{ - AddIntermediateTransactionsCalled: func(txs []data.TransactionHandler) error { + AddIntermediateTransactionsCalled: func(txs []data.TransactionHandler, key []byte) error { scrAdded = true return nil }, @@ -1380,7 +1381,7 @@ func TestScProcessor_DeploySmartContractAddIntermediateTxFails(t *testing.T) { arguments := createMockSmartContractProcessorArguments() arguments.ArgsParser = argParser arguments.ScrForwarder = &mock.IntermediateTransactionHandlerMock{ - AddIntermediateTransactionsCalled: func(txs []data.TransactionHandler) error { + AddIntermediateTransactionsCalled: func(txs []data.TransactionHandler, key []byte) error { return expectedError }, } @@ -1415,7 +1416,7 @@ func TestScProcessor_DeploySmartContractComputeRewardsFails(t *testing.T) { arguments := createMockSmartContractProcessorArguments() arguments.ArgsParser = argParser arguments.ScrForwarder = &mock.IntermediateTransactionHandlerMock{ - AddIntermediateTransactionsCalled: func(txs []data.TransactionHandler) error { + AddIntermediateTransactionsCalled: func(txs []data.TransactionHandler, key []byte) error { return expectedError }, } diff --git a/process/smartContract/processorV2/processV2.go b/process/smartContract/processorV2/processV2.go index 126433c6dee..55aff2b72a0 100644 --- a/process/smartContract/processorV2/processV2.go +++ b/process/smartContract/processorV2/processV2.go @@ -18,6 +18,12 @@ import ( vmData "github.com/multiversx/mx-chain-core-go/data/vm" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + logger "github.com/multiversx/mx-chain-logger-go" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-vm-common-go/parsers" + "github.com/multiversx/mx-chain-vm-go/vmhost" + "github.com/multiversx/mx-chain-vm-go/vmhost/contexts" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/smartContract/hooks" @@ -27,11 +33,6 @@ import ( "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/testscommon/txDataBuilder" "github.com/multiversx/mx-chain-go/vm" - logger "github.com/multiversx/mx-chain-logger-go" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" - "github.com/multiversx/mx-chain-vm-common-go/parsers" - "github.com/multiversx/mx-chain-vm-go/vmhost" - "github.com/multiversx/mx-chain-vm-go/vmhost/contexts" ) var _ process.SmartContractResultProcessor = (*scProcessor)(nil) @@ -526,7 +527,7 @@ func (sc *scProcessor) finishSCExecution( return 0, err } - err = sc.scrForwarder.AddIntermediateTransactions(finalResults) + err = sc.scrForwarder.AddIntermediateTransactions(finalResults, txHash) if err != nil { log.Error("AddIntermediateTransactions error", "error", err.Error()) return 0, err @@ -824,10 +825,10 @@ func (sc *scProcessor) saveAccounts(acntSnd, acntDst vmcommon.AccountHandler) er func (sc *scProcessor) resolveFailedTransaction( _ state.UserAccountHandler, tx data.TransactionHandler, - _ []byte, + txHash []byte, ) error { if _, ok := tx.(*transaction.Transaction); ok { - err := sc.badTxForwarder.AddIntermediateTransactions([]data.TransactionHandler{tx}) + err := sc.badTxForwarder.AddIntermediateTransactions([]data.TransactionHandler{tx}, txHash) if err != nil { return err } @@ -1487,7 +1488,7 @@ func (sc *scProcessor) processIfErrorWithAddedLogs(acntSnd state.UserAccountHand isRecvSelfShard := sc.shardCoordinator.SelfId() == sc.shardCoordinator.ComputeId(scrIfError.RcvAddr) if !isRecvSelfShard && !sc.isInformativeTxHandler(scrIfError) { - err = sc.scrForwarder.AddIntermediateTransactions([]data.TransactionHandler{scrIfError}) + err = sc.scrForwarder.AddIntermediateTransactions([]data.TransactionHandler{scrIfError}, failureContext.txHash) if err != nil { return err } @@ -1613,7 +1614,7 @@ func (sc *scProcessor) processForRelayerWhenError( } if scrForRelayer.Value.Cmp(zero) > 0 { - err = sc.scrForwarder.AddIntermediateTransactions([]data.TransactionHandler{scrForRelayer}) + err = sc.scrForwarder.AddIntermediateTransactions([]data.TransactionHandler{scrForRelayer}, txHash) if err != nil { return nil, err } @@ -1865,7 +1866,7 @@ func (sc *scProcessor) doDeploySmartContract( return 0, err } - err = sc.scrForwarder.AddIntermediateTransactions(finalResults) + err = sc.scrForwarder.AddIntermediateTransactions(finalResults, txHash) if err != nil { log.Debug("AddIntermediate Transaction error", "error", err.Error()) return 0, err diff --git a/process/smartContract/processorV2/process_test.go b/process/smartContract/processorV2/process_test.go index eedea17f1ad..8919006995f 100644 --- a/process/smartContract/processorV2/process_test.go +++ b/process/smartContract/processorV2/process_test.go @@ -15,6 +15,14 @@ import ( "github.com/multiversx/mx-chain-core-go/data/smartContractResult" "github.com/multiversx/mx-chain-core-go/data/transaction" vmData "github.com/multiversx/mx-chain-core-go/data/vm" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-vm-common-go/builtInFunctions" + "github.com/multiversx/mx-chain-vm-common-go/parsers" + "github.com/multiversx/mx-chain-vm-go/vmhost" + "github.com/pkg/errors" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/process" @@ -38,13 +46,6 @@ import ( stateMock "github.com/multiversx/mx-chain-go/testscommon/state" testsCommonStorage "github.com/multiversx/mx-chain-go/testscommon/storage" "github.com/multiversx/mx-chain-go/testscommon/vmcommonMocks" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" - "github.com/multiversx/mx-chain-vm-common-go/builtInFunctions" - "github.com/multiversx/mx-chain-vm-common-go/parsers" - "github.com/multiversx/mx-chain-vm-go/vmhost" - "github.com/pkg/errors" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) const maxEpoch = math.MaxUint32 @@ -553,13 +554,13 @@ func TestScProcessor_BuiltInCallSmartContractSenderFailed(t *testing.T) { scrAdded := false badTxAdded := false arguments.BadTxForwarder = &mock.IntermediateTransactionHandlerMock{ - AddIntermediateTransactionsCalled: func(txs []data.TransactionHandler) error { + AddIntermediateTransactionsCalled: func(txs []data.TransactionHandler, key []byte) error { badTxAdded = true return nil }, } arguments.ScrForwarder = &mock.IntermediateTransactionHandlerMock{ - AddIntermediateTransactionsCalled: func(txs []data.TransactionHandler) error { + AddIntermediateTransactionsCalled: func(txs []data.TransactionHandler, key []byte) error { scrAdded = true return nil }, @@ -1401,7 +1402,7 @@ func TestScProcessor_DeploySmartContractAddIntermediateTxFails(t *testing.T) { arguments := createMockSmartContractProcessorArguments() arguments.ArgsParser = argParser arguments.ScrForwarder = &mock.IntermediateTransactionHandlerMock{ - AddIntermediateTransactionsCalled: func(txs []data.TransactionHandler) error { + AddIntermediateTransactionsCalled: func(txs []data.TransactionHandler, key []byte) error { return expectedError }, } @@ -1436,7 +1437,7 @@ func TestScProcessor_DeploySmartContractComputeRewardsFails(t *testing.T) { arguments := createMockSmartContractProcessorArguments() arguments.ArgsParser = argParser arguments.ScrForwarder = &mock.IntermediateTransactionHandlerMock{ - AddIntermediateTransactionsCalled: func(txs []data.TransactionHandler) error { + AddIntermediateTransactionsCalled: func(txs []data.TransactionHandler, key []byte) error { return expectedError }, } diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 89b3572397b..95de88df395 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -15,12 +15,13 @@ import ( "github.com/multiversx/mx-chain-core-go/data/vm" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + logger "github.com/multiversx/mx-chain-logger-go" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/state" - logger "github.com/multiversx/mx-chain-logger-go" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) var log = logger.GetOrCreate("process/transaction") @@ -274,7 +275,7 @@ func (txProc *txProcessor) executeAfterFailedMoveBalanceTransaction( return nil } - err = txProc.badTxForwarder.AddIntermediateTransactions([]data.TransactionHandler{tx}) + err = txProc.badTxForwarder.AddIntermediateTransactions([]data.TransactionHandler{tx}, txHash) if err != nil { return err } @@ -300,13 +301,13 @@ func (txProc *txProcessor) executingFailedTransaction( return err } - acntSnd.IncreaseNonce(1) - err = txProc.badTxForwarder.AddIntermediateTransactions([]data.TransactionHandler{tx}) + txHash, err := core.CalculateHash(txProc.marshalizer, txProc.hasher, tx) if err != nil { return err } - txHash, err := core.CalculateHash(txProc.marshalizer, txProc.hasher, tx) + acntSnd.IncreaseNonce(1) + err = txProc.badTxForwarder.AddIntermediateTransactions([]data.TransactionHandler{tx}, txHash) if err != nil { return err } @@ -320,7 +321,7 @@ func (txProc *txProcessor) executingFailedTransaction( TxHash: txHash, } - err = txProc.receiptForwarder.AddIntermediateTransactions([]data.TransactionHandler{rpt}) + err = txProc.receiptForwarder.AddIntermediateTransactions([]data.TransactionHandler{rpt}, txHash) if err != nil { return err } @@ -366,7 +367,7 @@ func (txProc *txProcessor) createReceiptWithReturnedGas( TxHash: txHash, } - err := txProc.receiptForwarder.AddIntermediateTransactions([]data.TransactionHandler{rpt}) + err := txProc.receiptForwarder.AddIntermediateTransactions([]data.TransactionHandler{rpt}, txHash) if err != nil { return err } @@ -890,7 +891,7 @@ func (txProc *txProcessor) processUserTx( return returnCode, nil } - err = txProc.scrForwarder.AddIntermediateTransactions([]data.TransactionHandler{scrFromTx}) + err = txProc.scrForwarder.AddIntermediateTransactions([]data.TransactionHandler{scrFromTx}, txHash) if err != nil { return 0, err } @@ -963,7 +964,7 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( return err } - err = txProc.scrForwarder.AddIntermediateTransactions([]data.TransactionHandler{scrForRelayer}) + err = txProc.scrForwarder.AddIntermediateTransactions([]data.TransactionHandler{scrForRelayer}, originalTxHash) if err != nil { return err } @@ -985,7 +986,7 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( } if txProc.enableEpochsHandler.IsFlagEnabled(common.AddFailedRelayedTxToInvalidMBsFlag) { - err = txProc.badTxForwarder.AddIntermediateTransactions([]data.TransactionHandler{originalTx}) + err = txProc.badTxForwarder.AddIntermediateTransactions([]data.TransactionHandler{originalTx}, originalTxHash) if err != nil { return err } diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index b79b8b21ffc..7c90dbad75f 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -13,6 +13,11 @@ import ( "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/smartContractResult" "github.com/multiversx/mx-chain-core-go/data/transaction" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-vm-common-go/builtInFunctions" + "github.com/multiversx/mx-chain-vm-common-go/parsers" + "github.com/stretchr/testify/assert" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/coordinator" @@ -28,10 +33,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" "github.com/multiversx/mx-chain-go/vm" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" - "github.com/multiversx/mx-chain-vm-common-go/builtInFunctions" - "github.com/multiversx/mx-chain-vm-common-go/parsers" - "github.com/stretchr/testify/assert" ) func generateRandomByteSlice(size int) []byte { @@ -102,7 +103,7 @@ func createTxProcessor() txproc.TxProcessor { return txProc } -//------- NewTxProcessor +// ------- NewTxProcessor func TestNewTxProcessor_NilAccountsShouldErr(t *testing.T) { t.Parallel() @@ -312,7 +313,7 @@ func TestNewTxProcessor_OkValsShouldWork(t *testing.T) { assert.NotNil(t, txProc) } -//------- getAccounts +// ------- getAccounts func TestTxProcessor_GetAccountsShouldErrNilAddressContainer(t *testing.T) { t.Parallel() @@ -479,7 +480,7 @@ func TestTxProcessor_GetSameAccountShouldWork(t *testing.T) { assert.True(t, a1 == a2) } -//------- checkTxValues +// ------- checkTxValues func TestTxProcessor_CheckTxValuesHigherNonceShouldErr(t *testing.T) { t.Parallel() @@ -602,7 +603,7 @@ func TestTxProcessor_CheckTxValuesOkValsShouldErr(t *testing.T) { assert.Nil(t, err) } -//------- increaseNonce +// ------- increaseNonce func TestTxProcessor_IncreaseNonceOkValsShouldWork(t *testing.T) { t.Parallel() @@ -618,7 +619,7 @@ func TestTxProcessor_IncreaseNonceOkValsShouldWork(t *testing.T) { assert.Equal(t, uint64(46), acntSrc.GetNonce()) } -//------- ProcessTransaction +// ------- ProcessTransaction func TestTxProcessor_ProcessTransactionNilTxShouldErr(t *testing.T) { t.Parallel() @@ -651,7 +652,7 @@ func TestTxProcessor_ProcessTransactionMalfunctionAccountsShouldErr(t *testing.T func TestTxProcessor_ProcessCheckNotPassShouldErr(t *testing.T) { t.Parallel() - //these values will trigger ErrHigherNonceInTransaction + // these values will trigger ErrHigherNonceInTransaction tx := transaction.Transaction{} tx.Nonce = 1 tx.SndAddr = []byte("SRC") @@ -2612,7 +2613,7 @@ func TestTxProcessor_ProcessRelayedTransactionDisabled(t *testing.T) { args.ArgsParser = smartContract.NewArgumentParser() called := false args.BadTxForwarder = &mock.IntermediateTransactionHandlerMock{ - AddIntermediateTransactionsCalled: func(txs []data.TransactionHandler) error { + AddIntermediateTransactionsCalled: func(txs []data.TransactionHandler, key []byte) error { called = true return nil }, diff --git a/testscommon/transactionCoordinatorMock.go b/testscommon/transactionCoordinatorMock.go index cd25a769912..a1889b0b753 100644 --- a/testscommon/transactionCoordinatorMock.go +++ b/testscommon/transactionCoordinatorMock.go @@ -5,6 +5,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/block" + "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/block/processedMb" ) @@ -29,7 +30,7 @@ type TransactionCoordinatorMock struct { VerifyCreatedBlockTransactionsCalled func(hdr data.HeaderHandler, body *block.Body) error CreatePostProcessMiniBlocksCalled func() block.MiniBlockSlice VerifyCreatedMiniBlocksCalled func(hdr data.HeaderHandler, body *block.Body) error - AddIntermediateTransactionsCalled func(mapSCRs map[block.Type][]data.TransactionHandler) error + AddIntermediateTransactionsCalled func(mapSCRs map[block.Type][]data.TransactionHandler, key []byte) error GetAllIntermediateTxsCalled func() map[block.Type]map[string]data.TransactionHandler AddTxsFromMiniBlocksCalled func(miniBlocks block.MiniBlockSlice) AddTransactionsCalled func(txHandlers []data.TransactionHandler, blockType block.Type) @@ -215,12 +216,12 @@ func (tcm *TransactionCoordinatorMock) VerifyCreatedMiniBlocks(hdr data.HeaderHa } // AddIntermediateTransactions - -func (tcm *TransactionCoordinatorMock) AddIntermediateTransactions(mapSCRs map[block.Type][]data.TransactionHandler) error { +func (tcm *TransactionCoordinatorMock) AddIntermediateTransactions(mapSCRs map[block.Type][]data.TransactionHandler, key []byte) error { if tcm.AddIntermediateTransactionsCalled == nil { return nil } - return tcm.AddIntermediateTransactionsCalled(mapSCRs) + return tcm.AddIntermediateTransactionsCalled(mapSCRs, key) } // GetAllIntermediateTxs - diff --git a/update/mock/transactionCoordinatorMock.go b/update/mock/transactionCoordinatorMock.go index 07183d9467a..c0bb061a713 100644 --- a/update/mock/transactionCoordinatorMock.go +++ b/update/mock/transactionCoordinatorMock.go @@ -5,6 +5,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/block" + "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/block/processedMb" ) @@ -29,7 +30,7 @@ type TransactionCoordinatorMock struct { VerifyCreatedBlockTransactionsCalled func(hdr data.HeaderHandler, body *block.Body) error CreatePostProcessMiniBlocksCalled func() block.MiniBlockSlice VerifyCreatedMiniBlocksCalled func(hdr data.HeaderHandler, body *block.Body) error - AddIntermediateTransactionsCalled func(mapSCRs map[block.Type][]data.TransactionHandler) error + AddIntermediateTransactionsCalled func(mapSCRs map[block.Type][]data.TransactionHandler, key []byte) error GetAllIntermediateTxsCalled func() map[block.Type]map[string]data.TransactionHandler AddTxsFromMiniBlocksCalled func(miniBlocks block.MiniBlockSlice) AddTransactionsCalled func(txHandlers []data.TransactionHandler, blockType block.Type) @@ -204,12 +205,12 @@ func (tcm *TransactionCoordinatorMock) VerifyCreatedMiniBlocks(hdr data.HeaderHa } // AddIntermediateTransactions - -func (tcm *TransactionCoordinatorMock) AddIntermediateTransactions(mapSCRs map[block.Type][]data.TransactionHandler) error { +func (tcm *TransactionCoordinatorMock) AddIntermediateTransactions(mapSCRs map[block.Type][]data.TransactionHandler, key []byte) error { if tcm.AddIntermediateTransactionsCalled == nil { return nil } - return tcm.AddIntermediateTransactionsCalled(mapSCRs) + return tcm.AddIntermediateTransactionsCalled(mapSCRs, key) } // GetAllIntermediateTxs - From f47cf0c9654c52adef3a77d0a32931a53a766617 Mon Sep 17 00:00:00 2001 From: miiu Date: Thu, 16 May 2024 13:22:49 +0300 Subject: [PATCH 241/503] force change of epoch --- node/chainSimulator/chainSimulator.go | 16 +++++++ node/chainSimulator/chainSimulator_test.go | 43 +++++++++++++++++++ .../components/testOnlyProcessingNode.go | 12 ++++++ node/chainSimulator/configs/configs.go | 1 + node/chainSimulator/process/interface.go | 1 + testscommon/chainSimulator/nodeHandlerMock.go | 5 +++ 6 files changed, 78 insertions(+) diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index 5862f433b1c..aa2c6aa5453 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -278,6 +278,22 @@ func (s *simulator) incrementRoundOnAllValidators() { } } +// ForceChangeOfEpoch will force the change of current epoch +// This method will call the epoch change trigger and generate block till a new epoch is reached +func (s *simulator) ForceChangeOfEpoch() error { + log.Info("force change of epoch") + for shardID, node := range s.nodes { + err := node.ForceChangeOfEpoch() + if err != nil { + return fmt.Errorf("force change of epoch shardID-%d: error-%w", shardID, err) + } + } + + epoch := s.nodes[core.MetachainShardId].GetProcessComponents().EpochStartTrigger().Epoch() + + return s.GenerateBlocksUntilEpochIsReached(int32(epoch + 1)) +} + func (s *simulator) allNodesCreateBlocks() error { for _, node := range s.handlers { // TODO MX-15150 remove this when we remove all goroutines diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index 1929944d510..2ac75cae712 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -155,6 +155,49 @@ func TestChainSimulator_GenerateBlocksAndEpochChangeShouldWork(t *testing.T) { assert.True(t, numAccountsWithIncreasedBalances > 0) } +func TestSimulator_TriggerChangeOfEpoch(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 15000, + } + chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 100, + MetaChainMinNodes: 100, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + }) + require.Nil(t, err) + require.NotNil(t, chainSimulator) + + defer chainSimulator.Close() + + err = chainSimulator.ForceChangeOfEpoch() + require.Nil(t, err) + + err = chainSimulator.ForceChangeOfEpoch() + require.Nil(t, err) + + err = chainSimulator.ForceChangeOfEpoch() + require.Nil(t, err) + + err = chainSimulator.ForceChangeOfEpoch() + require.Nil(t, err) +} + func TestChainSimulator_SetState(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index 0dbe4430b5c..2439ce1f7d6 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -508,6 +508,18 @@ func (node *testOnlyProcessingNode) RemoveAccount(address []byte) error { return err } +// ForceChangeOfEpoch will force change of epoch +func (node *testOnlyProcessingNode) ForceChangeOfEpoch() error { + currentHeader := node.DataComponentsHolder.Blockchain().GetCurrentBlockHeader() + if currentHeader == nil { + currentHeader = node.DataComponentsHolder.Blockchain().GetGenesisHeader() + } + + node.ProcessComponentsHolder.EpochStartTrigger().ForceEpochStart(currentHeader.GetRound() + 1) + + return nil +} + func setNonceAndBalanceForAccount(userAccount state.UserAccountHandler, nonce *uint64, balance string) error { if nonce != nil { // set nonce to zero diff --git a/node/chainSimulator/configs/configs.go b/node/chainSimulator/configs/configs.go index 6f935f98dfe..c83d6494334 100644 --- a/node/chainSimulator/configs/configs.go +++ b/node/chainSimulator/configs/configs.go @@ -119,6 +119,7 @@ func CreateChainSimulatorConfigs(args ArgsChainSimulatorConfigs) (*ArgsConfigsSi configs.GeneralConfig.EpochStartConfig.ExtraDelayForRequestBlockInfoInMilliseconds = 1 configs.GeneralConfig.EpochStartConfig.GenesisEpoch = args.InitialEpoch + configs.GeneralConfig.EpochStartConfig.MinRoundsBetweenEpochs = 1 if args.RoundsPerEpoch.HasValue { configs.GeneralConfig.EpochStartConfig.RoundsPerEpoch = int64(args.RoundsPerEpoch.Value) diff --git a/node/chainSimulator/process/interface.go b/node/chainSimulator/process/interface.go index d7b0f15820e..47f937fb97c 100644 --- a/node/chainSimulator/process/interface.go +++ b/node/chainSimulator/process/interface.go @@ -24,6 +24,7 @@ type NodeHandler interface { SetKeyValueForAddress(addressBytes []byte, state map[string]string) error SetStateForAddress(address []byte, state *dtos.AddressState) error RemoveAccount(address []byte) error + ForceChangeOfEpoch() error Close() error IsInterfaceNil() bool } diff --git a/testscommon/chainSimulator/nodeHandlerMock.go b/testscommon/chainSimulator/nodeHandlerMock.go index 9e0a2ca4d3b..3f306807130 100644 --- a/testscommon/chainSimulator/nodeHandlerMock.go +++ b/testscommon/chainSimulator/nodeHandlerMock.go @@ -27,6 +27,11 @@ type NodeHandlerMock struct { CloseCalled func() error } +// ForceChangeOfEpoch - +func (mock *NodeHandlerMock) ForceChangeOfEpoch() error { + return nil +} + // GetProcessComponents - func (mock *NodeHandlerMock) GetProcessComponents() factory.ProcessComponentsHolder { if mock.GetProcessComponentsCalled != nil { From f11d9e9f2b944be90e90afd0484ba26d1176976f Mon Sep 17 00:00:00 2001 From: miiu Date: Thu, 16 May 2024 13:53:42 +0300 Subject: [PATCH 242/503] check current epoch at the end of test --- node/chainSimulator/chainSimulator_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index 2ac75cae712..020260760be 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -196,6 +196,10 @@ func TestSimulator_TriggerChangeOfEpoch(t *testing.T) { err = chainSimulator.ForceChangeOfEpoch() require.Nil(t, err) + + metaNode := chainSimulator.GetNodeHandler(core.MetachainShardId) + currentEpoch := metaNode.GetProcessComponents().EpochStartTrigger().Epoch() + require.Equal(t, uint32(4), currentEpoch) } func TestChainSimulator_SetState(t *testing.T) { From 0b00ad19352cefd80817e76350209d5e0e99be88 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 16 May 2024 16:43:15 +0300 Subject: [PATCH 243/503] append log events + new chain simulator integration test --- integrationTests/chainSimulator/interface.go | 1 + .../relayedTx/relayedTx_test.go | 231 +++++++++++++++--- process/transactionLog/process.go | 42 +++- process/transactionLog/process_test.go | 111 ++++++++- 4 files changed, 335 insertions(+), 50 deletions(-) diff --git a/integrationTests/chainSimulator/interface.go b/integrationTests/chainSimulator/interface.go index 759858a69c5..8f34eca85fa 100644 --- a/integrationTests/chainSimulator/interface.go +++ b/integrationTests/chainSimulator/interface.go @@ -24,4 +24,5 @@ type ChainSimulator interface { GetAccount(address dtos.WalletAddress) (api.AccountResponse, error) ForceResetValidatorStatisticsCache() error GetValidatorPrivateKeys() []crypto.PrivateKey + Close() } diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index a12d9e6ca92..6bd74c50ee7 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -3,6 +3,7 @@ package relayedTx import ( "encoding/hex" "math/big" + "strconv" "strings" "testing" "time" @@ -10,10 +11,14 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" + testsChainSimulator "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" "github.com/multiversx/mx-chain-go/integrationTests/vm/wasm" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" + chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" + "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/sharding" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -34,40 +39,9 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing. t.Skip("this is not a short test") } - roundDurationInMillis := uint64(6000) - roundsPerEpoch := core.OptionalUint64{ - HasValue: true, - Value: 30, - } - - cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, - AlterConfigsFunction: func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.RelayedTransactionsV3EnableEpoch = 1 - cfg.EpochConfig.EnableEpochs.FixRelayedMoveBalanceEnableEpoch = 1 - }, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - }) - require.NoError(t, err) - require.NotNil(t, cs) - + cs := startChainSimulator(t) defer cs.Close() - err = cs.GenerateBlocksUntilEpochIsReached(1) - require.NoError(t, err) - initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(30000)) relayer, err := cs.GenerateAndMintWalletAddress(0, initialBalance) require.NoError(t, err) @@ -163,13 +137,7 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing. // check SCRs shardC := cs.GetNodeHandler(0).GetShardCoordinator() for _, scr := range result.SmartContractResults { - addr, err := pkConv.Decode(scr.RcvAddr) - require.NoError(t, err) - - senderShard := shardC.ComputeId(addr) - tx, err := cs.GetNodeHandler(senderShard).GetFacadeHandler().GetTransaction(scr.Hash, true) - require.NoError(t, err) - assert.Equal(t, transaction.TxStatusSuccess, tx.Status) + checkSCRStatus(t, cs, pkConv, shardC, scr) } // check log events @@ -177,6 +145,152 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing. require.True(t, strings.Contains(string(result.Logs.Events[2].Data), "contract is paused")) } +func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorScCalls(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + cs := startChainSimulator(t) + defer cs.Close() + + initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(10)) + relayer, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + pkConv := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter() + shardC := cs.GetNodeHandler(0).GetShardCoordinator() + + // deploy adder contract + owner, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + ownerNonce := uint64(0) + scCode := wasm.GetSCCode("testData/adder.wasm") + params := []string{scCode, wasm.VMTypeHex, wasm.DummyCodeMetadataHex, "00"} + txDataDeploy := strings.Join(params, "@") + deployTx := generateTransaction(owner.Bytes, ownerNonce, make([]byte, 32), big.NewInt(0), txDataDeploy, 100000000) + + result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(deployTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + scAddress := result.Logs.Events[0].Address + scAddressBytes, _ := pkConv.Decode(scAddress) + scShard := shardC.ComputeId(scAddressBytes) + scShardNodeHandler := cs.GetNodeHandler(scShard) + + // 1st inner tx, successful add 1 + ownerNonce++ + txDataAdd := "add@" + hex.EncodeToString(big.NewInt(1).Bytes()) + innerTx1 := generateTransaction(owner.Bytes, ownerNonce, scAddressBytes, big.NewInt(0), txDataAdd, 5000000) + innerTx1.RelayerAddr = relayer.Bytes + + // 2nd inner tx, successful add 1 + ownerNonce++ + innerTx2 := generateTransaction(owner.Bytes, ownerNonce, scAddressBytes, big.NewInt(0), txDataAdd, 5000000) + innerTx2.RelayerAddr = relayer.Bytes + + // 3rd inner tx, wrong number of parameters + ownerNonce++ + innerTx3 := generateTransaction(owner.Bytes, ownerNonce, scAddressBytes, big.NewInt(0), "add", 5000000) + innerTx3.RelayerAddr = relayer.Bytes + + // 4th inner tx, successful add 1 + ownerNonce++ + innerTx4 := generateTransaction(owner.Bytes, ownerNonce, scAddressBytes, big.NewInt(0), txDataAdd, 5000000) + innerTx4.RelayerAddr = relayer.Bytes + + // 5th inner tx, invalid function + ownerNonce++ + innerTx5 := generateTransaction(owner.Bytes, ownerNonce, scAddressBytes, big.NewInt(0), "substract", 5000000) + innerTx5.RelayerAddr = relayer.Bytes + + // 6th inner tx, successful add 1 + ownerNonce++ + innerTx6 := generateTransaction(owner.Bytes, ownerNonce, scAddressBytes, big.NewInt(0), txDataAdd, 5000000) + innerTx6.RelayerAddr = relayer.Bytes + + // 7th inner tx, not enough gas + ownerNonce++ + innerTx7 := generateTransaction(owner.Bytes, ownerNonce, scAddressBytes, big.NewInt(0), txDataAdd, 100000) + innerTx7.RelayerAddr = relayer.Bytes + + innerTxs := []*transaction.Transaction{innerTx1, innerTx2, innerTx3, innerTx4, innerTx5, innerTx6, innerTx7} + + relayedTxGasLimit := uint64(minGasLimit) + for _, tx := range innerTxs { + relayedTxGasLimit += minGasLimit + tx.GasLimit + } + relayedTx := generateTransaction(relayer.Bytes, 0, relayer.Bytes, big.NewInt(0), "", relayedTxGasLimit) + relayedTx.InnerTransactions = innerTxs + + result, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + checkSum(t, scShardNodeHandler, scAddressBytes, owner.Bytes, 4) + + // 8 scrs, 4 from the succeeded txs + 4 with refunded gas to relayer + require.Equal(t, 8, len(result.SmartContractResults)) + for _, scr := range result.SmartContractResults { + if strings.Contains(scr.ReturnMessage, "gas refund for relayer") { + continue + } + + checkSCRStatus(t, cs, pkConv, shardC, scr) + } + + // 6 scrs, 3 with signalError + 3 with the actual errors + require.Equal(t, 6, len(result.Logs.Events)) + expectedLogEvents := map[int]string{ + 1: "[wrong number of arguments]", + 3: "[invalid function (not found)] [substract]", + 5: "[not enough gas] [add]", + } + for idx, logEvent := range result.Logs.Events { + if logEvent.Identifier == "signalError" { + continue + } + + expectedLogEvent := expectedLogEvents[idx] + require.True(t, strings.Contains(string(logEvent.Data), expectedLogEvent)) + } +} + +func startChainSimulator(t *testing.T) testsChainSimulator.ChainSimulator { + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 30, + } + + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.RelayedTransactionsV3EnableEpoch = 1 + cfg.EpochConfig.EnableEpochs.FixRelayedMoveBalanceEnableEpoch = 1 + }, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + }) + require.NoError(t, err) + require.NotNil(t, cs) + + err = cs.GenerateBlocksUntilEpochIsReached(1) + require.NoError(t, err) + + return cs +} + func generateTransaction(sender []byte, nonce uint64, receiver []byte, value *big.Int, data string, gasLimit uint64) *transaction.Transaction { return &transaction.Transaction{ Nonce: nonce, @@ -191,3 +305,42 @@ func generateTransaction(sender []byte, nonce uint64, receiver []byte, value *bi Signature: []byte(mockTxSignature), } } + +func checkSum( + t *testing.T, + nodeHandler chainSimulatorProcess.NodeHandler, + scAddress []byte, + callerAddress []byte, + expectedSum int, +) { + scQuery := &process.SCQuery{ + ScAddress: scAddress, + FuncName: "getSum", + CallerAddr: callerAddress, + CallValue: big.NewInt(0), + } + result, _, err := nodeHandler.GetFacadeHandler().ExecuteSCQuery(scQuery) + require.Nil(t, err) + require.Equal(t, "ok", result.ReturnCode) + + sum, err := strconv.Atoi(hex.EncodeToString(result.ReturnData[0])) + require.NoError(t, err) + + require.Equal(t, expectedSum, sum) +} + +func checkSCRStatus( + t *testing.T, + cs testsChainSimulator.ChainSimulator, + pkConv core.PubkeyConverter, + shardC sharding.Coordinator, + scr *transaction.ApiSmartContractResult, +) { + addr, err := pkConv.Decode(scr.RcvAddr) + require.NoError(t, err) + + senderShard := shardC.ComputeId(addr) + tx, err := cs.GetNodeHandler(senderShard).GetFacadeHandler().GetTransaction(scr.Hash, true) + require.NoError(t, err) + assert.Equal(t, transaction.TxStatusSuccess, tx.Status) +} diff --git a/process/transactionLog/process.go b/process/transactionLog/process.go index 76a44294cd2..eed686dd0e3 100644 --- a/process/transactionLog/process.go +++ b/process/transactionLog/process.go @@ -36,7 +36,8 @@ type txLogProcessor struct { } // NewTxLogProcessor creates a transaction log processor capable of parsing logs from the VM -// and saving them into the injected storage +// +// and saving them into the injected storage func NewTxLogProcessor(args ArgTxLogProcessor) (*txLogProcessor, error) { storer := args.Storer if check.IfNil(storer) && args.SaveInStorageEnabled { @@ -161,25 +162,54 @@ func (tlp *txLogProcessor) SaveLog(txHash []byte, tx data.TransactionHandler, lo }) } + tlp.mut.Lock() + defer tlp.mut.Unlock() + tlp.saveLogToCache(txHash, txLog) - buff, err := tlp.marshalizer.Marshal(txLog) + return tlp.appendLogToStorer(txHash, txLog) +} + +func (tlp *txLogProcessor) appendLogToStorer(txHash []byte, newLog *transaction.Log) error { + oldLogsBuff, errGet := tlp.storer.Get(txHash) + nilStorerResponse := errGet == nil && len(oldLogsBuff) == 0 + if errGet == storage.ErrKeyNotFound || nilStorerResponse { + allLogsBuff, err := tlp.marshalizer.Marshal(newLog) + if err != nil { + return err + } + + return tlp.storer.Put(txHash, allLogsBuff) + } + if errGet != nil { + return errGet + } + + oldLogs := &transaction.Log{} + err := tlp.marshalizer.Unmarshal(oldLogs, oldLogsBuff) if err != nil { return err } - return tlp.storer.Put(txHash, buff) + if oldLogs.Address == nil { + oldLogs.Address = newLog.Address + } + oldLogs.Events = append(oldLogs.Events, newLog.Events...) + + allLogsBuff, err := tlp.marshalizer.Marshal(oldLogs) + if err != nil { + return err + } + + return tlp.storer.Put(txHash, allLogsBuff) } func (tlp *txLogProcessor) saveLogToCache(txHash []byte, log *transaction.Log) { - tlp.mut.Lock() tlp.logs = append(tlp.logs, &data.LogData{ TxHash: string(txHash), LogHandler: log, }) tlp.logsIndices[string(txHash)] = len(tlp.logs) - 1 - tlp.mut.Unlock() - } // For SC deployment transactions, we use the sender address diff --git a/process/transactionLog/process_test.go b/process/transactionLog/process_test.go index f132c865486..c9247cc3d0b 100644 --- a/process/transactionLog/process_test.go +++ b/process/transactionLog/process_test.go @@ -8,11 +8,15 @@ import ( "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/mock" "github.com/multiversx/mx-chain-go/process/transactionLog" + "github.com/multiversx/mx-chain-go/testscommon" + "github.com/multiversx/mx-chain-go/testscommon/genericMocks" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/stretchr/testify/require" ) +var expectedErr = errors.New("expected err") + func TestNewTxLogProcessor_NilParameters(t *testing.T) { _, nilMarshalizer := transactionLog.NewTxLogProcessor(transactionLog.ArgTxLogProcessor{ Storer: &storageStubs.StorerStub{}, @@ -88,7 +92,7 @@ func TestTxLogProcessor_SaveLogsMarshalErr(t *testing.T) { retErr := errors.New("marshal err") txLogProcessor, _ := transactionLog.NewTxLogProcessor(transactionLog.ArgTxLogProcessor{ Storer: &storageStubs.StorerStub{}, - Marshalizer: &mock.MarshalizerStub{ + Marshalizer: &testscommon.MarshallerStub{ MarshalCalled: func(obj interface{}) (bytes []byte, err error) { return nil, retErr }, @@ -111,7 +115,7 @@ func TestTxLogProcessor_SaveLogsStoreErr(t *testing.T) { return retErr }, }, - Marshalizer: &mock.MarshalizerStub{ + Marshalizer: &testscommon.MarshallerStub{ MarshalCalled: func(obj interface{}) (bytes []byte, err error) { return nil, nil }, @@ -126,6 +130,87 @@ func TestTxLogProcessor_SaveLogsStoreErr(t *testing.T) { require.Equal(t, retErr, err) } +func TestTxLogProcessor_SaveLogsGetErrShouldError(t *testing.T) { + t.Parallel() + + txLogProcessor, _ := transactionLog.NewTxLogProcessor(transactionLog.ArgTxLogProcessor{ + Storer: &storageStubs.StorerStub{ + GetCalled: func(key []byte) ([]byte, error) { + return nil, expectedErr + }, + }, + Marshalizer: &mock.MarshalizerMock{}, + SaveInStorageEnabled: true, + }) + + logs := []*vmcommon.LogEntry{ + {Address: []byte("first log")}, + } + err := txLogProcessor.SaveLog([]byte("txhash"), &transaction.Transaction{}, logs) + require.Equal(t, expectedErr, err) +} + +func TestTxLogProcessor_SaveLogsUnmarshalErrShouldError(t *testing.T) { + t.Parallel() + + txLogProcessor, _ := transactionLog.NewTxLogProcessor(transactionLog.ArgTxLogProcessor{ + Storer: &storageStubs.StorerStub{ + GetCalled: func(key []byte) ([]byte, error) { + return []byte("dummy buff"), nil + }, + }, + Marshalizer: &testscommon.MarshallerStub{ + UnmarshalCalled: func(obj interface{}, buff []byte) error { + return expectedErr + }, + }, + SaveInStorageEnabled: true, + }) + + logs := []*vmcommon.LogEntry{ + {Address: []byte("first log")}, + } + err := txLogProcessor.SaveLog([]byte("txhash"), &transaction.Transaction{}, logs) + require.Equal(t, expectedErr, err) +} + +func TestTxLogProcessor_SaveLogsShouldWorkAndAppend(t *testing.T) { + t.Parallel() + + providedHash := []byte("txhash") + storer := genericMocks.NewStorerMockWithErrKeyNotFound(0) + marshaller := &mock.MarshalizerMock{} + txLogProcessor, _ := transactionLog.NewTxLogProcessor(transactionLog.ArgTxLogProcessor{ + Storer: storer, + Marshalizer: marshaller, + SaveInStorageEnabled: true, + }) + + oldLogs := []*vmcommon.LogEntry{ + {Address: []byte("addr 1"), Data: [][]byte{[]byte("old data 1")}}, + {Address: []byte("addr 2"), Data: [][]byte{[]byte("old data 2")}}, + } + + err := txLogProcessor.SaveLog(providedHash, &transaction.Transaction{}, oldLogs) + require.NoError(t, err) + + newLogs := []*vmcommon.LogEntry{ + {Address: []byte("addr 3"), Data: [][]byte{[]byte("new data 1")}}, + } + + err = txLogProcessor.SaveLog(providedHash, &transaction.Transaction{SndAddr: []byte("sender")}, newLogs) + require.NoError(t, err) + + buff, err := storer.Get(providedHash) + require.NoError(t, err) + + allLogs := &transaction.Log{} + err = marshaller.Unmarshal(allLogs, buff) + require.NoError(t, err) + + require.Equal(t, 3, len(allLogs.Events)) +} + func TestTxLogProcessor_SaveLogsCallsPutWithMarshalBuff(t *testing.T) { buffExpected := []byte("marshaled log") buffActual := []byte("currently wrong value") @@ -138,7 +223,7 @@ func TestTxLogProcessor_SaveLogsCallsPutWithMarshalBuff(t *testing.T) { return nil }, }, - Marshalizer: &mock.MarshalizerStub{ + Marshalizer: &testscommon.MarshallerStub{ MarshalCalled: func(obj interface{}) (bytes []byte, err error) { log, _ := obj.(*transaction.Log) require.Equal(t, expectedLogData[0], log.Events[0].Data) @@ -164,7 +249,7 @@ func TestTxLogProcessor_GetLogErrNotFound(t *testing.T) { return nil, errors.New("storer error") }, }, - Marshalizer: &mock.MarshalizerStub{}, + Marshalizer: &testscommon.MarshallerStub{}, SaveInStorageEnabled: true, }) @@ -181,7 +266,7 @@ func TestTxLogProcessor_GetLogUnmarshalErr(t *testing.T) { return make([]byte, 0), nil }, }, - Marshalizer: &mock.MarshalizerStub{ + Marshalizer: &testscommon.MarshallerStub{ UnmarshalCalled: func(obj interface{}, buff []byte) error { return retErr }, @@ -240,3 +325,19 @@ func TestTxLogProcessor_GetLogFromCacheNotInCacheShouldReturnFromStorage(t *test _, found := txLogProcessor.GetLogFromCache([]byte("txhash")) require.True(t, found) } + +func TestTxLogProcessor_IsInterfaceNil(t *testing.T) { + t.Parallel() + + txLogProcessor, _ := transactionLog.NewTxLogProcessor(transactionLog.ArgTxLogProcessor{ + Storer: &storageStubs.StorerStub{}, + Marshalizer: nil, + }) + require.True(t, txLogProcessor.IsInterfaceNil()) + + txLogProcessor, _ = transactionLog.NewTxLogProcessor(transactionLog.ArgTxLogProcessor{ + Storer: &storageStubs.StorerStub{}, + Marshalizer: &testscommon.MarshallerStub{}, + }) + require.False(t, txLogProcessor.IsInterfaceNil()) +} From 9a3d0a26dbbd973c2afc3460a01fe318a23f673e Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 17 May 2024 09:50:41 +0300 Subject: [PATCH 244/503] added missing file --- .../chainSimulator/relayedTx/testData/adder.wasm | Bin 0 -> 695 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 integrationTests/chainSimulator/relayedTx/testData/adder.wasm diff --git a/integrationTests/chainSimulator/relayedTx/testData/adder.wasm b/integrationTests/chainSimulator/relayedTx/testData/adder.wasm new file mode 100644 index 0000000000000000000000000000000000000000..b6bc9b4e13b3123daeafd40369383a54197cd160 GIT binary patch literal 695 zcmZuvO>dh(5S`g2n6M3OVyl&-9;i?4DYu@Br8=$P-~y=D)`C zb$XLm*RuMVm+Lf_NvP5~lX(Ty@O~<*yE;39C7?l>k&5kir3%&QF0yI8TuSv&6-uP? zwh##rBmK}5KZYpEMBu**mPi2KSDg$*fR20+zO` z;M~>=dZ;tFphBArorTzLr(&^z(V%`zl}IF%VBkiJL z5+Fa(aX`3z$%Y*W;j_-BeDErCLgZ(heFDz4iO)RXj&A9UbMEm|79eeU1#&(i+?(jC t+S(0BtEYgBUFl|ZTkPX+Rpe=q*V$aEpjZZ?|E0=OFUpL?te3;#@DIbRt0DjZ literal 0 HcmV?d00001 From f2efedd51dc4d2aac1ee9f4073876a8bfb7f604d Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Fri, 17 May 2024 13:22:38 +0300 Subject: [PATCH 245/503] add epoch enable flag for cleanup --- cmd/node/config/enableEpochs.toml | 4 + common/constants.go | 1 + common/enablers/enableEpochsHandler.go | 9 ++- common/enablers/enableEpochsHandler_test.go | 9 ++- config/epochConfig.go | 1 + config/tomlConfig_test.go | 9 ++- .../staking/stake/stakeAndUnStake_test.go | 1 + .../nodesCoordinator/hashValidatorShuffler.go | 74 ++++++++++--------- .../indexHashedNodesCoordinatorRegistry.go | 3 +- 9 files changed, 71 insertions(+), 40 deletions(-) diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index d24e57df7e7..9502cceba9a 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -302,6 +302,10 @@ # StakingV4Step3EnableEpoch represents the epoch in which selected nodes from auction will be distributed to waiting list StakingV4Step3EnableEpoch = 3 + # CleanupAuctionOnLowWaitingListEnableEpoch represents the epoch when duplicated data cleanup from auction list is enabled in the condition of a low waiting list + # Should have the same value as StakingV4Step1EnableEpoch if the low waiting list has not happened, otherwise should have a greater value + CleanupAuctionOnLowWaitingListEnableEpoch = 1 + # AlwaysMergeContextsInEEIEnableEpoch represents the epoch in which the EEI will always merge the contexts AlwaysMergeContextsInEEIEnableEpoch = 1 diff --git a/common/constants.go b/common/constants.go index 16c77a5d147..5320ee675c1 100644 --- a/common/constants.go +++ b/common/constants.go @@ -1011,6 +1011,7 @@ const ( StakingV4Step1Flag core.EnableEpochFlag = "StakingV4Step1Flag" StakingV4Step2Flag core.EnableEpochFlag = "StakingV4Step2Flag" StakingV4Step3Flag core.EnableEpochFlag = "StakingV4Step3Flag" + CleanupAuctionOnLowWaitingListFlag core.EnableEpochFlag = "CleanupAuctionOnLowWaitingListFlag" StakingV4StartedFlag core.EnableEpochFlag = "StakingV4StartedFlag" AlwaysMergeContextsInEEIFlag core.EnableEpochFlag = "AlwaysMergeContextsInEEIFlag" // all new flags must be added to createAllFlagsMap method, as part of enableEpochsHandler allFlagsDefined diff --git a/common/enablers/enableEpochsHandler.go b/common/enablers/enableEpochsHandler.go index f64dbf99ea5..5ce3812742f 100644 --- a/common/enablers/enableEpochsHandler.go +++ b/common/enablers/enableEpochsHandler.go @@ -6,10 +6,11 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/process" - logger "github.com/multiversx/mx-chain-logger-go" ) var log = logger.GetOrCreate("common/enablers") @@ -713,6 +714,12 @@ func (handler *enableEpochsHandler) createAllFlagsMap() { }, activationEpoch: handler.enableEpochsConfig.StakingV4Step3EnableEpoch, }, + common.CleanupAuctionOnLowWaitingListFlag: { + isActiveInEpoch: func(epoch uint32) bool { + return epoch >= handler.enableEpochsConfig.CleanupAuctionOnLowWaitingListEnableEpoch + }, + activationEpoch: handler.enableEpochsConfig.CleanupAuctionOnLowWaitingListEnableEpoch, + }, common.StakingV4StartedFlag: { isActiveInEpoch: func(epoch uint32) bool { return epoch >= handler.enableEpochsConfig.StakingV4Step1EnableEpoch diff --git a/common/enablers/enableEpochsHandler_test.go b/common/enablers/enableEpochsHandler_test.go index 4155b15dfbb..2c568f2043b 100644 --- a/common/enablers/enableEpochsHandler_test.go +++ b/common/enablers/enableEpochsHandler_test.go @@ -5,13 +5,14 @@ import ( "testing" "github.com/multiversx/mx-chain-core-go/core/check" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func createEnableEpochsConfig() config.EnableEpochs { @@ -113,6 +114,7 @@ func createEnableEpochsConfig() config.EnableEpochs { StakingV4Step1EnableEpoch: 96, StakingV4Step2EnableEpoch: 97, StakingV4Step3EnableEpoch: 98, + CleanupAuctionOnLowWaitingListEnableEpoch: 96, AlwaysMergeContextsInEEIEnableEpoch: 99, } } @@ -426,6 +428,7 @@ func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) { require.Equal(t, cfg.StakingV4Step1EnableEpoch, handler.GetActivationEpoch(common.StakingV4Step1Flag)) require.Equal(t, cfg.StakingV4Step2EnableEpoch, handler.GetActivationEpoch(common.StakingV4Step2Flag)) require.Equal(t, cfg.StakingV4Step3EnableEpoch, handler.GetActivationEpoch(common.StakingV4Step3Flag)) + require.Equal(t, cfg.CleanupAuctionOnLowWaitingListEnableEpoch, handler.GetActivationEpoch(common.CleanupAuctionOnLowWaitingListFlag)) require.Equal(t, cfg.StakingV4Step1EnableEpoch, handler.GetActivationEpoch(common.StakingV4StartedFlag)) require.Equal(t, cfg.AlwaysMergeContextsInEEIEnableEpoch, handler.GetActivationEpoch(common.AlwaysMergeContextsInEEIFlag)) } diff --git a/config/epochConfig.go b/config/epochConfig.go index 7789ecc72b3..764970ae050 100644 --- a/config/epochConfig.go +++ b/config/epochConfig.go @@ -112,6 +112,7 @@ type EnableEpochs struct { StakingV4Step1EnableEpoch uint32 StakingV4Step2EnableEpoch uint32 StakingV4Step3EnableEpoch uint32 + CleanupAuctionOnLowWaitingListEnableEpoch uint32 AlwaysMergeContextsInEEIEnableEpoch uint32 BLSMultiSignerEnableEpoch []MultiSignerConfig } diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index 45dd2c7ef00..84d0a7ecb57 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -5,10 +5,11 @@ import ( "strconv" "testing" - p2pConfig "github.com/multiversx/mx-chain-go/p2p/config" "github.com/pelletier/go-toml" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + p2pConfig "github.com/multiversx/mx-chain-go/p2p/config" ) func TestTomlParser(t *testing.T) { @@ -839,10 +840,13 @@ func TestEnableEpochConfig(t *testing.T) { # CurrentRandomnessOnSortingEnableEpoch represents the epoch when the current randomness on sorting is enabled CurrentRandomnessOnSortingEnableEpoch = 93 - + # AlwaysMergeContextsInEEIEnableEpoch represents the epoch in which the EEI will always merge the contexts AlwaysMergeContextsInEEIEnableEpoch = 94 + # CleanupAuctionOnLowWaitingListEnableEpoch represents the epoch when the cleanup auction on low waiting list is enabled + CleanupAuctionOnLowWaitingListEnableEpoch = 95 + # MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MaxNodesChangeEnableEpoch = [ { EpochEnable = 44, MaxNumNodes = 2169, NodesToShufflePerShard = 80 }, @@ -955,6 +959,7 @@ func TestEnableEpochConfig(t *testing.T) { MigrateDataTrieEnableEpoch: 92, CurrentRandomnessOnSortingEnableEpoch: 93, AlwaysMergeContextsInEEIEnableEpoch: 94, + CleanupAuctionOnLowWaitingListEnableEpoch: 95, MaxNodesChangeEnableEpoch: []MaxNodesChangeConfig{ { EpochEnable: 44, diff --git a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index a46d800fe82..b3a1f1b7d4f 100644 --- a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go @@ -2348,6 +2348,7 @@ func TestChainSimulator_UnStakeOneActiveNodeAndCheckAPIAuctionList(t *testing.T) cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = stakingV4Step1Epoch cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = stakingV4Step2Epoch cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = stakingV4Step3Epoch + cfg.EpochConfig.EnableEpochs.CleanupAuctionOnLowWaitingListEnableEpoch = stakingV4Step1Epoch cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[1].MaxNumNodes = 32 cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[1].NodesToShufflePerShard = 2 diff --git a/sharding/nodesCoordinator/hashValidatorShuffler.go b/sharding/nodesCoordinator/hashValidatorShuffler.go index 7c54e132ffc..71d2b5351b3 100644 --- a/sharding/nodesCoordinator/hashValidatorShuffler.go +++ b/sharding/nodesCoordinator/hashValidatorShuffler.go @@ -31,22 +31,23 @@ type NodesShufflerArgs struct { } type shuffleNodesArg struct { - eligible map[uint32][]Validator - waiting map[uint32][]Validator - unstakeLeaving []Validator - additionalLeaving []Validator - newNodes []Validator - auction []Validator - randomness []byte - distributor ValidatorsDistributor - nodesMeta uint32 - nodesPerShard uint32 - nbShards uint32 - maxNodesToSwapPerShard uint32 - maxNumNodes uint32 - flagBalanceWaitingLists bool - flagStakingV4Step2 bool - flagStakingV4Step3 bool + eligible map[uint32][]Validator + waiting map[uint32][]Validator + unstakeLeaving []Validator + additionalLeaving []Validator + newNodes []Validator + auction []Validator + randomness []byte + distributor ValidatorsDistributor + nodesMeta uint32 + nodesPerShard uint32 + nbShards uint32 + maxNodesToSwapPerShard uint32 + maxNumNodes uint32 + flagBalanceWaitingLists bool + flagStakingV4Step2 bool + flagStakingV4Step3 bool + flagCleanupAuctionOnLowWaitingList bool } type shuffledNodesConfig struct { @@ -91,6 +92,7 @@ func NewHashValidatorsShuffler(args *NodesShufflerArgs) (*randHashShuffler, erro } err := core.CheckHandlerCompatibility(args.EnableEpochsHandler, []core.EnableEpochFlag{ common.BalanceWaitingListsFlag, + common.CleanupAuctionOnLowWaitingListFlag, }) if err != nil { return nil, err @@ -197,22 +199,23 @@ func (rhs *randHashShuffler) UpdateNodeLists(args ArgsUpdateNodes) (*ResUpdateNo } return shuffleNodes(shuffleNodesArg{ - eligible: eligibleAfterReshard, - waiting: waitingAfterReshard, - unstakeLeaving: args.UnStakeLeaving, - additionalLeaving: args.AdditionalLeaving, - newNodes: args.NewNodes, - auction: args.Auction, - randomness: args.Rand, - nodesMeta: nodesMeta, - nodesPerShard: nodesPerShard, - nbShards: args.NbShards, - distributor: rhs.validatorDistributor, - maxNodesToSwapPerShard: rhs.activeNodesConfig.NodesToShufflePerShard, - flagBalanceWaitingLists: rhs.enableEpochsHandler.IsFlagEnabledInEpoch(common.BalanceWaitingListsFlag, args.Epoch), - flagStakingV4Step2: rhs.flagStakingV4Step2.IsSet(), - flagStakingV4Step3: rhs.flagStakingV4Step3.IsSet(), - maxNumNodes: rhs.activeNodesConfig.MaxNumNodes, + eligible: eligibleAfterReshard, + waiting: waitingAfterReshard, + unstakeLeaving: args.UnStakeLeaving, + additionalLeaving: args.AdditionalLeaving, + newNodes: args.NewNodes, + auction: args.Auction, + randomness: args.Rand, + nodesMeta: nodesMeta, + nodesPerShard: nodesPerShard, + nbShards: args.NbShards, + distributor: rhs.validatorDistributor, + maxNodesToSwapPerShard: rhs.activeNodesConfig.NodesToShufflePerShard, + flagBalanceWaitingLists: rhs.enableEpochsHandler.IsFlagEnabledInEpoch(common.BalanceWaitingListsFlag, args.Epoch), + flagStakingV4Step2: rhs.flagStakingV4Step2.IsSet(), + flagStakingV4Step3: rhs.flagStakingV4Step3.IsSet(), + maxNumNodes: rhs.activeNodesConfig.MaxNumNodes, + flagCleanupAuctionOnLowWaitingList: rhs.enableEpochsHandler.IsFlagEnabledInEpoch(common.CleanupAuctionOnLowWaitingListFlag, args.Epoch), }) } @@ -345,13 +348,18 @@ func shuffleNodes(arg shuffleNodesArg) (*ResUpdateNodes, error) { actualLeaving, _ := removeValidatorsFromList(allLeaving, stillRemainingInLeaving, len(stillRemainingInLeaving)) + shouldCleanupAuction := false + if arg.flagCleanupAuctionOnLowWaitingList { + shouldCleanupAuction = lowWaitingList + } + return &ResUpdateNodes{ Eligible: newEligible, Waiting: newWaiting, ShuffledOut: shuffledOutMap, Leaving: actualLeaving, StillRemaining: stillRemainingInLeaving, - LowWaitingList: lowWaitingList, + LowWaitingList: shouldCleanupAuction, }, nil } diff --git a/sharding/nodesCoordinator/indexHashedNodesCoordinatorRegistry.go b/sharding/nodesCoordinator/indexHashedNodesCoordinatorRegistry.go index 813929bac90..55cbb326753 100644 --- a/sharding/nodesCoordinator/indexHashedNodesCoordinatorRegistry.go +++ b/sharding/nodesCoordinator/indexHashedNodesCoordinatorRegistry.go @@ -61,7 +61,7 @@ func displayNodesConfigInfo(config map[uint32]*epochNodesConfig) { func (ihnc *indexHashedNodesCoordinator) saveState(key []byte, epoch uint32) error { registry := ihnc.NodesCoordinatorToRegistry(epoch) - data, err := ihnc.nodesCoordinatorRegistryFactory.GetRegistryData(registry, ihnc.currentEpoch) + data, err := ihnc.nodesCoordinatorRegistryFactory.GetRegistryData(registry, epoch) if err != nil { return err } @@ -212,6 +212,7 @@ func epochValidatorsToEpochNodesConfig(config EpochValidatorsHandler) (*epochNod if err != nil { return nil, err } + result.lowWaitingList = configWithAuction.GetLowWaitingList() } return result, nil From 1dd6e0755e3d063447980f2e61d41d28c83ff34e Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Fri, 17 May 2024 13:23:02 +0300 Subject: [PATCH 246/503] fix restore from registry --- ...ndexHashedNodesCoordinatorRegistry_test.go | 34 +++++++++++++++++-- sharding/nodesCoordinator/interface.go | 1 + .../nodesCoordinatorRegistryFactory.go | 2 +- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/sharding/nodesCoordinator/indexHashedNodesCoordinatorRegistry_test.go b/sharding/nodesCoordinator/indexHashedNodesCoordinatorRegistry_test.go index b2b99e6e87b..0a91ba9170a 100644 --- a/sharding/nodesCoordinator/indexHashedNodesCoordinatorRegistry_test.go +++ b/sharding/nodesCoordinator/indexHashedNodesCoordinatorRegistry_test.go @@ -7,10 +7,11 @@ import ( "testing" "github.com/multiversx/mx-chain-core-go/core" - "github.com/multiversx/mx-chain-go/common" - "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" ) func sameValidatorsMaps(map1, map2 map[uint32][]Validator) bool { @@ -174,6 +175,35 @@ func TestIndexHashedNodesCoordinator_nodesCoordinatorToRegistry(t *testing.T) { } } +func TestIndexHashedNodesCoordinator_nodesCoordinatorWithAuctionToRegistryAndBack(t *testing.T) { + args := createArguments() + nodesCoordinator, _ := NewIndexHashedNodesCoordinator(args) + + nodesConfigForEpoch := nodesCoordinator.nodesConfig[args.Epoch] + nodesConfigForEpoch.shuffledOutMap = createDummyNodesMap(3, 0, string(common.WaitingList)) + nodesConfigForEpoch.lowWaitingList = true + // leave only one epoch config in nc + nodesCoordinator.nodesConfig = make(map[uint32]*epochNodesConfig) + nodesCoordinator.nodesConfig[args.Epoch] = nodesConfigForEpoch + + ncr := nodesCoordinator.nodesCoordinatorToRegistryWithAuction() + require.True(t, sameValidatorsDifferentMapTypes(nodesConfigForEpoch.eligibleMap, ncr.GetEpochsConfig()[fmt.Sprint(args.Epoch)].GetEligibleValidators())) + require.True(t, sameValidatorsDifferentMapTypes(nodesConfigForEpoch.waitingMap, ncr.GetEpochsConfig()[fmt.Sprint(args.Epoch)].GetWaitingValidators())) + require.True(t, sameValidatorsDifferentMapTypes(nodesConfigForEpoch.shuffledOutMap, ncr.GetEpochsConfigWithAuction()[fmt.Sprint(args.Epoch)].GetShuffledOutValidators())) + require.Equal(t, nodesConfigForEpoch.lowWaitingList, ncr.GetEpochsConfigWithAuction()[fmt.Sprint(args.Epoch)].GetLowWaitingList()) + + nodesConfig, err := nodesCoordinator.registryToNodesCoordinator(ncr) + require.Nil(t, err) + + assert.Equal(t, len(nodesCoordinator.nodesConfig), len(nodesConfig)) + for epoch, config := range nodesCoordinator.nodesConfig { + require.True(t, sameValidatorsMaps(config.eligibleMap, nodesConfig[epoch].eligibleMap)) + require.True(t, sameValidatorsMaps(config.waitingMap, nodesConfig[epoch].waitingMap)) + require.True(t, sameValidatorsMaps(config.shuffledOutMap, nodesConfig[epoch].shuffledOutMap)) + require.Equal(t, config.lowWaitingList, nodesConfig[epoch].lowWaitingList) + } +} + func TestIndexHashedNodesCoordinator_registryToNodesCoordinator(t *testing.T) { args := createArguments() nodesCoordinator1, _ := NewIndexHashedNodesCoordinator(args) diff --git a/sharding/nodesCoordinator/interface.go b/sharding/nodesCoordinator/interface.go index b962c6fa50a..5e2d5564a5c 100644 --- a/sharding/nodesCoordinator/interface.go +++ b/sharding/nodesCoordinator/interface.go @@ -154,6 +154,7 @@ type EpochValidatorsHandler interface { type EpochValidatorsHandlerWithAuction interface { EpochValidatorsHandler GetShuffledOutValidators() map[string][]*SerializableValidator + GetLowWaitingList() bool } // NodesCoordinatorRegistryHandler defines what is used to initialize nodes coordinator diff --git a/sharding/nodesCoordinator/nodesCoordinatorRegistryFactory.go b/sharding/nodesCoordinator/nodesCoordinatorRegistryFactory.go index 0ef508fbf89..894d3f7a1f0 100644 --- a/sharding/nodesCoordinator/nodesCoordinatorRegistryFactory.go +++ b/sharding/nodesCoordinator/nodesCoordinatorRegistryFactory.go @@ -49,7 +49,7 @@ func (ncf *nodesCoordinatorRegistryFactory) createRegistryWithAuction(buff []byt return nil, err } - log.Debug("nodesCoordinatorRegistryFactory.CreateNodesCoordinatorRegistry created old registry", + log.Debug("nodesCoordinatorRegistryFactory.CreateNodesCoordinatorRegistry created registry with auction", "epoch", registry.CurrentEpoch) return registry, nil } From 8968d5cfaf04fe8883ecd86b268beaa1f03ba103 Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Fri, 17 May 2024 14:18:19 +0300 Subject: [PATCH 247/503] fix alignment --- config/tomlConfig_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index 84d0a7ecb57..eaeb4e6e2ae 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -840,12 +840,12 @@ func TestEnableEpochConfig(t *testing.T) { # CurrentRandomnessOnSortingEnableEpoch represents the epoch when the current randomness on sorting is enabled CurrentRandomnessOnSortingEnableEpoch = 93 - + # AlwaysMergeContextsInEEIEnableEpoch represents the epoch in which the EEI will always merge the contexts AlwaysMergeContextsInEEIEnableEpoch = 94 - # CleanupAuctionOnLowWaitingListEnableEpoch represents the epoch when the cleanup auction on low waiting list is enabled - CleanupAuctionOnLowWaitingListEnableEpoch = 95 + # CleanupAuctionOnLowWaitingListEnableEpoch represents the epoch when the cleanup auction on low waiting list is enabled + CleanupAuctionOnLowWaitingListEnableEpoch = 95 # MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MaxNodesChangeEnableEpoch = [ From 1786b4fa335070d03fdaef801e099a8f7dc3a531 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 20 May 2024 11:00:40 +0300 Subject: [PATCH 248/503] - added synced transaction sender component --- node/chainSimulator/components/interface.go | 6 + .../components/processComponents.go | 27 ++- .../components/syncedTxsSender.go | 110 +++++++++ .../components/syncedTxsSender_test.go | 211 ++++++++++++++++++ 4 files changed, 353 insertions(+), 1 deletion(-) create mode 100644 node/chainSimulator/components/syncedTxsSender.go create mode 100644 node/chainSimulator/components/syncedTxsSender_test.go diff --git a/node/chainSimulator/components/interface.go b/node/chainSimulator/components/interface.go index 4b1421341a0..6456c1e2b32 100644 --- a/node/chainSimulator/components/interface.go +++ b/node/chainSimulator/components/interface.go @@ -16,3 +16,9 @@ type SyncedBroadcastNetworkHandler interface { type APIConfigurator interface { RestApiInterface(shardID uint32) string } + +// NetworkMessenger defines what a network messenger should do +type NetworkMessenger interface { + Broadcast(topic string, buff []byte) + IsInterfaceNil() bool +} diff --git a/node/chainSimulator/components/processComponents.go b/node/chainSimulator/components/processComponents.go index 3bfd598f98d..3bef305e8c7 100644 --- a/node/chainSimulator/components/processComponents.go +++ b/node/chainSimulator/components/processComponents.go @@ -7,6 +7,7 @@ import ( "path/filepath" "time" + "github.com/multiversx/mx-chain-core-go/core/partitioning" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/forking" "github.com/multiversx/mx-chain-go/common/ordering" @@ -265,7 +266,7 @@ func CreateProcessComponents(args ArgsProcessComponentsHolder) (*processComponen nodeRedundancyHandler: managedProcessComponents.NodeRedundancyHandler(), currentEpochProvider: managedProcessComponents.CurrentEpochProvider(), scheduledTxsExecutionHandler: managedProcessComponents.ScheduledTxsExecutionHandler(), - txsSenderHandler: managedProcessComponents.TxsSenderHandler(), + txsSenderHandler: managedProcessComponents.TxsSenderHandler(), // warning: this will be replaced hardforkTrigger: managedProcessComponents.HardforkTrigger(), processedMiniBlocksTracker: managedProcessComponents.ProcessedMiniBlocksTracker(), esdtDataStorageHandlerForAPI: managedProcessComponents.ESDTDataStorageHandlerForAPI(), @@ -275,6 +276,30 @@ func CreateProcessComponents(args ArgsProcessComponentsHolder) (*processComponen managedProcessComponentsCloser: managedProcessComponents, } + return replaceWithCustomProcessSubComponents(instance, processArgs) +} + +func replaceWithCustomProcessSubComponents( + instance *processComponentsHolder, + processArgs processComp.ProcessComponentsFactoryArgs, +) (*processComponentsHolder, error) { + dataPacker, err := partitioning.NewSimpleDataPacker(processArgs.CoreData.InternalMarshalizer()) + if err != nil { + return nil, fmt.Errorf("%w in replaceWithCustomProcessSubComponents", err) + } + + argsSyncedTxsSender := ArgsSyncedTxsSender{ + Marshaller: processArgs.CoreData.InternalMarshalizer(), + ShardCoordinator: processArgs.BootstrapComponents.ShardCoordinator(), + NetworkMessenger: processArgs.Network.NetworkMessenger(), + DataPacker: dataPacker, + } + + instance.txsSenderHandler, err = NewSyncedTxsSender(argsSyncedTxsSender) + if err != nil { + return nil, fmt.Errorf("%w in replaceWithCustomProcessSubComponents", err) + } + return instance, nil } diff --git a/node/chainSimulator/components/syncedTxsSender.go b/node/chainSimulator/components/syncedTxsSender.go new file mode 100644 index 00000000000..9434c72a041 --- /dev/null +++ b/node/chainSimulator/components/syncedTxsSender.go @@ -0,0 +1,110 @@ +package components + +import ( + "github.com/multiversx/mx-chain-core-go/core/check" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-core-go/marshal" + "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/dataRetriever" + "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/process/factory" + "github.com/multiversx/mx-chain-go/sharding" +) + +// ArgsSyncedTxsSender is a holder struct for all necessary arguments to create a NewSyncedTxsSender +type ArgsSyncedTxsSender struct { + Marshaller marshal.Marshalizer + ShardCoordinator sharding.Coordinator + NetworkMessenger NetworkMessenger + DataPacker process.DataPacker +} + +type syncedTxsSender struct { + marshaller marshal.Marshalizer + shardCoordinator sharding.Coordinator + networkMessenger NetworkMessenger + dataPacker process.DataPacker +} + +// NewSyncedTxsSender creates a new instance of syncedTxsSender +func NewSyncedTxsSender(args ArgsSyncedTxsSender) (*syncedTxsSender, error) { + if check.IfNil(args.Marshaller) { + return nil, process.ErrNilMarshalizer + } + if check.IfNil(args.ShardCoordinator) { + return nil, process.ErrNilShardCoordinator + } + if check.IfNil(args.NetworkMessenger) { + return nil, process.ErrNilMessenger + } + if check.IfNil(args.DataPacker) { + return nil, dataRetriever.ErrNilDataPacker + } + + ret := &syncedTxsSender{ + marshaller: args.Marshaller, + shardCoordinator: args.ShardCoordinator, + networkMessenger: args.NetworkMessenger, + dataPacker: args.DataPacker, + } + + return ret, nil +} + +// SendBulkTransactions sends the provided transactions as a bulk, optimizing transfer between nodes +func (sender *syncedTxsSender) SendBulkTransactions(txs []*transaction.Transaction) (uint64, error) { + if len(txs) == 0 { + return 0, process.ErrNoTxToProcess + } + + sender.sendBulkTransactions(txs) + + return uint64(len(txs)), nil +} + +func (sender *syncedTxsSender) sendBulkTransactions(txs []*transaction.Transaction) { + transactionsByShards := make(map[uint32][][]byte) + for _, tx := range txs { + marshalledTx, err := sender.marshaller.Marshal(tx) + if err != nil { + log.Warn("txsSender.sendBulkTransactions", + "marshaller error", err, + ) + continue + } + + senderShardId := sender.shardCoordinator.ComputeId(tx.SndAddr) + transactionsByShards[senderShardId] = append(transactionsByShards[senderShardId], marshalledTx) + } + + for shardId, txsForShard := range transactionsByShards { + err := sender.sendBulkTransactionsFromShard(txsForShard, shardId) + log.LogIfError(err) + } +} + +func (sender *syncedTxsSender) sendBulkTransactionsFromShard(transactions [][]byte, senderShardId uint32) error { + // the topic identifier is made of the current shard id and sender's shard id + identifier := factory.TransactionTopic + sender.shardCoordinator.CommunicationIdentifier(senderShardId) + + packets, err := sender.dataPacker.PackDataInChunks(transactions, common.MaxBulkTransactionSize) + if err != nil { + return err + } + + for _, buff := range packets { + sender.networkMessenger.Broadcast(identifier, buff) + } + + return nil +} + +// Close returns nil +func (sender *syncedTxsSender) Close() error { + return nil +} + +// IsInterfaceNil checks if the underlying pointer is nil +func (sender *syncedTxsSender) IsInterfaceNil() bool { + return sender == nil +} diff --git a/node/chainSimulator/components/syncedTxsSender_test.go b/node/chainSimulator/components/syncedTxsSender_test.go new file mode 100644 index 00000000000..9af295c47cf --- /dev/null +++ b/node/chainSimulator/components/syncedTxsSender_test.go @@ -0,0 +1,211 @@ +package components + +import ( + "fmt" + "strings" + "testing" + + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-go/dataRetriever" + "github.com/multiversx/mx-chain-go/dataRetriever/mock" + "github.com/multiversx/mx-chain-go/process" + processMock "github.com/multiversx/mx-chain-go/process/mock" + "github.com/multiversx/mx-chain-go/testscommon" + "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" + "github.com/multiversx/mx-chain-go/testscommon/p2pmocks" + "github.com/stretchr/testify/assert" +) + +func createMockSyncedTxsSenderArgs() ArgsSyncedTxsSender { + return ArgsSyncedTxsSender{ + Marshaller: &marshallerMock.MarshalizerMock{}, + ShardCoordinator: testscommon.NewMultiShardsCoordinatorMock(3), + NetworkMessenger: &p2pmocks.MessengerStub{}, + DataPacker: &mock.DataPackerStub{}, + } +} + +func TestNewSyncedTxsSender(t *testing.T) { + t.Parallel() + + t.Run("nil marshaller should error", func(t *testing.T) { + t.Parallel() + + args := createMockSyncedTxsSenderArgs() + args.Marshaller = nil + sender, err := NewSyncedTxsSender(args) + + assert.Equal(t, process.ErrNilMarshalizer, err) + assert.Nil(t, sender) + }) + t.Run("nil shard coordinator should error", func(t *testing.T) { + t.Parallel() + + args := createMockSyncedTxsSenderArgs() + args.ShardCoordinator = nil + sender, err := NewSyncedTxsSender(args) + + assert.Equal(t, process.ErrNilShardCoordinator, err) + assert.Nil(t, sender) + }) + t.Run("nil network messenger should error", func(t *testing.T) { + t.Parallel() + + args := createMockSyncedTxsSenderArgs() + args.NetworkMessenger = nil + sender, err := NewSyncedTxsSender(args) + + assert.Equal(t, process.ErrNilMessenger, err) + assert.Nil(t, sender) + }) + t.Run("nil data packer should error", func(t *testing.T) { + t.Parallel() + + args := createMockSyncedTxsSenderArgs() + args.DataPacker = nil + sender, err := NewSyncedTxsSender(args) + + assert.Equal(t, dataRetriever.ErrNilDataPacker, err) + assert.Nil(t, sender) + }) + t.Run("should work", func(t *testing.T) { + t.Parallel() + + args := createMockSyncedTxsSenderArgs() + sender, err := NewSyncedTxsSender(args) + + assert.Nil(t, err) + assert.NotNil(t, sender) + }) +} + +func TestSyncedTxsSender_IsInterfaceNil(t *testing.T) { + t.Parallel() + + var instance *syncedTxsSender + assert.True(t, instance.IsInterfaceNil()) + + instance = &syncedTxsSender{} + assert.False(t, instance.IsInterfaceNil()) +} + +func TestSyncedTxsSender_Close(t *testing.T) { + t.Parallel() + + args := createMockSyncedTxsSenderArgs() + sender, _ := NewSyncedTxsSender(args) + + err := sender.Close() + assert.Nil(t, err) +} + +func TestSyncedTxsSender_SendBulkTransactions(t *testing.T) { + t.Parallel() + + senderAShard0 := []byte("sender A shard 0") + senderBShard1 := []byte("sender B shard 1") + senderCShard0 := []byte("sender C shard 0") + senderDShard1 := []byte("sender D shard 1") + testTransactions := []*transaction.Transaction{ + { + SndAddr: senderAShard0, + }, + { + SndAddr: senderBShard1, + }, + { + SndAddr: senderCShard0, + }, + { + SndAddr: senderDShard1, + }, + } + marshaller := &marshallerMock.MarshalizerMock{} + + marshalledTxs := make([][]byte, 0, len(testTransactions)) + for _, tx := range testTransactions { + buff, _ := marshaller.Marshal(tx) + marshalledTxs = append(marshalledTxs, buff) + } + + mockShardCoordinator := &processMock.ShardCoordinatorStub{ + ComputeIdCalled: func(address []byte) uint32 { + addrString := string(address) + if strings.Contains(addrString, "shard 0") { + return 0 + } + if strings.Contains(addrString, "shard 1") { + return 1 + } + + return core.MetachainShardId + }, + SelfIdCalled: func() uint32 { + return 1 + }, + CommunicationIdentifierCalled: func(destShardID uint32) string { + if destShardID == 1 { + return "_1" + } + if destShardID < 1 { + return fmt.Sprintf("_%d_1", destShardID) + } + + return fmt.Sprintf("_1_%d", destShardID) + }, + } + sentData := make(map[string][][]byte) + netMessenger := &p2pmocks.MessengerStub{ + BroadcastCalled: func(topic string, buff []byte) { + sentData[topic] = append(sentData[topic], buff) + }, + } + mockDataPacker := &mock.DataPackerStub{ + PackDataInChunksCalled: func(data [][]byte, limit int) ([][]byte, error) { + return data, nil + }, + } + + t.Run("no transactions provided should error", func(t *testing.T) { + t.Parallel() + + args := createMockSyncedTxsSenderArgs() + sender, _ := NewSyncedTxsSender(args) + + num, err := sender.SendBulkTransactions(nil) + assert.Equal(t, process.ErrNoTxToProcess, err) + assert.Zero(t, num) + }) + t.Run("should work", func(t *testing.T) { + t.Parallel() + + args := ArgsSyncedTxsSender{ + Marshaller: marshaller, + ShardCoordinator: mockShardCoordinator, + NetworkMessenger: netMessenger, + DataPacker: mockDataPacker, + } + sender, _ := NewSyncedTxsSender(args) + + num, err := sender.SendBulkTransactions(testTransactions) + assert.Nil(t, err) + assert.Equal(t, uint64(4), num) + + expectedSentSliceForShard0 := make([][]byte, 0) + expectedSentSliceForShard0 = append(expectedSentSliceForShard0, marshalledTxs[0]) + expectedSentSliceForShard0 = append(expectedSentSliceForShard0, marshalledTxs[2]) + + expectedSentSliceForShard1 := make([][]byte, 0) + expectedSentSliceForShard1 = append(expectedSentSliceForShard1, marshalledTxs[1]) + expectedSentSliceForShard1 = append(expectedSentSliceForShard1, marshalledTxs[3]) + + expectedSentMap := map[string][][]byte{ + "transactions_1": expectedSentSliceForShard1, + "transactions_0_1": expectedSentSliceForShard0, + } + + assert.Equal(t, expectedSentMap, sentData) + + }) +} From c62f302eafbc9d6670865e791e78a6baad42bf0d Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 20 May 2024 16:39:50 +0300 Subject: [PATCH 249/503] fix test after merge --- .../staking/stake/stakeAndUnStake_test.go | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index 310d10be1b9..f9a12a53036 100644 --- a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go @@ -2475,18 +2475,20 @@ func TestChainSimulator_EdgeCaseLowWaitingList(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 4, - MetaChainMinNodes: 4, - NumNodesWaitingListMeta: 2, - NumNodesWaitingListShard: 2, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 4, + MetaChainMinNodes: 4, + NumNodesWaitingListMeta: 2, + NumNodesWaitingListShard: 2, + MetaChainConsensusGroupSize: 1, + ConsensusGroupSize: 1, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = stakingV4Step1Epoch cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = stakingV4Step2Epoch From cb1baf02c8847b347dc67a002bdd41f1ddaa0206 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 20 May 2024 16:47:02 +0300 Subject: [PATCH 250/503] - renaming --- node/chainSimulator/chainSimulator_test.go | 4 ++-- node/chainSimulator/components/testOnlyProcessingNode.go | 2 +- node/chainSimulator/components/testOnlyProcessingNode_test.go | 2 +- node/chainSimulator/dtos/state.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index 1929944d510..f57a4aefeca 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -245,7 +245,7 @@ func TestChainSimulator_SetEntireState(t *testing.T) { CodeMetadata: "BQY=", Owner: "erd1ss6u80ruas2phpmr82r42xnkd6rxy40g9jl69frppl4qez9w2jpsqj8x97", DeveloperRewards: "5401004999998", - Keys: map[string]string{ + Pairs: map[string]string{ "73756d": "0a", }, } @@ -328,7 +328,7 @@ func TestChainSimulator_SetEntireStateWithRemoval(t *testing.T) { CodeMetadata: "BQY=", Owner: "erd1ss6u80ruas2phpmr82r42xnkd6rxy40g9jl69frppl4qez9w2jpsqj8x97", DeveloperRewards: "5401004999998", - Keys: map[string]string{ + Pairs: map[string]string{ "73756d": "0a", }, } diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index 0dbe4430b5c..b9e3803f09d 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -468,7 +468,7 @@ func (node *testOnlyProcessingNode) SetStateForAddress(address []byte, addressSt return err } - err = setKeyValueMap(userAccount, addressState.Keys) + err = setKeyValueMap(userAccount, addressState.Pairs) if err != nil { return err } diff --git a/node/chainSimulator/components/testOnlyProcessingNode_test.go b/node/chainSimulator/components/testOnlyProcessingNode_test.go index b82864cd6ac..c363ca8019c 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode_test.go +++ b/node/chainSimulator/components/testOnlyProcessingNode_test.go @@ -271,7 +271,7 @@ func TestTestOnlyProcessingNode_SetStateForAddress(t *testing.T) { Address: "erd1qtc600lryvytxuy4h7vn7xmsy5tw6vuw3tskr75cwnmv4mnyjgsq6e5zgj", Nonce: &nonce, Balance: "1000000000000000000", - Keys: map[string]string{ + Pairs: map[string]string{ "01": "02", }, } diff --git a/node/chainSimulator/dtos/state.go b/node/chainSimulator/dtos/state.go index a8edb7e212d..cfcf12070bc 100644 --- a/node/chainSimulator/dtos/state.go +++ b/node/chainSimulator/dtos/state.go @@ -11,5 +11,5 @@ type AddressState struct { CodeHash string `json:"codeHash,omitempty"` DeveloperRewards string `json:"developerReward,omitempty"` Owner string `json:"ownerAddress,omitempty"` - Keys map[string]string `json:"keys,omitempty"` + Pairs map[string]string `json:"pairs,omitempty"` } From e105bd9b5396a81269429c2734f4b5064cf29519 Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Mon, 20 May 2024 17:39:16 +0300 Subject: [PATCH 251/503] Link keys between headers, miniblocks and transactions for processed results. --- .../intermediateTransactionHandlerMock.go | 6 +- process/block/postprocess/basePostProcess.go | 76 ++++++++++++++++--- .../block/postprocess/intermediateResults.go | 2 +- .../postprocess/intermediateResults_test.go | 17 +++-- .../block/postprocess/oneMBPostProcessor.go | 2 +- .../postprocess/oneMBPostProcessor_test.go | 11 ++- process/block/preprocess/basePreProcess.go | 5 +- .../block/preprocess/basePreProcess_test.go | 10 ++- .../block/preprocess/rewardTxPreProcessor.go | 8 +- .../block/preprocess/smartContractResults.go | 8 +- process/block/preprocess/transactions.go | 16 +++- process/coordinator/process.go | 15 ++-- process/coordinator/process_test.go | 14 ++-- process/interface.go | 4 +- process/mock/intermProcessorStub.go | 6 +- .../intermediateTransactionHandlerMock.go | 6 +- .../preProcessorExecutionInfoHandlerMock.go | 6 +- 17 files changed, 151 insertions(+), 61 deletions(-) diff --git a/integrationTests/mock/intermediateTransactionHandlerMock.go b/integrationTests/mock/intermediateTransactionHandlerMock.go index df0e5d147d6..f86d69ff63e 100644 --- a/integrationTests/mock/intermediateTransactionHandlerMock.go +++ b/integrationTests/mock/intermediateTransactionHandlerMock.go @@ -16,7 +16,7 @@ type IntermediateTransactionHandlerMock struct { CreateMarshalledDataCalled func(txHashes [][]byte) ([][]byte, error) GetAllCurrentFinishedTxsCalled func() map[string]data.TransactionHandler RemoveProcessedResultsCalled func(key []byte) [][]byte - InitProcessedResultsCalled func(key []byte) + InitProcessedResultsCalled func(key []byte, parentKey []byte) intermediateTransactions []data.TransactionHandler } @@ -29,9 +29,9 @@ func (ith *IntermediateTransactionHandlerMock) RemoveProcessedResults(key []byte } // InitProcessedResults - -func (ith *IntermediateTransactionHandlerMock) InitProcessedResults(key []byte) { +func (ith *IntermediateTransactionHandlerMock) InitProcessedResults(key []byte, parentKey []byte) { if ith.InitProcessedResultsCalled != nil { - ith.InitProcessedResultsCalled(key) + ith.InitProcessedResultsCalled(key, parentKey) } } diff --git a/process/block/postprocess/basePostProcess.go b/process/block/postprocess/basePostProcess.go index d7918bb34b8..f15315fc9d1 100644 --- a/process/block/postprocess/basePostProcess.go +++ b/process/block/postprocess/basePostProcess.go @@ -29,6 +29,14 @@ type txInfo struct { *txShardInfo } +type processedResult struct { + parent []byte + children map[string]struct{} + results [][]byte +} + +const defaultCapacity = 100 + var log = logger.GetOrCreate("process/block/postprocess") type basePostProcessor struct { @@ -40,7 +48,7 @@ type basePostProcessor struct { mutInterResultsForBlock sync.Mutex interResultsForBlock map[string]*txInfo - mapProcessedResult map[string][][]byte + mapProcessedResult map[string]*processedResult intraShardMiniBlock *block.MiniBlock economicsFee process.FeeHandler index uint32 @@ -79,7 +87,7 @@ func (bpp *basePostProcessor) CreateBlockStarted() { bpp.mutInterResultsForBlock.Lock() bpp.interResultsForBlock = make(map[string]*txInfo) bpp.intraShardMiniBlock = nil - bpp.mapProcessedResult = make(map[string][][]byte) + bpp.mapProcessedResult = make(map[string]*processedResult) bpp.index = 0 bpp.mutInterResultsForBlock.Unlock() } @@ -171,24 +179,72 @@ func (bpp *basePostProcessor) RemoveProcessedResults(key []byte) [][]byte { bpp.mutInterResultsForBlock.Lock() defer bpp.mutInterResultsForBlock.Unlock() - txHashes, ok := bpp.mapProcessedResult[string(key)] + removedProcessedResults, ok := bpp.removeProcessedResultsAndLinks(string(key)) if !ok { return nil } - for _, txHash := range txHashes { - delete(bpp.interResultsForBlock, string(txHash)) + for _, result := range removedProcessedResults { + delete(bpp.interResultsForBlock, string(result)) } - return txHashes + return removedProcessedResults +} + +func (bpp *basePostProcessor) removeProcessedResultsAndLinks(key string) ([][]byte, bool) { + processedResults, ok := bpp.mapProcessedResult[key] + if !ok { + return nil, ok + } + delete(bpp.mapProcessedResult, key) + + collectedProcessedResultsKeys := make([][]byte, 0, defaultCapacity) + collectedProcessedResultsKeys = append(collectedProcessedResultsKeys, processedResults.results...) + + // go through the children and do the same + for childKey := range processedResults.children { + childProcessedResults, ok := bpp.removeProcessedResultsAndLinks(childKey) + if !ok { + continue + } + + collectedProcessedResultsKeys = append(collectedProcessedResultsKeys, childProcessedResults...) + } + + // remove link from parent + parent, ok := bpp.mapProcessedResult[string(processedResults.parent)] + if ok { + delete(parent.children, key) + } + + return collectedProcessedResultsKeys, true } // InitProcessedResults will initialize the processed results -func (bpp *basePostProcessor) InitProcessedResults(key []byte) { +func (bpp *basePostProcessor) InitProcessedResults(key []byte, parentKey []byte) { bpp.mutInterResultsForBlock.Lock() defer bpp.mutInterResultsForBlock.Unlock() - bpp.mapProcessedResult[string(key)] = make([][]byte, 0) + pr := &processedResult{ + parent: parentKey, + children: make(map[string]struct{}), + results: make([][]byte, 0), + } + + bpp.mapProcessedResult[string(key)] = pr + + if parentKey != nil { + parentPr, ok := bpp.mapProcessedResult[string(parentKey)] + if !ok { + bpp.mapProcessedResult[string(parentKey)] = &processedResult{ + parent: nil, + children: map[string]struct{}{string(key): {}}, + results: make([][]byte, 0), + } + } else { + parentPr.children[string(key)] = struct{}{} + } + } } func (bpp *basePostProcessor) splitMiniBlocksIfNeeded(miniBlocks []*block.MiniBlock) []*block.MiniBlock { @@ -283,10 +339,10 @@ func (bpp *basePostProcessor) addIntermediateTxToResultsForBlock( bpp.index++ bpp.interResultsForBlock[string(txHash)] = scrInfo - value, ok := bpp.mapProcessedResult[string(key)] + pr, ok := bpp.mapProcessedResult[string(key)] if !ok { return } - bpp.mapProcessedResult[string(key)] = append(value, txHash) + pr.results = append(pr.results, txHash) } diff --git a/process/block/postprocess/intermediateResults.go b/process/block/postprocess/intermediateResults.go index 77f90fc1033..d706e83623e 100644 --- a/process/block/postprocess/intermediateResults.go +++ b/process/block/postprocess/intermediateResults.go @@ -90,7 +90,7 @@ func NewIntermediateResultsProcessor( shardCoordinator: args.Coordinator, store: args.Store, storageType: dataRetriever.UnsignedTransactionUnit, - mapProcessedResult: make(map[string][][]byte), + mapProcessedResult: make(map[string]*processedResult), economicsFee: args.EconomicsFee, } diff --git a/process/block/postprocess/intermediateResults_test.go b/process/block/postprocess/intermediateResults_test.go index b2197451ca6..9ef1f6d0358 100644 --- a/process/block/postprocess/intermediateResults_test.go +++ b/process/block/postprocess/intermediateResults_test.go @@ -395,25 +395,26 @@ func TestIntermediateResultsProcessor_AddIntermediateTransactionsAddAndRevert(t txs = append(txs, &smartContractResult.SmartContractResult{RcvAddr: []byte("rcv"), SndAddr: []byte("snd"), Value: big.NewInt(0), PrevTxHash: txHash, Nonce: 3}) txs = append(txs, &smartContractResult.SmartContractResult{RcvAddr: []byte("rcv"), SndAddr: []byte("snd"), Value: big.NewInt(0), PrevTxHash: txHash, Nonce: 4}) + parentKey := []byte("parentKey") key := []byte("key") - irp.InitProcessedResults(key) + irp.InitProcessedResults(key, parentKey) err = irp.AddIntermediateTransactions(txs, key) assert.Nil(t, err) irp.mutInterResultsForBlock.Lock() - assert.Equal(t, len(irp.mapProcessedResult[string(key)]), len(txs)) + assert.Equal(t, len(irp.mapProcessedResult[string(key)].results), len(txs)) assert.Equal(t, len(txs), calledCount) irp.mutInterResultsForBlock.Unlock() irp.RemoveProcessedResults(key) irp.mutInterResultsForBlock.Lock() assert.Equal(t, len(irp.interResultsForBlock), 0) - assert.Equal(t, len(irp.mapProcessedResult[string(key)]), len(txs)) + require.Nil(t, irp.mapProcessedResult[string(key)]) irp.mutInterResultsForBlock.Unlock() - irp.InitProcessedResults(key) + irp.InitProcessedResults(key, parentKey) irp.mutInterResultsForBlock.Lock() - assert.Equal(t, len(irp.mapProcessedResult[string(key)]), 0) + assert.Equal(t, len(irp.mapProcessedResult[string(key)].results), 0) irp.mutInterResultsForBlock.Unlock() } @@ -959,7 +960,7 @@ func TestIntermediateResultsProcessor_addIntermediateTxToResultsForBlock(t *test irp, _ := NewIntermediateResultsProcessor(createMockArgsNewIntermediateResultsProcessor()) key := []byte("key") - irp.InitProcessedResults(key) + irp.InitProcessedResults(key, nil) tx := &transaction.Transaction{} txHash := []byte("txHash") @@ -978,6 +979,6 @@ func TestIntermediateResultsProcessor_addIntermediateTxToResultsForBlock(t *test intermediateResultsHashes, ok := irp.mapProcessedResult[string(key)] require.True(t, ok) - require.Equal(t, 1, len(intermediateResultsHashes)) - assert.Equal(t, txHash, intermediateResultsHashes[0]) + require.Equal(t, 1, len(intermediateResultsHashes.results)) + assert.Equal(t, txHash, intermediateResultsHashes.results[0]) } diff --git a/process/block/postprocess/oneMBPostProcessor.go b/process/block/postprocess/oneMBPostProcessor.go index 18668992a73..6a87e32d6f4 100644 --- a/process/block/postprocess/oneMBPostProcessor.go +++ b/process/block/postprocess/oneMBPostProcessor.go @@ -55,7 +55,7 @@ func NewOneMiniBlockPostProcessor( shardCoordinator: coordinator, store: store, storageType: storageType, - mapProcessedResult: make(map[string][][]byte), + mapProcessedResult: make(map[string]*processedResult), economicsFee: economicsFee, } diff --git a/process/block/postprocess/oneMBPostProcessor_test.go b/process/block/postprocess/oneMBPostProcessor_test.go index 5151fdc5f88..236f457198e 100644 --- a/process/block/postprocess/oneMBPostProcessor_test.go +++ b/process/block/postprocess/oneMBPostProcessor_test.go @@ -9,13 +9,14 @@ import ( "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/stretchr/testify/assert" + "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/mock" "github.com/multiversx/mx-chain-go/testscommon/economicsmocks" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/storage" - "github.com/stretchr/testify/assert" ) func TestNewOneMBPostProcessor_NilHasher(t *testing.T) { @@ -154,7 +155,9 @@ func TestOneMBPostProcessor_CreateAllInterMiniBlocksOneMinBlock(t *testing.T) { txs = append(txs, &transaction.Transaction{}) txs = append(txs, &transaction.Transaction{}) - err := irp.AddIntermediateTransactions(txs) + // with no InitProcessedResults, means that the transactions are added as scheduled transactions, not as + // processing results from the execution of other transactions or miniblocks + err := irp.AddIntermediateTransactions(txs, nil) assert.Nil(t, err) mbs := irp.CreateAllInterMiniBlocks() @@ -198,7 +201,7 @@ func TestOneMBPostProcessor_VerifyTooManyBlock(t *testing.T) { txs = append(txs, &transaction.Transaction{SndAddr: []byte("snd"), RcvAddr: []byte("recvaddr4")}) txs = append(txs, &transaction.Transaction{SndAddr: []byte("snd"), RcvAddr: []byte("recvaddr5")}) - err := irp.AddIntermediateTransactions(txs) + err := irp.AddIntermediateTransactions(txs, nil) assert.Nil(t, err) miniBlock := &block.MiniBlock{ @@ -267,7 +270,7 @@ func TestOneMBPostProcessor_VerifyOk(t *testing.T) { txs = append(txs, &transaction.Transaction{SndAddr: []byte("snd"), RcvAddr: []byte("recvaddr4")}) txs = append(txs, &transaction.Transaction{SndAddr: []byte("snd"), RcvAddr: []byte("recvaddr5")}) - err := irp.AddIntermediateTransactions(txs) + err := irp.AddIntermediateTransactions(txs, nil) assert.Nil(t, err) miniBlock := &block.MiniBlock{ diff --git a/process/block/preprocess/basePreProcess.go b/process/block/preprocess/basePreProcess.go index 58534fe4395..56ea615559e 100644 --- a/process/block/preprocess/basePreProcess.go +++ b/process/block/preprocess/basePreProcess.go @@ -12,6 +12,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/process" @@ -497,9 +498,9 @@ func (bpp *basePreProcess) updateGasConsumedWithGasRefundedAndGasPenalized( gasInfo.totalGasConsumedInSelfShard -= gasToBeSubtracted } -func (bpp *basePreProcess) handleProcessTransactionInit(preProcessorExecutionInfoHandler process.PreProcessorExecutionInfoHandler, txHash []byte) int { +func (bpp *basePreProcess) handleProcessTransactionInit(preProcessorExecutionInfoHandler process.PreProcessorExecutionInfoHandler, txHash []byte, mbHash []byte) int { snapshot := bpp.accounts.JournalLen() - preProcessorExecutionInfoHandler.InitProcessedTxsResults(txHash) + preProcessorExecutionInfoHandler.InitProcessedTxsResults(txHash, mbHash) return snapshot } diff --git a/process/block/preprocess/basePreProcess_test.go b/process/block/preprocess/basePreProcess_test.go index fc17684ca08..221f69c28db 100644 --- a/process/block/preprocess/basePreProcess_test.go +++ b/process/block/preprocess/basePreProcess_test.go @@ -4,22 +4,26 @@ import ( "bytes" "testing" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/state" - "github.com/stretchr/testify/assert" ) func TestBasePreProcess_handleProcessTransactionInit(t *testing.T) { t.Parallel() + mbHash := []byte("mb hash") txHash := []byte("tx hash") initProcessedTxsCalled := false preProcessorExecutionInfoHandler := &testscommon.PreProcessorExecutionInfoHandlerMock{ - InitProcessedTxsResultsCalled: func(key []byte) { + InitProcessedTxsResultsCalled: func(key []byte, parentKey []byte) { if !bytes.Equal(key, txHash) { return } + require.Equal(t, mbHash, parentKey) initProcessedTxsCalled = true }, @@ -41,7 +45,7 @@ func TestBasePreProcess_handleProcessTransactionInit(t *testing.T) { }, } - recoveredJournalLen := bp.handleProcessTransactionInit(preProcessorExecutionInfoHandler, txHash) + recoveredJournalLen := bp.handleProcessTransactionInit(preProcessorExecutionInfoHandler, txHash, mbHash) assert.Equal(t, journalLen, recoveredJournalLen) assert.True(t, initProcessedTxsCalled) } diff --git a/process/block/preprocess/rewardTxPreProcessor.go b/process/block/preprocess/rewardTxPreProcessor.go index d80d8ffbb4c..e695d51e498 100644 --- a/process/block/preprocess/rewardTxPreProcessor.go +++ b/process/block/preprocess/rewardTxPreProcessor.go @@ -10,6 +10,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data/rewardTx" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/process" @@ -494,6 +495,11 @@ func (rtp *rewardTxPreprocessor) ProcessMiniBlock( return nil, indexOfLastTxProcessed, false, process.ErrMaxBlockSizeReached } + miniBlockHash, err := core.CalculateHash(rtp.marshalizer, rtp.hasher, miniBlock) + if err != nil { + return nil, indexOfLastTxProcessed, false, err + } + processedTxHashes := make([][]byte, 0) for txIndex = indexOfFirstTxToBeProcessed; txIndex < len(miniBlockRewardTxs); txIndex++ { if !haveTime() { @@ -506,7 +512,7 @@ func (rtp *rewardTxPreprocessor) ProcessMiniBlock( break } - snapshot := rtp.handleProcessTransactionInit(preProcessorExecutionInfoHandler, miniBlockTxHashes[txIndex]) + snapshot := rtp.handleProcessTransactionInit(preProcessorExecutionInfoHandler, miniBlockTxHashes[txIndex], miniBlockHash) rtp.txExecutionOrderHandler.Add(miniBlockTxHashes[txIndex]) err = rtp.rewardsProcessor.ProcessRewardTransaction(miniBlockRewardTxs[txIndex]) diff --git a/process/block/preprocess/smartContractResults.go b/process/block/preprocess/smartContractResults.go index 471c94360bd..3ac910a1834 100644 --- a/process/block/preprocess/smartContractResults.go +++ b/process/block/preprocess/smartContractResults.go @@ -11,6 +11,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data/smartContractResult" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/process" @@ -571,6 +572,11 @@ func (scr *smartContractResults) ProcessMiniBlock( return nil, indexOfLastTxProcessed, false, process.ErrMaxBlockSizeReached } + miniBlockHash, err := core.CalculateHash(scr.marshalizer, scr.hasher, miniBlock) + if err != nil { + return nil, indexOfLastTxProcessed, false, err + } + gasInfo := gasConsumedInfo{ gasConsumedByMiniBlockInReceiverShard: uint64(0), gasConsumedByMiniBlocksInSenderShard: uint64(0), @@ -633,7 +639,7 @@ func (scr *smartContractResults) ProcessMiniBlock( break } - snapshot := scr.handleProcessTransactionInit(preProcessorExecutionInfoHandler, miniBlockTxHashes[txIndex]) + snapshot := scr.handleProcessTransactionInit(preProcessorExecutionInfoHandler, miniBlockTxHashes[txIndex], miniBlockHash) scr.txExecutionOrderHandler.Add(miniBlockTxHashes[txIndex]) _, err = scr.scrProcessor.ProcessSmartContractResult(miniBlockScrs[txIndex]) diff --git a/process/block/preprocess/transactions.go b/process/block/preprocess/transactions.go index fd53f95aad5..eb24585a55b 100644 --- a/process/block/preprocess/transactions.go +++ b/process/block/preprocess/transactions.go @@ -15,6 +15,9 @@ import ( "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + logger "github.com/multiversx/mx-chain-logger-go" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/process" @@ -23,8 +26,6 @@ import ( "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/storage/txcache" - logger "github.com/multiversx/mx-chain-logger-go" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) var _ process.DataMarshalizer = (*transactions)(nil) @@ -1508,6 +1509,11 @@ func (txs *transactions) ProcessMiniBlock( return nil, indexOfLastTxProcessed, false, process.ErrMaxBlockSizeReached } + miniBlockHash, err := core.CalculateHash(txs.marshalizer, txs.hasher, miniBlock) + if err != nil { + return nil, indexOfLastTxProcessed, false, err + } + var totalGasConsumed uint64 if scheduledMode { totalGasConsumed = txs.gasHandler.TotalGasProvidedAsScheduled() @@ -1587,7 +1593,8 @@ func (txs *transactions) ProcessMiniBlock( miniBlockTxs[txIndex], miniBlockTxHashes[txIndex], &gasInfo, - gasProvidedByTxInSelfShard) + gasProvidedByTxInSelfShard, + miniBlockHash) if err != nil { break } @@ -1646,9 +1653,10 @@ func (txs *transactions) processInNormalMode( txHash []byte, gasInfo *gasConsumedInfo, gasProvidedByTxInSelfShard uint64, + mbHash []byte, ) error { - snapshot := txs.handleProcessTransactionInit(preProcessorExecutionInfoHandler, txHash) + snapshot := txs.handleProcessTransactionInit(preProcessorExecutionInfoHandler, txHash, mbHash) txs.txExecutionOrderHandler.Add(txHash) _, err := txs.txProcessor.ProcessTransaction(tx) diff --git a/process/coordinator/process.go b/process/coordinator/process.go index e8a698f6ac7..8a50d9f0b21 100644 --- a/process/coordinator/process.go +++ b/process/coordinator/process.go @@ -704,7 +704,7 @@ func (tc *transactionCoordinator) CreateMbsAndProcessCrossShardTransactionsDstMe oldIndexOfLastTxProcessed := processedMbInfo.IndexOfLastTxProcessed - errProc := tc.processCompleteMiniBlock(preproc, miniBlock, miniBlockInfo.Hash, haveTime, haveAdditionalTime, scheduledMode, processedMbInfo) + errProc := tc.processCompleteMiniBlock(preproc, miniBlock, miniBlockInfo.Hash, haveTime, haveAdditionalTime, scheduledMode, processedMbInfo, headerHash) tc.handleProcessMiniBlockExecution(oldIndexOfLastTxProcessed, miniBlock, processedMbInfo, createMBDestMeExecutionInfo) if errProc != nil { shouldSkipShard[miniBlockInfo.SenderShardID] = true @@ -811,7 +811,7 @@ func (tc *transactionCoordinator) handleCreateMiniBlocksDestMeInit(headerHash [] return } - tc.InitProcessedTxsResults(headerHash) + tc.InitProcessedTxsResults(headerHash, nil) tc.gasHandler.Reset(headerHash) } @@ -1191,9 +1191,10 @@ func (tc *transactionCoordinator) processCompleteMiniBlock( haveAdditionalTime func() bool, scheduledMode bool, processedMbInfo *processedMb.ProcessedMiniBlockInfo, + headerHash []byte, ) error { - snapshot := tc.handleProcessMiniBlockInit(miniBlockHash) + snapshot := tc.handleProcessMiniBlockInit(miniBlockHash, headerHash) log.Debug("transactionsCoordinator.processCompleteMiniBlock: before processing", "scheduled mode", scheduledMode, @@ -1260,9 +1261,9 @@ func (tc *transactionCoordinator) processCompleteMiniBlock( return nil } -func (tc *transactionCoordinator) handleProcessMiniBlockInit(miniBlockHash []byte) int { +func (tc *transactionCoordinator) handleProcessMiniBlockInit(miniBlockHash []byte, headerHash []byte) int { snapshot := tc.accounts.JournalLen() - tc.InitProcessedTxsResults(miniBlockHash) + tc.InitProcessedTxsResults(miniBlockHash, headerHash) tc.gasHandler.Reset(miniBlockHash) return snapshot @@ -1283,7 +1284,7 @@ func (tc *transactionCoordinator) handleProcessTransactionError(snapshot int, mi } // InitProcessedTxsResults inits processed txs results for the given key -func (tc *transactionCoordinator) InitProcessedTxsResults(key []byte) { +func (tc *transactionCoordinator) InitProcessedTxsResults(key []byte, parentKey []byte) { tc.mutInterimProcessors.RLock() defer tc.mutInterimProcessors.RUnlock() @@ -1292,7 +1293,7 @@ func (tc *transactionCoordinator) InitProcessedTxsResults(key []byte) { if !ok { continue } - interProc.InitProcessedResults(key) + interProc.InitProcessedResults(key, parentKey) } } diff --git a/process/coordinator/process_test.go b/process/coordinator/process_test.go index d7045411ed7..d1dff667cb7 100644 --- a/process/coordinator/process_test.go +++ b/process/coordinator/process_test.go @@ -1021,6 +1021,7 @@ func TestTransactionCoordinator_CreateMbsAndProcessCrossShardTransactionsWithSki } func TestTransactionCoordinator_HandleProcessMiniBlockInit(t *testing.T) { + headerHash := []byte("header hash") mbHash := []byte("miniblock hash") numResetGasHandler := 0 numInitInterimProc := 0 @@ -1036,7 +1037,8 @@ func TestTransactionCoordinator_HandleProcessMiniBlockInit(t *testing.T) { keysInterimProcs: []block.Type{block.SmartContractResultBlock}, interimProcessors: map[block.Type]process.IntermediateTransactionHandler{ block.SmartContractResultBlock: &mock.IntermediateTransactionHandlerStub{ - InitProcessedResultsCalled: func(key []byte) { + InitProcessedResultsCalled: func(key []byte, parentKey []byte) { + assert.Equal(t, headerHash, parentKey) assert.Equal(t, mbHash, key) numInitInterimProc++ }, @@ -1050,7 +1052,7 @@ func TestTransactionCoordinator_HandleProcessMiniBlockInit(t *testing.T) { numInitInterimProc = 0 shardCoord.CurrentShard = 0 - tc.handleProcessMiniBlockInit(mbHash) + tc.handleProcessMiniBlockInit(mbHash, headerHash) assert.Equal(t, 1, numResetGasHandler) assert.Equal(t, 1, numInitInterimProc) }) @@ -1059,7 +1061,7 @@ func TestTransactionCoordinator_HandleProcessMiniBlockInit(t *testing.T) { numInitInterimProc = 0 shardCoord.CurrentShard = core.MetachainShardId - tc.handleProcessMiniBlockInit(mbHash) + tc.handleProcessMiniBlockInit(mbHash, headerHash) assert.Equal(t, 1, numResetGasHandler) assert.Equal(t, 1, numInitInterimProc) }) @@ -1927,6 +1929,7 @@ func TestShardProcessor_ProcessMiniBlockCompleteWithOkTxsShouldExecuteThemAndNot // all txs will be in datapool and none of them will return err when processed // so, tx processor will return nil on processing tx + headerHash := []byte("header hash") txHash1 := []byte("tx hash 1") txHash2 := []byte("tx hash 2") txHash3 := []byte("tx hash 3") @@ -2055,7 +2058,7 @@ func TestShardProcessor_ProcessMiniBlockCompleteWithOkTxsShouldExecuteThemAndNot IndexOfLastTxProcessed: -1, FullyProcessed: false, } - err = tc.processCompleteMiniBlock(preproc, &miniBlock, []byte("hash"), haveTime, haveAdditionalTime, false, processedMbInfo) + err = tc.processCompleteMiniBlock(preproc, &miniBlock, []byte("hash"), haveTime, haveAdditionalTime, false, processedMbInfo, headerHash) assert.Nil(t, err) assert.Equal(t, tx1Nonce, tx1ExecutionResult) @@ -2087,6 +2090,7 @@ func TestShardProcessor_ProcessMiniBlockCompleteWithErrorWhileProcessShouldCallR TxHashes: [][]byte{txHash1, txHash2, txHash3}, } + headerHash := []byte("header hash") tx1Nonce := uint64(45) tx2Nonce := uint64(46) tx3Nonce := uint64(47) @@ -2200,7 +2204,7 @@ func TestShardProcessor_ProcessMiniBlockCompleteWithErrorWhileProcessShouldCallR IndexOfLastTxProcessed: -1, FullyProcessed: false, } - err = tc.processCompleteMiniBlock(preproc, &miniBlock, []byte("hash"), haveTime, haveAdditionalTime, false, processedMbInfo) + err = tc.processCompleteMiniBlock(preproc, &miniBlock, []byte("hash"), haveTime, haveAdditionalTime, false, processedMbInfo, headerHash) assert.Equal(t, process.ErrHigherNonceInTransaction, err) assert.True(t, revertAccntStateCalled) diff --git a/process/interface.go b/process/interface.go index 5ae735f4027..747103f26ca 100644 --- a/process/interface.go +++ b/process/interface.go @@ -200,7 +200,7 @@ type IntermediateTransactionHandler interface { CreateBlockStarted() GetCreatedInShardMiniBlock() *block.MiniBlock RemoveProcessedResults(key []byte) [][]byte - InitProcessedResults(key []byte) + InitProcessedResults(key []byte, parentKey []byte) IsInterfaceNil() bool } @@ -1320,7 +1320,7 @@ type TxsSenderHandler interface { // PreProcessorExecutionInfoHandler handles pre processor execution info needed by the transactions preprocessors type PreProcessorExecutionInfoHandler interface { GetNumOfCrossInterMbsAndTxs() (int, int) - InitProcessedTxsResults(key []byte) + InitProcessedTxsResults(key []byte, parentKey []byte) RevertProcessedTxsResults(txHashes [][]byte, key []byte) } diff --git a/process/mock/intermProcessorStub.go b/process/mock/intermProcessorStub.go index aa405a69799..dde08776bd4 100644 --- a/process/mock/intermProcessorStub.go +++ b/process/mock/intermProcessorStub.go @@ -16,7 +16,7 @@ type IntermediateTransactionHandlerStub struct { CreateMarshalledDataCalled func(txHashes [][]byte) ([][]byte, error) GetAllCurrentFinishedTxsCalled func() map[string]data.TransactionHandler RemoveProcessedResultsCalled func(key []byte) [][]byte - InitProcessedResultsCalled func(key []byte) + InitProcessedResultsCalled func(key []byte, parentKey []byte) intermediateTransactions []data.TransactionHandler } @@ -29,9 +29,9 @@ func (ith *IntermediateTransactionHandlerStub) RemoveProcessedResults(key []byte } // InitProcessedResults - -func (ith *IntermediateTransactionHandlerStub) InitProcessedResults(key []byte) { +func (ith *IntermediateTransactionHandlerStub) InitProcessedResults(key []byte, parentKey []byte) { if ith.InitProcessedResultsCalled != nil { - ith.InitProcessedResultsCalled(key) + ith.InitProcessedResultsCalled(key, parentKey) } } diff --git a/process/mock/intermediateTransactionHandlerMock.go b/process/mock/intermediateTransactionHandlerMock.go index 4a68fb3d2f4..7bd71c3475c 100644 --- a/process/mock/intermediateTransactionHandlerMock.go +++ b/process/mock/intermediateTransactionHandlerMock.go @@ -16,7 +16,7 @@ type IntermediateTransactionHandlerMock struct { CreateMarshalledDataCalled func(txHashes [][]byte) ([][]byte, error) GetAllCurrentFinishedTxsCalled func() map[string]data.TransactionHandler RemoveProcessedResultsCalled func(key []byte) [][]byte - InitProcessedResultsCalled func(key []byte) + InitProcessedResultsCalled func(key []byte, parentKey []byte) GetCreatedInShardMiniBlockCalled func() *block.MiniBlock intermediateTransactions []data.TransactionHandler } @@ -30,9 +30,9 @@ func (ith *IntermediateTransactionHandlerMock) RemoveProcessedResults(key []byte } // InitProcessedResults - -func (ith *IntermediateTransactionHandlerMock) InitProcessedResults(key []byte) { +func (ith *IntermediateTransactionHandlerMock) InitProcessedResults(key []byte, parentKey []byte) { if ith.InitProcessedResultsCalled != nil { - ith.InitProcessedResultsCalled(key) + ith.InitProcessedResultsCalled(key, parentKey) } } diff --git a/testscommon/preProcessorExecutionInfoHandlerMock.go b/testscommon/preProcessorExecutionInfoHandlerMock.go index 116f58f7d88..0946db0f4ba 100644 --- a/testscommon/preProcessorExecutionInfoHandlerMock.go +++ b/testscommon/preProcessorExecutionInfoHandlerMock.go @@ -3,7 +3,7 @@ package testscommon // PreProcessorExecutionInfoHandlerMock - type PreProcessorExecutionInfoHandlerMock struct { GetNumOfCrossInterMbsAndTxsCalled func() (int, int) - InitProcessedTxsResultsCalled func(key []byte) + InitProcessedTxsResultsCalled func(key []byte, parentKey []byte) RevertProcessedTxsResultsCalled func(txHashes [][]byte, key []byte) } @@ -16,9 +16,9 @@ func (ppeihm *PreProcessorExecutionInfoHandlerMock) GetNumOfCrossInterMbsAndTxs( } // InitProcessedTxsResults - -func (ppeihm *PreProcessorExecutionInfoHandlerMock) InitProcessedTxsResults(key []byte) { +func (ppeihm *PreProcessorExecutionInfoHandlerMock) InitProcessedTxsResults(key []byte, parentKey []byte) { if ppeihm.InitProcessedTxsResultsCalled != nil { - ppeihm.InitProcessedTxsResultsCalled(key) + ppeihm.InitProcessedTxsResultsCalled(key, parentKey) } } From 288012b6e12eaff2b040cd1d3432536fbc10a9bf Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Tue, 21 May 2024 14:06:59 +0300 Subject: [PATCH 252/503] add activation flag for unjail cleanup backwards compatibility --- cmd/node/config/enableEpochs.toml | 3 +++ common/constants.go | 1 + common/enablers/enableEpochsHandler.go | 9 ++++++++- config/epochConfig.go | 1 + process/scToProtocol/stakingToPeer.go | 5 ++++- 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index 657d365fdc9..b5ece669247 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -314,6 +314,9 @@ # CryptoOpcodesV2EnableEpoch represents the epoch when BLSMultiSig, Secp256r1 and other opcodes are enabled CryptoOpcodesV2EnableEpoch = 4 + # UnjailCleanupEnableEpoch represents the epoch when the cleanup of the unjailed nodes is enabled + UnJailCleanupEnableEpoch = 4 + # BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers BLSMultiSignerEnableEpoch = [ { EnableEpoch = 0, Type = "no-KOSK" }, diff --git a/common/constants.go b/common/constants.go index 13fedb7e0bd..53f6d461412 100644 --- a/common/constants.go +++ b/common/constants.go @@ -1016,5 +1016,6 @@ const ( DynamicESDTFlag core.EnableEpochFlag = "DynamicEsdtFlag" EGLDInESDTMultiTransferFlag core.EnableEpochFlag = "EGLDInESDTMultiTransferFlag" CryptoOpcodesV2Flag core.EnableEpochFlag = "CryptoOpcodesV2Flag" + UnJailCleanupFlag core.EnableEpochFlag = "UnJailCleanupFlag" // all new flags must be added to createAllFlagsMap method, as part of enableEpochsHandler allFlagsDefined ) diff --git a/common/enablers/enableEpochsHandler.go b/common/enablers/enableEpochsHandler.go index efe8b4f304d..5313fb90972 100644 --- a/common/enablers/enableEpochsHandler.go +++ b/common/enablers/enableEpochsHandler.go @@ -6,10 +6,11 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/process" - logger "github.com/multiversx/mx-chain-logger-go" ) var log = logger.GetOrCreate("common/enablers") @@ -743,6 +744,12 @@ func (handler *enableEpochsHandler) createAllFlagsMap() { }, activationEpoch: handler.enableEpochsConfig.CryptoOpcodesV2EnableEpoch, }, + common.UnJailCleanupFlag: { + isActiveInEpoch: func(epoch uint32) bool { + return epoch >= handler.enableEpochsConfig.UnJailCleanupEnableEpoch + }, + activationEpoch: handler.enableEpochsConfig.UnJailCleanupEnableEpoch, + }, } } diff --git a/config/epochConfig.go b/config/epochConfig.go index 5f5f4ff7a0e..62191f0fe82 100644 --- a/config/epochConfig.go +++ b/config/epochConfig.go @@ -116,6 +116,7 @@ type EnableEpochs struct { DynamicESDTEnableEpoch uint32 EGLDInMultiTransferEnableEpoch uint32 CryptoOpcodesV2EnableEpoch uint32 + UnJailCleanupEnableEpoch uint32 BLSMultiSignerEnableEpoch []MultiSignerConfig } diff --git a/process/scToProtocol/stakingToPeer.go b/process/scToProtocol/stakingToPeer.go index b0a0d973786..363a7975a7a 100644 --- a/process/scToProtocol/stakingToPeer.go +++ b/process/scToProtocol/stakingToPeer.go @@ -110,6 +110,7 @@ func checkIfNil(args ArgStakingToPeer) error { return core.CheckHandlerCompatibility(args.EnableEpochsHandler, []core.EnableEpochFlag{ common.StakeFlag, common.ValidatorToDelegationFlag, + common.UnJailCleanupFlag, }) } @@ -342,7 +343,9 @@ func (stp *stakingToPeer) updatePeerState( if account.GetTempRating() < stp.unJailRating { log.Debug("node is unJailed, setting temp rating to start rating", "blsKey", blsPubKey) account.SetTempRating(stp.unJailRating) - account.SetConsecutiveProposerMisses(0) + if stp.enableEpochsHandler.IsFlagEnabled(common.UnJailCleanupFlag) { + account.SetConsecutiveProposerMisses(0) + } } isNewValidator := !isValidator && stakingData.Staked From b8674cadc6d3bfefcc30a11ec28842044cab4fdd Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Tue, 21 May 2024 16:21:06 +0300 Subject: [PATCH 253/503] add system vm critical section --- vm/process/systemVM.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vm/process/systemVM.go b/vm/process/systemVM.go index 6a3452304fa..90228e4adaa 100644 --- a/vm/process/systemVM.go +++ b/vm/process/systemVM.go @@ -6,9 +6,10 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/vm" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) type systemVM struct { @@ -18,6 +19,7 @@ type systemVM struct { asyncCallbackGasLock uint64 asyncCallStepCost uint64 mutGasLock sync.RWMutex + criticalSection sync.Mutex } // ArgsNewSystemVM defines the needed arguments to create a new system vm @@ -101,6 +103,9 @@ func (s *systemVM) RunSmartContractCreate(input *vmcommon.ContractCreateInput) ( // RunSmartContractCall executes a smart contract according to the input func (s *systemVM) RunSmartContractCall(input *vmcommon.ContractCallInput) (*vmcommon.VMOutput, error) { + s.criticalSection.Lock() + defer s.criticalSection.Unlock() + s.systemEI.CleanCache() s.systemEI.SetSCAddress(input.RecipientAddr) s.systemEI.AddTxValueToSmartContract(input.CallValue, input.RecipientAddr) From 8369e8d613d01c47dbf60f3042db61f0a35bcf4d Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Tue, 21 May 2024 16:28:13 +0300 Subject: [PATCH 254/503] add system vm critical section also on contract create --- vm/process/systemVM.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vm/process/systemVM.go b/vm/process/systemVM.go index 90228e4adaa..ca0553cb714 100644 --- a/vm/process/systemVM.go +++ b/vm/process/systemVM.go @@ -70,6 +70,9 @@ func NewSystemVM(args ArgsNewSystemVM) (*systemVM, error) { // RunSmartContractCreate creates and saves a new smart contract to the trie func (s *systemVM) RunSmartContractCreate(input *vmcommon.ContractCreateInput) (*vmcommon.VMOutput, error) { + s.criticalSection.Lock() + defer s.criticalSection.Unlock() + if input == nil { return nil, vm.ErrInputArgsIsNil } From 8632cc58efe2d269e80f309e5ec2ab2d7a9e152b Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 21 May 2024 17:34:55 +0300 Subject: [PATCH 255/503] added esdt improvements integration test setup --- .../vm/esdtImprovements_test.go | 196 ++++++++++++++++++ 1 file changed, 196 insertions(+) create mode 100644 integrationTests/chainSimulator/vm/esdtImprovements_test.go diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go new file mode 100644 index 00000000000..b79f9833d10 --- /dev/null +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -0,0 +1,196 @@ +package vm + +import ( + "bytes" + "encoding/hex" + "fmt" + "math/big" + "testing" + "time" + + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/esdt" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" + "github.com/multiversx/mx-chain-go/node/chainSimulator" + "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" + "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" + "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" + "github.com/multiversx/mx-chain-go/state" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/stretchr/testify/require" +) + +const ( + defaultPathToInitialConfig = "../../../cmd/node/config/" + + minGasPrice = 1000000000 +) + +var log = logger.GetOrCreate("integrationTests/chainSimulator/vm") + +// Test scenario +// +// Initial setup: Create an NFT and an SFT (before the activation of DynamicEsdtFlag) +// +// 1. check that the metadata for nft and sfts are saved on the system account +// 2. wait for DynamicEsdtFlag activation +// 3. transfer the NFT and the SFT to another account +// 4. check that the metadata for nft is saved to the receiver account +// 5. check that the metadata for the sft is saved on the system account +// 6. repeat 3-5 for both intra and cross shard +func TestChainSimulator_CheckNFTMetadata(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(4) + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + mintValue := big.NewInt(10) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + + address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) + require.Nil(t, err) + + shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) + + // set account esdt roles + tokenID := []byte("ASD-d31313") + + roles := [][]byte{[]byte(core.ESDTMetaDataRecreate), []byte(core.ESDTRoleNFTCreate)} + rolesKey := append([]byte(core.ProtectedKeyPrefix), append([]byte(core.ESDTRoleIdentifier), []byte(core.ESDTKeyIdentifier)...)...) + rolesKey = append(rolesKey, tokenID...) + + rolesData := &esdt.ESDTRoles{ + Roles: roles, + } + + rolesDataBytes, err := cs.GetNodeHandler(shardID).GetCoreComponents().InternalMarshalizer().Marshal(rolesData) + require.Nil(t, err) + + keys := make(map[string]string) + keys[hex.EncodeToString(rolesKey)] = hex.EncodeToString(rolesDataBytes) + + err = cs.SetStateMultiple([]*dtos.AddressState{ + { + Address: address.Bech32, + Balance: "10000000000000000000000", + Keys: keys, + }, + }) + require.Nil(t, err) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch) - 1) + require.Nil(t, err) + + privateKey, _, err := chainSimulator.GenerateBlsPrivateKeys(1) + require.Nil(t, err) + + err = cs.AddValidatorKeys(privateKey) + require.Nil(t, err) + + nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + name := []byte(hex.EncodeToString([]byte("name"))) + hash := []byte(hex.EncodeToString([]byte("hash"))) + attributes := []byte(hex.EncodeToString([]byte("attributes"))) + uris := []byte(hex.EncodeToString([]byte("uri"))) + + txDataField := bytes.Join( + [][]byte{ + []byte(core.BuiltInFunctionESDTNFTCreate), + []byte(hex.EncodeToString(tokenID)), + []byte(hex.EncodeToString(big.NewInt(1).Bytes())), // quantity + name, + []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + hash, + attributes, + uris, + }, + []byte("@"), + ) + + tx := &transaction.Transaction{ + Nonce: 0, + SndAddr: address.Bytes, + RcvAddr: address.Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + account, err := cs.GetNodeHandler(shardID).GetStateComponents().AccountsAdapter().LoadAccount(core.SystemAccountAddress) + require.Nil(t, err) + userAccount, ok := account.(state.UserAccountHandler) + require.True(t, ok) + + baseEsdtKeyPrefix := core.ProtectedKeyPrefix + core.ESDTKeyIdentifier + key := append([]byte(baseEsdtKeyPrefix), tokenID...) + + fmt.Println(userAccount) + + key2 := append(key, big.NewInt(0).SetUint64(1).Bytes()...) + esdtDataBytes, _, err := userAccount.RetrieveValue(key2) + require.Nil(t, err) + esdtData := &esdt.ESDigitalToken{} + + err = cs.GetNodeHandler(shardID).GetCoreComponents().InternalMarshalizer().Unmarshal(esdtData, esdtDataBytes) + require.Nil(t, err) + + require.NotNil(t, esdtData.TokenMetaData) + fmt.Println(esdtData.TokenMetaData) + + expUris := [][]byte{[]byte(hex.EncodeToString([]byte("uri")))} + + retrievedMetaData := esdtData.TokenMetaData + + require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) + require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) + // require.Equal(t, expectedMetaData.royalties, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Royalties)).Bytes()))) + require.Equal(t, hash, []byte(hex.EncodeToString(retrievedMetaData.Hash))) + for i, uri := range expUris { + require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) + } + require.Equal(t, attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) +} From 18e4b2ad40bebca2fe8fe1bfcee53d6a0b0968a8 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 21 May 2024 18:26:24 +0300 Subject: [PATCH 256/503] update separate functions --- .../vm/esdtImprovements_test.go | 150 ++++++++++++------ 1 file changed, 102 insertions(+), 48 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index b79f9833d10..30ed395ad92 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -12,6 +12,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data/esdt" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" + testsChainSimulator "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" @@ -85,42 +86,14 @@ func TestChainSimulator_CheckNFTMetadata(t *testing.T) { address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) - - // set account esdt roles - tokenID := []byte("ASD-d31313") - - roles := [][]byte{[]byte(core.ESDTMetaDataRecreate), []byte(core.ESDTRoleNFTCreate)} - rolesKey := append([]byte(core.ProtectedKeyPrefix), append([]byte(core.ESDTRoleIdentifier), []byte(core.ESDTKeyIdentifier)...)...) - rolesKey = append(rolesKey, tokenID...) - - rolesData := &esdt.ESDTRoles{ - Roles: roles, - } - - rolesDataBytes, err := cs.GetNodeHandler(shardID).GetCoreComponents().InternalMarshalizer().Marshal(rolesData) - require.Nil(t, err) - - keys := make(map[string]string) - keys[hex.EncodeToString(rolesKey)] = hex.EncodeToString(rolesDataBytes) - - err = cs.SetStateMultiple([]*dtos.AddressState{ - { - Address: address.Bech32, - Balance: "10000000000000000000000", - Keys: keys, - }, - }) - require.Nil(t, err) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch) - 1) require.Nil(t, err) - privateKey, _, err := chainSimulator.GenerateBlsPrivateKeys(1) - require.Nil(t, err) + log.Info("Initial setup: Create an NFT and an SFT (before the activation of DynamicEsdtFlag)") - err = cs.AddValidatorKeys(privateKey) - require.Nil(t, err) + tokenID := []byte("ASD-d31313") + + setAddressEsdtRoles(t, cs, address, tokenID) nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) name := []byte(hex.EncodeToString([]byte("name"))) @@ -128,6 +101,8 @@ func TestChainSimulator_CheckNFTMetadata(t *testing.T) { attributes := []byte(hex.EncodeToString([]byte("attributes"))) uris := []byte(hex.EncodeToString([]byte("uri"))) + expUris := [][]byte{[]byte(hex.EncodeToString([]byte("uri")))} + txDataField := bytes.Join( [][]byte{ []byte(core.BuiltInFunctionESDTNFTCreate), @@ -160,37 +135,116 @@ func TestChainSimulator_CheckNFTMetadata(t *testing.T) { require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - account, err := cs.GetNodeHandler(shardID).GetStateComponents().AccountsAdapter().LoadAccount(core.SystemAccountAddress) + err = cs.GenerateBlocks(10) + + shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) + + log.Info("Step 1. check that the metadata for nft and sfts are saved on the system account") + + retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) + + require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) + require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) + require.Equal(t, hash, []byte(hex.EncodeToString(retrievedMetaData.Hash))) + for i, uri := range expUris { + require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) + } + require.Equal(t, attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) + + log.Info("Step 2. wait for DynamicEsdtFlag activation") + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + log.Info("Step 3. transfer the NFT and the SFT to another account") + + nonceArg := hex.EncodeToString(big.NewInt(0).SetUint64(2).Bytes()) + quantityToTransfer := int64(1) + quantityToTransferArg := hex.EncodeToString(big.NewInt(quantityToTransfer).Bytes()) + txDataField = []byte(core.BuiltInFunctionESDTNFTTransfer + "@" + hex.EncodeToString([]byte(tokenID)) + + "@" + nonceArg + "@" + quantityToTransferArg + "@" + hex.EncodeToString(address.Bytes)) + + tx = &transaction.Transaction{ + Nonce: 1, + SndAddr: address.Bytes, + RcvAddr: address.Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult) + + require.Equal(t, "success", txResult.Status.String()) +} + +func getMetaDataFromAcc( + t *testing.T, + cs testsChainSimulator.ChainSimulator, + addressBytes []byte, + token []byte, + shardID uint32, +) *esdt.MetaData { + account, err := cs.GetNodeHandler(shardID).GetStateComponents().AccountsAdapter().LoadAccount(addressBytes) require.Nil(t, err) userAccount, ok := account.(state.UserAccountHandler) require.True(t, ok) baseEsdtKeyPrefix := core.ProtectedKeyPrefix + core.ESDTKeyIdentifier - key := append([]byte(baseEsdtKeyPrefix), tokenID...) - - fmt.Println(userAccount) + key := append([]byte(baseEsdtKeyPrefix), token...) key2 := append(key, big.NewInt(0).SetUint64(1).Bytes()...) esdtDataBytes, _, err := userAccount.RetrieveValue(key2) require.Nil(t, err) - esdtData := &esdt.ESDigitalToken{} + esdtData := &esdt.ESDigitalToken{} err = cs.GetNodeHandler(shardID).GetCoreComponents().InternalMarshalizer().Unmarshal(esdtData, esdtDataBytes) require.Nil(t, err) - require.NotNil(t, esdtData.TokenMetaData) - fmt.Println(esdtData.TokenMetaData) - expUris := [][]byte{[]byte(hex.EncodeToString([]byte("uri")))} + return esdtData.TokenMetaData +} - retrievedMetaData := esdtData.TokenMetaData +func setAddressEsdtRoles( + t *testing.T, + cs testsChainSimulator.ChainSimulator, + address dtos.WalletAddress, + token []byte, +) { + marshaller := cs.GetNodeHandler(0).GetCoreComponents().InternalMarshalizer() + + roles := [][]byte{ + []byte(core.ESDTMetaDataRecreate), + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleNFTBurn), + } + rolesKey := append([]byte(core.ProtectedKeyPrefix), append([]byte(core.ESDTRoleIdentifier), []byte(core.ESDTKeyIdentifier)...)...) + rolesKey = append(rolesKey, token...) - require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) - require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) - // require.Equal(t, expectedMetaData.royalties, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Royalties)).Bytes()))) - require.Equal(t, hash, []byte(hex.EncodeToString(retrievedMetaData.Hash))) - for i, uri := range expUris { - require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) + rolesData := &esdt.ESDTRoles{ + Roles: roles, } - require.Equal(t, attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) + + rolesDataBytes, err := marshaller.Marshal(rolesData) + require.Nil(t, err) + + keys := make(map[string]string) + keys[hex.EncodeToString(rolesKey)] = hex.EncodeToString(rolesDataBytes) + + err = cs.SetStateMultiple([]*dtos.AddressState{ + { + Address: address.Bech32, + Balance: "10000000000000000000000", + Keys: keys, + }, + }) + require.Nil(t, err) } From 3177a85df3360872d7e65944e6a3743fac54b16c Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 22 May 2024 00:36:09 +0300 Subject: [PATCH 257/503] copy validator status in epoch struct --- epochStart/metachain/stakingDataProvider.go | 19 +++++- .../metachain/stakingDataProvider_test.go | 64 ++++++++++++++++--- 2 files changed, 74 insertions(+), 9 deletions(-) diff --git a/epochStart/metachain/stakingDataProvider.go b/epochStart/metachain/stakingDataProvider.go index b655fbe1b16..aa0129a6f1a 100644 --- a/epochStart/metachain/stakingDataProvider.go +++ b/epochStart/metachain/stakingDataProvider.go @@ -580,7 +580,24 @@ func (sdp *stakingDataProvider) GetCurrentEpochValidatorStats() epochStart.Valid sdp.mutStakingData.RLock() defer sdp.mutStakingData.RUnlock() - return sdp.validatorStatsInEpoch + return copyValidatorStatsInEpoch(sdp.validatorStatsInEpoch) +} + +func copyValidatorStatsInEpoch(oldInstance epochStart.ValidatorStatsInEpoch) epochStart.ValidatorStatsInEpoch { + return epochStart.ValidatorStatsInEpoch{ + Eligible: copyMap(oldInstance.Eligible), + Waiting: copyMap(oldInstance.Waiting), + Leaving: copyMap(oldInstance.Leaving), + } +} + +func copyMap(oldMap map[uint32]int) map[uint32]int { + newMap := make(map[uint32]int, len(oldMap)) + for key, value := range oldMap { + newMap[key] = value + } + + return newMap } // IsInterfaceNil return true if underlying object is nil diff --git a/epochStart/metachain/stakingDataProvider_test.go b/epochStart/metachain/stakingDataProvider_test.go index e3bfc1e6259..e11bb45801e 100644 --- a/epochStart/metachain/stakingDataProvider_test.go +++ b/epochStart/metachain/stakingDataProvider_test.go @@ -7,6 +7,7 @@ import ( "fmt" "math/big" "strings" + "sync" "testing" "github.com/multiversx/mx-chain-core-go/core" @@ -465,16 +466,63 @@ func TestStakingDataProvider_PrepareStakingDataForRewards(t *testing.T) { func TestStakingDataProvider_FillValidatorInfo(t *testing.T) { t.Parallel() - owner := []byte("owner") - topUpVal := big.NewInt(828743) - basePrice := big.NewInt(100000) - stakeVal := big.NewInt(0).Add(topUpVal, basePrice) - numRunContractCalls := 0 + t.Run("should work", func(t *testing.T) { + t.Parallel() - sdp := createStakingDataProviderWithMockArgs(t, owner, topUpVal, stakeVal, &numRunContractCalls) + owner := []byte("owner") + topUpVal := big.NewInt(828743) + basePrice := big.NewInt(100000) + stakeVal := big.NewInt(0).Add(topUpVal, basePrice) + numRunContractCalls := 0 - err := sdp.FillValidatorInfo(&state.ValidatorInfo{PublicKey: []byte("bls key")}) - require.NoError(t, err) + sdp := createStakingDataProviderWithMockArgs(t, owner, topUpVal, stakeVal, &numRunContractCalls) + + err := sdp.FillValidatorInfo(&state.ValidatorInfo{PublicKey: []byte("bls key")}) + require.NoError(t, err) + }) + t.Run("concurrent calls should work", func(t *testing.T) { + t.Parallel() + + defer func() { + r := recover() + if r != nil { + require.Fail(t, "should have not panicked") + } + }() + + owner := []byte("owner") + topUpVal := big.NewInt(828743) + basePrice := big.NewInt(100000) + stakeVal := big.NewInt(0).Add(topUpVal, basePrice) + numRunContractCalls := 0 + + sdp := createStakingDataProviderWithMockArgs(t, owner, topUpVal, stakeVal, &numRunContractCalls) + + wg := sync.WaitGroup{} + numCalls := 100 + wg.Add(numCalls) + + for i := 0; i < numCalls; i++ { + go func(idx int) { + switch idx % 2 { + case 0: + err := sdp.FillValidatorInfo(&state.ValidatorInfo{ + PublicKey: []byte("bls key"), + List: string(common.EligibleList), + ShardId: 0, + }) + require.NoError(t, err) + case 1: + stats := sdp.GetCurrentEpochValidatorStats() + log.Info(fmt.Sprintf("%d", stats.Eligible[0])) + } + + wg.Done() + }(i) + } + + wg.Wait() + }) } func TestCheckAndFillOwnerValidatorAuctionData(t *testing.T) { From c9f1f93f1c2713331c8d7374027769bdef0cb6b7 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 22 May 2024 10:53:05 +0300 Subject: [PATCH 258/503] further test + mutex fix --- process/peer/validatorsProvider.go | 4 ++ process/peer/validatorsProviderAuction.go | 13 ++--- process/peer/validatorsProvider_test.go | 69 +++++++++++++++++++++++ 3 files changed, 78 insertions(+), 8 deletions(-) diff --git a/process/peer/validatorsProvider.go b/process/peer/validatorsProvider.go index 7c3b8505310..8caff26430a 100644 --- a/process/peer/validatorsProvider.go +++ b/process/peer/validatorsProvider.go @@ -320,6 +320,10 @@ func shouldCombine(triePeerType common.PeerType, currentPeerType common.PeerType // ForceUpdate will trigger the update process of all caches func (vp *validatorsProvider) ForceUpdate() error { vp.updateCache() + + vp.auctionMutex.Lock() + defer vp.auctionMutex.Unlock() + return vp.updateAuctionListCache() } diff --git a/process/peer/validatorsProviderAuction.go b/process/peer/validatorsProviderAuction.go index 144ace850fb..a31a89f97e8 100644 --- a/process/peer/validatorsProviderAuction.go +++ b/process/peer/validatorsProviderAuction.go @@ -27,9 +27,10 @@ func (vp *validatorsProvider) GetAuctionList() ([]*common.AuctionListValidatorAP } func (vp *validatorsProvider) updateAuctionListCacheIfNeeded() error { - vp.auctionMutex.RLock() + vp.auctionMutex.Lock() + defer vp.auctionMutex.Unlock() + shouldUpdate := time.Since(vp.lastAuctionCacheUpdate) > vp.cacheRefreshIntervalDuration - vp.auctionMutex.RUnlock() if shouldUpdate { return vp.updateAuctionListCache() @@ -38,6 +39,7 @@ func (vp *validatorsProvider) updateAuctionListCacheIfNeeded() error { return nil } +// this func should be called under mutex protection func (vp *validatorsProvider) updateAuctionListCache() error { rootHash := vp.validatorStatistics.LastFinalizedRootHash() if len(rootHash) == 0 { @@ -49,19 +51,15 @@ func (vp *validatorsProvider) updateAuctionListCache() error { return err } - vp.auctionMutex.Lock() vp.cachedRandomness = rootHash - vp.auctionMutex.Unlock() newCache, err := vp.createValidatorsAuctionCache(validatorsMap) if err != nil { return err } - vp.auctionMutex.Lock() vp.lastAuctionCacheUpdate = time.Now() vp.cachedAuctionValidators = newCache - vp.auctionMutex.Unlock() return nil } @@ -96,10 +94,9 @@ func (vp *validatorsProvider) fillAllValidatorsInfo(validatorsMap state.ShardVal return err } +// this func should be called under mutex protection func (vp *validatorsProvider) getSelectedNodesFromAuction(validatorsMap state.ShardValidatorsInfoMapHandler) ([]state.ValidatorInfoHandler, error) { - vp.auctionMutex.RLock() randomness := vp.cachedRandomness - vp.auctionMutex.RUnlock() err := vp.auctionListSelector.SelectNodesFromAuctionList(validatorsMap, randomness) if err != nil { diff --git a/process/peer/validatorsProvider_test.go b/process/peer/validatorsProvider_test.go index 931567a2435..8bb56753660 100644 --- a/process/peer/validatorsProvider_test.go +++ b/process/peer/validatorsProvider_test.go @@ -1044,6 +1044,75 @@ func TestValidatorsProvider_GetAuctionList(t *testing.T) { require.Equal(t, expectedList, list) }) + t.Run("concurrent calls should only update cache once", func(t *testing.T) { + t.Parallel() + + args := createDefaultValidatorsProviderArg() + + args.CacheRefreshIntervalDurationInSec = time.Second * 5 + + expectedRootHash := []byte("root hash") + ctRootHashCalled := uint32(0) + ctSelectNodesFromAuctionList := uint32(0) + ctFillValidatorInfoCalled := uint32(0) + ctGetOwnersDataCalled := uint32(0) + ctComputeUnqualifiedNodes := uint32(0) + + args.ValidatorStatistics = &testscommon.ValidatorStatisticsProcessorStub{ + LastFinalizedRootHashCalled: func() []byte { + atomic.AddUint32(&ctRootHashCalled, 1) + return expectedRootHash + }, + GetValidatorInfoForRootHashCalled: func(rootHash []byte) (state.ShardValidatorsInfoMapHandler, error) { + require.Equal(t, expectedRootHash, rootHash) + return state.NewShardValidatorsInfoMap(), nil + }, + } + args.AuctionListSelector = &stakingcommon.AuctionListSelectorStub{ + SelectNodesFromAuctionListCalled: func(validatorsInfoMap state.ShardValidatorsInfoMapHandler, randomness []byte) error { + atomic.AddUint32(&ctSelectNodesFromAuctionList, 1) + require.Equal(t, expectedRootHash, randomness) + return nil + }, + } + args.StakingDataProvider = &stakingcommon.StakingDataProviderStub{ + FillValidatorInfoCalled: func(validator state.ValidatorInfoHandler) error { + atomic.AddUint32(&ctFillValidatorInfoCalled, 1) + return nil + }, + GetOwnersDataCalled: func() map[string]*epochStart.OwnerData { + atomic.AddUint32(&ctGetOwnersDataCalled, 1) + return nil + }, + ComputeUnQualifiedNodesCalled: func(validatorInfos state.ShardValidatorsInfoMapHandler) ([][]byte, map[string][][]byte, error) { + atomic.AddUint32(&ctComputeUnqualifiedNodes, 1) + return nil, nil, nil + }, + } + vp, _ := NewValidatorsProvider(args) + time.Sleep(args.CacheRefreshIntervalDurationInSec) + + numCalls := 100 + wg := sync.WaitGroup{} + wg.Add(numCalls) + + for i := 0; i < numCalls; i++ { + go func() { + list, err := vp.GetAuctionList() + require.NoError(t, err) + require.Empty(t, list) + + wg.Done() + }() + } + + wg.Wait() + + require.LessOrEqual(t, ctRootHashCalled, uint32(2)) // another call might be from constructor in startRefreshProcess.updateCache + + require.NoError(t, vp.Close()) + }) + } func createMockValidatorInfo() *state.ValidatorInfo { From 3363e309a4f4a1ea42c1cfea9f42eaa1e88aae45 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 22 May 2024 11:07:55 +0300 Subject: [PATCH 259/503] further test + mutex fix for validatorsProvider as well --- process/peer/validatorsProvider.go | 15 +++++++------ process/peer/validatorsProvider_test.go | 28 ++++++++++++++++++------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/process/peer/validatorsProvider.go b/process/peer/validatorsProvider.go index 8caff26430a..a7aa60ea7f5 100644 --- a/process/peer/validatorsProvider.go +++ b/process/peer/validatorsProvider.go @@ -129,9 +129,10 @@ func (vp *validatorsProvider) GetLatestValidators() map[string]*validator.Valida } func (vp *validatorsProvider) updateCacheIfNeeded() { - vp.lock.RLock() + vp.lock.Lock() + defer vp.lock.Unlock() + shouldUpdate := time.Since(vp.lastCacheUpdate) > vp.cacheRefreshIntervalDuration - vp.lock.RUnlock() if shouldUpdate { vp.updateCache() @@ -192,7 +193,10 @@ func (vp *validatorsProvider) epochStartEventHandler() nodesCoordinator.EpochSta func (vp *validatorsProvider) startRefreshProcess(ctx context.Context) { for { + vp.lock.Lock() vp.updateCache() + vp.lock.Unlock() + select { case epoch := <-vp.refreshCache: vp.lock.Lock() @@ -206,6 +210,7 @@ func (vp *validatorsProvider) startRefreshProcess(ctx context.Context) { } } +// this func should be called under mutex protection func (vp *validatorsProvider) updateCache() { lastFinalizedRootHash := vp.validatorStatistics.LastFinalizedRootHash() if len(lastFinalizedRootHash) == 0 { @@ -217,16 +222,12 @@ func (vp *validatorsProvider) updateCache() { log.Trace("validatorsProvider - GetLatestValidatorInfos failed", "error", err) } - vp.lock.RLock() epoch := vp.currentEpoch - vp.lock.RUnlock() newCache := vp.createNewCache(epoch, allNodes) - vp.lock.Lock() vp.lastCacheUpdate = time.Now() vp.cache = newCache - vp.lock.Unlock() } func (vp *validatorsProvider) createNewCache( @@ -319,7 +320,9 @@ func shouldCombine(triePeerType common.PeerType, currentPeerType common.PeerType // ForceUpdate will trigger the update process of all caches func (vp *validatorsProvider) ForceUpdate() error { + vp.lock.Lock() vp.updateCache() + vp.lock.Unlock() vp.auctionMutex.Lock() defer vp.auctionMutex.Unlock() diff --git a/process/peer/validatorsProvider_test.go b/process/peer/validatorsProvider_test.go index 8bb56753660..71da53f08e7 100644 --- a/process/peer/validatorsProvider_test.go +++ b/process/peer/validatorsProvider_test.go @@ -1092,23 +1092,37 @@ func TestValidatorsProvider_GetAuctionList(t *testing.T) { vp, _ := NewValidatorsProvider(args) time.Sleep(args.CacheRefreshIntervalDurationInSec) - numCalls := 100 + numCalls := 99 wg := sync.WaitGroup{} wg.Add(numCalls) for i := 0; i < numCalls; i++ { - go func() { - list, err := vp.GetAuctionList() - require.NoError(t, err) - require.Empty(t, list) + go func(idx int) { + switch idx % 3 { + case 0: + list, err := vp.GetAuctionList() + require.NoError(t, err) + require.Empty(t, list) + case 1: + err := vp.ForceUpdate() + require.NoError(t, err) + case 2: + _ = vp.GetLatestValidators() + } wg.Done() - }() + }(i) } wg.Wait() - require.LessOrEqual(t, ctRootHashCalled, uint32(2)) // another call might be from constructor in startRefreshProcess.updateCache + // expectedMaxNumCalls is: + // - 1 from constructor + // - 1 from GetAuctionList, should not update second time + // - 1 from GetLatestValidators, should not update second time + // - 33 calls * 2 from ForceUpdate, calling it twice/call + expectedMaxNumCalls := uint32(1 + 1 + 1 + 66) + require.LessOrEqual(t, ctRootHashCalled, expectedMaxNumCalls) require.NoError(t, vp.Close()) }) From 9e45d8c5f80e18c8aae1c392dacbd47029e215b5 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 22 May 2024 11:19:10 +0300 Subject: [PATCH 260/503] use require.NotPanics --- .../metachain/stakingDataProvider_test.go | 47 +++++++++---------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/epochStart/metachain/stakingDataProvider_test.go b/epochStart/metachain/stakingDataProvider_test.go index e11bb45801e..6f5ad62868d 100644 --- a/epochStart/metachain/stakingDataProvider_test.go +++ b/epochStart/metachain/stakingDataProvider_test.go @@ -483,13 +483,6 @@ func TestStakingDataProvider_FillValidatorInfo(t *testing.T) { t.Run("concurrent calls should work", func(t *testing.T) { t.Parallel() - defer func() { - r := recover() - if r != nil { - require.Fail(t, "should have not panicked") - } - }() - owner := []byte("owner") topUpVal := big.NewInt(828743) basePrice := big.NewInt(100000) @@ -502,26 +495,28 @@ func TestStakingDataProvider_FillValidatorInfo(t *testing.T) { numCalls := 100 wg.Add(numCalls) - for i := 0; i < numCalls; i++ { - go func(idx int) { - switch idx % 2 { - case 0: - err := sdp.FillValidatorInfo(&state.ValidatorInfo{ - PublicKey: []byte("bls key"), - List: string(common.EligibleList), - ShardId: 0, - }) - require.NoError(t, err) - case 1: - stats := sdp.GetCurrentEpochValidatorStats() - log.Info(fmt.Sprintf("%d", stats.Eligible[0])) - } - - wg.Done() - }(i) - } + require.NotPanics(t, func() { + for i := 0; i < numCalls; i++ { + go func(idx int) { + switch idx % 2 { + case 0: + err := sdp.FillValidatorInfo(&state.ValidatorInfo{ + PublicKey: []byte("bls key"), + List: string(common.EligibleList), + ShardId: 0, + }) + require.NoError(t, err) + case 1: + stats := sdp.GetCurrentEpochValidatorStats() + log.Info(fmt.Sprintf("%d", stats.Eligible[0])) + } + + wg.Done() + }(i) + } - wg.Wait() + wg.Wait() + }) }) } From 9cede459c8285400b89090e2a7137a7221f9db6d Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 22 May 2024 13:10:51 +0300 Subject: [PATCH 261/503] use esdt transfer utils --- .../vm/esdtImprovements_test.go | 59 ++++++++++++------- 1 file changed, 38 insertions(+), 21 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 30ed395ad92..e6e720750f6 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -3,7 +3,6 @@ package vm import ( "bytes" "encoding/hex" - "fmt" "math/big" "testing" "time" @@ -14,6 +13,7 @@ import ( "github.com/multiversx/mx-chain-go/config" testsChainSimulator "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" + "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" @@ -46,6 +46,8 @@ func TestChainSimulator_CheckNFTMetadata(t *testing.T) { t.Skip("this is not a short test") } + // logger.SetLogLevel("*:TRACE") + startTime := time.Now().Unix() roundDurationInMillis := uint64(6000) roundsPerEpoch := core.OptionalUint64{ @@ -53,7 +55,7 @@ func TestChainSimulator_CheckNFTMetadata(t *testing.T) { Value: 20, } - activationEpoch := uint32(4) + activationEpoch := uint32(2) numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ @@ -156,34 +158,48 @@ func TestChainSimulator_CheckNFTMetadata(t *testing.T) { err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) require.Nil(t, err) + err = cs.GenerateBlocks(10) + require.Nil(t, err) + log.Info("Step 3. transfer the NFT and the SFT to another account") - nonceArg := hex.EncodeToString(big.NewInt(0).SetUint64(2).Bytes()) - quantityToTransfer := int64(1) - quantityToTransferArg := hex.EncodeToString(big.NewInt(quantityToTransfer).Bytes()) - txDataField = []byte(core.BuiltInFunctionESDTNFTTransfer + "@" + hex.EncodeToString([]byte(tokenID)) + - "@" + nonceArg + "@" + quantityToTransferArg + "@" + hex.EncodeToString(address.Bytes)) + address2, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) + require.Nil(t, err) - tx = &transaction.Transaction{ - Nonce: 1, - SndAddr: address.Bytes, - RcvAddr: address.Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, - } + tx = utils.CreateESDTNFTTransferTx( + 1, + address.Bytes, + address2.Bytes, + tokenID, + 1, + big.NewInt(1), + minGasPrice, + 10_000_000, + "", + ) + tx.Version = 1 + tx.Signature = []byte("dummySig") + tx.ChainID = []byte(configs.ChainID) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - require.Equal(t, "success", txResult.Status.String()) + + log.Info("Step 4. check that the metadata for nft is saved to the receiver account") + + shardID2 := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address2.Bytes) + + retrievedMetaData = getMetaDataFromAcc(t, cs, address2.Bytes, tokenID, shardID2) + + require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) + require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) + require.Equal(t, hash, []byte(hex.EncodeToString(retrievedMetaData.Hash))) + for i, uri := range expUris { + require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) + } + require.Equal(t, attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) } func getMetaDataFromAcc( @@ -225,6 +241,7 @@ func setAddressEsdtRoles( []byte(core.ESDTMetaDataRecreate), []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleNFTBurn), + []byte(core.ESDTRoleTransfer), } rolesKey := append([]byte(core.ProtectedKeyPrefix), append([]byte(core.ESDTRoleIdentifier), []byte(core.ESDTKeyIdentifier)...)...) rolesKey = append(rolesKey, token...) From 77a77ca4a18c2fea326455e1d58b93d795cc65d1 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 24 May 2024 15:11:54 +0300 Subject: [PATCH 262/503] fix indentation --- process/transactionLog/process.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/process/transactionLog/process.go b/process/transactionLog/process.go index eed686dd0e3..ae243a9930e 100644 --- a/process/transactionLog/process.go +++ b/process/transactionLog/process.go @@ -36,8 +36,7 @@ type txLogProcessor struct { } // NewTxLogProcessor creates a transaction log processor capable of parsing logs from the VM -// -// and saving them into the injected storage +// and saving them into the injected storage func NewTxLogProcessor(args ArgTxLogProcessor) (*txLogProcessor, error) { storer := args.Storer if check.IfNil(storer) && args.SaveInStorageEnabled { From a0b57b4e2cb6e5c97e722a7fe6ff277ba10bafe4 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Sat, 25 May 2024 17:40:06 +0300 Subject: [PATCH 263/503] update first scenario --- .../vm/esdtImprovements_test.go | 91 +++++++++++++++++-- 1 file changed, 82 insertions(+), 9 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index e6e720750f6..0e788675374 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -10,6 +10,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/esdt" "github.com/multiversx/mx-chain-core-go/data/transaction" + dataVm "github.com/multiversx/mx-chain-core-go/data/vm" "github.com/multiversx/mx-chain-go/config" testsChainSimulator "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" @@ -18,8 +19,11 @@ import ( "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" + "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/state" + "github.com/multiversx/mx-chain-go/vm" logger "github.com/multiversx/mx-chain-logger-go" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/stretchr/testify/require" ) @@ -35,13 +39,17 @@ var log = logger.GetOrCreate("integrationTests/chainSimulator/vm") // // Initial setup: Create an NFT and an SFT (before the activation of DynamicEsdtFlag) // -// 1. check that the metadata for nft and sfts are saved on the system account +// 1.check that the metadata for all tokens is saved on the system account // 2. wait for DynamicEsdtFlag activation -// 3. transfer the NFT and the SFT to another account -// 4. check that the metadata for nft is saved to the receiver account -// 5. check that the metadata for the sft is saved on the system account -// 6. repeat 3-5 for both intra and cross shard -func TestChainSimulator_CheckNFTMetadata(t *testing.T) { +// 3. transfer the tokens to another account +// 4. check that the metadata for all tokens is saved on the system account +// 5. make an updateTokenID@tokenID function call on the ESDTSystem SC for all token types +// 6. check that the metadata for all tokens is saved on the system account +// 7. transfer the tokens to another account +// 8. check that the metaData for the NFT was removed from the system account and moved to the user account +// 9. check that the metaData for the rest of the tokens is still present on the system account and not on the userAccount +// 10. do the test for both intra and cross shard txs +func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } @@ -141,7 +149,7 @@ func TestChainSimulator_CheckNFTMetadata(t *testing.T) { shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) - log.Info("Step 1. check that the metadata for nft and sfts are saved on the system account") + log.Info("Step 1. check that the metadata for all tokens is saved on the system account") retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) @@ -161,7 +169,7 @@ func TestChainSimulator_CheckNFTMetadata(t *testing.T) { err = cs.GenerateBlocks(10) require.Nil(t, err) - log.Info("Step 3. transfer the NFT and the SFT to another account") + log.Info("Step 3. transfer the tokens to another account") address2, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) @@ -187,7 +195,61 @@ func TestChainSimulator_CheckNFTMetadata(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) - log.Info("Step 4. check that the metadata for nft is saved to the receiver account") + log.Info("Step 4. check that the metadata for all tokens is saved on the system account") + + retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) + + require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) + require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) + require.Equal(t, hash, []byte(hex.EncodeToString(retrievedMetaData.Hash))) + for i, uri := range expUris { + require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) + } + require.Equal(t, attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) + + log.Info("Step 5. make an updateTokenID@tokenID function call on the ESDTSystem SC for all token types") + + output, err := executeQuery(cs, core.MetachainShardId, vm.ESDTSCAddress, "updateTokenID", [][]byte{tokenID}) + require.Nil(t, err) + require.Equal(t, "", output.ReturnMessage) + require.Equal(t, vmcommon.Ok, output.ReturnCode) + + log.Info("Step 6. check that the metadata for all tokens is saved on the system account") + + retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) + + require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) + require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) + require.Equal(t, hash, []byte(hex.EncodeToString(retrievedMetaData.Hash))) + for i, uri := range expUris { + require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) + } + require.Equal(t, attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) + + log.Info("Step 7. transfer the tokens to another account") + + tx = utils.CreateESDTNFTTransferTx( + 1, + address.Bytes, + address2.Bytes, + tokenID, + 1, + big.NewInt(1), + minGasPrice, + 10_000_000, + "", + ) + tx.Version = 1 + tx.Signature = []byte("dummySig") + tx.ChainID = []byte(configs.ChainID) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + log.Info("Step 8. check that the metaData for the NFT was removed from the system account and moved to the user account") shardID2 := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address2.Bytes) @@ -202,6 +264,15 @@ func TestChainSimulator_CheckNFTMetadata(t *testing.T) { require.Equal(t, attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) } +func executeQuery(cs testsChainSimulator.ChainSimulator, shardID uint32, scAddress []byte, funcName string, args [][]byte) (*dataVm.VMOutputApi, error) { + output, _, err := cs.GetNodeHandler(shardID).GetFacadeHandler().ExecuteSCQuery(&process.SCQuery{ + ScAddress: scAddress, + FuncName: funcName, + Arguments: args, + }) + return output, err +} + func getMetaDataFromAcc( t *testing.T, cs testsChainSimulator.ChainSimulator, @@ -242,6 +313,8 @@ func setAddressEsdtRoles( []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleNFTBurn), []byte(core.ESDTRoleTransfer), + []byte(core.ESDTRoleNFTUpdateAttributes), + []byte(core.ESDTRoleNFTAddURI), } rolesKey := append([]byte(core.ProtectedKeyPrefix), append([]byte(core.ESDTRoleIdentifier), []byte(core.ESDTKeyIdentifier)...)...) rolesKey = append(rolesKey, token...) From 2d3344b1dce6ec72e74d40bc6e1b6eafa5e2d5b7 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Sat, 25 May 2024 19:14:03 +0300 Subject: [PATCH 264/503] added more nft tests --- .../vm/esdtImprovements_test.go | 620 +++++++++++++++++- 1 file changed, 611 insertions(+), 9 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 0e788675374..bc6c2eddf70 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -103,7 +103,15 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { tokenID := []byte("ASD-d31313") - setAddressEsdtRoles(t, cs, address, tokenID) + roles := [][]byte{ + []byte(core.ESDTMetaDataRecreate), + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleNFTBurn), + []byte(core.ESDTRoleTransfer), + []byte(core.ESDTRoleNFTUpdateAttributes), + []byte(core.ESDTRoleNFTAddURI), + } + setAddressEsdtRoles(t, cs, address, tokenID, roles) nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) name := []byte(hex.EncodeToString([]byte("name"))) @@ -305,17 +313,10 @@ func setAddressEsdtRoles( cs testsChainSimulator.ChainSimulator, address dtos.WalletAddress, token []byte, + roles [][]byte, ) { marshaller := cs.GetNodeHandler(0).GetCoreComponents().InternalMarshalizer() - roles := [][]byte{ - []byte(core.ESDTMetaDataRecreate), - []byte(core.ESDTRoleNFTCreate), - []byte(core.ESDTRoleNFTBurn), - []byte(core.ESDTRoleTransfer), - []byte(core.ESDTRoleNFTUpdateAttributes), - []byte(core.ESDTRoleNFTAddURI), - } rolesKey := append([]byte(core.ProtectedKeyPrefix), append([]byte(core.ESDTRoleIdentifier), []byte(core.ESDTKeyIdentifier)...)...) rolesKey = append(rolesKey, token...) @@ -338,3 +339,604 @@ func setAddressEsdtRoles( }) require.Nil(t, err) } + +// Test scenario +// +// Initial setup: Create fungible, NFT, SFT and metaESDT tokens +// (after the activation of DynamicEsdtFlag) +// +// 1. check that the metaData for the NFT was saved in the user account and not on the system account +// 2. check that the metaData for the other token types is saved on the system account and not at the user account level +func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + // logger.SetLogLevel("*:TRACE") + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(2) + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + mintValue := big.NewInt(10) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + + address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) + require.Nil(t, err) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") + + tokenID := []byte("ASD-d31313") + + roles := [][]byte{ + []byte(core.ESDTMetaDataRecreate), + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleNFTBurn), + []byte(core.ESDTRoleTransfer), + []byte(core.ESDTRoleNFTUpdateAttributes), + []byte(core.ESDTRoleNFTAddURI), + } + setAddressEsdtRoles(t, cs, address, tokenID, roles) + + nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + name := []byte(hex.EncodeToString([]byte("name"))) + hash := []byte(hex.EncodeToString([]byte("hash"))) + attributes := []byte(hex.EncodeToString([]byte("attributes"))) + uris := []byte(hex.EncodeToString([]byte("uri"))) + + expUris := [][]byte{[]byte(hex.EncodeToString([]byte("uri")))} + + txDataField := bytes.Join( + [][]byte{ + []byte(core.BuiltInFunctionESDTNFTCreate), + []byte(hex.EncodeToString(tokenID)), + []byte(hex.EncodeToString(big.NewInt(1).Bytes())), // quantity + name, + []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + hash, + attributes, + uris, + }, + []byte("@"), + ) + + tx := &transaction.Transaction{ + Nonce: 0, + SndAddr: address.Bytes, + RcvAddr: address.Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + + shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) + + log.Info("Step 1. check that the metaData for the NFT was saved in the user account and not on the system account") + + retrievedMetaData := getMetaDataFromAcc(t, cs, address.Bytes, tokenID, shardID) + + require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) + require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) + require.Equal(t, hash, []byte(hex.EncodeToString(retrievedMetaData.Hash))) + for i, uri := range expUris { + require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) + } + require.Equal(t, attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) +} + +// Test scenario +// +// Initial setup: Create NFT +// +// Call ESDTMetaDataRecreate to rewrite the meta data for the nft +// (The sender must have the ESDTMetaDataRecreate role) +func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(2) + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + mintValue := big.NewInt(10) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + + address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) + require.Nil(t, err) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + log.Info("Initial setup: Create NFT") + + tokenID := []byte("ASD-d31313") + + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTMetaDataRecreate), + } + setAddressEsdtRoles(t, cs, address, tokenID, roles) + + name := []byte(hex.EncodeToString([]byte("name"))) + hash := []byte(hex.EncodeToString([]byte("hash"))) + attributes := []byte(hex.EncodeToString([]byte("attributes"))) + uris := [][]byte{[]byte(hex.EncodeToString([]byte("uri")))} + + txDataField := bytes.Join( + [][]byte{ + []byte(core.BuiltInFunctionESDTNFTCreate), + []byte(hex.EncodeToString(tokenID)), + []byte(hex.EncodeToString(big.NewInt(1).Bytes())), // quantity + name, + []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + hash, + attributes, + uris[0], + }, + []byte("@"), + ) + + tx := &transaction.Transaction{ + Nonce: 0, + SndAddr: address.Bytes, + RcvAddr: address.Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + + shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) + + log.Info("Call ESDTMetaDataRecreate to rewrite the meta data for the nft") + + nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + name = []byte(hex.EncodeToString([]byte("name2"))) + hash = []byte(hex.EncodeToString([]byte("hash2"))) + attributes = []byte(hex.EncodeToString([]byte("attributes2"))) + + txDataField = bytes.Join( + [][]byte{ + []byte(core.ESDTMetaDataRecreate), + []byte(hex.EncodeToString(tokenID)), + nonce, + name, + []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + hash, + attributes, + uris[0], + }, + []byte("@"), + ) + + tx = &transaction.Transaction{ + Nonce: 1, + SndAddr: address.Bytes, + RcvAddr: address.Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) + + require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) + require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) + require.Equal(t, hash, []byte(hex.EncodeToString(retrievedMetaData.Hash))) + for i, uri := range uris { + require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) + } + require.Equal(t, attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) +} + +// Test scenario +// +// Initial setup: Create NFT +// +// Call ESDTMetaDataUpdate to update some of the meta data parameters +// (The sender must have the ESDTRoleNFTUpdate role) +func TestChainSimulator_NFT_ESDTMetaDataUpdate(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(2) + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + mintValue := big.NewInt(10) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + + address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) + require.Nil(t, err) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + log.Info("Initial setup: Create NFT") + + tokenID := []byte("ASD-d31313") + + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleNFTUpdate), + } + setAddressEsdtRoles(t, cs, address, tokenID, roles) + + name := []byte(hex.EncodeToString([]byte("name"))) + hash := []byte(hex.EncodeToString([]byte("hash"))) + attributes := []byte(hex.EncodeToString([]byte("attributes"))) + uris := [][]byte{[]byte(hex.EncodeToString([]byte("uri")))} + + txDataField := bytes.Join( + [][]byte{ + []byte(core.BuiltInFunctionESDTNFTCreate), + []byte(hex.EncodeToString(tokenID)), + []byte(hex.EncodeToString(big.NewInt(1).Bytes())), // quantity + name, + []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + hash, + attributes, + uris[0], + }, + []byte("@"), + ) + + tx := &transaction.Transaction{ + Nonce: 0, + SndAddr: address.Bytes, + RcvAddr: address.Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + + shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) + + log.Info("Call ESDTMetaDataRecreate to rewrite the meta data for the nft") + + nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + name = []byte(hex.EncodeToString([]byte("name2"))) + hash = []byte(hex.EncodeToString([]byte("hash2"))) + attributes = []byte(hex.EncodeToString([]byte("attributes2"))) + + txDataField = bytes.Join( + [][]byte{ + []byte(core.ESDTMetaDataUpdate), + []byte(hex.EncodeToString(tokenID)), + nonce, + name, + []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + hash, + attributes, + uris[0], + }, + []byte("@"), + ) + + tx = &transaction.Transaction{ + Nonce: 1, + SndAddr: address.Bytes, + RcvAddr: address.Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) + + require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) + require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) + require.Equal(t, hash, []byte(hex.EncodeToString(retrievedMetaData.Hash))) + for i, uri := range uris { + require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) + } + require.Equal(t, attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) +} + +// Test scenario +// +// Initial setup: Create NFT +// +// Call ESDTModifyCreator and check that the creator was modified +// (The sender must have the ESDTRoleModifyCreator role) +func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(2) + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + mintValue := big.NewInt(10) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + + address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) + require.Nil(t, err) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + log.Info("Initial setup: Create NFT") + + tokenID := []byte("ASD-d31313") + + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + } + setAddressEsdtRoles(t, cs, address, tokenID, roles) + + name := []byte(hex.EncodeToString([]byte("name"))) + hash := []byte(hex.EncodeToString([]byte("hash"))) + attributes := []byte(hex.EncodeToString([]byte("attributes"))) + uris := [][]byte{[]byte(hex.EncodeToString([]byte("uri")))} + + txDataField := bytes.Join( + [][]byte{ + []byte(core.BuiltInFunctionESDTNFTCreate), + []byte(hex.EncodeToString(tokenID)), + []byte(hex.EncodeToString(big.NewInt(1).Bytes())), // quantity + name, + []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + hash, + attributes, + uris[0], + }, + []byte("@"), + ) + + tx := &transaction.Transaction{ + Nonce: 0, + SndAddr: address.Bytes, + RcvAddr: address.Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + + shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) + + log.Info("Call ESDTModifyCreator and check that the creator was modified") + + newCreatorAddress, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) + require.Nil(t, err) + + roles = [][]byte{ + []byte(core.ESDTRoleModifyCreator), + } + setAddressEsdtRoles(t, cs, newCreatorAddress, tokenID, roles) + + nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + txDataField = bytes.Join( + [][]byte{ + []byte(core.ESDTModifyCreator), + []byte(hex.EncodeToString(tokenID)), + nonce, + }, + []byte("@"), + ) + + tx = &transaction.Transaction{ + Nonce: 0, + SndAddr: newCreatorAddress.Bytes, + RcvAddr: newCreatorAddress.Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) + + require.Equal(t, newCreatorAddress.Bytes, retrievedMetaData.Creator) +} From 0d3ed9b18e064ac68a71317ee47ae793872d4853 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Mon, 27 May 2024 15:07:13 +0300 Subject: [PATCH 265/503] added set new uris and modify reyalties scenarios --- .../vm/esdtImprovements_test.go | 352 +++++++++++++++++- 1 file changed, 348 insertions(+), 4 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index bc6c2eddf70..858aab3fe60 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -102,6 +102,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Initial setup: Create an NFT and an SFT (before the activation of DynamicEsdtFlag)") tokenID := []byte("ASD-d31313") + tokenType := core.DynamicNFTESDT roles := [][]byte{ []byte(core.ESDTMetaDataRecreate), @@ -113,6 +114,28 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { } setAddressEsdtRoles(t, cs, address, tokenID, roles) + txDataField := bytes.Join( + [][]byte{ + []byte(core.ESDTSetTokenType), + []byte(hex.EncodeToString(tokenID)), + []byte(hex.EncodeToString([]byte(tokenType))), + }, + []byte("@"), + ) + + tx := &transaction.Transaction{ + Nonce: 0, + SndAddr: core.ESDTSCAddress, + RcvAddr: address.Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) name := []byte(hex.EncodeToString([]byte("name"))) hash := []byte(hex.EncodeToString([]byte("hash"))) @@ -121,7 +144,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { expUris := [][]byte{[]byte(hex.EncodeToString([]byte("uri")))} - txDataField := bytes.Join( + txDataField = bytes.Join( [][]byte{ []byte(core.BuiltInFunctionESDTNFTCreate), []byte(hex.EncodeToString(tokenID)), @@ -135,7 +158,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { []byte("@"), ) - tx := &transaction.Transaction{ + tx = &transaction.Transaction{ Nonce: 0, SndAddr: address.Bytes, RcvAddr: address.Bytes, @@ -154,6 +177,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) err = cs.GenerateBlocks(10) + require.Nil(t, err) shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) @@ -455,6 +479,7 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) err = cs.GenerateBlocks(10) + require.Nil(t, err) shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) @@ -576,6 +601,7 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) err = cs.GenerateBlocks(10) + require.Nil(t, err) shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) @@ -735,6 +761,7 @@ func TestChainSimulator_NFT_ESDTMetaDataUpdate(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) err = cs.GenerateBlocks(10) + require.Nil(t, err) shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) @@ -892,8 +919,6 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - err = cs.GenerateBlocks(10) - shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) log.Info("Call ESDTModifyCreator and check that the creator was modified") @@ -901,6 +926,9 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { newCreatorAddress, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) + err = cs.GenerateBlocks(10) + require.Nil(t, err) + roles = [][]byte{ []byte(core.ESDTRoleModifyCreator), } @@ -940,3 +968,319 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { require.Equal(t, newCreatorAddress.Bytes, retrievedMetaData.Creator) } + +// Test scenario +// +// Initial setup: Create NFT +// +// Call ESDTSetNewURIs and check that the new URIs were set for the NFT +// (The sender must have the ESDTRoleSetNewURI role) +func TestChainSimulator_NFT_ESDTSetNewURIs(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(2) + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + mintValue := big.NewInt(10) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + + address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) + require.Nil(t, err) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + log.Info("Initial setup: Create NFT") + + tokenID := []byte("ASD-d31313") + + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + } + setAddressEsdtRoles(t, cs, address, tokenID, roles) + + name := []byte(hex.EncodeToString([]byte("name"))) + hash := []byte(hex.EncodeToString([]byte("hash"))) + attributes := []byte(hex.EncodeToString([]byte("attributes"))) + uris := [][]byte{[]byte(hex.EncodeToString([]byte("uri")))} + + txDataField := bytes.Join( + [][]byte{ + []byte(core.BuiltInFunctionESDTNFTCreate), + []byte(hex.EncodeToString(tokenID)), + []byte(hex.EncodeToString(big.NewInt(1).Bytes())), // quantity + name, + []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + hash, + attributes, + uris[0], + }, + []byte("@"), + ) + + tx := &transaction.Transaction{ + Nonce: 0, + SndAddr: address.Bytes, + RcvAddr: address.Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) + + log.Info("Call ESDTSetNewURIs and check that the new URIs were set for the NFT") + + roles = [][]byte{ + []byte(core.ESDTRoleSetNewURI), + } + setAddressEsdtRoles(t, cs, address, tokenID, roles) + + nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + uris = [][]byte{ + []byte(hex.EncodeToString([]byte("uri0"))), + []byte(hex.EncodeToString([]byte("uri1"))), + []byte(hex.EncodeToString([]byte("uri2"))), + } + + expUris := [][]byte{ + []byte("uri0"), + []byte("uri1"), + []byte("uri2"), + } + + txDataField = bytes.Join( + [][]byte{ + []byte(core.ESDTSetNewURIs), + []byte(hex.EncodeToString(tokenID)), + nonce, + uris[0], + uris[1], + uris[2], + }, + []byte("@"), + ) + + tx = &transaction.Transaction{ + Nonce: 1, + SndAddr: address.Bytes, + RcvAddr: address.Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) + + require.Equal(t, expUris, retrievedMetaData.URIs) +} + +// Test scenario +// +// Initial setup: Create NFT +// +// Call ESDTModifyRoyalties and check that the royalties were changed +// (The sender must have the ESDTRoleModifyRoyalties role) +func TestChainSimulator_NFT_ESDTModifyRoyalties(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(2) + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + mintValue := big.NewInt(10) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + + address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) + require.Nil(t, err) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + log.Info("Initial setup: Create NFT") + + tokenID := []byte("ASD-d31313") + + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + } + setAddressEsdtRoles(t, cs, address, tokenID, roles) + + name := []byte(hex.EncodeToString([]byte("name"))) + hash := []byte(hex.EncodeToString([]byte("hash"))) + attributes := []byte(hex.EncodeToString([]byte("attributes"))) + uris := [][]byte{[]byte(hex.EncodeToString([]byte("uri")))} + + txDataField := bytes.Join( + [][]byte{ + []byte(core.BuiltInFunctionESDTNFTCreate), + []byte(hex.EncodeToString(tokenID)), + []byte(hex.EncodeToString(big.NewInt(1).Bytes())), // quantity + name, + []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + hash, + attributes, + uris[0], + }, + []byte("@"), + ) + + tx := &transaction.Transaction{ + Nonce: 0, + SndAddr: address.Bytes, + RcvAddr: address.Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) + + log.Info("Call ESDTModifyRoyalties and check that the royalties were changed") + + roles = [][]byte{ + []byte(core.ESDTRoleModifyRoyalties), + } + setAddressEsdtRoles(t, cs, address, tokenID, roles) + + nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + royalties := []byte(hex.EncodeToString(big.NewInt(20).Bytes())) + + txDataField = bytes.Join( + [][]byte{ + []byte(core.ESDTModifyRoyalties), + []byte(hex.EncodeToString(tokenID)), + nonce, + royalties, + }, + []byte("@"), + ) + + tx = &transaction.Transaction{ + Nonce: 1, + SndAddr: address.Bytes, + RcvAddr: address.Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) + + require.Equal(t, uint32(big.NewInt(20).Uint64()), retrievedMetaData.Royalties) +} From c2da37d757562f221e355bd21ba8330611a646df Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 27 May 2024 15:26:18 +0300 Subject: [PATCH 266/503] added extra check for multiple relayed types in the same tx + added CompletedTxEventIdentifier for completed inner move balance of v3 --- .../relayedTx/relayedTx_test.go | 11 ++++--- process/errors.go | 3 ++ process/transaction/interceptedTransaction.go | 13 ++++++++ .../interceptedTransaction_test.go | 32 ++++++++++++++++++- process/transaction/shardProcess.go | 31 +++++++++++++++++- process/transaction/shardProcess_test.go | 21 ++++++++++++ 6 files changed, 105 insertions(+), 6 deletions(-) diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index 6bd74c50ee7..e2eab749a2f 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -140,9 +140,12 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing. checkSCRStatus(t, cs, pkConv, shardC, scr) } - // check log events - require.Equal(t, 3, len(result.Logs.Events)) - require.True(t, strings.Contains(string(result.Logs.Events[2].Data), "contract is paused")) + // 6 log events, 3 from the succeeded txs + 3 from the failed one + require.Equal(t, 6, len(result.Logs.Events)) + require.Equal(t, core.CompletedTxEventIdentifier, result.Logs.Events[0].Identifier) + require.Equal(t, core.CompletedTxEventIdentifier, result.Logs.Events[1].Identifier) + require.Equal(t, core.CompletedTxEventIdentifier, result.Logs.Events[5].Identifier) + require.True(t, strings.Contains(string(result.Logs.Events[4].Data), "contract is paused")) } func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorScCalls(t *testing.T) { @@ -238,7 +241,7 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorScCalls(t *t checkSCRStatus(t, cs, pkConv, shardC, scr) } - // 6 scrs, 3 with signalError + 3 with the actual errors + // 6 events, 3 with signalError + 3 with the actual errors require.Equal(t, 6, len(result.Logs.Events)) expectedLogEvents := map[int]string{ 1: "[wrong number of arguments]", diff --git a/process/errors.go b/process/errors.go index 1f32d6b686c..1e6464ea87e 100644 --- a/process/errors.go +++ b/process/errors.go @@ -1265,3 +1265,6 @@ var ErrRelayedTxV3TooManyInnerTransactions = errors.New("too many inner transact // ErrConsumedFeesMismatch signals that the fees consumed from relayer do not match the inner transactions fees var ErrConsumedFeesMismatch = errors.New("consumed fees mismatch") + +// ErrMultipleRelayedTxTypesIsNotAllowed signals that multiple types of relayed tx is not allowed +var ErrMultipleRelayedTxTypesIsNotAllowed = errors.New("multiple relayed tx types is not allowed") diff --git a/process/transaction/interceptedTransaction.go b/process/transaction/interceptedTransaction.go index 11b7d219bc6..831afdcbcbc 100644 --- a/process/transaction/interceptedTransaction.go +++ b/process/transaction/interceptedTransaction.go @@ -265,6 +265,11 @@ func (inTx *InterceptedTransaction) verifyIfRelayedTxV3(tx *transaction.Transact return err } + funcName, _, err := inTx.argsParser.ParseCallData(string(tx.Data)) + if err == nil && isRelayedTx(funcName) { + return process.ErrMultipleRelayedTxTypesIsNotAllowed + } + return inTx.verifyInnerTransactions(tx) } @@ -293,6 +298,10 @@ func (inTx *InterceptedTransaction) verifyIfRelayedTxV2(tx *transaction.Transact return nil } + if len(tx.InnerTransactions) > 0 { + return process.ErrMultipleRelayedTxTypesIsNotAllowed + } + userTx, err := createRelayedV2(tx, userTxArgs) if err != nil { return err @@ -314,6 +323,10 @@ func (inTx *InterceptedTransaction) verifyIfRelayedTx(tx *transaction.Transactio return process.ErrInvalidArguments } + if len(tx.InnerTransactions) > 0 { + return process.ErrMultipleRelayedTxTypesIsNotAllowed + } + userTx, err := createTx(inTx.signMarshalizer, userTxArgs[0]) if err != nil { return fmt.Errorf("inner transaction: %w", err) diff --git a/process/transaction/interceptedTransaction_test.go b/process/transaction/interceptedTransaction_test.go index 983028e3ae1..cac68e3c288 100644 --- a/process/transaction/interceptedTransaction_test.go +++ b/process/transaction/interceptedTransaction_test.go @@ -1602,6 +1602,14 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTx(t *testing.T) { err = txi.CheckValidity() assert.True(t, strings.Contains(err.Error(), process.ErrRecursiveRelayedTxIsNotAllowed.Error())) assert.Contains(t, err.Error(), "inner transaction") + + userTx.Data = []byte("") + userTxData, _ = marshalizer.Marshal(userTx) + tx.Data = []byte(core.RelayedTransaction + "@" + hex.EncodeToString(userTxData)) + tx.InnerTransactions = []*dataTransaction.Transaction{{Nonce: 100}} + txi, _ = createInterceptedTxFromPlainTxWithArgParser(tx) + err = txi.CheckValidity() + assert.True(t, strings.Contains(err.Error(), process.ErrMultipleRelayedTxTypesIsNotAllowed.Error())) } func TestInterceptedTransaction_CheckValidityOfRelayedTxV2(t *testing.T) { @@ -1665,6 +1673,16 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV2(t *testing.T) { assert.True(t, strings.Contains(err.Error(), process.ErrRecursiveRelayedTxIsNotAllowed.Error())) assert.Contains(t, err.Error(), "inner transaction") + userTx.Data = []byte("") + marshalizer := &mock.MarshalizerMock{} + userTxData, _ := marshalizer.Marshal(userTx) + tx.Data = []byte(core.RelayedTransactionV2 + "@" + hex.EncodeToString(userTxData)) + tx.InnerTransactions = []*dataTransaction.Transaction{{Nonce: 100}} + txi, _ = createInterceptedTxFromPlainTxWithArgParser(tx) + err = txi.CheckValidity() + assert.True(t, strings.Contains(err.Error(), process.ErrMultipleRelayedTxTypesIsNotAllowed.Error())) + + tx.InnerTransactions = nil userTx.Signature = sigOk userTx.SndAddr = []byte("otherAddress") tx.Data = []byte(core.RelayedTransactionV2 + "@" + hex.EncodeToString(userTx.RcvAddr) + "@" + hex.EncodeToString(big.NewInt(0).SetUint64(userTx.Nonce).Bytes()) + "@" + hex.EncodeToString(userTx.Data) + "@" + hex.EncodeToString(userTx.Signature)) @@ -1793,7 +1811,6 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { err := txi.CheckValidity() assert.NotNil(t, err) }) - t.Run("relayed v3 not enabled yet should error", func(t *testing.T) { t.Parallel() @@ -1830,6 +1847,19 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { err := txi.CheckValidity() assert.Equal(t, process.ErrRelayedTxV3Disabled, err) }) + t.Run("inner txs + relayed v2 should error", func(t *testing.T) { + t.Parallel() + + txCopy := *tx + innerTxCopy := *innerTx + txCopy.InnerTransactions = []*dataTransaction.Transaction{&innerTxCopy} + marshaller := &marshallerMock.MarshalizerMock{} + userTxData, _ := marshaller.Marshal(innerTxCopy) + txCopy.Data = []byte(core.RelayedTransaction + "@" + hex.EncodeToString(userTxData)) + txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) + err := txi.CheckValidity() + assert.Equal(t, process.ErrMultipleRelayedTxTypesIsNotAllowed, err) + }) } // ------- IsInterfaceNil diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 0990335ee2a..ae0fb9494af 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -662,7 +662,12 @@ func (txProc *txProcessor) processRelayedTxV3( if check.IfNil(relayerAcnt) { return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrNilRelayerAccount) } - err := txProc.relayedTxV3Processor.CheckRelayedTx(tx) + funcName, _, err := txProc.argsParser.ParseCallData(string(tx.Data)) + if err == nil && isRelayedTx(funcName) { + return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrMultipleRelayedTxTypesIsNotAllowed) + } + + err = txProc.relayedTxV3Processor.CheckRelayedTx(tx) if err != nil { return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, err) } @@ -786,6 +791,10 @@ func (txProc *txProcessor) processRelayedTxV2( return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrInvalidArguments) } + if len(tx.InnerTransactions) > 0 { + return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrMultipleRelayedTxTypesIsNotAllowed) + } + userTx := makeUserTxFromRelayedTxV2Args(args) userTx.GasPrice = tx.GasPrice userTx.GasLimit = tx.GasLimit - txProc.economicsFee.ComputeGasLimit(tx) @@ -809,6 +818,9 @@ func (txProc *txProcessor) processRelayedTx( if !txProc.enableEpochsHandler.IsFlagEnabled(common.RelayedTransactionsFlag) { return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedTxDisabled) } + if len(tx.InnerTransactions) > 0 { + return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrMultipleRelayedTxTypesIsNotAllowed) + } userTx := &transaction.Transaction{} err = txProc.signMarshalizer.Unmarshal(userTx, args[0]) @@ -970,6 +982,10 @@ func (txProc *txProcessor) processUserTx( switch txType { case process.MoveBalance: err = txProc.processMoveBalance(userTx, acntSnd, acntDst, dstShardTxType, originalTxHash, true) + isUserTxOfRelayedV3 := len(originalTx.InnerTransactions) > 0 + if err == nil && isUserTxOfRelayedV3 { + txProc.createCompleteEventLog(scrFromTx, originalTxHash) + } case process.SCDeployment: err = txProc.processMoveBalanceCostRelayedUserTx(userTx, scrFromTx, acntSnd, originalTxHash) if err != nil { @@ -1175,6 +1191,19 @@ func isNonExecutableError(executionErr error) bool { errors.Is(executionErr, process.ErrTransactionNotExecutable) } +func (txProc *txProcessor) createCompleteEventLog(scr data.TransactionHandler, originalTxHash []byte) { + completedTxLog := &vmcommon.LogEntry{ + Identifier: []byte(core.CompletedTxEventIdentifier), + Address: scr.GetRcvAddr(), + Topics: [][]byte{originalTxHash}, + } + + ignorableError := txProc.txLogsProcessor.SaveLog(originalTxHash, scr, []*vmcommon.LogEntry{completedTxLog}) + if ignorableError != nil { + log.Debug("txProcessor.createCompleteEventLog txLogsProcessor.SaveLog()", "error", ignorableError.Error()) + } +} + // IsInterfaceNil returns true if there is no value under the interface func (txProc *txProcessor) IsInterfaceNil() bool { return txProc == nil diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index 6114e57ee0b..f8d8ccd7249 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -2178,6 +2178,15 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { txCopy.GasLimit = userTx.GasLimit - 1 testProcessRelayedTransactionV3(t, &txCopy, userTx.SndAddr, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) }) + t.Run("multiple types of relayed tx should error", func(t *testing.T) { + t.Parallel() + + txCopy := *tx + userTxCopy := *userTx + userTxData, _ := marshaller.Marshal(userTxCopy) + txCopy.Data = []byte(core.RelayedTransaction + "@" + hex.EncodeToString(userTxData)) + testProcessRelayedTransactionV3(t, &txCopy, userTx.SndAddr, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) + }) t.Run("failure to add fees on destination should skip transaction and continue", func(t *testing.T) { t.Parallel() @@ -2237,6 +2246,13 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { ShardCoordinator: args.ShardCoordinator, MaxTransactionsAllowed: 10, }) + logs := make([]*vmcommon.LogEntry, 0) + args.TxLogsProcessor = &mock.TxLogsProcessorStub{ + SaveLogCalled: func(txHash []byte, tx data.TransactionHandler, vmLogs []*vmcommon.LogEntry) error { + logs = append(logs, vmLogs...) + return nil + }, + } execTx, _ := txproc.NewTxProcessor(args) txCopy := *tx @@ -2288,6 +2304,11 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { assert.Equal(t, expectedBalance, acnt.GetBalance(), fmt.Sprintf("checks failed for address: %s", string(acnt.AddressBytes()))) } + + require.Equal(t, 2, len(logs)) + for _, log := range logs { + require.Equal(t, core.CompletedTxEventIdentifier, string(log.Identifier)) + } }) t.Run("one inner fails should return success on relayed", func(t *testing.T) { t.Parallel() From 1a64dd8823314cc5c35424962779742c0988898e Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 28 May 2024 15:52:33 +0300 Subject: [PATCH 267/503] added token issue operation --- .../vm/esdtImprovements_test.go | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 858aab3fe60..2f474c0e1d0 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -3,6 +3,7 @@ package vm import ( "bytes" "encoding/hex" + "fmt" "math/big" "testing" "time" @@ -63,7 +64,9 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { Value: 20, } - activationEpoch := uint32(2) + activationEpoch := uint32(4) + + baseIssuingCost := "1000" numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ @@ -83,6 +86,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { NumNodesWaitingListShard: 0, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost }, }) require.Nil(t, err) @@ -101,8 +105,29 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Initial setup: Create an NFT and an SFT (before the activation of DynamicEsdtFlag)") - tokenID := []byte("ASD-d31313") - tokenType := core.DynamicNFTESDT + arguments := [][]byte{ + []byte("asdname"), + []byte("ASD"), + // big.NewInt(0).Bytes(), + // big.NewInt(10).Bytes(), + } + + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + + output, _, err := cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ExecuteSCQuery(&process.SCQuery{ + ScAddress: vm.ESDTSCAddress, + FuncName: "issueNonFungible", + Arguments: arguments, + CallValue: callValue, + }) + require.Nil(t, err) + require.Equal(t, "", output.ReturnMessage) + require.Equal(t, "ok", output.ReturnCode) + + require.NotNil(t, output.ReturnData[0]) + tokenID := output.ReturnData[0] + + fmt.Println(string(tokenID)) roles := [][]byte{ []byte(core.ESDTMetaDataRecreate), @@ -114,6 +139,8 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { } setAddressEsdtRoles(t, cs, address, tokenID, roles) + tokenType := core.DynamicNFTESDT + txDataField := bytes.Join( [][]byte{ []byte(core.ESDTSetTokenType), @@ -241,7 +268,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 5. make an updateTokenID@tokenID function call on the ESDTSystem SC for all token types") - output, err := executeQuery(cs, core.MetachainShardId, vm.ESDTSCAddress, "updateTokenID", [][]byte{tokenID}) + output, err = executeQuery(cs, core.MetachainShardId, vm.ESDTSCAddress, "updateTokenID", [][]byte{[]byte(hex.EncodeToString(tokenID))}) require.Nil(t, err) require.Equal(t, "", output.ReturnMessage) require.Equal(t, vmcommon.Ok, output.ReturnCode) From 89e9fad8883ca8f5cc405ea3c30a04abd2d567f7 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 28 May 2024 16:29:27 +0300 Subject: [PATCH 268/503] display inner transactions on response of transaction endpoint --- go.mod | 2 +- go.sum | 4 +- node/external/transactionAPI/unmarshaller.go | 100 +++++++++++++------ process/transactionLog/process.go | 16 ++- 4 files changed, 87 insertions(+), 35 deletions(-) diff --git a/go.mod b/go.mod index 2dd782cc25c..28a805eb7b1 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e - github.com/multiversx/mx-chain-core-go v1.2.21-0.20240515142458-bb09ab417156 + github.com/multiversx/mx-chain-core-go v1.2.21-0.20240528132712-8b6faa711b23 github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df github.com/multiversx/mx-chain-es-indexer-go v1.7.1-0.20240509104512-25512675833d github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 diff --git a/go.sum b/go.sum index 6cdd0173967..04d4f367781 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY 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.20240515142458-bb09ab417156 h1:Lzm7USVM1b6h1OsizXYjVOiqX9USwaOuNCegkcAlFJM= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240515142458-bb09ab417156/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240528132712-8b6faa711b23 h1:jSP8BjMF9P5I9cO5hY2uN60q4+iPP9uq5WzETtcXWMI= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240528132712-8b6faa711b23/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.1-0.20240509104512-25512675833d h1:GD1D8V0bE6hDLjrduSsMwQwwf6PMq2Zww7FYMfJsuiw= diff --git a/node/external/transactionAPI/unmarshaller.go b/node/external/transactionAPI/unmarshaller.go index 197f4d53a46..2b56518e506 100644 --- a/node/external/transactionAPI/unmarshaller.go +++ b/node/external/transactionAPI/unmarshaller.go @@ -111,21 +111,22 @@ func (tu *txUnmarshaller) prepareNormalTx(tx *transaction.Transaction) *transact senderAddress := tu.addressPubKeyConverter.SilentEncode(tx.SndAddr, log) apiTx := &transaction.ApiTransactionResult{ - Tx: tx, - Type: string(transaction.TxTypeNormal), - Nonce: tx.Nonce, - Value: tx.Value.String(), - Receiver: receiverAddress, - ReceiverUsername: tx.RcvUserName, - Sender: senderAddress, - SenderUsername: tx.SndUserName, - GasPrice: tx.GasPrice, - GasLimit: tx.GasLimit, - Data: tx.Data, - Signature: hex.EncodeToString(tx.Signature), - Options: tx.Options, - Version: tx.Version, - ChainID: string(tx.ChainID), + Tx: tx, + Type: string(transaction.TxTypeNormal), + Nonce: tx.Nonce, + Value: tx.Value.String(), + Receiver: receiverAddress, + ReceiverUsername: tx.RcvUserName, + Sender: senderAddress, + SenderUsername: tx.SndUserName, + GasPrice: tx.GasPrice, + GasLimit: tx.GasLimit, + Data: tx.Data, + Signature: hex.EncodeToString(tx.Signature), + Options: tx.Options, + Version: tx.Version, + ChainID: string(tx.ChainID), + InnerTransactions: tu.prepareInnerTxs(tx), } if len(tx.GuardianAddr) > 0 { @@ -140,26 +141,65 @@ func (tu *txUnmarshaller) prepareNormalTx(tx *transaction.Transaction) *transact return apiTx } +func (tu *txUnmarshaller) prepareInnerTxs(tx *transaction.Transaction) []*transaction.FrontendTransaction { + if len(tx.InnerTransactions) == 0 { + return nil + } + + innerTxs := make([]*transaction.FrontendTransaction, 0, len(tx.InnerTransactions)) + for _, innerTx := range tx.InnerTransactions { + frontEndTx := &transaction.FrontendTransaction{ + Nonce: innerTx.Nonce, + Value: innerTx.Value.String(), + Receiver: tu.addressPubKeyConverter.SilentEncode(innerTx.RcvAddr, log), + Sender: tu.addressPubKeyConverter.SilentEncode(innerTx.SndAddr, log), + SenderUsername: innerTx.SndUserName, + ReceiverUsername: innerTx.RcvUserName, + GasPrice: innerTx.GasPrice, + GasLimit: innerTx.GasLimit, + Data: innerTx.Data, + Signature: hex.EncodeToString(innerTx.Signature), + ChainID: string(innerTx.ChainID), + Version: innerTx.Version, + Options: innerTx.Options, + } + + if len(tx.GuardianAddr) > 0 { + frontEndTx.GuardianAddr = tu.addressPubKeyConverter.SilentEncode(innerTx.GuardianAddr, log) + frontEndTx.GuardianSignature = hex.EncodeToString(innerTx.GuardianSignature) + } + + if len(tx.RelayerAddr) > 0 { + frontEndTx.Relayer = tu.addressPubKeyConverter.SilentEncode(innerTx.RelayerAddr, log) + } + + innerTxs = append(innerTxs, frontEndTx) + } + + return innerTxs +} + func (tu *txUnmarshaller) prepareInvalidTx(tx *transaction.Transaction) *transaction.ApiTransactionResult { receiverAddress := tu.addressPubKeyConverter.SilentEncode(tx.RcvAddr, log) senderAddress := tu.addressPubKeyConverter.SilentEncode(tx.SndAddr, log) apiTx := &transaction.ApiTransactionResult{ - Tx: tx, - Type: string(transaction.TxTypeInvalid), - Nonce: tx.Nonce, - Value: tx.Value.String(), - Receiver: receiverAddress, - ReceiverUsername: tx.RcvUserName, - Sender: senderAddress, - SenderUsername: tx.SndUserName, - GasPrice: tx.GasPrice, - GasLimit: tx.GasLimit, - Data: tx.Data, - Signature: hex.EncodeToString(tx.Signature), - Options: tx.Options, - Version: tx.Version, - ChainID: string(tx.ChainID), + Tx: tx, + Type: string(transaction.TxTypeInvalid), + Nonce: tx.Nonce, + Value: tx.Value.String(), + Receiver: receiverAddress, + ReceiverUsername: tx.RcvUserName, + Sender: senderAddress, + SenderUsername: tx.SndUserName, + GasPrice: tx.GasPrice, + GasLimit: tx.GasLimit, + Data: tx.Data, + Signature: hex.EncodeToString(tx.Signature), + Options: tx.Options, + Version: tx.Version, + ChainID: string(tx.ChainID), + InnerTransactions: tu.prepareInnerTxs(tx), } if len(tx.GuardianAddr) > 0 { diff --git a/process/transactionLog/process.go b/process/transactionLog/process.go index ae243a9930e..bdac14d542a 100644 --- a/process/transactionLog/process.go +++ b/process/transactionLog/process.go @@ -2,6 +2,7 @@ package transactionLog import ( "encoding/hex" + "strings" "sync" "github.com/multiversx/mx-chain-core-go/core" @@ -171,8 +172,7 @@ func (tlp *txLogProcessor) SaveLog(txHash []byte, tx data.TransactionHandler, lo func (tlp *txLogProcessor) appendLogToStorer(txHash []byte, newLog *transaction.Log) error { oldLogsBuff, errGet := tlp.storer.Get(txHash) - nilStorerResponse := errGet == nil && len(oldLogsBuff) == 0 - if errGet == storage.ErrKeyNotFound || nilStorerResponse { + if isFirstEntryForHash(oldLogsBuff, errGet) { allLogsBuff, err := tlp.marshalizer.Marshal(newLog) if err != nil { return err @@ -203,6 +203,18 @@ func (tlp *txLogProcessor) appendLogToStorer(txHash []byte, newLog *transaction. return tlp.storer.Put(txHash, allLogsBuff) } +func isFirstEntryForHash(oldLogsBuff []byte, errGet error) bool { + if errGet == nil && len(oldLogsBuff) == 0 { + return true + } + + if errGet == nil { + return false + } + + return strings.Contains(errGet.Error(), "not found") +} + func (tlp *txLogProcessor) saveLogToCache(txHash []byte, log *transaction.Log) { tlp.logs = append(tlp.logs, &data.LogData{ TxHash: string(txHash), From fe92cc49b0c96fc0a895a31e3a2eb4bb854fbef8 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 29 May 2024 11:40:44 +0300 Subject: [PATCH 269/503] use txs instead of sc query --- .../vm/esdtImprovements_test.go | 131 ++++++++++++------ 1 file changed, 86 insertions(+), 45 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 2f474c0e1d0..9fecfbab0b2 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -24,7 +24,6 @@ import ( "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/vm" logger "github.com/multiversx/mx-chain-logger-go" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/stretchr/testify/require" ) @@ -105,29 +104,41 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Initial setup: Create an NFT and an SFT (before the activation of DynamicEsdtFlag)") - arguments := [][]byte{ - []byte("asdname"), - []byte("ASD"), - // big.NewInt(0).Bytes(), - // big.NewInt(10).Bytes(), - } - callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) - output, _, err := cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ExecuteSCQuery(&process.SCQuery{ - ScAddress: vm.ESDTSCAddress, - FuncName: "issueNonFungible", - Arguments: arguments, - CallValue: callValue, - }) + txDataField := bytes.Join( + [][]byte{ + []byte("issueNonFungible"), + []byte(hex.EncodeToString([]byte("asdname"))), + []byte(hex.EncodeToString([]byte("ASD"))), + }, + []byte("@"), + ) + + tx := &transaction.Transaction{ + Nonce: 0, + SndAddr: address.Bytes, + RcvAddr: core.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: callValue, + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) - require.Equal(t, "", output.ReturnMessage) - require.Equal(t, "ok", output.ReturnCode) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) - require.NotNil(t, output.ReturnData[0]) - tokenID := output.ReturnData[0] + fmt.Println(txResult) + fmt.Println(txResult.Logs.Events[0]) + fmt.Println(txResult.Logs.Events[0].Identifier) + tokenID := txResult.Logs.Events[0].Topics[0] - fmt.Println(string(tokenID)) + log.Info("Issued token id", "tokenID", string(tokenID)) roles := [][]byte{ []byte(core.ESDTMetaDataRecreate), @@ -141,7 +152,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { tokenType := core.DynamicNFTESDT - txDataField := bytes.Join( + txDataField = bytes.Join( [][]byte{ []byte(core.ESDTSetTokenType), []byte(hex.EncodeToString(tokenID)), @@ -150,7 +161,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { []byte("@"), ) - tx := &transaction.Transaction{ + tx = &transaction.Transaction{ Nonce: 0, SndAddr: core.ESDTSCAddress, RcvAddr: address.Bytes, @@ -186,7 +197,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { ) tx = &transaction.Transaction{ - Nonce: 0, + Nonce: 1, SndAddr: address.Bytes, RcvAddr: address.Bytes, GasLimit: 10_000_000, @@ -198,7 +209,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { Version: 1, } - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -233,24 +244,29 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { address2, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - tx = utils.CreateESDTNFTTransferTx( - 1, - address.Bytes, - address2.Bytes, - tokenID, - 1, - big.NewInt(1), - minGasPrice, - 10_000_000, - "", - ) - tx.Version = 1 - tx.Signature = []byte("dummySig") - tx.ChainID = []byte(configs.ChainID) - - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) + // tx = utils.CreateESDTNFTTransferTx( + // 2, + // address.Bytes, + // address2.Bytes, + // tokenID, + // 1, + // big.NewInt(1), + // minGasPrice, + // 10_000_000, + // "", + // ) + // tx.Version = 1 + // tx.Signature = []byte("dummySig") + // tx.ChainID = []byte(configs.ChainID) + + // txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + // require.Nil(t, err) + // require.NotNil(t, txResult) + + // fmt.Println(txResult.Logs.Events[0]) + // fmt.Println(txResult.Logs.Events[0].Topics[0]) + // fmt.Println(txResult.Logs.Events[0].Topics[1]) + // fmt.Println(string(txResult.Logs.Events[0].Topics[1])) require.Equal(t, "success", txResult.Status.String()) @@ -268,10 +284,31 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 5. make an updateTokenID@tokenID function call on the ESDTSystem SC for all token types") - output, err = executeQuery(cs, core.MetachainShardId, vm.ESDTSCAddress, "updateTokenID", [][]byte{[]byte(hex.EncodeToString(tokenID))}) + txDataField = []byte("updateTokenID@" + hex.EncodeToString(tokenID)) + + tx = &transaction.Transaction{ + Nonce: 2, + SndAddr: address.Bytes, + RcvAddr: vm.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) - require.Equal(t, "", output.ReturnMessage) - require.Equal(t, vmcommon.Ok, output.ReturnCode) + require.NotNil(t, txResult) + + fmt.Println(txResult.Logs.Events[0]) + fmt.Println(txResult.Logs.Events[0].Topics[0]) + fmt.Println(txResult.Logs.Events[0].Topics[1]) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) log.Info("Step 6. check that the metadata for all tokens is saved on the system account") @@ -288,7 +325,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 7. transfer the tokens to another account") tx = utils.CreateESDTNFTTransferTx( - 1, + 3, address.Bytes, address2.Bytes, tokenID, @@ -306,6 +343,10 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) + fmt.Println(txResult.Logs.Events[0]) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + require.Equal(t, "success", txResult.Status.String()) log.Info("Step 8. check that the metaData for the NFT was removed from the system account and moved to the user account") From 8b25763fa9d45baa20e8193fd39ce18dbd682bef Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 29 May 2024 11:53:06 +0300 Subject: [PATCH 270/503] add address3 --- .../vm/esdtImprovements_test.go | 59 ++++++++++--------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 9fecfbab0b2..267f6f4ec0d 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -244,29 +244,32 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { address2, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - // tx = utils.CreateESDTNFTTransferTx( - // 2, - // address.Bytes, - // address2.Bytes, - // tokenID, - // 1, - // big.NewInt(1), - // minGasPrice, - // 10_000_000, - // "", - // ) - // tx.Version = 1 - // tx.Signature = []byte("dummySig") - // tx.ChainID = []byte(configs.ChainID) - - // txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) - // require.Nil(t, err) - // require.NotNil(t, txResult) - - // fmt.Println(txResult.Logs.Events[0]) - // fmt.Println(txResult.Logs.Events[0].Topics[0]) - // fmt.Println(txResult.Logs.Events[0].Topics[1]) - // fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + address3, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) + require.Nil(t, err) + + tx = utils.CreateESDTNFTTransferTx( + 2, + address.Bytes, + address2.Bytes, + tokenID, + 1, + big.NewInt(1), + minGasPrice, + 10_000_000, + "", + ) + tx.Version = 1 + tx.Signature = []byte("dummySig") + tx.ChainID = []byte(configs.ChainID) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult.Logs.Events[0]) + fmt.Println(txResult.Logs.Events[0].Topics[0]) + fmt.Println(txResult.Logs.Events[0].Topics[1]) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) require.Equal(t, "success", txResult.Status.String()) @@ -287,7 +290,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { txDataField = []byte("updateTokenID@" + hex.EncodeToString(tokenID)) tx = &transaction.Transaction{ - Nonce: 2, + Nonce: 3, SndAddr: address.Bytes, RcvAddr: vm.ESDTSCAddress, GasLimit: 100_000_000, @@ -325,9 +328,9 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 7. transfer the tokens to another account") tx = utils.CreateESDTNFTTransferTx( - 3, - address.Bytes, + 0, address2.Bytes, + address3.Bytes, tokenID, 1, big.NewInt(1), @@ -351,9 +354,9 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 8. check that the metaData for the NFT was removed from the system account and moved to the user account") - shardID2 := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address2.Bytes) + shardID3 := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address3.Bytes) - retrievedMetaData = getMetaDataFromAcc(t, cs, address2.Bytes, tokenID, shardID2) + retrievedMetaData = getMetaDataFromAcc(t, cs, address3.Bytes, tokenID, shardID3) require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) From ed646eb9006d6bf6dccc74223387e56250a34cf5 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 29 May 2024 12:49:59 +0300 Subject: [PATCH 271/503] added multiple shards --- .../vm/esdtImprovements_test.go | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 267f6f4ec0d..51c150b20e7 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -96,7 +96,11 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { mintValue := big.NewInt(10) mintValue = mintValue.Mul(staking.OneEGLD, mintValue) - address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) + shardID0 := uint32(0) + shardID1 := uint32(1) + shardID2 := uint32(2) + + address, err := cs.GenerateAndMintWalletAddress(shardID0, mintValue) require.Nil(t, err) err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch) - 1) @@ -136,6 +140,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { fmt.Println(txResult) fmt.Println(txResult.Logs.Events[0]) fmt.Println(txResult.Logs.Events[0].Identifier) + tokenID := txResult.Logs.Events[0].Topics[0] log.Info("Issued token id", "tokenID", string(tokenID)) @@ -217,11 +222,9 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { err = cs.GenerateBlocks(10) require.Nil(t, err) - shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) - log.Info("Step 1. check that the metadata for all tokens is saved on the system account") - retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) + retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID0) require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) @@ -241,10 +244,10 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 3. transfer the tokens to another account") - address2, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) + address2, err := cs.GenerateAndMintWalletAddress(shardID1, mintValue) require.Nil(t, err) - address3, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) + address3, err := cs.GenerateAndMintWalletAddress(shardID2, mintValue) require.Nil(t, err) tx = utils.CreateESDTNFTTransferTx( @@ -275,7 +278,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 4. check that the metadata for all tokens is saved on the system account") - retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) + retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID0) require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) @@ -315,7 +318,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 6. check that the metadata for all tokens is saved on the system account") - retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) + retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID0) require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) @@ -354,9 +357,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 8. check that the metaData for the NFT was removed from the system account and moved to the user account") - shardID3 := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address3.Bytes) - - retrievedMetaData = getMetaDataFromAcc(t, cs, address3.Bytes, tokenID, shardID3) + retrievedMetaData = getMetaDataFromAcc(t, cs, address3.Bytes, tokenID, shardID2) require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) From 81b2a33912b399244eefd28055e554a50fb86d77 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 29 May 2024 13:02:28 +0300 Subject: [PATCH 272/503] intra shard txs --- .../chainSimulator/vm/esdtImprovements_test.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 51c150b20e7..0150bcacc15 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -96,11 +96,9 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { mintValue := big.NewInt(10) mintValue = mintValue.Mul(staking.OneEGLD, mintValue) - shardID0 := uint32(0) - shardID1 := uint32(1) - shardID2 := uint32(2) + shardID := uint32(1) - address, err := cs.GenerateAndMintWalletAddress(shardID0, mintValue) + address, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) require.Nil(t, err) err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch) - 1) @@ -224,7 +222,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 1. check that the metadata for all tokens is saved on the system account") - retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID0) + retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) @@ -244,10 +242,10 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 3. transfer the tokens to another account") - address2, err := cs.GenerateAndMintWalletAddress(shardID1, mintValue) + address2, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) require.Nil(t, err) - address3, err := cs.GenerateAndMintWalletAddress(shardID2, mintValue) + address3, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) require.Nil(t, err) tx = utils.CreateESDTNFTTransferTx( @@ -278,7 +276,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 4. check that the metadata for all tokens is saved on the system account") - retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID0) + retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) @@ -318,7 +316,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 6. check that the metadata for all tokens is saved on the system account") - retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID0) + retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) @@ -357,7 +355,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 8. check that the metaData for the NFT was removed from the system account and moved to the user account") - retrievedMetaData = getMetaDataFromAcc(t, cs, address3.Bytes, tokenID, shardID2) + retrievedMetaData = getMetaDataFromAcc(t, cs, address3.Bytes, tokenID, shardID) require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) From ea84a25a5ad8aef6cc91c43277b10b803d259aea Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 29 May 2024 18:13:48 +0300 Subject: [PATCH 273/503] added sft token checks --- .../vm/esdtImprovements_test.go | 427 +++++++++++------- 1 file changed, 274 insertions(+), 153 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 0150bcacc15..1e71c1df27e 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -37,7 +37,8 @@ var log = logger.GetOrCreate("integrationTests/chainSimulator/vm") // Test scenario // -// Initial setup: Create an NFT and an SFT (before the activation of DynamicEsdtFlag) +// Initial setup: Create fungible, NFT, SFT and metaESDT tokens +// (before the activation of DynamicEsdtFlag) // // 1.check that the metadata for all tokens is saved on the system account // 2. wait for DynamicEsdtFlag activation @@ -104,31 +105,11 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch) - 1) require.Nil(t, err) - log.Info("Initial setup: Create an NFT and an SFT (before the activation of DynamicEsdtFlag)") + log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (before the activation of DynamicEsdtFlag)") - callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) - - txDataField := bytes.Join( - [][]byte{ - []byte("issueNonFungible"), - []byte(hex.EncodeToString([]byte("asdname"))), - []byte(hex.EncodeToString([]byte("ASD"))), - }, - []byte("@"), - ) - - tx := &transaction.Transaction{ - Nonce: 0, - SndAddr: address.Bytes, - RcvAddr: core.ESDTSCAddress, - GasLimit: 100_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: callValue, - ChainID: []byte(configs.ChainID), - Version: 1, - } + // issue NFT + nftTicker := []byte("NFTTICKER") + tx := issueNonFungibleTx(address.Bytes, nftTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -139,43 +120,38 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { fmt.Println(txResult.Logs.Events[0]) fmt.Println(txResult.Logs.Events[0].Identifier) - tokenID := txResult.Logs.Events[0].Topics[0] - - log.Info("Issued token id", "tokenID", string(tokenID)) + nftTokenID := txResult.Logs.Events[0].Topics[0] roles := [][]byte{ - []byte(core.ESDTMetaDataRecreate), []byte(core.ESDTRoleNFTCreate), - []byte(core.ESDTRoleNFTBurn), []byte(core.ESDTRoleTransfer), - []byte(core.ESDTRoleNFTUpdateAttributes), - []byte(core.ESDTRoleNFTAddURI), } - setAddressEsdtRoles(t, cs, address, tokenID, roles) + setAddressEsdtRoles(t, cs, address, nftTokenID, roles) - tokenType := core.DynamicNFTESDT + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) - txDataField = bytes.Join( - [][]byte{ - []byte(core.ESDTSetTokenType), - []byte(hex.EncodeToString(tokenID)), - []byte(hex.EncodeToString([]byte(tokenType))), - }, - []byte("@"), - ) + // issue SFT + sftTicker := []byte("SFTTICKER") + tx = issueSemiFungibleTx(1, address.Bytes, sftTicker, baseIssuingCost) - tx = &transaction.Transaction{ - Nonce: 0, - SndAddr: core.ESDTSCAddress, - RcvAddr: address.Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + fmt.Println(txResult) + fmt.Println(txResult.Logs.Events[0]) + fmt.Println(txResult.Logs.Events[0].Identifier) + + sftTokenID := txResult.Logs.Events[0].Topics[0] + + roles = [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), } + setAddressEsdtRoles(t, cs, address, sftTokenID, roles) + + log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) name := []byte(hex.EncodeToString([]byte("name"))) @@ -185,36 +161,33 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { expUris := [][]byte{[]byte(hex.EncodeToString([]byte("uri")))} - txDataField = bytes.Join( - [][]byte{ - []byte(core.BuiltInFunctionESDTNFTCreate), - []byte(hex.EncodeToString(tokenID)), - []byte(hex.EncodeToString(big.NewInt(1).Bytes())), // quantity - name, - []byte(hex.EncodeToString(big.NewInt(10).Bytes())), - hash, - attributes, - uris, - }, - []byte("@"), - ) + tx = nftCreateTx(2, address.Bytes, nftTokenID, name, hash, attributes, uris) - tx = &transaction.Transaction{ - Nonce: 1, - SndAddr: address.Bytes, - RcvAddr: address.Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, - } + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + name1 := []byte(hex.EncodeToString([]byte("name1"))) + hash1 := []byte(hex.EncodeToString([]byte("hash1"))) + attributes1 := []byte(hex.EncodeToString([]byte("attributes1"))) + uris1 := []byte(hex.EncodeToString([]byte("uri1"))) + + expUris1 := [][]byte{[]byte(hex.EncodeToString([]byte("uri1")))} + + tx = nftCreateTx(3, address.Bytes, sftTokenID, name1, hash1, attributes1, uris1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) + + fmt.Println(txResult) + fmt.Println(txResult.Logs.Events[0]) + fmt.Println(txResult.Logs.Events[0].Topics[0]) + fmt.Println(txResult.Logs.Events[0].Topics[1]) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + require.Equal(t, "success", txResult.Status.String()) err = cs.GenerateBlocks(10) @@ -222,7 +195,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 1. check that the metadata for all tokens is saved on the system account") - retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) + retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) @@ -232,6 +205,16 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { } require.Equal(t, attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) + retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, sftTokenID, shardID) + + require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) + require.Equal(t, name1, []byte(hex.EncodeToString(retrievedMetaData.Name))) + require.Equal(t, hash1, []byte(hex.EncodeToString(retrievedMetaData.Hash))) + for i, uri := range expUris1 { + require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) + } + require.Equal(t, attributes1, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) + log.Info("Step 2. wait for DynamicEsdtFlag activation") err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) @@ -249,10 +232,36 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { require.Nil(t, err) tx = utils.CreateESDTNFTTransferTx( - 2, + 4, + address.Bytes, + address2.Bytes, + nftTokenID, + 1, + big.NewInt(1), + minGasPrice, + 10_000_000, + "", + ) + tx.Version = 1 + tx.Signature = []byte("dummySig") + tx.ChainID = []byte(configs.ChainID) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult.Logs.Events[0]) + fmt.Println(txResult.Logs.Events[0].Topics[0]) + fmt.Println(txResult.Logs.Events[0].Topics[1]) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) + + tx = utils.CreateESDTNFTTransferTx( + 5, address.Bytes, address2.Bytes, - tokenID, + sftTokenID, 1, big.NewInt(1), minGasPrice, @@ -276,7 +285,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 4. check that the metadata for all tokens is saved on the system account") - retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) + retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) @@ -286,22 +295,32 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { } require.Equal(t, attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) + retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, sftTokenID, shardID) + + require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) + require.Equal(t, name1, []byte(hex.EncodeToString(retrievedMetaData.Name))) + require.Equal(t, hash1, []byte(hex.EncodeToString(retrievedMetaData.Hash))) + for i, uri := range expUris1 { + require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) + } + require.Equal(t, attributes1, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) + log.Info("Step 5. make an updateTokenID@tokenID function call on the ESDTSystem SC for all token types") - txDataField = []byte("updateTokenID@" + hex.EncodeToString(tokenID)) + tx = updateTokenIDTx(6, address.Bytes, nftTokenID) - tx = &transaction.Transaction{ - Nonce: 3, - SndAddr: address.Bytes, - RcvAddr: vm.ESDTSCAddress, - GasLimit: 100_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, - } + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult.Logs.Events[0]) + fmt.Println(txResult.Logs.Events[0].Topics[0]) + fmt.Println(txResult.Logs.Events[0].Topics[1]) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) + + tx = updateTokenIDTx(7, address.Bytes, sftTokenID) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -316,7 +335,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 6. check that the metadata for all tokens is saved on the system account") - retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) + retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) @@ -326,13 +345,48 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { } require.Equal(t, attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) + retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, sftTokenID, shardID) + + require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) + require.Equal(t, name1, []byte(hex.EncodeToString(retrievedMetaData.Name))) + require.Equal(t, hash1, []byte(hex.EncodeToString(retrievedMetaData.Hash))) + for i, uri := range expUris1 { + require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) + } + require.Equal(t, attributes1, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) + log.Info("Step 7. transfer the tokens to another account") tx = utils.CreateESDTNFTTransferTx( 0, address2.Bytes, address3.Bytes, - tokenID, + nftTokenID, + 1, + big.NewInt(1), + minGasPrice, + 10_000_000, + "", + ) + tx.Version = 1 + tx.Signature = []byte("dummySig") + tx.ChainID = []byte(configs.ChainID) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult.Logs.Events[0]) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) + + tx = utils.CreateESDTNFTTransferTx( + 1, + address2.Bytes, + address3.Bytes, + sftTokenID, 1, big.NewInt(1), minGasPrice, @@ -355,7 +409,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 8. check that the metaData for the NFT was removed from the system account and moved to the user account") - retrievedMetaData = getMetaDataFromAcc(t, cs, address3.Bytes, tokenID, shardID) + retrievedMetaData = getMetaDataFromAcc(t, cs, address3.Bytes, nftTokenID, shardID) require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) @@ -364,6 +418,121 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) } require.Equal(t, attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) + + log.Info("Step 9. check that the metaData for the rest of the tokens is still present on the system account and not on the userAccount") + + retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, sftTokenID, shardID) + + require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) + require.Equal(t, name1, []byte(hex.EncodeToString(retrievedMetaData.Name))) + require.Equal(t, hash1, []byte(hex.EncodeToString(retrievedMetaData.Hash))) + for i, uri := range expUris1 { + require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) + } + require.Equal(t, attributes1, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) +} + +func issueNonFungibleTx(sndAdr []byte, ticker []byte, baseIssuingCost string) *transaction.Transaction { + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + + txDataField := bytes.Join( + [][]byte{ + []byte("issueNonFungible"), + []byte(hex.EncodeToString([]byte("asdname"))), + []byte(hex.EncodeToString(ticker)), + }, + []byte("@"), + ) + + return &transaction.Transaction{ + Nonce: 0, + SndAddr: sndAdr, + RcvAddr: core.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: callValue, + ChainID: []byte(configs.ChainID), + Version: 1, + } +} + +func issueSemiFungibleTx(nonce uint64, sndAdr []byte, ticker []byte, baseIssuingCost string) *transaction.Transaction { + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + + txDataField := bytes.Join( + [][]byte{ + []byte("issueSemiFungible"), + []byte(hex.EncodeToString([]byte("asdname"))), + []byte(hex.EncodeToString(ticker)), + }, + []byte("@"), + ) + + return &transaction.Transaction{ + Nonce: nonce, + SndAddr: sndAdr, + RcvAddr: core.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: callValue, + ChainID: []byte(configs.ChainID), + Version: 1, + } +} + +func updateTokenIDTx(nonce uint64, sndAdr []byte, tokenID []byte) *transaction.Transaction { + txDataField := []byte("updateTokenID@" + hex.EncodeToString(tokenID)) + + return &transaction.Transaction{ + Nonce: nonce, + SndAddr: sndAdr, + RcvAddr: vm.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } +} + +func nftCreateTx( + nonce uint64, + sndAdr []byte, + tokenID []byte, + name, hash, attributes, uris []byte, +) *transaction.Transaction { + txDataField := bytes.Join( + [][]byte{ + []byte(core.BuiltInFunctionESDTNFTCreate), + []byte(hex.EncodeToString(tokenID)), + []byte(hex.EncodeToString(big.NewInt(1).Bytes())), // quantity + name, + []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + hash, + attributes, + uris, + }, + []byte("@"), + ) + + return &transaction.Transaction{ + Nonce: nonce, + SndAddr: sndAdr, + RcvAddr: sndAdr, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } } func executeQuery(cs testsChainSimulator.ChainSimulator, shardID uint32, scAddress []byte, funcName string, args [][]byte) (*dataVm.VMOutputApi, error) { @@ -516,32 +685,7 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { expUris := [][]byte{[]byte(hex.EncodeToString([]byte("uri")))} - txDataField := bytes.Join( - [][]byte{ - []byte(core.BuiltInFunctionESDTNFTCreate), - []byte(hex.EncodeToString(tokenID)), - []byte(hex.EncodeToString(big.NewInt(1).Bytes())), // quantity - name, - []byte(hex.EncodeToString(big.NewInt(10).Bytes())), - hash, - attributes, - uris, - }, - []byte("@"), - ) - - tx := &transaction.Transaction{ - Nonce: 0, - SndAddr: address.Bytes, - RcvAddr: address.Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, - } + tx := nftCreateTx(1, address.Bytes, tokenID, name, hash, attributes, uris) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -636,34 +780,11 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { name := []byte(hex.EncodeToString([]byte("name"))) hash := []byte(hex.EncodeToString([]byte("hash"))) attributes := []byte(hex.EncodeToString([]byte("attributes"))) - uris := [][]byte{[]byte(hex.EncodeToString([]byte("uri")))} + uris := []byte(hex.EncodeToString([]byte("uri"))) - txDataField := bytes.Join( - [][]byte{ - []byte(core.BuiltInFunctionESDTNFTCreate), - []byte(hex.EncodeToString(tokenID)), - []byte(hex.EncodeToString(big.NewInt(1).Bytes())), // quantity - name, - []byte(hex.EncodeToString(big.NewInt(10).Bytes())), - hash, - attributes, - uris[0], - }, - []byte("@"), - ) + expUris := [][]byte{[]byte(hex.EncodeToString([]byte("uri")))} - tx := &transaction.Transaction{ - Nonce: 0, - SndAddr: address.Bytes, - RcvAddr: address.Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, - } + tx := nftCreateTx(1, address.Bytes, tokenID, name, hash, attributes, uris) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -682,7 +803,7 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { hash = []byte(hex.EncodeToString([]byte("hash2"))) attributes = []byte(hex.EncodeToString([]byte("attributes2"))) - txDataField = bytes.Join( + txDataField := bytes.Join( [][]byte{ []byte(core.ESDTMetaDataRecreate), []byte(hex.EncodeToString(tokenID)), @@ -691,7 +812,7 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { []byte(hex.EncodeToString(big.NewInt(10).Bytes())), hash, attributes, - uris[0], + uris, }, []byte("@"), ) @@ -720,7 +841,7 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) require.Equal(t, hash, []byte(hex.EncodeToString(retrievedMetaData.Hash))) - for i, uri := range uris { + for i, uri := range expUris { require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) } require.Equal(t, attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) From f3a89fc1634eb15b6c5f49aca7503c9b96d2d481 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 29 May 2024 19:38:23 +0300 Subject: [PATCH 274/503] fixes after first review update tx unmarshaller to support relayed v3 as well --- factory/processing/processComponents.go | 1 + genesis/mock/txLogProcessorMock.go | 6 ++++ .../relayedTx/relayedTx_test.go | 26 ++++++++------ integrationTests/mock/txLogsProcessorStub.go | 14 ++++++-- integrationTests/testProcessorNode.go | 2 ++ node/external/transactionAPI/unmarshaller.go | 33 +++++++++++++++-- process/interface.go | 1 + process/mock/txLogsProcessorStub.go | 10 ++++++ .../smartContract/processorV2/processV2.go | 2 +- .../interceptedTransaction_test.go | 1 + process/transaction/relayedTxV3Processor.go | 12 +++++++ .../transaction/relayedTxV3Processor_test.go | 30 ++++++++++++++++ process/transaction/shardProcess.go | 20 +++++------ process/transaction/shardProcess_test.go | 13 +++---- process/transactionLog/printTxLogProcessor.go | 5 +++ .../printTxLogProcessor_test.go | 2 +- process/transactionLog/process.go | 36 ++++++++++--------- process/transactionLog/process_test.go | 20 +++++++---- 18 files changed, 175 insertions(+), 59 deletions(-) diff --git a/factory/processing/processComponents.go b/factory/processing/processComponents.go index 198e1a2d75a..ddeb217e7ee 100644 --- a/factory/processing/processComponents.go +++ b/factory/processing/processComponents.go @@ -382,6 +382,7 @@ func (pcf *processComponentsFactory) Create() (*processComponents, error) { argsRelayedTxV3Processor := transaction.ArgRelayedTxV3Processor{ EconomicsFee: pcf.coreData.EconomicsData(), ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), + ArgsParser: smartContract.NewArgumentParser(), MaxTransactionsAllowed: pcf.config.RelayedTransactionConfig.MaxTransactionsAllowed, } relayedTxV3Processor, err := transaction.NewRelayedTxV3Processor(argsRelayedTxV3Processor) diff --git a/genesis/mock/txLogProcessorMock.go b/genesis/mock/txLogProcessorMock.go index 11cef23871a..4d377541de7 100644 --- a/genesis/mock/txLogProcessorMock.go +++ b/genesis/mock/txLogProcessorMock.go @@ -21,6 +21,12 @@ func (tlpm *TxLogProcessorMock) SaveLog(_ []byte, _ data.TransactionHandler, _ [ return nil } +// AppendLog - +func (tlpm *TxLogProcessorMock) AppendLog(_ []byte, _ data.TransactionHandler, _ []*vmcommon.LogEntry) error { + + return nil +} + // Clean - func (tlpm *TxLogProcessorMock) Clean() { } diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index e2eab749a2f..f23a4080995 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -137,15 +137,12 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing. // check SCRs shardC := cs.GetNodeHandler(0).GetShardCoordinator() for _, scr := range result.SmartContractResults { - checkSCRStatus(t, cs, pkConv, shardC, scr) + checkSCRSucceeded(t, cs, pkConv, shardC, scr) } - // 6 log events, 3 from the succeeded txs + 3 from the failed one - require.Equal(t, 6, len(result.Logs.Events)) - require.Equal(t, core.CompletedTxEventIdentifier, result.Logs.Events[0].Identifier) - require.Equal(t, core.CompletedTxEventIdentifier, result.Logs.Events[1].Identifier) - require.Equal(t, core.CompletedTxEventIdentifier, result.Logs.Events[5].Identifier) - require.True(t, strings.Contains(string(result.Logs.Events[4].Data), "contract is paused")) + // 3 log events from the failed sc call + require.Equal(t, 3, len(result.Logs.Events)) + require.True(t, strings.Contains(string(result.Logs.Events[2].Data), "contract is paused")) } func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorScCalls(t *testing.T) { @@ -238,7 +235,7 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorScCalls(t *t continue } - checkSCRStatus(t, cs, pkConv, shardC, scr) + checkSCRSucceeded(t, cs, pkConv, shardC, scr) } // 6 events, 3 with signalError + 3 with the actual errors @@ -332,7 +329,7 @@ func checkSum( require.Equal(t, expectedSum, sum) } -func checkSCRStatus( +func checkSCRSucceeded( t *testing.T, cs testsChainSimulator.ChainSimulator, pkConv core.PubkeyConverter, @@ -345,5 +342,14 @@ func checkSCRStatus( senderShard := shardC.ComputeId(addr) tx, err := cs.GetNodeHandler(senderShard).GetFacadeHandler().GetTransaction(scr.Hash, true) require.NoError(t, err) - assert.Equal(t, transaction.TxStatusSuccess, tx.Status) + require.Equal(t, transaction.TxStatusSuccess, tx.Status) + + require.GreaterOrEqual(t, len(tx.Logs.Events), 1) + for _, event := range tx.Logs.Events { + if event.Identifier == core.WriteLogIdentifier { + continue + } + + require.Equal(t, core.CompletedTxEventIdentifier, event.Identifier) + } } diff --git a/integrationTests/mock/txLogsProcessorStub.go b/integrationTests/mock/txLogsProcessorStub.go index 124f5712843..651651455e8 100644 --- a/integrationTests/mock/txLogsProcessorStub.go +++ b/integrationTests/mock/txLogsProcessorStub.go @@ -7,8 +7,9 @@ import ( // TxLogsProcessorStub - type TxLogsProcessorStub struct { - GetLogCalled func(txHash []byte) (data.LogHandler, error) - SaveLogCalled func(txHash []byte, tx data.TransactionHandler, vmLogs []*vmcommon.LogEntry) error + GetLogCalled func(txHash []byte) (data.LogHandler, error) + SaveLogCalled func(txHash []byte, tx data.TransactionHandler, vmLogs []*vmcommon.LogEntry) error + AppendLogCalled func(txHash []byte, tx data.TransactionHandler, logEntries []*vmcommon.LogEntry) error } // GetLog - @@ -33,6 +34,15 @@ func (txls *TxLogsProcessorStub) SaveLog(txHash []byte, tx data.TransactionHandl return nil } +// AppendLog - +func (txls *TxLogsProcessorStub) AppendLog(txHash []byte, tx data.TransactionHandler, logEntries []*vmcommon.LogEntry) error { + if txls.AppendLogCalled != nil { + return txls.AppendLogCalled(txHash, tx, logEntries) + } + + return nil +} + // IsInterfaceNil - func (txls *TxLogsProcessorStub) IsInterfaceNil() bool { return txls == nil diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index 49ef2206b41..40472ae3576 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -1291,6 +1291,7 @@ func (tpn *TestProcessorNode) initInterceptors(heartbeatPk string) { relayedV3TxProcessor, _ := transaction.NewRelayedTxV3Processor(transaction.ArgRelayedTxV3Processor{ EconomicsFee: tpn.EconomicsData, ShardCoordinator: tpn.ShardCoordinator, + ArgsParser: smartContract.NewArgumentParser(), MaxTransactionsAllowed: 10, }) @@ -1728,6 +1729,7 @@ func (tpn *TestProcessorNode) initInnerProcessors(gasMap map[string]map[string]u relayedV3TxProcessor, _ := transaction.NewRelayedTxV3Processor(transaction.ArgRelayedTxV3Processor{ EconomicsFee: tpn.EconomicsData, ShardCoordinator: tpn.ShardCoordinator, + ArgsParser: smartContract.NewArgumentParser(), MaxTransactionsAllowed: 10, }) diff --git a/node/external/transactionAPI/unmarshaller.go b/node/external/transactionAPI/unmarshaller.go index 2b56518e506..cd7c63f83de 100644 --- a/node/external/transactionAPI/unmarshaller.go +++ b/node/external/transactionAPI/unmarshaller.go @@ -13,6 +13,8 @@ import ( "github.com/multiversx/mx-chain-go/sharding" ) +const operationTransfer = "transfer" + type txUnmarshaller struct { shardCoordinator sharding.Coordinator addressPubKeyConverter core.PubkeyConverter @@ -90,6 +92,33 @@ func (tu *txUnmarshaller) unmarshalTransaction(txBytes []byte, txType transactio return nil, err } + isRelayedV3 := len(apiTx.InnerTransactions) > 0 + if isRelayedV3 { + apiTx.Operation = operationTransfer + + rcvsShardIDs := make(map[uint32]struct{}) + for _, innerTx := range apiTx.InnerTransactions { + apiTx.Receivers = append(apiTx.Receivers, innerTx.Receiver) + + rcvBytes, errDecode := tu.addressPubKeyConverter.Decode(innerTx.Receiver) + if errDecode != nil { + log.Warn("bech32PubkeyConverter.Decode() failed while decoding innerTx.Receiver", "error", errDecode) + continue + } + + rcvShardID := tu.shardCoordinator.ComputeId(rcvBytes) + rcvsShardIDs[rcvShardID] = struct{}{} + } + + for rcvShard := range rcvsShardIDs { + apiTx.ReceiversShardIDs = append(apiTx.ReceiversShardIDs, rcvShard) + } + + apiTx.IsRelayed = true + + return apiTx, nil + } + res := tu.dataFieldParser.Parse(apiTx.Data, apiTx.Tx.GetSndAddr(), apiTx.Tx.GetRcvAddr(), tu.shardCoordinator.NumberOfShards()) apiTx.Operation = res.Operation apiTx.Function = res.Function @@ -164,12 +193,12 @@ func (tu *txUnmarshaller) prepareInnerTxs(tx *transaction.Transaction) []*transa Options: innerTx.Options, } - if len(tx.GuardianAddr) > 0 { + if len(innerTx.GuardianAddr) > 0 { frontEndTx.GuardianAddr = tu.addressPubKeyConverter.SilentEncode(innerTx.GuardianAddr, log) frontEndTx.GuardianSignature = hex.EncodeToString(innerTx.GuardianSignature) } - if len(tx.RelayerAddr) > 0 { + if len(innerTx.RelayerAddr) > 0 { frontEndTx.Relayer = tu.addressPubKeyConverter.SilentEncode(innerTx.RelayerAddr, log) } diff --git a/process/interface.go b/process/interface.go index a4b6e2c957e..21197ad7a8b 100644 --- a/process/interface.go +++ b/process/interface.go @@ -303,6 +303,7 @@ type TransactionLogProcessor interface { GetAllCurrentLogs() []*data.LogData GetLog(txHash []byte) (data.LogHandler, error) SaveLog(txHash []byte, tx data.TransactionHandler, vmLogs []*vmcommon.LogEntry) error + AppendLog(txHash []byte, tx data.TransactionHandler, logEntries []*vmcommon.LogEntry) error Clean() IsInterfaceNil() bool } diff --git a/process/mock/txLogsProcessorStub.go b/process/mock/txLogsProcessorStub.go index 18e1e368274..86f1791547a 100644 --- a/process/mock/txLogsProcessorStub.go +++ b/process/mock/txLogsProcessorStub.go @@ -9,6 +9,7 @@ import ( type TxLogsProcessorStub struct { GetLogCalled func(txHash []byte) (data.LogHandler, error) SaveLogCalled func(txHash []byte, tx data.TransactionHandler, vmLogs []*vmcommon.LogEntry) error + AppendLogCalled func(txHash []byte, tx data.TransactionHandler, logEntries []*vmcommon.LogEntry) error GetAllCurrentLogsCalled func() []*data.LogData } @@ -43,6 +44,15 @@ func (txls *TxLogsProcessorStub) GetAllCurrentLogs() []*data.LogData { return nil } +// AppendLog - +func (txls *TxLogsProcessorStub) AppendLog(txHash []byte, tx data.TransactionHandler, logEntries []*vmcommon.LogEntry) error { + if txls.AppendLogCalled != nil { + return txls.AppendLogCalled(txHash, tx, logEntries) + } + + return nil +} + // IsInterfaceNil - func (txls *TxLogsProcessorStub) IsInterfaceNil() bool { return txls == nil diff --git a/process/smartContract/processorV2/processV2.go b/process/smartContract/processorV2/processV2.go index 126433c6dee..76c157fa8a5 100644 --- a/process/smartContract/processorV2/processV2.go +++ b/process/smartContract/processorV2/processV2.go @@ -1508,7 +1508,7 @@ func (sc *scProcessor) processIfErrorWithAddedLogs(acntSnd state.UserAccountHand } logsTxHash := sc.getOriginalTxHashIfIntraShardRelayedSCR(tx, failureContext.txHash) - ignorableError := sc.txLogsProcessor.SaveLog(logsTxHash, tx, processIfErrorLogs) + ignorableError := sc.txLogsProcessor.AppendLog(logsTxHash, tx, processIfErrorLogs) if ignorableError != nil { log.Debug("scProcessor.ProcessIfError() txLogsProcessor.SaveLog()", "error", ignorableError.Error()) } diff --git a/process/transaction/interceptedTransaction_test.go b/process/transaction/interceptedTransaction_test.go index cac68e3c288..d4072d36977 100644 --- a/process/transaction/interceptedTransaction_test.go +++ b/process/transaction/interceptedTransaction_test.go @@ -202,6 +202,7 @@ func createInterceptedTxFromPlainTxWithArgParser(tx *dataTransaction.Transaction relayedTxV3Processor, err := transaction.NewRelayedTxV3Processor(transaction.ArgRelayedTxV3Processor{ EconomicsFee: txFeeHandler, ShardCoordinator: shardCoordinator, + ArgsParser: &mock.ArgumentParserMock{}, MaxTransactionsAllowed: 10, }) if err != nil { diff --git a/process/transaction/relayedTxV3Processor.go b/process/transaction/relayedTxV3Processor.go index e46db781cf6..bbaf81720e7 100644 --- a/process/transaction/relayedTxV3Processor.go +++ b/process/transaction/relayedTxV3Processor.go @@ -17,12 +17,14 @@ const minTransactionsAllowed = 1 type ArgRelayedTxV3Processor struct { EconomicsFee process.FeeHandler ShardCoordinator sharding.Coordinator + ArgsParser process.ArgumentsParser MaxTransactionsAllowed int } type relayedTxV3Processor struct { economicsFee process.FeeHandler shardCoordinator sharding.Coordinator + argsParser process.ArgumentsParser maxTransactionsAllowed int } @@ -36,6 +38,7 @@ func NewRelayedTxV3Processor(args ArgRelayedTxV3Processor) (*relayedTxV3Processo economicsFee: args.EconomicsFee, shardCoordinator: args.ShardCoordinator, maxTransactionsAllowed: args.MaxTransactionsAllowed, + argsParser: args.ArgsParser, }, nil } @@ -46,6 +49,9 @@ func checkArgs(args ArgRelayedTxV3Processor) error { if check.IfNil(args.ShardCoordinator) { return process.ErrNilShardCoordinator } + if check.IfNil(args.ArgsParser) { + return process.ErrNilArgumentParser + } if args.MaxTransactionsAllowed < minTransactionsAllowed { return fmt.Errorf("%w for MaxTransactionsAllowed, provided %d, min expected %d", process.ErrInvalidValue, args.MaxTransactionsAllowed, minTransactionsAllowed) } @@ -64,6 +70,12 @@ func (proc *relayedTxV3Processor) CheckRelayedTx(tx *transaction.Transaction) er if !bytes.Equal(tx.RcvAddr, tx.SndAddr) { return process.ErrRelayedTxV3SenderDoesNotMatchReceiver } + if len(tx.Data) > 0 { + funcName, _, err := proc.argsParser.ParseCallData(string(tx.Data)) + if err == nil && isRelayedTx(funcName) { + return process.ErrMultipleRelayedTxTypesIsNotAllowed + } + } if tx.GasLimit < proc.computeRelayedTxMinGasLimit(tx) { return process.ErrRelayedTxV3GasLimitMismatch } diff --git a/process/transaction/relayedTxV3Processor_test.go b/process/transaction/relayedTxV3Processor_test.go index ed0de081bb4..4d584bb0acf 100644 --- a/process/transaction/relayedTxV3Processor_test.go +++ b/process/transaction/relayedTxV3Processor_test.go @@ -10,6 +10,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data" coreTransaction "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/process/mock" "github.com/multiversx/mx-chain-go/process/transaction" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/economicsmocks" @@ -53,6 +54,7 @@ func createMockArgRelayedTxV3Processor() transaction.ArgRelayedTxV3Processor { return transaction.ArgRelayedTxV3Processor{ EconomicsFee: &economicsmocks.EconomicsHandlerStub{}, ShardCoordinator: &testscommon.ShardsCoordinatorMock{}, + ArgsParser: &mock.ArgumentParserMock{}, MaxTransactionsAllowed: 10, } } @@ -78,6 +80,15 @@ func TestNewRelayedTxV3Processor(t *testing.T) { require.Nil(t, proc) require.Equal(t, process.ErrNilShardCoordinator, err) }) + t.Run("nil args parser should error", func(t *testing.T) { + t.Parallel() + + args := createMockArgRelayedTxV3Processor() + args.ArgsParser = nil + proc, err := transaction.NewRelayedTxV3Processor(args) + require.Nil(t, proc) + require.Equal(t, process.ErrNilArgumentParser, err) + }) t.Run("invalid max transactions allowed should error", func(t *testing.T) { t.Parallel() @@ -150,6 +161,25 @@ func TestRelayedTxV3Processor_CheckRelayedTx(t *testing.T) { err = proc.CheckRelayedTx(tx) require.Equal(t, process.ErrRelayedTxV3SenderDoesNotMatchReceiver, err) }) + t.Run("multiple relayed txs should error", func(t *testing.T) { + t.Parallel() + + args := createMockArgRelayedTxV3Processor() + args.ArgsParser = &mock.ArgumentParserMock{ + ParseCallDataCalled: func(data string) (string, [][]byte, error) { + splitData := strings.Split(data, "@") + return splitData[0], nil, nil + }, + } + proc, err := transaction.NewRelayedTxV3Processor(args) + require.NoError(t, err) + + tx := getDefaultTx() + tx.Data = []byte("relayedTx@asd") + + err = proc.CheckRelayedTx(tx) + require.Equal(t, process.ErrMultipleRelayedTxTypesIsNotAllowed, err) + }) t.Run("invalid gas limit should error", func(t *testing.T) { t.Parallel() diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index ae0fb9494af..d9fe3c94891 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -662,12 +662,7 @@ func (txProc *txProcessor) processRelayedTxV3( if check.IfNil(relayerAcnt) { return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrNilRelayerAccount) } - funcName, _, err := txProc.argsParser.ParseCallData(string(tx.Data)) - if err == nil && isRelayedTx(funcName) { - return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrMultipleRelayedTxTypesIsNotAllowed) - } - - err = txProc.relayedTxV3Processor.CheckRelayedTx(tx) + err := txProc.relayedTxV3Processor.CheckRelayedTx(tx) if err != nil { return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, err) } @@ -982,8 +977,8 @@ func (txProc *txProcessor) processUserTx( switch txType { case process.MoveBalance: err = txProc.processMoveBalance(userTx, acntSnd, acntDst, dstShardTxType, originalTxHash, true) - isUserTxOfRelayedV3 := len(originalTx.InnerTransactions) > 0 - if err == nil && isUserTxOfRelayedV3 { + intraShard := txProc.shardCoordinator.SameShard(userTx.SndAddr, userTx.RcvAddr) + if err == nil && intraShard { txProc.createCompleteEventLog(scrFromTx, originalTxHash) } case process.SCDeployment: @@ -1192,13 +1187,18 @@ func isNonExecutableError(executionErr error) bool { } func (txProc *txProcessor) createCompleteEventLog(scr data.TransactionHandler, originalTxHash []byte) { + scrHash, err := core.CalculateHash(txProc.marshalizer, txProc.hasher, scr) + if err != nil { + scrHash = originalTxHash + } + completedTxLog := &vmcommon.LogEntry{ Identifier: []byte(core.CompletedTxEventIdentifier), Address: scr.GetRcvAddr(), - Topics: [][]byte{originalTxHash}, + Topics: [][]byte{scrHash}, } - ignorableError := txProc.txLogsProcessor.SaveLog(originalTxHash, scr, []*vmcommon.LogEntry{completedTxLog}) + ignorableError := txProc.txLogsProcessor.SaveLog(scrHash, scr, []*vmcommon.LogEntry{completedTxLog}) if ignorableError != nil { log.Debug("txProcessor.createCompleteEventLog txLogsProcessor.SaveLog()", "error", ignorableError.Error()) } diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index f8d8ccd7249..939ecbcfc37 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -2178,15 +2178,6 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { txCopy.GasLimit = userTx.GasLimit - 1 testProcessRelayedTransactionV3(t, &txCopy, userTx.SndAddr, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) }) - t.Run("multiple types of relayed tx should error", func(t *testing.T) { - t.Parallel() - - txCopy := *tx - userTxCopy := *userTx - userTxData, _ := marshaller.Marshal(userTxCopy) - txCopy.Data = []byte(core.RelayedTransaction + "@" + hex.EncodeToString(userTxData)) - testProcessRelayedTransactionV3(t, &txCopy, userTx.SndAddr, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) - }) t.Run("failure to add fees on destination should skip transaction and continue", func(t *testing.T) { t.Parallel() @@ -2244,6 +2235,7 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(txproc.ArgRelayedTxV3Processor{ EconomicsFee: args.EconomicsFee, ShardCoordinator: args.ShardCoordinator, + ArgsParser: &mock.ArgumentParserMock{}, MaxTransactionsAllowed: 10, }) logs := make([]*vmcommon.LogEntry, 0) @@ -2358,6 +2350,7 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(txproc.ArgRelayedTxV3Processor{ EconomicsFee: args.EconomicsFee, ShardCoordinator: args.ShardCoordinator, + ArgsParser: &mock.ArgumentParserMock{}, MaxTransactionsAllowed: 10, }) execTx, _ := txproc.NewTxProcessor(args) @@ -2424,6 +2417,7 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(txproc.ArgRelayedTxV3Processor{ EconomicsFee: args.EconomicsFee, ShardCoordinator: args.ShardCoordinator, + ArgsParser: &mock.ArgumentParserMock{}, MaxTransactionsAllowed: 10, }) execTx, _ := txproc.NewTxProcessor(args) @@ -2534,6 +2528,7 @@ func testProcessRelayedTransactionV3( args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(txproc.ArgRelayedTxV3Processor{ EconomicsFee: args.EconomicsFee, ShardCoordinator: args.ShardCoordinator, + ArgsParser: &mock.ArgumentParserMock{}, MaxTransactionsAllowed: 10, }) diff --git a/process/transactionLog/printTxLogProcessor.go b/process/transactionLog/printTxLogProcessor.go index 6a512219d6a..8f21674ee60 100644 --- a/process/transactionLog/printTxLogProcessor.go +++ b/process/transactionLog/printTxLogProcessor.go @@ -55,6 +55,11 @@ func (tlp *printTxLogProcessor) SaveLog(txHash []byte, _ data.TransactionHandler return nil } +// AppendLog - +func (tlp *printTxLogProcessor) AppendLog(txHash []byte, tx data.TransactionHandler, logEntries []*vmcommon.LogEntry) error { + return tlp.SaveLog(txHash, tx, logEntries) +} + func prepareTopics(topics [][]byte) string { all := "" for _, topic := range topics { diff --git a/process/transactionLog/printTxLogProcessor_test.go b/process/transactionLog/printTxLogProcessor_test.go index 5074ec617a4..703cdfabe86 100644 --- a/process/transactionLog/printTxLogProcessor_test.go +++ b/process/transactionLog/printTxLogProcessor_test.go @@ -65,7 +65,7 @@ func TestPrintTxLogProcessor_SaveLog(t *testing.T) { err := ptlp.SaveLog([]byte("hash"), &transaction.Transaction{}, txLogEntry) require.Nil(t, err) - err = ptlp.SaveLog([]byte("hash"), &transaction.Transaction{}, nil) + err = ptlp.AppendLog([]byte("hash"), &transaction.Transaction{}, nil) require.Nil(t, err) require.True(t, strings.Contains(buff.String(), "printTxLogProcessor.SaveLog")) diff --git a/process/transactionLog/process.go b/process/transactionLog/process.go index bdac14d542a..e0c2a8e072e 100644 --- a/process/transactionLog/process.go +++ b/process/transactionLog/process.go @@ -2,7 +2,6 @@ package transactionLog import ( "encoding/hex" - "strings" "sync" "github.com/multiversx/mx-chain-core-go/core" @@ -131,6 +130,15 @@ func (tlp *txLogProcessor) Clean() { // SaveLog takes the VM logs and saves them into the correct format in storage func (tlp *txLogProcessor) SaveLog(txHash []byte, tx data.TransactionHandler, logEntries []*vmcommon.LogEntry) error { + return tlp.saveLog(txHash, tx, logEntries, false) +} + +// AppendLog takes the VM logs and appends them into the correct format in storage +func (tlp *txLogProcessor) AppendLog(txHash []byte, tx data.TransactionHandler, logEntries []*vmcommon.LogEntry) error { + return tlp.saveLog(txHash, tx, logEntries, true) +} + +func (tlp *txLogProcessor) saveLog(txHash []byte, tx data.TransactionHandler, logEntries []*vmcommon.LogEntry, appendLog bool) error { if len(txHash) == 0 { return process.ErrNilTxHash } @@ -167,12 +175,21 @@ func (tlp *txLogProcessor) SaveLog(txHash []byte, tx data.TransactionHandler, lo tlp.saveLogToCache(txHash, txLog) + buff, err := tlp.marshalizer.Marshal(txLog) + if err != nil { + return err + } + + if !appendLog { + return tlp.storer.Put(txHash, buff) + } + return tlp.appendLogToStorer(txHash, txLog) } func (tlp *txLogProcessor) appendLogToStorer(txHash []byte, newLog *transaction.Log) error { oldLogsBuff, errGet := tlp.storer.Get(txHash) - if isFirstEntryForHash(oldLogsBuff, errGet) { + if errGet != nil || len(oldLogsBuff) == 0 { allLogsBuff, err := tlp.marshalizer.Marshal(newLog) if err != nil { return err @@ -180,9 +197,6 @@ func (tlp *txLogProcessor) appendLogToStorer(txHash []byte, newLog *transaction. return tlp.storer.Put(txHash, allLogsBuff) } - if errGet != nil { - return errGet - } oldLogs := &transaction.Log{} err := tlp.marshalizer.Unmarshal(oldLogs, oldLogsBuff) @@ -203,18 +217,6 @@ func (tlp *txLogProcessor) appendLogToStorer(txHash []byte, newLog *transaction. return tlp.storer.Put(txHash, allLogsBuff) } -func isFirstEntryForHash(oldLogsBuff []byte, errGet error) bool { - if errGet == nil && len(oldLogsBuff) == 0 { - return true - } - - if errGet == nil { - return false - } - - return strings.Contains(errGet.Error(), "not found") -} - func (tlp *txLogProcessor) saveLogToCache(txHash []byte, log *transaction.Log) { tlp.logs = append(tlp.logs, &data.LogData{ TxHash: string(txHash), diff --git a/process/transactionLog/process_test.go b/process/transactionLog/process_test.go index c9247cc3d0b..decde14253d 100644 --- a/process/transactionLog/process_test.go +++ b/process/transactionLog/process_test.go @@ -130,14 +130,19 @@ func TestTxLogProcessor_SaveLogsStoreErr(t *testing.T) { require.Equal(t, retErr, err) } -func TestTxLogProcessor_SaveLogsGetErrShouldError(t *testing.T) { +func TestTxLogProcessor_AppendLogGetErrSaveLog(t *testing.T) { t.Parallel() + wasSaved := false txLogProcessor, _ := transactionLog.NewTxLogProcessor(transactionLog.ArgTxLogProcessor{ Storer: &storageStubs.StorerStub{ GetCalled: func(key []byte) ([]byte, error) { return nil, expectedErr }, + PutCalled: func(key, data []byte) error { + wasSaved = true + return nil + }, }, Marshalizer: &mock.MarshalizerMock{}, SaveInStorageEnabled: true, @@ -146,11 +151,12 @@ func TestTxLogProcessor_SaveLogsGetErrShouldError(t *testing.T) { logs := []*vmcommon.LogEntry{ {Address: []byte("first log")}, } - err := txLogProcessor.SaveLog([]byte("txhash"), &transaction.Transaction{}, logs) - require.Equal(t, expectedErr, err) + err := txLogProcessor.AppendLog([]byte("txhash"), &transaction.Transaction{}, logs) + require.NoError(t, err) + require.True(t, wasSaved) } -func TestTxLogProcessor_SaveLogsUnmarshalErrShouldError(t *testing.T) { +func TestTxLogProcessor_AppendLogsUnmarshalErrShouldError(t *testing.T) { t.Parallel() txLogProcessor, _ := transactionLog.NewTxLogProcessor(transactionLog.ArgTxLogProcessor{ @@ -170,11 +176,11 @@ func TestTxLogProcessor_SaveLogsUnmarshalErrShouldError(t *testing.T) { logs := []*vmcommon.LogEntry{ {Address: []byte("first log")}, } - err := txLogProcessor.SaveLog([]byte("txhash"), &transaction.Transaction{}, logs) + err := txLogProcessor.AppendLog([]byte("txhash"), &transaction.Transaction{}, logs) require.Equal(t, expectedErr, err) } -func TestTxLogProcessor_SaveLogsShouldWorkAndAppend(t *testing.T) { +func TestTxLogProcessor_AppendLogShouldWorkAndAppend(t *testing.T) { t.Parallel() providedHash := []byte("txhash") @@ -198,7 +204,7 @@ func TestTxLogProcessor_SaveLogsShouldWorkAndAppend(t *testing.T) { {Address: []byte("addr 3"), Data: [][]byte{[]byte("new data 1")}}, } - err = txLogProcessor.SaveLog(providedHash, &transaction.Transaction{SndAddr: []byte("sender")}, newLogs) + err = txLogProcessor.AppendLog(providedHash, &transaction.Transaction{SndAddr: []byte("sender")}, newLogs) require.NoError(t, err) buff, err := storer.Get(providedHash) From f1ebcf54c7a165fe3a1bfcdd291a388218b5cbdf Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 30 May 2024 11:58:08 +0300 Subject: [PATCH 275/503] refactor to use common functions --- .../vm/esdtImprovements_test.go | 238 ++++-------------- integrationTests/vm/txsFee/common.go | 62 ++--- .../vm/txsFee/esdtMetaDataRecreate_test.go | 24 +- .../vm/txsFee/esdtMetaDataUpdate_test.go | 26 +- .../vm/txsFee/esdtModifyCreator_test.go | 10 +- .../vm/txsFee/esdtModifyRoyalties_test.go | 14 +- .../vm/txsFee/esdtSetNewURIs_test.go | 16 +- 7 files changed, 129 insertions(+), 261 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 1e71c1df27e..cfcbd14fcf9 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -3,7 +3,6 @@ package vm import ( "bytes" "encoding/hex" - "fmt" "math/big" "testing" "time" @@ -15,6 +14,7 @@ import ( "github.com/multiversx/mx-chain-go/config" testsChainSimulator "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" + "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee" "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" @@ -116,10 +116,6 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - fmt.Println(txResult) - fmt.Println(txResult.Logs.Events[0]) - fmt.Println(txResult.Logs.Events[0].Identifier) - nftTokenID := txResult.Logs.Events[0].Topics[0] roles := [][]byte{ @@ -139,10 +135,6 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - fmt.Println(txResult) - fmt.Println(txResult.Logs.Events[0]) - fmt.Println(txResult.Logs.Events[0].Identifier) - sftTokenID := txResult.Logs.Events[0].Topics[0] roles = [][]byte{ @@ -153,41 +145,24 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) - nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - name := []byte(hex.EncodeToString([]byte("name"))) - hash := []byte(hex.EncodeToString([]byte("hash"))) - attributes := []byte(hex.EncodeToString([]byte("attributes"))) - uris := []byte(hex.EncodeToString([]byte("uri"))) - - expUris := [][]byte{[]byte(hex.EncodeToString([]byte("uri")))} + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(2, address.Bytes, nftTokenID, name, hash, attributes, uris) + tx = nftCreateTx(2, address.Bytes, nftTokenID, nftMetaData) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - name1 := []byte(hex.EncodeToString([]byte("name1"))) - hash1 := []byte(hex.EncodeToString([]byte("hash1"))) - attributes1 := []byte(hex.EncodeToString([]byte("attributes1"))) - uris1 := []byte(hex.EncodeToString([]byte("uri1"))) + sftMetaData := txsFee.GetDefaultMetaData() + sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - expUris1 := [][]byte{[]byte(hex.EncodeToString([]byte("uri1")))} - - tx = nftCreateTx(3, address.Bytes, sftTokenID, name1, hash1, attributes1, uris1) + tx = nftCreateTx(3, address.Bytes, sftTokenID, sftMetaData) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - - fmt.Println(txResult) - fmt.Println(txResult.Logs.Events[0]) - fmt.Println(txResult.Logs.Events[0].Topics[0]) - fmt.Println(txResult.Logs.Events[0].Topics[1]) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) err = cs.GenerateBlocks(10) @@ -195,34 +170,14 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 1. check that the metadata for all tokens is saved on the system account") - retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) - - require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) - require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) - require.Equal(t, hash, []byte(hex.EncodeToString(retrievedMetaData.Hash))) - for i, uri := range expUris { - require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) - } - require.Equal(t, attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) - - retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, sftTokenID, shardID) - - require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) - require.Equal(t, name1, []byte(hex.EncodeToString(retrievedMetaData.Name))) - require.Equal(t, hash1, []byte(hex.EncodeToString(retrievedMetaData.Hash))) - for i, uri := range expUris1 { - require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) - } - require.Equal(t, attributes1, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, nftMetaData) log.Info("Step 2. wait for DynamicEsdtFlag activation") err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) require.Nil(t, err) - err = cs.GenerateBlocks(10) - require.Nil(t, err) - log.Info("Step 3. transfer the tokens to another account") address2, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) @@ -249,12 +204,6 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - - fmt.Println(txResult.Logs.Events[0]) - fmt.Println(txResult.Logs.Events[0].Topics[0]) - fmt.Println(txResult.Logs.Events[0].Topics[1]) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) tx = utils.CreateESDTNFTTransferTx( @@ -275,35 +224,12 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - - fmt.Println(txResult.Logs.Events[0]) - fmt.Println(txResult.Logs.Events[0].Topics[0]) - fmt.Println(txResult.Logs.Events[0].Topics[1]) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) log.Info("Step 4. check that the metadata for all tokens is saved on the system account") - retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) - - require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) - require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) - require.Equal(t, hash, []byte(hex.EncodeToString(retrievedMetaData.Hash))) - for i, uri := range expUris { - require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) - } - require.Equal(t, attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) - - retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, sftTokenID, shardID) - - require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) - require.Equal(t, name1, []byte(hex.EncodeToString(retrievedMetaData.Name))) - require.Equal(t, hash1, []byte(hex.EncodeToString(retrievedMetaData.Hash))) - for i, uri := range expUris1 { - require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) - } - require.Equal(t, attributes1, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, nftMetaData) log.Info("Step 5. make an updateTokenID@tokenID function call on the ESDTSystem SC for all token types") @@ -312,12 +238,6 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - - fmt.Println(txResult.Logs.Events[0]) - fmt.Println(txResult.Logs.Events[0].Topics[0]) - fmt.Println(txResult.Logs.Events[0].Topics[1]) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) tx = updateTokenIDTx(7, address.Bytes, sftTokenID) @@ -325,35 +245,12 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - - fmt.Println(txResult.Logs.Events[0]) - fmt.Println(txResult.Logs.Events[0].Topics[0]) - fmt.Println(txResult.Logs.Events[0].Topics[1]) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) log.Info("Step 6. check that the metadata for all tokens is saved on the system account") - retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) - - require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) - require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) - require.Equal(t, hash, []byte(hex.EncodeToString(retrievedMetaData.Hash))) - for i, uri := range expUris { - require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) - } - require.Equal(t, attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) - - retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, sftTokenID, shardID) - - require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) - require.Equal(t, name1, []byte(hex.EncodeToString(retrievedMetaData.Name))) - require.Equal(t, hash1, []byte(hex.EncodeToString(retrievedMetaData.Hash))) - for i, uri := range expUris1 { - require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) - } - require.Equal(t, attributes1, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, nftMetaData) log.Info("Step 7. transfer the tokens to another account") @@ -375,11 +272,6 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - - fmt.Println(txResult.Logs.Events[0]) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) tx = utils.CreateESDTNFTTransferTx( @@ -400,36 +292,35 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - - fmt.Println(txResult.Logs.Events[0]) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) log.Info("Step 8. check that the metaData for the NFT was removed from the system account and moved to the user account") - retrievedMetaData = getMetaDataFromAcc(t, cs, address3.Bytes, nftTokenID, shardID) - - require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) - require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) - require.Equal(t, hash, []byte(hex.EncodeToString(retrievedMetaData.Hash))) - for i, uri := range expUris { - require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) - } - require.Equal(t, attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) + checkMetaData(t, cs, address3.Bytes, nftTokenID, shardID, nftMetaData) log.Info("Step 9. check that the metaData for the rest of the tokens is still present on the system account and not on the userAccount") - retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, sftTokenID, shardID) + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, nftMetaData) +} + +func checkMetaData( + t *testing.T, + cs testsChainSimulator.ChainSimulator, + addressBytes []byte, + token []byte, + shardID uint32, + expectedMetaData *txsFee.MetaData, +) { + retrievedMetaData := getMetaDataFromAcc(t, cs, addressBytes, token, shardID) - require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) - require.Equal(t, name1, []byte(hex.EncodeToString(retrievedMetaData.Name))) - require.Equal(t, hash1, []byte(hex.EncodeToString(retrievedMetaData.Hash))) - for i, uri := range expUris1 { + require.Equal(t, expectedMetaData.Nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) + require.Equal(t, expectedMetaData.Name, []byte(hex.EncodeToString(retrievedMetaData.Name))) + require.Equal(t, expectedMetaData.Royalties, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Royalties)).Bytes()))) + require.Equal(t, expectedMetaData.Hash, []byte(hex.EncodeToString(retrievedMetaData.Hash))) + for i, uri := range expectedMetaData.Uris { require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) } - require.Equal(t, attributes1, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) + require.Equal(t, expectedMetaData.Attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) } func issueNonFungibleTx(sndAdr []byte, ticker []byte, baseIssuingCost string) *transaction.Transaction { @@ -505,18 +396,20 @@ func nftCreateTx( nonce uint64, sndAdr []byte, tokenID []byte, - name, hash, attributes, uris []byte, + metaData *txsFee.MetaData, ) *transaction.Transaction { txDataField := bytes.Join( [][]byte{ []byte(core.BuiltInFunctionESDTNFTCreate), []byte(hex.EncodeToString(tokenID)), []byte(hex.EncodeToString(big.NewInt(1).Bytes())), // quantity - name, + metaData.Name, []byte(hex.EncodeToString(big.NewInt(10).Bytes())), - hash, - attributes, - uris, + metaData.Hash, + metaData.Attributes, + metaData.Uris[0], + metaData.Uris[1], + metaData.Uris[2], }, []byte("@"), ) @@ -677,15 +570,9 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { } setAddressEsdtRoles(t, cs, address, tokenID, roles) - nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - name := []byte(hex.EncodeToString([]byte("name"))) - hash := []byte(hex.EncodeToString([]byte("hash"))) - attributes := []byte(hex.EncodeToString([]byte("attributes"))) - uris := []byte(hex.EncodeToString([]byte("uri"))) - - expUris := [][]byte{[]byte(hex.EncodeToString([]byte("uri")))} + nftMetaData := txsFee.GetDefaultMetaData() - tx := nftCreateTx(1, address.Bytes, tokenID, name, hash, attributes, uris) + tx := nftCreateTx(1, address.Bytes, tokenID, nftMetaData) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -699,15 +586,7 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { log.Info("Step 1. check that the metaData for the NFT was saved in the user account and not on the system account") - retrievedMetaData := getMetaDataFromAcc(t, cs, address.Bytes, tokenID, shardID) - - require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) - require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) - require.Equal(t, hash, []byte(hex.EncodeToString(retrievedMetaData.Hash))) - for i, uri := range expUris { - require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) - } - require.Equal(t, attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) + checkMetaData(t, cs, address.Bytes, tokenID, shardID, nftMetaData) } // Test scenario @@ -777,14 +656,9 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { } setAddressEsdtRoles(t, cs, address, tokenID, roles) - name := []byte(hex.EncodeToString([]byte("name"))) - hash := []byte(hex.EncodeToString([]byte("hash"))) - attributes := []byte(hex.EncodeToString([]byte("attributes"))) - uris := []byte(hex.EncodeToString([]byte("uri"))) - - expUris := [][]byte{[]byte(hex.EncodeToString([]byte("uri")))} + nftMetaData := txsFee.GetDefaultMetaData() - tx := nftCreateTx(1, address.Bytes, tokenID, name, hash, attributes, uris) + tx := nftCreateTx(1, address.Bytes, tokenID, nftMetaData) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -799,20 +673,20 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { log.Info("Call ESDTMetaDataRecreate to rewrite the meta data for the nft") nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - name = []byte(hex.EncodeToString([]byte("name2"))) - hash = []byte(hex.EncodeToString([]byte("hash2"))) - attributes = []byte(hex.EncodeToString([]byte("attributes2"))) + nftMetaData.Name = []byte(hex.EncodeToString([]byte("name2"))) + nftMetaData.Hash = []byte(hex.EncodeToString([]byte("hash2"))) + nftMetaData.Attributes = []byte(hex.EncodeToString([]byte("attributes2"))) txDataField := bytes.Join( [][]byte{ []byte(core.ESDTMetaDataRecreate), []byte(hex.EncodeToString(tokenID)), nonce, - name, + nftMetaData.Name, []byte(hex.EncodeToString(big.NewInt(10).Bytes())), - hash, - attributes, - uris, + nftMetaData.Hash, + nftMetaData.Attributes, + nftMetaData.Uris[0], }, []byte("@"), ) @@ -836,15 +710,7 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) - retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) - - require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) - require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) - require.Equal(t, hash, []byte(hex.EncodeToString(retrievedMetaData.Hash))) - for i, uri := range expUris { - require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) - } - require.Equal(t, attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, shardID, nftMetaData) } // Test scenario diff --git a/integrationTests/vm/txsFee/common.go b/integrationTests/vm/txsFee/common.go index 8d94f929382..9f6574aca1d 100644 --- a/integrationTests/vm/txsFee/common.go +++ b/integrationTests/vm/txsFee/common.go @@ -17,25 +17,27 @@ import ( const gasPrice = uint64(10) -type metaData struct { - tokenId []byte - nonce []byte - name []byte - royalties []byte - hash []byte - attributes []byte - uris [][]byte +// MetaData defines test meta data struct +type MetaData struct { + TokenId []byte + Nonce []byte + Name []byte + Royalties []byte + Hash []byte + Attributes []byte + Uris [][]byte } -func getDefaultMetaData() *metaData { - return &metaData{ - tokenId: []byte(hex.EncodeToString([]byte("tokenId"))), - nonce: []byte(hex.EncodeToString(big.NewInt(0).Bytes())), - name: []byte(hex.EncodeToString([]byte("name"))), - royalties: []byte(hex.EncodeToString(big.NewInt(10).Bytes())), - hash: []byte(hex.EncodeToString([]byte("hash"))), - attributes: []byte(hex.EncodeToString([]byte("attributes"))), - uris: [][]byte{[]byte(hex.EncodeToString([]byte("uri1"))), []byte(hex.EncodeToString([]byte("uri2"))), []byte(hex.EncodeToString([]byte("uri3")))}, +// GetDefaultMetaData will return default meta data structure +func GetDefaultMetaData() *MetaData { + return &MetaData{ + TokenId: []byte(hex.EncodeToString([]byte("tokenId"))), + Nonce: []byte(hex.EncodeToString(big.NewInt(0).Bytes())), + Name: []byte(hex.EncodeToString([]byte("name"))), + Royalties: []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + Hash: []byte(hex.EncodeToString([]byte("hash"))), + Attributes: []byte(hex.EncodeToString([]byte("attributes"))), + Uris: [][]byte{[]byte(hex.EncodeToString([]byte("uri1"))), []byte(hex.EncodeToString([]byte("uri2"))), []byte(hex.EncodeToString([]byte("uri3")))}, } } @@ -55,17 +57,17 @@ func getMetaDataFromAcc(t *testing.T, testContext *vm.VMTestContext, accWithMeta return esdtData.TokenMetaData } -func checkMetaData(t *testing.T, testContext *vm.VMTestContext, accWithMetaData []byte, token []byte, expectedMetaData *metaData) { +func checkMetaData(t *testing.T, testContext *vm.VMTestContext, accWithMetaData []byte, token []byte, expectedMetaData *MetaData) { retrievedMetaData := getMetaDataFromAcc(t, testContext, accWithMetaData, token) - require.Equal(t, expectedMetaData.nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) - require.Equal(t, expectedMetaData.name, []byte(hex.EncodeToString(retrievedMetaData.Name))) - require.Equal(t, expectedMetaData.royalties, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Royalties)).Bytes()))) - require.Equal(t, expectedMetaData.hash, []byte(hex.EncodeToString(retrievedMetaData.Hash))) - for i, uri := range expectedMetaData.uris { + require.Equal(t, expectedMetaData.Nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) + require.Equal(t, expectedMetaData.Name, []byte(hex.EncodeToString(retrievedMetaData.Name))) + require.Equal(t, expectedMetaData.Royalties, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Royalties)).Bytes()))) + require.Equal(t, expectedMetaData.Hash, []byte(hex.EncodeToString(retrievedMetaData.Hash))) + for i, uri := range expectedMetaData.Uris { require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) } - require.Equal(t, expectedMetaData.attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) + require.Equal(t, expectedMetaData.Attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) } func getDynamicTokenTypes() []string { @@ -81,17 +83,17 @@ func createTokenTx( rcvAddr []byte, gasLimit uint64, quantity int64, - metaData *metaData, + metaData *MetaData, ) *transaction.Transaction { txDataField := bytes.Join( [][]byte{ []byte(core.BuiltInFunctionESDTNFTCreate), - metaData.tokenId, + metaData.TokenId, []byte(hex.EncodeToString(big.NewInt(quantity).Bytes())), // quantity - metaData.name, - metaData.royalties, - metaData.hash, - metaData.attributes, + metaData.Name, + metaData.Royalties, + metaData.Hash, + metaData.Attributes, []byte(hex.EncodeToString([]byte("uri"))), }, []byte("@"), diff --git a/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go b/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go index ac0a7902f14..d980ed816d7 100644 --- a/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go +++ b/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go @@ -45,14 +45,14 @@ func runEsdtMetaDataRecreateTest(t *testing.T, tokenType string) { require.Equal(t, vmcommon.Ok, retCode) require.Nil(t, err) - defaultMetaData := getDefaultMetaData() + defaultMetaData := GetDefaultMetaData() tx = createTokenTx(sndAddr, sndAddr, 100000, 1, defaultMetaData) retCode, err = testContext.TxProcessor.ProcessTransaction(tx) require.Equal(t, vmcommon.Ok, retCode) require.Nil(t, err) // TODO change default metadata - defaultMetaData.nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + defaultMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = esdtMetaDataRecreateTx(sndAddr, sndAddr, 100000, defaultMetaData) retCode, err = testContext.TxProcessor.ProcessTransaction(tx) require.Equal(t, vmcommon.Ok, retCode) @@ -68,20 +68,20 @@ func esdtMetaDataRecreateTx( sndAddr []byte, rcvAddr []byte, gasLimit uint64, - metaData *metaData, + metaData *MetaData, ) *transaction.Transaction { txDataField := bytes.Join( [][]byte{ []byte(core.ESDTMetaDataRecreate), - metaData.tokenId, - metaData.nonce, - metaData.name, - metaData.royalties, - metaData.hash, - metaData.attributes, - metaData.uris[0], - metaData.uris[1], - metaData.uris[2], + metaData.TokenId, + metaData.Nonce, + metaData.Name, + metaData.Royalties, + metaData.Hash, + metaData.Attributes, + metaData.Uris[0], + metaData.Uris[1], + metaData.Uris[2], }, []byte("@"), ) diff --git a/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go b/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go index 33aece1aacc..ea5ec910c97 100644 --- a/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go +++ b/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go @@ -45,17 +45,17 @@ func runEsdtMetaDataUpdateTest(t *testing.T, tokenType string) { require.Equal(t, vmcommon.Ok, retCode) require.Nil(t, err) - defaultMetaData := getDefaultMetaData() + defaultMetaData := GetDefaultMetaData() tx = createTokenTx(sndAddr, sndAddr, 100000, 1, defaultMetaData) retCode, err = testContext.TxProcessor.ProcessTransaction(tx) require.Equal(t, vmcommon.Ok, retCode) require.Nil(t, err) // TODO change default metadata - defaultMetaData.nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - defaultMetaData.name = []byte(hex.EncodeToString([]byte("newName"))) - defaultMetaData.hash = []byte(hex.EncodeToString([]byte("newHash"))) - defaultMetaData.uris = [][]byte{defaultMetaData.uris[1]} + defaultMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + defaultMetaData.Name = []byte(hex.EncodeToString([]byte("newName"))) + defaultMetaData.Hash = []byte(hex.EncodeToString([]byte("newHash"))) + defaultMetaData.Uris = [][]byte{defaultMetaData.Uris[1]} tx = esdtMetaDataUpdateTx(sndAddr, sndAddr, 100000, defaultMetaData) retCode, err = testContext.TxProcessor.ProcessTransaction(tx) require.Equal(t, vmcommon.Ok, retCode) @@ -71,18 +71,18 @@ func esdtMetaDataUpdateTx( sndAddr []byte, rcvAddr []byte, gasLimit uint64, - metaData *metaData, + metaData *MetaData, ) *transaction.Transaction { txDataField := bytes.Join( [][]byte{ []byte(core.ESDTMetaDataUpdate), - metaData.tokenId, - metaData.nonce, - metaData.name, - metaData.royalties, - metaData.hash, - metaData.attributes, - metaData.uris[0], + metaData.TokenId, + metaData.Nonce, + metaData.Name, + metaData.Royalties, + metaData.Hash, + metaData.Attributes, + metaData.Uris[0], }, []byte("@"), ) diff --git a/integrationTests/vm/txsFee/esdtModifyCreator_test.go b/integrationTests/vm/txsFee/esdtModifyCreator_test.go index f800268602b..1aa80ffd5c3 100644 --- a/integrationTests/vm/txsFee/esdtModifyCreator_test.go +++ b/integrationTests/vm/txsFee/esdtModifyCreator_test.go @@ -51,8 +51,8 @@ func runEsdtModifyCreatorTest(t *testing.T, tokenType string) { require.Equal(t, vmcommon.Ok, retCode) require.Nil(t, err) - defaultMetaData := getDefaultMetaData() - defaultMetaData.nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + defaultMetaData := GetDefaultMetaData() + defaultMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = createTokenTx(creatorAddr, creatorAddr, 100000, 1, defaultMetaData) retCode, err = testContext.TxProcessor.ProcessTransaction(tx) require.Equal(t, vmcommon.Ok, retCode) @@ -74,13 +74,13 @@ func esdtModifyCreatorTx( sndAddr []byte, rcvAddr []byte, gasLimit uint64, - metaData *metaData, + metaData *MetaData, ) *transaction.Transaction { txDataField := bytes.Join( [][]byte{ []byte(core.ESDTModifyCreator), - metaData.tokenId, - metaData.nonce, + metaData.TokenId, + metaData.Nonce, }, []byte("@"), ) diff --git a/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go b/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go index aa13bdf3ef6..fd4b9c84880 100644 --- a/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go +++ b/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go @@ -44,14 +44,14 @@ func runEsdtModifyRoyaltiesTest(t *testing.T, tokenType string) { require.Equal(t, vmcommon.Ok, retCode) require.Nil(t, err) - defaultMetaData := getDefaultMetaData() + defaultMetaData := GetDefaultMetaData() tx = createTokenTx(creatorAddr, creatorAddr, 100000, 1, defaultMetaData) retCode, err = testContext.TxProcessor.ProcessTransaction(tx) require.Equal(t, vmcommon.Ok, retCode) require.Nil(t, err) - defaultMetaData.nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - defaultMetaData.royalties = []byte(hex.EncodeToString(big.NewInt(20).Bytes())) + defaultMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + defaultMetaData.Royalties = []byte(hex.EncodeToString(big.NewInt(20).Bytes())) tx = esdtModifyRoyaltiesTx(creatorAddr, creatorAddr, 100000, defaultMetaData) retCode, err = testContext.TxProcessor.ProcessTransaction(tx) require.Equal(t, vmcommon.Ok, retCode) @@ -68,14 +68,14 @@ func esdtModifyRoyaltiesTx( sndAddr []byte, rcvAddr []byte, gasLimit uint64, - metaData *metaData, + metaData *MetaData, ) *transaction.Transaction { txDataField := bytes.Join( [][]byte{ []byte(core.ESDTModifyRoyalties), - metaData.tokenId, - metaData.nonce, - metaData.royalties, + metaData.TokenId, + metaData.Nonce, + metaData.Royalties, }, []byte("@"), ) diff --git a/integrationTests/vm/txsFee/esdtSetNewURIs_test.go b/integrationTests/vm/txsFee/esdtSetNewURIs_test.go index d7b89d5445b..2354f4b9625 100644 --- a/integrationTests/vm/txsFee/esdtSetNewURIs_test.go +++ b/integrationTests/vm/txsFee/esdtSetNewURIs_test.go @@ -45,14 +45,14 @@ func runEsdtSetNewURIsTest(t *testing.T, tokenType string) { require.Equal(t, vmcommon.Ok, retCode) require.Nil(t, err) - defaultMetaData := getDefaultMetaData() + defaultMetaData := GetDefaultMetaData() tx = createTokenTx(sndAddr, sndAddr, 100000, 1, defaultMetaData) retCode, err = testContext.TxProcessor.ProcessTransaction(tx) require.Equal(t, vmcommon.Ok, retCode) require.Nil(t, err) - defaultMetaData.uris = [][]byte{[]byte(hex.EncodeToString([]byte("newUri1"))), []byte(hex.EncodeToString([]byte("newUri2")))} - defaultMetaData.nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + defaultMetaData.Uris = [][]byte{[]byte(hex.EncodeToString([]byte("newUri1"))), []byte(hex.EncodeToString([]byte("newUri2")))} + defaultMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = esdtSetNewUrisTx(sndAddr, sndAddr, 100000, defaultMetaData) retCode, err = testContext.TxProcessor.ProcessTransaction(tx) require.Equal(t, vmcommon.Ok, retCode) @@ -69,15 +69,15 @@ func esdtSetNewUrisTx( sndAddr []byte, rcvAddr []byte, gasLimit uint64, - metaData *metaData, + metaData *MetaData, ) *transaction.Transaction { txDataField := bytes.Join( [][]byte{ []byte(core.ESDTSetNewURIs), - metaData.tokenId, - metaData.nonce, - metaData.uris[0], - metaData.uris[1], + metaData.TokenId, + metaData.Nonce, + metaData.Uris[0], + metaData.Uris[1], }, []byte("@"), ) From 2a41ecb31352568cb1297494d481c98c1e2e532d Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 30 May 2024 12:10:18 +0300 Subject: [PATCH 276/503] added meta esdt token --- .../vm/esdtImprovements_test.go | 124 ++++++++++++++++-- 1 file changed, 112 insertions(+), 12 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index cfcbd14fcf9..d8a7e76c6da 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -107,18 +107,40 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (before the activation of DynamicEsdtFlag)") + // issue metaESDT + metaESDTTicker := []byte("METATTICKER") + tx := issueMetaESDTTx(0, address.Bytes, metaESDTTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + metaESDTTokenID := txResult.Logs.Events[0].Topics[0] + + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + } + setAddressEsdtRoles(t, cs, address, metaESDTTokenID, roles) + + log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) + + esdtMetaData := txsFee.GetDefaultMetaData() + esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + // issue NFT nftTicker := []byte("NFTTICKER") - tx := issueNonFungibleTx(address.Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(1, address.Bytes, nftTicker, baseIssuingCost) - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - roles := [][]byte{ + roles = [][]byte{ []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } @@ -128,7 +150,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(1, address.Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(2, address.Bytes, sftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -148,7 +170,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(2, address.Bytes, nftTokenID, nftMetaData) + tx = nftCreateTx(3, address.Bytes, nftTokenID, nftMetaData) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -158,7 +180,14 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { sftMetaData := txsFee.GetDefaultMetaData() sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(3, address.Bytes, sftTokenID, sftMetaData) + tx = nftCreateTx(4, address.Bytes, sftTokenID, sftMetaData) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + tx = nftCreateTx(5, address.Bytes, metaESDTTokenID, esdtMetaData) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -172,6 +201,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) log.Info("Step 2. wait for DynamicEsdtFlag activation") @@ -187,7 +217,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { require.Nil(t, err) tx = utils.CreateESDTNFTTransferTx( - 4, + 6, address.Bytes, address2.Bytes, nftTokenID, @@ -207,7 +237,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) tx = utils.CreateESDTNFTTransferTx( - 5, + 7, address.Bytes, address2.Bytes, sftTokenID, @@ -226,21 +256,42 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) + tx = utils.CreateESDTNFTTransferTx( + 8, + address.Bytes, + address2.Bytes, + metaESDTTokenID, + 1, + big.NewInt(1), + minGasPrice, + 10_000_000, + "", + ) + tx.Version = 1 + tx.Signature = []byte("dummySig") + tx.ChainID = []byte(configs.ChainID) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + log.Info("Step 4. check that the metadata for all tokens is saved on the system account") checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) log.Info("Step 5. make an updateTokenID@tokenID function call on the ESDTSystem SC for all token types") - tx = updateTokenIDTx(6, address.Bytes, nftTokenID) + tx = updateTokenIDTx(9, address.Bytes, nftTokenID) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - tx = updateTokenIDTx(7, address.Bytes, sftTokenID) + tx = updateTokenIDTx(10, address.Bytes, sftTokenID) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -251,6 +302,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) log.Info("Step 7. transfer the tokens to another account") @@ -294,6 +346,26 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) + tx = utils.CreateESDTNFTTransferTx( + 2, + address2.Bytes, + address3.Bytes, + metaESDTTokenID, + 1, + big.NewInt(1), + minGasPrice, + 10_000_000, + "", + ) + tx.Version = 1 + tx.Signature = []byte("dummySig") + tx.ChainID = []byte(configs.ChainID) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + log.Info("Step 8. check that the metaData for the NFT was removed from the system account and moved to the user account") checkMetaData(t, cs, address3.Bytes, nftTokenID, shardID, nftMetaData) @@ -301,6 +373,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 9. check that the metaData for the rest of the tokens is still present on the system account and not on the userAccount") checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) } func checkMetaData( @@ -323,7 +396,34 @@ func checkMetaData( require.Equal(t, expectedMetaData.Attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) } -func issueNonFungibleTx(sndAdr []byte, ticker []byte, baseIssuingCost string) *transaction.Transaction { +func issueMetaESDTTx(nonce uint64, sndAdr []byte, ticker []byte, baseIssuingCost string) *transaction.Transaction { + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + + txDataField := bytes.Join( + [][]byte{ + []byte("registerMetaESDT"), + []byte(hex.EncodeToString([]byte("asdname"))), + []byte(hex.EncodeToString(ticker)), + []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + }, + []byte("@"), + ) + + return &transaction.Transaction{ + Nonce: nonce, + SndAddr: sndAdr, + RcvAddr: core.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: callValue, + ChainID: []byte(configs.ChainID), + Version: 1, + } +} + +func issueNonFungibleTx(nonce uint64, sndAdr []byte, ticker []byte, baseIssuingCost string) *transaction.Transaction { callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) txDataField := bytes.Join( @@ -336,7 +436,7 @@ func issueNonFungibleTx(sndAdr []byte, ticker []byte, baseIssuingCost string) *t ) return &transaction.Transaction{ - Nonce: 0, + Nonce: nonce, SndAddr: sndAdr, RcvAddr: core.ESDTSCAddress, GasLimit: 100_000_000, From 0eb10e6ff02760d46467df8c3fde050196cf10e2 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Thu, 30 May 2024 12:10:36 +0300 Subject: [PATCH 277/503] chain simulator tests refactor --- integrationTests/chainSimulator/common.go | 45 ++++ integrationTests/chainSimulator/interface.go | 8 +- .../chainSimulator/staking/common.go | 39 +-- .../chainSimulator/staking/jail/jail_test.go | 15 +- .../staking/stake/simpleStake_test.go | 27 +- .../staking/stake/stakeAndUnStake_test.go | 182 ++++++------- .../stakingProvider/delegation_test.go | 160 ++++++------ .../stakingProviderWithNodesinQueue_test.go | 11 +- integrationTests/chainSimulator/testing.go | 245 ++++++++++++++++++ node/chainSimulator/chainSimulator.go | 7 +- node/chainSimulator/chainSimulator_test.go | 239 +---------------- node/chainSimulator/errors.go | 9 +- node/chainSimulator/errors/errors.go | 12 + 13 files changed, 525 insertions(+), 474 deletions(-) create mode 100644 integrationTests/chainSimulator/common.go create mode 100644 integrationTests/chainSimulator/testing.go create mode 100644 node/chainSimulator/errors/errors.go diff --git a/integrationTests/chainSimulator/common.go b/integrationTests/chainSimulator/common.go new file mode 100644 index 00000000000..0e29c33e617 --- /dev/null +++ b/integrationTests/chainSimulator/common.go @@ -0,0 +1,45 @@ +package chainSimulator + +import ( + "math/big" + + "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" + + "github.com/multiversx/mx-chain-core-go/data/transaction" +) + +const ( + minGasPrice = 1000000000 + txVersion = 1 + mockTxSignature = "sig" + + // OkReturnCode the const for the ok return code + OkReturnCode = "ok" +) + +var ( + // ZeroValue the variable for the zero big int + ZeroValue = big.NewInt(0) + // OneEGLD the variable for one egld value + OneEGLD = big.NewInt(1000000000000000000) + // MinimumStakeValue the variable for the minimum stake value + MinimumStakeValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(2500)) + // InitialAmount the variable for initial minting amount in account + InitialAmount = big.NewInt(0).Mul(OneEGLD, big.NewInt(100)) +) + +// GenerateTransaction will generate a transaction based on input data +func GenerateTransaction(sender []byte, nonce uint64, receiver []byte, value *big.Int, data string, gasLimit uint64) *transaction.Transaction { + return &transaction.Transaction{ + Nonce: nonce, + Value: value, + SndAddr: sender, + RcvAddr: receiver, + Data: []byte(data), + GasLimit: gasLimit, + GasPrice: minGasPrice, + ChainID: []byte(configs.ChainID), + Version: txVersion, + Signature: []byte(mockTxSignature), + } +} diff --git a/integrationTests/chainSimulator/interface.go b/integrationTests/chainSimulator/interface.go index 759858a69c5..7aba83c5103 100644 --- a/integrationTests/chainSimulator/interface.go +++ b/integrationTests/chainSimulator/interface.go @@ -3,11 +3,12 @@ package chainSimulator import ( "math/big" + "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" + "github.com/multiversx/mx-chain-go/node/chainSimulator/process" + "github.com/multiversx/mx-chain-core-go/data/api" "github.com/multiversx/mx-chain-core-go/data/transaction" crypto "github.com/multiversx/mx-chain-crypto-go" - "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" - "github.com/multiversx/mx-chain-go/node/chainSimulator/process" ) // ChainSimulator defines the operations for an entity that can simulate operations of a chain @@ -16,6 +17,7 @@ type ChainSimulator interface { GenerateBlocksUntilEpochIsReached(targetEpoch int32) error AddValidatorKeys(validatorsPrivateKeys [][]byte) error GetNodeHandler(shardID uint32) process.NodeHandler + RemoveAccounts(addresses []string) error SendTxAndGenerateBlockTilTxIsExecuted(txToSend *transaction.Transaction, maxNumOfBlockToGenerateWhenExecutingTx int) (*transaction.ApiTransactionResult, error) SendTxsAndGenerateBlocksTilAreExecuted(txsToSend []*transaction.Transaction, maxNumOfBlocksToGenerateWhenExecutingTx int) ([]*transaction.ApiTransactionResult, error) SetStateMultiple(stateSlice []*dtos.AddressState) error @@ -24,4 +26,6 @@ type ChainSimulator interface { GetAccount(address dtos.WalletAddress) (api.AccountResponse, error) ForceResetValidatorStatisticsCache() error GetValidatorPrivateKeys() []crypto.PrivateKey + SetKeyValueForAddress(address string, keyValueMap map[string]string) error + Close() } diff --git a/integrationTests/chainSimulator/staking/common.go b/integrationTests/chainSimulator/staking/common.go index a8500a05995..4de97df500e 100644 --- a/integrationTests/chainSimulator/staking/common.go +++ b/integrationTests/chainSimulator/staking/common.go @@ -5,24 +5,17 @@ import ( "math/big" "testing" - "github.com/multiversx/mx-chain-core-go/core" - "github.com/multiversx/mx-chain-core-go/data/transaction" chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" - "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/vm" + + "github.com/multiversx/mx-chain-core-go/core" "github.com/stretchr/testify/require" ) const ( - minGasPrice = 1000000000 - txVersion = 1 - mockTxSignature = "sig" - - // OkReturnCode the const for the ok return code - OkReturnCode = "ok" // MockBLSSignature the const for a mocked bls signature MockBLSSignature = "010101" // GasLimitForStakeOperation the const for the gas limit value for the stake operation @@ -45,14 +38,8 @@ const ( ) var ( - // ZeroValue the variable for the zero big int - ZeroValue = big.NewInt(0) - // OneEGLD the variable for one egld value - OneEGLD = big.NewInt(1000000000000000000) //InitialDelegationValue the variable for the initial delegation value - InitialDelegationValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(1250)) - // MinimumStakeValue the variable for the minimum stake value - MinimumStakeValue = big.NewInt(0).Mul(OneEGLD, big.NewInt(2500)) + InitialDelegationValue = big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(1250)) ) // GetNonce will return the nonce of the provided address @@ -63,22 +50,6 @@ func GetNonce(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, ad return account.Nonce } -// GenerateTransaction will generate a transaction based on input data -func GenerateTransaction(sender []byte, nonce uint64, receiver []byte, value *big.Int, data string, gasLimit uint64) *transaction.Transaction { - return &transaction.Transaction{ - Nonce: nonce, - Value: value, - SndAddr: sender, - RcvAddr: receiver, - Data: []byte(data), - GasLimit: gasLimit, - GasPrice: minGasPrice, - ChainID: []byte(configs.ChainID), - Version: txVersion, - Signature: []byte(mockTxSignature), - } -} - // GetBLSKeyStatus will return the bls key status func GetBLSKeyStatus(t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, blsKey []byte) string { scQuery := &process.SCQuery{ @@ -90,7 +61,7 @@ func GetBLSKeyStatus(t *testing.T, metachainNode chainSimulatorProcess.NodeHandl } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) return string(result.ReturnData[0]) } @@ -105,7 +76,7 @@ func GetAllNodeStates(t *testing.T, metachainNode chainSimulatorProcess.NodeHand } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) m := make(map[string]string) status := "" diff --git a/integrationTests/chainSimulator/staking/jail/jail_test.go b/integrationTests/chainSimulator/staking/jail/jail_test.go index b92625f0f87..3e2a1652de9 100644 --- a/integrationTests/chainSimulator/staking/jail/jail_test.go +++ b/integrationTests/chainSimulator/staking/jail/jail_test.go @@ -9,6 +9,7 @@ import ( "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" + chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" @@ -96,12 +97,12 @@ func testChainSimulatorJailAndUnJail(t *testing.T, targetEpoch int32, nodeStatus _, blsKeys, err := chainSimulator.GenerateBlsPrivateKeys(1) require.Nil(t, err) - mintValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(3000)) + mintValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(3000)) walletAddress, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -117,7 +118,7 @@ func testChainSimulatorJailAndUnJail(t *testing.T, targetEpoch int32, nodeStatus // do an unjail transaction unJailValue, _ := big.NewInt(0).SetString("2500000000000000000", 10) txUnJailDataField := fmt.Sprintf("unJail@%s", blsKeys[0]) - txUnJail := staking.GenerateTransaction(walletAddress.Bytes, 1, vm.ValidatorSCAddress, unJailValue, txUnJailDataField, staking.GasLimitForStakeOperation) + txUnJail := chainSimulatorIntegrationTests.GenerateTransaction(walletAddress.Bytes, 1, vm.ValidatorSCAddress, unJailValue, txUnJailDataField, staking.GasLimitForStakeOperation) err = cs.GenerateBlocksUntilEpochIsReached(targetEpoch) require.Nil(t, err) @@ -202,12 +203,12 @@ func TestChainSimulator_FromQueueToAuctionList(t *testing.T) { err = cs.AddValidatorKeys([][]byte{privateKeys[1]}) require.Nil(t, err) - mintValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(6000)) + mintValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(6000)) walletAddress, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -222,7 +223,7 @@ func TestChainSimulator_FromQueueToAuctionList(t *testing.T) { // add one more node txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], staking.MockBLSSignature) - txStake = staking.GenerateTransaction(walletAddress.Bytes, 1, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake = chainSimulatorIntegrationTests.GenerateTransaction(walletAddress.Bytes, 1, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -234,7 +235,7 @@ func TestChainSimulator_FromQueueToAuctionList(t *testing.T) { // unJail the first node unJailValue, _ := big.NewInt(0).SetString("2500000000000000000", 10) txUnJailDataField := fmt.Sprintf("unJail@%s", blsKeys[0]) - txUnJail := staking.GenerateTransaction(walletAddress.Bytes, 2, vm.ValidatorSCAddress, unJailValue, txUnJailDataField, staking.GasLimitForStakeOperation) + txUnJail := chainSimulatorIntegrationTests.GenerateTransaction(walletAddress.Bytes, 2, vm.ValidatorSCAddress, unJailValue, txUnJailDataField, staking.GasLimitForStakeOperation) unJailTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnJail, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) diff --git a/integrationTests/chainSimulator/staking/stake/simpleStake_test.go b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go index 198044a00e4..dcccdf5c291 100644 --- a/integrationTests/chainSimulator/staking/stake/simpleStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go @@ -7,18 +7,19 @@ import ( "testing" "time" - "github.com/multiversx/mx-chain-core-go/core" - "github.com/multiversx/mx-chain-core-go/data/transaction" - "github.com/stretchr/testify/require" - "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" + chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/vm" + + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/stretchr/testify/require" ) // Test scenarios @@ -87,7 +88,7 @@ func testChainSimulatorSimpleStake(t *testing.T, targetEpoch int32, nodesStatus require.NotNil(t, cs) defer cs.Close() - mintValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(3000)) + mintValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(3000)) wallet1, err := cs.GenerateAndMintWalletAddress(0, mintValue) require.Nil(t, err) wallet2, err := cs.GenerateAndMintWalletAddress(0, mintValue) @@ -102,15 +103,15 @@ func testChainSimulatorSimpleStake(t *testing.T, targetEpoch int32, nodesStatus require.Nil(t, err) dataFieldTx1 := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - tx1Value := big.NewInt(0).Mul(big.NewInt(2499), staking.OneEGLD) - tx1 := staking.GenerateTransaction(wallet1.Bytes, 0, vm.ValidatorSCAddress, tx1Value, dataFieldTx1, staking.GasLimitForStakeOperation) + tx1Value := big.NewInt(0).Mul(big.NewInt(2499), chainSimulatorIntegrationTests.OneEGLD) + tx1 := chainSimulatorIntegrationTests.GenerateTransaction(wallet1.Bytes, 0, vm.ValidatorSCAddress, tx1Value, dataFieldTx1, staking.GasLimitForStakeOperation) dataFieldTx2 := fmt.Sprintf("stake@01@%s@%s", blsKeys[1], staking.MockBLSSignature) - tx2 := staking.GenerateTransaction(wallet3.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, dataFieldTx2, staking.GasLimitForStakeOperation) + tx2 := chainSimulatorIntegrationTests.GenerateTransaction(wallet3.Bytes, 0, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.MinimumStakeValue, dataFieldTx2, staking.GasLimitForStakeOperation) dataFieldTx3 := fmt.Sprintf("stake@01@%s@%s", blsKeys[2], staking.MockBLSSignature) - tx3Value := big.NewInt(0).Mul(big.NewInt(2501), staking.OneEGLD) - tx3 := staking.GenerateTransaction(wallet2.Bytes, 0, vm.ValidatorSCAddress, tx3Value, dataFieldTx3, staking.GasLimitForStakeOperation) + tx3Value := big.NewInt(0).Mul(big.NewInt(2501), chainSimulatorIntegrationTests.OneEGLD) + tx3 := chainSimulatorIntegrationTests.GenerateTransaction(wallet2.Bytes, 0, vm.ValidatorSCAddress, tx3Value, dataFieldTx3, staking.GasLimitForStakeOperation) results, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{tx1, tx2, tx3}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -200,13 +201,13 @@ func TestChainSimulator_StakingV4Step2APICalls(t *testing.T) { err = cs.AddValidatorKeys(privateKey) require.Nil(t, err) - mintValue := big.NewInt(0).Add(staking.MinimumStakeValue, staking.OneEGLD) + mintValue := big.NewInt(0).Add(chainSimulatorIntegrationTests.MinimumStakeValue, chainSimulatorIntegrationTests.OneEGLD) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) // Stake a new validator that should end up in auction in step 1 txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -226,7 +227,7 @@ func TestChainSimulator_StakingV4Step2APICalls(t *testing.T) { // re-stake the node txDataField = fmt.Sprintf("reStakeUnStakedNodes@%s", blsKeys[0]) - txReStake := staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, big.NewInt(0), txDataField, staking.GasLimitForStakeOperation) + txReStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, big.NewInt(0), txDataField, staking.GasLimitForStakeOperation) reStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txReStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, reStakeTx) diff --git a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index f9a12a53036..9594ceef679 100644 --- a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go @@ -8,13 +8,6 @@ import ( "testing" "time" - "github.com/multiversx/mx-chain-core-go/core" - coreAPI "github.com/multiversx/mx-chain-core-go/data/api" - "github.com/multiversx/mx-chain-core-go/data/transaction" - "github.com/multiversx/mx-chain-core-go/data/validator" - logger "github.com/multiversx/mx-chain-logger-go" - "github.com/stretchr/testify/require" - "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" @@ -26,6 +19,13 @@ import ( chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/vm" + + "github.com/multiversx/mx-chain-core-go/core" + coreAPI "github.com/multiversx/mx-chain-core-go/data/api" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-core-go/data/validator" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/stretchr/testify/require" ) const ( @@ -354,13 +354,13 @@ func testStakeUnStakeUnBond(t *testing.T, targetEpoch int32) { err = cs.AddValidatorKeys(privateKeys) require.Nil(t, err) - mintValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(2600)) + mintValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(2600)) walletAddressShardID := uint32(0) walletAddress, err := cs.GenerateAndMintWalletAddress(walletAddressShardID, mintValue) require.Nil(t, err) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -371,7 +371,7 @@ func testStakeUnStakeUnBond(t *testing.T, targetEpoch int32) { require.Equal(t, "staked", blsKeyStatus) // do unStake - txUnStake := staking.GenerateTransaction(walletAddress.Bytes, 1, vm.ValidatorSCAddress, staking.ZeroValue, fmt.Sprintf("unStake@%s", blsKeys[0]), staking.GasLimitForStakeOperation) + txUnStake := chainSimulatorIntegrationTests.GenerateTransaction(walletAddress.Bytes, 1, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, fmt.Sprintf("unStake@%s", blsKeys[0]), staking.GasLimitForStakeOperation) unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -383,13 +383,13 @@ func testStakeUnStakeUnBond(t *testing.T, targetEpoch int32) { require.Nil(t, err) // do unBond - txUnBond := staking.GenerateTransaction(walletAddress.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, fmt.Sprintf("unBondNodes@%s", blsKeys[0]), staking.GasLimitForStakeOperation) + txUnBond := chainSimulatorIntegrationTests.GenerateTransaction(walletAddress.Bytes, 2, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, fmt.Sprintf("unBondNodes@%s", blsKeys[0]), staking.GasLimitForStakeOperation) unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) // do claim - txClaim := staking.GenerateTransaction(walletAddress.Bytes, 3, vm.ValidatorSCAddress, staking.ZeroValue, "unBondTokens", staking.GasLimitForStakeOperation) + txClaim := chainSimulatorIntegrationTests.GenerateTransaction(walletAddress.Bytes, 3, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, "unBondTokens", staking.GasLimitForStakeOperation) claimTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txClaim, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, claimTx) @@ -401,7 +401,7 @@ func testStakeUnStakeUnBond(t *testing.T, targetEpoch int32) { walletAccount, _, err := cs.GetNodeHandler(walletAddressShardID).GetFacadeHandler().GetAccount(walletAddress.Bech32, coreAPI.AccountQueryOptions{}) require.Nil(t, err) walletBalanceBig, _ := big.NewInt(0).SetString(walletAccount.Balance, 10) - require.True(t, walletBalanceBig.Cmp(staking.MinimumStakeValue) > 0) + require.True(t, walletBalanceBig.Cmp(chainSimulatorIntegrationTests.MinimumStakeValue) > 0) } func checkTotalQualified(t *testing.T, auctionList []*common.AuctionListValidatorAPIResponse, expected int) { @@ -592,14 +592,14 @@ func testChainSimulatorDirectStakedNodesStakingFunds(t *testing.T, cs chainSimul metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(5010) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(chainSimulatorIntegrationTests.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Set(staking.MinimumStakeValue) + stakeValue := big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -607,9 +607,9 @@ func testChainSimulatorDirectStakedNodesStakingFunds(t *testing.T, cs chainSimul err = cs.GenerateBlocks(2) // allow the metachain to finalize the block that contains the staking of the node require.Nil(t, err) - stakeValue = big.NewInt(0).Set(staking.MinimumStakeValue) + stakeValue = big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue) txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], staking.MockBLSSignature) - txStake = staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake = chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -622,9 +622,9 @@ func testChainSimulatorDirectStakedNodesStakingFunds(t *testing.T, cs chainSimul log.Info("Step 2. Create from the owner of the staked nodes a tx to stake 1 EGLD") - stakeValue = big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(1)) + stakeValue = big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(1)) txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake = staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake = chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -640,7 +640,7 @@ func checkExpectedStakedValue(t *testing.T, metachainNode chainSimulatorProcess. totalStaked := getTotalStaked(t, metachainNode, blsKey) expectedStaked := big.NewInt(expectedValue) - expectedStaked = expectedStaked.Mul(staking.OneEGLD, expectedStaked) + expectedStaked = expectedStaked.Mul(chainSimulatorIntegrationTests.OneEGLD, expectedStaked) require.Equal(t, expectedStaked.String(), string(totalStaked)) } @@ -654,7 +654,7 @@ func getTotalStaked(t *testing.T, metachainNode chainSimulatorProcess.NodeHandle } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, staking.OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) return result.ReturnData[0] } @@ -828,14 +828,14 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivation(t *testing.T, cs metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(5010) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(chainSimulatorIntegrationTests.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Set(staking.MinimumStakeValue) + stakeValue := big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -845,9 +845,9 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivation(t *testing.T, cs testBLSKeyStaked(t, metachainNode, blsKeys[0]) - stakeValue = big.NewInt(0).Set(staking.MinimumStakeValue) + stakeValue = big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue) txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], staking.MockBLSSignature) - txStake = staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake = chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -863,9 +863,9 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivation(t *testing.T, cs log.Info("Step 2. Create from the owner of staked nodes a transaction to unstake 10 EGLD and send it to the network") unStakeValue := big.NewInt(10) - unStakeValue = unStakeValue.Mul(staking.OneEGLD, unStakeValue) + unStakeValue = unStakeValue.Mul(chainSimulatorIntegrationTests.OneEGLD, unStakeValue) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue.Bytes())) - txUnStake := staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + txUnStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForStakeOperation) unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -879,7 +879,7 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivation(t *testing.T, cs unStakedTokensAmount := getUnStakedTokensList(t, metachainNode, validatorOwner.Bytes) expectedUnStaked := big.NewInt(10) - expectedUnStaked = expectedUnStaked.Mul(staking.OneEGLD, expectedUnStaked) + expectedUnStaked = expectedUnStaked.Mul(chainSimulatorIntegrationTests.OneEGLD, expectedUnStaked) require.Equal(t, expectedUnStaked.String(), big.NewInt(0).SetBytes(unStakedTokensAmount).String()) log.Info("Step 4. Wait for change of epoch and check the outcome") @@ -899,7 +899,7 @@ func getUnStakedTokensList(t *testing.T, metachainNode chainSimulatorProcess.Nod } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, staking.OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) return result.ReturnData[0] } @@ -1117,14 +1117,14 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivationAndReactivation(t metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(6000) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(chainSimulatorIntegrationTests.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Set(staking.MinimumStakeValue) + stakeValue := big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1134,9 +1134,9 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivationAndReactivation(t testBLSKeyStaked(t, metachainNode, blsKeys[0]) - stakeValue = big.NewInt(0).Set(staking.MinimumStakeValue) + stakeValue = big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue) txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], staking.MockBLSSignature) - txStake = staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake = chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1152,9 +1152,9 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivationAndReactivation(t log.Info("Step 2. Create from the owner of staked nodes a transaction to unstake 10 EGLD and send it to the network") unStakeValue := big.NewInt(10) - unStakeValue = unStakeValue.Mul(staking.OneEGLD, unStakeValue) + unStakeValue = unStakeValue.Mul(chainSimulatorIntegrationTests.OneEGLD, unStakeValue) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue.Bytes())) - txUnStake := staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + txUnStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForStakeOperation) unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -1168,15 +1168,15 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivationAndReactivation(t unStakedTokensAmount := getUnStakedTokensList(t, metachainNode, validatorOwner.Bytes) expectedUnStaked := big.NewInt(10) - expectedUnStaked = expectedUnStaked.Mul(staking.OneEGLD, expectedUnStaked) + expectedUnStaked = expectedUnStaked.Mul(chainSimulatorIntegrationTests.OneEGLD, expectedUnStaked) require.Equal(t, expectedUnStaked.String(), big.NewInt(0).SetBytes(unStakedTokensAmount).String()) log.Info("Step 4. Create from the owner of staked nodes a transaction to stake 10 EGLD and send it to the network") newStakeValue := big.NewInt(10) - newStakeValue = newStakeValue.Mul(staking.OneEGLD, newStakeValue) + newStakeValue = newStakeValue.Mul(chainSimulatorIntegrationTests.OneEGLD, newStakeValue) txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake = staking.GenerateTransaction(validatorOwner.Bytes, 3, vm.ValidatorSCAddress, newStakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake = chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 3, vm.ValidatorSCAddress, newStakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1355,14 +1355,14 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsBeforeUnbonding(t *testi metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(10000) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(chainSimulatorIntegrationTests.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(2600)) + stakeValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(2600)) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1380,9 +1380,9 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsBeforeUnbonding(t *testi log.Info("Step 1. Create from the owner of staked nodes a transaction to withdraw the unstaked funds") unStakeValue := big.NewInt(10) - unStakeValue = unStakeValue.Mul(staking.OneEGLD, unStakeValue) + unStakeValue = unStakeValue.Mul(chainSimulatorIntegrationTests.OneEGLD, unStakeValue) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue.Bytes())) - txUnStake := staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + txUnStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForStakeOperation) unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -1394,7 +1394,7 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsBeforeUnbonding(t *testi testBLSKeyStaked(t, metachainNode, blsKeys[0]) txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) - txUnBond := staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForUnBond) + txUnBond := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForUnBond) unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) @@ -1413,10 +1413,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsBeforeUnbonding(t *testi } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, staking.OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) expectedUnStaked := big.NewInt(10) - expectedUnStaked = expectedUnStaked.Mul(staking.OneEGLD, expectedUnStaked) + expectedUnStaked = expectedUnStaked.Mul(chainSimulatorIntegrationTests.OneEGLD, expectedUnStaked) require.Equal(t, expectedUnStaked.String(), big.NewInt(0).SetBytes(result.ReturnData[0]).String()) // the owner balance should decrease only with the txs fee @@ -1597,14 +1597,14 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInFirstEpoch(t *testing. metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(10000) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(chainSimulatorIntegrationTests.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(2600)) + stakeValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(2600)) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1620,9 +1620,9 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInFirstEpoch(t *testing. balanceBeforeUnbonding, _ := big.NewInt(0).SetString(accountValidatorOwner.Balance, 10) unStakeValue := big.NewInt(10) - unStakeValue = unStakeValue.Mul(staking.OneEGLD, unStakeValue) + unStakeValue = unStakeValue.Mul(chainSimulatorIntegrationTests.OneEGLD, unStakeValue) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue.Bytes())) - txUnStake := staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + txUnStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForStakeOperation) unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -1642,10 +1642,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInFirstEpoch(t *testing. } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, staking.OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) expectedUnStaked := big.NewInt(10) - expectedUnStaked = expectedUnStaked.Mul(staking.OneEGLD, expectedUnStaked) + expectedUnStaked = expectedUnStaked.Mul(chainSimulatorIntegrationTests.OneEGLD, expectedUnStaked) require.Equal(t, expectedUnStaked.String(), big.NewInt(0).SetBytes(result.ReturnData[0]).String()) log.Info("Step 1. Wait for the unbonding epoch to start") @@ -1656,7 +1656,7 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInFirstEpoch(t *testing. log.Info("Step 2. Create from the owner of staked nodes a transaction to withdraw the unstaked funds") txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) - txUnBond := staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForUnBond) + txUnBond := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForUnBond) unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) @@ -1675,10 +1675,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInFirstEpoch(t *testing. } result, _, err = metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, staking.OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) expectedStaked := big.NewInt(2590) - expectedStaked = expectedStaked.Mul(staking.OneEGLD, expectedStaked) + expectedStaked = expectedStaked.Mul(chainSimulatorIntegrationTests.OneEGLD, expectedStaked) require.Equal(t, expectedStaked.String(), string(result.ReturnData[0])) // the owner balance should increase with the (10 EGLD - tx fee) @@ -1876,14 +1876,14 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(2700) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(chainSimulatorIntegrationTests.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(2600)) + stakeValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(2600)) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -1904,9 +1904,9 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, log.Info("Step 2. Send the transactions in consecutive epochs, one TX in each epoch.") unStakeValue1 := big.NewInt(11) - unStakeValue1 = unStakeValue1.Mul(staking.OneEGLD, unStakeValue1) + unStakeValue1 = unStakeValue1.Mul(chainSimulatorIntegrationTests.OneEGLD, unStakeValue1) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue1.Bytes())) - txUnStake := staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + txUnStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForStakeOperation) unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -1918,9 +1918,9 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, require.Nil(t, err) unStakeValue2 := big.NewInt(12) - unStakeValue2 = unStakeValue2.Mul(staking.OneEGLD, unStakeValue2) + unStakeValue2 = unStakeValue2.Mul(chainSimulatorIntegrationTests.OneEGLD, unStakeValue2) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue2.Bytes())) - txUnStake = staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + txUnStake = chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForStakeOperation) unStakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -1930,9 +1930,9 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, require.Nil(t, err) unStakeValue3 := big.NewInt(13) - unStakeValue3 = unStakeValue3.Mul(staking.OneEGLD, unStakeValue3) + unStakeValue3 = unStakeValue3.Mul(chainSimulatorIntegrationTests.OneEGLD, unStakeValue3) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue3.Bytes())) - txUnStake = staking.GenerateTransaction(validatorOwner.Bytes, 3, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + txUnStake = chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 3, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForStakeOperation) unStakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -1953,10 +1953,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, staking.OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) expectedUnStaked := big.NewInt(11) - expectedUnStaked = expectedUnStaked.Mul(staking.OneEGLD, expectedUnStaked) + expectedUnStaked = expectedUnStaked.Mul(chainSimulatorIntegrationTests.OneEGLD, expectedUnStaked) require.Equal(t, expectedUnStaked.String(), big.NewInt(0).SetBytes(result.ReturnData[0]).String()) scQuery = &process.SCQuery{ @@ -1968,10 +1968,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, } result, _, err = metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, staking.OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) expectedStaked := big.NewInt(2600 - 11 - 12 - 13) - expectedStaked = expectedStaked.Mul(staking.OneEGLD, expectedStaked) + expectedStaked = expectedStaked.Mul(chainSimulatorIntegrationTests.OneEGLD, expectedStaked) require.Equal(t, expectedStaked.String(), string(result.ReturnData[0])) log.Info("Step 3. Wait for the unbonding epoch to start") @@ -1983,7 +1983,7 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, log.Info("Step 4.1. Create from the owner of staked nodes a transaction to withdraw the unstaked funds") txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) - txUnBond := staking.GenerateTransaction(validatorOwner.Bytes, 4, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForUnBond) + txUnBond := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 4, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForUnBond) unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) @@ -2019,7 +2019,7 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, require.Nil(t, err) txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) - txUnBond = staking.GenerateTransaction(validatorOwner.Bytes, 5, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForUnBond) + txUnBond = chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 5, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForUnBond) unBondTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) @@ -2047,7 +2047,7 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, require.Nil(t, err) txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) - txUnBond = staking.GenerateTransaction(validatorOwner.Bytes, 6, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForUnBond) + txUnBond = chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 6, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForUnBond) unBondTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) @@ -2240,14 +2240,14 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(2700) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(chainSimulatorIntegrationTests.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - stakeValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(2600)) + stakeValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(2600)) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -2268,9 +2268,9 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs log.Info("Step 2. Send the transactions in consecutively in same epoch.") unStakeValue1 := big.NewInt(11) - unStakeValue1 = unStakeValue1.Mul(staking.OneEGLD, unStakeValue1) + unStakeValue1 = unStakeValue1.Mul(chainSimulatorIntegrationTests.OneEGLD, unStakeValue1) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue1.Bytes())) - txUnStake := staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + txUnStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForStakeOperation) unStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -2278,17 +2278,17 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs unStakeTxFee, _ := big.NewInt(0).SetString(unStakeTx.Fee, 10) unStakeValue2 := big.NewInt(12) - unStakeValue2 = unStakeValue2.Mul(staking.OneEGLD, unStakeValue2) + unStakeValue2 = unStakeValue2.Mul(chainSimulatorIntegrationTests.OneEGLD, unStakeValue2) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue2.Bytes())) - txUnStake = staking.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + txUnStake = chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 2, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForStakeOperation) unStakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) unStakeValue3 := big.NewInt(13) - unStakeValue3 = unStakeValue3.Mul(staking.OneEGLD, unStakeValue3) + unStakeValue3 = unStakeValue3.Mul(chainSimulatorIntegrationTests.OneEGLD, unStakeValue3) txDataField = fmt.Sprintf("unStakeTokens@%s", hex.EncodeToString(unStakeValue3.Bytes())) - txUnStake = staking.GenerateTransaction(validatorOwner.Bytes, 3, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForStakeOperation) + txUnStake = chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 3, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForStakeOperation) unStakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unStakeTx) @@ -2305,10 +2305,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, staking.OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) expectedUnStaked := big.NewInt(11 + 12 + 13) - expectedUnStaked = expectedUnStaked.Mul(staking.OneEGLD, expectedUnStaked) + expectedUnStaked = expectedUnStaked.Mul(chainSimulatorIntegrationTests.OneEGLD, expectedUnStaked) require.Equal(t, expectedUnStaked.String(), big.NewInt(0).SetBytes(result.ReturnData[0]).String()) scQuery = &process.SCQuery{ @@ -2320,10 +2320,10 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs } result, _, err = metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, staking.OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) expectedStaked := big.NewInt(2600 - 11 - 12 - 13) - expectedStaked = expectedStaked.Mul(staking.OneEGLD, expectedStaked) + expectedStaked = expectedStaked.Mul(chainSimulatorIntegrationTests.OneEGLD, expectedStaked) require.Equal(t, expectedStaked.String(), string(result.ReturnData[0])) log.Info("Step 3. Wait for the unbonding epoch to start") @@ -2335,7 +2335,7 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs log.Info("Step 4.1. Create from the owner of staked nodes a transaction to withdraw the unstaked funds") txDataField = fmt.Sprintf("unBondTokens@%s", blsKeys[0]) - txUnBond := staking.GenerateTransaction(validatorOwner.Bytes, 4, vm.ValidatorSCAddress, staking.ZeroValue, txDataField, staking.GasLimitForUnBond) + txUnBond := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 4, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, staking.GasLimitForUnBond) unBondTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnBond, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unBondTx) @@ -2586,12 +2586,12 @@ func createStakeTransaction(t *testing.T, cs chainSimulatorIntegrationTests.Chai err = cs.AddValidatorKeys(privateKey) require.Nil(t, err) - mintValue := big.NewInt(0).Add(staking.MinimumStakeValue, staking.OneEGLD) + mintValue := big.NewInt(0).Add(chainSimulatorIntegrationTests.MinimumStakeValue, chainSimulatorIntegrationTests.OneEGLD) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - return staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + return chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) } func unStakeOneActiveNode(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator) { diff --git a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index bdcd9435795..bb30199e95c 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go @@ -8,17 +8,6 @@ import ( "testing" "time" - "github.com/multiversx/mx-chain-core-go/core" - "github.com/multiversx/mx-chain-core-go/data/transaction" - "github.com/multiversx/mx-chain-core-go/data/validator" - dataVm "github.com/multiversx/mx-chain-core-go/data/vm" - "github.com/multiversx/mx-chain-crypto-go/signing" - "github.com/multiversx/mx-chain-crypto-go/signing/mcl" - mclsig "github.com/multiversx/mx-chain-crypto-go/signing/mcl/singlesig" - logger "github.com/multiversx/mx-chain-logger-go" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" @@ -29,6 +18,17 @@ import ( chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/vm" + + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-core-go/data/validator" + dataVm "github.com/multiversx/mx-chain-core-go/data/vm" + "github.com/multiversx/mx-chain-crypto-go/signing" + "github.com/multiversx/mx-chain-crypto-go/signing/mcl" + mclsig "github.com/multiversx/mx-chain-crypto-go/signing/mcl/singlesig" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) var log = logger.GetOrCreate("stakingProvider") @@ -291,7 +291,7 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi log.Info("Step 2. Set the initial state for the owner and the 2 delegators") mintValue := big.NewInt(3010) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(chainSimulatorIntegrationTests.OneEGLD, mintValue) validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) @@ -306,11 +306,11 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi "newValidatorOwner", validatorOwner.Bech32, "delegator1", delegator1.Bech32, "delegator2", delegator2.Bech32) log.Info("Step 3. Do a stake transaction for the validator key and test that the new key is on queue / auction list and the correct topup") - stakeValue := big.NewInt(0).Set(staking.MinimumStakeValue) - addedStakedValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(500)) + stakeValue := big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue) + addedStakedValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(500)) stakeValue.Add(stakeValue, addedStakedValue) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -322,7 +322,7 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi log.Info("Step 4. Execute the MakeNewContractFromValidatorData transaction and test that the key is on queue / auction list and the correct topup") txDataField = fmt.Sprintf("makeNewContractFromValidatorData@%s@%s", maxCap, hexServiceFee) - txConvert := staking.GenerateTransaction(validatorOwner.Bytes, 1, vm.DelegationManagerSCAddress, staking.ZeroValue, txDataField, gasLimitForConvertOperation) + txConvert := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 1, vm.DelegationManagerSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, gasLimitForConvertOperation) convertTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txConvert, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, convertTx) @@ -337,35 +337,35 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], addedStakedValue, 1) log.Info("Step 5. Execute 2 delegation operations of 100 EGLD each, check the topup is 700") - delegateValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(100)) - txDelegate1 := staking.GenerateTransaction(delegator1.Bytes, 0, delegationAddress, delegateValue, "delegate", gasLimitForDelegate) + delegateValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(100)) + txDelegate1 := chainSimulatorIntegrationTests.GenerateTransaction(delegator1.Bytes, 0, delegationAddress, delegateValue, "delegate", gasLimitForDelegate) delegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate1, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegate1Tx) - txDelegate2 := staking.GenerateTransaction(delegator2.Bytes, 0, delegationAddress, delegateValue, "delegate", gasLimitForDelegate) + txDelegate2 := chainSimulatorIntegrationTests.GenerateTransaction(delegator2.Bytes, 0, delegationAddress, delegateValue, "delegate", gasLimitForDelegate) delegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate2, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegate2Tx) - expectedTopUp := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(700)) + expectedTopUp := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(700)) testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], expectedTopUp, 1) log.Info("6. Execute 2 unDelegate operations of 100 EGLD each, check the topup is back to 500") - unDelegateValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(100)) + unDelegateValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(100)) txDataField = fmt.Sprintf("unDelegate@%s", hex.EncodeToString(unDelegateValue.Bytes())) - txUnDelegate1 := staking.GenerateTransaction(delegator1.Bytes, 1, delegationAddress, staking.ZeroValue, txDataField, gasLimitForDelegate) + txUnDelegate1 := chainSimulatorIntegrationTests.GenerateTransaction(delegator1.Bytes, 1, delegationAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, gasLimitForDelegate) unDelegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnDelegate1, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unDelegate1Tx) txDataField = fmt.Sprintf("unDelegate@%s", hex.EncodeToString(unDelegateValue.Bytes())) - txUnDelegate2 := staking.GenerateTransaction(delegator2.Bytes, 1, delegationAddress, staking.ZeroValue, txDataField, gasLimitForDelegate) + txUnDelegate2 := chainSimulatorIntegrationTests.GenerateTransaction(delegator2.Bytes, 1, delegationAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, gasLimitForDelegate) unDelegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUnDelegate2, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, unDelegate2Tx) - expectedTopUp = big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(500)) + expectedTopUp = big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(500)) testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], expectedTopUp, 1) } @@ -635,7 +635,7 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith2StakingContracts(t * log.Info("Step 2. Set the initial state for 2 owners") mintValue := big.NewInt(3010) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(chainSimulatorIntegrationTests.OneEGLD, mintValue) validatorOwnerA, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) @@ -648,12 +648,12 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith2StakingContracts(t * log.Info("Step 3. Do 2 stake transactions and test that the new keys are on queue / auction list and have the correct topup") - topupA := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(100)) - stakeValueA := big.NewInt(0).Add(staking.MinimumStakeValue, topupA) + topupA := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(100)) + stakeValueA := big.NewInt(0).Add(chainSimulatorIntegrationTests.MinimumStakeValue, topupA) txStakeA := generateStakeTransaction(t, cs, validatorOwnerA, blsKeys[0], stakeValueA) - topupB := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(200)) - stakeValueB := big.NewInt(0).Add(staking.MinimumStakeValue, topupB) + topupB := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(200)) + stakeValueB := big.NewInt(0).Add(chainSimulatorIntegrationTests.MinimumStakeValue, topupB) txStakeB := generateStakeTransaction(t, cs, validatorOwnerB, blsKeys[1], stakeValueB) stakeTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStakeA, txStakeB}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) @@ -884,7 +884,7 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta log.Info("Step 2. Set the initial state for 1 owner and 1 delegator") mintValue := big.NewInt(10001) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(chainSimulatorIntegrationTests.OneEGLD, mintValue) owner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) @@ -897,8 +897,8 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta log.Info("Step 3. Do a stake transaction and test that the new key is on queue / auction list and has the correct topup") - topup := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(99)) - stakeValue := big.NewInt(0).Add(staking.MinimumStakeValue, topup) + topup := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(99)) + stakeValue := big.NewInt(0).Add(chainSimulatorIntegrationTests.MinimumStakeValue, topup) txStake := generateStakeTransaction(t, cs, owner, blsKeys[0], stakeValue) stakeTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStake}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) @@ -928,17 +928,17 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta log.Info("Step 5. Add 2 nodes in the staking contract") txDataFieldAddNodes := fmt.Sprintf("addNodes@%s@%s@%s@%s", blsKeys[1], staking.MockBLSSignature+"02", blsKeys[2], staking.MockBLSSignature+"03") ownerNonce := staking.GetNonce(t, cs, owner) - txAddNodes := staking.GenerateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldAddNodes, staking.GasLimitForStakeOperation) + txAddNodes := chainSimulatorIntegrationTests.GenerateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldAddNodes, staking.GasLimitForStakeOperation) addNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txAddNodes}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.Equal(t, 1, len(addNodesTxs)) log.Info("Step 6. Delegate 5000 EGLD to the contract") - delegateValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(5000)) + delegateValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(5000)) txDataFieldDelegate := "delegate" delegatorNonce := staking.GetNonce(t, cs, delegator) - txDelegate := staking.GenerateTransaction(delegator.Bytes, delegatorNonce, delegationAddress, delegateValue, txDataFieldDelegate, staking.GasLimitForStakeOperation) + txDelegate := chainSimulatorIntegrationTests.GenerateTransaction(delegator.Bytes, delegatorNonce, delegationAddress, delegateValue, txDataFieldDelegate, staking.GasLimitForStakeOperation) delegateTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txDelegate}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -947,7 +947,7 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta log.Info("Step 7. Stake the 2 nodes") txDataFieldStakeNodes := fmt.Sprintf("stakeNodes@%s@%s", blsKeys[1], blsKeys[2]) ownerNonce = staking.GetNonce(t, cs, owner) - txStakeNodes := staking.GenerateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldStakeNodes, staking.GasLimitForStakeOperation) + txStakeNodes := chainSimulatorIntegrationTests.GenerateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldStakeNodes, staking.GasLimitForStakeOperation) stakeNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStakeNodes}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -963,7 +963,7 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta txDataFieldUnStakeNodes := fmt.Sprintf("unStakeNodes@%s@%s", blsKeys[1], blsKeys[2]) ownerNonce = staking.GetNonce(t, cs, owner) - txUnStakeNodes := staking.GenerateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldUnStakeNodes, staking.GasLimitForStakeOperation) + txUnStakeNodes := chainSimulatorIntegrationTests.GenerateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldUnStakeNodes, staking.GasLimitForStakeOperation) unStakeNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txUnStakeNodes}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -981,7 +981,7 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta txDataFieldUnBondNodes := fmt.Sprintf("unBondNodes@%s@%s", blsKeys[1], blsKeys[2]) ownerNonce = staking.GetNonce(t, cs, owner) - txUnBondNodes := staking.GenerateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldUnBondNodes, staking.GasLimitForStakeOperation) + txUnBondNodes := chainSimulatorIntegrationTests.GenerateTransaction(owner.Bytes, ownerNonce, delegationAddress, big.NewInt(0), txDataFieldUnBondNodes, staking.GasLimitForStakeOperation) unBondNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txUnBondNodes}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1010,7 +1010,7 @@ func generateStakeTransaction( require.Nil(t, err) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeyHex, staking.MockBLSSignature) - return staking.GenerateTransaction(owner.Bytes, account.Nonce, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + return chainSimulatorIntegrationTests.GenerateTransaction(owner.Bytes, account.Nonce, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) } func generateConvertToStakingProviderTransaction( @@ -1022,7 +1022,7 @@ func generateConvertToStakingProviderTransaction( require.Nil(t, err) txDataField := fmt.Sprintf("makeNewContractFromValidatorData@%s@%s", maxCap, hexServiceFee) - return staking.GenerateTransaction(owner.Bytes, account.Nonce, vm.DelegationManagerSCAddress, staking.ZeroValue, txDataField, gasLimitForConvertOperation) + return chainSimulatorIntegrationTests.GenerateTransaction(owner.Bytes, account.Nonce, vm.DelegationManagerSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, gasLimitForConvertOperation) } // Test description @@ -1218,7 +1218,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Nil(t, err) metachainNode := cs.GetNodeHandler(core.MetachainShardId) - initialFunds := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(10000)) // 10000 EGLD for each + initialFunds := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(10000)) // 10000 EGLD for each validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, initialFunds) require.Nil(t, err) @@ -1228,8 +1228,8 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat delegator2, err := cs.GenerateAndMintWalletAddress(core.AllShardId, initialFunds) require.Nil(t, err) - maxDelegationCap := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(51000)) // 51000 EGLD cap - txCreateDelegationContract := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.DelegationManagerSCAddress, staking.InitialDelegationValue, + maxDelegationCap := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(51000)) // 51000 EGLD cap + txCreateDelegationContract := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.DelegationManagerSCAddress, staking.InitialDelegationValue, fmt.Sprintf("createNewDelegationContract@%s@%s", hex.EncodeToString(maxDelegationCap.Bytes()), hexServiceFee), gasLimitForDelegationContractCreationOperation) createDelegationContractTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txCreateDelegationContract, staking.MaxNumOfBlockToGenerateWhenExecutingTx) @@ -1261,7 +1261,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Nil(t, err) signatures := getSignatures(delegationContractAddressBytes, validatorSecretKeysBytes) - txAddNodes := staking.GenerateTransaction(validatorOwner.Bytes, 1, delegationContractAddressBytes, staking.ZeroValue, addNodesTxData(blsKeys, signatures), gasLimitForAddNodesOperation) + txAddNodes := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 1, delegationContractAddressBytes, chainSimulatorIntegrationTests.ZeroValue, addNodesTxData(blsKeys, signatures), gasLimitForAddNodesOperation) addNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txAddNodes, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, addNodesTx) @@ -1286,7 +1286,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Equal(t, staking.InitialDelegationValue, big.NewInt(0).SetBytes(output.ReturnData[0])) // Step 3: Perform delegation operations - txDelegate1 := staking.GenerateTransaction(delegator1.Bytes, 0, delegationContractAddressBytes, staking.InitialDelegationValue, "delegate", gasLimitForDelegate) + txDelegate1 := chainSimulatorIntegrationTests.GenerateTransaction(delegator1.Bytes, 0, delegationContractAddressBytes, staking.InitialDelegationValue, "delegate", gasLimitForDelegate) delegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate1, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegate1Tx) @@ -1302,7 +1302,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Nil(t, err) require.Equal(t, staking.InitialDelegationValue, big.NewInt(0).SetBytes(output.ReturnData[0])) - txDelegate2 := staking.GenerateTransaction(delegator2.Bytes, 0, delegationContractAddressBytes, staking.InitialDelegationValue, "delegate", gasLimitForDelegate) + txDelegate2 := chainSimulatorIntegrationTests.GenerateTransaction(delegator2.Bytes, 0, delegationContractAddressBytes, staking.InitialDelegationValue, "delegate", gasLimitForDelegate) delegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate2, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegate2Tx) @@ -1320,7 +1320,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat // Step 4: Perform stakeNodes - txStakeNodes := staking.GenerateTransaction(validatorOwner.Bytes, 2, delegationContractAddressBytes, staking.ZeroValue, fmt.Sprintf("stakeNodes@%s", blsKeys[0]), staking.GasLimitForStakeOperation) + txStakeNodes := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 2, delegationContractAddressBytes, chainSimulatorIntegrationTests.ZeroValue, fmt.Sprintf("stakeNodes@%s", blsKeys[0]), staking.GasLimitForStakeOperation) stakeNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStakeNodes, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeNodesTx) @@ -1347,7 +1347,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat // The nodes should remain in the staked state // The total active stake should be reduced by the amount undelegated - txUndelegate1 := staking.GenerateTransaction(delegator1.Bytes, 1, delegationContractAddressBytes, staking.ZeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(staking.InitialDelegationValue.Bytes())), gasLimitForUndelegateOperation) + txUndelegate1 := chainSimulatorIntegrationTests.GenerateTransaction(delegator1.Bytes, 1, delegationContractAddressBytes, chainSimulatorIntegrationTests.ZeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(staking.InitialDelegationValue.Bytes())), gasLimitForUndelegateOperation) undelegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUndelegate1, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, undelegate1Tx) @@ -1361,7 +1361,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator1.Bytes}) require.Nil(t, err) - require.Equal(t, staking.ZeroValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, chainSimulatorIntegrationTests.ZeroValue, big.NewInt(0).SetBytes(output.ReturnData[0])) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getAllNodeStates", nil) require.Nil(t, err) @@ -1375,7 +1375,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat // The nodes should change to unStaked state // The total active stake should be reduced by the amount undelegated - txUndelegate2 := staking.GenerateTransaction(delegator2.Bytes, 1, delegationContractAddressBytes, staking.ZeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(staking.InitialDelegationValue.Bytes())), gasLimitForUndelegateOperation) + txUndelegate2 := chainSimulatorIntegrationTests.GenerateTransaction(delegator2.Bytes, 1, delegationContractAddressBytes, chainSimulatorIntegrationTests.ZeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(staking.InitialDelegationValue.Bytes())), gasLimitForUndelegateOperation) undelegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUndelegate2, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, undelegate2Tx) @@ -1383,7 +1383,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, "1250000000000000000000", big.NewInt(0).SetBytes(output.ReturnData[0]).String()) - require.Equal(t, staking.ZeroValue, getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) + require.Equal(t, chainSimulatorIntegrationTests.ZeroValue, getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator2.Bytes}) require.Nil(t, err) @@ -1600,7 +1600,7 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati require.Nil(t, err) metachainNode := cs.GetNodeHandler(core.MetachainShardId) - initialFunds := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(10000)) // 10000 EGLD for each + initialFunds := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(10000)) // 10000 EGLD for each validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, initialFunds) require.Nil(t, err) @@ -1615,8 +1615,8 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati // Step 3: Create a new delegation contract - maxDelegationCap := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(3000)) // 3000 EGLD cap - txCreateDelegationContract := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.DelegationManagerSCAddress, staking.InitialDelegationValue, + maxDelegationCap := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(3000)) // 3000 EGLD cap + txCreateDelegationContract := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.DelegationManagerSCAddress, staking.InitialDelegationValue, fmt.Sprintf("createNewDelegationContract@%s@%s", hex.EncodeToString(maxDelegationCap.Bytes()), hexServiceFee), gasLimitForDelegationContractCreationOperation) createDelegationContractTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txCreateDelegationContract, staking.MaxNumOfBlockToGenerateWhenExecutingTx) @@ -1636,7 +1636,7 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati require.Nil(t, err) signatures := getSignatures(delegationContractAddress, validatorSecretKeysBytes) - txAddNodes := staking.GenerateTransaction(validatorOwner.Bytes, 1, delegationContractAddress, staking.ZeroValue, addNodesTxData(blsKeys, signatures), gasLimitForAddNodesOperation) + txAddNodes := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 1, delegationContractAddress, chainSimulatorIntegrationTests.ZeroValue, addNodesTxData(blsKeys, signatures), gasLimitForAddNodesOperation) addNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txAddNodes, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, addNodesTx) @@ -1653,7 +1653,7 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati require.Equal(t, staking.InitialDelegationValue, big.NewInt(0).SetBytes(output.ReturnData[0])) // Step 3: Perform delegation operations - tx1delegatorA := staking.GenerateTransaction(delegatorA.Bytes, 0, delegationContractAddress, staking.InitialDelegationValue, "delegate", gasLimitForDelegate) + tx1delegatorA := chainSimulatorIntegrationTests.GenerateTransaction(delegatorA.Bytes, 0, delegationContractAddress, staking.InitialDelegationValue, "delegate", gasLimitForDelegate) delegatorATx1, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx1delegatorA, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegatorATx1) @@ -1669,8 +1669,8 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati require.Nil(t, err) require.Equal(t, staking.InitialDelegationValue, big.NewInt(0).SetBytes(output.ReturnData[0])) - delegateValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(501)) // 501 EGLD - tx1delegatorB := staking.GenerateTransaction(delegatorB.Bytes, 0, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) + delegateValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(501)) // 501 EGLD + tx1delegatorB := chainSimulatorIntegrationTests.GenerateTransaction(delegatorB.Bytes, 0, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) delegatorBTx1, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx1delegatorB, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegatorBTx1) @@ -1688,12 +1688,12 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati // Step 4: Perform stakeNodes - txStakeNodes := staking.GenerateTransaction(validatorOwner.Bytes, 2, delegationContractAddress, staking.ZeroValue, fmt.Sprintf("stakeNodes@%s", blsKeys[0]), gasLimitForDelegate) + txStakeNodes := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 2, delegationContractAddress, chainSimulatorIntegrationTests.ZeroValue, fmt.Sprintf("stakeNodes@%s", blsKeys[0]), gasLimitForDelegate) stakeNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStakeNodes, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeNodesTx) - require.Equal(t, staking.ZeroValue.String(), getBLSTopUpValue(t, metachainNode, delegationContractAddress).String()) + require.Equal(t, chainSimulatorIntegrationTests.ZeroValue.String(), getBLSTopUpValue(t, metachainNode, delegationContractAddress).String()) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getAllNodeStates", nil) require.Nil(t, err) @@ -1706,9 +1706,9 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati err = cs.GenerateBlocks(2) // allow the metachain to finalize the block that contains the staking of the node require.Nil(t, err) - testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationContractAddress, blsKeys[0], staking.ZeroValue, 1) + testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationContractAddress, blsKeys[0], chainSimulatorIntegrationTests.ZeroValue, 1) - tx2delegatorB := staking.GenerateTransaction(delegatorB.Bytes, 1, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) + tx2delegatorB := chainSimulatorIntegrationTests.GenerateTransaction(delegatorB.Bytes, 1, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) delegatorBTx2, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx2delegatorB, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegatorBTx2) @@ -1719,15 +1719,15 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) - require.Equal(t, staking.ZeroValue.String(), getBLSTopUpValue(t, metachainNode, delegationContractAddress).String()) + require.Equal(t, chainSimulatorIntegrationTests.ZeroValue.String(), getBLSTopUpValue(t, metachainNode, delegationContractAddress).String()) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorB.Bytes}) require.Nil(t, err) require.Zero(t, len(output.ReturnData)) require.Equal(t, "view function works only for existing delegators", output.ReturnMessage) - delegateValue = big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(500)) // 500 EGLD - tx3delegatorB := staking.GenerateTransaction(delegatorB.Bytes, 2, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) + delegateValue = big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(500)) // 500 EGLD + tx3delegatorB := chainSimulatorIntegrationTests.GenerateTransaction(delegatorB.Bytes, 2, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) delegatorBTx3, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx3delegatorB, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegatorBTx3) @@ -1743,8 +1743,8 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati require.Nil(t, err) require.Equal(t, delegateValue, big.NewInt(0).SetBytes(output.ReturnData[0])) - delegateValue = big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(20)) // 20 EGLD - tx1DelegatorC := staking.GenerateTransaction(delegatorC.Bytes, 0, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) + delegateValue = big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(20)) // 20 EGLD + tx1DelegatorC := chainSimulatorIntegrationTests.GenerateTransaction(delegatorC.Bytes, 0, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) delegatorCTx1, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx1DelegatorC, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegatorCTx1) @@ -1818,7 +1818,7 @@ func getBLSTopUpValue(t *testing.T, metachainNode chainSimulatorProcess.NodeHand } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, staking.OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) if len(result.ReturnData[0]) == 0 { return big.NewInt(0) @@ -1998,7 +1998,7 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat metachainNode := cs.GetNodeHandler(core.MetachainShardId) mintValue := big.NewInt(3000) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(chainSimulatorIntegrationTests.OneEGLD, mintValue) validatorA, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) @@ -2007,11 +2007,11 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat require.Nil(t, err) log.Info("Step 1. User A: - stake 1 node to have 100 egld more than minimum stake value") - stakeValue := big.NewInt(0).Set(staking.MinimumStakeValue) - addedStakedValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(100)) + stakeValue := big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue) + addedStakedValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(100)) stakeValue.Add(stakeValue, addedStakedValue) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(validatorA.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorA.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -2024,7 +2024,7 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat log.Info("Step 2. Execute MakeNewContractFromValidatorData for User A") txDataField = fmt.Sprintf("makeNewContractFromValidatorData@%s@%s", maxCap, hexServiceFee) - txConvert := staking.GenerateTransaction(validatorA.Bytes, 1, vm.DelegationManagerSCAddress, staking.ZeroValue, txDataField, gasLimitForConvertOperation) + txConvert := chainSimulatorIntegrationTests.GenerateTransaction(validatorA.Bytes, 1, vm.DelegationManagerSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, gasLimitForConvertOperation) convertTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txConvert, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, convertTx) @@ -2037,11 +2037,11 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], addedStakedValue, 1) log.Info("Step 3. User B: - stake 1 node to have 100 egld more") - stakeValue = big.NewInt(0).Set(staking.MinimumStakeValue) - addedStakedValue = big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(100)) + stakeValue = big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue) + addedStakedValue = big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(100)) stakeValue.Add(stakeValue, addedStakedValue) txDataField = fmt.Sprintf("stake@01@%s@%s", blsKeys[1], staking.MockBLSSignature) - txStake = staking.GenerateTransaction(validatorB.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) + txStake = chainSimulatorIntegrationTests.GenerateTransaction(validatorB.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -2060,7 +2060,7 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat log.Info("Step 4. User A : whitelistForMerge@addressB") txDataField = fmt.Sprintf("whitelistForMerge@%s", hex.EncodeToString(validatorB.Bytes)) - whitelistForMerge := staking.GenerateTransaction(validatorA.Bytes, 2, delegationAddress, staking.ZeroValue, txDataField, gasLimitForDelegate) + whitelistForMerge := chainSimulatorIntegrationTests.GenerateTransaction(validatorA.Bytes, 2, delegationAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, gasLimitForDelegate) whitelistForMergeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(whitelistForMerge, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, whitelistForMergeTx) @@ -2071,7 +2071,7 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat log.Info("Step 5. User A : mergeValidatorToDelegationWithWhitelist") txDataField = fmt.Sprintf("mergeValidatorToDelegationWithWhitelist@%s", hex.EncodeToString(delegationAddress)) - txConvert = staking.GenerateTransaction(validatorB.Bytes, 1, vm.DelegationManagerSCAddress, staking.ZeroValue, txDataField, gasLimitForMergeOperation) + txConvert = chainSimulatorIntegrationTests.GenerateTransaction(validatorB.Bytes, 1, vm.DelegationManagerSCAddress, chainSimulatorIntegrationTests.ZeroValue, txDataField, gasLimitForMergeOperation) convertTx, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(txConvert, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, convertTx) @@ -2085,7 +2085,7 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat decodedBLSKey1, _ = hex.DecodeString(blsKeys[1]) require.Equal(t, delegationAddress, getBLSKeyOwner(t, metachainNode, decodedBLSKey1)) - expectedTopUpValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(200)) + expectedTopUpValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(200)) require.Equal(t, expectedTopUpValue, getBLSTopUpValue(t, metachainNode, delegationAddress)) } @@ -2099,7 +2099,7 @@ func getBLSKeyOwner(t *testing.T, metachainNode chainSimulatorProcess.NodeHandle } result, _, err := metachainNode.GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) - require.Equal(t, staking.OkReturnCode, result.ReturnCode) + require.Equal(t, chainSimulatorIntegrationTests.OkReturnCode, result.ReturnCode) return result.ReturnData[0] } diff --git a/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go b/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go index 649f807e6ce..05b3f1b8eac 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go @@ -8,6 +8,7 @@ import ( "time" "github.com/multiversx/mx-chain-go/config" + chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" @@ -73,7 +74,7 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati require.NotNil(t, cs) defer cs.Close() - mintValue := big.NewInt(0).Mul(big.NewInt(5000), staking.OneEGLD) + mintValue := big.NewInt(0).Mul(big.NewInt(5000), chainSimulatorIntegrationTests.OneEGLD) validatorOwner, err := cs.GenerateAndMintWalletAddress(0, mintValue) require.Nil(t, err) require.Nil(t, err) @@ -84,7 +85,7 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati // create delegation contract stakeValue, _ := big.NewInt(0).SetString("4250000000000000000000", 10) dataField := "createNewDelegationContract@00@0ea1" - txStake := staking.GenerateTransaction(validatorOwner.Bytes, staking.GetNonce(t, cs, validatorOwner), vm.DelegationManagerSCAddress, stakeValue, dataField, 80_000_000) + txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, staking.GetNonce(t, cs, validatorOwner), vm.DelegationManagerSCAddress, stakeValue, dataField, 80_000_000) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTx) @@ -98,14 +99,14 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati txDataFieldAddNodes := fmt.Sprintf("addNodes@%s@%s", blsKeys[0], staking.MockBLSSignature+"02") ownerNonce := staking.GetNonce(t, cs, validatorOwner) - txAddNodes := staking.GenerateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), txDataFieldAddNodes, staking.GasLimitForStakeOperation) + txAddNodes := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), txDataFieldAddNodes, staking.GasLimitForStakeOperation) addNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txAddNodes, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, addNodesTx) txDataFieldStakeNodes := fmt.Sprintf("stakeNodes@%s", blsKeys[0]) ownerNonce = staking.GetNonce(t, cs, validatorOwner) - txStakeNodes := staking.GenerateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), txDataFieldStakeNodes, staking.GasLimitForStakeOperation) + txStakeNodes := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), txDataFieldStakeNodes, staking.GasLimitForStakeOperation) stakeNodesTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txStakeNodes}, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -129,7 +130,7 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati ownerNonce = staking.GetNonce(t, cs, validatorOwner) reStakeTxData := fmt.Sprintf("reStakeUnStakedNodes@%s", blsKeys[0]) - reStakeNodes := staking.GenerateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), reStakeTxData, staking.GasLimitForStakeOperation) + reStakeNodes := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, ownerNonce, delegationAddressBytes, big.NewInt(0), reStakeTxData, staking.GasLimitForStakeOperation) reStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(reStakeNodes, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, reStakeTx) diff --git a/integrationTests/chainSimulator/testing.go b/integrationTests/chainSimulator/testing.go new file mode 100644 index 00000000000..605bf76ac7f --- /dev/null +++ b/integrationTests/chainSimulator/testing.go @@ -0,0 +1,245 @@ +package chainSimulator + +import ( + "encoding/base64" + "math/big" + "testing" + "time" + + "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" + "github.com/multiversx/mx-chain-go/node/chainSimulator/errors" + chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" + "github.com/multiversx/mx-chain-go/process" + + "github.com/multiversx/mx-chain-core-go/core" + coreAPI "github.com/multiversx/mx-chain-core-go/data/api" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +// CheckSetState - +func CheckSetState(t *testing.T, chainSimulator ChainSimulator, nodeHandler chainSimulatorProcess.NodeHandler) { + keyValueMap := map[string]string{ + "01": "01", + "02": "02", + } + + address := "erd1qtc600lryvytxuy4h7vn7xmsy5tw6vuw3tskr75cwnmv4mnyjgsq6e5zgj" + err := chainSimulator.SetKeyValueForAddress(address, keyValueMap) + require.Nil(t, err) + + err = chainSimulator.GenerateBlocks(1) + require.Nil(t, err) + + keyValuePairs, _, err := nodeHandler.GetFacadeHandler().GetKeyValuePairs(address, coreAPI.AccountQueryOptions{}) + require.Nil(t, err) + require.Equal(t, keyValueMap, keyValuePairs) +} + +// CheckSetEntireState - +func CheckSetEntireState(t *testing.T, chainSimulator ChainSimulator, nodeHandler chainSimulatorProcess.NodeHandler, accountState *dtos.AddressState) { + err := chainSimulator.SetStateMultiple([]*dtos.AddressState{accountState}) + require.Nil(t, err) + + err = chainSimulator.GenerateBlocks(30) + require.Nil(t, err) + + scAddress, _ := nodeHandler.GetCoreComponents().AddressPubKeyConverter().Decode(accountState.Address) + res, _, err := nodeHandler.GetFacadeHandler().ExecuteSCQuery(&process.SCQuery{ + ScAddress: scAddress, + FuncName: "getSum", + CallerAddr: nil, + BlockNonce: core.OptionalUint64{}, + }) + require.Nil(t, err) + + counterValue := big.NewInt(0).SetBytes(res.ReturnData[0]).Int64() + require.Equal(t, 10, int(counterValue)) + + time.Sleep(time.Second) + + account, _, err := nodeHandler.GetFacadeHandler().GetAccount(accountState.Address, coreAPI.AccountQueryOptions{}) + require.Nil(t, err) + require.Equal(t, accountState.Balance, account.Balance) + require.Equal(t, accountState.DeveloperRewards, account.DeveloperReward) + require.Equal(t, accountState.Code, account.Code) + require.Equal(t, accountState.CodeHash, base64.StdEncoding.EncodeToString(account.CodeHash)) + require.Equal(t, accountState.CodeMetadata, base64.StdEncoding.EncodeToString(account.CodeMetadata)) + require.Equal(t, accountState.Owner, account.OwnerAddress) + require.Equal(t, accountState.RootHash, base64.StdEncoding.EncodeToString(account.RootHash)) +} + +// CheckSetEntireStateWithRemoval - +func CheckSetEntireStateWithRemoval(t *testing.T, chainSimulator ChainSimulator, nodeHandler chainSimulatorProcess.NodeHandler, accountState *dtos.AddressState) { + // activate the auto balancing tries so the results will be the same + err := chainSimulator.GenerateBlocks(30) + require.Nil(t, err) + + err = chainSimulator.SetStateMultiple([]*dtos.AddressState{accountState}) + require.Nil(t, err) + + err = chainSimulator.GenerateBlocks(2) + require.Nil(t, err) + + scAddress, _ := nodeHandler.GetCoreComponents().AddressPubKeyConverter().Decode(accountState.Address) + res, _, err := nodeHandler.GetFacadeHandler().ExecuteSCQuery(&process.SCQuery{ + ScAddress: scAddress, + FuncName: "getSum", + CallerAddr: nil, + BlockNonce: core.OptionalUint64{}, + }) + require.Nil(t, err) + + counterValue := big.NewInt(0).SetBytes(res.ReturnData[0]).Int64() + require.Equal(t, 10, int(counterValue)) + + account, _, err := nodeHandler.GetFacadeHandler().GetAccount(accountState.Address, coreAPI.AccountQueryOptions{}) + require.Nil(t, err) + require.Equal(t, accountState.Balance, account.Balance) + require.Equal(t, accountState.DeveloperRewards, account.DeveloperReward) + require.Equal(t, accountState.Code, account.Code) + require.Equal(t, accountState.CodeHash, base64.StdEncoding.EncodeToString(account.CodeHash)) + require.Equal(t, accountState.CodeMetadata, base64.StdEncoding.EncodeToString(account.CodeMetadata)) + require.Equal(t, accountState.Owner, account.OwnerAddress) + require.Equal(t, accountState.RootHash, base64.StdEncoding.EncodeToString(account.RootHash)) + + // Now we remove the account + err = chainSimulator.RemoveAccounts([]string{accountState.Address}) + require.Nil(t, err) + + err = chainSimulator.GenerateBlocks(2) + require.Nil(t, err) + + account, _, err = nodeHandler.GetFacadeHandler().GetAccount(accountState.Address, coreAPI.AccountQueryOptions{}) + require.Nil(t, err) + require.Equal(t, "0", account.Balance) + require.Equal(t, "0", account.DeveloperReward) + require.Equal(t, "", account.Code) + require.Equal(t, "", base64.StdEncoding.EncodeToString(account.CodeHash)) + require.Equal(t, "", base64.StdEncoding.EncodeToString(account.CodeMetadata)) + require.Equal(t, "", account.OwnerAddress) + require.Equal(t, "", base64.StdEncoding.EncodeToString(account.RootHash)) + + // Set the state again + err = chainSimulator.SetStateMultiple([]*dtos.AddressState{accountState}) + require.Nil(t, err) + + err = chainSimulator.GenerateBlocks(2) + require.Nil(t, err) + + account, _, err = nodeHandler.GetFacadeHandler().GetAccount(accountState.Address, coreAPI.AccountQueryOptions{}) + require.Nil(t, err) + + require.Equal(t, accountState.Balance, account.Balance) + require.Equal(t, accountState.DeveloperRewards, account.DeveloperReward) + require.Equal(t, accountState.Code, account.Code) + require.Equal(t, accountState.CodeHash, base64.StdEncoding.EncodeToString(account.CodeHash)) + require.Equal(t, accountState.CodeMetadata, base64.StdEncoding.EncodeToString(account.CodeMetadata)) + require.Equal(t, accountState.Owner, account.OwnerAddress) + require.Equal(t, accountState.RootHash, base64.StdEncoding.EncodeToString(account.RootHash)) +} + +// CheckGetAccount - +func CheckGetAccount(t *testing.T, chainSimulator ChainSimulator) { + // the facade's GetAccount method requires that at least one block was produced over the genesis block + err := chainSimulator.GenerateBlocks(1) + require.Nil(t, err) + + address := dtos.WalletAddress{ + Bech32: "erd1qtc600lryvytxuy4h7vn7xmsy5tw6vuw3tskr75cwnmv4mnyjgsq6e5zgj", + } + address.Bytes, err = chainSimulator.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Decode(address.Bech32) + require.Nil(t, err) + + account, err := chainSimulator.GetAccount(address) + require.Nil(t, err) + require.Equal(t, uint64(0), account.Nonce) + require.Equal(t, "0", account.Balance) + + nonce := uint64(37) + err = chainSimulator.SetStateMultiple([]*dtos.AddressState{ + { + Address: address.Bech32, + Nonce: &nonce, + Balance: big.NewInt(38).String(), + }, + }) + require.Nil(t, err) + + // without this call the test will fail because the latest produced block points to a state roothash that tells that + // the account has the nonce 0 + _ = chainSimulator.GenerateBlocks(1) + + account, err = chainSimulator.GetAccount(address) + require.Nil(t, err) + require.Equal(t, uint64(37), account.Nonce) + require.Equal(t, "38", account.Balance) +} + +// CheckGenerateTransactions - +func CheckGenerateTransactions(t *testing.T, chainSimulator ChainSimulator) { + transferValue := big.NewInt(0).Mul(OneEGLD, big.NewInt(5)) + + wallet0, err := chainSimulator.GenerateAndMintWalletAddress(0, InitialAmount) + require.Nil(t, err) + + wallet1, err := chainSimulator.GenerateAndMintWalletAddress(1, InitialAmount) + require.Nil(t, err) + + wallet2, err := chainSimulator.GenerateAndMintWalletAddress(2, InitialAmount) + require.Nil(t, err) + + wallet3, err := chainSimulator.GenerateAndMintWalletAddress(2, InitialAmount) + require.Nil(t, err) + + wallet4, err := chainSimulator.GenerateAndMintWalletAddress(2, InitialAmount) + require.Nil(t, err) + + gasLimit := uint64(50000) + tx0 := GenerateTransaction(wallet0.Bytes, 0, wallet2.Bytes, transferValue, "", gasLimit) + tx1 := GenerateTransaction(wallet1.Bytes, 0, wallet2.Bytes, transferValue, "", gasLimit) + tx3 := GenerateTransaction(wallet3.Bytes, 0, wallet4.Bytes, transferValue, "", gasLimit) + + maxNumOfBlockToGenerateWhenExecutingTx := 15 + + t.Run("nil or empty slice of transactions should error", func(t *testing.T) { + sentTxs, errSend := chainSimulator.SendTxsAndGenerateBlocksTilAreExecuted(nil, 1) + assert.Equal(t, errors.ErrEmptySliceOfTxs, errSend) + assert.Nil(t, sentTxs) + + sentTxs, errSend = chainSimulator.SendTxsAndGenerateBlocksTilAreExecuted(make([]*transaction.Transaction, 0), 1) + assert.Equal(t, errors.ErrEmptySliceOfTxs, errSend) + assert.Nil(t, sentTxs) + }) + t.Run("invalid max number of blocks to generate should error", func(t *testing.T) { + sentTxs, errSend := chainSimulator.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{tx0, tx1}, 0) + assert.Equal(t, errors.ErrInvalidMaxNumOfBlocks, errSend) + assert.Nil(t, sentTxs) + }) + t.Run("nil transaction in slice should error", func(t *testing.T) { + sentTxs, errSend := chainSimulator.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{nil}, 1) + assert.ErrorIs(t, errSend, errors.ErrNilTransaction) + assert.Nil(t, sentTxs) + }) + t.Run("2 transactions from different shard should call send correctly", func(t *testing.T) { + sentTxs, errSend := chainSimulator.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{tx0, tx1}, maxNumOfBlockToGenerateWhenExecutingTx) + assert.Equal(t, 2, len(sentTxs)) + assert.Nil(t, errSend) + + account, errGet := chainSimulator.GetAccount(wallet2) + assert.Nil(t, errGet) + expectedBalance := big.NewInt(0).Add(InitialAmount, transferValue) + expectedBalance.Add(expectedBalance, transferValue) + assert.Equal(t, expectedBalance.String(), account.Balance) + }) + t.Run("1 transaction should be sent correctly", func(t *testing.T) { + _, errSend := chainSimulator.SendTxAndGenerateBlockTilTxIsExecuted(tx3, maxNumOfBlockToGenerateWhenExecutingTx) + assert.Nil(t, errSend) + + account, errGet := chainSimulator.GetAccount(wallet4) + assert.Nil(t, errGet) + expectedBalance := big.NewInt(0).Add(InitialAmount, transferValue) + assert.Equal(t, expectedBalance.String(), account.Balance) + }) +} diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index 5862f433b1c..3b7ca42a9ea 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -14,6 +14,7 @@ import ( "github.com/multiversx/mx-chain-go/node/chainSimulator/components" "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" "github.com/multiversx/mx-chain-go/node/chainSimulator/process" mxChainSharding "github.com/multiversx/mx-chain-go/sharding" @@ -500,16 +501,16 @@ func (s *simulator) SendTxAndGenerateBlockTilTxIsExecuted(txToSend *transaction. // SendTxsAndGenerateBlocksTilAreExecuted will send the provided transactions and generate block until all transactions are executed func (s *simulator) SendTxsAndGenerateBlocksTilAreExecuted(txsToSend []*transaction.Transaction, maxNumOfBlocksToGenerateWhenExecutingTx int) ([]*transaction.ApiTransactionResult, error) { if len(txsToSend) == 0 { - return nil, errEmptySliceOfTxs + return nil, chainSimulatorErrors.ErrEmptySliceOfTxs } if maxNumOfBlocksToGenerateWhenExecutingTx == 0 { - return nil, errInvalidMaxNumOfBlocks + return nil, chainSimulatorErrors.ErrInvalidMaxNumOfBlocks } transactionStatus := make([]*transactionWithResult, 0, len(txsToSend)) for idx, tx := range txsToSend { if tx == nil { - return nil, fmt.Errorf("%w on position %d", errNilTransaction, idx) + return nil, fmt.Errorf("%w on position %d", chainSimulatorErrors.ErrNilTransaction, idx) } txHashHex, err := s.sendTx(tx) diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index 1929944d510..2a882649e91 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -1,20 +1,16 @@ package chainSimulator import ( - "encoding/base64" "math/big" "testing" "time" "github.com/multiversx/mx-chain-go/config" + chainSimulatorCommon "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" - "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" - "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-core-go/core" - coreAPI "github.com/multiversx/mx-chain-core-go/data/api" - "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -185,22 +181,7 @@ func TestChainSimulator_SetState(t *testing.T) { defer chainSimulator.Close() - keyValueMap := map[string]string{ - "01": "01", - "02": "02", - } - - address := "erd1qtc600lryvytxuy4h7vn7xmsy5tw6vuw3tskr75cwnmv4mnyjgsq6e5zgj" - err = chainSimulator.SetKeyValueForAddress(address, keyValueMap) - require.Nil(t, err) - - err = chainSimulator.GenerateBlocks(1) - require.Nil(t, err) - - nodeHandler := chainSimulator.GetNodeHandler(0) - keyValuePairs, _, err := nodeHandler.GetFacadeHandler().GetKeyValuePairs(address, coreAPI.AccountQueryOptions{}) - require.Nil(t, err) - require.Equal(t, keyValueMap, keyValuePairs) + chainSimulatorCommon.CheckSetState(t, chainSimulator, chainSimulator.GetNodeHandler(0)) } func TestChainSimulator_SetEntireState(t *testing.T) { @@ -250,36 +231,7 @@ func TestChainSimulator_SetEntireState(t *testing.T) { }, } - err = chainSimulator.SetStateMultiple([]*dtos.AddressState{accountState}) - require.Nil(t, err) - - err = chainSimulator.GenerateBlocks(30) - require.Nil(t, err) - - nodeHandler := chainSimulator.GetNodeHandler(1) - scAddress, _ := nodeHandler.GetCoreComponents().AddressPubKeyConverter().Decode(contractAddress) - res, _, err := nodeHandler.GetFacadeHandler().ExecuteSCQuery(&process.SCQuery{ - ScAddress: scAddress, - FuncName: "getSum", - CallerAddr: nil, - BlockNonce: core.OptionalUint64{}, - }) - require.Nil(t, err) - - counterValue := big.NewInt(0).SetBytes(res.ReturnData[0]).Int64() - require.Equal(t, 10, int(counterValue)) - - time.Sleep(time.Second) - - account, _, err := nodeHandler.GetFacadeHandler().GetAccount(contractAddress, coreAPI.AccountQueryOptions{}) - require.Nil(t, err) - require.Equal(t, accountState.Balance, account.Balance) - require.Equal(t, accountState.DeveloperRewards, account.DeveloperReward) - require.Equal(t, accountState.Code, account.Code) - require.Equal(t, accountState.CodeHash, base64.StdEncoding.EncodeToString(account.CodeHash)) - require.Equal(t, accountState.CodeMetadata, base64.StdEncoding.EncodeToString(account.CodeMetadata)) - require.Equal(t, accountState.Owner, account.OwnerAddress) - require.Equal(t, accountState.RootHash, base64.StdEncoding.EncodeToString(account.RootHash)) + chainSimulatorCommon.CheckSetEntireState(t, chainSimulator, chainSimulator.GetNodeHandler(1), accountState) } func TestChainSimulator_SetEntireStateWithRemoval(t *testing.T) { @@ -312,10 +264,6 @@ func TestChainSimulator_SetEntireStateWithRemoval(t *testing.T) { defer chainSimulator.Close() - // activate the auto balancing tries so the results will be the same - err = chainSimulator.GenerateBlocks(30) - require.Nil(t, err) - balance := "431271308732096033771131" contractAddress := "erd1qqqqqqqqqqqqqpgqmzzm05jeav6d5qvna0q2pmcllelkz8xddz3syjszx5" accountState := &dtos.AddressState{ @@ -332,70 +280,7 @@ func TestChainSimulator_SetEntireStateWithRemoval(t *testing.T) { "73756d": "0a", }, } - - err = chainSimulator.SetStateMultiple([]*dtos.AddressState{accountState}) - require.Nil(t, err) - - err = chainSimulator.GenerateBlocks(2) - require.Nil(t, err) - - nodeHandler := chainSimulator.GetNodeHandler(1) - scAddress, _ := nodeHandler.GetCoreComponents().AddressPubKeyConverter().Decode(contractAddress) - res, _, err := nodeHandler.GetFacadeHandler().ExecuteSCQuery(&process.SCQuery{ - ScAddress: scAddress, - FuncName: "getSum", - CallerAddr: nil, - BlockNonce: core.OptionalUint64{}, - }) - require.Nil(t, err) - - counterValue := big.NewInt(0).SetBytes(res.ReturnData[0]).Int64() - require.Equal(t, 10, int(counterValue)) - - account, _, err := nodeHandler.GetFacadeHandler().GetAccount(contractAddress, coreAPI.AccountQueryOptions{}) - require.Nil(t, err) - require.Equal(t, accountState.Balance, account.Balance) - require.Equal(t, accountState.DeveloperRewards, account.DeveloperReward) - require.Equal(t, accountState.Code, account.Code) - require.Equal(t, accountState.CodeHash, base64.StdEncoding.EncodeToString(account.CodeHash)) - require.Equal(t, accountState.CodeMetadata, base64.StdEncoding.EncodeToString(account.CodeMetadata)) - require.Equal(t, accountState.Owner, account.OwnerAddress) - require.Equal(t, accountState.RootHash, base64.StdEncoding.EncodeToString(account.RootHash)) - - // Now we remove the account - err = chainSimulator.RemoveAccounts([]string{contractAddress}) - require.Nil(t, err) - - err = chainSimulator.GenerateBlocks(2) - require.Nil(t, err) - - account, _, err = nodeHandler.GetFacadeHandler().GetAccount(contractAddress, coreAPI.AccountQueryOptions{}) - require.Nil(t, err) - require.Equal(t, "0", account.Balance) - require.Equal(t, "0", account.DeveloperReward) - require.Equal(t, "", account.Code) - require.Equal(t, "", base64.StdEncoding.EncodeToString(account.CodeHash)) - require.Equal(t, "", base64.StdEncoding.EncodeToString(account.CodeMetadata)) - require.Equal(t, "", account.OwnerAddress) - require.Equal(t, "", base64.StdEncoding.EncodeToString(account.RootHash)) - - // Set the state again - err = chainSimulator.SetStateMultiple([]*dtos.AddressState{accountState}) - require.Nil(t, err) - - err = chainSimulator.GenerateBlocks(2) - require.Nil(t, err) - - account, _, err = nodeHandler.GetFacadeHandler().GetAccount(contractAddress, coreAPI.AccountQueryOptions{}) - require.Nil(t, err) - - require.Equal(t, accountState.Balance, account.Balance) - require.Equal(t, accountState.DeveloperRewards, account.DeveloperReward) - require.Equal(t, accountState.Code, account.Code) - require.Equal(t, accountState.CodeHash, base64.StdEncoding.EncodeToString(account.CodeHash)) - require.Equal(t, accountState.CodeMetadata, base64.StdEncoding.EncodeToString(account.CodeMetadata)) - require.Equal(t, accountState.Owner, account.OwnerAddress) - require.Equal(t, accountState.RootHash, base64.StdEncoding.EncodeToString(account.RootHash)) + chainSimulatorCommon.CheckSetEntireStateWithRemoval(t, chainSimulator, chainSimulator.GetNodeHandler(1), accountState) } func TestChainSimulator_GetAccount(t *testing.T) { @@ -431,35 +316,7 @@ func TestChainSimulator_GetAccount(t *testing.T) { defer chainSimulator.Close() - address := dtos.WalletAddress{ - Bech32: "erd1qtc600lryvytxuy4h7vn7xmsy5tw6vuw3tskr75cwnmv4mnyjgsq6e5zgj", - } - address.Bytes, err = chainSimulator.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Decode(address.Bech32) - assert.Nil(t, err) - - account, err := chainSimulator.GetAccount(address) - assert.Nil(t, err) - assert.Equal(t, uint64(0), account.Nonce) - assert.Equal(t, "0", account.Balance) - - nonce := uint64(37) - err = chainSimulator.SetStateMultiple([]*dtos.AddressState{ - { - Address: address.Bech32, - Nonce: &nonce, - Balance: big.NewInt(38).String(), - }, - }) - assert.Nil(t, err) - - // without this call the test will fail because the latest produced block points to a state roothash that tells that - // the account has the nonce 0 - _ = chainSimulator.GenerateBlocks(1) - - account, err = chainSimulator.GetAccount(address) - assert.Nil(t, err) - assert.Equal(t, uint64(37), account.Nonce) - assert.Equal(t, "38", account.Balance) + chainSimulatorCommon.CheckGetAccount(t, chainSimulator) } func TestSimulator_SendTransactions(t *testing.T) { @@ -492,89 +349,5 @@ func TestSimulator_SendTransactions(t *testing.T) { defer chainSimulator.Close() - oneEgld := big.NewInt(1000000000000000000) - initialMinting := big.NewInt(0).Mul(oneEgld, big.NewInt(100)) - transferValue := big.NewInt(0).Mul(oneEgld, big.NewInt(5)) - - wallet0, err := chainSimulator.GenerateAndMintWalletAddress(0, initialMinting) - require.Nil(t, err) - - wallet1, err := chainSimulator.GenerateAndMintWalletAddress(1, initialMinting) - require.Nil(t, err) - - wallet2, err := chainSimulator.GenerateAndMintWalletAddress(2, initialMinting) - require.Nil(t, err) - - wallet3, err := chainSimulator.GenerateAndMintWalletAddress(2, initialMinting) - require.Nil(t, err) - - wallet4, err := chainSimulator.GenerateAndMintWalletAddress(2, initialMinting) - require.Nil(t, err) - - gasLimit := uint64(50000) - tx0 := generateTransaction(wallet0.Bytes, 0, wallet2.Bytes, transferValue, "", gasLimit) - tx1 := generateTransaction(wallet1.Bytes, 0, wallet2.Bytes, transferValue, "", gasLimit) - tx3 := generateTransaction(wallet3.Bytes, 0, wallet4.Bytes, transferValue, "", gasLimit) - - maxNumOfBlockToGenerateWhenExecutingTx := 15 - - t.Run("nil or empty slice of transactions should error", func(t *testing.T) { - sentTxs, errSend := chainSimulator.SendTxsAndGenerateBlocksTilAreExecuted(nil, 1) - assert.Equal(t, errEmptySliceOfTxs, errSend) - assert.Nil(t, sentTxs) - - sentTxs, errSend = chainSimulator.SendTxsAndGenerateBlocksTilAreExecuted(make([]*transaction.Transaction, 0), 1) - assert.Equal(t, errEmptySliceOfTxs, errSend) - assert.Nil(t, sentTxs) - }) - t.Run("invalid max number of blocks to generate should error", func(t *testing.T) { - sentTxs, errSend := chainSimulator.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{tx0, tx1}, 0) - assert.Equal(t, errInvalidMaxNumOfBlocks, errSend) - assert.Nil(t, sentTxs) - }) - t.Run("nil transaction in slice should error", func(t *testing.T) { - sentTxs, errSend := chainSimulator.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{nil}, 1) - assert.ErrorIs(t, errSend, errNilTransaction) - assert.Nil(t, sentTxs) - }) - t.Run("2 transactions from different shard should call send correctly", func(t *testing.T) { - sentTxs, errSend := chainSimulator.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{tx0, tx1}, maxNumOfBlockToGenerateWhenExecutingTx) - assert.Equal(t, 2, len(sentTxs)) - assert.Nil(t, errSend) - - account, errGet := chainSimulator.GetAccount(wallet2) - assert.Nil(t, errGet) - expectedBalance := big.NewInt(0).Add(initialMinting, transferValue) - expectedBalance.Add(expectedBalance, transferValue) - assert.Equal(t, expectedBalance.String(), account.Balance) - }) - t.Run("1 transaction should be sent correctly", func(t *testing.T) { - _, errSend := chainSimulator.SendTxAndGenerateBlockTilTxIsExecuted(tx3, maxNumOfBlockToGenerateWhenExecutingTx) - assert.Nil(t, errSend) - - account, errGet := chainSimulator.GetAccount(wallet4) - assert.Nil(t, errGet) - expectedBalance := big.NewInt(0).Add(initialMinting, transferValue) - assert.Equal(t, expectedBalance.String(), account.Balance) - }) -} - -func generateTransaction(sender []byte, nonce uint64, receiver []byte, value *big.Int, data string, gasLimit uint64) *transaction.Transaction { - minGasPrice := uint64(1000000000) - txVersion := uint32(1) - mockTxSignature := "sig" - - transferValue := big.NewInt(0).Set(value) - return &transaction.Transaction{ - Nonce: nonce, - Value: transferValue, - SndAddr: sender, - RcvAddr: receiver, - Data: []byte(data), - GasLimit: gasLimit, - GasPrice: minGasPrice, - ChainID: []byte(configs.ChainID), - Version: txVersion, - Signature: []byte(mockTxSignature), - } + chainSimulatorCommon.CheckGenerateTransactions(t, chainSimulator) } diff --git a/node/chainSimulator/errors.go b/node/chainSimulator/errors.go index 5e2dec0c16a..57f0db0c457 100644 --- a/node/chainSimulator/errors.go +++ b/node/chainSimulator/errors.go @@ -3,10 +3,7 @@ package chainSimulator import "errors" var ( - errNilChainSimulator = errors.New("nil chain simulator") - errNilMetachainNode = errors.New("nil metachain node") - errShardSetupError = errors.New("shard setup error") - errEmptySliceOfTxs = errors.New("empty slice of transactions to send") - errNilTransaction = errors.New("nil transaction") - errInvalidMaxNumOfBlocks = errors.New("invalid max number of blocks to generate") + errNilChainSimulator = errors.New("nil chain simulator") + errNilMetachainNode = errors.New("nil metachain node") + errShardSetupError = errors.New("shard setup error") ) diff --git a/node/chainSimulator/errors/errors.go b/node/chainSimulator/errors/errors.go new file mode 100644 index 00000000000..c1be2d016b1 --- /dev/null +++ b/node/chainSimulator/errors/errors.go @@ -0,0 +1,12 @@ +package errors + +import "errors" + +// ErrEmptySliceOfTxs signals that an empty slice of transactions has been provided +var ErrEmptySliceOfTxs = errors.New("empty slice of transactions to send") + +// ErrNilTransaction signals that a nil transaction has been provided +var ErrNilTransaction = errors.New("nil transaction") + +// ErrInvalidMaxNumOfBlocks signals that an invalid max numerof blocks has been provided +var ErrInvalidMaxNumOfBlocks = errors.New("invalid max number of blocks to generate") From cfaeec70f95f6f9246c2405722be9931ee2c6b09 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 30 May 2024 12:22:50 +0300 Subject: [PATCH 278/503] added esdt transfer tx separate func --- .../vm/esdtImprovements_test.go | 133 +++++------------- 1 file changed, 34 insertions(+), 99 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index d8a7e76c6da..fd225e7cb24 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -102,6 +102,12 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { address, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) require.Nil(t, err) + address2, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) + require.Nil(t, err) + + address3, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) + require.Nil(t, err) + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch) - 1) require.Nil(t, err) @@ -126,9 +132,6 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) - esdtMetaData := txsFee.GetDefaultMetaData() - esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - // issue NFT nftTicker := []byte("NFTTICKER") tx = issueNonFungibleTx(1, address.Bytes, nftTicker, baseIssuingCost) @@ -187,6 +190,9 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) + esdtMetaData := txsFee.GetDefaultMetaData() + esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + tx = nftCreateTx(5, address.Bytes, metaESDTTokenID, esdtMetaData) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) @@ -210,67 +216,19 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 3. transfer the tokens to another account") - address2, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) - require.Nil(t, err) - - address3, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) - require.Nil(t, err) - - tx = utils.CreateESDTNFTTransferTx( - 6, - address.Bytes, - address2.Bytes, - nftTokenID, - 1, - big.NewInt(1), - minGasPrice, - 10_000_000, - "", - ) - tx.Version = 1 - tx.Signature = []byte("dummySig") - tx.ChainID = []byte(configs.ChainID) - + tx = esdtNFTTransferTx(6, address.Bytes, address2.Bytes, nftTokenID) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - tx = utils.CreateESDTNFTTransferTx( - 7, - address.Bytes, - address2.Bytes, - sftTokenID, - 1, - big.NewInt(1), - minGasPrice, - 10_000_000, - "", - ) - tx.Version = 1 - tx.Signature = []byte("dummySig") - tx.ChainID = []byte(configs.ChainID) - + tx = esdtNFTTransferTx(7, address.Bytes, address2.Bytes, sftTokenID) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - tx = utils.CreateESDTNFTTransferTx( - 8, - address.Bytes, - address2.Bytes, - metaESDTTokenID, - 1, - big.NewInt(1), - minGasPrice, - 10_000_000, - "", - ) - tx.Version = 1 - tx.Signature = []byte("dummySig") - tx.ChainID = []byte(configs.ChainID) - + tx = esdtNFTTransferTx(8, address.Bytes, address2.Bytes, metaESDTTokenID) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) @@ -306,61 +264,19 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 7. transfer the tokens to another account") - tx = utils.CreateESDTNFTTransferTx( - 0, - address2.Bytes, - address3.Bytes, - nftTokenID, - 1, - big.NewInt(1), - minGasPrice, - 10_000_000, - "", - ) - tx.Version = 1 - tx.Signature = []byte("dummySig") - tx.ChainID = []byte(configs.ChainID) - + tx = esdtNFTTransferTx(0, address2.Bytes, address3.Bytes, nftTokenID) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - tx = utils.CreateESDTNFTTransferTx( - 1, - address2.Bytes, - address3.Bytes, - sftTokenID, - 1, - big.NewInt(1), - minGasPrice, - 10_000_000, - "", - ) - tx.Version = 1 - tx.Signature = []byte("dummySig") - tx.ChainID = []byte(configs.ChainID) - + tx = esdtNFTTransferTx(1, address2.Bytes, address3.Bytes, sftTokenID) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - tx = utils.CreateESDTNFTTransferTx( - 2, - address2.Bytes, - address3.Bytes, - metaESDTTokenID, - 1, - big.NewInt(1), - minGasPrice, - 10_000_000, - "", - ) - tx.Version = 1 - tx.Signature = []byte("dummySig") - tx.ChainID = []byte(configs.ChainID) - + tx = esdtNFTTransferTx(2, address2.Bytes, address3.Bytes, metaESDTTokenID) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) @@ -396,6 +312,25 @@ func checkMetaData( require.Equal(t, expectedMetaData.Attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) } +func esdtNFTTransferTx(nonce uint64, sndAdr, rcvAddr, token []byte) *transaction.Transaction { + tx := utils.CreateESDTNFTTransferTx( + nonce, + sndAdr, + rcvAddr, + token, + 1, + big.NewInt(1), + minGasPrice, + 10_000_000, + "", + ) + tx.Version = 1 + tx.Signature = []byte("dummySig") + tx.ChainID = []byte(configs.ChainID) + + return tx +} + func issueMetaESDTTx(nonce uint64, sndAdr []byte, ticker []byte, baseIssuingCost string) *transaction.Transaction { callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) From 585a5dc9687b63648d8c9cc727bb1d483c74475b Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 30 May 2024 13:33:18 +0300 Subject: [PATCH 279/503] added fungible token --- .../vm/esdtImprovements_test.go | 174 +++++++++++------- 1 file changed, 103 insertions(+), 71 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index fd225e7cb24..80af705c3a1 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -132,9 +132,23 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) + // issue fungible + fungibleTicker := []byte("FUNGIBLETICKER") + tx = issueTx(1, address.Bytes, fungibleTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + fungibleTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, address, fungibleTokenID, roles) + + log.Info("Issued fungible token id", "tokenID", string(fungibleTokenID)) + // issue NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(1, address.Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(2, address.Bytes, nftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -142,18 +156,13 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - - roles = [][]byte{ - []byte(core.ESDTRoleNFTCreate), - []byte(core.ESDTRoleTransfer), - } setAddressEsdtRoles(t, cs, address, nftTokenID, roles) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, address.Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(3, address.Bytes, sftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -161,11 +170,6 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - - roles = [][]byte{ - []byte(core.ESDTRoleNFTCreate), - []byte(core.ESDTRoleTransfer), - } setAddressEsdtRoles(t, cs, address, sftTokenID, roles) log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -173,32 +177,40 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(3, address.Bytes, nftTokenID, nftMetaData) - - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - sftMetaData := txsFee.GetDefaultMetaData() sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(4, address.Bytes, sftTokenID, sftMetaData) - - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - esdtMetaData := txsFee.GetDefaultMetaData() esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(5, address.Bytes, metaESDTTokenID, esdtMetaData) + fungibleMetaData := txsFee.GetDefaultMetaData() + fungibleMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) + tokenIDs := [][]byte{ + nftTokenID, + sftTokenID, + metaESDTTokenID, + // fungibleTokenID, + } + + tokensMetadata := []*txsFee.MetaData{ + nftMetaData, + sftMetaData, + esdtMetaData, + // fungibleMetaData, + } + + nonce := uint64(4) + for i := range tokenIDs { + tx = nftCreateTx(nonce, address.Bytes, tokenIDs[i], tokensMetadata[i]) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } err = cs.GenerateBlocks(10) require.Nil(t, err) @@ -208,6 +220,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, nftMetaData) checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, shardID, fungibleMetaData) log.Info("Step 2. wait for DynamicEsdtFlag activation") @@ -216,71 +229,61 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 3. transfer the tokens to another account") - tx = esdtNFTTransferTx(6, address.Bytes, address2.Bytes, nftTokenID) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) + for _, tokenID := range tokenIDs { + log.Info("transfering token id", "tokenID", tokenID) - tx = esdtNFTTransferTx(7, address.Bytes, address2.Bytes, sftTokenID) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) + tx = esdtNFTTransferTx(nonce, address.Bytes, address2.Bytes, tokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) - tx = esdtNFTTransferTx(8, address.Bytes, address2.Bytes, metaESDTTokenID) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) + nonce++ + } log.Info("Step 4. check that the metadata for all tokens is saved on the system account") checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, nftMetaData) checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, shardID, fungibleMetaData) log.Info("Step 5. make an updateTokenID@tokenID function call on the ESDTSystem SC for all token types") - tx = updateTokenIDTx(9, address.Bytes, nftTokenID) + for _, tokenID := range tokenIDs { + tx = updateTokenIDTx(nonce, address.Bytes, tokenID) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) + log.Info("updating token id", "tokenID", tokenID) - tx = updateTokenIDTx(10, address.Bytes, sftTokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) + nonce++ + } log.Info("Step 6. check that the metadata for all tokens is saved on the system account") checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, nftMetaData) checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, shardID, fungibleMetaData) log.Info("Step 7. transfer the tokens to another account") - tx = esdtNFTTransferTx(0, address2.Bytes, address3.Bytes, nftTokenID) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) + nonce = uint64(0) + for _, tokenID := range tokenIDs { + log.Info("transfering token id", "tokenID", tokenID) - tx = esdtNFTTransferTx(1, address2.Bytes, address3.Bytes, sftTokenID) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) + tx = esdtNFTTransferTx(nonce, address2.Bytes, address3.Bytes, tokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) - tx = esdtNFTTransferTx(2, address2.Bytes, address3.Bytes, metaESDTTokenID) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) + nonce++ + } log.Info("Step 8. check that the metaData for the NFT was removed from the system account and moved to the user account") @@ -290,6 +293,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, nftMetaData) checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, shardID, fungibleMetaData) } func checkMetaData( @@ -331,6 +335,34 @@ func esdtNFTTransferTx(nonce uint64, sndAdr, rcvAddr, token []byte) *transaction return tx } +func issueTx(nonce uint64, sndAdr []byte, ticker []byte, baseIssuingCost string) *transaction.Transaction { + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + + txDataField := bytes.Join( + [][]byte{ + []byte("issue"), + []byte(hex.EncodeToString([]byte("asdname1"))), + []byte(hex.EncodeToString(ticker)), + []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + }, + []byte("@"), + ) + + return &transaction.Transaction{ + Nonce: nonce, + SndAddr: sndAdr, + RcvAddr: core.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: callValue, + ChainID: []byte(configs.ChainID), + Version: 1, + } +} + func issueMetaESDTTx(nonce uint64, sndAdr []byte, ticker []byte, baseIssuingCost string) *transaction.Transaction { callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) From 5257704f3422e57979f516af80e3a236e376435f Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 30 May 2024 14:51:52 +0300 Subject: [PATCH 280/503] added cross shard txs --- .../vm/esdtImprovements_test.go | 120 ++++++++++-------- 1 file changed, 70 insertions(+), 50 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 80af705c3a1..d3974abb42a 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -50,13 +50,21 @@ var log = logger.GetOrCreate("integrationTests/chainSimulator/vm") // 8. check that the metaData for the NFT was removed from the system account and moved to the user account // 9. check that the metaData for the rest of the tokens is still present on the system account and not on the userAccount // 10. do the test for both intra and cross shard txs -func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { +func TestChainSimulator_CheckTokensMetadata_TransferTokens(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } - // logger.SetLogLevel("*:TRACE") + t.Run("transfer and check all tokens - intra shard", func(t *testing.T) { + transferAndCheckTokensMetaData(t, false) + }) + + t.Run("transfer and check all tokens - intra shard", func(t *testing.T) { + transferAndCheckTokensMetaData(t, true) + }) +} +func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool) { startTime := time.Now().Unix() roundDurationInMillis := uint64(6000) roundsPerEpoch := core.OptionalUint64{ @@ -94,19 +102,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { defer cs.Close() - mintValue := big.NewInt(10) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) - - shardID := uint32(1) - - address, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) - require.Nil(t, err) - - address2, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) - require.Nil(t, err) - - address3, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) - require.Nil(t, err) + addrs := createAddresses(t, cs, isCrossShard) err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch) - 1) require.Nil(t, err) @@ -115,7 +111,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { // issue metaESDT metaESDTTicker := []byte("METATTICKER") - tx := issueMetaESDTTx(0, address.Bytes, metaESDTTicker, baseIssuingCost) + tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -128,13 +124,13 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, address, metaESDTTokenID, roles) + setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) // issue fungible fungibleTicker := []byte("FUNGIBLETICKER") - tx = issueTx(1, address.Bytes, fungibleTicker, baseIssuingCost) + tx = issueTx(1, addrs[0].Bytes, fungibleTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -142,13 +138,13 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) fungibleTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, address, fungibleTokenID, roles) + setAddressEsdtRoles(t, cs, addrs[0], fungibleTokenID, roles) log.Info("Issued fungible token id", "tokenID", string(fungibleTokenID)) // issue NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(2, address.Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(2, addrs[0].Bytes, nftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -156,13 +152,13 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, address, nftTokenID, roles) + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(3, address.Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(3, addrs[0].Bytes, sftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -170,7 +166,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, address, sftTokenID, roles) + setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -202,7 +198,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { nonce := uint64(4) for i := range tokenIDs { - tx = nftCreateTx(nonce, address.Bytes, tokenIDs[i], tokensMetadata[i]) + tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -217,10 +213,10 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 1. check that the metadata for all tokens is saved on the system account") - checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, nftMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, shardID, fungibleMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, esdtMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, fungibleMetaData) log.Info("Step 2. wait for DynamicEsdtFlag activation") @@ -232,7 +228,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { for _, tokenID := range tokenIDs { log.Info("transfering token id", "tokenID", tokenID) - tx = esdtNFTTransferTx(nonce, address.Bytes, address2.Bytes, tokenID) + tx = esdtNFTTransferTx(nonce, addrs[0].Bytes, addrs[1].Bytes, tokenID) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) @@ -243,15 +239,15 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 4. check that the metadata for all tokens is saved on the system account") - checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, nftMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, shardID, fungibleMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, esdtMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, fungibleMetaData) log.Info("Step 5. make an updateTokenID@tokenID function call on the ESDTSystem SC for all token types") for _, tokenID := range tokenIDs { - tx = updateTokenIDTx(nonce, address.Bytes, tokenID) + tx = updateTokenIDTx(nonce, addrs[0].Bytes, tokenID) log.Info("updating token id", "tokenID", tokenID) @@ -265,10 +261,10 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 6. check that the metadata for all tokens is saved on the system account") - checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, nftMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, shardID, fungibleMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, esdtMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, fungibleMetaData) log.Info("Step 7. transfer the tokens to another account") @@ -276,7 +272,7 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { for _, tokenID := range tokenIDs { log.Info("transfering token id", "tokenID", tokenID) - tx = esdtNFTTransferTx(nonce, address2.Bytes, address3.Bytes, tokenID) + tx = esdtNFTTransferTx(nonce, addrs[1].Bytes, addrs[2].Bytes, tokenID) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) @@ -287,13 +283,40 @@ func TestChainSimulator_CheckNFTandSFTMetadata(t *testing.T) { log.Info("Step 8. check that the metaData for the NFT was removed from the system account and moved to the user account") - checkMetaData(t, cs, address3.Bytes, nftTokenID, shardID, nftMetaData) + checkMetaData(t, cs, addrs[2].Bytes, nftTokenID, nftMetaData) log.Info("Step 9. check that the metaData for the rest of the tokens is still present on the system account and not on the userAccount") - checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, nftMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, shardID, fungibleMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, esdtMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, fungibleMetaData) +} + +func createAddresses( + t *testing.T, + cs testsChainSimulator.ChainSimulator, + isCrossShard bool, +) []dtos.WalletAddress { + var shardIDs []uint32 + if !isCrossShard { + shardIDs = []uint32{1, 1, 1} + } else { + shardIDs = []uint32{0, 1, 2} + } + + mintValue := big.NewInt(10) + mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + + address, err := cs.GenerateAndMintWalletAddress(shardIDs[0], mintValue) + require.Nil(t, err) + + address2, err := cs.GenerateAndMintWalletAddress(shardIDs[1], mintValue) + require.Nil(t, err) + + address3, err := cs.GenerateAndMintWalletAddress(shardIDs[2], mintValue) + require.Nil(t, err) + + return []dtos.WalletAddress{address, address2, address3} } func checkMetaData( @@ -301,9 +324,10 @@ func checkMetaData( cs testsChainSimulator.ChainSimulator, addressBytes []byte, token []byte, - shardID uint32, expectedMetaData *txsFee.MetaData, ) { + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addressBytes) + retrievedMetaData := getMetaDataFromAcc(t, cs, addressBytes, token, shardID) require.Equal(t, expectedMetaData.Nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) @@ -649,11 +673,9 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { err = cs.GenerateBlocks(10) require.Nil(t, err) - shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) - log.Info("Step 1. check that the metaData for the NFT was saved in the user account and not on the system account") - checkMetaData(t, cs, address.Bytes, tokenID, shardID, nftMetaData) + checkMetaData(t, cs, address.Bytes, tokenID, nftMetaData) } // Test scenario @@ -735,8 +757,6 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { err = cs.GenerateBlocks(10) require.Nil(t, err) - shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) - log.Info("Call ESDTMetaDataRecreate to rewrite the meta data for the nft") nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) @@ -777,7 +797,7 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) - checkMetaData(t, cs, core.SystemAccountAddress, tokenID, shardID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, nftMetaData) } // Test scenario From a34b25e84f7bd17da6318a6fc180fa7c87ccab18 Mon Sep 17 00:00:00 2001 From: miiu Date: Thu, 30 May 2024 15:42:40 +0300 Subject: [PATCH 281/503] token type --- go.mod | 2 +- go.sum | 4 ++-- .../alteredaccounts/alteredAccountsProvider.go | 11 +++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e70e37f4219..32a72f31314 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e - github.com/multiversx/mx-chain-core-go v1.2.21-0.20240508071047-fefea5737840 + github.com/multiversx/mx-chain-core-go v1.2.21-0.20240530111258-45870512bfbe github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df github.com/multiversx/mx-chain-es-indexer-go v1.7.1-0.20240509104512-25512675833d github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 diff --git a/go.sum b/go.sum index 185994c8e4f..994a0751b86 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY 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-core-go v1.2.21-0.20240530111258-45870512bfbe h1:7ccy0nNJkCGDlRrIbAmZfVv5XkZAxXuBFnfUMNuESRA= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240530111258-45870512bfbe/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.1-0.20240509104512-25512675833d h1:GD1D8V0bE6hDLjrduSsMwQwwf6PMq2Zww7FYMfJsuiw= diff --git a/outport/process/alteredaccounts/alteredAccountsProvider.go b/outport/process/alteredaccounts/alteredAccountsProvider.go index e7d855b1ebf..5a0a890381e 100644 --- a/outport/process/alteredaccounts/alteredAccountsProvider.go +++ b/outport/process/alteredaccounts/alteredAccountsProvider.go @@ -223,6 +223,7 @@ func (aap *alteredAccountsProvider) addTokensDataForMarkedAccount( Nonce: nonce, Properties: hex.EncodeToString(esdtToken.Properties), MetaData: aap.convertMetaData(esdtToken.TokenMetaData), + Type: getTokenType(esdtToken.Type, nonce), } if options.WithAdditionalOutportData { accountTokenData.AdditionalData = &alteredAccount.AdditionalAccountTokenData{ @@ -236,6 +237,16 @@ func (aap *alteredAccountsProvider) addTokensDataForMarkedAccount( return nil } +func getTokenType(tokenType uint32, tokenNonce uint64) string { + isNotFungible := tokenNonce != 0 + tokenTypeNotSet := isNotFungible && core.ESDTType(tokenType) == core.Fungible + if tokenTypeNotSet { + return "" + } + + return core.ESDTType(tokenType).String() +} + func (aap *alteredAccountsProvider) convertMetaData(metaData *esdt.MetaData) *alteredAccount.TokenMetaData { if metaData == nil { return nil From 7aea474a1914c00a6768552a7f77583ad4185644 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 30 May 2024 15:42:55 +0300 Subject: [PATCH 282/503] update create nft scenarios --- .../vm/esdtImprovements_test.go | 454 ++++++++++-------- 1 file changed, 241 insertions(+), 213 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index d3974abb42a..7783b281974 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -3,6 +3,7 @@ package vm import ( "bytes" "encoding/hex" + "fmt" "math/big" "testing" "time" @@ -35,7 +36,7 @@ const ( var log = logger.GetOrCreate("integrationTests/chainSimulator/vm") -// Test scenario +// Test scenario #1 // // Initial setup: Create fungible, NFT, SFT and metaESDT tokens // (before the activation of DynamicEsdtFlag) @@ -587,7 +588,7 @@ func setAddressEsdtRoles( require.Nil(t, err) } -// Test scenario +// Test scenario #3 // // Initial setup: Create fungible, NFT, SFT and metaESDT tokens // (after the activation of DynamicEsdtFlag) @@ -599,8 +600,6 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { t.Skip("this is not a short test") } - // logger.SetLogLevel("*:TRACE") - startTime := time.Now().Unix() roundDurationInMillis := uint64(6000) roundsPerEpoch := core.OptionalUint64{ @@ -610,6 +609,8 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { activationEpoch := uint32(2) + baseIssuingCost := "1000" + numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ BypassTxSignatureCheck: false, @@ -628,6 +629,7 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { NumNodesWaitingListShard: 0, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost }, }) require.Nil(t, err) @@ -635,11 +637,7 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { defer cs.Close() - mintValue := big.NewInt(10) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) - - address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) - require.Nil(t, err) + addrs := createAddresses(t, cs, false) err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) require.Nil(t, err) @@ -649,36 +647,120 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") - tokenID := []byte("ASD-d31313") + // issue metaESDT + metaESDTTicker := []byte("METATTICKER") + tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + metaESDTTokenID := txResult.Logs.Events[0].Topics[0] roles := [][]byte{ - []byte(core.ESDTMetaDataRecreate), []byte(core.ESDTRoleNFTCreate), - []byte(core.ESDTRoleNFTBurn), []byte(core.ESDTRoleTransfer), - []byte(core.ESDTRoleNFTUpdateAttributes), - []byte(core.ESDTRoleNFTAddURI), } - setAddressEsdtRoles(t, cs, address, tokenID, roles) + setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) - nftMetaData := txsFee.GetDefaultMetaData() + log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) - tx := nftCreateTx(1, address.Bytes, tokenID, nftMetaData) + // issue fungible + fungibleTicker := []byte("FUNGIBLETICKER") + tx = issueTx(1, addrs[0].Bytes, fungibleTicker, baseIssuingCost) - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) + fungibleTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], fungibleTokenID, roles) + + log.Info("Issued fungible token id", "tokenID", string(fungibleTokenID)) + + // issue NFT + nftTicker := []byte("NFTTICKER") + tx = issueNonFungibleTx(2, addrs[0].Bytes, nftTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) + + // issue SFT + sftTicker := []byte("SFTTICKER") + tx = issueSemiFungibleTx(3, addrs[0].Bytes, sftTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + sftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + + log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) + + tokenIDs := [][]byte{ + nftTokenID, + sftTokenID, + metaESDTTokenID, + // fungibleTokenID, + } + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + sftMetaData := txsFee.GetDefaultMetaData() + sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + esdtMetaData := txsFee.GetDefaultMetaData() + esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + fungibleMetaData := txsFee.GetDefaultMetaData() + fungibleMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tokensMetadata := []*txsFee.MetaData{ + nftMetaData, + sftMetaData, + esdtMetaData, + // fungibleMetaData, + } + + nonce := uint64(4) + for i := range tokenIDs { + tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } + err = cs.GenerateBlocks(10) require.Nil(t, err) log.Info("Step 1. check that the metaData for the NFT was saved in the user account and not on the system account") - checkMetaData(t, cs, address.Bytes, tokenID, nftMetaData) + checkMetaData(t, cs, addrs[0].Bytes, nftTokenID, nftMetaData) + + log.Info("Step 2. check that the metaData for the other token types is saved on the system account and not at the user account level") + + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, esdtMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, fungibleMetaData) } -// Test scenario +// Test scenario #4 // // Initial setup: Create NFT // @@ -698,6 +780,8 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { activationEpoch := uint32(2) + baseIssuingCost := "1000" + numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ BypassTxSignatureCheck: false, @@ -716,6 +800,7 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { NumNodesWaitingListShard: 0, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost }, }) require.Nil(t, err) @@ -737,19 +822,30 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { log.Info("Initial setup: Create NFT") - tokenID := []byte("ASD-d31313") + nftTicker := []byte("NFTTICKER") + tx := issueNonFungibleTx(0, address.Bytes, nftTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTMetaDataRecreate), } - setAddressEsdtRoles(t, cs, address, tokenID, roles) + + nftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, address, nftTokenID, roles) + + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx := nftCreateTx(1, address.Bytes, tokenID, nftMetaData) + tx = nftCreateTx(1, address.Bytes, nftTokenID, nftMetaData) - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -767,19 +863,21 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { txDataField := bytes.Join( [][]byte{ []byte(core.ESDTMetaDataRecreate), - []byte(hex.EncodeToString(tokenID)), + []byte(hex.EncodeToString(nftTokenID)), nonce, nftMetaData.Name, []byte(hex.EncodeToString(big.NewInt(10).Bytes())), nftMetaData.Hash, nftMetaData.Attributes, nftMetaData.Uris[0], + nftMetaData.Uris[1], + nftMetaData.Uris[2], }, []byte("@"), ) tx = &transaction.Transaction{ - Nonce: 1, + Nonce: 2, SndAddr: address.Bytes, RcvAddr: address.Bytes, GasLimit: 10_000_000, @@ -797,10 +895,10 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) - checkMetaData(t, cs, core.SystemAccountAddress, tokenID, nftMetaData) + checkMetaData(t, cs, address.Bytes, nftTokenID, nftMetaData) } -// Test scenario +// Test scenario #5 // // Initial setup: Create NFT // @@ -820,6 +918,8 @@ func TestChainSimulator_NFT_ESDTMetaDataUpdate(t *testing.T) { activationEpoch := uint32(2) + baseIssuingCost := "1000" + numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ BypassTxSignatureCheck: false, @@ -838,6 +938,7 @@ func TestChainSimulator_NFT_ESDTMetaDataUpdate(t *testing.T) { NumNodesWaitingListShard: 0, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost }, }) require.Nil(t, err) @@ -859,79 +960,59 @@ func TestChainSimulator_NFT_ESDTMetaDataUpdate(t *testing.T) { log.Info("Initial setup: Create NFT") - tokenID := []byte("ASD-d31313") + nftTicker := []byte("NFTTICKER") + tx := issueNonFungibleTx(0, address.Bytes, nftTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleNFTUpdate), } - setAddressEsdtRoles(t, cs, address, tokenID, roles) - name := []byte(hex.EncodeToString([]byte("name"))) - hash := []byte(hex.EncodeToString([]byte("hash"))) - attributes := []byte(hex.EncodeToString([]byte("attributes"))) - uris := [][]byte{[]byte(hex.EncodeToString([]byte("uri")))} + nftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, address, nftTokenID, roles) - txDataField := bytes.Join( - [][]byte{ - []byte(core.BuiltInFunctionESDTNFTCreate), - []byte(hex.EncodeToString(tokenID)), - []byte(hex.EncodeToString(big.NewInt(1).Bytes())), // quantity - name, - []byte(hex.EncodeToString(big.NewInt(10).Bytes())), - hash, - attributes, - uris[0], - }, - []byte("@"), - ) + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) - tx := &transaction.Transaction{ - Nonce: 0, - SndAddr: address.Bytes, - RcvAddr: address.Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, - } + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + tx = nftCreateTx(1, address.Bytes, nftTokenID, nftMetaData) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - err = cs.GenerateBlocks(10) - require.Nil(t, err) - - shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) - log.Info("Call ESDTMetaDataRecreate to rewrite the meta data for the nft") nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - name = []byte(hex.EncodeToString([]byte("name2"))) - hash = []byte(hex.EncodeToString([]byte("hash2"))) - attributes = []byte(hex.EncodeToString([]byte("attributes2"))) + nftMetaData.Name = []byte(hex.EncodeToString([]byte("name2"))) + nftMetaData.Hash = []byte(hex.EncodeToString([]byte("hash2"))) + nftMetaData.Attributes = []byte(hex.EncodeToString([]byte("attributes2"))) - txDataField = bytes.Join( + txDataField := bytes.Join( [][]byte{ []byte(core.ESDTMetaDataUpdate), - []byte(hex.EncodeToString(tokenID)), + []byte(hex.EncodeToString(nftTokenID)), nonce, - name, + nftMetaData.Name, []byte(hex.EncodeToString(big.NewInt(10).Bytes())), - hash, - attributes, - uris[0], + nftMetaData.Hash, + nftMetaData.Attributes, + nftMetaData.Uris[0], + nftMetaData.Uris[1], + nftMetaData.Uris[2], }, []byte("@"), ) tx = &transaction.Transaction{ - Nonce: 1, + Nonce: 2, SndAddr: address.Bytes, RcvAddr: address.Bytes, GasLimit: 10_000_000, @@ -949,18 +1030,10 @@ func TestChainSimulator_NFT_ESDTMetaDataUpdate(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) - retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) - - require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) - require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) - require.Equal(t, hash, []byte(hex.EncodeToString(retrievedMetaData.Hash))) - for i, uri := range uris { - require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) - } - require.Equal(t, attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) + checkMetaData(t, cs, address.Bytes, nftTokenID, nftMetaData) } -// Test scenario +// Test scenario #6 // // Initial setup: Create NFT // @@ -980,6 +1053,8 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { activationEpoch := uint32(2) + baseIssuingCost := "1000" + numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ BypassTxSignatureCheck: false, @@ -998,6 +1073,7 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { NumNodesWaitingListShard: 0, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost }, }) require.Nil(t, err) @@ -1019,52 +1095,34 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { log.Info("Initial setup: Create NFT") - tokenID := []byte("ASD-d31313") + nftTicker := []byte("NFTTICKER") + tx := issueNonFungibleTx(0, address.Bytes, nftTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleNFTUpdate), } - setAddressEsdtRoles(t, cs, address, tokenID, roles) - name := []byte(hex.EncodeToString([]byte("name"))) - hash := []byte(hex.EncodeToString([]byte("hash"))) - attributes := []byte(hex.EncodeToString([]byte("attributes"))) - uris := [][]byte{[]byte(hex.EncodeToString([]byte("uri")))} + nftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, address, nftTokenID, roles) - txDataField := bytes.Join( - [][]byte{ - []byte(core.BuiltInFunctionESDTNFTCreate), - []byte(hex.EncodeToString(tokenID)), - []byte(hex.EncodeToString(big.NewInt(1).Bytes())), // quantity - name, - []byte(hex.EncodeToString(big.NewInt(10).Bytes())), - hash, - attributes, - uris[0], - }, - []byte("@"), - ) + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) - tx := &transaction.Transaction{ - Nonce: 0, - SndAddr: address.Bytes, - RcvAddr: address.Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, - } + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + tx = nftCreateTx(1, address.Bytes, nftTokenID, nftMetaData) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) - log.Info("Call ESDTModifyCreator and check that the creator was modified") newCreatorAddress, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) @@ -1076,15 +1134,13 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { roles = [][]byte{ []byte(core.ESDTRoleModifyCreator), } - setAddressEsdtRoles(t, cs, newCreatorAddress, tokenID, roles) + setAddressEsdtRoles(t, cs, newCreatorAddress, nftTokenID, roles) - nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - - txDataField = bytes.Join( + txDataField := bytes.Join( [][]byte{ []byte(core.ESDTModifyCreator), - []byte(hex.EncodeToString(tokenID)), - nonce, + []byte(hex.EncodeToString(nftTokenID)), + nftMetaData.Nonce, }, []byte("@"), ) @@ -1106,14 +1162,20 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) + fmt.Println(txResult) + fmt.Println(txResult.Logs.Events[0]) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + require.Equal(t, "success", txResult.Status.String()) - retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(address.Bytes) + retrievedMetaData := getMetaDataFromAcc(t, cs, address.Bytes, nftTokenID, shardID) require.Equal(t, newCreatorAddress.Bytes, retrievedMetaData.Creator) } -// Test scenario +// Test scenario #7 // // Initial setup: Create NFT // @@ -1133,6 +1195,8 @@ func TestChainSimulator_NFT_ESDTSetNewURIs(t *testing.T) { activationEpoch := uint32(2) + baseIssuingCost := "1000" + numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ BypassTxSignatureCheck: false, @@ -1151,6 +1215,7 @@ func TestChainSimulator_NFT_ESDTSetNewURIs(t *testing.T) { NumNodesWaitingListShard: 0, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost }, }) require.Nil(t, err) @@ -1172,64 +1237,43 @@ func TestChainSimulator_NFT_ESDTSetNewURIs(t *testing.T) { log.Info("Initial setup: Create NFT") - tokenID := []byte("ASD-d31313") + nftTicker := []byte("NFTTICKER") + tx := issueNonFungibleTx(0, address.Bytes, nftTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleNFTUpdate), } - setAddressEsdtRoles(t, cs, address, tokenID, roles) - name := []byte(hex.EncodeToString([]byte("name"))) - hash := []byte(hex.EncodeToString([]byte("hash"))) - attributes := []byte(hex.EncodeToString([]byte("attributes"))) - uris := [][]byte{[]byte(hex.EncodeToString([]byte("uri")))} + nftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, address, nftTokenID, roles) - txDataField := bytes.Join( - [][]byte{ - []byte(core.BuiltInFunctionESDTNFTCreate), - []byte(hex.EncodeToString(tokenID)), - []byte(hex.EncodeToString(big.NewInt(1).Bytes())), // quantity - name, - []byte(hex.EncodeToString(big.NewInt(10).Bytes())), - hash, - attributes, - uris[0], - }, - []byte("@"), - ) + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) - tx := &transaction.Transaction{ - Nonce: 0, - SndAddr: address.Bytes, - RcvAddr: address.Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, - } + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + tx = nftCreateTx(1, address.Bytes, nftTokenID, nftMetaData) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - err = cs.GenerateBlocks(10) - require.Nil(t, err) - - shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) - log.Info("Call ESDTSetNewURIs and check that the new URIs were set for the NFT") roles = [][]byte{ []byte(core.ESDTRoleSetNewURI), } - setAddressEsdtRoles(t, cs, address, tokenID, roles) + setAddressEsdtRoles(t, cs, address, nftTokenID, roles) nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - uris = [][]byte{ + uris := [][]byte{ []byte(hex.EncodeToString([]byte("uri0"))), []byte(hex.EncodeToString([]byte("uri1"))), []byte(hex.EncodeToString([]byte("uri2"))), @@ -1241,10 +1285,10 @@ func TestChainSimulator_NFT_ESDTSetNewURIs(t *testing.T) { []byte("uri2"), } - txDataField = bytes.Join( + txDataField := bytes.Join( [][]byte{ []byte(core.ESDTSetNewURIs), - []byte(hex.EncodeToString(tokenID)), + []byte(hex.EncodeToString(nftTokenID)), nonce, uris[0], uris[1], @@ -1254,7 +1298,7 @@ func TestChainSimulator_NFT_ESDTSetNewURIs(t *testing.T) { ) tx = &transaction.Transaction{ - Nonce: 1, + Nonce: 2, SndAddr: address.Bytes, RcvAddr: address.Bytes, GasLimit: 10_000_000, @@ -1272,12 +1316,13 @@ func TestChainSimulator_NFT_ESDTSetNewURIs(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) - retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(address.Bytes) + retrievedMetaData := getMetaDataFromAcc(t, cs, address.Bytes, nftTokenID, shardID) require.Equal(t, expUris, retrievedMetaData.URIs) } -// Test scenario +// Test scenario #8 // // Initial setup: Create NFT // @@ -1297,6 +1342,8 @@ func TestChainSimulator_NFT_ESDTModifyRoyalties(t *testing.T) { activationEpoch := uint32(2) + baseIssuingCost := "1000" + numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ BypassTxSignatureCheck: false, @@ -1315,6 +1362,7 @@ func TestChainSimulator_NFT_ESDTModifyRoyalties(t *testing.T) { NumNodesWaitingListShard: 0, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost }, }) require.Nil(t, err) @@ -1336,69 +1384,48 @@ func TestChainSimulator_NFT_ESDTModifyRoyalties(t *testing.T) { log.Info("Initial setup: Create NFT") - tokenID := []byte("ASD-d31313") + nftTicker := []byte("NFTTICKER") + tx := issueNonFungibleTx(0, address.Bytes, nftTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleNFTUpdate), } - setAddressEsdtRoles(t, cs, address, tokenID, roles) - name := []byte(hex.EncodeToString([]byte("name"))) - hash := []byte(hex.EncodeToString([]byte("hash"))) - attributes := []byte(hex.EncodeToString([]byte("attributes"))) - uris := [][]byte{[]byte(hex.EncodeToString([]byte("uri")))} + nftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, address, nftTokenID, roles) - txDataField := bytes.Join( - [][]byte{ - []byte(core.BuiltInFunctionESDTNFTCreate), - []byte(hex.EncodeToString(tokenID)), - []byte(hex.EncodeToString(big.NewInt(1).Bytes())), // quantity - name, - []byte(hex.EncodeToString(big.NewInt(10).Bytes())), - hash, - attributes, - uris[0], - }, - []byte("@"), - ) + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) - tx := &transaction.Transaction{ - Nonce: 0, - SndAddr: address.Bytes, - RcvAddr: address.Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, - } + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + tx = nftCreateTx(1, address.Bytes, nftTokenID, nftMetaData) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - err = cs.GenerateBlocks(10) - require.Nil(t, err) - - shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) - log.Info("Call ESDTModifyRoyalties and check that the royalties were changed") roles = [][]byte{ []byte(core.ESDTRoleModifyRoyalties), } - setAddressEsdtRoles(t, cs, address, tokenID, roles) + setAddressEsdtRoles(t, cs, address, nftTokenID, roles) nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) royalties := []byte(hex.EncodeToString(big.NewInt(20).Bytes())) - txDataField = bytes.Join( + txDataField := bytes.Join( [][]byte{ []byte(core.ESDTModifyRoyalties), - []byte(hex.EncodeToString(tokenID)), + []byte(hex.EncodeToString(nftTokenID)), nonce, royalties, }, @@ -1406,7 +1433,7 @@ func TestChainSimulator_NFT_ESDTModifyRoyalties(t *testing.T) { ) tx = &transaction.Transaction{ - Nonce: 1, + Nonce: 2, SndAddr: address.Bytes, RcvAddr: address.Bytes, GasLimit: 10_000_000, @@ -1424,7 +1451,8 @@ func TestChainSimulator_NFT_ESDTModifyRoyalties(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) - retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) + shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) + retrievedMetaData := getMetaDataFromAcc(t, cs, address.Bytes, nftTokenID, shardID) require.Equal(t, uint32(big.NewInt(20).Uint64()), retrievedMetaData.Royalties) } From dcc2fcb6db5f09dcbce1783f0cad78cb8886a644 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 30 May 2024 17:13:42 +0300 Subject: [PATCH 283/503] updated es indexer --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e70e37f4219..1555c6f497d 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e github.com/multiversx/mx-chain-core-go v1.2.21-0.20240508071047-fefea5737840 github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df - github.com/multiversx/mx-chain-es-indexer-go v1.7.1-0.20240509104512-25512675833d + github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240514103357-929ece92ef86 github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f diff --git a/go.sum b/go.sum index 185994c8e4f..6d6fa3130cb 100644 --- a/go.sum +++ b/go.sum @@ -391,8 +391,8 @@ github.com/multiversx/mx-chain-core-go v1.2.21-0.20240508071047-fefea5737840 h1: 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.1-0.20240509104512-25512675833d h1:GD1D8V0bE6hDLjrduSsMwQwwf6PMq2Zww7FYMfJsuiw= -github.com/multiversx/mx-chain-es-indexer-go v1.7.1-0.20240509104512-25512675833d/go.mod h1:UDKRXmxsSyPeAcjLUfGeYkAtYp424PIYkL82kzFYobM= +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= From 8749c600de57bb313aee0a964dbc419cac1aeb22 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 30 May 2024 17:22:58 +0300 Subject: [PATCH 284/503] added vm-common fix --- go.mod | 2 +- go.sum | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index e70e37f4219..928c7a4b7c7 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f - github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240509103544-247ce5639c7a + github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240529093845-2a375eef5cc1 github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240509104009-598a37ff36b9 diff --git a/go.sum b/go.sum index 185994c8e4f..a528855ae3e 100644 --- a/go.sum +++ b/go.sum @@ -129,6 +129,7 @@ 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= @@ -261,6 +262,7 @@ 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= @@ -268,6 +270,7 @@ 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= @@ -401,6 +404,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f 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= 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= @@ -413,6 +418,7 @@ 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= From 5214d5b325264686f3d883b2acf3191f547749bb Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 30 May 2024 18:23:23 +0300 Subject: [PATCH 285/503] added already existing metrics --- node/metrics/metrics.go | 3 ++- statusHandler/statusMetricsProvider.go | 12 ++++++++++ statusHandler/statusMetricsProvider_test.go | 25 +++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/node/metrics/metrics.go b/node/metrics/metrics.go index 94c61a4aeb0..b7f0f5e1e1e 100644 --- a/node/metrics/metrics.go +++ b/node/metrics/metrics.go @@ -95,6 +95,7 @@ func InitConfigMetrics( enableEpochs := epochConfig.EnableEpochs + // enable epochs metrics appStatusHandler.SetUInt64Value(common.MetricScDeployEnableEpoch, uint64(enableEpochs.SCDeployEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricBuiltInFunctionsEnableEpoch, uint64(enableEpochs.BuiltInFunctionsEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricRelayedTransactionsEnableEpoch, uint64(enableEpochs.RelayedTransactionsEnableEpoch)) @@ -128,7 +129,6 @@ func InitConfigMetrics( appStatusHandler.SetUInt64Value(common.MetricESDTMultiTransferEnableEpoch, uint64(enableEpochs.ESDTMultiTransferEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricGlobalMintBurnDisableEpoch, uint64(enableEpochs.GlobalMintBurnDisableEpoch)) appStatusHandler.SetUInt64Value(common.MetricESDTTransferRoleEnableEpoch, uint64(enableEpochs.ESDTTransferRoleEnableEpoch)) - appStatusHandler.SetStringValue(common.MetricTotalSupply, economicsConfig.GlobalSettings.GenesisTotalSupply) appStatusHandler.SetUInt64Value(common.MetricSetGuardianEnableEpoch, uint64(enableEpochs.SetGuardianEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricSetScToScLogEventEnableEpoch, uint64(enableEpochs.ScToScLogEventEnableEpoch)) @@ -147,6 +147,7 @@ func InitConfigMetrics( appStatusHandler.SetStringValue(common.MetricHysteresis, fmt.Sprintf("%f", genesisNodesConfig.GetHysteresis())) appStatusHandler.SetStringValue(common.MetricAdaptivity, fmt.Sprintf("%t", genesisNodesConfig.GetAdaptivity())) appStatusHandler.SetStringValue(common.MetricGatewayMetricsEndpoint, gatewayMetricsConfig.URL) + appStatusHandler.SetStringValue(common.MetricTotalSupply, economicsConfig.GlobalSettings.GenesisTotalSupply) return nil } diff --git a/statusHandler/statusMetricsProvider.go b/statusHandler/statusMetricsProvider.go index d0f841468b8..b841d36c5c7 100644 --- a/statusHandler/statusMetricsProvider.go +++ b/statusHandler/statusMetricsProvider.go @@ -295,7 +295,19 @@ func (sm *statusMetrics) EnableEpochsMetrics() (map[string]interface{}, error) { enableEpochsMetrics[common.MetricDelegationSmartContractEnableEpoch] = sm.uint64Metrics[common.MetricDelegationSmartContractEnableEpoch] enableEpochsMetrics[common.MetricIncrementSCRNonceInMultiTransferEnableEpoch] = sm.uint64Metrics[common.MetricIncrementSCRNonceInMultiTransferEnableEpoch] enableEpochsMetrics[common.MetricBalanceWaitingListsEnableEpoch] = sm.uint64Metrics[common.MetricBalanceWaitingListsEnableEpoch] + enableEpochsMetrics[common.MetricCorrectLastUnjailedEnableEpoch] = sm.uint64Metrics[common.MetricCorrectLastUnjailedEnableEpoch] + enableEpochsMetrics[common.MetricReturnDataToLastTransferEnableEpoch] = sm.uint64Metrics[common.MetricReturnDataToLastTransferEnableEpoch] + enableEpochsMetrics[common.MetricSenderInOutTransferEnableEpoch] = sm.uint64Metrics[common.MetricSenderInOutTransferEnableEpoch] + enableEpochsMetrics[common.MetricRelayedTransactionsV2EnableEpoch] = sm.uint64Metrics[common.MetricRelayedTransactionsV2EnableEpoch] + enableEpochsMetrics[common.MetricUnbondTokensV2EnableEpoch] = sm.uint64Metrics[common.MetricUnbondTokensV2EnableEpoch] + enableEpochsMetrics[common.MetricSaveJailedAlwaysEnableEpoch] = sm.uint64Metrics[common.MetricSaveJailedAlwaysEnableEpoch] + enableEpochsMetrics[common.MetricValidatorToDelegationEnableEpoch] = sm.uint64Metrics[common.MetricValidatorToDelegationEnableEpoch] + enableEpochsMetrics[common.MetricReDelegateBelowMinCheckEnableEpoch] = sm.uint64Metrics[common.MetricReDelegateBelowMinCheckEnableEpoch] + enableEpochsMetrics[common.MetricESDTMultiTransferEnableEpoch] = sm.uint64Metrics[common.MetricESDTMultiTransferEnableEpoch] + enableEpochsMetrics[common.MetricGlobalMintBurnDisableEpoch] = sm.uint64Metrics[common.MetricGlobalMintBurnDisableEpoch] + enableEpochsMetrics[common.MetricESDTTransferRoleEnableEpoch] = sm.uint64Metrics[common.MetricESDTTransferRoleEnableEpoch] enableEpochsMetrics[common.MetricSetGuardianEnableEpoch] = sm.uint64Metrics[common.MetricSetGuardianEnableEpoch] + enableEpochsMetrics[common.MetricSetScToScLogEventEnableEpoch] = sm.uint64Metrics[common.MetricSetScToScLogEventEnableEpoch] numNodesChangeConfig := sm.uint64Metrics[common.MetricMaxNodesChangeEnableEpoch+"_count"] diff --git a/statusHandler/statusMetricsProvider_test.go b/statusHandler/statusMetricsProvider_test.go index fbf74ad26fc..3d3ff6a06e7 100644 --- a/statusHandler/statusMetricsProvider_test.go +++ b/statusHandler/statusMetricsProvider_test.go @@ -320,6 +320,19 @@ func TestStatusMetrics_EnableEpochMetrics(t *testing.T) { sm.SetUInt64Value(common.MetricIncrementSCRNonceInMultiTransferEnableEpoch, 3) sm.SetUInt64Value(common.MetricBalanceWaitingListsEnableEpoch, 4) sm.SetUInt64Value(common.MetricSetGuardianEnableEpoch, 3) + sm.SetUInt64Value(common.MetricCorrectLastUnjailedEnableEpoch, 4) + sm.SetUInt64Value(common.MetricReturnDataToLastTransferEnableEpoch, 4) + sm.SetUInt64Value(common.MetricSenderInOutTransferEnableEpoch, 4) + sm.SetUInt64Value(common.MetricRelayedTransactionsV2EnableEpoch, 4) + sm.SetUInt64Value(common.MetricUnbondTokensV2EnableEpoch, 4) + sm.SetUInt64Value(common.MetricSaveJailedAlwaysEnableEpoch, 4) + sm.SetUInt64Value(common.MetricValidatorToDelegationEnableEpoch, 4) + sm.SetUInt64Value(common.MetricReDelegateBelowMinCheckEnableEpoch, 4) + sm.SetUInt64Value(common.MetricESDTMultiTransferEnableEpoch, 4) + sm.SetUInt64Value(common.MetricGlobalMintBurnDisableEpoch, 4) + sm.SetUInt64Value(common.MetricESDTTransferRoleEnableEpoch, 4) + sm.SetUInt64Value(common.MetricSetGuardianEnableEpoch, 3) + sm.SetUInt64Value(common.MetricSetScToScLogEventEnableEpoch, 4) maxNodesChangeConfig := []map[string]uint64{ { @@ -368,7 +381,19 @@ func TestStatusMetrics_EnableEpochMetrics(t *testing.T) { common.MetricDelegationSmartContractEnableEpoch: uint64(2), common.MetricIncrementSCRNonceInMultiTransferEnableEpoch: uint64(3), common.MetricBalanceWaitingListsEnableEpoch: uint64(4), + common.MetricCorrectLastUnjailedEnableEpoch: uint64(4), + common.MetricReturnDataToLastTransferEnableEpoch: uint64(4), + common.MetricSenderInOutTransferEnableEpoch: uint64(4), + common.MetricRelayedTransactionsV2EnableEpoch: uint64(4), + common.MetricUnbondTokensV2EnableEpoch: uint64(4), + common.MetricSaveJailedAlwaysEnableEpoch: uint64(4), + common.MetricValidatorToDelegationEnableEpoch: uint64(4), + common.MetricReDelegateBelowMinCheckEnableEpoch: uint64(4), + common.MetricESDTMultiTransferEnableEpoch: uint64(4), + common.MetricGlobalMintBurnDisableEpoch: uint64(4), + common.MetricESDTTransferRoleEnableEpoch: uint64(4), common.MetricSetGuardianEnableEpoch: uint64(3), + common.MetricSetScToScLogEventEnableEpoch: uint64(4), common.MetricMaxNodesChangeEnableEpoch: []map[string]interface{}{ { From e1c4639e16e81c2509836931ac9937d975842437 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Fri, 31 May 2024 12:44:58 +0300 Subject: [PATCH 286/503] added missing enable epochs metrics --- common/constants.go | 223 +++++++++++++++++++++++-- node/metrics/metrics.go | 69 ++++++++ statusHandler/statusMetricsProvider.go | 69 ++++++++ 3 files changed, 351 insertions(+), 10 deletions(-) diff --git a/common/constants.go b/common/constants.go index 3616e7f67bf..83b4249b0d2 100644 --- a/common/constants.go +++ b/common/constants.go @@ -510,6 +510,9 @@ const ( // MetricIncrementSCRNonceInMultiTransferEnableEpoch represents the epoch when the fix for multi transfer SCR is enabled MetricIncrementSCRNonceInMultiTransferEnableEpoch = "erd_increment_scr_nonce_in_multi_transfer_enable_epoch" + // MetricScheduledMiniBlocksEnableEpoch represents the epoch when the scheduled miniblocks feature is enabled + MetricScheduledMiniBlocksEnableEpoch = "erd_scheduled_miniblocks_enable_epoch" + // MetricESDTMultiTransferEnableEpoch represents the epoch when the ESDT multi transfer feature is enabled MetricESDTMultiTransferEnableEpoch = "erd_esdt_multi_transfer_enable_epoch" @@ -519,6 +522,212 @@ const ( // MetricESDTTransferRoleEnableEpoch represents the epoch when the ESDT transfer role feature is enabled MetricESDTTransferRoleEnableEpoch = "erd_esdt_transfer_role_enable_epoch" + // MetricComputeRewardCheckpointEnableEpoch represents the epoch when compute reward checkpoint feature is enabled + MetricComputeRewardCheckpointEnableEpoch = "erd_compute_reward_checkpoint_enable_epoch" + + // MetricSCRSizeInvariantCheckEnableEpoch represents the epoch when scr size invariant check is enabled + MetricSCRSizeInvariantCheckEnableEpoch = "erd_scr_size_invariant_check_enable_epoch" + + // MetricBackwardCompSaveKeyValueEnableEpoch represents the epoch when backward compatibility save key valu is enabled + MetricBackwardCompSaveKeyValueEnableEpoch = "erd_backward_comp_save_keyvalue_enable_epoch" + + // MetricESDTNFTCreateOnMultiShardEnableEpoch represents the epoch when esdt nft create on multi shard is enabled + MetricESDTNFTCreateOnMultiShardEnableEpoch = "erd_esdt_nft_create_on_multi_shard_enable_epoch" + + // MetricMetaESDTSetEnableEpoch represents the epoch when meta esdt set is enabled + MetricMetaESDTSetEnableEpoch = "erd_meta_esdt_set_enable_epoch" + + // MetricAddTokensToDelegationEnableEpoch represents the epoch when add tokens to delegation + MetricAddTokensToDelegationEnableEpoch = "erd_add_tokens_to_delegation_enable_epoch" + + // MetricMultiESDTTransferFixOnCallBackOnEnableEpoch represents the epoch when multi esdt transfer fix on callback on is enabled + MetricMultiESDTTransferFixOnCallBackOnEnableEpoch = "erd_multi_esdt_transfer_fix_on_callback_enable_epoch" + + // MetricOptimizeGasUsedInCrossMiniBlocksEnableEpoch represents the epoch when optimize gas used in cross miniblocks is enabled + MetricOptimizeGasUsedInCrossMiniBlocksEnableEpoch = "erd_optimize_gas_used_in_cross_miniblocks_enable_epoch" + // MetricCorrectFirstQueuedEpoch represents the epoch when correct first queued fix is enabled + MetricCorrectFirstQueuedEpoch = "erd_correct_first_queued_enable_epoch" + + // MetricCorrectJailedNotUnstakedEmptyQueueEpoch represents the epoch when correct jailed not unstacked meptry queue fix is enabled + MetricCorrectJailedNotUnstakedEmptyQueueEpoch = "erd_correct_jailed_not_unstaked_empty_queue_enable_epoch" + + // MetricFixOOGReturnCodeEnableEpoch represents the epoch when OOG return code fix is enabled + MetricFixOOGReturnCodeEnableEpoch = "erd_fix_oog_return_code_enable_epoch" + + // MetricRemoveNonUpdatedStorageEnableEpoch represents the epoch when remove non updated storage fix is enabled + MetricRemoveNonUpdatedStorageEnableEpoch = "erd_remove_non_updated_storage_enable_epoch" + + // MetricDeleteDelegatorAfterClaimRewardsEnableEpoch represents the epoch when delete delegator after claim rewards fix is enabled + MetricDeleteDelegatorAfterClaimRewardsEnableEpoch = "erd_delete_delegator_after_claim_rewards_enable_epoch" + + // MetricOptimizeNFTStoreEnableEpoch represents the epoch when optimize nft store feature is enabled + MetricOptimizeNFTStoreEnableEpoch = "erd_optimize_nft_store_enable_epoch" + + // MetricCreateNFTThroughExecByCallerEnableEpoch represents the epoch when create nft through exec by caller functionality is enabled + MetricCreateNFTThroughExecByCallerEnableEpoch = "erd_create_nft_through_exec_by_caller_enable_epoch" + + // MetricStopDecreasingValidatorRatingWhenStuckEnableEpoch represents the epoch when stop decreaing validator rating when stuck functionality is enabled + MetricStopDecreasingValidatorRatingWhenStuckEnableEpoch = "erd_stop_decreasing_validator_rating_when_stuck_enable_epoch" + + // MetricFrontRunningProtectionEnableEpoch represents the epoch when front running protection feature is enabled + MetricFrontRunningProtectionEnableEpoch = "erd_front_running_protection_enable_epoch" + + // MetricIsPayableBySCEnableEpoch represents the epoch when is payable by SC feature is enabled + MetricIsPayableBySCEnableEpoch = "erd_is_payable_by_sc_enable_epoch" + + // MetricCleanUpInformativeSCRsEnableEpoch represents the epoch when cleanup informative scrs functionality is enabled + MetricCleanUpInformativeSCRsEnableEpoch = "erd_cleanup_informative_scrs_enable_epoch" + + // MetricStorageAPICostOptimizationEnableEpoch represents the epoch when storage api cost optimization feature is enabled + MetricStorageAPICostOptimizationEnableEpoch = "erd_storage_api_cost_optimization_enable_epoch" + + // MetricTransformToMultiShardCreateEnableEpoch represents the epoch when transform to multi shard create functionality is enabled + MetricTransformToMultiShardCreateEnableEpoch = "erd_transform_to_multi_shard_create_enable_epoch" + + // MetricESDTRegisterAndSetAllRolesEnableEpoch represents the epoch when esdt register and set all roles functionality is enabled + MetricESDTRegisterAndSetAllRolesEnableEpoch = "erd_esdt_register_and_set_all_roles_enable_epoch" + + // MetricDoNotReturnOldBlockInBlockchainHookEnableEpoch represents the epoch when do not return old block in blockchain hook fix is enabled + MetricDoNotReturnOldBlockInBlockchainHookEnableEpoch = "erd_do_not_returns_old_block_in_blockchain_hook_enable_epoch" + + // MetricAddFailedRelayedTxToInvalidMBsDisableEpoch represents the epoch when add failed relayed tx to invalid miniblocks functionality is enabled + MetricAddFailedRelayedTxToInvalidMBsDisableEpoch = "erd_add_failed_relayed_tx_to_invalid_mbs_enable_epoch" + + // MetricSCRSizeInvariantOnBuiltInResultEnableEpoch represents the epoch when scr size invariant on builtin result functionality is enabled + MetricSCRSizeInvariantOnBuiltInResultEnableEpoch = "erd_scr_size_invariant_on_builtin_result_enable_epoch" + + // MetricCheckCorrectTokenIDForTransferRoleEnableEpoch represents the epoch when check correct tokenID for transfer role fix is enabled + MetricCheckCorrectTokenIDForTransferRoleEnableEpoch = "erd_check_correct_tokenid_for_transfer_role_enable_epoch" + + // MetricDisableExecByCallerEnableEpoch represents the epoch when disable exec by caller functionality is enabled + MetricDisableExecByCallerEnableEpoch = "erd_disable_exec_by_caller_enable_epoch" + + // MetricFailExecutionOnEveryAPIErrorEnableEpoch represents the epoch when fail execution on every api error functionality is enabled + MetricFailExecutionOnEveryAPIErrorEnableEpoch = "erd_fail_execution_on_every_api_error_enable_epoch" + + // MetricManagedCryptoAPIsEnableEpoch represents the epoch when managed cypto apis functionality is enabled + MetricManagedCryptoAPIsEnableEpoch = "erd_managed_crypto_apis_enable_epoch" + + // MetricRefactorContextEnableEpoch represents the epoch when refactor context functionality is enabled + MetricRefactorContextEnableEpoch = "erd_refactor_context_enable_epoch" + + // MetricCheckFunctionArgumentEnableEpoch represents the epoch when check function argument functionality is enabled + MetricCheckFunctionArgumentEnableEpoch = "erd_check_function_argument_enable_epoch" + + // MetricCheckExecuteOnReadOnlyEnableEpoch represents the epoch when check execute on read only fix is enabled + MetricCheckExecuteOnReadOnlyEnableEpoch = "erd_check_execute_on_readonly_enable_epoch" + + // MetricMiniBlockPartialExecutionEnableEpoch represents the epoch when miniblock partial execution feature is enabled + MetricMiniBlockPartialExecutionEnableEpoch = "erd_miniblock_partial_execution_enable_epoch" + + // MetricESDTMetadataContinuousCleanupEnableEpoch represents the epoch when esdt metadata continuous clenaup functionality is enabled + MetricESDTMetadataContinuousCleanupEnableEpoch = "erd_esdt_metadata_continuous_cleanup_enable_epoch" + + // MetricFixAsyncCallBackArgsListEnableEpoch represents the epoch when fix async callback args list is enabled + MetricFixAsyncCallBackArgsListEnableEpoch = "erd_fix_async_callback_args_list_enable_epoch" + + // MetricFixOldTokenLiquidityEnableEpoch represents the epoch when fix old token liquidity is enabled + MetricFixOldTokenLiquidityEnableEpoch = "erd_fix_old_token_liquidity_enable_epoch" + + // MetricRuntimeMemStoreLimitEnableEpoch represents the epoch when runtime mem store limit functionality is enabled + MetricRuntimeMemStoreLimitEnableEpoch = "erd_runtime_mem_store_limit_enable_epoch" + + // MetricRuntimeCodeSizeFixEnableEpoch represents the epoch when runtime code size fix is enabled + MetricRuntimeCodeSizeFixEnableEpoch = "erd_runtime_code_size_fix_enable_epoch" + + // MetricSetSenderInEeiOutputTransferEnableEpoch represents the epoch when set sender in eei output transfer functionality is enabled + MetricSetSenderInEeiOutputTransferEnableEpoch = "erd_set_sender_in_eei_output_transfer_enable_epoch" + + // MetricRefactorPeersMiniBlocksEnableEpoch represents the epoch when refactor peers miniblock feature is enabled + MetricRefactorPeersMiniBlocksEnableEpoch = "erd_refactor_peers_miniblocks_enable_epoch" + + // MetricSCProcessorV2EnableEpoch represents the epoch when SC processor V2 feature is enabled + MetricSCProcessorV2EnableEpoch = "erd_sc_processorv2_enable_epoch" + + // MetricMaxBlockchainHookCountersEnableEpoch represents the epoch when max blockchain hook counters functionality is enabled + MetricMaxBlockchainHookCountersEnableEpoch = "erd_max_blockchain_hook_counters_enable_epoch" + + // MetricWipeSingleNFTLiquidityDecreaseEnableEpoch represents the epoch when wipe single NFT liquidity decrease functionality is enabled + MetricWipeSingleNFTLiquidityDecreaseEnableEpoch = "erd_wipe_single_nft_liquidity_decrease_enable_epoch" + + // MetricAlwaysSaveTokenMetaDataEnableEpoch represents the epoch when always save token metadata functionality is enabled + MetricAlwaysSaveTokenMetaDataEnableEpoch = "erd_always_save_token_metadata_enable_epoch" + + // MetricSetGuardianEnableEpoch represents the epoch when the guardian feature is enabled + MetricSetGuardianEnableEpoch = "erd_set_guardian_feature_enable_epoch" + + // MetricSetScToScLogEventEnableEpoch represents the epoch when the sc to sc log event feature is enabled + MetricSetScToScLogEventEnableEpoch = "erd_set_sc_to_sc_log_event_enable_epoch" + + // MetricRelayedNonceFixEnableEpoch represents the epoch when relayed nonce fix is enabled + MetricRelayedNonceFixEnableEpoch = "erd_relayed_nonce_fix_enable_epoch" + + // MetricDeterministicSortOnValidatorsInfoEnableEpoch represents the epoch when deterministic sort on validators info functionality is enabled + MetricDeterministicSortOnValidatorsInfoEnableEpoch = "erd_deterministic_sort_on_validators_info_enable_epoch" + + // MetricKeepExecOrderOnCreatedSCRsEnableEpoch represents the epoch when keep exec order on created scs fix is enabled + MetricKeepExecOrderOnCreatedSCRsEnableEpoch = "erd_keep_exec_order_on_created_scrs_enable_epoch" + + // MetricMultiClaimOnDelegationEnableEpoch represents the epoch when multi claim on delegation functionality is enabled + MetricMultiClaimOnDelegationEnableEpoch = "erd_multi_claim_on_delegation_enable_epoch" + + // MetricChangeUsernameEnableEpoch represents the epoch when change username functionality is enabled + MetricChangeUsernameEnableEpoch = "erd_change_username_enable_epoch" + + // MetricAutoBalanceDataTriesEnableEpoch represents the epoch when auto balance data tries feature is enabled + MetricAutoBalanceDataTriesEnableEpoch = "erd_auto_balance_data_tries_enable_epoch" + + // MetricMigrateDataTrieEnableEpoch represents the epoch when migrate data trie feature is enabled + MetricMigrateDataTrieEnableEpoch = "erd_migrate_datatrie_enable_epoch" + + // MetricConsistentTokensValuesLengthCheckEnableEpoch represents the epoch when consistent tokens values length check is enabled + MetricConsistentTokensValuesLengthCheckEnableEpoch = "erd_consistent_tokens_values_length_check_enable_epoch" + + // MetricFixDelegationChangeOwnerOnAccountEnableEpoch represents the epoch when fix delegation change owner on account is enabled + MetricFixDelegationChangeOwnerOnAccountEnableEpoch = "erd_fix_delegation_change_owner_on_account_enable_epoch" + + // MetricDynamicGasCostForDataTrieStorageLoadEnableEpoch represents the epoch when dynamic gas cost for data tries storage load functionality is enabled + MetricDynamicGasCostForDataTrieStorageLoadEnableEpoch = "erd_dynamic_gas_cost_for_datatrie_storage_load_enable_epoch" + + // MetricNFTStopCreateEnableEpoch represents the epoch when NFT stop create functionality is enabled + MetricNFTStopCreateEnableEpoch = "erd_nft_stop_create_enable_epoch" + + // MetricChangeOwnerAddressCrossShardThroughSCEnableEpoch represents the epoch when change owner address cross shard through SC functionality is enabled + MetricChangeOwnerAddressCrossShardThroughSCEnableEpoch = "erd_change_owner_address_cross_shard_through_sc_enable_epoch" + + // MetricFixGasRemainingForSaveKeyValueBuiltinFunctionEnableEpoch represents the epoch when fix gas remaining for save key value builin function is enabled + MetricFixGasRemainingForSaveKeyValueBuiltinFunctionEnableEpoch = "erd_fix_gas_remainig_for_save_keyvalue_builtin_function_enable_epoch" + + // MetricCurrentRandomnessOnSortingEnableEpoch represents the epoch when current randomness on sorting functionality is enabled + MetricCurrentRandomnessOnSortingEnableEpoch = "erd_current_randomness_on_sorting_enable_epoch" + + // MetricStakeLimitsEnableEpoch represents the epoch when stake limits functionality is enabled + MetricStakeLimitsEnableEpoch = "erd_stake_limits_enable_epoch" + + // MetricStakingV4Step1EnableEpoch represents the epoch when staking v4 step 1 feature is enabled + MetricStakingV4Step1EnableEpoch = "erd_staking_v4_step1_enable_epoch" + + // MetricStakingV4Step2EnableEpoch represents the epoch when staking v4 step 2 feature is enabled + MetricStakingV4Step2EnableEpoch = "erd_staking_v4_step2_enable_epoch" + + // MetricStakingV4Step3EnableEpoch represents the epoch when staking v4 step 3 feature is enabled + MetricStakingV4Step3EnableEpoch = "erd_staking_v4_step3_enable_epoch" + + // MetricCleanupAuctionOnLowWaitingListEnableEpoch represents the epoch when cleanup auction on low waiting list fix is enabled + MetricCleanupAuctionOnLowWaitingListEnableEpoch = "erd_cleanup_auction_on_low_waiting_list_enable_epoch" + + // MetricAlwaysMergeContextsInEEIEnableEpoch represents the epoch when always merge contexts in EEI fix is enabled + MetricAlwaysMergeContextsInEEIEnableEpoch = "erd_always_merge_contexts_in_eei_enable_epoch" + + // MetricDynamicESDTEnableEpoch represents the epoch when dynamic ESDT feature is enabled + MetricDynamicESDTEnableEpoch = "erd_dynamic_esdt_enable_epoch" + + // MetricEGLDInMultiTransferEnableEpoch represents the epoch when EGLD in multi transfer feature is enabled + MetricEGLDInMultiTransferEnableEpoch = "erd_egld_in_multi_transfer_enable_epoch" + + // MetricCryptoOpcodesV2EnableEpoch represents the epoch when crypto opcodes v2 feature is enabled + MetricCryptoOpcodesV2EnableEpoch = "erd_crypto_opcodes_v2_enable_epoch" + // MetricMaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MetricMaxNodesChangeEnableEpoch = "erd_max_nodes_change_enable_epoch" @@ -539,12 +748,6 @@ const ( // NodesToShufflePerShardSuffix represents the suffix for NodesToShufflePerShard item in MaxNodesChangeEnableEpoch list NodesToShufflePerShardSuffix = "_nodes_to_shuffle_per_shard" - - // MetricHysteresis represents the hysteresis threshold - MetricHysteresis = "erd_hysteresis" - - // MetricAdaptivity represents a boolean to determine if adaptivity will be enabled or not - MetricAdaptivity = "erd_adaptivity" ) const ( @@ -623,11 +826,11 @@ const ( // MetricRatingsPeerHonestyUnitValue represents the peer honesty unit value MetricRatingsPeerHonestyUnitValue = "erd_ratings_peerhonesty_unit_value" - // MetricSetGuardianEnableEpoch represents the epoch when the guardian feature is enabled - MetricSetGuardianEnableEpoch = "erd_set_guardian_feature_enable_epoch" + // MetricHysteresis represents the hysteresis threshold + MetricHysteresis = "erd_hysteresis" - // MetricSetScToScLogEventEnableEpoch represents the epoch when the sc to sc log event feature is enabled - MetricSetScToScLogEventEnableEpoch = "erd_set_sc_to_sc_log_event_enable_epoch" + // MetricAdaptivity represents a boolean to determine if adaptivity will be enabled or not + MetricAdaptivity = "erd_adaptivity" ) const ( diff --git a/node/metrics/metrics.go b/node/metrics/metrics.go index b7f0f5e1e1e..0fdd8f206b1 100644 --- a/node/metrics/metrics.go +++ b/node/metrics/metrics.go @@ -126,11 +126,80 @@ func InitConfigMetrics( appStatusHandler.SetUInt64Value(common.MetricValidatorToDelegationEnableEpoch, uint64(enableEpochs.ValidatorToDelegationEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricReDelegateBelowMinCheckEnableEpoch, uint64(enableEpochs.ReDelegateBelowMinCheckEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricIncrementSCRNonceInMultiTransferEnableEpoch, uint64(enableEpochs.IncrementSCRNonceInMultiTransferEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricScheduledMiniBlocksEnableEpoch, uint64(enableEpochs.ScheduledMiniBlocksEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricESDTMultiTransferEnableEpoch, uint64(enableEpochs.ESDTMultiTransferEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricGlobalMintBurnDisableEpoch, uint64(enableEpochs.GlobalMintBurnDisableEpoch)) appStatusHandler.SetUInt64Value(common.MetricESDTTransferRoleEnableEpoch, uint64(enableEpochs.ESDTTransferRoleEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricComputeRewardCheckpointEnableEpoch, uint64(enableEpochs.ComputeRewardCheckpointEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricSCRSizeInvariantCheckEnableEpoch, uint64(enableEpochs.SCRSizeInvariantCheckEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricBackwardCompSaveKeyValueEnableEpoch, uint64(enableEpochs.BackwardCompSaveKeyValueEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricESDTNFTCreateOnMultiShardEnableEpoch, uint64(enableEpochs.ESDTNFTCreateOnMultiShardEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricMetaESDTSetEnableEpoch, uint64(enableEpochs.MetaESDTSetEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricAddTokensToDelegationEnableEpoch, uint64(enableEpochs.AddTokensToDelegationEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricMultiESDTTransferFixOnCallBackOnEnableEpoch, uint64(enableEpochs.MultiESDTTransferFixOnCallBackOnEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricOptimizeGasUsedInCrossMiniBlocksEnableEpoch, uint64(enableEpochs.OptimizeGasUsedInCrossMiniBlocksEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricCorrectFirstQueuedEpoch, uint64(enableEpochs.CorrectFirstQueuedEpoch)) + appStatusHandler.SetUInt64Value(common.MetricCorrectJailedNotUnstakedEmptyQueueEpoch, uint64(enableEpochs.CorrectJailedNotUnstakedEmptyQueueEpoch)) + appStatusHandler.SetUInt64Value(common.MetricFixOOGReturnCodeEnableEpoch, uint64(enableEpochs.FixOOGReturnCodeEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricRemoveNonUpdatedStorageEnableEpoch, uint64(enableEpochs.RemoveNonUpdatedStorageEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricDeleteDelegatorAfterClaimRewardsEnableEpoch, uint64(enableEpochs.DeleteDelegatorAfterClaimRewardsEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricOptimizeNFTStoreEnableEpoch, uint64(enableEpochs.OptimizeNFTStoreEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricCreateNFTThroughExecByCallerEnableEpoch, uint64(enableEpochs.CreateNFTThroughExecByCallerEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricStopDecreasingValidatorRatingWhenStuckEnableEpoch, uint64(enableEpochs.StopDecreasingValidatorRatingWhenStuckEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricFrontRunningProtectionEnableEpoch, uint64(enableEpochs.FrontRunningProtectionEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricIsPayableBySCEnableEpoch, uint64(enableEpochs.IsPayableBySCEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricCleanUpInformativeSCRsEnableEpoch, uint64(enableEpochs.CleanUpInformativeSCRsEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricStorageAPICostOptimizationEnableEpoch, uint64(enableEpochs.StorageAPICostOptimizationEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricTransformToMultiShardCreateEnableEpoch, uint64(enableEpochs.TransformToMultiShardCreateEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricESDTRegisterAndSetAllRolesEnableEpoch, uint64(enableEpochs.ESDTRegisterAndSetAllRolesEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricDoNotReturnOldBlockInBlockchainHookEnableEpoch, uint64(enableEpochs.DoNotReturnOldBlockInBlockchainHookEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricAddFailedRelayedTxToInvalidMBsDisableEpoch, uint64(enableEpochs.AddFailedRelayedTxToInvalidMBsDisableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricSCRSizeInvariantOnBuiltInResultEnableEpoch, uint64(enableEpochs.SCRSizeInvariantOnBuiltInResultEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricCheckCorrectTokenIDForTransferRoleEnableEpoch, uint64(enableEpochs.CheckCorrectTokenIDForTransferRoleEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricDisableExecByCallerEnableEpoch, uint64(enableEpochs.DisableExecByCallerEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricFailExecutionOnEveryAPIErrorEnableEpoch, uint64(enableEpochs.FailExecutionOnEveryAPIErrorEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricManagedCryptoAPIsEnableEpoch, uint64(enableEpochs.ManagedCryptoAPIsEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricRefactorContextEnableEpoch, uint64(enableEpochs.RefactorContextEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricCheckFunctionArgumentEnableEpoch, uint64(enableEpochs.CheckFunctionArgumentEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricCheckExecuteOnReadOnlyEnableEpoch, uint64(enableEpochs.CheckExecuteOnReadOnlyEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricMiniBlockPartialExecutionEnableEpoch, uint64(enableEpochs.MiniBlockPartialExecutionEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricESDTMetadataContinuousCleanupEnableEpoch, uint64(enableEpochs.ESDTMetadataContinuousCleanupEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricFixAsyncCallBackArgsListEnableEpoch, uint64(enableEpochs.FixAsyncCallBackArgsListEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricFixOldTokenLiquidityEnableEpoch, uint64(enableEpochs.FixOldTokenLiquidityEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricRuntimeMemStoreLimitEnableEpoch, uint64(enableEpochs.RuntimeMemStoreLimitEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricRuntimeCodeSizeFixEnableEpoch, uint64(enableEpochs.RuntimeCodeSizeFixEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricSetSenderInEeiOutputTransferEnableEpoch, uint64(enableEpochs.SetSenderInEeiOutputTransferEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricRefactorPeersMiniBlocksEnableEpoch, uint64(enableEpochs.RefactorPeersMiniBlocksEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricSCProcessorV2EnableEpoch, uint64(enableEpochs.SCProcessorV2EnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricMaxBlockchainHookCountersEnableEpoch, uint64(enableEpochs.MaxBlockchainHookCountersEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricWipeSingleNFTLiquidityDecreaseEnableEpoch, uint64(enableEpochs.WipeSingleNFTLiquidityDecreaseEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricAlwaysSaveTokenMetaDataEnableEpoch, uint64(enableEpochs.AlwaysSaveTokenMetaDataEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricCleanUpInformativeSCRsEnableEpoch, uint64(enableEpochs.CleanUpInformativeSCRsEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricSetGuardianEnableEpoch, uint64(enableEpochs.SetGuardianEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricSetScToScLogEventEnableEpoch, uint64(enableEpochs.ScToScLogEventEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricRelayedNonceFixEnableEpoch, uint64(enableEpochs.RelayedNonceFixEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricDeterministicSortOnValidatorsInfoEnableEpoch, uint64(enableEpochs.DeterministicSortOnValidatorsInfoEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricKeepExecOrderOnCreatedSCRsEnableEpoch, uint64(enableEpochs.KeepExecOrderOnCreatedSCRsEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricMultiClaimOnDelegationEnableEpoch, uint64(enableEpochs.MultiClaimOnDelegationEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricChangeUsernameEnableEpoch, uint64(enableEpochs.ChangeUsernameEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricAutoBalanceDataTriesEnableEpoch, uint64(enableEpochs.AutoBalanceDataTriesEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricMigrateDataTrieEnableEpoch, uint64(enableEpochs.MigrateDataTrieEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricConsistentTokensValuesLengthCheckEnableEpoch, uint64(enableEpochs.ConsistentTokensValuesLengthCheckEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricFixDelegationChangeOwnerOnAccountEnableEpoch, uint64(enableEpochs.FixDelegationChangeOwnerOnAccountEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricDynamicGasCostForDataTrieStorageLoadEnableEpoch, uint64(enableEpochs.DynamicGasCostForDataTrieStorageLoadEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricNFTStopCreateEnableEpoch, uint64(enableEpochs.NFTStopCreateEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricChangeOwnerAddressCrossShardThroughSCEnableEpoch, uint64(enableEpochs.ChangeOwnerAddressCrossShardThroughSCEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricFixGasRemainingForSaveKeyValueBuiltinFunctionEnableEpoch, uint64(enableEpochs.FixGasRemainingForSaveKeyValueBuiltinFunctionEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricCurrentRandomnessOnSortingEnableEpoch, uint64(enableEpochs.CurrentRandomnessOnSortingEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricStakeLimitsEnableEpoch, uint64(enableEpochs.StakeLimitsEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricStakingV4Step1EnableEpoch, uint64(enableEpochs.StakingV4Step1EnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricStakingV4Step2EnableEpoch, uint64(enableEpochs.StakingV4Step2EnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricStakingV4Step3EnableEpoch, uint64(enableEpochs.StakingV4Step3EnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricCleanupAuctionOnLowWaitingListEnableEpoch, uint64(enableEpochs.CleanupAuctionOnLowWaitingListEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricAlwaysMergeContextsInEEIEnableEpoch, uint64(enableEpochs.AlwaysMergeContextsInEEIEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricDynamicESDTEnableEpoch, uint64(enableEpochs.DynamicESDTEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricEGLDInMultiTransferEnableEpoch, uint64(enableEpochs.EGLDInMultiTransferEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricCryptoOpcodesV2EnableEpoch, uint64(enableEpochs.CryptoOpcodesV2EnableEpoch)) for i, nodesChangeConfig := range enableEpochs.MaxNodesChangeEnableEpoch { epochEnable := fmt.Sprintf("%s%d%s", common.MetricMaxNodesChangeEnableEpoch, i, common.EpochEnableSuffix) diff --git a/statusHandler/statusMetricsProvider.go b/statusHandler/statusMetricsProvider.go index b841d36c5c7..b47b6851eae 100644 --- a/statusHandler/statusMetricsProvider.go +++ b/statusHandler/statusMetricsProvider.go @@ -303,11 +303,80 @@ func (sm *statusMetrics) EnableEpochsMetrics() (map[string]interface{}, error) { enableEpochsMetrics[common.MetricSaveJailedAlwaysEnableEpoch] = sm.uint64Metrics[common.MetricSaveJailedAlwaysEnableEpoch] enableEpochsMetrics[common.MetricValidatorToDelegationEnableEpoch] = sm.uint64Metrics[common.MetricValidatorToDelegationEnableEpoch] enableEpochsMetrics[common.MetricReDelegateBelowMinCheckEnableEpoch] = sm.uint64Metrics[common.MetricReDelegateBelowMinCheckEnableEpoch] + enableEpochsMetrics[common.MetricScheduledMiniBlocksEnableEpoch] = sm.uint64Metrics[common.MetricScheduledMiniBlocksEnableEpoch] enableEpochsMetrics[common.MetricESDTMultiTransferEnableEpoch] = sm.uint64Metrics[common.MetricESDTMultiTransferEnableEpoch] enableEpochsMetrics[common.MetricGlobalMintBurnDisableEpoch] = sm.uint64Metrics[common.MetricGlobalMintBurnDisableEpoch] enableEpochsMetrics[common.MetricESDTTransferRoleEnableEpoch] = sm.uint64Metrics[common.MetricESDTTransferRoleEnableEpoch] + enableEpochsMetrics[common.MetricComputeRewardCheckpointEnableEpoch] = sm.uint64Metrics[common.MetricComputeRewardCheckpointEnableEpoch] + enableEpochsMetrics[common.MetricSCRSizeInvariantCheckEnableEpoch] = sm.uint64Metrics[common.MetricSCRSizeInvariantCheckEnableEpoch] + enableEpochsMetrics[common.MetricBackwardCompSaveKeyValueEnableEpoch] = sm.uint64Metrics[common.MetricBackwardCompSaveKeyValueEnableEpoch] + enableEpochsMetrics[common.MetricESDTNFTCreateOnMultiShardEnableEpoch] = sm.uint64Metrics[common.MetricESDTNFTCreateOnMultiShardEnableEpoch] + enableEpochsMetrics[common.MetricMetaESDTSetEnableEpoch] = sm.uint64Metrics[common.MetricMetaESDTSetEnableEpoch] + enableEpochsMetrics[common.MetricAddTokensToDelegationEnableEpoch] = sm.uint64Metrics[common.MetricAddTokensToDelegationEnableEpoch] + enableEpochsMetrics[common.MetricMultiESDTTransferFixOnCallBackOnEnableEpoch] = sm.uint64Metrics[common.MetricMultiESDTTransferFixOnCallBackOnEnableEpoch] + enableEpochsMetrics[common.MetricOptimizeGasUsedInCrossMiniBlocksEnableEpoch] = sm.uint64Metrics[common.MetricOptimizeGasUsedInCrossMiniBlocksEnableEpoch] + enableEpochsMetrics[common.MetricCorrectFirstQueuedEpoch] = sm.uint64Metrics[common.MetricCorrectFirstQueuedEpoch] + enableEpochsMetrics[common.MetricCorrectJailedNotUnstakedEmptyQueueEpoch] = sm.uint64Metrics[common.MetricCorrectJailedNotUnstakedEmptyQueueEpoch] + enableEpochsMetrics[common.MetricFixOOGReturnCodeEnableEpoch] = sm.uint64Metrics[common.MetricFixOOGReturnCodeEnableEpoch] + enableEpochsMetrics[common.MetricRemoveNonUpdatedStorageEnableEpoch] = sm.uint64Metrics[common.MetricRemoveNonUpdatedStorageEnableEpoch] + enableEpochsMetrics[common.MetricDeleteDelegatorAfterClaimRewardsEnableEpoch] = sm.uint64Metrics[common.MetricDeleteDelegatorAfterClaimRewardsEnableEpoch] + enableEpochsMetrics[common.MetricOptimizeNFTStoreEnableEpoch] = sm.uint64Metrics[common.MetricOptimizeNFTStoreEnableEpoch] + enableEpochsMetrics[common.MetricCreateNFTThroughExecByCallerEnableEpoch] = sm.uint64Metrics[common.MetricCreateNFTThroughExecByCallerEnableEpoch] + enableEpochsMetrics[common.MetricStopDecreasingValidatorRatingWhenStuckEnableEpoch] = sm.uint64Metrics[common.MetricStopDecreasingValidatorRatingWhenStuckEnableEpoch] + enableEpochsMetrics[common.MetricFrontRunningProtectionEnableEpoch] = sm.uint64Metrics[common.MetricFrontRunningProtectionEnableEpoch] + enableEpochsMetrics[common.MetricIsPayableBySCEnableEpoch] = sm.uint64Metrics[common.MetricIsPayableBySCEnableEpoch] + enableEpochsMetrics[common.MetricCleanUpInformativeSCRsEnableEpoch] = sm.uint64Metrics[common.MetricCleanUpInformativeSCRsEnableEpoch] + enableEpochsMetrics[common.MetricStorageAPICostOptimizationEnableEpoch] = sm.uint64Metrics[common.MetricStorageAPICostOptimizationEnableEpoch] + enableEpochsMetrics[common.MetricTransformToMultiShardCreateEnableEpoch] = sm.uint64Metrics[common.MetricTransformToMultiShardCreateEnableEpoch] + enableEpochsMetrics[common.MetricESDTRegisterAndSetAllRolesEnableEpoch] = sm.uint64Metrics[common.MetricESDTRegisterAndSetAllRolesEnableEpoch] + enableEpochsMetrics[common.MetricDoNotReturnOldBlockInBlockchainHookEnableEpoch] = sm.uint64Metrics[common.MetricDoNotReturnOldBlockInBlockchainHookEnableEpoch] + enableEpochsMetrics[common.MetricAddFailedRelayedTxToInvalidMBsDisableEpoch] = sm.uint64Metrics[common.MetricAddFailedRelayedTxToInvalidMBsDisableEpoch] + enableEpochsMetrics[common.MetricSCRSizeInvariantOnBuiltInResultEnableEpoch] = sm.uint64Metrics[common.MetricSCRSizeInvariantOnBuiltInResultEnableEpoch] + enableEpochsMetrics[common.MetricCheckCorrectTokenIDForTransferRoleEnableEpoch] = sm.uint64Metrics[common.MetricCheckCorrectTokenIDForTransferRoleEnableEpoch] + enableEpochsMetrics[common.MetricDisableExecByCallerEnableEpoch] = sm.uint64Metrics[common.MetricDisableExecByCallerEnableEpoch] + enableEpochsMetrics[common.MetricFailExecutionOnEveryAPIErrorEnableEpoch] = sm.uint64Metrics[common.MetricFailExecutionOnEveryAPIErrorEnableEpoch] + enableEpochsMetrics[common.MetricManagedCryptoAPIsEnableEpoch] = sm.uint64Metrics[common.MetricManagedCryptoAPIsEnableEpoch] + enableEpochsMetrics[common.MetricRefactorContextEnableEpoch] = sm.uint64Metrics[common.MetricRefactorContextEnableEpoch] + enableEpochsMetrics[common.MetricCheckFunctionArgumentEnableEpoch] = sm.uint64Metrics[common.MetricCheckFunctionArgumentEnableEpoch] + enableEpochsMetrics[common.MetricCheckExecuteOnReadOnlyEnableEpoch] = sm.uint64Metrics[common.MetricCheckExecuteOnReadOnlyEnableEpoch] + enableEpochsMetrics[common.MetricMiniBlockPartialExecutionEnableEpoch] = sm.uint64Metrics[common.MetricMiniBlockPartialExecutionEnableEpoch] + enableEpochsMetrics[common.MetricESDTMetadataContinuousCleanupEnableEpoch] = sm.uint64Metrics[common.MetricESDTMetadataContinuousCleanupEnableEpoch] + enableEpochsMetrics[common.MetricFixAsyncCallBackArgsListEnableEpoch] = sm.uint64Metrics[common.MetricFixAsyncCallBackArgsListEnableEpoch] + enableEpochsMetrics[common.MetricFixOldTokenLiquidityEnableEpoch] = sm.uint64Metrics[common.MetricFixOldTokenLiquidityEnableEpoch] + enableEpochsMetrics[common.MetricRuntimeMemStoreLimitEnableEpoch] = sm.uint64Metrics[common.MetricRuntimeMemStoreLimitEnableEpoch] + enableEpochsMetrics[common.MetricRuntimeCodeSizeFixEnableEpoch] = sm.uint64Metrics[common.MetricRuntimeCodeSizeFixEnableEpoch] + enableEpochsMetrics[common.MetricSetSenderInEeiOutputTransferEnableEpoch] = sm.uint64Metrics[common.MetricSetSenderInEeiOutputTransferEnableEpoch] + enableEpochsMetrics[common.MetricRefactorPeersMiniBlocksEnableEpoch] = sm.uint64Metrics[common.MetricRefactorPeersMiniBlocksEnableEpoch] + enableEpochsMetrics[common.MetricSCProcessorV2EnableEpoch] = sm.uint64Metrics[common.MetricSCProcessorV2EnableEpoch] + enableEpochsMetrics[common.MetricMaxBlockchainHookCountersEnableEpoch] = sm.uint64Metrics[common.MetricMaxBlockchainHookCountersEnableEpoch] + enableEpochsMetrics[common.MetricWipeSingleNFTLiquidityDecreaseEnableEpoch] = sm.uint64Metrics[common.MetricWipeSingleNFTLiquidityDecreaseEnableEpoch] + enableEpochsMetrics[common.MetricAlwaysSaveTokenMetaDataEnableEpoch] = sm.uint64Metrics[common.MetricAlwaysSaveTokenMetaDataEnableEpoch] + enableEpochsMetrics[common.MetricCleanUpInformativeSCRsEnableEpoch] = sm.uint64Metrics[common.MetricCleanUpInformativeSCRsEnableEpoch] enableEpochsMetrics[common.MetricSetGuardianEnableEpoch] = sm.uint64Metrics[common.MetricSetGuardianEnableEpoch] enableEpochsMetrics[common.MetricSetScToScLogEventEnableEpoch] = sm.uint64Metrics[common.MetricSetScToScLogEventEnableEpoch] + enableEpochsMetrics[common.MetricRelayedNonceFixEnableEpoch] = sm.uint64Metrics[common.MetricRelayedNonceFixEnableEpoch] + enableEpochsMetrics[common.MetricDeterministicSortOnValidatorsInfoEnableEpoch] = sm.uint64Metrics[common.MetricDeterministicSortOnValidatorsInfoEnableEpoch] + enableEpochsMetrics[common.MetricKeepExecOrderOnCreatedSCRsEnableEpoch] = sm.uint64Metrics[common.MetricKeepExecOrderOnCreatedSCRsEnableEpoch] + enableEpochsMetrics[common.MetricMultiClaimOnDelegationEnableEpoch] = sm.uint64Metrics[common.MetricMultiClaimOnDelegationEnableEpoch] + enableEpochsMetrics[common.MetricChangeUsernameEnableEpoch] = sm.uint64Metrics[common.MetricChangeUsernameEnableEpoch] + enableEpochsMetrics[common.MetricAutoBalanceDataTriesEnableEpoch] = sm.uint64Metrics[common.MetricAutoBalanceDataTriesEnableEpoch] + enableEpochsMetrics[common.MetricMigrateDataTrieEnableEpoch] = sm.uint64Metrics[common.MetricMigrateDataTrieEnableEpoch] + enableEpochsMetrics[common.MetricConsistentTokensValuesLengthCheckEnableEpoch] = sm.uint64Metrics[common.MetricConsistentTokensValuesLengthCheckEnableEpoch] + enableEpochsMetrics[common.MetricFixDelegationChangeOwnerOnAccountEnableEpoch] = sm.uint64Metrics[common.MetricFixDelegationChangeOwnerOnAccountEnableEpoch] + enableEpochsMetrics[common.MetricDynamicGasCostForDataTrieStorageLoadEnableEpoch] = sm.uint64Metrics[common.MetricDynamicGasCostForDataTrieStorageLoadEnableEpoch] + enableEpochsMetrics[common.MetricNFTStopCreateEnableEpoch] = sm.uint64Metrics[common.MetricNFTStopCreateEnableEpoch] + enableEpochsMetrics[common.MetricChangeOwnerAddressCrossShardThroughSCEnableEpoch] = sm.uint64Metrics[common.MetricChangeOwnerAddressCrossShardThroughSCEnableEpoch] + enableEpochsMetrics[common.MetricFixGasRemainingForSaveKeyValueBuiltinFunctionEnableEpoch] = sm.uint64Metrics[common.MetricFixGasRemainingForSaveKeyValueBuiltinFunctionEnableEpoch] + enableEpochsMetrics[common.MetricCurrentRandomnessOnSortingEnableEpoch] = sm.uint64Metrics[common.MetricCurrentRandomnessOnSortingEnableEpoch] + enableEpochsMetrics[common.MetricStakeLimitsEnableEpoch] = sm.uint64Metrics[common.MetricStakeLimitsEnableEpoch] + enableEpochsMetrics[common.MetricStakingV4Step1EnableEpoch] = sm.uint64Metrics[common.MetricStakingV4Step1EnableEpoch] + enableEpochsMetrics[common.MetricStakingV4Step2EnableEpoch] = sm.uint64Metrics[common.MetricStakingV4Step2EnableEpoch] + enableEpochsMetrics[common.MetricStakingV4Step3EnableEpoch] = sm.uint64Metrics[common.MetricStakingV4Step3EnableEpoch] + enableEpochsMetrics[common.MetricCleanupAuctionOnLowWaitingListEnableEpoch] = sm.uint64Metrics[common.MetricCleanupAuctionOnLowWaitingListEnableEpoch] + enableEpochsMetrics[common.MetricAlwaysMergeContextsInEEIEnableEpoch] = sm.uint64Metrics[common.MetricAlwaysMergeContextsInEEIEnableEpoch] + enableEpochsMetrics[common.MetricDynamicESDTEnableEpoch] = sm.uint64Metrics[common.MetricDynamicESDTEnableEpoch] + enableEpochsMetrics[common.MetricEGLDInMultiTransferEnableEpoch] = sm.uint64Metrics[common.MetricEGLDInMultiTransferEnableEpoch] + enableEpochsMetrics[common.MetricCryptoOpcodesV2EnableEpoch] = sm.uint64Metrics[common.MetricCryptoOpcodesV2EnableEpoch] numNodesChangeConfig := sm.uint64Metrics[common.MetricMaxNodesChangeEnableEpoch+"_count"] From 29451429cff6ce6c212c669d27728daca611e34e Mon Sep 17 00:00:00 2001 From: ssd04 Date: Fri, 31 May 2024 13:37:56 +0300 Subject: [PATCH 287/503] update node metrics and status handler unit tests --- node/metrics/metrics.go | 1 - node/metrics/metrics_test.go | 292 ++++++++++++++------ statusHandler/statusMetricsProvider_test.go | 277 ++++++++++++++----- 3 files changed, 420 insertions(+), 150 deletions(-) diff --git a/node/metrics/metrics.go b/node/metrics/metrics.go index 0fdd8f206b1..25356b0513c 100644 --- a/node/metrics/metrics.go +++ b/node/metrics/metrics.go @@ -148,7 +148,6 @@ func InitConfigMetrics( appStatusHandler.SetUInt64Value(common.MetricStopDecreasingValidatorRatingWhenStuckEnableEpoch, uint64(enableEpochs.StopDecreasingValidatorRatingWhenStuckEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricFrontRunningProtectionEnableEpoch, uint64(enableEpochs.FrontRunningProtectionEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricIsPayableBySCEnableEpoch, uint64(enableEpochs.IsPayableBySCEnableEpoch)) - appStatusHandler.SetUInt64Value(common.MetricCleanUpInformativeSCRsEnableEpoch, uint64(enableEpochs.CleanUpInformativeSCRsEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricStorageAPICostOptimizationEnableEpoch, uint64(enableEpochs.StorageAPICostOptimizationEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricTransformToMultiShardCreateEnableEpoch, uint64(enableEpochs.TransformToMultiShardCreateEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricESDTRegisterAndSetAllRolesEnableEpoch, uint64(enableEpochs.ESDTRegisterAndSetAllRolesEnableEpoch)) diff --git a/node/metrics/metrics_test.go b/node/metrics/metrics_test.go index f10707c64f0..fdfbc3bb533 100644 --- a/node/metrics/metrics_test.go +++ b/node/metrics/metrics_test.go @@ -105,41 +105,109 @@ func TestInitConfigMetrics(t *testing.T) { cfg := config.EpochConfig{ EnableEpochs: config.EnableEpochs{ - SCDeployEnableEpoch: 1, - BuiltInFunctionsEnableEpoch: 2, - RelayedTransactionsEnableEpoch: 3, - PenalizedTooMuchGasEnableEpoch: 4, - SwitchJailWaitingEnableEpoch: 5, - SwitchHysteresisForMinNodesEnableEpoch: 6, - BelowSignedThresholdEnableEpoch: 7, - TransactionSignedWithTxHashEnableEpoch: 8, - MetaProtectionEnableEpoch: 9, - AheadOfTimeGasUsageEnableEpoch: 10, - GasPriceModifierEnableEpoch: 11, - RepairCallbackEnableEpoch: 12, - BlockGasAndFeesReCheckEnableEpoch: 13, - StakingV2EnableEpoch: 14, - StakeEnableEpoch: 15, - DoubleKeyProtectionEnableEpoch: 16, - ESDTEnableEpoch: 17, - GovernanceEnableEpoch: 18, - DelegationManagerEnableEpoch: 19, - DelegationSmartContractEnableEpoch: 20, - CorrectLastUnjailedEnableEpoch: 21, - BalanceWaitingListsEnableEpoch: 22, - ReturnDataToLastTransferEnableEpoch: 23, - SenderInOutTransferEnableEpoch: 24, - RelayedTransactionsV2EnableEpoch: 25, - UnbondTokensV2EnableEpoch: 26, - SaveJailedAlwaysEnableEpoch: 27, - ValidatorToDelegationEnableEpoch: 28, - ReDelegateBelowMinCheckEnableEpoch: 29, - IncrementSCRNonceInMultiTransferEnableEpoch: 30, - ESDTMultiTransferEnableEpoch: 31, - GlobalMintBurnDisableEpoch: 32, - ESDTTransferRoleEnableEpoch: 33, - SetGuardianEnableEpoch: 34, - ScToScLogEventEnableEpoch: 35, + SCDeployEnableEpoch: 1, + BuiltInFunctionsEnableEpoch: 2, + RelayedTransactionsEnableEpoch: 3, + PenalizedTooMuchGasEnableEpoch: 4, + SwitchJailWaitingEnableEpoch: 5, + SwitchHysteresisForMinNodesEnableEpoch: 6, + BelowSignedThresholdEnableEpoch: 7, + TransactionSignedWithTxHashEnableEpoch: 8, + MetaProtectionEnableEpoch: 9, + AheadOfTimeGasUsageEnableEpoch: 10, + GasPriceModifierEnableEpoch: 11, + RepairCallbackEnableEpoch: 12, + BlockGasAndFeesReCheckEnableEpoch: 13, + StakingV2EnableEpoch: 14, + StakeEnableEpoch: 15, + DoubleKeyProtectionEnableEpoch: 16, + ESDTEnableEpoch: 17, + GovernanceEnableEpoch: 18, + DelegationManagerEnableEpoch: 19, + DelegationSmartContractEnableEpoch: 20, + CorrectLastUnjailedEnableEpoch: 21, + BalanceWaitingListsEnableEpoch: 22, + ReturnDataToLastTransferEnableEpoch: 23, + SenderInOutTransferEnableEpoch: 24, + RelayedTransactionsV2EnableEpoch: 25, + UnbondTokensV2EnableEpoch: 26, + SaveJailedAlwaysEnableEpoch: 27, + ValidatorToDelegationEnableEpoch: 28, + ReDelegateBelowMinCheckEnableEpoch: 29, + IncrementSCRNonceInMultiTransferEnableEpoch: 30, + ScheduledMiniBlocksEnableEpoch: 31, + ESDTMultiTransferEnableEpoch: 32, + GlobalMintBurnDisableEpoch: 33, + ESDTTransferRoleEnableEpoch: 34, + ComputeRewardCheckpointEnableEpoch: 35, + SCRSizeInvariantCheckEnableEpoch: 36, + BackwardCompSaveKeyValueEnableEpoch: 37, + ESDTNFTCreateOnMultiShardEnableEpoch: 38, + MetaESDTSetEnableEpoch: 39, + AddTokensToDelegationEnableEpoch: 40, + MultiESDTTransferFixOnCallBackOnEnableEpoch: 41, + OptimizeGasUsedInCrossMiniBlocksEnableEpoch: 42, + CorrectFirstQueuedEpoch: 43, + CorrectJailedNotUnstakedEmptyQueueEpoch: 44, + FixOOGReturnCodeEnableEpoch: 45, + RemoveNonUpdatedStorageEnableEpoch: 46, + DeleteDelegatorAfterClaimRewardsEnableEpoch: 47, + OptimizeNFTStoreEnableEpoch: 48, + CreateNFTThroughExecByCallerEnableEpoch: 49, + StopDecreasingValidatorRatingWhenStuckEnableEpoch: 50, + FrontRunningProtectionEnableEpoch: 51, + IsPayableBySCEnableEpoch: 52, + CleanUpInformativeSCRsEnableEpoch: 53, + StorageAPICostOptimizationEnableEpoch: 54, + TransformToMultiShardCreateEnableEpoch: 55, + ESDTRegisterAndSetAllRolesEnableEpoch: 56, + DoNotReturnOldBlockInBlockchainHookEnableEpoch: 57, + AddFailedRelayedTxToInvalidMBsDisableEpoch: 58, + SCRSizeInvariantOnBuiltInResultEnableEpoch: 59, + CheckCorrectTokenIDForTransferRoleEnableEpoch: 60, + DisableExecByCallerEnableEpoch: 61, + FailExecutionOnEveryAPIErrorEnableEpoch: 62, + ManagedCryptoAPIsEnableEpoch: 63, + RefactorContextEnableEpoch: 64, + CheckFunctionArgumentEnableEpoch: 65, + CheckExecuteOnReadOnlyEnableEpoch: 66, + MiniBlockPartialExecutionEnableEpoch: 67, + ESDTMetadataContinuousCleanupEnableEpoch: 68, + FixAsyncCallBackArgsListEnableEpoch: 69, + FixOldTokenLiquidityEnableEpoch: 70, + RuntimeMemStoreLimitEnableEpoch: 71, + RuntimeCodeSizeFixEnableEpoch: 72, + SetSenderInEeiOutputTransferEnableEpoch: 73, + RefactorPeersMiniBlocksEnableEpoch: 74, + SCProcessorV2EnableEpoch: 75, + MaxBlockchainHookCountersEnableEpoch: 76, + WipeSingleNFTLiquidityDecreaseEnableEpoch: 77, + AlwaysSaveTokenMetaDataEnableEpoch: 78, + SetGuardianEnableEpoch: 79, + RelayedNonceFixEnableEpoch: 80, + DeterministicSortOnValidatorsInfoEnableEpoch: 81, + KeepExecOrderOnCreatedSCRsEnableEpoch: 82, + MultiClaimOnDelegationEnableEpoch: 83, + ChangeUsernameEnableEpoch: 84, + AutoBalanceDataTriesEnableEpoch: 85, + MigrateDataTrieEnableEpoch: 86, + ConsistentTokensValuesLengthCheckEnableEpoch: 87, + FixDelegationChangeOwnerOnAccountEnableEpoch: 88, + DynamicGasCostForDataTrieStorageLoadEnableEpoch: 89, + NFTStopCreateEnableEpoch: 90, + ChangeOwnerAddressCrossShardThroughSCEnableEpoch: 91, + FixGasRemainingForSaveKeyValueBuiltinFunctionEnableEpoch: 92, + CurrentRandomnessOnSortingEnableEpoch: 93, + StakeLimitsEnableEpoch: 94, + StakingV4Step1EnableEpoch: 95, + StakingV4Step2EnableEpoch: 96, + StakingV4Step3EnableEpoch: 97, + CleanupAuctionOnLowWaitingListEnableEpoch: 98, + AlwaysMergeContextsInEEIEnableEpoch: 99, + DynamicESDTEnableEpoch: 100, + EGLDInMultiTransferEnableEpoch: 101, + CryptoOpcodesV2EnableEpoch: 102, + ScToScLogEventEnableEpoch: 103, MaxNodesChangeEnableEpoch: []config.MaxNodesChangeConfig{ { EpochEnable: 0, @@ -155,49 +223,117 @@ func TestInitConfigMetrics(t *testing.T) { } expectedValues := map[string]interface{}{ - "erd_smart_contract_deploy_enable_epoch": uint32(1), - "erd_built_in_functions_enable_epoch": uint32(2), - "erd_relayed_transactions_enable_epoch": uint32(3), - "erd_penalized_too_much_gas_enable_epoch": uint32(4), - "erd_switch_jail_waiting_enable_epoch": uint32(5), - "erd_switch_hysteresis_for_min_nodes_enable_epoch": uint32(6), - "erd_below_signed_threshold_enable_epoch": uint32(7), - "erd_transaction_signed_with_txhash_enable_epoch": uint32(8), - "erd_meta_protection_enable_epoch": uint32(9), - "erd_ahead_of_time_gas_usage_enable_epoch": uint32(10), - "erd_gas_price_modifier_enable_epoch": uint32(11), - "erd_repair_callback_enable_epoch": uint32(12), - "erd_block_gas_and_fee_recheck_enable_epoch": uint32(13), - "erd_staking_v2_enable_epoch": uint32(14), - "erd_stake_enable_epoch": uint32(15), - "erd_double_key_protection_enable_epoch": uint32(16), - "erd_esdt_enable_epoch": uint32(17), - "erd_governance_enable_epoch": uint32(18), - "erd_delegation_manager_enable_epoch": uint32(19), - "erd_delegation_smart_contract_enable_epoch": uint32(20), - "erd_correct_last_unjailed_enable_epoch": uint32(21), - "erd_balance_waiting_lists_enable_epoch": uint32(22), - "erd_return_data_to_last_transfer_enable_epoch": uint32(23), - "erd_sender_in_out_transfer_enable_epoch": uint32(24), - "erd_relayed_transactions_v2_enable_epoch": uint32(25), - "erd_unbond_tokens_v2_enable_epoch": uint32(26), - "erd_save_jailed_always_enable_epoch": uint32(27), - "erd_validator_to_delegation_enable_epoch": uint32(28), - "erd_redelegate_below_min_check_enable_epoch": uint32(29), - "erd_increment_scr_nonce_in_multi_transfer_enable_epoch": uint32(30), - "erd_esdt_multi_transfer_enable_epoch": uint32(31), - "erd_global_mint_burn_disable_epoch": uint32(32), - "erd_esdt_transfer_role_enable_epoch": uint32(33), - "erd_max_nodes_change_enable_epoch": nil, - "erd_total_supply": "12345", - "erd_hysteresis": "0.100000", - "erd_adaptivity": "true", - "erd_max_nodes_change_enable_epoch0_epoch_enable": uint32(0), - "erd_max_nodes_change_enable_epoch0_max_num_nodes": uint32(1), - "erd_max_nodes_change_enable_epoch0_nodes_to_shuffle_per_shard": uint32(2), - "erd_set_guardian_feature_enable_epoch": uint32(34), - "erd_set_sc_to_sc_log_event_enable_epoch": uint32(35), - common.MetricGatewayMetricsEndpoint: "http://localhost:8080", + "erd_smart_contract_deploy_enable_epoch": uint32(1), + "erd_built_in_functions_enable_epoch": uint32(2), + "erd_relayed_transactions_enable_epoch": uint32(3), + "erd_penalized_too_much_gas_enable_epoch": uint32(4), + "erd_switch_jail_waiting_enable_epoch": uint32(5), + "erd_switch_hysteresis_for_min_nodes_enable_epoch": uint32(6), + "erd_below_signed_threshold_enable_epoch": uint32(7), + "erd_transaction_signed_with_txhash_enable_epoch": uint32(8), + "erd_meta_protection_enable_epoch": uint32(9), + "erd_ahead_of_time_gas_usage_enable_epoch": uint32(10), + "erd_gas_price_modifier_enable_epoch": uint32(11), + "erd_repair_callback_enable_epoch": uint32(12), + "erd_block_gas_and_fee_recheck_enable_epoch": uint32(13), + "erd_staking_v2_enable_epoch": uint32(14), + "erd_stake_enable_epoch": uint32(15), + "erd_double_key_protection_enable_epoch": uint32(16), + "erd_esdt_enable_epoch": uint32(17), + "erd_governance_enable_epoch": uint32(18), + "erd_delegation_manager_enable_epoch": uint32(19), + "erd_delegation_smart_contract_enable_epoch": uint32(20), + "erd_correct_last_unjailed_enable_epoch": uint32(21), + "erd_balance_waiting_lists_enable_epoch": uint32(22), + "erd_return_data_to_last_transfer_enable_epoch": uint32(23), + "erd_sender_in_out_transfer_enable_epoch": uint32(24), + "erd_relayed_transactions_v2_enable_epoch": uint32(25), + "erd_unbond_tokens_v2_enable_epoch": uint32(26), + "erd_save_jailed_always_enable_epoch": uint32(27), + "erd_validator_to_delegation_enable_epoch": uint32(28), + "erd_redelegate_below_min_check_enable_epoch": uint32(29), + "erd_increment_scr_nonce_in_multi_transfer_enable_epoch": uint32(30), + "erd_scheduled_miniblocks_enable_epoch": uint32(31), + "erd_esdt_multi_transfer_enable_epoch": uint32(32), + "erd_global_mint_burn_disable_epoch": uint32(33), + "erd_compute_reward_checkpoint_enable_epoch": uint32(35), + "erd_esdt_transfer_role_enable_epoch": uint32(34), + "erd_scr_size_invariant_check_enable_epoch": uint32(36), + "erd_backward_comp_save_keyvalue_enable_epoch": uint32(37), + "erd_esdt_nft_create_on_multi_shard_enable_epoch": uint32(38), + "erd_meta_esdt_set_enable_epoch": uint32(39), + "erd_add_tokens_to_delegation_enable_epoch": uint32(40), + "erd_multi_esdt_transfer_fix_on_callback_enable_epoch": uint32(41), + "erd_optimize_gas_used_in_cross_miniblocks_enable_epoch": uint32(42), + "erd_correct_first_queued_enable_epoch": uint32(43), + "erd_correct_jailed_not_unstaked_empty_queue_enable_epoch": uint32(44), + "erd_fix_oog_return_code_enable_epoch": uint32(45), + "erd_remove_non_updated_storage_enable_epoch": uint32(46), + "erd_delete_delegator_after_claim_rewards_enable_epoch": uint32(47), + "erd_optimize_nft_store_enable_epoch": uint32(48), + "erd_create_nft_through_exec_by_caller_enable_epoch": uint32(49), + "erd_stop_decreasing_validator_rating_when_stuck_enable_epoch": uint32(50), + "erd_front_running_protection_enable_epoch": uint32(51), + "erd_is_payable_by_sc_enable_epoch": uint32(52), + "erd_cleanup_informative_scrs_enable_epoch": uint32(53), + "erd_storage_api_cost_optimization_enable_epoch": uint32(54), + "erd_transform_to_multi_shard_create_enable_epoch": uint32(55), + "erd_esdt_register_and_set_all_roles_enable_epoch": uint32(56), + "erd_do_not_returns_old_block_in_blockchain_hook_enable_epoch": uint32(57), + "erd_add_failed_relayed_tx_to_invalid_mbs_enable_epoch": uint32(58), + "erd_scr_size_invariant_on_builtin_result_enable_epoch": uint32(59), + "erd_check_correct_tokenid_for_transfer_role_enable_epoch": uint32(60), + "erd_disable_exec_by_caller_enable_epoch": uint32(61), + "erd_fail_execution_on_every_api_error_enable_epoch": uint32(62), + "erd_managed_crypto_apis_enable_epoch": uint32(63), + "erd_refactor_context_enable_epoch": uint32(64), + "erd_check_function_argument_enable_epoch": uint32(65), + "erd_check_execute_on_readonly_enable_epoch": uint32(66), + "erd_miniblock_partial_execution_enable_epoch": uint32(67), + "erd_esdt_metadata_continuous_cleanup_enable_epoch": uint32(68), + "erd_fix_async_callback_args_list_enable_epoch": uint32(69), + "erd_fix_old_token_liquidity_enable_epoch": uint32(70), + "erd_runtime_mem_store_limit_enable_epoch": uint32(71), + "erd_runtime_code_size_fix_enable_epoch": uint32(72), + "erd_set_sender_in_eei_output_transfer_enable_epoch": uint32(73), + "erd_refactor_peers_miniblocks_enable_epoch": uint32(74), + "erd_sc_processorv2_enable_epoch": uint32(75), + "erd_max_blockchain_hook_counters_enable_epoch": uint32(76), + "erd_wipe_single_nft_liquidity_decrease_enable_epoch": uint32(77), + "erd_always_save_token_metadata_enable_epoch": uint32(78), + "erd_set_guardian_feature_enable_epoch": uint32(79), + "erd_relayed_nonce_fix_enable_epoch": uint32(80), + "erd_deterministic_sort_on_validators_info_enable_epoch": uint32(81), + "erd_keep_exec_order_on_created_scrs_enable_epoch": uint32(82), + "erd_multi_claim_on_delegation_enable_epoch": uint32(83), + "erd_change_username_enable_epoch": uint32(84), + "erd_auto_balance_data_tries_enable_epoch": uint32(85), + "erd_migrate_datatrie_enable_epoch": uint32(86), + "erd_consistent_tokens_values_length_check_enable_epoch": uint32(87), + "erd_fix_delegation_change_owner_on_account_enable_epoch": uint32(88), + "erd_dynamic_gas_cost_for_datatrie_storage_load_enable_epoch": uint32(89), + "erd_nft_stop_create_enable_epoch": uint32(90), + "erd_change_owner_address_cross_shard_through_sc_enable_epoch": uint32(91), + "erd_fix_gas_remainig_for_save_keyvalue_builtin_function_enable_epoch": uint32(92), + "erd_current_randomness_on_sorting_enable_epoch": uint32(93), + "erd_stake_limits_enable_epoch": uint32(94), + "erd_staking_v4_step1_enable_epoch": uint32(95), + "erd_staking_v4_step2_enable_epoch": uint32(96), + "erd_staking_v4_step3_enable_epoch": uint32(97), + "erd_cleanup_auction_on_low_waiting_list_enable_epoch": uint32(98), + "erd_always_merge_contexts_in_eei_enable_epoch": uint32(99), + "erd_dynamic_esdt_enable_epoch": uint32(100), + "erd_egld_in_multi_transfer_enable_epoch": uint32(101), + "erd_crypto_opcodes_v2_enable_epoch": uint32(102), + "erd_set_sc_to_sc_log_event_enable_epoch": uint32(103), + "erd_max_nodes_change_enable_epoch": nil, + "erd_total_supply": "12345", + "erd_hysteresis": "0.100000", + "erd_adaptivity": "true", + "erd_max_nodes_change_enable_epoch0_epoch_enable": uint32(0), + "erd_max_nodes_change_enable_epoch0_max_num_nodes": uint32(1), + "erd_max_nodes_change_enable_epoch0_nodes_to_shuffle_per_shard": uint32(2), + common.MetricGatewayMetricsEndpoint: "http://localhost:8080", } economicsConfig := config.EconomicsConfig{ diff --git a/statusHandler/statusMetricsProvider_test.go b/statusHandler/statusMetricsProvider_test.go index 3d3ff6a06e7..2eecf8cd598 100644 --- a/statusHandler/statusMetricsProvider_test.go +++ b/statusHandler/statusMetricsProvider_test.go @@ -297,42 +297,109 @@ func TestStatusMetrics_EnableEpochMetrics(t *testing.T) { sm := statusHandler.NewStatusMetrics() - sm.SetUInt64Value(common.MetricScDeployEnableEpoch, 4) - sm.SetUInt64Value(common.MetricBuiltInFunctionsEnableEpoch, 2) - sm.SetUInt64Value(common.MetricRelayedTransactionsEnableEpoch, 4) - sm.SetUInt64Value(common.MetricPenalizedTooMuchGasEnableEpoch, 2) - sm.SetUInt64Value(common.MetricSwitchJailWaitingEnableEpoch, 2) - sm.SetUInt64Value(common.MetricSwitchHysteresisForMinNodesEnableEpoch, 4) - sm.SetUInt64Value(common.MetricBelowSignedThresholdEnableEpoch, 2) - sm.SetUInt64Value(common.MetricTransactionSignedWithTxHashEnableEpoch, 4) - sm.SetUInt64Value(common.MetricMetaProtectionEnableEpoch, 6) - sm.SetUInt64Value(common.MetricAheadOfTimeGasUsageEnableEpoch, 2) - sm.SetUInt64Value(common.MetricGasPriceModifierEnableEpoch, 2) - sm.SetUInt64Value(common.MetricRepairCallbackEnableEpoch, 2) - sm.SetUInt64Value(common.MetricBlockGasAndFreeRecheckEnableEpoch, 2) - sm.SetUInt64Value(common.MetricStakingV2EnableEpoch, 2) - sm.SetUInt64Value(common.MetricStakeEnableEpoch, 2) - sm.SetUInt64Value(common.MetricDoubleKeyProtectionEnableEpoch, 2) - sm.SetUInt64Value(common.MetricEsdtEnableEpoch, 4) - sm.SetUInt64Value(common.MetricGovernanceEnableEpoch, 3) - sm.SetUInt64Value(common.MetricDelegationManagerEnableEpoch, 1) - sm.SetUInt64Value(common.MetricDelegationSmartContractEnableEpoch, 2) - sm.SetUInt64Value(common.MetricIncrementSCRNonceInMultiTransferEnableEpoch, 3) - sm.SetUInt64Value(common.MetricBalanceWaitingListsEnableEpoch, 4) - sm.SetUInt64Value(common.MetricSetGuardianEnableEpoch, 3) - sm.SetUInt64Value(common.MetricCorrectLastUnjailedEnableEpoch, 4) - sm.SetUInt64Value(common.MetricReturnDataToLastTransferEnableEpoch, 4) - sm.SetUInt64Value(common.MetricSenderInOutTransferEnableEpoch, 4) - sm.SetUInt64Value(common.MetricRelayedTransactionsV2EnableEpoch, 4) - sm.SetUInt64Value(common.MetricUnbondTokensV2EnableEpoch, 4) - sm.SetUInt64Value(common.MetricSaveJailedAlwaysEnableEpoch, 4) - sm.SetUInt64Value(common.MetricValidatorToDelegationEnableEpoch, 4) - sm.SetUInt64Value(common.MetricReDelegateBelowMinCheckEnableEpoch, 4) - sm.SetUInt64Value(common.MetricESDTMultiTransferEnableEpoch, 4) - sm.SetUInt64Value(common.MetricGlobalMintBurnDisableEpoch, 4) - sm.SetUInt64Value(common.MetricESDTTransferRoleEnableEpoch, 4) - sm.SetUInt64Value(common.MetricSetGuardianEnableEpoch, 3) - sm.SetUInt64Value(common.MetricSetScToScLogEventEnableEpoch, 4) + sm.SetUInt64Value(common.MetricScDeployEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricBuiltInFunctionsEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricRelayedTransactionsEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricPenalizedTooMuchGasEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricSwitchJailWaitingEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricSwitchHysteresisForMinNodesEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricBelowSignedThresholdEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricTransactionSignedWithTxHashEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricMetaProtectionEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricAheadOfTimeGasUsageEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricGasPriceModifierEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricRepairCallbackEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricBlockGasAndFreeRecheckEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricStakingV2EnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricStakeEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricDoubleKeyProtectionEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricEsdtEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricGovernanceEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricDelegationManagerEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricDelegationSmartContractEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricCorrectLastUnjailedEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricBalanceWaitingListsEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricReturnDataToLastTransferEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricSenderInOutTransferEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricRelayedTransactionsV2EnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricUnbondTokensV2EnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricSaveJailedAlwaysEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricValidatorToDelegationEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricReDelegateBelowMinCheckEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricIncrementSCRNonceInMultiTransferEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricScheduledMiniBlocksEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricESDTMultiTransferEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricGlobalMintBurnDisableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricESDTTransferRoleEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricComputeRewardCheckpointEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricSCRSizeInvariantCheckEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricBackwardCompSaveKeyValueEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricESDTNFTCreateOnMultiShardEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricMetaESDTSetEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricAddTokensToDelegationEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricMultiESDTTransferFixOnCallBackOnEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricOptimizeGasUsedInCrossMiniBlocksEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricCorrectFirstQueuedEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricCorrectJailedNotUnstakedEmptyQueueEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricFixOOGReturnCodeEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricRemoveNonUpdatedStorageEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricDeleteDelegatorAfterClaimRewardsEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricOptimizeNFTStoreEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricCreateNFTThroughExecByCallerEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricStopDecreasingValidatorRatingWhenStuckEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricFrontRunningProtectionEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricIsPayableBySCEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricStorageAPICostOptimizationEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricTransformToMultiShardCreateEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricESDTRegisterAndSetAllRolesEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricDoNotReturnOldBlockInBlockchainHookEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricAddFailedRelayedTxToInvalidMBsDisableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricSCRSizeInvariantOnBuiltInResultEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricCheckCorrectTokenIDForTransferRoleEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricDisableExecByCallerEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricFailExecutionOnEveryAPIErrorEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricManagedCryptoAPIsEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricRefactorContextEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricCheckFunctionArgumentEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricCheckExecuteOnReadOnlyEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricMiniBlockPartialExecutionEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricESDTMetadataContinuousCleanupEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricFixAsyncCallBackArgsListEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricFixOldTokenLiquidityEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricRuntimeMemStoreLimitEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricRuntimeCodeSizeFixEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricSetSenderInEeiOutputTransferEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricRefactorPeersMiniBlocksEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricSCProcessorV2EnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricMaxBlockchainHookCountersEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricWipeSingleNFTLiquidityDecreaseEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricAlwaysSaveTokenMetaDataEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricCleanUpInformativeSCRsEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricSetGuardianEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricSetScToScLogEventEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricRelayedNonceFixEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricDeterministicSortOnValidatorsInfoEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricKeepExecOrderOnCreatedSCRsEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricMultiClaimOnDelegationEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricChangeUsernameEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricAutoBalanceDataTriesEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricMigrateDataTrieEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricConsistentTokensValuesLengthCheckEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricFixDelegationChangeOwnerOnAccountEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricDynamicGasCostForDataTrieStorageLoadEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricNFTStopCreateEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricChangeOwnerAddressCrossShardThroughSCEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricFixGasRemainingForSaveKeyValueBuiltinFunctionEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricCurrentRandomnessOnSortingEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricStakeLimitsEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricStakingV4Step1EnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricStakingV4Step2EnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricStakingV4Step3EnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricCleanupAuctionOnLowWaitingListEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricAlwaysMergeContextsInEEIEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricDynamicESDTEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricEGLDInMultiTransferEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricCryptoOpcodesV2EnableEpoch, uint64(4)) maxNodesChangeConfig := []map[string]uint64{ { @@ -359,41 +426,109 @@ func TestStatusMetrics_EnableEpochMetrics(t *testing.T) { sm.SetUInt64Value(common.MetricMaxNodesChangeEnableEpoch+"_count", uint64(len(maxNodesChangeConfig))) expectedMetrics := map[string]interface{}{ - common.MetricScDeployEnableEpoch: uint64(4), - common.MetricBuiltInFunctionsEnableEpoch: uint64(2), - common.MetricRelayedTransactionsEnableEpoch: uint64(4), - common.MetricPenalizedTooMuchGasEnableEpoch: uint64(2), - common.MetricSwitchJailWaitingEnableEpoch: uint64(2), - common.MetricSwitchHysteresisForMinNodesEnableEpoch: uint64(4), - common.MetricBelowSignedThresholdEnableEpoch: uint64(2), - common.MetricTransactionSignedWithTxHashEnableEpoch: uint64(4), - common.MetricMetaProtectionEnableEpoch: uint64(6), - common.MetricAheadOfTimeGasUsageEnableEpoch: uint64(2), - common.MetricGasPriceModifierEnableEpoch: uint64(2), - common.MetricRepairCallbackEnableEpoch: uint64(2), - common.MetricBlockGasAndFreeRecheckEnableEpoch: uint64(2), - common.MetricStakingV2EnableEpoch: uint64(2), - common.MetricStakeEnableEpoch: uint64(2), - common.MetricDoubleKeyProtectionEnableEpoch: uint64(2), - common.MetricEsdtEnableEpoch: uint64(4), - common.MetricGovernanceEnableEpoch: uint64(3), - common.MetricDelegationManagerEnableEpoch: uint64(1), - common.MetricDelegationSmartContractEnableEpoch: uint64(2), - common.MetricIncrementSCRNonceInMultiTransferEnableEpoch: uint64(3), - common.MetricBalanceWaitingListsEnableEpoch: uint64(4), - common.MetricCorrectLastUnjailedEnableEpoch: uint64(4), - common.MetricReturnDataToLastTransferEnableEpoch: uint64(4), - common.MetricSenderInOutTransferEnableEpoch: uint64(4), - common.MetricRelayedTransactionsV2EnableEpoch: uint64(4), - common.MetricUnbondTokensV2EnableEpoch: uint64(4), - common.MetricSaveJailedAlwaysEnableEpoch: uint64(4), - common.MetricValidatorToDelegationEnableEpoch: uint64(4), - common.MetricReDelegateBelowMinCheckEnableEpoch: uint64(4), - common.MetricESDTMultiTransferEnableEpoch: uint64(4), - common.MetricGlobalMintBurnDisableEpoch: uint64(4), - common.MetricESDTTransferRoleEnableEpoch: uint64(4), - common.MetricSetGuardianEnableEpoch: uint64(3), - common.MetricSetScToScLogEventEnableEpoch: uint64(4), + common.MetricScDeployEnableEpoch: uint64(4), + common.MetricBuiltInFunctionsEnableEpoch: uint64(4), + common.MetricRelayedTransactionsEnableEpoch: uint64(4), + common.MetricPenalizedTooMuchGasEnableEpoch: uint64(4), + common.MetricSwitchJailWaitingEnableEpoch: uint64(4), + common.MetricSwitchHysteresisForMinNodesEnableEpoch: uint64(4), + common.MetricBelowSignedThresholdEnableEpoch: uint64(4), + common.MetricTransactionSignedWithTxHashEnableEpoch: uint64(4), + common.MetricMetaProtectionEnableEpoch: uint64(4), + common.MetricAheadOfTimeGasUsageEnableEpoch: uint64(4), + common.MetricGasPriceModifierEnableEpoch: uint64(4), + common.MetricRepairCallbackEnableEpoch: uint64(4), + common.MetricBlockGasAndFreeRecheckEnableEpoch: uint64(4), + common.MetricStakingV2EnableEpoch: uint64(4), + common.MetricStakeEnableEpoch: uint64(4), + common.MetricDoubleKeyProtectionEnableEpoch: uint64(4), + common.MetricEsdtEnableEpoch: uint64(4), + common.MetricGovernanceEnableEpoch: uint64(4), + common.MetricDelegationManagerEnableEpoch: uint64(4), + common.MetricDelegationSmartContractEnableEpoch: uint64(4), + common.MetricCorrectLastUnjailedEnableEpoch: uint64(4), + common.MetricBalanceWaitingListsEnableEpoch: uint64(4), + common.MetricReturnDataToLastTransferEnableEpoch: uint64(4), + common.MetricSenderInOutTransferEnableEpoch: uint64(4), + common.MetricRelayedTransactionsV2EnableEpoch: uint64(4), + common.MetricUnbondTokensV2EnableEpoch: uint64(4), + common.MetricSaveJailedAlwaysEnableEpoch: uint64(4), + common.MetricValidatorToDelegationEnableEpoch: uint64(4), + common.MetricReDelegateBelowMinCheckEnableEpoch: uint64(4), + common.MetricIncrementSCRNonceInMultiTransferEnableEpoch: uint64(4), + common.MetricScheduledMiniBlocksEnableEpoch: uint64(4), + common.MetricESDTMultiTransferEnableEpoch: uint64(4), + common.MetricGlobalMintBurnDisableEpoch: uint64(4), + common.MetricESDTTransferRoleEnableEpoch: uint64(4), + common.MetricComputeRewardCheckpointEnableEpoch: uint64(4), + common.MetricSCRSizeInvariantCheckEnableEpoch: uint64(4), + common.MetricBackwardCompSaveKeyValueEnableEpoch: uint64(4), + common.MetricESDTNFTCreateOnMultiShardEnableEpoch: uint64(4), + common.MetricMetaESDTSetEnableEpoch: uint64(4), + common.MetricAddTokensToDelegationEnableEpoch: uint64(4), + common.MetricMultiESDTTransferFixOnCallBackOnEnableEpoch: uint64(4), + common.MetricOptimizeGasUsedInCrossMiniBlocksEnableEpoch: uint64(4), + common.MetricCorrectFirstQueuedEpoch: uint64(4), + common.MetricCorrectJailedNotUnstakedEmptyQueueEpoch: uint64(4), + common.MetricFixOOGReturnCodeEnableEpoch: uint64(4), + common.MetricRemoveNonUpdatedStorageEnableEpoch: uint64(4), + common.MetricDeleteDelegatorAfterClaimRewardsEnableEpoch: uint64(4), + common.MetricOptimizeNFTStoreEnableEpoch: uint64(4), + common.MetricCreateNFTThroughExecByCallerEnableEpoch: uint64(4), + common.MetricStopDecreasingValidatorRatingWhenStuckEnableEpoch: uint64(4), + common.MetricFrontRunningProtectionEnableEpoch: uint64(4), + common.MetricIsPayableBySCEnableEpoch: uint64(4), + common.MetricStorageAPICostOptimizationEnableEpoch: uint64(4), + common.MetricTransformToMultiShardCreateEnableEpoch: uint64(4), + common.MetricESDTRegisterAndSetAllRolesEnableEpoch: uint64(4), + common.MetricDoNotReturnOldBlockInBlockchainHookEnableEpoch: uint64(4), + common.MetricAddFailedRelayedTxToInvalidMBsDisableEpoch: uint64(4), + common.MetricSCRSizeInvariantOnBuiltInResultEnableEpoch: uint64(4), + common.MetricCheckCorrectTokenIDForTransferRoleEnableEpoch: uint64(4), + common.MetricDisableExecByCallerEnableEpoch: uint64(4), + common.MetricFailExecutionOnEveryAPIErrorEnableEpoch: uint64(4), + common.MetricManagedCryptoAPIsEnableEpoch: uint64(4), + common.MetricRefactorContextEnableEpoch: uint64(4), + common.MetricCheckFunctionArgumentEnableEpoch: uint64(4), + common.MetricCheckExecuteOnReadOnlyEnableEpoch: uint64(4), + common.MetricMiniBlockPartialExecutionEnableEpoch: uint64(4), + common.MetricESDTMetadataContinuousCleanupEnableEpoch: uint64(4), + common.MetricFixAsyncCallBackArgsListEnableEpoch: uint64(4), + common.MetricFixOldTokenLiquidityEnableEpoch: uint64(4), + common.MetricRuntimeMemStoreLimitEnableEpoch: uint64(4), + common.MetricRuntimeCodeSizeFixEnableEpoch: uint64(4), + common.MetricSetSenderInEeiOutputTransferEnableEpoch: uint64(4), + common.MetricRefactorPeersMiniBlocksEnableEpoch: uint64(4), + common.MetricSCProcessorV2EnableEpoch: uint64(4), + common.MetricMaxBlockchainHookCountersEnableEpoch: uint64(4), + common.MetricWipeSingleNFTLiquidityDecreaseEnableEpoch: uint64(4), + common.MetricAlwaysSaveTokenMetaDataEnableEpoch: uint64(4), + common.MetricCleanUpInformativeSCRsEnableEpoch: uint64(4), + common.MetricSetGuardianEnableEpoch: uint64(4), + common.MetricSetScToScLogEventEnableEpoch: uint64(4), + common.MetricRelayedNonceFixEnableEpoch: uint64(4), + common.MetricDeterministicSortOnValidatorsInfoEnableEpoch: uint64(4), + common.MetricKeepExecOrderOnCreatedSCRsEnableEpoch: uint64(4), + common.MetricMultiClaimOnDelegationEnableEpoch: uint64(4), + common.MetricChangeUsernameEnableEpoch: uint64(4), + common.MetricAutoBalanceDataTriesEnableEpoch: uint64(4), + common.MetricMigrateDataTrieEnableEpoch: uint64(4), + common.MetricConsistentTokensValuesLengthCheckEnableEpoch: uint64(4), + common.MetricFixDelegationChangeOwnerOnAccountEnableEpoch: uint64(4), + common.MetricDynamicGasCostForDataTrieStorageLoadEnableEpoch: uint64(4), + common.MetricNFTStopCreateEnableEpoch: uint64(4), + common.MetricChangeOwnerAddressCrossShardThroughSCEnableEpoch: uint64(4), + common.MetricFixGasRemainingForSaveKeyValueBuiltinFunctionEnableEpoch: uint64(4), + common.MetricCurrentRandomnessOnSortingEnableEpoch: uint64(4), + common.MetricStakeLimitsEnableEpoch: uint64(4), + common.MetricStakingV4Step1EnableEpoch: uint64(4), + common.MetricStakingV4Step2EnableEpoch: uint64(4), + common.MetricStakingV4Step3EnableEpoch: uint64(4), + common.MetricCleanupAuctionOnLowWaitingListEnableEpoch: uint64(4), + common.MetricAlwaysMergeContextsInEEIEnableEpoch: uint64(4), + common.MetricDynamicESDTEnableEpoch: uint64(4), + common.MetricEGLDInMultiTransferEnableEpoch: uint64(4), + common.MetricCryptoOpcodesV2EnableEpoch: uint64(4), common.MetricMaxNodesChangeEnableEpoch: []map[string]interface{}{ { From ff786ca3d668ff4da8e05690317260664d1639c6 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Fri, 31 May 2024 14:10:31 +0300 Subject: [PATCH 288/503] remove staking common imports --- .../vm/esdtImprovements_test.go | 74 ++++++++++--------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 7783b281974..0af3401a068 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -14,7 +14,6 @@ import ( dataVm "github.com/multiversx/mx-chain-core-go/data/vm" "github.com/multiversx/mx-chain-go/config" testsChainSimulator "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" - "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee" "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" "github.com/multiversx/mx-chain-go/node/chainSimulator" @@ -31,9 +30,12 @@ import ( const ( defaultPathToInitialConfig = "../../../cmd/node/config/" - minGasPrice = 1000000000 + minGasPrice = 1000000000 + maxNumOfBlockToGenerateWhenExecutingTx = 7 ) +var oneEGLD = big.NewInt(1000000000000000000) + var log = logger.GetOrCreate("integrationTests/chainSimulator/vm") // Test scenario #1 @@ -114,7 +116,7 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool) { metaESDTTicker := []byte("METATTICKER") tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -133,7 +135,7 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool) { fungibleTicker := []byte("FUNGIBLETICKER") tx = issueTx(1, addrs[0].Bytes, fungibleTicker, baseIssuingCost) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -147,7 +149,7 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool) { nftTicker := []byte("NFTTICKER") tx = issueNonFungibleTx(2, addrs[0].Bytes, nftTicker, baseIssuingCost) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -161,7 +163,7 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool) { sftTicker := []byte("SFTTICKER") tx = issueSemiFungibleTx(3, addrs[0].Bytes, sftTicker, baseIssuingCost) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -201,7 +203,7 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool) { for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -230,7 +232,7 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool) { log.Info("transfering token id", "tokenID", tokenID) tx = esdtNFTTransferTx(nonce, addrs[0].Bytes, addrs[1].Bytes, tokenID) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -252,7 +254,7 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool) { log.Info("updating token id", "tokenID", tokenID) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -274,7 +276,7 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool) { log.Info("transfering token id", "tokenID", tokenID) tx = esdtNFTTransferTx(nonce, addrs[1].Bytes, addrs[2].Bytes, tokenID) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -306,7 +308,7 @@ func createAddresses( } mintValue := big.NewInt(10) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(oneEGLD, mintValue) address, err := cs.GenerateAndMintWalletAddress(shardIDs[0], mintValue) require.Nil(t, err) @@ -651,7 +653,7 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { metaESDTTicker := []byte("METATTICKER") tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -670,7 +672,7 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { fungibleTicker := []byte("FUNGIBLETICKER") tx = issueTx(1, addrs[0].Bytes, fungibleTicker, baseIssuingCost) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -684,7 +686,7 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { nftTicker := []byte("NFTTICKER") tx = issueNonFungibleTx(2, addrs[0].Bytes, nftTicker, baseIssuingCost) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -698,7 +700,7 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { sftTicker := []byte("SFTTICKER") tx = issueSemiFungibleTx(3, addrs[0].Bytes, sftTicker, baseIssuingCost) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -738,7 +740,7 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -809,7 +811,7 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { defer cs.Close() mintValue := big.NewInt(10) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(oneEGLD, mintValue) address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) @@ -825,7 +827,7 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { nftTicker := []byte("NFTTICKER") tx := issueNonFungibleTx(0, address.Bytes, nftTicker, baseIssuingCost) - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -845,7 +847,7 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { tx = nftCreateTx(1, address.Bytes, nftTokenID, nftMetaData) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -889,7 +891,7 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { Version: 1, } - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) @@ -947,7 +949,7 @@ func TestChainSimulator_NFT_ESDTMetaDataUpdate(t *testing.T) { defer cs.Close() mintValue := big.NewInt(10) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(oneEGLD, mintValue) address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) @@ -963,7 +965,7 @@ func TestChainSimulator_NFT_ESDTMetaDataUpdate(t *testing.T) { nftTicker := []byte("NFTTICKER") tx := issueNonFungibleTx(0, address.Bytes, nftTicker, baseIssuingCost) - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -983,7 +985,7 @@ func TestChainSimulator_NFT_ESDTMetaDataUpdate(t *testing.T) { tx = nftCreateTx(1, address.Bytes, nftTokenID, nftMetaData) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -1024,7 +1026,7 @@ func TestChainSimulator_NFT_ESDTMetaDataUpdate(t *testing.T) { Version: 1, } - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) @@ -1082,7 +1084,7 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { defer cs.Close() mintValue := big.NewInt(10) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(oneEGLD, mintValue) address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) @@ -1098,7 +1100,7 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { nftTicker := []byte("NFTTICKER") tx := issueNonFungibleTx(0, address.Bytes, nftTicker, baseIssuingCost) - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -1118,7 +1120,7 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { tx = nftCreateTx(1, address.Bytes, nftTokenID, nftMetaData) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -1158,7 +1160,7 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { Version: 1, } - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) @@ -1224,7 +1226,7 @@ func TestChainSimulator_NFT_ESDTSetNewURIs(t *testing.T) { defer cs.Close() mintValue := big.NewInt(10) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(oneEGLD, mintValue) address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) @@ -1240,7 +1242,7 @@ func TestChainSimulator_NFT_ESDTSetNewURIs(t *testing.T) { nftTicker := []byte("NFTTICKER") tx := issueNonFungibleTx(0, address.Bytes, nftTicker, baseIssuingCost) - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -1260,7 +1262,7 @@ func TestChainSimulator_NFT_ESDTSetNewURIs(t *testing.T) { tx = nftCreateTx(1, address.Bytes, nftTokenID, nftMetaData) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -1310,7 +1312,7 @@ func TestChainSimulator_NFT_ESDTSetNewURIs(t *testing.T) { Version: 1, } - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) @@ -1371,7 +1373,7 @@ func TestChainSimulator_NFT_ESDTModifyRoyalties(t *testing.T) { defer cs.Close() mintValue := big.NewInt(10) - mintValue = mintValue.Mul(staking.OneEGLD, mintValue) + mintValue = mintValue.Mul(oneEGLD, mintValue) address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) @@ -1387,7 +1389,7 @@ func TestChainSimulator_NFT_ESDTModifyRoyalties(t *testing.T) { nftTicker := []byte("NFTTICKER") tx := issueNonFungibleTx(0, address.Bytes, nftTicker, baseIssuingCost) - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -1407,7 +1409,7 @@ func TestChainSimulator_NFT_ESDTModifyRoyalties(t *testing.T) { tx = nftCreateTx(1, address.Bytes, nftTokenID, nftMetaData) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -1445,7 +1447,7 @@ func TestChainSimulator_NFT_ESDTModifyRoyalties(t *testing.T) { Version: 1, } - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) From f96c649b8bf107916152ed7e91037a3e752bfd66 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Fri, 31 May 2024 14:35:20 +0300 Subject: [PATCH 289/503] remove unused function --- .../chainSimulator/vm/esdtImprovements_test.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 0af3401a068..37b86515827 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -11,7 +11,6 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/esdt" "github.com/multiversx/mx-chain-core-go/data/transaction" - dataVm "github.com/multiversx/mx-chain-core-go/data/vm" "github.com/multiversx/mx-chain-go/config" testsChainSimulator "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee" @@ -20,7 +19,6 @@ import ( "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" - "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/vm" logger "github.com/multiversx/mx-chain-logger-go" @@ -522,15 +520,6 @@ func nftCreateTx( } } -func executeQuery(cs testsChainSimulator.ChainSimulator, shardID uint32, scAddress []byte, funcName string, args [][]byte) (*dataVm.VMOutputApi, error) { - output, _, err := cs.GetNodeHandler(shardID).GetFacadeHandler().ExecuteSCQuery(&process.SCQuery{ - ScAddress: scAddress, - FuncName: funcName, - Arguments: args, - }) - return output, err -} - func getMetaDataFromAcc( t *testing.T, cs testsChainSimulator.ChainSimulator, From 261c6ffb1e1e588f4db7eae58cc59db6dbd42c39 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 31 May 2024 17:45:19 +0300 Subject: [PATCH 290/503] fix TestRelayedTransactionV2InMultiShardEnvironmentWithSmartContractTX --- .../multiShard/relayedTx/relayedTxV2_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/integrationTests/multiShard/relayedTx/relayedTxV2_test.go b/integrationTests/multiShard/relayedTx/relayedTxV2_test.go index aa35951c3ea..2795646c359 100644 --- a/integrationTests/multiShard/relayedTx/relayedTxV2_test.go +++ b/integrationTests/multiShard/relayedTx/relayedTxV2_test.go @@ -66,7 +66,12 @@ func TestRelayedTransactionV2InMultiShardEnvironmentWithSmartContractTX(t *testi integrationTests.MinTransactionVersion, ) } - time.Sleep(time.Second) + + roundToPropagateMultiShard := int64(20) + for i := int64(0); i <= roundToPropagateMultiShard; i++ { + round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) + integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) + } nrRoundsToTest := int64(5) for i := int64(0); i < nrRoundsToTest; i++ { @@ -82,9 +87,7 @@ func TestRelayedTransactionV2InMultiShardEnvironmentWithSmartContractTX(t *testi time.Sleep(integrationTests.StepDelay) } - time.Sleep(time.Second) - roundToPropagateMultiShard := int64(25) for i := int64(0); i <= roundToPropagateMultiShard; i++ { round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) integrationTests.AddSelfNotarizedHeaderByMetachain(nodes) From 9ad3c234ad89f0792ffe679b92afe4ce6d946dce Mon Sep 17 00:00:00 2001 From: ssd04 Date: Sat, 1 Jun 2024 16:44:13 +0300 Subject: [PATCH 291/503] fixes after review - added checks for meta data not in account --- .../vm/esdtImprovements_test.go | 64 +++++++++++++++---- 1 file changed, 51 insertions(+), 13 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 37b86515827..ad5f7c713d8 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -60,7 +60,7 @@ func TestChainSimulator_CheckTokensMetadata_TransferTokens(t *testing.T) { transferAndCheckTokensMetaData(t, false) }) - t.Run("transfer and check all tokens - intra shard", func(t *testing.T) { + t.Run("transfer and check all tokens - cross shard", func(t *testing.T) { transferAndCheckTokensMetaData(t, true) }) } @@ -130,7 +130,7 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool) { log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) // issue fungible - fungibleTicker := []byte("FUNGIBLETICKER") + fungibleTicker := []byte("FUNTICKER") tx = issueTx(1, addrs[0].Bytes, fungibleTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -187,14 +187,14 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool) { nftTokenID, sftTokenID, metaESDTTokenID, - // fungibleTokenID, + fungibleTokenID, } tokensMetadata := []*txsFee.MetaData{ nftMetaData, sftMetaData, esdtMetaData, - // fungibleMetaData, + fungibleMetaData, } nonce := uint64(4) @@ -215,7 +215,7 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool) { log.Info("Step 1. check that the metadata for all tokens is saved on the system account") checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, nftMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, sftMetaData) checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, esdtMetaData) checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, fungibleMetaData) @@ -285,12 +285,18 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool) { log.Info("Step 8. check that the metaData for the NFT was removed from the system account and moved to the user account") checkMetaData(t, cs, addrs[2].Bytes, nftTokenID, nftMetaData) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID) log.Info("Step 9. check that the metaData for the rest of the tokens is still present on the system account and not on the userAccount") - checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, sftMetaData) + checkMetaDataNotInAcc(t, cs, addrs[2].Bytes, sftTokenID) + checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, esdtMetaData) + checkMetaDataNotInAcc(t, cs, addrs[2].Bytes, metaESDTTokenID) + checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, fungibleMetaData) + checkMetaDataNotInAcc(t, cs, addrs[2].Bytes, fungibleTokenID) } func createAddresses( @@ -341,6 +347,19 @@ func checkMetaData( require.Equal(t, expectedMetaData.Attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) } +func checkMetaDataNotInAcc( + t *testing.T, + cs testsChainSimulator.ChainSimulator, + addressBytes []byte, + token []byte, +) { + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addressBytes) + + esdtData := getESDTDataFromAcc(t, cs, addressBytes, token, shardID) + + require.Nil(t, esdtData.TokenMetaData) +} + func esdtNFTTransferTx(nonce uint64, sndAdr, rcvAddr, token []byte) *transaction.Transaction { tx := utils.CreateESDTNFTTransferTx( nonce, @@ -520,13 +539,13 @@ func nftCreateTx( } } -func getMetaDataFromAcc( +func getESDTDataFromAcc( t *testing.T, cs testsChainSimulator.ChainSimulator, addressBytes []byte, token []byte, shardID uint32, -) *esdt.MetaData { +) *esdt.ESDigitalToken { account, err := cs.GetNodeHandler(shardID).GetStateComponents().AccountsAdapter().LoadAccount(addressBytes) require.Nil(t, err) userAccount, ok := account.(state.UserAccountHandler) @@ -542,6 +561,19 @@ func getMetaDataFromAcc( esdtData := &esdt.ESDigitalToken{} err = cs.GetNodeHandler(shardID).GetCoreComponents().InternalMarshalizer().Unmarshal(esdtData, esdtDataBytes) require.Nil(t, err) + + return esdtData +} + +func getMetaDataFromAcc( + t *testing.T, + cs testsChainSimulator.ChainSimulator, + addressBytes []byte, + token []byte, + shardID uint32, +) *esdt.MetaData { + esdtData := getESDTDataFromAcc(t, cs, addressBytes, token, shardID) + require.NotNil(t, esdtData.TokenMetaData) return esdtData.TokenMetaData @@ -658,7 +690,7 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) // issue fungible - fungibleTicker := []byte("FUNGIBLETICKER") + fungibleTicker := []byte("FUNTICKER") tx = issueTx(1, addrs[0].Bytes, fungibleTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -703,7 +735,7 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { nftTokenID, sftTokenID, metaESDTTokenID, - // fungibleTokenID, + fungibleTokenID, } nftMetaData := txsFee.GetDefaultMetaData() @@ -722,7 +754,7 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { nftMetaData, sftMetaData, esdtMetaData, - // fungibleMetaData, + fungibleMetaData, } nonce := uint64(4) @@ -743,12 +775,18 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { log.Info("Step 1. check that the metaData for the NFT was saved in the user account and not on the system account") checkMetaData(t, cs, addrs[0].Bytes, nftTokenID, nftMetaData) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID) log.Info("Step 2. check that the metaData for the other token types is saved on the system account and not at the user account level") - checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, sftMetaData) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, sftTokenID) + checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, esdtMetaData) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, metaESDTTokenID) + checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, fungibleMetaData) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, fungibleTokenID) } // Test scenario #4 @@ -979,7 +1017,7 @@ func TestChainSimulator_NFT_ESDTMetaDataUpdate(t *testing.T) { require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - log.Info("Call ESDTMetaDataRecreate to rewrite the meta data for the nft") + log.Info("Call ESDTMetaDataUpdate to rewrite the meta data for the nft") nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) nftMetaData.Name = []byte(hex.EncodeToString([]byte("name2"))) From e6bf52c796443f27023da799e0147579c137aaf2 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Sat, 1 Jun 2024 17:13:05 +0300 Subject: [PATCH 292/503] added system acc address per shard --- .../vm/esdtImprovements_test.go | 65 ++++++++++++++----- 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index ad5f7c713d8..2dbe7fe23f2 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -22,6 +22,7 @@ import ( "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/vm" logger "github.com/multiversx/mx-chain-logger-go" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -214,10 +215,12 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool) { log.Info("Step 1. check that the metadata for all tokens is saved on the system account") - checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, nftMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, sftMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, esdtMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, fungibleMetaData) + systemAccountAddress := getSystemAccountAddress(t, cs, addrs[0].Bytes) + + checkMetaData(t, cs, systemAccountAddress, nftTokenID, nftMetaData) + checkMetaData(t, cs, systemAccountAddress, sftTokenID, sftMetaData) + checkMetaData(t, cs, systemAccountAddress, metaESDTTokenID, esdtMetaData) + checkMetaData(t, cs, systemAccountAddress, fungibleTokenID, fungibleMetaData) log.Info("Step 2. wait for DynamicEsdtFlag activation") @@ -240,10 +243,10 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool) { log.Info("Step 4. check that the metadata for all tokens is saved on the system account") - checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, nftMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, nftMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, esdtMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, fungibleMetaData) + checkMetaData(t, cs, systemAccountAddress, nftTokenID, nftMetaData) + checkMetaData(t, cs, systemAccountAddress, sftTokenID, sftMetaData) + checkMetaData(t, cs, systemAccountAddress, metaESDTTokenID, esdtMetaData) + checkMetaData(t, cs, systemAccountAddress, fungibleTokenID, fungibleMetaData) log.Info("Step 5. make an updateTokenID@tokenID function call on the ESDTSystem SC for all token types") @@ -262,10 +265,10 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool) { log.Info("Step 6. check that the metadata for all tokens is saved on the system account") - checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, nftMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, nftMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, esdtMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, fungibleMetaData) + checkMetaData(t, cs, systemAccountAddress, nftTokenID, nftMetaData) + checkMetaData(t, cs, systemAccountAddress, sftTokenID, sftMetaData) + checkMetaData(t, cs, systemAccountAddress, metaESDTTokenID, esdtMetaData) + checkMetaData(t, cs, systemAccountAddress, fungibleTokenID, fungibleMetaData) log.Info("Step 7. transfer the tokens to another account") @@ -284,18 +287,20 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool) { log.Info("Step 8. check that the metaData for the NFT was removed from the system account and moved to the user account") + systemAccountAddress = getSystemAccountAddress(t, cs, addrs[2].Bytes) + checkMetaData(t, cs, addrs[2].Bytes, nftTokenID, nftMetaData) - checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID) + checkMetaDataNotInAcc(t, cs, systemAccountAddress, nftTokenID) log.Info("Step 9. check that the metaData for the rest of the tokens is still present on the system account and not on the userAccount") - checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, sftMetaData) + checkMetaData(t, cs, systemAccountAddress, sftTokenID, sftMetaData) checkMetaDataNotInAcc(t, cs, addrs[2].Bytes, sftTokenID) - checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, esdtMetaData) + checkMetaData(t, cs, systemAccountAddress, metaESDTTokenID, esdtMetaData) checkMetaDataNotInAcc(t, cs, addrs[2].Bytes, metaESDTTokenID) - checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, fungibleMetaData) + checkMetaData(t, cs, systemAccountAddress, fungibleTokenID, fungibleMetaData) checkMetaDataNotInAcc(t, cs, addrs[2].Bytes, fungibleTokenID) } @@ -326,6 +331,34 @@ func createAddresses( return []dtos.WalletAddress{address, address2, address3} } +func getSystemAccountAddress( + t *testing.T, + cs testsChainSimulator.ChainSimulator, + addressBytes []byte, +) []byte { + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addressBytes) + pubKeyConverter := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter() + + var systemAccountAddress []byte + var err error + + switch shardID { + case uint32(0): + systemAccountAddress, err = pubKeyConverter.Decode("erd1llllllllllllllllllllllllllllllllllllllllllllllllluqq2m3f0f") + require.Nil(t, err) + case uint32(1): + systemAccountAddress, err = pubKeyConverter.Decode("erd1lllllllllllllllllllllllllllllllllllllllllllllllllllsckry7t") + require.Nil(t, err) + case uint32(2): + systemAccountAddress, err = pubKeyConverter.Decode("erd1lllllllllllllllllllllllllllllllllllllllllllllllllupq9x7ny0") + require.Nil(t, err) + default: + assert.Fail(t, "no valid shard ID") + } + + return systemAccountAddress +} + func checkMetaData( t *testing.T, cs testsChainSimulator.ChainSimulator, From e3471142aca8874d7e31ddd2b70ec942df5d0d24 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 3 Jun 2024 16:49:18 +0300 Subject: [PATCH 293/503] do not add relayed v3 to the bad tx forwarder --- process/transaction/shardProcess.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index d9fe3c94891..99d2affd2c2 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -1152,7 +1152,7 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( return err } - if txProc.enableEpochsHandler.IsFlagEnabled(common.AddFailedRelayedTxToInvalidMBsFlag) { + if txProc.enableEpochsHandler.IsFlagEnabled(common.AddFailedRelayedTxToInvalidMBsFlag) && !isRelayedV3(originalTx.InnerTransactions) { err = txProc.badTxForwarder.AddIntermediateTransactions([]data.TransactionHandler{originalTx}) if err != nil { return err From fd1ebcd77f239df903dbf787be4a9f31d2e6b516 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Mon, 3 Jun 2024 17:46:10 +0300 Subject: [PATCH 294/503] added scenario 9 --- .../vm/esdtImprovements_test.go | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 2dbe7fe23f2..52e0e1b8cf8 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -1518,3 +1518,138 @@ func TestChainSimulator_NFT_ESDTModifyRoyalties(t *testing.T) { require.Equal(t, uint32(big.NewInt(20).Uint64()), retrievedMetaData.Royalties) } + +// Test scenario #9 +// +// Initial setup: Create NFT +// +// 1. Change the nft to DYNAMIC type - the metadata should be on the system account +// 2. Send the NFT cross shard +// 3. The meta data should still be present on the system account +func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(2) + + baseIssuingCost := "1000" + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + mintValue := big.NewInt(10) + mintValue = mintValue.Mul(oneEGLD, mintValue) + + addrs := createAddresses(t, cs, true) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch) - 1) + require.Nil(t, err) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + log.Info("Initial setup: Create NFT") + + nftTicker := []byte("NFTTICKER") + tx := issueNonFungibleTx(0, addrs[1].Bytes, nftTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleNFTUpdate), + } + + nftTokenID := txResult.Logs.Events[0].Topics[0] + tokenType := core.DynamicNFTESDT + + setAddressEsdtRoles(t, cs, addrs[1], nftTokenID, roles) + + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = nftCreateTx(1, addrs[1].Bytes, nftTokenID, nftMetaData) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + log.Info("Step 1. Change the nft to DYNAMIC type - the metadata should be on the system account") + + txDataField := bytes.Join( + [][]byte{ + []byte(core.ESDTSetTokenType), + []byte(hex.EncodeToString(nftTokenID)), + []byte(hex.EncodeToString([]byte(tokenType))), + }, + []byte("@"), + ) + + tx = &transaction.Transaction{ + Nonce: 2, + SndAddr: addrs[1].Bytes, + RcvAddr: addrs[1].Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + systemAccountAddress := getSystemAccountAddress(t, cs, addrs[1].Bytes) + checkMetaData(t, cs, systemAccountAddress, nftTokenID, nftMetaData) + + log.Info("Step 2. Send the NFT cross shard") + + tx = esdtNFTTransferTx(2, addrs[1].Bytes, addrs[2].Bytes, nftTokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + log.Info("Step 3. The meta data should still be present on the system account") + + checkMetaData(t, cs, systemAccountAddress, nftTokenID, nftMetaData) +} From b81044145ede233178c6cf3935f8698e33256484 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 4 Jun 2024 10:56:04 +0300 Subject: [PATCH 295/503] updated core-go --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 2dd782cc25c..084e8e818e8 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e - github.com/multiversx/mx-chain-core-go v1.2.21-0.20240515142458-bb09ab417156 + github.com/multiversx/mx-chain-core-go v1.2.21-0.20240604075337-88bd243c9240 github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df github.com/multiversx/mx-chain-es-indexer-go v1.7.1-0.20240509104512-25512675833d github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 diff --git a/go.sum b/go.sum index 6cdd0173967..cd752364c18 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY 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.20240515142458-bb09ab417156 h1:Lzm7USVM1b6h1OsizXYjVOiqX9USwaOuNCegkcAlFJM= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240515142458-bb09ab417156/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240604075337-88bd243c9240 h1:aTh69ZTT1Vazs4gs39ulgM2F8auLBH6S+TF9l23OQl8= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240604075337-88bd243c9240/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.1-0.20240509104512-25512675833d h1:GD1D8V0bE6hDLjrduSsMwQwwf6PMq2Zww7FYMfJsuiw= From 1bb7148d829cf26196a8690f52b6cbbc7a211da8 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 4 Jun 2024 12:43:57 +0300 Subject: [PATCH 296/503] update check meta data for system account --- .../vm/esdtImprovements_test.go | 114 +++++++----------- 1 file changed, 46 insertions(+), 68 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 52e0e1b8cf8..4f4e70ae4ae 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -22,7 +22,6 @@ import ( "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/vm" logger "github.com/multiversx/mx-chain-logger-go" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -215,12 +214,12 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool) { log.Info("Step 1. check that the metadata for all tokens is saved on the system account") - systemAccountAddress := getSystemAccountAddress(t, cs, addrs[0].Bytes) + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - checkMetaData(t, cs, systemAccountAddress, nftTokenID, nftMetaData) - checkMetaData(t, cs, systemAccountAddress, sftTokenID, sftMetaData) - checkMetaData(t, cs, systemAccountAddress, metaESDTTokenID, esdtMetaData) - checkMetaData(t, cs, systemAccountAddress, fungibleTokenID, fungibleMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, shardID, fungibleMetaData) log.Info("Step 2. wait for DynamicEsdtFlag activation") @@ -243,10 +242,12 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool) { log.Info("Step 4. check that the metadata for all tokens is saved on the system account") - checkMetaData(t, cs, systemAccountAddress, nftTokenID, nftMetaData) - checkMetaData(t, cs, systemAccountAddress, sftTokenID, sftMetaData) - checkMetaData(t, cs, systemAccountAddress, metaESDTTokenID, esdtMetaData) - checkMetaData(t, cs, systemAccountAddress, fungibleTokenID, fungibleMetaData) + shardID = cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[1].Bytes) + + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, shardID, fungibleMetaData) log.Info("Step 5. make an updateTokenID@tokenID function call on the ESDTSystem SC for all token types") @@ -265,10 +266,10 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool) { log.Info("Step 6. check that the metadata for all tokens is saved on the system account") - checkMetaData(t, cs, systemAccountAddress, nftTokenID, nftMetaData) - checkMetaData(t, cs, systemAccountAddress, sftTokenID, sftMetaData) - checkMetaData(t, cs, systemAccountAddress, metaESDTTokenID, esdtMetaData) - checkMetaData(t, cs, systemAccountAddress, fungibleTokenID, fungibleMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, shardID, fungibleMetaData) log.Info("Step 7. transfer the tokens to another account") @@ -287,21 +288,21 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool) { log.Info("Step 8. check that the metaData for the NFT was removed from the system account and moved to the user account") - systemAccountAddress = getSystemAccountAddress(t, cs, addrs[2].Bytes) + shardID = cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[2].Bytes) - checkMetaData(t, cs, addrs[2].Bytes, nftTokenID, nftMetaData) - checkMetaDataNotInAcc(t, cs, systemAccountAddress, nftTokenID) + checkMetaData(t, cs, addrs[2].Bytes, nftTokenID, shardID, nftMetaData) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) log.Info("Step 9. check that the metaData for the rest of the tokens is still present on the system account and not on the userAccount") - checkMetaData(t, cs, systemAccountAddress, sftTokenID, sftMetaData) - checkMetaDataNotInAcc(t, cs, addrs[2].Bytes, sftTokenID) + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData) + checkMetaDataNotInAcc(t, cs, addrs[2].Bytes, sftTokenID, shardID) - checkMetaData(t, cs, systemAccountAddress, metaESDTTokenID, esdtMetaData) - checkMetaDataNotInAcc(t, cs, addrs[2].Bytes, metaESDTTokenID) + checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) + checkMetaDataNotInAcc(t, cs, addrs[2].Bytes, metaESDTTokenID, shardID) - checkMetaData(t, cs, systemAccountAddress, fungibleTokenID, fungibleMetaData) - checkMetaDataNotInAcc(t, cs, addrs[2].Bytes, fungibleTokenID) + checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, shardID, fungibleMetaData) + checkMetaDataNotInAcc(t, cs, addrs[2].Bytes, fungibleTokenID, shardID) } func createAddresses( @@ -331,43 +332,14 @@ func createAddresses( return []dtos.WalletAddress{address, address2, address3} } -func getSystemAccountAddress( - t *testing.T, - cs testsChainSimulator.ChainSimulator, - addressBytes []byte, -) []byte { - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addressBytes) - pubKeyConverter := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter() - - var systemAccountAddress []byte - var err error - - switch shardID { - case uint32(0): - systemAccountAddress, err = pubKeyConverter.Decode("erd1llllllllllllllllllllllllllllllllllllllllllllllllluqq2m3f0f") - require.Nil(t, err) - case uint32(1): - systemAccountAddress, err = pubKeyConverter.Decode("erd1lllllllllllllllllllllllllllllllllllllllllllllllllllsckry7t") - require.Nil(t, err) - case uint32(2): - systemAccountAddress, err = pubKeyConverter.Decode("erd1lllllllllllllllllllllllllllllllllllllllllllllllllupq9x7ny0") - require.Nil(t, err) - default: - assert.Fail(t, "no valid shard ID") - } - - return systemAccountAddress -} - func checkMetaData( t *testing.T, cs testsChainSimulator.ChainSimulator, addressBytes []byte, token []byte, + shardID uint32, expectedMetaData *txsFee.MetaData, ) { - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addressBytes) - retrievedMetaData := getMetaDataFromAcc(t, cs, addressBytes, token, shardID) require.Equal(t, expectedMetaData.Nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) @@ -385,9 +357,8 @@ func checkMetaDataNotInAcc( cs testsChainSimulator.ChainSimulator, addressBytes []byte, token []byte, + shardID uint32, ) { - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addressBytes) - esdtData := getESDTDataFromAcc(t, cs, addressBytes, token, shardID) require.Nil(t, esdtData.TokenMetaData) @@ -807,19 +778,21 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { log.Info("Step 1. check that the metaData for the NFT was saved in the user account and not on the system account") - checkMetaData(t, cs, addrs[0].Bytes, nftTokenID, nftMetaData) - checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID) + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + + checkMetaData(t, cs, addrs[0].Bytes, nftTokenID, shardID, nftMetaData) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) log.Info("Step 2. check that the metaData for the other token types is saved on the system account and not at the user account level") - checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, sftMetaData) - checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, sftTokenID) + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, sftTokenID, shardID) - checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, esdtMetaData) - checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, metaESDTTokenID) + checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, metaESDTTokenID, shardID) - checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, fungibleMetaData) - checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, fungibleTokenID) + checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, shardID, fungibleMetaData) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, fungibleTokenID, shardID) } // Test scenario #4 @@ -957,7 +930,9 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) - checkMetaData(t, cs, address.Bytes, nftTokenID, nftMetaData) + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(address.Bytes) + + checkMetaData(t, cs, address.Bytes, nftTokenID, shardID, nftMetaData) } // Test scenario #5 @@ -1092,7 +1067,9 @@ func TestChainSimulator_NFT_ESDTMetaDataUpdate(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) - checkMetaData(t, cs, address.Bytes, nftTokenID, nftMetaData) + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(address.Bytes) + + checkMetaData(t, cs, address.Bytes, nftTokenID, shardID, nftMetaData) } // Test scenario #6 @@ -1638,8 +1615,9 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { Version: 1, } - systemAccountAddress := getSystemAccountAddress(t, cs, addrs[1].Bytes) - checkMetaData(t, cs, systemAccountAddress, nftTokenID, nftMetaData) + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[1].Bytes) + + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) log.Info("Step 2. Send the NFT cross shard") @@ -1651,5 +1629,5 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { log.Info("Step 3. The meta data should still be present on the system account") - checkMetaData(t, cs, systemAccountAddress, nftTokenID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) } From c9d775ddc3d9d75bc6b98a8b4f92b93d92eb827a Mon Sep 17 00:00:00 2001 From: MariusC Date: Tue, 4 Jun 2024 16:19:37 +0300 Subject: [PATCH 297/503] FIX: Destination shard id in chain simulator for meta chain addresses --- node/chainSimulator/chainSimulator.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index e8ebd406739..46784ef90c0 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -566,6 +566,10 @@ func (s *simulator) computeTransactionsStatus(txsWithResult []*transactionWithRe sentTx := resultTx.tx destinationShardID := s.GetNodeHandler(0).GetShardCoordinator().ComputeId(sentTx.RcvAddr) + if core.IsSmartContractOnMetachain([]byte{255}, sentTx.RcvAddr) { + destinationShardID = s.GetNodeHandler(0).GetShardCoordinator().ComputeId(sentTx.SndAddr) + } + result, errGet := s.GetNodeHandler(destinationShardID).GetFacadeHandler().GetTransaction(resultTx.hexHash, true) if errGet == nil && result.Status != transaction.TxStatusPending { log.Info("############## transaction was executed ##############", "txHash", resultTx.hexHash) From e21b29810384e58a7e2409ba83a7198a050ebbe9 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 4 Jun 2024 16:44:54 +0300 Subject: [PATCH 298/503] added scenario 10 --- .../vm/esdtImprovements_test.go | 241 +++++++++++++++++- 1 file changed, 237 insertions(+), 4 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 4f4e70ae4ae..731b1fcc06a 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -56,9 +56,9 @@ func TestChainSimulator_CheckTokensMetadata_TransferTokens(t *testing.T) { t.Skip("this is not a short test") } - t.Run("transfer and check all tokens - intra shard", func(t *testing.T) { - transferAndCheckTokensMetaData(t, false) - }) + // t.Run("transfer and check all tokens - intra shard", func(t *testing.T) { + // transferAndCheckTokensMetaData(t, false) + // }) t.Run("transfer and check all tokens - cross shard", func(t *testing.T) { transferAndCheckTokensMetaData(t, true) @@ -517,7 +517,7 @@ func nftCreateTx( [][]byte{ []byte(core.BuiltInFunctionESDTNFTCreate), []byte(hex.EncodeToString(tokenID)), - []byte(hex.EncodeToString(big.NewInt(1).Bytes())), // quantity + []byte(hex.EncodeToString(big.NewInt(2).Bytes())), // quantity metaData.Name, []byte(hex.EncodeToString(big.NewInt(10).Bytes())), metaData.Hash, @@ -1631,3 +1631,236 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) } + +// Test scenario #10 +// +// Initial setup: Create SFT and send in 2 shards +// +// 1. change the sft meta data in one shard +// 2. change the sft meta data (differently from the previous one) in the other shard +// 3. send sft from one shard to another +// 4. check that the newest metadata is saved +func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(2) + + baseIssuingCost := "1000" + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + mintValue := big.NewInt(10) + mintValue = mintValue.Mul(oneEGLD, mintValue) + + addrs := createAddresses(t, cs, true) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + log.Info("Initial setup: Create SFT and send in 2 shards") + + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleNFTUpdate), + []byte(core.ESDTRoleNFTAddQuantity), + } + + sftTicker := []byte("SFTTICKER") + tx := issueSemiFungibleTx(0, addrs[1].Bytes, sftTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + sftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[1], sftTokenID, roles) + + setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + setAddressEsdtRoles(t, cs, addrs[2], sftTokenID, roles) + + log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) + + sftMetaData := txsFee.GetDefaultMetaData() + sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = nftCreateTx(1, addrs[1].Bytes, sftTokenID, sftMetaData) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + log.Info("Send to separate shards") + + tx = esdtNFTTransferTx(2, addrs[1].Bytes, addrs[2].Bytes, sftTokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + tx = esdtNFTTransferTx(3, addrs[1].Bytes, addrs[0].Bytes, sftTokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + log.Info("Step 1. change the sft meta data in one shard") + + sftMetaData2 := txsFee.GetDefaultMetaData() + sftMetaData2.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + sftMetaData2.Name = []byte(hex.EncodeToString([]byte("name2"))) + sftMetaData2.Hash = []byte(hex.EncodeToString([]byte("hash2"))) + sftMetaData2.Attributes = []byte(hex.EncodeToString([]byte("attributes2"))) + + txDataField := bytes.Join( + [][]byte{ + []byte(core.ESDTMetaDataUpdate), + []byte(hex.EncodeToString(sftTokenID)), + sftMetaData2.Nonce, + sftMetaData2.Name, + []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + sftMetaData2.Hash, + sftMetaData2.Attributes, + sftMetaData2.Uris[0], + sftMetaData2.Uris[1], + sftMetaData2.Uris[2], + }, + []byte("@"), + ) + + tx = &transaction.Transaction{ + Nonce: 0, + SndAddr: addrs[0].Bytes, + RcvAddr: addrs[0].Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData2) + + log.Info("Step 2. change the sft meta data (differently from the previous one) in the other shard") + + sftMetaData3 := txsFee.GetDefaultMetaData() + sftMetaData3.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + sftMetaData3.Name = []byte(hex.EncodeToString([]byte("name3"))) + sftMetaData3.Hash = []byte(hex.EncodeToString([]byte("hash3"))) + sftMetaData3.Attributes = []byte(hex.EncodeToString([]byte("attributes3"))) + + txDataField = bytes.Join( + [][]byte{ + []byte(core.ESDTMetaDataUpdate), + []byte(hex.EncodeToString(sftTokenID)), + sftMetaData3.Nonce, + sftMetaData3.Name, + []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + sftMetaData3.Hash, + sftMetaData3.Attributes, + sftMetaData3.Uris[0], + sftMetaData3.Uris[1], + sftMetaData3.Uris[2], + }, + []byte("@"), + ) + + tx = &transaction.Transaction{ + Nonce: 0, + SndAddr: addrs[2].Bytes, + RcvAddr: addrs[2].Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + shardID = cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[2].Bytes) + + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData3) + + log.Info("Step 3. send sft from one shard to another") + + tx = esdtNFTTransferTx(1, addrs[0].Bytes, addrs[2].Bytes, sftTokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + log.Info("Step 4. check that the newest metadata is saved") + + shardID = cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[2].Bytes) + + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData2) +} From e4241d01cde2cdc048a1800869a6db6473d2fc52 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 4 Jun 2024 17:08:49 +0300 Subject: [PATCH 299/503] update scenario 6 --- .../vm/esdtImprovements_test.go | 40 ++++++++++++++++--- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 731b1fcc06a..f256c7e89a6 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -517,7 +517,7 @@ func nftCreateTx( [][]byte{ []byte(core.BuiltInFunctionESDTNFTCreate), []byte(hex.EncodeToString(tokenID)), - []byte(hex.EncodeToString(big.NewInt(2).Bytes())), // quantity + []byte(hex.EncodeToString(big.NewInt(1).Bytes())), // quantity metaData.Name, []byte(hex.EncodeToString(big.NewInt(10).Bytes())), metaData.Hash, @@ -1123,7 +1123,8 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { mintValue := big.NewInt(10) mintValue = mintValue.Mul(oneEGLD, mintValue) - address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) + shardID := uint32(1) + address, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) require.Nil(t, err) err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) @@ -1160,11 +1161,12 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Call ESDTModifyCreator and check that the creator was modified") - newCreatorAddress, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) + newCreatorAddress, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) require.Nil(t, err) err = cs.GenerateBlocks(10) @@ -1208,7 +1210,6 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(address.Bytes) retrievedMetaData := getMetaDataFromAcc(t, cs, address.Bytes, nftTokenID, shardID) require.Equal(t, newCreatorAddress.Bytes, retrievedMetaData.Creator) @@ -1721,7 +1722,34 @@ func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { sftMetaData := txsFee.GetDefaultMetaData() sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[1].Bytes, sftTokenID, sftMetaData) + txDataField := bytes.Join( + [][]byte{ + []byte(core.BuiltInFunctionESDTNFTCreate), + []byte(hex.EncodeToString(sftTokenID)), + []byte(hex.EncodeToString(big.NewInt(2).Bytes())), // quantity + sftMetaData.Name, + []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + sftMetaData.Hash, + sftMetaData.Attributes, + sftMetaData.Uris[0], + sftMetaData.Uris[1], + sftMetaData.Uris[2], + }, + []byte("@"), + ) + + tx = &transaction.Transaction{ + Nonce: 1, + SndAddr: addrs[1].Bytes, + RcvAddr: addrs[1].Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1759,7 +1787,7 @@ func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { sftMetaData2.Hash = []byte(hex.EncodeToString([]byte("hash2"))) sftMetaData2.Attributes = []byte(hex.EncodeToString([]byte("attributes2"))) - txDataField := bytes.Join( + txDataField = bytes.Join( [][]byte{ []byte(core.ESDTMetaDataUpdate), []byte(hex.EncodeToString(sftTokenID)), From 5dd3e703ba17e02bd0988c914adb91839957f143 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 5 Jun 2024 09:30:02 +0300 Subject: [PATCH 300/503] added multi nft transfer --- .../vm/esdtImprovements_test.go | 49 ++++++++++++++++--- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index f256c7e89a6..4c78f107980 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -56,16 +56,20 @@ func TestChainSimulator_CheckTokensMetadata_TransferTokens(t *testing.T) { t.Skip("this is not a short test") } - // t.Run("transfer and check all tokens - intra shard", func(t *testing.T) { - // transferAndCheckTokensMetaData(t, false) - // }) + t.Run("transfer and check all tokens - intra shard", func(t *testing.T) { + transferAndCheckTokensMetaData(t, false, false) + }) + + t.Run("transfer and check all tokens - intra shard - multi transfer", func(t *testing.T) { + transferAndCheckTokensMetaData(t, false, true) + }) t.Run("transfer and check all tokens - cross shard", func(t *testing.T) { - transferAndCheckTokensMetaData(t, true) + transferAndCheckTokensMetaData(t, true, false) }) } -func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool) { +func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTransfer bool) { startTime := time.Now().Unix() roundDurationInMillis := uint64(6000) roundsPerEpoch := core.OptionalUint64{ @@ -204,6 +208,7 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool) { txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) nonce++ @@ -228,16 +233,44 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool) { log.Info("Step 3. transfer the tokens to another account") - for _, tokenID := range tokenIDs { - log.Info("transfering token id", "tokenID", tokenID) + if isMultiTransfer { + tx = utils.CreateMultiTransferTX(nonce, addrs[0].Bytes, addrs[1].Bytes, minGasPrice, 10_000_000, &utils.TransferESDTData{ + Token: nftTokenID, + Value: big.NewInt(1), + }, &utils.TransferESDTData{ + Token: sftTokenID, + Value: big.NewInt(1), + }, &utils.TransferESDTData{ + Token: metaESDTTokenID, + Value: big.NewInt(1), + }, &utils.TransferESDTData{ + Token: fungibleTokenID, + Value: big.NewInt(1), + }, + ) + tx.Version = 1 + tx.Signature = []byte("dummySig") + tx.ChainID = []byte(configs.ChainID) - tx = esdtNFTTransferTx(nonce, addrs[0].Bytes, addrs[1].Bytes, tokenID) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) nonce++ + } else { + for _, tokenID := range tokenIDs { + log.Info("transfering token id", "tokenID", tokenID) + + tx = esdtNFTTransferTx(nonce, addrs[0].Bytes, addrs[1].Bytes, tokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } } log.Info("Step 4. check that the metadata for all tokens is saved on the system account") From 7187083134f4949c0f2971f45e06d82a50be403d Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 5 Jun 2024 11:26:17 +0300 Subject: [PATCH 301/503] separate func for multi esdt nft tranfer tx --- .../vm/esdtImprovements_test.go | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 4c78f107980..5f006a97dc4 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -234,23 +234,7 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran log.Info("Step 3. transfer the tokens to another account") if isMultiTransfer { - tx = utils.CreateMultiTransferTX(nonce, addrs[0].Bytes, addrs[1].Bytes, minGasPrice, 10_000_000, &utils.TransferESDTData{ - Token: nftTokenID, - Value: big.NewInt(1), - }, &utils.TransferESDTData{ - Token: sftTokenID, - Value: big.NewInt(1), - }, &utils.TransferESDTData{ - Token: metaESDTTokenID, - Value: big.NewInt(1), - }, &utils.TransferESDTData{ - Token: fungibleTokenID, - Value: big.NewInt(1), - }, - ) - tx.Version = 1 - tx.Signature = []byte("dummySig") - tx.ChainID = []byte(configs.ChainID) + tx = multiESDTNFTTransferTx(nonce, addrs[0].Bytes, addrs[1].Bytes, tokenIDs) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -397,6 +381,32 @@ func checkMetaDataNotInAcc( require.Nil(t, esdtData.TokenMetaData) } +func multiESDTNFTTransferTx(nonce uint64, sndAdr, rcvAddr []byte, tokens [][]byte) *transaction.Transaction { + transferData := make([]*utils.TransferESDTData, 0) + + for _, tokenID := range tokens { + transferData = append(transferData, &utils.TransferESDTData{ + Token: tokenID, + Nonce: 1, + Value: big.NewInt(1), + }) + } + + tx := utils.CreateMultiTransferTX( + nonce, + sndAdr, + rcvAddr, + minGasPrice, + 10_000_000, + transferData..., + ) + tx.Version = 1 + tx.Signature = []byte("dummySig") + tx.ChainID = []byte(configs.ChainID) + + return tx +} + func esdtNFTTransferTx(nonce uint64, sndAdr, rcvAddr, token []byte) *transaction.Transaction { tx := utils.CreateESDTNFTTransferTx( nonce, From 862c590a33acd0f16a25846a90a128e89562e52c Mon Sep 17 00:00:00 2001 From: MariusC Date: Wed, 5 Jun 2024 13:20:32 +0300 Subject: [PATCH 302/503] FIX: Destination shard id in chain simulator for meta chain addresses 3 --- node/chainSimulator/chainSimulator.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index 46784ef90c0..b932a13f1c1 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -559,6 +559,7 @@ func (s *simulator) SendTxsAndGenerateBlocksTilAreExecuted(txsToSend []*transact func (s *simulator) computeTransactionsStatus(txsWithResult []*transactionWithResult) bool { allAreExecuted := true + contractDeploySCAddress := make([]byte, s.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Len()) for _, resultTx := range txsWithResult { if resultTx.result != nil { continue @@ -566,7 +567,7 @@ func (s *simulator) computeTransactionsStatus(txsWithResult []*transactionWithRe sentTx := resultTx.tx destinationShardID := s.GetNodeHandler(0).GetShardCoordinator().ComputeId(sentTx.RcvAddr) - if core.IsSmartContractOnMetachain([]byte{255}, sentTx.RcvAddr) { + if bytes.Equal(sentTx.RcvAddr, contractDeploySCAddress) { destinationShardID = s.GetNodeHandler(0).GetShardCoordinator().ComputeId(sentTx.SndAddr) } From 4dcfe41bc1561c46006d69ed5b5b1a34ba76486c Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 5 Jun 2024 13:29:54 +0300 Subject: [PATCH 303/503] fix linter issue - scenario 9 --- .../vm/esdtImprovements_test.go | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 5f006a97dc4..3fb26ac20f1 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -1224,7 +1224,7 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { [][]byte{ []byte(core.ESDTModifyCreator), []byte(hex.EncodeToString(nftTokenID)), - nftMetaData.Nonce, + []byte(hex.EncodeToString(big.NewInt(1).Bytes())), }, []byte("@"), ) @@ -1589,9 +1589,6 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { defer cs.Close() - mintValue := big.NewInt(10) - mintValue = mintValue.Mul(oneEGLD, mintValue) - addrs := createAddresses(t, cs, true) err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch) - 1) @@ -1647,9 +1644,9 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { ) tx = &transaction.Transaction{ - Nonce: 2, - SndAddr: addrs[1].Bytes, - RcvAddr: addrs[1].Bytes, + Nonce: 0, + SndAddr: core.ESDTSCAddress, + RcvAddr: core.SystemAccountAddress, GasLimit: 10_000_000, GasPrice: minGasPrice, Signature: []byte("dummySig"), @@ -1659,6 +1656,17 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { Version: 1, } + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult) + fmt.Println(txResult.Logs.Events[0]) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[1].Bytes) checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) @@ -1726,9 +1734,6 @@ func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { defer cs.Close() - mintValue := big.NewInt(10) - mintValue = mintValue.Mul(oneEGLD, mintValue) - addrs := createAddresses(t, cs, true) err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) From 490f5671f9fd1a202a1a923d6f705fce61fea30d Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 5 Jun 2024 16:41:51 +0300 Subject: [PATCH 304/503] scenario 9 - update --- .../vm/esdtImprovements_test.go | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 3fb26ac20f1..d128fb6c4c3 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -1613,26 +1613,8 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { } nftTokenID := txResult.Logs.Events[0].Topics[0] - tokenType := core.DynamicNFTESDT - - setAddressEsdtRoles(t, cs, addrs[1], nftTokenID, roles) - - log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) - - nftMetaData := txsFee.GetDefaultMetaData() - nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - - tx = nftCreateTx(1, addrs[1].Bytes, nftTokenID, nftMetaData) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - - err = cs.GenerateBlocks(10) - require.Nil(t, err) - - log.Info("Step 1. Change the nft to DYNAMIC type - the metadata should be on the system account") + tokenType := core.DynamicNFTESDT txDataField := bytes.Join( [][]byte{ @@ -1667,6 +1649,25 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) + setAddressEsdtRoles(t, cs, addrs[1], nftTokenID, roles) + + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = nftCreateTx(1, addrs[1].Bytes, nftTokenID, nftMetaData) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + log.Info("Step 1. Change the nft to DYNAMIC type - the metadata should be on the system account") + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[1].Bytes) checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) From 961b23fef31d8807e0404d5006ba4743fe1eec63 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 4 Jun 2024 09:25:31 +0300 Subject: [PATCH 305/503] added api esdt token type --- api/groups/addressGroup.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/groups/addressGroup.go b/api/groups/addressGroup.go index a059d3a4388..61ad38bee5e 100644 --- a/api/groups/addressGroup.go +++ b/api/groups/addressGroup.go @@ -75,6 +75,7 @@ type esdtTokenData struct { type esdtNFTTokenData struct { TokenIdentifier string `json:"tokenIdentifier"` Balance string `json:"balance"` + Type uint32 `json:"type"` Properties string `json:"properties,omitempty"` Name string `json:"name,omitempty"` Nonce uint64 `json:"nonce,omitempty"` @@ -485,6 +486,7 @@ func buildTokenDataApiResponse(tokenIdentifier string, esdtData *esdt.ESDigitalT tokenData := &esdtNFTTokenData{ TokenIdentifier: tokenIdentifier, Balance: esdtData.Value.String(), + Type: esdtData.GetType(), Properties: hex.EncodeToString(esdtData.Properties), } if esdtData.TokenMetaData != nil { From f6722c8af05923146ecd43ecd31a0cd49b1a79f6 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 6 Jun 2024 11:35:55 +0300 Subject: [PATCH 306/503] export api nft token data --- api/groups/addressGroup.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/api/groups/addressGroup.go b/api/groups/addressGroup.go index 61ad38bee5e..2018db97b1a 100644 --- a/api/groups/addressGroup.go +++ b/api/groups/addressGroup.go @@ -72,7 +72,8 @@ type esdtTokenData struct { Properties string `json:"properties"` } -type esdtNFTTokenData struct { +// ESDTNFTTokenData defines the exposed nft token data structure +type ESDTNFTTokenData struct { TokenIdentifier string `json:"tokenIdentifier"` Balance string `json:"balance"` Type uint32 `json:"type"` @@ -449,7 +450,7 @@ func (ag *addressGroup) getAllESDTData(c *gin.Context) { return } - formattedTokens := make(map[string]*esdtNFTTokenData) + formattedTokens := make(map[string]*ESDTNFTTokenData) for tokenID, esdtData := range tokens { tokenData := buildTokenDataApiResponse(tokenID, esdtData) @@ -482,8 +483,8 @@ func (ag *addressGroup) isDataTrieMigrated(c *gin.Context) { shared.RespondWithSuccess(c, gin.H{"isMigrated": isMigrated}) } -func buildTokenDataApiResponse(tokenIdentifier string, esdtData *esdt.ESDigitalToken) *esdtNFTTokenData { - tokenData := &esdtNFTTokenData{ +func buildTokenDataApiResponse(tokenIdentifier string, esdtData *esdt.ESDigitalToken) *ESDTNFTTokenData { + tokenData := &ESDTNFTTokenData{ TokenIdentifier: tokenIdentifier, Balance: esdtData.Value.String(), Type: esdtData.GetType(), From 3ece83141b9b6778a1e942cc2c2d465d30646a48 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 6 Jun 2024 11:44:48 +0300 Subject: [PATCH 307/503] set api token type to string --- api/groups/addressGroup.go | 4 ++-- go.mod | 2 +- go.sum | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/api/groups/addressGroup.go b/api/groups/addressGroup.go index 2018db97b1a..9d1e182cdbe 100644 --- a/api/groups/addressGroup.go +++ b/api/groups/addressGroup.go @@ -76,7 +76,7 @@ type esdtTokenData struct { type ESDTNFTTokenData struct { TokenIdentifier string `json:"tokenIdentifier"` Balance string `json:"balance"` - Type uint32 `json:"type"` + Type string `json:"type"` Properties string `json:"properties,omitempty"` Name string `json:"name,omitempty"` Nonce uint64 `json:"nonce,omitempty"` @@ -487,7 +487,7 @@ func buildTokenDataApiResponse(tokenIdentifier string, esdtData *esdt.ESDigitalT tokenData := &ESDTNFTTokenData{ TokenIdentifier: tokenIdentifier, Balance: esdtData.Value.String(), - Type: esdtData.GetType(), + Type: core.ESDTType(esdtData.GetType()).String(), Properties: hex.EncodeToString(esdtData.Properties), } if esdtData.TokenMetaData != nil { diff --git a/go.mod b/go.mod index 928c7a4b7c7..f0b84a37b29 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e - github.com/multiversx/mx-chain-core-go v1.2.21-0.20240508071047-fefea5737840 + github.com/multiversx/mx-chain-core-go v1.2.21-0.20240530111258-45870512bfbe github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df github.com/multiversx/mx-chain-es-indexer-go v1.7.1-0.20240509104512-25512675833d github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 diff --git a/go.sum b/go.sum index a528855ae3e..e6fcf7d3432 100644 --- a/go.sum +++ b/go.sum @@ -392,6 +392,8 @@ github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c 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-core-go v1.2.21-0.20240530111258-45870512bfbe h1:7ccy0nNJkCGDlRrIbAmZfVv5XkZAxXuBFnfUMNuESRA= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240530111258-45870512bfbe/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.1-0.20240509104512-25512675833d h1:GD1D8V0bE6hDLjrduSsMwQwwf6PMq2Zww7FYMfJsuiw= From cba8c10e172757175796e33b10ef6776f883d8ce Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 6 Jun 2024 11:45:03 +0300 Subject: [PATCH 308/503] added esdt tokens api integration test --- .../chainSimulator/vm/esdtTokens_test.go | 210 ++++++++++++++++++ 1 file changed, 210 insertions(+) create mode 100644 integrationTests/chainSimulator/vm/esdtTokens_test.go diff --git a/integrationTests/chainSimulator/vm/esdtTokens_test.go b/integrationTests/chainSimulator/vm/esdtTokens_test.go new file mode 100644 index 00000000000..ca70d98d7bc --- /dev/null +++ b/integrationTests/chainSimulator/vm/esdtTokens_test.go @@ -0,0 +1,210 @@ +package vm + +import ( + "encoding/hex" + "encoding/json" + "fmt" + "math/big" + "net/http" + "testing" + "time" + + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-go/api/groups" + "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee" + "github.com/multiversx/mx-chain-go/node/chainSimulator" + "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" + "github.com/stretchr/testify/require" +) + +type esdtTokensCompleteResponseData struct { + Tokens map[string]groups.ESDTNFTTokenData `json:"esdts"` +} + +type esdtTokensCompleteResponse struct { + Data esdtTokensCompleteResponseData `json:"data"` + Error string `json:"error"` + Code string +} + +func TestChainSimulator_Api_TokenType(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(2) + + baseIssuingCost := "1000" + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewFreePortAPIConfigurator("localhost"), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + mintValue := big.NewInt(10) + mintValue = mintValue.Mul(oneEGLD, mintValue) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + log.Info("Initial setup: Create tokens") + + addrs := createAddresses(t, cs, false) + + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + } + + // issue fungible + fungibleTicker := []byte("FUNTICKER") + tx := issueTx(0, addrs[0].Bytes, fungibleTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + fungibleTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], fungibleTokenID, roles) + + log.Info("Issued fungible token id", "tokenID", string(fungibleTokenID)) + + // issue NFT + nftTicker := []byte("NFTTICKER") + tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) + + // issue SFT + sftTicker := []byte("SFTTICKER") + tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + sftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + + log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + sftMetaData := txsFee.GetDefaultMetaData() + sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + fungibleMetaData := txsFee.GetDefaultMetaData() + fungibleMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tokenIDs := [][]byte{ + nftTokenID, + sftTokenID, + } + + tokensMetadata := []*txsFee.MetaData{ + nftMetaData, + sftMetaData, + } + + nonce := uint64(3) + for i := range tokenIDs { + tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + + restAPIInterfaces := cs.GetRestAPIInterfaces() + require.NotNil(t, restAPIInterfaces) + + url := fmt.Sprintf("http://%s/address/%s/esdt", restAPIInterfaces[shardID], addrs[0].Bech32) + response := &esdtTokensCompleteResponse{} + + doHTTPClientGetReq(t, url, response) + + allTokens := response.Data.Tokens + + require.Equal(t, 3, len(allTokens)) + + expTokenID := string(fungibleTokenID) + tokenData, ok := allTokens[expTokenID] + require.True(t, ok) + require.Equal(t, expTokenID, tokenData.TokenIdentifier) + require.Equal(t, core.FungibleESDT, tokenData.Type) + + expTokenID = string(nftTokenID) + "-01" + tokenData, ok = allTokens[expTokenID] + require.True(t, ok) + require.Equal(t, expTokenID, tokenData.TokenIdentifier) + require.Equal(t, core.NonFungibleESDTv2, tokenData.Type) + + expTokenID = string(sftTokenID) + "-01" + tokenData, ok = allTokens[expTokenID] + require.True(t, ok) + require.Equal(t, expTokenID, tokenData.TokenIdentifier) + require.Equal(t, core.SemiFungibleESDT, tokenData.Type) +} + +func doHTTPClientGetReq(t *testing.T, url string, response interface{}) { + httpClient := &http.Client{} + + req, err := http.NewRequest(http.MethodGet, url, nil) + + resp, err := httpClient.Do(req) + require.Nil(t, err) + require.Equal(t, http.StatusOK, resp.StatusCode) + + jsonParser := json.NewDecoder(resp.Body) + err = jsonParser.Decode(&response) + require.Nil(t, err) +} From 78831c6a4d08266cd5d2f81ce55fff424bbc28b0 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 6 Jun 2024 12:59:23 +0300 Subject: [PATCH 309/503] fixes after review --- api/groups/transactionGroup.go | 180 +++++++----------- factory/processing/processComponents.go | 25 ++- genesis/process/argGenesisBlockCreator.go | 1 - genesis/process/genesisBlockCreator_test.go | 2 - genesis/process/shardGenesisBlockCreator.go | 3 +- .../multiShard/hardFork/hardFork_test.go | 2 - .../multiShard/relayedTx/common.go | 14 +- .../relayedTx/edgecases/edgecases_test.go | 4 +- .../multiShard/relayedTx/relayedTx_test.go | 16 +- integrationTests/testInitializer.go | 2 - process/errors.go | 6 +- .../interceptedTransaction_test.go | 6 +- process/transaction/relayedTxV3Processor.go | 22 ++- .../transaction/relayedTxV3Processor_test.go | 94 +++++++-- process/transaction/shardProcess.go | 2 +- process/transaction/shardProcess_test.go | 2 +- 16 files changed, 188 insertions(+), 193 deletions(-) diff --git a/api/groups/transactionGroup.go b/api/groups/transactionGroup.go index 1d63c00c8a4..29d07de2640 100644 --- a/api/groups/transactionGroup.go +++ b/api/groups/transactionGroup.go @@ -182,36 +182,17 @@ func (tg *transactionGroup) simulateTransaction(c *gin.Context) { return } - innerTxs := make([]*transaction.Transaction, 0, len(ftx.InnerTransactions)) - if len(ftx.InnerTransactions) != 0 { - for _, innerTx := range ftx.InnerTransactions { - if len(innerTx.InnerTransactions) != 0 { - c.JSON( - http.StatusBadRequest, - shared.GenericAPIResponse{ - Data: nil, - Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), errors.ErrRecursiveRelayedTxIsNotAllowed.Error()), - Code: shared.ReturnCodeRequestError, - }, - ) - return - } - - newInnerTx, _, err := tg.createTransaction(innerTx, nil) - if err != nil { - c.JSON( - http.StatusBadRequest, - shared.GenericAPIResponse{ - Data: nil, - Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), err.Error()), - Code: shared.ReturnCodeRequestError, - }, - ) - return - } - - innerTxs = append(innerTxs, newInnerTx) - } + innerTxs, err := tg.extractInnerTransactions(ftx.InnerTransactions) + if err != nil { + c.JSON( + http.StatusBadRequest, + shared.GenericAPIResponse{ + Data: nil, + Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), err.Error()), + Code: shared.ReturnCodeRequestError, + }, + ) + return } if len(innerTxs) == 0 { @@ -287,36 +268,17 @@ func (tg *transactionGroup) sendTransaction(c *gin.Context) { return } - innerTxs := make([]*transaction.Transaction, 0, len(ftx.InnerTransactions)) - if len(ftx.InnerTransactions) != 0 { - for _, innerTx := range ftx.InnerTransactions { - if len(innerTx.InnerTransactions) != 0 { - c.JSON( - http.StatusBadRequest, - shared.GenericAPIResponse{ - Data: nil, - Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), errors.ErrRecursiveRelayedTxIsNotAllowed.Error()), - Code: shared.ReturnCodeRequestError, - }, - ) - return - } - - newInnerTx, _, err := tg.createTransaction(innerTx, nil) - if err != nil { - c.JSON( - http.StatusBadRequest, - shared.GenericAPIResponse{ - Data: nil, - Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), err.Error()), - Code: shared.ReturnCodeRequestError, - }, - ) - return - } - - innerTxs = append(innerTxs, newInnerTx) - } + innerTxs, err := tg.extractInnerTransactions(ftx.InnerTransactions) + if err != nil { + c.JSON( + http.StatusBadRequest, + shared.GenericAPIResponse{ + Data: nil, + Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), err.Error()), + Code: shared.ReturnCodeRequestError, + }, + ) + return } if len(innerTxs) == 0 { @@ -401,30 +363,17 @@ func (tg *transactionGroup) sendMultipleTransactions(c *gin.Context) { var start time.Time txsHashes := make(map[int]string) for idx, receivedTx := range ftxs { - innerTxs := make([]*transaction.Transaction, 0, len(receivedTx.InnerTransactions)) - if len(receivedTx.InnerTransactions) != 0 { - for _, innerTx := range receivedTx.InnerTransactions { - if len(innerTx.InnerTransactions) != 0 { - // if one of the inner txs is invalid, break the loop and move to the next transaction received - break - } - - newInnerTx, _, err := tg.createTransaction(innerTx, nil) - if err != nil { - // if one of the inner txs is invalid, return bad request - c.JSON( - http.StatusBadRequest, - shared.GenericAPIResponse{ - Data: nil, - Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), err.Error()), - Code: shared.ReturnCodeInternalError, - }, - ) - return - } - - innerTxs = append(innerTxs, newInnerTx) - } + innerTxs, errExtractInnerTransactions := tg.extractInnerTransactions(receivedTx.InnerTransactions) + if errExtractInnerTransactions != nil { + c.JSON( + http.StatusBadRequest, + shared.GenericAPIResponse{ + Data: nil, + Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), err.Error()), + Code: shared.ReturnCodeInternalError, + }, + ) + return } if len(innerTxs) == 0 { @@ -541,36 +490,17 @@ func (tg *transactionGroup) computeTransactionGasLimit(c *gin.Context) { return } - innerTxs := make([]*transaction.Transaction, 0, len(ftx.InnerTransactions)) - if len(ftx.InnerTransactions) != 0 { - for _, innerTx := range ftx.InnerTransactions { - if len(innerTx.InnerTransactions) != 0 { - c.JSON( - http.StatusBadRequest, - shared.GenericAPIResponse{ - Data: nil, - Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), errors.ErrRecursiveRelayedTxIsNotAllowed.Error()), - Code: shared.ReturnCodeRequestError, - }, - ) - return - } - - newInnerTx, _, err := tg.createTransaction(innerTx, nil) - if err != nil { - c.JSON( - http.StatusBadRequest, - shared.GenericAPIResponse{ - Data: nil, - Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), err.Error()), - Code: shared.ReturnCodeRequestError, - }, - ) - return - } - - innerTxs = append(innerTxs, newInnerTx) - } + innerTxs, errExtractInnerTransactions := tg.extractInnerTransactions(ftx.InnerTransactions) + if errExtractInnerTransactions != nil { + c.JSON( + http.StatusBadRequest, + shared.GenericAPIResponse{ + Data: nil, + Error: fmt.Sprintf("%s: %s", errors.ErrTxGenerationFailed.Error(), errExtractInnerTransactions.Error()), + Code: shared.ReturnCodeInternalError, + }, + ) + return } if len(innerTxs) == 0 { @@ -910,6 +840,28 @@ func (tg *transactionGroup) getFacade() transactionFacadeHandler { return tg.facade } +func (tg *transactionGroup) extractInnerTransactions( + innerTransactions []*transaction.FrontendTransaction, +) ([]*transaction.Transaction, error) { + innerTxs := make([]*transaction.Transaction, 0, len(innerTransactions)) + if len(innerTransactions) != 0 { + for _, innerTx := range innerTransactions { + if len(innerTx.InnerTransactions) != 0 { + return innerTxs, errors.ErrRecursiveRelayedTxIsNotAllowed + } + + newInnerTx, _, err := tg.createTransaction(innerTx, nil) + if err != nil { + return innerTxs, err + } + + innerTxs = append(innerTxs, newInnerTx) + } + } + + return innerTxs, nil +} + // UpdateFacade will update the facade func (tg *transactionGroup) UpdateFacade(newFacade interface{}) error { if newFacade == nil { diff --git a/factory/processing/processComponents.go b/factory/processing/processComponents.go index 198e1a2d75a..e031a69040c 100644 --- a/factory/processing/processComponents.go +++ b/factory/processing/processComponents.go @@ -379,18 +379,8 @@ func (pcf *processComponentsFactory) Create() (*processComponents, error) { return nil, err } - argsRelayedTxV3Processor := transaction.ArgRelayedTxV3Processor{ - EconomicsFee: pcf.coreData.EconomicsData(), - ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), - MaxTransactionsAllowed: pcf.config.RelayedTransactionConfig.MaxTransactionsAllowed, - } - relayedTxV3Processor, err := transaction.NewRelayedTxV3Processor(argsRelayedTxV3Processor) - if err != nil { - return nil, err - } - pcf.txLogsProcessor = txLogsProcessor - genesisBlocks, initialTxs, err := pcf.generateGenesisHeadersAndApplyInitialBalances(relayedTxV3Processor) + genesisBlocks, initialTxs, err := pcf.generateGenesisHeadersAndApplyInitialBalances() if err != nil { return nil, err } @@ -526,6 +516,16 @@ func (pcf *processComponentsFactory) Create() (*processComponents, error) { return nil, err } + argsRelayedTxV3Processor := transaction.ArgRelayedTxV3Processor{ + EconomicsFee: pcf.coreData.EconomicsData(), + ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), + MaxTransactionsAllowed: pcf.config.RelayedTransactionConfig.MaxTransactionsAllowed, + } + relayedTxV3Processor, err := transaction.NewRelayedTxV3Processor(argsRelayedTxV3Processor) + if err != nil { + return nil, err + } + interceptorContainerFactory, blackListHandler, err := pcf.newInterceptorContainerFactory( headerSigVerifier, pcf.bootstrapComponents.HeaderIntegrityVerifier(), @@ -888,7 +888,7 @@ func (pcf *processComponentsFactory) newEpochStartTrigger(requestHandler epochSt return nil, errors.New("error creating new start of epoch trigger because of invalid shard id") } -func (pcf *processComponentsFactory) generateGenesisHeadersAndApplyInitialBalances(relayedTxV3Processor process.RelayedTxV3Processor) (map[uint32]data.HeaderHandler, map[uint32]*genesis.IndexingData, error) { +func (pcf *processComponentsFactory) generateGenesisHeadersAndApplyInitialBalances() (map[uint32]data.HeaderHandler, map[uint32]*genesis.IndexingData, error) { genesisVmConfig := pcf.config.VirtualMachine.Execution conversionBase := 10 genesisNodePrice, ok := big.NewInt(0).SetString(pcf.systemSCConfig.StakingSystemSCConfig.GenesisNodePrice, conversionBase) @@ -925,7 +925,6 @@ func (pcf *processComponentsFactory) generateGenesisHeadersAndApplyInitialBalanc GenesisEpoch: pcf.config.EpochStartConfig.GenesisEpoch, GenesisNonce: pcf.genesisNonce, GenesisRound: pcf.genesisRound, - RelayedTxV3Processor: relayedTxV3Processor, } gbc, err := processGenesis.NewGenesisBlockCreator(arg) diff --git a/genesis/process/argGenesisBlockCreator.go b/genesis/process/argGenesisBlockCreator.go index 1904dfb09e4..19b5fc9adcc 100644 --- a/genesis/process/argGenesisBlockCreator.go +++ b/genesis/process/argGenesisBlockCreator.go @@ -70,7 +70,6 @@ type ArgsGenesisBlockCreator struct { BlockSignKeyGen crypto.KeyGenerator HistoryRepository dblookupext.HistoryRepository TxExecutionOrderHandler common.TxExecutionOrderHandler - RelayedTxV3Processor process.RelayedTxV3Processor GenesisNodePrice *big.Int GenesisString string diff --git a/genesis/process/genesisBlockCreator_test.go b/genesis/process/genesisBlockCreator_test.go index 6dcf996cce6..b7b788f0d37 100644 --- a/genesis/process/genesisBlockCreator_test.go +++ b/genesis/process/genesisBlockCreator_test.go @@ -34,7 +34,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/genericMocks" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" - "github.com/multiversx/mx-chain-go/testscommon/processMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" storageCommon "github.com/multiversx/mx-chain-go/testscommon/storage" "github.com/multiversx/mx-chain-go/trie" @@ -192,7 +191,6 @@ func createMockArgument( return &block.Header{} }, }, - RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, } arg.ShardCoordinator = &mock.ShardCoordinatorMock{ diff --git a/genesis/process/shardGenesisBlockCreator.go b/genesis/process/shardGenesisBlockCreator.go index 0bd7d6cc8f5..35bc217110e 100644 --- a/genesis/process/shardGenesisBlockCreator.go +++ b/genesis/process/shardGenesisBlockCreator.go @@ -24,6 +24,7 @@ import ( "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/block/preprocess" "github.com/multiversx/mx-chain-go/process/coordinator" + processDisabled "github.com/multiversx/mx-chain-go/process/disabled" "github.com/multiversx/mx-chain-go/process/factory/shard" disabledGuardian "github.com/multiversx/mx-chain-go/process/guardian/disabled" "github.com/multiversx/mx-chain-go/process/receipts" @@ -564,7 +565,7 @@ func createProcessorsForShardGenesisBlock(arg ArgsGenesisBlockCreator, enableEpo TxVersionChecker: arg.Core.TxVersionChecker(), GuardianChecker: disabledGuardian.NewDisabledGuardedAccountHandler(), TxLogsProcessor: arg.TxLogsProcessor, - RelayedTxV3Processor: arg.RelayedTxV3Processor, + RelayedTxV3Processor: processDisabled.NewRelayedTxV3Processor(), } transactionProcessor, err := transaction.NewTxProcessor(argsNewTxProcessor) if err != nil { diff --git a/integrationTests/multiShard/hardFork/hardFork_test.go b/integrationTests/multiShard/hardFork/hardFork_test.go index a8c2b897a40..61dbada5251 100644 --- a/integrationTests/multiShard/hardFork/hardFork_test.go +++ b/integrationTests/multiShard/hardFork/hardFork_test.go @@ -28,7 +28,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" factoryTests "github.com/multiversx/mx-chain-go/testscommon/factory" "github.com/multiversx/mx-chain-go/testscommon/genesisMocks" - "github.com/multiversx/mx-chain-go/testscommon/processMocks" "github.com/multiversx/mx-chain-go/testscommon/statusHandler" "github.com/multiversx/mx-chain-go/update/factory" "github.com/multiversx/mx-chain-go/vm/systemSmartContracts/defaults" @@ -504,7 +503,6 @@ func hardForkImport( HeaderVersionConfigs: testscommon.GetDefaultHeaderVersionConfig(), HistoryRepository: &dblookupext.HistoryRepositoryStub{}, TxExecutionOrderHandler: &commonMocks.TxExecutionOrderHandlerStub{}, - RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, } genesisProcessor, err := process.NewGenesisBlockCreator(argsGenesis) diff --git a/integrationTests/multiShard/relayedTx/common.go b/integrationTests/multiShard/relayedTx/common.go index 9ef05df816e..5e9768a77ce 100644 --- a/integrationTests/multiShard/relayedTx/common.go +++ b/integrationTests/multiShard/relayedTx/common.go @@ -14,21 +14,11 @@ import ( ) // CreateGeneralSetupForRelayTxTest will create the general setup for relayed transactions -func CreateGeneralSetupForRelayTxTest() ([]*integrationTests.TestProcessorNode, []int, []*integrationTests.TestWalletAccount, *integrationTests.TestWalletAccount) { +func CreateGeneralSetupForRelayTxTest(intraShardPlayers bool) ([]*integrationTests.TestProcessorNode, []int, []*integrationTests.TestWalletAccount, *integrationTests.TestWalletAccount) { initialVal := big.NewInt(10000000000) nodes, idxProposers := createAndMintNodes(initialVal) - players, relayerAccount := createAndMintPlayers(false, nodes, initialVal) - - return nodes, idxProposers, players, relayerAccount -} - -// CreateGeneralSetupForRelayedV3TxTest will create the general setup for relayed transactions v3 -func CreateGeneralSetupForRelayedV3TxTest() ([]*integrationTests.TestProcessorNode, []int, []*integrationTests.TestWalletAccount, *integrationTests.TestWalletAccount) { - initialVal := big.NewInt(10000000000) - nodes, idxProposers := createAndMintNodes(initialVal) - - players, relayerAccount := createAndMintPlayers(true, nodes, initialVal) + players, relayerAccount := createAndMintPlayers(intraShardPlayers, nodes, initialVal) return nodes, idxProposers, players, relayerAccount } diff --git a/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go b/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go index 6adf254433b..e2e6a3be043 100644 --- a/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go +++ b/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go @@ -18,7 +18,7 @@ func TestRelayedTransactionInMultiShardEnvironmentWithNormalTxButWrongNonceShoul t.Skip("this is not a short test") } - nodes, idxProposers, players, relayer := relayedTx.CreateGeneralSetupForRelayTxTest() + nodes, idxProposers, players, relayer := relayedTx.CreateGeneralSetupForRelayTxTest(false) defer func() { for _, n := range nodes { n.Close() @@ -81,7 +81,7 @@ func TestRelayedTransactionInMultiShardEnvironmentWithNormalTxButWithTooMuchGas( t.Skip("this is not a short test") } - nodes, idxProposers, players, relayer := relayedTx.CreateGeneralSetupForRelayTxTest() + nodes, idxProposers, players, relayer := relayedTx.CreateGeneralSetupForRelayTxTest(false) defer func() { for _, n := range nodes { n.Close() diff --git a/integrationTests/multiShard/relayedTx/relayedTx_test.go b/integrationTests/multiShard/relayedTx/relayedTx_test.go index 2ba26a73d13..d9ea772d7ba 100644 --- a/integrationTests/multiShard/relayedTx/relayedTx_test.go +++ b/integrationTests/multiShard/relayedTx/relayedTx_test.go @@ -62,7 +62,7 @@ func testRelayedTransactionInMultiShardEnvironmentWithNormalTx( t.Skip("this is not a short test") } - nodes, idxProposers, players, relayer := createSetupForTest(relayedV3Test) + nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest(relayedV3Test) defer func() { for _, n := range nodes { n.Close() @@ -126,7 +126,7 @@ func testRelayedTransactionInMultiShardEnvironmentWithSmartContractTX( t.Skip("this is not a short test") } - nodes, idxProposers, players, relayer := createSetupForTest(relayedV3Test) + nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest(relayedV3Test) defer func() { for _, n := range nodes { n.Close() @@ -222,7 +222,7 @@ func testRelayedTransactionInMultiShardEnvironmentWithESDTTX( t.Skip("this is not a short test") } - nodes, idxProposers, players, relayer := createSetupForTest(relayedV3Test) + nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest(relayedV3Test) defer func() { for _, n := range nodes { n.Close() @@ -320,7 +320,7 @@ func testRelayedTransactionInMultiShardEnvironmentWithAttestationContract( t.Skip("this is not a short test") } - nodes, idxProposers, players, relayer := createSetupForTest(relayedV3Test) + nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest(relayedV3Test) defer func() { for _, n := range nodes { n.Close() @@ -413,14 +413,6 @@ func testRelayedTransactionInMultiShardEnvironmentWithAttestationContract( } } -func createSetupForTest(relayedV3Test bool) ([]*integrationTests.TestProcessorNode, []int, []*integrationTests.TestWalletAccount, *integrationTests.TestWalletAccount) { - if relayedV3Test { - return CreateGeneralSetupForRelayedV3TxTest() - } - - return CreateGeneralSetupForRelayTxTest() -} - func checkAttestedPublicKeys( t *testing.T, node *integrationTests.TestProcessorNode, diff --git a/integrationTests/testInitializer.go b/integrationTests/testInitializer.go index be69ce4a7ec..ca5c97df80c 100644 --- a/integrationTests/testInitializer.go +++ b/integrationTests/testInitializer.go @@ -744,7 +744,6 @@ func CreateFullGenesisBlocks( HeaderVersionConfigs: testscommon.GetDefaultHeaderVersionConfig(), HistoryRepository: &dblookupext.HistoryRepositoryStub{}, TxExecutionOrderHandler: &commonMocks.TxExecutionOrderHandlerStub{}, - RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, } genesisProcessor, _ := genesisProcess.NewGenesisBlockCreator(argsGenesis) @@ -861,7 +860,6 @@ func CreateGenesisMetaBlock( HeaderVersionConfigs: testscommon.GetDefaultHeaderVersionConfig(), HistoryRepository: &dblookupext.HistoryRepositoryStub{}, TxExecutionOrderHandler: &commonMocks.TxExecutionOrderHandlerStub{}, - RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, } if shardCoordinator.SelfId() != core.MetachainShardId { diff --git a/process/errors.go b/process/errors.go index 1f32d6b686c..9c6c5240cb1 100644 --- a/process/errors.go +++ b/process/errors.go @@ -1242,9 +1242,6 @@ var ErrRelayedTxV3Disabled = errors.New("relayed tx v3 is disabled") // ErrRelayedTxV3ZeroVal signals that the v3 version of relayed tx should be created with 0 as value var ErrRelayedTxV3ZeroVal = errors.New("relayed tx v3 value should be 0") -// ErrRelayedTxV3EmptyRelayer signals that the inner tx of the relayed v3 does not have a relayer address set -var ErrRelayedTxV3EmptyRelayer = errors.New("empty relayer on inner tx of relayed tx v3") - // ErrRelayedTxV3RelayerMismatch signals that the relayer address of the inner tx does not match the real relayer var ErrRelayedTxV3RelayerMismatch = errors.New("relayed tx v3 relayer mismatch") @@ -1265,3 +1262,6 @@ var ErrRelayedTxV3TooManyInnerTransactions = errors.New("too many inner transact // ErrConsumedFeesMismatch signals that the fees consumed from relayer do not match the inner transactions fees var ErrConsumedFeesMismatch = errors.New("consumed fees mismatch") + +// ErrRelayedTxV3InvalidDataField signals that the data field is invalid +var ErrRelayedTxV3InvalidDataField = errors.New("invalid data field") diff --git a/process/transaction/interceptedTransaction_test.go b/process/transaction/interceptedTransaction_test.go index 983028e3ae1..4b762fa9a17 100644 --- a/process/transaction/interceptedTransaction_test.go +++ b/process/transaction/interceptedTransaction_test.go @@ -1713,17 +1713,17 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { err := txi.CheckValidity() assert.Nil(t, err) }) - t.Run("empty relayer on inner tx should error", func(t *testing.T) { + t.Run("inner txs on inner tx should error", func(t *testing.T) { t.Parallel() txCopy := *tx innerTxCopy := *innerTx - innerTxCopy.RelayerAddr = nil + innerTxCopy.InnerTransactions = []*dataTransaction.Transaction{{}} txCopy.InnerTransactions = []*dataTransaction.Transaction{&innerTxCopy} txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) err := txi.CheckValidity() - assert.Equal(t, process.ErrRelayedTxV3EmptyRelayer, err) + assert.Equal(t, process.ErrRecursiveRelayedTxIsNotAllowed, err) }) t.Run("different relayer on inner tx should error", func(t *testing.T) { t.Parallel() diff --git a/process/transaction/relayedTxV3Processor.go b/process/transaction/relayedTxV3Processor.go index e46db781cf6..099bace7a8c 100644 --- a/process/transaction/relayedTxV3Processor.go +++ b/process/transaction/relayedTxV3Processor.go @@ -5,6 +5,7 @@ import ( "fmt" "math/big" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/process" @@ -67,18 +68,21 @@ func (proc *relayedTxV3Processor) CheckRelayedTx(tx *transaction.Transaction) er if tx.GasLimit < proc.computeRelayedTxMinGasLimit(tx) { return process.ErrRelayedTxV3GasLimitMismatch } + if len(tx.Data) > 0 { + return process.ErrRelayedTxV3InvalidDataField + } innerTxs := tx.InnerTransactions for _, innerTx := range innerTxs { - if len(innerTx.RelayerAddr) == 0 { - return process.ErrRelayedTxV3EmptyRelayer - } if !bytes.Equal(innerTx.RelayerAddr, tx.SndAddr) { return process.ErrRelayedTxV3RelayerMismatch } if tx.GasPrice != innerTx.GasPrice { return process.ErrRelayedV3GasPriceMismatch } + if len(innerTx.InnerTransactions) > 0 { + return process.ErrRecursiveRelayedTxIsNotAllowed + } senderShard := proc.shardCoordinator.ComputeId(innerTx.SndAddr) relayerShard := proc.shardCoordinator.ComputeId(innerTx.RelayerAddr) @@ -94,8 +98,12 @@ func (proc *relayedTxV3Processor) CheckRelayedTx(tx *transaction.Transaction) er func (proc *relayedTxV3Processor) ComputeRelayedTxFees(tx *transaction.Transaction) (*big.Int, *big.Int) { feesForInnerTxs := proc.getTotalFeesRequiredForInnerTxs(tx.InnerTransactions) - relayerMoveBalanceFee := proc.economicsFee.ComputeMoveBalanceFee(tx) - relayerFee := big.NewInt(0).Mul(relayerMoveBalanceFee, big.NewInt(int64(len(tx.InnerTransactions)))) + relayerUnguardedMoveBalanceFee := core.SafeMul(proc.economicsFee.GasPriceForMove(tx), proc.economicsFee.MinGasLimit()) + relayerTotalMoveBalanceFee := proc.economicsFee.ComputeMoveBalanceFee(tx) + relayerMoveBalanceFeeDiff := big.NewInt(0).Sub(relayerTotalMoveBalanceFee, relayerUnguardedMoveBalanceFee) + + relayerFee := big.NewInt(0).Mul(relayerUnguardedMoveBalanceFee, big.NewInt(int64(len(tx.InnerTransactions)))) + relayerFee.Add(relayerFee, relayerMoveBalanceFeeDiff) // add the difference in case of guarded relayed tx totalFee := big.NewInt(0).Add(relayerFee, feesForInnerTxs) @@ -118,8 +126,10 @@ func (proc *relayedTxV3Processor) getTotalFeesRequiredForInnerTxs(innerTxs []*tr func (proc *relayedTxV3Processor) computeRelayedTxMinGasLimit(tx *transaction.Transaction) uint64 { relayedTxGasLimit := proc.economicsFee.ComputeGasLimit(tx) + relayedTxMinGasLimit := proc.economicsFee.MinGasLimit() + relayedTxGasLimitDiff := relayedTxGasLimit - relayedTxMinGasLimit // this may be positive if the relayed tx is guarded - totalGasLimit := relayedTxGasLimit * uint64(len(tx.InnerTransactions)) + totalGasLimit := relayedTxGasLimitDiff + relayedTxMinGasLimit*uint64(len(tx.InnerTransactions)) for _, innerTx := range tx.InnerTransactions { totalGasLimit += innerTx.GasLimit } diff --git a/process/transaction/relayedTxV3Processor_test.go b/process/transaction/relayedTxV3Processor_test.go index ed0de081bb4..01d298b5de4 100644 --- a/process/transaction/relayedTxV3Processor_test.go +++ b/process/transaction/relayedTxV3Processor_test.go @@ -16,7 +16,10 @@ import ( "github.com/stretchr/testify/require" ) -const minGasLimit = uint64(1) +const ( + minGasLimit = uint64(1) + guardedTxExtraGas = uint64(10) +) func getDefaultTx() *coreTransaction.Transaction { return &coreTransaction.Transaction{ @@ -168,17 +171,29 @@ func TestRelayedTxV3Processor_CheckRelayedTx(t *testing.T) { err = proc.CheckRelayedTx(tx) require.Equal(t, process.ErrRelayedTxV3GasLimitMismatch, err) }) - t.Run("empty relayer on inner should error", func(t *testing.T) { + t.Run("data field not empty should error", func(t *testing.T) { t.Parallel() proc, err := transaction.NewRelayedTxV3Processor(createMockArgRelayedTxV3Processor()) require.NoError(t, err) tx := getDefaultTx() - tx.InnerTransactions[0].RelayerAddr = []byte("") + tx.Data = []byte("dummy") err = proc.CheckRelayedTx(tx) - require.Equal(t, process.ErrRelayedTxV3EmptyRelayer, err) + require.Equal(t, process.ErrRelayedTxV3InvalidDataField, err) + }) + t.Run("inner txs on inner should error", func(t *testing.T) { + t.Parallel() + + proc, err := transaction.NewRelayedTxV3Processor(createMockArgRelayedTxV3Processor()) + require.NoError(t, err) + + tx := getDefaultTx() + tx.InnerTransactions[0].InnerTransactions = []*coreTransaction.Transaction{{}} + + err = proc.CheckRelayedTx(tx) + require.Equal(t, process.ErrRecursiveRelayedTxIsNotAllowed, err) }) t.Run("relayer mismatch on inner should error", func(t *testing.T) { t.Parallel() @@ -239,18 +254,61 @@ func TestRelayedTxV3Processor_CheckRelayedTx(t *testing.T) { func TestRelayedTxV3Processor_ComputeRelayedTxFees(t *testing.T) { t.Parallel() - args := createMockArgRelayedTxV3Processor() - args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ - ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { - return big.NewInt(int64(minGasLimit * tx.GetGasPrice())) - }, - } - proc, err := transaction.NewRelayedTxV3Processor(args) - require.NoError(t, err) - - tx := getDefaultTx() - relayerFee, totalFee := proc.ComputeRelayedTxFees(tx) - expectedRelayerFee := big.NewInt(int64(2 * minGasLimit * tx.GetGasPrice())) // 2 move balance - require.Equal(t, expectedRelayerFee, relayerFee) - require.Equal(t, big.NewInt(int64(tx.GetGasLimit()*tx.GetGasPrice())), totalFee) + t.Run("should work unguarded", func(t *testing.T) { + t.Parallel() + + args := createMockArgRelayedTxV3Processor() + args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ + ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { + return big.NewInt(int64(minGasLimit * tx.GetGasPrice())) + }, + MinGasLimitCalled: func() uint64 { + return minGasLimit + }, + GasPriceForMoveCalled: func(tx data.TransactionWithFeeHandler) uint64 { + return tx.GetGasPrice() + }, + } + proc, err := transaction.NewRelayedTxV3Processor(args) + require.NoError(t, err) + + tx := getDefaultTx() + relayerFee, totalFee := proc.ComputeRelayedTxFees(tx) + expectedRelayerFee := big.NewInt(int64(2 * minGasLimit * tx.GetGasPrice())) // 2 move balance + require.Equal(t, expectedRelayerFee, relayerFee) + require.Equal(t, big.NewInt(int64(tx.GetGasLimit()*tx.GetGasPrice())), totalFee) + }) + t.Run("should work guarded", func(t *testing.T) { + t.Parallel() + + args := createMockArgRelayedTxV3Processor() + args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ + ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { + txHandler, ok := tx.(data.TransactionHandler) + require.True(t, ok) + + if len(txHandler.GetUserTransactions()) == 0 { // inner tx + return big.NewInt(int64(minGasLimit * tx.GetGasPrice())) + } + + // relayed tx + return big.NewInt(int64(minGasLimit*tx.GetGasPrice() + guardedTxExtraGas*tx.GetGasPrice())) + }, + MinGasLimitCalled: func() uint64 { + return minGasLimit + }, + GasPriceForMoveCalled: func(tx data.TransactionWithFeeHandler) uint64 { + return tx.GetGasPrice() + }, + } + proc, err := transaction.NewRelayedTxV3Processor(args) + require.NoError(t, err) + + tx := getDefaultTx() + tx.GasLimit += guardedTxExtraGas + relayerFee, totalFee := proc.ComputeRelayedTxFees(tx) + expectedRelayerFee := big.NewInt(int64(2*minGasLimit*tx.GetGasPrice() + guardedTxExtraGas*tx.GetGasPrice())) // 2 move balance + require.Equal(t, expectedRelayerFee, relayerFee) + require.Equal(t, big.NewInt(int64(tx.GetGasLimit()*tx.GetGasPrice())), totalFee) + }) } diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 0990335ee2a..eb9d85c7259 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -304,7 +304,7 @@ func (txProc *txProcessor) executingFailedTransaction( return nil } - txFee := txProc.computeTxFee(tx) + txFee := txProc.economicsFee.ComputeTxFee(tx) err := acntSnd.SubFromBalance(txFee) if err != nil { return err diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index 6114e57ee0b..7b14c0732c7 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -1641,7 +1641,7 @@ func TestTxProcessor_ProcessTransactionShouldTreatAsInvalidTxIfTxTypeIsWrong(t * _, err := execTx.ProcessTransaction(&tx) assert.Equal(t, err, process.ErrFailedTransaction) assert.Equal(t, uint64(1), acntSrc.GetNonce()) - assert.Equal(t, uint64(46), acntSrc.GetBalance().Uint64()) + assert.Equal(t, uint64(45), acntSrc.GetBalance().Uint64()) } func TestTxProcessor_ProcessRelayedTransactionV2NotActiveShouldErr(t *testing.T) { From 443c7d139651c5a9de80366ae614f8540bd240ec Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 6 Jun 2024 13:38:17 +0300 Subject: [PATCH 310/503] scenario 9 - use changeToDynamic --- .../vm/esdtImprovements_test.go | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index d128fb6c4c3..c5d8a5edfba 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -259,6 +259,9 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran log.Info("Step 4. check that the metadata for all tokens is saved on the system account") + err = cs.GenerateBlocks(10) + require.Nil(t, err) + shardID = cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[1].Bytes) checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) @@ -283,6 +286,9 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran log.Info("Step 6. check that the metadata for all tokens is saved on the system account") + err = cs.GenerateBlocks(10) + require.Nil(t, err) + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData) checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) @@ -305,6 +311,9 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran log.Info("Step 8. check that the metaData for the NFT was removed from the system account and moved to the user account") + err = cs.GenerateBlocks(10) + require.Nil(t, err) + shardID = cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[2].Bytes) checkMetaData(t, cs, addrs[2].Bytes, nftTokenID, shardID, nftMetaData) @@ -533,6 +542,23 @@ func issueSemiFungibleTx(nonce uint64, sndAdr []byte, ticker []byte, baseIssuing } } +func changeToDynamicTx(nonce uint64, sndAdr []byte, tokenID []byte) *transaction.Transaction { + txDataField := []byte("changeToDynamic@" + hex.EncodeToString(tokenID)) + + return &transaction.Transaction{ + Nonce: nonce, + SndAddr: sndAdr, + RcvAddr: vm.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } +} + func updateTokenIDTx(nonce uint64, sndAdr []byte, tokenID []byte) *transaction.Transaction { txDataField := []byte("updateTokenID@" + hex.EncodeToString(tokenID)) @@ -1591,7 +1617,7 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { addrs := createAddresses(t, cs, true) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch) - 1) + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) require.Nil(t, err) err = cs.GenerateBlocks(10) @@ -1613,42 +1639,6 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { } nftTokenID := txResult.Logs.Events[0].Topics[0] - - tokenType := core.DynamicNFTESDT - - txDataField := bytes.Join( - [][]byte{ - []byte(core.ESDTSetTokenType), - []byte(hex.EncodeToString(nftTokenID)), - []byte(hex.EncodeToString([]byte(tokenType))), - }, - []byte("@"), - ) - - tx = &transaction.Transaction{ - Nonce: 0, - SndAddr: core.ESDTSCAddress, - RcvAddr: core.SystemAccountAddress, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, - } - - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - - fmt.Println(txResult) - fmt.Println(txResult.Logs.Events[0]) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - - require.Equal(t, "success", txResult.Status.String()) - setAddressEsdtRoles(t, cs, addrs[1], nftTokenID, roles) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) @@ -1670,11 +1660,21 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[1].Bytes) + tx = changeToDynamicTx(2, addrs[1].Bytes, nftTokenID) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) log.Info("Step 2. Send the NFT cross shard") - tx = esdtNFTTransferTx(2, addrs[1].Bytes, addrs[2].Bytes, nftTokenID) + tx = esdtNFTTransferTx(3, addrs[1].Bytes, addrs[2].Bytes, nftTokenID) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) From afb964368d25ae3284f908bc3f9106f925c6215c Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 6 Jun 2024 13:50:39 +0300 Subject: [PATCH 311/503] fix keys reference --- integrationTests/chainSimulator/vm/esdtImprovements_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index c5d8a5edfba..23e69e9955a 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -678,7 +678,7 @@ func setAddressEsdtRoles( { Address: address.Bech32, Balance: "10000000000000000000000", - Keys: keys, + Pairs: keys, }, }) require.Nil(t, err) From 551c28ea0591b7e7b96a62c5b8453ae1c2b3c01a Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 6 Jun 2024 13:53:56 +0300 Subject: [PATCH 312/503] scenario 9 - create token before activation --- .../chainSimulator/vm/esdtImprovements_test.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 23e69e9955a..9657e90536c 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -1585,7 +1585,7 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { Value: 20, } - activationEpoch := uint32(2) + activationEpoch := uint32(4) baseIssuingCost := "1000" @@ -1617,10 +1617,7 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { addrs := createAddresses(t, cs, true) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) - require.Nil(t, err) - - err = cs.GenerateBlocks(10) + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch) - 2) require.Nil(t, err) log.Info("Initial setup: Create NFT") @@ -1653,7 +1650,7 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - err = cs.GenerateBlocks(10) + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) require.Nil(t, err) log.Info("Step 1. Change the nft to DYNAMIC type - the metadata should be on the system account") From 6e3ff41aeb0e56419e3dbded0f1cfb292dd89cae Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 6 Jun 2024 14:35:06 +0300 Subject: [PATCH 313/503] fixes after branch update --- integrationTests/testProcessorNode.go | 2 -- process/errors.go | 3 ++ .../interceptedTransaction_test.go | 1 - process/transaction/relayedTxV3Processor.go | 12 -------- .../transaction/relayedTxV3Processor_test.go | 30 ------------------- process/transaction/shardProcess_test.go | 4 --- 6 files changed, 3 insertions(+), 49 deletions(-) diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index 40472ae3576..49ef2206b41 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -1291,7 +1291,6 @@ func (tpn *TestProcessorNode) initInterceptors(heartbeatPk string) { relayedV3TxProcessor, _ := transaction.NewRelayedTxV3Processor(transaction.ArgRelayedTxV3Processor{ EconomicsFee: tpn.EconomicsData, ShardCoordinator: tpn.ShardCoordinator, - ArgsParser: smartContract.NewArgumentParser(), MaxTransactionsAllowed: 10, }) @@ -1729,7 +1728,6 @@ func (tpn *TestProcessorNode) initInnerProcessors(gasMap map[string]map[string]u relayedV3TxProcessor, _ := transaction.NewRelayedTxV3Processor(transaction.ArgRelayedTxV3Processor{ EconomicsFee: tpn.EconomicsData, ShardCoordinator: tpn.ShardCoordinator, - ArgsParser: smartContract.NewArgumentParser(), MaxTransactionsAllowed: 10, }) diff --git a/process/errors.go b/process/errors.go index 9c6c5240cb1..7e585f6725c 100644 --- a/process/errors.go +++ b/process/errors.go @@ -1265,3 +1265,6 @@ var ErrConsumedFeesMismatch = errors.New("consumed fees mismatch") // ErrRelayedTxV3InvalidDataField signals that the data field is invalid var ErrRelayedTxV3InvalidDataField = errors.New("invalid data field") + +// ErrMultipleRelayedTxTypesIsNotAllowed signals that multiple types of relayed tx is not allowed +var ErrMultipleRelayedTxTypesIsNotAllowed = errors.New("multiple relayed tx types is not allowed") diff --git a/process/transaction/interceptedTransaction_test.go b/process/transaction/interceptedTransaction_test.go index 0f58e3950df..e2494cd71d7 100644 --- a/process/transaction/interceptedTransaction_test.go +++ b/process/transaction/interceptedTransaction_test.go @@ -202,7 +202,6 @@ func createInterceptedTxFromPlainTxWithArgParser(tx *dataTransaction.Transaction relayedTxV3Processor, err := transaction.NewRelayedTxV3Processor(transaction.ArgRelayedTxV3Processor{ EconomicsFee: txFeeHandler, ShardCoordinator: shardCoordinator, - ArgsParser: &mock.ArgumentParserMock{}, MaxTransactionsAllowed: 10, }) if err != nil { diff --git a/process/transaction/relayedTxV3Processor.go b/process/transaction/relayedTxV3Processor.go index 0b2eb18ac55..099bace7a8c 100644 --- a/process/transaction/relayedTxV3Processor.go +++ b/process/transaction/relayedTxV3Processor.go @@ -18,14 +18,12 @@ const minTransactionsAllowed = 1 type ArgRelayedTxV3Processor struct { EconomicsFee process.FeeHandler ShardCoordinator sharding.Coordinator - ArgsParser process.ArgumentsParser MaxTransactionsAllowed int } type relayedTxV3Processor struct { economicsFee process.FeeHandler shardCoordinator sharding.Coordinator - argsParser process.ArgumentsParser maxTransactionsAllowed int } @@ -39,7 +37,6 @@ func NewRelayedTxV3Processor(args ArgRelayedTxV3Processor) (*relayedTxV3Processo economicsFee: args.EconomicsFee, shardCoordinator: args.ShardCoordinator, maxTransactionsAllowed: args.MaxTransactionsAllowed, - argsParser: args.ArgsParser, }, nil } @@ -50,9 +47,6 @@ func checkArgs(args ArgRelayedTxV3Processor) error { if check.IfNil(args.ShardCoordinator) { return process.ErrNilShardCoordinator } - if check.IfNil(args.ArgsParser) { - return process.ErrNilArgumentParser - } if args.MaxTransactionsAllowed < minTransactionsAllowed { return fmt.Errorf("%w for MaxTransactionsAllowed, provided %d, min expected %d", process.ErrInvalidValue, args.MaxTransactionsAllowed, minTransactionsAllowed) } @@ -71,12 +65,6 @@ func (proc *relayedTxV3Processor) CheckRelayedTx(tx *transaction.Transaction) er if !bytes.Equal(tx.RcvAddr, tx.SndAddr) { return process.ErrRelayedTxV3SenderDoesNotMatchReceiver } - if len(tx.Data) > 0 { - funcName, _, err := proc.argsParser.ParseCallData(string(tx.Data)) - if err == nil && isRelayedTx(funcName) { - return process.ErrMultipleRelayedTxTypesIsNotAllowed - } - } if tx.GasLimit < proc.computeRelayedTxMinGasLimit(tx) { return process.ErrRelayedTxV3GasLimitMismatch } diff --git a/process/transaction/relayedTxV3Processor_test.go b/process/transaction/relayedTxV3Processor_test.go index 725c5dad8e5..01d298b5de4 100644 --- a/process/transaction/relayedTxV3Processor_test.go +++ b/process/transaction/relayedTxV3Processor_test.go @@ -10,7 +10,6 @@ import ( "github.com/multiversx/mx-chain-core-go/data" coreTransaction "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/process" - "github.com/multiversx/mx-chain-go/process/mock" "github.com/multiversx/mx-chain-go/process/transaction" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/economicsmocks" @@ -57,7 +56,6 @@ func createMockArgRelayedTxV3Processor() transaction.ArgRelayedTxV3Processor { return transaction.ArgRelayedTxV3Processor{ EconomicsFee: &economicsmocks.EconomicsHandlerStub{}, ShardCoordinator: &testscommon.ShardsCoordinatorMock{}, - ArgsParser: &mock.ArgumentParserMock{}, MaxTransactionsAllowed: 10, } } @@ -83,15 +81,6 @@ func TestNewRelayedTxV3Processor(t *testing.T) { require.Nil(t, proc) require.Equal(t, process.ErrNilShardCoordinator, err) }) - t.Run("nil args parser should error", func(t *testing.T) { - t.Parallel() - - args := createMockArgRelayedTxV3Processor() - args.ArgsParser = nil - proc, err := transaction.NewRelayedTxV3Processor(args) - require.Nil(t, proc) - require.Equal(t, process.ErrNilArgumentParser, err) - }) t.Run("invalid max transactions allowed should error", func(t *testing.T) { t.Parallel() @@ -164,25 +153,6 @@ func TestRelayedTxV3Processor_CheckRelayedTx(t *testing.T) { err = proc.CheckRelayedTx(tx) require.Equal(t, process.ErrRelayedTxV3SenderDoesNotMatchReceiver, err) }) - t.Run("multiple relayed txs should error", func(t *testing.T) { - t.Parallel() - - args := createMockArgRelayedTxV3Processor() - args.ArgsParser = &mock.ArgumentParserMock{ - ParseCallDataCalled: func(data string) (string, [][]byte, error) { - splitData := strings.Split(data, "@") - return splitData[0], nil, nil - }, - } - proc, err := transaction.NewRelayedTxV3Processor(args) - require.NoError(t, err) - - tx := getDefaultTx() - tx.Data = []byte("relayedTx@asd") - - err = proc.CheckRelayedTx(tx) - require.Equal(t, process.ErrMultipleRelayedTxTypesIsNotAllowed, err) - }) t.Run("invalid gas limit should error", func(t *testing.T) { t.Parallel() diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index 8c6fde7f4a8..2f19983bdcb 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -2235,7 +2235,6 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(txproc.ArgRelayedTxV3Processor{ EconomicsFee: args.EconomicsFee, ShardCoordinator: args.ShardCoordinator, - ArgsParser: &mock.ArgumentParserMock{}, MaxTransactionsAllowed: 10, }) logs := make([]*vmcommon.LogEntry, 0) @@ -2350,7 +2349,6 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(txproc.ArgRelayedTxV3Processor{ EconomicsFee: args.EconomicsFee, ShardCoordinator: args.ShardCoordinator, - ArgsParser: &mock.ArgumentParserMock{}, MaxTransactionsAllowed: 10, }) execTx, _ := txproc.NewTxProcessor(args) @@ -2417,7 +2415,6 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(txproc.ArgRelayedTxV3Processor{ EconomicsFee: args.EconomicsFee, ShardCoordinator: args.ShardCoordinator, - ArgsParser: &mock.ArgumentParserMock{}, MaxTransactionsAllowed: 10, }) execTx, _ := txproc.NewTxProcessor(args) @@ -2528,7 +2525,6 @@ func testProcessRelayedTransactionV3( args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(txproc.ArgRelayedTxV3Processor{ EconomicsFee: args.EconomicsFee, ShardCoordinator: args.ShardCoordinator, - ArgsParser: &mock.ArgumentParserMock{}, MaxTransactionsAllowed: 10, }) From 98480bf84186c423038838abebbc68e32f73d189 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 6 Jun 2024 14:49:54 +0300 Subject: [PATCH 314/503] scenario 6 - create nft token before activation --- .../vm/esdtImprovements_test.go | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 9657e90536c..f7586cf3409 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -3,7 +3,6 @@ package vm import ( "bytes" "encoding/hex" - "fmt" "math/big" "testing" "time" @@ -1159,7 +1158,7 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { Value: 20, } - activationEpoch := uint32(2) + activationEpoch := uint32(4) baseIssuingCost := "1000" @@ -1196,7 +1195,7 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { address, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) require.Nil(t, err) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch) - 2) require.Nil(t, err) err = cs.GenerateBlocks(10) @@ -1233,6 +1232,19 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + log.Info("Change to DYNAMIC type") + + tx = changeToDynamicTx(2, address.Bytes, nftTokenID) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + log.Info("Call ESDTModifyCreator and check that the creator was modified") newCreatorAddress, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) @@ -1272,14 +1284,9 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(txResult.Logs.Events[0]) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) - retrievedMetaData := getMetaDataFromAcc(t, cs, address.Bytes, nftTokenID, shardID) + retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) require.Equal(t, newCreatorAddress.Bytes, retrievedMetaData.Creator) } @@ -1662,6 +1669,7 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) err = cs.GenerateBlocks(10) From a3556df3a89ce7950ce0840e93c56a1a32c0e679 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 6 Jun 2024 16:01:07 +0300 Subject: [PATCH 315/503] added cross shard with multi transfer test --- integrationTests/chainSimulator/vm/esdtImprovements_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index f7586cf3409..008844e3ddc 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -66,6 +66,10 @@ func TestChainSimulator_CheckTokensMetadata_TransferTokens(t *testing.T) { t.Run("transfer and check all tokens - cross shard", func(t *testing.T) { transferAndCheckTokensMetaData(t, true, false) }) + + t.Run("transfer and check all tokens - cross shard - multi transfer", func(t *testing.T) { + transferAndCheckTokensMetaData(t, true, true) + }) } func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTransfer bool) { From 14f4e0fb84afda4a46688b8da0d3179e0c02a752 Mon Sep 17 00:00:00 2001 From: radu chis Date: Fri, 7 Jun 2024 11:28:56 +0300 Subject: [PATCH 316/503] fixed error on withKeys --- node/node.go | 4 ++++ node/node_test.go | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/node/node.go b/node/node.go index 992cba53768..a0ee8978ab8 100644 --- a/node/node.go +++ b/node/node.go @@ -960,6 +960,10 @@ func (n *Node) GetAccountWithKeys(address string, options api.AccountQueryOption return api.AccountResponse{}, api.BlockInfo{}, err } + if accInfo.account == nil { + return accInfo.accountResponse, accInfo.block, nil + } + var keys map[string]string if options.WithKeys { keys, err = n.getKeys(accInfo.account, ctx) diff --git a/node/node_test.go b/node/node_test.go index d2c19011830..e779776c14f 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -3536,6 +3536,28 @@ func TestNode_GetAccountAccountWithKeysShouldWork(t *testing.T) { require.Equal(t, hex.EncodeToString(v2), recovAccnt.Pairs[hex.EncodeToString(k2)]) } +func TestNode_GetAccountAccountWithKeysNeverUsedAccountShouldWork(t *testing.T) { + t.Parallel() + + accDB := &stateMock.AccountsStub{ + GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { + return nil, nil, nil + }, + RecreateTrieCalled: func(options common.RootHashHolder) error { + return nil + }, + } + + n := getNodeWithAccount(accDB) + + recovAccnt, blockInfo, err := n.GetAccountWithKeys(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: true}, context.Background()) + + require.Nil(t, err) + require.Equal(t, uint64(0), recovAccnt.Nonce) + require.Equal(t, testscommon.TestAddressBob, recovAccnt.Address) + require.Equal(t, api.BlockInfo{}, blockInfo) +} + func getNodeWithAccount(accDB *stateMock.AccountsStub) *node.Node { coreComponents := getDefaultCoreComponents() dataComponents := getDefaultDataComponents() From 3dc4427bd26d4743ffadb42bd5e687ece04f2123 Mon Sep 17 00:00:00 2001 From: radu chis Date: Fri, 7 Jun 2024 15:20:10 +0300 Subject: [PATCH 317/503] fixed error also when data trie is nil --- node/node.go | 2 +- node/node_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/node/node.go b/node/node.go index a0ee8978ab8..fb485671350 100644 --- a/node/node.go +++ b/node/node.go @@ -960,7 +960,7 @@ func (n *Node) GetAccountWithKeys(address string, options api.AccountQueryOption return api.AccountResponse{}, api.BlockInfo{}, err } - if accInfo.account == nil { + if accInfo.account == nil || accInfo.account.DataTrie() == nil { return accInfo.accountResponse, accInfo.block, nil } diff --git a/node/node_test.go b/node/node_test.go index e779776c14f..5982c2d4383 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -3558,6 +3558,32 @@ func TestNode_GetAccountAccountWithKeysNeverUsedAccountShouldWork(t *testing.T) require.Equal(t, api.BlockInfo{}, blockInfo) } +func TestNode_GetAccountAccountWithKeysNilDataTrieShouldWork(t *testing.T) { + t.Parallel() + + accnt := createAcc(testscommon.TestPubKeyBob) + accnt.SetDataTrie(nil) + _ = accnt.AddToBalance(big.NewInt(1)) + + accDB := &stateMock.AccountsStub{ + GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { + return accnt, nil, nil + }, + RecreateTrieCalled: func(options common.RootHashHolder) error { + return nil + }, + } + + n := getNodeWithAccount(accDB) + + recovAccnt, blockInfo, err := n.GetAccountWithKeys(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: true}, context.Background()) + + require.Nil(t, err) + require.Equal(t, uint64(0), recovAccnt.Nonce) + require.Equal(t, testscommon.TestAddressBob, recovAccnt.Address) + require.Equal(t, api.BlockInfo{}, blockInfo) +} + func getNodeWithAccount(accDB *stateMock.AccountsStub) *node.Node { coreComponents := getDefaultCoreComponents() dataComponents := getDefaultDataComponents() From 300fd32c032a696c49488c65cbc76665eeb95f48 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Fri, 7 Jun 2024 17:41:39 +0300 Subject: [PATCH 318/503] added nft token api type integration test --- .../chainSimulator/vm/esdtTokens_test.go | 188 ++++++++++++++++++ 1 file changed, 188 insertions(+) diff --git a/integrationTests/chainSimulator/vm/esdtTokens_test.go b/integrationTests/chainSimulator/vm/esdtTokens_test.go index ca70d98d7bc..c80615cf9e0 100644 --- a/integrationTests/chainSimulator/vm/esdtTokens_test.go +++ b/integrationTests/chainSimulator/vm/esdtTokens_test.go @@ -195,6 +195,194 @@ func TestChainSimulator_Api_TokenType(t *testing.T) { require.Equal(t, core.SemiFungibleESDT, tokenData.Type) } +func TestChainSimulator_Api_NFTToken(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(2) + + baseIssuingCost := "1000" + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewFreePortAPIConfigurator("localhost"), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + mintValue := big.NewInt(10) + mintValue = mintValue.Mul(oneEGLD, mintValue) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch) - 1) + require.Nil(t, err) + + log.Info("Initial setup: Create NFT token before activation") + + addrs := createAddresses(t, cs, false) + + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + } + + // issue NFT + nftTicker := []byte("NFTTICKER") + tx := issueNonFungibleTx(0, addrs[0].Bytes, nftTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(5) + require.Nil(t, err) + + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + + restAPIInterfaces := cs.GetRestAPIInterfaces() + require.NotNil(t, restAPIInterfaces) + + url := fmt.Sprintf("http://%s/address/%s/esdt", restAPIInterfaces[shardID], addrs[0].Bech32) + response := &esdtTokensCompleteResponse{} + + doHTTPClientGetReq(t, url, response) + + allTokens := response.Data.Tokens + + require.Equal(t, 1, len(allTokens)) + + expTokenID := string(nftTokenID) + "-01" + tokenData, ok := allTokens[expTokenID] + require.True(t, ok) + require.Equal(t, expTokenID, tokenData.TokenIdentifier) + require.Equal(t, core.NonFungibleESDT, tokenData.Type) + + log.Info("Wait for DynamicESDTFlag activation") + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + doHTTPClientGetReq(t, url, response) + + allTokens = response.Data.Tokens + + require.Equal(t, 1, len(allTokens)) + + expTokenID = string(nftTokenID) + "-01" + tokenData, ok = allTokens[expTokenID] + require.True(t, ok) + require.Equal(t, expTokenID, tokenData.TokenIdentifier) + require.Equal(t, core.NonFungibleESDT, tokenData.Type) + + log.Info("Update token id", "tokenID", nftTokenID) + + tx = updateTokenIDTx(2, addrs[0].Bytes, nftTokenID) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + doHTTPClientGetReq(t, url, response) + + allTokens = response.Data.Tokens + + require.Equal(t, 1, len(allTokens)) + + expTokenID = string(nftTokenID) + "-01" + tokenData, ok = allTokens[expTokenID] + require.True(t, ok) + require.Equal(t, expTokenID, tokenData.TokenIdentifier) + require.Equal(t, core.NonFungibleESDT, tokenData.Type) + + log.Info("Transfer token id", "tokenID", nftTokenID) + + tx = esdtNFTTransferTx(3, addrs[0].Bytes, addrs[1].Bytes, nftTokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + url = fmt.Sprintf("http://%s/address/%s/esdt", restAPIInterfaces[1], addrs[1].Bech32) + doHTTPClientGetReq(t, url, response) + + allTokens = response.Data.Tokens + + require.Equal(t, 1, len(allTokens)) + + expTokenID = string(nftTokenID) + "-01" + tokenData, ok = allTokens[expTokenID] + require.True(t, ok) + require.Equal(t, expTokenID, tokenData.TokenIdentifier) + require.Equal(t, core.NonFungibleESDTv2, tokenData.Type) + + log.Info("Change to DYNAMIC type") + + tx = changeToDynamicTx(4, addrs[0].Bytes, nftTokenID) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + response = &esdtTokensCompleteResponse{} + doHTTPClientGetReq(t, url, response) + + allTokens = response.Data.Tokens + + require.Equal(t, 1, len(allTokens)) + + expTokenID = string(nftTokenID) + "-01" + tokenData, ok = allTokens[expTokenID] + require.True(t, ok) + require.Equal(t, expTokenID, tokenData.TokenIdentifier) + require.Equal(t, core.NonFungibleESDTv2, tokenData.Type) +} + func doHTTPClientGetReq(t *testing.T, url string, response interface{}) { httpClient := &http.Client{} From 06328f8bedc9f688edea9938b282f0b6bc67c24d Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 10 Jun 2024 11:55:52 +0300 Subject: [PATCH 319/503] todo + fixes after review --- process/transaction/shardProcess.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index eb9d85c7259..3f1e545f39a 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -751,6 +751,7 @@ func (txProc *txProcessor) processInnerTx( process.ErrRelayedTxV3SenderShardMismatch.Error()) } + // TODO: remove adding and then removing the fee at the sender err = txProc.addFeeAndValueToDest(acntSnd, big.NewInt(0), txFee) if err != nil { return txFee, vmcommon.UserError, txProc.executeFailedRelayedUserTx( @@ -938,12 +939,23 @@ func (txProc *txProcessor) processUserTx( originalTxHash []byte, ) (vmcommon.ReturnCode, error) { + relayerAdr := originalTx.SndAddr acntSnd, acntDst, err := txProc.getAccounts(userTx.SndAddr, userTx.RcvAddr) if err != nil { - return 0, err + errRemove := txProc.removeValueAndConsumedFeeFromUser(userTx, relayedTxValue, originalTxHash, originalTx, err) + if errRemove != nil { + return vmcommon.UserError, errRemove + } + return vmcommon.UserError, txProc.executeFailedRelayedUserTx( + userTx, + relayerAdr, + relayedTxValue, + relayedNonce, + originalTx, + originalTxHash, + err.Error()) } - relayerAdr := originalTx.SndAddr txType, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(userTx) err = txProc.checkTxValues(userTx, acntSnd, acntDst, true) if err != nil { From 576309b1115e4ff35f0ae367706a028c2f510aaf Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 10 Jun 2024 12:06:29 +0300 Subject: [PATCH 320/503] remove consensus group size --- .../chainSimulator/staking/jail/jail_test.go | 44 +- .../staking/stake/simpleStake_test.go | 38 +- .../staking/stake/stakeAndUnStake_test.go | 850 ++++++++---------- .../stakingProvider/delegation_test.go | 650 +++++++------- .../stakingProviderWithNodesinQueue_test.go | 26 +- node/chainSimulator/chainSimulator.go | 64 +- node/chainSimulator/chainSimulator_test.go | 190 ++-- .../components/testOnlyProcessingNode_test.go | 16 +- node/chainSimulator/configs/configs.go | 34 +- node/chainSimulator/configs/configs_test.go | 16 +- 10 files changed, 888 insertions(+), 1040 deletions(-) diff --git a/integrationTests/chainSimulator/staking/jail/jail_test.go b/integrationTests/chainSimulator/staking/jail/jail_test.go index 3e2a1652de9..d306156d7b3 100644 --- a/integrationTests/chainSimulator/staking/jail/jail_test.go +++ b/integrationTests/chainSimulator/staking/jail/jail_test.go @@ -67,18 +67,16 @@ func testChainSimulatorJailAndUnJail(t *testing.T, targetEpoch int32, nodeStatus numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 2, - MetaChainMinNodes: 2, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 2, + MetaChainMinNodes: 2, AlterConfigsFunction: func(cfg *config.Configs) { configs.SetStakingV4ActivationEpochs(cfg, stakingV4JailUnJailStep1EnableEpoch) newNumNodes := cfg.SystemSCConfig.StakingSystemSCConfig.MaxNumberOfNodesForStake + 8 // 8 nodes until new nodes will be placed on queue @@ -169,18 +167,16 @@ func TestChainSimulator_FromQueueToAuctionList(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, AlterConfigsFunction: func(cfg *config.Configs) { configs.SetStakingV4ActivationEpochs(cfg, stakingV4JailUnJailStep1EnableEpoch) configs.SetQuickJailRatingConfig(cfg) diff --git a/integrationTests/chainSimulator/staking/stake/simpleStake_test.go b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go index dcccdf5c291..33ac33fecb7 100644 --- a/integrationTests/chainSimulator/staking/stake/simpleStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go @@ -66,20 +66,18 @@ func testChainSimulatorSimpleStake(t *testing.T, targetEpoch int32, nodesStatus numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { configs.SetStakingV4ActivationEpochs(cfg, 2) }, @@ -171,13 +169,11 @@ func TestChainSimulator_StakingV4Step2APICalls(t *testing.T) { HasValue: true, Value: 30, }, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 4, - MetaChainMinNodes: 4, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 4, - NumNodesWaitingListShard: 4, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 4, + MetaChainMinNodes: 4, + NumNodesWaitingListMeta: 4, + NumNodesWaitingListShard: 4, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = stakingV4Step1Epoch cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = stakingV4Step2Epoch diff --git a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index 9594ceef679..8344c757d80 100644 --- a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go @@ -57,20 +57,18 @@ func TestChainSimulator_AddValidatorKey(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, AlterConfigsFunction: func(cfg *config.Configs) { newNumNodes := cfg.SystemSCConfig.StakingSystemSCConfig.MaxNumberOfNodesForStake + 8 // 8 nodes until new nodes will be placed on queue configs.SetMaxNumberOfNodesInConfigs(cfg, uint32(newNumNodes), 0, numOfShards) @@ -191,18 +189,16 @@ func TestChainSimulator_AddANewValidatorAfterStakingV4(t *testing.T) { } numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 100, - MetaChainMinNodes: 100, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 100, + MetaChainMinNodes: 100, AlterConfigsFunction: func(cfg *config.Configs) { cfg.SystemSCConfig.StakingSystemSCConfig.NodeLimitPercentage = 1 cfg.GeneralConfig.ValidatorStatistics.CacheRefreshIntervalInSec = 1 @@ -322,18 +318,16 @@ func testStakeUnStakeUnBond(t *testing.T, targetEpoch int32) { } numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.SystemSCConfig.StakingSystemSCConfig.UnBondPeriod = 1 cfg.SystemSCConfig.StakingSystemSCConfig.UnBondPeriodInEpochs = 1 @@ -452,20 +446,18 @@ func TestChainSimulator_DirectStakingNodes_StakeFunds(t *testing.T) { t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 @@ -484,20 +476,18 @@ func TestChainSimulator_DirectStakingNodes_StakeFunds(t *testing.T) { t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -516,20 +506,18 @@ func TestChainSimulator_DirectStakingNodes_StakeFunds(t *testing.T) { t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -548,20 +536,18 @@ func TestChainSimulator_DirectStakingNodes_StakeFunds(t *testing.T) { t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -682,20 +668,18 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation(t *testi t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 @@ -715,20 +699,18 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation(t *testi t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 @@ -749,20 +731,18 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation(t *testi t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 @@ -783,20 +763,18 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation(t *testi t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 @@ -971,20 +949,18 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation_WithReac t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 @@ -1004,20 +980,18 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation_WithReac t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 @@ -1038,20 +1012,18 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation_WithReac t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 @@ -1072,20 +1044,18 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation_WithReac t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 @@ -1216,20 +1186,18 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedFundsBeforeUnbonding( t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 @@ -1248,20 +1216,18 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedFundsBeforeUnbonding( t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1280,20 +1246,18 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedFundsBeforeUnbonding( t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1312,20 +1276,18 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedFundsBeforeUnbonding( t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1458,20 +1420,18 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInWithdrawEpoch(t *te t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 @@ -1490,20 +1450,18 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInWithdrawEpoch(t *te t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1522,20 +1480,18 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInWithdrawEpoch(t *te t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1554,20 +1510,18 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInWithdrawEpoch(t *te t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1729,20 +1683,18 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInBatches(t *testing. t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 @@ -1763,20 +1715,18 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInBatches(t *testing. t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1797,20 +1747,18 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInBatches(t *testing. t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1831,20 +1779,18 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInBatches(t *testing. t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -2093,20 +2039,18 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInEpoch(t *testing.T) t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 @@ -2127,20 +2071,18 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInEpoch(t *testing.T) t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -2161,20 +2103,18 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInEpoch(t *testing.T) t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -2195,20 +2135,18 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInEpoch(t *testing.T) t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -2394,20 +2332,18 @@ func TestChainSimulator_UnStakeOneActiveNodeAndCheckAPIAuctionList(t *testing.T) numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 4, - MetaChainMinNodes: 4, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 4, - NumNodesWaitingListShard: 4, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 4, + MetaChainMinNodes: 4, + NumNodesWaitingListMeta: 4, + NumNodesWaitingListShard: 4, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = stakingV4Step1Epoch cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = stakingV4Step2Epoch @@ -2475,20 +2411,18 @@ func TestChainSimulator_EdgeCaseLowWaitingList(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 4, - MetaChainMinNodes: 4, - NumNodesWaitingListMeta: 2, - NumNodesWaitingListShard: 2, - MetaChainConsensusGroupSize: 1, - ConsensusGroupSize: 1, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 4, + MetaChainMinNodes: 4, + NumNodesWaitingListMeta: 2, + NumNodesWaitingListShard: 2, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = stakingV4Step1Epoch cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = stakingV4Step2Epoch diff --git a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index bb30199e95c..4697affa054 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go @@ -69,20 +69,18 @@ func TestChainSimulator_MakeNewContractFromValidatorData(t *testing.T) { // 6. Execute 2 unDelegate operations of 100 EGLD each, check the topup is back to 500 t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { maxNodesChangeEnableEpoch := cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch blsMultiSignerEnableEpoch := cfg.EpochConfig.EnableEpochs.BLSMultiSignerEnableEpoch @@ -115,20 +113,18 @@ func TestChainSimulator_MakeNewContractFromValidatorData(t *testing.T) { // 6. Execute 2 unDelegate operations of 100 EGLD each, check the topup is back to 500 t.Run("staking ph 4 is not active and all is done in epoch 0", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { maxNodesChangeEnableEpoch := cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch blsMultiSignerEnableEpoch := cfg.EpochConfig.EnableEpochs.BLSMultiSignerEnableEpoch @@ -168,20 +164,18 @@ func TestChainSimulator_MakeNewContractFromValidatorData(t *testing.T) { // 6. Execute 2 unDelegate operations of 100 EGLD each, check the topup is back to 500 t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -207,20 +201,18 @@ func TestChainSimulator_MakeNewContractFromValidatorData(t *testing.T) { // 6. Execute 2 unDelegate operations of 100 EGLD each, check the topup is back to 500 t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -246,20 +238,18 @@ func TestChainSimulator_MakeNewContractFromValidatorData(t *testing.T) { // 6. Execute 2 unDelegate operations of 100 EGLD each, check the topup is back to 500 t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -497,20 +487,18 @@ func TestChainSimulator_MakeNewContractFromValidatorDataWith2StakingContracts(t t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 @@ -528,20 +516,18 @@ func TestChainSimulator_MakeNewContractFromValidatorDataWith2StakingContracts(t }) t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -559,20 +545,18 @@ func TestChainSimulator_MakeNewContractFromValidatorDataWith2StakingContracts(t }) t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -590,20 +574,18 @@ func TestChainSimulator_MakeNewContractFromValidatorDataWith2StakingContracts(t }) t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -730,20 +712,18 @@ func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 @@ -763,20 +743,18 @@ func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta }) t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 @@ -797,20 +775,18 @@ func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta }) t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 @@ -831,20 +807,18 @@ func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta }) t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 @@ -1058,20 +1032,18 @@ func TestChainSimulator_CreateNewDelegationContract(t *testing.T) { // 6. Check the node is unstaked in the next epoch t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 @@ -1099,20 +1071,18 @@ func TestChainSimulator_CreateNewDelegationContract(t *testing.T) { // 6. Check the node is unstaked in the next epoch t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1140,20 +1110,18 @@ func TestChainSimulator_CreateNewDelegationContract(t *testing.T) { // 6. Check the node is unstaked in the next epoch t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1181,20 +1149,18 @@ func TestChainSimulator_CreateNewDelegationContract(t *testing.T) { // 6. Check the node is unstaked in the next epoch t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1434,20 +1400,18 @@ func TestChainSimulator_MaxDelegationCap(t *testing.T) { // 10. Delegate from user B 20 EGLD, check it fails t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 @@ -1477,20 +1441,18 @@ func TestChainSimulator_MaxDelegationCap(t *testing.T) { // 10. Delegate from user B 20 EGLD, check it fails t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1520,20 +1482,18 @@ func TestChainSimulator_MaxDelegationCap(t *testing.T) { // 10. Delegate from user B 20 EGLD, check it fails t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1563,20 +1523,18 @@ func TestChainSimulator_MaxDelegationCap(t *testing.T) { // 10. Delegate from user B 20 EGLD, check it fails t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 @@ -1852,20 +1810,18 @@ func TestChainSimulator_MergeDelegation(t *testing.T) { t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 @@ -1885,20 +1841,18 @@ func TestChainSimulator_MergeDelegation(t *testing.T) { t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 @@ -1919,20 +1873,18 @@ func TestChainSimulator_MergeDelegation(t *testing.T) { t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 @@ -1953,20 +1905,18 @@ func TestChainSimulator_MergeDelegation(t *testing.T) { t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2 cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 diff --git a/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go b/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go index 05b3f1b8eac..f47cf1eec9e 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go @@ -52,20 +52,18 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati } cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { configs.SetStakingV4ActivationEpochs(cfg, stakingV4ActivationEpoch) }, diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index b932a13f1c1..179df58961c 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -42,24 +42,22 @@ type transactionWithResult struct { // ArgsChainSimulator holds the arguments needed to create a new instance of simulator type ArgsChainSimulator struct { - BypassTxSignatureCheck bool - TempDir string - PathToInitialConfig string - NumOfShards uint32 - MinNodesPerShard uint32 - ConsensusGroupSize uint32 - MetaChainMinNodes uint32 - MetaChainConsensusGroupSize uint32 - NumNodesWaitingListShard uint32 - NumNodesWaitingListMeta uint32 - GenesisTimestamp int64 - InitialRound int64 - InitialEpoch uint32 - InitialNonce uint64 - RoundDurationInMillis uint64 - RoundsPerEpoch core.OptionalUint64 - ApiInterface components.APIConfigurator - AlterConfigsFunction func(cfg *config.Configs) + BypassTxSignatureCheck bool + TempDir string + PathToInitialConfig string + NumOfShards uint32 + MinNodesPerShard uint32 + MetaChainMinNodes uint32 + NumNodesWaitingListShard uint32 + NumNodesWaitingListMeta uint32 + GenesisTimestamp int64 + InitialRound int64 + InitialEpoch uint32 + InitialNonce uint64 + RoundDurationInMillis uint64 + RoundsPerEpoch core.OptionalUint64 + ApiInterface components.APIConfigurator + AlterConfigsFunction func(cfg *config.Configs) } type simulator struct { @@ -96,20 +94,18 @@ func NewChainSimulator(args ArgsChainSimulator) (*simulator, error) { func (s *simulator) createChainHandlers(args ArgsChainSimulator) error { outputConfigs, err := configs.CreateChainSimulatorConfigs(configs.ArgsChainSimulatorConfigs{ - NumOfShards: args.NumOfShards, - OriginalConfigsPath: args.PathToInitialConfig, - GenesisTimeStamp: computeStartTimeBaseOnInitialRound(args), - RoundDurationInMillis: args.RoundDurationInMillis, - TempDir: args.TempDir, - MinNodesPerShard: args.MinNodesPerShard, - ConsensusGroupSize: args.ConsensusGroupSize, - MetaChainMinNodes: args.MetaChainMinNodes, - MetaChainConsensusGroupSize: args.MetaChainConsensusGroupSize, - RoundsPerEpoch: args.RoundsPerEpoch, - InitialEpoch: args.InitialEpoch, - AlterConfigsFunction: args.AlterConfigsFunction, - NumNodesWaitingListShard: args.NumNodesWaitingListShard, - NumNodesWaitingListMeta: args.NumNodesWaitingListMeta, + NumOfShards: args.NumOfShards, + OriginalConfigsPath: args.PathToInitialConfig, + GenesisTimeStamp: computeStartTimeBaseOnInitialRound(args), + RoundDurationInMillis: args.RoundDurationInMillis, + TempDir: args.TempDir, + MinNodesPerShard: args.MinNodesPerShard, + MetaChainMinNodes: args.MetaChainMinNodes, + RoundsPerEpoch: args.RoundsPerEpoch, + InitialEpoch: args.InitialEpoch, + AlterConfigsFunction: args.AlterConfigsFunction, + NumNodesWaitingListShard: args.NumNodesWaitingListShard, + NumNodesWaitingListMeta: args.NumNodesWaitingListMeta, }) if err != nil { return err @@ -194,9 +190,9 @@ func (s *simulator) createTestNode( InitialRound: args.InitialRound, InitialNonce: args.InitialNonce, MinNodesPerShard: args.MinNodesPerShard, - ConsensusGroupSize: args.ConsensusGroupSize, + ConsensusGroupSize: configs.ChainSimulatorConsensusGroupSize, MinNodesMeta: args.MetaChainMinNodes, - MetaChainConsensusGroupSize: args.MetaChainConsensusGroupSize, + MetaChainConsensusGroupSize: configs.ChainSimulatorConsensusGroupSize, RoundDurationInMillis: args.RoundDurationInMillis, } diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index 190cf5a62b0..15a32de29c8 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -27,18 +27,16 @@ func TestNewChainSimulator(t *testing.T) { startTime := time.Now().Unix() roundDurationInMillis := uint64(6000) chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: core.OptionalUint64{}, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 1, - MetaChainMinNodes: 1, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: core.OptionalUint64{}, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 1, + MetaChainMinNodes: 1, }) require.Nil(t, err) require.NotNil(t, chainSimulator) @@ -66,14 +64,12 @@ func TestChainSimulator_GenerateBlocksShouldWork(t *testing.T) { HasValue: true, Value: 20, }, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 1, - MetaChainMinNodes: 1, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - InitialRound: 200000000, - InitialEpoch: 100, - InitialNonce: 100, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 1, + MetaChainMinNodes: 1, + InitialRound: 200000000, + InitialEpoch: 100, + InitialNonce: 100, AlterConfigsFunction: func(cfg *config.Configs) { // we need to enable this as this test skips a lot of epoch activations events, and it will fail otherwise // because the owner of a BLS key coming from genesis is not set @@ -104,18 +100,16 @@ func TestChainSimulator_GenerateBlocksAndEpochChangeShouldWork(t *testing.T) { Value: 20, } chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 100, - MetaChainMinNodes: 100, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 100, + MetaChainMinNodes: 100, }) require.Nil(t, err) require.NotNil(t, chainSimulator) @@ -163,18 +157,16 @@ func TestSimulator_TriggerChangeOfEpoch(t *testing.T) { Value: 15000, } chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 100, - MetaChainMinNodes: 100, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 100, + MetaChainMinNodes: 100, }) require.Nil(t, err) require.NotNil(t, chainSimulator) @@ -210,18 +202,16 @@ func TestChainSimulator_SetState(t *testing.T) { Value: 20, } chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 1, - MetaChainMinNodes: 1, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 1, + MetaChainMinNodes: 1, }) require.Nil(t, err) require.NotNil(t, chainSimulator) @@ -243,18 +233,16 @@ func TestChainSimulator_SetEntireState(t *testing.T) { Value: 20, } chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 1, - MetaChainMinNodes: 1, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 1, + MetaChainMinNodes: 1, }) require.Nil(t, err) require.NotNil(t, chainSimulator) @@ -293,18 +281,16 @@ func TestChainSimulator_SetEntireStateWithRemoval(t *testing.T) { Value: 20, } chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 1, - MetaChainMinNodes: 1, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 1, + MetaChainMinNodes: 1, }) require.Nil(t, err) require.NotNil(t, chainSimulator) @@ -342,18 +328,16 @@ func TestChainSimulator_GetAccount(t *testing.T) { Value: 20, } chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 1, - MetaChainMinNodes: 1, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 1, + MetaChainMinNodes: 1, }) require.Nil(t, err) require.NotNil(t, chainSimulator) @@ -378,18 +362,16 @@ func TestSimulator_SendTransactions(t *testing.T) { Value: 20, } chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 1, - MetaChainMinNodes: 1, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 1, + MetaChainMinNodes: 1, }) require.Nil(t, err) require.NotNil(t, chainSimulator) diff --git a/node/chainSimulator/components/testOnlyProcessingNode_test.go b/node/chainSimulator/components/testOnlyProcessingNode_test.go index c363ca8019c..ef4e6ba23fc 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode_test.go +++ b/node/chainSimulator/components/testOnlyProcessingNode_test.go @@ -24,15 +24,13 @@ var expectedErr = errors.New("expected error") func createMockArgsTestOnlyProcessingNode(t *testing.T) ArgsTestOnlyProcessingNode { outputConfigs, err := configs.CreateChainSimulatorConfigs(configs.ArgsChainSimulatorConfigs{ - NumOfShards: 3, - OriginalConfigsPath: "../../../cmd/node/config/", - GenesisTimeStamp: 0, - RoundDurationInMillis: 6000, - TempDir: t.TempDir(), - MinNodesPerShard: 1, - MetaChainMinNodes: 1, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, + NumOfShards: 3, + OriginalConfigsPath: "../../../cmd/node/config/", + GenesisTimeStamp: 0, + RoundDurationInMillis: 6000, + TempDir: t.TempDir(), + MinNodesPerShard: 1, + MetaChainMinNodes: 1, }) require.Nil(t, err) diff --git a/node/chainSimulator/configs/configs.go b/node/chainSimulator/configs/configs.go index c83d6494334..9b9e32832c6 100644 --- a/node/chainSimulator/configs/configs.go +++ b/node/chainSimulator/configs/configs.go @@ -36,25 +36,25 @@ const ( // ChainID contains the chain id ChainID = "chain" - allValidatorsPemFileName = "allValidatorsKeys.pem" + // ChainSimulatorConsensusGroupSize defines the size of the consensus group for chain simulator + ChainSimulatorConsensusGroupSize = 1 + allValidatorsPemFileName = "allValidatorsKeys.pem" ) // ArgsChainSimulatorConfigs holds all the components needed to create the chain simulator configs type ArgsChainSimulatorConfigs struct { - NumOfShards uint32 - OriginalConfigsPath string - GenesisTimeStamp int64 - RoundDurationInMillis uint64 - TempDir string - MinNodesPerShard uint32 - ConsensusGroupSize uint32 - MetaChainMinNodes uint32 - MetaChainConsensusGroupSize uint32 - InitialEpoch uint32 - RoundsPerEpoch core.OptionalUint64 - NumNodesWaitingListShard uint32 - NumNodesWaitingListMeta uint32 - AlterConfigsFunction func(cfg *config.Configs) + NumOfShards uint32 + OriginalConfigsPath string + GenesisTimeStamp int64 + RoundDurationInMillis uint64 + TempDir string + MinNodesPerShard uint32 + MetaChainMinNodes uint32 + InitialEpoch uint32 + RoundsPerEpoch core.OptionalUint64 + NumNodesWaitingListShard uint32 + NumNodesWaitingListMeta uint32 + AlterConfigsFunction func(cfg *config.Configs) } // ArgsConfigsSimulator holds the configs for the chain simulator @@ -278,8 +278,8 @@ func generateValidatorsKeyAndUpdateFiles( nodes.RoundDuration = args.RoundDurationInMillis nodes.StartTime = args.GenesisTimeStamp - nodes.ConsensusGroupSize = args.ConsensusGroupSize - nodes.MetaChainConsensusGroupSize = args.MetaChainConsensusGroupSize + nodes.ConsensusGroupSize = ChainSimulatorConsensusGroupSize + nodes.MetaChainConsensusGroupSize = ChainSimulatorConsensusGroupSize nodes.Hysteresis = 0 nodes.MinNodesPerShard = args.MinNodesPerShard diff --git a/node/chainSimulator/configs/configs_test.go b/node/chainSimulator/configs/configs_test.go index 03e464c5f36..07bd09e70c8 100644 --- a/node/chainSimulator/configs/configs_test.go +++ b/node/chainSimulator/configs/configs_test.go @@ -14,15 +14,13 @@ func TestNewProcessorRunnerChainArguments(t *testing.T) { } outputConfig, err := CreateChainSimulatorConfigs(ArgsChainSimulatorConfigs{ - NumOfShards: 3, - OriginalConfigsPath: "../../../cmd/node/config", - RoundDurationInMillis: 6000, - GenesisTimeStamp: 0, - TempDir: t.TempDir(), - MetaChainMinNodes: 1, - MinNodesPerShard: 1, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, + NumOfShards: 3, + OriginalConfigsPath: "../../../cmd/node/config", + RoundDurationInMillis: 6000, + GenesisTimeStamp: 0, + TempDir: t.TempDir(), + MetaChainMinNodes: 1, + MinNodesPerShard: 1, }) require.Nil(t, err) From e423508583bafa2f45a476b79e71d66ee0fac085 Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 10 Jun 2024 14:14:25 +0300 Subject: [PATCH 321/503] fixes --- node/chainSimulator/chainSimulator.go | 27 +++++++++++++++---- .../components/testOnlyProcessingNode_test.go | 16 ++++++----- node/chainSimulator/configs/configs.go | 6 +++-- node/chainSimulator/configs/configs_test.go | 16 ++++++----- 4 files changed, 44 insertions(+), 21 deletions(-) diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index 179df58961c..b8dadfdc945 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -60,6 +60,12 @@ type ArgsChainSimulator struct { AlterConfigsFunction func(cfg *config.Configs) } +type ArgsBaseChainSimulator struct { + ArgsChainSimulator + ConsensusGroupSize uint32 + MetaConsensusGroupSize uint32 +} + type simulator struct { chanStopNodeProcess chan endProcess.ArgEndProcess syncedBroadcastNetwork components.SyncedBroadcastNetworkHandler @@ -74,6 +80,15 @@ type simulator struct { // NewChainSimulator will create a new instance of simulator func NewChainSimulator(args ArgsChainSimulator) (*simulator, error) { + return NewBaseChainSimulator(ArgsBaseChainSimulator{ + ArgsChainSimulator: args, + ConsensusGroupSize: configs.ChainSimulatorConsensusGroupSize, + MetaConsensusGroupSize: configs.ChainSimulatorConsensusGroupSize, + }) +} + +// NewBaseChainSimulator will create a new instance of simulator +func NewBaseChainSimulator(args ArgsBaseChainSimulator) (*simulator, error) { instance := &simulator{ syncedBroadcastNetwork: components.NewSyncedBroadcastNetwork(), nodes: make(map[uint32]process.NodeHandler), @@ -92,17 +107,19 @@ func NewChainSimulator(args ArgsChainSimulator) (*simulator, error) { return instance, nil } -func (s *simulator) createChainHandlers(args ArgsChainSimulator) error { +func (s *simulator) createChainHandlers(args ArgsBaseChainSimulator) error { outputConfigs, err := configs.CreateChainSimulatorConfigs(configs.ArgsChainSimulatorConfigs{ NumOfShards: args.NumOfShards, OriginalConfigsPath: args.PathToInitialConfig, - GenesisTimeStamp: computeStartTimeBaseOnInitialRound(args), + GenesisTimeStamp: computeStartTimeBaseOnInitialRound(args.ArgsChainSimulator), RoundDurationInMillis: args.RoundDurationInMillis, TempDir: args.TempDir, MinNodesPerShard: args.MinNodesPerShard, MetaChainMinNodes: args.MetaChainMinNodes, RoundsPerEpoch: args.RoundsPerEpoch, InitialEpoch: args.InitialEpoch, + ConsensusGroupSize: args.ConsensusGroupSize, + MetaConsensusGroupSize: args.MetaConsensusGroupSize, AlterConfigsFunction: args.AlterConfigsFunction, NumNodesWaitingListShard: args.NumNodesWaitingListShard, NumNodesWaitingListMeta: args.NumNodesWaitingListMeta, @@ -176,7 +193,7 @@ func computeStartTimeBaseOnInitialRound(args ArgsChainSimulator) int64 { } func (s *simulator) createTestNode( - outputConfigs configs.ArgsConfigsSimulator, args ArgsChainSimulator, shardIDStr string, + outputConfigs configs.ArgsConfigsSimulator, args ArgsBaseChainSimulator, shardIDStr string, ) (process.NodeHandler, error) { argsTestOnlyProcessorNode := components.ArgsTestOnlyProcessingNode{ Configs: outputConfigs.Configs, @@ -190,9 +207,9 @@ func (s *simulator) createTestNode( InitialRound: args.InitialRound, InitialNonce: args.InitialNonce, MinNodesPerShard: args.MinNodesPerShard, - ConsensusGroupSize: configs.ChainSimulatorConsensusGroupSize, + ConsensusGroupSize: args.ConsensusGroupSize, MinNodesMeta: args.MetaChainMinNodes, - MetaChainConsensusGroupSize: configs.ChainSimulatorConsensusGroupSize, + MetaChainConsensusGroupSize: args.MetaConsensusGroupSize, RoundDurationInMillis: args.RoundDurationInMillis, } diff --git a/node/chainSimulator/components/testOnlyProcessingNode_test.go b/node/chainSimulator/components/testOnlyProcessingNode_test.go index ef4e6ba23fc..ed329ab8756 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode_test.go +++ b/node/chainSimulator/components/testOnlyProcessingNode_test.go @@ -24,13 +24,15 @@ var expectedErr = errors.New("expected error") func createMockArgsTestOnlyProcessingNode(t *testing.T) ArgsTestOnlyProcessingNode { outputConfigs, err := configs.CreateChainSimulatorConfigs(configs.ArgsChainSimulatorConfigs{ - NumOfShards: 3, - OriginalConfigsPath: "../../../cmd/node/config/", - GenesisTimeStamp: 0, - RoundDurationInMillis: 6000, - TempDir: t.TempDir(), - MinNodesPerShard: 1, - MetaChainMinNodes: 1, + NumOfShards: 3, + OriginalConfigsPath: "../../../cmd/node/config/", + GenesisTimeStamp: 0, + RoundDurationInMillis: 6000, + TempDir: t.TempDir(), + MinNodesPerShard: 1, + MetaChainMinNodes: 1, + ConsensusGroupSize: 1, + MetaConsensusGroupSize: 1, }) require.Nil(t, err) diff --git a/node/chainSimulator/configs/configs.go b/node/chainSimulator/configs/configs.go index 9b9e32832c6..afa57538d93 100644 --- a/node/chainSimulator/configs/configs.go +++ b/node/chainSimulator/configs/configs.go @@ -51,6 +51,8 @@ type ArgsChainSimulatorConfigs struct { MinNodesPerShard uint32 MetaChainMinNodes uint32 InitialEpoch uint32 + ConsensusGroupSize uint32 + MetaConsensusGroupSize uint32 RoundsPerEpoch core.OptionalUint64 NumNodesWaitingListShard uint32 NumNodesWaitingListMeta uint32 @@ -278,8 +280,8 @@ func generateValidatorsKeyAndUpdateFiles( nodes.RoundDuration = args.RoundDurationInMillis nodes.StartTime = args.GenesisTimeStamp - nodes.ConsensusGroupSize = ChainSimulatorConsensusGroupSize - nodes.MetaChainConsensusGroupSize = ChainSimulatorConsensusGroupSize + nodes.ConsensusGroupSize = args.ConsensusGroupSize + nodes.MetaChainConsensusGroupSize = args.MetaConsensusGroupSize nodes.Hysteresis = 0 nodes.MinNodesPerShard = args.MinNodesPerShard diff --git a/node/chainSimulator/configs/configs_test.go b/node/chainSimulator/configs/configs_test.go index 07bd09e70c8..cf49395fa5b 100644 --- a/node/chainSimulator/configs/configs_test.go +++ b/node/chainSimulator/configs/configs_test.go @@ -14,13 +14,15 @@ func TestNewProcessorRunnerChainArguments(t *testing.T) { } outputConfig, err := CreateChainSimulatorConfigs(ArgsChainSimulatorConfigs{ - NumOfShards: 3, - OriginalConfigsPath: "../../../cmd/node/config", - RoundDurationInMillis: 6000, - GenesisTimeStamp: 0, - TempDir: t.TempDir(), - MetaChainMinNodes: 1, - MinNodesPerShard: 1, + NumOfShards: 3, + OriginalConfigsPath: "../../../cmd/node/config", + RoundDurationInMillis: 6000, + GenesisTimeStamp: 0, + TempDir: t.TempDir(), + MetaChainMinNodes: 1, + MinNodesPerShard: 1, + ConsensusGroupSize: 1, + MetaConsensusGroupSize: 1, }) require.Nil(t, err) From 5577c9d6466e7c1982964c0fb87532a1f3e393ab Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 10 Jun 2024 14:21:23 +0300 Subject: [PATCH 322/503] rename and fixes --- node/chainSimulator/chainSimulator.go | 40 +++++++++---------- .../components/testOnlyProcessingNode_test.go | 18 ++++----- node/chainSimulator/configs/configs.go | 30 +++++++------- node/chainSimulator/configs/configs_test.go | 18 ++++----- 4 files changed, 53 insertions(+), 53 deletions(-) diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index b8dadfdc945..ad77ece5fd4 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -62,8 +62,8 @@ type ArgsChainSimulator struct { type ArgsBaseChainSimulator struct { ArgsChainSimulator - ConsensusGroupSize uint32 - MetaConsensusGroupSize uint32 + ConsensusGroupSize uint32 + MetaChainConsensusGroupSize uint32 } type simulator struct { @@ -81,9 +81,9 @@ type simulator struct { // NewChainSimulator will create a new instance of simulator func NewChainSimulator(args ArgsChainSimulator) (*simulator, error) { return NewBaseChainSimulator(ArgsBaseChainSimulator{ - ArgsChainSimulator: args, - ConsensusGroupSize: configs.ChainSimulatorConsensusGroupSize, - MetaConsensusGroupSize: configs.ChainSimulatorConsensusGroupSize, + ArgsChainSimulator: args, + ConsensusGroupSize: configs.ChainSimulatorConsensusGroupSize, + MetaChainConsensusGroupSize: configs.ChainSimulatorConsensusGroupSize, }) } @@ -109,20 +109,20 @@ func NewBaseChainSimulator(args ArgsBaseChainSimulator) (*simulator, error) { func (s *simulator) createChainHandlers(args ArgsBaseChainSimulator) error { outputConfigs, err := configs.CreateChainSimulatorConfigs(configs.ArgsChainSimulatorConfigs{ - NumOfShards: args.NumOfShards, - OriginalConfigsPath: args.PathToInitialConfig, - GenesisTimeStamp: computeStartTimeBaseOnInitialRound(args.ArgsChainSimulator), - RoundDurationInMillis: args.RoundDurationInMillis, - TempDir: args.TempDir, - MinNodesPerShard: args.MinNodesPerShard, - MetaChainMinNodes: args.MetaChainMinNodes, - RoundsPerEpoch: args.RoundsPerEpoch, - InitialEpoch: args.InitialEpoch, - ConsensusGroupSize: args.ConsensusGroupSize, - MetaConsensusGroupSize: args.MetaConsensusGroupSize, - AlterConfigsFunction: args.AlterConfigsFunction, - NumNodesWaitingListShard: args.NumNodesWaitingListShard, - NumNodesWaitingListMeta: args.NumNodesWaitingListMeta, + NumOfShards: args.NumOfShards, + OriginalConfigsPath: args.PathToInitialConfig, + GenesisTimeStamp: computeStartTimeBaseOnInitialRound(args.ArgsChainSimulator), + RoundDurationInMillis: args.RoundDurationInMillis, + TempDir: args.TempDir, + MinNodesPerShard: args.MinNodesPerShard, + ConsensusGroupSize: args.ConsensusGroupSize, + MetaChainMinNodes: args.MetaChainMinNodes, + MetaChainConsensusGroupSize: args.MetaChainConsensusGroupSize, + RoundsPerEpoch: args.RoundsPerEpoch, + InitialEpoch: args.InitialEpoch, + AlterConfigsFunction: args.AlterConfigsFunction, + NumNodesWaitingListShard: args.NumNodesWaitingListShard, + NumNodesWaitingListMeta: args.NumNodesWaitingListMeta, }) if err != nil { return err @@ -209,7 +209,7 @@ func (s *simulator) createTestNode( MinNodesPerShard: args.MinNodesPerShard, ConsensusGroupSize: args.ConsensusGroupSize, MinNodesMeta: args.MetaChainMinNodes, - MetaChainConsensusGroupSize: args.MetaConsensusGroupSize, + MetaChainConsensusGroupSize: args.MetaChainConsensusGroupSize, RoundDurationInMillis: args.RoundDurationInMillis, } diff --git a/node/chainSimulator/components/testOnlyProcessingNode_test.go b/node/chainSimulator/components/testOnlyProcessingNode_test.go index ed329ab8756..c363ca8019c 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode_test.go +++ b/node/chainSimulator/components/testOnlyProcessingNode_test.go @@ -24,15 +24,15 @@ var expectedErr = errors.New("expected error") func createMockArgsTestOnlyProcessingNode(t *testing.T) ArgsTestOnlyProcessingNode { outputConfigs, err := configs.CreateChainSimulatorConfigs(configs.ArgsChainSimulatorConfigs{ - NumOfShards: 3, - OriginalConfigsPath: "../../../cmd/node/config/", - GenesisTimeStamp: 0, - RoundDurationInMillis: 6000, - TempDir: t.TempDir(), - MinNodesPerShard: 1, - MetaChainMinNodes: 1, - ConsensusGroupSize: 1, - MetaConsensusGroupSize: 1, + NumOfShards: 3, + OriginalConfigsPath: "../../../cmd/node/config/", + GenesisTimeStamp: 0, + RoundDurationInMillis: 6000, + TempDir: t.TempDir(), + MinNodesPerShard: 1, + MetaChainMinNodes: 1, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, }) require.Nil(t, err) diff --git a/node/chainSimulator/configs/configs.go b/node/chainSimulator/configs/configs.go index afa57538d93..22fc863c7a0 100644 --- a/node/chainSimulator/configs/configs.go +++ b/node/chainSimulator/configs/configs.go @@ -43,20 +43,20 @@ const ( // ArgsChainSimulatorConfigs holds all the components needed to create the chain simulator configs type ArgsChainSimulatorConfigs struct { - NumOfShards uint32 - OriginalConfigsPath string - GenesisTimeStamp int64 - RoundDurationInMillis uint64 - TempDir string - MinNodesPerShard uint32 - MetaChainMinNodes uint32 - InitialEpoch uint32 - ConsensusGroupSize uint32 - MetaConsensusGroupSize uint32 - RoundsPerEpoch core.OptionalUint64 - NumNodesWaitingListShard uint32 - NumNodesWaitingListMeta uint32 - AlterConfigsFunction func(cfg *config.Configs) + NumOfShards uint32 + OriginalConfigsPath string + GenesisTimeStamp int64 + RoundDurationInMillis uint64 + TempDir string + MinNodesPerShard uint32 + ConsensusGroupSize uint32 + MetaChainMinNodes uint32 + MetaChainConsensusGroupSize uint32 + InitialEpoch uint32 + RoundsPerEpoch core.OptionalUint64 + NumNodesWaitingListShard uint32 + NumNodesWaitingListMeta uint32 + AlterConfigsFunction func(cfg *config.Configs) } // ArgsConfigsSimulator holds the configs for the chain simulator @@ -281,7 +281,7 @@ func generateValidatorsKeyAndUpdateFiles( nodes.StartTime = args.GenesisTimeStamp nodes.ConsensusGroupSize = args.ConsensusGroupSize - nodes.MetaChainConsensusGroupSize = args.MetaConsensusGroupSize + nodes.MetaChainConsensusGroupSize = args.MetaChainConsensusGroupSize nodes.Hysteresis = 0 nodes.MinNodesPerShard = args.MinNodesPerShard diff --git a/node/chainSimulator/configs/configs_test.go b/node/chainSimulator/configs/configs_test.go index cf49395fa5b..03e464c5f36 100644 --- a/node/chainSimulator/configs/configs_test.go +++ b/node/chainSimulator/configs/configs_test.go @@ -14,15 +14,15 @@ func TestNewProcessorRunnerChainArguments(t *testing.T) { } outputConfig, err := CreateChainSimulatorConfigs(ArgsChainSimulatorConfigs{ - NumOfShards: 3, - OriginalConfigsPath: "../../../cmd/node/config", - RoundDurationInMillis: 6000, - GenesisTimeStamp: 0, - TempDir: t.TempDir(), - MetaChainMinNodes: 1, - MinNodesPerShard: 1, - ConsensusGroupSize: 1, - MetaConsensusGroupSize: 1, + NumOfShards: 3, + OriginalConfigsPath: "../../../cmd/node/config", + RoundDurationInMillis: 6000, + GenesisTimeStamp: 0, + TempDir: t.TempDir(), + MetaChainMinNodes: 1, + MinNodesPerShard: 1, + ConsensusGroupSize: 1, + MetaChainConsensusGroupSize: 1, }) require.Nil(t, err) From d0b1ce2e3dfec93a66e1df0219bbf91063113132 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Tue, 11 Jun 2024 12:40:33 +0300 Subject: [PATCH 323/503] do not allow NFTs to be upgraded to dynamic --- .../vm/esdtImprovements_test.go | 26 +++++++++---------- vm/systemSmartContracts/esdt.go | 20 ++++++++++++-- vm/systemSmartContracts/esdt_test.go | 2 +- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 008844e3ddc..d21bb6e1f36 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -38,7 +38,7 @@ var log = logger.GetOrCreate("integrationTests/chainSimulator/vm") // Test scenario #1 // // Initial setup: Create fungible, NFT, SFT and metaESDT tokens -// (before the activation of DynamicEsdtFlag) +// (before the activation of DynamicEsdtFlag) // // 1.check that the metadata for all tokens is saved on the system account // 2. wait for DynamicEsdtFlag activation @@ -1146,7 +1146,7 @@ func TestChainSimulator_NFT_ESDTMetaDataUpdate(t *testing.T) { // Test scenario #6 // -// Initial setup: Create NFT +// Initial setup: Create SFT // // Call ESDTModifyCreator and check that the creator was modified // (The sender must have the ESDTRoleModifyCreator role) @@ -1205,10 +1205,10 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { err = cs.GenerateBlocks(10) require.Nil(t, err) - log.Info("Initial setup: Create NFT") + log.Info("Initial setup: Create SFT") - nftTicker := []byte("NFTTICKER") - tx := issueNonFungibleTx(0, address.Bytes, nftTicker, baseIssuingCost) + sftTicker := []byte("SFTTICKER") + tx := issueSemiFungibleTx(0, address.Bytes, sftTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1220,15 +1220,15 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { []byte(core.ESDTRoleNFTUpdate), } - nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, address, nftTokenID, roles) + sft := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, address, sft, roles) - log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) + log.Info("Issued SFT token id", "tokenID", string(sft)) nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, address.Bytes, nftTokenID, nftMetaData) + tx = nftCreateTx(1, address.Bytes, sft, nftMetaData) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1241,7 +1241,7 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { log.Info("Change to DYNAMIC type") - tx = changeToDynamicTx(2, address.Bytes, nftTokenID) + tx = changeToDynamicTx(2, address.Bytes, sft) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1260,12 +1260,12 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { roles = [][]byte{ []byte(core.ESDTRoleModifyCreator), } - setAddressEsdtRoles(t, cs, newCreatorAddress, nftTokenID, roles) + setAddressEsdtRoles(t, cs, newCreatorAddress, sft, roles) txDataField := bytes.Join( [][]byte{ []byte(core.ESDTModifyCreator), - []byte(hex.EncodeToString(nftTokenID)), + []byte(hex.EncodeToString(sft)), []byte(hex.EncodeToString(big.NewInt(1).Bytes())), }, []byte("@"), @@ -1290,7 +1290,7 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) - retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) + retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, sft, shardID) require.Equal(t, newCreatorAddress.Bytes, retrievedMetaData.Creator) } diff --git a/vm/systemSmartContracts/esdt.go b/vm/systemSmartContracts/esdt.go index 7d8fe4bba10..e8371e1eb79 100644 --- a/vm/systemSmartContracts/esdt.go +++ b/vm/systemSmartContracts/esdt.go @@ -2349,8 +2349,8 @@ func (e *esdt) changeToDynamic(args *vmcommon.ContractCallInput) vmcommon.Return return returnCode } - if bytes.Equal(token.TokenType, []byte(core.FungibleESDT)) { - e.eei.AddReturnMessage("cannot change fungible tokens to dynamic") + if isNotAllowed(token.TokenType) { + e.eei.AddReturnMessage(fmt.Sprintf("cannot change %s tokens to dynamic", token.TokenType)) return vmcommon.UserError } if isDynamicTokenType(token.TokenType) { @@ -2384,6 +2384,22 @@ func (e *esdt) changeToDynamic(args *vmcommon.ContractCallInput) vmcommon.Return return vmcommon.Ok } +func isNotAllowed(tokenType []byte) bool { + notAllowedTypes := [][]byte{ + []byte(core.FungibleESDT), + []byte(core.NonFungibleESDT), + []byte(core.NonFungibleESDTv2), + } + + for _, notAllowedType := range notAllowedTypes { + if bytes.Equal(tokenType, notAllowedType) { + return true + } + } + + return false +} + func (e *esdt) sendTokenTypeToSystemAccounts(caller []byte, tokenID []byte, token *ESDTDataV2) { if !e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) { return diff --git a/vm/systemSmartContracts/esdt_test.go b/vm/systemSmartContracts/esdt_test.go index 59cb7922888..81486e3fba6 100644 --- a/vm/systemSmartContracts/esdt_test.go +++ b/vm/systemSmartContracts/esdt_test.go @@ -4784,7 +4784,7 @@ func TestEsdt_ChangeToDynamic(t *testing.T) { eei.returnMessage = "" output = e.Execute(vmInput) assert.Equal(t, vmcommon.UserError, output) - assert.True(t, strings.Contains(eei.returnMessage, "cannot change fungible tokens to dynamic")) + assert.True(t, strings.Contains(eei.returnMessage, "cannot change FungibleESDT tokens to dynamic")) esdtData.TokenType = []byte(core.DynamicMetaESDT) _ = e.saveToken(vmInput.Arguments[0], esdtData) From b3d4207a30ef9d6f31d92dd7db1aaa3dbbf6427a Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 11 Jun 2024 14:19:38 +0300 Subject: [PATCH 324/503] moved ComputeRelayedTxFees from relayedTxV3Processor to economicsData fixed gasUsed field returned when checking transaction withResults=true --- genesis/process/disabled/feeHandler.go | 5 ++ go.mod | 2 +- go.sum | 4 +- .../transactionsFeeProcessor.go | 30 +++++++ process/disabled/relayedTxV3Processor.go | 7 -- process/economics/economicsData.go | 45 +++++++++++ process/economics/economicsData_test.go | 79 +++++++++++++++++++ process/errors.go | 3 + process/interface.go | 2 +- process/transaction/relayedTxV3Processor.go | 31 -------- .../transaction/relayedTxV3Processor_test.go | 67 +--------------- process/transaction/shardProcess.go | 41 +++++++++- process/transaction/shardProcess_test.go | 27 +++++++ .../economicsDataHandlerStub.go | 9 +++ .../economicsmocks/economicsHandlerMock.go | 9 +++ .../processMocks/relayedTxV3ProcessorMock.go | 13 +-- 16 files changed, 251 insertions(+), 123 deletions(-) diff --git a/genesis/process/disabled/feeHandler.go b/genesis/process/disabled/feeHandler.go index 1fc34bbc2b5..f81e7e978eb 100644 --- a/genesis/process/disabled/feeHandler.go +++ b/genesis/process/disabled/feeHandler.go @@ -183,6 +183,11 @@ func (fh *FeeHandler) ComputeTxFeeBasedOnGasUsedInEpoch(tx data.TransactionWithF return big.NewInt(0) } +// ComputeRelayedTxFees returns 0 and 0 +func (fh *FeeHandler) ComputeRelayedTxFees(_ data.TransactionWithFeeHandler) (*big.Int, *big.Int, error) { + return big.NewInt(0), big.NewInt(0), nil +} + // IsInterfaceNil returns true if there is no value under the interface func (fh *FeeHandler) IsInterfaceNil() bool { return fh == nil diff --git a/go.mod b/go.mod index 084e8e818e8..fbcf00fa719 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e - github.com/multiversx/mx-chain-core-go v1.2.21-0.20240604075337-88bd243c9240 + github.com/multiversx/mx-chain-core-go v1.2.21-0.20240611111433-86ff8cd5798b github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df github.com/multiversx/mx-chain-es-indexer-go v1.7.1-0.20240509104512-25512675833d github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 diff --git a/go.sum b/go.sum index cd752364c18..3e87e4bc725 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY 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.20240604075337-88bd243c9240 h1:aTh69ZTT1Vazs4gs39ulgM2F8auLBH6S+TF9l23OQl8= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240604075337-88bd243c9240/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240611111433-86ff8cd5798b h1:cbMcnL97p2NTn0KDyA9aEwnDzdmFf/lQaztsQujGZxY= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240611111433-86ff8cd5798b/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.1-0.20240509104512-25512675833d h1:GD1D8V0bE6hDLjrduSsMwQwwf6PMq2Zww7FYMfJsuiw= diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index c77956f5365..6520db7635d 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -115,6 +115,11 @@ func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *trans feeInfo.SetFee(initialPaidFee) } + if len(txHandler.GetUserTransactions()) > 0 { + tep.prepareRelayedTxV3WithResults(txHashHex, txWithResult) + continue + } + tep.prepareTxWithResults(txHashHex, txWithResult) } } @@ -141,6 +146,31 @@ func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWi } +func (tep *transactionsFeeProcessor) prepareRelayedTxV3WithResults(txHashHex string, txWithResults *transactionWithResults) { + refundsValue := big.NewInt(0) + for _, scrHandler := range txWithResults.scrs { + scr, ok := scrHandler.GetTxHandler().(*smartContractResult.SmartContractResult) + if !ok { + continue + } + + if !isRefundForRelayed(scr, txWithResults.GetTxHandler()) { + continue + } + + refundsValue.Add(refundsValue, scr.Value) + } + + gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txWithResults.GetTxHandler(), refundsValue) + + txWithResults.GetFeeInfo().SetGasUsed(gasUsed) + txWithResults.GetFeeInfo().SetFee(fee) + + hasRefunds := refundsValue.Cmp(big.NewInt(0)) == 1 + tep.prepareTxWithResultsBasedOnLogs(txHashHex, txWithResults, hasRefunds) + +} + func (tep *transactionsFeeProcessor) prepareTxWithResultsBasedOnLogs( txHashHex string, txWithResults *transactionWithResults, diff --git a/process/disabled/relayedTxV3Processor.go b/process/disabled/relayedTxV3Processor.go index 16f333263ff..ddabd2753c8 100644 --- a/process/disabled/relayedTxV3Processor.go +++ b/process/disabled/relayedTxV3Processor.go @@ -1,8 +1,6 @@ package disabled import ( - "math/big" - "github.com/multiversx/mx-chain-core-go/data/transaction" ) @@ -19,11 +17,6 @@ func (proc *relayedTxV3Processor) CheckRelayedTx(_ *transaction.Transaction) err return nil } -// ComputeRelayedTxFees returns 0, 0 as it is disabled -func (proc *relayedTxV3Processor) ComputeRelayedTxFees(_ *transaction.Transaction) (*big.Int, *big.Int) { - return big.NewInt(0), big.NewInt(0) -} - // IsInterfaceNil returns true if there is no value under the interface func (proc *relayedTxV3Processor) IsInterfaceNil() bool { return proc == nil diff --git a/process/economics/economicsData.go b/process/economics/economicsData.go index 5b7ce045237..209e8345941 100644 --- a/process/economics/economicsData.go +++ b/process/economics/economicsData.go @@ -285,6 +285,11 @@ func (ed *economicsData) ComputeTxFee(tx data.TransactionWithFeeHandler) *big.In // ComputeTxFeeInEpoch computes the provided transaction's fee in a specific epoch func (ed *economicsData) ComputeTxFeeInEpoch(tx data.TransactionWithFeeHandler, epoch uint32) *big.Int { + if len(tx.GetUserTransactions()) > 0 { + _, totalFee, _ := ed.ComputeRelayedTxFees(tx) + return totalFee + } + if ed.enableEpochsHandler.IsFlagEnabledInEpoch(common.GasPriceModifierFlag, epoch) { if isSmartContractResult(tx) { return ed.ComputeFeeForProcessingInEpoch(tx, tx.GetGasLimit(), epoch) @@ -308,6 +313,41 @@ func (ed *economicsData) ComputeTxFeeInEpoch(tx data.TransactionWithFeeHandler, return ed.ComputeMoveBalanceFeeInEpoch(tx, epoch) } +// ComputeRelayedTxFees returns the both the total fee for the entire relayed tx and the relayed only fee +func (ed *economicsData) ComputeRelayedTxFees(tx data.TransactionWithFeeHandler) (*big.Int, *big.Int, error) { + innerTxs := tx.GetUserTransactions() + if len(innerTxs) == 0 { + return big.NewInt(0), big.NewInt(0), process.ErrEmptyInnerTransactions + } + + feesForInnerTxs := ed.getTotalFeesRequiredForInnerTxs(innerTxs) + + relayerUnguardedMoveBalanceFee := core.SafeMul(ed.GasPriceForMove(tx), ed.MinGasLimit()) + relayerTotalMoveBalanceFee := ed.ComputeMoveBalanceFee(tx) + relayerMoveBalanceFeeDiff := big.NewInt(0).Sub(relayerTotalMoveBalanceFee, relayerUnguardedMoveBalanceFee) + + relayerFee := big.NewInt(0).Mul(relayerUnguardedMoveBalanceFee, big.NewInt(int64(len(innerTxs)))) + relayerFee.Add(relayerFee, relayerMoveBalanceFeeDiff) // add the difference in case of guarded relayed tx + + totalFee := big.NewInt(0).Add(relayerFee, feesForInnerTxs) + + return relayerFee, totalFee, nil +} + +func (ed *economicsData) getTotalFeesRequiredForInnerTxs(innerTxs []data.TransactionHandler) *big.Int { + totalFees := big.NewInt(0) + for _, innerTx := range innerTxs { + gasToUse := innerTx.GetGasLimit() - ed.ComputeGasLimit(innerTx) + moveBalanceUserFee := ed.ComputeMoveBalanceFee(innerTx) + processingUserFee := ed.ComputeFeeForProcessing(innerTx, gasToUse) + innerTxFee := big.NewInt(0).Add(moveBalanceUserFee, processingUserFee) + + totalFees.Add(totalFees, innerTxFee) + } + + return totalFees +} + // SplitTxGasInCategories returns the gas split per categories func (ed *economicsData) SplitTxGasInCategories(tx data.TransactionWithFeeHandler) (gasLimitMove, gasLimitProcess uint64) { currentEpoch := ed.enableEpochsHandler.GetCurrentEpoch() @@ -518,6 +558,11 @@ func (ed *economicsData) ComputeGasUsedAndFeeBasedOnRefundValueInEpoch(tx data.T txFee := ed.ComputeTxFeeInEpoch(tx, epoch) + if len(tx.GetUserTransactions()) > 0 { + gasUnitsUsed := big.NewInt(0).Div(txFee, big.NewInt(0).SetUint64(tx.GetGasPrice())) + return gasUnitsUsed.Uint64(), txFee + } + isPenalizedTooMuchGasFlagEnabled := ed.enableEpochsHandler.IsFlagEnabledInEpoch(common.PenalizedTooMuchGasFlag, epoch) isGasPriceModifierFlagEnabled := ed.enableEpochsHandler.IsFlagEnabledInEpoch(common.GasPriceModifierFlag, epoch) flagCorrectTxFee := !isPenalizedTooMuchGasFlagEnabled && !isGasPriceModifierFlagEnabled diff --git a/process/economics/economicsData_test.go b/process/economics/economicsData_test.go index 1f2c913a826..a5ac0b0c906 100644 --- a/process/economics/economicsData_test.go +++ b/process/economics/economicsData_test.go @@ -1621,3 +1621,82 @@ func TestEconomicsData_RewardsTopUpFactor(t *testing.T) { value := economicsData.RewardsTopUpFactor() assert.Equal(t, topUpFactor, value) } + +func TestEconomicsData_ComputeRelayedTxFees(t *testing.T) { + t.Parallel() + + args := createArgsForEconomicsData(1) + minGasLimit, _ := strconv.Atoi(args.Economics.FeeSettings.GasLimitSettings[0].MinGasLimit) + tx := &transaction.Transaction{ + Nonce: 0, + Value: big.NewInt(0), + RcvAddr: []byte("rel"), + SndAddr: []byte("rel"), + GasPrice: 1, + GasLimit: uint64(minGasLimit) * 4, + InnerTransactions: []*transaction.Transaction{ + { + Nonce: 0, + Value: big.NewInt(1), + RcvAddr: []byte("rcv1"), + SndAddr: []byte("snd1"), + GasPrice: 1, + GasLimit: uint64(minGasLimit), + RelayerAddr: []byte("rel"), + }, + { + Nonce: 0, + Value: big.NewInt(1), + RcvAddr: []byte("rcv1"), + SndAddr: []byte("snd2"), + GasPrice: 1, + GasLimit: uint64(minGasLimit), + RelayerAddr: []byte("rel"), + }, + }, + } + t.Run("empty inner txs should error", func(t *testing.T) { + t.Parallel() + + economicsData, _ := economics.NewEconomicsData(args) + + txCopy := *tx + txCopy.InnerTransactions = []*transaction.Transaction{} + relayerFee, totalFee, err := economicsData.ComputeRelayedTxFees(&txCopy) + require.Equal(t, process.ErrEmptyInnerTransactions, err) + require.Equal(t, big.NewInt(0), relayerFee) + require.Equal(t, big.NewInt(0), totalFee) + }) + t.Run("should work unguarded", func(t *testing.T) { + t.Parallel() + + economicsData, _ := economics.NewEconomicsData(args) + + relayerFee, totalFee, err := economicsData.ComputeRelayedTxFees(tx) + require.NoError(t, err) + expectedRelayerFee := big.NewInt(int64(2 * uint64(minGasLimit) * tx.GetGasPrice())) // 2 move balance + require.Equal(t, expectedRelayerFee, relayerFee) + require.Equal(t, big.NewInt(int64(tx.GetGasLimit()*tx.GetGasPrice())), totalFee) + }) + t.Run("should work guarded", func(t *testing.T) { + t.Parallel() + + argsLocal := createArgsForEconomicsData(1) + argsLocal.TxVersionChecker = &testscommon.TxVersionCheckerStub{ + IsGuardedTransactionCalled: func(tx *transaction.Transaction) bool { + return len(tx.InnerTransactions) > 0 // only the relayed tx is guarded + }, + } + economicsData, _ := economics.NewEconomicsData(argsLocal) + + extraGasLimitGuardedTx, _ := strconv.Atoi(argsLocal.Economics.FeeSettings.GasLimitSettings[0].ExtraGasLimitGuardedTx) + + txCopy := *tx + txCopy.GasLimit += uint64(extraGasLimitGuardedTx) + relayerFee, totalFee, err := economicsData.ComputeRelayedTxFees(&txCopy) + require.NoError(t, err) + expectedRelayerFee := big.NewInt(int64(2*uint64(minGasLimit)*txCopy.GetGasPrice() + uint64(extraGasLimitGuardedTx)*txCopy.GetGasPrice())) // 2 move balance + require.Equal(t, expectedRelayerFee, relayerFee) + require.Equal(t, big.NewInt(int64(txCopy.GetGasLimit()*txCopy.GetGasPrice())), totalFee) + }) +} diff --git a/process/errors.go b/process/errors.go index 7e585f6725c..c15f2f0129e 100644 --- a/process/errors.go +++ b/process/errors.go @@ -1268,3 +1268,6 @@ var ErrRelayedTxV3InvalidDataField = errors.New("invalid data field") // ErrMultipleRelayedTxTypesIsNotAllowed signals that multiple types of relayed tx is not allowed var ErrMultipleRelayedTxTypesIsNotAllowed = errors.New("multiple relayed tx types is not allowed") + +// ErrEmptyInnerTransactions signals that the inner transactions slice is empty +var ErrEmptyInnerTransactions = errors.New("empty inner transactions") diff --git a/process/interface.go b/process/interface.go index 21197ad7a8b..8ad4cb1f373 100644 --- a/process/interface.go +++ b/process/interface.go @@ -699,6 +699,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 + ComputeRelayedTxFees(tx data.TransactionWithFeeHandler) (*big.Int, *big.Int, error) } // TxGasHandler handles a transaction gas and gas cost @@ -1363,6 +1364,5 @@ type SentSignaturesTracker interface { // RelayedTxV3Processor defines a component able to check and process relayed transactions v3 type RelayedTxV3Processor interface { CheckRelayedTx(tx *transaction.Transaction) error - ComputeRelayedTxFees(tx *transaction.Transaction) (*big.Int, *big.Int) IsInterfaceNil() bool } diff --git a/process/transaction/relayedTxV3Processor.go b/process/transaction/relayedTxV3Processor.go index 099bace7a8c..1c25ad46214 100644 --- a/process/transaction/relayedTxV3Processor.go +++ b/process/transaction/relayedTxV3Processor.go @@ -5,7 +5,6 @@ import ( "fmt" "math/big" - "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/process" @@ -94,36 +93,6 @@ func (proc *relayedTxV3Processor) CheckRelayedTx(tx *transaction.Transaction) er return nil } -// ComputeRelayedTxFees returns the both the total fee for the entire relayed tx and the relayed only fee -func (proc *relayedTxV3Processor) ComputeRelayedTxFees(tx *transaction.Transaction) (*big.Int, *big.Int) { - feesForInnerTxs := proc.getTotalFeesRequiredForInnerTxs(tx.InnerTransactions) - - relayerUnguardedMoveBalanceFee := core.SafeMul(proc.economicsFee.GasPriceForMove(tx), proc.economicsFee.MinGasLimit()) - relayerTotalMoveBalanceFee := proc.economicsFee.ComputeMoveBalanceFee(tx) - relayerMoveBalanceFeeDiff := big.NewInt(0).Sub(relayerTotalMoveBalanceFee, relayerUnguardedMoveBalanceFee) - - relayerFee := big.NewInt(0).Mul(relayerUnguardedMoveBalanceFee, big.NewInt(int64(len(tx.InnerTransactions)))) - relayerFee.Add(relayerFee, relayerMoveBalanceFeeDiff) // add the difference in case of guarded relayed tx - - totalFee := big.NewInt(0).Add(relayerFee, feesForInnerTxs) - - return relayerFee, totalFee -} - -func (proc *relayedTxV3Processor) getTotalFeesRequiredForInnerTxs(innerTxs []*transaction.Transaction) *big.Int { - totalFees := big.NewInt(0) - for _, innerTx := range innerTxs { - gasToUse := innerTx.GetGasLimit() - proc.economicsFee.ComputeGasLimit(innerTx) - moveBalanceUserFee := proc.economicsFee.ComputeMoveBalanceFee(innerTx) - processingUserFee := proc.economicsFee.ComputeFeeForProcessing(innerTx, gasToUse) - innerTxFee := big.NewInt(0).Add(moveBalanceUserFee, processingUserFee) - - totalFees.Add(totalFees, innerTxFee) - } - - return totalFees -} - func (proc *relayedTxV3Processor) computeRelayedTxMinGasLimit(tx *transaction.Transaction) uint64 { relayedTxGasLimit := proc.economicsFee.ComputeGasLimit(tx) relayedTxMinGasLimit := proc.economicsFee.MinGasLimit() diff --git a/process/transaction/relayedTxV3Processor_test.go b/process/transaction/relayedTxV3Processor_test.go index 01d298b5de4..7f6495ebd92 100644 --- a/process/transaction/relayedTxV3Processor_test.go +++ b/process/transaction/relayedTxV3Processor_test.go @@ -16,10 +16,7 @@ import ( "github.com/stretchr/testify/require" ) -const ( - minGasLimit = uint64(1) - guardedTxExtraGas = uint64(10) -) +const minGasLimit = uint64(1) func getDefaultTx() *coreTransaction.Transaction { return &coreTransaction.Transaction{ @@ -250,65 +247,3 @@ func TestRelayedTxV3Processor_CheckRelayedTx(t *testing.T) { require.NoError(t, err) }) } - -func TestRelayedTxV3Processor_ComputeRelayedTxFees(t *testing.T) { - t.Parallel() - - t.Run("should work unguarded", func(t *testing.T) { - t.Parallel() - - args := createMockArgRelayedTxV3Processor() - args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ - ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { - return big.NewInt(int64(minGasLimit * tx.GetGasPrice())) - }, - MinGasLimitCalled: func() uint64 { - return minGasLimit - }, - GasPriceForMoveCalled: func(tx data.TransactionWithFeeHandler) uint64 { - return tx.GetGasPrice() - }, - } - proc, err := transaction.NewRelayedTxV3Processor(args) - require.NoError(t, err) - - tx := getDefaultTx() - relayerFee, totalFee := proc.ComputeRelayedTxFees(tx) - expectedRelayerFee := big.NewInt(int64(2 * minGasLimit * tx.GetGasPrice())) // 2 move balance - require.Equal(t, expectedRelayerFee, relayerFee) - require.Equal(t, big.NewInt(int64(tx.GetGasLimit()*tx.GetGasPrice())), totalFee) - }) - t.Run("should work guarded", func(t *testing.T) { - t.Parallel() - - args := createMockArgRelayedTxV3Processor() - args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ - ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { - txHandler, ok := tx.(data.TransactionHandler) - require.True(t, ok) - - if len(txHandler.GetUserTransactions()) == 0 { // inner tx - return big.NewInt(int64(minGasLimit * tx.GetGasPrice())) - } - - // relayed tx - return big.NewInt(int64(minGasLimit*tx.GetGasPrice() + guardedTxExtraGas*tx.GetGasPrice())) - }, - MinGasLimitCalled: func() uint64 { - return minGasLimit - }, - GasPriceForMoveCalled: func(tx data.TransactionWithFeeHandler) uint64 { - return tx.GetGasPrice() - }, - } - proc, err := transaction.NewRelayedTxV3Processor(args) - require.NoError(t, err) - - tx := getDefaultTx() - tx.GasLimit += guardedTxExtraGas - relayerFee, totalFee := proc.ComputeRelayedTxFees(tx) - expectedRelayerFee := big.NewInt(int64(2*minGasLimit*tx.GetGasPrice() + guardedTxExtraGas*tx.GetGasPrice())) // 2 move balance - require.Equal(t, expectedRelayerFee, relayerFee) - require.Equal(t, big.NewInt(int64(tx.GetGasLimit()*tx.GetGasPrice())), totalFee) - }) -} diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 0ce75c6f913..841e9aa8f25 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -232,7 +232,7 @@ func (txProc *txProcessor) ProcessTransaction(tx *transaction.Transaction) (vmco switch txType { case process.MoveBalance: - err = txProc.processMoveBalance(tx, acntSnd, acntDst, dstShardTxType, nil, false) + err = txProc.processMoveBalance(tx, acntSnd, acntDst, dstShardTxType, nil, false, false) if err != nil { return vmcommon.UserError, txProc.executeAfterFailedMoveBalanceTransaction(tx, err) } @@ -467,6 +467,7 @@ func (txProc *txProcessor) processMoveBalance( destShardTxType process.TransactionType, originalTxHash []byte, isUserTxOfRelayed bool, + isUserTxOfRelayedV3 bool, ) error { moveBalanceCost, totalCost, err := txProc.processTxFee(tx, acntSrc, acntDst, destShardTxType, isUserTxOfRelayed) @@ -530,6 +531,10 @@ func (txProc *txProcessor) processMoveBalance( txProc.txFeeHandler.ProcessTransactionFee(moveBalanceCost, big.NewInt(0), txHash) } + if isUserTxOfRelayedV3 { + return txProc.createRefundSCRForMoveBalance(tx, txHash, originalTxHash, moveBalanceCost) + } + return nil } @@ -670,7 +675,11 @@ func (txProc *txProcessor) processRelayedTxV3( snapshot := txProc.accounts.JournalLen() // process fees on both relayer and sender - relayerFee, totalFee := txProc.relayedTxV3Processor.ComputeRelayedTxFees(tx) + relayerFee, totalFee, err := txProc.economicsFee.ComputeRelayedTxFees(tx) + if err != nil { + return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, err) + } + err = txProc.processTxAtRelayer(relayerAcnt, totalFee, relayerFee, tx) if err != nil { return 0, err @@ -988,7 +997,8 @@ func (txProc *txProcessor) processUserTx( returnCode := vmcommon.Ok switch txType { case process.MoveBalance: - err = txProc.processMoveBalance(userTx, acntSnd, acntDst, dstShardTxType, originalTxHash, true) + isUserTxOfRelayedV3 := len(originalTx.InnerTransactions) > 0 + err = txProc.processMoveBalance(userTx, acntSnd, acntDst, dstShardTxType, originalTxHash, true, isUserTxOfRelayedV3) intraShard := txProc.shardCoordinator.SameShard(userTx.SndAddr, userTx.RcvAddr) if err == nil && intraShard { txProc.createCompleteEventLog(scrFromTx, originalTxHash) @@ -1216,6 +1226,31 @@ func (txProc *txProcessor) createCompleteEventLog(scr data.TransactionHandler, o } } +func (txProc *txProcessor) createRefundSCRForMoveBalance( + tx *transaction.Transaction, + txHash []byte, + originalTxHash []byte, + consumedFee *big.Int, +) error { + providedFee := big.NewInt(0).Mul(big.NewInt(0).SetUint64(tx.GasLimit), big.NewInt(0).SetUint64(tx.GasPrice)) + refundValue := big.NewInt(0).Sub(providedFee, consumedFee) + + refundGasToRelayerSCR := &smartContractResult.SmartContractResult{ + Nonce: tx.Nonce, + Value: refundValue, + RcvAddr: tx.RelayerAddr, + SndAddr: tx.SndAddr, + PrevTxHash: txHash, + OriginalTxHash: originalTxHash, + GasPrice: tx.GetGasPrice(), + CallType: vm.DirectCall, + ReturnMessage: []byte(core.GasRefundForRelayerMessage), + OriginalSender: tx.RelayerAddr, + } + + return txProc.scrForwarder.AddIntermediateTransactions([]data.TransactionHandler{refundGasToRelayerSCR}) +} + // IsInterfaceNil returns true if there is no value under the interface func (txProc *txProcessor) IsInterfaceNil() bool { return txProc == nil diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index 2f19983bdcb..a1303154920 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -2231,6 +2231,15 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { return big.NewInt(1) }, + ComputeRelayedTxFeesCalled: func(tx data.TransactionWithFeeHandler) (*big.Int, *big.Int, error) { + relayerFee := big.NewInt(0).SetInt64(int64(len(tx.GetUserTransactions()))) // gasPrice = 1 + totalFee := *relayerFee + for _, innerTx := range tx.GetUserTransactions() { + totalFee.Add(&totalFee, big.NewInt(0).SetUint64(innerTx.GetGasLimit())) + } + + return relayerFee, &totalFee, nil + }, } args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(txproc.ArgRelayedTxV3Processor{ EconomicsFee: args.EconomicsFee, @@ -2345,6 +2354,15 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { return big.NewInt(int64(tx.GetGasPrice() * tx.GetGasLimit())) }, + ComputeRelayedTxFeesCalled: func(tx data.TransactionWithFeeHandler) (*big.Int, *big.Int, error) { + relayerFee := big.NewInt(0).SetInt64(int64(len(tx.GetUserTransactions()))) // gasPrice = 1 + totalFee := *relayerFee + for _, innerTx := range tx.GetUserTransactions() { + totalFee.Add(&totalFee, big.NewInt(0).SetUint64(innerTx.GetGasLimit())) + } + + return relayerFee, &totalFee, nil + }, } args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(txproc.ArgRelayedTxV3Processor{ EconomicsFee: args.EconomicsFee, @@ -2521,6 +2539,15 @@ func testProcessRelayedTransactionV3( ComputeGasLimitCalled: func(tx data.TransactionWithFeeHandler) uint64 { return 4 }, + ComputeRelayedTxFeesCalled: func(tx data.TransactionWithFeeHandler) (*big.Int, *big.Int, error) { + relayerFee := big.NewInt(0).SetInt64(int64(len(tx.GetUserTransactions()))) // gasPrice = 1 + totalFee := *relayerFee + for _, innerTx := range tx.GetUserTransactions() { + totalFee.Add(&totalFee, big.NewInt(0).SetUint64(innerTx.GetGasLimit())) + } + + return relayerFee, &totalFee, nil + }, } args.RelayedTxV3Processor, _ = txproc.NewRelayedTxV3Processor(txproc.ArgRelayedTxV3Processor{ EconomicsFee: args.EconomicsFee, diff --git a/testscommon/economicsmocks/economicsDataHandlerStub.go b/testscommon/economicsmocks/economicsDataHandlerStub.go index b6cf36f4491..3c63a32aa60 100644 --- a/testscommon/economicsmocks/economicsDataHandlerStub.go +++ b/testscommon/economicsmocks/economicsDataHandlerStub.go @@ -46,6 +46,7 @@ type EconomicsHandlerStub struct { ComputeGasLimitInEpochCalled func(tx data.TransactionWithFeeHandler, epoch uint32) uint64 ComputeGasUsedAndFeeBasedOnRefundValueInEpochCalled func(tx data.TransactionWithFeeHandler, refundValue *big.Int, epoch uint32) (uint64, *big.Int) ComputeTxFeeBasedOnGasUsedInEpochCalled func(tx data.TransactionWithFeeHandler, gasUsed uint64, epoch uint32) *big.Int + ComputeRelayedTxFeesCalled func(tx data.TransactionWithFeeHandler) (*big.Int, *big.Int, error) } // ComputeFeeForProcessing - @@ -356,6 +357,14 @@ func (e *EconomicsHandlerStub) ComputeTxFeeBasedOnGasUsedInEpoch(tx data.Transac return nil } +// ComputeRelayedTxFees - +func (e *EconomicsHandlerStub) ComputeRelayedTxFees(tx data.TransactionWithFeeHandler) (*big.Int, *big.Int, error) { + if e.ComputeRelayedTxFeesCalled != nil { + return e.ComputeRelayedTxFeesCalled(tx) + } + return big.NewInt(0), big.NewInt(0), nil +} + // IsInterfaceNil returns true if there is no value under the interface func (e *EconomicsHandlerStub) IsInterfaceNil() bool { return e == nil diff --git a/testscommon/economicsmocks/economicsHandlerMock.go b/testscommon/economicsmocks/economicsHandlerMock.go index 88a54c90e72..98ddeb985c4 100644 --- a/testscommon/economicsmocks/economicsHandlerMock.go +++ b/testscommon/economicsmocks/economicsHandlerMock.go @@ -46,6 +46,7 @@ type EconomicsHandlerMock struct { ComputeGasLimitInEpochCalled func(tx data.TransactionWithFeeHandler, epoch uint32) uint64 ComputeGasUsedAndFeeBasedOnRefundValueInEpochCalled func(tx data.TransactionWithFeeHandler, refundValue *big.Int, epoch uint32) (uint64, *big.Int) ComputeTxFeeBasedOnGasUsedInEpochCalled func(tx data.TransactionWithFeeHandler, gasUsed uint64, epoch uint32) *big.Int + ComputeRelayedTxFeesCalled func(tx data.TransactionWithFeeHandler) (*big.Int, *big.Int, error) } // LeaderPercentage - @@ -335,6 +336,14 @@ func (ehm *EconomicsHandlerMock) ComputeTxFeeBasedOnGasUsedInEpoch(tx data.Trans return nil } +// ComputeRelayedTxFees - +func (ehm *EconomicsHandlerMock) ComputeRelayedTxFees(tx data.TransactionWithFeeHandler) (*big.Int, *big.Int, error) { + if ehm.ComputeRelayedTxFeesCalled != nil { + return ehm.ComputeRelayedTxFeesCalled(tx) + } + return big.NewInt(0), big.NewInt(0), nil +} + // IsInterfaceNil returns true if there is no value under the interface func (ehm *EconomicsHandlerMock) IsInterfaceNil() bool { return ehm == nil diff --git a/testscommon/processMocks/relayedTxV3ProcessorMock.go b/testscommon/processMocks/relayedTxV3ProcessorMock.go index 287adbb35a0..85af9584af5 100644 --- a/testscommon/processMocks/relayedTxV3ProcessorMock.go +++ b/testscommon/processMocks/relayedTxV3ProcessorMock.go @@ -1,23 +1,12 @@ package processMocks import ( - "math/big" - "github.com/multiversx/mx-chain-core-go/data/transaction" ) // RelayedTxV3ProcessorMock - type RelayedTxV3ProcessorMock struct { - ComputeRelayedTxFeesCalled func(tx *transaction.Transaction) (*big.Int, *big.Int) - CheckRelayedTxCalled func(tx *transaction.Transaction) error -} - -// ComputeRelayedTxFees - -func (mock *RelayedTxV3ProcessorMock) ComputeRelayedTxFees(tx *transaction.Transaction) (*big.Int, *big.Int) { - if mock.ComputeRelayedTxFeesCalled != nil { - return mock.ComputeRelayedTxFeesCalled(tx) - } - return nil, nil + CheckRelayedTxCalled func(tx *transaction.Transaction) error } // CheckRelayedTx - From 9588ce7c8dee468d2b5bf78b86351167b61166d5 Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 11 Jun 2024 15:38:15 +0300 Subject: [PATCH 325/503] add comment --- node/chainSimulator/chainSimulator.go | 1 + 1 file changed, 1 insertion(+) diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index ad77ece5fd4..8004d629b2f 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -60,6 +60,7 @@ type ArgsChainSimulator struct { AlterConfigsFunction func(cfg *config.Configs) } +// ArgsBaseChainSimulator holds the arguments needed to create a new instance of simulator type ArgsBaseChainSimulator struct { ArgsChainSimulator ConsensusGroupSize uint32 From 1a92d802136f55377cc5fcdcd5bb3b45f5c04c57 Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 11 Jun 2024 16:11:59 +0300 Subject: [PATCH 326/503] fixes after branch update --- .../vm/esdtImprovements_test.go | 237 ++++++++---------- 1 file changed, 110 insertions(+), 127 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 008844e3ddc..e3d83e092f8 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -38,7 +38,8 @@ var log = logger.GetOrCreate("integrationTests/chainSimulator/vm") // Test scenario #1 // // Initial setup: Create fungible, NFT, SFT and metaESDT tokens -// (before the activation of DynamicEsdtFlag) +// +// (before the activation of DynamicEsdtFlag) // // 1.check that the metadata for all tokens is saved on the system account // 2. wait for DynamicEsdtFlag activation @@ -86,20 +87,18 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost @@ -712,20 +711,18 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost @@ -891,20 +888,18 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost @@ -1031,20 +1026,18 @@ func TestChainSimulator_NFT_ESDTMetaDataUpdate(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost @@ -1168,20 +1161,18 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost @@ -1319,20 +1310,18 @@ func TestChainSimulator_NFT_ESDTSetNewURIs(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost @@ -1466,20 +1455,18 @@ func TestChainSimulator_NFT_ESDTModifyRoyalties(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost @@ -1602,20 +1589,18 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost @@ -1720,20 +1705,18 @@ func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost From 627a72d0cf1f4acd180f9bbf848220a9ee1cf247 Mon Sep 17 00:00:00 2001 From: radu chis Date: Wed, 12 Jun 2024 10:40:36 +0300 Subject: [PATCH 327/503] fix after review --- node/node.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/node/node.go b/node/node.go index fb485671350..d4261330b28 100644 --- a/node/node.go +++ b/node/node.go @@ -960,12 +960,12 @@ func (n *Node) GetAccountWithKeys(address string, options api.AccountQueryOption return api.AccountResponse{}, api.BlockInfo{}, err } - if accInfo.account == nil || accInfo.account.DataTrie() == nil { - return accInfo.accountResponse, accInfo.block, nil - } - var keys map[string]string if options.WithKeys { + if accInfo.account == nil || accInfo.account.DataTrie() == nil { + return accInfo.accountResponse, accInfo.block, nil + } + keys, err = n.getKeys(accInfo.account, ctx) if err != nil { return api.AccountResponse{}, api.BlockInfo{}, err From 75ef2631e72298207500b02251518f3943a32702 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 12 Jun 2024 16:20:05 +0300 Subject: [PATCH 328/503] updated the fix for relayed fee be active only on move balance + added integration test + fixed other tests --- .../relayedTx/relayedTx_test.go | 255 ++++++++++++++++-- .../multiShard/relayedTx/common.go | 38 ++- .../relayedTx/edgecases/edgecases_test.go | 25 +- .../multiShard/relayedTx/relayedTx_test.go | 5 +- integrationTests/testProcessorNode.go | 1 - process/transaction/baseProcess.go | 10 +- process/transaction/baseProcess_test.go | 2 + process/transaction/metaProcess.go | 3 +- process/transaction/shardProcess.go | 35 +-- process/transaction/shardProcess_test.go | 2 +- 10 files changed, 291 insertions(+), 85 deletions(-) diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index f23a4080995..dc7869eab98 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -2,6 +2,7 @@ package relayedTx import ( "encoding/hex" + "encoding/json" "math/big" "strconv" "strings" @@ -16,6 +17,7 @@ import ( "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" + "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/sharding" @@ -32,14 +34,20 @@ const ( maxNumOfBlocksToGenerateWhenExecutingTx = 10 ) -var oneEGLD = big.NewInt(1000000000000000000) +var ( + oneEGLD = big.NewInt(1000000000000000000) + alterConfigsFuncRelayedV3EarlyActivation = func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.RelayedTransactionsV3EnableEpoch = 1 + cfg.EpochConfig.EnableEpochs.FixRelayedMoveBalanceEnableEpoch = 1 + } +) func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } - cs := startChainSimulator(t) + cs := startChainSimulator(t, alterConfigsFuncRelayedV3EarlyActivation) defer cs.Close() initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(30000)) @@ -150,7 +158,7 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorScCalls(t *t t.Skip("this is not a short test") } - cs := startChainSimulator(t) + cs := startChainSimulator(t, alterConfigsFuncRelayedV3EarlyActivation) defer cs.Close() initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(10)) @@ -255,7 +263,199 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorScCalls(t *t } } -func startChainSimulator(t *testing.T) testsChainSimulator.ChainSimulator { +func TestFixRelayedMoveBalanceWithChainSimulator(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + expectedFeeScCall := "815285920000000" + t.Run("sc call", testFixRelayedMoveBalanceWithChainSimulatorScCall(expectedFeeScCall, expectedFeeScCall)) + + expectedFeeMoveBalanceBefore := "797500000000000" // 498 * 1500 + 50000 + 5000 + expectedFeeMoveBalanceAfter := "847000000000000" // 498 * 1500 + 50000 + 50000 + t.Run("move balance", testFixRelayedMoveBalanceWithChainSimulatorMoveBalance(expectedFeeMoveBalanceBefore, expectedFeeMoveBalanceAfter)) + +} + +func testFixRelayedMoveBalanceWithChainSimulatorScCall( + expectedFeeBeforeFix string, + expectedFeeAfterFix string, +) func(t *testing.T) { + return func(t *testing.T) { + + providedActivationEpoch := uint32(7) + alterConfigsFunc := func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.FixRelayedMoveBalanceEnableEpoch = providedActivationEpoch + } + + cs := startChainSimulator(t, alterConfigsFunc) + defer cs.Close() + + pkConv := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter() + + initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(10)) + relayer, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + // deploy adder contract + owner, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + // generate one block so the minting has effect + err = cs.GenerateBlocks(1) + require.NoError(t, err) + + scCode := wasm.GetSCCode("testData/adder.wasm") + params := []string{scCode, wasm.VMTypeHex, wasm.DummyCodeMetadataHex, "00"} + txDataDeploy := strings.Join(params, "@") + deployTx := generateTransaction(owner.Bytes, 0, make([]byte, 32), big.NewInt(0), txDataDeploy, 100000000) + + result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(deployTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + scAddress := result.Logs.Events[0].Address + scAddressBytes, _ := pkConv.Decode(scAddress) + + // fast-forward until epoch 4 + err = cs.GenerateBlocksUntilEpochIsReached(int32(4)) + require.NoError(t, err) + + // send relayed tx + txDataAdd := "add@" + hex.EncodeToString(big.NewInt(1).Bytes()) + innerTx := generateTransaction(owner.Bytes, 1, scAddressBytes, big.NewInt(0), txDataAdd, 3000000) + marshalledTx, err := json.Marshal(innerTx) + require.NoError(t, err) + txData := []byte("relayedTx@" + hex.EncodeToString(marshalledTx)) + gasLimit := 50000 + uint64(len(txData))*1500 + innerTx.GasLimit + + relayedTx := generateTransaction(relayer.Bytes, 0, owner.Bytes, big.NewInt(0), string(txData), gasLimit) + + result, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + // send relayed tx, fix still not active + innerTx = generateTransaction(owner.Bytes, 2, scAddressBytes, big.NewInt(0), txDataAdd, 3000000) + marshalledTx, err = json.Marshal(innerTx) + require.NoError(t, err) + txData = []byte("relayedTx@" + hex.EncodeToString(marshalledTx)) + gasLimit = 50000 + uint64(len(txData))*1500 + innerTx.GasLimit + + relayedTx = generateTransaction(relayer.Bytes, 1, owner.Bytes, big.NewInt(0), string(txData), gasLimit) + + relayerBalanceBefore := getBalance(t, cs, relayer) + + result, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + relayerBalanceAfter := getBalance(t, cs, relayer) + + feeConsumed := big.NewInt(0).Sub(relayerBalanceBefore, relayerBalanceAfter) + + require.Equal(t, expectedFeeBeforeFix, feeConsumed.String()) + + // fast-forward until the fix is active + err = cs.GenerateBlocksUntilEpochIsReached(int32(providedActivationEpoch)) + require.NoError(t, err) + + // send relayed tx after fix + innerTx = generateTransaction(owner.Bytes, 3, scAddressBytes, big.NewInt(0), txDataAdd, 3000000) + marshalledTx, err = json.Marshal(innerTx) + require.NoError(t, err) + txData = []byte("relayedTx@" + hex.EncodeToString(marshalledTx)) + gasLimit = 50000 + uint64(len(txData))*1500 + innerTx.GasLimit + + relayedTx = generateTransaction(relayer.Bytes, 2, owner.Bytes, big.NewInt(0), string(txData), gasLimit) + + relayerBalanceBefore = getBalance(t, cs, relayer) + + result, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + relayerBalanceAfter = getBalance(t, cs, relayer) + + feeConsumed = big.NewInt(0).Sub(relayerBalanceBefore, relayerBalanceAfter) + + require.Equal(t, expectedFeeAfterFix, feeConsumed.String()) + } +} + +func testFixRelayedMoveBalanceWithChainSimulatorMoveBalance( + expectedFeeBeforeFix string, + expectedFeeAfterFix string, +) func(t *testing.T) { + return func(t *testing.T) { + + providedActivationEpoch := uint32(5) + alterConfigsFunc := func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.FixRelayedMoveBalanceEnableEpoch = providedActivationEpoch + } + + cs := startChainSimulator(t, alterConfigsFunc) + defer cs.Close() + + initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(10)) + relayer, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + sender, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + receiver, err := cs.GenerateAndMintWalletAddress(0, big.NewInt(0)) + require.NoError(t, err) + + // generate one block so the minting has effect + err = cs.GenerateBlocks(1) + require.NoError(t, err) + + // send relayed tx + innerTx := generateTransaction(sender.Bytes, 0, receiver.Bytes, oneEGLD, "", 50000) + marshalledTx, err := json.Marshal(innerTx) + require.NoError(t, err) + txData := []byte("relayedTx@" + hex.EncodeToString(marshalledTx)) + gasLimit := 50000 + uint64(len(txData))*1500 + innerTx.GasLimit + + relayedTx := generateTransaction(relayer.Bytes, 0, sender.Bytes, big.NewInt(0), string(txData), gasLimit) + + relayerBalanceBefore := getBalance(t, cs, relayer) + + _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + relayerBalanceAfter := getBalance(t, cs, relayer) + + feeConsumed := big.NewInt(0).Sub(relayerBalanceBefore, relayerBalanceAfter) + + require.Equal(t, expectedFeeBeforeFix, feeConsumed.String()) + + // fast-forward until the fix is active + err = cs.GenerateBlocksUntilEpochIsReached(int32(providedActivationEpoch)) + require.NoError(t, err) + + // send relayed tx + innerTx = generateTransaction(sender.Bytes, 1, receiver.Bytes, oneEGLD, "", 50000) + marshalledTx, err = json.Marshal(innerTx) + require.NoError(t, err) + txData = []byte("relayedTx@" + hex.EncodeToString(marshalledTx)) + gasLimit = 50000 + uint64(len(txData))*1500 + innerTx.GasLimit + + relayedTx = generateTransaction(relayer.Bytes, 1, sender.Bytes, big.NewInt(0), string(txData), gasLimit) + + relayerBalanceBefore = getBalance(t, cs, relayer) + + _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + relayerBalanceAfter = getBalance(t, cs, relayer) + + feeConsumed = big.NewInt(0).Sub(relayerBalanceBefore, relayerBalanceAfter) + + require.Equal(t, expectedFeeAfterFix, feeConsumed.String()) + } +} + +func startChainSimulator( + t *testing.T, + alterConfigsFunction func(cfg *config.Configs), +) testsChainSimulator.ChainSimulator { roundDurationInMillis := uint64(6000) roundsPerEpoch := core.OptionalUint64{ HasValue: true, @@ -263,22 +463,19 @@ func startChainSimulator(t *testing.T) testsChainSimulator.ChainSimulator { } cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: 3, - GenesisTimestamp: time.Now().Unix(), - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 3, - NumNodesWaitingListShard: 3, - AlterConfigsFunction: func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.RelayedTransactionsV3EnableEpoch = 1 - cfg.EpochConfig.EnableEpochs.FixRelayedMoveBalanceEnableEpoch = 1 - }, + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, + AlterConfigsFunction: alterConfigsFunction, ConsensusGroupSize: 1, MetaChainConsensusGroupSize: 1, }) @@ -344,6 +541,10 @@ func checkSCRSucceeded( require.NoError(t, err) require.Equal(t, transaction.TxStatusSuccess, tx.Status) + if tx.ReturnMessage == core.GasRefundForRelayerMessage { + return + } + require.GreaterOrEqual(t, len(tx.Logs.Events), 1) for _, event := range tx.Logs.Events { if event.Identifier == core.WriteLogIdentifier { @@ -353,3 +554,17 @@ func checkSCRSucceeded( require.Equal(t, core.CompletedTxEventIdentifier, event.Identifier) } } + +func getBalance( + t *testing.T, + cs testsChainSimulator.ChainSimulator, + address dtos.WalletAddress, +) *big.Int { + account, err := cs.GetAccount(address) + require.NoError(t, err) + + balance, ok := big.NewInt(0).SetString(account.Balance, 10) + require.True(t, ok) + + return balance +} diff --git a/integrationTests/multiShard/relayedTx/common.go b/integrationTests/multiShard/relayedTx/common.go index 5e9768a77ce..037fb79138f 100644 --- a/integrationTests/multiShard/relayedTx/common.go +++ b/integrationTests/multiShard/relayedTx/common.go @@ -8,30 +8,37 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/state" ) // CreateGeneralSetupForRelayTxTest will create the general setup for relayed transactions -func CreateGeneralSetupForRelayTxTest(intraShardPlayers bool) ([]*integrationTests.TestProcessorNode, []int, []*integrationTests.TestWalletAccount, *integrationTests.TestWalletAccount) { +func CreateGeneralSetupForRelayTxTest(relayedV3Test bool) ([]*integrationTests.TestProcessorNode, []int, []*integrationTests.TestWalletAccount, *integrationTests.TestWalletAccount) { initialVal := big.NewInt(10000000000) - nodes, idxProposers := createAndMintNodes(initialVal) + epochsConfig := integrationTests.GetDefaultEnableEpochsConfig() + if !relayedV3Test { + epochsConfig.RelayedTransactionsV3EnableEpoch = integrationTests.UnreachableEpoch + epochsConfig.FixRelayedMoveBalanceEnableEpoch = integrationTests.UnreachableEpoch + } + nodes, idxProposers := createAndMintNodes(initialVal, epochsConfig) - players, relayerAccount := createAndMintPlayers(intraShardPlayers, nodes, initialVal) + players, relayerAccount := createAndMintPlayers(relayedV3Test, nodes, initialVal) return nodes, idxProposers, players, relayerAccount } -func createAndMintNodes(initialVal *big.Int) ([]*integrationTests.TestProcessorNode, []int) { +func createAndMintNodes(initialVal *big.Int, enableEpochsConfig *config.EnableEpochs) ([]*integrationTests.TestProcessorNode, []int) { numOfShards := 2 nodesPerShard := 2 numMetachainNodes := 1 - nodes := integrationTests.CreateNodes( + nodes := integrationTests.CreateNodesWithEnableEpochsConfig( numOfShards, nodesPerShard, numMetachainNodes, + enableEpochsConfig, ) idxProposers := make([]int, numOfShards+1) @@ -193,7 +200,8 @@ func createRelayedTx( relayer.Balance.Sub(relayer.Balance, tx.Value) - subFeesFromRelayer(tx, userTx, economicsFee, relayer) + txFee := economicsFee.ComputeTxFee(tx) + relayer.Balance.Sub(relayer.Balance, txFee) return tx } @@ -223,7 +231,8 @@ func createRelayedTxV2( relayer.Balance.Sub(relayer.Balance, tx.Value) - subFeesFromRelayer(tx, userTx, economicsFee, relayer) + txFee := economicsFee.ComputeTxFee(tx) + relayer.Balance.Sub(relayer.Balance, txFee) return tx } @@ -253,7 +262,8 @@ func createRelayedTxV3( relayer.Balance.Sub(relayer.Balance, tx.Value) - subFeesFromRelayer(tx, userTx, economicsFee, relayer) + txFee := economicsFee.ComputeTxFee(tx) + relayer.Balance.Sub(relayer.Balance, txFee) return tx } @@ -310,15 +320,3 @@ func GetUserAccount( } return nil } - -func subFeesFromRelayer(tx, userTx *transaction.Transaction, economicsFee process.FeeHandler, relayer *integrationTests.TestWalletAccount) { - relayerFee := economicsFee.ComputeMoveBalanceFee(tx) - relayer.Balance.Sub(relayer.Balance, relayerFee) - - userTxCopy := *userTx - if userTxCopy.GasLimit == 0 { // relayed v2 - userTxCopy.GasLimit = tx.GasLimit - economicsFee.ComputeGasLimit(tx) - } - userFee := economicsFee.ComputeTxFee(&userTxCopy) - relayer.Balance.Sub(relayer.Balance, userFee) -} diff --git a/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go b/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go index e2e6a3be043..72e7bafda2e 100644 --- a/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go +++ b/integrationTests/multiShard/relayedTx/edgecases/edgecases_test.go @@ -6,10 +6,8 @@ import ( "time" "github.com/multiversx/mx-chain-core-go/core/check" - "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/integrationTests" "github.com/multiversx/mx-chain-go/integrationTests/multiShard/relayedTx" - "github.com/multiversx/mx-chain-go/process" "github.com/stretchr/testify/assert" ) @@ -34,16 +32,12 @@ func TestRelayedTransactionInMultiShardEnvironmentWithNormalTxButWrongNonceShoul receiverAddress1 := []byte("12345678901234567890123456789012") receiverAddress2 := []byte("12345678901234567890123456789011") - totalFees := big.NewInt(0) - relayerInitialValue := big.NewInt(0).Set(relayer.Balance) nrRoundsToTest := int64(5) for i := int64(0); i < nrRoundsToTest; i++ { for _, player := range players { player.Nonce += 1 - relayerTx, userTx := relayedTx.CreateAndSendRelayedAndUserTx(nodes, relayer, player, receiverAddress1, sendValue, integrationTests.MinTxGasLimit, []byte("")) - appendFeeToTotalFees(relayerTx, userTx, nodes[0].EconomicsData, totalFees) - relayerTx, userTx = relayedTx.CreateAndSendRelayedAndUserTx(nodes, relayer, player, receiverAddress2, sendValue, integrationTests.MinTxGasLimit, []byte("")) - appendFeeToTotalFees(relayerTx, userTx, nodes[0].EconomicsData, totalFees) + _, _ = relayedTx.CreateAndSendRelayedAndUserTx(nodes, relayer, player, receiverAddress1, sendValue, integrationTests.MinTxGasLimit, []byte("")) + _, _ = relayedTx.CreateAndSendRelayedAndUserTx(nodes, relayer, player, receiverAddress2, sendValue, integrationTests.MinTxGasLimit, []byte("")) } round, nonce = integrationTests.ProposeAndSyncOneBlock(t, nodes, idxProposers, round, nonce) @@ -71,9 +65,8 @@ func TestRelayedTransactionInMultiShardEnvironmentWithNormalTxButWrongNonceShoul assert.Equal(t, uint64(0), account.GetNonce()) } - expectedBalance := big.NewInt(0).Sub(relayerInitialValue, totalFees) relayerAccount := relayedTx.GetUserAccount(nodes, relayer.Address) - assert.True(t, relayerAccount.GetBalance().Cmp(expectedBalance) == 0) + assert.True(t, relayerAccount.GetBalance().Cmp(relayer.Balance) == 0) } func TestRelayedTransactionInMultiShardEnvironmentWithNormalTxButWithTooMuchGas(t *testing.T) { @@ -149,15 +142,3 @@ func checkPlayerBalancesWithPenalization( assert.Equal(t, userAcc.GetNonce(), players[i].Nonce) } } - -func appendFeeToTotalFees(relayerTx, userTx *transaction.Transaction, economicsData process.EconomicsDataHandler, totalFees *big.Int) { - relayerFee := economicsData.ComputeMoveBalanceFee(relayerTx) - totalFees.Add(totalFees, relayerFee) - - userTxCopy := *userTx - if userTxCopy.GasLimit == 0 { // relayed v2 - userTxCopy.GasLimit = relayerTx.GasLimit - economicsData.ComputeGasLimit(relayerTx) - } - userFee := economicsData.ComputeTxFee(&userTxCopy) - totalFees.Add(totalFees, userFee) -} diff --git a/integrationTests/multiShard/relayedTx/relayedTx_test.go b/integrationTests/multiShard/relayedTx/relayedTx_test.go index d9ea772d7ba..cc3c2e8c0e6 100644 --- a/integrationTests/multiShard/relayedTx/relayedTx_test.go +++ b/integrationTests/multiShard/relayedTx/relayedTx_test.go @@ -447,8 +447,11 @@ func checkPlayerBalances( t *testing.T, nodes []*integrationTests.TestProcessorNode, players []*integrationTests.TestWalletAccount) { - for _, player := range players { + for idx, player := range players { userAcc := GetUserAccount(nodes, player.Address) + if idx == 5 { + print("x") + } assert.Equal(t, 0, userAcc.GetBalance().Cmp(player.Balance)) assert.Equal(t, userAcc.GetNonce(), player.Nonce) } diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index 49ef2206b41..178d0dbcc53 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -3582,6 +3582,5 @@ func GetDefaultEnableEpochsConfig() *config.EnableEpochs { DynamicGasCostForDataTrieStorageLoadEnableEpoch: UnreachableEpoch, StakingV4Step1EnableEpoch: UnreachableEpoch, StakingV4Step2EnableEpoch: UnreachableEpoch, - StakingV4Step3EnableEpoch: UnreachableEpoch, } } diff --git a/process/transaction/baseProcess.go b/process/transaction/baseProcess.go index 8b951d844da..a286bd9fb8f 100644 --- a/process/transaction/baseProcess.go +++ b/process/transaction/baseProcess.go @@ -29,6 +29,7 @@ type baseTxProcessor struct { enableEpochsHandler common.EnableEpochsHandler txVersionChecker process.TxVersionCheckerHandler guardianChecker process.GuardianChecker + txTypeHandler process.TxTypeHandler } func (txProc *baseTxProcessor) getAccounts( @@ -145,7 +146,10 @@ func (txProc *baseTxProcessor) checkTxValues( if tx.GasLimit < txProc.economicsFee.ComputeGasLimit(tx) { return process.ErrNotEnoughGasInUserTx } - txFee = txProc.computeTxFee(tx) + + _, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(tx) + isMoveBalance := dstShardTxType == process.MoveBalance + txFee = txProc.computeTxFee(tx, isMoveBalance) } else { txFee = txProc.economicsFee.ComputeTxFee(tx) } @@ -172,8 +176,8 @@ func (txProc *baseTxProcessor) checkTxValues( return nil } -func (txProc *baseTxProcessor) computeTxFee(tx *transaction.Transaction) *big.Int { - if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { +func (txProc *baseTxProcessor) computeTxFee(tx *transaction.Transaction, isInnerTxMoveBalance bool) *big.Int { + if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) && isInnerTxMoveBalance { return txProc.computeTxFeeAfterMoveBalanceFix(tx) } diff --git a/process/transaction/baseProcess_test.go b/process/transaction/baseProcess_test.go index 3527748a72e..7795c1a0f6a 100644 --- a/process/transaction/baseProcess_test.go +++ b/process/transaction/baseProcess_test.go @@ -44,6 +44,7 @@ func createMockBaseTxProcessor() *baseTxProcessor { enableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.PenalizedTooMuchGasFlag), txVersionChecker: &testscommon.TxVersionCheckerStub{}, guardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, + txTypeHandler: &testscommon.TxTypeHandlerMock{}, } return &baseProc @@ -212,6 +213,7 @@ func TestBaseTxProcessor_VerifyGuardian(t *testing.T) { enableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.PenalizedTooMuchGasFlag), txVersionChecker: &testscommon.TxVersionCheckerStub{}, guardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, + txTypeHandler: &testscommon.TxTypeHandlerMock{}, } notGuardedAccount := &stateMock.UserAccountStub{} diff --git a/process/transaction/metaProcess.go b/process/transaction/metaProcess.go index 62a8ad71d32..90aad3add00 100644 --- a/process/transaction/metaProcess.go +++ b/process/transaction/metaProcess.go @@ -20,7 +20,6 @@ var _ process.TransactionProcessor = (*metaTxProcessor)(nil) // txProcessor implements TransactionProcessor interface and can modify account states according to a transaction type metaTxProcessor struct { *baseTxProcessor - txTypeHandler process.TxTypeHandler enableEpochsHandler common.EnableEpochsHandler } @@ -89,11 +88,11 @@ func NewMetaTxProcessor(args ArgsNewMetaTxProcessor) (*metaTxProcessor, error) { enableEpochsHandler: args.EnableEpochsHandler, txVersionChecker: args.TxVersionChecker, guardianChecker: args.GuardianChecker, + txTypeHandler: args.TxTypeHandler, } txProc := &metaTxProcessor{ baseTxProcessor: baseTxProcess, - txTypeHandler: args.TxTypeHandler, enableEpochsHandler: args.EnableEpochsHandler, } diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 841e9aa8f25..f28426af7d3 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -38,7 +38,6 @@ type relayedFees struct { type txProcessor struct { *baseTxProcessor txFeeHandler process.TransactionFeeHandler - txTypeHandler process.TxTypeHandler receiptForwarder process.IntermediateTransactionHandler badTxForwarder process.IntermediateTransactionHandler argsParser process.ArgumentsParser @@ -160,12 +159,12 @@ func NewTxProcessor(args ArgsNewTxProcessor) (*txProcessor, error) { enableEpochsHandler: args.EnableEpochsHandler, txVersionChecker: args.TxVersionChecker, guardianChecker: args.GuardianChecker, + txTypeHandler: args.TxTypeHandler, } txProc := &txProcessor{ baseTxProcessor: baseTxProcess, txFeeHandler: args.TxFeeHandler, - txTypeHandler: args.TxTypeHandler, receiptForwarder: args.ReceiptForwarder, badTxForwarder: args.BadTxForwarder, argsParser: args.ArgsParser, @@ -395,7 +394,8 @@ func (txProc *txProcessor) processTxFee( } if isUserTxOfRelayed { - totalCost := txProc.computeTxFee(tx) + isUserTxMoveBalance := dstShardTxType == process.MoveBalance + totalCost := txProc.computeTxFee(tx, isUserTxMoveBalance) err := acntSnd.SubFromBalance(totalCost) if err != nil { @@ -712,11 +712,11 @@ func (txProc *txProcessor) processRelayedTxV3( log.Trace("failed to execute all inner transactions", "total", len(innerTxs), "executed transactions", len(executedUserTxs)) } - expectedInnerTxsTotalFees := big.NewInt(0).Sub(totalFee, relayerFee) - if innerTxsTotalFees.Cmp(expectedInnerTxsTotalFees) != 0 { + expectedMaxInnerTxsTotalFees := big.NewInt(0).Sub(totalFee, relayerFee) + if innerTxsTotalFees.Cmp(expectedMaxInnerTxsTotalFees) > 0 { log.Debug("reverting relayed transaction, total inner transactions fees mismatch", - "computed fee at relayer", expectedInnerTxsTotalFees.Uint64(), - "total inner fees", innerTxsTotalFees.Uint64()) + "computed max fees at relayer", expectedMaxInnerTxsTotalFees.Uint64(), + "total inner fees consumed", innerTxsTotalFees.Uint64()) errRevert := txProc.accounts.RevertToSnapshot(snapshot) if errRevert != nil { @@ -735,7 +735,9 @@ func (txProc *txProcessor) processInnerTx( originalTxHash []byte, ) (*big.Int, vmcommon.ReturnCode, error) { - txFee := txProc.computeTxFee(innerTx) + _, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(innerTx) + isMoveBalance := dstShardTxType == process.MoveBalance + txFee := txProc.computeTxFee(innerTx, isMoveBalance) acntSnd, err := txProc.getAccountFromAddress(innerTx.SndAddr) if err != nil { @@ -854,7 +856,9 @@ func (txProc *txProcessor) processRelayedTx( func (txProc *txProcessor) computeRelayedTxFees(tx, userTx *transaction.Transaction) relayedFees { relayerFee := txProc.economicsFee.ComputeMoveBalanceFee(tx) totalFee := txProc.economicsFee.ComputeTxFee(tx) - if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { + _, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(userTx) + isMoveBalance := dstShardTxType == process.MoveBalance + if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) && isMoveBalance { userFee := txProc.computeTxFeeAfterMoveBalanceFix(userTx) totalFee = totalFee.Add(relayerFee, userFee) @@ -889,7 +893,9 @@ func (txProc *txProcessor) removeValueAndConsumedFeeFromUser( return err } - consumedFee := txProc.computeTxFee(userTx) + _, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(userTx) + isMoveBalance := dstShardTxType == process.MoveBalance + consumedFee := txProc.computeTxFee(userTx, isMoveBalance) err = userAcnt.SubFromBalance(consumedFee) if err != nil { @@ -934,9 +940,6 @@ func (txProc *txProcessor) processMoveBalanceCostRelayedUserTx( ) error { moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(userTx) moveBalanceUserFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, moveBalanceGasLimit) - if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { - moveBalanceUserFee = txProc.economicsFee.ComputeMoveBalanceFee(userTx) - } userScrHash, err := core.CalculateHash(txProc.marshalizer, txProc.hasher, userScr) if err != nil { @@ -1147,18 +1150,20 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( return err } + _, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(userTx) + isMoveBalance := dstShardTxType == process.MoveBalance totalFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, userTx.GasLimit) moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(userTx) gasToUse := userTx.GetGasLimit() - moveBalanceGasLimit processingUserFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, gasToUse) - if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { + if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) && isMoveBalance { moveBalanceUserFee := txProc.economicsFee.ComputeMoveBalanceFee(userTx) totalFee = big.NewInt(0).Add(moveBalanceUserFee, processingUserFee) } senderShardID := txProc.shardCoordinator.ComputeId(userTx.SndAddr) if senderShardID != txProc.shardCoordinator.SelfId() { - if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) { + if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) && isMoveBalance { totalFee.Sub(totalFee, processingUserFee) } else { moveBalanceUserFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, moveBalanceGasLimit) diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index a1303154920..e6f4c4c9a0f 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -3182,7 +3182,7 @@ func TestTxProcessor_ConsumeMoveBalanceWithUserTx(t *testing.T) { ComputeTxFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { return big.NewInt(150) }, - ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { + ComputeFeeForProcessingCalled: func(tx data.TransactionWithFeeHandler, gasToUse uint64) *big.Int { return big.NewInt(1) }, } From fa37dae1b93822bd7ff3182070e5549704928b49 Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 14 Jun 2024 13:00:13 +0300 Subject: [PATCH 329/503] fixes --- go.mod | 2 +- go.sum | 10 ++-------- .../chainSimulator/vm/esdtImprovements_test.go | 2 +- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 3a719d45506..84157b3a840 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f - github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240529093845-2a375eef5cc1 + github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240614095805-b14f1d13b636 github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240509104009-598a37ff36b9 diff --git a/go.sum b/go.sum index 490a8453453..6b679a652b7 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,10 +399,8 @@ 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-common-go v1.5.13-0.20240614095805-b14f1d13b636 h1:M6737V6qijXGoACtcZ3HFI6ejN6G4A7Q69CZGNBKwRc= +github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240614095805-b14f1d13b636/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= @@ -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/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index e3d83e092f8..94890d8468e 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -934,7 +934,7 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), - []byte(core.ESDTMetaDataRecreate), + []byte(core.ESDTRoleNFTRecreate), } nftTokenID := txResult.Logs.Events[0].Topics[0] From 9982efd0554c2c274ff25d4c97c4aabb359d9869 Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 14 Jun 2024 14:00:26 +0300 Subject: [PATCH 330/503] new vm common --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 84157b3a840..0ab23b4b255 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f - github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240614095805-b14f1d13b636 + github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240614104805-22410d9e134e github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240509104009-598a37ff36b9 diff --git a/go.sum b/go.sum index 6b679a652b7..c39775da27d 100644 --- a/go.sum +++ b/go.sum @@ -399,8 +399,8 @@ 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.20240614095805-b14f1d13b636 h1:M6737V6qijXGoACtcZ3HFI6ejN6G4A7Q69CZGNBKwRc= -github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240614095805-b14f1d13b636/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo= +github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240614104805-22410d9e134e h1:uUNnziPQUXs7UDtwM0+32XEpkW8siBO3YNyflbAAHj8= +github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240614104805-22410d9e134e/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= From ff5ce51770f77cbcef92caf1b00fc63905417d3d Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Fri, 14 Jun 2024 15:32:13 +0300 Subject: [PATCH 331/503] fixes after review plus some tests --- factory/processing/processComponents.go | 5 +- process/block/postprocess/basePostProcess.go | 32 +-- .../block/postprocess/basePostProcess_test.go | 207 ++++++++++++++++++ 3 files changed, 226 insertions(+), 18 deletions(-) create mode 100644 process/block/postprocess/basePostProcess_test.go diff --git a/factory/processing/processComponents.go b/factory/processing/processComponents.go index 352343ce102..482343bbadf 100644 --- a/factory/processing/processComponents.go +++ b/factory/processing/processComponents.go @@ -16,6 +16,9 @@ import ( dataBlock "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/data/outport" "github.com/multiversx/mx-chain-core-go/data/receipt" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + vmcommonBuiltInFunctions "github.com/multiversx/mx-chain-vm-common-go/builtInFunctions" + nodeFactory "github.com/multiversx/mx-chain-go/cmd/node/factory" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/errChan" @@ -76,8 +79,6 @@ import ( updateDisabled "github.com/multiversx/mx-chain-go/update/disabled" updateFactory "github.com/multiversx/mx-chain-go/update/factory" "github.com/multiversx/mx-chain-go/update/trigger" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" - vmcommonBuiltInFunctions "github.com/multiversx/mx-chain-vm-common-go/builtInFunctions" ) // timeSpanForBadHeaders is the expiry time for an added block header hash diff --git a/process/block/postprocess/basePostProcess.go b/process/block/postprocess/basePostProcess.go index f15315fc9d1..26473387dd7 100644 --- a/process/block/postprocess/basePostProcess.go +++ b/process/block/postprocess/basePostProcess.go @@ -30,9 +30,9 @@ type txInfo struct { } type processedResult struct { - parent []byte - children map[string]struct{} - results [][]byte + parentKey []byte + childrenKeys map[string]struct{} + results [][]byte } const defaultCapacity = 100 @@ -201,8 +201,8 @@ func (bpp *basePostProcessor) removeProcessedResultsAndLinks(key string) ([][]by collectedProcessedResultsKeys := make([][]byte, 0, defaultCapacity) collectedProcessedResultsKeys = append(collectedProcessedResultsKeys, processedResults.results...) - // go through the children and do the same - for childKey := range processedResults.children { + // go through the childrenKeys and do the same + for childKey := range processedResults.childrenKeys { childProcessedResults, ok := bpp.removeProcessedResultsAndLinks(childKey) if !ok { continue @@ -211,10 +211,10 @@ func (bpp *basePostProcessor) removeProcessedResultsAndLinks(key string) ([][]by collectedProcessedResultsKeys = append(collectedProcessedResultsKeys, childProcessedResults...) } - // remove link from parent - parent, ok := bpp.mapProcessedResult[string(processedResults.parent)] + // remove link from parentKey + parent, ok := bpp.mapProcessedResult[string(processedResults.parentKey)] if ok { - delete(parent.children, key) + delete(parent.childrenKeys, key) } return collectedProcessedResultsKeys, true @@ -226,23 +226,23 @@ func (bpp *basePostProcessor) InitProcessedResults(key []byte, parentKey []byte) defer bpp.mutInterResultsForBlock.Unlock() pr := &processedResult{ - parent: parentKey, - children: make(map[string]struct{}), - results: make([][]byte, 0), + parentKey: parentKey, + childrenKeys: make(map[string]struct{}), + results: make([][]byte, 0), } bpp.mapProcessedResult[string(key)] = pr - if parentKey != nil { + if len(parentKey) > 0 { parentPr, ok := bpp.mapProcessedResult[string(parentKey)] if !ok { bpp.mapProcessedResult[string(parentKey)] = &processedResult{ - parent: nil, - children: map[string]struct{}{string(key): {}}, - results: make([][]byte, 0), + parentKey: nil, + childrenKeys: map[string]struct{}{string(key): {}}, + results: make([][]byte, 0), } } else { - parentPr.children[string(key)] = struct{}{} + parentPr.childrenKeys[string(key)] = struct{}{} } } } diff --git a/process/block/postprocess/basePostProcess_test.go b/process/block/postprocess/basePostProcess_test.go new file mode 100644 index 00000000000..9e39ff3f59e --- /dev/null +++ b/process/block/postprocess/basePostProcess_test.go @@ -0,0 +1,207 @@ +package postprocess + +import ( + "fmt" + "os" + "runtime/debug" + "runtime/pprof" + "sync" + "testing" + + "time" + + "github.com/multiversx/mx-chain-core-go/data" + "github.com/multiversx/mx-chain-core-go/data/smartContractResult" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-core-go/hashing" + "github.com/multiversx/mx-chain-core-go/hashing/sha256" + "github.com/multiversx/mx-chain-core-go/marshal" + "github.com/stretchr/testify/require" +) + +func createBaseProcessors(numProcessors int) []*basePostProcessor { + basePostProcessors := make([]*basePostProcessor, numProcessors) + for i := 0; i < numProcessors; i++ { + basePostProcessors[i] = &basePostProcessor{ + hasher: sha256.NewSha256(), + marshalizer: &marshal.GogoProtoMarshalizer{}, + store: nil, + shardCoordinator: nil, + storageType: 0, + mutInterResultsForBlock: sync.Mutex{}, + interResultsForBlock: make(map[string]*txInfo), + mapProcessedResult: make(map[string]*processedResult), + intraShardMiniBlock: nil, + economicsFee: nil, + index: 0, + } + } + return basePostProcessors +} + +func createTxs(hasher hashing.Hasher, num int) ([]data.TransactionHandler, [][]byte) { + txs := make([]data.TransactionHandler, num) + txHashes := make([][]byte, num) + marshaller := &marshal.GogoProtoMarshalizer{} + + for i := 0; i < num; i++ { + txs[i] = &transaction.Transaction{ + Nonce: uint64(i), + } + marshalledTx, _ := marshaller.Marshal(txs[i]) + txHashes[i] = hasher.Compute(string(marshalledTx)) + } + + return txs, txHashes +} + +func createScrs(hasher hashing.Hasher, num int) ([]data.TransactionHandler, [][]byte) { + scrs := make([]data.TransactionHandler, num) + scrHashes := make([][]byte, num) + marshaller := &marshal.GogoProtoMarshalizer{} + + for i := 0; i < num; i++ { + scrs[i] = &smartContractResult.SmartContractResult{ + Nonce: uint64(i), + OriginalTxHash: []byte("original tx hash"), + } + marshalledTx, _ := marshaller.Marshal(scrs[i]) + scrHashes[i] = hasher.Compute(string(marshalledTx)) + } + + return scrs, scrHashes +} + +func Test_addIntermediateTxToResultsForBlock(t *testing.T) { + numInstances := 1 + basePreProcs := createBaseProcessors(numInstances) + numTxs := 1000000 + txs, txHashes := createTxs(sha256.NewSha256(), numTxs) + defaultParentKey := "defaultParentKey" + key := "defaultkey" + for i := 0; i < numInstances; i++ { + basePreProcs[i].InitProcessedResults([]byte(key), []byte(defaultParentKey)) + } + t.Run("addIntermediateTxToResultsForBlock", func(t *testing.T) { + fileName := fmt.Sprintf("logs/cpu-profile-%d.pprof", time.Now().Unix()) + f, err := os.Create(fileName) + require.Nil(t, err) + debug.SetGCPercent(-1) + _ = pprof.StartCPUProfile(f) + defer func() { + pprof.StopCPUProfile() + + log.Info("cpu-profile saved", "file", fileName) + }() + + for i := 0; i < numInstances; i++ { + for j := 0; j < numTxs; j++ { + basePreProcs[i].addIntermediateTxToResultsForBlock(txs[j], txHashes[j], 0, 1, []byte(key)) + } + } + }) +} + +func TestBasePostProcessor_InitAddAndRemove(t *testing.T) { + numInstances := 1 + numTxs := 10000 + numScrs := 10000 + headerHash := []byte("headerHash") + miniBlockHash := []byte("miniBlockHash") + _, txHashes := createTxs(sha256.NewSha256(), numTxs) + scrs, scrHash := createScrs(sha256.NewSha256(), numScrs) + + t.Run("InitProcessedResults for header, miniblock and txs, remove one tx, then miniblock", func(t *testing.T) { + basePreProcs := createBaseProcessors(numInstances) + basePreProcs[0].InitProcessedResults(headerHash, nil) + basePreProcs[0].InitProcessedResults(miniBlockHash, headerHash) + require.Len(t, basePreProcs[0].mapProcessedResult[string(headerHash)].childrenKeys, 1) + require.Len(t, basePreProcs[0].mapProcessedResult[string(headerHash)].results, 0) + + for i := 0; i < numTxs; i++ { + basePreProcs[0].InitProcessedResults(txHashes[i], miniBlockHash) + basePreProcs[0].addIntermediateTxToResultsForBlock(scrs[i], scrHash[i], 0, 1, txHashes[i]) + } + require.Equal(t, numTxs, len(basePreProcs[0].mapProcessedResult[string(miniBlockHash)].childrenKeys)) + require.Len(t, basePreProcs[0].mapProcessedResult[string(miniBlockHash)].results, 0) + + for i := 0; i < numTxs; i++ { + require.Len(t, basePreProcs[0].mapProcessedResult[string(txHashes[i])].results, 1) + require.Len(t, basePreProcs[0].mapProcessedResult[string(txHashes[i])].childrenKeys, 0) + } + + results := basePreProcs[0].RemoveProcessedResults(txHashes[0]) + require.Len(t, results, 1) + + // miniBlockHash has numTxs-1 childrenKeys, as one was removed + // each child has one scr registered + results = basePreProcs[0].RemoveProcessedResults(miniBlockHash) + require.Len(t, results, numTxs-1) + + // headerHash no longer has childrenKeys and no direct results, so removing it should return an empty slice + results = basePreProcs[0].RemoveProcessedResults(headerHash) + require.Len(t, results, 0) + }) + t.Run("InitProcessedResults for header, miniblock and txs, remove directly the miniblock", func(t *testing.T) { + basePreProcs := createBaseProcessors(numInstances) + basePreProcs[0].InitProcessedResults(headerHash, nil) + basePreProcs[0].InitProcessedResults(miniBlockHash, headerHash) + require.Len(t, basePreProcs[0].mapProcessedResult[string(headerHash)].childrenKeys, 1) + require.Len(t, basePreProcs[0].mapProcessedResult[string(headerHash)].results, 0) + + for i := 0; i < numTxs; i++ { + basePreProcs[0].InitProcessedResults(txHashes[i], miniBlockHash) + basePreProcs[0].addIntermediateTxToResultsForBlock(scrs[i], scrHash[i], 0, 1, txHashes[i]) + } + require.Equal(t, numTxs, len(basePreProcs[0].mapProcessedResult[string(miniBlockHash)].childrenKeys)) + require.Len(t, basePreProcs[0].mapProcessedResult[string(miniBlockHash)].results, 0) + + for i := 0; i < numTxs; i++ { + require.Len(t, basePreProcs[0].mapProcessedResult[string(txHashes[i])].results, 1) + require.Len(t, basePreProcs[0].mapProcessedResult[string(txHashes[i])].childrenKeys, 0) + } + + // miniBlockHash has numTxs childrenKeys, each child has one scr registered + // removing directly the miniBlock should return numTxs results (the scrs) + results := basePreProcs[0].RemoveProcessedResults(miniBlockHash) + require.Len(t, results, numTxs) + for i := 0; i < numTxs; i++ { + require.Nil(t, basePreProcs[0].mapProcessedResult[string(txHashes[i])]) + } + + // headerHash no longer has childrenKeys and no direct results, so removing it should return an empty slice + results = basePreProcs[0].RemoveProcessedResults(headerHash) + require.Len(t, results, 0) + }) + + t.Run("InitProcessedResults for header, miniblock and txs, remove directly the headerhash", func(t *testing.T) { + basePreProcs := createBaseProcessors(numInstances) + basePreProcs[0].InitProcessedResults(headerHash, nil) + basePreProcs[0].InitProcessedResults(miniBlockHash, headerHash) + require.Len(t, basePreProcs[0].mapProcessedResult[string(headerHash)].childrenKeys, 1) + require.Len(t, basePreProcs[0].mapProcessedResult[string(headerHash)].results, 0) + + for i := 0; i < numTxs; i++ { + basePreProcs[0].InitProcessedResults(txHashes[i], miniBlockHash) + basePreProcs[0].addIntermediateTxToResultsForBlock(scrs[i], scrHash[i], 0, 1, txHashes[i]) + } + require.Equal(t, numTxs, len(basePreProcs[0].mapProcessedResult[string(miniBlockHash)].childrenKeys)) + require.Len(t, basePreProcs[0].mapProcessedResult[string(miniBlockHash)].results, 0) + + for i := 0; i < numTxs; i++ { + require.Len(t, basePreProcs[0].mapProcessedResult[string(txHashes[i])].results, 1) + require.Len(t, basePreProcs[0].mapProcessedResult[string(txHashes[i])].childrenKeys, 0) + } + + // headerHash has one child, miniBlockHash + // miniBlockHash has numTxs childrenKeys, each child has one scr registered + // removing directly the headerHash should return numTxs results (the scrs) for the removed chained childrenKeys + results := basePreProcs[0].RemoveProcessedResults(headerHash) + require.Len(t, results, numTxs) + require.Nil(t, basePreProcs[0].mapProcessedResult[string(miniBlockHash)]) + + for i := 0; i < numTxs; i++ { + require.Nil(t, basePreProcs[0].mapProcessedResult[string(txHashes[i])]) + } + }) +} From 599ea7617dbf1ff67ccb9ac225253f863e09671a Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Fri, 14 Jun 2024 15:37:32 +0300 Subject: [PATCH 332/503] remove profiling --- .../block/postprocess/basePostProcess_test.go | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/process/block/postprocess/basePostProcess_test.go b/process/block/postprocess/basePostProcess_test.go index 9e39ff3f59e..021ef491840 100644 --- a/process/block/postprocess/basePostProcess_test.go +++ b/process/block/postprocess/basePostProcess_test.go @@ -1,15 +1,9 @@ package postprocess import ( - "fmt" - "os" - "runtime/debug" - "runtime/pprof" "sync" "testing" - "time" - "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/smartContractResult" "github.com/multiversx/mx-chain-core-go/data/transaction" @@ -72,36 +66,6 @@ func createScrs(hasher hashing.Hasher, num int) ([]data.TransactionHandler, [][] return scrs, scrHashes } -func Test_addIntermediateTxToResultsForBlock(t *testing.T) { - numInstances := 1 - basePreProcs := createBaseProcessors(numInstances) - numTxs := 1000000 - txs, txHashes := createTxs(sha256.NewSha256(), numTxs) - defaultParentKey := "defaultParentKey" - key := "defaultkey" - for i := 0; i < numInstances; i++ { - basePreProcs[i].InitProcessedResults([]byte(key), []byte(defaultParentKey)) - } - t.Run("addIntermediateTxToResultsForBlock", func(t *testing.T) { - fileName := fmt.Sprintf("logs/cpu-profile-%d.pprof", time.Now().Unix()) - f, err := os.Create(fileName) - require.Nil(t, err) - debug.SetGCPercent(-1) - _ = pprof.StartCPUProfile(f) - defer func() { - pprof.StopCPUProfile() - - log.Info("cpu-profile saved", "file", fileName) - }() - - for i := 0; i < numInstances; i++ { - for j := 0; j < numTxs; j++ { - basePreProcs[i].addIntermediateTxToResultsForBlock(txs[j], txHashes[j], 0, 1, []byte(key)) - } - } - }) -} - func TestBasePostProcessor_InitAddAndRemove(t *testing.T) { numInstances := 1 numTxs := 10000 From 75efb5eddcdc8b032d9fde7a8ef198fec5261fa2 Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Fri, 14 Jun 2024 15:41:50 +0300 Subject: [PATCH 333/503] update gosum --- go.sum | 6 ------ 1 file changed, 6 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= From edaa9a5e6cd42b6ef9d1837b253a438aa8f985ff Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 14 Jun 2024 15:52:41 +0300 Subject: [PATCH 334/503] fixes after review: replaced AppendLog functionality with a new component that accumulates logs during execution of relayed tx from all failed inner txs --- factory/processing/blockProcessorCreator.go | 134 +++++++------- .../txSimulatorProcessComponents.go | 135 +++++++------- genesis/mock/txLogProcessorMock.go | 6 - genesis/process/metaGenesisBlockCreator.go | 46 ++--- genesis/process/shardGenesisBlockCreator.go | 86 ++++----- integrationTests/mock/txLogsProcessorStub.go | 14 +- integrationTests/testInitializer.go | 21 +-- integrationTests/testProcessorNode.go | 127 ++++++------- integrationTests/vm/testInitializer.go | 138 +++++++------- integrationTests/vm/wasm/utils.go | 54 +++--- .../vm/wasm/wasmvm/wasmVM_test.go | 37 ++-- process/disabled/failedTxLogsAccumulator.go | 33 ++++ process/errors.go | 3 + process/interface.go | 9 +- process/mock/txLogsProcessorStub.go | 10 -- .../processProxy/processProxy.go | 47 ++--- .../processProxy/processProxy_test.go | 8 +- .../processProxy/testProcessProxy.go | 47 ++--- process/smartContract/process_test.go | 12 +- .../smartContract/processorV2/processV2.go | 87 +++++---- .../smartContract/processorV2/process_test.go | 35 +++- process/smartContract/scrCommon/common.go | 50 +++--- process/transaction/shardProcess.go | 104 ++++++----- process/transaction/shardProcess_test.go | 66 ++++--- .../transactionLog/failedTxLogsAccumulator.go | 109 ++++++++++++ .../failedTxLogsAccumulator_test.go | 168 ++++++++++++++++++ process/transactionLog/printTxLogProcessor.go | 5 - .../printTxLogProcessor_test.go | 3 - process/transactionLog/process.go | 45 +---- process/transactionLog/process_test.go | 90 ---------- .../failedTxLogsAccumulatorMock.go | 41 +++++ 31 files changed, 1041 insertions(+), 729 deletions(-) create mode 100644 process/disabled/failedTxLogsAccumulator.go create mode 100644 process/transactionLog/failedTxLogsAccumulator.go create mode 100644 process/transactionLog/failedTxLogsAccumulator_test.go create mode 100644 testscommon/processMocks/failedTxLogsAccumulatorMock.go diff --git a/factory/processing/blockProcessorCreator.go b/factory/processing/blockProcessorCreator.go index 65c827e7b43..d3a65d66660 100644 --- a/factory/processing/blockProcessorCreator.go +++ b/factory/processing/blockProcessorCreator.go @@ -38,6 +38,7 @@ import ( "github.com/multiversx/mx-chain-go/process/smartContract/scrCommon" "github.com/multiversx/mx-chain-go/process/throttle" "github.com/multiversx/mx-chain-go/process/transaction" + "github.com/multiversx/mx-chain-go/process/transactionLog" "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/state/syncer" "github.com/multiversx/mx-chain-go/storage/txcache" @@ -236,30 +237,32 @@ func (pcf *processComponentsFactory) newShardBlockProcessor( return nil, err } + failedTxLogsAccumulator := transactionLog.NewFailedTxLogsAccumulator() txFeeHandler := postprocess.NewFeeAccumulator() argsNewScProcessor := scrCommon.ArgsNewSmartContractProcessor{ - VmContainer: vmContainer, - ArgsParser: argsParser, - Hasher: pcf.coreData.Hasher(), - Marshalizer: pcf.coreData.InternalMarshalizer(), - AccountsDB: pcf.state.AccountsAdapter(), - BlockChainHook: vmFactory.BlockChainHookImpl(), - BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), - PubkeyConv: pcf.coreData.AddressPubKeyConverter(), - ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), - ScrForwarder: scForwarder, - TxFeeHandler: txFeeHandler, - EconomicsFee: pcf.coreData.EconomicsData(), - GasHandler: gasHandler, - GasSchedule: pcf.gasSchedule, - TxLogsProcessor: pcf.txLogsProcessor, - TxTypeHandler: txTypeHandler, - IsGenesisProcessing: false, - BadTxForwarder: badTxInterim, - EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), - EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), - VMOutputCacher: txcache.NewDisabledCache(), - WasmVMChangeLocker: wasmVMChangeLocker, + VmContainer: vmContainer, + ArgsParser: argsParser, + Hasher: pcf.coreData.Hasher(), + Marshalizer: pcf.coreData.InternalMarshalizer(), + AccountsDB: pcf.state.AccountsAdapter(), + BlockChainHook: vmFactory.BlockChainHookImpl(), + BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), + PubkeyConv: pcf.coreData.AddressPubKeyConverter(), + ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), + ScrForwarder: scForwarder, + TxFeeHandler: txFeeHandler, + EconomicsFee: pcf.coreData.EconomicsData(), + GasHandler: gasHandler, + GasSchedule: pcf.gasSchedule, + TxLogsProcessor: pcf.txLogsProcessor, + TxTypeHandler: txTypeHandler, + IsGenesisProcessing: false, + BadTxForwarder: badTxInterim, + EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), + EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), + VMOutputCacher: txcache.NewDisabledCache(), + WasmVMChangeLocker: wasmVMChangeLocker, + FailedTxLogsAccumulator: failedTxLogsAccumulator, } scProcessorProxy, err := processProxy.NewSmartContractProcessorProxy(argsNewScProcessor, pcf.epochNotifier) @@ -277,26 +280,27 @@ func (pcf *processComponentsFactory) newShardBlockProcessor( } argsNewTxProcessor := transaction.ArgsNewTxProcessor{ - Accounts: pcf.state.AccountsAdapter(), - Hasher: pcf.coreData.Hasher(), - PubkeyConv: pcf.coreData.AddressPubKeyConverter(), - Marshalizer: pcf.coreData.InternalMarshalizer(), - SignMarshalizer: pcf.coreData.TxMarshalizer(), - ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), - ScProcessor: scProcessorProxy, - TxFeeHandler: txFeeHandler, - TxTypeHandler: txTypeHandler, - EconomicsFee: pcf.coreData.EconomicsData(), - ReceiptForwarder: receiptTxInterim, - BadTxForwarder: badTxInterim, - ArgsParser: argsParser, - ScrForwarder: scForwarder, - EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), - EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), - GuardianChecker: pcf.bootstrapComponents.GuardedAccountHandler(), - TxVersionChecker: pcf.coreData.TxVersionChecker(), - TxLogsProcessor: pcf.txLogsProcessor, - RelayedTxV3Processor: relayedTxV3Processor, + Accounts: pcf.state.AccountsAdapter(), + Hasher: pcf.coreData.Hasher(), + PubkeyConv: pcf.coreData.AddressPubKeyConverter(), + Marshalizer: pcf.coreData.InternalMarshalizer(), + SignMarshalizer: pcf.coreData.TxMarshalizer(), + ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), + ScProcessor: scProcessorProxy, + TxFeeHandler: txFeeHandler, + TxTypeHandler: txTypeHandler, + EconomicsFee: pcf.coreData.EconomicsData(), + ReceiptForwarder: receiptTxInterim, + BadTxForwarder: badTxInterim, + ArgsParser: argsParser, + ScrForwarder: scForwarder, + EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), + EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), + GuardianChecker: pcf.bootstrapComponents.GuardedAccountHandler(), + TxVersionChecker: pcf.coreData.TxVersionChecker(), + TxLogsProcessor: pcf.txLogsProcessor, + RelayedTxV3Processor: relayedTxV3Processor, + FailedTxLogsAccumulator: failedTxLogsAccumulator, } transactionProcessor, err := transaction.NewTxProcessor(argsNewTxProcessor) if err != nil { @@ -565,31 +569,33 @@ func (pcf *processComponentsFactory) newMetaBlockProcessor( return nil, err } + failedTxLogsAccumulator := transactionLog.NewFailedTxLogsAccumulator() txFeeHandler := postprocess.NewFeeAccumulator() enableEpochs := pcf.epochConfig.EnableEpochs argsNewScProcessor := scrCommon.ArgsNewSmartContractProcessor{ - VmContainer: vmContainer, - ArgsParser: argsParser, - Hasher: pcf.coreData.Hasher(), - Marshalizer: pcf.coreData.InternalMarshalizer(), - AccountsDB: pcf.state.AccountsAdapter(), - BlockChainHook: vmFactory.BlockChainHookImpl(), - BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), - PubkeyConv: pcf.coreData.AddressPubKeyConverter(), - ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), - ScrForwarder: scForwarder, - TxFeeHandler: txFeeHandler, - EconomicsFee: pcf.coreData.EconomicsData(), - TxTypeHandler: txTypeHandler, - GasHandler: gasHandler, - GasSchedule: pcf.gasSchedule, - TxLogsProcessor: pcf.txLogsProcessor, - IsGenesisProcessing: false, - BadTxForwarder: badTxForwarder, - EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), - EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), - VMOutputCacher: txcache.NewDisabledCache(), - WasmVMChangeLocker: wasmVMChangeLocker, + VmContainer: vmContainer, + ArgsParser: argsParser, + Hasher: pcf.coreData.Hasher(), + Marshalizer: pcf.coreData.InternalMarshalizer(), + AccountsDB: pcf.state.AccountsAdapter(), + BlockChainHook: vmFactory.BlockChainHookImpl(), + BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), + PubkeyConv: pcf.coreData.AddressPubKeyConverter(), + ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), + ScrForwarder: scForwarder, + TxFeeHandler: txFeeHandler, + EconomicsFee: pcf.coreData.EconomicsData(), + TxTypeHandler: txTypeHandler, + GasHandler: gasHandler, + GasSchedule: pcf.gasSchedule, + TxLogsProcessor: pcf.txLogsProcessor, + IsGenesisProcessing: false, + BadTxForwarder: badTxForwarder, + EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), + EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), + VMOutputCacher: txcache.NewDisabledCache(), + WasmVMChangeLocker: wasmVMChangeLocker, + FailedTxLogsAccumulator: failedTxLogsAccumulator, } scProcessorProxy, err := processProxy.NewSmartContractProcessorProxy(argsNewScProcessor, pcf.epochNotifier) diff --git a/factory/processing/txSimulatorProcessComponents.go b/factory/processing/txSimulatorProcessComponents.go index 09c94e4d6e9..21fe2ddc073 100644 --- a/factory/processing/txSimulatorProcessComponents.go +++ b/factory/processing/txSimulatorProcessComponents.go @@ -173,29 +173,32 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessorForMeta( return args, nil, nil, err } + failedTxLogsAccumulator := transactionLog.NewFailedTxLogsAccumulator() + scProcArgs := scrCommon.ArgsNewSmartContractProcessor{ - VmContainer: vmContainer, - ArgsParser: smartContract.NewArgumentParser(), - Hasher: pcf.coreData.Hasher(), - Marshalizer: pcf.coreData.InternalMarshalizer(), - AccountsDB: accountsAdapter, - BlockChainHook: vmContainerFactory.BlockChainHookImpl(), - BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), - PubkeyConv: pcf.coreData.AddressPubKeyConverter(), - ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), - ScrForwarder: scForwarder, - TxFeeHandler: &processDisabled.FeeHandler{}, - EconomicsFee: pcf.coreData.EconomicsData(), - TxTypeHandler: txTypeHandler, - GasHandler: gasHandler, - GasSchedule: pcf.gasSchedule, - TxLogsProcessor: txLogsProcessor, - EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), - EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), - BadTxForwarder: badTxInterim, - VMOutputCacher: vmOutputCacher, - WasmVMChangeLocker: pcf.coreData.WasmVMChangeLocker(), - IsGenesisProcessing: false, + VmContainer: vmContainer, + ArgsParser: smartContract.NewArgumentParser(), + Hasher: pcf.coreData.Hasher(), + Marshalizer: pcf.coreData.InternalMarshalizer(), + AccountsDB: accountsAdapter, + BlockChainHook: vmContainerFactory.BlockChainHookImpl(), + BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), + PubkeyConv: pcf.coreData.AddressPubKeyConverter(), + ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), + ScrForwarder: scForwarder, + TxFeeHandler: &processDisabled.FeeHandler{}, + EconomicsFee: pcf.coreData.EconomicsData(), + TxTypeHandler: txTypeHandler, + GasHandler: gasHandler, + GasSchedule: pcf.gasSchedule, + TxLogsProcessor: txLogsProcessor, + EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), + EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), + BadTxForwarder: badTxInterim, + VMOutputCacher: vmOutputCacher, + WasmVMChangeLocker: pcf.coreData.WasmVMChangeLocker(), + IsGenesisProcessing: false, + FailedTxLogsAccumulator: failedTxLogsAccumulator, } scProcessor, err := smartContract.NewSmartContractProcessor(scProcArgs) @@ -348,29 +351,32 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessorShard( argsParser := smartContract.NewArgumentParser() + failedTxLogsAccumulator := transactionLog.NewFailedTxLogsAccumulator() + scProcArgs := scrCommon.ArgsNewSmartContractProcessor{ - VmContainer: vmContainer, - ArgsParser: argsParser, - Hasher: pcf.coreData.Hasher(), - Marshalizer: pcf.coreData.InternalMarshalizer(), - AccountsDB: accountsAdapter, - BlockChainHook: vmContainerFactory.BlockChainHookImpl(), - BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), - PubkeyConv: pcf.coreData.AddressPubKeyConverter(), - ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), - ScrForwarder: scForwarder, - TxFeeHandler: &processDisabled.FeeHandler{}, - EconomicsFee: pcf.coreData.EconomicsData(), - TxTypeHandler: txTypeHandler, - GasHandler: gasHandler, - GasSchedule: pcf.gasSchedule, - TxLogsProcessor: txLogsProcessor, - EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), - EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), - BadTxForwarder: badTxInterim, - VMOutputCacher: vmOutputCacher, - WasmVMChangeLocker: pcf.coreData.WasmVMChangeLocker(), - IsGenesisProcessing: false, + VmContainer: vmContainer, + ArgsParser: argsParser, + Hasher: pcf.coreData.Hasher(), + Marshalizer: pcf.coreData.InternalMarshalizer(), + AccountsDB: accountsAdapter, + BlockChainHook: vmContainerFactory.BlockChainHookImpl(), + BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), + PubkeyConv: pcf.coreData.AddressPubKeyConverter(), + ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), + ScrForwarder: scForwarder, + TxFeeHandler: &processDisabled.FeeHandler{}, + EconomicsFee: pcf.coreData.EconomicsData(), + TxTypeHandler: txTypeHandler, + GasHandler: gasHandler, + GasSchedule: pcf.gasSchedule, + TxLogsProcessor: txLogsProcessor, + EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), + EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), + BadTxForwarder: badTxInterim, + VMOutputCacher: vmOutputCacher, + WasmVMChangeLocker: pcf.coreData.WasmVMChangeLocker(), + IsGenesisProcessing: false, + FailedTxLogsAccumulator: failedTxLogsAccumulator, } scProcessor, err := smartContract.NewSmartContractProcessor(scProcArgs) @@ -379,26 +385,27 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessorShard( } argsTxProcessor := transaction.ArgsNewTxProcessor{ - Accounts: accountsAdapter, - Hasher: pcf.coreData.Hasher(), - PubkeyConv: pcf.coreData.AddressPubKeyConverter(), - Marshalizer: pcf.coreData.InternalMarshalizer(), - SignMarshalizer: pcf.coreData.TxMarshalizer(), - ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), - ScProcessor: scProcessor, - TxFeeHandler: txFeeHandler, - TxTypeHandler: txTypeHandler, - EconomicsFee: pcf.coreData.EconomicsData(), - ReceiptForwarder: receiptTxInterim, - BadTxForwarder: badTxInterim, - ArgsParser: argsParser, - ScrForwarder: scForwarder, - EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), - EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), - TxVersionChecker: pcf.coreData.TxVersionChecker(), - GuardianChecker: pcf.bootstrapComponents.GuardedAccountHandler(), - TxLogsProcessor: txLogsProcessor, - RelayedTxV3Processor: relayedTxV3Processor, + Accounts: accountsAdapter, + Hasher: pcf.coreData.Hasher(), + PubkeyConv: pcf.coreData.AddressPubKeyConverter(), + Marshalizer: pcf.coreData.InternalMarshalizer(), + SignMarshalizer: pcf.coreData.TxMarshalizer(), + ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), + ScProcessor: scProcessor, + TxFeeHandler: txFeeHandler, + TxTypeHandler: txTypeHandler, + EconomicsFee: pcf.coreData.EconomicsData(), + ReceiptForwarder: receiptTxInterim, + BadTxForwarder: badTxInterim, + ArgsParser: argsParser, + ScrForwarder: scForwarder, + EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), + EnableRoundsHandler: pcf.coreData.EnableRoundsHandler(), + TxVersionChecker: pcf.coreData.TxVersionChecker(), + GuardianChecker: pcf.bootstrapComponents.GuardedAccountHandler(), + TxLogsProcessor: txLogsProcessor, + RelayedTxV3Processor: relayedTxV3Processor, + FailedTxLogsAccumulator: failedTxLogsAccumulator, } txProcessor, err := transaction.NewTxProcessor(argsTxProcessor) diff --git a/genesis/mock/txLogProcessorMock.go b/genesis/mock/txLogProcessorMock.go index 4d377541de7..11cef23871a 100644 --- a/genesis/mock/txLogProcessorMock.go +++ b/genesis/mock/txLogProcessorMock.go @@ -21,12 +21,6 @@ func (tlpm *TxLogProcessorMock) SaveLog(_ []byte, _ data.TransactionHandler, _ [ return nil } -// AppendLog - -func (tlpm *TxLogProcessorMock) AppendLog(_ []byte, _ data.TransactionHandler, _ []*vmcommon.LogEntry) error { - - return nil -} - // Clean - func (tlpm *TxLogProcessorMock) Clean() { } diff --git a/genesis/process/metaGenesisBlockCreator.go b/genesis/process/metaGenesisBlockCreator.go index f695c274b42..3a4769889b6 100644 --- a/genesis/process/metaGenesisBlockCreator.go +++ b/genesis/process/metaGenesisBlockCreator.go @@ -28,6 +28,7 @@ import ( "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/block/preprocess" "github.com/multiversx/mx-chain-go/process/coordinator" + disabledProcess "github.com/multiversx/mx-chain-go/process/disabled" "github.com/multiversx/mx-chain-go/process/factory" "github.com/multiversx/mx-chain-go/process/factory/metachain" disabledGuardian "github.com/multiversx/mx-chain-go/process/guardian/disabled" @@ -437,28 +438,29 @@ func createProcessorsForMetaGenesisBlock(arg ArgsGenesisBlockCreator, enableEpoc argsParser := smartContract.NewArgumentParser() argsNewSCProcessor := scrCommon.ArgsNewSmartContractProcessor{ - VmContainer: vmContainer, - ArgsParser: argsParser, - Hasher: arg.Core.Hasher(), - Marshalizer: arg.Core.InternalMarshalizer(), - AccountsDB: arg.Accounts, - BlockChainHook: virtualMachineFactory.BlockChainHookImpl(), - BuiltInFunctions: builtInFuncs, - PubkeyConv: arg.Core.AddressPubKeyConverter(), - ShardCoordinator: arg.ShardCoordinator, - ScrForwarder: scForwarder, - TxFeeHandler: genesisFeeHandler, - EconomicsFee: genesisFeeHandler, - TxTypeHandler: txTypeHandler, - GasHandler: gasHandler, - GasSchedule: arg.GasSchedule, - TxLogsProcessor: arg.TxLogsProcessor, - BadTxForwarder: badTxForwarder, - EnableRoundsHandler: enableRoundsHandler, - EnableEpochsHandler: enableEpochsHandler, - IsGenesisProcessing: true, - WasmVMChangeLocker: &sync.RWMutex{}, // local Locker as to not interfere with the rest of the components - VMOutputCacher: txcache.NewDisabledCache(), + VmContainer: vmContainer, + ArgsParser: argsParser, + Hasher: arg.Core.Hasher(), + Marshalizer: arg.Core.InternalMarshalizer(), + AccountsDB: arg.Accounts, + BlockChainHook: virtualMachineFactory.BlockChainHookImpl(), + BuiltInFunctions: builtInFuncs, + PubkeyConv: arg.Core.AddressPubKeyConverter(), + ShardCoordinator: arg.ShardCoordinator, + ScrForwarder: scForwarder, + TxFeeHandler: genesisFeeHandler, + EconomicsFee: genesisFeeHandler, + TxTypeHandler: txTypeHandler, + GasHandler: gasHandler, + GasSchedule: arg.GasSchedule, + TxLogsProcessor: arg.TxLogsProcessor, + BadTxForwarder: badTxForwarder, + EnableRoundsHandler: enableRoundsHandler, + EnableEpochsHandler: enableEpochsHandler, + IsGenesisProcessing: true, + WasmVMChangeLocker: &sync.RWMutex{}, // local Locker as to not interfere with the rest of the components + VMOutputCacher: txcache.NewDisabledCache(), + FailedTxLogsAccumulator: disabledProcess.NewFailedTxLogsAccumulator(), } scProcessorProxy, err := processProxy.NewSmartContractProcessorProxy(argsNewSCProcessor, epochNotifier) diff --git a/genesis/process/shardGenesisBlockCreator.go b/genesis/process/shardGenesisBlockCreator.go index 35bc217110e..7c2c6af06b3 100644 --- a/genesis/process/shardGenesisBlockCreator.go +++ b/genesis/process/shardGenesisBlockCreator.go @@ -507,28 +507,29 @@ func createProcessorsForShardGenesisBlock(arg ArgsGenesisBlockCreator, enableEpo } argsNewScProcessor := scrCommon.ArgsNewSmartContractProcessor{ - VmContainer: vmContainer, - ArgsParser: smartContract.NewArgumentParser(), - Hasher: arg.Core.Hasher(), - Marshalizer: arg.Core.InternalMarshalizer(), - AccountsDB: arg.Accounts, - BlockChainHook: vmFactoryImpl.BlockChainHookImpl(), - BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), - PubkeyConv: arg.Core.AddressPubKeyConverter(), - ShardCoordinator: arg.ShardCoordinator, - ScrForwarder: scForwarder, - TxFeeHandler: genesisFeeHandler, - EconomicsFee: genesisFeeHandler, - TxTypeHandler: txTypeHandler, - GasHandler: gasHandler, - GasSchedule: arg.GasSchedule, - TxLogsProcessor: arg.TxLogsProcessor, - BadTxForwarder: badTxInterim, - EnableRoundsHandler: enableRoundsHandler, - EnableEpochsHandler: enableEpochsHandler, - IsGenesisProcessing: true, - VMOutputCacher: txcache.NewDisabledCache(), - WasmVMChangeLocker: genesisWasmVMLocker, + VmContainer: vmContainer, + ArgsParser: smartContract.NewArgumentParser(), + Hasher: arg.Core.Hasher(), + Marshalizer: arg.Core.InternalMarshalizer(), + AccountsDB: arg.Accounts, + BlockChainHook: vmFactoryImpl.BlockChainHookImpl(), + BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), + PubkeyConv: arg.Core.AddressPubKeyConverter(), + ShardCoordinator: arg.ShardCoordinator, + ScrForwarder: scForwarder, + TxFeeHandler: genesisFeeHandler, + EconomicsFee: genesisFeeHandler, + TxTypeHandler: txTypeHandler, + GasHandler: gasHandler, + GasSchedule: arg.GasSchedule, + TxLogsProcessor: arg.TxLogsProcessor, + BadTxForwarder: badTxInterim, + EnableRoundsHandler: enableRoundsHandler, + EnableEpochsHandler: enableEpochsHandler, + IsGenesisProcessing: true, + VMOutputCacher: txcache.NewDisabledCache(), + WasmVMChangeLocker: genesisWasmVMLocker, + FailedTxLogsAccumulator: processDisabled.NewFailedTxLogsAccumulator(), } scProcessorProxy, err := processProxy.NewSmartContractProcessorProxy(argsNewScProcessor, epochNotifier) @@ -546,26 +547,27 @@ func createProcessorsForShardGenesisBlock(arg ArgsGenesisBlockCreator, enableEpo } argsNewTxProcessor := transaction.ArgsNewTxProcessor{ - Accounts: arg.Accounts, - Hasher: arg.Core.Hasher(), - PubkeyConv: arg.Core.AddressPubKeyConverter(), - Marshalizer: arg.Core.InternalMarshalizer(), - SignMarshalizer: arg.Core.TxMarshalizer(), - ShardCoordinator: arg.ShardCoordinator, - ScProcessor: scProcessorProxy, - TxFeeHandler: genesisFeeHandler, - TxTypeHandler: txTypeHandler, - EconomicsFee: genesisFeeHandler, - ReceiptForwarder: receiptTxInterim, - BadTxForwarder: badTxInterim, - ArgsParser: smartContract.NewArgumentParser(), - ScrForwarder: scForwarder, - EnableRoundsHandler: enableRoundsHandler, - EnableEpochsHandler: enableEpochsHandler, - TxVersionChecker: arg.Core.TxVersionChecker(), - GuardianChecker: disabledGuardian.NewDisabledGuardedAccountHandler(), - TxLogsProcessor: arg.TxLogsProcessor, - RelayedTxV3Processor: processDisabled.NewRelayedTxV3Processor(), + Accounts: arg.Accounts, + Hasher: arg.Core.Hasher(), + PubkeyConv: arg.Core.AddressPubKeyConverter(), + Marshalizer: arg.Core.InternalMarshalizer(), + SignMarshalizer: arg.Core.TxMarshalizer(), + ShardCoordinator: arg.ShardCoordinator, + ScProcessor: scProcessorProxy, + TxFeeHandler: genesisFeeHandler, + TxTypeHandler: txTypeHandler, + EconomicsFee: genesisFeeHandler, + ReceiptForwarder: receiptTxInterim, + BadTxForwarder: badTxInterim, + ArgsParser: smartContract.NewArgumentParser(), + ScrForwarder: scForwarder, + EnableRoundsHandler: enableRoundsHandler, + EnableEpochsHandler: enableEpochsHandler, + TxVersionChecker: arg.Core.TxVersionChecker(), + GuardianChecker: disabledGuardian.NewDisabledGuardedAccountHandler(), + TxLogsProcessor: arg.TxLogsProcessor, + RelayedTxV3Processor: processDisabled.NewRelayedTxV3Processor(), + FailedTxLogsAccumulator: processDisabled.NewFailedTxLogsAccumulator(), } transactionProcessor, err := transaction.NewTxProcessor(argsNewTxProcessor) if err != nil { diff --git a/integrationTests/mock/txLogsProcessorStub.go b/integrationTests/mock/txLogsProcessorStub.go index 651651455e8..124f5712843 100644 --- a/integrationTests/mock/txLogsProcessorStub.go +++ b/integrationTests/mock/txLogsProcessorStub.go @@ -7,9 +7,8 @@ import ( // TxLogsProcessorStub - type TxLogsProcessorStub struct { - GetLogCalled func(txHash []byte) (data.LogHandler, error) - SaveLogCalled func(txHash []byte, tx data.TransactionHandler, vmLogs []*vmcommon.LogEntry) error - AppendLogCalled func(txHash []byte, tx data.TransactionHandler, logEntries []*vmcommon.LogEntry) error + GetLogCalled func(txHash []byte) (data.LogHandler, error) + SaveLogCalled func(txHash []byte, tx data.TransactionHandler, vmLogs []*vmcommon.LogEntry) error } // GetLog - @@ -34,15 +33,6 @@ func (txls *TxLogsProcessorStub) SaveLog(txHash []byte, tx data.TransactionHandl return nil } -// AppendLog - -func (txls *TxLogsProcessorStub) AppendLog(txHash []byte, tx data.TransactionHandler, logEntries []*vmcommon.LogEntry) error { - if txls.AppendLogCalled != nil { - return txls.AppendLogCalled(txHash, tx, logEntries) - } - - return nil -} - // IsInterfaceNil - func (txls *TxLogsProcessorStub) IsInterfaceNil() bool { return txls == nil diff --git a/integrationTests/testInitializer.go b/integrationTests/testInitializer.go index ca5c97df80c..06dc1a24866 100644 --- a/integrationTests/testInitializer.go +++ b/integrationTests/testInitializer.go @@ -1056,16 +1056,17 @@ func CreateSimpleTxProcessor(accnts state.AccountsAdapter) process.TransactionPr return fee }, }, - ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, - BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, - ArgsParser: smartContract.NewArgumentParser(), - ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, - EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, - EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - TxVersionChecker: &testscommon.TxVersionCheckerStub{}, - GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, - TxLogsProcessor: &mock.TxLogsProcessorStub{}, - RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, + ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, + BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, + ArgsParser: smartContract.NewArgumentParser(), + ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, + EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, + EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + TxVersionChecker: &testscommon.TxVersionCheckerStub{}, + GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, + TxLogsProcessor: &mock.TxLogsProcessorStub{}, + RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, + FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, } txProcessor, _ := txProc.NewTxProcessor(argsNewTxProcessor) diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index 49ef2206b41..552fe8fc234 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -1700,27 +1700,28 @@ func (tpn *TestProcessorNode) initInnerProcessors(gasMap map[string]map[string]u badBlocksHandler, _ := tpn.InterimProcContainer.Get(dataBlock.InvalidBlock) argsNewScProcessor := scrCommon.ArgsNewSmartContractProcessor{ - VmContainer: tpn.VMContainer, - ArgsParser: tpn.ArgsParser, - Hasher: TestHasher, - Marshalizer: TestMarshalizer, - AccountsDB: tpn.AccntState, - BlockChainHook: vmFactory.BlockChainHookImpl(), - BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), - PubkeyConv: TestAddressPubkeyConverter, - ShardCoordinator: tpn.ShardCoordinator, - ScrForwarder: tpn.ScrForwarder, - TxFeeHandler: tpn.FeeAccumulator, - EconomicsFee: tpn.EconomicsData, - TxTypeHandler: txTypeHandler, - GasHandler: tpn.GasHandler, - GasSchedule: gasSchedule, - TxLogsProcessor: tpn.TransactionLogProcessor, - BadTxForwarder: badBlocksHandler, - EnableRoundsHandler: tpn.EnableRoundsHandler, - EnableEpochsHandler: tpn.EnableEpochsHandler, - VMOutputCacher: txcache.NewDisabledCache(), - WasmVMChangeLocker: tpn.WasmVMChangeLocker, + VmContainer: tpn.VMContainer, + ArgsParser: tpn.ArgsParser, + Hasher: TestHasher, + Marshalizer: TestMarshalizer, + AccountsDB: tpn.AccntState, + BlockChainHook: vmFactory.BlockChainHookImpl(), + BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), + PubkeyConv: TestAddressPubkeyConverter, + ShardCoordinator: tpn.ShardCoordinator, + ScrForwarder: tpn.ScrForwarder, + TxFeeHandler: tpn.FeeAccumulator, + EconomicsFee: tpn.EconomicsData, + TxTypeHandler: txTypeHandler, + GasHandler: tpn.GasHandler, + GasSchedule: gasSchedule, + TxLogsProcessor: tpn.TransactionLogProcessor, + BadTxForwarder: badBlocksHandler, + EnableRoundsHandler: tpn.EnableRoundsHandler, + EnableEpochsHandler: tpn.EnableEpochsHandler, + VMOutputCacher: txcache.NewDisabledCache(), + WasmVMChangeLocker: tpn.WasmVMChangeLocker, + FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, } tpn.ScProcessor, _ = processProxy.NewTestSmartContractProcessorProxy(argsNewScProcessor, tpn.EpochNotifier) @@ -1733,26 +1734,27 @@ func (tpn *TestProcessorNode) initInnerProcessors(gasMap map[string]map[string]u receiptsHandler, _ := tpn.InterimProcContainer.Get(dataBlock.ReceiptBlock) argsNewTxProcessor := transaction.ArgsNewTxProcessor{ - Accounts: tpn.AccntState, - Hasher: TestHasher, - PubkeyConv: TestAddressPubkeyConverter, - Marshalizer: TestMarshalizer, - SignMarshalizer: TestTxSignMarshalizer, - ShardCoordinator: tpn.ShardCoordinator, - ScProcessor: tpn.ScProcessor, - TxFeeHandler: tpn.FeeAccumulator, - TxTypeHandler: txTypeHandler, - EconomicsFee: tpn.EconomicsData, - ReceiptForwarder: receiptsHandler, - BadTxForwarder: badBlocksHandler, - ArgsParser: tpn.ArgsParser, - ScrForwarder: tpn.ScrForwarder, - EnableRoundsHandler: tpn.EnableRoundsHandler, - EnableEpochsHandler: tpn.EnableEpochsHandler, - GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, - TxVersionChecker: &testscommon.TxVersionCheckerStub{}, - TxLogsProcessor: tpn.TransactionLogProcessor, - RelayedTxV3Processor: relayedV3TxProcessor, + Accounts: tpn.AccntState, + Hasher: TestHasher, + PubkeyConv: TestAddressPubkeyConverter, + Marshalizer: TestMarshalizer, + SignMarshalizer: TestTxSignMarshalizer, + ShardCoordinator: tpn.ShardCoordinator, + ScProcessor: tpn.ScProcessor, + TxFeeHandler: tpn.FeeAccumulator, + TxTypeHandler: txTypeHandler, + EconomicsFee: tpn.EconomicsData, + ReceiptForwarder: receiptsHandler, + BadTxForwarder: badBlocksHandler, + ArgsParser: tpn.ArgsParser, + ScrForwarder: tpn.ScrForwarder, + EnableRoundsHandler: tpn.EnableRoundsHandler, + EnableEpochsHandler: tpn.EnableEpochsHandler, + GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, + TxVersionChecker: &testscommon.TxVersionCheckerStub{}, + TxLogsProcessor: tpn.TransactionLogProcessor, + RelayedTxV3Processor: relayedV3TxProcessor, + FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, } tpn.TxProcessor, _ = transaction.NewTxProcessor(argsNewTxProcessor) scheduledSCRsStorer, _ := tpn.Storage.GetStorer(dataRetriever.ScheduledSCRsUnit) @@ -1986,27 +1988,28 @@ func (tpn *TestProcessorNode) initMetaInnerProcessors(gasMap map[string]map[stri tpn.GasHandler, _ = preprocess.NewGasComputation(tpn.EconomicsData, txTypeHandler, tpn.EnableEpochsHandler) badBlocksHandler, _ := tpn.InterimProcContainer.Get(dataBlock.InvalidBlock) argsNewScProcessor := scrCommon.ArgsNewSmartContractProcessor{ - VmContainer: tpn.VMContainer, - ArgsParser: tpn.ArgsParser, - Hasher: TestHasher, - Marshalizer: TestMarshalizer, - AccountsDB: tpn.AccntState, - BlockChainHook: vmFactory.BlockChainHookImpl(), - BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), - PubkeyConv: TestAddressPubkeyConverter, - ShardCoordinator: tpn.ShardCoordinator, - ScrForwarder: tpn.ScrForwarder, - TxFeeHandler: tpn.FeeAccumulator, - EconomicsFee: tpn.EconomicsData, - TxTypeHandler: txTypeHandler, - GasHandler: tpn.GasHandler, - GasSchedule: gasSchedule, - TxLogsProcessor: tpn.TransactionLogProcessor, - BadTxForwarder: badBlocksHandler, - EnableRoundsHandler: tpn.EnableRoundsHandler, - EnableEpochsHandler: tpn.EnableEpochsHandler, - VMOutputCacher: txcache.NewDisabledCache(), - WasmVMChangeLocker: tpn.WasmVMChangeLocker, + VmContainer: tpn.VMContainer, + ArgsParser: tpn.ArgsParser, + Hasher: TestHasher, + Marshalizer: TestMarshalizer, + AccountsDB: tpn.AccntState, + BlockChainHook: vmFactory.BlockChainHookImpl(), + BuiltInFunctions: builtInFuncFactory.BuiltInFunctionContainer(), + PubkeyConv: TestAddressPubkeyConverter, + ShardCoordinator: tpn.ShardCoordinator, + ScrForwarder: tpn.ScrForwarder, + TxFeeHandler: tpn.FeeAccumulator, + EconomicsFee: tpn.EconomicsData, + TxTypeHandler: txTypeHandler, + GasHandler: tpn.GasHandler, + GasSchedule: gasSchedule, + TxLogsProcessor: tpn.TransactionLogProcessor, + BadTxForwarder: badBlocksHandler, + EnableRoundsHandler: tpn.EnableRoundsHandler, + EnableEpochsHandler: tpn.EnableEpochsHandler, + VMOutputCacher: txcache.NewDisabledCache(), + WasmVMChangeLocker: tpn.WasmVMChangeLocker, + FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, } tpn.ScProcessor, _ = processProxy.NewTestSmartContractProcessorProxy(argsNewScProcessor, tpn.EpochNotifier) diff --git a/integrationTests/vm/testInitializer.go b/integrationTests/vm/testInitializer.go index cc459663c56..4304dd291dd 100644 --- a/integrationTests/vm/testInitializer.go +++ b/integrationTests/vm/testInitializer.go @@ -461,12 +461,13 @@ func CreateTxProcessorWithOneSCExecutorMockVM( GasHandler: &testscommon.GasHandlerStub{ SetGasRefundedCalled: func(gasRefunded uint64, hash []byte) {}, }, - GasSchedule: gasScheduleNotifier, - TxLogsProcessor: &mock.TxLogsProcessorStub{}, - EnableEpochsHandler: enableEpochsHandler, - EnableRoundsHandler: enableRoundsHandler, - VMOutputCacher: txcache.NewDisabledCache(), - WasmVMChangeLocker: wasmVMChangeLocker, + GasSchedule: gasScheduleNotifier, + TxLogsProcessor: &mock.TxLogsProcessorStub{}, + EnableEpochsHandler: enableEpochsHandler, + EnableRoundsHandler: enableRoundsHandler, + VMOutputCacher: txcache.NewDisabledCache(), + WasmVMChangeLocker: wasmVMChangeLocker, + FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, } scProcessor, _ := processProxy.NewTestSmartContractProcessorProxy(argsNewSCProcessor, genericEpochNotifier) @@ -477,26 +478,27 @@ func CreateTxProcessorWithOneSCExecutorMockVM( } argsNewTxProcessor := transaction.ArgsNewTxProcessor{ - Accounts: accnts, - Hasher: integrationtests.TestHasher, - PubkeyConv: pubkeyConv, - Marshalizer: integrationtests.TestMarshalizer, - SignMarshalizer: integrationtests.TestMarshalizer, - ShardCoordinator: mock.NewMultiShardsCoordinatorMock(2), - ScProcessor: scProcessor, - TxFeeHandler: &testscommon.UnsignedTxHandlerStub{}, - TxTypeHandler: txTypeHandler, - EconomicsFee: economicsData, - ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, - BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, - ArgsParser: smartContract.NewArgumentParser(), - ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, - EnableRoundsHandler: enableRoundsHandler, - EnableEpochsHandler: enableEpochsHandler, - TxVersionChecker: versioning.NewTxVersionChecker(minTransactionVersion), - GuardianChecker: guardedAccountHandler, - TxLogsProcessor: &mock.TxLogsProcessorStub{}, - RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, + Accounts: accnts, + Hasher: integrationtests.TestHasher, + PubkeyConv: pubkeyConv, + Marshalizer: integrationtests.TestMarshalizer, + SignMarshalizer: integrationtests.TestMarshalizer, + ShardCoordinator: mock.NewMultiShardsCoordinatorMock(2), + ScProcessor: scProcessor, + TxFeeHandler: &testscommon.UnsignedTxHandlerStub{}, + TxTypeHandler: txTypeHandler, + EconomicsFee: economicsData, + ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, + BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, + ArgsParser: smartContract.NewArgumentParser(), + ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, + EnableRoundsHandler: enableRoundsHandler, + EnableEpochsHandler: enableEpochsHandler, + TxVersionChecker: versioning.NewTxVersionChecker(minTransactionVersion), + GuardianChecker: guardedAccountHandler, + TxLogsProcessor: &mock.TxLogsProcessorStub{}, + RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, + FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, } return transaction.NewTxProcessor(argsNewTxProcessor) @@ -867,52 +869,54 @@ func CreateTxProcessorWithOneSCExecutorWithVMs( intermediateTxHandler := &mock.IntermediateTransactionHandlerMock{} argsNewSCProcessor := scrCommon.ArgsNewSmartContractProcessor{ - VmContainer: vmContainer, - ArgsParser: smartContract.NewArgumentParser(), - Hasher: integrationtests.TestHasher, - Marshalizer: integrationtests.TestMarshalizer, - AccountsDB: accnts, - BlockChainHook: blockChainHook, - BuiltInFunctions: blockChainHook.GetBuiltinFunctionsContainer(), - PubkeyConv: pubkeyConv, - ShardCoordinator: shardCoordinator, - ScrForwarder: intermediateTxHandler, - BadTxForwarder: intermediateTxHandler, - TxFeeHandler: feeAccumulator, - EconomicsFee: economicsData, - TxTypeHandler: txTypeHandler, - GasHandler: gasComp, - GasSchedule: mock.NewGasScheduleNotifierMock(gasSchedule), - TxLogsProcessor: logProc, - EnableRoundsHandler: enableRoundsHandler, - EnableEpochsHandler: enableEpochsHandler, - WasmVMChangeLocker: wasmVMChangeLocker, - VMOutputCacher: txcache.NewDisabledCache(), + VmContainer: vmContainer, + ArgsParser: smartContract.NewArgumentParser(), + Hasher: integrationtests.TestHasher, + Marshalizer: integrationtests.TestMarshalizer, + AccountsDB: accnts, + BlockChainHook: blockChainHook, + BuiltInFunctions: blockChainHook.GetBuiltinFunctionsContainer(), + PubkeyConv: pubkeyConv, + ShardCoordinator: shardCoordinator, + ScrForwarder: intermediateTxHandler, + BadTxForwarder: intermediateTxHandler, + TxFeeHandler: feeAccumulator, + EconomicsFee: economicsData, + TxTypeHandler: txTypeHandler, + GasHandler: gasComp, + GasSchedule: mock.NewGasScheduleNotifierMock(gasSchedule), + TxLogsProcessor: logProc, + EnableRoundsHandler: enableRoundsHandler, + EnableEpochsHandler: enableEpochsHandler, + WasmVMChangeLocker: wasmVMChangeLocker, + VMOutputCacher: txcache.NewDisabledCache(), + FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, } scProcessorProxy, _ := processProxy.NewTestSmartContractProcessorProxy(argsNewSCProcessor, epochNotifierInstance) argsNewTxProcessor := transaction.ArgsNewTxProcessor{ - Accounts: accnts, - Hasher: integrationtests.TestHasher, - PubkeyConv: pubkeyConv, - Marshalizer: integrationtests.TestMarshalizer, - SignMarshalizer: integrationtests.TestMarshalizer, - ShardCoordinator: shardCoordinator, - ScProcessor: scProcessorProxy, - TxFeeHandler: feeAccumulator, - TxTypeHandler: txTypeHandler, - EconomicsFee: economicsData, - ReceiptForwarder: intermediateTxHandler, - BadTxForwarder: intermediateTxHandler, - ArgsParser: smartContract.NewArgumentParser(), - ScrForwarder: intermediateTxHandler, - EnableRoundsHandler: enableRoundsHandler, - EnableEpochsHandler: enableEpochsHandler, - TxVersionChecker: versioning.NewTxVersionChecker(minTransactionVersion), - GuardianChecker: guardianChecker, - TxLogsProcessor: logProc, - RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, + Accounts: accnts, + Hasher: integrationtests.TestHasher, + PubkeyConv: pubkeyConv, + Marshalizer: integrationtests.TestMarshalizer, + SignMarshalizer: integrationtests.TestMarshalizer, + ShardCoordinator: shardCoordinator, + ScProcessor: scProcessorProxy, + TxFeeHandler: feeAccumulator, + TxTypeHandler: txTypeHandler, + EconomicsFee: economicsData, + ReceiptForwarder: intermediateTxHandler, + BadTxForwarder: intermediateTxHandler, + ArgsParser: smartContract.NewArgumentParser(), + ScrForwarder: intermediateTxHandler, + EnableRoundsHandler: enableRoundsHandler, + EnableEpochsHandler: enableEpochsHandler, + TxVersionChecker: versioning.NewTxVersionChecker(minTransactionVersion), + GuardianChecker: guardianChecker, + TxLogsProcessor: logProc, + RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, + FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, } txProcessor, err := transaction.NewTxProcessor(argsNewTxProcessor) if err != nil { diff --git a/integrationTests/vm/wasm/utils.go b/integrationTests/vm/wasm/utils.go index 69bfa6a90fc..7ec28bb8f45 100644 --- a/integrationTests/vm/wasm/utils.go +++ b/integrationTests/vm/wasm/utils.go @@ -392,38 +392,40 @@ func (context *TestContext) initTxProcessorWithOneSCExecutorWithVMs() { GasHandler: &testscommon.GasHandlerStub{ SetGasRefundedCalled: func(gasRefunded uint64, hash []byte) {}, }, - GasSchedule: mock.NewGasScheduleNotifierMock(gasSchedule), - TxLogsProcessor: context.TxLogsProcessor, - EnableRoundsHandler: context.EnableRoundsHandler, - EnableEpochsHandler: context.EnableEpochsHandler, - WasmVMChangeLocker: context.WasmVMChangeLocker, - VMOutputCacher: txcache.NewDisabledCache(), + GasSchedule: mock.NewGasScheduleNotifierMock(gasSchedule), + TxLogsProcessor: context.TxLogsProcessor, + EnableRoundsHandler: context.EnableRoundsHandler, + EnableEpochsHandler: context.EnableEpochsHandler, + WasmVMChangeLocker: context.WasmVMChangeLocker, + VMOutputCacher: txcache.NewDisabledCache(), + FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, } context.ScProcessor, err = processProxy.NewTestSmartContractProcessorProxy(argsNewSCProcessor, context.EpochNotifier) require.Nil(context.T, err) argsNewTxProcessor := processTransaction.ArgsNewTxProcessor{ - Accounts: context.Accounts, - Hasher: hasher, - PubkeyConv: pkConverter, - Marshalizer: marshalizer, - SignMarshalizer: marshalizer, - ShardCoordinator: oneShardCoordinator, - ScProcessor: context.ScProcessor, - TxFeeHandler: context.UnsignexTxHandler, - TxTypeHandler: txTypeHandler, - EconomicsFee: context.EconomicsFee, - ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, - BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, - ArgsParser: smartContract.NewArgumentParser(), - ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, - EnableRoundsHandler: context.EnableRoundsHandler, - EnableEpochsHandler: context.EnableEpochsHandler, - TxVersionChecker: &testscommon.TxVersionCheckerStub{}, - GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, - TxLogsProcessor: context.TxLogsProcessor, - RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, + Accounts: context.Accounts, + Hasher: hasher, + PubkeyConv: pkConverter, + Marshalizer: marshalizer, + SignMarshalizer: marshalizer, + ShardCoordinator: oneShardCoordinator, + ScProcessor: context.ScProcessor, + TxFeeHandler: context.UnsignexTxHandler, + TxTypeHandler: txTypeHandler, + EconomicsFee: context.EconomicsFee, + ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, + BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, + ArgsParser: smartContract.NewArgumentParser(), + ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, + EnableRoundsHandler: context.EnableRoundsHandler, + EnableEpochsHandler: context.EnableEpochsHandler, + TxVersionChecker: &testscommon.TxVersionCheckerStub{}, + GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, + TxLogsProcessor: context.TxLogsProcessor, + RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, + FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, } context.TxProcessor, err = processTransaction.NewTxProcessor(argsNewTxProcessor) diff --git a/integrationTests/vm/wasm/wasmvm/wasmVM_test.go b/integrationTests/vm/wasm/wasmvm/wasmVM_test.go index 115c1ba8777..1fa706e8003 100644 --- a/integrationTests/vm/wasm/wasmvm/wasmVM_test.go +++ b/integrationTests/vm/wasm/wasmvm/wasmVM_test.go @@ -630,24 +630,25 @@ func TestExecuteTransactionAndTimeToProcessChange(t *testing.T) { _, _ = vm.CreateAccount(accnts, ownerAddressBytes, ownerNonce, ownerBalance) argsNewTxProcessor := processTransaction.ArgsNewTxProcessor{ - Accounts: accnts, - Hasher: testHasher, - PubkeyConv: pubkeyConv, - Marshalizer: testMarshalizer, - SignMarshalizer: testMarshalizer, - ShardCoordinator: shardCoordinator, - ScProcessor: &testscommon.SCProcessorMock{}, - TxFeeHandler: &testscommon.UnsignedTxHandlerStub{}, - TxTypeHandler: txTypeHandler, - EconomicsFee: &economicsmocks.EconomicsHandlerStub{}, - ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, - BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, - ArgsParser: smartContract.NewArgumentParser(), - ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, - EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, - EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - TxLogsProcessor: &mock.TxLogsProcessorStub{}, - RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, + Accounts: accnts, + Hasher: testHasher, + PubkeyConv: pubkeyConv, + Marshalizer: testMarshalizer, + SignMarshalizer: testMarshalizer, + ShardCoordinator: shardCoordinator, + ScProcessor: &testscommon.SCProcessorMock{}, + TxFeeHandler: &testscommon.UnsignedTxHandlerStub{}, + TxTypeHandler: txTypeHandler, + EconomicsFee: &economicsmocks.EconomicsHandlerStub{}, + ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, + BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, + ArgsParser: smartContract.NewArgumentParser(), + ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, + EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, + EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + TxLogsProcessor: &mock.TxLogsProcessorStub{}, + RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, + FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, } txProc, _ := processTransaction.NewTxProcessor(argsNewTxProcessor) diff --git a/process/disabled/failedTxLogsAccumulator.go b/process/disabled/failedTxLogsAccumulator.go new file mode 100644 index 00000000000..3bd3f01cd69 --- /dev/null +++ b/process/disabled/failedTxLogsAccumulator.go @@ -0,0 +1,33 @@ +package disabled + +import ( + "github.com/multiversx/mx-chain-core-go/data" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" +) + +type failedTxLogsAccumulator struct { +} + +// NewFailedTxLogsAccumulator returns a new instance of disabled failedTxLogsAccumulator +func NewFailedTxLogsAccumulator() *failedTxLogsAccumulator { + return &failedTxLogsAccumulator{} +} + +// GetLogs returns false as it is disabled +func (accumulator *failedTxLogsAccumulator) GetLogs(_ []byte) (data.TransactionHandler, []*vmcommon.LogEntry, bool) { + return nil, nil, false +} + +// SaveLogs returns nil as it is disabled +func (accumulator *failedTxLogsAccumulator) SaveLogs(_ []byte, _ data.TransactionHandler, _ []*vmcommon.LogEntry) error { + return nil +} + +// Remove does nothing as it is disabled +func (accumulator *failedTxLogsAccumulator) Remove(_ []byte) { +} + +// IsInterfaceNil returns true if there is no value under the interface +func (accumulator *failedTxLogsAccumulator) IsInterfaceNil() bool { + return accumulator == nil +} diff --git a/process/errors.go b/process/errors.go index 7e585f6725c..8753a061b9a 100644 --- a/process/errors.go +++ b/process/errors.go @@ -1268,3 +1268,6 @@ var ErrRelayedTxV3InvalidDataField = errors.New("invalid data field") // ErrMultipleRelayedTxTypesIsNotAllowed signals that multiple types of relayed tx is not allowed var ErrMultipleRelayedTxTypesIsNotAllowed = errors.New("multiple relayed tx types is not allowed") + +// ErrNilFailedTxLogsAccumulator signals that a nil failed transaction logs accumulator has been provided +var ErrNilFailedTxLogsAccumulator = errors.New("nil failed transaction logs accumulator") diff --git a/process/interface.go b/process/interface.go index 21197ad7a8b..debadba55bc 100644 --- a/process/interface.go +++ b/process/interface.go @@ -303,7 +303,6 @@ type TransactionLogProcessor interface { GetAllCurrentLogs() []*data.LogData GetLog(txHash []byte) (data.LogHandler, error) SaveLog(txHash []byte, tx data.TransactionHandler, vmLogs []*vmcommon.LogEntry) error - AppendLog(txHash []byte, tx data.TransactionHandler, logEntries []*vmcommon.LogEntry) error Clean() IsInterfaceNil() bool } @@ -1366,3 +1365,11 @@ type RelayedTxV3Processor interface { ComputeRelayedTxFees(tx *transaction.Transaction) (*big.Int, *big.Int) IsInterfaceNil() bool } + +// FailedTxLogsAccumulator defines a component able to accumulate logs during a relayed tx execution +type FailedTxLogsAccumulator interface { + GetLogs(txHash []byte) (data.TransactionHandler, []*vmcommon.LogEntry, bool) + SaveLogs(txHash []byte, tx data.TransactionHandler, logs []*vmcommon.LogEntry) error + Remove(txHash []byte) + IsInterfaceNil() bool +} diff --git a/process/mock/txLogsProcessorStub.go b/process/mock/txLogsProcessorStub.go index 86f1791547a..18e1e368274 100644 --- a/process/mock/txLogsProcessorStub.go +++ b/process/mock/txLogsProcessorStub.go @@ -9,7 +9,6 @@ import ( type TxLogsProcessorStub struct { GetLogCalled func(txHash []byte) (data.LogHandler, error) SaveLogCalled func(txHash []byte, tx data.TransactionHandler, vmLogs []*vmcommon.LogEntry) error - AppendLogCalled func(txHash []byte, tx data.TransactionHandler, logEntries []*vmcommon.LogEntry) error GetAllCurrentLogsCalled func() []*data.LogData } @@ -44,15 +43,6 @@ func (txls *TxLogsProcessorStub) GetAllCurrentLogs() []*data.LogData { return nil } -// AppendLog - -func (txls *TxLogsProcessorStub) AppendLog(txHash []byte, tx data.TransactionHandler, logEntries []*vmcommon.LogEntry) error { - if txls.AppendLogCalled != nil { - return txls.AppendLogCalled(txHash, tx, logEntries) - } - - return nil -} - // IsInterfaceNil - func (txls *TxLogsProcessorStub) IsInterfaceNil() bool { return txls == nil diff --git a/process/smartContract/processProxy/processProxy.go b/process/smartContract/processProxy/processProxy.go index c64db4791a4..a36a5fbd4f4 100644 --- a/process/smartContract/processProxy/processProxy.go +++ b/process/smartContract/processProxy/processProxy.go @@ -50,29 +50,30 @@ func NewSmartContractProcessorProxy(args scrCommon.ArgsNewSmartContractProcessor proxy := &scProcessorProxy{ args: scrCommon.ArgsNewSmartContractProcessor{ - VmContainer: args.VmContainer, - ArgsParser: args.ArgsParser, - Hasher: args.Hasher, - Marshalizer: args.Marshalizer, - AccountsDB: args.AccountsDB, - BlockChainHook: args.BlockChainHook, - BuiltInFunctions: args.BuiltInFunctions, - PubkeyConv: args.PubkeyConv, - ShardCoordinator: args.ShardCoordinator, - ScrForwarder: args.ScrForwarder, - TxFeeHandler: args.TxFeeHandler, - EconomicsFee: args.EconomicsFee, - TxTypeHandler: args.TxTypeHandler, - GasHandler: args.GasHandler, - GasSchedule: args.GasSchedule, - TxLogsProcessor: args.TxLogsProcessor, - BadTxForwarder: args.BadTxForwarder, - EnableRoundsHandler: args.EnableRoundsHandler, - EnableEpochsHandler: args.EnableEpochsHandler, - EnableEpochs: args.EnableEpochs, - VMOutputCacher: args.VMOutputCacher, - WasmVMChangeLocker: args.WasmVMChangeLocker, - IsGenesisProcessing: args.IsGenesisProcessing, + VmContainer: args.VmContainer, + ArgsParser: args.ArgsParser, + Hasher: args.Hasher, + Marshalizer: args.Marshalizer, + AccountsDB: args.AccountsDB, + BlockChainHook: args.BlockChainHook, + BuiltInFunctions: args.BuiltInFunctions, + PubkeyConv: args.PubkeyConv, + ShardCoordinator: args.ShardCoordinator, + ScrForwarder: args.ScrForwarder, + TxFeeHandler: args.TxFeeHandler, + EconomicsFee: args.EconomicsFee, + TxTypeHandler: args.TxTypeHandler, + GasHandler: args.GasHandler, + GasSchedule: args.GasSchedule, + TxLogsProcessor: args.TxLogsProcessor, + BadTxForwarder: args.BadTxForwarder, + EnableRoundsHandler: args.EnableRoundsHandler, + EnableEpochsHandler: args.EnableEpochsHandler, + EnableEpochs: args.EnableEpochs, + VMOutputCacher: args.VMOutputCacher, + WasmVMChangeLocker: args.WasmVMChangeLocker, + IsGenesisProcessing: args.IsGenesisProcessing, + FailedTxLogsAccumulator: args.FailedTxLogsAccumulator, }, } if check.IfNil(epochNotifier) { diff --git a/process/smartContract/processProxy/processProxy_test.go b/process/smartContract/processProxy/processProxy_test.go index 0b5695386a8..d74d09f377c 100644 --- a/process/smartContract/processProxy/processProxy_test.go +++ b/process/smartContract/processProxy/processProxy_test.go @@ -23,6 +23,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" epochNotifierMock "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" + "github.com/multiversx/mx-chain-go/testscommon/processMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/multiversx/mx-chain-vm-common-go/builtInFunctions" @@ -76,9 +77,10 @@ func createMockSmartContractProcessorArguments() scrCommon.ArgsNewSmartContractP return flag == common.SCDeployFlag }, }, - EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, - WasmVMChangeLocker: &sync.RWMutex{}, - VMOutputCacher: txcache.NewDisabledCache(), + EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, + WasmVMChangeLocker: &sync.RWMutex{}, + VMOutputCacher: txcache.NewDisabledCache(), + FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, } } diff --git a/process/smartContract/processProxy/testProcessProxy.go b/process/smartContract/processProxy/testProcessProxy.go index 5d5d96ee0d2..65e5d525565 100644 --- a/process/smartContract/processProxy/testProcessProxy.go +++ b/process/smartContract/processProxy/testProcessProxy.go @@ -28,29 +28,30 @@ type scProcessorTestProxy struct { func NewTestSmartContractProcessorProxy(args scrCommon.ArgsNewSmartContractProcessor, epochNotifier vmcommon.EpochNotifier) (*scProcessorTestProxy, error) { scProcessorTestProxy := &scProcessorTestProxy{ args: scrCommon.ArgsNewSmartContractProcessor{ - VmContainer: args.VmContainer, - ArgsParser: args.ArgsParser, - Hasher: args.Hasher, - Marshalizer: args.Marshalizer, - AccountsDB: args.AccountsDB, - BlockChainHook: args.BlockChainHook, - BuiltInFunctions: args.BuiltInFunctions, - PubkeyConv: args.PubkeyConv, - ShardCoordinator: args.ShardCoordinator, - ScrForwarder: args.ScrForwarder, - TxFeeHandler: args.TxFeeHandler, - EconomicsFee: args.EconomicsFee, - TxTypeHandler: args.TxTypeHandler, - GasHandler: args.GasHandler, - GasSchedule: args.GasSchedule, - TxLogsProcessor: args.TxLogsProcessor, - BadTxForwarder: args.BadTxForwarder, - EnableRoundsHandler: args.EnableRoundsHandler, - EnableEpochsHandler: args.EnableEpochsHandler, - EnableEpochs: args.EnableEpochs, - VMOutputCacher: args.VMOutputCacher, - WasmVMChangeLocker: args.WasmVMChangeLocker, - IsGenesisProcessing: args.IsGenesisProcessing, + VmContainer: args.VmContainer, + ArgsParser: args.ArgsParser, + Hasher: args.Hasher, + Marshalizer: args.Marshalizer, + AccountsDB: args.AccountsDB, + BlockChainHook: args.BlockChainHook, + BuiltInFunctions: args.BuiltInFunctions, + PubkeyConv: args.PubkeyConv, + ShardCoordinator: args.ShardCoordinator, + ScrForwarder: args.ScrForwarder, + TxFeeHandler: args.TxFeeHandler, + EconomicsFee: args.EconomicsFee, + TxTypeHandler: args.TxTypeHandler, + GasHandler: args.GasHandler, + GasSchedule: args.GasSchedule, + TxLogsProcessor: args.TxLogsProcessor, + BadTxForwarder: args.BadTxForwarder, + EnableRoundsHandler: args.EnableRoundsHandler, + EnableEpochsHandler: args.EnableEpochsHandler, + EnableEpochs: args.EnableEpochs, + VMOutputCacher: args.VMOutputCacher, + WasmVMChangeLocker: args.WasmVMChangeLocker, + IsGenesisProcessing: args.IsGenesisProcessing, + FailedTxLogsAccumulator: args.FailedTxLogsAccumulator, }, } diff --git a/process/smartContract/process_test.go b/process/smartContract/process_test.go index c53c7ef83c9..fa693dd5ab6 100644 --- a/process/smartContract/process_test.go +++ b/process/smartContract/process_test.go @@ -32,6 +32,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" + "github.com/multiversx/mx-chain-go/testscommon/processMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" "github.com/multiversx/mx-chain-go/testscommon/trie" "github.com/multiversx/mx-chain-go/testscommon/vmcommonMocks" @@ -114,11 +115,12 @@ func createMockSmartContractProcessorArguments() scrCommon.ArgsNewSmartContractP GasHandler: &testscommon.GasHandlerStub{ SetGasRefundedCalled: func(gasRefunded uint64, hash []byte) {}, }, - GasSchedule: testscommon.NewGasScheduleNotifierMock(gasSchedule), - EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, - EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.SCDeployFlag), - WasmVMChangeLocker: &sync.RWMutex{}, - VMOutputCacher: txcache.NewDisabledCache(), + GasSchedule: testscommon.NewGasScheduleNotifierMock(gasSchedule), + EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.SCDeployFlag), + WasmVMChangeLocker: &sync.RWMutex{}, + VMOutputCacher: txcache.NewDisabledCache(), + FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, } } diff --git a/process/smartContract/processorV2/processV2.go b/process/smartContract/processorV2/processV2.go index 76c157fa8a5..47c08e6829c 100644 --- a/process/smartContract/processorV2/processV2.go +++ b/process/smartContract/processorV2/processV2.go @@ -80,13 +80,14 @@ type scProcessor struct { txTypeHandler process.TxTypeHandler gasHandler process.GasHandler - builtInGasCosts map[string]uint64 - persistPerByte uint64 - storePerByte uint64 - mutGasLock sync.RWMutex - txLogsProcessor process.TransactionLogProcessor - vmOutputCacher storage.Cacher - isGenesisProcessing bool + builtInGasCosts map[string]uint64 + persistPerByte uint64 + storePerByte uint64 + mutGasLock sync.RWMutex + txLogsProcessor process.TransactionLogProcessor + failedTxLogsAccumulator process.FailedTxLogsAccumulator + vmOutputCacher storage.Cacher + isGenesisProcessing bool executableCheckers map[string]scrCommon.ExecutableChecker mutExecutableCheckers sync.RWMutex @@ -160,6 +161,9 @@ func NewSmartContractProcessorV2(args scrCommon.ArgsNewSmartContractProcessor) ( if check.IfNil(args.TxLogsProcessor) { return nil, process.ErrNilTxLogsProcessor } + if check.IfNil(args.FailedTxLogsAccumulator) { + return nil, process.ErrNilFailedTxLogsAccumulator + } if check.IfNil(args.EnableEpochsHandler) { return nil, process.ErrNilEnableEpochsHandler } @@ -183,30 +187,31 @@ func NewSmartContractProcessorV2(args scrCommon.ArgsNewSmartContractProcessor) ( builtInFuncCost := args.GasSchedule.LatestGasSchedule()[common.BuiltInCost] baseOperationCost := args.GasSchedule.LatestGasSchedule()[common.BaseOperationCost] sc := &scProcessor{ - vmContainer: args.VmContainer, - argsParser: args.ArgsParser, - hasher: args.Hasher, - marshalizer: args.Marshalizer, - accounts: args.AccountsDB, - blockChainHook: args.BlockChainHook, - pubkeyConv: args.PubkeyConv, - shardCoordinator: args.ShardCoordinator, - scrForwarder: args.ScrForwarder, - txFeeHandler: args.TxFeeHandler, - economicsFee: args.EconomicsFee, - txTypeHandler: args.TxTypeHandler, - gasHandler: args.GasHandler, - builtInGasCosts: builtInFuncCost, - txLogsProcessor: args.TxLogsProcessor, - badTxForwarder: args.BadTxForwarder, - builtInFunctions: args.BuiltInFunctions, - isGenesisProcessing: args.IsGenesisProcessing, - arwenChangeLocker: args.WasmVMChangeLocker, - vmOutputCacher: args.VMOutputCacher, - enableEpochsHandler: args.EnableEpochsHandler, - storePerByte: baseOperationCost["StorePerByte"], - persistPerByte: baseOperationCost["PersistPerByte"], - executableCheckers: scrCommon.CreateExecutableCheckersMap(args.BuiltInFunctions), + vmContainer: args.VmContainer, + argsParser: args.ArgsParser, + hasher: args.Hasher, + marshalizer: args.Marshalizer, + accounts: args.AccountsDB, + blockChainHook: args.BlockChainHook, + pubkeyConv: args.PubkeyConv, + shardCoordinator: args.ShardCoordinator, + scrForwarder: args.ScrForwarder, + txFeeHandler: args.TxFeeHandler, + economicsFee: args.EconomicsFee, + txTypeHandler: args.TxTypeHandler, + gasHandler: args.GasHandler, + builtInGasCosts: builtInFuncCost, + txLogsProcessor: args.TxLogsProcessor, + failedTxLogsAccumulator: args.FailedTxLogsAccumulator, + badTxForwarder: args.BadTxForwarder, + builtInFunctions: args.BuiltInFunctions, + isGenesisProcessing: args.IsGenesisProcessing, + arwenChangeLocker: args.WasmVMChangeLocker, + vmOutputCacher: args.VMOutputCacher, + enableEpochsHandler: args.EnableEpochsHandler, + storePerByte: baseOperationCost["StorePerByte"], + persistPerByte: baseOperationCost["PersistPerByte"], + executableCheckers: scrCommon.CreateExecutableCheckersMap(args.BuiltInFunctions), } sc.esdtTransferParser, err = parsers.NewESDTTransferParser(args.Marshalizer) @@ -1405,19 +1410,20 @@ func (sc *scProcessor) isCrossShardESDTTransfer(sender []byte, receiver []byte, func (sc *scProcessor) getOriginalTxHashIfIntraShardRelayedSCR( tx data.TransactionHandler, - txHash []byte) []byte { + txHash []byte, +) ([]byte, bool) { relayedSCR, isRelayed := isRelayedTx(tx) if !isRelayed { - return txHash + return txHash, isRelayed } sndShardID := sc.shardCoordinator.ComputeId(relayedSCR.SndAddr) rcvShardID := sc.shardCoordinator.ComputeId(relayedSCR.RcvAddr) if sndShardID != rcvShardID { - return txHash + return txHash, isRelayed } - return relayedSCR.OriginalTxHash + return relayedSCR.OriginalTxHash, isRelayed } // ProcessIfError creates a smart contract result, consumes the gas and returns the value to the user @@ -1507,10 +1513,15 @@ func (sc *scProcessor) processIfErrorWithAddedLogs(acntSnd state.UserAccountHand processIfErrorLogs = append(processIfErrorLogs, failureContext.logs...) } - logsTxHash := sc.getOriginalTxHashIfIntraShardRelayedSCR(tx, failureContext.txHash) - ignorableError := sc.txLogsProcessor.AppendLog(logsTxHash, tx, processIfErrorLogs) + logsTxHash, isRelayed := sc.getOriginalTxHashIfIntraShardRelayedSCR(tx, failureContext.txHash) + var ignorableError error + if isRelayed { + ignorableError = sc.failedTxLogsAccumulator.SaveLogs(logsTxHash, tx, processIfErrorLogs) + } else { + ignorableError = sc.txLogsProcessor.SaveLog(logsTxHash, tx, processIfErrorLogs) + } if ignorableError != nil { - log.Debug("scProcessor.ProcessIfError() txLogsProcessor.SaveLog()", "error", ignorableError.Error()) + log.Debug("scProcessor.ProcessIfError() save log", "error", ignorableError.Error(), "isRelayed", isRelayed) } txType, _ := sc.txTypeHandler.ComputeTransactionType(tx) diff --git a/process/smartContract/processorV2/process_test.go b/process/smartContract/processorV2/process_test.go index eedea17f1ad..4ef5ac15af8 100644 --- a/process/smartContract/processorV2/process_test.go +++ b/process/smartContract/processorV2/process_test.go @@ -35,6 +35,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" + "github.com/multiversx/mx-chain-go/testscommon/processMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" testsCommonStorage "github.com/multiversx/mx-chain-go/testscommon/storage" "github.com/multiversx/mx-chain-go/testscommon/vmcommonMocks" @@ -129,9 +130,10 @@ func createMockSmartContractProcessorArguments() scrCommon.ArgsNewSmartContractP return flag == common.SCDeployFlag }, }, - GasSchedule: testscommon.NewGasScheduleNotifierMock(gasSchedule), - WasmVMChangeLocker: &sync.RWMutex{}, - VMOutputCacher: txcache.NewDisabledCache(), + GasSchedule: testscommon.NewGasScheduleNotifierMock(gasSchedule), + WasmVMChangeLocker: &sync.RWMutex{}, + VMOutputCacher: txcache.NewDisabledCache(), + FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, } } @@ -334,6 +336,17 @@ func TestNewSmartContractProcessor_NilTxLogsProcessorShouldErr(t *testing.T) { require.Equal(t, process.ErrNilTxLogsProcessor, err) } +func TestNewSmartContractProcessor_NilFailedTxLogsAccumulatorShouldErr(t *testing.T) { + t.Parallel() + + arguments := createMockSmartContractProcessorArguments() + arguments.FailedTxLogsAccumulator = nil + sc, err := NewSmartContractProcessorV2(arguments) + + require.Nil(t, sc) + require.Equal(t, process.ErrNilFailedTxLogsAccumulator, err) +} + func TestNewSmartContractProcessor_NilBadTxForwarderShouldErr(t *testing.T) { t.Parallel() @@ -3330,6 +3343,13 @@ func TestScProcessor_ProcessRelayedSCRValueBackToRelayer(t *testing.T) { return process.SCInvoking, process.SCInvoking }, } + wasSaveLogsCalled := false + arguments.FailedTxLogsAccumulator = &processMocks.FailedTxLogsAccumulatorMock{ + SaveLogsCalled: func(txHash []byte, tx data.TransactionHandler, logs []*vmcommon.LogEntry) error { + wasSaveLogsCalled = true + return nil + }, + } sc, err := NewSmartContractProcessorV2(arguments) require.NotNil(t, sc) require.Nil(t, err) @@ -3352,6 +3372,7 @@ func TestScProcessor_ProcessRelayedSCRValueBackToRelayer(t *testing.T) { userFinalValue := baseValue.Sub(baseValue, scr.Value) userFinalValue.Add(userFinalValue, userReturnValue) require.True(t, userAcc.GetBalance().Cmp(userFinalValue) == 0) + require.True(t, wasSaveLogsCalled) } func TestScProcessor_checkUpgradePermission(t *testing.T) { @@ -4061,18 +4082,20 @@ func TestProcessGetOriginalTxHashForRelayedIntraShard(t *testing.T) { scr := &smartContractResult.SmartContractResult{Value: big.NewInt(1), SndAddr: bytes.Repeat([]byte{1}, 32)} scrHash := []byte("hash") - logHash := sc.getOriginalTxHashIfIntraShardRelayedSCR(scr, scrHash) + logHash, isRelayed := sc.getOriginalTxHashIfIntraShardRelayedSCR(scr, scrHash) assert.Equal(t, scrHash, logHash) + assert.False(t, isRelayed) scr.OriginalTxHash = []byte("originalHash") scr.RelayerAddr = bytes.Repeat([]byte{1}, 32) scr.SndAddr = bytes.Repeat([]byte{1}, 32) scr.RcvAddr = bytes.Repeat([]byte{1}, 32) - logHash = sc.getOriginalTxHashIfIntraShardRelayedSCR(scr, scrHash) + logHash, isRelayed = sc.getOriginalTxHashIfIntraShardRelayedSCR(scr, scrHash) assert.Equal(t, scr.OriginalTxHash, logHash) + assert.True(t, isRelayed) scr.RcvAddr = bytes.Repeat([]byte{2}, 32) - logHash = sc.getOriginalTxHashIfIntraShardRelayedSCR(scr, scrHash) + logHash, _ = sc.getOriginalTxHashIfIntraShardRelayedSCR(scr, scrHash) assert.Equal(t, scrHash, logHash) } diff --git a/process/smartContract/scrCommon/common.go b/process/smartContract/scrCommon/common.go index 957abe5800b..07efc6cfd59 100644 --- a/process/smartContract/scrCommon/common.go +++ b/process/smartContract/scrCommon/common.go @@ -1,6 +1,8 @@ package scrCommon import ( + "math/big" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/hashing" @@ -12,7 +14,6 @@ import ( "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/storage" vmcommon "github.com/multiversx/mx-chain-vm-common-go" - "math/big" ) // TestSmartContractProcessor is a SmartContractProcessor used in integration tests @@ -31,29 +32,30 @@ type ExecutableChecker interface { // ArgsNewSmartContractProcessor defines the arguments needed for new smart contract processor type ArgsNewSmartContractProcessor struct { - VmContainer process.VirtualMachinesContainer - ArgsParser process.ArgumentsParser - Hasher hashing.Hasher - Marshalizer marshal.Marshalizer - AccountsDB state.AccountsAdapter - BlockChainHook process.BlockChainHookHandler - BuiltInFunctions vmcommon.BuiltInFunctionContainer - PubkeyConv core.PubkeyConverter - ShardCoordinator sharding.Coordinator - ScrForwarder process.IntermediateTransactionHandler - TxFeeHandler process.TransactionFeeHandler - EconomicsFee process.FeeHandler - TxTypeHandler process.TxTypeHandler - GasHandler process.GasHandler - GasSchedule core.GasScheduleNotifier - TxLogsProcessor process.TransactionLogProcessor - BadTxForwarder process.IntermediateTransactionHandler - EnableRoundsHandler process.EnableRoundsHandler - EnableEpochsHandler common.EnableEpochsHandler - EnableEpochs config.EnableEpochs - VMOutputCacher storage.Cacher - WasmVMChangeLocker common.Locker - IsGenesisProcessing bool + VmContainer process.VirtualMachinesContainer + ArgsParser process.ArgumentsParser + Hasher hashing.Hasher + Marshalizer marshal.Marshalizer + AccountsDB state.AccountsAdapter + BlockChainHook process.BlockChainHookHandler + BuiltInFunctions vmcommon.BuiltInFunctionContainer + PubkeyConv core.PubkeyConverter + ShardCoordinator sharding.Coordinator + ScrForwarder process.IntermediateTransactionHandler + TxFeeHandler process.TransactionFeeHandler + EconomicsFee process.FeeHandler + TxTypeHandler process.TxTypeHandler + GasHandler process.GasHandler + GasSchedule core.GasScheduleNotifier + TxLogsProcessor process.TransactionLogProcessor + FailedTxLogsAccumulator process.FailedTxLogsAccumulator + BadTxForwarder process.IntermediateTransactionHandler + EnableRoundsHandler process.EnableRoundsHandler + EnableEpochsHandler common.EnableEpochsHandler + EnableEpochs config.EnableEpochs + VMOutputCacher storage.Cacher + WasmVMChangeLocker common.Locker + IsGenesisProcessing bool } // FindVMByScAddress is exported for use in all version of scr processors diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 0ce75c6f913..68b4cd967d0 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -37,40 +37,42 @@ type relayedFees struct { // txProcessor implements TransactionProcessor interface and can modify account states according to a transaction type txProcessor struct { *baseTxProcessor - txFeeHandler process.TransactionFeeHandler - txTypeHandler process.TxTypeHandler - receiptForwarder process.IntermediateTransactionHandler - badTxForwarder process.IntermediateTransactionHandler - argsParser process.ArgumentsParser - scrForwarder process.IntermediateTransactionHandler - signMarshalizer marshal.Marshalizer - enableEpochsHandler common.EnableEpochsHandler - txLogsProcessor process.TransactionLogProcessor - relayedTxV3Processor process.RelayedTxV3Processor + txFeeHandler process.TransactionFeeHandler + txTypeHandler process.TxTypeHandler + receiptForwarder process.IntermediateTransactionHandler + badTxForwarder process.IntermediateTransactionHandler + argsParser process.ArgumentsParser + scrForwarder process.IntermediateTransactionHandler + signMarshalizer marshal.Marshalizer + enableEpochsHandler common.EnableEpochsHandler + txLogsProcessor process.TransactionLogProcessor + relayedTxV3Processor process.RelayedTxV3Processor + failedTxLogsAccumulator process.FailedTxLogsAccumulator } // ArgsNewTxProcessor defines the arguments needed for new tx processor type ArgsNewTxProcessor struct { - Accounts state.AccountsAdapter - Hasher hashing.Hasher - PubkeyConv core.PubkeyConverter - Marshalizer marshal.Marshalizer - SignMarshalizer marshal.Marshalizer - ShardCoordinator sharding.Coordinator - ScProcessor process.SmartContractProcessor - TxFeeHandler process.TransactionFeeHandler - TxTypeHandler process.TxTypeHandler - EconomicsFee process.FeeHandler - ReceiptForwarder process.IntermediateTransactionHandler - BadTxForwarder process.IntermediateTransactionHandler - ArgsParser process.ArgumentsParser - ScrForwarder process.IntermediateTransactionHandler - EnableRoundsHandler process.EnableRoundsHandler - EnableEpochsHandler common.EnableEpochsHandler - TxVersionChecker process.TxVersionCheckerHandler - GuardianChecker process.GuardianChecker - TxLogsProcessor process.TransactionLogProcessor - RelayedTxV3Processor process.RelayedTxV3Processor + Accounts state.AccountsAdapter + Hasher hashing.Hasher + PubkeyConv core.PubkeyConverter + Marshalizer marshal.Marshalizer + SignMarshalizer marshal.Marshalizer + ShardCoordinator sharding.Coordinator + ScProcessor process.SmartContractProcessor + TxFeeHandler process.TransactionFeeHandler + TxTypeHandler process.TxTypeHandler + EconomicsFee process.FeeHandler + ReceiptForwarder process.IntermediateTransactionHandler + BadTxForwarder process.IntermediateTransactionHandler + ArgsParser process.ArgumentsParser + ScrForwarder process.IntermediateTransactionHandler + EnableRoundsHandler process.EnableRoundsHandler + EnableEpochsHandler common.EnableEpochsHandler + TxVersionChecker process.TxVersionCheckerHandler + GuardianChecker process.GuardianChecker + TxLogsProcessor process.TransactionLogProcessor + RelayedTxV3Processor process.RelayedTxV3Processor + FailedTxLogsAccumulator process.FailedTxLogsAccumulator } // NewTxProcessor creates a new txProcessor engine @@ -148,6 +150,9 @@ func NewTxProcessor(args ArgsNewTxProcessor) (*txProcessor, error) { if check.IfNil(args.RelayedTxV3Processor) { return nil, process.ErrNilRelayedTxV3Processor } + if check.IfNil(args.FailedTxLogsAccumulator) { + return nil, process.ErrNilFailedTxLogsAccumulator + } baseTxProcess := &baseTxProcessor{ accounts: args.Accounts, @@ -163,17 +168,18 @@ func NewTxProcessor(args ArgsNewTxProcessor) (*txProcessor, error) { } txProc := &txProcessor{ - baseTxProcessor: baseTxProcess, - txFeeHandler: args.TxFeeHandler, - txTypeHandler: args.TxTypeHandler, - receiptForwarder: args.ReceiptForwarder, - badTxForwarder: args.BadTxForwarder, - argsParser: args.ArgsParser, - scrForwarder: args.ScrForwarder, - signMarshalizer: args.SignMarshalizer, - enableEpochsHandler: args.EnableEpochsHandler, - txLogsProcessor: args.TxLogsProcessor, - relayedTxV3Processor: args.RelayedTxV3Processor, + baseTxProcessor: baseTxProcess, + txFeeHandler: args.TxFeeHandler, + txTypeHandler: args.TxTypeHandler, + receiptForwarder: args.ReceiptForwarder, + badTxForwarder: args.BadTxForwarder, + argsParser: args.ArgsParser, + scrForwarder: args.ScrForwarder, + signMarshalizer: args.SignMarshalizer, + enableEpochsHandler: args.EnableEpochsHandler, + txLogsProcessor: args.TxLogsProcessor, + relayedTxV3Processor: args.RelayedTxV3Processor, + failedTxLogsAccumulator: args.FailedTxLogsAccumulator, } return txProc, nil @@ -601,6 +607,8 @@ func (txProc *txProcessor) finishExecutionOfRelayedTx( err.Error()) } + defer txProc.saveFailedLogsIfNeeded(originalTxHash) + return txProc.processUserTx(tx, userTx, tx.Value, tx.Nonce, originalTxHash) } @@ -701,6 +709,8 @@ func (txProc *txProcessor) processRelayedTxV3( allUserTxsSucceeded := len(executedUserTxs) == len(innerTxs) && innerTxErr == nil && innerTxRetCode == vmcommon.Ok if !allUserTxsSucceeded { log.Trace("failed to execute all inner transactions", "total", len(innerTxs), "executed transactions", len(executedUserTxs)) + + txProc.saveFailedLogsIfNeeded(originalTxHash) } expectedInnerTxsTotalFees := big.NewInt(0).Sub(totalFee, relayerFee) @@ -1216,6 +1226,18 @@ func (txProc *txProcessor) createCompleteEventLog(scr data.TransactionHandler, o } } +func (txProc *txProcessor) saveFailedLogsIfNeeded(originalTxHash []byte) { + logsTx, logs, ok := txProc.failedTxLogsAccumulator.GetLogs(originalTxHash) + if ok { + ignorableErr := txProc.txLogsProcessor.SaveLog(originalTxHash, logsTx, logs) + if ignorableErr != nil { + log.Debug("txLogsProcessor.SaveLog failed", "error", ignorableErr.Error()) + } + } + + txProc.failedTxLogsAccumulator.Remove(originalTxHash) +} + // IsInterfaceNil returns true if there is no value under the interface func (txProc *txProcessor) IsInterfaceNil() bool { return txProc == nil diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index 2f19983bdcb..76307c8be37 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -78,26 +78,27 @@ func createAccountStub(sndAddr, rcvAddr []byte, func createArgsForTxProcessor() txproc.ArgsNewTxProcessor { args := txproc.ArgsNewTxProcessor{ - Accounts: &stateMock.AccountsStub{}, - Hasher: &hashingMocks.HasherMock{}, - PubkeyConv: createMockPubKeyConverter(), - Marshalizer: &mock.MarshalizerMock{}, - SignMarshalizer: &mock.MarshalizerMock{}, - ShardCoordinator: mock.NewOneShardCoordinatorMock(), - ScProcessor: &testscommon.SCProcessorMock{}, - TxFeeHandler: &mock.FeeAccumulatorStub{}, - TxTypeHandler: &testscommon.TxTypeHandlerMock{}, - EconomicsFee: feeHandlerMock(), - ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, - BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, - ArgsParser: &mock.ArgumentParserMock{}, - ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, - EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.PenalizedTooMuchGasFlag, common.FixRelayedMoveBalanceFlag), - GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, - TxVersionChecker: &testscommon.TxVersionCheckerStub{}, - TxLogsProcessor: &mock.TxLogsProcessorStub{}, - EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, - RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, + Accounts: &stateMock.AccountsStub{}, + Hasher: &hashingMocks.HasherMock{}, + PubkeyConv: createMockPubKeyConverter(), + Marshalizer: &mock.MarshalizerMock{}, + SignMarshalizer: &mock.MarshalizerMock{}, + ShardCoordinator: mock.NewOneShardCoordinatorMock(), + ScProcessor: &testscommon.SCProcessorMock{}, + TxFeeHandler: &mock.FeeAccumulatorStub{}, + TxTypeHandler: &testscommon.TxTypeHandlerMock{}, + EconomicsFee: feeHandlerMock(), + ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, + BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, + ArgsParser: &mock.ArgumentParserMock{}, + ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.PenalizedTooMuchGasFlag, common.FixRelayedMoveBalanceFlag), + GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, + TxVersionChecker: &testscommon.TxVersionCheckerStub{}, + TxLogsProcessor: &mock.TxLogsProcessorStub{}, + EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, + RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, + FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, } return args } @@ -340,6 +341,17 @@ func TestNewTxProcessor_NilRelayedTxV3ProcessorShouldErr(t *testing.T) { assert.Nil(t, txProc) } +func TestNewTxProcessor_NilFailedTxLogsAccumulatorShouldErr(t *testing.T) { + t.Parallel() + + args := createArgsForTxProcessor() + args.FailedTxLogsAccumulator = nil + txProc, err := txproc.NewTxProcessor(args) + + assert.Equal(t, process.ErrNilFailedTxLogsAccumulator, err) + assert.Nil(t, txProc) +} + func TestNewTxProcessor_OkValsShouldWork(t *testing.T) { t.Parallel() @@ -2351,6 +2363,18 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { ShardCoordinator: args.ShardCoordinator, MaxTransactionsAllowed: 10, }) + wasGetLogsCalled := false + wasRemoveCalled := false + args.FailedTxLogsAccumulator = &processMocks.FailedTxLogsAccumulatorMock{ + GetLogsCalled: func(txHash []byte) (data.TransactionHandler, []*vmcommon.LogEntry, bool) { + wasGetLogsCalled = true + + return &smartContractResult.SmartContractResult{}, []*vmcommon.LogEntry{}, true + }, + RemoveCalled: func(txHash []byte) { + wasRemoveCalled = true + }, + } execTx, _ := txproc.NewTxProcessor(args) txCopy := *tx @@ -2359,6 +2383,8 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { returnCode, err := execTx.ProcessTransaction(&txCopy) assert.NoError(t, err) assert.Equal(t, vmcommon.Ok, returnCode) + assert.True(t, wasGetLogsCalled) + assert.True(t, wasRemoveCalled) }) t.Run("fees consumed mismatch should error", func(t *testing.T) { t.Parallel() diff --git a/process/transactionLog/failedTxLogsAccumulator.go b/process/transactionLog/failedTxLogsAccumulator.go new file mode 100644 index 00000000000..a0d973541bc --- /dev/null +++ b/process/transactionLog/failedTxLogsAccumulator.go @@ -0,0 +1,109 @@ +package transactionLog + +import ( + "sync" + + "github.com/multiversx/mx-chain-core-go/core/check" + "github.com/multiversx/mx-chain-core-go/data" + "github.com/multiversx/mx-chain-go/process" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" +) + +type logData struct { + tx data.TransactionHandler + logs []*vmcommon.LogEntry +} + +type failedTxLogsAccumulator struct { + mut sync.RWMutex + logsMap map[string]*logData +} + +// NewFailedTxLogsAccumulator returns a new instance of failedTxLogsAccumulator +func NewFailedTxLogsAccumulator() *failedTxLogsAccumulator { + return &failedTxLogsAccumulator{ + logsMap: make(map[string]*logData), + } +} + +// GetLogs returns the accumulated logs for the provided txHash +func (accumulator *failedTxLogsAccumulator) GetLogs(txHash []byte) (data.TransactionHandler, []*vmcommon.LogEntry, bool) { + if len(txHash) == 0 { + return nil, nil, false + } + + logsData, found := accumulator.getLogDataCopy(txHash) + + if !found { + return nil, nil, found + } + + return logsData.tx, logsData.logs, found +} + +func (accumulator *failedTxLogsAccumulator) getLogDataCopy(txHash []byte) (logData, bool) { + accumulator.mut.RLock() + defer accumulator.mut.RUnlock() + + logsData, found := accumulator.logsMap[string(txHash)] + if !found { + return logData{}, found + } + + logsDataCopy := logData{ + tx: logsData.tx, + } + + logsDataCopy.logs = append(logsDataCopy.logs, logsData.logs...) + + return logsDataCopy, found +} + +// SaveLogs saves the logs into the internal map +func (accumulator *failedTxLogsAccumulator) SaveLogs(txHash []byte, tx data.TransactionHandler, logs []*vmcommon.LogEntry) error { + if len(txHash) == 0 { + return process.ErrNilTxHash + } + + if check.IfNil(tx) { + return process.ErrNilTransaction + } + + if len(logs) == 0 { + return nil + } + + accumulator.mut.Lock() + defer accumulator.mut.Unlock() + + _, found := accumulator.logsMap[string(txHash)] + if !found { + accumulator.logsMap[string(txHash)] = &logData{ + tx: tx, + logs: logs, + } + + return nil + } + + accumulator.logsMap[string(txHash)].logs = append(accumulator.logsMap[string(txHash)].logs, logs...) + + return nil +} + +// Remove removes the accumulated logs for the provided txHash +func (accumulator *failedTxLogsAccumulator) Remove(txHash []byte) { + if len(txHash) == 0 { + return + } + + accumulator.mut.Lock() + defer accumulator.mut.Unlock() + + delete(accumulator.logsMap, string(txHash)) +} + +// IsInterfaceNil returns true if there is no value under the interface +func (accumulator *failedTxLogsAccumulator) IsInterfaceNil() bool { + return accumulator == nil +} diff --git a/process/transactionLog/failedTxLogsAccumulator_test.go b/process/transactionLog/failedTxLogsAccumulator_test.go new file mode 100644 index 00000000000..691f4b41ffa --- /dev/null +++ b/process/transactionLog/failedTxLogsAccumulator_test.go @@ -0,0 +1,168 @@ +package transactionLog + +import ( + "fmt" + "sync" + "testing" + + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-go/process" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/stretchr/testify/require" +) + +var ( + providedHash = []byte("hash") + providedTx = &transaction.Transaction{Nonce: 123} + providedLogs = []*vmcommon.LogEntry{ + { + Identifier: []byte("identifier"), + Address: []byte("addr"), + Topics: [][]byte{[]byte("topic")}, + Data: [][]byte{[]byte("data")}, + }, + } +) + +func TestNewFailedTxLogsAccumulator(t *testing.T) { + t.Parallel() + + accumulator := NewFailedTxLogsAccumulator() + require.NotNil(t, accumulator) +} + +func TestFailedTxLogsAccumulator_IsInterfaceNil(t *testing.T) { + t.Parallel() + + var accumulator *failedTxLogsAccumulator + require.True(t, accumulator.IsInterfaceNil()) + + accumulator = NewFailedTxLogsAccumulator() + require.False(t, accumulator.IsInterfaceNil()) +} + +func TestFailedTxLogsAccumulator_GetLogs(t *testing.T) { + t.Parallel() + + accumulator := NewFailedTxLogsAccumulator() + tx, logs, ok := accumulator.GetLogs([]byte("")) + require.False(t, ok) + require.Nil(t, tx) + require.Nil(t, logs) + + err := accumulator.SaveLogs(providedHash, providedTx, providedLogs) + require.NoError(t, err) + + tx, logs, ok = accumulator.GetLogs([]byte("missing hash")) + require.False(t, ok) + require.Nil(t, tx) + require.Nil(t, logs) + + tx, logs, ok = accumulator.GetLogs(providedHash) + require.True(t, ok) + require.Equal(t, providedTx, tx) + require.Equal(t, providedLogs, logs) +} + +func TestFailedTxLogsAccumulator_SaveLogs(t *testing.T) { + t.Parallel() + + t.Run("empty hash should error", func(t *testing.T) { + t.Parallel() + + accumulator := NewFailedTxLogsAccumulator() + err := accumulator.SaveLogs([]byte(""), nil, nil) + require.Equal(t, process.ErrNilTxHash, err) + }) + t.Run("nil tx should error", func(t *testing.T) { + t.Parallel() + + accumulator := NewFailedTxLogsAccumulator() + err := accumulator.SaveLogs(providedHash, nil, nil) + require.Equal(t, process.ErrNilTransaction, err) + }) + t.Run("empty logs should return nil", func(t *testing.T) { + t.Parallel() + + accumulator := NewFailedTxLogsAccumulator() + err := accumulator.SaveLogs(providedHash, providedTx, nil) + require.NoError(t, err) + }) + t.Run("should work and append logs", func(t *testing.T) { + t.Parallel() + + accumulator := NewFailedTxLogsAccumulator() + err := accumulator.SaveLogs(providedHash, providedTx, providedLogs) + require.NoError(t, err) + + providedNewLogs := []*vmcommon.LogEntry{ + { + Identifier: []byte("identifier 2"), + Address: []byte("addr"), + Topics: [][]byte{[]byte("topic 2")}, + Data: [][]byte{[]byte("data 2")}, + }, + } + err = accumulator.SaveLogs(providedHash, providedTx, providedNewLogs) + require.NoError(t, err) + + expectedLogs := append(providedLogs, providedNewLogs...) + receivedTx, receivedLogs, ok := accumulator.GetLogs(providedHash) + require.True(t, ok) + require.Equal(t, providedTx, receivedTx) + require.Equal(t, expectedLogs, receivedLogs) + }) +} + +func TestFailedTxLogsAccumulator_Remove(t *testing.T) { + t.Parallel() + + accumulator := NewFailedTxLogsAccumulator() + err := accumulator.SaveLogs(providedHash, providedTx, providedLogs) + require.NoError(t, err) + _, _, ok := accumulator.GetLogs(providedHash) + require.True(t, ok) + + accumulator.Remove([]byte("")) // coverage only + + accumulator.Remove(providedHash) + _, _, ok = accumulator.GetLogs(providedHash) + require.False(t, ok) +} + +func TestTxLogProcessor_ConcurrentOperations(t *testing.T) { + t.Parallel() + + require.NotPanics(t, func() { + accumulator := NewFailedTxLogsAccumulator() + + numCalls := 1000 + wg := sync.WaitGroup{} + wg.Add(numCalls) + + for i := 0; i < numCalls; i++ { + go func(idx int) { + switch idx % 3 { + case 0: + err := accumulator.SaveLogs(providedHash, providedTx, []*vmcommon.LogEntry{ + { + Identifier: []byte(fmt.Sprintf("identifier %d", idx)), + Address: []byte("addr"), + Topics: [][]byte{[]byte(fmt.Sprintf("topic %d", idx))}, + Data: [][]byte{[]byte(fmt.Sprintf("data %d", idx))}, + }, + }) + require.NoError(t, err) + case 1: + _, _, _ = accumulator.GetLogs(providedHash) + case 2: + accumulator.Remove(providedHash) + } + + wg.Done() + }(i) + } + + wg.Wait() + }) +} diff --git a/process/transactionLog/printTxLogProcessor.go b/process/transactionLog/printTxLogProcessor.go index 8f21674ee60..6a512219d6a 100644 --- a/process/transactionLog/printTxLogProcessor.go +++ b/process/transactionLog/printTxLogProcessor.go @@ -55,11 +55,6 @@ func (tlp *printTxLogProcessor) SaveLog(txHash []byte, _ data.TransactionHandler return nil } -// AppendLog - -func (tlp *printTxLogProcessor) AppendLog(txHash []byte, tx data.TransactionHandler, logEntries []*vmcommon.LogEntry) error { - return tlp.SaveLog(txHash, tx, logEntries) -} - func prepareTopics(topics [][]byte) string { all := "" for _, topic := range topics { diff --git a/process/transactionLog/printTxLogProcessor_test.go b/process/transactionLog/printTxLogProcessor_test.go index 703cdfabe86..c442440afb9 100644 --- a/process/transactionLog/printTxLogProcessor_test.go +++ b/process/transactionLog/printTxLogProcessor_test.go @@ -65,9 +65,6 @@ func TestPrintTxLogProcessor_SaveLog(t *testing.T) { err := ptlp.SaveLog([]byte("hash"), &transaction.Transaction{}, txLogEntry) require.Nil(t, err) - err = ptlp.AppendLog([]byte("hash"), &transaction.Transaction{}, nil) - require.Nil(t, err) - require.True(t, strings.Contains(buff.String(), "printTxLogProcessor.SaveLog")) require.True(t, strings.Contains(buff.String(), "printTxLogProcessor.entry")) } diff --git a/process/transactionLog/process.go b/process/transactionLog/process.go index e0c2a8e072e..786990034da 100644 --- a/process/transactionLog/process.go +++ b/process/transactionLog/process.go @@ -130,15 +130,6 @@ func (tlp *txLogProcessor) Clean() { // SaveLog takes the VM logs and saves them into the correct format in storage func (tlp *txLogProcessor) SaveLog(txHash []byte, tx data.TransactionHandler, logEntries []*vmcommon.LogEntry) error { - return tlp.saveLog(txHash, tx, logEntries, false) -} - -// AppendLog takes the VM logs and appends them into the correct format in storage -func (tlp *txLogProcessor) AppendLog(txHash []byte, tx data.TransactionHandler, logEntries []*vmcommon.LogEntry) error { - return tlp.saveLog(txHash, tx, logEntries, true) -} - -func (tlp *txLogProcessor) saveLog(txHash []byte, tx data.TransactionHandler, logEntries []*vmcommon.LogEntry, appendLog bool) error { if len(txHash) == 0 { return process.ErrNilTxHash } @@ -180,41 +171,7 @@ func (tlp *txLogProcessor) saveLog(txHash []byte, tx data.TransactionHandler, lo return err } - if !appendLog { - return tlp.storer.Put(txHash, buff) - } - - return tlp.appendLogToStorer(txHash, txLog) -} - -func (tlp *txLogProcessor) appendLogToStorer(txHash []byte, newLog *transaction.Log) error { - oldLogsBuff, errGet := tlp.storer.Get(txHash) - if errGet != nil || len(oldLogsBuff) == 0 { - allLogsBuff, err := tlp.marshalizer.Marshal(newLog) - if err != nil { - return err - } - - return tlp.storer.Put(txHash, allLogsBuff) - } - - oldLogs := &transaction.Log{} - err := tlp.marshalizer.Unmarshal(oldLogs, oldLogsBuff) - if err != nil { - return err - } - - if oldLogs.Address == nil { - oldLogs.Address = newLog.Address - } - oldLogs.Events = append(oldLogs.Events, newLog.Events...) - - allLogsBuff, err := tlp.marshalizer.Marshal(oldLogs) - if err != nil { - return err - } - - return tlp.storer.Put(txHash, allLogsBuff) + return tlp.storer.Put(txHash, buff) } func (tlp *txLogProcessor) saveLogToCache(txHash []byte, log *transaction.Log) { diff --git a/process/transactionLog/process_test.go b/process/transactionLog/process_test.go index decde14253d..c4f58322056 100644 --- a/process/transactionLog/process_test.go +++ b/process/transactionLog/process_test.go @@ -9,14 +9,11 @@ import ( "github.com/multiversx/mx-chain-go/process/mock" "github.com/multiversx/mx-chain-go/process/transactionLog" "github.com/multiversx/mx-chain-go/testscommon" - "github.com/multiversx/mx-chain-go/testscommon/genericMocks" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/stretchr/testify/require" ) -var expectedErr = errors.New("expected err") - func TestNewTxLogProcessor_NilParameters(t *testing.T) { _, nilMarshalizer := transactionLog.NewTxLogProcessor(transactionLog.ArgTxLogProcessor{ Storer: &storageStubs.StorerStub{}, @@ -130,93 +127,6 @@ func TestTxLogProcessor_SaveLogsStoreErr(t *testing.T) { require.Equal(t, retErr, err) } -func TestTxLogProcessor_AppendLogGetErrSaveLog(t *testing.T) { - t.Parallel() - - wasSaved := false - txLogProcessor, _ := transactionLog.NewTxLogProcessor(transactionLog.ArgTxLogProcessor{ - Storer: &storageStubs.StorerStub{ - GetCalled: func(key []byte) ([]byte, error) { - return nil, expectedErr - }, - PutCalled: func(key, data []byte) error { - wasSaved = true - return nil - }, - }, - Marshalizer: &mock.MarshalizerMock{}, - SaveInStorageEnabled: true, - }) - - logs := []*vmcommon.LogEntry{ - {Address: []byte("first log")}, - } - err := txLogProcessor.AppendLog([]byte("txhash"), &transaction.Transaction{}, logs) - require.NoError(t, err) - require.True(t, wasSaved) -} - -func TestTxLogProcessor_AppendLogsUnmarshalErrShouldError(t *testing.T) { - t.Parallel() - - txLogProcessor, _ := transactionLog.NewTxLogProcessor(transactionLog.ArgTxLogProcessor{ - Storer: &storageStubs.StorerStub{ - GetCalled: func(key []byte) ([]byte, error) { - return []byte("dummy buff"), nil - }, - }, - Marshalizer: &testscommon.MarshallerStub{ - UnmarshalCalled: func(obj interface{}, buff []byte) error { - return expectedErr - }, - }, - SaveInStorageEnabled: true, - }) - - logs := []*vmcommon.LogEntry{ - {Address: []byte("first log")}, - } - err := txLogProcessor.AppendLog([]byte("txhash"), &transaction.Transaction{}, logs) - require.Equal(t, expectedErr, err) -} - -func TestTxLogProcessor_AppendLogShouldWorkAndAppend(t *testing.T) { - t.Parallel() - - providedHash := []byte("txhash") - storer := genericMocks.NewStorerMockWithErrKeyNotFound(0) - marshaller := &mock.MarshalizerMock{} - txLogProcessor, _ := transactionLog.NewTxLogProcessor(transactionLog.ArgTxLogProcessor{ - Storer: storer, - Marshalizer: marshaller, - SaveInStorageEnabled: true, - }) - - oldLogs := []*vmcommon.LogEntry{ - {Address: []byte("addr 1"), Data: [][]byte{[]byte("old data 1")}}, - {Address: []byte("addr 2"), Data: [][]byte{[]byte("old data 2")}}, - } - - err := txLogProcessor.SaveLog(providedHash, &transaction.Transaction{}, oldLogs) - require.NoError(t, err) - - newLogs := []*vmcommon.LogEntry{ - {Address: []byte("addr 3"), Data: [][]byte{[]byte("new data 1")}}, - } - - err = txLogProcessor.AppendLog(providedHash, &transaction.Transaction{SndAddr: []byte("sender")}, newLogs) - require.NoError(t, err) - - buff, err := storer.Get(providedHash) - require.NoError(t, err) - - allLogs := &transaction.Log{} - err = marshaller.Unmarshal(allLogs, buff) - require.NoError(t, err) - - require.Equal(t, 3, len(allLogs.Events)) -} - func TestTxLogProcessor_SaveLogsCallsPutWithMarshalBuff(t *testing.T) { buffExpected := []byte("marshaled log") buffActual := []byte("currently wrong value") diff --git a/testscommon/processMocks/failedTxLogsAccumulatorMock.go b/testscommon/processMocks/failedTxLogsAccumulatorMock.go new file mode 100644 index 00000000000..903e56cd79f --- /dev/null +++ b/testscommon/processMocks/failedTxLogsAccumulatorMock.go @@ -0,0 +1,41 @@ +package processMocks + +import ( + "github.com/multiversx/mx-chain-core-go/data" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" +) + +// FailedTxLogsAccumulatorMock - +type FailedTxLogsAccumulatorMock struct { + GetLogsCalled func(txHash []byte) (data.TransactionHandler, []*vmcommon.LogEntry, bool) + SaveLogsCalled func(txHash []byte, tx data.TransactionHandler, logs []*vmcommon.LogEntry) error + RemoveCalled func(txHash []byte) +} + +// GetLogs - +func (mock *FailedTxLogsAccumulatorMock) GetLogs(txHash []byte) (data.TransactionHandler, []*vmcommon.LogEntry, bool) { + if mock.GetLogsCalled != nil { + return mock.GetLogsCalled(txHash) + } + return nil, nil, false +} + +// SaveLogs - +func (mock *FailedTxLogsAccumulatorMock) SaveLogs(txHash []byte, tx data.TransactionHandler, logs []*vmcommon.LogEntry) error { + if mock.SaveLogsCalled != nil { + return mock.SaveLogsCalled(txHash, tx, logs) + } + return nil +} + +// Remove - +func (mock *FailedTxLogsAccumulatorMock) Remove(txHash []byte) { + if mock.RemoveCalled != nil { + mock.RemoveCalled(txHash) + } +} + +// IsInterfaceNil - +func (mock *FailedTxLogsAccumulatorMock) IsInterfaceNil() bool { + return mock == nil +} From b52afea036b6898f90ca51540880861ae8e7d5bb Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 14 Jun 2024 15:56:17 +0300 Subject: [PATCH 335/503] reverted change not needed --- process/transactionLog/process.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/process/transactionLog/process.go b/process/transactionLog/process.go index 786990034da..39b74f4b02a 100644 --- a/process/transactionLog/process.go +++ b/process/transactionLog/process.go @@ -161,9 +161,6 @@ func (tlp *txLogProcessor) SaveLog(txHash []byte, tx data.TransactionHandler, lo }) } - tlp.mut.Lock() - defer tlp.mut.Unlock() - tlp.saveLogToCache(txHash, txLog) buff, err := tlp.marshalizer.Marshal(txLog) @@ -175,11 +172,13 @@ func (tlp *txLogProcessor) SaveLog(txHash []byte, tx data.TransactionHandler, lo } func (tlp *txLogProcessor) saveLogToCache(txHash []byte, log *transaction.Log) { + tlp.mut.Lock() tlp.logs = append(tlp.logs, &data.LogData{ TxHash: string(txHash), LogHandler: log, }) tlp.logsIndices[string(txHash)] = len(tlp.logs) - 1 + tlp.mut.Unlock() } // For SC deployment transactions, we use the sender address From a40f03cd774056680a3cffc7084da26aa5c1d301 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 17 Jun 2024 14:02:13 +0300 Subject: [PATCH 336/503] fix after review --- process/transaction/shardProcess.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index f3901ae7939..0a82b720c65 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -237,7 +237,7 @@ func (txProc *txProcessor) ProcessTransaction(tx *transaction.Transaction) (vmco switch txType { case process.MoveBalance: - err = txProc.processMoveBalance(tx, acntSnd, acntDst, dstShardTxType, nil, false, false) + err = txProc.processMoveBalance(tx, acntSnd, acntDst, dstShardTxType, nil, false) if err != nil { return vmcommon.UserError, txProc.executeAfterFailedMoveBalanceTransaction(tx, err) } @@ -473,7 +473,6 @@ func (txProc *txProcessor) processMoveBalance( destShardTxType process.TransactionType, originalTxHash []byte, isUserTxOfRelayed bool, - isUserTxOfRelayedV3 bool, ) error { moveBalanceCost, totalCost, err := txProc.processTxFee(tx, acntSrc, acntDst, destShardTxType, isUserTxOfRelayed) @@ -537,7 +536,7 @@ func (txProc *txProcessor) processMoveBalance( txProc.txFeeHandler.ProcessTransactionFee(moveBalanceCost, big.NewInt(0), txHash) } - if isUserTxOfRelayedV3 { + if len(tx.RelayerAddr) > 0 { return txProc.createRefundSCRForMoveBalance(tx, txHash, originalTxHash, moveBalanceCost) } @@ -1010,8 +1009,7 @@ func (txProc *txProcessor) processUserTx( returnCode := vmcommon.Ok switch txType { case process.MoveBalance: - isUserTxOfRelayedV3 := len(originalTx.InnerTransactions) > 0 - err = txProc.processMoveBalance(userTx, acntSnd, acntDst, dstShardTxType, originalTxHash, true, isUserTxOfRelayedV3) + err = txProc.processMoveBalance(userTx, acntSnd, acntDst, dstShardTxType, originalTxHash, true) intraShard := txProc.shardCoordinator.SameShard(userTx.SndAddr, userTx.RcvAddr) if err == nil && intraShard { txProc.createCompleteEventLog(scrFromTx, originalTxHash) From 18ea18dd70a58d26902806c4c5792ccd3e603fa8 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Mon, 17 Jun 2024 16:57:10 +0300 Subject: [PATCH 337/503] added register dynamic integration test --- .../vm/esdtImprovements_test.go | 126 ++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 608c24ee3b0..5f49890528a 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -3,6 +3,7 @@ package vm import ( "bytes" "encoding/hex" + "fmt" "math/big" "testing" "time" @@ -1932,3 +1933,128 @@ func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData2) } + +// Test scenario #11 +// +func TestChainSimulator_RegisterDynamic(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(2) + + baseIssuingCost := "1000" + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + addrs := createAddresses(t, cs, true) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + log.Info("Register dynamic nft token") + + nftTicker := []byte("NFTTICKER") + nftTokenName := []byte("tokenName") + + // decimals := big.NewInt(20) + + txDataField := bytes.Join( + [][]byte{ + []byte("registerDynamic"), + []byte(hex.EncodeToString(nftTokenName)), + []byte(hex.EncodeToString(nftTicker)), + []byte(hex.EncodeToString([]byte("NFT"))), + // []byte(hex.EncodeToString(decimals.Bytes())), + // []byte("canBurn"), []byte("true"), + // []byte("canMint"), []byte("true"), + // []byte("canPause"), []byte("true"), + }, + []byte("@"), + ) + + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + + tx := &transaction.Transaction{ + Nonce: 0, + SndAddr: addrs[0].Bytes, + RcvAddr: vm.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: callValue, + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult) + fmt.Println(txResult.Logs.Events[0]) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) + + nftTokenID := txResult.Logs.Events[0].Topics[0] + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + } + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult) + fmt.Println(txResult.Logs.Events[0]) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) +} From bc4db4459a1ae93d9f82794ff35680c704808e25 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Mon, 17 Jun 2024 17:09:31 +0300 Subject: [PATCH 338/503] added register and set all roles dynamic integration test --- .../vm/esdtImprovements_test.go | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 5f49890528a..652205f17c7 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -2058,3 +2058,128 @@ func TestChainSimulator_RegisterDynamic(t *testing.T) { checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) } + +// Test scenario #12 +// +func TestChainSimulator_RegisterAndSetAllRolesDynamic(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(2) + + baseIssuingCost := "1000" + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + addrs := createAddresses(t, cs, true) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + log.Info("Register dynamic nft token") + + nftTicker := []byte("NFTTICKER") + nftTokenName := []byte("tokenName") + + // decimals := big.NewInt(20) + + txDataField := bytes.Join( + [][]byte{ + []byte("registerAndSetAllRolesDynamic"), + []byte(hex.EncodeToString(nftTokenName)), + []byte(hex.EncodeToString(nftTicker)), + []byte(hex.EncodeToString([]byte("NFT"))), + // []byte(hex.EncodeToString(decimals.Bytes())), + // []byte("canBurn"), []byte("true"), + // []byte("canMint"), []byte("true"), + // []byte("canPause"), []byte("true"), + }, + []byte("@"), + ) + + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + + tx := &transaction.Transaction{ + Nonce: 0, + SndAddr: addrs[0].Bytes, + RcvAddr: vm.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: callValue, + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult) + fmt.Println(txResult.Logs.Events[0]) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) + + nftTokenID := txResult.Logs.Events[0].Topics[0] + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + } + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult) + fmt.Println(txResult.Logs.Events[0]) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) +} From f66551186a9c68c5d74a360ce83f23094cb41be4 Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 18 Jun 2024 10:35:02 +0300 Subject: [PATCH 339/503] new vm common --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 0ab23b4b255..cefd79fee44 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f - github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240614104805-22410d9e134e + github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240618072615-e9c0c43e9fa1 github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240509104009-598a37ff36b9 diff --git a/go.sum b/go.sum index c39775da27d..4d6d77a3451 100644 --- a/go.sum +++ b/go.sum @@ -399,8 +399,8 @@ 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.20240614104805-22410d9e134e h1:uUNnziPQUXs7UDtwM0+32XEpkW8siBO3YNyflbAAHj8= -github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240614104805-22410d9e134e/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo= +github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240618072615-e9c0c43e9fa1 h1:NDouJwS8vAPLsNLZiOO5x9vXZeUKxYpIxN3H6Qvotv8= +github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240618072615-e9c0c43e9fa1/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= From 06565e34e2d9b8e97a520bb7e2f1ef0967df8ccd Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 18 Jun 2024 11:06:48 +0300 Subject: [PATCH 340/503] add token type check --- .../chainSimulator/vm/esdtImprovements_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 652205f17c7..9458bbd5efd 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -19,6 +19,7 @@ import ( "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" + "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/vm" logger "github.com/multiversx/mx-chain-logger-go" @@ -2057,6 +2058,20 @@ func TestChainSimulator_RegisterDynamic(t *testing.T) { shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + + scQuery := &process.SCQuery{ + ScAddress: vm.ESDTSCAddress, + FuncName: "getTokenProperties", + CallValue: big.NewInt(0), + Arguments: [][]byte{nftTokenID}, + } + result, _, err := cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ExecuteSCQuery(scQuery) + require.Nil(t, err) + require.Equal(t, "", result.ReturnMessage) + require.Equal(t, testsChainSimulator.OkReturnCode, result.ReturnCode) + + tokenType := result.ReturnData[1] + require.Equal(t, core.Dynamic+core.NonFungibleESDTv2, string(tokenType)) } // Test scenario #12 From 7199aa29fc10865d14137a6495ab7cd04cc212a1 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 18 Jun 2024 12:12:18 +0300 Subject: [PATCH 341/503] added register dynamic scenario for meta esdt token --- .../vm/esdtImprovements_test.go | 160 ++++++++++++++++-- 1 file changed, 147 insertions(+), 13 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 9458bbd5efd..0b053ce19e2 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -1937,7 +1937,7 @@ func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { // Test scenario #11 // -func TestChainSimulator_RegisterDynamic(t *testing.T) { +func TestChainSimulator_NFT_RegisterDynamic(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } @@ -1987,18 +1987,12 @@ func TestChainSimulator_RegisterDynamic(t *testing.T) { nftTicker := []byte("NFTTICKER") nftTokenName := []byte("tokenName") - // decimals := big.NewInt(20) - txDataField := bytes.Join( [][]byte{ []byte("registerDynamic"), []byte(hex.EncodeToString(nftTokenName)), []byte(hex.EncodeToString(nftTicker)), []byte(hex.EncodeToString([]byte("NFT"))), - // []byte(hex.EncodeToString(decimals.Bytes())), - // []byte("canBurn"), []byte("true"), - // []byte("canMint"), []byte("true"), - // []byte("canPause"), []byte("true"), }, []byte("@"), ) @@ -2059,6 +2053,8 @@ func TestChainSimulator_RegisterDynamic(t *testing.T) { checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + log.Info("Check that token type is Dynamic") + scQuery := &process.SCQuery{ ScAddress: vm.ESDTSCAddress, FuncName: "getTokenProperties", @@ -2074,6 +2070,134 @@ func TestChainSimulator_RegisterDynamic(t *testing.T) { require.Equal(t, core.Dynamic+core.NonFungibleESDTv2, string(tokenType)) } +// Test scenario #11b +// +func TestChainSimulator_MetaESDT_RegisterDynamic(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(2) + + baseIssuingCost := "1000" + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + addrs := createAddresses(t, cs, true) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + log.Info("Register dynamic metaESDT token") + + metaTicker := []byte("METATICKER") + metaTokenName := []byte("tokenName") + + decimals := big.NewInt(15) + + txDataField := bytes.Join( + [][]byte{ + []byte("registerDynamic"), + []byte(hex.EncodeToString(metaTokenName)), + []byte(hex.EncodeToString(metaTicker)), + []byte(hex.EncodeToString([]byte("META"))), + []byte(hex.EncodeToString(decimals.Bytes())), + }, + []byte("@"), + ) + + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + + tx := &transaction.Transaction{ + Nonce: 0, + SndAddr: addrs[0].Bytes, + RcvAddr: vm.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: callValue, + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + nftTokenID := txResult.Logs.Events[0].Topics[0] + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + } + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + + log.Info("Check that token type is Dynamic") + + scQuery := &process.SCQuery{ + ScAddress: vm.ESDTSCAddress, + FuncName: "getTokenProperties", + CallValue: big.NewInt(0), + Arguments: [][]byte{nftTokenID}, + } + result, _, err := cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ExecuteSCQuery(scQuery) + require.Nil(t, err) + require.Equal(t, "", result.ReturnMessage) + require.Equal(t, testsChainSimulator.OkReturnCode, result.ReturnCode) + + tokenType := result.ReturnData[1] + require.Equal(t, core.Dynamic+core.MetaESDT, string(tokenType)) +} + // Test scenario #12 // func TestChainSimulator_RegisterAndSetAllRolesDynamic(t *testing.T) { @@ -2126,18 +2250,12 @@ func TestChainSimulator_RegisterAndSetAllRolesDynamic(t *testing.T) { nftTicker := []byte("NFTTICKER") nftTokenName := []byte("tokenName") - // decimals := big.NewInt(20) - txDataField := bytes.Join( [][]byte{ []byte("registerAndSetAllRolesDynamic"), []byte(hex.EncodeToString(nftTokenName)), []byte(hex.EncodeToString(nftTicker)), []byte(hex.EncodeToString([]byte("NFT"))), - // []byte(hex.EncodeToString(decimals.Bytes())), - // []byte("canBurn"), []byte("true"), - // []byte("canMint"), []byte("true"), - // []byte("canPause"), []byte("true"), }, []byte("@"), ) @@ -2197,4 +2315,20 @@ func TestChainSimulator_RegisterAndSetAllRolesDynamic(t *testing.T) { shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + + log.Info("Check that token type is Dynamic") + + scQuery := &process.SCQuery{ + ScAddress: vm.ESDTSCAddress, + FuncName: "getTokenProperties", + CallValue: big.NewInt(0), + Arguments: [][]byte{nftTokenID}, + } + result, _, err := cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ExecuteSCQuery(scQuery) + require.Nil(t, err) + require.Equal(t, "", result.ReturnMessage) + require.Equal(t, testsChainSimulator.OkReturnCode, result.ReturnCode) + + tokenType := result.ReturnData[1] + require.Equal(t, core.Dynamic+core.MetaESDT, string(tokenType)) } From 85ebe4b726bedc7486b9aa952eba0abbf1e8f98a Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 18 Jun 2024 12:40:51 +0300 Subject: [PATCH 342/503] added roles check --- .../vm/esdtImprovements_test.go | 212 ++++++++++++++++-- 1 file changed, 191 insertions(+), 21 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 0b053ce19e2..1f095434500 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -3,7 +3,6 @@ package vm import ( "bytes" "encoding/hex" - "fmt" "math/big" "testing" "time" @@ -2016,11 +2015,6 @@ func TestChainSimulator_NFT_RegisterDynamic(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(txResult.Logs.Events[0]) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] @@ -2039,11 +2033,6 @@ func TestChainSimulator_NFT_RegisterDynamic(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(txResult.Logs.Events[0]) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) err = cs.GenerateBlocks(10) @@ -2279,11 +2268,6 @@ func TestChainSimulator_RegisterAndSetAllRolesDynamic(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(txResult.Logs.Events[0]) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] @@ -2302,11 +2286,6 @@ func TestChainSimulator_RegisterAndSetAllRolesDynamic(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(txResult.Logs.Events[0]) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) err = cs.GenerateBlocks(10) @@ -2331,4 +2310,195 @@ func TestChainSimulator_RegisterAndSetAllRolesDynamic(t *testing.T) { tokenType := result.ReturnData[1] require.Equal(t, core.Dynamic+core.MetaESDT, string(tokenType)) + + log.Info("Check token roles") + + scQuery = &process.SCQuery{ + ScAddress: vm.ESDTSCAddress, + FuncName: "getAllAddressesAndRoles", + CallValue: big.NewInt(0), + Arguments: [][]byte{nftTokenID}, + } + result, _, err = cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ExecuteSCQuery(scQuery) + require.Nil(t, err) + require.Equal(t, "", result.ReturnMessage) + require.Equal(t, testsChainSimulator.OkReturnCode, result.ReturnCode) + + expectedRoles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleNFTBurn), + []byte(core.ESDTRoleNFTUpdateAttributes), + []byte(core.ESDTRoleNFTAddURI), + []byte(core.ESDTRoleNFTRecreate), + []byte(core.ESDTRoleModifyCreator), + []byte(core.ESDTRoleModifyRoyalties), + []byte(core.ESDTRoleSetNewURI), + } + + checkTokenRoles(t, result.ReturnData, expectedRoles) +} + +// Test scenario #12b +// +func TestChainSimulator_MetaESDT_RegisterAndSetAllRolesDynamic(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(2) + + baseIssuingCost := "1000" + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + addrs := createAddresses(t, cs, true) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + log.Info("Register dynamic meta esdt token") + + metaTicker := []byte("METATICKER") + metaTokenName := []byte("tokenName") + + decimals := big.NewInt(10) + + txDataField := bytes.Join( + [][]byte{ + []byte("registerAndSetAllRolesDynamic"), + []byte(hex.EncodeToString(metaTokenName)), + []byte(hex.EncodeToString(metaTicker)), + []byte(hex.EncodeToString([]byte("META"))), + []byte(hex.EncodeToString(decimals.Bytes())), + }, + []byte("@"), + ) + + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + + tx := &transaction.Transaction{ + Nonce: 0, + SndAddr: addrs[0].Bytes, + RcvAddr: vm.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: callValue, + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + metaTokenID := txResult.Logs.Events[0].Topics[0] + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + } + setAddressEsdtRoles(t, cs, addrs[0], metaTokenID, roles) + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = nftCreateTx(1, addrs[0].Bytes, metaTokenID, nftMetaData) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + + checkMetaData(t, cs, core.SystemAccountAddress, metaTokenID, shardID, nftMetaData) + + log.Info("Check that token type is Dynamic") + + scQuery := &process.SCQuery{ + ScAddress: vm.ESDTSCAddress, + FuncName: "getTokenProperties", + CallValue: big.NewInt(0), + Arguments: [][]byte{metaTokenID}, + } + result, _, err := cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ExecuteSCQuery(scQuery) + require.Nil(t, err) + require.Equal(t, "", result.ReturnMessage) + require.Equal(t, testsChainSimulator.OkReturnCode, result.ReturnCode) + + tokenType := result.ReturnData[1] + require.Equal(t, core.Dynamic+core.MetaESDT, string(tokenType)) + + log.Info("Check token roles") + + scQuery = &process.SCQuery{ + ScAddress: vm.ESDTSCAddress, + FuncName: "getAllAddressesAndRoles", + CallValue: big.NewInt(0), + Arguments: [][]byte{metaTokenID}, + } + result, _, err = cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ExecuteSCQuery(scQuery) + require.Nil(t, err) + require.Equal(t, "", result.ReturnMessage) + require.Equal(t, testsChainSimulator.OkReturnCode, result.ReturnCode) + + expectedRoles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleNFTBurn), + []byte(core.ESDTRoleNFTAddQuantity), + []byte(core.ESDTRoleNFTUpdateAttributes), + []byte(core.ESDTRoleNFTAddURI), + } + + checkTokenRoles(t, result.ReturnData, expectedRoles) +} + +func checkTokenRoles(t *testing.T, returnData [][]byte, expectedRoles [][]byte) { + for _, expRole := range expectedRoles { + found := false + + for _, item := range returnData { + if bytes.Equal(expRole, item) { + found = true + } + } + + require.True(t, found) + } } From 01541f27f6cc876b794ef2b5c9b5e83bb3f1a302 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Tue, 18 Jun 2024 14:22:19 +0300 Subject: [PATCH 343/503] add more testing scenarios --- .../vm/esdtImprovements_test.go | 235 ++++++++++++++++++ 1 file changed, 235 insertions(+) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 608c24ee3b0..f55ea07e4bc 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -1932,3 +1932,238 @@ func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData2) } + +func TestChainSimulator_NFTcreatedBeforeSaveToSystemAccountEnabled(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + baseIssuingCost := "1000" + cs, epochForDynamicNFT := getTestChainSimulatorWithSaveToSystemAccountDisabled(t, baseIssuingCost) + defer cs.Close() + + addrs := createAddresses(t, cs, false) + + log.Info("Initial setup: Create NFT that will have it's metadata saved to the user account") + + nftTicker := []byte("NFTTICKER") + tx := issueNonFungibleTx(0, addrs[0].Bytes, nftTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + nftTokenID := txResult.Logs.Events[0].Topics[0] + + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + createTokenUpdateTokenIDAndTransfer(t, cs, addrs[0].Bytes, addrs[1].Bytes, nftTokenID, nftMetaData, epochForDynamicNFT, addrs[0]) + + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + checkMetaData(t, cs, addrs[1].Bytes, nftTokenID, shardID, nftMetaData) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, nftTokenID, shardID) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) +} + +func TestChainSimulator_SFTcreatedBeforeSaveToSystemAccountEnabled(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + baseIssuingCost := "1000" + cs, epochForDynamicNFT := getTestChainSimulatorWithSaveToSystemAccountDisabled(t, baseIssuingCost) + defer cs.Close() + + addrs := createAddresses(t, cs, false) + + log.Info("Initial setup: Create SFT that will have it's metadata saved to the user account") + + sftTicker := []byte("SFTTICKER") + tx := issueSemiFungibleTx(0, addrs[0].Bytes, sftTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + sftTokenID := txResult.Logs.Events[0].Topics[0] + + log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + createTokenUpdateTokenIDAndTransfer(t, cs, addrs[0].Bytes, addrs[1].Bytes, sftTokenID, nftMetaData, epochForDynamicNFT, addrs[0]) + + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, nftMetaData) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, sftTokenID, shardID) + checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, sftTokenID, shardID) +} + +func TestChainSimulator_FungibleCreatedBeforeSaveToSystemAccountEnabled(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + baseIssuingCost := "1000" + cs, epochForDynamicNFT := getTestChainSimulatorWithSaveToSystemAccountDisabled(t, baseIssuingCost) + defer cs.Close() + + addrs := createAddresses(t, cs, false) + + log.Info("Initial setup: Create FungibleESDT that will have it's metadata saved to the user account") + + funTicker := []byte("FUNTICKER") + tx := issueTx(0, addrs[0].Bytes, funTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + funTokenID := txResult.Logs.Events[0].Topics[0] + + log.Info("Issued FungibleESDT token id", "tokenID", string(funTokenID)) + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + createTokenUpdateTokenIDAndTransfer(t, cs, addrs[0].Bytes, addrs[1].Bytes, funTokenID, nftMetaData, epochForDynamicNFT, addrs[0]) + + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + + checkMetaData(t, cs, core.SystemAccountAddress, funTokenID, shardID, nftMetaData) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, funTokenID, shardID) + checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, funTokenID, shardID) +} + +func TestChainSimulator_MetaESDTCreatedBeforeSaveToSystemAccountEnabled(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + baseIssuingCost := "1000" + cs, epochForDynamicNFT := getTestChainSimulatorWithSaveToSystemAccountDisabled(t, baseIssuingCost) + defer cs.Close() + + addrs := createAddresses(t, cs, false) + + log.Info("Initial setup: Create MetaESDT that will have it's metadata saved to the user account") + + metaTicker := []byte("METATICKER") + tx := issueMetaESDTTx(0, addrs[0].Bytes, metaTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + metaTokenID := txResult.Logs.Events[0].Topics[0] + + log.Info("Issued MetaESDT token id", "tokenID", string(metaTokenID)) + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + createTokenUpdateTokenIDAndTransfer(t, cs, addrs[0].Bytes, addrs[1].Bytes, metaTokenID, nftMetaData, epochForDynamicNFT, addrs[0]) + + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + checkMetaData(t, cs, core.SystemAccountAddress, metaTokenID, shardID, nftMetaData) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, metaTokenID, shardID) + checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, metaTokenID, shardID) +} + +func getTestChainSimulatorWithSaveToSystemAccountDisabled(t *testing.T, baseIssuingCost string) (testsChainSimulator.ChainSimulator, int32) { + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpochForSaveToSystemAccount := uint32(2) + activationEpochForDynamicNFT := uint32(4) + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.OptimizeNFTStoreEnableEpoch = activationEpochForSaveToSystemAccount + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpochForDynamicNFT + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpochForSaveToSystemAccount) - 1) + require.Nil(t, err) + + return cs, int32(activationEpochForDynamicNFT) +} + +func createTokenUpdateTokenIDAndTransfer( + t *testing.T, + cs testsChainSimulator.ChainSimulator, + originAddress []byte, + targetAddress []byte, + tokenID []byte, + metaData *txsFee.MetaData, + epochForDynamicNFT int32, + walletWithRoles dtos.WalletAddress, +) { + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + } + setAddressEsdtRoles(t, cs, walletWithRoles, tokenID, roles) + + tx := nftCreateTx(1, originAddress, tokenID, metaData) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + log.Info("check that the metadata is saved on the user account") + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(originAddress) + checkMetaData(t, cs, originAddress, tokenID, shardID, metaData) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) + + err = cs.GenerateBlocksUntilEpochIsReached(epochForDynamicNFT) + require.Nil(t, err) + + tx = updateTokenIDTx(2, originAddress, tokenID) + + log.Info("updating token id", "tokenID", tokenID) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + log.Info("transferring token id", "tokenID", tokenID) + + tx = esdtNFTTransferTx(3, originAddress, targetAddress, tokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) +} From 68bbfbc247e5defd3e316cdd7bdea4b22a45a7a6 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 18 Jun 2024 14:29:02 +0300 Subject: [PATCH 344/503] fix dynamic token type for non fungible v2 token --- .../chainSimulator/vm/esdtImprovements_test.go | 4 ++-- vm/systemSmartContracts/esdt.go | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 1f095434500..9c1bfff7b39 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -2189,7 +2189,7 @@ func TestChainSimulator_MetaESDT_RegisterDynamic(t *testing.T) { // Test scenario #12 // -func TestChainSimulator_RegisterAndSetAllRolesDynamic(t *testing.T) { +func TestChainSimulator_NFT_RegisterAndSetAllRolesDynamic(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } @@ -2309,7 +2309,7 @@ func TestChainSimulator_RegisterAndSetAllRolesDynamic(t *testing.T) { require.Equal(t, testsChainSimulator.OkReturnCode, result.ReturnCode) tokenType := result.ReturnData[1] - require.Equal(t, core.Dynamic+core.MetaESDT, string(tokenType)) + require.Equal(t, core.DynamicNFTESDT, string(tokenType)) log.Info("Check token roles") diff --git a/vm/systemSmartContracts/esdt.go b/vm/systemSmartContracts/esdt.go index e8371e1eb79..05ff4638cd1 100644 --- a/vm/systemSmartContracts/esdt.go +++ b/vm/systemSmartContracts/esdt.go @@ -2257,7 +2257,7 @@ func (e *esdt) createDynamicToken(args *vmcommon.ContractCallInput) ([]byte, *ES } } - dynamicTokenType := append([]byte(core.Dynamic), tokenType...) + dynamicTokenType := getDynamicTokenType(tokenType) tokenIdentifier, token, err := e.createNewToken( args.CallerAddr, @@ -2283,6 +2283,15 @@ func (e *esdt) createDynamicToken(args *vmcommon.ContractCallInput) ([]byte, *ES return tokenIdentifier, token, vmcommon.Ok } +func getDynamicTokenType(tokenType []byte) []byte { + if bytes.Equal(tokenType, []byte(core.NonFungibleESDTv2)) || + bytes.Equal(tokenType, []byte(core.NonFungibleESDT)) { + return []byte(core.DynamicNFTESDT) + } + + return append([]byte(core.Dynamic), tokenType...) +} + func (e *esdt) registerDynamic(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { _, _, returnCode := e.createDynamicToken(args) return returnCode From e89eabdf1660748b6e705f9de215f653621ff6e1 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 18 Jun 2024 15:13:08 +0300 Subject: [PATCH 345/503] fix after merge --- integrationTests/chainSimulator/relayedTx/relayedTx_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index a12d9e6ca92..950f07f2b6b 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -57,8 +57,6 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing. cfg.EpochConfig.EnableEpochs.RelayedTransactionsV3EnableEpoch = 1 cfg.EpochConfig.EnableEpochs.FixRelayedMoveBalanceEnableEpoch = 1 }, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, }) require.NoError(t, err) require.NotNil(t, cs) From 8d4a515f70ac90703b0008206b67b2ff7e245d93 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 18 Jun 2024 15:58:44 +0300 Subject: [PATCH 346/503] added more tokens for register dynamic scenarios --- .../vm/esdtImprovements_test.go | 341 +++++++++++++++++- 1 file changed, 331 insertions(+), 10 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 9c1bfff7b39..a7a0682ef65 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -3,6 +3,7 @@ package vm import ( "bytes" "encoding/hex" + "fmt" "math/big" "testing" "time" @@ -1934,8 +1935,6 @@ func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData2) } -// Test scenario #11 -// func TestChainSimulator_NFT_RegisterDynamic(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") @@ -2059,8 +2058,6 @@ func TestChainSimulator_NFT_RegisterDynamic(t *testing.T) { require.Equal(t, core.Dynamic+core.NonFungibleESDTv2, string(tokenType)) } -// Test scenario #11b -// func TestChainSimulator_MetaESDT_RegisterDynamic(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") @@ -2187,8 +2184,98 @@ func TestChainSimulator_MetaESDT_RegisterDynamic(t *testing.T) { require.Equal(t, core.Dynamic+core.MetaESDT, string(tokenType)) } -// Test scenario #12 -// +func TestChainSimulator_FNG_RegisterDynamic(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(2) + + baseIssuingCost := "1000" + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + addrs := createAddresses(t, cs, true) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + log.Info("Register dynamic fungible token") + + metaTicker := []byte("FNGTICKER") + metaTokenName := []byte("tokenName") + + decimals := big.NewInt(15) + + txDataField := bytes.Join( + [][]byte{ + []byte("registerDynamic"), + []byte(hex.EncodeToString(metaTokenName)), + []byte(hex.EncodeToString(metaTicker)), + []byte(hex.EncodeToString([]byte("FNG"))), + []byte(hex.EncodeToString(decimals.Bytes())), + }, + []byte("@"), + ) + + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + + tx := &transaction.Transaction{ + Nonce: 0, + SndAddr: addrs[0].Bytes, + RcvAddr: vm.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: callValue, + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult) + fmt.Println(txResult.Logs.Events[0]) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + signalErrorTopic := string(txResult.Logs.Events[0].Topics[1]) + + require.Equal(t, fmt.Sprintf("cannot create %s tokens as dynamic", core.FungibleESDT), signalErrorTopic) +} + func TestChainSimulator_NFT_RegisterAndSetAllRolesDynamic(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") @@ -2338,6 +2425,240 @@ func TestChainSimulator_NFT_RegisterAndSetAllRolesDynamic(t *testing.T) { checkTokenRoles(t, result.ReturnData, expectedRoles) } +func TestChainSimulator_SFT_RegisterAndSetAllRolesDynamic(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(2) + + baseIssuingCost := "1000" + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + addrs := createAddresses(t, cs, true) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + log.Info("Register dynamic sft token") + + sftTicker := []byte("SFTTICKER") + sftTokenName := []byte("tokenName") + + txDataField := bytes.Join( + [][]byte{ + []byte("registerAndSetAllRolesDynamic"), + []byte(hex.EncodeToString(sftTokenName)), + []byte(hex.EncodeToString(sftTicker)), + []byte(hex.EncodeToString([]byte("SFT"))), + }, + []byte("@"), + ) + + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + + tx := &transaction.Transaction{ + Nonce: 0, + SndAddr: addrs[0].Bytes, + RcvAddr: vm.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: callValue, + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + sftTokenID := txResult.Logs.Events[0].Topics[0] + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + } + setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = nftCreateTx(1, addrs[0].Bytes, sftTokenID, nftMetaData) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, nftMetaData) + + log.Info("Check that token type is Dynamic") + + scQuery := &process.SCQuery{ + ScAddress: vm.ESDTSCAddress, + FuncName: "getTokenProperties", + CallValue: big.NewInt(0), + Arguments: [][]byte{sftTokenID}, + } + result, _, err := cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ExecuteSCQuery(scQuery) + require.Nil(t, err) + require.Equal(t, "", result.ReturnMessage) + require.Equal(t, testsChainSimulator.OkReturnCode, result.ReturnCode) + + tokenType := result.ReturnData[1] + require.Equal(t, core.DynamicSFTESDT, string(tokenType)) + + log.Info("Check token roles") + + scQuery = &process.SCQuery{ + ScAddress: vm.ESDTSCAddress, + FuncName: "getAllAddressesAndRoles", + CallValue: big.NewInt(0), + Arguments: [][]byte{sftTokenID}, + } + result, _, err = cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ExecuteSCQuery(scQuery) + require.Nil(t, err) + require.Equal(t, "", result.ReturnMessage) + require.Equal(t, testsChainSimulator.OkReturnCode, result.ReturnCode) + + expectedRoles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleNFTBurn), + []byte(core.ESDTRoleNFTUpdateAttributes), + []byte(core.ESDTRoleNFTAddURI), + []byte(core.ESDTRoleNFTRecreate), + []byte(core.ESDTRoleModifyCreator), + []byte(core.ESDTRoleModifyRoyalties), + []byte(core.ESDTRoleSetNewURI), + } + + checkTokenRoles(t, result.ReturnData, expectedRoles) +} + +func TestChainSimulator_FNG_RegisterAndSetAllRolesDynamic(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(2) + + baseIssuingCost := "1000" + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + addrs := createAddresses(t, cs, true) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + log.Info("Register dynamic fungible token") + + fngTicker := []byte("FNGTICKER") + fngTokenName := []byte("tokenName") + + txDataField := bytes.Join( + [][]byte{ + []byte("registerAndSetAllRolesDynamic"), + []byte(hex.EncodeToString(fngTokenName)), + []byte(hex.EncodeToString(fngTicker)), + []byte(hex.EncodeToString([]byte("FNG"))), + []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + }, + []byte("@"), + ) + + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + + tx := &transaction.Transaction{ + Nonce: 0, + SndAddr: addrs[0].Bytes, + RcvAddr: vm.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: callValue, + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + signalErrorTopic := string(txResult.Logs.Events[0].Topics[1]) + + require.Equal(t, fmt.Sprintf("cannot create %s tokens as dynamic", core.FungibleESDT), signalErrorTopic) +} + // Test scenario #12b // func TestChainSimulator_MetaESDT_RegisterAndSetAllRolesDynamic(t *testing.T) { @@ -2387,16 +2708,16 @@ func TestChainSimulator_MetaESDT_RegisterAndSetAllRolesDynamic(t *testing.T) { log.Info("Register dynamic meta esdt token") - metaTicker := []byte("METATICKER") - metaTokenName := []byte("tokenName") + ticker := []byte("META" + "TICKER") + tokenName := []byte("tokenName") decimals := big.NewInt(10) txDataField := bytes.Join( [][]byte{ []byte("registerAndSetAllRolesDynamic"), - []byte(hex.EncodeToString(metaTokenName)), - []byte(hex.EncodeToString(metaTicker)), + []byte(hex.EncodeToString(tokenName)), + []byte(hex.EncodeToString(ticker)), []byte(hex.EncodeToString([]byte("META"))), []byte(hex.EncodeToString(decimals.Bytes())), }, From fe9936be3488a121a0dbc7294356244c875ff7d4 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 18 Jun 2024 15:59:14 +0300 Subject: [PATCH 347/503] fix for fungible register dynamic --- vm/systemSmartContracts/esdt.go | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/vm/systemSmartContracts/esdt.go b/vm/systemSmartContracts/esdt.go index 05ff4638cd1..8e1aac1e0a5 100644 --- a/vm/systemSmartContracts/esdt.go +++ b/vm/systemSmartContracts/esdt.go @@ -585,6 +585,15 @@ func (e *esdt) getTokenType(compressed []byte) (bool, []byte, error) { return false, nil, vm.ErrInvalidArgument } +func getDynamicTokenType(tokenType []byte) []byte { + if bytes.Equal(tokenType, []byte(core.NonFungibleESDTv2)) || + bytes.Equal(tokenType, []byte(core.NonFungibleESDT)) { + return []byte(core.DynamicNFTESDT) + } + + return append([]byte(core.Dynamic), tokenType...) +} + func (e *esdt) changeSFTToMetaESDT(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { if !e.enableEpochsHandler.IsFlagEnabled(common.MetaESDTSetFlag) { e.eei.AddReturnMessage("invalid method to call") @@ -2236,6 +2245,11 @@ func (e *esdt) createDynamicToken(args *vmcommon.ContractCallInput) ([]byte, *ES return nil, nil, vmcommon.UserError } + if isNotAllowedToCreateDynamicToken(tokenType) { + e.eei.AddReturnMessage(fmt.Sprintf("cannot create %s tokens as dynamic", tokenType)) + return nil, nil, vmcommon.UserError + } + propertiesStart := 3 numOfDecimals := uint32(0) if isWithDecimals { @@ -2283,15 +2297,6 @@ func (e *esdt) createDynamicToken(args *vmcommon.ContractCallInput) ([]byte, *ES return tokenIdentifier, token, vmcommon.Ok } -func getDynamicTokenType(tokenType []byte) []byte { - if bytes.Equal(tokenType, []byte(core.NonFungibleESDTv2)) || - bytes.Equal(tokenType, []byte(core.NonFungibleESDT)) { - return []byte(core.DynamicNFTESDT) - } - - return append([]byte(core.Dynamic), tokenType...) -} - func (e *esdt) registerDynamic(args *vmcommon.ContractCallInput) vmcommon.ReturnCode { _, _, returnCode := e.createDynamicToken(args) return returnCode @@ -2409,6 +2414,14 @@ func isNotAllowed(tokenType []byte) bool { return false } +func isNotAllowedToCreateDynamicToken(tokenType []byte) bool { + if bytes.Equal(tokenType, []byte(core.FungibleESDT)) { + return true + } + + return false +} + func (e *esdt) sendTokenTypeToSystemAccounts(caller []byte, tokenID []byte, token *ESDTDataV2) { if !e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) { return From 2c2c16ffaba59be5f96b8dd3dcc3340e3b9c6186 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 18 Jun 2024 16:04:19 +0300 Subject: [PATCH 348/503] fix linter issue --- .../chainSimulator/vm/esdtImprovements_test.go | 7 ------- vm/systemSmartContracts/esdt.go | 6 +----- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index a7a0682ef65..6dffa745477 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -2266,11 +2266,6 @@ func TestChainSimulator_FNG_RegisterDynamic(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(txResult.Logs.Events[0]) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - signalErrorTopic := string(txResult.Logs.Events[0].Topics[1]) require.Equal(t, fmt.Sprintf("cannot create %s tokens as dynamic", core.FungibleESDT), signalErrorTopic) @@ -2659,8 +2654,6 @@ func TestChainSimulator_FNG_RegisterAndSetAllRolesDynamic(t *testing.T) { require.Equal(t, fmt.Sprintf("cannot create %s tokens as dynamic", core.FungibleESDT), signalErrorTopic) } -// Test scenario #12b -// func TestChainSimulator_MetaESDT_RegisterAndSetAllRolesDynamic(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") diff --git a/vm/systemSmartContracts/esdt.go b/vm/systemSmartContracts/esdt.go index 8e1aac1e0a5..6852dbf04fc 100644 --- a/vm/systemSmartContracts/esdt.go +++ b/vm/systemSmartContracts/esdt.go @@ -2415,11 +2415,7 @@ func isNotAllowed(tokenType []byte) bool { } func isNotAllowedToCreateDynamicToken(tokenType []byte) bool { - if bytes.Equal(tokenType, []byte(core.FungibleESDT)) { - return true - } - - return false + return bytes.Equal(tokenType, []byte(core.FungibleESDT)) } func (e *esdt) sendTokenTypeToSystemAccounts(caller []byte, tokenID []byte, token *ESDTDataV2) { From 934bdda4b379a0ef28e0cf773834349badb3e237 Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 18 Jun 2024 16:28:09 +0300 Subject: [PATCH 349/503] new vm common with fixes --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index cefd79fee44..ca263e05a3b 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f - github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240618072615-e9c0c43e9fa1 + github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240618132642-bd8b15211219 github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240509104009-598a37ff36b9 diff --git a/go.sum b/go.sum index 4d6d77a3451..2cc1057b231 100644 --- a/go.sum +++ b/go.sum @@ -399,8 +399,8 @@ 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.20240618072615-e9c0c43e9fa1 h1:NDouJwS8vAPLsNLZiOO5x9vXZeUKxYpIxN3H6Qvotv8= -github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240618072615-e9c0c43e9fa1/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo= +github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240618132642-bd8b15211219 h1:DX6I8zwPnNelzKWhUMZWTDADMN+2bRl3uCxtPpYXr8U= +github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240618132642-bd8b15211219/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= From a4bcca14763e64f9517d0e780b4ce2dc5b993e46 Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 18 Jun 2024 16:34:26 +0300 Subject: [PATCH 350/503] extra fix --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index ca263e05a3b..9fc119c930a 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f - github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240618132642-bd8b15211219 + github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240618133316-4c17adfcaea6 github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240509104009-598a37ff36b9 diff --git a/go.sum b/go.sum index 2cc1057b231..5d1b6238dbe 100644 --- a/go.sum +++ b/go.sum @@ -399,8 +399,8 @@ 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.20240618132642-bd8b15211219 h1:DX6I8zwPnNelzKWhUMZWTDADMN+2bRl3uCxtPpYXr8U= -github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240618132642-bd8b15211219/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo= +github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240618133316-4c17adfcaea6 h1:416tIBSfXoXuA15BUVY53m84LVZysVFz0M4yuw2kKh4= +github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240618133316-4c17adfcaea6/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= From 4fdf47ddd0d591a0416645751335f3c68c321214 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 18 Jun 2024 19:28:35 +0300 Subject: [PATCH 351/503] fix test after merge --- integrationTests/chainSimulator/relayedTx/relayedTx_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index f23a4080995..e104035d6c1 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -279,8 +279,6 @@ func startChainSimulator(t *testing.T) testsChainSimulator.ChainSimulator { cfg.EpochConfig.EnableEpochs.RelayedTransactionsV3EnableEpoch = 1 cfg.EpochConfig.EnableEpochs.FixRelayedMoveBalanceEnableEpoch = 1 }, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, }) require.NoError(t, err) require.NotNil(t, cs) From 9d62f1caad2847e0b1053180cd303fe686fba11a Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 19 Jun 2024 10:28:40 +0300 Subject: [PATCH 352/503] fix linter after merge --- integrationTests/chainSimulator/relayedTx/relayedTx_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index b2d3fb74030..d987690bf18 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -330,7 +330,7 @@ func testFixRelayedMoveBalanceWithChainSimulatorScCall( relayedTx := generateTransaction(relayer.Bytes, 0, owner.Bytes, big.NewInt(0), string(txData), gasLimit) - result, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) + _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) require.NoError(t, err) // send relayed tx, fix still not active @@ -344,7 +344,7 @@ func testFixRelayedMoveBalanceWithChainSimulatorScCall( relayerBalanceBefore := getBalance(t, cs, relayer) - result, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) + _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) require.NoError(t, err) relayerBalanceAfter := getBalance(t, cs, relayer) @@ -367,7 +367,7 @@ func testFixRelayedMoveBalanceWithChainSimulatorScCall( relayerBalanceBefore = getBalance(t, cs, relayer) - result, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) + _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) require.NoError(t, err) relayerBalanceAfter = getBalance(t, cs, relayer) From 784dce52fdd48fe81383943c6cc146531148a9d6 Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 19 Jun 2024 10:43:49 +0300 Subject: [PATCH 353/503] fix unit tests --- .../process/alteredaccounts/alteredAccountsProvider_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/outport/process/alteredaccounts/alteredAccountsProvider_test.go b/outport/process/alteredaccounts/alteredAccountsProvider_test.go index 7832e6e55bb..032af616d19 100644 --- a/outport/process/alteredaccounts/alteredAccountsProvider_test.go +++ b/outport/process/alteredaccounts/alteredAccountsProvider_test.go @@ -620,6 +620,7 @@ func testExtractAlteredAccountsFromPoolShouldIncludeESDT(t *testing.T) { Nonce: 0, Properties: "6f6b", MetaData: nil, + Type: core.FungibleESDT, }, res[encodedAddr].Tokens[0]) } @@ -1124,6 +1125,7 @@ func testExtractAlteredAccountsFromPoolAddressHasMultipleNfts(t *testing.T) { Balance: expectedToken0.Value.String(), Nonce: 0, MetaData: nil, + Type: core.FungibleESDT, }) require.Contains(t, res[encodedAddr].Tokens, &alteredAccount.AccountTokenData{ @@ -1222,6 +1224,7 @@ func testExtractAlteredAccountsFromPoolESDTTransferBalanceNotChanged(t *testing. AdditionalData: &alteredAccount.AdditionalAccountTokenData{ IsNFTCreate: false, }, + Type: core.FungibleESDT, }, }, AdditionalData: &alteredAccount.AdditionalAccountData{ @@ -1241,6 +1244,7 @@ func testExtractAlteredAccountsFromPoolESDTTransferBalanceNotChanged(t *testing. AdditionalData: &alteredAccount.AdditionalAccountTokenData{ IsNFTCreate: false, }, + Type: core.FungibleESDT, }, }, AdditionalData: &alteredAccount.AdditionalAccountData{ @@ -1432,6 +1436,7 @@ func textExtractAlteredAccountsFromPoolNftCreate(t *testing.T) { AdditionalData: &alteredAccount.AdditionalAccountTokenData{ IsNFTCreate: true, }, + Type: core.FungibleESDT, }, }, AdditionalData: &alteredAccount.AdditionalAccountData{ From b6cb7be772c7d965f5525d003965007ee1c46778 Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 19 Jun 2024 12:39:14 +0300 Subject: [PATCH 354/503] new version es indexer --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 9fc119c930a..786caa073f5 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e github.com/multiversx/mx-chain-core-go v1.2.21-0.20240530111258-45870512bfbe github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df - github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240514103357-929ece92ef86 + github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619060917-731bddac4821 github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f diff --git a/go.sum b/go.sum index 5d1b6238dbe..47c61e5e62d 100644 --- a/go.sum +++ b/go.sum @@ -391,8 +391,8 @@ github.com/multiversx/mx-chain-core-go v1.2.21-0.20240530111258-45870512bfbe h1: github.com/multiversx/mx-chain-core-go v1.2.21-0.20240530111258-45870512bfbe/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-es-indexer-go v1.7.2-0.20240619060917-731bddac4821 h1:rB5XbWMILQJLH1GmsXjdfE28+k1cvovyP0/M77jrcs4= +github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619060917-731bddac4821/go.mod h1:Phf/QUo+JG6aoyUrktqPKg6exkj+Uz2kT5a8Tiyises= 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= From 640552c4ea91cbf4da11366f9250cb6d73cd4e44 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 19 Jun 2024 12:56:04 +0300 Subject: [PATCH 355/503] gasScheduleV8 --- cmd/node/config/enableEpochs.toml | 2 +- .../config/gasSchedules/gasScheduleV8.toml | 828 ++++++++++++++++++ .../components/coreComponents_test.go | 2 +- .../components/processComponents_test.go | 2 +- 4 files changed, 831 insertions(+), 3 deletions(-) create mode 100644 cmd/node/config/gasSchedules/gasScheduleV8.toml diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index 9502cceba9a..dce2d48be2c 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -329,5 +329,5 @@ [GasSchedule] # GasScheduleByEpochs holds the configuration for the gas schedule that will be applied from specific epochs GasScheduleByEpochs = [ - { StartEpoch = 0, FileName = "gasScheduleV7.toml" }, + { StartEpoch = 0, FileName = "gasScheduleV8.toml" }, ] diff --git a/cmd/node/config/gasSchedules/gasScheduleV8.toml b/cmd/node/config/gasSchedules/gasScheduleV8.toml new file mode 100644 index 00000000000..3f30d694591 --- /dev/null +++ b/cmd/node/config/gasSchedules/gasScheduleV8.toml @@ -0,0 +1,828 @@ +[BuiltInCost] + ChangeOwnerAddress = 5000000 + ClaimDeveloperRewards = 5000000 + SaveUserName = 1000000 + SaveKeyValue = 100000 + ESDTTransfer = 200000 + ESDTBurn = 100000 + ESDTLocalMint = 50000 + ESDTLocalBurn = 50000 + ESDTNFTCreate = 150000 + ESDTNFTAddQuantity = 50000 + ESDTNFTBurn = 50000 + ESDTNFTTransfer = 200000 + ESDTNFTChangeCreateOwner = 1000000 + ESDTNFTAddUri = 50000 + ESDTNFTUpdateAttributes = 50000 + ESDTNFTMultiTransfer = 200000 + MultiESDTNFTTransfer = 200000 # should be the same value with the ESDTNFTMultiTransfer + SetGuardian = 250000 + GuardAccount = 250000 + UnGuardAccount = 250000 + TrieLoadPerNode = 100000 + TrieStorePerNode = 50000 + +[MetaChainSystemSCsCost] + Stake = 5000000 + UnStake = 5000000 + UnBond = 5000000 + Claim = 5000000 + Get = 5000000 + ChangeRewardAddress = 5000000 + ChangeValidatorKeys = 5000000 + UnJail = 5000000 + DelegationOps = 1000000 + DelegationMgrOps = 50000000 + ValidatorToDelegation = 500000000 + ESDTIssue = 50000000 + ESDTOperations = 50000000 + Proposal = 50000000 + Vote = 5000000 + DelegateVote = 50000000 + RevokeVote = 50000000 + CloseProposal = 50000000 + GetAllNodeStates = 20000000 + UnstakeTokens = 5000000 + UnbondTokens = 5000000 + GetActiveFund = 50000 + FixWaitingListSize = 500000000 + +[BaseOperationCost] + StorePerByte = 10000 + ReleasePerByte = 1000 + DataCopyPerByte = 50 + PersistPerByte = 1000 + CompilePerByte = 300 + AoTPreparePerByte = 100 + GetCode = 1000000 + +[BaseOpsAPICost] + GetSCAddress = 1000 + GetOwnerAddress = 5000 + IsSmartContract = 5000 + GetShardOfAddress = 5000 + GetExternalBalance = 7000 + GetBlockHash = 10000 + TransferValue = 100000 + GetArgument = 1000 + GetFunction = 1000 + GetNumArguments = 1000 + StorageStore = 75000 + StorageLoad = 50000 + CachedStorageLoad = 1000 + GetCaller = 1000 + GetCallValue = 1000 + Log = 3750 + Finish = 1 + SignalError = 1 + GetBlockTimeStamp = 10000 + GetGasLeft = 1000 + Int64GetArgument = 1000 + Int64StorageStore = 75000 + Int64StorageLoad = 50000 + Int64Finish = 1000 + GetStateRootHash = 10000 + GetBlockNonce = 10000 + GetBlockEpoch = 10000 + GetBlockRound = 10000 + GetBlockRandomSeed = 10000 + ExecuteOnSameContext = 100000 + ExecuteOnDestContext = 100000 + DelegateExecution = 100000 + AsyncCallStep = 100000 + AsyncCallbackGasLock = 4000000 + ExecuteReadOnly = 160000 + CreateContract = 300000 + GetReturnData = 1000 + GetNumReturnData = 1000 + GetReturnDataSize = 1000 + GetOriginalTxHash = 10000 + CleanReturnData = 1000 + DeleteFromReturnData = 1000 + GetPrevTxHash = 10000 + GetCurrentTxHash = 10000 + CreateAsyncCall = 200000 + SetAsyncCallback = 100000 + SetAsyncGroupCallback = 100000 + SetAsyncContextCallback = 100000 + GetCallbackClosure = 10000 + GetCodeMetadata = 10000 + IsBuiltinFunction = 10000 + +[EthAPICost] + UseGas = 100 + GetAddress = 100000 + GetExternalBalance = 70000 + GetBlockHash = 100000 + Call = 160000 + CallDataCopy = 200 + GetCallDataSize = 100 + CallCode = 160000 + CallDelegate = 160000 + CallStatic = 160000 + StorageStore = 250000 + StorageLoad = 100000 + GetCaller = 100 + GetCallValue = 100 + CodeCopy = 1000 + GetCodeSize = 100 + GetBlockCoinbase = 100 + Create = 320000 + GetBlockDifficulty = 100 + ExternalCodeCopy = 3000 + GetExternalCodeSize = 2500 + GetGasLeft = 100 + GetBlockGasLimit = 100000 + GetTxGasPrice = 1000 + Log = 3750 + GetBlockNumber = 100000 + GetTxOrigin = 100000 + Finish = 1 + Revert = 1 + GetReturnDataSize = 200 + ReturnDataCopy = 500 + SelfDestruct = 5000000 + GetBlockTimeStamp = 100000 + +[BigIntAPICost] + BigIntNew = 2000 + BigIntByteLength = 2000 + BigIntUnsignedByteLength = 2000 + BigIntSignedByteLength = 2000 + BigIntGetBytes = 2000 + BigIntGetUnsignedBytes = 2000 + BigIntGetSignedBytes = 2000 + BigIntSetBytes = 2000 + BigIntSetUnsignedBytes = 2000 + BigIntSetSignedBytes = 2000 + BigIntIsInt64 = 2000 + BigIntGetInt64 = 2000 + BigIntSetInt64 = 2000 + BigIntAdd = 2000 + BigIntSub = 2000 + BigIntMul = 6000 + BigIntSqrt = 6000 + BigIntPow = 6000 + BigIntLog = 6000 + BigIntTDiv = 6000 + BigIntTMod = 6000 + BigIntEDiv = 6000 + BigIntEMod = 6000 + BigIntAbs = 2000 + BigIntNeg = 2000 + BigIntSign = 2000 + BigIntCmp = 2000 + BigIntNot = 2000 + BigIntAnd = 2000 + BigIntOr = 2000 + BigIntXor = 2000 + BigIntShr = 2000 + BigIntShl = 2000 + BigIntFinishUnsigned = 1000 + BigIntFinishSigned = 1000 + BigIntStorageLoadUnsigned = 50000 + BigIntStorageStoreUnsigned = 75000 + BigIntGetArgument = 1000 + BigIntGetUnsignedArgument = 1000 + BigIntGetSignedArgument = 1000 + BigIntGetCallValue = 1000 + BigIntGetExternalBalance = 10000 + CopyPerByteForTooBig = 1000 + +[CryptoAPICost] + SHA256 = 1000000 + Keccak256 = 1000000 + Ripemd160 = 1000000 + VerifyBLS = 5000000 + VerifyEd25519 = 2000000 + VerifySecp256k1 = 2000000 + EllipticCurveNew = 10000 + AddECC = 75000 + DoubleECC = 65000 + IsOnCurveECC = 10000 + ScalarMultECC = 400000 + MarshalECC = 13000 + MarshalCompressedECC = 15000 + UnmarshalECC = 20000 + UnmarshalCompressedECC = 270000 + GenerateKeyECC = 7000000 + EncodeDERSig = 10000000 + +[ManagedBufferAPICost] + MBufferNew = 2000 + MBufferNewFromBytes = 2000 + MBufferGetLength = 2000 + MBufferGetBytes = 2000 + MBufferGetByteSlice = 2000 + MBufferCopyByteSlice = 2000 + MBufferSetBytes = 2000 + MBufferAppend = 2000 + MBufferAppendBytes = 2000 + MBufferToBigIntUnsigned = 2000 + MBufferToBigIntSigned = 5000 + MBufferFromBigIntUnsigned = 2000 + MBufferFromBigIntSigned = 5000 + MBufferStorageStore = 75000 + MBufferStorageLoad = 50000 + MBufferGetArgument = 1000 + MBufferFinish = 1000 + MBufferSetRandom = 6000 + MBufferToBigFloat = 2000 + MBufferFromBigFloat = 2000 + +[BigFloatAPICost] + BigFloatNewFromParts = 3000 + BigFloatAdd = 7000 + BigFloatSub = 7000 + BigFloatMul = 7000 + BigFloatDiv = 7000 + BigFloatTruncate = 5000 + BigFloatNeg = 5000 + BigFloatClone = 5000 + BigFloatCmp = 4000 + BigFloatAbs = 5000 + BigFloatSqrt = 7000 + BigFloatPow = 10000 + BigFloatFloor = 5000 + BigFloatCeil = 5000 + BigFloatIsInt = 3000 + BigFloatSetBigInt = 3000 + BigFloatSetInt64 = 1000 + BigFloatGetConst = 1000 + +[WASMOpcodeCost] + Unreachable = 5 + Nop = 5 + Block = 5 + Loop = 5 + If = 5 + Else = 5 + End = 5 + Br = 5 + BrIf = 5 + BrTable = 5 + Return = 5 + Call = 5 + CallIndirect = 5 + Drop = 5 + Select = 5 + TypedSelect = 5 + LocalGet = 5 + LocalSet = 5 + LocalTee = 5 + GlobalGet = 5 + GlobalSet = 5 + I32Load = 5 + I64Load = 5 + F32Load = 6 + F64Load = 6 + I32Load8S = 5 + I32Load8U = 5 + I32Load16S = 5 + I32Load16U = 5 + I64Load8S = 5 + I64Load8U = 5 + I64Load16S = 5 + I64Load16U = 5 + I64Load32S = 5 + I64Load32U = 5 + I32Store = 5 + I64Store = 5 + F32Store = 12 + F64Store = 12 + I32Store8 = 5 + I32Store16 = 5 + I64Store8 = 5 + I64Store16 = 5 + I64Store32 = 5 + MemorySize = 5 + MemoryGrow = 1000000 + I32Const = 5 + I64Const = 5 + F32Const = 5 + F64Const = 5 + RefNull = 5 + RefIsNull = 5 + RefFunc = 5 + I32Eqz = 5 + I32Eq = 5 + I32Ne = 5 + I32LtS = 5 + I32LtU = 5 + I32GtS = 5 + I32GtU = 5 + I32LeS = 5 + I32LeU = 5 + I32GeS = 5 + I32GeU = 5 + I64Eqz = 5 + I64Eq = 5 + I64Ne = 5 + I64LtS = 5 + I64LtU = 5 + I64GtS = 5 + I64GtU = 5 + I64LeS = 5 + I64LeU = 5 + I64GeS = 5 + I64GeU = 5 + F32Eq = 6 + F32Ne = 6 + F32Lt = 6 + F32Gt = 6 + F32Le = 6 + F32Ge = 6 + F64Eq = 6 + F64Ne = 6 + F64Lt = 6 + F64Gt = 6 + F64Le = 6 + F64Ge = 6 + I32Clz = 100 + I32Ctz = 100 + I32Popcnt = 100 + I32Add = 5 + I32Sub = 5 + I32Mul = 5 + I32DivS = 18 + I32DivU = 18 + I32RemS = 18 + I32RemU = 18 + I32And = 5 + I32Or = 5 + I32Xor = 5 + I32Shl = 5 + I32ShrS = 5 + I32ShrU = 5 + I32Rotl = 5 + I32Rotr = 5 + I64Clz = 100 + I64Ctz = 100 + I64Popcnt = 100 + I64Add = 5 + I64Sub = 5 + I64Mul = 5 + I64DivS = 18 + I64DivU = 18 + I64RemS = 18 + I64RemU = 18 + I64And = 5 + I64Or = 5 + I64Xor = 5 + I64Shl = 5 + I64ShrS = 5 + I64ShrU = 5 + I64Rotl = 5 + I64Rotr = 5 + F32Abs = 5 + F32Neg = 5 + F32Ceil = 100 + F32Floor = 100 + F32Trunc = 100 + F32Nearest = 100 + F32Sqrt = 100 + F32Add = 5 + F32Sub = 5 + F32Mul = 15 + F32Div = 100 + F32Min = 15 + F32Max = 15 + F32Copysign = 5 + F64Abs = 5 + F64Neg = 5 + F64Ceil = 100 + F64Floor = 100 + F64Trunc = 100 + F64Nearest = 100 + F64Sqrt = 100 + F64Add = 5 + F64Sub = 5 + F64Mul = 15 + F64Div = 100 + F64Min = 15 + F64Max = 15 + F64Copysign = 5 + I32WrapI64 = 9 + I32TruncF32S = 100 + I32TruncF32U = 100 + I32TruncF64S = 100 + I32TruncF64U = 100 + I64ExtendI32S = 9 + I64ExtendI32U = 9 + I64TruncF32S = 100 + I64TruncF32U = 100 + I64TruncF64S = 100 + I64TruncF64U = 100 + F32ConvertI32S = 100 + F32ConvertI32U = 100 + F32ConvertI64S = 100 + F32ConvertI64U = 100 + F32DemoteF64 = 100 + F64ConvertI32S = 100 + F64ConvertI32U = 100 + F64ConvertI64S = 100 + F64ConvertI64U = 100 + F64PromoteF32 = 100 + I32ReinterpretF32 = 100 + I64ReinterpretF64 = 100 + F32ReinterpretI32 = 100 + F64ReinterpretI64 = 100 + I32Extend8S = 9 + I32Extend16S = 9 + I64Extend8S = 9 + I64Extend16S = 9 + I64Extend32S = 9 + I32TruncSatF32S = 100 + I32TruncSatF32U = 100 + I32TruncSatF64S = 100 + I32TruncSatF64U = 100 + I64TruncSatF32S = 100 + I64TruncSatF32U = 100 + I64TruncSatF64S = 100 + I64TruncSatF64U = 100 + MemoryInit = 5 + DataDrop = 5 + MemoryCopy = 5 + MemoryFill = 5 + TableInit = 10 + ElemDrop = 10 + TableCopy = 10 + TableFill = 10 + TableGet = 10 + TableSet = 10 + TableGrow = 10 + TableSize = 10 + AtomicNotify = 1000000 + I32AtomicWait = 1000000 + I64AtomicWait = 1000000 + AtomicFence = 1000000 + I32AtomicLoad = 1000000 + I64AtomicLoad = 1000000 + I32AtomicLoad8U = 1000000 + I32AtomicLoad16U = 1000000 + I64AtomicLoad8U = 1000000 + I64AtomicLoad16U = 1000000 + I64AtomicLoad32U = 1000000 + I32AtomicStore = 1000000 + I64AtomicStore = 1000000 + I32AtomicStore8 = 1000000 + I32AtomicStore16 = 1000000 + I64AtomicStore8 = 1000000 + I64AtomicStore16 = 1000000 + I64AtomicStore32 = 1000000 + I32AtomicRmwAdd = 1000000 + I64AtomicRmwAdd = 1000000 + I32AtomicRmw8AddU = 1000000 + I32AtomicRmw16AddU = 1000000 + I64AtomicRmw8AddU = 1000000 + I64AtomicRmw16AddU = 1000000 + I64AtomicRmw32AddU = 1000000 + I32AtomicRmwSub = 1000000 + I64AtomicRmwSub = 1000000 + I32AtomicRmw8SubU = 1000000 + I32AtomicRmw16SubU = 1000000 + I64AtomicRmw8SubU = 1000000 + I64AtomicRmw16SubU = 1000000 + I64AtomicRmw32SubU = 1000000 + I32AtomicRmwAnd = 1000000 + I64AtomicRmwAnd = 1000000 + I32AtomicRmw8AndU = 1000000 + I32AtomicRmw16AndU = 1000000 + I64AtomicRmw8AndU = 1000000 + I64AtomicRmw16AndU = 1000000 + I64AtomicRmw32AndU = 1000000 + I32AtomicRmwOr = 1000000 + I64AtomicRmwOr = 1000000 + I32AtomicRmw8OrU = 1000000 + I32AtomicRmw16OrU = 1000000 + I64AtomicRmw8OrU = 1000000 + I64AtomicRmw16OrU = 1000000 + I64AtomicRmw32OrU = 1000000 + I32AtomicRmwXor = 1000000 + I64AtomicRmwXor = 1000000 + I32AtomicRmw8XorU = 1000000 + I32AtomicRmw16XorU = 1000000 + I64AtomicRmw8XorU = 1000000 + I64AtomicRmw16XorU = 1000000 + I64AtomicRmw32XorU = 1000000 + I32AtomicRmwXchg = 1000000 + I64AtomicRmwXchg = 1000000 + I32AtomicRmw8XchgU = 1000000 + I32AtomicRmw16XchgU = 1000000 + I64AtomicRmw8XchgU = 1000000 + I64AtomicRmw16XchgU = 1000000 + I64AtomicRmw32XchgU = 1000000 + I32AtomicRmwCmpxchg = 1000000 + I64AtomicRmwCmpxchg = 1000000 + I32AtomicRmw8CmpxchgU = 1000000 + I32AtomicRmw16CmpxchgU = 1000000 + I64AtomicRmw8CmpxchgU = 1000000 + I64AtomicRmw16CmpxchgU = 1000000 + I64AtomicRmw32CmpxchgU = 1000000 + V128Load = 1000000 + V128Store = 1000000 + V128Const = 1000000 + I8x16Splat = 1000000 + I8x16ExtractLaneS = 1000000 + I8x16ExtractLaneU = 1000000 + I8x16ReplaceLane = 1000000 + I16x8Splat = 1000000 + I16x8ExtractLaneS = 1000000 + I16x8ExtractLaneU = 1000000 + I16x8ReplaceLane = 1000000 + I32x4Splat = 1000000 + I32x4ExtractLane = 1000000 + I32x4ReplaceLane = 1000000 + I64x2Splat = 1000000 + I64x2ExtractLane = 1000000 + I64x2ReplaceLane = 1000000 + F32x4Splat = 1000000 + F32x4ExtractLane = 1000000 + F32x4ReplaceLane = 1000000 + F64x2Splat = 1000000 + F64x2ExtractLane = 1000000 + F64x2ReplaceLane = 1000000 + I8x16Eq = 1000000 + I8x16Ne = 1000000 + I8x16LtS = 1000000 + I8x16LtU = 1000000 + I8x16GtS = 1000000 + I8x16GtU = 1000000 + I8x16LeS = 1000000 + I8x16LeU = 1000000 + I8x16GeS = 1000000 + I8x16GeU = 1000000 + I16x8Eq = 1000000 + I16x8Ne = 1000000 + I16x8LtS = 1000000 + I16x8LtU = 1000000 + I16x8GtS = 1000000 + I16x8GtU = 1000000 + I16x8LeS = 1000000 + I16x8LeU = 1000000 + I16x8GeS = 1000000 + I16x8GeU = 1000000 + I32x4Eq = 1000000 + I32x4Ne = 1000000 + I32x4LtS = 1000000 + I32x4LtU = 1000000 + I32x4GtS = 1000000 + I32x4GtU = 1000000 + I32x4LeS = 1000000 + I32x4LeU = 1000000 + I32x4GeS = 1000000 + I32x4GeU = 1000000 + F32x4Eq = 1000000 + F32x4Ne = 1000000 + F32x4Lt = 1000000 + F32x4Gt = 1000000 + F32x4Le = 1000000 + F32x4Ge = 1000000 + F64x2Eq = 1000000 + F64x2Ne = 1000000 + F64x2Lt = 1000000 + F64x2Gt = 1000000 + F64x2Le = 1000000 + F64x2Ge = 1000000 + V128Not = 1000000 + V128And = 1000000 + V128AndNot = 1000000 + V128Or = 1000000 + V128Xor = 1000000 + V128Bitselect = 1000000 + I8x16Neg = 1000000 + I8x16AnyTrue = 1000000 + I8x16AllTrue = 1000000 + I8x16Shl = 1000000 + I8x16ShrS = 1000000 + I8x16ShrU = 1000000 + I8x16Add = 1000000 + I8x16AddSaturateS = 1000000 + I8x16AddSaturateU = 1000000 + I8x16Sub = 1000000 + I8x16SubSaturateS = 1000000 + I8x16SubSaturateU = 1000000 + I8x16MinS = 1000000 + I8x16MinU = 1000000 + I8x16MaxS = 1000000 + I8x16MaxU = 1000000 + I8x16Mul = 1000000 + I16x8Neg = 1000000 + I16x8AnyTrue = 1000000 + I16x8AllTrue = 1000000 + I16x8Shl = 1000000 + I16x8ShrS = 1000000 + I16x8ShrU = 1000000 + I16x8Add = 1000000 + I16x8AddSaturateS = 1000000 + I16x8AddSaturateU = 1000000 + I16x8Sub = 1000000 + I16x8SubSaturateS = 1000000 + I16x8SubSaturateU = 1000000 + I16x8Mul = 1000000 + I16x8MinS = 1000000 + I16x8MinU = 1000000 + I16x8MaxS = 1000000 + I16x8MaxU = 1000000 + I32x4Neg = 1000000 + I32x4AnyTrue = 1000000 + I32x4AllTrue = 1000000 + I32x4Shl = 1000000 + I32x4ShrS = 1000000 + I32x4ShrU = 1000000 + I32x4Add = 1000000 + I32x4Sub = 1000000 + I32x4Mul = 1000000 + I32x4MinS = 1000000 + I32x4MinU = 1000000 + I32x4MaxS = 1000000 + I32x4MaxU = 1000000 + I64x2Neg = 1000000 + I64x2AnyTrue = 1000000 + I64x2AllTrue = 1000000 + I64x2Shl = 1000000 + I64x2ShrS = 1000000 + I64x2ShrU = 1000000 + I64x2Add = 1000000 + I64x2Sub = 1000000 + I64x2Mul = 1000000 + F32x4Abs = 1000000 + F32x4Neg = 1000000 + F32x4Sqrt = 1000000 + F32x4Add = 1000000 + F32x4Sub = 1000000 + F32x4Mul = 1000000 + F32x4Div = 1000000 + F32x4Min = 1000000 + F32x4Max = 1000000 + F64x2Abs = 1000000 + F64x2Neg = 1000000 + F64x2Sqrt = 1000000 + F64x2Add = 1000000 + F64x2Sub = 1000000 + F64x2Mul = 1000000 + F64x2Div = 1000000 + F64x2Min = 1000000 + F64x2Max = 1000000 + I32x4TruncSatF32x4S = 1000000 + I32x4TruncSatF32x4U = 1000000 + I64x2TruncSatF64x2S = 1000000 + I64x2TruncSatF64x2U = 1000000 + F32x4ConvertI32x4S = 1000000 + F32x4ConvertI32x4U = 1000000 + F64x2ConvertI64x2S = 1000000 + F64x2ConvertI64x2U = 1000000 + V8x16Swizzle = 1000000 + V8x16Shuffle = 1000000 + V8x16LoadSplat = 1000000 + V16x8LoadSplat = 1000000 + V32x4LoadSplat = 1000000 + V64x2LoadSplat = 1000000 + I8x16NarrowI16x8S = 1000000 + I8x16NarrowI16x8U = 1000000 + I16x8NarrowI32x4S = 1000000 + I16x8NarrowI32x4U = 1000000 + I16x8WidenLowI8x16S = 1000000 + I16x8WidenHighI8x16S = 1000000 + I16x8WidenLowI8x16U = 1000000 + I16x8WidenHighI8x16U = 1000000 + I32x4WidenLowI16x8S = 1000000 + I32x4WidenHighI16x8S = 1000000 + I32x4WidenLowI16x8U = 1000000 + I32x4WidenHighI16x8U = 1000000 + I16x8Load8x8S = 1000000 + I16x8Load8x8U = 1000000 + I32x4Load16x4S = 1000000 + I32x4Load16x4U = 1000000 + I64x2Load32x2S = 1000000 + I64x2Load32x2U = 1000000 + I8x16RoundingAverageU = 1000000 + I16x8RoundingAverageU = 1000000 + LocalAllocate = 5 + LocalsUnmetered = 100 + MaxMemoryGrowDelta = 1 + MaxMemoryGrow = 10 + Catch = 10 + CatchAll = 10 + Delegate = 10 + Rethrow = 10 + ReturnCall = 10 + ReturnCallIndirect = 10 + Throw = 10 + Try = 10 + Unwind = 10 + F32x4Ceil = 1000000 + F32x4DemoteF64x2Zero = 1000000 + F32x4Floor = 1000000 + F32x4Nearest = 1000000 + F32x4PMax = 1000000 + F32x4PMin = 1000000 + F32x4Trunc = 1000000 + F64x2Ceil = 1000000 + F64x2ConvertLowI32x4S = 1000000 + F64x2ConvertLowI32x4U = 1000000 + F64x2Floor = 1000000 + F64x2Nearest = 1000000 + F64x2PMax = 1000000 + F64x2PMin = 1000000 + F64x2PromoteLowF32x4 = 1000000 + F64x2Trunc = 1000000 + I16x8Abs = 1000000 + I16x8AddSatS = 1000000 + I16x8AddSatU = 1000000 + I16x8Bitmask = 1000000 + I16x8ExtAddPairwiseI8x16S = 1000000 + I16x8ExtAddPairwiseI8x16U = 1000000 + I16x8ExtMulHighI8x16S = 1000000 + I16x8ExtMulHighI8x16U = 1000000 + I16x8ExtMulLowI8x16S = 1000000 + I16x8ExtMulLowI8x16U = 1000000 + I16x8ExtendHighI8x16S = 1000000 + I16x8ExtendHighI8x16U = 1000000 + I16x8ExtendLowI8x16S = 1000000 + I16x8ExtendLowI8x16U = 1000000 + I16x8Q15MulrSatS = 1000000 + I16x8SubSatS = 1000000 + I16x8SubSatU = 1000000 + I32x4Abs = 1000000 + I32x4Bitmask = 1000000 + I32x4DotI16x8S = 1000000 + I32x4ExtAddPairwiseI16x8S = 1000000 + I32x4ExtAddPairwiseI16x8U = 1000000 + I32x4ExtMulHighI16x8S = 1000000 + I32x4ExtMulHighI16x8U = 1000000 + I32x4ExtMulLowI16x8S = 1000000 + I32x4ExtMulLowI16x8U = 1000000 + I32x4ExtendHighI16x8S = 1000000 + I32x4ExtendHighI16x8U = 1000000 + I32x4ExtendLowI16x8S = 1000000 + I32x4ExtendLowI16x8U = 1000000 + I32x4TruncSatF64x2SZero = 1000000 + I32x4TruncSatF64x2UZero = 1000000 + I64x2Abs = 1000000 + I64x2Bitmask = 1000000 + I64x2Eq = 1000000 + I64x2ExtMulHighI32x4S = 1000000 + I64x2ExtMulHighI32x4U = 1000000 + I64x2ExtMulLowI32x4S = 1000000 + I64x2ExtMulLowI32x4U = 1000000 + I64x2ExtendHighI32x4S = 1000000 + I64x2ExtendHighI32x4U = 1000000 + I64x2ExtendLowI32x4S = 1000000 + I64x2ExtendLowI32x4U = 1000000 + I64x2GeS = 1000000 + I64x2GtS = 1000000 + I64x2LeS = 1000000 + I64x2LtS = 1000000 + I64x2Ne = 1000000 + I8x16Abs = 1000000 + I8x16AddSatS = 1000000 + I8x16AddSatU = 1000000 + I8x16Bitmask = 1000000 + I8x16Popcnt = 1000000 + I8x16Shuffle = 1000000 + I8x16SubSatS = 1000000 + I8x16SubSatU = 1000000 + I8x16Swizzle = 1000000 + MemoryAtomicNotify = 1000000 + MemoryAtomicWait32 = 1000000 + MemoryAtomicWait64 = 1000000 + V128AnyTrue = 1000000 + V128Load16Lane = 1000000 + V128Load16Splat = 1000000 + V128Load16x4S = 1000000 + V128Load16x4U = 1000000 + V128Load32Lane = 1000000 + V128Load32Splat = 1000000 + V128Load32Zero = 1000000 + V128Load32x2S = 1000000 + V128Load32x2U = 1000000 + V128Load64Lane = 1000000 + V128Load64Splat = 1000000 + V128Load64Zero = 1000000 + V128Load8Lane = 1000000 + V128Load8Splat = 1000000 + V128Load8x8S = 1000000 + V128Load8x8U = 1000000 + V128Store16Lane = 1000000 + V128Store32Lane = 1000000 + V128Store64Lane = 1000000 + V128Store8Lane = 1000000 + +[MaxPerTransaction] + MaxBuiltInCallsPerTx = 100 + MaxNumberOfTransfersPerTx = 250 + MaxNumberOfTrieReadsPerTx = 1500 + +# Quadratic, Linear and Constant are the coefficients for a quadratic func. Separate variables are used for the +# sign of each coefficient, 0 meaning positive and 1 meaning negative +# The current values for the coefficients were computed based on benchmarking. +# For the given coefficients, the minimum of the function must not be lower than MinimumGasCost +[DynamicStorageLoad] + QuadraticCoefficient = 688 + SignOfQuadratic = 0 + LinearCoefficient = 31858 + SignOfLinear = 0 + ConstantCoefficient = 15287 + SignOfConstant = 0 + MinimumGasCost = 10000 diff --git a/node/chainSimulator/components/coreComponents_test.go b/node/chainSimulator/components/coreComponents_test.go index 619eb9d3a2e..f11899f66f8 100644 --- a/node/chainSimulator/components/coreComponents_test.go +++ b/node/chainSimulator/components/coreComponents_test.go @@ -127,7 +127,7 @@ func createArgsCoreComponentsHolder() ArgsCoreComponentsHolder { ChanStopNodeProcess: make(chan endProcess.ArgEndProcess), InitialRound: 0, NodesSetupPath: "../../../sharding/mock/testdata/nodesSetupMock.json", - GasScheduleFilename: "../../../cmd/node/config/gasSchedules/gasScheduleV7.toml", + GasScheduleFilename: "../../../cmd/node/config/gasSchedules/gasScheduleV8.toml", NumShards: 3, WorkingDir: ".", MinNodesPerShard: 1, diff --git a/node/chainSimulator/components/processComponents_test.go b/node/chainSimulator/components/processComponents_test.go index efc5590e7f4..a8cb2f053e7 100644 --- a/node/chainSimulator/components/processComponents_test.go +++ b/node/chainSimulator/components/processComponents_test.go @@ -66,7 +66,7 @@ func createArgsProcessComponentsHolder() ArgsProcessComponentsHolder { GasScheduleByEpochs: []config.GasScheduleByEpochs{ { StartEpoch: 0, - FileName: "../../../cmd/node/config/gasSchedules/gasScheduleV7.toml", + FileName: "../../../cmd/node/config/gasSchedules/gasScheduleV8.toml", }, }, }, From 8443b80b748ce687609cde68863d4d3b6fc3e4fc Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 19 Jun 2024 14:34:19 +0300 Subject: [PATCH 356/503] fix integration test --- integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go b/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go index d980ed816d7..afb0166de58 100644 --- a/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go +++ b/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go @@ -28,7 +28,7 @@ func TestESDTMetaDataRecreate(t *testing.T) { func runEsdtMetaDataRecreateTest(t *testing.T, tokenType string) { sndAddr := []byte("12345678901234567890123456789012") token := []byte("tokenId") - roles := [][]byte{[]byte(core.ESDTMetaDataRecreate), []byte(core.ESDTRoleNFTCreate)} + roles := [][]byte{[]byte(core.ESDTRoleNFTRecreate), []byte(core.ESDTRoleNFTCreate)} baseEsdtKeyPrefix := core.ProtectedKeyPrefix + core.ESDTKeyIdentifier key := append([]byte(baseEsdtKeyPrefix), token...) From 7817fca464f741df0c1b2c22cea69a792683d798 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 19 Jun 2024 15:11:52 +0300 Subject: [PATCH 357/503] updated processComponents of chainSimulator to use a disabledWhiteListDataVerifier that returns false on IsWhitelisted --- .../chainSimulator/staking/jail/jail_test.go | 4 +- .../staking/stake/simpleStake_test.go | 4 +- .../staking/stake/stakeAndUnStake_test.go | 66 +++++++++---------- .../stakingProvider/delegation_test.go | 50 +++++++------- .../stakingProviderWithNodesinQueue_test.go | 2 +- .../vm/esdtImprovements_test.go | 18 ++--- node/chainSimulator/chainSimulator_test.go | 18 ++--- .../components/cryptoComponents_test.go | 2 +- .../components/processComponents.go | 6 +- 9 files changed, 84 insertions(+), 86 deletions(-) diff --git a/integrationTests/chainSimulator/staking/jail/jail_test.go b/integrationTests/chainSimulator/staking/jail/jail_test.go index d306156d7b3..42c4e69eaca 100644 --- a/integrationTests/chainSimulator/staking/jail/jail_test.go +++ b/integrationTests/chainSimulator/staking/jail/jail_test.go @@ -67,7 +67,7 @@ func testChainSimulatorJailAndUnJail(t *testing.T, targetEpoch int32, nodeStatus numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: numOfShards, @@ -167,7 +167,7 @@ func TestChainSimulator_FromQueueToAuctionList(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: numOfShards, diff --git a/integrationTests/chainSimulator/staking/stake/simpleStake_test.go b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go index 33ac33fecb7..a1176b7795f 100644 --- a/integrationTests/chainSimulator/staking/stake/simpleStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go @@ -66,7 +66,7 @@ func testChainSimulatorSimpleStake(t *testing.T, targetEpoch int32, nodesStatus numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: numOfShards, @@ -159,7 +159,7 @@ func TestChainSimulator_StakingV4Step2APICalls(t *testing.T) { stakingV4Step3Epoch := uint32(4) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, diff --git a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index 8344c757d80..1804350ded9 100644 --- a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go @@ -57,7 +57,7 @@ func TestChainSimulator_AddValidatorKey(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: numOfShards, @@ -189,7 +189,7 @@ func TestChainSimulator_AddANewValidatorAfterStakingV4(t *testing.T) { } numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: numOfShards, @@ -318,7 +318,7 @@ func testStakeUnStakeUnBond(t *testing.T, targetEpoch int32) { } numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: numOfShards, @@ -446,7 +446,7 @@ func TestChainSimulator_DirectStakingNodes_StakeFunds(t *testing.T) { t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -476,7 +476,7 @@ func TestChainSimulator_DirectStakingNodes_StakeFunds(t *testing.T) { t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -506,7 +506,7 @@ func TestChainSimulator_DirectStakingNodes_StakeFunds(t *testing.T) { t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -536,7 +536,7 @@ func TestChainSimulator_DirectStakingNodes_StakeFunds(t *testing.T) { t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -668,7 +668,7 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation(t *testi t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -699,7 +699,7 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation(t *testi t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -731,7 +731,7 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation(t *testi t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -763,7 +763,7 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation(t *testi t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -949,7 +949,7 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation_WithReac t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -980,7 +980,7 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation_WithReac t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1012,7 +1012,7 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation_WithReac t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1044,7 +1044,7 @@ func TestChainSimulator_DirectStakingNodes_UnstakeFundsWithDeactivation_WithReac t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1186,7 +1186,7 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedFundsBeforeUnbonding( t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1216,7 +1216,7 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedFundsBeforeUnbonding( t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1246,7 +1246,7 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedFundsBeforeUnbonding( t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1276,7 +1276,7 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedFundsBeforeUnbonding( t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1420,7 +1420,7 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInWithdrawEpoch(t *te t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1450,7 +1450,7 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInWithdrawEpoch(t *te t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1480,7 +1480,7 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInWithdrawEpoch(t *te t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1510,7 +1510,7 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInWithdrawEpoch(t *te t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1683,7 +1683,7 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInBatches(t *testing. t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1715,7 +1715,7 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInBatches(t *testing. t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1747,7 +1747,7 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInBatches(t *testing. t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1779,7 +1779,7 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInBatches(t *testing. t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -2039,7 +2039,7 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInEpoch(t *testing.T) t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -2071,7 +2071,7 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInEpoch(t *testing.T) t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -2103,7 +2103,7 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInEpoch(t *testing.T) t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -2135,7 +2135,7 @@ func TestChainSimulator_DirectStakingNodes_WithdrawUnstakedInEpoch(t *testing.T) t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -2332,7 +2332,7 @@ func TestChainSimulator_UnStakeOneActiveNodeAndCheckAPIAuctionList(t *testing.T) numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: numOfShards, @@ -2411,7 +2411,7 @@ func TestChainSimulator_EdgeCaseLowWaitingList(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: numOfShards, diff --git a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index 4697affa054..4c7475701e4 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go @@ -69,7 +69,7 @@ func TestChainSimulator_MakeNewContractFromValidatorData(t *testing.T) { // 6. Execute 2 unDelegate operations of 100 EGLD each, check the topup is back to 500 t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -113,7 +113,7 @@ func TestChainSimulator_MakeNewContractFromValidatorData(t *testing.T) { // 6. Execute 2 unDelegate operations of 100 EGLD each, check the topup is back to 500 t.Run("staking ph 4 is not active and all is done in epoch 0", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -164,7 +164,7 @@ func TestChainSimulator_MakeNewContractFromValidatorData(t *testing.T) { // 6. Execute 2 unDelegate operations of 100 EGLD each, check the topup is back to 500 t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -201,7 +201,7 @@ func TestChainSimulator_MakeNewContractFromValidatorData(t *testing.T) { // 6. Execute 2 unDelegate operations of 100 EGLD each, check the topup is back to 500 t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -238,7 +238,7 @@ func TestChainSimulator_MakeNewContractFromValidatorData(t *testing.T) { // 6. Execute 2 unDelegate operations of 100 EGLD each, check the topup is back to 500 t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -487,7 +487,7 @@ func TestChainSimulator_MakeNewContractFromValidatorDataWith2StakingContracts(t t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -516,7 +516,7 @@ func TestChainSimulator_MakeNewContractFromValidatorDataWith2StakingContracts(t }) t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -545,7 +545,7 @@ func TestChainSimulator_MakeNewContractFromValidatorDataWith2StakingContracts(t }) t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -574,7 +574,7 @@ func TestChainSimulator_MakeNewContractFromValidatorDataWith2StakingContracts(t }) t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -712,7 +712,7 @@ func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -743,7 +743,7 @@ func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta }) t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -775,7 +775,7 @@ func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta }) t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -807,7 +807,7 @@ func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta }) t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1032,7 +1032,7 @@ func TestChainSimulator_CreateNewDelegationContract(t *testing.T) { // 6. Check the node is unstaked in the next epoch t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1071,7 +1071,7 @@ func TestChainSimulator_CreateNewDelegationContract(t *testing.T) { // 6. Check the node is unstaked in the next epoch t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1110,7 +1110,7 @@ func TestChainSimulator_CreateNewDelegationContract(t *testing.T) { // 6. Check the node is unstaked in the next epoch t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1149,7 +1149,7 @@ func TestChainSimulator_CreateNewDelegationContract(t *testing.T) { // 6. Check the node is unstaked in the next epoch t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1400,7 +1400,7 @@ func TestChainSimulator_MaxDelegationCap(t *testing.T) { // 10. Delegate from user B 20 EGLD, check it fails t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1441,7 +1441,7 @@ func TestChainSimulator_MaxDelegationCap(t *testing.T) { // 10. Delegate from user B 20 EGLD, check it fails t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1482,7 +1482,7 @@ func TestChainSimulator_MaxDelegationCap(t *testing.T) { // 10. Delegate from user B 20 EGLD, check it fails t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1523,7 +1523,7 @@ func TestChainSimulator_MaxDelegationCap(t *testing.T) { // 10. Delegate from user B 20 EGLD, check it fails t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1810,7 +1810,7 @@ func TestChainSimulator_MergeDelegation(t *testing.T) { t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1841,7 +1841,7 @@ func TestChainSimulator_MergeDelegation(t *testing.T) { t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1873,7 +1873,7 @@ func TestChainSimulator_MergeDelegation(t *testing.T) { t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -1905,7 +1905,7 @@ func TestChainSimulator_MergeDelegation(t *testing.T) { t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, diff --git a/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go b/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go index f47cf1eec9e..375953d7588 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go @@ -52,7 +52,7 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati } cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 608c24ee3b0..d1d92e64d75 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -86,7 +86,7 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: numOfShards, @@ -710,7 +710,7 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: numOfShards, @@ -887,7 +887,7 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: numOfShards, @@ -1025,7 +1025,7 @@ func TestChainSimulator_NFT_ESDTMetaDataUpdate(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: numOfShards, @@ -1160,7 +1160,7 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: numOfShards, @@ -1309,7 +1309,7 @@ func TestChainSimulator_NFT_ESDTSetNewURIs(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: numOfShards, @@ -1454,7 +1454,7 @@ func TestChainSimulator_NFT_ESDTModifyRoyalties(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: numOfShards, @@ -1588,7 +1588,7 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: numOfShards, @@ -1704,7 +1704,7 @@ func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: numOfShards, diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index 15a32de29c8..3ed39bc8fba 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -27,7 +27,7 @@ func TestNewChainSimulator(t *testing.T) { startTime := time.Now().Unix() roundDurationInMillis := uint64(6000) chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -54,7 +54,7 @@ func TestChainSimulator_GenerateBlocksShouldWork(t *testing.T) { startTime := time.Now().Unix() roundDurationInMillis := uint64(6000) chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -100,7 +100,7 @@ func TestChainSimulator_GenerateBlocksAndEpochChangeShouldWork(t *testing.T) { Value: 20, } chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -157,7 +157,7 @@ func TestSimulator_TriggerChangeOfEpoch(t *testing.T) { Value: 15000, } chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -202,7 +202,7 @@ func TestChainSimulator_SetState(t *testing.T) { Value: 20, } chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -233,7 +233,7 @@ func TestChainSimulator_SetEntireState(t *testing.T) { Value: 20, } chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -281,7 +281,7 @@ func TestChainSimulator_SetEntireStateWithRemoval(t *testing.T) { Value: 20, } chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -328,7 +328,7 @@ func TestChainSimulator_GetAccount(t *testing.T) { Value: 20, } chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -362,7 +362,7 @@ func TestSimulator_SendTransactions(t *testing.T) { Value: 20, } chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, diff --git a/node/chainSimulator/components/cryptoComponents_test.go b/node/chainSimulator/components/cryptoComponents_test.go index fc8087f5cd4..3bba81c9b91 100644 --- a/node/chainSimulator/components/cryptoComponents_test.go +++ b/node/chainSimulator/components/cryptoComponents_test.go @@ -47,7 +47,7 @@ func createArgsCryptoComponentsHolder() ArgsCryptoComponentsHolder { }, }, AllValidatorKeysPemFileName: "allValidatorKeys.pem", - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, } } diff --git a/node/chainSimulator/components/processComponents.go b/node/chainSimulator/components/processComponents.go index 3bef305e8c7..8a2dd6baf1d 100644 --- a/node/chainSimulator/components/processComponents.go +++ b/node/chainSimulator/components/processComponents.go @@ -21,6 +21,7 @@ import ( processComp "github.com/multiversx/mx-chain-go/factory/processing" "github.com/multiversx/mx-chain-go/genesis" "github.com/multiversx/mx-chain-go/genesis/parsing" + nodeDisabled "github.com/multiversx/mx-chain-go/node/disabled" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/interceptors/disabled" "github.com/multiversx/mx-chain-go/sharding" @@ -158,10 +159,7 @@ func CreateProcessComponents(args ArgsProcessComponentsHolder) (*processComponen return nil, err } - whiteListerVerifiedTxs, err := disabled.NewDisabledWhiteListDataVerifier() - if err != nil { - return nil, err - } + whiteListerVerifiedTxs := nodeDisabled.NewDisabledWhiteListDataVerifier() historyRepository, err := historyRepositoryFactory.Create() if err != nil { From 6af2c883d1d4dc43adba6ad944fed8554d567aeb Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 19 Jun 2024 15:13:50 +0300 Subject: [PATCH 358/503] fix failing test --- integrationTests/chainSimulator/vm/esdtImprovements_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 6dffa745477..7c44ca6250c 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -2055,7 +2055,7 @@ func TestChainSimulator_NFT_RegisterDynamic(t *testing.T) { require.Equal(t, testsChainSimulator.OkReturnCode, result.ReturnCode) tokenType := result.ReturnData[1] - require.Equal(t, core.Dynamic+core.NonFungibleESDTv2, string(tokenType)) + require.Equal(t, core.DynamicNFTESDT, string(tokenType)) } func TestChainSimulator_MetaESDT_RegisterDynamic(t *testing.T) { From 4191a897f4e5e089c9c8f1bb88656177e32402b4 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 19 Jun 2024 15:20:24 +0300 Subject: [PATCH 359/503] fix after review --- integrationTests/multiShard/relayedTx/relayedTx_test.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/integrationTests/multiShard/relayedTx/relayedTx_test.go b/integrationTests/multiShard/relayedTx/relayedTx_test.go index cc3c2e8c0e6..d9ea772d7ba 100644 --- a/integrationTests/multiShard/relayedTx/relayedTx_test.go +++ b/integrationTests/multiShard/relayedTx/relayedTx_test.go @@ -447,11 +447,8 @@ func checkPlayerBalances( t *testing.T, nodes []*integrationTests.TestProcessorNode, players []*integrationTests.TestWalletAccount) { - for idx, player := range players { + for _, player := range players { userAcc := GetUserAccount(nodes, player.Address) - if idx == 5 { - print("x") - } assert.Equal(t, 0, userAcc.GetBalance().Cmp(player.Balance)) assert.Equal(t, userAcc.GetNonce(), player.Nonce) } From 1bd3721e527d5dfc4c5f58400eef04fcb13ff64b Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Wed, 19 Jun 2024 15:21:36 +0300 Subject: [PATCH 360/503] fix after review --- .../vm/esdtImprovements_test.go | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index f55ea07e4bc..3600f8b60b9 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -1992,14 +1992,14 @@ func TestChainSimulator_SFTcreatedBeforeSaveToSystemAccountEnabled(t *testing.T) log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) - nftMetaData := txsFee.GetDefaultMetaData() - nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + metaData := txsFee.GetDefaultMetaData() + metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - createTokenUpdateTokenIDAndTransfer(t, cs, addrs[0].Bytes, addrs[1].Bytes, sftTokenID, nftMetaData, epochForDynamicNFT, addrs[0]) + createTokenUpdateTokenIDAndTransfer(t, cs, addrs[0].Bytes, addrs[1].Bytes, sftTokenID, metaData, epochForDynamicNFT, addrs[0]) shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, metaData) checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, sftTokenID, shardID) checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, sftTokenID, shardID) } @@ -2028,14 +2028,14 @@ func TestChainSimulator_FungibleCreatedBeforeSaveToSystemAccountEnabled(t *testi log.Info("Issued FungibleESDT token id", "tokenID", string(funTokenID)) - nftMetaData := txsFee.GetDefaultMetaData() - nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + metaData := txsFee.GetDefaultMetaData() + metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - createTokenUpdateTokenIDAndTransfer(t, cs, addrs[0].Bytes, addrs[1].Bytes, funTokenID, nftMetaData, epochForDynamicNFT, addrs[0]) + createTokenUpdateTokenIDAndTransfer(t, cs, addrs[0].Bytes, addrs[1].Bytes, funTokenID, metaData, epochForDynamicNFT, addrs[0]) shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - checkMetaData(t, cs, core.SystemAccountAddress, funTokenID, shardID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, funTokenID, shardID, metaData) checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, funTokenID, shardID) checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, funTokenID, shardID) } @@ -2064,13 +2064,13 @@ func TestChainSimulator_MetaESDTCreatedBeforeSaveToSystemAccountEnabled(t *testi log.Info("Issued MetaESDT token id", "tokenID", string(metaTokenID)) - nftMetaData := txsFee.GetDefaultMetaData() - nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + metaData := txsFee.GetDefaultMetaData() + metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - createTokenUpdateTokenIDAndTransfer(t, cs, addrs[0].Bytes, addrs[1].Bytes, metaTokenID, nftMetaData, epochForDynamicNFT, addrs[0]) + createTokenUpdateTokenIDAndTransfer(t, cs, addrs[0].Bytes, addrs[1].Bytes, metaTokenID, metaData, epochForDynamicNFT, addrs[0]) shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - checkMetaData(t, cs, core.SystemAccountAddress, metaTokenID, shardID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, metaTokenID, shardID, metaData) checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, metaTokenID, shardID) checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, metaTokenID, shardID) } From fda1bfa6452eb3c247ce2074c8ca7a5e23f22711 Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 19 Jun 2024 15:31:26 +0300 Subject: [PATCH 361/503] latest vm common and indexer --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 786caa073f5..1b381e3a86f 100644 --- a/go.mod +++ b/go.mod @@ -17,11 +17,11 @@ require ( github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e github.com/multiversx/mx-chain-core-go v1.2.21-0.20240530111258-45870512bfbe github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df - github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619060917-731bddac4821 + github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619122842-05143459c554 github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f - github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240618133316-4c17adfcaea6 + github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240619122724-2bd2e64cebdc github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240509104009-598a37ff36b9 diff --git a/go.sum b/go.sum index 47c61e5e62d..f7cc76137bf 100644 --- a/go.sum +++ b/go.sum @@ -391,16 +391,16 @@ github.com/multiversx/mx-chain-core-go v1.2.21-0.20240530111258-45870512bfbe h1: github.com/multiversx/mx-chain-core-go v1.2.21-0.20240530111258-45870512bfbe/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.20240619060917-731bddac4821 h1:rB5XbWMILQJLH1GmsXjdfE28+k1cvovyP0/M77jrcs4= -github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619060917-731bddac4821/go.mod h1:Phf/QUo+JG6aoyUrktqPKg6exkj+Uz2kT5a8Tiyises= +github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619122842-05143459c554 h1:Fv8BfzJSzdovmoh9Jh/by++0uGsOVBlMP3XiN5Svkn4= +github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619122842-05143459c554/go.mod h1:yMq9q5VdN7jBaErRGQ0T8dkZwbBtfQYmqGbD/Ese1us= 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.20240618133316-4c17adfcaea6 h1:416tIBSfXoXuA15BUVY53m84LVZysVFz0M4yuw2kKh4= -github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240618133316-4c17adfcaea6/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo= +github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240619122724-2bd2e64cebdc h1:KpLloX0pIclo3axCQVOm3wZE+U9cfeHgPWGvDuUohTk= +github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240619122724-2bd2e64cebdc/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= From c4870673381010cff84e395a1932bf8bf440fa39 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 19 Jun 2024 15:56:16 +0300 Subject: [PATCH 362/503] gasScheduleV8 --- cmd/node/config/enableEpochs.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index dce2d48be2c..eb391d8df1e 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -329,5 +329,6 @@ [GasSchedule] # GasScheduleByEpochs holds the configuration for the gas schedule that will be applied from specific epochs GasScheduleByEpochs = [ - { StartEpoch = 0, FileName = "gasScheduleV8.toml" }, + { StartEpoch = 0, FileName = "gasScheduleV7.toml" }, + { StartEpoch = 3, FileName = "gasScheduleV8.toml" }, ] From 2052fc290bb610362c55773f859c3235ff11d79f Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 19 Jun 2024 16:26:38 +0300 Subject: [PATCH 363/503] fix after merge --- integrationTests/chainSimulator/relayedTx/relayedTx_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index e104035d6c1..c809e562f89 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -263,7 +263,7 @@ func startChainSimulator(t *testing.T) testsChainSimulator.ChainSimulator { } cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, From 9526bb8db3c537dbfbbb8025bc6733aaf9eea7c4 Mon Sep 17 00:00:00 2001 From: miiu Date: Thu, 20 Jun 2024 10:23:41 +0300 Subject: [PATCH 364/503] extra checks --- integrationTests/chainSimulator/vm/esdtImprovements_test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 3f781858792..01b99d1bc23 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -999,6 +999,7 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(address.Bytes) checkMetaData(t, cs, address.Bytes, nftTokenID, shardID, nftMetaData) + require.Equal(t, core.ESDTMetaDataRecreate, txResult.Logs.Events[0].Identifier) } // Test scenario #5 @@ -1134,6 +1135,7 @@ func TestChainSimulator_NFT_ESDTMetaDataUpdate(t *testing.T) { shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(address.Bytes) checkMetaData(t, cs, address.Bytes, nftTokenID, shardID, nftMetaData) + require.Equal(t, core.ESDTMetaDataUpdate, txResult.Logs.Events[0].Identifier) } // Test scenario #6 @@ -1283,6 +1285,7 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, sft, shardID) require.Equal(t, newCreatorAddress.Bytes, retrievedMetaData.Creator) + require.Equal(t, core.ESDTModifyCreator, txResult.Logs.Events[0].Identifier) } // Test scenario #7 @@ -1428,6 +1431,7 @@ func TestChainSimulator_NFT_ESDTSetNewURIs(t *testing.T) { retrievedMetaData := getMetaDataFromAcc(t, cs, address.Bytes, nftTokenID, shardID) require.Equal(t, expUris, retrievedMetaData.URIs) + require.Equal(t, core.ESDTSetNewURIs, txResult.Logs.Events[0].Identifier) } // Test scenario #8 @@ -1561,6 +1565,7 @@ func TestChainSimulator_NFT_ESDTModifyRoyalties(t *testing.T) { retrievedMetaData := getMetaDataFromAcc(t, cs, address.Bytes, nftTokenID, shardID) require.Equal(t, uint32(big.NewInt(20).Uint64()), retrievedMetaData.Royalties) + require.Equal(t, core.ESDTModifyRoyalties, txResult.Logs.Events[0].Identifier) } // Test scenario #9 From c5cedb681edbf55f2bbefd3f0b66729b1dd8c9c5 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Thu, 20 Jun 2024 10:47:30 +0300 Subject: [PATCH 365/503] fix after merge --- integrationTests/chainSimulator/vm/esdtImprovements_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 1f663a70e69..0e31eda7eeb 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -2088,7 +2088,7 @@ func getTestChainSimulatorWithSaveToSystemAccountDisabled(t *testing.T, baseIssu numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: numOfShards, From 4ba631fcbc7994b303ba3540218d72e8f2061891 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 20 Jun 2024 11:20:02 +0300 Subject: [PATCH 366/503] added token type based on token nonce --- api/groups/addressGroup.go | 17 +++++- .../chainSimulator/vm/esdtTokens_test.go | 52 +++++++++---------- 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/api/groups/addressGroup.go b/api/groups/addressGroup.go index 9d1e182cdbe..a60d79b0047 100644 --- a/api/groups/addressGroup.go +++ b/api/groups/addressGroup.go @@ -487,9 +487,10 @@ func buildTokenDataApiResponse(tokenIdentifier string, esdtData *esdt.ESDigitalT tokenData := &ESDTNFTTokenData{ TokenIdentifier: tokenIdentifier, Balance: esdtData.Value.String(), - Type: core.ESDTType(esdtData.GetType()).String(), Properties: hex.EncodeToString(esdtData.Properties), } + + tokenType := core.ESDTType(esdtData.Type).String() if esdtData.TokenMetaData != nil { tokenData.Name = string(esdtData.TokenMetaData.Name) tokenData.Nonce = esdtData.TokenMetaData.Nonce @@ -498,11 +499,25 @@ func buildTokenDataApiResponse(tokenIdentifier string, esdtData *esdt.ESDigitalT tokenData.Hash = esdtData.TokenMetaData.Hash tokenData.URIs = esdtData.TokenMetaData.URIs tokenData.Attributes = esdtData.TokenMetaData.Attributes + + tokenType = getTokenType(esdtData.GetType(), tokenData.Nonce) } + tokenData.Type = tokenType + return tokenData } +func getTokenType(tokenType uint32, tokenNonce uint64) string { + isNotFungible := tokenNonce != 0 + tokenTypeNotSet := isNotFungible && core.ESDTType(tokenType) == core.Fungible + if tokenTypeNotSet { + return "" + } + + return core.ESDTType(tokenType).String() +} + func (ag *addressGroup) getFacade() addressFacadeHandler { ag.mutFacade.RLock() defer ag.mutFacade.RUnlock() diff --git a/integrationTests/chainSimulator/vm/esdtTokens_test.go b/integrationTests/chainSimulator/vm/esdtTokens_test.go index c80615cf9e0..f52936f3418 100644 --- a/integrationTests/chainSimulator/vm/esdtTokens_test.go +++ b/integrationTests/chainSimulator/vm/esdtTokens_test.go @@ -46,20 +46,18 @@ func TestChainSimulator_Api_TokenType(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewFreePortAPIConfigurator("localhost"), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, + BypassTxSignatureCheck: true, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewFreePortAPIConfigurator("localhost"), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost @@ -213,20 +211,18 @@ func TestChainSimulator_Api_NFTToken(t *testing.T) { numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewFreePortAPIConfigurator("localhost"), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - ConsensusGroupSize: 1, - MetaChainConsensusGroupSize: 1, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, + BypassTxSignatureCheck: true, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewFreePortAPIConfigurator("localhost"), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, AlterConfigsFunction: func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost From e2327ed0f4026f4013ad096b9a19a0f1a0a844d2 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 20 Jun 2024 11:26:23 +0300 Subject: [PATCH 367/503] fix linter issues --- integrationTests/chainSimulator/vm/esdtTokens_test.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtTokens_test.go b/integrationTests/chainSimulator/vm/esdtTokens_test.go index f52936f3418..f3516333558 100644 --- a/integrationTests/chainSimulator/vm/esdtTokens_test.go +++ b/integrationTests/chainSimulator/vm/esdtTokens_test.go @@ -68,9 +68,6 @@ func TestChainSimulator_Api_TokenType(t *testing.T) { defer cs.Close() - mintValue := big.NewInt(10) - mintValue = mintValue.Mul(oneEGLD, mintValue) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) require.Nil(t, err) @@ -233,9 +230,6 @@ func TestChainSimulator_Api_NFTToken(t *testing.T) { defer cs.Close() - mintValue := big.NewInt(10) - mintValue = mintValue.Mul(oneEGLD, mintValue) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch) - 1) require.Nil(t, err) @@ -383,6 +377,7 @@ func doHTTPClientGetReq(t *testing.T, url string, response interface{}) { httpClient := &http.Client{} req, err := http.NewRequest(http.MethodGet, url, nil) + require.Nil(t, err) resp, err := httpClient.Do(req) require.Nil(t, err) From 6ddee65f5f1fbe5165daaec78e641558cc769686 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 20 Jun 2024 13:02:05 +0300 Subject: [PATCH 368/503] changed default type check to non fungible --- api/groups/addressGroup.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/groups/addressGroup.go b/api/groups/addressGroup.go index a60d79b0047..151b7f53372 100644 --- a/api/groups/addressGroup.go +++ b/api/groups/addressGroup.go @@ -510,7 +510,7 @@ func buildTokenDataApiResponse(tokenIdentifier string, esdtData *esdt.ESDigitalT func getTokenType(tokenType uint32, tokenNonce uint64) string { isNotFungible := tokenNonce != 0 - tokenTypeNotSet := isNotFungible && core.ESDTType(tokenType) == core.Fungible + tokenTypeNotSet := isNotFungible && core.ESDTType(tokenType) == core.NonFungible if tokenTypeNotSet { return "" } From 49397f8b2f917da466d67871715adffe7c090dc7 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 21 Jun 2024 14:12:50 +0300 Subject: [PATCH 369/503] proper fix for relayed base cost + renamed FixRelayedMoveBalanceFlag to FixRelayedBaseCostFlag --- cmd/node/config/enableEpochs.toml | 4 +-- common/constants.go | 6 ++--- common/enablers/enableEpochsHandler.go | 6 ++--- common/enablers/enableEpochsHandler_test.go | 6 ++--- config/epochConfig.go | 4 +-- config/tomlConfig_test.go | 8 +++--- .../relayedTx/relayedTx_test.go | 11 ++++---- .../multiShard/relayedTx/common.go | 2 +- integrationTests/testProcessorNode.go | 2 +- .../multiShard/relayedMoveBalance_test.go | 18 ++++++------- .../vm/txsFee/relayedBuiltInFunctions_test.go | 18 ++++++------- .../vm/txsFee/relayedESDT_test.go | 4 +-- .../vm/txsFee/relayedScCalls_test.go | 6 ++--- .../vm/txsFee/relayedScDeploy_test.go | 8 +++--- node/metrics/metrics.go | 2 +- node/metrics/metrics_test.go | 8 +++--- process/transaction/baseProcess.go | 12 ++++----- process/transaction/metaProcess.go | 2 +- process/transaction/shardProcess.go | 26 ++++++++----------- process/transaction/shardProcess_test.go | 11 ++++---- sharding/mock/enableEpochsHandlerMock.go | 4 +-- 21 files changed, 82 insertions(+), 86 deletions(-) diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index 295d825e289..12ef3dc9f60 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -321,8 +321,8 @@ # RelayedTransactionsV3EnableEpoch represents the epoch when the relayed transactions V3 will be enabled RelayedTransactionsV3EnableEpoch = 7 - # FixRelayedMoveBalanceEnableEpoch represents the epoch when the fix for relayed for move balance will be enabled - FixRelayedMoveBalanceEnableEpoch = 7 + # FixRelayedBaseCostEnableEpoch represents the epoch when the fix for relayed base cost will be enabled + FixRelayedBaseCostEnableEpoch = 7 # BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers BLSMultiSignerEnableEpoch = [ diff --git a/common/constants.go b/common/constants.go index dc1c087a15f..ee46ec8a8f6 100644 --- a/common/constants.go +++ b/common/constants.go @@ -498,8 +498,8 @@ const ( // MetricRelayedTransactionsV3EnableEpoch represents the epoch when the relayed transactions v3 is enabled MetricRelayedTransactionsV3EnableEpoch = "erd_relayed_transactions_v3_enable_epoch" - // MetricFixRelayedMoveBalanceEnableEpoch represents the epoch when the fix for relayed move balance is enabled - MetricFixRelayedMoveBalanceEnableEpoch = "erd_fix_relayed_move_balance_enable_epoch" + // MetricFixRelayedBaseCostEnableEpoch represents the epoch when the fix for relayed base cost is enabled + MetricFixRelayedBaseCostEnableEpoch = "erd_fix_relayed_base_cost_enable_epoch" // MetricUnbondTokensV2EnableEpoch represents the epoch when the unbond tokens v2 is applied MetricUnbondTokensV2EnableEpoch = "erd_unbond_tokens_v2_enable_epoch" @@ -1227,6 +1227,6 @@ const ( EGLDInESDTMultiTransferFlag core.EnableEpochFlag = "EGLDInESDTMultiTransferFlag" CryptoOpcodesV2Flag core.EnableEpochFlag = "CryptoOpcodesV2Flag" RelayedTransactionsV3Flag core.EnableEpochFlag = "RelayedTransactionsV3Flag" - FixRelayedMoveBalanceFlag core.EnableEpochFlag = "FixRelayedMoveBalanceFlag" + FixRelayedBaseCostFlag core.EnableEpochFlag = "FixRelayedBaseCostFlag" // all new flags must be added to createAllFlagsMap method, as part of enableEpochsHandler allFlagsDefined ) diff --git a/common/enablers/enableEpochsHandler.go b/common/enablers/enableEpochsHandler.go index ecda650171c..4b7a3589770 100644 --- a/common/enablers/enableEpochsHandler.go +++ b/common/enablers/enableEpochsHandler.go @@ -756,11 +756,11 @@ func (handler *enableEpochsHandler) createAllFlagsMap() { }, activationEpoch: handler.enableEpochsConfig.RelayedTransactionsV3EnableEpoch, }, - common.FixRelayedMoveBalanceFlag: { + common.FixRelayedBaseCostFlag: { isActiveInEpoch: func(epoch uint32) bool { - return epoch >= handler.enableEpochsConfig.FixRelayedMoveBalanceEnableEpoch + return epoch >= handler.enableEpochsConfig.FixRelayedBaseCostEnableEpoch }, - activationEpoch: handler.enableEpochsConfig.FixRelayedMoveBalanceEnableEpoch, + activationEpoch: handler.enableEpochsConfig.FixRelayedBaseCostEnableEpoch, }, } } diff --git a/common/enablers/enableEpochsHandler_test.go b/common/enablers/enableEpochsHandler_test.go index 80fbc833dc5..ad1bf9d386d 100644 --- a/common/enablers/enableEpochsHandler_test.go +++ b/common/enablers/enableEpochsHandler_test.go @@ -120,7 +120,7 @@ func createEnableEpochsConfig() config.EnableEpochs { EGLDInMultiTransferEnableEpoch: 103, CryptoOpcodesV2EnableEpoch: 104, RelayedTransactionsV3EnableEpoch: 105, - FixRelayedMoveBalanceEnableEpoch: 106, + FixRelayedBaseCostEnableEpoch: 106, } } @@ -322,7 +322,7 @@ func TestEnableEpochsHandler_IsFlagEnabled(t *testing.T) { require.True(t, handler.IsFlagEnabled(common.AlwaysMergeContextsInEEIFlag)) require.True(t, handler.IsFlagEnabled(common.DynamicESDTFlag)) require.True(t, handler.IsFlagEnabled(common.RelayedTransactionsV3Flag)) - require.True(t, handler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag)) + require.True(t, handler.IsFlagEnabled(common.FixRelayedBaseCostFlag)) } func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) { @@ -443,7 +443,7 @@ func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) { require.Equal(t, cfg.EGLDInMultiTransferEnableEpoch, handler.GetActivationEpoch(common.EGLDInESDTMultiTransferFlag)) require.Equal(t, cfg.CryptoOpcodesV2EnableEpoch, handler.GetActivationEpoch(common.CryptoOpcodesV2Flag)) require.Equal(t, cfg.RelayedTransactionsV3EnableEpoch, handler.GetActivationEpoch(common.RelayedTransactionsV3Flag)) - require.Equal(t, cfg.FixRelayedMoveBalanceEnableEpoch, handler.GetActivationEpoch(common.FixRelayedMoveBalanceFlag)) + require.Equal(t, cfg.FixRelayedBaseCostEnableEpoch, handler.GetActivationEpoch(common.FixRelayedBaseCostFlag)) } func TestEnableEpochsHandler_IsInterfaceNil(t *testing.T) { diff --git a/config/epochConfig.go b/config/epochConfig.go index 4e835e62008..5005386fa1d 100644 --- a/config/epochConfig.go +++ b/config/epochConfig.go @@ -117,8 +117,8 @@ type EnableEpochs struct { DynamicESDTEnableEpoch uint32 EGLDInMultiTransferEnableEpoch uint32 CryptoOpcodesV2EnableEpoch uint32 - RelayedTransactionsV3EnableEpoch uint32 - FixRelayedMoveBalanceEnableEpoch uint32 + RelayedTransactionsV3EnableEpoch uint32 + FixRelayedBaseCostEnableEpoch uint32 BLSMultiSignerEnableEpoch []MultiSignerConfig } diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index d64bcb922a3..554066dfb16 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -875,8 +875,8 @@ func TestEnableEpochConfig(t *testing.T) { # RelayedTransactionsV3EnableEpoch represents the epoch when the relayed transactions V3 will be enabled RelayedTransactionsV3EnableEpoch = 99 - # FixRelayedMoveBalanceEnableEpoch represents the epoch when the fix for relayed for move balance will be enabled - FixRelayedMoveBalanceEnableEpoch = 100 + # FixRelayedBaseCostEnableEpoch represents the epoch when the fix for relayed base cost will be enabled + FixRelayedBaseCostEnableEpoch = 100 # MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MaxNodesChangeEnableEpoch = [ @@ -994,8 +994,8 @@ func TestEnableEpochConfig(t *testing.T) { DynamicESDTEnableEpoch: 96, EGLDInMultiTransferEnableEpoch: 97, CryptoOpcodesV2EnableEpoch: 98, - RelayedTransactionsV3EnableEpoch: 99, - FixRelayedMoveBalanceEnableEpoch: 100, + RelayedTransactionsV3EnableEpoch: 99, + FixRelayedBaseCostEnableEpoch: 100, MaxNodesChangeEnableEpoch: []MaxNodesChangeConfig{ { EpochEnable: 44, diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index e2c5422b62b..38e5f56f806 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -38,7 +38,7 @@ var ( oneEGLD = big.NewInt(1000000000000000000) alterConfigsFuncRelayedV3EarlyActivation = func(cfg *config.Configs) { cfg.EpochConfig.EnableEpochs.RelayedTransactionsV3EnableEpoch = 1 - cfg.EpochConfig.EnableEpochs.FixRelayedMoveBalanceEnableEpoch = 1 + cfg.EpochConfig.EnableEpochs.FixRelayedBaseCostEnableEpoch = 1 } ) @@ -268,8 +268,9 @@ func TestFixRelayedMoveBalanceWithChainSimulator(t *testing.T) { t.Skip("this is not a short test") } - expectedFeeScCall := "815285920000000" - t.Run("sc call", testFixRelayedMoveBalanceWithChainSimulatorScCall(expectedFeeScCall, expectedFeeScCall)) + expectedFeeScCallBefore := "815285920000000" + expectedFeeScCallAfter := "873695920000000" + t.Run("sc call", testFixRelayedMoveBalanceWithChainSimulatorScCall(expectedFeeScCallBefore, expectedFeeScCallAfter)) expectedFeeMoveBalanceBefore := "797500000000000" // 498 * 1500 + 50000 + 5000 expectedFeeMoveBalanceAfter := "847000000000000" // 498 * 1500 + 50000 + 50000 @@ -285,7 +286,7 @@ func testFixRelayedMoveBalanceWithChainSimulatorScCall( providedActivationEpoch := uint32(7) alterConfigsFunc := func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.FixRelayedMoveBalanceEnableEpoch = providedActivationEpoch + cfg.EpochConfig.EnableEpochs.FixRelayedBaseCostEnableEpoch = providedActivationEpoch } cs := startChainSimulator(t, alterConfigsFunc) @@ -386,7 +387,7 @@ func testFixRelayedMoveBalanceWithChainSimulatorMoveBalance( providedActivationEpoch := uint32(5) alterConfigsFunc := func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.FixRelayedMoveBalanceEnableEpoch = providedActivationEpoch + cfg.EpochConfig.EnableEpochs.FixRelayedBaseCostEnableEpoch = providedActivationEpoch } cs := startChainSimulator(t, alterConfigsFunc) diff --git a/integrationTests/multiShard/relayedTx/common.go b/integrationTests/multiShard/relayedTx/common.go index 037fb79138f..c2bc8e5995c 100644 --- a/integrationTests/multiShard/relayedTx/common.go +++ b/integrationTests/multiShard/relayedTx/common.go @@ -20,7 +20,7 @@ func CreateGeneralSetupForRelayTxTest(relayedV3Test bool) ([]*integrationTests.T epochsConfig := integrationTests.GetDefaultEnableEpochsConfig() if !relayedV3Test { epochsConfig.RelayedTransactionsV3EnableEpoch = integrationTests.UnreachableEpoch - epochsConfig.FixRelayedMoveBalanceEnableEpoch = integrationTests.UnreachableEpoch + epochsConfig.FixRelayedBaseCostEnableEpoch = integrationTests.UnreachableEpoch } nodes, idxProposers := createAndMintNodes(initialVal, epochsConfig) diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index 49b3960409c..cbd0f65b2c6 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -3274,7 +3274,7 @@ func CreateEnableEpochsConfig() config.EnableEpochs { RefactorPeersMiniBlocksEnableEpoch: UnreachableEpoch, SCProcessorV2EnableEpoch: UnreachableEpoch, RelayedTransactionsV3EnableEpoch: UnreachableEpoch, - FixRelayedMoveBalanceEnableEpoch: UnreachableEpoch, + FixRelayedBaseCostEnableEpoch: UnreachableEpoch, } } diff --git a/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go b/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go index 4d0c9861ec9..db9029e03f7 100644 --- a/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go +++ b/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go @@ -145,13 +145,13 @@ func TestRelayedMoveBalanceExecuteOnSourceAndDestination(t *testing.T) { func testRelayedMoveBalanceExecuteOnSourceAndDestination(relayedFixActivationEpoch uint32) func(t *testing.T) { return func(t *testing.T) { testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{ - FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, }) require.Nil(t, err) defer testContextSource.Close() testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ - FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, }) require.Nil(t, err) defer testContextDst.Close() @@ -226,13 +226,13 @@ func TestRelayedMoveBalanceExecuteOnSourceAndDestinationRelayerAndInnerTxSenderS func testRelayedMoveBalanceExecuteOnSourceAndDestinationRelayerAndInnerTxSenderShard0InnerTxReceiverShard1ShouldWork(relayedFixActivationEpoch uint32) func(t *testing.T) { return func(t *testing.T) { testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{ - FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, }) require.Nil(t, err) defer testContextSource.Close() testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ - FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, }) require.Nil(t, err) defer testContextDst.Close() @@ -303,13 +303,13 @@ func TestRelayedMoveBalanceRelayerAndInnerTxReceiverShard0SenderShard1(t *testin func testRelayedMoveBalanceRelayerAndInnerTxReceiverShard0SenderShard1(relayedFixActivationEpoch uint32) func(t *testing.T) { return func(t *testing.T) { testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{ - FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, }) require.Nil(t, err) defer testContextSource.Close() testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ - FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, }) require.Nil(t, err) defer testContextDst.Close() @@ -392,19 +392,19 @@ func TestMoveBalanceRelayerShard0InnerTxSenderShard1InnerTxReceiverShard2ShouldW func testMoveBalanceRelayerShard0InnerTxSenderShard1InnerTxReceiverShard2ShouldWork(relayedFixActivationEpoch uint32) func(t *testing.T) { return func(t *testing.T) { testContextRelayer, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{ - FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, }) require.Nil(t, err) defer testContextRelayer.Close() testContextInnerSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ - FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, }) require.Nil(t, err) defer testContextInnerSource.Close() testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{ - FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, }) require.Nil(t, err) defer testContextDst.Close() diff --git a/integrationTests/vm/txsFee/relayedBuiltInFunctions_test.go b/integrationTests/vm/txsFee/relayedBuiltInFunctions_test.go index 273ad3549d2..d9b71e9cc1d 100644 --- a/integrationTests/vm/txsFee/relayedBuiltInFunctions_test.go +++ b/integrationTests/vm/txsFee/relayedBuiltInFunctions_test.go @@ -28,8 +28,8 @@ func testRelayedBuildInFunctionChangeOwnerCallShouldWork(relayedFixActivationEpo return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs( config.EnableEpochs{ - PenalizedTooMuchGasEnableEpoch: integrationTests.UnreachableEpoch, - FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + PenalizedTooMuchGasEnableEpoch: integrationTests.UnreachableEpoch, + FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, }) require.Nil(t, err) defer testContext.Close() @@ -63,8 +63,8 @@ func testRelayedBuildInFunctionChangeOwnerCallShouldWork(relayedFixActivationEpo expectedBalanceRelayer := big.NewInt(16610) vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) - expectedBalance := big.NewInt(9988100) - vm.TestAccount(t, testContext.Accounts, owner, 2, expectedBalance) + expectedBalance := big.NewInt(9988100) + vm.TestAccount(t, testContext.Accounts, owner, 2, expectedBalance) // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() @@ -87,7 +87,7 @@ func TestRelayedBuildInFunctionChangeOwnerCallWrongOwnerShouldConsumeGas(t *test func testRelayedBuildInFunctionChangeOwnerCallWrongOwnerShouldConsumeGas(relayedFixActivationEpoch uint32) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ - FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, }) require.Nil(t, err) defer testContext.Close() @@ -190,15 +190,15 @@ func TestRelayedBuildInFunctionChangeOwnerCallInsufficientGasLimitShouldConsumeG t.Run("nonce fix is disabled, should increase the sender's nonce", func(t *testing.T) { testRelayedBuildInFunctionChangeOwnerCallInsufficientGasLimitShouldConsumeGas(t, config.EnableEpochs{ - RelayedNonceFixEnableEpoch: 1000, - FixRelayedMoveBalanceEnableEpoch: 1000, + RelayedNonceFixEnableEpoch: 1000, + FixRelayedBaseCostEnableEpoch: 1000, }) }) t.Run("nonce fix is enabled, should still increase the sender's nonce", func(t *testing.T) { testRelayedBuildInFunctionChangeOwnerCallInsufficientGasLimitShouldConsumeGas(t, config.EnableEpochs{ - RelayedNonceFixEnableEpoch: 0, - FixRelayedMoveBalanceEnableEpoch: 1000, + RelayedNonceFixEnableEpoch: 0, + FixRelayedBaseCostEnableEpoch: 1000, }) }) } diff --git a/integrationTests/vm/txsFee/relayedESDT_test.go b/integrationTests/vm/txsFee/relayedESDT_test.go index b1e9cc19ee4..04571b8fb23 100644 --- a/integrationTests/vm/txsFee/relayedESDT_test.go +++ b/integrationTests/vm/txsFee/relayedESDT_test.go @@ -24,7 +24,7 @@ func TestRelayedESDTTransferShouldWork(t *testing.T) { func testRelayedESDTTransferShouldWork(relayedFixActivationEpoch uint32) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ - FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, }) require.Nil(t, err) defer testContext.Close() @@ -82,7 +82,7 @@ func TestRelayedESTTransferNotEnoughESTValueShouldConsumeGas(t *testing.T) { func testRelayedESTTransferNotEnoughESTValueShouldConsumeGas(relayedFixActivationEpoch uint32) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ - FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, }) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/relayedScCalls_test.go b/integrationTests/vm/txsFee/relayedScCalls_test.go index ec737526453..50e13d4b7c4 100644 --- a/integrationTests/vm/txsFee/relayedScCalls_test.go +++ b/integrationTests/vm/txsFee/relayedScCalls_test.go @@ -27,7 +27,7 @@ func testRelayedScCallShouldWork(relayedFixActivationEpoch uint32) func(t *testi return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, - FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, }) require.Nil(t, err) defer testContext.Close() @@ -82,7 +82,7 @@ func TestRelayedScCallContractNotFoundShouldConsumeGas(t *testing.T) { func testRelayedScCallContractNotFoundShouldConsumeGas(relayedFixActivationEpoch uint32) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ - FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, }) require.Nil(t, err) defer testContext.Close() @@ -186,7 +186,7 @@ func TestRelayedScCallInsufficientGasLimitShouldConsumeGas(t *testing.T) { func testRelayedScCallInsufficientGasLimitShouldConsumeGas(relayedFixActivationEpoch uint32, expectedBalance *big.Int, expectedAccumulatedFees *big.Int) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ - FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, }) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/relayedScDeploy_test.go b/integrationTests/vm/txsFee/relayedScDeploy_test.go index 6c33afe8c44..1a45e2c8760 100644 --- a/integrationTests/vm/txsFee/relayedScDeploy_test.go +++ b/integrationTests/vm/txsFee/relayedScDeploy_test.go @@ -24,7 +24,7 @@ func TestRelayedScDeployShouldWork(t *testing.T) { func testRelayedScDeployShouldWork(relayedFixActivationEpoch uint32) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ - FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, }) require.Nil(t, err) defer testContext.Close() @@ -77,7 +77,7 @@ func TestRelayedScDeployInvalidCodeShouldConsumeGas(t *testing.T) { func testRelayedScDeployInvalidCodeShouldConsumeGas(relayedFixActivationEpoch uint32, expectedBalance *big.Int, expectedAccumulatedFees *big.Int) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ - FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, }) require.Nil(t, err) defer testContext.Close() @@ -130,7 +130,7 @@ func TestRelayedScDeployInsufficientGasLimitShouldConsumeGas(t *testing.T) { func testRelayedScDeployInsufficientGasLimitShouldConsumeGas(relayedFixActivationEpoch uint32, expectedBalance *big.Int, expectedAccumulatedFees *big.Int) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ - FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, }) require.Nil(t, err) defer testContext.Close() @@ -182,7 +182,7 @@ func TestRelayedScDeployOutOfGasShouldConsumeGas(t *testing.T) { func testRelayedScDeployOutOfGasShouldConsumeGas(relayedFixActivationEpoch uint32, expectedBalance *big.Int, expectedAccumulatedFees *big.Int) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ - FixRelayedMoveBalanceEnableEpoch: relayedFixActivationEpoch, + FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, }) require.Nil(t, err) defer testContext.Close() diff --git a/node/metrics/metrics.go b/node/metrics/metrics.go index 92fc37bdecb..38c616e97f5 100644 --- a/node/metrics/metrics.go +++ b/node/metrics/metrics.go @@ -122,7 +122,7 @@ func InitConfigMetrics( appStatusHandler.SetUInt64Value(common.MetricSenderInOutTransferEnableEpoch, uint64(enableEpochs.SenderInOutTransferEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricRelayedTransactionsV2EnableEpoch, uint64(enableEpochs.RelayedTransactionsV2EnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricRelayedTransactionsV3EnableEpoch, uint64(enableEpochs.RelayedTransactionsV3EnableEpoch)) - appStatusHandler.SetUInt64Value(common.MetricFixRelayedMoveBalanceEnableEpoch, uint64(enableEpochs.FixRelayedMoveBalanceEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricFixRelayedBaseCostEnableEpoch, uint64(enableEpochs.FixRelayedBaseCostEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricUnbondTokensV2EnableEpoch, uint64(enableEpochs.UnbondTokensV2EnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricSaveJailedAlwaysEnableEpoch, uint64(enableEpochs.SaveJailedAlwaysEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricValidatorToDelegationEnableEpoch, uint64(enableEpochs.ValidatorToDelegationEnableEpoch)) diff --git a/node/metrics/metrics_test.go b/node/metrics/metrics_test.go index 964bc0cd70a..71c96ba7304 100644 --- a/node/metrics/metrics_test.go +++ b/node/metrics/metrics_test.go @@ -208,8 +208,8 @@ func TestInitConfigMetrics(t *testing.T) { EGLDInMultiTransferEnableEpoch: 101, CryptoOpcodesV2EnableEpoch: 102, ScToScLogEventEnableEpoch: 103, - RelayedTransactionsV3EnableEpoch: 104, - FixRelayedMoveBalanceEnableEpoch: 105, + RelayedTransactionsV3EnableEpoch: 104, + FixRelayedBaseCostEnableEpoch: 105, MaxNodesChangeEnableEpoch: []config.MaxNodesChangeConfig{ { EpochEnable: 0, @@ -328,8 +328,8 @@ func TestInitConfigMetrics(t *testing.T) { "erd_egld_in_multi_transfer_enable_epoch": uint32(101), "erd_crypto_opcodes_v2_enable_epoch": uint32(102), "erd_set_sc_to_sc_log_event_enable_epoch": uint32(103), - "erd_relayed_transactions_v3_enable_epoch": uint32(104), - "erd_fix_relayed_move_balance_enable_epoch": uint32(105), + "erd_relayed_transactions_v3_enable_epoch": uint32(104), + "erd_fix_relayed_base_cost_enable_epoch": uint32(105), "erd_max_nodes_change_enable_epoch": nil, "erd_total_supply": "12345", "erd_hysteresis": "0.100000", diff --git a/process/transaction/baseProcess.go b/process/transaction/baseProcess.go index a286bd9fb8f..cad051e59a0 100644 --- a/process/transaction/baseProcess.go +++ b/process/transaction/baseProcess.go @@ -147,9 +147,7 @@ func (txProc *baseTxProcessor) checkTxValues( return process.ErrNotEnoughGasInUserTx } - _, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(tx) - isMoveBalance := dstShardTxType == process.MoveBalance - txFee = txProc.computeTxFee(tx, isMoveBalance) + txFee = txProc.computeTxFee(tx) } else { txFee = txProc.economicsFee.ComputeTxFee(tx) } @@ -176,15 +174,15 @@ func (txProc *baseTxProcessor) checkTxValues( return nil } -func (txProc *baseTxProcessor) computeTxFee(tx *transaction.Transaction, isInnerTxMoveBalance bool) *big.Int { - if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) && isInnerTxMoveBalance { - return txProc.computeTxFeeAfterMoveBalanceFix(tx) +func (txProc *baseTxProcessor) computeTxFee(tx *transaction.Transaction) *big.Int { + if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedBaseCostFlag) { + return txProc.computeTxFeeAfterBaseCostFix(tx) } return txProc.economicsFee.ComputeFeeForProcessing(tx, tx.GasLimit) } -func (txProc *baseTxProcessor) computeTxFeeAfterMoveBalanceFix(tx *transaction.Transaction) *big.Int { +func (txProc *baseTxProcessor) computeTxFeeAfterBaseCostFix(tx *transaction.Transaction) *big.Int { moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(tx) gasToUse := tx.GetGasLimit() - moveBalanceGasLimit moveBalanceUserFee := txProc.economicsFee.ComputeMoveBalanceFee(tx) diff --git a/process/transaction/metaProcess.go b/process/transaction/metaProcess.go index 90aad3add00..13d6fd4715b 100644 --- a/process/transaction/metaProcess.go +++ b/process/transaction/metaProcess.go @@ -65,7 +65,7 @@ func NewMetaTxProcessor(args ArgsNewMetaTxProcessor) (*metaTxProcessor, error) { err := core.CheckHandlerCompatibility(args.EnableEpochsHandler, []core.EnableEpochFlag{ common.PenalizedTooMuchGasFlag, common.ESDTFlag, - common.FixRelayedMoveBalanceFlag, + common.FixRelayedBaseCostFlag, }) if err != nil { return nil, err diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 0a82b720c65..64a34500938 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -132,7 +132,7 @@ func NewTxProcessor(args ArgsNewTxProcessor) (*txProcessor, error) { common.RelayedTransactionsV2Flag, common.RelayedNonceFixFlag, common.RelayedTransactionsV3Flag, - common.FixRelayedMoveBalanceFlag, + common.FixRelayedBaseCostFlag, }) if err != nil { return nil, err @@ -400,8 +400,7 @@ func (txProc *txProcessor) processTxFee( } if isUserTxOfRelayed { - isUserTxMoveBalance := dstShardTxType == process.MoveBalance - totalCost := txProc.computeTxFee(tx, isUserTxMoveBalance) + totalCost := txProc.computeTxFee(tx) err := acntSnd.SubFromBalance(totalCost) if err != nil { @@ -744,9 +743,7 @@ func (txProc *txProcessor) processInnerTx( originalTxHash []byte, ) (*big.Int, vmcommon.ReturnCode, error) { - _, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(innerTx) - isMoveBalance := dstShardTxType == process.MoveBalance - txFee := txProc.computeTxFee(innerTx, isMoveBalance) + txFee := txProc.computeTxFee(innerTx) acntSnd, err := txProc.getAccountFromAddress(innerTx.SndAddr) if err != nil { @@ -865,10 +862,8 @@ func (txProc *txProcessor) processRelayedTx( func (txProc *txProcessor) computeRelayedTxFees(tx, userTx *transaction.Transaction) relayedFees { relayerFee := txProc.economicsFee.ComputeMoveBalanceFee(tx) totalFee := txProc.economicsFee.ComputeTxFee(tx) - _, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(userTx) - isMoveBalance := dstShardTxType == process.MoveBalance - if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) && isMoveBalance { - userFee := txProc.computeTxFeeAfterMoveBalanceFix(userTx) + if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedBaseCostFlag) { + userFee := txProc.computeTxFeeAfterBaseCostFix(userTx) totalFee = totalFee.Add(relayerFee, userFee) } @@ -902,9 +897,7 @@ func (txProc *txProcessor) removeValueAndConsumedFeeFromUser( return err } - _, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(userTx) - isMoveBalance := dstShardTxType == process.MoveBalance - consumedFee := txProc.computeTxFee(userTx, isMoveBalance) + consumedFee := txProc.computeTxFee(userTx) err = userAcnt.SubFromBalance(consumedFee) if err != nil { @@ -949,6 +942,9 @@ func (txProc *txProcessor) processMoveBalanceCostRelayedUserTx( ) error { moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(userTx) moveBalanceUserFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, moveBalanceGasLimit) + if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedBaseCostFlag) { + moveBalanceUserFee = txProc.economicsFee.ComputeMoveBalanceFee(userTx) + } userScrHash, err := core.CalculateHash(txProc.marshalizer, txProc.hasher, userScr) if err != nil { @@ -1164,14 +1160,14 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(userTx) gasToUse := userTx.GetGasLimit() - moveBalanceGasLimit processingUserFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, gasToUse) - if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) && isMoveBalance { + if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedBaseCostFlag) && isMoveBalance { moveBalanceUserFee := txProc.economicsFee.ComputeMoveBalanceFee(userTx) totalFee = big.NewInt(0).Add(moveBalanceUserFee, processingUserFee) } senderShardID := txProc.shardCoordinator.ComputeId(userTx.SndAddr) if senderShardID != txProc.shardCoordinator.SelfId() { - if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceFlag) && isMoveBalance { + if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedBaseCostFlag) && isMoveBalance { totalFee.Sub(totalFee, processingUserFee) } else { moveBalanceUserFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, moveBalanceGasLimit) diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index e753cd4a1ac..4c27d1b17ce 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -92,7 +92,7 @@ func createArgsForTxProcessor() txproc.ArgsNewTxProcessor { BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, ArgsParser: &mock.ArgumentParserMock{}, ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, - EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.PenalizedTooMuchGasFlag, common.FixRelayedMoveBalanceFlag), + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.PenalizedTooMuchGasFlag, common.FixRelayedBaseCostFlag), GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, TxVersionChecker: &testscommon.TxVersionCheckerStub{}, TxLogsProcessor: &mock.TxLogsProcessorStub{}, @@ -2238,7 +2238,7 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { args.TxTypeHandler = txTypeHandler args.PubkeyConv = pubKeyConverter args.ArgsParser = smartContract.NewArgumentParser() - args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV3Flag, common.FixRelayedMoveBalanceFlag) + args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV3Flag, common.FixRelayedBaseCostFlag) args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { return big.NewInt(1) @@ -2361,7 +2361,7 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { args.TxTypeHandler = txTypeHandler args.PubkeyConv = pubKeyConverter args.ArgsParser = smartContract.NewArgumentParser() - args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV3Flag, common.FixRelayedMoveBalanceFlag) + args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV3Flag, common.FixRelayedBaseCostFlag) args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { return big.NewInt(int64(tx.GetGasPrice() * tx.GetGasLimit())) @@ -2448,7 +2448,7 @@ func TestTxProcessor_ProcessRelayedTransactionV3(t *testing.T) { args.TxTypeHandler = txTypeHandler args.PubkeyConv = pubKeyConverter args.ArgsParser = smartContract.NewArgumentParser() - args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV3Flag, common.FixRelayedMoveBalanceFlag) + args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV3Flag, common.FixRelayedBaseCostFlag) increasingFee := big.NewInt(0) args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ ComputeMoveBalanceFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { @@ -2554,7 +2554,7 @@ func testProcessRelayedTransactionV3( args.TxTypeHandler = txTypeHandler args.PubkeyConv = pubKeyConverter args.ArgsParser = smartContract.NewArgumentParser() - args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV3Flag, common.FixRelayedMoveBalanceFlag) + args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV3Flag, common.FixRelayedBaseCostFlag) args.EconomicsFee = &economicsmocks.EconomicsHandlerMock{ ComputeTxFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { return big.NewInt(4) @@ -3204,6 +3204,7 @@ func TestTxProcessor_ConsumeMoveBalanceWithUserTx(t *testing.T) { t.Parallel() args := createArgsForTxProcessor() + args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub() args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ ComputeTxFeeCalled: func(tx data.TransactionWithFeeHandler) *big.Int { return big.NewInt(150) diff --git a/sharding/mock/enableEpochsHandlerMock.go b/sharding/mock/enableEpochsHandlerMock.go index 03c15cf8154..9a842f9adae 100644 --- a/sharding/mock/enableEpochsHandlerMock.go +++ b/sharding/mock/enableEpochsHandlerMock.go @@ -53,8 +53,8 @@ func (mock *EnableEpochsHandlerMock) IsRelayedTransactionsV3FlagEnabled() bool { return false } -// IsFixRelayedMoveBalanceFlagEnabled - -func (mock *EnableEpochsHandlerMock) IsFixRelayedMoveBalanceFlagEnabled() bool { +// IsFixRelayedBaseCostFlagEnabled - +func (mock *EnableEpochsHandlerMock) IsFixRelayedBaseCostFlagEnabled() bool { return false } From e019c78b0f578d5cba73465e3a65c90ef63d6779 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 21 Jun 2024 14:22:43 +0300 Subject: [PATCH 370/503] fix after review --- process/transaction/baseProcess.go | 4 ++-- process/transaction/shardProcess.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/process/transaction/baseProcess.go b/process/transaction/baseProcess.go index cad051e59a0..319a8a65b9e 100644 --- a/process/transaction/baseProcess.go +++ b/process/transaction/baseProcess.go @@ -147,7 +147,7 @@ func (txProc *baseTxProcessor) checkTxValues( return process.ErrNotEnoughGasInUserTx } - txFee = txProc.computeTxFee(tx) + txFee = txProc.computeTxFeeForRelayedTx(tx) } else { txFee = txProc.economicsFee.ComputeTxFee(tx) } @@ -174,7 +174,7 @@ func (txProc *baseTxProcessor) checkTxValues( return nil } -func (txProc *baseTxProcessor) computeTxFee(tx *transaction.Transaction) *big.Int { +func (txProc *baseTxProcessor) computeTxFeeForRelayedTx(tx *transaction.Transaction) *big.Int { if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedBaseCostFlag) { return txProc.computeTxFeeAfterBaseCostFix(tx) } diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 64a34500938..bf7d7554304 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -400,7 +400,7 @@ func (txProc *txProcessor) processTxFee( } if isUserTxOfRelayed { - totalCost := txProc.computeTxFee(tx) + totalCost := txProc.computeTxFeeForRelayedTx(tx) err := acntSnd.SubFromBalance(totalCost) if err != nil { @@ -743,7 +743,7 @@ func (txProc *txProcessor) processInnerTx( originalTxHash []byte, ) (*big.Int, vmcommon.ReturnCode, error) { - txFee := txProc.computeTxFee(innerTx) + txFee := txProc.computeTxFeeForRelayedTx(innerTx) acntSnd, err := txProc.getAccountFromAddress(innerTx.SndAddr) if err != nil { @@ -897,7 +897,7 @@ func (txProc *txProcessor) removeValueAndConsumedFeeFromUser( return err } - consumedFee := txProc.computeTxFee(userTx) + consumedFee := txProc.computeTxFeeForRelayedTx(userTx) err = userAcnt.SubFromBalance(consumedFee) if err != nil { From 51434d22331ea0c36fc3097705093240e453ee91 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 21 Jun 2024 15:55:44 +0300 Subject: [PATCH 371/503] fix after second review --- process/transaction/shardProcess.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index bf7d7554304..76791e895d2 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -1154,20 +1154,18 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( return err } - _, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(userTx) - isMoveBalance := dstShardTxType == process.MoveBalance totalFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, userTx.GasLimit) moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(userTx) gasToUse := userTx.GetGasLimit() - moveBalanceGasLimit processingUserFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, gasToUse) - if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedBaseCostFlag) && isMoveBalance { + if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedBaseCostFlag) { moveBalanceUserFee := txProc.economicsFee.ComputeMoveBalanceFee(userTx) totalFee = big.NewInt(0).Add(moveBalanceUserFee, processingUserFee) } senderShardID := txProc.shardCoordinator.ComputeId(userTx.SndAddr) if senderShardID != txProc.shardCoordinator.SelfId() { - if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedBaseCostFlag) && isMoveBalance { + if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedBaseCostFlag) { totalFee.Sub(totalFee, processingUserFee) } else { moveBalanceUserFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, moveBalanceGasLimit) From 4de9055ec3c9e4ab2ca68ea85756580ed1e4264a Mon Sep 17 00:00:00 2001 From: Daniel Drasovean Date: Fri, 21 Jun 2024 17:01:39 +0300 Subject: [PATCH 372/503] Added action for building keygenerator docker images --- .github/workflows/deploy-docker.yaml | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/deploy-docker.yaml diff --git a/.github/workflows/deploy-docker.yaml b/.github/workflows/deploy-docker.yaml new file mode 100644 index 00000000000..438da3ed406 --- /dev/null +++ b/.github/workflows/deploy-docker.yaml @@ -0,0 +1,40 @@ +env: + IMAGE_NODE: chain-keygenerator + REGISTRY_HOSTNAME: multiversx + +name: Build Docker image & push + +on: + workflow_dispatch: + pull_request: + +jobs: + build-docker-image: + strategy: + matrix: + runs-on: [ubuntu-latest] + runs-on: ${{ matrix.runs-on }} + + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + 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 }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push image to Docker Hub + id: push + uses: docker/build-push-action@v6 + with: + context: . + file: ./docker/keygenerator/Dockerfile + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ env.REGISTRY_HOSTNAME }}/${{ env.IMAGE_NODE }}:latest From be31480fe2616e460c1014a11568e71b2aa402c7 Mon Sep 17 00:00:00 2001 From: Daniel Drasovean Date: Fri, 21 Jun 2024 18:03:01 +0300 Subject: [PATCH 373/503] Refactor workflow --- .../{deploy-docker.yaml => docker-keygenerator.yaml} | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) rename .github/workflows/{deploy-docker.yaml => docker-keygenerator.yaml} (83%) diff --git a/.github/workflows/deploy-docker.yaml b/.github/workflows/docker-keygenerator.yaml similarity index 83% rename from .github/workflows/deploy-docker.yaml rename to .github/workflows/docker-keygenerator.yaml index 438da3ed406..5e4d9d44a32 100644 --- a/.github/workflows/deploy-docker.yaml +++ b/.github/workflows/docker-keygenerator.yaml @@ -1,8 +1,4 @@ -env: - IMAGE_NODE: chain-keygenerator - REGISTRY_HOSTNAME: multiversx - -name: Build Docker image & push +name: Build & push keygenerator docker image on: workflow_dispatch: @@ -37,4 +33,4 @@ jobs: file: ./docker/keygenerator/Dockerfile platforms: linux/amd64,linux/arm64 push: ${{ github.event_name != 'pull_request' }} - tags: ${{ env.REGISTRY_HOSTNAME }}/${{ env.IMAGE_NODE }}:latest + tags: multiversx/chain-keygenerator:latest From 7427db91f9b321e0d2b1fcb2f7a3027f5da4dd24 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 25 Jun 2024 09:41:28 +0300 Subject: [PATCH 374/503] compressed flags --- cmd/node/config/enableEpochs.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index eb391d8df1e..dce2d48be2c 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -329,6 +329,5 @@ [GasSchedule] # GasScheduleByEpochs holds the configuration for the gas schedule that will be applied from specific epochs GasScheduleByEpochs = [ - { StartEpoch = 0, FileName = "gasScheduleV7.toml" }, - { StartEpoch = 3, FileName = "gasScheduleV8.toml" }, + { StartEpoch = 0, FileName = "gasScheduleV8.toml" }, ] From fb89c15755dbc163497c3a56538cc0b1e649d54a Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 25 Jun 2024 14:57:27 +0300 Subject: [PATCH 375/503] fixed processTxFee for inner tx after base cost fix --- process/transaction/shardProcess.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 76791e895d2..90a390eb63b 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -413,6 +413,10 @@ func (txProc *txProcessor) processTxFee( moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(tx) currentShardFee := txProc.economicsFee.ComputeFeeForProcessing(tx, moveBalanceGasLimit) + if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedBaseCostFlag) { + currentShardFee = txProc.economicsFee.ComputeMoveBalanceFee(tx) + } + return currentShardFee, totalCost, nil } From 116f2b6a2acef23d80996c4f772cf36d36802b2e Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 25 Jun 2024 16:24:39 +0300 Subject: [PATCH 376/503] further fixes on inner tx fee --- integrationTests/vm/txsFee/dns_test.go | 4 ++- .../vm/txsFee/guardAccount_test.go | 1 + .../multiShard/relayedMoveBalance_test.go | 36 ++++++++++--------- .../vm/txsFee/relayedMoveBalance_test.go | 11 ++++-- process/transaction/baseProcess.go | 13 ++++--- process/transaction/shardProcess.go | 8 ++--- 6 files changed, 44 insertions(+), 29 deletions(-) diff --git a/integrationTests/vm/txsFee/dns_test.go b/integrationTests/vm/txsFee/dns_test.go index 0ff3914d7a0..1b1b345ec05 100644 --- a/integrationTests/vm/txsFee/dns_test.go +++ b/integrationTests/vm/txsFee/dns_test.go @@ -200,7 +200,9 @@ func TestDeployDNSContract_TestGasWhenSaveUsernameAfterDNSv2IsActivated(t *testi t.Skip("this is not a short test") } - testContextForDNSContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) + testContextForDNSContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ + FixRelayedBaseCostEnableEpoch: integrationTests.UnreachableEpoch, + }) require.Nil(t, err) defer testContextForDNSContract.Close() diff --git a/integrationTests/vm/txsFee/guardAccount_test.go b/integrationTests/vm/txsFee/guardAccount_test.go index bef70420427..c8e10d8c229 100644 --- a/integrationTests/vm/txsFee/guardAccount_test.go +++ b/integrationTests/vm/txsFee/guardAccount_test.go @@ -97,6 +97,7 @@ func prepareTestContextForGuardedAccounts(tb testing.TB) *vm.VMTestContext { GovernanceEnableEpoch: unreachableEpoch, SetSenderInEeiOutputTransferEnableEpoch: unreachableEpoch, RefactorPeersMiniBlocksEnableEpoch: unreachableEpoch, + FixRelayedBaseCostEnableEpoch: unreachableEpoch, }, testscommon.NewMultiShardsCoordinatorMock(2), db, diff --git a/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go b/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go index db9029e03f7..b9d4078cfa9 100644 --- a/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go +++ b/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go @@ -20,14 +20,13 @@ func TestRelayedMoveBalanceRelayerShard0InnerTxSenderAndReceiverShard1ShouldWork t.Skip("this is not a short test") } - t.Run("before relayed move balance fix", testRelayedMoveBalanceRelayerShard0InnerTxSenderAndReceiverShard1ShouldWork(integrationTests.UnreachableEpoch)) - t.Run("after relayed move balance fix", testRelayedMoveBalanceRelayerShard0InnerTxSenderAndReceiverShard1ShouldWork(0)) + t.Run("before relayed base cost fix", testRelayedMoveBalanceRelayerShard0InnerTxSenderAndReceiverShard1ShouldWork(integrationTests.UnreachableEpoch)) } func testRelayedMoveBalanceRelayerShard0InnerTxSenderAndReceiverShard1ShouldWork(relayedFixActivationEpoch uint32) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ - RelayedNonceFixEnableEpoch: relayedFixActivationEpoch, + FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, }) require.Nil(t, err) defer testContext.Close() @@ -80,14 +79,13 @@ func TestRelayedMoveBalanceRelayerAndInnerTxSenderShard0ReceiverShard1(t *testin t.Skip("this is not a short test") } - t.Run("before relayed move balance fix", testRelayedMoveBalanceRelayerAndInnerTxSenderShard0ReceiverShard1(integrationTests.UnreachableEpoch)) - t.Run("after relayed move balance fix", testRelayedMoveBalanceRelayerAndInnerTxSenderShard0ReceiverShard1(0)) + t.Run("before relayed base cost fix", testRelayedMoveBalanceRelayerAndInnerTxSenderShard0ReceiverShard1(integrationTests.UnreachableEpoch)) } func testRelayedMoveBalanceRelayerAndInnerTxSenderShard0ReceiverShard1(relayedFixActivationEpoch uint32) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ - RelayedNonceFixEnableEpoch: relayedFixActivationEpoch, + FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, }) require.Nil(t, err) defer testContext.Close() @@ -138,8 +136,7 @@ func TestRelayedMoveBalanceExecuteOnSourceAndDestination(t *testing.T) { t.Skip("this is not a short test") } - t.Run("before relayed move balance fix", testRelayedMoveBalanceExecuteOnSourceAndDestination(integrationTests.UnreachableEpoch)) - t.Run("after relayed move balance fix", testRelayedMoveBalanceExecuteOnSourceAndDestination(0)) + t.Run("before relayed base cost fix", testRelayedMoveBalanceExecuteOnSourceAndDestination(integrationTests.UnreachableEpoch)) } func testRelayedMoveBalanceExecuteOnSourceAndDestination(relayedFixActivationEpoch uint32) func(t *testing.T) { @@ -219,8 +216,8 @@ func TestRelayedMoveBalanceExecuteOnSourceAndDestinationRelayerAndInnerTxSenderS t.Skip("this is not a short test") } - t.Run("before relayed move balance fix", testRelayedMoveBalanceExecuteOnSourceAndDestinationRelayerAndInnerTxSenderShard0InnerTxReceiverShard1ShouldWork(integrationTests.UnreachableEpoch)) - t.Run("after relayed move balance fix", testRelayedMoveBalanceExecuteOnSourceAndDestinationRelayerAndInnerTxSenderShard0InnerTxReceiverShard1ShouldWork(0)) + t.Run("before relayed base cost fix", testRelayedMoveBalanceExecuteOnSourceAndDestinationRelayerAndInnerTxSenderShard0InnerTxReceiverShard1ShouldWork(integrationTests.UnreachableEpoch)) + t.Run("after relayed base cost fix", testRelayedMoveBalanceExecuteOnSourceAndDestinationRelayerAndInnerTxSenderShard0InnerTxReceiverShard1ShouldWork(0)) } func testRelayedMoveBalanceExecuteOnSourceAndDestinationRelayerAndInnerTxSenderShard0InnerTxReceiverShard1ShouldWork(relayedFixActivationEpoch uint32) func(t *testing.T) { @@ -267,14 +264,21 @@ func testRelayedMoveBalanceExecuteOnSourceAndDestinationRelayerAndInnerTxSenderS require.Nil(t, err) // check relayed balance - // 100000 - rTxFee(163)*gasPrice(10) - innerTxFee(1000) = 97370 - utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, big.NewInt(97370)) + // before base cost fix: 100000 - rTxFee(163)*gasPrice(10) - innerTxFee(1000) = 97370 + // after base cost fix: 100000 - rTxFee(163)*gasPrice(10) - innerTxFee(10) = 98360 + expectedConsumedFee := big.NewInt(97370) + expectedAccumulatedFees := big.NewInt(2630) + if relayedFixActivationEpoch != integrationTests.UnreachableEpoch { + expectedConsumedFee = big.NewInt(98360) + expectedAccumulatedFees = big.NewInt(1640) + } + utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, expectedConsumedFee) // check inner tx sender utils.TestAccount(t, testContextSource.Accounts, sndAddr, 1, big.NewInt(0)) // check accumulated fees accumulatedFees := testContextSource.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(2630), accumulatedFees) + require.Equal(t, expectedAccumulatedFees, accumulatedFees) // get scr for destination shard txs := testContextSource.GetIntermediateTransactions(t) @@ -296,8 +300,7 @@ func TestRelayedMoveBalanceRelayerAndInnerTxReceiverShard0SenderShard1(t *testin t.Skip("this is not a short test") } - t.Run("before relayed move balance fix", testRelayedMoveBalanceRelayerAndInnerTxReceiverShard0SenderShard1(integrationTests.UnreachableEpoch)) - t.Run("after relayed move balance fix", testRelayedMoveBalanceRelayerAndInnerTxReceiverShard0SenderShard1(0)) + t.Run("before relayed base cost fix", testRelayedMoveBalanceRelayerAndInnerTxReceiverShard0SenderShard1(integrationTests.UnreachableEpoch)) } func testRelayedMoveBalanceRelayerAndInnerTxReceiverShard0SenderShard1(relayedFixActivationEpoch uint32) func(t *testing.T) { @@ -385,8 +388,7 @@ func TestMoveBalanceRelayerShard0InnerTxSenderShard1InnerTxReceiverShard2ShouldW t.Skip("this is not a short test") } - t.Run("before relayed move balance fix", testMoveBalanceRelayerShard0InnerTxSenderShard1InnerTxReceiverShard2ShouldWork(integrationTests.UnreachableEpoch)) - t.Run("after relayed move balance fix", testMoveBalanceRelayerShard0InnerTxSenderShard1InnerTxReceiverShard2ShouldWork(0)) + t.Run("before relayed base cost fix", testMoveBalanceRelayerShard0InnerTxSenderShard1InnerTxReceiverShard2ShouldWork(integrationTests.UnreachableEpoch)) } func testMoveBalanceRelayerShard0InnerTxSenderShard1InnerTxReceiverShard2ShouldWork(relayedFixActivationEpoch uint32) func(t *testing.T) { diff --git a/integrationTests/vm/txsFee/relayedMoveBalance_test.go b/integrationTests/vm/txsFee/relayedMoveBalance_test.go index 2748e314c05..b0f95f095a9 100644 --- a/integrationTests/vm/txsFee/relayedMoveBalance_test.go +++ b/integrationTests/vm/txsFee/relayedMoveBalance_test.go @@ -23,7 +23,9 @@ func TestRelayedMoveBalanceShouldWork(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ + FixRelayedBaseCostEnableEpoch: integrationTests.UnreachableEpoch, + }) require.Nil(t, err) defer testContext.Close() @@ -109,7 +111,9 @@ func TestRelayedMoveBalanceInvalidUserTxShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ + FixRelayedBaseCostEnableEpoch: integrationTests.UnreachableEpoch, + }) require.Nil(t, err) defer testContext.Close() @@ -147,7 +151,8 @@ func TestRelayedMoveBalanceInvalidUserTxValueShouldConsumeGas(t *testing.T) { } testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ - RelayedNonceFixEnableEpoch: 1, + RelayedNonceFixEnableEpoch: 1, + FixRelayedBaseCostEnableEpoch: integrationTests.UnreachableEpoch, }) require.Nil(t, err) defer testContext.Close() diff --git a/process/transaction/baseProcess.go b/process/transaction/baseProcess.go index 319a8a65b9e..b1e95a71339 100644 --- a/process/transaction/baseProcess.go +++ b/process/transaction/baseProcess.go @@ -147,7 +147,7 @@ func (txProc *baseTxProcessor) checkTxValues( return process.ErrNotEnoughGasInUserTx } - txFee = txProc.computeTxFeeForRelayedTx(tx) + txFee = txProc.computeInnerTxFee(tx) } else { txFee = txProc.economicsFee.ComputeTxFee(tx) } @@ -174,15 +174,20 @@ func (txProc *baseTxProcessor) checkTxValues( return nil } -func (txProc *baseTxProcessor) computeTxFeeForRelayedTx(tx *transaction.Transaction) *big.Int { +func (txProc *baseTxProcessor) computeInnerTxFee(tx *transaction.Transaction) *big.Int { if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedBaseCostFlag) { - return txProc.computeTxFeeAfterBaseCostFix(tx) + return txProc.computeInnerTxFeeAfterBaseCostFix(tx) } return txProc.economicsFee.ComputeFeeForProcessing(tx, tx.GasLimit) } -func (txProc *baseTxProcessor) computeTxFeeAfterBaseCostFix(tx *transaction.Transaction) *big.Int { +func (txProc *baseTxProcessor) computeInnerTxFeeAfterBaseCostFix(tx *transaction.Transaction) *big.Int { + _, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(tx) + if dstShardTxType == process.MoveBalance { + return txProc.economicsFee.ComputeMoveBalanceFee(tx) + } + moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(tx) gasToUse := tx.GetGasLimit() - moveBalanceGasLimit moveBalanceUserFee := txProc.economicsFee.ComputeMoveBalanceFee(tx) diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 90a390eb63b..83ef7b368c6 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -400,7 +400,7 @@ func (txProc *txProcessor) processTxFee( } if isUserTxOfRelayed { - totalCost := txProc.computeTxFeeForRelayedTx(tx) + totalCost := txProc.computeInnerTxFee(tx) err := acntSnd.SubFromBalance(totalCost) if err != nil { @@ -747,7 +747,7 @@ func (txProc *txProcessor) processInnerTx( originalTxHash []byte, ) (*big.Int, vmcommon.ReturnCode, error) { - txFee := txProc.computeTxFeeForRelayedTx(innerTx) + txFee := txProc.computeInnerTxFee(innerTx) acntSnd, err := txProc.getAccountFromAddress(innerTx.SndAddr) if err != nil { @@ -867,7 +867,7 @@ func (txProc *txProcessor) computeRelayedTxFees(tx, userTx *transaction.Transact relayerFee := txProc.economicsFee.ComputeMoveBalanceFee(tx) totalFee := txProc.economicsFee.ComputeTxFee(tx) if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedBaseCostFlag) { - userFee := txProc.computeTxFeeAfterBaseCostFix(userTx) + userFee := txProc.computeInnerTxFeeAfterBaseCostFix(userTx) totalFee = totalFee.Add(relayerFee, userFee) } @@ -901,7 +901,7 @@ func (txProc *txProcessor) removeValueAndConsumedFeeFromUser( return err } - consumedFee := txProc.computeTxFeeForRelayedTx(userTx) + consumedFee := txProc.computeInnerTxFee(userTx) err = userAcnt.SubFromBalance(consumedFee) if err != nil { From b9c4a4d130876ae0b711cebc3bc51189a6c30fe0 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 25 Jun 2024 16:33:17 +0300 Subject: [PATCH 377/503] fix economicsData too --- process/economics/economicsData.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/process/economics/economicsData.go b/process/economics/economicsData.go index 209e8345941..2385f7feda2 100644 --- a/process/economics/economicsData.go +++ b/process/economics/economicsData.go @@ -337,6 +337,13 @@ func (ed *economicsData) ComputeRelayedTxFees(tx data.TransactionWithFeeHandler) func (ed *economicsData) getTotalFeesRequiredForInnerTxs(innerTxs []data.TransactionHandler) *big.Int { totalFees := big.NewInt(0) for _, innerTx := range innerTxs { + if !core.IsSmartContractAddress(innerTx.GetRcvAddr()) { + innerTxFee := ed.ComputeMoveBalanceFee(innerTx) + totalFees.Add(totalFees, innerTxFee) + + continue + } + gasToUse := innerTx.GetGasLimit() - ed.ComputeGasLimit(innerTx) moveBalanceUserFee := ed.ComputeMoveBalanceFee(innerTx) processingUserFee := ed.ComputeFeeForProcessing(innerTx, gasToUse) From e10c4fbfbe880504357d7ea6ac4a6d62bbc6de32 Mon Sep 17 00:00:00 2001 From: Daniel Drasovean Date: Tue, 25 Jun 2024 17:01:28 +0300 Subject: [PATCH 378/503] Fix keygenerator Dockerfile --- docker/keygenerator/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/keygenerator/Dockerfile b/docker/keygenerator/Dockerfile index c66a732e629..5d79327bc2a 100644 --- a/docker/keygenerator/Dockerfile +++ b/docker/keygenerator/Dockerfile @@ -13,4 +13,4 @@ FROM ubuntu:22.04 COPY --from=builder /go/mx-chain-go/cmd/keygenerator /go/mx-chain-go/cmd/keygenerator WORKDIR /go/mx-chain-go/cmd/keygenerator/ -ENTRYPOINT ["./keygenerator"] +ENTRYPOINT ["/go/mx-chain-go/cmd/keygenerator/keygenerator"] From c3344d8c17e056393ba867ca1d87d67c29218996 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 25 Jun 2024 19:39:44 +0300 Subject: [PATCH 379/503] fixes after merge --- .../config/gasSchedules/gasScheduleV8.toml | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/cmd/node/config/gasSchedules/gasScheduleV8.toml b/cmd/node/config/gasSchedules/gasScheduleV8.toml index 3f30d694591..424c07e79f2 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV8.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV8.toml @@ -16,6 +16,11 @@ ESDTNFTUpdateAttributes = 50000 ESDTNFTMultiTransfer = 200000 MultiESDTNFTTransfer = 200000 # should be the same value with the ESDTNFTMultiTransfer + ESDTModifyRoyalties = 500000 + ESDTModifyCreator = 500000 + ESDTNFTRecreate = 1000000 + ESDTNFTUpdate = 1000000 + ESDTNFTSetNewURIs = 500000 SetGuardian = 250000 GuardAccount = 250000 UnGuardAccount = 250000 @@ -190,23 +195,26 @@ CopyPerByteForTooBig = 1000 [CryptoAPICost] - SHA256 = 1000000 - Keccak256 = 1000000 - Ripemd160 = 1000000 - VerifyBLS = 5000000 - VerifyEd25519 = 2000000 - VerifySecp256k1 = 2000000 - EllipticCurveNew = 10000 - AddECC = 75000 - DoubleECC = 65000 - IsOnCurveECC = 10000 - ScalarMultECC = 400000 - MarshalECC = 13000 - MarshalCompressedECC = 15000 - UnmarshalECC = 20000 - UnmarshalCompressedECC = 270000 - GenerateKeyECC = 7000000 - EncodeDERSig = 10000000 + SHA256 = 1000000 + Keccak256 = 1000000 + Ripemd160 = 1000000 + VerifyBLS = 5000000 + VerifyEd25519 = 2000000 + VerifySecp256k1 = 2000000 + EllipticCurveNew = 10000 + AddECC = 75000 + DoubleECC = 65000 + IsOnCurveECC = 10000 + ScalarMultECC = 400000 + MarshalECC = 13000 + MarshalCompressedECC = 15000 + UnmarshalECC = 20000 + UnmarshalCompressedECC = 270000 + GenerateKeyECC = 7000000 + EncodeDERSig = 10000000 + VerifySecp256r1 = 2000000 + VerifyBLSSignatureShare = 2000000 + VerifyBLSMultiSig = 2000000 [ManagedBufferAPICost] MBufferNew = 2000 From fc1d704558672e17cb4abd6b9cf1cfd163b43e8b Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 26 Jun 2024 12:59:21 +0300 Subject: [PATCH 380/503] adapted scenarios to work with all tokens --- .../vm/esdtImprovements_test.go | 866 ++++++++++++------ 1 file changed, 596 insertions(+), 270 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 74cb76d3f84..06a78619282 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -867,7 +867,7 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { // Test scenario #4 // -// Initial setup: Create NFT +// Initial setup: Create NFT, SFT, metaESDT tokens // // Call ESDTMetaDataRecreate to rewrite the meta data for the nft // (The sender must have the ESDTMetaDataRecreate role) @@ -911,11 +911,7 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { defer cs.Close() - mintValue := big.NewInt(10) - mintValue = mintValue.Mul(oneEGLD, mintValue) - - address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) - require.Nil(t, err) + addrs := createAddresses(t, cs, false) err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) require.Nil(t, err) @@ -923,89 +919,174 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { err = cs.GenerateBlocks(10) require.Nil(t, err) - log.Info("Initial setup: Create NFT") + log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") - nftTicker := []byte("NFTTICKER") - tx := issueNonFungibleTx(0, address.Bytes, nftTicker, baseIssuingCost) + // issue metaESDT + metaESDTTicker := []byte("METATTICKER") + tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) + metaESDTTokenID := txResult.Logs.Events[0].Topics[0] + roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), []byte(core.ESDTMetaDataRecreate), } + setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + + log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) + + // issue fungible + fungibleTicker := []byte("FUNTICKER") + tx = issueTx(1, addrs[0].Bytes, fungibleTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + fungibleTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], fungibleTokenID, roles) + + log.Info("Issued fungible token id", "tokenID", string(fungibleTokenID)) + + // issue NFT + nftTicker := []byte("NFTTICKER") + tx = issueNonFungibleTx(2, addrs[0].Bytes, nftTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, address, nftTokenID, roles) + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) - nftMetaData := txsFee.GetDefaultMetaData() - nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - - tx = nftCreateTx(1, address.Bytes, nftTokenID, nftMetaData) + // issue SFT + sftTicker := []byte("SFTTICKER") + tx = issueSemiFungibleTx(3, addrs[0].Bytes, sftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) + sftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + + log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) + + tokenIDs := [][]byte{ + nftTokenID, + sftTokenID, + metaESDTTokenID, + fungibleTokenID, + } + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + sftMetaData := txsFee.GetDefaultMetaData() + sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + esdtMetaData := txsFee.GetDefaultMetaData() + esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + fungibleMetaData := txsFee.GetDefaultMetaData() + fungibleMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tokensMetadata := []*txsFee.MetaData{ + nftMetaData, + sftMetaData, + esdtMetaData, + fungibleMetaData, + } + + nonce := uint64(4) + for i := range tokenIDs { + tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } + err = cs.GenerateBlocks(10) require.Nil(t, err) log.Info("Call ESDTMetaDataRecreate to rewrite the meta data for the nft") - nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - nftMetaData.Name = []byte(hex.EncodeToString([]byte("name2"))) - nftMetaData.Hash = []byte(hex.EncodeToString([]byte("hash2"))) - nftMetaData.Attributes = []byte(hex.EncodeToString([]byte("attributes2"))) + for i := range tokenIDs { + newMetaData := txsFee.GetDefaultMetaData() + newMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + newMetaData.Name = []byte(hex.EncodeToString([]byte("name2"))) + newMetaData.Hash = []byte(hex.EncodeToString([]byte("hash2"))) + newMetaData.Attributes = []byte(hex.EncodeToString([]byte("attributes2"))) + + txDataField := bytes.Join( + [][]byte{ + []byte(core.ESDTMetaDataRecreate), + []byte(hex.EncodeToString(tokenIDs[i])), + newMetaData.Nonce, + newMetaData.Name, + []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + newMetaData.Hash, + newMetaData.Attributes, + newMetaData.Uris[0], + newMetaData.Uris[1], + newMetaData.Uris[2], + }, + []byte("@"), + ) + + tx = &transaction.Transaction{ + Nonce: nonce, + SndAddr: addrs[0].Bytes, + RcvAddr: addrs[0].Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } - txDataField := bytes.Join( - [][]byte{ - []byte(core.ESDTMetaDataRecreate), - []byte(hex.EncodeToString(nftTokenID)), - nonce, - nftMetaData.Name, - []byte(hex.EncodeToString(big.NewInt(10).Bytes())), - nftMetaData.Hash, - nftMetaData.Attributes, - nftMetaData.Uris[0], - nftMetaData.Uris[1], - nftMetaData.Uris[2], - }, - []byte("@"), - ) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) - tx = &transaction.Transaction{ - Nonce: 2, - SndAddr: address.Bytes, - RcvAddr: address.Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, - } + // fmt.Println(txResult) + // fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + // fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) - require.Equal(t, "success", txResult.Status.String()) + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(address.Bytes) + if bytes.Equal(tokenIDs[i], tokenIDs[0]) { // nft token + checkMetaData(t, cs, addrs[0].Bytes, tokenIDs[i], shardID, newMetaData) + } else { + checkMetaData(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID, newMetaData) + } - checkMetaData(t, cs, address.Bytes, nftTokenID, shardID, nftMetaData) + nonce++ + } } // Test scenario #5 // -// Initial setup: Create NFT +// Initial setup: Create NFT, SFT, metaESDT tokens // // Call ESDTMetaDataUpdate to update some of the meta data parameters // (The sender must have the ESDTRoleNFTUpdate role) @@ -1049,98 +1130,158 @@ func TestChainSimulator_NFT_ESDTMetaDataUpdate(t *testing.T) { defer cs.Close() - mintValue := big.NewInt(10) - mintValue = mintValue.Mul(oneEGLD, mintValue) - - address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) - require.Nil(t, err) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) require.Nil(t, err) - err = cs.GenerateBlocks(10) - require.Nil(t, err) + log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") - log.Info("Initial setup: Create NFT") + addrs := createAddresses(t, cs, false) - nftTicker := []byte("NFTTICKER") - tx := issueNonFungibleTx(0, address.Bytes, nftTicker, baseIssuingCost) + // issue metaESDT + metaESDTTicker := []byte("METATTICKER") + tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) + metaESDTTokenID := txResult.Logs.Events[0].Topics[0] + roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), []byte(core.ESDTRoleNFTUpdate), } + setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + + log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) + + // issue NFT + nftTicker := []byte("NFTTICKER") + tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, address, nftTokenID, roles) + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) - nftMetaData := txsFee.GetDefaultMetaData() - nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - - tx = nftCreateTx(1, address.Bytes, nftTokenID, nftMetaData) + // issue SFT + sftTicker := []byte("SFTTICKER") + tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - log.Info("Call ESDTMetaDataUpdate to rewrite the meta data for the nft") + sftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) - nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - nftMetaData.Name = []byte(hex.EncodeToString([]byte("name2"))) - nftMetaData.Hash = []byte(hex.EncodeToString([]byte("hash2"))) - nftMetaData.Attributes = []byte(hex.EncodeToString([]byte("attributes2"))) + log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) - txDataField := bytes.Join( - [][]byte{ - []byte(core.ESDTMetaDataUpdate), - []byte(hex.EncodeToString(nftTokenID)), - nonce, - nftMetaData.Name, - []byte(hex.EncodeToString(big.NewInt(10).Bytes())), - nftMetaData.Hash, - nftMetaData.Attributes, - nftMetaData.Uris[0], - nftMetaData.Uris[1], - nftMetaData.Uris[2], - }, - []byte("@"), - ) + tokenIDs := [][]byte{ + nftTokenID, + sftTokenID, + metaESDTTokenID, + } - tx = &transaction.Transaction{ - Nonce: 2, - SndAddr: address.Bytes, - RcvAddr: address.Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + sftMetaData := txsFee.GetDefaultMetaData() + sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + esdtMetaData := txsFee.GetDefaultMetaData() + esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tokensMetadata := []*txsFee.MetaData{ + nftMetaData, + sftMetaData, + esdtMetaData, } - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) + nonce := uint64(3) + for i := range tokenIDs { + tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) - require.Equal(t, "success", txResult.Status.String()) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } + + log.Info("Call ESDTMetaDataUpdate to rewrite the meta data for the nft") + + for i := range tokenIDs { + newMetaData := txsFee.GetDefaultMetaData() + newMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + newMetaData.Name = []byte(hex.EncodeToString([]byte("name2"))) + newMetaData.Hash = []byte(hex.EncodeToString([]byte("hash2"))) + newMetaData.Attributes = []byte(hex.EncodeToString([]byte("attributes2"))) + + txDataField := bytes.Join( + [][]byte{ + []byte(core.ESDTMetaDataUpdate), + []byte(hex.EncodeToString(tokenIDs[i])), + newMetaData.Nonce, + newMetaData.Name, + []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + newMetaData.Hash, + newMetaData.Attributes, + newMetaData.Uris[0], + newMetaData.Uris[1], + newMetaData.Uris[2], + }, + []byte("@"), + ) + + tx = &transaction.Transaction{ + Nonce: nonce, + SndAddr: addrs[0].Bytes, + RcvAddr: addrs[0].Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + // fmt.Println(txResult) + // fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + // fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(address.Bytes) + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - checkMetaData(t, cs, address.Bytes, nftTokenID, shardID, nftMetaData) + if bytes.Equal(tokenIDs[i], tokenIDs[0]) { // nft token + checkMetaData(t, cs, addrs[0].Bytes, tokenIDs[i], shardID, newMetaData) + } else { + checkMetaData(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID, newMetaData) + } + + nonce++ + } } // Test scenario #6 // -// Initial setup: Create SFT +// Initial setup: Create NFT, SFT, metaESDT tokens // // Call ESDTModifyCreator and check that the creator was modified // (The sender must have the ESDTRoleModifyCreator role) @@ -1184,114 +1325,190 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { defer cs.Close() - mintValue := big.NewInt(10) - mintValue = mintValue.Mul(oneEGLD, mintValue) - - shardID := uint32(1) - address, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) - require.Nil(t, err) - - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch) - 2) + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) require.Nil(t, err) - err = cs.GenerateBlocks(10) - require.Nil(t, err) + log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") - log.Info("Initial setup: Create SFT") + addrs := createAddresses(t, cs, false) - sftTicker := []byte("SFTTICKER") - tx := issueSemiFungibleTx(0, address.Bytes, sftTicker, baseIssuingCost) + // issue metaESDT + metaESDTTicker := []byte("METATTICKER") + tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) + metaESDTTokenID := txResult.Logs.Events[0].Topics[0] + roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), []byte(core.ESDTRoleNFTUpdate), } + setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) - sft := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, address, sft, roles) - - log.Info("Issued SFT token id", "tokenID", string(sft)) - - nftMetaData := txsFee.GetDefaultMetaData() - nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) - tx = nftCreateTx(1, address.Bytes, sft, nftMetaData) + // issue NFT + nftTicker := []byte("NFTTICKER") + tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) - require.Nil(t, err) + nftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) - log.Info("Change to DYNAMIC type") + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) - tx = changeToDynamicTx(2, address.Bytes, sft) + // issue SFT + sftTicker := []byte("SFTTICKER") + tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - log.Info("Call ESDTModifyCreator and check that the creator was modified") + sftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) - newCreatorAddress, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) - require.Nil(t, err) + log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) - err = cs.GenerateBlocks(10) - require.Nil(t, err) + tokenIDs := [][]byte{ + // nftTokenID, + sftTokenID, + metaESDTTokenID, + } - roles = [][]byte{ - []byte(core.ESDTRoleModifyCreator), + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + sftMetaData := txsFee.GetDefaultMetaData() + sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + esdtMetaData := txsFee.GetDefaultMetaData() + esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tokensMetadata := []*txsFee.MetaData{ + // nftMetaData, + sftMetaData, + esdtMetaData, } - setAddressEsdtRoles(t, cs, newCreatorAddress, sft, roles) - txDataField := bytes.Join( - [][]byte{ - []byte(core.ESDTModifyCreator), - []byte(hex.EncodeToString(sft)), - []byte(hex.EncodeToString(big.NewInt(1).Bytes())), - }, - []byte("@"), - ) + nonce := uint64(3) + for i := range tokenIDs { + tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) - tx = &transaction.Transaction{ - Nonce: 0, - SndAddr: newCreatorAddress.Bytes, - RcvAddr: newCreatorAddress.Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) + + nonce++ } - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + log.Info("Change to DYNAMIC type") + + for i := range tokenIDs { + tx = changeToDynamicTx(nonce, addrs[0].Bytes, tokenIDs[i]) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } + + err = cs.GenerateBlocks(10) require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) + log.Info("Call ESDTModifyCreator and check that the creator was modified") + + mintValue := big.NewInt(10) + mintValue = mintValue.Mul(oneEGLD, mintValue) + + shardID := uint32(0) + + for i := range tokenIDs { + log.Info("Modify creator for token", "tokenID", string(tokenIDs[i])) + + newCreatorAddress, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) + require.Nil(t, err) - retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, sft, shardID) + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + roles = [][]byte{ + []byte(core.ESDTRoleModifyCreator), + } + setAddressEsdtRoles(t, cs, newCreatorAddress, tokenIDs[i], roles) + + txDataField := bytes.Join( + [][]byte{ + []byte(core.ESDTModifyCreator), + []byte(hex.EncodeToString(tokenIDs[i])), + []byte(hex.EncodeToString(big.NewInt(1).Bytes())), + }, + []byte("@"), + ) + + tx = &transaction.Transaction{ + Nonce: 0, + SndAddr: newCreatorAddress.Bytes, + RcvAddr: newCreatorAddress.Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) - require.Equal(t, newCreatorAddress.Bytes, retrievedMetaData.Creator) + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) + + var retrievedMetaData *esdt.MetaData + if bytes.Equal(tokenIDs[i], tokenIDs[0]) { // nft token + retrievedMetaData = getMetaDataFromAcc(t, cs, addrs[0].Bytes, tokenIDs[i], shardID) + } else { + retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID) + } + + require.Equal(t, newCreatorAddress.Bytes, retrievedMetaData.Creator) + + nonce++ + } } // Test scenario #7 // -// Initial setup: Create NFT +// Initial setup: Create NFT, SFT, metaESDT tokens // -// Call ESDTSetNewURIs and check that the new URIs were set for the NFT +// Call ESDTSetNewURIs and check that the new URIs were set for the token // (The sender must have the ESDTRoleSetNewURI role) func TestChainSimulator_NFT_ESDTSetNewURIs(t *testing.T) { if testing.Short() { @@ -1333,56 +1550,103 @@ func TestChainSimulator_NFT_ESDTSetNewURIs(t *testing.T) { defer cs.Close() - mintValue := big.NewInt(10) - mintValue = mintValue.Mul(oneEGLD, mintValue) - - address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) - require.Nil(t, err) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) require.Nil(t, err) - err = cs.GenerateBlocks(10) - require.Nil(t, err) + log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") - log.Info("Initial setup: Create NFT") + addrs := createAddresses(t, cs, false) - nftTicker := []byte("NFTTICKER") - tx := issueNonFungibleTx(0, address.Bytes, nftTicker, baseIssuingCost) + // issue metaESDT + metaESDTTicker := []byte("METATTICKER") + tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) + metaESDTTokenID := txResult.Logs.Events[0].Topics[0] + roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), []byte(core.ESDTRoleNFTUpdate), + []byte(core.ESDTRoleSetNewURI), } + setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + + log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) + + // issue NFT + nftTicker := []byte("NFTTICKER") + tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, address, nftTokenID, roles) + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) - nftMetaData := txsFee.GetDefaultMetaData() - nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - - tx = nftCreateTx(1, address.Bytes, nftTokenID, nftMetaData) + // issue SFT + sftTicker := []byte("SFTTICKER") + tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - log.Info("Call ESDTSetNewURIs and check that the new URIs were set for the NFT") + sftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) - roles = [][]byte{ - []byte(core.ESDTRoleSetNewURI), + log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) + + tokenIDs := [][]byte{ + nftTokenID, + sftTokenID, + metaESDTTokenID, } - setAddressEsdtRoles(t, cs, address, nftTokenID, roles) - nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + sftMetaData := txsFee.GetDefaultMetaData() + sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + esdtMetaData := txsFee.GetDefaultMetaData() + esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tokensMetadata := []*txsFee.MetaData{ + nftMetaData, + sftMetaData, + esdtMetaData, + } + + nonce := uint64(3) + for i := range tokenIDs { + tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } + + log.Info("Call ESDTSetNewURIs and check that the new URIs were set for the NFT") + + metaDataNonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) uris := [][]byte{ []byte(hex.EncodeToString([]byte("uri0"))), []byte(hex.EncodeToString([]byte("uri1"))), @@ -1395,50 +1659,61 @@ func TestChainSimulator_NFT_ESDTSetNewURIs(t *testing.T) { []byte("uri2"), } - txDataField := bytes.Join( - [][]byte{ - []byte(core.ESDTSetNewURIs), - []byte(hex.EncodeToString(nftTokenID)), - nonce, - uris[0], - uris[1], - uris[2], - }, - []byte("@"), - ) + for i := range tokenIDs { + log.Info("Set new uris for token", "tokenID", string(tokenIDs[i])) + + txDataField := bytes.Join( + [][]byte{ + []byte(core.ESDTSetNewURIs), + []byte(hex.EncodeToString(tokenIDs[i])), + metaDataNonce, + uris[0], + uris[1], + uris[2], + }, + []byte("@"), + ) + + tx = &transaction.Transaction{ + Nonce: nonce, + SndAddr: addrs[0].Bytes, + RcvAddr: addrs[0].Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } - tx = &transaction.Transaction{ - Nonce: 2, - SndAddr: address.Bytes, - RcvAddr: address.Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, - } + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) - require.Equal(t, "success", txResult.Status.String()) + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + var retrievedMetaData *esdt.MetaData + if bytes.Equal(tokenIDs[i], tokenIDs[0]) { // nft token + retrievedMetaData = getMetaDataFromAcc(t, cs, addrs[0].Bytes, tokenIDs[i], shardID) + } else { + retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID) + } - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(address.Bytes) - retrievedMetaData := getMetaDataFromAcc(t, cs, address.Bytes, nftTokenID, shardID) + require.Equal(t, expUris, retrievedMetaData.URIs) - require.Equal(t, expUris, retrievedMetaData.URIs) + nonce++ + } } // Test scenario #8 // -// Initial setup: Create NFT +// Initial setup: Create NFT, SFT, metaESDT tokens // // Call ESDTModifyRoyalties and check that the royalties were changed // (The sender must have the ESDTRoleModifyRoyalties role) -func TestChainSimulator_NFT_ESDTModifyRoyalties(t *testing.T) { +func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } @@ -1478,91 +1753,142 @@ func TestChainSimulator_NFT_ESDTModifyRoyalties(t *testing.T) { defer cs.Close() - mintValue := big.NewInt(10) - mintValue = mintValue.Mul(oneEGLD, mintValue) - - address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) - require.Nil(t, err) + addrs := createAddresses(t, cs, false) err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) require.Nil(t, err) - err = cs.GenerateBlocks(10) - require.Nil(t, err) - - log.Info("Initial setup: Create NFT") - - nftTicker := []byte("NFTTICKER") - tx := issueNonFungibleTx(0, address.Bytes, nftTicker, baseIssuingCost) + // issue metaESDT + metaESDTTicker := []byte("METATTICKER") + tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) + metaESDTTokenID := txResult.Logs.Events[0].Topics[0] + roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), []byte(core.ESDTRoleNFTUpdate), + []byte(core.ESDTRoleModifyRoyalties), } + setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + + log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) + + // issue NFT + nftTicker := []byte("NFTTICKER") + tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, address, nftTokenID, roles) + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) - nftMetaData := txsFee.GetDefaultMetaData() - nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - - tx = nftCreateTx(1, address.Bytes, nftTokenID, nftMetaData) + // issue SFT + sftTicker := []byte("SFTTICKER") + tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - log.Info("Call ESDTModifyRoyalties and check that the royalties were changed") + sftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) - roles = [][]byte{ - []byte(core.ESDTRoleModifyRoyalties), + log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) + + tokenIDs := [][]byte{ + nftTokenID, + sftTokenID, + metaESDTTokenID, } - setAddressEsdtRoles(t, cs, address, nftTokenID, roles) - nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - royalties := []byte(hex.EncodeToString(big.NewInt(20).Bytes())) + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - txDataField := bytes.Join( - [][]byte{ - []byte(core.ESDTModifyRoyalties), - []byte(hex.EncodeToString(nftTokenID)), - nonce, - royalties, - }, - []byte("@"), - ) + sftMetaData := txsFee.GetDefaultMetaData() + sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = &transaction.Transaction{ - Nonce: 2, - SndAddr: address.Bytes, - RcvAddr: address.Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, + esdtMetaData := txsFee.GetDefaultMetaData() + esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tokensMetadata := []*txsFee.MetaData{ + nftMetaData, + sftMetaData, + esdtMetaData, } - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) + nonce := uint64(3) + for i := range tokenIDs { + tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) - require.Equal(t, "success", txResult.Status.String()) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } + + log.Info("Call ESDTModifyRoyalties and check that the royalties were changed") + + metaDataNonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + royalties := []byte(hex.EncodeToString(big.NewInt(20).Bytes())) + + for i := range tokenIDs { + log.Info("Set new royalities for token", "tokenID", string(tokenIDs[i])) + + txDataField := bytes.Join( + [][]byte{ + []byte(core.ESDTModifyRoyalties), + []byte(hex.EncodeToString(tokenIDs[i])), + metaDataNonce, + royalties, + }, + []byte("@"), + ) + + tx = &transaction.Transaction{ + Nonce: nonce, + SndAddr: addrs[0].Bytes, + RcvAddr: addrs[0].Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } - shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) - retrievedMetaData := getMetaDataFromAcc(t, cs, address.Bytes, nftTokenID, shardID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) - require.Equal(t, uint32(big.NewInt(20).Uint64()), retrievedMetaData.Royalties) + shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(addrs[0].Bytes) + retrievedMetaData := getMetaDataFromAcc(t, cs, addrs[0].Bytes, nftTokenID, shardID) + + require.Equal(t, uint32(big.NewInt(20).Uint64()), retrievedMetaData.Royalties) + + nonce++ + } } // Test scenario #9 From cfb556884c537b662b98f942155f1e5da4b20e86 Mon Sep 17 00:00:00 2001 From: Daniel Drasovean Date: Wed, 26 Jun 2024 13:38:01 +0300 Subject: [PATCH 381/503] Remove redundant code --- docker/keygenerator/Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/docker/keygenerator/Dockerfile b/docker/keygenerator/Dockerfile index 5d79327bc2a..a73d7951d42 100644 --- a/docker/keygenerator/Dockerfile +++ b/docker/keygenerator/Dockerfile @@ -12,5 +12,4 @@ RUN go build FROM ubuntu:22.04 COPY --from=builder /go/mx-chain-go/cmd/keygenerator /go/mx-chain-go/cmd/keygenerator -WORKDIR /go/mx-chain-go/cmd/keygenerator/ ENTRYPOINT ["/go/mx-chain-go/cmd/keygenerator/keygenerator"] From a5d15092412e7411a5dff77ef149d9f03f5d3350 Mon Sep 17 00:00:00 2001 From: Daniel Drasovean Date: Wed, 26 Jun 2024 13:41:24 +0300 Subject: [PATCH 382/503] Updated to support multi-arch docker builds --- docker/node/Dockerfile | 14 ++++++++++---- docker/termui/Dockerfile | 9 +++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/docker/node/Dockerfile b/docker/node/Dockerfile index 2513f789dc8..81675a6f6a3 100644 --- a/docker/node/Dockerfile +++ b/docker/node/Dockerfile @@ -7,15 +7,21 @@ RUN go mod tidy # Multiversx node WORKDIR /go/mx-chain-go/cmd/node RUN go build -v -ldflags="-X main.appVersion=$(git describe --tags --long --dirty)" -RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-v | sort -n | tail -n -1| awk -F '/' '{print$3}'| sed 's/ /@/g')/wasmer/libwasmer_linux_amd64.so /lib/libwasmer_linux_amd64.so -RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-go | sort -n | tail -n -1| awk -F '/' '{print$3}'| sed 's/ /@/g')/wasmer2/libvmexeccapi.so /lib/libvmexeccapi.so + +RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-v | sort -n | tail -n -1 | awk -F '/' '{print$3}' | sed 's/ /@/g')/wasmer/libwasmer_linux_amd64.so /lib_amd64/ +RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-go | sort -n | tail -n -1 | awk -F '/' '{print$3}' | sed 's/ /@/g')/wasmer2/libvmexeccapi.so /lib_amd64/ + +RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-v | sort -n | tail -n -1 | awk -F '/' '{print$3}' | sed 's/ /@/g')/wasmer/libwasmer_linux_arm64_shim.so /lib_arm64/ +RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-go | sort -n | tail -n -1 | awk -F '/' '{print$3}' | sed 's/ /@/g')/wasmer2/libvmexeccapi_arm.so /lib_arm64/ # ===== SECOND STAGE ====== FROM ubuntu:22.04 RUN apt-get update && apt-get upgrade -y COPY --from=builder "/go/mx-chain-go/cmd/node/node" "/go/mx-chain-go/cmd/node/" -COPY --from=builder "/lib/libwasmer_linux_amd64.so" "/lib/libwasmer_linux_amd64.so" -COPY --from=builder "/lib/libvmexeccapi.so" "/lib/libvmexeccapi.so" + +# Copy architecture-specific files +COPY --from=builder "/lib_${TARGETARCH}/*" "/lib/" + WORKDIR /go/mx-chain-go/cmd/node/ EXPOSE 8080 ENTRYPOINT ["/go/mx-chain-go/cmd/node/node"] diff --git a/docker/termui/Dockerfile b/docker/termui/Dockerfile index bcc670e3ce3..e25e75833e5 100644 --- a/docker/termui/Dockerfile +++ b/docker/termui/Dockerfile @@ -4,11 +4,16 @@ WORKDIR /go/mx-chain-go COPY . . WORKDIR /go/mx-chain-go/cmd/termui RUN go build -v -RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-v | sort -n | tail -n -1| awk -F '/' '{print$3}'| sed 's/ /@/g')/wasmer/libwasmer_linux_amd64.so /lib/libwasmer_linux_amd64.so +RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-v | sort -n | tail -n -1| awk -F '/' '{print$3}'| sed 's/ /@/g')/wasmer/libwasmer_linux_amd64.so /lib_amd64/ +RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-v | sort -n | tail -n -1 | awk -F '/' '{print$3}' | sed 's/ /@/g')/wasmer/libwasmer_linux_arm64_shim.so /lib_arm64/ + # ===== SECOND STAGE ====== FROM ubuntu:22.04 COPY --from=builder /go/mx-chain-go/cmd/termui /go/mx-chain-go/cmd/termui -COPY --from=builder "/lib/libwasmer_linux_amd64.so" "/lib/libwasmer_linux_amd64.so" + +# Copy architecture-specific files +COPY --from=builder "/lib_${TARGETARCH}/*" "/lib/" + WORKDIR /go/mx-chain-go/cmd/termui/ ENTRYPOINT ["./termui"] From c2bf800d348ecc355a0cdd74a58303eaf54060c4 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 26 Jun 2024 14:29:58 +0300 Subject: [PATCH 383/503] fix economicsData too --- epochStart/bootstrap/process_test.go | 2 +- factory/core/coreComponents.go | 2 + integrationTests/testProcessorNode.go | 1 + integrationTests/vm/testInitializer.go | 1 + integrationTests/vm/wasm/utils.go | 1 + .../components/coreComponents.go | 2 + .../timemachine/fee/feeComputer_test.go | 1 + .../fee/memoryFootprint/memory_test.go | 1 + .../gasUsedAndFeeProcessor_test.go | 1 + process/economics/economicsData.go | 25 ++++++- process/economics/economicsData_test.go | 12 +++ .../metaInterceptorsContainerFactory_test.go | 2 +- .../shardInterceptorsContainerFactory_test.go | 2 +- .../metachain/vmContainerFactory_test.go | 1 + .../interceptedMetaHeaderDataFactory_test.go | 2 +- process/mock/argumentsParserMock.go | 60 --------------- process/peer/process_test.go | 1 + process/scToProtocol/stakingToPeer_test.go | 18 ++--- .../processProxy/processProxy_test.go | 2 +- process/smartContract/process_test.go | 73 ++++++++++--------- .../smartContract/processorV2/process_test.go | 65 +++++++++-------- .../interceptedTransaction_test.go | 50 ++++++------- process/transaction/shardProcess_test.go | 36 ++++----- .../argumentsParserMock.go | 2 +- testscommon/stakingcommon/stakingCommon.go | 2 + 25 files changed, 178 insertions(+), 187 deletions(-) delete mode 100644 process/mock/argumentsParserMock.go rename {epochStart/mock => testscommon}/argumentsParserMock.go (98%) diff --git a/epochStart/bootstrap/process_test.go b/epochStart/bootstrap/process_test.go index 11a42a22301..552148003d6 100644 --- a/epochStart/bootstrap/process_test.go +++ b/epochStart/bootstrap/process_test.go @@ -221,7 +221,7 @@ func createMockEpochStartBootstrapArgs( RoundHandler: &mock.RoundHandlerStub{}, LatestStorageDataProvider: &mock.LatestStorageDataProviderStub{}, StorageUnitOpener: &storageMocks.UnitOpenerStub{}, - ArgumentsParser: &mock.ArgumentParserMock{}, + ArgumentsParser: &testscommon.ArgumentParserMock{}, StatusHandler: &statusHandlerMock.AppStatusHandlerStub{}, HeaderIntegrityVerifier: &mock.HeaderIntegrityVerifierStub{}, DataSyncerCreator: &scheduledDataSyncer.ScheduledSyncerFactoryStub{ diff --git a/factory/core/coreComponents.go b/factory/core/coreComponents.go index 247ee7e05f8..1656a042de0 100644 --- a/factory/core/coreComponents.go +++ b/factory/core/coreComponents.go @@ -33,6 +33,7 @@ import ( "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/economics" "github.com/multiversx/mx-chain-go/process/rating" + "github.com/multiversx/mx-chain-go/process/smartContract" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "github.com/multiversx/mx-chain-go/statusHandler" @@ -252,6 +253,7 @@ func (ccf *coreComponentsFactory) Create() (*coreComponents, error) { EpochNotifier: epochNotifier, EnableEpochsHandler: enableEpochsHandler, TxVersionChecker: txVersionChecker, + ArgumentParser: smartContract.NewArgumentParser(), } economicsData, err := economics.NewEconomicsData(argsNewEconomicsData) if err != nil { diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index cbd0f65b2c6..c093df85361 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -1109,6 +1109,7 @@ func (tpn *TestProcessorNode) initEconomicsData(economicsConfig *config.Economic EpochNotifier: tpn.EpochNotifier, EnableEpochsHandler: tpn.EnableEpochsHandler, TxVersionChecker: &testscommon.TxVersionCheckerStub{}, + ArgumentParser: smartContract.NewArgumentParser(), } economicsData, _ := economics.NewEconomicsData(argsNewEconomicsData) tpn.EconomicsData = economics.NewTestEconomicsData(economicsData) diff --git a/integrationTests/vm/testInitializer.go b/integrationTests/vm/testInitializer.go index 4304dd291dd..ed9bc1e8773 100644 --- a/integrationTests/vm/testInitializer.go +++ b/integrationTests/vm/testInitializer.go @@ -371,6 +371,7 @@ func createEconomicsData(enableEpochsConfig config.EnableEpochs) (process.Econom EpochNotifier: realEpochNotifier, EnableEpochsHandler: enableEpochsHandler, TxVersionChecker: versioning.NewTxVersionChecker(minTransactionVersion), + ArgumentParser: smartContract.NewArgumentParser(), } return economics.NewEconomicsData(argsNewEconomicsData) diff --git a/integrationTests/vm/wasm/utils.go b/integrationTests/vm/wasm/utils.go index 7ec28bb8f45..6e9a11b865c 100644 --- a/integrationTests/vm/wasm/utils.go +++ b/integrationTests/vm/wasm/utils.go @@ -254,6 +254,7 @@ func (context *TestContext) initFeeHandlers() { EpochNotifier: context.EpochNotifier, EnableEpochsHandler: context.EnableEpochsHandler, TxVersionChecker: &testscommon.TxVersionCheckerStub{}, + ArgumentParser: smartContract.NewArgumentParser(), } economicsData, _ := economics.NewEconomicsData(argsNewEconomicsData) diff --git a/node/chainSimulator/components/coreComponents.go b/node/chainSimulator/components/coreComponents.go index 49a7269d74b..0398c406d48 100644 --- a/node/chainSimulator/components/coreComponents.go +++ b/node/chainSimulator/components/coreComponents.go @@ -18,6 +18,7 @@ import ( "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/economics" "github.com/multiversx/mx-chain-go/process/rating" + "github.com/multiversx/mx-chain-go/process/smartContract" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "github.com/multiversx/mx-chain-go/statusHandler" @@ -173,6 +174,7 @@ func CreateCoreComponents(args ArgsCoreComponentsHolder) (*coreComponentsHolder, Economics: &args.EconomicsConfig, EpochNotifier: instance.epochNotifier, EnableEpochsHandler: instance.enableEpochsHandler, + ArgumentParser: smartContract.NewArgumentParser(), } instance.economicsData, err = economics.NewEconomicsData(argsEconomicsHandler) diff --git a/node/external/timemachine/fee/feeComputer_test.go b/node/external/timemachine/fee/feeComputer_test.go index 46e2904d6d2..1d99c91215e 100644 --- a/node/external/timemachine/fee/feeComputer_test.go +++ b/node/external/timemachine/fee/feeComputer_test.go @@ -35,6 +35,7 @@ func createEconomicsData() process.EconomicsDataHandler { }, TxVersionChecker: &testscommon.TxVersionCheckerStub{}, EpochNotifier: &epochNotifier.EpochNotifierStub{}, + ArgumentParser: &testscommon.ArgumentParserMock{}, }) return economicsData diff --git a/node/external/timemachine/fee/memoryFootprint/memory_test.go b/node/external/timemachine/fee/memoryFootprint/memory_test.go index a854a286ddd..ac7330a9206 100644 --- a/node/external/timemachine/fee/memoryFootprint/memory_test.go +++ b/node/external/timemachine/fee/memoryFootprint/memory_test.go @@ -44,6 +44,7 @@ func TestFeeComputer_MemoryFootprint(t *testing.T) { }, TxVersionChecker: &testscommon.TxVersionCheckerStub{}, EpochNotifier: &epochNotifier.EpochNotifierStub{}, + ArgumentParser: &testscommon.ArgumentParserMock{}, }) feeComputer, _ := fee.NewFeeComputer(economicsData) computer := fee.NewTestFeeComputer(feeComputer) diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go index 99541bfef5d..cbc510a97d4 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go @@ -24,6 +24,7 @@ func createEconomicsData(enableEpochsHandler common.EnableEpochsHandler) process EnableEpochsHandler: enableEpochsHandler, TxVersionChecker: &testscommon.TxVersionCheckerStub{}, EpochNotifier: &epochNotifier.EpochNotifierStub{}, + ArgumentParser: &testscommon.ArgumentParserMock{}, }) return economicsData diff --git a/process/economics/economicsData.go b/process/economics/economicsData.go index 2385f7feda2..387c0e8cb09 100644 --- a/process/economics/economicsData.go +++ b/process/economics/economicsData.go @@ -34,6 +34,7 @@ type economicsData struct { statusHandler core.AppStatusHandler enableEpochsHandler common.EnableEpochsHandler txVersionHandler process.TxVersionCheckerHandler + argumentParser process.ArgumentsParser mut sync.RWMutex } @@ -43,6 +44,7 @@ type ArgsNewEconomicsData struct { Economics *config.EconomicsConfig EpochNotifier process.EpochNotifier EnableEpochsHandler common.EnableEpochsHandler + ArgumentParser process.ArgumentsParser } // NewEconomicsData will create an object with information about economics parameters @@ -63,6 +65,9 @@ func NewEconomicsData(args ArgsNewEconomicsData) (*economicsData, error) { if err != nil { return nil, err } + if check.IfNil(args.ArgumentParser) { + return nil, process.ErrNilArgumentParser + } err = checkEconomicsConfig(args.Economics) if err != nil { @@ -75,6 +80,7 @@ func NewEconomicsData(args ArgsNewEconomicsData) (*economicsData, error) { statusHandler: statusHandler.NewNilStatusHandler(), enableEpochsHandler: args.EnableEpochsHandler, txVersionHandler: args.TxVersionChecker, + argumentParser: args.ArgumentParser, } ed.yearSettings = make(map[uint32]*config.YearSetting) @@ -337,7 +343,7 @@ func (ed *economicsData) ComputeRelayedTxFees(tx data.TransactionWithFeeHandler) func (ed *economicsData) getTotalFeesRequiredForInnerTxs(innerTxs []data.TransactionHandler) *big.Int { totalFees := big.NewInt(0) for _, innerTx := range innerTxs { - if !core.IsSmartContractAddress(innerTx.GetRcvAddr()) { + if ed.isMoveBalance(innerTx) { innerTxFee := ed.ComputeMoveBalanceFee(innerTx) totalFees.Add(totalFees, innerTxFee) @@ -355,6 +361,23 @@ func (ed *economicsData) getTotalFeesRequiredForInnerTxs(innerTxs []data.Transac return totalFees } +func (ed *economicsData) isMoveBalance(tx data.TransactionHandler) bool { + if len(tx.GetData()) == 0 { + return true + } + + if core.IsSmartContractAddress(tx.GetRcvAddr()) { + return false + } + + _, args, err := ed.argumentParser.ParseCallData(string(tx.GetData())) + if err != nil { + return false + } + + return len(args) == 0 +} + // SplitTxGasInCategories returns the gas split per categories func (ed *economicsData) SplitTxGasInCategories(tx data.TransactionWithFeeHandler) (gasLimitMove, gasLimitProcess uint64) { currentEpoch := ed.enableEpochsHandler.GetCurrentEpoch() diff --git a/process/economics/economicsData_test.go b/process/economics/economicsData_test.go index a5ac0b0c906..2b577ad0a8f 100644 --- a/process/economics/economicsData_test.go +++ b/process/economics/economicsData_test.go @@ -104,6 +104,7 @@ func createArgsForEconomicsData(gasModifier float64) economics.ArgsNewEconomicsD }, }, TxVersionChecker: &testscommon.TxVersionCheckerStub{}, + ArgumentParser: &testscommon.ArgumentParserMock{}, } return args } @@ -119,6 +120,7 @@ func createArgsForEconomicsDataRealFees() economics.ArgsNewEconomicsData { }, }, TxVersionChecker: &testscommon.TxVersionCheckerStub{}, + ArgumentParser: &testscommon.ArgumentParserMock{}, } return args } @@ -165,6 +167,16 @@ func TestNewEconomicsData_NilOrEmptyGasLimitSettingsShouldErr(t *testing.T) { assert.Equal(t, process.ErrEmptyGasLimitSettings, err) } +func TestNewEconomicsData_NilArgumentParserShouldErr(t *testing.T) { + t.Parallel() + + args := createArgsForEconomicsData(1) + args.ArgumentParser = nil + + _, err := economics.NewEconomicsData(args) + assert.Equal(t, process.ErrNilArgumentParser, err) +} + func TestNewEconomicsData_InvalidMaxGasLimitPerBlockShouldErr(t *testing.T) { t.Parallel() diff --git a/process/factory/interceptorscontainer/metaInterceptorsContainerFactory_test.go b/process/factory/interceptorscontainer/metaInterceptorsContainerFactory_test.go index 3964342133a..b9124001264 100644 --- a/process/factory/interceptorscontainer/metaInterceptorsContainerFactory_test.go +++ b/process/factory/interceptorscontainer/metaInterceptorsContainerFactory_test.go @@ -698,7 +698,7 @@ func getArgumentsMeta( WhiteListHandler: &testscommon.WhiteListHandlerStub{}, WhiteListerVerifiedTxs: &testscommon.WhiteListHandlerStub{}, AntifloodHandler: &mock.P2PAntifloodHandlerStub{}, - ArgumentsParser: &mock.ArgumentParserMock{}, + ArgumentsParser: &testscommon.ArgumentParserMock{}, PreferredPeersHolder: &p2pmocks.PeersHolderStub{}, RequestHandler: &testscommon.RequestHandlerStub{}, PeerSignatureHandler: &mock.PeerSignatureHandlerStub{}, diff --git a/process/factory/interceptorscontainer/shardInterceptorsContainerFactory_test.go b/process/factory/interceptorscontainer/shardInterceptorsContainerFactory_test.go index cf787a684a2..f802562ae35 100644 --- a/process/factory/interceptorscontainer/shardInterceptorsContainerFactory_test.go +++ b/process/factory/interceptorscontainer/shardInterceptorsContainerFactory_test.go @@ -724,7 +724,7 @@ func getArgumentsShard( AntifloodHandler: &mock.P2PAntifloodHandlerStub{}, WhiteListHandler: &testscommon.WhiteListHandlerStub{}, WhiteListerVerifiedTxs: &testscommon.WhiteListHandlerStub{}, - ArgumentsParser: &mock.ArgumentParserMock{}, + ArgumentsParser: &testscommon.ArgumentParserMock{}, PreferredPeersHolder: &p2pmocks.PeersHolderStub{}, RequestHandler: &testscommon.RequestHandlerStub{}, PeerSignatureHandler: &mock.PeerSignatureHandlerStub{}, diff --git a/process/factory/metachain/vmContainerFactory_test.go b/process/factory/metachain/vmContainerFactory_test.go index ff542213ef4..ea0123a183c 100644 --- a/process/factory/metachain/vmContainerFactory_test.go +++ b/process/factory/metachain/vmContainerFactory_test.go @@ -323,6 +323,7 @@ func TestVmContainerFactory_Create(t *testing.T) { EpochNotifier: &epochNotifier.EpochNotifierStub{}, EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), TxVersionChecker: &testscommon.TxVersionCheckerStub{}, + ArgumentParser: &testscommon.ArgumentParserMock{}, } economicsData, _ := economics.NewEconomicsData(argsNewEconomicsData) diff --git a/process/interceptors/factory/interceptedMetaHeaderDataFactory_test.go b/process/interceptors/factory/interceptedMetaHeaderDataFactory_test.go index edbc59757da..d2ecc63e59d 100644 --- a/process/interceptors/factory/interceptedMetaHeaderDataFactory_test.go +++ b/process/interceptors/factory/interceptedMetaHeaderDataFactory_test.go @@ -102,7 +102,7 @@ func createMockArgument( ValidityAttester: &mock.ValidityAttesterStub{}, HeaderIntegrityVerifier: &mock.HeaderIntegrityVerifierStub{}, EpochStartTrigger: &mock.EpochStartTriggerStub{}, - ArgsParser: &mock.ArgumentParserMock{}, + ArgsParser: &testscommon.ArgumentParserMock{}, PeerSignatureHandler: &processMocks.PeerSignatureHandlerStub{}, SignaturesHandler: &processMocks.SignaturesHandlerStub{}, HeartbeatExpiryTimespanInSec: 30, diff --git a/process/mock/argumentsParserMock.go b/process/mock/argumentsParserMock.go deleted file mode 100644 index 02ce8f408ae..00000000000 --- a/process/mock/argumentsParserMock.go +++ /dev/null @@ -1,60 +0,0 @@ -package mock - -import ( - vmcommon "github.com/multiversx/mx-chain-vm-common-go" - "github.com/multiversx/mx-chain-vm-common-go/parsers" -) - -// ArgumentParserMock - -type ArgumentParserMock struct { - ParseCallDataCalled func(data string) (string, [][]byte, error) - ParseArgumentsCalled func(data string) ([][]byte, error) - ParseDeployDataCalled func(data string) (*parsers.DeployArgs, error) - CreateDataFromStorageUpdateCalled func(storageUpdates []*vmcommon.StorageUpdate) string - GetStorageUpdatesCalled func(data string) ([]*vmcommon.StorageUpdate, error) -} - -// ParseCallData - -func (ap *ArgumentParserMock) ParseCallData(data string) (string, [][]byte, error) { - if ap.ParseCallDataCalled == nil { - return "", nil, nil - } - return ap.ParseCallDataCalled(data) -} - -// ParseArguments - -func (ap *ArgumentParserMock) ParseArguments(data string) ([][]byte, error) { - if ap.ParseArgumentsCalled == nil { - return [][]byte{}, nil - } - return ap.ParseArgumentsCalled(data) -} - -// ParseDeployData - -func (ap *ArgumentParserMock) ParseDeployData(data string) (*parsers.DeployArgs, error) { - if ap.ParseDeployDataCalled == nil { - return nil, nil - } - return ap.ParseDeployDataCalled(data) -} - -// CreateDataFromStorageUpdate - -func (ap *ArgumentParserMock) CreateDataFromStorageUpdate(storageUpdates []*vmcommon.StorageUpdate) string { - if ap.CreateDataFromStorageUpdateCalled == nil { - return "" - } - return ap.CreateDataFromStorageUpdateCalled(storageUpdates) -} - -// GetStorageUpdates - -func (ap *ArgumentParserMock) GetStorageUpdates(data string) ([]*vmcommon.StorageUpdate, error) { - if ap.GetStorageUpdatesCalled == nil { - return nil, nil - } - return ap.GetStorageUpdatesCalled(data) -} - -// IsInterfaceNil returns true if there is no value under the interface -func (ap *ArgumentParserMock) IsInterfaceNil() bool { - return ap == nil -} diff --git a/process/peer/process_test.go b/process/peer/process_test.go index d4c85a5601f..38d72b8297e 100644 --- a/process/peer/process_test.go +++ b/process/peer/process_test.go @@ -105,6 +105,7 @@ func createMockArguments() peer.ArgValidatorStatisticsProcessor { EpochNotifier: &epochNotifier.EpochNotifierStub{}, EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), TxVersionChecker: &testscommon.TxVersionCheckerStub{}, + ArgumentParser: &testscommon.ArgumentParserMock{}, } economicsData, _ := economics.NewEconomicsData(argsNewEconomicsData) diff --git a/process/scToProtocol/stakingToPeer_test.go b/process/scToProtocol/stakingToPeer_test.go index f53495e92c9..a6f0d80bc1b 100644 --- a/process/scToProtocol/stakingToPeer_test.go +++ b/process/scToProtocol/stakingToPeer_test.go @@ -40,7 +40,7 @@ func createMockArgumentsNewStakingToPeer() ArgStakingToPeer { Marshalizer: &mock.MarshalizerStub{}, PeerState: &stateMock.AccountsStub{}, BaseState: &stateMock.AccountsStub{}, - ArgParser: &mock.ArgumentParserMock{}, + ArgParser: &testscommon.ArgumentParserMock{}, CurrTxs: &mock.TxForCurrentBlockStub{}, RatingsData: &mock.RatingsInfoMock{}, EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.StakeFlag, common.ValidatorToDelegationFlag), @@ -227,7 +227,7 @@ func TestStakingToPeer_UpdateProtocolCannotGetStorageUpdatesShouldErr(t *testing }, nil } - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} argParser.GetStorageUpdatesCalled = func(data string) (updates []*vmcommon.StorageUpdate, e error) { return nil, testError } @@ -252,7 +252,7 @@ func TestStakingToPeer_UpdateProtocolRemoveAccountShouldReturnNil(t *testing.T) }, nil } - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} argParser.GetStorageUpdatesCalled = func(data string) (updates []*vmcommon.StorageUpdate, e error) { return []*vmcommon.StorageUpdate{ {Offset: []byte("aabbcc"), Data: []byte("data1")}, @@ -311,7 +311,7 @@ func TestStakingToPeer_UpdateProtocolCannotSetRewardAddressShouldErr(t *testing. offset = append(offset, 99) } - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} argParser.GetStorageUpdatesCalled = func(data string) (updates []*vmcommon.StorageUpdate, e error) { return []*vmcommon.StorageUpdate{ {Offset: offset, Data: []byte("data1")}, @@ -368,7 +368,7 @@ func TestStakingToPeer_UpdateProtocolEmptyDataShouldNotAddToTrie(t *testing.T) { offset = append(offset, 99) } - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} argParser.GetStorageUpdatesCalled = func(data string) (updates []*vmcommon.StorageUpdate, e error) { return []*vmcommon.StorageUpdate{ {Offset: offset, Data: []byte("data1")}, @@ -429,7 +429,7 @@ func TestStakingToPeer_UpdateProtocolCannotSaveAccountShouldErr(t *testing.T) { offset = append(offset, 99) } - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} argParser.GetStorageUpdatesCalled = func(data string) (updates []*vmcommon.StorageUpdate, e error) { return []*vmcommon.StorageUpdate{ {Offset: offset, Data: []byte("data1")}, @@ -492,7 +492,7 @@ func TestStakingToPeer_UpdateProtocolCannotSaveAccountNonceShouldErr(t *testing. offset = append(offset, 99) } - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} argParser.GetStorageUpdatesCalled = func(data string) (updates []*vmcommon.StorageUpdate, e error) { return []*vmcommon.StorageUpdate{ {Offset: offset, Data: []byte("data1")}, @@ -554,7 +554,7 @@ func TestStakingToPeer_UpdateProtocol(t *testing.T) { offset = append(offset, 99) } - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} argParser.GetStorageUpdatesCalled = func(data string) (updates []*vmcommon.StorageUpdate, e error) { return []*vmcommon.StorageUpdate{ {Offset: offset, Data: []byte("data1")}, @@ -617,7 +617,7 @@ func TestStakingToPeer_UpdateProtocolCannotSaveUnStakedNonceShouldErr(t *testing offset = append(offset, 99) } - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} argParser.GetStorageUpdatesCalled = func(data string) (updates []*vmcommon.StorageUpdate, e error) { return []*vmcommon.StorageUpdate{ {Offset: offset, Data: []byte("data1")}, diff --git a/process/smartContract/processProxy/processProxy_test.go b/process/smartContract/processProxy/processProxy_test.go index d74d09f377c..98a56fd0f30 100644 --- a/process/smartContract/processProxy/processProxy_test.go +++ b/process/smartContract/processProxy/processProxy_test.go @@ -40,7 +40,7 @@ func createMockSmartContractProcessorArguments() scrCommon.ArgsNewSmartContractP return scrCommon.ArgsNewSmartContractProcessor{ VmContainer: &mock.VMContainerMock{}, - ArgsParser: &mock.ArgumentParserMock{}, + ArgsParser: &testscommon.ArgumentParserMock{}, Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, AccountsDB: &stateMock.AccountsStub{ diff --git a/process/smartContract/process_test.go b/process/smartContract/process_test.go index fa693dd5ab6..c8b8097559d 100644 --- a/process/smartContract/process_test.go +++ b/process/smartContract/process_test.go @@ -84,7 +84,7 @@ func createMockSmartContractProcessorArguments() scrCommon.ArgsNewSmartContractP return scrCommon.ArgsNewSmartContractProcessor{ VmContainer: &mock.VMContainerMock{}, - ArgsParser: &mock.ArgumentParserMock{}, + ArgsParser: &testscommon.ArgumentParserMock{}, Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, AccountsDB: &stateMock.AccountsStub{ @@ -459,7 +459,7 @@ func TestGasScheduleChangeShouldWork(t *testing.T) { func TestScProcessor_DeploySmartContractBadParse(t *testing.T) { t.Parallel() - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = &mock.VMContainerMock{} arguments.ArgsParser = argParser @@ -889,7 +889,7 @@ func TestScProcessor_DeploySmartContractWrongTx(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -911,7 +911,7 @@ func TestScProcessor_DeploySmartContractNilTx(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -933,7 +933,7 @@ func TestScProcessor_DeploySmartContractNotEmptyDestinationAddress(t *testing.T) t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -956,7 +956,7 @@ func TestScProcessor_DeploySmartContractCalculateHashFails(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -988,7 +988,7 @@ func TestScProcessor_DeploySmartContractEconomicsFeeValidateFails(t *testing.T) expectedError := errors.New("expected error") vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -1019,7 +1019,7 @@ func TestScProcessor_DeploySmartContractEconomicsFeeSaveAccountsFails(t *testing expectedError := errors.New("expected error") vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -1478,7 +1478,7 @@ func TestScProcessor_ExecuteSmartContractTransactionNilTx(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -1502,7 +1502,7 @@ func TestScProcessor_ExecuteSmartContractTransactionNilAccount(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -1535,7 +1535,7 @@ func TestScProcessor_ExecuteSmartContractTransactionBadParser(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -1567,7 +1567,7 @@ func TestScProcessor_ExecuteSmartContractTransactionVMRunError(t *testing.T) { t.Parallel() vmContainer := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vmContainer arguments.ArgsParser = argParser @@ -1704,7 +1704,7 @@ func TestScProcessor_ExecuteSmartContractTransaction(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} accntState := &stateMock.AccountsStub{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm @@ -1737,7 +1737,7 @@ func TestScProcessor_ExecuteSmartContractTransactionSaveLogCalled(t *testing.T) slCalled := false vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} accntState := &stateMock.AccountsStub{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm @@ -1774,7 +1774,7 @@ func TestScProcessor_CreateVMCallInputWrongCode(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -1802,7 +1802,7 @@ func TestScProcessor_CreateVMCallInput(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -1826,7 +1826,7 @@ func TestScProcessor_CreateVMDeployBadCode(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -1853,7 +1853,7 @@ func TestScProcessor_CreateVMDeployInput(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -1917,7 +1917,7 @@ func TestScProcessor_CreateVMDeployInputWrongArgument(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -1946,7 +1946,7 @@ func TestScProcessor_InitializeVMInputFromTx_ShouldErrNotEnoughGas(t *testing.T) t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -1976,7 +1976,7 @@ func TestScProcessor_InitializeVMInputFromTx(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -2013,7 +2013,7 @@ func TestScProcessor_processVMOutputNilSndAcc(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -2042,7 +2042,7 @@ func TestScProcessor_processVMOutputNilDstAcc(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} accntState := &stateMock.AccountsStub{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm @@ -2086,7 +2086,7 @@ func TestScProcessor_GetAccountFromAddressAccNotFound(t *testing.T) { } vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -2117,7 +2117,7 @@ func TestScProcessor_GetAccountFromAddrFailedGetExistingAccount(t *testing.T) { } vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -2149,7 +2149,7 @@ func TestScProcessor_GetAccountFromAddrAccNotInShard(t *testing.T) { } vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -2182,7 +2182,7 @@ func TestScProcessor_GetAccountFromAddr(t *testing.T) { } vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -2217,7 +2217,7 @@ func TestScProcessor_DeleteAccountsFailedAtRemove(t *testing.T) { } vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -2252,7 +2252,7 @@ func TestScProcessor_DeleteAccountsNotInShard(t *testing.T) { } vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -2291,7 +2291,7 @@ func TestScProcessor_DeleteAccountsInShard(t *testing.T) { } vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -4248,6 +4248,7 @@ func createRealEconomicsDataArgs() *economics.ArgsNewEconomicsData { }, }, TxVersionChecker: &testscommon.TxVersionCheckerStub{}, + ArgumentParser: &testscommon.ArgumentParserMock{}, } } @@ -4397,7 +4398,7 @@ func TestScProcessor_CheckBuiltinFunctionIsExecutable(t *testing.T) { }) t.Run("", func(t *testing.T) { argsCopy := arguments - argsCopy.ArgsParser = &mock.ArgumentParserMock{ + argsCopy.ArgsParser = &testscommon.ArgumentParserMock{ ParseCallDataCalled: func(data string) (string, [][]byte, error) { return "", nil, expectedErr }, @@ -4408,7 +4409,7 @@ func TestScProcessor_CheckBuiltinFunctionIsExecutable(t *testing.T) { }) t.Run("expected builtin function different than the parsed function name should return error", func(t *testing.T) { argsCopy := arguments - argsCopy.ArgsParser = &mock.ArgumentParserMock{ + argsCopy.ArgsParser = &testscommon.ArgumentParserMock{ ParseCallDataCalled: func(data string) (string, [][]byte, error) { return "differentFunction", nil, nil }, @@ -4419,7 +4420,7 @@ func TestScProcessor_CheckBuiltinFunctionIsExecutable(t *testing.T) { }) t.Run("prepare gas provided with error should error", func(t *testing.T) { argsCopy := arguments - argsCopy.ArgsParser = &mock.ArgumentParserMock{ + argsCopy.ArgsParser = &testscommon.ArgumentParserMock{ ParseCallDataCalled: func(data string) (string, [][]byte, error) { return "SetGuardian", nil, nil }, @@ -4437,7 +4438,7 @@ func TestScProcessor_CheckBuiltinFunctionIsExecutable(t *testing.T) { }) t.Run("builtin function not found should error", func(t *testing.T) { argsCopy := arguments - argsCopy.ArgsParser = &mock.ArgumentParserMock{ + argsCopy.ArgsParser = &testscommon.ArgumentParserMock{ ParseCallDataCalled: func(data string) (string, [][]byte, error) { return "SetGuardian", nil, nil }, @@ -4458,7 +4459,7 @@ func TestScProcessor_CheckBuiltinFunctionIsExecutable(t *testing.T) { }) t.Run("builtin function not supporting executable check should error", func(t *testing.T) { argsCopy := arguments - argsCopy.ArgsParser = &mock.ArgumentParserMock{ + argsCopy.ArgsParser = &testscommon.ArgumentParserMock{ ParseCallDataCalled: func(data string) (string, [][]byte, error) { return "SetGuardian", nil, nil }, @@ -4478,7 +4479,7 @@ func TestScProcessor_CheckBuiltinFunctionIsExecutable(t *testing.T) { }) t.Run("OK", func(t *testing.T) { argsCopy := arguments - argsCopy.ArgsParser = &mock.ArgumentParserMock{ + argsCopy.ArgsParser = &testscommon.ArgumentParserMock{ ParseCallDataCalled: func(data string) (string, [][]byte, error) { return "SetGuardian", nil, nil }, diff --git a/process/smartContract/processorV2/process_test.go b/process/smartContract/processorV2/process_test.go index 4ef5ac15af8..14f0ea0ba17 100644 --- a/process/smartContract/processorV2/process_test.go +++ b/process/smartContract/processorV2/process_test.go @@ -94,7 +94,7 @@ func createMockSmartContractProcessorArguments() scrCommon.ArgsNewSmartContractP return scrCommon.ArgsNewSmartContractProcessor{ VmContainer: &mock.VMContainerMock{}, - ArgsParser: &mock.ArgumentParserMock{}, + ArgsParser: &testscommon.ArgumentParserMock{}, Hasher: &hashingMocks.HasherMock{}, Marshalizer: &mock.MarshalizerMock{}, AccountsDB: &stateMock.AccountsStub{ @@ -451,7 +451,7 @@ func createTxLogsProcessor() process.TransactionLogProcessor { func TestScProcessor_DeploySmartContractBadParse(t *testing.T) { t.Parallel() - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = &mock.VMContainerMock{} arguments.ArgsParser = argParser @@ -921,7 +921,7 @@ func TestScProcessor_DeploySmartContractWrongTx(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -943,7 +943,7 @@ func TestScProcessor_DeploySmartContractNilTx(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -965,7 +965,7 @@ func TestScProcessor_DeploySmartContractNotEmptyDestinationAddress(t *testing.T) t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -988,7 +988,7 @@ func TestScProcessor_DeploySmartContractCalculateHashFails(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -1020,7 +1020,7 @@ func TestScProcessor_DeploySmartContractEconomicsFeeValidateFails(t *testing.T) expectedError := errors.New("expected error") vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -1051,7 +1051,7 @@ func TestScProcessor_DeploySmartContractEconomicsFeeSaveAccountsFails(t *testing expectedError := errors.New("expected error") vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -1510,7 +1510,7 @@ func TestScProcessor_ExecuteSmartContractTransactionNilTx(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -1534,7 +1534,7 @@ func TestScProcessor_ExecuteSmartContractTransactionNilAccount(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -1567,7 +1567,7 @@ func TestScProcessor_ExecuteSmartContractTransactionBadParser(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -1599,7 +1599,7 @@ func TestScProcessor_ExecuteSmartContractTransactionVMRunError(t *testing.T) { t.Parallel() vmContainer := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vmContainer arguments.ArgsParser = argParser @@ -1736,7 +1736,7 @@ func TestScProcessor_ExecuteSmartContractTransaction(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} accntState := &stateMock.AccountsStub{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm @@ -1769,7 +1769,7 @@ func TestScProcessor_ExecuteSmartContractTransactionSaveLogCalled(t *testing.T) slCalled := false vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} accntState := &stateMock.AccountsStub{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm @@ -1806,7 +1806,7 @@ func TestScProcessor_CreateVMCallInputWrongCode(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -1834,7 +1834,7 @@ func TestScProcessor_CreateVMCallInput(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -1858,7 +1858,7 @@ func TestScProcessor_CreateVMDeployBadCode(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -1885,7 +1885,7 @@ func TestScProcessor_CreateVMCallInputBadAsync(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -1915,7 +1915,7 @@ func TestScProcessor_CreateVMDeployInput(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -1979,7 +1979,7 @@ func TestScProcessor_CreateVMDeployInputWrongArgument(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -2008,7 +2008,7 @@ func TestScProcessor_InitializeVMInputFromTx_ShouldErrNotEnoughGas(t *testing.T) t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -2038,7 +2038,7 @@ func TestScProcessor_InitializeVMInputFromTx(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -2075,7 +2075,7 @@ func TestScProcessor_processVMOutputNilSndAcc(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -2104,7 +2104,7 @@ func TestScProcessor_processVMOutputNilDstAcc(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} accntState := &stateMock.AccountsStub{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm @@ -2148,7 +2148,7 @@ func TestScProcessor_GetAccountFromAddressAccNotFound(t *testing.T) { } vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -2179,7 +2179,7 @@ func TestScProcessor_GetAccountFromAddrFailedGetExistingAccount(t *testing.T) { } vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -2211,7 +2211,7 @@ func TestScProcessor_GetAccountFromAddrAccNotInShard(t *testing.T) { } vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -2244,7 +2244,7 @@ func TestScProcessor_GetAccountFromAddr(t *testing.T) { } vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -2279,7 +2279,7 @@ func TestScProcessor_DeleteAccountsFailedAtRemove(t *testing.T) { } vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -2314,7 +2314,7 @@ func TestScProcessor_DeleteAccountsNotInShard(t *testing.T) { } vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -2354,7 +2354,7 @@ func TestScProcessor_DeleteAccountsInShard(t *testing.T) { } vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm arguments.ArgsParser = argParser @@ -4206,6 +4206,7 @@ func createRealEconomicsDataArgs() *economics.ArgsNewEconomicsData { }, }, TxVersionChecker: &testscommon.TxVersionCheckerStub{}, + ArgumentParser: &testscommon.ArgumentParserMock{}, } } @@ -4366,7 +4367,7 @@ func TestSCProcessor_PrependAsyncParamsToData(t *testing.T) { func TestScProcessor_ForbidMultiLevelAsync(t *testing.T) { t.Parallel() vm := &mock.VMContainerMock{} - argParser := &mock.ArgumentParserMock{} + argParser := &testscommon.ArgumentParserMock{} accntState := &stateMock.AccountsStub{} arguments := createMockSmartContractProcessorArguments() arguments.VmContainer = vm diff --git a/process/transaction/interceptedTransaction_test.go b/process/transaction/interceptedTransaction_test.go index e2494cd71d7..44d416194ab 100644 --- a/process/transaction/interceptedTransaction_test.go +++ b/process/transaction/interceptedTransaction_test.go @@ -117,7 +117,7 @@ func createInterceptedTxWithTxFeeHandlerAndVersionChecker(tx *dataTransaction.Tr shardCoordinator, txFeeHandler, &testscommon.WhiteListHandlerStub{}, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, []byte("T"), false, &hashingMocks.HasherMock{}, @@ -165,7 +165,7 @@ func createInterceptedTxFromPlainTx(tx *dataTransaction.Transaction, txFeeHandle shardCoordinator, txFeeHandler, &testscommon.WhiteListHandlerStub{}, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, chainID, false, &hashingMocks.HasherMock{}, @@ -249,7 +249,7 @@ func TestNewInterceptedTransaction_NilBufferShouldErr(t *testing.T) { mock.NewOneShardCoordinatorMock(), &economicsmocks.EconomicsHandlerStub{}, &testscommon.WhiteListHandlerStub{}, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, []byte("chainID"), false, &hashingMocks.HasherMock{}, @@ -303,7 +303,7 @@ func TestNewInterceptedTransaction_NilVersionChecker(t *testing.T) { mock.NewOneShardCoordinatorMock(), &economicsmocks.EconomicsHandlerStub{}, &testscommon.WhiteListHandlerStub{}, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, []byte("chainID"), false, &hashingMocks.HasherMock{}, @@ -330,7 +330,7 @@ func TestNewInterceptedTransaction_NilMarshalizerShouldErr(t *testing.T) { mock.NewOneShardCoordinatorMock(), &economicsmocks.EconomicsHandlerStub{}, &testscommon.WhiteListHandlerStub{}, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, []byte("chainID"), false, &hashingMocks.HasherMock{}, @@ -357,7 +357,7 @@ func TestNewInterceptedTransaction_NilSignMarshalizerShouldErr(t *testing.T) { mock.NewOneShardCoordinatorMock(), &economicsmocks.EconomicsHandlerStub{}, &testscommon.WhiteListHandlerStub{}, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, []byte("chainID"), false, &hashingMocks.HasherMock{}, @@ -384,7 +384,7 @@ func TestNewInterceptedTransaction_NilHasherShouldErr(t *testing.T) { mock.NewOneShardCoordinatorMock(), &economicsmocks.EconomicsHandlerStub{}, &testscommon.WhiteListHandlerStub{}, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, []byte("chainID"), false, &hashingMocks.HasherMock{}, @@ -411,7 +411,7 @@ func TestNewInterceptedTransaction_NilKeyGenShouldErr(t *testing.T) { mock.NewOneShardCoordinatorMock(), &economicsmocks.EconomicsHandlerStub{}, &testscommon.WhiteListHandlerStub{}, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, []byte("chainID"), false, &hashingMocks.HasherMock{}, @@ -438,7 +438,7 @@ func TestNewInterceptedTransaction_NilSignerShouldErr(t *testing.T) { mock.NewOneShardCoordinatorMock(), &economicsmocks.EconomicsHandlerStub{}, &testscommon.WhiteListHandlerStub{}, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, []byte("chainID"), false, &hashingMocks.HasherMock{}, @@ -465,7 +465,7 @@ func TestNewInterceptedTransaction_NilPubkeyConverterShouldErr(t *testing.T) { mock.NewOneShardCoordinatorMock(), &economicsmocks.EconomicsHandlerStub{}, &testscommon.WhiteListHandlerStub{}, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, []byte("chainID"), false, &hashingMocks.HasherMock{}, @@ -492,7 +492,7 @@ func TestNewInterceptedTransaction_NilCoordinatorShouldErr(t *testing.T) { nil, &economicsmocks.EconomicsHandlerStub{}, &testscommon.WhiteListHandlerStub{}, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, []byte("chainID"), false, &hashingMocks.HasherMock{}, @@ -519,7 +519,7 @@ func TestNewInterceptedTransaction_NilFeeHandlerShouldErr(t *testing.T) { mock.NewOneShardCoordinatorMock(), nil, &testscommon.WhiteListHandlerStub{}, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, []byte("chainID"), false, &hashingMocks.HasherMock{}, @@ -546,7 +546,7 @@ func TestNewInterceptedTransaction_NilWhiteListerVerifiedTxsShouldErr(t *testing mock.NewOneShardCoordinatorMock(), &economicsmocks.EconomicsHandlerStub{}, nil, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, []byte("chainID"), false, &hashingMocks.HasherMock{}, @@ -573,7 +573,7 @@ func TestNewInterceptedTransaction_InvalidChainIDShouldErr(t *testing.T) { mock.NewOneShardCoordinatorMock(), &economicsmocks.EconomicsHandlerStub{}, &testscommon.WhiteListHandlerStub{}, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, nil, false, &hashingMocks.HasherMock{}, @@ -600,7 +600,7 @@ func TestNewInterceptedTransaction_NilTxSignHasherShouldErr(t *testing.T) { mock.NewOneShardCoordinatorMock(), &economicsmocks.EconomicsHandlerStub{}, &testscommon.WhiteListHandlerStub{}, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, []byte("chainID"), false, nil, @@ -627,7 +627,7 @@ func TestNewInterceptedTransaction_NilEnableEpochsHandlerShouldErr(t *testing.T) mock.NewOneShardCoordinatorMock(), &economicsmocks.EconomicsHandlerStub{}, &testscommon.WhiteListHandlerStub{}, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, []byte("chainID"), false, &hashingMocks.HasherMock{}, @@ -654,7 +654,7 @@ func TestNewInterceptedTransaction_NilRelayedV3ProcessorShouldErr(t *testing.T) mock.NewOneShardCoordinatorMock(), &economicsmocks.EconomicsHandlerStub{}, &testscommon.WhiteListHandlerStub{}, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, []byte("chainID"), false, &hashingMocks.HasherMock{}, @@ -687,7 +687,7 @@ func TestNewInterceptedTransaction_UnmarshalingTxFailsShouldErr(t *testing.T) { mock.NewOneShardCoordinatorMock(), &economicsmocks.EconomicsHandlerStub{}, &testscommon.WhiteListHandlerStub{}, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, []byte("chainID"), false, &hashingMocks.HasherMock{}, @@ -1185,7 +1185,7 @@ func TestInterceptedTransaction_CheckValiditySignedWithHashButNotEnabled(t *test shardCoordinator, createFreeTxFeeHandler(), &testscommon.WhiteListHandlerStub{}, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, chainID, false, &hashingMocks.HasherMock{}, @@ -1247,7 +1247,7 @@ func TestInterceptedTransaction_CheckValiditySignedWithHashShouldWork(t *testing shardCoordinator, createFreeTxFeeHandler(), &testscommon.WhiteListHandlerStub{}, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, chainID, true, &hashingMocks.HasherMock{}, @@ -1334,7 +1334,7 @@ func TestInterceptedTransaction_ScTxDeployRecvShardIdShouldBeSendersShardId(t *t shardCoordinator, createFreeTxFeeHandler(), &testscommon.WhiteListHandlerStub{}, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, chainID, false, &hashingMocks.HasherMock{}, @@ -1500,7 +1500,7 @@ func TestInterceptedTransaction_CheckValiditySecondTimeDoesNotVerifySig(t *testi shardCoordinator, createFreeTxFeeHandler(), whiteListerVerifiedTxs, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, chainID, false, &hashingMocks.HasherMock{}, @@ -1834,7 +1834,7 @@ func TestInterceptedTransaction_CheckValidityOfRelayedTxV3(t *testing.T) { mock.NewMultipleShardsCoordinatorMock(), createFreeTxFeeHandler(), &testscommon.WhiteListHandlerStub{}, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, txCopy.ChainID, false, &hashingMocks.HasherMock{}, @@ -1986,7 +1986,7 @@ func TestInterceptedTransaction_Fee(t *testing.T) { shardCoordinator, createFreeTxFeeHandler(), &testscommon.WhiteListHandlerStub{}, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, []byte("T"), false, &hashingMocks.HasherMock{}, @@ -2031,7 +2031,7 @@ func TestInterceptedTransaction_String(t *testing.T) { shardCoordinator, createFreeTxFeeHandler(), &testscommon.WhiteListHandlerStub{}, - &mock.ArgumentParserMock{}, + &testscommon.ArgumentParserMock{}, []byte("T"), false, &hashingMocks.HasherMock{}, diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index 4c27d1b17ce..a601c1af81d 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -90,7 +90,7 @@ func createArgsForTxProcessor() txproc.ArgsNewTxProcessor { EconomicsFee: feeHandlerMock(), ReceiptForwarder: &mock.IntermediateTransactionHandlerMock{}, BadTxForwarder: &mock.IntermediateTransactionHandlerMock{}, - ArgsParser: &mock.ArgumentParserMock{}, + ArgsParser: &testscommon.ArgumentParserMock{}, ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.PenalizedTooMuchGasFlag, common.FixRelayedBaseCostFlag), GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, @@ -1514,8 +1514,8 @@ func TestTxProcessor_ProcessTxFeeMoveBalanceUserTx(t *testing.T) { cost, totalCost, err := execTx.ProcessTxFee(tx, acntSnd, nil, process.MoveBalance, true) assert.Nil(t, err) - assert.True(t, cost.Cmp(big.NewInt(0).Add(moveBalanceFee, processingFee)) == 0) - assert.True(t, totalCost.Cmp(big.NewInt(0).Add(moveBalanceFee, processingFee)) == 0) + assert.True(t, cost.Cmp(moveBalanceFee) == 0) + assert.True(t, totalCost.Cmp(moveBalanceFee) == 0) } func TestTxProcessor_ProcessTxFeeSCInvokeUserTx(t *testing.T) { @@ -1885,7 +1885,7 @@ func TestTxProcessor_ProcessRelayedTransactionV2ArgsParserShouldErr(t *testing.T parseError := errors.New("parse error") args := createArgsForTxProcessor() - args.ArgsParser = &mock.ArgumentParserMock{ + args.ArgsParser = &testscommon.ArgumentParserMock{ ParseCallDataCalled: func(data string) (string, [][]byte, error) { return "", nil, parseError }} @@ -2701,7 +2701,7 @@ func TestTxProcessor_ProcessRelayedTransactionArgsParserErrorShouldError(t *test parseError := errors.New("parse error") args := createArgsForTxProcessor() - args.ArgsParser = &mock.ArgumentParserMock{ + args.ArgsParser = &testscommon.ArgumentParserMock{ ParseCallDataCalled: func(data string) (string, [][]byte, error) { return "", nil, parseError }} @@ -2764,7 +2764,7 @@ func TestTxProcessor_ProcessRelayedTransactionMultipleArgumentsShouldError(t *te tx.Data = []byte(core.RelayedTransaction + "@" + hex.EncodeToString(userTxMarshalled)) args := createArgsForTxProcessor() - args.ArgsParser = &mock.ArgumentParserMock{ + args.ArgsParser = &testscommon.ArgumentParserMock{ ParseCallDataCalled: func(data string) (string, [][]byte, error) { return core.RelayedTransaction, [][]byte{[]byte("0"), []byte("1")}, nil }} @@ -2827,7 +2827,7 @@ func TestTxProcessor_ProcessRelayedTransactionFailUnMarshalInnerShouldError(t *t tx.Data = []byte(core.RelayedTransaction + "@" + hex.EncodeToString(userTxMarshalled)) args := createArgsForTxProcessor() - args.ArgsParser = &mock.ArgumentParserMock{ + args.ArgsParser = &testscommon.ArgumentParserMock{ ParseCallDataCalled: func(data string) (string, [][]byte, error) { return core.RelayedTransaction, [][]byte{[]byte("0")}, nil }} @@ -2890,7 +2890,7 @@ func TestTxProcessor_ProcessRelayedTransactionDifferentSenderInInnerTxThanReceiv tx.Data = []byte(core.RelayedTransaction + "@" + hex.EncodeToString(userTxMarshalled)) args := createArgsForTxProcessor() - args.ArgsParser = &mock.ArgumentParserMock{ + args.ArgsParser = &testscommon.ArgumentParserMock{ ParseCallDataCalled: func(data string) (string, [][]byte, error) { return core.RelayedTransaction, [][]byte{userTxMarshalled}, nil }} @@ -2953,7 +2953,7 @@ func TestTxProcessor_ProcessRelayedTransactionSmallerValueInnerTxShouldError(t * tx.Data = []byte(core.RelayedTransaction + "@" + hex.EncodeToString(userTxMarshalled)) args := createArgsForTxProcessor() - args.ArgsParser = &mock.ArgumentParserMock{ + args.ArgsParser = &testscommon.ArgumentParserMock{ ParseCallDataCalled: func(data string) (string, [][]byte, error) { return core.RelayedTransaction, [][]byte{userTxMarshalled}, nil }} @@ -3016,7 +3016,7 @@ func TestTxProcessor_ProcessRelayedTransactionGasPriceMismatchShouldError(t *tes tx.Data = []byte(core.RelayedTransaction + "@" + hex.EncodeToString(userTxMarshalled)) args := createArgsForTxProcessor() - args.ArgsParser = &mock.ArgumentParserMock{ + args.ArgsParser = &testscommon.ArgumentParserMock{ ParseCallDataCalled: func(data string) (string, [][]byte, error) { return core.RelayedTransaction, [][]byte{userTxMarshalled}, nil }} @@ -3079,7 +3079,7 @@ func TestTxProcessor_ProcessRelayedTransactionGasLimitMismatchShouldError(t *tes tx.Data = []byte(core.RelayedTransaction + "@" + hex.EncodeToString(userTxMarshalled)) args := createArgsForTxProcessor() - args.ArgsParser = &mock.ArgumentParserMock{ + args.ArgsParser = &testscommon.ArgumentParserMock{ ParseCallDataCalled: func(data string) (string, [][]byte, error) { return core.RelayedTransaction, [][]byte{userTxMarshalled}, nil }} @@ -3275,7 +3275,7 @@ func TestTxProcessor_ProcessUserTxOfTypeRelayedShouldError(t *testing.T) { tx.Data = []byte(core.RelayedTransaction + "@" + hex.EncodeToString(userTxMarshalled)) args := createArgsForTxProcessor() - args.ArgsParser = &mock.ArgumentParserMock{ + args.ArgsParser = &testscommon.ArgumentParserMock{ ParseCallDataCalled: func(data string) (string, [][]byte, error) { return core.RelayedTransaction, [][]byte{userTxMarshalled}, nil }} @@ -3338,7 +3338,7 @@ func TestTxProcessor_ProcessUserTxOfTypeMoveBalanceShouldWork(t *testing.T) { tx.Data = []byte(core.RelayedTransaction + "@" + hex.EncodeToString(userTxMarshalled)) args := createArgsForTxProcessor() - args.ArgsParser = &mock.ArgumentParserMock{ + args.ArgsParser = &testscommon.ArgumentParserMock{ ParseCallDataCalled: func(data string) (string, [][]byte, error) { return core.RelayedTransaction, [][]byte{userTxMarshalled}, nil }} @@ -3401,7 +3401,7 @@ func TestTxProcessor_ProcessUserTxOfTypeSCDeploymentShouldWork(t *testing.T) { tx.Data = []byte(core.RelayedTransaction + "@" + hex.EncodeToString(userTxMarshalled)) args := createArgsForTxProcessor() - args.ArgsParser = &mock.ArgumentParserMock{ + args.ArgsParser = &testscommon.ArgumentParserMock{ ParseCallDataCalled: func(data string) (string, [][]byte, error) { return core.RelayedTransaction, [][]byte{userTxMarshalled}, nil }} @@ -3464,7 +3464,7 @@ func TestTxProcessor_ProcessUserTxOfTypeSCInvokingShouldWork(t *testing.T) { tx.Data = []byte(core.RelayedTransaction + "@" + hex.EncodeToString(userTxMarshalled)) args := createArgsForTxProcessor() - args.ArgsParser = &mock.ArgumentParserMock{ + args.ArgsParser = &testscommon.ArgumentParserMock{ ParseCallDataCalled: func(data string) (string, [][]byte, error) { return core.RelayedTransaction, [][]byte{userTxMarshalled}, nil }} @@ -3527,7 +3527,7 @@ func TestTxProcessor_ProcessUserTxOfTypeBuiltInFunctionCallShouldWork(t *testing tx.Data = []byte(core.RelayedTransaction + "@" + hex.EncodeToString(userTxMarshalled)) args := createArgsForTxProcessor() - args.ArgsParser = &mock.ArgumentParserMock{ + args.ArgsParser = &testscommon.ArgumentParserMock{ ParseCallDataCalled: func(data string) (string, [][]byte, error) { return core.RelayedTransaction, [][]byte{userTxMarshalled}, nil }} @@ -3590,7 +3590,7 @@ func TestTxProcessor_ProcessUserTxErrNotPayableShouldFailRelayTx(t *testing.T) { tx.Data = []byte(core.RelayedTransaction + "@" + hex.EncodeToString(userTxMarshalled)) args := createArgsForTxProcessor() - args.ArgsParser = &mock.ArgumentParserMock{ + args.ArgsParser = &testscommon.ArgumentParserMock{ ParseCallDataCalled: func(data string) (string, [][]byte, error) { return core.RelayedTransaction, [][]byte{userTxMarshalled}, nil }} @@ -3657,7 +3657,7 @@ func TestTxProcessor_ProcessUserTxFailedBuiltInFunctionCall(t *testing.T) { tx.Data = []byte(core.RelayedTransaction + "@" + hex.EncodeToString(userTxMarshalled)) args := createArgsForTxProcessor() - args.ArgsParser = &mock.ArgumentParserMock{ + args.ArgsParser = &testscommon.ArgumentParserMock{ ParseCallDataCalled: func(data string) (string, [][]byte, error) { return core.RelayedTransaction, [][]byte{userTxMarshalled}, nil }} diff --git a/epochStart/mock/argumentsParserMock.go b/testscommon/argumentsParserMock.go similarity index 98% rename from epochStart/mock/argumentsParserMock.go rename to testscommon/argumentsParserMock.go index 02ce8f408ae..b23b66b682b 100644 --- a/epochStart/mock/argumentsParserMock.go +++ b/testscommon/argumentsParserMock.go @@ -1,4 +1,4 @@ -package mock +package testscommon import ( vmcommon "github.com/multiversx/mx-chain-vm-common-go" diff --git a/testscommon/stakingcommon/stakingCommon.go b/testscommon/stakingcommon/stakingCommon.go index 1af9b441b9c..6b85d5a238a 100644 --- a/testscommon/stakingcommon/stakingCommon.go +++ b/testscommon/stakingcommon/stakingCommon.go @@ -9,6 +9,7 @@ import ( "github.com/multiversx/mx-chain-go/genesis/process/disabled" "github.com/multiversx/mx-chain-go/process" economicsHandler "github.com/multiversx/mx-chain-go/process/economics" + "github.com/multiversx/mx-chain-go/process/smartContract" "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" @@ -277,6 +278,7 @@ func CreateEconomicsData() process.EconomicsDataHandler { EpochNotifier: &epochNotifier.EpochNotifierStub{}, EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, TxVersionChecker: &disabled.TxVersionChecker{}, + ArgumentParser: smartContract.NewArgumentParser(), } economicsData, _ := economicsHandler.NewEconomicsData(argsNewEconomicsData) return economicsData From 53ca5097b4d158a22a5d4718c4faa8831ffb570a Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 26 Jun 2024 15:58:07 +0300 Subject: [PATCH 384/503] fix modify creator test --- .../vm/esdtImprovements_test.go | 85 +++++++++++-------- 1 file changed, 50 insertions(+), 35 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 06a78619282..3f7156898f1 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -1328,17 +1328,22 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) require.Nil(t, err) - log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") + log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag). Register NFT directly as dynamic") addrs := createAddresses(t, cs, false) // issue metaESDT - metaESDTTicker := []byte("METATTICKER") - tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + metaESDTTicker := []byte("METATICKER") + tx := issueMetaESDTTx(0, addrs[1].Bytes, metaESDTTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) + + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + require.Equal(t, "success", txResult.Status.String()) metaESDTTokenID := txResult.Logs.Events[0].Topics[0] @@ -1348,27 +1353,53 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { []byte(core.ESDTRoleTransfer), []byte(core.ESDTRoleNFTUpdate), } - setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + setAddressEsdtRoles(t, cs, addrs[1], metaESDTTokenID, roles) log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) - // issue NFT + // register dynamic NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + nftTokenName := []byte("tokenName") + + txDataField := bytes.Join( + [][]byte{ + []byte("registerDynamic"), + []byte(hex.EncodeToString(nftTokenName)), + []byte(hex.EncodeToString(nftTicker)), + []byte(hex.EncodeToString([]byte("NFT"))), + }, + []byte("@"), + ) + + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + + tx = &transaction.Transaction{ + Nonce: 1, + SndAddr: addrs[1].Bytes, + RcvAddr: vm.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: callValue, + ChainID: []byte(configs.ChainID), + Version: 1, + } txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, addrs[1], nftTokenID, roles) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(2, addrs[1].Bytes, sftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1376,12 +1407,12 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + setAddressEsdtRoles(t, cs, addrs[1], sftTokenID, roles) log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) tokenIDs := [][]byte{ - // nftTokenID, + nftTokenID, sftTokenID, metaESDTTokenID, } @@ -1396,57 +1427,50 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tokensMetadata := []*txsFee.MetaData{ - // nftMetaData, + nftMetaData, sftMetaData, esdtMetaData, } nonce := uint64(3) for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = nftCreateTx(nonce, addrs[1].Bytes, tokenIDs[i], tokensMetadata[i]) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) nonce++ } + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + log.Info("Change to DYNAMIC type") for i := range tokenIDs { - tx = changeToDynamicTx(nonce, addrs[0].Bytes, tokenIDs[i]) + tx = changeToDynamicTx(nonce, addrs[1].Bytes, tokenIDs[i]) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) require.Equal(t, "success", txResult.Status.String()) nonce++ } - err = cs.GenerateBlocks(10) - require.Nil(t, err) - log.Info("Call ESDTModifyCreator and check that the creator was modified") mintValue := big.NewInt(10) mintValue = mintValue.Mul(oneEGLD, mintValue) - shardID := uint32(0) + shardID := uint32(1) for i := range tokenIDs { - log.Info("Modify creator for token", "tokenID", string(tokenIDs[i])) + log.Info("Modify creator for token", "tokenID", tokenIDs[i]) newCreatorAddress, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) require.Nil(t, err) @@ -1485,18 +1509,9 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) - var retrievedMetaData *esdt.MetaData - if bytes.Equal(tokenIDs[i], tokenIDs[0]) { // nft token - retrievedMetaData = getMetaDataFromAcc(t, cs, addrs[0].Bytes, tokenIDs[i], shardID) - } else { - retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID) - } + retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID) require.Equal(t, newCreatorAddress.Bytes, retrievedMetaData.Creator) From 7a5a0748c1073c51963af277696f79eec150ce12 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 26 Jun 2024 16:22:19 +0300 Subject: [PATCH 385/503] added func for chain simulator with dynamic nfts enabled --- .../vm/esdtImprovements_test.go | 290 +++--------------- 1 file changed, 49 insertions(+), 241 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 3f7156898f1..cba5d1158e4 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -699,49 +699,13 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { t.Skip("this is not a short test") } - startTime := time.Now().Unix() - roundDurationInMillis := uint64(6000) - roundsPerEpoch := core.OptionalUint64{ - HasValue: true, - Value: 20, - } - - activationEpoch := uint32(2) - baseIssuingCost := "1000" - numOfShards := uint32(3) - cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: true, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, - AlterConfigsFunction: func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch - cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost - }, - }) - require.Nil(t, err) - require.NotNil(t, cs) - + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() addrs := createAddresses(t, cs, false) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) - require.Nil(t, err) - - err = cs.GenerateBlocks(10) - require.Nil(t, err) - log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") // issue metaESDT @@ -876,51 +840,15 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { t.Skip("this is not a short test") } - startTime := time.Now().Unix() - roundDurationInMillis := uint64(6000) - roundsPerEpoch := core.OptionalUint64{ - HasValue: true, - Value: 20, - } - - activationEpoch := uint32(2) - baseIssuingCost := "1000" - numOfShards := uint32(3) - cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: true, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, - AlterConfigsFunction: func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch - cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost - }, - }) - require.Nil(t, err) - require.NotNil(t, cs) - + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() - addrs := createAddresses(t, cs, false) - - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) - require.Nil(t, err) - - err = cs.GenerateBlocks(10) - require.Nil(t, err) - log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") + addrs := createAddresses(t, cs, false) + // issue metaESDT metaESDTTicker := []byte("METATTICKER") tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) @@ -941,23 +869,9 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) - // issue fungible - fungibleTicker := []byte("FUNTICKER") - tx = issueTx(1, addrs[0].Bytes, fungibleTicker, baseIssuingCost) - - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - - fungibleTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], fungibleTokenID, roles) - - log.Info("Issued fungible token id", "tokenID", string(fungibleTokenID)) - // issue NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(2, addrs[0].Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -971,7 +885,7 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(3, addrs[0].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -987,7 +901,6 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { nftTokenID, sftTokenID, metaESDTTokenID, - fungibleTokenID, } nftMetaData := txsFee.GetDefaultMetaData() @@ -999,17 +912,13 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { esdtMetaData := txsFee.GetDefaultMetaData() esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - fungibleMetaData := txsFee.GetDefaultMetaData() - fungibleMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tokensMetadata := []*txsFee.MetaData{ nftMetaData, sftMetaData, esdtMetaData, - fungibleMetaData, } - nonce := uint64(4) + nonce := uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) @@ -1066,10 +975,6 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - // fmt.Println(txResult) - // fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - // fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) @@ -1095,44 +1000,11 @@ func TestChainSimulator_NFT_ESDTMetaDataUpdate(t *testing.T) { t.Skip("this is not a short test") } - startTime := time.Now().Unix() - roundDurationInMillis := uint64(6000) - roundsPerEpoch := core.OptionalUint64{ - HasValue: true, - Value: 20, - } - - activationEpoch := uint32(2) - baseIssuingCost := "1000" - numOfShards := uint32(3) - cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: true, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, - AlterConfigsFunction: func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch - cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost - }, - }) - require.Nil(t, err) - require.NotNil(t, cs) - + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) - require.Nil(t, err) - log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") addrs := createAddresses(t, cs, false) @@ -1290,44 +1162,11 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { t.Skip("this is not a short test") } - startTime := time.Now().Unix() - roundDurationInMillis := uint64(6000) - roundsPerEpoch := core.OptionalUint64{ - HasValue: true, - Value: 20, - } - - activationEpoch := uint32(4) - baseIssuingCost := "1000" - numOfShards := uint32(3) - cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: true, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, - AlterConfigsFunction: func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch - cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost - }, - }) - require.Nil(t, err) - require.NotNil(t, cs) - + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) - require.Nil(t, err) - log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag). Register NFT directly as dynamic") addrs := createAddresses(t, cs, false) @@ -1445,9 +1284,6 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { nonce++ } - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) - require.Nil(t, err) - log.Info("Change to DYNAMIC type") for i := range tokenIDs { @@ -1530,44 +1366,11 @@ func TestChainSimulator_NFT_ESDTSetNewURIs(t *testing.T) { t.Skip("this is not a short test") } - startTime := time.Now().Unix() - roundDurationInMillis := uint64(6000) - roundsPerEpoch := core.OptionalUint64{ - HasValue: true, - Value: 20, - } - - activationEpoch := uint32(2) - baseIssuingCost := "1000" - numOfShards := uint32(3) - cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: true, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, - AlterConfigsFunction: func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch - cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost - }, - }) - require.Nil(t, err) - require.NotNil(t, cs) - + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) - require.Nil(t, err) - log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") addrs := createAddresses(t, cs, false) @@ -1733,46 +1536,13 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { t.Skip("this is not a short test") } - startTime := time.Now().Unix() - roundDurationInMillis := uint64(6000) - roundsPerEpoch := core.OptionalUint64{ - HasValue: true, - Value: 20, - } - - activationEpoch := uint32(2) - baseIssuingCost := "1000" - numOfShards := uint32(3) - cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: true, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, - AlterConfigsFunction: func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch - cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost - }, - }) - require.Nil(t, err) - require.NotNil(t, cs) - + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() addrs := createAddresses(t, cs, false) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) - require.Nil(t, err) - // issue metaESDT metaESDTTicker := []byte("METATTICKER") tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) @@ -3300,6 +3070,44 @@ func TestChainSimulator_MetaESDTCreatedBeforeSaveToSystemAccountEnabled(t *testi checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, metaTokenID, shardID) } +func getTestChainSimulatorWithDynamicNFTEnabled(t *testing.T, baseIssuingCost string) (testsChainSimulator.ChainSimulator, int32) { + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpochForDynamicNFT := uint32(2) + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: true, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpochForDynamicNFT + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpochForDynamicNFT)) + require.Nil(t, err) + + return cs, int32(activationEpochForDynamicNFT) +} + func getTestChainSimulatorWithSaveToSystemAccountDisabled(t *testing.T, baseIssuingCost string) (testsChainSimulator.ChainSimulator, int32) { startTime := time.Now().Unix() roundDurationInMillis := uint64(6000) From 9b1340613865df88fb21a5c65b77dd3919f7b13f Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 26 Jun 2024 17:09:33 +0300 Subject: [PATCH 386/503] fix test after merge --- integrationTests/chainSimulator/relayedTx/relayedTx_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index 38e5f56f806..29637aa1efc 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -268,8 +268,8 @@ func TestFixRelayedMoveBalanceWithChainSimulator(t *testing.T) { t.Skip("this is not a short test") } - expectedFeeScCallBefore := "815285920000000" - expectedFeeScCallAfter := "873695920000000" + expectedFeeScCallBefore := "815294920000000" + expectedFeeScCallAfter := "873704920000000" t.Run("sc call", testFixRelayedMoveBalanceWithChainSimulatorScCall(expectedFeeScCallBefore, expectedFeeScCallAfter)) expectedFeeMoveBalanceBefore := "797500000000000" // 498 * 1500 + 50000 + 5000 From c4dc47d24a6881d32aa8fe86e1acbeab7a494ab5 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 26 Jun 2024 17:25:19 +0300 Subject: [PATCH 387/503] change to dynamic old tokens scenario --- .../vm/esdtImprovements_test.go | 417 ++++++------------ 1 file changed, 142 insertions(+), 275 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index cba5d1158e4..8f075e5b95d 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -1804,49 +1804,13 @@ func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { t.Skip("this is not a short test") } - startTime := time.Now().Unix() - roundDurationInMillis := uint64(6000) - roundsPerEpoch := core.OptionalUint64{ - HasValue: true, - Value: 20, - } - - activationEpoch := uint32(2) - baseIssuingCost := "1000" - numOfShards := uint32(3) - cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: true, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, - AlterConfigsFunction: func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch - cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost - }, - }) - require.Nil(t, err) - require.NotNil(t, cs) - + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() addrs := createAddresses(t, cs, true) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) - require.Nil(t, err) - - err = cs.GenerateBlocks(10) - require.Nil(t, err) - log.Info("Initial setup: Create SFT and send in 2 shards") roles := [][]byte{ @@ -2051,46 +2015,13 @@ func TestChainSimulator_NFT_RegisterDynamic(t *testing.T) { t.Skip("this is not a short test") } - startTime := time.Now().Unix() - roundDurationInMillis := uint64(6000) - roundsPerEpoch := core.OptionalUint64{ - HasValue: true, - Value: 20, - } - - activationEpoch := uint32(2) - baseIssuingCost := "1000" - numOfShards := uint32(3) - cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: true, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, - AlterConfigsFunction: func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch - cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost - }, - }) - require.Nil(t, err) - require.NotNil(t, cs) - + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() addrs := createAddresses(t, cs, true) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) - require.Nil(t, err) - log.Info("Register dynamic nft token") nftTicker := []byte("NFTTICKER") @@ -2174,46 +2105,13 @@ func TestChainSimulator_MetaESDT_RegisterDynamic(t *testing.T) { t.Skip("this is not a short test") } - startTime := time.Now().Unix() - roundDurationInMillis := uint64(6000) - roundsPerEpoch := core.OptionalUint64{ - HasValue: true, - Value: 20, - } - - activationEpoch := uint32(2) - baseIssuingCost := "1000" - numOfShards := uint32(3) - cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: true, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, - AlterConfigsFunction: func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch - cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost - }, - }) - require.Nil(t, err) - require.NotNil(t, cs) - + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() addrs := createAddresses(t, cs, true) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) - require.Nil(t, err) - log.Info("Register dynamic metaESDT token") metaTicker := []byte("METATICKER") @@ -2300,46 +2198,13 @@ func TestChainSimulator_FNG_RegisterDynamic(t *testing.T) { t.Skip("this is not a short test") } - startTime := time.Now().Unix() - roundDurationInMillis := uint64(6000) - roundsPerEpoch := core.OptionalUint64{ - HasValue: true, - Value: 20, - } - - activationEpoch := uint32(2) - baseIssuingCost := "1000" - numOfShards := uint32(3) - cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: true, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, - AlterConfigsFunction: func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch - cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost - }, - }) - require.Nil(t, err) - require.NotNil(t, cs) - + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() addrs := createAddresses(t, cs, true) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) - require.Nil(t, err) - log.Info("Register dynamic fungible token") metaTicker := []byte("FNGTICKER") @@ -2387,46 +2252,13 @@ func TestChainSimulator_NFT_RegisterAndSetAllRolesDynamic(t *testing.T) { t.Skip("this is not a short test") } - startTime := time.Now().Unix() - roundDurationInMillis := uint64(6000) - roundsPerEpoch := core.OptionalUint64{ - HasValue: true, - Value: 20, - } - - activationEpoch := uint32(2) - baseIssuingCost := "1000" - numOfShards := uint32(3) - cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: true, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, - AlterConfigsFunction: func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch - cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost - }, - }) - require.Nil(t, err) - require.NotNil(t, cs) - + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() addrs := createAddresses(t, cs, true) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) - require.Nil(t, err) - log.Info("Register dynamic nft token") nftTicker := []byte("NFTTICKER") @@ -2536,46 +2368,13 @@ func TestChainSimulator_SFT_RegisterAndSetAllRolesDynamic(t *testing.T) { t.Skip("this is not a short test") } - startTime := time.Now().Unix() - roundDurationInMillis := uint64(6000) - roundsPerEpoch := core.OptionalUint64{ - HasValue: true, - Value: 20, - } - - activationEpoch := uint32(2) - baseIssuingCost := "1000" - numOfShards := uint32(3) - cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: true, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, - AlterConfigsFunction: func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch - cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost - }, - }) - require.Nil(t, err) - require.NotNil(t, cs) - + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() addrs := createAddresses(t, cs, true) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) - require.Nil(t, err) - log.Info("Register dynamic sft token") sftTicker := []byte("SFTTICKER") @@ -2685,46 +2484,13 @@ func TestChainSimulator_FNG_RegisterAndSetAllRolesDynamic(t *testing.T) { t.Skip("this is not a short test") } - startTime := time.Now().Unix() - roundDurationInMillis := uint64(6000) - roundsPerEpoch := core.OptionalUint64{ - HasValue: true, - Value: 20, - } - - activationEpoch := uint32(2) - baseIssuingCost := "1000" - numOfShards := uint32(3) - cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: true, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, - AlterConfigsFunction: func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch - cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost - }, - }) - require.Nil(t, err) - require.NotNil(t, cs) - + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() addrs := createAddresses(t, cs, true) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) - require.Nil(t, err) - log.Info("Register dynamic fungible token") fngTicker := []byte("FNGTICKER") @@ -2770,46 +2536,13 @@ func TestChainSimulator_MetaESDT_RegisterAndSetAllRolesDynamic(t *testing.T) { t.Skip("this is not a short test") } - startTime := time.Now().Unix() - roundDurationInMillis := uint64(6000) - roundsPerEpoch := core.OptionalUint64{ - HasValue: true, - Value: 20, - } - - activationEpoch := uint32(2) - baseIssuingCost := "1000" - numOfShards := uint32(3) - cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: true, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, - AlterConfigsFunction: func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch - cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost - }, - }) - require.Nil(t, err) - require.NotNil(t, cs) - + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() addrs := createAddresses(t, cs, true) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) - require.Nil(t, err) - log.Info("Register dynamic meta esdt token") ticker := []byte("META" + "TICKER") @@ -3200,3 +2933,137 @@ func createTokenUpdateTokenIDAndTransfer( require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) } + +func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + baseIssuingCost := "1000" + + cs, epochForDynamicNFT := getTestChainSimulatorWithSaveToSystemAccountDisabled(t, baseIssuingCost) + defer cs.Close() + + addrs := createAddresses(t, cs, false) + + // issue metaESDT + metaESDTTicker := []byte("METATTICKER") + tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + metaESDTTokenID := txResult.Logs.Events[0].Topics[0] + + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + } + setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + + log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) + + // issue NFT + nftTicker := []byte("NFTTICKER") + tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) + + // issue SFT + sftTicker := []byte("SFTTICKER") + tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + sftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + + log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) + + tokenIDs := [][]byte{ + nftTokenID, + sftTokenID, + metaESDTTokenID, + } + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + sftMetaData := txsFee.GetDefaultMetaData() + sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + esdtMetaData := txsFee.GetDefaultMetaData() + esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tokensMetadata := []*txsFee.MetaData{ + nftMetaData, + sftMetaData, + esdtMetaData, + } + + nonce := uint64(3) + for i := range tokenIDs { + tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } + + shardID := uint32(0) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) + + checkMetaData(t, cs, addrs[0].Bytes, sftTokenID, shardID, sftMetaData) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, sftTokenID, shardID) + + checkMetaData(t, cs, addrs[0].Bytes, metaESDTTokenID, shardID, esdtMetaData) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(epochForDynamicNFT)) + require.Nil(t, err) + + log.Info("Change to DYNAMIC type") + + for i := range tokenIDs { + tx = changeToDynamicTx(nonce, addrs[0].Bytes, tokenIDs[i]) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } + + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, sftTokenID, shardID) + + checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, metaESDTTokenID, shardID) +} From 5139fa9463ceac49a8ba8c7e5c8f358a82a9e3cd Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 26 Jun 2024 18:47:49 +0300 Subject: [PATCH 388/503] fix after review, use real txTypeHandler with a setter --- factory/api/apiResolverFactory.go | 5 +++ factory/core/coreComponents.go | 2 - factory/processing/blockProcessorCreator.go | 10 +++++ .../txSimulatorProcessComponents.go | 10 +++++ genesis/mock/coreComponentsMock.go | 6 +++ genesis/process/argGenesisBlockCreator.go | 1 + genesis/process/genesisBlockCreator_test.go | 4 +- genesis/process/metaGenesisBlockCreator.go | 5 +++ genesis/process/shardGenesisBlockCreator.go | 5 +++ integrationTests/testProcessorNode.go | 3 +- .../testProcessorNodeWithTestWebServer.go | 1 + integrationTests/vm/testInitializer.go | 3 +- integrationTests/vm/wasm/utils.go | 1 - .../components/coreComponents.go | 2 - .../timemachine/fee/feeComputer_test.go | 1 - .../fee/memoryFootprint/memory_test.go | 1 - .../gasUsedAndFeeProcessor_test.go | 1 - process/disabled/txTypeHandler.go | 28 +++++++++++++ process/economics/economicsData.go | 40 ++++++++++--------- process/economics/economicsData_test.go | 12 ------ .../metachain/vmContainerFactory_test.go | 1 - process/interface.go | 1 + process/peer/process_test.go | 1 - process/smartContract/process_test.go | 1 - .../smartContract/processorV2/process_test.go | 1 - .../economicsDataHandlerStub.go | 10 +++++ .../economicsmocks/economicsHandlerMock.go | 10 +++++ testscommon/stakingcommon/stakingCommon.go | 2 - 28 files changed, 120 insertions(+), 48 deletions(-) create mode 100644 process/disabled/txTypeHandler.go diff --git a/factory/api/apiResolverFactory.go b/factory/api/apiResolverFactory.go index dfefa56ff94..90edb620860 100644 --- a/factory/api/apiResolverFactory.go +++ b/factory/api/apiResolverFactory.go @@ -185,6 +185,11 @@ func CreateApiResolver(args *ApiResolverArgs) (facade.ApiResolver, error) { return nil, err } + err = args.CoreComponents.EconomicsData().SetTxTypeHandler(txTypeHandler) + if err != nil { + return nil, err + } + accountsWrapper := &trieIterators.AccountsWrapper{ Mutex: &sync.Mutex{}, AccountsAdapter: args.StateComponents.AccountsAdapterAPI(), diff --git a/factory/core/coreComponents.go b/factory/core/coreComponents.go index 1656a042de0..247ee7e05f8 100644 --- a/factory/core/coreComponents.go +++ b/factory/core/coreComponents.go @@ -33,7 +33,6 @@ import ( "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/economics" "github.com/multiversx/mx-chain-go/process/rating" - "github.com/multiversx/mx-chain-go/process/smartContract" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "github.com/multiversx/mx-chain-go/statusHandler" @@ -253,7 +252,6 @@ func (ccf *coreComponentsFactory) Create() (*coreComponents, error) { EpochNotifier: epochNotifier, EnableEpochsHandler: enableEpochsHandler, TxVersionChecker: txVersionChecker, - ArgumentParser: smartContract.NewArgumentParser(), } economicsData, err := economics.NewEconomicsData(argsNewEconomicsData) if err != nil { diff --git a/factory/processing/blockProcessorCreator.go b/factory/processing/blockProcessorCreator.go index d3a65d66660..93f3e1e95a3 100644 --- a/factory/processing/blockProcessorCreator.go +++ b/factory/processing/blockProcessorCreator.go @@ -228,6 +228,11 @@ func (pcf *processComponentsFactory) newShardBlockProcessor( return nil, err } + err = pcf.coreData.EconomicsData().SetTxTypeHandler(txTypeHandler) + if err != nil { + return nil, err + } + gasHandler, err := preprocess.NewGasComputation( pcf.coreData.EconomicsData(), txTypeHandler, @@ -560,6 +565,11 @@ func (pcf *processComponentsFactory) newMetaBlockProcessor( return nil, err } + err = pcf.coreData.EconomicsData().SetTxTypeHandler(txTypeHandler) + if err != nil { + return nil, err + } + gasHandler, err := preprocess.NewGasComputation( pcf.coreData.EconomicsData(), txTypeHandler, diff --git a/factory/processing/txSimulatorProcessComponents.go b/factory/processing/txSimulatorProcessComponents.go index 21fe2ddc073..65361580358 100644 --- a/factory/processing/txSimulatorProcessComponents.go +++ b/factory/processing/txSimulatorProcessComponents.go @@ -155,6 +155,11 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessorForMeta( return args, nil, nil, err } + err = pcf.coreData.EconomicsData().SetTxTypeHandler(txTypeHandler) + if err != nil { + return args, nil, nil, err + } + gasHandler, err := preprocess.NewGasComputation( pcf.coreData.EconomicsData(), txTypeHandler, @@ -327,6 +332,11 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessorShard( } txFeeHandler := &processDisabled.FeeHandler{} + err = pcf.coreData.EconomicsData().SetTxTypeHandler(txTypeHandler) + if err != nil { + return args, nil, nil, err + } + gasHandler, err := preprocess.NewGasComputation( pcf.coreData.EconomicsData(), txTypeHandler, diff --git a/genesis/mock/coreComponentsMock.go b/genesis/mock/coreComponentsMock.go index fb0907ef8a0..e44dd801243 100644 --- a/genesis/mock/coreComponentsMock.go +++ b/genesis/mock/coreComponentsMock.go @@ -22,6 +22,12 @@ type CoreComponentsMock struct { StatHandler core.AppStatusHandler EnableEpochsHandlerField common.EnableEpochsHandler TxVersionCheck process.TxVersionCheckerHandler + EconomicsDataField process.EconomicsDataHandler +} + +// EconomicsData - +func (ccm *CoreComponentsMock) EconomicsData() process.EconomicsDataHandler { + return ccm.EconomicsDataField } // InternalMarshalizer - diff --git a/genesis/process/argGenesisBlockCreator.go b/genesis/process/argGenesisBlockCreator.go index 19b5fc9adcc..685e356f31b 100644 --- a/genesis/process/argGenesisBlockCreator.go +++ b/genesis/process/argGenesisBlockCreator.go @@ -29,6 +29,7 @@ type coreComponentsHandler interface { TxVersionChecker() process.TxVersionCheckerHandler ChainID() string EnableEpochsHandler() common.EnableEpochsHandler + EconomicsData() process.EconomicsDataHandler IsInterfaceNil() bool } diff --git a/genesis/process/genesisBlockCreator_test.go b/genesis/process/genesisBlockCreator_test.go index b7b788f0d37..a681a0e271c 100644 --- a/genesis/process/genesisBlockCreator_test.go +++ b/genesis/process/genesisBlockCreator_test.go @@ -76,6 +76,7 @@ func createMockArgument( TxVersionCheck: &testscommon.TxVersionCheckerStub{}, MinTxVersion: 1, EnableEpochsHandlerField: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, + EconomicsDataField: &economicsmocks.EconomicsHandlerMock{}, }, Data: &mock.DataComponentsMock{ Storage: &storageCommon.ChainStorerStub{ @@ -307,7 +308,8 @@ func TestNewGenesisBlockCreator(t *testing.T) { arg := createMockArgument(t, "testdata/genesisTest1.json", &mock.InitialNodesHandlerStub{}, big.NewInt(22000)) arg.Core = &mock.CoreComponentsMock{ - AddrPubKeyConv: nil, + AddrPubKeyConv: nil, + EconomicsDataField: &economicsmocks.EconomicsHandlerMock{}, } gbc, err := NewGenesisBlockCreator(arg) diff --git a/genesis/process/metaGenesisBlockCreator.go b/genesis/process/metaGenesisBlockCreator.go index 3a4769889b6..78546562736 100644 --- a/genesis/process/metaGenesisBlockCreator.go +++ b/genesis/process/metaGenesisBlockCreator.go @@ -431,6 +431,11 @@ func createProcessorsForMetaGenesisBlock(arg ArgsGenesisBlockCreator, enableEpoc return nil, err } + err = arg.Core.EconomicsData().SetTxTypeHandler(txTypeHandler) + if err != nil { + return nil, err + } + gasHandler, err := preprocess.NewGasComputation(arg.Economics, txTypeHandler, enableEpochsHandler) if err != nil { return nil, err diff --git a/genesis/process/shardGenesisBlockCreator.go b/genesis/process/shardGenesisBlockCreator.go index 7c2c6af06b3..b44ed14c207 100644 --- a/genesis/process/shardGenesisBlockCreator.go +++ b/genesis/process/shardGenesisBlockCreator.go @@ -501,6 +501,11 @@ func createProcessorsForShardGenesisBlock(arg ArgsGenesisBlockCreator, enableEpo return nil, err } + err = arg.Core.EconomicsData().SetTxTypeHandler(txTypeHandler) + if err != nil { + return nil, err + } + gasHandler, err := preprocess.NewGasComputation(arg.Economics, txTypeHandler, enableEpochsHandler) if err != nil { return nil, err diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index c093df85361..ef55c21f54a 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -1109,7 +1109,6 @@ func (tpn *TestProcessorNode) initEconomicsData(economicsConfig *config.Economic EpochNotifier: tpn.EpochNotifier, EnableEpochsHandler: tpn.EnableEpochsHandler, TxVersionChecker: &testscommon.TxVersionCheckerStub{}, - ArgumentParser: smartContract.NewArgumentParser(), } economicsData, _ := economics.NewEconomicsData(argsNewEconomicsData) tpn.EconomicsData = economics.NewTestEconomicsData(economicsData) @@ -1697,6 +1696,7 @@ func (tpn *TestProcessorNode) initInnerProcessors(gasMap map[string]map[string]u EnableEpochsHandler: tpn.EnableEpochsHandler, } txTypeHandler, _ := coordinator.NewTxTypeHandler(argsTxTypeHandler) + _ = tpn.EconomicsData.SetTxTypeHandler(txTypeHandler) tpn.GasHandler, _ = preprocess.NewGasComputation(tpn.EconomicsData, txTypeHandler, tpn.EnableEpochsHandler) badBlocksHandler, _ := tpn.InterimProcContainer.Get(dataBlock.InvalidBlock) @@ -1986,6 +1986,7 @@ func (tpn *TestProcessorNode) initMetaInnerProcessors(gasMap map[string]map[stri EnableEpochsHandler: tpn.EnableEpochsHandler, } txTypeHandler, _ := coordinator.NewTxTypeHandler(argsTxTypeHandler) + _ = tpn.EconomicsData.SetTxTypeHandler(txTypeHandler) tpn.GasHandler, _ = preprocess.NewGasComputation(tpn.EconomicsData, txTypeHandler, tpn.EnableEpochsHandler) badBlocksHandler, _ := tpn.InterimProcContainer.Get(dataBlock.InvalidBlock) argsNewScProcessor := scrCommon.ArgsNewSmartContractProcessor{ diff --git a/integrationTests/testProcessorNodeWithTestWebServer.go b/integrationTests/testProcessorNodeWithTestWebServer.go index 592d7d1bdba..b380a643660 100644 --- a/integrationTests/testProcessorNodeWithTestWebServer.go +++ b/integrationTests/testProcessorNodeWithTestWebServer.go @@ -162,6 +162,7 @@ func createFacadeComponents(tpn *TestProcessorNode) nodeFacade.ApiResolver { } txTypeHandler, err := coordinator.NewTxTypeHandler(argsTxTypeHandler) log.LogIfError(err) + _ = tpn.EconomicsData.SetTxTypeHandler(txTypeHandler) argsDataFieldParser := &datafield.ArgsOperationDataFieldParser{ AddressLength: TestAddressPubkeyConverter.Len(), diff --git a/integrationTests/vm/testInitializer.go b/integrationTests/vm/testInitializer.go index ed9bc1e8773..8fcd704ad88 100644 --- a/integrationTests/vm/testInitializer.go +++ b/integrationTests/vm/testInitializer.go @@ -371,7 +371,6 @@ func createEconomicsData(enableEpochsConfig config.EnableEpochs) (process.Econom EpochNotifier: realEpochNotifier, EnableEpochsHandler: enableEpochsHandler, TxVersionChecker: versioning.NewTxVersionChecker(minTransactionVersion), - ArgumentParser: smartContract.NewArgumentParser(), } return economics.NewEconomicsData(argsNewEconomicsData) @@ -443,6 +442,7 @@ func CreateTxProcessorWithOneSCExecutorMockVM( if err != nil { return nil, err } + _ = economicsData.SetTxTypeHandler(txTypeHandler) argsNewSCProcessor := scrCommon.ArgsNewSmartContractProcessor{ VmContainer: vmContainer, @@ -857,6 +857,7 @@ func CreateTxProcessorWithOneSCExecutorWithVMs( if err != nil { return nil, err } + _ = economicsData.SetTxTypeHandler(txTypeHandler) gasComp, err := preprocess.NewGasComputation(economicsData, txTypeHandler, enableEpochsHandler) if err != nil { diff --git a/integrationTests/vm/wasm/utils.go b/integrationTests/vm/wasm/utils.go index 6e9a11b865c..7ec28bb8f45 100644 --- a/integrationTests/vm/wasm/utils.go +++ b/integrationTests/vm/wasm/utils.go @@ -254,7 +254,6 @@ func (context *TestContext) initFeeHandlers() { EpochNotifier: context.EpochNotifier, EnableEpochsHandler: context.EnableEpochsHandler, TxVersionChecker: &testscommon.TxVersionCheckerStub{}, - ArgumentParser: smartContract.NewArgumentParser(), } economicsData, _ := economics.NewEconomicsData(argsNewEconomicsData) diff --git a/node/chainSimulator/components/coreComponents.go b/node/chainSimulator/components/coreComponents.go index 0398c406d48..49a7269d74b 100644 --- a/node/chainSimulator/components/coreComponents.go +++ b/node/chainSimulator/components/coreComponents.go @@ -18,7 +18,6 @@ import ( "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/economics" "github.com/multiversx/mx-chain-go/process/rating" - "github.com/multiversx/mx-chain-go/process/smartContract" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "github.com/multiversx/mx-chain-go/statusHandler" @@ -174,7 +173,6 @@ func CreateCoreComponents(args ArgsCoreComponentsHolder) (*coreComponentsHolder, Economics: &args.EconomicsConfig, EpochNotifier: instance.epochNotifier, EnableEpochsHandler: instance.enableEpochsHandler, - ArgumentParser: smartContract.NewArgumentParser(), } instance.economicsData, err = economics.NewEconomicsData(argsEconomicsHandler) diff --git a/node/external/timemachine/fee/feeComputer_test.go b/node/external/timemachine/fee/feeComputer_test.go index 1d99c91215e..46e2904d6d2 100644 --- a/node/external/timemachine/fee/feeComputer_test.go +++ b/node/external/timemachine/fee/feeComputer_test.go @@ -35,7 +35,6 @@ func createEconomicsData() process.EconomicsDataHandler { }, TxVersionChecker: &testscommon.TxVersionCheckerStub{}, EpochNotifier: &epochNotifier.EpochNotifierStub{}, - ArgumentParser: &testscommon.ArgumentParserMock{}, }) return economicsData diff --git a/node/external/timemachine/fee/memoryFootprint/memory_test.go b/node/external/timemachine/fee/memoryFootprint/memory_test.go index ac7330a9206..a854a286ddd 100644 --- a/node/external/timemachine/fee/memoryFootprint/memory_test.go +++ b/node/external/timemachine/fee/memoryFootprint/memory_test.go @@ -44,7 +44,6 @@ func TestFeeComputer_MemoryFootprint(t *testing.T) { }, TxVersionChecker: &testscommon.TxVersionCheckerStub{}, EpochNotifier: &epochNotifier.EpochNotifierStub{}, - ArgumentParser: &testscommon.ArgumentParserMock{}, }) feeComputer, _ := fee.NewFeeComputer(economicsData) computer := fee.NewTestFeeComputer(feeComputer) diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go index cbc510a97d4..99541bfef5d 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go @@ -24,7 +24,6 @@ func createEconomicsData(enableEpochsHandler common.EnableEpochsHandler) process EnableEpochsHandler: enableEpochsHandler, TxVersionChecker: &testscommon.TxVersionCheckerStub{}, EpochNotifier: &epochNotifier.EpochNotifierStub{}, - ArgumentParser: &testscommon.ArgumentParserMock{}, }) return economicsData diff --git a/process/disabled/txTypeHandler.go b/process/disabled/txTypeHandler.go new file mode 100644 index 00000000000..302e81af555 --- /dev/null +++ b/process/disabled/txTypeHandler.go @@ -0,0 +1,28 @@ +package disabled + +import ( + "github.com/multiversx/mx-chain-core-go/data" + "github.com/multiversx/mx-chain-go/process" + logger "github.com/multiversx/mx-chain-logger-go" +) + +var log = logger.GetOrCreate("disabledTxTypeHandler") + +type txTypeHandler struct { +} + +// NewTxTypeHandler returns a new instance of disabled txTypeHandler +func NewTxTypeHandler() *txTypeHandler { + return &txTypeHandler{} +} + +// ComputeTransactionType always returns invalid transaction as it is disabled +func (handler *txTypeHandler) ComputeTransactionType(_ data.TransactionHandler) (process.TransactionType, process.TransactionType) { + log.Warn("disabled txTypeHandler ComputeTransactionType always returns invalid transaction") + return process.InvalidTransaction, process.InvalidTransaction +} + +// IsInterfaceNil returns true if there is no value under the interface +func (handler *txTypeHandler) IsInterfaceNil() bool { + return handler == nil +} diff --git a/process/economics/economicsData.go b/process/economics/economicsData.go index 387c0e8cb09..a510447dab2 100644 --- a/process/economics/economicsData.go +++ b/process/economics/economicsData.go @@ -13,6 +13,7 @@ import ( "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/process/disabled" "github.com/multiversx/mx-chain-go/statusHandler" logger "github.com/multiversx/mx-chain-logger-go" ) @@ -34,7 +35,8 @@ type economicsData struct { statusHandler core.AppStatusHandler enableEpochsHandler common.EnableEpochsHandler txVersionHandler process.TxVersionCheckerHandler - argumentParser process.ArgumentsParser + txTypeHandler process.TxTypeHandler + mutTxTypeHandler sync.RWMutex mut sync.RWMutex } @@ -44,7 +46,6 @@ type ArgsNewEconomicsData struct { Economics *config.EconomicsConfig EpochNotifier process.EpochNotifier EnableEpochsHandler common.EnableEpochsHandler - ArgumentParser process.ArgumentsParser } // NewEconomicsData will create an object with information about economics parameters @@ -65,9 +66,6 @@ func NewEconomicsData(args ArgsNewEconomicsData) (*economicsData, error) { if err != nil { return nil, err } - if check.IfNil(args.ArgumentParser) { - return nil, process.ErrNilArgumentParser - } err = checkEconomicsConfig(args.Economics) if err != nil { @@ -80,7 +78,7 @@ func NewEconomicsData(args ArgsNewEconomicsData) (*economicsData, error) { statusHandler: statusHandler.NewNilStatusHandler(), enableEpochsHandler: args.EnableEpochsHandler, txVersionHandler: args.TxVersionChecker, - argumentParser: args.ArgumentParser, + txTypeHandler: disabled.NewTxTypeHandler(), } ed.yearSettings = make(map[uint32]*config.YearSetting) @@ -143,6 +141,19 @@ func (ed *economicsData) SetStatusHandler(statusHandler core.AppStatusHandler) e return ed.rewardsConfigHandler.setStatusHandler(statusHandler) } +// SetTxTypeHandler sets the provided tx type handler +func (ed *economicsData) SetTxTypeHandler(txTypeHandler process.TxTypeHandler) error { + if check.IfNil(txTypeHandler) { + return process.ErrNilTxTypeHandler + } + + ed.mutTxTypeHandler.Lock() + ed.txTypeHandler = txTypeHandler + ed.mutTxTypeHandler.Unlock() + + return nil +} + // LeaderPercentage returns leader reward percentage func (ed *economicsData) LeaderPercentage() float64 { currentEpoch := ed.enableEpochsHandler.GetCurrentEpoch() @@ -362,20 +373,11 @@ func (ed *economicsData) getTotalFeesRequiredForInnerTxs(innerTxs []data.Transac } func (ed *economicsData) isMoveBalance(tx data.TransactionHandler) bool { - if len(tx.GetData()) == 0 { - return true - } - - if core.IsSmartContractAddress(tx.GetRcvAddr()) { - return false - } - - _, args, err := ed.argumentParser.ParseCallData(string(tx.GetData())) - if err != nil { - return false - } + ed.mutTxTypeHandler.RLock() + _, dstTxType := ed.txTypeHandler.ComputeTransactionType(tx) + ed.mutTxTypeHandler.RUnlock() - return len(args) == 0 + return dstTxType == process.MoveBalance } // SplitTxGasInCategories returns the gas split per categories diff --git a/process/economics/economicsData_test.go b/process/economics/economicsData_test.go index 2b577ad0a8f..a5ac0b0c906 100644 --- a/process/economics/economicsData_test.go +++ b/process/economics/economicsData_test.go @@ -104,7 +104,6 @@ func createArgsForEconomicsData(gasModifier float64) economics.ArgsNewEconomicsD }, }, TxVersionChecker: &testscommon.TxVersionCheckerStub{}, - ArgumentParser: &testscommon.ArgumentParserMock{}, } return args } @@ -120,7 +119,6 @@ func createArgsForEconomicsDataRealFees() economics.ArgsNewEconomicsData { }, }, TxVersionChecker: &testscommon.TxVersionCheckerStub{}, - ArgumentParser: &testscommon.ArgumentParserMock{}, } return args } @@ -167,16 +165,6 @@ func TestNewEconomicsData_NilOrEmptyGasLimitSettingsShouldErr(t *testing.T) { assert.Equal(t, process.ErrEmptyGasLimitSettings, err) } -func TestNewEconomicsData_NilArgumentParserShouldErr(t *testing.T) { - t.Parallel() - - args := createArgsForEconomicsData(1) - args.ArgumentParser = nil - - _, err := economics.NewEconomicsData(args) - assert.Equal(t, process.ErrNilArgumentParser, err) -} - func TestNewEconomicsData_InvalidMaxGasLimitPerBlockShouldErr(t *testing.T) { t.Parallel() diff --git a/process/factory/metachain/vmContainerFactory_test.go b/process/factory/metachain/vmContainerFactory_test.go index ea0123a183c..ff542213ef4 100644 --- a/process/factory/metachain/vmContainerFactory_test.go +++ b/process/factory/metachain/vmContainerFactory_test.go @@ -323,7 +323,6 @@ func TestVmContainerFactory_Create(t *testing.T) { EpochNotifier: &epochNotifier.EpochNotifierStub{}, EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), TxVersionChecker: &testscommon.TxVersionCheckerStub{}, - ArgumentParser: &testscommon.ArgumentParserMock{}, } economicsData, _ := economics.NewEconomicsData(argsNewEconomicsData) diff --git a/process/interface.go b/process/interface.go index 7490d82a666..0b6d264060b 100644 --- a/process/interface.go +++ b/process/interface.go @@ -725,6 +725,7 @@ type EconomicsDataHandler interface { rewardsHandler feeHandler SetStatusHandler(statusHandler core.AppStatusHandler) error + SetTxTypeHandler(txTypeHandler TxTypeHandler) error IsInterfaceNil() bool } diff --git a/process/peer/process_test.go b/process/peer/process_test.go index 38d72b8297e..d4c85a5601f 100644 --- a/process/peer/process_test.go +++ b/process/peer/process_test.go @@ -105,7 +105,6 @@ func createMockArguments() peer.ArgValidatorStatisticsProcessor { EpochNotifier: &epochNotifier.EpochNotifierStub{}, EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), TxVersionChecker: &testscommon.TxVersionCheckerStub{}, - ArgumentParser: &testscommon.ArgumentParserMock{}, } economicsData, _ := economics.NewEconomicsData(argsNewEconomicsData) diff --git a/process/smartContract/process_test.go b/process/smartContract/process_test.go index c8b8097559d..30f0046c9d3 100644 --- a/process/smartContract/process_test.go +++ b/process/smartContract/process_test.go @@ -4248,7 +4248,6 @@ func createRealEconomicsDataArgs() *economics.ArgsNewEconomicsData { }, }, TxVersionChecker: &testscommon.TxVersionCheckerStub{}, - ArgumentParser: &testscommon.ArgumentParserMock{}, } } diff --git a/process/smartContract/processorV2/process_test.go b/process/smartContract/processorV2/process_test.go index 14f0ea0ba17..59feba18e64 100644 --- a/process/smartContract/processorV2/process_test.go +++ b/process/smartContract/processorV2/process_test.go @@ -4206,7 +4206,6 @@ func createRealEconomicsDataArgs() *economics.ArgsNewEconomicsData { }, }, TxVersionChecker: &testscommon.TxVersionCheckerStub{}, - ArgumentParser: &testscommon.ArgumentParserMock{}, } } diff --git a/testscommon/economicsmocks/economicsDataHandlerStub.go b/testscommon/economicsmocks/economicsDataHandlerStub.go index 3c63a32aa60..bb59020bc27 100644 --- a/testscommon/economicsmocks/economicsDataHandlerStub.go +++ b/testscommon/economicsmocks/economicsDataHandlerStub.go @@ -5,6 +5,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data" + "github.com/multiversx/mx-chain-go/process" ) // EconomicsHandlerStub - @@ -47,6 +48,7 @@ type EconomicsHandlerStub struct { ComputeGasUsedAndFeeBasedOnRefundValueInEpochCalled func(tx data.TransactionWithFeeHandler, refundValue *big.Int, epoch uint32) (uint64, *big.Int) ComputeTxFeeBasedOnGasUsedInEpochCalled func(tx data.TransactionWithFeeHandler, gasUsed uint64, epoch uint32) *big.Int ComputeRelayedTxFeesCalled func(tx data.TransactionWithFeeHandler) (*big.Int, *big.Int, error) + SetTxTypeHandlerCalled func(txTypeHandler process.TxTypeHandler) error } // ComputeFeeForProcessing - @@ -365,6 +367,14 @@ func (e *EconomicsHandlerStub) ComputeRelayedTxFees(tx data.TransactionWithFeeHa return big.NewInt(0), big.NewInt(0), nil } +// SetTxTypeHandler - +func (e *EconomicsHandlerStub) SetTxTypeHandler(txTypeHandler process.TxTypeHandler) error { + if e.SetTxTypeHandlerCalled != nil { + return e.SetTxTypeHandlerCalled(txTypeHandler) + } + return nil +} + // IsInterfaceNil returns true if there is no value under the interface func (e *EconomicsHandlerStub) IsInterfaceNil() bool { return e == nil diff --git a/testscommon/economicsmocks/economicsHandlerMock.go b/testscommon/economicsmocks/economicsHandlerMock.go index 98ddeb985c4..3506d2ba9a7 100644 --- a/testscommon/economicsmocks/economicsHandlerMock.go +++ b/testscommon/economicsmocks/economicsHandlerMock.go @@ -5,6 +5,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data" + "github.com/multiversx/mx-chain-go/process" ) // EconomicsHandlerMock - @@ -47,6 +48,7 @@ type EconomicsHandlerMock struct { ComputeGasUsedAndFeeBasedOnRefundValueInEpochCalled func(tx data.TransactionWithFeeHandler, refundValue *big.Int, epoch uint32) (uint64, *big.Int) ComputeTxFeeBasedOnGasUsedInEpochCalled func(tx data.TransactionWithFeeHandler, gasUsed uint64, epoch uint32) *big.Int ComputeRelayedTxFeesCalled func(tx data.TransactionWithFeeHandler) (*big.Int, *big.Int, error) + SetTxTypeHandlerCalled func(txTypeHandler process.TxTypeHandler) error } // LeaderPercentage - @@ -344,6 +346,14 @@ func (ehm *EconomicsHandlerMock) ComputeRelayedTxFees(tx data.TransactionWithFee return big.NewInt(0), big.NewInt(0), nil } +// SetTxTypeHandler - +func (ehm *EconomicsHandlerMock) SetTxTypeHandler(txTypeHandler process.TxTypeHandler) error { + if ehm.SetTxTypeHandlerCalled != nil { + return ehm.SetTxTypeHandlerCalled(txTypeHandler) + } + return nil +} + // IsInterfaceNil returns true if there is no value under the interface func (ehm *EconomicsHandlerMock) IsInterfaceNil() bool { return ehm == nil diff --git a/testscommon/stakingcommon/stakingCommon.go b/testscommon/stakingcommon/stakingCommon.go index 6b85d5a238a..1af9b441b9c 100644 --- a/testscommon/stakingcommon/stakingCommon.go +++ b/testscommon/stakingcommon/stakingCommon.go @@ -9,7 +9,6 @@ import ( "github.com/multiversx/mx-chain-go/genesis/process/disabled" "github.com/multiversx/mx-chain-go/process" economicsHandler "github.com/multiversx/mx-chain-go/process/economics" - "github.com/multiversx/mx-chain-go/process/smartContract" "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" @@ -278,7 +277,6 @@ func CreateEconomicsData() process.EconomicsDataHandler { EpochNotifier: &epochNotifier.EpochNotifierStub{}, EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, TxVersionChecker: &disabled.TxVersionChecker{}, - ArgumentParser: smartContract.NewArgumentParser(), } economicsData, _ := economicsHandler.NewEconomicsData(argsNewEconomicsData) return economicsData From ae492324e7233917c7d658afb3dfc244b9c07431 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 26 Jun 2024 19:14:24 +0300 Subject: [PATCH 389/503] increased the coverage --- process/economics/economicsData_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/process/economics/economicsData_test.go b/process/economics/economicsData_test.go index a5ac0b0c906..5fdb8c369c2 100644 --- a/process/economics/economicsData_test.go +++ b/process/economics/economicsData_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/smartContractResult" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/common" @@ -1672,6 +1673,12 @@ func TestEconomicsData_ComputeRelayedTxFees(t *testing.T) { economicsData, _ := economics.NewEconomicsData(args) + _ = economicsData.SetTxTypeHandler(&testscommon.TxTypeHandlerMock{ + ComputeTransactionTypeCalled: func(tx data.TransactionHandler) (process.TransactionType, process.TransactionType) { + return process.MoveBalance, process.MoveBalance + }, + }) + relayerFee, totalFee, err := economicsData.ComputeRelayedTxFees(tx) require.NoError(t, err) expectedRelayerFee := big.NewInt(int64(2 * uint64(minGasLimit) * tx.GetGasPrice())) // 2 move balance @@ -1700,3 +1707,17 @@ func TestEconomicsData_ComputeRelayedTxFees(t *testing.T) { require.Equal(t, big.NewInt(int64(txCopy.GetGasLimit()*txCopy.GetGasPrice())), totalFee) }) } + +func TestEconomicsData_SetTxTypeHandler(t *testing.T) { + t.Parallel() + + args := createArgsForEconomicsData(1) + economicsData, _ := economics.NewEconomicsData(args) + assert.NotNil(t, economicsData) + + err := economicsData.SetTxTypeHandler(nil) + require.Equal(t, process.ErrNilTxTypeHandler, err) + + err = economicsData.SetTxTypeHandler(&testscommon.TxTypeHandlerMock{}) + require.NoError(t, err) +} From e4f88e36f0da5dedbeba5fa43d8c257a08348293 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 27 Jun 2024 11:17:41 +0300 Subject: [PATCH 390/503] remove refund scr added for v3 inner tx move balance, not needed anymore --- process/transaction/shardProcess.go | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 83ef7b368c6..fe2dd4dcb8b 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -539,10 +539,6 @@ func (txProc *txProcessor) processMoveBalance( txProc.txFeeHandler.ProcessTransactionFee(moveBalanceCost, big.NewInt(0), txHash) } - if len(tx.RelayerAddr) > 0 { - return txProc.createRefundSCRForMoveBalance(tx, txHash, originalTxHash, moveBalanceCost) - } - return nil } @@ -1249,31 +1245,6 @@ func (txProc *txProcessor) saveFailedLogsIfNeeded(originalTxHash []byte) { txProc.failedTxLogsAccumulator.Remove(originalTxHash) } -func (txProc *txProcessor) createRefundSCRForMoveBalance( - tx *transaction.Transaction, - txHash []byte, - originalTxHash []byte, - consumedFee *big.Int, -) error { - providedFee := big.NewInt(0).Mul(big.NewInt(0).SetUint64(tx.GasLimit), big.NewInt(0).SetUint64(tx.GasPrice)) - refundValue := big.NewInt(0).Sub(providedFee, consumedFee) - - refundGasToRelayerSCR := &smartContractResult.SmartContractResult{ - Nonce: tx.Nonce, - Value: refundValue, - RcvAddr: tx.RelayerAddr, - SndAddr: tx.SndAddr, - PrevTxHash: txHash, - OriginalTxHash: originalTxHash, - GasPrice: tx.GetGasPrice(), - CallType: vm.DirectCall, - ReturnMessage: []byte(core.GasRefundForRelayerMessage), - OriginalSender: tx.RelayerAddr, - } - - return txProc.scrForwarder.AddIntermediateTransactions([]data.TransactionHandler{refundGasToRelayerSCR}) -} - // IsInterfaceNil returns true if there is no value under the interface func (txProc *txProcessor) IsInterfaceNil() bool { return txProc == nil From ed5d580004737c3ab76fc4a5b11b9d133d782e7c Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 27 Jun 2024 12:57:28 +0300 Subject: [PATCH 391/503] fix change to dynamic old tokens scenario --- .../vm/esdtImprovements_test.go | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 8f075e5b95d..c23c42a15c5 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -3030,12 +3030,13 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { nonce++ } - shardID := uint32(0) - err = cs.GenerateBlocks(10) require.Nil(t, err) - checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + + // meta data should be saved on account, since it is before `OptimizeNFTStoreEnableEpoch` + checkMetaData(t, cs, addrs[0].Bytes, nftTokenID, shardID, nftMetaData) checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) checkMetaData(t, cs, addrs[0].Bytes, sftTokenID, shardID, sftMetaData) @@ -3056,6 +3057,27 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } + + for _, tokenID := range tokenIDs { + log.Info("transfering token id", "tokenID", tokenID) + + tx = esdtNFTTransferTx(nonce, addrs[0].Bytes, addrs[1].Bytes, tokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + require.Equal(t, "success", txResult.Status.String()) nonce++ @@ -3063,7 +3085,13 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData) checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, sftTokenID, shardID) + checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, sftTokenID, shardID) checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, metaESDTTokenID, shardID) + checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, metaESDTTokenID, shardID) + + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, nftTokenID, shardID) + checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, nftTokenID, shardID) } From c3d558ff78f0efdd2cfa1b9c3c61e2e2d5298285 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 27 Jun 2024 13:04:41 +0300 Subject: [PATCH 392/503] fix change to dynamic old tokens scenario - add updateTokenID --- .../vm/esdtImprovements_test.go | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index c23c42a15c5..6c692f0e340 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -3022,9 +3022,6 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) require.Equal(t, "success", txResult.Status.String()) nonce++ @@ -3050,6 +3047,7 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { log.Info("Change to DYNAMIC type") + // it will not be able to change nft to dynamic type for i := range tokenIDs { tx = changeToDynamicTx(nonce, addrs[0].Bytes, tokenIDs[i]) @@ -3057,10 +3055,19 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } + + for _, tokenID := range tokenIDs { + tx = updateTokenIDTx(nonce, addrs[0].Bytes, tokenID) + log.Info("updating token id", "tokenID", tokenID) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) nonce++ @@ -3074,10 +3081,6 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) nonce++ @@ -3091,7 +3094,7 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, metaESDTTokenID, shardID) checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, metaESDTTokenID, shardID) - checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + checkMetaData(t, cs, addrs[1].Bytes, nftTokenID, shardID, nftMetaData) checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, nftTokenID, shardID) - checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, nftTokenID, shardID) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) } From bdcea1dd7bd1dbd3205c83ab662656ee95c1b16e Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 27 Jun 2024 16:01:31 +0300 Subject: [PATCH 393/503] cleanup changes --- .../vm/esdtImprovements_test.go | 28 ++++--------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 6c692f0e340..c37f5b4b27b 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -835,7 +835,7 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { // // Call ESDTMetaDataRecreate to rewrite the meta data for the nft // (The sender must have the ESDTMetaDataRecreate role) -func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { +func TestChainSimulator_ESDTMetaDataRecreate(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } @@ -995,7 +995,7 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { // // Call ESDTMetaDataUpdate to update some of the meta data parameters // (The sender must have the ESDTRoleNFTUpdate role) -func TestChainSimulator_NFT_ESDTMetaDataUpdate(t *testing.T) { +func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } @@ -1133,10 +1133,6 @@ func TestChainSimulator_NFT_ESDTMetaDataUpdate(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - // fmt.Println(txResult) - // fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - // fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) @@ -1157,7 +1153,7 @@ func TestChainSimulator_NFT_ESDTMetaDataUpdate(t *testing.T) { // // Call ESDTModifyCreator and check that the creator was modified // (The sender must have the ESDTRoleModifyCreator role) -func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { +func TestChainSimulator_ESDTModifyCreator(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } @@ -1179,10 +1175,6 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) metaESDTTokenID := txResult.Logs.Events[0].Topics[0] @@ -1361,7 +1353,7 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { // // Call ESDTSetNewURIs and check that the new URIs were set for the token // (The sender must have the ESDTRoleSetNewURI role) -func TestChainSimulator_NFT_ESDTSetNewURIs(t *testing.T) { +func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } @@ -1453,16 +1445,12 @@ func TestChainSimulator_NFT_ESDTSetNewURIs(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) nonce++ } - log.Info("Call ESDTSetNewURIs and check that the new URIs were set for the NFT") + log.Info("Call ESDTSetNewURIs and check that the new URIs were set for the tokens") metaDataNonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) uris := [][]byte{ @@ -1621,10 +1609,6 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) nonce++ @@ -1636,7 +1620,7 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { royalties := []byte(hex.EncodeToString(big.NewInt(20).Bytes())) for i := range tokenIDs { - log.Info("Set new royalities for token", "tokenID", string(tokenIDs[i])) + log.Info("Set new royalties for token", "tokenID", string(tokenIDs[i])) txDataField := bytes.Join( [][]byte{ From ddf28bae15bafbcb9809cd3afc3182174949f171 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Fri, 28 Jun 2024 11:14:27 +0300 Subject: [PATCH 394/503] added more scenarios --- .../vm/esdtImprovements_test.go | 1941 ++++++++++++----- 1 file changed, 1347 insertions(+), 594 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index c37f5b4b27b..12996710749 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -300,16 +300,28 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran log.Info("Step 7. transfer the tokens to another account") nonce = uint64(0) - for _, tokenID := range tokenIDs { - log.Info("transfering token id", "tokenID", tokenID) + if isMultiTransfer { + tx = multiESDTNFTTransferTx(nonce, addrs[1].Bytes, addrs[2].Bytes, tokenIDs) - tx = esdtNFTTransferTx(nonce, addrs[1].Bytes, addrs[2].Bytes, tokenID) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) nonce++ + } else { + for _, tokenID := range tokenIDs { + log.Info("transfering token id", "tokenID", tokenID) + + tx = esdtNFTTransferTx(nonce, addrs[1].Bytes, addrs[2].Bytes, tokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } } log.Info("Step 8. check that the metaData for the NFT was removed from the system account and moved to the user account") @@ -1295,7 +1307,7 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { mintValue := big.NewInt(10) mintValue = mintValue.Mul(oneEGLD, mintValue) - shardID := uint32(1) + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[1].Bytes) for i := range tokenIDs { log.Info("Modify creator for token", "tokenID", tokenIDs[i]) @@ -1347,13 +1359,7 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { } } -// Test scenario #7 -// -// Initial setup: Create NFT, SFT, metaESDT tokens -// -// Call ESDTSetNewURIs and check that the new URIs were set for the token -// (The sender must have the ESDTRoleSetNewURI role) -func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { +func TestChainSimulator_ESDTModifyCreator_SFTmetaESDT(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } @@ -1363,17 +1369,18 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() - log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") + log.Info("Initial setup: Create SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") addrs := createAddresses(t, cs, false) // issue metaESDT - metaESDTTicker := []byte("METATTICKER") - tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + metaESDTTicker := []byte("METATICKER") + tx := issueMetaESDTTx(0, addrs[1].Bytes, metaESDTTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) metaESDTTokenID := txResult.Logs.Events[0].Topics[0] @@ -1382,29 +1389,14 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), []byte(core.ESDTRoleNFTUpdate), - []byte(core.ESDTRoleSetNewURI), } - setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + setAddressEsdtRoles(t, cs, addrs[1], metaESDTTokenID, roles) log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) - // issue NFT - nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) - - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - - nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) - - log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) - // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(1, addrs[1].Bytes, sftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1412,19 +1404,15 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + setAddressEsdtRoles(t, cs, addrs[1], sftTokenID, roles) log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) tokenIDs := [][]byte{ - nftTokenID, - sftTokenID, metaESDTTokenID, + sftTokenID, } - nftMetaData := txsFee.GetDefaultMetaData() - nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - sftMetaData := txsFee.GetDefaultMetaData() sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) @@ -1432,58 +1420,82 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tokensMetadata := []*txsFee.MetaData{ - nftMetaData, - sftMetaData, esdtMetaData, + sftMetaData, } - nonce := uint64(3) + nonce := uint64(2) for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = nftCreateTx(nonce, addrs[1].Bytes, tokenIDs[i], tokensMetadata[i]) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + require.Equal(t, "success", txResult.Status.String()) nonce++ } - log.Info("Call ESDTSetNewURIs and check that the new URIs were set for the tokens") + for _, tokenID := range tokenIDs { + tx = updateTokenIDTx(nonce, addrs[1].Bytes, tokenID) - metaDataNonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - uris := [][]byte{ - []byte(hex.EncodeToString([]byte("uri0"))), - []byte(hex.EncodeToString([]byte("uri1"))), - []byte(hex.EncodeToString([]byte("uri2"))), - } + log.Info("updating token id", "tokenID", tokenID) - expUris := [][]byte{ - []byte("uri0"), - []byte("uri1"), - []byte("uri2"), + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) + + nonce++ } + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[1].Bytes) + + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) + + log.Info("Call ESDTModifyCreator and check that the creator was modified") + + mintValue := big.NewInt(10) + mintValue = mintValue.Mul(oneEGLD, mintValue) + for i := range tokenIDs { - log.Info("Set new uris for token", "tokenID", string(tokenIDs[i])) + log.Info("Modify creator for token", "tokenID", string(tokenIDs[i])) + + newCreatorAddress, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) + require.Nil(t, err) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + roles = [][]byte{ + []byte(core.ESDTRoleModifyCreator), + } + setAddressEsdtRoles(t, cs, newCreatorAddress, tokenIDs[i], roles) txDataField := bytes.Join( [][]byte{ - []byte(core.ESDTSetNewURIs), + []byte(core.ESDTModifyCreator), []byte(hex.EncodeToString(tokenIDs[i])), - metaDataNonce, - uris[0], - uris[1], - uris[2], + []byte(hex.EncodeToString(big.NewInt(1).Bytes())), }, []byte("@"), ) tx = &transaction.Transaction{ - Nonce: nonce, - SndAddr: addrs[0].Bytes, - RcvAddr: addrs[0].Bytes, + Nonce: 0, + SndAddr: newCreatorAddress.Bytes, + RcvAddr: newCreatorAddress.Bytes, GasLimit: 10_000_000, GasPrice: minGasPrice, Signature: []byte("dummySig"), @@ -1497,29 +1509,21 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + require.Equal(t, "success", txResult.Status.String()) - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - var retrievedMetaData *esdt.MetaData - if bytes.Equal(tokenIDs[i], tokenIDs[0]) { // nft token - retrievedMetaData = getMetaDataFromAcc(t, cs, addrs[0].Bytes, tokenIDs[i], shardID) - } else { - retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID) - } + retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID) - require.Equal(t, expUris, retrievedMetaData.URIs) + require.Equal(t, newCreatorAddress.Bytes, retrievedMetaData.Creator) nonce++ } } -// Test scenario #8 -// -// Initial setup: Create NFT, SFT, metaESDT tokens -// -// Call ESDTModifyRoyalties and check that the royalties were changed -// (The sender must have the ESDTRoleModifyRoyalties role) -func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { +func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } @@ -1529,15 +1533,18 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() + log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag). Register NFT directly as dynamic") + addrs := createAddresses(t, cs, false) // issue metaESDT - metaESDTTicker := []byte("METATTICKER") - tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + metaESDTTicker := []byte("METATICKER") + tx := issueMetaESDTTx(0, addrs[1].Bytes, metaESDTTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) metaESDTTokenID := txResult.Logs.Events[0].Topics[0] @@ -1546,29 +1553,54 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), []byte(core.ESDTRoleNFTUpdate), - []byte(core.ESDTRoleModifyRoyalties), } - setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + setAddressEsdtRoles(t, cs, addrs[1], metaESDTTokenID, roles) log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) - // issue NFT + // register dynamic NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + nftTokenName := []byte("tokenName") + + txDataField := bytes.Join( + [][]byte{ + []byte("registerDynamic"), + []byte(hex.EncodeToString(nftTokenName)), + []byte(hex.EncodeToString(nftTicker)), + []byte(hex.EncodeToString([]byte("NFT"))), + }, + []byte("@"), + ) + + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + + tx = &transaction.Transaction{ + Nonce: 1, + SndAddr: addrs[1].Bytes, + RcvAddr: vm.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: callValue, + ChainID: []byte(configs.ChainID), + Version: 1, + } txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, addrs[1], nftTokenID, roles) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(2, addrs[1].Bytes, sftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1576,7 +1608,7 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + setAddressEsdtRoles(t, cs, addrs[1], sftTokenID, roles) log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -1603,7 +1635,7 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { nonce := uint64(3) for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = nftCreateTx(nonce, addrs[1].Bytes, tokenIDs[i], tokensMetadata[i]) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1614,28 +1646,59 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { nonce++ } - log.Info("Call ESDTModifyRoyalties and check that the royalties were changed") + log.Info("Change to DYNAMIC type") - metaDataNonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - royalties := []byte(hex.EncodeToString(big.NewInt(20).Bytes())) + for i := range tokenIDs { + tx = changeToDynamicTx(nonce, addrs[1].Bytes, tokenIDs[i]) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } + + log.Info("Call ESDTModifyCreator and check that the creator was modified") + + mintValue := big.NewInt(10) + mintValue = mintValue.Mul(oneEGLD, mintValue) + + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[1].Bytes) + + crossShardID := uint32(2) + if shardID == uint32(2) { + crossShardID = uint32(1) + } for i := range tokenIDs { - log.Info("Set new royalties for token", "tokenID", string(tokenIDs[i])) + log.Info("Modify creator for token", "tokenID", string(tokenIDs[i])) + + newCreatorAddress, err := cs.GenerateAndMintWalletAddress(crossShardID, mintValue) + require.Nil(t, err) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + roles = [][]byte{ + []byte(core.ESDTRoleModifyCreator), + } + setAddressEsdtRoles(t, cs, newCreatorAddress, tokenIDs[i], roles) txDataField := bytes.Join( [][]byte{ - []byte(core.ESDTModifyRoyalties), + []byte(core.ESDTModifyCreator), []byte(hex.EncodeToString(tokenIDs[i])), - metaDataNonce, - royalties, + []byte(hex.EncodeToString(big.NewInt(1).Bytes())), }, []byte("@"), ) tx = &transaction.Transaction{ - Nonce: nonce, - SndAddr: addrs[0].Bytes, - RcvAddr: addrs[0].Bytes, + Nonce: 0, + SndAddr: newCreatorAddress.Bytes, + RcvAddr: newCreatorAddress.Bytes, GasLimit: 10_000_000, GasPrice: minGasPrice, Signature: []byte("dummySig"), @@ -1649,141 +1712,193 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + require.Equal(t, "success", txResult.Status.String()) - shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(addrs[0].Bytes) - retrievedMetaData := getMetaDataFromAcc(t, cs, addrs[0].Bytes, nftTokenID, shardID) + retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID) - require.Equal(t, uint32(big.NewInt(20).Uint64()), retrievedMetaData.Royalties) + require.Equal(t, newCreatorAddress.Bytes, retrievedMetaData.Creator) nonce++ } } -// Test scenario #9 +// Test scenario #7 // -// Initial setup: Create NFT +// Initial setup: Create NFT, SFT, metaESDT tokens // -// 1. Change the nft to DYNAMIC type - the metadata should be on the system account -// 2. Send the NFT cross shard -// 3. The meta data should still be present on the system account -func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { +// Call ESDTSetNewURIs and check that the new URIs were set for the token +// (The sender must have the ESDTRoleSetNewURI role) +func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } - startTime := time.Now().Unix() - roundDurationInMillis := uint64(6000) - roundsPerEpoch := core.OptionalUint64{ - HasValue: true, - Value: 20, - } - - activationEpoch := uint32(4) - baseIssuingCost := "1000" - numOfShards := uint32(3) - cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: true, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, - AlterConfigsFunction: func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch - cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost - }, - }) - require.Nil(t, err) - require.NotNil(t, cs) - + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() - addrs := createAddresses(t, cs, true) - - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch) - 2) - require.Nil(t, err) + log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") - log.Info("Initial setup: Create NFT") + addrs := createAddresses(t, cs, false) - nftTicker := []byte("NFTTICKER") - tx := issueNonFungibleTx(0, addrs[1].Bytes, nftTicker, baseIssuingCost) + // issue metaESDT + metaESDTTicker := []byte("METATTICKER") + tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) + metaESDTTokenID := txResult.Logs.Events[0].Topics[0] + roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), []byte(core.ESDTRoleNFTUpdate), + []byte(core.ESDTRoleSetNewURI), } + setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + + log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) + + // issue NFT + nftTicker := []byte("NFTTICKER") + tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[1], nftTokenID, roles) + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) - nftMetaData := txsFee.GetDefaultMetaData() - nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - - tx = nftCreateTx(1, addrs[1].Bytes, nftTokenID, nftMetaData) + // issue SFT + sftTicker := []byte("SFTTICKER") + tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) - require.Nil(t, err) + sftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) - log.Info("Step 1. Change the nft to DYNAMIC type - the metadata should be on the system account") + log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[1].Bytes) + tokenIDs := [][]byte{ + nftTokenID, + sftTokenID, + metaESDTTokenID, + } - tx = changeToDynamicTx(2, addrs[1].Bytes, nftTokenID) + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) + sftMetaData := txsFee.GetDefaultMetaData() + sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - require.Equal(t, "success", txResult.Status.String()) + esdtMetaData := txsFee.GetDefaultMetaData() + esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - err = cs.GenerateBlocks(10) - require.Nil(t, err) + tokensMetadata := []*txsFee.MetaData{ + nftMetaData, + sftMetaData, + esdtMetaData, + } - checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + nonce := uint64(3) + for i := range tokenIDs { + tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) - log.Info("Step 2. Send the NFT cross shard") + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) - tx = esdtNFTTransferTx(3, addrs[1].Bytes, addrs[2].Bytes, nftTokenID) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) + require.Equal(t, "success", txResult.Status.String()) - log.Info("Step 3. The meta data should still be present on the system account") + nonce++ + } - checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + log.Info("Call ESDTSetNewURIs and check that the new URIs were set for the tokens") + + metaDataNonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + uris := [][]byte{ + []byte(hex.EncodeToString([]byte("uri0"))), + []byte(hex.EncodeToString([]byte("uri1"))), + []byte(hex.EncodeToString([]byte("uri2"))), + } + + expUris := [][]byte{ + []byte("uri0"), + []byte("uri1"), + []byte("uri2"), + } + + for i := range tokenIDs { + log.Info("Set new uris for token", "tokenID", string(tokenIDs[i])) + + txDataField := bytes.Join( + [][]byte{ + []byte(core.ESDTSetNewURIs), + []byte(hex.EncodeToString(tokenIDs[i])), + metaDataNonce, + uris[0], + uris[1], + uris[2], + }, + []byte("@"), + ) + + tx = &transaction.Transaction{ + Nonce: nonce, + SndAddr: addrs[0].Bytes, + RcvAddr: addrs[0].Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + var retrievedMetaData *esdt.MetaData + if bytes.Equal(tokenIDs[i], tokenIDs[0]) { // nft token + retrievedMetaData = getMetaDataFromAcc(t, cs, addrs[0].Bytes, tokenIDs[i], shardID) + } else { + retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID) + } + + require.Equal(t, expUris, retrievedMetaData.URIs) + + nonce++ + } } -// Test scenario #10 +// Test scenario #8 // -// Initial setup: Create SFT and send in 2 shards +// Initial setup: Create NFT, SFT, metaESDT tokens // -// 1. change the sft meta data in one shard -// 2. change the sft meta data (differently from the previous one) in the other shard -// 3. send sft from one shard to another -// 4. check that the newest metadata is saved -func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { +// Call ESDTModifyRoyalties and check that the royalties were changed +// (The sender must have the ESDTRoleModifyRoyalties role) +func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } @@ -1793,59 +1908,323 @@ func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() - addrs := createAddresses(t, cs, true) + addrs := createAddresses(t, cs, false) - log.Info("Initial setup: Create SFT and send in 2 shards") + // issue metaESDT + metaESDTTicker := []byte("METATTICKER") + tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + metaESDTTokenID := txResult.Logs.Events[0].Topics[0] roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), []byte(core.ESDTRoleNFTUpdate), - []byte(core.ESDTRoleNFTAddQuantity), + []byte(core.ESDTRoleModifyRoyalties), } + setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) - sftTicker := []byte("SFTTICKER") - tx := issueSemiFungibleTx(0, addrs[1].Bytes, sftTicker, baseIssuingCost) + log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + // issue NFT + nftTicker := []byte("NFTTICKER") + tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + nftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) + + // issue SFT + sftTicker := []byte("SFTTICKER") + tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[1], sftTokenID, roles) - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) - setAddressEsdtRoles(t, cs, addrs[2], sftTokenID, roles) log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) + tokenIDs := [][]byte{ + nftTokenID, + sftTokenID, + metaESDTTokenID, + } + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + sftMetaData := txsFee.GetDefaultMetaData() sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - txDataField := bytes.Join( - [][]byte{ - []byte(core.BuiltInFunctionESDTNFTCreate), - []byte(hex.EncodeToString(sftTokenID)), - []byte(hex.EncodeToString(big.NewInt(2).Bytes())), // quantity - sftMetaData.Name, - []byte(hex.EncodeToString(big.NewInt(10).Bytes())), - sftMetaData.Hash, - sftMetaData.Attributes, - sftMetaData.Uris[0], - sftMetaData.Uris[1], - sftMetaData.Uris[2], - }, - []byte("@"), - ) + esdtMetaData := txsFee.GetDefaultMetaData() + esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = &transaction.Transaction{ - Nonce: 1, - SndAddr: addrs[1].Bytes, - RcvAddr: addrs[1].Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), + tokensMetadata := []*txsFee.MetaData{ + nftMetaData, + sftMetaData, + esdtMetaData, + } + + nonce := uint64(3) + for i := range tokenIDs { + tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } + + log.Info("Call ESDTModifyRoyalties and check that the royalties were changed") + + metaDataNonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + royalties := []byte(hex.EncodeToString(big.NewInt(20).Bytes())) + + for i := range tokenIDs { + log.Info("Set new royalties for token", "tokenID", string(tokenIDs[i])) + + txDataField := bytes.Join( + [][]byte{ + []byte(core.ESDTModifyRoyalties), + []byte(hex.EncodeToString(tokenIDs[i])), + metaDataNonce, + royalties, + }, + []byte("@"), + ) + + tx = &transaction.Transaction{ + Nonce: nonce, + SndAddr: addrs[0].Bytes, + RcvAddr: addrs[0].Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(addrs[0].Bytes) + retrievedMetaData := getMetaDataFromAcc(t, cs, addrs[0].Bytes, nftTokenID, shardID) + + require.Equal(t, uint32(big.NewInt(20).Uint64()), retrievedMetaData.Royalties) + + nonce++ + } +} + +// Test scenario #9 +// +// Initial setup: Create NFT +// +// 1. Change the nft to DYNAMIC type - the metadata should be on the system account +// 2. Send the NFT cross shard +// 3. The meta data should still be present on the system account +func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(4) + + baseIssuingCost := "1000" + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: true, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + addrs := createAddresses(t, cs, true) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch) - 2) + require.Nil(t, err) + + log.Info("Initial setup: Create NFT") + + nftTicker := []byte("NFTTICKER") + tx := issueNonFungibleTx(0, addrs[1].Bytes, nftTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleNFTUpdate), + } + + nftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[1], nftTokenID, roles) + + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = nftCreateTx(1, addrs[1].Bytes, nftTokenID, nftMetaData) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + log.Info("Step 1. Change the nft to DYNAMIC type - the metadata should be on the system account") + + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[1].Bytes) + + tx = changeToDynamicTx(2, addrs[1].Bytes, nftTokenID) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + + log.Info("Step 2. Send the NFT cross shard") + + tx = esdtNFTTransferTx(3, addrs[1].Bytes, addrs[2].Bytes, nftTokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + log.Info("Step 3. The meta data should still be present on the system account") + + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) +} + +// Test scenario #10 +// +// Initial setup: Create SFT and send in 2 shards +// +// 1. change the sft meta data in one shard +// 2. change the sft meta data (differently from the previous one) in the other shard +// 3. send sft from one shard to another +// 4. check that the newest metadata is saved +func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + baseIssuingCost := "1000" + + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) + defer cs.Close() + + addrs := createAddresses(t, cs, true) + + log.Info("Initial setup: Create SFT and send in 2 shards") + + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleNFTUpdate), + []byte(core.ESDTRoleNFTAddQuantity), + } + + sftTicker := []byte("SFTTICKER") + tx := issueSemiFungibleTx(0, addrs[1].Bytes, sftTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + sftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[1], sftTokenID, roles) + + setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + setAddressEsdtRoles(t, cs, addrs[2], sftTokenID, roles) + + log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) + + sftMetaData := txsFee.GetDefaultMetaData() + sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + txDataField := bytes.Join( + [][]byte{ + []byte(core.BuiltInFunctionESDTNFTCreate), + []byte(hex.EncodeToString(sftTokenID)), + []byte(hex.EncodeToString(big.NewInt(2).Bytes())), // quantity + sftMetaData.Name, + []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + sftMetaData.Hash, + sftMetaData.Attributes, + sftMetaData.Uris[0], + sftMetaData.Uris[1], + sftMetaData.Uris[2], + }, + []byte("@"), + ) + + tx = &transaction.Transaction{ + Nonce: 1, + SndAddr: addrs[1].Bytes, + RcvAddr: addrs[1].Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), Data: txDataField, Value: big.NewInt(0), ChainID: []byte(configs.ChainID), @@ -2522,35 +2901,631 @@ func TestChainSimulator_MetaESDT_RegisterAndSetAllRolesDynamic(t *testing.T) { baseIssuingCost := "1000" - cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) + defer cs.Close() + + addrs := createAddresses(t, cs, true) + + log.Info("Register dynamic meta esdt token") + + ticker := []byte("META" + "TICKER") + tokenName := []byte("tokenName") + + decimals := big.NewInt(10) + + txDataField := bytes.Join( + [][]byte{ + []byte("registerAndSetAllRolesDynamic"), + []byte(hex.EncodeToString(tokenName)), + []byte(hex.EncodeToString(ticker)), + []byte(hex.EncodeToString([]byte("META"))), + []byte(hex.EncodeToString(decimals.Bytes())), + }, + []byte("@"), + ) + + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + + tx := &transaction.Transaction{ + Nonce: 0, + SndAddr: addrs[0].Bytes, + RcvAddr: vm.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: callValue, + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + metaTokenID := txResult.Logs.Events[0].Topics[0] + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + } + setAddressEsdtRoles(t, cs, addrs[0], metaTokenID, roles) + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = nftCreateTx(1, addrs[0].Bytes, metaTokenID, nftMetaData) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + + checkMetaData(t, cs, core.SystemAccountAddress, metaTokenID, shardID, nftMetaData) + + log.Info("Check that token type is Dynamic") + + scQuery := &process.SCQuery{ + ScAddress: vm.ESDTSCAddress, + FuncName: "getTokenProperties", + CallValue: big.NewInt(0), + Arguments: [][]byte{metaTokenID}, + } + result, _, err := cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ExecuteSCQuery(scQuery) + require.Nil(t, err) + require.Equal(t, "", result.ReturnMessage) + require.Equal(t, testsChainSimulator.OkReturnCode, result.ReturnCode) + + tokenType := result.ReturnData[1] + require.Equal(t, core.Dynamic+core.MetaESDT, string(tokenType)) + + log.Info("Check token roles") + + scQuery = &process.SCQuery{ + ScAddress: vm.ESDTSCAddress, + FuncName: "getAllAddressesAndRoles", + CallValue: big.NewInt(0), + Arguments: [][]byte{metaTokenID}, + } + result, _, err = cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ExecuteSCQuery(scQuery) + require.Nil(t, err) + require.Equal(t, "", result.ReturnMessage) + require.Equal(t, testsChainSimulator.OkReturnCode, result.ReturnCode) + + expectedRoles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleNFTBurn), + []byte(core.ESDTRoleNFTAddQuantity), + []byte(core.ESDTRoleNFTUpdateAttributes), + []byte(core.ESDTRoleNFTAddURI), + } + + checkTokenRoles(t, result.ReturnData, expectedRoles) +} + +func checkTokenRoles(t *testing.T, returnData [][]byte, expectedRoles [][]byte) { + for _, expRole := range expectedRoles { + found := false + + for _, item := range returnData { + if bytes.Equal(expRole, item) { + found = true + } + } + + require.True(t, found) + } +} + +func TestChainSimulator_NFTcreatedBeforeSaveToSystemAccountEnabled(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + baseIssuingCost := "1000" + cs, epochForDynamicNFT := getTestChainSimulatorWithSaveToSystemAccountDisabled(t, baseIssuingCost) + defer cs.Close() + + addrs := createAddresses(t, cs, false) + + log.Info("Initial setup: Create NFT that will have it's metadata saved to the user account") + + nftTicker := []byte("NFTTICKER") + tx := issueNonFungibleTx(0, addrs[0].Bytes, nftTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + nftTokenID := txResult.Logs.Events[0].Topics[0] + + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + createTokenUpdateTokenIDAndTransfer(t, cs, addrs[0].Bytes, addrs[1].Bytes, nftTokenID, nftMetaData, epochForDynamicNFT, addrs[0]) + + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + checkMetaData(t, cs, addrs[1].Bytes, nftTokenID, shardID, nftMetaData) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, nftTokenID, shardID) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) +} + +func TestChainSimulator_SFTcreatedBeforeSaveToSystemAccountEnabled(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + baseIssuingCost := "1000" + cs, epochForDynamicNFT := getTestChainSimulatorWithSaveToSystemAccountDisabled(t, baseIssuingCost) + defer cs.Close() + + addrs := createAddresses(t, cs, false) + + log.Info("Initial setup: Create SFT that will have it's metadata saved to the user account") + + sftTicker := []byte("SFTTICKER") + tx := issueSemiFungibleTx(0, addrs[0].Bytes, sftTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + sftTokenID := txResult.Logs.Events[0].Topics[0] + + log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) + + metaData := txsFee.GetDefaultMetaData() + metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + createTokenUpdateTokenIDAndTransfer(t, cs, addrs[0].Bytes, addrs[1].Bytes, sftTokenID, metaData, epochForDynamicNFT, addrs[0]) + + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, metaData) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, sftTokenID, shardID) + checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, sftTokenID, shardID) +} + +func TestChainSimulator_FungibleCreatedBeforeSaveToSystemAccountEnabled(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + baseIssuingCost := "1000" + cs, epochForDynamicNFT := getTestChainSimulatorWithSaveToSystemAccountDisabled(t, baseIssuingCost) + defer cs.Close() + + addrs := createAddresses(t, cs, false) + + log.Info("Initial setup: Create FungibleESDT that will have it's metadata saved to the user account") + + funTicker := []byte("FUNTICKER") + tx := issueTx(0, addrs[0].Bytes, funTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + funTokenID := txResult.Logs.Events[0].Topics[0] + + log.Info("Issued FungibleESDT token id", "tokenID", string(funTokenID)) + + metaData := txsFee.GetDefaultMetaData() + metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + createTokenUpdateTokenIDAndTransfer(t, cs, addrs[0].Bytes, addrs[1].Bytes, funTokenID, metaData, epochForDynamicNFT, addrs[0]) + + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + + checkMetaData(t, cs, core.SystemAccountAddress, funTokenID, shardID, metaData) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, funTokenID, shardID) + checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, funTokenID, shardID) +} + +func TestChainSimulator_MetaESDTCreatedBeforeSaveToSystemAccountEnabled(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + baseIssuingCost := "1000" + cs, epochForDynamicNFT := getTestChainSimulatorWithSaveToSystemAccountDisabled(t, baseIssuingCost) + defer cs.Close() + + addrs := createAddresses(t, cs, false) + + log.Info("Initial setup: Create MetaESDT that will have it's metadata saved to the user account") + + metaTicker := []byte("METATICKER") + tx := issueMetaESDTTx(0, addrs[0].Bytes, metaTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + metaTokenID := txResult.Logs.Events[0].Topics[0] + + log.Info("Issued MetaESDT token id", "tokenID", string(metaTokenID)) + + metaData := txsFee.GetDefaultMetaData() + metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + createTokenUpdateTokenIDAndTransfer(t, cs, addrs[0].Bytes, addrs[1].Bytes, metaTokenID, metaData, epochForDynamicNFT, addrs[0]) + + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + checkMetaData(t, cs, core.SystemAccountAddress, metaTokenID, shardID, metaData) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, metaTokenID, shardID) + checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, metaTokenID, shardID) +} + +func getTestChainSimulatorWithDynamicNFTEnabled(t *testing.T, baseIssuingCost string) (testsChainSimulator.ChainSimulator, int32) { + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpochForDynamicNFT := uint32(2) + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: true, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpochForDynamicNFT + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpochForDynamicNFT)) + require.Nil(t, err) + + return cs, int32(activationEpochForDynamicNFT) +} + +func getTestChainSimulatorWithSaveToSystemAccountDisabled(t *testing.T, baseIssuingCost string) (testsChainSimulator.ChainSimulator, int32) { + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpochForSaveToSystemAccount := uint32(2) + activationEpochForDynamicNFT := uint32(4) + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: true, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.OptimizeNFTStoreEnableEpoch = activationEpochForSaveToSystemAccount + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpochForDynamicNFT + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpochForSaveToSystemAccount) - 1) + require.Nil(t, err) + + return cs, int32(activationEpochForDynamicNFT) +} + +func createTokenUpdateTokenIDAndTransfer( + t *testing.T, + cs testsChainSimulator.ChainSimulator, + originAddress []byte, + targetAddress []byte, + tokenID []byte, + metaData *txsFee.MetaData, + epochForDynamicNFT int32, + walletWithRoles dtos.WalletAddress, +) { + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + } + setAddressEsdtRoles(t, cs, walletWithRoles, tokenID, roles) + + tx := nftCreateTx(1, originAddress, tokenID, metaData) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + log.Info("check that the metadata is saved on the user account") + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(originAddress) + checkMetaData(t, cs, originAddress, tokenID, shardID, metaData) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) + + err = cs.GenerateBlocksUntilEpochIsReached(epochForDynamicNFT) + require.Nil(t, err) + + tx = updateTokenIDTx(2, originAddress, tokenID) + + log.Info("updating token id", "tokenID", tokenID) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + log.Info("transferring token id", "tokenID", tokenID) + + tx = esdtNFTTransferTx(3, originAddress, targetAddress, tokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) +} + +func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + baseIssuingCost := "1000" + + cs, epochForDynamicNFT := getTestChainSimulatorWithSaveToSystemAccountDisabled(t, baseIssuingCost) + defer cs.Close() + + addrs := createAddresses(t, cs, false) + + // issue metaESDT + metaESDTTicker := []byte("METATTICKER") + tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + metaESDTTokenID := txResult.Logs.Events[0].Topics[0] + + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + } + setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + + log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) + + // issue NFT + nftTicker := []byte("NFTTICKER") + tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) + + // issue SFT + sftTicker := []byte("SFTTICKER") + tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + sftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + + log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) + + tokenIDs := [][]byte{ + nftTokenID, + sftTokenID, + metaESDTTokenID, + } + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + sftMetaData := txsFee.GetDefaultMetaData() + sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + esdtMetaData := txsFee.GetDefaultMetaData() + esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tokensMetadata := []*txsFee.MetaData{ + nftMetaData, + sftMetaData, + esdtMetaData, + } + + nonce := uint64(3) + for i := range tokenIDs { + tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + + // meta data should be saved on account, since it is before `OptimizeNFTStoreEnableEpoch` + checkMetaData(t, cs, addrs[0].Bytes, nftTokenID, shardID, nftMetaData) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) + + checkMetaData(t, cs, addrs[0].Bytes, sftTokenID, shardID, sftMetaData) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, sftTokenID, shardID) + + checkMetaData(t, cs, addrs[0].Bytes, metaESDTTokenID, shardID, esdtMetaData) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(epochForDynamicNFT)) + require.Nil(t, err) + + log.Info("Change to DYNAMIC type") + + // it will not be able to change nft to dynamic type + for i := range tokenIDs { + tx = changeToDynamicTx(nonce, addrs[0].Bytes, tokenIDs[i]) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } + + for _, tokenID := range tokenIDs { + tx = updateTokenIDTx(nonce, addrs[0].Bytes, tokenID) + + log.Info("updating token id", "tokenID", tokenID) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } + + for _, tokenID := range tokenIDs { + log.Info("transfering token id", "tokenID", tokenID) + + tx = esdtNFTTransferTx(nonce, addrs[0].Bytes, addrs[1].Bytes, tokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } + + checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, sftTokenID, shardID) + checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, sftTokenID, shardID) + + checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, metaESDTTokenID, shardID) + checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, metaESDTTokenID, shardID) + + checkMetaData(t, cs, addrs[1].Bytes, nftTokenID, shardID, nftMetaData) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, nftTokenID, shardID) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) +} + +func TestChainSimulator_CreateAndPauseTokens(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(4) + + baseIssuingCost := "1000" + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: true, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + defer cs.Close() - addrs := createAddresses(t, cs, true) - - log.Info("Register dynamic meta esdt token") + addrs := createAddresses(t, cs, false) - ticker := []byte("META" + "TICKER") - tokenName := []byte("tokenName") + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch) - 1) + require.Nil(t, err) - decimals := big.NewInt(10) + // issue NFT + nftTicker := []byte("NFTTICKER") + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) txDataField := bytes.Join( [][]byte{ - []byte("registerAndSetAllRolesDynamic"), - []byte(hex.EncodeToString(tokenName)), - []byte(hex.EncodeToString(ticker)), - []byte(hex.EncodeToString([]byte("META"))), - []byte(hex.EncodeToString(decimals.Bytes())), + []byte("issueNonFungible"), + []byte(hex.EncodeToString([]byte("asdname"))), + []byte(hex.EncodeToString(nftTicker)), + []byte(hex.EncodeToString([]byte("canPause"))), + []byte(hex.EncodeToString([]byte("true"))), }, []byte("@"), ) - callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) - tx := &transaction.Transaction{ Nonce: 0, SndAddr: addrs[0].Bytes, - RcvAddr: vm.ESDTSCAddress, + RcvAddr: core.ESDTSCAddress, GasLimit: 100_000_000, GasPrice: minGasPrice, Signature: []byte("dummySig"), @@ -2563,20 +3538,21 @@ func TestChainSimulator_MetaESDT_RegisterAndSetAllRolesDynamic(t *testing.T) { txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - metaTokenID := txResult.Logs.Events[0].Topics[0] roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], metaTokenID, roles) + nftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, metaTokenID, nftMetaData) + tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2587,245 +3563,86 @@ func TestChainSimulator_MetaESDT_RegisterAndSetAllRolesDynamic(t *testing.T) { err = cs.GenerateBlocks(10) require.Nil(t, err) + log.Info("Step 1. check that the metadata for all tokens is saved on the system account") + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - checkMetaData(t, cs, core.SystemAccountAddress, metaTokenID, shardID, nftMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) - log.Info("Check that token type is Dynamic") + log.Info("Step 1b. Pause all tokens") scQuery := &process.SCQuery{ - ScAddress: vm.ESDTSCAddress, - FuncName: "getTokenProperties", - CallValue: big.NewInt(0), - Arguments: [][]byte{metaTokenID}, + ScAddress: vm.ESDTSCAddress, + CallerAddr: addrs[0].Bytes, + FuncName: "pause", + CallValue: big.NewInt(0), + Arguments: [][]byte{nftTokenID}, } result, _, err := cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) require.Equal(t, "", result.ReturnMessage) require.Equal(t, testsChainSimulator.OkReturnCode, result.ReturnCode) - tokenType := result.ReturnData[1] - require.Equal(t, core.Dynamic+core.MetaESDT, string(tokenType)) - - log.Info("Check token roles") - - scQuery = &process.SCQuery{ - ScAddress: vm.ESDTSCAddress, - FuncName: "getAllAddressesAndRoles", - CallValue: big.NewInt(0), - Arguments: [][]byte{metaTokenID}, - } - result, _, err = cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ExecuteSCQuery(scQuery) - require.Nil(t, err) - require.Equal(t, "", result.ReturnMessage) - require.Equal(t, testsChainSimulator.OkReturnCode, result.ReturnCode) - - expectedRoles := [][]byte{ - []byte(core.ESDTRoleNFTCreate), - []byte(core.ESDTRoleNFTBurn), - []byte(core.ESDTRoleNFTAddQuantity), - []byte(core.ESDTRoleNFTUpdateAttributes), - []byte(core.ESDTRoleNFTAddURI), - } - - checkTokenRoles(t, result.ReturnData, expectedRoles) -} - -func checkTokenRoles(t *testing.T, returnData [][]byte, expectedRoles [][]byte) { - for _, expRole := range expectedRoles { - found := false - - for _, item := range returnData { - if bytes.Equal(expRole, item) { - found = true - } - } - - require.True(t, found) - } -} - -func TestChainSimulator_NFTcreatedBeforeSaveToSystemAccountEnabled(t *testing.T) { - if testing.Short() { - t.Skip("this is not a short test") - } - - baseIssuingCost := "1000" - cs, epochForDynamicNFT := getTestChainSimulatorWithSaveToSystemAccountDisabled(t, baseIssuingCost) - defer cs.Close() - - addrs := createAddresses(t, cs, false) - - log.Info("Initial setup: Create NFT that will have it's metadata saved to the user account") - - nftTicker := []byte("NFTTICKER") - tx := issueNonFungibleTx(0, addrs[0].Bytes, nftTicker, baseIssuingCost) + log.Info("Step 2. wait for DynamicEsdtFlag activation") - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - nftTokenID := txResult.Logs.Events[0].Topics[0] - - log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) - - nftMetaData := txsFee.GetDefaultMetaData() - nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - - createTokenUpdateTokenIDAndTransfer(t, cs, addrs[0].Bytes, addrs[1].Bytes, nftTokenID, nftMetaData, epochForDynamicNFT, addrs[0]) - - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - checkMetaData(t, cs, addrs[1].Bytes, nftTokenID, shardID, nftMetaData) - checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, nftTokenID, shardID) - checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) -} -func TestChainSimulator_SFTcreatedBeforeSaveToSystemAccountEnabled(t *testing.T) { - if testing.Short() { - t.Skip("this is not a short test") - } - - baseIssuingCost := "1000" - cs, epochForDynamicNFT := getTestChainSimulatorWithSaveToSystemAccountDisabled(t, baseIssuingCost) - defer cs.Close() - - addrs := createAddresses(t, cs, false) + log.Info("Step 5. make an updateTokenID@tokenID function call on the ESDTSystem SC for all token types") - log.Info("Initial setup: Create SFT that will have it's metadata saved to the user account") + tx = updateTokenIDTx(2, addrs[0].Bytes, nftTokenID) - sftTicker := []byte("SFTTICKER") - tx := issueSemiFungibleTx(0, addrs[0].Bytes, sftTicker, baseIssuingCost) + log.Info("updating token id", "tokenID", nftTokenID) - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - sftTokenID := txResult.Logs.Events[0].Topics[0] - - log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) - - metaData := txsFee.GetDefaultMetaData() - metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - - createTokenUpdateTokenIDAndTransfer(t, cs, addrs[0].Bytes, addrs[1].Bytes, sftTokenID, metaData, epochForDynamicNFT, addrs[0]) - - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - - checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, metaData) - checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, sftTokenID, shardID) - checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, sftTokenID, shardID) -} -func TestChainSimulator_FungibleCreatedBeforeSaveToSystemAccountEnabled(t *testing.T) { - if testing.Short() { - t.Skip("this is not a short test") - } - - baseIssuingCost := "1000" - cs, epochForDynamicNFT := getTestChainSimulatorWithSaveToSystemAccountDisabled(t, baseIssuingCost) - defer cs.Close() + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - addrs := createAddresses(t, cs, false) - - log.Info("Initial setup: Create FungibleESDT that will have it's metadata saved to the user account") - - funTicker := []byte("FUNTICKER") - tx := issueTx(0, addrs[0].Bytes, funTicker, baseIssuingCost) - - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - funTokenID := txResult.Logs.Events[0].Topics[0] - - log.Info("Issued FungibleESDT token id", "tokenID", string(funTokenID)) - - metaData := txsFee.GetDefaultMetaData() - metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - - createTokenUpdateTokenIDAndTransfer(t, cs, addrs[0].Bytes, addrs[1].Bytes, funTokenID, metaData, epochForDynamicNFT, addrs[0]) - - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - - checkMetaData(t, cs, core.SystemAccountAddress, funTokenID, shardID, metaData) - checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, funTokenID, shardID) - checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, funTokenID, shardID) -} - -func TestChainSimulator_MetaESDTCreatedBeforeSaveToSystemAccountEnabled(t *testing.T) { - if testing.Short() { - t.Skip("this is not a short test") - } - - baseIssuingCost := "1000" - cs, epochForDynamicNFT := getTestChainSimulatorWithSaveToSystemAccountDisabled(t, baseIssuingCost) - defer cs.Close() - - addrs := createAddresses(t, cs, false) - log.Info("Initial setup: Create MetaESDT that will have it's metadata saved to the user account") - - metaTicker := []byte("METATICKER") - tx := issueMetaESDTTx(0, addrs[0].Bytes, metaTicker, baseIssuingCost) + log.Info("Step 6. check that the metadata for all tokens is saved on the system account") - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + err = cs.GenerateBlocks(10) require.Nil(t, err) - require.NotNil(t, txResult) - - metaTokenID := txResult.Logs.Events[0].Topics[0] - - log.Info("Issued MetaESDT token id", "tokenID", string(metaTokenID)) - - metaData := txsFee.GetDefaultMetaData() - metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - - createTokenUpdateTokenIDAndTransfer(t, cs, addrs[0].Bytes, addrs[1].Bytes, metaTokenID, metaData, epochForDynamicNFT, addrs[0]) - - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - checkMetaData(t, cs, core.SystemAccountAddress, metaTokenID, shardID, metaData) - checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, metaTokenID, shardID) - checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, metaTokenID, shardID) -} - -func getTestChainSimulatorWithDynamicNFTEnabled(t *testing.T, baseIssuingCost string) (testsChainSimulator.ChainSimulator, int32) { - startTime := time.Now().Unix() - roundDurationInMillis := uint64(6000) - roundsPerEpoch := core.OptionalUint64{ - HasValue: true, - Value: 20, - } - activationEpochForDynamicNFT := uint32(2) + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) - numOfShards := uint32(3) - cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: true, - TempDir: t.TempDir(), - PathToInitialConfig: defaultPathToInitialConfig, - NumOfShards: numOfShards, - GenesisTimestamp: startTime, - RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, - ApiInterface: api.NewNoApiInterface(), - MinNodesPerShard: 3, - MetaChainMinNodes: 3, - NumNodesWaitingListMeta: 0, - NumNodesWaitingListShard: 0, - AlterConfigsFunction: func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpochForDynamicNFT - cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost - }, - }) + log.Info("Step 7. transfer the tokens to another account") + + log.Info("transfering token id", "tokenID", nftTokenID) + + tx = esdtNFTTransferTx(3, addrs[0].Bytes, addrs[1].Bytes, nftTokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) - require.NotNil(t, cs) + require.NotNil(t, txResult) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpochForDynamicNFT)) + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) + + log.Info("Step 8. check that the metaData for the NFT is still on the system account") + + err = cs.GenerateBlocks(10) require.Nil(t, err) - return cs, int32(activationEpochForDynamicNFT) + shardID = cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[2].Bytes) + + checkMetaData(t, cs, addrs[1].Bytes, nftTokenID, shardID, nftMetaData) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, nftTokenID, shardID) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) } -func getTestChainSimulatorWithSaveToSystemAccountDisabled(t *testing.T, baseIssuingCost string) (testsChainSimulator.ChainSimulator, int32) { +func TestChainSimulator_CreateAndPauseTokens_ChangeToDynamic(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + startTime := time.Now().Unix() roundDurationInMillis := uint64(6000) roundsPerEpoch := core.OptionalUint64{ @@ -2833,8 +3650,9 @@ func getTestChainSimulatorWithSaveToSystemAccountDisabled(t *testing.T, baseIssu Value: 20, } - activationEpochForSaveToSystemAccount := uint32(2) - activationEpochForDynamicNFT := uint32(4) + activationEpoch := uint32(4) + + baseIssuingCost := "1000" numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ @@ -2851,234 +3669,169 @@ func getTestChainSimulatorWithSaveToSystemAccountDisabled(t *testing.T, baseIssu NumNodesWaitingListMeta: 0, NumNodesWaitingListShard: 0, AlterConfigsFunction: func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.OptimizeNFTStoreEnableEpoch = activationEpochForSaveToSystemAccount - cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpochForDynamicNFT + cfg.EpochConfig.EnableEpochs.DynamicESDTEnableEpoch = activationEpoch cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost }, }) require.Nil(t, err) require.NotNil(t, cs) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpochForSaveToSystemAccount) - 1) - require.Nil(t, err) - - return cs, int32(activationEpochForDynamicNFT) -} - -func createTokenUpdateTokenIDAndTransfer( - t *testing.T, - cs testsChainSimulator.ChainSimulator, - originAddress []byte, - targetAddress []byte, - tokenID []byte, - metaData *txsFee.MetaData, - epochForDynamicNFT int32, - walletWithRoles dtos.WalletAddress, -) { - roles := [][]byte{ - []byte(core.ESDTRoleNFTCreate), - []byte(core.ESDTRoleTransfer), - } - setAddressEsdtRoles(t, cs, walletWithRoles, tokenID, roles) - - tx := nftCreateTx(1, originAddress, tokenID, metaData) - - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - - require.Equal(t, "success", txResult.Status.String()) + defer cs.Close() - log.Info("check that the metadata is saved on the user account") - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(originAddress) - checkMetaData(t, cs, originAddress, tokenID, shardID, metaData) - checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) + addrs := createAddresses(t, cs, false) - err = cs.GenerateBlocksUntilEpochIsReached(epochForDynamicNFT) + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch) - 1) require.Nil(t, err) - tx = updateTokenIDTx(2, originAddress, tokenID) - - log.Info("updating token id", "tokenID", tokenID) + log.Info("Step 2. wait for DynamicEsdtFlag activation") - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - err = cs.GenerateBlocks(10) - require.Nil(t, err) + // register dynamic NFT + nftTicker := []byte("NFTTICKER") + nftTokenName := []byte("tokenName") - log.Info("transferring token id", "tokenID", tokenID) + txDataField := bytes.Join( + [][]byte{ + []byte("registerDynamic"), + []byte(hex.EncodeToString(nftTokenName)), + []byte(hex.EncodeToString(nftTicker)), + []byte(hex.EncodeToString([]byte("NFT"))), + []byte(hex.EncodeToString([]byte("canPause"))), + []byte(hex.EncodeToString([]byte("true"))), + }, + []byte("@"), + ) - tx = esdtNFTTransferTx(3, originAddress, targetAddress, tokenID) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) -} + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) -func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { - if testing.Short() { - t.Skip("this is not a short test") + tx := &transaction.Transaction{ + Nonce: 0, + SndAddr: addrs[0].Bytes, + RcvAddr: vm.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: callValue, + ChainID: []byte(configs.ChainID), + Version: 1, } - baseIssuingCost := "1000" - - cs, epochForDynamicNFT := getTestChainSimulatorWithSaveToSystemAccountDisabled(t, baseIssuingCost) - defer cs.Close() - - addrs := createAddresses(t, cs, false) - - // issue metaESDT - metaESDTTicker := []byte("METATTICKER") - tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - metaESDTTokenID := txResult.Logs.Events[0].Topics[0] + require.Equal(t, "success", txResult.Status.String()) roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), + []byte(core.ESDTRoleNFTUpdate), } - setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) - - log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) - - // issue NFT - nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) - - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) - // issue SFT - sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - - sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) - - log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) - tokenIDs := [][]byte{ - nftTokenID, - sftTokenID, - metaESDTTokenID, - } - - nftMetaData := txsFee.GetDefaultMetaData() - nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - sftMetaData := txsFee.GetDefaultMetaData() - sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + require.Equal(t, "success", txResult.Status.String()) - esdtMetaData := txsFee.GetDefaultMetaData() - esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + err = cs.GenerateBlocks(10) + require.Nil(t, err) - tokensMetadata := []*txsFee.MetaData{ - nftMetaData, - sftMetaData, - esdtMetaData, - } + log.Info("Step 1. check that the metadata for all tokens is saved on the system account") - nonce := uint64(3) - for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) - require.Equal(t, "success", txResult.Status.String()) + log.Info("Step 1b. Pause all tokens") - nonce++ + scQuery := &process.SCQuery{ + ScAddress: vm.ESDTSCAddress, + CallerAddr: addrs[0].Bytes, + FuncName: "pause", + CallValue: big.NewInt(0), + Arguments: [][]byte{nftTokenID}, } - - err = cs.GenerateBlocks(10) + result, _, err := cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ExecuteSCQuery(scQuery) require.Nil(t, err) + require.Equal(t, "", result.ReturnMessage) + require.Equal(t, testsChainSimulator.OkReturnCode, result.ReturnCode) - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + tx = updateTokenIDTx(2, addrs[0].Bytes, nftTokenID) - // meta data should be saved on account, since it is before `OptimizeNFTStoreEnableEpoch` - checkMetaData(t, cs, addrs[0].Bytes, nftTokenID, shardID, nftMetaData) - checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) + log.Info("updating token id", "tokenID", nftTokenID) - checkMetaData(t, cs, addrs[0].Bytes, sftTokenID, shardID, sftMetaData) - checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, sftTokenID, shardID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) - checkMetaData(t, cs, addrs[0].Bytes, metaESDTTokenID, shardID, esdtMetaData) - checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID) + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - err = cs.GenerateBlocksUntilEpochIsReached(int32(epochForDynamicNFT)) - require.Nil(t, err) + require.Equal(t, "success", txResult.Status.String()) - log.Info("Change to DYNAMIC type") + log.Info("change to dynamic token") - // it will not be able to change nft to dynamic type - for i := range tokenIDs { - tx = changeToDynamicTx(nonce, addrs[0].Bytes, tokenIDs[i]) + tx = changeToDynamicTx(3, addrs[0].Bytes, nftTokenID) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) + log.Info("updating token id", "tokenID", nftTokenID) - require.Equal(t, "success", txResult.Status.String()) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) - nonce++ - } + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - for _, tokenID := range tokenIDs { - tx = updateTokenIDTx(nonce, addrs[0].Bytes, tokenID) + require.Equal(t, "success", txResult.Status.String()) - log.Info("updating token id", "tokenID", tokenID) + log.Info("Step 6. check that the metadata for all tokens is saved on the system account") - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) + err = cs.GenerateBlocks(10) + require.Nil(t, err) - nonce++ - } + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) - for _, tokenID := range tokenIDs { - log.Info("transfering token id", "tokenID", tokenID) + log.Info("transfering token id", "tokenID", nftTokenID) - tx = esdtNFTTransferTx(nonce, addrs[0].Bytes, addrs[1].Bytes, tokenID) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) + tx = esdtNFTTransferTx(4, addrs[0].Bytes, addrs[1].Bytes, nftTokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - nonce++ - } + require.Equal(t, "success", txResult.Status.String()) - checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData) - checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, sftTokenID, shardID) - checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, sftTokenID, shardID) + log.Info("Step 8. check that the metaData for the NFT is still on the system account") - checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) - checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, metaESDTTokenID, shardID) - checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, metaESDTTokenID, shardID) + err = cs.GenerateBlocks(10) + require.Nil(t, err) - checkMetaData(t, cs, addrs[1].Bytes, nftTokenID, shardID, nftMetaData) + shardID = cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[2].Bytes) + + checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, nftTokenID, shardID) - checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) + checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, nftTokenID, shardID) } From f73164719becbc34af6349a0126519e9c174029a Mon Sep 17 00:00:00 2001 From: ssd04 Date: Mon, 1 Jul 2024 12:53:24 +0300 Subject: [PATCH 395/503] update sft metaesdt modify creator scenario --- .../chainSimulator/vm/esdtImprovements_test.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 12996710749..e13501faede 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -1359,6 +1359,7 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { } } +// ESDTModifyCreator without changing to dynamic type func TestChainSimulator_ESDTModifyCreator_SFTmetaESDT(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") @@ -1483,6 +1484,14 @@ func TestChainSimulator_ESDTModifyCreator_SFTmetaESDT(t *testing.T) { } setAddressEsdtRoles(t, cs, newCreatorAddress, tokenIDs[i], roles) + log.Info("transfering token id", "tokenID", tokenIDs[i]) + + tx = esdtNFTTransferTx(nonce, addrs[1].Bytes, newCreatorAddress.Bytes, tokenIDs[i]) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + txDataField := bytes.Join( [][]byte{ []byte(core.ESDTModifyCreator), @@ -1533,8 +1542,6 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() - log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag). Register NFT directly as dynamic") - addrs := createAddresses(t, cs, false) // issue metaESDT @@ -1742,8 +1749,6 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() - log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") - addrs := createAddresses(t, cs, false) // issue metaESDT From d10c39624ea063f70b17742fb53b16d7d469e37b Mon Sep 17 00:00:00 2001 From: ssd04 Date: Mon, 1 Jul 2024 13:11:19 +0300 Subject: [PATCH 396/503] refactor modify creator tx --- .../vm/esdtImprovements_test.go | 111 ++++++------------ 1 file changed, 37 insertions(+), 74 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index e13501faede..9af46d630b6 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -627,6 +627,33 @@ func nftCreateTx( } } +func modifyCreatorTx( + sndAdr []byte, + tokenID []byte, +) *transaction.Transaction { + txDataField := bytes.Join( + [][]byte{ + []byte(core.ESDTModifyCreator), + []byte(hex.EncodeToString(tokenID)), + []byte(hex.EncodeToString(big.NewInt(1).Bytes())), + }, + []byte("@"), + ) + + return &transaction.Transaction{ + Nonce: 0, + SndAddr: sndAdr, + RcvAddr: sndAdr, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } +} + func getESDTDataFromAcc( t *testing.T, cs testsChainSimulator.ChainSimulator, @@ -1323,27 +1350,7 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { } setAddressEsdtRoles(t, cs, newCreatorAddress, tokenIDs[i], roles) - txDataField := bytes.Join( - [][]byte{ - []byte(core.ESDTModifyCreator), - []byte(hex.EncodeToString(tokenIDs[i])), - []byte(hex.EncodeToString(big.NewInt(1).Bytes())), - }, - []byte("@"), - ) - - tx = &transaction.Transaction{ - Nonce: 0, - SndAddr: newCreatorAddress.Bytes, - RcvAddr: newCreatorAddress.Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, - } + tx = modifyCreatorTx(newCreatorAddress.Bytes, tokenIDs[i]) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1433,10 +1440,6 @@ func TestChainSimulator_ESDTModifyCreator_SFTmetaESDT(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) nonce++ @@ -1451,10 +1454,6 @@ func TestChainSimulator_ESDTModifyCreator_SFTmetaESDT(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) nonce++ @@ -1492,36 +1491,12 @@ func TestChainSimulator_ESDTModifyCreator_SFTmetaESDT(t *testing.T) { require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - txDataField := bytes.Join( - [][]byte{ - []byte(core.ESDTModifyCreator), - []byte(hex.EncodeToString(tokenIDs[i])), - []byte(hex.EncodeToString(big.NewInt(1).Bytes())), - }, - []byte("@"), - ) - - tx = &transaction.Transaction{ - Nonce: 0, - SndAddr: newCreatorAddress.Bytes, - RcvAddr: newCreatorAddress.Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, - } + tx = modifyCreatorTx(newCreatorAddress.Bytes, tokenIDs[i]) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID) @@ -1693,27 +1668,15 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { } setAddressEsdtRoles(t, cs, newCreatorAddress, tokenIDs[i], roles) - txDataField := bytes.Join( - [][]byte{ - []byte(core.ESDTModifyCreator), - []byte(hex.EncodeToString(tokenIDs[i])), - []byte(hex.EncodeToString(big.NewInt(1).Bytes())), - }, - []byte("@"), - ) + log.Info("transfering token id", "tokenID", tokenIDs[i]) - tx = &transaction.Transaction{ - Nonce: 0, - SndAddr: newCreatorAddress.Bytes, - RcvAddr: newCreatorAddress.Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, - } + tx = esdtNFTTransferTx(nonce, addrs[1].Bytes, newCreatorAddress.Bytes, tokenIDs[i]) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + tx = modifyCreatorTx(newCreatorAddress.Bytes, tokenIDs[i]) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) From 025be07dced4b54f33f77ff6c5c0006484187c30 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Mon, 1 Jul 2024 13:16:49 +0300 Subject: [PATCH 397/503] cleanup changes --- .../vm/esdtImprovements_test.go | 52 ++++--------------- 1 file changed, 11 insertions(+), 41 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 9af46d630b6..099dad860d5 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -3430,7 +3430,7 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) } -func TestChainSimulator_CreateAndPauseTokens(t *testing.T) { +func TestChainSimulator_CreateAndPause_NFT(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } @@ -3531,13 +3531,13 @@ func TestChainSimulator_CreateAndPauseTokens(t *testing.T) { err = cs.GenerateBlocks(10) require.Nil(t, err) - log.Info("Step 1. check that the metadata for all tokens is saved on the system account") + log.Info("check that the metadata for all tokens is saved on the system account") shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) - log.Info("Step 1b. Pause all tokens") + log.Info("Pause all tokens") scQuery := &process.SCQuery{ ScAddress: vm.ESDTSCAddress, @@ -3551,12 +3551,12 @@ func TestChainSimulator_CreateAndPauseTokens(t *testing.T) { require.Equal(t, "", result.ReturnMessage) require.Equal(t, testsChainSimulator.OkReturnCode, result.ReturnCode) - log.Info("Step 2. wait for DynamicEsdtFlag activation") + log.Info("wait for DynamicEsdtFlag activation") err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) require.Nil(t, err) - log.Info("Step 5. make an updateTokenID@tokenID function call on the ESDTSystem SC for all token types") + log.Info("make an updateTokenID@tokenID function call on the ESDTSystem SC for all token types") tx = updateTokenIDTx(2, addrs[0].Bytes, nftTokenID) @@ -3565,21 +3565,16 @@ func TestChainSimulator_CreateAndPauseTokens(t *testing.T) { txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) - log.Info("Step 6. check that the metadata for all tokens is saved on the system account") + log.Info("check that the metadata for all tokens is saved on the system account") err = cs.GenerateBlocks(10) require.Nil(t, err) checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) - log.Info("Step 7. transfer the tokens to another account") + log.Info("transfer the tokens to another account") log.Info("transfering token id", "tokenID", nftTokenID) @@ -3587,14 +3582,9 @@ func TestChainSimulator_CreateAndPauseTokens(t *testing.T) { txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) - log.Info("Step 8. check that the metaData for the NFT is still on the system account") + log.Info("check that the metaData for the NFT is still on the system account") err = cs.GenerateBlocks(10) require.Nil(t, err) @@ -3606,7 +3596,7 @@ func TestChainSimulator_CreateAndPauseTokens(t *testing.T) { checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) } -func TestChainSimulator_CreateAndPauseTokens_ChangeToDynamic(t *testing.T) { +func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } @@ -3712,11 +3702,6 @@ func TestChainSimulator_CreateAndPauseTokens_ChangeToDynamic(t *testing.T) { txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) err = cs.GenerateBlocks(10) @@ -3749,11 +3734,6 @@ func TestChainSimulator_CreateAndPauseTokens_ChangeToDynamic(t *testing.T) { txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) log.Info("change to dynamic token") @@ -3765,14 +3745,9 @@ func TestChainSimulator_CreateAndPauseTokens_ChangeToDynamic(t *testing.T) { txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) - log.Info("Step 6. check that the metadata for all tokens is saved on the system account") + log.Info("check that the metadata for all tokens is saved on the system account") err = cs.GenerateBlocks(10) require.Nil(t, err) @@ -3785,14 +3760,9 @@ func TestChainSimulator_CreateAndPauseTokens_ChangeToDynamic(t *testing.T) { txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) - log.Info("Step 8. check that the metaData for the NFT is still on the system account") + log.Info("check that the metaData for the NFT is still on the system account") err = cs.GenerateBlocks(10) require.Nil(t, err) From 2b5f7fa57cb43963588a39e1912d18535e127973 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Mon, 1 Jul 2024 15:40:17 +0300 Subject: [PATCH 398/503] fix modify creator cross shard test --- .../chainSimulator/vm/esdtImprovements_test.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 099dad860d5..affd7a6a894 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -628,6 +628,7 @@ func nftCreateTx( } func modifyCreatorTx( + nonce uint64, sndAdr []byte, tokenID []byte, ) *transaction.Transaction { @@ -641,7 +642,7 @@ func modifyCreatorTx( ) return &transaction.Transaction{ - Nonce: 0, + Nonce: nonce, SndAddr: sndAdr, RcvAddr: sndAdr, GasLimit: 10_000_000, @@ -1350,7 +1351,7 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { } setAddressEsdtRoles(t, cs, newCreatorAddress, tokenIDs[i], roles) - tx = modifyCreatorTx(newCreatorAddress.Bytes, tokenIDs[i]) + tx = modifyCreatorTx(0, newCreatorAddress.Bytes, tokenIDs[i]) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1491,7 +1492,7 @@ func TestChainSimulator_ESDTModifyCreator_SFTmetaESDT(t *testing.T) { require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - tx = modifyCreatorTx(newCreatorAddress.Bytes, tokenIDs[i]) + tx = modifyCreatorTx(0, newCreatorAddress.Bytes, tokenIDs[i]) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1674,9 +1675,13 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) - tx = modifyCreatorTx(newCreatorAddress.Bytes, tokenIDs[i]) + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + tx = modifyCreatorTx(0, newCreatorAddress.Bytes, tokenIDs[i]) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1688,6 +1693,7 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(newCreatorAddress.Bytes) retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID) require.Equal(t, newCreatorAddress.Bytes, retrievedMetaData.Creator) From 7847e2e4adef137eb548aacde2487dce4106384d Mon Sep 17 00:00:00 2001 From: ssd04 Date: Mon, 1 Jul 2024 18:48:52 +0300 Subject: [PATCH 399/503] update change metadata test --- .../vm/esdtImprovements_test.go | 56 +++++++++++-------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index affd7a6a894..8eb54942d38 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -2136,11 +2136,27 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { // 2. change the sft meta data (differently from the previous one) in the other shard // 3. send sft from one shard to another // 4. check that the newest metadata is saved -func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { +func TestChainSimulator_ChangeMetaData(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } + t.Run("sft change metadata", func(t *testing.T) { + testChainSimulatorChangeMetaData(t, issueSemiFungibleTx) + }) + + t.Run("metaESDT change metadata", func(t *testing.T) { + testChainSimulatorChangeMetaData(t, issueMetaESDTTx) + }) + + t.Run("fungible change metadata", func(t *testing.T) { + testChainSimulatorChangeMetaData(t, issueTx) + }) +} + +type issueTxFunc func(uint64, []byte, []byte, string) *transaction.Transaction + +func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { baseIssuingCost := "1000" cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) @@ -2148,7 +2164,7 @@ func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { addrs := createAddresses(t, cs, true) - log.Info("Initial setup: Create SFT and send in 2 shards") + log.Info("Initial setup: Create token and send in 2 shards") roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), @@ -2156,22 +2172,20 @@ func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { []byte(core.ESDTRoleNFTAddQuantity), } - sftTicker := []byte("SFTTICKER") - tx := issueSemiFungibleTx(0, addrs[1].Bytes, sftTicker, baseIssuingCost) - + ticker := []byte("TICKER") + tx := issueFn(0, addrs[1].Bytes, ticker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[1], sftTokenID, roles) + tokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[1], tokenID, roles) - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) - setAddressEsdtRoles(t, cs, addrs[2], sftTokenID, roles) + setAddressEsdtRoles(t, cs, addrs[0], tokenID, roles) + setAddressEsdtRoles(t, cs, addrs[2], tokenID, roles) - log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) + log.Info("Issued token id", "tokenID", string(tokenID)) sftMetaData := txsFee.GetDefaultMetaData() sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) @@ -2179,7 +2193,7 @@ func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { txDataField := bytes.Join( [][]byte{ []byte(core.BuiltInFunctionESDTNFTCreate), - []byte(hex.EncodeToString(sftTokenID)), + []byte(hex.EncodeToString(tokenID)), []byte(hex.EncodeToString(big.NewInt(2).Bytes())), // quantity sftMetaData.Name, []byte(hex.EncodeToString(big.NewInt(10).Bytes())), @@ -2208,7 +2222,6 @@ func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) err = cs.GenerateBlocks(10) @@ -2216,13 +2229,13 @@ func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { log.Info("Send to separate shards") - tx = esdtNFTTransferTx(2, addrs[1].Bytes, addrs[2].Bytes, sftTokenID) + tx = esdtNFTTransferTx(2, addrs[1].Bytes, addrs[2].Bytes, tokenID) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - tx = esdtNFTTransferTx(3, addrs[1].Bytes, addrs[0].Bytes, sftTokenID) + tx = esdtNFTTransferTx(3, addrs[1].Bytes, addrs[0].Bytes, tokenID) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) @@ -2244,7 +2257,7 @@ func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { txDataField = bytes.Join( [][]byte{ []byte(core.ESDTMetaDataUpdate), - []byte(hex.EncodeToString(sftTokenID)), + []byte(hex.EncodeToString(tokenID)), sftMetaData2.Nonce, sftMetaData2.Name, []byte(hex.EncodeToString(big.NewInt(10).Bytes())), @@ -2273,12 +2286,11 @@ func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData2) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, shardID, sftMetaData2) log.Info("Step 2. change the sft meta data (differently from the previous one) in the other shard") @@ -2292,7 +2304,7 @@ func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { txDataField = bytes.Join( [][]byte{ []byte(core.ESDTMetaDataUpdate), - []byte(hex.EncodeToString(sftTokenID)), + []byte(hex.EncodeToString(tokenID)), sftMetaData3.Nonce, sftMetaData3.Name, []byte(hex.EncodeToString(big.NewInt(10).Bytes())), @@ -2326,11 +2338,11 @@ func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { shardID = cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[2].Bytes) - checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData3) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, shardID, sftMetaData3) log.Info("Step 3. send sft from one shard to another") - tx = esdtNFTTransferTx(1, addrs[0].Bytes, addrs[2].Bytes, sftTokenID) + tx = esdtNFTTransferTx(1, addrs[0].Bytes, addrs[2].Bytes, tokenID) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) @@ -2344,7 +2356,7 @@ func TestChainSimulator_SFT_ChangeMetaData(t *testing.T) { shardID = cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[2].Bytes) - checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData2) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, shardID, sftMetaData2) } func TestChainSimulator_NFT_RegisterDynamic(t *testing.T) { From dcb8d79f1a0a06d0dd5f1b246adf083dda9e8421 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 1 Jul 2024 19:51:40 +0300 Subject: [PATCH 400/503] fixes after review --- factory/api/apiResolverFactory.go | 5 ----- factory/processing/txSimulatorProcessComponents.go | 10 ---------- .../vm/txsFee/multiShard/relayedMoveBalance_test.go | 6 +++--- 3 files changed, 3 insertions(+), 18 deletions(-) diff --git a/factory/api/apiResolverFactory.go b/factory/api/apiResolverFactory.go index 90edb620860..dfefa56ff94 100644 --- a/factory/api/apiResolverFactory.go +++ b/factory/api/apiResolverFactory.go @@ -185,11 +185,6 @@ func CreateApiResolver(args *ApiResolverArgs) (facade.ApiResolver, error) { return nil, err } - err = args.CoreComponents.EconomicsData().SetTxTypeHandler(txTypeHandler) - if err != nil { - return nil, err - } - accountsWrapper := &trieIterators.AccountsWrapper{ Mutex: &sync.Mutex{}, AccountsAdapter: args.StateComponents.AccountsAdapterAPI(), diff --git a/factory/processing/txSimulatorProcessComponents.go b/factory/processing/txSimulatorProcessComponents.go index 65361580358..21fe2ddc073 100644 --- a/factory/processing/txSimulatorProcessComponents.go +++ b/factory/processing/txSimulatorProcessComponents.go @@ -155,11 +155,6 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessorForMeta( return args, nil, nil, err } - err = pcf.coreData.EconomicsData().SetTxTypeHandler(txTypeHandler) - if err != nil { - return args, nil, nil, err - } - gasHandler, err := preprocess.NewGasComputation( pcf.coreData.EconomicsData(), txTypeHandler, @@ -332,11 +327,6 @@ func (pcf *processComponentsFactory) createArgsTxSimulatorProcessorShard( } txFeeHandler := &processDisabled.FeeHandler{} - err = pcf.coreData.EconomicsData().SetTxTypeHandler(txTypeHandler) - if err != nil { - return args, nil, nil, err - } - gasHandler, err := preprocess.NewGasComputation( pcf.coreData.EconomicsData(), txTypeHandler, diff --git a/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go b/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go index b9d4078cfa9..b8cbfeae1da 100644 --- a/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go +++ b/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go @@ -266,13 +266,13 @@ func testRelayedMoveBalanceExecuteOnSourceAndDestinationRelayerAndInnerTxSenderS // check relayed balance // before base cost fix: 100000 - rTxFee(163)*gasPrice(10) - innerTxFee(1000) = 97370 // after base cost fix: 100000 - rTxFee(163)*gasPrice(10) - innerTxFee(10) = 98360 - expectedConsumedFee := big.NewInt(97370) + expectedRelayerBalance := big.NewInt(97370) expectedAccumulatedFees := big.NewInt(2630) if relayedFixActivationEpoch != integrationTests.UnreachableEpoch { - expectedConsumedFee = big.NewInt(98360) + expectedRelayerBalance = big.NewInt(98360) expectedAccumulatedFees = big.NewInt(1640) } - utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, expectedConsumedFee) + utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, expectedRelayerBalance) // check inner tx sender utils.TestAccount(t, testContextSource.Accounts, sndAddr, 1, big.NewInt(0)) From 80218b63d21a6eac225ad02b3ed26060284a7b5b Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 2 Jul 2024 13:56:50 +0300 Subject: [PATCH 401/503] fixes after review, use gas price modifier in tests --- integrationTests/vm/testInitializer.go | 54 +++++++--- .../vm/txsFee/apiTransactionEvaluator_test.go | 12 +-- .../vm/txsFee/asyncCall_multi_test.go | 26 ++--- integrationTests/vm/txsFee/asyncCall_test.go | 8 +- integrationTests/vm/txsFee/asyncESDT_test.go | 16 +-- .../vm/txsFee/backwardsCompatibility_test.go | 6 +- .../vm/txsFee/builtInFunctions_test.go | 29 +++--- integrationTests/vm/txsFee/common.go | 5 +- integrationTests/vm/txsFee/dns_test.go | 8 +- .../vm/txsFee/dynamicGasCost_test.go | 2 +- .../vm/txsFee/esdtLocalBurn_test.go | 6 +- .../vm/txsFee/esdtLocalMint_test.go | 4 +- .../vm/txsFee/esdtMetaDataRecreate_test.go | 2 +- .../vm/txsFee/esdtMetaDataUpdate_test.go | 2 +- .../vm/txsFee/esdtModifyCreator_test.go | 2 +- .../vm/txsFee/esdtModifyRoyalties_test.go | 2 +- .../vm/txsFee/esdtSetNewURIs_test.go | 2 +- integrationTests/vm/txsFee/esdt_test.go | 8 +- .../vm/txsFee/guardAccount_test.go | 1 + .../vm/txsFee/migrateDataTrie_test.go | 4 +- .../vm/txsFee/moveBalance_test.go | 14 +-- .../vm/txsFee/multiESDTTransfer_test.go | 4 +- .../asyncCallWithChangeOwner_test.go | 4 +- .../vm/txsFee/multiShard/asyncCall_test.go | 12 +-- .../vm/txsFee/multiShard/asyncESDT_test.go | 12 +-- .../multiShard/builtInFunctions_test.go | 6 +- .../txsFee/multiShard/esdtLiquidity_test.go | 12 +-- .../vm/txsFee/multiShard/esdt_test.go | 6 +- .../vm/txsFee/multiShard/moveBalance_test.go | 10 +- .../multiShard/nftTransferUpdate_test.go | 4 +- .../relayedBuiltInFunctions_test.go | 6 +- .../multiShard/relayedMoveBalance_test.go | 55 ++++++----- .../txsFee/multiShard/relayedScDeploy_test.go | 4 +- .../multiShard/relayedTxScCalls_test.go | 12 +-- .../scCallWithValueTransfer_test.go | 4 +- .../vm/txsFee/multiShard/scCalls_test.go | 8 +- .../vm/txsFee/relayedAsyncCall_test.go | 2 +- .../vm/txsFee/relayedAsyncESDT_test.go | 6 +- .../vm/txsFee/relayedBuiltInFunctions_test.go | 52 +++++----- integrationTests/vm/txsFee/relayedDns_test.go | 2 +- .../vm/txsFee/relayedESDT_test.go | 32 +++--- .../vm/txsFee/relayedMoveBalance_test.go | 14 +-- .../vm/txsFee/relayedScCalls_test.go | 99 +++++++++++-------- .../vm/txsFee/relayedScDeploy_test.go | 47 ++++++--- integrationTests/vm/txsFee/scCalls_test.go | 27 ++--- integrationTests/vm/txsFee/scDeploy_test.go | 8 +- integrationTests/vm/txsFee/utils/utils.go | 5 +- .../vm/txsFee/validatorSC_test.go | 7 +- .../scenariosConverterUtils.go | 4 +- .../vm/wasm/wasmvm/wasmVM_test.go | 4 +- 50 files changed, 388 insertions(+), 293 deletions(-) diff --git a/integrationTests/vm/testInitializer.go b/integrationTests/vm/testInitializer.go index 8fcd704ad88..151b64bb57b 100644 --- a/integrationTests/vm/testInitializer.go +++ b/integrationTests/vm/testInitializer.go @@ -318,7 +318,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, gasPriceModifier float64) (process.EconomicsDataHandler, error) { maxGasLimitPerBlock := strconv.FormatUint(math.MaxUint64, 10) minGasPrice := strconv.FormatUint(1, 10) minGasLimit := strconv.FormatUint(1, 10) @@ -364,7 +364,7 @@ func createEconomicsData(enableEpochsConfig config.EnableEpochs) (process.Econom }, MinGasPrice: minGasPrice, GasPerDataByte: "1", - GasPriceModifier: 1.0, + GasPriceModifier: gasPriceModifier, MaxGasPriceSetGuardian: "2000000000", }, }, @@ -438,7 +438,7 @@ func CreateTxProcessorWithOneSCExecutorMockVM( } txTypeHandler, _ := coordinator.NewTxTypeHandler(argsTxTypeHandler) - economicsData, err := createEconomicsData(enableEpochsConfig) + economicsData, err := createEconomicsData(enableEpochsConfig, 1) if err != nil { return nil, err } @@ -691,7 +691,7 @@ func CreateVMAndBlockchainHookMeta( MissingTrieNodesNotifier: &testscommon.MissingTrieNodesNotifierStub{}, } - economicsData, err := createEconomicsData(config.EnableEpochs{}) + economicsData, err := createEconomicsData(config.EnableEpochs{}, 1) if err != nil { log.LogIfError(err) } @@ -831,6 +831,7 @@ func CreateTxProcessorWithOneSCExecutorWithVMs( guardianChecker process.GuardianChecker, roundNotifierInstance process.RoundNotifier, chainHandler data.ChainHandler, + gasPriceModifier float64, ) (*ResultsCreateTxProcessor, error) { if check.IfNil(poolsHolder) { poolsHolder = dataRetrieverMock.NewPoolsHolderMock() @@ -853,7 +854,7 @@ func CreateTxProcessorWithOneSCExecutorWithVMs( gasSchedule := make(map[string]map[string]uint64) defaults.FillGasMapInternal(gasSchedule, 1) - economicsData, err := createEconomicsData(enableEpochsConfig) + economicsData, err := createEconomicsData(enableEpochsConfig, gasPriceModifier) if err != nil { return nil, err } @@ -1148,6 +1149,7 @@ func CreatePreparedTxProcessorAndAccountsWithVMsWithRoundsConfig( guardedAccountHandler, roundNotifierInstance, chainHandler, + 1, ) if err != nil { return nil, err @@ -1181,36 +1183,48 @@ func createMockGasScheduleNotifierWithCustomGasSchedule(updateGasSchedule func(g } // CreatePreparedTxProcessorWithVMs - -func CreatePreparedTxProcessorWithVMs(enableEpochs config.EnableEpochs) (*VMTestContext, error) { - return CreatePreparedTxProcessorWithVMsAndCustomGasSchedule(enableEpochs, func(gasMap wasmConfig.GasScheduleMap) {}) +func CreatePreparedTxProcessorWithVMs(enableEpochs config.EnableEpochs, gasPriceModifier float64) (*VMTestContext, error) { + return CreatePreparedTxProcessorWithVMsAndCustomGasSchedule(enableEpochs, func(gasMap wasmConfig.GasScheduleMap) {}, gasPriceModifier) } // CreatePreparedTxProcessorWithVMsAndCustomGasSchedule - func CreatePreparedTxProcessorWithVMsAndCustomGasSchedule( enableEpochs config.EnableEpochs, - updateGasSchedule func(gasMap wasmConfig.GasScheduleMap)) (*VMTestContext, error) { + updateGasSchedule func(gasMap wasmConfig.GasScheduleMap), + gasPriceModifier float64) (*VMTestContext, error) { return CreatePreparedTxProcessorWithVMsWithShardCoordinatorDBAndGasAndRoundConfig( enableEpochs, mock.NewMultiShardsCoordinatorMock(2), integrationtests.CreateMemUnit(), createMockGasScheduleNotifierWithCustomGasSchedule(updateGasSchedule), testscommon.GetDefaultRoundsConfig(), + gasPriceModifier, ) } // CreatePreparedTxProcessorWithVMsWithShardCoordinator - -func CreatePreparedTxProcessorWithVMsWithShardCoordinator(enableEpochsConfig config.EnableEpochs, shardCoordinator sharding.Coordinator) (*VMTestContext, error) { - return CreatePreparedTxProcessorWithVMsWithShardCoordinatorAndRoundConfig(enableEpochsConfig, testscommon.GetDefaultRoundsConfig(), shardCoordinator) +func CreatePreparedTxProcessorWithVMsWithShardCoordinator( + enableEpochsConfig config.EnableEpochs, + shardCoordinator sharding.Coordinator, + gasPriceModifier float64, +) (*VMTestContext, error) { + return CreatePreparedTxProcessorWithVMsWithShardCoordinatorAndRoundConfig(enableEpochsConfig, testscommon.GetDefaultRoundsConfig(), shardCoordinator, gasPriceModifier) } // CreatePreparedTxProcessorWithVMsWithShardCoordinatorAndRoundConfig - -func CreatePreparedTxProcessorWithVMsWithShardCoordinatorAndRoundConfig(enableEpochsConfig config.EnableEpochs, roundsConfig config.RoundConfig, shardCoordinator sharding.Coordinator) (*VMTestContext, error) { +func CreatePreparedTxProcessorWithVMsWithShardCoordinatorAndRoundConfig( + enableEpochsConfig config.EnableEpochs, + roundsConfig config.RoundConfig, + shardCoordinator sharding.Coordinator, + gasPriceModifier float64, +) (*VMTestContext, error) { return CreatePreparedTxProcessorWithVMsWithShardCoordinatorDBAndGasAndRoundConfig( enableEpochsConfig, shardCoordinator, integrationtests.CreateMemUnit(), CreateMockGasScheduleNotifier(), roundsConfig, + gasPriceModifier, ) } @@ -1220,6 +1234,7 @@ func CreatePreparedTxProcessorWithVMsWithShardCoordinatorDBAndGas( shardCoordinator sharding.Coordinator, db storage.Storer, gasScheduleNotifier core.GasScheduleNotifier, + gasPriceModifier float64, ) (*VMTestContext, error) { vmConfig := createDefaultVMConfig() return CreatePreparedTxProcessorWithVMConfigWithShardCoordinatorDBAndGasAndRoundConfig( @@ -1229,6 +1244,7 @@ func CreatePreparedTxProcessorWithVMsWithShardCoordinatorDBAndGas( gasScheduleNotifier, testscommon.GetDefaultRoundsConfig(), vmConfig, + gasPriceModifier, ) } @@ -1239,6 +1255,7 @@ func CreatePreparedTxProcessorWithVMsWithShardCoordinatorDBAndGasAndRoundConfig( db storage.Storer, gasScheduleNotifier core.GasScheduleNotifier, roundsConfig config.RoundConfig, + gasPriceModifier float64, ) (*VMTestContext, error) { vmConfig := createDefaultVMConfig() return CreatePreparedTxProcessorWithVMConfigWithShardCoordinatorDBAndGasAndRoundConfig( @@ -1248,6 +1265,7 @@ func CreatePreparedTxProcessorWithVMsWithShardCoordinatorDBAndGasAndRoundConfig( gasScheduleNotifier, roundsConfig, vmConfig, + gasPriceModifier, ) } @@ -1259,6 +1277,7 @@ func CreatePreparedTxProcessorWithVMConfigWithShardCoordinatorDBAndGasAndRoundCo gasScheduleNotifier core.GasScheduleNotifier, roundsConfig config.RoundConfig, vmConfig *config.VirtualMachineConfig, + gasPriceModifier float64, ) (*VMTestContext, error) { feeAccumulator := postprocess.NewFeeAccumulator() epochNotifierInstance := forking.NewGenericEpochNotifier() @@ -1300,6 +1319,7 @@ func CreatePreparedTxProcessorWithVMConfigWithShardCoordinatorDBAndGasAndRoundCo guardedAccountHandler, roundNotifierInstance, chainHandler, + gasPriceModifier, ) if err != nil { return nil, err @@ -1396,6 +1416,7 @@ func CreateTxProcessorArwenVMWithGasScheduleAndRoundConfig( guardedAccountHandler, roundNotifierInstance, chainHandler, + 1, ) if err != nil { return nil, err @@ -1478,6 +1499,7 @@ func CreateTxProcessorArwenWithVMConfigAndRoundConfig( guardedAccountHandler, roundNotifierInstance, chainHandler, + 1, ) if err != nil { return nil, err @@ -1845,13 +1867,13 @@ func GetNodeIndex(nodeList []*integrationTests.TestProcessorNode, node *integrat } // CreatePreparedTxProcessorWithVMsMultiShard - -func CreatePreparedTxProcessorWithVMsMultiShard(selfShardID uint32, enableEpochsConfig config.EnableEpochs) (*VMTestContext, error) { - return CreatePreparedTxProcessorWithVMsMultiShardAndRoundConfig(selfShardID, enableEpochsConfig, testscommon.GetDefaultRoundsConfig()) +func CreatePreparedTxProcessorWithVMsMultiShard(selfShardID uint32, enableEpochsConfig config.EnableEpochs, gasPriceModifier float64) (*VMTestContext, error) { + return CreatePreparedTxProcessorWithVMsMultiShardAndRoundConfig(selfShardID, enableEpochsConfig, testscommon.GetDefaultRoundsConfig(), gasPriceModifier) } // CreatePreparedTxProcessorWithVMsMultiShardAndRoundConfig - -func CreatePreparedTxProcessorWithVMsMultiShardAndRoundConfig(selfShardID uint32, enableEpochsConfig config.EnableEpochs, roundsConfig config.RoundConfig) (*VMTestContext, error) { - return CreatePreparedTxProcessorWithVMsMultiShardRoundVMConfig(selfShardID, enableEpochsConfig, roundsConfig, createDefaultVMConfig()) +func CreatePreparedTxProcessorWithVMsMultiShardAndRoundConfig(selfShardID uint32, enableEpochsConfig config.EnableEpochs, roundsConfig config.RoundConfig, gasPriceModifier float64) (*VMTestContext, error) { + return CreatePreparedTxProcessorWithVMsMultiShardRoundVMConfig(selfShardID, enableEpochsConfig, roundsConfig, createDefaultVMConfig(), gasPriceModifier) } // CreatePreparedTxProcessorWithVMsMultiShardRoundVMConfig - @@ -1860,6 +1882,7 @@ func CreatePreparedTxProcessorWithVMsMultiShardRoundVMConfig( enableEpochsConfig config.EnableEpochs, roundsConfig config.RoundConfig, vmConfig *config.VirtualMachineConfig, + gasPriceModifier float64, ) (*VMTestContext, error) { shardCoordinator, _ := sharding.NewMultiShardCoordinator(3, selfShardID) @@ -1909,6 +1932,7 @@ func CreatePreparedTxProcessorWithVMsMultiShardRoundVMConfig( guardedAccountHandler, roundNotifierInstance, chainHandler, + gasPriceModifier, ) if err != nil { return nil, err diff --git a/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go b/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go index 56551737de5..8f3894aa319 100644 --- a/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go +++ b/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go @@ -30,7 +30,7 @@ func TestSCCallCostTransactionCost(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -55,7 +55,7 @@ func TestScDeployTransactionCost(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -75,7 +75,7 @@ func TestAsyncCallsTransactionCost(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -109,7 +109,7 @@ func TestBuiltInFunctionTransactionCost(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs( config.EnableEpochs{ PenalizedTooMuchGasEnableEpoch: integrationTests.UnreachableEpoch, - }) + }, 1) require.Nil(t, err) defer testContext.Close() @@ -132,7 +132,7 @@ func TestESDTTransfer(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -157,7 +157,7 @@ func TestAsyncESDTTransfer(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, - }) + }, 1) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/asyncCall_multi_test.go b/integrationTests/vm/txsFee/asyncCall_multi_test.go index 24cf1f14750..56a6dc02a26 100644 --- a/integrationTests/vm/txsFee/asyncCall_multi_test.go +++ b/integrationTests/vm/txsFee/asyncCall_multi_test.go @@ -24,7 +24,7 @@ func TestAsyncCallLegacy(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -71,7 +71,7 @@ func TestAsyncCallMulti(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -122,7 +122,7 @@ func TestAsyncCallTransferAndExecute(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -183,7 +183,7 @@ func TestAsyncCallTransferESDTAndExecute_Success(t *testing.T) { } func transferESDTAndExecute(t *testing.T, numberOfCallsFromParent int, numberOfBackTransfers int) { - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -297,15 +297,15 @@ func TestAsyncCallMulti_CrossShard(t *testing.T) { t.Skip("this is not a short test") } - testContextFirstContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) + testContextFirstContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}, 1) require.Nil(t, err) defer testContextFirstContract.Close() - testContextSecondContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) + testContextSecondContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}, 1) require.Nil(t, err) defer testContextSecondContract.Close() - testContextSender, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{}) + testContextSender, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{}, 1) require.Nil(t, err) defer testContextSender.Close() @@ -387,15 +387,15 @@ func TestAsyncCallTransferAndExecute_CrossShard(t *testing.T) { t.Skip("this is not a short test") } - childShard, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) + childShard, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}, 1) require.Nil(t, err) defer childShard.Close() - forwarderShard, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) + forwarderShard, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}, 1) require.Nil(t, err) defer forwarderShard.Close() - testContextSender, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{}) + testContextSender, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{}, 1) require.Nil(t, err) defer testContextSender.Close() @@ -479,15 +479,15 @@ func TestAsyncCallTransferESDTAndExecute_CrossShard_Success(t *testing.T) { } func transferESDTAndExecuteCrossShard(t *testing.T, numberOfCallsFromParent int, numberOfBackTransfers int) { - vaultShard, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) + vaultShard, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}, 1) require.Nil(t, err) defer vaultShard.Close() - forwarderShard, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) + forwarderShard, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}, 1) require.Nil(t, err) defer forwarderShard.Close() - testContextSender, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{}) + testContextSender, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{}, 1) require.Nil(t, err) defer testContextSender.Close() diff --git a/integrationTests/vm/txsFee/asyncCall_test.go b/integrationTests/vm/txsFee/asyncCall_test.go index 19a966e2fa8..88057f564a7 100644 --- a/integrationTests/vm/txsFee/asyncCall_test.go +++ b/integrationTests/vm/txsFee/asyncCall_test.go @@ -33,7 +33,7 @@ func TestAsyncCallShouldWork(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -94,7 +94,7 @@ func TestMinterContractWithAsyncCalls(t *testing.T) { gasMap[common.MaxPerTransaction]["MaxBuiltInCallsPerTx"] = 199 gasMap[common.MaxPerTransaction]["MaxNumberOfTransfersPerTx"] = 100000 gasMap[common.MaxPerTransaction]["MaxNumberOfTrieReadsPerTx"] = 100000 - }) + }, 1) require.Nil(t, err) defer testContext.Close() @@ -202,6 +202,7 @@ func testAsyncCallsOnInitFunctionOnUpgrade( gasScheduleNotifier, testscommon.GetDefaultRoundsConfig(), vm.CreateVMConfigWithVersion("v1.4"), + 1, ) require.Nil(t, err) testContextShardMeta, err := vm.CreatePreparedTxProcessorWithVMConfigWithShardCoordinatorDBAndGasAndRoundConfig( @@ -211,6 +212,7 @@ func testAsyncCallsOnInitFunctionOnUpgrade( gasScheduleNotifier, testscommon.GetDefaultRoundsConfig(), vm.CreateVMConfigWithVersion("v1.4"), + 1, ) require.Nil(t, err) @@ -340,6 +342,7 @@ func testAsyncCallsOnInitFunctionOnDeploy(t *testing.T, gasScheduleNotifier, testscommon.GetDefaultRoundsConfig(), vm.CreateVMConfigWithVersion("v1.4"), + 1, ) require.Nil(t, err) testContextShardMeta, err := vm.CreatePreparedTxProcessorWithVMConfigWithShardCoordinatorDBAndGasAndRoundConfig( @@ -349,6 +352,7 @@ func testAsyncCallsOnInitFunctionOnDeploy(t *testing.T, gasScheduleNotifier, testscommon.GetDefaultRoundsConfig(), vm.CreateVMConfigWithVersion("v1.4"), + 1, ) require.Nil(t, err) diff --git a/integrationTests/vm/txsFee/asyncESDT_test.go b/integrationTests/vm/txsFee/asyncESDT_test.go index 4476a79511d..c7c8d088fb9 100644 --- a/integrationTests/vm/txsFee/asyncESDT_test.go +++ b/integrationTests/vm/txsFee/asyncESDT_test.go @@ -27,7 +27,7 @@ func TestAsyncESDTCallShouldWork(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, - }) + }, 1) require.Nil(t, err) defer testContext.Close() @@ -83,7 +83,7 @@ func TestAsyncESDTCallSecondScRefusesPayment(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -140,7 +140,7 @@ func TestAsyncESDTCallsOutOfGas(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -198,7 +198,7 @@ func TestAsyncMultiTransferOnCallback(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, - }) + }, 1) require.Nil(t, err) defer testContext.Close() @@ -295,7 +295,7 @@ func TestAsyncMultiTransferOnCallAndOnCallback(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -399,7 +399,7 @@ func TestSendNFTToContractWith0Function(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -452,7 +452,7 @@ func TestSendNFTToContractWith0FunctionNonPayable(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -506,7 +506,7 @@ func TestAsyncESDTCallForThirdContractShouldWork(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/backwardsCompatibility_test.go b/integrationTests/vm/txsFee/backwardsCompatibility_test.go index 2b160d342cd..424594c6754 100644 --- a/integrationTests/vm/txsFee/backwardsCompatibility_test.go +++ b/integrationTests/vm/txsFee/backwardsCompatibility_test.go @@ -26,7 +26,7 @@ func TestMoveBalanceSelfShouldWorkAndConsumeTxFeeWhenAllFlagsAreDisabled(t *test SCDeployEnableEpoch: 100, MetaProtectionEnableEpoch: 100, RelayedTransactionsEnableEpoch: 100, - }) + }, 1) require.Nil(t, err) defer testContext.Close() @@ -71,7 +71,7 @@ func TestMoveBalanceAllFlagsDisabledLessBalanceThanGasLimitMulGasPrice(t *testin SCDeployEnableEpoch: integrationTests.UnreachableEpoch, MetaProtectionEnableEpoch: integrationTests.UnreachableEpoch, RelayedTransactionsEnableEpoch: integrationTests.UnreachableEpoch, - }) + }, 1) require.Nil(t, err) defer testContext.Close() @@ -99,7 +99,7 @@ func TestMoveBalanceSelfShouldWorkAndConsumeTxFeeWhenSomeFlagsAreDisabled(t *tes SCDeployEnableEpoch: 100, MetaProtectionEnableEpoch: 100, RelayedTransactionsV2EnableEpoch: 100, - }) + }, 1) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/builtInFunctions_test.go b/integrationTests/vm/txsFee/builtInFunctions_test.go index 4ac02c62661..0c7c1f7cdf3 100644 --- a/integrationTests/vm/txsFee/builtInFunctions_test.go +++ b/integrationTests/vm/txsFee/builtInFunctions_test.go @@ -32,11 +32,11 @@ func TestBuildInFunctionChangeOwnerCallShouldWorkV1(t *testing.T) { config.EnableEpochs{ PenalizedTooMuchGasEnableEpoch: integrationTests.UnreachableEpoch, SCProcessorV2EnableEpoch: integrationTests.UnreachableEpoch, - }) + }, 1) require.Nil(t, err) defer testContext.Close() - scAddress, owner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + scAddress, owner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm", 9988100, 11900, 399) testContext.TxFeeHandler.CreateBlockStarted(getZeroGasAndFees()) utils.CleanAccumulatedIntermediateTransactions(t, testContext) @@ -73,11 +73,11 @@ func TestBuildInFunctionChangeOwnerCallShouldWork(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs( config.EnableEpochs{ PenalizedTooMuchGasEnableEpoch: integrationTests.UnreachableEpoch, - }) + }, 1) require.Nil(t, err) defer testContext.Close() - scAddress, owner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + scAddress, owner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm", 9988100, 11900, 399) testContext.TxFeeHandler.CreateBlockStarted(getZeroGasAndFees()) utils.CleanAccumulatedIntermediateTransactions(t, testContext) @@ -111,11 +111,11 @@ func TestBuildInFunctionChangeOwnerCallWrongOwnerShouldConsumeGas(t *testing.T) t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() - scAddress, initialOwner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + scAddress, initialOwner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm", 9988100, 11900, 399) utils.CleanAccumulatedIntermediateTransactions(t, testContext) testContext.TxFeeHandler.CreateBlockStarted(getZeroGasAndFees()) @@ -152,11 +152,11 @@ func TestBuildInFunctionChangeOwnerInvalidAddressShouldConsumeGas(t *testing.T) t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() - scAddress, owner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + scAddress, owner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm", 9988100, 11900, 399) utils.CleanAccumulatedIntermediateTransactions(t, testContext) testContext.TxFeeHandler.CreateBlockStarted(getZeroGasAndFees()) @@ -190,11 +190,11 @@ func TestBuildInFunctionChangeOwnerCallInsufficientGasLimitShouldNotConsumeGas(t t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() - scAddress, owner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + scAddress, owner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm", 9988100, 11900, 399) testContext.TxFeeHandler.CreateBlockStarted(getZeroGasAndFees()) newOwner := []byte("12345678901234567890123456789112") @@ -230,11 +230,11 @@ func TestBuildInFunctionChangeOwnerOutOfGasShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() - scAddress, owner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + scAddress, owner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm", 9988100, 11900, 399) utils.CleanAccumulatedIntermediateTransactions(t, testContext) testContext.TxFeeHandler.CreateBlockStarted(getZeroGasAndFees()) @@ -275,7 +275,7 @@ func TestBuildInFunctionSaveKeyValue_WrongDestination(t *testing.T) { config.EnableEpochs{ CleanUpInformativeSCRsEnableEpoch: integrationTests.UnreachableEpoch, SCProcessorV2EnableEpoch: integrationTests.UnreachableEpoch, - }, shardCoord) + }, shardCoord, 1) require.Nil(t, err) defer testContext.Close() @@ -313,7 +313,7 @@ func TestBuildInFunctionSaveKeyValue_NotEnoughGasFor3rdSave(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMsWithShardCoordinator( config.EnableEpochs{ BackwardCompSaveKeyValueEnableEpoch: 5, - }, shardCoord) + }, shardCoord, 1) require.Nil(t, err) defer testContext.Close() @@ -356,6 +356,7 @@ func TestBuildInFunctionSaveKeyValue_NotEnoughGasForTheSameKeyValue(t *testing.T gasScheduleNotifier, testscommon.GetDefaultRoundsConfig(), vm.CreateVMConfigWithVersion("v1.5"), + 1, ) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/common.go b/integrationTests/vm/txsFee/common.go index 6feb164f322..774af8202d2 100644 --- a/integrationTests/vm/txsFee/common.go +++ b/integrationTests/vm/txsFee/common.go @@ -16,8 +16,9 @@ import ( ) const ( - gasPrice = uint64(10) - minGasLimit = uint64(1) + gasPrice = uint64(10) + minGasLimit = uint64(1) + gasPriceModifier = float64(0.1) ) // MetaData defines test meta data struct diff --git a/integrationTests/vm/txsFee/dns_test.go b/integrationTests/vm/txsFee/dns_test.go index 1b1b345ec05..c8787d99db5 100644 --- a/integrationTests/vm/txsFee/dns_test.go +++ b/integrationTests/vm/txsFee/dns_test.go @@ -31,7 +31,7 @@ func TestDeployDNSContract_TestRegisterAndResolveAndSendTxWithSndAndRcvUserName( testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ DynamicGasCostForDataTrieStorageLoadEnableEpoch: 10, - }) + }, 1) require.Nil(t, err) defer testContext.Close() @@ -131,6 +131,7 @@ func TestDeployDNSContract_TestGasWhenSaveUsernameFailsCrossShardBackwardsCompat enableEpochs, testscommon.GetDefaultRoundsConfig(), vmConfig, + 1, ) require.Nil(t, err) defer testContextForDNSContract.Close() @@ -140,6 +141,7 @@ func TestDeployDNSContract_TestGasWhenSaveUsernameFailsCrossShardBackwardsCompat enableEpochs, testscommon.GetDefaultRoundsConfig(), vmConfig, + 1, ) require.Nil(t, err) defer testContextForRelayerAndUser.Close() @@ -202,11 +204,11 @@ func TestDeployDNSContract_TestGasWhenSaveUsernameAfterDNSv2IsActivated(t *testi testContextForDNSContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ FixRelayedBaseCostEnableEpoch: integrationTests.UnreachableEpoch, - }) + }, 1) require.Nil(t, err) defer testContextForDNSContract.Close() - testContextForRelayerAndUser, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{}) + testContextForRelayerAndUser, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{}, 1) require.Nil(t, err) defer testContextForRelayerAndUser.Close() scAddress, _ := utils.DoDeployDNS(t, testContextForDNSContract, "../../multiShard/smartContract/dns/dns.wasm") diff --git a/integrationTests/vm/txsFee/dynamicGasCost_test.go b/integrationTests/vm/txsFee/dynamicGasCost_test.go index e1fca367f3f..08edae2af13 100644 --- a/integrationTests/vm/txsFee/dynamicGasCost_test.go +++ b/integrationTests/vm/txsFee/dynamicGasCost_test.go @@ -29,7 +29,7 @@ func TestDynamicGasCostForDataTrieStorageLoad(t *testing.T) { shardCoordinator, _ := sharding.NewMultiShardCoordinator(3, 1) gasScheduleNotifier := vm.CreateMockGasScheduleNotifier() - testContext, err := vm.CreatePreparedTxProcessorWithVMsWithShardCoordinatorDBAndGas(enableEpochs, shardCoordinator, integrationTests.CreateMemUnit(), gasScheduleNotifier) + testContext, err := vm.CreatePreparedTxProcessorWithVMsWithShardCoordinatorDBAndGas(enableEpochs, shardCoordinator, integrationTests.CreateMemUnit(), gasScheduleNotifier, 1) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/esdtLocalBurn_test.go b/integrationTests/vm/txsFee/esdtLocalBurn_test.go index 29c4fc26320..681c7e293b4 100644 --- a/integrationTests/vm/txsFee/esdtLocalBurn_test.go +++ b/integrationTests/vm/txsFee/esdtLocalBurn_test.go @@ -18,7 +18,7 @@ func TestESDTLocalBurnShouldWork(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -52,7 +52,7 @@ func TestESDTLocalBurnMoreThanTotalBalanceShouldErr(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -86,7 +86,7 @@ func TestESDTLocalBurnNotAllowedShouldErr(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/esdtLocalMint_test.go b/integrationTests/vm/txsFee/esdtLocalMint_test.go index f2104f4c341..516402c80a4 100644 --- a/integrationTests/vm/txsFee/esdtLocalMint_test.go +++ b/integrationTests/vm/txsFee/esdtLocalMint_test.go @@ -18,7 +18,7 @@ func TestESDTLocalMintShouldWork(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -52,7 +52,7 @@ func TestESDTLocalMintNotAllowedShouldErr(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go b/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go index d980ed816d7..9d6b7d7645b 100644 --- a/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go +++ b/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go @@ -32,7 +32,7 @@ func runEsdtMetaDataRecreateTest(t *testing.T, tokenType string) { baseEsdtKeyPrefix := core.ProtectedKeyPrefix + core.ESDTKeyIdentifier key := append([]byte(baseEsdtKeyPrefix), token...) - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go b/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go index ea5ec910c97..53174e22a35 100644 --- a/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go +++ b/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go @@ -32,7 +32,7 @@ func runEsdtMetaDataUpdateTest(t *testing.T, tokenType string) { baseEsdtKeyPrefix := core.ProtectedKeyPrefix + core.ESDTKeyIdentifier key := append([]byte(baseEsdtKeyPrefix), token...) - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/esdtModifyCreator_test.go b/integrationTests/vm/txsFee/esdtModifyCreator_test.go index 1aa80ffd5c3..ead51c5d61d 100644 --- a/integrationTests/vm/txsFee/esdtModifyCreator_test.go +++ b/integrationTests/vm/txsFee/esdtModifyCreator_test.go @@ -36,7 +36,7 @@ func runEsdtModifyCreatorTest(t *testing.T, tokenType string) { baseEsdtKeyPrefix := core.ProtectedKeyPrefix + core.ESDTKeyIdentifier key := append([]byte(baseEsdtKeyPrefix), token...) - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go b/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go index fd4b9c84880..f4ef7dc9f49 100644 --- a/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go +++ b/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go @@ -31,7 +31,7 @@ func runEsdtModifyRoyaltiesTest(t *testing.T, tokenType string) { baseEsdtKeyPrefix := core.ProtectedKeyPrefix + core.ESDTKeyIdentifier key := append([]byte(baseEsdtKeyPrefix), token...) - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/esdtSetNewURIs_test.go b/integrationTests/vm/txsFee/esdtSetNewURIs_test.go index 2354f4b9625..66ec209c3ef 100644 --- a/integrationTests/vm/txsFee/esdtSetNewURIs_test.go +++ b/integrationTests/vm/txsFee/esdtSetNewURIs_test.go @@ -32,7 +32,7 @@ func runEsdtSetNewURIsTest(t *testing.T, tokenType string) { baseEsdtKeyPrefix := core.ProtectedKeyPrefix + core.ESDTKeyIdentifier key := append([]byte(baseEsdtKeyPrefix), token...) - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/esdt_test.go b/integrationTests/vm/txsFee/esdt_test.go index 07871a87750..d51848762e8 100644 --- a/integrationTests/vm/txsFee/esdt_test.go +++ b/integrationTests/vm/txsFee/esdt_test.go @@ -22,7 +22,7 @@ func TestESDTTransferShouldWork(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -62,7 +62,7 @@ func TestESDTTransferShouldWorkToMuchGasShouldConsumeAllGas(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -102,7 +102,7 @@ func TestESDTTransferInvalidESDTValueShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -143,7 +143,7 @@ func TestESDTTransferCallBackOnErrorShouldNotGenerateSCRsFurther(t *testing.T) { } shardC, _ := sharding.NewMultiShardCoordinator(2, 0) - testContext, err := vm.CreatePreparedTxProcessorWithVMsWithShardCoordinator(config.EnableEpochs{}, shardC) + testContext, err := vm.CreatePreparedTxProcessorWithVMsWithShardCoordinator(config.EnableEpochs{}, shardC, 1) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/guardAccount_test.go b/integrationTests/vm/txsFee/guardAccount_test.go index c8e10d8c229..52a64322bb1 100644 --- a/integrationTests/vm/txsFee/guardAccount_test.go +++ b/integrationTests/vm/txsFee/guardAccount_test.go @@ -103,6 +103,7 @@ func prepareTestContextForGuardedAccounts(tb testing.TB) *vm.VMTestContext { db, gasScheduleNotifier, testscommon.GetDefaultRoundsConfig(), + 1, ) require.Nil(tb, err) diff --git a/integrationTests/vm/txsFee/migrateDataTrie_test.go b/integrationTests/vm/txsFee/migrateDataTrie_test.go index 02eecc0e1c3..d089be8fc14 100644 --- a/integrationTests/vm/txsFee/migrateDataTrie_test.go +++ b/integrationTests/vm/txsFee/migrateDataTrie_test.go @@ -45,7 +45,7 @@ func TestMigrateDataTrieBuiltInFunc(t *testing.T) { t.Run("deterministic trie", func(t *testing.T) { t.Parallel() - testContext, err := vm.CreatePreparedTxProcessorWithVMsWithShardCoordinatorDBAndGas(enableEpochs, shardCoordinator, integrationTests.CreateMemUnit(), gasScheduleNotifier) + testContext, err := vm.CreatePreparedTxProcessorWithVMsWithShardCoordinatorDBAndGas(enableEpochs, shardCoordinator, integrationTests.CreateMemUnit(), gasScheduleNotifier, 1) require.Nil(t, err) defer testContext.Close() @@ -123,7 +123,7 @@ func TestMigrateDataTrieBuiltInFunc(t *testing.T) { t.Run("random trie - all leaves are migrated in multiple transactions", func(t *testing.T) { t.Parallel() - testContext, err := vm.CreatePreparedTxProcessorWithVMsWithShardCoordinatorDBAndGas(enableEpochs, shardCoordinator, integrationTests.CreateMemUnit(), gasScheduleNotifier) + testContext, err := vm.CreatePreparedTxProcessorWithVMsWithShardCoordinatorDBAndGas(enableEpochs, shardCoordinator, integrationTests.CreateMemUnit(), gasScheduleNotifier, 1) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/moveBalance_test.go b/integrationTests/vm/txsFee/moveBalance_test.go index 28907f5a2c6..8e847dba20b 100644 --- a/integrationTests/vm/txsFee/moveBalance_test.go +++ b/integrationTests/vm/txsFee/moveBalance_test.go @@ -22,7 +22,7 @@ func TestMoveBalanceSelfShouldWorkAndConsumeTxFee(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -61,7 +61,7 @@ func TestMoveBalanceAllFlagsEnabledLessBalanceThanGasLimitMulGasPrice(t *testing t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -82,7 +82,7 @@ func TestMoveBalanceShouldWork(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -126,7 +126,7 @@ func TestMoveBalanceInvalidHasGasButNoValueShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -159,7 +159,7 @@ func TestMoveBalanceHigherNonceShouldNotConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -193,7 +193,7 @@ func TestMoveBalanceMoreGasThanGasLimitPerMiniBlockForSafeCrossShard(t *testing. t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -228,7 +228,7 @@ func TestMoveBalanceInvalidUserNames(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/multiESDTTransfer_test.go b/integrationTests/vm/txsFee/multiESDTTransfer_test.go index c85a1a2bc1b..adaf89ad340 100644 --- a/integrationTests/vm/txsFee/multiESDTTransfer_test.go +++ b/integrationTests/vm/txsFee/multiESDTTransfer_test.go @@ -19,7 +19,7 @@ func TestMultiESDTTransferShouldWork(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -80,7 +80,7 @@ func TestMultiESDTTransferFailsBecauseOfMaxLimit(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMsAndCustomGasSchedule(config.EnableEpochs{}, func(gasMap wasmConfig.GasScheduleMap) { gasMap[common.MaxPerTransaction]["MaxNumberOfTransfersPerTx"] = 1 - }) + }, 1) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/multiShard/asyncCallWithChangeOwner_test.go b/integrationTests/vm/txsFee/multiShard/asyncCallWithChangeOwner_test.go index 28130046e11..573370bab26 100644 --- a/integrationTests/vm/txsFee/multiShard/asyncCallWithChangeOwner_test.go +++ b/integrationTests/vm/txsFee/multiShard/asyncCallWithChangeOwner_test.go @@ -25,7 +25,7 @@ func TestDoChangeOwnerCrossShardFromAContract(t *testing.T) { ChangeOwnerAddressCrossShardThroughSCEnableEpoch: 0, } - testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, enableEpochs) + testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, enableEpochs, 1) require.Nil(t, err) defer testContextSource.Close() @@ -42,7 +42,7 @@ func TestDoChangeOwnerCrossShardFromAContract(t *testing.T) { require.Equal(t, uint32(0), testContextSource.ShardCoordinator.ComputeId(firstContract)) require.Equal(t, uint32(0), testContextSource.ShardCoordinator.ComputeId(firstOwner)) - testContextSecondContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, enableEpochs) + testContextSecondContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, enableEpochs, 1) require.Nil(t, err) defer testContextSecondContract.Close() diff --git a/integrationTests/vm/txsFee/multiShard/asyncCall_test.go b/integrationTests/vm/txsFee/multiShard/asyncCall_test.go index e6e7fe5ce6e..c02aed11578 100644 --- a/integrationTests/vm/txsFee/multiShard/asyncCall_test.go +++ b/integrationTests/vm/txsFee/multiShard/asyncCall_test.go @@ -23,15 +23,15 @@ func TestAsyncCallShouldWork(t *testing.T) { DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, } - testContextFirstContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, enableEpochs) + testContextFirstContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, enableEpochs, 1) require.Nil(t, err) defer testContextFirstContract.Close() - testContextSecondContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, enableEpochs) + testContextSecondContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, enableEpochs, 1) require.Nil(t, err) defer testContextSecondContract.Close() - testContextSender, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, enableEpochs) + testContextSender, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, enableEpochs, 1) require.Nil(t, err) defer testContextSender.Close() @@ -131,15 +131,15 @@ func TestAsyncCallDisabled(t *testing.T) { activationRound.Round = "0" roundsConfig.RoundActivations["DisableAsyncCallV1"] = activationRound - testContextFirstContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShardAndRoundConfig(0, enableEpochs, roundsConfig) + testContextFirstContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShardAndRoundConfig(0, enableEpochs, roundsConfig, 1) require.Nil(t, err) defer testContextFirstContract.Close() - testContextSecondContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShardAndRoundConfig(1, enableEpochs, roundsConfig) + testContextSecondContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShardAndRoundConfig(1, enableEpochs, roundsConfig, 1) require.Nil(t, err) defer testContextSecondContract.Close() - testContextSender, err := vm.CreatePreparedTxProcessorWithVMsMultiShardAndRoundConfig(2, enableEpochs, roundsConfig) + testContextSender, err := vm.CreatePreparedTxProcessorWithVMsMultiShardAndRoundConfig(2, enableEpochs, roundsConfig, 1) require.Nil(t, err) defer testContextSender.Close() diff --git a/integrationTests/vm/txsFee/multiShard/asyncESDT_test.go b/integrationTests/vm/txsFee/multiShard/asyncESDT_test.go index 21a894662a7..aa37bc6bf94 100644 --- a/integrationTests/vm/txsFee/multiShard/asyncESDT_test.go +++ b/integrationTests/vm/txsFee/multiShard/asyncESDT_test.go @@ -22,15 +22,15 @@ func TestAsyncESDTTransferWithSCCallShouldWork(t *testing.T) { DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, } - testContextSender, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, enableEpochs) + testContextSender, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, enableEpochs, 1) require.Nil(t, err) defer testContextSender.Close() - testContextFirstContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, enableEpochs) + testContextFirstContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, enableEpochs, 1) require.Nil(t, err) defer testContextFirstContract.Close() - testContextSecondContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, enableEpochs) + testContextSecondContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, enableEpochs, 1) require.Nil(t, err) defer testContextSecondContract.Close() @@ -138,15 +138,15 @@ func TestAsyncESDTTransferWithSCCallSecondContractAnotherToken(t *testing.T) { DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, } - testContextSender, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, enableEpochs) + testContextSender, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, enableEpochs, 1) require.Nil(t, err) defer testContextSender.Close() - testContextFirstContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, enableEpochs) + testContextFirstContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, enableEpochs, 1) require.Nil(t, err) defer testContextFirstContract.Close() - testContextSecondContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, enableEpochs) + testContextSecondContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, enableEpochs, 1) require.Nil(t, err) defer testContextSecondContract.Close() diff --git a/integrationTests/vm/txsFee/multiShard/builtInFunctions_test.go b/integrationTests/vm/txsFee/multiShard/builtInFunctions_test.go index fd0232072c2..b8aff559fbc 100644 --- a/integrationTests/vm/txsFee/multiShard/builtInFunctions_test.go +++ b/integrationTests/vm/txsFee/multiShard/builtInFunctions_test.go @@ -41,7 +41,8 @@ func TestBuiltInFunctionExecuteOnSourceAndDestinationShouldWork(t *testing.T) { config.EnableEpochs{ PenalizedTooMuchGasEnableEpoch: integrationTests.UnreachableEpoch, DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, - }) + }, + 1) require.Nil(t, err) defer testContextSource.Close() @@ -50,7 +51,8 @@ func TestBuiltInFunctionExecuteOnSourceAndDestinationShouldWork(t *testing.T) { config.EnableEpochs{ PenalizedTooMuchGasEnableEpoch: integrationTests.UnreachableEpoch, DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, - }) + }, + 1) require.Nil(t, err) defer testContextDst.Close() diff --git a/integrationTests/vm/txsFee/multiShard/esdtLiquidity_test.go b/integrationTests/vm/txsFee/multiShard/esdtLiquidity_test.go index 036c17d9cef..6d2fe8cfa00 100644 --- a/integrationTests/vm/txsFee/multiShard/esdtLiquidity_test.go +++ b/integrationTests/vm/txsFee/multiShard/esdtLiquidity_test.go @@ -25,11 +25,11 @@ func TestSystemAccountLiquidityAfterCrossShardTransferAndBurn(t *testing.T) { tokenID := []byte("MYNFT") sh0Addr := []byte("12345678901234567890123456789010") sh1Addr := []byte("12345678901234567890123456789011") - sh0Context, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) + sh0Context, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}, 1) require.Nil(t, err) defer sh0Context.Close() - sh1Context, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) + sh1Context, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}, 1) require.Nil(t, err) defer sh1Context.Close() _, _ = vm.CreateAccount(sh1Context.Accounts, sh1Addr, 0, big.NewInt(1000000000)) @@ -77,11 +77,11 @@ func TestSystemAccountLiquidityAfterNFTWipe(t *testing.T) { tokenID := []byte("MYNFT-0a0a0a") sh0Addr := bytes.Repeat([]byte{1}, 31) sh0Addr = append(sh0Addr, 0) - sh0Context, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) + sh0Context, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}, 1) require.Nil(t, err) defer sh0Context.Close() - metaContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(core.MetachainShardId, config.EnableEpochs{}) + metaContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(core.MetachainShardId, config.EnableEpochs{}, 1) require.Nil(t, err) defer metaContext.Close() @@ -127,11 +127,11 @@ func TestSystemAccountLiquidityAfterSFTWipe(t *testing.T) { tokenID := []byte("MYSFT-0a0a0a") sh0Addr := bytes.Repeat([]byte{1}, 31) sh0Addr = append(sh0Addr, 0) - sh0Context, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) + sh0Context, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}, 1) require.Nil(t, err) defer sh0Context.Close() - metaContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(core.MetachainShardId, config.EnableEpochs{}) + metaContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(core.MetachainShardId, config.EnableEpochs{}, 1) require.Nil(t, err) defer metaContext.Close() diff --git a/integrationTests/vm/txsFee/multiShard/esdt_test.go b/integrationTests/vm/txsFee/multiShard/esdt_test.go index 8f978daee1c..9dd828eb8c1 100644 --- a/integrationTests/vm/txsFee/multiShard/esdt_test.go +++ b/integrationTests/vm/txsFee/multiShard/esdt_test.go @@ -20,7 +20,7 @@ func TestESDTTransferShouldWork(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -61,11 +61,11 @@ func TestMultiESDTNFTTransferViaRelayedV2(t *testing.T) { relayerSh0 := []byte("12345678901234567890123456789110") relayerSh1 := []byte("12345678901234567890123456789111") - sh0Context, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) + sh0Context, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}, 1) require.Nil(t, err) defer sh0Context.Close() - sh1Context, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) + sh1Context, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}, 1) require.Nil(t, err) defer sh1Context.Close() _, _ = vm.CreateAccount(sh1Context.Accounts, sh1Addr, 0, big.NewInt(10000000000)) diff --git a/integrationTests/vm/txsFee/multiShard/moveBalance_test.go b/integrationTests/vm/txsFee/multiShard/moveBalance_test.go index 8c5f6bd6015..dcf42bce5b9 100644 --- a/integrationTests/vm/txsFee/multiShard/moveBalance_test.go +++ b/integrationTests/vm/txsFee/multiShard/moveBalance_test.go @@ -18,7 +18,7 @@ func TestMoveBalanceShouldWork(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -57,7 +57,7 @@ func TestMoveBalanceContractAddressDataFieldNilShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -99,7 +99,7 @@ func TestMoveBalanceContractAddressDataFieldNotNilShouldConsumeGas(t *testing.T) t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -141,11 +141,11 @@ func TestMoveBalanceExecuteOneSourceAndDestinationShard(t *testing.T) { t.Skip("this is not a short test") } - testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) + testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}, 1) require.Nil(t, err) defer testContextSource.Close() - testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) + testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}, 1) require.Nil(t, err) defer testContextDst.Close() diff --git a/integrationTests/vm/txsFee/multiShard/nftTransferUpdate_test.go b/integrationTests/vm/txsFee/multiShard/nftTransferUpdate_test.go index 1fdd2f6f78f..4a15002f5c0 100644 --- a/integrationTests/vm/txsFee/multiShard/nftTransferUpdate_test.go +++ b/integrationTests/vm/txsFee/multiShard/nftTransferUpdate_test.go @@ -40,11 +40,11 @@ func TestNFTTransferAndUpdateOnOldTypeToken(t *testing.T) { initialAttribute := []byte("initial attribute") newAttribute := []byte("new attribute") - sh0Context, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, enableEpochs) + sh0Context, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, enableEpochs, 1) require.Nil(t, err) defer sh0Context.Close() - sh1Context, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, enableEpochs) + sh1Context, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, enableEpochs, 1) require.Nil(t, err) defer sh1Context.Close() diff --git a/integrationTests/vm/txsFee/multiShard/relayedBuiltInFunctions_test.go b/integrationTests/vm/txsFee/multiShard/relayedBuiltInFunctions_test.go index e987d4dbc74..49a0e256483 100644 --- a/integrationTests/vm/txsFee/multiShard/relayedBuiltInFunctions_test.go +++ b/integrationTests/vm/txsFee/multiShard/relayedBuiltInFunctions_test.go @@ -23,7 +23,8 @@ func TestRelayedBuiltInFunctionExecuteOnRelayerAndDstShardShouldWork(t *testing. 2, config.EnableEpochs{ PenalizedTooMuchGasEnableEpoch: integrationTests.UnreachableEpoch, - }) + }, + 1) require.Nil(t, err) defer testContextRelayer.Close() @@ -31,7 +32,8 @@ func TestRelayedBuiltInFunctionExecuteOnRelayerAndDstShardShouldWork(t *testing. 1, config.EnableEpochs{ PenalizedTooMuchGasEnableEpoch: integrationTests.UnreachableEpoch, - }) + }, + 1) require.Nil(t, err) defer testContextInner.Close() diff --git a/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go b/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go index b8cbfeae1da..2d2013fd0e8 100644 --- a/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go +++ b/integrationTests/vm/txsFee/multiShard/relayedMoveBalance_test.go @@ -13,7 +13,10 @@ import ( "github.com/stretchr/testify/require" ) -const minGasLimit = uint64(1) +const ( + minGasLimit = uint64(1) + gasPriceModifier = float64(0.1) +) func TestRelayedMoveBalanceRelayerShard0InnerTxSenderAndReceiverShard1ShouldWork(t *testing.T) { if testing.Short() { @@ -27,7 +30,7 @@ func testRelayedMoveBalanceRelayerShard0InnerTxSenderAndReceiverShard1ShouldWork return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, - }) + }, gasPriceModifier) require.Nil(t, err) defer testContext.Close() @@ -70,7 +73,7 @@ func testRelayedMoveBalanceRelayerShard0InnerTxSenderAndReceiverShard1ShouldWork // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(1000), accumulatedFees) + require.Equal(t, big.NewInt(100), accumulatedFees) } } @@ -86,7 +89,7 @@ func testRelayedMoveBalanceRelayerAndInnerTxSenderShard0ReceiverShard1(relayedFi return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, - }) + }, gasPriceModifier) require.Nil(t, err) defer testContext.Close() @@ -127,7 +130,7 @@ func testRelayedMoveBalanceRelayerAndInnerTxSenderShard0ReceiverShard1(relayedFi // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(1000), accumulatedFees) + require.Equal(t, big.NewInt(100), accumulatedFees) } } @@ -143,13 +146,13 @@ func testRelayedMoveBalanceExecuteOnSourceAndDestination(relayedFixActivationEpo return func(t *testing.T) { testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{ FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, - }) + }, gasPriceModifier) require.Nil(t, err) defer testContextSource.Close() testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, - }) + }, gasPriceModifier) require.Nil(t, err) defer testContextDst.Close() @@ -185,8 +188,8 @@ func testRelayedMoveBalanceExecuteOnSourceAndDestination(relayedFixActivationEpo require.Nil(t, err) // check relayed balance - // 100000 - rTxFee(163)*gasPrice(10) - txFeeInner(1000) = 97370 - utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, big.NewInt(97370)) + // 100000 - rTxFee(163)*gasPrice(10) - txFeeInner(1000*gasPriceModifier(0.1)) = 98270 + utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, big.NewInt(98270)) // check accumulated fees accumulatedFees := testContextSource.TxFeeHandler.GetAccumulatedFees() @@ -207,7 +210,7 @@ func testRelayedMoveBalanceExecuteOnSourceAndDestination(relayedFixActivationEpo // check accumulated fees accumulatedFees = testContextDst.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(1000), accumulatedFees) + require.Equal(t, big.NewInt(100), accumulatedFees) } } @@ -224,13 +227,13 @@ func testRelayedMoveBalanceExecuteOnSourceAndDestinationRelayerAndInnerTxSenderS return func(t *testing.T) { testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{ FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, - }) + }, gasPriceModifier) require.Nil(t, err) defer testContextSource.Close() testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, - }) + }, gasPriceModifier) require.Nil(t, err) defer testContextDst.Close() @@ -264,10 +267,10 @@ func testRelayedMoveBalanceExecuteOnSourceAndDestinationRelayerAndInnerTxSenderS require.Nil(t, err) // check relayed balance - // before base cost fix: 100000 - rTxFee(163)*gasPrice(10) - innerTxFee(1000) = 97370 + // before base cost fix: 100000 - rTxFee(163)*gasPrice(10) - innerTxFee(1000*gasPriceModifier(0.1)) = 98270 // after base cost fix: 100000 - rTxFee(163)*gasPrice(10) - innerTxFee(10) = 98360 - expectedRelayerBalance := big.NewInt(97370) - expectedAccumulatedFees := big.NewInt(2630) + expectedRelayerBalance := big.NewInt(98270) + expectedAccumulatedFees := big.NewInt(1730) if relayedFixActivationEpoch != integrationTests.UnreachableEpoch { expectedRelayerBalance = big.NewInt(98360) expectedAccumulatedFees = big.NewInt(1640) @@ -307,13 +310,13 @@ func testRelayedMoveBalanceRelayerAndInnerTxReceiverShard0SenderShard1(relayedFi return func(t *testing.T) { testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{ FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, - }) + }, gasPriceModifier) require.Nil(t, err) defer testContextSource.Close() testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, - }) + }, gasPriceModifier) require.Nil(t, err) defer testContextDst.Close() @@ -347,8 +350,8 @@ func testRelayedMoveBalanceRelayerAndInnerTxReceiverShard0SenderShard1(relayedFi require.Nil(t, err) // check relayed balance - // 100000 - rTxFee(163)*gasPrice(10) - innerTxFee(1000) = 97370 - utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, big.NewInt(97370)) + // 100000 - rTxFee(163)*gasPrice(10) - innerTxFee(1000*gasPriceModifier(0.1)) = 98270 + utils.TestAccount(t, testContextSource.Accounts, relayerAddr, 1, big.NewInt(98270)) // check inner Tx receiver innerTxSenderAccount, err := testContextSource.Accounts.GetExistingAccount(sndAddr) @@ -369,7 +372,7 @@ func testRelayedMoveBalanceRelayerAndInnerTxReceiverShard0SenderShard1(relayedFi // check accumulated fees accumulatedFees = testContextDst.TxFeeHandler.GetAccumulatedFees() - expectedAccFees = big.NewInt(1000) + expectedAccFees = big.NewInt(100) require.Equal(t, expectedAccFees, accumulatedFees) txs := testContextDst.GetIntermediateTransactions(t) @@ -395,19 +398,19 @@ func testMoveBalanceRelayerShard0InnerTxSenderShard1InnerTxReceiverShard2ShouldW return func(t *testing.T) { testContextRelayer, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{ FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, - }) + }, gasPriceModifier) require.Nil(t, err) defer testContextRelayer.Close() testContextInnerSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, - }) + }, gasPriceModifier) require.Nil(t, err) defer testContextInnerSource.Close() testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{ FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, - }) + }, gasPriceModifier) require.Nil(t, err) defer testContextDst.Close() @@ -441,8 +444,8 @@ func testMoveBalanceRelayerShard0InnerTxSenderShard1InnerTxReceiverShard2ShouldW require.Nil(t, err) // check relayed balance - // 100000 - rTxFee(164)*gasPrice(10) - innerTxFee(1000) = 97370 - utils.TestAccount(t, testContextRelayer.Accounts, relayerAddr, 1, big.NewInt(97370)) + // 100000 - rTxFee(164)*gasPrice(10) - innerTxFee(1000*gasPriceModifier(0.1)) = 98270 + utils.TestAccount(t, testContextRelayer.Accounts, relayerAddr, 1, big.NewInt(98270)) // check inner Tx receiver innerTxSenderAccount, err := testContextRelayer.Accounts.GetExistingAccount(sndAddr) @@ -463,7 +466,7 @@ func testMoveBalanceRelayerShard0InnerTxSenderShard1InnerTxReceiverShard2ShouldW // check accumulated fees accumulatedFees = testContextInnerSource.TxFeeHandler.GetAccumulatedFees() - expectedAccFees = big.NewInt(1000) + expectedAccFees = big.NewInt(100) require.Equal(t, expectedAccFees, accumulatedFees) // execute on inner tx receiver shard diff --git a/integrationTests/vm/txsFee/multiShard/relayedScDeploy_test.go b/integrationTests/vm/txsFee/multiShard/relayedScDeploy_test.go index 7700c55b0f4..de22bb57d60 100644 --- a/integrationTests/vm/txsFee/multiShard/relayedScDeploy_test.go +++ b/integrationTests/vm/txsFee/multiShard/relayedScDeploy_test.go @@ -18,11 +18,11 @@ func TestRelayedSCDeployShouldWork(t *testing.T) { t.Skip("this is not a short test") } - testContextRelayer, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{}) + testContextRelayer, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{}, 1) require.Nil(t, err) defer testContextRelayer.Close() - testContextInner, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) + testContextInner, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}, 1) require.Nil(t, err) defer testContextInner.Close() diff --git a/integrationTests/vm/txsFee/multiShard/relayedTxScCalls_test.go b/integrationTests/vm/txsFee/multiShard/relayedTxScCalls_test.go index bbab4208aa2..736783b11ae 100644 --- a/integrationTests/vm/txsFee/multiShard/relayedTxScCalls_test.go +++ b/integrationTests/vm/txsFee/multiShard/relayedTxScCalls_test.go @@ -31,15 +31,15 @@ func TestRelayedTxScCallMultiShardShouldWork(t *testing.T) { DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, } - testContextRelayer, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, enableEpochs) + testContextRelayer, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, enableEpochs, 1) require.Nil(t, err) defer testContextRelayer.Close() - testContextInnerSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, enableEpochs) + testContextInnerSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, enableEpochs, 1) require.Nil(t, err) defer testContextInnerSource.Close() - testContextInnerDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, enableEpochs) + testContextInnerDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, enableEpochs, 1) require.Nil(t, err) defer testContextInnerDst.Close() @@ -140,15 +140,15 @@ func TestRelayedTxScCallMultiShardFailOnInnerTxDst(t *testing.T) { t.Skip("this is not a short test") } - testContextRelayer, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{}) + testContextRelayer, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{}, 1) require.Nil(t, err) defer testContextRelayer.Close() - testContextInnerSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) + testContextInnerSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}, 1) require.Nil(t, err) defer testContextInnerSource.Close() - testContextInnerDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) + testContextInnerDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}, 1) require.Nil(t, err) defer testContextInnerDst.Close() diff --git a/integrationTests/vm/txsFee/multiShard/scCallWithValueTransfer_test.go b/integrationTests/vm/txsFee/multiShard/scCallWithValueTransfer_test.go index 8f66a649a3b..c2a7356d1f3 100644 --- a/integrationTests/vm/txsFee/multiShard/scCallWithValueTransfer_test.go +++ b/integrationTests/vm/txsFee/multiShard/scCallWithValueTransfer_test.go @@ -30,14 +30,14 @@ func TestDeployContractAndTransferValueSCProcessorV2(t *testing.T) { } func testDeployContractAndTransferValue(t *testing.T, scProcessorV2EnabledEpoch uint32) { - testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) + testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}, 1) require.Nil(t, err) defer testContextSource.Close() configEnabledEpochs := config.EnableEpochs{} configEnabledEpochs.SCProcessorV2EnableEpoch = scProcessorV2EnabledEpoch - testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, configEnabledEpochs) + testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, configEnabledEpochs, 1) require.Nil(t, err) defer testContextDst.Close() diff --git a/integrationTests/vm/txsFee/multiShard/scCalls_test.go b/integrationTests/vm/txsFee/multiShard/scCalls_test.go index 34aa049c7c4..9eb2d85fbe0 100644 --- a/integrationTests/vm/txsFee/multiShard/scCalls_test.go +++ b/integrationTests/vm/txsFee/multiShard/scCalls_test.go @@ -18,11 +18,11 @@ func TestScCallExecuteOnSourceAndDstShardShouldWork(t *testing.T) { enableEpochs := config.EnableEpochs{} - testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, enableEpochs) + testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, enableEpochs, 1) require.Nil(t, err) defer testContextSource.Close() - testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, enableEpochs) + testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, enableEpochs, 1) require.Nil(t, err) defer testContextDst.Close() @@ -98,11 +98,11 @@ func TestScCallExecuteOnSourceAndDstShardInvalidOnDst(t *testing.T) { t.Skip("this is not a short test") } - testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) + testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}, 1) require.Nil(t, err) defer testContextSource.Close() - testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) + testContextDst, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}, 1) require.Nil(t, err) defer testContextDst.Close() diff --git a/integrationTests/vm/txsFee/relayedAsyncCall_test.go b/integrationTests/vm/txsFee/relayedAsyncCall_test.go index d98a440b648..9b4e243ec6a 100644 --- a/integrationTests/vm/txsFee/relayedAsyncCall_test.go +++ b/integrationTests/vm/txsFee/relayedAsyncCall_test.go @@ -42,7 +42,7 @@ func TestRelayedAsyncCallShouldWork(t *testing.T) { } func testRelayedAsyncCallShouldWork(t *testing.T, enableEpochs config.EnableEpochs, senderAddr []byte) *vm.VMTestContext { - testContext, err := vm.CreatePreparedTxProcessorWithVMs(enableEpochs) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(enableEpochs, 1) require.Nil(t, err) localEgldBalance := big.NewInt(100000000) diff --git a/integrationTests/vm/txsFee/relayedAsyncESDT_test.go b/integrationTests/vm/txsFee/relayedAsyncESDT_test.go index 204f8e4b885..bb8b05606a7 100644 --- a/integrationTests/vm/txsFee/relayedAsyncESDT_test.go +++ b/integrationTests/vm/txsFee/relayedAsyncESDT_test.go @@ -20,7 +20,7 @@ func TestRelayedAsyncESDTCallShouldWork(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, - }) + }, 1) require.Nil(t, err) defer testContext.Close() @@ -82,7 +82,7 @@ func TestRelayedAsyncESDTCall_InvalidCallFirstContract(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -144,7 +144,7 @@ func TestRelayedAsyncESDTCall_InvalidOutOfGas(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/relayedBuiltInFunctions_test.go b/integrationTests/vm/txsFee/relayedBuiltInFunctions_test.go index d9b71e9cc1d..7688f147729 100644 --- a/integrationTests/vm/txsFee/relayedBuiltInFunctions_test.go +++ b/integrationTests/vm/txsFee/relayedBuiltInFunctions_test.go @@ -20,21 +20,25 @@ func TestRelayedBuildInFunctionChangeOwnerCallShouldWork(t *testing.T) { t.Skip("this is not a short test") } - t.Run("before relayed move balance fix", testRelayedBuildInFunctionChangeOwnerCallShouldWork(integrationTests.UnreachableEpoch)) - t.Run("after relayed move balance fix", testRelayedBuildInFunctionChangeOwnerCallShouldWork(0)) + t.Run("before relayed base cost fix", testRelayedBuildInFunctionChangeOwnerCallShouldWork(integrationTests.UnreachableEpoch, big.NewInt(25610), big.NewInt(4390))) + t.Run("after relayed base cost fix", testRelayedBuildInFunctionChangeOwnerCallShouldWork(0, big.NewInt(24854), big.NewInt(5146))) } -func testRelayedBuildInFunctionChangeOwnerCallShouldWork(relayedFixActivationEpoch uint32) func(t *testing.T) { +func testRelayedBuildInFunctionChangeOwnerCallShouldWork( + relayedFixActivationEpoch uint32, + expectedBalanceRelayer *big.Int, + expectedAccumulatedFees *big.Int, +) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs( config.EnableEpochs{ PenalizedTooMuchGasEnableEpoch: integrationTests.UnreachableEpoch, FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, - }) + }, gasPriceModifier) require.Nil(t, err) defer testContext.Close() - scAddress, owner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + scAddress, owner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm", 9991691, 8309, 39) testContext.TxFeeHandler.CreateBlockStarted(getZeroGasAndFees()) utils.CleanAccumulatedIntermediateTransactions(t, testContext) @@ -60,18 +64,17 @@ func testRelayedBuildInFunctionChangeOwnerCallShouldWork(relayedFixActivationEpo utils.CheckOwnerAddr(t, testContext, scAddress, newOwner) - expectedBalanceRelayer := big.NewInt(16610) vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) - expectedBalance := big.NewInt(9988100) + expectedBalance := big.NewInt(9991691) vm.TestAccount(t, testContext.Accounts, owner, 2, expectedBalance) // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(13390), accumulatedFees) + require.Equal(t, expectedAccumulatedFees, accumulatedFees) developerFees := testContext.TxFeeHandler.GetDeveloperFees() - require.Equal(t, big.NewInt(915), developerFees) + require.Equal(t, big.NewInt(91), developerFees) } } @@ -80,19 +83,23 @@ func TestRelayedBuildInFunctionChangeOwnerCallWrongOwnerShouldConsumeGas(t *test t.Skip("this is not a short test") } - t.Run("before relayed move balance fix", testRelayedBuildInFunctionChangeOwnerCallWrongOwnerShouldConsumeGas(integrationTests.UnreachableEpoch)) - t.Run("after relayed move balance fix", testRelayedBuildInFunctionChangeOwnerCallWrongOwnerShouldConsumeGas(0)) + t.Run("before relayed base cost fix", testRelayedBuildInFunctionChangeOwnerCallWrongOwnerShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(25610), big.NewInt(4390))) + t.Run("after relayed base cost fix", testRelayedBuildInFunctionChangeOwnerCallWrongOwnerShouldConsumeGas(0, big.NewInt(25610), big.NewInt(4390))) } -func testRelayedBuildInFunctionChangeOwnerCallWrongOwnerShouldConsumeGas(relayedFixActivationEpoch uint32) func(t *testing.T) { +func testRelayedBuildInFunctionChangeOwnerCallWrongOwnerShouldConsumeGas( + relayedFixActivationEpoch uint32, + expectedBalanceRelayer *big.Int, + expectedAccumulatedFees *big.Int, +) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, - }) + }, gasPriceModifier) require.Nil(t, err) defer testContext.Close() - scAddress, owner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + scAddress, owner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm", 9991691, 8309, 39) testContext.TxFeeHandler.CreateBlockStarted(getZeroGasAndFees()) utils.CleanAccumulatedIntermediateTransactions(t, testContext) @@ -119,15 +126,14 @@ func testRelayedBuildInFunctionChangeOwnerCallWrongOwnerShouldConsumeGas(relayed utils.CheckOwnerAddr(t, testContext, scAddress, owner) - expectedBalanceRelayer := big.NewInt(16610) vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) - expectedBalance := big.NewInt(9988100) + expectedBalance := big.NewInt(9991691) vm.TestAccount(t, testContext.Accounts, owner, 1, expectedBalance) // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(13390), accumulatedFees) + require.Equal(t, expectedAccumulatedFees, accumulatedFees) developerFees := testContext.TxFeeHandler.GetDeveloperFees() require.Equal(t, big.NewInt(0), developerFees) @@ -139,11 +145,11 @@ func TestRelayedBuildInFunctionChangeOwnerInvalidAddressShouldConsumeGas(t *test t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() - scAddress, owner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + scAddress, owner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm", 9988100, 11900, 399) testContext.TxFeeHandler.CreateBlockStarted(getZeroGasAndFees()) utils.CleanAccumulatedIntermediateTransactions(t, testContext) @@ -207,11 +213,11 @@ func testRelayedBuildInFunctionChangeOwnerCallInsufficientGasLimitShouldConsumeG t *testing.T, enableEpochs config.EnableEpochs, ) { - testContext, err := vm.CreatePreparedTxProcessorWithVMs(enableEpochs) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(enableEpochs, 1) require.Nil(t, err) defer testContext.Close() - scAddress, owner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + scAddress, owner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm", 9988100, 11900, 399) testContext.TxFeeHandler.CreateBlockStarted(getZeroGasAndFees()) utils.CleanAccumulatedIntermediateTransactions(t, testContext) @@ -255,11 +261,11 @@ func TestRelayedBuildInFunctionChangeOwnerCallOutOfGasShouldConsumeGas(t *testin t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() - scAddress, owner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + scAddress, owner := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm", 9988100, 11900, 399) testContext.TxFeeHandler.CreateBlockStarted(getZeroGasAndFees()) utils.CleanAccumulatedIntermediateTransactions(t, testContext) diff --git a/integrationTests/vm/txsFee/relayedDns_test.go b/integrationTests/vm/txsFee/relayedDns_test.go index 54c70be0ee8..389941886e7 100644 --- a/integrationTests/vm/txsFee/relayedDns_test.go +++ b/integrationTests/vm/txsFee/relayedDns_test.go @@ -18,7 +18,7 @@ func TestRelayedTxDnsTransaction_ShouldWork(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/relayedESDT_test.go b/integrationTests/vm/txsFee/relayedESDT_test.go index 04571b8fb23..55a7e1bde04 100644 --- a/integrationTests/vm/txsFee/relayedESDT_test.go +++ b/integrationTests/vm/txsFee/relayedESDT_test.go @@ -17,15 +17,19 @@ func TestRelayedESDTTransferShouldWork(t *testing.T) { t.Skip("this is not a short test") } - t.Run("before relayed move balance fix", testRelayedESDTTransferShouldWork(integrationTests.UnreachableEpoch)) - t.Run("after relayed move balance fix", testRelayedESDTTransferShouldWork(0)) + t.Run("before relayed base cost fix", testRelayedESDTTransferShouldWork(integrationTests.UnreachableEpoch, big.NewInt(9997614), big.NewInt(2386))) + t.Run("after relayed base cost fix", testRelayedESDTTransferShouldWork(0, big.NewInt(9997299), big.NewInt(2701))) } -func testRelayedESDTTransferShouldWork(relayedFixActivationEpoch uint32) func(t *testing.T) { +func testRelayedESDTTransferShouldWork( + relayedFixActivationEpoch uint32, + expectedRelayerBalance *big.Int, + expectedAccFees *big.Int, +) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, - }) + }, gasPriceModifier) require.Nil(t, err) defer testContext.Close() @@ -62,11 +66,11 @@ func testRelayedESDTTransferShouldWork(relayedFixActivationEpoch uint32) func(t expectedEGLDBalance := big.NewInt(0) utils.TestAccount(t, testContext.Accounts, sndAddr, 1, expectedEGLDBalance) - utils.TestAccount(t, testContext.Accounts, relayerAddr, 1, big.NewInt(9997290)) + utils.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedRelayerBalance) // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(2710), accumulatedFees) + require.Equal(t, expectedAccFees, accumulatedFees) } } @@ -75,15 +79,19 @@ func TestRelayedESTTransferNotEnoughESTValueShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - t.Run("before relayed move balance fix", testRelayedESTTransferNotEnoughESTValueShouldConsumeGas(integrationTests.UnreachableEpoch)) - t.Run("after relayed move balance fix", testRelayedESTTransferNotEnoughESTValueShouldConsumeGas(0)) + t.Run("before relayed base cost fix", testRelayedESTTransferNotEnoughESTValueShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(9997488), big.NewInt(2512))) + t.Run("after relayed base cost fix", testRelayedESTTransferNotEnoughESTValueShouldConsumeGas(0, big.NewInt(9997119), big.NewInt(2881))) } -func testRelayedESTTransferNotEnoughESTValueShouldConsumeGas(relayedFixActivationEpoch uint32) func(t *testing.T) { +func testRelayedESTTransferNotEnoughESTValueShouldConsumeGas( + relayedFixActivationEpoch uint32, + expectedRelayerBalance *big.Int, + expectedAccFees *big.Int, +) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, - }) + }, gasPriceModifier) require.Nil(t, err) defer testContext.Close() @@ -120,10 +128,10 @@ func testRelayedESTTransferNotEnoughESTValueShouldConsumeGas(relayedFixActivatio expectedEGLDBalance := big.NewInt(0) utils.TestAccount(t, testContext.Accounts, sndAddr, 1, expectedEGLDBalance) - utils.TestAccount(t, testContext.Accounts, relayerAddr, 1, big.NewInt(9997110)) + utils.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedRelayerBalance) // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(2890), accumulatedFees) + require.Equal(t, expectedAccFees, accumulatedFees) } } diff --git a/integrationTests/vm/txsFee/relayedMoveBalance_test.go b/integrationTests/vm/txsFee/relayedMoveBalance_test.go index b0f95f095a9..1a81602ff82 100644 --- a/integrationTests/vm/txsFee/relayedMoveBalance_test.go +++ b/integrationTests/vm/txsFee/relayedMoveBalance_test.go @@ -25,7 +25,7 @@ func TestRelayedMoveBalanceShouldWork(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ FixRelayedBaseCostEnableEpoch: integrationTests.UnreachableEpoch, - }) + }, 1) require.Nil(t, err) defer testContext.Close() @@ -75,7 +75,7 @@ func TestRelayedMoveBalanceInvalidGasLimitShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -113,7 +113,7 @@ func TestRelayedMoveBalanceInvalidUserTxShouldConsumeGas(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ FixRelayedBaseCostEnableEpoch: integrationTests.UnreachableEpoch, - }) + }, 1) require.Nil(t, err) defer testContext.Close() @@ -153,7 +153,7 @@ func TestRelayedMoveBalanceInvalidUserTxValueShouldConsumeGas(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ RelayedNonceFixEnableEpoch: 1, FixRelayedBaseCostEnableEpoch: integrationTests.UnreachableEpoch, - }) + }, 1) require.Nil(t, err) defer testContext.Close() @@ -192,7 +192,7 @@ func TestRelayedMoveBalanceHigherNonce(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ RelayedNonceFixEnableEpoch: 1, - }) + }, 1) require.Nil(t, err) defer testContext.Close() @@ -248,7 +248,7 @@ func TestRelayedMoveBalanceLowerNonce(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ RelayedNonceFixEnableEpoch: 1, - }) + }, 1) require.Nil(t, err) defer testContext.Close() @@ -312,6 +312,7 @@ func TestRelayedMoveBalanceHigherNonceWithActivatedFixCrossShard(t *testing.T) { shardCoordinator0, integrationtests.CreateMemUnit(), vm.CreateMockGasScheduleNotifier(), + 1, ) require.Nil(t, err) @@ -321,6 +322,7 @@ func TestRelayedMoveBalanceHigherNonceWithActivatedFixCrossShard(t *testing.T) { shardCoordinator1, integrationtests.CreateMemUnit(), vm.CreateMockGasScheduleNotifier(), + 1, ) require.Nil(t, err) defer testContext0.Close() diff --git a/integrationTests/vm/txsFee/relayedScCalls_test.go b/integrationTests/vm/txsFee/relayedScCalls_test.go index 50e13d4b7c4..20ee29b02e5 100644 --- a/integrationTests/vm/txsFee/relayedScCalls_test.go +++ b/integrationTests/vm/txsFee/relayedScCalls_test.go @@ -19,20 +19,25 @@ func TestRelayedScCallShouldWork(t *testing.T) { t.Skip("this is not a short test") } - t.Run("before relayed fix", testRelayedScCallShouldWork(integrationTests.UnreachableEpoch)) - t.Run("after relayed fix", testRelayedScCallShouldWork(0)) + t.Run("before relayed base cost fix", testRelayedScCallShouldWork(integrationTests.UnreachableEpoch, big.NewInt(29982306), big.NewInt(25903), big.NewInt(1608))) + t.Run("after relayed base cost fix", testRelayedScCallShouldWork(0, big.NewInt(29982216), big.NewInt(25993), big.NewInt(1608))) } -func testRelayedScCallShouldWork(relayedFixActivationEpoch uint32) func(t *testing.T) { +func testRelayedScCallShouldWork( + relayedFixActivationEpoch uint32, + expectedRelayerBalance *big.Int, + expectedAccFees *big.Int, + expectedDevFees *big.Int, +) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, - }) + }, gasPriceModifier) require.Nil(t, err) defer testContext.Close() - scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm", 9991691, 8309, 39) utils.CleanAccumulatedIntermediateTransactions(t, testContext) relayerAddr := []byte("12345678901234567890123456789033") @@ -58,15 +63,14 @@ func testRelayedScCallShouldWork(relayedFixActivationEpoch uint32) func(t *testi ret := vm.GetIntValueFromSC(nil, testContext.Accounts, scAddress, "get") require.Equal(t, big.NewInt(2), ret) - expectedBalance := big.NewInt(29840970) - vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalance) + vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedRelayerBalance) // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(170830), accumulatedFees) + require.Equal(t, expectedAccFees, accumulatedFees) developerFees := testContext.TxFeeHandler.GetDeveloperFees() - require.Equal(t, big.NewInt(16093), developerFees) + require.Equal(t, expectedDevFees, developerFees) } } @@ -75,15 +79,19 @@ func TestRelayedScCallContractNotFoundShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - t.Run("before relayed fix", testRelayedScCallContractNotFoundShouldConsumeGas(integrationTests.UnreachableEpoch)) - t.Run("after relayed fix", testRelayedScCallContractNotFoundShouldConsumeGas(0)) + t.Run("before relayed fix", testRelayedScCallContractNotFoundShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(27130), big.NewInt(2870))) + t.Run("after relayed fix", testRelayedScCallContractNotFoundShouldConsumeGas(0, big.NewInt(27040), big.NewInt(2960))) } -func testRelayedScCallContractNotFoundShouldConsumeGas(relayedFixActivationEpoch uint32) func(t *testing.T) { +func testRelayedScCallContractNotFoundShouldConsumeGas( + relayedFixActivationEpoch uint32, + expectedRelayerBalance *big.Int, + expectedAccFees *big.Int, +) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, - }) + }, gasPriceModifier) require.Nil(t, err) defer testContext.Close() @@ -110,12 +118,11 @@ func testRelayedScCallContractNotFoundShouldConsumeGas(relayedFixActivationEpoch _, err = testContext.Accounts.Commit() require.Nil(t, err) - expectedBalance := big.NewInt(18130) - vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalance) + vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedRelayerBalance) // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(11870), accumulatedFees) + require.Equal(t, expectedAccFees, accumulatedFees) developerFees := testContext.TxFeeHandler.GetDeveloperFees() require.Equal(t, big.NewInt(0), developerFees) @@ -127,19 +134,23 @@ func TestRelayedScCallInvalidMethodShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - t.Run("before relayed fix", testRelayedScCallInvalidMethodShouldConsumeGas(integrationTests.UnreachableEpoch)) - t.Run("after relayed fix", testRelayedScCallInvalidMethodShouldConsumeGas(0)) + t.Run("before relayed fix", testRelayedScCallInvalidMethodShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(26924), big.NewInt(11385))) + t.Run("after relayed fix", testRelayedScCallInvalidMethodShouldConsumeGas(0, big.NewInt(26924), big.NewInt(11385))) } -func testRelayedScCallInvalidMethodShouldConsumeGas(relayedFixActivationEpoch uint32) func(t *testing.T) { +func testRelayedScCallInvalidMethodShouldConsumeGas( + relayedFixActivationEpoch uint32, + expectedRelayerBalance *big.Int, + expectedAccFees *big.Int, +) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ RelayedNonceFixEnableEpoch: relayedFixActivationEpoch, - }) + }, gasPriceModifier) require.Nil(t, err) defer testContext.Close() - scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm", 9991691, 8309, 39) utils.CleanAccumulatedIntermediateTransactions(t, testContext) relayerAddr := []byte("12345678901234567890123456789033") @@ -162,15 +173,14 @@ func testRelayedScCallInvalidMethodShouldConsumeGas(relayedFixActivationEpoch ui _, err = testContext.Accounts.Commit() require.Nil(t, err) - expectedBalance := big.NewInt(18050) - vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalance) + vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedRelayerBalance) // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(23850), accumulatedFees) + require.Equal(t, expectedAccFees, accumulatedFees) developerFees := testContext.TxFeeHandler.GetDeveloperFees() - require.Equal(t, big.NewInt(399), developerFees) + require.Equal(t, big.NewInt(39), developerFees) } } @@ -179,19 +189,23 @@ func TestRelayedScCallInsufficientGasLimitShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - t.Run("before relayed fix", testRelayedScCallInsufficientGasLimitShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(28050), big.NewInt(13850))) - t.Run("after relayed fix", testRelayedScCallInsufficientGasLimitShouldConsumeGas(0, big.NewInt(28050), big.NewInt(13850))) + t.Run("before relayed fix", testRelayedScCallInsufficientGasLimitShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(28140), big.NewInt(10169))) + t.Run("after relayed fix", testRelayedScCallInsufficientGasLimitShouldConsumeGas(0, big.NewInt(28050), big.NewInt(10259))) } -func testRelayedScCallInsufficientGasLimitShouldConsumeGas(relayedFixActivationEpoch uint32, expectedBalance *big.Int, expectedAccumulatedFees *big.Int) func(t *testing.T) { +func testRelayedScCallInsufficientGasLimitShouldConsumeGas( + relayedFixActivationEpoch uint32, + expectedBalance *big.Int, + expectedAccumulatedFees *big.Int, +) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, - }) + }, gasPriceModifier) require.Nil(t, err) defer testContext.Close() - scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm", 9991691, 8309, 39) utils.CleanAccumulatedIntermediateTransactions(t, testContext) relayerAddr := []byte("12345678901234567890123456789033") @@ -221,7 +235,7 @@ func testRelayedScCallInsufficientGasLimitShouldConsumeGas(relayedFixActivationE require.Equal(t, expectedAccumulatedFees, accumulatedFees) developerFees := testContext.TxFeeHandler.GetDeveloperFees() - require.Equal(t, big.NewInt(399), developerFees) + require.Equal(t, big.NewInt(39), developerFees) } } @@ -230,19 +244,23 @@ func TestRelayedScCallOutOfGasShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - t.Run("before relayed fix", testRelayedScCallOutOfGasShouldConsumeGas(integrationTests.UnreachableEpoch)) - t.Run("after relayed fix", testRelayedScCallOutOfGasShouldConsumeGas(0)) + t.Run("before relayed fix", testRelayedScCallOutOfGasShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(28040), big.NewInt(10269))) + t.Run("after relayed fix", testRelayedScCallOutOfGasShouldConsumeGas(0, big.NewInt(28040), big.NewInt(10269))) } -func testRelayedScCallOutOfGasShouldConsumeGas(relayedFixActivationEpoch uint32) func(t *testing.T) { +func testRelayedScCallOutOfGasShouldConsumeGas( + relayedFixActivationEpoch uint32, + expectedRelayerBalance *big.Int, + expectedAccFees *big.Int, +) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ RelayedNonceFixEnableEpoch: relayedFixActivationEpoch, - }) + }, gasPriceModifier) require.Nil(t, err) defer testContext.Close() - scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm", 9991691, 8309, 39) utils.CleanAccumulatedIntermediateTransactions(t, testContext) relayerAddr := []byte("12345678901234567890123456789033") @@ -265,15 +283,14 @@ func testRelayedScCallOutOfGasShouldConsumeGas(relayedFixActivationEpoch uint32) _, err = testContext.Accounts.Commit() require.Nil(t, err) - expectedBalance := big.NewInt(27950) - vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalance) + vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedRelayerBalance) // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(13950), accumulatedFees) + require.Equal(t, expectedAccFees, accumulatedFees) developerFees := testContext.TxFeeHandler.GetDeveloperFees() - require.Equal(t, big.NewInt(399), developerFees) + require.Equal(t, big.NewInt(39), developerFees) } } @@ -325,7 +342,7 @@ func testRelayedDeployInvalidContractShouldIncrementNonceOnSender( senderAddr []byte, senderNonce uint64, ) *vm.VMTestContext { - testContext, err := vm.CreatePreparedTxProcessorWithVMs(enableEpochs) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(enableEpochs, 1) require.Nil(t, err) relayerAddr := []byte("12345678901234567890123456789033") diff --git a/integrationTests/vm/txsFee/relayedScDeploy_test.go b/integrationTests/vm/txsFee/relayedScDeploy_test.go index 1a45e2c8760..21bd43df7e2 100644 --- a/integrationTests/vm/txsFee/relayedScDeploy_test.go +++ b/integrationTests/vm/txsFee/relayedScDeploy_test.go @@ -17,15 +17,19 @@ func TestRelayedScDeployShouldWork(t *testing.T) { t.Skip("this is not a short test") } - t.Run("before relayed fix", testRelayedScDeployShouldWork(integrationTests.UnreachableEpoch)) - t.Run("after relayed fix", testRelayedScDeployShouldWork(0)) + t.Run("before relayed fix", testRelayedScDeployShouldWork(integrationTests.UnreachableEpoch, big.NewInt(20170), big.NewInt(29830))) + t.Run("after relayed fix", testRelayedScDeployShouldWork(0, big.NewInt(8389), big.NewInt(41611))) } -func testRelayedScDeployShouldWork(relayedFixActivationEpoch uint32) func(t *testing.T) { +func testRelayedScDeployShouldWork( + relayedFixActivationEpoch uint32, + expectedRelayerBalance *big.Int, + expectedAccFees *big.Int, +) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, - }) + }, gasPriceModifier) require.Nil(t, err) defer testContext.Close() @@ -53,15 +57,14 @@ func testRelayedScDeployShouldWork(relayedFixActivationEpoch uint32) func(t *tes _, err = testContext.Accounts.Commit() require.Nil(t, err) - expectedBalanceRelayer := big.NewInt(2530) - vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedBalanceRelayer) + vm.TestAccount(t, testContext.Accounts, relayerAddr, 1, expectedRelayerBalance) // check balance inner tx sender vm.TestAccount(t, testContext.Accounts, sndAddr, 1, big.NewInt(0)) // check accumulated fees accumulatedFees := testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(47470), accumulatedFees) + require.Equal(t, expectedAccFees, accumulatedFees) } } @@ -70,15 +73,19 @@ func TestRelayedScDeployInvalidCodeShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - t.Run("before relayed fix", testRelayedScDeployInvalidCodeShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(8890), big.NewInt(41110))) + t.Run("before relayed fix", testRelayedScDeployInvalidCodeShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(20716), big.NewInt(29284))) t.Run("after relayed fix", testRelayedScDeployInvalidCodeShouldConsumeGas(0, big.NewInt(8890), big.NewInt(41110))) } -func testRelayedScDeployInvalidCodeShouldConsumeGas(relayedFixActivationEpoch uint32, expectedBalance *big.Int, expectedAccumulatedFees *big.Int) func(t *testing.T) { +func testRelayedScDeployInvalidCodeShouldConsumeGas( + relayedFixActivationEpoch uint32, + expectedBalance *big.Int, + expectedAccumulatedFees *big.Int, +) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, - }) + }, gasPriceModifier) require.Nil(t, err) defer testContext.Close() @@ -123,15 +130,19 @@ func TestRelayedScDeployInsufficientGasLimitShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - t.Run("before relayed fix", testRelayedScDeployInsufficientGasLimitShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(9040), big.NewInt(40960))) + t.Run("before relayed fix", testRelayedScDeployInsufficientGasLimitShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(20821), big.NewInt(29179))) t.Run("after relayed fix", testRelayedScDeployInsufficientGasLimitShouldConsumeGas(0, big.NewInt(9040), big.NewInt(40960))) } -func testRelayedScDeployInsufficientGasLimitShouldConsumeGas(relayedFixActivationEpoch uint32, expectedBalance *big.Int, expectedAccumulatedFees *big.Int) func(t *testing.T) { +func testRelayedScDeployInsufficientGasLimitShouldConsumeGas( + relayedFixActivationEpoch uint32, + expectedBalance *big.Int, + expectedAccumulatedFees *big.Int, +) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, - }) + }, gasPriceModifier) require.Nil(t, err) defer testContext.Close() @@ -175,15 +186,19 @@ func TestRelayedScDeployOutOfGasShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - t.Run("before relayed fix", testRelayedScDeployOutOfGasShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(9040), big.NewInt(40960))) + t.Run("before relayed fix", testRelayedScDeployOutOfGasShouldConsumeGas(integrationTests.UnreachableEpoch, big.NewInt(20821), big.NewInt(29179))) t.Run("after relayed fix", testRelayedScDeployOutOfGasShouldConsumeGas(0, big.NewInt(9040), big.NewInt(40960))) } -func testRelayedScDeployOutOfGasShouldConsumeGas(relayedFixActivationEpoch uint32, expectedBalance *big.Int, expectedAccumulatedFees *big.Int) func(t *testing.T) { +func testRelayedScDeployOutOfGasShouldConsumeGas( + relayedFixActivationEpoch uint32, + expectedBalance *big.Int, + expectedAccumulatedFees *big.Int, +) func(t *testing.T) { return func(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ FixRelayedBaseCostEnableEpoch: relayedFixActivationEpoch, - }) + }, gasPriceModifier) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/scCalls_test.go b/integrationTests/vm/txsFee/scCalls_test.go index 0c2262a9362..c17474eb9e3 100644 --- a/integrationTests/vm/txsFee/scCalls_test.go +++ b/integrationTests/vm/txsFee/scCalls_test.go @@ -66,6 +66,7 @@ func prepareTestContextForEpoch836(tb testing.TB) (*vm.VMTestContext, []byte) { db, gasScheduleNotifier, testscommon.GetDefaultRoundsConfig(), + 1, ) require.Nil(tb, err) @@ -92,11 +93,11 @@ func TestScCallShouldWork(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, - }) + }, 1) require.Nil(t, err) defer testContext.Close() - scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm", 9988100, 11900, 399) utils.CleanAccumulatedIntermediateTransactions(t, testContext) sndAddr := []byte("12345678901234567890123456789112") @@ -138,7 +139,7 @@ func TestScCallContractNotFoundShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -171,11 +172,11 @@ func TestScCallInvalidMethodToCallShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() - scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm", 9988100, 11900, 399) utils.CleanAccumulatedIntermediateTransactions(t, testContext) sndAddr := []byte("12345678901234567890123456789112") @@ -208,11 +209,11 @@ func TestScCallInsufficientGasLimitShouldNotConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() - scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm", 9988100, 11900, 399) sndAddr := []byte("12345678901234567890123456789112") senderBalance := big.NewInt(100000) @@ -246,11 +247,11 @@ func TestScCallOutOfGasShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() - scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm", 9988100, 11900, 399) utils.CleanAccumulatedIntermediateTransactions(t, testContext) sndAddr := []byte("12345678901234567890123456789112") @@ -285,13 +286,13 @@ func TestScCallAndGasChangeShouldWork(t *testing.T) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{ DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, - }) + }, 1) require.Nil(t, err) defer testContext.Close() mockGasSchedule := testContext.GasSchedule.(*mock.GasScheduleNotifierMock) - scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm") + scAddress, _ := utils.DoDeploy(t, testContext, "../wasm/testdata/counter/output/counter.wasm", 9988100, 11900, 399) utils.CleanAccumulatedIntermediateTransactions(t, testContext) sndAddr := []byte("12345678901234567890123456789112") @@ -332,7 +333,7 @@ func TestESDTScCallAndGasChangeShouldWork(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -421,7 +422,7 @@ func prepareTestContextForEpoch460(tb testing.TB) (*vm.VMTestContext, []byte) { RefactorPeersMiniBlocksEnableEpoch: unreachableEpoch, RuntimeMemStoreLimitEnableEpoch: unreachableEpoch, MaxBlockchainHookCountersEnableEpoch: unreachableEpoch, - }) + }, 1) require.Nil(tb, err) senderBalance := big.NewInt(1000000000000000000) diff --git a/integrationTests/vm/txsFee/scDeploy_test.go b/integrationTests/vm/txsFee/scDeploy_test.go index 8410bcf4917..ea646e6db73 100644 --- a/integrationTests/vm/txsFee/scDeploy_test.go +++ b/integrationTests/vm/txsFee/scDeploy_test.go @@ -17,7 +17,7 @@ func TestScDeployShouldWork(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -52,7 +52,7 @@ func TestScDeployInvalidContractCodeShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -88,7 +88,7 @@ func TestScDeployInsufficientGasLimitShouldNotConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() @@ -123,7 +123,7 @@ func TestScDeployOutOfGasShouldConsumeGas(t *testing.T) { t.Skip("this is not a short test") } - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() diff --git a/integrationTests/vm/txsFee/utils/utils.go b/integrationTests/vm/txsFee/utils/utils.go index 3eea35a4833..bc7abfbeaf0 100644 --- a/integrationTests/vm/txsFee/utils/utils.go +++ b/integrationTests/vm/txsFee/utils/utils.go @@ -37,8 +37,11 @@ func DoDeploy( t *testing.T, testContext *vm.VMTestContext, pathToContract string, + expectedBalance, + expectedAccFees, + expectedDevFees int64, ) (scAddr []byte, owner []byte) { - return doDeployInternal(t, testContext, pathToContract, 9988100, 11900, 399) + return doDeployInternal(t, testContext, pathToContract, expectedBalance, expectedAccFees, expectedDevFees) } // DoDeployOldCounter - diff --git a/integrationTests/vm/txsFee/validatorSC_test.go b/integrationTests/vm/txsFee/validatorSC_test.go index 6de545c5c93..c54025a90b1 100644 --- a/integrationTests/vm/txsFee/validatorSC_test.go +++ b/integrationTests/vm/txsFee/validatorSC_test.go @@ -54,7 +54,7 @@ func TestValidatorsSC_DoStakePutInQueueUnStakeAndUnBondShouldRefund(t *testing.T t.Skip("this is not a short test") } - testContextMeta, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(core.MetachainShardId, config.EnableEpochs{}) + testContextMeta, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(core.MetachainShardId, config.EnableEpochs{}, 1) require.Nil(t, err) defer testContextMeta.Close() @@ -120,6 +120,7 @@ func TestValidatorsSC_DoStakePutInQueueUnStakeAndUnBondTokensShouldRefund(t *tes StakingV4Step1EnableEpoch: stakingV4Step1EnableEpoch, StakingV4Step2EnableEpoch: stakingV4Step2EnableEpoch, }, + 1, ) require.Nil(t, err) @@ -170,7 +171,7 @@ func TestValidatorsSC_DoStakeWithTopUpValueTryToUnStakeTokensAndUnBondTokens(t * } func testValidatorsSCDoStakeWithTopUpValueTryToUnStakeTokensAndUnBondTokens(t *testing.T, enableEpochs config.EnableEpochs) { - testContextMeta, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(core.MetachainShardId, enableEpochs) + testContextMeta, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(core.MetachainShardId, enableEpochs, 1) require.Nil(t, err) defer testContextMeta.Close() @@ -207,6 +208,7 @@ func TestValidatorsSC_ToStakePutInQueueUnStakeAndUnBondShouldRefundUnBondTokens( StakingV4Step1EnableEpoch: stakingV4Step1EnableEpoch, StakingV4Step2EnableEpoch: stakingV4Step2EnableEpoch, }, + 1, ) require.Nil(t, err) @@ -263,6 +265,7 @@ func TestValidatorsSC_ToStakePutInQueueUnStakeNodesAndUnBondNodesShouldRefund(t StakingV4Step1EnableEpoch: stakingV4Step1EnableEpoch, StakingV4Step2EnableEpoch: stakingV4Step2EnableEpoch, }, + 1, ) require.Nil(t, err) diff --git a/integrationTests/vm/wasm/wasmvm/scenariosConverter/scenariosConverterUtils.go b/integrationTests/vm/wasm/wasmvm/scenariosConverter/scenariosConverterUtils.go index 2d3d15f681d..ad23085011f 100644 --- a/integrationTests/vm/wasm/wasmvm/scenariosConverter/scenariosConverterUtils.go +++ b/integrationTests/vm/wasm/wasmvm/scenariosConverter/scenariosConverterUtils.go @@ -119,7 +119,7 @@ func SetStateFromScenariosTest(scenariosTestPath string) (testContext *vm.VMTest if err != nil { return nil, nil, exporter.InvalidBenchmarkTxPos, err } - testContext, err = vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err = vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) if err != nil { return nil, nil, exporter.InvalidBenchmarkTxPos, err } @@ -140,7 +140,7 @@ func SetStateFromScenariosTest(scenariosTestPath string) (testContext *vm.VMTest func CheckConverter(t *testing.T, scenariosTestPath string) { stateAndBenchmarkInfo, err := exporter.GetAccountsAndTransactionsFromScenarios(scenariosTestPath) require.Nil(t, err) - testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}) + testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) err = CreateAccountsFromScenariosAccs(testContext, stateAndBenchmarkInfo.Accs) require.Nil(t, err) diff --git a/integrationTests/vm/wasm/wasmvm/wasmVM_test.go b/integrationTests/vm/wasm/wasmvm/wasmVM_test.go index 1fa706e8003..9ad6a861235 100644 --- a/integrationTests/vm/wasm/wasmvm/wasmVM_test.go +++ b/integrationTests/vm/wasm/wasmvm/wasmVM_test.go @@ -948,11 +948,11 @@ func TestCommunityContract_CrossShard_TxProcessor(t *testing.T) { zero := big.NewInt(0) transferEGLD := big.NewInt(42) - testContextFunderSC, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}) + testContextFunderSC, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, config.EnableEpochs{}, 1) require.Nil(t, err) defer testContextFunderSC.Close() - testContextParentSC, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) + testContextParentSC, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}, 1) require.Nil(t, err) defer testContextParentSC.Close() From dcee74cc51a6e9bd84de7ceb2f8610f1903e4cfe Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 2 Jul 2024 14:22:13 +0300 Subject: [PATCH 402/503] fix nft api test --- integrationTests/chainSimulator/vm/esdtTokens_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtTokens_test.go b/integrationTests/chainSimulator/vm/esdtTokens_test.go index f3516333558..00f5e3344f6 100644 --- a/integrationTests/chainSimulator/vm/esdtTokens_test.go +++ b/integrationTests/chainSimulator/vm/esdtTokens_test.go @@ -288,7 +288,7 @@ func TestChainSimulator_Api_NFTToken(t *testing.T) { tokenData, ok := allTokens[expTokenID] require.True(t, ok) require.Equal(t, expTokenID, tokenData.TokenIdentifier) - require.Equal(t, core.NonFungibleESDT, tokenData.Type) + require.Equal(t, "", tokenData.Type) log.Info("Wait for DynamicESDTFlag activation") @@ -305,7 +305,7 @@ func TestChainSimulator_Api_NFTToken(t *testing.T) { tokenData, ok = allTokens[expTokenID] require.True(t, ok) require.Equal(t, expTokenID, tokenData.TokenIdentifier) - require.Equal(t, core.NonFungibleESDT, tokenData.Type) + require.Equal(t, "", tokenData.Type) log.Info("Update token id", "tokenID", nftTokenID) @@ -326,7 +326,7 @@ func TestChainSimulator_Api_NFTToken(t *testing.T) { tokenData, ok = allTokens[expTokenID] require.True(t, ok) require.Equal(t, expTokenID, tokenData.TokenIdentifier) - require.Equal(t, core.NonFungibleESDT, tokenData.Type) + require.Equal(t, "", tokenData.Type) log.Info("Transfer token id", "tokenID", nftTokenID) From 703fe6e3f742dd7693ef924e368be7cb2a8b837e Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 2 Jul 2024 16:22:37 +0300 Subject: [PATCH 403/503] small fix --- outport/process/alteredaccounts/alteredAccountsProvider.go | 2 +- .../process/alteredaccounts/alteredAccountsProvider_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/outport/process/alteredaccounts/alteredAccountsProvider.go b/outport/process/alteredaccounts/alteredAccountsProvider.go index 5a0a890381e..c95fea79b69 100644 --- a/outport/process/alteredaccounts/alteredAccountsProvider.go +++ b/outport/process/alteredaccounts/alteredAccountsProvider.go @@ -239,7 +239,7 @@ func (aap *alteredAccountsProvider) addTokensDataForMarkedAccount( func getTokenType(tokenType uint32, tokenNonce uint64) string { isNotFungible := tokenNonce != 0 - tokenTypeNotSet := isNotFungible && core.ESDTType(tokenType) == core.Fungible + tokenTypeNotSet := isNotFungible && core.ESDTType(tokenType) == core.NonFungible if tokenTypeNotSet { return "" } diff --git a/outport/process/alteredaccounts/alteredAccountsProvider_test.go b/outport/process/alteredaccounts/alteredAccountsProvider_test.go index 032af616d19..c6fce787c71 100644 --- a/outport/process/alteredaccounts/alteredAccountsProvider_test.go +++ b/outport/process/alteredaccounts/alteredAccountsProvider_test.go @@ -628,6 +628,7 @@ func testExtractAlteredAccountsFromPoolShouldIncludeNFT(t *testing.T) { t.Parallel() expectedToken := esdt.ESDigitalToken{ + Type: uint32(core.NonFungible), Value: big.NewInt(37), TokenMetaData: &esdt.MetaData{ Nonce: 38, @@ -758,6 +759,7 @@ func testExtractAlteredAccountsFromPoolShouldIncludeDestinationFromTokensLogsTop receiverOnDestination := []byte("receiver on destination shard") expectedToken := esdt.ESDigitalToken{ Value: big.NewInt(37), + Type: uint32(core.NonFungible), TokenMetaData: &esdt.MetaData{ Nonce: 38, Name: []byte("name"), @@ -904,12 +906,14 @@ func testExtractAlteredAccountsFromPoolMultiTransferEventV2(t *testing.T) { TokenMetaData: &esdt.MetaData{ Nonce: 1, }, + Type: uint32(core.NonFungible), } expectedToken2 := &esdt.ESDigitalToken{ Value: big.NewInt(10), TokenMetaData: &esdt.MetaData{ Nonce: 1, }, + Type: uint32(core.NonFungible), } args := getMockArgs() @@ -1004,6 +1008,7 @@ func testExtractAlteredAccountsFromPoolAddressHasMultipleNfts(t *testing.T) { } expectedToken1 := esdt.ESDigitalToken{ Value: big.NewInt(38), + Type: uint32(core.NonFungible), TokenMetaData: &esdt.MetaData{ Nonce: 5, Name: []byte("nft-0"), @@ -1011,6 +1016,7 @@ func testExtractAlteredAccountsFromPoolAddressHasMultipleNfts(t *testing.T) { } expectedToken2 := esdt.ESDigitalToken{ Value: big.NewInt(37), + Type: uint32(core.NonFungible), TokenMetaData: &esdt.MetaData{ Nonce: 6, Name: []byte("nft-0"), From f1286c4e6b0b068e3dfe64f5c2a0b4696fd8f1a6 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 3 Jul 2024 13:04:53 +0300 Subject: [PATCH 404/503] updated core-go --- go.mod | 2 +- go.sum | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 0865d10ebc3..ffd392aa952 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e - github.com/multiversx/mx-chain-core-go v1.2.21-0.20240611111433-86ff8cd5798b + github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703095353-e5daea901067 github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240514103357-929ece92ef86 github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 diff --git a/go.sum b/go.sum index 728b917de55..b802809adf4 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= @@ -390,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY 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.20240611111433-86ff8cd5798b h1:cbMcnL97p2NTn0KDyA9aEwnDzdmFf/lQaztsQujGZxY= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240611111433-86ff8cd5798b/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703095353-e5daea901067 h1:xkWwOJok4GlbMd/BBtJ75wnNRjIVh4o+7RdZL/q/mlQ= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703095353-e5daea901067/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= @@ -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= From c6eb449d931c99cb07fa21ba2d67dd70e5e2205f Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 3 Jul 2024 13:51:53 +0300 Subject: [PATCH 405/503] extend log events for claimRewards and reDelegate --- vm/systemSmartContracts/delegation.go | 2 +- vm/systemSmartContracts/logs.go | 7 ++----- vm/systemSmartContracts/logs_test.go | 3 ++- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/vm/systemSmartContracts/delegation.go b/vm/systemSmartContracts/delegation.go index ab5c97cfce0..da23e0c8a15 100644 --- a/vm/systemSmartContracts/delegation.go +++ b/vm/systemSmartContracts/delegation.go @@ -2096,7 +2096,7 @@ func (d *delegation) claimRewards(args *vmcommon.ContractCallInput) vmcommon.Ret } } - d.createAndAddLogEntry(args, unclaimedRewardsBytes, boolToSlice(wasDeleted)) + d.createAndAddLogEntry(args, unclaimedRewardsBytes, boolToSlice(wasDeleted), args.RecipientAddr) return vmcommon.Ok } diff --git a/vm/systemSmartContracts/logs.go b/vm/systemSmartContracts/logs.go index 69af22820e1..c40834107f3 100644 --- a/vm/systemSmartContracts/logs.go +++ b/vm/systemSmartContracts/logs.go @@ -64,13 +64,10 @@ func (d *delegation) createAndAddLogEntryForDelegate( function == mergeValidatorDataToDelegation || function == changeOwner { address = contractCallInput.Arguments[0] - - topics = append(topics, contractCallInput.RecipientAddr) - } - if function == core.SCDeployInitFunctionName { - topics = append(topics, contractCallInput.RecipientAddr) } + topics = append(topics, contractCallInput.RecipientAddr) + entry := &vmcommon.LogEntry{ Identifier: []byte("delegate"), Address: address, diff --git a/vm/systemSmartContracts/logs_test.go b/vm/systemSmartContracts/logs_test.go index 5f88b1ddabd..4fc3f536878 100644 --- a/vm/systemSmartContracts/logs_test.go +++ b/vm/systemSmartContracts/logs_test.go @@ -37,6 +37,7 @@ func TestCreateLogEntryForDelegate(t *testing.T) { VMInput: vmcommon.VMInput{ CallerAddr: []byte("caller"), }, + RecipientAddr: []byte("recipient"), }, delegationValue, &GlobalFundData{ @@ -52,7 +53,7 @@ func TestCreateLogEntryForDelegate(t *testing.T) { require.Equal(t, &vmcommon.LogEntry{ Identifier: []byte("delegate"), Address: []byte("caller"), - Topics: [][]byte{delegationValue.Bytes(), big.NewInt(6000).Bytes(), big.NewInt(1).Bytes(), big.NewInt(1001000).Bytes()}, + Topics: [][]byte{delegationValue.Bytes(), big.NewInt(6000).Bytes(), big.NewInt(1).Bytes(), big.NewInt(1001000).Bytes(), []byte("recipient")}, }, res) } From d6f4f4aeb066f72214d91deee6ef73196a61117d Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 3 Jul 2024 17:02:23 +0300 Subject: [PATCH 406/503] update mx-chain-core-go after merge --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 111e739a2a4..6dfb3d0c7c0 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e - github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703095353-e5daea901067 + github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703135649-550eebfbc10b github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619122842-05143459c554 github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 diff --git a/go.sum b/go.sum index f7cc76137bf..27c71b04923 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY 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.20240530111258-45870512bfbe h1:7ccy0nNJkCGDlRrIbAmZfVv5XkZAxXuBFnfUMNuESRA= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240530111258-45870512bfbe/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703135649-550eebfbc10b h1:bmN8RtaWC/7lQenavRVVY5NrAPOdh3N9tGyxqVrx2qU= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703135649-550eebfbc10b/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.20240619122842-05143459c554 h1:Fv8BfzJSzdovmoh9Jh/by++0uGsOVBlMP3XiN5Svkn4= From b19c5bfc15067735c4e38180de0b384e908345b0 Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Thu, 4 Jul 2024 09:44:38 +0300 Subject: [PATCH 407/503] update gosum --- go.sum | 2 -- 1 file changed, 2 deletions(-) diff --git a/go.sum b/go.sum index 1d3b86150e2..0741a2c097b 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,6 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY 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-core-go v1.2.21-0.20240530111258-45870512bfbe h1:7ccy0nNJkCGDlRrIbAmZfVv5XkZAxXuBFnfUMNuESRA= github.com/multiversx/mx-chain-core-go v1.2.21-0.20240530111258-45870512bfbe/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df h1:clihfi78bMEOWk/qw6WA4uQbCM2e2NGliqswLAvw19k= From 56aa201ce35acd2a483afd5167ee9098e6fd17e7 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 4 Jul 2024 11:40:58 +0300 Subject: [PATCH 408/503] fixes after merge --- process/transaction/shardProcess.go | 2 +- process/transaction/shardProcess_test.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 297b66abacb..0b60687a199 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -1077,7 +1077,7 @@ func (txProc *txProcessor) processUserTx( return returnCode, nil } - err = txProc.scrForwarder.AddIntermediateTransactions([]data.TransactionHandler{scrFromTx}, txHash) + err = txProc.scrForwarder.AddIntermediateTransactions([]data.TransactionHandler{scrFromTx}, originalTxHash) if err != nil { return 0, err } diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index a7b30d5ccda..4756e48773b 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -17,6 +17,7 @@ import ( "github.com/multiversx/mx-chain-vm-common-go/builtInFunctions" "github.com/multiversx/mx-chain-vm-common-go/parsers" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/process" From 83695fca10e3a3f0e52ab8fea2e5b52376404e74 Mon Sep 17 00:00:00 2001 From: miiu Date: Thu, 4 Jul 2024 14:03:36 +0300 Subject: [PATCH 409/503] latest indexer version --- go.mod | 4 ++-- go.sum | 16 ++++------------ 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 3a719d45506..a4a1d2163a0 100644 --- a/go.mod +++ b/go.mod @@ -17,11 +17,11 @@ require ( github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e github.com/multiversx/mx-chain-core-go v1.2.21-0.20240530111258-45870512bfbe github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df - github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240514103357-929ece92ef86 + github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240703134111-bda0024613cc github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f - github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240529093845-2a375eef5cc1 + github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240619122724-2bd2e64cebdc github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240509104009-598a37ff36b9 diff --git a/go.sum b/go.sum index d0391c90496..13e357a1680 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= @@ -390,24 +387,20 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY 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-core-go v1.2.21-0.20240530111258-45870512bfbe h1:7ccy0nNJkCGDlRrIbAmZfVv5XkZAxXuBFnfUMNuESRA= github.com/multiversx/mx-chain-core-go v1.2.21-0.20240530111258-45870512bfbe/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-es-indexer-go v1.7.2-0.20240703134111-bda0024613cc h1:Bvy/34YigrjhUNBoyQBj9f5YlUyAnyZ3jR0aWnQa4yE= +github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240703134111-bda0024613cc/go.mod h1:yMq9q5VdN7jBaErRGQ0T8dkZwbBtfQYmqGbD/Ese1us= 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.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-common-go v1.5.13-0.20240619122724-2bd2e64cebdc h1:KpLloX0pIclo3axCQVOm3wZE+U9cfeHgPWGvDuUohTk= +github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240619122724-2bd2e64cebdc/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= @@ -420,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= From 0eb2890ce8334917d154abde982df3ebdaddef74 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 5 Jul 2024 17:30:32 +0300 Subject: [PATCH 410/503] added more integration tests for non-executable inner tx + small fix on failed tx logs --- .../relayedTx/relayedTx_test.go | 167 +++++++++++++++--- process/transaction/shardProcess.go | 3 +- process/transaction/shardProcess_test.go | 8 +- 3 files changed, 151 insertions(+), 27 deletions(-) diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index 29637aa1efc..860404e7ab9 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -21,7 +21,6 @@ import ( chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/sharding" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -29,9 +28,12 @@ const ( defaultPathToInitialConfig = "../../../cmd/node/config/" minGasPrice = 1_000_000_000 minGasLimit = 50_000 + guardAccountCost = 250_000 + extraGasLimitForGuarded = minGasLimit txVersion = 2 mockTxSignature = "sig" maxNumOfBlocksToGenerateWhenExecutingTx = 10 + roundsPerEpoch = 30 ) var ( @@ -102,7 +104,7 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing. innerTxs := []*transaction.Transaction{innerTx, innerTx2, innerTx3Failure, innerTx3} // relayer will consume first a move balance for each inner tx, then the specific gas for each inner tx - relayedTxGasLimit := uint64(minGasLimit) + relayedTxGasLimit := uint64(0) for _, tx := range innerTxs { relayedTxGasLimit += minGasLimit + tx.GasLimit } @@ -116,31 +118,21 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing. err = cs.GenerateBlocks(maxNumOfBlocksToGenerateWhenExecutingTx) require.NoError(t, err) - relayerAccount, err := cs.GetAccount(relayer) - require.NoError(t, err) economicsData := cs.GetNodeHandler(0).GetCoreComponents().EconomicsData() relayerMoveBalanceFee := economicsData.ComputeMoveBalanceFee(relayedTx) expectedRelayerFee := big.NewInt(0).Mul(relayerMoveBalanceFee, big.NewInt(int64(len(relayedTx.InnerTransactions)))) for _, tx := range innerTxs { expectedRelayerFee.Add(expectedRelayerFee, economicsData.ComputeTxFee(tx)) } - assert.Equal(t, big.NewInt(0).Sub(initialBalance, expectedRelayerFee).String(), relayerAccount.Balance) + checkBalance(t, cs, relayer, big.NewInt(0).Sub(initialBalance, expectedRelayerFee)) - senderAccount, err := cs.GetAccount(sender) - require.NoError(t, err) - assert.Equal(t, big.NewInt(0).Sub(initialBalance, big.NewInt(0).Mul(oneEGLD, big.NewInt(2))).String(), senderAccount.Balance) + checkBalance(t, cs, sender, big.NewInt(0).Sub(initialBalance, big.NewInt(0).Mul(oneEGLD, big.NewInt(2)))) - sender2Account, err := cs.GetAccount(sender2) - require.NoError(t, err) - assert.Equal(t, big.NewInt(0).Sub(initialBalance, oneEGLD).String(), sender2Account.Balance) + checkBalance(t, cs, sender2, big.NewInt(0).Sub(initialBalance, oneEGLD)) - receiverAccount, err := cs.GetAccount(receiver) - require.NoError(t, err) - assert.Equal(t, oneEGLD.String(), receiverAccount.Balance) + checkBalance(t, cs, receiver, oneEGLD) - receiver2Account, err := cs.GetAccount(receiver2) - require.NoError(t, err) - assert.Equal(t, big.NewInt(0).Mul(oneEGLD, big.NewInt(2)).String(), receiver2Account.Balance) + checkBalance(t, cs, receiver2, big.NewInt(0).Mul(oneEGLD, big.NewInt(2))) // check SCRs shardC := cs.GetNodeHandler(0).GetShardCoordinator() @@ -224,7 +216,7 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorScCalls(t *t innerTxs := []*transaction.Transaction{innerTx1, innerTx2, innerTx3, innerTx4, innerTx5, innerTx6, innerTx7} - relayedTxGasLimit := uint64(minGasLimit) + relayedTxGasLimit := uint64(0) for _, tx := range innerTxs { relayedTxGasLimit += minGasLimit + tx.GasLimit } @@ -275,7 +267,6 @@ func TestFixRelayedMoveBalanceWithChainSimulator(t *testing.T) { expectedFeeMoveBalanceBefore := "797500000000000" // 498 * 1500 + 50000 + 5000 expectedFeeMoveBalanceAfter := "847000000000000" // 498 * 1500 + 50000 + 50000 t.Run("move balance", testFixRelayedMoveBalanceWithChainSimulatorMoveBalance(expectedFeeMoveBalanceBefore, expectedFeeMoveBalanceAfter)) - } func testFixRelayedMoveBalanceWithChainSimulatorScCall( @@ -453,14 +444,136 @@ func testFixRelayedMoveBalanceWithChainSimulatorMoveBalance( } } +func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorInnerNotExecutable(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + cs := startChainSimulator(t, alterConfigsFuncRelayedV3EarlyActivation) + defer cs.Close() + + initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(10)) + relayer, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + sender, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + sender2, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + guardian, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + // Set guardian for sender + senderNonce := uint64(0) + setGuardianTxData := "SetGuardian@" + hex.EncodeToString(guardian.Bytes) + "@" + hex.EncodeToString([]byte("uuid")) + setGuardianGasLimit := minGasLimit + 1500*len(setGuardianTxData) + guardAccountCost + setGuardianTx := generateTransaction(sender.Bytes, senderNonce, sender.Bytes, big.NewInt(0), setGuardianTxData, uint64(setGuardianGasLimit)) + _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(setGuardianTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + // fast-forward until the guardian becomes active + err = cs.GenerateBlocks(roundsPerEpoch * 20) + require.NoError(t, err) + + // guard account + senderNonce++ + guardAccountTxData := "GuardAccount" + guardAccountGasLimit := minGasLimit + 1500*len(guardAccountTxData) + guardAccountCost + guardAccountTx := generateTransaction(sender.Bytes, senderNonce, sender.Bytes, big.NewInt(0), guardAccountTxData, uint64(guardAccountGasLimit)) + _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(guardAccountTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + receiver, err := cs.GenerateAndMintWalletAddress(1, big.NewInt(0)) + require.NoError(t, err) + + // move balance inner transaction non-executable due to guardian mismatch + senderNonce++ + innerTx := generateTransaction(sender.Bytes, senderNonce, receiver.Bytes, oneEGLD, "", minGasLimit+extraGasLimitForGuarded) + innerTx.RelayerAddr = relayer.Bytes + innerTx.GuardianAddr = sender.Bytes // this is not the real guardian + innerTx.GuardianSignature = []byte(mockTxSignature) + innerTx.Options = 2 + + // move balance inner transaction non-executable due to higher nonce + nonceTooHigh := uint64(100) + innerTx2 := generateTransaction(sender2.Bytes, nonceTooHigh, receiver.Bytes, oneEGLD, "", minGasLimit) + innerTx2.RelayerAddr = relayer.Bytes + + innerTxs := []*transaction.Transaction{innerTx, innerTx2} + + // relayer will consume first a move balance for each inner tx, then the specific gas for each inner tx + relayedTxGasLimit := uint64(0) + for _, tx := range innerTxs { + relayedTxGasLimit += minGasLimit + tx.GasLimit + } + relayedTx := generateTransaction(relayer.Bytes, 0, relayer.Bytes, big.NewInt(0), "", relayedTxGasLimit) + relayedTx.InnerTransactions = innerTxs + + result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + // generate few more blocks for the cross shard scrs to be done + err = cs.GenerateBlocks(maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + // check the inner tx failed with the desired error + require.Equal(t, 2, len(result.SmartContractResults)) + require.True(t, strings.Contains(result.SmartContractResults[0].ReturnMessage, process.ErrTransactionNotExecutable.Error())) + require.True(t, strings.Contains(result.SmartContractResults[0].ReturnMessage, process.ErrTransactionAndAccountGuardianMismatch.Error())) + require.True(t, strings.Contains(result.SmartContractResults[1].ReturnMessage, process.ErrHigherNonceInTransaction.Error())) + + // check events + require.Equal(t, 2, len(result.Logs.Events)) + for _, event := range result.Logs.Events { + require.Equal(t, core.SignalErrorOperation, event.Identifier) + } + + // compute expected consumed fee for relayer + expectedConsumedGasForGuardedInnerTx := minGasLimit + minGasLimit + extraGasLimitForGuarded // invalid guardian + expectedConsumedGasForHigherNonceInnerTx := minGasLimit + minGasLimit // higher nonce + expectedConsumeGas := expectedConsumedGasForGuardedInnerTx + expectedConsumedGasForHigherNonceInnerTx + expectedRelayerFee := core.SafeMul(uint64(expectedConsumeGas), minGasPrice) + checkBalance(t, cs, relayer, big.NewInt(0).Sub(initialBalance, expectedRelayerFee)) + + checkBalance(t, cs, receiver, big.NewInt(0)) + + relayerBalanceBeforeSuccessfullAttempt := getBalance(t, cs, relayer) + + // generate a valid guarded move balance inner tx + // senderNonce would be the same, as previous failed tx didn't increase it(expected) + innerTx = generateTransaction(sender.Bytes, senderNonce, receiver.Bytes, oneEGLD, "", minGasLimit+extraGasLimitForGuarded) + innerTx.RelayerAddr = relayer.Bytes + innerTx.GuardianAddr = guardian.Bytes + innerTx.GuardianSignature = []byte(mockTxSignature) + innerTx.Options = 2 + + innerTxs = []*transaction.Transaction{innerTx} + relayedTx = generateTransaction(relayer.Bytes, 1, relayer.Bytes, big.NewInt(0), "", relayedTxGasLimit) + relayedTx.InnerTransactions = innerTxs + + _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + // generate few more blocks for the cross shard scrs to be done + err = cs.GenerateBlocks(maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + expectedRelayerFee = core.SafeMul(uint64(expectedConsumedGasForGuardedInnerTx), minGasPrice) + checkBalance(t, cs, relayer, big.NewInt(0).Sub(relayerBalanceBeforeSuccessfullAttempt, expectedRelayerFee)) + + checkBalance(t, cs, receiver, oneEGLD) +} + func startChainSimulator( t *testing.T, alterConfigsFunction func(cfg *config.Configs), ) testsChainSimulator.ChainSimulator { roundDurationInMillis := uint64(6000) - roundsPerEpoch := core.OptionalUint64{ + roundsPerEpochOpt := core.OptionalUint64{ HasValue: true, - Value: 30, + Value: roundsPerEpoch, } cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ @@ -470,7 +583,7 @@ func startChainSimulator( NumOfShards: 3, GenesisTimestamp: time.Now().Unix(), RoundDurationInMillis: roundDurationInMillis, - RoundsPerEpoch: roundsPerEpoch, + RoundsPerEpoch: roundsPerEpochOpt, ApiInterface: api.NewNoApiInterface(), MinNodesPerShard: 3, MetaChainMinNodes: 3, @@ -567,3 +680,13 @@ func getBalance( return balance } + +func checkBalance( + t *testing.T, + cs testsChainSimulator.ChainSimulator, + address dtos.WalletAddress, + expectedBalance *big.Int, +) { + balance := getBalance(t, cs, address) + require.Equal(t, expectedBalance.String(), balance.String()) +} diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 0b60687a199..129ad2c5db8 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -932,7 +932,8 @@ func (txProc *txProcessor) addNonExecutableLog(executionErr error, originalTxHas Address: originalTx.GetRcvAddr(), } - return txProc.txLogsProcessor.SaveLog(originalTxHash, originalTx, []*vmcommon.LogEntry{logEntry}) + return txProc.failedTxLogsAccumulator.SaveLogs(originalTxHash, originalTx, []*vmcommon.LogEntry{logEntry}) + } func (txProc *txProcessor) processMoveBalanceCostRelayedUserTx( diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index 4756e48773b..1f077525ae2 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -3846,12 +3846,12 @@ func TestTxProcessor_AddNonExecutableLog(t *testing.T) { originalTxHash, err := core.CalculateHash(args.Marshalizer, args.Hasher, originalTx) assert.Nil(t, err) numLogsSaved := 0 - args.TxLogsProcessor = &mock.TxLogsProcessorStub{ - SaveLogCalled: func(txHash []byte, tx data.TransactionHandler, vmLogs []*vmcommon.LogEntry) error { + args.FailedTxLogsAccumulator = &processMocks.FailedTxLogsAccumulatorMock{ + SaveLogsCalled: func(txHash []byte, tx data.TransactionHandler, logs []*vmcommon.LogEntry) error { assert.Equal(t, originalTxHash, txHash) assert.Equal(t, originalTx, tx) - assert.Equal(t, 1, len(vmLogs)) - firstLog := vmLogs[0] + assert.Equal(t, 1, len(logs)) + firstLog := logs[0] assert.Equal(t, core.SignalErrorOperation, string(firstLog.Identifier)) assert.Equal(t, sender, firstLog.Address) assert.Empty(t, firstLog.Data) From 36ca3e5d6082897b681a76d7cd627a1ac30ea06c Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 8 Jul 2024 16:20:09 +0300 Subject: [PATCH 411/503] change receivers ids --- node/external/transactionAPI/unmarshaller.go | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/node/external/transactionAPI/unmarshaller.go b/node/external/transactionAPI/unmarshaller.go index cd7c63f83de..bc997cdf042 100644 --- a/node/external/transactionAPI/unmarshaller.go +++ b/node/external/transactionAPI/unmarshaller.go @@ -88,15 +88,10 @@ func (tu *txUnmarshaller) unmarshalTransaction(txBytes []byte, txType transactio } apiTx = tu.prepareUnsignedTx(&tx) } - if err != nil { - return nil, err - } isRelayedV3 := len(apiTx.InnerTransactions) > 0 if isRelayedV3 { apiTx.Operation = operationTransfer - - rcvsShardIDs := make(map[uint32]struct{}) for _, innerTx := range apiTx.InnerTransactions { apiTx.Receivers = append(apiTx.Receivers, innerTx.Receiver) @@ -106,12 +101,7 @@ func (tu *txUnmarshaller) unmarshalTransaction(txBytes []byte, txType transactio continue } - rcvShardID := tu.shardCoordinator.ComputeId(rcvBytes) - rcvsShardIDs[rcvShardID] = struct{}{} - } - - for rcvShard := range rcvsShardIDs { - apiTx.ReceiversShardIDs = append(apiTx.ReceiversShardIDs, rcvShard) + apiTx.ReceiversShardIDs = append(apiTx.ReceiversShardIDs, tu.shardCoordinator.ComputeId(rcvBytes)) } apiTx.IsRelayed = true From 189c060b193a37ceb21512f4d7b89912d3cc2676 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 9 Jul 2024 21:44:54 +0300 Subject: [PATCH 412/503] remove metadata test with fungible token --- .../vm/esdtImprovements_test.go | 75 +++---------------- 1 file changed, 12 insertions(+), 63 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index c35a38ae334..f24bef01b57 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -115,7 +115,7 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch) - 1) require.Nil(t, err) - log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (before the activation of DynamicEsdtFlag)") + log.Info("Initial setup: Create NFT, SFT and metaESDT tokens (before the activation of DynamicEsdtFlag)") // issue metaESDT metaESDTTicker := []byte("METATTICKER") @@ -136,23 +136,9 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) - // issue fungible - fungibleTicker := []byte("FUNTICKER") - tx = issueTx(1, addrs[0].Bytes, fungibleTicker, baseIssuingCost) - - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - - fungibleTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], fungibleTokenID, roles) - - log.Info("Issued fungible token id", "tokenID", string(fungibleTokenID)) - // issue NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(2, addrs[0].Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -166,7 +152,7 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(3, addrs[0].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -187,24 +173,19 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran esdtMetaData := txsFee.GetDefaultMetaData() esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - fungibleMetaData := txsFee.GetDefaultMetaData() - fungibleMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tokenIDs := [][]byte{ nftTokenID, sftTokenID, metaESDTTokenID, - fungibleTokenID, } tokensMetadata := []*txsFee.MetaData{ nftMetaData, sftMetaData, esdtMetaData, - fungibleMetaData, } - nonce := uint64(4) + nonce := uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) @@ -227,7 +208,6 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData) checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, shardID, fungibleMetaData) log.Info("Step 2. wait for DynamicEsdtFlag activation") @@ -270,7 +250,6 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData) checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, shardID, fungibleMetaData) log.Info("Step 5. make an updateTokenID@tokenID function call on the ESDTSystem SC for all token types") @@ -295,7 +274,6 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData) checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, shardID, fungibleMetaData) log.Info("Step 7. transfer the tokens to another account") @@ -341,9 +319,6 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) checkMetaDataNotInAcc(t, cs, addrs[2].Bytes, metaESDTTokenID, shardID) - - checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, shardID, fungibleMetaData) - checkMetaDataNotInAcc(t, cs, addrs[2].Bytes, fungibleTokenID, shardID) } func createAddresses( @@ -729,7 +704,7 @@ func setAddressEsdtRoles( // Test scenario #3 // -// Initial setup: Create fungible, NFT, SFT and metaESDT tokens +// Initial setup: Create NFT, SFT and metaESDT tokens // (after the activation of DynamicEsdtFlag) // // 1. check that the metaData for the NFT was saved in the user account and not on the system account @@ -746,7 +721,7 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { addrs := createAddresses(t, cs, false) - log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") + log.Info("Initial setup: Create NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") // issue metaESDT metaESDTTicker := []byte("METATTICKER") @@ -767,23 +742,9 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) - // issue fungible - fungibleTicker := []byte("FUNTICKER") - tx = issueTx(1, addrs[0].Bytes, fungibleTicker, baseIssuingCost) - - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - - fungibleTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], fungibleTokenID, roles) - - log.Info("Issued fungible token id", "tokenID", string(fungibleTokenID)) - // issue NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(2, addrs[0].Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -797,7 +758,7 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(3, addrs[0].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -813,7 +774,6 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { nftTokenID, sftTokenID, metaESDTTokenID, - fungibleTokenID, } nftMetaData := txsFee.GetDefaultMetaData() @@ -825,17 +785,13 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { esdtMetaData := txsFee.GetDefaultMetaData() esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - fungibleMetaData := txsFee.GetDefaultMetaData() - fungibleMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tokensMetadata := []*txsFee.MetaData{ nftMetaData, sftMetaData, esdtMetaData, - fungibleMetaData, } - nonce := uint64(4) + nonce := uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) @@ -864,9 +820,6 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, metaESDTTokenID, shardID) - - checkMetaData(t, cs, core.SystemAccountAddress, fungibleTokenID, shardID, fungibleMetaData) - checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, fungibleTokenID, shardID) } // Test scenario #4 @@ -885,7 +838,7 @@ func TestChainSimulator_ESDTMetaDataRecreate(t *testing.T) { cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() - log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") + log.Info("Initial setup: Create NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") addrs := createAddresses(t, cs, false) @@ -1044,7 +997,7 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() - log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") + log.Info("Initial setup: Create NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") addrs := createAddresses(t, cs, false) @@ -1202,7 +1155,7 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() - log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag). Register NFT directly as dynamic") + log.Info("Initial setup: Create NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag). Register NFT directly as dynamic") addrs := createAddresses(t, cs, false) @@ -2147,10 +2100,6 @@ func TestChainSimulator_ChangeMetaData(t *testing.T) { t.Run("metaESDT change metadata", func(t *testing.T) { testChainSimulatorChangeMetaData(t, issueMetaESDTTx) }) - - t.Run("fungible change metadata", func(t *testing.T) { - testChainSimulatorChangeMetaData(t, issueTx) - }) } type issueTxFunc func(uint64, []byte, []byte, string) *transaction.Transaction From a318cbc764ce8895d2d7b39483d6e41ec1852778 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 10 Jul 2024 22:00:02 +0300 Subject: [PATCH 413/503] updated mx-chain-vm-go to latest rc/v1.7.next1 --- cmd/node/config/gasSchedules/gasScheduleV1.toml | 1 + cmd/node/config/gasSchedules/gasScheduleV2.toml | 1 + cmd/node/config/gasSchedules/gasScheduleV3.toml | 1 + cmd/node/config/gasSchedules/gasScheduleV4.toml | 1 + cmd/node/config/gasSchedules/gasScheduleV5.toml | 1 + cmd/node/config/gasSchedules/gasScheduleV6.toml | 1 + cmd/node/config/gasSchedules/gasScheduleV7.toml | 1 + cmd/node/config/gasSchedules/gasScheduleV8.toml | 1 + go.mod | 2 +- go.sum | 4 ++-- 10 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cmd/node/config/gasSchedules/gasScheduleV1.toml b/cmd/node/config/gasSchedules/gasScheduleV1.toml index 5e715a2d466..7fca1d6a7d2 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV1.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV1.toml @@ -112,6 +112,7 @@ GetCallbackClosure = 10000 GetCodeMetadata = 10000 IsBuiltinFunction = 10000 + IsReservedFunctionName = 10000 [EthAPICost] UseGas = 100 diff --git a/cmd/node/config/gasSchedules/gasScheduleV2.toml b/cmd/node/config/gasSchedules/gasScheduleV2.toml index e0d1c4e366e..bfc53d1b91d 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV2.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV2.toml @@ -112,6 +112,7 @@ GetCallbackClosure = 10000 GetCodeMetadata = 10000 IsBuiltinFunction = 10000 + IsReservedFunctionName = 10000 [EthAPICost] UseGas = 100 diff --git a/cmd/node/config/gasSchedules/gasScheduleV3.toml b/cmd/node/config/gasSchedules/gasScheduleV3.toml index 8c3a763363e..eb88204bf5e 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV3.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV3.toml @@ -112,6 +112,7 @@ GetCallbackClosure = 10000 GetCodeMetadata = 10000 IsBuiltinFunction = 10000 + IsReservedFunctionName = 10000 [EthAPICost] UseGas = 100 diff --git a/cmd/node/config/gasSchedules/gasScheduleV4.toml b/cmd/node/config/gasSchedules/gasScheduleV4.toml index 4d178ff0fd5..f41a7a8d940 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV4.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV4.toml @@ -112,6 +112,7 @@ GetCallbackClosure = 10000 GetCodeMetadata = 10000 IsBuiltinFunction = 10000 + IsReservedFunctionName = 10000 [EthAPICost] UseGas = 100 diff --git a/cmd/node/config/gasSchedules/gasScheduleV5.toml b/cmd/node/config/gasSchedules/gasScheduleV5.toml index e5f5035bb17..34b4336b32c 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV5.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV5.toml @@ -112,6 +112,7 @@ GetCallbackClosure = 10000 GetCodeMetadata = 10000 IsBuiltinFunction = 10000 + IsReservedFunctionName = 10000 [EthAPICost] UseGas = 100 diff --git a/cmd/node/config/gasSchedules/gasScheduleV6.toml b/cmd/node/config/gasSchedules/gasScheduleV6.toml index f41c5002b85..99ff15c8482 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV6.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV6.toml @@ -112,6 +112,7 @@ GetCallbackClosure = 10000 GetCodeMetadata = 10000 IsBuiltinFunction = 10000 + IsReservedFunctionName = 10000 [EthAPICost] UseGas = 100 diff --git a/cmd/node/config/gasSchedules/gasScheduleV7.toml b/cmd/node/config/gasSchedules/gasScheduleV7.toml index 6b580c893cc..250d89117cf 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV7.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV7.toml @@ -113,6 +113,7 @@ GetCallbackClosure = 10000 GetCodeMetadata = 10000 IsBuiltinFunction = 10000 + IsReservedFunctionName = 10000 [EthAPICost] UseGas = 100 diff --git a/cmd/node/config/gasSchedules/gasScheduleV8.toml b/cmd/node/config/gasSchedules/gasScheduleV8.toml index 424c07e79f2..7a0c11de4e9 100644 --- a/cmd/node/config/gasSchedules/gasScheduleV8.toml +++ b/cmd/node/config/gasSchedules/gasScheduleV8.toml @@ -113,6 +113,7 @@ GetCallbackClosure = 10000 GetCodeMetadata = 10000 IsBuiltinFunction = 10000 + IsReservedFunctionName = 10000 [EthAPICost] UseGas = 100 diff --git a/go.mod b/go.mod index 1b381e3a86f..70fd3bd037d 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240619122724-2bd2e64cebdc - github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1 + github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240704061008-9de107a0db23 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240509104009-598a37ff36b9 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98-0.20240509104102-2a6a709b4041 diff --git a/go.sum b/go.sum index f7cc76137bf..5c93002f8a3 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f 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.20240619122724-2bd2e64cebdc h1:KpLloX0pIclo3axCQVOm3wZE+U9cfeHgPWGvDuUohTk= github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240619122724-2bd2e64cebdc/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-go v1.5.30-0.20240704061008-9de107a0db23 h1:fGrQOGhPm7xofx0fpN5QQi+frhf0U5bI5+Rn04D9hjQ= +github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240704061008-9de107a0db23/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= From 5b283ae9fee19933670a74c6d1a0b7d6e6154d2c Mon Sep 17 00:00:00 2001 From: miiu Date: Thu, 11 Jul 2024 16:21:23 +0300 Subject: [PATCH 414/503] multi transfer --- go.mod | 2 +- go.sum | 4 +-- .../alteredaccounts/tokensProcessor.go | 27 +++++++++++++- .../alteredaccounts/tokensProcessor_test.go | 36 +++++++++++++++++++ 4 files changed, 65 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 6dfb3d0c7c0..c90387d5f04 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f - github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240619122724-2bd2e64cebdc + github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240711073837-9d5b724082b5 github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240509104009-598a37ff36b9 diff --git a/go.sum b/go.sum index 27c71b04923..d450e6648bc 100644 --- a/go.sum +++ b/go.sum @@ -399,8 +399,8 @@ 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.20240619122724-2bd2e64cebdc h1:KpLloX0pIclo3axCQVOm3wZE+U9cfeHgPWGvDuUohTk= -github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240619122724-2bd2e64cebdc/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo= +github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240711073837-9d5b724082b5 h1:xx0KtuMO7WizDrBarwozOQDUu69E9KLU7/FDj336uLw= +github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240711073837-9d5b724082b5/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= diff --git a/outport/process/alteredaccounts/tokensProcessor.go b/outport/process/alteredaccounts/tokensProcessor.go index bb0839ef44a..bc2ecedb8de 100644 --- a/outport/process/alteredaccounts/tokensProcessor.go +++ b/outport/process/alteredaccounts/tokensProcessor.go @@ -1,6 +1,7 @@ package alteredaccounts import ( + vmcommon "github.com/multiversx/mx-chain-vm-common-go" "math/big" "github.com/multiversx/mx-chain-core-go/core" @@ -116,7 +117,7 @@ func (tp *tokensProcessor) processMultiTransferEvent(event data.EventHandler, ma // N = len(topics) // i := 0; i < N-1; i+=3 // { - // topics[i] --- token identifier + // topics[i] --- token identifier or EGLD token identifier // topics[i+1] --- token nonce // topics[i+2] --- transferred value // } @@ -133,6 +134,12 @@ func (tp *tokensProcessor) processMultiTransferEvent(event data.EventHandler, ma for i := 0; i < numOfTopics-1; i += 3 { tokenID := topics[i] nonceBigInt := big.NewInt(0).SetBytes(topics[i+1]) + + if string(tokenID) == vmcommon.EGLDIdentifier { + tp.processNativeEGLDTransferWithMultiTransfer(destinationAddress, markedAlteredAccounts) + return + } + // process event for the sender address tp.processEsdtDataForAddress(address, nonceBigInt, string(tokenID), markedAlteredAccounts, false) @@ -177,6 +184,24 @@ func (tp *tokensProcessor) processEsdtDataForAddress( } } +func (tp *tokensProcessor) processNativeEGLDTransferWithMultiTransfer(address []byte, markedAlteredAccounts map[string]*markedAlteredAccount) { + if !tp.isSameShard(address) { + return + } + + addressStr := string(address) + _, addressAlreadySelected := markedAlteredAccounts[addressStr] + if addressAlreadySelected { + markedAlteredAccounts[addressStr].balanceChanged = true + return + } + + markedAlteredAccounts[addressStr] = &markedAlteredAccount{ + balanceChanged: true, + } + +} + func (tp *tokensProcessor) isSameShard(address []byte) bool { return tp.shardCoordinator.SelfId() == tp.shardCoordinator.ComputeId(address) } diff --git a/outport/process/alteredaccounts/tokensProcessor_test.go b/outport/process/alteredaccounts/tokensProcessor_test.go index a7a6a65af96..9ee7467b911 100644 --- a/outport/process/alteredaccounts/tokensProcessor_test.go +++ b/outport/process/alteredaccounts/tokensProcessor_test.go @@ -1,6 +1,7 @@ package alteredaccounts import ( + vmcommon "github.com/multiversx/mx-chain-vm-common-go" "math/big" "testing" @@ -61,3 +62,38 @@ func TestTokenProcessorProcessEventMultiTransferV2(t *testing.T) { require.Equal(t, markedAccount, markedAccounts["addr"]) require.Equal(t, markedAccount, markedAccounts["receiver"]) } + +func TestTokenProcessorProcessEventMultiTransferV2WithEGLD(t *testing.T) { + t.Parallel() + + tp := newTokensProcessor(&mock.ShardCoordinatorStub{}) + + markedAccounts := make(map[string]*markedAlteredAccount) + tp.processEvent(&transaction.Event{ + Identifier: []byte(core.BuiltInFunctionMultiESDTNFTTransfer), + Address: []byte("addr"), + Topics: [][]byte{[]byte("token1"), big.NewInt(0).Bytes(), []byte("2"), []byte(vmcommon.EGLDIdentifier), big.NewInt(0).Bytes(), []byte("3"), []byte("receiver")}, + }, markedAccounts) + + require.Equal(t, 2, len(markedAccounts)) + markedAccount1 := &markedAlteredAccount{ + tokens: map[string]*markedAlteredAccountToken{ + "token1": { + identifier: "token1", + nonce: 0, + }, + }, + } + require.Equal(t, markedAccount1, markedAccounts["addr"]) + + markedAccount2 := &markedAlteredAccount{ + balanceChanged: true, + tokens: map[string]*markedAlteredAccountToken{ + "token1": { + identifier: "token1", + nonce: 0, + }, + }, + } + require.Equal(t, markedAccount2, markedAccounts["receiver"]) +} From 43a40414f00e54bcfb43daac3c311b237acc23f8 Mon Sep 17 00:00:00 2001 From: miiu Date: Thu, 11 Jul 2024 16:21:48 +0300 Subject: [PATCH 415/503] fix imports --- outport/process/alteredaccounts/tokensProcessor.go | 2 +- outport/process/alteredaccounts/tokensProcessor_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/outport/process/alteredaccounts/tokensProcessor.go b/outport/process/alteredaccounts/tokensProcessor.go index bc2ecedb8de..687c543bcdf 100644 --- a/outport/process/alteredaccounts/tokensProcessor.go +++ b/outport/process/alteredaccounts/tokensProcessor.go @@ -1,13 +1,13 @@ package alteredaccounts import ( - vmcommon "github.com/multiversx/mx-chain-vm-common-go" "math/big" "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data" outportcore "github.com/multiversx/mx-chain-core-go/data/outport" "github.com/multiversx/mx-chain-go/sharding" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) const ( diff --git a/outport/process/alteredaccounts/tokensProcessor_test.go b/outport/process/alteredaccounts/tokensProcessor_test.go index 9ee7467b911..af737a1de94 100644 --- a/outport/process/alteredaccounts/tokensProcessor_test.go +++ b/outport/process/alteredaccounts/tokensProcessor_test.go @@ -1,13 +1,13 @@ package alteredaccounts import ( - vmcommon "github.com/multiversx/mx-chain-vm-common-go" "math/big" "testing" "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/process/mock" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/stretchr/testify/require" ) From 0e64a75bea5e84744def337854ecbec22e13968a Mon Sep 17 00:00:00 2001 From: miiu Date: Thu, 11 Jul 2024 16:53:41 +0300 Subject: [PATCH 416/503] new indexer version --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index c90387d5f04..b477749d353 100644 --- a/go.mod +++ b/go.mod @@ -15,9 +15,9 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e - github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703135649-550eebfbc10b + github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703140829-626328c91a8d github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df - github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619122842-05143459c554 + github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240708091128-643032ac245a github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f diff --git a/go.sum b/go.sum index d450e6648bc..9d36df90dad 100644 --- a/go.sum +++ b/go.sum @@ -387,12 +387,12 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY 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.20240703135649-550eebfbc10b h1:bmN8RtaWC/7lQenavRVVY5NrAPOdh3N9tGyxqVrx2qU= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703135649-550eebfbc10b/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703140829-626328c91a8d h1:2x1arnxYt28ZlDAZj61dzmG4NqoUmAZbe3pTFsBZHek= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703140829-626328c91a8d/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.20240619122842-05143459c554 h1:Fv8BfzJSzdovmoh9Jh/by++0uGsOVBlMP3XiN5Svkn4= -github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619122842-05143459c554/go.mod h1:yMq9q5VdN7jBaErRGQ0T8dkZwbBtfQYmqGbD/Ese1us= +github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240708091128-643032ac245a h1:zn8wCK9Hyge0hm76hUUWhuFkpjitj3P+gjpiTdgU150= +github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240708091128-643032ac245a/go.mod h1:rEQ0HPBp0Rg7in8TrC+vncV03yyWWTSTur2sbVGUtUw= 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= From 133f5213f70d9808fe463dcd6241ec6326d43b20 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Fri, 12 Jul 2024 10:11:39 +0300 Subject: [PATCH 417/503] added egld with multi transfer scenario --- .../vm/egldMultiTransfer_test.go | 234 ++++++++++++++++++ 1 file changed, 234 insertions(+) create mode 100644 integrationTests/chainSimulator/vm/egldMultiTransfer_test.go diff --git a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go new file mode 100644 index 00000000000..54efde0469f --- /dev/null +++ b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go @@ -0,0 +1,234 @@ +package vm + +import ( + "encoding/hex" + "math/big" + "strings" + "testing" + "time" + + "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee" + "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" + "github.com/multiversx/mx-chain-go/node/chainSimulator" + "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" + "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" + "github.com/stretchr/testify/require" +) + +func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(4) + + baseIssuingCost := "1000" + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: true, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.EGLDInMultiTransferEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + addrs := createAddresses(t, cs, false) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (before the activation of DynamicEsdtFlag)") + + // issue metaESDT + metaESDTTicker := []byte("METATTICKER") + tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + metaESDTTokenID := txResult.Logs.Events[0].Topics[0] + + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + } + setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + + log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) + + // issue NFT + nftTicker := []byte("NFTTICKER") + tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) + + // issue SFT + sftTicker := []byte("SFTTICKER") + tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + sftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + + log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + sftMetaData := txsFee.GetDefaultMetaData() + sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + esdtMetaData := txsFee.GetDefaultMetaData() + esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tokenIDs := [][]byte{ + nftTokenID, + sftTokenID, + metaESDTTokenID, + } + + tokensMetadata := []*txsFee.MetaData{ + nftMetaData, + sftMetaData, + esdtMetaData, + } + + nonce := uint64(3) + for i := range tokenIDs { + tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + account0, err := cs.GetAccount(addrs[0]) + require.Nil(t, err) + + beforeBalanceStr := account0.Balance + + egldValue := oneEGLD.Mul(oneEGLD, big.NewInt(3)) + tx = multiESDTNFTTransferWithEGLDTx(nonce, addrs[0].Bytes, addrs[1].Bytes, tokenIDs, egldValue) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + account0, err = cs.GetAccount(addrs[0]) + require.Nil(t, err) + + beforeBalance, _ := big.NewInt(0).SetString(beforeBalanceStr, 10) + + expectedBalance := big.NewInt(0).Sub(beforeBalance, egldValue) + txsFee, _ := big.NewInt(0).SetString(txResult.Fee, 10) + expectedBalanceWithFee := big.NewInt(0).Sub(expectedBalance, txsFee) + + require.Equal(t, expectedBalanceWithFee.String(), account0.Balance) +} + +func multiESDTNFTTransferWithEGLDTx(nonce uint64, sndAdr, rcvAddr []byte, tokens [][]byte, egldValue *big.Int) *transaction.Transaction { + transferData := make([]*utils.TransferESDTData, 0) + + for _, tokenID := range tokens { + transferData = append(transferData, &utils.TransferESDTData{ + Token: tokenID, + Nonce: 1, + Value: big.NewInt(1), + }) + } + + numTransfers := len(tokens) + encodedReceiver := hex.EncodeToString(rcvAddr) + hexEncodedNumTransfers := hex.EncodeToString(big.NewInt(int64(numTransfers)).Bytes()) + hexEncodedEGLD := hex.EncodeToString([]byte("EGLD-000000")) + hexEncodedEGLDNonce := "00" + + txDataField := []byte(strings.Join( + []string{ + core.BuiltInFunctionMultiESDTNFTTransfer, + encodedReceiver, + hexEncodedNumTransfers, + hexEncodedEGLD, + hexEncodedEGLDNonce, + hex.EncodeToString(egldValue.Bytes()), + }, "@"), + ) + + for _, td := range transferData { + hexEncodedToken := hex.EncodeToString(td.Token) + esdtValueEncoded := hex.EncodeToString(td.Value.Bytes()) + hexEncodedNonce := "00" + if td.Nonce != 0 { + hexEncodedNonce = hex.EncodeToString(big.NewInt(int64(td.Nonce)).Bytes()) + } + + txDataField = []byte(strings.Join([]string{string(txDataField), hexEncodedToken, hexEncodedNonce, esdtValueEncoded}, "@")) + } + + tx := &transaction.Transaction{ + Nonce: nonce, + SndAddr: sndAdr, + RcvAddr: sndAdr, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Data: txDataField, + Value: big.NewInt(0), + Version: 1, + Signature: []byte("dummySig"), + ChainID: []byte(configs.ChainID), + } + + return tx +} From 3919cc194fe76168d30aa367911a6b189be0f28b Mon Sep 17 00:00:00 2001 From: ssd04 Date: Fri, 12 Jul 2024 13:06:06 +0300 Subject: [PATCH 418/503] check account received balance --- .../vm/egldMultiTransfer_test.go | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go index 54efde0469f..aa540399336 100644 --- a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go +++ b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go @@ -152,7 +152,12 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { account0, err := cs.GetAccount(addrs[0]) require.Nil(t, err) - beforeBalanceStr := account0.Balance + beforeBalanceStr0 := account0.Balance + + account1, err := cs.GetAccount(addrs[1]) + require.Nil(t, err) + + beforeBalanceStr1 := account1.Balance egldValue := oneEGLD.Mul(oneEGLD, big.NewInt(3)) tx = multiESDTNFTTransferWithEGLDTx(nonce, addrs[0].Bytes, addrs[1].Bytes, tokenIDs, egldValue) @@ -166,16 +171,25 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { err = cs.GenerateBlocks(10) require.Nil(t, err) + // check accounts balance account0, err = cs.GetAccount(addrs[0]) require.Nil(t, err) - beforeBalance, _ := big.NewInt(0).SetString(beforeBalanceStr, 10) + beforeBalance0, _ := big.NewInt(0).SetString(beforeBalanceStr0, 10) - expectedBalance := big.NewInt(0).Sub(beforeBalance, egldValue) + expectedBalance0 := big.NewInt(0).Sub(beforeBalance0, egldValue) txsFee, _ := big.NewInt(0).SetString(txResult.Fee, 10) - expectedBalanceWithFee := big.NewInt(0).Sub(expectedBalance, txsFee) + expectedBalanceWithFee0 := big.NewInt(0).Sub(expectedBalance0, txsFee) + + require.Equal(t, expectedBalanceWithFee0.String(), account0.Balance) + + account1, err = cs.GetAccount(addrs[1]) + require.Nil(t, err) + + beforeBalance1, _ := big.NewInt(0).SetString(beforeBalanceStr1, 10) + expectedBalance1 := big.NewInt(0).Add(beforeBalance1, egldValue) - require.Equal(t, expectedBalanceWithFee.String(), account0.Balance) + require.Equal(t, expectedBalance1.String(), account1.Balance) } func multiESDTNFTTransferWithEGLDTx(nonce uint64, sndAdr, rcvAddr []byte, tokens [][]byte, egldValue *big.Int) *transaction.Transaction { From ac70201580e16441015378504c285310c3a3b83d Mon Sep 17 00:00:00 2001 From: ssd04 Date: Fri, 12 Jul 2024 13:44:57 +0300 Subject: [PATCH 419/503] check egld log event --- integrationTests/chainSimulator/vm/egldMultiTransfer_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go index aa540399336..1b97077f5d0 100644 --- a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go +++ b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go @@ -168,6 +168,9 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) + egldLog := string(txResult.Logs.Events[0].Topics[0]) + require.Equal(t, "EGLD-000000", egldLog) + err = cs.GenerateBlocks(10) require.Nil(t, err) From 3d878ba5f0f3f2694fe3a765f6bc88050ab249e8 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Fri, 12 Jul 2024 14:56:23 +0300 Subject: [PATCH 420/503] issue token with egld ticker --- .../vm/egldMultiTransfer_test.go | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go index 1b97077f5d0..81a1768c2a7 100644 --- a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go +++ b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go @@ -249,3 +249,96 @@ func multiESDTNFTTransferWithEGLDTx(nonce uint64, sndAdr, rcvAddr []byte, tokens return tx } + +func TestChainSimulator_IssueToken_EGLDTicker(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(4) + + baseIssuingCost := "1000" + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: true, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.EGLDInMultiTransferEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + addrs := createAddresses(t, cs, false) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch) - 1) + require.Nil(t, err) + + log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (before the activation of DynamicEsdtFlag)") + + // issue NFT + nftTicker := []byte("EGLD") + tx := issueNonFungibleTx(0, addrs[0].Bytes, nftTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nftTokenID := txResult.Logs.Events[0].Topics[0] + + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + } + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + // should fail issuing token with EGLD ticker + tx = issueNonFungibleTx(2, addrs[0].Bytes, nftTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.NotEqual(t, "success", txResult.Status.String()) +} From 395238708ec9c3a14c5e1a052090dcc86096efbb Mon Sep 17 00:00:00 2001 From: radu chis Date: Fri, 12 Jul 2024 16:46:11 +0300 Subject: [PATCH 421/503] retured always blockInfo --- node/node.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/node/node.go b/node/node.go index d4261330b28..6d83411350a 100644 --- a/node/node.go +++ b/node/node.go @@ -290,20 +290,20 @@ func (n *Node) GetKeyValuePairs(address string, options api.AccountQueryOptions, return make(map[string]string), adaptedBlockInfo, nil } - return nil, api.BlockInfo{}, err + return nil, blockInfo, err } if check.IfNil(userAccount.DataTrie()) { - return map[string]string{}, api.BlockInfo{}, nil + return map[string]string{}, blockInfo, nil } mapToReturn, err := n.getKeys(userAccount, ctx) if err != nil { - return nil, api.BlockInfo{}, err + return nil, blockInfo, err } if common.IsContextDone(ctx) { - return nil, api.BlockInfo{}, ErrTrieOperationsTimeout + return nil, blockInfo, ErrTrieOperationsTimeout } return mapToReturn, blockInfo, nil From e520f75f28016a1af5974788eba9d91eee766844 Mon Sep 17 00:00:00 2001 From: radu chis Date: Fri, 12 Jul 2024 17:07:40 +0300 Subject: [PATCH 422/503] if error return empty blockInfo --- node/node.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/node/node.go b/node/node.go index 6d83411350a..e9bc7094ff1 100644 --- a/node/node.go +++ b/node/node.go @@ -290,7 +290,7 @@ func (n *Node) GetKeyValuePairs(address string, options api.AccountQueryOptions, return make(map[string]string), adaptedBlockInfo, nil } - return nil, blockInfo, err + return nil, api.BlockInfo{}, err } if check.IfNil(userAccount.DataTrie()) { @@ -299,11 +299,11 @@ func (n *Node) GetKeyValuePairs(address string, options api.AccountQueryOptions, mapToReturn, err := n.getKeys(userAccount, ctx) if err != nil { - return nil, blockInfo, err + return nil, api.BlockInfo{}, err } if common.IsContextDone(ctx) { - return nil, blockInfo, ErrTrieOperationsTimeout + return nil, api.BlockInfo{}, ErrTrieOperationsTimeout } return mapToReturn, blockInfo, nil From c0c5019000e5762cfadb34f5367bb697b475f370 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 15 Jul 2024 12:56:47 +0300 Subject: [PATCH 423/503] proper update of vm-go --- process/smartContract/processorV2/vmInputV2.go | 6 ++++++ vm/systemSmartContracts/esdt.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/process/smartContract/processorV2/vmInputV2.go b/process/smartContract/processorV2/vmInputV2.go index 35e68776907..06c4c3f0ad2 100644 --- a/process/smartContract/processorV2/vmInputV2.go +++ b/process/smartContract/processorV2/vmInputV2.go @@ -39,6 +39,12 @@ func (sc *scProcessor) initializeVMInputFromTx(vmInput *vmcommon.VMInput, tx dat vmInput.CallerAddr = tx.GetSndAddr() vmInput.CallValue = new(big.Int).Set(tx.GetValue()) vmInput.GasPrice = tx.GetGasPrice() + + relayedTx, isRelayed := isRelayedTx(tx) + if isRelayed { + vmInput.RelayerAddr = relayedTx.RelayerAddr + } + vmInput.GasProvided, err = sc.prepareGasProvided(tx) if err != nil { return err diff --git a/vm/systemSmartContracts/esdt.go b/vm/systemSmartContracts/esdt.go index 6852dbf04fc..5daa2f2eb19 100644 --- a/vm/systemSmartContracts/esdt.go +++ b/vm/systemSmartContracts/esdt.go @@ -42,6 +42,7 @@ const canTransferNFTCreateRole = "canTransferNFTCreateRole" const upgradable = "canUpgrade" const canCreateMultiShard = "canCreateMultiShard" const upgradeProperties = "upgradeProperties" +const eGLD = "EGLD" const conversionBase = 10 @@ -723,6 +724,11 @@ func isTokenNameHumanReadable(tokenName []byte) bool { } func (e *esdt) createNewTokenIdentifier(caller []byte, ticker []byte) ([]byte, error) { + if e.enableEpochsHandler.IsFlagEnabled(common.EGLDInESDTMultiTransferFlag) { + if bytes.Equal(ticker, []byte(eGLD)) { + return nil, vm.ErrCouldNotCreateNewTokenIdentifier + } + } newRandomBase := append(caller, e.eei.BlockChainHook().CurrentRandomSeed()...) newRandom := e.hasher.Compute(string(newRandomBase)) newRandomForTicker := newRandom[:tickerRandomSequenceLength] From 2ff7e6c8c235c98b33c6929fcb2a6153030cc8e5 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Mon, 15 Jul 2024 13:49:29 +0300 Subject: [PATCH 424/503] fix log messages --- .../chainSimulator/vm/egldMultiTransfer_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go index 81a1768c2a7..a8862217991 100644 --- a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go +++ b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go @@ -63,8 +63,6 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) require.Nil(t, err) - log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (before the activation of DynamicEsdtFlag)") - // issue metaESDT metaESDTTicker := []byte("METATTICKER") tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) @@ -295,7 +293,7 @@ func TestChainSimulator_IssueToken_EGLDTicker(t *testing.T) { err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch) - 1) require.Nil(t, err) - log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (before the activation of DynamicEsdtFlag)") + log.Info("Initial setup: Issue token (before the activation of EGLDInMultiTransferFlag)") // issue NFT nftTicker := []byte("EGLD") @@ -333,6 +331,8 @@ func TestChainSimulator_IssueToken_EGLDTicker(t *testing.T) { err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) require.Nil(t, err) + log.Info("Issue token (after activation of EGLDInMultiTransferFlag)") + // should fail issuing token with EGLD ticker tx = issueNonFungibleTx(2, addrs[0].Bytes, nftTicker, baseIssuingCost) From 51f530b63459fa93789736a799e0ec02474083f9 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Mon, 15 Jul 2024 14:14:42 +0300 Subject: [PATCH 425/503] update dependencies --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 8faffcd1519..8ea57d19fbf 100644 --- a/go.mod +++ b/go.mod @@ -21,8 +21,8 @@ require ( github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f - github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240619122724-2bd2e64cebdc - github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240704061008-9de107a0db23 + github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240715100647-8ce0ec25ff1d + github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240715111121-ec175dad3ac8 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240509104009-598a37ff36b9 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98-0.20240509104102-2a6a709b4041 diff --git a/go.sum b/go.sum index 0fab89453cd..5c81848fe6c 100644 --- a/go.sum +++ b/go.sum @@ -399,10 +399,10 @@ 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.20240619122724-2bd2e64cebdc h1:KpLloX0pIclo3axCQVOm3wZE+U9cfeHgPWGvDuUohTk= -github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240619122724-2bd2e64cebdc/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo= -github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240704061008-9de107a0db23 h1:fGrQOGhPm7xofx0fpN5QQi+frhf0U5bI5+Rn04D9hjQ= -github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240704061008-9de107a0db23/go.mod h1:N3Oa8QeeHlSip4nbESQpVSLgi/WxtgIwvqfXIZm6gDs= +github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240715100647-8ce0ec25ff1d h1:GqwJaWDgWFuHx4AsUBMwpHWzY4afyTbWBk0nwYG6lsY= +github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240715100647-8ce0ec25ff1d/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo= +github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240715111121-ec175dad3ac8 h1:yWqReDIF3P7Y37nonIip7uVVUERFCJIWlIvM3G2qb38= +github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240715111121-ec175dad3ac8/go.mod h1:AKygEQlZe9F2YdO8VKK8QCWb7UTCuN2KclFcEfFo0m4= 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= From b5fdc84a1d0719ff7cd864218b0d0e4409f7ea82 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 16 Jul 2024 12:40:27 +0300 Subject: [PATCH 426/503] update test error check --- .../chainSimulator/vm/egldMultiTransfer_test.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go index a8862217991..6aa5f6dfda9 100644 --- a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go +++ b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go @@ -15,6 +15,7 @@ import ( "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" + "github.com/multiversx/mx-chain-go/vm" "github.com/stretchr/testify/require" ) @@ -325,10 +326,10 @@ func TestChainSimulator_IssueToken_EGLDTicker(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) - err = cs.GenerateBlocks(10) + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) require.Nil(t, err) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + err = cs.GenerateBlocks(10) require.Nil(t, err) log.Info("Issue token (after activation of EGLDInMultiTransferFlag)") @@ -340,5 +341,8 @@ func TestChainSimulator_IssueToken_EGLDTicker(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - require.NotEqual(t, "success", txResult.Status.String()) + errMessage := string(txResult.Logs.Events[0].Topics[1]) + require.Equal(t, vm.ErrCouldNotCreateNewTokenIdentifier.Error(), errMessage) + + require.Equal(t, "success", txResult.Status.String()) } From 0a13356221e5f81b2696679be489d0c900a7ece7 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 16 Jul 2024 16:16:23 +0300 Subject: [PATCH 427/503] added more scenarios --- .../vm/egldMultiTransfer_test.go | 258 ++++++++++++++++++ 1 file changed, 258 insertions(+) diff --git a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go index 6aa5f6dfda9..72a30420827 100644 --- a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go +++ b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go @@ -2,6 +2,7 @@ package vm import ( "encoding/hex" + "fmt" "math/big" "strings" "testing" @@ -194,6 +195,263 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { require.Equal(t, expectedBalance1.String(), account1.Balance) } +func TestChainSimulator_EGLD_MultiTransfer_Insufficient_Funds(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(4) + + baseIssuingCost := "1000" + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: true, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.EGLDInMultiTransferEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + addrs := createAddresses(t, cs, false) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + // issue NFT + nftTicker := []byte("NFTTICKER") + tx := issueNonFungibleTx(0, addrs[0].Bytes, nftTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nftTokenID := txResult.Logs.Events[0].Topics[0] + + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + } + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + account0, err := cs.GetAccount(addrs[0]) + require.Nil(t, err) + + beforeBalanceStr0 := account0.Balance + + egldValue, _ := big.NewInt(0).SetString(beforeBalanceStr0, 10) + egldValue = egldValue.Add(egldValue, big.NewInt(13)) + tx = multiESDTNFTTransferWithEGLDTx(2, addrs[0].Bytes, addrs[1].Bytes, [][]byte{nftTokenID}, egldValue) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.NotEqual(t, "success", txResult.Status.String()) + + eventLog := string(txResult.Logs.Events[0].Topics[1]) + require.Equal(t, "insufficient funds for token EGLD-000000", eventLog) +} + +func TestChainSimulator_Multiple_EGLD_Transfers(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(4) + + baseIssuingCost := "1000" + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: true, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.EGLDInMultiTransferEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + addrs := createAddresses(t, cs, false) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + // issue NFT + nftTicker := []byte("NFTTICKER") + tx := issueNonFungibleTx(0, addrs[0].Bytes, nftTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nftTokenID := txResult.Logs.Events[0].Topics[0] + + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + } + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + account0, err := cs.GetAccount(addrs[0]) + require.Nil(t, err) + + beforeBalanceStr0 := account0.Balance + + account1, err := cs.GetAccount(addrs[1]) + require.Nil(t, err) + + beforeBalanceStr1 := account1.Balance + + // multi nft transfer with multiple EGLD-000000 tokens + numTransfers := 3 + encodedReceiver := hex.EncodeToString(addrs[1].Bytes) + egldValue := oneEGLD.Mul(oneEGLD, big.NewInt(3)) + + txDataField := []byte(strings.Join( + []string{ + core.BuiltInFunctionMultiESDTNFTTransfer, + encodedReceiver, + hex.EncodeToString(big.NewInt(int64(numTransfers)).Bytes()), + hex.EncodeToString([]byte("EGLD-000000")), + "00", + hex.EncodeToString(egldValue.Bytes()), + hex.EncodeToString(nftTokenID), + hex.EncodeToString(big.NewInt(1).Bytes()), + hex.EncodeToString(big.NewInt(int64(1)).Bytes()), + hex.EncodeToString([]byte("EGLD-000000")), + "00", + hex.EncodeToString(egldValue.Bytes()), + }, "@"), + ) + + tx = &transaction.Transaction{ + Nonce: 2, + SndAddr: addrs[0].Bytes, + RcvAddr: addrs[0].Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Data: txDataField, + Value: big.NewInt(0), + Version: 1, + Signature: []byte("dummySig"), + ChainID: []byte(configs.ChainID), + } + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) + + // check accounts balance + account0, err = cs.GetAccount(addrs[0]) + require.Nil(t, err) + + beforeBalance0, _ := big.NewInt(0).SetString(beforeBalanceStr0, 10) + + expectedBalance0 := big.NewInt(0).Sub(beforeBalance0, egldValue) + expectedBalance0 = big.NewInt(0).Sub(expectedBalance0, egldValue) + txsFee, _ := big.NewInt(0).SetString(txResult.Fee, 10) + expectedBalanceWithFee0 := big.NewInt(0).Sub(expectedBalance0, txsFee) + + require.Equal(t, expectedBalanceWithFee0.String(), account0.Balance) + + account1, err = cs.GetAccount(addrs[1]) + require.Nil(t, err) + + beforeBalance1, _ := big.NewInt(0).SetString(beforeBalanceStr1, 10) + expectedBalance1 := big.NewInt(0).Add(beforeBalance1, egldValue) + expectedBalance1 = big.NewInt(0).Add(expectedBalance1, egldValue) + + require.Equal(t, expectedBalance1.String(), account1.Balance) +} + func multiESDTNFTTransferWithEGLDTx(nonce uint64, sndAdr, rcvAddr []byte, tokens [][]byte, egldValue *big.Int) *transaction.Transaction { transferData := make([]*utils.TransferESDTData, 0) From 382a6b82252023f8459c11d38c3a2a75b481d0df Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 17 Jul 2024 11:14:48 +0300 Subject: [PATCH 428/503] extra parameter chain simulator --- node/chainSimulator/chainSimulator.go | 36 ++++++++++--------- node/chainSimulator/components/nodeFacade.go | 4 +-- .../components/testOnlyProcessingNode.go | 3 +- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index 8004d629b2f..742d040c8c8 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -42,22 +42,23 @@ type transactionWithResult struct { // ArgsChainSimulator holds the arguments needed to create a new instance of simulator type ArgsChainSimulator struct { - BypassTxSignatureCheck bool - TempDir string - PathToInitialConfig string - NumOfShards uint32 - MinNodesPerShard uint32 - MetaChainMinNodes uint32 - NumNodesWaitingListShard uint32 - NumNodesWaitingListMeta uint32 - GenesisTimestamp int64 - InitialRound int64 - InitialEpoch uint32 - InitialNonce uint64 - RoundDurationInMillis uint64 - RoundsPerEpoch core.OptionalUint64 - ApiInterface components.APIConfigurator - AlterConfigsFunction func(cfg *config.Configs) + BypassTxSignatureCheck bool + TempDir string + PathToInitialConfig string + NumOfShards uint32 + MinNodesPerShard uint32 + MetaChainMinNodes uint32 + NumNodesWaitingListShard uint32 + NumNodesWaitingListMeta uint32 + GenesisTimestamp int64 + InitialRound int64 + InitialEpoch uint32 + InitialNonce uint64 + RoundDurationInMillis uint64 + RoundsPerEpoch core.OptionalUint64 + ApiInterface components.APIConfigurator + AlterConfigsFunction func(cfg *config.Configs) + VmQueryDelayAfterStartInMs uint64 } // ArgsBaseChainSimulator holds the arguments needed to create a new instance of simulator @@ -156,7 +157,7 @@ func (s *simulator) createChainHandlers(args ArgsBaseChainSimulator) error { } allValidatorsInfo, errGet := node.GetProcessComponents().ValidatorsStatistics().GetValidatorInfoForRootHash(currentRootHash) - if errRootHash != nil { + if errGet != nil { return errGet } @@ -212,6 +213,7 @@ func (s *simulator) createTestNode( MinNodesMeta: args.MetaChainMinNodes, MetaChainConsensusGroupSize: args.MetaChainConsensusGroupSize, RoundDurationInMillis: args.RoundDurationInMillis, + VmQueryDelayAfterStartInMs: args.VmQueryDelayAfterStartInMs, } return components.NewTestOnlyProcessingNode(argsTestOnlyProcessorNode) diff --git a/node/chainSimulator/components/nodeFacade.go b/node/chainSimulator/components/nodeFacade.go index 7ed67018579..d62814fdf03 100644 --- a/node/chainSimulator/components/nodeFacade.go +++ b/node/chainSimulator/components/nodeFacade.go @@ -18,7 +18,7 @@ import ( "github.com/multiversx/mx-chain-go/process/mock" ) -func (node *testOnlyProcessingNode) createFacade(configs config.Configs, apiInterface APIConfigurator) error { +func (node *testOnlyProcessingNode) createFacade(configs config.Configs, apiInterface APIConfigurator, vmQueryDelayAfterStartInMs uint64) error { log.Debug("creating api resolver structure") err := node.createMetrics(configs) @@ -39,7 +39,7 @@ func (node *testOnlyProcessingNode) createFacade(configs config.Configs, apiInte allowVMQueriesChan := make(chan struct{}) go func() { - time.Sleep(time.Second) + time.Sleep(time.Duration(vmQueryDelayAfterStartInMs) * time.Millisecond) close(allowVMQueriesChan) node.StatusCoreComponents.AppStatusHandler().SetStringValue(common.MetricAreVMQueriesReady, strconv.FormatBool(true)) }() diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index f74598ce666..20e2f7402c6 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -49,6 +49,7 @@ type ArgsTestOnlyProcessingNode struct { MinNodesMeta uint32 MetaChainConsensusGroupSize uint32 RoundDurationInMillis uint64 + VmQueryDelayAfterStartInMs uint64 } type testOnlyProcessingNode struct { @@ -233,7 +234,7 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces return nil, err } - err = instance.createFacade(args.Configs, args.APIInterface) + err = instance.createFacade(args.Configs, args.APIInterface, args.VmQueryDelayAfterStartInMs) if err != nil { return nil, err } From 5c065c7077084e37720d4c32fb1c230331b76002 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 17 Jul 2024 12:47:38 +0300 Subject: [PATCH 429/503] fixes after review --- .../vm/egldMultiTransfer_test.go | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go index 72a30420827..e2c1c8019af 100644 --- a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go +++ b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go @@ -2,7 +2,6 @@ package vm import ( "encoding/hex" - "fmt" "math/big" "strings" "testing" @@ -278,6 +277,11 @@ func TestChainSimulator_EGLD_MultiTransfer_Insufficient_Funds(t *testing.T) { beforeBalanceStr0 := account0.Balance + account1, err := cs.GetAccount(addrs[1]) + require.Nil(t, err) + + beforeBalanceStr1 := account1.Balance + egldValue, _ := big.NewInt(0).SetString(beforeBalanceStr0, 10) egldValue = egldValue.Add(egldValue, big.NewInt(13)) tx = multiESDTNFTTransferWithEGLDTx(2, addrs[0].Bytes, addrs[1].Bytes, [][]byte{nftTokenID}, egldValue) @@ -286,14 +290,26 @@ func TestChainSimulator_EGLD_MultiTransfer_Insufficient_Funds(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.NotEqual(t, "success", txResult.Status.String()) eventLog := string(txResult.Logs.Events[0].Topics[1]) require.Equal(t, "insufficient funds for token EGLD-000000", eventLog) + + // check accounts balance + account0, err = cs.GetAccount(addrs[0]) + require.Nil(t, err) + + beforeBalance0, _ := big.NewInt(0).SetString(beforeBalanceStr0, 10) + + txsFee, _ := big.NewInt(0).SetString(txResult.Fee, 10) + expectedBalanceWithFee0 := big.NewInt(0).Sub(beforeBalance0, txsFee) + + require.Equal(t, expectedBalanceWithFee0.String(), account0.Balance) + + account1, err = cs.GetAccount(addrs[1]) + require.Nil(t, err) + + require.Equal(t, beforeBalanceStr1, account1.Balance) } func TestChainSimulator_Multiple_EGLD_Transfers(t *testing.T) { @@ -423,10 +439,6 @@ func TestChainSimulator_Multiple_EGLD_Transfers(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) // check accounts balance From 872a0eebf0626bc070341241148435b53bab8f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Wed, 17 Jul 2024 14:22:37 +0300 Subject: [PATCH 430/503] Optimize DisplayProcessTxDetails. Early exit if log level is not TRACE. --- process/common.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/process/common.go b/process/common.go index f06e0d00091..e8c9c7504ff 100644 --- a/process/common.go +++ b/process/common.go @@ -680,6 +680,10 @@ func DisplayProcessTxDetails( txHash []byte, addressPubkeyConverter core.PubkeyConverter, ) { + if log.GetLevel() > logger.LogTrace { + return + } + if !check.IfNil(accountHandler) { account, ok := accountHandler.(state.UserAccountHandler) if ok { From 930ed33d8d9f77f61b024625da0911b85e98f45d Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 17 Jul 2024 16:15:56 +0300 Subject: [PATCH 431/503] invalid tx value field scenario --- .../vm/egldMultiTransfer_test.go | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go index e2c1c8019af..8638445dacf 100644 --- a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go +++ b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go @@ -312,6 +312,124 @@ func TestChainSimulator_EGLD_MultiTransfer_Insufficient_Funds(t *testing.T) { require.Equal(t, beforeBalanceStr1, account1.Balance) } +func TestChainSimulator_EGLD_MultiTransfer_Invalid_Value(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + activationEpoch := uint32(4) + + baseIssuingCost := "1000" + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: true, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 0, + NumNodesWaitingListShard: 0, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.EGLDInMultiTransferEnableEpoch = activationEpoch + cfg.SystemSCConfig.ESDTSystemSCConfig.BaseIssuingCost = baseIssuingCost + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + addrs := createAddresses(t, cs, false) + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + // issue NFT + nftTicker := []byte("NFTTICKER") + tx := issueNonFungibleTx(0, addrs[0].Bytes, nftTicker, baseIssuingCost) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nftTokenID := txResult.Logs.Events[0].Topics[0] + + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + } + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + account0, err := cs.GetAccount(addrs[0]) + require.Nil(t, err) + + beforeBalanceStr0 := account0.Balance + + account1, err := cs.GetAccount(addrs[1]) + require.Nil(t, err) + + beforeBalanceStr1 := account1.Balance + + egldValue := oneEGLD.Mul(oneEGLD, big.NewInt(3)) + tx = multiESDTNFTTransferWithEGLDTx(2, addrs[0].Bytes, addrs[1].Bytes, [][]byte{nftTokenID}, egldValue) + tx.Value = egldValue // invalid value field + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.NotEqual(t, "success", txResult.Status.String()) + + eventLog := string(txResult.Logs.Events[0].Topics[1]) + require.Equal(t, "built in function called with tx value is not allowed", eventLog) + + // check accounts balance + account0, err = cs.GetAccount(addrs[0]) + require.Nil(t, err) + + beforeBalance0, _ := big.NewInt(0).SetString(beforeBalanceStr0, 10) + + txsFee, _ := big.NewInt(0).SetString(txResult.Fee, 10) + expectedBalanceWithFee0 := big.NewInt(0).Sub(beforeBalance0, txsFee) + + require.Equal(t, expectedBalanceWithFee0.String(), account0.Balance) + + account1, err = cs.GetAccount(addrs[1]) + require.Nil(t, err) + + require.Equal(t, beforeBalanceStr1, account1.Balance) +} + func TestChainSimulator_Multiple_EGLD_Transfers(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") From 8cecafc85b9dcf111dfe17ec231eb7ea5058ec67 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 18 Jul 2024 11:12:14 +0300 Subject: [PATCH 432/503] proper deps after merge --- go.mod | 6 +++--- go.sum | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index b477749d353..9ce7b739da6 100644 --- a/go.mod +++ b/go.mod @@ -17,12 +17,12 @@ require ( github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703140829-626328c91a8d github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df - github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240708091128-643032ac245a + github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240716122746-98808ec1d4da github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f - github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240711073837-9d5b724082b5 - github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1 + github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240718081121-561b61a8f07f + github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240716073310-c7de86535df1 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240509104009-598a37ff36b9 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98-0.20240509104102-2a6a709b4041 diff --git a/go.sum b/go.sum index 9d36df90dad..40dea7a6a6e 100644 --- a/go.sum +++ b/go.sum @@ -391,18 +391,18 @@ github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703140829-626328c91a8d h1: github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703140829-626328c91a8d/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.20240708091128-643032ac245a h1:zn8wCK9Hyge0hm76hUUWhuFkpjitj3P+gjpiTdgU150= -github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240708091128-643032ac245a/go.mod h1:rEQ0HPBp0Rg7in8TrC+vncV03yyWWTSTur2sbVGUtUw= +github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240716122746-98808ec1d4da h1:PRJLylGD/RRJg3kVc38YJDeAkDBqzXL2B1a+TLQGrYw= +github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240716122746-98808ec1d4da/go.mod h1:rEQ0HPBp0Rg7in8TrC+vncV03yyWWTSTur2sbVGUtUw= 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.20240711073837-9d5b724082b5 h1:xx0KtuMO7WizDrBarwozOQDUu69E9KLU7/FDj336uLw= -github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240711073837-9d5b724082b5/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-common-go v1.5.13-0.20240718081121-561b61a8f07f h1:YSq5I39Rqd1gm2mR40qzlBo/6HP7Eb2MZ+jUkmhn2mw= +github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240718081121-561b61a8f07f/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo= +github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240716073310-c7de86535df1 h1:iEF9yjTDl/WSvHHi+1hU84NCC7ZprSHDI9W68ruJ8BQ= +github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240716073310-c7de86535df1/go.mod h1:AKygEQlZe9F2YdO8VKK8QCWb7UTCuN2KclFcEfFo0m4= 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= From 60a747599704e9498eca8c1ba1e5387831519b47 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 19 Jul 2024 12:43:49 +0300 Subject: [PATCH 433/503] fixed tests by using real FailedTxLogsAccumulator --- integrationTests/vm/testInitializer.go | 88 ++++++++++++++------------ 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/integrationTests/vm/testInitializer.go b/integrationTests/vm/testInitializer.go index 151b64bb57b..fc129e36d90 100644 --- a/integrationTests/vm/testInitializer.go +++ b/integrationTests/vm/testInitializer.go @@ -141,8 +141,9 @@ type VMTestContext struct { ContractOwner VMTestAccount Contract VMTestAccount - TxCostHandler external.TransactionEvaluator - TxsLogsProcessor process.TransactionLogProcessor + TxCostHandler external.TransactionEvaluator + TxsLogsProcessor process.TransactionLogProcessor + FailedTxLogsAccumulator process.FailedTxLogsAccumulator } // Close - @@ -808,12 +809,13 @@ func CreateVMConfigWithVersion(version string) *config.VirtualMachineConfig { // ResultsCreateTxProcessor is the struct that will hold all needed processor instances type ResultsCreateTxProcessor struct { - TxProc process.TransactionProcessor - SCProc scrCommon.TestSmartContractProcessor - IntermediateTxProc process.IntermediateTransactionHandler - EconomicsHandler process.EconomicsDataHandler - CostHandler external.TransactionEvaluator - TxLogProc process.TransactionLogProcessor + TxProc process.TransactionProcessor + SCProc scrCommon.TestSmartContractProcessor + IntermediateTxProc process.IntermediateTransactionHandler + EconomicsHandler process.EconomicsDataHandler + CostHandler external.TransactionEvaluator + TxLogProc process.TransactionLogProcessor + FailedTxLogsAccumulator process.FailedTxLogsAccumulator } // CreateTxProcessorWithOneSCExecutorWithVMs - @@ -870,6 +872,8 @@ func CreateTxProcessorWithOneSCExecutorWithVMs( Marshalizer: integrationtests.TestMarshalizer, }) + failedLogsAcc := transactionLog.NewFailedTxLogsAccumulator() + intermediateTxHandler := &mock.IntermediateTransactionHandlerMock{} argsNewSCProcessor := scrCommon.ArgsNewSmartContractProcessor{ VmContainer: vmContainer, @@ -918,8 +922,8 @@ func CreateTxProcessorWithOneSCExecutorWithVMs( TxVersionChecker: versioning.NewTxVersionChecker(minTransactionVersion), GuardianChecker: guardianChecker, TxLogsProcessor: logProc, + FailedTxLogsAccumulator: failedLogsAcc, RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, } txProcessor, err := transaction.NewTxProcessor(argsNewTxProcessor) if err != nil { @@ -1326,23 +1330,24 @@ func CreatePreparedTxProcessorWithVMConfigWithShardCoordinatorDBAndGasAndRoundCo } return &VMTestContext{ - TxProcessor: res.TxProc, - ScProcessor: res.SCProc, - Accounts: accounts, - BlockchainHook: blockchainHook, - VMContainer: vmContainer, - TxFeeHandler: feeAccumulator, - ScForwarder: res.IntermediateTxProc, - ShardCoordinator: shardCoordinator, - EconomicsData: res.EconomicsHandler, - TxCostHandler: res.CostHandler, - TxsLogsProcessor: res.TxLogProc, - GasSchedule: gasScheduleNotifier, - EpochNotifier: epochNotifierInstance, - EnableEpochsHandler: enableEpochsHandler, - ChainHandler: chainHandler, - Marshalizer: integrationtests.TestMarshalizer, - GuardedAccountsHandler: guardedAccountHandler, + TxProcessor: res.TxProc, + ScProcessor: res.SCProc, + Accounts: accounts, + BlockchainHook: blockchainHook, + VMContainer: vmContainer, + TxFeeHandler: feeAccumulator, + ScForwarder: res.IntermediateTxProc, + ShardCoordinator: shardCoordinator, + EconomicsData: res.EconomicsHandler, + TxCostHandler: res.CostHandler, + TxsLogsProcessor: res.TxLogProc, + FailedTxLogsAccumulator: res.FailedTxLogsAccumulator, + GasSchedule: gasScheduleNotifier, + EpochNotifier: epochNotifierInstance, + EnableEpochsHandler: enableEpochsHandler, + ChainHandler: chainHandler, + Marshalizer: integrationtests.TestMarshalizer, + GuardedAccountsHandler: guardedAccountHandler, }, nil } @@ -1939,21 +1944,22 @@ func CreatePreparedTxProcessorWithVMsMultiShardRoundVMConfig( } return &VMTestContext{ - TxProcessor: res.TxProc, - ScProcessor: res.SCProc, - Accounts: accounts, - BlockchainHook: blockchainHook, - VMContainer: vmContainer, - TxFeeHandler: feeAccumulator, - ShardCoordinator: shardCoordinator, - ScForwarder: res.IntermediateTxProc, - EconomicsData: res.EconomicsHandler, - Marshalizer: integrationtests.TestMarshalizer, - TxsLogsProcessor: res.TxLogProc, - EpochNotifier: epochNotifierInstance, - EnableEpochsHandler: enableEpochsHandler, - ChainHandler: chainHandler, - GuardedAccountsHandler: guardedAccountHandler, + TxProcessor: res.TxProc, + ScProcessor: res.SCProc, + Accounts: accounts, + BlockchainHook: blockchainHook, + VMContainer: vmContainer, + TxFeeHandler: feeAccumulator, + ShardCoordinator: shardCoordinator, + ScForwarder: res.IntermediateTxProc, + EconomicsData: res.EconomicsHandler, + Marshalizer: integrationtests.TestMarshalizer, + TxsLogsProcessor: res.TxLogProc, + FailedTxLogsAccumulator: res.FailedTxLogsAccumulator, + EpochNotifier: epochNotifierInstance, + EnableEpochsHandler: enableEpochsHandler, + ChainHandler: chainHandler, + GuardedAccountsHandler: guardedAccountHandler, }, nil } From c90ae5b9d9ef567e9e0435bc1b582695332fb7d7 Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 19 Jul 2024 16:07:58 +0300 Subject: [PATCH 434/503] fix white list handler for txs on source --- .../chainSimulator/staking/jail/jail_test.go | 6 ++ .../staking/stake/simpleStake_test.go | 6 ++ .../staking/stake/stakeAndUnStake_test.go | 33 ++++++++ .../stakingProvider/delegation_test.go | 18 +++++ .../stakingProviderWithNodesinQueue_test.go | 2 + integrationTests/chainSimulator/testing.go | 3 + .../vm/esdtImprovements_test.go | 3 + node/chainSimulator/chainSimulator_test.go | 80 +++++++++++++++++++ .../components/processComponents.go | 3 +- .../components/whiteListDataVerifier.go | 46 +++++++++++ 10 files changed, 198 insertions(+), 2 deletions(-) create mode 100644 node/chainSimulator/components/whiteListDataVerifier.go diff --git a/integrationTests/chainSimulator/staking/jail/jail_test.go b/integrationTests/chainSimulator/staking/jail/jail_test.go index 42c4e69eaca..bb449da993f 100644 --- a/integrationTests/chainSimulator/staking/jail/jail_test.go +++ b/integrationTests/chainSimulator/staking/jail/jail_test.go @@ -99,6 +99,9 @@ func testChainSimulatorJailAndUnJail(t *testing.T, targetEpoch int32, nodeStatus walletAddress, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) txStake := chainSimulatorIntegrationTests.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) @@ -203,6 +206,9 @@ func TestChainSimulator_FromQueueToAuctionList(t *testing.T) { walletAddress, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) txStake := chainSimulatorIntegrationTests.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) diff --git a/integrationTests/chainSimulator/staking/stake/simpleStake_test.go b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go index a1176b7795f..bfc9f3c11b6 100644 --- a/integrationTests/chainSimulator/staking/stake/simpleStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go @@ -94,6 +94,9 @@ func testChainSimulatorSimpleStake(t *testing.T, targetEpoch int32, nodesStatus wallet3, err := cs.GenerateAndMintWalletAddress(0, mintValue) require.Nil(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + _, blsKeys, err := chainSimulator.GenerateBlsPrivateKeys(3) require.Nil(t, err) @@ -201,6 +204,9 @@ func TestChainSimulator_StakingV4Step2APICalls(t *testing.T) { validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + // Stake a new validator that should end up in auction in step 1 txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) diff --git a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index 1804350ded9..acb0c7537ed 100644 --- a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go @@ -103,6 +103,9 @@ func TestChainSimulator_AddValidatorKey(t *testing.T) { }) require.Nil(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + // Step 3 --- generate and send a stake transaction with the BLS key of the validator key that was added at step 1 stakeValue, _ := big.NewInt(0).SetString("2500000000000000000000", 10) tx := &transaction.Transaction{ @@ -237,6 +240,9 @@ func TestChainSimulator_AddANewValidatorAfterStakingV4(t *testing.T) { }) require.Nil(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + // Step 3 --- generate and send a stake transaction with the BLS keys of the validators key that were added at step 1 validatorData := "" for _, blsKey := range blsKeys { @@ -353,6 +359,9 @@ func testStakeUnStakeUnBond(t *testing.T, targetEpoch int32) { walletAddress, err := cs.GenerateAndMintWalletAddress(walletAddressShardID, mintValue) require.Nil(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) txStake := chainSimulatorIntegrationTests.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) @@ -583,6 +592,9 @@ func testChainSimulatorDirectStakedNodesStakingFunds(t *testing.T, cs chainSimul validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + stakeValue := big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) @@ -811,6 +823,9 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivation(t *testing.T, cs validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + stakeValue := big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) @@ -1092,6 +1107,9 @@ func testChainSimulatorDirectStakedUnstakeFundsWithDeactivationAndReactivation(t validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + stakeValue := big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) @@ -1322,6 +1340,9 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsBeforeUnbonding(t *testi validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + stakeValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(2600)) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) @@ -1556,6 +1577,9 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInFirstEpoch(t *testing. validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + stakeValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(2600)) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) @@ -1827,6 +1851,9 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + stakeValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(2600)) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) @@ -2183,6 +2210,9 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + stakeValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(2600)) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) txStake := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) @@ -2524,6 +2554,9 @@ func createStakeTransaction(t *testing.T, cs chainSimulatorIntegrationTests.Chai validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) return chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, chainSimulatorIntegrationTests.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) } diff --git a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index 4c7475701e4..423faa3fbab 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go @@ -292,6 +292,9 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi delegator2, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + log.Info("working with the following addresses", "newValidatorOwner", validatorOwner.Bech32, "delegator1", delegator1.Bech32, "delegator2", delegator2.Bech32) @@ -625,6 +628,9 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith2StakingContracts(t * validatorOwnerB, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + log.Info("working with the following addresses", "validatorOwnerA", validatorOwnerA.Bech32, "validatorOwnerB", validatorOwnerB.Bech32) @@ -866,6 +872,9 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnsta delegator, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + log.Info("working with the following addresses", "owner", owner.Bech32, "", delegator.Bech32) @@ -1194,6 +1203,9 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat delegator2, err := cs.GenerateAndMintWalletAddress(core.AllShardId, initialFunds) require.Nil(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + maxDelegationCap := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(51000)) // 51000 EGLD cap txCreateDelegationContract := chainSimulatorIntegrationTests.GenerateTransaction(validatorOwner.Bytes, 0, vm.DelegationManagerSCAddress, staking.InitialDelegationValue, fmt.Sprintf("createNewDelegationContract@%s@%s", hex.EncodeToString(maxDelegationCap.Bytes()), hexServiceFee), @@ -1571,6 +1583,9 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati delegatorC, err := cs.GenerateAndMintWalletAddress(core.AllShardId, initialFunds) require.Nil(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + // Step 3: Create a new delegation contract maxDelegationCap := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(3000)) // 3000 EGLD cap @@ -1956,6 +1971,9 @@ func testChainSimulatorMergingDelegation(t *testing.T, cs chainSimulatorIntegrat validatorB, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + log.Info("Step 1. User A: - stake 1 node to have 100 egld more than minimum stake value") stakeValue := big.NewInt(0).Set(chainSimulatorIntegrationTests.MinimumStakeValue) addedStakedValue := big.NewInt(0).Mul(chainSimulatorIntegrationTests.OneEGLD, big.NewInt(100)) diff --git a/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go b/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go index 375953d7588..dd89ecf2c28 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go @@ -75,6 +75,8 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati mintValue := big.NewInt(0).Mul(big.NewInt(5000), chainSimulatorIntegrationTests.OneEGLD) validatorOwner, err := cs.GenerateAndMintWalletAddress(0, mintValue) require.Nil(t, err) + + err = cs.GenerateBlocks(1) require.Nil(t, err) err = cs.GenerateBlocksUntilEpochIsReached(1) diff --git a/integrationTests/chainSimulator/testing.go b/integrationTests/chainSimulator/testing.go index 605bf76ac7f..212021a8fbd 100644 --- a/integrationTests/chainSimulator/testing.go +++ b/integrationTests/chainSimulator/testing.go @@ -196,6 +196,9 @@ func CheckGenerateTransactions(t *testing.T, chainSimulator ChainSimulator) { wallet4, err := chainSimulator.GenerateAndMintWalletAddress(2, InitialAmount) require.Nil(t, err) + err = chainSimulator.GenerateBlocks(1) + require.Nil(t, err) + gasLimit := uint64(50000) tx0 := GenerateTransaction(wallet0.Bytes, 0, wallet2.Bytes, transferValue, "", gasLimit) tx1 := GenerateTransaction(wallet1.Bytes, 0, wallet2.Bytes, transferValue, "", gasLimit) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index f24bef01b57..417349eff4f 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -345,6 +345,9 @@ func createAddresses( address3, err := cs.GenerateAndMintWalletAddress(shardIDs[2], mintValue) require.Nil(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + return []dtos.WalletAddress{address, address2, address3} } diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index 3ed39bc8fba..6559087f60b 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -1,14 +1,21 @@ package chainSimulator import ( + "encoding/hex" + "fmt" "math/big" + "strings" "testing" "time" + "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/errors" chainSimulatorCommon "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" + "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" + "github.com/multiversx/mx-chain-go/node/external" "github.com/multiversx/mx-chain-core-go/core" "github.com/stretchr/testify/assert" @@ -380,3 +387,76 @@ func TestSimulator_SendTransactions(t *testing.T) { chainSimulatorCommon.CheckGenerateTransactions(t, chainSimulator) } + +func TestSimulator_SentMoveBalanceNoGasForFee(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ + BypassTxSignatureCheck: true, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 1, + MetaChainMinNodes: 1, + }) + require.Nil(t, err) + require.NotNil(t, chainSimulator) + + defer chainSimulator.Close() + + wallet0, err := chainSimulator.GenerateAndMintWalletAddress(0, big.NewInt(0)) + require.Nil(t, err) + + ftx := transaction.FrontendTransaction{ + Nonce: 0, + Value: "0", + Sender: wallet0.Bech32, + Receiver: wallet0.Bech32, + Data: []byte(""), + GasLimit: 50_000, + GasPrice: 1_000_000_000, + ChainID: configs.ChainID, + Version: 1, + Signature: "010101", + } + + txArgs := &external.ArgsCreateTransaction{ + Nonce: ftx.Nonce, + Value: ftx.Value, + Receiver: ftx.Receiver, + ReceiverUsername: ftx.ReceiverUsername, + Sender: ftx.Sender, + SenderUsername: ftx.SenderUsername, + GasPrice: ftx.GasPrice, + GasLimit: ftx.GasLimit, + DataField: ftx.Data, + SignatureHex: ftx.Signature, + ChainID: ftx.ChainID, + Version: ftx.Version, + Options: ftx.Options, + Guardian: ftx.GuardianAddr, + GuardianSigHex: ftx.GuardianSignature, + } + + shardFacadeHandle := chainSimulator.nodes[0].GetFacadeHandler() + tx, txHash, err := shardFacadeHandle.CreateTransaction(txArgs) + require.Nil(t, err) + require.NotNil(t, tx) + fmt.Printf("txHash: %s\n", hex.EncodeToString(txHash)) + + err = shardFacadeHandle.ValidateTransaction(tx) + require.NotNil(t, err) + require.True(t, strings.Contains(err.Error(), errors.ErrInsufficientFunds.Error())) +} diff --git a/node/chainSimulator/components/processComponents.go b/node/chainSimulator/components/processComponents.go index 8a2dd6baf1d..d6261921cec 100644 --- a/node/chainSimulator/components/processComponents.go +++ b/node/chainSimulator/components/processComponents.go @@ -23,7 +23,6 @@ import ( "github.com/multiversx/mx-chain-go/genesis/parsing" nodeDisabled "github.com/multiversx/mx-chain-go/node/disabled" "github.com/multiversx/mx-chain-go/process" - "github.com/multiversx/mx-chain-go/process/interceptors/disabled" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "github.com/multiversx/mx-chain-go/storage/cache" @@ -154,7 +153,7 @@ func CreateProcessComponents(args ArgsProcessComponentsHolder) (*processComponen return nil, err } - whiteListRequest, err := disabled.NewDisabledWhiteListDataVerifier() + whiteListRequest, err := NewWhiteListDataVerifier(args.BootstrapComponents.ShardCoordinator().SelfId()) if err != nil { return nil, err } diff --git a/node/chainSimulator/components/whiteListDataVerifier.go b/node/chainSimulator/components/whiteListDataVerifier.go new file mode 100644 index 00000000000..fbdb8730593 --- /dev/null +++ b/node/chainSimulator/components/whiteListDataVerifier.go @@ -0,0 +1,46 @@ +package components + +import "github.com/multiversx/mx-chain-go/process" + +type whiteListVerifier struct { + shardID uint32 +} + +// NewWhiteListDataVerifier returns a default data verifier +func NewWhiteListDataVerifier(shardID uint32) (*whiteListVerifier, error) { + return &whiteListVerifier{ + shardID: shardID, + }, nil +} + +// IsWhiteListed returns true +func (w *whiteListVerifier) IsWhiteListed(interceptedData process.InterceptedData) bool { + interceptedTx, ok := interceptedData.(process.InterceptedTransactionHandler) + if !ok { + return true + } + + if interceptedTx.SenderShardId() == w.shardID { + return false + } + + return true +} + +// IsWhiteListedAtLeastOne returns true +func (w *whiteListVerifier) IsWhiteListedAtLeastOne(_ [][]byte) bool { + return true +} + +// Add does nothing +func (w *whiteListVerifier) Add(_ [][]byte) { +} + +// Remove does nothing +func (w *whiteListVerifier) Remove(_ [][]byte) { +} + +// IsInterfaceNil returns true if underlying object is nil +func (w *whiteListVerifier) IsInterfaceNil() bool { + return w == nil +} From 768ec0db4f5e1b73f88314d20356189791d22507 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 25 Jul 2024 10:43:34 +0300 Subject: [PATCH 435/503] updated deps after merge --- go.mod | 24 ++++++++++++------------ go.sum | 48 ++++++++++++++++++++++++------------------------ 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/go.mod b/go.mod index 9ce7b739da6..140e76d10c8 100644 --- a/go.mod +++ b/go.mod @@ -14,18 +14,18 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 - github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e - github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703140829-626328c91a8d - github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df - github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240716122746-98808ec1d4da - github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 - github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 - github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f - github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240718081121-561b61a8f07f - github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240716073310-c7de86535df1 - github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b - github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240509104009-598a37ff36b9 - github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98-0.20240509104102-2a6a709b4041 + github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240725071304-ebce652ff65d + github.com/multiversx/mx-chain-core-go v1.2.21-0.20240725065431-6e9bfee5a4c6 + github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f + github.com/multiversx/mx-chain-es-indexer-go v1.7.3-0.20240725073933-b3457c5308ca + github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240725065747-176bd697c775 + github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240725072925-89c927c8b6a6 + github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240725070753-aa7fb322ebdf + github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240725072715-8806f1301087 + github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240725073737-3f682a6c59db + github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240725073104-85ec99cb9260 + github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240725073322-952f3197e2e2 + github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98-0.20240725073616-3b96f06509cf github.com/pelletier/go-toml v1.9.3 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.14.0 diff --git a/go.sum b/go.sum index 40dea7a6a6e..1522bc6a3e5 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.20240703140829-626328c91a8d h1:2x1arnxYt28ZlDAZj61dzmG4NqoUmAZbe3pTFsBZHek= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703140829-626328c91a8d/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.20240716122746-98808ec1d4da h1:PRJLylGD/RRJg3kVc38YJDeAkDBqzXL2B1a+TLQGrYw= -github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240716122746-98808ec1d4da/go.mod h1:rEQ0HPBp0Rg7in8TrC+vncV03yyWWTSTur2sbVGUtUw= -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.20240718081121-561b61a8f07f h1:YSq5I39Rqd1gm2mR40qzlBo/6HP7Eb2MZ+jUkmhn2mw= -github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240718081121-561b61a8f07f/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo= -github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240716073310-c7de86535df1 h1:iEF9yjTDl/WSvHHi+1hU84NCC7ZprSHDI9W68ruJ8BQ= -github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240716073310-c7de86535df1/go.mod h1:AKygEQlZe9F2YdO8VKK8QCWb7UTCuN2KclFcEfFo0m4= -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.0.15-0.20240725071304-ebce652ff65d h1:grQCJW4DCvvIQ6q84sy23oAp8XQ8Dxr3Js8aoh+m99M= +github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240725071304-ebce652ff65d/go.mod h1:hFGM+O7rt+gWXSHFoRjC3/oN0OJfPfeFAxqXIac5UdQ= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240725065431-6e9bfee5a4c6 h1:Q7uUjTYTrt8Mw9oq5JWPv+WHhpxHTv6lhZZlhPuNcoQ= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240725065431-6e9bfee5a4c6/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f h1:jydjrmVFvSllBOTppveOAkLITpOYKk0kma5z0bfDImI= +github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f/go.mod h1:9aSp//uBSvqFdzh4gvYISraoruhr1FCTXgPQalQ687k= +github.com/multiversx/mx-chain-es-indexer-go v1.7.3-0.20240725073933-b3457c5308ca h1:9b2yFAarWDG/jTYePv0UqNWQ9gxeSZy9mGxtd8dFj2Y= +github.com/multiversx/mx-chain-es-indexer-go v1.7.3-0.20240725073933-b3457c5308ca/go.mod h1:bHPP5zerhmbRfVcbfXgpMPUaTKMrK6gGi+rRbw0BpDE= +github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240725065747-176bd697c775 h1:a8LOfz3p4MQfRtbF00rGDAJiebziwtSfVmBHIaHBDdY= +github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240725065747-176bd697c775/go.mod h1:owPYyrK7RcsLx9eOCAZQ22fIyW6BE7ttJr4XIhFIbQw= +github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240725072925-89c927c8b6a6 h1:QGQjSlPix5nBtCkcdyKo0b2sRYXwYF/GBtccOqDbU6Y= +github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240725072925-89c927c8b6a6/go.mod h1:MvJiMtuyGq43aS9eOgF+xQUWk0hYxvCQqLrT77bhBaE= +github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240725070753-aa7fb322ebdf h1:L9K7Xzq5SZz6k55R7HrafiRcU+c8/PqozJxys65G4bI= +github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240725070753-aa7fb322ebdf/go.mod h1:ptvW/8r6bam55mVpeVZbyvvvydYM0DQwcPOH0W4Xyx8= +github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240725072715-8806f1301087 h1:ovxs8X50iBL9TOkn0qHrkuXrBS1Y/EWfQOYmFEaXRNs= +github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240725072715-8806f1301087/go.mod h1:nNGN+rdLRN8Nd6OhFGrkEZS5Ipj5IQCvFT0L/iQbOpU= +github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240725073737-3f682a6c59db h1:ZSvHaMsoL0hNfaVBsBZskUdMEaKu+Fdrx3KZrSBbkio= +github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240725073737-3f682a6c59db/go.mod h1:CFOSVrsHOzaO5YX2L/wyjP76L+BE/9rh+SereQV3pHA= +github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240725073104-85ec99cb9260 h1:Ny3s7dw2oF6AVq4kZYmhNYWvAuLEbd48JPPIC6tFzOA= +github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240725073104-85ec99cb9260/go.mod h1:NFRX6UrkBMb28HFKZyKwH894uxfrZyfuFqMF1KBVqFw= +github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240725073322-952f3197e2e2 h1:TM45+UXZV5DYOHlbGiHyQm44hOlBid8g9qfvYqopILs= +github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240725073322-952f3197e2e2/go.mod h1:Ntfq9tUV3I5k6SS/OpW4HSO6AlZbs/xxgB2poOuc2pg= +github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98-0.20240725073616-3b96f06509cf h1:axwaSswcaw8pituLVAu4IWlGNtYwXvUMYy+MGPwmxuY= +github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98-0.20240725073616-3b96f06509cf/go.mod h1:2TjMTiVFkh5wFImEEFZl+k5MU8bh2287btJuVCR3sL0= 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 e0145217e80724e9e6a5f3a6235cbe1a042ed8a1 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 25 Jul 2024 13:18:19 +0300 Subject: [PATCH 436/503] fix lint --- integrationTests/chainSimulator/vm/esdtImprovements_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index f24bef01b57..e94ba571162 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -286,8 +286,6 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - - nonce++ } else { for _, tokenID := range tokenIDs { log.Info("transfering token id", "tokenID", tokenID) From 0d44327528544a9231b506ad9b9cdcbf880e0d52 Mon Sep 17 00:00:00 2001 From: miiu Date: Thu, 25 Jul 2024 13:53:28 +0300 Subject: [PATCH 437/503] fixes --- .../relayedTx/relayedTx_test.go | 15 ++++++ .../components/processComponents.go | 13 ++++-- .../components/whiteListDataVerifier.go | 46 ------------------- 3 files changed, 23 insertions(+), 51 deletions(-) delete mode 100644 node/chainSimulator/components/whiteListDataVerifier.go diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index 860404e7ab9..72bc9575763 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -62,6 +62,9 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing. receiver, err := cs.GenerateAndMintWalletAddress(1, big.NewInt(0)) require.NoError(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + innerTx := generateTransaction(sender.Bytes, 0, receiver.Bytes, oneEGLD, "", minGasLimit) innerTx.RelayerAddr = relayer.Bytes @@ -71,6 +74,9 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing. receiver2, err := cs.GenerateAndMintWalletAddress(0, big.NewInt(0)) require.NoError(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + innerTx2 := generateTransaction(sender2.Bytes, 0, receiver2.Bytes, oneEGLD, "", minGasLimit) innerTx2.RelayerAddr = relayer.Bytes @@ -81,6 +87,9 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing. owner, err := cs.GenerateAndMintWalletAddress(0, initialBalance) require.NoError(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + scCode := wasm.GetSCCode("testData/egld-esdt-swap.wasm") params := []string{scCode, wasm.VMTypeHex, wasm.DummyCodeMetadataHex, hex.EncodeToString([]byte("WEGLD"))} txDataDeploy := strings.Join(params, "@") @@ -164,6 +173,9 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorScCalls(t *t owner, err := cs.GenerateAndMintWalletAddress(0, initialBalance) require.NoError(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + ownerNonce := uint64(0) scCode := wasm.GetSCCode("testData/adder.wasm") params := []string{scCode, wasm.VMTypeHex, wasm.DummyCodeMetadataHex, "00"} @@ -465,6 +477,9 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorInnerNotExec guardian, err := cs.GenerateAndMintWalletAddress(0, initialBalance) require.NoError(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + // Set guardian for sender senderNonce := uint64(0) setGuardianTxData := "SetGuardian@" + hex.EncodeToString(guardian.Bytes) + "@" + hex.EncodeToString([]byte("uuid")) diff --git a/node/chainSimulator/components/processComponents.go b/node/chainSimulator/components/processComponents.go index c0723365edd..70bab3155a1 100644 --- a/node/chainSimulator/components/processComponents.go +++ b/node/chainSimulator/components/processComponents.go @@ -21,8 +21,8 @@ import ( processComp "github.com/multiversx/mx-chain-go/factory/processing" "github.com/multiversx/mx-chain-go/genesis" "github.com/multiversx/mx-chain-go/genesis/parsing" - nodeDisabled "github.com/multiversx/mx-chain-go/node/disabled" "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/process/interceptors" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "github.com/multiversx/mx-chain-go/storage/cache" @@ -154,12 +154,15 @@ func CreateProcessComponents(args ArgsProcessComponentsHolder) (*processComponen return nil, err } - whiteListRequest, err := NewWhiteListDataVerifier(args.BootstrapComponents.ShardCoordinator().SelfId()) + lruCache, err := cache.NewLRUCache(100000) if err != nil { return nil, err - } - whiteListerVerifiedTxs := nodeDisabled.NewDisabledWhiteListDataVerifier() + } + whiteListRequest, err := interceptors.NewWhiteListDataVerifier(lruCache) + if err != nil { + return nil, err + } historyRepository, err := historyRepositoryFactory.Create() if err != nil { @@ -195,7 +198,7 @@ func CreateProcessComponents(args ArgsProcessComponentsHolder) (*processComponen NodesCoordinator: args.NodesCoordinator, RequestedItemsHandler: requestedItemsHandler, WhiteListHandler: whiteListRequest, - WhiteListerVerifiedTxs: whiteListerVerifiedTxs, + WhiteListerVerifiedTxs: whiteListRequest, MaxRating: 50, SystemSCConfig: &args.SystemSCConfig, ImportStartHandler: importStartHandler, diff --git a/node/chainSimulator/components/whiteListDataVerifier.go b/node/chainSimulator/components/whiteListDataVerifier.go deleted file mode 100644 index fbdb8730593..00000000000 --- a/node/chainSimulator/components/whiteListDataVerifier.go +++ /dev/null @@ -1,46 +0,0 @@ -package components - -import "github.com/multiversx/mx-chain-go/process" - -type whiteListVerifier struct { - shardID uint32 -} - -// NewWhiteListDataVerifier returns a default data verifier -func NewWhiteListDataVerifier(shardID uint32) (*whiteListVerifier, error) { - return &whiteListVerifier{ - shardID: shardID, - }, nil -} - -// IsWhiteListed returns true -func (w *whiteListVerifier) IsWhiteListed(interceptedData process.InterceptedData) bool { - interceptedTx, ok := interceptedData.(process.InterceptedTransactionHandler) - if !ok { - return true - } - - if interceptedTx.SenderShardId() == w.shardID { - return false - } - - return true -} - -// IsWhiteListedAtLeastOne returns true -func (w *whiteListVerifier) IsWhiteListedAtLeastOne(_ [][]byte) bool { - return true -} - -// Add does nothing -func (w *whiteListVerifier) Add(_ [][]byte) { -} - -// Remove does nothing -func (w *whiteListVerifier) Remove(_ [][]byte) { -} - -// IsInterfaceNil returns true if underlying object is nil -func (w *whiteListVerifier) IsInterfaceNil() bool { - return w == nil -} From 1657f8a7b6522e8449cb827fe05b7abe1af63931 Mon Sep 17 00:00:00 2001 From: Daniel Drasovean Date: Thu, 25 Jul 2024 14:20:19 +0300 Subject: [PATCH 438/503] fix node dockerfile --- docker/node/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/node/Dockerfile b/docker/node/Dockerfile index 81675a6f6a3..47516b05b74 100644 --- a/docker/node/Dockerfile +++ b/docker/node/Dockerfile @@ -16,6 +16,7 @@ RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx- # ===== SECOND STAGE ====== FROM ubuntu:22.04 +ARG TARGETARCH RUN apt-get update && apt-get upgrade -y COPY --from=builder "/go/mx-chain-go/cmd/node/node" "/go/mx-chain-go/cmd/node/" From 4b4eccfbd2b8575b551b32e27dc7e4d74aad43ba Mon Sep 17 00:00:00 2001 From: Daniel Drasovean Date: Thu, 25 Jul 2024 14:47:11 +0300 Subject: [PATCH 439/503] fix node dockerfile --- docker/node/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker/node/Dockerfile b/docker/node/Dockerfile index 47516b05b74..2a341a8409b 100644 --- a/docker/node/Dockerfile +++ b/docker/node/Dockerfile @@ -8,6 +8,8 @@ RUN go mod tidy WORKDIR /go/mx-chain-go/cmd/node RUN go build -v -ldflags="-X main.appVersion=$(git describe --tags --long --dirty)" +RUN mkdir -p /lib_amd64 /lib_arm64 + RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-v | sort -n | tail -n -1 | awk -F '/' '{print$3}' | sed 's/ /@/g')/wasmer/libwasmer_linux_amd64.so /lib_amd64/ RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-go | sort -n | tail -n -1 | awk -F '/' '{print$3}' | sed 's/ /@/g')/wasmer2/libvmexeccapi.so /lib_amd64/ From 620538dd9f8c07659117b3ca557cd28462646d13 Mon Sep 17 00:00:00 2001 From: Daniel Drasovean Date: Thu, 25 Jul 2024 15:06:09 +0300 Subject: [PATCH 440/503] fix termui dockerfile --- docker/termui/Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker/termui/Dockerfile b/docker/termui/Dockerfile index e25e75833e5..e22986033eb 100644 --- a/docker/termui/Dockerfile +++ b/docker/termui/Dockerfile @@ -4,12 +4,14 @@ WORKDIR /go/mx-chain-go COPY . . WORKDIR /go/mx-chain-go/cmd/termui RUN go build -v +RUN mkdir -p /lib_amd64 /lib_arm64 RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-v | sort -n | tail -n -1| awk -F '/' '{print$3}'| sed 's/ /@/g')/wasmer/libwasmer_linux_amd64.so /lib_amd64/ RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-v | sort -n | tail -n -1 | awk -F '/' '{print$3}' | sed 's/ /@/g')/wasmer/libwasmer_linux_arm64_shim.so /lib_arm64/ # ===== SECOND STAGE ====== FROM ubuntu:22.04 +ARG TARGETARCH COPY --from=builder /go/mx-chain-go/cmd/termui /go/mx-chain-go/cmd/termui # Copy architecture-specific files From 8098d3bffe0ae472cab0d413fee2a39d489b7c70 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Fri, 26 Jul 2024 11:05:09 +0300 Subject: [PATCH 441/503] new flag for multi transfer and execute by user --- cmd/node/config/enableEpochs.toml | 3 +++ common/constants.go | 4 ++++ common/enablers/enableEpochsHandler.go | 6 ++++++ common/enablers/enableEpochsHandler_test.go | 2 ++ config/epochConfig.go | 1 + config/tomlConfig_test.go | 4 ++++ go.mod | 2 +- go.sum | 4 ++-- node/metrics/metrics.go | 1 + node/metrics/metrics_test.go | 1 + statusHandler/statusMetricsProvider.go | 1 + statusHandler/statusMetricsProvider_test.go | 2 ++ 12 files changed, 28 insertions(+), 3 deletions(-) diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index 7b1177754bb..f088f7b549c 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -327,6 +327,9 @@ # FixRelayedBaseCostEnableEpoch represents the epoch when the fix for relayed base cost will be enabled FixRelayedBaseCostEnableEpoch = 7 + # MultiESDTNFTTransferAndExecuteByUserEnableEpoch represents the epoch when enshrined sovereign cross chain opcodes are enabled + MultiESDTNFTTransferAndExecuteByUserEnableEpoch = 9999999 + # BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers BLSMultiSignerEnableEpoch = [ { EnableEpoch = 0, Type = "no-KOSK" }, diff --git a/common/constants.go b/common/constants.go index d5875d10de9..984dec87b07 100644 --- a/common/constants.go +++ b/common/constants.go @@ -734,6 +734,9 @@ const ( // MetricCryptoOpcodesV2EnableEpoch represents the epoch when crypto opcodes v2 feature is enabled MetricCryptoOpcodesV2EnableEpoch = "erd_crypto_opcodes_v2_enable_epoch" + // MetricMultiESDTNFTTransferAndExecuteByUserEnableEpoch represents the epoch when enshrined sovereign opcodes are enabled + MetricMultiESDTNFTTransferAndExecuteByUserEnableEpoch = "erd_multi_esdt_transfer_execute_by_user_enable_epoch" + // MetricMaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MetricMaxNodesChangeEnableEpoch = "erd_max_nodes_change_enable_epoch" @@ -1229,5 +1232,6 @@ const ( UnJailCleanupFlag core.EnableEpochFlag = "UnJailCleanupFlag" RelayedTransactionsV3Flag core.EnableEpochFlag = "RelayedTransactionsV3Flag" FixRelayedBaseCostFlag core.EnableEpochFlag = "FixRelayedBaseCostFlag" + MultiESDTNFTTransferAndExecuteByUserFlag core.EnableEpochFlag = "MultiESDTNFTTransferAndExecuteByUserFlag" // all new flags must be added to createAllFlagsMap method, as part of enableEpochsHandler allFlagsDefined ) diff --git a/common/enablers/enableEpochsHandler.go b/common/enablers/enableEpochsHandler.go index 8b00b91f6f8..d3df21b6bbb 100644 --- a/common/enablers/enableEpochsHandler.go +++ b/common/enablers/enableEpochsHandler.go @@ -768,6 +768,12 @@ func (handler *enableEpochsHandler) createAllFlagsMap() { }, activationEpoch: handler.enableEpochsConfig.FixRelayedBaseCostEnableEpoch, }, + common.MultiESDTNFTTransferAndExecuteByUserFlag: { + isActiveInEpoch: func(epoch uint32) bool { + return epoch >= handler.enableEpochsConfig.MultiESDTNFTTransferAndExecuteByUserEnableEpoch + }, + activationEpoch: handler.enableEpochsConfig.MultiESDTNFTTransferAndExecuteByUserEnableEpoch, + }, } } diff --git a/common/enablers/enableEpochsHandler_test.go b/common/enablers/enableEpochsHandler_test.go index ad1bf9d386d..72fafc5a689 100644 --- a/common/enablers/enableEpochsHandler_test.go +++ b/common/enablers/enableEpochsHandler_test.go @@ -121,6 +121,7 @@ func createEnableEpochsConfig() config.EnableEpochs { CryptoOpcodesV2EnableEpoch: 104, RelayedTransactionsV3EnableEpoch: 105, FixRelayedBaseCostEnableEpoch: 106, + MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 107, } } @@ -444,6 +445,7 @@ func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) { require.Equal(t, cfg.CryptoOpcodesV2EnableEpoch, handler.GetActivationEpoch(common.CryptoOpcodesV2Flag)) require.Equal(t, cfg.RelayedTransactionsV3EnableEpoch, handler.GetActivationEpoch(common.RelayedTransactionsV3Flag)) require.Equal(t, cfg.FixRelayedBaseCostEnableEpoch, handler.GetActivationEpoch(common.FixRelayedBaseCostFlag)) + require.Equal(t, cfg.MultiESDTNFTTransferAndExecuteByUserEnableEpoch, handler.GetActivationEpoch(common.MultiESDTNFTTransferAndExecuteByUserFlag)) } func TestEnableEpochsHandler_IsInterfaceNil(t *testing.T) { diff --git a/config/epochConfig.go b/config/epochConfig.go index 4600c6ccb4c..7f965e3c5c5 100644 --- a/config/epochConfig.go +++ b/config/epochConfig.go @@ -120,6 +120,7 @@ type EnableEpochs struct { UnJailCleanupEnableEpoch uint32 RelayedTransactionsV3EnableEpoch uint32 FixRelayedBaseCostEnableEpoch uint32 + MultiESDTNFTTransferAndExecuteByUserEnableEpoch uint32 BLSMultiSignerEnableEpoch []MultiSignerConfig } diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index 554066dfb16..c6cecedc774 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -878,6 +878,9 @@ func TestEnableEpochConfig(t *testing.T) { # FixRelayedBaseCostEnableEpoch represents the epoch when the fix for relayed base cost will be enabled FixRelayedBaseCostEnableEpoch = 100 + # MultiESDTNFTTransferAndExecuteByUserEnableEpoch represents the epoch when enshrined sovereign cross chain opcodes are enabled + MultiESDTNFTTransferAndExecuteByUserEnableEpoch = 101 + # MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MaxNodesChangeEnableEpoch = [ { EpochEnable = 44, MaxNumNodes = 2169, NodesToShufflePerShard = 80 }, @@ -996,6 +999,7 @@ func TestEnableEpochConfig(t *testing.T) { CryptoOpcodesV2EnableEpoch: 98, RelayedTransactionsV3EnableEpoch: 99, FixRelayedBaseCostEnableEpoch: 100, + MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 101, MaxNodesChangeEnableEpoch: []MaxNodesChangeConfig{ { EpochEnable: 44, diff --git a/go.mod b/go.mod index 140e76d10c8..2157463e439 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240725072925-89c927c8b6a6 github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240725070753-aa7fb322ebdf github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240725072715-8806f1301087 - github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240725073737-3f682a6c59db + github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240726073639-9001fcac5337 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240725073104-85ec99cb9260 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240725073322-952f3197e2e2 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98-0.20240725073616-3b96f06509cf diff --git a/go.sum b/go.sum index 1522bc6a3e5..4dd78fb05a5 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240725070753-aa7fb322ebdf github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240725070753-aa7fb322ebdf/go.mod h1:ptvW/8r6bam55mVpeVZbyvvvydYM0DQwcPOH0W4Xyx8= github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240725072715-8806f1301087 h1:ovxs8X50iBL9TOkn0qHrkuXrBS1Y/EWfQOYmFEaXRNs= github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240725072715-8806f1301087/go.mod h1:nNGN+rdLRN8Nd6OhFGrkEZS5Ipj5IQCvFT0L/iQbOpU= -github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240725073737-3f682a6c59db h1:ZSvHaMsoL0hNfaVBsBZskUdMEaKu+Fdrx3KZrSBbkio= -github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240725073737-3f682a6c59db/go.mod h1:CFOSVrsHOzaO5YX2L/wyjP76L+BE/9rh+SereQV3pHA= +github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240726073639-9001fcac5337 h1:CZDuVh/lKUdv+KMkiKrSMFi85lSL8Ykp1at9alM7c1U= +github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240726073639-9001fcac5337/go.mod h1:CFOSVrsHOzaO5YX2L/wyjP76L+BE/9rh+SereQV3pHA= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240725073104-85ec99cb9260 h1:Ny3s7dw2oF6AVq4kZYmhNYWvAuLEbd48JPPIC6tFzOA= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240725073104-85ec99cb9260/go.mod h1:NFRX6UrkBMb28HFKZyKwH894uxfrZyfuFqMF1KBVqFw= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240725073322-952f3197e2e2 h1:TM45+UXZV5DYOHlbGiHyQm44hOlBid8g9qfvYqopILs= diff --git a/node/metrics/metrics.go b/node/metrics/metrics.go index 38c616e97f5..c380c08b95d 100644 --- a/node/metrics/metrics.go +++ b/node/metrics/metrics.go @@ -201,6 +201,7 @@ func InitConfigMetrics( appStatusHandler.SetUInt64Value(common.MetricDynamicESDTEnableEpoch, uint64(enableEpochs.DynamicESDTEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricEGLDInMultiTransferEnableEpoch, uint64(enableEpochs.EGLDInMultiTransferEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricCryptoOpcodesV2EnableEpoch, uint64(enableEpochs.CryptoOpcodesV2EnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricMultiESDTNFTTransferAndExecuteByUserEnableEpoch, uint64(enableEpochs.MultiESDTNFTTransferAndExecuteByUserEnableEpoch)) for i, nodesChangeConfig := range enableEpochs.MaxNodesChangeEnableEpoch { epochEnable := fmt.Sprintf("%s%d%s", common.MetricMaxNodesChangeEnableEpoch, i, common.EpochEnableSuffix) diff --git a/node/metrics/metrics_test.go b/node/metrics/metrics_test.go index 71c96ba7304..bc81912d74a 100644 --- a/node/metrics/metrics_test.go +++ b/node/metrics/metrics_test.go @@ -210,6 +210,7 @@ func TestInitConfigMetrics(t *testing.T) { ScToScLogEventEnableEpoch: 103, RelayedTransactionsV3EnableEpoch: 104, FixRelayedBaseCostEnableEpoch: 105, + MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 106, MaxNodesChangeEnableEpoch: []config.MaxNodesChangeConfig{ { EpochEnable: 0, diff --git a/statusHandler/statusMetricsProvider.go b/statusHandler/statusMetricsProvider.go index b47b6851eae..30ead1e5749 100644 --- a/statusHandler/statusMetricsProvider.go +++ b/statusHandler/statusMetricsProvider.go @@ -377,6 +377,7 @@ func (sm *statusMetrics) EnableEpochsMetrics() (map[string]interface{}, error) { enableEpochsMetrics[common.MetricDynamicESDTEnableEpoch] = sm.uint64Metrics[common.MetricDynamicESDTEnableEpoch] enableEpochsMetrics[common.MetricEGLDInMultiTransferEnableEpoch] = sm.uint64Metrics[common.MetricEGLDInMultiTransferEnableEpoch] enableEpochsMetrics[common.MetricCryptoOpcodesV2EnableEpoch] = sm.uint64Metrics[common.MetricCryptoOpcodesV2EnableEpoch] + enableEpochsMetrics[common.MetricMultiESDTNFTTransferAndExecuteByUserEnableEpoch] = sm.uint64Metrics[common.MetricMultiESDTNFTTransferAndExecuteByUserEnableEpoch] numNodesChangeConfig := sm.uint64Metrics[common.MetricMaxNodesChangeEnableEpoch+"_count"] diff --git a/statusHandler/statusMetricsProvider_test.go b/statusHandler/statusMetricsProvider_test.go index 2eecf8cd598..02f33d62549 100644 --- a/statusHandler/statusMetricsProvider_test.go +++ b/statusHandler/statusMetricsProvider_test.go @@ -400,6 +400,7 @@ func TestStatusMetrics_EnableEpochMetrics(t *testing.T) { sm.SetUInt64Value(common.MetricDynamicESDTEnableEpoch, uint64(4)) sm.SetUInt64Value(common.MetricEGLDInMultiTransferEnableEpoch, uint64(4)) sm.SetUInt64Value(common.MetricCryptoOpcodesV2EnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricMultiESDTNFTTransferAndExecuteByUserEnableEpoch, uint64(4)) maxNodesChangeConfig := []map[string]uint64{ { @@ -529,6 +530,7 @@ func TestStatusMetrics_EnableEpochMetrics(t *testing.T) { common.MetricDynamicESDTEnableEpoch: uint64(4), common.MetricEGLDInMultiTransferEnableEpoch: uint64(4), common.MetricCryptoOpcodesV2EnableEpoch: uint64(4), + common.MetricMultiESDTNFTTransferAndExecuteByUserEnableEpoch: uint64(4), common.MetricMaxNodesChangeEnableEpoch: []map[string]interface{}{ { From 397439f900adf5f9f86fc750c65e364313af23d6 Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 26 Jul 2024 11:11:16 +0300 Subject: [PATCH 442/503] fixes --- .../components/processComponents.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/node/chainSimulator/components/processComponents.go b/node/chainSimulator/components/processComponents.go index 70bab3155a1..32348d14c4c 100644 --- a/node/chainSimulator/components/processComponents.go +++ b/node/chainSimulator/components/processComponents.go @@ -154,12 +154,22 @@ func CreateProcessComponents(args ArgsProcessComponentsHolder) (*processComponen return nil, err } - lruCache, err := cache.NewLRUCache(100000) + lruCache1, err := cache.NewLRUCache(100000) if err != nil { return nil, err } - whiteListRequest, err := interceptors.NewWhiteListDataVerifier(lruCache) + whiteListRequest, err := interceptors.NewWhiteListDataVerifier(lruCache1) + if err != nil { + return nil, err + } + + lruCache2, err := cache.NewLRUCache(100000) + if err != nil { + return nil, err + + } + whiteListRequestTxs, err := interceptors.NewWhiteListDataVerifier(lruCache2) if err != nil { return nil, err } @@ -198,7 +208,7 @@ func CreateProcessComponents(args ArgsProcessComponentsHolder) (*processComponen NodesCoordinator: args.NodesCoordinator, RequestedItemsHandler: requestedItemsHandler, WhiteListHandler: whiteListRequest, - WhiteListerVerifiedTxs: whiteListRequest, + WhiteListerVerifiedTxs: whiteListRequestTxs, MaxRating: 50, SystemSCConfig: &args.SystemSCConfig, ImportStartHandler: importStartHandler, From ee15920de256da2ea6cb50d23a667503901e0093 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Fri, 26 Jul 2024 11:35:51 +0300 Subject: [PATCH 443/503] fix test --- node/metrics/metrics_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/node/metrics/metrics_test.go b/node/metrics/metrics_test.go index bc81912d74a..395d42afc15 100644 --- a/node/metrics/metrics_test.go +++ b/node/metrics/metrics_test.go @@ -331,6 +331,7 @@ func TestInitConfigMetrics(t *testing.T) { "erd_set_sc_to_sc_log_event_enable_epoch": uint32(103), "erd_relayed_transactions_v3_enable_epoch": uint32(104), "erd_fix_relayed_base_cost_enable_epoch": uint32(105), + "erd_multi_esdt_transfer_execute_by_user_enable_epoch": uint32(106), "erd_max_nodes_change_enable_epoch": nil, "erd_total_supply": "12345", "erd_hysteresis": "0.100000", From 28f517a3e3df40864838a9123b3aa7191c83a6f2 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Fri, 26 Jul 2024 11:59:27 +0300 Subject: [PATCH 444/503] new vm --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 2157463e439..809222ccff9 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240725072925-89c927c8b6a6 github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240725070753-aa7fb322ebdf github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240725072715-8806f1301087 - github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240726073639-9001fcac5337 + github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240726084628-e3e50b6f78d7 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240725073104-85ec99cb9260 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240725073322-952f3197e2e2 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98-0.20240725073616-3b96f06509cf diff --git a/go.sum b/go.sum index 4dd78fb05a5..20cd9322e3b 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240725070753-aa7fb322ebdf github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240725070753-aa7fb322ebdf/go.mod h1:ptvW/8r6bam55mVpeVZbyvvvydYM0DQwcPOH0W4Xyx8= github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240725072715-8806f1301087 h1:ovxs8X50iBL9TOkn0qHrkuXrBS1Y/EWfQOYmFEaXRNs= github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240725072715-8806f1301087/go.mod h1:nNGN+rdLRN8Nd6OhFGrkEZS5Ipj5IQCvFT0L/iQbOpU= -github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240726073639-9001fcac5337 h1:CZDuVh/lKUdv+KMkiKrSMFi85lSL8Ykp1at9alM7c1U= -github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240726073639-9001fcac5337/go.mod h1:CFOSVrsHOzaO5YX2L/wyjP76L+BE/9rh+SereQV3pHA= +github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240726084628-e3e50b6f78d7 h1:LN9W/RcrhNR3dLB9FhsuCl9fViwceyjzMUeL/s9SBIs= +github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240726084628-e3e50b6f78d7/go.mod h1:CFOSVrsHOzaO5YX2L/wyjP76L+BE/9rh+SereQV3pHA= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240725073104-85ec99cb9260 h1:Ny3s7dw2oF6AVq4kZYmhNYWvAuLEbd48JPPIC6tFzOA= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240725073104-85ec99cb9260/go.mod h1:NFRX6UrkBMb28HFKZyKwH894uxfrZyfuFqMF1KBVqFw= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240725073322-952f3197e2e2 h1:TM45+UXZV5DYOHlbGiHyQm44hOlBid8g9qfvYqopILs= From 12e7f54b60e73ad5133c765171019ff5cda219ef Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 26 Jul 2024 12:11:45 +0300 Subject: [PATCH 445/503] fixes after review --- node/chainSimulator/chainSimulator_test.go | 48 ++++--------------- .../components/processComponents.go | 12 ++--- 2 files changed, 15 insertions(+), 45 deletions(-) diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index 6559087f60b..18f54ccbfe9 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -1,23 +1,19 @@ package chainSimulator import ( - "encoding/hex" - "fmt" + "github.com/multiversx/mx-chain-go/errors" "math/big" "strings" "testing" "time" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" - "github.com/multiversx/mx-chain-go/errors" chainSimulatorCommon "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" - "github.com/multiversx/mx-chain-go/node/external" - - "github.com/multiversx/mx-chain-core-go/core" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -419,44 +415,18 @@ func TestSimulator_SentMoveBalanceNoGasForFee(t *testing.T) { wallet0, err := chainSimulator.GenerateAndMintWalletAddress(0, big.NewInt(0)) require.Nil(t, err) - ftx := transaction.FrontendTransaction{ + ftx := &transaction.Transaction{ Nonce: 0, - Value: "0", - Sender: wallet0.Bech32, - Receiver: wallet0.Bech32, + Value: big.NewInt(0), + SndAddr: wallet0.Bytes, + RcvAddr: wallet0.Bytes, Data: []byte(""), GasLimit: 50_000, GasPrice: 1_000_000_000, - ChainID: configs.ChainID, + ChainID: []byte(configs.ChainID), Version: 1, - Signature: "010101", + Signature: []byte("010101"), } - - txArgs := &external.ArgsCreateTransaction{ - Nonce: ftx.Nonce, - Value: ftx.Value, - Receiver: ftx.Receiver, - ReceiverUsername: ftx.ReceiverUsername, - Sender: ftx.Sender, - SenderUsername: ftx.SenderUsername, - GasPrice: ftx.GasPrice, - GasLimit: ftx.GasLimit, - DataField: ftx.Data, - SignatureHex: ftx.Signature, - ChainID: ftx.ChainID, - Version: ftx.Version, - Options: ftx.Options, - Guardian: ftx.GuardianAddr, - GuardianSigHex: ftx.GuardianSignature, - } - - shardFacadeHandle := chainSimulator.nodes[0].GetFacadeHandler() - tx, txHash, err := shardFacadeHandle.CreateTransaction(txArgs) - require.Nil(t, err) - require.NotNil(t, tx) - fmt.Printf("txHash: %s\n", hex.EncodeToString(txHash)) - - err = shardFacadeHandle.ValidateTransaction(tx) - require.NotNil(t, err) + _, err = chainSimulator.sendTx(ftx) require.True(t, strings.Contains(err.Error(), errors.ErrInsufficientFunds.Error())) } diff --git a/node/chainSimulator/components/processComponents.go b/node/chainSimulator/components/processComponents.go index 32348d14c4c..6e00d776784 100644 --- a/node/chainSimulator/components/processComponents.go +++ b/node/chainSimulator/components/processComponents.go @@ -154,22 +154,22 @@ func CreateProcessComponents(args ArgsProcessComponentsHolder) (*processComponen return nil, err } - lruCache1, err := cache.NewLRUCache(100000) + lruCacheRequest, err := cache.NewLRUCache(int(args.Config.WhiteListPool.Capacity)) if err != nil { return nil, err } - whiteListRequest, err := interceptors.NewWhiteListDataVerifier(lruCache1) + whiteListHandler, err := interceptors.NewWhiteListDataVerifier(lruCacheRequest) if err != nil { return nil, err } - lruCache2, err := cache.NewLRUCache(100000) + lruCacheTx, err := cache.NewLRUCache(int(args.Config.WhiteListerVerifiedTxs.Capacity)) if err != nil { return nil, err } - whiteListRequestTxs, err := interceptors.NewWhiteListDataVerifier(lruCache2) + whiteListVerifiedTxs, err := interceptors.NewWhiteListDataVerifier(lruCacheTx) if err != nil { return nil, err } @@ -207,8 +207,8 @@ func CreateProcessComponents(args ArgsProcessComponentsHolder) (*processComponen GasSchedule: gasScheduleNotifier, NodesCoordinator: args.NodesCoordinator, RequestedItemsHandler: requestedItemsHandler, - WhiteListHandler: whiteListRequest, - WhiteListerVerifiedTxs: whiteListRequestTxs, + WhiteListHandler: whiteListHandler, + WhiteListerVerifiedTxs: whiteListVerifiedTxs, MaxRating: 50, SystemSCConfig: &args.SystemSCConfig, ImportStartHandler: importStartHandler, From baa62660721f22eb67ce9f9904df7a119be823d7 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 26 Jul 2024 15:39:09 +0300 Subject: [PATCH 446/503] fixed fee field for guardian operations --- common/forking/gasSchedule.go | 20 +++++++ factory/api/apiResolverFactory.go | 1 + genesis/process/disabled/feeHandler.go | 5 ++ go.mod | 2 +- go.sum | 4 +- .../mock/gasScheduleNotifierMock.go | 5 ++ .../testProcessorNodeWithTestWebServer.go | 1 + node/external/timemachine/fee/feeComputer.go | 6 +++ .../transactionAPI/apiTransactionArgs.go | 1 + .../transactionAPI/apiTransactionProcessor.go | 2 +- .../apiTransactionProcessor_test.go | 3 ++ node/external/transactionAPI/check.go | 3 ++ .../transactionAPI/gasUsedAndFeeProcessor.go | 52 +++++++++++++++++-- .../gasUsedAndFeeProcessor_test.go | 52 +++++++++++++++++-- node/external/transactionAPI/interface.go | 1 + process/interface.go | 1 + .../economicsDataHandlerStub.go | 9 ++++ .../economicsmocks/economicsHandlerMock.go | 8 +++ testscommon/feeComputerStub.go | 10 ++++ testscommon/gasScheduleNotifierMock.go | 10 ++++ 20 files changed, 182 insertions(+), 14 deletions(-) diff --git a/common/forking/gasSchedule.go b/common/forking/gasSchedule.go index 7da39fed41f..cac675387be 100644 --- a/common/forking/gasSchedule.go +++ b/common/forking/gasSchedule.go @@ -163,6 +163,26 @@ func (g *gasScheduleNotifier) LatestGasSchedule() map[string]map[string]uint64 { return g.lastGasSchedule } +// GasScheduleForEpoch returns the gas schedule for the specific epoch +func (g *gasScheduleNotifier) GasScheduleForEpoch(epoch uint32) (map[string]map[string]uint64, error) { + g.mutNotifier.RLock() + defer g.mutNotifier.RUnlock() + + currentVersion := g.getMatchingVersion(g.currentEpoch) + requestedVersion := g.getMatchingVersion(epoch) + if currentVersion == requestedVersion { + return g.lastGasSchedule, nil + } + + gasSchedule, err := common.LoadGasScheduleConfig(filepath.Join(g.configDir, requestedVersion.FileName)) + if err != nil { + log.Error("could not load the gas schedule", "epoch", requestedVersion.StartEpoch) + return nil, err + } + + return gasSchedule, nil +} + // LatestGasScheduleCopy returns a copy of the latest gas schedule func (g *gasScheduleNotifier) LatestGasScheduleCopy() map[string]map[string]uint64 { g.mutNotifier.RLock() diff --git a/factory/api/apiResolverFactory.go b/factory/api/apiResolverFactory.go index dfefa56ff94..67eb70aa4a9 100644 --- a/factory/api/apiResolverFactory.go +++ b/factory/api/apiResolverFactory.go @@ -244,6 +244,7 @@ func CreateApiResolver(args *ApiResolverArgs) (facade.ApiResolver, error) { TxTypeHandler: txTypeHandler, LogsFacade: logsFacade, DataFieldParser: dataFieldParser, + GasScheduleNotifier: args.GasScheduleNotifier, } apiTransactionProcessor, err := transactionAPI.NewAPITransactionProcessor(argsAPITransactionProc) if err != nil { diff --git a/genesis/process/disabled/feeHandler.go b/genesis/process/disabled/feeHandler.go index f81e7e978eb..1d4679e859f 100644 --- a/genesis/process/disabled/feeHandler.go +++ b/genesis/process/disabled/feeHandler.go @@ -87,6 +87,11 @@ func (fh *FeeHandler) ComputeMoveBalanceFee(_ data.TransactionWithFeeHandler) *b return big.NewInt(0) } +// ComputeMoveBalanceFeeInEpoch returns 0 +func (fh *FeeHandler) ComputeMoveBalanceFeeInEpoch(_ data.TransactionWithFeeHandler, _ uint32) *big.Int { + return big.NewInt(0) +} + // ComputeFeeForProcessing returns 0 func (fh *FeeHandler) ComputeFeeForProcessing(_ data.TransactionWithFeeHandler, _ uint64) *big.Int { return big.NewInt(0) diff --git a/go.mod b/go.mod index 140e76d10c8..98ec8bc66e9 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240725071304-ebce652ff65d - github.com/multiversx/mx-chain-core-go v1.2.21-0.20240725065431-6e9bfee5a4c6 + github.com/multiversx/mx-chain-core-go v1.2.21-0.20240726123734-d2e801ceb0bc github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f github.com/multiversx/mx-chain-es-indexer-go v1.7.3-0.20240725073933-b3457c5308ca github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240725065747-176bd697c775 diff --git a/go.sum b/go.sum index 1522bc6a3e5..5396bd3968b 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY 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.20240725071304-ebce652ff65d h1:grQCJW4DCvvIQ6q84sy23oAp8XQ8Dxr3Js8aoh+m99M= github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240725071304-ebce652ff65d/go.mod h1:hFGM+O7rt+gWXSHFoRjC3/oN0OJfPfeFAxqXIac5UdQ= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240725065431-6e9bfee5a4c6 h1:Q7uUjTYTrt8Mw9oq5JWPv+WHhpxHTv6lhZZlhPuNcoQ= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240725065431-6e9bfee5a4c6/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240726123734-d2e801ceb0bc h1:COQlZ7wmOz15F40woVfRb6sl5CLQCKcRv13e9s/2PT0= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240726123734-d2e801ceb0bc/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f h1:jydjrmVFvSllBOTppveOAkLITpOYKk0kma5z0bfDImI= github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f/go.mod h1:9aSp//uBSvqFdzh4gvYISraoruhr1FCTXgPQalQ687k= github.com/multiversx/mx-chain-es-indexer-go v1.7.3-0.20240725073933-b3457c5308ca h1:9b2yFAarWDG/jTYePv0UqNWQ9gxeSZy9mGxtd8dFj2Y= diff --git a/integrationTests/mock/gasScheduleNotifierMock.go b/integrationTests/mock/gasScheduleNotifierMock.go index 6ef6ea2684c..ddcff3873fc 100644 --- a/integrationTests/mock/gasScheduleNotifierMock.go +++ b/integrationTests/mock/gasScheduleNotifierMock.go @@ -28,6 +28,11 @@ func (g *GasScheduleNotifierMock) LatestGasSchedule() map[string]map[string]uint return g.GasSchedule } +// GasScheduleForEpoch - +func (g *GasScheduleNotifierMock) GasScheduleForEpoch(_ uint32) (map[string]map[string]uint64, error) { + return g.GasSchedule, nil +} + // UnRegisterAll - func (g *GasScheduleNotifierMock) UnRegisterAll() { } diff --git a/integrationTests/testProcessorNodeWithTestWebServer.go b/integrationTests/testProcessorNodeWithTestWebServer.go index b380a643660..02849a7803a 100644 --- a/integrationTests/testProcessorNodeWithTestWebServer.go +++ b/integrationTests/testProcessorNodeWithTestWebServer.go @@ -236,6 +236,7 @@ func createFacadeComponents(tpn *TestProcessorNode) nodeFacade.ApiResolver { TxTypeHandler: txTypeHandler, LogsFacade: logsFacade, DataFieldParser: dataFieldParser, + GasScheduleNotifier: gasScheduleNotifier, } apiTransactionHandler, err := transactionAPI.NewAPITransactionProcessor(argsApiTransactionProc) log.LogIfError(err) diff --git a/node/external/timemachine/fee/feeComputer.go b/node/external/timemachine/fee/feeComputer.go index 6d19ce05ceb..ee4d67910db 100644 --- a/node/external/timemachine/fee/feeComputer.go +++ b/node/external/timemachine/fee/feeComputer.go @@ -42,6 +42,7 @@ func (computer *feeComputer) ComputeTxFeeBasedOnGasUsed(tx *transaction.ApiTrans // ComputeGasLimit computes a transaction gas limit, at a given epoch func (computer *feeComputer) ComputeGasLimit(tx *transaction.ApiTransactionResult) uint64 { + computer.economicsInstance.MaxGasPriceSetGuardian() return computer.economicsInstance.ComputeGasLimitInEpoch(tx.Tx, tx.Epoch) } @@ -50,6 +51,11 @@ func (computer *feeComputer) ComputeTransactionFee(tx *transaction.ApiTransactio return computer.economicsInstance.ComputeTxFeeInEpoch(tx.Tx, tx.Epoch) } +// ComputeMoveBalanceFee computes a transaction's move balance fee, at a given epoch +func (computer *feeComputer) ComputeMoveBalanceFee(tx *transaction.ApiTransactionResult) *big.Int { + return computer.economicsInstance.ComputeMoveBalanceFeeInEpoch(tx.Tx, tx.Epoch) +} + // IsInterfaceNil returns true if there is no value under the interface func (computer *feeComputer) IsInterfaceNil() bool { return computer == nil diff --git a/node/external/transactionAPI/apiTransactionArgs.go b/node/external/transactionAPI/apiTransactionArgs.go index bb1aa10a659..a4ad9421a31 100644 --- a/node/external/transactionAPI/apiTransactionArgs.go +++ b/node/external/transactionAPI/apiTransactionArgs.go @@ -27,4 +27,5 @@ type ArgAPITransactionProcessor struct { TxTypeHandler process.TxTypeHandler LogsFacade LogsFacade DataFieldParser DataFieldParser + GasScheduleNotifier core.GasScheduleNotifier } diff --git a/node/external/transactionAPI/apiTransactionProcessor.go b/node/external/transactionAPI/apiTransactionProcessor.go index b12aa9ac86f..6528d195026 100644 --- a/node/external/transactionAPI/apiTransactionProcessor.go +++ b/node/external/transactionAPI/apiTransactionProcessor.go @@ -65,7 +65,7 @@ func NewAPITransactionProcessor(args *ArgAPITransactionProcessor) (*apiTransacti ) refundDetectorInstance := NewRefundDetector() - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(args.FeeComputer, args.AddressPubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor(args.FeeComputer, args.GasScheduleNotifier, args.AddressPubKeyConverter) return &apiTransactionProcessor{ roundDuration: args.RoundDuration, diff --git a/node/external/transactionAPI/apiTransactionProcessor_test.go b/node/external/transactionAPI/apiTransactionProcessor_test.go index 7d86a1610c5..fa13f040037 100644 --- a/node/external/transactionAPI/apiTransactionProcessor_test.go +++ b/node/external/transactionAPI/apiTransactionProcessor_test.go @@ -59,6 +59,7 @@ func createMockArgAPITransactionProcessor() *ArgAPITransactionProcessor { return &datafield.ResponseParseData{} }, }, + GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, } } @@ -459,6 +460,7 @@ func TestNode_GetTransactionWithResultsFromStorage(t *testing.T) { return &datafield.ResponseParseData{} }, }, + GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, } apiTransactionProc, _ := NewAPITransactionProcessor(args) @@ -1027,6 +1029,7 @@ func createAPITransactionProc(t *testing.T, epoch uint32, withDbLookupExt bool) TxTypeHandler: &testscommon.TxTypeHandlerMock{}, LogsFacade: &testscommon.LogsFacadeStub{}, DataFieldParser: dataFieldParser, + GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, } apiTransactionProc, err := NewAPITransactionProcessor(args) require.Nil(t, err) diff --git a/node/external/transactionAPI/check.go b/node/external/transactionAPI/check.go index 0959ba6c5db..bbb3e2ab9df 100644 --- a/node/external/transactionAPI/check.go +++ b/node/external/transactionAPI/check.go @@ -42,6 +42,9 @@ func checkNilArgs(arg *ArgAPITransactionProcessor) error { if check.IfNilReflect(arg.DataFieldParser) { return ErrNilDataFieldParser } + if check.IfNilReflect(arg.GasScheduleNotifier) { + return process.ErrNilGasSchedule + } return nil } diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index f0036bc136b..6e6f48ebccb 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -5,18 +5,21 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-go/common" datafield "github.com/multiversx/mx-chain-vm-common-go/parsers/dataField" ) type gasUsedAndFeeProcessor struct { - feeComputer feeComputer - pubKeyConverter core.PubkeyConverter + feeComputer feeComputer + gasScheduleNotifier core.GasScheduleNotifier + pubKeyConverter core.PubkeyConverter } -func newGasUsedAndFeeProcessor(txFeeCalculator feeComputer, pubKeyConverter core.PubkeyConverter) *gasUsedAndFeeProcessor { +func newGasUsedAndFeeProcessor(txFeeCalculator feeComputer, gasScheduleNotifier core.GasScheduleNotifier, pubKeyConverter core.PubkeyConverter) *gasUsedAndFeeProcessor { return &gasUsedAndFeeProcessor{ - feeComputer: txFeeCalculator, - pubKeyConverter: pubKeyConverter, + feeComputer: txFeeCalculator, + gasScheduleNotifier: gasScheduleNotifier, + pubKeyConverter: pubKeyConverter, } } @@ -32,6 +35,21 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction tx.Fee = tx.InitiallyPaidFee } + if gfp.isGuardianOperation(tx) { + gasUsed = gfp.feeComputer.ComputeGasLimit(tx) + guardianOperationCost := gfp.getGuardianOperationCost(tx) + gasUsed += guardianOperationCost + tx.GasUsed = gasUsed + + fee = big.NewInt(0).SetUint64(gasUsed * tx.GasPrice) + tx.Fee = fee.String() + + initiallyPaidFee := gfp.feeComputer.ComputeMoveBalanceFee(tx) + tx.InitiallyPaidFee = initiallyPaidFee.String() + + return + } + hasRefundForSender := false for _, scr := range tx.SmartContractResults { if !scr.IsRefund || scr.RcvAddr != tx.Sender { @@ -49,6 +67,30 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction gfp.prepareTxWithResultsBasedOnLogs(tx, hasRefundForSender) } +func (gfp *gasUsedAndFeeProcessor) getGuardianOperationCost(tx *transaction.ApiTransactionResult) uint64 { + gasSchedule, err := gfp.gasScheduleNotifier.GasScheduleForEpoch(tx.Epoch) + if err != nil { + return 0 + } + + switch tx.Operation { + case core.BuiltInFunctionSetGuardian: + return gasSchedule[common.BuiltInCost][core.BuiltInFunctionSetGuardian] + case core.BuiltInFunctionGuardAccount: + return gasSchedule[common.BuiltInCost][core.BuiltInFunctionGuardAccount] + case core.BuiltInFunctionUnGuardAccount: + return gasSchedule[common.BuiltInCost][core.BuiltInFunctionUnGuardAccount] + default: + return 0 + } +} + +func (gfp *gasUsedAndFeeProcessor) isGuardianOperation(tx *transaction.ApiTransactionResult) bool { + return tx.Operation == core.BuiltInFunctionSetGuardian || + tx.Operation == core.BuiltInFunctionGuardAccount || + tx.Operation == core.BuiltInFunctionUnGuardAccount +} + func (gfp *gasUsedAndFeeProcessor) prepareTxWithResultsBasedOnLogs( tx *transaction.ApiTransactionResult, hasRefund bool, diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go index 99541bfef5d..9a35be6efa9 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go @@ -38,7 +38,7 @@ func TestComputeTransactionGasUsedAndFeeMoveBalance(t *testing.T) { feeComp, _ := fee.NewFeeComputer(createEconomicsData(&enableEpochsHandlerMock.EnableEpochsHandlerStub{})) computer := fee.NewTestFeeComputer(feeComp) - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, pubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, &testscommon.GasScheduleNotifierMock{}, pubKeyConverter) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" receiver := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -68,7 +68,7 @@ func TestComputeTransactionGasUsedAndFeeLogWithError(t *testing.T) { })) computer := fee.NewTestFeeComputer(feeComp) - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, pubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, &testscommon.GasScheduleNotifierMock{}, pubKeyConverter) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" receiver := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -111,7 +111,7 @@ func TestComputeTransactionGasUsedAndFeeRelayedTxWithWriteLog(t *testing.T) { })) computer := fee.NewTestFeeComputer(feeComp) - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, pubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, &testscommon.GasScheduleNotifierMock{}, pubKeyConverter) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" receiver := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -149,7 +149,7 @@ func TestComputeTransactionGasUsedAndFeeTransactionWithScrWithRefund(t *testing. })) computer := fee.NewTestFeeComputer(feeComp) - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, pubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, &testscommon.GasScheduleNotifierMock{}, pubKeyConverter) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" receiver := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -197,7 +197,7 @@ func TestNFTTransferWithScCall(t *testing.T) { computer := fee.NewTestFeeComputer(feeComp) req.Nil(err) - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, pubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, &testscommon.GasScheduleNotifierMock{}, pubKeyConverter) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" receiver := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -221,3 +221,45 @@ func TestNFTTransferWithScCall(t *testing.T) { req.Equal(uint64(55_000_000), tx.GasUsed) req.Equal("822250000000000", tx.Fee) } + +func TestComputeAndAttachGasUsedAndFeeSetGuardian(t *testing.T) { + t.Parallel() + + feeComp, err := fee.NewFeeComputer(createEconomicsData(&enableEpochsHandlerMock.EnableEpochsHandlerStub{ + IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool { + return flag == common.GasPriceModifierFlag || flag == common.PenalizedTooMuchGasFlag + }, + })) + computer := fee.NewTestFeeComputer(feeComp) + require.NoError(t, err) + + gasSch := &testscommon.GasScheduleNotifierMock{ + GasSchedule: map[string]map[string]uint64{ + common.BuiltInCost: { + core.BuiltInFunctionSetGuardian: 250000, + }, + }, + } + + gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, gasSch, pubKeyConverter) + + sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" + + tx := &transaction.ApiTransactionResult{ + Tx: &transaction.Transaction{ + GasLimit: 475_500, + GasPrice: 1000000000, + SndAddr: silentDecodeAddress(sender), + RcvAddr: silentDecodeAddress(sender), + Data: []byte("SetGuardian@835741dd7018300bb4ed14211f9a9118ea7049572402c3a553deb1141f9c89aa@4d756c7469766572735854435353657276696365"), + }, + GasLimit: 475_500, + Operation: "SetGuardian", + GasPrice: 1000000000, + } + tx.InitiallyPaidFee = feeComp.ComputeTransactionFee(tx).String() + + gasUsedAndFeeProc.computeAndAttachGasUsedAndFee(tx) + require.Equal(t, uint64(475_500), tx.GasUsed) + require.Equal(t, "475500000000000", tx.Fee) +} diff --git a/node/external/transactionAPI/interface.go b/node/external/transactionAPI/interface.go index a32cac06184..77057e1de05 100644 --- a/node/external/transactionAPI/interface.go +++ b/node/external/transactionAPI/interface.go @@ -12,6 +12,7 @@ type feeComputer interface { ComputeTxFeeBasedOnGasUsed(tx *transaction.ApiTransactionResult, gasUsed uint64) *big.Int ComputeGasLimit(tx *transaction.ApiTransactionResult) uint64 ComputeTransactionFee(tx *transaction.ApiTransactionResult) *big.Int + ComputeMoveBalanceFee(tx *transaction.ApiTransactionResult) *big.Int IsInterfaceNil() bool } diff --git a/process/interface.go b/process/interface.go index 8e943d0a44e..e1c81fa6f96 100644 --- a/process/interface.go +++ b/process/interface.go @@ -680,6 +680,7 @@ type feeHandler interface { MaxGasLimitPerTx() uint64 ComputeGasLimit(tx data.TransactionWithFeeHandler) uint64 ComputeMoveBalanceFee(tx data.TransactionWithFeeHandler) *big.Int + ComputeMoveBalanceFeeInEpoch(tx data.TransactionWithFeeHandler, epoch uint32) *big.Int ComputeTxFee(tx data.TransactionWithFeeHandler) *big.Int CheckValidityTxValues(tx data.TransactionWithFeeHandler) error ComputeFeeForProcessing(tx data.TransactionWithFeeHandler, gasToUse uint64) *big.Int diff --git a/testscommon/economicsmocks/economicsDataHandlerStub.go b/testscommon/economicsmocks/economicsDataHandlerStub.go index bb59020bc27..c76ce6c59a2 100644 --- a/testscommon/economicsmocks/economicsDataHandlerStub.go +++ b/testscommon/economicsmocks/economicsDataHandlerStub.go @@ -49,6 +49,7 @@ type EconomicsHandlerStub struct { ComputeTxFeeBasedOnGasUsedInEpochCalled func(tx data.TransactionWithFeeHandler, gasUsed uint64, epoch uint32) *big.Int ComputeRelayedTxFeesCalled func(tx data.TransactionWithFeeHandler) (*big.Int, *big.Int, error) SetTxTypeHandlerCalled func(txTypeHandler process.TxTypeHandler) error + ComputeMoveBalanceFeeInEpochCalled func(tx data.TransactionWithFeeHandler, epoch uint32) *big.Int } // ComputeFeeForProcessing - @@ -228,6 +229,14 @@ func (e *EconomicsHandlerStub) ComputeMoveBalanceFee(tx data.TransactionWithFeeH return big.NewInt(0) } +// ComputeMoveBalanceFeeInEpoch - +func (e *EconomicsHandlerStub) ComputeMoveBalanceFeeInEpoch(tx data.TransactionWithFeeHandler, epoch uint32) *big.Int { + if e.ComputeMoveBalanceFeeInEpochCalled != nil { + return e.ComputeMoveBalanceFeeInEpochCalled(tx, epoch) + } + return big.NewInt(0) +} + // ComputeTxFee - func (e *EconomicsHandlerStub) ComputeTxFee(tx data.TransactionWithFeeHandler) *big.Int { if e.ComputeTxFeeCalled != nil { diff --git a/testscommon/economicsmocks/economicsHandlerMock.go b/testscommon/economicsmocks/economicsHandlerMock.go index 3506d2ba9a7..0c92fff0238 100644 --- a/testscommon/economicsmocks/economicsHandlerMock.go +++ b/testscommon/economicsmocks/economicsHandlerMock.go @@ -27,6 +27,7 @@ type EconomicsHandlerMock struct { ComputeFeeCalled func(tx data.TransactionWithFeeHandler) *big.Int CheckValidityTxValuesCalled func(tx data.TransactionWithFeeHandler) error ComputeMoveBalanceFeeCalled func(tx data.TransactionWithFeeHandler) *big.Int + ComputeMoveBalanceFeeInEpochCalled func(tx data.TransactionWithFeeHandler, epoch uint32) *big.Int ComputeTxFeeCalled func(tx data.TransactionWithFeeHandler) *big.Int DeveloperPercentageCalled func() float64 MinGasPriceCalled func() uint64 @@ -199,7 +200,14 @@ func (ehm *EconomicsHandlerMock) ComputeMoveBalanceFee(tx data.TransactionWithFe return ehm.ComputeMoveBalanceFeeCalled(tx) } return big.NewInt(0) +} +// ComputeMoveBalanceFeeInEpoch - +func (ehm *EconomicsHandlerMock) ComputeMoveBalanceFeeInEpoch(tx data.TransactionWithFeeHandler, epoch uint32) *big.Int { + if ehm.ComputeMoveBalanceFeeInEpochCalled != nil { + return ehm.ComputeMoveBalanceFeeInEpochCalled(tx, epoch) + } + return big.NewInt(0) } // ComputeGasLimitBasedOnBalance - diff --git a/testscommon/feeComputerStub.go b/testscommon/feeComputerStub.go index 33dcfbb4e4b..884351576d9 100644 --- a/testscommon/feeComputerStub.go +++ b/testscommon/feeComputerStub.go @@ -12,6 +12,7 @@ type FeeComputerStub struct { ComputeGasUsedAndFeeBasedOnRefundValueCalled func(tx *transaction.ApiTransactionResult, refundValue *big.Int) (uint64, *big.Int) ComputeTxFeeBasedOnGasUsedCalled func(tx *transaction.ApiTransactionResult, gasUsed uint64) *big.Int ComputeGasLimitCalled func(tx *transaction.ApiTransactionResult) uint64 + ComputeMoveBalanceFeeCalled func(tx *transaction.ApiTransactionResult) *big.Int } // ComputeTransactionFee - @@ -49,6 +50,15 @@ func (stub *FeeComputerStub) ComputeGasLimit(tx *transaction.ApiTransactionResul return 0 } +// ComputeMoveBalanceFee - +func (stub *FeeComputerStub) ComputeMoveBalanceFee(tx *transaction.ApiTransactionResult) *big.Int { + if stub.ComputeMoveBalanceFeeCalled != nil { + return stub.ComputeMoveBalanceFeeCalled(tx) + } + + return big.NewInt(0) +} + // IsInterfaceNil returns true if there is no value under the interface func (stub *FeeComputerStub) IsInterfaceNil() bool { return false diff --git a/testscommon/gasScheduleNotifierMock.go b/testscommon/gasScheduleNotifierMock.go index dd0f728cfad..e7894c25e40 100644 --- a/testscommon/gasScheduleNotifierMock.go +++ b/testscommon/gasScheduleNotifierMock.go @@ -8,6 +8,7 @@ type GasScheduleNotifierMock struct { RegisterNotifyHandlerCalled func(handler core.GasScheduleSubscribeHandler) LatestGasScheduleCalled func() map[string]map[string]uint64 LatestGasScheduleCopyCalled func() map[string]map[string]uint64 + GasScheduleForEpochCalled func(epoch uint32) (map[string]map[string]uint64, error) } // NewGasScheduleNotifierMock - @@ -50,6 +51,15 @@ func (g *GasScheduleNotifierMock) LatestGasScheduleCopy() map[string]map[string] func (g *GasScheduleNotifierMock) UnRegisterAll() { } +// GasScheduleForEpoch - +func (g *GasScheduleNotifierMock) GasScheduleForEpoch(epoch uint32) (map[string]map[string]uint64, error) { + if g.GasScheduleForEpochCalled != nil { + return g.GasScheduleForEpochCalled(epoch) + } + + return g.GasSchedule, nil +} + // IsInterfaceNil - func (g *GasScheduleNotifierMock) IsInterfaceNil() bool { return g == nil From 8fd393ce7e4904fe41a9fbca6a34ea2672351b6d Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 29 Jul 2024 11:36:55 +0300 Subject: [PATCH 447/503] updated deps --- go.mod | 24 ++++++++++++------------ go.sum | 48 ++++++++++++++++++++++++------------------------ 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/go.mod b/go.mod index 809222ccff9..e2d3cb99819 100644 --- a/go.mod +++ b/go.mod @@ -14,18 +14,18 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 - github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240725071304-ebce652ff65d - github.com/multiversx/mx-chain-core-go v1.2.21-0.20240725065431-6e9bfee5a4c6 - github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f - github.com/multiversx/mx-chain-es-indexer-go v1.7.3-0.20240725073933-b3457c5308ca - github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240725065747-176bd697c775 - github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240725072925-89c927c8b6a6 - github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240725070753-aa7fb322ebdf - github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240725072715-8806f1301087 - github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240726084628-e3e50b6f78d7 - github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240725073104-85ec99cb9260 - github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240725073322-952f3197e2e2 - github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98-0.20240725073616-3b96f06509cf + github.com/multiversx/mx-chain-communication-go v1.1.0 + github.com/multiversx/mx-chain-core-go v1.2.21 + github.com/multiversx/mx-chain-crypto-go v1.2.12 + github.com/multiversx/mx-chain-es-indexer-go v1.7.4 + github.com/multiversx/mx-chain-logger-go v1.0.15 + github.com/multiversx/mx-chain-scenario-go v1.4.4 + github.com/multiversx/mx-chain-storage-go v1.0.16 + github.com/multiversx/mx-chain-vm-common-go v1.5.13 + github.com/multiversx/mx-chain-vm-go v1.5.30 + github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 + github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 + github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 github.com/pelletier/go-toml v1.9.3 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.14.0 diff --git a/go.sum b/go.sum index 20cd9322e3b..5c4d74b40ab 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.20240725071304-ebce652ff65d h1:grQCJW4DCvvIQ6q84sy23oAp8XQ8Dxr3Js8aoh+m99M= -github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240725071304-ebce652ff65d/go.mod h1:hFGM+O7rt+gWXSHFoRjC3/oN0OJfPfeFAxqXIac5UdQ= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240725065431-6e9bfee5a4c6 h1:Q7uUjTYTrt8Mw9oq5JWPv+WHhpxHTv6lhZZlhPuNcoQ= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240725065431-6e9bfee5a4c6/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= -github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f h1:jydjrmVFvSllBOTppveOAkLITpOYKk0kma5z0bfDImI= -github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f/go.mod h1:9aSp//uBSvqFdzh4gvYISraoruhr1FCTXgPQalQ687k= -github.com/multiversx/mx-chain-es-indexer-go v1.7.3-0.20240725073933-b3457c5308ca h1:9b2yFAarWDG/jTYePv0UqNWQ9gxeSZy9mGxtd8dFj2Y= -github.com/multiversx/mx-chain-es-indexer-go v1.7.3-0.20240725073933-b3457c5308ca/go.mod h1:bHPP5zerhmbRfVcbfXgpMPUaTKMrK6gGi+rRbw0BpDE= -github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240725065747-176bd697c775 h1:a8LOfz3p4MQfRtbF00rGDAJiebziwtSfVmBHIaHBDdY= -github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240725065747-176bd697c775/go.mod h1:owPYyrK7RcsLx9eOCAZQ22fIyW6BE7ttJr4XIhFIbQw= -github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240725072925-89c927c8b6a6 h1:QGQjSlPix5nBtCkcdyKo0b2sRYXwYF/GBtccOqDbU6Y= -github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240725072925-89c927c8b6a6/go.mod h1:MvJiMtuyGq43aS9eOgF+xQUWk0hYxvCQqLrT77bhBaE= -github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240725070753-aa7fb322ebdf h1:L9K7Xzq5SZz6k55R7HrafiRcU+c8/PqozJxys65G4bI= -github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240725070753-aa7fb322ebdf/go.mod h1:ptvW/8r6bam55mVpeVZbyvvvydYM0DQwcPOH0W4Xyx8= -github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240725072715-8806f1301087 h1:ovxs8X50iBL9TOkn0qHrkuXrBS1Y/EWfQOYmFEaXRNs= -github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240725072715-8806f1301087/go.mod h1:nNGN+rdLRN8Nd6OhFGrkEZS5Ipj5IQCvFT0L/iQbOpU= -github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240726084628-e3e50b6f78d7 h1:LN9W/RcrhNR3dLB9FhsuCl9fViwceyjzMUeL/s9SBIs= -github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240726084628-e3e50b6f78d7/go.mod h1:CFOSVrsHOzaO5YX2L/wyjP76L+BE/9rh+SereQV3pHA= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240725073104-85ec99cb9260 h1:Ny3s7dw2oF6AVq4kZYmhNYWvAuLEbd48JPPIC6tFzOA= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240725073104-85ec99cb9260/go.mod h1:NFRX6UrkBMb28HFKZyKwH894uxfrZyfuFqMF1KBVqFw= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240725073322-952f3197e2e2 h1:TM45+UXZV5DYOHlbGiHyQm44hOlBid8g9qfvYqopILs= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240725073322-952f3197e2e2/go.mod h1:Ntfq9tUV3I5k6SS/OpW4HSO6AlZbs/xxgB2poOuc2pg= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98-0.20240725073616-3b96f06509cf h1:axwaSswcaw8pituLVAu4IWlGNtYwXvUMYy+MGPwmxuY= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98-0.20240725073616-3b96f06509cf/go.mod h1:2TjMTiVFkh5wFImEEFZl+k5MU8bh2287btJuVCR3sL0= +github.com/multiversx/mx-chain-communication-go v1.1.0 h1:J7bX6HoN3HiHY7cUeEjG8AJWgQDDPcY+OPDOsSUOkRE= +github.com/multiversx/mx-chain-communication-go v1.1.0/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= +github.com/multiversx/mx-chain-core-go v1.2.21 h1:+XVKznPTlUU5EFS1A8chtS8fStW60upRIyF4Pgml19I= +github.com/multiversx/mx-chain-core-go v1.2.21/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.4 h1:SjJk9G9SN8baz0sFIU2jymYCfx3XiikGEB2wW0jwvfw= +github.com/multiversx/mx-chain-es-indexer-go v1.7.4/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.13 h1:ymnIHJW4Z4mFa0hZzla4fozkF30vjH5O1q+Y7Ftc+pQ= +github.com/multiversx/mx-chain-vm-common-go v1.5.13/go.mod h1:OSvFbzdWThfRbLZbUsEr7bikBSaLrPJQ2iUm9jw9nXQ= +github.com/multiversx/mx-chain-vm-go v1.5.30 h1:CXBQF3o+dai4nx2qYfMIACva+6SqPO5fZjZtVq72RTI= +github.com/multiversx/mx-chain-vm-go v1.5.30/go.mod h1:iq6sCPweoHC9Fx56uf8buPrqlGVGJKUMRFxTunzjvys= +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 c9e292c0bc22c22c73c026f46dd323fb13cd777e Mon Sep 17 00:00:00 2001 From: ssd04 Date: Mon, 29 Jul 2024 18:27:13 +0300 Subject: [PATCH 448/503] use setSpecialRole function in tests --- .../vm/egldMultiTransfer_test.go | 49 ++- .../vm/esdtImprovements_test.go | 332 +++++++++--------- 2 files changed, 202 insertions(+), 179 deletions(-) diff --git a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go index 8638445dacf..d7c06a7901d 100644 --- a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go +++ b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go @@ -66,7 +66,9 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { // issue metaESDT metaESDTTicker := []byte("METATTICKER") - tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueMetaESDTTx(nonce, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -80,12 +82,14 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { []byte(core.ESDTRoleTransfer), } setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + nonce++ log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) // issue NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -94,12 +98,14 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { nftTokenID := txResult.Logs.Events[0].Topics[0] setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(nonce, addrs[0].Bytes, sftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -108,6 +114,7 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { sftTokenID := txResult.Logs.Events[0].Topics[0] setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + nonce++ log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -132,7 +139,6 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { esdtMetaData, } - nonce := uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) @@ -241,7 +247,9 @@ func TestChainSimulator_EGLD_MultiTransfer_Insufficient_Funds(t *testing.T) { // issue NFT nftTicker := []byte("NFTTICKER") - tx := issueNonFungibleTx(0, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -255,13 +263,15 @@ func TestChainSimulator_EGLD_MultiTransfer_Insufficient_Funds(t *testing.T) { []byte(core.ESDTRoleTransfer), } setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -359,7 +369,9 @@ func TestChainSimulator_EGLD_MultiTransfer_Invalid_Value(t *testing.T) { // issue NFT nftTicker := []byte("NFTTICKER") - tx := issueNonFungibleTx(0, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -373,13 +385,15 @@ func TestChainSimulator_EGLD_MultiTransfer_Invalid_Value(t *testing.T) { []byte(core.ESDTRoleTransfer), } setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -477,7 +491,9 @@ func TestChainSimulator_Multiple_EGLD_Transfers(t *testing.T) { // issue NFT nftTicker := []byte("NFTTICKER") - tx := issueNonFungibleTx(0, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -491,13 +507,15 @@ func TestChainSimulator_Multiple_EGLD_Transfers(t *testing.T) { []byte(core.ESDTRoleTransfer), } setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -686,7 +704,9 @@ func TestChainSimulator_IssueToken_EGLDTicker(t *testing.T) { // issue NFT nftTicker := []byte("EGLD") - tx := issueNonFungibleTx(0, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -700,13 +720,15 @@ func TestChainSimulator_IssueToken_EGLDTicker(t *testing.T) { []byte(core.ESDTRoleTransfer), } setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -723,7 +745,8 @@ func TestChainSimulator_IssueToken_EGLDTicker(t *testing.T) { log.Info("Issue token (after activation of EGLDInMultiTransferFlag)") // should fail issuing token with EGLD ticker - tx = issueNonFungibleTx(2, addrs[0].Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index e94ba571162..ad17776c87d 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -118,8 +118,10 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran log.Info("Initial setup: Create NFT, SFT and metaESDT tokens (before the activation of DynamicEsdtFlag)") // issue metaESDT - metaESDTTicker := []byte("METATTICKER") - tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + metaESDTTicker := []byte("METATICKER") + nonce := uint64(0) + tx := issueMetaESDTTx(nonce, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -138,7 +140,8 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran // issue NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -152,7 +155,8 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(nonce, addrs[0].Bytes, sftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -185,7 +189,6 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran esdtMetaData, } - nonce := uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) @@ -668,6 +671,42 @@ func getMetaDataFromAcc( return esdtData.TokenMetaData } +func setSpecialRoleTx( + nonce uint64, + sndAddr []byte, + address []byte, + token []byte, + roles [][]byte, +) *transaction.Transaction { + txDataBytes := [][]byte{ + []byte("setSpecialRole"), + []byte(hex.EncodeToString(token)), + []byte(hex.EncodeToString(address)), + } + + for _, role := range roles { + txDataBytes = append(txDataBytes, []byte(hex.EncodeToString(role))) + } + + txDataField := bytes.Join( + txDataBytes, + []byte("@"), + ) + + return &transaction.Transaction{ + Nonce: nonce, + SndAddr: sndAddr, + RcvAddr: vm.ESDTSCAddress, + GasLimit: 60_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } +} + func setAddressEsdtRoles( t *testing.T, cs testsChainSimulator.ChainSimulator, @@ -722,8 +761,10 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { log.Info("Initial setup: Create NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") // issue metaESDT - metaESDTTicker := []byte("METATTICKER") - tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + metaESDTTicker := []byte("METATICKER") + nonce := uint64(0) + tx := issueMetaESDTTx(nonce, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -789,7 +830,7 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { esdtMetaData, } - nonce := uint64(3) + nonce = uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) @@ -841,7 +882,7 @@ func TestChainSimulator_ESDTMetaDataRecreate(t *testing.T) { addrs := createAddresses(t, cs, false) // issue metaESDT - metaESDTTicker := []byte("METATTICKER") + metaESDTTicker := []byte("METATICKER") tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -853,7 +894,6 @@ func TestChainSimulator_ESDTMetaDataRecreate(t *testing.T) { roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), - []byte(core.ESDTRoleNFTRecreate), } setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) @@ -918,6 +958,30 @@ func TestChainSimulator_ESDTMetaDataRecreate(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nonce++ + + tx = changeToDynamicTx(nonce, addrs[0].Bytes, tokenIDs[i]) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + + roles := [][]byte{ + []byte(core.ESDTRoleNFTRecreate), + } + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, tokenIDs[i], roles) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult) + + require.Equal(t, "success", txResult.Status.String()) + + nonce++ } err = cs.GenerateBlocks(10) @@ -1000,7 +1064,7 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { addrs := createAddresses(t, cs, false) // issue metaESDT - metaESDTTicker := []byte("METATTICKER") + metaESDTTicker := []byte("METATICKER") tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -1013,7 +1077,6 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), - []byte(core.ESDTRoleNFTUpdate), } setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) @@ -1079,6 +1142,32 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nonce++ + + tx = changeToDynamicTx(nonce, addrs[0].Bytes, tokenIDs[i]) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + + roles := [][]byte{ + []byte(core.ESDTRoleNFTUpdate), + } + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, tokenIDs[i], roles) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) + + nonce++ } log.Info("Call ESDTMetaDataUpdate to rewrite the meta data for the nft") @@ -1123,6 +1212,10 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + require.Equal(t, "success", txResult.Status.String()) shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) @@ -1299,145 +1392,10 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { roles = [][]byte{ []byte(core.ESDTRoleModifyCreator), } - setAddressEsdtRoles(t, cs, newCreatorAddress, tokenIDs[i], roles) - - tx = modifyCreatorTx(0, newCreatorAddress.Bytes, tokenIDs[i]) - - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - - require.Equal(t, "success", txResult.Status.String()) - - retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID) - - require.Equal(t, newCreatorAddress.Bytes, retrievedMetaData.Creator) - - nonce++ - } -} - -// ESDTModifyCreator without changing to dynamic type -func TestChainSimulator_ESDTModifyCreator_SFTmetaESDT(t *testing.T) { - if testing.Short() { - t.Skip("this is not a short test") - } - - baseIssuingCost := "1000" - - cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) - defer cs.Close() - - log.Info("Initial setup: Create SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") - - addrs := createAddresses(t, cs, false) - - // issue metaESDT - metaESDTTicker := []byte("METATICKER") - tx := issueMetaESDTTx(0, addrs[1].Bytes, metaESDTTicker, baseIssuingCost) - - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - - require.Equal(t, "success", txResult.Status.String()) - - metaESDTTokenID := txResult.Logs.Events[0].Topics[0] - - roles := [][]byte{ - []byte(core.ESDTRoleNFTCreate), - []byte(core.ESDTRoleTransfer), - []byte(core.ESDTRoleNFTUpdate), - } - setAddressEsdtRoles(t, cs, addrs[1], metaESDTTokenID, roles) - - log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) - - // issue SFT - sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(1, addrs[1].Bytes, sftTicker, baseIssuingCost) - - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - - sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[1], sftTokenID, roles) - - log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) - - tokenIDs := [][]byte{ - metaESDTTokenID, - sftTokenID, - } - - sftMetaData := txsFee.GetDefaultMetaData() - sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - - esdtMetaData := txsFee.GetDefaultMetaData() - esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - - tokensMetadata := []*txsFee.MetaData{ - esdtMetaData, - sftMetaData, - } - - nonce := uint64(2) - for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[1].Bytes, tokenIDs[i], tokensMetadata[i]) - - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - - require.Equal(t, "success", txResult.Status.String()) - + tx = setSpecialRoleTx(nonce, addrs[1].Bytes, newCreatorAddress.Bytes, tokenIDs[i], roles) nonce++ - } - for _, tokenID := range tokenIDs { - tx = updateTokenIDTx(nonce, addrs[1].Bytes, tokenID) - - log.Info("updating token id", "tokenID", tokenID) - - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - - require.Equal(t, "success", txResult.Status.String()) - - nonce++ - } - - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[1].Bytes) - - checkMetaData(t, cs, core.SystemAccountAddress, sftTokenID, shardID, sftMetaData) - checkMetaData(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID, esdtMetaData) - - log.Info("Call ESDTModifyCreator and check that the creator was modified") - - mintValue := big.NewInt(10) - mintValue = mintValue.Mul(oneEGLD, mintValue) - - for i := range tokenIDs { - log.Info("Modify creator for token", "tokenID", string(tokenIDs[i])) - - newCreatorAddress, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) - require.Nil(t, err) - - err = cs.GenerateBlocks(10) - require.Nil(t, err) - - roles = [][]byte{ - []byte(core.ESDTRoleModifyCreator), - } - setAddressEsdtRoles(t, cs, newCreatorAddress, tokenIDs[i], roles) - - log.Info("transfering token id", "tokenID", tokenIDs[i]) - - tx = esdtNFTTransferTx(nonce, addrs[1].Bytes, newCreatorAddress.Bytes, tokenIDs[i]) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) @@ -1453,8 +1411,6 @@ func TestChainSimulator_ESDTModifyCreator_SFTmetaESDT(t *testing.T) { retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID) require.Equal(t, newCreatorAddress.Bytes, retrievedMetaData.Creator) - - nonce++ } } @@ -1617,7 +1573,13 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { roles = [][]byte{ []byte(core.ESDTRoleModifyCreator), } - setAddressEsdtRoles(t, cs, newCreatorAddress, tokenIDs[i], roles) + tx = setSpecialRoleTx(nonce, addrs[1].Bytes, newCreatorAddress.Bytes, tokenIDs[i], roles) + nonce++ + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("transfering token id", "tokenID", tokenIDs[i]) @@ -1637,10 +1599,6 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(newCreatorAddress.Bytes) @@ -1671,8 +1629,10 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { addrs := createAddresses(t, cs, false) // issue metaESDT - metaESDTTicker := []byte("METATTICKER") - tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + metaESDTTicker := []byte("METATICKER") + nonce := uint64(0) + tx := issueMetaESDTTx(nonce, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1682,10 +1642,10 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { metaESDTTokenID := txResult.Logs.Events[0].Topics[0] roles := [][]byte{ + []byte(core.ESDTRoleNFTBurn), []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), []byte(core.ESDTRoleNFTUpdate), - []byte(core.ESDTRoleSetNewURI), } setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) @@ -1693,7 +1653,8 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { // issue NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1707,7 +1668,8 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(nonce, addrs[0].Bytes, sftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1740,14 +1702,33 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { esdtMetaData, } - nonce := uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + + tx = changeToDynamicTx(nonce, addrs[0].Bytes, tokenIDs[i]) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + roles := [][]byte{ + []byte(core.ESDTRoleSetNewURI), + } + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, tokenIDs[i], roles) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) nonce++ @@ -1799,7 +1780,6 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) @@ -1835,7 +1815,7 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { addrs := createAddresses(t, cs, false) // issue metaESDT - metaESDTTicker := []byte("METATTICKER") + metaESDTTicker := []byte("METATICKER") tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -1849,7 +1829,6 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), []byte(core.ESDTRoleNFTUpdate), - []byte(core.ESDTRoleModifyRoyalties), } setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) @@ -1915,6 +1894,27 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nonce++ + + tx = changeToDynamicTx(nonce, addrs[0].Bytes, tokenIDs[i]) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + + roles := [][]byte{ + []byte(core.ESDTRoleModifyRoyalties), + } + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, tokenIDs[i], roles) + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nonce++ } log.Info("Call ESDTModifyRoyalties and check that the royalties were changed") @@ -3242,7 +3242,7 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { addrs := createAddresses(t, cs, false) // issue metaESDT - metaESDTTicker := []byte("METATTICKER") + metaESDTTicker := []byte("METATICKER") tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) From e46a815e1a9e7d9013c4a0c9f1ee2a3ac13e9009 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 30 Jul 2024 09:50:29 +0300 Subject: [PATCH 449/503] fix linter issues --- .../chainSimulator/vm/egldMultiTransfer_test.go | 7 ------- .../chainSimulator/vm/esdtImprovements_test.go | 16 ++++------------ 2 files changed, 4 insertions(+), 19 deletions(-) diff --git a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go index d7c06a7901d..162ce5f4efb 100644 --- a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go +++ b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go @@ -82,7 +82,6 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { []byte(core.ESDTRoleTransfer), } setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) - nonce++ log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) @@ -98,7 +97,6 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { nftTokenID := txResult.Logs.Events[0].Topics[0] setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) - nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) @@ -114,7 +112,6 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { sftTokenID := txResult.Logs.Events[0].Topics[0] setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) - nonce++ log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -263,7 +260,6 @@ func TestChainSimulator_EGLD_MultiTransfer_Insufficient_Funds(t *testing.T) { []byte(core.ESDTRoleTransfer), } setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) - nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) @@ -385,7 +381,6 @@ func TestChainSimulator_EGLD_MultiTransfer_Invalid_Value(t *testing.T) { []byte(core.ESDTRoleTransfer), } setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) - nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) @@ -507,7 +502,6 @@ func TestChainSimulator_Multiple_EGLD_Transfers(t *testing.T) { []byte(core.ESDTRoleTransfer), } setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) - nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) @@ -720,7 +714,6 @@ func TestChainSimulator_IssueToken_EGLDTicker(t *testing.T) { []byte(core.ESDTRoleTransfer), } setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) - nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index ad17776c87d..62d4da6d6fa 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -783,7 +783,8 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { // issue NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -797,7 +798,8 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(nonce, addrs[0].Bytes, sftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -977,8 +979,6 @@ func TestChainSimulator_ESDTMetaDataRecreate(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - require.Equal(t, "success", txResult.Status.String()) nonce++ @@ -1161,10 +1161,6 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) nonce++ @@ -1212,10 +1208,6 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - require.Equal(t, "success", txResult.Status.String()) shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) From 2b97908d922372ee2ee190fe982ca756ecb63812 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 30 Jul 2024 09:50:57 +0300 Subject: [PATCH 450/503] fix missing ESDTRoleNFTUpdate role --- vm/systemSmartContracts/esdt.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/vm/systemSmartContracts/esdt.go b/vm/systemSmartContracts/esdt.go index 5daa2f2eb19..63f612610f3 100644 --- a/vm/systemSmartContracts/esdt.go +++ b/vm/systemSmartContracts/esdt.go @@ -1641,6 +1641,11 @@ func (e *esdt) isSpecialRoleValidForNonFungible(argument string) error { return nil } return vm.ErrInvalidArgument + case core.ESDTRoleNFTUpdate: + if e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) { + return nil + } + return vm.ErrInvalidArgument default: return vm.ErrInvalidArgument } @@ -1666,6 +1671,8 @@ func (e *esdt) isSpecialRoleValidForDynamicNFT(argument string) error { return nil case core.ESDTRoleNFTRecreate: return nil + case core.ESDTRoleNFTUpdate: + return nil default: return vm.ErrInvalidArgument } From 18baf55d275930177af6bfa0640a1489535cc9ee Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 30 Jul 2024 09:57:39 +0300 Subject: [PATCH 451/503] fix nonce var linter --- integrationTests/chainSimulator/vm/egldMultiTransfer_test.go | 3 --- integrationTests/chainSimulator/vm/esdtImprovements_test.go | 1 - 2 files changed, 4 deletions(-) diff --git a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go index 162ce5f4efb..caaa6fac41d 100644 --- a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go +++ b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go @@ -267,7 +267,6 @@ func TestChainSimulator_EGLD_MultiTransfer_Insufficient_Funds(t *testing.T) { nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -388,7 +387,6 @@ func TestChainSimulator_EGLD_MultiTransfer_Invalid_Value(t *testing.T) { nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -739,7 +737,6 @@ func TestChainSimulator_IssueToken_EGLDTicker(t *testing.T) { // should fail issuing token with EGLD ticker tx = issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 62d4da6d6fa..6401a67e640 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -832,7 +832,6 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { esdtMetaData, } - nonce = uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) From 01aa23cb09d7ba59dc363a32083fe7ada3f76e72 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 30 Jul 2024 10:01:27 +0300 Subject: [PATCH 452/503] fix linter issue --- integrationTests/chainSimulator/vm/egldMultiTransfer_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go index caaa6fac41d..75974fbec35 100644 --- a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go +++ b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go @@ -507,7 +507,6 @@ func TestChainSimulator_Multiple_EGLD_Transfers(t *testing.T) { nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) From c5975d8f5aba796854c353897eae7a93a1bb23d8 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 30 Jul 2024 13:30:57 +0300 Subject: [PATCH 453/503] refactor to use setSpecialRole in all tests --- .../vm/egldMultiTransfer_test.go | 39 +- .../vm/esdtImprovements_test.go | 537 ++++++++++++------ .../chainSimulator/vm/esdtTokens_test.go | 39 +- 3 files changed, 419 insertions(+), 196 deletions(-) diff --git a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go index 75974fbec35..52aaa9b7e36 100644 --- a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go +++ b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go @@ -2,6 +2,7 @@ package vm import ( "encoding/hex" + "fmt" "math/big" "strings" "testing" @@ -65,7 +66,7 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { require.Nil(t, err) // issue metaESDT - metaESDTTicker := []byte("METATTICKER") + metaESDTTicker := []byte("METATICKER") nonce := uint64(0) tx := issueMetaESDTTx(nonce, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) nonce++ @@ -81,7 +82,8 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], metaESDTTokenID, roles) + nonce++ log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) @@ -96,7 +98,8 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) @@ -111,7 +114,8 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], sftTokenID, roles) + nonce++ log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -143,6 +147,10 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { require.Nil(t, err) require.NotNil(t, txResult) + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + require.Equal(t, "success", txResult.Status.String()) nonce++ @@ -259,7 +267,8 @@ func TestChainSimulator_EGLD_MultiTransfer_Insufficient_Funds(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) @@ -267,6 +276,7 @@ func TestChainSimulator_EGLD_MultiTransfer_Insufficient_Funds(t *testing.T) { nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -289,7 +299,8 @@ func TestChainSimulator_EGLD_MultiTransfer_Insufficient_Funds(t *testing.T) { egldValue, _ := big.NewInt(0).SetString(beforeBalanceStr0, 10) egldValue = egldValue.Add(egldValue, big.NewInt(13)) - tx = multiESDTNFTTransferWithEGLDTx(2, addrs[0].Bytes, addrs[1].Bytes, [][]byte{nftTokenID}, egldValue) + tx = multiESDTNFTTransferWithEGLDTx(nonce, addrs[0].Bytes, addrs[1].Bytes, [][]byte{nftTokenID}, egldValue) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -379,7 +390,8 @@ func TestChainSimulator_EGLD_MultiTransfer_Invalid_Value(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) @@ -387,6 +399,7 @@ func TestChainSimulator_EGLD_MultiTransfer_Invalid_Value(t *testing.T) { nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -408,7 +421,8 @@ func TestChainSimulator_EGLD_MultiTransfer_Invalid_Value(t *testing.T) { beforeBalanceStr1 := account1.Balance egldValue := oneEGLD.Mul(oneEGLD, big.NewInt(3)) - tx = multiESDTNFTTransferWithEGLDTx(2, addrs[0].Bytes, addrs[1].Bytes, [][]byte{nftTokenID}, egldValue) + tx = multiESDTNFTTransferWithEGLDTx(nonce, addrs[0].Bytes, addrs[1].Bytes, [][]byte{nftTokenID}, egldValue) + nonce++ tx.Value = egldValue // invalid value field txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -499,7 +513,8 @@ func TestChainSimulator_Multiple_EGLD_Transfers(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) @@ -507,6 +522,7 @@ func TestChainSimulator_Multiple_EGLD_Transfers(t *testing.T) { nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -550,7 +566,7 @@ func TestChainSimulator_Multiple_EGLD_Transfers(t *testing.T) { ) tx = &transaction.Transaction{ - Nonce: 2, + Nonce: nonce, SndAddr: addrs[0].Bytes, RcvAddr: addrs[0].Bytes, GasLimit: 10_000_000, @@ -710,7 +726,8 @@ func TestChainSimulator_IssueToken_EGLDTicker(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 6401a67e640..bdabac5b2c9 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -134,7 +134,16 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], metaESDTTokenID, roles) + nonce++ + + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[1].Bytes, metaESDTTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) @@ -149,7 +158,16 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ + + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[1].Bytes, nftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) @@ -164,7 +182,16 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], sftTokenID, roles) + nonce++ + + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[1].Bytes, sftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -225,6 +252,9 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) require.Equal(t, "success", txResult.Status.String()) @@ -287,6 +317,9 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) require.Equal(t, "success", txResult.Status.String()) } else { @@ -710,33 +743,24 @@ func setSpecialRoleTx( func setAddressEsdtRoles( t *testing.T, cs testsChainSimulator.ChainSimulator, + nonce uint64, address dtos.WalletAddress, token []byte, roles [][]byte, ) { - marshaller := cs.GetNodeHandler(0).GetCoreComponents().InternalMarshalizer() - - rolesKey := append([]byte(core.ProtectedKeyPrefix), append([]byte(core.ESDTRoleIdentifier), []byte(core.ESDTKeyIdentifier)...)...) - rolesKey = append(rolesKey, token...) + tx := setSpecialRoleTx(nonce, address.Bytes, address.Bytes, token, roles) - rolesData := &esdt.ESDTRoles{ - Roles: roles, - } - - rolesDataBytes, err := marshaller.Marshal(rolesData) + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) + require.NotNil(t, txResult) - keys := make(map[string]string) - keys[hex.EncodeToString(rolesKey)] = hex.EncodeToString(rolesDataBytes) + fmt.Println(txResult) + if txResult.Logs != nil && len(txResult.Logs.Events) > 0 { + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + } - err = cs.SetStateMultiple([]*dtos.AddressState{ - { - Address: address.Bech32, - Balance: "10000000000000000000000", - Pairs: keys, - }, - }) - require.Nil(t, err) + require.Equal(t, "success", txResult.Status.String()) } // Test scenario #3 @@ -777,7 +801,8 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], metaESDTTokenID, roles) + nonce++ log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) @@ -792,7 +817,8 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) @@ -807,7 +833,8 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], sftTokenID, roles) + nonce++ log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -884,7 +911,9 @@ func TestChainSimulator_ESDTMetaDataRecreate(t *testing.T) { // issue metaESDT metaESDTTicker := []byte("METATICKER") - tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueMetaESDTTx(nonce, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -896,13 +925,20 @@ func TestChainSimulator_ESDTMetaDataRecreate(t *testing.T) { roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), } - setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, metaESDTTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) // issue NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -910,13 +946,20 @@ func TestChainSimulator_ESDTMetaDataRecreate(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, nftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(nonce, addrs[0].Bytes, sftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -924,7 +967,13 @@ func TestChainSimulator_ESDTMetaDataRecreate(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, sftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -949,7 +998,6 @@ func TestChainSimulator_ESDTMetaDataRecreate(t *testing.T) { esdtMetaData, } - nonce := uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) @@ -1064,7 +1112,9 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { // issue metaESDT metaESDTTicker := []byte("METATICKER") - tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueMetaESDTTx(nonce, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1077,13 +1127,20 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, metaESDTTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) // issue NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1091,13 +1148,20 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, nftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(nonce, addrs[0].Bytes, sftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1105,7 +1169,13 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, sftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -1130,7 +1200,6 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { esdtMetaData, } - nonce := uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) @@ -1243,7 +1312,9 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { // issue metaESDT metaESDTTicker := []byte("METATICKER") - tx := issueMetaESDTTx(0, addrs[1].Bytes, metaESDTTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueMetaESDTTx(nonce, addrs[1].Bytes, metaESDTTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1256,9 +1327,15 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), - []byte(core.ESDTRoleNFTUpdate), } - setAddressEsdtRoles(t, cs, addrs[1], metaESDTTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[1].Bytes, addrs[1].Bytes, metaESDTTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) @@ -1279,7 +1356,7 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) tx = &transaction.Transaction{ - Nonce: 1, + Nonce: nonce, SndAddr: addrs[1].Bytes, RcvAddr: vm.ESDTSCAddress, GasLimit: 100_000_000, @@ -1290,6 +1367,7 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { ChainID: []byte(configs.ChainID), Version: 1, } + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1298,13 +1376,20 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[1], nftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[1].Bytes, addrs[1].Bytes, nftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[1].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(nonce, addrs[1].Bytes, sftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1312,7 +1397,13 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[1], sftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[1].Bytes, addrs[1].Bytes, sftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -1337,7 +1428,6 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { esdtMetaData, } - nonce := uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[1].Bytes, tokenIDs[i], tokensMetadata[i]) @@ -1419,7 +1509,9 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { // issue metaESDT metaESDTTicker := []byte("METATICKER") - tx := issueMetaESDTTx(0, addrs[1].Bytes, metaESDTTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueMetaESDTTx(nonce, addrs[1].Bytes, metaESDTTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1432,9 +1524,14 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), - []byte(core.ESDTRoleNFTUpdate), } - setAddressEsdtRoles(t, cs, addrs[1], metaESDTTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[1].Bytes, addrs[1].Bytes, metaESDTTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) @@ -1455,7 +1552,7 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) tx = &transaction.Transaction{ - Nonce: 1, + Nonce: nonce, SndAddr: addrs[1].Bytes, RcvAddr: vm.ESDTSCAddress, GasLimit: 100_000_000, @@ -1466,6 +1563,7 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { ChainID: []byte(configs.ChainID), Version: 1, } + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1474,13 +1572,20 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[1], nftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[1].Bytes, addrs[1].Bytes, nftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[1].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(nonce, addrs[1].Bytes, sftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1488,7 +1593,13 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[1], sftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[1].Bytes, addrs[1].Bytes, sftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -1513,7 +1624,6 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { esdtMetaData, } - nonce := uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[1].Bytes, tokenIDs[i], tokensMetadata[i]) @@ -1633,12 +1743,16 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { metaESDTTokenID := txResult.Logs.Events[0].Topics[0] roles := [][]byte{ - []byte(core.ESDTRoleNFTBurn), []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), - []byte(core.ESDTRoleNFTUpdate), } - setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, metaESDTTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) @@ -1653,7 +1767,13 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, nftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) @@ -1668,7 +1788,13 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, sftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -1807,7 +1933,9 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { // issue metaESDT metaESDTTicker := []byte("METATICKER") - tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueMetaESDTTx(nonce, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1819,15 +1947,21 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), - []byte(core.ESDTRoleNFTUpdate), } - setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, metaESDTTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) // issue NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1835,13 +1969,20 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, nftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(nonce, addrs[0].Bytes, sftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1849,7 +1990,13 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, sftTokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -1874,7 +2021,6 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { esdtMetaData, } - nonce := uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) @@ -2009,7 +2155,9 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { log.Info("Initial setup: Create NFT") nftTicker := []byte("NFTTICKER") - tx := issueNonFungibleTx(0, addrs[1].Bytes, nftTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueNonFungibleTx(nonce, addrs[1].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2018,18 +2166,19 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), - []byte(core.ESDTRoleNFTUpdate), } nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[1], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[1], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[1].Bytes, nftTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[1].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2043,7 +2192,8 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[1].Bytes) - tx = changeToDynamicTx(2, addrs[1].Bytes, nftTokenID) + tx = changeToDynamicTx(nonce, addrs[1].Bytes, nftTokenID) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2051,6 +2201,13 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) + roles = [][]byte{ + []byte(core.ESDTRoleNFTUpdate), + } + + setAddressEsdtRoles(t, cs, nonce, addrs[1], nftTokenID, roles) + nonce++ + err = cs.GenerateBlocks(10) require.Nil(t, err) @@ -2058,7 +2215,8 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { log.Info("Step 2. Send the NFT cross shard") - tx = esdtNFTTransferTx(3, addrs[1].Bytes, addrs[2].Bytes, nftTokenID) + tx = esdtNFTTransferTx(nonce, addrs[1].Bytes, addrs[2].Bytes, nftTokenID) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) @@ -2105,46 +2263,47 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), - []byte(core.ESDTRoleNFTUpdate), + []byte(core.ESDTRoleTransfer), []byte(core.ESDTRoleNFTAddQuantity), } ticker := []byte("TICKER") - tx := issueFn(0, addrs[1].Bytes, ticker, baseIssuingCost) + nonce := uint64(0) + tx := issueFn(nonce, addrs[1].Bytes, ticker, baseIssuingCost) + nonce++ + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) tokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[1], tokenID, roles) - - setAddressEsdtRoles(t, cs, addrs[0], tokenID, roles) - setAddressEsdtRoles(t, cs, addrs[2], tokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[1], tokenID, roles) + nonce++ log.Info("Issued token id", "tokenID", string(tokenID)) - sftMetaData := txsFee.GetDefaultMetaData() - sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + metaData := txsFee.GetDefaultMetaData() + metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) txDataField := bytes.Join( [][]byte{ []byte(core.BuiltInFunctionESDTNFTCreate), []byte(hex.EncodeToString(tokenID)), []byte(hex.EncodeToString(big.NewInt(2).Bytes())), // quantity - sftMetaData.Name, + metaData.Name, []byte(hex.EncodeToString(big.NewInt(10).Bytes())), - sftMetaData.Hash, - sftMetaData.Attributes, - sftMetaData.Uris[0], - sftMetaData.Uris[1], - sftMetaData.Uris[2], + metaData.Hash, + metaData.Attributes, + metaData.Uris[0], + metaData.Uris[1], + metaData.Uris[2], }, []byte("@"), ) tx = &transaction.Transaction{ - Nonce: 1, + Nonce: nonce, SndAddr: addrs[1].Bytes, RcvAddr: addrs[1].Bytes, GasLimit: 10_000_000, @@ -2155,6 +2314,7 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { ChainID: []byte(configs.ChainID), Version: 1, } + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2164,21 +2324,48 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { err = cs.GenerateBlocks(10) require.Nil(t, err) + tx = changeToDynamicTx(nonce, addrs[1].Bytes, tokenID) + nonce++ + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + roles = [][]byte{ + []byte(core.ESDTRoleNFTUpdate), + } + setAddressEsdtRoles(t, cs, nonce, addrs[1], tokenID, roles) + nonce++ + log.Info("Send to separate shards") - tx = esdtNFTTransferTx(2, addrs[1].Bytes, addrs[2].Bytes, tokenID) + tx = esdtNFTTransferTx(nonce, addrs[1].Bytes, addrs[2].Bytes, tokenID) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - tx = esdtNFTTransferTx(3, addrs[1].Bytes, addrs[0].Bytes, tokenID) + tx = esdtNFTTransferTx(nonce, addrs[1].Bytes, addrs[0].Bytes, tokenID) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) + roles = [][]byte{ + []byte(core.ESDTRoleTransfer), + []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) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + err = cs.GenerateBlocks(10) require.Nil(t, err) @@ -2231,6 +2418,14 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { log.Info("Step 2. change the sft meta data (differently from the previous one) in the other shard") + tx = setSpecialRoleTx(nonce, addrs[1].Bytes, addrs[2].Bytes, tokenID, roles) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + sftMetaData3 := txsFee.GetDefaultMetaData() sftMetaData3.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) @@ -2270,7 +2465,6 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) shardID = cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[2].Bytes) @@ -2283,7 +2477,6 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) err = cs.GenerateBlocks(10) @@ -2325,8 +2518,9 @@ func TestChainSimulator_NFT_RegisterDynamic(t *testing.T) { callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + nonce := uint64(0) tx := &transaction.Transaction{ - Nonce: 0, + Nonce: nonce, SndAddr: addrs[0].Bytes, RcvAddr: vm.ESDTSCAddress, GasLimit: 100_000_000, @@ -2337,6 +2531,7 @@ func TestChainSimulator_NFT_RegisterDynamic(t *testing.T) { ChainID: []byte(configs.ChainID), Version: 1, } + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2349,12 +2544,14 @@ func TestChainSimulator_NFT_RegisterDynamic(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2418,8 +2615,9 @@ func TestChainSimulator_MetaESDT_RegisterDynamic(t *testing.T) { callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + nonce := uint64(0) tx := &transaction.Transaction{ - Nonce: 0, + Nonce: nonce, SndAddr: addrs[0].Bytes, RcvAddr: vm.ESDTSCAddress, GasLimit: 100_000_000, @@ -2430,6 +2628,7 @@ func TestChainSimulator_MetaESDT_RegisterDynamic(t *testing.T) { ChainID: []byte(configs.ChainID), Version: 1, } + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2442,12 +2641,14 @@ func TestChainSimulator_MetaESDT_RegisterDynamic(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2562,8 +2763,9 @@ func TestChainSimulator_NFT_RegisterAndSetAllRolesDynamic(t *testing.T) { callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + nonce := uint64(0) tx := &transaction.Transaction{ - Nonce: 0, + Nonce: nonce, SndAddr: addrs[0].Bytes, RcvAddr: vm.ESDTSCAddress, GasLimit: 100_000_000, @@ -2574,6 +2776,7 @@ func TestChainSimulator_NFT_RegisterAndSetAllRolesDynamic(t *testing.T) { ChainID: []byte(configs.ChainID), Version: 1, } + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2586,12 +2789,14 @@ func TestChainSimulator_NFT_RegisterAndSetAllRolesDynamic(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2678,8 +2883,9 @@ func TestChainSimulator_SFT_RegisterAndSetAllRolesDynamic(t *testing.T) { callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + nonce := uint64(0) tx := &transaction.Transaction{ - Nonce: 0, + Nonce: nonce, SndAddr: addrs[0].Bytes, RcvAddr: vm.ESDTSCAddress, GasLimit: 100_000_000, @@ -2690,6 +2896,7 @@ func TestChainSimulator_SFT_RegisterAndSetAllRolesDynamic(t *testing.T) { ChainID: []byte(configs.ChainID), Version: 1, } + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2702,12 +2909,14 @@ func TestChainSimulator_SFT_RegisterAndSetAllRolesDynamic(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], sftTokenID, roles) + nonce++ nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, sftTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[0].Bytes, sftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2849,8 +3058,9 @@ func TestChainSimulator_MetaESDT_RegisterAndSetAllRolesDynamic(t *testing.T) { callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + nonce := uint64(0) tx := &transaction.Transaction{ - Nonce: 0, + Nonce: nonce, SndAddr: addrs[0].Bytes, RcvAddr: vm.ESDTSCAddress, GasLimit: 100_000_000, @@ -2861,6 +3071,7 @@ func TestChainSimulator_MetaESDT_RegisterAndSetAllRolesDynamic(t *testing.T) { ChainID: []byte(configs.ChainID), Version: 1, } + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2873,12 +3084,14 @@ func TestChainSimulator_MetaESDT_RegisterAndSetAllRolesDynamic(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], metaTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], metaTokenID, roles) + nonce++ nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, metaTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[0].Bytes, metaTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3018,42 +3231,6 @@ func TestChainSimulator_SFTcreatedBeforeSaveToSystemAccountEnabled(t *testing.T) checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, sftTokenID, shardID) } -func TestChainSimulator_FungibleCreatedBeforeSaveToSystemAccountEnabled(t *testing.T) { - if testing.Short() { - t.Skip("this is not a short test") - } - - baseIssuingCost := "1000" - cs, epochForDynamicNFT := getTestChainSimulatorWithSaveToSystemAccountDisabled(t, baseIssuingCost) - defer cs.Close() - - addrs := createAddresses(t, cs, false) - - log.Info("Initial setup: Create FungibleESDT that will have it's metadata saved to the user account") - - funTicker := []byte("FUNTICKER") - tx := issueTx(0, addrs[0].Bytes, funTicker, baseIssuingCost) - - txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - funTokenID := txResult.Logs.Events[0].Topics[0] - - log.Info("Issued FungibleESDT token id", "tokenID", string(funTokenID)) - - metaData := txsFee.GetDefaultMetaData() - metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - - createTokenUpdateTokenIDAndTransfer(t, cs, addrs[0].Bytes, addrs[1].Bytes, funTokenID, metaData, epochForDynamicNFT, addrs[0]) - - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - - checkMetaData(t, cs, core.SystemAccountAddress, funTokenID, shardID, metaData) - checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, funTokenID, shardID) - checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, funTokenID, shardID) -} - func TestChainSimulator_MetaESDTCreatedBeforeSaveToSystemAccountEnabled(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") @@ -3135,8 +3312,8 @@ func getTestChainSimulatorWithSaveToSystemAccountDisabled(t *testing.T, baseIssu Value: 20, } - activationEpochForSaveToSystemAccount := uint32(2) - activationEpochForDynamicNFT := uint32(4) + activationEpochForSaveToSystemAccount := uint32(4) + activationEpochForDynamicNFT := uint32(6) numOfShards := uint32(3) cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ @@ -3161,7 +3338,7 @@ func getTestChainSimulatorWithSaveToSystemAccountDisabled(t *testing.T, baseIssu require.Nil(t, err) require.NotNil(t, cs) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpochForSaveToSystemAccount) - 1) + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpochForSaveToSystemAccount) - 2) require.Nil(t, err) return cs, int32(activationEpochForDynamicNFT) @@ -3181,9 +3358,9 @@ func createTokenUpdateTokenIDAndTransfer( []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, walletWithRoles, tokenID, roles) + setAddressEsdtRoles(t, cs, 1, walletWithRoles, tokenID, roles) - tx := nftCreateTx(1, originAddress, tokenID, metaData) + tx := nftCreateTx(2, originAddress, tokenID, metaData) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3199,7 +3376,7 @@ func createTokenUpdateTokenIDAndTransfer( err = cs.GenerateBlocksUntilEpochIsReached(epochForDynamicNFT) require.Nil(t, err) - tx = updateTokenIDTx(2, originAddress, tokenID) + tx = updateTokenIDTx(3, originAddress, tokenID) log.Info("updating token id", "tokenID", tokenID) @@ -3213,7 +3390,7 @@ func createTokenUpdateTokenIDAndTransfer( log.Info("transferring token id", "tokenID", tokenID) - tx = esdtNFTTransferTx(3, originAddress, targetAddress, tokenID) + tx = esdtNFTTransferTx(4, originAddress, targetAddress, tokenID) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) @@ -3234,7 +3411,9 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { // issue metaESDT metaESDTTicker := []byte("METATICKER") - tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueMetaESDTTx(nonce, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3247,13 +3426,15 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { []byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleTransfer), } - setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], metaESDTTokenID, roles) + nonce++ log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) // issue NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3261,13 +3442,15 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(nonce, addrs[0].Bytes, sftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3275,7 +3458,8 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], sftTokenID, roles) + nonce++ log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -3300,7 +3484,6 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { esdtMetaData, } - nonce := uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) @@ -3313,9 +3496,6 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { nonce++ } - err = cs.GenerateBlocks(10) - require.Nil(t, err) - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) // meta data should be saved on account, since it is before `OptimizeNFTStoreEnableEpoch` @@ -3445,8 +3625,9 @@ func TestChainSimulator_CreateAndPause_NFT(t *testing.T) { []byte("@"), ) + nonce := uint64(0) tx := &transaction.Transaction{ - Nonce: 0, + Nonce: nonce, SndAddr: addrs[0].Bytes, RcvAddr: core.ESDTSCAddress, GasLimit: 100_000_000, @@ -3457,6 +3638,7 @@ func TestChainSimulator_CreateAndPause_NFT(t *testing.T) { ChainID: []byte(configs.ChainID), Version: 1, } + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3468,14 +3650,16 @@ func TestChainSimulator_CreateAndPause_NFT(t *testing.T) { []byte(core.ESDTRoleTransfer), } nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3513,7 +3697,8 @@ func TestChainSimulator_CreateAndPause_NFT(t *testing.T) { log.Info("make an updateTokenID@tokenID function call on the ESDTSystem SC for all token types") - tx = updateTokenIDTx(2, addrs[0].Bytes, nftTokenID) + tx = updateTokenIDTx(nonce, addrs[0].Bytes, nftTokenID) + nonce++ log.Info("updating token id", "tokenID", nftTokenID) @@ -3533,7 +3718,8 @@ func TestChainSimulator_CreateAndPause_NFT(t *testing.T) { log.Info("transfering token id", "tokenID", nftTokenID) - tx = esdtNFTTransferTx(3, addrs[0].Bytes, addrs[1].Bytes, nftTokenID) + tx = esdtNFTTransferTx(nonce, addrs[0].Bytes, addrs[1].Bytes, nftTokenID) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) @@ -3619,8 +3805,9 @@ func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(t *testing.T) { callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + nonce := uint64(0) tx := &transaction.Transaction{ - Nonce: 0, + Nonce: nonce, SndAddr: addrs[0].Bytes, RcvAddr: vm.ESDTSCAddress, GasLimit: 100_000_000, @@ -3631,6 +3818,7 @@ func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(t *testing.T) { ChainID: []byte(configs.ChainID), Version: 1, } + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3645,14 +3833,16 @@ func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(t *testing.T) { } nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3682,7 +3872,8 @@ func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(t *testing.T) { require.Equal(t, "", result.ReturnMessage) require.Equal(t, testsChainSimulator.OkReturnCode, result.ReturnCode) - tx = updateTokenIDTx(2, addrs[0].Bytes, nftTokenID) + tx = updateTokenIDTx(nonce, addrs[0].Bytes, nftTokenID) + nonce++ log.Info("updating token id", "tokenID", nftTokenID) @@ -3693,7 +3884,8 @@ func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(t *testing.T) { log.Info("change to dynamic token") - tx = changeToDynamicTx(3, addrs[0].Bytes, nftTokenID) + tx = changeToDynamicTx(nonce, addrs[0].Bytes, nftTokenID) + nonce++ log.Info("updating token id", "tokenID", nftTokenID) @@ -3711,7 +3903,8 @@ func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(t *testing.T) { log.Info("transfering token id", "tokenID", nftTokenID) - tx = esdtNFTTransferTx(4, addrs[0].Bytes, addrs[1].Bytes, nftTokenID) + tx = esdtNFTTransferTx(nonce, addrs[0].Bytes, addrs[1].Bytes, nftTokenID) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) diff --git a/integrationTests/chainSimulator/vm/esdtTokens_test.go b/integrationTests/chainSimulator/vm/esdtTokens_test.go index 00f5e3344f6..7fc9c84037a 100644 --- a/integrationTests/chainSimulator/vm/esdtTokens_test.go +++ b/integrationTests/chainSimulator/vm/esdtTokens_test.go @@ -82,7 +82,9 @@ func TestChainSimulator_Api_TokenType(t *testing.T) { // issue fungible fungibleTicker := []byte("FUNTICKER") - tx := issueTx(0, addrs[0].Bytes, fungibleTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueTx(nonce, addrs[0].Bytes, fungibleTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -90,13 +92,15 @@ func TestChainSimulator_Api_TokenType(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) fungibleTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], fungibleTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], fungibleTokenID, roles) + nonce++ log.Info("Issued fungible token id", "tokenID", string(fungibleTokenID)) // issue NFT nftTicker := []byte("NFTTICKER") - tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + tx = issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -104,13 +108,15 @@ func TestChainSimulator_Api_TokenType(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) // issue SFT sftTicker := []byte("SFTTICKER") - tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) + tx = issueSemiFungibleTx(nonce, addrs[0].Bytes, sftTicker, baseIssuingCost) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -118,7 +124,8 @@ func TestChainSimulator_Api_TokenType(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) sftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], sftTokenID, roles) + nonce++ log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) @@ -141,7 +148,6 @@ func TestChainSimulator_Api_TokenType(t *testing.T) { sftMetaData, } - nonce := uint64(3) for i := range tokenIDs { tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) @@ -244,7 +250,9 @@ func TestChainSimulator_Api_NFTToken(t *testing.T) { // issue NFT nftTicker := []byte("NFTTICKER") - tx := issueNonFungibleTx(0, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce := uint64(0) + tx := issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -252,14 +260,16 @@ func TestChainSimulator_Api_NFTToken(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(1, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -309,7 +319,8 @@ func TestChainSimulator_Api_NFTToken(t *testing.T) { log.Info("Update token id", "tokenID", nftTokenID) - tx = updateTokenIDTx(2, addrs[0].Bytes, nftTokenID) + tx = updateTokenIDTx(nonce, addrs[0].Bytes, nftTokenID) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -330,7 +341,8 @@ func TestChainSimulator_Api_NFTToken(t *testing.T) { log.Info("Transfer token id", "tokenID", nftTokenID) - tx = esdtNFTTransferTx(3, addrs[0].Bytes, addrs[1].Bytes, nftTokenID) + tx = esdtNFTTransferTx(nonce, addrs[0].Bytes, addrs[1].Bytes, nftTokenID) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) @@ -351,7 +363,8 @@ func TestChainSimulator_Api_NFTToken(t *testing.T) { log.Info("Change to DYNAMIC type") - tx = changeToDynamicTx(4, addrs[0].Bytes, nftTokenID) + tx = changeToDynamicTx(nonce, addrs[0].Bytes, nftTokenID) + nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) From 5087af138a816edb591d02bbd52d9bdabe774bde Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 30 Jul 2024 13:31:23 +0300 Subject: [PATCH 454/503] update getAllRolesForTokenType --- .../vm/esdtImprovements_test.go | 2 ++ vm/systemSmartContracts/esdt.go | 33 ++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index bdabac5b2c9..ac9c719f564 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -2849,6 +2849,7 @@ func TestChainSimulator_NFT_RegisterAndSetAllRolesDynamic(t *testing.T) { []byte(core.ESDTRoleModifyCreator), []byte(core.ESDTRoleModifyRoyalties), []byte(core.ESDTRoleSetNewURI), + []byte(core.ESDTRoleNFTUpdate), } checkTokenRoles(t, result.ReturnData, expectedRoles) @@ -2969,6 +2970,7 @@ func TestChainSimulator_SFT_RegisterAndSetAllRolesDynamic(t *testing.T) { []byte(core.ESDTRoleModifyCreator), []byte(core.ESDTRoleModifyRoyalties), []byte(core.ESDTRoleSetNewURI), + []byte(core.ESDTRoleNFTUpdate), } checkTokenRoles(t, result.ReturnData, expectedRoles) diff --git a/vm/systemSmartContracts/esdt.go b/vm/systemSmartContracts/esdt.go index 63f612610f3..b7b21b743c0 100644 --- a/vm/systemSmartContracts/esdt.go +++ b/vm/systemSmartContracts/esdt.go @@ -548,9 +548,21 @@ func (e *esdt) registerAndSetRoles(args *vmcommon.ContractCallInput) vmcommon.Re func (e *esdt) getAllRolesForTokenType(tokenType string) ([][]byte, error) { switch tokenType { case core.NonFungibleESDT, core.NonFungibleESDTv2, core.DynamicNFTESDT: - nftRoles := [][]byte{[]byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleNFTBurn), []byte(core.ESDTRoleNFTUpdateAttributes), []byte(core.ESDTRoleNFTAddURI)} + nftRoles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleNFTBurn), + []byte(core.ESDTRoleNFTUpdateAttributes), + []byte(core.ESDTRoleNFTAddURI), + } + if e.enableEpochsHandler.IsFlagEnabled(common.DynamicESDTFlag) { - nftRoles = append(nftRoles, [][]byte{[]byte(core.ESDTRoleNFTRecreate), []byte(core.ESDTRoleModifyCreator), []byte(core.ESDTRoleModifyRoyalties), []byte(core.ESDTRoleSetNewURI)}...) + nftRoles = append(nftRoles, [][]byte{ + []byte(core.ESDTRoleNFTRecreate), + []byte(core.ESDTRoleModifyCreator), + []byte(core.ESDTRoleModifyRoyalties), + []byte(core.ESDTRoleSetNewURI), + []byte(core.ESDTRoleNFTUpdate), + }...) } return nftRoles, nil @@ -559,8 +571,21 @@ func (e *esdt) getAllRolesForTokenType(tokenType string) ([][]byte, error) { case core.FungibleESDT: return [][]byte{[]byte(core.ESDTRoleLocalMint), []byte(core.ESDTRoleLocalBurn)}, nil case core.DynamicSFTESDT, core.DynamicMetaESDT: - dynamicRoles := [][]byte{[]byte(core.ESDTRoleNFTCreate), []byte(core.ESDTRoleNFTBurn), []byte(core.ESDTRoleNFTAddQuantity), []byte(core.ESDTRoleNFTUpdateAttributes), []byte(core.ESDTRoleNFTAddURI)} - dynamicRoles = append(dynamicRoles, [][]byte{[]byte(core.ESDTRoleNFTRecreate), []byte(core.ESDTRoleModifyCreator), []byte(core.ESDTRoleModifyRoyalties), []byte(core.ESDTRoleSetNewURI)}...) + dynamicRoles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleNFTBurn), + []byte(core.ESDTRoleNFTAddQuantity), + []byte(core.ESDTRoleNFTUpdateAttributes), + []byte(core.ESDTRoleNFTAddURI), + } + + dynamicRoles = append(dynamicRoles, [][]byte{ + []byte(core.ESDTRoleNFTRecreate), + []byte(core.ESDTRoleModifyCreator), + []byte(core.ESDTRoleModifyRoyalties), + []byte(core.ESDTRoleSetNewURI), + []byte(core.ESDTRoleNFTUpdate), + }...) return dynamicRoles, nil } From 1521c987f100ccee9dbc88dd26578723ea05e40c Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 30 Jul 2024 14:19:08 +0300 Subject: [PATCH 455/503] fix linter issues --- .../chainSimulator/vm/egldMultiTransfer_test.go | 2 -- .../chainSimulator/vm/esdtImprovements_test.go | 8 -------- 2 files changed, 10 deletions(-) diff --git a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go index 52aaa9b7e36..10a10cee5ad 100644 --- a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go +++ b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go @@ -300,7 +300,6 @@ func TestChainSimulator_EGLD_MultiTransfer_Insufficient_Funds(t *testing.T) { egldValue, _ := big.NewInt(0).SetString(beforeBalanceStr0, 10) egldValue = egldValue.Add(egldValue, big.NewInt(13)) tx = multiESDTNFTTransferWithEGLDTx(nonce, addrs[0].Bytes, addrs[1].Bytes, [][]byte{nftTokenID}, egldValue) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -422,7 +421,6 @@ func TestChainSimulator_EGLD_MultiTransfer_Invalid_Value(t *testing.T) { egldValue := oneEGLD.Mul(oneEGLD, big.NewInt(3)) tx = multiESDTNFTTransferWithEGLDTx(nonce, addrs[0].Bytes, addrs[1].Bytes, [][]byte{nftTokenID}, egldValue) - nonce++ tx.Value = egldValue // invalid value field txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index ac9c719f564..bdd4ac2e2ea 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -2216,7 +2216,6 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { log.Info("Step 2. Send the NFT cross shard") tx = esdtNFTTransferTx(nonce, addrs[1].Bytes, addrs[2].Bytes, nftTokenID) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) @@ -2419,7 +2418,6 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { log.Info("Step 2. change the sft meta data (differently from the previous one) in the other shard") tx = setSpecialRoleTx(nonce, addrs[1].Bytes, addrs[2].Bytes, tokenID, roles) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2551,7 +2549,6 @@ func TestChainSimulator_NFT_RegisterDynamic(t *testing.T) { nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2648,7 +2645,6 @@ func TestChainSimulator_MetaESDT_RegisterDynamic(t *testing.T) { nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2796,7 +2792,6 @@ func TestChainSimulator_NFT_RegisterAndSetAllRolesDynamic(t *testing.T) { nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2917,7 +2912,6 @@ func TestChainSimulator_SFT_RegisterAndSetAllRolesDynamic(t *testing.T) { nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = nftCreateTx(nonce, addrs[0].Bytes, sftTokenID, nftMetaData) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3093,7 +3087,6 @@ func TestChainSimulator_MetaESDT_RegisterAndSetAllRolesDynamic(t *testing.T) { nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) tx = nftCreateTx(nonce, addrs[0].Bytes, metaTokenID, nftMetaData) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3721,7 +3714,6 @@ func TestChainSimulator_CreateAndPause_NFT(t *testing.T) { log.Info("transfering token id", "tokenID", nftTokenID) tx = esdtNFTTransferTx(nonce, addrs[0].Bytes, addrs[1].Bytes, nftTokenID) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) From 06b165bd4bad393b19c25a36d3e77043e1048b65 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 30 Jul 2024 14:52:47 +0300 Subject: [PATCH 456/503] fix - only transfer role for second address --- .../chainSimulator/vm/esdtImprovements_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index bdd4ac2e2ea..fa40135b5e1 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -137,7 +137,8 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran setAddressEsdtRoles(t, cs, nonce, addrs[0], metaESDTTokenID, roles) nonce++ - tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[1].Bytes, metaESDTTokenID, roles) + rolesTransfer := [][]byte{[]byte(core.ESDTRoleTransfer)} + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[1].Bytes, metaESDTTokenID, rolesTransfer) nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -161,7 +162,7 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) nonce++ - tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[1].Bytes, nftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[1].Bytes, nftTokenID, rolesTransfer) nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -185,7 +186,7 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran setAddressEsdtRoles(t, cs, nonce, addrs[0], sftTokenID, roles) nonce++ - tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[1].Bytes, sftTokenID, roles) + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[1].Bytes, sftTokenID, rolesTransfer) nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) From 3bb84e73111e5eadc034418d93a1411da211ce0d Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 30 Jul 2024 14:59:53 +0300 Subject: [PATCH 457/503] fix linter issues --- integrationTests/chainSimulator/vm/esdtImprovements_test.go | 1 - integrationTests/chainSimulator/vm/esdtTokens_test.go | 1 - 2 files changed, 2 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index fa40135b5e1..97acfa79fd2 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -3899,7 +3899,6 @@ func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(t *testing.T) { log.Info("transfering token id", "tokenID", nftTokenID) tx = esdtNFTTransferTx(nonce, addrs[0].Bytes, addrs[1].Bytes, nftTokenID) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) diff --git a/integrationTests/chainSimulator/vm/esdtTokens_test.go b/integrationTests/chainSimulator/vm/esdtTokens_test.go index 7fc9c84037a..d12bfcbb550 100644 --- a/integrationTests/chainSimulator/vm/esdtTokens_test.go +++ b/integrationTests/chainSimulator/vm/esdtTokens_test.go @@ -364,7 +364,6 @@ func TestChainSimulator_Api_NFTToken(t *testing.T) { log.Info("Change to DYNAMIC type") tx = changeToDynamicTx(nonce, addrs[0].Bytes, nftTokenID) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) From 9e9ecdac075ab52cba1d0d5e8dab7e041e6f7cad Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 31 Jul 2024 10:47:50 +0300 Subject: [PATCH 458/503] fix - only transfer role for second address --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index ad3320aa141..3346fdb7919 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.3 github.com/multiversx/mx-chain-storage-go v1.0.15 github.com/multiversx/mx-chain-vm-common-go v1.5.12 - github.com/multiversx/mx-chain-vm-go v1.5.29 + github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240731074331-32488d472365 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.97 diff --git a/go.sum b/go.sum index 1fd68ab48f7..1e1a56a818c 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go v1.5.29 h1:Ovz5/WM9KbD3YKRafdKI4RwtsNN36AGeNw81LZAhE70= -github.com/multiversx/mx-chain-vm-go v1.5.29/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240731074331-32488d472365 h1:6gRrsqpIjXAw6P40PcQ3txOLPTcSOmisIe+HVyyVeAE= +github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240731074331-32488d472365/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From f7483c67328f5969cc253c972cbf59c02ed4fc83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Wed, 31 Jul 2024 10:51:45 +0300 Subject: [PATCH 459/503] Fix workflow matrix. --- .github/workflows/build_and_test.yml | 2 +- .github/workflows/create_release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 19fdaec07e0..d552db889c7 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-latest, macos-13-xlarge] + runs-on: [ubuntu-latest, macos-13, macos-13-xlarge] runs-on: ${{ matrix.runs-on }} name: Build steps: diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index ca13a9f0313..fe74d301325 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-latest, macos-13-xlarge] + runs-on: [ubuntu-latest, macos-13, macos-13-xlarge] runs-on: ${{ matrix.runs-on }} name: Build steps: From 1eefd6f27f7ad5128685f950b9bc9b8f4656b802 Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 31 Jul 2024 11:56:38 +0300 Subject: [PATCH 460/503] legacy indexer chain simulator --- .../components/statusComponents.go | 34 +++++++++++++++---- .../components/statusComponents_test.go | 16 ++++----- .../components/testOnlyProcessingNode.go | 1 + 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/node/chainSimulator/components/statusComponents.go b/node/chainSimulator/components/statusComponents.go index fa0027ca967..be094472fc1 100644 --- a/node/chainSimulator/components/statusComponents.go +++ b/node/chainSimulator/components/statusComponents.go @@ -10,6 +10,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core/appStatusPolling" "github.com/multiversx/mx-chain-core-go/core/check" 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" @@ -34,7 +35,7 @@ type statusComponentsHolder struct { } // CreateStatusComponents will create a new instance of status components holder -func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandler, statusPollingIntervalSec int, external config.ExternalConfig) (*statusComponentsHolder, error) { +func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandler, statusPollingIntervalSec int, external config.ExternalConfig, coreComponents process.CoreComponentsHolder) (*statusComponentsHolder, error) { if check.IfNil(appStatusHandler) { return nil, core.ErrNilAppStatusHandler } @@ -51,11 +52,12 @@ func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandl return nil, err } instance.outportHandler, err = factory.CreateOutport(&factory.OutportFactoryArgs{ - IsImportDB: false, - ShardID: shardID, - RetrialInterval: time.Second, - HostDriversArgs: hostDriverArgs, - EventNotifierFactoryArgs: &factory.EventNotifierFactoryArgs{}, + IsImportDB: false, + ShardID: shardID, + RetrialInterval: time.Second, + HostDriversArgs: hostDriverArgs, + EventNotifierFactoryArgs: &factory.EventNotifierFactoryArgs{}, + ElasticIndexerFactoryArgs: makeElasticIndexerArgs(external, coreComponents), }) if err != nil { return nil, err @@ -90,6 +92,26 @@ func makeHostDriversArgs(external config.ExternalConfig) ([]factory.ArgsHostDriv return argsHostDriverFactorySlice, nil } +func makeElasticIndexerArgs(external config.ExternalConfig, coreComponents process.CoreComponentsHolder) indexerFactory.ArgsIndexerFactory { + elasticSearchConfig := external.ElasticSearchConnector + return indexerFactory.ArgsIndexerFactory{ + Enabled: elasticSearchConfig.Enabled, + BulkRequestMaxSize: elasticSearchConfig.BulkRequestMaxSizeInBytes, + Url: elasticSearchConfig.URL, + UserName: elasticSearchConfig.Username, + Password: elasticSearchConfig.Password, + Marshalizer: coreComponents.InternalMarshalizer(), + Hasher: coreComponents.Hasher(), + AddressPubkeyConverter: coreComponents.AddressPubKeyConverter(), + ValidatorPubkeyConverter: coreComponents.ValidatorPubKeyConverter(), + EnabledIndexes: elasticSearchConfig.EnabledIndexes, + Denomination: 18, + UseKibana: elasticSearchConfig.UseKibana, + ImportDB: false, + HeaderMarshaller: coreComponents.InternalMarshalizer(), + } +} + // OutportHandler will return the outport handler func (s *statusComponentsHolder) OutportHandler() outport.OutportHandler { return s.outportHandler diff --git a/node/chainSimulator/components/statusComponents_test.go b/node/chainSimulator/components/statusComponents_test.go index b6e2e296fbb..24f3b4595c1 100644 --- a/node/chainSimulator/components/statusComponents_test.go +++ b/node/chainSimulator/components/statusComponents_test.go @@ -21,7 +21,7 @@ func TestCreateStatusComponents(t *testing.T) { t.Run("should work", func(t *testing.T) { t.Parallel() - comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{}) + comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{}, &mock.CoreComponentsStub{}) require.NoError(t, err) require.NotNil(t, comp) @@ -31,7 +31,7 @@ func TestCreateStatusComponents(t *testing.T) { t.Run("nil app status handler should error", func(t *testing.T) { t.Parallel() - comp, err := CreateStatusComponents(0, nil, 5, config.ExternalConfig{}) + comp, err := CreateStatusComponents(0, nil, 5, config.ExternalConfig{}, &mock.CoreComponentsStub{}) require.Equal(t, core.ErrNilAppStatusHandler, err) require.Nil(t, comp) }) @@ -43,7 +43,7 @@ func TestStatusComponentsHolder_IsInterfaceNil(t *testing.T) { var comp *statusComponentsHolder require.True(t, comp.IsInterfaceNil()) - comp, _ = CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{}) + comp, _ = CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{}, &mock.CoreComponentsStub{}) require.False(t, comp.IsInterfaceNil()) require.Nil(t, comp.Close()) } @@ -51,7 +51,7 @@ func TestStatusComponentsHolder_IsInterfaceNil(t *testing.T) { func TestStatusComponentsHolder_Getters(t *testing.T) { t.Parallel() - comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{}) + comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{}, &mock.CoreComponentsStub{}) require.NoError(t, err) require.NotNil(t, comp.OutportHandler()) @@ -65,7 +65,7 @@ func TestStatusComponentsHolder_Getters(t *testing.T) { func TestStatusComponentsHolder_SetForkDetector(t *testing.T) { t.Parallel() - comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{}) + comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{}, &mock.CoreComponentsStub{}) require.NoError(t, err) err = comp.SetForkDetector(nil) @@ -83,7 +83,7 @@ func TestStatusComponentsHolder_StartPolling(t *testing.T) { t.Run("nil fork detector should error", func(t *testing.T) { t.Parallel() - comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{}) + comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 5, config.ExternalConfig{}, &mock.CoreComponentsStub{}) require.NoError(t, err) err = comp.StartPolling() @@ -92,7 +92,7 @@ func TestStatusComponentsHolder_StartPolling(t *testing.T) { t.Run("NewAppStatusPolling failure should error", func(t *testing.T) { t.Parallel() - comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 0, config.ExternalConfig{}) + comp, err := CreateStatusComponents(0, &statusHandler.AppStatusHandlerStub{}, 0, config.ExternalConfig{}, &mock.CoreComponentsStub{}) require.NoError(t, err) err = comp.SetForkDetector(&mock.ForkDetectorStub{}) @@ -114,7 +114,7 @@ func TestStatusComponentsHolder_StartPolling(t *testing.T) { wasSetUInt64ValueCalled.SetValue(true) }, } - comp, err := CreateStatusComponents(0, appStatusHandler, providedStatusPollingIntervalSec, config.ExternalConfig{}) + comp, err := CreateStatusComponents(0, appStatusHandler, providedStatusPollingIntervalSec, config.ExternalConfig{}, &mock.CoreComponentsStub{}) require.NoError(t, err) forkDetector := &mock.ForkDetectorStub{ diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index 20e2f7402c6..28256c4820f 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -153,6 +153,7 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces instance.StatusCoreComponents.AppStatusHandler(), args.Configs.GeneralConfig.GeneralSettings.StatusPollingIntervalSec, *args.Configs.ExternalConfig, + instance.CoreComponentsHolder, ) if err != nil { return nil, err From fe8f6a9584c6bc1fbe26b646ea310b4f7d11ed05 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 31 Jul 2024 12:22:57 +0300 Subject: [PATCH 461/503] check roles which has to be singular --- .../vm/esdtImprovements_test.go | 69 ++++++++++++++++++- 1 file changed, 66 insertions(+), 3 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 97acfa79fd2..555f1f75536 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -318,9 +318,6 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) require.Equal(t, "success", txResult.Status.String()) } else { @@ -3915,3 +3912,69 @@ func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(t *testing.T) { checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, nftTokenID, shardID) checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, nftTokenID, shardID) } + +func TestChainSimulator_CheckRolesWhichHasToBeSingular(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + baseIssuingCost := "1000" + + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) + defer cs.Close() + + addrs := createAddresses(t, cs, true) + + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + []byte(core.ESDTRoleModifyRoyalties), + } + + nftTicker := []byte("NFTTICKER") + nonce := uint64(0) + tx := issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + nonce++ + + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) + nonce++ + + tx = changeToDynamicTx(nonce, addrs[0].Bytes, nftTokenID) + nonce++ + + log.Info("updating token id", "tokenID", nftTokenID) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + rolesTransfer := [][]byte{ + []byte(core.ESDTRoleNFTUpdate), + } + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, nftTokenID, rolesTransfer) + nonce++ + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult) + if txResult.Logs != nil && len(txResult.Logs.Events) > 0 { + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + } + + require.Equal(t, "success", txResult.Status.String()) + + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) +} From d2a504f135c86957e86bac7cb1896498caefc732 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 31 Jul 2024 12:41:39 +0300 Subject: [PATCH 462/503] check roles which has to be singular - update test + fix --- .../vm/esdtImprovements_test.go | 88 ++++++++++++------- vm/systemSmartContracts/esdt.go | 12 ++- 2 files changed, 64 insertions(+), 36 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 555f1f75536..281a8d944eb 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -5,6 +5,7 @@ import ( "encoding/hex" "fmt" "math/big" + "strings" "testing" "time" @@ -3925,56 +3926,75 @@ func TestChainSimulator_CheckRolesWhichHasToBeSingular(t *testing.T) { addrs := createAddresses(t, cs, true) - roles := [][]byte{ - []byte(core.ESDTRoleNFTCreate), - []byte(core.ESDTRoleTransfer), - []byte(core.ESDTRoleModifyRoyalties), - } - + // register dynamic NFT nftTicker := []byte("NFTTICKER") + nftTokenName := []byte("tokenName") + + txDataField := bytes.Join( + [][]byte{ + []byte("registerDynamic"), + []byte(hex.EncodeToString(nftTokenName)), + []byte(hex.EncodeToString(nftTicker)), + []byte(hex.EncodeToString([]byte("NFT"))), + []byte(hex.EncodeToString([]byte("canPause"))), + []byte(hex.EncodeToString([]byte("true"))), + }, + []byte("@"), + ) + + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + nonce := uint64(0) - tx := issueNonFungibleTx(nonce, addrs[0].Bytes, nftTicker, baseIssuingCost) + tx := &transaction.Transaction{ + Nonce: nonce, + SndAddr: addrs[0].Bytes, + RcvAddr: vm.ESDTSCAddress, + GasLimit: 100_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: callValue, + ChainID: []byte(configs.ChainID), + Version: 1, + } nonce++ txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) - nonce++ - tx = changeToDynamicTx(nonce, addrs[0].Bytes, nftTokenID) - nonce++ - - log.Info("updating token id", "tokenID", nftTokenID) - - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - - err = cs.GenerateBlocks(10) - require.Nil(t, err) + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) - rolesTransfer := [][]byte{ + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleNFTUpdateAttributes), + []byte(core.ESDTRoleNFTAddURI), + []byte(core.ESDTRoleSetNewURI), + []byte(core.ESDTRoleModifyCreator), + []byte(core.ESDTRoleModifyRoyalties), + []byte(core.ESDTRoleNFTRecreate), []byte(core.ESDTRoleNFTUpdate), } - tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[0].Bytes, nftTokenID, rolesTransfer) + setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) nonce++ - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - - fmt.Println(txResult) - if txResult.Logs != nil && len(txResult.Logs.Events) > 0 { - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - } + for _, role := range roles { + tx = setSpecialRoleTx(nonce, addrs[0].Bytes, addrs[1].Bytes, nftTokenID, [][]byte{role}) + nonce++ - require.Equal(t, "success", txResult.Status.String()) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) - log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) + if txResult.Logs != nil && len(txResult.Logs.Events) > 0 { + returnMessage := string(txResult.Logs.Events[0].Topics[1]) + require.True(t, strings.Contains(returnMessage, "already exists")) + } else { + require.Fail(t, "should have been return error message") + } + } } diff --git a/vm/systemSmartContracts/esdt.go b/vm/systemSmartContracts/esdt.go index b7b21b743c0..99b29035aef 100644 --- a/vm/systemSmartContracts/esdt.go +++ b/vm/systemSmartContracts/esdt.go @@ -1804,8 +1804,16 @@ func isDynamicTokenType(tokenType []byte) bool { } func rolesForDynamicWhichHasToBeSingular() []string { - return []string{core.ESDTRoleNFTCreate, core.ESDTRoleNFTUpdateAttributes, core.ESDTRoleNFTAddURI, - core.ESDTRoleSetNewURI, core.ESDTRoleModifyCreator, core.ESDTRoleModifyRoyalties, core.ESDTRoleNFTRecreate} + return []string{ + core.ESDTRoleNFTCreate, + core.ESDTRoleNFTUpdateAttributes, + core.ESDTRoleNFTAddURI, + core.ESDTRoleSetNewURI, + core.ESDTRoleModifyCreator, + core.ESDTRoleModifyRoyalties, + core.ESDTRoleNFTRecreate, + core.ESDTRoleNFTUpdate, + } } func (e *esdt) checkRolesForDynamicTokens( From 223bfb551282481927ee2f40f39adba12a0ad938 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 31 Jul 2024 12:46:47 +0300 Subject: [PATCH 463/503] remove debug messages --- .../chainSimulator/vm/esdtImprovements_test.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 281a8d944eb..ddb51d499c6 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -254,9 +254,6 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) require.Equal(t, "success", txResult.Status.String()) @@ -753,12 +750,6 @@ func setAddressEsdtRoles( require.Nil(t, err) require.NotNil(t, txResult) - fmt.Println(txResult) - if txResult.Logs != nil && len(txResult.Logs.Events) > 0 { - fmt.Println(string(txResult.Logs.Events[0].Topics[0])) - fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - } - require.Equal(t, "success", txResult.Status.String()) } From f9aadacc3951cb66ef79d3a6802fe820211ecbfb Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 31 Jul 2024 14:17:36 +0300 Subject: [PATCH 464/503] update change metadata test --- .../vm/esdtImprovements_test.go | 89 ++----------------- 1 file changed, 6 insertions(+), 83 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index ddb51d499c6..efdea1bcb9f 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -2218,12 +2218,10 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { // Test scenario #10 // -// Initial setup: Create SFT and send in 2 shards +// Initial setup: Create SFT and send in another shard // -// 1. change the sft meta data in one shard -// 2. change the sft meta data (differently from the previous one) in the other shard -// 3. send sft from one shard to another -// 4. check that the newest metadata is saved +// 1. change the sft meta data (differently from the previous one) in the other shard +// 2. check that the newest metadata is saved func TestChainSimulator_ChangeMetaData(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") @@ -2248,7 +2246,7 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { addrs := createAddresses(t, cs, true) - log.Info("Initial setup: Create token and send in 2 shards") + log.Info("Initial setup: Create token and send in another shard") roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), @@ -2320,12 +2318,6 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - roles = [][]byte{ - []byte(core.ESDTRoleNFTUpdate), - } - setAddressEsdtRoles(t, cs, nonce, addrs[1], tokenID, roles) - nonce++ - log.Info("Send to separate shards") tx = esdtNFTTransferTx(nonce, addrs[1].Bytes, addrs[2].Bytes, tokenID) @@ -2401,78 +2393,9 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - - checkMetaData(t, cs, core.SystemAccountAddress, tokenID, shardID, sftMetaData2) - - log.Info("Step 2. change the sft meta data (differently from the previous one) in the other shard") - - tx = setSpecialRoleTx(nonce, addrs[1].Bytes, addrs[2].Bytes, tokenID, roles) - - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - - sftMetaData3 := txsFee.GetDefaultMetaData() - sftMetaData3.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - - sftMetaData3.Name = []byte(hex.EncodeToString([]byte("name3"))) - sftMetaData3.Hash = []byte(hex.EncodeToString([]byte("hash3"))) - sftMetaData3.Attributes = []byte(hex.EncodeToString([]byte("attributes3"))) - - txDataField = bytes.Join( - [][]byte{ - []byte(core.ESDTMetaDataUpdate), - []byte(hex.EncodeToString(tokenID)), - sftMetaData3.Nonce, - sftMetaData3.Name, - []byte(hex.EncodeToString(big.NewInt(10).Bytes())), - sftMetaData3.Hash, - sftMetaData3.Attributes, - sftMetaData3.Uris[0], - sftMetaData3.Uris[1], - sftMetaData3.Uris[2], - }, - []byte("@"), - ) - - tx = &transaction.Transaction{ - Nonce: 0, - SndAddr: addrs[2].Bytes, - RcvAddr: addrs[2].Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, - } - - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - - shardID = cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[2].Bytes) - - checkMetaData(t, cs, core.SystemAccountAddress, tokenID, shardID, sftMetaData3) - - log.Info("Step 3. send sft from one shard to another") - - tx = esdtNFTTransferTx(1, addrs[0].Bytes, addrs[2].Bytes, tokenID) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - - err = cs.GenerateBlocks(10) - require.Nil(t, err) + log.Info("Step 2. check that the newest metadata is saved") - log.Info("Step 4. check that the newest metadata is saved") - - shardID = cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[2].Bytes) + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) checkMetaData(t, cs, core.SystemAccountAddress, tokenID, shardID, sftMetaData2) } From afe791533cebc4cbb4b5b814af184c4de3c9bcc0 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 1 Aug 2024 08:49:38 +0300 Subject: [PATCH 465/503] even newer wasmer --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 3346fdb7919..7ef2feb817b 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.3 github.com/multiversx/mx-chain-storage-go v1.0.15 github.com/multiversx/mx-chain-vm-common-go v1.5.12 - github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240731074331-32488d472365 + github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240801054658-dd0579e7d74b github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.97 diff --git a/go.sum b/go.sum index 1e1a56a818c..a36b7ceb563 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240731074331-32488d472365 h1:6gRrsqpIjXAw6P40PcQ3txOLPTcSOmisIe+HVyyVeAE= -github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240731074331-32488d472365/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240801054658-dd0579e7d74b h1:gPOH3m+KxTZr4K5af3cS0URQKRLL8WsHXcY1PJeCtO0= +github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240801054658-dd0579e7d74b/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From 3da197f2075c0b009398332a559da4704f08f74e Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 1 Aug 2024 14:07:24 +0300 Subject: [PATCH 466/503] even newer wasmer --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e2d3cb99819..7ddfcc65b21 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.4 github.com/multiversx/mx-chain-storage-go v1.0.16 github.com/multiversx/mx-chain-vm-common-go v1.5.13 - github.com/multiversx/mx-chain-vm-go v1.5.30 + github.com/multiversx/mx-chain-vm-go v1.5.31-0.20240801110141-816d65400283 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index 5c4d74b40ab..8fac367ef03 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1X 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.13 h1:ymnIHJW4Z4mFa0hZzla4fozkF30vjH5O1q+Y7Ftc+pQ= github.com/multiversx/mx-chain-vm-common-go v1.5.13/go.mod h1:OSvFbzdWThfRbLZbUsEr7bikBSaLrPJQ2iUm9jw9nXQ= -github.com/multiversx/mx-chain-vm-go v1.5.30 h1:CXBQF3o+dai4nx2qYfMIACva+6SqPO5fZjZtVq72RTI= -github.com/multiversx/mx-chain-vm-go v1.5.30/go.mod h1:iq6sCPweoHC9Fx56uf8buPrqlGVGJKUMRFxTunzjvys= +github.com/multiversx/mx-chain-vm-go v1.5.31-0.20240801110141-816d65400283 h1:jq2GJYkiuX5karbU7vC9/XF6/gVGgRIzgcQhb5MNUvc= +github.com/multiversx/mx-chain-vm-go v1.5.31-0.20240801110141-816d65400283/go.mod h1:iq6sCPweoHC9Fx56uf8buPrqlGVGJKUMRFxTunzjvys= 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= From ce9b2835cae5eeb90b65bca85bb9ebae520baad1 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Fri, 2 Aug 2024 12:26:40 +0300 Subject: [PATCH 467/503] even newer wasmer --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 7ddfcc65b21..45b20fe50cb 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.4 github.com/multiversx/mx-chain-storage-go v1.0.16 github.com/multiversx/mx-chain-vm-common-go v1.5.13 - github.com/multiversx/mx-chain-vm-go v1.5.31-0.20240801110141-816d65400283 + github.com/multiversx/mx-chain-vm-go v1.5.31-0.20240802091618-d50489328579 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index 8fac367ef03..00a1ae81423 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1X 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.13 h1:ymnIHJW4Z4mFa0hZzla4fozkF30vjH5O1q+Y7Ftc+pQ= github.com/multiversx/mx-chain-vm-common-go v1.5.13/go.mod h1:OSvFbzdWThfRbLZbUsEr7bikBSaLrPJQ2iUm9jw9nXQ= -github.com/multiversx/mx-chain-vm-go v1.5.31-0.20240801110141-816d65400283 h1:jq2GJYkiuX5karbU7vC9/XF6/gVGgRIzgcQhb5MNUvc= -github.com/multiversx/mx-chain-vm-go v1.5.31-0.20240801110141-816d65400283/go.mod h1:iq6sCPweoHC9Fx56uf8buPrqlGVGJKUMRFxTunzjvys= +github.com/multiversx/mx-chain-vm-go v1.5.31-0.20240802091618-d50489328579 h1:49NRtf8yd6dhM/gpkqjPYejNNIbuAUHTQj+plK64DVI= +github.com/multiversx/mx-chain-vm-go v1.5.31-0.20240802091618-d50489328579/go.mod h1:iq6sCPweoHC9Fx56uf8buPrqlGVGJKUMRFxTunzjvys= 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= From 8b4fb3a4003232e3eeda190f4d5e222bfcac9433 Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 5 Aug 2024 14:56:18 +0300 Subject: [PATCH 468/503] new endpoint --- api/errors/errors.go | 5 ++ api/groups/transactionGroup.go | 66 +++++++++++++++++++ api/mock/facadeStub.go | 10 +++ api/shared/interface.go | 1 + cmd/node/config/api.toml | 3 + facade/initial/initialNodeFacade.go | 5 ++ facade/interface.go | 1 + facade/nodeFacade.go | 4 ++ .../chainSimulator/vm/esdtTokens_test.go | 5 ++ integrationTests/interface.go | 1 + node/external/interface.go | 1 + node/external/nodeApiResolver.go | 4 ++ .../transactionAPI/apiTransactionProcessor.go | 43 ++++++++++++ .../transactionAPI/apiTransactionResults.go | 13 ++-- node/mock/apiTransactionHandlerStub.go | 10 +++ 15 files changed, 167 insertions(+), 5 deletions(-) diff --git a/api/errors/errors.go b/api/errors/errors.go index 30cfb923bbd..e2c22411dac 100644 --- a/api/errors/errors.go +++ b/api/errors/errors.go @@ -64,6 +64,8 @@ var ErrTxGenerationFailed = errors.New("transaction generation failed") // ErrValidationEmptyTxHash signals that an empty tx hash was provided var ErrValidationEmptyTxHash = errors.New("TxHash is empty") +var ErrValidationEmptySCRHash = errors.New("SCRHash is empty") + // ErrInvalidBlockNonce signals that an invalid block nonce was provided var ErrInvalidBlockNonce = errors.New("invalid block nonce") @@ -79,6 +81,9 @@ var ErrValidationEmptyBlockHash = errors.New("block hash is empty") // ErrGetTransaction signals an error happening when trying to fetch a transaction var ErrGetTransaction = errors.New("getting transaction failed") +// ErrGetSmartContractResults signals an error happening when trying to fetch smart contract results +var ErrGetSmartContractResults = errors.New("getting smart contract results failed") + // ErrGetBlock signals an error happening when trying to fetch a block var ErrGetBlock = errors.New("getting block failed") diff --git a/api/groups/transactionGroup.go b/api/groups/transactionGroup.go index 29d07de2640..1ae19424cb4 100644 --- a/api/groups/transactionGroup.go +++ b/api/groups/transactionGroup.go @@ -26,11 +26,13 @@ const ( simulateTransactionEndpoint = "/transaction/simulate" sendMultipleTransactionsEndpoint = "/transaction/send-multiple" getTransactionEndpoint = "/transaction/:hash" + getScrsByTxHashEndpoint = "/transaction/scrs-by-tx-hash/:txhash" sendTransactionPath = "/send" simulateTransactionPath = "/simulate" costPath = "/cost" sendMultiplePath = "/send-multiple" getTransactionPath = "/:txhash" + getScrsByTxHashPath = "/scrs-by-tx-hash/:txhash" getTransactionsPool = "/pool" queryParamWithResults = "withResults" @@ -39,6 +41,7 @@ const ( queryParamFields = "fields" queryParamLastNonce = "last-nonce" queryParamNonceGaps = "nonce-gaps" + queryParameterScrHash = "scrHash" ) // transactionFacadeHandler defines the methods to be implemented by a facade for transaction requests @@ -49,6 +52,7 @@ type transactionFacadeHandler interface { SendBulkTransactions([]*transaction.Transaction) (uint64, error) SimulateTransactionExecution(tx *transaction.Transaction) (*txSimData.SimulationResultsWithVMOutput, error) GetTransaction(hash string, withResults bool) (*transaction.ApiTransactionResult, error) + GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) GetTransactionsPool(fields string) (*common.TransactionsPoolAPIResponse, error) GetTransactionsPoolForSender(sender, fields string) (*common.TransactionsPoolForSenderApiResponse, error) GetLastPoolNonceForSender(sender string) (uint64, error) @@ -137,6 +141,17 @@ func NewTransactionGroup(facade transactionFacadeHandler) (*transactionGroup, er }, }, }, + { + Path: getScrsByTxHashPath, + Method: http.MethodGet, + Handler: tg.getTransaction, + AdditionalMiddlewares: []shared.AdditionalMiddleware{ + { + Middleware: middleware.CreateEndpointThrottlerFromFacade(getScrsByTxHashEndpoint, facade), + Position: shared.Before, + }, + }, + }, } tg.endpoints = endpoints @@ -421,6 +436,57 @@ func (tg *transactionGroup) sendMultipleTransactions(c *gin.Context) { ) } +func (tg *transactionGroup) getScrsByTxHash(c *gin.Context) { + txhash := c.Param("txhash") + if txhash == "" { + c.JSON( + http.StatusBadRequest, + shared.GenericAPIResponse{ + Data: nil, + Error: fmt.Sprintf("%s: %s", errors.ErrValidation.Error(), errors.ErrValidationEmptyTxHash.Error()), + Code: shared.ReturnCodeRequestError, + }, + ) + return + } + scrHashStr := c.Request.URL.Query().Get(queryParameterScrHash) + if scrHashStr == "" { + c.JSON( + http.StatusBadRequest, + shared.GenericAPIResponse{ + Data: nil, + Error: fmt.Sprintf("%s: %s", errors.ErrValidation.Error(), errors.ErrValidationEmptySCRHash.Error()), + Code: shared.ReturnCodeRequestError, + }, + ) + return + } + + start := time.Now() + scrs, err := tg.getFacade().GetSCRsByTxHash(txhash, scrHashStr) + if err != nil { + c.JSON( + http.StatusInternalServerError, + shared.GenericAPIResponse{ + Data: nil, + Error: fmt.Sprintf("%s: %s", errors.ErrGetSmartContractResults.Error(), err.Error()), + Code: shared.ReturnCodeInternalError, + }, + ) + return + } + logging.LogAPIActionDurationIfNeeded(start, "API call: GetSCRsByTxHash") + + c.JSON( + http.StatusOK, + shared.GenericAPIResponse{ + Data: gin.H{"scrs": scrs}, + Error: "", + Code: shared.ReturnCodeSuccess, + }, + ) +} + // getTransaction returns transaction details for a given txhash func (tg *transactionGroup) getTransaction(c *gin.Context) { txhash := c.Param("txhash") diff --git a/api/mock/facadeStub.go b/api/mock/facadeStub.go index e40645c1ac3..62de2febc81 100644 --- a/api/mock/facadeStub.go +++ b/api/mock/facadeStub.go @@ -97,6 +97,16 @@ type FacadeStub struct { GetWaitingEpochsLeftForPublicKeyCalled func(publicKey string) (uint32, error) P2PPrometheusMetricsEnabledCalled func() bool AuctionListHandler func() ([]*common.AuctionListValidatorAPIResponse, error) + GetSCRsByTxHashCalled func(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) +} + +// GetSCRsByTxHash - +func (f *FacadeStub) GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) { + if f.GetSCRsByTxHashCalled != nil { + return f.GetSCRsByTxHashCalled(txHash, scrHash) + } + + return nil, nil } // GetTokenSupply - diff --git a/api/shared/interface.go b/api/shared/interface.go index 4b775ebdd39..206cea6ee30 100644 --- a/api/shared/interface.go +++ b/api/shared/interface.go @@ -135,6 +135,7 @@ type FacadeHandler interface { GetEligibleManagedKeys() ([]string, error) GetWaitingManagedKeys() ([]string, error) GetWaitingEpochsLeftForPublicKey(publicKey string) (uint32, error) + GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) P2PPrometheusMetricsEnabled() bool IsInterfaceNil() bool } diff --git a/cmd/node/config/api.toml b/cmd/node/config/api.toml index a10ec049554..af0567899d1 100644 --- a/cmd/node/config/api.toml +++ b/cmd/node/config/api.toml @@ -221,6 +221,9 @@ # /transaction/:txhash will return the transaction in JSON format based on its hash { Name = "/:txhash", Open = true }, + + # /transaction/scrs-by-tx-hash/:txhash will return the smart contract results generated by the provided transaction hash + { Name = "/transaction/scrs-by-tx-hash/:txhash", Open = true }, ] [APIPackages.block] diff --git a/facade/initial/initialNodeFacade.go b/facade/initial/initialNodeFacade.go index 7411a2078e9..d6043dbcd62 100644 --- a/facade/initial/initialNodeFacade.go +++ b/facade/initial/initialNodeFacade.go @@ -421,6 +421,11 @@ func (inf *initialNodeFacade) IsDataTrieMigrated(_ string, _ api.AccountQueryOpt return false, errNodeStarting } +// GetSCRsByTxHash return a nil slice and error +func (inf *initialNodeFacade) GetSCRsByTxHash(_ string, _ string) ([]*transaction.ApiSmartContractResult, error) { + return nil, errNodeStarting +} + // GetManagedKeysCount returns 0 func (inf *initialNodeFacade) GetManagedKeysCount() int { return 0 diff --git a/facade/interface.go b/facade/interface.go index 35f185874ed..309f6c98d6f 100644 --- a/facade/interface.go +++ b/facade/interface.go @@ -127,6 +127,7 @@ type ApiResolver interface { GetDirectStakedList(ctx context.Context) ([]*api.DirectStakedValue, error) GetDelegatorsList(ctx context.Context) ([]*api.Delegator, error) GetTransaction(hash string, withResults bool) (*transaction.ApiTransactionResult, error) + GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) GetTransactionsPool(fields string) (*common.TransactionsPoolAPIResponse, error) GetTransactionsPoolForSender(sender, fields string) (*common.TransactionsPoolForSenderApiResponse, error) GetLastPoolNonceForSender(sender string) (uint64, error) diff --git a/facade/nodeFacade.go b/facade/nodeFacade.go index 8bc696b6adc..479cb4f5412 100644 --- a/facade/nodeFacade.go +++ b/facade/nodeFacade.go @@ -304,6 +304,10 @@ func (nf *nodeFacade) GetTransaction(hash string, withResults bool) (*transactio return nf.apiResolver.GetTransaction(hash, withResults) } +func (nf *nodeFacade) GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) { + return nf.apiResolver.GetSCRsByTxHash(txHash, scrHash) +} + // GetTransactionsPool will return a structure containing the transactions pool that is to be returned on API calls func (nf *nodeFacade) GetTransactionsPool(fields string) (*common.TransactionsPoolAPIResponse, error) { return nf.apiResolver.GetTransactionsPool(fields) diff --git a/integrationTests/chainSimulator/vm/esdtTokens_test.go b/integrationTests/chainSimulator/vm/esdtTokens_test.go index d12bfcbb550..1000265d8d0 100644 --- a/integrationTests/chainSimulator/vm/esdtTokens_test.go +++ b/integrationTests/chainSimulator/vm/esdtTokens_test.go @@ -107,6 +107,11 @@ func TestChainSimulator_Api_TokenType(t *testing.T) { require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) + scrs, err := cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().GetSCRsByTxHash(txResult.Hash, txResult.SmartContractResults[0].Hash) + require.Nil(t, err) + require.NotNil(t, scrs) + require.Equal(t, len(txResult.SmartContractResults), len(scrs)) + nftTokenID := txResult.Logs.Events[0].Topics[0] setAddressEsdtRoles(t, cs, nonce, addrs[0], nftTokenID, roles) nonce++ diff --git a/integrationTests/interface.go b/integrationTests/interface.go index e4be7fe388c..ad90ffbb6a3 100644 --- a/integrationTests/interface.go +++ b/integrationTests/interface.go @@ -118,5 +118,6 @@ type Facade interface { GetEligibleManagedKeys() ([]string, error) GetWaitingManagedKeys() ([]string, error) GetWaitingEpochsLeftForPublicKey(publicKey string) (uint32, error) + GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) IsInterfaceNil() bool } diff --git a/node/external/interface.go b/node/external/interface.go index a12ef177ce1..e70367e201d 100644 --- a/node/external/interface.go +++ b/node/external/interface.go @@ -61,6 +61,7 @@ type DelegatedListHandler interface { // APITransactionHandler defines what an API transaction handler should be able to do type APITransactionHandler interface { GetTransaction(txHash string, withResults bool) (*transaction.ApiTransactionResult, error) + GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) GetTransactionsPool(fields string) (*common.TransactionsPoolAPIResponse, error) GetTransactionsPoolForSender(sender, fields string) (*common.TransactionsPoolForSenderApiResponse, error) GetLastPoolNonceForSender(sender string) (uint64, error) diff --git a/node/external/nodeApiResolver.go b/node/external/nodeApiResolver.go index 0ae0356f4f7..b359c31b986 100644 --- a/node/external/nodeApiResolver.go +++ b/node/external/nodeApiResolver.go @@ -189,6 +189,10 @@ func (nar *nodeApiResolver) GetTransaction(hash string, withResults bool) (*tran return nar.apiTransactionHandler.GetTransaction(hash, withResults) } +func (nar *nodeApiResolver) GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) { + return nar.apiTransactionHandler.GetSCRsByTxHash(txHash, scrHash) +} + // GetTransactionsPool will return a structure containing the transactions pool that is to be returned on API calls func (nar *nodeApiResolver) GetTransactionsPool(fields string) (*common.TransactionsPoolAPIResponse, error) { return nar.apiTransactionHandler.GetTransactionsPool(fields) diff --git a/node/external/transactionAPI/apiTransactionProcessor.go b/node/external/transactionAPI/apiTransactionProcessor.go index b12aa9ac86f..bcfb265df62 100644 --- a/node/external/transactionAPI/apiTransactionProcessor.go +++ b/node/external/transactionAPI/apiTransactionProcessor.go @@ -2,6 +2,7 @@ package transactionAPI import ( "encoding/hex" + "errors" "fmt" "sort" "strings" @@ -86,6 +87,48 @@ func NewAPITransactionProcessor(args *ArgAPITransactionProcessor) (*apiTransacti }, nil } +func (atp *apiTransactionProcessor) GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) { + decodedScrHash, err := hex.DecodeString(scrHash) + if err != nil { + return nil, err + } + + decodedTxHash, err := hex.DecodeString(txHash) + if err != nil { + return nil, err + } + + if !atp.historyRepository.IsEnabled() { + return []*transaction.ApiSmartContractResult{}, nil + } + + miniblockMetadata, err := atp.historyRepository.GetMiniblockMetadataByTxHash(decodedScrHash) + if err != nil { + return nil, fmt.Errorf("%s: %w", ErrTransactionNotFound.Error(), err) + } + + resultsHashes, err := atp.historyRepository.GetResultsHashesByTxHash(decodedTxHash, miniblockMetadata.Epoch) + if err != nil { + // It's perfectly normal to have transactions without SCRs. + if errors.Is(err, dblookupext.ErrNotFoundInStorage) { + return []*transaction.ApiSmartContractResult{}, nil + } + return nil, err + } + + scrsAPI := make([]*transaction.ApiSmartContractResult, 0) + for _, scrHashesEpoch := range resultsHashes.ScResultsHashesAndEpoch { + scrs, errGet := atp.transactionResultsProcessor.getSmartContractResultsInTransactionByHashesAndEpoch(scrHashesEpoch.ScResultsHashes, scrHashesEpoch.Epoch) + if errGet != nil { + return nil, errGet + } + + scrsAPI = append(scrsAPI, scrs...) + } + + return scrsAPI, nil +} + // GetTransaction gets the transaction based on the given hash. It will search in the cache and the storage and // will return the transaction in a format which can be respected by all types of transactions (normal, reward or unsigned) func (atp *apiTransactionProcessor) GetTransaction(txHash string, withResults bool) (*transaction.ApiTransactionResult, error) { diff --git a/node/external/transactionAPI/apiTransactionResults.go b/node/external/transactionAPI/apiTransactionResults.go index 125376f39da..d4a89edfd15 100644 --- a/node/external/transactionAPI/apiTransactionResults.go +++ b/node/external/transactionAPI/apiTransactionResults.go @@ -102,10 +102,12 @@ func (arp *apiTransactionResultsProcessor) putSmartContractResultsInTransaction( scrHashesEpoch []*dblookupext.ScResultsHashesAndEpoch, ) error { for _, scrHashesE := range scrHashesEpoch { - err := arp.putSmartContractResultsInTransactionByHashesAndEpoch(tx, scrHashesE.ScResultsHashes, scrHashesE.Epoch) + scrsAPI, err := arp.getSmartContractResultsInTransactionByHashesAndEpoch(scrHashesE.ScResultsHashes, scrHashesE.Epoch) if err != nil { return err } + + tx.SmartContractResults = append(tx.SmartContractResults, scrsAPI...) } statusFilters := filters.NewStatusFilters(arp.shardCoordinator.SelfId()) @@ -113,21 +115,22 @@ func (arp *apiTransactionResultsProcessor) putSmartContractResultsInTransaction( return nil } -func (arp *apiTransactionResultsProcessor) putSmartContractResultsInTransactionByHashesAndEpoch(tx *transaction.ApiTransactionResult, scrsHashes [][]byte, epoch uint32) error { +func (arp *apiTransactionResultsProcessor) getSmartContractResultsInTransactionByHashesAndEpoch(scrsHashes [][]byte, epoch uint32) ([]*transaction.ApiSmartContractResult, error) { + scrsAPI := make([]*transaction.ApiSmartContractResult, 0, len(scrsHashes)) for _, scrHash := range scrsHashes { scr, err := arp.getScrFromStorage(scrHash, epoch) if err != nil { - return fmt.Errorf("%w: %v, hash = %s", errCannotLoadContractResults, err, hex.EncodeToString(scrHash)) + return nil, fmt.Errorf("%w: %v, hash = %s", errCannotLoadContractResults, err, hex.EncodeToString(scrHash)) } scrAPI := arp.adaptSmartContractResult(scrHash, scr) arp.loadLogsIntoContractResults(scrHash, epoch, scrAPI) - tx.SmartContractResults = append(tx.SmartContractResults, scrAPI) + scrsAPI = append(scrsAPI, scrAPI) } - return nil + return scrsAPI, nil } func (arp *apiTransactionResultsProcessor) loadLogsIntoTransaction(hash []byte, tx *transaction.ApiTransactionResult, epoch uint32) { diff --git a/node/mock/apiTransactionHandlerStub.go b/node/mock/apiTransactionHandlerStub.go index 2ae18622197..4bd9ca4633f 100644 --- a/node/mock/apiTransactionHandlerStub.go +++ b/node/mock/apiTransactionHandlerStub.go @@ -15,6 +15,16 @@ type TransactionAPIHandlerStub struct { UnmarshalTransactionCalled func(txBytes []byte, txType transaction.TxType) (*transaction.ApiTransactionResult, error) UnmarshalReceiptCalled func(receiptBytes []byte) (*transaction.ApiReceipt, error) PopulateComputedFieldsCalled func(tx *transaction.ApiTransactionResult) + GetSCRsByTxHashCalled func(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) +} + +// GetSCRsByTxHash -- +func (tas *TransactionAPIHandlerStub) GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) { + if tas.GetSCRsByTxHashCalled != nil { + return tas.GetSCRsByTxHashCalled(txHash, scrHash) + } + + return nil, nil } // GetTransaction - From 2bad2a74fad592e0cdcdf603777b9804af5db11c Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 5 Aug 2024 15:18:16 +0300 Subject: [PATCH 469/503] fix --- cmd/node/config/api.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/node/config/api.toml b/cmd/node/config/api.toml index af0567899d1..fcf9cf7fc0b 100644 --- a/cmd/node/config/api.toml +++ b/cmd/node/config/api.toml @@ -223,7 +223,7 @@ { Name = "/:txhash", Open = true }, # /transaction/scrs-by-tx-hash/:txhash will return the smart contract results generated by the provided transaction hash - { Name = "/transaction/scrs-by-tx-hash/:txhash", Open = true }, + { Name = "/scrs-by-tx-hash/:txhash", Open = true }, ] [APIPackages.block] From 792f6a7ac100590c2ca3dcbc3af91b81cd82dc84 Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 5 Aug 2024 15:24:58 +0300 Subject: [PATCH 470/503] fix endpoint --- api/groups/transactionGroup.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/groups/transactionGroup.go b/api/groups/transactionGroup.go index 1ae19424cb4..83eb97136b8 100644 --- a/api/groups/transactionGroup.go +++ b/api/groups/transactionGroup.go @@ -144,7 +144,7 @@ func NewTransactionGroup(facade transactionFacadeHandler) (*transactionGroup, er { Path: getScrsByTxHashPath, Method: http.MethodGet, - Handler: tg.getTransaction, + Handler: tg.getScrsByTxHash, AdditionalMiddlewares: []shared.AdditionalMiddleware{ { Middleware: middleware.CreateEndpointThrottlerFromFacade(getScrsByTxHashEndpoint, facade), From 77d133cac079b715405c5b1e8d64a4a9527eaec0 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 6 Aug 2024 12:02:06 +0300 Subject: [PATCH 471/503] even newer wasmer --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 45b20fe50cb..af2b74d188e 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.4 github.com/multiversx/mx-chain-storage-go v1.0.16 github.com/multiversx/mx-chain-vm-common-go v1.5.13 - github.com/multiversx/mx-chain-vm-go v1.5.31-0.20240802091618-d50489328579 + github.com/multiversx/mx-chain-vm-go v1.5.31 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index 00a1ae81423..1dd242a3f9c 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1X 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.13 h1:ymnIHJW4Z4mFa0hZzla4fozkF30vjH5O1q+Y7Ftc+pQ= github.com/multiversx/mx-chain-vm-common-go v1.5.13/go.mod h1:OSvFbzdWThfRbLZbUsEr7bikBSaLrPJQ2iUm9jw9nXQ= -github.com/multiversx/mx-chain-vm-go v1.5.31-0.20240802091618-d50489328579 h1:49NRtf8yd6dhM/gpkqjPYejNNIbuAUHTQj+plK64DVI= -github.com/multiversx/mx-chain-vm-go v1.5.31-0.20240802091618-d50489328579/go.mod h1:iq6sCPweoHC9Fx56uf8buPrqlGVGJKUMRFxTunzjvys= +github.com/multiversx/mx-chain-vm-go v1.5.31 h1:ywyqbVE94bhbO3LvcP/28pWoSR0NfEXLJNe+q1cgQ78= +github.com/multiversx/mx-chain-vm-go v1.5.31/go.mod h1:iq6sCPweoHC9Fx56uf8buPrqlGVGJKUMRFxTunzjvys= 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= From 6539ea4dd9f66e74b020893427895fee84fc33f7 Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 6 Aug 2024 14:00:31 +0300 Subject: [PATCH 472/503] fix tests --- facade/mock/apiResolverStub.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/facade/mock/apiResolverStub.go b/facade/mock/apiResolverStub.go index 33bae8518aa..8e38ab6707d 100644 --- a/facade/mock/apiResolverStub.go +++ b/facade/mock/apiResolverStub.go @@ -50,6 +50,16 @@ type ApiResolverStub struct { GetEligibleManagedKeysCalled func() ([]string, error) GetWaitingManagedKeysCalled func() ([]string, error) GetWaitingEpochsLeftForPublicKeyCalled func(publicKey string) (uint32, error) + GetSCRsByTxHashCalled func(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) +} + +// GetSCRsByTxHash - +func (ars *ApiResolverStub) GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) { + if ars.GetSCRsByTxHashCalled != nil { + return ars.GetSCRsByTxHashCalled(txHash, scrHash) + } + + return nil, nil } // GetTransaction - From 708e08e99b2fa9520966b9047f0535767b2eb69e Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 6 Aug 2024 14:26:47 +0300 Subject: [PATCH 473/503] unit tests --- .../apiTransactionProcessor_test.go | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/node/external/transactionAPI/apiTransactionProcessor_test.go b/node/external/transactionAPI/apiTransactionProcessor_test.go index 7d86a1610c5..3101cf763f4 100644 --- a/node/external/transactionAPI/apiTransactionProcessor_test.go +++ b/node/external/transactionAPI/apiTransactionProcessor_test.go @@ -268,6 +268,93 @@ func TestNode_GetTransactionFromPool(t *testing.T) { require.Equal(t, transaction.TxStatusPending, actualG.Status) } +func TestNode_GetSCRs(t *testing.T) { + scResultHash := []byte("scHash") + txHash := []byte("txHash") + + marshalizer := &mock.MarshalizerFake{} + scResult := &smartContractResult.SmartContractResult{ + Nonce: 1, + SndAddr: []byte("snd"), + RcvAddr: []byte("rcv"), + OriginalTxHash: txHash, + Data: []byte("test"), + } + + resultHashesByTxHash := &dblookupext.ResultsHashesByTxHash{ + ScResultsHashesAndEpoch: []*dblookupext.ScResultsHashesAndEpoch{ + { + Epoch: 0, + ScResultsHashes: [][]byte{scResultHash}, + }, + }, + } + + chainStorer := &storageStubs.ChainStorerStub{ + GetStorerCalled: func(unitType dataRetriever.UnitType) (storage.Storer, error) { + switch unitType { + case dataRetriever.UnsignedTransactionUnit: + return &storageStubs.StorerStub{ + GetFromEpochCalled: func(key []byte, epoch uint32) ([]byte, error) { + return marshalizer.Marshal(scResult) + }, + }, nil + default: + return nil, storage.ErrKeyNotFound + } + }, + } + + historyRepo := &dblookupextMock.HistoryRepositoryStub{ + GetMiniblockMetadataByTxHashCalled: func(hash []byte) (*dblookupext.MiniblockMetadata, error) { + return &dblookupext.MiniblockMetadata{}, nil + }, + GetEventsHashesByTxHashCalled: func(hash []byte, epoch uint32) (*dblookupext.ResultsHashesByTxHash, error) { + return resultHashesByTxHash, nil + }, + } + + feeComp := &testscommon.FeeComputerStub{ + ComputeTransactionFeeCalled: func(tx *transaction.ApiTransactionResult) *big.Int { + return big.NewInt(1000) + }, + } + + args := &ArgAPITransactionProcessor{ + RoundDuration: 0, + GenesisTime: time.Time{}, + Marshalizer: &mock.MarshalizerFake{}, + AddressPubKeyConverter: &testscommon.PubkeyConverterMock{}, + ShardCoordinator: &mock.ShardCoordinatorMock{}, + HistoryRepository: historyRepo, + StorageService: chainStorer, + DataPool: dataRetrieverMock.NewPoolsHolderMock(), + Uint64ByteSliceConverter: mock.NewNonceHashConverterMock(), + FeeComputer: feeComp, + TxTypeHandler: &testscommon.TxTypeHandlerMock{}, + LogsFacade: &testscommon.LogsFacadeStub{}, + DataFieldParser: &testscommon.DataFieldParserStub{ + ParseCalled: func(dataField []byte, sender, receiver []byte, _ uint32) *datafield.ResponseParseData { + return &datafield.ResponseParseData{} + }, + }, + } + apiTransactionProc, _ := NewAPITransactionProcessor(args) + + scrs, err := apiTransactionProc.GetSCRsByTxHash(hex.EncodeToString(txHash), hex.EncodeToString(scResultHash)) + require.Nil(t, err) + require.Equal(t, 1, len(scrs)) + require.Equal(t, &transaction.ApiSmartContractResult{ + Nonce: 1, + Data: "test", + Hash: "736348617368", + RcvAddr: "726376", + SndAddr: "736e64", + OriginalTxHash: "747848617368", + Receivers: []string{}, + }, scrs[0]) +} + func TestNode_GetTransactionFromStorage(t *testing.T) { t.Parallel() From abf23769b5b9136e3ec1f7d7c014d9447b7359db Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 6 Aug 2024 14:37:27 +0300 Subject: [PATCH 474/503] tags --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 7ef2feb817b..cf1bccc8a8d 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.3 github.com/multiversx/mx-chain-storage-go v1.0.15 github.com/multiversx/mx-chain-vm-common-go v1.5.12 - github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240801054658-dd0579e7d74b + github.com/multiversx/mx-chain-vm-go v1.5.30-patch1 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.97 diff --git a/go.sum b/go.sum index a36b7ceb563..c74b95d8eeb 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240801054658-dd0579e7d74b h1:gPOH3m+KxTZr4K5af3cS0URQKRLL8WsHXcY1PJeCtO0= -github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240801054658-dd0579e7d74b/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go v1.5.30-patch1 h1:fFCSnV/JKxr1Rr5K4CXkDrwHzp7ZsGK0X4bRmwx0Cgk= +github.com/multiversx/mx-chain-vm-go v1.5.30-patch1/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From 55b7954d236886e0440b91f6be49ee4d3d8b62eb Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 6 Aug 2024 14:41:02 +0300 Subject: [PATCH 475/503] tags --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index cf1bccc8a8d..24474aeef37 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.3 github.com/multiversx/mx-chain-storage-go v1.0.15 github.com/multiversx/mx-chain-vm-common-go v1.5.12 - github.com/multiversx/mx-chain-vm-go v1.5.30-patch1 + github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.97 diff --git a/go.sum b/go.sum index c74b95d8eeb..ec1a900502b 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go v1.5.30-patch1 h1:fFCSnV/JKxr1Rr5K4CXkDrwHzp7ZsGK0X4bRmwx0Cgk= -github.com/multiversx/mx-chain-vm-go v1.5.30-patch1/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 h1:wDrE+ZMoHH+BzG3n4ERUR9Luas2w+GvV6e3w4r9hFw0= +github.com/multiversx/mx-chain-vm-go v1.5.29-patch1/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From d8f0a125205466cacd00a5ba20cadf4f1da7590d Mon Sep 17 00:00:00 2001 From: python-qa Date: Tue, 6 Aug 2024 10:11:03 +0300 Subject: [PATCH 476/503] pre-final version. Add gh-action yml that build mx-chain-simulator-go latest version with latest hash from mx-chain-go, and execute system tests --- ...hain_simulator_and_execute_system_test.yml | 341 ++++++++++++++++++ 1 file changed, 341 insertions(+) create mode 100644 .github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml diff --git a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml new file mode 100644 index 00000000000..cd405ee65a6 --- /dev/null +++ b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml @@ -0,0 +1,341 @@ +name: Build and Smoke Test + +on: + pull_request: + branches: + - 'main' + - 'master' + - 'rc/*' + workflow_dispatch: + issue_comment: + types: [created] + +permissions: + issues: write + pull-requests: write + contents: read + +jobs: + build-and-test: + if: | + github.event_name == 'pull_request' || + (github.event_name == 'issue_comment' && contains(github.event.comment.body, 'Run Tests:')) || + github.event_name == 'workflow_dispatch' + + strategy: + matrix: + #TODO Include Macos support later on + runs-on: [ubuntu-latest] + runs-on: ${{ matrix.runs-on }} + env: + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} + TARGET_BRANCH: "" + MX_CHAIN_GO_TARGET_BRANCH: "" + MX_CHAIN_SIMULATOR_TARGET_BRANCH: "" + MX_CHAIN_TESTING_SUITE_TARGET_BRANCH: "" + + steps: + - name: Fetch Latest Comment + if: github.event_name != 'issue_comment' + uses: actions/github-script@v7 + id: fetch_comment + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const comments = await github.rest.issues.listComments({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + }); + + // Filter for comments containing "Run Tests:" + const latestComment = comments.data.reverse().find(comment => comment.body.includes('Run Tests:')); + + if (latestComment) { + core.setOutput('latest_comment', latestComment.body); + } else { + core.setOutput('latest_comment', ''); + } + env: + LATEST_COMMENT: ${{ steps.fetch_comment.outputs.latest_comment }} + + - name: Parse Comment for Branches + run: | + # Use fetched comment if available, otherwise use current event comment + COMMENT="${{ steps.fetch_comment.outputs.latest_comment || github.event.comment.body }}" + + # Debug print the comment being used + echo "Comment used for parsing: $COMMENT" + + # Extract branch names from the comment + if echo "$COMMENT" | grep -q "mx-chain-simulator-go:"; then + SIMULATOR_BRANCH=$(echo "$COMMENT" | grep "mx-chain-simulator-go:" | awk -F': ' '{print $2}') + echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=${SIMULATOR_BRANCH}" >> $GITHUB_ENV + fi + + if echo "$COMMENT" | grep -q "mx-chain-testing-suite:"; then + TESTING_SUITE_BRANCH=$(echo "$COMMENT" | grep "mx-chain-testing-suite:" | awk -F': ' '{print $2}') + echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=${TESTING_SUITE_BRANCH}" >> $GITHUB_ENV + fi + + - name: Set up Go 1.20.7 + uses: actions/setup-go@v3 + with: + go-version: 1.20.7 + id: go + + - name: Checkout mx-chain-go + uses: actions/checkout@v4 + with: + repository: 'multiversx/mx-chain-go' + ref: ${{ env.MX_CHAIN_GO_TARGET_BRANCH || github.head_ref || github.ref }} + fetch-depth: 0 + path: 'mx-chain-go' + + - name: Get Latest Commit Hash + run: | + cd mx-chain-go + current_branch=$(git symbolic-ref --short HEAD) + echo "CURRENT_BRANCH=${current_branch}" >> $GITHUB_ENV + git fetch origin ${current_branch} --prune + latest_commit_hash=$(git rev-parse origin/${current_branch}) + echo "LATEST_COMMIT_HASH=${latest_commit_hash}" >> $GITHUB_ENV + echo "Latest commit hash: ${latest_commit_hash}" + + - name: Determine Target Branches + id: target_branch + run: | + echo "CURRENT_BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}" >> $GITHUB_ENV + + # Use branches from comment if they are set + if [ -n "${{ env.MX_CHAIN_SIMULATOR_TARGET_BRANCH }}" ]; then + echo "Using comment-specified mx-chain-simulator-go branch: ${{ env.MX_CHAIN_SIMULATOR_TARGET_BRANCH }}" + echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=${{ env.MX_CHAIN_SIMULATOR_TARGET_BRANCH }}" >> $GITHUB_ENV + else + if [[ "${{ github.event.pull_request.base.ref }}" == "main" ]]; then + echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=main" >> $GITHUB_ENV + elif [[ "${{ github.event.pull_request.base.ref }}" == "master" ]]; then + echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=main" >> $GITHUB_ENV + elif [[ "${{ github.event.pull_request.base.ref }}" == rc/* || "${{ github.event.pull_request.base.ref }}" == integrate-sys-tests-ci* ]]; then + echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV + fi + fi + + if [ -n "${{ env.MX_CHAIN_TESTING_SUITE_TARGET_BRANCH }}" ]; then + echo "Using comment-specified mx-chain-testing-suite branch: ${{ env.MX_CHAIN_TESTING_SUITE_TARGET_BRANCH }}" + echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=${{ env.MX_CHAIN_TESTING_SUITE_TARGET_BRANCH }}" >> $GITHUB_ENV + else + if [[ "${{ github.event.pull_request.base.ref }}" == "main" ]]; then + echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=main" >> $GITHUB_ENV + elif [[ "${{ github.event.pull_request.base.ref }}" == "master" ]]; then + echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=main" >> $GITHUB_ENV + elif [[ "${{ github.event.pull_request.base.ref }}" == rc/* || "${{ github.event.pull_request.base.ref }}" == integrate-sys-tests-ci* ]]; then + echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV + fi + fi + + # Always set MX_CHAIN_GO_TARGET_BRANCH based on the PR base branch + echo "MX_CHAIN_GO_TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV + + + - name: Print Target Branches + run: | + echo "Current branch mx-chain-go: ${{ env.CURRENT_BRANCH }}" + echo "mx-chain-go target branch: ${{ env.MX_CHAIN_GO_TARGET_BRANCH }}" + echo "mx-chain-simulator-go target branch: ${{ env.MX_CHAIN_SIMULATOR_TARGET_BRANCH }}" + echo "mx-chain-testing-suite target branch: ${{ env.MX_CHAIN_TESTING_SUITE_TARGET_BRANCH }}" + + - name: Checkout mx-chain-simulator-go + uses: actions/checkout@v4 + with: + repository: 'multiversx/mx-chain-simulator-go' + ref: ${{ env.MX_CHAIN_SIMULATOR_TARGET_BRANCH || github.event.pull_request.base.ref }} + path: 'mx-chain-simulator-go' + + - name: Set up Python 3.10 + uses: actions/setup-python@v2 + with: + python-version: '3.10' + + - name: Install Python Dependencies and Update go.mod + run: | + cd mx-chain-simulator-go + pip install -r scripts/update_go_mod/requirements.txt + python scripts/update_go_mod/update_go_mod.py $LATEST_COMMIT_HASH + + + - name: Run go mod tidy and go build + run: | + cd mx-chain-simulator-go/cmd/chainsimulator + go mod tidy + go build + echo "CHAIN_SIMULATOR_BUILD_PATH=$(pwd)" >> $GITHUB_ENV + + - name: Checkout mx-chain-testing-suite + uses: actions/checkout@v4 + with: + repository: 'multiversx/mx-chain-testing-suite' + path: 'mx-chain-testing-suite' + fetch-depth: 0 + ref: ${{ env.MX_CHAIN_TESTING_SUITE_TARGET_BRANCH || github.event.pull_request.base.ref }} + token: ${{ secrets.MVX_TESTER_GH_TOKEN }} + + - name: Install Dependencies + run: | + pip install -r mx-chain-testing-suite/requirements.txt + echo "PYTHONPATH=mx-chain-testing-suite" >> $GITHUB_ENV + + + - name: Run tests and generate HTML report + run: | + set +e + pytest mx-chain-testing-suite/scenarios/ --html=report.html --self-contained-html --continue-on-collection-errors + PYTEST_EXIT_CODE=$? + set -e + echo "PYTEST_EXIT_CODE=$PYTEST_EXIT_CODE" >> $GITHUB_ENV + echo "Pytest exit code: $PYTEST_EXIT_CODE" + if [ -f "report.html" ]; then + echo "Report generated successfully." + mkdir -p ./reports + mv report.html ./reports/ + else + echo "Report not found." + fi + + - name: Upload test report + if: always() + uses: actions/upload-artifact@v2 + with: + name: pytest-report-${{ github.run_id }} + path: reports/report.html + + - name: Deploy Report to GitHub Pages + if: always() + id: deploy_report + run: | + # Navigate to the mx-chain-testing-suite directory + cd mx-chain-testing-suite + + # Configure Git user + git config user.name "GitHub Action" + git config user.email "action@github.com" + + # Check if the report exists + if [ -f "../reports/report.html" ]; then + # Ensure we're on the 'gh-pages' branch and up to date + git fetch --all + git checkout gh-pages || git checkout --orphan gh-pages + + # Create a new directory for the report based on the current timestamp + TIMESTAMP=$(date +'%d%m%Y-%H%M%S') + echo "TIMESTAMP=$TIMESTAMP" >> $GITHUB_ENV + REPORT_DIR="reports/${BRANCH_NAME}/${TIMESTAMP}" + mkdir -p $REPORT_DIR + + # Move the report into the new directory + cp ../reports/report.html $REPORT_DIR/index.html + + # Add and commit only the new report + git add $REPORT_DIR/index.html + git commit -m "Deploy Test Report at $BRANCH_NAME/$TIMESTAMP" + + # Set remote URL with authentication token + git remote set-url origin https://x-access-token:${{ secrets.MVX_TESTER_GH_TOKEN }}@github.com/multiversx/mx-chain-testing-suite.git + + # Push changes to the remote 'gh-pages' branch + git push --force origin gh-pages + else + echo "Report file not found, skipping deployment." + fi + + + - name: Update Index Page + if: always() + run: | + cd mx-chain-testing-suite + git fetch --all + git checkout gh-pages || git checkout --orphan gh-pages + if [ -d "docs" ]; then + cd docs + echo "

Test Reports

    " > index.html + for report in $(ls ../reports); do + echo "
  • Report - $report
  • " >> index.html + done + echo "
" >> index.html + git add index.html + git commit -m "Update Index of Reports" + git push origin gh-pages --force + else + mkdir -p docs + cd docs + echo "

Test Reports

    " > index.html + echo "
" >> index.html + echo "Docs directory was not found and has been created." + fi + + - name: Comment PR with report link or error message + if: always() + uses: actions/github-script@v7 + env: + TIMESTAMP: ${{ env.TIMESTAMP }} + BRANCH_NAME: ${{ env.BRANCH_NAME }} + CURRENT_BRANCH: ${{ env.CURRENT_BRANCH }} + MX_CHAIN_GO_TARGET_BRANCH: ${{ env.MX_CHAIN_GO_TARGET_BRANCH }} + MX_CHAIN_SIMULATOR_TARGET_BRANCH: ${{ env.MX_CHAIN_SIMULATOR_TARGET_BRANCH }} + MX_CHAIN_TESTING_SUITE_TARGET_BRANCH: ${{ env.MX_CHAIN_TESTING_SUITE_TARGET_BRANCH }} + LATEST_COMMIT_HASH: ${{ env.LATEST_COMMIT_HASH }} + PYTEST_EXIT_CODE: ${{ env.PYTEST_EXIT_CODE }} + + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const timestamp = process.env.TIMESTAMP; + const branchName = process.env.BRANCH_NAME; + const currentBranch = process.env.CURRENT_BRANCH; + const goTargetBranch = process.env.MX_CHAIN_GO_TARGET_BRANCH; + const simulatorTargetBranch = process.env.MX_CHAIN_SIMULATOR_TARGET_BRANCH; + const testingSuiteTargetBranch = process.env.MX_CHAIN_TESTING_SUITE_TARGET_BRANCH; + const commitHash = process.env.LATEST_COMMIT_HASH; + const exitCode = process.env.PYTEST_EXIT_CODE; + const issue_number = context.issue.number; + const owner = context.repo.owner; + const repo = context.repo.repo; + let message; + + if (timestamp && branchName && timestamp !== "" && branchName !== "") { + const reportUrl = `https://multiversx.github.io/mx-chain-testing-suite/reports/${branchName}/${timestamp}/index.html`; + message = ` + 📊 **MultiversX Automated Test Report:** [View Report](${reportUrl}) + + 🔄 **Build Details:** + - **mx-chain-go Commit Hash:** \`${commitHash}\` + - **Current Branch:** \`${currentBranch}\` + - **mx-chain-go Target Branch:** \`${goTargetBranch}\` + - **mx-chain-simulator-go Target Branch:** \`${simulatorTargetBranch}\` + - **mx-chain-testing-suite Target Branch:** \`${testingSuiteTargetBranch}\` + + 🚀 **Environment Variables:** + - **TIMESTAMP:** \`${timestamp}\` + - **PYTEST_EXIT_CODE:** \`${exitCode}\` + 🎉 **MultiversX CI/CD Workflow Complete!** + `; + } else { + message = "⚠️ No report was generated due to an error or cancellation of the process.\nPlease checkout gh action logs for details"; + } + + github.rest.issues.createComment({ + issue_number: issue_number, + owner: owner, + repo: repo, + body: message + }); + + - name: Fail job if tests failed + if: always() + run: | + if [ "${{ env.PYTEST_EXIT_CODE }}" != "0" ]; then + echo "Tests failed with exit code ${{ env.PYTEST_EXIT_CODE }}" + exit 1 + else + echo "Tests passed successfully." + fi \ No newline at end of file From b60aa5278067d7cdd426d97cec1ff9df1e11ad0c Mon Sep 17 00:00:00 2001 From: python-qa Date: Wed, 7 Aug 2024 15:31:21 +0300 Subject: [PATCH 477/503] fix PR comments. Remove go Tidy from action and move it to the python script --- ...ild_and_run_chain_simulator_and_execute_system_test.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml index cd405ee65a6..4ea0d71b04a 100644 --- a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml +++ b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml @@ -24,7 +24,7 @@ jobs: strategy: matrix: - #TODO Include Macos support later on + #TODO Include Macos support later on runs-on: [ubuntu-latest] runs-on: ${{ matrix.runs-on }} env: @@ -116,8 +116,6 @@ jobs: echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=main" >> $GITHUB_ENV elif [[ "${{ github.event.pull_request.base.ref }}" == "master" ]]; then echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=main" >> $GITHUB_ENV - elif [[ "${{ github.event.pull_request.base.ref }}" == rc/* || "${{ github.event.pull_request.base.ref }}" == integrate-sys-tests-ci* ]]; then - echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV fi fi @@ -129,8 +127,6 @@ jobs: echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=main" >> $GITHUB_ENV elif [[ "${{ github.event.pull_request.base.ref }}" == "master" ]]; then echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=main" >> $GITHUB_ENV - elif [[ "${{ github.event.pull_request.base.ref }}" == rc/* || "${{ github.event.pull_request.base.ref }}" == integrate-sys-tests-ci* ]]; then - echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV fi fi @@ -167,7 +163,6 @@ jobs: - name: Run go mod tidy and go build run: | cd mx-chain-simulator-go/cmd/chainsimulator - go mod tidy go build echo "CHAIN_SIMULATOR_BUILD_PATH=$(pwd)" >> $GITHUB_ENV From a94af2a9e61f41bb7817106ca62efa2c138dcea9 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 8 Aug 2024 10:42:41 +0300 Subject: [PATCH 478/503] updated deps after merge --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index af2b74d188e..4667bd06e7e 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.4 github.com/multiversx/mx-chain-storage-go v1.0.16 github.com/multiversx/mx-chain-vm-common-go v1.5.13 - github.com/multiversx/mx-chain-vm-go v1.5.31 + github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240808073353-f1fbbf147537 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index 1dd242a3f9c..11a9bc62556 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1X 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.13 h1:ymnIHJW4Z4mFa0hZzla4fozkF30vjH5O1q+Y7Ftc+pQ= github.com/multiversx/mx-chain-vm-common-go v1.5.13/go.mod h1:OSvFbzdWThfRbLZbUsEr7bikBSaLrPJQ2iUm9jw9nXQ= -github.com/multiversx/mx-chain-vm-go v1.5.31 h1:ywyqbVE94bhbO3LvcP/28pWoSR0NfEXLJNe+q1cgQ78= -github.com/multiversx/mx-chain-vm-go v1.5.31/go.mod h1:iq6sCPweoHC9Fx56uf8buPrqlGVGJKUMRFxTunzjvys= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240808073353-f1fbbf147537 h1:x1Fn0tlkicBNsRB/co/c9TTjyvCrzmE/rVXA8uUWhII= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240808073353-f1fbbf147537/go.mod h1:iq6sCPweoHC9Fx56uf8buPrqlGVGJKUMRFxTunzjvys= 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= From f894d55b5cee58b7a96d895b4a45919642468c72 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 8 Aug 2024 13:50:59 +0300 Subject: [PATCH 479/503] use macos-13 instead of latest --- .github/workflows/build_and_test.yml | 2 +- .github/workflows/create_release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 19fdaec07e0..d552db889c7 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-latest, macos-13-xlarge] + runs-on: [ubuntu-latest, macos-13, macos-13-xlarge] runs-on: ${{ matrix.runs-on }} name: Build steps: diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index ca13a9f0313..fe74d301325 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-latest, macos-13-xlarge] + runs-on: [ubuntu-latest, macos-13, macos-13-xlarge] runs-on: ${{ matrix.runs-on }} name: Build steps: From 75cb69565b9bcfb05c4eb3cea1d38fd5b6a21c6a Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 8 Aug 2024 21:00:36 +0300 Subject: [PATCH 480/503] added fix for relayed move balance to non payables --- cmd/node/config/enableEpochs.toml | 3 + common/constants.go | 4 ++ common/enablers/enableEpochsHandler.go | 6 ++ common/enablers/enableEpochsHandler_test.go | 3 + config/epochConfig.go | 1 + config/tomlConfig_test.go | 4 ++ .../relayedTx/relayedTx_test.go | 70 +++++++++++++++++++ .../vm/esdtImprovements_test.go | 1 - .../multiShard/relayedTx/common.go | 1 + integrationTests/testProcessorNode.go | 1 + node/metrics/metrics.go | 1 + node/metrics/metrics_test.go | 2 + process/transaction/shardProcess.go | 39 +++++++++++ process/transaction/shardProcess_test.go | 63 +++++++++++++++++ statusHandler/statusMetricsProvider.go | 1 + statusHandler/statusMetricsProvider_test.go | 2 + 16 files changed, 201 insertions(+), 1 deletion(-) diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index f088f7b549c..60884a826e0 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -330,6 +330,9 @@ # MultiESDTNFTTransferAndExecuteByUserEnableEpoch represents the epoch when enshrined sovereign cross chain opcodes are enabled MultiESDTNFTTransferAndExecuteByUserEnableEpoch = 9999999 + # FixRelayedMoveBalanceToNonPayableSCEnableEpoch represents the epoch when the fix for relayed move balance to non payable sc will be enabled + FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 7 + # BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers BLSMultiSignerEnableEpoch = [ { EnableEpoch = 0, Type = "no-KOSK" }, diff --git a/common/constants.go b/common/constants.go index 984dec87b07..2a7948ca9ee 100644 --- a/common/constants.go +++ b/common/constants.go @@ -737,6 +737,9 @@ const ( // MetricMultiESDTNFTTransferAndExecuteByUserEnableEpoch represents the epoch when enshrined sovereign opcodes are enabled MetricMultiESDTNFTTransferAndExecuteByUserEnableEpoch = "erd_multi_esdt_transfer_execute_by_user_enable_epoch" + // MetricFixRelayedMoveBalanceToNonPayableSCEnableEpoch represents the epoch when the fix for relayed move balance to non-payable sc is enabled + MetricFixRelayedMoveBalanceToNonPayableSCEnableEpoch = "erd_fix_relayed_move_balance_to_non_payable_sc_enable_epoch" + // MetricMaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MetricMaxNodesChangeEnableEpoch = "erd_max_nodes_change_enable_epoch" @@ -1233,5 +1236,6 @@ const ( RelayedTransactionsV3Flag core.EnableEpochFlag = "RelayedTransactionsV3Flag" FixRelayedBaseCostFlag core.EnableEpochFlag = "FixRelayedBaseCostFlag" MultiESDTNFTTransferAndExecuteByUserFlag core.EnableEpochFlag = "MultiESDTNFTTransferAndExecuteByUserFlag" + FixRelayedMoveBalanceToNonPayableSCFlag core.EnableEpochFlag = "FixRelayedMoveBalanceToNonPayableSCFlag" // all new flags must be added to createAllFlagsMap method, as part of enableEpochsHandler allFlagsDefined ) diff --git a/common/enablers/enableEpochsHandler.go b/common/enablers/enableEpochsHandler.go index d3df21b6bbb..01155e47dcf 100644 --- a/common/enablers/enableEpochsHandler.go +++ b/common/enablers/enableEpochsHandler.go @@ -774,6 +774,12 @@ func (handler *enableEpochsHandler) createAllFlagsMap() { }, activationEpoch: handler.enableEpochsConfig.MultiESDTNFTTransferAndExecuteByUserEnableEpoch, }, + common.FixRelayedMoveBalanceToNonPayableSCFlag: { + isActiveInEpoch: func(epoch uint32) bool { + return epoch >= handler.enableEpochsConfig.FixRelayedMoveBalanceToNonPayableSCEnableEpoch + }, + activationEpoch: handler.enableEpochsConfig.FixRelayedMoveBalanceToNonPayableSCEnableEpoch, + }, } } diff --git a/common/enablers/enableEpochsHandler_test.go b/common/enablers/enableEpochsHandler_test.go index 72fafc5a689..48497586187 100644 --- a/common/enablers/enableEpochsHandler_test.go +++ b/common/enablers/enableEpochsHandler_test.go @@ -122,6 +122,7 @@ func createEnableEpochsConfig() config.EnableEpochs { RelayedTransactionsV3EnableEpoch: 105, FixRelayedBaseCostEnableEpoch: 106, MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 107, + FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 107, } } @@ -324,6 +325,7 @@ func TestEnableEpochsHandler_IsFlagEnabled(t *testing.T) { require.True(t, handler.IsFlagEnabled(common.DynamicESDTFlag)) require.True(t, handler.IsFlagEnabled(common.RelayedTransactionsV3Flag)) require.True(t, handler.IsFlagEnabled(common.FixRelayedBaseCostFlag)) + require.True(t, handler.IsFlagEnabled(common.FixRelayedMoveBalanceToNonPayableSCFlag)) } func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) { @@ -446,6 +448,7 @@ func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) { require.Equal(t, cfg.RelayedTransactionsV3EnableEpoch, handler.GetActivationEpoch(common.RelayedTransactionsV3Flag)) require.Equal(t, cfg.FixRelayedBaseCostEnableEpoch, handler.GetActivationEpoch(common.FixRelayedBaseCostFlag)) require.Equal(t, cfg.MultiESDTNFTTransferAndExecuteByUserEnableEpoch, handler.GetActivationEpoch(common.MultiESDTNFTTransferAndExecuteByUserFlag)) + require.Equal(t, cfg.MultiESDTNFTTransferAndExecuteByUserEnableEpoch, handler.GetActivationEpoch(common.FixRelayedMoveBalanceToNonPayableSCFlag)) } func TestEnableEpochsHandler_IsInterfaceNil(t *testing.T) { diff --git a/config/epochConfig.go b/config/epochConfig.go index 7f965e3c5c5..d449afe73af 100644 --- a/config/epochConfig.go +++ b/config/epochConfig.go @@ -121,6 +121,7 @@ type EnableEpochs struct { RelayedTransactionsV3EnableEpoch uint32 FixRelayedBaseCostEnableEpoch uint32 MultiESDTNFTTransferAndExecuteByUserEnableEpoch uint32 + FixRelayedMoveBalanceToNonPayableSCEnableEpoch uint32 BLSMultiSignerEnableEpoch []MultiSignerConfig } diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index c6cecedc774..ea9d1f6a46b 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -881,6 +881,9 @@ func TestEnableEpochConfig(t *testing.T) { # MultiESDTNFTTransferAndExecuteByUserEnableEpoch represents the epoch when enshrined sovereign cross chain opcodes are enabled MultiESDTNFTTransferAndExecuteByUserEnableEpoch = 101 + # FixRelayedMoveBalanceToNonPayableSCEnableEpoch represents the epoch when the fix for relayed move balance to non payable sc will be enabled + FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 102 + # MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MaxNodesChangeEnableEpoch = [ { EpochEnable = 44, MaxNumNodes = 2169, NodesToShufflePerShard = 80 }, @@ -1000,6 +1003,7 @@ func TestEnableEpochConfig(t *testing.T) { RelayedTransactionsV3EnableEpoch: 99, FixRelayedBaseCostEnableEpoch: 100, MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 101, + FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 102, MaxNodesChangeEnableEpoch: []MaxNodesChangeConfig{ { EpochEnable: 44, diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index 72bc9575763..6e71ae4bab9 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -267,6 +267,76 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorScCalls(t *t } } +func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorInvalidInnerMoveBalance(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + cs := startChainSimulator(t, func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.RelayedTransactionsV3EnableEpoch = 1 + cfg.EpochConfig.EnableEpochs.FixRelayedBaseCostEnableEpoch = 1 + cfg.EpochConfig.EnableEpochs.FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 1 + }) + defer cs.Close() + + initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(10)) + relayer, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + pkConv := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter() + + // deploy adder contract + owner, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + err = cs.GenerateBlocks(1) + require.Nil(t, err) + + ownerNonce := uint64(0) + scCode := wasm.GetSCCode("testData/adder.wasm") + params := []string{scCode, wasm.VMTypeHex, "0000", "00"} + txDataDeploy := strings.Join(params, "@") + deployTx := generateTransaction(owner.Bytes, ownerNonce, make([]byte, 32), big.NewInt(0), txDataDeploy, 100000000) + + result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(deployTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + scAddress := result.Logs.Events[0].Address + scAddressBytes, _ := pkConv.Decode(scAddress) + + balanceRelayerBefore := getBalance(t, cs, relayer) + balanceOwnerBefore := getBalance(t, cs, owner) + + // move balance to non-payable contract should only consume fees and sender's nonce + ownerNonce++ + innerTx1 := generateTransaction(owner.Bytes, ownerNonce, scAddressBytes, oneEGLD, "", 50000) + innerTx1.RelayerAddr = relayer.Bytes + + // move balance to meta contract should only consume fees and sender's nonce + ownerNonce++ + innerTx2 := generateTransaction(owner.Bytes, ownerNonce, core.ESDTSCAddress, oneEGLD, "", 50000) + innerTx2.RelayerAddr = relayer.Bytes + + innerTxs := []*transaction.Transaction{innerTx1, innerTx2} + + relayedTxGasLimit := uint64(0) + for _, tx := range innerTxs { + relayedTxGasLimit += minGasLimit + tx.GasLimit + } + relayedTx := generateTransaction(relayer.Bytes, 0, relayer.Bytes, big.NewInt(0), "", relayedTxGasLimit) + relayedTx.InnerTransactions = innerTxs + + _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + balanceRelayerAfter := getBalance(t, cs, relayer) + balanceOwnerAfter := getBalance(t, cs, owner) + consumedRelayedFee := core.SafeMul(relayedTxGasLimit, minGasPrice) + expectedBalanceRelayerAfter := big.NewInt(0).Sub(balanceRelayerBefore, consumedRelayedFee) + require.Equal(t, balanceOwnerBefore.String(), balanceOwnerAfter.String()) + require.Equal(t, expectedBalanceRelayerAfter.String(), balanceRelayerAfter.String()) +} + func TestFixRelayedMoveBalanceWithChainSimulator(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") 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) diff --git a/integrationTests/multiShard/relayedTx/common.go b/integrationTests/multiShard/relayedTx/common.go index c2bc8e5995c..6815d12802e 100644 --- a/integrationTests/multiShard/relayedTx/common.go +++ b/integrationTests/multiShard/relayedTx/common.go @@ -21,6 +21,7 @@ func CreateGeneralSetupForRelayTxTest(relayedV3Test bool) ([]*integrationTests.T if !relayedV3Test { epochsConfig.RelayedTransactionsV3EnableEpoch = integrationTests.UnreachableEpoch epochsConfig.FixRelayedBaseCostEnableEpoch = integrationTests.UnreachableEpoch + epochsConfig.FixRelayedMoveBalanceToNonPayableSCEnableEpoch = integrationTests.UnreachableEpoch } nodes, idxProposers := createAndMintNodes(initialVal, epochsConfig) diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index ef55c21f54a..cf76e1582d0 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -3277,6 +3277,7 @@ func CreateEnableEpochsConfig() config.EnableEpochs { SCProcessorV2EnableEpoch: UnreachableEpoch, RelayedTransactionsV3EnableEpoch: UnreachableEpoch, FixRelayedBaseCostEnableEpoch: UnreachableEpoch, + FixRelayedMoveBalanceToNonPayableSCEnableEpoch: UnreachableEpoch, } } diff --git a/node/metrics/metrics.go b/node/metrics/metrics.go index c380c08b95d..bc84198eca5 100644 --- a/node/metrics/metrics.go +++ b/node/metrics/metrics.go @@ -202,6 +202,7 @@ func InitConfigMetrics( appStatusHandler.SetUInt64Value(common.MetricEGLDInMultiTransferEnableEpoch, uint64(enableEpochs.EGLDInMultiTransferEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricCryptoOpcodesV2EnableEpoch, uint64(enableEpochs.CryptoOpcodesV2EnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricMultiESDTNFTTransferAndExecuteByUserEnableEpoch, uint64(enableEpochs.MultiESDTNFTTransferAndExecuteByUserEnableEpoch)) + appStatusHandler.SetUInt64Value(common.MetricFixRelayedMoveBalanceToNonPayableSCEnableEpoch, uint64(enableEpochs.FixRelayedMoveBalanceToNonPayableSCEnableEpoch)) for i, nodesChangeConfig := range enableEpochs.MaxNodesChangeEnableEpoch { epochEnable := fmt.Sprintf("%s%d%s", common.MetricMaxNodesChangeEnableEpoch, i, common.EpochEnableSuffix) diff --git a/node/metrics/metrics_test.go b/node/metrics/metrics_test.go index 395d42afc15..bec9f099923 100644 --- a/node/metrics/metrics_test.go +++ b/node/metrics/metrics_test.go @@ -211,6 +211,7 @@ func TestInitConfigMetrics(t *testing.T) { RelayedTransactionsV3EnableEpoch: 104, FixRelayedBaseCostEnableEpoch: 105, MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 106, + FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 107, MaxNodesChangeEnableEpoch: []config.MaxNodesChangeConfig{ { EpochEnable: 0, @@ -332,6 +333,7 @@ func TestInitConfigMetrics(t *testing.T) { "erd_relayed_transactions_v3_enable_epoch": uint32(104), "erd_fix_relayed_base_cost_enable_epoch": uint32(105), "erd_multi_esdt_transfer_execute_by_user_enable_epoch": uint32(106), + "erd_fix_relayed_move_balance_to_non_payable_sc_enable_epoch": uint32(107), "erd_max_nodes_change_enable_epoch": nil, "erd_total_supply": "12345", "erd_hysteresis": "0.100000", diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 129ad2c5db8..168eb19c539 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -500,14 +500,28 @@ func (txProc *txProcessor) processMoveBalance( isPayable, err := txProc.scProcessor.IsPayable(tx.SndAddr, tx.RcvAddr) if err != nil { + errRefund := txProc.removeConsumedValueFromSender(tx, acntSrc, isUserTxOfRelayed) + if errRefund != nil { + log.Warn("failed to return funds to sender after check if receiver is payable", "error", errRefund) + } return err } if !isPayable { + err = txProc.removeConsumedValueFromSender(tx, acntSrc, isUserTxOfRelayed) + if err != nil { + log.Warn("failed to return funds to sender while transferring to non payable sc", "error", err) + } + return process.ErrAccountNotPayable } err = txProc.checkIfValidTxToMetaChain(tx, tx.RcvAddr) if err != nil { + errLocal := txProc.removeConsumedValueFromSender(tx, acntSrc, isUserTxOfRelayed) + if errLocal != nil { + log.Warn("failed to return funds to sender while sending invalid tx to metachain", "error", errLocal) + } + return err } @@ -543,6 +557,31 @@ func (txProc *txProcessor) processMoveBalance( return nil } +func (txProc *txProcessor) removeConsumedValueFromSender( + tx *transaction.Transaction, + acntSrc state.UserAccountHandler, + isUserTxOfRelayed bool, +) error { + if !isUserTxOfRelayed { + return nil + } + + if !txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedMoveBalanceToNonPayableSCFlag) { + return nil + } + + if check.IfNil(acntSrc) { + return nil + } + + err := acntSrc.AddToBalance(tx.Value) + if err != nil { + return err + } + + return txProc.accounts.SaveAccount(acntSrc) +} + func (txProc *txProcessor) processSCDeployment( tx *transaction.Transaction, acntSrc state.UserAccountHandler, diff --git a/process/transaction/shardProcess_test.go b/process/transaction/shardProcess_test.go index 1f077525ae2..4c325a8f78e 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -3876,6 +3876,69 @@ func TestTxProcessor_AddNonExecutableLog(t *testing.T) { }) } +func TestTxProcessor_ProcessMoveBalanceToNonPayableContract(t *testing.T) { + t.Parallel() + + shardCoordinator := mock.NewOneShardCoordinatorMock() + + innerTx := transaction.Transaction{} + innerTx.Nonce = 1 + innerTx.SndAddr = []byte("SRC") + innerTx.RcvAddr = make([]byte, 32) + innerTx.Value = big.NewInt(100) + innerTx.RelayerAddr = []byte("SRC") + + tx := transaction.Transaction{} + tx.Nonce = 0 + tx.SndAddr = []byte("SRC") + tx.RcvAddr = []byte("SRC") + tx.Value = big.NewInt(0) + tx.InnerTransactions = []*transaction.Transaction{&innerTx} + + shardCoordinator.ComputeIdCalled = func(address []byte) uint32 { + return 0 + } + + acntSrc := createUserAcc(innerTx.SndAddr) + initialBalance := big.NewInt(100) + _ = acntSrc.AddToBalance(initialBalance) + acntDst := createUserAcc(innerTx.RcvAddr) + + adb := createAccountStub(innerTx.SndAddr, innerTx.RcvAddr, acntSrc, acntDst) + + args := createArgsForTxProcessor() + args.Accounts = adb + args.ShardCoordinator = shardCoordinator + cnt := 0 + args.TxTypeHandler = &testscommon.TxTypeHandlerMock{ + ComputeTransactionTypeCalled: func(tx data.TransactionHandler) (process.TransactionType, process.TransactionType) { + cnt++ + if cnt == 1 { + return process.RelayedTxV3, process.RelayedTxV3 + } + + return process.MoveBalance, process.MoveBalance + }, + } + args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub( + common.RelayedTransactionsV3Flag, + common.FixRelayedBaseCostFlag, + common.FixRelayedMoveBalanceToNonPayableSCFlag, + ) + args.ScProcessor = &testscommon.SCProcessorMock{ + IsPayableCalled: func(sndAddress, recvAddress []byte) (bool, error) { + return false, nil + }, + } + execTx, _ := txproc.NewTxProcessor(args) + + _, err := execTx.ProcessTransaction(&tx) + assert.Nil(t, err) + + balance := acntSrc.GetBalance() + require.Equal(t, initialBalance, balance) // disabled economics data, testing only tx.value +} + func TestTxProcessor_IsInterfaceNil(t *testing.T) { t.Parallel() diff --git a/statusHandler/statusMetricsProvider.go b/statusHandler/statusMetricsProvider.go index 30ead1e5749..8050d335431 100644 --- a/statusHandler/statusMetricsProvider.go +++ b/statusHandler/statusMetricsProvider.go @@ -378,6 +378,7 @@ func (sm *statusMetrics) EnableEpochsMetrics() (map[string]interface{}, error) { enableEpochsMetrics[common.MetricEGLDInMultiTransferEnableEpoch] = sm.uint64Metrics[common.MetricEGLDInMultiTransferEnableEpoch] enableEpochsMetrics[common.MetricCryptoOpcodesV2EnableEpoch] = sm.uint64Metrics[common.MetricCryptoOpcodesV2EnableEpoch] enableEpochsMetrics[common.MetricMultiESDTNFTTransferAndExecuteByUserEnableEpoch] = sm.uint64Metrics[common.MetricMultiESDTNFTTransferAndExecuteByUserEnableEpoch] + enableEpochsMetrics[common.MetricFixRelayedMoveBalanceToNonPayableSCEnableEpoch] = sm.uint64Metrics[common.MetricFixRelayedMoveBalanceToNonPayableSCEnableEpoch] numNodesChangeConfig := sm.uint64Metrics[common.MetricMaxNodesChangeEnableEpoch+"_count"] diff --git a/statusHandler/statusMetricsProvider_test.go b/statusHandler/statusMetricsProvider_test.go index 02f33d62549..14b5b5225d3 100644 --- a/statusHandler/statusMetricsProvider_test.go +++ b/statusHandler/statusMetricsProvider_test.go @@ -401,6 +401,7 @@ func TestStatusMetrics_EnableEpochMetrics(t *testing.T) { sm.SetUInt64Value(common.MetricEGLDInMultiTransferEnableEpoch, uint64(4)) sm.SetUInt64Value(common.MetricCryptoOpcodesV2EnableEpoch, uint64(4)) sm.SetUInt64Value(common.MetricMultiESDTNFTTransferAndExecuteByUserEnableEpoch, uint64(4)) + sm.SetUInt64Value(common.MetricFixRelayedMoveBalanceToNonPayableSCEnableEpoch, uint64(4)) maxNodesChangeConfig := []map[string]uint64{ { @@ -531,6 +532,7 @@ func TestStatusMetrics_EnableEpochMetrics(t *testing.T) { common.MetricEGLDInMultiTransferEnableEpoch: uint64(4), common.MetricCryptoOpcodesV2EnableEpoch: uint64(4), common.MetricMultiESDTNFTTransferAndExecuteByUserEnableEpoch: uint64(4), + common.MetricFixRelayedMoveBalanceToNonPayableSCEnableEpoch: uint64(4), common.MetricMaxNodesChangeEnableEpoch: []map[string]interface{}{ { From f289f70a2703b3dffd0602efa2c6bfedec7eb14a Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 9 Aug 2024 11:33:27 +0300 Subject: [PATCH 481/503] updated core-go after merge --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 6001f2447b4..5a2ac5d99fd 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.1.0 - github.com/multiversx/mx-chain-core-go v1.2.21-0.20240726123734-d2e801ceb0bc + github.com/multiversx/mx-chain-core-go v1.2.22-0.20240726123734-d2e801ceb0bc github.com/multiversx/mx-chain-crypto-go v1.2.12 github.com/multiversx/mx-chain-es-indexer-go v1.7.4 github.com/multiversx/mx-chain-logger-go v1.0.15 diff --git a/go.sum b/go.sum index c22310babde..431460a09e2 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.1.0 h1:J7bX6HoN3HiHY7cUeEjG8AJWgQDDPcY+OPDOsSUOkRE= github.com/multiversx/mx-chain-communication-go v1.1.0/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240726123734-d2e801ceb0bc h1:COQlZ7wmOz15F40woVfRb6sl5CLQCKcRv13e9s/2PT0= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240726123734-d2e801ceb0bc/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.22-0.20240726123734-d2e801ceb0bc h1:EB25Psgi0GjWJfrNfgvGEMcuoqj63BnFrw0bqsl9Hdc= +github.com/multiversx/mx-chain-core-go v1.2.22-0.20240726123734-d2e801ceb0bc/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.4 h1:SjJk9G9SN8baz0sFIU2jymYCfx3XiikGEB2wW0jwvfw= From dab6bcd7a8a79930bd52a0e052f8572d9aeb350f Mon Sep 17 00:00:00 2001 From: python-qa Date: Fri, 9 Aug 2024 15:33:05 +0300 Subject: [PATCH 482/503] rename the action --- .../build_and_run_chain_simulator_and_execute_system_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml index 4ea0d71b04a..1d5502d56a3 100644 --- a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml +++ b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml @@ -1,4 +1,4 @@ -name: Build and Smoke Test +name: Chain Simulator Build and Integration Test on: pull_request: From ffa43f71ecb0c4297aed5010ad61c7a9563ef3f0 Mon Sep 17 00:00:00 2001 From: python-qa Date: Fri, 9 Aug 2024 15:38:15 +0300 Subject: [PATCH 483/503] fix CS script path --- .../build_and_run_chain_simulator_and_execute_system_test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml index 1d5502d56a3..2b36714fdeb 100644 --- a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml +++ b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml @@ -156,8 +156,8 @@ jobs: - name: Install Python Dependencies and Update go.mod run: | cd mx-chain-simulator-go - pip install -r scripts/update_go_mod/requirements.txt - python scripts/update_go_mod/update_go_mod.py $LATEST_COMMIT_HASH + pip install -r scripts/update-go-mod/requirements.txt + python scripts/update-go-mod/update-go-mod.py $LATEST_COMMIT_HASH - name: Run go mod tidy and go build From db3bb47eb50980c2c1d8efb7fba4727867ea87cb Mon Sep 17 00:00:00 2001 From: python-qa Date: Fri, 9 Aug 2024 16:35:07 +0300 Subject: [PATCH 484/503] rename step --- .../build_and_run_chain_simulator_and_execute_system_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml index 2b36714fdeb..0bb675230ae 100644 --- a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml +++ b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml @@ -160,7 +160,7 @@ jobs: python scripts/update-go-mod/update-go-mod.py $LATEST_COMMIT_HASH - - name: Run go mod tidy and go build + - name: Run go build run: | cd mx-chain-simulator-go/cmd/chainsimulator go build From 87cae3bd847ced041f61f0c8779609b4b923c655 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 9 Aug 2024 16:49:25 +0300 Subject: [PATCH 485/503] fixes after review --- common/enablers/enableEpochsHandler_test.go | 2 +- integrationTests/chainSimulator/relayedTx/relayedTx_test.go | 2 +- process/transaction/shardProcess.go | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/common/enablers/enableEpochsHandler_test.go b/common/enablers/enableEpochsHandler_test.go index 48497586187..83977fa51b9 100644 --- a/common/enablers/enableEpochsHandler_test.go +++ b/common/enablers/enableEpochsHandler_test.go @@ -122,7 +122,7 @@ func createEnableEpochsConfig() config.EnableEpochs { RelayedTransactionsV3EnableEpoch: 105, FixRelayedBaseCostEnableEpoch: 106, MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 107, - FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 107, + FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 108, } } diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index 6e71ae4bab9..8b5a5b9e525 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -267,7 +267,7 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorScCalls(t *t } } -func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorInvalidInnerMoveBalance(t *testing.T) { +func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorInnerMoveBalanceToNonPayableSC(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 168eb19c539..92aeaec8838 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -502,14 +502,14 @@ func (txProc *txProcessor) processMoveBalance( if err != nil { errRefund := txProc.removeConsumedValueFromSender(tx, acntSrc, isUserTxOfRelayed) if errRefund != nil { - log.Warn("failed to return funds to sender after check if receiver is payable", "error", errRefund) + log.Error("failed to return funds to sender after check if receiver is payable", "error", errRefund) } return err } if !isPayable { err = txProc.removeConsumedValueFromSender(tx, acntSrc, isUserTxOfRelayed) if err != nil { - log.Warn("failed to return funds to sender while transferring to non payable sc", "error", err) + log.Error("failed to return funds to sender while transferring to non payable sc", "error", err) } return process.ErrAccountNotPayable @@ -519,7 +519,7 @@ func (txProc *txProcessor) processMoveBalance( if err != nil { errLocal := txProc.removeConsumedValueFromSender(tx, acntSrc, isUserTxOfRelayed) if errLocal != nil { - log.Warn("failed to return funds to sender while sending invalid tx to metachain", "error", errLocal) + log.Error("failed to return funds to sender while sending invalid tx to metachain", "error", errLocal) } return err From 7d0ea8697d043ac4fbaf504a70d52dae0f89f1c6 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 9 Aug 2024 17:03:14 +0300 Subject: [PATCH 486/503] fixed test after fixes --- common/enablers/enableEpochsHandler_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/enablers/enableEpochsHandler_test.go b/common/enablers/enableEpochsHandler_test.go index 83977fa51b9..64e23a6e122 100644 --- a/common/enablers/enableEpochsHandler_test.go +++ b/common/enablers/enableEpochsHandler_test.go @@ -448,7 +448,7 @@ func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) { require.Equal(t, cfg.RelayedTransactionsV3EnableEpoch, handler.GetActivationEpoch(common.RelayedTransactionsV3Flag)) require.Equal(t, cfg.FixRelayedBaseCostEnableEpoch, handler.GetActivationEpoch(common.FixRelayedBaseCostFlag)) require.Equal(t, cfg.MultiESDTNFTTransferAndExecuteByUserEnableEpoch, handler.GetActivationEpoch(common.MultiESDTNFTTransferAndExecuteByUserFlag)) - require.Equal(t, cfg.MultiESDTNFTTransferAndExecuteByUserEnableEpoch, handler.GetActivationEpoch(common.FixRelayedMoveBalanceToNonPayableSCFlag)) + require.Equal(t, cfg.FixRelayedMoveBalanceToNonPayableSCEnableEpoch, handler.GetActivationEpoch(common.FixRelayedMoveBalanceToNonPayableSCFlag)) } func TestEnableEpochsHandler_IsInterfaceNil(t *testing.T) { From 760583c8229200683e3ca5957c07469cb6436960 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 9 Aug 2024 17:28:32 +0300 Subject: [PATCH 487/503] missing fix --- process/transaction/shardProcess.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 92aeaec8838..50fa0c94d21 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -500,14 +500,14 @@ func (txProc *txProcessor) processMoveBalance( isPayable, err := txProc.scProcessor.IsPayable(tx.SndAddr, tx.RcvAddr) if err != nil { - errRefund := txProc.removeConsumedValueFromSender(tx, acntSrc, isUserTxOfRelayed) + errRefund := txProc.revertConsumedValueFromSender(tx, acntSrc, isUserTxOfRelayed) if errRefund != nil { log.Error("failed to return funds to sender after check if receiver is payable", "error", errRefund) } return err } if !isPayable { - err = txProc.removeConsumedValueFromSender(tx, acntSrc, isUserTxOfRelayed) + err = txProc.revertConsumedValueFromSender(tx, acntSrc, isUserTxOfRelayed) if err != nil { log.Error("failed to return funds to sender while transferring to non payable sc", "error", err) } @@ -517,7 +517,7 @@ func (txProc *txProcessor) processMoveBalance( err = txProc.checkIfValidTxToMetaChain(tx, tx.RcvAddr) if err != nil { - errLocal := txProc.removeConsumedValueFromSender(tx, acntSrc, isUserTxOfRelayed) + errLocal := txProc.revertConsumedValueFromSender(tx, acntSrc, isUserTxOfRelayed) if errLocal != nil { log.Error("failed to return funds to sender while sending invalid tx to metachain", "error", errLocal) } @@ -557,7 +557,7 @@ func (txProc *txProcessor) processMoveBalance( return nil } -func (txProc *txProcessor) removeConsumedValueFromSender( +func (txProc *txProcessor) revertConsumedValueFromSender( tx *transaction.Transaction, acntSrc state.UserAccountHandler, isUserTxOfRelayed bool, From 970a776943e38cf64c17aa06ec9b69f49f2022d0 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 9 Aug 2024 17:40:26 +0300 Subject: [PATCH 488/503] fix fee field for other relayed cases --- factory/api/apiResolverFactory.go | 1 + .../relayedTx/relayedTx_test.go | 114 ++++++++++++++---- .../testProcessorNodeWithTestWebServer.go | 2 + .../transactionAPI/apiTransactionArgs.go | 1 + .../transactionAPI/apiTransactionProcessor.go | 9 +- .../apiTransactionProcessor_test.go | 14 +++ node/external/transactionAPI/check.go | 5 + .../transactionAPI/gasUsedAndFeeProcessor.go | 96 ++++++++++++++- .../gasUsedAndFeeProcessor_test.go | 48 +++++++- 9 files changed, 258 insertions(+), 32 deletions(-) diff --git a/factory/api/apiResolverFactory.go b/factory/api/apiResolverFactory.go index 67eb70aa4a9..621ff7a8d13 100644 --- a/factory/api/apiResolverFactory.go +++ b/factory/api/apiResolverFactory.go @@ -245,6 +245,7 @@ func CreateApiResolver(args *ApiResolverArgs) (facade.ApiResolver, error) { LogsFacade: logsFacade, DataFieldParser: dataFieldParser, GasScheduleNotifier: args.GasScheduleNotifier, + TxMarshaller: args.CoreComponents.TxMarshalizer(), } apiTransactionProcessor, err := transactionAPI.NewAPITransactionProcessor(argsAPITransactionProc) if err != nil { diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index 72bc9575763..f10f9a705a8 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -30,6 +30,7 @@ const ( minGasLimit = 50_000 guardAccountCost = 250_000 extraGasLimitForGuarded = minGasLimit + gasPerDataByte = 1_500 txVersion = 2 mockTxSignature = "sig" maxNumOfBlocksToGenerateWhenExecutingTx = 10 @@ -177,16 +178,7 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorScCalls(t *t require.Nil(t, err) ownerNonce := uint64(0) - scCode := wasm.GetSCCode("testData/adder.wasm") - params := []string{scCode, wasm.VMTypeHex, wasm.DummyCodeMetadataHex, "00"} - txDataDeploy := strings.Join(params, "@") - deployTx := generateTransaction(owner.Bytes, ownerNonce, make([]byte, 32), big.NewInt(0), txDataDeploy, 100000000) - - result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(deployTx, maxNumOfBlocksToGenerateWhenExecutingTx) - require.NoError(t, err) - - scAddress := result.Logs.Events[0].Address - scAddressBytes, _ := pkConv.Decode(scAddress) + scAddressBytes := deployAdder(t, cs, owner, ownerNonce) scShard := shardC.ComputeId(scAddressBytes) scShardNodeHandler := cs.GetNodeHandler(scShard) @@ -235,7 +227,7 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorScCalls(t *t relayedTx := generateTransaction(relayer.Bytes, 0, relayer.Bytes, big.NewInt(0), "", relayedTxGasLimit) relayedTx.InnerTransactions = innerTxs - result, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) + result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) require.NoError(t, err) checkSum(t, scShardNodeHandler, scAddressBytes, owner.Bytes, 4) @@ -295,8 +287,6 @@ func testFixRelayedMoveBalanceWithChainSimulatorScCall( cs := startChainSimulator(t, alterConfigsFunc) defer cs.Close() - pkConv := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter() - initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(10)) relayer, err := cs.GenerateAndMintWalletAddress(0, initialBalance) require.NoError(t, err) @@ -309,16 +299,8 @@ func testFixRelayedMoveBalanceWithChainSimulatorScCall( err = cs.GenerateBlocks(1) require.NoError(t, err) - scCode := wasm.GetSCCode("testData/adder.wasm") - params := []string{scCode, wasm.VMTypeHex, wasm.DummyCodeMetadataHex, "00"} - txDataDeploy := strings.Join(params, "@") - deployTx := generateTransaction(owner.Bytes, 0, make([]byte, 32), big.NewInt(0), txDataDeploy, 100000000) - - result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(deployTx, maxNumOfBlocksToGenerateWhenExecutingTx) - require.NoError(t, err) - - scAddress := result.Logs.Events[0].Address - scAddressBytes, _ := pkConv.Decode(scAddress) + ownerNonce := uint64(0) + scAddressBytes := deployAdder(t, cs, owner, ownerNonce) // fast-forward until epoch 4 err = cs.GenerateBlocksUntilEpochIsReached(int32(4)) @@ -581,6 +563,67 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorInnerNotExec checkBalance(t, cs, receiver, oneEGLD) } +func TestRelayedTransactionFeeField(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + cs := startChainSimulator(t, func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.RelayedTransactionsEnableEpoch = 1 + cfg.EpochConfig.EnableEpochs.RelayedTransactionsV2EnableEpoch = 1 + cfg.EpochConfig.EnableEpochs.RelayedTransactionsV3EnableEpoch = 1 + cfg.EpochConfig.EnableEpochs.FixRelayedBaseCostEnableEpoch = 1 + }) + defer cs.Close() + + initialBalance := big.NewInt(0).Mul(oneEGLD, big.NewInt(10)) + relayer, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + sender, err := cs.GenerateAndMintWalletAddress(0, initialBalance) + require.NoError(t, err) + + receiver, err := cs.GenerateAndMintWalletAddress(0, big.NewInt(0)) + require.NoError(t, err) + + err = cs.GenerateBlocks(1) + require.Nil(t, err) + + t.Run("relayed v1", func(t *testing.T) { + innerTx := generateTransaction(sender.Bytes, 0, receiver.Bytes, oneEGLD, "", minGasLimit) + buff, err := json.Marshal(innerTx) + require.NoError(t, err) + + txData := []byte("relayedTx@" + hex.EncodeToString(buff)) + gasLimit := minGasLimit + len(txData)*gasPerDataByte + int(innerTx.GasLimit) + relayedTx := generateTransaction(relayer.Bytes, 0, sender.Bytes, big.NewInt(0), string(txData), uint64(gasLimit)) + + result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + expectedFee := core.SafeMul(uint64(gasLimit), minGasPrice) + require.Equal(t, expectedFee.String(), result.Fee) + require.Equal(t, expectedFee.String(), result.InitiallyPaidFee) + require.Equal(t, uint64(gasLimit), result.GasUsed) + }) + t.Run("relayed v3", func(t *testing.T) { + innerTx := generateTransaction(sender.Bytes, 1, receiver.Bytes, oneEGLD, "", minGasLimit) + innerTx.RelayerAddr = relayer.Bytes + + gasLimit := minGasLimit + int(innerTx.GasLimit) + relayedTx := generateTransaction(relayer.Bytes, 1, relayer.Bytes, big.NewInt(0), "", uint64(gasLimit)) + relayedTx.InnerTransactions = []*transaction.Transaction{innerTx} + + result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(relayedTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + expectedFee := core.SafeMul(uint64(gasLimit), minGasPrice) + require.Equal(t, expectedFee.String(), result.Fee) + require.Equal(t, expectedFee.String(), result.InitiallyPaidFee) + require.Equal(t, uint64(gasLimit), result.GasUsed) + }) +} + func startChainSimulator( t *testing.T, alterConfigsFunction func(cfg *config.Configs), @@ -705,3 +748,28 @@ func checkBalance( balance := getBalance(t, cs, address) require.Equal(t, expectedBalance.String(), balance.String()) } + +func deployAdder( + t *testing.T, + cs testsChainSimulator.ChainSimulator, + owner dtos.WalletAddress, + ownerNonce uint64, +) []byte { + pkConv := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter() + + err := cs.GenerateBlocks(1) + require.Nil(t, err) + + scCode := wasm.GetSCCode("testData/adder.wasm") + params := []string{scCode, wasm.VMTypeHex, wasm.DummyCodeMetadataHex, "00"} + txDataDeploy := strings.Join(params, "@") + deployTx := generateTransaction(owner.Bytes, ownerNonce, make([]byte, 32), big.NewInt(0), txDataDeploy, 100000000) + + result, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(deployTx, maxNumOfBlocksToGenerateWhenExecutingTx) + require.NoError(t, err) + + scAddress := result.Logs.Events[0].Address + scAddressBytes, _ := pkConv.Decode(scAddress) + + return scAddressBytes +} diff --git a/integrationTests/testProcessorNodeWithTestWebServer.go b/integrationTests/testProcessorNodeWithTestWebServer.go index 02849a7803a..c194695fb73 100644 --- a/integrationTests/testProcessorNodeWithTestWebServer.go +++ b/integrationTests/testProcessorNodeWithTestWebServer.go @@ -24,6 +24,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/genesisMocks" + "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" "github.com/multiversx/mx-chain-go/testscommon/state" "github.com/multiversx/mx-chain-go/vm/systemSmartContracts/defaults" "github.com/multiversx/mx-chain-vm-common-go/parsers" @@ -237,6 +238,7 @@ func createFacadeComponents(tpn *TestProcessorNode) nodeFacade.ApiResolver { LogsFacade: logsFacade, DataFieldParser: dataFieldParser, GasScheduleNotifier: gasScheduleNotifier, + TxMarshaller: &marshallerMock.MarshalizerMock{}, } apiTransactionHandler, err := transactionAPI.NewAPITransactionProcessor(argsApiTransactionProc) log.LogIfError(err) diff --git a/node/external/transactionAPI/apiTransactionArgs.go b/node/external/transactionAPI/apiTransactionArgs.go index a4ad9421a31..1c9a79b874d 100644 --- a/node/external/transactionAPI/apiTransactionArgs.go +++ b/node/external/transactionAPI/apiTransactionArgs.go @@ -28,4 +28,5 @@ type ArgAPITransactionProcessor struct { LogsFacade LogsFacade DataFieldParser DataFieldParser GasScheduleNotifier core.GasScheduleNotifier + TxMarshaller marshal.Marshalizer } diff --git a/node/external/transactionAPI/apiTransactionProcessor.go b/node/external/transactionAPI/apiTransactionProcessor.go index 6528d195026..7702d4ad053 100644 --- a/node/external/transactionAPI/apiTransactionProcessor.go +++ b/node/external/transactionAPI/apiTransactionProcessor.go @@ -19,6 +19,7 @@ import ( "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/dblookupext" "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/process/smartContract" "github.com/multiversx/mx-chain-go/process/txstatus" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/storage/txcache" @@ -65,7 +66,13 @@ func NewAPITransactionProcessor(args *ArgAPITransactionProcessor) (*apiTransacti ) refundDetectorInstance := NewRefundDetector() - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(args.FeeComputer, args.GasScheduleNotifier, args.AddressPubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor( + args.FeeComputer, + args.GasScheduleNotifier, + args.AddressPubKeyConverter, + smartContract.NewArgumentParser(), + args.TxMarshaller, + ) return &apiTransactionProcessor{ roundDuration: args.RoundDuration, diff --git a/node/external/transactionAPI/apiTransactionProcessor_test.go b/node/external/transactionAPI/apiTransactionProcessor_test.go index fa13f040037..4609d0bdfb6 100644 --- a/node/external/transactionAPI/apiTransactionProcessor_test.go +++ b/node/external/transactionAPI/apiTransactionProcessor_test.go @@ -33,6 +33,7 @@ import ( dataRetrieverMock "github.com/multiversx/mx-chain-go/testscommon/dataRetriever" dblookupextMock "github.com/multiversx/mx-chain-go/testscommon/dblookupext" "github.com/multiversx/mx-chain-go/testscommon/genericMocks" + "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" "github.com/multiversx/mx-chain-go/testscommon/txcachemocks" datafield "github.com/multiversx/mx-chain-vm-common-go/parsers/dataField" @@ -60,6 +61,7 @@ func createMockArgAPITransactionProcessor() *ArgAPITransactionProcessor { }, }, GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, + TxMarshaller: &marshallerMock.MarshalizerMock{}, } } @@ -182,6 +184,16 @@ func TestNewAPITransactionProcessor(t *testing.T) { _, err := NewAPITransactionProcessor(arguments) require.Equal(t, ErrNilDataFieldParser, err) }) + + t.Run("NilTxMarshaller", func(t *testing.T) { + t.Parallel() + + arguments := createMockArgAPITransactionProcessor() + arguments.TxMarshaller = nil + + _, err := NewAPITransactionProcessor(arguments) + require.True(t, strings.Contains(err.Error(), process.ErrNilMarshalizer.Error())) + }) } func TestNode_GetTransactionInvalidHashShouldErr(t *testing.T) { @@ -461,6 +473,7 @@ func TestNode_GetTransactionWithResultsFromStorage(t *testing.T) { }, }, GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, + TxMarshaller: &marshallerMock.MarshalizerMock{}, } apiTransactionProc, _ := NewAPITransactionProcessor(args) @@ -1030,6 +1043,7 @@ func createAPITransactionProc(t *testing.T, epoch uint32, withDbLookupExt bool) LogsFacade: &testscommon.LogsFacadeStub{}, DataFieldParser: dataFieldParser, GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, + TxMarshaller: &marshallerMock.MarshalizerMock{}, } apiTransactionProc, err := NewAPITransactionProcessor(args) require.Nil(t, err) diff --git a/node/external/transactionAPI/check.go b/node/external/transactionAPI/check.go index bbb3e2ab9df..729391d4914 100644 --- a/node/external/transactionAPI/check.go +++ b/node/external/transactionAPI/check.go @@ -1,6 +1,8 @@ package transactionAPI import ( + "fmt" + "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-go/process" ) @@ -45,6 +47,9 @@ func checkNilArgs(arg *ArgAPITransactionProcessor) error { if check.IfNilReflect(arg.GasScheduleNotifier) { return process.ErrNilGasSchedule } + if check.IfNilReflect(arg.TxMarshaller) { + return fmt.Errorf("%w for tx marshaller", process.ErrNilMarshalizer) + } return nil } diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index 6e6f48ebccb..3916c28f798 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -5,7 +5,9 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-core-go/marshal" "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/process" datafield "github.com/multiversx/mx-chain-vm-common-go/parsers/dataField" ) @@ -13,13 +15,23 @@ type gasUsedAndFeeProcessor struct { feeComputer feeComputer gasScheduleNotifier core.GasScheduleNotifier pubKeyConverter core.PubkeyConverter + argsParser process.ArgumentsParser + marshaller marshal.Marshalizer } -func newGasUsedAndFeeProcessor(txFeeCalculator feeComputer, gasScheduleNotifier core.GasScheduleNotifier, pubKeyConverter core.PubkeyConverter) *gasUsedAndFeeProcessor { +func newGasUsedAndFeeProcessor( + txFeeCalculator feeComputer, + gasScheduleNotifier core.GasScheduleNotifier, + pubKeyConverter core.PubkeyConverter, + argsParser process.ArgumentsParser, + marshaller marshal.Marshalizer, +) *gasUsedAndFeeProcessor { return &gasUsedAndFeeProcessor{ feeComputer: txFeeCalculator, gasScheduleNotifier: gasScheduleNotifier, pubKeyConverter: pubKeyConverter, + argsParser: argsParser, + marshaller: marshaller, } } @@ -30,7 +42,7 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction tx.GasUsed = gasUsed tx.Fee = fee.String() - if tx.IsRelayed || gfp.isESDTOperationWithSCCall(tx) { + if gfp.isESDTOperationWithSCCall(tx) { tx.GasUsed = tx.GasLimit tx.Fee = tx.InitiallyPaidFee } @@ -50,6 +62,15 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction return } + if tx.IsRelayed { + totalFee, isRelayed := gfp.getFeeOfRelayed(tx) + if isRelayed { + tx.Fee = totalFee.String() + tx.InitiallyPaidFee = totalFee.String() + tx.GasUsed = big.NewInt(0).Div(totalFee, big.NewInt(0).SetUint64(tx.GasPrice)).Uint64() + } + } + hasRefundForSender := false for _, scr := range tx.SmartContractResults { if !scr.IsRefund || scr.RcvAddr != tx.Sender { @@ -67,6 +88,77 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction gfp.prepareTxWithResultsBasedOnLogs(tx, hasRefundForSender) } +func (gfp *gasUsedAndFeeProcessor) getFeeOfRelayed(tx *transaction.ApiTransactionResult) (*big.Int, bool) { + if !tx.IsRelayed { + return nil, false + } + + if len(tx.InnerTransactions) > 0 { + return gfp.feeComputer.ComputeTransactionFee(tx), true + } + + if len(tx.Data) == 0 { + return nil, false + } + + funcName, args, err := gfp.argsParser.ParseCallData(string(tx.Data)) + if err != nil { + return nil, false + } + + if funcName == core.RelayedTransaction { + return gfp.handleRelayedV1(args, tx) + } + + if funcName == core.RelayedTransactionV2 { + return gfp.handleRelayedV2(args, tx) + } + + return nil, false +} + +func (gfp *gasUsedAndFeeProcessor) handleRelayedV1(args [][]byte, tx *transaction.ApiTransactionResult) (*big.Int, bool) { + if len(args) != 1 { + return nil, false + } + + innerTx := &transaction.Transaction{} + err := gfp.marshaller.Unmarshal(innerTx, args[0]) + if err != nil { + return nil, false + } + + gasUsed := gfp.feeComputer.ComputeGasLimit(tx) + fee := gfp.feeComputer.ComputeTxFeeBasedOnGasUsed(tx, gasUsed) + + innerFee := gfp.feeComputer.ComputeTransactionFee(&transaction.ApiTransactionResult{ + Tx: innerTx, + }) + + return big.NewInt(0).Add(fee, innerFee), true +} + +func (gfp *gasUsedAndFeeProcessor) handleRelayedV2(args [][]byte, tx *transaction.ApiTransactionResult) (*big.Int, bool) { + innerTx := &transaction.Transaction{} + innerTx.RcvAddr = args[0] + innerTx.Nonce = big.NewInt(0).SetBytes(args[1]).Uint64() + innerTx.Data = args[2] + innerTx.Signature = args[3] + innerTx.Value = big.NewInt(0) + innerTx.GasPrice = tx.GasPrice + innerTx.GasLimit = tx.GasLimit - gfp.feeComputer.ComputeGasLimit(tx) + innerTx.SndAddr = tx.Tx.GetRcvAddr() + + gasUsed := gfp.feeComputer.ComputeGasLimit(tx) + fee := gfp.feeComputer.ComputeTxFeeBasedOnGasUsed(tx, gasUsed) + + innerFee := gfp.feeComputer.ComputeTransactionFee(&transaction.ApiTransactionResult{ + Tx: innerTx, + }) + + return big.NewInt(0).Add(fee, innerFee), true +} + func (gfp *gasUsedAndFeeProcessor) getGuardianOperationCost(tx *transaction.ApiTransactionResult) uint64 { gasSchedule, err := gfp.gasScheduleNotifier.GasScheduleForEpoch(tx.Epoch) if err != nil { diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go index 9a35be6efa9..1a9c7f922f4 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go @@ -38,7 +38,13 @@ func TestComputeTransactionGasUsedAndFeeMoveBalance(t *testing.T) { feeComp, _ := fee.NewFeeComputer(createEconomicsData(&enableEpochsHandlerMock.EnableEpochsHandlerStub{})) computer := fee.NewTestFeeComputer(feeComp) - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, &testscommon.GasScheduleNotifierMock{}, pubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor( + computer, + &testscommon.GasScheduleNotifierMock{}, + pubKeyConverter, + &testscommon.ArgumentParserMock{}, + &testscommon.MarshallerStub{}, + ) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" receiver := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -68,7 +74,13 @@ func TestComputeTransactionGasUsedAndFeeLogWithError(t *testing.T) { })) computer := fee.NewTestFeeComputer(feeComp) - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, &testscommon.GasScheduleNotifierMock{}, pubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor( + computer, + &testscommon.GasScheduleNotifierMock{}, + pubKeyConverter, + &testscommon.ArgumentParserMock{}, + &testscommon.MarshallerStub{}, + ) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" receiver := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -111,7 +123,13 @@ func TestComputeTransactionGasUsedAndFeeRelayedTxWithWriteLog(t *testing.T) { })) computer := fee.NewTestFeeComputer(feeComp) - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, &testscommon.GasScheduleNotifierMock{}, pubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor( + computer, + &testscommon.GasScheduleNotifierMock{}, + pubKeyConverter, + &testscommon.ArgumentParserMock{}, + &testscommon.MarshallerStub{}, + ) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" receiver := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -149,7 +167,13 @@ func TestComputeTransactionGasUsedAndFeeTransactionWithScrWithRefund(t *testing. })) computer := fee.NewTestFeeComputer(feeComp) - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, &testscommon.GasScheduleNotifierMock{}, pubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor( + computer, + &testscommon.GasScheduleNotifierMock{}, + pubKeyConverter, + &testscommon.ArgumentParserMock{}, + &testscommon.MarshallerStub{}, + ) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" receiver := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -197,7 +221,13 @@ func TestNFTTransferWithScCall(t *testing.T) { computer := fee.NewTestFeeComputer(feeComp) req.Nil(err) - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, &testscommon.GasScheduleNotifierMock{}, pubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor( + computer, + &testscommon.GasScheduleNotifierMock{}, + pubKeyConverter, + &testscommon.ArgumentParserMock{}, + &testscommon.MarshallerStub{}, + ) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" receiver := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -241,7 +271,13 @@ func TestComputeAndAttachGasUsedAndFeeSetGuardian(t *testing.T) { }, } - gasUsedAndFeeProc := newGasUsedAndFeeProcessor(computer, gasSch, pubKeyConverter) + gasUsedAndFeeProc := newGasUsedAndFeeProcessor( + computer, + gasSch, + pubKeyConverter, + &testscommon.ArgumentParserMock{}, + &testscommon.MarshallerStub{}, + ) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" From 8fd9fe80b8e7b374d9bc02c148e7034f1dc4b34d Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Fri, 9 Aug 2024 19:29:27 +0300 Subject: [PATCH 489/503] fix some tests and add more checks --- factory/processing/blockProcessorCreator.go | 5 ++++ go.mod | 2 +- go.sum | 4 +-- .../vm/esdtImprovements_test.go | 29 ++++++++++++++++++- integrationTests/vm/testInitializer.go | 1 + .../vm/txsFee/esdtMetaDataRecreate_test.go | 3 ++ .../vm/txsFee/esdtMetaDataUpdate_test.go | 3 ++ .../vm/txsFee/esdtModifyCreator_test.go | 3 ++ .../vm/txsFee/esdtModifyRoyalties_test.go | 3 ++ .../vm/txsFee/esdtSetNewURIs_test.go | 3 ++ 10 files changed, 52 insertions(+), 4 deletions(-) diff --git a/factory/processing/blockProcessorCreator.go b/factory/processing/blockProcessorCreator.go index 93f3e1e95a3..c48a777f01c 100644 --- a/factory/processing/blockProcessorCreator.go +++ b/factory/processing/blockProcessorCreator.go @@ -178,6 +178,11 @@ func (pcf *processComponentsFactory) newShardBlockProcessor( return nil, err } + err = builtInFuncFactory.SetBlockchainHook(vmFactory.BlockChainHookImpl()) + if err != nil { + return nil, err + } + argsFactory := shard.ArgsNewIntermediateProcessorsContainerFactory{ ShardCoordinator: pcf.bootstrapComponents.ShardCoordinator(), Marshalizer: pcf.coreData.InternalMarshalizer(), diff --git a/go.mod b/go.mod index af2b74d188e..ab249b49c76 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/multiversx/mx-chain-logger-go v1.0.15 github.com/multiversx/mx-chain-scenario-go v1.4.4 github.com/multiversx/mx-chain-storage-go v1.0.16 - github.com/multiversx/mx-chain-vm-common-go v1.5.13 + github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240809150339-0b582caa0adc github.com/multiversx/mx-chain-vm-go v1.5.31 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 diff --git a/go.sum b/go.sum index 1dd242a3f9c..0c44a62b0f9 100644 --- a/go.sum +++ b/go.sum @@ -399,8 +399,8 @@ github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFz 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.13 h1:ymnIHJW4Z4mFa0hZzla4fozkF30vjH5O1q+Y7Ftc+pQ= -github.com/multiversx/mx-chain-vm-common-go v1.5.13/go.mod h1:OSvFbzdWThfRbLZbUsEr7bikBSaLrPJQ2iUm9jw9nXQ= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240809150339-0b582caa0adc h1:OBzqgjM7tPB6qM1wp9WKmg2gtgmuTkIhkuMKoC9ooQg= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240809150339-0b582caa0adc/go.mod h1:OSvFbzdWThfRbLZbUsEr7bikBSaLrPJQ2iUm9jw9nXQ= github.com/multiversx/mx-chain-vm-go v1.5.31 h1:ywyqbVE94bhbO3LvcP/28pWoSR0NfEXLJNe+q1cgQ78= github.com/multiversx/mx-chain-vm-go v1.5.31/go.mod h1:iq6sCPweoHC9Fx56uf8buPrqlGVGJKUMRFxTunzjvys= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index d8e5c065a45..22f4e8d0ba0 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -2321,6 +2321,9 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) + err = cs.GenerateBlocks(10) + require.Nil(t, err) + log.Info("Send to separate shards") tx = esdtNFTTransferTx(nonce, addrs[1].Bytes, addrs[2].Bytes, tokenID) @@ -2399,8 +2402,32 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { log.Info("Step 2. check that the newest metadata is saved") shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - checkMetaData(t, cs, core.SystemAccountAddress, tokenID, shardID, sftMetaData2) + + shard2ID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[2].Bytes) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, shard2ID, metaData) + + log.Info("Step 3. create new wallet is shard 2") + + mintValue := big.NewInt(10) + mintValue = mintValue.Mul(oneEGLD, mintValue) + newShard2Addr, err := cs.GenerateAndMintWalletAddress(2, mintValue) + require.Nil(t, err) + err = cs.GenerateBlocks(1) + require.Nil(t, err) + + log.Info("Step 4. send updated token to shard 2 ") + + tx = esdtNFTTransferTx(1, addrs[0].Bytes, newShard2Addr.Bytes, tokenID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + err = cs.GenerateBlocks(5) + + log.Info("Step 5. check meta data in shard 2 is updated to latest version ") + + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, shard2ID, sftMetaData2) } func TestChainSimulator_NFT_RegisterDynamic(t *testing.T) { diff --git a/integrationTests/vm/testInitializer.go b/integrationTests/vm/testInitializer.go index fc129e36d90..c701007ca00 100644 --- a/integrationTests/vm/testInitializer.go +++ b/integrationTests/vm/testInitializer.go @@ -629,6 +629,7 @@ func CreateVMAndBlockchainHookAndDataPool( blockChainHook, _ := vmFactory.BlockChainHookImpl().(*hooks.BlockChainHookImpl) _ = builtInFuncFactory.SetPayableHandler(blockChainHook) + _ = builtInFuncFactory.SetBlockchainHook(blockChainHook) return vmContainer, blockChainHook, datapool } diff --git a/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go b/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go index 8e46c5d613b..d5778000cbe 100644 --- a/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go +++ b/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go @@ -7,10 +7,12 @@ import ( "testing" "github.com/multiversx/mx-chain-core-go/core" + dataBlock "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/vm" "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" + "github.com/multiversx/mx-chain-go/process" vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/stretchr/testify/require" ) @@ -35,6 +37,7 @@ func runEsdtMetaDataRecreateTest(t *testing.T, tokenType string) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() + testContext.BlockchainHook.(process.BlockChainHookHandler).SetCurrentHeader(&dataBlock.Header{Round: 7}) createAccWithBalance(t, testContext.Accounts, sndAddr, big.NewInt(100000000)) createAccWithBalance(t, testContext.Accounts, core.ESDTSCAddress, big.NewInt(100000000)) diff --git a/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go b/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go index 53174e22a35..4eba58ca178 100644 --- a/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go +++ b/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go @@ -7,10 +7,12 @@ import ( "testing" "github.com/multiversx/mx-chain-core-go/core" + dataBlock "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/vm" "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" + "github.com/multiversx/mx-chain-go/process" vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/stretchr/testify/require" ) @@ -35,6 +37,7 @@ func runEsdtMetaDataUpdateTest(t *testing.T, tokenType string) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() + testContext.BlockchainHook.(process.BlockChainHookHandler).SetCurrentHeader(&dataBlock.Header{Round: 7}) createAccWithBalance(t, testContext.Accounts, sndAddr, big.NewInt(100000000)) createAccWithBalance(t, testContext.Accounts, core.ESDTSCAddress, big.NewInt(100000000)) diff --git a/integrationTests/vm/txsFee/esdtModifyCreator_test.go b/integrationTests/vm/txsFee/esdtModifyCreator_test.go index ead51c5d61d..109e6e937e3 100644 --- a/integrationTests/vm/txsFee/esdtModifyCreator_test.go +++ b/integrationTests/vm/txsFee/esdtModifyCreator_test.go @@ -7,10 +7,12 @@ import ( "testing" "github.com/multiversx/mx-chain-core-go/core" + dataBlock "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/vm" "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" + "github.com/multiversx/mx-chain-go/process" vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/stretchr/testify/require" ) @@ -39,6 +41,7 @@ func runEsdtModifyCreatorTest(t *testing.T, tokenType string) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() + testContext.BlockchainHook.(process.BlockChainHookHandler).SetCurrentHeader(&dataBlock.Header{Round: 7}) createAccWithBalance(t, testContext.Accounts, newCreator, big.NewInt(100000000)) createAccWithBalance(t, testContext.Accounts, creatorAddr, big.NewInt(100000000)) diff --git a/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go b/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go index f4ef7dc9f49..9d6def6a297 100644 --- a/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go +++ b/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go @@ -7,10 +7,12 @@ import ( "testing" "github.com/multiversx/mx-chain-core-go/core" + dataBlock "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/vm" "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" + "github.com/multiversx/mx-chain-go/process" vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/stretchr/testify/require" ) @@ -34,6 +36,7 @@ func runEsdtModifyRoyaltiesTest(t *testing.T, tokenType string) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() + testContext.BlockchainHook.(process.BlockChainHookHandler).SetCurrentHeader(&dataBlock.Header{Round: 7}) createAccWithBalance(t, testContext.Accounts, creatorAddr, big.NewInt(100000000)) createAccWithBalance(t, testContext.Accounts, core.ESDTSCAddress, big.NewInt(100000000)) diff --git a/integrationTests/vm/txsFee/esdtSetNewURIs_test.go b/integrationTests/vm/txsFee/esdtSetNewURIs_test.go index 66ec209c3ef..f97e9e0e651 100644 --- a/integrationTests/vm/txsFee/esdtSetNewURIs_test.go +++ b/integrationTests/vm/txsFee/esdtSetNewURIs_test.go @@ -7,10 +7,12 @@ import ( "testing" "github.com/multiversx/mx-chain-core-go/core" + dataBlock "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/vm" "github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils" + "github.com/multiversx/mx-chain-go/process" vmcommon "github.com/multiversx/mx-chain-vm-common-go" "github.com/stretchr/testify/require" ) @@ -35,6 +37,7 @@ func runEsdtSetNewURIsTest(t *testing.T, tokenType string) { testContext, err := vm.CreatePreparedTxProcessorWithVMs(config.EnableEpochs{}, 1) require.Nil(t, err) defer testContext.Close() + testContext.BlockchainHook.(process.BlockChainHookHandler).SetCurrentHeader(&dataBlock.Header{Round: 7}) createAccWithBalance(t, testContext.Accounts, sndAddr, big.NewInt(100000000)) createAccWithBalance(t, testContext.Accounts, core.ESDTSCAddress, big.NewInt(100000000)) From 3a16b1b9ba491cef29ecf54935c631292f2c762a Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Mon, 12 Aug 2024 09:33:37 +0300 Subject: [PATCH 490/503] update go mo --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 4667bd06e7e..843dda8b18c 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( github.com/multiversx/mx-chain-logger-go v1.0.15 github.com/multiversx/mx-chain-scenario-go v1.4.4 github.com/multiversx/mx-chain-storage-go v1.0.16 - github.com/multiversx/mx-chain-vm-common-go v1.5.13 + github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240809150339-0b582caa0adc github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240808073353-f1fbbf147537 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 diff --git a/go.sum b/go.sum index 11a9bc62556..17ed08cd677 100644 --- a/go.sum +++ b/go.sum @@ -399,8 +399,8 @@ github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFz 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.13 h1:ymnIHJW4Z4mFa0hZzla4fozkF30vjH5O1q+Y7Ftc+pQ= -github.com/multiversx/mx-chain-vm-common-go v1.5.13/go.mod h1:OSvFbzdWThfRbLZbUsEr7bikBSaLrPJQ2iUm9jw9nXQ= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240809150339-0b582caa0adc h1:OBzqgjM7tPB6qM1wp9WKmg2gtgmuTkIhkuMKoC9ooQg= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240809150339-0b582caa0adc/go.mod h1:OSvFbzdWThfRbLZbUsEr7bikBSaLrPJQ2iUm9jw9nXQ= github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240808073353-f1fbbf147537 h1:x1Fn0tlkicBNsRB/co/c9TTjyvCrzmE/rVXA8uUWhII= github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240808073353-f1fbbf147537/go.mod h1:iq6sCPweoHC9Fx56uf8buPrqlGVGJKUMRFxTunzjvys= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= From 1494445465c7f130bb916515d86056729e4290d4 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Mon, 12 Aug 2024 09:48:08 +0300 Subject: [PATCH 491/503] linter fixes --- integrationTests/chainSimulator/vm/esdtImprovements_test.go | 1 + testscommon/esdtStorageHandlerStub.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 22f4e8d0ba0..eee8f50e204 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -2424,6 +2424,7 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) err = cs.GenerateBlocks(5) + require.Nil(t, err) log.Info("Step 5. check meta data in shard 2 is updated to latest version ") diff --git a/testscommon/esdtStorageHandlerStub.go b/testscommon/esdtStorageHandlerStub.go index 47825717409..b6ff81f2b00 100644 --- a/testscommon/esdtStorageHandlerStub.go +++ b/testscommon/esdtStorageHandlerStub.go @@ -18,7 +18,7 @@ type EsdtStorageHandlerStub struct { SaveNFTMetaDataCalled func(tx data.TransactionHandler) error AddToLiquiditySystemAccCalled func(esdtTokenKey []byte, tokenType uint32, nonce uint64, transferValue *big.Int, keepMetadataOnZeroLiquidity bool) error SaveMetaDataToSystemAccountCalled func(tokenKey []byte, nonce uint64, esdtData *esdt.ESDigitalToken) error - GetMetaDataFromSystemAccountCalled func(bytes []byte, u uint64) (*esdt.MetaData, error) + GetMetaDataFromSystemAccountCalled func(bytes []byte, u uint64) (*esdt.ESDigitalToken, error) } // SaveMetaDataToSystemAccount - @@ -31,7 +31,7 @@ func (e *EsdtStorageHandlerStub) SaveMetaDataToSystemAccount(tokenKey []byte, no } // GetMetaDataFromSystemAccount - -func (e *EsdtStorageHandlerStub) GetMetaDataFromSystemAccount(bytes []byte, u uint64) (*esdt.MetaData, error) { +func (e *EsdtStorageHandlerStub) GetMetaDataFromSystemAccount(bytes []byte, u uint64) (*esdt.ESDigitalToken, error) { if e.GetMetaDataFromSystemAccountCalled != nil { return e.GetMetaDataFromSystemAccountCalled(bytes, u) } From a9e2b8f75992026f47fe8b87da51c33d411531fe Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Mon, 12 Aug 2024 11:44:04 +0300 Subject: [PATCH 492/503] update go mod --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 843dda8b18c..c6b99bc0214 100644 --- a/go.mod +++ b/go.mod @@ -21,8 +21,8 @@ require ( github.com/multiversx/mx-chain-logger-go v1.0.15 github.com/multiversx/mx-chain-scenario-go v1.4.4 github.com/multiversx/mx-chain-storage-go v1.0.16 - github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240809150339-0b582caa0adc - github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240808073353-f1fbbf147537 + github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240812082318-afa839968da3 + github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240812082514-1f3c25b3171e github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 diff --git a/go.sum b/go.sum index 17ed08cd677..d8ed7091831 100644 --- a/go.sum +++ b/go.sum @@ -399,10 +399,10 @@ github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFz 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.14-0.20240809150339-0b582caa0adc h1:OBzqgjM7tPB6qM1wp9WKmg2gtgmuTkIhkuMKoC9ooQg= -github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240809150339-0b582caa0adc/go.mod h1:OSvFbzdWThfRbLZbUsEr7bikBSaLrPJQ2iUm9jw9nXQ= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240808073353-f1fbbf147537 h1:x1Fn0tlkicBNsRB/co/c9TTjyvCrzmE/rVXA8uUWhII= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240808073353-f1fbbf147537/go.mod h1:iq6sCPweoHC9Fx56uf8buPrqlGVGJKUMRFxTunzjvys= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240812082318-afa839968da3 h1:RlHKl5enbGrleB0Aea9TinZLLymS4WvG0/xAt/iRb6E= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240812082318-afa839968da3/go.mod h1:OSvFbzdWThfRbLZbUsEr7bikBSaLrPJQ2iUm9jw9nXQ= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240812082514-1f3c25b3171e h1:BkZtPUAQ9JlATkENydCLxPZ819hjop6laZtmC7Wzqec= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240812082514-1f3c25b3171e/go.mod h1:j9FBeftA/BKfn0BbndKV7bNFJAzwCnYZuebsM/sufK0= 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= From 42bf1a3142d5f8d9174b7c78a6023077366ada57 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 12 Aug 2024 15:11:18 +0300 Subject: [PATCH 493/503] fixes after review --- factory/processing/blockProcessorCreator.go | 1 + node/external/timemachine/fee/feeComputer.go | 1 - .../transactionAPI/gasUsedAndFeeProcessor.go | 2 + outport/process/factory/check_test.go | 1 + .../factory/outportDataProviderFactory.go | 14 +- outport/process/interface.go | 2 +- outport/process/outportDataProvider.go | 2 +- outport/process/outportDataProvider_test.go | 10 +- .../transactionsFeeProcessor.go | 164 ++++++++++++++++-- .../transactionsFeeProcessor_test.go | 47 +++-- 10 files changed, 196 insertions(+), 48 deletions(-) diff --git a/factory/processing/blockProcessorCreator.go b/factory/processing/blockProcessorCreator.go index 93f3e1e95a3..f4ee93124a2 100644 --- a/factory/processing/blockProcessorCreator.go +++ b/factory/processing/blockProcessorCreator.go @@ -1052,6 +1052,7 @@ func (pcf *processComponentsFactory) createOutportDataProvider( MbsStorer: mbsStorer, EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), ExecutionOrderGetter: pcf.txExecutionOrderHandler, + GasScheduleNotifier: pcf.gasSchedule, }) } diff --git a/node/external/timemachine/fee/feeComputer.go b/node/external/timemachine/fee/feeComputer.go index ee4d67910db..9ad90d2b221 100644 --- a/node/external/timemachine/fee/feeComputer.go +++ b/node/external/timemachine/fee/feeComputer.go @@ -42,7 +42,6 @@ func (computer *feeComputer) ComputeTxFeeBasedOnGasUsed(tx *transaction.ApiTrans // ComputeGasLimit computes a transaction gas limit, at a given epoch func (computer *feeComputer) ComputeGasLimit(tx *transaction.ApiTransactionResult) uint64 { - computer.economicsInstance.MaxGasPriceSetGuardian() return computer.economicsInstance.ComputeGasLimitInEpoch(tx.Tx, tx.Epoch) } diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index 3916c28f798..30ac5cbc910 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -47,6 +47,8 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction tx.Fee = tx.InitiallyPaidFee } + // if there is a guardian operation, SetGuardian/GuardAccount/UnGuardAccount + // the pre-configured cost of the operation must be added separately if gfp.isGuardianOperation(tx) { gasUsed = gfp.feeComputer.ComputeGasLimit(tx) guardianOperationCost := gfp.getGuardianOperationCost(tx) diff --git a/outport/process/factory/check_test.go b/outport/process/factory/check_test.go index 513a3c7305b..67b9a91b7dc 100644 --- a/outport/process/factory/check_test.go +++ b/outport/process/factory/check_test.go @@ -34,6 +34,7 @@ func createArgOutportDataProviderFactory() ArgOutportDataProviderFactory { MbsStorer: &genericMocks.StorerMock{}, EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ExecutionOrderGetter: &commonMocks.TxExecutionOrderHandlerStub{}, + GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, } } diff --git a/outport/process/factory/outportDataProviderFactory.go b/outport/process/factory/outportDataProviderFactory.go index 68546df1c50..4350605b000 100644 --- a/outport/process/factory/outportDataProviderFactory.go +++ b/outport/process/factory/outportDataProviderFactory.go @@ -11,6 +11,7 @@ import ( "github.com/multiversx/mx-chain-go/outport/process/disabled" "github.com/multiversx/mx-chain-go/outport/process/transactionsfee" processTxs "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/process/smartContract" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "github.com/multiversx/mx-chain-go/state" @@ -36,6 +37,7 @@ type ArgOutportDataProviderFactory struct { MbsStorer storage.Storer EnableEpochsHandler common.EnableEpochsHandler ExecutionOrderGetter common.ExecutionOrderGetter + GasScheduleNotifier core.GasScheduleNotifier } // CreateOutportDataProvider will create a new instance of outport.DataProviderOutport @@ -60,11 +62,13 @@ func CreateOutportDataProvider(arg ArgOutportDataProviderFactory) (outport.DataP } transactionsFeeProc, err := transactionsfee.NewTransactionsFeeProcessor(transactionsfee.ArgTransactionsFeeProcessor{ - Marshaller: arg.Marshaller, - TransactionsStorer: arg.TransactionsStorer, - ShardCoordinator: arg.ShardCoordinator, - TxFeeCalculator: arg.EconomicsData, - PubKeyConverter: arg.AddressConverter, + Marshaller: arg.Marshaller, + TransactionsStorer: arg.TransactionsStorer, + ShardCoordinator: arg.ShardCoordinator, + TxFeeCalculator: arg.EconomicsData, + PubKeyConverter: arg.AddressConverter, + ArgsParser: smartContract.NewArgumentParser(), + GasScheduleNotifier: arg.GasScheduleNotifier, }) if err != nil { return nil, err diff --git a/outport/process/interface.go b/outport/process/interface.go index 5fcb19020f3..bec97f362b3 100644 --- a/outport/process/interface.go +++ b/outport/process/interface.go @@ -17,7 +17,7 @@ type AlteredAccountsProviderHandler interface { // TransactionsFeeHandler defines the functionality needed for computation of the transaction fee and gas used type TransactionsFeeHandler interface { - PutFeeAndGasUsed(pool *outport.TransactionPool) error + PutFeeAndGasUsed(pool *outport.TransactionPool, epoch uint32) error IsInterfaceNil() bool } diff --git a/outport/process/outportDataProvider.go b/outport/process/outportDataProvider.go index a99e0bc4827..aec1f15df8b 100644 --- a/outport/process/outportDataProvider.go +++ b/outport/process/outportDataProvider.go @@ -100,7 +100,7 @@ func (odp *outportDataProvider) PrepareOutportSaveBlockData(arg ArgPrepareOutpor return nil, err } - err = odp.transactionsFeeProcessor.PutFeeAndGasUsed(pool) + err = odp.transactionsFeeProcessor.PutFeeAndGasUsed(pool, arg.Header.GetEpoch()) if err != nil { return nil, fmt.Errorf("transactionsFeeProcessor.PutFeeAndGasUsed %w", err) } diff --git a/outport/process/outportDataProvider_test.go b/outport/process/outportDataProvider_test.go index c240fe50ab7..32193eef23f 100644 --- a/outport/process/outportDataProvider_test.go +++ b/outport/process/outportDataProvider_test.go @@ -25,10 +25,12 @@ import ( func createArgOutportDataProvider() ArgOutportDataProvider { txsFeeProc, _ := transactionsfee.NewTransactionsFeeProcessor(transactionsfee.ArgTransactionsFeeProcessor{ - Marshaller: &marshallerMock.MarshalizerMock{}, - TransactionsStorer: &genericMocks.StorerMock{}, - ShardCoordinator: &testscommon.ShardsCoordinatorMock{}, - TxFeeCalculator: &mock.EconomicsHandlerMock{}, + Marshaller: &marshallerMock.MarshalizerMock{}, + TransactionsStorer: &genericMocks.StorerMock{}, + ShardCoordinator: &testscommon.ShardsCoordinatorMock{}, + TxFeeCalculator: &mock.EconomicsHandlerMock{}, + ArgsParser: &testscommon.ArgumentParserMock{}, + GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, }) return ArgOutportDataProvider{ diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index 6520db7635d..be5689e4c62 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -8,7 +8,10 @@ import ( "github.com/multiversx/mx-chain-core-go/core/check" outportcore "github.com/multiversx/mx-chain-core-go/data/outport" "github.com/multiversx/mx-chain-core-go/data/smartContractResult" + "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-core-go/marshal" + "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/storage" logger "github.com/multiversx/mx-chain-logger-go" @@ -19,19 +22,24 @@ const loggerName = "outport/process/transactionsfee" // ArgTransactionsFeeProcessor holds the arguments needed for creating a new instance of transactionsFeeProcessor type ArgTransactionsFeeProcessor struct { - Marshaller marshal.Marshalizer - TransactionsStorer storage.Storer - ShardCoordinator sharding.Coordinator - TxFeeCalculator FeesProcessorHandler - PubKeyConverter core.PubkeyConverter + Marshaller marshal.Marshalizer + TransactionsStorer storage.Storer + ShardCoordinator sharding.Coordinator + TxFeeCalculator FeesProcessorHandler + PubKeyConverter core.PubkeyConverter + GasScheduleNotifier core.GasScheduleNotifier + ArgsParser process.ArgumentsParser } type transactionsFeeProcessor struct { - txGetter transactionGetter - txFeeCalculator FeesProcessorHandler - shardCoordinator sharding.Coordinator - dataFieldParser dataFieldParser - log logger.Logger + txGetter transactionGetter + txFeeCalculator FeesProcessorHandler + shardCoordinator sharding.Coordinator + dataFieldParser dataFieldParser + log logger.Logger + marshaller marshal.Marshalizer + gasScheduleNotifier core.GasScheduleNotifier + argsParser process.ArgumentsParser } // NewTransactionsFeeProcessor will create a new instance of transactionsFeeProcessor @@ -50,11 +58,14 @@ func NewTransactionsFeeProcessor(arg ArgTransactionsFeeProcessor) (*transactions } return &transactionsFeeProcessor{ - txFeeCalculator: arg.TxFeeCalculator, - shardCoordinator: arg.ShardCoordinator, - txGetter: newTxGetter(arg.TransactionsStorer, arg.Marshaller), - log: logger.GetOrCreate(loggerName), - dataFieldParser: parser, + txFeeCalculator: arg.TxFeeCalculator, + shardCoordinator: arg.ShardCoordinator, + txGetter: newTxGetter(arg.TransactionsStorer, arg.Marshaller), + log: logger.GetOrCreate(loggerName), + dataFieldParser: parser, + marshaller: arg.Marshaller, + gasScheduleNotifier: arg.GasScheduleNotifier, + argsParser: arg.ArgsParser, }, nil } @@ -74,16 +85,22 @@ func checkArg(arg ArgTransactionsFeeProcessor) error { if check.IfNil(arg.PubKeyConverter) { return core.ErrNilPubkeyConverter } + if check.IfNil(arg.ArgsParser) { + return process.ErrNilArgumentParser + } + if check.IfNil(arg.GasScheduleNotifier) { + return process.ErrNilGasSchedule + } return nil } // PutFeeAndGasUsed will compute and set in transactions pool fee and gas used -func (tep *transactionsFeeProcessor) PutFeeAndGasUsed(pool *outportcore.TransactionPool) error { +func (tep *transactionsFeeProcessor) PutFeeAndGasUsed(pool *outportcore.TransactionPool, epoch uint32) error { tep.prepareInvalidTxs(pool) txsWithResultsMap := prepareTransactionsAndScrs(pool) - tep.prepareNormalTxs(txsWithResultsMap) + tep.prepareNormalTxs(txsWithResultsMap, epoch) return tep.prepareScrsNoTx(txsWithResultsMap) } @@ -97,7 +114,7 @@ func (tep *transactionsFeeProcessor) prepareInvalidTxs(pool *outportcore.Transac } } -func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *transactionsAndScrsHolder) { +func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *transactionsAndScrsHolder, epoch uint32) { for txHashHex, txWithResult := range transactionsAndScrs.txsWithResults { txHandler := txWithResult.GetTxHandler() @@ -110,16 +127,39 @@ func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *trans feeInfo.SetFee(fee) feeInfo.SetInitialPaidFee(initialPaidFee) - if isRelayedTx(txWithResult) || tep.isESDTOperationWithSCCall(txHandler) { + if tep.isESDTOperationWithSCCall(txHandler) { feeInfo.SetGasUsed(txWithResult.GetTxHandler().GetGasLimit()) feeInfo.SetFee(initialPaidFee) } + res := tep.dataFieldParser.Parse(txHandler.GetData(), txHandler.GetSndAddr(), txHandler.GetRcvAddr(), tep.shardCoordinator.NumberOfShards()) + if tep.isGuardianOperation(res.Operation) { + gasUsed = tep.txFeeCalculator.ComputeGasLimit(txHandler) + guardianOperationCost := tep.getGuardianOperationCost(res.Operation, epoch) + gasUsed += guardianOperationCost + feeInfo.SetGasUsed(gasUsed) + + fee = big.NewInt(0).SetUint64(gasUsed * txHandler.GetGasPrice()) + feeInfo.SetFee(fee) + feeInfo.SetInitialPaidFee(fee) + + return + } + if len(txHandler.GetUserTransactions()) > 0 { tep.prepareRelayedTxV3WithResults(txHashHex, txWithResult) continue } + if isRelayedTx(txWithResult) { + totalFee, isRelayed := tep.getFeeOfRelayed(txWithResult) + if isRelayed { + feeInfo.SetFee(totalFee) + feeInfo.SetInitialPaidFee(totalFee) + feeInfo.SetGasUsed(big.NewInt(0).Div(totalFee, big.NewInt(0).SetUint64(txHandler.GetGasPrice())).Uint64()) + } + } + tep.prepareTxWithResults(txHashHex, txWithResult) } } @@ -146,6 +186,92 @@ func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWi } +func (tep *transactionsFeeProcessor) getFeeOfRelayed(tx *transactionWithResults) (*big.Int, bool) { + if len(tx.GetTxHandler().GetData()) == 0 { + return nil, false + } + + funcName, args, err := tep.argsParser.ParseCallData(string(tx.GetTxHandler().GetData())) + if err != nil { + return nil, false + } + + if funcName == core.RelayedTransaction { + return tep.handleRelayedV1(args, tx) + } + + if funcName == core.RelayedTransactionV2 { + return tep.handleRelayedV2(args, tx) + } + + return nil, false +} + +func (tep *transactionsFeeProcessor) handleRelayedV1(args [][]byte, tx *transactionWithResults) (*big.Int, bool) { + if len(args) != 1 { + return nil, false + } + + innerTx := &transaction.Transaction{} + err := tep.marshaller.Unmarshal(innerTx, args[0]) + if err != nil { + return nil, false + } + + txHandler := tx.GetTxHandler() + gasUsed := tep.txFeeCalculator.ComputeGasLimit(txHandler) + fee := tep.txFeeCalculator.ComputeTxFeeBasedOnGasUsed(txHandler, gasUsed) + + innerFee := tep.txFeeCalculator.ComputeTxFee(innerTx) + + return big.NewInt(0).Add(fee, innerFee), true +} + +func (tep *transactionsFeeProcessor) handleRelayedV2(args [][]byte, tx *transactionWithResults) (*big.Int, bool) { + txHandler := tx.GetTxHandler() + + innerTx := &transaction.Transaction{} + innerTx.RcvAddr = args[0] + innerTx.Nonce = big.NewInt(0).SetBytes(args[1]).Uint64() + innerTx.Data = args[2] + innerTx.Signature = args[3] + innerTx.Value = big.NewInt(0) + innerTx.GasPrice = txHandler.GetGasPrice() + innerTx.GasLimit = txHandler.GetGasLimit() - tep.txFeeCalculator.ComputeGasLimit(txHandler) + innerTx.SndAddr = txHandler.GetRcvAddr() + + gasUsed := tep.txFeeCalculator.ComputeGasLimit(txHandler) + fee := tep.txFeeCalculator.ComputeTxFeeBasedOnGasUsed(txHandler, gasUsed) + + innerFee := tep.txFeeCalculator.ComputeTxFee(innerTx) + + return big.NewInt(0).Add(fee, innerFee), true +} + +func (tep *transactionsFeeProcessor) getGuardianOperationCost(operation string, epoch uint32) uint64 { + gasSchedule, err := tep.gasScheduleNotifier.GasScheduleForEpoch(epoch) + if err != nil { + return 0 + } + + switch operation { + case core.BuiltInFunctionSetGuardian: + return gasSchedule[common.BuiltInCost][core.BuiltInFunctionSetGuardian] + case core.BuiltInFunctionGuardAccount: + return gasSchedule[common.BuiltInCost][core.BuiltInFunctionGuardAccount] + case core.BuiltInFunctionUnGuardAccount: + return gasSchedule[common.BuiltInCost][core.BuiltInFunctionUnGuardAccount] + default: + return 0 + } +} + +func (tep *transactionsFeeProcessor) isGuardianOperation(operation string) bool { + return operation == core.BuiltInFunctionSetGuardian || + operation == core.BuiltInFunctionGuardAccount || + operation == core.BuiltInFunctionUnGuardAccount +} + func (tep *transactionsFeeProcessor) prepareRelayedTxV3WithResults(txHashHex string, txWithResults *transactionWithResults) { refundsValue := big.NewInt(0) for _, scrHandler := range txWithResults.scrs { diff --git a/outport/process/transactionsfee/transactionsFeeProcessor_test.go b/outport/process/transactionsfee/transactionsFeeProcessor_test.go index 8ff4cf14501..8e6d6d7156d 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor_test.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor_test.go @@ -11,6 +11,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data/smartContractResult" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/outport/mock" + "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/genericMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" @@ -22,11 +23,13 @@ var pubKeyConverter, _ = pubkeyConverter.NewBech32PubkeyConverter(32, "erd") func prepareMockArg() ArgTransactionsFeeProcessor { return ArgTransactionsFeeProcessor{ - Marshaller: marshallerMock.MarshalizerMock{}, - TransactionsStorer: genericMocks.NewStorerMock(), - ShardCoordinator: &testscommon.ShardsCoordinatorMock{}, - TxFeeCalculator: &mock.EconomicsHandlerMock{}, - PubKeyConverter: pubKeyConverter, + Marshaller: marshallerMock.MarshalizerMock{}, + TransactionsStorer: genericMocks.NewStorerMock(), + ShardCoordinator: &testscommon.ShardsCoordinatorMock{}, + TxFeeCalculator: &mock.EconomicsHandlerMock{}, + PubKeyConverter: pubKeyConverter, + ArgsParser: &testscommon.ArgumentParserMock{}, + GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, } } @@ -53,6 +56,16 @@ func TestNewTransactionFeeProcessor(t *testing.T) { _, err = NewTransactionsFeeProcessor(arg) require.Equal(t, ErrNilTransactionFeeCalculator, err) + arg = prepareMockArg() + arg.ArgsParser = nil + _, err = NewTransactionsFeeProcessor(arg) + require.Equal(t, process.ErrNilArgumentParser, err) + + arg = prepareMockArg() + arg.GasScheduleNotifier = nil + _, err = NewTransactionsFeeProcessor(arg) + require.Equal(t, process.ErrNilGasSchedule, err) + arg = prepareMockArg() txsFeeProc, err := NewTransactionsFeeProcessor(arg) require.NotNil(t, txsFeeProc) @@ -125,7 +138,7 @@ func TestPutFeeAndGasUsedTx1(t *testing.T) { require.NotNil(t, txsFeeProc) require.Nil(t, err) - err = txsFeeProc.PutFeeAndGasUsed(pool) + err = txsFeeProc.PutFeeAndGasUsed(pool, 0) require.Nil(t, err) require.Equal(t, big.NewInt(1673728170000000), initialTx.GetFeeInfo().GetFee()) require.Equal(t, uint64(7982817), initialTx.GetFeeInfo().GetGasUsed()) @@ -175,7 +188,7 @@ func TestPutFeeAndGasUsedScrNoTx(t *testing.T) { require.NotNil(t, txsFeeProc) require.Nil(t, err) - err = txsFeeProc.PutFeeAndGasUsed(pool) + err = txsFeeProc.PutFeeAndGasUsed(pool, 0) require.Nil(t, err) require.Equal(t, big.NewInt(123001460000000), scr.GetFeeInfo().GetFee()) require.Equal(t, uint64(7350146), scr.GetFeeInfo().GetGasUsed()) @@ -203,7 +216,7 @@ func TestPutFeeAndGasUsedInvalidTxs(t *testing.T) { require.NotNil(t, txsFeeProc) require.Nil(t, err) - err = txsFeeProc.PutFeeAndGasUsed(pool) + err = txsFeeProc.PutFeeAndGasUsed(pool, 0) require.Nil(t, err) require.Equal(t, big.NewInt(349500000000000), tx.GetFeeInfo().GetFee()) require.Equal(t, tx.GetTxHandler().GetGasLimit(), tx.GetFeeInfo().GetGasUsed()) @@ -284,7 +297,7 @@ func TestPutFeeAndGasUsedLogWithErrorAndInformative(t *testing.T) { require.NotNil(t, txsFeeProc) require.Nil(t, err) - err = txsFeeProc.PutFeeAndGasUsed(pool) + err = txsFeeProc.PutFeeAndGasUsed(pool, 0) require.Nil(t, err) require.Equal(t, tx1.GetTxHandler().GetGasLimit(), tx1.GetFeeInfo().GetGasUsed()) @@ -335,10 +348,10 @@ func TestPutFeeAndGasUsedWrongRelayedTx(t *testing.T) { require.NotNil(t, txsFeeProc) require.Nil(t, err) - err = txsFeeProc.PutFeeAndGasUsed(pool) + err = txsFeeProc.PutFeeAndGasUsed(pool, 0) require.Nil(t, err) - require.Equal(t, big.NewInt(6103405000000000), initialTx.GetFeeInfo().GetFee()) - require.Equal(t, uint64(550000000), initialTx.GetFeeInfo().GetGasUsed()) + require.Equal(t, big.NewInt(609500000000000), initialTx.GetFeeInfo().GetFee()) + require.Equal(t, uint64(609500), initialTx.GetFeeInfo().GetGasUsed()) require.Equal(t, "6103405000000000", initialTx.GetFeeInfo().GetInitialPaidFee().String()) } @@ -370,7 +383,7 @@ func TestPutFeeAndGasUsedESDTWithScCall(t *testing.T) { require.NotNil(t, txsFeeProc) require.Nil(t, err) - err = txsFeeProc.PutFeeAndGasUsed(pool) + err = txsFeeProc.PutFeeAndGasUsed(pool, 0) require.Nil(t, err) require.Equal(t, big.NewInt(820765000000000), tx.GetFeeInfo().GetFee()) require.Equal(t, uint64(55_000_000), tx.GetFeeInfo().GetGasUsed()) @@ -425,7 +438,7 @@ func TestPutFeeAndGasUsedScrWithRefundNoTx(t *testing.T) { require.NotNil(t, txsFeeProc) require.Nil(t, err) - err = txsFeeProc.PutFeeAndGasUsed(pool) + err = txsFeeProc.PutFeeAndGasUsed(pool, 0) require.Nil(t, err) require.Equal(t, big.NewInt(0), scr.GetFeeInfo().GetFee()) require.Equal(t, uint64(0), scr.GetFeeInfo().GetGasUsed()) @@ -474,7 +487,7 @@ func TestPutFeeAndGasUsedScrWithRefundNotForInitialSender(t *testing.T) { require.NotNil(t, txsFeeProc) require.Nil(t, err) - err = txsFeeProc.PutFeeAndGasUsed(pool) + err = txsFeeProc.PutFeeAndGasUsed(pool, 0) require.Nil(t, err) require.Equal(t, big.NewInt(0), scr.GetFeeInfo().GetFee()) require.Equal(t, uint64(0), scr.GetFeeInfo().GetGasUsed()) @@ -522,7 +535,7 @@ func TestPutFeeAndGasUsedScrWithRefund(t *testing.T) { require.NotNil(t, txsFeeProc) require.Nil(t, err) - err = txsFeeProc.PutFeeAndGasUsed(pool) + err = txsFeeProc.PutFeeAndGasUsed(pool, 0) require.Nil(t, err) require.Equal(t, big.NewInt(552865000000000), initialTx.GetFeeInfo().GetFee()) require.Equal(t, uint64(50_336_500), initialTx.GetFeeInfo().GetGasUsed()) @@ -579,7 +592,7 @@ func TestMoveBalanceWithSignalError(t *testing.T) { require.NotNil(t, txsFeeProc) require.Nil(t, err) - err = txsFeeProc.PutFeeAndGasUsed(pool) + err = txsFeeProc.PutFeeAndGasUsed(pool, 0) require.Nil(t, err) require.Equal(t, uint64(225_500), initialTx.GetFeeInfo().GetGasUsed()) } From dd0576468d6db957240354317ce0d81451f26636 Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 12 Aug 2024 15:07:57 +0300 Subject: [PATCH 494/503] fixes after review --- api/groups/transactionGroup_test.go | 71 +++++++++++++++++++ facade/nodeFacade.go | 1 + node/external/nodeApiResolver.go | 1 + .../transactionAPI/apiTransactionProcessor.go | 3 +- node/external/transactionAPI/errors.go | 3 + 5 files changed, 78 insertions(+), 1 deletion(-) diff --git a/api/groups/transactionGroup_test.go b/api/groups/transactionGroup_test.go index f183dd30b4c..e517f51f8bd 100644 --- a/api/groups/transactionGroup_test.go +++ b/api/groups/transactionGroup_test.go @@ -343,6 +343,76 @@ func TestTransactionGroup_sendTransaction(t *testing.T) { }) } +func TestTransactionsGroup_getSCRsByTxHash(t *testing.T) { + t.Parallel() + + t.Run("get SCRsByTxHash empty scr hash should error", func(t *testing.T) { + facade := &mock.FacadeStub{} + + transactionGroup, err := groups.NewTransactionGroup(facade) + require.NoError(t, err) + + ws := startWebServer(transactionGroup, "transaction", getTransactionRoutesConfig()) + + req, _ := http.NewRequest(http.MethodGet, "/transaction/scrs-by-tx-hash/txHash", bytes.NewBuffer([]byte{})) + resp := httptest.NewRecorder() + ws.ServeHTTP(resp, req) + + txResp := shared.GenericAPIResponse{} + loadResponse(resp.Body, &txResp) + + assert.Equal(t, http.StatusBadRequest, resp.Code) + assert.True(t, strings.Contains(txResp.Error, apiErrors.ErrValidationEmptySCRHash.Error())) + assert.Empty(t, txResp.Data) + }) + t.Run("get scrs facade error", func(t *testing.T) { + localErr := fmt.Errorf("error") + facade := &mock.FacadeStub{ + GetSCRsByTxHashCalled: func(txHash string, scrHash string) ([]*dataTx.ApiSmartContractResult, error) { + return nil, localErr + }, + } + + transactionGroup, err := groups.NewTransactionGroup(facade) + require.NoError(t, err) + + ws := startWebServer(transactionGroup, "transaction", getTransactionRoutesConfig()) + + req, _ := http.NewRequest(http.MethodGet, "/transaction/scrs-by-tx-hash/txhash?scrHash=hash", bytes.NewBuffer([]byte{})) + resp := httptest.NewRecorder() + ws.ServeHTTP(resp, req) + + txResp := shared.GenericAPIResponse{} + loadResponse(resp.Body, &txResp) + + assert.Equal(t, http.StatusInternalServerError, resp.Code) + assert.True(t, strings.Contains(txResp.Error, localErr.Error())) + assert.Empty(t, txResp.Data) + }) + t.Run("get scrs should work", func(t *testing.T) { + facade := &mock.FacadeStub{ + GetSCRsByTxHashCalled: func(txHash string, scrHash string) ([]*dataTx.ApiSmartContractResult, error) { + return []*dataTx.ApiSmartContractResult{}, nil + }, + } + + transactionGroup, err := groups.NewTransactionGroup(facade) + require.NoError(t, err) + + ws := startWebServer(transactionGroup, "transaction", getTransactionRoutesConfig()) + + req, _ := http.NewRequest(http.MethodGet, "/transaction/scrs-by-tx-hash/txhash?scrHash=hash", bytes.NewBuffer([]byte{})) + resp := httptest.NewRecorder() + ws.ServeHTTP(resp, req) + + txResp := shared.GenericAPIResponse{} + loadResponse(resp.Body, &txResp) + + assert.Equal(t, http.StatusOK, resp.Code) + assert.Equal(t, "", txResp.Error) + }) +} + func TestTransactionGroup_sendMultipleTransactions(t *testing.T) { t.Parallel() @@ -1125,6 +1195,7 @@ func getTransactionRoutesConfig() config.ApiRoutesConfig { {Name: "/:txhash", Open: true}, {Name: "/:txhash/status", Open: true}, {Name: "/simulate", Open: true}, + {Name: "/scrs-by-tx-hash/:txhash", Open: true}, }, }, }, diff --git a/facade/nodeFacade.go b/facade/nodeFacade.go index 479cb4f5412..c3a7f290edf 100644 --- a/facade/nodeFacade.go +++ b/facade/nodeFacade.go @@ -304,6 +304,7 @@ func (nf *nodeFacade) GetTransaction(hash string, withResults bool) (*transactio return nf.apiResolver.GetTransaction(hash, withResults) } +// GetSCRsByTxHash will return a list of smart contract results based on a provided tx hash and smart contract result hash func (nf *nodeFacade) GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) { return nf.apiResolver.GetSCRsByTxHash(txHash, scrHash) } diff --git a/node/external/nodeApiResolver.go b/node/external/nodeApiResolver.go index b359c31b986..7f1bd2269b4 100644 --- a/node/external/nodeApiResolver.go +++ b/node/external/nodeApiResolver.go @@ -189,6 +189,7 @@ func (nar *nodeApiResolver) GetTransaction(hash string, withResults bool) (*tran return nar.apiTransactionHandler.GetTransaction(hash, withResults) } +// GetSCRsByTxHash will return a list of smart contract results based on a provided tx hash and smart contract result hash func (nar *nodeApiResolver) GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) { return nar.apiTransactionHandler.GetSCRsByTxHash(txHash, scrHash) } diff --git a/node/external/transactionAPI/apiTransactionProcessor.go b/node/external/transactionAPI/apiTransactionProcessor.go index bcfb265df62..e1a3d14e93e 100644 --- a/node/external/transactionAPI/apiTransactionProcessor.go +++ b/node/external/transactionAPI/apiTransactionProcessor.go @@ -87,6 +87,7 @@ func NewAPITransactionProcessor(args *ArgAPITransactionProcessor) (*apiTransacti }, nil } +// GetSCRsByTxHash will return a list of smart contract results based on a provided tx hash and smart contract result hash func (atp *apiTransactionProcessor) GetSCRsByTxHash(txHash string, scrHash string) ([]*transaction.ApiSmartContractResult, error) { decodedScrHash, err := hex.DecodeString(scrHash) if err != nil { @@ -99,7 +100,7 @@ func (atp *apiTransactionProcessor) GetSCRsByTxHash(txHash string, scrHash strin } if !atp.historyRepository.IsEnabled() { - return []*transaction.ApiSmartContractResult{}, nil + return nil, fmt.Errorf("cannot return smat contract results: %w", ErrDBLookExtensionIsNotEnabled) } miniblockMetadata, err := atp.historyRepository.GetMiniblockMetadataByTxHash(decodedScrHash) diff --git a/node/external/transactionAPI/errors.go b/node/external/transactionAPI/errors.go index 924bd6040a5..105d6c3e930 100644 --- a/node/external/transactionAPI/errors.go +++ b/node/external/transactionAPI/errors.go @@ -31,3 +31,6 @@ var ErrCannotRetrieveTransactions = errors.New("transactions cannot be retrieved // ErrInvalidAddress signals that the address is invalid var ErrInvalidAddress = errors.New("invalid address") + +// ErrDBLookExtensionIsNotEnabled signals that the db look extension is not enabled +var ErrDBLookExtensionIsNotEnabled = errors.New("db look extension is not enabled") From 75b2aaa5dd54af3fb27c16f3fe730d231cdd78cf Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 12 Aug 2024 15:21:07 +0300 Subject: [PATCH 495/503] small fix --- node/external/transactionAPI/apiTransactionProcessor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/external/transactionAPI/apiTransactionProcessor.go b/node/external/transactionAPI/apiTransactionProcessor.go index e1a3d14e93e..c87cbea5d9e 100644 --- a/node/external/transactionAPI/apiTransactionProcessor.go +++ b/node/external/transactionAPI/apiTransactionProcessor.go @@ -117,7 +117,7 @@ func (atp *apiTransactionProcessor) GetSCRsByTxHash(txHash string, scrHash strin return nil, err } - scrsAPI := make([]*transaction.ApiSmartContractResult, 0) + scrsAPI := make([]*transaction.ApiSmartContractResult, 0, len(resultsHashes.ScResultsHashesAndEpoch)) for _, scrHashesEpoch := range resultsHashes.ScResultsHashesAndEpoch { scrs, errGet := atp.transactionResultsProcessor.getSmartContractResultsInTransactionByHashesAndEpoch(scrHashesEpoch.ScResultsHashes, scrHashesEpoch.Epoch) if errGet != nil { From 1745d470be0b3d70793e10c56250c1bbec53d05f Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 12 Aug 2024 15:45:01 +0300 Subject: [PATCH 496/503] comment --- api/errors/errors.go | 1 + 1 file changed, 1 insertion(+) diff --git a/api/errors/errors.go b/api/errors/errors.go index e2c22411dac..3f4e495b9d2 100644 --- a/api/errors/errors.go +++ b/api/errors/errors.go @@ -64,6 +64,7 @@ var ErrTxGenerationFailed = errors.New("transaction generation failed") // ErrValidationEmptyTxHash signals that an empty tx hash was provided var ErrValidationEmptyTxHash = errors.New("TxHash is empty") +// ErrValidationEmptySCRHash signals that provided smart contract result hash is empty var ErrValidationEmptySCRHash = errors.New("SCRHash is empty") // ErrInvalidBlockNonce signals that an invalid block nonce was provided From a7a39d34e5049dd98be4d2d85e70977d3641c11e Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 13 Aug 2024 12:11:06 +0300 Subject: [PATCH 497/503] further fixes after review-testing --- factory/api/apiResolverFactory.go | 1 + .../testProcessorNodeWithTestWebServer.go | 1 + .../external/transactionAPI/apiTransactionArgs.go | 2 ++ .../transactionAPI/apiTransactionProcessor.go | 10 ++++++++++ .../apiTransactionProcessor_test.go | 14 +++++++++++++- node/external/transactionAPI/check.go | 5 ++++- .../transactionAPI/gasUsedAndFeeProcessor.go | 15 +++++++++------ .../transactionAPI/gasUsedAndFeeProcessor_test.go | 11 ++++++++++- .../process/factory/outportDataProviderFactory.go | 1 + outport/process/outportDataProvider_test.go | 2 ++ .../transactionsfee/transactionsFeeProcessor.go | 15 ++++++++++++--- .../transactionsFeeProcessor_test.go | 11 +++++++++-- 12 files changed, 74 insertions(+), 14 deletions(-) diff --git a/factory/api/apiResolverFactory.go b/factory/api/apiResolverFactory.go index 621ff7a8d13..a33fa09b4a8 100644 --- a/factory/api/apiResolverFactory.go +++ b/factory/api/apiResolverFactory.go @@ -246,6 +246,7 @@ func CreateApiResolver(args *ApiResolverArgs) (facade.ApiResolver, error) { DataFieldParser: dataFieldParser, GasScheduleNotifier: args.GasScheduleNotifier, TxMarshaller: args.CoreComponents.TxMarshalizer(), + EnableEpochsHandler: args.CoreComponents.EnableEpochsHandler(), } apiTransactionProcessor, err := transactionAPI.NewAPITransactionProcessor(argsAPITransactionProc) if err != nil { diff --git a/integrationTests/testProcessorNodeWithTestWebServer.go b/integrationTests/testProcessorNodeWithTestWebServer.go index c194695fb73..8a4d6483970 100644 --- a/integrationTests/testProcessorNodeWithTestWebServer.go +++ b/integrationTests/testProcessorNodeWithTestWebServer.go @@ -239,6 +239,7 @@ func createFacadeComponents(tpn *TestProcessorNode) nodeFacade.ApiResolver { DataFieldParser: dataFieldParser, GasScheduleNotifier: gasScheduleNotifier, TxMarshaller: &marshallerMock.MarshalizerMock{}, + EnableEpochsHandler: tpn.EnableEpochsHandler, } apiTransactionHandler, err := transactionAPI.NewAPITransactionProcessor(argsApiTransactionProc) log.LogIfError(err) diff --git a/node/external/transactionAPI/apiTransactionArgs.go b/node/external/transactionAPI/apiTransactionArgs.go index 1c9a79b874d..8083a4096cb 100644 --- a/node/external/transactionAPI/apiTransactionArgs.go +++ b/node/external/transactionAPI/apiTransactionArgs.go @@ -6,6 +6,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/typeConverters" "github.com/multiversx/mx-chain-core-go/marshal" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/dataRetriever" "github.com/multiversx/mx-chain-go/dblookupext" "github.com/multiversx/mx-chain-go/process" @@ -29,4 +30,5 @@ type ArgAPITransactionProcessor struct { DataFieldParser DataFieldParser GasScheduleNotifier core.GasScheduleNotifier TxMarshaller marshal.Marshalizer + EnableEpochsHandler common.EnableEpochsHandler } diff --git a/node/external/transactionAPI/apiTransactionProcessor.go b/node/external/transactionAPI/apiTransactionProcessor.go index 7702d4ad053..3568175af14 100644 --- a/node/external/transactionAPI/apiTransactionProcessor.go +++ b/node/external/transactionAPI/apiTransactionProcessor.go @@ -44,6 +44,7 @@ type apiTransactionProcessor struct { transactionResultsProcessor *apiTransactionResultsProcessor refundDetector *refundDetector gasUsedAndFeeProcessor *gasUsedAndFeeProcessor + enableEpochsHandler common.EnableEpochsHandler } // NewAPITransactionProcessor will create a new instance of apiTransactionProcessor @@ -72,6 +73,7 @@ func NewAPITransactionProcessor(args *ArgAPITransactionProcessor) (*apiTransacti args.AddressPubKeyConverter, smartContract.NewArgumentParser(), args.TxMarshaller, + args.EnableEpochsHandler, ) return &apiTransactionProcessor{ @@ -90,6 +92,7 @@ func NewAPITransactionProcessor(args *ArgAPITransactionProcessor) (*apiTransacti transactionResultsProcessor: txResultsProc, refundDetector: refundDetectorInstance, gasUsedAndFeeProcessor: gasUsedAndFeeProc, + enableEpochsHandler: args.EnableEpochsHandler, }, nil } @@ -151,6 +154,13 @@ func (atp *apiTransactionProcessor) populateComputedFieldInitiallyPaidFee(tx *tr fee := atp.feeComputer.ComputeTransactionFee(tx) // For user-initiated transactions, we can assume the fee is always strictly positive (note: BigInt(0) is stringified as ""). tx.InitiallyPaidFee = fee.String() + + isFeeFixActive := atp.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, tx.Epoch) + isRelayedAfterFix := tx.IsRelayed && isFeeFixActive + if isRelayedAfterFix { + fee, _ = atp.gasUsedAndFeeProcessor.getFeeOfRelayed(tx) + tx.InitiallyPaidFee = fee.String() + } } func (atp *apiTransactionProcessor) populateComputedFieldIsRefund(tx *transaction.ApiTransactionResult) { diff --git a/node/external/transactionAPI/apiTransactionProcessor_test.go b/node/external/transactionAPI/apiTransactionProcessor_test.go index 4609d0bdfb6..0a36b4b304f 100644 --- a/node/external/transactionAPI/apiTransactionProcessor_test.go +++ b/node/external/transactionAPI/apiTransactionProcessor_test.go @@ -32,6 +32,7 @@ import ( "github.com/multiversx/mx-chain-go/testscommon" dataRetrieverMock "github.com/multiversx/mx-chain-go/testscommon/dataRetriever" dblookupextMock "github.com/multiversx/mx-chain-go/testscommon/dblookupext" + "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/genericMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" @@ -62,6 +63,7 @@ func createMockArgAPITransactionProcessor() *ArgAPITransactionProcessor { }, GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, TxMarshaller: &marshallerMock.MarshalizerMock{}, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), } } @@ -184,7 +186,6 @@ func TestNewAPITransactionProcessor(t *testing.T) { _, err := NewAPITransactionProcessor(arguments) require.Equal(t, ErrNilDataFieldParser, err) }) - t.Run("NilTxMarshaller", func(t *testing.T) { t.Parallel() @@ -194,6 +195,15 @@ func TestNewAPITransactionProcessor(t *testing.T) { _, err := NewAPITransactionProcessor(arguments) require.True(t, strings.Contains(err.Error(), process.ErrNilMarshalizer.Error())) }) + t.Run("NilEnableEpochsHandler", func(t *testing.T) { + t.Parallel() + + arguments := createMockArgAPITransactionProcessor() + arguments.EnableEpochsHandler = nil + + _, err := NewAPITransactionProcessor(arguments) + require.Equal(t, process.ErrNilEnableEpochsHandler, err) + }) } func TestNode_GetTransactionInvalidHashShouldErr(t *testing.T) { @@ -474,6 +484,7 @@ func TestNode_GetTransactionWithResultsFromStorage(t *testing.T) { }, GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, TxMarshaller: &marshallerMock.MarshalizerMock{}, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), } apiTransactionProc, _ := NewAPITransactionProcessor(args) @@ -1044,6 +1055,7 @@ func createAPITransactionProc(t *testing.T, epoch uint32, withDbLookupExt bool) DataFieldParser: dataFieldParser, GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, TxMarshaller: &marshallerMock.MarshalizerMock{}, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), } apiTransactionProc, err := NewAPITransactionProcessor(args) require.Nil(t, err) diff --git a/node/external/transactionAPI/check.go b/node/external/transactionAPI/check.go index 729391d4914..ce45c38bae4 100644 --- a/node/external/transactionAPI/check.go +++ b/node/external/transactionAPI/check.go @@ -47,9 +47,12 @@ func checkNilArgs(arg *ArgAPITransactionProcessor) error { if check.IfNilReflect(arg.GasScheduleNotifier) { return process.ErrNilGasSchedule } - if check.IfNilReflect(arg.TxMarshaller) { + if check.IfNil(arg.TxMarshaller) { return fmt.Errorf("%w for tx marshaller", process.ErrNilMarshalizer) } + if check.IfNil(arg.EnableEpochsHandler) { + return process.ErrNilEnableEpochsHandler + } return nil } diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index 30ac5cbc910..1ad96c810f9 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -17,6 +17,7 @@ type gasUsedAndFeeProcessor struct { pubKeyConverter core.PubkeyConverter argsParser process.ArgumentsParser marshaller marshal.Marshalizer + enableEpochsHandler common.EnableEpochsHandler } func newGasUsedAndFeeProcessor( @@ -25,6 +26,7 @@ func newGasUsedAndFeeProcessor( pubKeyConverter core.PubkeyConverter, argsParser process.ArgumentsParser, marshaller marshal.Marshalizer, + enableEpochsHandler common.EnableEpochsHandler, ) *gasUsedAndFeeProcessor { return &gasUsedAndFeeProcessor{ feeComputer: txFeeCalculator, @@ -32,6 +34,7 @@ func newGasUsedAndFeeProcessor( pubKeyConverter: pubKeyConverter, argsParser: argsParser, marshaller: marshaller, + enableEpochsHandler: enableEpochsHandler, } } @@ -42,14 +45,16 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction tx.GasUsed = gasUsed tx.Fee = fee.String() - if gfp.isESDTOperationWithSCCall(tx) { + isFeeFixActive := gfp.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, tx.Epoch) + isRelayedBeforeFix := tx.IsRelayed && !isFeeFixActive + if isRelayedBeforeFix || gfp.isESDTOperationWithSCCall(tx) { tx.GasUsed = tx.GasLimit tx.Fee = tx.InitiallyPaidFee } // if there is a guardian operation, SetGuardian/GuardAccount/UnGuardAccount // the pre-configured cost of the operation must be added separately - if gfp.isGuardianOperation(tx) { + if gfp.isGuardianOperation(tx) && isFeeFixActive { gasUsed = gfp.feeComputer.ComputeGasLimit(tx) guardianOperationCost := gfp.getGuardianOperationCost(tx) gasUsed += guardianOperationCost @@ -57,14 +62,12 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction fee = big.NewInt(0).SetUint64(gasUsed * tx.GasPrice) tx.Fee = fee.String() - - initiallyPaidFee := gfp.feeComputer.ComputeMoveBalanceFee(tx) - tx.InitiallyPaidFee = initiallyPaidFee.String() + tx.InitiallyPaidFee = fee.String() return } - if tx.IsRelayed { + if tx.IsRelayed && isFeeFixActive { totalFee, isRelayed := gfp.getFeeOfRelayed(tx) if isRelayed { tx.Fee = totalFee.String() diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go index 1a9c7f922f4..f6af8464428 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go @@ -44,6 +44,7 @@ func TestComputeTransactionGasUsedAndFeeMoveBalance(t *testing.T) { pubKeyConverter, &testscommon.ArgumentParserMock{}, &testscommon.MarshallerStub{}, + enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), ) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -80,6 +81,7 @@ func TestComputeTransactionGasUsedAndFeeLogWithError(t *testing.T) { pubKeyConverter, &testscommon.ArgumentParserMock{}, &testscommon.MarshallerStub{}, + enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), ) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -129,6 +131,7 @@ func TestComputeTransactionGasUsedAndFeeRelayedTxWithWriteLog(t *testing.T) { pubKeyConverter, &testscommon.ArgumentParserMock{}, &testscommon.MarshallerStub{}, + enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), ) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -173,6 +176,7 @@ func TestComputeTransactionGasUsedAndFeeTransactionWithScrWithRefund(t *testing. pubKeyConverter, &testscommon.ArgumentParserMock{}, &testscommon.MarshallerStub{}, + enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), ) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -227,6 +231,7 @@ func TestNFTTransferWithScCall(t *testing.T) { pubKeyConverter, &testscommon.ArgumentParserMock{}, &testscommon.MarshallerStub{}, + enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), ) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -277,6 +282,11 @@ func TestComputeAndAttachGasUsedAndFeeSetGuardian(t *testing.T) { pubKeyConverter, &testscommon.ArgumentParserMock{}, &testscommon.MarshallerStub{}, + &enableEpochsHandlerMock.EnableEpochsHandlerStub{ + IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool { + return flag == common.FixRelayedBaseCostFlag + }, + }, ) sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" @@ -293,7 +303,6 @@ func TestComputeAndAttachGasUsedAndFeeSetGuardian(t *testing.T) { Operation: "SetGuardian", GasPrice: 1000000000, } - tx.InitiallyPaidFee = feeComp.ComputeTransactionFee(tx).String() gasUsedAndFeeProc.computeAndAttachGasUsedAndFee(tx) require.Equal(t, uint64(475_500), tx.GasUsed) diff --git a/outport/process/factory/outportDataProviderFactory.go b/outport/process/factory/outportDataProviderFactory.go index 4350605b000..c57f2a09282 100644 --- a/outport/process/factory/outportDataProviderFactory.go +++ b/outport/process/factory/outportDataProviderFactory.go @@ -69,6 +69,7 @@ func CreateOutportDataProvider(arg ArgOutportDataProviderFactory) (outport.DataP PubKeyConverter: arg.AddressConverter, ArgsParser: smartContract.NewArgumentParser(), GasScheduleNotifier: arg.GasScheduleNotifier, + EnableEpochsHandler: arg.EnableEpochsHandler, }) if err != nil { return nil, err diff --git a/outport/process/outportDataProvider_test.go b/outport/process/outportDataProvider_test.go index 32193eef23f..96527e6404a 100644 --- a/outport/process/outportDataProvider_test.go +++ b/outport/process/outportDataProvider_test.go @@ -16,6 +16,7 @@ import ( "github.com/multiversx/mx-chain-go/outport/process/transactionsfee" "github.com/multiversx/mx-chain-go/testscommon" commonMocks "github.com/multiversx/mx-chain-go/testscommon/common" + "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/genericMocks" "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" @@ -31,6 +32,7 @@ func createArgOutportDataProvider() ArgOutportDataProvider { TxFeeCalculator: &mock.EconomicsHandlerMock{}, ArgsParser: &testscommon.ArgumentParserMock{}, GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), }) return ArgOutportDataProvider{ diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index be5689e4c62..61f87666d2d 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -29,6 +29,7 @@ type ArgTransactionsFeeProcessor struct { PubKeyConverter core.PubkeyConverter GasScheduleNotifier core.GasScheduleNotifier ArgsParser process.ArgumentsParser + EnableEpochsHandler common.EnableEpochsHandler } type transactionsFeeProcessor struct { @@ -40,6 +41,7 @@ type transactionsFeeProcessor struct { marshaller marshal.Marshalizer gasScheduleNotifier core.GasScheduleNotifier argsParser process.ArgumentsParser + enableEpochsHandler common.EnableEpochsHandler } // NewTransactionsFeeProcessor will create a new instance of transactionsFeeProcessor @@ -66,6 +68,7 @@ func NewTransactionsFeeProcessor(arg ArgTransactionsFeeProcessor) (*transactions marshaller: arg.Marshaller, gasScheduleNotifier: arg.GasScheduleNotifier, argsParser: arg.ArgsParser, + enableEpochsHandler: arg.EnableEpochsHandler, }, nil } @@ -91,6 +94,9 @@ func checkArg(arg ArgTransactionsFeeProcessor) error { if check.IfNil(arg.GasScheduleNotifier) { return process.ErrNilGasSchedule } + if check.IfNil(arg.EnableEpochsHandler) { + return process.ErrNilEnableEpochsHandler + } return nil } @@ -127,13 +133,16 @@ func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *trans feeInfo.SetFee(fee) feeInfo.SetInitialPaidFee(initialPaidFee) - if tep.isESDTOperationWithSCCall(txHandler) { + isRelayed := isRelayedTx(txWithResult) + isFeeFixActive := tep.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, epoch) + isRelayedBeforeFix := isRelayed && !isFeeFixActive + if isRelayedBeforeFix || tep.isESDTOperationWithSCCall(txHandler) { feeInfo.SetGasUsed(txWithResult.GetTxHandler().GetGasLimit()) feeInfo.SetFee(initialPaidFee) } res := tep.dataFieldParser.Parse(txHandler.GetData(), txHandler.GetSndAddr(), txHandler.GetRcvAddr(), tep.shardCoordinator.NumberOfShards()) - if tep.isGuardianOperation(res.Operation) { + if tep.isGuardianOperation(res.Operation) && isFeeFixActive { gasUsed = tep.txFeeCalculator.ComputeGasLimit(txHandler) guardianOperationCost := tep.getGuardianOperationCost(res.Operation, epoch) gasUsed += guardianOperationCost @@ -151,7 +160,7 @@ func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *trans continue } - if isRelayedTx(txWithResult) { + if isRelayedTx(txWithResult) && isFeeFixActive { totalFee, isRelayed := tep.getFeeOfRelayed(txWithResult) if isRelayed { feeInfo.SetFee(totalFee) diff --git a/outport/process/transactionsfee/transactionsFeeProcessor_test.go b/outport/process/transactionsfee/transactionsFeeProcessor_test.go index 8e6d6d7156d..b3bda2cc9c9 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor_test.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor_test.go @@ -13,6 +13,7 @@ import ( "github.com/multiversx/mx-chain-go/outport/mock" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/testscommon" + "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/genericMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" logger "github.com/multiversx/mx-chain-logger-go" @@ -30,6 +31,7 @@ func prepareMockArg() ArgTransactionsFeeProcessor { PubKeyConverter: pubKeyConverter, ArgsParser: &testscommon.ArgumentParserMock{}, GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), } } @@ -66,6 +68,11 @@ func TestNewTransactionFeeProcessor(t *testing.T) { _, err = NewTransactionsFeeProcessor(arg) require.Equal(t, process.ErrNilGasSchedule, err) + arg = prepareMockArg() + arg.EnableEpochsHandler = nil + _, err = NewTransactionsFeeProcessor(arg) + require.Equal(t, process.ErrNilEnableEpochsHandler, err) + arg = prepareMockArg() txsFeeProc, err := NewTransactionsFeeProcessor(arg) require.NotNil(t, txsFeeProc) @@ -350,8 +357,8 @@ func TestPutFeeAndGasUsedWrongRelayedTx(t *testing.T) { err = txsFeeProc.PutFeeAndGasUsed(pool, 0) require.Nil(t, err) - require.Equal(t, big.NewInt(609500000000000), initialTx.GetFeeInfo().GetFee()) - require.Equal(t, uint64(609500), initialTx.GetFeeInfo().GetGasUsed()) + require.Equal(t, big.NewInt(6103405000000000), initialTx.GetFeeInfo().GetFee()) + require.Equal(t, uint64(550000000), initialTx.GetFeeInfo().GetGasUsed()) require.Equal(t, "6103405000000000", initialTx.GetFeeInfo().GetInitialPaidFee().String()) } From e8f7d9f8fa5c71eef00944d9854f29f230dae1ea Mon Sep 17 00:00:00 2001 From: python-qa Date: Tue, 13 Aug 2024 16:00:21 +0300 Subject: [PATCH 498/503] fix gh action --- ...hain_simulator_and_execute_system_test.yml | 118 ++++++++---------- 1 file changed, 49 insertions(+), 69 deletions(-) diff --git a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml index 0bb675230ae..00c329dd3fa 100644 --- a/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml +++ b/.github/workflows/build_and_run_chain_simulator_and_execute_system_test.yml @@ -35,48 +35,68 @@ jobs: MX_CHAIN_TESTING_SUITE_TARGET_BRANCH: "" steps: - - name: Fetch Latest Comment - if: github.event_name != 'issue_comment' + - name: Determine Target Branches + id: target_branch + run: | + echo "CURRENT_BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}" >> $GITHUB_ENV + + # Default target branches based on the PR base branch + if [[ "${{ github.event.pull_request.base.ref }}" == "main" ]]; then + echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=main" >> $GITHUB_ENV + echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=main" >> $GITHUB_ENV + elif [[ "${{ github.event.pull_request.base.ref }}" == "master" ]]; then + echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=main" >> $GITHUB_ENV + echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=main" >> $GITHUB_ENV + else + echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV + echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV + fi + + # Always set MX_CHAIN_GO_TARGET_BRANCH based on the PR base branch + echo "MX_CHAIN_GO_TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV + + + - name: Fetch and Parse Last Comment for Branches uses: actions/github-script@v7 - id: fetch_comment + id: fetch_and_parse_last_comment with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | + // Get the latest comment const comments = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, }); - // Filter for comments containing "Run Tests:" - const latestComment = comments.data.reverse().find(comment => comment.body.includes('Run Tests:')); + const lastComment = comments.data.pop(); // Get the last comment + + if (lastComment && lastComment.body.includes('Run Tests:')) { + const body = lastComment.body.trim(); + core.setOutput('latest_comment', body); - if (latestComment) { - core.setOutput('latest_comment', latestComment.body); + // Parse the branches from the last comment + const simulatorBranchMatch = body.match(/mx-chain-simulator-go:\s*(\S+)/); + const testingSuiteBranchMatch = body.match(/mx-chain-testing-suite:\s*(\S+)/); + + // Override the target branches if specified + if (simulatorBranchMatch) { + core.exportVariable('MX_CHAIN_SIMULATOR_TARGET_BRANCH', simulatorBranchMatch[1]); + } + if (testingSuiteBranchMatch) { + core.exportVariable('MX_CHAIN_TESTING_SUITE_TARGET_BRANCH', testingSuiteBranchMatch[1]); + } } else { - core.setOutput('latest_comment', ''); + core.info('The last comment does not contain "Run Tests:". Skipping branch override.'); } - env: - LATEST_COMMENT: ${{ steps.fetch_comment.outputs.latest_comment }} + - - name: Parse Comment for Branches + - name: Print Target Branches run: | - # Use fetched comment if available, otherwise use current event comment - COMMENT="${{ steps.fetch_comment.outputs.latest_comment || github.event.comment.body }}" - - # Debug print the comment being used - echo "Comment used for parsing: $COMMENT" - - # Extract branch names from the comment - if echo "$COMMENT" | grep -q "mx-chain-simulator-go:"; then - SIMULATOR_BRANCH=$(echo "$COMMENT" | grep "mx-chain-simulator-go:" | awk -F': ' '{print $2}') - echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=${SIMULATOR_BRANCH}" >> $GITHUB_ENV - fi - - if echo "$COMMENT" | grep -q "mx-chain-testing-suite:"; then - TESTING_SUITE_BRANCH=$(echo "$COMMENT" | grep "mx-chain-testing-suite:" | awk -F': ' '{print $2}') - echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=${TESTING_SUITE_BRANCH}" >> $GITHUB_ENV - fi + echo "Current branch mx-chain-go: ${{ env.CURRENT_BRANCH }}" + echo "mx-chain-go target branch: ${{ env.MX_CHAIN_GO_TARGET_BRANCH }}" + echo "mx-chain-simulator-go target branch: ${{ env.MX_CHAIN_SIMULATOR_TARGET_BRANCH }}" + echo "mx-chain-testing-suite target branch: ${{ env.MX_CHAIN_TESTING_SUITE_TARGET_BRANCH }}" - name: Set up Go 1.20.7 uses: actions/setup-go@v3 @@ -88,11 +108,11 @@ jobs: uses: actions/checkout@v4 with: repository: 'multiversx/mx-chain-go' - ref: ${{ env.MX_CHAIN_GO_TARGET_BRANCH || github.head_ref || github.ref }} + ref: ${{ github.head_ref }} fetch-depth: 0 path: 'mx-chain-go' - - name: Get Latest Commit Hash + - name: Get Latest mx-chain-go Commit Hash run: | cd mx-chain-go current_branch=$(git symbolic-ref --short HEAD) @@ -102,45 +122,6 @@ jobs: echo "LATEST_COMMIT_HASH=${latest_commit_hash}" >> $GITHUB_ENV echo "Latest commit hash: ${latest_commit_hash}" - - name: Determine Target Branches - id: target_branch - run: | - echo "CURRENT_BRANCH=${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}" >> $GITHUB_ENV - - # Use branches from comment if they are set - if [ -n "${{ env.MX_CHAIN_SIMULATOR_TARGET_BRANCH }}" ]; then - echo "Using comment-specified mx-chain-simulator-go branch: ${{ env.MX_CHAIN_SIMULATOR_TARGET_BRANCH }}" - echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=${{ env.MX_CHAIN_SIMULATOR_TARGET_BRANCH }}" >> $GITHUB_ENV - else - if [[ "${{ github.event.pull_request.base.ref }}" == "main" ]]; then - echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=main" >> $GITHUB_ENV - elif [[ "${{ github.event.pull_request.base.ref }}" == "master" ]]; then - echo "MX_CHAIN_SIMULATOR_TARGET_BRANCH=main" >> $GITHUB_ENV - fi - fi - - if [ -n "${{ env.MX_CHAIN_TESTING_SUITE_TARGET_BRANCH }}" ]; then - echo "Using comment-specified mx-chain-testing-suite branch: ${{ env.MX_CHAIN_TESTING_SUITE_TARGET_BRANCH }}" - echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=${{ env.MX_CHAIN_TESTING_SUITE_TARGET_BRANCH }}" >> $GITHUB_ENV - else - if [[ "${{ github.event.pull_request.base.ref }}" == "main" ]]; then - echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=main" >> $GITHUB_ENV - elif [[ "${{ github.event.pull_request.base.ref }}" == "master" ]]; then - echo "MX_CHAIN_TESTING_SUITE_TARGET_BRANCH=main" >> $GITHUB_ENV - fi - fi - - # Always set MX_CHAIN_GO_TARGET_BRANCH based on the PR base branch - echo "MX_CHAIN_GO_TARGET_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV - - - - name: Print Target Branches - run: | - echo "Current branch mx-chain-go: ${{ env.CURRENT_BRANCH }}" - echo "mx-chain-go target branch: ${{ env.MX_CHAIN_GO_TARGET_BRANCH }}" - echo "mx-chain-simulator-go target branch: ${{ env.MX_CHAIN_SIMULATOR_TARGET_BRANCH }}" - echo "mx-chain-testing-suite target branch: ${{ env.MX_CHAIN_TESTING_SUITE_TARGET_BRANCH }}" - - name: Checkout mx-chain-simulator-go uses: actions/checkout@v4 with: @@ -159,7 +140,6 @@ jobs: pip install -r scripts/update-go-mod/requirements.txt python scripts/update-go-mod/update-go-mod.py $LATEST_COMMIT_HASH - - name: Run go build run: | cd mx-chain-simulator-go/cmd/chainsimulator From d7e5ef83299b73654c135e76bfbd9609304be32d Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 13 Aug 2024 19:59:03 +0300 Subject: [PATCH 499/503] reverted fix for guarded operations, not needed --- common/forking/gasSchedule.go | 20 ------- factory/api/apiResolverFactory.go | 1 - genesis/process/disabled/feeHandler.go | 5 -- go.mod | 2 +- go.sum | 4 +- .../mock/gasScheduleNotifierMock.go | 5 -- .../testProcessorNodeWithTestWebServer.go | 1 - node/external/timemachine/fee/feeComputer.go | 5 -- .../transactionAPI/apiTransactionArgs.go | 1 - .../transactionAPI/apiTransactionProcessor.go | 1 - .../apiTransactionProcessor_test.go | 3 - node/external/transactionAPI/check.go | 3 - .../transactionAPI/gasUsedAndFeeProcessor.go | 42 -------------- .../gasUsedAndFeeProcessor_test.go | 57 ------------------- node/external/transactionAPI/interface.go | 1 - .../transactionsFeeProcessor.go | 38 ------------- process/interface.go | 1 - testscommon/gasScheduleNotifierMock.go | 10 ---- 18 files changed, 3 insertions(+), 197 deletions(-) diff --git a/common/forking/gasSchedule.go b/common/forking/gasSchedule.go index cac675387be..7da39fed41f 100644 --- a/common/forking/gasSchedule.go +++ b/common/forking/gasSchedule.go @@ -163,26 +163,6 @@ func (g *gasScheduleNotifier) LatestGasSchedule() map[string]map[string]uint64 { return g.lastGasSchedule } -// GasScheduleForEpoch returns the gas schedule for the specific epoch -func (g *gasScheduleNotifier) GasScheduleForEpoch(epoch uint32) (map[string]map[string]uint64, error) { - g.mutNotifier.RLock() - defer g.mutNotifier.RUnlock() - - currentVersion := g.getMatchingVersion(g.currentEpoch) - requestedVersion := g.getMatchingVersion(epoch) - if currentVersion == requestedVersion { - return g.lastGasSchedule, nil - } - - gasSchedule, err := common.LoadGasScheduleConfig(filepath.Join(g.configDir, requestedVersion.FileName)) - if err != nil { - log.Error("could not load the gas schedule", "epoch", requestedVersion.StartEpoch) - return nil, err - } - - return gasSchedule, nil -} - // LatestGasScheduleCopy returns a copy of the latest gas schedule func (g *gasScheduleNotifier) LatestGasScheduleCopy() map[string]map[string]uint64 { g.mutNotifier.RLock() diff --git a/factory/api/apiResolverFactory.go b/factory/api/apiResolverFactory.go index a33fa09b4a8..399ee4b1533 100644 --- a/factory/api/apiResolverFactory.go +++ b/factory/api/apiResolverFactory.go @@ -244,7 +244,6 @@ func CreateApiResolver(args *ApiResolverArgs) (facade.ApiResolver, error) { TxTypeHandler: txTypeHandler, LogsFacade: logsFacade, DataFieldParser: dataFieldParser, - GasScheduleNotifier: args.GasScheduleNotifier, TxMarshaller: args.CoreComponents.TxMarshalizer(), EnableEpochsHandler: args.CoreComponents.EnableEpochsHandler(), } diff --git a/genesis/process/disabled/feeHandler.go b/genesis/process/disabled/feeHandler.go index 1d4679e859f..f81e7e978eb 100644 --- a/genesis/process/disabled/feeHandler.go +++ b/genesis/process/disabled/feeHandler.go @@ -87,11 +87,6 @@ func (fh *FeeHandler) ComputeMoveBalanceFee(_ data.TransactionWithFeeHandler) *b return big.NewInt(0) } -// ComputeMoveBalanceFeeInEpoch returns 0 -func (fh *FeeHandler) ComputeMoveBalanceFeeInEpoch(_ data.TransactionWithFeeHandler, _ uint32) *big.Int { - return big.NewInt(0) -} - // ComputeFeeForProcessing returns 0 func (fh *FeeHandler) ComputeFeeForProcessing(_ data.TransactionWithFeeHandler, _ uint64) *big.Int { return big.NewInt(0) diff --git a/go.mod b/go.mod index 5a2ac5d99fd..4667bd06e7e 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.1.0 - github.com/multiversx/mx-chain-core-go v1.2.22-0.20240726123734-d2e801ceb0bc + github.com/multiversx/mx-chain-core-go v1.2.21 github.com/multiversx/mx-chain-crypto-go v1.2.12 github.com/multiversx/mx-chain-es-indexer-go v1.7.4 github.com/multiversx/mx-chain-logger-go v1.0.15 diff --git a/go.sum b/go.sum index 431460a09e2..11a9bc62556 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.1.0 h1:J7bX6HoN3HiHY7cUeEjG8AJWgQDDPcY+OPDOsSUOkRE= github.com/multiversx/mx-chain-communication-go v1.1.0/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= -github.com/multiversx/mx-chain-core-go v1.2.22-0.20240726123734-d2e801ceb0bc h1:EB25Psgi0GjWJfrNfgvGEMcuoqj63BnFrw0bqsl9Hdc= -github.com/multiversx/mx-chain-core-go v1.2.22-0.20240726123734-d2e801ceb0bc/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.21 h1:+XVKznPTlUU5EFS1A8chtS8fStW60upRIyF4Pgml19I= +github.com/multiversx/mx-chain-core-go v1.2.21/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.4 h1:SjJk9G9SN8baz0sFIU2jymYCfx3XiikGEB2wW0jwvfw= diff --git a/integrationTests/mock/gasScheduleNotifierMock.go b/integrationTests/mock/gasScheduleNotifierMock.go index ddcff3873fc..6ef6ea2684c 100644 --- a/integrationTests/mock/gasScheduleNotifierMock.go +++ b/integrationTests/mock/gasScheduleNotifierMock.go @@ -28,11 +28,6 @@ func (g *GasScheduleNotifierMock) LatestGasSchedule() map[string]map[string]uint return g.GasSchedule } -// GasScheduleForEpoch - -func (g *GasScheduleNotifierMock) GasScheduleForEpoch(_ uint32) (map[string]map[string]uint64, error) { - return g.GasSchedule, nil -} - // UnRegisterAll - func (g *GasScheduleNotifierMock) UnRegisterAll() { } diff --git a/integrationTests/testProcessorNodeWithTestWebServer.go b/integrationTests/testProcessorNodeWithTestWebServer.go index 8a4d6483970..d533f4c75b1 100644 --- a/integrationTests/testProcessorNodeWithTestWebServer.go +++ b/integrationTests/testProcessorNodeWithTestWebServer.go @@ -237,7 +237,6 @@ func createFacadeComponents(tpn *TestProcessorNode) nodeFacade.ApiResolver { TxTypeHandler: txTypeHandler, LogsFacade: logsFacade, DataFieldParser: dataFieldParser, - GasScheduleNotifier: gasScheduleNotifier, TxMarshaller: &marshallerMock.MarshalizerMock{}, EnableEpochsHandler: tpn.EnableEpochsHandler, } diff --git a/node/external/timemachine/fee/feeComputer.go b/node/external/timemachine/fee/feeComputer.go index 9ad90d2b221..6d19ce05ceb 100644 --- a/node/external/timemachine/fee/feeComputer.go +++ b/node/external/timemachine/fee/feeComputer.go @@ -50,11 +50,6 @@ func (computer *feeComputer) ComputeTransactionFee(tx *transaction.ApiTransactio return computer.economicsInstance.ComputeTxFeeInEpoch(tx.Tx, tx.Epoch) } -// ComputeMoveBalanceFee computes a transaction's move balance fee, at a given epoch -func (computer *feeComputer) ComputeMoveBalanceFee(tx *transaction.ApiTransactionResult) *big.Int { - return computer.economicsInstance.ComputeMoveBalanceFeeInEpoch(tx.Tx, tx.Epoch) -} - // IsInterfaceNil returns true if there is no value under the interface func (computer *feeComputer) IsInterfaceNil() bool { return computer == nil diff --git a/node/external/transactionAPI/apiTransactionArgs.go b/node/external/transactionAPI/apiTransactionArgs.go index 8083a4096cb..1e4099390fd 100644 --- a/node/external/transactionAPI/apiTransactionArgs.go +++ b/node/external/transactionAPI/apiTransactionArgs.go @@ -28,7 +28,6 @@ type ArgAPITransactionProcessor struct { TxTypeHandler process.TxTypeHandler LogsFacade LogsFacade DataFieldParser DataFieldParser - GasScheduleNotifier core.GasScheduleNotifier TxMarshaller marshal.Marshalizer EnableEpochsHandler common.EnableEpochsHandler } diff --git a/node/external/transactionAPI/apiTransactionProcessor.go b/node/external/transactionAPI/apiTransactionProcessor.go index 3568175af14..d018a3322ad 100644 --- a/node/external/transactionAPI/apiTransactionProcessor.go +++ b/node/external/transactionAPI/apiTransactionProcessor.go @@ -69,7 +69,6 @@ func NewAPITransactionProcessor(args *ArgAPITransactionProcessor) (*apiTransacti refundDetectorInstance := NewRefundDetector() gasUsedAndFeeProc := newGasUsedAndFeeProcessor( args.FeeComputer, - args.GasScheduleNotifier, args.AddressPubKeyConverter, smartContract.NewArgumentParser(), args.TxMarshaller, diff --git a/node/external/transactionAPI/apiTransactionProcessor_test.go b/node/external/transactionAPI/apiTransactionProcessor_test.go index 0a36b4b304f..18d524d9c2c 100644 --- a/node/external/transactionAPI/apiTransactionProcessor_test.go +++ b/node/external/transactionAPI/apiTransactionProcessor_test.go @@ -61,7 +61,6 @@ func createMockArgAPITransactionProcessor() *ArgAPITransactionProcessor { return &datafield.ResponseParseData{} }, }, - GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, TxMarshaller: &marshallerMock.MarshalizerMock{}, EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), } @@ -482,7 +481,6 @@ func TestNode_GetTransactionWithResultsFromStorage(t *testing.T) { return &datafield.ResponseParseData{} }, }, - GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, TxMarshaller: &marshallerMock.MarshalizerMock{}, EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), } @@ -1053,7 +1051,6 @@ func createAPITransactionProc(t *testing.T, epoch uint32, withDbLookupExt bool) TxTypeHandler: &testscommon.TxTypeHandlerMock{}, LogsFacade: &testscommon.LogsFacadeStub{}, DataFieldParser: dataFieldParser, - GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, TxMarshaller: &marshallerMock.MarshalizerMock{}, EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), } diff --git a/node/external/transactionAPI/check.go b/node/external/transactionAPI/check.go index ce45c38bae4..012aae77618 100644 --- a/node/external/transactionAPI/check.go +++ b/node/external/transactionAPI/check.go @@ -44,9 +44,6 @@ func checkNilArgs(arg *ArgAPITransactionProcessor) error { if check.IfNilReflect(arg.DataFieldParser) { return ErrNilDataFieldParser } - if check.IfNilReflect(arg.GasScheduleNotifier) { - return process.ErrNilGasSchedule - } if check.IfNil(arg.TxMarshaller) { return fmt.Errorf("%w for tx marshaller", process.ErrNilMarshalizer) } diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index 1ad96c810f9..8951149c983 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -13,7 +13,6 @@ import ( type gasUsedAndFeeProcessor struct { feeComputer feeComputer - gasScheduleNotifier core.GasScheduleNotifier pubKeyConverter core.PubkeyConverter argsParser process.ArgumentsParser marshaller marshal.Marshalizer @@ -22,7 +21,6 @@ type gasUsedAndFeeProcessor struct { func newGasUsedAndFeeProcessor( txFeeCalculator feeComputer, - gasScheduleNotifier core.GasScheduleNotifier, pubKeyConverter core.PubkeyConverter, argsParser process.ArgumentsParser, marshaller marshal.Marshalizer, @@ -30,7 +28,6 @@ func newGasUsedAndFeeProcessor( ) *gasUsedAndFeeProcessor { return &gasUsedAndFeeProcessor{ feeComputer: txFeeCalculator, - gasScheduleNotifier: gasScheduleNotifier, pubKeyConverter: pubKeyConverter, argsParser: argsParser, marshaller: marshaller, @@ -52,21 +49,6 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction tx.Fee = tx.InitiallyPaidFee } - // if there is a guardian operation, SetGuardian/GuardAccount/UnGuardAccount - // the pre-configured cost of the operation must be added separately - if gfp.isGuardianOperation(tx) && isFeeFixActive { - gasUsed = gfp.feeComputer.ComputeGasLimit(tx) - guardianOperationCost := gfp.getGuardianOperationCost(tx) - gasUsed += guardianOperationCost - tx.GasUsed = gasUsed - - fee = big.NewInt(0).SetUint64(gasUsed * tx.GasPrice) - tx.Fee = fee.String() - tx.InitiallyPaidFee = fee.String() - - return - } - if tx.IsRelayed && isFeeFixActive { totalFee, isRelayed := gfp.getFeeOfRelayed(tx) if isRelayed { @@ -164,30 +146,6 @@ func (gfp *gasUsedAndFeeProcessor) handleRelayedV2(args [][]byte, tx *transactio return big.NewInt(0).Add(fee, innerFee), true } -func (gfp *gasUsedAndFeeProcessor) getGuardianOperationCost(tx *transaction.ApiTransactionResult) uint64 { - gasSchedule, err := gfp.gasScheduleNotifier.GasScheduleForEpoch(tx.Epoch) - if err != nil { - return 0 - } - - switch tx.Operation { - case core.BuiltInFunctionSetGuardian: - return gasSchedule[common.BuiltInCost][core.BuiltInFunctionSetGuardian] - case core.BuiltInFunctionGuardAccount: - return gasSchedule[common.BuiltInCost][core.BuiltInFunctionGuardAccount] - case core.BuiltInFunctionUnGuardAccount: - return gasSchedule[common.BuiltInCost][core.BuiltInFunctionUnGuardAccount] - default: - return 0 - } -} - -func (gfp *gasUsedAndFeeProcessor) isGuardianOperation(tx *transaction.ApiTransactionResult) bool { - return tx.Operation == core.BuiltInFunctionSetGuardian || - tx.Operation == core.BuiltInFunctionGuardAccount || - tx.Operation == core.BuiltInFunctionUnGuardAccount -} - func (gfp *gasUsedAndFeeProcessor) prepareTxWithResultsBasedOnLogs( tx *transaction.ApiTransactionResult, hasRefund bool, diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go index f6af8464428..d5340e7903c 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go @@ -40,7 +40,6 @@ func TestComputeTransactionGasUsedAndFeeMoveBalance(t *testing.T) { gasUsedAndFeeProc := newGasUsedAndFeeProcessor( computer, - &testscommon.GasScheduleNotifierMock{}, pubKeyConverter, &testscommon.ArgumentParserMock{}, &testscommon.MarshallerStub{}, @@ -77,7 +76,6 @@ func TestComputeTransactionGasUsedAndFeeLogWithError(t *testing.T) { gasUsedAndFeeProc := newGasUsedAndFeeProcessor( computer, - &testscommon.GasScheduleNotifierMock{}, pubKeyConverter, &testscommon.ArgumentParserMock{}, &testscommon.MarshallerStub{}, @@ -127,7 +125,6 @@ func TestComputeTransactionGasUsedAndFeeRelayedTxWithWriteLog(t *testing.T) { gasUsedAndFeeProc := newGasUsedAndFeeProcessor( computer, - &testscommon.GasScheduleNotifierMock{}, pubKeyConverter, &testscommon.ArgumentParserMock{}, &testscommon.MarshallerStub{}, @@ -172,7 +169,6 @@ func TestComputeTransactionGasUsedAndFeeTransactionWithScrWithRefund(t *testing. gasUsedAndFeeProc := newGasUsedAndFeeProcessor( computer, - &testscommon.GasScheduleNotifierMock{}, pubKeyConverter, &testscommon.ArgumentParserMock{}, &testscommon.MarshallerStub{}, @@ -227,7 +223,6 @@ func TestNFTTransferWithScCall(t *testing.T) { gasUsedAndFeeProc := newGasUsedAndFeeProcessor( computer, - &testscommon.GasScheduleNotifierMock{}, pubKeyConverter, &testscommon.ArgumentParserMock{}, &testscommon.MarshallerStub{}, @@ -256,55 +251,3 @@ func TestNFTTransferWithScCall(t *testing.T) { req.Equal(uint64(55_000_000), tx.GasUsed) req.Equal("822250000000000", tx.Fee) } - -func TestComputeAndAttachGasUsedAndFeeSetGuardian(t *testing.T) { - t.Parallel() - - feeComp, err := fee.NewFeeComputer(createEconomicsData(&enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool { - return flag == common.GasPriceModifierFlag || flag == common.PenalizedTooMuchGasFlag - }, - })) - computer := fee.NewTestFeeComputer(feeComp) - require.NoError(t, err) - - gasSch := &testscommon.GasScheduleNotifierMock{ - GasSchedule: map[string]map[string]uint64{ - common.BuiltInCost: { - core.BuiltInFunctionSetGuardian: 250000, - }, - }, - } - - gasUsedAndFeeProc := newGasUsedAndFeeProcessor( - computer, - gasSch, - pubKeyConverter, - &testscommon.ArgumentParserMock{}, - &testscommon.MarshallerStub{}, - &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool { - return flag == common.FixRelayedBaseCostFlag - }, - }, - ) - - sender := "erd1wc3uh22g2aved3qeehkz9kzgrjwxhg9mkkxp2ee7jj7ph34p2csq0n2y5x" - - tx := &transaction.ApiTransactionResult{ - Tx: &transaction.Transaction{ - GasLimit: 475_500, - GasPrice: 1000000000, - SndAddr: silentDecodeAddress(sender), - RcvAddr: silentDecodeAddress(sender), - Data: []byte("SetGuardian@835741dd7018300bb4ed14211f9a9118ea7049572402c3a553deb1141f9c89aa@4d756c7469766572735854435353657276696365"), - }, - GasLimit: 475_500, - Operation: "SetGuardian", - GasPrice: 1000000000, - } - - gasUsedAndFeeProc.computeAndAttachGasUsedAndFee(tx) - require.Equal(t, uint64(475_500), tx.GasUsed) - require.Equal(t, "475500000000000", tx.Fee) -} diff --git a/node/external/transactionAPI/interface.go b/node/external/transactionAPI/interface.go index 77057e1de05..a32cac06184 100644 --- a/node/external/transactionAPI/interface.go +++ b/node/external/transactionAPI/interface.go @@ -12,7 +12,6 @@ type feeComputer interface { ComputeTxFeeBasedOnGasUsed(tx *transaction.ApiTransactionResult, gasUsed uint64) *big.Int ComputeGasLimit(tx *transaction.ApiTransactionResult) uint64 ComputeTransactionFee(tx *transaction.ApiTransactionResult) *big.Int - ComputeMoveBalanceFee(tx *transaction.ApiTransactionResult) *big.Int IsInterfaceNil() bool } diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index 61f87666d2d..cbeaea814be 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -141,20 +141,6 @@ func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *trans feeInfo.SetFee(initialPaidFee) } - res := tep.dataFieldParser.Parse(txHandler.GetData(), txHandler.GetSndAddr(), txHandler.GetRcvAddr(), tep.shardCoordinator.NumberOfShards()) - if tep.isGuardianOperation(res.Operation) && isFeeFixActive { - gasUsed = tep.txFeeCalculator.ComputeGasLimit(txHandler) - guardianOperationCost := tep.getGuardianOperationCost(res.Operation, epoch) - gasUsed += guardianOperationCost - feeInfo.SetGasUsed(gasUsed) - - fee = big.NewInt(0).SetUint64(gasUsed * txHandler.GetGasPrice()) - feeInfo.SetFee(fee) - feeInfo.SetInitialPaidFee(fee) - - return - } - if len(txHandler.GetUserTransactions()) > 0 { tep.prepareRelayedTxV3WithResults(txHashHex, txWithResult) continue @@ -257,30 +243,6 @@ func (tep *transactionsFeeProcessor) handleRelayedV2(args [][]byte, tx *transact return big.NewInt(0).Add(fee, innerFee), true } -func (tep *transactionsFeeProcessor) getGuardianOperationCost(operation string, epoch uint32) uint64 { - gasSchedule, err := tep.gasScheduleNotifier.GasScheduleForEpoch(epoch) - if err != nil { - return 0 - } - - switch operation { - case core.BuiltInFunctionSetGuardian: - return gasSchedule[common.BuiltInCost][core.BuiltInFunctionSetGuardian] - case core.BuiltInFunctionGuardAccount: - return gasSchedule[common.BuiltInCost][core.BuiltInFunctionGuardAccount] - case core.BuiltInFunctionUnGuardAccount: - return gasSchedule[common.BuiltInCost][core.BuiltInFunctionUnGuardAccount] - default: - return 0 - } -} - -func (tep *transactionsFeeProcessor) isGuardianOperation(operation string) bool { - return operation == core.BuiltInFunctionSetGuardian || - operation == core.BuiltInFunctionGuardAccount || - operation == core.BuiltInFunctionUnGuardAccount -} - func (tep *transactionsFeeProcessor) prepareRelayedTxV3WithResults(txHashHex string, txWithResults *transactionWithResults) { refundsValue := big.NewInt(0) for _, scrHandler := range txWithResults.scrs { diff --git a/process/interface.go b/process/interface.go index e1c81fa6f96..8e943d0a44e 100644 --- a/process/interface.go +++ b/process/interface.go @@ -680,7 +680,6 @@ type feeHandler interface { MaxGasLimitPerTx() uint64 ComputeGasLimit(tx data.TransactionWithFeeHandler) uint64 ComputeMoveBalanceFee(tx data.TransactionWithFeeHandler) *big.Int - ComputeMoveBalanceFeeInEpoch(tx data.TransactionWithFeeHandler, epoch uint32) *big.Int ComputeTxFee(tx data.TransactionWithFeeHandler) *big.Int CheckValidityTxValues(tx data.TransactionWithFeeHandler) error ComputeFeeForProcessing(tx data.TransactionWithFeeHandler, gasToUse uint64) *big.Int diff --git a/testscommon/gasScheduleNotifierMock.go b/testscommon/gasScheduleNotifierMock.go index e7894c25e40..dd0f728cfad 100644 --- a/testscommon/gasScheduleNotifierMock.go +++ b/testscommon/gasScheduleNotifierMock.go @@ -8,7 +8,6 @@ type GasScheduleNotifierMock struct { RegisterNotifyHandlerCalled func(handler core.GasScheduleSubscribeHandler) LatestGasScheduleCalled func() map[string]map[string]uint64 LatestGasScheduleCopyCalled func() map[string]map[string]uint64 - GasScheduleForEpochCalled func(epoch uint32) (map[string]map[string]uint64, error) } // NewGasScheduleNotifierMock - @@ -51,15 +50,6 @@ func (g *GasScheduleNotifierMock) LatestGasScheduleCopy() map[string]map[string] func (g *GasScheduleNotifierMock) UnRegisterAll() { } -// GasScheduleForEpoch - -func (g *GasScheduleNotifierMock) GasScheduleForEpoch(epoch uint32) (map[string]map[string]uint64, error) { - if g.GasScheduleForEpochCalled != nil { - return g.GasScheduleForEpochCalled(epoch) - } - - return g.GasSchedule, nil -} - // IsInterfaceNil - func (g *GasScheduleNotifierMock) IsInterfaceNil() bool { return g == nil From fc273728c0ceeb498b5732b8aaf3b297499e529d Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 13 Aug 2024 20:04:39 +0300 Subject: [PATCH 500/503] further reverts --- factory/processing/blockProcessorCreator.go | 1 - outport/process/factory/check_test.go | 1 - outport/process/factory/outportDataProviderFactory.go | 2 -- outport/process/outportDataProvider_test.go | 1 - outport/process/transactionsfee/transactionsFeeProcessor.go | 6 ------ .../transactionsfee/transactionsFeeProcessor_test.go | 6 ------ 6 files changed, 17 deletions(-) diff --git a/factory/processing/blockProcessorCreator.go b/factory/processing/blockProcessorCreator.go index f4ee93124a2..93f3e1e95a3 100644 --- a/factory/processing/blockProcessorCreator.go +++ b/factory/processing/blockProcessorCreator.go @@ -1052,7 +1052,6 @@ func (pcf *processComponentsFactory) createOutportDataProvider( MbsStorer: mbsStorer, EnableEpochsHandler: pcf.coreData.EnableEpochsHandler(), ExecutionOrderGetter: pcf.txExecutionOrderHandler, - GasScheduleNotifier: pcf.gasSchedule, }) } diff --git a/outport/process/factory/check_test.go b/outport/process/factory/check_test.go index 67b9a91b7dc..513a3c7305b 100644 --- a/outport/process/factory/check_test.go +++ b/outport/process/factory/check_test.go @@ -34,7 +34,6 @@ func createArgOutportDataProviderFactory() ArgOutportDataProviderFactory { MbsStorer: &genericMocks.StorerMock{}, EnableEpochsHandler: &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, ExecutionOrderGetter: &commonMocks.TxExecutionOrderHandlerStub{}, - GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, } } diff --git a/outport/process/factory/outportDataProviderFactory.go b/outport/process/factory/outportDataProviderFactory.go index c57f2a09282..5bb2c698136 100644 --- a/outport/process/factory/outportDataProviderFactory.go +++ b/outport/process/factory/outportDataProviderFactory.go @@ -37,7 +37,6 @@ type ArgOutportDataProviderFactory struct { MbsStorer storage.Storer EnableEpochsHandler common.EnableEpochsHandler ExecutionOrderGetter common.ExecutionOrderGetter - GasScheduleNotifier core.GasScheduleNotifier } // CreateOutportDataProvider will create a new instance of outport.DataProviderOutport @@ -68,7 +67,6 @@ func CreateOutportDataProvider(arg ArgOutportDataProviderFactory) (outport.DataP TxFeeCalculator: arg.EconomicsData, PubKeyConverter: arg.AddressConverter, ArgsParser: smartContract.NewArgumentParser(), - GasScheduleNotifier: arg.GasScheduleNotifier, EnableEpochsHandler: arg.EnableEpochsHandler, }) if err != nil { diff --git a/outport/process/outportDataProvider_test.go b/outport/process/outportDataProvider_test.go index 96527e6404a..ef1422d230a 100644 --- a/outport/process/outportDataProvider_test.go +++ b/outport/process/outportDataProvider_test.go @@ -31,7 +31,6 @@ func createArgOutportDataProvider() ArgOutportDataProvider { ShardCoordinator: &testscommon.ShardsCoordinatorMock{}, TxFeeCalculator: &mock.EconomicsHandlerMock{}, ArgsParser: &testscommon.ArgumentParserMock{}, - GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), }) diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index cbeaea814be..ffad67ee22f 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -27,7 +27,6 @@ type ArgTransactionsFeeProcessor struct { ShardCoordinator sharding.Coordinator TxFeeCalculator FeesProcessorHandler PubKeyConverter core.PubkeyConverter - GasScheduleNotifier core.GasScheduleNotifier ArgsParser process.ArgumentsParser EnableEpochsHandler common.EnableEpochsHandler } @@ -39,7 +38,6 @@ type transactionsFeeProcessor struct { dataFieldParser dataFieldParser log logger.Logger marshaller marshal.Marshalizer - gasScheduleNotifier core.GasScheduleNotifier argsParser process.ArgumentsParser enableEpochsHandler common.EnableEpochsHandler } @@ -66,7 +64,6 @@ func NewTransactionsFeeProcessor(arg ArgTransactionsFeeProcessor) (*transactions log: logger.GetOrCreate(loggerName), dataFieldParser: parser, marshaller: arg.Marshaller, - gasScheduleNotifier: arg.GasScheduleNotifier, argsParser: arg.ArgsParser, enableEpochsHandler: arg.EnableEpochsHandler, }, nil @@ -91,9 +88,6 @@ func checkArg(arg ArgTransactionsFeeProcessor) error { if check.IfNil(arg.ArgsParser) { return process.ErrNilArgumentParser } - if check.IfNil(arg.GasScheduleNotifier) { - return process.ErrNilGasSchedule - } if check.IfNil(arg.EnableEpochsHandler) { return process.ErrNilEnableEpochsHandler } diff --git a/outport/process/transactionsfee/transactionsFeeProcessor_test.go b/outport/process/transactionsfee/transactionsFeeProcessor_test.go index b3bda2cc9c9..6f0e0f94c35 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor_test.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor_test.go @@ -30,7 +30,6 @@ func prepareMockArg() ArgTransactionsFeeProcessor { TxFeeCalculator: &mock.EconomicsHandlerMock{}, PubKeyConverter: pubKeyConverter, ArgsParser: &testscommon.ArgumentParserMock{}, - GasScheduleNotifier: &testscommon.GasScheduleNotifierMock{}, EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), } } @@ -63,11 +62,6 @@ func TestNewTransactionFeeProcessor(t *testing.T) { _, err = NewTransactionsFeeProcessor(arg) require.Equal(t, process.ErrNilArgumentParser, err) - arg = prepareMockArg() - arg.GasScheduleNotifier = nil - _, err = NewTransactionsFeeProcessor(arg) - require.Equal(t, process.ErrNilGasSchedule, err) - arg = prepareMockArg() arg.EnableEpochsHandler = nil _, err = NewTransactionsFeeProcessor(arg) From cab29d2fbe34b15275106991855e97e376de8345 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 14 Aug 2024 18:16:11 +0300 Subject: [PATCH 501/503] switch log level --- process/block/preprocess/transactionsV2.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/process/block/preprocess/transactionsV2.go b/process/block/preprocess/transactionsV2.go index 654ff4231a8..6391987983a 100644 --- a/process/block/preprocess/transactionsV2.go +++ b/process/block/preprocess/transactionsV2.go @@ -218,7 +218,7 @@ func (txs *transactions) processTransaction( } if errors.Is(err, process.ErrFailedTransaction) { - log.Debug("transactions.processTransaction", + log.Trace("transactions.processTransaction", "txHash", txHash, "nonce", tx.Nonce, "value", tx.Value, From 6cec9edf3d3e7380c2f41eb39f6ece5ae9981459 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 19 Aug 2024 09:52:26 +0300 Subject: [PATCH 502/503] fix test after merge --- node/external/transactionAPI/apiTransactionProcessor_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/node/external/transactionAPI/apiTransactionProcessor_test.go b/node/external/transactionAPI/apiTransactionProcessor_test.go index 204c123decc..e6a7040fe87 100644 --- a/node/external/transactionAPI/apiTransactionProcessor_test.go +++ b/node/external/transactionAPI/apiTransactionProcessor_test.go @@ -360,6 +360,8 @@ func TestNode_GetSCRs(t *testing.T) { return &datafield.ResponseParseData{} }, }, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + TxMarshaller: &mock.MarshalizerFake{}, } apiTransactionProc, _ := NewAPITransactionProcessor(args) From 0123471c9682912859ffda012304b067dcea77f4 Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 19 Aug 2024 10:23:55 +0300 Subject: [PATCH 503/503] latest indexer version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c6b99bc0214..49f55d1e0b4 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/multiversx/mx-chain-communication-go v1.1.0 github.com/multiversx/mx-chain-core-go v1.2.21 github.com/multiversx/mx-chain-crypto-go v1.2.12 - github.com/multiversx/mx-chain-es-indexer-go v1.7.4 + github.com/multiversx/mx-chain-es-indexer-go v1.7.5-0.20240807095116-4f2f595e52d9 github.com/multiversx/mx-chain-logger-go v1.0.15 github.com/multiversx/mx-chain-scenario-go v1.4.4 github.com/multiversx/mx-chain-storage-go v1.0.16 diff --git a/go.sum b/go.sum index d8ed7091831..00b1197adc8 100644 --- a/go.sum +++ b/go.sum @@ -391,8 +391,8 @@ github.com/multiversx/mx-chain-core-go v1.2.21 h1:+XVKznPTlUU5EFS1A8chtS8fStW60u github.com/multiversx/mx-chain-core-go v1.2.21/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.4 h1:SjJk9G9SN8baz0sFIU2jymYCfx3XiikGEB2wW0jwvfw= -github.com/multiversx/mx-chain-es-indexer-go v1.7.4/go.mod h1:oGcRK2E3Syv6vRTszWrrb/TqD8akq0yeoMr1wPPiTO4= +github.com/multiversx/mx-chain-es-indexer-go v1.7.5-0.20240807095116-4f2f595e52d9 h1:VJOigTM9JbjFdy9ICVhsDfM9YQkFqMigAaQCHaM0iwY= +github.com/multiversx/mx-chain-es-indexer-go v1.7.5-0.20240807095116-4f2f595e52d9/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=