From 18e8d700d2bec46c3aaef4999ebc625cd24e5212 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 8 Sep 2023 15:06:17 +0300 Subject: [PATCH 001/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] 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/434] - 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/434] 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/434] 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/434] 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/434] - 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 45dd9dba37c8711411ceb52d179a4e943dfd4e1b Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 19 Feb 2024 18:41:57 +0200 Subject: [PATCH 059/434] 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 060/434] 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 061/434] 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 062/434] 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 063/434] 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 064/434] 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 065/434] 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 066/434] 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 067/434] 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 068/434] 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 069/434] 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 070/434] 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 071/434] 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 072/434] 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 073/434] 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 074/434] 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 075/434] 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 076/434] 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 077/434] 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 078/434] 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 079/434] 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 080/434] 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 081/434] 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 082/434] 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 083/434] 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 084/434] 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 085/434] 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 8c50313934ecf13cd2fd9c20a20252e8801c278b Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 21 Mar 2024 17:39:12 +0200 Subject: [PATCH 086/434] 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 087/434] 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 088/434] 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 2afa2568370fd7c818e561316f6596fca4d42d25 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 22 Mar 2024 15:10:12 +0200 Subject: [PATCH 089/434] 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 9ff5a6970be5438cb06aaf4a0db48b9a04e45582 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Thu, 28 Mar 2024 12:11:47 +0200 Subject: [PATCH 090/434] 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 5afe305f43530adfb5bf98a31a6fa37f4dc467ae Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Fri, 12 Apr 2024 12:13:48 +0300 Subject: [PATCH 091/434] 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 ec0a7251a631c5283b8c85a9b877a9edb58d0bcc Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Fri, 12 Apr 2024 13:23:07 +0300 Subject: [PATCH 092/434] 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 093/434] 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 a67343ddd00bba279ae921ae98a9165ccce15692 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Fri, 12 Apr 2024 18:00:58 +0300 Subject: [PATCH 094/434] 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 095/434] 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 096/434] 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 097/434] 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 098/434] 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 10411000c3fd12ceba2da7dcabc180b9d38a3f7e Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Tue, 16 Apr 2024 18:59:13 +0300 Subject: [PATCH 099/434] 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 7111b29e1445d5ea2f2fe155a9d62d4b0efdcbbc Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 24 Apr 2024 11:03:36 +0300 Subject: [PATCH 100/434] 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 101/434] 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 102/434] 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 103/434] 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 104/434] 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 105/434] 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 106/434] 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 107/434] 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 108/434] 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 109/434] 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 110/434] 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 111/434] 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 7149419bb9017fdfbd10f7f684887b371ff90f8d Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 25 Apr 2024 11:13:17 +0300 Subject: [PATCH 112/434] 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 113/434] 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 114/434] 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 115/434] 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 116/434] 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 b7e2c6064fad3db946538e735709c02b8f733249 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Fri, 26 Apr 2024 17:09:33 +0300 Subject: [PATCH 117/434] 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 118/434] 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 119/434] 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 120/434] 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 121/434] 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 122/434] 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 123/434] 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 124/434] 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 125/434] 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 126/434] 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 127/434] 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 128/434] 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 129/434] 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 018804eac62b259aef7a9bc010a5c30b40483002 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Mon, 13 May 2024 11:51:33 +0300 Subject: [PATCH 130/434] 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 131/434] 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 132/434] 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 133/434] 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 134/434] 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 135/434] 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 136/434] 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 2bb0754624ee0f216878c5472a478242cb736ee4 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 15 May 2024 11:54:41 +0300 Subject: [PATCH 137/434] 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 637df8da91fe4fa9184467285f6558df78060660 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 15 May 2024 18:15:00 +0300 Subject: [PATCH 138/434] 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 139/434] 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 140/434] 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 141/434] 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 142/434] 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 143/434] 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 144/434] 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 145/434] 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 1786b4fa335070d03fdaef801e099a8f7dc3a531 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 20 May 2024 11:00:40 +0300 Subject: [PATCH 146/434] - 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 147/434] 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 148/434] - 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 149/434] 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 150/434] 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 8632cc58efe2d269e80f309e5ec2ab2d7a9e152b Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 21 May 2024 17:34:55 +0300 Subject: [PATCH 151/434] 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 152/434] 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 9cede459c8285400b89090e2a7137a7221f9db6d Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 22 May 2024 13:10:51 +0300 Subject: [PATCH 153/434] 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 154/434] 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 155/434] 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 156/434] 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 157/434] 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 158/434] 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 159/434] 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 160/434] 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 161/434] 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 162/434] 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 163/434] 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 164/434] 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 165/434] 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 166/434] 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 167/434] 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 168/434] 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 169/434] 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 170/434] 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 171/434] 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 172/434] 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 173/434] 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 174/434] 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 175/434] 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 176/434] 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 177/434] 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 178/434] 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 179/434] 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 180/434] 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 181/434] 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 182/434] 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 183/434] 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 184/434] 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 185/434] 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 186/434] 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 187/434] 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 188/434] 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 189/434] 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 190/434] 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 191/434] 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 192/434] 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 193/434] 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 194/434] 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 195/434] 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 196/434] 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 197/434] 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 198/434] 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 199/434] 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 200/434] 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 201/434] 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 202/434] 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 203/434] 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 204/434] 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 205/434] 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 206/434] 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 207/434] 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 208/434] 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 209/434] 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 210/434] 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 211/434] 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 212/434] 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 213/434] 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 214/434] 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 215/434] 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 216/434] 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 217/434] 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 218/434] 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 219/434] 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 220/434] 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 221/434] 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 222/434] 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 223/434] 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 224/434] 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 225/434] 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 226/434] 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 227/434] 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 228/434] 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 229/434] 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 230/434] 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 231/434] 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 232/434] 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 233/434] 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 234/434] 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 235/434] 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 236/434] 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 237/434] 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 238/434] 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 239/434] 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 240/434] 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 241/434] 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 242/434] 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 243/434] 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 244/434] 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 245/434] 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 246/434] 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 8443b80b748ce687609cde68863d4d3b6fc3e4fc Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 19 Jun 2024 14:34:19 +0300 Subject: [PATCH 247/434] 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 248/434] 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 249/434] 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 250/434] 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 251/434] 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 252/434] 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 2052fc290bb610362c55773f859c3235ff11d79f Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 19 Jun 2024 16:26:38 +0300 Subject: [PATCH 253/434] 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 254/434] 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 255/434] 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 256/434] 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 257/434] 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 258/434] 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 259/434] 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 260/434] 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 261/434] 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 fb89c15755dbc163497c3a56538cc0b1e649d54a Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 25 Jun 2024 14:57:27 +0300 Subject: [PATCH 262/434] 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 263/434] 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 264/434] 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 c3344d8c17e056393ba867ca1d87d67c29218996 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 25 Jun 2024 19:39:44 +0300 Subject: [PATCH 265/434] 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 266/434] 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 c2bf800d348ecc355a0cdd74a58303eaf54060c4 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 26 Jun 2024 14:29:58 +0300 Subject: [PATCH 267/434] 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 268/434] 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 269/434] 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 270/434] 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 271/434] 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 272/434] 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 273/434] 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 274/434] 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 275/434] 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 276/434] 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 277/434] 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 278/434] 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 279/434] 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 280/434] 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 281/434] 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 282/434] 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 283/434] 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 284/434] 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 285/434] 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 286/434] 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 287/434] 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 288/434] 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 289/434] 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 290/434] 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 291/434] 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 292/434] 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 293/434] 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 294/434] 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 295/434] 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 296/434] 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 297/434] 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 298/434] 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 299/434] 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 300/434] 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 301/434] 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 302/434] 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 303/434] 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 304/434] 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 305/434] 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 306/434] 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 307/434] 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 308/434] 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 309/434] 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 310/434] 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 311/434] 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 312/434] 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 313/434] 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 314/434] 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 315/434] 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 316/434] 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 317/434] 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 318/434] 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 319/434] 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 320/434] 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 321/434] 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 322/434] 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 323/434] 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 324/434] 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 325/434] 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 326/434] 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 327/434] 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 328/434] 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 329/434] 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 330/434] 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 331/434] 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 332/434] 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 333/434] 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 334/434] 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 335/434] 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 336/434] 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 337/434] 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 338/434] 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 339/434] 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 340/434] 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 341/434] 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 1eefd6f27f7ad5128685f950b9bc9b8f4656b802 Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 31 Jul 2024 11:56:38 +0300 Subject: [PATCH 342/434] 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 343/434] 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 344/434] 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 345/434] 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 346/434] 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 3da197f2075c0b009398332a559da4704f08f74e Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 1 Aug 2024 14:07:24 +0300 Subject: [PATCH 347/434] 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 348/434] 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 349/434] 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 350/434] 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 351/434] 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 352/434] 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 353/434] 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 354/434] 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 d8f0a125205466cacd00a5ba20cadf4f1da7590d Mon Sep 17 00:00:00 2001 From: python-qa Date: Tue, 6 Aug 2024 10:11:03 +0300 Subject: [PATCH 355/434] 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 356/434] 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 357/434] 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 358/434] 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 359/434] 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 360/434] 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 361/434] 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 362/434] 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 363/434] 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 364/434] 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 365/434] 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 366/434] 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 367/434] 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 368/434] 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 369/434] 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 370/434] 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 371/434] 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 372/434] 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 373/434] 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 374/434] 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 375/434] 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 376/434] 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 377/434] 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 378/434] 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 379/434] 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 380/434] 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 381/434] 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 382/434] 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= From 290d028e7aeea37da99b725533079c8771667782 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 20 Aug 2024 10:05:10 +0300 Subject: [PATCH 383/434] new VM after merge --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index c6b99bc0214..28b3fde7ecd 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.14-0.20240812082318-afa839968da3 - github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240812082514-1f3c25b3171e + github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240820061342-7527911e28ac 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 d8ed7091831..15a316a964c 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.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-go v1.5.32-0.20240820061342-7527911e28ac h1:hf6BZxtkI0mhXbKnaCKYnD6vSxjLVnfhoy1b634T0TE= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240820061342-7527911e28ac/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 aa22dd216ed070d23e76f3dde7be08f8a69e9476 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 21 Aug 2024 13:50:20 +0300 Subject: [PATCH 384/434] new VM after merge --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index d0ce340fe1e..7f65b32114a 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.14-0.20240812082318-afa839968da3 - github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240820061342-7527911e28ac + github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240821104654-483a1cfdfc69 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 ad104f86de3..71cb103a90f 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.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.20240820061342-7527911e28ac h1:hf6BZxtkI0mhXbKnaCKYnD6vSxjLVnfhoy1b634T0TE= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240820061342-7527911e28ac/go.mod h1:j9FBeftA/BKfn0BbndKV7bNFJAzwCnYZuebsM/sufK0= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240821104654-483a1cfdfc69 h1:HoyZbjYuQLVHJ8UMOkoIyKLA/jq80kbb3Gbqe2AfuPM= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240821104654-483a1cfdfc69/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 d391df9a37aff59444fe0a80b9b2f45cb2bfaf50 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Sat, 24 Aug 2024 15:35:06 +0300 Subject: [PATCH 385/434] update go mod and tests --- go.mod | 4 +- go.sum | 8 +-- .../vm/esdtImprovements_test.go | 58 ++++++++----------- .../vm/txsFee/apiTransactionEvaluator_test.go | 4 +- .../vm/txsFee/asyncCall_multi_test.go | 5 +- integrationTests/vm/txsFee/asyncESDT_test.go | 16 ++--- .../vm/txsFee/esdtLocalBurn_test.go | 2 +- .../vm/txsFee/esdtLocalMint_test.go | 2 +- .../vm/txsFee/esdtMetaDataRecreate_test.go | 6 +- .../vm/txsFee/esdtMetaDataUpdate_test.go | 6 +- .../vm/txsFee/esdtModifyCreator_test.go | 8 ++- .../vm/txsFee/esdtModifyRoyalties_test.go | 8 ++- .../vm/txsFee/esdtSetNewURIs_test.go | 8 ++- integrationTests/vm/txsFee/esdt_test.go | 8 +-- .../vm/txsFee/multiESDTTransfer_test.go | 9 +-- .../vm/txsFee/multiShard/asyncESDT_test.go | 5 +- .../txsFee/multiShard/esdtLiquidity_test.go | 6 +- .../vm/txsFee/multiShard/esdt_test.go | 6 +- .../vm/txsFee/relayedAsyncESDT_test.go | 7 ++- .../vm/txsFee/relayedESDT_test.go | 5 +- integrationTests/vm/txsFee/scCalls_test.go | 2 +- integrationTests/vm/txsFee/utils/utilsESDT.go | 5 +- 22 files changed, 107 insertions(+), 81 deletions(-) diff --git a/go.mod b/go.mod index c6b99bc0214..5f648904813 100644 --- a/go.mod +++ b/go.mod @@ -15,13 +15,13 @@ 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 + github.com/multiversx/mx-chain-core-go v1.2.22-0.20240823091930-22b700471ada 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.14-0.20240812082318-afa839968da3 + github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240824090826-0159b7bb576f 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 diff --git a/go.sum b/go.sum index d8ed7091831..e6d78cf7129 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 h1:+XVKznPTlUU5EFS1A8chtS8fStW60upRIyF4Pgml19I= -github.com/multiversx/mx-chain-core-go v1.2.21/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.22-0.20240823091930-22b700471ada h1:Yi4gpXr/LzpLR2Soca5SNC/NRGnPCrD5FyGKShGLFpE= +github.com/multiversx/mx-chain-core-go v1.2.22-0.20240823091930-22b700471ada/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= @@ -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.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-common-go v1.5.14-0.20240824090826-0159b7bb576f h1:sJupgH9e7xZCHp53COO6eWrdoTUQqaiddnhb9IzUh0A= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240824090826-0159b7bb576f/go.mod h1:sN471lwUKZMIfhNEDgHnSUR5SOv+BCoxF2kv2AnOCj8= 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= diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 5ef014f6b65..dbb98384825 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -1482,7 +1482,12 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) - retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID) + retrievedMetaData := &esdt.MetaData{} + if bytes.Equal(tokenIDs[i], nftTokenID) { + retrievedMetaData = getMetaDataFromAcc(t, cs, newCreatorAddress.Bytes, tokenIDs[i], shardID) + } else { + retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID) + } require.Equal(t, newCreatorAddress.Bytes, retrievedMetaData.Creator) } @@ -1695,8 +1700,13 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { require.Equal(t, "success", txResult.Status.String()) + retrievedMetaData := &esdt.MetaData{} shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(newCreatorAddress.Bytes) - retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID) + if bytes.Equal(tokenIDs[i], nftTokenID) { + retrievedMetaData = getMetaDataFromAcc(t, cs, newCreatorAddress.Bytes, tokenIDs[i], shardID) + } else { + retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID) + } require.Equal(t, newCreatorAddress.Bytes, retrievedMetaData.Creator) @@ -2504,7 +2514,8 @@ func TestChainSimulator_NFT_RegisterDynamic(t *testing.T) { shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + checkMetaData(t, cs, addrs[0].Bytes, nftTokenID, shardID, nftMetaData) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) log.Info("Check that token type is Dynamic") @@ -2747,7 +2758,8 @@ func TestChainSimulator_NFT_RegisterAndSetAllRolesDynamic(t *testing.T) { shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + checkMetaData(t, cs, addrs[0].Bytes, nftTokenID, shardID, nftMetaData) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) log.Info("Check that token type is Dynamic") @@ -3789,11 +3801,12 @@ func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(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("Step 1. check that the metadata for the Dynamic NFT is saved on the user account") shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + checkMetaData(t, cs, addrs[0].Bytes, nftTokenID, shardID, nftMetaData) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) log.Info("Step 1b. Pause all tokens") @@ -3809,34 +3822,13 @@ func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(t *testing.T) { require.Equal(t, "", result.ReturnMessage) require.Equal(t, testsChainSimulator.OkReturnCode, result.ReturnCode) - tx = updateTokenIDTx(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()) - - log.Info("change to dynamic token") - - 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()) - - log.Info("check that the metadata for all tokens is saved on the system account") + log.Info("check that the metadata for the Dynamic NFT is saved on the user account") err = cs.GenerateBlocks(10) require.Nil(t, err) - checkMetaData(t, cs, core.SystemAccountAddress, nftTokenID, shardID, nftMetaData) + checkMetaData(t, cs, addrs[0].Bytes, nftTokenID, shardID, nftMetaData) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, nftTokenID, shardID) log.Info("transfering token id", "tokenID", nftTokenID) @@ -3846,16 +3838,16 @@ func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(t *testing.T) { require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - log.Info("check that the metaData for the NFT is still on the system account") + log.Info("check that the metaData for the NFT is on the new user account") err = cs.GenerateBlocks(10) require.Nil(t, err) shardID = cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[2].Bytes) - 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) } func TestChainSimulator_CheckRolesWhichHasToBeSingular(t *testing.T) { diff --git a/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go b/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go index 8f3894aa319..4c66bf28f52 100644 --- a/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go +++ b/integrationTests/vm/txsFee/apiTransactionEvaluator_test.go @@ -142,7 +142,7 @@ func TestESDTTransfer(t *testing.T) { egldBalance := big.NewInt(100000000) esdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) tx := utils.CreateESDTTransferTx(0, sndAddr, rcvAddr, token, big.NewInt(100), 0, 0) res, err := testContext.TxCostHandler.ComputeTransactionGasLimit(tx) @@ -170,7 +170,7 @@ func TestAsyncESDTTransfer(t *testing.T) { esdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) // deploy 2 contracts ownerAccount, _ := testContext.Accounts.LoadAccount(ownerAddr) diff --git a/integrationTests/vm/txsFee/asyncCall_multi_test.go b/integrationTests/vm/txsFee/asyncCall_multi_test.go index 56a6dc02a26..ef14b5556a3 100644 --- a/integrationTests/vm/txsFee/asyncCall_multi_test.go +++ b/integrationTests/vm/txsFee/asyncCall_multi_test.go @@ -5,6 +5,7 @@ import ( "math/big" "testing" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/scheduled" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/vm" @@ -276,7 +277,7 @@ func deployForwarderAndTestContract( forwarderSCAddress := utils.DoDeploySecond(t, testContext, pathToForwarder, ownerAccount, gasPrice, deployGasLimit, nil, big.NewInt(0)) - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, forwarderSCAddress, egldBalance, esdtToken, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, forwarderSCAddress, egldBalance, esdtToken, 0, esdtBalance, uint32(core.Fungible)) utils.CleanAccumulatedIntermediateTransactions(t, testContext) @@ -514,7 +515,7 @@ func transferESDTAndExecuteCrossShard(t *testing.T, numberOfCallsFromParent int, pathToContract = "testdata/forwarderQueue/forwarder-queue-promises.wasm" forwarderSCAddress := utils.DoDeploySecond(t, forwarderShard, pathToContract, forwarderOwnerAccount, gasPrice, gasLimit, nil, big.NewInt(0)) - utils.CreateAccountWithESDTBalance(t, forwarderShard.Accounts, forwarderSCAddress, egldBalance, esdtToken, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, forwarderShard.Accounts, forwarderSCAddress, egldBalance, esdtToken, 0, esdtBalance, uint32(core.Fungible)) utils.CheckESDTNFTBalance(t, forwarderShard, forwarderSCAddress, esdtToken, 0, esdtBalance) diff --git a/integrationTests/vm/txsFee/asyncESDT_test.go b/integrationTests/vm/txsFee/asyncESDT_test.go index c7c8d088fb9..32869f51ae9 100644 --- a/integrationTests/vm/txsFee/asyncESDT_test.go +++ b/integrationTests/vm/txsFee/asyncESDT_test.go @@ -40,7 +40,7 @@ func TestAsyncESDTCallShouldWork(t *testing.T) { localEsdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, localEgldBalance, token, 0, localEsdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, localEgldBalance, token, 0, localEsdtBalance, uint32(core.Fungible)) // deploy 2 contracts ownerAccount, _ := testContext.Accounts.LoadAccount(ownerAddr) @@ -96,7 +96,7 @@ func TestAsyncESDTCallSecondScRefusesPayment(t *testing.T) { localEsdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, localEgldBalance, token, 0, localEsdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, localEgldBalance, token, 0, localEsdtBalance, uint32(core.Fungible)) // deploy 2 contracts ownerAccount, _ := testContext.Accounts.LoadAccount(ownerAddr) @@ -153,7 +153,7 @@ func TestAsyncESDTCallsOutOfGas(t *testing.T) { localEsdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, localEgldBalance, token, 0, localEsdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, localEgldBalance, token, 0, localEsdtBalance, uint32(core.Fungible)) // deploy 2 contracts ownerAccount, _ := testContext.Accounts.LoadAccount(ownerAddr) @@ -208,7 +208,7 @@ func TestAsyncMultiTransferOnCallback(t *testing.T) { sftBalance := big.NewInt(1000) halfBalance := big.NewInt(500) - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, ownerAddr, big.NewInt(1000000000), sftTokenID, sftNonce, sftBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, ownerAddr, big.NewInt(1000000000), sftTokenID, sftNonce, sftBalance, uint32(core.SemiFungible)) utils.CheckESDTNFTBalance(t, testContext, ownerAddr, sftTokenID, sftNonce, sftBalance) ownerAccount, _ := testContext.Accounts.LoadAccount(ownerAddr) @@ -305,7 +305,7 @@ func TestAsyncMultiTransferOnCallAndOnCallback(t *testing.T) { sftBalance := big.NewInt(1000) halfBalance := big.NewInt(500) - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, ownerAddr, big.NewInt(1000000000), sftTokenID, sftNonce, sftBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, ownerAddr, big.NewInt(1000000000), sftTokenID, sftNonce, sftBalance, uint32(core.SemiFungible)) utils.CheckESDTNFTBalance(t, testContext, ownerAddr, sftTokenID, sftNonce, sftBalance) ownerAccount, _ := testContext.Accounts.LoadAccount(ownerAddr) @@ -408,7 +408,7 @@ func TestSendNFTToContractWith0Function(t *testing.T) { sftNonce := uint64(1) sftBalance := big.NewInt(1000) - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, ownerAddr, big.NewInt(1000000000), sftTokenID, sftNonce, sftBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, ownerAddr, big.NewInt(1000000000), sftTokenID, sftNonce, sftBalance, uint32(core.SemiFungible)) utils.CheckESDTNFTBalance(t, testContext, ownerAddr, sftTokenID, sftNonce, sftBalance) ownerAccount, _ := testContext.Accounts.LoadAccount(ownerAddr) @@ -461,7 +461,7 @@ func TestSendNFTToContractWith0FunctionNonPayable(t *testing.T) { sftNonce := uint64(1) sftBalance := big.NewInt(1000) - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, ownerAddr, big.NewInt(1000000000), sftTokenID, sftNonce, sftBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, ownerAddr, big.NewInt(1000000000), sftTokenID, sftNonce, sftBalance, uint32(core.SemiFungible)) utils.CheckESDTNFTBalance(t, testContext, ownerAddr, sftTokenID, sftNonce, sftBalance) ownerAccount, _ := testContext.Accounts.LoadAccount(ownerAddr) @@ -523,7 +523,7 @@ func TestAsyncESDTCallForThirdContractShouldWork(t *testing.T) { localEsdtBalance := big.NewInt(100000000) esdtTransferValue := big.NewInt(5000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, localEgldBalance, token, 0, localEsdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, localEgldBalance, token, 0, localEsdtBalance, uint32(core.Fungible)) // deploy contract ownerAccount, _ := testContext.Accounts.LoadAccount(ownerAddr) diff --git a/integrationTests/vm/txsFee/esdtLocalBurn_test.go b/integrationTests/vm/txsFee/esdtLocalBurn_test.go index 681c7e293b4..77edb13d0e2 100644 --- a/integrationTests/vm/txsFee/esdtLocalBurn_test.go +++ b/integrationTests/vm/txsFee/esdtLocalBurn_test.go @@ -95,7 +95,7 @@ func TestESDTLocalBurnNotAllowedShouldErr(t *testing.T) { egldBalance := big.NewInt(100000000) esdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) gasLimit := uint64(40) tx := utils.CreateESDTLocalBurnTx(0, sndAddr, sndAddr, token, big.NewInt(100), gasPrice, gasLimit) diff --git a/integrationTests/vm/txsFee/esdtLocalMint_test.go b/integrationTests/vm/txsFee/esdtLocalMint_test.go index 516402c80a4..62d7bf5decf 100644 --- a/integrationTests/vm/txsFee/esdtLocalMint_test.go +++ b/integrationTests/vm/txsFee/esdtLocalMint_test.go @@ -61,7 +61,7 @@ func TestESDTLocalMintNotAllowedShouldErr(t *testing.T) { egldBalance := big.NewInt(100000000) esdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) gasLimit := uint64(40) tx := utils.CreateESDTLocalMintTx(0, sndAddr, sndAddr, token, big.NewInt(100), gasPrice, gasLimit) diff --git a/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go b/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go index d5778000cbe..e2dc58caf8f 100644 --- a/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go +++ b/integrationTests/vm/txsFee/esdtMetaDataRecreate_test.go @@ -64,7 +64,11 @@ func runEsdtMetaDataRecreateTest(t *testing.T, tokenType string) { _, err = testContext.Accounts.Commit() require.Nil(t, err) - checkMetaData(t, testContext, core.SystemAccountAddress, key, defaultMetaData) + if tokenType == core.DynamicNFTESDT { + checkMetaData(t, testContext, sndAddr, key, defaultMetaData) + } else { + checkMetaData(t, testContext, core.SystemAccountAddress, key, defaultMetaData) + } } func esdtMetaDataRecreateTx( diff --git a/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go b/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go index 4eba58ca178..d8fc6c7bb19 100644 --- a/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go +++ b/integrationTests/vm/txsFee/esdtMetaDataUpdate_test.go @@ -67,7 +67,11 @@ func runEsdtMetaDataUpdateTest(t *testing.T, tokenType string) { _, err = testContext.Accounts.Commit() require.Nil(t, err) - checkMetaData(t, testContext, core.SystemAccountAddress, key, defaultMetaData) + if tokenType == core.DynamicNFTESDT { + checkMetaData(t, testContext, sndAddr, key, defaultMetaData) + } else { + checkMetaData(t, testContext, core.SystemAccountAddress, key, defaultMetaData) + } } func esdtMetaDataUpdateTx( diff --git a/integrationTests/vm/txsFee/esdtModifyCreator_test.go b/integrationTests/vm/txsFee/esdtModifyCreator_test.go index 109e6e937e3..d12eb5186af 100644 --- a/integrationTests/vm/txsFee/esdtModifyCreator_test.go +++ b/integrationTests/vm/txsFee/esdtModifyCreator_test.go @@ -8,6 +8,7 @@ import ( "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/esdt" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/vm" @@ -69,7 +70,12 @@ func runEsdtModifyCreatorTest(t *testing.T, tokenType string) { _, err = testContext.Accounts.Commit() require.Nil(t, err) - retrievedMetaData := getMetaDataFromAcc(t, testContext, core.SystemAccountAddress, key) + retrievedMetaData := &esdt.MetaData{} + if tokenType == core.DynamicNFTESDT { + retrievedMetaData = getMetaDataFromAcc(t, testContext, newCreator, key) + } else { + retrievedMetaData = getMetaDataFromAcc(t, testContext, core.SystemAccountAddress, key) + } require.Equal(t, newCreator, retrievedMetaData.Creator) } diff --git a/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go b/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go index 9d6def6a297..151f1a62866 100644 --- a/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go +++ b/integrationTests/vm/txsFee/esdtModifyRoyalties_test.go @@ -8,6 +8,7 @@ import ( "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/esdt" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/vm" @@ -63,7 +64,12 @@ func runEsdtModifyRoyaltiesTest(t *testing.T, tokenType string) { _, err = testContext.Accounts.Commit() require.Nil(t, err) - retrievedMetaData := getMetaDataFromAcc(t, testContext, core.SystemAccountAddress, key) + retrievedMetaData := &esdt.MetaData{} + if tokenType == core.DynamicNFTESDT { + retrievedMetaData = getMetaDataFromAcc(t, testContext, creatorAddr, key) + } else { + retrievedMetaData = getMetaDataFromAcc(t, testContext, core.SystemAccountAddress, key) + } require.Equal(t, uint32(big.NewInt(20).Uint64()), retrievedMetaData.Royalties) } diff --git a/integrationTests/vm/txsFee/esdtSetNewURIs_test.go b/integrationTests/vm/txsFee/esdtSetNewURIs_test.go index f97e9e0e651..7c3500cd641 100644 --- a/integrationTests/vm/txsFee/esdtSetNewURIs_test.go +++ b/integrationTests/vm/txsFee/esdtSetNewURIs_test.go @@ -8,6 +8,7 @@ import ( "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/esdt" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/vm" @@ -64,7 +65,12 @@ func runEsdtSetNewURIsTest(t *testing.T, tokenType string) { _, err = testContext.Accounts.Commit() require.Nil(t, err) - retrievedMetaData := getMetaDataFromAcc(t, testContext, core.SystemAccountAddress, key) + retrievedMetaData := &esdt.MetaData{} + if tokenType == core.DynamicNFTESDT { + retrievedMetaData = getMetaDataFromAcc(t, testContext, sndAddr, key) + } else { + retrievedMetaData = getMetaDataFromAcc(t, testContext, core.SystemAccountAddress, key) + } require.Equal(t, [][]byte{[]byte("newUri1"), []byte("newUri2")}, retrievedMetaData.URIs) } diff --git a/integrationTests/vm/txsFee/esdt_test.go b/integrationTests/vm/txsFee/esdt_test.go index d51848762e8..54cf8b38b71 100644 --- a/integrationTests/vm/txsFee/esdt_test.go +++ b/integrationTests/vm/txsFee/esdt_test.go @@ -32,7 +32,7 @@ func TestESDTTransferShouldWork(t *testing.T) { egldBalance := big.NewInt(100000000) esdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) gasLimit := uint64(40) tx := utils.CreateESDTTransferTx(0, sndAddr, rcvAddr, token, big.NewInt(100), gasPrice, gasLimit) @@ -72,7 +72,7 @@ func TestESDTTransferShouldWorkToMuchGasShouldConsumeAllGas(t *testing.T) { egldBalance := big.NewInt(100000000) esdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) gasLimit := uint64(1000) tx := utils.CreateESDTTransferTx(0, sndAddr, rcvAddr, token, big.NewInt(100), gasPrice, gasLimit) @@ -112,7 +112,7 @@ func TestESDTTransferInvalidESDTValueShouldConsumeGas(t *testing.T) { egldBalance := big.NewInt(100000000) esdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) gasLimit := uint64(1000) tx := utils.CreateESDTTransferTx(0, sndAddr, rcvAddr, token, big.NewInt(100000000+1), gasPrice, gasLimit) @@ -156,7 +156,7 @@ func TestESDTTransferCallBackOnErrorShouldNotGenerateSCRsFurther(t *testing.T) { egldBalance := big.NewInt(100000000) esdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) hexEncodedToken := hex.EncodeToString(token) esdtValueEncoded := hex.EncodeToString(big.NewInt(100).Bytes()) diff --git a/integrationTests/vm/txsFee/multiESDTTransfer_test.go b/integrationTests/vm/txsFee/multiESDTTransfer_test.go index adaf89ad340..b9a4474cf34 100644 --- a/integrationTests/vm/txsFee/multiESDTTransfer_test.go +++ b/integrationTests/vm/txsFee/multiESDTTransfer_test.go @@ -4,6 +4,7 @@ import ( "math/big" "testing" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/vm" @@ -29,9 +30,9 @@ func TestMultiESDTTransferShouldWork(t *testing.T) { egldBalance := big.NewInt(100000000) esdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) secondToken := []byte("second") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), secondToken, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), secondToken, 0, esdtBalance, uint32(core.Fungible)) gasLimit := uint64(4000) tx := utils.CreateMultiTransferTX(0, sndAddr, rcvAddr, gasPrice, gasLimit, &utils.TransferESDTData{ @@ -90,9 +91,9 @@ func TestMultiESDTTransferFailsBecauseOfMaxLimit(t *testing.T) { egldBalance := big.NewInt(100000000) esdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) secondToken := []byte("second") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), secondToken, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), secondToken, 0, esdtBalance, uint32(core.Fungible)) gasLimit := uint64(4000) tx := utils.CreateMultiTransferTX(0, sndAddr, rcvAddr, gasPrice, gasLimit, &utils.TransferESDTData{ diff --git a/integrationTests/vm/txsFee/multiShard/asyncESDT_test.go b/integrationTests/vm/txsFee/multiShard/asyncESDT_test.go index aa37bc6bf94..5ea878f2b26 100644 --- a/integrationTests/vm/txsFee/multiShard/asyncESDT_test.go +++ b/integrationTests/vm/txsFee/multiShard/asyncESDT_test.go @@ -5,6 +5,7 @@ import ( "math/big" "testing" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests" "github.com/multiversx/mx-chain-go/integrationTests/vm" @@ -46,7 +47,7 @@ func TestAsyncESDTTransferWithSCCallShouldWork(t *testing.T) { token := []byte("miiutoken") egldBalance := big.NewInt(10000000) esdtBalance := big.NewInt(10000000) - utils.CreateAccountWithESDTBalance(t, testContextSender.Accounts, senderAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContextSender.Accounts, senderAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) // create accounts for owners _, _ = vm.CreateAccount(testContextFirstContract.Accounts, firstContractOwner, 0, egldBalance) @@ -162,7 +163,7 @@ func TestAsyncESDTTransferWithSCCallSecondContractAnotherToken(t *testing.T) { token := []byte("miiutoken") egldBalance := big.NewInt(10000000) esdtBalance := big.NewInt(10000000) - utils.CreateAccountWithESDTBalance(t, testContextSender.Accounts, senderAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContextSender.Accounts, senderAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) // create accounts for owners _, _ = vm.CreateAccount(testContextFirstContract.Accounts, firstContractOwner, 0, egldBalance) diff --git a/integrationTests/vm/txsFee/multiShard/esdtLiquidity_test.go b/integrationTests/vm/txsFee/multiShard/esdtLiquidity_test.go index 6d2fe8cfa00..3e863713571 100644 --- a/integrationTests/vm/txsFee/multiShard/esdtLiquidity_test.go +++ b/integrationTests/vm/txsFee/multiShard/esdtLiquidity_test.go @@ -35,7 +35,7 @@ func TestSystemAccountLiquidityAfterCrossShardTransferAndBurn(t *testing.T) { _, _ = vm.CreateAccount(sh1Context.Accounts, sh1Addr, 0, big.NewInt(1000000000)) // create the nft and ensure that it exists on the account's trie and the liquidity is set on the system account - utils.CreateAccountWithESDTBalance(t, sh0Context.Accounts, sh0Addr, big.NewInt(100000000), tokenID, 1, big.NewInt(1)) + utils.CreateAccountWithESDTBalance(t, sh0Context.Accounts, sh0Addr, big.NewInt(100000000), tokenID, 1, big.NewInt(1), uint32(core.NonFungible)) utils.CheckESDTNFTBalance(t, sh0Context, sh0Addr, tokenID, 1, big.NewInt(1)) utils.CheckESDTNFTBalance(t, sh0Context, core.SystemAccountAddress, tokenID, 1, big.NewInt(1)) @@ -86,7 +86,7 @@ func TestSystemAccountLiquidityAfterNFTWipe(t *testing.T) { defer metaContext.Close() // create the nft and ensure that it exists on the account's trie and the liquidity is set on the system account - utils.CreateAccountWithESDTBalance(t, sh0Context.Accounts, sh0Addr, big.NewInt(10000000000000), tokenID, 1, big.NewInt(1)) + utils.CreateAccountWithESDTBalance(t, sh0Context.Accounts, sh0Addr, big.NewInt(10000000000000), tokenID, 1, big.NewInt(1), uint32(core.NonFungible)) utils.CheckESDTNFTBalance(t, sh0Context, sh0Addr, tokenID, 1, big.NewInt(1)) utils.CheckESDTNFTBalance(t, sh0Context, core.SystemAccountAddress, tokenID, 1, big.NewInt(1)) @@ -136,7 +136,7 @@ func TestSystemAccountLiquidityAfterSFTWipe(t *testing.T) { defer metaContext.Close() // create the nft and ensure that it exists on the account's trie and the liquidity is set on the system account - utils.CreateAccountWithESDTBalance(t, sh0Context.Accounts, sh0Addr, big.NewInt(10000000000000), tokenID, 1, big.NewInt(10)) + utils.CreateAccountWithESDTBalance(t, sh0Context.Accounts, sh0Addr, big.NewInt(10000000000000), tokenID, 1, big.NewInt(10), uint32(core.SemiFungible)) utils.CheckESDTNFTBalance(t, sh0Context, sh0Addr, tokenID, 1, big.NewInt(10)) utils.CheckESDTNFTBalance(t, sh0Context, core.SystemAccountAddress, tokenID, 1, big.NewInt(10)) diff --git a/integrationTests/vm/txsFee/multiShard/esdt_test.go b/integrationTests/vm/txsFee/multiShard/esdt_test.go index 9dd828eb8c1..2e37f2c9948 100644 --- a/integrationTests/vm/txsFee/multiShard/esdt_test.go +++ b/integrationTests/vm/txsFee/multiShard/esdt_test.go @@ -33,7 +33,7 @@ func TestESDTTransferShouldWork(t *testing.T) { egldBalance := big.NewInt(100000000) esdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, egldBalance, token, 0, esdtBalance, uint32(core.Fungible)) gasPrice := uint64(10) gasLimit := uint64(40) @@ -73,8 +73,8 @@ func TestMultiESDTNFTTransferViaRelayedV2(t *testing.T) { _, _ = vm.CreateAccount(sh1Context.Accounts, relayerSh1, 0, big.NewInt(1000000000)) // create the nfts, add the liquidity to the system accounts and check for balances - utils.CreateAccountWithESDTBalance(t, sh0Context.Accounts, sh0Addr, big.NewInt(100000000), tokenID1, 1, big.NewInt(1)) - utils.CreateAccountWithESDTBalance(t, sh0Context.Accounts, sh0Addr, big.NewInt(100000000), tokenID2, 1, big.NewInt(1)) + utils.CreateAccountWithESDTBalance(t, sh0Context.Accounts, sh0Addr, big.NewInt(100000000), tokenID1, 1, big.NewInt(1), uint32(core.NonFungible)) + utils.CreateAccountWithESDTBalance(t, sh0Context.Accounts, sh0Addr, big.NewInt(100000000), tokenID2, 1, big.NewInt(1), uint32(core.NonFungible)) sh0Accnt, _ := sh0Context.Accounts.LoadAccount(sh0Addr) sh1Accnt, _ := sh1Context.Accounts.LoadAccount(sh1Addr) diff --git a/integrationTests/vm/txsFee/relayedAsyncESDT_test.go b/integrationTests/vm/txsFee/relayedAsyncESDT_test.go index bb8b05606a7..9958dc2e6b2 100644 --- a/integrationTests/vm/txsFee/relayedAsyncESDT_test.go +++ b/integrationTests/vm/txsFee/relayedAsyncESDT_test.go @@ -5,6 +5,7 @@ import ( "math/big" "testing" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests" "github.com/multiversx/mx-chain-go/integrationTests/vm" @@ -34,7 +35,7 @@ func TestRelayedAsyncESDTCallShouldWork(t *testing.T) { localEsdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), token, 0, localEsdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), token, 0, localEsdtBalance, uint32(core.Fungible)) _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, localEgldBalance) // deploy 2 contracts @@ -96,7 +97,7 @@ func TestRelayedAsyncESDTCall_InvalidCallFirstContract(t *testing.T) { localEsdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), token, 0, localEsdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), token, 0, localEsdtBalance, uint32(core.Fungible)) _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, localEgldBalance) // deploy 2 contracts @@ -158,7 +159,7 @@ func TestRelayedAsyncESDTCall_InvalidOutOfGas(t *testing.T) { localEsdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), token, 0, localEsdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), token, 0, localEsdtBalance, uint32(core.Fungible)) _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, localEgldBalance) // deploy 2 contracts diff --git a/integrationTests/vm/txsFee/relayedESDT_test.go b/integrationTests/vm/txsFee/relayedESDT_test.go index 55a7e1bde04..ffe9597f943 100644 --- a/integrationTests/vm/txsFee/relayedESDT_test.go +++ b/integrationTests/vm/txsFee/relayedESDT_test.go @@ -4,6 +4,7 @@ import ( "math/big" "testing" + "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests" "github.com/multiversx/mx-chain-go/integrationTests/vm" @@ -40,7 +41,7 @@ func testRelayedESDTTransferShouldWork( relayerBalance := big.NewInt(10000000) localEsdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), token, 0, localEsdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), token, 0, localEsdtBalance, uint32(core.Fungible)) _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, relayerBalance) gasLimit := uint64(40) @@ -102,7 +103,7 @@ func testRelayedESTTransferNotEnoughESTValueShouldConsumeGas( relayerBalance := big.NewInt(10000000) localEsdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), token, 0, localEsdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, big.NewInt(0), token, 0, localEsdtBalance, uint32(core.Fungible)) _, _ = vm.CreateAccount(testContext.Accounts, relayerAddr, 0, relayerBalance) gasLimit := uint64(42) diff --git a/integrationTests/vm/txsFee/scCalls_test.go b/integrationTests/vm/txsFee/scCalls_test.go index c17474eb9e3..c98d0960b66 100644 --- a/integrationTests/vm/txsFee/scCalls_test.go +++ b/integrationTests/vm/txsFee/scCalls_test.go @@ -352,7 +352,7 @@ func TestESDTScCallAndGasChangeShouldWork(t *testing.T) { localEsdtBalance := big.NewInt(100000000) token := []byte("miiutoken") - utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, senderBalance, token, 0, localEsdtBalance) + utils.CreateAccountWithESDTBalance(t, testContext.Accounts, sndAddr, senderBalance, token, 0, localEsdtBalance, uint32(core.Fungible)) txData := txDataBuilder.NewBuilder() valueToSendToSc := int64(1000) diff --git a/integrationTests/vm/txsFee/utils/utilsESDT.go b/integrationTests/vm/txsFee/utils/utilsESDT.go index 68fe255a1ba..99428ecfcf7 100644 --- a/integrationTests/vm/txsFee/utils/utilsESDT.go +++ b/integrationTests/vm/txsFee/utils/utilsESDT.go @@ -27,6 +27,7 @@ func CreateAccountWithESDTBalance( tokenIdentifier []byte, esdtNonce uint64, esdtValue *big.Int, + esdtType uint32, ) { account, err := accnts.LoadAccount(pubKey) require.Nil(t, err) @@ -39,6 +40,7 @@ func CreateAccountWithESDTBalance( require.Nil(t, err) esdtData := &esdt.ESDigitalToken{ + Type: esdtType, Value: esdtValue, Properties: []byte{}, } @@ -92,6 +94,7 @@ func CreateAccountWithNFT( require.Nil(t, err) esdtData := &esdt.ESDigitalToken{ + Type: uint32(core.NonFungible), Value: big.NewInt(1), Properties: []byte{}, TokenMetaData: &esdt.MetaData{ @@ -152,7 +155,7 @@ func CreateAccountWithESDTBalanceAndRoles( esdtValue *big.Int, roles [][]byte, ) { - CreateAccountWithESDTBalance(t, accnts, pubKey, egldValue, tokenIdentifier, esdtNonce, esdtValue) + CreateAccountWithESDTBalance(t, accnts, pubKey, egldValue, tokenIdentifier, esdtNonce, esdtValue, uint32(core.Fungible)) SetESDTRoles(t, accnts, pubKey, tokenIdentifier, roles) } From fc4edd1e1ad678d7a1e77eb7ab9698586877da06 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Sat, 24 Aug 2024 16:05:13 +0300 Subject: [PATCH 386/434] update stub --- testscommon/esdtStorageHandlerStub.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/testscommon/esdtStorageHandlerStub.go b/testscommon/esdtStorageHandlerStub.go index b6ff81f2b00..599197e7fca 100644 --- a/testscommon/esdtStorageHandlerStub.go +++ b/testscommon/esdtStorageHandlerStub.go @@ -10,7 +10,7 @@ import ( // EsdtStorageHandlerStub - type EsdtStorageHandlerStub struct { - SaveESDTNFTTokenCalled func(senderAddress []byte, acnt vmcommon.UserAccountHandler, esdtTokenKey []byte, nonce uint64, esdtData *esdt.ESDigitalToken, isCreation bool, isReturnWithError bool) ([]byte, error) + SaveESDTNFTTokenCalled func(senderAddress []byte, acnt vmcommon.UserAccountHandler, esdtTokenKey []byte, nonce uint64, esdtData *esdt.ESDigitalToken, saveArgs vmcommon.NftSaveArgs) ([]byte, error) GetESDTNFTTokenOnSenderCalled func(acnt vmcommon.UserAccountHandler, esdtTokenKey []byte, nonce uint64) (*esdt.ESDigitalToken, error) 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) @@ -40,9 +40,9 @@ func (e *EsdtStorageHandlerStub) GetMetaDataFromSystemAccount(bytes []byte, u ui } // SaveESDTNFTToken - -func (e *EsdtStorageHandlerStub) SaveESDTNFTToken(senderAddress []byte, acnt vmcommon.UserAccountHandler, esdtTokenKey []byte, nonce uint64, esdtData *esdt.ESDigitalToken, isCreation bool, isReturnWithError bool) ([]byte, error) { +func (e *EsdtStorageHandlerStub) SaveESDTNFTToken(senderAddress []byte, acnt vmcommon.UserAccountHandler, esdtTokenKey []byte, nonce uint64, esdtData *esdt.ESDigitalToken, saveArgs vmcommon.NftSaveArgs) ([]byte, error) { if e.SaveESDTNFTTokenCalled != nil { - return e.SaveESDTNFTTokenCalled(senderAddress, acnt, esdtTokenKey, nonce, esdtData, isCreation, isReturnWithError) + return e.SaveESDTNFTTokenCalled(senderAddress, acnt, esdtTokenKey, nonce, esdtData, saveArgs) } return nil, nil From aa637404027f90235b07253691372c9cad644c63 Mon Sep 17 00:00:00 2001 From: Daniel Drasovean Date: Mon, 26 Aug 2024 15:07:12 +0300 Subject: [PATCH 387/434] Removed the pull request trigger from the workflow --- .github/workflows/docker-keygenerator.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/docker-keygenerator.yaml b/.github/workflows/docker-keygenerator.yaml index 5e4d9d44a32..c3cca7fc279 100644 --- a/.github/workflows/docker-keygenerator.yaml +++ b/.github/workflows/docker-keygenerator.yaml @@ -2,7 +2,6 @@ name: Build & push keygenerator docker image on: workflow_dispatch: - pull_request: jobs: build-docker-image: @@ -19,7 +18,6 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Log into Docker Hub - if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} @@ -32,5 +30,5 @@ jobs: context: . file: ./docker/keygenerator/Dockerfile platforms: linux/amd64,linux/arm64 - push: ${{ github.event_name != 'pull_request' }} + push: true tags: multiversx/chain-keygenerator:latest From 667579e0717c2baae02923e0bad2384c6082e7b8 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Tue, 27 Aug 2024 12:20:48 +0300 Subject: [PATCH 388/434] 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 df04b5af702..603e813c8d4 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.20240824090826-0159b7bb576f - github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240821104654-483a1cfdfc69 + github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240827070828-a7bb8c51a98e + github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240827072959-38b7c6f69191 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 890d5c75e54..2eb4ea81617 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.20240824090826-0159b7bb576f h1:sJupgH9e7xZCHp53COO6eWrdoTUQqaiddnhb9IzUh0A= -github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240824090826-0159b7bb576f/go.mod h1:sN471lwUKZMIfhNEDgHnSUR5SOv+BCoxF2kv2AnOCj8= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240821104654-483a1cfdfc69 h1:HoyZbjYuQLVHJ8UMOkoIyKLA/jq80kbb3Gbqe2AfuPM= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240821104654-483a1cfdfc69/go.mod h1:j9FBeftA/BKfn0BbndKV7bNFJAzwCnYZuebsM/sufK0= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240827070828-a7bb8c51a98e h1:bM3ftf0/bgyeNs7vEWwXJU/4pIzJ39144jT3v9sDnNQ= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240827070828-a7bb8c51a98e/go.mod h1:sN471lwUKZMIfhNEDgHnSUR5SOv+BCoxF2kv2AnOCj8= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240827072959-38b7c6f69191 h1:yTooD6GHLgOlBK74X4u7okJ2qeGAnCo5TrAoyH+PiVY= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240827072959-38b7c6f69191/go.mod h1:v14k+Xd4Rj+wjfU4b6F25SzwqLsU7DiRN/BfQV4qwVU= 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 b4b7a2ad38cc62cb385d04fc548ecbcc5aa9ddc0 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Thu, 29 Aug 2024 21:37:36 +0300 Subject: [PATCH 389/434] 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 603e813c8d4..6568d791977 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.20240827070828-a7bb8c51a98e - github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240827072959-38b7c6f69191 + github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240829181448-2a52a6d5eb74 + github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240829181819-28231ad08f5c 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 2eb4ea81617..de47f0ae1eb 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.20240827070828-a7bb8c51a98e h1:bM3ftf0/bgyeNs7vEWwXJU/4pIzJ39144jT3v9sDnNQ= -github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240827070828-a7bb8c51a98e/go.mod h1:sN471lwUKZMIfhNEDgHnSUR5SOv+BCoxF2kv2AnOCj8= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240827072959-38b7c6f69191 h1:yTooD6GHLgOlBK74X4u7okJ2qeGAnCo5TrAoyH+PiVY= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240827072959-38b7c6f69191/go.mod h1:v14k+Xd4Rj+wjfU4b6F25SzwqLsU7DiRN/BfQV4qwVU= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240829181448-2a52a6d5eb74 h1:AJWrr+AuSjjHzDFEAWIlkJXL/k/QTN5t+3fbKxbA5iI= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240829181448-2a52a6d5eb74/go.mod h1:sN471lwUKZMIfhNEDgHnSUR5SOv+BCoxF2kv2AnOCj8= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240829181819-28231ad08f5c h1:789cSBvz2KNSch5N9QrxZ/1NmWDabMjib46DrymNNDU= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240829181819-28231ad08f5c/go.mod h1:kBt/qUp0G53AvLb3K0OxD5pNHOZuFrzHclF5uLPV9lE= 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 dd9dcaf48436b5efd76a37b720eb6f8c96742029 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Fri, 30 Aug 2024 13:27:58 +0300 Subject: [PATCH 390/434] 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 6568d791977..e11bd4e7eb9 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.20240829181448-2a52a6d5eb74 - github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240829181819-28231ad08f5c + github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240830102128-33dd73d11361 + github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240830102521-585b30e96690 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 de47f0ae1eb..a48b6f2e508 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.20240829181448-2a52a6d5eb74 h1:AJWrr+AuSjjHzDFEAWIlkJXL/k/QTN5t+3fbKxbA5iI= -github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240829181448-2a52a6d5eb74/go.mod h1:sN471lwUKZMIfhNEDgHnSUR5SOv+BCoxF2kv2AnOCj8= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240829181819-28231ad08f5c h1:789cSBvz2KNSch5N9QrxZ/1NmWDabMjib46DrymNNDU= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240829181819-28231ad08f5c/go.mod h1:kBt/qUp0G53AvLb3K0OxD5pNHOZuFrzHclF5uLPV9lE= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240830102128-33dd73d11361 h1:N1CxdRfh+7S0Yywtl3N8LmQDE3ff7wutV58hZvfdnyQ= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240830102128-33dd73d11361/go.mod h1:sN471lwUKZMIfhNEDgHnSUR5SOv+BCoxF2kv2AnOCj8= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240830102521-585b30e96690 h1:rdTYzHlQY4BCru5/hBn5cobNiUwyoCwmxpjNOFUC17k= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240830102521-585b30e96690/go.mod h1:up5NULwRXIPld30uaU1IQulTzW9Bew/L1LTcKBTN8Zc= 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 5934073cbc60080245b32d36e77942ee48561704 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 30 Aug 2024 14:42:51 +0300 Subject: [PATCH 391/434] fixed missing scrs when multiple inner tx fail with the same error, caused by hash collision --- .../relayedTx/relayedTx_test.go | 86 +++++++++++++++++++ process/transaction/export_test.go | 11 ++- process/transaction/shardProcess.go | 45 +++++++--- 3 files changed, 127 insertions(+), 15 deletions(-) diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index 97a815549c3..fa2b02b9fe3 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -155,6 +155,92 @@ func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(t *testing. require.True(t, strings.Contains(string(result.Logs.Events[2].Data), "contract is paused")) } +func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorAndInvalidNonces(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(30000)) + 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) + + // bump sender nonce to 3 + tx0 := generateTransaction(sender.Bytes, 0, sender.Bytes, big.NewInt(0), "", minGasLimit) + tx1 := generateTransaction(sender.Bytes, 1, sender.Bytes, big.NewInt(0), "", minGasLimit) + tx2 := generateTransaction(sender.Bytes, 2, sender.Bytes, big.NewInt(0), "", minGasLimit) + _, err = cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{tx0, tx1, tx2}, maxNumOfBlocksToGenerateWhenExecutingTx) + require.Nil(t, err) + + // higher nonce + innerTx1 := generateTransaction(sender.Bytes, 10, receiver.Bytes, oneEGLD, "", minGasLimit) + innerTx1.RelayerAddr = relayer.Bytes + + // higher nonce + innerTx2 := generateTransaction(sender.Bytes, 9, receiver.Bytes, oneEGLD, "", minGasLimit) + innerTx2.RelayerAddr = relayer.Bytes + + // nonce ok + innerTx3 := generateTransaction(sender.Bytes, 3, receiver.Bytes, oneEGLD, "", minGasLimit) + innerTx3.RelayerAddr = relayer.Bytes + + // higher nonce + innerTx4 := generateTransaction(sender.Bytes, 8, receiver.Bytes, oneEGLD, "", minGasLimit) + innerTx4.RelayerAddr = relayer.Bytes + + // lower nonce - initial one + innerTx5 := generateTransaction(sender.Bytes, 3, receiver.Bytes, oneEGLD, "", minGasLimit) + innerTx5.RelayerAddr = relayer.Bytes + + innerTxs := []*transaction.Transaction{innerTx1, innerTx2, innerTx3, innerTx4, innerTx5} + + // 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) + + // 5 scrs, 4 from the failed txs + 1 with success + require.Equal(t, 5, len(result.SmartContractResults)) + scrsMap := make(map[string]int, len(result.SmartContractResults)) + for _, scr := range result.SmartContractResults { + if len(scr.ReturnMessage) == 0 { + scrsMap["success"]++ + } + if strings.Contains(scr.ReturnMessage, process.ErrHigherNonceInTransaction.Error()) { + scrsMap[process.ErrHigherNonceInTransaction.Error()]++ + } + if strings.Contains(scr.ReturnMessage, process.ErrLowerNonceInTransaction.Error()) { + scrsMap[process.ErrLowerNonceInTransaction.Error()]++ + } + } + require.Equal(t, 1, scrsMap["success"]) + require.Equal(t, 3, scrsMap[process.ErrHigherNonceInTransaction.Error()]) + require.Equal(t, 1, scrsMap[process.ErrLowerNonceInTransaction.Error()]) + + // 4 log events from the failed txs + require.Equal(t, 4, len(result.Logs.Events)) + for _, event := range result.Logs.Events { + require.Equal(t, core.SignalErrorOperation, event.Identifier) + } +} + func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorScCalls(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") diff --git a/process/transaction/export_test.go b/process/transaction/export_test.go index 07ed7a91896..ef23d5c114f 100644 --- a/process/transaction/export_test.go +++ b/process/transaction/export_test.go @@ -57,7 +57,13 @@ func (txProc *txProcessor) ProcessUserTx( relayedNonce uint64, originalTxHash []byte, ) (vmcommon.ReturnCode, error) { - return txProc.processUserTx(originalTx, userTx, relayedTxValue, relayedNonce, originalTxHash) + return txProc.processUserTx( + originalTx, + userTx, + relayedTxValue, + relayedNonce, + originalTxHash, + nonRelayedV3UserTxIdx) } // ProcessMoveBalanceCostRelayedUserTx calls the un-exported method processMoveBalanceCostRelayedUserTx @@ -87,7 +93,8 @@ func (txProc *txProcessor) ExecuteFailedRelayedTransaction( relayedNonce, originalTx, originalTxHash, - errorMsg) + errorMsg, + nonRelayedV3UserTxIdx) } // CheckMaxGasPrice calls the un-exported method checkMaxGasPrice diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 50fa0c94d21..6d2fbeb80f3 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -31,6 +31,8 @@ var _ process.TransactionProcessor = (*txProcessor)(nil) // for move balance transactions that provide more gas than needed const RefundGasMessage = "refundedGas" +const nonRelayedV3UserTxIdx = -1 + type relayedFees struct { totalFee, remainingFee, relayerFee *big.Int } @@ -647,12 +649,13 @@ func (txProc *txProcessor) finishExecutionOfRelayedTx( tx.Nonce, tx, originalTxHash, - err.Error()) + err.Error(), + nonRelayedV3UserTxIdx) } defer txProc.saveFailedLogsIfNeeded(originalTxHash) - return txProc.processUserTx(tx, userTx, tx.Value, tx.Nonce, originalTxHash) + return txProc.processUserTx(tx, userTx, tx.Value, tx.Nonce, originalTxHash, nonRelayedV3UserTxIdx) } func (txProc *txProcessor) processTxAtRelayer( @@ -743,8 +746,8 @@ func (txProc *txProcessor) processRelayedTxV3( var innerTxFee *big.Int innerTxsTotalFees := big.NewInt(0) executedUserTxs := make([]*transaction.Transaction, 0) - for _, innerTx := range innerTxs { - innerTxFee, innerTxRetCode, innerTxErr = txProc.processInnerTx(tx, innerTx, originalTxHash) + for innerTxIdx, innerTx := range innerTxs { + innerTxFee, innerTxRetCode, innerTxErr = txProc.processInnerTx(tx, innerTx, originalTxHash, innerTxIdx) innerTxsTotalFees.Add(innerTxsTotalFees, innerTxFee) if innerTxErr != nil || innerTxRetCode != vmcommon.Ok { continue @@ -781,6 +784,7 @@ func (txProc *txProcessor) processInnerTx( tx *transaction.Transaction, innerTx *transaction.Transaction, originalTxHash []byte, + innerTxIdx int, ) (*big.Int, vmcommon.ReturnCode, error) { txFee := txProc.computeInnerTxFee(innerTx) @@ -794,7 +798,8 @@ func (txProc *txProcessor) processInnerTx( tx.Nonce, tx, originalTxHash, - err.Error()) + err.Error(), + innerTxIdx) } if check.IfNil(acntSnd) { @@ -805,7 +810,8 @@ func (txProc *txProcessor) processInnerTx( tx.Nonce, tx, originalTxHash, - process.ErrRelayedTxV3SenderShardMismatch.Error()) + process.ErrRelayedTxV3SenderShardMismatch.Error(), + innerTxIdx) } // TODO: remove adding and then removing the fee at the sender @@ -818,10 +824,11 @@ func (txProc *txProcessor) processInnerTx( tx.Nonce, tx, originalTxHash, - err.Error()) + err.Error(), + innerTxIdx) } - result, err := txProc.processUserTx(tx, innerTx, tx.Value, tx.Nonce, originalTxHash) + result, err := txProc.processUserTx(tx, innerTx, tx.Value, tx.Nonce, originalTxHash, innerTxIdx) return txFee, result, err } @@ -1002,6 +1009,7 @@ func (txProc *txProcessor) processUserTx( relayedTxValue *big.Int, relayedNonce uint64, originalTxHash []byte, + innerTxIdx int, ) (vmcommon.ReturnCode, error) { relayerAdr := originalTx.SndAddr @@ -1018,7 +1026,8 @@ func (txProc *txProcessor) processUserTx( relayedNonce, originalTx, originalTxHash, - err.Error()) + err.Error(), + innerTxIdx) } txType, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(userTx) @@ -1035,7 +1044,8 @@ func (txProc *txProcessor) processUserTx( relayedNonce, originalTx, originalTxHash, - err.Error()) + err.Error(), + innerTxIdx) } scrFromTx, err := txProc.makeSCRFromUserTx(userTx, relayerAdr, relayedTxValue, originalTxHash) @@ -1085,7 +1095,8 @@ func (txProc *txProcessor) processUserTx( relayedNonce, originalTx, originalTxHash, - err.Error()) + err.Error(), + innerTxIdx) } if errors.Is(err, process.ErrInvalidMetaTransaction) || errors.Is(err, process.ErrAccountNotPayable) { @@ -1096,7 +1107,8 @@ func (txProc *txProcessor) processUserTx( relayedNonce, originalTx, originalTxHash, - err.Error()) + err.Error(), + innerTxIdx) } if errors.Is(err, process.ErrFailedTransaction) { @@ -1174,7 +1186,14 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( originalTx *transaction.Transaction, originalTxHash []byte, errorMsg string, + innerTxIdx int, ) error { + + returnMessage := []byte(errorMsg) + isUserTxOfRelayedV3 := innerTxIdx != nonRelayedV3UserTxIdx + if isUserTxOfRelayedV3 { + returnMessage = []byte(fmt.Sprintf("%s while executing inner tx at index %d", errorMsg, innerTxIdx)) + } scrForRelayer := &smartContractResult.SmartContractResult{ Nonce: relayedNonce, Value: big.NewInt(0).Set(relayedTxValue), @@ -1182,7 +1201,7 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( SndAddr: userTx.SndAddr, PrevTxHash: originalTxHash, OriginalTxHash: originalTxHash, - ReturnMessage: []byte(errorMsg), + ReturnMessage: returnMessage, } relayerAcnt, err := txProc.getAccountFromAddress(relayerAdr) From 814e4934d227658e58e679cfedecacfe8c2b1227 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 3 Sep 2024 11:18:27 +0300 Subject: [PATCH 392/434] fix docker annotations --- docker/keygenerator/Dockerfile | 2 +- docker/node/Dockerfile | 2 +- docker/seednode/Dockerfile | 2 +- docker/termui/Dockerfile | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docker/keygenerator/Dockerfile b/docker/keygenerator/Dockerfile index a73d7951d42..574f9ea15e5 100644 --- a/docker/keygenerator/Dockerfile +++ b/docker/keygenerator/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.20.7 as builder +FROM golang:1.20.7 AS builder RUN apt-get update && apt-get install -y WORKDIR /go/mx-chain-go diff --git a/docker/node/Dockerfile b/docker/node/Dockerfile index 2a341a8409b..205733030c1 100644 --- a/docker/node/Dockerfile +++ b/docker/node/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.20.7 as builder +FROM golang:1.20.7 AS builder RUN apt-get update && apt-get upgrade -y WORKDIR /go/mx-chain-go diff --git a/docker/seednode/Dockerfile b/docker/seednode/Dockerfile index 74cc250c047..0a88e94e2c0 100644 --- a/docker/seednode/Dockerfile +++ b/docker/seednode/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.20.7 as builder +FROM golang:1.20.7 AS builder RUN apt-get update && apt-get install -y WORKDIR /go/mx-chain-go diff --git a/docker/termui/Dockerfile b/docker/termui/Dockerfile index e22986033eb..22b053b64d4 100644 --- a/docker/termui/Dockerfile +++ b/docker/termui/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.20.7 as builder +FROM golang:1.20.7 AS builder RUN apt-get update && apt-get install -y WORKDIR /go/mx-chain-go COPY . . From e4a09c614abd96b7e1d0705a65fed058aa51b7b8 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Tue, 3 Sep 2024 14:25:32 +0300 Subject: [PATCH 393/434] add testing scenarios and update go mod --- go.mod | 4 +- go.sum | 8 +- .../vm/egldMultiTransfer_test.go | 10 +- .../vm/esdtImprovements_test.go | 597 ++++++++++++++---- .../chainSimulator/vm/esdtTokens_test.go | 4 +- 5 files changed, 503 insertions(+), 120 deletions(-) diff --git a/go.mod b/go.mod index e11bd4e7eb9..92a18248de8 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.20240830102128-33dd73d11361 - github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240830102521-585b30e96690 + github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240903110629-ee357f94b63c + github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240903110843-ed790853265d 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 a48b6f2e508..21ac2f73c29 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.20240830102128-33dd73d11361 h1:N1CxdRfh+7S0Yywtl3N8LmQDE3ff7wutV58hZvfdnyQ= -github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240830102128-33dd73d11361/go.mod h1:sN471lwUKZMIfhNEDgHnSUR5SOv+BCoxF2kv2AnOCj8= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240830102521-585b30e96690 h1:rdTYzHlQY4BCru5/hBn5cobNiUwyoCwmxpjNOFUC17k= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240830102521-585b30e96690/go.mod h1:up5NULwRXIPld30uaU1IQulTzW9Bew/L1LTcKBTN8Zc= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240903110629-ee357f94b63c h1:VLAdXl0NsnMWBuJZUJPxK8qK1AKyEzqSoQ7I8NOj0t4= +github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240903110629-ee357f94b63c/go.mod h1:sN471lwUKZMIfhNEDgHnSUR5SOv+BCoxF2kv2AnOCj8= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240903110843-ed790853265d h1:TSObh+pVpKdjBb0eyLHjBRULIZU+v6voSJd2CNprllg= +github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240903110843-ed790853265d/go.mod h1:2x0I5wbWgrVKj7zeVSWITWqdnqmAiuBfsAdrdbAViQE= 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= diff --git a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go index 10a10cee5ad..5e9d641f90a 100644 --- a/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go +++ b/integrationTests/chainSimulator/vm/egldMultiTransfer_test.go @@ -141,7 +141,7 @@ func TestChainSimulator_EGLD_MultiTransfer(t *testing.T) { } for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i], 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -275,7 +275,7 @@ func TestChainSimulator_EGLD_MultiTransfer_Insufficient_Funds(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData, 1) nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -397,7 +397,7 @@ func TestChainSimulator_EGLD_MultiTransfer_Invalid_Value(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData, 1) nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -519,7 +519,7 @@ func TestChainSimulator_Multiple_EGLD_Transfers(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData, 1) nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -732,7 +732,7 @@ func TestChainSimulator_IssueToken_EGLDTicker(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData, 1) nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index dbb98384825..b1b09764573 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -219,7 +219,7 @@ func transferAndCheckTokensMetaData(t *testing.T, isCrossShard bool, isMultiTran } for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i], 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -599,19 +599,20 @@ func updateTokenIDTx(nonce uint64, sndAdr []byte, tokenID []byte) *transaction.T } } -func nftCreateTx( +func esdtNftCreateTx( nonce uint64, sndAdr []byte, tokenID []byte, metaData *txsFee.MetaData, + quantity int64, ) *transaction.Transaction { txDataField := bytes.Join( [][]byte{ []byte(core.BuiltInFunctionESDTNFTCreate), []byte(hex.EncodeToString(tokenID)), - []byte(hex.EncodeToString(big.NewInt(1).Bytes())), // quantity + []byte(hex.EncodeToString(big.NewInt(quantity).Bytes())), // quantity metaData.Name, - []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + metaData.Royalties, metaData.Hash, metaData.Attributes, metaData.Uris[0], @@ -853,7 +854,7 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { } for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i], 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -992,7 +993,7 @@ func TestChainSimulator_ESDTMetaDataRecreate(t *testing.T) { } for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i], 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1194,7 +1195,7 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { } for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i], 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1236,35 +1237,7 @@ func TestChainSimulator_ESDTMetaDataUpdate(t *testing.T) { 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, - } - + tx = esdtMetaDataUpdateTx(tokenIDs[i], newMetaData, nonce, addrs[0].Bytes) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) @@ -1422,7 +1395,7 @@ func TestChainSimulator_ESDTModifyCreator(t *testing.T) { } for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[1].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = esdtNftCreateTx(nonce, addrs[1].Bytes, tokenIDs[i], tokensMetadata[i], 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1623,7 +1596,7 @@ func TestChainSimulator_ESDTModifyCreator_CrossShard(t *testing.T) { } for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[1].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = esdtNftCreateTx(nonce, addrs[1].Bytes, tokenIDs[i], tokensMetadata[i], 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -1823,7 +1796,7 @@ func TestChainSimulator_ESDTSetNewURIs(t *testing.T) { } for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i], 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2025,7 +1998,7 @@ func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { } for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i], 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2180,7 +2153,7 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[1].Bytes, nftTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[1].Bytes, nftTokenID, nftMetaData, 1) nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -2286,34 +2259,7 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { 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 - metaData.Name, - []byte(hex.EncodeToString(big.NewInt(10).Bytes())), - metaData.Hash, - metaData.Attributes, - metaData.Uris[0], - metaData.Uris[1], - metaData.Uris[2], - }, - []byte("@"), - ) - - tx = &transaction.Transaction{ - Nonce: nonce, - 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, - } + tx = esdtNftCreateTx(nonce, addrs[1].Bytes, tokenID, metaData, 2) nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -2374,35 +2320,7 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { sftMetaData2.Hash = []byte(hex.EncodeToString([]byte("hash2"))) sftMetaData2.Attributes = []byte(hex.EncodeToString([]byte("attributes2"))) - txDataField = bytes.Join( - [][]byte{ - []byte(core.ESDTMetaDataUpdate), - []byte(hex.EncodeToString(tokenID)), - 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, - } - + tx = esdtMetaDataUpdateTx(tokenID, sftMetaData2, 0, addrs[0].Bytes) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) @@ -2438,6 +2356,8 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { log.Info("Step 5. check meta data in shard 2 is updated to latest version ") checkMetaData(t, cs, core.SystemAccountAddress, tokenID, shard2ID, sftMetaData2) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, shardID, sftMetaData2) + } func TestChainSimulator_NFT_RegisterDynamic(t *testing.T) { @@ -2501,7 +2421,7 @@ func TestChainSimulator_NFT_RegisterDynamic(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData, 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2598,7 +2518,7 @@ func TestChainSimulator_MetaESDT_RegisterDynamic(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData, 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2745,7 +2665,7 @@ func TestChainSimulator_NFT_RegisterAndSetAllRolesDynamic(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData, 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -2866,7 +2786,7 @@ func TestChainSimulator_SFT_RegisterAndSetAllRolesDynamic(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[0].Bytes, sftTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, sftTokenID, nftMetaData, 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3041,7 +2961,7 @@ func TestChainSimulator_MetaESDT_RegisterAndSetAllRolesDynamic(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[0].Bytes, metaTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, metaTokenID, nftMetaData, 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3310,7 +3230,7 @@ func createTokenUpdateTokenIDAndTransfer( } setAddressEsdtRoles(t, cs, 1, walletWithRoles, tokenID, roles) - tx := nftCreateTx(2, originAddress, tokenID, metaData) + tx := esdtNftCreateTx(2, originAddress, tokenID, metaData, 1) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3435,7 +3355,7 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { } for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i], 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -3608,7 +3528,7 @@ func TestChainSimulator_CreateAndPause_NFT(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData, 1) nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -3790,7 +3710,7 @@ func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData, 1) nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -3934,3 +3854,466 @@ func TestChainSimulator_CheckRolesWhichHasToBeSingular(t *testing.T) { } } } + +func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) { + t.Parallel() + + baseIssuingCost := "1000" + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) + defer cs.Close() + + addrs := createAddresses(t, cs, true) + + 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) + + shard0Nonce := uint64(0) + tx := &transaction.Transaction{ + Nonce: shard0Nonce, + 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, + } + shard0Nonce++ + + 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] + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleNFTAddQuantity), + []byte(core.ESDTRoleTransfer), + []byte(core.ESDTRoleNFTUpdate), + } + setAddressEsdtRoles(t, cs, shard0Nonce, addrs[0], tokenID, roles) + shard0Nonce++ + + metaData := txsFee.GetDefaultMetaData() + metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = esdtNftCreateTx(shard0Nonce, addrs[0].Bytes, tokenID, metaData, 2) + shard0Nonce++ + 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, tokenID, shardID, metaData) + + log.Info("send metaEsdt cross shard") + + tx = esdtNFTTransferTx(shard0Nonce, 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()) + shard0Nonce++ + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + log.Info("update metaData on shard 0") + + newMetaData := &txsFee.MetaData{} + 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"))) + + tx = esdtMetaDataUpdateTx(tokenID, newMetaData, shard0Nonce, addrs[0].Bytes) + shard0Nonce++ + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + expectedMetaData := txsFee.GetDefaultMetaData() + expectedMetaData.Nonce = newMetaData.Nonce + expectedMetaData.Name = newMetaData.Name + expectedMetaData.Hash = newMetaData.Hash + expectedMetaData.Attributes = newMetaData.Attributes + + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 0, expectedMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 1, metaData) + + log.Info("send the update role to shard 2") + + shard0Nonce = transferSpecialRoleToAddr(t, cs, shard0Nonce, tokenID, addrs[0].Bytes, addrs[2].Bytes, []byte(core.ESDTRoleNFTUpdate)) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + log.Info("update metaData on shard 2") + + newMetaData2 := &txsFee.MetaData{} + newMetaData2.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + newMetaData2.Uris = [][]byte{[]byte(hex.EncodeToString([]byte("uri5"))), []byte(hex.EncodeToString([]byte("uri6"))), []byte(hex.EncodeToString([]byte("uri7")))} + newMetaData2.Royalties = []byte(hex.EncodeToString(big.NewInt(15).Bytes())) + + tx = esdtMetaDataUpdateTx(tokenID, newMetaData2, 0, addrs[2].Bytes) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 0, expectedMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 1, metaData) + + retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, 2) + require.Equal(t, uint64(0), retrievedMetaData.Nonce) + require.Equal(t, 0, len(retrievedMetaData.Name)) + require.Equal(t, addrs[2].Bytes, retrievedMetaData.Creator) + require.Equal(t, newMetaData2.Royalties, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Royalties)).Bytes()))) + require.Equal(t, 0, len(retrievedMetaData.Hash)) + require.Equal(t, 3, len(retrievedMetaData.URIs)) + for i, uri := range newMetaData2.Uris { + require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) + } + require.Equal(t, 0, len(retrievedMetaData.Attributes)) + + log.Info("transfer from shard 0 to shard 1 - should merge metaData") + + tx = esdtNFTTransferTx(shard0Nonce, 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()) + shard0Nonce++ + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 0, expectedMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 1, expectedMetaData) + + log.Info("transfer from shard 1 to shard 2 - should merge metaData") + + tx = setSpecialRoleTx(shard0Nonce, addrs[0].Bytes, addrs[1].Bytes, tokenID, [][]byte{[]byte(core.ESDTRoleTransfer)}) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + shard0Nonce++ + + tx = esdtNFTTransferTx(0, 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()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 0, expectedMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 1, expectedMetaData) + + latestMetaData := txsFee.GetDefaultMetaData() + latestMetaData.Nonce = expectedMetaData.Nonce + latestMetaData.Name = expectedMetaData.Name + latestMetaData.Royalties = newMetaData2.Royalties + latestMetaData.Hash = expectedMetaData.Hash + latestMetaData.Attributes = expectedMetaData.Attributes + latestMetaData.Uris = newMetaData2.Uris + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 2, latestMetaData) + + log.Info("transfer from shard 2 to shard 0 - should update metaData") + + tx = setSpecialRoleTx(shard0Nonce, addrs[0].Bytes, addrs[2].Bytes, tokenID, [][]byte{[]byte(core.ESDTRoleTransfer)}) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + shard0Nonce++ + + tx = esdtNFTTransferTx(1, addrs[2].Bytes, addrs[0].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) + + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 0, latestMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 1, expectedMetaData) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 2, latestMetaData) +} + +func unsetSpecialRole( + nonce uint64, + sndAddr []byte, + address []byte, + token []byte, + role []byte, +) *transaction.Transaction { + txDataBytes := [][]byte{ + []byte("unSetSpecialRole"), + []byte(hex.EncodeToString(token)), + []byte(hex.EncodeToString(address)), + []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 esdtMetaDataUpdateTx(tokenID []byte, metaData *txsFee.MetaData, nonce uint64, address []byte) *transaction.Transaction { + txData := [][]byte{ + []byte(core.ESDTMetaDataUpdate), + []byte(hex.EncodeToString(tokenID)), + metaData.Nonce, + metaData.Name, + metaData.Royalties, + metaData.Hash, + metaData.Attributes, + } + if len(metaData.Uris) > 0 { + for _, uri := range metaData.Uris { + txData = append(txData, uri) + } + } else { + txData = append(txData, nil) + } + + txDataField := bytes.Join( + txData, + []byte("@"), + ) + + tx := &transaction.Transaction{ + Nonce: nonce, + SndAddr: address, + RcvAddr: address, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + return tx +} + +func transferSpecialRoleToAddr( + t *testing.T, + cs testsChainSimulator.ChainSimulator, + nonce uint64, + tokenID []byte, + sndAddr []byte, + dstAddr []byte, + role []byte, +) uint64 { + tx := unsetSpecialRole(nonce, sndAddr, sndAddr, tokenID, role) + nonce++ + txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + tx = setSpecialRoleTx(nonce, sndAddr, dstAddr, tokenID, [][]byte{role}) + nonce++ + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + return nonce +} + +func TestChainSimulator_dynamicNFT_mergeMetaDataFromMultipleUpdates(t *testing.T) { + t.Parallel() + + baseIssuingCost := "1000" + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) + defer cs.Close() + + addrs := createAddresses(t, cs, true) + + log.Info("Register dynamic NFT token") + + ticker := []byte("NFTTICKER") + tokenName := []byte("tokenName") + + txDataField := bytes.Join( + [][]byte{ + []byte("registerDynamic"), + []byte(hex.EncodeToString(tokenName)), + []byte(hex.EncodeToString(ticker)), + []byte(hex.EncodeToString([]byte("NFT"))), + }, + []byte("@"), + ) + + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + + shard0Nonce := uint64(0) + tx := &transaction.Transaction{ + Nonce: shard0Nonce, + 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, + } + shard0Nonce++ + + 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] + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + []byte(core.ESDTRoleNFTUpdate), + } + setAddressEsdtRoles(t, cs, shard0Nonce, addrs[0], tokenID, roles) + shard0Nonce++ + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + metaData := txsFee.GetDefaultMetaData() + metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = esdtNftCreateTx(shard0Nonce, addrs[0].Bytes, tokenID, metaData, 1) + shard0Nonce++ + 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) + + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 0) + checkMetaData(t, cs, addrs[0].Bytes, tokenID, 0, metaData) + + log.Info("give update role to another account and update metaData") + + shard0Nonce = transferSpecialRoleToAddr(t, cs, shard0Nonce, tokenID, addrs[0].Bytes, addrs[1].Bytes, []byte(core.ESDTRoleNFTUpdate)) + + newMetaData := &txsFee.MetaData{} + newMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + newMetaData.Name = []byte(hex.EncodeToString([]byte("name2"))) + newMetaData.Hash = []byte(hex.EncodeToString([]byte("hash2"))) + newMetaData.Royalties = []byte(hex.EncodeToString(big.NewInt(15).Bytes())) + + tx = esdtMetaDataUpdateTx(tokenID, newMetaData, 0, addrs[1].Bytes) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 0) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 1) + checkMetaData(t, cs, addrs[0].Bytes, tokenID, 0, metaData) + newMetaData.Nonce = []byte{} + newMetaData.Attributes = []byte{} + checkMetaData(t, cs, addrs[1].Bytes, tokenID, 1, newMetaData) + + log.Info("transfer nft - should merge metaData") + + tx = esdtNFTTransferTx(shard0Nonce, addrs[0].Bytes, addrs[1].Bytes, tokenID) + shard0Nonce++ + 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) + + mergedMetaData := txsFee.GetDefaultMetaData() + mergedMetaData.Nonce = metaData.Nonce + mergedMetaData.Name = newMetaData.Name + mergedMetaData.Hash = newMetaData.Hash + mergedMetaData.Royalties = newMetaData.Royalties + + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 0) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 1) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, tokenID, 0) + checkMetaData(t, cs, addrs[1].Bytes, tokenID, 1, mergedMetaData) + + log.Info("transfer nft - should remove metaData from sender") + + tx = setSpecialRoleTx(shard0Nonce, addrs[0].Bytes, addrs[1].Bytes, tokenID, [][]byte{[]byte(core.ESDTRoleTransfer)}) + shard0Nonce++ + 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) + + tx = esdtNFTTransferTx(1, 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()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 0) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 1) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 2) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, tokenID, 0) + checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, tokenID, 1) + checkMetaData(t, cs, addrs[2].Bytes, tokenID, 2, mergedMetaData) +} diff --git a/integrationTests/chainSimulator/vm/esdtTokens_test.go b/integrationTests/chainSimulator/vm/esdtTokens_test.go index 1000265d8d0..a5505de14ff 100644 --- a/integrationTests/chainSimulator/vm/esdtTokens_test.go +++ b/integrationTests/chainSimulator/vm/esdtTokens_test.go @@ -154,7 +154,7 @@ func TestChainSimulator_Api_TokenType(t *testing.T) { } for i := range tokenIDs { - tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i], 1) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -273,7 +273,7 @@ func TestChainSimulator_Api_NFTToken(t *testing.T) { nftMetaData := txsFee.GetDefaultMetaData() nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = nftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData) + tx = esdtNftCreateTx(nonce, addrs[0].Bytes, nftTokenID, nftMetaData, 1) nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) From 7c71e3ff4c0dcdb5a92d0bd1caddd2a320d42c28 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Tue, 3 Sep 2024 14:44:59 +0300 Subject: [PATCH 394/434] linter fixes --- .../chainSimulator/vm/esdtImprovements_test.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index b1b09764573..8f8417d9b84 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -3378,7 +3378,7 @@ func TestChainSimulator_ChangeToDynamic_OldTokens(t *testing.T) { checkMetaData(t, cs, addrs[0].Bytes, metaESDTTokenID, shardID, esdtMetaData) checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, metaESDTTokenID, shardID) - err = cs.GenerateBlocksUntilEpochIsReached(int32(epochForDynamicNFT)) + err = cs.GenerateBlocksUntilEpochIsReached(epochForDynamicNFT) require.Nil(t, err) log.Info("Change to DYNAMIC type") @@ -4054,7 +4054,6 @@ func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - shard0Nonce++ tx = esdtNFTTransferTx(1, addrs[2].Bytes, addrs[0].Bytes, tokenID) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) @@ -4114,9 +4113,7 @@ func esdtMetaDataUpdateTx(tokenID []byte, metaData *txsFee.MetaData, nonce uint6 metaData.Attributes, } if len(metaData.Uris) > 0 { - for _, uri := range metaData.Uris { - txData = append(txData, uri) - } + txData = append(txData, metaData.Uris...) } else { txData = append(txData, nil) } @@ -4292,7 +4289,6 @@ func TestChainSimulator_dynamicNFT_mergeMetaDataFromMultipleUpdates(t *testing.T log.Info("transfer nft - should remove metaData from sender") tx = setSpecialRoleTx(shard0Nonce, addrs[0].Bytes, addrs[1].Bytes, tokenID, [][]byte{[]byte(core.ESDTRoleTransfer)}) - shard0Nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) From 506cd9fa48ec334775f05b3b92dc3458fa5a3d24 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 6 Sep 2024 13:22:58 +0300 Subject: [PATCH 395/434] proper fix for gasUsed and fee in case of relayedV3 --- .../transactionAPI/gasUsedAndFeeProcessor.go | 26 +++-- .../transactionsFeeProcessor.go | 15 ++- .../transactionsFeeProcessor_test.go | 103 ++++++++++++++++++ process/economics/economicsData.go | 25 ++++- process/economics/economicsData_test.go | 33 ++++++ 5 files changed, 190 insertions(+), 12 deletions(-) diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index 8951149c983..342aa11cce9 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -49,16 +49,16 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction tx.Fee = tx.InitiallyPaidFee } - if tx.IsRelayed && isFeeFixActive { - 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() - } + initialTotalFee, isRelayed := gfp.getFeeOfRelayed(tx) + if isRelayed && isFeeFixActive { + tx.InitiallyPaidFee = initialTotalFee.String() + tx.Fee = initialTotalFee.String() + tx.GasUsed = big.NewInt(0).Div(initialTotalFee, big.NewInt(0).SetUint64(tx.GasPrice)).Uint64() } hasRefundForSender := false + totalRefunds := big.NewInt(0) + isRelayedV3 := len(tx.InnerTransactions) > 0 for _, scr := range tx.SmartContractResults { if !scr.IsRefund || scr.RcvAddr != tx.Sender { continue @@ -69,7 +69,17 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction gfp.setGasUsedAndFeeBaseOnRefundValue(tx, scr.Value) hasRefundForSender = true - break + totalRefunds.Add(totalRefunds, scr.Value) + if !isRelayedV3 { + break + } + } + + if isRelayedV3 { + gasUsed, fee = gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(tx, totalRefunds) + tx.GasUsed = gasUsed + tx.Fee = fee.String() + return } gfp.prepareTxWithResultsBasedOnLogs(tx, hasRefundForSender) diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index ffad67ee22f..23dcb3fedf1 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -155,6 +155,8 @@ func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *trans func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWithResults *transactionWithResults) { hasRefund := false + totalRefunds := big.NewInt(0) + isRelayedV3 := len(txWithResults.GetTxHandler().GetUserTransactions()) > 0 for _, scrHandler := range txWithResults.scrs { scr, ok := scrHandler.GetTxHandler().(*smartContractResult.SmartContractResult) if !ok { @@ -167,12 +169,21 @@ func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWi txWithResults.GetFeeInfo().SetGasUsed(gasUsed) txWithResults.GetFeeInfo().SetFee(fee) hasRefund = true - break + totalRefunds.Add(totalRefunds, scr.Value) + if !isRelayedV3 { + break + } } } - tep.prepareTxWithResultsBasedOnLogs(txHashHex, txWithResults, hasRefund) + if isRelayedV3 { + gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txWithResults.GetTxHandler(), totalRefunds) + txWithResults.GetFeeInfo().SetGasUsed(gasUsed) + txWithResults.GetFeeInfo().SetFee(fee) + return + } + tep.prepareTxWithResultsBasedOnLogs(txHashHex, txWithResults, hasRefund) } func (tep *transactionsFeeProcessor) getFeeOfRelayed(tx *transactionWithResults) (*big.Int, bool) { diff --git a/outport/process/transactionsfee/transactionsFeeProcessor_test.go b/outport/process/transactionsfee/transactionsFeeProcessor_test.go index 6f0e0f94c35..8472ad1551d 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor_test.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor_test.go @@ -10,10 +10,13 @@ import ( 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-go/common" "github.com/multiversx/mx-chain-go/outport/mock" "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/process/economics" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" + "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" "github.com/multiversx/mx-chain-go/testscommon/genericMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" logger "github.com/multiversx/mx-chain-logger-go" @@ -597,3 +600,103 @@ func TestMoveBalanceWithSignalError(t *testing.T) { require.Nil(t, err) require.Equal(t, uint64(225_500), initialTx.GetFeeInfo().GetGasUsed()) } + +func TestPutFeeAndGasUsedRelayedTxV3WithRefunds(t *testing.T) { + t.Parallel() + + txHash := []byte("af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa") + scrHash1 := []byte("4c58801e77c57e88294f21018145662e2fb1698fd5f1a1cf7b6f81f073f5cd6c") + scrWithRefundHash := []byte("94e678f400192eeae3c84b3125c9d45301db619a3ecbf9e7f46266a81a85ef51") + refundValueBig, _ := big.NewInt(0).SetString("299005000000000", 10) + initialTx := &outportcore.TxInfo{ + Transaction: &transaction.Transaction{ + Nonce: 0, + SndAddr: []byte("erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze"), + RcvAddr: []byte("erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze"), + GasLimit: 99000000, + GasPrice: 1000000000, + Value: big.NewInt(0), + InnerTransactions: []*transaction.Transaction{ + { + Nonce: 0, + SndAddr: []byte("erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg"), + RcvAddr: []byte("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6"), + RelayerAddr: []byte("erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze"), + GasLimit: 85000000, + GasPrice: 1000000000, + Data: []byte("createNewDelegationContract@00@00"), + Value: big.NewInt(0), + }, + }, + }, + FeeInfo: &outportcore.FeeInfo{Fee: big.NewInt(0)}, + } + + scr1 := &smartContractResult.SmartContractResult{ + Nonce: 0, + GasPrice: 1000000000, + GasLimit: 84900500, + SndAddr: []byte("erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg"), + RcvAddr: []byte("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6"), + Data: []byte("createNewDelegationContract@00@00"), + PrevTxHash: txHash, + OriginalTxHash: txHash, + } + scrWithRefund := &smartContractResult.SmartContractResult{ + Nonce: 1, + GasPrice: 1000000000, + GasLimit: 0, + Value: refundValueBig, + SndAddr: []byte("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6"), + RcvAddr: []byte("erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze"), + PrevTxHash: scrHash1, + OriginalTxHash: txHash, + ReturnMessage: []byte("gas refund for relayer"), + } + + pool := &outportcore.TransactionPool{ + Transactions: map[string]*outportcore.TxInfo{ + hex.EncodeToString(txHash): initialTx, + }, + SmartContractResults: map[string]*outportcore.SCRInfo{ + hex.EncodeToString(scrHash1): { + SmartContractResult: scr1, + FeeInfo: &outportcore.FeeInfo{ + Fee: big.NewInt(0), + }, + }, + hex.EncodeToString(scrWithRefundHash): { + SmartContractResult: scrWithRefund, + FeeInfo: &outportcore.FeeInfo{ + Fee: big.NewInt(0), + }, + }, + }, + } + + enableEpochsHandler := &enableEpochsHandlerMock.EnableEpochsHandlerStub{ + IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool { + return flag == common.GasPriceModifierFlag || + flag == common.RelayedTransactionsV3Flag || + flag == common.FixRelayedBaseCostFlag + }, + } + arg := prepareMockArg() + arg.EnableEpochsHandler = enableEpochsHandler + economicsConfig := testscommon.GetEconomicsConfig() + arg.TxFeeCalculator, _ = economics.NewEconomicsData(economics.ArgsNewEconomicsData{ + TxVersionChecker: &testscommon.TxVersionCheckerStub{}, + Economics: &economicsConfig, + EpochNotifier: &epochNotifier.EpochNotifierStub{}, + EnableEpochsHandler: enableEpochsHandler, + }) + txsFeeProc, err := NewTransactionsFeeProcessor(arg) + require.NotNil(t, txsFeeProc) + require.Nil(t, err) + + err = txsFeeProc.PutFeeAndGasUsed(pool, 0) + require.Nil(t, err) + require.Equal(t, big.NewInt(699500000000000), initialTx.GetFeeInfo().GetFee()) + require.Equal(t, uint64(55149500), initialTx.GetFeeInfo().GetGasUsed()) + require.Equal(t, "998505000000000", initialTx.GetFeeInfo().GetInitialPaidFee().String()) +} diff --git a/process/economics/economicsData.go b/process/economics/economicsData.go index a510447dab2..170377e62d3 100644 --- a/process/economics/economicsData.go +++ b/process/economics/economicsData.go @@ -591,8 +591,15 @@ 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 + txFeeAfterRefund := txFee.Sub(txFee, refundValue) + + gasPriceForProcessing := ed.GasPriceForProcessingInEpoch(tx, epoch) + gasUnitsRefunded := refundValue.Uint64() / gasPriceForProcessing + + gasUnitsConsideredForInitialFee := ed.computeRelayedTxV3MinGasLimit(tx) + gasUnitsUsed := gasUnitsConsideredForInitialFee - gasUnitsRefunded + + return gasUnitsUsed, txFeeAfterRefund } isPenalizedTooMuchGasFlagEnabled := ed.enableEpochsHandler.IsFlagEnabledInEpoch(common.PenalizedTooMuchGasFlag, epoch) @@ -682,6 +689,20 @@ func (ed *economicsData) ComputeGasLimitBasedOnBalanceInEpoch(tx data.Transactio return totalGasLimit, nil } +func (ed *economicsData) computeRelayedTxV3MinGasLimit(tx data.TransactionWithFeeHandler) uint64 { + relayedTxGasLimit := ed.ComputeGasLimit(tx) + relayedTxMinGasLimit := ed.MinGasLimit() + relayedTxGasLimitDiff := relayedTxGasLimit - relayedTxMinGasLimit // this may be positive if the relayed tx is guarded + + innerTxs := tx.GetUserTransactions() + totalGasLimit := relayedTxGasLimitDiff + relayedTxMinGasLimit*uint64(len(innerTxs)) + for _, innerTx := range innerTxs { + totalGasLimit += innerTx.GetGasLimit() + } + + return totalGasLimit +} + // IsInterfaceNil returns true if there is no value under the interface func (ed *economicsData) IsInterfaceNil() bool { return ed == nil diff --git a/process/economics/economicsData_test.go b/process/economics/economicsData_test.go index 5fdb8c369c2..f1a66e25dcd 100644 --- a/process/economics/economicsData_test.go +++ b/process/economics/economicsData_test.go @@ -1281,6 +1281,39 @@ func TestEconomicsData_ComputeGasUsedAndFeeBasedOnRefundValueSpecialBuiltInTooMu require.Equal(t, expectedFee, fee) } +func TestEconomicsData_ComputeGasUsedAndFeeBasedOnRefundValueRelayedV3(t *testing.T) { + t.Parallel() + + economicData, _ := economics.NewEconomicsData(createArgsForEconomicsDataRealFees()) + tx := &transaction.Transaction{ + GasPrice: 1000000000, + GasLimit: 99000000, + InnerTransactions: []*transaction.Transaction{ + { + GasPrice: 1000000000, + GasLimit: 85000000, + Data: []byte("createNewDelegationContract@00@00"), + }, + { + GasPrice: 1000000000, + GasLimit: 50000, + }, + { + GasPrice: 1000000000, + GasLimit: 50000, + }, + }, + } + + expectedGasUsed := uint64(55349500) + expectedFee, _ := big.NewInt(0).SetString("899500000000000", 10) + + refundValue, _ := big.NewInt(0).SetString("299005000000000", 10) + gasUsed, fee := economicData.ComputeGasUsedAndFeeBasedOnRefundValue(tx, refundValue) + require.Equal(t, expectedGasUsed, gasUsed) + require.Equal(t, expectedFee, fee) +} + func TestEconomicsData_ComputeGasLimitBasedOnBalance(t *testing.T) { t.Parallel() From f3b4b1342f950aea68ccdc2dd520abbfba2ac4d2 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 6 Sep 2024 15:11:50 +0300 Subject: [PATCH 396/434] fixes after review + extra test with multiple refunds --- .../transactionAPI/gasUsedAndFeeProcessor.go | 17 +- .../gasUsedAndFeeProcessor_test.go | 108 ++++++ .../testData/relayedV3WithOneRefund.json | 174 +++++++++ .../scInvokingWithMultipleRefunds.json | 347 ++++++++++++++++++ .../transactionsFeeProcessor.go | 11 +- 5 files changed, 631 insertions(+), 26 deletions(-) create mode 100644 node/external/transactionAPI/testData/relayedV3WithOneRefund.json create mode 100644 node/external/transactionAPI/testData/scInvokingWithMultipleRefunds.json diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index 342aa11cce9..5f4e2626fca 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -58,28 +58,19 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction hasRefundForSender := false totalRefunds := big.NewInt(0) - isRelayedV3 := len(tx.InnerTransactions) > 0 for _, scr := range tx.SmartContractResults { if !scr.IsRefund || scr.RcvAddr != tx.Sender { continue } - if scr.RcvAddr != tx.Sender { - continue - } - gfp.setGasUsedAndFeeBaseOnRefundValue(tx, scr.Value) hasRefundForSender = true totalRefunds.Add(totalRefunds, scr.Value) - if !isRelayedV3 { - break - } } - if isRelayedV3 { + if totalRefunds.Cmp(big.NewInt(0)) > 0 { gasUsed, fee = gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(tx, totalRefunds) tx.GasUsed = gasUsed tx.Fee = fee.String() - return } gfp.prepareTxWithResultsBasedOnLogs(tx, hasRefundForSender) @@ -182,12 +173,6 @@ func (gfp *gasUsedAndFeeProcessor) setGasUsedAndFeeBaseOnLogEvent(tx *transactio } } -func (gfp *gasUsedAndFeeProcessor) setGasUsedAndFeeBaseOnRefundValue(tx *transaction.ApiTransactionResult, refund *big.Int) { - gasUsed, fee := gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(tx, refund) - tx.GasUsed = gasUsed - tx.Fee = fee.String() -} - func (gfp *gasUsedAndFeeProcessor) isESDTOperationWithSCCall(tx *transaction.ApiTransactionResult) bool { isESDTTransferOperation := tx.Operation == core.BuiltInFunctionESDTTransfer || tx.Operation == core.BuiltInFunctionESDTNFTTransfer || tx.Operation == core.BuiltInFunctionMultiESDTNFTTransfer diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go index d5340e7903c..3c8bb6d05cd 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go @@ -251,3 +251,111 @@ func TestNFTTransferWithScCall(t *testing.T) { req.Equal(uint64(55_000_000), tx.GasUsed) req.Equal("822250000000000", tx.Fee) } + +func TestComputeAndAttachGasUsedAndFeeTransactionWithMultipleScrWithRefund(t *testing.T) { + t.Parallel() + + feeComp, _ := fee.NewFeeComputer(createEconomicsData(&enableEpochsHandlerMock.EnableEpochsHandlerStub{ + IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool { + return flag == common.GasPriceModifierFlag || + flag == common.PenalizedTooMuchGasFlag || + flag == common.FixRelayedBaseCostFlag + }, + })) + computer := fee.NewTestFeeComputer(feeComp) + + gasUsedAndFeeProc := newGasUsedAndFeeProcessor( + computer, + pubKeyConverter, + &testscommon.ArgumentParserMock{}, + &testscommon.MarshallerStub{}, + enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + ) + + txWithSRefundSCR := &transaction.ApiTransactionResult{} + err := core.LoadJsonFile(txWithSRefundSCR, "testData/scInvokingWithMultipleRefunds.json") + require.NoError(t, err) + + txWithSRefundSCR.Fee = "" + txWithSRefundSCR.GasUsed = 0 + + snd, _ := pubKeyConverter.Decode(txWithSRefundSCR.Sender) + rcv, _ := pubKeyConverter.Decode(txWithSRefundSCR.Receiver) + val, _ := big.NewInt(0).SetString(txWithSRefundSCR.Value, 10) + txWithSRefundSCR.Tx = &transaction.Transaction{ + Nonce: txWithSRefundSCR.Nonce, + Value: val, + RcvAddr: rcv, + SndAddr: snd, + GasPrice: txWithSRefundSCR.GasPrice, + GasLimit: txWithSRefundSCR.GasLimit, + Data: txWithSRefundSCR.Data, + } + + gasUsedAndFeeProc.computeAndAttachGasUsedAndFee(txWithSRefundSCR) + require.Equal(t, uint64(20313408), txWithSRefundSCR.GasUsed) + require.Equal(t, "319459080000000", txWithSRefundSCR.Fee) +} + +func TestComputeAndAttachGasUsedAndFeeRelayedV3WithRefund(t *testing.T) { + t.Parallel() + + feeComp, _ := fee.NewFeeComputer(createEconomicsData(&enableEpochsHandlerMock.EnableEpochsHandlerStub{ + IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool { + return flag == common.GasPriceModifierFlag || + flag == common.PenalizedTooMuchGasFlag || + flag == common.FixRelayedBaseCostFlag + }, + })) + computer := fee.NewTestFeeComputer(feeComp) + + gasUsedAndFeeProc := newGasUsedAndFeeProcessor( + computer, + pubKeyConverter, + &testscommon.ArgumentParserMock{}, + &testscommon.MarshallerStub{}, + enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), + ) + + txWithSRefundSCR := &transaction.ApiTransactionResult{} + err := core.LoadJsonFile(txWithSRefundSCR, "testData/relayedV3WithOneRefund.json") + require.NoError(t, err) + + txWithSRefundSCR.Fee = "" + txWithSRefundSCR.GasUsed = 0 + + innerTxs := make([]*transaction.Transaction, 0, len(txWithSRefundSCR.InnerTransactions)) + for _, innerTx := range txWithSRefundSCR.InnerTransactions { + snd, _ := pubKeyConverter.Decode(innerTx.Sender) + rcv, _ := pubKeyConverter.Decode(innerTx.Receiver) + val, _ := big.NewInt(0).SetString(innerTx.Value, 10) + + innerTxs = append(innerTxs, &transaction.Transaction{ + Nonce: innerTx.Nonce, + Value: val, + RcvAddr: rcv, + SndAddr: snd, + GasPrice: innerTx.GasPrice, + GasLimit: innerTx.GasLimit, + Data: innerTx.Data, + }) + } + + snd, _ := pubKeyConverter.Decode(txWithSRefundSCR.Sender) + rcv, _ := pubKeyConverter.Decode(txWithSRefundSCR.Receiver) + val, _ := big.NewInt(0).SetString(txWithSRefundSCR.Value, 10) + txWithSRefundSCR.Tx = &transaction.Transaction{ + Nonce: txWithSRefundSCR.Nonce, + Value: val, + RcvAddr: rcv, + SndAddr: snd, + GasPrice: txWithSRefundSCR.GasPrice, + GasLimit: txWithSRefundSCR.GasLimit, + Data: txWithSRefundSCR.Data, + InnerTransactions: innerTxs, + } + + gasUsedAndFeeProc.computeAndAttachGasUsedAndFee(txWithSRefundSCR) + require.Equal(t, uint64(55149500), txWithSRefundSCR.GasUsed) + require.Equal(t, "699500000000000", txWithSRefundSCR.Fee) +} diff --git a/node/external/transactionAPI/testData/relayedV3WithOneRefund.json b/node/external/transactionAPI/testData/relayedV3WithOneRefund.json new file mode 100644 index 00000000000..7b29520b9e9 --- /dev/null +++ b/node/external/transactionAPI/testData/relayedV3WithOneRefund.json @@ -0,0 +1,174 @@ +{ + "type": "normal", + "processingTypeOnSource": "RelayedTxV3", + "processingTypeOnDestination": "RelayedTxV3", + "hash": "af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa", + "nonce": 0, + "round": 19, + "epoch": 7, + "value": "0", + "receiver": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", + "sender": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", + "gasPrice": 1000000000, + "gasLimit": 99000000, + "gasUsed": 998505, + "signature": "416a2c25a9ccaabc0f6c55b870f9f028f87cbd617d77fa46ffeb488dbbb7a6e6b54c9baa464580ced73c1d7355a5d529e22d0e2bba3077adbc549bce1d596f0b", + "sourceShard": 1, + "destinationShard": 1, + "blockNonce": 19, + "blockHash": "fa0a0c232f0c1f44f6ba133c3d60f509146ecc845179b0658bcbef8ceded1f6e", + "notarizedAtSourceInMetaNonce": 21, + "NotarizedAtSourceInMetaHash": "dbb8f798ac83c2d0dbee9f37016ca1239e62a1d5a1bcda6a245167c80b285185", + "notarizedAtDestinationInMetaNonce": 21, + "notarizedAtDestinationInMetaHash": "dbb8f798ac83c2d0dbee9f37016ca1239e62a1d5a1bcda6a245167c80b285185", + "miniblockType": "TxBlock", + "miniblockHash": "b5ed48533fabb058444c6ce1303bf08b4dc11559b938f50a2e0e2dc8722dee20", + "hyperblockNonce": 21, + "hyperblockHash": "dbb8f798ac83c2d0dbee9f37016ca1239e62a1d5a1bcda6a245167c80b285185", + "timestamp": 1725611916, + "smartContractResults": [ + { + "hash": "4c58801e77c57e88294f21018145662e2fb1698fd5f1a1cf7b6f81f073f5cd6c", + "nonce": 0, + "value": 2501000000000000000000, + "receiver": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", + "sender": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg", + "relayerAddress": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", + "relayedValue": 0, + "data": "createNewDelegationContract@00@00", + "prevTxHash": "af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa", + "originalTxHash": "af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa", + "gasLimit": 84900500, + "gasPrice": 1000000000, + "callType": 0, + "logs": { + "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", + "events": [ + { + "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", + "identifier": "transferValueOnly", + "topics": [ + "h5RY6SJT9AAA", + "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAL///8=" + ], + "data": "RGVwbG95U21hcnRDb250cmFjdA==", + "additionalData": [ + "RGVwbG95U21hcnRDb250cmFjdA==", + "X2luaXQ=", + "AA==", + "AA==" + ] + }, + { + "address": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg", + "identifier": "delegate", + "topics": [ + "h5RY6SJT9AAA", + "h5RY6SJT9AAA", + "AQ==", + "h5RY6SJT9AAA", + "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAL///8=" + ], + "data": null, + "additionalData": null + }, + { + "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqhllllsajxzat", + "identifier": "transferValueOnly", + "topics": [ + "h5RY6SJT9AAA", + "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAB//8=" + ], + "data": "RXhlY3V0ZU9uRGVzdENvbnRleHQ=", + "additionalData": [ + "RXhlY3V0ZU9uRGVzdENvbnRleHQ=", + "c3Rha2U=" + ] + }, + { + "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqhllllsajxzat", + "identifier": "SCDeploy", + "topics": [ + "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAL///8=", + "gco962zRiYXE44sB1svVHsHJ93dxBewevdcKu+WyU7k=", + "/uYNe6O98aIOSpF57HocNxS4JQ7FILx6+N7MEN3oAQY=" + ], + "data": null, + "additionalData": null + }, + { + "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", + "identifier": "writeLog", + "topics": [ + "gco962zRiYXE44sB1svVHsHJ93dxBewevdcKu+WyU7k=" + ], + "data": "QDZmNmJAMDAwMDAwMDAwMDAwMDAwMDAwMDEwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMmZmZmZmZg==", + "additionalData": [ + "QDZmNmJAMDAwMDAwMDAwMDAwMDAwMDAwMDEwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMmZmZmZmZg==" + ] + } + ] + }, + "operation": "transfer", + "function": "createNewDelegationContract" + }, + { + "hash": "94e678f400192eeae3c84b3125c9d45301db619a3ecbf9e7f46266a81a85ef51", + "nonce": 1, + "value": 299005000000000, + "receiver": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", + "sender": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", + "prevTxHash": "4c58801e77c57e88294f21018145662e2fb1698fd5f1a1cf7b6f81f073f5cd6c", + "originalTxHash": "af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa", + "gasLimit": 0, + "gasPrice": 1000000000, + "callType": 0, + "returnMessage": "gas refund for relayer", + "logs": { + "address": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", + "events": [ + { + "address": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", + "identifier": "completedTxEvent", + "topics": [ + "TFiAHnfFfogpTyEBgUVmLi+xaY/V8aHPe2+B8HP1zWw=" + ], + "data": null, + "additionalData": null + } + ] + }, + "operation": "transfer", + "isRefund": true + } + ], + "status": "success", + "receivers": [ + "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6" + ], + "receiversShardIDs": [ + 4294967295 + ], + "operation": "transfer", + "initiallyPaidFee": "998505000000000", + "fee": "998505000000000", + "isRelayed": true, + "chainID": "chain", + "version": 2, + "options": 0, + "innerTransactions": [ + { + "nonce": 0, + "value": "2501000000000000000000", + "receiver": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", + "sender": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg", + "gasPrice": 1000000000, + "gasLimit": 85000000, + "data": "Y3JlYXRlTmV3RGVsZWdhdGlvbkNvbnRyYWN0QDAwQDAw", + "signature": "610493074d4e3ce0d8dcc5434cc67032f7e4acf3fd9f97525dba4865ba42408df8315824bf7b6268e2fa0d97fc51efe1a32f7928a799064a69d54bf063a19607", + "chainID": "chain", + "version": 2, + "relayer": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze" + } + ] +} \ No newline at end of file diff --git a/node/external/transactionAPI/testData/scInvokingWithMultipleRefunds.json b/node/external/transactionAPI/testData/scInvokingWithMultipleRefunds.json new file mode 100644 index 00000000000..b198565d1e8 --- /dev/null +++ b/node/external/transactionAPI/testData/scInvokingWithMultipleRefunds.json @@ -0,0 +1,347 @@ +{ + "type": "normal", + "processingTypeOnSource": "SCInvoking", + "processingTypeOnDestination": "SCInvoking", + "hash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "nonce": 5720, + "round": 21578404, + "epoch": 1498, + "value": "88000000000000000", + "receiver": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "sender": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", + "gasPrice": 1000000000, + "gasLimit": 45000000, + "gasUsed": 20313408, + "data": "YnV5QDEzMDA5N0A1NjQzNGY0OTRlMmQzMjY0MzQzNDMzNjRAMDFAMDE4NmEw", + "signature": "c3bea1fad86fc321a5016ec2283215b1371dc31a0b6297354bea303267193e3c27ca9589f9899a95e81b4d8cbd4d9fd6d27c765bde004f73efd9c882eb9e2d02", + "sourceShard": 1, + "destinationShard": 2, + "blockNonce": 21569950, + "blockHash": "16981d9bdf3710602366c1ad39c915597755d41aad6b5890fe3ecb7d453e8265", + "notarizedAtSourceInMetaNonce": 21554156, + "NotarizedAtSourceInMetaHash": "3886d224da560e51a1ff57912972bb6793628f5d5231bbafd54edfb81d700081", + "notarizedAtDestinationInMetaNonce": 21554160, + "notarizedAtDestinationInMetaHash": "e0058827df26c4d9ac36748f10a9e0ea56427b4ebfdc4e085bed6ae23eba0a87", + "miniblockType": "TxBlock", + "miniblockHash": "843a4b6fe2ec761ad6a23d5611d26d269c312fc6d1400a524a096102e35e594b", + "hyperblockNonce": 21554160, + "hyperblockHash": "e0058827df26c4d9ac36748f10a9e0ea56427b4ebfdc4e085bed6ae23eba0a87", + "timestamp": 1725588024, + "smartContractResults": [ + { + "hash": "ebc994f2e46037fbf16f3426ab3ea40a43b648620209372bcb158153053fb5f9", + "nonce": 5721, + "value": 246865920000000, + "receiver": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", + "sender": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "data": "@6f6b", + "prevTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "gasLimit": 0, + "gasPrice": 1000000000, + "callType": 0, + "logs": { + "address": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", + "events": [ + { + "address": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", + "identifier": "completedTxEvent", + "topics": [ + "KTJWMUYmQIrMhmeTy052LsSykl2847+xZuOeTe6mbpM=" + ], + "data": null, + "additionalData": null + } + ] + }, + "operation": "transfer", + "isRefund": true + }, + { + "hash": "402b39eba60202424565e224ab7121fd49eb8da366bc8b7b5d38496f1ce29f0d", + "nonce": 0, + "value": 2640000000000000, + "receiver": "erd1qqqqqqqqqqqqqpgq8538ku69p97lq4eug75y8d6g6yfwhd7c45qs4zvejt", + "sender": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "data": "depositRoyalties@0000000000000000050073175b6392a2f2661f2fb1fd2552787534433af98638", + "prevTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "gasLimit": 5500000, + "gasPrice": 1000000000, + "callType": 0, + "originalSender": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", + "operation": "transfer", + "function": "depositRoyalties" + }, + { + "hash": "9912a1b3d3918a79f9c560ff2d81b24b316a89cbefd195325807132319147502", + "nonce": 0, + "value": 84480000000000000, + "receiver": "erd1qtkml3n4lwy5hxdmdfe67nm5jg5v6kqrtsdjt76za35ms4nnvghsjfujaw", + "sender": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "prevTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "gasLimit": 0, + "gasPrice": 1000000000, + "callType": 0, + "originalSender": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", + "logs": { + "address": "erd1qtkml3n4lwy5hxdmdfe67nm5jg5v6kqrtsdjt76za35ms4nnvghsjfujaw", + "events": [ + { + "address": "erd1qtkml3n4lwy5hxdmdfe67nm5jg5v6kqrtsdjt76za35ms4nnvghsjfujaw", + "identifier": "completedTxEvent", + "topics": [ + "KTJWMUYmQIrMhmeTy052LsSykl2847+xZuOeTe6mbpM=" + ], + "data": null, + "additionalData": null + } + ] + }, + "operation": "transfer" + }, + { + "hash": "11c18202b3d117fa3301e8cbc72f6d258d56b70686fa174bffa331079b753b31", + "nonce": 0, + "value": 0, + "receiver": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", + "sender": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "data": "ESDTNFTTransfer@56434f494e2d326434343364@01@0186a0@08011204000186a022ef020801120d56696c6c6167657220436f696e1a200000000000000000050073175b6392a2f2661f2fb1fd2552787534433af9863820ac022a203e0e25256b5c0a5d5825deb7519eeae0468c2597533db2de10bb560ae317b7f0325068747470733a2f2f697066732e696f2f697066732f6261666b7265696864703577797975706a6174356a6d68726e706c786d3333616570737a67667333656733716c336e776f6268736d72376e747434325068747470733a2f2f697066732e696f2f697066732f6261666b726569636d727763366b6b7472646d6669797a66616f687664357977796f34746f343670776c6b3767363562366d6b74376835697a6f793a71746167733a6769616e74732c6769616e74732076696c6c6167652c6e70632c76696c6c6167657220636f696e3b6d657461646174613a6261666b726569636d727763366b6b7472646d6669797a66616f687664357977796f34746f343670776c6b3767363562366d6b74376835697a6f79", + "prevTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "gasLimit": 0, + "gasPrice": 1000000000, + "callType": 0, + "originalSender": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", + "logs": { + "address": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", + "events": [ + { + "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "identifier": "ESDTNFTTransfer", + "topics": [ + "VkNPSU4tMmQ0NDNk", + "AQ==", + "AYag", + "WMAwz/7NJw6hIL1AFS0hAj15dxDMBwXy8re0NHUdQV0=" + ], + "data": null, + "additionalData": [ + "", + "RVNEVE5GVFRyYW5zZmVy", + "VkNPSU4tMmQ0NDNk", + "AQ==", + "AYag", + "CAESBAABhqAi7wIIARINVmlsbGFnZXIgQ29pbhogAAAAAAAAAAAFAHMXW2OSovJmHy+x/SVSeHU0Qzr5hjggrAIqID4OJSVrXApdWCXet1Ge6uBGjCWXUz2y3hC7VgrjF7fwMlBodHRwczovL2lwZnMuaW8vaXBmcy9iYWZrcmVpaGRwNXd5eXVwamF0NWptaHJucGx4bTMzYWVwc3pnZnMzZWczcWwzbndvYmhzbXI3bnR0NDJQaHR0cHM6Ly9pcGZzLmlvL2lwZnMvYmFma3JlaWNtcndjNmtrdHJkbWZpeXpmYW9odmQ1eXd5bzR0bzQ2cHdsazdnNjViNm1rdDdoNWl6b3k6cXRhZ3M6Z2lhbnRzLGdpYW50cyB2aWxsYWdlLG5wYyx2aWxsYWdlciBjb2luO21ldGFkYXRhOmJhZmtyZWljbXJ3YzZra3RyZG1maXl6ZmFvaHZkNXl3eW80dG80NnB3bGs3ZzY1YjZta3Q3aDVpem95" + ] + }, + { + "address": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", + "identifier": "writeLog", + "topics": [ + "AAAAAAAAAAAFANOyiCjWIFISTwfc1Q7TGwgl9g7uFSY=" + ], + "data": "QDZmNmI=", + "additionalData": [ + "QDZmNmI=" + ] + }, + { + "address": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", + "identifier": "completedTxEvent", + "topics": [ + "KTJWMUYmQIrMhmeTy052LsSykl2847+xZuOeTe6mbpM=" + ], + "data": null, + "additionalData": null + } + ] + }, + "tokens": [ + "VCOIN-2d443d-01" + ], + "esdtValues": [ + "100000" + ], + "receivers": [ + "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l" + ], + "receiversShardIDs": [ + 1 + ], + "operation": "ESDTNFTTransfer" + }, + { + "hash": "3a814d0abb4c00c44bc8ba29007c51edc487daa17c7666efc9fad1f5a86d03a2", + "nonce": 1, + "value": 880000000000000, + "receiver": "erd1qqqqqqqqqqqqqpgq8538ku69p97lq4eug75y8d6g6yfwhd7c45qs4zvejt", + "sender": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "data": "deposit", + "prevTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "gasLimit": 3500000, + "gasPrice": 1000000000, + "callType": 0, + "originalSender": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", + "operation": "transfer", + "function": "deposit" + }, + { + "hash": "b7a2e5cf1ddad2630ccf8c703c9494b9b446e3a25ce362f6ec7c739448e41cbf", + "nonce": 1, + "value": 26131840000000, + "receiver": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "sender": "erd1qqqqqqqqqqqqqpgq8538ku69p97lq4eug75y8d6g6yfwhd7c45qs4zvejt", + "data": "@6f6b", + "prevTxHash": "402b39eba60202424565e224ab7121fd49eb8da366bc8b7b5d38496f1ce29f0d", + "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "gasLimit": 0, + "gasPrice": 1000000000, + "callType": 0, + "logs": { + "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "events": [ + { + "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "identifier": "completedTxEvent", + "topics": [ + "QCs566YCAkJFZeIkq3Eh/UnrjaNmvIt7XThJbxzinw0=" + ], + "data": null, + "additionalData": null + } + ] + }, + "operation": "transfer", + "isRefund": true + }, + { + "hash": "40d329ecd05ffa543a41efd216c463f2ec229432d7b5c1c9132af29e406f389d", + "nonce": 2, + "value": 7494280000000, + "receiver": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "sender": "erd1qqqqqqqqqqqqqpgq8538ku69p97lq4eug75y8d6g6yfwhd7c45qs4zvejt", + "data": "@6f6b", + "prevTxHash": "3a814d0abb4c00c44bc8ba29007c51edc487daa17c7666efc9fad1f5a86d03a2", + "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", + "gasLimit": 0, + "gasPrice": 1000000000, + "callType": 0, + "logs": { + "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "events": [ + { + "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "identifier": "completedTxEvent", + "topics": [ + "OoFNCrtMAMRLyLopAHxR7cSH2qF8dmbvyfrR9ahtA6I=" + ], + "data": null, + "additionalData": null + } + ] + }, + "operation": "transfer", + "isRefund": true + } + ], + "logs": { + "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "events": [ + { + "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "identifier": "buy", + "topics": [ + "YnV5X2V2ZW50", + "VkNPSU4tMmQ0NDNk", + "AQ==", + "EwCX", + "AYag", + "WMAwz/7NJw6hIL1AFS0hAj15dxDMBwXy8re0NHUdQV0=", + "zOQWYAA=", + "Au2/xnX7iUuZu2pzr090kijNWANcGyX7QuxpuFZzYi8=", + "RUdMRA==", + "", + "ZtpiOA==", + "", + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=", + "aeMS", + "AAAABEVHTEQAAAAAAAAAAAAAAAgBOKOIpDwAAA==" + ], + "data": null, + "additionalData": [ + "" + ] + }, + { + "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "identifier": "transferValueOnly", + "topics": [ + "CWEQ5jUAAA==", + "AAAAAAAAAAAFAD0ie3NFCX3wVzxHqEO3SNES67fYrQE=" + ], + "data": "VHJhbnNmZXJBbmRFeGVjdXRl", + "additionalData": [ + "VHJhbnNmZXJBbmRFeGVjdXRl", + "ZGVwb3NpdFJveWFsdGllcw==", + "AAAAAAAAAAAFAHMXW2OSovJmHy+x/SVSeHU0Qzr5hjg=" + ] + }, + { + "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "identifier": "transferValueOnly", + "topics": [ + "ASwiHMagAAA=", + "Au2/xnX7iUuZu2pzr090kijNWANcGyX7QuxpuFZzYi8=" + ], + "data": "RGlyZWN0Q2FsbA==", + "additionalData": [ + "RGlyZWN0Q2FsbA==", + "" + ] + }, + { + "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "identifier": "ESDTNFTTransfer", + "topics": [ + "VkNPSU4tMmQ0NDNk", + "AQ==", + "AYag", + "WMAwz/7NJw6hIL1AFS0hAj15dxDMBwXy8re0NHUdQV0=" + ], + "data": "RGlyZWN0Q2FsbA==", + "additionalData": [ + "RGlyZWN0Q2FsbA==", + "RVNEVE5GVFRyYW5zZmVy", + "VkNPSU4tMmQ0NDNk", + "AQ==", + "AYag", + "WMAwz/7NJw6hIL1AFS0hAj15dxDMBwXy8re0NHUdQV0=" + ] + }, + { + "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", + "identifier": "transferValueOnly", + "topics": [ + "AyBa92cAAA==", + "AAAAAAAAAAAFAD0ie3NFCX3wVzxHqEO3SNES67fYrQE=" + ], + "data": "VHJhbnNmZXJBbmRFeGVjdXRl", + "additionalData": [ + "VHJhbnNmZXJBbmRFeGVjdXRl", + "ZGVwb3NpdA==" + ] + } + ] + }, + "status": "success", + "operation": "transfer", + "function": "buy", + "initiallyPaidFee": "566325000000000", + "fee": "319459080000000", + "chainID": "1", + "version": 2, + "options": 0 +} diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index 23dcb3fedf1..ac92ce09790 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -156,7 +156,6 @@ func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *trans func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWithResults *transactionWithResults) { hasRefund := false totalRefunds := big.NewInt(0) - isRelayedV3 := len(txWithResults.GetTxHandler().GetUserTransactions()) > 0 for _, scrHandler := range txWithResults.scrs { scr, ok := scrHandler.GetTxHandler().(*smartContractResult.SmartContractResult) if !ok { @@ -164,23 +163,15 @@ func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWi } if isSCRForSenderWithRefund(scr, txHashHex, txWithResults.GetTxHandler()) || isRefundForRelayed(scr, txWithResults.GetTxHandler()) { - gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txWithResults.GetTxHandler(), scr.Value) - - txWithResults.GetFeeInfo().SetGasUsed(gasUsed) - txWithResults.GetFeeInfo().SetFee(fee) hasRefund = true totalRefunds.Add(totalRefunds, scr.Value) - if !isRelayedV3 { - break - } } } - if isRelayedV3 { + if totalRefunds.Cmp(big.NewInt(0)) > 0 { gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txWithResults.GetTxHandler(), totalRefunds) txWithResults.GetFeeInfo().SetGasUsed(gasUsed) txWithResults.GetFeeInfo().SetFee(fee) - return } tep.prepareTxWithResultsBasedOnLogs(txHashHex, txWithResults, hasRefund) From 51990e706e6fda906aaf3e4cc2bd68ecbe1f6268 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 6 Sep 2024 15:12:46 +0300 Subject: [PATCH 397/434] removed test --- .../transactionsFeeProcessor_test.go | 103 ------------------ 1 file changed, 103 deletions(-) diff --git a/outport/process/transactionsfee/transactionsFeeProcessor_test.go b/outport/process/transactionsfee/transactionsFeeProcessor_test.go index 8472ad1551d..6f0e0f94c35 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor_test.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor_test.go @@ -10,13 +10,10 @@ import ( 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-go/common" "github.com/multiversx/mx-chain-go/outport/mock" "github.com/multiversx/mx-chain-go/process" - "github.com/multiversx/mx-chain-go/process/economics" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" - "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" "github.com/multiversx/mx-chain-go/testscommon/genericMocks" "github.com/multiversx/mx-chain-go/testscommon/marshallerMock" logger "github.com/multiversx/mx-chain-logger-go" @@ -600,103 +597,3 @@ func TestMoveBalanceWithSignalError(t *testing.T) { require.Nil(t, err) require.Equal(t, uint64(225_500), initialTx.GetFeeInfo().GetGasUsed()) } - -func TestPutFeeAndGasUsedRelayedTxV3WithRefunds(t *testing.T) { - t.Parallel() - - txHash := []byte("af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa") - scrHash1 := []byte("4c58801e77c57e88294f21018145662e2fb1698fd5f1a1cf7b6f81f073f5cd6c") - scrWithRefundHash := []byte("94e678f400192eeae3c84b3125c9d45301db619a3ecbf9e7f46266a81a85ef51") - refundValueBig, _ := big.NewInt(0).SetString("299005000000000", 10) - initialTx := &outportcore.TxInfo{ - Transaction: &transaction.Transaction{ - Nonce: 0, - SndAddr: []byte("erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze"), - RcvAddr: []byte("erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze"), - GasLimit: 99000000, - GasPrice: 1000000000, - Value: big.NewInt(0), - InnerTransactions: []*transaction.Transaction{ - { - Nonce: 0, - SndAddr: []byte("erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg"), - RcvAddr: []byte("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6"), - RelayerAddr: []byte("erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze"), - GasLimit: 85000000, - GasPrice: 1000000000, - Data: []byte("createNewDelegationContract@00@00"), - Value: big.NewInt(0), - }, - }, - }, - FeeInfo: &outportcore.FeeInfo{Fee: big.NewInt(0)}, - } - - scr1 := &smartContractResult.SmartContractResult{ - Nonce: 0, - GasPrice: 1000000000, - GasLimit: 84900500, - SndAddr: []byte("erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg"), - RcvAddr: []byte("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6"), - Data: []byte("createNewDelegationContract@00@00"), - PrevTxHash: txHash, - OriginalTxHash: txHash, - } - scrWithRefund := &smartContractResult.SmartContractResult{ - Nonce: 1, - GasPrice: 1000000000, - GasLimit: 0, - Value: refundValueBig, - SndAddr: []byte("erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6"), - RcvAddr: []byte("erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze"), - PrevTxHash: scrHash1, - OriginalTxHash: txHash, - ReturnMessage: []byte("gas refund for relayer"), - } - - pool := &outportcore.TransactionPool{ - Transactions: map[string]*outportcore.TxInfo{ - hex.EncodeToString(txHash): initialTx, - }, - SmartContractResults: map[string]*outportcore.SCRInfo{ - hex.EncodeToString(scrHash1): { - SmartContractResult: scr1, - FeeInfo: &outportcore.FeeInfo{ - Fee: big.NewInt(0), - }, - }, - hex.EncodeToString(scrWithRefundHash): { - SmartContractResult: scrWithRefund, - FeeInfo: &outportcore.FeeInfo{ - Fee: big.NewInt(0), - }, - }, - }, - } - - enableEpochsHandler := &enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool { - return flag == common.GasPriceModifierFlag || - flag == common.RelayedTransactionsV3Flag || - flag == common.FixRelayedBaseCostFlag - }, - } - arg := prepareMockArg() - arg.EnableEpochsHandler = enableEpochsHandler - economicsConfig := testscommon.GetEconomicsConfig() - arg.TxFeeCalculator, _ = economics.NewEconomicsData(economics.ArgsNewEconomicsData{ - TxVersionChecker: &testscommon.TxVersionCheckerStub{}, - Economics: &economicsConfig, - EpochNotifier: &epochNotifier.EpochNotifierStub{}, - EnableEpochsHandler: enableEpochsHandler, - }) - txsFeeProc, err := NewTransactionsFeeProcessor(arg) - require.NotNil(t, txsFeeProc) - require.Nil(t, err) - - err = txsFeeProc.PutFeeAndGasUsed(pool, 0) - require.Nil(t, err) - require.Equal(t, big.NewInt(699500000000000), initialTx.GetFeeInfo().GetFee()) - require.Equal(t, uint64(55149500), initialTx.GetFeeInfo().GetGasUsed()) - require.Equal(t, "998505000000000", initialTx.GetFeeInfo().GetInitialPaidFee().String()) -} From 398361a09f24c15fc039f637fb02740a298a2274 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 6 Sep 2024 16:21:12 +0300 Subject: [PATCH 398/434] simplify jsons --- .../testData/relayedV3WithOneRefund.json | 120 +-------- .../scInvokingWithMultipleRefunds.json | 234 +----------------- 2 files changed, 2 insertions(+), 352 deletions(-) diff --git a/node/external/transactionAPI/testData/relayedV3WithOneRefund.json b/node/external/transactionAPI/testData/relayedV3WithOneRefund.json index 7b29520b9e9..c2b0484f877 100644 --- a/node/external/transactionAPI/testData/relayedV3WithOneRefund.json +++ b/node/external/transactionAPI/testData/relayedV3WithOneRefund.json @@ -4,28 +4,12 @@ "processingTypeOnDestination": "RelayedTxV3", "hash": "af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa", "nonce": 0, - "round": 19, - "epoch": 7, "value": "0", "receiver": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", "sender": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", "gasPrice": 1000000000, "gasLimit": 99000000, "gasUsed": 998505, - "signature": "416a2c25a9ccaabc0f6c55b870f9f028f87cbd617d77fa46ffeb488dbbb7a6e6b54c9baa464580ced73c1d7355a5d529e22d0e2bba3077adbc549bce1d596f0b", - "sourceShard": 1, - "destinationShard": 1, - "blockNonce": 19, - "blockHash": "fa0a0c232f0c1f44f6ba133c3d60f509146ecc845179b0658bcbef8ceded1f6e", - "notarizedAtSourceInMetaNonce": 21, - "NotarizedAtSourceInMetaHash": "dbb8f798ac83c2d0dbee9f37016ca1239e62a1d5a1bcda6a245167c80b285185", - "notarizedAtDestinationInMetaNonce": 21, - "notarizedAtDestinationInMetaHash": "dbb8f798ac83c2d0dbee9f37016ca1239e62a1d5a1bcda6a245167c80b285185", - "miniblockType": "TxBlock", - "miniblockHash": "b5ed48533fabb058444c6ce1303bf08b4dc11559b938f50a2e0e2dc8722dee20", - "hyperblockNonce": 21, - "hyperblockHash": "dbb8f798ac83c2d0dbee9f37016ca1239e62a1d5a1bcda6a245167c80b285185", - "timestamp": 1725611916, "smartContractResults": [ { "hash": "4c58801e77c57e88294f21018145662e2fb1698fd5f1a1cf7b6f81f073f5cd6c", @@ -33,84 +17,11 @@ "value": 2501000000000000000000, "receiver": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", "sender": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg", - "relayerAddress": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", - "relayedValue": 0, "data": "createNewDelegationContract@00@00", "prevTxHash": "af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa", "originalTxHash": "af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa", "gasLimit": 84900500, - "gasPrice": 1000000000, - "callType": 0, - "logs": { - "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", - "events": [ - { - "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", - "identifier": "transferValueOnly", - "topics": [ - "h5RY6SJT9AAA", - "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAL///8=" - ], - "data": "RGVwbG95U21hcnRDb250cmFjdA==", - "additionalData": [ - "RGVwbG95U21hcnRDb250cmFjdA==", - "X2luaXQ=", - "AA==", - "AA==" - ] - }, - { - "address": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg", - "identifier": "delegate", - "topics": [ - "h5RY6SJT9AAA", - "h5RY6SJT9AAA", - "AQ==", - "h5RY6SJT9AAA", - "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAL///8=" - ], - "data": null, - "additionalData": null - }, - { - "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqhllllsajxzat", - "identifier": "transferValueOnly", - "topics": [ - "h5RY6SJT9AAA", - "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAB//8=" - ], - "data": "RXhlY3V0ZU9uRGVzdENvbnRleHQ=", - "additionalData": [ - "RXhlY3V0ZU9uRGVzdENvbnRleHQ=", - "c3Rha2U=" - ] - }, - { - "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqhllllsajxzat", - "identifier": "SCDeploy", - "topics": [ - "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAL///8=", - "gco962zRiYXE44sB1svVHsHJ93dxBewevdcKu+WyU7k=", - "/uYNe6O98aIOSpF57HocNxS4JQ7FILx6+N7MEN3oAQY=" - ], - "data": null, - "additionalData": null - }, - { - "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", - "identifier": "writeLog", - "topics": [ - "gco962zRiYXE44sB1svVHsHJ93dxBewevdcKu+WyU7k=" - ], - "data": "QDZmNmJAMDAwMDAwMDAwMDAwMDAwMDAwMDEwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMmZmZmZmZg==", - "additionalData": [ - "QDZmNmJAMDAwMDAwMDAwMDAwMDAwMDAwMDEwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMmZmZmZmZg==" - ] - } - ] - }, - "operation": "transfer", - "function": "createNewDelegationContract" + "gasPrice": 1000000000 }, { "hash": "94e678f400192eeae3c84b3125c9d45301db619a3ecbf9e7f46266a81a85ef51", @@ -122,40 +33,11 @@ "originalTxHash": "af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa", "gasLimit": 0, "gasPrice": 1000000000, - "callType": 0, "returnMessage": "gas refund for relayer", - "logs": { - "address": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", - "events": [ - { - "address": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", - "identifier": "completedTxEvent", - "topics": [ - "TFiAHnfFfogpTyEBgUVmLi+xaY/V8aHPe2+B8HP1zWw=" - ], - "data": null, - "additionalData": null - } - ] - }, "operation": "transfer", "isRefund": true } ], - "status": "success", - "receivers": [ - "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6" - ], - "receiversShardIDs": [ - 4294967295 - ], - "operation": "transfer", - "initiallyPaidFee": "998505000000000", - "fee": "998505000000000", - "isRelayed": true, - "chainID": "chain", - "version": 2, - "options": 0, "innerTransactions": [ { "nonce": 0, diff --git a/node/external/transactionAPI/testData/scInvokingWithMultipleRefunds.json b/node/external/transactionAPI/testData/scInvokingWithMultipleRefunds.json index b198565d1e8..6223da3db9f 100644 --- a/node/external/transactionAPI/testData/scInvokingWithMultipleRefunds.json +++ b/node/external/transactionAPI/testData/scInvokingWithMultipleRefunds.json @@ -4,8 +4,6 @@ "processingTypeOnDestination": "SCInvoking", "hash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", "nonce": 5720, - "round": 21578404, - "epoch": 1498, "value": "88000000000000000", "receiver": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", "sender": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", @@ -13,20 +11,6 @@ "gasLimit": 45000000, "gasUsed": 20313408, "data": "YnV5QDEzMDA5N0A1NjQzNGY0OTRlMmQzMjY0MzQzNDMzNjRAMDFAMDE4NmEw", - "signature": "c3bea1fad86fc321a5016ec2283215b1371dc31a0b6297354bea303267193e3c27ca9589f9899a95e81b4d8cbd4d9fd6d27c765bde004f73efd9c882eb9e2d02", - "sourceShard": 1, - "destinationShard": 2, - "blockNonce": 21569950, - "blockHash": "16981d9bdf3710602366c1ad39c915597755d41aad6b5890fe3ecb7d453e8265", - "notarizedAtSourceInMetaNonce": 21554156, - "NotarizedAtSourceInMetaHash": "3886d224da560e51a1ff57912972bb6793628f5d5231bbafd54edfb81d700081", - "notarizedAtDestinationInMetaNonce": 21554160, - "notarizedAtDestinationInMetaHash": "e0058827df26c4d9ac36748f10a9e0ea56427b4ebfdc4e085bed6ae23eba0a87", - "miniblockType": "TxBlock", - "miniblockHash": "843a4b6fe2ec761ad6a23d5611d26d269c312fc6d1400a524a096102e35e594b", - "hyperblockNonce": 21554160, - "hyperblockHash": "e0058827df26c4d9ac36748f10a9e0ea56427b4ebfdc4e085bed6ae23eba0a87", - "timestamp": 1725588024, "smartContractResults": [ { "hash": "ebc994f2e46037fbf16f3426ab3ea40a43b648620209372bcb158153053fb5f9", @@ -39,21 +23,6 @@ "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", "gasLimit": 0, "gasPrice": 1000000000, - "callType": 0, - "logs": { - "address": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", - "events": [ - { - "address": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", - "identifier": "completedTxEvent", - "topics": [ - "KTJWMUYmQIrMhmeTy052LsSykl2847+xZuOeTe6mbpM=" - ], - "data": null, - "additionalData": null - } - ] - }, "operation": "transfer", "isRefund": true }, @@ -68,7 +37,6 @@ "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", "gasLimit": 5500000, "gasPrice": 1000000000, - "callType": 0, "originalSender": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", "operation": "transfer", "function": "depositRoyalties" @@ -83,22 +51,7 @@ "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", "gasLimit": 0, "gasPrice": 1000000000, - "callType": 0, "originalSender": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", - "logs": { - "address": "erd1qtkml3n4lwy5hxdmdfe67nm5jg5v6kqrtsdjt76za35ms4nnvghsjfujaw", - "events": [ - { - "address": "erd1qtkml3n4lwy5hxdmdfe67nm5jg5v6kqrtsdjt76za35ms4nnvghsjfujaw", - "identifier": "completedTxEvent", - "topics": [ - "KTJWMUYmQIrMhmeTy052LsSykl2847+xZuOeTe6mbpM=" - ], - "data": null, - "additionalData": null - } - ] - }, "operation": "transfer" }, { @@ -112,64 +65,7 @@ "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", "gasLimit": 0, "gasPrice": 1000000000, - "callType": 0, "originalSender": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", - "logs": { - "address": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", - "events": [ - { - "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", - "identifier": "ESDTNFTTransfer", - "topics": [ - "VkNPSU4tMmQ0NDNk", - "AQ==", - "AYag", - "WMAwz/7NJw6hIL1AFS0hAj15dxDMBwXy8re0NHUdQV0=" - ], - "data": null, - "additionalData": [ - "", - "RVNEVE5GVFRyYW5zZmVy", - "VkNPSU4tMmQ0NDNk", - "AQ==", - "AYag", - "CAESBAABhqAi7wIIARINVmlsbGFnZXIgQ29pbhogAAAAAAAAAAAFAHMXW2OSovJmHy+x/SVSeHU0Qzr5hjggrAIqID4OJSVrXApdWCXet1Ge6uBGjCWXUz2y3hC7VgrjF7fwMlBodHRwczovL2lwZnMuaW8vaXBmcy9iYWZrcmVpaGRwNXd5eXVwamF0NWptaHJucGx4bTMzYWVwc3pnZnMzZWczcWwzbndvYmhzbXI3bnR0NDJQaHR0cHM6Ly9pcGZzLmlvL2lwZnMvYmFma3JlaWNtcndjNmtrdHJkbWZpeXpmYW9odmQ1eXd5bzR0bzQ2cHdsazdnNjViNm1rdDdoNWl6b3k6cXRhZ3M6Z2lhbnRzLGdpYW50cyB2aWxsYWdlLG5wYyx2aWxsYWdlciBjb2luO21ldGFkYXRhOmJhZmtyZWljbXJ3YzZra3RyZG1maXl6ZmFvaHZkNXl3eW80dG80NnB3bGs3ZzY1YjZta3Q3aDVpem95" - ] - }, - { - "address": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", - "identifier": "writeLog", - "topics": [ - "AAAAAAAAAAAFANOyiCjWIFISTwfc1Q7TGwgl9g7uFSY=" - ], - "data": "QDZmNmI=", - "additionalData": [ - "QDZmNmI=" - ] - }, - { - "address": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", - "identifier": "completedTxEvent", - "topics": [ - "KTJWMUYmQIrMhmeTy052LsSykl2847+xZuOeTe6mbpM=" - ], - "data": null, - "additionalData": null - } - ] - }, - "tokens": [ - "VCOIN-2d443d-01" - ], - "esdtValues": [ - "100000" - ], - "receivers": [ - "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l" - ], - "receiversShardIDs": [ - 1 - ], "operation": "ESDTNFTTransfer" }, { @@ -183,7 +79,6 @@ "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", "gasLimit": 3500000, "gasPrice": 1000000000, - "callType": 0, "originalSender": "erd1trqrpnl7e5nsagfqh4qp2tfpqg7hjacsesrstuhjk76rgagag9ws87gy6l", "operation": "transfer", "function": "deposit" @@ -199,21 +94,6 @@ "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", "gasLimit": 0, "gasPrice": 1000000000, - "callType": 0, - "logs": { - "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", - "events": [ - { - "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", - "identifier": "completedTxEvent", - "topics": [ - "QCs566YCAkJFZeIkq3Eh/UnrjaNmvIt7XThJbxzinw0=" - ], - "data": null, - "additionalData": null - } - ] - }, "operation": "transfer", "isRefund": true }, @@ -228,120 +108,8 @@ "originalTxHash": "293256314626408acc866793cb4e762ec4b2925dbce3bfb166e39e4deea66e93", "gasLimit": 0, "gasPrice": 1000000000, - "callType": 0, - "logs": { - "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", - "events": [ - { - "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", - "identifier": "completedTxEvent", - "topics": [ - "OoFNCrtMAMRLyLopAHxR7cSH2qF8dmbvyfrR9ahtA6I=" - ], - "data": null, - "additionalData": null - } - ] - }, "operation": "transfer", "isRefund": true } - ], - "logs": { - "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", - "events": [ - { - "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", - "identifier": "buy", - "topics": [ - "YnV5X2V2ZW50", - "VkNPSU4tMmQ0NDNk", - "AQ==", - "EwCX", - "AYag", - "WMAwz/7NJw6hIL1AFS0hAj15dxDMBwXy8re0NHUdQV0=", - "zOQWYAA=", - "Au2/xnX7iUuZu2pzr090kijNWANcGyX7QuxpuFZzYi8=", - "RUdMRA==", - "", - "ZtpiOA==", - "", - "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=", - "aeMS", - "AAAABEVHTEQAAAAAAAAAAAAAAAgBOKOIpDwAAA==" - ], - "data": null, - "additionalData": [ - "" - ] - }, - { - "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", - "identifier": "transferValueOnly", - "topics": [ - "CWEQ5jUAAA==", - "AAAAAAAAAAAFAD0ie3NFCX3wVzxHqEO3SNES67fYrQE=" - ], - "data": "VHJhbnNmZXJBbmRFeGVjdXRl", - "additionalData": [ - "VHJhbnNmZXJBbmRFeGVjdXRl", - "ZGVwb3NpdFJveWFsdGllcw==", - "AAAAAAAAAAAFAHMXW2OSovJmHy+x/SVSeHU0Qzr5hjg=" - ] - }, - { - "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", - "identifier": "transferValueOnly", - "topics": [ - "ASwiHMagAAA=", - "Au2/xnX7iUuZu2pzr090kijNWANcGyX7QuxpuFZzYi8=" - ], - "data": "RGlyZWN0Q2FsbA==", - "additionalData": [ - "RGlyZWN0Q2FsbA==", - "" - ] - }, - { - "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", - "identifier": "ESDTNFTTransfer", - "topics": [ - "VkNPSU4tMmQ0NDNk", - "AQ==", - "AYag", - "WMAwz/7NJw6hIL1AFS0hAj15dxDMBwXy8re0NHUdQV0=" - ], - "data": "RGlyZWN0Q2FsbA==", - "additionalData": [ - "RGlyZWN0Q2FsbA==", - "RVNEVE5GVFRyYW5zZmVy", - "VkNPSU4tMmQ0NDNk", - "AQ==", - "AYag", - "WMAwz/7NJw6hIL1AFS0hAj15dxDMBwXy8re0NHUdQV0=" - ] - }, - { - "address": "erd1qqqqqqqqqqqqqpgq6wegs2xkypfpync8mn2sa5cmpqjlvrhwz5nqgepyg8", - "identifier": "transferValueOnly", - "topics": [ - "AyBa92cAAA==", - "AAAAAAAAAAAFAD0ie3NFCX3wVzxHqEO3SNES67fYrQE=" - ], - "data": "VHJhbnNmZXJBbmRFeGVjdXRl", - "additionalData": [ - "VHJhbnNmZXJBbmRFeGVjdXRl", - "ZGVwb3NpdA==" - ] - } - ] - }, - "status": "success", - "operation": "transfer", - "function": "buy", - "initiallyPaidFee": "566325000000000", - "fee": "319459080000000", - "chainID": "1", - "version": 2, - "options": 0 + ] } From 0378c6dfd7900cfb1d7b5b7a2191cfce168713e7 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 9 Sep 2024 11:32:05 +0300 Subject: [PATCH 399/434] updated deps to tags --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 92a18248de8..857521f3966 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.1.0 - github.com/multiversx/mx-chain-core-go v1.2.22-0.20240823091930-22b700471ada + github.com/multiversx/mx-chain-core-go v1.2.22 github.com/multiversx/mx-chain-crypto-go v1.2.12 - github.com/multiversx/mx-chain-es-indexer-go v1.7.5-0.20240807095116-4f2f595e52d9 + github.com/multiversx/mx-chain-es-indexer-go v1.7.8 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.20240903110629-ee357f94b63c - github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240903110843-ed790853265d + github.com/multiversx/mx-chain-vm-common-go v1.5.14 + github.com/multiversx/mx-chain-vm-go v1.5.32 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 21ac2f73c29..5eb00724155 100644 --- a/go.sum +++ b/go.sum @@ -387,22 +387,22 @@ 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.20240823091930-22b700471ada h1:Yi4gpXr/LzpLR2Soca5SNC/NRGnPCrD5FyGKShGLFpE= -github.com/multiversx/mx-chain-core-go v1.2.22-0.20240823091930-22b700471ada/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.22 h1:yDYrvoQOBbsDerEp7L3+de5AfMy3pTF333gWPpd+FNk= +github.com/multiversx/mx-chain-core-go v1.2.22/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.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-es-indexer-go v1.7.8 h1:ZDKTXkQhQ7lLi6huVrBTUssVEqCvaCxGH4Y52GapboQ= +github.com/multiversx/mx-chain-es-indexer-go v1.7.8/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.14-0.20240903110629-ee357f94b63c h1:VLAdXl0NsnMWBuJZUJPxK8qK1AKyEzqSoQ7I8NOj0t4= -github.com/multiversx/mx-chain-vm-common-go v1.5.14-0.20240903110629-ee357f94b63c/go.mod h1:sN471lwUKZMIfhNEDgHnSUR5SOv+BCoxF2kv2AnOCj8= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240903110843-ed790853265d h1:TSObh+pVpKdjBb0eyLHjBRULIZU+v6voSJd2CNprllg= -github.com/multiversx/mx-chain-vm-go v1.5.32-0.20240903110843-ed790853265d/go.mod h1:2x0I5wbWgrVKj7zeVSWITWqdnqmAiuBfsAdrdbAViQE= +github.com/multiversx/mx-chain-vm-common-go v1.5.14 h1:QauClmsZVKnShhvAVkXndO4j25q361SPvt9dqdx1qlM= +github.com/multiversx/mx-chain-vm-common-go v1.5.14/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= +github.com/multiversx/mx-chain-vm-go v1.5.32 h1:bEHKmXhjo2aHsx+cFDtKRV7/uq0yBip47gj9Xrl/B84= +github.com/multiversx/mx-chain-vm-go v1.5.32/go.mod h1:yjOCetRG0wFXm+IWGyioipdR959TYoR+FRdAGVq8xXw= 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 0e3adbbb2a81955a82e87f83f10d0705e3f83916 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 11 Sep 2024 10:41:06 +0300 Subject: [PATCH 400/434] proper fix for fee/initially paid fee for relayed after fix --- .../transactionAPI/gasUsedAndFeeProcessor.go | 7 +++++- .../transactionsFeeProcessor.go | 22 +++++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index 5f4e2626fca..7f957f50ece 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -50,7 +50,8 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction } initialTotalFee, isRelayed := gfp.getFeeOfRelayed(tx) - if isRelayed && isFeeFixActive { + isRelayedAfterFix := isRelayed && isFeeFixActive + if isRelayedAfterFix { tx.InitiallyPaidFee = initialTotalFee.String() tx.Fee = initialTotalFee.String() tx.GasUsed = big.NewInt(0).Div(initialTotalFee, big.NewInt(0).SetUint64(tx.GasPrice)).Uint64() @@ -73,6 +74,10 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction tx.Fee = fee.String() } + if isRelayedAfterFix { + return + } + gfp.prepareTxWithResultsBasedOnLogs(tx, hasRefundForSender) } diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index ac92ce09790..dccf0366b23 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -140,20 +140,20 @@ func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *trans continue } - if isRelayedTx(txWithResult) && isFeeFixActive { - 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()) - } + totalFee, isRelayed := tep.getFeeOfRelayed(txWithResult) + isRelayedAfterFix := isRelayed && isFeeFixActive + if isRelayedAfterFix { + feeInfo.SetFee(totalFee) + feeInfo.SetInitialPaidFee(totalFee) + feeInfo.SetGasUsed(big.NewInt(0).Div(totalFee, big.NewInt(0).SetUint64(txHandler.GetGasPrice())).Uint64()) + } - tep.prepareTxWithResults(txHashHex, txWithResult) + tep.prepareTxWithResults(txHashHex, txWithResult, isRelayedAfterFix) } } -func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWithResults *transactionWithResults) { +func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWithResults *transactionWithResults, isRelayedAfterFix bool) { hasRefund := false totalRefunds := big.NewInt(0) for _, scrHandler := range txWithResults.scrs { @@ -174,6 +174,10 @@ func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWi txWithResults.GetFeeInfo().SetFee(fee) } + if isRelayedAfterFix { + return + } + tep.prepareTxWithResultsBasedOnLogs(txHashHex, txWithResults, hasRefund) } From cfc8c78746bc60c8ed919c3f7b08788714dc5040 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 11 Sep 2024 13:11:10 +0300 Subject: [PATCH 401/434] added unittest --- .../gasUsedAndFeeProcessor_test.go | 50 +++++++++++++++ .../testData/failedRelayedV1.json | 61 +++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 node/external/transactionAPI/testData/failedRelayedV1.json diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go index 3c8bb6d05cd..7e4011e0f2c 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go @@ -7,10 +7,12 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/pubkeyConverter" "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/node/external/timemachine/fee" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/process/economics" + "github.com/multiversx/mx-chain-go/process/smartContract" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" @@ -359,3 +361,51 @@ func TestComputeAndAttachGasUsedAndFeeRelayedV3WithRefund(t *testing.T) { require.Equal(t, uint64(55149500), txWithSRefundSCR.GasUsed) require.Equal(t, "699500000000000", txWithSRefundSCR.Fee) } + +func TestComputeAndAttachGasUsedAndFeeFailedRelayedV1(t *testing.T) { + t.Parallel() + + enableEpochsHandler := &enableEpochsHandlerMock.EnableEpochsHandlerStub{ + IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool { + return flag == common.GasPriceModifierFlag || + flag == common.PenalizedTooMuchGasFlag || + flag == common.FixRelayedBaseCostFlag + }, + } + feeComp, _ := fee.NewFeeComputer(createEconomicsData(enableEpochsHandler)) + computer := fee.NewTestFeeComputer(feeComp) + + gasUsedAndFeeProc := newGasUsedAndFeeProcessor( + computer, + pubKeyConverter, + smartContract.NewArgumentParser(), + &marshal.JsonMarshalizer{}, + enableEpochsHandler, + ) + + txWithSRefundSCR := &transaction.ApiTransactionResult{} + err := core.LoadJsonFile(txWithSRefundSCR, "testData/failedRelayedV1.json") + require.NoError(t, err) + + snd, _ := pubKeyConverter.Decode(txWithSRefundSCR.Sender) + rcv, _ := pubKeyConverter.Decode(txWithSRefundSCR.Receiver) + val, _ := big.NewInt(0).SetString(txWithSRefundSCR.Value, 10) + txWithSRefundSCR.Tx = &transaction.Transaction{ + Nonce: txWithSRefundSCR.Nonce, + Value: val, + RcvAddr: rcv, + SndAddr: snd, + GasPrice: txWithSRefundSCR.GasPrice, + GasLimit: txWithSRefundSCR.GasLimit, + Data: txWithSRefundSCR.Data, + } + + txWithSRefundSCR.InitiallyPaidFee = "" + txWithSRefundSCR.Fee = "" + txWithSRefundSCR.GasUsed = 0 + + gasUsedAndFeeProc.computeAndAttachGasUsedAndFee(txWithSRefundSCR) + require.Equal(t, uint64(1274230), txWithSRefundSCR.GasUsed) + require.Equal(t, "1274230000000000", txWithSRefundSCR.Fee) + require.Equal(t, "1274230000000000", txWithSRefundSCR.InitiallyPaidFee) +} diff --git a/node/external/transactionAPI/testData/failedRelayedV1.json b/node/external/transactionAPI/testData/failedRelayedV1.json new file mode 100644 index 00000000000..5f1a72c8c33 --- /dev/null +++ b/node/external/transactionAPI/testData/failedRelayedV1.json @@ -0,0 +1,61 @@ +{ + "type": "normal", + "processingTypeOnSource": "RelayedTx", + "processingTypeOnDestination": "RelayedTx", + "hash": "efe3e8fa273fc2db4d559185e9729f7bbf17f617e28424b6a6533fb193caf561", + "nonce": 125, + "value": "0", + "receiver": "erd1x9hax7mdqux0nak9ahxrc2g75h5ckpfs4ssr8l7tkxscaa293x6q8ffd4e", + "sender": "erd1tn62hjp72rznp8vq0lplva5csav6rccpqqdungpxtqz0g2hcq6uq9k4cc6", + "gasPrice": 1000000000, + "gasLimit": 6148000, + "gasUsed": 6148000, + "data": "cmVsYXllZFR4QDdiMjI2ZTZmNmU2MzY1MjIzYTM0MzcyYzIyNzM2NTZlNjQ2NTcyMjIzYTIyNGQ1NzJmNTQ2NTMyMzA0ODQ0NTA2ZTMyNzg2NTMzNGQ1MDQzNmI2NTcwNjU2ZDRjNDI1NDQzNzM0OTQ0NTAyZjc5Mzc0NzY4NmE3NjU2NDY2OTYyNTEzZDIyMmMyMjcyNjU2MzY1Njk3NjY1NzIyMjNhMjI0MTQxNDE0MTQxNDE0MTQxNDE0MTQxNDY0MTQ0MzU1MzM3NTg2MjUwNzk1NTQzNzU3NzRiNDk1MTM0NmUzNzMxNTE3OTZmNGE1ODM1NzM1NDQyNzI2NzNkMjIyYzIyNzY2MTZjNzU2NTIyM2EzMTMwMzAzMDMwMzAzMDMwMzAzMDMwMzAzMDMwMzAzMDMwMzAzMDJjMjI2NzYxNzM1MDcyNjk2MzY1MjIzYTMxMzAzMDMwMzAzMDMwMzAzMDMwMmMyMjY3NjE3MzRjNjk2ZDY5NzQyMjNhMzUzMDMwMzAzMDMwMzAyYzIyNjQ2MTc0NjEyMjNhMjI1OTU3NTI2YjUxNDQ0MTc4NTE0NDQxNzk1MTQ0NDE3YTUxNDQ0MTMwNTE0NDQxMzEyMjJjMjI3MzY5Njc2ZTYxNzQ3NTcyNjUyMjNhMjI3NjRjNjQ2ZDMyMmY0ZTQ0NTQ0NDc3MzgzMTMxNTEzMDYyNzgyYjU4NGI1MTc4NTA0NTJmNzY0OTU3NDM2ODRlNzI2OTU1NmE3ODcyNzAyZjU5Mzg1MDRlNzI0ZDQ1NmM2NTQ3NmUzNTMxNTM3NjUyNTk2NDQ3MzQ2ZjQ3NTc3MjQ5Njk0MzQ4Mzk2YTMxNzY0ZjRiNmY1OTJmNDg1NTUyNjE0ZTQxNDg0MjUxM2QzZDIyMmMyMjYzNjg2MTY5NmU0OTQ0MjIzYTIyNTY0MTNkM2QyMjJjMjI3NjY1NzI3MzY5NmY2ZTIyM2EzMjdk", + "sourceShard": 0, + "destinationShard": 0, + "logs": { + "address": "erd1qqqqqqqqqqqqqpgq8efw6ak0e9q2as9zzr38aa2r9gy4lxcnq6uqpefzvu", + "events": [ + { + "address": "erd1qqqqqqqqqqqqqpgq8efw6ak0e9q2as9zzr38aa2r9gy4lxcnq6uqpefzvu", + "identifier": "signalError", + "topics": [ + "MW/Te20HDPn2xe3MPCkepemLBTCsIDP/y7GhjvVFibQ=", + "ZnVuY3Rpb24gZG9lcyBub3QgYWNjZXB0IEVHTEQgcGF5bWVudA==" + ], + "data": "QDY1Nzg2NTYzNzU3NDY5NmY2ZTIwNjY2MTY5NmM2NTY0", + "additionalData": [ + "QDY1Nzg2NTYzNzU3NDY5NmY2ZTIwNjY2MTY5NmM2NTY0" + ] + }, + { + "address": "erd1qqqqqqqqqqqqqpgq8efw6ak0e9q2as9zzr38aa2r9gy4lxcnq6uqpefzvu", + "identifier": "signalError", + "topics": [ + "XPSryD5QxTCdgH/D9naYh1mh4wEAG8mgJlgE9Cr4Brg=", + "ZnVuY3Rpb24gZG9lcyBub3QgYWNjZXB0IEVHTEQgcGF5bWVudA==" + ], + "data": null, + "additionalData": [ + "" + ] + }, + { + "address": "erd1x9hax7mdqux0nak9ahxrc2g75h5ckpfs4ssr8l7tkxscaa293x6q8ffd4e", + "identifier": "internalVMErrors", + "topics": [ + "AAAAAAAAAAAFAD5S7XbPyUCuwKIQ4n71QyoJX5sTBrg=", + "YWRk" + ], + "data": "CglydW50aW1lLmdvOjg1NiBbZXhlY3V0aW9uIGZhaWxlZF0gW2FkZF0KCXJ1bnRpbWUuZ286ODU2IFtleGVjdXRpb24gZmFpbGVkXSBbYWRkXQoJcnVudGltZS5nbzo4NTMgW2Z1bmN0aW9uIGRvZXMgbm90IGFjY2VwdCBFR0xEIHBheW1lbnRd", + "additionalData": [ + "CglydW50aW1lLmdvOjg1NiBbZXhlY3V0aW9uIGZhaWxlZF0gW2FkZF0KCXJ1bnRpbWUuZ286ODU2IFtleGVjdXRpb24gZmFpbGVkXSBbYWRkXQoJcnVudGltZS5nbzo4NTMgW2Z1bmN0aW9uIGRvZXMgbm90IGFjY2VwdCBFR0xEIHBheW1lbnRd" + ] + } + ] + }, + "status": "success", + "operation": "transfer", + "function": "add", + "isRelayed": true +} \ No newline at end of file From 1f2d5930888ca7c98ff7ad052d9c765ad382c9ca Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 11 Sep 2024 13:13:17 +0300 Subject: [PATCH 402/434] new line at the end of newly added test json --- node/external/transactionAPI/testData/failedRelayedV1.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/node/external/transactionAPI/testData/failedRelayedV1.json b/node/external/transactionAPI/testData/failedRelayedV1.json index 5f1a72c8c33..e2b1be88bee 100644 --- a/node/external/transactionAPI/testData/failedRelayedV1.json +++ b/node/external/transactionAPI/testData/failedRelayedV1.json @@ -9,7 +9,6 @@ "sender": "erd1tn62hjp72rznp8vq0lplva5csav6rccpqqdungpxtqz0g2hcq6uq9k4cc6", "gasPrice": 1000000000, "gasLimit": 6148000, - "gasUsed": 6148000, "data": "cmVsYXllZFR4QDdiMjI2ZTZmNmU2MzY1MjIzYTM0MzcyYzIyNzM2NTZlNjQ2NTcyMjIzYTIyNGQ1NzJmNTQ2NTMyMzA0ODQ0NTA2ZTMyNzg2NTMzNGQ1MDQzNmI2NTcwNjU2ZDRjNDI1NDQzNzM0OTQ0NTAyZjc5Mzc0NzY4NmE3NjU2NDY2OTYyNTEzZDIyMmMyMjcyNjU2MzY1Njk3NjY1NzIyMjNhMjI0MTQxNDE0MTQxNDE0MTQxNDE0MTQxNDY0MTQ0MzU1MzM3NTg2MjUwNzk1NTQzNzU3NzRiNDk1MTM0NmUzNzMxNTE3OTZmNGE1ODM1NzM1NDQyNzI2NzNkMjIyYzIyNzY2MTZjNzU2NTIyM2EzMTMwMzAzMDMwMzAzMDMwMzAzMDMwMzAzMDMwMzAzMDMwMzAzMDJjMjI2NzYxNzM1MDcyNjk2MzY1MjIzYTMxMzAzMDMwMzAzMDMwMzAzMDMwMmMyMjY3NjE3MzRjNjk2ZDY5NzQyMjNhMzUzMDMwMzAzMDMwMzAyYzIyNjQ2MTc0NjEyMjNhMjI1OTU3NTI2YjUxNDQ0MTc4NTE0NDQxNzk1MTQ0NDE3YTUxNDQ0MTMwNTE0NDQxMzEyMjJjMjI3MzY5Njc2ZTYxNzQ3NTcyNjUyMjNhMjI3NjRjNjQ2ZDMyMmY0ZTQ0NTQ0NDc3MzgzMTMxNTEzMDYyNzgyYjU4NGI1MTc4NTA0NTJmNzY0OTU3NDM2ODRlNzI2OTU1NmE3ODcyNzAyZjU5Mzg1MDRlNzI0ZDQ1NmM2NTQ3NmUzNTMxNTM3NjUyNTk2NDQ3MzQ2ZjQ3NTc3MjQ5Njk0MzQ4Mzk2YTMxNzY0ZjRiNmY1OTJmNDg1NTUyNjE0ZTQxNDg0MjUxM2QzZDIyMmMyMjYzNjg2MTY5NmU0OTQ0MjIzYTIyNTY0MTNkM2QyMjJjMjI3NjY1NzI3MzY5NmY2ZTIyM2EzMjdk", "sourceShard": 0, "destinationShard": 0, @@ -58,4 +57,4 @@ "operation": "transfer", "function": "add", "isRelayed": true -} \ No newline at end of file +} From 7becc67db2e307548cb0ebaf144d2141758b22fe Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 11 Sep 2024 13:40:56 +0300 Subject: [PATCH 403/434] added missing epoch for inner tx --- node/external/transactionAPI/gasUsedAndFeeProcessor.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index 7f957f50ece..530b6b81b3d 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -125,7 +125,8 @@ func (gfp *gasUsedAndFeeProcessor) handleRelayedV1(args [][]byte, tx *transactio fee := gfp.feeComputer.ComputeTxFeeBasedOnGasUsed(tx, gasUsed) innerFee := gfp.feeComputer.ComputeTransactionFee(&transaction.ApiTransactionResult{ - Tx: innerTx, + Tx: innerTx, + Epoch: tx.Epoch, }) return big.NewInt(0).Add(fee, innerFee), true @@ -146,7 +147,8 @@ func (gfp *gasUsedAndFeeProcessor) handleRelayedV2(args [][]byte, tx *transactio fee := gfp.feeComputer.ComputeTxFeeBasedOnGasUsed(tx, gasUsed) innerFee := gfp.feeComputer.ComputeTransactionFee(&transaction.ApiTransactionResult{ - Tx: innerTx, + Tx: innerTx, + Epoch: tx.Epoch, }) return big.NewInt(0).Add(fee, innerFee), true From e37b5c29f7b8702edf63d1d0e6d3804e92dbb09b Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Thu, 12 Sep 2024 14:55:08 +0300 Subject: [PATCH 404/434] update go mod and refactor some tests --- go.mod | 4 +- go.sum | 8 +- .../vm/esdtImprovements_test.go | 73 ++++++++++++++++++- 3 files changed, 78 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index 857521f3966..f7148271aeb 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 - github.com/multiversx/mx-chain-vm-go v1.5.32 + github.com/multiversx/mx-chain-vm-common-go v1.5.15-0.20240912084229-e96c462e523d + github.com/multiversx/mx-chain-vm-go v1.5.33-0.20240912115217-e4a93d0c7fa2 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 5eb00724155..b899383ae66 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 h1:QauClmsZVKnShhvAVkXndO4j25q361SPvt9dqdx1qlM= -github.com/multiversx/mx-chain-vm-common-go v1.5.14/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= -github.com/multiversx/mx-chain-vm-go v1.5.32 h1:bEHKmXhjo2aHsx+cFDtKRV7/uq0yBip47gj9Xrl/B84= -github.com/multiversx/mx-chain-vm-go v1.5.32/go.mod h1:yjOCetRG0wFXm+IWGyioipdR959TYoR+FRdAGVq8xXw= +github.com/multiversx/mx-chain-vm-common-go v1.5.15-0.20240912084229-e96c462e523d h1:R/4JLgd6voLZPieHhHCh3uTztlSym0iDI8fkMpN4JAE= +github.com/multiversx/mx-chain-vm-common-go v1.5.15-0.20240912084229-e96c462e523d/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= +github.com/multiversx/mx-chain-vm-go v1.5.33-0.20240912115217-e4a93d0c7fa2 h1:p8pHfq+VhdKUp4oSP0QEjUkjAVLpXlCXnM4eS1vsGoo= +github.com/multiversx/mx-chain-vm-go v1.5.33-0.20240912115217-e4a93d0c7fa2/go.mod h1:3LmdbQOb+Fy3UqF9DtQ9j/RITetee9CHbEm+PV+JrC4= 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= diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 8f8417d9b84..10fdc804257 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -401,6 +401,18 @@ func checkMetaData( require.Equal(t, expectedMetaData.Attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) } +func checkReservedField( + t *testing.T, + cs testsChainSimulator.ChainSimulator, + addressBytes []byte, + tokenID []byte, + shardID uint32, + expectedReservedField []byte, +) { + esdtData := getESDTDataFromAcc(t, cs, addressBytes, tokenID, shardID) + require.Equal(t, expectedReservedField, esdtData.Reserved) +} + func checkMetaDataNotInAcc( t *testing.T, cs testsChainSimulator.ChainSimulator, @@ -3861,7 +3873,7 @@ func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) baseIssuingCost := "1000" cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) defer cs.Close() - + marshaller := cs.GetNodeHandler(0).GetCoreComponents().InternalMarshalizer() addrs := createAddresses(t, cs, true) log.Info("Register dynamic metaESDT token") @@ -3930,6 +3942,7 @@ func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) checkMetaData(t, cs, core.SystemAccountAddress, tokenID, shardID, metaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, shardID, []byte{1}) log.Info("send metaEsdt cross shard") @@ -3964,8 +3977,19 @@ func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) expectedMetaData.Hash = newMetaData.Hash expectedMetaData.Attributes = newMetaData.Attributes + round := cs.GetNodeHandler(0).GetChainHandler().GetCurrentBlockHeader().GetRound() + reserved := &esdt.MetaDataVersion{ + Name: round, + Creator: round, + Hash: round, + Attributes: round, + } + firstVersion, _ := marshaller.Marshal(reserved) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 0, expectedMetaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 0, firstVersion) checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 1, metaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 1, []byte{1}) log.Info("send the update role to shard 2") @@ -3988,7 +4012,9 @@ func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) require.Equal(t, "success", txResult.Status.String()) checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 0, expectedMetaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 0, firstVersion) checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 1, metaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 1, []byte{1}) retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, 2) require.Equal(t, uint64(0), retrievedMetaData.Nonce) @@ -4002,6 +4028,15 @@ func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) } require.Equal(t, 0, len(retrievedMetaData.Attributes)) + round2 := cs.GetNodeHandler(2).GetChainHandler().GetCurrentBlockHeader().GetRound() + reserved = &esdt.MetaDataVersion{ + URIs: round2, + Creator: round2, + Royalties: round2, + } + secondVersion, _ := cs.GetNodeHandler(shardID).GetCoreComponents().InternalMarshalizer().Marshal(reserved) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 2, secondVersion) + log.Info("transfer from shard 0 to shard 1 - should merge metaData") tx = esdtNFTTransferTx(shard0Nonce, addrs[0].Bytes, addrs[1].Bytes, tokenID) @@ -4015,7 +4050,9 @@ func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) require.Nil(t, err) checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 0, expectedMetaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 0, firstVersion) checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 1, expectedMetaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 1, firstVersion) log.Info("transfer from shard 1 to shard 2 - should merge metaData") @@ -4036,7 +4073,9 @@ func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) require.Nil(t, err) checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 0, expectedMetaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 0, firstVersion) checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 1, expectedMetaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 1, firstVersion) latestMetaData := txsFee.GetDefaultMetaData() latestMetaData.Nonce = expectedMetaData.Nonce @@ -4047,6 +4086,17 @@ func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) latestMetaData.Uris = newMetaData2.Uris checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 2, latestMetaData) + reserved = &esdt.MetaDataVersion{ + Name: round, + Creator: round2, + Royalties: round2, + Hash: round, + URIs: round2, + Attributes: round, + } + thirdVersion, _ := cs.GetNodeHandler(shardID).GetCoreComponents().InternalMarshalizer().Marshal(reserved) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 2, thirdVersion) + log.Info("transfer from shard 2 to shard 0 - should update metaData") tx = setSpecialRoleTx(shard0Nonce, addrs[0].Bytes, addrs[2].Bytes, tokenID, [][]byte{[]byte(core.ESDTRoleTransfer)}) @@ -4065,8 +4115,29 @@ func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) require.Nil(t, err) checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 0, latestMetaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 0, thirdVersion) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 1, expectedMetaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 1, firstVersion) + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 2, latestMetaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 2, thirdVersion) + + log.Info("transfer from shard 1 to shard 0 - liquidity should be updated") + + tx = esdtNFTTransferTx(1, addrs[1].Bytes, addrs[0].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) + + checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 0, latestMetaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 0, thirdVersion) checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 1, expectedMetaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 1, firstVersion) checkMetaData(t, cs, core.SystemAccountAddress, tokenID, 2, latestMetaData) + checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 2, thirdVersion) } func unsetSpecialRole( From 3ec3288f3c6f9c257309a201897842ed0514dc1d Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Thu, 12 Sep 2024 15:10:00 +0300 Subject: [PATCH 405/434] change github workflow --- .../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 00c329dd3fa..f766ccddbf5 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 @@ -179,7 +179,7 @@ jobs: - name: Upload test report if: always() - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: pytest-report-${{ github.run_id }} path: reports/report.html From 4e58b182b7d88dd55e736ea058a944974e4472fc Mon Sep 17 00:00:00 2001 From: miiu Date: Thu, 12 Sep 2024 16:19:52 +0300 Subject: [PATCH 406/434] new indexer version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index f7148271aeb..bd9b064e48c 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.22 github.com/multiversx/mx-chain-crypto-go v1.2.12 - github.com/multiversx/mx-chain-es-indexer-go v1.7.8 + github.com/multiversx/mx-chain-es-indexer-go v1.7.9-0.20240912110120-3287bbe713da 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 b899383ae66..5a11bafdc94 100644 --- a/go.sum +++ b/go.sum @@ -391,8 +391,8 @@ github.com/multiversx/mx-chain-core-go v1.2.22 h1:yDYrvoQOBbsDerEp7L3+de5AfMy3pT github.com/multiversx/mx-chain-core-go v1.2.22/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.8 h1:ZDKTXkQhQ7lLi6huVrBTUssVEqCvaCxGH4Y52GapboQ= -github.com/multiversx/mx-chain-es-indexer-go v1.7.8/go.mod h1:oGcRK2E3Syv6vRTszWrrb/TqD8akq0yeoMr1wPPiTO4= +github.com/multiversx/mx-chain-es-indexer-go v1.7.9-0.20240912110120-3287bbe713da h1:Dk0UXrr4rwMblSnsXWERKiqi1Jwa+bWIrLn7J03ixZU= +github.com/multiversx/mx-chain-es-indexer-go v1.7.9-0.20240912110120-3287bbe713da/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= From 82658db527c77c3790d33d06a9c41310944ac0a5 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 17 Sep 2024 14:53:03 +0300 Subject: [PATCH 407/434] updated deps to tags --- go.mod | 6 +++--- go.sum | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index bd9b064e48c..99629511184 100644 --- a/go.mod +++ b/go.mod @@ -17,12 +17,12 @@ require ( github.com/multiversx/mx-chain-communication-go v1.1.0 github.com/multiversx/mx-chain-core-go v1.2.22 github.com/multiversx/mx-chain-crypto-go v1.2.12 - github.com/multiversx/mx-chain-es-indexer-go v1.7.9-0.20240912110120-3287bbe713da + github.com/multiversx/mx-chain-es-indexer-go v1.7.9 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.15-0.20240912084229-e96c462e523d - github.com/multiversx/mx-chain-vm-go v1.5.33-0.20240912115217-e4a93d0c7fa2 + github.com/multiversx/mx-chain-vm-common-go v1.5.15 + github.com/multiversx/mx-chain-vm-go v1.5.33 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 5a11bafdc94..c9deff299f6 100644 --- a/go.sum +++ b/go.sum @@ -391,18 +391,18 @@ github.com/multiversx/mx-chain-core-go v1.2.22 h1:yDYrvoQOBbsDerEp7L3+de5AfMy3pT github.com/multiversx/mx-chain-core-go v1.2.22/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.9-0.20240912110120-3287bbe713da h1:Dk0UXrr4rwMblSnsXWERKiqi1Jwa+bWIrLn7J03ixZU= -github.com/multiversx/mx-chain-es-indexer-go v1.7.9-0.20240912110120-3287bbe713da/go.mod h1:oGcRK2E3Syv6vRTszWrrb/TqD8akq0yeoMr1wPPiTO4= +github.com/multiversx/mx-chain-es-indexer-go v1.7.9 h1:rWq9phJu8GG6TtoJ5cL+MmhyReWCEyqBE5ymXUvudCg= +github.com/multiversx/mx-chain-es-indexer-go v1.7.9/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.15-0.20240912084229-e96c462e523d h1:R/4JLgd6voLZPieHhHCh3uTztlSym0iDI8fkMpN4JAE= -github.com/multiversx/mx-chain-vm-common-go v1.5.15-0.20240912084229-e96c462e523d/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= -github.com/multiversx/mx-chain-vm-go v1.5.33-0.20240912115217-e4a93d0c7fa2 h1:p8pHfq+VhdKUp4oSP0QEjUkjAVLpXlCXnM4eS1vsGoo= -github.com/multiversx/mx-chain-vm-go v1.5.33-0.20240912115217-e4a93d0c7fa2/go.mod h1:3LmdbQOb+Fy3UqF9DtQ9j/RITetee9CHbEm+PV+JrC4= +github.com/multiversx/mx-chain-vm-common-go v1.5.15 h1:e6VXktd0eDbm0TVR2T3X9c1TAtQArxmNf79cGAZ7IYA= +github.com/multiversx/mx-chain-vm-common-go v1.5.15/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= +github.com/multiversx/mx-chain-vm-go v1.5.33 h1:KM/qNf6xpg0rgLI4BwQRdleeFqLwI2QC3ZJpV/EIrzg= +github.com/multiversx/mx-chain-vm-go v1.5.33/go.mod h1:2PLHmpy4uXMkikoTkEIKoqEM8ZQ/USA/vak9b+Ft5PE= 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 7173c623b909b3b5299a4294c8e13e16c42ddcfe Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Tue, 17 Sep 2024 14:02:26 +0000 Subject: [PATCH 408/434] errors for invalid signatures in crypto hooks; update vm version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 99629511184..39983f02e15 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.15 - github.com/multiversx/mx-chain-vm-go v1.5.33 + github.com/multiversx/mx-chain-vm-go v1.5.34-0.20240917134424-18af34aca4d4 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 c9deff299f6..35e134237be 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.15 h1:e6VXktd0eDbm0TVR2T3X9c1TAtQArxmNf79cGAZ7IYA= github.com/multiversx/mx-chain-vm-common-go v1.5.15/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= -github.com/multiversx/mx-chain-vm-go v1.5.33 h1:KM/qNf6xpg0rgLI4BwQRdleeFqLwI2QC3ZJpV/EIrzg= -github.com/multiversx/mx-chain-vm-go v1.5.33/go.mod h1:2PLHmpy4uXMkikoTkEIKoqEM8ZQ/USA/vak9b+Ft5PE= +github.com/multiversx/mx-chain-vm-go v1.5.34-0.20240917134424-18af34aca4d4 h1:Isk9b3npbJlfSzlTxiF8eZxt/sGJggkn6OhAt0P6YEs= +github.com/multiversx/mx-chain-vm-go v1.5.34-0.20240917134424-18af34aca4d4/go.mod h1:2PLHmpy4uXMkikoTkEIKoqEM8ZQ/USA/vak9b+Ft5PE= 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 e140ea3a733266f5f6755711de9c64d6e4a61f32 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 18 Sep 2024 13:42:46 +0300 Subject: [PATCH 409/434] new vm go tag --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 39983f02e15..b7041989903 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.15 - github.com/multiversx/mx-chain-vm-go v1.5.34-0.20240917134424-18af34aca4d4 + github.com/multiversx/mx-chain-vm-go v1.5.34 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 35e134237be..7a40bc97102 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.15 h1:e6VXktd0eDbm0TVR2T3X9c1TAtQArxmNf79cGAZ7IYA= github.com/multiversx/mx-chain-vm-common-go v1.5.15/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= -github.com/multiversx/mx-chain-vm-go v1.5.34-0.20240917134424-18af34aca4d4 h1:Isk9b3npbJlfSzlTxiF8eZxt/sGJggkn6OhAt0P6YEs= -github.com/multiversx/mx-chain-vm-go v1.5.34-0.20240917134424-18af34aca4d4/go.mod h1:2PLHmpy4uXMkikoTkEIKoqEM8ZQ/USA/vak9b+Ft5PE= +github.com/multiversx/mx-chain-vm-go v1.5.34 h1:SPFMdO6E7sUYiFpZ41wtNOGfukR7Xqp6z5RA4sTSX9c= +github.com/multiversx/mx-chain-vm-go v1.5.34/go.mod h1:2PLHmpy4uXMkikoTkEIKoqEM8ZQ/USA/vak9b+Ft5PE= 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 a6d2fabb7a000eedc0f6fe39875f7d32a90f6381 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 18 Sep 2024 14:53:52 +0300 Subject: [PATCH 410/434] newer vm go tag --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index b7041989903..ea003f03a1f 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.15 - github.com/multiversx/mx-chain-vm-go v1.5.34 + github.com/multiversx/mx-chain-vm-go v1.5.35 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 7a40bc97102..b0f8c511822 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.15 h1:e6VXktd0eDbm0TVR2T3X9c1TAtQArxmNf79cGAZ7IYA= github.com/multiversx/mx-chain-vm-common-go v1.5.15/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= -github.com/multiversx/mx-chain-vm-go v1.5.34 h1:SPFMdO6E7sUYiFpZ41wtNOGfukR7Xqp6z5RA4sTSX9c= -github.com/multiversx/mx-chain-vm-go v1.5.34/go.mod h1:2PLHmpy4uXMkikoTkEIKoqEM8ZQ/USA/vak9b+Ft5PE= +github.com/multiversx/mx-chain-vm-go v1.5.35 h1:UP6jjtI4L8beY5kYvqeNNtgn7CR4SM8XlHVtIYsQxS0= +github.com/multiversx/mx-chain-vm-go v1.5.35/go.mod h1:2PLHmpy4uXMkikoTkEIKoqEM8ZQ/USA/vak9b+Ft5PE= 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 965682c1749bdfdbe35e06b82f16e5688b6197e6 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Mon, 23 Sep 2024 16:03:30 +0300 Subject: [PATCH 411/434] update vm common version and add integration tests --- go.mod | 4 +- go.sum | 8 +- .../vm/esdtImprovements_test.go | 117 +++++++++++++++++- 3 files changed, 121 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index ea003f03a1f..9668440bbf5 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.15 - github.com/multiversx/mx-chain-vm-go v1.5.35 + github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923123831-e44cdaa3a9ba + github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923130037-58aebb427313 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 b0f8c511822..164339f5b75 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.15 h1:e6VXktd0eDbm0TVR2T3X9c1TAtQArxmNf79cGAZ7IYA= -github.com/multiversx/mx-chain-vm-common-go v1.5.15/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= -github.com/multiversx/mx-chain-vm-go v1.5.35 h1:UP6jjtI4L8beY5kYvqeNNtgn7CR4SM8XlHVtIYsQxS0= -github.com/multiversx/mx-chain-vm-go v1.5.35/go.mod h1:2PLHmpy4uXMkikoTkEIKoqEM8ZQ/USA/vak9b+Ft5PE= +github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923123831-e44cdaa3a9ba h1:UGKkWK2JJx09NG0b6Dv/BOrkptv7f9M5MNMY+X1yyvg= +github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923123831-e44cdaa3a9ba/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= +github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923130037-58aebb427313 h1:O9XppzM+i/l553T2XpiPKMvIhdX9aOe0ze9S3Fpptkw= +github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923130037-58aebb427313/go.mod h1:VIxYqss+koXj6qfy2c3geluFAZd2BC70YGv8MQlzAKU= 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= diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 10fdc804257..ed810c0150c 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -4017,7 +4017,7 @@ func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) checkReservedField(t, cs, core.SystemAccountAddress, tokenID, 1, []byte{1}) retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, 2) - require.Equal(t, uint64(0), retrievedMetaData.Nonce) + require.Equal(t, uint64(1), retrievedMetaData.Nonce) require.Equal(t, 0, len(retrievedMetaData.Name)) require.Equal(t, addrs[2].Bytes, retrievedMetaData.Creator) require.Equal(t, newMetaData2.Royalties, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Royalties)).Bytes()))) @@ -4330,7 +4330,6 @@ func TestChainSimulator_dynamicNFT_mergeMetaDataFromMultipleUpdates(t *testing.T checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 0) checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 1) checkMetaData(t, cs, addrs[0].Bytes, tokenID, 0, metaData) - newMetaData.Nonce = []byte{} newMetaData.Attributes = []byte{} checkMetaData(t, cs, addrs[1].Bytes, tokenID, 1, newMetaData) @@ -4384,3 +4383,117 @@ func TestChainSimulator_dynamicNFT_mergeMetaDataFromMultipleUpdates(t *testing.T checkMetaDataNotInAcc(t, cs, addrs[1].Bytes, tokenID, 1) checkMetaData(t, cs, addrs[2].Bytes, tokenID, 2, mergedMetaData) } + +func TestChainSimulator_dynamicNFT_changeMetaDataForOneNFTShouldNotChangeOtherNonces(t *testing.T) { + t.Parallel() + + baseIssuingCost := "1000" + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) + defer cs.Close() + + addrs := createAddresses(t, cs, true) + + log.Info("Register dynamic NFT token") + + ticker := []byte("NFTTICKER") + tokenName := []byte("tokenName") + + txDataField := bytes.Join( + [][]byte{ + []byte("registerDynamic"), + []byte(hex.EncodeToString(tokenName)), + []byte(hex.EncodeToString(ticker)), + []byte(hex.EncodeToString([]byte("NFT"))), + }, + []byte("@"), + ) + + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + + shard0Nonce := uint64(0) + tx := &transaction.Transaction{ + Nonce: shard0Nonce, + 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, + } + shard0Nonce++ + + 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] + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + []byte(core.ESDTRoleNFTUpdate), + } + setAddressEsdtRoles(t, cs, shard0Nonce, addrs[0], tokenID, roles) + shard0Nonce++ + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + metaData := txsFee.GetDefaultMetaData() + metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = esdtNftCreateTx(shard0Nonce, addrs[0].Bytes, tokenID, metaData, 1) + shard0Nonce++ + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(2).Bytes())) + tx = esdtNftCreateTx(shard0Nonce, addrs[0].Bytes, tokenID, metaData, 1) + shard0Nonce++ + 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("give update role to another account and update metaData for nonce 2") + + shard0Nonce = transferSpecialRoleToAddr(t, cs, shard0Nonce, tokenID, addrs[0].Bytes, addrs[1].Bytes, []byte(core.ESDTRoleNFTUpdate)) + + newMetaData := &txsFee.MetaData{} + newMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(2).Bytes())) + newMetaData.Name = []byte(hex.EncodeToString([]byte("name2"))) + newMetaData.Hash = []byte(hex.EncodeToString([]byte("hash2"))) + newMetaData.Royalties = []byte(hex.EncodeToString(big.NewInt(15).Bytes())) + + tx = esdtMetaDataUpdateTx(tokenID, newMetaData, 0, addrs[1].Bytes) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + log.Info("transfer nft with nonce 1 - should not merge metaData") + + tx = esdtNFTTransferTx(shard0Nonce, addrs[0].Bytes, addrs[1].Bytes, tokenID) + shard0Nonce++ + 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) + + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 0) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 1) + metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + checkMetaData(t, cs, addrs[1].Bytes, tokenID, 1, metaData) +} From 61a1de9ae3058ff432d9ebb6d366d7c4a5e77e0f Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Mon, 23 Sep 2024 16:15:20 +0300 Subject: [PATCH 412/434] fix linter issue --- integrationTests/chainSimulator/vm/esdtImprovements_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index ed810c0150c..e26b35c9a3a 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -4483,7 +4483,6 @@ func TestChainSimulator_dynamicNFT_changeMetaDataForOneNFTShouldNotChangeOtherNo log.Info("transfer nft with nonce 1 - should not merge metaData") tx = esdtNFTTransferTx(shard0Nonce, addrs[0].Bytes, addrs[1].Bytes, tokenID) - shard0Nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) From 7c480fa3240343b9377cc5ebba29ac9442eb212b Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Mon, 23 Sep 2024 16:43:49 +0300 Subject: [PATCH 413/434] 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 9668440bbf5..8d4d271b7dd 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.16-0.20240923123831-e44cdaa3a9ba - github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923130037-58aebb427313 + github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923133909-21d98c3bd0ab + github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134141-bdba60bb6bcd 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 164339f5b75..b963afb82df 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.16-0.20240923123831-e44cdaa3a9ba h1:UGKkWK2JJx09NG0b6Dv/BOrkptv7f9M5MNMY+X1yyvg= -github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923123831-e44cdaa3a9ba/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= -github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923130037-58aebb427313 h1:O9XppzM+i/l553T2XpiPKMvIhdX9aOe0ze9S3Fpptkw= -github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923130037-58aebb427313/go.mod h1:VIxYqss+koXj6qfy2c3geluFAZd2BC70YGv8MQlzAKU= +github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923133909-21d98c3bd0ab h1:EcurAXYDlfnXtwPDz8tBBdbnh+ntsK6Dw77DL1/tVdI= +github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923133909-21d98c3bd0ab/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= +github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134141-bdba60bb6bcd h1:2vJk299/KQbtTE/dUmwFW8dkn0RTru0F7EqFqSyMneQ= +github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134141-bdba60bb6bcd/go.mod h1:EJF+vOF/9ZhACjcKhIeCUzr4CL31rWaeC9ReV8EJqfw= 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 023dcb59390ed8420b70518767e1074332c523ce Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Mon, 23 Sep 2024 13:59:32 +0000 Subject: [PATCH 414/434] upgrade wasmer executor version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index ea003f03a1f..f495ebcc9d3 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.15 - github.com/multiversx/mx-chain-vm-go v1.5.35 + github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134722-38e303b7a93d 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 b0f8c511822..0f06273f7b6 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.15 h1:e6VXktd0eDbm0TVR2T3X9c1TAtQArxmNf79cGAZ7IYA= github.com/multiversx/mx-chain-vm-common-go v1.5.15/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= -github.com/multiversx/mx-chain-vm-go v1.5.35 h1:UP6jjtI4L8beY5kYvqeNNtgn7CR4SM8XlHVtIYsQxS0= -github.com/multiversx/mx-chain-vm-go v1.5.35/go.mod h1:2PLHmpy4uXMkikoTkEIKoqEM8ZQ/USA/vak9b+Ft5PE= +github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134722-38e303b7a93d h1:AZzDVIr5o12ZRRObHwneLlEiAUQhsrhr/x/hFMCxYeM= +github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134722-38e303b7a93d/go.mod h1:2PLHmpy4uXMkikoTkEIKoqEM8ZQ/USA/vak9b+Ft5PE= 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 c69930e50f4c9c27123ab94a49e5c48d500fa10a Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Tue, 24 Sep 2024 14:19:45 +0000 Subject: [PATCH 415/434] update vm version --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index f495ebcc9d3..cc2c5233096 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.15 - github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134722-38e303b7a93d + github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923133909-21d98c3bd0ab + github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240924141331-94343be3e5f5 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 0f06273f7b6..788adc85758 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.15 h1:e6VXktd0eDbm0TVR2T3X9c1TAtQArxmNf79cGAZ7IYA= -github.com/multiversx/mx-chain-vm-common-go v1.5.15/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= -github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134722-38e303b7a93d h1:AZzDVIr5o12ZRRObHwneLlEiAUQhsrhr/x/hFMCxYeM= -github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134722-38e303b7a93d/go.mod h1:2PLHmpy4uXMkikoTkEIKoqEM8ZQ/USA/vak9b+Ft5PE= +github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923133909-21d98c3bd0ab h1:EcurAXYDlfnXtwPDz8tBBdbnh+ntsK6Dw77DL1/tVdI= +github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923133909-21d98c3bd0ab/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= +github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240924141331-94343be3e5f5 h1:daWLWs7Ei99rpdScJlEUOjGfUItS2OAUJkDJux6BOBo= +github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240924141331-94343be3e5f5/go.mod h1:EJF+vOF/9ZhACjcKhIeCUzr4CL31rWaeC9ReV8EJqfw= 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 87bda6fcddab7030ebad8b1ba469f662ad869e2f Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Wed, 25 Sep 2024 09:21:28 +0000 Subject: [PATCH 416/434] upgrade wasmer executor version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index cc2c5233096..560cb07cdc8 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.16-0.20240923133909-21d98c3bd0ab - github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240924141331-94343be3e5f5 + github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240925091549-21115eb9e7e3 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 788adc85758..b9c62be4605 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.16-0.20240923133909-21d98c3bd0ab h1:EcurAXYDlfnXtwPDz8tBBdbnh+ntsK6Dw77DL1/tVdI= github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923133909-21d98c3bd0ab/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= -github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240924141331-94343be3e5f5 h1:daWLWs7Ei99rpdScJlEUOjGfUItS2OAUJkDJux6BOBo= -github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240924141331-94343be3e5f5/go.mod h1:EJF+vOF/9ZhACjcKhIeCUzr4CL31rWaeC9ReV8EJqfw= +github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240925091549-21115eb9e7e3 h1:XxCQ6pHf6py8jUlg7BR8JaSPB92yj4/TK/HTLw6Bmg4= +github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240925091549-21115eb9e7e3/go.mod h1:EJF+vOF/9ZhACjcKhIeCUzr4CL31rWaeC9ReV8EJqfw= 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 fa5fc0b6a66168804fb9d19fcf2b174015e65777 Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Thu, 26 Sep 2024 08:42:19 +0000 Subject: [PATCH 417/434] upgrade wasmer executor version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 560cb07cdc8..f81cdfd8451 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.16-0.20240923133909-21d98c3bd0ab - github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240925091549-21115eb9e7e3 + github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240926083101-d10ec7c4e3f5 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 b9c62be4605..fd1a8286ebe 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.16-0.20240923133909-21d98c3bd0ab h1:EcurAXYDlfnXtwPDz8tBBdbnh+ntsK6Dw77DL1/tVdI= github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923133909-21d98c3bd0ab/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= -github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240925091549-21115eb9e7e3 h1:XxCQ6pHf6py8jUlg7BR8JaSPB92yj4/TK/HTLw6Bmg4= -github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240925091549-21115eb9e7e3/go.mod h1:EJF+vOF/9ZhACjcKhIeCUzr4CL31rWaeC9ReV8EJqfw= +github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240926083101-d10ec7c4e3f5 h1:aVzZYR0Bro1na2MIeOcLmcAlel5IHcu5aap1VLT5w40= +github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240926083101-d10ec7c4e3f5/go.mod h1:EJF+vOF/9ZhACjcKhIeCUzr4CL31rWaeC9ReV8EJqfw= 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 7b855cd18da9f341d1c83b2e22872534570b6288 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 27 Sep 2024 15:31:24 +0300 Subject: [PATCH 418/434] updated mx-chain-vm-go to latest rc/v1.7.next1 --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 8d4d271b7dd..d2b76ce9593 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.16-0.20240923133909-21d98c3bd0ab - github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134141-bdba60bb6bcd + github.com/multiversx/mx-chain-vm-common-go v1.5.16 + github.com/multiversx/mx-chain-vm-go v1.5.37 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 b963afb82df..0b789eb79b2 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.16-0.20240923133909-21d98c3bd0ab h1:EcurAXYDlfnXtwPDz8tBBdbnh+ntsK6Dw77DL1/tVdI= -github.com/multiversx/mx-chain-vm-common-go v1.5.16-0.20240923133909-21d98c3bd0ab/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= -github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134141-bdba60bb6bcd h1:2vJk299/KQbtTE/dUmwFW8dkn0RTru0F7EqFqSyMneQ= -github.com/multiversx/mx-chain-vm-go v1.5.36-0.20240923134141-bdba60bb6bcd/go.mod h1:EJF+vOF/9ZhACjcKhIeCUzr4CL31rWaeC9ReV8EJqfw= +github.com/multiversx/mx-chain-vm-common-go v1.5.16 h1:g1SqYjxl7K66Y1O/q6tvDJ37fzpzlxCSfRzSm/woQQY= +github.com/multiversx/mx-chain-vm-common-go v1.5.16/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= +github.com/multiversx/mx-chain-vm-go v1.5.37 h1:Iy3KCvM+DOq1f9UPA7uYK/rI3ZbBOXc2CVNO2/vm5zw= +github.com/multiversx/mx-chain-vm-go v1.5.37/go.mod h1:nzLrWeXvfxCIiwj5uNBZq3d7stkXyeY+Fktfr4tTaiY= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc= From 4f16b0a52b5c7e65226f3794a8f1d4b03f4d9359 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Mon, 7 Oct 2024 12:35:19 +0300 Subject: [PATCH 419/434] add more integration tests --- .../vm/esdtImprovements_test.go | 220 ++++++++++++++++++ 1 file changed, 220 insertions(+) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index e26b35c9a3a..e0f23f1ce8c 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -4496,3 +4496,223 @@ func TestChainSimulator_dynamicNFT_changeMetaDataForOneNFTShouldNotChangeOtherNo metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) checkMetaData(t, cs, addrs[1].Bytes, tokenID, 1, metaData) } + +func TestChainSimulator_dynamicNFT_updateBeforeCreateOnSameAccountShouldOverwrite(t *testing.T) { + t.Parallel() + + baseIssuingCost := "1000" + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) + defer cs.Close() + + addrs := createAddresses(t, cs, true) + + log.Info("Register dynamic NFT token") + + ticker := []byte("NFTTICKER") + tokenName := []byte("tokenName") + + txDataField := bytes.Join( + [][]byte{ + []byte("registerDynamic"), + []byte(hex.EncodeToString(tokenName)), + []byte(hex.EncodeToString(ticker)), + []byte(hex.EncodeToString([]byte("NFT"))), + }, + []byte("@"), + ) + + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + + shard0Nonce := uint64(0) + tx := &transaction.Transaction{ + Nonce: shard0Nonce, + 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, + } + shard0Nonce++ + + 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] + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + []byte(core.ESDTRoleNFTUpdate), + } + setAddressEsdtRoles(t, cs, shard0Nonce, addrs[0], tokenID, roles) + shard0Nonce++ + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + log.Info("update meta data for a token that is not yet created") + + newMetaData := &txsFee.MetaData{} + newMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + newMetaData.Name = []byte(hex.EncodeToString([]byte("name2"))) + newMetaData.Hash = []byte(hex.EncodeToString([]byte("hash2"))) + newMetaData.Royalties = []byte(hex.EncodeToString(big.NewInt(15).Bytes())) + + tx = esdtMetaDataUpdateTx(tokenID, newMetaData, shard0Nonce, addrs[0].Bytes) + shard0Nonce++ + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 1) + newMetaData.Attributes = []byte{} + newMetaData.Uris = [][]byte{} + checkMetaData(t, cs, addrs[0].Bytes, tokenID, 0, newMetaData) + + log.Info("create nft with the same nonce - should overwrite the metadata") + + metaData := txsFee.GetDefaultMetaData() + metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = esdtNftCreateTx(shard0Nonce, addrs[0].Bytes, tokenID, metaData, 1) + 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) + + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 0) + checkMetaData(t, cs, addrs[0].Bytes, tokenID, 0, metaData) +} + +func TestChainSimulator_dynamicNFT_updateBeforeCreateOnDifferentAccountsShouldMergeMetaDataWhenTransferred(t *testing.T) { + t.Parallel() + + baseIssuingCost := "1000" + cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) + defer cs.Close() + + addrs := createAddresses(t, cs, true) + + log.Info("Register dynamic NFT token") + + ticker := []byte("NFTTICKER") + tokenName := []byte("tokenName") + + txDataField := bytes.Join( + [][]byte{ + []byte("registerDynamic"), + []byte(hex.EncodeToString(tokenName)), + []byte(hex.EncodeToString(ticker)), + []byte(hex.EncodeToString([]byte("NFT"))), + }, + []byte("@"), + ) + + callValue, _ := big.NewInt(0).SetString(baseIssuingCost, 10) + + shard0Nonce := uint64(0) + tx := &transaction.Transaction{ + Nonce: shard0Nonce, + 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, + } + shard0Nonce++ + + 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] + roles := [][]byte{ + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), + []byte(core.ESDTRoleNFTUpdate), + } + setAddressEsdtRoles(t, cs, shard0Nonce, addrs[0], tokenID, roles) + shard0Nonce++ + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + log.Info("transfer update role to another address") + + shard0Nonce = transferSpecialRoleToAddr(t, cs, shard0Nonce, tokenID, addrs[0].Bytes, addrs[1].Bytes, []byte(core.ESDTRoleNFTUpdate)) + + log.Info("update meta data for a token that is not yet created") + + newMetaData := &txsFee.MetaData{} + newMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + newMetaData.Name = []byte(hex.EncodeToString([]byte("name2"))) + newMetaData.Hash = []byte(hex.EncodeToString([]byte("hash2"))) + newMetaData.Royalties = []byte(hex.EncodeToString(big.NewInt(15).Bytes())) + + tx = esdtMetaDataUpdateTx(tokenID, newMetaData, 0, addrs[1].Bytes) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 0) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 1) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, tokenID, 0) + newMetaData.Attributes = []byte{} + newMetaData.Uris = [][]byte{} + checkMetaData(t, cs, addrs[1].Bytes, tokenID, 1, newMetaData) + + log.Info("create nft with the same nonce on different account") + + metaData := txsFee.GetDefaultMetaData() + metaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tx = esdtNftCreateTx(shard0Nonce, addrs[0].Bytes, tokenID, metaData, 1) + shard0Nonce++ + 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) + + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 0) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 1) + checkMetaData(t, cs, addrs[0].Bytes, tokenID, 0, metaData) + checkMetaData(t, cs, addrs[1].Bytes, tokenID, 1, newMetaData) + + log.Info("transfer dynamic NFT to the updated account") + + tx = esdtNFTTransferTx(shard0Nonce, 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()) + + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 0) + checkMetaDataNotInAcc(t, cs, core.SystemAccountAddress, tokenID, 1) + checkMetaDataNotInAcc(t, cs, addrs[0].Bytes, tokenID, 0) + newMetaData.Attributes = metaData.Attributes + newMetaData.Uris = metaData.Uris + checkMetaData(t, cs, addrs[1].Bytes, tokenID, 1, newMetaData) +} From 7005551274cc1b9d461e7ff86cd0fa5b374a2c60 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 18 Oct 2024 19:00:04 +0300 Subject: [PATCH 420/434] reverted relayed v3 --- api/groups/transactionGroup.go | 128 +--- api/groups/transactionGroup_test.go | 62 -- cmd/node/config/enableEpochs.toml | 7 +- common/constants.go | 4 - common/enablers/enableEpochsHandler.go | 6 - common/enablers/enableEpochsHandler_test.go | 11 +- config/epochConfig.go | 1 - config/tomlConfig_test.go | 16 +- .../epochStartInterceptorsContainerFactory.go | 2 - errors/errors.go | 3 - factory/interface.go | 1 - factory/mock/processComponentsStub.go | 6 - factory/processing/blockProcessorCreator.go | 146 ++--- .../processing/blockProcessorCreator_test.go | 2 - factory/processing/export_test.go | 6 +- factory/processing/processComponents.go | 24 +- .../processing/processComponentsHandler.go | 15 - .../processComponentsHandler_test.go | 2 - .../txSimulatorProcessComponents.go | 142 ++-- .../txSimulatorProcessComponents_test.go | 7 +- genesis/process/disabled/feeHandler.go | 5 - genesis/process/metaGenesisBlockCreator.go | 51 +- genesis/process/shardGenesisBlockCreator.go | 91 ++- go.mod | 4 +- go.sum | 8 +- .../relayedTx/relayedTx_test.go | 587 +---------------- .../mock/processComponentsStub.go | 6 - .../multiShard/relayedTx/common.go | 81 +-- .../multiShard/relayedTx/relayedTx_test.go | 4 - integrationTests/testHeartbeatNode.go | 2 - integrationTests/testInitializer.go | 21 +- integrationTests/testProcessorNode.go | 180 +++-- .../testProcessorNodeWithTestWebServer.go | 1 - integrationTests/vm/testInitializer.go | 225 +++---- integrationTests/vm/wasm/utils.go | 54 +- .../vm/wasm/wasmvm/wasmVM_test.go | 37 +- .../components/processComponents.go | 7 - .../components/processComponents_test.go | 1 - node/external/dtos.go | 35 +- .../transactionAPI/gasUsedAndFeeProcessor.go | 31 +- .../gasUsedAndFeeProcessor_test.go | 67 +- .../testData/relayedV3WithOneRefund.json | 56 -- node/external/transactionAPI/unmarshaller.go | 131 +--- node/metrics/metrics.go | 1 - node/metrics/metrics_test.go | 14 +- node/node.go | 36 +- node/node_test.go | 33 +- .../transactionsFeeProcessor.go | 47 +- process/block/preprocess/gasComputation.go | 2 +- process/constants.go | 4 - process/coordinator/transactionType.go | 9 - process/coordinator/transactionType_test.go | 26 - process/disabled/failedTxLogsAccumulator.go | 33 - process/disabled/relayedTxV3Processor.go | 23 - process/economics/economicsData.go | 98 --- process/economics/economicsData_test.go | 133 ---- process/errors.go | 45 -- 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 | 4 - process/interface.go | 16 - .../processProxy/processProxy.go | 47 +- .../processProxy/processProxy_test.go | 8 +- .../processProxy/testProcessProxy.go | 47 +- process/smartContract/process_test.go | 12 +- .../smartContract/processorV2/processV2.go | 86 ++- .../smartContract/processorV2/process_test.go | 31 +- process/smartContract/scrCommon/common.go | 47 +- process/transaction/export_test.go | 6 +- process/transaction/interceptedTransaction.go | 83 +-- .../interceptedTransaction_test.go | 368 +---------- process/transaction/relayedTxV3Processor.go | 112 ---- .../transaction/relayedTxV3Processor_test.go | 249 ------- process/transaction/shardProcess.go | 327 ++-------- process/transaction/shardProcess_test.go | 613 +----------------- .../transactionEvaluator.go | 2 +- .../transactionLog/failedTxLogsAccumulator.go | 109 ---- .../failedTxLogsAccumulator_test.go | 168 ----- sharding/mock/enableEpochsHandlerMock.go | 15 - testscommon/components/default.go | 4 +- .../economicsDataHandlerStub.go | 19 - .../economicsmocks/economicsHandlerMock.go | 19 - .../failedTxLogsAccumulatorMock.go | 41 -- .../processMocks/relayedTxV3ProcessorMock.go | 23 - update/factory/exportHandlerFactory.go | 2 - update/factory/fullSyncInterceptors.go | 2 - 91 files changed, 808 insertions(+), 4442 deletions(-) delete mode 100644 node/external/transactionAPI/testData/relayedV3WithOneRefund.json delete mode 100644 process/disabled/failedTxLogsAccumulator.go delete mode 100644 process/disabled/relayedTxV3Processor.go delete mode 100644 process/transaction/relayedTxV3Processor.go delete mode 100644 process/transaction/relayedTxV3Processor_test.go delete mode 100644 process/transactionLog/failedTxLogsAccumulator.go delete mode 100644 process/transactionLog/failedTxLogsAccumulator_test.go delete mode 100644 testscommon/processMocks/failedTxLogsAccumulatorMock.go delete mode 100644 testscommon/processMocks/relayedTxV3ProcessorMock.go diff --git a/api/groups/transactionGroup.go b/api/groups/transactionGroup.go index 83eb97136b8..f35969ed701 100644 --- a/api/groups/transactionGroup.go +++ b/api/groups/transactionGroup.go @@ -197,23 +197,7 @@ func (tg *transactionGroup) simulateTransaction(c *gin.Context) { return } - 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 { - innerTxs = nil - } - tx, txHash, err := tg.createTransaction(&ftx, innerTxs) + tx, txHash, err := tg.createTransaction(&ftx) if err != nil { c.JSON( http.StatusBadRequest, @@ -283,23 +267,7 @@ func (tg *transactionGroup) sendTransaction(c *gin.Context) { return } - 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 { - innerTxs = nil - } - tx, txHash, err := tg.createTransaction(&ftx, innerTxs) + tx, txHash, err := tg.createTransaction(&ftx) if err != nil { c.JSON( http.StatusBadRequest, @@ -378,23 +346,7 @@ func (tg *transactionGroup) sendMultipleTransactions(c *gin.Context) { var start time.Time txsHashes := make(map[int]string) for idx, receivedTx := range ftxs { - 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 { - innerTxs = nil - } - tx, txHash, err = tg.createTransaction(&receivedTx, innerTxs) + tx, txHash, err = tg.createTransaction(&receivedTx) if err != nil { continue } @@ -556,23 +508,7 @@ func (tg *transactionGroup) computeTransactionGasLimit(c *gin.Context) { return } - 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 { - innerTxs = nil - } - tx, _, err := tg.createTransaction(&ftx, innerTxs) + tx, _, err := tg.createTransaction(&ftx) if err != nil { c.JSON( http.StatusInternalServerError, @@ -782,25 +718,23 @@ func (tg *transactionGroup) getTransactionsPoolNonceGapsForSender(sender string, ) } -func (tg *transactionGroup) createTransaction(receivedTx *transaction.FrontendTransaction, innerTxs []*transaction.Transaction) (*transaction.Transaction, []byte, error) { +func (tg *transactionGroup) createTransaction(receivedTx *transaction.FrontendTransaction) (*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, - InnerTransactions: innerTxs, + 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, } start := time.Now() tx, txHash, err := tg.getFacade().CreateTransaction(txArgs) @@ -906,28 +840,6 @@ 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/api/groups/transactionGroup_test.go b/api/groups/transactionGroup_test.go index e517f51f8bd..9f603412ae0 100644 --- a/api/groups/transactionGroup_test.go +++ b/api/groups/transactionGroup_test.go @@ -312,7 +312,6 @@ 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() @@ -591,7 +590,6 @@ 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() @@ -712,7 +710,6 @@ 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() @@ -1201,62 +1198,3 @@ 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", "innerTransactions":[%s]}`, - nonce, - sender, - receiver, - value, - signature, - userTx1, - ) - tx := fmt.Sprintf(`{"nonce": %d, "sender":"%s", "receiver":"%s", "value":"%s", "signature":"%s", "innerTransactions":[%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/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index 7f41c21468a..9ca2083a352 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -324,17 +324,14 @@ # UnjailCleanupEnableEpoch represents the epoch when the cleanup of the unjailed nodes is enabled UnJailCleanupEnableEpoch = 4 - # RelayedTransactionsV3EnableEpoch represents the epoch when the relayed transactions V3 will be enabled - RelayedTransactionsV3EnableEpoch = 7 - # FixRelayedBaseCostEnableEpoch represents the epoch when the fix for relayed base cost will be enabled - FixRelayedBaseCostEnableEpoch = 7 + FixRelayedBaseCostEnableEpoch = 4 # 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 + FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 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 cbcd0caa6c8..2b56d2f388b 100644 --- a/common/constants.go +++ b/common/constants.go @@ -495,9 +495,6 @@ 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" - // MetricFixRelayedBaseCostEnableEpoch represents the epoch when the fix for relayed base cost is enabled MetricFixRelayedBaseCostEnableEpoch = "erd_fix_relayed_base_cost_enable_epoch" @@ -1234,7 +1231,6 @@ const ( EGLDInESDTMultiTransferFlag core.EnableEpochFlag = "EGLDInESDTMultiTransferFlag" CryptoOpcodesV2Flag core.EnableEpochFlag = "CryptoOpcodesV2Flag" UnJailCleanupFlag core.EnableEpochFlag = "UnJailCleanupFlag" - RelayedTransactionsV3Flag core.EnableEpochFlag = "RelayedTransactionsV3Flag" FixRelayedBaseCostFlag core.EnableEpochFlag = "FixRelayedBaseCostFlag" MultiESDTNFTTransferAndExecuteByUserFlag core.EnableEpochFlag = "MultiESDTNFTTransferAndExecuteByUserFlag" FixRelayedMoveBalanceToNonPayableSCFlag core.EnableEpochFlag = "FixRelayedMoveBalanceToNonPayableSCFlag" diff --git a/common/enablers/enableEpochsHandler.go b/common/enablers/enableEpochsHandler.go index cba4bb4fb4a..65cc7762796 100644 --- a/common/enablers/enableEpochsHandler.go +++ b/common/enablers/enableEpochsHandler.go @@ -762,12 +762,6 @@ func (handler *enableEpochsHandler) createAllFlagsMap() { }, activationEpoch: handler.enableEpochsConfig.UnJailCleanupEnableEpoch, }, - common.RelayedTransactionsV3Flag: { - isActiveInEpoch: func(epoch uint32) bool { - return epoch >= handler.enableEpochsConfig.RelayedTransactionsV3EnableEpoch - }, - activationEpoch: handler.enableEpochsConfig.RelayedTransactionsV3EnableEpoch, - }, common.FixRelayedBaseCostFlag: { isActiveInEpoch: func(epoch uint32) bool { return epoch >= handler.enableEpochsConfig.FixRelayedBaseCostEnableEpoch diff --git a/common/enablers/enableEpochsHandler_test.go b/common/enablers/enableEpochsHandler_test.go index b7d8f27692d..d0f9191055e 100644 --- a/common/enablers/enableEpochsHandler_test.go +++ b/common/enablers/enableEpochsHandler_test.go @@ -119,11 +119,10 @@ func createEnableEpochsConfig() config.EnableEpochs { DynamicESDTEnableEpoch: 102, EGLDInMultiTransferEnableEpoch: 103, CryptoOpcodesV2EnableEpoch: 104, - RelayedTransactionsV3EnableEpoch: 105, - FixRelayedBaseCostEnableEpoch: 106, - MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 107, - FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 108, - UseGasBoundedShouldFailExecutionEnableEpoch: 110, + FixRelayedBaseCostEnableEpoch: 105, + MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 106, + FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 107, + UseGasBoundedShouldFailExecutionEnableEpoch: 108, } } @@ -324,7 +323,6 @@ func TestEnableEpochsHandler_IsFlagEnabled(t *testing.T) { require.True(t, handler.IsFlagEnabled(common.StakingV4StartedFlag)) 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.FixRelayedBaseCostFlag)) require.True(t, handler.IsFlagEnabled(common.FixRelayedMoveBalanceToNonPayableSCFlag)) } @@ -447,7 +445,6 @@ func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) { require.Equal(t, cfg.DynamicESDTEnableEpoch, handler.GetActivationEpoch(common.DynamicESDTFlag)) 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.FixRelayedBaseCostEnableEpoch, handler.GetActivationEpoch(common.FixRelayedBaseCostFlag)) require.Equal(t, cfg.MultiESDTNFTTransferAndExecuteByUserEnableEpoch, handler.GetActivationEpoch(common.MultiESDTNFTTransferAndExecuteByUserFlag)) require.Equal(t, cfg.FixRelayedMoveBalanceToNonPayableSCEnableEpoch, handler.GetActivationEpoch(common.FixRelayedMoveBalanceToNonPayableSCFlag)) diff --git a/config/epochConfig.go b/config/epochConfig.go index e24c302b7d0..a7fd67c680a 100644 --- a/config/epochConfig.go +++ b/config/epochConfig.go @@ -119,7 +119,6 @@ type EnableEpochs struct { EGLDInMultiTransferEnableEpoch uint32 CryptoOpcodesV2EnableEpoch uint32 UnJailCleanupEnableEpoch uint32 - RelayedTransactionsV3EnableEpoch uint32 FixRelayedBaseCostEnableEpoch uint32 MultiESDTNFTTransferAndExecuteByUserEnableEpoch uint32 FixRelayedMoveBalanceToNonPayableSCEnableEpoch uint32 diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index f331917c5d0..e7095b0b096 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -875,17 +875,14 @@ func TestEnableEpochConfig(t *testing.T) { # CryptoOpcodesV2EnableEpoch represents the epoch when BLSMultiSig, Secp256r1 and other opcodes are enabled CryptoOpcodesV2EnableEpoch = 98 - # RelayedTransactionsV3EnableEpoch represents the epoch when the relayed transactions V3 will be enabled - RelayedTransactionsV3EnableEpoch = 99 - # FixRelayedBaseCostEnableEpoch represents the epoch when the fix for relayed base cost will be enabled - FixRelayedBaseCostEnableEpoch = 100 + FixRelayedBaseCostEnableEpoch = 99 # MultiESDTNFTTransferAndExecuteByUserEnableEpoch represents the epoch when enshrined sovereign cross chain opcodes are enabled - MultiESDTNFTTransferAndExecuteByUserEnableEpoch = 101 + MultiESDTNFTTransferAndExecuteByUserEnableEpoch = 100 # FixRelayedMoveBalanceToNonPayableSCEnableEpoch represents the epoch when the fix for relayed move balance to non payable sc will be enabled - FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 102 + FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 101 # MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MaxNodesChangeEnableEpoch = [ @@ -1004,10 +1001,9 @@ func TestEnableEpochConfig(t *testing.T) { DynamicESDTEnableEpoch: 96, EGLDInMultiTransferEnableEpoch: 97, CryptoOpcodesV2EnableEpoch: 98, - RelayedTransactionsV3EnableEpoch: 99, - FixRelayedBaseCostEnableEpoch: 100, - MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 101, - FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 102, + FixRelayedBaseCostEnableEpoch: 99, + MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 100, + FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 101, MaxNodesChangeEnableEpoch: []MaxNodesChangeConfig{ { EpochEnable: 44, diff --git a/epochStart/bootstrap/factory/epochStartInterceptorsContainerFactory.go b/epochStart/bootstrap/factory/epochStartInterceptorsContainerFactory.go index 0ebf8417d7b..d659989896b 100644 --- a/epochStart/bootstrap/factory/epochStartInterceptorsContainerFactory.go +++ b/epochStart/bootstrap/factory/epochStartInterceptorsContainerFactory.go @@ -14,7 +14,6 @@ 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" @@ -109,7 +108,6 @@ 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 b1edc990afc..dd475327876 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -598,6 +598,3 @@ 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") - -// 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 ec92f478992..0f1c237d0d9 100644 --- a/factory/interface.go +++ b/factory/interface.go @@ -311,7 +311,6 @@ type ProcessComponentsHolder interface { ReceiptsRepository() ReceiptsRepository SentSignaturesTracker() process.SentSignaturesTracker EpochSystemSCProcessor() process.EpochStartSystemSCProcessor - RelayedTxV3Processor() process.RelayedTxV3Processor IsInterfaceNil() bool } diff --git a/factory/mock/processComponentsStub.go b/factory/mock/processComponentsStub.go index 4a52413b7cd..32bbfaf2df3 100644 --- a/factory/mock/processComponentsStub.go +++ b/factory/mock/processComponentsStub.go @@ -58,7 +58,6 @@ type ProcessComponentsMock struct { ReceiptsRepositoryInternal factory.ReceiptsRepository SentSignaturesTrackerInternal process.SentSignaturesTracker EpochSystemSCProcessorInternal process.EpochStartSystemSCProcessor - RelayedTxV3ProcessorField process.RelayedTxV3Processor } // Create - @@ -291,11 +290,6 @@ func (pcm *ProcessComponentsMock) EpochSystemSCProcessor() process.EpochStartSys return pcm.EpochSystemSCProcessorInternal } -// 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 c48a777f01c..0721efc6a23 100644 --- a/factory/processing/blockProcessorCreator.go +++ b/factory/processing/blockProcessorCreator.go @@ -38,7 +38,6 @@ 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" @@ -70,7 +69,6 @@ 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() { @@ -89,7 +87,6 @@ func (pcf *processComponentsFactory) newBlockProcessor( blockCutoffProcessingHandler, missingTrieNodesNotifier, sentSignaturesTracker, - relayedTxV3Processor, ) } if shardCoordinator.SelfId() == core.MetachainShardId { @@ -131,7 +128,6 @@ func (pcf *processComponentsFactory) newShardBlockProcessor( blockProcessingCutoffHandler cutoff.BlockProcessingCutoffHandler, missingTrieNodesNotifier common.MissingTrieNodesNotifier, sentSignaturesTracker process.SentSignaturesTracker, - relayedTxV3Processor process.RelayedTxV3Processor, ) (*blockProcessorAndVmFactories, error) { argsParser := smartContract.NewArgumentParser() @@ -233,11 +229,6 @@ 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, @@ -247,32 +238,30 @@ 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, - FailedTxLogsAccumulator: failedTxLogsAccumulator, + 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, } scProcessorProxy, err := processProxy.NewSmartContractProcessorProxy(argsNewScProcessor, pcf.epochNotifier) @@ -290,27 +279,25 @@ 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, - FailedTxLogsAccumulator: failedTxLogsAccumulator, + 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, } transactionProcessor, err := transaction.NewTxProcessor(argsNewTxProcessor) if err != nil { @@ -570,11 +557,6 @@ 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, @@ -584,33 +566,31 @@ 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, - FailedTxLogsAccumulator: failedTxLogsAccumulator, + 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, } scProcessorProxy, err := processProxy.NewSmartContractProcessorProxy(argsNewScProcessor, pcf.epochNotifier) diff --git a/factory/processing/blockProcessorCreator_test.go b/factory/processing/blockProcessorCreator_test.go index 4fb8f8c5d7d..099fec4a82d 100644 --- a/factory/processing/blockProcessorCreator_test.go +++ b/factory/processing/blockProcessorCreator_test.go @@ -57,7 +57,6 @@ func Test_newBlockProcessorCreatorForShard(t *testing.T) { &testscommon.BlockProcessingCutoffStub{}, &testscommon.MissingTrieNodesNotifierStub{}, &testscommon.SentSignatureTrackerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) require.NoError(t, err) @@ -185,7 +184,6 @@ 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 c82f01b3f6f..76e84d75fee 100644 --- a/factory/processing/export_test.go +++ b/factory/processing/export_test.go @@ -25,7 +25,6 @@ func (pcf *processComponentsFactory) NewBlockProcessor( blockProcessingCutoff cutoff.BlockProcessingCutoffHandler, missingTrieNodesNotifier common.MissingTrieNodesNotifier, sentSignaturesTracker process.SentSignaturesTracker, - relayedV3TxProcessor process.RelayedTxV3Processor, ) (process.BlockProcessor, process.EpochStartSystemSCProcessor, error) { blockProcessorComponents, err := pcf.newBlockProcessor( requestHandler, @@ -43,7 +42,6 @@ func (pcf *processComponentsFactory) NewBlockProcessor( blockProcessingCutoff, missingTrieNodesNotifier, sentSignaturesTracker, - relayedV3TxProcessor, ) if err != nil { return nil, nil, err @@ -53,6 +51,6 @@ func (pcf *processComponentsFactory) NewBlockProcessor( } // CreateAPITransactionEvaluator - -func (pcf *processComponentsFactory) CreateAPITransactionEvaluator(relayedV3TxProcessor process.RelayedTxV3Processor) (factory.TransactionEvaluator, process.VirtualMachinesContainerFactory, error) { - return pcf.createAPITransactionEvaluator(relayedV3TxProcessor) +func (pcf *processComponentsFactory) CreateAPITransactionEvaluator() (factory.TransactionEvaluator, process.VirtualMachinesContainerFactory, error) { + return pcf.createAPITransactionEvaluator() } diff --git a/factory/processing/processComponents.go b/factory/processing/processComponents.go index 6f711a502ae..482343bbadf 100644 --- a/factory/processing/processComponents.go +++ b/factory/processing/processComponents.go @@ -62,7 +62,6 @@ 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" @@ -134,7 +133,6 @@ type processComponents struct { receiptsRepository mainFactory.ReceiptsRepository sentSignaturesTracker process.SentSignaturesTracker epochSystemSCProcessor process.EpochStartSystemSCProcessor - relayedTxV3Processor process.RelayedTxV3Processor } // ProcessComponentsFactoryArgs holds the arguments needed to create a process components factory @@ -517,16 +515,6 @@ 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(), @@ -536,7 +524,6 @@ func (pcf *processComponentsFactory) Create() (*processComponents, error) { mainPeerShardMapper, fullArchivePeerShardMapper, hardforkTrigger, - relayedTxV3Processor, ) if err != nil { return nil, err @@ -633,7 +620,6 @@ func (pcf *processComponentsFactory) Create() (*processComponents, error) { blockCutoffProcessingHandler, pcf.state.MissingTrieNodesNotifier(), sentSignaturesTracker, - relayedTxV3Processor, ) if err != nil { return nil, err @@ -723,7 +709,7 @@ func (pcf *processComponentsFactory) Create() (*processComponents, error) { return nil, err } - apiTransactionEvaluator, vmFactoryForTxSimulate, err := pcf.createAPITransactionEvaluator(relayedTxV3Processor) + apiTransactionEvaluator, vmFactoryForTxSimulate, err := pcf.createAPITransactionEvaluator() if err != nil { return nil, fmt.Errorf("%w when assembling components for the transactions simulator processor", err) } @@ -776,7 +762,6 @@ func (pcf *processComponentsFactory) Create() (*processComponents, error) { accountsParser: pcf.accountsParser, receiptsRepository: receiptsRepository, sentSignaturesTracker: sentSignaturesTracker, - relayedTxV3Processor: relayedTxV3Processor, }, nil } @@ -1508,7 +1493,6 @@ 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 { @@ -1527,7 +1511,6 @@ func (pcf *processComponentsFactory) newInterceptorContainerFactory( fullArchivePeerShardMapper, hardforkTrigger, nodeOperationMode, - relayedTxV3Processor, ) } if shardCoordinator.SelfId() == core.MetachainShardId { @@ -1541,7 +1524,6 @@ func (pcf *processComponentsFactory) newInterceptorContainerFactory( fullArchivePeerShardMapper, hardforkTrigger, nodeOperationMode, - relayedTxV3Processor, ) } @@ -1681,7 +1663,6 @@ 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{ @@ -1715,7 +1696,6 @@ func (pcf *processComponentsFactory) newShardInterceptorContainerFactory( FullArchivePeerShardMapper: fullArchivePeerShardMapper, HardforkTrigger: hardforkTrigger, NodeOperationMode: nodeOperationMode, - RelayedTxV3Processor: relayedTxV3Processor, } interceptorContainerFactory, err := interceptorscontainer.NewShardInterceptorsContainerFactory(shardInterceptorsContainerFactoryArgs) @@ -1736,7 +1716,6 @@ 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{ @@ -1770,7 +1749,6 @@ 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 94f21a5b8f2..28b3c4b0eed 100644 --- a/factory/processing/processComponentsHandler.go +++ b/factory/processing/processComponentsHandler.go @@ -180,9 +180,6 @@ func (m *managedProcessComponents) CheckSubcomponents() error { if check.IfNil(m.processComponents.epochSystemSCProcessor) { return errors.ErrNilEpochSystemSCProcessor } - if check.IfNil(m.processComponents.relayedTxV3Processor) { - return errors.ErrNilRelayedTxV3Processor - } return nil } @@ -691,18 +688,6 @@ func (m *managedProcessComponents) EpochSystemSCProcessor() process.EpochStartSy return m.processComponents.epochSystemSCProcessor } -// 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/processComponentsHandler_test.go b/factory/processing/processComponentsHandler_test.go index c999d25b041..2aec3cb8c6e 100644 --- a/factory/processing/processComponentsHandler_test.go +++ b/factory/processing/processComponentsHandler_test.go @@ -94,7 +94,6 @@ func TestManagedProcessComponents_Create(t *testing.T) { require.True(t, check.IfNil(managedProcessComponents.FullArchiveInterceptorsContainer())) require.True(t, check.IfNil(managedProcessComponents.SentSignaturesTracker())) require.True(t, check.IfNil(managedProcessComponents.EpochSystemSCProcessor())) - require.True(t, check.IfNil(managedProcessComponents.RelayedTxV3Processor())) err := managedProcessComponents.Create() require.NoError(t, err) @@ -140,7 +139,6 @@ func TestManagedProcessComponents_Create(t *testing.T) { require.False(t, check.IfNil(managedProcessComponents.FullArchiveInterceptorsContainer())) require.False(t, check.IfNil(managedProcessComponents.SentSignaturesTracker())) require.False(t, check.IfNil(managedProcessComponents.EpochSystemSCProcessor())) - require.False(t, check.IfNil(managedProcessComponents.RelayedTxV3Processor())) require.Equal(t, factory.ProcessComponentsName, managedProcessComponents.String()) }) diff --git a/factory/processing/txSimulatorProcessComponents.go b/factory/processing/txSimulatorProcessComponents.go index 21fe2ddc073..257a46af1a5 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(relayedTxV3Processor process.RelayedTxV3Processor) (factory.TransactionEvaluator, process.VirtualMachinesContainerFactory, error) { +func (pcf *processComponentsFactory) createAPITransactionEvaluator() (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(relayedTxV3Pr return nil, nil, err } - txSimulatorProcessorArgs, vmContainerFactory, txTypeHandler, err := pcf.createArgsTxSimulatorProcessor(simulationAccountsDB, vmOutputCacher, txLogsProcessor, relayedTxV3Processor) + txSimulatorProcessorArgs, vmContainerFactory, txTypeHandler, err := pcf.createArgsTxSimulatorProcessor(simulationAccountsDB, vmOutputCacher, txLogsProcessor) if err != nil { return nil, nil, err } @@ -89,13 +89,12 @@ 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, relayedTxV3Processor) + return pcf.createArgsTxSimulatorProcessorShard(accountsAdapter, vmOutputCacher, txLogsProcessor) } } @@ -173,32 +172,29 @@ 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, - FailedTxLogsAccumulator: failedTxLogsAccumulator, + 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, } scProcessor, err := smartContract.NewSmartContractProcessor(scProcArgs) @@ -253,7 +249,6 @@ 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{} @@ -351,32 +346,29 @@ 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, - FailedTxLogsAccumulator: failedTxLogsAccumulator, + 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, } scProcessor, err := smartContract.NewSmartContractProcessor(scProcArgs) @@ -385,27 +377,25 @@ 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, - FailedTxLogsAccumulator: failedTxLogsAccumulator, + 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, } txProcessor, err := transaction.NewTxProcessor(argsTxProcessor) diff --git a/factory/processing/txSimulatorProcessComponents_test.go b/factory/processing/txSimulatorProcessComponents_test.go index 37944768bfe..aad848600d8 100644 --- a/factory/processing/txSimulatorProcessComponents_test.go +++ b/factory/processing/txSimulatorProcessComponents_test.go @@ -8,7 +8,6 @@ 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" ) @@ -27,7 +26,7 @@ func TestManagedProcessComponents_createAPITransactionEvaluator(t *testing.T) { processArgs.Config.VMOutputCacher.Type = "invalid" pcf, _ := processing.NewProcessComponentsFactory(processArgs) - apiTransactionEvaluator, vmContainerFactory, err := pcf.CreateAPITransactionEvaluator(&processMocks.RelayedTxV3ProcessorMock{}) + apiTransactionEvaluator, vmContainerFactory, err := pcf.CreateAPITransactionEvaluator() assert.NotNil(t, err) assert.True(t, check.IfNil(apiTransactionEvaluator)) assert.True(t, check.IfNil(vmContainerFactory)) @@ -37,7 +36,7 @@ func TestManagedProcessComponents_createAPITransactionEvaluator(t *testing.T) { processArgs := components.GetProcessComponentsFactoryArgs(shardCoordinatorForShardID2) pcf, _ := processing.NewProcessComponentsFactory(processArgs) - apiTransactionEvaluator, vmContainerFactory, err := pcf.CreateAPITransactionEvaluator(&processMocks.RelayedTxV3ProcessorMock{}) + apiTransactionEvaluator, vmContainerFactory, err := pcf.CreateAPITransactionEvaluator() assert.Nil(t, err) assert.False(t, check.IfNil(apiTransactionEvaluator)) assert.False(t, check.IfNil(vmContainerFactory)) @@ -46,7 +45,7 @@ func TestManagedProcessComponents_createAPITransactionEvaluator(t *testing.T) { processArgs := components.GetProcessComponentsFactoryArgs(shardCoordinatorForMetachain) pcf, _ := processing.NewProcessComponentsFactory(processArgs) - apiTransactionEvaluator, vmContainerFactory, err := pcf.CreateAPITransactionEvaluator(&processMocks.RelayedTxV3ProcessorMock{}) + apiTransactionEvaluator, vmContainerFactory, err := pcf.CreateAPITransactionEvaluator() assert.Nil(t, err) assert.False(t, check.IfNil(apiTransactionEvaluator)) assert.False(t, check.IfNil(vmContainerFactory)) diff --git a/genesis/process/disabled/feeHandler.go b/genesis/process/disabled/feeHandler.go index f81e7e978eb..1fc34bbc2b5 100644 --- a/genesis/process/disabled/feeHandler.go +++ b/genesis/process/disabled/feeHandler.go @@ -183,11 +183,6 @@ 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/genesis/process/metaGenesisBlockCreator.go b/genesis/process/metaGenesisBlockCreator.go index 78546562736..f695c274b42 100644 --- a/genesis/process/metaGenesisBlockCreator.go +++ b/genesis/process/metaGenesisBlockCreator.go @@ -28,7 +28,6 @@ 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" @@ -431,11 +430,6 @@ 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 @@ -443,29 +437,28 @@ 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(), - FailedTxLogsAccumulator: disabledProcess.NewFailedTxLogsAccumulator(), + 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(), } scProcessorProxy, err := processProxy.NewSmartContractProcessorProxy(argsNewSCProcessor, epochNotifier) diff --git a/genesis/process/shardGenesisBlockCreator.go b/genesis/process/shardGenesisBlockCreator.go index b44ed14c207..2347632d2d5 100644 --- a/genesis/process/shardGenesisBlockCreator.go +++ b/genesis/process/shardGenesisBlockCreator.go @@ -24,7 +24,6 @@ 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" @@ -501,40 +500,34 @@ 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 } 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, - FailedTxLogsAccumulator: processDisabled.NewFailedTxLogsAccumulator(), + 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, } scProcessorProxy, err := processProxy.NewSmartContractProcessorProxy(argsNewScProcessor, epochNotifier) @@ -552,27 +545,25 @@ 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(), - FailedTxLogsAccumulator: processDisabled.NewFailedTxLogsAccumulator(), + 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, } transactionProcessor, err := transaction.NewTxProcessor(argsNewTxProcessor) if err != nil { diff --git a/go.mod b/go.mod index d2b76ce9593..8718f3e9d10 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.1.0 - github.com/multiversx/mx-chain-core-go v1.2.22 + github.com/multiversx/mx-chain-core-go v1.2.23-0.20241018134424-75bab2a9058c github.com/multiversx/mx-chain-crypto-go v1.2.12 - github.com/multiversx/mx-chain-es-indexer-go v1.7.9 + github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018153953-b27532a1b4a6 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 0b789eb79b2..232f91ed5a7 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.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 h1:yDYrvoQOBbsDerEp7L3+de5AfMy3pTF333gWPpd+FNk= -github.com/multiversx/mx-chain-core-go v1.2.22/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.23-0.20241018134424-75bab2a9058c h1:hPCfMSj2vd9xNkARNxB1b3b9k8taFb+Xfja+WK97jno= +github.com/multiversx/mx-chain-core-go v1.2.23-0.20241018134424-75bab2a9058c/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4= -github.com/multiversx/mx-chain-es-indexer-go v1.7.9 h1:rWq9phJu8GG6TtoJ5cL+MmhyReWCEyqBE5ymXUvudCg= -github.com/multiversx/mx-chain-es-indexer-go v1.7.9/go.mod h1:oGcRK2E3Syv6vRTszWrrb/TqD8akq0yeoMr1wPPiTO4= +github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018153953-b27532a1b4a6 h1:2F5WyCIvFVs4CONd9kJxibY1NIfJLYFAwqNJvC31qNA= +github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018153953-b27532a1b4a6/go.mod h1:AJew7KVcICVyVDlXpDQzvjcSnKs0aCYl7eXnJwg+15E= 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= diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index fa2b02b9fe3..f7c0f74649b 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -4,7 +4,6 @@ import ( "encoding/hex" "encoding/json" "math/big" - "strconv" "strings" "testing" "time" @@ -18,9 +17,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" - 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/require" ) @@ -28,8 +24,6 @@ const ( defaultPathToInitialConfig = "../../../cmd/node/config/" minGasPrice = 1_000_000_000 minGasLimit = 50_000 - guardAccountCost = 250_000 - extraGasLimitForGuarded = minGasLimit gasPerDataByte = 1_500 txVersion = 2 mockTxSignature = "sig" @@ -38,383 +32,9 @@ const ( ) var ( - oneEGLD = big.NewInt(1000000000000000000) - alterConfigsFuncRelayedV3EarlyActivation = func(cfg *config.Configs) { - cfg.EpochConfig.EnableEpochs.RelayedTransactionsV3EnableEpoch = 1 - cfg.EpochConfig.EnableEpochs.FixRelayedBaseCostEnableEpoch = 1 - } + oneEGLD = big.NewInt(1000000000000000000) ) -func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulator(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(30000)) - 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) - - err = cs.GenerateBlocks(1) - require.Nil(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) - - err = cs.GenerateBlocks(1) - require.Nil(t, err) - - 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 - // deploy a wrapper contract - 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, "@") - 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, innerTx3Failure, innerTx3} - - // 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) - - 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)) - } - checkBalance(t, cs, relayer, big.NewInt(0).Sub(initialBalance, expectedRelayerFee)) - - checkBalance(t, cs, sender, big.NewInt(0).Sub(initialBalance, big.NewInt(0).Mul(oneEGLD, big.NewInt(2)))) - - checkBalance(t, cs, sender2, big.NewInt(0).Sub(initialBalance, oneEGLD)) - - checkBalance(t, cs, receiver, oneEGLD) - - checkBalance(t, cs, receiver2, big.NewInt(0).Mul(oneEGLD, big.NewInt(2))) - - // check SCRs - shardC := cs.GetNodeHandler(0).GetShardCoordinator() - for _, scr := range result.SmartContractResults { - checkSCRSucceeded(t, cs, pkConv, shardC, scr) - } - - // 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 TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorAndInvalidNonces(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(30000)) - 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) - - // bump sender nonce to 3 - tx0 := generateTransaction(sender.Bytes, 0, sender.Bytes, big.NewInt(0), "", minGasLimit) - tx1 := generateTransaction(sender.Bytes, 1, sender.Bytes, big.NewInt(0), "", minGasLimit) - tx2 := generateTransaction(sender.Bytes, 2, sender.Bytes, big.NewInt(0), "", minGasLimit) - _, err = cs.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{tx0, tx1, tx2}, maxNumOfBlocksToGenerateWhenExecutingTx) - require.Nil(t, err) - - // higher nonce - innerTx1 := generateTransaction(sender.Bytes, 10, receiver.Bytes, oneEGLD, "", minGasLimit) - innerTx1.RelayerAddr = relayer.Bytes - - // higher nonce - innerTx2 := generateTransaction(sender.Bytes, 9, receiver.Bytes, oneEGLD, "", minGasLimit) - innerTx2.RelayerAddr = relayer.Bytes - - // nonce ok - innerTx3 := generateTransaction(sender.Bytes, 3, receiver.Bytes, oneEGLD, "", minGasLimit) - innerTx3.RelayerAddr = relayer.Bytes - - // higher nonce - innerTx4 := generateTransaction(sender.Bytes, 8, receiver.Bytes, oneEGLD, "", minGasLimit) - innerTx4.RelayerAddr = relayer.Bytes - - // lower nonce - initial one - innerTx5 := generateTransaction(sender.Bytes, 3, receiver.Bytes, oneEGLD, "", minGasLimit) - innerTx5.RelayerAddr = relayer.Bytes - - innerTxs := []*transaction.Transaction{innerTx1, innerTx2, innerTx3, innerTx4, innerTx5} - - // 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) - - // 5 scrs, 4 from the failed txs + 1 with success - require.Equal(t, 5, len(result.SmartContractResults)) - scrsMap := make(map[string]int, len(result.SmartContractResults)) - for _, scr := range result.SmartContractResults { - if len(scr.ReturnMessage) == 0 { - scrsMap["success"]++ - } - if strings.Contains(scr.ReturnMessage, process.ErrHigherNonceInTransaction.Error()) { - scrsMap[process.ErrHigherNonceInTransaction.Error()]++ - } - if strings.Contains(scr.ReturnMessage, process.ErrLowerNonceInTransaction.Error()) { - scrsMap[process.ErrLowerNonceInTransaction.Error()]++ - } - } - require.Equal(t, 1, scrsMap["success"]) - require.Equal(t, 3, scrsMap[process.ErrHigherNonceInTransaction.Error()]) - require.Equal(t, 1, scrsMap[process.ErrLowerNonceInTransaction.Error()]) - - // 4 log events from the failed txs - require.Equal(t, 4, len(result.Logs.Events)) - for _, event := range result.Logs.Events { - require.Equal(t, core.SignalErrorOperation, event.Identifier) - } -} - -func TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorScCalls(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) - - pkConv := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter() - shardC := cs.GetNodeHandler(0).GetShardCoordinator() - - // deploy adder contract - owner, err := cs.GenerateAndMintWalletAddress(0, initialBalance) - require.NoError(t, err) - - err = cs.GenerateBlocks(1) - require.Nil(t, err) - - ownerNonce := uint64(0) - scAddressBytes := deployAdder(t, cs, owner, ownerNonce) - 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(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) - - 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 - } - - checkSCRSucceeded(t, cs, pkConv, shardC, scr) - } - - // 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]", - 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 TestRelayedTransactionInMultiShardEnvironmentWithChainSimulatorInnerMoveBalanceToNonPayableSC(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") @@ -594,131 +214,6 @@ 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) - - 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")) - 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 TestRelayedTransactionFeeField(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") @@ -726,8 +221,6 @@ func TestRelayedTransactionFeeField(t *testing.T) { 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() @@ -757,22 +250,6 @@ func TestRelayedTransactionFeeField(t *testing.T) { 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) @@ -829,58 +306,6 @@ func generateTransaction(sender []byte, nonce uint64, receiver []byte, value *bi } } -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 checkSCRSucceeded( - 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) - 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 { - continue - } - - require.Equal(t, core.CompletedTxEventIdentifier, event.Identifier) - } -} - func getBalance( t *testing.T, cs testsChainSimulator.ChainSimulator, @@ -895,16 +320,6 @@ 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()) -} - func deployAdder( t *testing.T, cs testsChainSimulator.ChainSimulator, diff --git a/integrationTests/mock/processComponentsStub.go b/integrationTests/mock/processComponentsStub.go index 04dad00a52c..11d4f4ce69d 100644 --- a/integrationTests/mock/processComponentsStub.go +++ b/integrationTests/mock/processComponentsStub.go @@ -61,7 +61,6 @@ type ProcessComponentsStub struct { ESDTDataStorageHandlerForAPIInternal vmcommon.ESDTNFTStorageHandler SentSignaturesTrackerInternal process.SentSignaturesTracker EpochSystemSCProcessorInternal process.EpochStartSystemSCProcessor - RelayedTxV3ProcessorField process.RelayedTxV3Processor } // Create - @@ -303,11 +302,6 @@ func (pcs *ProcessComponentsStub) EpochSystemSCProcessor() process.EpochStartSys return pcs.EpochSystemSCProcessorInternal } -// RelayedTxV3Processor - -func (pcs *ProcessComponentsStub) RelayedTxV3Processor() process.RelayedTxV3Processor { - return pcs.RelayedTxV3ProcessorField -} - // IsInterfaceNil - func (pcs *ProcessComponentsStub) IsInterfaceNil() bool { return pcs == nil diff --git a/integrationTests/multiShard/relayedTx/common.go b/integrationTests/multiShard/relayedTx/common.go index 6815d12802e..54d99ff869d 100644 --- a/integrationTests/multiShard/relayedTx/common.go +++ b/integrationTests/multiShard/relayedTx/common.go @@ -19,7 +19,6 @@ func CreateGeneralSetupForRelayTxTest(relayedV3Test bool) ([]*integrationTests.T initialVal := big.NewInt(10000000000) epochsConfig := integrationTests.GetDefaultEnableEpochsConfig() if !relayedV3Test { - epochsConfig.RelayedTransactionsV3EnableEpoch = integrationTests.UnreachableEpoch epochsConfig.FixRelayedBaseCostEnableEpoch = integrationTests.UnreachableEpoch epochsConfig.FixRelayedMoveBalanceToNonPayableSCEnableEpoch = integrationTests.UnreachableEpoch } @@ -90,7 +89,7 @@ func CreateAndSendRelayedAndUserTx( ) (*transaction.Transaction, *transaction.Transaction) { txDispatcherNode := getNodeWithinSameShardAsPlayer(nodes, relayer.Address) - userTx := createUserTx(player, rcvAddr, value, gasLimit, txData, nil) + userTx := createUserTx(player, rcvAddr, value, gasLimit, txData) relayedTx := createRelayedTx(txDispatcherNode.EconomicsData, relayer, userTx) _, err := txDispatcherNode.SendTransaction(relayedTx) @@ -113,7 +112,7 @@ func CreateAndSendRelayedAndUserTxV2( ) (*transaction.Transaction, *transaction.Transaction) { txDispatcherNode := getNodeWithinSameShardAsPlayer(nodes, relayer.Address) - userTx := createUserTx(player, rcvAddr, value, 0, txData, nil) + userTx := createUserTx(player, rcvAddr, value, 0, txData) relayedTx := createRelayedTxV2(txDispatcherNode.EconomicsData, relayer, userTx, gasLimit) _, err := txDispatcherNode.SendTransaction(relayedTx) @@ -124,48 +123,23 @@ func CreateAndSendRelayedAndUserTxV2( return relayedTx, userTx } -// 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, *transaction.Transaction) { - txDispatcherNode := getNodeWithinSameShardAsPlayer(nodes, relayer.Address) - - userTx := createUserTx(player, rcvAddr, value, gasLimit, txData, relayer.Address) - relayedTx := createRelayedTxV3(txDispatcherNode.EconomicsData, relayer, userTx) - - _, err := txDispatcherNode.SendTransaction(relayedTx) - if err != nil { - fmt.Println(err.Error()) - } - - return relayedTx, userTx -} - func createUserTx( player *integrationTests.TestWalletAccount, rcvAddr []byte, 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, - RelayerAddr: relayerAddress, + 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, } txBuff, _ := tx.GetDataForSigning(integrationTests.TestAddressPubkeyConverter, integrationTests.TestTxSignMarshalizer, integrationTests.TestTxSignHasher) tx.Signature, _ = player.SingleSigner.Sign(player.SkTxSign, txBuff) @@ -238,37 +212,6 @@ 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), - 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 - - txBuff, _ := tx.GetDataForSigning(integrationTests.TestAddressPubkeyConverter, integrationTests.TestTxSignMarshalizer, integrationTests.TestTxSignHasher) - tx.Signature, _ = relayer.SingleSigner.Sign(relayer.SkTxSign, txBuff) - relayer.Nonce++ - - relayer.Balance.Sub(relayer.Balance, tx.Value) - - txFee := economicsFee.ComputeTxFee(tx) - relayer.Balance.Sub(relayer.Balance, txFee) - - return tx -} - func createAndSendSimpleTransaction( nodes []*integrationTests.TestProcessorNode, player *integrationTests.TestWalletAccount, @@ -279,7 +222,7 @@ func createAndSendSimpleTransaction( ) { txDispatcherNode := getNodeWithinSameShardAsPlayer(nodes, player.Address) - userTx := createUserTx(player, rcvAddr, value, gasLimit, txData, nil) + userTx := createUserTx(player, rcvAddr, value, gasLimit, txData) _, err := txDispatcherNode.SendTransaction(userTx) if err != nil { fmt.Println(err.Error()) diff --git a/integrationTests/multiShard/relayedTx/relayedTx_test.go b/integrationTests/multiShard/relayedTx/relayedTx_test.go index d9ea772d7ba..87a54633953 100644 --- a/integrationTests/multiShard/relayedTx/relayedTx_test.go +++ b/integrationTests/multiShard/relayedTx/relayedTx_test.go @@ -33,24 +33,20 @@ type createAndSendRelayedAndUserTxFuncType = func( func TestRelayedTransactionInMultiShardEnvironmentWithNormalTx(t *testing.T) { 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, 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, 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, false)) - t.Run("relayed v3", testRelayedTransactionInMultiShardEnvironmentWithAttestationContract(CreateAndSendRelayedAndUserTxV3, true)) } func testRelayedTransactionInMultiShardEnvironmentWithNormalTx( diff --git a/integrationTests/testHeartbeatNode.go b/integrationTests/testHeartbeatNode.go index 43b2ac576a0..1ba488b9e12 100644 --- a/integrationTests/testHeartbeatNode.go +++ b/integrationTests/testHeartbeatNode.go @@ -54,7 +54,6 @@ 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" @@ -627,7 +626,6 @@ 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 06dc1a24866..a7c6cdac3c3 100644 --- a/integrationTests/testInitializer.go +++ b/integrationTests/testInitializer.go @@ -69,7 +69,6 @@ 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" @@ -1056,17 +1055,15 @@ 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{}, - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + 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{}, } txProcessor, _ := txProc.NewTxProcessor(argsNewTxProcessor) diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index cf76e1582d0..dc828291384 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/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" @@ -1288,12 +1287,6 @@ func (tpn *TestProcessorNode) initInterceptors(heartbeatPk string) { cryptoComponents.BlKeyGen = tpn.OwnAccount.KeygenBlockSign cryptoComponents.TxKeyGen = tpn.OwnAccount.KeygenTxSign - relayedV3TxProcessor, _ := transaction.NewRelayedTxV3Processor(transaction.ArgRelayedTxV3Processor{ - EconomicsFee: tpn.EconomicsData, - ShardCoordinator: tpn.ShardCoordinator, - MaxTransactionsAllowed: 10, - }) - if tpn.ShardCoordinator.SelfId() == core.MetachainShardId { argsEpochStart := &metachain.ArgsNewMetaEpochStartTrigger{ GenesisTime: tpn.RoundHandler.TimeStamp(), @@ -1346,7 +1339,6 @@ func (tpn *TestProcessorNode) initInterceptors(heartbeatPk string) { FullArchivePeerShardMapper: tpn.FullArchivePeerShardMapper, HardforkTrigger: tpn.HardforkTrigger, NodeOperationMode: tpn.NodeOperationMode, - RelayedTxV3Processor: relayedV3TxProcessor, } interceptorContainerFactory, _ := interceptorscontainer.NewMetaInterceptorsContainerFactory(metaInterceptorContainerFactoryArgs) @@ -1415,7 +1407,6 @@ func (tpn *TestProcessorNode) initInterceptors(heartbeatPk string) { FullArchivePeerShardMapper: tpn.FullArchivePeerShardMapper, HardforkTrigger: tpn.HardforkTrigger, NodeOperationMode: tpn.NodeOperationMode, - RelayedTxV3Processor: relayedV3TxProcessor, } interceptorContainerFactory, _ := interceptorscontainer.NewShardInterceptorsContainerFactory(shardIntereptorContainerFactoryArgs) @@ -1696,66 +1687,56 @@ 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) 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, - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + 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, } tpn.ScProcessor, _ = processProxy.NewTestSmartContractProcessorProxy(argsNewScProcessor, tpn.EpochNotifier) - relayedV3TxProcessor, _ := transaction.NewRelayedTxV3Processor(transaction.ArgRelayedTxV3Processor{ - EconomicsFee: tpn.EconomicsData, - ShardCoordinator: tpn.ShardCoordinator, - MaxTransactionsAllowed: 10, - }) - 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, - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + 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, } tpn.TxProcessor, _ = transaction.NewTxProcessor(argsNewTxProcessor) scheduledSCRsStorer, _ := tpn.Storage.GetStorer(dataRetriever.ScheduledSCRsUnit) @@ -1986,32 +1967,30 @@ 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{ - 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{}, + 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, } tpn.ScProcessor, _ = processProxy.NewTestSmartContractProcessorProxy(argsNewScProcessor, tpn.EpochNotifier) @@ -2614,22 +2593,21 @@ 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), - InnerTransactions: tx.InnerTransactions, + 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), } tx, txHash, err := tpn.Node.CreateTransaction(createTxArgs) if err != nil { @@ -3275,7 +3253,6 @@ func CreateEnableEpochsConfig() config.EnableEpochs { MiniBlockPartialExecutionEnableEpoch: UnreachableEpoch, RefactorPeersMiniBlocksEnableEpoch: UnreachableEpoch, SCProcessorV2EnableEpoch: UnreachableEpoch, - RelayedTransactionsV3EnableEpoch: UnreachableEpoch, FixRelayedBaseCostEnableEpoch: UnreachableEpoch, FixRelayedMoveBalanceToNonPayableSCEnableEpoch: UnreachableEpoch, } @@ -3363,11 +3340,6 @@ 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/testProcessorNodeWithTestWebServer.go b/integrationTests/testProcessorNodeWithTestWebServer.go index d533f4c75b1..b4e2490b900 100644 --- a/integrationTests/testProcessorNodeWithTestWebServer.go +++ b/integrationTests/testProcessorNodeWithTestWebServer.go @@ -163,7 +163,6 @@ 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 c701007ca00..c6e33ddc21a 100644 --- a/integrationTests/vm/testInitializer.go +++ b/integrationTests/vm/testInitializer.go @@ -62,7 +62,6 @@ 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" @@ -141,9 +140,8 @@ type VMTestContext struct { ContractOwner VMTestAccount Contract VMTestAccount - TxCostHandler external.TransactionEvaluator - TxsLogsProcessor process.TransactionLogProcessor - FailedTxLogsAccumulator process.FailedTxLogsAccumulator + TxCostHandler external.TransactionEvaluator + TxsLogsProcessor process.TransactionLogProcessor } // Close - @@ -443,7 +441,6 @@ func CreateTxProcessorWithOneSCExecutorMockVM( if err != nil { return nil, err } - _ = economicsData.SetTxTypeHandler(txTypeHandler) argsNewSCProcessor := scrCommon.ArgsNewSmartContractProcessor{ VmContainer: vmContainer, @@ -463,13 +460,12 @@ 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, - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + GasSchedule: gasScheduleNotifier, + TxLogsProcessor: &mock.TxLogsProcessorStub{}, + EnableEpochsHandler: enableEpochsHandler, + EnableRoundsHandler: enableRoundsHandler, + VMOutputCacher: txcache.NewDisabledCache(), + WasmVMChangeLocker: wasmVMChangeLocker, } scProcessor, _ := processProxy.NewTestSmartContractProcessorProxy(argsNewSCProcessor, genericEpochNotifier) @@ -480,27 +476,25 @@ 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{}, - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + 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{}, } return transaction.NewTxProcessor(argsNewTxProcessor) @@ -810,13 +804,12 @@ 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 - FailedTxLogsAccumulator process.FailedTxLogsAccumulator + TxProc process.TransactionProcessor + SCProc scrCommon.TestSmartContractProcessor + IntermediateTxProc process.IntermediateTransactionHandler + EconomicsHandler process.EconomicsDataHandler + CostHandler external.TransactionEvaluator + TxLogProc process.TransactionLogProcessor } // CreateTxProcessorWithOneSCExecutorWithVMs - @@ -861,7 +854,6 @@ func CreateTxProcessorWithOneSCExecutorWithVMs( if err != nil { return nil, err } - _ = economicsData.SetTxTypeHandler(txTypeHandler) gasComp, err := preprocess.NewGasComputation(economicsData, txTypeHandler, enableEpochsHandler) if err != nil { @@ -873,58 +865,53 @@ func CreateTxProcessorWithOneSCExecutorWithVMs( Marshalizer: integrationtests.TestMarshalizer, }) - failedLogsAcc := transactionLog.NewFailedTxLogsAccumulator() - 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(), - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + 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(), } 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, - FailedTxLogsAccumulator: failedLogsAcc, - 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, } txProcessor, err := transaction.NewTxProcessor(argsNewTxProcessor) if err != nil { @@ -1331,24 +1318,23 @@ 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, - FailedTxLogsAccumulator: res.FailedTxLogsAccumulator, - 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, + GasSchedule: gasScheduleNotifier, + EpochNotifier: epochNotifierInstance, + EnableEpochsHandler: enableEpochsHandler, + ChainHandler: chainHandler, + Marshalizer: integrationtests.TestMarshalizer, + GuardedAccountsHandler: guardedAccountHandler, }, nil } @@ -1945,22 +1931,21 @@ 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, - FailedTxLogsAccumulator: res.FailedTxLogsAccumulator, - 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, + EpochNotifier: epochNotifierInstance, + EnableEpochsHandler: enableEpochsHandler, + ChainHandler: chainHandler, + GuardedAccountsHandler: guardedAccountHandler, }, nil } diff --git a/integrationTests/vm/wasm/utils.go b/integrationTests/vm/wasm/utils.go index 7ec28bb8f45..bfe7b4b7ca9 100644 --- a/integrationTests/vm/wasm/utils.go +++ b/integrationTests/vm/wasm/utils.go @@ -53,7 +53,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/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" @@ -392,40 +391,37 @@ 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(), - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + GasSchedule: mock.NewGasScheduleNotifierMock(gasSchedule), + TxLogsProcessor: context.TxLogsProcessor, + EnableRoundsHandler: context.EnableRoundsHandler, + EnableEpochsHandler: context.EnableEpochsHandler, + WasmVMChangeLocker: context.WasmVMChangeLocker, + VMOutputCacher: txcache.NewDisabledCache(), } 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{}, - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + 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, } 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 9ad6a861235..2957aa42add 100644 --- a/integrationTests/vm/wasm/wasmvm/wasmVM_test.go +++ b/integrationTests/vm/wasm/wasmvm/wasmVM_test.go @@ -31,7 +31,6 @@ 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" @@ -630,25 +629,23 @@ 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{}, - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + 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{}, } txProc, _ := processTransaction.NewTxProcessor(argsNewTxProcessor) diff --git a/node/chainSimulator/components/processComponents.go b/node/chainSimulator/components/processComponents.go index 6e00d776784..cbd119fa517 100644 --- a/node/chainSimulator/components/processComponents.go +++ b/node/chainSimulator/components/processComponents.go @@ -100,7 +100,6 @@ type processComponentsHolder struct { accountsParser genesis.AccountsParser sentSignatureTracker process.SentSignaturesTracker epochStartSystemSCProcessor process.EpochStartSystemSCProcessor - relayedTxV3Processor process.RelayedTxV3Processor managedProcessComponentsCloser io.Closer } @@ -284,7 +283,6 @@ func CreateProcessComponents(args ArgsProcessComponentsHolder) (*processComponen accountsParser: managedProcessComponents.AccountsParser(), sentSignatureTracker: managedProcessComponents.SentSignaturesTracker(), epochStartSystemSCProcessor: managedProcessComponents.EpochSystemSCProcessor(), - relayedTxV3Processor: managedProcessComponents.RelayedTxV3Processor(), managedProcessComponentsCloser: managedProcessComponents, } @@ -525,11 +523,6 @@ func (p *processComponentsHolder) EpochSystemSCProcessor() process.EpochStartSys return p.epochStartSystemSCProcessor } -// 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/chainSimulator/components/processComponents_test.go b/node/chainSimulator/components/processComponents_test.go index 93b6a7689a3..a8cb2f053e7 100644 --- a/node/chainSimulator/components/processComponents_test.go +++ b/node/chainSimulator/components/processComponents_test.go @@ -408,7 +408,6 @@ func TestProcessComponentsHolder_Getters(t *testing.T) { require.NotNil(t, comp.AccountsParser()) require.NotNil(t, comp.ReceiptsRepository()) require.NotNil(t, comp.EpochSystemSCProcessor()) - require.NotNil(t, comp.RelayedTxV3Processor()) require.Nil(t, comp.CheckSubcomponents()) require.Empty(t, comp.String()) diff --git a/node/external/dtos.go b/node/external/dtos.go index 12a6b153c46..ad8d073967b 100644 --- a/node/external/dtos.go +++ b/node/external/dtos.go @@ -1,24 +1,21 @@ package external -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 - InnerTransactions []*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 } diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index 530b6b81b3d..ab5c77fee40 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -58,24 +58,17 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction } hasRefundForSender := false - totalRefunds := big.NewInt(0) for _, scr := range tx.SmartContractResults { if !scr.IsRefund || scr.RcvAddr != tx.Sender { continue } + if scr.RcvAddr != tx.Sender { + continue + } + gfp.setGasUsedAndFeeBaseOnRefundValue(tx, scr.Value) hasRefundForSender = true - totalRefunds.Add(totalRefunds, scr.Value) - } - - if totalRefunds.Cmp(big.NewInt(0)) > 0 { - gasUsed, fee = gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(tx, totalRefunds) - tx.GasUsed = gasUsed - tx.Fee = fee.String() - } - - if isRelayedAfterFix { - return + break } gfp.prepareTxWithResultsBasedOnLogs(tx, hasRefundForSender) @@ -86,10 +79,6 @@ func (gfp *gasUsedAndFeeProcessor) getFeeOfRelayed(tx *transaction.ApiTransactio return nil, false } - if len(tx.InnerTransactions) > 0 { - return gfp.feeComputer.ComputeTransactionFee(tx), true - } - if len(tx.Data) == 0 { return nil, false } @@ -180,6 +169,16 @@ func (gfp *gasUsedAndFeeProcessor) setGasUsedAndFeeBaseOnLogEvent(tx *transactio } } +func (gfp *gasUsedAndFeeProcessor) setGasUsedAndFeeBaseOnRefundValue(tx *transaction.ApiTransactionResult, refund *big.Int) { + + gasUsed, fee := gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(tx, refund) + + tx.GasUsed = gasUsed + + tx.Fee = fee.String() + +} + func (gfp *gasUsedAndFeeProcessor) isESDTOperationWithSCCall(tx *transaction.ApiTransactionResult) bool { isESDTTransferOperation := tx.Operation == core.BuiltInFunctionESDTTransfer || tx.Operation == core.BuiltInFunctionESDTNFTTransfer || tx.Operation == core.BuiltInFunctionMultiESDTNFTTransfer diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go index 7e4011e0f2c..c6abd9278d6 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go @@ -299,69 +299,6 @@ func TestComputeAndAttachGasUsedAndFeeTransactionWithMultipleScrWithRefund(t *te require.Equal(t, "319459080000000", txWithSRefundSCR.Fee) } -func TestComputeAndAttachGasUsedAndFeeRelayedV3WithRefund(t *testing.T) { - t.Parallel() - - feeComp, _ := fee.NewFeeComputer(createEconomicsData(&enableEpochsHandlerMock.EnableEpochsHandlerStub{ - IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool { - return flag == common.GasPriceModifierFlag || - flag == common.PenalizedTooMuchGasFlag || - flag == common.FixRelayedBaseCostFlag - }, - })) - computer := fee.NewTestFeeComputer(feeComp) - - gasUsedAndFeeProc := newGasUsedAndFeeProcessor( - computer, - pubKeyConverter, - &testscommon.ArgumentParserMock{}, - &testscommon.MarshallerStub{}, - enableEpochsHandlerMock.NewEnableEpochsHandlerStub(), - ) - - txWithSRefundSCR := &transaction.ApiTransactionResult{} - err := core.LoadJsonFile(txWithSRefundSCR, "testData/relayedV3WithOneRefund.json") - require.NoError(t, err) - - txWithSRefundSCR.Fee = "" - txWithSRefundSCR.GasUsed = 0 - - innerTxs := make([]*transaction.Transaction, 0, len(txWithSRefundSCR.InnerTransactions)) - for _, innerTx := range txWithSRefundSCR.InnerTransactions { - snd, _ := pubKeyConverter.Decode(innerTx.Sender) - rcv, _ := pubKeyConverter.Decode(innerTx.Receiver) - val, _ := big.NewInt(0).SetString(innerTx.Value, 10) - - innerTxs = append(innerTxs, &transaction.Transaction{ - Nonce: innerTx.Nonce, - Value: val, - RcvAddr: rcv, - SndAddr: snd, - GasPrice: innerTx.GasPrice, - GasLimit: innerTx.GasLimit, - Data: innerTx.Data, - }) - } - - snd, _ := pubKeyConverter.Decode(txWithSRefundSCR.Sender) - rcv, _ := pubKeyConverter.Decode(txWithSRefundSCR.Receiver) - val, _ := big.NewInt(0).SetString(txWithSRefundSCR.Value, 10) - txWithSRefundSCR.Tx = &transaction.Transaction{ - Nonce: txWithSRefundSCR.Nonce, - Value: val, - RcvAddr: rcv, - SndAddr: snd, - GasPrice: txWithSRefundSCR.GasPrice, - GasLimit: txWithSRefundSCR.GasLimit, - Data: txWithSRefundSCR.Data, - InnerTransactions: innerTxs, - } - - gasUsedAndFeeProc.computeAndAttachGasUsedAndFee(txWithSRefundSCR) - require.Equal(t, uint64(55149500), txWithSRefundSCR.GasUsed) - require.Equal(t, "699500000000000", txWithSRefundSCR.Fee) -} - func TestComputeAndAttachGasUsedAndFeeFailedRelayedV1(t *testing.T) { t.Parallel() @@ -405,7 +342,7 @@ func TestComputeAndAttachGasUsedAndFeeFailedRelayedV1(t *testing.T) { txWithSRefundSCR.GasUsed = 0 gasUsedAndFeeProc.computeAndAttachGasUsedAndFee(txWithSRefundSCR) - require.Equal(t, uint64(1274230), txWithSRefundSCR.GasUsed) - require.Equal(t, "1274230000000000", txWithSRefundSCR.Fee) + require.Equal(t, uint64(6148000), txWithSRefundSCR.GasUsed) + require.Equal(t, "1198000000000000", txWithSRefundSCR.Fee) require.Equal(t, "1274230000000000", txWithSRefundSCR.InitiallyPaidFee) } diff --git a/node/external/transactionAPI/testData/relayedV3WithOneRefund.json b/node/external/transactionAPI/testData/relayedV3WithOneRefund.json deleted file mode 100644 index c2b0484f877..00000000000 --- a/node/external/transactionAPI/testData/relayedV3WithOneRefund.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "type": "normal", - "processingTypeOnSource": "RelayedTxV3", - "processingTypeOnDestination": "RelayedTxV3", - "hash": "af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa", - "nonce": 0, - "value": "0", - "receiver": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", - "sender": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", - "gasPrice": 1000000000, - "gasLimit": 99000000, - "gasUsed": 998505, - "smartContractResults": [ - { - "hash": "4c58801e77c57e88294f21018145662e2fb1698fd5f1a1cf7b6f81f073f5cd6c", - "nonce": 0, - "value": 2501000000000000000000, - "receiver": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", - "sender": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg", - "data": "createNewDelegationContract@00@00", - "prevTxHash": "af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa", - "originalTxHash": "af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa", - "gasLimit": 84900500, - "gasPrice": 1000000000 - }, - { - "hash": "94e678f400192eeae3c84b3125c9d45301db619a3ecbf9e7f46266a81a85ef51", - "nonce": 1, - "value": 299005000000000, - "receiver": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", - "sender": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", - "prevTxHash": "4c58801e77c57e88294f21018145662e2fb1698fd5f1a1cf7b6f81f073f5cd6c", - "originalTxHash": "af1581562830e36b0bfb12c618a4ee92d6b7f2e0aa84935432a44c9b63cc8daa", - "gasLimit": 0, - "gasPrice": 1000000000, - "returnMessage": "gas refund for relayer", - "operation": "transfer", - "isRefund": true - } - ], - "innerTransactions": [ - { - "nonce": 0, - "value": "2501000000000000000000", - "receiver": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", - "sender": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg", - "gasPrice": 1000000000, - "gasLimit": 85000000, - "data": "Y3JlYXRlTmV3RGVsZWdhdGlvbkNvbnRyYWN0QDAwQDAw", - "signature": "610493074d4e3ce0d8dcc5434cc67032f7e4acf3fd9f97525dba4865ba42408df8315824bf7b6268e2fa0d97fc51efe1a32f7928a799064a69d54bf063a19607", - "chainID": "chain", - "version": 2, - "relayer": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze" - } - ] -} \ No newline at end of file diff --git a/node/external/transactionAPI/unmarshaller.go b/node/external/transactionAPI/unmarshaller.go index bc997cdf042..c9526217f4f 100644 --- a/node/external/transactionAPI/unmarshaller.go +++ b/node/external/transactionAPI/unmarshaller.go @@ -13,8 +13,6 @@ import ( "github.com/multiversx/mx-chain-go/sharding" ) -const operationTransfer = "transfer" - type txUnmarshaller struct { shardCoordinator sharding.Coordinator addressPubKeyConverter core.PubkeyConverter @@ -88,25 +86,8 @@ func (tu *txUnmarshaller) unmarshalTransaction(txBytes []byte, txType transactio } apiTx = tu.prepareUnsignedTx(&tx) } - - isRelayedV3 := len(apiTx.InnerTransactions) > 0 - if isRelayedV3 { - apiTx.Operation = operationTransfer - 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 - } - - apiTx.ReceiversShardIDs = append(apiTx.ReceiversShardIDs, tu.shardCoordinator.ComputeId(rcvBytes)) - } - - apiTx.IsRelayed = true - - return apiTx, nil + if err != nil { + return nil, err } res := tu.dataFieldParser.Parse(apiTx.Data, apiTx.Tx.GetSndAddr(), apiTx.Tx.GetRcvAddr(), tu.shardCoordinator.NumberOfShards()) @@ -130,22 +111,21 @@ 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), - InnerTransactions: tu.prepareInnerTxs(tx), + 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), } if len(tx.GuardianAddr) > 0 { @@ -153,72 +133,29 @@ 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 } -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(innerTx.GuardianAddr) > 0 { - frontEndTx.GuardianAddr = tu.addressPubKeyConverter.SilentEncode(innerTx.GuardianAddr, log) - frontEndTx.GuardianSignature = hex.EncodeToString(innerTx.GuardianSignature) - } - - if len(innerTx.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), - InnerTransactions: tu.prepareInnerTxs(tx), + 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), } if len(tx.GuardianAddr) > 0 { @@ -226,10 +163,6 @@ 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/node/metrics/metrics.go b/node/metrics/metrics.go index bc84198eca5..7d828d26394 100644 --- a/node/metrics/metrics.go +++ b/node/metrics/metrics.go @@ -121,7 +121,6 @@ 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.MetricFixRelayedBaseCostEnableEpoch, uint64(enableEpochs.FixRelayedBaseCostEnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricUnbondTokensV2EnableEpoch, uint64(enableEpochs.UnbondTokensV2EnableEpoch)) appStatusHandler.SetUInt64Value(common.MetricSaveJailedAlwaysEnableEpoch, uint64(enableEpochs.SaveJailedAlwaysEnableEpoch)) diff --git a/node/metrics/metrics_test.go b/node/metrics/metrics_test.go index bec9f099923..1aa3bd7be2e 100644 --- a/node/metrics/metrics_test.go +++ b/node/metrics/metrics_test.go @@ -208,10 +208,9 @@ func TestInitConfigMetrics(t *testing.T) { EGLDInMultiTransferEnableEpoch: 101, CryptoOpcodesV2EnableEpoch: 102, ScToScLogEventEnableEpoch: 103, - RelayedTransactionsV3EnableEpoch: 104, - FixRelayedBaseCostEnableEpoch: 105, - MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 106, - FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 107, + FixRelayedBaseCostEnableEpoch: 104, + MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 105, + FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 106, MaxNodesChangeEnableEpoch: []config.MaxNodesChangeConfig{ { EpochEnable: 0, @@ -330,10 +329,9 @@ 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_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_fix_relayed_base_cost_enable_epoch": uint32(104), + "erd_multi_esdt_transfer_execute_by_user_enable_epoch": uint32(105), + "erd_fix_relayed_move_balance_to_non_payable_sc_enable_epoch": uint32(106), "erd_max_nodes_change_enable_epoch": nil, "erd_total_supply": "12345", "erd_hysteresis": "0.100000", diff --git a/node/node.go b/node/node.go index 7331b9d44ca..a652e80be60 100644 --- a/node/node.go +++ b/node/node.go @@ -798,8 +798,6 @@ func (n *Node) commonTransactionValidation( enableSignWithTxHash, n.coreComponents.TxSignHasher(), n.coreComponents.TxVersionChecker(), - n.coreComponents.EnableEpochsHandler(), - n.processComponents.RelayedTxV3Processor(), ) if err != nil { return nil, nil, err @@ -893,20 +891,19 @@ 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, - InnerTransactions: txArgs.InnerTransactions, + 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, } if len(txArgs.Guardian) > 0 { @@ -916,13 +913,6 @@ func (n *Node) CreateTransaction(txArgs *external.ArgsCreateTransaction) (*trans } } - if len(txArgs.Relayer) > 0 { - tx.RelayerAddr, 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/node/node_test.go b/node/node_test.go index b584dc2370b..319890a5d0d 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -61,7 +61,6 @@ 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" @@ -1851,22 +1850,21 @@ 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: "", - InnerTransactions: 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: "", } } @@ -5297,7 +5295,6 @@ func getDefaultProcessComponents() *factoryMock.ProcessComponentsMock { TxsSenderHandlerField: &txsSenderMock.TxsSenderHandlerMock{}, ScheduledTxsExecutionHandlerInternal: &testscommon.ScheduledTxsExecutionStub{}, HistoryRepositoryInternal: &dblookupext.HistoryRepositoryStub{}, - RelayedTxV3ProcessorField: &processMocks.RelayedTxV3ProcessorMock{}, } } diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index dccf0366b23..e0d56acbde3 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -135,11 +135,6 @@ func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *trans feeInfo.SetFee(initialPaidFee) } - if len(txHandler.GetUserTransactions()) > 0 { - tep.prepareRelayedTxV3WithResults(txHashHex, txWithResult) - continue - } - totalFee, isRelayed := tep.getFeeOfRelayed(txWithResult) isRelayedAfterFix := isRelayed && isFeeFixActive if isRelayedAfterFix { @@ -155,7 +150,6 @@ func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *trans func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWithResults *transactionWithResults, isRelayedAfterFix bool) { hasRefund := false - totalRefunds := big.NewInt(0) for _, scrHandler := range txWithResults.scrs { scr, ok := scrHandler.GetTxHandler().(*smartContractResult.SmartContractResult) if !ok { @@ -163,21 +157,15 @@ func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWi } if isSCRForSenderWithRefund(scr, txHashHex, txWithResults.GetTxHandler()) || isRefundForRelayed(scr, txWithResults.GetTxHandler()) { + gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txWithResults.GetTxHandler(), scr.Value) + + txWithResults.GetFeeInfo().SetGasUsed(gasUsed) + txWithResults.GetFeeInfo().SetFee(fee) hasRefund = true - totalRefunds.Add(totalRefunds, scr.Value) + break } } - if totalRefunds.Cmp(big.NewInt(0)) > 0 { - gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txWithResults.GetTxHandler(), totalRefunds) - txWithResults.GetFeeInfo().SetGasUsed(gasUsed) - txWithResults.GetFeeInfo().SetFee(fee) - } - - if isRelayedAfterFix { - return - } - tep.prepareTxWithResultsBasedOnLogs(txHashHex, txWithResults, hasRefund) } @@ -243,31 +231,6 @@ func (tep *transactionsFeeProcessor) handleRelayedV2(args [][]byte, tx *transact return big.NewInt(0).Add(fee, innerFee), true } -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/block/preprocess/gasComputation.go b/process/block/preprocess/gasComputation.go index 9888917b7f3..628c6de455f 100644 --- a/process/block/preprocess/gasComputation.go +++ b/process/block/preprocess/gasComputation.go @@ -426,7 +426,7 @@ func (gc *gasComputation) computeGasProvidedByTxV1( } func (gc *gasComputation) isRelayedTx(txType process.TransactionType) bool { - return txType == process.RelayedTx || txType == process.RelayedTxV2 || txType == process.RelayedTxV3 + return txType == process.RelayedTx || txType == process.RelayedTxV2 } // IsInterfaceNil returns true if there is no value under the interface diff --git a/process/constants.go b/process/constants.go index 44101f50b7c..f75e7b882ee 100644 --- a/process/constants.go +++ b/process/constants.go @@ -36,8 +36,6 @@ 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 @@ -58,8 +56,6 @@ 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 d754da2c34d..32081a1ac0e 100644 --- a/process/coordinator/transactionType.go +++ b/process/coordinator/transactionType.go @@ -90,11 +90,6 @@ 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 } @@ -195,10 +190,6 @@ func (tth *txTypeHandler) isRelayedTransactionV2(functionName string) bool { return functionName == core.RelayedTransactionV2 } -func (tth *txTypeHandler) isRelayedTransactionV3(tx data.TransactionHandler) bool { - return len(tx.GetUserTransactions()) != 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 9739075d847..918b6069212 100644 --- a/process/coordinator/transactionType_test.go +++ b/process/coordinator/transactionType_test.go @@ -466,32 +466,6 @@ 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.InnerTransactions = []*transaction.Transaction{{Nonce: 1}} - - 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/disabled/failedTxLogsAccumulator.go b/process/disabled/failedTxLogsAccumulator.go deleted file mode 100644 index 3bd3f01cd69..00000000000 --- a/process/disabled/failedTxLogsAccumulator.go +++ /dev/null @@ -1,33 +0,0 @@ -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/disabled/relayedTxV3Processor.go b/process/disabled/relayedTxV3Processor.go deleted file mode 100644 index ddabd2753c8..00000000000 --- a/process/disabled/relayedTxV3Processor.go +++ /dev/null @@ -1,23 +0,0 @@ -package disabled - -import ( - "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 -} - -// 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 170377e62d3..5b7ce045237 100644 --- a/process/economics/economicsData.go +++ b/process/economics/economicsData.go @@ -13,7 +13,6 @@ 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" ) @@ -35,8 +34,6 @@ type economicsData struct { statusHandler core.AppStatusHandler enableEpochsHandler common.EnableEpochsHandler txVersionHandler process.TxVersionCheckerHandler - txTypeHandler process.TxTypeHandler - mutTxTypeHandler sync.RWMutex mut sync.RWMutex } @@ -78,7 +75,6 @@ func NewEconomicsData(args ArgsNewEconomicsData) (*economicsData, error) { statusHandler: statusHandler.NewNilStatusHandler(), enableEpochsHandler: args.EnableEpochsHandler, txVersionHandler: args.TxVersionChecker, - txTypeHandler: disabled.NewTxTypeHandler(), } ed.yearSettings = make(map[uint32]*config.YearSetting) @@ -141,19 +137,6 @@ 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() @@ -302,11 +285,6 @@ 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) @@ -330,56 +308,6 @@ 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 { - if ed.isMoveBalance(innerTx) { - innerTxFee := ed.ComputeMoveBalanceFee(innerTx) - totalFees.Add(totalFees, innerTxFee) - - continue - } - - 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 -} - -func (ed *economicsData) isMoveBalance(tx data.TransactionHandler) bool { - ed.mutTxTypeHandler.RLock() - _, dstTxType := ed.txTypeHandler.ComputeTransactionType(tx) - ed.mutTxTypeHandler.RUnlock() - - return dstTxType == process.MoveBalance -} - // SplitTxGasInCategories returns the gas split per categories func (ed *economicsData) SplitTxGasInCategories(tx data.TransactionWithFeeHandler) (gasLimitMove, gasLimitProcess uint64) { currentEpoch := ed.enableEpochsHandler.GetCurrentEpoch() @@ -590,18 +518,6 @@ func (ed *economicsData) ComputeGasUsedAndFeeBasedOnRefundValueInEpoch(tx data.T txFee := ed.ComputeTxFeeInEpoch(tx, epoch) - if len(tx.GetUserTransactions()) > 0 { - txFeeAfterRefund := txFee.Sub(txFee, refundValue) - - gasPriceForProcessing := ed.GasPriceForProcessingInEpoch(tx, epoch) - gasUnitsRefunded := refundValue.Uint64() / gasPriceForProcessing - - gasUnitsConsideredForInitialFee := ed.computeRelayedTxV3MinGasLimit(tx) - gasUnitsUsed := gasUnitsConsideredForInitialFee - gasUnitsRefunded - - return gasUnitsUsed, txFeeAfterRefund - } - isPenalizedTooMuchGasFlagEnabled := ed.enableEpochsHandler.IsFlagEnabledInEpoch(common.PenalizedTooMuchGasFlag, epoch) isGasPriceModifierFlagEnabled := ed.enableEpochsHandler.IsFlagEnabledInEpoch(common.GasPriceModifierFlag, epoch) flagCorrectTxFee := !isPenalizedTooMuchGasFlagEnabled && !isGasPriceModifierFlagEnabled @@ -689,20 +605,6 @@ func (ed *economicsData) ComputeGasLimitBasedOnBalanceInEpoch(tx data.Transactio return totalGasLimit, nil } -func (ed *economicsData) computeRelayedTxV3MinGasLimit(tx data.TransactionWithFeeHandler) uint64 { - relayedTxGasLimit := ed.ComputeGasLimit(tx) - relayedTxMinGasLimit := ed.MinGasLimit() - relayedTxGasLimitDiff := relayedTxGasLimit - relayedTxMinGasLimit // this may be positive if the relayed tx is guarded - - innerTxs := tx.GetUserTransactions() - totalGasLimit := relayedTxGasLimitDiff + relayedTxMinGasLimit*uint64(len(innerTxs)) - for _, innerTx := range innerTxs { - totalGasLimit += innerTx.GetGasLimit() - } - - return totalGasLimit -} - // IsInterfaceNil returns true if there is no value under the interface func (ed *economicsData) IsInterfaceNil() bool { return ed == nil diff --git a/process/economics/economicsData_test.go b/process/economics/economicsData_test.go index f1a66e25dcd..1f2c913a826 100644 --- a/process/economics/economicsData_test.go +++ b/process/economics/economicsData_test.go @@ -8,7 +8,6 @@ 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" @@ -1281,39 +1280,6 @@ func TestEconomicsData_ComputeGasUsedAndFeeBasedOnRefundValueSpecialBuiltInTooMu require.Equal(t, expectedFee, fee) } -func TestEconomicsData_ComputeGasUsedAndFeeBasedOnRefundValueRelayedV3(t *testing.T) { - t.Parallel() - - economicData, _ := economics.NewEconomicsData(createArgsForEconomicsDataRealFees()) - tx := &transaction.Transaction{ - GasPrice: 1000000000, - GasLimit: 99000000, - InnerTransactions: []*transaction.Transaction{ - { - GasPrice: 1000000000, - GasLimit: 85000000, - Data: []byte("createNewDelegationContract@00@00"), - }, - { - GasPrice: 1000000000, - GasLimit: 50000, - }, - { - GasPrice: 1000000000, - GasLimit: 50000, - }, - }, - } - - expectedGasUsed := uint64(55349500) - expectedFee, _ := big.NewInt(0).SetString("899500000000000", 10) - - refundValue, _ := big.NewInt(0).SetString("299005000000000", 10) - gasUsed, fee := economicData.ComputeGasUsedAndFeeBasedOnRefundValue(tx, refundValue) - require.Equal(t, expectedGasUsed, gasUsed) - require.Equal(t, expectedFee, fee) -} - func TestEconomicsData_ComputeGasLimitBasedOnBalance(t *testing.T) { t.Parallel() @@ -1655,102 +1621,3 @@ 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) - - _ = 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 - 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) - }) -} - -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) -} diff --git a/process/errors.go b/process/errors.go index a4e426691bd..83e8095dcb3 100644 --- a/process/errors.go +++ b/process/errors.go @@ -1229,48 +1229,3 @@ var ErrNilSentSignatureTracker = errors.New("nil sent signature tracker") // ErrTransferAndExecuteByUserAddressesAreNil signals that transfer and execute by user addresses are nil var ErrTransferAndExecuteByUserAddressesAreNil = errors.New("transfer and execute by user addresses are nil") - -// ErrRelayedV3GasPriceMismatch signals that relayed v3 gas price is not equal with inner tx -var ErrRelayedV3GasPriceMismatch = errors.New("relayed tx v3 gas price mismatch") - -// 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") - -// 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") - -// 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") - -// 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") - -// 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") - -// 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") - -// ErrNilFailedTxLogsAccumulator signals that a nil failed transaction logs accumulator has been provided -var ErrNilFailedTxLogsAccumulator = errors.New("nil failed transaction logs accumulator") - -// ErrEmptyInnerTransactions signals that the inner transactions slice is empty -var ErrEmptyInnerTransactions = errors.New("empty inner transactions") diff --git a/process/factory/interceptorscontainer/args.go b/process/factory/interceptorscontainer/args.go index 0d224b031ad..294e66290b3 100644 --- a/process/factory/interceptorscontainer/args.go +++ b/process/factory/interceptorscontainer/args.go @@ -43,5 +43,4 @@ 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 31a4344b771..38d3e460bce 100644 --- a/process/factory/interceptorscontainer/metaInterceptorsContainerFactory.go +++ b/process/factory/interceptorscontainer/metaInterceptorsContainerFactory.go @@ -99,7 +99,6 @@ 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 b9124001264..fe853c32662 100644 --- a/process/factory/interceptorscontainer/metaInterceptorsContainerFactory_test.go +++ b/process/factory/interceptorscontainer/metaInterceptorsContainerFactory_test.go @@ -18,7 +18,6 @@ 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" @@ -708,6 +707,5 @@ 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 26224fbc152..beef288c54c 100644 --- a/process/factory/interceptorscontainer/shardInterceptorsContainerFactory.go +++ b/process/factory/interceptorscontainer/shardInterceptorsContainerFactory.go @@ -98,7 +98,6 @@ 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 f802562ae35..677876311e9 100644 --- a/process/factory/interceptorscontainer/shardInterceptorsContainerFactory_test.go +++ b/process/factory/interceptorscontainer/shardInterceptorsContainerFactory_test.go @@ -22,7 +22,6 @@ 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" @@ -733,6 +732,5 @@ 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 36ab4968375..37701a92f7a 100644 --- a/process/interceptors/factory/argInterceptedDataFactory.go +++ b/process/interceptors/factory/argInterceptedDataFactory.go @@ -57,5 +57,4 @@ 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 d2ecc63e59d..e46692e6614 100644 --- a/process/interceptors/factory/interceptedMetaHeaderDataFactory_test.go +++ b/process/interceptors/factory/interceptedMetaHeaderDataFactory_test.go @@ -20,7 +20,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/hashingMocks" - testProcessMocks "github.com/multiversx/mx-chain-go/testscommon/processMocks" "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" "github.com/stretchr/testify/assert" ) @@ -107,7 +106,6 @@ 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 e2dc86e599c..563997c5066 100644 --- a/process/interceptors/factory/interceptedTxDataFactory.go +++ b/process/interceptors/factory/interceptedTxDataFactory.go @@ -31,7 +31,6 @@ type interceptedTxDataFactory struct { txSignHasher hashing.Hasher txVersionChecker process.TxVersionCheckerHandler enableEpochsHandler common.EnableEpochsHandler - relayedTxV3Processor process.RelayedTxV3Processor } // NewInterceptedTxDataFactory creates an instance of interceptedTxDataFactory @@ -108,7 +107,6 @@ func NewInterceptedTxDataFactory(argument *ArgInterceptedDataFactory) (*intercep txSignHasher: argument.CoreComponents.TxSignHasher(), txVersionChecker: argument.CoreComponents.TxVersionChecker(), enableEpochsHandler: argument.CoreComponents.EnableEpochsHandler(), - relayedTxV3Processor: argument.RelayedTxV3Processor, } return itdf, nil @@ -132,8 +130,6 @@ func (itdf *interceptedTxDataFactory) Create(buff []byte) (process.InterceptedDa itdf.enableEpochsHandler.IsFlagEnabled(common.TransactionSignedWithTxHashFlag), itdf.txSignHasher, itdf.txVersionChecker, - itdf.enableEpochsHandler, - itdf.relayedTxV3Processor, ) } diff --git a/process/interface.go b/process/interface.go index 8e943d0a44e..747103f26ca 100644 --- a/process/interface.go +++ b/process/interface.go @@ -699,7 +699,6 @@ 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 @@ -726,7 +725,6 @@ type EconomicsDataHandler interface { rewardsHandler feeHandler SetStatusHandler(statusHandler core.AppStatusHandler) error - SetTxTypeHandler(txTypeHandler TxTypeHandler) error IsInterfaceNil() bool } @@ -1361,17 +1359,3 @@ 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 - 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/smartContract/processProxy/processProxy.go b/process/smartContract/processProxy/processProxy.go index a36a5fbd4f4..c64db4791a4 100644 --- a/process/smartContract/processProxy/processProxy.go +++ b/process/smartContract/processProxy/processProxy.go @@ -50,30 +50,29 @@ 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, - FailedTxLogsAccumulator: args.FailedTxLogsAccumulator, + 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, }, } if check.IfNil(epochNotifier) { diff --git a/process/smartContract/processProxy/processProxy_test.go b/process/smartContract/processProxy/processProxy_test.go index 98a56fd0f30..d153615600f 100644 --- a/process/smartContract/processProxy/processProxy_test.go +++ b/process/smartContract/processProxy/processProxy_test.go @@ -23,7 +23,6 @@ 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" @@ -77,10 +76,9 @@ func createMockSmartContractProcessorArguments() scrCommon.ArgsNewSmartContractP return flag == common.SCDeployFlag }, }, - EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, - WasmVMChangeLocker: &sync.RWMutex{}, - VMOutputCacher: txcache.NewDisabledCache(), - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, + WasmVMChangeLocker: &sync.RWMutex{}, + VMOutputCacher: txcache.NewDisabledCache(), } } diff --git a/process/smartContract/processProxy/testProcessProxy.go b/process/smartContract/processProxy/testProcessProxy.go index 65e5d525565..5d5d96ee0d2 100644 --- a/process/smartContract/processProxy/testProcessProxy.go +++ b/process/smartContract/processProxy/testProcessProxy.go @@ -28,30 +28,29 @@ 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, - FailedTxLogsAccumulator: args.FailedTxLogsAccumulator, + 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, }, } diff --git a/process/smartContract/process_test.go b/process/smartContract/process_test.go index 29c1e082be3..bc8caf169f3 100644 --- a/process/smartContract/process_test.go +++ b/process/smartContract/process_test.go @@ -39,7 +39,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/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" @@ -116,12 +115,11 @@ 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(), - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + GasSchedule: testscommon.NewGasScheduleNotifierMock(gasSchedule), + EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.SCDeployFlag), + WasmVMChangeLocker: &sync.RWMutex{}, + VMOutputCacher: txcache.NewDisabledCache(), } } diff --git a/process/smartContract/processorV2/processV2.go b/process/smartContract/processorV2/processV2.go index dafa4f9712f..5f6c02b7d09 100644 --- a/process/smartContract/processorV2/processV2.go +++ b/process/smartContract/processorV2/processV2.go @@ -81,14 +81,13 @@ type scProcessor struct { txTypeHandler process.TxTypeHandler gasHandler process.GasHandler - builtInGasCosts map[string]uint64 - persistPerByte uint64 - storePerByte uint64 - mutGasLock sync.RWMutex - txLogsProcessor process.TransactionLogProcessor - failedTxLogsAccumulator process.FailedTxLogsAccumulator - vmOutputCacher storage.Cacher - isGenesisProcessing bool + builtInGasCosts map[string]uint64 + persistPerByte uint64 + storePerByte uint64 + mutGasLock sync.RWMutex + txLogsProcessor process.TransactionLogProcessor + vmOutputCacher storage.Cacher + isGenesisProcessing bool executableCheckers map[string]scrCommon.ExecutableChecker mutExecutableCheckers sync.RWMutex @@ -162,9 +161,6 @@ 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 } @@ -188,31 +184,30 @@ 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, - 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), + 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), } sc.esdtTransferParser, err = parsers.NewESDTTransferParser(args.Marshalizer) @@ -1412,19 +1407,19 @@ func (sc *scProcessor) isCrossShardESDTTransfer(sender []byte, receiver []byte, func (sc *scProcessor) getOriginalTxHashIfIntraShardRelayedSCR( tx data.TransactionHandler, txHash []byte, -) ([]byte, bool) { +) []byte { relayedSCR, isRelayed := isRelayedTx(tx) if !isRelayed { - return txHash, isRelayed + return txHash } sndShardID := sc.shardCoordinator.ComputeId(relayedSCR.SndAddr) rcvShardID := sc.shardCoordinator.ComputeId(relayedSCR.RcvAddr) if sndShardID != rcvShardID { - return txHash, isRelayed + return txHash } - return relayedSCR.OriginalTxHash, isRelayed + return relayedSCR.OriginalTxHash } // ProcessIfError creates a smart contract result, consumes the gas and returns the value to the user @@ -1514,15 +1509,10 @@ func (sc *scProcessor) processIfErrorWithAddedLogs(acntSnd state.UserAccountHand processIfErrorLogs = append(processIfErrorLogs, failureContext.logs...) } - 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) - } + logsTxHash := sc.getOriginalTxHashIfIntraShardRelayedSCR(tx, failureContext.txHash) + ignorableError := sc.txLogsProcessor.SaveLog(logsTxHash, tx, processIfErrorLogs) if ignorableError != nil { - log.Debug("scProcessor.ProcessIfError() save log", "error", ignorableError.Error(), "isRelayed", isRelayed) + log.Debug("scProcessor.ProcessIfError() save log", "error", ignorableError.Error()) } txType, _ := sc.txTypeHandler.ComputeTransactionType(tx) diff --git a/process/smartContract/processorV2/process_test.go b/process/smartContract/processorV2/process_test.go index 8722991d0a7..905c18a033d 100644 --- a/process/smartContract/processorV2/process_test.go +++ b/process/smartContract/processorV2/process_test.go @@ -43,7 +43,6 @@ 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" @@ -131,10 +130,9 @@ func createMockSmartContractProcessorArguments() scrCommon.ArgsNewSmartContractP return flag == common.SCDeployFlag }, }, - GasSchedule: testscommon.NewGasScheduleNotifierMock(gasSchedule), - WasmVMChangeLocker: &sync.RWMutex{}, - VMOutputCacher: txcache.NewDisabledCache(), - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + GasSchedule: testscommon.NewGasScheduleNotifierMock(gasSchedule), + WasmVMChangeLocker: &sync.RWMutex{}, + VMOutputCacher: txcache.NewDisabledCache(), } } @@ -337,17 +335,6 @@ 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() @@ -3345,8 +3332,8 @@ func TestScProcessor_ProcessRelayedSCRValueBackToRelayer(t *testing.T) { }, } wasSaveLogsCalled := false - arguments.FailedTxLogsAccumulator = &processMocks.FailedTxLogsAccumulatorMock{ - SaveLogsCalled: func(txHash []byte, tx data.TransactionHandler, logs []*vmcommon.LogEntry) error { + arguments.TxLogsProcessor = &mock.TxLogsProcessorStub{ + SaveLogCalled: func(txHash []byte, tx data.TransactionHandler, logs []*vmcommon.LogEntry) error { wasSaveLogsCalled = true return nil }, @@ -4083,20 +4070,18 @@ func TestProcessGetOriginalTxHashForRelayedIntraShard(t *testing.T) { scr := &smartContractResult.SmartContractResult{Value: big.NewInt(1), SndAddr: bytes.Repeat([]byte{1}, 32)} scrHash := []byte("hash") - logHash, isRelayed := sc.getOriginalTxHashIfIntraShardRelayedSCR(scr, scrHash) + logHash := 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, isRelayed = sc.getOriginalTxHashIfIntraShardRelayedSCR(scr, scrHash) + logHash = 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 07efc6cfd59..8cd8efd6484 100644 --- a/process/smartContract/scrCommon/common.go +++ b/process/smartContract/scrCommon/common.go @@ -32,30 +32,29 @@ 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 - FailedTxLogsAccumulator process.FailedTxLogsAccumulator - 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 + 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/export_test.go b/process/transaction/export_test.go index ef23d5c114f..cd657c3991d 100644 --- a/process/transaction/export_test.go +++ b/process/transaction/export_test.go @@ -62,8 +62,7 @@ func (txProc *txProcessor) ProcessUserTx( userTx, relayedTxValue, relayedNonce, - originalTxHash, - nonRelayedV3UserTxIdx) + originalTxHash) } // ProcessMoveBalanceCostRelayedUserTx calls the un-exported method processMoveBalanceCostRelayedUserTx @@ -93,8 +92,7 @@ func (txProc *txProcessor) ExecuteFailedRelayedTransaction( relayedNonce, originalTx, originalTxHash, - errorMsg, - nonRelayedV3UserTxIdx) + errorMsg) } // CheckMaxGasPrice calls the un-exported method checkMaxGasPrice diff --git a/process/transaction/interceptedTransaction.go b/process/transaction/interceptedTransaction.go index 831afdcbcbc..75b9a65ae7c 100644 --- a/process/transaction/interceptedTransaction.go +++ b/process/transaction/interceptedTransaction.go @@ -13,7 +13,6 @@ 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" @@ -43,8 +42,6 @@ type InterceptedTransaction struct { sndShard uint32 isForCurrentShard bool enableSignedTxWithHash bool - enableEpochsHandler common.EnableEpochsHandler - relayedTxV3Processor process.RelayedTxV3Processor } // NewInterceptedTransaction returns a new instance of InterceptedTransaction @@ -64,8 +61,6 @@ func NewInterceptedTransaction( enableSignedTxWithHash bool, txSignHasher hashing.Hasher, txVersionChecker process.TxVersionCheckerHandler, - enableEpochsHandler common.EnableEpochsHandler, - relayedTxV3Processor process.RelayedTxV3Processor, ) (*InterceptedTransaction, error) { if txBuff == nil { @@ -110,12 +105,6 @@ func NewInterceptedTransaction( if check.IfNil(txVersionChecker) { return nil, process.ErrNilTransactionVersionChecker } - if check.IfNil(enableEpochsHandler) { - return nil, process.ErrNilEnableEpochsHandler - } - if check.IfNil(relayedTxV3Processor) { - return nil, process.ErrNilRelayedTxV3Processor - } tx, err := createTx(protoMarshalizer, txBuff) if err != nil { @@ -138,8 +127,6 @@ func NewInterceptedTransaction( enableSignedTxWithHash: enableSignedTxWithHash, txVersionChecker: txVersionChecker, txSignHasher: txSignHasher, - enableEpochsHandler: enableEpochsHandler, - relayedTxV3Processor: relayedTxV3Processor, } err = inTx.processFields(txBuff) @@ -212,26 +199,13 @@ func (inTx *InterceptedTransaction) CheckValidity() error { return err } - err = inTx.verifyIfRelayedTxV3(inTx.tx) - if err != nil { - 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()}) } return nil } -func (inTx *InterceptedTransaction) checkRecursiveRelayed(userTxData []byte, innerTxs []*transaction.Transaction) error { - if isRelayedV3(innerTxs) { - return process.ErrRecursiveRelayedTxIsNotAllowed - } - +func (inTx *InterceptedTransaction) checkRecursiveRelayed(userTxData []byte) error { funcName, _, err := inTx.argsParser.ParseCallData(string(userTxData)) if err != nil { return nil @@ -249,46 +223,6 @@ func isRelayedTx(funcName string) bool { core.RelayedTransactionV2 == funcName } -func isRelayedV3(innerTxs []*transaction.Transaction) bool { - return len(innerTxs) > 0 -} - -func (inTx *InterceptedTransaction) verifyIfRelayedTxV3(tx *transaction.Transaction) error { - if len(tx.InnerTransactions) == 0 { - return nil - } - if !inTx.enableEpochsHandler.IsFlagEnabled(common.RelayedTransactionsV3Flag) { - return process.ErrRelayedTxV3Disabled - } - err := inTx.relayedTxV3Processor.CheckRelayedTx(tx) - if err != nil { - return err - } - - funcName, _, err := inTx.argsParser.ParseCallData(string(tx.Data)) - if err == nil && isRelayedTx(funcName) { - return process.ErrMultipleRelayedTxTypesIsNotAllowed - } - - 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 -} - func (inTx *InterceptedTransaction) verifyIfRelayedTxV2(tx *transaction.Transaction) error { funcName, userTxArgs, err := inTx.argsParser.ParseCallData(string(tx.Data)) if err != nil { @@ -298,10 +232,6 @@ 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 @@ -323,10 +253,6 @@ 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) @@ -346,7 +272,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.InnerTransactions) + err := inTx.checkRecursiveRelayed(userTx.Data) if err != nil { return fmt.Errorf("inner transaction: %w", err) } @@ -537,11 +463,6 @@ 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 44d416194ab..f35ce467d13 100644 --- a/process/transaction/interceptedTransaction_test.go +++ b/process/transaction/interceptedTransaction_test.go @@ -15,7 +15,6 @@ 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" @@ -23,10 +22,8 @@ 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" - "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" @@ -37,10 +34,8 @@ 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") @@ -95,9 +90,6 @@ func createInterceptedTxWithTxFeeHandlerAndVersionChecker(tx *dataTransaction.Tr if bytes.Equal(address, recvAddress) { return recvShard } - if bytes.Equal(address, relayerAddress) { - return relayerShard - } return shardCoordinator.CurrentShard } @@ -122,8 +114,6 @@ func createInterceptedTxWithTxFeeHandlerAndVersionChecker(tx *dataTransaction.Tr false, &hashingMocks.HasherMock{}, txVerChecker, - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) } @@ -143,9 +133,6 @@ func createInterceptedTxFromPlainTx(tx *dataTransaction.Transaction, txFeeHandle if bytes.Equal(address, recvAddress) { return recvShard } - if bytes.Equal(address, relayerAddress) { - return relayerShard - } return shardCoordinator.CurrentShard } @@ -170,8 +157,6 @@ func createInterceptedTxFromPlainTx(tx *dataTransaction.Transaction, txFeeHandle false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(minTxVersion), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) } @@ -191,23 +176,10 @@ 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(transaction.ArgRelayedTxV3Processor{ - EconomicsFee: txFeeHandler, - ShardCoordinator: shardCoordinator, - MaxTransactionsAllowed: 10, - }) - if err != nil { - return nil, err - } - return transaction.NewInterceptedTransaction( txBuff, marshalizer, @@ -221,15 +193,13 @@ func createInterceptedTxFromPlainTxWithArgParser(tx *dataTransaction.Transaction }, }, shardCoordinator, - txFeeHandler, + createFreeTxFeeHandler(), &testscommon.WhiteListHandlerStub{}, smartContract.NewArgumentParser(), tx.ChainID, false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(tx.Version), - enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.RelayedTransactionsV3Flag), - relayedTxV3Processor, ) } @@ -254,8 +224,6 @@ func TestNewInterceptedTransaction_NilBufferShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -281,8 +249,6 @@ func TestNewInterceptedTransaction_NilArgsParser(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -308,8 +274,6 @@ func TestNewInterceptedTransaction_NilVersionChecker(t *testing.T) { false, &hashingMocks.HasherMock{}, nil, - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -335,8 +299,6 @@ func TestNewInterceptedTransaction_NilMarshalizerShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -362,8 +324,6 @@ func TestNewInterceptedTransaction_NilSignMarshalizerShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -389,8 +349,6 @@ func TestNewInterceptedTransaction_NilHasherShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -416,8 +374,6 @@ func TestNewInterceptedTransaction_NilKeyGenShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -443,8 +399,6 @@ func TestNewInterceptedTransaction_NilSignerShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -470,8 +424,6 @@ func TestNewInterceptedTransaction_NilPubkeyConverterShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -497,8 +449,6 @@ func TestNewInterceptedTransaction_NilCoordinatorShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -524,8 +474,6 @@ func TestNewInterceptedTransaction_NilFeeHandlerShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -551,8 +499,6 @@ func TestNewInterceptedTransaction_NilWhiteListerVerifiedTxsShouldErr(t *testing false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -578,8 +524,6 @@ func TestNewInterceptedTransaction_InvalidChainIDShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -605,68 +549,12 @@ func TestNewInterceptedTransaction_NilTxSignHasherShouldErr(t *testing.T) { false, nil, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) 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{}, - &testscommon.ArgumentParserMock{}, - []byte("chainID"), - false, - &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{}, - &testscommon.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() @@ -692,8 +580,6 @@ func TestNewInterceptedTransaction_UnmarshalingTxFailsShouldErr(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(1), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, txi) @@ -1110,32 +996,6 @@ 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() @@ -1190,8 +1050,6 @@ func TestInterceptedTransaction_CheckValiditySignedWithHashButNotEnabled(t *test false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(minTxVersion), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) err := txi.CheckValidity() @@ -1252,8 +1110,6 @@ func TestInterceptedTransaction_CheckValiditySignedWithHashShouldWork(t *testing true, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(minTxVersion), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) err := txi.CheckValidity() @@ -1339,8 +1195,6 @@ func TestInterceptedTransaction_ScTxDeployRecvShardIdShouldBeSendersShardId(t *t false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(minTxVersion), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Nil(t, err) @@ -1421,31 +1275,6 @@ 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() @@ -1505,8 +1334,6 @@ func TestInterceptedTransaction_CheckValiditySecondTimeDoesNotVerifySig(t *testi false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(minTxVersion), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) require.Nil(t, err) @@ -1602,14 +1429,6 @@ 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) { @@ -1673,16 +1492,6 @@ 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)) @@ -1691,177 +1500,6 @@ 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, - RelayerAddr: relayerAddress, - } - - tx := &dataTransaction.Transaction{ - Nonce: 1, - Value: big.NewInt(0), - GasLimit: 10, - GasPrice: 4, - RcvAddr: relayerAddress, - SndAddr: relayerAddress, - Signature: sigOk, - ChainID: chainID, - Version: minTxVersion, - InnerTransactions: []*dataTransaction.Transaction{innerTx}, - } - - t.Run("should work", func(t *testing.T) { - t.Parallel() - - txCopy := *tx - txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) - err := txi.CheckValidity() - assert.Nil(t, err) - }) - t.Run("inner txs on inner tx should error", func(t *testing.T) { - t.Parallel() - - txCopy := *tx - innerTxCopy := *innerTx - innerTxCopy.InnerTransactions = []*dataTransaction.Transaction{{}} - txCopy.InnerTransactions = []*dataTransaction.Transaction{&innerTxCopy} - - txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) - err := txi.CheckValidity() - assert.Equal(t, process.ErrRecursiveRelayedTxIsNotAllowed, err) - }) - t.Run("different relayer on inner tx should error", func(t *testing.T) { - t.Parallel() - - txCopy := *tx - innerTxCopy := *innerTx - innerTxCopy.RelayerAddr = recvAddress - txCopy.InnerTransactions = []*dataTransaction.Transaction{&innerTxCopy} - - txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) - err := txi.CheckValidity() - assert.Equal(t, process.ErrRelayedTxV3RelayerMismatch, err) - }) - t.Run("different sender than receiver should error", func(t *testing.T) { - t.Parallel() - - txCopy := *tx - innerTxCopy := *innerTx - txCopy.RcvAddr = recvAddress - txCopy.InnerTransactions = []*dataTransaction.Transaction{&innerTxCopy} - txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) - err := txi.CheckValidity() - assert.Equal(t, process.ErrRelayedTxV3SenderDoesNotMatchReceiver, err) - }) - t.Run("empty signature on inner tx should error", func(t *testing.T) { - t.Parallel() - - txCopy := *tx - innerTxCopy := *innerTx - innerTxCopy.Signature = nil - txCopy.InnerTransactions = []*dataTransaction.Transaction{&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.InnerTransactions = []*dataTransaction.Transaction{&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.InnerTransactions = []*dataTransaction.Transaction{&innerTxCopy} - innerTx2 := &dataTransaction.Transaction{ - Nonce: 2, - Value: big.NewInt(3), - Data: []byte(""), - GasLimit: 3, - GasPrice: 4, - RcvAddr: recvAddress, - SndAddr: senderAddress, - Signature: sigOk, - ChainID: chainID, - Version: minTxVersion, - } - innerTxCopy.InnerTransactions = []*dataTransaction.Transaction{innerTx2} - txi, _ := createInterceptedTxFromPlainTxWithArgParser(&txCopy) - err := txi.CheckValidity() - assert.NotNil(t, err) - }) - t.Run("relayed v3 not enabled yet should error", func(t *testing.T) { - t.Parallel() - - txCopy := *tx - innerTxCopy := *innerTx - txCopy.InnerTransactions = []*dataTransaction.Transaction{&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{}, - &testscommon.ArgumentParserMock{}, - txCopy.ChainID, - false, - &hashingMocks.HasherMock{}, - versioning.NewTxVersionChecker(0), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, - ) - - assert.NotNil(t, txi) - 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 func TestInterceptedTransaction_IsInterfaceNil(t *testing.T) { t.Parallel() @@ -1991,8 +1629,6 @@ func TestInterceptedTransaction_Fee(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(0), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) assert.Equal(t, big.NewInt(0), txin.Fee()) @@ -2036,8 +1672,6 @@ func TestInterceptedTransaction_String(t *testing.T) { false, &hashingMocks.HasherMock{}, versioning.NewTxVersionChecker(0), - &enableEpochsHandlerMock.EnableEpochsHandlerStub{}, - &processMocks.RelayedTxV3ProcessorMock{}, ) expectedFormat := fmt.Sprintf( diff --git a/process/transaction/relayedTxV3Processor.go b/process/transaction/relayedTxV3Processor.go deleted file mode 100644 index 1c25ad46214..00000000000 --- a/process/transaction/relayedTxV3Processor.go +++ /dev/null @@ -1,112 +0,0 @@ -package transaction - -import ( - "bytes" - "fmt" - "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" -) - -const minTransactionsAllowed = 1 - -// ArgRelayedTxV3Processor is the DTO used to create a new instance of relayedTxV3Processor -type ArgRelayedTxV3Processor struct { - EconomicsFee process.FeeHandler - ShardCoordinator sharding.Coordinator - MaxTransactionsAllowed int -} - -type relayedTxV3Processor struct { - economicsFee process.FeeHandler - shardCoordinator sharding.Coordinator - maxTransactionsAllowed int -} - -// NewRelayedTxV3Processor returns a new instance of relayedTxV3Processor -func NewRelayedTxV3Processor(args ArgRelayedTxV3Processor) (*relayedTxV3Processor, error) { - err := checkArgs(args) - if err != nil { - return nil, err - } - return &relayedTxV3Processor{ - 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 - } - if !bytes.Equal(tx.RcvAddr, tx.SndAddr) { - return process.ErrRelayedTxV3SenderDoesNotMatchReceiver - } - 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 !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) - if senderShard != relayerShard { - return process.ErrRelayedTxV3SenderShardMismatch - } - } - - return nil -} - -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 := relayedTxGasLimitDiff + relayedTxMinGasLimit*uint64(len(tx.InnerTransactions)) - for _, innerTx := range tx.InnerTransactions { - totalGasLimit += innerTx.GasLimit - } - - return totalGasLimit -} - -// IsInterfaceNil returns true if there is no value under the interface -func (proc *relayedTxV3Processor) IsInterfaceNil() bool { - return proc == nil -} diff --git a/process/transaction/relayedTxV3Processor_test.go b/process/transaction/relayedTxV3Processor_test.go deleted file mode 100644 index 7f6495ebd92..00000000000 --- a/process/transaction/relayedTxV3Processor_test.go +++ /dev/null @@ -1,249 +0,0 @@ -package transaction_test - -import ( - "bytes" - "errors" - "math/big" - "strings" - "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 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() - - 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() - - 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(createMockArgRelayedTxV3Processor()) - require.NoError(t, err) - require.NotNil(t, proc) - }) -} - -func TestRelayedTxV3Processor_IsInterfaceNil(t *testing.T) { - t.Parallel() - - args := createMockArgRelayedTxV3Processor() - args.EconomicsFee = nil - proc, _ := transaction.NewRelayedTxV3Processor(args) - require.True(t, proc.IsInterfaceNil()) - - 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(createMockArgRelayedTxV3Processor()) - 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(createMockArgRelayedTxV3Processor()) - 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() - - args := createMockArgRelayedTxV3Processor() - args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ - ComputeGasLimitCalled: func(tx data.TransactionWithFeeHandler) uint64 { - return minGasLimit - }, - } - proc, err := transaction.NewRelayedTxV3Processor(args) - require.NoError(t, err) - - tx := getDefaultTx() - tx.GasLimit = minGasLimit - - err = proc.CheckRelayedTx(tx) - require.Equal(t, process.ErrRelayedTxV3GasLimitMismatch, err) - }) - 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.Data = []byte("dummy") - - err = proc.CheckRelayedTx(tx) - 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() - - proc, err := transaction.NewRelayedTxV3Processor(createMockArgRelayedTxV3Processor()) - 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(createMockArgRelayedTxV3Processor()) - 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() - args := createMockArgRelayedTxV3Processor() - args.ShardCoordinator = &testscommon.ShardsCoordinatorMock{ - ComputeIdCalled: func(address []byte) uint32 { - if bytes.Equal(address, tx.SndAddr) { - return 0 - } - - return 1 - }, - } - proc, err := transaction.NewRelayedTxV3Processor(args) - 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(createMockArgRelayedTxV3Processor()) - require.NoError(t, err) - - tx := getDefaultTx() - err = proc.CheckRelayedTx(tx) - require.NoError(t, err) - }) -} diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 6d2fbeb80f3..51910b537e2 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -31,8 +31,6 @@ var _ process.TransactionProcessor = (*txProcessor)(nil) // for move balance transactions that provide more gas than needed const RefundGasMessage = "refundedGas" -const nonRelayedV3UserTxIdx = -1 - type relayedFees struct { totalFee, remainingFee, relayerFee *big.Int } @@ -40,41 +38,37 @@ type relayedFees struct { // txProcessor implements TransactionProcessor interface and can modify account states according to a transaction type txProcessor struct { *baseTxProcessor - txFeeHandler process.TransactionFeeHandler - 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 + txFeeHandler process.TransactionFeeHandler + receiptForwarder process.IntermediateTransactionHandler + badTxForwarder process.IntermediateTransactionHandler + argsParser process.ArgumentsParser + scrForwarder process.IntermediateTransactionHandler + signMarshalizer marshal.Marshalizer + enableEpochsHandler common.EnableEpochsHandler + txLogsProcessor process.TransactionLogProcessor } // 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 - FailedTxLogsAccumulator process.FailedTxLogsAccumulator + 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 } // NewTxProcessor creates a new txProcessor engine @@ -134,7 +128,6 @@ func NewTxProcessor(args ArgsNewTxProcessor) (*txProcessor, error) { common.RelayedTransactionsFlag, common.RelayedTransactionsV2Flag, common.RelayedNonceFixFlag, - common.RelayedTransactionsV3Flag, common.FixRelayedBaseCostFlag, }) if err != nil { @@ -149,12 +142,6 @@ func NewTxProcessor(args ArgsNewTxProcessor) (*txProcessor, error) { if check.IfNil(args.TxLogsProcessor) { return nil, process.ErrNilTxLogsProcessor } - if check.IfNil(args.RelayedTxV3Processor) { - return nil, process.ErrNilRelayedTxV3Processor - } - if check.IfNil(args.FailedTxLogsAccumulator) { - return nil, process.ErrNilFailedTxLogsAccumulator - } baseTxProcess := &baseTxProcessor{ accounts: args.Accounts, @@ -171,17 +158,15 @@ func NewTxProcessor(args ArgsNewTxProcessor) (*txProcessor, error) { } txProc := &txProcessor{ - baseTxProcessor: baseTxProcess, - txFeeHandler: args.TxFeeHandler, - 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, + baseTxProcessor: baseTxProcess, + txFeeHandler: args.TxFeeHandler, + receiptForwarder: args.ReceiptForwarder, + badTxForwarder: args.BadTxForwarder, + argsParser: args.ArgsParser, + scrForwarder: args.ScrForwarder, + signMarshalizer: args.SignMarshalizer, + enableEpochsHandler: args.EnableEpochsHandler, + txLogsProcessor: args.TxLogsProcessor, } return txProc, nil @@ -255,8 +240,6 @@ 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) } return vmcommon.UserError, txProc.executingFailedTransaction(tx, acntSnd, process.ErrWrongTransaction) @@ -621,7 +604,7 @@ func (txProc *txProcessor) finishExecutionOfRelayedTx( userTx *transaction.Transaction, ) (vmcommon.ReturnCode, error) { computedFees := txProc.computeRelayedTxFees(tx, userTx) - err := txProc.processTxAtRelayer(relayerAcnt, computedFees.totalFee, computedFees.relayerFee, tx) + txHash, err := txProc.processTxAtRelayer(relayerAcnt, computedFees.totalFee, computedFees.relayerFee, tx) if err != nil { return 0, err } @@ -635,27 +618,7 @@ func (txProc *txProcessor) finishExecutionOfRelayedTx( return 0, err } - 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(), - nonRelayedV3UserTxIdx) - } - - defer txProc.saveFailedLogsIfNeeded(originalTxHash) - - return txProc.processUserTx(tx, userTx, tx.Value, tx.Nonce, originalTxHash, nonRelayedV3UserTxIdx) + return txProc.processUserTx(tx, userTx, tx.Value, tx.Nonce, txHash) } func (txProc *txProcessor) processTxAtRelayer( @@ -663,33 +626,33 @@ func (txProc *txProcessor) processTxAtRelayer( totalFee *big.Int, relayerFee *big.Int, tx *transaction.Transaction, -) error { +) ([]byte, error) { + txHash, err := core.CalculateHash(txProc.marshalizer, txProc.hasher, tx) + if err != nil { + return nil, err + } + if !check.IfNil(relayerAcnt) { - err := relayerAcnt.SubFromBalance(tx.GetValue()) + err = relayerAcnt.SubFromBalance(tx.GetValue()) if err != nil { - return err + return nil, err } err = relayerAcnt.SubFromBalance(totalFee) if err != nil { - return err + return nil, err } relayerAcnt.IncreaseNonce(1) err = txProc.accounts.SaveAccount(relayerAcnt) if err != nil { - return err - } - - txHash, err := core.CalculateHash(txProc.marshalizer, txProc.hasher, tx) - if err != nil { - return err + return nil, err } txProc.txFeeHandler.ProcessTransactionFee(relayerFee, big.NewInt(0), txHash) } - return nil + return txHash, nil } func (txProc *txProcessor) addFeeAndValueToDest(acntDst state.UserAccountHandler, txValue *big.Int, remainingFee *big.Int) error { @@ -706,132 +669,6 @@ func (txProc *txProcessor) addFeeAndValueToDest(acntDst state.UserAccountHandler return txProc.accounts.SaveAccount(acntDst) } -func (txProc *txProcessor) processRelayedTxV3( - tx *transaction.Transaction, - relayerAcnt state.UserAccountHandler, -) (vmcommon.ReturnCode, error) { - if !txProc.enableEpochsHandler.IsFlagEnabled(common.RelayedTransactionsV3Flag) { - return vmcommon.UserError, txProc.executingFailedTransaction(tx, relayerAcnt, process.ErrRelayedTxV3Disabled) - } - 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) - } - - snapshot := txProc.accounts.JournalLen() - - // process fees on both relayer and sender - 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 - } - - 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 - var innerTxFee *big.Int - innerTxsTotalFees := big.NewInt(0) - executedUserTxs := make([]*transaction.Transaction, 0) - for innerTxIdx, innerTx := range innerTxs { - innerTxFee, innerTxRetCode, innerTxErr = txProc.processInnerTx(tx, innerTx, originalTxHash, innerTxIdx) - innerTxsTotalFees.Add(innerTxsTotalFees, innerTxFee) - if innerTxErr != nil || innerTxRetCode != vmcommon.Ok { - continue - } - - executedUserTxs = append(executedUserTxs, innerTx) - } - - 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) - } - - expectedMaxInnerTxsTotalFees := big.NewInt(0).Sub(totalFee, relayerFee) - if innerTxsTotalFees.Cmp(expectedMaxInnerTxsTotalFees) > 0 { - log.Debug("reverting relayed transaction, total inner transactions fees mismatch", - "computed max fees at relayer", expectedMaxInnerTxsTotalFees.Uint64(), - "total inner fees consumed", 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) processInnerTx( - tx *transaction.Transaction, - innerTx *transaction.Transaction, - originalTxHash []byte, - innerTxIdx int, -) (*big.Int, vmcommon.ReturnCode, error) { - - txFee := txProc.computeInnerTxFee(innerTx) - - acntSnd, err := txProc.getAccountFromAddress(innerTx.SndAddr) - if err != nil { - return txFee, vmcommon.UserError, txProc.executeFailedRelayedUserTx( - innerTx, - innerTx.RelayerAddr, - big.NewInt(0), - tx.Nonce, - tx, - originalTxHash, - err.Error(), - innerTxIdx) - } - - if check.IfNil(acntSnd) { - return txFee, vmcommon.UserError, txProc.executeFailedRelayedUserTx( - innerTx, - innerTx.RelayerAddr, - big.NewInt(0), - tx.Nonce, - tx, - originalTxHash, - process.ErrRelayedTxV3SenderShardMismatch.Error(), - innerTxIdx) - } - - // 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( - innerTx, - innerTx.RelayerAddr, - big.NewInt(0), - tx.Nonce, - tx, - originalTxHash, - err.Error(), - innerTxIdx) - } - - result, err := txProc.processUserTx(tx, innerTx, tx.Value, tx.Nonce, originalTxHash, innerTxIdx) - return txFee, result, err -} - func (txProc *txProcessor) processRelayedTxV2( tx *transaction.Transaction, relayerAcnt, acntDst state.UserAccountHandler, @@ -851,10 +688,6 @@ 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) @@ -878,9 +711,6 @@ 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]) @@ -978,7 +808,7 @@ func (txProc *txProcessor) addNonExecutableLog(executionErr error, originalTxHas Address: originalTx.GetRcvAddr(), } - return txProc.failedTxLogsAccumulator.SaveLogs(originalTxHash, originalTx, []*vmcommon.LogEntry{logEntry}) + return txProc.txLogsProcessor.SaveLog(originalTxHash, originalTx, []*vmcommon.LogEntry{logEntry}) } @@ -1009,7 +839,6 @@ func (txProc *txProcessor) processUserTx( relayedTxValue *big.Int, relayedNonce uint64, originalTxHash []byte, - innerTxIdx int, ) (vmcommon.ReturnCode, error) { relayerAdr := originalTx.SndAddr @@ -1026,8 +855,7 @@ func (txProc *txProcessor) processUserTx( relayedNonce, originalTx, originalTxHash, - err.Error(), - innerTxIdx) + err.Error()) } txType, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(userTx) @@ -1044,8 +872,7 @@ func (txProc *txProcessor) processUserTx( relayedNonce, originalTx, originalTxHash, - err.Error(), - innerTxIdx) + err.Error()) } scrFromTx, err := txProc.makeSCRFromUserTx(userTx, relayerAdr, relayedTxValue, originalTxHash) @@ -1057,10 +884,6 @@ func (txProc *txProcessor) processUserTx( switch txType { case process.MoveBalance: 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) - } case process.SCDeployment: err = txProc.processMoveBalanceCostRelayedUserTx(userTx, scrFromTx, acntSnd, originalTxHash) if err != nil { @@ -1095,8 +918,7 @@ func (txProc *txProcessor) processUserTx( relayedNonce, originalTx, originalTxHash, - err.Error(), - innerTxIdx) + err.Error()) } if errors.Is(err, process.ErrInvalidMetaTransaction) || errors.Is(err, process.ErrAccountNotPayable) { @@ -1107,8 +929,7 @@ func (txProc *txProcessor) processUserTx( relayedNonce, originalTx, originalTxHash, - err.Error(), - innerTxIdx) + err.Error()) } if errors.Is(err, process.ErrFailedTransaction) { @@ -1186,14 +1007,8 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( originalTx *transaction.Transaction, originalTxHash []byte, errorMsg string, - innerTxIdx int, ) error { - returnMessage := []byte(errorMsg) - isUserTxOfRelayedV3 := innerTxIdx != nonRelayedV3UserTxIdx - if isUserTxOfRelayedV3 { - returnMessage = []byte(fmt.Sprintf("%s while executing inner tx at index %d", errorMsg, innerTxIdx)) - } scrForRelayer := &smartContractResult.SmartContractResult{ Nonce: relayedNonce, Value: big.NewInt(0).Set(relayedTxValue), @@ -1201,7 +1016,7 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( SndAddr: userTx.SndAddr, PrevTxHash: originalTxHash, OriginalTxHash: originalTxHash, - ReturnMessage: returnMessage, + ReturnMessage: []byte(errorMsg), } relayerAcnt, err := txProc.getAccountFromAddress(relayerAdr) @@ -1241,7 +1056,7 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( return err } - if txProc.enableEpochsHandler.IsFlagEnabled(common.AddFailedRelayedTxToInvalidMBsFlag) && !isRelayedV3(originalTx.InnerTransactions) { + if txProc.enableEpochsHandler.IsFlagEnabled(common.AddFailedRelayedTxToInvalidMBsFlag) { err = txProc.badTxForwarder.AddIntermediateTransactions([]data.TransactionHandler{originalTx}, originalTxHash) if err != nil { return err @@ -1275,36 +1090,6 @@ func isNonExecutableError(executionErr error) bool { errors.Is(executionErr, process.ErrTransactionNotExecutable) } -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{scrHash}, - } - - ignorableError := txProc.txLogsProcessor.SaveLog(scrHash, scr, []*vmcommon.LogEntry{completedTxLog}) - if ignorableError != nil { - log.Debug("txProcessor.createCompleteEventLog txLogsProcessor.SaveLog()", "error", ignorableError.Error()) - } -} - -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 4c325a8f78e..88797d31a0c 100644 --- a/process/transaction/shardProcess_test.go +++ b/process/transaction/shardProcess_test.go @@ -13,6 +13,7 @@ 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" + "github.com/multiversx/mx-chain-core-go/marshal" 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" @@ -32,7 +33,6 @@ 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" ) @@ -79,27 +79,25 @@ 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: &testscommon.ArgumentParserMock{}, - ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, - EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.PenalizedTooMuchGasFlag, common.FixRelayedBaseCostFlag), - GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, - TxVersionChecker: &testscommon.TxVersionCheckerStub{}, - TxLogsProcessor: &mock.TxLogsProcessorStub{}, - EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, - RelayedTxV3Processor: &processMocks.RelayedTxV3ProcessorMock{}, - FailedTxLogsAccumulator: &processMocks.FailedTxLogsAccumulatorMock{}, + 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: &testscommon.ArgumentParserMock{}, + ScrForwarder: &mock.IntermediateTransactionHandlerMock{}, + EnableEpochsHandler: enableEpochsHandlerMock.NewEnableEpochsHandlerStub(common.PenalizedTooMuchGasFlag, common.FixRelayedBaseCostFlag), + GuardianChecker: &guardianMocks.GuardedAccountHandlerStub{}, + TxVersionChecker: &testscommon.TxVersionCheckerStub{}, + TxLogsProcessor: &mock.TxLogsProcessorStub{}, + EnableRoundsHandler: &testscommon.EnableRoundsHandlerStub{}, } return args } @@ -331,28 +329,6 @@ func TestNewTxProcessor_NilGuardianCheckerShouldErr(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_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() @@ -2065,530 +2041,6 @@ 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 = []byte("sSRC") - tx.Value = big.NewInt(0) - tx.GasPrice = 1 - tx.GasLimit = 8 - - 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 = 4 - userTx.RelayerAddr = tx.SndAddr - - tx.InnerTransactions = []*transaction.Transaction{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.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.EnableEpochsHandlerStub{} - execTx, _ := txproc.NewTxProcessor(args) - - returnCode, err := execTx.ProcessTransaction(tx) - assert.Equal(t, process.ErrFailedTransaction, err) - assert.Equal(t, vmcommon.UserError, returnCode) - }) - t.Run("value on parent tx should error", func(t *testing.T) { - t.Parallel() - - txCopy := *tx - txCopy.Value = big.NewInt(1) - testProcessRelayedTransactionV3(t, &txCopy, userTx.SndAddr, userTx.RcvAddr, process.ErrFailedTransaction, vmcommon.UserError) - }) - t.Run("different receiver on tx should error", func(t *testing.T) { - t.Parallel() - - txCopy := *tx - 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() - - txCopy := *tx - userTxCopy := *userTx - userTxCopy.RelayerAddr = nil - 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() - - txCopy := *tx - userTxCopy := *userTx - userTxCopy.RelayerAddr = []byte("other") - 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.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.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() - - 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.FixRelayedBaseCostFlag) - args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ - 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, - 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 - 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, - } - innerTx3 := &transaction.Transaction{ - Nonce: 0, - Value: big.NewInt(10), - RcvAddr: []byte("sDST"), - SndAddr: providedAddrFail, - GasPrice: 1, - GasLimit: 1, - RelayerAddr: txCopy.SndAddr, - } - - txCopy.InnerTransactions = []*transaction.Transaction{innerTx1, innerTx2, innerTx3} - returnCode, err := execTx.ProcessTransaction(&txCopy) - assert.NoError(t, err) - assert.Equal(t, vmcommon.Ok, returnCode) - - expectedBalance := providedInitialBalance - for _, acnt := range accounts { - switch string(acnt.AddressBytes()) { - case "sSRC": - continue // relayer - case "sDST": - expectedBalance = big.NewInt(120) // 2 successful txs received - 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") - } - - 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() - - 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.FixRelayedBaseCostFlag) - args.EconomicsFee = &economicsmocks.EconomicsHandlerStub{ - 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, - 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 - 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) - assert.True(t, wasGetLogsCalled) - assert.True(t, wasRemoveCalled) - }) - 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.FixRelayedBaseCostFlag) - 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) - }) -} - -func testProcessRelayedTransactionV3( - t *testing.T, - tx *transaction.Transaction, - innerSender []byte, - 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)) - acntInnerSender := createUserAcc(innerSender) - _ = acntInnerSender.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 - } - if bytes.Equal(address, innerSender) { - return acntInnerSender, 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.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.FixRelayedBaseCostFlag) - 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 - }, - 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, - ShardCoordinator: args.ShardCoordinator, - MaxTransactionsAllowed: 10, - }) - - 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() @@ -3846,12 +3298,12 @@ func TestTxProcessor_AddNonExecutableLog(t *testing.T) { originalTxHash, err := core.CalculateHash(args.Marshalizer, args.Hasher, originalTx) assert.Nil(t, err) numLogsSaved := 0 - args.FailedTxLogsAccumulator = &processMocks.FailedTxLogsAccumulatorMock{ - SaveLogsCalled: func(txHash []byte, tx data.TransactionHandler, logs []*vmcommon.LogEntry) error { + args.TxLogsProcessor = &mock.TxLogsProcessorStub{ + SaveLogCalled: func(txHash []byte, tx data.TransactionHandler, vmLogs []*vmcommon.LogEntry) error { assert.Equal(t, originalTxHash, txHash) assert.Equal(t, originalTx, tx) - assert.Equal(t, 1, len(logs)) - firstLog := logs[0] + assert.Equal(t, 1, len(vmLogs)) + firstLog := vmLogs[0] assert.Equal(t, core.SignalErrorOperation, string(firstLog.Identifier)) assert.Equal(t, sender, firstLog.Address) assert.Empty(t, firstLog.Data) @@ -3880,20 +3332,21 @@ func TestTxProcessor_ProcessMoveBalanceToNonPayableContract(t *testing.T) { t.Parallel() shardCoordinator := mock.NewOneShardCoordinatorMock() + marshaller := marshal.JsonMarshalizer{} 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} + marshalledData, _ := marshaller.Marshal(&innerTx) + tx.Data = []byte("relayedTx@" + hex.EncodeToString(marshalledData)) shardCoordinator.ComputeIdCalled = func(address []byte) uint32 { return 0 @@ -3909,19 +3362,20 @@ func TestTxProcessor_ProcessMoveBalanceToNonPayableContract(t *testing.T) { args := createArgsForTxProcessor() args.Accounts = adb args.ShardCoordinator = shardCoordinator + args.SignMarshalizer = &marshaller 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.RelayedTx, process.RelayedTx } return process.MoveBalance, process.MoveBalance }, } args.EnableEpochsHandler = enableEpochsHandlerMock.NewEnableEpochsHandlerStub( - common.RelayedTransactionsV3Flag, + common.RelayedTransactionsFlag, common.FixRelayedBaseCostFlag, common.FixRelayedMoveBalanceToNonPayableSCFlag, ) @@ -3930,6 +3384,11 @@ func TestTxProcessor_ProcessMoveBalanceToNonPayableContract(t *testing.T) { return false, nil }, } + args.ArgsParser = &testscommon.ArgumentParserMock{ + ParseCallDataCalled: func(data string) (string, [][]byte, error) { + return core.RelayedTransaction, [][]byte{marshalledData}, nil + }, + } execTx, _ := txproc.NewTxProcessor(args) _, err := execTx.ProcessTransaction(&tx) @@ -3943,7 +3402,7 @@ func TestTxProcessor_IsInterfaceNil(t *testing.T) { t.Parallel() args := createArgsForTxProcessor() - args.RelayedTxV3Processor = nil + args.Hasher = nil proc, _ := txproc.NewTxProcessor(args) require.True(t, proc.IsInterfaceNil()) diff --git a/process/transactionEvaluator/transactionEvaluator.go b/process/transactionEvaluator/transactionEvaluator.go index 032aeefdc80..9e61d138419 100644 --- a/process/transactionEvaluator/transactionEvaluator.go +++ b/process/transactionEvaluator/transactionEvaluator.go @@ -119,7 +119,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, process.RelayedTxV3: + case process.RelayedTx, process.RelayedTxV2: // TODO implement in the next PR return &transaction.CostResponse{ GasUnits: 0, diff --git a/process/transactionLog/failedTxLogsAccumulator.go b/process/transactionLog/failedTxLogsAccumulator.go deleted file mode 100644 index a0d973541bc..00000000000 --- a/process/transactionLog/failedTxLogsAccumulator.go +++ /dev/null @@ -1,109 +0,0 @@ -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 deleted file mode 100644 index 691f4b41ffa..00000000000 --- a/process/transactionLog/failedTxLogsAccumulator_test.go +++ /dev/null @@ -1,168 +0,0 @@ -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/sharding/mock/enableEpochsHandlerMock.go b/sharding/mock/enableEpochsHandlerMock.go index 9a842f9adae..48dfcedfa52 100644 --- a/sharding/mock/enableEpochsHandlerMock.go +++ b/sharding/mock/enableEpochsHandlerMock.go @@ -43,21 +43,6 @@ func (mock *EnableEpochsHandlerMock) GetCurrentEpoch() uint32 { return mock.CurrentEpoch } -// FixGasRemainingForSaveKeyValueBuiltinFunctionEnabled - -func (mock *EnableEpochsHandlerMock) FixGasRemainingForSaveKeyValueBuiltinFunctionEnabled() bool { - return false -} - -// IsRelayedTransactionsV3FlagEnabled - -func (mock *EnableEpochsHandlerMock) IsRelayedTransactionsV3FlagEnabled() bool { - return false -} - -// IsFixRelayedBaseCostFlagEnabled - -func (mock *EnableEpochsHandlerMock) IsFixRelayedBaseCostFlagEnabled() 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/components/default.go b/testscommon/components/default.go index 8e1942037dd..514b8355407 100644 --- a/testscommon/components/default.go +++ b/testscommon/components/default.go @@ -20,7 +20,6 @@ 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" @@ -157,7 +156,6 @@ func GetDefaultProcessComponents(shardCoordinator sharding.Coordinator) *mock.Pr return &mock.PrivateKeyStub{} }, }, - HardforkTriggerField: &testscommon.HardforkTriggerStub{}, - RelayedTxV3ProcessorField: &processMocks.RelayedTxV3ProcessorMock{}, + HardforkTriggerField: &testscommon.HardforkTriggerStub{}, } } diff --git a/testscommon/economicsmocks/economicsDataHandlerStub.go b/testscommon/economicsmocks/economicsDataHandlerStub.go index c76ce6c59a2..4ef784c596f 100644 --- a/testscommon/economicsmocks/economicsDataHandlerStub.go +++ b/testscommon/economicsmocks/economicsDataHandlerStub.go @@ -5,7 +5,6 @@ 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,8 +46,6 @@ 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) - SetTxTypeHandlerCalled func(txTypeHandler process.TxTypeHandler) error ComputeMoveBalanceFeeInEpochCalled func(tx data.TransactionWithFeeHandler, epoch uint32) *big.Int } @@ -368,22 +365,6 @@ 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 -} - -// 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 0c92fff0238..b1e4321f389 100644 --- a/testscommon/economicsmocks/economicsHandlerMock.go +++ b/testscommon/economicsmocks/economicsHandlerMock.go @@ -5,7 +5,6 @@ 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 - @@ -48,8 +47,6 @@ 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) - SetTxTypeHandlerCalled func(txTypeHandler process.TxTypeHandler) error } // LeaderPercentage - @@ -346,22 +343,6 @@ 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 -} - -// 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/processMocks/failedTxLogsAccumulatorMock.go b/testscommon/processMocks/failedTxLogsAccumulatorMock.go deleted file mode 100644 index 903e56cd79f..00000000000 --- a/testscommon/processMocks/failedTxLogsAccumulatorMock.go +++ /dev/null @@ -1,41 +0,0 @@ -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 -} diff --git a/testscommon/processMocks/relayedTxV3ProcessorMock.go b/testscommon/processMocks/relayedTxV3ProcessorMock.go deleted file mode 100644 index 85af9584af5..00000000000 --- a/testscommon/processMocks/relayedTxV3ProcessorMock.go +++ /dev/null @@ -1,23 +0,0 @@ -package processMocks - -import ( - "github.com/multiversx/mx-chain-core-go/data/transaction" -) - -// RelayedTxV3ProcessorMock - -type RelayedTxV3ProcessorMock struct { - CheckRelayedTxCalled func(tx *transaction.Transaction) error -} - -// 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 a8ed95f4ceb..c13f25f3f5a 100644 --- a/update/factory/exportHandlerFactory.go +++ b/update/factory/exportHandlerFactory.go @@ -18,7 +18,6 @@ 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" @@ -589,7 +588,6 @@ 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 67d5a86a503..0fe0298c4d6 100644 --- a/update/factory/fullSyncInterceptors.go +++ b/update/factory/fullSyncInterceptors.go @@ -75,7 +75,6 @@ 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 @@ -146,7 +145,6 @@ func NewFullSyncInterceptorsContainerFactory( EpochStartTrigger: args.EpochStartTrigger, WhiteListerVerifiedTxs: args.WhiteListerVerifiedTxs, ArgsParser: smartContract.NewArgumentParser(), - RelayedTxV3Processor: args.RelayedTxV3Processor, } icf := &fullSyncInterceptorsContainerFactory{ From 0678c6eb479d913087a82e61e71dd274f1735119 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 21 Oct 2024 08:50:26 +0300 Subject: [PATCH 421/434] updated indexer --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 8718f3e9d10..b1eb1aa4ddb 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.23-0.20241018134424-75bab2a9058c github.com/multiversx/mx-chain-crypto-go v1.2.12 - github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018153953-b27532a1b4a6 + github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018130218-f48c7282690b 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 232f91ed5a7..32ad88ef7af 100644 --- a/go.sum +++ b/go.sum @@ -391,8 +391,8 @@ github.com/multiversx/mx-chain-core-go v1.2.23-0.20241018134424-75bab2a9058c h1: github.com/multiversx/mx-chain-core-go v1.2.23-0.20241018134424-75bab2a9058c/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4= -github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018153953-b27532a1b4a6 h1:2F5WyCIvFVs4CONd9kJxibY1NIfJLYFAwqNJvC31qNA= -github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018153953-b27532a1b4a6/go.mod h1:AJew7KVcICVyVDlXpDQzvjcSnKs0aCYl7eXnJwg+15E= +github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018130218-f48c7282690b h1:GYvm0yGkdQ3OCfNqnyIQNzAzydN3cES8noJZ3eZHN1A= +github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018130218-f48c7282690b/go.mod h1:oGcRK2E3Syv6vRTszWrrb/TqD8akq0yeoMr1wPPiTO4= github.com/multiversx/mx-chain-logger-go v1.0.15 h1:HlNdK8etyJyL9NQ+6mIXyKPEBo+wRqOwi3n+m2QIHXc= github.com/multiversx/mx-chain-logger-go v1.0.15/go.mod h1:t3PRKaWB1M+i6gUfD27KXgzLJJC+mAQiN+FLlL1yoGQ= github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFzHeruelESfpTlf460= From 953bb39d3627e20276876a66a966676e18556766 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 21 Oct 2024 10:54:07 +0300 Subject: [PATCH 422/434] possible fix for failing test --- factory/processing/txSimulatorProcessComponents_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/factory/processing/txSimulatorProcessComponents_test.go b/factory/processing/txSimulatorProcessComponents_test.go index aad848600d8..0c919b0ba95 100644 --- a/factory/processing/txSimulatorProcessComponents_test.go +++ b/factory/processing/txSimulatorProcessComponents_test.go @@ -9,6 +9,7 @@ import ( "github.com/multiversx/mx-chain-go/process/mock" "github.com/multiversx/mx-chain-go/testscommon/components" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestManagedProcessComponents_createAPITransactionEvaluator(t *testing.T) { @@ -40,6 +41,7 @@ func TestManagedProcessComponents_createAPITransactionEvaluator(t *testing.T) { assert.Nil(t, err) assert.False(t, check.IfNil(apiTransactionEvaluator)) assert.False(t, check.IfNil(vmContainerFactory)) + require.NoError(t, vmContainerFactory.Close()) }) t.Run("should work for metachain", func(t *testing.T) { processArgs := components.GetProcessComponentsFactoryArgs(shardCoordinatorForMetachain) @@ -49,5 +51,6 @@ func TestManagedProcessComponents_createAPITransactionEvaluator(t *testing.T) { assert.Nil(t, err) assert.False(t, check.IfNil(apiTransactionEvaluator)) assert.False(t, check.IfNil(vmContainerFactory)) + require.NoError(t, vmContainerFactory.Close()) }) } From 919d287c618073636f8a3a636db5fcae9bc30b03 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 21 Oct 2024 13:20:20 +0300 Subject: [PATCH 423/434] fixes after review --- node/external/dtos.go | 1 - node/external/transactionAPI/gasUsedAndFeeProcessor.go | 3 --- 2 files changed, 4 deletions(-) diff --git a/node/external/dtos.go b/node/external/dtos.go index ad8d073967b..f884d8d32c9 100644 --- a/node/external/dtos.go +++ b/node/external/dtos.go @@ -17,5 +17,4 @@ type ArgsCreateTransaction struct { Options uint32 Guardian string GuardianSigHex string - Relayer string } diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index ab5c77fee40..bc01297ef85 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -62,9 +62,6 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction if !scr.IsRefund || scr.RcvAddr != tx.Sender { continue } - if scr.RcvAddr != tx.Sender { - continue - } gfp.setGasUsedAndFeeBaseOnRefundValue(tx, scr.Value) hasRefundForSender = true From 2bcbc152fd4075631d12d070e093b119957d4b0c Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 21 Oct 2024 14:12:47 +0300 Subject: [PATCH 424/434] removed config --- cmd/node/config/config.toml | 3 --- config/config.go | 7 ------- testscommon/generalConfig.go | 3 --- 3 files changed, 13 deletions(-) diff --git a/cmd/node/config/config.toml b/cmd/node/config/config.toml index 7f07d4dd380..6e1205d5f7e 100644 --- a/cmd/node/config/config.toml +++ b/cmd/node/config/config.toml @@ -946,6 +946,3 @@ # 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 diff --git a/config/config.go b/config/config.go index 412ab59f776..49ef257c341 100644 --- a/config/config.go +++ b/config/config.go @@ -228,8 +228,6 @@ type Config struct { PeersRatingConfig PeersRatingConfig PoolsCleanersConfig PoolsCleanersConfig Redundancy RedundancyConfig - - RelayedTransactionConfig RelayedTransactionConfig } // PeersRatingConfig will hold settings related to peers rating @@ -642,8 +640,3 @@ 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/testscommon/generalConfig.go b/testscommon/generalConfig.go index 53299443ebe..1eea96a2bdb 100644 --- a/testscommon/generalConfig.go +++ b/testscommon/generalConfig.go @@ -429,9 +429,6 @@ func GetGeneralConfig() config.Config { ResourceStats: config.ResourceStatsConfig{ RefreshIntervalInSec: 1, }, - RelayedTransactionConfig: config.RelayedTransactionConfig{ - MaxTransactionsAllowed: 10, - }, } } From 520f93f7db12bd54c49a670ed49d193830e8a52e Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 21 Oct 2024 15:47:40 +0300 Subject: [PATCH 425/434] more fixes after review --- config/tomlConfig_test.go | 24 +++++++++---------- .../multiShard/relayedTx/common.go | 6 ++--- .../multiShard/relayedTx/relayedTx_test.go | 12 +++++----- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index e7095b0b096..39a582b1ef2 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -867,22 +867,22 @@ func TestEnableEpochConfig(t *testing.T) { UseGasBoundedShouldFailExecutionEnableEpoch = 96 # DynamicESDTEnableEpoch represents the epoch when dynamic NFT feature is enabled - DynamicESDTEnableEpoch = 96 + DynamicESDTEnableEpoch = 97 # EGLDInMultiTransferEnableEpoch represents the epoch when EGLD in MultiTransfer is enabled - EGLDInMultiTransferEnableEpoch = 97 + EGLDInMultiTransferEnableEpoch = 98 # CryptoOpcodesV2EnableEpoch represents the epoch when BLSMultiSig, Secp256r1 and other opcodes are enabled - CryptoOpcodesV2EnableEpoch = 98 + CryptoOpcodesV2EnableEpoch = 99 # FixRelayedBaseCostEnableEpoch represents the epoch when the fix for relayed base cost will be enabled - FixRelayedBaseCostEnableEpoch = 99 + FixRelayedBaseCostEnableEpoch = 100 # MultiESDTNFTTransferAndExecuteByUserEnableEpoch represents the epoch when enshrined sovereign cross chain opcodes are enabled - MultiESDTNFTTransferAndExecuteByUserEnableEpoch = 100 + MultiESDTNFTTransferAndExecuteByUserEnableEpoch = 101 # FixRelayedMoveBalanceToNonPayableSCEnableEpoch represents the epoch when the fix for relayed move balance to non payable sc will be enabled - FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 101 + FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 102 # MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MaxNodesChangeEnableEpoch = [ @@ -998,12 +998,12 @@ func TestEnableEpochConfig(t *testing.T) { AlwaysMergeContextsInEEIEnableEpoch: 94, CleanupAuctionOnLowWaitingListEnableEpoch: 95, UseGasBoundedShouldFailExecutionEnableEpoch: 96, - DynamicESDTEnableEpoch: 96, - EGLDInMultiTransferEnableEpoch: 97, - CryptoOpcodesV2EnableEpoch: 98, - FixRelayedBaseCostEnableEpoch: 99, - MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 100, - FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 101, + DynamicESDTEnableEpoch: 97, + EGLDInMultiTransferEnableEpoch: 98, + CryptoOpcodesV2EnableEpoch: 99, + FixRelayedBaseCostEnableEpoch: 100, + MultiESDTNFTTransferAndExecuteByUserEnableEpoch: 101, + FixRelayedMoveBalanceToNonPayableSCEnableEpoch: 102, MaxNodesChangeEnableEpoch: []MaxNodesChangeConfig{ { EpochEnable: 44, diff --git a/integrationTests/multiShard/relayedTx/common.go b/integrationTests/multiShard/relayedTx/common.go index 54d99ff869d..a9098c6c668 100644 --- a/integrationTests/multiShard/relayedTx/common.go +++ b/integrationTests/multiShard/relayedTx/common.go @@ -15,16 +15,16 @@ import ( ) // CreateGeneralSetupForRelayTxTest will create the general setup for relayed transactions -func CreateGeneralSetupForRelayTxTest(relayedV3Test bool) ([]*integrationTests.TestProcessorNode, []int, []*integrationTests.TestWalletAccount, *integrationTests.TestWalletAccount) { +func CreateGeneralSetupForRelayTxTest(baseCostFixEnabled bool) ([]*integrationTests.TestProcessorNode, []int, []*integrationTests.TestWalletAccount, *integrationTests.TestWalletAccount) { initialVal := big.NewInt(10000000000) epochsConfig := integrationTests.GetDefaultEnableEpochsConfig() - if !relayedV3Test { + if !baseCostFixEnabled { epochsConfig.FixRelayedBaseCostEnableEpoch = integrationTests.UnreachableEpoch epochsConfig.FixRelayedMoveBalanceToNonPayableSCEnableEpoch = integrationTests.UnreachableEpoch } nodes, idxProposers := createAndMintNodes(initialVal, epochsConfig) - players, relayerAccount := createAndMintPlayers(relayedV3Test, nodes, initialVal) + players, relayerAccount := createAndMintPlayers(baseCostFixEnabled, nodes, initialVal) return nodes, idxProposers, players, relayerAccount } diff --git a/integrationTests/multiShard/relayedTx/relayedTx_test.go b/integrationTests/multiShard/relayedTx/relayedTx_test.go index 87a54633953..41ece5b81eb 100644 --- a/integrationTests/multiShard/relayedTx/relayedTx_test.go +++ b/integrationTests/multiShard/relayedTx/relayedTx_test.go @@ -51,14 +51,14 @@ func TestRelayedTransactionInMultiShardEnvironmentWithAttestationContract(t *tes func testRelayedTransactionInMultiShardEnvironmentWithNormalTx( createAndSendRelayedAndUserTxFunc createAndSendRelayedAndUserTxFuncType, - relayedV3Test bool, + baseCostFixEnabled 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(relayedV3Test) + nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest(baseCostFixEnabled) defer func() { for _, n := range nodes { n.Close() @@ -115,14 +115,14 @@ func testRelayedTransactionInMultiShardEnvironmentWithNormalTx( func testRelayedTransactionInMultiShardEnvironmentWithSmartContractTX( createAndSendRelayedAndUserTxFunc createAndSendRelayedAndUserTxFuncType, - relayedV3Test bool, + baseCostFixEnabled 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(relayedV3Test) + nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest(baseCostFixEnabled) defer func() { for _, n := range nodes { n.Close() @@ -211,14 +211,14 @@ func testRelayedTransactionInMultiShardEnvironmentWithSmartContractTX( func testRelayedTransactionInMultiShardEnvironmentWithESDTTX( createAndSendRelayedAndUserTxFunc createAndSendRelayedAndUserTxFuncType, - relayedV3Test bool, + baseCostFixEnabled 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(relayedV3Test) + nodes, idxProposers, players, relayer := CreateGeneralSetupForRelayTxTest(baseCostFixEnabled) defer func() { for _, n := range nodes { n.Close() From 4306c57eaa83d6b58d9c59c4d4754b3163ba9bca Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 21 Oct 2024 16:48:47 +0300 Subject: [PATCH 426/434] new version of mx-chain-comm-go --- cmd/node/config/external.toml | 2 +- go.mod | 2 +- go.sum | 4 ++-- node/chainSimulator/components/memoryComponents.go | 4 ++-- outport/factory/hostDriverFactory_test.go | 2 +- outport/factory/outportFactory_test.go | 6 +++--- testscommon/components/components.go | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cmd/node/config/external.toml b/cmd/node/config/external.toml index 1058e0c3fb7..6fbbbb195c6 100644 --- a/cmd/node/config/external.toml +++ b/cmd/node/config/external.toml @@ -51,7 +51,7 @@ # URL for the WebSocket client/server connection # This value represents the IP address and port number that the WebSocket client or server will use to establish a connection. - URL = "127.0.0.1:22111" + URL = "ws://127.0.0.1:22111" # After a message will be sent it will wait for an ack message if this flag is enabled WithAcknowledge = true diff --git a/go.mod b/go.mod index d2b76ce9593..ef4af183e27 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.1.0 + github.com/multiversx/mx-chain-communication-go v1.1.1-0.20241021133229-d0833256e3ec github.com/multiversx/mx-chain-core-go v1.2.22 github.com/multiversx/mx-chain-crypto-go v1.2.12 github.com/multiversx/mx-chain-es-indexer-go v1.7.9 diff --git a/go.sum b/go.sum index 0b789eb79b2..335ffcb2984 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.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-communication-go v1.1.1-0.20241021133229-d0833256e3ec h1:KwpeVZXSHzic8DV9zaJZmaBgDNIIpSdbGz4Q+9fZyiI= +github.com/multiversx/mx-chain-communication-go v1.1.1-0.20241021133229-d0833256e3ec/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= github.com/multiversx/mx-chain-core-go v1.2.22 h1:yDYrvoQOBbsDerEp7L3+de5AfMy3pTF333gWPpd+FNk= github.com/multiversx/mx-chain-core-go v1.2.22/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= diff --git a/node/chainSimulator/components/memoryComponents.go b/node/chainSimulator/components/memoryComponents.go index 3b12e720756..639dafc753d 100644 --- a/node/chainSimulator/components/memoryComponents.go +++ b/node/chainSimulator/components/memoryComponents.go @@ -9,11 +9,11 @@ import ( // CreateMemUnit creates a new in-memory storage unit func CreateMemUnit() storage.Storer { - capacity := uint32(10) + capacity := uint32(10_000_000) shards := uint32(1) sizeInBytes := uint64(0) cache, _ := storageunit.NewCache(storageunit.CacheConfig{Type: storageunit.LRUCache, Capacity: capacity, Shards: shards, SizeInBytes: sizeInBytes}) - persist, _ := database.NewlruDB(100000) + persist, _ := database.NewlruDB(10_000_000) unit, _ := storageunit.NewStorageUnit(cache, persist) return unit diff --git a/outport/factory/hostDriverFactory_test.go b/outport/factory/hostDriverFactory_test.go index d41079c0f55..d005ea4ba74 100644 --- a/outport/factory/hostDriverFactory_test.go +++ b/outport/factory/hostDriverFactory_test.go @@ -15,7 +15,7 @@ func TestCreateHostDriver(t *testing.T) { args := ArgsHostDriverFactory{ HostConfig: config.HostDriversConfig{ - URL: "localhost", + URL: "ws://localhost", RetryDurationInSec: 1, MarshallerType: "json", Mode: data.ModeClient, diff --git a/outport/factory/outportFactory_test.go b/outport/factory/outportFactory_test.go index 93b4657427b..94d8c38839c 100644 --- a/outport/factory/outportFactory_test.go +++ b/outport/factory/outportFactory_test.go @@ -122,7 +122,7 @@ func TestCreateOutport_SubscribeMultipleHostDrivers(t *testing.T) { Marshaller: &testscommon.MarshalizerMock{}, HostConfig: config.HostDriversConfig{ Enabled: true, - URL: "localhost", + URL: "ws://localhost", RetryDurationInSec: 1, MarshallerType: "json", Mode: data.ModeClient, @@ -132,7 +132,7 @@ func TestCreateOutport_SubscribeMultipleHostDrivers(t *testing.T) { Marshaller: &testscommon.MarshalizerMock{}, HostConfig: config.HostDriversConfig{ Enabled: false, - URL: "localhost", + URL: "ws://localhost", RetryDurationInSec: 1, MarshallerType: "json", Mode: data.ModeClient, @@ -142,7 +142,7 @@ func TestCreateOutport_SubscribeMultipleHostDrivers(t *testing.T) { Marshaller: &testscommon.MarshalizerMock{}, HostConfig: config.HostDriversConfig{ Enabled: true, - URL: "localhost", + URL: "ws://localhost", RetryDurationInSec: 1, MarshallerType: "json", Mode: data.ModeClient, diff --git a/testscommon/components/components.go b/testscommon/components/components.go index 0e3dcc14cd1..55b09fe99de 100644 --- a/testscommon/components/components.go +++ b/testscommon/components/components.go @@ -687,7 +687,7 @@ func GetStatusComponentsFactoryArgsAndProcessComponents(shardCoordinator shardin { MarshallerType: "json", Mode: "client", - URL: "localhost:12345", + URL: "ws://localhost:12345", RetryDurationInSec: 1, }, }, From 5897fbc85dc57227b1b3ebd714d810ad577de881 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 22 Oct 2024 12:12:16 +0300 Subject: [PATCH 427/434] fix for workflow --- .../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 f766ccddbf5..8cf5c879345 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 @@ -164,7 +164,7 @@ jobs: - 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 --html=report.html --self-contained-html --continue-on-collection-errors PYTEST_EXIT_CODE=$? set -e echo "PYTEST_EXIT_CODE=$PYTEST_EXIT_CODE" >> $GITHUB_ENV From 0b88dd59484f856aac69f3b37d6efb677958540f Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 22 Oct 2024 13:19:09 +0300 Subject: [PATCH 428/434] reverted last commit --- .../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 8cf5c879345..f766ccddbf5 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 @@ -164,7 +164,7 @@ jobs: - name: Run tests and generate HTML report run: | set +e - pytest --html=report.html --self-contained-html --continue-on-collection-errors + 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 From f8f6b35b3a0c04ad10f835baf0c0f27480953867 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 23 Oct 2024 21:57:41 +0300 Subject: [PATCH 429/434] fix gasUsed and fee for relayed v1 and v2 --- .../transactionAPI/apiTransactionProcessor.go | 2 +- .../transactionAPI/gasUsedAndFeeProcessor.go | 80 ++++++--- .../gasUsedAndFeeProcessor_test.go | 48 ++++++ .../relayedV1CreateNewDelegationContract.json | 158 ++++++++++++++++++ .../transactionsFeeProcessor.go | 46 +++-- 5 files changed, 295 insertions(+), 39 deletions(-) create mode 100644 node/external/transactionAPI/testData/relayedV1CreateNewDelegationContract.json diff --git a/node/external/transactionAPI/apiTransactionProcessor.go b/node/external/transactionAPI/apiTransactionProcessor.go index c4e75bc29b9..c67ad1cb445 100644 --- a/node/external/transactionAPI/apiTransactionProcessor.go +++ b/node/external/transactionAPI/apiTransactionProcessor.go @@ -201,7 +201,7 @@ func (atp *apiTransactionProcessor) populateComputedFieldInitiallyPaidFee(tx *tr isFeeFixActive := atp.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, tx.Epoch) isRelayedAfterFix := tx.IsRelayed && isFeeFixActive if isRelayedAfterFix { - fee, _ = atp.gasUsedAndFeeProcessor.getFeeOfRelayed(tx) + _, fee, _ = atp.gasUsedAndFeeProcessor.getFeeOfRelayed(tx) tx.InitiallyPaidFee = fee.String() } } diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index bc01297ef85..06c2c7d3bfc 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -4,6 +4,7 @@ import ( "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-core-go/marshal" "github.com/multiversx/mx-chain-go/common" @@ -49,7 +50,7 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction tx.Fee = tx.InitiallyPaidFee } - initialTotalFee, isRelayed := gfp.getFeeOfRelayed(tx) + userTx, initialTotalFee, isRelayed := gfp.getFeeOfRelayed(tx) isRelayedAfterFix := isRelayed && isFeeFixActive if isRelayedAfterFix { tx.InitiallyPaidFee = initialTotalFee.String() @@ -63,26 +64,26 @@ func (gfp *gasUsedAndFeeProcessor) computeAndAttachGasUsedAndFee(tx *transaction continue } - gfp.setGasUsedAndFeeBaseOnRefundValue(tx, scr.Value) + gfp.setGasUsedAndFeeBaseOnRefundValue(tx, userTx, scr.Value) hasRefundForSender = true break } - gfp.prepareTxWithResultsBasedOnLogs(tx, hasRefundForSender) + gfp.prepareTxWithResultsBasedOnLogs(tx, userTx, hasRefundForSender) } -func (gfp *gasUsedAndFeeProcessor) getFeeOfRelayed(tx *transaction.ApiTransactionResult) (*big.Int, bool) { +func (gfp *gasUsedAndFeeProcessor) getFeeOfRelayed(tx *transaction.ApiTransactionResult) (*transaction.ApiTransactionResult, *big.Int, bool) { if !tx.IsRelayed { - return nil, false + return nil, nil, false } if len(tx.Data) == 0 { - return nil, false + return nil, nil, false } funcName, args, err := gfp.argsParser.ParseCallData(string(tx.Data)) if err != nil { - return nil, false + return nil, nil, false } if funcName == core.RelayedTransaction { @@ -93,32 +94,33 @@ func (gfp *gasUsedAndFeeProcessor) getFeeOfRelayed(tx *transaction.ApiTransactio return gfp.handleRelayedV2(args, tx) } - return nil, false + return nil, nil, false } -func (gfp *gasUsedAndFeeProcessor) handleRelayedV1(args [][]byte, tx *transaction.ApiTransactionResult) (*big.Int, bool) { +func (gfp *gasUsedAndFeeProcessor) handleRelayedV1(args [][]byte, tx *transaction.ApiTransactionResult) (*transaction.ApiTransactionResult, *big.Int, bool) { if len(args) != 1 { - return nil, false + return nil, nil, false } innerTx := &transaction.Transaction{} err := gfp.marshaller.Unmarshal(innerTx, args[0]) if err != nil { - return nil, false + return nil, nil, false } gasUsed := gfp.feeComputer.ComputeGasLimit(tx) fee := gfp.feeComputer.ComputeTxFeeBasedOnGasUsed(tx, gasUsed) - innerFee := gfp.feeComputer.ComputeTransactionFee(&transaction.ApiTransactionResult{ + innerTxApiResult := &transaction.ApiTransactionResult{ Tx: innerTx, Epoch: tx.Epoch, - }) + } + innerFee := gfp.feeComputer.ComputeTransactionFee(innerTxApiResult) - return big.NewInt(0).Add(fee, innerFee), true + return innerTxApiResult, big.NewInt(0).Add(fee, innerFee), true } -func (gfp *gasUsedAndFeeProcessor) handleRelayedV2(args [][]byte, tx *transaction.ApiTransactionResult) (*big.Int, bool) { +func (gfp *gasUsedAndFeeProcessor) handleRelayedV2(args [][]byte, tx *transaction.ApiTransactionResult) (*transaction.ApiTransactionResult, *big.Int, bool) { innerTx := &transaction.Transaction{} innerTx.RcvAddr = args[0] innerTx.Nonce = big.NewInt(0).SetBytes(args[1]).Uint64() @@ -132,16 +134,18 @@ func (gfp *gasUsedAndFeeProcessor) handleRelayedV2(args [][]byte, tx *transactio gasUsed := gfp.feeComputer.ComputeGasLimit(tx) fee := gfp.feeComputer.ComputeTxFeeBasedOnGasUsed(tx, gasUsed) - innerFee := gfp.feeComputer.ComputeTransactionFee(&transaction.ApiTransactionResult{ + innerTxApiResult := &transaction.ApiTransactionResult{ Tx: innerTx, Epoch: tx.Epoch, - }) + } + innerFee := gfp.feeComputer.ComputeTransactionFee(innerTxApiResult) - return big.NewInt(0).Add(fee, innerFee), true + return innerTxApiResult, big.NewInt(0).Add(fee, innerFee), true } func (gfp *gasUsedAndFeeProcessor) prepareTxWithResultsBasedOnLogs( tx *transaction.ApiTransactionResult, + userTx *transaction.ApiTransactionResult, hasRefund bool, ) { if tx.Logs == nil || (tx.Function == "" && tx.Operation == datafield.OperationTransfer) { @@ -149,15 +153,26 @@ func (gfp *gasUsedAndFeeProcessor) prepareTxWithResultsBasedOnLogs( } for _, event := range tx.Logs.Events { - gfp.setGasUsedAndFeeBaseOnLogEvent(tx, hasRefund, event) + gfp.setGasUsedAndFeeBaseOnLogEvent(tx, userTx, hasRefund, event) } } -func (gfp *gasUsedAndFeeProcessor) setGasUsedAndFeeBaseOnLogEvent(tx *transaction.ApiTransactionResult, hasRefund bool, event *transaction.Events) { +func (gfp *gasUsedAndFeeProcessor) setGasUsedAndFeeBaseOnLogEvent(tx *transaction.ApiTransactionResult, userTx *transaction.ApiTransactionResult, hasRefund bool, event *transaction.Events) { if core.WriteLogIdentifier == event.Identifier && !hasRefund { - gasUsed, fee := gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(tx, big.NewInt(0)) - tx.GasUsed = gasUsed - tx.Fee = fee.String() + if !check.IfNilReflect(userTx) && gfp.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, tx.Epoch) { + gasUsed, fee := gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(userTx, big.NewInt(0)) + gasUsedRelayedTx := gfp.feeComputer.ComputeGasLimit(tx) + feeRelayedTx := gfp.feeComputer.ComputeTxFeeBasedOnGasUsed(tx, gasUsedRelayedTx) + + tx.GasUsed = gasUsed + gasUsedRelayedTx + + fee.Add(fee, feeRelayedTx) + tx.Fee = fee.String() + } else { + gasUsed, fee := gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(tx, big.NewInt(0)) + tx.GasUsed = gasUsed + tx.Fee = fee.String() + } } if core.SignalErrorOperation == event.Identifier { fee := gfp.feeComputer.ComputeTxFeeBasedOnGasUsed(tx, tx.GasLimit) @@ -166,14 +181,29 @@ func (gfp *gasUsedAndFeeProcessor) setGasUsedAndFeeBaseOnLogEvent(tx *transactio } } -func (gfp *gasUsedAndFeeProcessor) setGasUsedAndFeeBaseOnRefundValue(tx *transaction.ApiTransactionResult, refund *big.Int) { +func (gfp *gasUsedAndFeeProcessor) setGasUsedAndFeeBaseOnRefundValue( + tx *transaction.ApiTransactionResult, + userTx *transaction.ApiTransactionResult, + refund *big.Int, +) { + if !check.IfNilReflect(userTx) && gfp.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, tx.Epoch) { + gasUsed, fee := gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(userTx, refund) + gasUsedRelayedTx := gfp.feeComputer.ComputeGasLimit(tx) + feeRelayedTx := gfp.feeComputer.ComputeTxFeeBasedOnGasUsed(tx, gasUsedRelayedTx) + + tx.GasUsed = gasUsed + gasUsedRelayedTx + + fee.Add(fee, feeRelayedTx) + tx.Fee = fee.String() + + return + } gasUsed, fee := gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(tx, refund) tx.GasUsed = gasUsed tx.Fee = fee.String() - } func (gfp *gasUsedAndFeeProcessor) isESDTOperationWithSCCall(tx *transaction.ApiTransactionResult) bool { diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go index c6abd9278d6..8c5c80826c0 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor_test.go @@ -346,3 +346,51 @@ func TestComputeAndAttachGasUsedAndFeeFailedRelayedV1(t *testing.T) { require.Equal(t, "1198000000000000", txWithSRefundSCR.Fee) require.Equal(t, "1274230000000000", txWithSRefundSCR.InitiallyPaidFee) } + +func TestComputeAndAttachGasUsedAndFeeRelayedV1CreateNewDelegationContractWithRefund(t *testing.T) { + t.Parallel() + + enableEpochsHandler := &enableEpochsHandlerMock.EnableEpochsHandlerStub{ + IsFlagEnabledInEpochCalled: func(flag core.EnableEpochFlag, epoch uint32) bool { + return flag == common.GasPriceModifierFlag || + flag == common.PenalizedTooMuchGasFlag || + flag == common.FixRelayedBaseCostFlag + }, + } + feeComp, _ := fee.NewFeeComputer(createEconomicsData(enableEpochsHandler)) + computer := fee.NewTestFeeComputer(feeComp) + + gasUsedAndFeeProc := newGasUsedAndFeeProcessor( + computer, + pubKeyConverter, + smartContract.NewArgumentParser(), + &marshal.JsonMarshalizer{}, + enableEpochsHandler, + ) + + txWithSRefundSCR := &transaction.ApiTransactionResult{} + err := core.LoadJsonFile(txWithSRefundSCR, "testData/relayedV1CreateNewDelegationContract.json") + require.NoError(t, err) + + snd, _ := pubKeyConverter.Decode(txWithSRefundSCR.Sender) + rcv, _ := pubKeyConverter.Decode(txWithSRefundSCR.Receiver) + val, _ := big.NewInt(0).SetString(txWithSRefundSCR.Value, 10) + txWithSRefundSCR.Tx = &transaction.Transaction{ + Nonce: txWithSRefundSCR.Nonce, + Value: val, + RcvAddr: rcv, + SndAddr: snd, + GasPrice: txWithSRefundSCR.GasPrice, + GasLimit: txWithSRefundSCR.GasLimit, + Data: txWithSRefundSCR.Data, + } + + txWithSRefundSCR.InitiallyPaidFee = "" + txWithSRefundSCR.Fee = "" + txWithSRefundSCR.GasUsed = 0 + + gasUsedAndFeeProc.computeAndAttachGasUsedAndFee(txWithSRefundSCR) + require.Equal(t, uint64(56328500), txWithSRefundSCR.GasUsed) + require.Equal(t, "1878500000000000", txWithSRefundSCR.Fee) + require.Equal(t, "2177505000000000", txWithSRefundSCR.InitiallyPaidFee) +} diff --git a/node/external/transactionAPI/testData/relayedV1CreateNewDelegationContract.json b/node/external/transactionAPI/testData/relayedV1CreateNewDelegationContract.json new file mode 100644 index 00000000000..a15e3c533ae --- /dev/null +++ b/node/external/transactionAPI/testData/relayedV1CreateNewDelegationContract.json @@ -0,0 +1,158 @@ +{ + "type": "normal", + "processingTypeOnSource": "RelayedTx", + "processingTypeOnDestination": "RelayedTx", + "hash": "94cb3bd3e2dca9920115f05549c9eee4dfc1d33e4ac3edd0741eb51165148b52", + "nonce": 0, + "round": 7, + "epoch": 1, + "value": "0", + "receiver": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg", + "sender": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", + "gasPrice": 1000000000, + "gasLimit": 86229000, + "data": "cmVsYXllZFR4QDdiMjI2ZTZmNmU2MzY1MjIzYTMwMmMyMjczNjU2ZTY0NjU3MjIyM2EyMjY3NjM2ZjM5MzYzMjdhNTI2OTU5NTg0NTM0MzQ3MzQyMzE3Mzc2NTY0ODczNDg0YTM5MzM2NDc4NDI2NTc3NjU3NjY0NjM0Yjc1MmI1Nzc5NTUzNzZiM2QyMjJjMjI3MjY1NjM2NTY5NzY2NTcyMjIzYTIyNDE0MTQxNDE0MTQxNDE0MTQxNDE0MTQxNDE1MTQxNDE0MTQxNDE0MTQxNDE0MTQxNDE0MTQxNDE0MTQxNDE0MTQxNDE0MTQxNDE0MTQxNDUyZjJmMzgzZDIyMmMyMjc2NjE2Yzc1NjUyMjNhMzIzNTMwMzEzMDMwMzAzMDMwMzAzMDMwMzAzMDMwMzAzMDMwMzAzMDMwMzAyYzIyNjc2MTczNTA3MjY5NjM2NTIyM2EzMTMwMzAzMDMwMzAzMDMwMzAzMDJjMjI2NzYxNzM0YzY5NmQ2OTc0MjIzYTM4MzUzMDMwMzAzMDMwMzAyYzIyNjQ2MTc0NjEyMjNhMjI1OTMzNGE2YzU5NTg1MjZjNTQ2ZDU2MzM1MjQ3NTY3MzVhNTc2NDY4NjQ0NzZjNzY2MjZiNGU3NjYyNmU1Mjc5NTk1NzRlMzA1MTQ0NDE3NzUxNDQ0MTc3MjIyYzIyNzM2OTY3NmU2MTc0NzU3MjY1MjIzYTIyNTk1MTUzNTQ0MjMwMzE0ZjUwNGY0NDU5MzM0ZDU2NDQ1NDRkNWE3NzRkNzY2NjZiNzI1MDUwMzk2ZTM1NjQ1MzU4NjI3MDQ5NWE2MjcwNDM1MTQ5MzMzNDRkNTY2NzZiNzYzMzc0Njk2MTRmNGMzNjQ0NWE2NjM4NTU2NTJmNjg2Zjc5MzkzNTRiNGI2NTVhNDI2YjcwNzAzMTU1NzY3NzU5MzY0NzU3NDI3NzNkM2QyMjJjMjI2MzY4NjE2OTZlNDk0NDIyM2EyMjU5MzI2ODY4NjE1NzM0M2QyMjJjMjI3NjY1NzI3MzY5NmY2ZTIyM2EzMjdk", + "signature": "bf5d14d237b951d23247e99113fa15566ebbd0dccd215b743ae9629f226ab3f9ba333622567c5606e2ed06104df52f81f05fad2488be9cb50a83e1356e0d070e", + "sourceShard": 1, + "destinationShard": 1, + "blockNonce": 7, + "blockHash": "5f2a597d07b4b5ae84195178eb6f83493bb1230c7f316b40a0d9b6efbe1a4da5", + "notarizedAtSourceInMetaNonce": 9, + "NotarizedAtSourceInMetaHash": "34cd7dc91fc9773ddd2e09d900087b96cfecf6280a6dc25a1894c2db161cded1", + "notarizedAtDestinationInMetaNonce": 9, + "notarizedAtDestinationInMetaHash": "34cd7dc91fc9773ddd2e09d900087b96cfecf6280a6dc25a1894c2db161cded1", + "miniblockType": "TxBlock", + "miniblockHash": "03ef037eb1fd03f89a9b5ece12aa422223b440cb1fd02c4a6b82d65268121d28", + "hyperblockNonce": 9, + "hyperblockHash": "34cd7dc91fc9773ddd2e09d900087b96cfecf6280a6dc25a1894c2db161cded1", + "timestamp": 1729691671, + "smartContractResults": [ + { + "hash": "6e71137c75ad162d97ce45502d38f0af96362c06f03378f03a4e50bec6ce31ea", + "nonce": 1, + "value": 299005000000000, + "receiver": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", + "sender": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", + "prevTxHash": "c825db2f9e6d17e41ed12e1aac86eecd7a828eeea0caf63a6e6a979f02a74f70", + "originalTxHash": "94cb3bd3e2dca9920115f05549c9eee4dfc1d33e4ac3edd0741eb51165148b52", + "gasLimit": 0, + "gasPrice": 1000000000, + "callType": 0, + "returnMessage": "gas refund for relayer", + "logs": { + "address": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", + "events": [ + { + "address": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", + "identifier": "completedTxEvent", + "topics": [ + "yCXbL55tF+Qe0S4arIbuzXqCju6gyvY6bmqXnwKnT3A=" + ], + "data": null, + "additionalData": null + } + ] + }, + "operation": "transfer", + "isRefund": true + }, + { + "hash": "c825db2f9e6d17e41ed12e1aac86eecd7a828eeea0caf63a6e6a979f02a74f70", + "nonce": 0, + "value": 2501000000000000000000, + "receiver": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", + "sender": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg", + "relayerAddress": "erd1tp66n2lkhs2fm7elvh9lmzfajpg480v55sd8lf2lvu4fw92zsrasvn2wze", + "relayedValue": 0, + "data": "createNewDelegationContract@00@00", + "prevTxHash": "94cb3bd3e2dca9920115f05549c9eee4dfc1d33e4ac3edd0741eb51165148b52", + "originalTxHash": "94cb3bd3e2dca9920115f05549c9eee4dfc1d33e4ac3edd0741eb51165148b52", + "gasLimit": 84900500, + "gasPrice": 1000000000, + "callType": 0, + "logs": { + "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", + "events": [ + { + "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", + "identifier": "transferValueOnly", + "topics": [ + "h5RY6SJT9AAA", + "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAL///8=" + ], + "data": "RGVwbG95U21hcnRDb250cmFjdA==", + "additionalData": [ + "RGVwbG95U21hcnRDb250cmFjdA==", + "X2luaXQ=", + "AA==", + "AA==" + ] + }, + { + "address": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg", + "identifier": "delegate", + "topics": [ + "h5RY6SJT9AAA", + "h5RY6SJT9AAA", + "AQ==", + "h5RY6SJT9AAA", + "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAL///8=" + ], + "data": null, + "additionalData": null + }, + { + "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqhllllsajxzat", + "identifier": "transferValueOnly", + "topics": [ + "h5RY6SJT9AAA", + "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAB//8=" + ], + "data": "RXhlY3V0ZU9uRGVzdENvbnRleHQ=", + "additionalData": [ + "RXhlY3V0ZU9uRGVzdENvbnRleHQ=", + "c3Rha2U=" + ] + }, + { + "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqhllllsajxzat", + "identifier": "SCDeploy", + "topics": [ + "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAL///8=", + "gco962zRiYXE44sB1svVHsHJ93dxBewevdcKu+WyU7k=", + "/uYNe6O98aIOSpF57HocNxS4JQ7FILx6+N7MEN3oAQY=" + ], + "data": null, + "additionalData": null + }, + { + "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6", + "identifier": "writeLog", + "topics": [ + "gco962zRiYXE44sB1svVHsHJ93dxBewevdcKu+WyU7k=" + ], + "data": "QDZmNmJAMDAwMDAwMDAwMDAwMDAwMDAwMDEwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMmZmZmZmZg==", + "additionalData": [ + "QDZmNmJAMDAwMDAwMDAwMDAwMDAwMDAwMDEwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMmZmZmZmZg==" + ] + } + ] + }, + "operation": "transfer", + "function": "createNewDelegationContract" + } + ], + "status": "success", + "receivers": [ + "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqylllslmq6y6" + ], + "receiversShardIDs": [ + 4294967295 + ], + "operation": "transfer", + "function": "createNewDelegationContract", + "isRelayed": true, + "chainID": "chain", + "version": 2, + "options": 0 +} diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index e0d56acbde3..ae59d6454d7 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -6,6 +6,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" 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" @@ -135,7 +136,7 @@ func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *trans feeInfo.SetFee(initialPaidFee) } - totalFee, isRelayed := tep.getFeeOfRelayed(txWithResult) + userTx, totalFee, isRelayed := tep.getFeeOfRelayed(txWithResult) isRelayedAfterFix := isRelayed && isFeeFixActive if isRelayedAfterFix { feeInfo.SetFee(totalFee) @@ -144,11 +145,16 @@ func (tep *transactionsFeeProcessor) prepareNormalTxs(transactionsAndScrs *trans } - tep.prepareTxWithResults(txHashHex, txWithResult, isRelayedAfterFix) + tep.prepareTxWithResults(txHashHex, txWithResult, userTx, epoch) } } -func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWithResults *transactionWithResults, isRelayedAfterFix bool) { +func (tep *transactionsFeeProcessor) prepareTxWithResults( + txHashHex string, + txWithResults *transactionWithResults, + userTx data.TransactionHandler, + epoch uint32, +) { hasRefund := false for _, scrHandler := range txWithResults.scrs { scr, ok := scrHandler.GetTxHandler().(*smartContractResult.SmartContractResult) @@ -157,6 +163,20 @@ func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWi } if isSCRForSenderWithRefund(scr, txHashHex, txWithResults.GetTxHandler()) || isRefundForRelayed(scr, txWithResults.GetTxHandler()) { + if !check.IfNilReflect(userTx) && tep.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, epoch) { + gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(userTx, scr.Value) + + tx := txWithResults.GetTxHandler() + gasUsedRelayedTx := tep.txFeeCalculator.ComputeGasLimit(tx) + feeRelayedTx := tep.txFeeCalculator.ComputeTxFeeBasedOnGasUsed(tx, gasUsedRelayedTx) + + txWithResults.GetFeeInfo().SetGasUsed(gasUsed + gasUsedRelayedTx) + txWithResults.GetFeeInfo().SetFee(fee.Add(fee, feeRelayedTx)) + hasRefund = true + + break + } + gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txWithResults.GetTxHandler(), scr.Value) txWithResults.GetFeeInfo().SetGasUsed(gasUsed) @@ -169,14 +189,14 @@ func (tep *transactionsFeeProcessor) prepareTxWithResults(txHashHex string, txWi tep.prepareTxWithResultsBasedOnLogs(txHashHex, txWithResults, hasRefund) } -func (tep *transactionsFeeProcessor) getFeeOfRelayed(tx *transactionWithResults) (*big.Int, bool) { +func (tep *transactionsFeeProcessor) getFeeOfRelayed(tx *transactionWithResults) (data.TransactionHandler, *big.Int, bool) { if len(tx.GetTxHandler().GetData()) == 0 { - return nil, false + return nil, nil, false } funcName, args, err := tep.argsParser.ParseCallData(string(tx.GetTxHandler().GetData())) if err != nil { - return nil, false + return nil, nil, false } if funcName == core.RelayedTransaction { @@ -187,18 +207,18 @@ func (tep *transactionsFeeProcessor) getFeeOfRelayed(tx *transactionWithResults) return tep.handleRelayedV2(args, tx) } - return nil, false + return nil, nil, false } -func (tep *transactionsFeeProcessor) handleRelayedV1(args [][]byte, tx *transactionWithResults) (*big.Int, bool) { +func (tep *transactionsFeeProcessor) handleRelayedV1(args [][]byte, tx *transactionWithResults) (data.TransactionHandler, *big.Int, bool) { if len(args) != 1 { - return nil, false + return nil, nil, false } innerTx := &transaction.Transaction{} err := tep.marshaller.Unmarshal(innerTx, args[0]) if err != nil { - return nil, false + return nil, nil, false } txHandler := tx.GetTxHandler() @@ -207,10 +227,10 @@ func (tep *transactionsFeeProcessor) handleRelayedV1(args [][]byte, tx *transact innerFee := tep.txFeeCalculator.ComputeTxFee(innerTx) - return big.NewInt(0).Add(fee, innerFee), true + return innerTx, big.NewInt(0).Add(fee, innerFee), true } -func (tep *transactionsFeeProcessor) handleRelayedV2(args [][]byte, tx *transactionWithResults) (*big.Int, bool) { +func (tep *transactionsFeeProcessor) handleRelayedV2(args [][]byte, tx *transactionWithResults) (data.TransactionHandler, *big.Int, bool) { txHandler := tx.GetTxHandler() innerTx := &transaction.Transaction{} @@ -228,7 +248,7 @@ func (tep *transactionsFeeProcessor) handleRelayedV2(args [][]byte, tx *transact innerFee := tep.txFeeCalculator.ComputeTxFee(innerTx) - return big.NewInt(0).Add(fee, innerFee), true + return innerTx, big.NewInt(0).Add(fee, innerFee), true } func (tep *transactionsFeeProcessor) prepareTxWithResultsBasedOnLogs( From 79e9f2cc236d69ff789cd7a39b28829d9460b696 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 24 Oct 2024 09:06:06 +0300 Subject: [PATCH 430/434] fixed also prepareTxWithResultsBasedOnLogs --- .../transactionsfee/transactionsFeeProcessor.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index ae59d6454d7..f1d60d0034d 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -186,7 +186,7 @@ func (tep *transactionsFeeProcessor) prepareTxWithResults( } } - tep.prepareTxWithResultsBasedOnLogs(txHashHex, txWithResults, hasRefund) + tep.prepareTxWithResultsBasedOnLogs(txHashHex, txWithResults, userTx, hasRefund, epoch) } func (tep *transactionsFeeProcessor) getFeeOfRelayed(tx *transactionWithResults) (data.TransactionHandler, *big.Int, bool) { @@ -254,7 +254,9 @@ func (tep *transactionsFeeProcessor) handleRelayedV2(args [][]byte, tx *transact func (tep *transactionsFeeProcessor) prepareTxWithResultsBasedOnLogs( txHashHex string, txWithResults *transactionWithResults, + userTx data.TransactionHandler, hasRefund bool, + epoch uint32, ) { tx := txWithResults.GetTxHandler() if check.IfNil(tx) { @@ -269,6 +271,19 @@ func (tep *transactionsFeeProcessor) prepareTxWithResultsBasedOnLogs( for _, event := range txWithResults.log.GetLogEvents() { if core.WriteLogIdentifier == string(event.GetIdentifier()) && !hasRefund { + if !check.IfNilReflect(userTx) && tep.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, epoch) { + gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(userTx, big.NewInt(0)) + + gasUsedRelayedTx := tep.txFeeCalculator.ComputeGasLimit(tx) + feeRelayedTx := tep.txFeeCalculator.ComputeTxFeeBasedOnGasUsed(tx, gasUsedRelayedTx) + + txWithResults.GetFeeInfo().SetGasUsed(gasUsed + gasUsedRelayedTx) + txWithResults.GetFeeInfo().SetFee(fee.Add(fee, feeRelayedTx)) + hasRefund = true + + break + } + gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txWithResults.GetTxHandler(), big.NewInt(0)) txWithResults.GetFeeInfo().SetGasUsed(gasUsed) txWithResults.GetFeeInfo().SetFee(fee) From 158ca36cdc80fe47ead80ec41663c2a0b362ea1b Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 24 Oct 2024 10:02:14 +0300 Subject: [PATCH 431/434] fixes after review --- .../transactionsFeeProcessor.go | 62 +++++++++++++++++-- 1 file changed, 57 insertions(+), 5 deletions(-) diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index f1d60d0034d..d94b83694bb 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -163,7 +163,7 @@ func (tep *transactionsFeeProcessor) prepareTxWithResults( } if isSCRForSenderWithRefund(scr, txHashHex, txWithResults.GetTxHandler()) || isRefundForRelayed(scr, txWithResults.GetTxHandler()) { - if !check.IfNilReflect(userTx) && tep.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, epoch) { + if !check.IfNil(userTx) && tep.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, epoch) { gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(userTx, scr.Value) tx := txWithResults.GetTxHandler() @@ -271,7 +271,7 @@ func (tep *transactionsFeeProcessor) prepareTxWithResultsBasedOnLogs( for _, event := range txWithResults.log.GetLogEvents() { if core.WriteLogIdentifier == string(event.GetIdentifier()) && !hasRefund { - if !check.IfNilReflect(userTx) && tep.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, epoch) { + if !check.IfNil(userTx) && tep.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, epoch) { gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(userTx, big.NewInt(0)) gasUsedRelayedTx := tep.txFeeCalculator.ComputeGasLimit(tx) @@ -326,10 +326,62 @@ func (tep *transactionsFeeProcessor) prepareScrsNoTx(transactionsAndScrs *transa continue } - gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txFromStorage, scr.Value) + userTx := tep.getUserTxOfRelayed(txFromStorage) + if check.IfNil(userTx) { + gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txFromStorage, scr.Value) - scrHandler.GetFeeInfo().SetGasUsed(gasUsed) - scrHandler.GetFeeInfo().SetFee(fee) + scrHandler.GetFeeInfo().SetGasUsed(gasUsed) + scrHandler.GetFeeInfo().SetFee(fee) + } else { + gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(userTx, scr.Value) + + gasUsedRelayedTx := tep.txFeeCalculator.ComputeGasLimit(txFromStorage) + feeRelayedTx := tep.txFeeCalculator.ComputeTxFeeBasedOnGasUsed(txFromStorage, gasUsedRelayedTx) + + scrHandler.GetFeeInfo().SetGasUsed(gasUsed + gasUsedRelayedTx) + scrHandler.GetFeeInfo().SetFee(fee.Add(fee, feeRelayedTx)) + } + } + + return nil +} + +func (tep *transactionsFeeProcessor) getUserTxOfRelayed(tx data.TransactionHandler) data.TransactionHandler { + if len(tx.GetData()) == 0 { + return nil + } + + funcName, args, err := tep.argsParser.ParseCallData(string(tx.GetData())) + if err != nil { + return nil + } + + if funcName == core.RelayedTransaction { + if len(args) != 1 { + return nil + } + + userTx := &transaction.Transaction{} + err := tep.marshaller.Unmarshal(userTx, args[0]) + if err != nil { + return nil + } + + return userTx + } + + if funcName == core.RelayedTransactionV2 { + userTx := &transaction.Transaction{} + userTx.RcvAddr = args[0] + userTx.Nonce = big.NewInt(0).SetBytes(args[1]).Uint64() + userTx.Data = args[2] + userTx.Signature = args[3] + userTx.Value = big.NewInt(0) + userTx.GasPrice = tx.GetGasPrice() + userTx.GasLimit = tx.GetGasLimit() - tep.txFeeCalculator.ComputeGasLimit(tx) + userTx.SndAddr = tx.GetRcvAddr() + + return userTx } return nil From 6f7ae0b36182ac3177b5e4fe1d8ba89178fb96ed Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 24 Oct 2024 11:53:56 +0300 Subject: [PATCH 432/434] fix linter --- outport/process/transactionsfee/transactionsFeeProcessor.go | 1 - 1 file changed, 1 deletion(-) diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index d94b83694bb..f66ffd3f9cf 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -279,7 +279,6 @@ func (tep *transactionsFeeProcessor) prepareTxWithResultsBasedOnLogs( txWithResults.GetFeeInfo().SetGasUsed(gasUsed + gasUsedRelayedTx) txWithResults.GetFeeInfo().SetFee(fee.Add(fee, feeRelayedTx)) - hasRefund = true break } From 895c6b2922bdfa8b18ed62903d75807bb76064a3 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 24 Oct 2024 15:40:57 +0300 Subject: [PATCH 433/434] fixes after review, removed duplicated code --- .../transactionAPI/gasUsedAndFeeProcessor.go | 15 +---- .../transactionsFeeProcessor.go | 59 ++++++++----------- 2 files changed, 26 insertions(+), 48 deletions(-) diff --git a/node/external/transactionAPI/gasUsedAndFeeProcessor.go b/node/external/transactionAPI/gasUsedAndFeeProcessor.go index 06c2c7d3bfc..c4cd9578394 100644 --- a/node/external/transactionAPI/gasUsedAndFeeProcessor.go +++ b/node/external/transactionAPI/gasUsedAndFeeProcessor.go @@ -159,20 +159,7 @@ func (gfp *gasUsedAndFeeProcessor) prepareTxWithResultsBasedOnLogs( func (gfp *gasUsedAndFeeProcessor) setGasUsedAndFeeBaseOnLogEvent(tx *transaction.ApiTransactionResult, userTx *transaction.ApiTransactionResult, hasRefund bool, event *transaction.Events) { if core.WriteLogIdentifier == event.Identifier && !hasRefund { - if !check.IfNilReflect(userTx) && gfp.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, tx.Epoch) { - gasUsed, fee := gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(userTx, big.NewInt(0)) - gasUsedRelayedTx := gfp.feeComputer.ComputeGasLimit(tx) - feeRelayedTx := gfp.feeComputer.ComputeTxFeeBasedOnGasUsed(tx, gasUsedRelayedTx) - - tx.GasUsed = gasUsed + gasUsedRelayedTx - - fee.Add(fee, feeRelayedTx) - tx.Fee = fee.String() - } else { - gasUsed, fee := gfp.feeComputer.ComputeGasUsedAndFeeBasedOnRefundValue(tx, big.NewInt(0)) - tx.GasUsed = gasUsed - tx.Fee = fee.String() - } + gfp.setGasUsedAndFeeBaseOnRefundValue(tx, userTx, big.NewInt(0)) } if core.SignalErrorOperation == event.Identifier { fee := gfp.feeComputer.ComputeTxFeeBasedOnGasUsed(tx, tx.GasLimit) diff --git a/outport/process/transactionsfee/transactionsFeeProcessor.go b/outport/process/transactionsfee/transactionsFeeProcessor.go index f66ffd3f9cf..30bcf0fca76 100644 --- a/outport/process/transactionsfee/transactionsFeeProcessor.go +++ b/outport/process/transactionsfee/transactionsFeeProcessor.go @@ -163,24 +163,7 @@ func (tep *transactionsFeeProcessor) prepareTxWithResults( } if isSCRForSenderWithRefund(scr, txHashHex, txWithResults.GetTxHandler()) || isRefundForRelayed(scr, txWithResults.GetTxHandler()) { - if !check.IfNil(userTx) && tep.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, epoch) { - gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(userTx, scr.Value) - - tx := txWithResults.GetTxHandler() - gasUsedRelayedTx := tep.txFeeCalculator.ComputeGasLimit(tx) - feeRelayedTx := tep.txFeeCalculator.ComputeTxFeeBasedOnGasUsed(tx, gasUsedRelayedTx) - - txWithResults.GetFeeInfo().SetGasUsed(gasUsed + gasUsedRelayedTx) - txWithResults.GetFeeInfo().SetFee(fee.Add(fee, feeRelayedTx)) - hasRefund = true - - break - } - - gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txWithResults.GetTxHandler(), scr.Value) - - txWithResults.GetFeeInfo().SetGasUsed(gasUsed) - txWithResults.GetFeeInfo().SetFee(fee) + tep.setGasUsedAndFeeBasedOnRefundValue(txWithResults, userTx, scr.Value, epoch) hasRefund = true break } @@ -271,22 +254,7 @@ func (tep *transactionsFeeProcessor) prepareTxWithResultsBasedOnLogs( for _, event := range txWithResults.log.GetLogEvents() { if core.WriteLogIdentifier == string(event.GetIdentifier()) && !hasRefund { - if !check.IfNil(userTx) && tep.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, epoch) { - gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(userTx, big.NewInt(0)) - - gasUsedRelayedTx := tep.txFeeCalculator.ComputeGasLimit(tx) - feeRelayedTx := tep.txFeeCalculator.ComputeTxFeeBasedOnGasUsed(tx, gasUsedRelayedTx) - - txWithResults.GetFeeInfo().SetGasUsed(gasUsed + gasUsedRelayedTx) - txWithResults.GetFeeInfo().SetFee(fee.Add(fee, feeRelayedTx)) - - break - } - - gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txWithResults.GetTxHandler(), big.NewInt(0)) - txWithResults.GetFeeInfo().SetGasUsed(gasUsed) - txWithResults.GetFeeInfo().SetFee(fee) - + tep.setGasUsedAndFeeBasedOnRefundValue(txWithResults, userTx, big.NewInt(0), epoch) continue } if core.SignalErrorOperation == string(event.GetIdentifier()) { @@ -295,7 +263,30 @@ func (tep *transactionsFeeProcessor) prepareTxWithResultsBasedOnLogs( txWithResults.GetFeeInfo().SetFee(fee) } } +} + +func (tep *transactionsFeeProcessor) setGasUsedAndFeeBasedOnRefundValue( + txWithResults *transactionWithResults, + userTx data.TransactionHandler, + refund *big.Int, + epoch uint32, +) { + if !check.IfNil(userTx) && tep.enableEpochsHandler.IsFlagEnabledInEpoch(common.FixRelayedBaseCostFlag, epoch) { + gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(userTx, refund) + + tx := txWithResults.GetTxHandler() + gasUsedRelayedTx := tep.txFeeCalculator.ComputeGasLimit(tx) + feeRelayedTx := tep.txFeeCalculator.ComputeTxFeeBasedOnGasUsed(tx, gasUsedRelayedTx) + + txWithResults.GetFeeInfo().SetGasUsed(gasUsed + gasUsedRelayedTx) + txWithResults.GetFeeInfo().SetFee(fee.Add(fee, feeRelayedTx)) + + return + } + gasUsed, fee := tep.txFeeCalculator.ComputeGasUsedAndFeeBasedOnRefundValue(txWithResults.GetTxHandler(), refund) + txWithResults.GetFeeInfo().SetGasUsed(gasUsed) + txWithResults.GetFeeInfo().SetFee(fee) } func (tep *transactionsFeeProcessor) prepareScrsNoTx(transactionsAndScrs *transactionsAndScrsHolder) error { From 32ce83e4295c2ed2ba8ee06638ed5cbeb144ab54 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 31 Oct 2024 14:27:02 +0200 Subject: [PATCH 434/434] update tags --- go.mod | 6 +++--- go.sum | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/go.mod b/go.mod index 75a2eee7f19..083ce5d42fd 100644 --- a/go.mod +++ b/go.mod @@ -14,10 +14,10 @@ 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.1.1-0.20241021133229-d0833256e3ec - github.com/multiversx/mx-chain-core-go v1.2.23-0.20241018134424-75bab2a9058c + github.com/multiversx/mx-chain-communication-go v1.1.1 + github.com/multiversx/mx-chain-core-go v1.2.23 github.com/multiversx/mx-chain-crypto-go v1.2.12 - github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018130218-f48c7282690b + github.com/multiversx/mx-chain-es-indexer-go v1.7.10 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 4de240abdf8..b7402b7c8e4 100644 --- a/go.sum +++ b/go.sum @@ -385,14 +385,14 @@ 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.1.1-0.20241021133229-d0833256e3ec h1:KwpeVZXSHzic8DV9zaJZmaBgDNIIpSdbGz4Q+9fZyiI= -github.com/multiversx/mx-chain-communication-go v1.1.1-0.20241021133229-d0833256e3ec/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= -github.com/multiversx/mx-chain-core-go v1.2.23-0.20241018134424-75bab2a9058c h1:hPCfMSj2vd9xNkARNxB1b3b9k8taFb+Xfja+WK97jno= -github.com/multiversx/mx-chain-core-go v1.2.23-0.20241018134424-75bab2a9058c/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-communication-go v1.1.1 h1:y4DoQeQOJTaSUsRzczQFazf8JYQmInddypApqA3AkwM= +github.com/multiversx/mx-chain-communication-go v1.1.1/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= +github.com/multiversx/mx-chain-core-go v1.2.23 h1:8WlCGqJHR2HQ0vN4feJwb7W4VrCwBGIzPPHunOOg5Wc= +github.com/multiversx/mx-chain-core-go v1.2.23/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4= -github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018130218-f48c7282690b h1:GYvm0yGkdQ3OCfNqnyIQNzAzydN3cES8noJZ3eZHN1A= -github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018130218-f48c7282690b/go.mod h1:oGcRK2E3Syv6vRTszWrrb/TqD8akq0yeoMr1wPPiTO4= +github.com/multiversx/mx-chain-es-indexer-go v1.7.10 h1:Umi7WN8h4BOXLw7CM3VgvaWkLGef7nXtaPIGbjBCT3U= +github.com/multiversx/mx-chain-es-indexer-go v1.7.10/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=