From 822c6303e0c91175eff0432ab9383c9eeb5f2a7a Mon Sep 17 00:00:00 2001 From: miiu Date: Thu, 16 May 2024 13:22:49 +0300 Subject: [PATCH 01/20] 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 d70921984e3..5c5d9004f04 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -273,6 +273,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 8b32a8655e3..d116313af96 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -148,6 +148,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 1aec0201e6c..4a60765db9c 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -503,6 +503,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 3334f470fa3..0bf2c1503d2 100644 --- a/node/chainSimulator/configs/configs.go +++ b/node/chainSimulator/configs/configs.go @@ -116,6 +116,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 2efd047f0c0dcba9babb35f6098f5b597d7add3c Mon Sep 17 00:00:00 2001 From: miiu Date: Thu, 16 May 2024 13:53:42 +0300 Subject: [PATCH 02/20] 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 d116313af96..81587662174 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -189,6 +189,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 5941378b2d8fc8d05b4705f818d044ed2d84ab3a Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 7 Jun 2024 14:33:40 +0300 Subject: [PATCH 03/20] fix unit test --- node/chainSimulator/chainSimulator_test.go | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index 81587662174..4758284d679 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -160,18 +160,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) From 3e057772a751da4f19407fa863c49366882ba3c5 Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 17 Jul 2024 11:27:18 +0300 Subject: [PATCH 04/20] extra parameter chain simulator --- node/chainSimulator/chainSimulator.go | 62 ++++++++++--------- node/chainSimulator/components/nodeFacade.go | 4 +- .../components/testOnlyProcessingNode.go | 21 ++++--- 3 files changed, 45 insertions(+), 42 deletions(-) diff --git a/node/chainSimulator/chainSimulator.go b/node/chainSimulator/chainSimulator.go index 5c5d9004f04..6fa4353bf84 100644 --- a/node/chainSimulator/chainSimulator.go +++ b/node/chainSimulator/chainSimulator.go @@ -40,22 +40,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 } type simulator struct { @@ -138,7 +139,7 @@ func (s *simulator) createChainHandlers(args ArgsChainSimulator) error { } allValidatorsInfo, errGet := node.GetProcessComponents().ValidatorsStatistics().GetValidatorInfoForRootHash(currentRootHash) - if errRootHash != nil { + if errGet != nil { return errGet } @@ -179,19 +180,20 @@ 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, + MinNodesMeta: args.MetaChainMinNodes, + 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 4a60765db9c..1c389f30c06 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -37,15 +37,16 @@ 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 + MinNodesMeta uint32 + RoundDurationInMillis uint64 + VmQueryDelayAfterStartInMs uint64 } type testOnlyProcessingNode struct { @@ -228,7 +229,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 2fd55c8cbe00866adcdc49108090b2a847bab99e Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 19 Jul 2024 16:07:58 +0300 Subject: [PATCH 05/20] 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 + node/chainSimulator/chainSimulator_test.go | 81 +++++++++++++++++++ .../components/processComponents.go | 3 +- .../components/whiteListDataVerifier.go | 46 +++++++++++ 8 files changed, 193 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 496db236d2c..2a89cf59fc5 100644 --- a/integrationTests/chainSimulator/staking/jail/jail_test.go +++ b/integrationTests/chainSimulator/staking/jail/jail_test.go @@ -98,6 +98,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 := staking.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) stakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txStake, staking.MaxNumOfBlockToGenerateWhenExecutingTx) @@ -202,6 +205,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 := staking.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, staking.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 9685ce78cc6..768577dbbf2 100644 --- a/integrationTests/chainSimulator/staking/stake/simpleStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go @@ -93,6 +93,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) @@ -200,6 +203,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 := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) diff --git a/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go b/integrationTests/chainSimulator/staking/stake/stakeAndUnStake_test.go index b3a1f1b7d4f..ed56e54b31b 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 := staking.GenerateTransaction(walletAddress.Bytes, 0, vm.ValidatorSCAddress, staking.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(staking.MinimumStakeValue) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) @@ -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(staking.MinimumStakeValue) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) @@ -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(staking.MinimumStakeValue) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) @@ -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(staking.OneEGLD, big.NewInt(2600)) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) @@ -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(staking.OneEGLD, big.NewInt(2600)) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) @@ -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(staking.OneEGLD, big.NewInt(2600)) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) @@ -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(staking.OneEGLD, big.NewInt(2600)) txDataField := fmt.Sprintf("stake@01@%s@%s", blsKeys[0], staking.MockBLSSignature) txStake := staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, stakeValue, txDataField, staking.GasLimitForStakeOperation) @@ -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 staking.GenerateTransaction(validatorOwner.Bytes, 0, vm.ValidatorSCAddress, staking.MinimumStakeValue, txDataField, staking.GasLimitForStakeOperation) } diff --git a/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go b/integrationTests/chainSimulator/staking/stakingProvider/delegation_test.go index da3950818b7..4ad2e85338e 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(staking.OneEGLD, big.NewInt(51000)) // 51000 EGLD cap txCreateDelegationContract := staking.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(staking.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(staking.MinimumStakeValue) addedStakedValue := big.NewInt(0).Mul(staking.OneEGLD, big.NewInt(100)) diff --git a/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go b/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go index 99cc7a66518..be468e5058f 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go @@ -73,6 +73,8 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati mintValue := big.NewInt(0).Mul(big.NewInt(5000), staking.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/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index 4758284d679..80240600501 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -2,7 +2,10 @@ package chainSimulator import ( "encoding/base64" + "encoding/hex" + "fmt" "math/big" + "strings" "testing" "time" @@ -10,10 +13,15 @@ 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-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/process" + "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" ) @@ -606,3 +614,76 @@ func generateTransaction(sender []byte, nonce uint64, receiver []byte, value *bi Signature: []byte(mockTxSignature), } } + +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 3bfd598f98d..4ee0d9150be 100644 --- a/node/chainSimulator/components/processComponents.go +++ b/node/chainSimulator/components/processComponents.go @@ -21,7 +21,6 @@ import ( "github.com/multiversx/mx-chain-go/genesis" "github.com/multiversx/mx-chain-go/genesis/parsing" "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" @@ -152,7 +151,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 a032c1471e1f1c617cb44e3f7b50219742abf2c9 Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 26 Jul 2024 10:56:01 +0300 Subject: [PATCH 06/20] small fix --- node/chainSimulator/chainSimulator_test.go | 4 +--- node/chainSimulator/components/processComponents.go | 7 +------ 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index 80240600501..c3aa08cd515 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -9,17 +9,15 @@ 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/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/process" "github.com/multiversx/mx-chain-go/node/external" + "github.com/multiversx/mx-chain-go/process" "github.com/multiversx/mx-chain-core-go/core" "github.com/stretchr/testify/assert" diff --git a/node/chainSimulator/components/processComponents.go b/node/chainSimulator/components/processComponents.go index 4ee0d9150be..56680a9c034 100644 --- a/node/chainSimulator/components/processComponents.go +++ b/node/chainSimulator/components/processComponents.go @@ -156,11 +156,6 @@ func CreateProcessComponents(args ArgsProcessComponentsHolder) (*processComponen return nil, err } - whiteListerVerifiedTxs, err := disabled.NewDisabledWhiteListDataVerifier() - if err != nil { - return nil, err - } - historyRepository, err := historyRepositoryFactory.Create() if err != nil { return nil, err @@ -195,7 +190,7 @@ func CreateProcessComponents(args ArgsProcessComponentsHolder) (*processComponen NodesCoordinator: args.NodesCoordinator, RequestedItemsHandler: requestedItemsHandler, WhiteListHandler: whiteListRequest, - WhiteListerVerifiedTxs: whiteListerVerifiedTxs, + WhiteListerVerifiedTxs: whiteListRequest, MaxRating: 50, SystemSCConfig: &args.SystemSCConfig, ImportStartHandler: importStartHandler, From ff4106d63e89420df4d730738fcb0607b82eb4e7 Mon Sep 17 00:00:00 2001 From: miiu Date: Thu, 25 Jul 2024 13:53:28 +0300 Subject: [PATCH 07/20] fixes --- .../components/processComponents.go | 8 +++- .../components/whiteListDataVerifier.go | 46 ------------------- 2 files changed, 7 insertions(+), 47 deletions(-) delete mode 100644 node/chainSimulator/components/whiteListDataVerifier.go diff --git a/node/chainSimulator/components/processComponents.go b/node/chainSimulator/components/processComponents.go index 56680a9c034..31c20782bb0 100644 --- a/node/chainSimulator/components/processComponents.go +++ b/node/chainSimulator/components/processComponents.go @@ -21,6 +21,7 @@ import ( "github.com/multiversx/mx-chain-go/genesis" "github.com/multiversx/mx-chain-go/genesis/parsing" "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" @@ -151,7 +152,12 @@ 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 + + } + whiteListRequest, err := interceptors.NewWhiteListDataVerifier(lruCache) if err != nil { return nil, err } 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 c93a39efa81fad2b795cdec4e6a8da46f628a82e Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 26 Jul 2024 11:11:16 +0300 Subject: [PATCH 08/20] 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 31c20782bb0..5f029d888ea 100644 --- a/node/chainSimulator/components/processComponents.go +++ b/node/chainSimulator/components/processComponents.go @@ -152,12 +152,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 } @@ -196,7 +206,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 85b07ce8002964f6ff21f434b21484fd63f5dcb0 Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 26 Jul 2024 11:41:49 +0300 Subject: [PATCH 09/20] fix test --- node/chainSimulator/chainSimulator_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index c3aa08cd515..f1d57363ea4 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -510,7 +510,7 @@ func TestSimulator_SendTransactions(t *testing.T) { Value: 20, } chainSimulator, err := NewChainSimulator(ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, @@ -545,6 +545,9 @@ func TestSimulator_SendTransactions(t *testing.T) { wallet4, err := chainSimulator.GenerateAndMintWalletAddress(2, initialMinting) 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) From b1b0145410e8e00a94412fda3e2378cceadd8f56 Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 26 Jul 2024 11:54:27 +0300 Subject: [PATCH 10/20] fix integration tests --- .../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 +- 5 files changed, 63 insertions(+), 63 deletions(-) diff --git a/integrationTests/chainSimulator/staking/jail/jail_test.go b/integrationTests/chainSimulator/staking/jail/jail_test.go index 2a89cf59fc5..0b46486a4fa 100644 --- a/integrationTests/chainSimulator/staking/jail/jail_test.go +++ b/integrationTests/chainSimulator/staking/jail/jail_test.go @@ -66,7 +66,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, @@ -169,7 +169,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 768577dbbf2..fe8c6183c69 100644 --- a/integrationTests/chainSimulator/staking/stake/simpleStake_test.go +++ b/integrationTests/chainSimulator/staking/stake/simpleStake_test.go @@ -65,7 +65,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, @@ -161,7 +161,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 ed56e54b31b..f0481a3ca4a 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, @@ -192,7 +192,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, @@ -324,7 +324,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, @@ -455,7 +455,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, @@ -485,7 +485,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, @@ -515,7 +515,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, @@ -545,7 +545,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, @@ -680,7 +680,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, @@ -711,7 +711,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, @@ -743,7 +743,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, @@ -775,7 +775,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, @@ -964,7 +964,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, @@ -995,7 +995,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, @@ -1027,7 +1027,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, @@ -1059,7 +1059,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, @@ -1204,7 +1204,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, @@ -1234,7 +1234,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, @@ -1264,7 +1264,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, @@ -1294,7 +1294,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, @@ -1441,7 +1441,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, @@ -1471,7 +1471,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, @@ -1501,7 +1501,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, @@ -1531,7 +1531,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, @@ -1707,7 +1707,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, @@ -1739,7 +1739,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, @@ -1771,7 +1771,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, @@ -1803,7 +1803,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, @@ -2066,7 +2066,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, @@ -2098,7 +2098,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, @@ -2130,7 +2130,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, @@ -2162,7 +2162,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, @@ -2362,7 +2362,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, @@ -2441,7 +2441,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 4ad2e85338e..df5b24241a9 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, @@ -490,7 +490,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, @@ -519,7 +519,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, @@ -548,7 +548,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, @@ -577,7 +577,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, @@ -718,7 +718,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, @@ -749,7 +749,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, @@ -781,7 +781,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, @@ -813,7 +813,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, @@ -1041,7 +1041,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, @@ -1080,7 +1080,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, @@ -1119,7 +1119,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, @@ -1158,7 +1158,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, @@ -1412,7 +1412,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, @@ -1453,7 +1453,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, @@ -1494,7 +1494,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, @@ -1535,7 +1535,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, @@ -1825,7 +1825,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, @@ -1856,7 +1856,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, @@ -1888,7 +1888,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, @@ -1920,7 +1920,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 be468e5058f..039010405b4 100644 --- a/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go +++ b/integrationTests/chainSimulator/staking/stakingProvider/stakingProviderWithNodesinQueue_test.go @@ -50,7 +50,7 @@ func testStakingProviderWithNodesReStakeUnStaked(t *testing.T, stakingV4Activati } cs, err := chainSimulator.NewChainSimulator(chainSimulator.ArgsChainSimulator{ - BypassTxSignatureCheck: false, + BypassTxSignatureCheck: true, TempDir: t.TempDir(), PathToInitialConfig: defaultPathToInitialConfig, NumOfShards: 3, From d503aa2a3913f8bb04f67f7fd77d73c37d1021fd Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 26 Jul 2024 12:11:45 +0300 Subject: [PATCH 11/20] fixes after review --- node/chainSimulator/chainSimulator_test.go | 45 ++++--------------- .../components/processComponents.go | 12 ++--- 2 files changed, 14 insertions(+), 43 deletions(-) diff --git a/node/chainSimulator/chainSimulator_test.go b/node/chainSimulator/chainSimulator_test.go index f1d57363ea4..ed3a84dd909 100644 --- a/node/chainSimulator/chainSimulator_test.go +++ b/node/chainSimulator/chainSimulator_test.go @@ -2,13 +2,12 @@ package chainSimulator import ( "encoding/base64" - "encoding/hex" - "fmt" "math/big" "strings" "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/config" @@ -16,10 +15,8 @@ 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/node/external" "github.com/multiversx/mx-chain-go/process" - "github.com/multiversx/mx-chain-core-go/core" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -647,44 +644,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", - } - - 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, + Signature: []byte("010101"), } - - 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 5f029d888ea..2d44ea70cbd 100644 --- a/node/chainSimulator/components/processComponents.go +++ b/node/chainSimulator/components/processComponents.go @@ -152,22 +152,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 } @@ -205,8 +205,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 c2f32513e024bd1064c719729e76207cb0a0340c Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 31 Jul 2024 11:56:38 +0300 Subject: [PATCH 12/20] 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 1c389f30c06..fa6105053be 100644 --- a/node/chainSimulator/components/testOnlyProcessingNode.go +++ b/node/chainSimulator/components/testOnlyProcessingNode.go @@ -148,6 +148,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 6879c30d24b305ca0a2f8254bb85dc48f12e3dc0 Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 5 Aug 2024 14:56:18 +0300 Subject: [PATCH 13/20] 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 ++ 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 +++ 14 files changed, 162 insertions(+), 5 deletions(-) diff --git a/api/errors/errors.go b/api/errors/errors.go index b01cec657ca..9e033d38e04 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 c2b47bf7a87..393875d8d6d 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 @@ -430,6 +445,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/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 404cc8eba8d..03c37f5ef0e 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" @@ -85,6 +86,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 13bdc9359085aca39e101b4df2c87f739eb9515e Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 5 Aug 2024 15:18:16 +0300 Subject: [PATCH 14/20] 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 02e48af112b355699dbe2b2c70197203257e2e64 Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 5 Aug 2024 15:24:58 +0300 Subject: [PATCH 15/20] 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 393875d8d6d..31020fd1899 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 72e8b30dc81292194acebb20c73d2448c2315e2c Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 6 Aug 2024 14:00:31 +0300 Subject: [PATCH 16/20] 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 1b47e0c1e045ebc22b36b7d7566c5315bf1a562a Mon Sep 17 00:00:00 2001 From: miiu Date: Tue, 6 Aug 2024 14:26:47 +0300 Subject: [PATCH 17/20] 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 f7d90c8f15b..449559b9dcb 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 f40e6a624af3656054f3cf3035c1310aa9eb201f Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 12 Aug 2024 15:07:57 +0300 Subject: [PATCH 18/20] 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 1f8f6bffbd4..c58c4262d68 100644 --- a/api/groups/transactionGroup_test.go +++ b/api/groups/transactionGroup_test.go @@ -342,6 +342,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() @@ -1122,6 +1192,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 03c37f5ef0e..399622565ae 100644 --- a/node/external/transactionAPI/apiTransactionProcessor.go +++ b/node/external/transactionAPI/apiTransactionProcessor.go @@ -86,6 +86,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 { @@ -98,7 +99,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 f179ee05ec066bd6e2ca6ae2225dadf7db085a29 Mon Sep 17 00:00:00 2001 From: Iulian Pascalau Date: Mon, 12 Aug 2024 23:03:12 +0300 Subject: [PATCH 19/20] - added synced transaction sender component --- node/chainSimulator/components/interface.go | 6 + .../components/processComponents.go | 25 +++ .../components/syncedTxsSender.go | 110 +++++++++ .../components/syncedTxsSender_test.go | 211 ++++++++++++++++++ 4 files changed, 352 insertions(+) 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 2d44ea70cbd..d141ce12d7e 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" @@ -285,6 +286,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 f3910c79643f276bc4fd0b6c2691a4fed637a7f0 Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 18 Oct 2024 14:47:40 +0300 Subject: [PATCH 20/20] increase the capacity and the size of the memory unit --- node/chainSimulator/components/memoryComponents.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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