From eb1c68f9b75b899fb588f8c59cf621b2fe35d541 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 22 Nov 2024 16:43:09 +0200 Subject: [PATCH] fix process-status for relayed v3 of type move balance --- process/testdata/relayedV3MoveBalanceOk.json | 91 ++++++++++++++++++++ process/transactionProcessor.go | 17 ++++ process/transactionProcessor_test.go | 42 +++++++++ 3 files changed, 150 insertions(+) create mode 100644 process/testdata/relayedV3MoveBalanceOk.json diff --git a/process/testdata/relayedV3MoveBalanceOk.json b/process/testdata/relayedV3MoveBalanceOk.json new file mode 100644 index 00000000..f06126c8 --- /dev/null +++ b/process/testdata/relayedV3MoveBalanceOk.json @@ -0,0 +1,91 @@ +{ + "transaction": { + "type": "normal", + "processingTypeOnSource": "RelayedTxV3", + "processingTypeOnDestination": "RelayedTxV3", + "hash": "9483ff1b8e83f6364da1903e750e3629a874e1370c0664a1c9fc1a823dec3fb3", + "nonce": 0, + "round": 4, + "epoch": 0, + "value": "1000000000000000000", + "receiver": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg", + "sender": "erd10vn8cuug0wx6anj84g7ukzlm06fullcjadetvmusqzv039x04f3supvc4v", + "gasPrice": 1000000000, + "gasLimit": 300000, + "gasUsed": 300000, + "signature": "0ba816dd7d6f9f5b05b3ef6f4ea46caf3d6869ebd890510b7801067dd5179fe4c6f5b128d7538eed0414cfd3380c54810709a984bd6d53ab56f71b7f91533206", + "sourceShard": 1, + "destinationShard": 1, + "blockNonce": 4, + "blockHash": "1eb5515921d9f53aa23d7f6d5ef088d4df335fb237e90a46b111c4f299fba0a7", + "notarizedAtSourceInMetaNonce": 6, + "NotarizedAtSourceInMetaHash": "b65de97cd422f5d1a14ede7ac16da42e0de979ad0818c91a57d423fed8cd37b8", + "notarizedAtDestinationInMetaNonce": 6, + "notarizedAtDestinationInMetaHash": "b65de97cd422f5d1a14ede7ac16da42e0de979ad0818c91a57d423fed8cd37b8", + "miniblockType": "TxBlock", + "miniblockHash": "3cba328024e2fa1f5be2aea6413b5f2b3f7d20ba426cc7cd0c5ff4df32968a38", + "hyperblockNonce": 6, + "hyperblockHash": "b65de97cd422f5d1a14ede7ac16da42e0de979ad0818c91a57d423fed8cd37b8", + "timestamp": 1732283756, + "smartContractResults": [ + { + "hash": "08f9e753dca6fff9237ef168912f8c6c407b9c8d2c0163a2d72b6ad7b5e7619b", + "nonce": 0, + "value": 1000000000000000000, + "receiver": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg", + "sender": "erd10vn8cuug0wx6anj84g7ukzlm06fullcjadetvmusqzv039x04f3supvc4v", + "relayerAddress": "erd15uchpdmkn90qxd9add6npnst3mckkapkq7zmn5l8rlkwnvk7k0ese9q8z5", + "relayedValue": 0, + "prevTxHash": "9483ff1b8e83f6364da1903e750e3629a874e1370c0664a1c9fc1a823dec3fb3", + "originalTxHash": "9483ff1b8e83f6364da1903e750e3629a874e1370c0664a1c9fc1a823dec3fb3", + "gasLimit": 200000, + "gasPrice": 1000000000, + "callType": 0, + "operation": "transfer" + } + ], + "status": "success", + "operation": "transfer", + "initiallyPaidFee": "300000000000000", + "fee": "300000000000000", + "isRelayed": true, + "relayerAddress": "erd15uchpdmkn90qxd9add6npnst3mckkapkq7zmn5l8rlkwnvk7k0ese9q8z5", + "relayerSignature": "62e1ed470dd07a7fe513cf9e93652bf8d27127d1a8fb12724dd45e2a7fcb3311071bc0f54856718fc07c42b11be7b357a5538c39864fa337f73cfa0ca2aed50e", + "chainID": "chain", + "version": 2, + "options": 0 + }, + "scrs": [ + { + "type": "unsigned", + "processingTypeOnSource": "MoveBalance", + "processingTypeOnDestination": "MoveBalance", + "hash": "08f9e753dca6fff9237ef168912f8c6c407b9c8d2c0163a2d72b6ad7b5e7619b", + "nonce": 0, + "round": 4, + "epoch": 0, + "value": "1000000000000000000", + "receiver": "erd1s89rm6mv6xyct38r3vqadj74rmqunamhwyz7c84a6u9thedj2wus5nlchg", + "sender": "erd10vn8cuug0wx6anj84g7ukzlm06fullcjadetvmusqzv039x04f3supvc4v", + "gasPrice": 1000000000, + "gasLimit": 200000, + "gasUsed": 50000, + "previousTransactionHash": "9483ff1b8e83f6364da1903e750e3629a874e1370c0664a1c9fc1a823dec3fb3", + "originalTransactionHash": "9483ff1b8e83f6364da1903e750e3629a874e1370c0664a1c9fc1a823dec3fb3", + "sourceShard": 1, + "destinationShard": 1, + "blockNonce": 4, + "blockHash": "1eb5515921d9f53aa23d7f6d5ef088d4df335fb237e90a46b111c4f299fba0a7", + "miniblockType": "SmartContractResultBlock", + "miniblockHash": "aada9d10986b36e44feb55aba48518172b53e320e40cae3c22b40964a0cd8aec", + "timestamp": 1732283756, + "status": "success", + "operation": "transfer", + "fee": "0", + "callType": "directCall", + "relayerAddress": "erd15uchpdmkn90qxd9add6npnst3mckkapkq7zmn5l8rlkwnvk7k0ese9q8z5", + "relayedValue": "0", + "options": 0 + } + ] +} diff --git a/process/transactionProcessor.go b/process/transactionProcessor.go index b91cf6c2..f0cdb19b 100644 --- a/process/transactionProcessor.go +++ b/process/transactionProcessor.go @@ -45,6 +45,7 @@ const ( moveBalanceDescriptor = "MoveBalance" relayedV1TransactionDescriptor = "RelayedTx" relayedV2TransactionDescriptor = "RelayedTxV2" + relayedV3TransactionDescriptor = "RelayedTxV3" emptyDataStr = "" ) @@ -511,6 +512,12 @@ func (tp *TransactionProcessor) computeTransactionStatus(tx *transaction.ApiTran } } + if checkIfRelayedV3Notarized(tx) { + return &data.ProcessStatusResponse{ + Status: string(tx.Status), + } + } + return &data.ProcessStatusResponse{ Status: string(transaction.TxStatusPending), } @@ -590,6 +597,16 @@ func checkIfMoveBalanceNotarized(tx *transaction.ApiTransactionResult) bool { return isMoveBalance } +func checkIfRelayedV3Notarized(tx *transaction.ApiTransactionResult) bool { + isNotarized := tx.NotarizedAtSourceInMetaNonce > 0 && tx.NotarizedAtDestinationInMetaNonce > 0 + if !isNotarized { + return false + } + isRelayedV3 := tx.ProcessingTypeOnSource == relayedV3TransactionDescriptor && tx.ProcessingTypeOnDestination == relayedV3TransactionDescriptor + + return isRelayedV3 +} + func (tp *TransactionProcessor) addMissingLogsOnProcessingExceptions( tx *transaction.ApiTransactionResult, allLogs []*transaction.ApiLogs, diff --git a/process/transactionProcessor_test.go b/process/transactionProcessor_test.go index aba0ceb1..57c2cda4 100644 --- a/process/transactionProcessor_test.go +++ b/process/transactionProcessor_test.go @@ -2151,3 +2151,45 @@ func TestCheckIfFailed(t *testing.T) { require.True(t, ok) require.True(t, strings.Contains(str, "storage decode error: input too short")) } + +func TestTransactionProcessor_GetProcessedStatusIntraShardRelayedV3WithMoveBalance(t *testing.T) { + txWithSCRs := loadJsonIntoTxAndScrs(t, "./testdata/relayedV3MoveBalanceOk.json") + + processorStub := &mock.ProcessorStub{ + GetShardIDsCalled: func() []uint32 { + return []uint32{1} // force everything intra-shard for test setup simplicity + }, + ComputeShardIdCalled: func(addressBuff []byte) (uint32, error) { + return 1, nil + }, + GetObserversCalled: func(shardId uint32, dataAvailability data.ObserverDataAvailabilityType) ([]*data.NodeData, error) { + return []*data.NodeData{ + { + Address: "test", + ShardId: 1, + }, + }, nil + }, + CallGetRestEndPointCalled: func(address string, path string, value interface{}) (int, error) { + valueC, ok := value.(*data.GetTransactionResponse) + if !ok { + return http.StatusOK, nil + } + valueC.Data.Transaction = *txWithSCRs.SCRs[0] + + return http.StatusOK, nil + }, + } + tp, _ := process.NewTransactionProcessor( + processorStub, + testPubkeyConverter, + hasher, + marshalizer, + funcNewTxCostHandler, + logsMerger, + false, + ) + + status := tp.ComputeTransactionStatus(txWithSCRs.Transaction, true) + require.Equal(t, string(transaction.TxStatusSuccess), status.Status) +}