From 18e8d700d2bec46c3aaef4999ebc625cd24e5212 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 8 Sep 2023 15:06:17 +0300 Subject: [PATCH 001/467] 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/467] 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/467] 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/467] 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/467] 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/467] 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/467] 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/467] 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/467] 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/467] 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/467] 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/467] 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/467] 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/467] 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/467] 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 828e69da6130852d628e4a269bc8c924a4fba045 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 31 Oct 2023 11:28:01 +0200 Subject: [PATCH 016/467] 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 017/467] 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 21fd96a453d2062076919bdd427dac6d24699a38 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 13 Nov 2023 10:19:06 +0200 Subject: [PATCH 018/467] 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 019/467] 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 020/467] 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 021/467] 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 da58e7e4192b5049e4b92d5753da278949c06810 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 30 Jan 2024 11:13:01 +0200 Subject: [PATCH 022/467] 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 b4379e3b8aeb09c0de4561b5fbecbf9a731b0cbe Mon Sep 17 00:00:00 2001 From: dragosrebegea Date: Mon, 12 Feb 2024 18:13:49 +0200 Subject: [PATCH 023/467] MX-15168: MaxDelegationCap tests --- .../chainSimulator/staking/delegation_test.go | 365 +++++++++++++++++- 1 file changed, 359 insertions(+), 6 deletions(-) diff --git a/integrationTests/chainSimulator/staking/delegation_test.go b/integrationTests/chainSimulator/staking/delegation_test.go index 8bf2ca1e1d5..625d1759426 100644 --- a/integrationTests/chainSimulator/staking/delegation_test.go +++ b/integrationTests/chainSimulator/staking/delegation_test.go @@ -48,10 +48,10 @@ const maxCap = "00" // no cap const serviceFee = "0ea1" // 37.45% const walletAddressBytesLen = 32 -var stakeValue = big.NewInt(0).Mul(oneEGLD, big.NewInt(1250)) // 1250 EGLD var zeroValue = big.NewInt(0) var oneEGLD = big.NewInt(1000000000000000000) var minimumStakeValue = big.NewInt(0).Mul(oneEGLD, big.NewInt(2500)) +var minimumCreateDelegationStakeValue = big.NewInt(0).Mul(oneEGLD, big.NewInt(1250)) // Test description // Test that delegation contract created with MakeNewContractFromValidatorData works properly @@ -317,7 +317,7 @@ func testBLSKeyIsInQueueOrAuction(t *testing.T, metachainNode chainSimulatorProc require.Nil(t, err) statistics, err := metachainNode.GetFacadeHandler().ValidatorStatisticsApi() require.Nil(t, err) - assert.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, address)) + require.Zero(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, address))) activationEpoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step1Flag) if activationEpoch <= metachainNode.GetCoreComponents().EnableEpochsHandler().GetCurrentEpoch() { @@ -355,8 +355,8 @@ func testBLSKeyIsInAuction( require.Equal(t, actionListSize, len(auctionList)) if actionListSize != 0 { - require.Equal(t, 1, len(auctionList[0].Nodes)) - require.Equal(t, topUpInAuctionList.String(), auctionList[0].TopUpPerNode) + require.Equal(t, 1, len(auctionList[0].Nodes)) + require.Equal(t, topUpInAuctionList.String(), auctionList[0].TopUpPerNode) } // in staking ph 4 we should find the key in the validators statics @@ -566,6 +566,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat err = cs.SetStateMultiple(addresses) require.Nil(t, err) + stakeValue := big.NewInt(0).Set(minimumCreateDelegationStakeValue) // 1250 EGLD // Step 3: Create a new delegation contract maxDelegationCap := big.NewInt(0).Mul(oneEGLD, big.NewInt(51000)) // 51000 EGLD cap serviceFee := big.NewInt(100) // 100 as service fee @@ -678,7 +679,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Equal(t, 0, len(unStakedKeys)) // Make block finalized - err = cs.GenerateBlocks(1) + err = cs.GenerateBlocks(2) // allow the metachain to finalize the block that contains the staking of the node require.Nil(t, err) testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationContractAddressBytes, blsKeys[0], expectedTopUp, 1) @@ -697,7 +698,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) - require.Equal(t, expectedTopUp.String(), getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes).String()) + require.Zero(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes))) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator1Bytes}) require.Nil(t, err) @@ -750,6 +751,358 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Equal(t, blsKeys[0], hex.EncodeToString(unStakedKeys[0])) } +func TestChainSimulator_MaxDelegationCap(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 30, + } + + // Test scenario done in staking 3.5 phase (staking v4 is not active) + // 1. Add a new validator private key in the multi key handler + // 2. Set the initial state for the owner and the 3 delegators + // 3. Create a new delegation contract with 1250 egld + // 4. Add node to the delegation contract + // 5. Delegate from user A 1250 EGLD each, check the topup is 2500 + // 6. Delegate from user B 501 EGLD each, check it fails + // 7. Stake node, check the topup is 0, check the node is staked + // 8. Delegate from user B 501 EGLD each, check it fails + // 9. Delegate from user B 500 EGLD each, check the topup is 500 + // 10. Delegate from user B 20 EGLD each, check it fails + t.Run("staking ph 4 is not active", func(t *testing.T) { + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 + cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 + cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 102 + + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 102 + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + testChainSimulatorMaxDelegationCap(t, cs, 1) + }) + + // Test scenario done in staking v4 phase step 1 + // 1. Add a new validator private key in the multi key handler + // 2. Set the initial state for the owner and the 3 delegators + // 3. Create a new delegation contract with 1250 egld + // 4. Add node to the delegation contract + // 5. Delegate from user A 1250 EGLD each, check the topup is 2500 + // 6. Delegate from user B 501 EGLD each, check it fails + // 7. Stake node, check the topup is 0, check the node is staked, check the node is in action list + // 8. Delegate from user B 501 EGLD each, check it fails + // 9. Delegate from user B 500 EGLD each, check the topup is 500 + // 10. Delegate from user B 20 EGLD each, check it fails + t.Run("staking ph 4 step 1 is active", func(t *testing.T) { + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 + cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 + cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 4 + + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 4 + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + testChainSimulatorMaxDelegationCap(t, cs, 2) + }) + + // Test scenario done in staking v4 phase step 2 + // 1. Add a new validator private key in the multi key handler + // 2. Set the initial state for the owner and the 3 delegators + // 3. Create a new delegation contract with 1250 egld + // 4. Add node to the delegation contract + // 5. Delegate from user A 1250 EGLD each, check the topup is 2500 + // 6. Delegate from user B 501 EGLD each, check it fails + // 7. Stake node, check the topup is 0, check the node is staked, check the node is in action list + // 8. Delegate from user B 501 EGLD each, check it fails + // 9. Delegate from user B 500 EGLD each, check the topup is 500 + // 10. Delegate from user B 20 EGLD each, check it fails + t.Run("staking ph 4 step 2 is active", func(t *testing.T) { + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 + cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 + cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 4 + + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 4 + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + testChainSimulatorMaxDelegationCap(t, cs, 3) + }) + + // Test scenario done in staking v4 phase step 3 + // 1. Add a new validator private key in the multi key handler + // 2. Set the initial state for the owner and the 3 delegators + // 3. Create a new delegation contract with 1250 egld + // 4. Add node to the delegation contract + // 5. Delegate from user A 1250 EGLD each, check the topup is 2500 + // 6. Delegate from user B 501 EGLD each, check it fails + // 7. Stake node, check the topup is 0, check the node is staked, check the node is in action list + // 8. Delegate from user B 501 EGLD each, check it fails + // 9. Delegate from user B 500 EGLD each, check the topup is 500 + // 10. Delegate from user B 20 EGLD each, check it fails + t.Run("staking ph 4 step 3 is active", func(t *testing.T) { + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2 + cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3 + cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 4 + + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 4 + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + testChainSimulatorMaxDelegationCap(t, cs, 4) + }) + +} + +func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, targetEpoch int32) { + err := cs.GenerateBlocksUntilEpochIsReached(targetEpoch) + require.Nil(t, err) + metachainNode := cs.GetNodeHandler(core.MetachainShardId) + + // Create new validator owner and delegators with initial funds + validatorOwnerBytes := generateWalletAddressBytes() + validatorOwner, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(validatorOwnerBytes) + delegatorABytes := generateWalletAddressBytes() + delegatorA, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(delegatorABytes) + delegatorBBytes := generateWalletAddressBytes() + delegatorB, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(delegatorBBytes) + delegatorCBytes := generateWalletAddressBytes() + delegatorC, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(delegatorCBytes) + initialFunds := big.NewInt(0).Mul(oneEGLD, big.NewInt(10000)) // 10000 EGLD for each + addresses := []*dtos.AddressState{ + {Address: validatorOwner, Balance: initialFunds.String()}, + {Address: delegatorA, Balance: initialFunds.String()}, + {Address: delegatorB, Balance: initialFunds.String()}, + {Address: delegatorC, Balance: initialFunds.String()}, + } + err = cs.SetStateMultiple(addresses) + require.Nil(t, err) + + // Step 3: Create a new delegation contract + stakeValue := big.NewInt(0).Set(minimumCreateDelegationStakeValue) // 1250 EGLD + maxDelegationCap := big.NewInt(0).Mul(oneEGLD, big.NewInt(3000)) // 3000 EGLD cap + serviceFee := big.NewInt(100) // 100 as service fee + txCreateDelegationContract := generateTransaction(validatorOwnerBytes, 0, vm.DelegationManagerSCAddress, stakeValue, + fmt.Sprintf("createNewDelegationContract@%s@%s", hex.EncodeToString(maxDelegationCap.Bytes()), hex.EncodeToString(serviceFee.Bytes())), + gasLimitForDelegationContractCreationOperation) + createDelegationContractTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txCreateDelegationContract, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, createDelegationContractTx) + + output, err := executeQuery(cs, core.MetachainShardId, vm.DelegationManagerSCAddress, "getAllContractAddresses", nil) + require.Nil(t, err) + delegationContractAddress := output.ReturnData[0] + + // Step 2: Add validator nodes to the delegation contract + // This step requires generating BLS keys for validators, signing messages, and sending the "addNodes" transaction. + // Add checks to verify nodes are added successfully. + validatorSecretKeysBytes, blsKeys, err := chainSimulator.GenerateBlsPrivateKeys(1) + require.Nil(t, err) + err = cs.AddValidatorKeys(validatorSecretKeysBytes) + require.Nil(t, err) + + signatures := getSignatures(delegationContractAddress, validatorSecretKeysBytes) + txAddNodes := generateTransaction(validatorOwnerBytes, 1, delegationContractAddress, zeroValue, addNodesTxData(blsKeys, signatures), gasLimitForAddNodesOperation) + addNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txAddNodes, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, addNodesTx) + + expectedTopUp := big.NewInt(0).Set(stakeValue) + expectedTotalStaked := big.NewInt(0).Set(stakeValue) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) + require.Nil(t, err) + require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddress)) + + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{validatorOwnerBytes}) + require.Nil(t, err) + require.Equal(t, stakeValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + + // Step 3: Perform delegation operations + tx1delegatorA := generateTransaction(delegatorABytes, 0, delegationContractAddress, stakeValue, "delegate", gasLimitForDelegate) + delegatorATx1, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx1delegatorA, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, delegatorATx1) + + expectedTopUp = expectedTopUp.Add(expectedTopUp, stakeValue) + expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, stakeValue) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) + require.Nil(t, err) + require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddress)) + + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorABytes}) + require.Nil(t, err) + require.Equal(t, stakeValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + + delegateValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(501)) // 501 EGLD + tx1delegatorB := generateTransaction(delegatorBBytes, 0, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) + delegatorBTx1, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx1delegatorB, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, delegatorBTx1) + assert.Equal(t, delegatorBTx1.SmartContractResults[0].ReturnMessage, "total delegation cap reached") + + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) + require.Nil(t, err) + require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddress)) + + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorBBytes}) + require.Nil(t, err) + require.Zero(t, len(output.ReturnData)) + require.Equal(t, "view function works only for existing delegators", output.ReturnMessage) + + // Step 4: Perform stakeNodes + + txStakeNodes := generateTransaction(validatorOwnerBytes, 2, delegationContractAddress, zeroValue, fmt.Sprintf("stakeNodes@%s", blsKeys[0]), gasLimitForDelegate) + stakeNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStakeNodes, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, stakeNodesTx) + + expectedTopUp = expectedTopUp.Sub(expectedTopUp, stakeValue) + expectedTopUp = expectedTopUp.Sub(expectedTopUp, stakeValue) + require.Zero(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, delegationContractAddress))) + + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getAllNodeStates", nil) + require.Nil(t, err) + stakedKeys, notStakedKeys, unStakedKeys := getNodesFromContract(output.ReturnData) + require.Equal(t, 1, len(stakedKeys)) + require.Equal(t, blsKeys[0], hex.EncodeToString(stakedKeys[0])) + require.Equal(t, 0, len(notStakedKeys)) + require.Equal(t, 0, len(unStakedKeys)) + + err = cs.GenerateBlocks(50) // allow the metachain to finalize the block that contains the staking of the node + require.Nil(t, err) + + testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationContractAddress, blsKeys[0], expectedTopUp, 1) + + tx2delegatorB := generateTransaction(delegatorBBytes, 1, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) + delegatorBTx2, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx2delegatorB, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, delegatorBTx2) + assert.Equal(t, delegatorBTx2.SmartContractResults[0].ReturnMessage, "total delegation cap reached") + + // check the tx failed + + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) + require.Nil(t, err) + require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Zero(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, delegationContractAddress))) + + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorBBytes}) + require.Nil(t, err) + require.Zero(t, len(output.ReturnData)) + require.Equal(t, "view function works only for existing delegators", output.ReturnMessage) + + delegateValue = delegateValue.Sub(delegateValue, oneEGLD) // 500 EGLD + tx3delegatorB := generateTransaction(delegatorBBytes, 2, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) + delegatorBTx3, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx3delegatorB, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, delegatorBTx3) + + expectedTopUp = expectedTopUp.Add(expectedTopUp, delegateValue) + expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, delegateValue) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) + require.Nil(t, err) + require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddress)) + + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorBBytes}) + require.Nil(t, err) + require.Equal(t, delegateValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + + delegateValue = big.NewInt(0).Mul(oneEGLD, big.NewInt(20)) // 20 EGLD + txDelegate3 := generateTransaction(delegatorCBytes, 0, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) + delegatorCTx1, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate3, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, delegatorCTx1) + assert.Equal(t, delegatorBTx2.SmartContractResults[0].ReturnMessage, "total delegation cap reached") + + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) + require.Nil(t, err) + require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddress)) + + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorCBytes}) + require.Nil(t, err) + require.Zero(t, len(output.ReturnData)) + require.Equal(t, "view function works only for existing delegators", output.ReturnMessage) +} + func generateWalletAddressBytes() []byte { buff := make([]byte, walletAddressBytesLen) _, _ = rand.Read(buff) From febf7443b33efc56e2bfcae9929d720b2b826453 Mon Sep 17 00:00:00 2001 From: dragosrebegea Date: Tue, 13 Feb 2024 12:23:36 +0200 Subject: [PATCH 024/467] MX-15168: fix tests --- .../chainSimulator/staking/delegation_test.go | 47 ++++++++++++------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/integrationTests/chainSimulator/staking/delegation_test.go b/integrationTests/chainSimulator/staking/delegation_test.go index 625d1759426..70ac03a195c 100644 --- a/integrationTests/chainSimulator/staking/delegation_test.go +++ b/integrationTests/chainSimulator/staking/delegation_test.go @@ -260,7 +260,7 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi err = cs.GenerateBlocks(2) // allow the metachain to finalize the block that contains the staking of the node assert.Nil(t, err) - testBLSKeyIsInQueueOrAuction(t, metachainNode, validatorOwner.Bytes, blsKeys[0], addedStakedValue, 1) + testBLSKeyIsInQueueOrAuction(t, metachainNode, validatorOwner.Bytes, blsKeys[0], addedStakedValue) log.Info("Step 4. Execute the MakeNewContractFromValidatorData transaction and test that the key is on queue / auction list and the correct topup") txDataField = fmt.Sprintf("makeNewContractFromValidatorData@%s@%s", maxCap, serviceFee) @@ -276,7 +276,7 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi err = metachainNode.GetProcessComponents().ValidatorsProvider().ForceUpdate() require.Nil(t, err) - testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], addedStakedValue, 1) + testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], addedStakedValue) log.Info("Step 5. Execute 2 delegation operations of 100 EGLD each, check the topup is 700") delegateValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(100)) @@ -291,7 +291,7 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi require.NotNil(t, delegate2Tx) expectedTopUp := big.NewInt(0).Mul(oneEGLD, big.NewInt(700)) - testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], expectedTopUp, 1) + testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], expectedTopUp) log.Info("6. Execute 2 unDelegate operations of 100 EGLD each, check the topup is back to 500") unDelegateValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(100)) @@ -308,10 +308,10 @@ func testChainSimulatorMakeNewContractFromValidatorData(t *testing.T, cs chainSi require.NotNil(t, unDelegate2Tx) expectedTopUp = big.NewInt(0).Mul(oneEGLD, big.NewInt(500)) - testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], expectedTopUp, 1) + testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationAddress, blsKeys[0], expectedTopUp) } -func testBLSKeyIsInQueueOrAuction(t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, address []byte, blsKey string, expectedTopUp *big.Int, actionListSize int) { +func testBLSKeyIsInQueueOrAuction(t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, address []byte, blsKey string, expectedTopUp *big.Int) { decodedBLSKey, _ := hex.DecodeString(blsKey) err := metachainNode.GetProcessComponents().ValidatorsProvider().ForceUpdate() require.Nil(t, err) @@ -321,7 +321,7 @@ func testBLSKeyIsInQueueOrAuction(t *testing.T, metachainNode chainSimulatorProc activationEpoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step1Flag) if activationEpoch <= metachainNode.GetCoreComponents().EnableEpochsHandler().GetCurrentEpoch() { - testBLSKeyIsInAuction(t, metachainNode, decodedBLSKey, blsKey, expectedTopUp, actionListSize, statistics) + testBLSKeyIsInAuction(t, metachainNode, address, decodedBLSKey, blsKey, expectedTopUp, statistics) return } @@ -334,10 +334,10 @@ func testBLSKeyIsInQueueOrAuction(t *testing.T, metachainNode chainSimulatorProc func testBLSKeyIsInAuction( t *testing.T, metachainNode chainSimulatorProcess.NodeHandler, + address []byte, blsKeyBytes []byte, blsKey string, topUpInAuctionList *big.Int, - actionListSize int, validatorStatistics map[string]*validator.ValidatorStatistics, ) { require.Equal(t, stakedStatus, getBLSKeyStatus(t, metachainNode, blsKeyBytes)) @@ -347,17 +347,30 @@ func testBLSKeyIsInAuction( auctionList, err := metachainNode.GetProcessComponents().ValidatorsProvider().GetAuctionList() require.Nil(t, err) + expectedNodesInWaitingList := 1 + expectedActionListOwnersSize := 1 currentEpoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetCurrentEpoch() - if metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step2Flag) <= currentEpoch { + if currentEpoch == metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step2Flag) { // starting from phase 2, we have the shuffled out nodes from the previous epoch in the action list - actionListSize += 1 + expectedActionListOwnersSize += 1 + expectedNodesInWaitingList += 8 + } + if currentEpoch == metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step3Flag) { + // starting from phase 2, we have the shuffled out nodes from the previous epoch in the action list + expectedActionListOwnersSize += 1 + expectedNodesInWaitingList += 4 } - require.Equal(t, actionListSize, len(auctionList)) - if actionListSize != 0 { - require.Equal(t, 1, len(auctionList[0].Nodes)) - require.Equal(t, topUpInAuctionList.String(), auctionList[0].TopUpPerNode) + require.Equal(t, expectedActionListOwnersSize, len(auctionList)) + nodesInWaitingList := 0 + addressBech32 := metachainNode.GetCoreComponents().AddressPubKeyConverter().SilentEncode(address, log) + for i := 0; i < len(auctionList); i++ { + nodesInWaitingList += len(auctionList[i].Nodes) + if auctionList[i].Owner == addressBech32 { + require.Equal(t, topUpInAuctionList.String(), auctionList[i].TopUpPerNode) + } } + require.Equal(t, expectedNodesInWaitingList, nodesInWaitingList) // in staking ph 4 we should find the key in the validators statics validatorInfo, found := validatorStatistics[blsKey] @@ -682,7 +695,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat err = cs.GenerateBlocks(2) // allow the metachain to finalize the block that contains the staking of the node require.Nil(t, err) - testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationContractAddressBytes, blsKeys[0], expectedTopUp, 1) + testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationContractAddressBytes, blsKeys[0], expectedTopUp) // Step 5: Perform unDelegate from 1 user // The nodes should remain in the staked state @@ -713,7 +726,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Equal(t, 0, len(unStakedKeys)) // Step 6: Perform unDelegate from last user - // The nodes should remain in the unStaked state + // The nodes should change to unStaked state // The total active stake should be reduced by the amount undelegated txUndelegate2 := generateTransaction(delegator2Bytes, 1, delegationContractAddressBytes, zeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(stakeValue.Bytes())), gasLimitForUndelegateOperation) @@ -1045,10 +1058,10 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati require.Equal(t, 0, len(notStakedKeys)) require.Equal(t, 0, len(unStakedKeys)) - err = cs.GenerateBlocks(50) // allow the metachain to finalize the block that contains the staking of the node + err = cs.GenerateBlocks(2) // allow the metachain to finalize the block that contains the staking of the node require.Nil(t, err) - testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationContractAddress, blsKeys[0], expectedTopUp, 1) + testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationContractAddress, blsKeys[0], expectedTopUp) tx2delegatorB := generateTransaction(delegatorBBytes, 1, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) delegatorBTx2, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx2delegatorB, maxNumOfBlockToGenerateWhenExecutingTx) From 31f50f4c06316f5f9819487106f07d3e2aec06f0 Mon Sep 17 00:00:00 2001 From: dragosrebegea Date: Tue, 13 Feb 2024 17:06:22 +0200 Subject: [PATCH 025/467] MX-15168: fixes after review --- .../chainSimulator/staking/delegation_test.go | 250 ++++++++---------- 1 file changed, 113 insertions(+), 137 deletions(-) diff --git a/integrationTests/chainSimulator/staking/delegation_test.go b/integrationTests/chainSimulator/staking/delegation_test.go index f9b800dce3d..f90d1f987e2 100644 --- a/integrationTests/chainSimulator/staking/delegation_test.go +++ b/integrationTests/chainSimulator/staking/delegation_test.go @@ -1,7 +1,6 @@ package staking import ( - "crypto/rand" "encoding/hex" "fmt" "math/big" @@ -22,7 +21,6 @@ import ( "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" - "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/vm" @@ -46,7 +44,6 @@ const auctionStatus = "auction" const okReturnCode = "ok" const maxCap = "00" // no cap const serviceFee = "0ea1" // 37.45% -const walletAddressBytesLen = 32 var zeroValue = big.NewInt(0) var oneEGLD = big.NewInt(1000000000000000000) @@ -317,7 +314,7 @@ func testBLSKeyIsInQueueOrAuction(t *testing.T, metachainNode chainSimulatorProc require.Nil(t, err) statistics, err := metachainNode.GetFacadeHandler().ValidatorStatisticsApi() require.Nil(t, err) - require.Zero(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, address))) + require.True(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, address)) == 0) activationEpoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step1Flag) if activationEpoch <= metachainNode.GetCoreComponents().EnableEpochsHandler().GetCurrentEpoch() { @@ -347,30 +344,33 @@ func testBLSKeyIsInAuction( auctionList, err := metachainNode.GetProcessComponents().ValidatorsProvider().GetAuctionList() require.Nil(t, err) - expectedNodesInWaitingList := 1 - expectedActionListOwnersSize := 1 + expectedNodesInAuctionList := 1 + expectedAuctionListOwnersSize := 1 currentEpoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetCurrentEpoch() if currentEpoch == metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step2Flag) { // starting from phase 2, we have the shuffled out nodes from the previous epoch in the action list - expectedActionListOwnersSize += 1 - expectedNodesInWaitingList += 8 + expectedAuctionListOwnersSize += 1 + expectedNodesInAuctionList += 8 } - if currentEpoch == metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step3Flag) { + if currentEpoch >= metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step3Flag) { // starting from phase 2, we have the shuffled out nodes from the previous epoch in the action list - expectedActionListOwnersSize += 1 - expectedNodesInWaitingList += 4 + expectedAuctionListOwnersSize += 1 + expectedNodesInAuctionList += 4 } - require.Equal(t, expectedActionListOwnersSize, len(auctionList)) - nodesInWaitingList := 0 + require.Equal(t, expectedAuctionListOwnersSize, len(auctionList)) + nodesInAuctionList := 0 addressBech32 := metachainNode.GetCoreComponents().AddressPubKeyConverter().SilentEncode(address, log) + ownerFound := false for i := 0; i < len(auctionList); i++ { - nodesInWaitingList += len(auctionList[i].Nodes) + nodesInAuctionList += len(auctionList[i].Nodes) if auctionList[i].Owner == addressBech32 { + ownerFound = true require.Equal(t, topUpInAuctionList.String(), auctionList[i].TopUpPerNode) } } - require.Equal(t, expectedNodesInWaitingList, nodesInWaitingList) + require.True(t, ownerFound) + require.Equal(t, expectedNodesInAuctionList, nodesInAuctionList) // in staking ph 4 we should find the key in the validators statics validatorInfo, found := validatorStatistics[blsKey] @@ -563,28 +563,19 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Nil(t, err) metachainNode := cs.GetNodeHandler(core.MetachainShardId) - // Create new validator owner and delegators with initial funds - validatorOwnerBytes := generateWalletAddressBytes() - validatorOwner, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(validatorOwnerBytes) - delegator1Bytes := generateWalletAddressBytes() - delegator1, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(delegator1Bytes) - delegator2Bytes := generateWalletAddressBytes() - delegator2, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(delegator2Bytes) initialFunds := big.NewInt(0).Mul(oneEGLD, big.NewInt(10000)) // 10000 EGLD for each - addresses := []*dtos.AddressState{ - {Address: validatorOwner, Balance: initialFunds.String()}, - {Address: delegator1, Balance: initialFunds.String()}, - {Address: delegator2, Balance: initialFunds.String()}, - } - err = cs.SetStateMultiple(addresses) + validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, initialFunds) + require.Nil(t, err) + + delegator1, err := cs.GenerateAndMintWalletAddress(core.AllShardId, initialFunds) + require.Nil(t, err) + + delegator2, err := cs.GenerateAndMintWalletAddress(core.AllShardId, initialFunds) require.Nil(t, err) - stakeValue := big.NewInt(0).Set(minimumCreateDelegationStakeValue) // 1250 EGLD - // Step 3: Create a new delegation contract maxDelegationCap := big.NewInt(0).Mul(oneEGLD, big.NewInt(51000)) // 51000 EGLD cap - serviceFee := big.NewInt(100) // 100 as service fee - txCreateDelegationContract := generateTransaction(validatorOwnerBytes, 0, vm.DelegationManagerSCAddress, stakeValue, - fmt.Sprintf("createNewDelegationContract@%s@%s", hex.EncodeToString(maxDelegationCap.Bytes()), hex.EncodeToString(serviceFee.Bytes())), + txCreateDelegationContract := generateTransaction(validatorOwner.Bytes, 0, vm.DelegationManagerSCAddress, minimumCreateDelegationStakeValue, + fmt.Sprintf("createNewDelegationContract@%s@%s", hex.EncodeToString(maxDelegationCap.Bytes()), serviceFee), gasLimitForDelegationContractCreationOperation) createDelegationContractTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txCreateDelegationContract, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -615,7 +606,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Nil(t, err) signatures := getSignatures(delegationContractAddressBytes, validatorSecretKeysBytes) - txAddNodes := generateTransaction(validatorOwnerBytes, 1, delegationContractAddressBytes, zeroValue, addNodesTxData(blsKeys, signatures), gasLimitForAddNodesOperation) + txAddNodes := generateTransaction(validatorOwner.Bytes, 1, delegationContractAddressBytes, zeroValue, addNodesTxData(blsKeys, signatures), gasLimitForAddNodesOperation) addNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txAddNodes, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, addNodesTx) @@ -628,59 +619,58 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Equal(t, blsKeys[0], hex.EncodeToString(notStakedKeys[0])) require.Equal(t, 0, len(unStakedKeys)) - expectedTopUp := big.NewInt(0).Set(stakeValue) - expectedTotalStaked := big.NewInt(0).Set(stakeValue) + expectedTopUp := big.NewInt(0).Set(minimumCreateDelegationStakeValue) + expectedTotalStaked := big.NewInt(0).Set(minimumCreateDelegationStakeValue) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{validatorOwnerBytes}) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{validatorOwner.Bytes}) require.Nil(t, err) - require.Equal(t, stakeValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, minimumCreateDelegationStakeValue, big.NewInt(0).SetBytes(output.ReturnData[0])) // Step 3: Perform delegation operations - txDelegate1 := generateTransaction(delegator1Bytes, 0, delegationContractAddressBytes, stakeValue, "delegate", gasLimitForDelegate) + txDelegate1 := generateTransaction(delegator1.Bytes, 0, delegationContractAddressBytes, minimumCreateDelegationStakeValue, "delegate", gasLimitForDelegate) delegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate1, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegate1Tx) - expectedTopUp = expectedTopUp.Add(expectedTopUp, stakeValue) - expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, stakeValue) + expectedTopUp = expectedTopUp.Add(expectedTopUp, minimumCreateDelegationStakeValue) + expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, minimumCreateDelegationStakeValue) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator1Bytes}) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator1.Bytes}) require.Nil(t, err) - require.Equal(t, stakeValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, minimumCreateDelegationStakeValue, big.NewInt(0).SetBytes(output.ReturnData[0])) - txDelegate2 := generateTransaction(delegator2Bytes, 0, delegationContractAddressBytes, stakeValue, "delegate", gasLimitForDelegate) + txDelegate2 := generateTransaction(delegator2.Bytes, 0, delegationContractAddressBytes, minimumCreateDelegationStakeValue, "delegate", gasLimitForDelegate) delegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate2, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegate2Tx) - expectedTopUp = expectedTopUp.Add(expectedTopUp, stakeValue) - expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, stakeValue) + expectedTopUp = expectedTopUp.Add(expectedTopUp, minimumCreateDelegationStakeValue) + expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, minimumCreateDelegationStakeValue) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator2Bytes}) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator2.Bytes}) require.Nil(t, err) - require.Equal(t, stakeValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, minimumCreateDelegationStakeValue, big.NewInt(0).SetBytes(output.ReturnData[0])) // Step 4: Perform stakeNodes - txStakeNodes := generateTransaction(validatorOwnerBytes, 2, delegationContractAddressBytes, zeroValue, fmt.Sprintf("stakeNodes@%s", blsKeys[0]), gasLimitForStakeOperation) + txStakeNodes := generateTransaction(validatorOwner.Bytes, 2, delegationContractAddressBytes, zeroValue, fmt.Sprintf("stakeNodes@%s", blsKeys[0]), gasLimitForStakeOperation) stakeNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStakeNodes, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeNodesTx) - expectedTopUp = expectedTopUp.Sub(expectedTopUp, stakeValue) - expectedTopUp = expectedTopUp.Sub(expectedTopUp, stakeValue) + expectedTopUp = big.NewInt(0).Set(minimumCreateDelegationStakeValue) require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getAllNodeStates", nil) @@ -701,19 +691,19 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat // The nodes should remain in the staked state // The total active stake should be reduced by the amount undelegated - txUndelegate1 := generateTransaction(delegator1Bytes, 1, delegationContractAddressBytes, zeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(stakeValue.Bytes())), gasLimitForUndelegateOperation) + txUndelegate1 := generateTransaction(delegator1.Bytes, 1, delegationContractAddressBytes, zeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(minimumCreateDelegationStakeValue.Bytes())), gasLimitForUndelegateOperation) undelegate1Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUndelegate1, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, undelegate1Tx) - expectedTopUp = expectedTopUp.Sub(expectedTopUp, stakeValue) - expectedTotalStaked = expectedTotalStaked.Sub(expectedTotalStaked, stakeValue) + expectedTopUp = expectedTopUp.Sub(expectedTopUp, minimumCreateDelegationStakeValue) + expectedTotalStaked = expectedTotalStaked.Sub(expectedTotalStaked, minimumCreateDelegationStakeValue) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) - require.Zero(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes))) + require.True(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) == 0) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator1Bytes}) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator1.Bytes}) require.Nil(t, err) require.Equal(t, zeroValue, big.NewInt(0).SetBytes(output.ReturnData[0])) @@ -729,7 +719,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat // The nodes should change to unStaked state // The total active stake should be reduced by the amount undelegated - txUndelegate2 := generateTransaction(delegator2Bytes, 1, delegationContractAddressBytes, zeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(stakeValue.Bytes())), gasLimitForUndelegateOperation) + txUndelegate2 := generateTransaction(delegator2.Bytes, 1, delegationContractAddressBytes, zeroValue, fmt.Sprintf("unDelegate@%s", hex.EncodeToString(minimumCreateDelegationStakeValue.Bytes())), gasLimitForUndelegateOperation) undelegate2Tx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txUndelegate2, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, undelegate2Tx) @@ -739,7 +729,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat require.Equal(t, "1250000000000000000000", big.NewInt(0).SetBytes(output.ReturnData[0]).String()) require.Equal(t, zeroValue, getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator2Bytes}) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator2.Bytes}) require.Nil(t, err) require.Equal(t, "0", big.NewInt(0).SetBytes(output.ReturnData[0]).String()) @@ -778,14 +768,14 @@ func TestChainSimulator_MaxDelegationCap(t *testing.T) { // Test scenario done in staking 3.5 phase (staking v4 is not active) // 1. Add a new validator private key in the multi key handler // 2. Set the initial state for the owner and the 3 delegators - // 3. Create a new delegation contract with 1250 egld + // 3. Create a new delegation contract with 1250 egld and maximum delegation cap of 3000 EGLD // 4. Add node to the delegation contract - // 5. Delegate from user A 1250 EGLD each, check the topup is 2500 - // 6. Delegate from user B 501 EGLD each, check it fails + // 5. Delegate from user A 1250 EGLD, check the topup is 2500 + // 6. Delegate from user B 501 EGLD, check it fails // 7. Stake node, check the topup is 0, check the node is staked - // 8. Delegate from user B 501 EGLD each, check it fails - // 9. Delegate from user B 500 EGLD each, check the topup is 500 - // 10. Delegate from user B 20 EGLD each, check it fails + // 8. Delegate from user B 501 EGLD, check it fails + // 9. Delegate from user B 500 EGLD, check the topup is 500 + // 10. Delegate from user B 20 EGLD, check it fails t.Run("staking ph 4 is not active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ BypassTxSignatureCheck: false, @@ -819,14 +809,14 @@ func TestChainSimulator_MaxDelegationCap(t *testing.T) { // Test scenario done in staking v4 phase step 1 // 1. Add a new validator private key in the multi key handler // 2. Set the initial state for the owner and the 3 delegators - // 3. Create a new delegation contract with 1250 egld + // 3. Create a new delegation contract with 1250 egld and maximum delegation cap of 3000 EGLD // 4. Add node to the delegation contract - // 5. Delegate from user A 1250 EGLD each, check the topup is 2500 - // 6. Delegate from user B 501 EGLD each, check it fails + // 5. Delegate from user A 1250 EGLD, check the topup is 2500 + // 6. Delegate from user B 501 EGLD, check it fails // 7. Stake node, check the topup is 0, check the node is staked, check the node is in action list - // 8. Delegate from user B 501 EGLD each, check it fails - // 9. Delegate from user B 500 EGLD each, check the topup is 500 - // 10. Delegate from user B 20 EGLD each, check it fails + // 8. Delegate from user B 501 EGLD, check it fails + // 9. Delegate from user B 500 EGLD, check the topup is 500 + // 10. Delegate from user B 20 EGLD, check it fails t.Run("staking ph 4 step 1 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ BypassTxSignatureCheck: false, @@ -860,14 +850,14 @@ func TestChainSimulator_MaxDelegationCap(t *testing.T) { // Test scenario done in staking v4 phase step 2 // 1. Add a new validator private key in the multi key handler // 2. Set the initial state for the owner and the 3 delegators - // 3. Create a new delegation contract with 1250 egld + // 3. Create a new delegation contract with 1250 egld and maximum delegation cap of 3000 EGLD // 4. Add node to the delegation contract - // 5. Delegate from user A 1250 EGLD each, check the topup is 2500 - // 6. Delegate from user B 501 EGLD each, check it fails + // 5. Delegate from user A 1250 EGLD, check the topup is 2500 + // 6. Delegate from user B 501 EGLD, check it fails // 7. Stake node, check the topup is 0, check the node is staked, check the node is in action list - // 8. Delegate from user B 501 EGLD each, check it fails - // 9. Delegate from user B 500 EGLD each, check the topup is 500 - // 10. Delegate from user B 20 EGLD each, check it fails + // 8. Delegate from user B 501 EGLD, check it fails + // 9. Delegate from user B 500 EGLD, check the topup is 500 + // 10. Delegate from user B 20 EGLD, check it fails t.Run("staking ph 4 step 2 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ BypassTxSignatureCheck: false, @@ -903,12 +893,12 @@ func TestChainSimulator_MaxDelegationCap(t *testing.T) { // 2. Set the initial state for the owner and the 3 delegators // 3. Create a new delegation contract with 1250 egld // 4. Add node to the delegation contract - // 5. Delegate from user A 1250 EGLD each, check the topup is 2500 - // 6. Delegate from user B 501 EGLD each, check it fails + // 5. Delegate from user A 1250 EGLD, check the topup is 2500 + // 6. Delegate from user B 501 EGLD, check it fails // 7. Stake node, check the topup is 0, check the node is staked, check the node is in action list - // 8. Delegate from user B 501 EGLD each, check it fails - // 9. Delegate from user B 500 EGLD each, check the topup is 500 - // 10. Delegate from user B 20 EGLD each, check it fails + // 8. Delegate from user B 501 EGLD, check it fails + // 9. Delegate from user B 500 EGLD, check the topup is 500 + // 10. Delegate from user B 20 EGLD, check it fails t.Run("staking ph 4 step 3 is active", func(t *testing.T) { cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ BypassTxSignatureCheck: false, @@ -946,31 +936,24 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati require.Nil(t, err) metachainNode := cs.GetNodeHandler(core.MetachainShardId) - // Create new validator owner and delegators with initial funds - validatorOwnerBytes := generateWalletAddressBytes() - validatorOwner, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(validatorOwnerBytes) - delegatorABytes := generateWalletAddressBytes() - delegatorA, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(delegatorABytes) - delegatorBBytes := generateWalletAddressBytes() - delegatorB, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(delegatorBBytes) - delegatorCBytes := generateWalletAddressBytes() - delegatorC, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Encode(delegatorCBytes) initialFunds := big.NewInt(0).Mul(oneEGLD, big.NewInt(10000)) // 10000 EGLD for each - addresses := []*dtos.AddressState{ - {Address: validatorOwner, Balance: initialFunds.String()}, - {Address: delegatorA, Balance: initialFunds.String()}, - {Address: delegatorB, Balance: initialFunds.String()}, - {Address: delegatorC, Balance: initialFunds.String()}, - } - err = cs.SetStateMultiple(addresses) + validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, initialFunds) + require.Nil(t, err) + + delegatorA, err := cs.GenerateAndMintWalletAddress(core.AllShardId, initialFunds) + require.Nil(t, err) + + delegatorB, err := cs.GenerateAndMintWalletAddress(core.AllShardId, initialFunds) + require.Nil(t, err) + + delegatorC, err := cs.GenerateAndMintWalletAddress(core.AllShardId, initialFunds) require.Nil(t, err) // Step 3: Create a new delegation contract - stakeValue := big.NewInt(0).Set(minimumCreateDelegationStakeValue) // 1250 EGLD - maxDelegationCap := big.NewInt(0).Mul(oneEGLD, big.NewInt(3000)) // 3000 EGLD cap - serviceFee := big.NewInt(100) // 100 as service fee - txCreateDelegationContract := generateTransaction(validatorOwnerBytes, 0, vm.DelegationManagerSCAddress, stakeValue, - fmt.Sprintf("createNewDelegationContract@%s@%s", hex.EncodeToString(maxDelegationCap.Bytes()), hex.EncodeToString(serviceFee.Bytes())), + + maxDelegationCap := big.NewInt(0).Mul(oneEGLD, big.NewInt(3000)) // 3000 EGLD cap + txCreateDelegationContract := generateTransaction(validatorOwner.Bytes, 0, vm.DelegationManagerSCAddress, minimumCreateDelegationStakeValue, + fmt.Sprintf("createNewDelegationContract@%s@%s", hex.EncodeToString(maxDelegationCap.Bytes()), serviceFee), gasLimitForDelegationContractCreationOperation) createDelegationContractTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txCreateDelegationContract, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) @@ -989,66 +972,66 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati require.Nil(t, err) signatures := getSignatures(delegationContractAddress, validatorSecretKeysBytes) - txAddNodes := generateTransaction(validatorOwnerBytes, 1, delegationContractAddress, zeroValue, addNodesTxData(blsKeys, signatures), gasLimitForAddNodesOperation) + txAddNodes := generateTransaction(validatorOwner.Bytes, 1, delegationContractAddress, zeroValue, addNodesTxData(blsKeys, signatures), gasLimitForAddNodesOperation) addNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txAddNodes, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, addNodesTx) - expectedTopUp := big.NewInt(0).Set(stakeValue) - expectedTotalStaked := big.NewInt(0).Set(stakeValue) + expectedTopUp := big.NewInt(0).Set(minimumCreateDelegationStakeValue) + expectedTotalStaked := big.NewInt(0).Set(minimumCreateDelegationStakeValue) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddress)) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{validatorOwnerBytes}) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{validatorOwner.Bytes}) require.Nil(t, err) - require.Equal(t, stakeValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, minimumCreateDelegationStakeValue, big.NewInt(0).SetBytes(output.ReturnData[0])) // Step 3: Perform delegation operations - tx1delegatorA := generateTransaction(delegatorABytes, 0, delegationContractAddress, stakeValue, "delegate", gasLimitForDelegate) + tx1delegatorA := generateTransaction(delegatorA.Bytes, 0, delegationContractAddress, minimumCreateDelegationStakeValue, "delegate", gasLimitForDelegate) delegatorATx1, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx1delegatorA, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegatorATx1) - expectedTopUp = expectedTopUp.Add(expectedTopUp, stakeValue) - expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, stakeValue) + expectedTopUp = expectedTopUp.Add(expectedTopUp, minimumCreateDelegationStakeValue) + expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, minimumCreateDelegationStakeValue) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddress)) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorABytes}) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorA.Bytes}) require.Nil(t, err) - require.Equal(t, stakeValue, big.NewInt(0).SetBytes(output.ReturnData[0])) + require.Equal(t, minimumCreateDelegationStakeValue, big.NewInt(0).SetBytes(output.ReturnData[0])) delegateValue := big.NewInt(0).Mul(oneEGLD, big.NewInt(501)) // 501 EGLD - tx1delegatorB := generateTransaction(delegatorBBytes, 0, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) + tx1delegatorB := generateTransaction(delegatorB.Bytes, 0, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) delegatorBTx1, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx1delegatorB, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegatorBTx1) - assert.Equal(t, delegatorBTx1.SmartContractResults[0].ReturnMessage, "total delegation cap reached") + require.Equal(t, delegatorBTx1.SmartContractResults[0].ReturnMessage, "total delegation cap reached") output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddress)) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorBBytes}) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorB.Bytes}) require.Nil(t, err) require.Zero(t, len(output.ReturnData)) require.Equal(t, "view function works only for existing delegators", output.ReturnMessage) // Step 4: Perform stakeNodes - txStakeNodes := generateTransaction(validatorOwnerBytes, 2, delegationContractAddress, zeroValue, fmt.Sprintf("stakeNodes@%s", blsKeys[0]), gasLimitForDelegate) + txStakeNodes := generateTransaction(validatorOwner.Bytes, 2, delegationContractAddress, zeroValue, fmt.Sprintf("stakeNodes@%s", blsKeys[0]), gasLimitForDelegate) stakeNodesTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStakeNodes, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeNodesTx) - expectedTopUp = expectedTopUp.Sub(expectedTopUp, stakeValue) - expectedTopUp = expectedTopUp.Sub(expectedTopUp, stakeValue) - require.Zero(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, delegationContractAddress))) + expectedTopUp = expectedTopUp.Sub(expectedTopUp, minimumCreateDelegationStakeValue) + expectedTopUp = expectedTopUp.Sub(expectedTopUp, minimumCreateDelegationStakeValue) + require.True(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, delegationContractAddress)) == 0) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getAllNodeStates", nil) require.Nil(t, err) @@ -1063,26 +1046,26 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationContractAddress, blsKeys[0], expectedTopUp) - tx2delegatorB := generateTransaction(delegatorBBytes, 1, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) + tx2delegatorB := generateTransaction(delegatorB.Bytes, 1, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) delegatorBTx2, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx2delegatorB, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegatorBTx2) - assert.Equal(t, delegatorBTx2.SmartContractResults[0].ReturnMessage, "total delegation cap reached") + require.Equal(t, delegatorBTx2.SmartContractResults[0].ReturnMessage, "total delegation cap reached") // check the tx failed output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) - require.Zero(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, delegationContractAddress))) + require.True(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, delegationContractAddress)) == 0) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorBBytes}) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorB.Bytes}) require.Nil(t, err) require.Zero(t, len(output.ReturnData)) require.Equal(t, "view function works only for existing delegators", output.ReturnMessage) - delegateValue = delegateValue.Sub(delegateValue, oneEGLD) // 500 EGLD - tx3delegatorB := generateTransaction(delegatorBBytes, 2, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) + delegateValue = big.NewInt(0).Mul(oneEGLD, big.NewInt(500)) // 500 EGLD + tx3delegatorB := generateTransaction(delegatorB.Bytes, 2, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) delegatorBTx3, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx3delegatorB, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegatorBTx3) @@ -1094,35 +1077,28 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddress)) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorBBytes}) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorB.Bytes}) require.Nil(t, err) require.Equal(t, delegateValue, big.NewInt(0).SetBytes(output.ReturnData[0])) delegateValue = big.NewInt(0).Mul(oneEGLD, big.NewInt(20)) // 20 EGLD - txDelegate3 := generateTransaction(delegatorCBytes, 0, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) - delegatorCTx1, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txDelegate3, maxNumOfBlockToGenerateWhenExecutingTx) + tx1DelegatorC := generateTransaction(delegatorC.Bytes, 0, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) + delegatorCTx1, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx1DelegatorC, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, delegatorCTx1) - assert.Equal(t, delegatorBTx2.SmartContractResults[0].ReturnMessage, "total delegation cap reached") + require.Equal(t, delegatorBTx2.SmartContractResults[0].ReturnMessage, "total delegation cap reached") output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) require.Equal(t, expectedTopUp, getBLSTopUpValue(t, metachainNode, delegationContractAddress)) - output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorCBytes}) + output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorC.Bytes}) require.Nil(t, err) require.Zero(t, len(output.ReturnData)) require.Equal(t, "view function works only for existing delegators", output.ReturnMessage) } -func generateWalletAddressBytes() []byte { - buff := make([]byte, walletAddressBytesLen) - _, _ = rand.Read(buff) - - return buff -} - func executeQuery(cs chainSimulatorIntegrationTests.ChainSimulator, shardID uint32, scAddress []byte, funcName string, args [][]byte) (*dataVm.VMOutputApi, error) { output, _, err := cs.GetNodeHandler(shardID).GetFacadeHandler().ExecuteSCQuery(&process.SCQuery{ ScAddress: scAddress, From 679a823615f60cc123830e91c9ab34cbeea137f1 Mon Sep 17 00:00:00 2001 From: dragosrebegea Date: Tue, 13 Feb 2024 18:05:23 +0200 Subject: [PATCH 026/467] MX-15168: fixes after review --- .../chainSimulator/staking/delegation_test.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/integrationTests/chainSimulator/staking/delegation_test.go b/integrationTests/chainSimulator/staking/delegation_test.go index f90d1f987e2..62854a79e15 100644 --- a/integrationTests/chainSimulator/staking/delegation_test.go +++ b/integrationTests/chainSimulator/staking/delegation_test.go @@ -314,7 +314,7 @@ func testBLSKeyIsInQueueOrAuction(t *testing.T, metachainNode chainSimulatorProc require.Nil(t, err) statistics, err := metachainNode.GetFacadeHandler().ValidatorStatisticsApi() require.Nil(t, err) - require.True(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, address)) == 0) + require.Equal(t, expectedTopUp.String(), getBLSTopUpValue(t, metachainNode, address).String()) activationEpoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step1Flag) if activationEpoch <= metachainNode.GetCoreComponents().EnableEpochsHandler().GetCurrentEpoch() { @@ -701,7 +701,7 @@ func testChainSimulatorCreateNewDelegationContract(t *testing.T, cs chainSimulat output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) - require.True(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes)) == 0) + require.Equal(t, expectedTopUp.String(), getBLSTopUpValue(t, metachainNode, delegationContractAddressBytes).String()) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddressBytes, "getUserActiveStake", [][]byte{delegator1.Bytes}) require.Nil(t, err) @@ -1029,9 +1029,7 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati require.Nil(t, err) require.NotNil(t, stakeNodesTx) - expectedTopUp = expectedTopUp.Sub(expectedTopUp, minimumCreateDelegationStakeValue) - expectedTopUp = expectedTopUp.Sub(expectedTopUp, minimumCreateDelegationStakeValue) - require.True(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, delegationContractAddress)) == 0) + require.Equal(t, zeroValue.String(), getBLSTopUpValue(t, metachainNode, delegationContractAddress).String()) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getAllNodeStates", nil) require.Nil(t, err) @@ -1044,7 +1042,7 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati err = cs.GenerateBlocks(2) // allow the metachain to finalize the block that contains the staking of the node require.Nil(t, err) - testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationContractAddress, blsKeys[0], expectedTopUp) + testBLSKeyIsInQueueOrAuction(t, metachainNode, delegationContractAddress, blsKeys[0], zeroValue) tx2delegatorB := generateTransaction(delegatorB.Bytes, 1, delegationContractAddress, delegateValue, "delegate", gasLimitForDelegate) delegatorBTx2, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx2delegatorB, maxNumOfBlockToGenerateWhenExecutingTx) @@ -1057,7 +1055,7 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) require.Nil(t, err) require.Equal(t, expectedTotalStaked, big.NewInt(0).SetBytes(output.ReturnData[0])) - require.True(t, expectedTopUp.Cmp(getBLSTopUpValue(t, metachainNode, delegationContractAddress)) == 0) + require.Equal(t, zeroValue.String(), getBLSTopUpValue(t, metachainNode, delegationContractAddress).String()) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getUserActiveStake", [][]byte{delegatorB.Bytes}) require.Nil(t, err) @@ -1070,7 +1068,7 @@ func testChainSimulatorMaxDelegationCap(t *testing.T, cs chainSimulatorIntegrati require.Nil(t, err) require.NotNil(t, delegatorBTx3) - expectedTopUp = expectedTopUp.Add(expectedTopUp, delegateValue) + expectedTopUp = big.NewInt(0).Set(delegateValue) expectedTotalStaked = expectedTotalStaked.Add(expectedTotalStaked, delegateValue) output, err = executeQuery(cs, core.MetachainShardId, delegationContractAddress, "getTotalActiveStake", nil) require.Nil(t, err) From c593c5b55c99c234834974ceee5ca0b846070926 Mon Sep 17 00:00:00 2001 From: Rebegea Dragos-Alexandru <42241923+dragos-rebegea@users.noreply.github.com> Date: Wed, 14 Feb 2024 15:51:55 +0200 Subject: [PATCH 027/467] Update integrationTests/chainSimulator/staking/delegation_test.go Co-authored-by: mariusmihaic <82832880+mariusmihaic@users.noreply.github.com> --- integrationTests/chainSimulator/staking/delegation_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrationTests/chainSimulator/staking/delegation_test.go b/integrationTests/chainSimulator/staking/delegation_test.go index 62854a79e15..45f6e841c8a 100644 --- a/integrationTests/chainSimulator/staking/delegation_test.go +++ b/integrationTests/chainSimulator/staking/delegation_test.go @@ -348,7 +348,7 @@ func testBLSKeyIsInAuction( expectedAuctionListOwnersSize := 1 currentEpoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetCurrentEpoch() if currentEpoch == metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step2Flag) { - // starting from phase 2, we have the shuffled out nodes from the previous epoch in the action list + // starting from step 2, we have the shuffled out nodes from the previous epoch in the action list expectedAuctionListOwnersSize += 1 expectedNodesInAuctionList += 8 } From f979dc1cacefee47dfa8709c1e59e563ddba91c2 Mon Sep 17 00:00:00 2001 From: Rebegea Dragos-Alexandru <42241923+dragos-rebegea@users.noreply.github.com> Date: Wed, 14 Feb 2024 15:52:03 +0200 Subject: [PATCH 028/467] Update integrationTests/chainSimulator/staking/delegation_test.go Co-authored-by: mariusmihaic <82832880+mariusmihaic@users.noreply.github.com> --- integrationTests/chainSimulator/staking/delegation_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrationTests/chainSimulator/staking/delegation_test.go b/integrationTests/chainSimulator/staking/delegation_test.go index 45f6e841c8a..e46cf5a08a2 100644 --- a/integrationTests/chainSimulator/staking/delegation_test.go +++ b/integrationTests/chainSimulator/staking/delegation_test.go @@ -353,7 +353,7 @@ func testBLSKeyIsInAuction( expectedNodesInAuctionList += 8 } if currentEpoch >= metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step3Flag) { - // starting from phase 2, we have the shuffled out nodes from the previous epoch in the action list + // starting from step 3, we have the shuffled out nodes from the previous epoch in the action list expectedAuctionListOwnersSize += 1 expectedNodesInAuctionList += 4 } From 45dd9dba37c8711411ceb52d179a4e943dfd4e1b Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 19 Feb 2024 18:41:57 +0200 Subject: [PATCH 029/467] 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 030/467] 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 031/467] 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 2a34318133579fb6cfdb74a74bcb3821e129eba3 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 22 Mar 2024 13:46:26 +0200 Subject: [PATCH 032/467] 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 033/467] 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 56b13a8cd384359d8051c5f9d5087330f60574ae Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Wed, 3 Apr 2024 15:23:38 +0300 Subject: [PATCH 034/467] - fixed backwards compatibility problem --- vm/systemSmartContracts/eei.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/vm/systemSmartContracts/eei.go b/vm/systemSmartContracts/eei.go index 3f251a6cca4..55f554d11b0 100644 --- a/vm/systemSmartContracts/eei.go +++ b/vm/systemSmartContracts/eei.go @@ -144,8 +144,6 @@ func (host *vmContext) GetStorageFromAddress(address []byte, key []byte) []byte if value, isInMap := storageAdrMap[string(key)]; isInMap { return value } - } else { - storageAdrMap = make(map[string][]byte) } data, _, err := host.blockChainHook.GetStorageData(address, key) @@ -153,8 +151,6 @@ func (host *vmContext) GetStorageFromAddress(address []byte, key []byte) []byte return nil } - storageAdrMap[string(key)] = data - return data } From eb9bd6557424c2afc2c2c99f41eea4ab63dea7f3 Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Thu, 4 Apr 2024 15:37:32 +0300 Subject: [PATCH 035/467] fix backwards compatibility issues in legacySystemSCs --- epochStart/metachain/legacySystemSCs.go | 34 ++++++++++++++++++------- state/interface.go | 5 +++- state/validatorsInfoMap.go | 31 ++++++++++++++-------- 3 files changed, 49 insertions(+), 21 deletions(-) diff --git a/epochStart/metachain/legacySystemSCs.go b/epochStart/metachain/legacySystemSCs.go index 327a5ab88e5..c95b77547c4 100644 --- a/epochStart/metachain/legacySystemSCs.go +++ b/epochStart/metachain/legacySystemSCs.go @@ -14,6 +14,8 @@ import ( "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/marshal" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/errChan" vInfo "github.com/multiversx/mx-chain-go/common/validatorInfo" @@ -24,7 +26,6 @@ import ( "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/vm" "github.com/multiversx/mx-chain-go/vm/systemSmartContracts" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) type legacySystemSCProcessor struct { @@ -288,9 +289,10 @@ func (s *legacySystemSCProcessor) unStakeNodesWithNotEnoughFunds( continue } + stakingV4Enabled := s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) validatorLeaving := validatorInfo.ShallowClone() - validatorLeaving.SetListAndIndex(string(common.LeavingList), validatorLeaving.GetIndex(), s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag)) - err = validatorsInfoMap.Replace(validatorInfo, validatorLeaving) + validatorLeaving.SetListAndIndex(string(common.LeavingList), validatorLeaving.GetIndex(), stakingV4Enabled) + err = s.replaceValidators(validatorInfo, validatorLeaving, validatorsInfoMap) if err != nil { return 0, err } @@ -302,7 +304,9 @@ func (s *legacySystemSCProcessor) unStakeNodesWithNotEnoughFunds( } nodesToStakeFromQueue := uint32(len(nodesToUnStake)) - nodesToStakeFromQueue -= nodesUnStakedFromAdditionalQueue + if s.enableEpochsHandler.IsFlagEnabled(common.CorrectLastUnJailedFlag) { + nodesToStakeFromQueue -= nodesUnStakedFromAdditionalQueue + } log.Debug("stake nodes from waiting list", "num", nodesToStakeFromQueue) return nodesToStakeFromQueue, nil @@ -720,10 +724,8 @@ func (s *legacySystemSCProcessor) stakingToValidatorStatistics( } if !isNew { - err = validatorsInfoMap.Delete(jailedValidator) - if err != nil { - return nil, err - } + // the new validator is deleted from the staking queue, not the jailed validator + validatorsInfoMap.DeleteKey(blsPubKey, account.GetShardId()) } account.SetListAndIndex(jailedValidator.GetShardId(), string(common.NewList), uint32(stakingData.StakedNonce), s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag)) @@ -752,7 +754,7 @@ func (s *legacySystemSCProcessor) stakingToValidatorStatistics( } newValidatorInfo := s.validatorInfoCreator.PeerAccountToValidatorInfo(account) - err = validatorsInfoMap.Replace(jailedValidator, newValidatorInfo) + err = s.replaceValidators(jailedValidator, newValidatorInfo, validatorsInfoMap) if err != nil { return nil, err } @@ -760,6 +762,20 @@ func (s *legacySystemSCProcessor) stakingToValidatorStatistics( return blsPubKey, nil } +func (s *legacySystemSCProcessor) replaceValidators( + old state.ValidatorInfoHandler, + new state.ValidatorInfoHandler, + validatorsInfoMap state.ShardValidatorsInfoMapHandler, +) error { + stakingV4Enabled := s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) + if stakingV4Enabled { + return validatorsInfoMap.Replace(old, new) + } + + validatorsInfoMap.ReplaceValidatorByKey(old.GetPublicKey(), new, old.GetShardId()) + return nil +} + func isValidator(validator state.ValidatorInfoHandler) bool { return validator.GetList() == string(common.WaitingList) || validator.GetList() == string(common.EligibleList) } diff --git a/state/interface.go b/state/interface.go index bf515803346..59275bb0e57 100644 --- a/state/interface.go +++ b/state/interface.go @@ -6,8 +6,9 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/api" - "github.com/multiversx/mx-chain-go/common" vmcommon "github.com/multiversx/mx-chain-vm-common-go" + + "github.com/multiversx/mx-chain-go/common" ) // AccountFactory creates an account of different types @@ -292,7 +293,9 @@ type ShardValidatorsInfoMapHandler interface { Add(validator ValidatorInfoHandler) error Delete(validator ValidatorInfoHandler) error + DeleteKey(blsKey []byte, shardID uint32) Replace(old ValidatorInfoHandler, new ValidatorInfoHandler) error + ReplaceValidatorByKey(oldBlsKey []byte, new ValidatorInfoHandler, shardID uint32) SetValidatorsInShard(shardID uint32, validators []ValidatorInfoHandler) error } diff --git a/state/validatorsInfoMap.go b/state/validatorsInfoMap.go index e6c492d9d39..80199d45e6a 100644 --- a/state/validatorsInfoMap.go +++ b/state/validatorsInfoMap.go @@ -106,21 +106,26 @@ func (vi *shardValidatorsInfoMap) Replace(old ValidatorInfoHandler, new Validato "with new validator", hex.EncodeToString(new.GetPublicKey()), "shard", new.GetShardId(), "list", new.GetList(), ) + vi.ReplaceValidatorByKey(old.GetPublicKey(), new, shardID) + + return fmt.Errorf("old %w: %s when trying to replace it with %s", + ErrValidatorNotFound, + hex.EncodeToString(old.GetPublicKey()), + hex.EncodeToString(new.GetPublicKey()), + ) +} + +// ReplaceValidatorByKey will replace an existing ValidatorInfoHandler with a new one, based on the provided blsKey for the old record. +func (vi *shardValidatorsInfoMap) ReplaceValidatorByKey(oldBlsKey []byte, new ValidatorInfoHandler, shardID uint32) { vi.mutex.Lock() defer vi.mutex.Unlock() for idx, validator := range vi.valInfoMap[shardID] { - if bytes.Equal(validator.GetPublicKey(), old.GetPublicKey()) { + if bytes.Equal(validator.GetPublicKey(), oldBlsKey) { vi.valInfoMap[shardID][idx] = new - return nil + break } } - - return fmt.Errorf("old %w: %s when trying to replace it with %s", - ErrValidatorNotFound, - hex.EncodeToString(old.GetPublicKey()), - hex.EncodeToString(new.GetPublicKey()), - ) } // SetValidatorsInShard resets all validators saved in a specific shard with the provided []ValidatorInfoHandler. @@ -160,11 +165,17 @@ func (vi *shardValidatorsInfoMap) Delete(validator ValidatorInfoHandler) error { } shardID := validator.GetShardId() + vi.DeleteKey(validator.GetPublicKey(), shardID) + return nil +} + +// DeleteKey will delete the provided blsKey from the internally stored map, if found. +func (vi *shardValidatorsInfoMap) DeleteKey(blsKey []byte, shardID uint32) { vi.mutex.Lock() defer vi.mutex.Unlock() for index, validatorInfo := range vi.valInfoMap[shardID] { - if bytes.Equal(validatorInfo.GetPublicKey(), validator.GetPublicKey()) { + if bytes.Equal(validatorInfo.GetPublicKey(), blsKey) { length := len(vi.valInfoMap[shardID]) vi.valInfoMap[shardID][index] = vi.valInfoMap[shardID][length-1] vi.valInfoMap[shardID][length-1] = nil @@ -172,6 +183,4 @@ func (vi *shardValidatorsInfoMap) Delete(validator ValidatorInfoHandler) error { break } } - - return nil } From 4a4000fca3d6cb729b4cf784f82de6df7a83892b Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Thu, 4 Apr 2024 16:03:30 +0300 Subject: [PATCH 036/467] only return error if not replaced --- epochStart/metachain/legacySystemSCs.go | 2 +- state/interface.go | 2 +- state/validatorsInfoMap.go | 10 +++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/epochStart/metachain/legacySystemSCs.go b/epochStart/metachain/legacySystemSCs.go index c95b77547c4..4173a3cfc59 100644 --- a/epochStart/metachain/legacySystemSCs.go +++ b/epochStart/metachain/legacySystemSCs.go @@ -772,7 +772,7 @@ func (s *legacySystemSCProcessor) replaceValidators( return validatorsInfoMap.Replace(old, new) } - validatorsInfoMap.ReplaceValidatorByKey(old.GetPublicKey(), new, old.GetShardId()) + _ = validatorsInfoMap.ReplaceValidatorByKey(old.GetPublicKey(), new, old.GetShardId()) return nil } diff --git a/state/interface.go b/state/interface.go index 59275bb0e57..842260cff28 100644 --- a/state/interface.go +++ b/state/interface.go @@ -295,7 +295,7 @@ type ShardValidatorsInfoMapHandler interface { Delete(validator ValidatorInfoHandler) error DeleteKey(blsKey []byte, shardID uint32) Replace(old ValidatorInfoHandler, new ValidatorInfoHandler) error - ReplaceValidatorByKey(oldBlsKey []byte, new ValidatorInfoHandler, shardID uint32) + ReplaceValidatorByKey(oldBlsKey []byte, new ValidatorInfoHandler, shardID uint32) bool SetValidatorsInShard(shardID uint32, validators []ValidatorInfoHandler) error } diff --git a/state/validatorsInfoMap.go b/state/validatorsInfoMap.go index 80199d45e6a..76e543c4394 100644 --- a/state/validatorsInfoMap.go +++ b/state/validatorsInfoMap.go @@ -106,7 +106,10 @@ func (vi *shardValidatorsInfoMap) Replace(old ValidatorInfoHandler, new Validato "with new validator", hex.EncodeToString(new.GetPublicKey()), "shard", new.GetShardId(), "list", new.GetList(), ) - vi.ReplaceValidatorByKey(old.GetPublicKey(), new, shardID) + found := vi.ReplaceValidatorByKey(old.GetPublicKey(), new, shardID) + if found { + return nil + } return fmt.Errorf("old %w: %s when trying to replace it with %s", ErrValidatorNotFound, @@ -116,16 +119,17 @@ func (vi *shardValidatorsInfoMap) Replace(old ValidatorInfoHandler, new Validato } // ReplaceValidatorByKey will replace an existing ValidatorInfoHandler with a new one, based on the provided blsKey for the old record. -func (vi *shardValidatorsInfoMap) ReplaceValidatorByKey(oldBlsKey []byte, new ValidatorInfoHandler, shardID uint32) { +func (vi *shardValidatorsInfoMap) ReplaceValidatorByKey(oldBlsKey []byte, new ValidatorInfoHandler, shardID uint32) bool { vi.mutex.Lock() defer vi.mutex.Unlock() for idx, validator := range vi.valInfoMap[shardID] { if bytes.Equal(validator.GetPublicKey(), oldBlsKey) { vi.valInfoMap[shardID][idx] = new - break + return true } } + return false } // SetValidatorsInShard resets all validators saved in a specific shard with the provided []ValidatorInfoHandler. From e932f1b3386e00a15107bd58519f328062a43432 Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Thu, 4 Apr 2024 16:07:39 +0300 Subject: [PATCH 037/467] rename local variable --- state/validatorsInfoMap.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/state/validatorsInfoMap.go b/state/validatorsInfoMap.go index 76e543c4394..d72d1b17996 100644 --- a/state/validatorsInfoMap.go +++ b/state/validatorsInfoMap.go @@ -106,8 +106,8 @@ func (vi *shardValidatorsInfoMap) Replace(old ValidatorInfoHandler, new Validato "with new validator", hex.EncodeToString(new.GetPublicKey()), "shard", new.GetShardId(), "list", new.GetList(), ) - found := vi.ReplaceValidatorByKey(old.GetPublicKey(), new, shardID) - if found { + replaced := vi.ReplaceValidatorByKey(old.GetPublicKey(), new, shardID) + if replaced { return nil } From 760a76735951c1d55a9f033cace5b415ec312a08 Mon Sep 17 00:00:00 2001 From: MariusC Date: Mon, 8 Apr 2024 16:14:17 +0300 Subject: [PATCH 038/467] FIX: Possible backwards incompatibilities fixes --- epochStart/metachain/legacySystemSCs.go | 28 ++++++++++++++++++------- epochStart/metachain/systemSCs_test.go | 4 ++++ state/interface.go | 1 + state/validatorsInfoMap.go | 8 +++++++ 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/epochStart/metachain/legacySystemSCs.go b/epochStart/metachain/legacySystemSCs.go index 4173a3cfc59..6b434eb209e 100644 --- a/epochStart/metachain/legacySystemSCs.go +++ b/epochStart/metachain/legacySystemSCs.go @@ -432,7 +432,7 @@ func (s *legacySystemSCProcessor) fillStakingDataForNonEligible(validatorsInfoMa } if deleteCalled { - err := validatorsInfoMap.SetValidatorsInShard(shId, newList) + err := s.setValidatorsInShard(validatorsInfoMap, shId, newList) if err != nil { return err } @@ -442,6 +442,19 @@ func (s *legacySystemSCProcessor) fillStakingDataForNonEligible(validatorsInfoMa return nil } +func (s *legacySystemSCProcessor) setValidatorsInShard( + validatorsInfoMap state.ShardValidatorsInfoMapHandler, + shardID uint32, + validators []state.ValidatorInfoHandler, +) error { + if s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) { + return validatorsInfoMap.SetValidatorsInShard(shardID, validators) + } + + validatorsInfoMap.SetValidatorsInShardUnsafe(shardID, validators) + return nil +} + func (s *legacySystemSCProcessor) prepareStakingDataForEligibleNodes(validatorsInfoMap state.ShardValidatorsInfoMapHandler) error { eligibleNodes, err := getEligibleNodeKeys(validatorsInfoMap) if err != nil { @@ -589,6 +602,12 @@ func (s *legacySystemSCProcessor) updateMaxNodes(validatorsInfoMap state.ShardVa return err } + if !s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) { + if maxNumberOfNodes < prevMaxNumberOfNodes { + return epochStart.ErrInvalidMaxNumberOfNodes + } + } + if s.enableEpochsHandler.IsFlagEnabled(common.StakingQueueFlag) { sw.Start("stakeNodesFromQueue") err = s.stakeNodesFromQueue(validatorsInfoMap, maxNumberOfNodes-prevMaxNumberOfNodes, nonce, common.NewList) @@ -1223,11 +1242,6 @@ func (s *legacySystemSCProcessor) addNewlyStakedNodesToValidatorTrie( return err } - err = peerAcc.SetBLSPublicKey(blsKey) - if err != nil { - return err - } - peerAcc.SetListAndIndex(peerAcc.GetShardId(), string(list), uint32(nonce), s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag)) peerAcc.SetTempRating(s.startRating) peerAcc.SetUnStakedEpoch(common.DefaultUnstakedEpoch) @@ -1281,7 +1295,7 @@ func (s *legacySystemSCProcessor) extractConfigFromESDTContract() ([][]byte, err CallerAddr: s.endOfEpochCallerAddress, Arguments: [][]byte{}, CallValue: big.NewInt(0), - GasProvided: math.MaxUint64, + GasProvided: math.MaxInt64, }, Function: "getContractConfig", RecipientAddr: vm.ESDTSCAddress, diff --git a/epochStart/metachain/systemSCs_test.go b/epochStart/metachain/systemSCs_test.go index 7826c461d36..0dc9eb82b23 100644 --- a/epochStart/metachain/systemSCs_test.go +++ b/epochStart/metachain/systemSCs_test.go @@ -2326,6 +2326,10 @@ func TestSystemSCProcessor_LegacyEpochConfirmedCorrectMaxNumNodesAfterNodeRestar args.EpochNotifier.CheckEpoch(&block.Header{Epoch: 6, Nonce: 6}) require.True(t, s.flagChangeMaxNodesEnabled.IsSet()) err = s.processLegacy(validatorsInfoMap, 6, 6) + require.Equal(t, epochStart.ErrInvalidMaxNumberOfNodes, err) + + args.EnableEpochsHandler.(*enableEpochsHandlerMock.EnableEpochsHandlerStub).AddActiveFlags(common.StakingV4StartedFlag) + err = s.processLegacy(validatorsInfoMap, 6, 6) require.Nil(t, err) require.Equal(t, nodesConfigEpoch6.MaxNumNodes, s.maxNodes) diff --git a/state/interface.go b/state/interface.go index 842260cff28..6a6c098ade5 100644 --- a/state/interface.go +++ b/state/interface.go @@ -297,6 +297,7 @@ type ShardValidatorsInfoMapHandler interface { Replace(old ValidatorInfoHandler, new ValidatorInfoHandler) error ReplaceValidatorByKey(oldBlsKey []byte, new ValidatorInfoHandler, shardID uint32) bool SetValidatorsInShard(shardID uint32, validators []ValidatorInfoHandler) error + SetValidatorsInShardUnsafe(shardID uint32, validators []ValidatorInfoHandler) } // ValidatorInfoHandler defines which data shall a validator info hold. diff --git a/state/validatorsInfoMap.go b/state/validatorsInfoMap.go index d72d1b17996..27100745e02 100644 --- a/state/validatorsInfoMap.go +++ b/state/validatorsInfoMap.go @@ -161,6 +161,14 @@ func (vi *shardValidatorsInfoMap) SetValidatorsInShard(shardID uint32, validator return nil } +// SetValidatorsInShardUnsafe resets all validators saved in a specific shard with the provided ones. +// It does not check that provided validators are in the same shard as provided shard id. +func (vi *shardValidatorsInfoMap) SetValidatorsInShardUnsafe(shardID uint32, validators []ValidatorInfoHandler) { + vi.mutex.Lock() + vi.valInfoMap[shardID] = validators + vi.mutex.Unlock() +} + // Delete will delete the provided validator from the internally stored map, if found. // The validators slice at the corresponding shardID key will be re-sliced, without reordering func (vi *shardValidatorsInfoMap) Delete(validator ValidatorInfoHandler) error { From df4da690356735b9d80dd01415ef22b26e13d81c Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Wed, 10 Apr 2024 14:26:59 +0300 Subject: [PATCH 039/467] fixes after review --- epochStart/metachain/legacySystemSCs.go | 10 +++------- state/interface.go | 2 +- state/validatorsInfoMap.go | 6 +++--- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/epochStart/metachain/legacySystemSCs.go b/epochStart/metachain/legacySystemSCs.go index 4173a3cfc59..02107c1c950 100644 --- a/epochStart/metachain/legacySystemSCs.go +++ b/epochStart/metachain/legacySystemSCs.go @@ -293,9 +293,7 @@ func (s *legacySystemSCProcessor) unStakeNodesWithNotEnoughFunds( validatorLeaving := validatorInfo.ShallowClone() validatorLeaving.SetListAndIndex(string(common.LeavingList), validatorLeaving.GetIndex(), stakingV4Enabled) err = s.replaceValidators(validatorInfo, validatorLeaving, validatorsInfoMap) - if err != nil { - return 0, err - } + log.LogIfError(err) } err = s.updateDelegationContracts(mapOwnersKeys) @@ -725,7 +723,7 @@ func (s *legacySystemSCProcessor) stakingToValidatorStatistics( if !isNew { // the new validator is deleted from the staking queue, not the jailed validator - validatorsInfoMap.DeleteKey(blsPubKey, account.GetShardId()) + validatorsInfoMap.DeleteByKey(blsPubKey, account.GetShardId()) } account.SetListAndIndex(jailedValidator.GetShardId(), string(common.NewList), uint32(stakingData.StakedNonce), s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag)) @@ -755,9 +753,7 @@ func (s *legacySystemSCProcessor) stakingToValidatorStatistics( newValidatorInfo := s.validatorInfoCreator.PeerAccountToValidatorInfo(account) err = s.replaceValidators(jailedValidator, newValidatorInfo, validatorsInfoMap) - if err != nil { - return nil, err - } + log.LogIfError(err) return blsPubKey, nil } diff --git a/state/interface.go b/state/interface.go index 842260cff28..8a8c18a18c7 100644 --- a/state/interface.go +++ b/state/interface.go @@ -293,7 +293,7 @@ type ShardValidatorsInfoMapHandler interface { Add(validator ValidatorInfoHandler) error Delete(validator ValidatorInfoHandler) error - DeleteKey(blsKey []byte, shardID uint32) + DeleteByKey(blsKey []byte, shardID uint32) Replace(old ValidatorInfoHandler, new ValidatorInfoHandler) error ReplaceValidatorByKey(oldBlsKey []byte, new ValidatorInfoHandler, shardID uint32) bool SetValidatorsInShard(shardID uint32, validators []ValidatorInfoHandler) error diff --git a/state/validatorsInfoMap.go b/state/validatorsInfoMap.go index d72d1b17996..9069bf4a01d 100644 --- a/state/validatorsInfoMap.go +++ b/state/validatorsInfoMap.go @@ -169,12 +169,12 @@ func (vi *shardValidatorsInfoMap) Delete(validator ValidatorInfoHandler) error { } shardID := validator.GetShardId() - vi.DeleteKey(validator.GetPublicKey(), shardID) + vi.DeleteByKey(validator.GetPublicKey(), shardID) return nil } -// DeleteKey will delete the provided blsKey from the internally stored map, if found. -func (vi *shardValidatorsInfoMap) DeleteKey(blsKey []byte, shardID uint32) { +// DeleteByKey will delete the provided blsKey from the internally stored map, if found. +func (vi *shardValidatorsInfoMap) DeleteByKey(blsKey []byte, shardID uint32) { vi.mutex.Lock() defer vi.mutex.Unlock() From c655353a7298c99e2d4800c4d7c02ab9c81b53bf Mon Sep 17 00:00:00 2001 From: MariusC Date: Thu, 11 Apr 2024 10:53:18 +0300 Subject: [PATCH 040/467] FEAT: Extra safety measure checks --- epochStart/metachain/legacySystemSCs.go | 40 ++++++++++++++----------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/epochStart/metachain/legacySystemSCs.go b/epochStart/metachain/legacySystemSCs.go index aa9ff71c3fe..3247cb2dff1 100644 --- a/epochStart/metachain/legacySystemSCs.go +++ b/epochStart/metachain/legacySystemSCs.go @@ -292,8 +292,7 @@ func (s *legacySystemSCProcessor) unStakeNodesWithNotEnoughFunds( stakingV4Enabled := s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) validatorLeaving := validatorInfo.ShallowClone() validatorLeaving.SetListAndIndex(string(common.LeavingList), validatorLeaving.GetIndex(), stakingV4Enabled) - err = s.replaceValidators(validatorInfo, validatorLeaving, validatorsInfoMap) - log.LogIfError(err) + s.replaceValidators(validatorInfo, validatorLeaving, validatorsInfoMap) } err = s.updateDelegationContracts(mapOwnersKeys) @@ -430,10 +429,7 @@ func (s *legacySystemSCProcessor) fillStakingDataForNonEligible(validatorsInfoMa } if deleteCalled { - err := s.setValidatorsInShard(validatorsInfoMap, shId, newList) - if err != nil { - return err - } + s.setValidatorsInShard(validatorsInfoMap, shId, newList) } } @@ -444,13 +440,15 @@ func (s *legacySystemSCProcessor) setValidatorsInShard( validatorsInfoMap state.ShardValidatorsInfoMapHandler, shardID uint32, validators []state.ValidatorInfoHandler, -) error { - if s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) { - return validatorsInfoMap.SetValidatorsInShard(shardID, validators) +) { + err := validatorsInfoMap.SetValidatorsInShard(shardID, validators) + if err == nil { + return } + // this should never happen, but replace them anyway, as in old legacy code + log.Error("legacySystemSCProcessor.setValidatorsInShard", "error", err) validatorsInfoMap.SetValidatorsInShardUnsafe(shardID, validators) - return nil } func (s *legacySystemSCProcessor) prepareStakingDataForEligibleNodes(validatorsInfoMap state.ShardValidatorsInfoMapHandler) error { @@ -771,8 +769,7 @@ func (s *legacySystemSCProcessor) stakingToValidatorStatistics( } newValidatorInfo := s.validatorInfoCreator.PeerAccountToValidatorInfo(account) - err = s.replaceValidators(jailedValidator, newValidatorInfo, validatorsInfoMap) - log.LogIfError(err) + s.replaceValidators(jailedValidator, newValidatorInfo, validatorsInfoMap) return blsPubKey, nil } @@ -781,14 +778,21 @@ func (s *legacySystemSCProcessor) replaceValidators( old state.ValidatorInfoHandler, new state.ValidatorInfoHandler, validatorsInfoMap state.ShardValidatorsInfoMapHandler, -) error { - stakingV4Enabled := s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) - if stakingV4Enabled { - return validatorsInfoMap.Replace(old, new) +) { + // legacy code + if !s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) { + _ = validatorsInfoMap.ReplaceValidatorByKey(old.GetPublicKey(), new, old.GetShardId()) + return } - _ = validatorsInfoMap.ReplaceValidatorByKey(old.GetPublicKey(), new, old.GetShardId()) - return nil + // try with new code which does extra validity checks. + // if this also fails, do legacy code + if err := validatorsInfoMap.Replace(old, new); err != nil { + log.Error("legacySystemSCProcessor.replaceValidators", "error", err) + + replaced := validatorsInfoMap.ReplaceValidatorByKey(old.GetPublicKey(), new, old.GetShardId()) + log.Debug("legacySystemSCProcessor.replaceValidators", "old", old.GetPublicKey(), "new", new.GetPublicKey(), "was replace successful", replaced) + } } func isValidator(validator state.ValidatorInfoHandler) bool { From e9c876a35df758403ca5583d37b18e27d4e5ec7f Mon Sep 17 00:00:00 2001 From: MariusC Date: Thu, 11 Apr 2024 13:18:31 +0300 Subject: [PATCH 041/467] FEAT: Distribute to waiting from auction based on leaving nodes --- epochStart/dtos.go | 7 +++ epochStart/interface.go | 1 + epochStart/metachain/auctionListSelector.go | 37 ++++++++++++- epochStart/metachain/stakingDataProvider.go | 54 +++++++++++++++++++ .../stakingcommon/stakingDataProviderStub.go | 8 +++ 5 files changed, 106 insertions(+), 1 deletion(-) diff --git a/epochStart/dtos.go b/epochStart/dtos.go index ea5aa95f626..ecac1a4217f 100644 --- a/epochStart/dtos.go +++ b/epochStart/dtos.go @@ -15,3 +15,10 @@ type OwnerData struct { AuctionList []state.ValidatorInfoHandler Qualified bool } + +// ValidatorStatsInEpoch holds validator stats in an epoch +type ValidatorStatsInEpoch struct { + Eligible map[uint32]int + Waiting map[uint32]int + Leaving map[uint32]int +} diff --git a/epochStart/interface.go b/epochStart/interface.go index 06f04c11117..37df49df292 100644 --- a/epochStart/interface.go +++ b/epochStart/interface.go @@ -159,6 +159,7 @@ type StakingDataProvider interface { ComputeUnQualifiedNodes(validatorInfos state.ShardValidatorsInfoMapHandler) ([][]byte, map[string][][]byte, error) GetBlsKeyOwner(blsKey []byte) (string, error) GetNumOfValidatorsInCurrentEpoch() uint32 + GetCurrentEpochValidatorStats() ValidatorStatsInEpoch GetOwnersData() map[string]*OwnerData Clean() IsInterfaceNil() bool diff --git a/epochStart/metachain/auctionListSelector.go b/epochStart/metachain/auctionListSelector.go index 4b7c353a180..9d77a4f8bb6 100644 --- a/epochStart/metachain/auctionListSelector.go +++ b/epochStart/metachain/auctionListSelector.go @@ -198,7 +198,7 @@ func (als *auctionListSelector) SelectNodesFromAuctionList( currNodesConfig := als.nodesConfigProvider.GetCurrentNodesConfig() currNumOfValidators := als.stakingDataProvider.GetNumOfValidatorsInCurrentEpoch() - numOfShuffledNodes := currNodesConfig.NodesToShufflePerShard * (als.shardCoordinator.NumberOfShards() + 1) + numOfShuffledNodes := als.computeNumShuffledNodes(currNodesConfig) numOfValidatorsAfterShuffling, err := safeSub(currNumOfValidators, numOfShuffledNodes) if err != nil { log.Warn(fmt.Sprintf("auctionListSelector.SelectNodesFromAuctionList: %v when trying to compute numOfValidatorsAfterShuffling = %v - %v (currNumOfValidators - numOfShuffledNodes)", @@ -272,6 +272,41 @@ func isInAuction(validator state.ValidatorInfoHandler) bool { return validator.GetList() == string(common.AuctionList) } +func (als *auctionListSelector) computeNumShuffledNodes(currNodesConfig config.MaxNodesChangeConfig) uint32 { + numNodesToShufflePerShard := currNodesConfig.NodesToShufflePerShard + numShuffledOut := numNodesToShufflePerShard * (als.shardCoordinator.NumberOfShards() + 1) + epochStats := als.stakingDataProvider.GetCurrentEpochValidatorStats() + + actuallyNumLeaving := uint32(0) + for shardID := uint32(0); shardID < als.shardCoordinator.NumberOfShards(); shardID++ { + actuallyNumLeaving += computeActuallyNumLeaving(shardID, epochStats, numNodesToShufflePerShard) + } + + actuallyNumLeaving += computeActuallyNumLeaving(core.MetachainShardId, epochStats, numNodesToShufflePerShard) + + finalShuffledOut, err := safeSub(numShuffledOut, actuallyNumLeaving) + if err != nil { + log.Error("auctionListSelector.computeNumShuffledNodes", "error", err) + return numShuffledOut + } + + return finalShuffledOut +} + +func computeActuallyNumLeaving(shardID uint32, epochStats epochStart.ValidatorStatsInEpoch, numNodesToShuffledPerShard uint32) uint32 { + numLeavingInShard := uint32(epochStats.Leaving[shardID]) + numActiveInShard := uint32(epochStats.Waiting[shardID] + epochStats.Eligible[shardID]) + + log.Debug("auctionListSelector.computeActuallyNumLeaving", + "shardID", shardID, "numLeavingInShard", numLeavingInShard, "numActiveInShard", numActiveInShard) + + if numLeavingInShard < numNodesToShuffledPerShard && numActiveInShard > numLeavingInShard { + return numLeavingInShard + } + + return 0 +} + // TODO: Move this in elrond-go-core func safeSub(a, b uint32) (uint32, error) { if a < b { diff --git a/epochStart/metachain/stakingDataProvider.go b/epochStart/metachain/stakingDataProvider.go index 722a838193f..00c559bc6ad 100644 --- a/epochStart/metachain/stakingDataProvider.go +++ b/epochStart/metachain/stakingDataProvider.go @@ -46,6 +46,7 @@ type stakingDataProvider struct { minNodePrice *big.Int numOfValidatorsInCurrEpoch uint32 enableEpochsHandler common.EnableEpochsHandler + validatorStatsInEpoch epochStart.ValidatorStatsInEpoch } // StakingDataProviderArgs is a struct placeholder for all arguments required to create a NewStakingDataProvider @@ -77,6 +78,11 @@ func NewStakingDataProvider(args StakingDataProviderArgs) (*stakingDataProvider, totalEligibleStake: big.NewInt(0), totalEligibleTopUpStake: big.NewInt(0), enableEpochsHandler: args.EnableEpochsHandler, + validatorStatsInEpoch: epochStart.ValidatorStatsInEpoch{ + Eligible: make(map[uint32]int), + Waiting: make(map[uint32]int), + Leaving: make(map[uint32]int), + }, } return sdp, nil @@ -89,6 +95,11 @@ func (sdp *stakingDataProvider) Clean() { sdp.totalEligibleStake.SetInt64(0) sdp.totalEligibleTopUpStake.SetInt64(0) sdp.numOfValidatorsInCurrEpoch = 0 + sdp.validatorStatsInEpoch = epochStart.ValidatorStatsInEpoch{ + Eligible: make(map[uint32]int), + Waiting: make(map[uint32]int), + Leaving: make(map[uint32]int), + } sdp.mutStakingData.Unlock() } @@ -200,6 +211,7 @@ func (sdp *stakingDataProvider) getAndFillOwnerStats(validator state.ValidatorIn sdp.numOfValidatorsInCurrEpoch++ } + sdp.updateEpochStats(validator) return ownerData, nil } @@ -532,6 +544,48 @@ func (sdp *stakingDataProvider) GetNumOfValidatorsInCurrentEpoch() uint32 { return sdp.numOfValidatorsInCurrEpoch } +func (sdp *stakingDataProvider) updateEpochStats(validator state.ValidatorInfoHandler) { + validatorCurrentList := common.PeerType(validator.GetList()) + shardID := validator.GetShardId() + + if validatorCurrentList == common.EligibleList { + sdp.validatorStatsInEpoch.Eligible[shardID]++ + return + } + + if validatorCurrentList == common.WaitingList { + sdp.validatorStatsInEpoch.Waiting[shardID]++ + return + } + + validatorPreviousList := common.PeerType(validator.GetPreviousList()) + if sdp.isValidatorLeaving(validatorCurrentList, validatorPreviousList) { + sdp.validatorStatsInEpoch.Leaving[shardID]++ + } +} + +func (sdp *stakingDataProvider) isValidatorLeaving(validatorCurrentList, validatorPreviousList common.PeerType) bool { + if validatorCurrentList != common.LeavingList { + return false + } + + // If no previous list is set, means that staking v4 is not activated or node is leaving right before activation + // and this node will be considered as eligible by the nodes coordinator with legacy bug. + // Otherwise, it will have it set, and we should check its previous list in the current epoch + if len(validatorPreviousList) == 0 || validatorPreviousList == common.EligibleList || validatorPreviousList == common.WaitingList { + return true + } + + return false +} + +func (sdp *stakingDataProvider) GetCurrentEpochValidatorStats() epochStart.ValidatorStatsInEpoch { + sdp.mutStakingData.RLock() + defer sdp.mutStakingData.RUnlock() + + return sdp.validatorStatsInEpoch +} + // IsInterfaceNil return true if underlying object is nil func (sdp *stakingDataProvider) IsInterfaceNil() bool { return sdp == nil diff --git a/testscommon/stakingcommon/stakingDataProviderStub.go b/testscommon/stakingcommon/stakingDataProviderStub.go index dc2b990c20c..b6b356cc1e7 100644 --- a/testscommon/stakingcommon/stakingDataProviderStub.go +++ b/testscommon/stakingcommon/stakingDataProviderStub.go @@ -88,6 +88,14 @@ func (sdps *StakingDataProviderStub) GetNumOfValidatorsInCurrentEpoch() uint32 { return 0 } +func (sdps *StakingDataProviderStub) GetCurrentEpochValidatorStats() epochStart.ValidatorStatsInEpoch { + return epochStart.ValidatorStatsInEpoch{ + Eligible: map[uint32]int{}, + Waiting: map[uint32]int{}, + Leaving: map[uint32]int{}, + } +} + // GetOwnersData - func (sdps *StakingDataProviderStub) GetOwnersData() map[string]*epochStart.OwnerData { if sdps.GetOwnersDataCalled != nil { From d7b665d094e82e7ef8fa211a0bb851947cd9ef20 Mon Sep 17 00:00:00 2001 From: MariusC Date: Thu, 11 Apr 2024 16:24:59 +0300 Subject: [PATCH 042/467] FEAT: Test + compute forced to stay --- epochStart/metachain/auctionListSelector.go | 41 +++-- epochStart/metachain/systemSCs_test.go | 4 +- integrationTests/vm/staking/stakingV4_test.go | 163 ++++++++++++++++++ 3 files changed, 192 insertions(+), 16 deletions(-) diff --git a/epochStart/metachain/auctionListSelector.go b/epochStart/metachain/auctionListSelector.go index 9d77a4f8bb6..7737dba8fc8 100644 --- a/epochStart/metachain/auctionListSelector.go +++ b/epochStart/metachain/auctionListSelector.go @@ -198,7 +198,7 @@ func (als *auctionListSelector) SelectNodesFromAuctionList( currNodesConfig := als.nodesConfigProvider.GetCurrentNodesConfig() currNumOfValidators := als.stakingDataProvider.GetNumOfValidatorsInCurrentEpoch() - numOfShuffledNodes := als.computeNumShuffledNodes(currNodesConfig) + numOfShuffledNodes, numForcedToStay := als.computeNumShuffledNodes(currNodesConfig) numOfValidatorsAfterShuffling, err := safeSub(currNumOfValidators, numOfShuffledNodes) if err != nil { log.Warn(fmt.Sprintf("auctionListSelector.SelectNodesFromAuctionList: %v when trying to compute numOfValidatorsAfterShuffling = %v - %v (currNumOfValidators - numOfShuffledNodes)", @@ -210,12 +210,12 @@ func (als *auctionListSelector) SelectNodesFromAuctionList( } maxNumNodes := currNodesConfig.MaxNumNodes - availableSlots, err := safeSub(maxNumNodes, numOfValidatorsAfterShuffling) + availableSlots, err := safeSub(maxNumNodes, numOfValidatorsAfterShuffling+numForcedToStay) if availableSlots == 0 || err != nil { - log.Info(fmt.Sprintf("auctionListSelector.SelectNodesFromAuctionList: %v or zero value when trying to compute availableSlots = %v - %v (maxNodes - numOfValidatorsAfterShuffling); skip selecting nodes from auction list", + log.Info(fmt.Sprintf("auctionListSelector.SelectNodesFromAuctionList: %v or zero value when trying to compute availableSlots = %v - %v (maxNodes - numOfValidatorsAfterShuffling+numForcedToStay); skip selecting nodes from auction list", err, maxNumNodes, - numOfValidatorsAfterShuffling, + numOfValidatorsAfterShuffling+numForcedToStay, )) return nil } @@ -224,9 +224,10 @@ func (als *auctionListSelector) SelectNodesFromAuctionList( "max nodes", maxNumNodes, "current number of validators", currNumOfValidators, "num of nodes which will be shuffled out", numOfShuffledNodes, + "num forced to stay", numForcedToStay, "num of validators after shuffling", numOfValidatorsAfterShuffling, "auction list size", auctionListSize, - fmt.Sprintf("available slots (%v - %v)", maxNumNodes, numOfValidatorsAfterShuffling), availableSlots, + fmt.Sprintf("available slots (%v - %v)", maxNumNodes, numOfValidatorsAfterShuffling+numForcedToStay), availableSlots, ) als.auctionListDisplayer.DisplayOwnersData(ownersData) @@ -272,39 +273,51 @@ func isInAuction(validator state.ValidatorInfoHandler) bool { return validator.GetList() == string(common.AuctionList) } -func (als *auctionListSelector) computeNumShuffledNodes(currNodesConfig config.MaxNodesChangeConfig) uint32 { +func (als *auctionListSelector) computeNumShuffledNodes(currNodesConfig config.MaxNodesChangeConfig) (uint32, uint32) { numNodesToShufflePerShard := currNodesConfig.NodesToShufflePerShard numShuffledOut := numNodesToShufflePerShard * (als.shardCoordinator.NumberOfShards() + 1) epochStats := als.stakingDataProvider.GetCurrentEpochValidatorStats() actuallyNumLeaving := uint32(0) + forcedToStay := uint32(0) for shardID := uint32(0); shardID < als.shardCoordinator.NumberOfShards(); shardID++ { - actuallyNumLeaving += computeActuallyNumLeaving(shardID, epochStats, numNodesToShufflePerShard) + leavingInShard, forcedToStayInShard := computeActuallyNumLeaving(shardID, epochStats, numNodesToShufflePerShard) + actuallyNumLeaving += leavingInShard + forcedToStay += forcedToStayInShard } - actuallyNumLeaving += computeActuallyNumLeaving(core.MetachainShardId, epochStats, numNodesToShufflePerShard) + leavingInShard, forcedToStayInShard := computeActuallyNumLeaving(core.MetachainShardId, epochStats, numNodesToShufflePerShard) + actuallyNumLeaving += leavingInShard + forcedToStay += forcedToStayInShard finalShuffledOut, err := safeSub(numShuffledOut, actuallyNumLeaving) if err != nil { log.Error("auctionListSelector.computeNumShuffledNodes", "error", err) - return numShuffledOut + return numShuffledOut, 0 } - return finalShuffledOut + return finalShuffledOut, forcedToStay } -func computeActuallyNumLeaving(shardID uint32, epochStats epochStart.ValidatorStatsInEpoch, numNodesToShuffledPerShard uint32) uint32 { +func computeActuallyNumLeaving(shardID uint32, epochStats epochStart.ValidatorStatsInEpoch, numNodesToShuffledPerShard uint32) (uint32, uint32) { numLeavingInShard := uint32(epochStats.Leaving[shardID]) numActiveInShard := uint32(epochStats.Waiting[shardID] + epochStats.Eligible[shardID]) - log.Debug("auctionListSelector.computeActuallyNumLeaving", + log.Info("auctionListSelector.computeActuallyNumLeaving", "shardID", shardID, "numLeavingInShard", numLeavingInShard, "numActiveInShard", numActiveInShard) + actuallyleaving := uint32(0) + forcedToStay := uint32(0) if numLeavingInShard < numNodesToShuffledPerShard && numActiveInShard > numLeavingInShard { - return numLeavingInShard + actuallyleaving = numLeavingInShard } - return 0 + if numLeavingInShard > numNodesToShuffledPerShard { + actuallyleaving = numNodesToShuffledPerShard + forcedToStay = numLeavingInShard - numNodesToShuffledPerShard + } + + return actuallyleaving, forcedToStay } // TODO: Move this in elrond-go-core diff --git a/epochStart/metachain/systemSCs_test.go b/epochStart/metachain/systemSCs_test.go index 0dc9eb82b23..c2000e16c60 100644 --- a/epochStart/metachain/systemSCs_test.go +++ b/epochStart/metachain/systemSCs_test.go @@ -2093,7 +2093,7 @@ func TestSystemSCProcessor_ProcessSystemSmartContractStakingV4Enabled(t *testing t.Parallel() args, _ := createFullArgumentsForSystemSCProcessing(config.EnableEpochs{}, testscommon.CreateMemUnit()) - nodesConfigProvider, _ := notifier.NewNodesConfigProvider(args.EpochNotifier, []config.MaxNodesChangeConfig{{MaxNumNodes: 8}}) + nodesConfigProvider, _ := notifier.NewNodesConfigProvider(args.EpochNotifier, []config.MaxNodesChangeConfig{{MaxNumNodes: 9}}) auctionCfg := config.SoftAuctionConfig{ TopUpStep: "10", @@ -2179,7 +2179,7 @@ func TestSystemSCProcessor_ProcessSystemSmartContractStakingV4Enabled(t *testing will not participate in auction selection - owner6 does not have enough stake for 2 nodes => one of his auction nodes(pubKey14) will be unStaked at the end of the epoch => his other auction node(pubKey15) will not participate in auction selection - - MaxNumNodes = 8 + - MaxNumNodes = 9 - EligibleBlsKeys = 5 (pubKey0, pubKey1, pubKey3, pubKe13, pubKey17) - QualifiedAuctionBlsKeys = 7 (pubKey2, pubKey4, pubKey5, pubKey7, pubKey9, pubKey10, pubKey11) We can only select (MaxNumNodes - EligibleBlsKeys = 3) bls keys from AuctionList to be added to NewList diff --git a/integrationTests/vm/staking/stakingV4_test.go b/integrationTests/vm/staking/stakingV4_test.go index 67b1f19ab03..3b139c40b29 100644 --- a/integrationTests/vm/staking/stakingV4_test.go +++ b/integrationTests/vm/staking/stakingV4_test.go @@ -1524,3 +1524,166 @@ func TestStakingV4_LeavingNodesEdgeCases(t *testing.T) { owner1LeftNodes := getIntersection(owner1NodesThatAreStillForcedToRemain, allCurrentNodesInSystem) require.Zero(t, len(owner1LeftNodes)) } + +// TODO if necessary: +// - test with limit (unstake exactly 80 per shard) +// - unstake more nodes when waiting lists are pretty empty + +func TestStakingV4LeavingNodesShouldDistributeToWaitingOnlyNecessaryNodes(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + numOfMetaNodes := uint32(400) + numOfShards := uint32(3) + numOfEligibleNodesPerShard := uint32(400) + numOfWaitingNodesPerShard := uint32(400) + numOfNodesToShufflePerShard := uint32(80) + shardConsensusGroupSize := 266 + metaConsensusGroupSize := 266 + numOfNodesInStakingQueue := uint32(80) + + totalEligible := int(numOfEligibleNodesPerShard*numOfShards) + int(numOfMetaNodes) // 1600 + totalWaiting := int(numOfWaitingNodesPerShard*numOfShards) + int(numOfMetaNodes) // 1600 + + node := NewTestMetaProcessor( + numOfMetaNodes, + numOfShards, + numOfEligibleNodesPerShard, + numOfWaitingNodesPerShard, + numOfNodesToShufflePerShard, + shardConsensusGroupSize, + metaConsensusGroupSize, + numOfNodesInStakingQueue, + ) + node.EpochStartTrigger.SetRoundsPerEpoch(4) + + // 1. Check initial config is correct + initialNodes := node.NodesConfig + require.Len(t, getAllPubKeys(initialNodes.eligible), totalEligible) + require.Len(t, getAllPubKeys(initialNodes.waiting), totalWaiting) + require.Len(t, initialNodes.queue, int(numOfNodesInStakingQueue)) + require.Empty(t, initialNodes.shuffledOut) + require.Empty(t, initialNodes.auction) + + // 2. Check config after staking v4 initialization + node.Process(t, 5) + nodesConfigStakingV4Step1 := node.NodesConfig + require.Len(t, getAllPubKeys(nodesConfigStakingV4Step1.eligible), totalEligible) + require.Len(t, getAllPubKeys(nodesConfigStakingV4Step1.waiting), totalWaiting) + require.Empty(t, nodesConfigStakingV4Step1.queue) + require.Empty(t, nodesConfigStakingV4Step1.shuffledOut) + require.Empty(t, nodesConfigStakingV4Step1.auction) // the queue should be empty + + // 3. re-stake the node nodes that were in the queue + node.ProcessReStake(t, initialNodes.queue) + nodesConfigStakingV4Step1 = node.NodesConfig + requireSameSliceDifferentOrder(t, initialNodes.queue, nodesConfigStakingV4Step1.auction) + + node.Process(t, 10) + + epochs := 0 + prevConfig := node.NodesConfig + numOfSelectedNodesFromAuction := 320 // 320, since we will always fill shuffled out nodes with this config + numOfUnselectedNodesFromAuction := 80 // 80 = 400 from queue - 320 + numOfShuffledOut := 80 * 4 // 80 per shard + meta + for epochs < 4 { + node.Process(t, 5) + newNodeConfig := node.NodesConfig + + require.Len(t, getAllPubKeys(newNodeConfig.eligible), totalEligible) // 1600 + require.Len(t, getAllPubKeys(newNodeConfig.waiting), 1280) // 1280 + require.Len(t, getAllPubKeys(newNodeConfig.shuffledOut), 320) // 320 + require.Len(t, newNodeConfig.auction, 400) // 400 + require.Empty(t, newNodeConfig.queue) + require.Empty(t, newNodeConfig.leaving) + + checkStakingV4EpochChangeFlow(t, newNodeConfig, prevConfig, numOfShuffledOut, numOfUnselectedNodesFromAuction, numOfSelectedNodesFromAuction) + prevConfig = newNodeConfig + epochs++ + } + + // UnStake: + // - 46 from waiting + eligible ( 13 waiting + 36 eligible) + // - 11 from auction + currNodesCfg := node.NodesConfig + nodesToUnstakeFromAuction := currNodesCfg.auction[:11] + + nodesToUnstakeFromWaiting := append(currNodesCfg.waiting[0][:3], currNodesCfg.waiting[1][:3]...) + nodesToUnstakeFromWaiting = append(nodesToUnstakeFromWaiting, currNodesCfg.waiting[2][:3]...) + nodesToUnstakeFromWaiting = append(nodesToUnstakeFromWaiting, currNodesCfg.waiting[core.MetachainShardId][:4]...) + + nodesToUnstakeFromEligible := append(currNodesCfg.eligible[0][:8], currNodesCfg.eligible[1][:8]...) + nodesToUnstakeFromEligible = append(nodesToUnstakeFromEligible, currNodesCfg.eligible[2][:8]...) + nodesToUnstakeFromEligible = append(nodesToUnstakeFromEligible, currNodesCfg.eligible[core.MetachainShardId][:9]...) + + nodesToUnstake := getAllNodesToUnStake(nodesToUnstakeFromAuction, nodesToUnstakeFromWaiting, nodesToUnstakeFromEligible) + + prevConfig = currNodesCfg + node.ProcessUnStake(t, nodesToUnstake) + node.Process(t, 5) + currNodesCfg = node.NodesConfig + + require.Len(t, getAllPubKeys(currNodesCfg.leaving), 57) // 11 auction + 46 active (13 waiting + 36 eligible) + require.Len(t, getAllPubKeys(currNodesCfg.shuffledOut), 274) // 320 - 46 active + require.Len(t, currNodesCfg.auction, 343) // 400 initial - 57 leaving + requireSliceContainsNumOfElements(t, getAllPubKeys(currNodesCfg.waiting), prevConfig.auction, 320) // 320 selected + requireSliceContainsNumOfElements(t, currNodesCfg.auction, prevConfig.auction, 69) // 69 unselected + + nodesToUnstakeFromAuction = make([][]byte, 0) + nodesToUnstakeFromWaiting = make([][]byte, 0) + nodesToUnstakeFromEligible = make([][]byte, 0) + + prevConfig = currNodesCfg + // UnStake: + // - 224 from waiting + eligible ( 13 waiting + 36 eligible), but unbalanced: + // -> unStake 100 from waiting shard=meta => will force to stay = 100 from meta + // -> unStake 90 from eligible shard=2 => will force to stay = 90 from shard 2 + // - 11 from auction + nodesToUnstakeFromAuction = currNodesCfg.auction[:11] + nodesToUnstakeFromWaiting = append(currNodesCfg.waiting[0][:3], currNodesCfg.waiting[1][:3]...) + nodesToUnstakeFromWaiting = append(nodesToUnstakeFromWaiting, currNodesCfg.waiting[2][:3]...) + nodesToUnstakeFromWaiting = append(nodesToUnstakeFromWaiting, currNodesCfg.waiting[core.MetachainShardId][:100]...) + + nodesToUnstakeFromEligible = append(currNodesCfg.eligible[0][:8], currNodesCfg.eligible[1][:8]...) + nodesToUnstakeFromEligible = append(nodesToUnstakeFromEligible, currNodesCfg.eligible[2][:90]...) + nodesToUnstakeFromEligible = append(nodesToUnstakeFromEligible, currNodesCfg.eligible[core.MetachainShardId][:9]...) + + nodesToUnstake = getAllNodesToUnStake(nodesToUnstakeFromAuction, nodesToUnstakeFromWaiting, nodesToUnstakeFromEligible) + node.ProcessUnStake(t, nodesToUnstake) + node.Process(t, 5) + currNodesCfg = node.NodesConfig + + // Leaving: + // - 11 auction + // - shard 0 = 11 + // - shard 1 = 11 + // - shard 2 = 80 (there were 93 unStakes, but only 80 will be leaving, rest 13 will be forced to stay) + // - shard meta = 80 (there were 109 unStakes, but only 80 will be leaving, rest 29 will be forced to stay) + // Therefore we will have in total actually leaving = 193 (11 + 11 + 11 + 80 + 80) + // We should see a log in selector like this: + // auctionListSelector.SelectNodesFromAuctionList max nodes = 2880 current number of validators = 2656 num of nodes which will be shuffled out = 138 num forced to stay = 42 num of validators after shuffling = 2518 auction list size = 332 available slots (2880 - 2560) = 320 + require.Len(t, getAllPubKeys(currNodesCfg.leaving), 193) + require.Len(t, getAllPubKeys(currNodesCfg.shuffledOut), 138) // 69 from shard0 + shard from shard1, rest will not be shuffled + require.Len(t, currNodesCfg.auction, 150) // 138 shuffled out + 12 unselected + requireSliceContainsNumOfElements(t, getAllPubKeys(currNodesCfg.waiting), prevConfig.auction, 320) // 320 selected + requireSliceContainsNumOfElements(t, currNodesCfg.auction, prevConfig.auction, 12) // 12 unselected +} + +func getAllNodesToUnStake(nodesToUnStakeFromAuction, nodesToUnStakeFromWaiting, nodesToUnStakeFromEligible [][]byte) map[string][][]byte { + ret := make(map[string][][]byte) + + for _, nodeToUnstake := range nodesToUnStakeFromAuction { + ret[string(nodeToUnstake)] = [][]byte{nodeToUnstake} + } + + for _, nodeToUnstake := range nodesToUnStakeFromWaiting { + ret[string(nodeToUnstake)] = [][]byte{nodeToUnstake} + } + + for _, nodeToUnstake := range nodesToUnStakeFromEligible { + ret[string(nodeToUnstake)] = [][]byte{nodeToUnstake} + } + + return ret +} From f8151b193d479b93ff487b5df94a47dbe7a4d9eb Mon Sep 17 00:00:00 2001 From: MariusC Date: Fri, 12 Apr 2024 11:35:32 +0300 Subject: [PATCH 043/467] CLN: AddNewValidator to trie --- epochStart/metachain/legacySystemSCs.go | 28 +++++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/epochStart/metachain/legacySystemSCs.go b/epochStart/metachain/legacySystemSCs.go index 3247cb2dff1..2abe8a993fb 100644 --- a/epochStart/metachain/legacySystemSCs.go +++ b/epochStart/metachain/legacySystemSCs.go @@ -1262,22 +1262,32 @@ func (s *legacySystemSCProcessor) addNewlyStakedNodesToValidatorTrie( AccumulatedFees: big.NewInt(0), } - existingValidator := validatorsInfoMap.GetValidator(validatorInfo.GetPublicKey()) - // This fix is not be backwards incompatible - if !check.IfNil(existingValidator) && s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) { - err = validatorsInfoMap.Delete(existingValidator) - if err != nil { - return err - } + err = s.addNewValidator(validatorsInfoMap, validatorInfo) + if err != nil { + return err } + } - err = validatorsInfoMap.Add(validatorInfo) + return nil +} + +func (s *legacySystemSCProcessor) addNewValidator( + validatorsInfoMap state.ShardValidatorsInfoMapHandler, + validatorInfo state.ValidatorInfoHandler, +) error { + if !s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) { + return validatorsInfoMap.Add(validatorInfo) + } + + existingValidator := validatorsInfoMap.GetValidator(validatorInfo.GetPublicKey()) + if !check.IfNil(existingValidator) { + err := validatorsInfoMap.Delete(existingValidator) if err != nil { return err } } - return nil + return validatorsInfoMap.Add(validatorInfo) } func (s *legacySystemSCProcessor) initESDT() error { From 86445c954e5a290a68bca997dad69c2026e2bda4 Mon Sep 17 00:00:00 2001 From: MariusC Date: Fri, 12 Apr 2024 13:21:02 +0300 Subject: [PATCH 044/467] CLN: auctionListSelector.go --- epochStart/metachain/auctionListSelector.go | 38 +++++++++++-------- integrationTests/vm/staking/stakingV4_test.go | 1 + 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/epochStart/metachain/auctionListSelector.go b/epochStart/metachain/auctionListSelector.go index 7737dba8fc8..becbfd8409d 100644 --- a/epochStart/metachain/auctionListSelector.go +++ b/epochStart/metachain/auctionListSelector.go @@ -210,12 +210,13 @@ func (als *auctionListSelector) SelectNodesFromAuctionList( } maxNumNodes := currNodesConfig.MaxNumNodes - availableSlots, err := safeSub(maxNumNodes, numOfValidatorsAfterShuffling+numForcedToStay) + numValidatorsAfterShufflingWithForcedToStay := numOfValidatorsAfterShuffling + numForcedToStay + availableSlots, err := safeSub(maxNumNodes, numValidatorsAfterShufflingWithForcedToStay) if availableSlots == 0 || err != nil { log.Info(fmt.Sprintf("auctionListSelector.SelectNodesFromAuctionList: %v or zero value when trying to compute availableSlots = %v - %v (maxNodes - numOfValidatorsAfterShuffling+numForcedToStay); skip selecting nodes from auction list", err, maxNumNodes, - numOfValidatorsAfterShuffling+numForcedToStay, + numValidatorsAfterShufflingWithForcedToStay, )) return nil } @@ -225,9 +226,9 @@ func (als *auctionListSelector) SelectNodesFromAuctionList( "current number of validators", currNumOfValidators, "num of nodes which will be shuffled out", numOfShuffledNodes, "num forced to stay", numForcedToStay, - "num of validators after shuffling", numOfValidatorsAfterShuffling, + "num of validators after shuffling with forced to stay", numValidatorsAfterShufflingWithForcedToStay, "auction list size", auctionListSize, - fmt.Sprintf("available slots (%v - %v)", maxNumNodes, numOfValidatorsAfterShuffling+numForcedToStay), availableSlots, + fmt.Sprintf("available slots (%v - %v)", maxNumNodes, numValidatorsAfterShufflingWithForcedToStay), availableSlots, ) als.auctionListDisplayer.DisplayOwnersData(ownersData) @@ -275,25 +276,27 @@ func isInAuction(validator state.ValidatorInfoHandler) bool { func (als *auctionListSelector) computeNumShuffledNodes(currNodesConfig config.MaxNodesChangeConfig) (uint32, uint32) { numNodesToShufflePerShard := currNodesConfig.NodesToShufflePerShard - numShuffledOut := numNodesToShufflePerShard * (als.shardCoordinator.NumberOfShards() + 1) + numTotalToShuffleOut := numNodesToShufflePerShard * (als.shardCoordinator.NumberOfShards() + 1) epochStats := als.stakingDataProvider.GetCurrentEpochValidatorStats() actuallyNumLeaving := uint32(0) forcedToStay := uint32(0) + for shardID := uint32(0); shardID < als.shardCoordinator.NumberOfShards(); shardID++ { leavingInShard, forcedToStayInShard := computeActuallyNumLeaving(shardID, epochStats, numNodesToShufflePerShard) actuallyNumLeaving += leavingInShard forcedToStay += forcedToStayInShard } - leavingInShard, forcedToStayInShard := computeActuallyNumLeaving(core.MetachainShardId, epochStats, numNodesToShufflePerShard) - actuallyNumLeaving += leavingInShard - forcedToStay += forcedToStayInShard + leavingInMeta, forcedToStayInMeta := computeActuallyNumLeaving(core.MetachainShardId, epochStats, numNodesToShufflePerShard) + actuallyNumLeaving += leavingInMeta + forcedToStay += forcedToStayInMeta - finalShuffledOut, err := safeSub(numShuffledOut, actuallyNumLeaving) + finalShuffledOut, err := safeSub(numTotalToShuffleOut, actuallyNumLeaving) if err != nil { - log.Error("auctionListSelector.computeNumShuffledNodes", "error", err) - return numShuffledOut, 0 + log.Error("auctionListSelector.computeNumShuffledNodes error computing finalShuffledOut, returning default values", + "error", err, "numTotalToShuffleOut", numTotalToShuffleOut, "actuallyNumLeaving", actuallyNumLeaving) + return numTotalToShuffleOut, 0 } return finalShuffledOut, forcedToStay @@ -303,21 +306,24 @@ func computeActuallyNumLeaving(shardID uint32, epochStats epochStart.ValidatorSt numLeavingInShard := uint32(epochStats.Leaving[shardID]) numActiveInShard := uint32(epochStats.Waiting[shardID] + epochStats.Eligible[shardID]) - log.Info("auctionListSelector.computeActuallyNumLeaving", + log.Debug("auctionListSelector.computeActuallyNumLeaving computing", "shardID", shardID, "numLeavingInShard", numLeavingInShard, "numActiveInShard", numActiveInShard) - actuallyleaving := uint32(0) + actuallyLeaving := uint32(0) forcedToStay := uint32(0) if numLeavingInShard < numNodesToShuffledPerShard && numActiveInShard > numLeavingInShard { - actuallyleaving = numLeavingInShard + actuallyLeaving = numLeavingInShard } if numLeavingInShard > numNodesToShuffledPerShard { - actuallyleaving = numNodesToShuffledPerShard + actuallyLeaving = numNodesToShuffledPerShard forcedToStay = numLeavingInShard - numNodesToShuffledPerShard } - return actuallyleaving, forcedToStay + log.Debug("auctionListSelector.computeActuallyNumLeaving computed", + "actuallyLeaving", actuallyLeaving, "forcedToStay", forcedToStay) + + return actuallyLeaving, forcedToStay } // TODO: Move this in elrond-go-core diff --git a/integrationTests/vm/staking/stakingV4_test.go b/integrationTests/vm/staking/stakingV4_test.go index 3b139c40b29..f7cd6d698d8 100644 --- a/integrationTests/vm/staking/stakingV4_test.go +++ b/integrationTests/vm/staking/stakingV4_test.go @@ -1528,6 +1528,7 @@ func TestStakingV4_LeavingNodesEdgeCases(t *testing.T) { // TODO if necessary: // - test with limit (unstake exactly 80 per shard) // - unstake more nodes when waiting lists are pretty empty +// - chain simulator api calls func TestStakingV4LeavingNodesShouldDistributeToWaitingOnlyNecessaryNodes(t *testing.T) { if testing.Short() { From a3207449ccfdb5c8da793a47d3b1f6d69f988cf5 Mon Sep 17 00:00:00 2001 From: MariusC Date: Fri, 12 Apr 2024 15:09:20 +0300 Subject: [PATCH 045/467] FEAT: Integration tests with more leaving than to shuffle --- epochStart/metachain/auctionListSelector.go | 2 +- epochStart/metachain/stakingDataProvider.go | 9 +- integrationTests/vm/staking/stakingV4_test.go | 178 ++++++++++++++---- .../testMetaProcessorWithCustomNodesConfig.go | 2 +- .../stakingcommon/stakingDataProviderStub.go | 1 + 5 files changed, 146 insertions(+), 46 deletions(-) diff --git a/epochStart/metachain/auctionListSelector.go b/epochStart/metachain/auctionListSelector.go index becbfd8409d..96c65e4a579 100644 --- a/epochStart/metachain/auctionListSelector.go +++ b/epochStart/metachain/auctionListSelector.go @@ -311,7 +311,7 @@ func computeActuallyNumLeaving(shardID uint32, epochStats epochStart.ValidatorSt actuallyLeaving := uint32(0) forcedToStay := uint32(0) - if numLeavingInShard < numNodesToShuffledPerShard && numActiveInShard > numLeavingInShard { + if numLeavingInShard <= numNodesToShuffledPerShard && numActiveInShard > numLeavingInShard { actuallyLeaving = numLeavingInShard } diff --git a/epochStart/metachain/stakingDataProvider.go b/epochStart/metachain/stakingDataProvider.go index 00c559bc6ad..b655fbe1b16 100644 --- a/epochStart/metachain/stakingDataProvider.go +++ b/epochStart/metachain/stakingDataProvider.go @@ -570,15 +570,12 @@ func (sdp *stakingDataProvider) isValidatorLeaving(validatorCurrentList, validat } // If no previous list is set, means that staking v4 is not activated or node is leaving right before activation - // and this node will be considered as eligible by the nodes coordinator with legacy bug. + // and this node will be considered as eligible by the nodes coordinator with old code. // Otherwise, it will have it set, and we should check its previous list in the current epoch - if len(validatorPreviousList) == 0 || validatorPreviousList == common.EligibleList || validatorPreviousList == common.WaitingList { - return true - } - - return false + return len(validatorPreviousList) == 0 || validatorPreviousList == common.EligibleList || validatorPreviousList == common.WaitingList } +// GetCurrentEpochValidatorStats returns the current epoch validator stats func (sdp *stakingDataProvider) GetCurrentEpochValidatorStats() epochStart.ValidatorStatsInEpoch { sdp.mutStakingData.RLock() defer sdp.mutStakingData.RUnlock() diff --git a/integrationTests/vm/staking/stakingV4_test.go b/integrationTests/vm/staking/stakingV4_test.go index f7cd6d698d8..b6a351ed7f7 100644 --- a/integrationTests/vm/staking/stakingV4_test.go +++ b/integrationTests/vm/staking/stakingV4_test.go @@ -186,6 +186,22 @@ func checkStakingV4EpochChangeFlow( requireSliceContainsNumOfElements(t, getAllPubKeys(currNodesConfig.waiting), prevNodesConfig.auction, numOfSelectedNodesFromAuction) } +func getAllOwnerNodesMap(nodeGroups ...[][]byte) map[string][][]byte { + ret := make(map[string][][]byte) + + for _, nodes := range nodeGroups { + addNodesToMap(nodes, ret) + } + + return ret +} + +func addNodesToMap(nodes [][]byte, allOwnerNodes map[string][][]byte) { + for _, node := range nodes { + allOwnerNodes[string(node)] = [][]byte{node} + } +} + func TestStakingV4(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") @@ -1581,14 +1597,14 @@ func TestStakingV4LeavingNodesShouldDistributeToWaitingOnlyNecessaryNodes(t *tes nodesConfigStakingV4Step1 = node.NodesConfig requireSameSliceDifferentOrder(t, initialNodes.queue, nodesConfigStakingV4Step1.auction) + // Reach step 3 and check normal flow node.Process(t, 10) - epochs := 0 prevConfig := node.NodesConfig numOfSelectedNodesFromAuction := 320 // 320, since we will always fill shuffled out nodes with this config numOfUnselectedNodesFromAuction := 80 // 80 = 400 from queue - 320 numOfShuffledOut := 80 * 4 // 80 per shard + meta - for epochs < 4 { + for epochs < 3 { node.Process(t, 5) newNodeConfig := node.NodesConfig @@ -1608,20 +1624,20 @@ func TestStakingV4LeavingNodesShouldDistributeToWaitingOnlyNecessaryNodes(t *tes // - 46 from waiting + eligible ( 13 waiting + 36 eligible) // - 11 from auction currNodesCfg := node.NodesConfig - nodesToUnstakeFromAuction := currNodesCfg.auction[:11] + nodesToUnStakeFromAuction := currNodesCfg.auction[:11] - nodesToUnstakeFromWaiting := append(currNodesCfg.waiting[0][:3], currNodesCfg.waiting[1][:3]...) - nodesToUnstakeFromWaiting = append(nodesToUnstakeFromWaiting, currNodesCfg.waiting[2][:3]...) - nodesToUnstakeFromWaiting = append(nodesToUnstakeFromWaiting, currNodesCfg.waiting[core.MetachainShardId][:4]...) + nodesToUnStakeFromWaiting := append(currNodesCfg.waiting[0][:3], currNodesCfg.waiting[1][:3]...) + nodesToUnStakeFromWaiting = append(nodesToUnStakeFromWaiting, currNodesCfg.waiting[2][:3]...) + nodesToUnStakeFromWaiting = append(nodesToUnStakeFromWaiting, currNodesCfg.waiting[core.MetachainShardId][:4]...) - nodesToUnstakeFromEligible := append(currNodesCfg.eligible[0][:8], currNodesCfg.eligible[1][:8]...) - nodesToUnstakeFromEligible = append(nodesToUnstakeFromEligible, currNodesCfg.eligible[2][:8]...) - nodesToUnstakeFromEligible = append(nodesToUnstakeFromEligible, currNodesCfg.eligible[core.MetachainShardId][:9]...) + nodesToUnStakeFromEligible := append(currNodesCfg.eligible[0][:8], currNodesCfg.eligible[1][:8]...) + nodesToUnStakeFromEligible = append(nodesToUnStakeFromEligible, currNodesCfg.eligible[2][:8]...) + nodesToUnStakeFromEligible = append(nodesToUnStakeFromEligible, currNodesCfg.eligible[core.MetachainShardId][:9]...) - nodesToUnstake := getAllNodesToUnStake(nodesToUnstakeFromAuction, nodesToUnstakeFromWaiting, nodesToUnstakeFromEligible) + nodesToUnStake := getAllOwnerNodesMap(nodesToUnStakeFromAuction, nodesToUnStakeFromWaiting, nodesToUnStakeFromEligible) prevConfig = currNodesCfg - node.ProcessUnStake(t, nodesToUnstake) + node.ProcessUnStake(t, nodesToUnStake) node.Process(t, 5) currNodesCfg = node.NodesConfig @@ -1631,28 +1647,28 @@ func TestStakingV4LeavingNodesShouldDistributeToWaitingOnlyNecessaryNodes(t *tes requireSliceContainsNumOfElements(t, getAllPubKeys(currNodesCfg.waiting), prevConfig.auction, 320) // 320 selected requireSliceContainsNumOfElements(t, currNodesCfg.auction, prevConfig.auction, 69) // 69 unselected - nodesToUnstakeFromAuction = make([][]byte, 0) - nodesToUnstakeFromWaiting = make([][]byte, 0) - nodesToUnstakeFromEligible = make([][]byte, 0) + nodesToUnStakeFromAuction = make([][]byte, 0) + nodesToUnStakeFromWaiting = make([][]byte, 0) + nodesToUnStakeFromEligible = make([][]byte, 0) prevConfig = currNodesCfg // UnStake: // - 224 from waiting + eligible ( 13 waiting + 36 eligible), but unbalanced: - // -> unStake 100 from waiting shard=meta => will force to stay = 100 from meta - // -> unStake 90 from eligible shard=2 => will force to stay = 90 from shard 2 + // -> unStake 100 from waiting shard=meta + // -> unStake 90 from eligible shard=2 // - 11 from auction - nodesToUnstakeFromAuction = currNodesCfg.auction[:11] - nodesToUnstakeFromWaiting = append(currNodesCfg.waiting[0][:3], currNodesCfg.waiting[1][:3]...) - nodesToUnstakeFromWaiting = append(nodesToUnstakeFromWaiting, currNodesCfg.waiting[2][:3]...) - nodesToUnstakeFromWaiting = append(nodesToUnstakeFromWaiting, currNodesCfg.waiting[core.MetachainShardId][:100]...) + nodesToUnStakeFromAuction = currNodesCfg.auction[:11] + nodesToUnStakeFromWaiting = append(currNodesCfg.waiting[0][:3], currNodesCfg.waiting[1][:3]...) + nodesToUnStakeFromWaiting = append(nodesToUnStakeFromWaiting, currNodesCfg.waiting[2][:3]...) + nodesToUnStakeFromWaiting = append(nodesToUnStakeFromWaiting, currNodesCfg.waiting[core.MetachainShardId][:100]...) - nodesToUnstakeFromEligible = append(currNodesCfg.eligible[0][:8], currNodesCfg.eligible[1][:8]...) - nodesToUnstakeFromEligible = append(nodesToUnstakeFromEligible, currNodesCfg.eligible[2][:90]...) - nodesToUnstakeFromEligible = append(nodesToUnstakeFromEligible, currNodesCfg.eligible[core.MetachainShardId][:9]...) + nodesToUnStakeFromEligible = append(currNodesCfg.eligible[0][:8], currNodesCfg.eligible[1][:8]...) + nodesToUnStakeFromEligible = append(nodesToUnStakeFromEligible, currNodesCfg.eligible[2][:90]...) + nodesToUnStakeFromEligible = append(nodesToUnStakeFromEligible, currNodesCfg.eligible[core.MetachainShardId][:9]...) - nodesToUnstake = getAllNodesToUnStake(nodesToUnstakeFromAuction, nodesToUnstakeFromWaiting, nodesToUnstakeFromEligible) - node.ProcessUnStake(t, nodesToUnstake) - node.Process(t, 5) + nodesToUnStake = getAllOwnerNodesMap(nodesToUnStakeFromAuction, nodesToUnStakeFromWaiting, nodesToUnStakeFromEligible) + node.ProcessUnStake(t, nodesToUnStake) + node.Process(t, 4) currNodesCfg = node.NodesConfig // Leaving: @@ -1671,20 +1687,106 @@ func TestStakingV4LeavingNodesShouldDistributeToWaitingOnlyNecessaryNodes(t *tes requireSliceContainsNumOfElements(t, currNodesCfg.auction, prevConfig.auction, 12) // 12 unselected } -func getAllNodesToUnStake(nodesToUnStakeFromAuction, nodesToUnStakeFromWaiting, nodesToUnStakeFromEligible [][]byte) map[string][][]byte { - ret := make(map[string][][]byte) - - for _, nodeToUnstake := range nodesToUnStakeFromAuction { - ret[string(nodeToUnstake)] = [][]byte{nodeToUnstake} +func TestStakingV4MoreLeavingNodesThanToShufflePerShard(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") } - for _, nodeToUnstake := range nodesToUnStakeFromWaiting { - ret[string(nodeToUnstake)] = [][]byte{nodeToUnstake} - } + numOfMetaNodes := uint32(400) + numOfShards := uint32(3) + numOfEligibleNodesPerShard := uint32(400) + numOfWaitingNodesPerShard := uint32(400) + numOfNodesToShufflePerShard := uint32(80) + shardConsensusGroupSize := 266 + metaConsensusGroupSize := 266 + numOfNodesInStakingQueue := uint32(80) - for _, nodeToUnstake := range nodesToUnStakeFromEligible { - ret[string(nodeToUnstake)] = [][]byte{nodeToUnstake} - } + totalEligible := int(numOfEligibleNodesPerShard*numOfShards) + int(numOfMetaNodes) // 1600 + totalWaiting := int(numOfWaitingNodesPerShard*numOfShards) + int(numOfMetaNodes) // 1600 - return ret + node := NewTestMetaProcessor( + numOfMetaNodes, + numOfShards, + numOfEligibleNodesPerShard, + numOfWaitingNodesPerShard, + numOfNodesToShufflePerShard, + shardConsensusGroupSize, + metaConsensusGroupSize, + numOfNodesInStakingQueue, + ) + node.EpochStartTrigger.SetRoundsPerEpoch(4) + + // 1. Check initial config is correct + initialNodes := node.NodesConfig + require.Len(t, getAllPubKeys(initialNodes.eligible), totalEligible) + require.Len(t, getAllPubKeys(initialNodes.waiting), totalWaiting) + require.Len(t, initialNodes.queue, int(numOfNodesInStakingQueue)) + require.Empty(t, initialNodes.shuffledOut) + require.Empty(t, initialNodes.auction) + + // 2. Check config after staking v4 initialization + node.Process(t, 5) + nodesConfigStakingV4Step1 := node.NodesConfig + require.Len(t, getAllPubKeys(nodesConfigStakingV4Step1.eligible), totalEligible) + require.Len(t, getAllPubKeys(nodesConfigStakingV4Step1.waiting), totalWaiting) + require.Empty(t, nodesConfigStakingV4Step1.queue) + require.Empty(t, nodesConfigStakingV4Step1.shuffledOut) + require.Empty(t, nodesConfigStakingV4Step1.auction) // the queue should be empty + + // 3. re-stake the node nodes that were in the queue + node.ProcessReStake(t, initialNodes.queue) + nodesConfigStakingV4Step1 = node.NodesConfig + requireSameSliceDifferentOrder(t, initialNodes.queue, nodesConfigStakingV4Step1.auction) + + // Reach step 3 + node.Process(t, 10) + + // UnStake 100 nodes from each shard: + // - shard 0: 100 waiting + // - shard 1: 50 waiting + 50 eligible + // - shard 2: 20 waiting + 80 eligible + // - shard meta: 100 eligible + currNodesCfg := node.NodesConfig + + nodesToUnStakeFromWaiting := currNodesCfg.waiting[0][:100] + nodesToUnStakeFromWaiting = append(nodesToUnStakeFromWaiting, currNodesCfg.waiting[1][:50]...) + nodesToUnStakeFromWaiting = append(nodesToUnStakeFromWaiting, currNodesCfg.waiting[2][:20]...) + + nodesToUnStakeFromEligible := currNodesCfg.eligible[1][:50] + nodesToUnStakeFromEligible = append(nodesToUnStakeFromEligible, currNodesCfg.eligible[2][:80]...) + nodesToUnStakeFromEligible = append(nodesToUnStakeFromEligible, currNodesCfg.eligible[core.MetachainShardId][:100]...) + + nodesToUnStake := getAllOwnerNodesMap(nodesToUnStakeFromWaiting, nodesToUnStakeFromEligible) + + prevConfig := currNodesCfg + node.ProcessUnStake(t, nodesToUnStake) + node.Process(t, 4) + currNodesCfg = node.NodesConfig + + require.Len(t, getAllPubKeys(currNodesCfg.leaving), 320) // we unStaked 400, but only allowed 320 to leave + require.Len(t, getAllPubKeys(currNodesCfg.shuffledOut), 0) // no shuffled out, since 80 per shard were leaving + require.Len(t, currNodesCfg.auction, 80) // 400 initial - 320 selected + requireSliceContainsNumOfElements(t, getAllPubKeys(currNodesCfg.waiting), prevConfig.auction, 320) // 320 selected + requireSliceContainsNumOfElements(t, currNodesCfg.auction, prevConfig.auction, 80) // 80 unselected + + // Add 400 new nodes in the system and fast-forward + node.ProcessStake(t, map[string]*NodesRegisterData{ + "ownerX": { + BLSKeys: generateAddresses(99999, 400), + TotalStake: big.NewInt(nodePrice * 400), + }, + }) + node.Process(t, 10) + + // UnStake exactly 80 nodes + prevConfig = node.NodesConfig + nodesToUnStake = getAllOwnerNodesMap(node.NodesConfig.eligible[1][:80]) + node.ProcessUnStake(t, nodesToUnStake) + node.Process(t, 4) + + currNodesCfg = node.NodesConfig + require.Len(t, getAllPubKeys(currNodesCfg.leaving), 80) // 320 - 80 leaving + require.Len(t, getAllPubKeys(currNodesCfg.shuffledOut), 240) // 240 shuffled out + requireSliceContainsNumOfElements(t, getAllPubKeys(currNodesCfg.waiting), prevConfig.auction, 320) // 320 selected + requireSliceContainsNumOfElements(t, currNodesCfg.auction, prevConfig.auction, 80) // 80 unselected } diff --git a/integrationTests/vm/staking/testMetaProcessorWithCustomNodesConfig.go b/integrationTests/vm/staking/testMetaProcessorWithCustomNodesConfig.go index 841a2b77b43..f9e9da84a8d 100644 --- a/integrationTests/vm/staking/testMetaProcessorWithCustomNodesConfig.go +++ b/integrationTests/vm/staking/testMetaProcessorWithCustomNodesConfig.go @@ -115,7 +115,7 @@ func (tmp *TestMetaProcessor) doStake( CallerAddr: owner, Arguments: createStakeArgs(registerData.BLSKeys), CallValue: registerData.TotalStake, - GasProvided: 10, + GasProvided: 400, }, RecipientAddr: vm.ValidatorSCAddress, Function: "stake", diff --git a/testscommon/stakingcommon/stakingDataProviderStub.go b/testscommon/stakingcommon/stakingDataProviderStub.go index b6b356cc1e7..27ec1a550e2 100644 --- a/testscommon/stakingcommon/stakingDataProviderStub.go +++ b/testscommon/stakingcommon/stakingDataProviderStub.go @@ -88,6 +88,7 @@ func (sdps *StakingDataProviderStub) GetNumOfValidatorsInCurrentEpoch() uint32 { return 0 } +// GetCurrentEpochValidatorStats - func (sdps *StakingDataProviderStub) GetCurrentEpochValidatorStats() epochStart.ValidatorStatsInEpoch { return epochStart.ValidatorStatsInEpoch{ Eligible: map[uint32]int{}, From ddd8cdb791e650bd67a27e4df8dcce2330c396df Mon Sep 17 00:00:00 2001 From: MariusC Date: Fri, 12 Apr 2024 16:31:27 +0300 Subject: [PATCH 046/467] FEAT: Integration tests chain simulator with leaving active nodes --- integrationTests/chainSimulator/interface.go | 2 + .../staking/stake/stakeAndUnStake_test.go | 163 ++++++++++++++++++ 2 files changed, 165 insertions(+) diff --git a/integrationTests/chainSimulator/interface.go b/integrationTests/chainSimulator/interface.go index eff1aac7874..759858a69c5 100644 --- a/integrationTests/chainSimulator/interface.go +++ b/integrationTests/chainSimulator/interface.go @@ -5,6 +5,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data/api" "github.com/multiversx/mx-chain-core-go/data/transaction" + crypto "github.com/multiversx/mx-chain-crypto-go" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" "github.com/multiversx/mx-chain-go/node/chainSimulator/process" ) @@ -22,4 +23,5 @@ type ChainSimulator interface { GetInitialWalletKeys() *dtos.InitialWalletKeys GetAccount(address dtos.WalletAddress) (api.AccountResponse, error) ForceResetValidatorStatisticsCache() error + GetValidatorPrivateKeys() []crypto.PrivateKey } diff --git a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index 2b2246df713..57a8df77cec 100644 --- a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go @@ -4,6 +4,7 @@ import ( "encoding/hex" "fmt" "math/big" + "strings" "testing" "time" @@ -2302,3 +2303,165 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInEpoch(t *testing.T, cs require.Equal(t, 1, balanceAfterUnbonding.Cmp(balanceBeforeUnbonding)) } + +// Test that if we unStake one active node(waiting/eligible), the number of qualified nodes will remain the same +// Nodes configuration at genesis consisting of a total of 32 nodes, distributed on 3 shards + meta: +// - 4 eligible nodes/shard +// - 4 waiting nodes/shard +// - 2 nodes to shuffle per shard +// - max num nodes config for stakingV4 step3 = 24 (being downsized from previously 32 nodes) +// - with this config, we should always select 8 nodes from auction list +// We will add one extra node, so auction list size = 9, but will always select 8. Even if we unStake one active node, +// we should still only select 8 nodes. +func TestChainSimulator_UnStakeOneActiveNodeAndCheckAPIAuctionList(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 30, + } + + stakingV4Step1Epoch := uint32(2) + stakingV4Step2Epoch := uint32(3) + stakingV4Step3Epoch := uint32(4) + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 4, + MetaChainMinNodes: 4, + NumNodesWaitingListMeta: 4, + NumNodesWaitingListShard: 4, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = stakingV4Step1Epoch + cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = stakingV4Step2Epoch + cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = stakingV4Step3Epoch + + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[1].MaxNumNodes = 32 + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[1].NodesToShufflePerShard = 2 + + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = stakingV4Step3Epoch + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].MaxNumNodes = 24 + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].NodesToShufflePerShard = 2 + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + err = cs.GenerateBlocksUntilEpochIsReached(int32(stakingV4Step3Epoch + 1)) + require.Nil(t, err) + + metachainNode := cs.GetNodeHandler(core.MetachainShardId) + + numQualified, numUnQualified := getNumQualifiedAndUnqualified(t, metachainNode) + require.Equal(t, 8, numQualified) + require.Equal(t, 0, numUnQualified) + + stakeOneNode(t, cs) + + numQualified, numUnQualified = getNumQualifiedAndUnqualified(t, metachainNode) + require.Equal(t, 8, numQualified) + require.Equal(t, 1, numUnQualified) + + unStakeOneActiveNode(t, cs) + + numQualified, numUnQualified = getNumQualifiedAndUnqualified(t, metachainNode) + require.Equal(t, 8, numQualified) + require.Equal(t, 1, numUnQualified) +} + +func stakeOneNode(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator) { + privateKey, blsKeys, err := chainSimulator.GenerateBlsPrivateKeys(1) + require.Nil(t, err) + err = cs.AddValidatorKeys(privateKey) + require.Nil(t, err) + + mintValue := big.NewInt(0).Add(staking.MinimumStakeValue, staking.OneEGLD) + validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) + require.Nil(t, err) + + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, stakeTx) + + require.Nil(t, cs.GenerateBlocks(1)) +} + +func unStakeOneActiveNode(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator) { + err := cs.ForceResetValidatorStatisticsCache() + require.Nil(t, err) + + validators, err := cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ValidatorStatisticsApi() + require.Nil(t, err) + + idx := 0 + keyToUnStake := make([]byte, 0) + numKeys := len(cs.GetValidatorPrivateKeys()) + for idx = 0; idx < numKeys; idx++ { + keyToUnStake, err = cs.GetValidatorPrivateKeys()[idx].GeneratePublic().ToByteArray() + require.Nil(t, err) + + apiValidator, found := validators[hex.EncodeToString(keyToUnStake)] + require.True(t, found) + + validatorStatus := apiValidator.ValidatorStatus + if validatorStatus == "waiting" || validatorStatus == "eligible" { + log.Info("found active key to unStake", "index", idx, "bls key", keyToUnStake, "list", validatorStatus) + break + } + + if idx == numKeys-1 { + require.Fail(t, "did not find key to unStake") + } + } + + rcv := "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqplllst77y4l" + rcvAddrBytes, _ := cs.GetNodeHandler(0).GetCoreComponents().AddressPubKeyConverter().Decode(rcv) + + validatorWallet := cs.GetInitialWalletKeys().StakeWallets[idx].Address + shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(validatorWallet.Bytes) + initialAccount, _, err := cs.GetNodeHandler(shardID).GetFacadeHandler().GetAccount(validatorWallet.Bech32, coreAPI.AccountQueryOptions{}) + + require.Nil(t, err) + tx := &transaction.Transaction{ + Nonce: initialAccount.Nonce, + Value: big.NewInt(0), + SndAddr: validatorWallet.Bytes, + RcvAddr: rcvAddrBytes, + Data: []byte(fmt.Sprintf("unStake@%s", hex.EncodeToString(keyToUnStake))), + GasLimit: 50_000_000, + GasPrice: 1000000000, + Signature: []byte("dummy"), + ChainID: []byte(configs.ChainID), + Version: 1, + } + _, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + + err = cs.GenerateBlocks(1) + require.Nil(t, err) + + err = cs.ForceResetValidatorStatisticsCache() + require.Nil(t, err) + validators, err = cs.GetNodeHandler(core.MetachainShardId).GetFacadeHandler().ValidatorStatisticsApi() + require.Nil(t, err) + + apiValidator, found := validators[hex.EncodeToString(keyToUnStake)] + require.True(t, found) + require.True(t, strings.Contains(apiValidator.ValidatorStatus, "leaving")) +} From 4626f801f8f7fb6b8cc8c22aa7b7ccb56a45d6df Mon Sep 17 00:00:00 2001 From: MariusC Date: Fri, 12 Apr 2024 17:23:57 +0300 Subject: [PATCH 047/467] CLN: Comm --- integrationTests/vm/staking/stakingV4_test.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/integrationTests/vm/staking/stakingV4_test.go b/integrationTests/vm/staking/stakingV4_test.go index b6a351ed7f7..f927ddadfe3 100644 --- a/integrationTests/vm/staking/stakingV4_test.go +++ b/integrationTests/vm/staking/stakingV4_test.go @@ -1541,11 +1541,6 @@ func TestStakingV4_LeavingNodesEdgeCases(t *testing.T) { require.Zero(t, len(owner1LeftNodes)) } -// TODO if necessary: -// - test with limit (unstake exactly 80 per shard) -// - unstake more nodes when waiting lists are pretty empty -// - chain simulator api calls - func TestStakingV4LeavingNodesShouldDistributeToWaitingOnlyNecessaryNodes(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") From e1d0f11464dc3bdae9b63a57861052a61ec79283 Mon Sep 17 00:00:00 2001 From: MariusC Date: Fri, 12 Apr 2024 17:31:43 +0300 Subject: [PATCH 048/467] FIX: Remove StakingQueueEnabled flag --- common/constants.go | 1 - common/enablers/enableEpochsHandler.go | 6 ----- common/enablers/enableEpochsHandler_test.go | 9 -------- epochStart/metachain/legacySystemSCs.go | 25 +++++++++++---------- epochStart/metachain/systemSCs.go | 1 - 5 files changed, 13 insertions(+), 29 deletions(-) diff --git a/common/constants.go b/common/constants.go index 0476f1aa5e5..16c77a5d147 100644 --- a/common/constants.go +++ b/common/constants.go @@ -1011,7 +1011,6 @@ const ( StakingV4Step1Flag core.EnableEpochFlag = "StakingV4Step1Flag" StakingV4Step2Flag core.EnableEpochFlag = "StakingV4Step2Flag" StakingV4Step3Flag core.EnableEpochFlag = "StakingV4Step3Flag" - StakingQueueFlag core.EnableEpochFlag = "StakingQueueFlag" StakingV4StartedFlag core.EnableEpochFlag = "StakingV4StartedFlag" AlwaysMergeContextsInEEIFlag core.EnableEpochFlag = "AlwaysMergeContextsInEEIFlag" // all new flags must be added to createAllFlagsMap method, as part of enableEpochsHandler allFlagsDefined diff --git a/common/enablers/enableEpochsHandler.go b/common/enablers/enableEpochsHandler.go index d560a432462..f64dbf99ea5 100644 --- a/common/enablers/enableEpochsHandler.go +++ b/common/enablers/enableEpochsHandler.go @@ -713,12 +713,6 @@ func (handler *enableEpochsHandler) createAllFlagsMap() { }, activationEpoch: handler.enableEpochsConfig.StakingV4Step3EnableEpoch, }, - common.StakingQueueFlag: { - isActiveInEpoch: func(epoch uint32) bool { - return epoch < handler.enableEpochsConfig.StakingV4Step1EnableEpoch - }, - activationEpoch: handler.enableEpochsConfig.StakingV4Step1EnableEpoch, - }, common.StakingV4StartedFlag: { isActiveInEpoch: func(epoch uint32) bool { return epoch >= handler.enableEpochsConfig.StakingV4Step1EnableEpoch diff --git a/common/enablers/enableEpochsHandler_test.go b/common/enablers/enableEpochsHandler_test.go index c91f65b805a..4155b15dfbb 100644 --- a/common/enablers/enableEpochsHandler_test.go +++ b/common/enablers/enableEpochsHandler_test.go @@ -192,13 +192,6 @@ func TestEnableEpochsHandler_IsFlagEnabled(t *testing.T) { handler.EpochConfirmed(cfg.SetGuardianEnableEpoch+1, 0) require.True(t, handler.IsFlagEnabled(common.SetGuardianFlag)) - handler.EpochConfirmed(cfg.StakingV4Step1EnableEpoch-1, 0) - require.True(t, handler.IsFlagEnabled(common.StakingQueueFlag)) - handler.EpochConfirmed(cfg.StakingV4Step1EnableEpoch, 0) - require.False(t, handler.IsFlagEnabled(common.StakingQueueFlag)) - handler.EpochConfirmed(cfg.StakingV4Step1EnableEpoch+1, 0) - require.False(t, handler.IsFlagEnabled(common.StakingQueueFlag)) - handler.EpochConfirmed(cfg.StakingV4Step1EnableEpoch-1, 0) require.False(t, handler.IsFlagEnabled(common.StakingV4StartedFlag)) handler.EpochConfirmed(cfg.StakingV4Step1EnableEpoch, 0) @@ -318,7 +311,6 @@ func TestEnableEpochsHandler_IsFlagEnabled(t *testing.T) { require.False(t, handler.IsFlagEnabled(common.StakingV4Step1Flag)) require.True(t, handler.IsFlagEnabled(common.StakingV4Step2Flag)) require.True(t, handler.IsFlagEnabled(common.StakingV4Step3Flag)) - require.False(t, handler.IsFlagEnabled(common.StakingQueueFlag)) require.True(t, handler.IsFlagEnabled(common.StakingV4StartedFlag)) require.True(t, handler.IsFlagEnabled(common.AlwaysMergeContextsInEEIFlag)) } @@ -434,7 +426,6 @@ func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) { require.Equal(t, cfg.StakingV4Step1EnableEpoch, handler.GetActivationEpoch(common.StakingV4Step1Flag)) require.Equal(t, cfg.StakingV4Step2EnableEpoch, handler.GetActivationEpoch(common.StakingV4Step2Flag)) require.Equal(t, cfg.StakingV4Step3EnableEpoch, handler.GetActivationEpoch(common.StakingV4Step3Flag)) - require.Equal(t, cfg.StakingV4Step1EnableEpoch, handler.GetActivationEpoch(common.StakingQueueFlag)) require.Equal(t, cfg.StakingV4Step1EnableEpoch, handler.GetActivationEpoch(common.StakingV4StartedFlag)) require.Equal(t, cfg.AlwaysMergeContextsInEEIEnableEpoch, handler.GetActivationEpoch(common.AlwaysMergeContextsInEEIFlag)) } diff --git a/epochStart/metachain/legacySystemSCs.go b/epochStart/metachain/legacySystemSCs.go index 2abe8a993fb..677cbcb682b 100644 --- a/epochStart/metachain/legacySystemSCs.go +++ b/epochStart/metachain/legacySystemSCs.go @@ -207,7 +207,7 @@ func (s *legacySystemSCProcessor) processLegacy( return err } - if s.enableEpochsHandler.IsFlagEnabled(common.StakingQueueFlag) { + if !s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) { err = s.stakeNodesFromQueue(validatorsInfoMap, numUnStaked, nonce, common.NewList) if err != nil { return err @@ -598,20 +598,21 @@ func (s *legacySystemSCProcessor) updateMaxNodes(validatorsInfoMap state.ShardVa return err } - if !s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) { - if maxNumberOfNodes < prevMaxNumberOfNodes { - return epochStart.ErrInvalidMaxNumberOfNodes - } + if s.enableEpochsHandler.IsFlagEnabled(common.StakingV4StartedFlag) { + return nil } - if s.enableEpochsHandler.IsFlagEnabled(common.StakingQueueFlag) { - sw.Start("stakeNodesFromQueue") - err = s.stakeNodesFromQueue(validatorsInfoMap, maxNumberOfNodes-prevMaxNumberOfNodes, nonce, common.NewList) - sw.Stop("stakeNodesFromQueue") - if err != nil { - return err - } + if maxNumberOfNodes < prevMaxNumberOfNodes { + return epochStart.ErrInvalidMaxNumberOfNodes } + + sw.Start("stakeNodesFromQueue") + err = s.stakeNodesFromQueue(validatorsInfoMap, maxNumberOfNodes-prevMaxNumberOfNodes, nonce, common.NewList) + sw.Stop("stakeNodesFromQueue") + if err != nil { + return err + } + return nil } diff --git a/epochStart/metachain/systemSCs.go b/epochStart/metachain/systemSCs.go index 229a41d5710..96cba60251b 100644 --- a/epochStart/metachain/systemSCs.go +++ b/epochStart/metachain/systemSCs.go @@ -78,7 +78,6 @@ func NewSystemSCProcessor(args ArgsNewEpochStartSystemSCProcessing) (*systemSCPr common.SaveJailedAlwaysFlag, common.StakingV4Step1Flag, common.StakingV4Step2Flag, - common.StakingQueueFlag, common.StakingV4StartedFlag, common.DelegationSmartContractFlagInSpecificEpochOnly, common.GovernanceFlagInSpecificEpochOnly, From a67343ddd00bba279ae921ae98a9165ccce15692 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Fri, 12 Apr 2024 18:00:58 +0300 Subject: [PATCH 049/467] 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 050/467] 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 051/467] 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 052/467] 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 053/467] removed commented code --- process/transaction/shardProcess.go | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index 3d50cea16a5..efa6e0a14e9 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -1215,20 +1215,6 @@ func (txProc *txProcessor) processInnerTxsFeesAfterSnapshot(tx *transaction.Tran sendersBalancesSnapshot[senderAcnt] = prevBalanceForSender } - // if one error occurred, revert all transfers that succeeded and return error - //if lastTransferErr != nil { - // for i := 0; i < lastIdx; i++ { - // uniqueSender := uniqueSendersSlice[i] - // totalFessSentForSender := uniqueSendersMap[uniqueSender] - // _, _, err = txProc.addFeesToDest([]byte(uniqueSender), big.NewInt(0).Neg(totalFessSentForSender)) - // if err != nil { - // log.Warn("could not revert the fees transferred from relayer to sender", - // "sender", txProc.pubkeyConv.SilentEncode([]byte(uniqueSender), log), - // "relayer", txProc.pubkeyConv.SilentEncode(relayerAcnt.AddressBytes(), log)) - // } - // } - //} - return sendersBalancesSnapshot, lastTransferErr } From 5258bf0881dc2da18de677db74856a72ab31e708 Mon Sep 17 00:00:00 2001 From: MariusC Date: Tue, 16 Apr 2024 11:05:58 +0300 Subject: [PATCH 054/467] CLN: Test + fix linter --- integrationTests/vm/staking/stakingV4_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/integrationTests/vm/staking/stakingV4_test.go b/integrationTests/vm/staking/stakingV4_test.go index f927ddadfe3..077c87c407b 100644 --- a/integrationTests/vm/staking/stakingV4_test.go +++ b/integrationTests/vm/staking/stakingV4_test.go @@ -1641,10 +1641,8 @@ func TestStakingV4LeavingNodesShouldDistributeToWaitingOnlyNecessaryNodes(t *tes require.Len(t, currNodesCfg.auction, 343) // 400 initial - 57 leaving requireSliceContainsNumOfElements(t, getAllPubKeys(currNodesCfg.waiting), prevConfig.auction, 320) // 320 selected requireSliceContainsNumOfElements(t, currNodesCfg.auction, prevConfig.auction, 69) // 69 unselected - - nodesToUnStakeFromAuction = make([][]byte, 0) - nodesToUnStakeFromWaiting = make([][]byte, 0) - nodesToUnStakeFromEligible = make([][]byte, 0) + require.Len(t, getAllPubKeys(currNodesCfg.eligible), 1600) + require.Len(t, getAllPubKeys(currNodesCfg.waiting), 1280) prevConfig = currNodesCfg // UnStake: @@ -1680,6 +1678,8 @@ func TestStakingV4LeavingNodesShouldDistributeToWaitingOnlyNecessaryNodes(t *tes require.Len(t, currNodesCfg.auction, 150) // 138 shuffled out + 12 unselected requireSliceContainsNumOfElements(t, getAllPubKeys(currNodesCfg.waiting), prevConfig.auction, 320) // 320 selected requireSliceContainsNumOfElements(t, currNodesCfg.auction, prevConfig.auction, 12) // 12 unselected + require.Len(t, getAllPubKeys(currNodesCfg.eligible), 1600) + require.Len(t, getAllPubKeys(currNodesCfg.waiting), 1280) } func TestStakingV4MoreLeavingNodesThanToShufflePerShard(t *testing.T) { @@ -1763,6 +1763,8 @@ func TestStakingV4MoreLeavingNodesThanToShufflePerShard(t *testing.T) { require.Len(t, currNodesCfg.auction, 80) // 400 initial - 320 selected requireSliceContainsNumOfElements(t, getAllPubKeys(currNodesCfg.waiting), prevConfig.auction, 320) // 320 selected requireSliceContainsNumOfElements(t, currNodesCfg.auction, prevConfig.auction, 80) // 80 unselected + require.Len(t, getAllPubKeys(currNodesCfg.eligible), 1600) + require.Len(t, getAllPubKeys(currNodesCfg.waiting), 1280) // Add 400 new nodes in the system and fast-forward node.ProcessStake(t, map[string]*NodesRegisterData{ @@ -1784,4 +1786,6 @@ func TestStakingV4MoreLeavingNodesThanToShufflePerShard(t *testing.T) { require.Len(t, getAllPubKeys(currNodesCfg.shuffledOut), 240) // 240 shuffled out requireSliceContainsNumOfElements(t, getAllPubKeys(currNodesCfg.waiting), prevConfig.auction, 320) // 320 selected requireSliceContainsNumOfElements(t, currNodesCfg.auction, prevConfig.auction, 80) // 80 unselected + require.Len(t, getAllPubKeys(currNodesCfg.eligible), 1600) + require.Len(t, getAllPubKeys(currNodesCfg.waiting), 1280) } From 10411000c3fd12ceba2da7dcabc180b9d38a3f7e Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Tue, 16 Apr 2024 18:59:13 +0300 Subject: [PATCH 055/467] over writable map fixes --- common/reflectcommon/structFieldsUpdate.go | 10 +- .../reflectcommon/structFieldsUpdate_test.go | 242 ++++++++---------- testscommon/toml/config.go | 27 +- testscommon/toml/config.toml | 5 +- testscommon/toml/overwrite.toml | 64 ++--- 5 files changed, 163 insertions(+), 185 deletions(-) diff --git a/common/reflectcommon/structFieldsUpdate.go b/common/reflectcommon/structFieldsUpdate.go index 66434365179..be8671eff4f 100644 --- a/common/reflectcommon/structFieldsUpdate.go +++ b/common/reflectcommon/structFieldsUpdate.go @@ -175,7 +175,15 @@ func tryUpdateMapValue(value *reflect.Value, newValue reflect.Value) error { switch newValue.Kind() { case reflect.Map: for _, key := range newValue.MapKeys() { - value.SetMapIndex(key, newValue.MapIndex(key)) + item := newValue.MapIndex(key) + newItem := reflect.New(value.Type().Elem()).Elem() + + err := trySetTheNewValue(&newItem, item.Interface()) + if err != nil { + return err + } + + value.SetMapIndex(key, newItem) } default: return fmt.Errorf("unsupported type <%s> when trying to add value in type <%s>", newValue.Kind(), value.Kind()) diff --git a/common/reflectcommon/structFieldsUpdate_test.go b/common/reflectcommon/structFieldsUpdate_test.go index e59695598f4..44d3ae7d694 100644 --- a/common/reflectcommon/structFieldsUpdate_test.go +++ b/common/reflectcommon/structFieldsUpdate_test.go @@ -518,11 +518,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI8.Int8.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[0].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[0].Path, overrideConfig.OverridableConfigTomlValues[0].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[0].Value, int64(testConfig.Int8.Value)) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[0].Value, int64(testConfig.Int8.Number)) }) t.Run("should error int8 value", func(t *testing.T) { @@ -534,9 +532,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI8.Int8.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[1].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[1].Path, overrideConfig.OverridableConfigTomlValues[1].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '128' of type to type ", err.Error()) }) @@ -550,11 +546,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI8.Int8.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[2].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[2].Path, overrideConfig.OverridableConfigTomlValues[2].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[2].Value, int64(testConfig.Int8.Value)) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[2].Value, int64(testConfig.Int8.Number)) }) t.Run("should error int8 negative value", func(t *testing.T) { @@ -566,9 +560,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI8.Int8.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[3].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[3].Path, overrideConfig.OverridableConfigTomlValues[3].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '-129' of type to type ", err.Error()) }) @@ -582,11 +574,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI16.Int16.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[4].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[4].Path, overrideConfig.OverridableConfigTomlValues[4].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[4].Value, int64(testConfig.Int16.Value)) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[4].Value, int64(testConfig.Int16.Number)) }) t.Run("should error int16 value", func(t *testing.T) { @@ -598,9 +588,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI16.Int16.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[5].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[5].Path, overrideConfig.OverridableConfigTomlValues[5].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '32768' of type to type ", err.Error()) }) @@ -614,11 +602,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI16.Int16.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[6].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[6].Path, overrideConfig.OverridableConfigTomlValues[6].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[6].Value, int64(testConfig.Int16.Value)) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[6].Value, int64(testConfig.Int16.Number)) }) t.Run("should error int16 negative value", func(t *testing.T) { @@ -630,9 +616,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI16.Int16.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[7].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[7].Path, overrideConfig.OverridableConfigTomlValues[7].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '-32769' of type to type ", err.Error()) }) @@ -646,11 +630,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI32.Int32.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[17].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[8].Path, overrideConfig.OverridableConfigTomlValues[8].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[17].Value, int64(testConfig.Int32.Value)) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[8].Value, int64(testConfig.Int32.Number)) }) t.Run("should work and override int32 value with uint16", func(t *testing.T) { @@ -661,11 +643,11 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { expectedNewValue := uint16(10) - path := "TestConfigI32.Int32.Value" + path := "TestConfigI32.Int32.Number" err = AdaptStructureValueBasedOnPath(testConfig, path, expectedNewValue) require.NoError(t, err) - require.Equal(t, int32(expectedNewValue), testConfig.Int32.Value) + require.Equal(t, int32(expectedNewValue), testConfig.Int32.Number) }) t.Run("should error int32 value", func(t *testing.T) { @@ -677,9 +659,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI32.Int32.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[9].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[9].Path, overrideConfig.OverridableConfigTomlValues[9].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '2147483648' of type to type ", err.Error()) }) @@ -693,11 +673,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI32.Int32.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[10].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[10].Path, overrideConfig.OverridableConfigTomlValues[10].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[10].Value, int64(testConfig.Int32.Value)) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[10].Value, int64(testConfig.Int32.Number)) }) t.Run("should error int32 negative value", func(t *testing.T) { @@ -709,9 +687,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI32.Int32.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[11].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[11].Path, overrideConfig.OverridableConfigTomlValues[11].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '-2147483649' of type to type ", err.Error()) }) @@ -725,11 +701,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI64.Int64.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[12].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[12].Path, overrideConfig.OverridableConfigTomlValues[12].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[12].Value, int64(testConfig.Int64.Value)) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[12].Value, int64(testConfig.Int64.Number)) }) t.Run("should work and override int64 negative value", func(t *testing.T) { @@ -741,11 +715,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigI64.Int64.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[13].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[13].Path, overrideConfig.OverridableConfigTomlValues[13].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[13].Value, int64(testConfig.Int64.Value)) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[13].Value, int64(testConfig.Int64.Number)) }) t.Run("should work and override uint8 value", func(t *testing.T) { @@ -757,11 +729,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigU8.Uint8.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[14].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[14].Path, overrideConfig.OverridableConfigTomlValues[14].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[14].Value, int64(testConfig.Uint8.Value)) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[14].Value, int64(testConfig.Uint8.Number)) }) t.Run("should error uint8 value", func(t *testing.T) { @@ -773,9 +743,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigU8.Uint8.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[15].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[15].Path, overrideConfig.OverridableConfigTomlValues[15].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '256' of type to type ", err.Error()) }) @@ -789,9 +757,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigU8.Uint8.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[16].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[16].Path, overrideConfig.OverridableConfigTomlValues[16].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '-256' of type to type ", err.Error()) }) @@ -805,11 +771,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigU16.Uint16.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[17].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[17].Path, overrideConfig.OverridableConfigTomlValues[17].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[17].Value, int64(testConfig.Uint16.Value)) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[17].Value, int64(testConfig.Uint16.Number)) }) t.Run("should error uint16 value", func(t *testing.T) { @@ -821,9 +785,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigU16.Uint16.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[18].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[18].Path, overrideConfig.OverridableConfigTomlValues[18].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '65536' of type to type ", err.Error()) }) @@ -837,9 +799,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigU16.Uint16.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[19].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[19].Path, overrideConfig.OverridableConfigTomlValues[19].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '-65536' of type to type ", err.Error()) }) @@ -853,11 +813,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigU32.Uint32.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[20].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[20].Path, overrideConfig.OverridableConfigTomlValues[20].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[20].Value, int64(testConfig.Uint32.Value)) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[20].Value, int64(testConfig.Uint32.Number)) }) t.Run("should error uint32 value", func(t *testing.T) { @@ -869,9 +827,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigU32.Uint32.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[21].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[21].Path, overrideConfig.OverridableConfigTomlValues[21].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '4294967296' of type to type ", err.Error()) }) @@ -885,9 +841,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigU32.Uint32.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[22].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[22].Path, overrideConfig.OverridableConfigTomlValues[22].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '-4294967296' of type to type ", err.Error()) }) @@ -901,11 +855,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigU64.Uint64.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[23].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[23].Path, overrideConfig.OverridableConfigTomlValues[23].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[23].Value, int64(testConfig.Uint64.Value)) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[23].Value, int64(testConfig.Uint64.Number)) }) t.Run("should error uint64 negative value", func(t *testing.T) { @@ -917,9 +869,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigU64.Uint64.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[24].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[24].Path, overrideConfig.OverridableConfigTomlValues[24].Value) require.Equal(t, "unable to cast value '-9223372036854775808' of type to type ", err.Error()) }) @@ -932,11 +882,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigF32.Float32.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[25].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[25].Path, overrideConfig.OverridableConfigTomlValues[25].Value) require.NoError(t, err) - require.Equal(t, float32(3.4), testConfig.Float32.Value) + require.Equal(t, float32(3.4), testConfig.Float32.Number) }) t.Run("should error float32 value", func(t *testing.T) { @@ -948,9 +896,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigF32.Float32.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[26].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[26].Path, overrideConfig.OverridableConfigTomlValues[26].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '3.4e+39' of type to type ", err.Error()) }) @@ -964,11 +910,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigF32.Float32.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[27].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[27].Path, overrideConfig.OverridableConfigTomlValues[27].Value) require.NoError(t, err) - require.Equal(t, float32(-3.4), testConfig.Float32.Value) + require.Equal(t, float32(-3.4), testConfig.Float32.Number) }) t.Run("should error float32 negative value", func(t *testing.T) { @@ -980,9 +924,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigF32.Float32.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[28].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[28].Path, overrideConfig.OverridableConfigTomlValues[28].Value) require.NotNil(t, err) require.Equal(t, "unable to cast value '-3.4e+40' of type to type ", err.Error()) }) @@ -996,11 +938,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigF64.Float64.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[29].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[29].Path, overrideConfig.OverridableConfigTomlValues[29].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[29].Value, testConfig.Float64.Value) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[29].Value, testConfig.Float64.Number) }) t.Run("should work and override float64 negative value", func(t *testing.T) { @@ -1012,11 +952,9 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigF64.Float64.Value" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[30].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[30].Path, overrideConfig.OverridableConfigTomlValues[30].Value) require.NoError(t, err) - require.Equal(t, overrideConfig.OverridableConfigTomlValues[30].Value, testConfig.Float64.Value) + require.Equal(t, overrideConfig.OverridableConfigTomlValues[30].Value, testConfig.Float64.Number) }) t.Run("should work and override struct", func(t *testing.T) { @@ -1028,13 +966,11 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigStruct.ConfigStruct.Description" - expectedNewValue := toml.Description{ Number: 11, } - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[31].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[31].Path, overrideConfig.OverridableConfigTomlValues[31].Value) require.NoError(t, err) require.Equal(t, expectedNewValue, testConfig.TestConfigStruct.ConfigStruct.Description) }) @@ -1048,9 +984,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigStruct.ConfigStruct.Description" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[32].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[32].Path, overrideConfig.OverridableConfigTomlValues[32].Value) require.Equal(t, "field not found or cannot be set", err.Error()) }) @@ -1063,9 +997,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigStruct.ConfigStruct.Description" - - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[33].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[33].Path, overrideConfig.OverridableConfigTomlValues[33].Value) require.Equal(t, "unable to cast value '11' of type to type ", err.Error()) }) @@ -1078,8 +1010,6 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigNestedStruct.ConfigNestedStruct" - expectedNewValue := toml.ConfigNestedStruct{ Text: "Overwritten text", Message: toml.Message{ @@ -1090,7 +1020,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { }, } - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[34].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[34].Path, overrideConfig.OverridableConfigTomlValues[34].Value) require.NoError(t, err) require.Equal(t, expectedNewValue, testConfig.TestConfigNestedStruct.ConfigNestedStruct) }) @@ -1104,14 +1034,12 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") require.NoError(t, err) - path := "TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription" - expectedNewValue := []toml.MessageDescription{ {Text: "Overwritten Text1"}, {Text: "Overwritten Text2"}, } - err = AdaptStructureValueBasedOnPath(testConfig, path, overrideConfig.OverridableConfigTomlValues[35].Value) + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[35].Path, overrideConfig.OverridableConfigTomlValues[35].Value) require.NoError(t, err) require.Equal(t, expectedNewValue, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription) }) @@ -1194,38 +1122,72 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { require.Equal(t, expectedNewValue, testConfig.TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription) }) - t.Run("should work on map and override existing value in map", func(t *testing.T) { + t.Run("should work on map, override and insert from config", func(t *testing.T) { t.Parallel() testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") require.NoError(t, err) - expectedNewValue := make(map[string]int) - expectedNewValue["key"] = 100 + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) - path := "TestMap.Value" + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[36].Path, overrideConfig.OverridableConfigTomlValues[36].Value) + require.NoError(t, err) + require.Equal(t, 2, len(testConfig.TestMap.Map)) + require.Equal(t, 10, testConfig.TestMap.Map["Key1"].Number) + require.Equal(t, 11, testConfig.TestMap.Map["Key2"].Number) + }) - err = AdaptStructureValueBasedOnPath(testConfig, path, expectedNewValue) + t.Run("should work on map and insert from config", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + overrideConfig, err := loadOverrideConfig("../../testscommon/toml/overwrite.toml") + require.NoError(t, err) + + err = AdaptStructureValueBasedOnPath(testConfig, overrideConfig.OverridableConfigTomlValues[37].Path, overrideConfig.OverridableConfigTomlValues[37].Value) require.NoError(t, err) - require.Equal(t, 1, len(testConfig.TestMap.Value)) - require.Equal(t, testConfig.TestMap.Value["key"], 100) + require.Equal(t, 3, len(testConfig.TestMap.Map)) + require.Equal(t, 999, testConfig.TestMap.Map["Key1"].Number) + require.Equal(t, 2, testConfig.TestMap.Map["Key2"].Number) + require.Equal(t, 3, testConfig.TestMap.Map["Key3"].Number) }) - t.Run("should work on map and insert values in map", func(t *testing.T) { + t.Run("should work on map, override and insert values in map", func(t *testing.T) { t.Parallel() testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") require.NoError(t, err) - expectedNewValue := make(map[string]int) - expectedNewValue["first"] = 1 - expectedNewValue["second"] = 2 + expectedNewValue := make(map[string]toml.MapValues) + expectedNewValue["Key1"] = toml.MapValues{Number: 100} + expectedNewValue["Key2"] = toml.MapValues{Number: 200} - path := "TestMap.Value" + path := "TestMap.Map" err = AdaptStructureValueBasedOnPath(testConfig, path, expectedNewValue) require.NoError(t, err) - require.Equal(t, 3, len(testConfig.TestMap.Value)) + require.Equal(t, 2, len(testConfig.TestMap.Map)) + require.Equal(t, 100, testConfig.TestMap.Map["Key1"].Number) + require.Equal(t, 200, testConfig.TestMap.Map["Key2"].Number) + }) + + t.Run("should error on map when override different map", func(t *testing.T) { + t.Parallel() + + testConfig, err := loadTestConfig("../../testscommon/toml/config.toml") + require.NoError(t, err) + + expectedNewValue := make(map[string]toml.MessageDescription) + expectedNewValue["Key1"] = toml.MessageDescription{Text: "A"} + expectedNewValue["Key2"] = toml.MessageDescription{Text: "B"} + + path := "TestMap.Map" + + err = AdaptStructureValueBasedOnPath(testConfig, path, expectedNewValue) + require.Equal(t, "field not found or cannot be set", err.Error()) }) t.Run("should error on map when override anything else other than map", func(t *testing.T) { @@ -1236,7 +1198,7 @@ func TestAdaptStructureValueBasedOnPath(t *testing.T) { expectedNewValue := 1 - path := "TestMap.Value" + path := "TestMap.Map" err = AdaptStructureValueBasedOnPath(testConfig, path, expectedNewValue) require.Equal(t, "unsupported type when trying to add value in type ", err.Error()) diff --git a/testscommon/toml/config.go b/testscommon/toml/config.go index 16ec8a7fdd4..56cfeb1f0ad 100644 --- a/testscommon/toml/config.go +++ b/testscommon/toml/config.go @@ -25,7 +25,7 @@ type TestConfigI8 struct { // Int8 will hold the value type Int8 struct { - Value int8 + Number int8 } // TestConfigI16 will hold an int16 value for testing @@ -35,7 +35,7 @@ type TestConfigI16 struct { // Int16 will hold the value type Int16 struct { - Value int16 + Number int16 } // TestConfigI32 will hold an int32 value for testing @@ -45,7 +45,7 @@ type TestConfigI32 struct { // Int32 will hold the value type Int32 struct { - Value int32 + Number int32 } // TestConfigI64 will hold an int64 value for testing @@ -55,7 +55,7 @@ type TestConfigI64 struct { // Int64 will hold the value type Int64 struct { - Value int64 + Number int64 } // TestConfigU8 will hold an uint8 value for testing @@ -65,7 +65,7 @@ type TestConfigU8 struct { // Uint8 will hold the value type Uint8 struct { - Value uint8 + Number uint8 } // TestConfigU16 will hold an uint16 value for testing @@ -75,7 +75,7 @@ type TestConfigU16 struct { // Uint16 will hold the value type Uint16 struct { - Value uint16 + Number uint16 } // TestConfigU32 will hold an uint32 value for testing @@ -85,7 +85,7 @@ type TestConfigU32 struct { // Uint32 will hold the value type Uint32 struct { - Value uint32 + Number uint32 } // TestConfigU64 will hold an uint64 value for testing @@ -95,7 +95,7 @@ type TestConfigU64 struct { // Uint64 will hold the value type Uint64 struct { - Value uint64 + Number uint64 } // TestConfigF32 will hold a float32 value for testing @@ -105,7 +105,7 @@ type TestConfigF32 struct { // Float32 will hold the value type Float32 struct { - Value float32 + Number float32 } // TestConfigF64 will hold a float64 value for testing @@ -115,7 +115,7 @@ type TestConfigF64 struct { // Float64 will hold the value type Float64 struct { - Value float64 + Number float64 } // TestConfigStruct will hold a configuration struct for testing @@ -168,7 +168,12 @@ type MessageDescriptionOtherName struct { // TestMap will hold a map for testing type TestMap struct { - Value map[string]int + Map map[string]MapValues +} + +// MapValues will hold a value for map +type MapValues struct { + Number int } // TestInterface will hold an interface for testing diff --git a/testscommon/toml/config.toml b/testscommon/toml/config.toml index af54141fe5f..91512d5e664 100644 --- a/testscommon/toml/config.toml +++ b/testscommon/toml/config.toml @@ -48,5 +48,6 @@ Text = "Config Nested Struct" Mesage = { Public = true, MessageDescription = [{ Text = "Text1" }, { Text = "Text2"}] } -[TestMap] - Value = { "key" = 0 } +[Map] + [Map.Key1] + Number = 999 diff --git a/testscommon/toml/overwrite.toml b/testscommon/toml/overwrite.toml index 5d1e6690caf..63f74b7828c 100644 --- a/testscommon/toml/overwrite.toml +++ b/testscommon/toml/overwrite.toml @@ -1,38 +1,40 @@ OverridableConfigTomlValues = [ - { File = "config.toml", Path = "TestConfigI8.Int8", Value = 127 }, - { File = "config.toml", Path = "TestConfigI8.Int8", Value = 128 }, - { File = "config.toml", Path = "TestConfigI8.Int8", Value = -128 }, - { File = "config.toml", Path = "TestConfigI8.Int8", Value = -129 }, - { File = "config.toml", Path = "TestConfigI16.Int16", Value = 32767 }, - { File = "config.toml", Path = "TestConfigI16.Int16", Value = 32768 }, - { File = "config.toml", Path = "TestConfigI16.Int16", Value = -32768 }, - { File = "config.toml", Path = "TestConfigI16.Int16", Value = -32769 }, - { File = "config.toml", Path = "TestConfigI32.Int32", Value = 2147483647 }, - { File = "config.toml", Path = "TestConfigI32.Int32", Value = 2147483648 }, - { File = "config.toml", Path = "TestConfigI32.Int32", Value = -2147483648 }, - { File = "config.toml", Path = "TestConfigI32.Int32", Value = -2147483649 }, - { File = "config.toml", Path = "TestConfigI32.Int64", Value = 9223372036854775807 }, - { File = "config.toml", Path = "TestConfigI32.Int64", Value = -9223372036854775808 }, - { File = "config.toml", Path = "TestConfigU8.Uint8", Value = 255 }, - { File = "config.toml", Path = "TestConfigU8.Uint8", Value = 256 }, - { File = "config.toml", Path = "TestConfigU8.Uint8", Value = -256 }, - { File = "config.toml", Path = "TestConfigU16.Uint16", Value = 65535 }, - { File = "config.toml", Path = "TestConfigU16.Uint16", Value = 65536 }, - { File = "config.toml", Path = "TestConfigU16.Uint16", Value = -65536 }, - { File = "config.toml", Path = "TestConfigU32.Uint32", Value = 4294967295 }, - { File = "config.toml", Path = "TestConfigU32.Uint32", Value = 4294967296 }, - { File = "config.toml", Path = "TestConfigU32.Uint32", Value = -4294967296 }, - { File = "config.toml", Path = "TestConfigU64.Uint64", Value = 9223372036854775807 }, - { File = "config.toml", Path = "TestConfigU64.Uint64", Value = -9223372036854775808 }, - { File = "config.toml", Path = "TestConfigF32.Float32", Value = 3.4 }, - { File = "config.toml", Path = "TestConfigF32.Float32", Value = 3.4e+39 }, - { File = "config.toml", Path = "TestConfigF32.Float32", Value = -3.4 }, - { File = "config.toml", Path = "TestConfigF32.Float32", Value = -3.4e+40 }, - { File = "config.toml", Path = "TestConfigF64.Float64", Value = 1.7e+308 }, - { File = "config.toml", Path = "TestConfigF64.Float64", Value = -1.7e+308 }, + { File = "config.toml", Path = "TestConfigI8.Int8.Number", Value = 127 }, + { File = "config.toml", Path = "TestConfigI8.Int8.Number", Value = 128 }, + { File = "config.toml", Path = "TestConfigI8.Int8.Number", Value = -128 }, + { File = "config.toml", Path = "TestConfigI8.Int8.Number", Value = -129 }, + { File = "config.toml", Path = "TestConfigI16.Int16.Number", Value = 32767 }, + { File = "config.toml", Path = "TestConfigI16.Int16.Number", Value = 32768 }, + { File = "config.toml", Path = "TestConfigI16.Int16.Number", Value = -32768 }, + { File = "config.toml", Path = "TestConfigI16.Int16.Number", Value = -32769 }, + { File = "config.toml", Path = "TestConfigI32.Int32.Number", Value = 2147483647 }, + { File = "config.toml", Path = "TestConfigI32.Int32.Number", Value = 2147483648 }, + { File = "config.toml", Path = "TestConfigI32.Int32.Number", Value = -2147483648 }, + { File = "config.toml", Path = "TestConfigI32.Int32.Number", Value = -2147483649 }, + { File = "config.toml", Path = "TestConfigI64.Int64.Number", Value = 9223372036854775807 }, + { File = "config.toml", Path = "TestConfigI64.Int64.Number", Value = -9223372036854775808 }, + { File = "config.toml", Path = "TestConfigU8.Uint8.Number", Value = 255 }, + { File = "config.toml", Path = "TestConfigU8.Uint8.Number", Value = 256 }, + { File = "config.toml", Path = "TestConfigU8.Uint8.Number", Value = -256 }, + { File = "config.toml", Path = "TestConfigU16.Uint16.Number", Value = 65535 }, + { File = "config.toml", Path = "TestConfigU16.Uint16.Number", Value = 65536 }, + { File = "config.toml", Path = "TestConfigU16.Uint16.Number", Value = -65536 }, + { File = "config.toml", Path = "TestConfigU32.Uint32.Number", Value = 4294967295 }, + { File = "config.toml", Path = "TestConfigU32.Uint32.Number", Value = 4294967296 }, + { File = "config.toml", Path = "TestConfigU32.Uint32.Number", Value = -4294967296 }, + { File = "config.toml", Path = "TestConfigU64.Uint64.Number", Value = 9223372036854775807 }, + { File = "config.toml", Path = "TestConfigU64.Uint64.Number", Value = -9223372036854775808 }, + { File = "config.toml", Path = "TestConfigF32.Float32.Number", Value = 3.4 }, + { File = "config.toml", Path = "TestConfigF32.Float32.Number", Value = 3.4e+39 }, + { File = "config.toml", Path = "TestConfigF32.Float32.Number", Value = -3.4 }, + { File = "config.toml", Path = "TestConfigF32.Float32.Number", Value = -3.4e+40 }, + { File = "config.toml", Path = "TestConfigF64.Float64.Number", Value = 1.7e+308 }, + { File = "config.toml", Path = "TestConfigF64.Float64.Number", Value = -1.7e+308 }, { File = "config.toml", Path = "TestConfigStruct.ConfigStruct.Description", Value = { Number = 11 } }, { File = "config.toml", Path = "TestConfigStruct.ConfigStruct.Description", Value = { Nr = 222 } }, { File = "config.toml", Path = "TestConfigStruct.ConfigStruct.Description", Value = { Number = "11" } }, { File = "config.toml", Path = "TestConfigNestedStruct.ConfigNestedStruct", Value = { Text = "Overwritten text", Message = { Public = false, MessageDescription = [{ Text = "Overwritten Text1" }] } } }, { File = "config.toml", Path = "TestConfigNestedStruct.ConfigNestedStruct.Message.MessageDescription", Value = [{ Text = "Overwritten Text1" }, { Text = "Overwritten Text2" }] }, + { File = "config.toml", Path = "TestMap.Map", Value = { "Key1" = { Number = 10 }, "Key2" = { Number = 11 } } }, + { File = "config.toml", Path = "TestMap.Map", Value = { "Key2" = { Number = 2 }, "Key3" = { Number = 3 } } }, ] From 652ef7ae5e8e7d1a874ed12e1ed180349c777a09 Mon Sep 17 00:00:00 2001 From: radu chis Date: Fri, 19 Apr 2024 12:09:12 +0300 Subject: [PATCH 056/467] update x/crypto to v0.22.0 --- go.mod | 8 ++++---- go.sum | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index aafbc51ec02..c7ef33c791d 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( github.com/shirou/gopsutil v3.21.11+incompatible github.com/stretchr/testify v1.8.4 github.com/urfave/cli v1.22.10 - golang.org/x/crypto v0.10.0 + golang.org/x/crypto v0.22.0 gopkg.in/go-playground/validator.v8 v8.18.2 ) @@ -175,10 +175,10 @@ require ( golang.org/x/arch v0.3.0 // indirect golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect golang.org/x/mod v0.10.0 // indirect - golang.org/x/net v0.11.0 // indirect + golang.org/x/net v0.21.0 // indirect golang.org/x/sync v0.2.0 // indirect - golang.org/x/sys v0.10.0 // indirect - golang.org/x/text v0.10.0 // indirect + golang.org/x/sys v0.19.0 // indirect + golang.org/x/text v0.14.0 // indirect golang.org/x/tools v0.9.1 // indirect gonum.org/v1/gonum v0.11.0 // indirect google.golang.org/protobuf v1.30.0 // indirect diff --git a/go.sum b/go.sum index 09c6f9ea503..813d0a8327a 100644 --- a/go.sum +++ b/go.sum @@ -129,6 +129,7 @@ github.com/gizak/termui/v3 v3.1.0 h1:ZZmVDgwHl7gR7elfKf1xc4IudXZ5qqfDh4wExk4Iajc github.com/gizak/termui/v3 v3.1.0/go.mod h1:bXQEBkJpzxUAKf0+xq9MSWAvWZlE7c+aidmyFlkYTrY= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= +github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -261,6 +262,7 @@ github.com/jbenet/goprocess v0.1.4/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZl github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= @@ -268,6 +270,7 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= +github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19/go.mod h1:hY+WOq6m2FpbvyrI93sMaypsttvaIL5nhVR92dTMUcQ= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= @@ -413,6 +416,7 @@ github.com/multiversx/mx-components-big-int v1.0.0 h1:Wkr8lSzK2nDqixOrrBa47VNuqd github.com/multiversx/mx-components-big-int v1.0.0/go.mod h1:maIEMgHlNE2u78JaDD0oLzri+ShgU4okHfzP3LWGdQM= github.com/multiversx/protobuf v1.3.2 h1:RaNkxvGTGbA0lMcnHAN24qE1G1i+Xs5yHA6MDvQ4mSM= github.com/multiversx/protobuf v1.3.2/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo= github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM= github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d h1:x3S6kxmy49zXVVyhcnrFqxvNVCBPb2KZ9hV2RBdS840= @@ -626,6 +630,8 @@ golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM= golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I= +golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= +golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug= golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= @@ -670,6 +676,7 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU= golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -725,6 +732,7 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= @@ -740,6 +748,7 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58= golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= From 1030bcd997cdc1bca43defd05aea2941793de7f9 Mon Sep 17 00:00:00 2001 From: radu chis Date: Fri, 19 Apr 2024 10:48:37 +0300 Subject: [PATCH 057/467] add withKeys option on account --- api/groups/addressGroup.go | 1 + api/groups/addressGroupOptions.go | 6 ++ facade/interface.go | 2 +- facade/mock/nodeStub.go | 6 +- facade/nodeFacade.go | 14 +++- facade/nodeFacade_test.go | 14 ++-- go.mod | 2 +- go.sum | 4 +- .../node/getAccount/getAccount_test.go | 5 +- node/node.go | 34 +++++--- node/nodeLoadAccounts_test.go | 3 +- node/node_test.go | 79 +++++++++++++++++-- 12 files changed, 135 insertions(+), 35 deletions(-) diff --git a/api/groups/addressGroup.go b/api/groups/addressGroup.go index 1866c3bf022..da2adc0ab56 100644 --- a/api/groups/addressGroup.go +++ b/api/groups/addressGroup.go @@ -38,6 +38,7 @@ const ( urlParamBlockHash = "blockHash" urlParamBlockRootHash = "blockRootHash" urlParamHintEpoch = "hintEpoch" + urlParamWithKeys = "withKeys" ) // addressFacadeHandler defines the methods to be implemented by a facade for handling address requests diff --git a/api/groups/addressGroupOptions.go b/api/groups/addressGroupOptions.go index 5cd4fc6a11f..c3841f7e7fd 100644 --- a/api/groups/addressGroupOptions.go +++ b/api/groups/addressGroupOptions.go @@ -54,6 +54,11 @@ func parseAccountQueryOptions(c *gin.Context) (api.AccountQueryOptions, error) { return api.AccountQueryOptions{}, err } + withKeys, err := parseBoolUrlParam(c, urlParamWithKeys) + if err != nil { + return api.AccountQueryOptions{}, err + } + options := api.AccountQueryOptions{ OnFinalBlock: onFinalBlock, OnStartOfEpoch: onStartOfEpoch, @@ -61,6 +66,7 @@ func parseAccountQueryOptions(c *gin.Context) (api.AccountQueryOptions, error) { BlockHash: blockHash, BlockRootHash: blockRootHash, HintEpoch: hintEpoch, + WithKeys: withKeys, } return options, nil } diff --git a/facade/interface.go b/facade/interface.go index 07488622a96..b7deebb17e7 100644 --- a/facade/interface.go +++ b/facade/interface.go @@ -74,7 +74,7 @@ type NodeHandler interface { // GetAccount returns an accountResponse containing information // about the account correlated with provided address - GetAccount(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) + GetAccount(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) // GetCode returns the code for the given code hash GetCode(codeHash []byte, options api.AccountQueryOptions) ([]byte, api.BlockInfo) diff --git a/facade/mock/nodeStub.go b/facade/mock/nodeStub.go index 74c9cbea536..d03d847b151 100644 --- a/facade/mock/nodeStub.go +++ b/facade/mock/nodeStub.go @@ -25,7 +25,7 @@ type NodeStub struct { ValidateTransactionHandler func(tx *transaction.Transaction) error ValidateTransactionForSimulationCalled func(tx *transaction.Transaction, bypassSignature bool) error SendBulkTransactionsHandler func(txs []*transaction.Transaction) (uint64, error) - GetAccountCalled func(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) + GetAccountCalled func(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) GetCodeCalled func(codeHash []byte, options api.AccountQueryOptions) ([]byte, api.BlockInfo) GetCurrentPublicKeyHandler func() string GenerateAndSendBulkTransactionsHandler func(destination string, value *big.Int, nrTransactions uint64) error @@ -181,9 +181,9 @@ func (ns *NodeStub) SendBulkTransactions(txs []*transaction.Transaction) (uint64 } // GetAccount - -func (ns *NodeStub) GetAccount(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { +func (ns *NodeStub) GetAccount(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) { if ns.GetAccountCalled != nil { - return ns.GetAccountCalled(address, options) + return ns.GetAccountCalled(address, options, ctx) } return api.AccountResponse{}, api.BlockInfo{}, nil diff --git a/facade/nodeFacade.go b/facade/nodeFacade.go index 03dd77c76b7..4e328b5462a 100644 --- a/facade/nodeFacade.go +++ b/facade/nodeFacade.go @@ -321,7 +321,10 @@ func (nf *nodeFacade) GetLastPoolNonceForSender(sender string) (uint64, error) { // GetTransactionsPoolNonceGapsForSender will return the nonce gaps from pool for sender, if exists, that is to be returned on API calls func (nf *nodeFacade) GetTransactionsPoolNonceGapsForSender(sender string) (*common.TransactionsPoolNonceGapsForSenderApiResponse, error) { - accountResponse, _, err := nf.node.GetAccount(sender, apiData.AccountQueryOptions{}) + ctx, cancel := nf.getContextForApiTrieRangeOperations() + defer cancel() + + accountResponse, _, err := nf.node.GetAccount(sender, apiData.AccountQueryOptions{}, ctx) if err != nil { return &common.TransactionsPoolNonceGapsForSenderApiResponse{}, err } @@ -336,7 +339,10 @@ func (nf *nodeFacade) ComputeTransactionGasLimit(tx *transaction.Transaction) (* // GetAccount returns a response containing information about the account correlated with provided address func (nf *nodeFacade) GetAccount(address string, options apiData.AccountQueryOptions) (apiData.AccountResponse, apiData.BlockInfo, error) { - accountResponse, blockInfo, err := nf.node.GetAccount(address, options) + ctx, cancel := nf.getContextForApiTrieRangeOperations() + defer cancel() + + accountResponse, blockInfo, err := nf.node.GetAccount(address, options, ctx) if err != nil { return apiData.AccountResponse{}, apiData.BlockInfo{}, err } @@ -358,9 +364,11 @@ func (nf *nodeFacade) GetAccounts(addresses []string, options apiData.AccountQue response := make(map[string]*apiData.AccountResponse) var blockInfo apiData.BlockInfo + ctx, cancel := nf.getContextForApiTrieRangeOperations() + defer cancel() for _, address := range addresses { - accountResponse, blockInfoForAccount, err := nf.node.GetAccount(address, options) + accountResponse, blockInfoForAccount, err := nf.node.GetAccount(address, options, ctx) if err != nil { return nil, apiData.BlockInfo{}, err } diff --git a/facade/nodeFacade_test.go b/facade/nodeFacade_test.go index 21823b60b6e..f2eaff6025e 100644 --- a/facade/nodeFacade_test.go +++ b/facade/nodeFacade_test.go @@ -338,7 +338,7 @@ func TestNodeFacade_GetAccount(t *testing.T) { arg := createMockArguments() arg.Node = &mock.NodeStub{ - GetAccountCalled: func(_ string, _ api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { + GetAccountCalled: func(_ string, _ api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { return api.AccountResponse{}, api.BlockInfo{}, expectedErr }, } @@ -352,7 +352,7 @@ func TestNodeFacade_GetAccount(t *testing.T) { getAccountCalled := false node := &mock.NodeStub{} - node.GetAccountCalled = func(address string, _ api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { + node.GetAccountCalled = func(address string, _ api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { getAccountCalled = true return api.AccountResponse{}, api.BlockInfo{}, nil } @@ -387,7 +387,7 @@ func TestNodeFacade_GetAccounts(t *testing.T) { t.Parallel() node := &mock.NodeStub{} - node.GetAccountCalled = func(address string, _ api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { + node.GetAccountCalled = func(address string, _ api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { return api.AccountResponse{}, api.BlockInfo{}, expectedErr } @@ -407,7 +407,7 @@ func TestNodeFacade_GetAccounts(t *testing.T) { expectedAcount := api.AccountResponse{Address: "test"} node := &mock.NodeStub{} - node.GetAccountCalled = func(address string, _ api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { + node.GetAccountCalled = func(address string, _ api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { return expectedAcount, api.BlockInfo{}, nil } @@ -2008,7 +2008,7 @@ func TestNodeFacade_GetTransactionsPoolNonceGapsForSender(t *testing.T) { arg := createMockArguments() arg.Node = &mock.NodeStub{ - GetAccountCalled: func(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { + GetAccountCalled: func(address string, options api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { return api.AccountResponse{}, api.BlockInfo{}, expectedErr }, } @@ -2030,7 +2030,7 @@ func TestNodeFacade_GetTransactionsPoolNonceGapsForSender(t *testing.T) { arg := createMockArguments() arg.Node = &mock.NodeStub{ - GetAccountCalled: func(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { + GetAccountCalled: func(address string, options api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { return api.AccountResponse{}, api.BlockInfo{}, nil }, } @@ -2062,7 +2062,7 @@ func TestNodeFacade_GetTransactionsPoolNonceGapsForSender(t *testing.T) { } providedNonce := uint64(10) arg.Node = &mock.NodeStub{ - GetAccountCalled: func(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { + GetAccountCalled: func(address string, options api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { return api.AccountResponse{Nonce: providedNonce}, api.BlockInfo{}, nil }, } diff --git a/go.mod b/go.mod index aafbc51ec02..b5d8fd684c6 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.14 - github.com/multiversx/mx-chain-core-go v1.2.19 + github.com/multiversx/mx-chain-core-go v1.2.20-0.20240418121049-6970013b49d9 github.com/multiversx/mx-chain-crypto-go v1.2.11 github.com/multiversx/mx-chain-es-indexer-go v1.4.21 github.com/multiversx/mx-chain-logger-go v1.0.14 diff --git a/go.sum b/go.sum index 09c6f9ea503..64517c9b404 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.14 h1:YhAUDjBBpc5h5W0A7LHLXUMIMeCgwgGvkqfAPbFqsno= github.com/multiversx/mx-chain-communication-go v1.0.14/go.mod h1:qYCqgk0h+YpcTA84jHIpCBy6UShRwmXzHSCcdfwNrkw= -github.com/multiversx/mx-chain-core-go v1.2.19 h1:2BaVHkB0tro3cjs5ay2pmLup1loCV0e1p9jV5QW0xqc= -github.com/multiversx/mx-chain-core-go v1.2.19/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.20-0.20240418121049-6970013b49d9 h1:iUGEUzmxh2xrgaHS9Lq5CpnKGDsR02v9gEWroc/jbpA= +github.com/multiversx/mx-chain-core-go v1.2.20-0.20240418121049-6970013b49d9/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.11 h1:MNPJoiTJA5/tedYrI0N22OorbsKDESWG0SF8MCJwcJI= github.com/multiversx/mx-chain-crypto-go v1.2.11/go.mod h1:pcZutPdfLiAFytzCU3LxU3s8cXkvpNqquyitFSfoF3o= github.com/multiversx/mx-chain-es-indexer-go v1.4.21 h1:rzxXCkgOsqj67GRYtqzKuf9XgHwnZLTZhU90Ck3VbrE= diff --git a/integrationTests/node/getAccount/getAccount_test.go b/integrationTests/node/getAccount/getAccount_test.go index 487c8b1a15a..c48a1017a4e 100644 --- a/integrationTests/node/getAccount/getAccount_test.go +++ b/integrationTests/node/getAccount/getAccount_test.go @@ -1,6 +1,7 @@ package getAccount import ( + "context" "math/big" "testing" @@ -57,7 +58,7 @@ func TestNode_GetAccountAccountDoesNotExistsShouldRetEmpty(t *testing.T) { encodedAddress, err := integrationTests.TestAddressPubkeyConverter.Encode(integrationTests.CreateRandomBytes(32)) require.Nil(t, err) - recovAccnt, _, err := n.GetAccount(encodedAddress, api.AccountQueryOptions{}) + recovAccnt, _, err := n.GetAccount(encodedAddress, api.AccountQueryOptions{}, context.Background()) require.Nil(t, err) assert.Equal(t, uint64(0), recovAccnt.Nonce) @@ -99,7 +100,7 @@ func TestNode_GetAccountAccountExistsShouldReturn(t *testing.T) { testAddress, err := coreComponents.AddressPubKeyConverter().Encode(testPubkey) require.Nil(t, err) - recovAccnt, _, err := n.GetAccount(testAddress, api.AccountQueryOptions{}) + recovAccnt, _, err := n.GetAccount(testAddress, api.AccountQueryOptions{}, context.Background()) require.Nil(t, err) require.Equal(t, testNonce, recovAccnt.Nonce) diff --git a/node/node.go b/node/node.go index 978fd45dc99..29cea2671d6 100644 --- a/node/node.go +++ b/node/node.go @@ -291,13 +291,26 @@ func (n *Node) GetKeyValuePairs(address string, options api.AccountQueryOptions, return map[string]string{}, api.BlockInfo{}, nil } + mapToReturn, err := n.getKeys(userAccount, ctx) + if err != nil { + return nil, api.BlockInfo{}, err + } + + if common.IsContextDone(ctx) { + return nil, api.BlockInfo{}, ErrTrieOperationsTimeout + } + + return mapToReturn, blockInfo, nil +} + +func (n *Node) getKeys(userAccount state.UserAccountHandler, ctx context.Context) (map[string]string, error) { chLeaves := &common.TrieIteratorChannels{ LeavesChan: make(chan core.KeyValueHolder, common.TrieLeavesChannelDefaultCapacity), ErrChan: errChan.NewErrChanWrapper(), } - err = userAccount.GetAllLeaves(chLeaves, ctx) + err := userAccount.GetAllLeaves(chLeaves, ctx) if err != nil { - return nil, api.BlockInfo{}, err + return nil, err } mapToReturn := make(map[string]string) @@ -307,14 +320,9 @@ func (n *Node) GetKeyValuePairs(address string, options api.AccountQueryOptions, err = chLeaves.ErrChan.ReadFromChanNonBlocking() if err != nil { - return nil, api.BlockInfo{}, err - } - - if common.IsContextDone(ctx) { - return nil, api.BlockInfo{}, ErrTrieOperationsTimeout + return nil, err } - - return mapToReturn, blockInfo, nil + return mapToReturn, nil } // GetValueForKey will return the value for a key from a given account @@ -930,7 +938,7 @@ func (n *Node) setTxGuardianData(guardian string, guardianSigHex string, tx *tra } // GetAccount will return account details for a given address -func (n *Node) GetAccount(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { +func (n *Node) GetAccount(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) { account, blockInfo, err := n.loadUserAccountHandlerByAddress(address, options) if err != nil { adaptedBlockInfo, isEmptyAccount := extractBlockInfoIfNewAccount(err) @@ -954,6 +962,11 @@ func (n *Node) GetAccount(address string, options api.AccountQueryOptions) (api. } } + var keys map[string]string + if options.WithKeys { + keys, _ = n.getKeys(account, ctx) + } + return api.AccountResponse{ Address: address, Nonce: account.GetNonce(), @@ -964,6 +977,7 @@ func (n *Node) GetAccount(address string, options api.AccountQueryOptions) (api. CodeMetadata: account.GetCodeMetadata(), DeveloperReward: account.GetDeveloperReward().String(), OwnerAddress: ownerAddress, + Pairs: keys, }, blockInfo, nil } diff --git a/node/nodeLoadAccounts_test.go b/node/nodeLoadAccounts_test.go index e7e03c2d05b..7ef831bca0f 100644 --- a/node/nodeLoadAccounts_test.go +++ b/node/nodeLoadAccounts_test.go @@ -2,6 +2,7 @@ package node_test import ( "bytes" + "context" "errors" "math/big" "testing" @@ -45,7 +46,7 @@ func TestNode_GetAccountWithOptionsShouldWork(t *testing.T) { node.WithStateComponents(stateComponents), ) - account, blockInfo, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}) + account, blockInfo, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}, context.Background()) require.Nil(t, err) require.Equal(t, "100", account.Balance) require.Equal(t, uint64(1), blockInfo.Nonce) diff --git a/node/node_test.go b/node/node_test.go index 2cde11d08a0..d10f79b67be 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -3293,7 +3293,7 @@ func TestNode_GetAccountPubkeyConverterFailsShouldErr(t *testing.T) { node.WithCoreComponents(coreComponents), ) - recovAccnt, _, err := n.GetAccount(createDummyHexAddress(64), api.AccountQueryOptions{}) + recovAccnt, _, err := n.GetAccount(createDummyHexAddress(64), api.AccountQueryOptions{}, context.Background()) assert.Empty(t, recovAccnt) assert.ErrorIs(t, err, errExpected) @@ -3320,7 +3320,7 @@ func TestNode_GetAccountAccountDoesNotExistsShouldRetEmpty(t *testing.T) { node.WithStateComponents(stateComponents), ) - account, blockInfo, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}) + account, blockInfo, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}, context.Background()) require.Nil(t, err) require.Equal(t, uint64(0), account.Nonce) @@ -3355,7 +3355,7 @@ func TestNode_GetAccountAccountsRepositoryFailsShouldErr(t *testing.T) { node.WithStateComponents(stateComponents), ) - recovAccnt, _, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}) + recovAccnt, _, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}, context.Background()) assert.Empty(t, recovAccnt) assert.NotNil(t, err) @@ -3394,7 +3394,7 @@ func TestNode_GetAccountAccNotFoundShouldReturnEmpty(t *testing.T) { node.WithStateComponents(stateComponents), ) - acc, bInfo, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}) + acc, bInfo, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}, context.Background()) require.Nil(t, err) require.Equal(t, dummyBlockInfo.apiResult(), bInfo) require.Equal(t, api.AccountResponse{Address: testscommon.TestAddressAlice, Balance: "0", DeveloperReward: "0"}, acc) @@ -3436,7 +3436,7 @@ func TestNode_GetAccountAccountExistsShouldReturn(t *testing.T) { node.WithStateComponents(stateComponents), ) - recovAccnt, _, err := n.GetAccount(testscommon.TestAddressBob, api.AccountQueryOptions{}) + recovAccnt, _, err := n.GetAccount(testscommon.TestAddressBob, api.AccountQueryOptions{}, context.Background()) require.Nil(t, err) require.Equal(t, uint64(2), recovAccnt.Nonce) @@ -3447,6 +3447,75 @@ func TestNode_GetAccountAccountExistsShouldReturn(t *testing.T) { require.Equal(t, testscommon.TestAddressAlice, recovAccnt.OwnerAddress) } +func TestNode_GetAccountAccountWithKeysShouldReturn(t *testing.T) { + t.Parallel() + + accnt := createAcc(testscommon.TestPubKeyBob) + _ = accnt.AddToBalance(big.NewInt(1)) + + k1, v1 := []byte("key1"), []byte("value1") + k2, v2 := []byte("key2"), []byte("value2") + + accnt.SetDataTrie( + &trieMock.TrieStub{ + GetAllLeavesOnChannelCalled: func(leavesChannels *common.TrieIteratorChannels, ctx context.Context, rootHash []byte, _ common.KeyBuilder, tlp common.TrieLeafParser) error { + go func() { + suffix := append(k1, accnt.AddressBytes()...) + trieLeaf, _ := tlp.ParseLeaf(k1, append(v1, suffix...), core.NotSpecified) + leavesChannels.LeavesChan <- trieLeaf + + suffix = append(k2, accnt.AddressBytes()...) + trieLeaf2, _ := tlp.ParseLeaf(k2, append(v2, suffix...), core.NotSpecified) + leavesChannels.LeavesChan <- trieLeaf2 + + close(leavesChannels.LeavesChan) + leavesChannels.ErrChan.Close() + }() + + return nil + }, + RootCalled: func() ([]byte, error) { + return nil, nil + }, + }) + + accDB := &stateMock.AccountsStub{ + GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { + return accnt, nil, nil + }, + RecreateTrieCalled: func(rootHash []byte) error { + return nil + }, + } + + coreComponents := getDefaultCoreComponents() + dataComponents := getDefaultDataComponents() + stateComponents := getDefaultStateComponents() + args := state.ArgsAccountsRepository{ + FinalStateAccountsWrapper: accDB, + CurrentStateAccountsWrapper: accDB, + HistoricalStateAccountsWrapper: accDB, + } + stateComponents.AccountsRepo, _ = state.NewAccountsRepository(args) + n, _ := node.NewNode( + node.WithCoreComponents(coreComponents), + node.WithDataComponents(dataComponents), + node.WithStateComponents(stateComponents), + ) + + recovAccnt, _, err := n.GetAccount(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: false}, context.Background()) + require.Nil(t, err) + require.Nil(t, recovAccnt.Pairs) + + recovAccnt, _, err = n.GetAccount(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: true}, context.Background()) + + require.Nil(t, err) + require.NotNil(t, recovAccnt.Pairs) + require.Equal(t, 2, len(recovAccnt.Pairs)) + require.Equal(t, hex.EncodeToString(v1), recovAccnt.Pairs[hex.EncodeToString(k1)]) + require.Equal(t, hex.EncodeToString(v2), recovAccnt.Pairs[hex.EncodeToString(k2)]) +} + func TestNode_AppStatusHandlersShouldIncrement(t *testing.T) { t.Parallel() From ddb907c7b739905d778d7e4902affe2dbb07efa1 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Fri, 19 Apr 2024 16:59:05 +0300 Subject: [PATCH 058/467] - fixed the initialization of the chain simulator when working with 0 value activation epochs --- epochStart/metachain/legacySystemSCs.go | 3 +- errors/errors.go | 3 + .../disabled/epochStartSystemSCProcessor.go | 42 ++++++++++++++ factory/interface.go | 1 + factory/mock/processComponentsStub.go | 6 ++ factory/processing/blockProcessorCreator.go | 3 + .../processing/blockProcessorCreator_test.go | 7 ++- factory/processing/export_test.go | 6 +- factory/processing/processComponents.go | 2 + .../processing/processComponentsHandler.go | 15 +++++ .../processComponentsHandler_test.go | 2 + .../stakingProvider/delegation_test.go | 58 +++++++++++++++++++ .../mock/processComponentsStub.go | 6 ++ node/chainSimulator/chainSimulator.go | 33 +++++++++-- .../components/processComponents.go | 7 +++ .../components/processComponents_test.go | 1 + .../components/testOnlyProcessingNode.go | 5 ++ node/chainSimulator/process/interface.go | 1 + testscommon/chainSimulator/nodeHandlerMock.go | 9 +++ 19 files changed, 200 insertions(+), 10 deletions(-) create mode 100644 factory/disabled/epochStartSystemSCProcessor.go diff --git a/epochStart/metachain/legacySystemSCs.go b/epochStart/metachain/legacySystemSCs.go index 677cbcb682b..0db6a39916f 100644 --- a/epochStart/metachain/legacySystemSCs.go +++ b/epochStart/metachain/legacySystemSCs.go @@ -151,7 +151,8 @@ func (s *legacySystemSCProcessor) processLegacy( } } - if s.flagChangeMaxNodesEnabled.IsSet() { + // the updateMaxNodes call needs the StakingV2Flag functionality to be enabled. Otherwise, the call will error + if s.flagChangeMaxNodesEnabled.IsSet() && s.enableEpochsHandler.IsFlagEnabled(common.StakingV2Flag) { err := s.updateMaxNodes(validatorsInfoMap, nonce) if err != nil { return err diff --git a/errors/errors.go b/errors/errors.go index 771c65adc07..dd475327876 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -595,3 +595,6 @@ var ErrInvalidNodeOperationMode = errors.New("invalid node operation mode") // ErrNilSentSignatureTracker defines the error for setting a nil SentSignatureTracker var ErrNilSentSignatureTracker = errors.New("nil sent signature tracker") + +// ErrNilEpochSystemSCProcessor defines the error for setting a nil EpochSystemSCProcessor +var ErrNilEpochSystemSCProcessor = errors.New("nil epoch system SC processor") diff --git a/factory/disabled/epochStartSystemSCProcessor.go b/factory/disabled/epochStartSystemSCProcessor.go new file mode 100644 index 00000000000..7d9e8720a79 --- /dev/null +++ b/factory/disabled/epochStartSystemSCProcessor.go @@ -0,0 +1,42 @@ +package disabled + +import ( + "github.com/multiversx/mx-chain-core-go/data" + "github.com/multiversx/mx-chain-core-go/data/block" + "github.com/multiversx/mx-chain-go/epochStart" + "github.com/multiversx/mx-chain-go/state" +) + +type epochStartSystemSCProcessor struct { +} + +// NewDisabledEpochStartSystemSC creates a new disabled EpochStartSystemSCProcessor instance +func NewDisabledEpochStartSystemSC() *epochStartSystemSCProcessor { + return &epochStartSystemSCProcessor{} +} + +// ToggleUnStakeUnBond returns nil +func (e *epochStartSystemSCProcessor) ToggleUnStakeUnBond(_ bool) error { + return nil +} + +// ProcessSystemSmartContract returns nil +func (e *epochStartSystemSCProcessor) ProcessSystemSmartContract( + _ state.ShardValidatorsInfoMapHandler, + _ data.HeaderHandler, +) error { + return nil +} + +// ProcessDelegationRewards returns nil +func (e *epochStartSystemSCProcessor) ProcessDelegationRewards( + _ block.MiniBlockSlice, + _ epochStart.TransactionCacher, +) error { + return nil +} + +// IsInterfaceNil returns true if there is no value under the interface +func (e *epochStartSystemSCProcessor) IsInterfaceNil() bool { + return e == nil +} diff --git a/factory/interface.go b/factory/interface.go index ede9f39089b..0f1c237d0d9 100644 --- a/factory/interface.go +++ b/factory/interface.go @@ -310,6 +310,7 @@ type ProcessComponentsHolder interface { AccountsParser() genesis.AccountsParser ReceiptsRepository() ReceiptsRepository SentSignaturesTracker() process.SentSignaturesTracker + EpochSystemSCProcessor() process.EpochStartSystemSCProcessor IsInterfaceNil() bool } diff --git a/factory/mock/processComponentsStub.go b/factory/mock/processComponentsStub.go index e646958281c..32bbfaf2df3 100644 --- a/factory/mock/processComponentsStub.go +++ b/factory/mock/processComponentsStub.go @@ -57,6 +57,7 @@ type ProcessComponentsMock struct { AccountsParserInternal genesis.AccountsParser ReceiptsRepositoryInternal factory.ReceiptsRepository SentSignaturesTrackerInternal process.SentSignaturesTracker + EpochSystemSCProcessorInternal process.EpochStartSystemSCProcessor } // Create - @@ -284,6 +285,11 @@ func (pcm *ProcessComponentsMock) SentSignaturesTracker() process.SentSignatures return pcm.SentSignaturesTrackerInternal } +// EpochSystemSCProcessor - +func (pcm *ProcessComponentsMock) EpochSystemSCProcessor() process.EpochStartSystemSCProcessor { + return pcm.EpochSystemSCProcessorInternal +} + // IsInterfaceNil - func (pcm *ProcessComponentsMock) IsInterfaceNil() bool { return pcm == nil diff --git a/factory/processing/blockProcessorCreator.go b/factory/processing/blockProcessorCreator.go index 7db9e20cf7d..2cf54aaa955 100644 --- a/factory/processing/blockProcessorCreator.go +++ b/factory/processing/blockProcessorCreator.go @@ -50,6 +50,7 @@ import ( type blockProcessorAndVmFactories struct { blockProcessor process.BlockProcessor vmFactoryForProcessing process.VirtualMachinesContainerFactory + epochSystemSCProcessor process.EpochStartSystemSCProcessor } func (pcf *processComponentsFactory) newBlockProcessor( @@ -453,6 +454,7 @@ func (pcf *processComponentsFactory) newShardBlockProcessor( blockProcessorComponents := &blockProcessorAndVmFactories{ blockProcessor: blockProcessor, vmFactoryForProcessing: vmFactory, + epochSystemSCProcessor: factoryDisabled.NewDisabledEpochStartSystemSC(), } pcf.stakingDataProviderAPI = factoryDisabled.NewDisabledStakingDataProvider() @@ -982,6 +984,7 @@ func (pcf *processComponentsFactory) newMetaBlockProcessor( blockProcessorComponents := &blockProcessorAndVmFactories{ blockProcessor: metaProcessor, vmFactoryForProcessing: vmFactory, + epochSystemSCProcessor: epochStartSystemSCProcessor, } return blockProcessorComponents, nil diff --git a/factory/processing/blockProcessorCreator_test.go b/factory/processing/blockProcessorCreator_test.go index 3ecc3432f9e..099fec4a82d 100644 --- a/factory/processing/blockProcessorCreator_test.go +++ b/factory/processing/blockProcessorCreator_test.go @@ -1,6 +1,7 @@ package processing_test import ( + "fmt" "sync" "testing" @@ -40,7 +41,7 @@ func Test_newBlockProcessorCreatorForShard(t *testing.T) { _, err = pcf.Create() require.NoError(t, err) - bp, err := pcf.NewBlockProcessor( + bp, epochStartSCProc, err := pcf.NewBlockProcessor( &testscommon.RequestHandlerStub{}, &processMocks.ForkDetectorStub{}, &mock.EpochStartTriggerStub{}, @@ -60,6 +61,7 @@ func Test_newBlockProcessorCreatorForShard(t *testing.T) { require.NoError(t, err) require.NotNil(t, bp) + require.Equal(t, "*disabled.epochStartSystemSCProcessor", fmt.Sprintf("%T", epochStartSCProc)) } func Test_newBlockProcessorCreatorForMeta(t *testing.T) { @@ -166,7 +168,7 @@ func Test_newBlockProcessorCreatorForMeta(t *testing.T) { _, err = pcf.Create() require.NoError(t, err) - bp, err := pcf.NewBlockProcessor( + bp, epochStartSCProc, err := pcf.NewBlockProcessor( &testscommon.RequestHandlerStub{}, &processMocks.ForkDetectorStub{}, &mock.EpochStartTriggerStub{}, @@ -186,6 +188,7 @@ func Test_newBlockProcessorCreatorForMeta(t *testing.T) { require.NoError(t, err) require.NotNil(t, bp) + require.Equal(t, "*metachain.systemSCProcessor", fmt.Sprintf("%T", epochStartSCProc)) } func createAccountAdapter( diff --git a/factory/processing/export_test.go b/factory/processing/export_test.go index 50c5123634c..76e84d75fee 100644 --- a/factory/processing/export_test.go +++ b/factory/processing/export_test.go @@ -25,7 +25,7 @@ func (pcf *processComponentsFactory) NewBlockProcessor( blockProcessingCutoff cutoff.BlockProcessingCutoffHandler, missingTrieNodesNotifier common.MissingTrieNodesNotifier, sentSignaturesTracker process.SentSignaturesTracker, -) (process.BlockProcessor, error) { +) (process.BlockProcessor, process.EpochStartSystemSCProcessor, error) { blockProcessorComponents, err := pcf.newBlockProcessor( requestHandler, forkDetector, @@ -44,10 +44,10 @@ func (pcf *processComponentsFactory) NewBlockProcessor( sentSignaturesTracker, ) if err != nil { - return nil, err + return nil, nil, err } - return blockProcessorComponents.blockProcessor, nil + return blockProcessorComponents.blockProcessor, blockProcessorComponents.epochSystemSCProcessor, nil } // CreateAPITransactionEvaluator - diff --git a/factory/processing/processComponents.go b/factory/processing/processComponents.go index 72d75c69dc3..352343ce102 100644 --- a/factory/processing/processComponents.go +++ b/factory/processing/processComponents.go @@ -131,6 +131,7 @@ type processComponents struct { accountsParser genesis.AccountsParser receiptsRepository mainFactory.ReceiptsRepository sentSignaturesTracker process.SentSignaturesTracker + epochSystemSCProcessor process.EpochStartSystemSCProcessor } // ProcessComponentsFactoryArgs holds the arguments needed to create a process components factory @@ -751,6 +752,7 @@ func (pcf *processComponentsFactory) Create() (*processComponents, error) { currentEpochProvider: currentEpochProvider, vmFactoryForTxSimulator: vmFactoryForTxSimulate, vmFactoryForProcessing: blockProcessorComponents.vmFactoryForProcessing, + epochSystemSCProcessor: blockProcessorComponents.epochSystemSCProcessor, scheduledTxsExecutionHandler: scheduledTxsExecutionHandler, txsSender: txsSenderWithAccumulator, hardforkTrigger: hardforkTrigger, diff --git a/factory/processing/processComponentsHandler.go b/factory/processing/processComponentsHandler.go index a5b71ca3b28..28b3c4b0eed 100644 --- a/factory/processing/processComponentsHandler.go +++ b/factory/processing/processComponentsHandler.go @@ -177,6 +177,9 @@ func (m *managedProcessComponents) CheckSubcomponents() error { if check.IfNil(m.processComponents.sentSignaturesTracker) { return errors.ErrNilSentSignatureTracker } + if check.IfNil(m.processComponents.epochSystemSCProcessor) { + return errors.ErrNilEpochSystemSCProcessor + } return nil } @@ -673,6 +676,18 @@ func (m *managedProcessComponents) SentSignaturesTracker() process.SentSignature return m.processComponents.sentSignaturesTracker } +// EpochSystemSCProcessor returns the epoch start system SC processor +func (m *managedProcessComponents) EpochSystemSCProcessor() process.EpochStartSystemSCProcessor { + m.mutProcessComponents.RLock() + defer m.mutProcessComponents.RUnlock() + + if m.processComponents == nil { + return nil + } + + return m.processComponents.epochSystemSCProcessor +} + // IsInterfaceNil returns true if the interface is nil func (m *managedProcessComponents) IsInterfaceNil() bool { return m == nil diff --git a/factory/processing/processComponentsHandler_test.go b/factory/processing/processComponentsHandler_test.go index 36638afacfd..2aec3cb8c6e 100644 --- a/factory/processing/processComponentsHandler_test.go +++ b/factory/processing/processComponentsHandler_test.go @@ -93,6 +93,7 @@ func TestManagedProcessComponents_Create(t *testing.T) { require.True(t, check.IfNil(managedProcessComponents.FullArchivePeerShardMapper())) require.True(t, check.IfNil(managedProcessComponents.FullArchiveInterceptorsContainer())) require.True(t, check.IfNil(managedProcessComponents.SentSignaturesTracker())) + require.True(t, check.IfNil(managedProcessComponents.EpochSystemSCProcessor())) err := managedProcessComponents.Create() require.NoError(t, err) @@ -137,6 +138,7 @@ func TestManagedProcessComponents_Create(t *testing.T) { require.False(t, check.IfNil(managedProcessComponents.FullArchivePeerShardMapper())) require.False(t, check.IfNil(managedProcessComponents.FullArchiveInterceptorsContainer())) require.False(t, check.IfNil(managedProcessComponents.SentSignaturesTracker())) + require.False(t, check.IfNil(managedProcessComponents.EpochSystemSCProcessor())) require.Equal(t, factory.ProcessComponentsName, managedProcessComponents.String()) }) diff --git a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index 653ab74f031..e61166264bb 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go @@ -83,6 +83,13 @@ func TestChainSimulator_MakeNewContractFromValidatorData(t *testing.T) { NumNodesWaitingListMeta: 3, NumNodesWaitingListShard: 3, AlterConfigsFunction: func(cfg *config.Configs) { + maxNodesChangeEnableEpoch := cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch + blsMultiSignerEnableEpoch := cfg.EpochConfig.EnableEpochs.BLSMultiSignerEnableEpoch + + cfg.EpochConfig.EnableEpochs = config.EnableEpochs{} + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch = maxNodesChangeEnableEpoch + cfg.EpochConfig.EnableEpochs.BLSMultiSignerEnableEpoch = blsMultiSignerEnableEpoch + cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 102 @@ -98,6 +105,57 @@ func TestChainSimulator_MakeNewContractFromValidatorData(t *testing.T) { testChainSimulatorMakeNewContractFromValidatorData(t, cs, 1) }) + // Test scenario done in staking 3.5 phase (staking v4 is not active) + // 1. Add a new validator private key in the multi key handler + // 2. Set the initial state for the owner and the 2 delegators + // 3. Do a stake transaction for the validator key and test that the new key is on queue and topup is 500 + // 4. Execute the MakeNewContractFromValidatorData transaction and test that the key is on queue and topup is 500 + // 5. Execute 2 delegation operations of 100 EGLD each, check the topup is 700 + // 6. Execute 2 unDelegate operations of 100 EGLD each, check the topup is back to 500 + t.Run("staking ph 4 is not active and all is done in epoch 0", func(t *testing.T) { + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: time.Now().Unix(), + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 3, + MetaChainMinNodes: 3, + NumNodesWaitingListMeta: 3, + NumNodesWaitingListShard: 3, + AlterConfigsFunction: func(cfg *config.Configs) { + maxNodesChangeEnableEpoch := cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch + blsMultiSignerEnableEpoch := cfg.EpochConfig.EnableEpochs.BLSMultiSignerEnableEpoch + + // set all activation epoch values on 0 + cfg.EpochConfig.EnableEpochs = config.EnableEpochs{} + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch = maxNodesChangeEnableEpoch + cfg.EpochConfig.EnableEpochs.BLSMultiSignerEnableEpoch = blsMultiSignerEnableEpoch + + cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100 + cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101 + cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 102 + + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 102 + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + // we need a little time to enable the VM queries on the http server + time.Sleep(time.Second) + // also, propose a couple of blocks + err = cs.GenerateBlocks(3) + require.Nil(t, err) + + testChainSimulatorMakeNewContractFromValidatorData(t, cs, 0) + }) + // Test scenario done in staking v4 phase step 1 // 1. Add a new validator private key in the multi key handler // 2. Set the initial state for the owner and the 2 delegators diff --git a/integrationTests/mock/processComponentsStub.go b/integrationTests/mock/processComponentsStub.go index e0407b5d6f9..11d4f4ce69d 100644 --- a/integrationTests/mock/processComponentsStub.go +++ b/integrationTests/mock/processComponentsStub.go @@ -60,6 +60,7 @@ type ProcessComponentsStub struct { ReceiptsRepositoryInternal factory.ReceiptsRepository ESDTDataStorageHandlerForAPIInternal vmcommon.ESDTNFTStorageHandler SentSignaturesTrackerInternal process.SentSignaturesTracker + EpochSystemSCProcessorInternal process.EpochStartSystemSCProcessor } // Create - @@ -296,6 +297,11 @@ func (pcs *ProcessComponentsStub) SentSignaturesTracker() process.SentSignatures return pcs.SentSignaturesTrackerInternal } +// EpochSystemSCProcessor - +func (pcs *ProcessComponentsStub) EpochSystemSCProcessor() process.EpochStartSystemSCProcessor { + return pcs.EpochSystemSCProcessorInternal +} + // IsInterfaceNil - func (pcs *ProcessComponentsStub) IsInterfaceNil() bool { return pcs == nil diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index 8bffcb6c63a..4a0bfcb636e 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -130,6 +130,31 @@ func (s *simulator) createChainHandlers(args ArgsChainSimulator) error { shardID := node.GetShardCoordinator().SelfId() s.nodes[shardID] = node s.handlers = append(s.handlers, chainHandler) + + if node.GetShardCoordinator().SelfId() == core.MetachainShardId { + currentRootHash, errRootHash := node.GetProcessComponents().ValidatorsStatistics().RootHash() + if errRootHash != nil { + return errRootHash + } + + allValidatorsInfo, errGet := node.GetProcessComponents().ValidatorsStatistics().GetValidatorInfoForRootHash(currentRootHash) + if errRootHash != nil { + return errGet + } + + err = node.GetProcessComponents().EpochSystemSCProcessor().ProcessSystemSmartContract( + allValidatorsInfo, + node.GetDataComponents().Blockchain().GetGenesisHeader(), + ) + if err != nil { + return err + } + + _, err = node.GetStateComponents().AccountsAdapter().Commit() + if err != nil { + return err + } + } } s.initialWalletKeys = outputConfigs.InitialWallets @@ -411,17 +436,17 @@ func (s *simulator) SetStateMultiple(stateSlice []*dtos.AddressState) error { defer s.mutex.Unlock() addressConverter := s.nodes[core.MetachainShardId].GetCoreComponents().AddressPubKeyConverter() - for _, state := range stateSlice { - addressBytes, err := addressConverter.Decode(state.Address) + for _, stateValue := range stateSlice { + addressBytes, err := addressConverter.Decode(stateValue.Address) if err != nil { return err } if bytes.Equal(addressBytes, core.SystemAccountAddress) { - err = s.setStateSystemAccount(state) + err = s.setStateSystemAccount(stateValue) } else { shardID := sharding.ComputeShardID(addressBytes, s.numOfShards) - err = s.nodes[shardID].SetStateForAddress(addressBytes, state) + err = s.nodes[shardID].SetStateForAddress(addressBytes, stateValue) } if err != nil { return err diff --git a/node/chainSimulator/components/processComponents.go b/node/chainSimulator/components/processComponents.go index efa7af79c10..3bfd598f98d 100644 --- a/node/chainSimulator/components/processComponents.go +++ b/node/chainSimulator/components/processComponents.go @@ -98,6 +98,7 @@ type processComponentsHolder struct { esdtDataStorageHandlerForAPI vmcommon.ESDTNFTStorageHandler accountsParser genesis.AccountsParser sentSignatureTracker process.SentSignaturesTracker + epochStartSystemSCProcessor process.EpochStartSystemSCProcessor managedProcessComponentsCloser io.Closer } @@ -270,6 +271,7 @@ func CreateProcessComponents(args ArgsProcessComponentsHolder) (*processComponen esdtDataStorageHandlerForAPI: managedProcessComponents.ESDTDataStorageHandlerForAPI(), accountsParser: managedProcessComponents.AccountsParser(), sentSignatureTracker: managedProcessComponents.SentSignaturesTracker(), + epochStartSystemSCProcessor: managedProcessComponents.EpochSystemSCProcessor(), managedProcessComponentsCloser: managedProcessComponents, } @@ -481,6 +483,11 @@ func (p *processComponentsHolder) ReceiptsRepository() factory.ReceiptsRepositor return p.receiptsRepository } +// EpochSystemSCProcessor returns the epoch start system SC processor +func (p *processComponentsHolder) EpochSystemSCProcessor() process.EpochStartSystemSCProcessor { + return p.epochStartSystemSCProcessor +} + // Close will call the Close methods on all inner components func (p *processComponentsHolder) Close() error { return p.managedProcessComponentsCloser.Close() diff --git a/node/chainSimulator/components/processComponents_test.go b/node/chainSimulator/components/processComponents_test.go index 4628bbc4f66..efc5590e7f4 100644 --- a/node/chainSimulator/components/processComponents_test.go +++ b/node/chainSimulator/components/processComponents_test.go @@ -407,6 +407,7 @@ func TestProcessComponentsHolder_Getters(t *testing.T) { require.NotNil(t, comp.ESDTDataStorageHandlerForAPI()) require.NotNil(t, comp.AccountsParser()) require.NotNil(t, comp.ReceiptsRepository()) + require.NotNil(t, comp.EpochSystemSCProcessor()) require.Nil(t, comp.CheckSubcomponents()) require.Empty(t, comp.String()) diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index e08f4fc1367..7b375ae08cb 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -370,6 +370,11 @@ func (node *testOnlyProcessingNode) GetCoreComponents() factory.CoreComponentsHo return node.CoreComponentsHolder } +// GetDataComponents will return the data components +func (node *testOnlyProcessingNode) GetDataComponents() factory.DataComponentsHolder { + return node.DataComponentsHolder +} + // GetStateComponents will return the state components func (node *testOnlyProcessingNode) GetStateComponents() factory.StateComponentsHolder { return node.StateComponentsHolder diff --git a/node/chainSimulator/process/interface.go b/node/chainSimulator/process/interface.go index 6dc0b84fa02..ee54998dc7f 100644 --- a/node/chainSimulator/process/interface.go +++ b/node/chainSimulator/process/interface.go @@ -17,6 +17,7 @@ type NodeHandler interface { GetShardCoordinator() sharding.Coordinator GetCryptoComponents() factory.CryptoComponentsHolder GetCoreComponents() factory.CoreComponentsHolder + GetDataComponents() factory.DataComponentsHolder GetStateComponents() factory.StateComponentsHolder GetFacadeHandler() shared.FacadeHandler GetStatusCoreComponents() factory.StatusCoreComponentsHolder diff --git a/testscommon/chainSimulator/nodeHandlerMock.go b/testscommon/chainSimulator/nodeHandlerMock.go index 23941f914eb..52b72a17acc 100644 --- a/testscommon/chainSimulator/nodeHandlerMock.go +++ b/testscommon/chainSimulator/nodeHandlerMock.go @@ -17,6 +17,7 @@ type NodeHandlerMock struct { GetShardCoordinatorCalled func() sharding.Coordinator GetCryptoComponentsCalled func() factory.CryptoComponentsHolder GetCoreComponentsCalled func() factory.CoreComponentsHolder + GetDataComponentsCalled func() factory.DataComponentsHandler GetStateComponentsCalled func() factory.StateComponentsHolder GetFacadeHandlerCalled func() shared.FacadeHandler GetStatusCoreComponentsCalled func() factory.StatusCoreComponentsHolder @@ -73,6 +74,14 @@ func (mock *NodeHandlerMock) GetCoreComponents() factory.CoreComponentsHolder { return nil } +// GetDataComponents - +func (mock *NodeHandlerMock) GetDataComponents() factory.DataComponentsHolder { + if mock.GetDataComponentsCalled != nil { + return mock.GetDataComponentsCalled() + } + return nil +} + // GetStateComponents - func (mock *NodeHandlerMock) GetStateComponents() factory.StateComponentsHolder { if mock.GetStateComponentsCalled != nil { From bcd6efca6ce8150da9f5f895d06e80d59caf4d86 Mon Sep 17 00:00:00 2001 From: radu chis Date: Mon, 22 Apr 2024 15:33:18 +0300 Subject: [PATCH 059/467] refactored withKeys --- api/groups/addressGroup.go | 8 ++++ api/groups/addressGroupOptions.go | 7 +-- facade/interface.go | 6 ++- facade/mock/nodeStub.go | 16 +++++-- facade/nodeFacade.go | 36 +++++++++------ facade/nodeFacade_test.go | 14 +++--- go.mod | 2 +- go.sum | 4 +- .../node/getAccount/getAccount_test.go | 5 +-- node/node.go | 45 ++++++++++++++++++- node/nodeLoadAccounts_test.go | 3 +- node/node_test.go | 14 +++--- 12 files changed, 113 insertions(+), 47 deletions(-) diff --git a/api/groups/addressGroup.go b/api/groups/addressGroup.go index da2adc0ab56..a059d3a4388 100644 --- a/api/groups/addressGroup.go +++ b/api/groups/addressGroup.go @@ -186,6 +186,14 @@ func (ag *addressGroup) getAccount(c *gin.Context) { return } + withKeys, err := parseBoolUrlParam(c, urlParamWithKeys) + if err != nil { + shared.RespondWithValidationError(c, errors.ErrCouldNotGetAccount, err) + return + } + + options.WithKeys = withKeys + accountResponse, blockInfo, err := ag.getFacade().GetAccount(addr, options) if err != nil { shared.RespondWithInternalError(c, errors.ErrCouldNotGetAccount, err) diff --git a/api/groups/addressGroupOptions.go b/api/groups/addressGroupOptions.go index c3841f7e7fd..e21dc6d361a 100644 --- a/api/groups/addressGroupOptions.go +++ b/api/groups/addressGroupOptions.go @@ -54,11 +54,6 @@ func parseAccountQueryOptions(c *gin.Context) (api.AccountQueryOptions, error) { return api.AccountQueryOptions{}, err } - withKeys, err := parseBoolUrlParam(c, urlParamWithKeys) - if err != nil { - return api.AccountQueryOptions{}, err - } - options := api.AccountQueryOptions{ OnFinalBlock: onFinalBlock, OnStartOfEpoch: onStartOfEpoch, @@ -66,7 +61,7 @@ func parseAccountQueryOptions(c *gin.Context) (api.AccountQueryOptions, error) { BlockHash: blockHash, BlockRootHash: blockRootHash, HintEpoch: hintEpoch, - WithKeys: withKeys, + WithKeys: false, } return options, nil } diff --git a/facade/interface.go b/facade/interface.go index b7deebb17e7..e3be7b76cb0 100644 --- a/facade/interface.go +++ b/facade/interface.go @@ -74,7 +74,11 @@ type NodeHandler interface { // GetAccount returns an accountResponse containing information // about the account correlated with provided address - GetAccount(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) + GetAccount(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) + + // GetAccountWithKeys returns an accountResponse containing information + // about the account correlated with provided address and all keys + GetAccountWithKeys(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) // GetCode returns the code for the given code hash GetCode(codeHash []byte, options api.AccountQueryOptions) ([]byte, api.BlockInfo) diff --git a/facade/mock/nodeStub.go b/facade/mock/nodeStub.go index d03d847b151..1e779e0ebce 100644 --- a/facade/mock/nodeStub.go +++ b/facade/mock/nodeStub.go @@ -25,7 +25,8 @@ type NodeStub struct { ValidateTransactionHandler func(tx *transaction.Transaction) error ValidateTransactionForSimulationCalled func(tx *transaction.Transaction, bypassSignature bool) error SendBulkTransactionsHandler func(txs []*transaction.Transaction) (uint64, error) - GetAccountCalled func(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) + GetAccountCalled func(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) + GetAccountWithKeysCalled func(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) GetCodeCalled func(codeHash []byte, options api.AccountQueryOptions) ([]byte, api.BlockInfo) GetCurrentPublicKeyHandler func() string GenerateAndSendBulkTransactionsHandler func(destination string, value *big.Int, nrTransactions uint64) error @@ -181,9 +182,18 @@ func (ns *NodeStub) SendBulkTransactions(txs []*transaction.Transaction) (uint64 } // GetAccount - -func (ns *NodeStub) GetAccount(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) { +func (ns *NodeStub) GetAccount(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { if ns.GetAccountCalled != nil { - return ns.GetAccountCalled(address, options, ctx) + return ns.GetAccountCalled(address, options) + } + + return api.AccountResponse{}, api.BlockInfo{}, nil +} + +// GetAccountWithKeys - +func (ns *NodeStub) GetAccountWithKeys(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) { + if ns.GetAccountWithKeysCalled != nil { + return ns.GetAccountWithKeysCalled(address, options, ctx) } return api.AccountResponse{}, api.BlockInfo{}, nil diff --git a/facade/nodeFacade.go b/facade/nodeFacade.go index 4e328b5462a..8bc696b6adc 100644 --- a/facade/nodeFacade.go +++ b/facade/nodeFacade.go @@ -321,10 +321,7 @@ func (nf *nodeFacade) GetLastPoolNonceForSender(sender string) (uint64, error) { // GetTransactionsPoolNonceGapsForSender will return the nonce gaps from pool for sender, if exists, that is to be returned on API calls func (nf *nodeFacade) GetTransactionsPoolNonceGapsForSender(sender string) (*common.TransactionsPoolNonceGapsForSenderApiResponse, error) { - ctx, cancel := nf.getContextForApiTrieRangeOperations() - defer cancel() - - accountResponse, _, err := nf.node.GetAccount(sender, apiData.AccountQueryOptions{}, ctx) + accountResponse, _, err := nf.node.GetAccount(sender, apiData.AccountQueryOptions{}) if err != nil { return &common.TransactionsPoolNonceGapsForSenderApiResponse{}, err } @@ -339,10 +336,19 @@ func (nf *nodeFacade) ComputeTransactionGasLimit(tx *transaction.Transaction) (* // GetAccount returns a response containing information about the account correlated with provided address func (nf *nodeFacade) GetAccount(address string, options apiData.AccountQueryOptions) (apiData.AccountResponse, apiData.BlockInfo, error) { - ctx, cancel := nf.getContextForApiTrieRangeOperations() - defer cancel() + var accountResponse apiData.AccountResponse + var blockInfo apiData.BlockInfo + var err error + + if options.WithKeys { + ctx, cancel := nf.getContextForApiTrieRangeOperations() + defer cancel() + + accountResponse, blockInfo, err = nf.node.GetAccountWithKeys(address, options, ctx) + } else { + accountResponse, blockInfo, err = nf.node.GetAccount(address, options) + } - accountResponse, blockInfo, err := nf.node.GetAccount(address, options, ctx) if err != nil { return apiData.AccountResponse{}, apiData.BlockInfo{}, err } @@ -364,16 +370,20 @@ func (nf *nodeFacade) GetAccounts(addresses []string, options apiData.AccountQue response := make(map[string]*apiData.AccountResponse) var blockInfo apiData.BlockInfo - ctx, cancel := nf.getContextForApiTrieRangeOperations() - defer cancel() - for _, address := range addresses { - accountResponse, blockInfoForAccount, err := nf.node.GetAccount(address, options, ctx) + for i, address := range addresses { + accountResponse, blockInfoForAccount, err := nf.node.GetAccount(address, options) if err != nil { return nil, apiData.BlockInfo{}, err } - - blockInfo = blockInfoForAccount + // Use the first block info as the block info for the whole bulk + if i == 0 { + blockInfo = blockInfoForAccount + blockRootHash, errBlockRootHash := hex.DecodeString(blockInfoForAccount.RootHash) + if errBlockRootHash == nil { + options.BlockRootHash = blockRootHash + } + } codeHash := accountResponse.CodeHash code, _ := nf.node.GetCode(codeHash, options) diff --git a/facade/nodeFacade_test.go b/facade/nodeFacade_test.go index f2eaff6025e..21823b60b6e 100644 --- a/facade/nodeFacade_test.go +++ b/facade/nodeFacade_test.go @@ -338,7 +338,7 @@ func TestNodeFacade_GetAccount(t *testing.T) { arg := createMockArguments() arg.Node = &mock.NodeStub{ - GetAccountCalled: func(_ string, _ api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { + GetAccountCalled: func(_ string, _ api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { return api.AccountResponse{}, api.BlockInfo{}, expectedErr }, } @@ -352,7 +352,7 @@ func TestNodeFacade_GetAccount(t *testing.T) { getAccountCalled := false node := &mock.NodeStub{} - node.GetAccountCalled = func(address string, _ api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { + node.GetAccountCalled = func(address string, _ api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { getAccountCalled = true return api.AccountResponse{}, api.BlockInfo{}, nil } @@ -387,7 +387,7 @@ func TestNodeFacade_GetAccounts(t *testing.T) { t.Parallel() node := &mock.NodeStub{} - node.GetAccountCalled = func(address string, _ api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { + node.GetAccountCalled = func(address string, _ api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { return api.AccountResponse{}, api.BlockInfo{}, expectedErr } @@ -407,7 +407,7 @@ func TestNodeFacade_GetAccounts(t *testing.T) { expectedAcount := api.AccountResponse{Address: "test"} node := &mock.NodeStub{} - node.GetAccountCalled = func(address string, _ api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { + node.GetAccountCalled = func(address string, _ api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { return expectedAcount, api.BlockInfo{}, nil } @@ -2008,7 +2008,7 @@ func TestNodeFacade_GetTransactionsPoolNonceGapsForSender(t *testing.T) { arg := createMockArguments() arg.Node = &mock.NodeStub{ - GetAccountCalled: func(address string, options api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { + GetAccountCalled: func(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { return api.AccountResponse{}, api.BlockInfo{}, expectedErr }, } @@ -2030,7 +2030,7 @@ func TestNodeFacade_GetTransactionsPoolNonceGapsForSender(t *testing.T) { arg := createMockArguments() arg.Node = &mock.NodeStub{ - GetAccountCalled: func(address string, options api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { + GetAccountCalled: func(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { return api.AccountResponse{}, api.BlockInfo{}, nil }, } @@ -2062,7 +2062,7 @@ func TestNodeFacade_GetTransactionsPoolNonceGapsForSender(t *testing.T) { } providedNonce := uint64(10) arg.Node = &mock.NodeStub{ - GetAccountCalled: func(address string, options api.AccountQueryOptions, _ context.Context) (api.AccountResponse, api.BlockInfo, error) { + GetAccountCalled: func(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { return api.AccountResponse{Nonce: providedNonce}, api.BlockInfo{}, nil }, } diff --git a/go.mod b/go.mod index b5d8fd684c6..f8454ef4f3a 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 github.com/multiversx/mx-chain-communication-go v1.0.14 - github.com/multiversx/mx-chain-core-go v1.2.20-0.20240418121049-6970013b49d9 + github.com/multiversx/mx-chain-core-go v1.2.20 github.com/multiversx/mx-chain-crypto-go v1.2.11 github.com/multiversx/mx-chain-es-indexer-go v1.4.21 github.com/multiversx/mx-chain-logger-go v1.0.14 diff --git a/go.sum b/go.sum index 64517c9b404..03321b70303 100644 --- a/go.sum +++ b/go.sum @@ -387,8 +387,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= github.com/multiversx/mx-chain-communication-go v1.0.14 h1:YhAUDjBBpc5h5W0A7LHLXUMIMeCgwgGvkqfAPbFqsno= github.com/multiversx/mx-chain-communication-go v1.0.14/go.mod h1:qYCqgk0h+YpcTA84jHIpCBy6UShRwmXzHSCcdfwNrkw= -github.com/multiversx/mx-chain-core-go v1.2.20-0.20240418121049-6970013b49d9 h1:iUGEUzmxh2xrgaHS9Lq5CpnKGDsR02v9gEWroc/jbpA= -github.com/multiversx/mx-chain-core-go v1.2.20-0.20240418121049-6970013b49d9/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.20 h1:jOQ10LxxUqECnuqUYeBBT6VoZcpJDdYgOvsSGtifDdI= +github.com/multiversx/mx-chain-core-go v1.2.20/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.11 h1:MNPJoiTJA5/tedYrI0N22OorbsKDESWG0SF8MCJwcJI= github.com/multiversx/mx-chain-crypto-go v1.2.11/go.mod h1:pcZutPdfLiAFytzCU3LxU3s8cXkvpNqquyitFSfoF3o= github.com/multiversx/mx-chain-es-indexer-go v1.4.21 h1:rzxXCkgOsqj67GRYtqzKuf9XgHwnZLTZhU90Ck3VbrE= diff --git a/integrationTests/node/getAccount/getAccount_test.go b/integrationTests/node/getAccount/getAccount_test.go index c48a1017a4e..487c8b1a15a 100644 --- a/integrationTests/node/getAccount/getAccount_test.go +++ b/integrationTests/node/getAccount/getAccount_test.go @@ -1,7 +1,6 @@ package getAccount import ( - "context" "math/big" "testing" @@ -58,7 +57,7 @@ func TestNode_GetAccountAccountDoesNotExistsShouldRetEmpty(t *testing.T) { encodedAddress, err := integrationTests.TestAddressPubkeyConverter.Encode(integrationTests.CreateRandomBytes(32)) require.Nil(t, err) - recovAccnt, _, err := n.GetAccount(encodedAddress, api.AccountQueryOptions{}, context.Background()) + recovAccnt, _, err := n.GetAccount(encodedAddress, api.AccountQueryOptions{}) require.Nil(t, err) assert.Equal(t, uint64(0), recovAccnt.Nonce) @@ -100,7 +99,7 @@ func TestNode_GetAccountAccountExistsShouldReturn(t *testing.T) { testAddress, err := coreComponents.AddressPubKeyConverter().Encode(testPubkey) require.Nil(t, err) - recovAccnt, _, err := n.GetAccount(testAddress, api.AccountQueryOptions{}, context.Background()) + recovAccnt, _, err := n.GetAccount(testAddress, api.AccountQueryOptions{}) require.Nil(t, err) require.Equal(t, testNonce, recovAccnt.Nonce) diff --git a/node/node.go b/node/node.go index 29cea2671d6..db2031a37ca 100644 --- a/node/node.go +++ b/node/node.go @@ -938,7 +938,45 @@ func (n *Node) setTxGuardianData(guardian string, guardianSigHex string, tx *tra } // GetAccount will return account details for a given address -func (n *Node) GetAccount(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) { +func (n *Node) GetAccount(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { + account, blockInfo, err := n.loadUserAccountHandlerByAddress(address, options) + if err != nil { + adaptedBlockInfo, isEmptyAccount := extractBlockInfoIfNewAccount(err) + if isEmptyAccount { + return api.AccountResponse{ + Address: address, + Balance: "0", + DeveloperReward: "0", + }, adaptedBlockInfo, nil + } + + return api.AccountResponse{}, api.BlockInfo{}, err + } + + ownerAddress := "" + if len(account.GetOwnerAddress()) > 0 { + addressPubkeyConverter := n.coreComponents.AddressPubKeyConverter() + ownerAddress, err = addressPubkeyConverter.Encode(account.GetOwnerAddress()) + if err != nil { + return api.AccountResponse{}, api.BlockInfo{}, err + } + } + + return api.AccountResponse{ + Address: address, + Nonce: account.GetNonce(), + Balance: account.GetBalance().String(), + Username: string(account.GetUserName()), + CodeHash: account.GetCodeHash(), + RootHash: account.GetRootHash(), + CodeMetadata: account.GetCodeMetadata(), + DeveloperReward: account.GetDeveloperReward().String(), + OwnerAddress: ownerAddress, + }, blockInfo, nil +} + +// GetAccountWithKeys will return account details for a given address including the keys +func (n *Node) GetAccountWithKeys(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) { account, blockInfo, err := n.loadUserAccountHandlerByAddress(address, options) if err != nil { adaptedBlockInfo, isEmptyAccount := extractBlockInfoIfNewAccount(err) @@ -964,7 +1002,10 @@ func (n *Node) GetAccount(address string, options api.AccountQueryOptions, ctx c var keys map[string]string if options.WithKeys { - keys, _ = n.getKeys(account, ctx) + keys, err = n.getKeys(account, ctx) + if err != nil { + return api.AccountResponse{}, api.BlockInfo{}, err + } } return api.AccountResponse{ diff --git a/node/nodeLoadAccounts_test.go b/node/nodeLoadAccounts_test.go index 7ef831bca0f..e7e03c2d05b 100644 --- a/node/nodeLoadAccounts_test.go +++ b/node/nodeLoadAccounts_test.go @@ -2,7 +2,6 @@ package node_test import ( "bytes" - "context" "errors" "math/big" "testing" @@ -46,7 +45,7 @@ func TestNode_GetAccountWithOptionsShouldWork(t *testing.T) { node.WithStateComponents(stateComponents), ) - account, blockInfo, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}, context.Background()) + account, blockInfo, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}) require.Nil(t, err) require.Equal(t, "100", account.Balance) require.Equal(t, uint64(1), blockInfo.Nonce) diff --git a/node/node_test.go b/node/node_test.go index d10f79b67be..dc8b012734e 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -3293,7 +3293,7 @@ func TestNode_GetAccountPubkeyConverterFailsShouldErr(t *testing.T) { node.WithCoreComponents(coreComponents), ) - recovAccnt, _, err := n.GetAccount(createDummyHexAddress(64), api.AccountQueryOptions{}, context.Background()) + recovAccnt, _, err := n.GetAccount(createDummyHexAddress(64), api.AccountQueryOptions{}) assert.Empty(t, recovAccnt) assert.ErrorIs(t, err, errExpected) @@ -3320,7 +3320,7 @@ func TestNode_GetAccountAccountDoesNotExistsShouldRetEmpty(t *testing.T) { node.WithStateComponents(stateComponents), ) - account, blockInfo, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}, context.Background()) + account, blockInfo, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}) require.Nil(t, err) require.Equal(t, uint64(0), account.Nonce) @@ -3355,7 +3355,7 @@ func TestNode_GetAccountAccountsRepositoryFailsShouldErr(t *testing.T) { node.WithStateComponents(stateComponents), ) - recovAccnt, _, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}, context.Background()) + recovAccnt, _, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}) assert.Empty(t, recovAccnt) assert.NotNil(t, err) @@ -3394,7 +3394,7 @@ func TestNode_GetAccountAccNotFoundShouldReturnEmpty(t *testing.T) { node.WithStateComponents(stateComponents), ) - acc, bInfo, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}, context.Background()) + acc, bInfo, err := n.GetAccount(testscommon.TestAddressAlice, api.AccountQueryOptions{}) require.Nil(t, err) require.Equal(t, dummyBlockInfo.apiResult(), bInfo) require.Equal(t, api.AccountResponse{Address: testscommon.TestAddressAlice, Balance: "0", DeveloperReward: "0"}, acc) @@ -3436,7 +3436,7 @@ func TestNode_GetAccountAccountExistsShouldReturn(t *testing.T) { node.WithStateComponents(stateComponents), ) - recovAccnt, _, err := n.GetAccount(testscommon.TestAddressBob, api.AccountQueryOptions{}, context.Background()) + recovAccnt, _, err := n.GetAccount(testscommon.TestAddressBob, api.AccountQueryOptions{}) require.Nil(t, err) require.Equal(t, uint64(2), recovAccnt.Nonce) @@ -3503,11 +3503,11 @@ func TestNode_GetAccountAccountWithKeysShouldReturn(t *testing.T) { node.WithStateComponents(stateComponents), ) - recovAccnt, _, err := n.GetAccount(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: false}, context.Background()) + recovAccnt, _, err := n.GetAccountWithKeys(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: false}, context.Background()) require.Nil(t, err) require.Nil(t, recovAccnt.Pairs) - recovAccnt, _, err = n.GetAccount(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: true}, context.Background()) + recovAccnt, _, err = n.GetAccountWithKeys(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: true}, context.Background()) require.Nil(t, err) require.NotNil(t, recovAccnt.Pairs) From ec6236c52bb80ddf867cb59d12506e52a0dfa6db Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Tue, 23 Apr 2024 11:03:36 +0300 Subject: [PATCH 060/467] - added RemoveAccounts feature on the chain simulator --- node/chainSimulator/chainSimulator.go | 37 ++++++ node/chainSimulator/chainSimulator_test.go | 115 ++++++++++++++++++ .../components/testOnlyProcessingNode.go | 12 ++ node/chainSimulator/process/interface.go | 1 + testscommon/chainSimulator/nodeHandlerMock.go | 10 ++ 5 files changed, 175 insertions(+) diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index 4a0bfcb636e..d70921984e3 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -456,6 +456,32 @@ func (s *simulator) SetStateMultiple(stateSlice []*dtos.AddressState) error { return nil } +// RemoveAccounts will try to remove all accounts data for the addresses provided +func (s *simulator) RemoveAccounts(addresses []string) error { + s.mutex.Lock() + defer s.mutex.Unlock() + + addressConverter := s.nodes[core.MetachainShardId].GetCoreComponents().AddressPubKeyConverter() + for _, address := range addresses { + addressBytes, err := addressConverter.Decode(address) + if err != nil { + return err + } + + if bytes.Equal(addressBytes, core.SystemAccountAddress) { + err = s.removeAllSystemAccounts() + } else { + shardID := sharding.ComputeShardID(addressBytes, s.numOfShards) + err = s.nodes[shardID].RemoveAccount(addressBytes) + } + if err != nil { + return err + } + } + + return nil +} + // SendTxAndGenerateBlockTilTxIsExecuted will send the provided transaction and generate block until the transaction is executed func (s *simulator) SendTxAndGenerateBlockTilTxIsExecuted(txToSend *transaction.Transaction, maxNumOfBlocksToGenerateWhenExecutingTx int) (*transaction.ApiTransactionResult, error) { result, err := s.SendTxsAndGenerateBlocksTilAreExecuted([]*transaction.Transaction{txToSend}, maxNumOfBlocksToGenerateWhenExecutingTx) @@ -581,6 +607,17 @@ func (s *simulator) setStateSystemAccount(state *dtos.AddressState) error { return nil } +func (s *simulator) removeAllSystemAccounts() error { + for shard, node := range s.nodes { + err := node.RemoveAccount(core.SystemAccountAddress) + if err != nil { + return fmt.Errorf("%w for shard %d", err, shard) + } + } + + return nil +} + // GetAccount will fetch the account of the provided address func (s *simulator) GetAccount(address dtos.WalletAddress) (api.AccountResponse, error) { destinationShardID := s.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index 1a65b37ff78..e4092a16b9c 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -264,6 +264,121 @@ func TestChainSimulator_SetEntireState(t *testing.T) { require.Equal(t, accountState.RootHash, base64.StdEncoding.EncodeToString(account.RootHash)) } +func TestChainSimulator_SetEntireStateWithRemoval(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: 3, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 1, + MetaChainMinNodes: 1, + }) + require.Nil(t, err) + require.NotNil(t, chainSimulator) + + defer chainSimulator.Close() + + // activate the auto balancing tries so the results will be the same + err = chainSimulator.GenerateBlocks(30) + require.Nil(t, err) + + balance := "431271308732096033771131" + contractAddress := "erd1qqqqqqqqqqqqqpgqmzzm05jeav6d5qvna0q2pmcllelkz8xddz3syjszx5" + accountState := &dtos.AddressState{ + Address: contractAddress, + Nonce: new(uint64), + Balance: balance, + Code: "0061736d010000000129086000006000017f60027f7f017f60027f7f0060017f0060037f7f7f017f60037f7f7f0060017f017f0290020b03656e7619626967496e74476574556e7369676e6564417267756d656e74000303656e760f6765744e756d417267756d656e7473000103656e760b7369676e616c4572726f72000303656e76126d42756666657253746f726167654c6f6164000203656e76176d427566666572546f426967496e74556e7369676e6564000203656e76196d42756666657246726f6d426967496e74556e7369676e6564000203656e76136d42756666657253746f7261676553746f7265000203656e760f6d4275666665725365744279746573000503656e760e636865636b4e6f5061796d656e74000003656e7614626967496e7446696e697368556e7369676e6564000403656e7609626967496e744164640006030b0a010104070301000000000503010003060f027f0041a080080b7f0041a080080b074607066d656d6f7279020004696e697400110667657453756d00120361646400130863616c6c4261636b00140a5f5f646174615f656e6403000b5f5f686561705f6261736503010aca010a0e01017f4100100c2200100020000b1901017f419c8008419c800828020041016b220036020020000b1400100120004604400f0b4180800841191002000b16002000100c220010031a2000100c220010041a20000b1401017f100c2202200110051a2000200210061a0b1301017f100c220041998008410310071a20000b1401017f10084101100d100b210010102000100f0b0e0010084100100d1010100e10090b2201037f10084101100d100b210110102202100e220020002001100a20022000100f0b0300010b0b2f0200418080080b1c77726f6e67206e756d626572206f6620617267756d656e747373756d00419c80080b049cffffff", + CodeHash: "n9EviPlHS6EV+3Xp0YqP28T0IUfeAFRFBIRC1Jw6pyU=", + RootHash: "eqIumOaMn7G5cNSViK3XHZIW/C392ehfHxOZkHGp+Gc=", // root hash with auto balancing enabled + CodeMetadata: "BQY=", + Owner: "erd1ss6u80ruas2phpmr82r42xnkd6rxy40g9jl69frppl4qez9w2jpsqj8x97", + DeveloperRewards: "5401004999998", + Keys: map[string]string{ + "73756d": "0a", + }, + } + + err = chainSimulator.SetStateMultiple([]*dtos.AddressState{accountState}) + require.Nil(t, err) + + err = chainSimulator.GenerateBlocks(2) + require.Nil(t, err) + + nodeHandler := chainSimulator.GetNodeHandler(1) + scAddress, _ := nodeHandler.GetCoreComponents().AddressPubKeyConverter().Decode(contractAddress) + res, _, err := nodeHandler.GetFacadeHandler().ExecuteSCQuery(&process.SCQuery{ + ScAddress: scAddress, + FuncName: "getSum", + CallerAddr: nil, + BlockNonce: core.OptionalUint64{}, + }) + require.Nil(t, err) + + counterValue := big.NewInt(0).SetBytes(res.ReturnData[0]).Int64() + require.Equal(t, 10, int(counterValue)) + + account, _, err := nodeHandler.GetFacadeHandler().GetAccount(contractAddress, coreAPI.AccountQueryOptions{}) + require.Nil(t, err) + require.Equal(t, accountState.Balance, account.Balance) + require.Equal(t, accountState.DeveloperRewards, account.DeveloperReward) + require.Equal(t, accountState.Code, account.Code) + require.Equal(t, accountState.CodeHash, base64.StdEncoding.EncodeToString(account.CodeHash)) + require.Equal(t, accountState.CodeMetadata, base64.StdEncoding.EncodeToString(account.CodeMetadata)) + require.Equal(t, accountState.Owner, account.OwnerAddress) + require.Equal(t, accountState.RootHash, base64.StdEncoding.EncodeToString(account.RootHash)) + + // Now we remove the account + err = chainSimulator.RemoveAccounts([]string{contractAddress}) + require.Nil(t, err) + + err = chainSimulator.GenerateBlocks(2) + require.Nil(t, err) + + account, _, err = nodeHandler.GetFacadeHandler().GetAccount(contractAddress, coreAPI.AccountQueryOptions{}) + require.Nil(t, err) + require.Equal(t, "0", account.Balance) + require.Equal(t, "0", account.DeveloperReward) + require.Equal(t, "", account.Code) + require.Equal(t, "", base64.StdEncoding.EncodeToString(account.CodeHash)) + require.Equal(t, "", base64.StdEncoding.EncodeToString(account.CodeMetadata)) + require.Equal(t, "", account.OwnerAddress) + require.Equal(t, "", base64.StdEncoding.EncodeToString(account.RootHash)) + + // Set the state again + err = chainSimulator.SetStateMultiple([]*dtos.AddressState{accountState}) + require.Nil(t, err) + + err = chainSimulator.GenerateBlocks(2) + require.Nil(t, err) + + account, _, err = nodeHandler.GetFacadeHandler().GetAccount(contractAddress, coreAPI.AccountQueryOptions{}) + require.Nil(t, err) + + require.Equal(t, accountState.Balance, account.Balance) + require.Equal(t, accountState.DeveloperRewards, account.DeveloperReward) + require.Equal(t, accountState.Code, account.Code) + require.Equal(t, accountState.CodeHash, base64.StdEncoding.EncodeToString(account.CodeHash)) + require.Equal(t, accountState.CodeMetadata, base64.StdEncoding.EncodeToString(account.CodeMetadata)) + require.Equal(t, accountState.Owner, account.OwnerAddress) + require.Equal(t, accountState.RootHash, base64.StdEncoding.EncodeToString(account.RootHash)) + +} + func TestChainSimulator_GetAccount(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index 7b375ae08cb..1aec0201e6c 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -491,6 +491,18 @@ func (node *testOnlyProcessingNode) SetStateForAddress(address []byte, addressSt return err } +// RemoveAccount will remove the account for the given address +func (node *testOnlyProcessingNode) RemoveAccount(address []byte) error { + accountsAdapter := node.StateComponentsHolder.AccountsAdapter() + err := accountsAdapter.RemoveAccount(address) + if err != nil { + return err + } + + _, err = accountsAdapter.Commit() + return err +} + func setNonceAndBalanceForAccount(userAccount state.UserAccountHandler, nonce *uint64, balance string) error { if nonce != nil { // set nonce to zero diff --git a/node/chainSimulator/process/interface.go b/node/chainSimulator/process/interface.go index ee54998dc7f..d7b0f15820e 100644 --- a/node/chainSimulator/process/interface.go +++ b/node/chainSimulator/process/interface.go @@ -23,6 +23,7 @@ type NodeHandler interface { GetStatusCoreComponents() factory.StatusCoreComponentsHolder SetKeyValueForAddress(addressBytes []byte, state map[string]string) error SetStateForAddress(address []byte, state *dtos.AddressState) error + RemoveAccount(address []byte) error Close() error IsInterfaceNil() bool } diff --git a/testscommon/chainSimulator/nodeHandlerMock.go b/testscommon/chainSimulator/nodeHandlerMock.go index 52b72a17acc..9e0a2ca4d3b 100644 --- a/testscommon/chainSimulator/nodeHandlerMock.go +++ b/testscommon/chainSimulator/nodeHandlerMock.go @@ -23,6 +23,7 @@ type NodeHandlerMock struct { GetStatusCoreComponentsCalled func() factory.StatusCoreComponentsHolder SetKeyValueForAddressCalled func(addressBytes []byte, state map[string]string) error SetStateForAddressCalled func(address []byte, state *dtos.AddressState) error + RemoveAccountCalled func(address []byte) error CloseCalled func() error } @@ -122,6 +123,15 @@ func (mock *NodeHandlerMock) SetStateForAddress(address []byte, state *dtos.Addr return nil } +// RemoveAccount - +func (mock *NodeHandlerMock) RemoveAccount(address []byte) error { + if mock.RemoveAccountCalled != nil { + return mock.RemoveAccountCalled(address) + } + + return nil +} + // Close - func (mock *NodeHandlerMock) Close() error { if mock.CloseCalled != nil { From 4cae25d8bdff39ef737874f72334ee83ddd60655 Mon Sep 17 00:00:00 2001 From: radu chis Date: Tue, 23 Apr 2024 11:12:34 +0300 Subject: [PATCH 061/467] added test for withKeys error --- api/groups/addressGroupOptions.go | 1 - node/node_test.go | 46 +++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/api/groups/addressGroupOptions.go b/api/groups/addressGroupOptions.go index e21dc6d361a..5cd4fc6a11f 100644 --- a/api/groups/addressGroupOptions.go +++ b/api/groups/addressGroupOptions.go @@ -61,7 +61,6 @@ func parseAccountQueryOptions(c *gin.Context) (api.AccountQueryOptions, error) { BlockHash: blockHash, BlockRootHash: blockRootHash, HintEpoch: hintEpoch, - WithKeys: false, } return options, nil } diff --git a/node/node_test.go b/node/node_test.go index dc8b012734e..71eba9f5467 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -3447,6 +3447,51 @@ func TestNode_GetAccountAccountExistsShouldReturn(t *testing.T) { require.Equal(t, testscommon.TestAddressAlice, recovAccnt.OwnerAddress) } +func TestNode_GetAccountAccountWithKeysErrorShouldErr(t *testing.T) { + accnt := createAcc(testscommon.TestPubKeyBob) + _ = accnt.AddToBalance(big.NewInt(1)) + expectedErr := errors.New("expected error") + accnt.SetDataTrie( + &trieMock.TrieStub{ + GetAllLeavesOnChannelCalled: func(leavesChannels *common.TrieIteratorChannels, ctx context.Context, rootHash []byte, _ common.KeyBuilder, tlp common.TrieLeafParser) error { + return expectedErr + }, + RootCalled: func() ([]byte, error) { + return nil, nil + }, + }) + + accDB := &stateMock.AccountsStub{ + GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { + return accnt, nil, nil + }, + RecreateTrieCalled: func(rootHash []byte) error { + return nil + }, + } + + coreComponents := getDefaultCoreComponents() + dataComponents := getDefaultDataComponents() + stateComponents := getDefaultStateComponents() + args := state.ArgsAccountsRepository{ + FinalStateAccountsWrapper: accDB, + CurrentStateAccountsWrapper: accDB, + HistoricalStateAccountsWrapper: accDB, + } + stateComponents.AccountsRepo, _ = state.NewAccountsRepository(args) + n, _ := node.NewNode( + node.WithCoreComponents(coreComponents), + node.WithDataComponents(dataComponents), + node.WithStateComponents(stateComponents), + ) + + recovAccnt, blockInfo, err := n.GetAccountWithKeys(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: true}, context.Background()) + + require.Equal(t, expectedErr, err) + require.Equal(t, api.AccountResponse{}, recovAccnt) + require.Equal(t, api.BlockInfo{}, blockInfo) +} + func TestNode_GetAccountAccountWithKeysShouldReturn(t *testing.T) { t.Parallel() @@ -3504,6 +3549,7 @@ func TestNode_GetAccountAccountWithKeysShouldReturn(t *testing.T) { ) recovAccnt, _, err := n.GetAccountWithKeys(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: false}, context.Background()) + require.Nil(t, err) require.Nil(t, recovAccnt.Pairs) From e4338c6574b0a120a002346c15f96c1ecd84d562 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Tue, 23 Apr 2024 11:55:40 +0300 Subject: [PATCH 062/467] - removed useless empty line --- node/chainSimulator/chainSimulator_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index e4092a16b9c..23bbb007f8b 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -376,7 +376,6 @@ func TestChainSimulator_SetEntireStateWithRemoval(t *testing.T) { require.Equal(t, accountState.CodeMetadata, base64.StdEncoding.EncodeToString(account.CodeMetadata)) require.Equal(t, accountState.Owner, account.OwnerAddress) require.Equal(t, accountState.RootHash, base64.StdEncoding.EncodeToString(account.RootHash)) - } func TestChainSimulator_GetAccount(t *testing.T) { From 5a774a56faf2d0cfc1c9f884834a9e4f9a34d7cf Mon Sep 17 00:00:00 2001 From: radu chis Date: Tue, 23 Apr 2024 13:16:01 +0300 Subject: [PATCH 063/467] fix after review --- facade/interface.go | 2 +- node/node.go | 116 +++++++++++++++++++++----------------------- node/node_test.go | 50 ++++++++----------- 3 files changed, 76 insertions(+), 92 deletions(-) diff --git a/facade/interface.go b/facade/interface.go index e3be7b76cb0..35f185874ed 100644 --- a/facade/interface.go +++ b/facade/interface.go @@ -77,7 +77,7 @@ type NodeHandler interface { GetAccount(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) // GetAccountWithKeys returns an accountResponse containing information - // about the account correlated with provided address and all keys + // about the account correlated with provided address and all keys GetAccountWithKeys(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) // GetCode returns the code for the given code hash diff --git a/node/node.go b/node/node.go index db2031a37ca..9cdf368c57e 100644 --- a/node/node.go +++ b/node/node.go @@ -62,6 +62,12 @@ type filter interface { filter(tokenIdentifier string, esdtData *systemSmartContracts.ESDTDataV2) bool } +type accountInfo struct { + account state.UserAccountHandler + block api.BlockInfo + accountResponse api.AccountResponse +} + // Node is a structure that holds all managed components type Node struct { initialNodesPubkeys map[uint32][]string @@ -939,87 +945,32 @@ func (n *Node) setTxGuardianData(guardian string, guardianSigHex string, tx *tra // GetAccount will return account details for a given address func (n *Node) GetAccount(address string, options api.AccountQueryOptions) (api.AccountResponse, api.BlockInfo, error) { - account, blockInfo, err := n.loadUserAccountHandlerByAddress(address, options) + accInfo, err := n.getAccountInfo(address, options) if err != nil { - adaptedBlockInfo, isEmptyAccount := extractBlockInfoIfNewAccount(err) - if isEmptyAccount { - return api.AccountResponse{ - Address: address, - Balance: "0", - DeveloperReward: "0", - }, adaptedBlockInfo, nil - } - return api.AccountResponse{}, api.BlockInfo{}, err } - ownerAddress := "" - if len(account.GetOwnerAddress()) > 0 { - addressPubkeyConverter := n.coreComponents.AddressPubKeyConverter() - ownerAddress, err = addressPubkeyConverter.Encode(account.GetOwnerAddress()) - if err != nil { - return api.AccountResponse{}, api.BlockInfo{}, err - } - } - - return api.AccountResponse{ - Address: address, - Nonce: account.GetNonce(), - Balance: account.GetBalance().String(), - Username: string(account.GetUserName()), - CodeHash: account.GetCodeHash(), - RootHash: account.GetRootHash(), - CodeMetadata: account.GetCodeMetadata(), - DeveloperReward: account.GetDeveloperReward().String(), - OwnerAddress: ownerAddress, - }, blockInfo, nil + return accInfo.accountResponse, accInfo.block, nil } // GetAccountWithKeys will return account details for a given address including the keys func (n *Node) GetAccountWithKeys(address string, options api.AccountQueryOptions, ctx context.Context) (api.AccountResponse, api.BlockInfo, error) { - account, blockInfo, err := n.loadUserAccountHandlerByAddress(address, options) + accInfo, err := n.getAccountInfo(address, options) if err != nil { - adaptedBlockInfo, isEmptyAccount := extractBlockInfoIfNewAccount(err) - if isEmptyAccount { - return api.AccountResponse{ - Address: address, - Balance: "0", - DeveloperReward: "0", - }, adaptedBlockInfo, nil - } - return api.AccountResponse{}, api.BlockInfo{}, err } - ownerAddress := "" - if len(account.GetOwnerAddress()) > 0 { - addressPubkeyConverter := n.coreComponents.AddressPubKeyConverter() - ownerAddress, err = addressPubkeyConverter.Encode(account.GetOwnerAddress()) - if err != nil { - return api.AccountResponse{}, api.BlockInfo{}, err - } - } - var keys map[string]string if options.WithKeys { - keys, err = n.getKeys(account, ctx) + keys, err = n.getKeys(accInfo.account, ctx) if err != nil { return api.AccountResponse{}, api.BlockInfo{}, err } } - return api.AccountResponse{ - Address: address, - Nonce: account.GetNonce(), - Balance: account.GetBalance().String(), - Username: string(account.GetUserName()), - CodeHash: account.GetCodeHash(), - RootHash: account.GetRootHash(), - CodeMetadata: account.GetCodeMetadata(), - DeveloperReward: account.GetDeveloperReward().String(), - OwnerAddress: ownerAddress, - Pairs: keys, - }, blockInfo, nil + accInfo.accountResponse.Pairs = keys + + return accInfo.accountResponse, accInfo.block, nil } func extractBlockInfoIfNewAccount(err error) (api.BlockInfo, bool) { @@ -1039,6 +990,47 @@ func extractBlockInfoIfNewAccount(err error) (api.BlockInfo, bool) { return api.BlockInfo{}, false } +func (n *Node) getAccountInfo(address string, options api.AccountQueryOptions) (accountInfo, error) { + account, blockInfo, err := n.loadUserAccountHandlerByAddress(address, options) + if err != nil { + adaptedBlockInfo, isEmptyAccount := extractBlockInfoIfNewAccount(err) + if isEmptyAccount { + return accountInfo{ + accountResponse: api.AccountResponse{ + Address: address, + Balance: "0", + DeveloperReward: "0", + }, + block: adaptedBlockInfo}, err + } + } + + ownerAddress := "" + if len(account.GetOwnerAddress()) > 0 { + addressPubkeyConverter := n.coreComponents.AddressPubKeyConverter() + ownerAddress, err = addressPubkeyConverter.Encode(account.GetOwnerAddress()) + if err != nil { + return accountInfo{ + accountResponse: api.AccountResponse{}, + block: api.BlockInfo{}, + }, err + } + } + + return accountInfo{ + accountResponse: api.AccountResponse{ + Address: address, + Nonce: account.GetNonce(), + Balance: account.GetBalance().String(), + Username: string(account.GetUserName()), + CodeHash: account.GetCodeHash(), + RootHash: account.GetRootHash(), + CodeMetadata: account.GetCodeMetadata(), + DeveloperReward: account.GetDeveloperReward().String(), + OwnerAddress: ownerAddress, + }, block: blockInfo}, nil +} + // GetCode returns the code for the given code hash func (n *Node) GetCode(codeHash []byte, options api.AccountQueryOptions) ([]byte, api.BlockInfo) { return n.loadAccountCode(codeHash, options) diff --git a/node/node_test.go b/node/node_test.go index 71eba9f5467..f1740ada505 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -3447,7 +3447,7 @@ func TestNode_GetAccountAccountExistsShouldReturn(t *testing.T) { require.Equal(t, testscommon.TestAddressAlice, recovAccnt.OwnerAddress) } -func TestNode_GetAccountAccountWithKeysErrorShouldErr(t *testing.T) { +func TestNode_GetAccountAccountWithKeysErrorShouldFail(t *testing.T) { accnt := createAcc(testscommon.TestPubKeyBob) _ = accnt.AddToBalance(big.NewInt(1)) expectedErr := errors.New("expected error") @@ -3470,20 +3470,7 @@ func TestNode_GetAccountAccountWithKeysErrorShouldErr(t *testing.T) { }, } - coreComponents := getDefaultCoreComponents() - dataComponents := getDefaultDataComponents() - stateComponents := getDefaultStateComponents() - args := state.ArgsAccountsRepository{ - FinalStateAccountsWrapper: accDB, - CurrentStateAccountsWrapper: accDB, - HistoricalStateAccountsWrapper: accDB, - } - stateComponents.AccountsRepo, _ = state.NewAccountsRepository(args) - n, _ := node.NewNode( - node.WithCoreComponents(coreComponents), - node.WithDataComponents(dataComponents), - node.WithStateComponents(stateComponents), - ) + n := getNodeWithAccount(accDB) recovAccnt, blockInfo, err := n.GetAccountWithKeys(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: true}, context.Background()) @@ -3492,7 +3479,7 @@ func TestNode_GetAccountAccountWithKeysErrorShouldErr(t *testing.T) { require.Equal(t, api.BlockInfo{}, blockInfo) } -func TestNode_GetAccountAccountWithKeysShouldReturn(t *testing.T) { +func TestNode_GetAccountAccountWithKeysShouldWork(t *testing.T) { t.Parallel() accnt := createAcc(testscommon.TestPubKeyBob) @@ -3533,6 +3520,23 @@ func TestNode_GetAccountAccountWithKeysShouldReturn(t *testing.T) { }, } + n := getNodeWithAccount(accDB) + + recovAccnt, _, err := n.GetAccountWithKeys(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: false}, context.Background()) + + require.Nil(t, err) + require.Nil(t, recovAccnt.Pairs) + + recovAccnt, _, err = n.GetAccountWithKeys(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: true}, context.Background()) + + require.Nil(t, err) + require.NotNil(t, recovAccnt.Pairs) + require.Equal(t, 2, len(recovAccnt.Pairs)) + require.Equal(t, hex.EncodeToString(v1), recovAccnt.Pairs[hex.EncodeToString(k1)]) + require.Equal(t, hex.EncodeToString(v2), recovAccnt.Pairs[hex.EncodeToString(k2)]) +} + +func getNodeWithAccount(accDB *stateMock.AccountsStub) *node.Node { coreComponents := getDefaultCoreComponents() dataComponents := getDefaultDataComponents() stateComponents := getDefaultStateComponents() @@ -3547,19 +3551,7 @@ func TestNode_GetAccountAccountWithKeysShouldReturn(t *testing.T) { node.WithDataComponents(dataComponents), node.WithStateComponents(stateComponents), ) - - recovAccnt, _, err := n.GetAccountWithKeys(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: false}, context.Background()) - - require.Nil(t, err) - require.Nil(t, recovAccnt.Pairs) - - recovAccnt, _, err = n.GetAccountWithKeys(testscommon.TestAddressBob, api.AccountQueryOptions{WithKeys: true}, context.Background()) - - require.Nil(t, err) - require.NotNil(t, recovAccnt.Pairs) - require.Equal(t, 2, len(recovAccnt.Pairs)) - require.Equal(t, hex.EncodeToString(v1), recovAccnt.Pairs[hex.EncodeToString(k1)]) - require.Equal(t, hex.EncodeToString(v2), recovAccnt.Pairs[hex.EncodeToString(k2)]) + return n } func TestNode_AppStatusHandlersShouldIncrement(t *testing.T) { From 3531379b72a2ac8e53fc39a39f03e1094d987fe4 Mon Sep 17 00:00:00 2001 From: radu chis Date: Tue, 23 Apr 2024 13:58:26 +0300 Subject: [PATCH 064/467] refactored and fixed test --- node/node.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/node/node.go b/node/node.go index 9cdf368c57e..992cba53768 100644 --- a/node/node.go +++ b/node/node.go @@ -1001,8 +1001,15 @@ func (n *Node) getAccountInfo(address string, options api.AccountQueryOptions) ( Balance: "0", DeveloperReward: "0", }, - block: adaptedBlockInfo}, err + block: adaptedBlockInfo, + account: account, + }, nil } + return accountInfo{ + accountResponse: api.AccountResponse{}, + block: api.BlockInfo{}, + account: nil, + }, err } ownerAddress := "" @@ -1013,6 +1020,7 @@ func (n *Node) getAccountInfo(address string, options api.AccountQueryOptions) ( return accountInfo{ accountResponse: api.AccountResponse{}, block: api.BlockInfo{}, + account: nil, }, err } } @@ -1028,7 +1036,10 @@ func (n *Node) getAccountInfo(address string, options api.AccountQueryOptions) ( CodeMetadata: account.GetCodeMetadata(), DeveloperReward: account.GetDeveloperReward().String(), OwnerAddress: ownerAddress, - }, block: blockInfo}, nil + }, + block: blockInfo, + account: account, + }, nil } // GetCode returns the code for the given code hash From 144a039becd418dbdfeba583adedd4c47b5a92a6 Mon Sep 17 00:00:00 2001 From: radu chis Date: Tue, 23 Apr 2024 14:39:03 +0300 Subject: [PATCH 065/467] downgraded to v0.21.0 --- go.mod | 2 +- go.sum | 15 +++++---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/go.mod b/go.mod index c7ef33c791d..c67839d751f 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( github.com/shirou/gopsutil v3.21.11+incompatible github.com/stretchr/testify v1.8.4 github.com/urfave/cli v1.22.10 - golang.org/x/crypto v0.22.0 + golang.org/x/crypto v0.21.0 gopkg.in/go-playground/validator.v8 v8.18.2 ) diff --git a/go.sum b/go.sum index 813d0a8327a..d1277df6ca3 100644 --- a/go.sum +++ b/go.sum @@ -129,7 +129,6 @@ github.com/gizak/termui/v3 v3.1.0 h1:ZZmVDgwHl7gR7elfKf1xc4IudXZ5qqfDh4wExk4Iajc github.com/gizak/termui/v3 v3.1.0/go.mod h1:bXQEBkJpzxUAKf0+xq9MSWAvWZlE7c+aidmyFlkYTrY= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= -github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -262,7 +261,6 @@ github.com/jbenet/goprocess v0.1.4/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZl github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= -github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= @@ -270,7 +268,6 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19/go.mod h1:hY+WOq6m2FpbvyrI93sMaypsttvaIL5nhVR92dTMUcQ= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= @@ -416,7 +413,6 @@ github.com/multiversx/mx-components-big-int v1.0.0 h1:Wkr8lSzK2nDqixOrrBa47VNuqd github.com/multiversx/mx-components-big-int v1.0.0/go.mod h1:maIEMgHlNE2u78JaDD0oLzri+ShgU4okHfzP3LWGdQM= github.com/multiversx/protobuf v1.3.2 h1:RaNkxvGTGbA0lMcnHAN24qE1G1i+Xs5yHA6MDvQ4mSM= github.com/multiversx/protobuf v1.3.2/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= -github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo= github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM= github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d h1:x3S6kxmy49zXVVyhcnrFqxvNVCBPb2KZ9hV2RBdS840= @@ -628,10 +624,9 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM= golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I= -golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= -golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= +golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= +golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug= golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc= @@ -674,8 +669,8 @@ golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU= golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ= +golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -730,8 +725,8 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -746,8 +741,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58= golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= From 7111b29e1445d5ea2f2fe155a9d62d4b0efdcbbc Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 24 Apr 2024 11:03:36 +0300 Subject: [PATCH 066/467] 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 067/467] 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 068/467] 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 069/467] 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 070/467] 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 071/467] 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 072/467] 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 073/467] 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 074/467] 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 075/467] 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 076/467] 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 077/467] delete log --- integrationTests/multiShard/smartContract/scCallingSC_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/integrationTests/multiShard/smartContract/scCallingSC_test.go b/integrationTests/multiShard/smartContract/scCallingSC_test.go index 73ed54fb791..aee8eacfe5a 100644 --- a/integrationTests/multiShard/smartContract/scCallingSC_test.go +++ b/integrationTests/multiShard/smartContract/scCallingSC_test.go @@ -775,7 +775,6 @@ func TestSCCallingInCrossShardDelegation(t *testing.T) { require.True(t, bytes.Contains(vmOutputVersion.ReturnData[0], []byte("0.3."))) log.Info("SC deployed", "version", string(vmOutputVersion.ReturnData[0])) - logger.SetLogLevel("process/smartcontract:TRACE") nonce, round = integrationTests.WaitOperationToBeDone(t, nodes, 1, nonce, round, idxProposers) // set stake per node From bef659207acf334baa45b9b3925f86b2c9bb8c0a Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Thu, 25 Apr 2024 09:28:55 +0300 Subject: [PATCH 078/467] - fixed the genesis flag --- genesis/process/shardGenesisBlockCreator.go | 1 + 1 file changed, 1 insertion(+) diff --git a/genesis/process/shardGenesisBlockCreator.go b/genesis/process/shardGenesisBlockCreator.go index 3c7e47070c7..b984e3aa86f 100644 --- a/genesis/process/shardGenesisBlockCreator.go +++ b/genesis/process/shardGenesisBlockCreator.go @@ -65,6 +65,7 @@ func createGenesisConfig(providedEnableEpochs config.EnableEpochs) config.Enable NodesToShufflePerShard: 0, }, } + clonedConfig.StakeEnableEpoch = unreachableEpoch // we need to specifically disable this, we have exceptions in the staking system SC clonedConfig.DoubleKeyProtectionEnableEpoch = 0 return clonedConfig From 7149419bb9017fdfbd10f7f684887b371ff90f8d Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 25 Apr 2024 11:13:17 +0300 Subject: [PATCH 079/467] 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 080/467] 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 081/467] 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 082/467] 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 083/467] fixing more and more tests --- integrationTests/vm/txsFee/dns_test.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/integrationTests/vm/txsFee/dns_test.go b/integrationTests/vm/txsFee/dns_test.go index f191a8ddcd3..0ff3914d7a0 100644 --- a/integrationTests/vm/txsFee/dns_test.go +++ b/integrationTests/vm/txsFee/dns_test.go @@ -62,7 +62,7 @@ func TestDeployDNSContract_TestRegisterAndResolveAndSendTxWithSndAndRcvUserName( require.Equal(t, big.NewInt(736770), accumulatedFees) developerFees := testContext.TxFeeHandler.GetDeveloperFees() - require.Equal(t, big.NewInt(73677), developerFees) + require.Equal(t, big.NewInt(73633), developerFees) utils.CleanAccumulatedIntermediateTransactions(t, testContext) @@ -77,13 +77,13 @@ func TestDeployDNSContract_TestRegisterAndResolveAndSendTxWithSndAndRcvUserName( _, err = testContext.Accounts.Commit() require.Nil(t, err) - vm.TestAccount(t, testContext.Accounts, rcvAddr, 1, big.NewInt(9721810)) + vm.TestAccount(t, testContext.Accounts, rcvAddr, 1, big.NewInt(9263230)) // check accumulated fees accumulatedFees = testContext.TxFeeHandler.GetAccumulatedFees() - require.Equal(t, big.NewInt(556380), accumulatedFees) + require.Equal(t, big.NewInt(1473540), accumulatedFees) developerFees = testContext.TxFeeHandler.GetDeveloperFees() - require.Equal(t, big.NewInt(55550), developerFees) + require.Equal(t, big.NewInt(147266), developerFees) ret := vm.GetVmOutput(nil, testContext.Accounts, scAddress, "resolve", userName) dnsUserNameAddr := ret.ReturnData[0] @@ -200,15 +200,11 @@ func TestDeployDNSContract_TestGasWhenSaveUsernameAfterDNSv2IsActivated(t *testi t.Skip("this is not a short test") } - testContextForDNSContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{ - DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, - }) + testContextForDNSContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, config.EnableEpochs{}) require.Nil(t, err) defer testContextForDNSContract.Close() - testContextForRelayerAndUser, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{ - DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch, - }) + testContextForRelayerAndUser, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(2, config.EnableEpochs{}) require.Nil(t, err) defer testContextForRelayerAndUser.Close() scAddress, _ := utils.DoDeployDNS(t, testContextForDNSContract, "../../multiShard/smartContract/dns/dns.wasm") @@ -274,7 +270,7 @@ func processRegisterThroughRelayedTxs(tb testing.TB, args argsProcessRegister) ( // generate the user transaction userTxData := []byte("register@" + hex.EncodeToString(args.username)) - userTxGasLimit := uint64(200000) + userTxGasLimit := uint64(2000000) userTx := vm.CreateTransaction( getNonce(args.testContextForRelayerAndUser, args.userAddress), big.NewInt(0), From 66e5d41623ac62825d0ce9858989c3e36472f266 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Thu, 25 Apr 2024 18:34:19 +0300 Subject: [PATCH 084/467] - fixed a chain simulator test --- node/chainSimulator/chainSimulator_test.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index 23bbb007f8b..8b32a8655e3 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -9,6 +9,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core" coreAPI "github.com/multiversx/mx-chain-core-go/data/api" "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" @@ -72,6 +73,12 @@ func TestChainSimulator_GenerateBlocksShouldWork(t *testing.T) { InitialRound: 200000000, InitialEpoch: 100, InitialNonce: 100, + AlterConfigsFunction: func(cfg *config.Configs) { + // we need to enable this as this test skips a lot of epoch activations events, and it will fail otherwise + // because the owner of a BLS key coming from genesis is not set + // (the owner is not set at genesis anymore because we do not enable the staking v2 in that phase) + cfg.EpochConfig.EnableEpochs.StakingV2EnableEpoch = 0 + }, }) require.Nil(t, err) require.NotNil(t, chainSimulator) From b7e2c6064fad3db946538e735709c02b8f733249 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Fri, 26 Apr 2024 17:09:33 +0300 Subject: [PATCH 085/467] 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 086/467] 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 087/467] 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 088/467] 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 089/467] 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 090/467] 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 091/467] 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 092/467] 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 093/467] 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 094/467] 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 095/467] 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 096/467] 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 097/467] updated dependencies after merges + fixes --- .../heartbeat/heartbeatV2Components_test.go | 31 ------------ go.mod | 24 +++++----- go.sum | 48 +++++++++---------- .../components/syncedMessenger.go | 5 -- .../components/syncedMessenger_test.go | 1 - node/node_test.go | 4 +- p2p/disabled/networkMessenger.go | 5 -- p2p/interface.go | 3 -- p2p/mock/peerTopicNotifierStub.go | 20 -------- testscommon/p2pmocks/messengerStub.go | 10 ---- 10 files changed, 38 insertions(+), 113 deletions(-) delete mode 100644 p2p/mock/peerTopicNotifierStub.go diff --git a/factory/heartbeat/heartbeatV2Components_test.go b/factory/heartbeat/heartbeatV2Components_test.go index 6b5088cab5b..9a0eb3b14e3 100644 --- a/factory/heartbeat/heartbeatV2Components_test.go +++ b/factory/heartbeat/heartbeatV2Components_test.go @@ -11,7 +11,6 @@ import ( errorsMx "github.com/multiversx/mx-chain-go/errors" heartbeatComp "github.com/multiversx/mx-chain-go/factory/heartbeat" testsMocks "github.com/multiversx/mx-chain-go/integrationTests/mock" - "github.com/multiversx/mx-chain-go/sharding" "github.com/multiversx/mx-chain-go/storage" "github.com/multiversx/mx-chain-go/testscommon" "github.com/multiversx/mx-chain-go/testscommon/bootstrapMocks" @@ -473,36 +472,6 @@ func TestHeartbeatV2Components_Create(t *testing.T) { assert.Nil(t, hc) assert.Error(t, err) }) - t.Run("NewCrossShardPeerTopicNotifier fails should error", func(t *testing.T) { - t.Parallel() - - args := createMockHeartbeatV2ComponentsFactoryArgs() - processComp := args.ProcessComponents - cnt := 0 - args.ProcessComponents = &testsMocks.ProcessComponentsStub{ - NodesCoord: processComp.NodesCoordinator(), - EpochTrigger: processComp.EpochStartTrigger(), - EpochNotifier: processComp.EpochStartNotifier(), - NodeRedundancyHandlerInternal: processComp.NodeRedundancyHandler(), - HardforkTriggerField: processComp.HardforkTrigger(), - MainPeerMapper: processComp.PeerShardMapper(), - FullArchivePeerMapper: processComp.FullArchivePeerShardMapper(), - ShardCoordinatorCalled: func() sharding.Coordinator { - cnt++ - if cnt > 3 { - return nil - } - return processComp.ShardCoordinator() - }, - } - hcf, err := heartbeatComp.NewHeartbeatV2ComponentsFactory(args) - assert.NotNil(t, hcf) - assert.NoError(t, err) - - hc, err := hcf.Create() - assert.Nil(t, hc) - assert.Error(t, err) - }) t.Run("should work", func(t *testing.T) { t.Parallel() diff --git a/go.mod b/go.mod index 3bdbf023722..e70e37f4219 100644 --- a/go.mod +++ b/go.mod @@ -14,18 +14,18 @@ require ( github.com/gorilla/websocket v1.5.0 github.com/klauspost/cpuid/v2 v2.2.5 github.com/mitchellh/mapstructure v1.5.0 - github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240321151517-2fffad77c605 - github.com/multiversx/mx-chain-core-go v1.2.20-0.20240328090024-e88291d59ace - github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 - github.com/multiversx/mx-chain-es-indexer-go v1.4.20-0.20240228094052-28a36809b9b8 - github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c - github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 - github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474 - github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240424111748-6dfa8aa14813 - github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240429094120-31dea4df3221 - github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240424112443-1a66307bc44e - github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240424112610-ab7b9e5829bd - github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240424113019-3a7d2b215137 + github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e + github.com/multiversx/mx-chain-core-go v1.2.21-0.20240508071047-fefea5737840 + github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df + github.com/multiversx/mx-chain-es-indexer-go v1.7.1-0.20240509104512-25512675833d + github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 + github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 + github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f + github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240509103544-247ce5639c7a + github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1 + github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b + github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240509104009-598a37ff36b9 + github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98-0.20240509104102-2a6a709b4041 github.com/pelletier/go-toml v1.9.3 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.14.0 diff --git a/go.sum b/go.sum index a06d6c94a56..185994c8e4f 100644 --- a/go.sum +++ b/go.sum @@ -385,30 +385,30 @@ github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/n github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUYwbO0993uPI= github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= -github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240321151517-2fffad77c605 h1:WYPdDmxL5rk9O6wUYVW4Fpw/QtwkWiIzFHeH2F5Zap4= -github.com/multiversx/mx-chain-communication-go v1.0.13-0.20240321151517-2fffad77c605/go.mod h1:wUM/1NFfgeTjovQMaaXghynwXgOyoPchMquu2wnCHz8= -github.com/multiversx/mx-chain-core-go v1.2.20-0.20240328090024-e88291d59ace h1:sCXg0IlWmi0k5mC3BmUVCKVrxatGRQKGmqVS/froLDw= -github.com/multiversx/mx-chain-core-go v1.2.20-0.20240328090024-e88291d59ace/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= -github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479 h1:beVIhs5ysylwNplQ/bZ0h5DoDlqKNWgpWE/NMHHNmAw= -github.com/multiversx/mx-chain-crypto-go v1.2.10-0.20231206065052-38843c1f1479/go.mod h1:Ap6p7QZFtwPlb++OvCG+85BfuZ+bLP/JtQp6EwjWJsI= -github.com/multiversx/mx-chain-es-indexer-go v1.4.20-0.20240228094052-28a36809b9b8 h1:z9ePQGALhPCs9Fv7cQsnsScbEq8KuOJ9xrJEEEOiHyI= -github.com/multiversx/mx-chain-es-indexer-go v1.4.20-0.20240228094052-28a36809b9b8/go.mod h1:3aSGRJNvfUuPQkZUGHWuF11rPPxphsKGuAuIB+eD3is= -github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c h1:QIUOn8FgNRa5cir4BCWHZi/Qcr6Gg0eGNhns4+jy6+k= -github.com/multiversx/mx-chain-logger-go v1.0.14-0.20240129144507-d00e967c890c/go.mod h1:fH/fR/GEBsDjPkBoZDVJMoYo2HhlA7++DP6QfITJ1N8= -github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157 h1:ydzN3f+Y7H0InXuxAcNUSyVc+omNYL8uYtLqVzqaaX4= -github.com/multiversx/mx-chain-scenario-go v1.4.3-0.20240212160120-cc32d1580157/go.mod h1:ndk45i9J9McuCJpTcgiaK4ocd0yhnBBCPrlFwO6GRcs= -github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474 h1:x65Su8ojHwA+NICp9DrSVGLDDcAlW04DafkqCHY1QPE= -github.com/multiversx/mx-chain-storage-go v1.0.15-0.20240321150623-3974ec1d6474/go.mod h1:hnc6H4D5Ge1haRAQ6QHTXhyh+CT2DRiNJ0U0HQYI3DY= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240424111748-6dfa8aa14813 h1:pjknvxvRG1fQ6Dc0ZjFkWBwDLfPn2DbtACIwTBwYIA8= -github.com/multiversx/mx-chain-vm-common-go v1.5.12-0.20240424111748-6dfa8aa14813/go.mod h1:G6daPJC6bFsvAw45RPMCRi2rP+8LjFxa8G+3alHuJow= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240429094120-31dea4df3221 h1:lTJ26YdhQoANfWSfAX/fyZj6rv0vHcLUyxtZbpQn3nk= -github.com/multiversx/mx-chain-vm-go v1.5.28-0.20240429094120-31dea4df3221/go.mod h1:DyMusfHXRXyVYQmH2umBTZD5gm6p136EJNC6YI2l+kU= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240424112443-1a66307bc44e h1:Yg5Bx9iuMBpe+MTbL+VTdINlQeqjqDFIAOE4A8sWamc= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.66-0.20240424112443-1a66307bc44e/go.mod h1:0hoqSWVXkNvg0iYWDpYQcLyCBwz0DPIrTVf3kAtXHwU= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240424112610-ab7b9e5829bd h1:uM2FFSLvdWT7V8xRCaP01roTINT3rfTXAaiWQ1yFhag= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.67-0.20240424112610-ab7b9e5829bd/go.mod h1:MgRH/vdAXmXQiRdmN/b7hTxmQfPVFbVDqAHKc6Z3064= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240424113019-3a7d2b215137 h1:JL0Nn39C6f9mWJ+16xaCbrWZcZ/+TkbBMKmPxf4IVKo= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.96-0.20240424113019-3a7d2b215137/go.mod h1:3i2JOOE0VYvZE4K9C0VLi8mM/bBrY0dyWu3f9aw8RZI= +github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e h1:Tsmwhu+UleE+l3buPuqXSKTqfu5FbPmzQ4MjMoUvCWA= +github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e/go.mod h1:2yXl18wUbuV3cRZr7VHxM1xo73kTaC1WUcu2kx8R034= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240508071047-fefea5737840 h1:2mCrTUmbbA+Xv4UifZY9xptrGjcJBcJ2wavSb4FwejU= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240508071047-fefea5737840/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df h1:clihfi78bMEOWk/qw6WA4uQbCM2e2NGliqswLAvw19k= +github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df/go.mod h1:gtJYB4rR21KBSqJlazn+2z6f9gFSqQP3KvAgL7Qgxw4= +github.com/multiversx/mx-chain-es-indexer-go v1.7.1-0.20240509104512-25512675833d h1:GD1D8V0bE6hDLjrduSsMwQwwf6PMq2Zww7FYMfJsuiw= +github.com/multiversx/mx-chain-es-indexer-go v1.7.1-0.20240509104512-25512675833d/go.mod h1:UDKRXmxsSyPeAcjLUfGeYkAtYp424PIYkL82kzFYobM= +github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 h1:g9t410dqjcb7UUptbVd/H6Ua12sEzWU4v7VplyNvRZ0= +github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57/go.mod h1:cY6CIXpndW5g5PTPn4WzPwka/UBEf+mgw+PSY5pHGAU= +github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 h1:hFEcbGBtXu8UyB9BMhmAIH2R8BtV/NOq/rsxespLCN8= +github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00/go.mod h1:pnIIfWopbDMQ1EW5Ddc6KDMqv8Qtx+hxbH9rorHpCyo= +github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f h1:yd/G8iPBGOEAwbaS8zndJpO6bQk7Tk72ZhmlqRasThI= +github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f/go.mod h1:E6nfj9EQzGxWDGM3Dn6eZWRC3qFy1G8IqOsYsBOcgWw= +github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240509103544-247ce5639c7a h1:7M+jXVlnl43zd2NuimL1KnAVAdpUr/QoHqG0TUKoyaM= +github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240509103544-247ce5639c7a/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo= +github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1 h1:5/h1i7Xd/JH9CiO3ZqvzAjdze+mAbar5sWkh2UqfLgI= +github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1/go.mod h1:N3Oa8QeeHlSip4nbESQpVSLgi/WxtgIwvqfXIZm6gDs= +github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b h1:puYO0lUyPGA5kZqsiDjGa+daDGQwj9xFs0S5urhZjU8= +github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b/go.mod h1:SY95hGdAIc8YCGb4uNSy1ux8V8qQbF1ReZJDwQ6AqEo= +github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240509104009-598a37ff36b9 h1:rrkgAS58jRXc6LThPHY5fm3AnFoUa0VUiYkH5czdlYg= +github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240509104009-598a37ff36b9/go.mod h1:TiOTsz2kxHadU0It7okOwcynyNPePXzjyl7lnpGLlUQ= +github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98-0.20240509104102-2a6a709b4041 h1:k0xkmCrJiQzsWk4ZM3oNQ31lheiDvd1qQnNwnyuZzXU= +github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98-0.20240509104102-2a6a709b4041/go.mod h1:XeZNaDMV0hbDlm3JtW0Hj3mCWKaB/XecQlCzEjiK5L8= github.com/multiversx/mx-components-big-int v1.0.0 h1:Wkr8lSzK2nDqixOrrBa47VNuqdhV1m/aJhaP1EMaiS8= github.com/multiversx/mx-components-big-int v1.0.0/go.mod h1:maIEMgHlNE2u78JaDD0oLzri+ShgU4okHfzP3LWGdQM= github.com/multiversx/protobuf v1.3.2 h1:RaNkxvGTGbA0lMcnHAN24qE1G1i+Xs5yHA6MDvQ4mSM= diff --git a/node/chainSimulator/components/syncedMessenger.go b/node/chainSimulator/components/syncedMessenger.go index d30ac85b409..cc437d02038 100644 --- a/node/chainSimulator/components/syncedMessenger.go +++ b/node/chainSimulator/components/syncedMessenger.go @@ -364,11 +364,6 @@ func (messenger *syncedMessenger) SignUsingPrivateKey(_ []byte, _ []byte) ([]byt return make([]byte, 0), nil } -// AddPeerTopicNotifier does nothing and returns nil -func (messenger *syncedMessenger) AddPeerTopicNotifier(_ p2p.PeerTopicNotifier) error { - return nil -} - // SetDebugger will set the provided debugger func (messenger *syncedMessenger) SetDebugger(_ p2p.Debugger) error { return nil diff --git a/node/chainSimulator/components/syncedMessenger_test.go b/node/chainSimulator/components/syncedMessenger_test.go index c0efd6f2942..c8c17918141 100644 --- a/node/chainSimulator/components/syncedMessenger_test.go +++ b/node/chainSimulator/components/syncedMessenger_test.go @@ -50,7 +50,6 @@ func TestSyncedMessenger_DisabledMethodsShouldNotPanic(t *testing.T) { messenger, _ := NewSyncedMessenger(NewSyncedBroadcastNetwork()) assert.Nil(t, messenger.Close()) - assert.Nil(t, messenger.AddPeerTopicNotifier(nil)) assert.Zero(t, messenger.Port()) assert.Nil(t, messenger.SetPeerDenialEvaluator(nil)) assert.Nil(t, messenger.SetThresholdMinConnectedPeers(0)) diff --git a/node/node_test.go b/node/node_test.go index 21c050974b1..d2c19011830 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -3465,7 +3465,7 @@ func TestNode_GetAccountAccountWithKeysErrorShouldFail(t *testing.T) { GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { return accnt, nil, nil }, - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(options common.RootHashHolder) error { return nil }, } @@ -3515,7 +3515,7 @@ func TestNode_GetAccountAccountWithKeysShouldWork(t *testing.T) { GetAccountWithBlockInfoCalled: func(address []byte, options common.RootHashHolder) (vmcommon.AccountHandler, common.BlockInfo, error) { return accnt, nil, nil }, - RecreateTrieCalled: func(rootHash []byte) error { + RecreateTrieCalled: func(options common.RootHashHolder) error { return nil }, } diff --git a/p2p/disabled/networkMessenger.go b/p2p/disabled/networkMessenger.go index 1eb767d26c8..4f854d976bc 100644 --- a/p2p/disabled/networkMessenger.go +++ b/p2p/disabled/networkMessenger.go @@ -175,11 +175,6 @@ func (netMes *networkMessenger) SignUsingPrivateKey(_ []byte, _ []byte) ([]byte, return make([]byte, 0), nil } -// AddPeerTopicNotifier returns nil as it is disabled -func (netMes *networkMessenger) AddPeerTopicNotifier(_ p2p.PeerTopicNotifier) error { - return nil -} - // ProcessReceivedMessage returns nil as it is disabled func (netMes *networkMessenger) ProcessReceivedMessage(_ p2p.MessageP2P, _ core.PeerID, _ p2p.MessageHandler) error { return nil diff --git a/p2p/interface.go b/p2p/interface.go index dbdabc4248c..e2f7130c6ae 100644 --- a/p2p/interface.go +++ b/p2p/interface.go @@ -102,9 +102,6 @@ type PeersRatingHandler interface { // PeersRatingMonitor represents an entity able to provide peers ratings type PeersRatingMonitor = p2p.PeersRatingMonitor -// PeerTopicNotifier represents an entity able to handle new notifications on a new peer on a topic -type PeerTopicNotifier = p2p.PeerTopicNotifier - // P2PSigningHandler defines the behaviour of a component able to verify p2p message signature type P2PSigningHandler interface { Verify(message MessageP2P) error diff --git a/p2p/mock/peerTopicNotifierStub.go b/p2p/mock/peerTopicNotifierStub.go deleted file mode 100644 index bc1446ae819..00000000000 --- a/p2p/mock/peerTopicNotifierStub.go +++ /dev/null @@ -1,20 +0,0 @@ -package mock - -import "github.com/multiversx/mx-chain-core-go/core" - -// PeerTopicNotifierStub - -type PeerTopicNotifierStub struct { - NewPeerFoundCalled func(pid core.PeerID, topic string) -} - -// NewPeerFound - -func (stub *PeerTopicNotifierStub) NewPeerFound(pid core.PeerID, topic string) { - if stub.NewPeerFoundCalled != nil { - stub.NewPeerFoundCalled(pid, topic) - } -} - -// IsInterfaceNil - -func (stub *PeerTopicNotifierStub) IsInterfaceNil() bool { - return stub == nil -} diff --git a/testscommon/p2pmocks/messengerStub.go b/testscommon/p2pmocks/messengerStub.go index 77d058c71a1..c48c95b9868 100644 --- a/testscommon/p2pmocks/messengerStub.go +++ b/testscommon/p2pmocks/messengerStub.go @@ -40,7 +40,6 @@ type MessengerStub struct { WaitForConnectionsCalled func(maxWaitingTime time.Duration, minNumOfPeers uint32) SignCalled func(payload []byte) ([]byte, error) VerifyCalled func(payload []byte, pid core.PeerID, signature []byte) error - AddPeerTopicNotifierCalled func(notifier p2p.PeerTopicNotifier) error BroadcastUsingPrivateKeyCalled func(topic string, buff []byte, pid core.PeerID, skBytes []byte) BroadcastOnChannelUsingPrivateKeyCalled func(channel string, topic string, buff []byte, pid core.PeerID, skBytes []byte) SignUsingPrivateKeyCalled func(skBytes []byte, payload []byte) ([]byte, error) @@ -322,15 +321,6 @@ func (ms *MessengerStub) Verify(payload []byte, pid core.PeerID, signature []byt return nil } -// AddPeerTopicNotifier - -func (ms *MessengerStub) AddPeerTopicNotifier(notifier p2p.PeerTopicNotifier) error { - if ms.AddPeerTopicNotifierCalled != nil { - return ms.AddPeerTopicNotifierCalled(notifier) - } - - return nil -} - // BroadcastUsingPrivateKey - func (ms *MessengerStub) BroadcastUsingPrivateKey(topic string, buff []byte, pid core.PeerID, skBytes []byte) { if ms.BroadcastUsingPrivateKeyCalled != nil { From 0ac91d02eeaa6df28b5d7d790b184cf0b81a9701 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 13 May 2024 11:21:11 +0300 Subject: [PATCH 098/467] - aligned mainnet configs with mx-chain-go --- cmd/node/config/systemSmartContractsConfig.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/node/config/systemSmartContractsConfig.toml b/cmd/node/config/systemSmartContractsConfig.toml index 372cd0eba03..2ffc4da94c0 100644 --- a/cmd/node/config/systemSmartContractsConfig.toml +++ b/cmd/node/config/systemSmartContractsConfig.toml @@ -10,7 +10,7 @@ BleedPercentagePerRound = 0.00001 MaxNumberOfNodesForStake = 64 UnJailValue = "2500000000000000000" #0.1% of genesis node price - ActivateBLSPubKeyMessageVerification = false + ActivateBLSPubKeyMessageVerification = true StakeLimitPercentage = 1.0 #fraction of value 1 - 100%, for the time being no stake limit NodeLimitPercentage = 0.1 #fraction of value 0.1 - 10% @@ -35,7 +35,7 @@ [DelegationManagerSystemSCConfig] MinCreationDeposit = "1250000000000000000000" #1.25K eGLD - MinStakeAmount = "10000000000000000000" #10 eGLD + MinStakeAmount = "1000000000000000000" #1 eGLD ConfigChangeAddress = "erd1vxy22x0fj4zv6hktmydg8vpfh6euv02cz4yg0aaws6rrad5a5awqgqky80" #should use a multisign contract instead of a wallet address [DelegationSystemSCConfig] From c267fd1a5ff330e77789f61b778dd74c9578b334 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 13 May 2024 11:30:52 +0300 Subject: [PATCH 099/467] - compressed configs --- cmd/node/config/enableEpochs.toml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index 482b30b0329..d24e57df7e7 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -285,25 +285,25 @@ FixGasRemainingForSaveKeyValueBuiltinFunctionEnableEpoch = 1 # CurrentRandomnessOnSortingEnableEpoch represents the epoch when the current randomness on sorting is enabled - CurrentRandomnessOnSortingEnableEpoch = 4 + CurrentRandomnessOnSortingEnableEpoch = 1 # StakeLimitsEnableEpoch represents the epoch when stake limits on validators are enabled # Should have the same value as StakingV4Step1EnableEpoch that triggers the automatic unstake operations for the queue nodes - StakeLimitsEnableEpoch = 4 + StakeLimitsEnableEpoch = 1 # StakingV4Step1EnableEpoch represents the epoch when staking v4 is initialized. This is the epoch in which # all nodes from staking queue are moved in the auction list - StakingV4Step1EnableEpoch = 4 + StakingV4Step1EnableEpoch = 1 # StakingV4Step2EnableEpoch represents the epoch when staking v4 is enabled. Should have a greater value than StakingV4Step1EnableEpoch. # From this epoch, all shuffled out nodes are moved to auction nodes. No auction nodes selection is done yet. - StakingV4Step2EnableEpoch = 5 + StakingV4Step2EnableEpoch = 2 # StakingV4Step3EnableEpoch represents the epoch in which selected nodes from auction will be distributed to waiting list - StakingV4Step3EnableEpoch = 6 + StakingV4Step3EnableEpoch = 3 # AlwaysMergeContextsInEEIEnableEpoch represents the epoch in which the EEI will always merge the contexts - AlwaysMergeContextsInEEIEnableEpoch = 4 + AlwaysMergeContextsInEEIEnableEpoch = 1 # BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers BLSMultiSignerEnableEpoch = [ @@ -319,7 +319,7 @@ # - Enable epoch = StakingV4Step3EnableEpoch # - NodesToShufflePerShard = same as previous entry in MaxNodesChangeEnableEpoch # - MaxNumNodes = (MaxNumNodesFromPreviousEpochEnable - (numOfShards+1)*NodesToShufflePerShard) - { EpochEnable = 6, MaxNumNodes = 56, NodesToShufflePerShard = 2 }, + { EpochEnable = 3, MaxNumNodes = 56, NodesToShufflePerShard = 2 }, ] [GasSchedule] From 018804eac62b259aef7a9bc010a5c30b40483002 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Mon, 13 May 2024 11:51:33 +0300 Subject: [PATCH 100/467] 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 101/467] 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 102/467] 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 103/467] 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 104/467] 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 105/467] 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 106/467] Adjust workflow runners (MacOS). --- .github/workflows/build_and_test.yml | 2 +- .github/workflows/create_release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 19fdaec07e0..b43adf3ef0e 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -9,7 +9,7 @@ jobs: build: strategy: matrix: - runs-on: [ubuntu-latest, macos-latest, macos-13-xlarge] + runs-on: [ubuntu-latest, macos-13-xlarge] runs-on: ${{ matrix.runs-on }} name: Build steps: diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index ca13a9f0313..81fd087a704 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -15,7 +15,7 @@ jobs: build: strategy: matrix: - runs-on: [ubuntu-latest, macos-latest, macos-13-xlarge] + runs-on: [ubuntu-latest, macos-13-xlarge] runs-on: ${{ matrix.runs-on }} name: Build steps: From 126424119bca114aedd2f25d4b994fe62180dc78 Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Tue, 14 May 2024 18:53:14 +0300 Subject: [PATCH 107/467] highlight nodes shuffled out to auction list --- .../disabled/disabledNodesCoordinator.go | 5 + process/peer/process.go | 5 +- process/peer/process_test.go | 14 +- sharding/nodesCoordinator/dtos.go | 1 + .../nodesCoordinator/hashValidatorShuffler.go | 2 + .../indexHashedNodesCoordinator.go | 25 +++- ...shedNodesCoordinatorRegistryWithAuction.go | 9 +- sharding/nodesCoordinator/interface.go | 8 +- .../nodesCoordinatorRegistryWithAuction.pb.go | 131 ++++++++++++------ .../nodesCoordinatorRegistryWithAuction.proto | 15 +- .../shardingMocks/nodesCoordinatorMock.go | 45 +++--- .../shardingMocks/nodesCoordinatorStub.go | 6 + 12 files changed, 187 insertions(+), 79 deletions(-) diff --git a/epochStart/bootstrap/disabled/disabledNodesCoordinator.go b/epochStart/bootstrap/disabled/disabledNodesCoordinator.go index efee420feec..f7c1502d0c4 100644 --- a/epochStart/bootstrap/disabled/disabledNodesCoordinator.go +++ b/epochStart/bootstrap/disabled/disabledNodesCoordinator.go @@ -54,6 +54,11 @@ func (n *nodesCoordinator) GetAllShuffledOutValidatorsPublicKeys(_ uint32) (map[ return nil, nil } +// GetShuffledOutToAuctionValidatorsPublicKeys - +func (n *nodesCoordinator) GetShuffledOutToAuctionValidatorsPublicKeys(_ uint32) (map[uint32][][]byte, error) { + return nil, nil +} + // GetConsensusValidatorsPublicKeys - func (n *nodesCoordinator) GetConsensusValidatorsPublicKeys(_ []byte, _ uint64, _ uint32, _ uint32) ([]string, error) { return nil, nil diff --git a/process/peer/process.go b/process/peer/process.go index 4c04de6a25d..579d4a16930 100644 --- a/process/peer/process.go +++ b/process/peer/process.go @@ -13,6 +13,8 @@ import ( "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/block" "github.com/multiversx/mx-chain-core-go/marshal" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/errChan" "github.com/multiversx/mx-chain-go/common/validatorInfo" @@ -23,7 +25,6 @@ import ( "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/state/accounts" "github.com/multiversx/mx-chain-go/state/parsers" - logger "github.com/multiversx/mx-chain-logger-go" ) var log = logger.GetOrCreate("process/peer") @@ -197,7 +198,7 @@ func (vs *validatorStatistics) saveNodesCoordinatorUpdates(epoch uint32) (bool, nodeForcedToRemain = nodeForcedToRemain || tmpNodeForcedToRemain if vs.enableEpochsHandler.IsFlagEnabled(common.StakingV4Step2Flag) { - nodesMap, err = vs.nodesCoordinator.GetAllShuffledOutValidatorsPublicKeys(epoch) + nodesMap, err = vs.nodesCoordinator.GetShuffledOutToAuctionValidatorsPublicKeys(epoch) if err != nil { return false, err } diff --git a/process/peer/process_test.go b/process/peer/process_test.go index 69adb3e936a..d4c85a5601f 100644 --- a/process/peer/process_test.go +++ b/process/peer/process_test.go @@ -14,6 +14,10 @@ import ( "github.com/multiversx/mx-chain-core-go/core/keyValStorage" "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-core-go/data/block" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/dataRetriever" @@ -33,9 +37,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/shardingMocks" stateMock "github.com/multiversx/mx-chain-go/testscommon/state" storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) const ( @@ -2719,6 +2720,13 @@ func TestValidatorStatisticsProcessor_SaveNodesCoordinatorUpdatesWithStakingV4(t } return mapNodes, nil }, + GetShuffledOutToAuctionValidatorsPublicKeysCalled: func(epoch uint32) (map[uint32][][]byte, error) { + mapNodes := map[uint32][][]byte{ + 0: {pk1}, + core.MetachainShardId: {pk2}, + } + return mapNodes, nil + }, } stakingV4Step2EnableEpochCalledCt := 0 arguments.EnableEpochsHandler = &enableEpochsHandlerMock.EnableEpochsHandlerStub{ diff --git a/sharding/nodesCoordinator/dtos.go b/sharding/nodesCoordinator/dtos.go index ab54bdeb4fa..75c28194a6a 100644 --- a/sharding/nodesCoordinator/dtos.go +++ b/sharding/nodesCoordinator/dtos.go @@ -20,4 +20,5 @@ type ResUpdateNodes struct { ShuffledOut map[uint32][]Validator Leaving []Validator StillRemaining []Validator + LowWaitingList bool } diff --git a/sharding/nodesCoordinator/hashValidatorShuffler.go b/sharding/nodesCoordinator/hashValidatorShuffler.go index ceecc9ca352..7c54e132ffc 100644 --- a/sharding/nodesCoordinator/hashValidatorShuffler.go +++ b/sharding/nodesCoordinator/hashValidatorShuffler.go @@ -10,6 +10,7 @@ import ( "github.com/multiversx/mx-chain-core-go/core/atomic" "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/hashing/sha256" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/epochStart" @@ -350,6 +351,7 @@ func shuffleNodes(arg shuffleNodesArg) (*ResUpdateNodes, error) { ShuffledOut: shuffledOutMap, Leaving: actualLeaving, StillRemaining: stillRemainingInLeaving, + LowWaitingList: lowWaitingList, }, nil } diff --git a/sharding/nodesCoordinator/indexHashedNodesCoordinator.go b/sharding/nodesCoordinator/indexHashedNodesCoordinator.go index f70bce06b04..4deb3f01bcd 100644 --- a/sharding/nodesCoordinator/indexHashedNodesCoordinator.go +++ b/sharding/nodesCoordinator/indexHashedNodesCoordinator.go @@ -15,11 +15,12 @@ import ( "github.com/multiversx/mx-chain-core-go/data/endProcess" "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/marshal" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/epochStart" "github.com/multiversx/mx-chain-go/state" "github.com/multiversx/mx-chain-go/storage" - logger "github.com/multiversx/mx-chain-logger-go" ) var _ NodesCoordinator = (*indexHashedNodesCoordinator)(nil) @@ -68,6 +69,7 @@ type epochNodesConfig struct { newList []Validator auctionList []Validator mutNodesMaps sync.RWMutex + lowWaitingList bool } type indexHashedNodesCoordinator struct { @@ -122,6 +124,7 @@ func NewIndexHashedNodesCoordinator(arguments ArgNodesCoordinator) (*indexHashed shuffledOutMap: make(map[uint32][]Validator), newList: make([]Validator, 0), auctionList: make([]Validator, 0), + lowWaitingList: false, } // todo: if not genesis, use previous randomness from start of epoch meta block @@ -546,6 +549,26 @@ func (ihnc *indexHashedNodesCoordinator) GetAllShuffledOutValidatorsPublicKeys(e return validatorsPubKeys, nil } +// GetShuffledOutToAuctionValidatorsPublicKeys will return shuffled out to auction validators public keys +func (ihnc *indexHashedNodesCoordinator) GetShuffledOutToAuctionValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error) { + validatorsPubKeys := make(map[uint32][][]byte) + + ihnc.mutNodesConfig.RLock() + nodesConfig, ok := ihnc.nodesConfig[epoch] + ihnc.mutNodesConfig.RUnlock() + + if !ok { + return nil, fmt.Errorf("%w epoch=%v", ErrEpochNodesConfigDoesNotExist, epoch) + } + + if nodesConfig.lowWaitingList { + // in case of low waiting list the nodes do not go through auction but directly to waiting + return validatorsPubKeys, nil + } + + return ihnc.GetAllShuffledOutValidatorsPublicKeys(epoch) +} + // GetValidatorsIndexes will return validators indexes for a block func (ihnc *indexHashedNodesCoordinator) GetValidatorsIndexes( publicKeys []string, diff --git a/sharding/nodesCoordinator/indexHashedNodesCoordinatorRegistryWithAuction.go b/sharding/nodesCoordinator/indexHashedNodesCoordinatorRegistryWithAuction.go index 261aa60aefc..76deba81eaa 100644 --- a/sharding/nodesCoordinator/indexHashedNodesCoordinatorRegistryWithAuction.go +++ b/sharding/nodesCoordinator/indexHashedNodesCoordinatorRegistryWithAuction.go @@ -29,10 +29,11 @@ func (ihnc *indexHashedNodesCoordinator) nodesCoordinatorToRegistryWithAuction() func epochNodesConfigToEpochValidatorsWithAuction(config *epochNodesConfig) *EpochValidatorsWithAuction { result := &EpochValidatorsWithAuction{ - Eligible: make(map[string]Validators, len(config.eligibleMap)), - Waiting: make(map[string]Validators, len(config.waitingMap)), - Leaving: make(map[string]Validators, len(config.leavingMap)), - ShuffledOut: make(map[string]Validators, len(config.shuffledOutMap)), + Eligible: make(map[string]Validators, len(config.eligibleMap)), + Waiting: make(map[string]Validators, len(config.waitingMap)), + Leaving: make(map[string]Validators, len(config.leavingMap)), + ShuffledOut: make(map[string]Validators, len(config.shuffledOutMap)), + LowWaitingList: config.lowWaitingList, } for k, v := range config.eligibleMap { diff --git a/sharding/nodesCoordinator/interface.go b/sharding/nodesCoordinator/interface.go index 68dfa9bbb15..b962c6fa50a 100644 --- a/sharding/nodesCoordinator/interface.go +++ b/sharding/nodesCoordinator/interface.go @@ -3,9 +3,10 @@ package nodesCoordinator import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-go/epochStart" "github.com/multiversx/mx-chain-go/state" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) // Validator defines a node that can be allocated to a shard for participation in a consensus group as validator @@ -48,6 +49,7 @@ type PublicKeysSelector interface { GetAllWaitingValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error) GetAllLeavingValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error) GetAllShuffledOutValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error) + GetShuffledOutToAuctionValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error) GetConsensusValidatorsPublicKeys(randomness []byte, round uint64, shardId uint32, epoch uint32) ([]string, error) GetOwnPublicKey() []byte } @@ -68,9 +70,9 @@ type NodesCoordinatorHelper interface { // ChanceComputer provides chance computation capabilities based on a rating type ChanceComputer interface { - //GetChance returns the chances for the rating + // GetChance returns the chances for the rating GetChance(uint32) uint32 - //IsInterfaceNil verifies if the interface is nil + // IsInterfaceNil verifies if the interface is nil IsInterfaceNil() bool } diff --git a/sharding/nodesCoordinator/nodesCoordinatorRegistryWithAuction.pb.go b/sharding/nodesCoordinator/nodesCoordinatorRegistryWithAuction.pb.go index 3c69dc78080..3fa0434075a 100644 --- a/sharding/nodesCoordinator/nodesCoordinatorRegistryWithAuction.pb.go +++ b/sharding/nodesCoordinator/nodesCoordinatorRegistryWithAuction.pb.go @@ -122,10 +122,11 @@ func (m *Validators) GetData() []*SerializableValidator { } type EpochValidatorsWithAuction struct { - Eligible map[string]Validators `protobuf:"bytes,1,rep,name=Eligible,proto3" json:"Eligible" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - Waiting map[string]Validators `protobuf:"bytes,2,rep,name=Waiting,proto3" json:"Waiting" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - Leaving map[string]Validators `protobuf:"bytes,3,rep,name=Leaving,proto3" json:"Leaving" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` - ShuffledOut map[string]Validators `protobuf:"bytes,4,rep,name=ShuffledOut,proto3" json:"ShuffledOut" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Eligible map[string]Validators `protobuf:"bytes,1,rep,name=Eligible,proto3" json:"Eligible" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Waiting map[string]Validators `protobuf:"bytes,2,rep,name=Waiting,proto3" json:"Waiting" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Leaving map[string]Validators `protobuf:"bytes,3,rep,name=Leaving,proto3" json:"Leaving" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + ShuffledOut map[string]Validators `protobuf:"bytes,4,rep,name=ShuffledOut,proto3" json:"ShuffledOut" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + LowWaitingList bool `protobuf:"varint,5,opt,name=LowWaitingList,proto3" json:"LowWaitingList,omitempty"` } func (m *EpochValidatorsWithAuction) Reset() { *m = EpochValidatorsWithAuction{} } @@ -184,6 +185,13 @@ func (m *EpochValidatorsWithAuction) GetShuffledOut() map[string]Validators { return nil } +func (m *EpochValidatorsWithAuction) GetLowWaitingList() bool { + if m != nil { + return m.LowWaitingList + } + return false +} + type NodesCoordinatorRegistryWithAuction struct { CurrentEpoch uint32 `protobuf:"varint,1,opt,name=CurrentEpoch,proto3" json:"CurrentEpoch,omitempty"` EpochsConfigWithAuction map[string]*EpochValidatorsWithAuction `protobuf:"bytes,2,rep,name=EpochsConfigWithAuction,proto3" json:"EpochsConfigWithAuction,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` @@ -248,43 +256,44 @@ func init() { } var fileDescriptor_f04461c784f438d5 = []byte{ - // 561 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x94, 0x4f, 0x8f, 0xd2, 0x40, - 0x18, 0xc6, 0x3b, 0xb0, 0x80, 0xfb, 0x02, 0x09, 0x4e, 0x62, 0x6c, 0xc8, 0x66, 0xc0, 0x1a, 0x23, - 0x1e, 0x2c, 0x06, 0x0f, 0x1a, 0x0f, 0x26, 0x82, 0xc4, 0xf8, 0x0f, 0xdd, 0x6e, 0xe2, 0x26, 0x7b, - 0x6b, 0x61, 0x28, 0x13, 0xbb, 0x1d, 0x52, 0xa6, 0x1b, 0xf1, 0xa4, 0xf1, 0x0b, 0xf8, 0x31, 0x3c, - 0xf8, 0x11, 0xfc, 0x00, 0x7b, 0xe4, 0xc8, 0x89, 0x48, 0xb9, 0x18, 0x4e, 0xfb, 0x11, 0x0c, 0xd3, - 0xb2, 0x5b, 0x36, 0x8b, 0x6c, 0xb2, 0x9e, 0x98, 0x3e, 0x33, 0xcf, 0xef, 0x19, 0x1e, 0x5e, 0x0a, - 0xf7, 0x5c, 0xde, 0xa1, 0x83, 0x06, 0xe7, 0x5e, 0x87, 0xb9, 0xa6, 0xe0, 0x9e, 0x41, 0x6d, 0x36, - 0x10, 0xde, 0x70, 0x9f, 0x89, 0xde, 0x33, 0xbf, 0x2d, 0x18, 0x77, 0xf5, 0xbe, 0xc7, 0x05, 0xc7, - 0x29, 0xf9, 0x51, 0xbc, 0x6f, 0x33, 0xd1, 0xf3, 0x2d, 0xbd, 0xcd, 0x0f, 0xab, 0x36, 0xb7, 0x79, - 0x55, 0xca, 0x96, 0xdf, 0x95, 0x4f, 0xf2, 0x41, 0xae, 0x42, 0x97, 0xf6, 0x0d, 0xc1, 0x8d, 0x3d, - 0xea, 0x31, 0xd3, 0x61, 0x9f, 0x4d, 0xcb, 0xa1, 0x1f, 0x4c, 0x87, 0x75, 0x16, 0x41, 0x58, 0x83, - 0xf4, 0x7b, 0xdf, 0x7a, 0x4d, 0x87, 0x2a, 0x2a, 0xa3, 0x4a, 0xae, 0x0e, 0xf3, 0x49, 0x29, 0xdd, - 0x97, 0x8a, 0x11, 0xed, 0xe0, 0x3b, 0x90, 0x69, 0xf4, 0x4c, 0xb7, 0x4d, 0x07, 0x6a, 0xa2, 0x8c, - 0x2a, 0xf9, 0x7a, 0x76, 0x3e, 0x29, 0x65, 0xda, 0xa1, 0x64, 0x2c, 0xf7, 0x70, 0x09, 0x52, 0x2f, - 0xdd, 0x0e, 0xfd, 0xa4, 0x26, 0xe5, 0xa1, 0xed, 0xf9, 0xa4, 0x94, 0x62, 0x0b, 0xc1, 0x08, 0x75, - 0xed, 0x29, 0xc0, 0x69, 0xf0, 0x00, 0x3f, 0x80, 0xad, 0xe7, 0xa6, 0x30, 0x55, 0x54, 0x4e, 0x56, - 0xb2, 0xb5, 0x9d, 0xf0, 0xa6, 0xfa, 0x85, 0xb7, 0x34, 0xe4, 0x49, 0xed, 0x67, 0x0a, 0x8a, 0xcd, - 0x3e, 0x6f, 0xf7, 0xce, 0x28, 0xb1, 0x82, 0xf0, 0x2e, 0x5c, 0x6b, 0x3a, 0xcc, 0x66, 0x96, 0x43, - 0x23, 0x68, 0x35, 0x82, 0xae, 0x37, 0xe9, 0x4b, 0x47, 0xd3, 0x15, 0xde, 0xb0, 0xbe, 0x75, 0x3c, - 0x29, 0x29, 0xc6, 0x29, 0x06, 0xb7, 0x20, 0xb3, 0x6f, 0x32, 0xc1, 0x5c, 0x5b, 0x4d, 0x48, 0xa2, - 0xbe, 0x99, 0x18, 0x19, 0xe2, 0xc0, 0x25, 0x64, 0xc1, 0x7b, 0x43, 0xcd, 0xa3, 0x05, 0x2f, 0x79, - 0x59, 0x5e, 0x64, 0x58, 0xe1, 0x45, 0x1a, 0x3e, 0x80, 0xec, 0x5e, 0xcf, 0xef, 0x76, 0x1d, 0xda, - 0x79, 0xe7, 0x0b, 0x75, 0x4b, 0x32, 0x6b, 0x9b, 0x99, 0x31, 0x53, 0x9c, 0x1b, 0x87, 0x15, 0x5b, - 0x90, 0x5f, 0x29, 0x07, 0x17, 0x20, 0xf9, 0x31, 0x9a, 0x93, 0x6d, 0x63, 0xb1, 0xc4, 0x77, 0x21, - 0x75, 0x64, 0x3a, 0x3e, 0x95, 0x63, 0x91, 0xad, 0x5d, 0x8f, 0x82, 0xcf, 0x32, 0x8d, 0x70, 0xff, - 0x49, 0xe2, 0x31, 0x2a, 0xbe, 0x85, 0x5c, 0xbc, 0x9a, 0xff, 0x80, 0x8b, 0x37, 0x73, 0x55, 0xdc, - 0x2e, 0x14, 0xce, 0x97, 0x72, 0x45, 0xa4, 0xf6, 0x2b, 0x01, 0xb7, 0x5b, 0x9b, 0xff, 0xd8, 0x58, - 0x83, 0x5c, 0xc3, 0xf7, 0x3c, 0xea, 0x0a, 0xf9, 0x8b, 0xc9, 0xbc, 0xbc, 0xb1, 0xa2, 0xe1, 0xaf, - 0x08, 0x6e, 0xca, 0xd5, 0xa0, 0xc1, 0xdd, 0x2e, 0xb3, 0x63, 0xfe, 0x68, 0x32, 0x5f, 0x44, 0x77, - 0xb9, 0x44, 0xa2, 0xbe, 0x86, 0x24, 0xbf, 0xb5, 0xb1, 0x2e, 0xa7, 0x78, 0x08, 0x3b, 0xff, 0x32, - 0x5e, 0x50, 0xd7, 0xa3, 0xd5, 0xba, 0x6e, 0x6d, 0x1c, 0xcc, 0x58, 0x7d, 0xf5, 0x57, 0xa3, 0x29, - 0x51, 0xc6, 0x53, 0xa2, 0x9c, 0x4c, 0x09, 0xfa, 0x12, 0x10, 0xf4, 0x23, 0x20, 0xe8, 0x38, 0x20, - 0x68, 0x14, 0x10, 0x34, 0x0e, 0x08, 0xfa, 0x1d, 0x10, 0xf4, 0x27, 0x20, 0xca, 0x49, 0x40, 0xd0, - 0xf7, 0x19, 0x51, 0x46, 0x33, 0xa2, 0x8c, 0x67, 0x44, 0x39, 0x28, 0x9c, 0x7f, 0x9d, 0x5a, 0x69, - 0x19, 0xfc, 0xf0, 0x6f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x45, 0x19, 0xc5, 0xc4, 0x69, 0x05, 0x00, - 0x00, + // 580 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x94, 0xc1, 0x8e, 0xd2, 0x40, + 0x18, 0xc7, 0x3b, 0x40, 0x61, 0x77, 0x00, 0x83, 0x93, 0x18, 0x1b, 0xb2, 0x19, 0xb0, 0x46, 0xc5, + 0x83, 0xc5, 0xe0, 0x41, 0xe3, 0xc1, 0x44, 0x90, 0x18, 0x15, 0xd1, 0xed, 0x26, 0x6e, 0xb2, 0xb7, + 0x16, 0x86, 0x32, 0xb1, 0xdb, 0x21, 0xed, 0x74, 0x15, 0x4f, 0x1a, 0x5f, 0xc0, 0xc7, 0xf0, 0x21, + 0x7c, 0x80, 0x3d, 0x72, 0xf0, 0xc0, 0x89, 0x48, 0xb9, 0x18, 0x4e, 0xfb, 0x08, 0x86, 0xa1, 0xec, + 0x16, 0xb2, 0xc8, 0x26, 0xbb, 0x27, 0x66, 0xfe, 0x33, 0xff, 0xdf, 0xf7, 0xf1, 0xef, 0x97, 0x81, + 0xf7, 0x1d, 0xd6, 0x26, 0x5e, 0x8d, 0x31, 0xb7, 0x4d, 0x1d, 0x83, 0x33, 0x57, 0x27, 0x16, 0xf5, + 0xb8, 0xdb, 0xdf, 0xa7, 0xbc, 0xfb, 0xdc, 0x6f, 0x71, 0xca, 0x1c, 0xad, 0xe7, 0x32, 0xce, 0x90, + 0x2c, 0x7e, 0xf2, 0x0f, 0x2c, 0xca, 0xbb, 0xbe, 0xa9, 0xb5, 0xd8, 0x61, 0xd9, 0x62, 0x16, 0x2b, + 0x0b, 0xd9, 0xf4, 0x3b, 0x62, 0x27, 0x36, 0x62, 0x35, 0x77, 0xa9, 0xdf, 0x01, 0xbc, 0xb1, 0x47, + 0x5c, 0x6a, 0xd8, 0xf4, 0x8b, 0x61, 0xda, 0xe4, 0x83, 0x61, 0xd3, 0xf6, 0xac, 0x10, 0x52, 0x61, + 0xf2, 0xbd, 0x6f, 0xbe, 0x21, 0x7d, 0x05, 0x14, 0x41, 0x29, 0x53, 0x85, 0xd3, 0x51, 0x21, 0xd9, + 0x13, 0x8a, 0x1e, 0x9e, 0xa0, 0x3b, 0x30, 0x55, 0xeb, 0x1a, 0x4e, 0x8b, 0x78, 0x4a, 0xac, 0x08, + 0x4a, 0xd9, 0x6a, 0x7a, 0x3a, 0x2a, 0xa4, 0x5a, 0x73, 0x49, 0x5f, 0x9c, 0xa1, 0x02, 0x94, 0x5f, + 0x39, 0x6d, 0xf2, 0x59, 0x89, 0x8b, 0x4b, 0xdb, 0xd3, 0x51, 0x41, 0xa6, 0x33, 0x41, 0x9f, 0xeb, + 0xea, 0x33, 0x08, 0x4f, 0x0b, 0x7b, 0xe8, 0x21, 0x4c, 0xbc, 0x30, 0xb8, 0xa1, 0x80, 0x62, 0xbc, + 0x94, 0xae, 0xec, 0xcc, 0x3b, 0xd5, 0xce, 0xed, 0x52, 0x17, 0x37, 0xd5, 0xdf, 0x32, 0xcc, 0xd7, + 0x7b, 0xac, 0xd5, 0x3d, 0xa3, 0x44, 0x02, 0x42, 0xbb, 0x70, 0xab, 0x6e, 0x53, 0x8b, 0x9a, 0x36, + 0x09, 0xa1, 0xe5, 0x10, 0xba, 0xde, 0xa4, 0x2d, 0x1c, 0x75, 0x87, 0xbb, 0xfd, 0x6a, 0xe2, 0x78, + 0x54, 0x90, 0xf4, 0x53, 0x0c, 0x6a, 0xc2, 0xd4, 0xbe, 0x41, 0x39, 0x75, 0x2c, 0x25, 0x26, 0x88, + 0xda, 0x66, 0x62, 0x68, 0x88, 0x02, 0x17, 0x90, 0x19, 0xaf, 0x41, 0x8c, 0xa3, 0x19, 0x2f, 0x7e, + 0x51, 0x5e, 0x68, 0x58, 0xe2, 0x85, 0x1a, 0x3a, 0x80, 0xe9, 0xbd, 0xae, 0xdf, 0xe9, 0xd8, 0xa4, + 0xfd, 0xce, 0xe7, 0x4a, 0x42, 0x30, 0x2b, 0x9b, 0x99, 0x11, 0x53, 0x94, 0x1b, 0x85, 0xa1, 0xbb, + 0xf0, 0x5a, 0x83, 0x7d, 0x0a, 0x3b, 0x6f, 0x50, 0x8f, 0x2b, 0x72, 0x11, 0x94, 0xb6, 0xf4, 0x15, + 0x35, 0xdf, 0x84, 0xd9, 0xa5, 0x10, 0x51, 0x0e, 0xc6, 0x3f, 0x86, 0xf3, 0xb4, 0xad, 0xcf, 0x96, + 0xe8, 0x1e, 0x94, 0x8f, 0x0c, 0xdb, 0x27, 0x62, 0x7c, 0xd2, 0x95, 0xeb, 0x61, 0x83, 0x67, 0xbd, + 0xe9, 0xf3, 0xf3, 0xa7, 0xb1, 0x27, 0x20, 0xff, 0x16, 0x66, 0xa2, 0x11, 0x5e, 0x01, 0x2e, 0x9a, + 0xe0, 0x65, 0x71, 0xbb, 0x30, 0xb7, 0x1a, 0xde, 0x25, 0x91, 0xea, 0xaf, 0x18, 0xbc, 0xdd, 0xdc, + 0xfc, 0x00, 0x20, 0x15, 0x66, 0x6a, 0xbe, 0xeb, 0x12, 0x87, 0x8b, 0x2f, 0x2b, 0xea, 0x65, 0xf5, + 0x25, 0x0d, 0x7d, 0x03, 0xf0, 0xa6, 0x58, 0x79, 0x35, 0xe6, 0x74, 0xa8, 0x15, 0xf1, 0x87, 0x13, + 0xfc, 0x32, 0xec, 0xe5, 0x02, 0x15, 0xb5, 0x35, 0x24, 0xf1, 0xaf, 0xf5, 0x75, 0x75, 0xf2, 0x87, + 0x70, 0xe7, 0x7f, 0xc6, 0x73, 0xe2, 0x7a, 0xbc, 0x1c, 0xd7, 0xad, 0x8d, 0x03, 0x1c, 0x89, 0xaf, + 0xfa, 0x7a, 0x30, 0xc6, 0xd2, 0x70, 0x8c, 0xa5, 0x93, 0x31, 0x06, 0x5f, 0x03, 0x0c, 0x7e, 0x06, + 0x18, 0x1c, 0x07, 0x18, 0x0c, 0x02, 0x0c, 0x86, 0x01, 0x06, 0x7f, 0x02, 0x0c, 0xfe, 0x06, 0x58, + 0x3a, 0x09, 0x30, 0xf8, 0x31, 0xc1, 0xd2, 0x60, 0x82, 0xa5, 0xe1, 0x04, 0x4b, 0x07, 0xb9, 0xd5, + 0x67, 0xd7, 0x4c, 0x8a, 0xc2, 0x8f, 0xfe, 0x05, 0x00, 0x00, 0xff, 0xff, 0x65, 0xa3, 0xf9, 0xfb, + 0x91, 0x05, 0x00, 0x00, } func (this *SerializableValidator) Equal(that interface{}) bool { @@ -405,6 +414,9 @@ func (this *EpochValidatorsWithAuction) Equal(that interface{}) bool { return false } } + if this.LowWaitingList != that1.LowWaitingList { + return false + } return true } func (this *NodesCoordinatorRegistryWithAuction) Equal(that interface{}) bool { @@ -467,7 +479,7 @@ func (this *EpochValidatorsWithAuction) GoString() string { if this == nil { return "nil" } - s := make([]string, 0, 8) + s := make([]string, 0, 9) s = append(s, "&nodesCoordinator.EpochValidatorsWithAuction{") keysForEligible := make([]string, 0, len(this.Eligible)) for k, _ := range this.Eligible { @@ -521,6 +533,7 @@ func (this *EpochValidatorsWithAuction) GoString() string { if this.ShuffledOut != nil { s = append(s, "ShuffledOut: "+mapStringForShuffledOut+",\n") } + s = append(s, "LowWaitingList: "+fmt.Sprintf("%#v", this.LowWaitingList)+",\n") s = append(s, "}") return strings.Join(s, "") } @@ -652,6 +665,16 @@ func (m *EpochValidatorsWithAuction) MarshalToSizedBuffer(dAtA []byte) (int, err _ = i var l int _ = l + if m.LowWaitingList { + i-- + if m.LowWaitingList { + dAtA[i] = 1 + } else { + dAtA[i] = 0 + } + i-- + dAtA[i] = 0x28 + } if len(m.ShuffledOut) > 0 { keysForShuffledOut := make([]string, 0, len(m.ShuffledOut)) for k := range m.ShuffledOut { @@ -917,6 +940,9 @@ func (m *EpochValidatorsWithAuction) Size() (n int) { n += mapEntrySize + 1 + sovNodesCoordinatorRegistryWithAuction(uint64(mapEntrySize)) } } + if m.LowWaitingList { + n += 2 + } return n } @@ -1027,6 +1053,7 @@ func (this *EpochValidatorsWithAuction) String() string { `Waiting:` + mapStringForWaiting + `,`, `Leaving:` + mapStringForLeaving + `,`, `ShuffledOut:` + mapStringForShuffledOut + `,`, + `LowWaitingList:` + fmt.Sprintf("%v", this.LowWaitingList) + `,`, `}`, }, "") return s @@ -1817,6 +1844,26 @@ func (m *EpochValidatorsWithAuction) Unmarshal(dAtA []byte) error { } m.ShuffledOut[mapkey] = *mapvalue iNdEx = postIndex + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field LowWaitingList", wireType) + } + var v int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowNodesCoordinatorRegistryWithAuction + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + v |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + m.LowWaitingList = bool(v != 0) default: iNdEx = preIndex skippy, err := skipNodesCoordinatorRegistryWithAuction(dAtA[iNdEx:]) diff --git a/sharding/nodesCoordinator/nodesCoordinatorRegistryWithAuction.proto b/sharding/nodesCoordinator/nodesCoordinatorRegistryWithAuction.proto index 3ff1c90acb1..d4b3ef455bd 100644 --- a/sharding/nodesCoordinator/nodesCoordinatorRegistryWithAuction.proto +++ b/sharding/nodesCoordinator/nodesCoordinatorRegistryWithAuction.proto @@ -8,9 +8,9 @@ option (gogoproto.stable_marshaler_all) = true; import "github.com/gogo/protobuf/gogoproto/gogo.proto"; message SerializableValidator { - bytes PubKey = 1 [(gogoproto.jsontag) = "pubKey"]; + bytes PubKey = 1 [(gogoproto.jsontag) = "pubKey"]; uint32 Chances = 2 [(gogoproto.jsontag) = "chances"]; - uint32 Index = 3 [(gogoproto.jsontag) = "index"]; + uint32 Index = 3 [(gogoproto.jsontag) = "index"]; } message Validators { @@ -18,13 +18,14 @@ message Validators { } message EpochValidatorsWithAuction { - map Eligible = 1 [(gogoproto.nullable) = false]; - map Waiting = 2 [(gogoproto.nullable) = false]; - map Leaving = 3 [(gogoproto.nullable) = false]; - map ShuffledOut = 4 [(gogoproto.nullable) = false]; + map Eligible = 1 [(gogoproto.nullable) = false]; + map Waiting = 2 [(gogoproto.nullable) = false]; + map Leaving = 3 [(gogoproto.nullable) = false]; + map ShuffledOut = 4 [(gogoproto.nullable) = false]; + bool LowWaitingList = 5; } message NodesCoordinatorRegistryWithAuction { - uint32 CurrentEpoch = 1; + uint32 CurrentEpoch = 1; map EpochsConfigWithAuction = 2; } diff --git a/testscommon/shardingMocks/nodesCoordinatorMock.go b/testscommon/shardingMocks/nodesCoordinatorMock.go index 3ee80f88d3d..9f1b872e2ab 100644 --- a/testscommon/shardingMocks/nodesCoordinatorMock.go +++ b/testscommon/shardingMocks/nodesCoordinatorMock.go @@ -5,29 +5,31 @@ import ( "fmt" "github.com/multiversx/mx-chain-core-go/core" + "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "github.com/multiversx/mx-chain-go/state" ) // NodesCoordinatorMock defines the behaviour of a struct able to do validator group selection type NodesCoordinatorMock struct { - Validators map[uint32][]nodesCoordinator.Validator - ShardConsensusSize uint32 - MetaConsensusSize uint32 - ShardId uint32 - NbShards uint32 - GetSelectedPublicKeysCalled func(selection []byte, shardId uint32, epoch uint32) (publicKeys []string, err error) - GetValidatorsPublicKeysCalled func(randomness []byte, round uint64, shardId uint32, epoch uint32) ([]string, error) - GetValidatorsRewardsAddressesCalled func(randomness []byte, round uint64, shardId uint32, epoch uint32) ([]string, error) - SetNodesPerShardsCalled func(nodes map[uint32][]nodesCoordinator.Validator, epoch uint32) error - ComputeValidatorsGroupCalled func(randomness []byte, round uint64, shardId uint32, epoch uint32) (validatorsGroup []nodesCoordinator.Validator, err error) - GetValidatorWithPublicKeyCalled func(publicKey []byte) (validator nodesCoordinator.Validator, shardId uint32, err error) - GetAllEligibleValidatorsPublicKeysCalled func(epoch uint32) (map[uint32][][]byte, error) - GetAllWaitingValidatorsPublicKeysCalled func() (map[uint32][][]byte, error) - ConsensusGroupSizeCalled func(uint32) int - GetValidatorsIndexesCalled func(publicKeys []string, epoch uint32) ([]uint64, error) - GetAllShuffledOutValidatorsPublicKeysCalled func(epoch uint32) (map[uint32][][]byte, error) - GetNumTotalEligibleCalled func() uint64 + Validators map[uint32][]nodesCoordinator.Validator + ShardConsensusSize uint32 + MetaConsensusSize uint32 + ShardId uint32 + NbShards uint32 + GetSelectedPublicKeysCalled func(selection []byte, shardId uint32, epoch uint32) (publicKeys []string, err error) + GetValidatorsPublicKeysCalled func(randomness []byte, round uint64, shardId uint32, epoch uint32) ([]string, error) + GetValidatorsRewardsAddressesCalled func(randomness []byte, round uint64, shardId uint32, epoch uint32) ([]string, error) + SetNodesPerShardsCalled func(nodes map[uint32][]nodesCoordinator.Validator, epoch uint32) error + ComputeValidatorsGroupCalled func(randomness []byte, round uint64, shardId uint32, epoch uint32) (validatorsGroup []nodesCoordinator.Validator, err error) + GetValidatorWithPublicKeyCalled func(publicKey []byte) (validator nodesCoordinator.Validator, shardId uint32, err error) + GetAllEligibleValidatorsPublicKeysCalled func(epoch uint32) (map[uint32][][]byte, error) + GetAllWaitingValidatorsPublicKeysCalled func() (map[uint32][][]byte, error) + ConsensusGroupSizeCalled func(uint32) int + GetValidatorsIndexesCalled func(publicKeys []string, epoch uint32) ([]uint64, error) + GetAllShuffledOutValidatorsPublicKeysCalled func(epoch uint32) (map[uint32][][]byte, error) + GetShuffledOutToAuctionValidatorsPublicKeysCalled func(epoch uint32) (map[uint32][][]byte, error) + GetNumTotalEligibleCalled func() uint64 } // NewNodesCoordinatorMock - @@ -110,6 +112,15 @@ func (ncm *NodesCoordinatorMock) GetAllShuffledOutValidatorsPublicKeys(epoch uin return nil, nil } +// GetShuffledOutToAuctionValidatorsPublicKeys - +func (ncm *NodesCoordinatorMock) GetShuffledOutToAuctionValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error) { + if ncm.GetShuffledOutToAuctionValidatorsPublicKeysCalled != nil { + return ncm.GetShuffledOutToAuctionValidatorsPublicKeysCalled(epoch) + } + + return nil, nil +} + // GetValidatorsIndexes - func (ncm *NodesCoordinatorMock) GetValidatorsIndexes(publicKeys []string, epoch uint32) ([]uint64, error) { if ncm.GetValidatorsIndexesCalled != nil { diff --git a/testscommon/shardingMocks/nodesCoordinatorStub.go b/testscommon/shardingMocks/nodesCoordinatorStub.go index 9f82a5256e5..a142f0509ed 100644 --- a/testscommon/shardingMocks/nodesCoordinatorStub.go +++ b/testscommon/shardingMocks/nodesCoordinatorStub.go @@ -2,6 +2,7 @@ package shardingMocks import ( "github.com/multiversx/mx-chain-core-go/data" + "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "github.com/multiversx/mx-chain-go/state" ) @@ -82,6 +83,11 @@ func (ncm *NodesCoordinatorStub) GetAllShuffledOutValidatorsPublicKeys(_ uint32) return nil, nil } +// GetShuffledOutToAuctionValidatorsPublicKeys - +func (ncm *NodesCoordinatorStub) GetShuffledOutToAuctionValidatorsPublicKeys(_ uint32) (map[uint32][][]byte, error) { + return nil, nil +} + // GetNumTotalEligible - func (ncm *NodesCoordinatorStub) GetNumTotalEligible() uint64 { if ncm.GetNumTotalEligibleCalled != nil { From 2bb0754624ee0f216878c5472a478242cb736ee4 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 15 May 2024 11:54:41 +0300 Subject: [PATCH 108/467] added missing config --- cmd/node/config/config.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cmd/node/config/config.toml b/cmd/node/config/config.toml index b6c11452a64..f434fd3398d 100644 --- a/cmd/node/config/config.toml +++ b/cmd/node/config/config.toml @@ -940,3 +940,6 @@ # MaxRoundsOfInactivityAccepted defines the number of rounds missed by a main or higher level backup machine before # the current machine will take over and propose/sign blocks. Used in both single-key and multi-key modes. MaxRoundsOfInactivityAccepted = 3 + +[RelayedTransactionConfig] + MaxTransactionsAllowed = 50 From f79acdf7b24fdd18498772b39bc8ae360a3d64ff Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Wed, 15 May 2024 13:11:01 +0300 Subject: [PATCH 109/467] fix nodes config update after shuffling and add chain simulator scenario --- .../staking/stake/stakeAndUnStake_test.go | 113 +++++++++++++++++- .../indexHashedNodesCoordinator.go | 6 +- .../indexHashedNodesCoordinatorLite.go | 2 +- ...dexHashedNodesCoordinatorWithRater_test.go | 19 +-- .../indexHashedNodesCoordinator_test.go | 27 +++-- 5 files changed, 140 insertions(+), 27 deletions(-) diff --git a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index 57a8df77cec..c29f5cab9b0 100644 --- a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go @@ -12,6 +12,9 @@ import ( coreAPI "github.com/multiversx/mx-chain-core-go/data/api" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-core-go/data/validator" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" @@ -23,8 +26,6 @@ import ( chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/vm" - logger "github.com/multiversx/mx-chain-logger-go" - "github.com/stretchr/testify/require" ) const ( @@ -2383,6 +2384,114 @@ func TestChainSimulator_UnStakeOneActiveNodeAndCheckAPIAuctionList(t *testing.T) require.Equal(t, 1, numUnQualified) } +// Nodes configuration at genesis consisting of a total of 40 nodes, distributed on 3 shards + meta: +// - 4 eligible nodes/shard +// - 4 waiting nodes/shard +// - 2 nodes to shuffle per shard +// - max num nodes config for stakingV4 step3 = 32 (being downsized from previously 40 nodes) +// - with this config, we should always select max 8 nodes from auction list if there are > 40 nodes in the network +// This test will run with only 32 nodes and check that there are no nodes in the auction list, +// because of the lowWaitingList condition being triggered when in staking v4 +func TestChainSimulator_EdgeCaseLowWaitingList(t *testing.T) { + if testing.Short() { + t.Skip("this is not a short test") + } + + startTime := time.Now().Unix() + roundDurationInMillis := uint64(6000) + roundsPerEpoch := core.OptionalUint64{ + HasValue: true, + Value: 20, + } + + stakingV4Step1Epoch := uint32(2) + stakingV4Step2Epoch := uint32(3) + stakingV4Step3Epoch := uint32(4) + + numOfShards := uint32(3) + cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ + BypassTxSignatureCheck: false, + TempDir: t.TempDir(), + PathToInitialConfig: defaultPathToInitialConfig, + NumOfShards: numOfShards, + GenesisTimestamp: startTime, + RoundDurationInMillis: roundDurationInMillis, + RoundsPerEpoch: roundsPerEpoch, + ApiInterface: api.NewNoApiInterface(), + MinNodesPerShard: 4, + MetaChainMinNodes: 4, + NumNodesWaitingListMeta: 2, + NumNodesWaitingListShard: 2, + AlterConfigsFunction: func(cfg *config.Configs) { + cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = stakingV4Step1Epoch + cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = stakingV4Step2Epoch + cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = stakingV4Step3Epoch + + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[1].MaxNumNodes = 40 + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[1].NodesToShufflePerShard = 2 + + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = stakingV4Step3Epoch + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].MaxNumNodes = 32 + cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].NodesToShufflePerShard = 2 + }, + }) + require.Nil(t, err) + require.NotNil(t, cs) + + defer cs.Close() + + epochToCheck := int32(stakingV4Step3Epoch + 1) + err = cs.GenerateBlocksUntilEpochIsReached(epochToCheck) + require.Nil(t, err) + + metachainNode := cs.GetNodeHandler(core.MetachainShardId) + numQualified, numUnQualified := getNumQualifiedAndUnqualified(t, metachainNode) + require.Equal(t, 0, numQualified) + require.Equal(t, 0, numUnQualified) + + // we always have 0 in auction list because of the lowWaitingList condition + epochToCheck += 1 + err = cs.GenerateBlocksUntilEpochIsReached(epochToCheck) + numQualified, numUnQualified = getNumQualifiedAndUnqualified(t, metachainNode) + require.Equal(t, 0, numQualified) + require.Equal(t, 0, numUnQualified) + + // stake 16 mode nodes, these will go to auction list + stakeNodes(t, cs, 16) + + epochToCheck += 1 + err = cs.GenerateBlocksUntilEpochIsReached(epochToCheck) + numQualified, numUnQualified = getNumQualifiedAndUnqualified(t, metachainNode) + // all the previously registered will be selected, as we have 24 nodes in eligible+waiting, 8 will shuffle out, + // but this time there will be not be lowWaitingList, as there are enough in auction, so we will end up with + // 24-8 = 16 nodes remaining + 16 from auction, to fill up all 32 positions + require.Equal(t, 16, numQualified) + require.Equal(t, 0, numUnQualified) +} + +func stakeNodes(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, numTxs int) { + txs := make([]*transaction.Transaction, numTxs) + for i := 0; i < numTxs; i++ { + privateKey, blsKeys, err := chainSimulator.GenerateBlsPrivateKeys(1) + require.Nil(t, err) + err = cs.AddValidatorKeys(privateKey) + require.Nil(t, err) + + mintValue := big.NewInt(0).Add(staking.MinimumStakeValue, staking.OneEGLD) + validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) + require.Nil(t, err) + + txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) + txs[i] = staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) + } + stakeTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted(txs, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, stakeTxs) + require.Len(t, stakeTxs, numTxs) + + require.Nil(t, cs.GenerateBlocks(1)) +} + func stakeOneNode(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator) { privateKey, blsKeys, err := chainSimulator.GenerateBlsPrivateKeys(1) require.Nil(t, err) diff --git a/sharding/nodesCoordinator/indexHashedNodesCoordinator.go b/sharding/nodesCoordinator/indexHashedNodesCoordinator.go index 4deb3f01bcd..4898f018010 100644 --- a/sharding/nodesCoordinator/indexHashedNodesCoordinator.go +++ b/sharding/nodesCoordinator/indexHashedNodesCoordinator.go @@ -159,7 +159,7 @@ func NewIndexHashedNodesCoordinator(arguments ArgNodesCoordinator) (*indexHashed ihnc.loadingFromDisk.Store(false) ihnc.nodesCoordinatorHelper = ihnc - err = ihnc.setNodesPerShards(arguments.EligibleNodes, arguments.WaitingNodes, nil, nil, arguments.Epoch) + err = ihnc.setNodesPerShards(arguments.EligibleNodes, arguments.WaitingNodes, nil, nil, arguments.Epoch, false) if err != nil { return nil, err } @@ -260,6 +260,7 @@ func (ihnc *indexHashedNodesCoordinator) setNodesPerShards( leaving map[uint32][]Validator, shuffledOut map[uint32][]Validator, epoch uint32, + lowWaitingList bool, ) error { ihnc.mutNodesConfig.Lock() defer ihnc.mutNodesConfig.Unlock() @@ -299,6 +300,7 @@ func (ihnc *indexHashedNodesCoordinator) setNodesPerShards( nodesConfig.waitingMap = waiting nodesConfig.leavingMap = leaving nodesConfig.shuffledOutMap = shuffledOut + nodesConfig.lowWaitingList = lowWaitingList nodesConfig.shardID, isCurrentNodeValidator = ihnc.computeShardForSelfPublicKey(nodesConfig) nodesConfig.selectors, err = ihnc.createSelectors(nodesConfig) if err != nil { @@ -685,7 +687,7 @@ func (ihnc *indexHashedNodesCoordinator) EpochStartPrepare(metaHdr data.HeaderHa resUpdateNodes.Leaving, ) - err = ihnc.setNodesPerShards(resUpdateNodes.Eligible, resUpdateNodes.Waiting, leavingNodesMap, resUpdateNodes.ShuffledOut, newEpoch) + err = ihnc.setNodesPerShards(resUpdateNodes.Eligible, resUpdateNodes.Waiting, leavingNodesMap, resUpdateNodes.ShuffledOut, newEpoch, resUpdateNodes.LowWaitingList) if err != nil { log.Error("set nodes per shard failed", "error", err.Error()) } diff --git a/sharding/nodesCoordinator/indexHashedNodesCoordinatorLite.go b/sharding/nodesCoordinator/indexHashedNodesCoordinatorLite.go index 3b80e8bdd23..b5b87781a73 100644 --- a/sharding/nodesCoordinator/indexHashedNodesCoordinatorLite.go +++ b/sharding/nodesCoordinator/indexHashedNodesCoordinatorLite.go @@ -41,7 +41,7 @@ func (ihnc *indexHashedNodesCoordinator) SetNodesConfigFromValidatorsInfo(epoch resUpdateNodes.Leaving, ) - err = ihnc.setNodesPerShards(resUpdateNodes.Eligible, resUpdateNodes.Waiting, leavingNodesMap, resUpdateNodes.ShuffledOut, epoch) + err = ihnc.setNodesPerShards(resUpdateNodes.Eligible, resUpdateNodes.Waiting, leavingNodesMap, resUpdateNodes.ShuffledOut, epoch, resUpdateNodes.LowWaitingList) if err != nil { return err } diff --git a/sharding/nodesCoordinator/indexHashedNodesCoordinatorWithRater_test.go b/sharding/nodesCoordinator/indexHashedNodesCoordinatorWithRater_test.go index 40286a0c135..a80006cceae 100644 --- a/sharding/nodesCoordinator/indexHashedNodesCoordinatorWithRater_test.go +++ b/sharding/nodesCoordinator/indexHashedNodesCoordinatorWithRater_test.go @@ -13,6 +13,9 @@ import ( "github.com/multiversx/mx-chain-core-go/data/endProcess" "github.com/multiversx/mx-chain-core-go/hashing/blake2b" "github.com/multiversx/mx-chain-core-go/hashing/sha256" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/sharding/mock" "github.com/multiversx/mx-chain-go/state" @@ -20,8 +23,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/nodeTypeProviderMock" vic "github.com/multiversx/mx-chain-go/testscommon/validatorInfoCacher" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestNewIndexHashedNodesCoordinatorWithRater_NilRaterShouldErr(t *testing.T) { @@ -48,14 +49,14 @@ func TestNewIndexHashedGroupSelectorWithRater_OkValsShouldWork(t *testing.T) { assert.Nil(t, err) } -//------- LoadEligibleList +// ------- LoadEligibleList func TestIndexHashedGroupSelectorWithRater_SetNilEligibleMapShouldErr(t *testing.T) { t.Parallel() waiting := createDummyNodesMap(2, 1, "waiting") nc, _ := NewIndexHashedNodesCoordinator(createArguments()) ihnc, _ := NewIndexHashedNodesCoordinatorWithRater(nc, &mock.RaterMock{}) - assert.Equal(t, ErrNilInputNodesMap, ihnc.setNodesPerShards(nil, waiting, nil, nil, 0)) + assert.Equal(t, ErrNilInputNodesMap, ihnc.setNodesPerShards(nil, waiting, nil, nil, 0, false)) } func TestIndexHashedGroupSelectorWithRater_OkValShouldWork(t *testing.T) { @@ -113,7 +114,7 @@ func TestIndexHashedGroupSelectorWithRater_OkValShouldWork(t *testing.T) { assert.Equal(t, eligibleMap[0], readEligible) } -//------- functionality tests +// ------- functionality tests func TestIndexHashedGroupSelectorWithRater_ComputeValidatorsGroup1ValidatorShouldNotCallGetRating(t *testing.T) { t.Parallel() @@ -149,7 +150,7 @@ func BenchmarkIndexHashedGroupSelectorWithRater_ComputeValidatorsGroup63of400(b consensusGroupSize := 63 list := make([]Validator, 0) - //generate 400 validators + // generate 400 validators for i := 0; i < 400; i++ { list = append(list, newValidatorMock([]byte("pk"+strconv.Itoa(i)), 1, defaultSelectionChances)) } @@ -219,7 +220,7 @@ func Test_ComputeValidatorsGroup63of400(t *testing.T) { shardSize := uint32(400) list := make([]Validator, 0) - //generate 400 validators + // generate 400 validators for i := uint32(0); i < shardSize; i++ { list = append(list, newValidatorMock([]byte(fmt.Sprintf("pk%v", i)), 1, defaultSelectionChances)) } @@ -785,7 +786,7 @@ func BenchmarkIndexHashedGroupSelectorWithRater_TestExpandList(b *testing.B) { } } - //a := []int{1, 2, 3, 4, 5, 6, 7, 8} + // a := []int{1, 2, 3, 4, 5, 6, 7, 8} rnd := rand.New(rand.NewSource(time.Now().UnixNano())) rnd.Shuffle(len(array), func(i, j int) { array[i], array[j] = array[j], array[i] }) m2 := runtime.MemStats{} @@ -820,7 +821,7 @@ func BenchmarkIndexHashedWithRaterGroupSelector_ComputeValidatorsGroup21of400(b consensusGroupSize := 21 list := make([]Validator, 0) - //generate 400 validators + // generate 400 validators for i := 0; i < 400; i++ { list = append(list, newValidatorMock([]byte("pk"+strconv.Itoa(i)), 1, defaultSelectionChances)) } diff --git a/sharding/nodesCoordinator/indexHashedNodesCoordinator_test.go b/sharding/nodesCoordinator/indexHashedNodesCoordinator_test.go index 5db65609f59..32cc2ca8326 100644 --- a/sharding/nodesCoordinator/indexHashedNodesCoordinator_test.go +++ b/sharding/nodesCoordinator/indexHashedNodesCoordinator_test.go @@ -20,6 +20,9 @@ import ( "github.com/multiversx/mx-chain-core-go/hashing" "github.com/multiversx/mx-chain-core-go/hashing/sha256" "github.com/multiversx/mx-chain-core-go/marshal" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/dataRetriever/dataPool" "github.com/multiversx/mx-chain-go/epochStart" @@ -31,8 +34,6 @@ import ( "github.com/multiversx/mx-chain-go/testscommon/hashingMocks" "github.com/multiversx/mx-chain-go/testscommon/nodeTypeProviderMock" vic "github.com/multiversx/mx-chain-go/testscommon/validatorInfoCacher" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) const stakingV4Epoch = 444 @@ -145,7 +146,7 @@ func validatorsPubKeys(validators []Validator) []string { return pKeys } -//------- NewIndexHashedNodesCoordinator +// ------- NewIndexHashedNodesCoordinator func TestNewIndexHashedNodesCoordinator_NilHasherShouldErr(t *testing.T) { t.Parallel() @@ -247,7 +248,7 @@ func TestNewIndexHashedGroupSelector_OkValsShouldWork(t *testing.T) { require.Nil(t, err) } -//------- LoadEligibleList +// ------- LoadEligibleList func TestIndexHashedNodesCoordinator_SetNilEligibleMapShouldErr(t *testing.T) { t.Parallel() @@ -256,7 +257,7 @@ func TestIndexHashedNodesCoordinator_SetNilEligibleMapShouldErr(t *testing.T) { arguments := createArguments() ihnc, _ := NewIndexHashedNodesCoordinator(arguments) - require.Equal(t, ErrNilInputNodesMap, ihnc.setNodesPerShards(nil, waitingMap, nil, nil, 0)) + require.Equal(t, ErrNilInputNodesMap, ihnc.setNodesPerShards(nil, waitingMap, nil, nil, 0, false)) } func TestIndexHashedNodesCoordinator_SetNilWaitingMapShouldErr(t *testing.T) { @@ -266,7 +267,7 @@ func TestIndexHashedNodesCoordinator_SetNilWaitingMapShouldErr(t *testing.T) { arguments := createArguments() ihnc, _ := NewIndexHashedNodesCoordinator(arguments) - require.Equal(t, ErrNilInputNodesMap, ihnc.setNodesPerShards(eligibleMap, nil, nil, nil, 0)) + require.Equal(t, ErrNilInputNodesMap, ihnc.setNodesPerShards(eligibleMap, nil, nil, nil, 0, false)) } func TestIndexHashedNodesCoordinator_OkValShouldWork(t *testing.T) { @@ -319,7 +320,7 @@ func TestIndexHashedNodesCoordinator_OkValShouldWork(t *testing.T) { require.Equal(t, eligibleMap[0], readEligible) } -//------- ComputeValidatorsGroup +// ------- ComputeValidatorsGroup func TestIndexHashedNodesCoordinator_NewCoordinatorGroup0SizeShouldErr(t *testing.T) { t.Parallel() @@ -401,7 +402,7 @@ func TestIndexHashedNodesCoordinator_ComputeValidatorsGroupInvalidShardIdShouldE require.Nil(t, list2) } -//------- functionality tests +// ------- functionality tests func TestIndexHashedNodesCoordinator_ComputeValidatorsGroup1ValidatorShouldReturnSame(t *testing.T) { t.Parallel() @@ -558,7 +559,7 @@ func TestIndexHashedNodesCoordinator_ComputeValidatorsGroup400of400For10BlocksMe mut := sync.Mutex{} - //consensusGroup := list[0:21] + // consensusGroup := list[0:21] cacheMap := make(map[string]interface{}) lruCache := &mock.NodesCoordinatorCacheMock{ PutCalled: func(key []byte, value interface{}, sizeInBytes int) (evicted bool) { @@ -1275,7 +1276,7 @@ func TestIndexHashedNodesCoordinator_setNodesPerShardsShouldTriggerWrongConfigur }, } - err = ihnc.setNodesPerShards(eligibleMap, map[uint32][]Validator{}, map[uint32][]Validator{}, map[uint32][]Validator{}, 2) + err = ihnc.setNodesPerShards(eligibleMap, map[uint32][]Validator{}, map[uint32][]Validator{}, map[uint32][]Validator{}, 2, false) require.NoError(t, err) value := <-chanStopNode @@ -1301,7 +1302,7 @@ func TestIndexHashedNodesCoordinator_setNodesPerShardsShouldNotTriggerWrongConfi }, } - err = ihnc.setNodesPerShards(eligibleMap, map[uint32][]Validator{}, map[uint32][]Validator{}, map[uint32][]Validator{}, 2) + err = ihnc.setNodesPerShards(eligibleMap, map[uint32][]Validator{}, map[uint32][]Validator{}, map[uint32][]Validator{}, 2, false) require.NoError(t, err) require.Empty(t, chanStopNode) @@ -1333,7 +1334,7 @@ func TestIndexHashedNodesCoordinator_setNodesPerShardsShouldSetNodeTypeValidator }, } - err = ihnc.setNodesPerShards(eligibleMap, map[uint32][]Validator{}, map[uint32][]Validator{}, map[uint32][]Validator{}, 2) + err = ihnc.setNodesPerShards(eligibleMap, map[uint32][]Validator{}, map[uint32][]Validator{}, map[uint32][]Validator{}, 2, false) require.NoError(t, err) require.True(t, setTypeWasCalled) require.Equal(t, core.NodeTypeValidator, nodeTypeResult) @@ -1365,7 +1366,7 @@ func TestIndexHashedNodesCoordinator_setNodesPerShardsShouldSetNodeTypeObserver( }, } - err = ihnc.setNodesPerShards(eligibleMap, map[uint32][]Validator{}, map[uint32][]Validator{}, map[uint32][]Validator{}, 2) + err = ihnc.setNodesPerShards(eligibleMap, map[uint32][]Validator{}, map[uint32][]Validator{}, map[uint32][]Validator{}, 2, false) require.NoError(t, err) require.True(t, setTypeWasCalled) require.Equal(t, core.NodeTypeObserver, nodeTypeResult) From 643030750d923256f74159f6f623964b03dc7c8e Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Wed, 15 May 2024 13:24:19 +0300 Subject: [PATCH 110/467] fix linter issues --- .../chainSimulator/staking/stake/stakeAndUnStake_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index c29f5cab9b0..d876545a124 100644 --- a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go @@ -2452,6 +2452,8 @@ func TestChainSimulator_EdgeCaseLowWaitingList(t *testing.T) { // we always have 0 in auction list because of the lowWaitingList condition epochToCheck += 1 err = cs.GenerateBlocksUntilEpochIsReached(epochToCheck) + require.Nil(t, err) + numQualified, numUnQualified = getNumQualifiedAndUnqualified(t, metachainNode) require.Equal(t, 0, numQualified) require.Equal(t, 0, numUnQualified) @@ -2461,6 +2463,8 @@ func TestChainSimulator_EdgeCaseLowWaitingList(t *testing.T) { epochToCheck += 1 err = cs.GenerateBlocksUntilEpochIsReached(epochToCheck) + require.Nil(t, err) + numQualified, numUnQualified = getNumQualifiedAndUnqualified(t, metachainNode) // all the previously registered will be selected, as we have 24 nodes in eligible+waiting, 8 will shuffle out, // but this time there will be not be lowWaitingList, as there are enough in auction, so we will end up with From b9c087e984f393dfefcc6881b805f94b20f76962 Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Wed, 15 May 2024 14:41:24 +0300 Subject: [PATCH 111/467] fix integration tests --- .../stakingProvider/delegation_test.go | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index ad238766068..3ee5971a502 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go @@ -15,6 +15,10 @@ import ( "github.com/multiversx/mx-chain-crypto-go/signing" "github.com/multiversx/mx-chain-crypto-go/signing/mcl" mclsig "github.com/multiversx/mx-chain-crypto-go/signing/mcl/singlesig" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" @@ -25,9 +29,6 @@ import ( chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/vm" - logger "github.com/multiversx/mx-chain-logger-go" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) var log = logger.GetOrCreate("stakingProvider") @@ -399,11 +400,25 @@ func testBLSKeyIsInAuction( currentEpoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetCurrentEpoch() if metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step2Flag) == currentEpoch { // starting from phase 2, we have the shuffled out nodes from the previous epoch in the action list - actionListSize += 8 + // if there is no lowWaitingList condition + shuffledToAuctionValPubKeys, err := metachainNode.GetProcessComponents().NodesCoordinator().GetShuffledOutToAuctionValidatorsPublicKeys(currentEpoch) + require.Nil(t, err) + + if len(shuffledToAuctionValPubKeys) > 0 { + // there are 2 nodes per shard shuffled out so 2 * 4 = 8 + actionListSize += 8 + } } if metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step3Flag) <= currentEpoch { // starting from phase 3, we have the shuffled out nodes from the previous epoch in the action list - actionListSize += 4 + // if there is no lowWaitingList condition + shuffledToAuctionValPubKeys, err := metachainNode.GetProcessComponents().NodesCoordinator().GetShuffledOutToAuctionValidatorsPublicKeys(currentEpoch) + require.Nil(t, err) + + if len(shuffledToAuctionValPubKeys) > 0 { + // there are 2 nodes per shard shuffled out so 2 * 4 = 8 + actionListSize += 8 + } } require.Equal(t, actionListSize, len(auctionList)) From 3a877d975dadbf9e28faa53dfc3f9140506c0542 Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Wed, 15 May 2024 14:46:01 +0300 Subject: [PATCH 112/467] simplify --- .../stakingProvider/delegation_test.go | 22 ++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index 3ee5971a502..da3950818b7 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go @@ -398,23 +398,15 @@ func testBLSKeyIsInAuction( require.Nil(t, err) currentEpoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetCurrentEpoch() - if metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step2Flag) == currentEpoch { - // starting from phase 2, we have the shuffled out nodes from the previous epoch in the action list - // if there is no lowWaitingList condition - shuffledToAuctionValPubKeys, err := metachainNode.GetProcessComponents().NodesCoordinator().GetShuffledOutToAuctionValidatorsPublicKeys(currentEpoch) - require.Nil(t, err) - if len(shuffledToAuctionValPubKeys) > 0 { - // there are 2 nodes per shard shuffled out so 2 * 4 = 8 - actionListSize += 8 - } - } - if metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step3Flag) <= currentEpoch { - // starting from phase 3, we have the shuffled out nodes from the previous epoch in the action list - // if there is no lowWaitingList condition - shuffledToAuctionValPubKeys, err := metachainNode.GetProcessComponents().NodesCoordinator().GetShuffledOutToAuctionValidatorsPublicKeys(currentEpoch) - require.Nil(t, err) + shuffledToAuctionValPubKeys, err := metachainNode.GetProcessComponents().NodesCoordinator().GetShuffledOutToAuctionValidatorsPublicKeys(currentEpoch) + require.Nil(t, err) + stakingV4Step2Epoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step2Flag) + stakingV4Step3Epoch := metachainNode.GetCoreComponents().EnableEpochsHandler().GetActivationEpoch(common.StakingV4Step3Flag) + if stakingV4Step2Epoch == currentEpoch || stakingV4Step3Epoch == currentEpoch { + // starting from phase 2, we have the shuffled out nodes from the previous epoch in the action list + // if there is no lowWaitingList condition if len(shuffledToAuctionValPubKeys) > 0 { // there are 2 nodes per shard shuffled out so 2 * 4 = 8 actionListSize += 8 From 5e31461c03d4e602faef74d66c342b390b81c682 Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Wed, 15 May 2024 15:27:05 +0300 Subject: [PATCH 113/467] simplify and add more constraints in integration test --- .../staking/stake/simpleStake_test.go | 21 ++--- .../staking/stake/stakeAndUnStake_test.go | 90 +++++++++++-------- 2 files changed, 62 insertions(+), 49 deletions(-) diff --git a/integrationTests/chainSimulator/staking/stake/simpleStake_test.go b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go index a4f63e44f28..9685ce78cc6 100644 --- a/integrationTests/chainSimulator/staking/stake/simpleStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go @@ -9,6 +9,8 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/data/transaction" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" @@ -17,7 +19,6 @@ import ( "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/vm" - "github.com/stretchr/testify/require" ) // Test scenarios @@ -261,30 +262,30 @@ func TestChainSimulator_StakingV4Step2APICalls(t *testing.T) { err = cs.GenerateBlocks(2) require.Nil(t, err) - numQualified, numUnQualified := getNumQualifiedAndUnqualified(t, metachainNode) - require.Equal(t, 8, numQualified) - require.Equal(t, 1, numUnQualified) + qualified, unQualified := getQualifiedAndUnqualifiedNodes(t, metachainNode) + require.Equal(t, 8, len(qualified)) + require.Equal(t, 1, len(unQualified)) } } -func getNumQualifiedAndUnqualified(t *testing.T, metachainNode process.NodeHandler) (int, int) { +func getQualifiedAndUnqualifiedNodes(t *testing.T, metachainNode process.NodeHandler) ([]string, []string) { err := metachainNode.GetProcessComponents().ValidatorsProvider().ForceUpdate() require.Nil(t, err) auctionList, err := metachainNode.GetProcessComponents().ValidatorsProvider().GetAuctionList() require.Nil(t, err) - numQualified := 0 - numUnQualified := 0 + qualified := make([]string, 0) + unQualified := make([]string, 0) for _, auctionOwnerData := range auctionList { for _, auctionNode := range auctionOwnerData.Nodes { if auctionNode.Qualified { - numQualified++ + qualified = append(qualified, auctionNode.BlsKey) } else { - numUnQualified++ + unQualified = append(unQualified, auctionNode.BlsKey) } } } - return numQualified, numUnQualified + return qualified, unQualified } diff --git a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index d876545a124..a46d800fe82 100644 --- a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go @@ -2367,21 +2367,21 @@ func TestChainSimulator_UnStakeOneActiveNodeAndCheckAPIAuctionList(t *testing.T) metachainNode := cs.GetNodeHandler(core.MetachainShardId) - numQualified, numUnQualified := getNumQualifiedAndUnqualified(t, metachainNode) - require.Equal(t, 8, numQualified) - require.Equal(t, 0, numUnQualified) + qualified, unQualified := getQualifiedAndUnqualifiedNodes(t, metachainNode) + require.Equal(t, 8, len(qualified)) + require.Equal(t, 0, len(unQualified)) stakeOneNode(t, cs) - numQualified, numUnQualified = getNumQualifiedAndUnqualified(t, metachainNode) - require.Equal(t, 8, numQualified) - require.Equal(t, 1, numUnQualified) + qualified, unQualified = getQualifiedAndUnqualifiedNodes(t, metachainNode) + require.Equal(t, 8, len(qualified)) + require.Equal(t, 1, len(unQualified)) unStakeOneActiveNode(t, cs) - numQualified, numUnQualified = getNumQualifiedAndUnqualified(t, metachainNode) - require.Equal(t, 8, numQualified) - require.Equal(t, 1, numUnQualified) + qualified, unQualified = getQualifiedAndUnqualifiedNodes(t, metachainNode) + require.Equal(t, 8, len(qualified)) + require.Equal(t, 1, len(unQualified)) } // Nodes configuration at genesis consisting of a total of 40 nodes, distributed on 3 shards + meta: @@ -2445,58 +2445,75 @@ func TestChainSimulator_EdgeCaseLowWaitingList(t *testing.T) { require.Nil(t, err) metachainNode := cs.GetNodeHandler(core.MetachainShardId) - numQualified, numUnQualified := getNumQualifiedAndUnqualified(t, metachainNode) - require.Equal(t, 0, numQualified) - require.Equal(t, 0, numUnQualified) + qualified, unQualified := getQualifiedAndUnqualifiedNodes(t, metachainNode) + require.Equal(t, 0, len(qualified)) + require.Equal(t, 0, len(unQualified)) // we always have 0 in auction list because of the lowWaitingList condition epochToCheck += 1 err = cs.GenerateBlocksUntilEpochIsReached(epochToCheck) require.Nil(t, err) - numQualified, numUnQualified = getNumQualifiedAndUnqualified(t, metachainNode) - require.Equal(t, 0, numQualified) - require.Equal(t, 0, numUnQualified) + qualified, unQualified = getQualifiedAndUnqualifiedNodes(t, metachainNode) + require.Equal(t, 0, len(qualified)) + require.Equal(t, 0, len(unQualified)) // stake 16 mode nodes, these will go to auction list - stakeNodes(t, cs, 16) + stakeNodes(t, cs, 17) epochToCheck += 1 err = cs.GenerateBlocksUntilEpochIsReached(epochToCheck) require.Nil(t, err) - numQualified, numUnQualified = getNumQualifiedAndUnqualified(t, metachainNode) + qualified, unQualified = getQualifiedAndUnqualifiedNodes(t, metachainNode) // all the previously registered will be selected, as we have 24 nodes in eligible+waiting, 8 will shuffle out, // but this time there will be not be lowWaitingList, as there are enough in auction, so we will end up with // 24-8 = 16 nodes remaining + 16 from auction, to fill up all 32 positions - require.Equal(t, 16, numQualified) - require.Equal(t, 0, numUnQualified) -} + require.Equal(t, 16, len(qualified)) + require.Equal(t, 1, len(unQualified)) -func stakeNodes(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, numTxs int) { - txs := make([]*transaction.Transaction, numTxs) - for i := 0; i < numTxs; i++ { - privateKey, blsKeys, err := chainSimulator.GenerateBlsPrivateKeys(1) - require.Nil(t, err) - err = cs.AddValidatorKeys(privateKey) - require.Nil(t, err) + shuffledOutNodesKeys, err := metachainNode.GetProcessComponents().NodesCoordinator().GetShuffledOutToAuctionValidatorsPublicKeys(uint32(epochToCheck)) + require.Nil(t, err) - mintValue := big.NewInt(0).Add(staking.MinimumStakeValue, staking.OneEGLD) - validatorOwner, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) - require.Nil(t, err) + checkKeysNotInMap(t, shuffledOutNodesKeys, qualified) + checkKeysNotInMap(t, shuffledOutNodesKeys, unQualified) +} - txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txs[i] = staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) +func checkKeysNotInMap(t *testing.T, m map[uint32][][]byte, keys []string) { + for _, key := range keys { + for _, v := range m { + for _, k := range v { + mapKey := hex.EncodeToString(k) + require.NotEqual(t, key, mapKey) + } + } + } +} + +func stakeNodes(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, numNodesToStake int) { + txs := make([]*transaction.Transaction, numNodesToStake) + for i := 0; i < numNodesToStake; i++ { + txs[i] = createStakeTransaction(t, cs) } + stakeTxs, err := cs.SendTxsAndGenerateBlocksTilAreExecuted(txs, staking.MaxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, stakeTxs) - require.Len(t, stakeTxs, numTxs) + require.Len(t, stakeTxs, numNodesToStake) require.Nil(t, cs.GenerateBlocks(1)) } func stakeOneNode(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator) { + txStake := createStakeTransaction(t, cs) + stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, stakeTx) + + require.Nil(t, cs.GenerateBlocks(1)) +} + +func createStakeTransaction(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator) *transaction.Transaction { privateKey, blsKeys, err := chainSimulator.GenerateBlsPrivateKeys(1) require.Nil(t, err) err = cs.AddValidatorKeys(privateKey) @@ -2507,12 +2524,7 @@ func stakeOneNode(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator require.Nil(t, err) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) - txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) - stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, stakeTx) - - require.Nil(t, cs.GenerateBlocks(1)) + return staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) } func unStakeOneActiveNode(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator) { From 637df8da91fe4fa9184467285f6558df78060660 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 15 May 2024 18:15:00 +0300 Subject: [PATCH 114/467] 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 115/467] 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 116/467] 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 117/467] 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 118/467] 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 119/467] 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 120/467] 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 121/467] added missing file --- .../chainSimulator/relayedTx/testData/adder.wasm | Bin 0 -> 695 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 integrationTests/chainSimulator/relayedTx/testData/adder.wasm diff --git a/integrationTests/chainSimulator/relayedTx/testData/adder.wasm b/integrationTests/chainSimulator/relayedTx/testData/adder.wasm new file mode 100644 index 0000000000000000000000000000000000000000..b6bc9b4e13b3123daeafd40369383a54197cd160 GIT binary patch literal 695 zcmZuvO>dh(5S`g2n6M3OVyl&-9;i?4DYu@Br8=$P-~y=D)`C zb$XLm*RuMVm+Lf_NvP5~lX(Ty@O~<*yE;39C7?l>k&5kir3%&QF0yI8TuSv&6-uP? zwh##rBmK}5KZYpEMBu**mPi2KSDg$*fR20+zO` z;M~>=dZ;tFphBArorTzLr(&^z(V%`zl}IF%VBkiJL z5+Fa(aX`3z$%Y*W;j_-BeDErCLgZ(heFDz4iO)RXj&A9UbMEm|79eeU1#&(i+?(jC t+S(0BtEYgBUFl|ZTkPX+Rpe=q*V$aEpjZZ?|E0=OFUpL?te3;#@DIbRt0DjZ literal 0 HcmV?d00001 From f2efedd51dc4d2aac1ee9f4073876a8bfb7f604d Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Fri, 17 May 2024 13:22:38 +0300 Subject: [PATCH 122/467] add epoch enable flag for cleanup --- cmd/node/config/enableEpochs.toml | 4 + common/constants.go | 1 + common/enablers/enableEpochsHandler.go | 9 ++- common/enablers/enableEpochsHandler_test.go | 9 ++- config/epochConfig.go | 1 + config/tomlConfig_test.go | 9 ++- .../staking/stake/stakeAndUnStake_test.go | 1 + .../nodesCoordinator/hashValidatorShuffler.go | 74 ++++++++++--------- .../indexHashedNodesCoordinatorRegistry.go | 3 +- 9 files changed, 71 insertions(+), 40 deletions(-) diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index d24e57df7e7..9502cceba9a 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -302,6 +302,10 @@ # StakingV4Step3EnableEpoch represents the epoch in which selected nodes from auction will be distributed to waiting list StakingV4Step3EnableEpoch = 3 + # CleanupAuctionOnLowWaitingListEnableEpoch represents the epoch when duplicated data cleanup from auction list is enabled in the condition of a low waiting list + # Should have the same value as StakingV4Step1EnableEpoch if the low waiting list has not happened, otherwise should have a greater value + CleanupAuctionOnLowWaitingListEnableEpoch = 1 + # AlwaysMergeContextsInEEIEnableEpoch represents the epoch in which the EEI will always merge the contexts AlwaysMergeContextsInEEIEnableEpoch = 1 diff --git a/common/constants.go b/common/constants.go index 16c77a5d147..5320ee675c1 100644 --- a/common/constants.go +++ b/common/constants.go @@ -1011,6 +1011,7 @@ const ( StakingV4Step1Flag core.EnableEpochFlag = "StakingV4Step1Flag" StakingV4Step2Flag core.EnableEpochFlag = "StakingV4Step2Flag" StakingV4Step3Flag core.EnableEpochFlag = "StakingV4Step3Flag" + CleanupAuctionOnLowWaitingListFlag core.EnableEpochFlag = "CleanupAuctionOnLowWaitingListFlag" StakingV4StartedFlag core.EnableEpochFlag = "StakingV4StartedFlag" AlwaysMergeContextsInEEIFlag core.EnableEpochFlag = "AlwaysMergeContextsInEEIFlag" // all new flags must be added to createAllFlagsMap method, as part of enableEpochsHandler allFlagsDefined diff --git a/common/enablers/enableEpochsHandler.go b/common/enablers/enableEpochsHandler.go index f64dbf99ea5..5ce3812742f 100644 --- a/common/enablers/enableEpochsHandler.go +++ b/common/enablers/enableEpochsHandler.go @@ -6,10 +6,11 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/process" - logger "github.com/multiversx/mx-chain-logger-go" ) var log = logger.GetOrCreate("common/enablers") @@ -713,6 +714,12 @@ func (handler *enableEpochsHandler) createAllFlagsMap() { }, activationEpoch: handler.enableEpochsConfig.StakingV4Step3EnableEpoch, }, + common.CleanupAuctionOnLowWaitingListFlag: { + isActiveInEpoch: func(epoch uint32) bool { + return epoch >= handler.enableEpochsConfig.CleanupAuctionOnLowWaitingListEnableEpoch + }, + activationEpoch: handler.enableEpochsConfig.CleanupAuctionOnLowWaitingListEnableEpoch, + }, common.StakingV4StartedFlag: { isActiveInEpoch: func(epoch uint32) bool { return epoch >= handler.enableEpochsConfig.StakingV4Step1EnableEpoch diff --git a/common/enablers/enableEpochsHandler_test.go b/common/enablers/enableEpochsHandler_test.go index 4155b15dfbb..2c568f2043b 100644 --- a/common/enablers/enableEpochsHandler_test.go +++ b/common/enablers/enableEpochsHandler_test.go @@ -5,13 +5,14 @@ import ( "testing" "github.com/multiversx/mx-chain-core-go/core/check" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/testscommon/epochNotifier" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func createEnableEpochsConfig() config.EnableEpochs { @@ -113,6 +114,7 @@ func createEnableEpochsConfig() config.EnableEpochs { StakingV4Step1EnableEpoch: 96, StakingV4Step2EnableEpoch: 97, StakingV4Step3EnableEpoch: 98, + CleanupAuctionOnLowWaitingListEnableEpoch: 96, AlwaysMergeContextsInEEIEnableEpoch: 99, } } @@ -426,6 +428,7 @@ func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) { require.Equal(t, cfg.StakingV4Step1EnableEpoch, handler.GetActivationEpoch(common.StakingV4Step1Flag)) require.Equal(t, cfg.StakingV4Step2EnableEpoch, handler.GetActivationEpoch(common.StakingV4Step2Flag)) require.Equal(t, cfg.StakingV4Step3EnableEpoch, handler.GetActivationEpoch(common.StakingV4Step3Flag)) + require.Equal(t, cfg.CleanupAuctionOnLowWaitingListEnableEpoch, handler.GetActivationEpoch(common.CleanupAuctionOnLowWaitingListFlag)) require.Equal(t, cfg.StakingV4Step1EnableEpoch, handler.GetActivationEpoch(common.StakingV4StartedFlag)) require.Equal(t, cfg.AlwaysMergeContextsInEEIEnableEpoch, handler.GetActivationEpoch(common.AlwaysMergeContextsInEEIFlag)) } diff --git a/config/epochConfig.go b/config/epochConfig.go index 7789ecc72b3..764970ae050 100644 --- a/config/epochConfig.go +++ b/config/epochConfig.go @@ -112,6 +112,7 @@ type EnableEpochs struct { StakingV4Step1EnableEpoch uint32 StakingV4Step2EnableEpoch uint32 StakingV4Step3EnableEpoch uint32 + CleanupAuctionOnLowWaitingListEnableEpoch uint32 AlwaysMergeContextsInEEIEnableEpoch uint32 BLSMultiSignerEnableEpoch []MultiSignerConfig } diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index 45dd2c7ef00..84d0a7ecb57 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -5,10 +5,11 @@ import ( "strconv" "testing" - p2pConfig "github.com/multiversx/mx-chain-go/p2p/config" "github.com/pelletier/go-toml" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + p2pConfig "github.com/multiversx/mx-chain-go/p2p/config" ) func TestTomlParser(t *testing.T) { @@ -839,10 +840,13 @@ func TestEnableEpochConfig(t *testing.T) { # CurrentRandomnessOnSortingEnableEpoch represents the epoch when the current randomness on sorting is enabled CurrentRandomnessOnSortingEnableEpoch = 93 - + # AlwaysMergeContextsInEEIEnableEpoch represents the epoch in which the EEI will always merge the contexts AlwaysMergeContextsInEEIEnableEpoch = 94 + # CleanupAuctionOnLowWaitingListEnableEpoch represents the epoch when the cleanup auction on low waiting list is enabled + CleanupAuctionOnLowWaitingListEnableEpoch = 95 + # MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MaxNodesChangeEnableEpoch = [ { EpochEnable = 44, MaxNumNodes = 2169, NodesToShufflePerShard = 80 }, @@ -955,6 +959,7 @@ func TestEnableEpochConfig(t *testing.T) { MigrateDataTrieEnableEpoch: 92, CurrentRandomnessOnSortingEnableEpoch: 93, AlwaysMergeContextsInEEIEnableEpoch: 94, + CleanupAuctionOnLowWaitingListEnableEpoch: 95, MaxNodesChangeEnableEpoch: []MaxNodesChangeConfig{ { EpochEnable: 44, diff --git a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index a46d800fe82..b3a1f1b7d4f 100644 --- a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go @@ -2348,6 +2348,7 @@ func TestChainSimulator_UnStakeOneActiveNodeAndCheckAPIAuctionList(t *testing.T) cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = stakingV4Step1Epoch cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = stakingV4Step2Epoch cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = stakingV4Step3Epoch + cfg.EpochConfig.EnableEpochs.CleanupAuctionOnLowWaitingListEnableEpoch = stakingV4Step1Epoch cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[1].MaxNumNodes = 32 cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[1].NodesToShufflePerShard = 2 diff --git a/sharding/nodesCoordinator/hashValidatorShuffler.go b/sharding/nodesCoordinator/hashValidatorShuffler.go index 7c54e132ffc..71d2b5351b3 100644 --- a/sharding/nodesCoordinator/hashValidatorShuffler.go +++ b/sharding/nodesCoordinator/hashValidatorShuffler.go @@ -31,22 +31,23 @@ type NodesShufflerArgs struct { } type shuffleNodesArg struct { - eligible map[uint32][]Validator - waiting map[uint32][]Validator - unstakeLeaving []Validator - additionalLeaving []Validator - newNodes []Validator - auction []Validator - randomness []byte - distributor ValidatorsDistributor - nodesMeta uint32 - nodesPerShard uint32 - nbShards uint32 - maxNodesToSwapPerShard uint32 - maxNumNodes uint32 - flagBalanceWaitingLists bool - flagStakingV4Step2 bool - flagStakingV4Step3 bool + eligible map[uint32][]Validator + waiting map[uint32][]Validator + unstakeLeaving []Validator + additionalLeaving []Validator + newNodes []Validator + auction []Validator + randomness []byte + distributor ValidatorsDistributor + nodesMeta uint32 + nodesPerShard uint32 + nbShards uint32 + maxNodesToSwapPerShard uint32 + maxNumNodes uint32 + flagBalanceWaitingLists bool + flagStakingV4Step2 bool + flagStakingV4Step3 bool + flagCleanupAuctionOnLowWaitingList bool } type shuffledNodesConfig struct { @@ -91,6 +92,7 @@ func NewHashValidatorsShuffler(args *NodesShufflerArgs) (*randHashShuffler, erro } err := core.CheckHandlerCompatibility(args.EnableEpochsHandler, []core.EnableEpochFlag{ common.BalanceWaitingListsFlag, + common.CleanupAuctionOnLowWaitingListFlag, }) if err != nil { return nil, err @@ -197,22 +199,23 @@ func (rhs *randHashShuffler) UpdateNodeLists(args ArgsUpdateNodes) (*ResUpdateNo } return shuffleNodes(shuffleNodesArg{ - eligible: eligibleAfterReshard, - waiting: waitingAfterReshard, - unstakeLeaving: args.UnStakeLeaving, - additionalLeaving: args.AdditionalLeaving, - newNodes: args.NewNodes, - auction: args.Auction, - randomness: args.Rand, - nodesMeta: nodesMeta, - nodesPerShard: nodesPerShard, - nbShards: args.NbShards, - distributor: rhs.validatorDistributor, - maxNodesToSwapPerShard: rhs.activeNodesConfig.NodesToShufflePerShard, - flagBalanceWaitingLists: rhs.enableEpochsHandler.IsFlagEnabledInEpoch(common.BalanceWaitingListsFlag, args.Epoch), - flagStakingV4Step2: rhs.flagStakingV4Step2.IsSet(), - flagStakingV4Step3: rhs.flagStakingV4Step3.IsSet(), - maxNumNodes: rhs.activeNodesConfig.MaxNumNodes, + eligible: eligibleAfterReshard, + waiting: waitingAfterReshard, + unstakeLeaving: args.UnStakeLeaving, + additionalLeaving: args.AdditionalLeaving, + newNodes: args.NewNodes, + auction: args.Auction, + randomness: args.Rand, + nodesMeta: nodesMeta, + nodesPerShard: nodesPerShard, + nbShards: args.NbShards, + distributor: rhs.validatorDistributor, + maxNodesToSwapPerShard: rhs.activeNodesConfig.NodesToShufflePerShard, + flagBalanceWaitingLists: rhs.enableEpochsHandler.IsFlagEnabledInEpoch(common.BalanceWaitingListsFlag, args.Epoch), + flagStakingV4Step2: rhs.flagStakingV4Step2.IsSet(), + flagStakingV4Step3: rhs.flagStakingV4Step3.IsSet(), + maxNumNodes: rhs.activeNodesConfig.MaxNumNodes, + flagCleanupAuctionOnLowWaitingList: rhs.enableEpochsHandler.IsFlagEnabledInEpoch(common.CleanupAuctionOnLowWaitingListFlag, args.Epoch), }) } @@ -345,13 +348,18 @@ func shuffleNodes(arg shuffleNodesArg) (*ResUpdateNodes, error) { actualLeaving, _ := removeValidatorsFromList(allLeaving, stillRemainingInLeaving, len(stillRemainingInLeaving)) + shouldCleanupAuction := false + if arg.flagCleanupAuctionOnLowWaitingList { + shouldCleanupAuction = lowWaitingList + } + return &ResUpdateNodes{ Eligible: newEligible, Waiting: newWaiting, ShuffledOut: shuffledOutMap, Leaving: actualLeaving, StillRemaining: stillRemainingInLeaving, - LowWaitingList: lowWaitingList, + LowWaitingList: shouldCleanupAuction, }, nil } diff --git a/sharding/nodesCoordinator/indexHashedNodesCoordinatorRegistry.go b/sharding/nodesCoordinator/indexHashedNodesCoordinatorRegistry.go index 813929bac90..55cbb326753 100644 --- a/sharding/nodesCoordinator/indexHashedNodesCoordinatorRegistry.go +++ b/sharding/nodesCoordinator/indexHashedNodesCoordinatorRegistry.go @@ -61,7 +61,7 @@ func displayNodesConfigInfo(config map[uint32]*epochNodesConfig) { func (ihnc *indexHashedNodesCoordinator) saveState(key []byte, epoch uint32) error { registry := ihnc.NodesCoordinatorToRegistry(epoch) - data, err := ihnc.nodesCoordinatorRegistryFactory.GetRegistryData(registry, ihnc.currentEpoch) + data, err := ihnc.nodesCoordinatorRegistryFactory.GetRegistryData(registry, epoch) if err != nil { return err } @@ -212,6 +212,7 @@ func epochValidatorsToEpochNodesConfig(config EpochValidatorsHandler) (*epochNod if err != nil { return nil, err } + result.lowWaitingList = configWithAuction.GetLowWaitingList() } return result, nil From 1dd6e0755e3d063447980f2e61d41d28c83ff34e Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Fri, 17 May 2024 13:23:02 +0300 Subject: [PATCH 123/467] fix restore from registry --- ...ndexHashedNodesCoordinatorRegistry_test.go | 34 +++++++++++++++++-- sharding/nodesCoordinator/interface.go | 1 + .../nodesCoordinatorRegistryFactory.go | 2 +- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/sharding/nodesCoordinator/indexHashedNodesCoordinatorRegistry_test.go b/sharding/nodesCoordinator/indexHashedNodesCoordinatorRegistry_test.go index b2b99e6e87b..0a91ba9170a 100644 --- a/sharding/nodesCoordinator/indexHashedNodesCoordinatorRegistry_test.go +++ b/sharding/nodesCoordinator/indexHashedNodesCoordinatorRegistry_test.go @@ -7,10 +7,11 @@ import ( "testing" "github.com/multiversx/mx-chain-core-go/core" - "github.com/multiversx/mx-chain-go/common" - "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + + "github.com/multiversx/mx-chain-go/common" + "github.com/multiversx/mx-chain-go/testscommon/enableEpochsHandlerMock" ) func sameValidatorsMaps(map1, map2 map[uint32][]Validator) bool { @@ -174,6 +175,35 @@ func TestIndexHashedNodesCoordinator_nodesCoordinatorToRegistry(t *testing.T) { } } +func TestIndexHashedNodesCoordinator_nodesCoordinatorWithAuctionToRegistryAndBack(t *testing.T) { + args := createArguments() + nodesCoordinator, _ := NewIndexHashedNodesCoordinator(args) + + nodesConfigForEpoch := nodesCoordinator.nodesConfig[args.Epoch] + nodesConfigForEpoch.shuffledOutMap = createDummyNodesMap(3, 0, string(common.WaitingList)) + nodesConfigForEpoch.lowWaitingList = true + // leave only one epoch config in nc + nodesCoordinator.nodesConfig = make(map[uint32]*epochNodesConfig) + nodesCoordinator.nodesConfig[args.Epoch] = nodesConfigForEpoch + + ncr := nodesCoordinator.nodesCoordinatorToRegistryWithAuction() + require.True(t, sameValidatorsDifferentMapTypes(nodesConfigForEpoch.eligibleMap, ncr.GetEpochsConfig()[fmt.Sprint(args.Epoch)].GetEligibleValidators())) + require.True(t, sameValidatorsDifferentMapTypes(nodesConfigForEpoch.waitingMap, ncr.GetEpochsConfig()[fmt.Sprint(args.Epoch)].GetWaitingValidators())) + require.True(t, sameValidatorsDifferentMapTypes(nodesConfigForEpoch.shuffledOutMap, ncr.GetEpochsConfigWithAuction()[fmt.Sprint(args.Epoch)].GetShuffledOutValidators())) + require.Equal(t, nodesConfigForEpoch.lowWaitingList, ncr.GetEpochsConfigWithAuction()[fmt.Sprint(args.Epoch)].GetLowWaitingList()) + + nodesConfig, err := nodesCoordinator.registryToNodesCoordinator(ncr) + require.Nil(t, err) + + assert.Equal(t, len(nodesCoordinator.nodesConfig), len(nodesConfig)) + for epoch, config := range nodesCoordinator.nodesConfig { + require.True(t, sameValidatorsMaps(config.eligibleMap, nodesConfig[epoch].eligibleMap)) + require.True(t, sameValidatorsMaps(config.waitingMap, nodesConfig[epoch].waitingMap)) + require.True(t, sameValidatorsMaps(config.shuffledOutMap, nodesConfig[epoch].shuffledOutMap)) + require.Equal(t, config.lowWaitingList, nodesConfig[epoch].lowWaitingList) + } +} + func TestIndexHashedNodesCoordinator_registryToNodesCoordinator(t *testing.T) { args := createArguments() nodesCoordinator1, _ := NewIndexHashedNodesCoordinator(args) diff --git a/sharding/nodesCoordinator/interface.go b/sharding/nodesCoordinator/interface.go index b962c6fa50a..5e2d5564a5c 100644 --- a/sharding/nodesCoordinator/interface.go +++ b/sharding/nodesCoordinator/interface.go @@ -154,6 +154,7 @@ type EpochValidatorsHandler interface { type EpochValidatorsHandlerWithAuction interface { EpochValidatorsHandler GetShuffledOutValidators() map[string][]*SerializableValidator + GetLowWaitingList() bool } // NodesCoordinatorRegistryHandler defines what is used to initialize nodes coordinator diff --git a/sharding/nodesCoordinator/nodesCoordinatorRegistryFactory.go b/sharding/nodesCoordinator/nodesCoordinatorRegistryFactory.go index 0ef508fbf89..894d3f7a1f0 100644 --- a/sharding/nodesCoordinator/nodesCoordinatorRegistryFactory.go +++ b/sharding/nodesCoordinator/nodesCoordinatorRegistryFactory.go @@ -49,7 +49,7 @@ func (ncf *nodesCoordinatorRegistryFactory) createRegistryWithAuction(buff []byt return nil, err } - log.Debug("nodesCoordinatorRegistryFactory.CreateNodesCoordinatorRegistry created old registry", + log.Debug("nodesCoordinatorRegistryFactory.CreateNodesCoordinatorRegistry created registry with auction", "epoch", registry.CurrentEpoch) return registry, nil } From 8968d5cfaf04fe8883ecd86b268beaa1f03ba103 Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Fri, 17 May 2024 14:18:19 +0300 Subject: [PATCH 124/467] fix alignment --- config/tomlConfig_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index 84d0a7ecb57..eaeb4e6e2ae 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -840,12 +840,12 @@ func TestEnableEpochConfig(t *testing.T) { # CurrentRandomnessOnSortingEnableEpoch represents the epoch when the current randomness on sorting is enabled CurrentRandomnessOnSortingEnableEpoch = 93 - + # AlwaysMergeContextsInEEIEnableEpoch represents the epoch in which the EEI will always merge the contexts AlwaysMergeContextsInEEIEnableEpoch = 94 - # CleanupAuctionOnLowWaitingListEnableEpoch represents the epoch when the cleanup auction on low waiting list is enabled - CleanupAuctionOnLowWaitingListEnableEpoch = 95 + # CleanupAuctionOnLowWaitingListEnableEpoch represents the epoch when the cleanup auction on low waiting list is enabled + CleanupAuctionOnLowWaitingListEnableEpoch = 95 # MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MaxNodesChangeEnableEpoch = [ From 1786b4fa335070d03fdaef801e099a8f7dc3a531 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 20 May 2024 11:00:40 +0300 Subject: [PATCH 125/467] - 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 126/467] 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 127/467] - 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 128/467] 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 129/467] add activation flag for unjail cleanup backwards compatibility --- cmd/node/config/enableEpochs.toml | 3 +++ common/constants.go | 1 + common/enablers/enableEpochsHandler.go | 9 ++++++++- config/epochConfig.go | 1 + process/scToProtocol/stakingToPeer.go | 5 ++++- 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index 657d365fdc9..b5ece669247 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -314,6 +314,9 @@ # CryptoOpcodesV2EnableEpoch represents the epoch when BLSMultiSig, Secp256r1 and other opcodes are enabled CryptoOpcodesV2EnableEpoch = 4 + # UnjailCleanupEnableEpoch represents the epoch when the cleanup of the unjailed nodes is enabled + UnJailCleanupEnableEpoch = 4 + # BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers BLSMultiSignerEnableEpoch = [ { EnableEpoch = 0, Type = "no-KOSK" }, diff --git a/common/constants.go b/common/constants.go index 13fedb7e0bd..53f6d461412 100644 --- a/common/constants.go +++ b/common/constants.go @@ -1016,5 +1016,6 @@ const ( DynamicESDTFlag core.EnableEpochFlag = "DynamicEsdtFlag" EGLDInESDTMultiTransferFlag core.EnableEpochFlag = "EGLDInESDTMultiTransferFlag" CryptoOpcodesV2Flag core.EnableEpochFlag = "CryptoOpcodesV2Flag" + UnJailCleanupFlag core.EnableEpochFlag = "UnJailCleanupFlag" // all new flags must be added to createAllFlagsMap method, as part of enableEpochsHandler allFlagsDefined ) diff --git a/common/enablers/enableEpochsHandler.go b/common/enablers/enableEpochsHandler.go index efe8b4f304d..5313fb90972 100644 --- a/common/enablers/enableEpochsHandler.go +++ b/common/enablers/enableEpochsHandler.go @@ -6,10 +6,11 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" + logger "github.com/multiversx/mx-chain-logger-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/process" - logger "github.com/multiversx/mx-chain-logger-go" ) var log = logger.GetOrCreate("common/enablers") @@ -743,6 +744,12 @@ func (handler *enableEpochsHandler) createAllFlagsMap() { }, activationEpoch: handler.enableEpochsConfig.CryptoOpcodesV2EnableEpoch, }, + common.UnJailCleanupFlag: { + isActiveInEpoch: func(epoch uint32) bool { + return epoch >= handler.enableEpochsConfig.UnJailCleanupEnableEpoch + }, + activationEpoch: handler.enableEpochsConfig.UnJailCleanupEnableEpoch, + }, } } diff --git a/config/epochConfig.go b/config/epochConfig.go index 5f5f4ff7a0e..62191f0fe82 100644 --- a/config/epochConfig.go +++ b/config/epochConfig.go @@ -116,6 +116,7 @@ type EnableEpochs struct { DynamicESDTEnableEpoch uint32 EGLDInMultiTransferEnableEpoch uint32 CryptoOpcodesV2EnableEpoch uint32 + UnJailCleanupEnableEpoch uint32 BLSMultiSignerEnableEpoch []MultiSignerConfig } diff --git a/process/scToProtocol/stakingToPeer.go b/process/scToProtocol/stakingToPeer.go index b0a0d973786..363a7975a7a 100644 --- a/process/scToProtocol/stakingToPeer.go +++ b/process/scToProtocol/stakingToPeer.go @@ -110,6 +110,7 @@ func checkIfNil(args ArgStakingToPeer) error { return core.CheckHandlerCompatibility(args.EnableEpochsHandler, []core.EnableEpochFlag{ common.StakeFlag, common.ValidatorToDelegationFlag, + common.UnJailCleanupFlag, }) } @@ -342,7 +343,9 @@ func (stp *stakingToPeer) updatePeerState( if account.GetTempRating() < stp.unJailRating { log.Debug("node is unJailed, setting temp rating to start rating", "blsKey", blsPubKey) account.SetTempRating(stp.unJailRating) - account.SetConsecutiveProposerMisses(0) + if stp.enableEpochsHandler.IsFlagEnabled(common.UnJailCleanupFlag) { + account.SetConsecutiveProposerMisses(0) + } } isNewValidator := !isValidator && stakingData.Staked From b8674cadc6d3bfefcc30a11ec28842044cab4fdd Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Tue, 21 May 2024 16:21:06 +0300 Subject: [PATCH 130/467] add system vm critical section --- vm/process/systemVM.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vm/process/systemVM.go b/vm/process/systemVM.go index 6a3452304fa..90228e4adaa 100644 --- a/vm/process/systemVM.go +++ b/vm/process/systemVM.go @@ -6,9 +6,10 @@ import ( "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" + vmcommon "github.com/multiversx/mx-chain-vm-common-go" + "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/vm" - vmcommon "github.com/multiversx/mx-chain-vm-common-go" ) type systemVM struct { @@ -18,6 +19,7 @@ type systemVM struct { asyncCallbackGasLock uint64 asyncCallStepCost uint64 mutGasLock sync.RWMutex + criticalSection sync.Mutex } // ArgsNewSystemVM defines the needed arguments to create a new system vm @@ -101,6 +103,9 @@ func (s *systemVM) RunSmartContractCreate(input *vmcommon.ContractCreateInput) ( // RunSmartContractCall executes a smart contract according to the input func (s *systemVM) RunSmartContractCall(input *vmcommon.ContractCallInput) (*vmcommon.VMOutput, error) { + s.criticalSection.Lock() + defer s.criticalSection.Unlock() + s.systemEI.CleanCache() s.systemEI.SetSCAddress(input.RecipientAddr) s.systemEI.AddTxValueToSmartContract(input.CallValue, input.RecipientAddr) From 8369e8d613d01c47dbf60f3042db61f0a35bcf4d Mon Sep 17 00:00:00 2001 From: Adrian Dobrita Date: Tue, 21 May 2024 16:28:13 +0300 Subject: [PATCH 131/467] add system vm critical section also on contract create --- vm/process/systemVM.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vm/process/systemVM.go b/vm/process/systemVM.go index 90228e4adaa..ca0553cb714 100644 --- a/vm/process/systemVM.go +++ b/vm/process/systemVM.go @@ -70,6 +70,9 @@ func NewSystemVM(args ArgsNewSystemVM) (*systemVM, error) { // RunSmartContractCreate creates and saves a new smart contract to the trie func (s *systemVM) RunSmartContractCreate(input *vmcommon.ContractCreateInput) (*vmcommon.VMOutput, error) { + s.criticalSection.Lock() + defer s.criticalSection.Unlock() + if input == nil { return nil, vm.ErrInputArgsIsNil } From 8632cc58efe2d269e80f309e5ec2ab2d7a9e152b Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 21 May 2024 17:34:55 +0300 Subject: [PATCH 132/467] 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 133/467] update separate functions --- .../vm/esdtImprovements_test.go | 150 ++++++++++++------ 1 file changed, 102 insertions(+), 48 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index b79f9833d10..30ed395ad92 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -12,6 +12,7 @@ import ( "github.com/multiversx/mx-chain-core-go/data/esdt" "github.com/multiversx/mx-chain-core-go/data/transaction" "github.com/multiversx/mx-chain-go/config" + testsChainSimulator "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator" "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator/staking" "github.com/multiversx/mx-chain-go/node/chainSimulator" "github.com/multiversx/mx-chain-go/node/chainSimulator/components/api" @@ -85,42 +86,14 @@ func TestChainSimulator_CheckNFTMetadata(t *testing.T) { address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) require.Nil(t, err) - shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) - - // set account esdt roles - tokenID := []byte("ASD-d31313") - - roles := [][]byte{[]byte(core.ESDTMetaDataRecreate), []byte(core.ESDTRoleNFTCreate)} - rolesKey := append([]byte(core.ProtectedKeyPrefix), append([]byte(core.ESDTRoleIdentifier), []byte(core.ESDTKeyIdentifier)...)...) - rolesKey = append(rolesKey, tokenID...) - - rolesData := &esdt.ESDTRoles{ - Roles: roles, - } - - rolesDataBytes, err := cs.GetNodeHandler(shardID).GetCoreComponents().InternalMarshalizer().Marshal(rolesData) - require.Nil(t, err) - - keys := make(map[string]string) - keys[hex.EncodeToString(rolesKey)] = hex.EncodeToString(rolesDataBytes) - - err = cs.SetStateMultiple([]*dtos.AddressState{ - { - Address: address.Bech32, - Balance: "10000000000000000000000", - Keys: keys, - }, - }) - require.Nil(t, err) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch) - 1) require.Nil(t, err) - privateKey, _, err := chainSimulator.GenerateBlsPrivateKeys(1) - require.Nil(t, err) + log.Info("Initial setup: Create an NFT and an SFT (before the activation of DynamicEsdtFlag)") - err = cs.AddValidatorKeys(privateKey) - require.Nil(t, err) + tokenID := []byte("ASD-d31313") + + setAddressEsdtRoles(t, cs, address, tokenID) nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) name := []byte(hex.EncodeToString([]byte("name"))) @@ -128,6 +101,8 @@ func TestChainSimulator_CheckNFTMetadata(t *testing.T) { attributes := []byte(hex.EncodeToString([]byte("attributes"))) uris := []byte(hex.EncodeToString([]byte("uri"))) + expUris := [][]byte{[]byte(hex.EncodeToString([]byte("uri")))} + txDataField := bytes.Join( [][]byte{ []byte(core.BuiltInFunctionESDTNFTCreate), @@ -160,37 +135,116 @@ func TestChainSimulator_CheckNFTMetadata(t *testing.T) { require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - account, err := cs.GetNodeHandler(shardID).GetStateComponents().AccountsAdapter().LoadAccount(core.SystemAccountAddress) + err = cs.GenerateBlocks(10) + + shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) + + log.Info("Step 1. check that the metadata for nft and sfts are saved on the system account") + + retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenID, shardID) + + require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) + require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) + require.Equal(t, hash, []byte(hex.EncodeToString(retrievedMetaData.Hash))) + for i, uri := range expUris { + require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) + } + require.Equal(t, attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) + + log.Info("Step 2. wait for DynamicEsdtFlag activation") + + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) + require.Nil(t, err) + + log.Info("Step 3. transfer the NFT and the SFT to another account") + + nonceArg := hex.EncodeToString(big.NewInt(0).SetUint64(2).Bytes()) + quantityToTransfer := int64(1) + quantityToTransferArg := hex.EncodeToString(big.NewInt(quantityToTransfer).Bytes()) + txDataField = []byte(core.BuiltInFunctionESDTNFTTransfer + "@" + hex.EncodeToString([]byte(tokenID)) + + "@" + nonceArg + "@" + quantityToTransferArg + "@" + hex.EncodeToString(address.Bytes)) + + tx = &transaction.Transaction{ + Nonce: 1, + SndAddr: address.Bytes, + RcvAddr: address.Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, staking.MaxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult) + + require.Equal(t, "success", txResult.Status.String()) +} + +func getMetaDataFromAcc( + t *testing.T, + cs testsChainSimulator.ChainSimulator, + addressBytes []byte, + token []byte, + shardID uint32, +) *esdt.MetaData { + account, err := cs.GetNodeHandler(shardID).GetStateComponents().AccountsAdapter().LoadAccount(addressBytes) require.Nil(t, err) userAccount, ok := account.(state.UserAccountHandler) require.True(t, ok) baseEsdtKeyPrefix := core.ProtectedKeyPrefix + core.ESDTKeyIdentifier - key := append([]byte(baseEsdtKeyPrefix), tokenID...) - - fmt.Println(userAccount) + key := append([]byte(baseEsdtKeyPrefix), token...) key2 := append(key, big.NewInt(0).SetUint64(1).Bytes()...) esdtDataBytes, _, err := userAccount.RetrieveValue(key2) require.Nil(t, err) - esdtData := &esdt.ESDigitalToken{} + esdtData := &esdt.ESDigitalToken{} err = cs.GetNodeHandler(shardID).GetCoreComponents().InternalMarshalizer().Unmarshal(esdtData, esdtDataBytes) require.Nil(t, err) - require.NotNil(t, esdtData.TokenMetaData) - fmt.Println(esdtData.TokenMetaData) - expUris := [][]byte{[]byte(hex.EncodeToString([]byte("uri")))} + return esdtData.TokenMetaData +} - retrievedMetaData := esdtData.TokenMetaData +func setAddressEsdtRoles( + t *testing.T, + cs testsChainSimulator.ChainSimulator, + address dtos.WalletAddress, + token []byte, +) { + marshaller := cs.GetNodeHandler(0).GetCoreComponents().InternalMarshalizer() + + roles := [][]byte{ + []byte(core.ESDTMetaDataRecreate), + []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleNFTBurn), + } + rolesKey := append([]byte(core.ProtectedKeyPrefix), append([]byte(core.ESDTRoleIdentifier), []byte(core.ESDTKeyIdentifier)...)...) + rolesKey = append(rolesKey, token...) - require.Equal(t, nonce, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Nonce)).Bytes()))) - require.Equal(t, name, []byte(hex.EncodeToString(retrievedMetaData.Name))) - // require.Equal(t, expectedMetaData.royalties, []byte(hex.EncodeToString(big.NewInt(int64(retrievedMetaData.Royalties)).Bytes()))) - require.Equal(t, hash, []byte(hex.EncodeToString(retrievedMetaData.Hash))) - for i, uri := range expUris { - require.Equal(t, uri, []byte(hex.EncodeToString(retrievedMetaData.URIs[i]))) + rolesData := &esdt.ESDTRoles{ + Roles: roles, } - require.Equal(t, attributes, []byte(hex.EncodeToString(retrievedMetaData.Attributes))) + + rolesDataBytes, err := marshaller.Marshal(rolesData) + require.Nil(t, err) + + keys := make(map[string]string) + keys[hex.EncodeToString(rolesKey)] = hex.EncodeToString(rolesDataBytes) + + err = cs.SetStateMultiple([]*dtos.AddressState{ + { + Address: address.Bech32, + Balance: "10000000000000000000000", + Keys: keys, + }, + }) + require.Nil(t, err) } From 3177a85df3360872d7e65944e6a3743fac54b16c Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 22 May 2024 00:36:09 +0300 Subject: [PATCH 134/467] copy validator status in epoch struct --- epochStart/metachain/stakingDataProvider.go | 19 +++++- .../metachain/stakingDataProvider_test.go | 64 ++++++++++++++++--- 2 files changed, 74 insertions(+), 9 deletions(-) diff --git a/epochStart/metachain/stakingDataProvider.go b/epochStart/metachain/stakingDataProvider.go index b655fbe1b16..aa0129a6f1a 100644 --- a/epochStart/metachain/stakingDataProvider.go +++ b/epochStart/metachain/stakingDataProvider.go @@ -580,7 +580,24 @@ func (sdp *stakingDataProvider) GetCurrentEpochValidatorStats() epochStart.Valid sdp.mutStakingData.RLock() defer sdp.mutStakingData.RUnlock() - return sdp.validatorStatsInEpoch + return copyValidatorStatsInEpoch(sdp.validatorStatsInEpoch) +} + +func copyValidatorStatsInEpoch(oldInstance epochStart.ValidatorStatsInEpoch) epochStart.ValidatorStatsInEpoch { + return epochStart.ValidatorStatsInEpoch{ + Eligible: copyMap(oldInstance.Eligible), + Waiting: copyMap(oldInstance.Waiting), + Leaving: copyMap(oldInstance.Leaving), + } +} + +func copyMap(oldMap map[uint32]int) map[uint32]int { + newMap := make(map[uint32]int, len(oldMap)) + for key, value := range oldMap { + newMap[key] = value + } + + return newMap } // IsInterfaceNil return true if underlying object is nil diff --git a/epochStart/metachain/stakingDataProvider_test.go b/epochStart/metachain/stakingDataProvider_test.go index e3bfc1e6259..e11bb45801e 100644 --- a/epochStart/metachain/stakingDataProvider_test.go +++ b/epochStart/metachain/stakingDataProvider_test.go @@ -7,6 +7,7 @@ import ( "fmt" "math/big" "strings" + "sync" "testing" "github.com/multiversx/mx-chain-core-go/core" @@ -465,16 +466,63 @@ func TestStakingDataProvider_PrepareStakingDataForRewards(t *testing.T) { func TestStakingDataProvider_FillValidatorInfo(t *testing.T) { t.Parallel() - owner := []byte("owner") - topUpVal := big.NewInt(828743) - basePrice := big.NewInt(100000) - stakeVal := big.NewInt(0).Add(topUpVal, basePrice) - numRunContractCalls := 0 + t.Run("should work", func(t *testing.T) { + t.Parallel() - sdp := createStakingDataProviderWithMockArgs(t, owner, topUpVal, stakeVal, &numRunContractCalls) + owner := []byte("owner") + topUpVal := big.NewInt(828743) + basePrice := big.NewInt(100000) + stakeVal := big.NewInt(0).Add(topUpVal, basePrice) + numRunContractCalls := 0 - err := sdp.FillValidatorInfo(&state.ValidatorInfo{PublicKey: []byte("bls key")}) - require.NoError(t, err) + sdp := createStakingDataProviderWithMockArgs(t, owner, topUpVal, stakeVal, &numRunContractCalls) + + err := sdp.FillValidatorInfo(&state.ValidatorInfo{PublicKey: []byte("bls key")}) + require.NoError(t, err) + }) + t.Run("concurrent calls should work", func(t *testing.T) { + t.Parallel() + + defer func() { + r := recover() + if r != nil { + require.Fail(t, "should have not panicked") + } + }() + + owner := []byte("owner") + topUpVal := big.NewInt(828743) + basePrice := big.NewInt(100000) + stakeVal := big.NewInt(0).Add(topUpVal, basePrice) + numRunContractCalls := 0 + + sdp := createStakingDataProviderWithMockArgs(t, owner, topUpVal, stakeVal, &numRunContractCalls) + + wg := sync.WaitGroup{} + numCalls := 100 + wg.Add(numCalls) + + for i := 0; i < numCalls; i++ { + go func(idx int) { + switch idx % 2 { + case 0: + err := sdp.FillValidatorInfo(&state.ValidatorInfo{ + PublicKey: []byte("bls key"), + List: string(common.EligibleList), + ShardId: 0, + }) + require.NoError(t, err) + case 1: + stats := sdp.GetCurrentEpochValidatorStats() + log.Info(fmt.Sprintf("%d", stats.Eligible[0])) + } + + wg.Done() + }(i) + } + + wg.Wait() + }) } func TestCheckAndFillOwnerValidatorAuctionData(t *testing.T) { From c9f1f93f1c2713331c8d7374027769bdef0cb6b7 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 22 May 2024 10:53:05 +0300 Subject: [PATCH 135/467] further test + mutex fix --- process/peer/validatorsProvider.go | 4 ++ process/peer/validatorsProviderAuction.go | 13 ++--- process/peer/validatorsProvider_test.go | 69 +++++++++++++++++++++++ 3 files changed, 78 insertions(+), 8 deletions(-) diff --git a/process/peer/validatorsProvider.go b/process/peer/validatorsProvider.go index 7c3b8505310..8caff26430a 100644 --- a/process/peer/validatorsProvider.go +++ b/process/peer/validatorsProvider.go @@ -320,6 +320,10 @@ func shouldCombine(triePeerType common.PeerType, currentPeerType common.PeerType // ForceUpdate will trigger the update process of all caches func (vp *validatorsProvider) ForceUpdate() error { vp.updateCache() + + vp.auctionMutex.Lock() + defer vp.auctionMutex.Unlock() + return vp.updateAuctionListCache() } diff --git a/process/peer/validatorsProviderAuction.go b/process/peer/validatorsProviderAuction.go index 144ace850fb..a31a89f97e8 100644 --- a/process/peer/validatorsProviderAuction.go +++ b/process/peer/validatorsProviderAuction.go @@ -27,9 +27,10 @@ func (vp *validatorsProvider) GetAuctionList() ([]*common.AuctionListValidatorAP } func (vp *validatorsProvider) updateAuctionListCacheIfNeeded() error { - vp.auctionMutex.RLock() + vp.auctionMutex.Lock() + defer vp.auctionMutex.Unlock() + shouldUpdate := time.Since(vp.lastAuctionCacheUpdate) > vp.cacheRefreshIntervalDuration - vp.auctionMutex.RUnlock() if shouldUpdate { return vp.updateAuctionListCache() @@ -38,6 +39,7 @@ func (vp *validatorsProvider) updateAuctionListCacheIfNeeded() error { return nil } +// this func should be called under mutex protection func (vp *validatorsProvider) updateAuctionListCache() error { rootHash := vp.validatorStatistics.LastFinalizedRootHash() if len(rootHash) == 0 { @@ -49,19 +51,15 @@ func (vp *validatorsProvider) updateAuctionListCache() error { return err } - vp.auctionMutex.Lock() vp.cachedRandomness = rootHash - vp.auctionMutex.Unlock() newCache, err := vp.createValidatorsAuctionCache(validatorsMap) if err != nil { return err } - vp.auctionMutex.Lock() vp.lastAuctionCacheUpdate = time.Now() vp.cachedAuctionValidators = newCache - vp.auctionMutex.Unlock() return nil } @@ -96,10 +94,9 @@ func (vp *validatorsProvider) fillAllValidatorsInfo(validatorsMap state.ShardVal return err } +// this func should be called under mutex protection func (vp *validatorsProvider) getSelectedNodesFromAuction(validatorsMap state.ShardValidatorsInfoMapHandler) ([]state.ValidatorInfoHandler, error) { - vp.auctionMutex.RLock() randomness := vp.cachedRandomness - vp.auctionMutex.RUnlock() err := vp.auctionListSelector.SelectNodesFromAuctionList(validatorsMap, randomness) if err != nil { diff --git a/process/peer/validatorsProvider_test.go b/process/peer/validatorsProvider_test.go index 931567a2435..8bb56753660 100644 --- a/process/peer/validatorsProvider_test.go +++ b/process/peer/validatorsProvider_test.go @@ -1044,6 +1044,75 @@ func TestValidatorsProvider_GetAuctionList(t *testing.T) { require.Equal(t, expectedList, list) }) + t.Run("concurrent calls should only update cache once", func(t *testing.T) { + t.Parallel() + + args := createDefaultValidatorsProviderArg() + + args.CacheRefreshIntervalDurationInSec = time.Second * 5 + + expectedRootHash := []byte("root hash") + ctRootHashCalled := uint32(0) + ctSelectNodesFromAuctionList := uint32(0) + ctFillValidatorInfoCalled := uint32(0) + ctGetOwnersDataCalled := uint32(0) + ctComputeUnqualifiedNodes := uint32(0) + + args.ValidatorStatistics = &testscommon.ValidatorStatisticsProcessorStub{ + LastFinalizedRootHashCalled: func() []byte { + atomic.AddUint32(&ctRootHashCalled, 1) + return expectedRootHash + }, + GetValidatorInfoForRootHashCalled: func(rootHash []byte) (state.ShardValidatorsInfoMapHandler, error) { + require.Equal(t, expectedRootHash, rootHash) + return state.NewShardValidatorsInfoMap(), nil + }, + } + args.AuctionListSelector = &stakingcommon.AuctionListSelectorStub{ + SelectNodesFromAuctionListCalled: func(validatorsInfoMap state.ShardValidatorsInfoMapHandler, randomness []byte) error { + atomic.AddUint32(&ctSelectNodesFromAuctionList, 1) + require.Equal(t, expectedRootHash, randomness) + return nil + }, + } + args.StakingDataProvider = &stakingcommon.StakingDataProviderStub{ + FillValidatorInfoCalled: func(validator state.ValidatorInfoHandler) error { + atomic.AddUint32(&ctFillValidatorInfoCalled, 1) + return nil + }, + GetOwnersDataCalled: func() map[string]*epochStart.OwnerData { + atomic.AddUint32(&ctGetOwnersDataCalled, 1) + return nil + }, + ComputeUnQualifiedNodesCalled: func(validatorInfos state.ShardValidatorsInfoMapHandler) ([][]byte, map[string][][]byte, error) { + atomic.AddUint32(&ctComputeUnqualifiedNodes, 1) + return nil, nil, nil + }, + } + vp, _ := NewValidatorsProvider(args) + time.Sleep(args.CacheRefreshIntervalDurationInSec) + + numCalls := 100 + wg := sync.WaitGroup{} + wg.Add(numCalls) + + for i := 0; i < numCalls; i++ { + go func() { + list, err := vp.GetAuctionList() + require.NoError(t, err) + require.Empty(t, list) + + wg.Done() + }() + } + + wg.Wait() + + require.LessOrEqual(t, ctRootHashCalled, uint32(2)) // another call might be from constructor in startRefreshProcess.updateCache + + require.NoError(t, vp.Close()) + }) + } func createMockValidatorInfo() *state.ValidatorInfo { From 3363e309a4f4a1ea42c1cfea9f42eaa1e88aae45 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 22 May 2024 11:07:55 +0300 Subject: [PATCH 136/467] further test + mutex fix for validatorsProvider as well --- process/peer/validatorsProvider.go | 15 +++++++------ process/peer/validatorsProvider_test.go | 28 ++++++++++++++++++------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/process/peer/validatorsProvider.go b/process/peer/validatorsProvider.go index 8caff26430a..a7aa60ea7f5 100644 --- a/process/peer/validatorsProvider.go +++ b/process/peer/validatorsProvider.go @@ -129,9 +129,10 @@ func (vp *validatorsProvider) GetLatestValidators() map[string]*validator.Valida } func (vp *validatorsProvider) updateCacheIfNeeded() { - vp.lock.RLock() + vp.lock.Lock() + defer vp.lock.Unlock() + shouldUpdate := time.Since(vp.lastCacheUpdate) > vp.cacheRefreshIntervalDuration - vp.lock.RUnlock() if shouldUpdate { vp.updateCache() @@ -192,7 +193,10 @@ func (vp *validatorsProvider) epochStartEventHandler() nodesCoordinator.EpochSta func (vp *validatorsProvider) startRefreshProcess(ctx context.Context) { for { + vp.lock.Lock() vp.updateCache() + vp.lock.Unlock() + select { case epoch := <-vp.refreshCache: vp.lock.Lock() @@ -206,6 +210,7 @@ func (vp *validatorsProvider) startRefreshProcess(ctx context.Context) { } } +// this func should be called under mutex protection func (vp *validatorsProvider) updateCache() { lastFinalizedRootHash := vp.validatorStatistics.LastFinalizedRootHash() if len(lastFinalizedRootHash) == 0 { @@ -217,16 +222,12 @@ func (vp *validatorsProvider) updateCache() { log.Trace("validatorsProvider - GetLatestValidatorInfos failed", "error", err) } - vp.lock.RLock() epoch := vp.currentEpoch - vp.lock.RUnlock() newCache := vp.createNewCache(epoch, allNodes) - vp.lock.Lock() vp.lastCacheUpdate = time.Now() vp.cache = newCache - vp.lock.Unlock() } func (vp *validatorsProvider) createNewCache( @@ -319,7 +320,9 @@ func shouldCombine(triePeerType common.PeerType, currentPeerType common.PeerType // ForceUpdate will trigger the update process of all caches func (vp *validatorsProvider) ForceUpdate() error { + vp.lock.Lock() vp.updateCache() + vp.lock.Unlock() vp.auctionMutex.Lock() defer vp.auctionMutex.Unlock() diff --git a/process/peer/validatorsProvider_test.go b/process/peer/validatorsProvider_test.go index 8bb56753660..71da53f08e7 100644 --- a/process/peer/validatorsProvider_test.go +++ b/process/peer/validatorsProvider_test.go @@ -1092,23 +1092,37 @@ func TestValidatorsProvider_GetAuctionList(t *testing.T) { vp, _ := NewValidatorsProvider(args) time.Sleep(args.CacheRefreshIntervalDurationInSec) - numCalls := 100 + numCalls := 99 wg := sync.WaitGroup{} wg.Add(numCalls) for i := 0; i < numCalls; i++ { - go func() { - list, err := vp.GetAuctionList() - require.NoError(t, err) - require.Empty(t, list) + go func(idx int) { + switch idx % 3 { + case 0: + list, err := vp.GetAuctionList() + require.NoError(t, err) + require.Empty(t, list) + case 1: + err := vp.ForceUpdate() + require.NoError(t, err) + case 2: + _ = vp.GetLatestValidators() + } wg.Done() - }() + }(i) } wg.Wait() - require.LessOrEqual(t, ctRootHashCalled, uint32(2)) // another call might be from constructor in startRefreshProcess.updateCache + // expectedMaxNumCalls is: + // - 1 from constructor + // - 1 from GetAuctionList, should not update second time + // - 1 from GetLatestValidators, should not update second time + // - 33 calls * 2 from ForceUpdate, calling it twice/call + expectedMaxNumCalls := uint32(1 + 1 + 1 + 66) + require.LessOrEqual(t, ctRootHashCalled, expectedMaxNumCalls) require.NoError(t, vp.Close()) }) From 9e45d8c5f80e18c8aae1c392dacbd47029e215b5 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 22 May 2024 11:19:10 +0300 Subject: [PATCH 137/467] use require.NotPanics --- .../metachain/stakingDataProvider_test.go | 47 +++++++++---------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/epochStart/metachain/stakingDataProvider_test.go b/epochStart/metachain/stakingDataProvider_test.go index e11bb45801e..6f5ad62868d 100644 --- a/epochStart/metachain/stakingDataProvider_test.go +++ b/epochStart/metachain/stakingDataProvider_test.go @@ -483,13 +483,6 @@ func TestStakingDataProvider_FillValidatorInfo(t *testing.T) { t.Run("concurrent calls should work", func(t *testing.T) { t.Parallel() - defer func() { - r := recover() - if r != nil { - require.Fail(t, "should have not panicked") - } - }() - owner := []byte("owner") topUpVal := big.NewInt(828743) basePrice := big.NewInt(100000) @@ -502,26 +495,28 @@ func TestStakingDataProvider_FillValidatorInfo(t *testing.T) { numCalls := 100 wg.Add(numCalls) - for i := 0; i < numCalls; i++ { - go func(idx int) { - switch idx % 2 { - case 0: - err := sdp.FillValidatorInfo(&state.ValidatorInfo{ - PublicKey: []byte("bls key"), - List: string(common.EligibleList), - ShardId: 0, - }) - require.NoError(t, err) - case 1: - stats := sdp.GetCurrentEpochValidatorStats() - log.Info(fmt.Sprintf("%d", stats.Eligible[0])) - } - - wg.Done() - }(i) - } + require.NotPanics(t, func() { + for i := 0; i < numCalls; i++ { + go func(idx int) { + switch idx % 2 { + case 0: + err := sdp.FillValidatorInfo(&state.ValidatorInfo{ + PublicKey: []byte("bls key"), + List: string(common.EligibleList), + ShardId: 0, + }) + require.NoError(t, err) + case 1: + stats := sdp.GetCurrentEpochValidatorStats() + log.Info(fmt.Sprintf("%d", stats.Eligible[0])) + } + + wg.Done() + }(i) + } - wg.Wait() + wg.Wait() + }) }) } From 9cede459c8285400b89090e2a7137a7221f9db6d Mon Sep 17 00:00:00 2001 From: ssd04 Date: Wed, 22 May 2024 13:10:51 +0300 Subject: [PATCH 138/467] 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 139/467] 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 140/467] 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 141/467] 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 142/467] 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 143/467] 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 144/467] 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 145/467] 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 146/467] 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 147/467] 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 148/467] 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 149/467] 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 150/467] 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 151/467] 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 152/467] 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 153/467] 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 154/467] 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 155/467] 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 156/467] 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 157/467] 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 158/467] 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 159/467] 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 160/467] 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 161/467] 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 162/467] 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 163/467] 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 164/467] 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 165/467] 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 166/467] 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 167/467] 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 168/467] 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 169/467] 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 170/467] 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 171/467] 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 172/467] 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 173/467] 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 174/467] 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 175/467] 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 176/467] 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 177/467] 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 178/467] 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 179/467] 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 180/467] 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 181/467] 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 182/467] 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 183/467] 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 184/467] 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 185/467] 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 186/467] 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 187/467] 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 188/467] 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 189/467] 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 190/467] 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 191/467] 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 192/467] 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 193/467] 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 194/467] 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 195/467] 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 196/467] 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 197/467] 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 198/467] 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 199/467] 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 200/467] 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 201/467] 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 202/467] 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 203/467] 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 204/467] 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 205/467] 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 206/467] 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 207/467] 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 208/467] 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 209/467] 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 210/467] 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 211/467] 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 212/467] 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 213/467] 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 214/467] 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 215/467] 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 216/467] 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 217/467] 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 218/467] 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 219/467] 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 220/467] 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 892749f1762219543ad525efe7d8faf4ebebea5f Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 18 Jun 2024 14:24:45 +0300 Subject: [PATCH 221/467] add max gas higher factory accepted to economics toml --- cmd/node/config/economics.toml | 6 +++--- config/economicsConfig.go | 1 + config/tomlConfig_test.go | 11 +++++++---- genesis/process/disabled/feeHandler.go | 13 +++++++++---- integrationTests/testProcessorNode.go | 1 + integrationTests/vm/testInitializer.go | 7 ++++--- integrationTests/vm/wasm/utils.go | 1 + .../components/coreComponents_test.go | 1 + process/economics/economicsData.go | 11 +++++++++++ process/economics/economicsData_test.go | 6 ++++++ process/economics/gasConfigHandler.go | 15 +++++++++++++++ process/economics/testEconomicsData.go | 5 +++++ process/errors.go | 3 +++ .../factory/metachain/vmContainerFactory_test.go | 1 + process/interface.go | 10 ++++++++++ process/peer/process_test.go | 1 + process/smartContract/process_test.go | 1 + process/smartContract/processorV2/processV2.go | 10 +++++++--- process/smartContract/processorV2/process_test.go | 11 +++++++---- testscommon/components/configs.go | 1 + testscommon/economicsConfig.go | 1 + .../economicsmocks/economicsDataHandlerStub.go | 9 +++++++++ testscommon/stakingcommon/stakingCommon.go | 1 + 23 files changed, 106 insertions(+), 21 deletions(-) diff --git a/cmd/node/config/economics.toml b/cmd/node/config/economics.toml index f0bac97a055..b29c91978fc 100644 --- a/cmd/node/config/economics.toml +++ b/cmd/node/config/economics.toml @@ -39,9 +39,9 @@ [FeeSettings] GasLimitSettings = [ - {EnableEpoch = 0, MaxGasLimitPerBlock = "1500000000", MaxGasLimitPerMiniBlock = "1500000000", MaxGasLimitPerMetaBlock = "15000000000", MaxGasLimitPerMetaMiniBlock = "15000000000", MaxGasLimitPerTx = "1500000000", MinGasLimit = "50000", ExtraGasLimitGuardedTx = "50000"}, - {EnableEpoch = 1, MaxGasLimitPerBlock = "1500000000", MaxGasLimitPerMiniBlock = "250000000", MaxGasLimitPerMetaBlock = "15000000000", MaxGasLimitPerMetaMiniBlock = "250000000", MaxGasLimitPerTx = "600000000", MinGasLimit = "50000", ExtraGasLimitGuardedTx = "50000"}, - {EnableEpoch = 2, MaxGasLimitPerBlock = "1500000000", MaxGasLimitPerMiniBlock = "250000000", MaxGasLimitPerMetaBlock = "15000000000", MaxGasLimitPerMetaMiniBlock = "250000000", MaxGasLimitPerTx = "600000000", MinGasLimit = "50000", ExtraGasLimitGuardedTx = "50000"}, + {EnableEpoch = 0, MaxGasLimitPerBlock = "1500000000", MaxGasLimitPerMiniBlock = "1500000000", MaxGasLimitPerMetaBlock = "15000000000", MaxGasLimitPerMetaMiniBlock = "15000000000", MaxGasLimitPerTx = "1500000000", MinGasLimit = "50000", ExtraGasLimitGuardedTx = "50000", MaxGasHigherFactorAccepted = "10"}, + {EnableEpoch = 1, MaxGasLimitPerBlock = "1500000000", MaxGasLimitPerMiniBlock = "250000000", MaxGasLimitPerMetaBlock = "15000000000", MaxGasLimitPerMetaMiniBlock = "250000000", MaxGasLimitPerTx = "600000000", MinGasLimit = "50000", ExtraGasLimitGuardedTx = "50000", MaxGasHigherFactorAccepted = "10"}, + {EnableEpoch = 2, MaxGasLimitPerBlock = "1500000000", MaxGasLimitPerMiniBlock = "250000000", MaxGasLimitPerMetaBlock = "15000000000", MaxGasLimitPerMetaMiniBlock = "250000000", MaxGasLimitPerTx = "600000000", MinGasLimit = "50000", ExtraGasLimitGuardedTx = "50000", MaxGasHigherFactorAccepted = "10"}, ] MinGasPrice = "1000000000" #will yield min tx fee of 0.00005 eGLD GasPriceModifier = 0.01 diff --git a/config/economicsConfig.go b/config/economicsConfig.go index 35c67d92469..4d33b87f548 100644 --- a/config/economicsConfig.go +++ b/config/economicsConfig.go @@ -41,6 +41,7 @@ type GasLimitSetting struct { MaxGasLimitPerTx string MinGasLimit string ExtraGasLimitGuardedTx string + MaxGasHigherFactorAccepted string } // FeeSettings will hold economics fee settings diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index 97232f39f41..ab0b5fe4eec 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -271,7 +271,9 @@ func TestTomlEconomicsParser(t *testing.T) { minGasLimit := "18446744073709551615" extraGasLimitGuardedTx := "50000" maxGasPriceSetGuardian := "1234567" + maxGasHigherFactorAccepted := "10" protocolSustainabilityAddress := "erd1932eft30w753xyvme8d49qejgkjc09n5e49w4mwdjtm0neld797su0dlxp" + denomination := 18 cfgEconomicsExpected := EconomicsConfig{ @@ -299,9 +301,10 @@ func TestTomlEconomicsParser(t *testing.T) { FeeSettings: FeeSettings{ GasLimitSettings: []GasLimitSetting{ { - MaxGasLimitPerBlock: maxGasLimitPerBlock, - MinGasLimit: minGasLimit, - ExtraGasLimitGuardedTx: extraGasLimitGuardedTx, + MaxGasLimitPerBlock: maxGasLimitPerBlock, + MinGasLimit: minGasLimit, + ExtraGasLimitGuardedTx: extraGasLimitGuardedTx, + MaxGasHigherFactorAccepted: maxGasHigherFactorAccepted, }, }, MinGasPrice: minGasPrice, @@ -328,7 +331,7 @@ func TestTomlEconomicsParser(t *testing.T) { ProtocolSustainabilityAddress = "` + protocolSustainabilityAddress + `" [FeeSettings] - GasLimitSettings = [{EnableEpoch = 0, MaxGasLimitPerBlock = "` + maxGasLimitPerBlock + `", MaxGasLimitPerMiniBlock = "", MaxGasLimitPerMetaBlock = "", MaxGasLimitPerMetaMiniBlock = "", MaxGasLimitPerTx = "", MinGasLimit = "` + minGasLimit + `", ExtraGasLimitGuardedTx = "` + extraGasLimitGuardedTx + `"}] + GasLimitSettings = [{EnableEpoch = 0, MaxGasLimitPerBlock = "` + maxGasLimitPerBlock + `", MaxGasLimitPerMiniBlock = "", MaxGasLimitPerMetaBlock = "", MaxGasLimitPerMetaMiniBlock = "", MaxGasLimitPerTx = "", MinGasLimit = "` + minGasLimit + `", ExtraGasLimitGuardedTx = "` + extraGasLimitGuardedTx + `", MaxGasHigherFactorAccepted = "` + maxGasHigherFactorAccepted + `"}] MinGasPrice = "` + minGasPrice + `" MaxGasPriceSetGuardian = "` + maxGasPriceSetGuardian + `" ` diff --git a/genesis/process/disabled/feeHandler.go b/genesis/process/disabled/feeHandler.go index 1fc34bbc2b5..df171e3d37c 100644 --- a/genesis/process/disabled/feeHandler.go +++ b/genesis/process/disabled/feeHandler.go @@ -72,6 +72,11 @@ func (fh *FeeHandler) MaxGasLimitPerMiniBlockForSafeCrossShard() uint64 { return math.MaxUint64 } +// MaxGasHigherFactorAccepted returns 10 +func (fh *FeeHandler) MaxGasHigherFactorAccepted() uint64 { + return 10 +} + // MaxGasLimitPerTx returns max uint64 func (fh *FeeHandler) MaxGasLimitPerTx() uint64 { return math.MaxUint64 @@ -164,22 +169,22 @@ func (fh *FeeHandler) ComputeTxFeeBasedOnGasUsed(_ data.TransactionWithFeeHandle } // ComputeTxFeeInEpoch returns 0 -func (fh *FeeHandler) ComputeTxFeeInEpoch(tx data.TransactionWithFeeHandler, epoch uint32) *big.Int { +func (fh *FeeHandler) ComputeTxFeeInEpoch(_ data.TransactionWithFeeHandler, _ uint32) *big.Int { return big.NewInt(0) } // ComputeGasLimitInEpoch returns 0 -func (fh *FeeHandler) ComputeGasLimitInEpoch(tx data.TransactionWithFeeHandler, epoch uint32) uint64 { +func (fh *FeeHandler) ComputeGasLimitInEpoch(_ data.TransactionWithFeeHandler, _ uint32) uint64 { return 0 } // ComputeGasUsedAndFeeBasedOnRefundValueInEpoch returns 0 -func (fh *FeeHandler) ComputeGasUsedAndFeeBasedOnRefundValueInEpoch(tx data.TransactionWithFeeHandler, refundValue *big.Int, epoch uint32) (uint64, *big.Int) { +func (fh *FeeHandler) ComputeGasUsedAndFeeBasedOnRefundValueInEpoch(_ data.TransactionWithFeeHandler, _ *big.Int, _ uint32) (uint64, *big.Int) { return 0, big.NewInt(0) } // ComputeTxFeeBasedOnGasUsedInEpoch returns 0 -func (fh *FeeHandler) ComputeTxFeeBasedOnGasUsedInEpoch(tx data.TransactionWithFeeHandler, gasUsed uint64, epoch uint32) *big.Int { +func (fh *FeeHandler) ComputeTxFeeBasedOnGasUsedInEpoch(_ data.TransactionWithFeeHandler, _ uint64, _ uint32) *big.Int { return big.NewInt(0) } diff --git a/integrationTests/testProcessorNode.go b/integrationTests/testProcessorNode.go index a7468de8485..cdfcd6f903f 100644 --- a/integrationTests/testProcessorNode.go +++ b/integrationTests/testProcessorNode.go @@ -1151,6 +1151,7 @@ func createDefaultEconomicsConfig() *config.EconomicsConfig { MaxGasLimitPerTx: maxGasLimitPerBlock, MinGasLimit: minGasLimit, ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, }, MinGasPrice: minGasPrice, diff --git a/integrationTests/vm/testInitializer.go b/integrationTests/vm/testInitializer.go index 4ffd57197ca..f1f14abbdda 100644 --- a/integrationTests/vm/testInitializer.go +++ b/integrationTests/vm/testInitializer.go @@ -126,7 +126,7 @@ type VMTestContext struct { TxFeeHandler process.TransactionFeeHandler ShardCoordinator sharding.Coordinator ScForwarder process.IntermediateTransactionHandler - EconomicsData process.EconomicsDataHandler + EconomicsData process.CompleteEconomicsDataHandler Marshalizer marshal.Marshalizer GasSchedule core.GasScheduleNotifier VMConfiguration *config.VirtualMachineConfig @@ -317,7 +317,7 @@ func CreateAccount(accnts state.AccountsAdapter, pubKey []byte, nonce uint64, ba return hashCreated, nil } -func createEconomicsData(enableEpochsConfig config.EnableEpochs) (process.EconomicsDataHandler, error) { +func createEconomicsData(enableEpochsConfig config.EnableEpochs) (process.CompleteEconomicsDataHandler, error) { maxGasLimitPerBlock := strconv.FormatUint(math.MaxUint64, 10) minGasPrice := strconv.FormatUint(1, 10) minGasLimit := strconv.FormatUint(1, 10) @@ -359,6 +359,7 @@ func createEconomicsData(enableEpochsConfig config.EnableEpochs) (process.Econom MaxGasLimitPerTx: maxGasLimitPerBlock, MinGasLimit: minGasLimit, ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, }, MinGasPrice: minGasPrice, @@ -806,7 +807,7 @@ type ResultsCreateTxProcessor struct { TxProc process.TransactionProcessor SCProc scrCommon.TestSmartContractProcessor IntermediateTxProc process.IntermediateTransactionHandler - EconomicsHandler process.EconomicsDataHandler + EconomicsHandler process.CompleteEconomicsDataHandler CostHandler external.TransactionEvaluator TxLogProc process.TransactionLogProcessor } diff --git a/integrationTests/vm/wasm/utils.go b/integrationTests/vm/wasm/utils.go index bfe7b4b7ca9..61402910679 100644 --- a/integrationTests/vm/wasm/utils.go +++ b/integrationTests/vm/wasm/utils.go @@ -242,6 +242,7 @@ func (context *TestContext) initFeeHandlers() { MaxGasLimitPerTx: maxGasLimitPerBlock, MinGasLimit: minGasLimit, ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, }, MinGasPrice: minGasPrice, diff --git a/node/chainSimulator/components/coreComponents_test.go b/node/chainSimulator/components/coreComponents_test.go index f8fc663fa64..3b250384781 100644 --- a/node/chainSimulator/components/coreComponents_test.go +++ b/node/chainSimulator/components/coreComponents_test.go @@ -73,6 +73,7 @@ func createArgsCoreComponentsHolder() ArgsCoreComponentsHolder { MaxGasLimitPerTx: "10000000000", MinGasLimit: "10", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, }, GasPriceModifier: 0.01, diff --git a/process/economics/economicsData.go b/process/economics/economicsData.go index 5b7ce045237..ed8a7a5aa99 100644 --- a/process/economics/economicsData.go +++ b/process/economics/economicsData.go @@ -400,6 +400,17 @@ func (ed *economicsData) MaxGasLimitPerBlockForSafeCrossShard() uint64 { return ed.MaxGasLimitPerBlockForSafeCrossShardInEpoch(currentEpoch) } +// MaxGasHigherFactorAccepted returns maximum gas higher factor accepted +func (ed *economicsData) MaxGasHigherFactorAccepted() uint64 { + currentEpoch := ed.enableEpochsHandler.GetCurrentEpoch() + return ed.MaxGasHigherFactorAcceptedInEpoch(currentEpoch) +} + +// MaxGasHigherFactorAcceptedInEpoch returns maximum gas higher factor accepted for epoch +func (ed *economicsData) MaxGasHigherFactorAcceptedInEpoch(epoch uint32) uint64 { + return ed.getGasHigherFactorAccepted(epoch) +} + // MaxGasLimitPerBlockForSafeCrossShardInEpoch returns maximum gas limit per block for safe cross shard in a specific epoch func (ed *economicsData) MaxGasLimitPerBlockForSafeCrossShardInEpoch(epoch uint32) uint64 { return ed.getMaxGasLimitPerBlockForSafeCrossShard(epoch) diff --git a/process/economics/economicsData_test.go b/process/economics/economicsData_test.go index 1f2c913a826..f144158d87b 100644 --- a/process/economics/economicsData_test.go +++ b/process/economics/economicsData_test.go @@ -64,6 +64,7 @@ func feeSettingsDummy(gasModifier float64) config.FeeSettings { MaxGasLimitPerTx: "100000", MinGasLimit: "500", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, }, MinGasPrice: "18446744073709551615", @@ -84,6 +85,7 @@ func feeSettingsReal() config.FeeSettings { MaxGasLimitPerTx: "1500000000", MinGasLimit: "50000", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, }, MinGasPrice: "1000000000", @@ -716,6 +718,7 @@ func TestEconomicsData_ConfirmedGasLimitSettingsChangeOrderedConfigs(t *testing. MaxGasLimitPerTx: "1500000000", MinGasLimit: "50000", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, { EnableEpoch: 2, @@ -726,6 +729,7 @@ func TestEconomicsData_ConfirmedGasLimitSettingsChangeOrderedConfigs(t *testing. MaxGasLimitPerTx: "500000000", MinGasLimit: "50000", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, } @@ -800,6 +804,7 @@ func TestEconomicsData_ConfirmedGasLimitSettingsChangeUnOrderedConfigs(t *testin MaxGasLimitPerTx: "500000000", MinGasLimit: "50000", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, { EnableEpoch: 0, @@ -810,6 +815,7 @@ func TestEconomicsData_ConfirmedGasLimitSettingsChangeUnOrderedConfigs(t *testin MaxGasLimitPerTx: "1500000000", MinGasLimit: "50000", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, } diff --git a/process/economics/gasConfigHandler.go b/process/economics/gasConfigHandler.go index 02fcc3cece6..2955160b1c8 100644 --- a/process/economics/gasConfigHandler.go +++ b/process/economics/gasConfigHandler.go @@ -26,6 +26,7 @@ type gasConfig struct { maxGasLimitPerTx uint64 minGasLimit uint64 extraGasLimitGuardedTx uint64 + maxGasHigherFactorAccepted uint64 } type gasConfigHandler struct { @@ -113,6 +114,12 @@ func (handler *gasConfigHandler) getMaxGasLimitPerMiniBlock(epoch uint32) uint64 return gc.maxGasLimitPerMiniBlock } +// getMaxGasLimitPerMiniBlock returns max gas limit per mini block in a specific epoch +func (handler *gasConfigHandler) getGasHigherFactorAccepted(epoch uint32) uint64 { + gc := handler.getGasConfigForEpoch(epoch) + return gc.maxGasHigherFactorAccepted +} + // getMaxGasLimitPerBlockForSafeCrossShard returns maximum gas limit per block for safe cross shard in a specific epoch func (handler *gasConfigHandler) getMaxGasLimitPerBlockForSafeCrossShard(epoch uint32) uint64 { gc := handler.getGasConfigForEpoch(epoch) @@ -225,6 +232,11 @@ func checkAndParseGasLimitSettings(gasLimitSetting config.GasLimitSetting) (*gas return nil, fmt.Errorf("%w for epoch %d", process.ErrInvalidExtraGasLimitGuardedTx, gasLimitSetting.EnableEpoch) } + gc.maxGasHigherFactorAccepted, err = strconv.ParseUint(gasLimitSetting.MaxGasHigherFactorAccepted, conversionBase, bitConversionSize) + if err != nil { + return nil, fmt.Errorf("%w for epoch %d", process.ErrInvalidMaxGasHigherFactorAccepted, gasLimitSetting.EnableEpoch) + } + if gc.maxGasLimitPerBlock < gc.minGasLimit { return nil, fmt.Errorf("%w: maxGasLimitPerBlock = %d minGasLimit = %d in epoch %d", process.ErrInvalidMaxGasLimitPerBlock, gc.maxGasLimitPerBlock, gc.minGasLimit, gasLimitSetting.EnableEpoch) } @@ -240,6 +252,9 @@ func checkAndParseGasLimitSettings(gasLimitSetting config.GasLimitSetting) (*gas if gc.maxGasLimitPerTx < gc.minGasLimit { return nil, fmt.Errorf("%w: maxGasLimitPerTx = %d minGasLimit = %d in epoch %d", process.ErrInvalidMaxGasLimitPerTx, gc.maxGasLimitPerTx, gc.minGasLimit, gasLimitSetting.EnableEpoch) } + if gc.maxGasHigherFactorAccepted < 1 { + return nil, fmt.Errorf("%w for epoch %d, it is set to 0", process.ErrInvalidMaxGasHigherFactorAccepted, gasLimitSetting.EnableEpoch) + } return gc, nil } diff --git a/process/economics/testEconomicsData.go b/process/economics/testEconomicsData.go index 7e60812d1df..556cedb3ef6 100644 --- a/process/economics/testEconomicsData.go +++ b/process/economics/testEconomicsData.go @@ -68,6 +68,11 @@ func (ted *TestEconomicsData) SetMaxInflationRate(maximumInflation float64) { ted.yearSettings[0].MaximumInflation = maximumInflation } +// MaxGasHigherFactorAccepted returns 10 +func (ted *TestEconomicsData) MaxGasHigherFactorAccepted() uint64 { + return 10 +} + // SetStatusHandler returns nil func (ted *TestEconomicsData) SetStatusHandler(_ core.AppStatusHandler) error { return nil diff --git a/process/errors.go b/process/errors.go index 83e8095dcb3..8fd231731bf 100644 --- a/process/errors.go +++ b/process/errors.go @@ -534,6 +534,9 @@ var ErrInvalidExtraGasLimitGuardedTx = errors.New("invalid extra gas limit for g // ErrInvalidMaxGasPriceSetGuardian signals that an invalid maximum gas price has been provided in the config file var ErrInvalidMaxGasPriceSetGuardian = errors.New("invalid maximum gas price for set guardian") +// ErrInvalidMaxGasHigherFactorAccepted signals that an invalid gas factor has been provided in the config file +var ErrInvalidMaxGasHigherFactorAccepted = errors.New("invalid gas higher factor accepted") + // ErrGuardianSignatureNotExpected signals that the guardian signature is not expected var ErrGuardianSignatureNotExpected = errors.New("guardian signature not expected") diff --git a/process/factory/metachain/vmContainerFactory_test.go b/process/factory/metachain/vmContainerFactory_test.go index ff542213ef4..95d0fc05610 100644 --- a/process/factory/metachain/vmContainerFactory_test.go +++ b/process/factory/metachain/vmContainerFactory_test.go @@ -312,6 +312,7 @@ func TestVmContainerFactory_Create(t *testing.T) { MaxGasLimitPerTx: "10000000000", MinGasLimit: "10", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, }, MinGasPrice: "10", diff --git a/process/interface.go b/process/interface.go index 69b1b139e89..26094127611 100644 --- a/process/interface.go +++ b/process/interface.go @@ -716,6 +716,7 @@ type TxGasHandler interface { // FeeHandler is able to perform some economics calculation on a provided transaction type FeeHandler interface { feeHandler + MaxGasHigherFactorAccepted() uint64 IsInterfaceNil() bool } @@ -727,6 +728,15 @@ type EconomicsDataHandler interface { IsInterfaceNil() bool } +// CompleteEconomicsDataHandler provides some economics related computation and read access to economics data +type CompleteEconomicsDataHandler interface { + rewardsHandler + feeHandler + MaxGasHigherFactorAccepted() uint64 + SetStatusHandler(statusHandler core.AppStatusHandler) error + IsInterfaceNil() bool +} + // SmartContractToProtocolHandler is able to translate data from smart contract state into protocol changes type SmartContractToProtocolHandler interface { UpdateProtocol(body *block.Body, nonce uint64) error diff --git a/process/peer/process_test.go b/process/peer/process_test.go index d4c85a5601f..3df1a8f5505 100644 --- a/process/peer/process_test.go +++ b/process/peer/process_test.go @@ -94,6 +94,7 @@ func createMockArguments() peer.ArgValidatorStatisticsProcessor { MaxGasLimitPerTx: "10000000", MinGasLimit: "10", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, }, MinGasPrice: "10", diff --git a/process/smartContract/process_test.go b/process/smartContract/process_test.go index c53c7ef83c9..1bbd2c2b404 100644 --- a/process/smartContract/process_test.go +++ b/process/smartContract/process_test.go @@ -4231,6 +4231,7 @@ func createRealEconomicsDataArgs() *economics.ArgsNewEconomicsData { MaxGasLimitPerTx: "1500000000", MinGasLimit: "50000", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, }, GasPerDataByte: "1500", diff --git a/process/smartContract/processorV2/processV2.go b/process/smartContract/processorV2/processV2.go index 126433c6dee..46634a936c2 100644 --- a/process/smartContract/processorV2/processV2.go +++ b/process/smartContract/processorV2/processV2.go @@ -2093,7 +2093,7 @@ func (sc *scProcessor) penalizeUserIfNeeded( return } - isTooMuchProvided := isTooMuchGasProvided(gasProvidedForProcessing, vmOutput.GasRemaining) + isTooMuchProvided := isTooMuchGasProvided(gasProvidedForProcessing, vmOutput.GasRemaining, sc.economicsFee) if !isTooMuchProvided { return } @@ -2122,13 +2122,17 @@ func (sc *scProcessor) penalizeUserIfNeeded( vmOutput.GasRemaining = 0 } -func isTooMuchGasProvided(gasProvided uint64, gasRemained uint64) bool { +func isTooMuchGasProvided( + gasProvided uint64, + gasRemained uint64, + economicsFee process.FeeHandler, +) bool { if gasProvided <= gasRemained { return false } gasUsed := gasProvided - gasRemained - return gasProvided > gasUsed*process.MaxGasFeeHigherFactorAccepted + return gasProvided > gasUsed*economicsFee.MaxGasHigherFactorAccepted() } func (sc *scProcessor) createSCRsWhenError( diff --git a/process/smartContract/processorV2/process_test.go b/process/smartContract/processorV2/process_test.go index eedea17f1ad..fdc2342ec56 100644 --- a/process/smartContract/processorV2/process_test.go +++ b/process/smartContract/processorV2/process_test.go @@ -3437,16 +3437,18 @@ func TestScProcessor_isTooMuchGasProvidedShouldWork(t *testing.T) { gasProvided := uint64(100) maxGasToRemain := gasProvided - (gasProvided / process.MaxGasFeeHigherFactorAccepted) - isTooMuchGas := isTooMuchGasProvided(gasProvided, gasProvided) + economicsHandler := &economicsmocks.EconomicsHandlerStub{} + + isTooMuchGas := isTooMuchGasProvided(gasProvided, gasProvided, economicsHandler) assert.False(t, isTooMuchGas) - isTooMuchGas = isTooMuchGasProvided(gasProvided, maxGasToRemain-1) + isTooMuchGas = isTooMuchGasProvided(gasProvided, maxGasToRemain-1, economicsHandler) assert.False(t, isTooMuchGas) - isTooMuchGas = isTooMuchGasProvided(gasProvided, maxGasToRemain) + isTooMuchGas = isTooMuchGasProvided(gasProvided, maxGasToRemain, economicsHandler) assert.False(t, isTooMuchGas) - isTooMuchGas = isTooMuchGasProvided(gasProvided, maxGasToRemain+1) + isTooMuchGas = isTooMuchGasProvided(gasProvided, maxGasToRemain+1, economicsHandler) assert.True(t, isTooMuchGas) } @@ -4168,6 +4170,7 @@ func createRealEconomicsDataArgs() *economics.ArgsNewEconomicsData { MaxGasLimitPerTx: "1500000000", MinGasLimit: "50000", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, }, GasPerDataByte: "1500", diff --git a/testscommon/components/configs.go b/testscommon/components/configs.go index f86a5ae59cc..12598af042c 100644 --- a/testscommon/components/configs.go +++ b/testscommon/components/configs.go @@ -249,6 +249,7 @@ func CreateDummyEconomicsConfig() config.EconomicsConfig { MaxGasLimitPerTx: "1500000000", MinGasLimit: "50000", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, }, MinGasPrice: "1000000000", diff --git a/testscommon/economicsConfig.go b/testscommon/economicsConfig.go index 59ec0088240..aae732d7446 100644 --- a/testscommon/economicsConfig.go +++ b/testscommon/economicsConfig.go @@ -39,6 +39,7 @@ func GetEconomicsConfig() config.EconomicsConfig { MaxGasLimitPerTx: "600000000", MinGasLimit: "50000", ExtraGasLimitGuardedTx: "50000", + MaxGasHigherFactorAccepted: "10", }, }, MinGasPrice: "1000000000", diff --git a/testscommon/economicsmocks/economicsDataHandlerStub.go b/testscommon/economicsmocks/economicsDataHandlerStub.go index b6cf36f4491..49c9545d529 100644 --- a/testscommon/economicsmocks/economicsDataHandlerStub.go +++ b/testscommon/economicsmocks/economicsDataHandlerStub.go @@ -30,6 +30,7 @@ type EconomicsHandlerStub struct { MinGasLimitCalled func() uint64 ExtraGasLimitGuardedTxCalled func() uint64 MaxGasPriceSetGuardianCalled func() uint64 + MaxGasHigherFactorAcceptedCalled func() uint64 GenesisTotalSupplyCalled func() *big.Int ComputeFeeForProcessingCalled func(tx data.TransactionWithFeeHandler, gasToUse uint64) *big.Int RewardsTopUpGradientPointCalled func() *big.Int @@ -201,6 +202,14 @@ func (e *EconomicsHandlerStub) MaxGasLimitPerMiniBlockForSafeCrossShard() uint64 return 1000000 } +// MaxGasHigherFactorAccepted - +func (e *EconomicsHandlerStub) MaxGasHigherFactorAccepted() uint64 { + if e.MaxGasHigherFactorAcceptedCalled != nil { + return e.MaxGasHigherFactorAcceptedCalled() + } + return 10 +} + // MaxGasLimitPerTx - func (e *EconomicsHandlerStub) MaxGasLimitPerTx() uint64 { if e.MaxGasLimitPerTxCalled != nil { diff --git a/testscommon/stakingcommon/stakingCommon.go b/testscommon/stakingcommon/stakingCommon.go index 1af9b441b9c..bdad4a47bde 100644 --- a/testscommon/stakingcommon/stakingCommon.go +++ b/testscommon/stakingcommon/stakingCommon.go @@ -266,6 +266,7 @@ func CreateEconomicsData() process.EconomicsDataHandler { MaxGasLimitPerTx: maxGasLimitPerBlock, MinGasLimit: minGasLimit, ExtraGasLimitGuardedTx: maxGasLimitPerBlock, + MaxGasHigherFactorAccepted: "10", }, }, MinGasPrice: minGasPrice, From 68bbfbc247e5defd3e316cdd7bdea4b22a45a7a6 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 18 Jun 2024 14:29:02 +0300 Subject: [PATCH 222/467] 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 9382c6cdf244bca37642453d37b3278b1a111af9 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 18 Jun 2024 14:47:24 +0300 Subject: [PATCH 223/467] adding tests --- process/economics/economicsData_test.go | 30 +++++++++++++++++++ .../smartContract/processorV2/process_test.go | 25 ++++++++++++++-- 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/process/economics/economicsData_test.go b/process/economics/economicsData_test.go index f144158d87b..f97dec2104e 100644 --- a/process/economics/economicsData_test.go +++ b/process/economics/economicsData_test.go @@ -391,6 +391,36 @@ func TestNewEconomicsData_InvalidExtraGasLimitGuardedTxShouldErr(t *testing.T) { } } +func TestNewEconomicsData_InvalidMaxGasHigherFactorAccepted(t *testing.T) { + t.Parallel() + + args := createArgsForEconomicsData(1) + badExtraMaxGasHigherFactorAccepted := []string{ + "-1", + "-100000000000000000000", + "badValue", + "", + "#########", + "11112S", + "1111O0000", + "10ERD", + } + + for _, gasLimitGuardedTx := range badExtraMaxGasHigherFactorAccepted { + args.Economics.FeeSettings.GasLimitSettings[0].MaxGasHigherFactorAccepted = gasLimitGuardedTx + _, err := economics.NewEconomicsData(args) + assert.True(t, errors.Is(err, process.ErrInvalidMaxGasHigherFactorAccepted)) + } + + args.Economics.FeeSettings.GasLimitSettings[0].MaxGasHigherFactorAccepted = "0" + _, err := economics.NewEconomicsData(args) + assert.True(t, errors.Is(err, process.ErrInvalidMaxGasHigherFactorAccepted)) + + args.Economics.FeeSettings.GasLimitSettings[0].MaxGasHigherFactorAccepted = "2" + _, err = economics.NewEconomicsData(args) + assert.Nil(t, err) +} + func TestNewEconomicsData_MaxGasLimitPerBlockLowerThanMinGasLimitShouldErr(t *testing.T) { t.Parallel() diff --git a/process/smartContract/processorV2/process_test.go b/process/smartContract/processorV2/process_test.go index fdc2342ec56..b2931e4e941 100644 --- a/process/smartContract/processorV2/process_test.go +++ b/process/smartContract/processorV2/process_test.go @@ -3434,11 +3434,11 @@ func TestScProcessor_penalizeUserIfNeededShouldWork(t *testing.T) { func TestScProcessor_isTooMuchGasProvidedShouldWork(t *testing.T) { t.Parallel() - gasProvided := uint64(100) - maxGasToRemain := gasProvided - (gasProvided / process.MaxGasFeeHigherFactorAccepted) - economicsHandler := &economicsmocks.EconomicsHandlerStub{} + gasProvided := uint64(100) + maxGasToRemain := gasProvided - (gasProvided / economicsHandler.MaxGasHigherFactorAccepted()) + isTooMuchGas := isTooMuchGasProvided(gasProvided, gasProvided, economicsHandler) assert.False(t, isTooMuchGas) @@ -3450,6 +3450,25 @@ func TestScProcessor_isTooMuchGasProvidedShouldWork(t *testing.T) { isTooMuchGas = isTooMuchGasProvided(gasProvided, maxGasToRemain+1, economicsHandler) assert.True(t, isTooMuchGas) + + economicsHandler.MaxGasHigherFactorAcceptedCalled = func() uint64 { + return 2 + } + + maxGasToRemain = gasProvided - (gasProvided / economicsHandler.MaxGasHigherFactorAccepted()) + + isTooMuchGas = isTooMuchGasProvided(gasProvided, gasProvided, economicsHandler) + assert.False(t, isTooMuchGas) + + isTooMuchGas = isTooMuchGasProvided(gasProvided, maxGasToRemain-1, economicsHandler) + assert.False(t, isTooMuchGas) + + isTooMuchGas = isTooMuchGasProvided(gasProvided, maxGasToRemain, economicsHandler) + assert.False(t, isTooMuchGas) + + isTooMuchGas = isTooMuchGasProvided(gasProvided, maxGasToRemain+1, economicsHandler) + assert.True(t, isTooMuchGas) + } func TestSCProcessor_createSCRWhenError(t *testing.T) { From ec0edab776ff5126fed5b12d9798b7d80d3ea3b0 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 18 Jun 2024 15:11:49 +0300 Subject: [PATCH 224/467] adding tests --- go.sum | 6 ------ integrationTests/vm/testInitializer.go | 6 +++--- process/interface.go | 11 +---------- testscommon/economicsmocks/economicsHandlerMock.go | 9 +++++++++ 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/go.sum b/go.sum index a98f8ba06c2..990794e0d27 100644 --- a/go.sum +++ b/go.sum @@ -129,7 +129,6 @@ github.com/gizak/termui/v3 v3.1.0 h1:ZZmVDgwHl7gR7elfKf1xc4IudXZ5qqfDh4wExk4Iajc github.com/gizak/termui/v3 v3.1.0/go.mod h1:bXQEBkJpzxUAKf0+xq9MSWAvWZlE7c+aidmyFlkYTrY= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q= -github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= @@ -262,7 +261,6 @@ github.com/jbenet/goprocess v0.1.4/go.mod h1:5yspPrukOVuOLORacaBi858NqyClJPQxYZl github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU= github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= -github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= @@ -270,7 +268,6 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/keybase/go-ps v0.0.0-20190827175125-91aafc93ba19/go.mod h1:hY+WOq6m2FpbvyrI93sMaypsttvaIL5nhVR92dTMUcQ= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= @@ -402,8 +399,6 @@ github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00/go.mod h1:pnIIfWopbDMQ1EW5Ddc6KDMqv8Qtx+hxbH9rorHpCyo= github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f h1:yd/G8iPBGOEAwbaS8zndJpO6bQk7Tk72ZhmlqRasThI= github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f/go.mod h1:E6nfj9EQzGxWDGM3Dn6eZWRC3qFy1G8IqOsYsBOcgWw= -github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240509103544-247ce5639c7a h1:7M+jXVlnl43zd2NuimL1KnAVAdpUr/QoHqG0TUKoyaM= -github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240509103544-247ce5639c7a/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo= github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240529093845-2a375eef5cc1 h1:C6NQcbfusGkhWP2FNvzafX2w7lKGSzZIius/fM5Gm3c= github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240529093845-2a375eef5cc1/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo= github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1 h1:5/h1i7Xd/JH9CiO3ZqvzAjdze+mAbar5sWkh2UqfLgI= @@ -418,7 +413,6 @@ github.com/multiversx/mx-components-big-int v1.0.0 h1:Wkr8lSzK2nDqixOrrBa47VNuqd github.com/multiversx/mx-components-big-int v1.0.0/go.mod h1:maIEMgHlNE2u78JaDD0oLzri+ShgU4okHfzP3LWGdQM= github.com/multiversx/protobuf v1.3.2 h1:RaNkxvGTGbA0lMcnHAN24qE1G1i+Xs5yHA6MDvQ4mSM= github.com/multiversx/protobuf v1.3.2/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= -github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo= github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM= github.com/nsf/termbox-go v0.0.0-20190121233118-02980233997d h1:x3S6kxmy49zXVVyhcnrFqxvNVCBPb2KZ9hV2RBdS840= diff --git a/integrationTests/vm/testInitializer.go b/integrationTests/vm/testInitializer.go index f1f14abbdda..cafdda755a2 100644 --- a/integrationTests/vm/testInitializer.go +++ b/integrationTests/vm/testInitializer.go @@ -126,7 +126,7 @@ type VMTestContext struct { TxFeeHandler process.TransactionFeeHandler ShardCoordinator sharding.Coordinator ScForwarder process.IntermediateTransactionHandler - EconomicsData process.CompleteEconomicsDataHandler + EconomicsData process.EconomicsDataHandler Marshalizer marshal.Marshalizer GasSchedule core.GasScheduleNotifier VMConfiguration *config.VirtualMachineConfig @@ -317,7 +317,7 @@ func CreateAccount(accnts state.AccountsAdapter, pubKey []byte, nonce uint64, ba return hashCreated, nil } -func createEconomicsData(enableEpochsConfig config.EnableEpochs) (process.CompleteEconomicsDataHandler, error) { +func createEconomicsData(enableEpochsConfig config.EnableEpochs) (process.EconomicsDataHandler, error) { maxGasLimitPerBlock := strconv.FormatUint(math.MaxUint64, 10) minGasPrice := strconv.FormatUint(1, 10) minGasLimit := strconv.FormatUint(1, 10) @@ -807,7 +807,7 @@ type ResultsCreateTxProcessor struct { TxProc process.TransactionProcessor SCProc scrCommon.TestSmartContractProcessor IntermediateTxProc process.IntermediateTransactionHandler - EconomicsHandler process.CompleteEconomicsDataHandler + EconomicsHandler process.EconomicsDataHandler CostHandler external.TransactionEvaluator TxLogProc process.TransactionLogProcessor } diff --git a/process/interface.go b/process/interface.go index 26094127611..911ab25105c 100644 --- a/process/interface.go +++ b/process/interface.go @@ -698,6 +698,7 @@ type feeHandler interface { ComputeGasLimitInEpoch(tx data.TransactionWithFeeHandler, epoch uint32) uint64 ComputeGasUsedAndFeeBasedOnRefundValueInEpoch(tx data.TransactionWithFeeHandler, refundValue *big.Int, epoch uint32) (uint64, *big.Int) ComputeTxFeeBasedOnGasUsedInEpoch(tx data.TransactionWithFeeHandler, gasUsed uint64, epoch uint32) *big.Int + MaxGasHigherFactorAccepted() uint64 } // TxGasHandler handles a transaction gas and gas cost @@ -716,7 +717,6 @@ type TxGasHandler interface { // FeeHandler is able to perform some economics calculation on a provided transaction type FeeHandler interface { feeHandler - MaxGasHigherFactorAccepted() uint64 IsInterfaceNil() bool } @@ -728,15 +728,6 @@ type EconomicsDataHandler interface { IsInterfaceNil() bool } -// CompleteEconomicsDataHandler provides some economics related computation and read access to economics data -type CompleteEconomicsDataHandler interface { - rewardsHandler - feeHandler - MaxGasHigherFactorAccepted() uint64 - SetStatusHandler(statusHandler core.AppStatusHandler) error - IsInterfaceNil() bool -} - // SmartContractToProtocolHandler is able to translate data from smart contract state into protocol changes type SmartContractToProtocolHandler interface { UpdateProtocol(body *block.Body, nonce uint64) error diff --git a/testscommon/economicsmocks/economicsHandlerMock.go b/testscommon/economicsmocks/economicsHandlerMock.go index 88a54c90e72..0e8f0001b06 100644 --- a/testscommon/economicsmocks/economicsHandlerMock.go +++ b/testscommon/economicsmocks/economicsHandlerMock.go @@ -30,6 +30,7 @@ type EconomicsHandlerMock struct { DeveloperPercentageCalled func() float64 MinGasPriceCalled func() uint64 GasPerDataByteCalled func() uint64 + MaxGasHigherFactorAcceptedCalled func() uint64 RewardsTopUpGradientPointCalled func() *big.Int RewardsTopUpFactorCalled func() float64 ComputeFeeForProcessingCalled func(tx data.TransactionWithFeeHandler, gasToUse uint64) *big.Int @@ -335,6 +336,14 @@ func (ehm *EconomicsHandlerMock) ComputeTxFeeBasedOnGasUsedInEpoch(tx data.Trans return nil } +// MaxGasHigherFactorAccepted - +func (ehm *EconomicsHandlerMock) MaxGasHigherFactorAccepted() uint64 { + if ehm.MaxGasHigherFactorAcceptedCalled != nil { + return ehm.MaxGasHigherFactorAcceptedCalled() + } + return 10 +} + // IsInterfaceNil returns true if there is no value under the interface func (ehm *EconomicsHandlerMock) IsInterfaceNil() bool { return ehm == nil From e89eabdf1660748b6e705f9de215f653621ff6e1 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 18 Jun 2024 15:13:08 +0300 Subject: [PATCH 225/467] 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 e6f889452b2018a93800cc2612476f4b5a0a78af Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 18 Jun 2024 15:46:38 +0300 Subject: [PATCH 226/467] adding tests --- process/economics/export_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/process/economics/export_test.go b/process/economics/export_test.go index f466b60301e..fac481d4086 100644 --- a/process/economics/export_test.go +++ b/process/economics/export_test.go @@ -37,6 +37,7 @@ func (ed *economicsData) GetGasLimitSetting(epoch uint32) *config.GasLimitSettin gasLimitSetting.MaxGasLimitPerTx = strconv.FormatUint(cfg.maxGasLimitPerTx, 10) gasLimitSetting.MinGasLimit = strconv.FormatUint(cfg.minGasLimit, 10) gasLimitSetting.ExtraGasLimitGuardedTx = strconv.FormatUint(cfg.extraGasLimitGuardedTx, 10) + gasLimitSetting.MaxGasHigherFactorAccepted = strconv.FormatUint(cfg.maxGasHigherFactorAccepted, 10) return gasLimitSetting } From 8d4a515f70ac90703b0008206b67b2ff7e245d93 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Tue, 18 Jun 2024 15:58:44 +0300 Subject: [PATCH 227/467] 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 228/467] 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 229/467] 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 230/467] 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 231/467] 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 232/467] 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 233/467] 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 234/467] 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 235/467] new version es indexer --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 9fc119c930a..786caa073f5 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e github.com/multiversx/mx-chain-core-go v1.2.21-0.20240530111258-45870512bfbe github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df - github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240514103357-929ece92ef86 + github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619060917-731bddac4821 github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f diff --git a/go.sum b/go.sum index 5d1b6238dbe..47c61e5e62d 100644 --- a/go.sum +++ b/go.sum @@ -391,8 +391,8 @@ github.com/multiversx/mx-chain-core-go v1.2.21-0.20240530111258-45870512bfbe h1: github.com/multiversx/mx-chain-core-go v1.2.21-0.20240530111258-45870512bfbe/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df h1:clihfi78bMEOWk/qw6WA4uQbCM2e2NGliqswLAvw19k= github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df/go.mod h1:gtJYB4rR21KBSqJlazn+2z6f9gFSqQP3KvAgL7Qgxw4= -github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240514103357-929ece92ef86 h1:rw+u7qv0HO+7lRddCzfciqDcAWL9/fl2LQqU8AmVtdU= -github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240514103357-929ece92ef86/go.mod h1:UDKRXmxsSyPeAcjLUfGeYkAtYp424PIYkL82kzFYobM= +github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619060917-731bddac4821 h1:rB5XbWMILQJLH1GmsXjdfE28+k1cvovyP0/M77jrcs4= +github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619060917-731bddac4821/go.mod h1:Phf/QUo+JG6aoyUrktqPKg6exkj+Uz2kT5a8Tiyises= github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 h1:g9t410dqjcb7UUptbVd/H6Ua12sEzWU4v7VplyNvRZ0= github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57/go.mod h1:cY6CIXpndW5g5PTPn4WzPwka/UBEf+mgw+PSY5pHGAU= github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 h1:hFEcbGBtXu8UyB9BMhmAIH2R8BtV/NOq/rsxespLCN8= From 640552c4ea91cbf4da11366f9250cb6d73cd4e44 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 19 Jun 2024 12:56:04 +0300 Subject: [PATCH 236/467] gasScheduleV8 --- cmd/node/config/enableEpochs.toml | 2 +- .../config/gasSchedules/gasScheduleV8.toml | 828 ++++++++++++++++++ .../components/coreComponents_test.go | 2 +- .../components/processComponents_test.go | 2 +- 4 files changed, 831 insertions(+), 3 deletions(-) create mode 100644 cmd/node/config/gasSchedules/gasScheduleV8.toml diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index 9502cceba9a..dce2d48be2c 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -329,5 +329,5 @@ [GasSchedule] # GasScheduleByEpochs holds the configuration for the gas schedule that will be applied from specific epochs GasScheduleByEpochs = [ - { StartEpoch = 0, FileName = "gasScheduleV7.toml" }, + { StartEpoch = 0, FileName = "gasScheduleV8.toml" }, ] diff --git a/cmd/node/config/gasSchedules/gasScheduleV8.toml b/cmd/node/config/gasSchedules/gasScheduleV8.toml new file mode 100644 index 00000000000..3f30d694591 --- /dev/null +++ b/cmd/node/config/gasSchedules/gasScheduleV8.toml @@ -0,0 +1,828 @@ +[BuiltInCost] + ChangeOwnerAddress = 5000000 + ClaimDeveloperRewards = 5000000 + SaveUserName = 1000000 + SaveKeyValue = 100000 + ESDTTransfer = 200000 + ESDTBurn = 100000 + ESDTLocalMint = 50000 + ESDTLocalBurn = 50000 + ESDTNFTCreate = 150000 + ESDTNFTAddQuantity = 50000 + ESDTNFTBurn = 50000 + ESDTNFTTransfer = 200000 + ESDTNFTChangeCreateOwner = 1000000 + ESDTNFTAddUri = 50000 + ESDTNFTUpdateAttributes = 50000 + ESDTNFTMultiTransfer = 200000 + MultiESDTNFTTransfer = 200000 # should be the same value with the ESDTNFTMultiTransfer + SetGuardian = 250000 + GuardAccount = 250000 + UnGuardAccount = 250000 + TrieLoadPerNode = 100000 + TrieStorePerNode = 50000 + +[MetaChainSystemSCsCost] + Stake = 5000000 + UnStake = 5000000 + UnBond = 5000000 + Claim = 5000000 + Get = 5000000 + ChangeRewardAddress = 5000000 + ChangeValidatorKeys = 5000000 + UnJail = 5000000 + DelegationOps = 1000000 + DelegationMgrOps = 50000000 + ValidatorToDelegation = 500000000 + ESDTIssue = 50000000 + ESDTOperations = 50000000 + Proposal = 50000000 + Vote = 5000000 + DelegateVote = 50000000 + RevokeVote = 50000000 + CloseProposal = 50000000 + GetAllNodeStates = 20000000 + UnstakeTokens = 5000000 + UnbondTokens = 5000000 + GetActiveFund = 50000 + FixWaitingListSize = 500000000 + +[BaseOperationCost] + StorePerByte = 10000 + ReleasePerByte = 1000 + DataCopyPerByte = 50 + PersistPerByte = 1000 + CompilePerByte = 300 + AoTPreparePerByte = 100 + GetCode = 1000000 + +[BaseOpsAPICost] + GetSCAddress = 1000 + GetOwnerAddress = 5000 + IsSmartContract = 5000 + GetShardOfAddress = 5000 + GetExternalBalance = 7000 + GetBlockHash = 10000 + TransferValue = 100000 + GetArgument = 1000 + GetFunction = 1000 + GetNumArguments = 1000 + StorageStore = 75000 + StorageLoad = 50000 + CachedStorageLoad = 1000 + GetCaller = 1000 + GetCallValue = 1000 + Log = 3750 + Finish = 1 + SignalError = 1 + GetBlockTimeStamp = 10000 + GetGasLeft = 1000 + Int64GetArgument = 1000 + Int64StorageStore = 75000 + Int64StorageLoad = 50000 + Int64Finish = 1000 + GetStateRootHash = 10000 + GetBlockNonce = 10000 + GetBlockEpoch = 10000 + GetBlockRound = 10000 + GetBlockRandomSeed = 10000 + ExecuteOnSameContext = 100000 + ExecuteOnDestContext = 100000 + DelegateExecution = 100000 + AsyncCallStep = 100000 + AsyncCallbackGasLock = 4000000 + ExecuteReadOnly = 160000 + CreateContract = 300000 + GetReturnData = 1000 + GetNumReturnData = 1000 + GetReturnDataSize = 1000 + GetOriginalTxHash = 10000 + CleanReturnData = 1000 + DeleteFromReturnData = 1000 + GetPrevTxHash = 10000 + GetCurrentTxHash = 10000 + CreateAsyncCall = 200000 + SetAsyncCallback = 100000 + SetAsyncGroupCallback = 100000 + SetAsyncContextCallback = 100000 + GetCallbackClosure = 10000 + GetCodeMetadata = 10000 + IsBuiltinFunction = 10000 + +[EthAPICost] + UseGas = 100 + GetAddress = 100000 + GetExternalBalance = 70000 + GetBlockHash = 100000 + Call = 160000 + CallDataCopy = 200 + GetCallDataSize = 100 + CallCode = 160000 + CallDelegate = 160000 + CallStatic = 160000 + StorageStore = 250000 + StorageLoad = 100000 + GetCaller = 100 + GetCallValue = 100 + CodeCopy = 1000 + GetCodeSize = 100 + GetBlockCoinbase = 100 + Create = 320000 + GetBlockDifficulty = 100 + ExternalCodeCopy = 3000 + GetExternalCodeSize = 2500 + GetGasLeft = 100 + GetBlockGasLimit = 100000 + GetTxGasPrice = 1000 + Log = 3750 + GetBlockNumber = 100000 + GetTxOrigin = 100000 + Finish = 1 + Revert = 1 + GetReturnDataSize = 200 + ReturnDataCopy = 500 + SelfDestruct = 5000000 + GetBlockTimeStamp = 100000 + +[BigIntAPICost] + BigIntNew = 2000 + BigIntByteLength = 2000 + BigIntUnsignedByteLength = 2000 + BigIntSignedByteLength = 2000 + BigIntGetBytes = 2000 + BigIntGetUnsignedBytes = 2000 + BigIntGetSignedBytes = 2000 + BigIntSetBytes = 2000 + BigIntSetUnsignedBytes = 2000 + BigIntSetSignedBytes = 2000 + BigIntIsInt64 = 2000 + BigIntGetInt64 = 2000 + BigIntSetInt64 = 2000 + BigIntAdd = 2000 + BigIntSub = 2000 + BigIntMul = 6000 + BigIntSqrt = 6000 + BigIntPow = 6000 + BigIntLog = 6000 + BigIntTDiv = 6000 + BigIntTMod = 6000 + BigIntEDiv = 6000 + BigIntEMod = 6000 + BigIntAbs = 2000 + BigIntNeg = 2000 + BigIntSign = 2000 + BigIntCmp = 2000 + BigIntNot = 2000 + BigIntAnd = 2000 + BigIntOr = 2000 + BigIntXor = 2000 + BigIntShr = 2000 + BigIntShl = 2000 + BigIntFinishUnsigned = 1000 + BigIntFinishSigned = 1000 + BigIntStorageLoadUnsigned = 50000 + BigIntStorageStoreUnsigned = 75000 + BigIntGetArgument = 1000 + BigIntGetUnsignedArgument = 1000 + BigIntGetSignedArgument = 1000 + BigIntGetCallValue = 1000 + BigIntGetExternalBalance = 10000 + CopyPerByteForTooBig = 1000 + +[CryptoAPICost] + SHA256 = 1000000 + Keccak256 = 1000000 + Ripemd160 = 1000000 + VerifyBLS = 5000000 + VerifyEd25519 = 2000000 + VerifySecp256k1 = 2000000 + EllipticCurveNew = 10000 + AddECC = 75000 + DoubleECC = 65000 + IsOnCurveECC = 10000 + ScalarMultECC = 400000 + MarshalECC = 13000 + MarshalCompressedECC = 15000 + UnmarshalECC = 20000 + UnmarshalCompressedECC = 270000 + GenerateKeyECC = 7000000 + EncodeDERSig = 10000000 + +[ManagedBufferAPICost] + MBufferNew = 2000 + MBufferNewFromBytes = 2000 + MBufferGetLength = 2000 + MBufferGetBytes = 2000 + MBufferGetByteSlice = 2000 + MBufferCopyByteSlice = 2000 + MBufferSetBytes = 2000 + MBufferAppend = 2000 + MBufferAppendBytes = 2000 + MBufferToBigIntUnsigned = 2000 + MBufferToBigIntSigned = 5000 + MBufferFromBigIntUnsigned = 2000 + MBufferFromBigIntSigned = 5000 + MBufferStorageStore = 75000 + MBufferStorageLoad = 50000 + MBufferGetArgument = 1000 + MBufferFinish = 1000 + MBufferSetRandom = 6000 + MBufferToBigFloat = 2000 + MBufferFromBigFloat = 2000 + +[BigFloatAPICost] + BigFloatNewFromParts = 3000 + BigFloatAdd = 7000 + BigFloatSub = 7000 + BigFloatMul = 7000 + BigFloatDiv = 7000 + BigFloatTruncate = 5000 + BigFloatNeg = 5000 + BigFloatClone = 5000 + BigFloatCmp = 4000 + BigFloatAbs = 5000 + BigFloatSqrt = 7000 + BigFloatPow = 10000 + BigFloatFloor = 5000 + BigFloatCeil = 5000 + BigFloatIsInt = 3000 + BigFloatSetBigInt = 3000 + BigFloatSetInt64 = 1000 + BigFloatGetConst = 1000 + +[WASMOpcodeCost] + Unreachable = 5 + Nop = 5 + Block = 5 + Loop = 5 + If = 5 + Else = 5 + End = 5 + Br = 5 + BrIf = 5 + BrTable = 5 + Return = 5 + Call = 5 + CallIndirect = 5 + Drop = 5 + Select = 5 + TypedSelect = 5 + LocalGet = 5 + LocalSet = 5 + LocalTee = 5 + GlobalGet = 5 + GlobalSet = 5 + I32Load = 5 + I64Load = 5 + F32Load = 6 + F64Load = 6 + I32Load8S = 5 + I32Load8U = 5 + I32Load16S = 5 + I32Load16U = 5 + I64Load8S = 5 + I64Load8U = 5 + I64Load16S = 5 + I64Load16U = 5 + I64Load32S = 5 + I64Load32U = 5 + I32Store = 5 + I64Store = 5 + F32Store = 12 + F64Store = 12 + I32Store8 = 5 + I32Store16 = 5 + I64Store8 = 5 + I64Store16 = 5 + I64Store32 = 5 + MemorySize = 5 + MemoryGrow = 1000000 + I32Const = 5 + I64Const = 5 + F32Const = 5 + F64Const = 5 + RefNull = 5 + RefIsNull = 5 + RefFunc = 5 + I32Eqz = 5 + I32Eq = 5 + I32Ne = 5 + I32LtS = 5 + I32LtU = 5 + I32GtS = 5 + I32GtU = 5 + I32LeS = 5 + I32LeU = 5 + I32GeS = 5 + I32GeU = 5 + I64Eqz = 5 + I64Eq = 5 + I64Ne = 5 + I64LtS = 5 + I64LtU = 5 + I64GtS = 5 + I64GtU = 5 + I64LeS = 5 + I64LeU = 5 + I64GeS = 5 + I64GeU = 5 + F32Eq = 6 + F32Ne = 6 + F32Lt = 6 + F32Gt = 6 + F32Le = 6 + F32Ge = 6 + F64Eq = 6 + F64Ne = 6 + F64Lt = 6 + F64Gt = 6 + F64Le = 6 + F64Ge = 6 + I32Clz = 100 + I32Ctz = 100 + I32Popcnt = 100 + I32Add = 5 + I32Sub = 5 + I32Mul = 5 + I32DivS = 18 + I32DivU = 18 + I32RemS = 18 + I32RemU = 18 + I32And = 5 + I32Or = 5 + I32Xor = 5 + I32Shl = 5 + I32ShrS = 5 + I32ShrU = 5 + I32Rotl = 5 + I32Rotr = 5 + I64Clz = 100 + I64Ctz = 100 + I64Popcnt = 100 + I64Add = 5 + I64Sub = 5 + I64Mul = 5 + I64DivS = 18 + I64DivU = 18 + I64RemS = 18 + I64RemU = 18 + I64And = 5 + I64Or = 5 + I64Xor = 5 + I64Shl = 5 + I64ShrS = 5 + I64ShrU = 5 + I64Rotl = 5 + I64Rotr = 5 + F32Abs = 5 + F32Neg = 5 + F32Ceil = 100 + F32Floor = 100 + F32Trunc = 100 + F32Nearest = 100 + F32Sqrt = 100 + F32Add = 5 + F32Sub = 5 + F32Mul = 15 + F32Div = 100 + F32Min = 15 + F32Max = 15 + F32Copysign = 5 + F64Abs = 5 + F64Neg = 5 + F64Ceil = 100 + F64Floor = 100 + F64Trunc = 100 + F64Nearest = 100 + F64Sqrt = 100 + F64Add = 5 + F64Sub = 5 + F64Mul = 15 + F64Div = 100 + F64Min = 15 + F64Max = 15 + F64Copysign = 5 + I32WrapI64 = 9 + I32TruncF32S = 100 + I32TruncF32U = 100 + I32TruncF64S = 100 + I32TruncF64U = 100 + I64ExtendI32S = 9 + I64ExtendI32U = 9 + I64TruncF32S = 100 + I64TruncF32U = 100 + I64TruncF64S = 100 + I64TruncF64U = 100 + F32ConvertI32S = 100 + F32ConvertI32U = 100 + F32ConvertI64S = 100 + F32ConvertI64U = 100 + F32DemoteF64 = 100 + F64ConvertI32S = 100 + F64ConvertI32U = 100 + F64ConvertI64S = 100 + F64ConvertI64U = 100 + F64PromoteF32 = 100 + I32ReinterpretF32 = 100 + I64ReinterpretF64 = 100 + F32ReinterpretI32 = 100 + F64ReinterpretI64 = 100 + I32Extend8S = 9 + I32Extend16S = 9 + I64Extend8S = 9 + I64Extend16S = 9 + I64Extend32S = 9 + I32TruncSatF32S = 100 + I32TruncSatF32U = 100 + I32TruncSatF64S = 100 + I32TruncSatF64U = 100 + I64TruncSatF32S = 100 + I64TruncSatF32U = 100 + I64TruncSatF64S = 100 + I64TruncSatF64U = 100 + MemoryInit = 5 + DataDrop = 5 + MemoryCopy = 5 + MemoryFill = 5 + TableInit = 10 + ElemDrop = 10 + TableCopy = 10 + TableFill = 10 + TableGet = 10 + TableSet = 10 + TableGrow = 10 + TableSize = 10 + AtomicNotify = 1000000 + I32AtomicWait = 1000000 + I64AtomicWait = 1000000 + AtomicFence = 1000000 + I32AtomicLoad = 1000000 + I64AtomicLoad = 1000000 + I32AtomicLoad8U = 1000000 + I32AtomicLoad16U = 1000000 + I64AtomicLoad8U = 1000000 + I64AtomicLoad16U = 1000000 + I64AtomicLoad32U = 1000000 + I32AtomicStore = 1000000 + I64AtomicStore = 1000000 + I32AtomicStore8 = 1000000 + I32AtomicStore16 = 1000000 + I64AtomicStore8 = 1000000 + I64AtomicStore16 = 1000000 + I64AtomicStore32 = 1000000 + I32AtomicRmwAdd = 1000000 + I64AtomicRmwAdd = 1000000 + I32AtomicRmw8AddU = 1000000 + I32AtomicRmw16AddU = 1000000 + I64AtomicRmw8AddU = 1000000 + I64AtomicRmw16AddU = 1000000 + I64AtomicRmw32AddU = 1000000 + I32AtomicRmwSub = 1000000 + I64AtomicRmwSub = 1000000 + I32AtomicRmw8SubU = 1000000 + I32AtomicRmw16SubU = 1000000 + I64AtomicRmw8SubU = 1000000 + I64AtomicRmw16SubU = 1000000 + I64AtomicRmw32SubU = 1000000 + I32AtomicRmwAnd = 1000000 + I64AtomicRmwAnd = 1000000 + I32AtomicRmw8AndU = 1000000 + I32AtomicRmw16AndU = 1000000 + I64AtomicRmw8AndU = 1000000 + I64AtomicRmw16AndU = 1000000 + I64AtomicRmw32AndU = 1000000 + I32AtomicRmwOr = 1000000 + I64AtomicRmwOr = 1000000 + I32AtomicRmw8OrU = 1000000 + I32AtomicRmw16OrU = 1000000 + I64AtomicRmw8OrU = 1000000 + I64AtomicRmw16OrU = 1000000 + I64AtomicRmw32OrU = 1000000 + I32AtomicRmwXor = 1000000 + I64AtomicRmwXor = 1000000 + I32AtomicRmw8XorU = 1000000 + I32AtomicRmw16XorU = 1000000 + I64AtomicRmw8XorU = 1000000 + I64AtomicRmw16XorU = 1000000 + I64AtomicRmw32XorU = 1000000 + I32AtomicRmwXchg = 1000000 + I64AtomicRmwXchg = 1000000 + I32AtomicRmw8XchgU = 1000000 + I32AtomicRmw16XchgU = 1000000 + I64AtomicRmw8XchgU = 1000000 + I64AtomicRmw16XchgU = 1000000 + I64AtomicRmw32XchgU = 1000000 + I32AtomicRmwCmpxchg = 1000000 + I64AtomicRmwCmpxchg = 1000000 + I32AtomicRmw8CmpxchgU = 1000000 + I32AtomicRmw16CmpxchgU = 1000000 + I64AtomicRmw8CmpxchgU = 1000000 + I64AtomicRmw16CmpxchgU = 1000000 + I64AtomicRmw32CmpxchgU = 1000000 + V128Load = 1000000 + V128Store = 1000000 + V128Const = 1000000 + I8x16Splat = 1000000 + I8x16ExtractLaneS = 1000000 + I8x16ExtractLaneU = 1000000 + I8x16ReplaceLane = 1000000 + I16x8Splat = 1000000 + I16x8ExtractLaneS = 1000000 + I16x8ExtractLaneU = 1000000 + I16x8ReplaceLane = 1000000 + I32x4Splat = 1000000 + I32x4ExtractLane = 1000000 + I32x4ReplaceLane = 1000000 + I64x2Splat = 1000000 + I64x2ExtractLane = 1000000 + I64x2ReplaceLane = 1000000 + F32x4Splat = 1000000 + F32x4ExtractLane = 1000000 + F32x4ReplaceLane = 1000000 + F64x2Splat = 1000000 + F64x2ExtractLane = 1000000 + F64x2ReplaceLane = 1000000 + I8x16Eq = 1000000 + I8x16Ne = 1000000 + I8x16LtS = 1000000 + I8x16LtU = 1000000 + I8x16GtS = 1000000 + I8x16GtU = 1000000 + I8x16LeS = 1000000 + I8x16LeU = 1000000 + I8x16GeS = 1000000 + I8x16GeU = 1000000 + I16x8Eq = 1000000 + I16x8Ne = 1000000 + I16x8LtS = 1000000 + I16x8LtU = 1000000 + I16x8GtS = 1000000 + I16x8GtU = 1000000 + I16x8LeS = 1000000 + I16x8LeU = 1000000 + I16x8GeS = 1000000 + I16x8GeU = 1000000 + I32x4Eq = 1000000 + I32x4Ne = 1000000 + I32x4LtS = 1000000 + I32x4LtU = 1000000 + I32x4GtS = 1000000 + I32x4GtU = 1000000 + I32x4LeS = 1000000 + I32x4LeU = 1000000 + I32x4GeS = 1000000 + I32x4GeU = 1000000 + F32x4Eq = 1000000 + F32x4Ne = 1000000 + F32x4Lt = 1000000 + F32x4Gt = 1000000 + F32x4Le = 1000000 + F32x4Ge = 1000000 + F64x2Eq = 1000000 + F64x2Ne = 1000000 + F64x2Lt = 1000000 + F64x2Gt = 1000000 + F64x2Le = 1000000 + F64x2Ge = 1000000 + V128Not = 1000000 + V128And = 1000000 + V128AndNot = 1000000 + V128Or = 1000000 + V128Xor = 1000000 + V128Bitselect = 1000000 + I8x16Neg = 1000000 + I8x16AnyTrue = 1000000 + I8x16AllTrue = 1000000 + I8x16Shl = 1000000 + I8x16ShrS = 1000000 + I8x16ShrU = 1000000 + I8x16Add = 1000000 + I8x16AddSaturateS = 1000000 + I8x16AddSaturateU = 1000000 + I8x16Sub = 1000000 + I8x16SubSaturateS = 1000000 + I8x16SubSaturateU = 1000000 + I8x16MinS = 1000000 + I8x16MinU = 1000000 + I8x16MaxS = 1000000 + I8x16MaxU = 1000000 + I8x16Mul = 1000000 + I16x8Neg = 1000000 + I16x8AnyTrue = 1000000 + I16x8AllTrue = 1000000 + I16x8Shl = 1000000 + I16x8ShrS = 1000000 + I16x8ShrU = 1000000 + I16x8Add = 1000000 + I16x8AddSaturateS = 1000000 + I16x8AddSaturateU = 1000000 + I16x8Sub = 1000000 + I16x8SubSaturateS = 1000000 + I16x8SubSaturateU = 1000000 + I16x8Mul = 1000000 + I16x8MinS = 1000000 + I16x8MinU = 1000000 + I16x8MaxS = 1000000 + I16x8MaxU = 1000000 + I32x4Neg = 1000000 + I32x4AnyTrue = 1000000 + I32x4AllTrue = 1000000 + I32x4Shl = 1000000 + I32x4ShrS = 1000000 + I32x4ShrU = 1000000 + I32x4Add = 1000000 + I32x4Sub = 1000000 + I32x4Mul = 1000000 + I32x4MinS = 1000000 + I32x4MinU = 1000000 + I32x4MaxS = 1000000 + I32x4MaxU = 1000000 + I64x2Neg = 1000000 + I64x2AnyTrue = 1000000 + I64x2AllTrue = 1000000 + I64x2Shl = 1000000 + I64x2ShrS = 1000000 + I64x2ShrU = 1000000 + I64x2Add = 1000000 + I64x2Sub = 1000000 + I64x2Mul = 1000000 + F32x4Abs = 1000000 + F32x4Neg = 1000000 + F32x4Sqrt = 1000000 + F32x4Add = 1000000 + F32x4Sub = 1000000 + F32x4Mul = 1000000 + F32x4Div = 1000000 + F32x4Min = 1000000 + F32x4Max = 1000000 + F64x2Abs = 1000000 + F64x2Neg = 1000000 + F64x2Sqrt = 1000000 + F64x2Add = 1000000 + F64x2Sub = 1000000 + F64x2Mul = 1000000 + F64x2Div = 1000000 + F64x2Min = 1000000 + F64x2Max = 1000000 + I32x4TruncSatF32x4S = 1000000 + I32x4TruncSatF32x4U = 1000000 + I64x2TruncSatF64x2S = 1000000 + I64x2TruncSatF64x2U = 1000000 + F32x4ConvertI32x4S = 1000000 + F32x4ConvertI32x4U = 1000000 + F64x2ConvertI64x2S = 1000000 + F64x2ConvertI64x2U = 1000000 + V8x16Swizzle = 1000000 + V8x16Shuffle = 1000000 + V8x16LoadSplat = 1000000 + V16x8LoadSplat = 1000000 + V32x4LoadSplat = 1000000 + V64x2LoadSplat = 1000000 + I8x16NarrowI16x8S = 1000000 + I8x16NarrowI16x8U = 1000000 + I16x8NarrowI32x4S = 1000000 + I16x8NarrowI32x4U = 1000000 + I16x8WidenLowI8x16S = 1000000 + I16x8WidenHighI8x16S = 1000000 + I16x8WidenLowI8x16U = 1000000 + I16x8WidenHighI8x16U = 1000000 + I32x4WidenLowI16x8S = 1000000 + I32x4WidenHighI16x8S = 1000000 + I32x4WidenLowI16x8U = 1000000 + I32x4WidenHighI16x8U = 1000000 + I16x8Load8x8S = 1000000 + I16x8Load8x8U = 1000000 + I32x4Load16x4S = 1000000 + I32x4Load16x4U = 1000000 + I64x2Load32x2S = 1000000 + I64x2Load32x2U = 1000000 + I8x16RoundingAverageU = 1000000 + I16x8RoundingAverageU = 1000000 + LocalAllocate = 5 + LocalsUnmetered = 100 + MaxMemoryGrowDelta = 1 + MaxMemoryGrow = 10 + Catch = 10 + CatchAll = 10 + Delegate = 10 + Rethrow = 10 + ReturnCall = 10 + ReturnCallIndirect = 10 + Throw = 10 + Try = 10 + Unwind = 10 + F32x4Ceil = 1000000 + F32x4DemoteF64x2Zero = 1000000 + F32x4Floor = 1000000 + F32x4Nearest = 1000000 + F32x4PMax = 1000000 + F32x4PMin = 1000000 + F32x4Trunc = 1000000 + F64x2Ceil = 1000000 + F64x2ConvertLowI32x4S = 1000000 + F64x2ConvertLowI32x4U = 1000000 + F64x2Floor = 1000000 + F64x2Nearest = 1000000 + F64x2PMax = 1000000 + F64x2PMin = 1000000 + F64x2PromoteLowF32x4 = 1000000 + F64x2Trunc = 1000000 + I16x8Abs = 1000000 + I16x8AddSatS = 1000000 + I16x8AddSatU = 1000000 + I16x8Bitmask = 1000000 + I16x8ExtAddPairwiseI8x16S = 1000000 + I16x8ExtAddPairwiseI8x16U = 1000000 + I16x8ExtMulHighI8x16S = 1000000 + I16x8ExtMulHighI8x16U = 1000000 + I16x8ExtMulLowI8x16S = 1000000 + I16x8ExtMulLowI8x16U = 1000000 + I16x8ExtendHighI8x16S = 1000000 + I16x8ExtendHighI8x16U = 1000000 + I16x8ExtendLowI8x16S = 1000000 + I16x8ExtendLowI8x16U = 1000000 + I16x8Q15MulrSatS = 1000000 + I16x8SubSatS = 1000000 + I16x8SubSatU = 1000000 + I32x4Abs = 1000000 + I32x4Bitmask = 1000000 + I32x4DotI16x8S = 1000000 + I32x4ExtAddPairwiseI16x8S = 1000000 + I32x4ExtAddPairwiseI16x8U = 1000000 + I32x4ExtMulHighI16x8S = 1000000 + I32x4ExtMulHighI16x8U = 1000000 + I32x4ExtMulLowI16x8S = 1000000 + I32x4ExtMulLowI16x8U = 1000000 + I32x4ExtendHighI16x8S = 1000000 + I32x4ExtendHighI16x8U = 1000000 + I32x4ExtendLowI16x8S = 1000000 + I32x4ExtendLowI16x8U = 1000000 + I32x4TruncSatF64x2SZero = 1000000 + I32x4TruncSatF64x2UZero = 1000000 + I64x2Abs = 1000000 + I64x2Bitmask = 1000000 + I64x2Eq = 1000000 + I64x2ExtMulHighI32x4S = 1000000 + I64x2ExtMulHighI32x4U = 1000000 + I64x2ExtMulLowI32x4S = 1000000 + I64x2ExtMulLowI32x4U = 1000000 + I64x2ExtendHighI32x4S = 1000000 + I64x2ExtendHighI32x4U = 1000000 + I64x2ExtendLowI32x4S = 1000000 + I64x2ExtendLowI32x4U = 1000000 + I64x2GeS = 1000000 + I64x2GtS = 1000000 + I64x2LeS = 1000000 + I64x2LtS = 1000000 + I64x2Ne = 1000000 + I8x16Abs = 1000000 + I8x16AddSatS = 1000000 + I8x16AddSatU = 1000000 + I8x16Bitmask = 1000000 + I8x16Popcnt = 1000000 + I8x16Shuffle = 1000000 + I8x16SubSatS = 1000000 + I8x16SubSatU = 1000000 + I8x16Swizzle = 1000000 + MemoryAtomicNotify = 1000000 + MemoryAtomicWait32 = 1000000 + MemoryAtomicWait64 = 1000000 + V128AnyTrue = 1000000 + V128Load16Lane = 1000000 + V128Load16Splat = 1000000 + V128Load16x4S = 1000000 + V128Load16x4U = 1000000 + V128Load32Lane = 1000000 + V128Load32Splat = 1000000 + V128Load32Zero = 1000000 + V128Load32x2S = 1000000 + V128Load32x2U = 1000000 + V128Load64Lane = 1000000 + V128Load64Splat = 1000000 + V128Load64Zero = 1000000 + V128Load8Lane = 1000000 + V128Load8Splat = 1000000 + V128Load8x8S = 1000000 + V128Load8x8U = 1000000 + V128Store16Lane = 1000000 + V128Store32Lane = 1000000 + V128Store64Lane = 1000000 + V128Store8Lane = 1000000 + +[MaxPerTransaction] + MaxBuiltInCallsPerTx = 100 + MaxNumberOfTransfersPerTx = 250 + MaxNumberOfTrieReadsPerTx = 1500 + +# Quadratic, Linear and Constant are the coefficients for a quadratic func. Separate variables are used for the +# sign of each coefficient, 0 meaning positive and 1 meaning negative +# The current values for the coefficients were computed based on benchmarking. +# For the given coefficients, the minimum of the function must not be lower than MinimumGasCost +[DynamicStorageLoad] + QuadraticCoefficient = 688 + SignOfQuadratic = 0 + LinearCoefficient = 31858 + SignOfLinear = 0 + ConstantCoefficient = 15287 + SignOfConstant = 0 + MinimumGasCost = 10000 diff --git a/node/chainSimulator/components/coreComponents_test.go b/node/chainSimulator/components/coreComponents_test.go index 619eb9d3a2e..f11899f66f8 100644 --- a/node/chainSimulator/components/coreComponents_test.go +++ b/node/chainSimulator/components/coreComponents_test.go @@ -127,7 +127,7 @@ func createArgsCoreComponentsHolder() ArgsCoreComponentsHolder { ChanStopNodeProcess: make(chan endProcess.ArgEndProcess), InitialRound: 0, NodesSetupPath: "../../../sharding/mock/testdata/nodesSetupMock.json", - GasScheduleFilename: "../../../cmd/node/config/gasSchedules/gasScheduleV7.toml", + GasScheduleFilename: "../../../cmd/node/config/gasSchedules/gasScheduleV8.toml", NumShards: 3, WorkingDir: ".", MinNodesPerShard: 1, diff --git a/node/chainSimulator/components/processComponents_test.go b/node/chainSimulator/components/processComponents_test.go index efc5590e7f4..a8cb2f053e7 100644 --- a/node/chainSimulator/components/processComponents_test.go +++ b/node/chainSimulator/components/processComponents_test.go @@ -66,7 +66,7 @@ func createArgsProcessComponentsHolder() ArgsProcessComponentsHolder { GasScheduleByEpochs: []config.GasScheduleByEpochs{ { StartEpoch: 0, - FileName: "../../../cmd/node/config/gasSchedules/gasScheduleV7.toml", + FileName: "../../../cmd/node/config/gasSchedules/gasScheduleV8.toml", }, }, }, From 8443b80b748ce687609cde68863d4d3b6fc3e4fc Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 19 Jun 2024 14:34:19 +0300 Subject: [PATCH 237/467] 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 238/467] 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 239/467] 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 240/467] 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 241/467] 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 242/467] latest vm common and indexer --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 786caa073f5..1b381e3a86f 100644 --- a/go.mod +++ b/go.mod @@ -17,11 +17,11 @@ require ( github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e github.com/multiversx/mx-chain-core-go v1.2.21-0.20240530111258-45870512bfbe github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df - github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619060917-731bddac4821 + github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619122842-05143459c554 github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f - github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240618133316-4c17adfcaea6 + github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240619122724-2bd2e64cebdc github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240509104009-598a37ff36b9 diff --git a/go.sum b/go.sum index 47c61e5e62d..f7cc76137bf 100644 --- a/go.sum +++ b/go.sum @@ -391,16 +391,16 @@ github.com/multiversx/mx-chain-core-go v1.2.21-0.20240530111258-45870512bfbe h1: github.com/multiversx/mx-chain-core-go v1.2.21-0.20240530111258-45870512bfbe/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df h1:clihfi78bMEOWk/qw6WA4uQbCM2e2NGliqswLAvw19k= github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df/go.mod h1:gtJYB4rR21KBSqJlazn+2z6f9gFSqQP3KvAgL7Qgxw4= -github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619060917-731bddac4821 h1:rB5XbWMILQJLH1GmsXjdfE28+k1cvovyP0/M77jrcs4= -github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619060917-731bddac4821/go.mod h1:Phf/QUo+JG6aoyUrktqPKg6exkj+Uz2kT5a8Tiyises= +github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619122842-05143459c554 h1:Fv8BfzJSzdovmoh9Jh/by++0uGsOVBlMP3XiN5Svkn4= +github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619122842-05143459c554/go.mod h1:yMq9q5VdN7jBaErRGQ0T8dkZwbBtfQYmqGbD/Ese1us= github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 h1:g9t410dqjcb7UUptbVd/H6Ua12sEzWU4v7VplyNvRZ0= github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57/go.mod h1:cY6CIXpndW5g5PTPn4WzPwka/UBEf+mgw+PSY5pHGAU= github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 h1:hFEcbGBtXu8UyB9BMhmAIH2R8BtV/NOq/rsxespLCN8= github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00/go.mod h1:pnIIfWopbDMQ1EW5Ddc6KDMqv8Qtx+hxbH9rorHpCyo= github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f h1:yd/G8iPBGOEAwbaS8zndJpO6bQk7Tk72ZhmlqRasThI= github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f/go.mod h1:E6nfj9EQzGxWDGM3Dn6eZWRC3qFy1G8IqOsYsBOcgWw= -github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240618133316-4c17adfcaea6 h1:416tIBSfXoXuA15BUVY53m84LVZysVFz0M4yuw2kKh4= -github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240618133316-4c17adfcaea6/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo= +github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240619122724-2bd2e64cebdc h1:KpLloX0pIclo3axCQVOm3wZE+U9cfeHgPWGvDuUohTk= +github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240619122724-2bd2e64cebdc/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo= github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1 h1:5/h1i7Xd/JH9CiO3ZqvzAjdze+mAbar5sWkh2UqfLgI= github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1/go.mod h1:N3Oa8QeeHlSip4nbESQpVSLgi/WxtgIwvqfXIZm6gDs= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b h1:puYO0lUyPGA5kZqsiDjGa+daDGQwj9xFs0S5urhZjU8= From c4870673381010cff84e395a1932bf8bf440fa39 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 19 Jun 2024 15:56:16 +0300 Subject: [PATCH 243/467] gasScheduleV8 --- cmd/node/config/enableEpochs.toml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index dce2d48be2c..eb391d8df1e 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -329,5 +329,6 @@ [GasSchedule] # GasScheduleByEpochs holds the configuration for the gas schedule that will be applied from specific epochs GasScheduleByEpochs = [ - { StartEpoch = 0, FileName = "gasScheduleV8.toml" }, + { StartEpoch = 0, FileName = "gasScheduleV7.toml" }, + { StartEpoch = 3, FileName = "gasScheduleV8.toml" }, ] From 2052fc290bb610362c55773f859c3235ff11d79f Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 19 Jun 2024 16:26:38 +0300 Subject: [PATCH 244/467] 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 245/467] 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 246/467] 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 247/467] 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 248/467] 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 716d67dcc01be05e097cf980c69821257ab7eb7d Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 20 Jun 2024 12:02:50 +0300 Subject: [PATCH 249/467] activate in new epoch --- cmd/node/config/economics.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/node/config/economics.toml b/cmd/node/config/economics.toml index b29c91978fc..f34d9ed57f3 100644 --- a/cmd/node/config/economics.toml +++ b/cmd/node/config/economics.toml @@ -42,6 +42,7 @@ {EnableEpoch = 0, MaxGasLimitPerBlock = "1500000000", MaxGasLimitPerMiniBlock = "1500000000", MaxGasLimitPerMetaBlock = "15000000000", MaxGasLimitPerMetaMiniBlock = "15000000000", MaxGasLimitPerTx = "1500000000", MinGasLimit = "50000", ExtraGasLimitGuardedTx = "50000", MaxGasHigherFactorAccepted = "10"}, {EnableEpoch = 1, MaxGasLimitPerBlock = "1500000000", MaxGasLimitPerMiniBlock = "250000000", MaxGasLimitPerMetaBlock = "15000000000", MaxGasLimitPerMetaMiniBlock = "250000000", MaxGasLimitPerTx = "600000000", MinGasLimit = "50000", ExtraGasLimitGuardedTx = "50000", MaxGasHigherFactorAccepted = "10"}, {EnableEpoch = 2, MaxGasLimitPerBlock = "1500000000", MaxGasLimitPerMiniBlock = "250000000", MaxGasLimitPerMetaBlock = "15000000000", MaxGasLimitPerMetaMiniBlock = "250000000", MaxGasLimitPerTx = "600000000", MinGasLimit = "50000", ExtraGasLimitGuardedTx = "50000", MaxGasHigherFactorAccepted = "10"}, + {EnableEpoch = 3, MaxGasLimitPerBlock = "1500000000", MaxGasLimitPerMiniBlock = "250000000", MaxGasLimitPerMetaBlock = "15000000000", MaxGasLimitPerMetaMiniBlock = "250000000", MaxGasLimitPerTx = "600000000", MinGasLimit = "50000", ExtraGasLimitGuardedTx = "50000", MaxGasHigherFactorAccepted = "2"}, ] MinGasPrice = "1000000000" #will yield min tx fee of 0.00005 eGLD GasPriceModifier = 0.01 From 6ddee65f5f1fbe5165daaec78e641558cc769686 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 20 Jun 2024 13:02:05 +0300 Subject: [PATCH 250/467] 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 251/467] 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 252/467] 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 253/467] fix after second review --- process/transaction/shardProcess.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/process/transaction/shardProcess.go b/process/transaction/shardProcess.go index bf7d7554304..76791e895d2 100644 --- a/process/transaction/shardProcess.go +++ b/process/transaction/shardProcess.go @@ -1154,20 +1154,18 @@ func (txProc *txProcessor) executeFailedRelayedUserTx( return err } - _, dstShardTxType := txProc.txTypeHandler.ComputeTransactionType(userTx) - isMoveBalance := dstShardTxType == process.MoveBalance totalFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, userTx.GasLimit) moveBalanceGasLimit := txProc.economicsFee.ComputeGasLimit(userTx) gasToUse := userTx.GetGasLimit() - moveBalanceGasLimit processingUserFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, gasToUse) - if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedBaseCostFlag) && isMoveBalance { + if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedBaseCostFlag) { moveBalanceUserFee := txProc.economicsFee.ComputeMoveBalanceFee(userTx) totalFee = big.NewInt(0).Add(moveBalanceUserFee, processingUserFee) } senderShardID := txProc.shardCoordinator.ComputeId(userTx.SndAddr) if senderShardID != txProc.shardCoordinator.SelfId() { - if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedBaseCostFlag) && isMoveBalance { + if txProc.enableEpochsHandler.IsFlagEnabled(common.FixRelayedBaseCostFlag) { totalFee.Sub(totalFee, processingUserFee) } else { moveBalanceUserFee := txProc.economicsFee.ComputeFeeForProcessing(userTx, moveBalanceGasLimit) From 4de9055ec3c9e4ab2ca68ea85756580ed1e4264a Mon Sep 17 00:00:00 2001 From: Daniel Drasovean Date: Fri, 21 Jun 2024 17:01:39 +0300 Subject: [PATCH 254/467] Added action for building keygenerator docker images --- .github/workflows/deploy-docker.yaml | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/deploy-docker.yaml diff --git a/.github/workflows/deploy-docker.yaml b/.github/workflows/deploy-docker.yaml new file mode 100644 index 00000000000..438da3ed406 --- /dev/null +++ b/.github/workflows/deploy-docker.yaml @@ -0,0 +1,40 @@ +env: + IMAGE_NODE: chain-keygenerator + REGISTRY_HOSTNAME: multiversx + +name: Build Docker image & push + +on: + workflow_dispatch: + pull_request: + +jobs: + build-docker-image: + strategy: + matrix: + runs-on: [ubuntu-latest] + runs-on: ${{ matrix.runs-on }} + + steps: + - name: Check out code into the Go module directory + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log into Docker Hub + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push image to Docker Hub + id: push + uses: docker/build-push-action@v6 + with: + context: . + file: ./docker/keygenerator/Dockerfile + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ env.REGISTRY_HOSTNAME }}/${{ env.IMAGE_NODE }}:latest From be31480fe2616e460c1014a11568e71b2aa402c7 Mon Sep 17 00:00:00 2001 From: Daniel Drasovean Date: Fri, 21 Jun 2024 18:03:01 +0300 Subject: [PATCH 255/467] Refactor workflow --- .../{deploy-docker.yaml => docker-keygenerator.yaml} | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) rename .github/workflows/{deploy-docker.yaml => docker-keygenerator.yaml} (83%) diff --git a/.github/workflows/deploy-docker.yaml b/.github/workflows/docker-keygenerator.yaml similarity index 83% rename from .github/workflows/deploy-docker.yaml rename to .github/workflows/docker-keygenerator.yaml index 438da3ed406..5e4d9d44a32 100644 --- a/.github/workflows/deploy-docker.yaml +++ b/.github/workflows/docker-keygenerator.yaml @@ -1,8 +1,4 @@ -env: - IMAGE_NODE: chain-keygenerator - REGISTRY_HOSTNAME: multiversx - -name: Build Docker image & push +name: Build & push keygenerator docker image on: workflow_dispatch: @@ -37,4 +33,4 @@ jobs: file: ./docker/keygenerator/Dockerfile platforms: linux/amd64,linux/arm64 push: ${{ github.event_name != 'pull_request' }} - tags: ${{ env.REGISTRY_HOSTNAME }}/${{ env.IMAGE_NODE }}:latest + tags: multiversx/chain-keygenerator:latest From 7427db91f9b321e0d2b1fcb2f7a3027f5da4dd24 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 25 Jun 2024 09:41:28 +0300 Subject: [PATCH 256/467] compressed flags --- cmd/node/config/enableEpochs.toml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index eb391d8df1e..dce2d48be2c 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -329,6 +329,5 @@ [GasSchedule] # GasScheduleByEpochs holds the configuration for the gas schedule that will be applied from specific epochs GasScheduleByEpochs = [ - { StartEpoch = 0, FileName = "gasScheduleV7.toml" }, - { StartEpoch = 3, FileName = "gasScheduleV8.toml" }, + { StartEpoch = 0, FileName = "gasScheduleV8.toml" }, ] From fb89c15755dbc163497c3a56538cc0b1e649d54a Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 25 Jun 2024 14:57:27 +0300 Subject: [PATCH 257/467] 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 258/467] 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 259/467] fix economicsData too --- process/economics/economicsData.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/process/economics/economicsData.go b/process/economics/economicsData.go index 209e8345941..2385f7feda2 100644 --- a/process/economics/economicsData.go +++ b/process/economics/economicsData.go @@ -337,6 +337,13 @@ func (ed *economicsData) ComputeRelayedTxFees(tx data.TransactionWithFeeHandler) func (ed *economicsData) getTotalFeesRequiredForInnerTxs(innerTxs []data.TransactionHandler) *big.Int { totalFees := big.NewInt(0) for _, innerTx := range innerTxs { + if !core.IsSmartContractAddress(innerTx.GetRcvAddr()) { + innerTxFee := ed.ComputeMoveBalanceFee(innerTx) + totalFees.Add(totalFees, innerTxFee) + + continue + } + gasToUse := innerTx.GetGasLimit() - ed.ComputeGasLimit(innerTx) moveBalanceUserFee := ed.ComputeMoveBalanceFee(innerTx) processingUserFee := ed.ComputeFeeForProcessing(innerTx, gasToUse) From e10c4fbfbe880504357d7ea6ac4a6d62bbc6de32 Mon Sep 17 00:00:00 2001 From: Daniel Drasovean Date: Tue, 25 Jun 2024 17:01:28 +0300 Subject: [PATCH 260/467] Fix keygenerator Dockerfile --- docker/keygenerator/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/keygenerator/Dockerfile b/docker/keygenerator/Dockerfile index c66a732e629..5d79327bc2a 100644 --- a/docker/keygenerator/Dockerfile +++ b/docker/keygenerator/Dockerfile @@ -13,4 +13,4 @@ FROM ubuntu:22.04 COPY --from=builder /go/mx-chain-go/cmd/keygenerator /go/mx-chain-go/cmd/keygenerator WORKDIR /go/mx-chain-go/cmd/keygenerator/ -ENTRYPOINT ["./keygenerator"] +ENTRYPOINT ["/go/mx-chain-go/cmd/keygenerator/keygenerator"] From c3344d8c17e056393ba867ca1d87d67c29218996 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 25 Jun 2024 19:39:44 +0300 Subject: [PATCH 261/467] 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 262/467] adapted scenarios to work with all tokens --- .../vm/esdtImprovements_test.go | 866 ++++++++++++------ 1 file changed, 596 insertions(+), 270 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index 74cb76d3f84..06a78619282 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -867,7 +867,7 @@ func TestChainSimulator_CreateTokensAfterActivation(t *testing.T) { // Test scenario #4 // -// Initial setup: Create NFT +// Initial setup: Create NFT, SFT, metaESDT tokens // // Call ESDTMetaDataRecreate to rewrite the meta data for the nft // (The sender must have the ESDTMetaDataRecreate role) @@ -911,11 +911,7 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { defer cs.Close() - mintValue := big.NewInt(10) - mintValue = mintValue.Mul(oneEGLD, mintValue) - - address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) - require.Nil(t, err) + addrs := createAddresses(t, cs, false) err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) require.Nil(t, err) @@ -923,89 +919,174 @@ func TestChainSimulator_NFT_ESDTMetaDataRecreate(t *testing.T) { err = cs.GenerateBlocks(10) require.Nil(t, err) - log.Info("Initial setup: Create NFT") + log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") - nftTicker := []byte("NFTTICKER") - tx := issueNonFungibleTx(0, address.Bytes, nftTicker, baseIssuingCost) + // issue metaESDT + metaESDTTicker := []byte("METATTICKER") + tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) + metaESDTTokenID := txResult.Logs.Events[0].Topics[0] + roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), []byte(core.ESDTMetaDataRecreate), } + setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + + log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) + + // issue fungible + fungibleTicker := []byte("FUNTICKER") + tx = issueTx(1, addrs[0].Bytes, fungibleTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + fungibleTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], fungibleTokenID, roles) + + log.Info("Issued fungible token id", "tokenID", string(fungibleTokenID)) + + // issue NFT + nftTicker := []byte("NFTTICKER") + tx = issueNonFungibleTx(2, addrs[0].Bytes, nftTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, address, nftTokenID, roles) + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) - nftMetaData := txsFee.GetDefaultMetaData() - nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - - tx = nftCreateTx(1, address.Bytes, nftTokenID, nftMetaData) + // issue SFT + sftTicker := []byte("SFTTICKER") + tx = issueSemiFungibleTx(3, addrs[0].Bytes, sftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) + sftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) + + log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) + + tokenIDs := [][]byte{ + nftTokenID, + sftTokenID, + metaESDTTokenID, + fungibleTokenID, + } + + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + sftMetaData := txsFee.GetDefaultMetaData() + sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + esdtMetaData := txsFee.GetDefaultMetaData() + esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + fungibleMetaData := txsFee.GetDefaultMetaData() + fungibleMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tokensMetadata := []*txsFee.MetaData{ + nftMetaData, + sftMetaData, + esdtMetaData, + fungibleMetaData, + } + + nonce := uint64(4) + for i := range tokenIDs { + tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } + err = cs.GenerateBlocks(10) require.Nil(t, err) log.Info("Call ESDTMetaDataRecreate to rewrite the meta data for the nft") - nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - nftMetaData.Name = []byte(hex.EncodeToString([]byte("name2"))) - nftMetaData.Hash = []byte(hex.EncodeToString([]byte("hash2"))) - nftMetaData.Attributes = []byte(hex.EncodeToString([]byte("attributes2"))) + for i := range tokenIDs { + newMetaData := txsFee.GetDefaultMetaData() + newMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + newMetaData.Name = []byte(hex.EncodeToString([]byte("name2"))) + newMetaData.Hash = []byte(hex.EncodeToString([]byte("hash2"))) + newMetaData.Attributes = []byte(hex.EncodeToString([]byte("attributes2"))) + + txDataField := bytes.Join( + [][]byte{ + []byte(core.ESDTMetaDataRecreate), + []byte(hex.EncodeToString(tokenIDs[i])), + newMetaData.Nonce, + newMetaData.Name, + []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + newMetaData.Hash, + newMetaData.Attributes, + newMetaData.Uris[0], + newMetaData.Uris[1], + newMetaData.Uris[2], + }, + []byte("@"), + ) + + tx = &transaction.Transaction{ + Nonce: nonce, + SndAddr: addrs[0].Bytes, + RcvAddr: addrs[0].Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } - txDataField := bytes.Join( - [][]byte{ - []byte(core.ESDTMetaDataRecreate), - []byte(hex.EncodeToString(nftTokenID)), - nonce, - nftMetaData.Name, - []byte(hex.EncodeToString(big.NewInt(10).Bytes())), - nftMetaData.Hash, - nftMetaData.Attributes, - nftMetaData.Uris[0], - nftMetaData.Uris[1], - nftMetaData.Uris[2], - }, - []byte("@"), - ) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) - tx = &transaction.Transaction{ - Nonce: 2, - SndAddr: address.Bytes, - RcvAddr: address.Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, - } + // fmt.Println(txResult) + // fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + // fmt.Println(string(txResult.Logs.Events[0].Topics[1])) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) - require.Equal(t, "success", txResult.Status.String()) + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(address.Bytes) + if bytes.Equal(tokenIDs[i], tokenIDs[0]) { // nft token + checkMetaData(t, cs, addrs[0].Bytes, tokenIDs[i], shardID, newMetaData) + } else { + checkMetaData(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID, newMetaData) + } - checkMetaData(t, cs, address.Bytes, nftTokenID, shardID, nftMetaData) + nonce++ + } } // Test scenario #5 // -// Initial setup: Create NFT +// Initial setup: Create NFT, SFT, metaESDT tokens // // Call ESDTMetaDataUpdate to update some of the meta data parameters // (The sender must have the ESDTRoleNFTUpdate role) @@ -1049,98 +1130,158 @@ func TestChainSimulator_NFT_ESDTMetaDataUpdate(t *testing.T) { defer cs.Close() - mintValue := big.NewInt(10) - mintValue = mintValue.Mul(oneEGLD, mintValue) - - address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) - require.Nil(t, err) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) require.Nil(t, err) - err = cs.GenerateBlocks(10) - require.Nil(t, err) + log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") - log.Info("Initial setup: Create NFT") + addrs := createAddresses(t, cs, false) - nftTicker := []byte("NFTTICKER") - tx := issueNonFungibleTx(0, address.Bytes, nftTicker, baseIssuingCost) + // issue metaESDT + metaESDTTicker := []byte("METATTICKER") + tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) + metaESDTTokenID := txResult.Logs.Events[0].Topics[0] + roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), []byte(core.ESDTRoleNFTUpdate), } + setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + + log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) + + // issue NFT + nftTicker := []byte("NFTTICKER") + tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, address, nftTokenID, roles) + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) - nftMetaData := txsFee.GetDefaultMetaData() - nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - - tx = nftCreateTx(1, address.Bytes, nftTokenID, nftMetaData) + // issue SFT + sftTicker := []byte("SFTTICKER") + tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - log.Info("Call ESDTMetaDataUpdate to rewrite the meta data for the nft") + sftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) - nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - nftMetaData.Name = []byte(hex.EncodeToString([]byte("name2"))) - nftMetaData.Hash = []byte(hex.EncodeToString([]byte("hash2"))) - nftMetaData.Attributes = []byte(hex.EncodeToString([]byte("attributes2"))) + log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) - txDataField := bytes.Join( - [][]byte{ - []byte(core.ESDTMetaDataUpdate), - []byte(hex.EncodeToString(nftTokenID)), - nonce, - nftMetaData.Name, - []byte(hex.EncodeToString(big.NewInt(10).Bytes())), - nftMetaData.Hash, - nftMetaData.Attributes, - nftMetaData.Uris[0], - nftMetaData.Uris[1], - nftMetaData.Uris[2], - }, - []byte("@"), - ) + tokenIDs := [][]byte{ + nftTokenID, + sftTokenID, + metaESDTTokenID, + } - tx = &transaction.Transaction{ - Nonce: 2, - SndAddr: address.Bytes, - RcvAddr: address.Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + sftMetaData := txsFee.GetDefaultMetaData() + sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + esdtMetaData := txsFee.GetDefaultMetaData() + esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tokensMetadata := []*txsFee.MetaData{ + nftMetaData, + sftMetaData, + esdtMetaData, } - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) + nonce := uint64(3) + for i := range tokenIDs { + tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) - require.Equal(t, "success", txResult.Status.String()) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } + + log.Info("Call ESDTMetaDataUpdate to rewrite the meta data for the nft") + + for i := range tokenIDs { + newMetaData := txsFee.GetDefaultMetaData() + newMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + newMetaData.Name = []byte(hex.EncodeToString([]byte("name2"))) + newMetaData.Hash = []byte(hex.EncodeToString([]byte("hash2"))) + newMetaData.Attributes = []byte(hex.EncodeToString([]byte("attributes2"))) + + txDataField := bytes.Join( + [][]byte{ + []byte(core.ESDTMetaDataUpdate), + []byte(hex.EncodeToString(tokenIDs[i])), + newMetaData.Nonce, + newMetaData.Name, + []byte(hex.EncodeToString(big.NewInt(10).Bytes())), + newMetaData.Hash, + newMetaData.Attributes, + newMetaData.Uris[0], + newMetaData.Uris[1], + newMetaData.Uris[2], + }, + []byte("@"), + ) + + tx = &transaction.Transaction{ + Nonce: nonce, + SndAddr: addrs[0].Bytes, + RcvAddr: addrs[0].Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + // fmt.Println(txResult) + // fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + // fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(address.Bytes) + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - checkMetaData(t, cs, address.Bytes, nftTokenID, shardID, nftMetaData) + if bytes.Equal(tokenIDs[i], tokenIDs[0]) { // nft token + checkMetaData(t, cs, addrs[0].Bytes, tokenIDs[i], shardID, newMetaData) + } else { + checkMetaData(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID, newMetaData) + } + + nonce++ + } } // Test scenario #6 // -// Initial setup: Create SFT +// Initial setup: Create NFT, SFT, metaESDT tokens // // Call ESDTModifyCreator and check that the creator was modified // (The sender must have the ESDTRoleModifyCreator role) @@ -1184,114 +1325,190 @@ func TestChainSimulator_NFT_ESDTModifyCreator(t *testing.T) { defer cs.Close() - mintValue := big.NewInt(10) - mintValue = mintValue.Mul(oneEGLD, mintValue) - - shardID := uint32(1) - address, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) - require.Nil(t, err) - - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch) - 2) + err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) require.Nil(t, err) - err = cs.GenerateBlocks(10) - require.Nil(t, err) + log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") - log.Info("Initial setup: Create SFT") + addrs := createAddresses(t, cs, false) - sftTicker := []byte("SFTTICKER") - tx := issueSemiFungibleTx(0, address.Bytes, sftTicker, baseIssuingCost) + // issue metaESDT + metaESDTTicker := []byte("METATTICKER") + tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) + metaESDTTokenID := txResult.Logs.Events[0].Topics[0] + roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), []byte(core.ESDTRoleNFTUpdate), } + setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) - sft := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, address, sft, roles) - - log.Info("Issued SFT token id", "tokenID", string(sft)) - - nftMetaData := txsFee.GetDefaultMetaData() - nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) - tx = nftCreateTx(1, address.Bytes, sft, nftMetaData) + // issue NFT + nftTicker := []byte("NFTTICKER") + tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) - require.Nil(t, err) + nftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) - log.Info("Change to DYNAMIC type") + log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) - tx = changeToDynamicTx(2, address.Bytes, sft) + // issue SFT + sftTicker := []byte("SFTTICKER") + tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - log.Info("Call ESDTModifyCreator and check that the creator was modified") + sftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) - newCreatorAddress, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) - require.Nil(t, err) + log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) - err = cs.GenerateBlocks(10) - require.Nil(t, err) + tokenIDs := [][]byte{ + // nftTokenID, + sftTokenID, + metaESDTTokenID, + } - roles = [][]byte{ - []byte(core.ESDTRoleModifyCreator), + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + sftMetaData := txsFee.GetDefaultMetaData() + sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + esdtMetaData := txsFee.GetDefaultMetaData() + esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tokensMetadata := []*txsFee.MetaData{ + // nftMetaData, + sftMetaData, + esdtMetaData, } - setAddressEsdtRoles(t, cs, newCreatorAddress, sft, roles) - txDataField := bytes.Join( - [][]byte{ - []byte(core.ESDTModifyCreator), - []byte(hex.EncodeToString(sft)), - []byte(hex.EncodeToString(big.NewInt(1).Bytes())), - }, - []byte("@"), - ) + nonce := uint64(3) + for i := range tokenIDs { + tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) - tx = &transaction.Transaction{ - Nonce: 0, - SndAddr: newCreatorAddress.Bytes, - RcvAddr: newCreatorAddress.Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) + + nonce++ } - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + log.Info("Change to DYNAMIC type") + + for i := range tokenIDs { + tx = changeToDynamicTx(nonce, addrs[0].Bytes, tokenIDs[i]) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } + + err = cs.GenerateBlocks(10) require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) + log.Info("Call ESDTModifyCreator and check that the creator was modified") + + mintValue := big.NewInt(10) + mintValue = mintValue.Mul(oneEGLD, mintValue) + + shardID := uint32(0) + + for i := range tokenIDs { + log.Info("Modify creator for token", "tokenID", string(tokenIDs[i])) + + newCreatorAddress, err := cs.GenerateAndMintWalletAddress(shardID, mintValue) + require.Nil(t, err) - retrievedMetaData := getMetaDataFromAcc(t, cs, core.SystemAccountAddress, sft, shardID) + err = cs.GenerateBlocks(10) + require.Nil(t, err) + + roles = [][]byte{ + []byte(core.ESDTRoleModifyCreator), + } + setAddressEsdtRoles(t, cs, newCreatorAddress, tokenIDs[i], roles) + + txDataField := bytes.Join( + [][]byte{ + []byte(core.ESDTModifyCreator), + []byte(hex.EncodeToString(tokenIDs[i])), + []byte(hex.EncodeToString(big.NewInt(1).Bytes())), + }, + []byte("@"), + ) + + tx = &transaction.Transaction{ + Nonce: 0, + SndAddr: newCreatorAddress.Bytes, + RcvAddr: newCreatorAddress.Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) - require.Equal(t, newCreatorAddress.Bytes, retrievedMetaData.Creator) + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) + + var retrievedMetaData *esdt.MetaData + if bytes.Equal(tokenIDs[i], tokenIDs[0]) { // nft token + retrievedMetaData = getMetaDataFromAcc(t, cs, addrs[0].Bytes, tokenIDs[i], shardID) + } else { + retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID) + } + + require.Equal(t, newCreatorAddress.Bytes, retrievedMetaData.Creator) + + nonce++ + } } // Test scenario #7 // -// Initial setup: Create NFT +// Initial setup: Create NFT, SFT, metaESDT tokens // -// Call ESDTSetNewURIs and check that the new URIs were set for the NFT +// Call ESDTSetNewURIs and check that the new URIs were set for the token // (The sender must have the ESDTRoleSetNewURI role) func TestChainSimulator_NFT_ESDTSetNewURIs(t *testing.T) { if testing.Short() { @@ -1333,56 +1550,103 @@ func TestChainSimulator_NFT_ESDTSetNewURIs(t *testing.T) { defer cs.Close() - mintValue := big.NewInt(10) - mintValue = mintValue.Mul(oneEGLD, mintValue) - - address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) - require.Nil(t, err) - err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) require.Nil(t, err) - err = cs.GenerateBlocks(10) - require.Nil(t, err) + log.Info("Initial setup: Create fungible, NFT, SFT and metaESDT tokens (after the activation of DynamicEsdtFlag)") - log.Info("Initial setup: Create NFT") + addrs := createAddresses(t, cs, false) - nftTicker := []byte("NFTTICKER") - tx := issueNonFungibleTx(0, address.Bytes, nftTicker, baseIssuingCost) + // issue metaESDT + metaESDTTicker := []byte("METATTICKER") + tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) + metaESDTTokenID := txResult.Logs.Events[0].Topics[0] + roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), []byte(core.ESDTRoleNFTUpdate), + []byte(core.ESDTRoleSetNewURI), } + setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + + log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) + + // issue NFT + nftTicker := []byte("NFTTICKER") + tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, address, nftTokenID, roles) + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) - nftMetaData := txsFee.GetDefaultMetaData() - nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - - tx = nftCreateTx(1, address.Bytes, nftTokenID, nftMetaData) + // issue SFT + sftTicker := []byte("SFTTICKER") + tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - log.Info("Call ESDTSetNewURIs and check that the new URIs were set for the NFT") + sftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) - roles = [][]byte{ - []byte(core.ESDTRoleSetNewURI), + log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) + + tokenIDs := [][]byte{ + nftTokenID, + sftTokenID, + metaESDTTokenID, } - setAddressEsdtRoles(t, cs, address, nftTokenID, roles) - nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + sftMetaData := txsFee.GetDefaultMetaData() + sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + esdtMetaData := txsFee.GetDefaultMetaData() + esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tokensMetadata := []*txsFee.MetaData{ + nftMetaData, + sftMetaData, + esdtMetaData, + } + + nonce := uint64(3) + for i := range tokenIDs { + tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } + + log.Info("Call ESDTSetNewURIs and check that the new URIs were set for the NFT") + + metaDataNonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) uris := [][]byte{ []byte(hex.EncodeToString([]byte("uri0"))), []byte(hex.EncodeToString([]byte("uri1"))), @@ -1395,50 +1659,61 @@ func TestChainSimulator_NFT_ESDTSetNewURIs(t *testing.T) { []byte("uri2"), } - txDataField := bytes.Join( - [][]byte{ - []byte(core.ESDTSetNewURIs), - []byte(hex.EncodeToString(nftTokenID)), - nonce, - uris[0], - uris[1], - uris[2], - }, - []byte("@"), - ) + for i := range tokenIDs { + log.Info("Set new uris for token", "tokenID", string(tokenIDs[i])) + + txDataField := bytes.Join( + [][]byte{ + []byte(core.ESDTSetNewURIs), + []byte(hex.EncodeToString(tokenIDs[i])), + metaDataNonce, + uris[0], + uris[1], + uris[2], + }, + []byte("@"), + ) + + tx = &transaction.Transaction{ + Nonce: nonce, + SndAddr: addrs[0].Bytes, + RcvAddr: addrs[0].Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } - tx = &transaction.Transaction{ - Nonce: 2, - SndAddr: address.Bytes, - RcvAddr: address.Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, - } + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) - require.Equal(t, "success", txResult.Status.String()) + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) + var retrievedMetaData *esdt.MetaData + if bytes.Equal(tokenIDs[i], tokenIDs[0]) { // nft token + retrievedMetaData = getMetaDataFromAcc(t, cs, addrs[0].Bytes, tokenIDs[i], shardID) + } else { + retrievedMetaData = getMetaDataFromAcc(t, cs, core.SystemAccountAddress, tokenIDs[i], shardID) + } - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(address.Bytes) - retrievedMetaData := getMetaDataFromAcc(t, cs, address.Bytes, nftTokenID, shardID) + require.Equal(t, expUris, retrievedMetaData.URIs) - require.Equal(t, expUris, retrievedMetaData.URIs) + nonce++ + } } // Test scenario #8 // -// Initial setup: Create NFT +// Initial setup: Create NFT, SFT, metaESDT tokens // // Call ESDTModifyRoyalties and check that the royalties were changed // (The sender must have the ESDTRoleModifyRoyalties role) -func TestChainSimulator_NFT_ESDTModifyRoyalties(t *testing.T) { +func TestChainSimulator_ESDTModifyRoyalties(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") } @@ -1478,91 +1753,142 @@ func TestChainSimulator_NFT_ESDTModifyRoyalties(t *testing.T) { defer cs.Close() - mintValue := big.NewInt(10) - mintValue = mintValue.Mul(oneEGLD, mintValue) - - address, err := cs.GenerateAndMintWalletAddress(core.AllShardId, mintValue) - require.Nil(t, err) + addrs := createAddresses(t, cs, false) err = cs.GenerateBlocksUntilEpochIsReached(int32(activationEpoch)) require.Nil(t, err) - err = cs.GenerateBlocks(10) - require.Nil(t, err) - - log.Info("Initial setup: Create NFT") - - nftTicker := []byte("NFTTICKER") - tx := issueNonFungibleTx(0, address.Bytes, nftTicker, baseIssuingCost) + // issue metaESDT + metaESDTTicker := []byte("METATTICKER") + tx := issueMetaESDTTx(0, addrs[0].Bytes, metaESDTTicker, baseIssuingCost) txResult, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) + metaESDTTokenID := txResult.Logs.Events[0].Topics[0] + roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), + []byte(core.ESDTRoleTransfer), []byte(core.ESDTRoleNFTUpdate), + []byte(core.ESDTRoleModifyRoyalties), } + setAddressEsdtRoles(t, cs, addrs[0], metaESDTTokenID, roles) + + log.Info("Issued metaESDT token id", "tokenID", string(metaESDTTokenID)) + + // issue NFT + nftTicker := []byte("NFTTICKER") + tx = issueNonFungibleTx(1, addrs[0].Bytes, nftTicker, baseIssuingCost) + + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + require.Equal(t, "success", txResult.Status.String()) nftTokenID := txResult.Logs.Events[0].Topics[0] - setAddressEsdtRoles(t, cs, address, nftTokenID, roles) + setAddressEsdtRoles(t, cs, addrs[0], nftTokenID, roles) log.Info("Issued NFT token id", "tokenID", string(nftTokenID)) - nftMetaData := txsFee.GetDefaultMetaData() - nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - - tx = nftCreateTx(1, address.Bytes, nftTokenID, nftMetaData) + // issue SFT + sftTicker := []byte("SFTTICKER") + tx = issueSemiFungibleTx(2, addrs[0].Bytes, sftTicker, baseIssuingCost) txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - log.Info("Call ESDTModifyRoyalties and check that the royalties were changed") + sftTokenID := txResult.Logs.Events[0].Topics[0] + setAddressEsdtRoles(t, cs, addrs[0], sftTokenID, roles) - roles = [][]byte{ - []byte(core.ESDTRoleModifyRoyalties), + log.Info("Issued SFT token id", "tokenID", string(sftTokenID)) + + tokenIDs := [][]byte{ + nftTokenID, + sftTokenID, + metaESDTTokenID, } - setAddressEsdtRoles(t, cs, address, nftTokenID, roles) - nonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - royalties := []byte(hex.EncodeToString(big.NewInt(20).Bytes())) + nftMetaData := txsFee.GetDefaultMetaData() + nftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - txDataField := bytes.Join( - [][]byte{ - []byte(core.ESDTModifyRoyalties), - []byte(hex.EncodeToString(nftTokenID)), - nonce, - royalties, - }, - []byte("@"), - ) + sftMetaData := txsFee.GetDefaultMetaData() + sftMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - tx = &transaction.Transaction{ - Nonce: 2, - SndAddr: address.Bytes, - RcvAddr: address.Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, + esdtMetaData := txsFee.GetDefaultMetaData() + esdtMetaData.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + + tokensMetadata := []*txsFee.MetaData{ + nftMetaData, + sftMetaData, + esdtMetaData, } - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) + nonce := uint64(3) + for i := range tokenIDs { + tx = nftCreateTx(nonce, addrs[0].Bytes, tokenIDs[i], tokensMetadata[i]) - require.Equal(t, "success", txResult.Status.String()) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + fmt.Println(txResult) + fmt.Println(string(txResult.Logs.Events[0].Topics[0])) + fmt.Println(string(txResult.Logs.Events[0].Topics[1])) + + require.Equal(t, "success", txResult.Status.String()) + + nonce++ + } + + log.Info("Call ESDTModifyRoyalties and check that the royalties were changed") + + metaDataNonce := []byte(hex.EncodeToString(big.NewInt(1).Bytes())) + royalties := []byte(hex.EncodeToString(big.NewInt(20).Bytes())) + + for i := range tokenIDs { + log.Info("Set new royalities for token", "tokenID", string(tokenIDs[i])) + + txDataField := bytes.Join( + [][]byte{ + []byte(core.ESDTModifyRoyalties), + []byte(hex.EncodeToString(tokenIDs[i])), + metaDataNonce, + royalties, + }, + []byte("@"), + ) + + tx = &transaction.Transaction{ + Nonce: nonce, + SndAddr: addrs[0].Bytes, + RcvAddr: addrs[0].Bytes, + GasLimit: 10_000_000, + GasPrice: minGasPrice, + Signature: []byte("dummySig"), + Data: txDataField, + Value: big.NewInt(0), + ChainID: []byte(configs.ChainID), + Version: 1, + } - shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(address.Bytes) - retrievedMetaData := getMetaDataFromAcc(t, cs, address.Bytes, nftTokenID, shardID) + txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) + require.Nil(t, err) + require.NotNil(t, txResult) + + require.Equal(t, "success", txResult.Status.String()) - require.Equal(t, uint32(big.NewInt(20).Uint64()), retrievedMetaData.Royalties) + shardID := cs.GetNodeHandler(0).GetShardCoordinator().ComputeId(addrs[0].Bytes) + retrievedMetaData := getMetaDataFromAcc(t, cs, addrs[0].Bytes, nftTokenID, shardID) + + require.Equal(t, uint32(big.NewInt(20).Uint64()), retrievedMetaData.Royalties) + + nonce++ + } } // Test scenario #9 From cfb556884c537b662b98f942155f1e5da4b20e86 Mon Sep 17 00:00:00 2001 From: Daniel Drasovean Date: Wed, 26 Jun 2024 13:38:01 +0300 Subject: [PATCH 263/467] Remove redundant code --- docker/keygenerator/Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/docker/keygenerator/Dockerfile b/docker/keygenerator/Dockerfile index 5d79327bc2a..a73d7951d42 100644 --- a/docker/keygenerator/Dockerfile +++ b/docker/keygenerator/Dockerfile @@ -12,5 +12,4 @@ RUN go build FROM ubuntu:22.04 COPY --from=builder /go/mx-chain-go/cmd/keygenerator /go/mx-chain-go/cmd/keygenerator -WORKDIR /go/mx-chain-go/cmd/keygenerator/ ENTRYPOINT ["/go/mx-chain-go/cmd/keygenerator/keygenerator"] From a5d15092412e7411a5dff77ef149d9f03f5d3350 Mon Sep 17 00:00:00 2001 From: Daniel Drasovean Date: Wed, 26 Jun 2024 13:41:24 +0300 Subject: [PATCH 264/467] Updated to support multi-arch docker builds --- docker/node/Dockerfile | 14 ++++++++++---- docker/termui/Dockerfile | 9 +++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/docker/node/Dockerfile b/docker/node/Dockerfile index 2513f789dc8..81675a6f6a3 100644 --- a/docker/node/Dockerfile +++ b/docker/node/Dockerfile @@ -7,15 +7,21 @@ RUN go mod tidy # Multiversx node WORKDIR /go/mx-chain-go/cmd/node RUN go build -v -ldflags="-X main.appVersion=$(git describe --tags --long --dirty)" -RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-v | sort -n | tail -n -1| awk -F '/' '{print$3}'| sed 's/ /@/g')/wasmer/libwasmer_linux_amd64.so /lib/libwasmer_linux_amd64.so -RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-go | sort -n | tail -n -1| awk -F '/' '{print$3}'| sed 's/ /@/g')/wasmer2/libvmexeccapi.so /lib/libvmexeccapi.so + +RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-v | sort -n | tail -n -1 | awk -F '/' '{print$3}' | sed 's/ /@/g')/wasmer/libwasmer_linux_amd64.so /lib_amd64/ +RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-go | sort -n | tail -n -1 | awk -F '/' '{print$3}' | sed 's/ /@/g')/wasmer2/libvmexeccapi.so /lib_amd64/ + +RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-v | sort -n | tail -n -1 | awk -F '/' '{print$3}' | sed 's/ /@/g')/wasmer/libwasmer_linux_arm64_shim.so /lib_arm64/ +RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-go | sort -n | tail -n -1 | awk -F '/' '{print$3}' | sed 's/ /@/g')/wasmer2/libvmexeccapi_arm.so /lib_arm64/ # ===== SECOND STAGE ====== FROM ubuntu:22.04 RUN apt-get update && apt-get upgrade -y COPY --from=builder "/go/mx-chain-go/cmd/node/node" "/go/mx-chain-go/cmd/node/" -COPY --from=builder "/lib/libwasmer_linux_amd64.so" "/lib/libwasmer_linux_amd64.so" -COPY --from=builder "/lib/libvmexeccapi.so" "/lib/libvmexeccapi.so" + +# Copy architecture-specific files +COPY --from=builder "/lib_${TARGETARCH}/*" "/lib/" + WORKDIR /go/mx-chain-go/cmd/node/ EXPOSE 8080 ENTRYPOINT ["/go/mx-chain-go/cmd/node/node"] diff --git a/docker/termui/Dockerfile b/docker/termui/Dockerfile index bcc670e3ce3..e25e75833e5 100644 --- a/docker/termui/Dockerfile +++ b/docker/termui/Dockerfile @@ -4,11 +4,16 @@ WORKDIR /go/mx-chain-go COPY . . WORKDIR /go/mx-chain-go/cmd/termui RUN go build -v -RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-v | sort -n | tail -n -1| awk -F '/' '{print$3}'| sed 's/ /@/g')/wasmer/libwasmer_linux_amd64.so /lib/libwasmer_linux_amd64.so +RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-v | sort -n | tail -n -1| awk -F '/' '{print$3}'| sed 's/ /@/g')/wasmer/libwasmer_linux_amd64.so /lib_amd64/ +RUN cp /go/pkg/mod/github.com/multiversx/$(cat /go/mx-chain-go/go.mod | grep mx-chain-vm-v | sort -n | tail -n -1 | awk -F '/' '{print$3}' | sed 's/ /@/g')/wasmer/libwasmer_linux_arm64_shim.so /lib_arm64/ + # ===== SECOND STAGE ====== FROM ubuntu:22.04 COPY --from=builder /go/mx-chain-go/cmd/termui /go/mx-chain-go/cmd/termui -COPY --from=builder "/lib/libwasmer_linux_amd64.so" "/lib/libwasmer_linux_amd64.so" + +# Copy architecture-specific files +COPY --from=builder "/lib_${TARGETARCH}/*" "/lib/" + WORKDIR /go/mx-chain-go/cmd/termui/ ENTRYPOINT ["./termui"] From c2bf800d348ecc355a0cdd74a58303eaf54060c4 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 26 Jun 2024 14:29:58 +0300 Subject: [PATCH 265/467] 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 266/467] 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 267/467] 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 268/467] 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 269/467] 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 270/467] 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 271/467] 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 272/467] 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 273/467] 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 274/467] 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 275/467] 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 276/467] 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 277/467] 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 278/467] 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 279/467] 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 280/467] 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 281/467] 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 282/467] 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 283/467] 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 284/467] 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 285/467] 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 286/467] 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 287/467] 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 288/467] 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 289/467] 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 290/467] 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 291/467] 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 292/467] 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 293/467] 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 294/467] 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 295/467] 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 296/467] 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 297/467] 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 298/467] 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 299/467] 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 300/467] 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 301/467] 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 302/467] 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 303/467] 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 304/467] 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 305/467] 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 306/467] 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 307/467] 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 308/467] 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 309/467] 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 310/467] 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 311/467] 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 312/467] 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 313/467] 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 314/467] 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 315/467] 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 316/467] 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 317/467] 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 318/467] 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 319/467] 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 320/467] 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 321/467] 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 322/467] 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 323/467] 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 324/467] 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 325/467] 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 326/467] 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 327/467] 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 328/467] 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 329/467] 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 330/467] 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 331/467] 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 332/467] 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 333/467] 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 334/467] 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 335/467] 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 336/467] 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 337/467] 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 338/467] 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 339/467] fix linter issues --- integrationTests/chainSimulator/vm/esdtImprovements_test.go | 1 - integrationTests/chainSimulator/vm/esdtTokens_test.go | 1 - 2 files changed, 2 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index fa40135b5e1..97acfa79fd2 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -3899,7 +3899,6 @@ func TestChainSimulator_CreateAndPauseTokens_DynamicNFT(t *testing.T) { log.Info("transfering token id", "tokenID", nftTokenID) tx = esdtNFTTransferTx(nonce, addrs[0].Bytes, addrs[1].Bytes, nftTokenID) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) require.NotNil(t, txResult) diff --git a/integrationTests/chainSimulator/vm/esdtTokens_test.go b/integrationTests/chainSimulator/vm/esdtTokens_test.go index 7fc9c84037a..d12bfcbb550 100644 --- a/integrationTests/chainSimulator/vm/esdtTokens_test.go +++ b/integrationTests/chainSimulator/vm/esdtTokens_test.go @@ -364,7 +364,6 @@ func TestChainSimulator_Api_NFTToken(t *testing.T) { log.Info("Change to DYNAMIC type") tx = changeToDynamicTx(nonce, addrs[0].Bytes, nftTokenID) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) From 9e9ecdac075ab52cba1d0d5e8dab7e041e6f7cad Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 31 Jul 2024 10:47:50 +0300 Subject: [PATCH 340/467] fix - only transfer role for second address --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index ad3320aa141..3346fdb7919 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.3 github.com/multiversx/mx-chain-storage-go v1.0.15 github.com/multiversx/mx-chain-vm-common-go v1.5.12 - github.com/multiversx/mx-chain-vm-go v1.5.29 + github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240731074331-32488d472365 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.97 diff --git a/go.sum b/go.sum index 1fd68ab48f7..1e1a56a818c 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go v1.5.29 h1:Ovz5/WM9KbD3YKRafdKI4RwtsNN36AGeNw81LZAhE70= -github.com/multiversx/mx-chain-vm-go v1.5.29/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240731074331-32488d472365 h1:6gRrsqpIjXAw6P40PcQ3txOLPTcSOmisIe+HVyyVeAE= +github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240731074331-32488d472365/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From f7483c67328f5969cc253c972cbf59c02ed4fc83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Wed, 31 Jul 2024 10:51:45 +0300 Subject: [PATCH 341/467] Fix workflow matrix. --- .github/workflows/build_and_test.yml | 2 +- .github/workflows/create_release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 19fdaec07e0..d552db889c7 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -9,7 +9,7 @@ jobs: build: strategy: matrix: - runs-on: [ubuntu-latest, macos-latest, macos-13-xlarge] + runs-on: [ubuntu-latest, macos-13, macos-13-xlarge] runs-on: ${{ matrix.runs-on }} name: Build steps: diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index ca13a9f0313..fe74d301325 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -15,7 +15,7 @@ jobs: build: strategy: matrix: - runs-on: [ubuntu-latest, macos-latest, macos-13-xlarge] + runs-on: [ubuntu-latest, macos-13, macos-13-xlarge] runs-on: ${{ matrix.runs-on }} name: Build steps: From 1eefd6f27f7ad5128685f950b9bc9b8f4656b802 Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 31 Jul 2024 11:56:38 +0300 Subject: [PATCH 342/467] 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/467] 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/467] 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/467] 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/467] update change metadata test --- .../vm/esdtImprovements_test.go | 89 ++----------------- 1 file changed, 6 insertions(+), 83 deletions(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index ddb51d499c6..efdea1bcb9f 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -2218,12 +2218,10 @@ func TestChainSimulator_NFT_ChangeToDynamicType(t *testing.T) { // Test scenario #10 // -// Initial setup: Create SFT and send in 2 shards +// Initial setup: Create SFT and send in another shard // -// 1. change the sft meta data in one shard -// 2. change the sft meta data (differently from the previous one) in the other shard -// 3. send sft from one shard to another -// 4. check that the newest metadata is saved +// 1. change the sft meta data (differently from the previous one) in the other shard +// 2. check that the newest metadata is saved func TestChainSimulator_ChangeMetaData(t *testing.T) { if testing.Short() { t.Skip("this is not a short test") @@ -2248,7 +2246,7 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { addrs := createAddresses(t, cs, true) - log.Info("Initial setup: Create token and send in 2 shards") + log.Info("Initial setup: Create token and send in another shard") roles := [][]byte{ []byte(core.ESDTRoleNFTCreate), @@ -2320,12 +2318,6 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - roles = [][]byte{ - []byte(core.ESDTRoleNFTUpdate), - } - setAddressEsdtRoles(t, cs, nonce, addrs[1], tokenID, roles) - nonce++ - log.Info("Send to separate shards") tx = esdtNFTTransferTx(nonce, addrs[1].Bytes, addrs[2].Bytes, tokenID) @@ -2401,78 +2393,9 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { require.NotNil(t, txResult) require.Equal(t, "success", txResult.Status.String()) - shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) - - checkMetaData(t, cs, core.SystemAccountAddress, tokenID, shardID, sftMetaData2) - - log.Info("Step 2. change the sft meta data (differently from the previous one) in the other shard") - - tx = setSpecialRoleTx(nonce, addrs[1].Bytes, addrs[2].Bytes, tokenID, roles) - - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - - sftMetaData3 := txsFee.GetDefaultMetaData() - sftMetaData3.Nonce = []byte(hex.EncodeToString(big.NewInt(1).Bytes())) - - sftMetaData3.Name = []byte(hex.EncodeToString([]byte("name3"))) - sftMetaData3.Hash = []byte(hex.EncodeToString([]byte("hash3"))) - sftMetaData3.Attributes = []byte(hex.EncodeToString([]byte("attributes3"))) - - txDataField = bytes.Join( - [][]byte{ - []byte(core.ESDTMetaDataUpdate), - []byte(hex.EncodeToString(tokenID)), - sftMetaData3.Nonce, - sftMetaData3.Name, - []byte(hex.EncodeToString(big.NewInt(10).Bytes())), - sftMetaData3.Hash, - sftMetaData3.Attributes, - sftMetaData3.Uris[0], - sftMetaData3.Uris[1], - sftMetaData3.Uris[2], - }, - []byte("@"), - ) - - tx = &transaction.Transaction{ - Nonce: 0, - SndAddr: addrs[2].Bytes, - RcvAddr: addrs[2].Bytes, - GasLimit: 10_000_000, - GasPrice: minGasPrice, - Signature: []byte("dummySig"), - Data: txDataField, - Value: big.NewInt(0), - ChainID: []byte(configs.ChainID), - Version: 1, - } - - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - - shardID = cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[2].Bytes) - - checkMetaData(t, cs, core.SystemAccountAddress, tokenID, shardID, sftMetaData3) - - log.Info("Step 3. send sft from one shard to another") - - tx = esdtNFTTransferTx(1, addrs[0].Bytes, addrs[2].Bytes, tokenID) - txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) - require.Nil(t, err) - require.NotNil(t, txResult) - require.Equal(t, "success", txResult.Status.String()) - - err = cs.GenerateBlocks(10) - require.Nil(t, err) + log.Info("Step 2. check that the newest metadata is saved") - log.Info("Step 4. check that the newest metadata is saved") - - shardID = cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[2].Bytes) + shardID := cs.GetNodeHandler(0).GetProcessComponents().ShardCoordinator().ComputeId(addrs[0].Bytes) checkMetaData(t, cs, core.SystemAccountAddress, tokenID, shardID, sftMetaData2) } From afe791533cebc4cbb4b5b814af184c4de3c9bcc0 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 1 Aug 2024 08:49:38 +0300 Subject: [PATCH 347/467] even newer wasmer --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 3346fdb7919..7ef2feb817b 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.3 github.com/multiversx/mx-chain-storage-go v1.0.15 github.com/multiversx/mx-chain-vm-common-go v1.5.12 - github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240731074331-32488d472365 + github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240801054658-dd0579e7d74b github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.97 diff --git a/go.sum b/go.sum index 1e1a56a818c..a36b7ceb563 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240731074331-32488d472365 h1:6gRrsqpIjXAw6P40PcQ3txOLPTcSOmisIe+HVyyVeAE= -github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240731074331-32488d472365/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240801054658-dd0579e7d74b h1:gPOH3m+KxTZr4K5af3cS0URQKRLL8WsHXcY1PJeCtO0= +github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240801054658-dd0579e7d74b/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From 3da197f2075c0b009398332a559da4704f08f74e Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 1 Aug 2024 14:07:24 +0300 Subject: [PATCH 348/467] 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 349/467] 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 350/467] 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 351/467] 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 352/467] 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 353/467] 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 354/467] 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 355/467] unit tests --- .../apiTransactionProcessor_test.go | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/node/external/transactionAPI/apiTransactionProcessor_test.go b/node/external/transactionAPI/apiTransactionProcessor_test.go index 7d86a1610c5..3101cf763f4 100644 --- a/node/external/transactionAPI/apiTransactionProcessor_test.go +++ b/node/external/transactionAPI/apiTransactionProcessor_test.go @@ -268,6 +268,93 @@ func TestNode_GetTransactionFromPool(t *testing.T) { require.Equal(t, transaction.TxStatusPending, actualG.Status) } +func TestNode_GetSCRs(t *testing.T) { + scResultHash := []byte("scHash") + txHash := []byte("txHash") + + marshalizer := &mock.MarshalizerFake{} + scResult := &smartContractResult.SmartContractResult{ + Nonce: 1, + SndAddr: []byte("snd"), + RcvAddr: []byte("rcv"), + OriginalTxHash: txHash, + Data: []byte("test"), + } + + resultHashesByTxHash := &dblookupext.ResultsHashesByTxHash{ + ScResultsHashesAndEpoch: []*dblookupext.ScResultsHashesAndEpoch{ + { + Epoch: 0, + ScResultsHashes: [][]byte{scResultHash}, + }, + }, + } + + chainStorer := &storageStubs.ChainStorerStub{ + GetStorerCalled: func(unitType dataRetriever.UnitType) (storage.Storer, error) { + switch unitType { + case dataRetriever.UnsignedTransactionUnit: + return &storageStubs.StorerStub{ + GetFromEpochCalled: func(key []byte, epoch uint32) ([]byte, error) { + return marshalizer.Marshal(scResult) + }, + }, nil + default: + return nil, storage.ErrKeyNotFound + } + }, + } + + historyRepo := &dblookupextMock.HistoryRepositoryStub{ + GetMiniblockMetadataByTxHashCalled: func(hash []byte) (*dblookupext.MiniblockMetadata, error) { + return &dblookupext.MiniblockMetadata{}, nil + }, + GetEventsHashesByTxHashCalled: func(hash []byte, epoch uint32) (*dblookupext.ResultsHashesByTxHash, error) { + return resultHashesByTxHash, nil + }, + } + + feeComp := &testscommon.FeeComputerStub{ + ComputeTransactionFeeCalled: func(tx *transaction.ApiTransactionResult) *big.Int { + return big.NewInt(1000) + }, + } + + args := &ArgAPITransactionProcessor{ + RoundDuration: 0, + GenesisTime: time.Time{}, + Marshalizer: &mock.MarshalizerFake{}, + AddressPubKeyConverter: &testscommon.PubkeyConverterMock{}, + ShardCoordinator: &mock.ShardCoordinatorMock{}, + HistoryRepository: historyRepo, + StorageService: chainStorer, + DataPool: dataRetrieverMock.NewPoolsHolderMock(), + Uint64ByteSliceConverter: mock.NewNonceHashConverterMock(), + FeeComputer: feeComp, + TxTypeHandler: &testscommon.TxTypeHandlerMock{}, + LogsFacade: &testscommon.LogsFacadeStub{}, + DataFieldParser: &testscommon.DataFieldParserStub{ + ParseCalled: func(dataField []byte, sender, receiver []byte, _ uint32) *datafield.ResponseParseData { + return &datafield.ResponseParseData{} + }, + }, + } + apiTransactionProc, _ := NewAPITransactionProcessor(args) + + scrs, err := apiTransactionProc.GetSCRsByTxHash(hex.EncodeToString(txHash), hex.EncodeToString(scResultHash)) + require.Nil(t, err) + require.Equal(t, 1, len(scrs)) + require.Equal(t, &transaction.ApiSmartContractResult{ + Nonce: 1, + Data: "test", + Hash: "736348617368", + RcvAddr: "726376", + SndAddr: "736e64", + OriginalTxHash: "747848617368", + Receivers: []string{}, + }, scrs[0]) +} + func TestNode_GetTransactionFromStorage(t *testing.T) { t.Parallel() From abf23769b5b9136e3ec1f7d7c014d9447b7359db Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 6 Aug 2024 14:37:27 +0300 Subject: [PATCH 356/467] tags --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 7ef2feb817b..cf1bccc8a8d 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.3 github.com/multiversx/mx-chain-storage-go v1.0.15 github.com/multiversx/mx-chain-vm-common-go v1.5.12 - github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240801054658-dd0579e7d74b + github.com/multiversx/mx-chain-vm-go v1.5.30-patch1 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.97 diff --git a/go.sum b/go.sum index a36b7ceb563..c74b95d8eeb 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240801054658-dd0579e7d74b h1:gPOH3m+KxTZr4K5af3cS0URQKRLL8WsHXcY1PJeCtO0= -github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240801054658-dd0579e7d74b/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go v1.5.30-patch1 h1:fFCSnV/JKxr1Rr5K4CXkDrwHzp7ZsGK0X4bRmwx0Cgk= +github.com/multiversx/mx-chain-vm-go v1.5.30-patch1/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From 55b7954d236886e0440b91f6be49ee4d3d8b62eb Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 6 Aug 2024 14:41:02 +0300 Subject: [PATCH 357/467] tags --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index cf1bccc8a8d..24474aeef37 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.3 github.com/multiversx/mx-chain-storage-go v1.0.15 github.com/multiversx/mx-chain-vm-common-go v1.5.12 - github.com/multiversx/mx-chain-vm-go v1.5.30-patch1 + github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.97 diff --git a/go.sum b/go.sum index c74b95d8eeb..ec1a900502b 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go v1.5.30-patch1 h1:fFCSnV/JKxr1Rr5K4CXkDrwHzp7ZsGK0X4bRmwx0Cgk= -github.com/multiversx/mx-chain-vm-go v1.5.30-patch1/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 h1:wDrE+ZMoHH+BzG3n4ERUR9Luas2w+GvV6e3w4r9hFw0= +github.com/multiversx/mx-chain-vm-go v1.5.29-patch1/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From d8f0a125205466cacd00a5ba20cadf4f1da7590d Mon Sep 17 00:00:00 2001 From: python-qa Date: Tue, 6 Aug 2024 10:11:03 +0300 Subject: [PATCH 358/467] 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 359/467] 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 360/467] 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 361/467] 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 362/467] 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 d78614a8ca0f8961ec1adcf175cd980f6949cbfd Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Thu, 8 Aug 2024 23:02:42 +0300 Subject: [PATCH 363/467] - integrated new VM --- go.mod | 2 + go.sum | 4 +- .../wasmvm/mockcontracts/simpleChildSC.go | 50 ------------------- .../wasmvm/mockcontracts/simpleParentSC.go | 43 ---------------- 4 files changed, 4 insertions(+), 95 deletions(-) delete mode 100644 integrationTests/vm/wasm/wasmvm/mockcontracts/simpleChildSC.go delete mode 100644 integrationTests/vm/wasm/wasmvm/mockcontracts/simpleParentSC.go diff --git a/go.mod b/go.mod index 24474aeef37..e6154610617 100644 --- a/go.mod +++ b/go.mod @@ -188,3 +188,5 @@ require ( ) replace github.com/gogo/protobuf => github.com/multiversx/protobuf v1.3.2 + +replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240808185405-c196977d9ac3 diff --git a/go.sum b/go.sum index ec1a900502b..4ff92ec601b 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 h1:wDrE+ZMoHH+BzG3n4ERUR9Luas2w+GvV6e3w4r9hFw0= -github.com/multiversx/mx-chain-vm-go v1.5.29-patch1/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240808185405-c196977d9ac3 h1:64gr6OyTPjrtHlEhH2KjY15zMeEmfD1vofVViKbMa2w= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240808185405-c196977d9ac3/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= diff --git a/integrationTests/vm/wasm/wasmvm/mockcontracts/simpleChildSC.go b/integrationTests/vm/wasm/wasmvm/mockcontracts/simpleChildSC.go deleted file mode 100644 index 7e1bb9dbaf5..00000000000 --- a/integrationTests/vm/wasm/wasmvm/mockcontracts/simpleChildSC.go +++ /dev/null @@ -1,50 +0,0 @@ -package mockcontracts - -import ( - "errors" - - mock "github.com/multiversx/mx-chain-vm-go/mock/context" - test "github.com/multiversx/mx-chain-vm-go/testcommon" - "github.com/multiversx/mx-chain-vm-go/vmhost" -) - -// SimpleCallChildMock is an exposed mock contract method -func SimpleCallChildMock(instanceMock *mock.InstanceMock, config interface{}) { - instanceMock.AddMockMethod("simpleChildFunction", func() *mock.InstanceMock { - testConfig := config.(*test.TestConfig) - host := instanceMock.Host - instance := mock.GetMockInstance(host) - - arguments := host.Runtime().Arguments() - if len(arguments) != 1 { - host.Runtime().SignalUserError("wrong num of arguments") - return instance - } - - host.Metering().UseGas(testConfig.GasUsedByChild) - - behavior := byte(0) - if len(arguments[0]) != 0 { - behavior = arguments[0][0] - } - err := handleChildBehaviorArgument(host, behavior) - if err != nil { - return instance - } - - _, _ = host.Storage().SetStorage(test.ChildKey, test.ChildData) - host.Output().Finish(test.ChildFinish) - - return instance - }) -} - -func handleChildBehaviorArgument(host vmhost.VMHost, behavior byte) error { - if behavior == 1 { - host.Runtime().SignalUserError("child error") - return errors.New("behavior / child error") - } - - host.Output().Finish([]byte{behavior}) - return nil -} diff --git a/integrationTests/vm/wasm/wasmvm/mockcontracts/simpleParentSC.go b/integrationTests/vm/wasm/wasmvm/mockcontracts/simpleParentSC.go deleted file mode 100644 index 63f4fcc5d4e..00000000000 --- a/integrationTests/vm/wasm/wasmvm/mockcontracts/simpleParentSC.go +++ /dev/null @@ -1,43 +0,0 @@ -package mockcontracts - -import ( - "math/big" - - mock "github.com/multiversx/mx-chain-vm-go/mock/context" - test "github.com/multiversx/mx-chain-vm-go/testcommon" - "github.com/multiversx/mx-chain-vm-go/vmhost" - "github.com/multiversx/mx-chain-vm-go/vmhost/vmhooks" - "github.com/stretchr/testify/require" -) - -var failBehavior = []byte{1} - -// PerformOnDestCallFailParentMock is an exposed mock contract method -func PerformOnDestCallFailParentMock(instanceMock *mock.InstanceMock, config interface{}) { - instanceMock.AddMockMethod("performOnDestCallFail", func() *mock.InstanceMock { - testConfig := config.(*test.TestConfig) - host := instanceMock.Host - instance := mock.GetMockInstance(host) - t := instance.T - - err := host.Metering().UseGasBounded(testConfig.GasUsedByParent) - if err != nil { - host.Runtime().SetRuntimeBreakpointValue(vmhost.BreakpointOutOfGas) - return instance - } - - _, _ = host.Storage().SetStorage(test.ParentKeyA, test.ParentDataA) - host.Output().Finish(test.ParentFinishA) - - retVal := vmhooks.ExecuteOnDestContextWithTypedArgs( - host, - int64(testConfig.GasProvidedToChild), - big.NewInt(0), - []byte("simpleChildFunction"), - testConfig.ChildAddress, - [][]byte{failBehavior}) - require.Equal(t, retVal, int32(1)) - - return instance - }) -} From f289f70a2703b3dffd0602efa2c6bfedec7eb14a Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 9 Aug 2024 11:33:27 +0300 Subject: [PATCH 364/467] 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 365/467] 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 366/467] 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 367/467] 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 368/467] 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 369/467] 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 370/467] 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 371/467] 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 372/467] 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 373/467] 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 374/467] 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 23b065f6cb990b9fbc1748edb8ba801825d49fe4 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 12 Aug 2024 10:55:46 +0300 Subject: [PATCH 375/467] - new VM version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e6154610617..3d8e37c97c3 100644 --- a/go.mod +++ b/go.mod @@ -189,4 +189,4 @@ require ( replace github.com/gogo/protobuf => github.com/multiversx/protobuf v1.3.2 -replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240808185405-c196977d9ac3 +replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240812072513-1dc750527d61 diff --git a/go.sum b/go.sum index 4ff92ec601b..0a6945fd561 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240808185405-c196977d9ac3 h1:64gr6OyTPjrtHlEhH2KjY15zMeEmfD1vofVViKbMa2w= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240808185405-c196977d9ac3/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240812072513-1dc750527d61 h1:4YAzUQuXqaGELfbl3lCLWK18aiqo45sUqcofW0vA/co= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240812072513-1dc750527d61/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From a9e2b8f75992026f47fe8b87da51c33d411531fe Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Mon, 12 Aug 2024 11:44:04 +0300 Subject: [PATCH 376/467] 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 377/467] 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 378/467] 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 379/467] 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 380/467] 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 edfc0a076a3b9eee63be21289710a9076d1a5633 Mon Sep 17 00:00:00 2001 From: ssd04 Date: Mon, 12 Aug 2024 16:57:13 +0300 Subject: [PATCH 381/467] fix linter issue --- integrationTests/chainSimulator/vm/esdtImprovements_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index d8e5c065a45..438660658f3 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -2343,7 +2343,6 @@ func testChainSimulatorChangeMetaData(t *testing.T, issueFn issueTxFunc) { []byte(core.ESDTRoleNFTUpdate), } tx = setSpecialRoleTx(nonce, addrs[1].Bytes, addrs[0].Bytes, tokenID, roles) - nonce++ txResult, err = cs.SendTxAndGenerateBlockTilTxIsExecuted(tx, maxNumOfBlockToGenerateWhenExecutingTx) require.Nil(t, err) From c78c99562d8be493af11815b6e60e3787dfb3aa6 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Tue, 13 Aug 2024 11:39:06 +0300 Subject: [PATCH 382/467] - new VM version --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 3d8e37c97c3..50506f20018 100644 --- a/go.mod +++ b/go.mod @@ -189,4 +189,4 @@ require ( replace github.com/gogo/protobuf => github.com/multiversx/protobuf v1.3.2 -replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240812072513-1dc750527d61 +replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813082455-adc3bd3acd79 diff --git a/go.sum b/go.sum index 0a6945fd561..4a7a2b9d06b 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240812072513-1dc750527d61 h1:4YAzUQuXqaGELfbl3lCLWK18aiqo45sUqcofW0vA/co= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240812072513-1dc750527d61/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813082455-adc3bd3acd79 h1:XCL3LLJ2hgVPuYwuMmM9RtJDStLn822bOvRHMCkbnYM= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813082455-adc3bd3acd79/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From a7a39d34e5049dd98be4d2d85e70977d3641c11e Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 13 Aug 2024 12:11:06 +0300 Subject: [PATCH 383/467] 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 cff7df6f8d0fbf0355a6c8d1ed9d974e69604a4c Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 13 Aug 2024 12:44:37 +0300 Subject: [PATCH 384/467] integration of flag --- cmd/node/config/enableEpochs.toml | 3 +++ common/constants.go | 1 + common/enablers/enableEpochsHandler.go | 6 ++++++ common/enablers/enableEpochsHandler_test.go | 2 ++ config/epochConfig.go | 1 + config/tomlConfig_test.go | 4 ++++ 6 files changed, 17 insertions(+) diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index dce2d48be2c..779ba4ba6b5 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -309,6 +309,9 @@ # AlwaysMergeContextsInEEIEnableEpoch represents the epoch in which the EEI will always merge the contexts AlwaysMergeContextsInEEIEnableEpoch = 1 + # UseGasBoundedShouldFailExecutionEnableEpoch represents the epoch when use bounded gas function should fail execution in case of error + UseGasBoundedShouldFailExecutionEnableEpoch = 1 + # 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 5320ee675c1..53f5a242b2c 100644 --- a/common/constants.go +++ b/common/constants.go @@ -1014,5 +1014,6 @@ const ( CleanupAuctionOnLowWaitingListFlag core.EnableEpochFlag = "CleanupAuctionOnLowWaitingListFlag" StakingV4StartedFlag core.EnableEpochFlag = "StakingV4StartedFlag" AlwaysMergeContextsInEEIFlag core.EnableEpochFlag = "AlwaysMergeContextsInEEIFlag" + UseGasBoundedShouldFailExecutionFlag core.EnableEpochFlag = "UseGasBoundedShouldFailExecutionFlag" // 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 5ce3812742f..ed3ee5960fc 100644 --- a/common/enablers/enableEpochsHandler.go +++ b/common/enablers/enableEpochsHandler.go @@ -732,6 +732,12 @@ func (handler *enableEpochsHandler) createAllFlagsMap() { }, activationEpoch: handler.enableEpochsConfig.AlwaysMergeContextsInEEIEnableEpoch, }, + common.UseGasBoundedShouldFailExecutionFlag: { + isActiveInEpoch: func(epoch uint32) bool { + return epoch >= handler.enableEpochsConfig.UseGasBoundedShouldFailExecutionEnableEpoch + }, + activationEpoch: handler.enableEpochsConfig.UseGasBoundedShouldFailExecutionEnableEpoch, + }, } } diff --git a/common/enablers/enableEpochsHandler_test.go b/common/enablers/enableEpochsHandler_test.go index 2c568f2043b..807394e131f 100644 --- a/common/enablers/enableEpochsHandler_test.go +++ b/common/enablers/enableEpochsHandler_test.go @@ -116,6 +116,7 @@ func createEnableEpochsConfig() config.EnableEpochs { StakingV4Step3EnableEpoch: 98, CleanupAuctionOnLowWaitingListEnableEpoch: 96, AlwaysMergeContextsInEEIEnableEpoch: 99, + UseGasBoundedShouldFailExecutionEnableEpoch: 100, } } @@ -431,6 +432,7 @@ func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) { require.Equal(t, cfg.CleanupAuctionOnLowWaitingListEnableEpoch, handler.GetActivationEpoch(common.CleanupAuctionOnLowWaitingListFlag)) require.Equal(t, cfg.StakingV4Step1EnableEpoch, handler.GetActivationEpoch(common.StakingV4StartedFlag)) require.Equal(t, cfg.AlwaysMergeContextsInEEIEnableEpoch, handler.GetActivationEpoch(common.AlwaysMergeContextsInEEIFlag)) + require.Equal(t, cfg.UseGasBoundedShouldFailExecutionEnableEpoch, handler.GetActivationEpoch(common.UseGasBoundedShouldFailExecutionFlag)) } func TestEnableEpochsHandler_IsInterfaceNil(t *testing.T) { diff --git a/config/epochConfig.go b/config/epochConfig.go index 764970ae050..cd7c74e490f 100644 --- a/config/epochConfig.go +++ b/config/epochConfig.go @@ -114,6 +114,7 @@ type EnableEpochs struct { StakingV4Step3EnableEpoch uint32 CleanupAuctionOnLowWaitingListEnableEpoch uint32 AlwaysMergeContextsInEEIEnableEpoch uint32 + UseGasBoundedShouldFailExecutionEnableEpoch uint32 BLSMultiSignerEnableEpoch []MultiSignerConfig } diff --git a/config/tomlConfig_test.go b/config/tomlConfig_test.go index eaeb4e6e2ae..eefbc9498e7 100644 --- a/config/tomlConfig_test.go +++ b/config/tomlConfig_test.go @@ -847,6 +847,9 @@ func TestEnableEpochConfig(t *testing.T) { # CleanupAuctionOnLowWaitingListEnableEpoch represents the epoch when the cleanup auction on low waiting list is enabled CleanupAuctionOnLowWaitingListEnableEpoch = 95 + # UseGasBoundedShouldFailExecutionEnableEpoch represents the epoch when use bounded gas function should fail execution in case of error + UseGasBoundedShouldFailExecutionEnableEpoch = 96 + # MaxNodesChangeEnableEpoch holds configuration for changing the maximum number of nodes and the enabling epoch MaxNodesChangeEnableEpoch = [ { EpochEnable = 44, MaxNumNodes = 2169, NodesToShufflePerShard = 80 }, @@ -960,6 +963,7 @@ func TestEnableEpochConfig(t *testing.T) { CurrentRandomnessOnSortingEnableEpoch: 93, AlwaysMergeContextsInEEIEnableEpoch: 94, CleanupAuctionOnLowWaitingListEnableEpoch: 95, + UseGasBoundedShouldFailExecutionEnableEpoch: 96, MaxNodesChangeEnableEpoch: []MaxNodesChangeConfig{ { EpochEnable: 44, From e8f7d9f8fa5c71eef00944d9854f29f230dae1ea Mon Sep 17 00:00:00 2001 From: python-qa Date: Tue, 13 Aug 2024 16:00:21 +0300 Subject: [PATCH 385/467] 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 fc42f1fc895bca6bfdebb8f4e8b3b5b259b356ea Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 13 Aug 2024 17:11:53 +0300 Subject: [PATCH 386/467] debug --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 50506f20018..f0f14d283c0 100644 --- a/go.mod +++ b/go.mod @@ -189,4 +189,4 @@ require ( replace github.com/gogo/protobuf => github.com/multiversx/protobuf v1.3.2 -replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813082455-adc3bd3acd79 +replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813140946-901dedbef9c9 diff --git a/go.sum b/go.sum index 4a7a2b9d06b..0b739180652 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813082455-adc3bd3acd79 h1:XCL3LLJ2hgVPuYwuMmM9RtJDStLn822bOvRHMCkbnYM= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813082455-adc3bd3acd79/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813140946-901dedbef9c9 h1:bq4Dqa8N8hgqXBWicQ6IwvTJtuEfCZmkj0/QponsmE4= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813140946-901dedbef9c9/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From f1a3ceb4589e2d512d8fbbb41108115454ad45af Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 13 Aug 2024 17:39:29 +0300 Subject: [PATCH 387/467] new vm --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index f0f14d283c0..247a43b09ef 100644 --- a/go.mod +++ b/go.mod @@ -189,4 +189,4 @@ require ( replace github.com/gogo/protobuf => github.com/multiversx/protobuf v1.3.2 -replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813140946-901dedbef9c9 +replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813143740-31c6a6a559e9 diff --git a/go.sum b/go.sum index 0b739180652..f5ec4b8cf9c 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813140946-901dedbef9c9 h1:bq4Dqa8N8hgqXBWicQ6IwvTJtuEfCZmkj0/QponsmE4= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813140946-901dedbef9c9/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813143740-31c6a6a559e9 h1:eWd7ycVjsozzqfJLp8jMgAni8vu3taF2I/OVUZuyrcM= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813143740-31c6a6a559e9/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From d7e5ef83299b73654c135e76bfbd9609304be32d Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 13 Aug 2024 19:59:03 +0300 Subject: [PATCH 388/467] 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 389/467] 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 894c853d441b7240e7a48ca4273a8472519c4c17 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 14 Aug 2024 09:28:27 +0300 Subject: [PATCH 390/467] debug --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 247a43b09ef..e7d8edc648d 100644 --- a/go.mod +++ b/go.mod @@ -189,4 +189,4 @@ require ( replace github.com/gogo/protobuf => github.com/multiversx/protobuf v1.3.2 -replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813143740-31c6a6a559e9 +replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814062709-6e516e240346 diff --git a/go.sum b/go.sum index f5ec4b8cf9c..a35ee905a8e 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813143740-31c6a6a559e9 h1:eWd7ycVjsozzqfJLp8jMgAni8vu3taF2I/OVUZuyrcM= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240813143740-31c6a6a559e9/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814062709-6e516e240346 h1:o13yI3MmkwWshKD5617u9zCdcLFd1v2iBiqAaEpW57k= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814062709-6e516e240346/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From 728bc517da15259dd5883daa79a3880cc139ee49 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 14 Aug 2024 10:11:31 +0300 Subject: [PATCH 391/467] backward compatibility --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e7d8edc648d..674b640c67b 100644 --- a/go.mod +++ b/go.mod @@ -189,4 +189,4 @@ require ( replace github.com/gogo/protobuf => github.com/multiversx/protobuf v1.3.2 -replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814062709-6e516e240346 +replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814070940-6b440d4bd1cc diff --git a/go.sum b/go.sum index a35ee905a8e..e0970255215 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814062709-6e516e240346 h1:o13yI3MmkwWshKD5617u9zCdcLFd1v2iBiqAaEpW57k= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814062709-6e516e240346/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814070940-6b440d4bd1cc h1:WGjf5v8O5NKeAI9oIG+Jb6EkroR3SjIjIHSDXY/msI4= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814070940-6b440d4bd1cc/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From 215dd458a8566a5bf069af2b5b9f2cd9cc836f2c Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 14 Aug 2024 10:20:23 +0300 Subject: [PATCH 392/467] debug --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 674b640c67b..b79259147e4 100644 --- a/go.mod +++ b/go.mod @@ -189,4 +189,4 @@ require ( replace github.com/gogo/protobuf => github.com/multiversx/protobuf v1.3.2 -replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814070940-6b440d4bd1cc +replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814071924-d8547b75a990 diff --git a/go.sum b/go.sum index e0970255215..cc6d790bf62 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814070940-6b440d4bd1cc h1:WGjf5v8O5NKeAI9oIG+Jb6EkroR3SjIjIHSDXY/msI4= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814070940-6b440d4bd1cc/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814071924-d8547b75a990 h1:jb43pkrPsbL4m04OTiDFLR7DtNBx5s61NnTCixgoeYI= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814071924-d8547b75a990/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From 047464621f15e63366e35614a5d2fd9003e9501e Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 14 Aug 2024 14:16:28 +0300 Subject: [PATCH 393/467] debug delete --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index b79259147e4..04e06bec707 100644 --- a/go.mod +++ b/go.mod @@ -189,4 +189,4 @@ require ( replace github.com/gogo/protobuf => github.com/multiversx/protobuf v1.3.2 -replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814071924-d8547b75a990 +replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814111502-a06f25e941b6 diff --git a/go.sum b/go.sum index cc6d790bf62..cd867580cfc 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814071924-d8547b75a990 h1:jb43pkrPsbL4m04OTiDFLR7DtNBx5s61NnTCixgoeYI= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814071924-d8547b75a990/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814111502-a06f25e941b6 h1:7q4B9MXAfEWhSSCMPvt5eelxtcit55islP7Yu3MkVwA= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814111502-a06f25e941b6/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From cab29d2fbe34b15275106991855e97e376de8345 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 14 Aug 2024 18:16:11 +0300 Subject: [PATCH 394/467] 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 ebfc4f7e566daa712c1613a53f677be208d015f6 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Wed, 14 Aug 2024 19:08:58 +0300 Subject: [PATCH 395/467] debug and fix --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 04e06bec707..f4f809e4c0b 100644 --- a/go.mod +++ b/go.mod @@ -189,4 +189,4 @@ require ( replace github.com/gogo/protobuf => github.com/multiversx/protobuf v1.3.2 -replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814111502-a06f25e941b6 +replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814160727-f5c5080c53e3 diff --git a/go.sum b/go.sum index cd867580cfc..c9f247ab27d 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814111502-a06f25e941b6 h1:7q4B9MXAfEWhSSCMPvt5eelxtcit55islP7Yu3MkVwA= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814111502-a06f25e941b6/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814160727-f5c5080c53e3 h1:iGyaiwd2koj93cAlqFehZZBHVRTOKD9xzvfBf+MRNB8= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814160727-f5c5080c53e3/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From 069ff1d8a20f4e55d1f0f2295d7209d77dc7d1f4 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Thu, 15 Aug 2024 09:47:16 +0300 Subject: [PATCH 396/467] integrate newest vm --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index f4f809e4c0b..315f9358f6c 100644 --- a/go.mod +++ b/go.mod @@ -189,4 +189,4 @@ require ( replace github.com/gogo/protobuf => github.com/multiversx/protobuf v1.3.2 -replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814160727-f5c5080c53e3 +replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240815063326-1ccc655c9f4f diff --git a/go.sum b/go.sum index c9f247ab27d..8e75a213f52 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814160727-f5c5080c53e3 h1:iGyaiwd2koj93cAlqFehZZBHVRTOKD9xzvfBf+MRNB8= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240814160727-f5c5080c53e3/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240815063326-1ccc655c9f4f h1:3XBgHHpdLNqTGRr6Muupn8g4Cu7J6/jxjQb4OpklSKo= +github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240815063326-1ccc655c9f4f/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From 6cec9edf3d3e7380c2f41eb39f6ece5ae9981459 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 19 Aug 2024 09:52:26 +0300 Subject: [PATCH 397/467] 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 398/467] 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 f6a7e13e2cad715cc7a44a9ca13f521469d8ca79 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 19 Aug 2024 12:17:24 +0300 Subject: [PATCH 399/467] - new VM version --- go.mod | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 315f9358f6c..85c91c1b534 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/multiversx/mx-chain-scenario-go v1.4.3 github.com/multiversx/mx-chain-storage-go v1.0.15 github.com/multiversx/mx-chain-vm-common-go v1.5.12 - github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 + github.com/multiversx/mx-chain-vm-go v1.5.29-patch2 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.97 @@ -188,5 +188,3 @@ require ( ) replace github.com/gogo/protobuf => github.com/multiversx/protobuf v1.3.2 - -replace github.com/multiversx/mx-chain-vm-go v1.5.29-patch1 => github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240815063326-1ccc655c9f4f From 943e43bebd253a77174de531bcf64d060850395d Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 19 Aug 2024 12:20:43 +0300 Subject: [PATCH 400/467] - go mod tidy --- go.sum | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go.sum b/go.sum index 8e75a213f52..753d3faadb1 100644 --- a/go.sum +++ b/go.sum @@ -401,8 +401,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.15 h1:PDyP1uouAVjR32dFgM+7iaQBdRe github.com/multiversx/mx-chain-storage-go v1.0.15/go.mod h1:GZUK3sqf5onsWS/0ZPWjDCBjAL22FigQPUh252PAVk0= github.com/multiversx/mx-chain-vm-common-go v1.5.12 h1:Q8F6DE7XhgHtWgg2rozSv4Tv5fE3ENkJz6mjRoAfht8= github.com/multiversx/mx-chain-vm-common-go v1.5.12/go.mod h1:Sv6iS1okB6gy3HAsW6KHYtAxShNAfepKLtu//AURI8c= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240815063326-1ccc655c9f4f h1:3XBgHHpdLNqTGRr6Muupn8g4Cu7J6/jxjQb4OpklSKo= -github.com/multiversx/mx-chain-vm-go-ghsa-jrrc-6rqr-2fq4 v1.5.30-patch1.0.20240815063326-1ccc655c9f4f/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= +github.com/multiversx/mx-chain-vm-go v1.5.29-patch2 h1:KvTUbtGZmWNr7/b+WT0TlAiXBYtdCvDQoFp8MhWTPPo= +github.com/multiversx/mx-chain-vm-go v1.5.29-patch2/go.mod h1:n0SbVEAhIflreAGi7BnfWg4p4VHh4G8ArbvYQZsZsKQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67 h1:W0bwj5zXM2JEeOEqfKTZE1ecuSJwTuRZZrl9oircRc0= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.67/go.mod h1:lrDQWpv1yZHlX6ZgWJsTMxxOkeoVTKLQsl1+mr50Z24= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.68 h1:px2YHay6BSVheLxb3gdZQX0enlqKzu6frngWEZRtr6g= From 290d028e7aeea37da99b725533079c8771667782 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Tue, 20 Aug 2024 10:05:10 +0300 Subject: [PATCH 401/467] 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 402/467] 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 403/467] 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 404/467] 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 405/467] 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 406/467] 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 407/467] 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 408/467] 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 409/467] 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 410/467] 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 411/467] 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 412/467] 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 413/467] 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 414/467] 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 415/467] 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 416/467] 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 417/467] 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 418/467] 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 419/467] 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 420/467] 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 421/467] 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 422/467] 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 423/467] 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 424/467] 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 425/467] 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 426/467] 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 427/467] 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 428/467] 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 cd5c81e107b13a044e3e6e49560e66e875f2a297 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Mon, 23 Sep 2024 14:41:23 +0300 Subject: [PATCH 429/467] Optimize GH workflows. --- .github/workflows/build_and_test.yml | 2 +- .github/workflows/build_and_test_macos.yml | 48 ++++++++++++++++++++++ .github/workflows/create_release.yml | 6 +-- .github/workflows/docker-keygenerator.yaml | 4 +- .github/workflows/golangci-lint.yml | 1 + 5 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/build_and_test_macos.yml diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index d552db889c7..efb1c939339 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -9,7 +9,7 @@ jobs: build: strategy: matrix: - runs-on: [ubuntu-latest, macos-13, macos-13-xlarge] + runs-on: [ubuntu-latest] runs-on: ${{ matrix.runs-on }} name: Build steps: diff --git a/.github/workflows/build_and_test_macos.yml b/.github/workflows/build_and_test_macos.yml new file mode 100644 index 00000000000..114a3bcd2b8 --- /dev/null +++ b/.github/workflows/build_and_test_macos.yml @@ -0,0 +1,48 @@ +name: Build and smoke test (MacOS) + +on: + pull_request: + branches: [master] + workflow_dispatch: + +jobs: + build: + strategy: + matrix: + runs-on: [macos-latest] + runs-on: ${{ matrix.runs-on }} + name: Build + steps: + - name: Set up Go 1.20.7 + uses: actions/setup-go@v3 + with: + go-version: 1.20.7 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v3 + + - name: Get dependencies + run: | + go get -v -t -d ./... + if [ -f Gopkg.toml ]; then + curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh + dep ensure + fi + + - name: Build + run: | + cd ${GITHUB_WORKSPACE}/cmd/node && go build . + cd ${GITHUB_WORKSPACE}/cmd/seednode && go build . + cd ${GITHUB_WORKSPACE}/cmd/keygenerator && go build . + cd ${GITHUB_WORKSPACE}/cmd/logviewer && go build . + cd ${GITHUB_WORKSPACE}/cmd/termui && go build . + + # On GitHub, we only run the short tests, and we only run them for some OS/ARCH combinations. + - name: Run tests + run: | + GOOS=$(go env GOOS) + + if [[ "$GOOS" == darwin ]]; then + go test -short -v ./... + fi diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index fe74d301325..bac2bab26b7 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -15,7 +15,7 @@ jobs: build: strategy: matrix: - runs-on: [ubuntu-latest, macos-13, macos-13-xlarge] + runs-on: [ubuntu-latest] runs-on: ${{ matrix.runs-on }} name: Build steps: @@ -129,7 +129,7 @@ jobs: zip -r -j ${ARCHIVE} ${BUILD_DIR} - name: Save artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ${{ env.ARCHIVE }} path: ${{ env.ARCHIVE }} @@ -145,7 +145,7 @@ jobs: # https://docs.github.com/en/free-pro-team@latest/actions/guides/storing-workflow-data-as-artifacts#downloading-or-deleting-artifacts # A directory for each artifact is created using its name - name: Download all workflow run artifacts - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4 with: path: assets diff --git a/.github/workflows/docker-keygenerator.yaml b/.github/workflows/docker-keygenerator.yaml index 5e4d9d44a32..c3cca7fc279 100644 --- a/.github/workflows/docker-keygenerator.yaml +++ b/.github/workflows/docker-keygenerator.yaml @@ -2,7 +2,6 @@ name: Build & push keygenerator docker image on: workflow_dispatch: - pull_request: jobs: build-docker-image: @@ -19,7 +18,6 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Log into Docker Hub - if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} @@ -32,5 +30,5 @@ jobs: context: . file: ./docker/keygenerator/Dockerfile platforms: linux/amd64,linux/arm64 - push: ${{ github.event_name != 'pull_request' }} + push: true tags: multiversx/chain-keygenerator:latest diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 611fadc3d08..1cc46af26c8 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -5,6 +5,7 @@ on: - master pull_request: branches: [ master, feat/*, rc/* ] + workflow_dispatch: permissions: contents: read From 75156ecd26c8eafc977804ffe34bcf57e0cc0f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Mon, 23 Sep 2024 14:56:43 +0300 Subject: [PATCH 430/467] Simplification. --- .github/workflows/build_and_test.yml | 2 +- .github/workflows/build_and_test_macos.yml | 48 ---------------------- 2 files changed, 1 insertion(+), 49 deletions(-) delete mode 100644 .github/workflows/build_and_test_macos.yml diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index efb1c939339..8f8985811cc 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -9,7 +9,7 @@ jobs: build: strategy: matrix: - runs-on: [ubuntu-latest] + runs-on: [ubuntu-latest, macos-latest] runs-on: ${{ matrix.runs-on }} name: Build steps: diff --git a/.github/workflows/build_and_test_macos.yml b/.github/workflows/build_and_test_macos.yml deleted file mode 100644 index 114a3bcd2b8..00000000000 --- a/.github/workflows/build_and_test_macos.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: Build and smoke test (MacOS) - -on: - pull_request: - branches: [master] - workflow_dispatch: - -jobs: - build: - strategy: - matrix: - runs-on: [macos-latest] - runs-on: ${{ matrix.runs-on }} - name: Build - steps: - - name: Set up Go 1.20.7 - uses: actions/setup-go@v3 - with: - go-version: 1.20.7 - id: go - - - name: Check out code into the Go module directory - uses: actions/checkout@v3 - - - name: Get dependencies - run: | - go get -v -t -d ./... - if [ -f Gopkg.toml ]; then - curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh - dep ensure - fi - - - name: Build - run: | - cd ${GITHUB_WORKSPACE}/cmd/node && go build . - cd ${GITHUB_WORKSPACE}/cmd/seednode && go build . - cd ${GITHUB_WORKSPACE}/cmd/keygenerator && go build . - cd ${GITHUB_WORKSPACE}/cmd/logviewer && go build . - cd ${GITHUB_WORKSPACE}/cmd/termui && go build . - - # On GitHub, we only run the short tests, and we only run them for some OS/ARCH combinations. - - name: Run tests - run: | - GOOS=$(go env GOOS) - - if [[ "$GOOS" == darwin ]]; then - go test -short -v ./... - fi From 965682c1749bdfdbe35e06b82f16e5688b6197e6 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Mon, 23 Sep 2024 16:03:30 +0300 Subject: [PATCH 431/467] 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 432/467] 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 433/467] 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 434/467] 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 435/467] 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 436/467] 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 437/467] 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 438/467] 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 e67616d1a4e8fa970787404bde4379f12b91d9bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20B=C4=83ncioiu?= Date: Thu, 3 Oct 2024 17:36:08 +0300 Subject: [PATCH 439/467] Optimize GitHub workflows. --- .github/workflows/build_and_test.yml | 2 +- .github/workflows/create_release.yml | 6 +++--- .github/workflows/docker-keygenerator.yaml | 4 +--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index d552db889c7..8f8985811cc 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -9,7 +9,7 @@ jobs: build: strategy: matrix: - runs-on: [ubuntu-latest, macos-13, macos-13-xlarge] + runs-on: [ubuntu-latest, macos-latest] runs-on: ${{ matrix.runs-on }} name: Build steps: diff --git a/.github/workflows/create_release.yml b/.github/workflows/create_release.yml index fe74d301325..bac2bab26b7 100644 --- a/.github/workflows/create_release.yml +++ b/.github/workflows/create_release.yml @@ -15,7 +15,7 @@ jobs: build: strategy: matrix: - runs-on: [ubuntu-latest, macos-13, macos-13-xlarge] + runs-on: [ubuntu-latest] runs-on: ${{ matrix.runs-on }} name: Build steps: @@ -129,7 +129,7 @@ jobs: zip -r -j ${ARCHIVE} ${BUILD_DIR} - name: Save artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: ${{ env.ARCHIVE }} path: ${{ env.ARCHIVE }} @@ -145,7 +145,7 @@ jobs: # https://docs.github.com/en/free-pro-team@latest/actions/guides/storing-workflow-data-as-artifacts#downloading-or-deleting-artifacts # A directory for each artifact is created using its name - name: Download all workflow run artifacts - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4 with: path: assets diff --git a/.github/workflows/docker-keygenerator.yaml b/.github/workflows/docker-keygenerator.yaml index 5e4d9d44a32..c3cca7fc279 100644 --- a/.github/workflows/docker-keygenerator.yaml +++ b/.github/workflows/docker-keygenerator.yaml @@ -2,7 +2,6 @@ name: Build & push keygenerator docker image on: workflow_dispatch: - pull_request: jobs: build-docker-image: @@ -19,7 +18,6 @@ jobs: uses: docker/setup-buildx-action@v3 - name: Log into Docker Hub - if: github.event_name != 'pull_request' uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} @@ -32,5 +30,5 @@ jobs: context: . file: ./docker/keygenerator/Dockerfile platforms: linux/amd64,linux/arm64 - push: ${{ github.event_name != 'pull_request' }} + push: true tags: multiversx/chain-keygenerator:latest From 4f16b0a52b5c7e65226f3794a8f1d4b03f4d9359 Mon Sep 17 00:00:00 2001 From: BeniaminDrasovean Date: Mon, 7 Oct 2024 12:35:19 +0300 Subject: [PATCH 440/467] 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 441/467] 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 442/467] 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 443/467] 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 444/467] 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 445/467] 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 446/467] 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 447/467] 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 448/467] 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 449/467] 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 450/467] 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 451/467] 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 452/467] 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 453/467] 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 454/467] 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 455/467] 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= From 35bfe149d3c9067f54a1d6e5de98f9c783650260 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Mon, 4 Nov 2024 14:37:01 +0200 Subject: [PATCH 456/467] merges --- go.sum | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/go.sum b/go.sum index 990794e0d27..4de240abdf8 100644 --- a/go.sum +++ b/go.sum @@ -385,30 +385,30 @@ github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/n github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU= github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUYwbO0993uPI= github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= -github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e h1:Tsmwhu+UleE+l3buPuqXSKTqfu5FbPmzQ4MjMoUvCWA= -github.com/multiversx/mx-chain-communication-go v1.0.15-0.20240508074652-e128a1c05c8e/go.mod h1:2yXl18wUbuV3cRZr7VHxM1xo73kTaC1WUcu2kx8R034= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240508071047-fefea5737840 h1:2mCrTUmbbA+Xv4UifZY9xptrGjcJBcJ2wavSb4FwejU= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240508071047-fefea5737840/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= -github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df h1:clihfi78bMEOWk/qw6WA4uQbCM2e2NGliqswLAvw19k= -github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df/go.mod h1:gtJYB4rR21KBSqJlazn+2z6f9gFSqQP3KvAgL7Qgxw4= -github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240514103357-929ece92ef86 h1:rw+u7qv0HO+7lRddCzfciqDcAWL9/fl2LQqU8AmVtdU= -github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240514103357-929ece92ef86/go.mod h1:UDKRXmxsSyPeAcjLUfGeYkAtYp424PIYkL82kzFYobM= -github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 h1:g9t410dqjcb7UUptbVd/H6Ua12sEzWU4v7VplyNvRZ0= -github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57/go.mod h1:cY6CIXpndW5g5PTPn4WzPwka/UBEf+mgw+PSY5pHGAU= -github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00 h1:hFEcbGBtXu8UyB9BMhmAIH2R8BtV/NOq/rsxespLCN8= -github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240509103754-9e8129721f00/go.mod h1:pnIIfWopbDMQ1EW5Ddc6KDMqv8Qtx+hxbH9rorHpCyo= -github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f h1:yd/G8iPBGOEAwbaS8zndJpO6bQk7Tk72ZhmlqRasThI= -github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240508073549-dcb8e6e0370f/go.mod h1:E6nfj9EQzGxWDGM3Dn6eZWRC3qFy1G8IqOsYsBOcgWw= -github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240529093845-2a375eef5cc1 h1:C6NQcbfusGkhWP2FNvzafX2w7lKGSzZIius/fM5Gm3c= -github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240529093845-2a375eef5cc1/go.mod h1:RgGmPei0suQcFTHfO4cS5dxJSiokp2SM5lmNgp1icMo= -github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1 h1:5/h1i7Xd/JH9CiO3ZqvzAjdze+mAbar5sWkh2UqfLgI= -github.com/multiversx/mx-chain-vm-go v1.5.30-0.20240509104139-8b0eaa8a85d1/go.mod h1:N3Oa8QeeHlSip4nbESQpVSLgi/WxtgIwvqfXIZm6gDs= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b h1:puYO0lUyPGA5kZqsiDjGa+daDGQwj9xFs0S5urhZjU8= -github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68-0.20240509103859-89de3c5da36b/go.mod h1:SY95hGdAIc8YCGb4uNSy1ux8V8qQbF1ReZJDwQ6AqEo= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240509104009-598a37ff36b9 h1:rrkgAS58jRXc6LThPHY5fm3AnFoUa0VUiYkH5czdlYg= -github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69-0.20240509104009-598a37ff36b9/go.mod h1:TiOTsz2kxHadU0It7okOwcynyNPePXzjyl7lnpGLlUQ= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98-0.20240509104102-2a6a709b4041 h1:k0xkmCrJiQzsWk4ZM3oNQ31lheiDvd1qQnNwnyuZzXU= -github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98-0.20240509104102-2a6a709b4041/go.mod h1:XeZNaDMV0hbDlm3JtW0Hj3mCWKaB/XecQlCzEjiK5L8= +github.com/multiversx/mx-chain-communication-go v1.1.1-0.20241021133229-d0833256e3ec h1:KwpeVZXSHzic8DV9zaJZmaBgDNIIpSdbGz4Q+9fZyiI= +github.com/multiversx/mx-chain-communication-go v1.1.1-0.20241021133229-d0833256e3ec/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= +github.com/multiversx/mx-chain-core-go v1.2.23-0.20241018134424-75bab2a9058c h1:hPCfMSj2vd9xNkARNxB1b3b9k8taFb+Xfja+WK97jno= +github.com/multiversx/mx-chain-core-go v1.2.23-0.20241018134424-75bab2a9058c/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= +github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4= +github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018130218-f48c7282690b h1:GYvm0yGkdQ3OCfNqnyIQNzAzydN3cES8noJZ3eZHN1A= +github.com/multiversx/mx-chain-es-indexer-go v1.7.10-0.20241018130218-f48c7282690b/go.mod h1:oGcRK2E3Syv6vRTszWrrb/TqD8akq0yeoMr1wPPiTO4= +github.com/multiversx/mx-chain-logger-go v1.0.15 h1:HlNdK8etyJyL9NQ+6mIXyKPEBo+wRqOwi3n+m2QIHXc= +github.com/multiversx/mx-chain-logger-go v1.0.15/go.mod h1:t3PRKaWB1M+i6gUfD27KXgzLJJC+mAQiN+FLlL1yoGQ= +github.com/multiversx/mx-chain-scenario-go v1.4.4 h1:DVE2V+FPeyD/yWoC+KEfPK3jsFzHeruelESfpTlf460= +github.com/multiversx/mx-chain-scenario-go v1.4.4/go.mod h1:kI+TWR3oIEgUkbwkHCPo2CQ3VjIge+ezGTibiSGwMxo= +github.com/multiversx/mx-chain-storage-go v1.0.16 h1:l2lJq+EAN3YwLbjJrnoKfFd1/1Xmo9DcAUECND2obLs= +github.com/multiversx/mx-chain-storage-go v1.0.16/go.mod h1:uM/z7YyqTOD3wgyH8TfapyEl5sb+7x/Jaxne4cfG4HI= +github.com/multiversx/mx-chain-vm-common-go v1.5.16 h1:g1SqYjxl7K66Y1O/q6tvDJ37fzpzlxCSfRzSm/woQQY= +github.com/multiversx/mx-chain-vm-common-go v1.5.16/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY= +github.com/multiversx/mx-chain-vm-go v1.5.37 h1:Iy3KCvM+DOq1f9UPA7uYK/rI3ZbBOXc2CVNO2/vm5zw= +github.com/multiversx/mx-chain-vm-go v1.5.37/go.mod h1:nzLrWeXvfxCIiwj5uNBZq3d7stkXyeY+Fktfr4tTaiY= +github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68 h1:L3GoAVFtLLzr9ya0rVv1YdTUzS3MyM7kQNBSAjCNO2g= +github.com/multiversx/mx-chain-vm-v1_2-go v1.2.68/go.mod h1:ixxwib+1pXwSDHG5Wa34v0SRScF+BwFzH4wFWY31saI= +github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69 h1:G/PLsyfQV4bMLs2amGRvaLKZoW1DC7M+7ecVaLuaCNc= +github.com/multiversx/mx-chain-vm-v1_3-go v1.3.69/go.mod h1:msY3zaS+K+R10ypqQs/jke6xdNAJzS38PGIaeJj2zhg= +github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98 h1:/fYx4ClVPU48pTKh2qk4QVlve0xjjDpvzOakjFUtXJ8= +github.com/multiversx/mx-chain-vm-v1_4-go v1.4.98/go.mod h1:4vqG8bSmufZx263DMrmr8OLbO6q6//VPC4W9PxZLB5Q= github.com/multiversx/mx-components-big-int v1.0.0 h1:Wkr8lSzK2nDqixOrrBa47VNuqdhV1m/aJhaP1EMaiS8= github.com/multiversx/mx-components-big-int v1.0.0/go.mod h1:maIEMgHlNE2u78JaDD0oLzri+ShgU4okHfzP3LWGdQM= github.com/multiversx/protobuf v1.3.2 h1:RaNkxvGTGbA0lMcnHAN24qE1G1i+Xs5yHA6MDvQ4mSM= From 93a819853081a2c13c1995cad3bc4dbae3fb143f Mon Sep 17 00:00:00 2001 From: robertsasu Date: Mon, 11 Nov 2024 10:31:48 +0200 Subject: [PATCH 457/467] fixing tests --- .../chainSimulator/staking/stakingProvider/delegation_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index 423faa3fbab..bcc63c71d28 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go @@ -34,7 +34,7 @@ import ( var log = logger.GetOrCreate("stakingProvider") const gasLimitForConvertOperation = 510_000_000 -const gasLimitForDelegationContractCreationOperation = 500_000_000 +const gasLimitForDelegationContractCreationOperation = 100_000_000 const gasLimitForAddNodesOperation = 500_000_000 const gasLimitForUndelegateOperation = 500_000_000 const gasLimitForMergeOperation = 600_000_000 From 0b6485b716c3366e4f46f43a829399f671d50a76 Mon Sep 17 00:00:00 2001 From: robertsasu Date: Mon, 11 Nov 2024 12:01:24 +0200 Subject: [PATCH 458/467] fixing tests --- .../chainSimulator/relayedTx/relayedTx_test.go | 4 ++-- .../staking/stake/stakeAndUnStake_test.go | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go index f7c0f74649b..69d7d505143 100644 --- a/integrationTests/chainSimulator/relayedTx/relayedTx_test.go +++ b/integrationTests/chainSimulator/relayedTx/relayedTx_test.go @@ -96,7 +96,7 @@ func testFixRelayedMoveBalanceWithChainSimulatorScCall( require.NoError(t, err) // send relayed tx, fix still not active - innerTx = generateTransaction(owner.Bytes, 2, scAddressBytes, big.NewInt(0), txDataAdd, 3000000) + innerTx = generateTransaction(owner.Bytes, 2, scAddressBytes, big.NewInt(0), txDataAdd, 1230000) marshalledTx, err = json.Marshal(innerTx) require.NoError(t, err) txData = []byte("relayedTx@" + hex.EncodeToString(marshalledTx)) @@ -119,7 +119,7 @@ func testFixRelayedMoveBalanceWithChainSimulatorScCall( require.NoError(t, err) // send relayed tx after fix - innerTx = generateTransaction(owner.Bytes, 3, scAddressBytes, big.NewInt(0), txDataAdd, 3000000) + innerTx = generateTransaction(owner.Bytes, 3, scAddressBytes, big.NewInt(0), txDataAdd, 1500000) marshalledTx, err = json.Marshal(innerTx) require.NoError(t, err) txData = []byte("relayedTx@" + hex.EncodeToString(marshalledTx)) diff --git a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index acb0c7537ed..53509154985 100644 --- a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go @@ -1884,7 +1884,7 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, require.Nil(t, err) require.NotNil(t, unStakeTx) - unStakeTxFee, _ := big.NewInt(0).SetString(unStakeTx.Fee, 10) + unStakeTxFee1, _ := big.NewInt(0).SetString(unStakeTx.Fee, 10) testEpoch := targetEpoch + 1 err = cs.GenerateBlocksUntilEpochIsReached(testEpoch) @@ -1898,6 +1898,8 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, require.Nil(t, err) require.NotNil(t, unStakeTx) + unStakeTxFee2, _ := big.NewInt(0).SetString(unStakeTx.Fee, 10) + testEpoch++ err = cs.GenerateBlocksUntilEpochIsReached(testEpoch) require.Nil(t, err) @@ -1910,6 +1912,8 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, require.Nil(t, err) require.NotNil(t, unStakeTx) + unStakeTxFee3, _ := big.NewInt(0).SetString(unStakeTx.Fee, 10) + testEpoch++ err = cs.GenerateBlocksUntilEpochIsReached(testEpoch) require.Nil(t, err) @@ -1977,9 +1981,9 @@ func testChainSimulatorDirectStakedWithdrawUnstakedFundsInBatches(t *testing.T, txsFee.Add(txsFee, stakeTxFee) txsFee.Add(txsFee, unBondTxFee) - txsFee.Add(txsFee, unStakeTxFee) - txsFee.Add(txsFee, unStakeTxFee) - txsFee.Add(txsFee, unStakeTxFee) + txsFee.Add(txsFee, unStakeTxFee1) + txsFee.Add(txsFee, unStakeTxFee2) + txsFee.Add(txsFee, unStakeTxFee3) balanceAfterUnbonding.Add(balanceAfterUnbonding, txsFee) From 171a31edab020c8ae1222bcf3391f806b035173f Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 13 Nov 2024 22:08:02 +0200 Subject: [PATCH 459/467] compressed flags --- cmd/node/config/enableEpochs.toml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/node/config/enableEpochs.toml b/cmd/node/config/enableEpochs.toml index 9ca2083a352..48567b6131f 100644 --- a/cmd/node/config/enableEpochs.toml +++ b/cmd/node/config/enableEpochs.toml @@ -313,25 +313,25 @@ UseGasBoundedShouldFailExecutionEnableEpoch = 1 # DynamicESDTEnableEpoch represents the epoch when dynamic NFT feature is enabled - DynamicESDTEnableEpoch = 4 + DynamicESDTEnableEpoch = 1 # EGLDInMultiTransferEnableEpoch represents the epoch when EGLD in multitransfer is enabled - EGLDInMultiTransferEnableEpoch = 4 + EGLDInMultiTransferEnableEpoch = 1 # CryptoOpcodesV2EnableEpoch represents the epoch when BLSMultiSig, Secp256r1 and other opcodes are enabled - CryptoOpcodesV2EnableEpoch = 4 + CryptoOpcodesV2EnableEpoch = 1 # UnjailCleanupEnableEpoch represents the epoch when the cleanup of the unjailed nodes is enabled - UnJailCleanupEnableEpoch = 4 + UnJailCleanupEnableEpoch = 1 # FixRelayedBaseCostEnableEpoch represents the epoch when the fix for relayed base cost will be enabled - FixRelayedBaseCostEnableEpoch = 4 + FixRelayedBaseCostEnableEpoch = 1 # 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 = 4 + FixRelayedMoveBalanceToNonPayableSCEnableEpoch = 1 # BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers BLSMultiSignerEnableEpoch = [ From 065db180a5c528b4b8ef704bb78b54c8a0520d6d Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 15 Nov 2024 10:39:02 +0200 Subject: [PATCH 460/467] heart beats in chain simulator --- cmd/node/config/external.toml | 4 +-- node/chainSimulator/chainSimulator_test.go | 6 +++++ node/chainSimulator/components/nodeFacade.go | 26 ++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/cmd/node/config/external.toml b/cmd/node/config/external.toml index 6fbbbb195c6..73bc78bae55 100644 --- a/cmd/node/config/external.toml +++ b/cmd/node/config/external.toml @@ -12,8 +12,8 @@ Username = "" Password = "" # EnabledIndexes represents a slice of indexes that will be enabled for indexing. Full list is: - # ["rating", "transactions", "blocks", "validators", "miniblocks", "rounds", "accounts", "accountshistory", "receipts", "scresults", "accountsesdt", "accountsesdthistory", "epochinfo", "scdeploys", "tokens", "tags", "logs", "delegators", "operations", "esdts"] - EnabledIndexes = ["rating", "transactions", "blocks", "validators", "miniblocks", "rounds", "accounts", "accountshistory", "receipts", "scresults", "accountsesdt", "accountsesdthistory", "epochinfo", "scdeploys", "tokens", "tags", "logs", "delegators", "operations", "esdts"] + # ["rating", "transactions", "blocks", "validators", "miniblocks", "rounds", "accounts", "accountshistory", "receipts", "scresults", "accountsesdt", "accountsesdthistory", "epochinfo", "scdeploys", "tokens", "tags", "logs", "delegators", "operations", "esdts", "events"] + EnabledIndexes = ["rating", "transactions", "blocks", "validators", "miniblocks", "rounds", "accounts", "accountshistory", "receipts", "scresults", "accountsesdt", "accountsesdthistory", "epochinfo", "scdeploys", "tokens", "tags", "logs", "delegators", "operations", "esdts", "events"] # EventNotifierConnector defines settings needed to configure and launch the event notifier component # HTTP event notifier connector integration will be DEPRECATED in the following iterations diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index 18f54ccbfe9..fde143eb3e5 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -83,6 +83,12 @@ func TestChainSimulator_GenerateBlocksShouldWork(t *testing.T) { require.Nil(t, err) require.NotNil(t, chainSimulator) + time.Sleep(time.Second) + + heartBeats, err := chainSimulator.GetNodeHandler(0).GetFacadeHandler().GetHeartbeats() + require.Nil(t, err) + require.Equal(t, 1, len(heartBeats)) + defer chainSimulator.Close() time.Sleep(time.Second) diff --git a/node/chainSimulator/components/nodeFacade.go b/node/chainSimulator/components/nodeFacade.go index d62814fdf03..44dd39b2999 100644 --- a/node/chainSimulator/components/nodeFacade.go +++ b/node/chainSimulator/components/nodeFacade.go @@ -3,6 +3,7 @@ package components import ( "errors" "fmt" + "github.com/multiversx/mx-chain-go/factory/heartbeat" "strconv" "time" @@ -73,6 +74,30 @@ func (node *testOnlyProcessingNode) createFacade(configs config.Configs, apiInte flagsConfig := configs.FlagsConfig + heartBeatComponentsFactory, err := heartbeat.NewHeartbeatV2ComponentsFactory(heartbeat.ArgHeartbeatV2ComponentsFactory{ + Config: *configs.GeneralConfig, + Prefs: *configs.PreferencesConfig, + BaseVersion: "1", + AppVersion: "1", + BootstrapComponents: node.BootstrapComponentsHolder, + CoreComponents: node.CoreComponentsHolder, + DataComponents: node.DataComponentsHolder, + NetworkComponents: node.NetworkComponentsHolder, + CryptoComponents: node.CryptoComponentsHolder, + ProcessComponents: node.ProcessComponentsHolder, + StatusCoreComponents: node.StatusCoreComponents, + }) + + managedHeartbeatV2Components, err := heartbeat.NewManagedHeartbeatV2Components(heartBeatComponentsFactory) + if err != nil { + return err + } + + err = managedHeartbeatV2Components.Create() + if err != nil { + return err + } + nd, err := nodePack.NewNode( nodePack.WithStatusCoreComponents(node.StatusCoreComponents), nodePack.WithCoreComponents(node.CoreComponentsHolder), @@ -95,6 +120,7 @@ func (node *testOnlyProcessingNode) createFacade(configs config.Configs, apiInte nodePack.WithNodeStopChannel(node.CoreComponentsHolder.ChanStopNodeProcess()), nodePack.WithImportMode(configs.ImportDbConfig.IsImportDBMode), nodePack.WithESDTNFTStorageHandler(node.ProcessComponentsHolder.ESDTDataStorageHandlerForAPI()), + nodePack.WithHeartbeatV2Components(managedHeartbeatV2Components), ) if err != nil { return errors.New("error creating node: " + err.Error()) From 38d41ac23dc64a3d55670e3885577854d5568761 Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 15 Nov 2024 10:39:28 +0200 Subject: [PATCH 461/467] fix imports --- node/chainSimulator/components/nodeFacade.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/node/chainSimulator/components/nodeFacade.go b/node/chainSimulator/components/nodeFacade.go index 44dd39b2999..14218befefa 100644 --- a/node/chainSimulator/components/nodeFacade.go +++ b/node/chainSimulator/components/nodeFacade.go @@ -3,7 +3,6 @@ package components import ( "errors" "fmt" - "github.com/multiversx/mx-chain-go/factory/heartbeat" "strconv" "time" @@ -14,6 +13,7 @@ import ( "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/facade" apiComp "github.com/multiversx/mx-chain-go/factory/api" + "github.com/multiversx/mx-chain-go/factory/heartbeat" nodePack "github.com/multiversx/mx-chain-go/node" "github.com/multiversx/mx-chain-go/node/metrics" "github.com/multiversx/mx-chain-go/process/mock" From c1bcc7e03d1420c5e42f27000ab54d883039cc60 Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 15 Nov 2024 11:47:47 +0200 Subject: [PATCH 462/467] index validators chain simulator --- .../components/statusComponents.go | 53 ++++++++++++++++--- .../components/testOnlyProcessingNode.go | 7 ++- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/node/chainSimulator/components/statusComponents.go b/node/chainSimulator/components/statusComponents.go index be094472fc1..ab62c86581f 100644 --- a/node/chainSimulator/components/statusComponents.go +++ b/node/chainSimulator/components/statusComponents.go @@ -3,6 +3,12 @@ package components import ( "context" "fmt" + nodeData "github.com/multiversx/mx-chain-core-go/data" + outportCore "github.com/multiversx/mx-chain-core-go/data/outport" + "github.com/multiversx/mx-chain-go/epochStart" + "github.com/multiversx/mx-chain-go/epochStart/notifier" + "github.com/multiversx/mx-chain-go/factory" + "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "sync" "time" @@ -17,7 +23,7 @@ import ( "github.com/multiversx/mx-chain-go/errors" "github.com/multiversx/mx-chain-go/integrationTests/mock" "github.com/multiversx/mx-chain-go/outport" - "github.com/multiversx/mx-chain-go/outport/factory" + outportFactory "github.com/multiversx/mx-chain-go/outport/factory" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/testscommon" ) @@ -32,10 +38,11 @@ type statusComponentsHolder struct { statusPollingIntervalSec int cancelFunc func() mutex sync.RWMutex + nodesCoordinator nodesCoordinator.NodesCoordinator } // CreateStatusComponents will create a new instance of status components holder -func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandler, statusPollingIntervalSec int, external config.ExternalConfig, coreComponents process.CoreComponentsHolder) (*statusComponentsHolder, error) { +func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandler, statusPollingIntervalSec int, external config.ExternalConfig, coreComponents factory.CoreComponentsHandler) (*statusComponentsHolder, error) { if check.IfNil(appStatusHandler) { return nil, core.ErrNilAppStatusHandler } @@ -51,12 +58,12 @@ func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandl if err != nil { return nil, err } - instance.outportHandler, err = factory.CreateOutport(&factory.OutportFactoryArgs{ + instance.outportHandler, err = outportFactory.CreateOutport(&outportFactory.OutportFactoryArgs{ IsImportDB: false, ShardID: shardID, RetrialInterval: time.Second, HostDriversArgs: hostDriverArgs, - EventNotifierFactoryArgs: &factory.EventNotifierFactoryArgs{}, + EventNotifierFactoryArgs: &outportFactory.EventNotifierFactoryArgs{}, ElasticIndexerFactoryArgs: makeElasticIndexerArgs(external, coreComponents), }) if err != nil { @@ -65,13 +72,45 @@ func CreateStatusComponents(shardID uint32, appStatusHandler core.AppStatusHandl instance.softwareVersionChecker = &mock.SoftwareVersionCheckerMock{} instance.managedPeerMonitor = &testscommon.ManagedPeersMonitorStub{} + if shardID == core.MetachainShardId { + coreComponents.EpochStartNotifierWithConfirm().RegisterHandler(instance.epochStartEventHandler()) + } + instance.collectClosableComponents() return instance, nil } -func makeHostDriversArgs(external config.ExternalConfig) ([]factory.ArgsHostDriverFactory, error) { - argsHostDriverFactorySlice := make([]factory.ArgsHostDriverFactory, 0, len(external.HostDriversConfig)) +// SetNodesCoordinator will set the nodes coordinator +func (s *statusComponentsHolder) SetNodesCoordinator(nodesCoordinator nodesCoordinator.NodesCoordinator) { + s.mutex.Lock() + s.nodesCoordinator = nodesCoordinator + s.mutex.Unlock() +} + +func (s *statusComponentsHolder) epochStartEventHandler() epochStart.ActionHandler { + subscribeHandler := notifier.NewHandlerForEpochStart(func(hdr nodeData.HeaderHandler) { + currentEpoch := hdr.GetEpoch() + validatorsPubKeys, err := s.nodesCoordinator.GetAllEligibleValidatorsPublicKeys(currentEpoch) + if err != nil { + log.Warn("s.nodesCoordinator.GetAllEligibleValidatorPublicKeys for current epoch failed", + "epoch", currentEpoch, + "error", err.Error()) + } + + s.outportHandler.SaveValidatorsPubKeys(&outportCore.ValidatorsPubKeys{ + ShardID: hdr.GetShardID(), + ShardValidatorsPubKeys: outportCore.ConvertPubKeys(validatorsPubKeys), + Epoch: currentEpoch, + }) + + }, func(_ nodeData.HeaderHandler) {}, common.IndexerOrder) + + return subscribeHandler +} + +func makeHostDriversArgs(external config.ExternalConfig) ([]outportFactory.ArgsHostDriverFactory, error) { + argsHostDriverFactorySlice := make([]outportFactory.ArgsHostDriverFactory, 0, len(external.HostDriversConfig)) for idx := 0; idx < len(external.HostDriversConfig); idx++ { hostConfig := external.HostDriversConfig[idx] if !hostConfig.Enabled { @@ -83,7 +122,7 @@ func makeHostDriversArgs(external config.ExternalConfig) ([]factory.ArgsHostDriv return argsHostDriverFactorySlice, err } - argsHostDriverFactorySlice = append(argsHostDriverFactorySlice, factory.ArgsHostDriverFactory{ + argsHostDriverFactorySlice = append(argsHostDriverFactorySlice, outportFactory.ArgsHostDriverFactory{ Marshaller: marshaller, HostConfig: hostConfig, }) diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index 28256c4820f..6f90485993c 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -148,7 +148,8 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces } selfShardID := instance.GetShardCoordinator().SelfId() - instance.StatusComponentsHolder, err = CreateStatusComponents( + + statusComponentsH, err := CreateStatusComponents( selfShardID, instance.StatusCoreComponents.AppStatusHandler(), args.Configs.GeneralConfig.GeneralSettings.StatusPollingIntervalSec, @@ -159,6 +160,8 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces return nil, err } + instance.StatusComponentsHolder = statusComponentsH + err = instance.createBlockChain(selfShardID) if err != nil { return nil, err @@ -184,6 +187,8 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces return nil, err } + statusComponentsH.SetNodesCoordinator(instance.NodesCoordinator) + instance.DataComponentsHolder, err = CreateDataComponents(ArgsDataComponentsHolder{ Chain: instance.ChainHandler, StorageService: instance.StoreService, From 2c33cdf89e251c72591f767f44e08fe8e4536571 Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 15 Nov 2024 11:48:15 +0200 Subject: [PATCH 463/467] imports --- node/chainSimulator/components/statusComponents.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/node/chainSimulator/components/statusComponents.go b/node/chainSimulator/components/statusComponents.go index ab62c86581f..ab561e25c2c 100644 --- a/node/chainSimulator/components/statusComponents.go +++ b/node/chainSimulator/components/statusComponents.go @@ -3,28 +3,28 @@ package components import ( "context" "fmt" - nodeData "github.com/multiversx/mx-chain-core-go/data" - outportCore "github.com/multiversx/mx-chain-core-go/data/outport" - "github.com/multiversx/mx-chain-go/epochStart" - "github.com/multiversx/mx-chain-go/epochStart/notifier" - "github.com/multiversx/mx-chain-go/factory" - "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "sync" "time" "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/appStatusPolling" "github.com/multiversx/mx-chain-core-go/core/check" + nodeData "github.com/multiversx/mx-chain-core-go/data" + outportCore "github.com/multiversx/mx-chain-core-go/data/outport" factoryMarshalizer "github.com/multiversx/mx-chain-core-go/marshal/factory" indexerFactory "github.com/multiversx/mx-chain-es-indexer-go/process/factory" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/common/statistics" "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/epochStart" + "github.com/multiversx/mx-chain-go/epochStart/notifier" "github.com/multiversx/mx-chain-go/errors" + "github.com/multiversx/mx-chain-go/factory" "github.com/multiversx/mx-chain-go/integrationTests/mock" "github.com/multiversx/mx-chain-go/outport" outportFactory "github.com/multiversx/mx-chain-go/outport/factory" "github.com/multiversx/mx-chain-go/process" + "github.com/multiversx/mx-chain-go/sharding/nodesCoordinator" "github.com/multiversx/mx-chain-go/testscommon" ) From 860f20d5f8f2794a994b202f6ed262fcf854ccf2 Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 15 Nov 2024 12:26:04 +0200 Subject: [PATCH 464/467] fix linter --- node/chainSimulator/components/nodeFacade.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/node/chainSimulator/components/nodeFacade.go b/node/chainSimulator/components/nodeFacade.go index 14218befefa..4d0af7def23 100644 --- a/node/chainSimulator/components/nodeFacade.go +++ b/node/chainSimulator/components/nodeFacade.go @@ -87,6 +87,9 @@ func (node *testOnlyProcessingNode) createFacade(configs config.Configs, apiInte ProcessComponents: node.ProcessComponentsHolder, StatusCoreComponents: node.StatusCoreComponents, }) + if err != nil { + return err + } managedHeartbeatV2Components, err := heartbeat.NewManagedHeartbeatV2Components(heartBeatComponentsFactory) if err != nil { From a97147f97d05234653cd560e398c3896d569884d Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 19 Nov 2024 16:48:03 +0200 Subject: [PATCH 465/467] chain simulator heartbeat --- .../vm/esdtImprovements_test.go | 20 +++++-- node/chainSimulator/chainSimulator.go | 11 ++-- node/chainSimulator/chainSimulator_test.go | 12 ++--- .../components/heartbeat/heartBeat.go | 52 +++++++++++++++++++ .../components/heartbeat/monitor.go | 39 ++++++++++++++ node/chainSimulator/components/nodeFacade.go | 31 +++-------- .../components/testOnlyProcessingNode.go | 3 +- node/chainSimulator/process/interface.go | 7 +++ node/chainSimulator/process/processor.go | 38 +++++++++++++- node/chainSimulator/process/processor_test.go | 33 ++++++------ 10 files changed, 188 insertions(+), 58 deletions(-) create mode 100644 node/chainSimulator/components/heartbeat/heartBeat.go create mode 100644 node/chainSimulator/components/heartbeat/monitor.go diff --git a/integrationTests/chainSimulator/vm/esdtImprovements_test.go b/integrationTests/chainSimulator/vm/esdtImprovements_test.go index e0f23f1ce8c..8361feb4fee 100644 --- a/integrationTests/chainSimulator/vm/esdtImprovements_test.go +++ b/integrationTests/chainSimulator/vm/esdtImprovements_test.go @@ -3868,7 +3868,9 @@ func TestChainSimulator_CheckRolesWhichHasToBeSingular(t *testing.T) { } func TestChainSimulator_metaESDT_mergeMetaDataFromMultipleUpdates(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } baseIssuingCost := "1000" cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) @@ -4237,7 +4239,9 @@ func transferSpecialRoleToAddr( } func TestChainSimulator_dynamicNFT_mergeMetaDataFromMultipleUpdates(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } baseIssuingCost := "1000" cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) @@ -4385,7 +4389,9 @@ func TestChainSimulator_dynamicNFT_mergeMetaDataFromMultipleUpdates(t *testing.T } func TestChainSimulator_dynamicNFT_changeMetaDataForOneNFTShouldNotChangeOtherNonces(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } baseIssuingCost := "1000" cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) @@ -4498,7 +4504,9 @@ func TestChainSimulator_dynamicNFT_changeMetaDataForOneNFTShouldNotChangeOtherNo } func TestChainSimulator_dynamicNFT_updateBeforeCreateOnSameAccountShouldOverwrite(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } baseIssuingCost := "1000" cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) @@ -4595,7 +4603,9 @@ func TestChainSimulator_dynamicNFT_updateBeforeCreateOnSameAccountShouldOverwrit } func TestChainSimulator_dynamicNFT_updateBeforeCreateOnDifferentAccountsShouldMergeMetaDataWhenTransferred(t *testing.T) { - t.Parallel() + if testing.Short() { + t.Skip("this is not a short test") + } baseIssuingCost := "1000" cs, _ := getTestChainSimulatorWithDynamicNFTEnabled(t, baseIssuingCost) diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index 742d040c8c8..b8edc491eda 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -11,7 +11,9 @@ import ( "time" "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/factory" "github.com/multiversx/mx-chain-go/node/chainSimulator/components" + "github.com/multiversx/mx-chain-go/node/chainSimulator/components/heartbeat" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" chainSimulatorErrors "github.com/multiversx/mx-chain-go/node/chainSimulator/errors" @@ -130,18 +132,20 @@ func (s *simulator) createChainHandlers(args ArgsBaseChainSimulator) error { return err } + monitor := heartbeat.NewHeartbeatMonitor() + for idx := -1; idx < int(args.NumOfShards); idx++ { shardIDStr := fmt.Sprintf("%d", idx) if idx == -1 { shardIDStr = "metachain" } - node, errCreate := s.createTestNode(*outputConfigs, args, shardIDStr) + node, errCreate := s.createTestNode(*outputConfigs, args, shardIDStr, monitor) if errCreate != nil { return errCreate } - chainHandler, errCreate := process.NewBlocksCreator(node) + chainHandler, errCreate := process.NewBlocksCreator(node, monitor) if errCreate != nil { return errCreate } @@ -195,7 +199,7 @@ func computeStartTimeBaseOnInitialRound(args ArgsChainSimulator) int64 { } func (s *simulator) createTestNode( - outputConfigs configs.ArgsConfigsSimulator, args ArgsBaseChainSimulator, shardIDStr string, + outputConfigs configs.ArgsConfigsSimulator, args ArgsBaseChainSimulator, shardIDStr string, monitor factory.HeartbeatV2Monitor, ) (process.NodeHandler, error) { argsTestOnlyProcessorNode := components.ArgsTestOnlyProcessingNode{ Configs: outputConfigs.Configs, @@ -214,6 +218,7 @@ func (s *simulator) createTestNode( MetaChainConsensusGroupSize: args.MetaChainConsensusGroupSize, RoundDurationInMillis: args.RoundDurationInMillis, VmQueryDelayAfterStartInMs: args.VmQueryDelayAfterStartInMs, + Monitor: monitor, } return components.NewTestOnlyProcessingNode(argsTestOnlyProcessorNode) diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index fde143eb3e5..2ba89205afe 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -82,19 +82,17 @@ func TestChainSimulator_GenerateBlocksShouldWork(t *testing.T) { }) require.Nil(t, err) require.NotNil(t, chainSimulator) - - time.Sleep(time.Second) - - heartBeats, err := chainSimulator.GetNodeHandler(0).GetFacadeHandler().GetHeartbeats() - require.Nil(t, err) - require.Equal(t, 1, len(heartBeats)) - defer chainSimulator.Close() time.Sleep(time.Second) err = chainSimulator.GenerateBlocks(50) require.Nil(t, err) + + heartBeats, err := chainSimulator.GetNodeHandler(0).GetFacadeHandler().GetHeartbeats() + require.Nil(t, err) + require.Equal(t, 4, len(heartBeats)) + } func TestChainSimulator_GenerateBlocksAndEpochChangeShouldWork(t *testing.T) { diff --git a/node/chainSimulator/components/heartbeat/heartBeat.go b/node/chainSimulator/components/heartbeat/heartBeat.go new file mode 100644 index 00000000000..ffdd53b6961 --- /dev/null +++ b/node/chainSimulator/components/heartbeat/heartBeat.go @@ -0,0 +1,52 @@ +package heartbeat + +import ( + "github.com/multiversx/mx-chain-core-go/core/check" + "github.com/multiversx/mx-chain-go/factory" + "github.com/multiversx/mx-chain-go/heartbeat" +) + +type heartBeatComponents struct { + monitor factory.HeartbeatV2Monitor +} + +// NewSyncedHeartbeatComponents will create a new instance of heartbeat components +func NewSyncedHeartbeatComponents(monitor factory.HeartbeatV2Monitor) (factory.HeartbeatV2ComponentsHandler, error) { + if check.IfNil(monitor) { + return nil, heartbeat.ErrNilHeartbeatMonitor + } + + return &heartBeatComponents{ + monitor: monitor, + }, nil +} + +// Create will do nothing +func (h *heartBeatComponents) Create() error { + return nil +} + +// Close will do nothing +func (h *heartBeatComponents) Close() error { + return nil +} + +// CheckSubcomponents will do nothing +func (h *heartBeatComponents) CheckSubcomponents() error { + return nil +} + +// String will return a string +func (h *heartBeatComponents) String() string { + return "heartBeat" +} + +// Monitor will return the monitor +func (h *heartBeatComponents) Monitor() factory.HeartbeatV2Monitor { + return h.monitor +} + +// IsInterfaceNil returns true if there is no value under the interface +func (h *heartBeatComponents) IsInterfaceNil() bool { + return h == nil +} diff --git a/node/chainSimulator/components/heartbeat/monitor.go b/node/chainSimulator/components/heartbeat/monitor.go new file mode 100644 index 00000000000..9fda1a369f8 --- /dev/null +++ b/node/chainSimulator/components/heartbeat/monitor.go @@ -0,0 +1,39 @@ +package heartbeat + +import ( + "sync" + + "github.com/multiversx/mx-chain-go/heartbeat/data" +) + +type heartbeatMonitor struct { + heartbeats []data.PubKeyHeartbeat + mutex sync.RWMutex +} + +// NewHeartbeatMonitor will create a new instance of heartbeat monitor +func NewHeartbeatMonitor() *heartbeatMonitor { + return &heartbeatMonitor{ + heartbeats: make([]data.PubKeyHeartbeat, 0), + } +} + +// GetHeartbeats will return the heartbeats +func (hm *heartbeatMonitor) GetHeartbeats() []data.PubKeyHeartbeat { + hm.mutex.RLock() + defer hm.mutex.RUnlock() + + return hm.heartbeats +} + +// SetHeartbeats will set the provided heartbeats +func (hm *heartbeatMonitor) SetHeartbeats(heartbeats []data.PubKeyHeartbeat) { + hm.mutex.Lock() + hm.heartbeats = heartbeats + hm.mutex.Unlock() +} + +// IsInterfaceNil returns true if there is no value under the interface +func (hm *heartbeatMonitor) IsInterfaceNil() bool { + return nil == hm +} diff --git a/node/chainSimulator/components/nodeFacade.go b/node/chainSimulator/components/nodeFacade.go index 4d0af7def23..f1bacb11b96 100644 --- a/node/chainSimulator/components/nodeFacade.go +++ b/node/chainSimulator/components/nodeFacade.go @@ -3,6 +3,8 @@ package components import ( "errors" "fmt" + "github.com/multiversx/mx-chain-go/factory" + heartbeat2 "github.com/multiversx/mx-chain-go/node/chainSimulator/components/heartbeat" "strconv" "time" @@ -13,13 +15,12 @@ import ( "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/facade" apiComp "github.com/multiversx/mx-chain-go/factory/api" - "github.com/multiversx/mx-chain-go/factory/heartbeat" nodePack "github.com/multiversx/mx-chain-go/node" "github.com/multiversx/mx-chain-go/node/metrics" "github.com/multiversx/mx-chain-go/process/mock" ) -func (node *testOnlyProcessingNode) createFacade(configs config.Configs, apiInterface APIConfigurator, vmQueryDelayAfterStartInMs uint64) error { +func (node *testOnlyProcessingNode) createFacade(configs config.Configs, apiInterface APIConfigurator, vmQueryDelayAfterStartInMs uint64, monitor factory.HeartbeatV2Monitor) error { log.Debug("creating api resolver structure") err := node.createMetrics(configs) @@ -74,32 +75,12 @@ func (node *testOnlyProcessingNode) createFacade(configs config.Configs, apiInte flagsConfig := configs.FlagsConfig - heartBeatComponentsFactory, err := heartbeat.NewHeartbeatV2ComponentsFactory(heartbeat.ArgHeartbeatV2ComponentsFactory{ - Config: *configs.GeneralConfig, - Prefs: *configs.PreferencesConfig, - BaseVersion: "1", - AppVersion: "1", - BootstrapComponents: node.BootstrapComponentsHolder, - CoreComponents: node.CoreComponentsHolder, - DataComponents: node.DataComponentsHolder, - NetworkComponents: node.NetworkComponentsHolder, - CryptoComponents: node.CryptoComponentsHolder, - ProcessComponents: node.ProcessComponentsHolder, - StatusCoreComponents: node.StatusCoreComponents, - }) + heartbeatComponents, err := heartbeat2.NewSyncedHeartbeatComponents(monitor) if err != nil { return err } - managedHeartbeatV2Components, err := heartbeat.NewManagedHeartbeatV2Components(heartBeatComponentsFactory) - if err != nil { - return err - } - - err = managedHeartbeatV2Components.Create() - if err != nil { - return err - } + node.closeHandler.AddComponent(heartbeatComponents) nd, err := nodePack.NewNode( nodePack.WithStatusCoreComponents(node.StatusCoreComponents), @@ -123,7 +104,7 @@ func (node *testOnlyProcessingNode) createFacade(configs config.Configs, apiInte nodePack.WithNodeStopChannel(node.CoreComponentsHolder.ChanStopNodeProcess()), nodePack.WithImportMode(configs.ImportDbConfig.IsImportDBMode), nodePack.WithESDTNFTStorageHandler(node.ProcessComponentsHolder.ESDTDataStorageHandlerForAPI()), - nodePack.WithHeartbeatV2Components(managedHeartbeatV2Components), + nodePack.WithHeartbeatV2Components(heartbeatComponents), ) if err != nil { return errors.New("error creating node: " + err.Error()) diff --git a/node/chainSimulator/components/testOnlyProcessingNode.go b/node/chainSimulator/components/testOnlyProcessingNode.go index 6f90485993c..8bc542f432c 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -37,6 +37,7 @@ type ArgsTestOnlyProcessingNode struct { ChanStopNodeProcess chan endProcess.ArgEndProcess SyncedBroadcastNetwork SyncedBroadcastNetworkHandler + Monitor factory.HeartbeatV2Monitor InitialRound int64 InitialNonce uint64 @@ -240,7 +241,7 @@ func NewTestOnlyProcessingNode(args ArgsTestOnlyProcessingNode) (*testOnlyProces return nil, err } - err = instance.createFacade(args.Configs, args.APIInterface, args.VmQueryDelayAfterStartInMs) + err = instance.createFacade(args.Configs, args.APIInterface, args.VmQueryDelayAfterStartInMs, args.Monitor) if err != nil { return nil, err } diff --git a/node/chainSimulator/process/interface.go b/node/chainSimulator/process/interface.go index 47f937fb97c..7ae2f07517e 100644 --- a/node/chainSimulator/process/interface.go +++ b/node/chainSimulator/process/interface.go @@ -5,6 +5,7 @@ import ( "github.com/multiversx/mx-chain-go/api/shared" "github.com/multiversx/mx-chain-go/consensus" "github.com/multiversx/mx-chain-go/factory" + "github.com/multiversx/mx-chain-go/heartbeat/data" "github.com/multiversx/mx-chain-go/node/chainSimulator/dtos" "github.com/multiversx/mx-chain-go/sharding" ) @@ -28,3 +29,9 @@ type NodeHandler interface { Close() error IsInterfaceNil() bool } + +// HeartbeatMonitorWithSet defines what a heartbeat monitor with set should be able to do +type HeartbeatMonitorWithSet interface { + SetHeartbeats(heartbeats []data.PubKeyHeartbeat) + IsInterfaceNil() bool +} diff --git a/node/chainSimulator/process/processor.go b/node/chainSimulator/process/processor.go index d8f225bfde8..1c9819e27f0 100644 --- a/node/chainSimulator/process/processor.go +++ b/node/chainSimulator/process/processor.go @@ -1,10 +1,13 @@ package process import ( + "time" + "github.com/multiversx/mx-chain-core-go/core/check" "github.com/multiversx/mx-chain-core-go/data" "github.com/multiversx/mx-chain-go/common" "github.com/multiversx/mx-chain-go/consensus/spos" + heartbeatData "github.com/multiversx/mx-chain-go/heartbeat/data" "github.com/multiversx/mx-chain-go/node/chainSimulator/configs" logger "github.com/multiversx/mx-chain-logger-go" ) @@ -17,16 +20,18 @@ type manualRoundHandler interface { type blocksCreator struct { nodeHandler NodeHandler + monitor HeartbeatMonitorWithSet } // NewBlocksCreator will create a new instance of blocksCreator -func NewBlocksCreator(nodeHandler NodeHandler) (*blocksCreator, error) { +func NewBlocksCreator(nodeHandler NodeHandler, monitor HeartbeatMonitorWithSet) (*blocksCreator, error) { if check.IfNil(nodeHandler) { return nil, ErrNilNodeHandler } return &blocksCreator{ nodeHandler: nodeHandler, + monitor: monitor, }, nil } @@ -123,6 +128,11 @@ func (creator *blocksCreator) CreateNewBlock() error { return err } + err = creator.setHeartBeat(header) + if err != nil { + return err + } + miniBlocks, transactions, err := bp.MarshalizedDataToBroadcast(header, block) if err != nil { return err @@ -141,6 +151,32 @@ func (creator *blocksCreator) CreateNewBlock() error { return creator.nodeHandler.GetBroadcastMessenger().BroadcastTransactions(transactions, blsKey.PubKey()) } +func (creator *blocksCreator) setHeartBeat(header data.HeaderHandler) error { + if !header.IsStartOfEpochBlock() { + return nil + } + + validators := creator.nodeHandler.GetProcessComponents().ValidatorsProvider().GetLatestValidators() + + var heartbeats []heartbeatData.PubKeyHeartbeat + for key, validator := range validators { + heartbeats = append(heartbeats, heartbeatData.PubKeyHeartbeat{ + PublicKey: key, + TimeStamp: time.Now(), + IsActive: true, + NumInstances: 1, + ComputedShardID: creator.nodeHandler.GetShardCoordinator().SelfId(), + ReceivedShardID: validator.ShardId, + }) + } + + if len(heartbeats) > 0 { + creator.monitor.SetHeartbeats(heartbeats) + } + + return nil +} + func (creator *blocksCreator) getPreviousHeaderData() (nonce, round uint64, prevHash, prevRandSeed []byte, epoch uint32) { currentHeader := creator.nodeHandler.GetChainHandler().GetCurrentBlockHeader() diff --git a/node/chainSimulator/process/processor_test.go b/node/chainSimulator/process/processor_test.go index 80ffd568134..84a93eea028 100644 --- a/node/chainSimulator/process/processor_test.go +++ b/node/chainSimulator/process/processor_test.go @@ -14,6 +14,7 @@ import ( mockConsensus "github.com/multiversx/mx-chain-go/consensus/mock" "github.com/multiversx/mx-chain-go/factory" "github.com/multiversx/mx-chain-go/integrationTests/mock" + "github.com/multiversx/mx-chain-go/node/chainSimulator/components/heartbeat" chainSimulatorProcess "github.com/multiversx/mx-chain-go/node/chainSimulator/process" "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-go/sharding" @@ -35,14 +36,14 @@ func TestNewBlocksCreator(t *testing.T) { t.Run("nil node handler should error", func(t *testing.T) { t.Parallel() - creator, err := chainSimulatorProcess.NewBlocksCreator(nil) + creator, err := chainSimulatorProcess.NewBlocksCreator(nil, heartbeat.NewHeartbeatMonitor()) require.Equal(t, chainSimulatorProcess.ErrNilNodeHandler, err) require.Nil(t, creator) }) t.Run("should work", func(t *testing.T) { t.Parallel() - creator, err := chainSimulatorProcess.NewBlocksCreator(&chainSimulator.NodeHandlerMock{}) + creator, err := chainSimulatorProcess.NewBlocksCreator(&chainSimulator.NodeHandlerMock{}, heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) require.NotNil(t, creator) }) @@ -51,10 +52,10 @@ func TestNewBlocksCreator(t *testing.T) { func TestBlocksCreator_IsInterfaceNil(t *testing.T) { t.Parallel() - creator, _ := chainSimulatorProcess.NewBlocksCreator(nil) + creator, _ := chainSimulatorProcess.NewBlocksCreator(nil, heartbeat.NewHeartbeatMonitor()) require.True(t, creator.IsInterfaceNil()) - creator, _ = chainSimulatorProcess.NewBlocksCreator(&chainSimulator.NodeHandlerMock{}) + creator, _ = chainSimulatorProcess.NewBlocksCreator(&chainSimulator.NodeHandlerMock{}, heartbeat.NewHeartbeatMonitor()) require.False(t, creator.IsInterfaceNil()) } @@ -86,7 +87,7 @@ func TestBlocksCreator_IncrementRound(t *testing.T) { } }, } - creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler) + creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler, heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) creator.IncrementRound() @@ -119,7 +120,7 @@ func TestBlocksCreator_CreateNewBlock(t *testing.T) { } } - creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler) + creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler, heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) err = creator.CreateNewBlock() @@ -227,7 +228,7 @@ func TestBlocksCreator_CreateNewBlock(t *testing.T) { }, } } - creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler) + creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler, heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) err = creator.CreateNewBlock() @@ -246,7 +247,7 @@ func TestBlocksCreator_CreateNewBlock(t *testing.T) { }, } } - creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler) + creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler, heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) err = creator.CreateNewBlock() @@ -267,7 +268,7 @@ func TestBlocksCreator_CreateNewBlock(t *testing.T) { }, } } - creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler) + creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler, heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) err = creator.CreateNewBlock() @@ -319,7 +320,7 @@ func TestBlocksCreator_CreateNewBlock(t *testing.T) { }, } } - creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler) + creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler, heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) err = creator.CreateNewBlock() @@ -340,7 +341,7 @@ func TestBlocksCreator_CreateNewBlock(t *testing.T) { }, } } - creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler) + creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler, heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) err = creator.CreateNewBlock() @@ -361,7 +362,7 @@ func TestBlocksCreator_CreateNewBlock(t *testing.T) { }, } } - creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler) + creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler, heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) err = creator.CreateNewBlock() @@ -382,7 +383,7 @@ func TestBlocksCreator_CreateNewBlock(t *testing.T) { }, } } - creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler) + creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler, heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) err = creator.CreateNewBlock() @@ -521,7 +522,7 @@ func TestBlocksCreator_CreateNewBlock(t *testing.T) { }, } } - creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler) + creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler, heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) err = creator.CreateNewBlock() @@ -530,7 +531,7 @@ func TestBlocksCreator_CreateNewBlock(t *testing.T) { t.Run("should work", func(t *testing.T) { t.Parallel() - creator, err := chainSimulatorProcess.NewBlocksCreator(getNodeHandler()) + creator, err := chainSimulatorProcess.NewBlocksCreator(getNodeHandler(), heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) err = creator.CreateNewBlock() @@ -547,7 +548,7 @@ func testCreateNewBlock(t *testing.T, blockProcess process.BlockProcessor, expec NodesCoord: nc, } } - creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler) + creator, err := chainSimulatorProcess.NewBlocksCreator(nodeHandler, heartbeat.NewHeartbeatMonitor()) require.NoError(t, err) err = creator.CreateNewBlock() From ba15dcb20411be069c88882f1cc00b03472c4705 Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 19 Nov 2024 16:50:05 +0200 Subject: [PATCH 466/467] fixes --- node/chainSimulator/components/testOnlyProcessingNode_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/node/chainSimulator/components/testOnlyProcessingNode_test.go b/node/chainSimulator/components/testOnlyProcessingNode_test.go index c363ca8019c..801c11585e9 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode_test.go +++ b/node/chainSimulator/components/testOnlyProcessingNode_test.go @@ -2,6 +2,7 @@ package components import ( "errors" + "github.com/multiversx/mx-chain-go/node/chainSimulator/components/heartbeat" "math/big" "strings" "testing" @@ -44,6 +45,7 @@ func createMockArgsTestOnlyProcessingNode(t *testing.T) ArgsTestOnlyProcessingNo SyncedBroadcastNetwork: NewSyncedBroadcastNetwork(), ChanStopNodeProcess: make(chan endProcess.ArgEndProcess), APIInterface: api.NewNoApiInterface(), + Monitor: heartbeat.NewHeartbeatMonitor(), ShardIDStr: "0", RoundDurationInMillis: 6000, MinNodesMeta: 1, From 5e01a062b7d170b871aece1113ad83ea1bc9c7c1 Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 20 Nov 2024 10:27:07 +0200 Subject: [PATCH 467/467] fixes after review --- node/chainSimulator/components/nodeFacade.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/node/chainSimulator/components/nodeFacade.go b/node/chainSimulator/components/nodeFacade.go index f1bacb11b96..24bdc3d1ada 100644 --- a/node/chainSimulator/components/nodeFacade.go +++ b/node/chainSimulator/components/nodeFacade.go @@ -3,8 +3,6 @@ package components import ( "errors" "fmt" - "github.com/multiversx/mx-chain-go/factory" - heartbeat2 "github.com/multiversx/mx-chain-go/node/chainSimulator/components/heartbeat" "strconv" "time" @@ -14,8 +12,10 @@ import ( "github.com/multiversx/mx-chain-go/common/forking" "github.com/multiversx/mx-chain-go/config" "github.com/multiversx/mx-chain-go/facade" + "github.com/multiversx/mx-chain-go/factory" apiComp "github.com/multiversx/mx-chain-go/factory/api" nodePack "github.com/multiversx/mx-chain-go/node" + simulatorHeartbeat "github.com/multiversx/mx-chain-go/node/chainSimulator/components/heartbeat" "github.com/multiversx/mx-chain-go/node/metrics" "github.com/multiversx/mx-chain-go/process/mock" ) @@ -75,7 +75,7 @@ func (node *testOnlyProcessingNode) createFacade(configs config.Configs, apiInte flagsConfig := configs.FlagsConfig - heartbeatComponents, err := heartbeat2.NewSyncedHeartbeatComponents(monitor) + heartbeatComponents, err := simulatorHeartbeat.NewSyncedHeartbeatComponents(monitor) if err != nil { return err }