From 80471cb56497b800f5addb981b6dbd2e51dbde42 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 9 Oct 2023 15:23:37 +0300 Subject: [PATCH 01/25] support for relayed v3 --- data/transaction.go | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/data/transaction.go b/data/transaction.go index b2ea4d10..975c6945 100644 --- a/data/transaction.go +++ b/data/transaction.go @@ -11,22 +11,24 @@ import ( // Transaction represents the structure that maps and validates user input for publishing a new transaction type Transaction struct { // This field is used to tag transactions for send-multiple route - Index int `json:"-"` - Nonce uint64 `json:"nonce"` - Value string `json:"value"` - Receiver string `json:"receiver"` - Sender string `json:"sender"` - SenderUsername []byte `json:"senderUsername,omitempty"` - ReceiverUsername []byte `json:"receiverUsername,omitempty"` - GasPrice uint64 `json:"gasPrice"` - GasLimit uint64 `json:"gasLimit"` - Data []byte `json:"data,omitempty"` - Signature string `json:"signature,omitempty"` - ChainID string `json:"chainID"` - Version uint32 `json:"version"` - Options uint32 `json:"options,omitempty"` - GuardianAddr string `json:"guardian,omitempty"` - GuardianSignature string `json:"guardianSignature,omitempty"` + Index int `json:"-"` + Nonce uint64 `json:"nonce"` + Value string `json:"value"` + Receiver string `json:"receiver"` + Sender string `json:"sender"` + SenderUsername []byte `json:"senderUsername,omitempty"` + ReceiverUsername []byte `json:"receiverUsername,omitempty"` + GasPrice uint64 `json:"gasPrice"` + GasLimit uint64 `json:"gasLimit"` + Data []byte `json:"data,omitempty"` + Signature string `json:"signature,omitempty"` + ChainID string `json:"chainID"` + Version uint32 `json:"version"` + Options uint32 `json:"options,omitempty"` + GuardianAddr string `json:"guardian,omitempty"` + GuardianSignature string `json:"guardianSignature,omitempty"` + Relayer string `json:"relayer,omitempty"` + InnerTransactions []*Transaction `json:"innerTransactions,omitempty"` } // GetTransactionResponseData follows the format of the data field of get transaction response From 627293e012eec314292284d935589ad59aba0fc1 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 27 Oct 2023 14:10:03 +0300 Subject: [PATCH 02/25] single inner tx --- data/transaction.go | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/data/transaction.go b/data/transaction.go index 975c6945..aa71295b 100644 --- a/data/transaction.go +++ b/data/transaction.go @@ -11,24 +11,24 @@ import ( // Transaction represents the structure that maps and validates user input for publishing a new transaction type Transaction struct { // This field is used to tag transactions for send-multiple route - Index int `json:"-"` - Nonce uint64 `json:"nonce"` - Value string `json:"value"` - Receiver string `json:"receiver"` - Sender string `json:"sender"` - SenderUsername []byte `json:"senderUsername,omitempty"` - ReceiverUsername []byte `json:"receiverUsername,omitempty"` - GasPrice uint64 `json:"gasPrice"` - GasLimit uint64 `json:"gasLimit"` - Data []byte `json:"data,omitempty"` - Signature string `json:"signature,omitempty"` - ChainID string `json:"chainID"` - Version uint32 `json:"version"` - Options uint32 `json:"options,omitempty"` - GuardianAddr string `json:"guardian,omitempty"` - GuardianSignature string `json:"guardianSignature,omitempty"` - Relayer string `json:"relayer,omitempty"` - InnerTransactions []*Transaction `json:"innerTransactions,omitempty"` + Index int `json:"-"` + Nonce uint64 `json:"nonce"` + Value string `json:"value"` + Receiver string `json:"receiver"` + Sender string `json:"sender"` + SenderUsername []byte `json:"senderUsername,omitempty"` + ReceiverUsername []byte `json:"receiverUsername,omitempty"` + GasPrice uint64 `json:"gasPrice"` + GasLimit uint64 `json:"gasLimit"` + Data []byte `json:"data,omitempty"` + Signature string `json:"signature,omitempty"` + ChainID string `json:"chainID"` + Version uint32 `json:"version"` + Options uint32 `json:"options,omitempty"` + GuardianAddr string `json:"guardian,omitempty"` + GuardianSignature string `json:"guardianSignature,omitempty"` + Relayer string `json:"relayer,omitempty"` + InnerTransaction *Transaction `json:"innerTransaction,omitempty"` } // GetTransactionResponseData follows the format of the data field of get transaction response From 990158ee9ea3386d04871555b81ddd70f66cab37 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 11 Mar 2024 20:53:55 +0200 Subject: [PATCH 03/25] added support for wild card in tx pool request by sender --- api/groups/baseTransactionGroup.go | 4 ++++ api/groups/baseTransactionGroup_test.go | 1 + 2 files changed, 5 insertions(+) diff --git a/api/groups/baseTransactionGroup.go b/api/groups/baseTransactionGroup.go index 59a64037..f73c68a4 100644 --- a/api/groups/baseTransactionGroup.go +++ b/api/groups/baseTransactionGroup.go @@ -337,6 +337,10 @@ func validateOptions(options common.TransactionsPoolOptions) error { return errors.ErrEmptySenderToGetNonceGaps } + if options.Fields == "*" { + return nil + } + if options.Fields != "" { return validateFields(options.Fields) } diff --git a/api/groups/baseTransactionGroup_test.go b/api/groups/baseTransactionGroup_test.go index f067abcd..fd4b9c82 100644 --- a/api/groups/baseTransactionGroup_test.go +++ b/api/groups/baseTransactionGroup_test.go @@ -561,6 +561,7 @@ func TestGetTransactionsPool_InvalidOptions(t *testing.T) { t.Run("empty sender when fetching nonce gaps", testInvalidParameters("?nonce-gaps=true", apiErrors.ErrEmptySenderToGetNonceGaps)) t.Run("invalid fields - numeric", testInvalidParameters("?fields=123", apiErrors.ErrInvalidFields)) t.Run("invalid characters on fields", testInvalidParameters("?fields=_/+", apiErrors.ErrInvalidFields)) + t.Run("fields + wild card", testInvalidParameters("?fields=nonce,sender,*", apiErrors.ErrInvalidFields)) } func testInvalidParameters(path string, expectedErr error) func(t *testing.T) { From 826a1ae88780ce7bbe7feae280eb239c1eec6d49 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 5 Apr 2024 09:56:53 +0300 Subject: [PATCH 04/25] multiple inner txs on relayed v3 --- data/transaction.go | 36 ++++++++++++++++++------------------ go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/data/transaction.go b/data/transaction.go index a54572b8..9173a883 100644 --- a/data/transaction.go +++ b/data/transaction.go @@ -11,24 +11,24 @@ import ( // Transaction represents the structure that maps and validates user input for publishing a new transaction type Transaction struct { // This field is used to tag transactions for send-multiple route - Index int `json:"-"` - Nonce uint64 `json:"nonce"` - Value string `json:"value"` - Receiver string `json:"receiver"` - Sender string `json:"sender"` - SenderUsername []byte `json:"senderUsername,omitempty"` - ReceiverUsername []byte `json:"receiverUsername,omitempty"` - GasPrice uint64 `json:"gasPrice"` - GasLimit uint64 `json:"gasLimit"` - Data []byte `json:"data,omitempty"` - Signature string `json:"signature,omitempty"` - ChainID string `json:"chainID"` - Version uint32 `json:"version"` - Options uint32 `json:"options,omitempty"` - GuardianAddr string `json:"guardian,omitempty"` - GuardianSignature string `json:"guardianSignature,omitempty"` - Relayer string `json:"relayer,omitempty"` - InnerTransaction *Transaction `json:"innerTransaction,omitempty"` + Index int `json:"-"` + Nonce uint64 `json:"nonce"` + Value string `json:"value"` + Receiver string `json:"receiver"` + Sender string `json:"sender"` + SenderUsername []byte `json:"senderUsername,omitempty"` + ReceiverUsername []byte `json:"receiverUsername,omitempty"` + GasPrice uint64 `json:"gasPrice"` + GasLimit uint64 `json:"gasLimit"` + Data []byte `json:"data,omitempty"` + Signature string `json:"signature,omitempty"` + ChainID string `json:"chainID"` + Version uint32 `json:"version"` + Options uint32 `json:"options,omitempty"` + GuardianAddr string `json:"guardian,omitempty"` + GuardianSignature string `json:"guardianSignature,omitempty"` + Relayer string `json:"relayer,omitempty"` + InnerTransactions []*Transaction `json:"innerTransactions,omitempty"` } // GetTransactionResponseData follows the format of the data field of get transaction response diff --git a/go.mod b/go.mod index fe449993..ab60d138 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/gin-contrib/pprof v1.4.0 github.com/gin-contrib/static v0.0.1 github.com/gin-gonic/gin v1.9.1 - github.com/multiversx/mx-chain-core-go v1.2.19-0.20231208083458-cdde72601592 + github.com/multiversx/mx-chain-core-go v1.2.20-0.20240404181342-48e2da52259e github.com/multiversx/mx-chain-crypto-go v1.2.9 github.com/multiversx/mx-chain-es-indexer-go v1.4.13 github.com/multiversx/mx-chain-logger-go v1.0.13 diff --git a/go.sum b/go.sum index 06e0a306..83a50dd5 100644 --- a/go.sum +++ b/go.sum @@ -131,8 +131,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20231208083458-cdde72601592 h1:fXpqfN64mLKvJycf5doOhvFRLM06eaMi7Ag3mO1fsbg= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20231208083458-cdde72601592/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.20-0.20240404181342-48e2da52259e h1:MseWlrUS8b8RhJ6JUqQBpYeYylmyoWqom+bvn3Cl/U4= +github.com/multiversx/mx-chain-core-go v1.2.20-0.20240404181342-48e2da52259e/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.9 h1:OEfF2kOQrtzUl273Z3DEcshjlTVUfPpJMd0R0SvTrlU= github.com/multiversx/mx-chain-crypto-go v1.2.9/go.mod h1:fkaWKp1rbQN9wPKya5jeoRyC+c/SyN/NfggreyeBw+8= github.com/multiversx/mx-chain-es-indexer-go v1.4.13 h1:3Ayaw9bSpeNOF+Z3L/11MN1rIJH8Rc6dqtt+o4Wfdno= From 6956918038e87603d616d98b59aca32428795c2b Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 9 May 2024 15:38:19 +0300 Subject: [PATCH 05/25] updated deps after merge --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index fe449993..b875aa32 100644 --- a/go.mod +++ b/go.mod @@ -8,10 +8,10 @@ require ( github.com/gin-contrib/pprof v1.4.0 github.com/gin-contrib/static v0.0.1 github.com/gin-gonic/gin v1.9.1 - github.com/multiversx/mx-chain-core-go v1.2.19-0.20231208083458-cdde72601592 - github.com/multiversx/mx-chain-crypto-go v1.2.9 - github.com/multiversx/mx-chain-es-indexer-go v1.4.13 - github.com/multiversx/mx-chain-logger-go v1.0.13 + github.com/multiversx/mx-chain-core-go v1.2.21-0.20240508071047-fefea5737840 + github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df + github.com/multiversx/mx-chain-es-indexer-go v1.7.1-0.20240509104512-25512675833d + github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.4 github.com/urfave/cli v1.22.10 diff --git a/go.sum b/go.sum index 06e0a306..e763f63d 100644 --- a/go.sum +++ b/go.sum @@ -131,14 +131,14 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20231208083458-cdde72601592 h1:fXpqfN64mLKvJycf5doOhvFRLM06eaMi7Ag3mO1fsbg= -github.com/multiversx/mx-chain-core-go v1.2.19-0.20231208083458-cdde72601592/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= -github.com/multiversx/mx-chain-crypto-go v1.2.9 h1:OEfF2kOQrtzUl273Z3DEcshjlTVUfPpJMd0R0SvTrlU= -github.com/multiversx/mx-chain-crypto-go v1.2.9/go.mod h1:fkaWKp1rbQN9wPKya5jeoRyC+c/SyN/NfggreyeBw+8= -github.com/multiversx/mx-chain-es-indexer-go v1.4.13 h1:3Ayaw9bSpeNOF+Z3L/11MN1rIJH8Rc6dqtt+o4Wfdno= -github.com/multiversx/mx-chain-es-indexer-go v1.4.13/go.mod h1:g0REyU8rqJfoBq6mIfqEi6IdpLofECLEvKKGMJO8ZhM= -github.com/multiversx/mx-chain-logger-go v1.0.13 h1:eru/TETo0MkO4ZTnXsQDKf4PBRpAXmqjT02klNT/JnY= -github.com/multiversx/mx-chain-logger-go v1.0.13/go.mod h1:MZJhTAtZTJxT+yK2EHc4ZW3YOHUc1UdjCD0iahRNBZk= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240508071047-fefea5737840 h1:2mCrTUmbbA+Xv4UifZY9xptrGjcJBcJ2wavSb4FwejU= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240508071047-fefea5737840/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df h1:clihfi78bMEOWk/qw6WA4uQbCM2e2NGliqswLAvw19k= +github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df/go.mod h1:gtJYB4rR21KBSqJlazn+2z6f9gFSqQP3KvAgL7Qgxw4= +github.com/multiversx/mx-chain-es-indexer-go v1.7.1-0.20240509104512-25512675833d h1:GD1D8V0bE6hDLjrduSsMwQwwf6PMq2Zww7FYMfJsuiw= +github.com/multiversx/mx-chain-es-indexer-go v1.7.1-0.20240509104512-25512675833d/go.mod h1:UDKRXmxsSyPeAcjLUfGeYkAtYp424PIYkL82kzFYobM= +github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 h1:g9t410dqjcb7UUptbVd/H6Ua12sEzWU4v7VplyNvRZ0= +github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57/go.mod h1:cY6CIXpndW5g5PTPn4WzPwka/UBEf+mgw+PSY5pHGAU= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= From fbe7165d56b0d70d7cb06479a564e463fe314680 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 28 May 2024 16:28:11 +0300 Subject: [PATCH 06/25] updated core-go + process-status support for v3 --- go.mod | 2 +- go.sum | 4 ++-- process/transactionProcessor.go | 36 +++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index ab60d138..a16300f3 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/gin-contrib/pprof v1.4.0 github.com/gin-contrib/static v0.0.1 github.com/gin-gonic/gin v1.9.1 - github.com/multiversx/mx-chain-core-go v1.2.20-0.20240404181342-48e2da52259e + github.com/multiversx/mx-chain-core-go v1.2.21-0.20240528132712-8b6faa711b23 github.com/multiversx/mx-chain-crypto-go v1.2.9 github.com/multiversx/mx-chain-es-indexer-go v1.4.13 github.com/multiversx/mx-chain-logger-go v1.0.13 diff --git a/go.sum b/go.sum index 83a50dd5..fcf85897 100644 --- a/go.sum +++ b/go.sum @@ -131,8 +131,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/multiversx/mx-chain-core-go v1.2.20-0.20240404181342-48e2da52259e h1:MseWlrUS8b8RhJ6JUqQBpYeYylmyoWqom+bvn3Cl/U4= -github.com/multiversx/mx-chain-core-go v1.2.20-0.20240404181342-48e2da52259e/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240528132712-8b6faa711b23 h1:jSP8BjMF9P5I9cO5hY2uN60q4+iPP9uq5WzETtcXWMI= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240528132712-8b6faa711b23/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.9 h1:OEfF2kOQrtzUl273Z3DEcshjlTVUfPpJMd0R0SvTrlU= github.com/multiversx/mx-chain-crypto-go v1.2.9/go.mod h1:fkaWKp1rbQN9wPKya5jeoRyC+c/SyN/NfggreyeBw+8= github.com/multiversx/mx-chain-es-indexer-go v1.4.13 h1:3Ayaw9bSpeNOF+Z3L/11MN1rIJH8Rc6dqtt+o4Wfdno= diff --git a/process/transactionProcessor.go b/process/transactionProcessor.go index 05cae2b5..b3ce2860 100644 --- a/process/transactionProcessor.go +++ b/process/transactionProcessor.go @@ -487,6 +487,13 @@ func (tp *TransactionProcessor) computeTransactionStatus(tx *transaction.ApiTran } } + isRelayedV3, status := checkIfRelayedV3Completed(allLogs, tx) + if isRelayedV3 { + return &data.ProcessStatusResponse{ + Status: status, + } + } + if checkIfCompleted(allLogs) { return &data.ProcessStatusResponse{ Status: string(transaction.TxStatusSuccess), @@ -522,6 +529,35 @@ func checkIfCompleted(logs []*transaction.ApiLogs) bool { return found } +func checkIfRelayedV3Completed(logs []*transaction.ApiLogs, tx *transaction.ApiTransactionResult) (bool, string) { + if len(tx.InnerTransactions) == 0 { + return false, string(transaction.TxStatusPending) + } + + if len(logs) == 0 { + return true, string(transaction.TxStatusPending) + } + + completedCnt := 0 + for _, logInstance := range logs { + if logInstance == nil { + continue + } + + completedFound, _ := findIdentifierInSingleLog(logInstance, core.CompletedTxEventIdentifier) + deployFound, _ := findIdentifierInSingleLog(logInstance, core.SCDeployIdentifier) + if completedFound || deployFound { + completedCnt++ + } + } + + status := string(transaction.TxStatusFail) + if completedCnt == len(tx.InnerTransactions) { + status = string(transaction.TxStatusSuccess) + } + return true, status +} + func checkIfMoveBalanceNotarized(tx *transaction.ApiTransactionResult) bool { isNotarized := tx.NotarizedAtSourceInMetaNonce > 0 && tx.NotarizedAtDestinationInMetaNonce > 0 if !isNotarized { From 79e98bc14749890f8a395ea47704ed2db85ae58a Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 28 May 2024 17:41:45 +0300 Subject: [PATCH 07/25] fixed process-status on relayed v1 with move balance --- ...ishedOkRelayedTxCrossShardMoveBalance.json | 101 +++++++++++++++ process/transactionProcessor.go | 84 +------------ process/transactionProcessor_test.go | 119 ++---------------- 3 files changed, 114 insertions(+), 190 deletions(-) create mode 100644 process/testdata/finishedOkRelayedTxCrossShardMoveBalance.json diff --git a/process/testdata/finishedOkRelayedTxCrossShardMoveBalance.json b/process/testdata/finishedOkRelayedTxCrossShardMoveBalance.json new file mode 100644 index 00000000..0e73e09e --- /dev/null +++ b/process/testdata/finishedOkRelayedTxCrossShardMoveBalance.json @@ -0,0 +1,101 @@ +{ + "transaction": { + "type": "normal", + "processingTypeOnSource": "RelayedTx", + "processingTypeOnDestination": "RelayedTx", + "hash": "4dd5faec9431b8111e96ac01e592b66be50a1454eb2d008ce941323d49715ca9", + "nonce": 159, + "round": 17813271, + "epoch": 1236, + "value": "0", + "receiver": "erd13mfn9qksaq03c0nltpg23lqca67lhup544a56z0j4vlrhgu90lxq7hpjgw", + "sender": "erd16mpvgjpfgj8fd8h2stw9zxqx2n0prmmqsan02ash93jdrp6m7fqswke499", + "gasPrice": 1000000000, + "gasLimit": 1084000, + "gasUsed": 1084000, + "data": "cmVsYXllZFR4QDdiMjI2ZTZmNmU2MzY1MjIzYTMwMmMyMjc2NjE2Yzc1NjUyMjNhMzMzMzM3MzQzMDMwMzAzMDMwMzAzMDMwMzAzMDMwMzAzMDMwMmMyMjcyNjU2MzY1Njk3NjY1NzIyMjNhMjIzMTczNGM0NTUzNDM2YzQ1NmE3MDYxNjUzNjZmNGM2MzU1NTI2NzQ3NTY0ZTM0NTIzNzMyNDM0ODVhNzY1NjMyNDY3OTc4NmIzMDU5NjQ2MjM4NmI0NTNkMjIyYzIyNzM2NTZlNjQ2NTcyMjIzYTIyNmE3NDRkNzk2Nzc0NDQ2ZjQ4Nzg3NzJiNjYzMTY4NTE3MTUwNzc1OTM3NzIzMzM3Mzg0NDUzNzQ2NTMwMzA0YTM4NzE3MzJiNGYzNjRmNDY2NjM4NzczZDIyMmMyMjY3NjE3MzUwNzI2OTYzNjUyMjNhMzEzMDMwMzAzMDMwMzAzMDMwMzAyYzIyNjc2MTczNGM2OTZkNjk3NDIyM2EzNTMwMzAzMDMwMmMyMjYzNjg2MTY5NmU0OTQ0MjIzYTIyNGQ1MTNkM2QyMjJjMjI3NjY1NzI3MzY5NmY2ZTIyM2EzMTJjMjI3MzY5Njc2ZTYxNzQ3NTcyNjUyMjNhMjI2OTcwNjU2YzY2NWE0ODc1NDE0NTMzMzI2ZTcxMzAyZjU2NDc0ZDZhNjYzNzRhNTQ1NTQ1NTA1NTc3NjQzMjQ4NTA0ZjY1MzU2ZTZhNDMzMDM2MmI0MjcwMzAzMzZiMzAzODZlNTA2YTMxNjMzOTM3NTE1MTQzNzI1OTQ4Nzc1MzQ0NTU1YTZiNDg1MzY1NDk3MTczMmY3YTMyNTE1NTRkNGU2ZTQxNDc0MTQxM2QzZDIyN2Q=", + "signature": "b0a477a7db6820ccd99291e92a7f8f32f3901e54eec99cf143ae7151a51bfbc219853069d4ad515ee5179175937d673efd4549a53ed30f00beb07f3ead68b00c", + "sourceShard": 1, + "destinationShard": 0, + "blockNonce": 17806968, + "blockHash": "52a92fd2b486cf0710e646bc0e91da429d617e47a1f34380c0f890e3f218a072", + "notarizedAtSourceInMetaNonce": 17792304, + "NotarizedAtSourceInMetaHash": "4e82f772d8415d23934693c787a08e75862841a8116682f66c8739f32afb5033", + "notarizedAtDestinationInMetaNonce": 17792308, + "notarizedAtDestinationInMetaHash": "7baa2ddbc7200d0cb20bb445eb9d80f946b5daf7a24a7c6069038d97fd7354e2", + "miniblockType": "TxBlock", + "miniblockHash": "53a543f844b67bea604d5ca90b3c363bb60ae09ec54451fff115ecadcdb946f3", + "hyperblockNonce": 17792308, + "hyperblockHash": "7baa2ddbc7200d0cb20bb445eb9d80f946b5daf7a24a7c6069038d97fd7354e2", + "timestamp": 1702997226, + "smartContractResults": [ + { + "hash": "8cc84367ffe898d922c82d23e7557c4b735c4ef1e93e563a1dfa36839bdfdaa4", + "nonce": 0, + "value": 337400000000000000, + "receiver": "erd16mpvgjpfgj8fd8h2stw9zxqx2n0prmmqsan02ash93jdrp6m7fqswke499", + "sender": "erd13mfn9qksaq03c0nltpg23lqca67lhup544a56z0j4vlrhgu90lxq7hpjgw", + "relayerAddress": "erd16mpvgjpfgj8fd8h2stw9zxqx2n0prmmqsan02ash93jdrp6m7fqswke499", + "relayedValue": 0, + "prevTxHash": "4dd5faec9431b8111e96ac01e592b66be50a1454eb2d008ce941323d49715ca9", + "originalTxHash": "4dd5faec9431b8111e96ac01e592b66be50a1454eb2d008ce941323d49715ca9", + "gasLimit": 0, + "gasPrice": 1000000000, + "callType": 0, + "operation": "transfer" + } + ], + "status": "success", + "receivers": [ + "erd16mpvgjpfgj8fd8h2stw9zxqx2n0prmmqsan02ash93jdrp6m7fqswke499" + ], + "receiversShardIDs": [ + 1 + ], + "operation": "transfer", + "initiallyPaidFee": "1034500000000000", + "fee": "1034500000000000", + "isRelayed": true, + "chainID": "1", + "version": 1, + "options": 0 + }, + "scrs": [ + { + "type": "unsigned", + "processingTypeOnSource": "MoveBalance", + "processingTypeOnDestination": "MoveBalance", + "hash": "8cc84367ffe898d922c82d23e7557c4b735c4ef1e93e563a1dfa36839bdfdaa4", + "nonce": 0, + "round": 17813275, + "epoch": 1236, + "value": "337400000000000000", + "receiver": "erd16mpvgjpfgj8fd8h2stw9zxqx2n0prmmqsan02ash93jdrp6m7fqswke499", + "sender": "erd13mfn9qksaq03c0nltpg23lqca67lhup544a56z0j4vlrhgu90lxq7hpjgw", + "gasPrice": 1000000000, + "gasUsed": 50000, + "previousTransactionHash": "4dd5faec9431b8111e96ac01e592b66be50a1454eb2d008ce941323d49715ca9", + "originalTransactionHash": "4dd5faec9431b8111e96ac01e592b66be50a1454eb2d008ce941323d49715ca9", + "sourceShard": 0, + "destinationShard": 1, + "blockNonce": 17800066, + "blockHash": "cdeff6a0d8da1eae1de2a434b4834ee23bea45c64d43e3f303b3b862fdc5028b", + "notarizedAtSourceInMetaNonce": 17792308, + "NotarizedAtSourceInMetaHash": "7baa2ddbc7200d0cb20bb445eb9d80f946b5daf7a24a7c6069038d97fd7354e2", + "notarizedAtDestinationInMetaNonce": 17792312, + "notarizedAtDestinationInMetaHash": "0316c2b4a03ad3172ce3ce975447cace67d30b5002b1e00d40ca44dd43768219", + "miniblockType": "SmartContractResultBlock", + "miniblockHash": "daa45fb36173df935d0786c43afe4085e8a9a20b53aab3b602bd8d8ec3cd1880", + "hyperblockNonce": 17792312, + "hyperblockHash": "0316c2b4a03ad3172ce3ce975447cace67d30b5002b1e00d40ca44dd43768219", + "timestamp": 1702997250, + "status": "success", + "operation": "transfer", + "fee": "0", + "callType": "directCall", + "relayerAddress": "erd16mpvgjpfgj8fd8h2stw9zxqx2n0prmmqsan02ash93jdrp6m7fqswke499", + "relayedValue": "0", + "options": 0 + } + ] +} diff --git a/process/transactionProcessor.go b/process/transactionProcessor.go index 05cae2b5..40cde1f1 100644 --- a/process/transactionProcessor.go +++ b/process/transactionProcessor.go @@ -5,7 +5,6 @@ import ( "fmt" "math/big" "net/http" - "strings" "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" @@ -552,12 +551,12 @@ func (tp *TransactionProcessor) handleIntraShardRelayedMoveBalanceTransactions( allScrs []*transaction.ApiTransactionResult, ) ([]*transaction.ApiLogs, error) { var newLogs []*transaction.ApiLogs - isIntraShardRelayedV1MoveBalanceTransaction, err := tp.isIntraShardRelayedMoveBalanceTransaction(tx, allScrs) + isRelayedMoveBalanceTransaction, err := tp.isRelayedMoveBalanceTransaction(tx, allScrs) if err != nil { return newLogs, err } - if isIntraShardRelayedV1MoveBalanceTransaction { + if isRelayedMoveBalanceTransaction { newLogs = append(newLogs, &transaction.ApiLogs{ Address: tx.Sender, Events: []*transaction.Events{ @@ -572,7 +571,7 @@ func (tp *TransactionProcessor) handleIntraShardRelayedMoveBalanceTransactions( return newLogs, nil } -func (tp *TransactionProcessor) isIntraShardRelayedMoveBalanceTransaction( +func (tp *TransactionProcessor) isRelayedMoveBalanceTransaction( tx *transaction.ApiTransactionResult, allScrs []*transaction.ApiTransactionResult, ) (bool, error) { @@ -595,83 +594,8 @@ func (tp *TransactionProcessor) isIntraShardRelayedMoveBalanceTransaction( firstScr := allScrs[0] innerIsMoveBalance := firstScr.ProcessingTypeOnSource == moveBalanceDescriptor && firstScr.ProcessingTypeOnDestination == moveBalanceDescriptor - if !innerIsMoveBalance { - return false, nil - } - - senderAddress, err := tp.pubKeyConverter.Decode(tx.Sender) - if err != nil { - return false, err - } - receiverAddress, err := tp.pubKeyConverter.Decode(tx.Receiver) - if err != nil { - return false, err - } - - isSameShardOnRelayed := tp.proc.GetShardCoordinator().SameShard(senderAddress, receiverAddress) - isInnerTxSameShard, err := tp.isSameShardSenderReceiverOfInnerTx(senderAddress, tx) - - return isSameShardOnRelayed && isInnerTxSameShard, err -} - -func (tp *TransactionProcessor) isSameShardSenderReceiverOfInnerTx( - relayedSender []byte, - relayedTx *transaction.ApiTransactionResult, -) (bool, error) { - if relayedTx.ProcessingTypeOnSource == relayedV1TransactionDescriptor { - return tp.isSameShardSenderReceiverOfInnerTxV1(relayedSender, relayedTx) - } - - return tp.isSameShardSenderReceiverOfInnerTxV2(relayedSender, relayedTx) -} - -func (tp *TransactionProcessor) isSameShardSenderReceiverOfInnerTxV1( - relayedSender []byte, - relayedTx *transaction.ApiTransactionResult, -) (bool, error) { - relayedDataField := string(relayedTx.Data) - if strings.Index(relayedDataField, relayedTxV1DataMarker) != 0 { - return false, fmt.Errorf("wrong relayed v1 data marker position") - } - - hexedInnerTxData := relayedDataField[len(relayedTxV1DataMarker):] - innerTxData, err := hex.DecodeString(hexedInnerTxData) - if err != nil { - return false, err - } - - innerTx := &transaction.Transaction{} - err = tp.relayedTxsMarshaller.Unmarshal(innerTx, innerTxData) - if err != nil { - return false, err - } - - isSameShardOnInnerForReceiver := tp.proc.GetShardCoordinator().SameShard(relayedSender, innerTx.RcvAddr) - isSameShardOnInnerForSender := tp.proc.GetShardCoordinator().SameShard(relayedSender, innerTx.SndAddr) - - return isSameShardOnInnerForReceiver && isSameShardOnInnerForSender, nil -} - -func (tp *TransactionProcessor) isSameShardSenderReceiverOfInnerTxV2( - relayedSender []byte, - relayedTx *transaction.ApiTransactionResult, -) (bool, error) { - relayedDataField := string(relayedTx.Data) - if strings.Index(relayedDataField, relayedTxV2DataMarker) != 0 { - return false, fmt.Errorf("wrong relayed v2 data marker position") - } - arguments := strings.Split(relayedDataField, argumentsSeparator) - if len(arguments) < 2 { - return false, fmt.Errorf("wrong relayed v2 formatted data field") - } - - hexedReceiver := arguments[1] - receiver, err := hex.DecodeString(hexedReceiver) - if err != nil { - return false, err - } - return tp.proc.GetShardCoordinator().SameShard(relayedSender, receiver), nil + return innerIsMoveBalance, nil } func findIdentifierInLogs(logs []*transaction.ApiLogs, identifier string) (bool, string) { diff --git a/process/transactionProcessor_test.go b/process/transactionProcessor_test.go index c1329261..0fa9b76f 100644 --- a/process/transactionProcessor_test.go +++ b/process/transactionProcessor_test.go @@ -1961,6 +1961,15 @@ func TestTransactionProcessor_computeTransactionStatus(t *testing.T) { testData := loadJsonIntoTxAndScrs(t, "./testdata/finishedOKRelayedTxWithSCCall.json") tp := createTestProcessorFromScenarioData(testData) + status := tp.ComputeTransactionStatus(testData.Transaction, withResults) + require.Equal(t, string(transaction.TxStatusSuccess), status.Status) + }) + t.Run("tx move balance cross ok", func(t *testing.T) { + t.Parallel() + + testData := loadJsonIntoTxAndScrs(t, "./testdata/finishedOkRelayedTxCrossShardMoveBalance.json") + tp := createTestProcessorFromScenarioData(testData) + status := tp.ComputeTransactionStatus(testData.Transaction, withResults) require.Equal(t, string(transaction.TxStatusSuccess), status.Status) }) @@ -1983,116 +1992,6 @@ func TestTransactionProcessor_computeTransactionStatus(t *testing.T) { status := tp.ComputeTransactionStatus(testData.Transaction, withResults) require.Equal(t, string(transaction.TxStatusFail), status.Status) }) - t.Run("malformed transactions", func(t *testing.T) { - t.Parallel() - - t.Run("malformed relayed v1 inner transaction - wrong sender", func(t *testing.T) { - t.Parallel() - - testData := loadJsonIntoTxAndScrs(t, "./testdata/finishedOKRelayedTxIntraShard.json") - tp := createTestProcessorFromScenarioData(testData) - - testData.Transaction.Sender = "not a sender" - - status := tp.ComputeTransactionStatus(testData.Transaction, withResults) - require.Equal(t, string(data.TxStatusUnknown), status.Status) - }) - t.Run("malformed relayed v1 inner transaction - wrong receiver", func(t *testing.T) { - t.Parallel() - - testData := loadJsonIntoTxAndScrs(t, "./testdata/finishedOKRelayedTxIntraShard.json") - tp := createTestProcessorFromScenarioData(testData) - - testData.Transaction.Receiver = "not a sender" - - status := tp.ComputeTransactionStatus(testData.Transaction, withResults) - require.Equal(t, string(data.TxStatusUnknown), status.Status) - }) - t.Run("malformed relayed v1 - relayed v1 marker on wrong position", func(t *testing.T) { - t.Parallel() - - testData := loadJsonIntoTxAndScrs(t, "./testdata/finishedOKRelayedTxIntraShard.json") - tp := createTestProcessorFromScenarioData(testData) - - testData.Transaction.Data = append([]byte("A"), testData.Transaction.Data...) - - status := tp.ComputeTransactionStatus(testData.Transaction, withResults) - require.Equal(t, string(data.TxStatusUnknown), status.Status) - }) - t.Run("malformed relayed v2 - missing marker", func(t *testing.T) { - t.Parallel() - - testData := loadJsonIntoTxAndScrs(t, "./testdata/finishedOKRelayedV2TxIntraShard.json") - tp := createTestProcessorFromScenarioData(testData) - - testData.Transaction.Data = []byte("aa") - - status := tp.ComputeTransactionStatus(testData.Transaction, withResults) - require.Equal(t, string(data.TxStatusUnknown), status.Status) - }) - t.Run("malformed relayed v2 - not enough arguments", func(t *testing.T) { - t.Parallel() - - testData := loadJsonIntoTxAndScrs(t, "./testdata/finishedOKRelayedV2TxIntraShard.json") - tp := createTestProcessorFromScenarioData(testData) - - testData.Transaction.Data = []byte(process.RelayedTxV2DataMarker) - - status := tp.ComputeTransactionStatus(testData.Transaction, withResults) - require.Equal(t, string(data.TxStatusUnknown), status.Status) - }) - t.Run("malformed relayed v1 - not a hex character after the marker", func(t *testing.T) { - t.Parallel() - - testData := loadJsonIntoTxAndScrs(t, "./testdata/finishedOKRelayedTxIntraShard.json") - tp := createTestProcessorFromScenarioData(testData) - - testData.Transaction.Data[45] = byte('T') - - status := tp.ComputeTransactionStatus(testData.Transaction, withResults) - require.Equal(t, string(data.TxStatusUnknown), status.Status) - }) - t.Run("malformed relayed v1 - marshaller will fail", func(t *testing.T) { - t.Parallel() - - testData := loadJsonIntoTxAndScrs(t, "./testdata/finishedOKRelayedTxIntraShard.json") - tp := createTestProcessorFromScenarioData(testData) - - testData.Transaction.Data = append(testData.Transaction.Data, []byte("aaaaaa")...) - - status := tp.ComputeTransactionStatus(testData.Transaction, withResults) - require.Equal(t, string(data.TxStatusUnknown), status.Status) - }) - t.Run("malformed relayed v1 - missing scrs", func(t *testing.T) { - t.Parallel() - - testData := loadJsonIntoTxAndScrs(t, "./testdata/finishedOKRelayedTxIntraShard.json") - tp := createTestProcessorFromScenarioData(testData) - - testData.SCRs = nil - - status := tp.ComputeTransactionStatus(testData.Transaction, withResults) - require.Equal(t, string(data.TxStatusUnknown), status.Status) - }) - t.Run("malformed relayed v1 - no scr generated", func(t *testing.T) { - t.Parallel() - - testData := loadJsonIntoTxAndScrs(t, "./testdata/malformedRelayedTxIntraShard.json") - tp := createTestProcessorFromScenarioData(testData) - - status := tp.ComputeTransactionStatus(testData.Transaction, withResults) - require.Equal(t, string(data.TxStatusUnknown), status.Status) - }) - t.Run("malformed relayed v2 - no scr generated", func(t *testing.T) { - t.Parallel() - - testData := loadJsonIntoTxAndScrs(t, "./testdata/malformedRelayedV2TxIntraShard.json") - tp := createTestProcessorFromScenarioData(testData) - - status := tp.ComputeTransactionStatus(testData.Transaction, withResults) - require.Equal(t, string(data.TxStatusUnknown), status.Status) - }) - }) } func TestTransactionProcessor_GetProcessedTransactionStatus(t *testing.T) { From 3f9f7fc91fdcd4e1f09fb9a346538024781017bb Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 29 May 2024 20:01:39 +0300 Subject: [PATCH 08/25] merged logs from destination on relayed tx v3 get transaction --- process/transactionProcessor.go | 64 +++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/process/transactionProcessor.go b/process/transactionProcessor.go index b3ce2860..399934f5 100644 --- a/process/transactionProcessor.go +++ b/process/transactionProcessor.go @@ -42,6 +42,7 @@ const ( moveBalanceDescriptor = "MoveBalance" relayedV1TransactionDescriptor = "RelayedTx" relayedV2TransactionDescriptor = "RelayedTxV2" + relayedV3TransactionDescriptor = "RelayedTxV3" relayedTxV1DataMarker = "relayedTx@" relayedTxV2DataMarker = "relayedTxV2" argumentsSeparator = "@" @@ -793,8 +794,13 @@ func (tp *TransactionProcessor) getTxFromObservers(txHash string, reqType reques "error", err.Error()) } + if isRelayedTxV3(getTxResponse.Data.Transaction) { + return tp.mergeSCRLogsFromInnerReceivers(&getTxResponse.Data.Transaction, withResults), nil + } + isIntraShard := sndShardID == rcvShardID observerIsInDestShard := rcvShardID == observerShardID + if isIntraShard { return &getTxResponse.Data.Transaction, nil } @@ -820,6 +826,64 @@ func (tp *TransactionProcessor) getTxFromObservers(txHash string, reqType reques return nil, errors.ErrTransactionNotFound } +func isRelayedTxV3(tx transaction.ApiTransactionResult) bool { + return tx.ProcessingTypeOnSource == relayedV3TransactionDescriptor && tx.ProcessingTypeOnDestination == relayedV3TransactionDescriptor +} + +func (tp *TransactionProcessor) mergeSCRLogsFromInnerReceivers(tx *transaction.ApiTransactionResult, withResults bool) *transaction.ApiTransactionResult { + logsOnDestMap := make(map[string]*transaction.ApiLogs, len(tx.SmartContractResults)) + + txsByReceiverShardMap := tp.groupTxsByReceiverShard(tx) + for shardID, scrHashes := range txsByReceiverShardMap { + for _, scrHash := range scrHashes { + observers, err := tp.getNodesInShard(shardID, requestTypeObservers) + if err != nil { + break + } + + for _, observer := range observers { + getTxResponse, ok, _ := tp.getTxFromObserver(observer, scrHash, withResults) + if !ok { + continue + } + + if withResults { + logsOnDestMap[scrHash] = getTxResponse.Data.Transaction.Logs + } + } + } + } + + finalTx := *tx + // if withResults, override the scr logs with the one from the receiver shard + if withResults { + for _, scr := range finalTx.SmartContractResults { + logsOnDest, found := logsOnDestMap[scr.Hash] + if !found { + continue + } + + scr.Logs = logsOnDest + } + } + + return &finalTx +} + +func (tp *TransactionProcessor) groupTxsByReceiverShard(tx *transaction.ApiTransactionResult) map[uint32][]string { + txsByReceiverShardMap := make(map[uint32][]string) + for _, scr := range tx.SmartContractResults { + shardID, err := tp.getShardByAddress(scr.RcvAddr) + if err != nil { + continue + } + + txsByReceiverShardMap[shardID] = append(txsByReceiverShardMap[shardID], scr.Hash) + } + + return txsByReceiverShardMap +} + func (tp *TransactionProcessor) alterTxWithScResultsFromSourceIfNeeded(txHash string, tx *transaction.ApiTransactionResult, withResults bool) *transaction.ApiTransactionResult { if !withResults || len(tx.SmartContractResults) == 0 { return tx From f2a02806edf1318dd08e602b406c1df0c751832a Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 30 May 2024 13:13:30 +0300 Subject: [PATCH 09/25] added unittest for relayed v3 merge of scr events --- process/transactionProcessor_test.go | 125 +++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/process/transactionProcessor_test.go b/process/transactionProcessor_test.go index c1329261..d822e8ea 100644 --- a/process/transactionProcessor_test.go +++ b/process/transactionProcessor_test.go @@ -1312,6 +1312,131 @@ func TestTransactionProcessor_GetTransactionWithEventsFirstFromDstShardAndAfterS assert.Equal(t, 3, len(tx.SmartContractResults)) } +func TestTransactionProcessor_GetTransactionRelayedV3ShouldMergeEvents(t *testing.T) { + t.Parallel() + + relayer := hex.EncodeToString([]byte("relayer")) + sender1 := hex.EncodeToString([]byte("sender1")) + sender2 := hex.EncodeToString([]byte("sender2")) + receiver1 := hex.EncodeToString([]byte("receiver1")) + receiver2 := hex.EncodeToString([]byte("receiver2")) + + addrObs0 := "observer0" + addrObsFailing := "observerFailing" + addrObs1 := "observer1" + + hashRelayed := "hashRelayed" + + scrHash1 := "scrHash1" + providedLogsInnerTx1 := &transaction.ApiLogs{ + Events: []*transaction.Events{ + { + Address: receiver1, + Identifier: "events innertx 1", + }, + }, + } + + scrHash2 := "scrHash2" + providedLogsInnerTx2 := &transaction.ApiLogs{ + Events: []*transaction.Events{ + { + Address: receiver2, + Identifier: "events innertx 2", + }, + }, + } + + tp, _ := process.NewTransactionProcessor( + &mock.ProcessorStub{ + ComputeShardIdCalled: func(addressBuff []byte) (uint32, error) { + switch string(addressBuff) { + case "relayer", "sender1", "sender2", "receiver1": + return 0, nil + case "receiver2": + return 1, nil + } + + return 0, nil + }, + GetShardIDsCalled: func() []uint32 { + return []uint32{0, 1} + }, + GetObserversCalled: func(shardId uint32, dataAvailability data.ObserverDataAvailabilityType) ([]*data.NodeData, error) { + if shardId == 0 { + return []*data.NodeData{ + {Address: addrObs0, ShardId: 0}, + }, nil + } + if shardId == 1 { + return []*data.NodeData{ + {Address: addrObsFailing, ShardId: 1}, + {Address: addrObs1, ShardId: 1}, + }, nil + } + + return nil, nil + }, + CallGetRestEndPointCalled: func(address string, path string, value interface{}) (i int, err error) { + if address == addrObsFailing { + return http.StatusBadRequest, errors.New("error for coverage only") + } + + responseGetTx := value.(*data.GetTransactionResponse) + if strings.Contains(path, hashRelayed) { + responseGetTx.Data.Transaction.Hash = hashRelayed + responseGetTx.Data.Transaction.ProcessingTypeOnSource = "RelayedTxV3" + responseGetTx.Data.Transaction.ProcessingTypeOnDestination = "RelayedTxV3" + responseGetTx.Data.Transaction.SmartContractResults = []*transaction.ApiSmartContractResult{ + { + Hash: scrHash1, + RcvAddr: receiver1, + SndAddr: sender1, + RelayerAddr: relayer, + IsRelayed: true, + }, + { + Hash: scrHash2, + RcvAddr: receiver2, + SndAddr: sender2, + RelayerAddr: relayer, + IsRelayed: true, + }, + } + + return http.StatusOK, nil + } + if strings.Contains(path, scrHash1) { + responseGetTx.Data.Transaction.Hash = scrHash1 + responseGetTx.Data.Transaction.Logs = providedLogsInnerTx1 + + return http.StatusOK, nil + } + if strings.Contains(path, scrHash2) { + responseGetTx.Data.Transaction.Hash = scrHash2 + responseGetTx.Data.Transaction.Logs = providedLogsInnerTx2 + + return http.StatusOK, nil + } + + return http.StatusBadRequest, nil + }, + }, + &mock.PubKeyConverterMock{}, + hasher, + marshalizer, + funcNewTxCostHandler, + logsMerger, + true, + ) + + tx, err := tp.GetTransaction(hashRelayed, true) + require.NoError(t, err) + require.Equal(t, 2, len(tx.SmartContractResults)) + require.Equal(t, providedLogsInnerTx1, tx.SmartContractResults[0].Logs) + require.Equal(t, providedLogsInnerTx2, tx.SmartContractResults[1].Logs) +} + func TestTransactionProcessor_GetTransactionPool(t *testing.T) { t.Parallel() From bd24a18aaf86dd6dff5e08ad630694c545a8c58c Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 30 May 2024 19:16:28 +0300 Subject: [PATCH 10/25] fix process status returning failed instead of pending --- process/transactionProcessor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/process/transactionProcessor.go b/process/transactionProcessor.go index 399934f5..81eb5339 100644 --- a/process/transactionProcessor.go +++ b/process/transactionProcessor.go @@ -552,7 +552,7 @@ func checkIfRelayedV3Completed(logs []*transaction.ApiLogs, tx *transaction.ApiT } } - status := string(transaction.TxStatusFail) + status := string(transaction.TxStatusPending) if completedCnt == len(tx.InnerTransactions) { status = string(transaction.TxStatusSuccess) } From 04c644f8d83316eadd7f375b4c09aff3e6a3ec90 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 3 Jun 2024 18:37:00 +0300 Subject: [PATCH 11/25] added proper return on /process-status for un-executable relayed move balance --- ...iledRelayedTxMoveBalanceReturnMessage.json | 92 +++++++++++++++++++ process/testdata/finishedFailedSCR.json | 30 ++++++ process/transactionProcessor.go | 25 +++++ process/transactionProcessor_test.go | 18 ++++ 4 files changed, 165 insertions(+) create mode 100644 process/testdata/finishedFailedRelayedTxMoveBalanceReturnMessage.json create mode 100644 process/testdata/finishedFailedSCR.json diff --git a/process/testdata/finishedFailedRelayedTxMoveBalanceReturnMessage.json b/process/testdata/finishedFailedRelayedTxMoveBalanceReturnMessage.json new file mode 100644 index 00000000..41236c65 --- /dev/null +++ b/process/testdata/finishedFailedRelayedTxMoveBalanceReturnMessage.json @@ -0,0 +1,92 @@ +{ + "transaction": { + "type": "normal", + "processingTypeOnSource": "RelayedTx", + "processingTypeOnDestination": "RelayedTx", + "hash": "6c9d9eaf8928257c8019c56d56a9c0273e6428de00b96a584077778a5128be6a", + "nonce": 0, + "round": 66, + "epoch": 3, + "value": "0", + "receiver": "erd1ykqd64fxxpp4wsz0v7sjqem038wfpzlljhx4mhwx8w9lcxmdzcfszrp64a", + "sender": "erd1u39p5ld7qjg5qz8tnj2zr2ntvqeskzryu3fnh343uux2xlxzk6dsq5zx75", + "gasPrice": 1000000000, + "gasLimit": 1132000, + "gasUsed": 1132000, + "data": "cmVsYXllZFR4QDdiMjI2ZTZmNmU2MzY1MjIzYTMwMmMyMjc2NjE2Yzc1NjUyMjNhMzEzMDMwMzAzMDMwMzAzMDMwMzAzMDMwMzAzMDMwMzAzMDMwMmMyMjcyNjU2MzY1Njk3NjY1NzIyMjNhMjIzNjMzNjc0MTVhNDU0YTdhMmI1MjZjMzU1YTQ4NjY0MjQ4NTkyZjc2NGE0ZjZmNzQ0YTMwNzc2OTMyNzkzNDY0NDM0ODdhNzk0MzRhMzAzOTM0NTE1NTNkMjIyYzIyNzM2NTZlNjQ2NTcyMjIzYTIyNGE1OTQ0NjQ1NjUzNTk3NzUxMzE2NDQxNTQzMjY1Njg0OTQ3NjQ3NjY5NjQ3OTUxNjkyZjJiNTY3YTU2MzM2NDc4NmE3NTRjMmY0Mjc0NzQ0NjY4NGQzZDIyMmMyMjY3NjE3MzUwNzI2OTYzNjUyMjNhMzEzMDMwMzAzMDMwMzAzMDMwMzAyYzIyNjc2MTczNGM2OTZkNjk3NDIyM2EzNTMwMzAzMDMwMmMyMjYzNjg2MTY5NmU0OTQ0MjIzYTIyNjI0NzM5NmE1OTU3Nzc3NDY0NDc1NjdhNjQ0NzM1NmM2NDQxM2QzZDIyMmMyMjc2NjU3MjczNjk2ZjZlMjIzYTMyMmMyMjczNjk2NzZlNjE3NDc1NzI2NTIyM2EyMjcyNDQ1MTRiNTE0ODM0NGU2ZDZkNzQzMjUxNDYzNDcyNGEzMjU3NDYzNTRlNzk3MjYzNjc3NDY1NDM1OTY5NzE2YjRlNTEzMjcwNGM2YTYzNDc3OTc5NTU2NDQ2NTk2ODQ1NDgzMzU4MzE0YTU5NGE3OTQ3NTA1NDRlNDkzMDY2NTU2YTMyNTQ2Mzc0MmY2NzY0NGM2YjYyNDg0NjM3NmE1MDM4MzgzNTQyNDEzZDNkMjI3ZA==", + "signature": "d80e6db348ef8456eb1bf20aa4ba7863deb96366eb45ae0538efc4a43a894615ba72107048fa1b5793743b69e1720e83dac73d5b8cddb747fc8bb88816a5830a", + "sourceShard": 1, + "destinationShard": 1, + "blockNonce": 66, + "blockHash": "84bb2e631eec1c3665839f087e170de19bdaf287a83c6065fa97310f57b94e4c", + "notarizedAtSourceInMetaNonce": 68, + "NotarizedAtSourceInMetaHash": "808f39ce82d978f393d72dc78c3dbb17ab2bfd9fc8812cd982a2fd50fbc89667", + "notarizedAtDestinationInMetaNonce": 68, + "notarizedAtDestinationInMetaHash": "808f39ce82d978f393d72dc78c3dbb17ab2bfd9fc8812cd982a2fd50fbc89667", + "miniblockType": "TxBlock", + "miniblockHash": "fa5a6008a3b30ae7c59960d8d1fb221da0ce38fb38267f2fd40c69fd983581ea", + "hyperblockNonce": 68, + "hyperblockHash": "808f39ce82d978f393d72dc78c3dbb17ab2bfd9fc8812cd982a2fd50fbc89667", + "timestamp": 1717422998, + "smartContractResults": [ + { + "hash": "7cfde9ad5ead518ec768607a3ac992763f5afdcf31e603fdd56418c7ffe19774", + "nonce": 0, + "value": 0, + "receiver": "erd1u39p5ld7qjg5qz8tnj2zr2ntvqeskzryu3fnh343uux2xlxzk6dsq5zx75", + "sender": "erd1ykqd64fxxpp4wsz0v7sjqem038wfpzlljhx4mhwx8w9lcxmdzcfszrp64a", + "prevTxHash": "6c9d9eaf8928257c8019c56d56a9c0273e6428de00b96a584077778a5128be6a", + "originalTxHash": "6c9d9eaf8928257c8019c56d56a9c0273e6428de00b96a584077778a5128be6a", + "gasLimit": 0, + "gasPrice": 0, + "callType": 0, + "returnMessage": "insufficient funds", + "operation": "transfer" + } + ], + "status": "success", + "receivers": [ + "erd1aduqqezzw0u3j7tywlq3mrl0yn4z6f6vytdju8gg0neq38fauyzsa5yy6r" + ], + "receiversShardIDs": [ + 1 + ], + "operation": "transfer", + "initiallyPaidFee": "1082500000000000", + "fee": "1082500000000000", + "isRelayed": true, + "chainID": "local-testnet", + "version": 2, + "options": 0 + }, + "scrs": [ + { + "type": "unsigned", + "processingTypeOnSource": "MoveBalance", + "processingTypeOnDestination": "MoveBalance", + "hash": "7cfde9ad5ead518ec768607a3ac992763f5afdcf31e603fdd56418c7ffe19774", + "nonce": 0, + "round": 66, + "epoch": 3, + "value": "0", + "receiver": "erd1u39p5ld7qjg5qz8tnj2zr2ntvqeskzryu3fnh343uux2xlxzk6dsq5zx75", + "sender": "erd1ykqd64fxxpp4wsz0v7sjqem038wfpzlljhx4mhwx8w9lcxmdzcfszrp64a", + "gasUsed": 50000, + "previousTransactionHash": "6c9d9eaf8928257c8019c56d56a9c0273e6428de00b96a584077778a5128be6a", + "originalTransactionHash": "6c9d9eaf8928257c8019c56d56a9c0273e6428de00b96a584077778a5128be6a", + "returnMessage": "insufficient funds", + "sourceShard": 1, + "destinationShard": 1, + "blockNonce": 66, + "blockHash": "84bb2e631eec1c3665839f087e170de19bdaf287a83c6065fa97310f57b94e4c", + "miniblockType": "SmartContractResultBlock", + "miniblockHash": "9627ce0cafb78c5c109ce4fbb9011e8a07ac05057b89488348a05cd9a30d9717", + "timestamp": 1717422998, + "status": "success", + "operation": "transfer", + "fee": "0", + "callType": "directCall", + "options": 0 + } + ] +} diff --git a/process/testdata/finishedFailedSCR.json b/process/testdata/finishedFailedSCR.json new file mode 100644 index 00000000..a41fd6bd --- /dev/null +++ b/process/testdata/finishedFailedSCR.json @@ -0,0 +1,30 @@ +{ + "transaction": { + "type": "unsigned", + "processingTypeOnSource": "MoveBalance", + "processingTypeOnDestination": "MoveBalance", + "hash": "7cfde9ad5ead518ec768607a3ac992763f5afdcf31e603fdd56418c7ffe19774", + "nonce": 0, + "round": 66, + "epoch": 3, + "value": "0", + "receiver": "erd1u39p5ld7qjg5qz8tnj2zr2ntvqeskzryu3fnh343uux2xlxzk6dsq5zx75", + "sender": "erd1ykqd64fxxpp4wsz0v7sjqem038wfpzlljhx4mhwx8w9lcxmdzcfszrp64a", + "gasUsed": 50000, + "previousTransactionHash": "6c9d9eaf8928257c8019c56d56a9c0273e6428de00b96a584077778a5128be6a", + "originalTransactionHash": "6c9d9eaf8928257c8019c56d56a9c0273e6428de00b96a584077778a5128be6a", + "returnMessage": "insufficient funds", + "sourceShard": 1, + "destinationShard": 1, + "blockNonce": 66, + "blockHash": "84bb2e631eec1c3665839f087e170de19bdaf287a83c6065fa97310f57b94e4c", + "miniblockType": "SmartContractResultBlock", + "miniblockHash": "9627ce0cafb78c5c109ce4fbb9011e8a07ac05057b89488348a05cd9a30d9717", + "timestamp": 1717422998, + "status": "success", + "operation": "transfer", + "fee": "0", + "callType": "directCall", + "options": 0 + } +} diff --git a/process/transactionProcessor.go b/process/transactionProcessor.go index 40cde1f1..982a471d 100644 --- a/process/transactionProcessor.go +++ b/process/transactionProcessor.go @@ -486,6 +486,12 @@ func (tp *TransactionProcessor) computeTransactionStatus(tx *transaction.ApiTran } } + if checkIfFailedOnReturnMessage(allScrs, tx) { + return &data.ProcessStatusResponse{ + Status: string(transaction.TxStatusFail), + } + } + if checkIfCompleted(allLogs) { return &data.ProcessStatusResponse{ Status: string(transaction.TxStatusSuccess), @@ -497,6 +503,25 @@ func (tp *TransactionProcessor) computeTransactionStatus(tx *transaction.ApiTran } } +func checkIfFailedOnReturnMessage(allScrs []*transaction.ApiTransactionResult, tx *transaction.ApiTransactionResult) bool { + if returnMessageFailure(tx.Value, tx.ReturnMessage) { + return true + } + + for _, scr := range allScrs { + if returnMessageFailure(scr.Value, scr.ReturnMessage) { + return true + } + } + + return false +} + +func returnMessageFailure(value string, returnMessage string) bool { + isZeroValue := value == "0" + return len(returnMessage) > 0 && isZeroValue +} + func checkIfFailed(logs []*transaction.ApiLogs) (bool, string) { found, reason := findIdentifierInLogs(logs, internalVMErrorsEventIdentifier) if found { diff --git a/process/transactionProcessor_test.go b/process/transactionProcessor_test.go index 0fa9b76f..7578f93b 100644 --- a/process/transactionProcessor_test.go +++ b/process/transactionProcessor_test.go @@ -1789,6 +1789,15 @@ func TestTransactionProcessor_computeTransactionStatus(t *testing.T) { status := tp.ComputeTransactionStatus(testData.Transaction, withResults) require.Equal(t, string(transaction.TxStatusSuccess), status.Status) }) + t.Run("failed un-executable move balance scr", func(t *testing.T) { + t.Parallel() + + testData := loadJsonIntoTxAndScrs(t, "./testdata/finishedFailedSCR.json") + tp := createTestProcessorFromScenarioData(testData) + + status := tp.ComputeTransactionStatus(testData.Transaction, withResults) + require.Equal(t, string(transaction.TxStatusFail), status.Status) + }) }) t.Run("SC calls", func(t *testing.T) { t.Run("pending new", func(t *testing.T) { @@ -1898,6 +1907,15 @@ func TestTransactionProcessor_computeTransactionStatus(t *testing.T) { status := tp.ComputeTransactionStatus(testData.Transaction, withResults) require.Equal(t, string(transaction.TxStatusFail), status.Status) }) + t.Run("failed relayed transaction un-executable move balance", func(t *testing.T) { + t.Parallel() + + testData := loadJsonIntoTxAndScrs(t, "./testdata/finishedFailedRelayedTxMoveBalanceReturnMessage.json") + tp := createTestProcessorFromScenarioData(testData) + + status := tp.ComputeTransactionStatus(testData.Transaction, withResults) + require.Equal(t, string(transaction.TxStatusFail), status.Status) + }) t.Run("failed relayed transaction with SC call", func(t *testing.T) { t.Parallel() From 3813d381c349f778c2413beff2f1aac9daa9c0f0 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 4 Jun 2024 09:54:28 +0300 Subject: [PATCH 12/25] fix after review --- process/transactionProcessor.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/process/transactionProcessor.go b/process/transactionProcessor.go index 982a471d..55d953b5 100644 --- a/process/transactionProcessor.go +++ b/process/transactionProcessor.go @@ -504,12 +504,12 @@ func (tp *TransactionProcessor) computeTransactionStatus(tx *transaction.ApiTran } func checkIfFailedOnReturnMessage(allScrs []*transaction.ApiTransactionResult, tx *transaction.ApiTransactionResult) bool { - if returnMessageFailure(tx.Value, tx.ReturnMessage) { + if len(tx.ReturnMessage) > 0 && isZeroValue(tx.Value) { return true } for _, scr := range allScrs { - if returnMessageFailure(scr.Value, scr.ReturnMessage) { + if len(scr.ReturnMessage) > 0 && isZeroValue(scr.Value) { return true } } @@ -517,9 +517,11 @@ func checkIfFailedOnReturnMessage(allScrs []*transaction.ApiTransactionResult, t return false } -func returnMessageFailure(value string, returnMessage string) bool { - isZeroValue := value == "0" - return len(returnMessage) > 0 && isZeroValue +func isZeroValue(value string) bool { + if len(value) == 0 { + return true + } + return value == "0" } func checkIfFailed(logs []*transaction.ApiLogs) (bool, string) { From e60a623e288d3c251ca96e2e5080a2d397c7fb4d Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 5 Jun 2024 18:05:33 +0300 Subject: [PATCH 13/25] go mod tidy after merge --- go.sum | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/go.sum b/go.sum index e763f63d..d50efa14 100644 --- a/go.sum +++ b/go.sum @@ -131,8 +131,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240508071047-fefea5737840 h1:2mCrTUmbbA+Xv4UifZY9xptrGjcJBcJ2wavSb4FwejU= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240508071047-fefea5737840/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240528132712-8b6faa711b23 h1:jSP8BjMF9P5I9cO5hY2uN60q4+iPP9uq5WzETtcXWMI= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240528132712-8b6faa711b23/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df h1:clihfi78bMEOWk/qw6WA4uQbCM2e2NGliqswLAvw19k= github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df/go.mod h1:gtJYB4rR21KBSqJlazn+2z6f9gFSqQP3KvAgL7Qgxw4= github.com/multiversx/mx-chain-es-indexer-go v1.7.1-0.20240509104512-25512675833d h1:GD1D8V0bE6hDLjrduSsMwQwwf6PMq2Zww7FYMfJsuiw= From 87b39765fd29daf779698476dbdeda985f6ac3bc Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 5 Jun 2024 18:09:09 +0300 Subject: [PATCH 14/25] fixes after merge --- process/transactionProcessor.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/process/transactionProcessor.go b/process/transactionProcessor.go index 97d95a5d..2ef984eb 100644 --- a/process/transactionProcessor.go +++ b/process/transactionProcessor.go @@ -5,7 +5,6 @@ import ( "fmt" "math/big" "net/http" - "strings" "github.com/multiversx/mx-chain-core-go/core" "github.com/multiversx/mx-chain-core-go/core/check" @@ -43,9 +42,7 @@ const ( relayedV1TransactionDescriptor = "RelayedTx" relayedV2TransactionDescriptor = "RelayedTxV2" relayedV3TransactionDescriptor = "RelayedTxV3" - relayedTxV1DataMarker = "relayedTx@" relayedTxV2DataMarker = "relayedTxV2" - argumentsSeparator = "@" emptyDataStr = "" ) @@ -488,7 +485,7 @@ func (tp *TransactionProcessor) computeTransactionStatus(tx *transaction.ApiTran } } - isRelayedV3, status := checkIfRelayedV3Completed(allLogs, tx) + isRelayedV3, status := checkIfRelayedV3Completed(allScrs, allLogs, tx) if isRelayedV3 { return &data.ProcessStatusResponse{ Status: status, @@ -557,7 +554,7 @@ func checkIfCompleted(logs []*transaction.ApiLogs) bool { return found } -func checkIfRelayedV3Completed(logs []*transaction.ApiLogs, tx *transaction.ApiTransactionResult) (bool, string) { +func checkIfRelayedV3Completed(scrs []*transaction.ApiTransactionResult, logs []*transaction.ApiLogs, tx *transaction.ApiTransactionResult) (bool, string) { if len(tx.InnerTransactions) == 0 { return false, string(transaction.TxStatusPending) } @@ -574,11 +571,16 @@ func checkIfRelayedV3Completed(logs []*transaction.ApiLogs, tx *transaction.ApiT completedFound, _ := findIdentifierInSingleLog(logInstance, core.CompletedTxEventIdentifier) deployFound, _ := findIdentifierInSingleLog(logInstance, core.SCDeployIdentifier) + if completedFound || deployFound { completedCnt++ } } + if checkIfFailedOnReturnMessage(scrs, tx) { + return true, string(transaction.TxStatusFail) + } + status := string(transaction.TxStatusPending) if completedCnt == len(tx.InnerTransactions) { status = string(transaction.TxStatusSuccess) From 935bdb359a0cbdc4012c373a814a444b76451929 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 13 Jun 2024 18:20:57 +0300 Subject: [PATCH 15/25] fixes after review --- process/export_test.go | 3 --- process/transactionProcessor.go | 14 +++++++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/process/export_test.go b/process/export_test.go index be16c7f7..e75d3da2 100644 --- a/process/export_test.go +++ b/process/export_test.go @@ -7,9 +7,6 @@ import ( proxyData "github.com/multiversx/mx-chain-proxy-go/data" ) -// RelayedTxV2DataMarker - -const RelayedTxV2DataMarker = relayedTxV2DataMarker - // SetDelayForCheckingNodesSyncState - func (bp *BaseProcessor) SetDelayForCheckingNodesSyncState(delay time.Duration) { bp.delayForCheckingNodesSyncState = delay diff --git a/process/transactionProcessor.go b/process/transactionProcessor.go index 2ef984eb..40c2b9aa 100644 --- a/process/transactionProcessor.go +++ b/process/transactionProcessor.go @@ -42,7 +42,6 @@ const ( relayedV1TransactionDescriptor = "RelayedTx" relayedV2TransactionDescriptor = "RelayedTxV2" relayedV3TransactionDescriptor = "RelayedTxV3" - relayedTxV2DataMarker = "relayedTxV2" emptyDataStr = "" ) @@ -795,14 +794,15 @@ func (tp *TransactionProcessor) mergeSCRLogsFromInnerReceivers(tx *transaction.A break } - for _, observer := range observers { - getTxResponse, ok, _ := tp.getTxFromObserver(observer, scrHash, withResults) - if !ok { - continue - } + if withResults { + for _, observer := range observers { + getTxResponse, ok, _ := tp.getTxFromObserver(observer, scrHash, withResults) + if !ok { + continue + } - if withResults { logsOnDestMap[scrHash] = getTxResponse.Data.Transaction.Logs + break } } } From b28ae65afbe2d0c66ae70f201c210b41c5d8f7a4 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 19 Jun 2024 17:04:03 +0300 Subject: [PATCH 16/25] fix /process-status returning incorrect failed tx with gas refund --- process/transactionProcessor.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/process/transactionProcessor.go b/process/transactionProcessor.go index 40c2b9aa..78c4c3b9 100644 --- a/process/transactionProcessor.go +++ b/process/transactionProcessor.go @@ -509,11 +509,16 @@ func (tp *TransactionProcessor) computeTransactionStatus(tx *transaction.ApiTran } func checkIfFailedOnReturnMessage(allScrs []*transaction.ApiTransactionResult, tx *transaction.ApiTransactionResult) bool { - if len(tx.ReturnMessage) > 0 && isZeroValue(tx.Value) { + hasReturnMessageWithZeroValue := len(tx.ReturnMessage) > 0 && isZeroValue(tx.Value) + if hasReturnMessageWithZeroValue && !isRefundScr(tx.ReturnMessage) { return true } for _, scr := range allScrs { + if isRefundScr(scr.ReturnMessage) { + continue + } + if len(scr.ReturnMessage) > 0 && isZeroValue(scr.Value) { return true } @@ -522,6 +527,10 @@ func checkIfFailedOnReturnMessage(allScrs []*transaction.ApiTransactionResult, t return false } +func isRefundScr(returnMessage string) bool { + return returnMessage == core.GasRefundForRelayerMessage +} + func isZeroValue(value string) bool { if len(value) == 0 { return true From ebbe8373830a65b91d07f930bef464ea28fe8737 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 2 Jul 2024 13:58:31 +0300 Subject: [PATCH 17/25] fix /process-status returning incorrect pending tx for issue which generates more than one completedTxEvent --- process/transactionProcessor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/process/transactionProcessor.go b/process/transactionProcessor.go index 78c4c3b9..bc140fec 100644 --- a/process/transactionProcessor.go +++ b/process/transactionProcessor.go @@ -590,7 +590,7 @@ func checkIfRelayedV3Completed(scrs []*transaction.ApiTransactionResult, logs [] } status := string(transaction.TxStatusPending) - if completedCnt == len(tx.InnerTransactions) { + if completedCnt >= len(tx.InnerTransactions) { status = string(transaction.TxStatusSuccess) } return true, status From dc3cc55deae90cc3e05c9c5ef1f3f48700ee41fe Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 3 Jul 2024 12:34:54 +0300 Subject: [PATCH 18/25] /process-status now returns success for relayed v3 --- process/transactionProcessor.go | 42 ++++++++------------------------- 1 file changed, 10 insertions(+), 32 deletions(-) diff --git a/process/transactionProcessor.go b/process/transactionProcessor.go index bc140fec..9d55ee1a 100644 --- a/process/transactionProcessor.go +++ b/process/transactionProcessor.go @@ -476,18 +476,18 @@ func (tp *TransactionProcessor) computeTransactionStatus(tx *transaction.ApiTran } } - failed, reason = checkIfFailed(allLogs) - if failed { + isRelayedV3, status := checkIfRelayedV3Completed(allLogs, tx) + if isRelayedV3 { return &data.ProcessStatusResponse{ - Status: string(transaction.TxStatusFail), - Reason: reason, + Status: status, } } - isRelayedV3, status := checkIfRelayedV3Completed(allScrs, allLogs, tx) - if isRelayedV3 { + failed, reason = checkIfFailed(allLogs) + if failed { return &data.ProcessStatusResponse{ - Status: status, + Status: string(transaction.TxStatusFail), + Reason: reason, } } @@ -562,38 +562,16 @@ func checkIfCompleted(logs []*transaction.ApiLogs) bool { return found } -func checkIfRelayedV3Completed(scrs []*transaction.ApiTransactionResult, logs []*transaction.ApiLogs, tx *transaction.ApiTransactionResult) (bool, string) { +func checkIfRelayedV3Completed(logs []*transaction.ApiLogs, tx *transaction.ApiTransactionResult) (bool, string) { if len(tx.InnerTransactions) == 0 { return false, string(transaction.TxStatusPending) } - if len(logs) == 0 { + if len(logs) < len(tx.InnerTransactions) { return true, string(transaction.TxStatusPending) } - completedCnt := 0 - for _, logInstance := range logs { - if logInstance == nil { - continue - } - - completedFound, _ := findIdentifierInSingleLog(logInstance, core.CompletedTxEventIdentifier) - deployFound, _ := findIdentifierInSingleLog(logInstance, core.SCDeployIdentifier) - - if completedFound || deployFound { - completedCnt++ - } - } - - if checkIfFailedOnReturnMessage(scrs, tx) { - return true, string(transaction.TxStatusFail) - } - - status := string(transaction.TxStatusPending) - if completedCnt >= len(tx.InnerTransactions) { - status = string(transaction.TxStatusSuccess) - } - return true, status + return true, string(transaction.TxStatusSuccess) } func checkIfMoveBalanceNotarized(tx *transaction.ApiTransactionResult) bool { From 0283601eb7261af04bf8bd8a943a97b3b0690766 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 3 Jul 2024 13:03:44 +0300 Subject: [PATCH 19/25] update deps --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 91972d32..d101ad9a 100644 --- a/go.mod +++ b/go.mod @@ -8,9 +8,9 @@ require ( github.com/gin-contrib/pprof v1.4.0 github.com/gin-contrib/static v0.0.1 github.com/gin-gonic/gin v1.9.1 - github.com/multiversx/mx-chain-core-go v1.2.21-0.20240528132712-8b6faa711b23 + github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703095353-e5daea901067 github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df - github.com/multiversx/mx-chain-es-indexer-go v1.7.1-0.20240509104512-25512675833d + github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240514103357-929ece92ef86 github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index d50efa14..592e8c9d 100644 --- a/go.sum +++ b/go.sum @@ -131,12 +131,12 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240528132712-8b6faa711b23 h1:jSP8BjMF9P5I9cO5hY2uN60q4+iPP9uq5WzETtcXWMI= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240528132712-8b6faa711b23/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703095353-e5daea901067 h1:xkWwOJok4GlbMd/BBtJ75wnNRjIVh4o+7RdZL/q/mlQ= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703095353-e5daea901067/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df h1:clihfi78bMEOWk/qw6WA4uQbCM2e2NGliqswLAvw19k= github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df/go.mod h1:gtJYB4rR21KBSqJlazn+2z6f9gFSqQP3KvAgL7Qgxw4= -github.com/multiversx/mx-chain-es-indexer-go v1.7.1-0.20240509104512-25512675833d h1:GD1D8V0bE6hDLjrduSsMwQwwf6PMq2Zww7FYMfJsuiw= -github.com/multiversx/mx-chain-es-indexer-go v1.7.1-0.20240509104512-25512675833d/go.mod h1:UDKRXmxsSyPeAcjLUfGeYkAtYp424PIYkL82kzFYobM= +github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240514103357-929ece92ef86 h1:rw+u7qv0HO+7lRddCzfciqDcAWL9/fl2LQqU8AmVtdU= +github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240514103357-929ece92ef86/go.mod h1:UDKRXmxsSyPeAcjLUfGeYkAtYp424PIYkL82kzFYobM= github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 h1:g9t410dqjcb7UUptbVd/H6Ua12sEzWU4v7VplyNvRZ0= github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57/go.mod h1:cY6CIXpndW5g5PTPn4WzPwka/UBEf+mgw+PSY5pHGAU= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= From f599657093bc53280fba9778f5d202237fe91a66 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 3 Jul 2024 17:04:41 +0300 Subject: [PATCH 20/25] update deps --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index d101ad9a..0db9fd93 100644 --- a/go.mod +++ b/go.mod @@ -8,9 +8,9 @@ require ( github.com/gin-contrib/pprof v1.4.0 github.com/gin-contrib/static v0.0.1 github.com/gin-gonic/gin v1.9.1 - github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703095353-e5daea901067 + github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703135649-550eebfbc10b github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df - github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240514103357-929ece92ef86 + github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619122842-05143459c554 github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index 592e8c9d..c21a856f 100644 --- a/go.sum +++ b/go.sum @@ -131,12 +131,12 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703095353-e5daea901067 h1:xkWwOJok4GlbMd/BBtJ75wnNRjIVh4o+7RdZL/q/mlQ= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703095353-e5daea901067/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703135649-550eebfbc10b h1:bmN8RtaWC/7lQenavRVVY5NrAPOdh3N9tGyxqVrx2qU= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703135649-550eebfbc10b/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df h1:clihfi78bMEOWk/qw6WA4uQbCM2e2NGliqswLAvw19k= github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df/go.mod h1:gtJYB4rR21KBSqJlazn+2z6f9gFSqQP3KvAgL7Qgxw4= -github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240514103357-929ece92ef86 h1:rw+u7qv0HO+7lRddCzfciqDcAWL9/fl2LQqU8AmVtdU= -github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240514103357-929ece92ef86/go.mod h1:UDKRXmxsSyPeAcjLUfGeYkAtYp424PIYkL82kzFYobM= +github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619122842-05143459c554 h1:Fv8BfzJSzdovmoh9Jh/by++0uGsOVBlMP3XiN5Svkn4= +github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619122842-05143459c554/go.mod h1:yMq9q5VdN7jBaErRGQ0T8dkZwbBtfQYmqGbD/Ese1us= github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 h1:g9t410dqjcb7UUptbVd/H6Ua12sEzWU4v7VplyNvRZ0= github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57/go.mod h1:cY6CIXpndW5g5PTPn4WzPwka/UBEf+mgw+PSY5pHGAU= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= From 9a6b0bb680364777e2e77194c57c7603b4824851 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 25 Jul 2024 10:45:38 +0300 Subject: [PATCH 21/25] updated deps after merge --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 0db9fd93..2ace1a0a 100644 --- a/go.mod +++ b/go.mod @@ -8,10 +8,10 @@ require ( github.com/gin-contrib/pprof v1.4.0 github.com/gin-contrib/static v0.0.1 github.com/gin-gonic/gin v1.9.1 - github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703135649-550eebfbc10b - github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df - github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619122842-05143459c554 - github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 + github.com/multiversx/mx-chain-core-go v1.2.21-0.20240725065431-6e9bfee5a4c6 + github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f + github.com/multiversx/mx-chain-es-indexer-go v1.7.3-0.20240725073933-b3457c5308ca + github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240725065747-176bd697c775 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.4 github.com/urfave/cli v1.22.10 diff --git a/go.sum b/go.sum index c21a856f..9b19a00d 100644 --- a/go.sum +++ b/go.sum @@ -131,14 +131,14 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703135649-550eebfbc10b h1:bmN8RtaWC/7lQenavRVVY5NrAPOdh3N9tGyxqVrx2qU= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240703135649-550eebfbc10b/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= -github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df h1:clihfi78bMEOWk/qw6WA4uQbCM2e2NGliqswLAvw19k= -github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240508074452-cc21c1b505df/go.mod h1:gtJYB4rR21KBSqJlazn+2z6f9gFSqQP3KvAgL7Qgxw4= -github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619122842-05143459c554 h1:Fv8BfzJSzdovmoh9Jh/by++0uGsOVBlMP3XiN5Svkn4= -github.com/multiversx/mx-chain-es-indexer-go v1.7.2-0.20240619122842-05143459c554/go.mod h1:yMq9q5VdN7jBaErRGQ0T8dkZwbBtfQYmqGbD/Ese1us= -github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57 h1:g9t410dqjcb7UUptbVd/H6Ua12sEzWU4v7VplyNvRZ0= -github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240508072523-3f00a726af57/go.mod h1:cY6CIXpndW5g5PTPn4WzPwka/UBEf+mgw+PSY5pHGAU= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240725065431-6e9bfee5a4c6 h1:Q7uUjTYTrt8Mw9oq5JWPv+WHhpxHTv6lhZZlhPuNcoQ= +github.com/multiversx/mx-chain-core-go v1.2.21-0.20240725065431-6e9bfee5a4c6/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f h1:jydjrmVFvSllBOTppveOAkLITpOYKk0kma5z0bfDImI= +github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f/go.mod h1:9aSp//uBSvqFdzh4gvYISraoruhr1FCTXgPQalQ687k= +github.com/multiversx/mx-chain-es-indexer-go v1.7.3-0.20240725073933-b3457c5308ca h1:9b2yFAarWDG/jTYePv0UqNWQ9gxeSZy9mGxtd8dFj2Y= +github.com/multiversx/mx-chain-es-indexer-go v1.7.3-0.20240725073933-b3457c5308ca/go.mod h1:bHPP5zerhmbRfVcbfXgpMPUaTKMrK6gGi+rRbw0BpDE= +github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240725065747-176bd697c775 h1:a8LOfz3p4MQfRtbF00rGDAJiebziwtSfVmBHIaHBDdY= +github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240725065747-176bd697c775/go.mod h1:owPYyrK7RcsLx9eOCAZQ22fIyW6BE7ttJr4XIhFIbQw= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= From dd7d971672af6b70328742c41365cfaadd102f83 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Mon, 29 Jul 2024 11:38:27 +0300 Subject: [PATCH 22/25] updated deps --- go.mod | 8 ++++---- go.sum | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 2ace1a0a..fbb90512 100644 --- a/go.mod +++ b/go.mod @@ -8,10 +8,10 @@ require ( github.com/gin-contrib/pprof v1.4.0 github.com/gin-contrib/static v0.0.1 github.com/gin-gonic/gin v1.9.1 - github.com/multiversx/mx-chain-core-go v1.2.21-0.20240725065431-6e9bfee5a4c6 - github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f - github.com/multiversx/mx-chain-es-indexer-go v1.7.3-0.20240725073933-b3457c5308ca - github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240725065747-176bd697c775 + github.com/multiversx/mx-chain-core-go v1.2.21 + github.com/multiversx/mx-chain-crypto-go v1.2.12 + github.com/multiversx/mx-chain-es-indexer-go v1.7.4 + github.com/multiversx/mx-chain-logger-go v1.0.15 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.8.4 github.com/urfave/cli v1.22.10 diff --git a/go.sum b/go.sum index 9b19a00d..3ff90b70 100644 --- a/go.sum +++ b/go.sum @@ -131,14 +131,14 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o= github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240725065431-6e9bfee5a4c6 h1:Q7uUjTYTrt8Mw9oq5JWPv+WHhpxHTv6lhZZlhPuNcoQ= -github.com/multiversx/mx-chain-core-go v1.2.21-0.20240725065431-6e9bfee5a4c6/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= -github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f h1:jydjrmVFvSllBOTppveOAkLITpOYKk0kma5z0bfDImI= -github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f/go.mod h1:9aSp//uBSvqFdzh4gvYISraoruhr1FCTXgPQalQ687k= -github.com/multiversx/mx-chain-es-indexer-go v1.7.3-0.20240725073933-b3457c5308ca h1:9b2yFAarWDG/jTYePv0UqNWQ9gxeSZy9mGxtd8dFj2Y= -github.com/multiversx/mx-chain-es-indexer-go v1.7.3-0.20240725073933-b3457c5308ca/go.mod h1:bHPP5zerhmbRfVcbfXgpMPUaTKMrK6gGi+rRbw0BpDE= -github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240725065747-176bd697c775 h1:a8LOfz3p4MQfRtbF00rGDAJiebziwtSfVmBHIaHBDdY= -github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240725065747-176bd697c775/go.mod h1:owPYyrK7RcsLx9eOCAZQ22fIyW6BE7ttJr4XIhFIbQw= +github.com/multiversx/mx-chain-core-go v1.2.21 h1:+XVKznPTlUU5EFS1A8chtS8fStW60upRIyF4Pgml19I= +github.com/multiversx/mx-chain-core-go v1.2.21/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= +github.com/multiversx/mx-chain-crypto-go v1.2.12/go.mod h1:HzcPpCm1zanNct/6h2rIh+MFrlXbjA5C8+uMyXj3LI4= +github.com/multiversx/mx-chain-es-indexer-go v1.7.4 h1:SjJk9G9SN8baz0sFIU2jymYCfx3XiikGEB2wW0jwvfw= +github.com/multiversx/mx-chain-es-indexer-go v1.7.4/go.mod h1:oGcRK2E3Syv6vRTszWrrb/TqD8akq0yeoMr1wPPiTO4= +github.com/multiversx/mx-chain-logger-go v1.0.15 h1:HlNdK8etyJyL9NQ+6mIXyKPEBo+wRqOwi3n+m2QIHXc= +github.com/multiversx/mx-chain-logger-go v1.0.15/go.mod h1:t3PRKaWB1M+i6gUfD27KXgzLJJC+mAQiN+FLlL1yoGQ= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= From 2487bb1fc8b7815b347cc5f20b7803dcd0864acb Mon Sep 17 00:00:00 2001 From: danielailie Date: Thu, 1 Aug 2024 15:46:10 +0300 Subject: [PATCH 23/25] Remove code for address/:address/transactions --- .gitignore | 1 + README.md | 1 - api/groups/baseAccountsGroup.go | 22 ---------- api/groups/interface.go | 1 - cmd/proxy/config/apiConfig/v1_0.toml | 1 - cmd/proxy/config/apiConfig/v_next.toml | 1 - cmd/proxy/config/swagger/openapi.json | 44 +++---------------- facade/baseFacade.go | 5 --- facade/interface.go | 1 - facade/mock/accountProccessorStub.go | 5 --- process/accountProcessor.go | 9 ---- process/accountProcessor_test.go | 20 --------- process/database/elasticSearchConnector.go | 10 ----- .../database/elasticSearchConnector_test.go | 14 ------ process/interface.go | 1 - process/mock/elasticSearchConnectorMock.go | 5 --- process/mock/externalStorageConnectorStub.go | 10 ----- 17 files changed, 7 insertions(+), 144 deletions(-) diff --git a/.gitignore b/.gitignore index 44e69658..a4530dd0 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ .idea/ vendor/ +cmd/proxy/proxy diff --git a/README.md b/README.md index bef3670e..5967add5 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,6 @@ For more details, go [here](https://docs.multiversx.com/sdk-and-tools/proxy/). - `/v1.0/address/:address/shard` (GET) --> returns the shard of an :address based on current proxy's configuration. - `/v1.0/address/:address/keys ` (GET) --> returns the key-value pairs of an :address. - `/v1.0/address/:address/storage/:key` (GET) --> returns the value for a given key for an account. -- `/v1.0/address/:address/transactions` (GET) --> returns the transactions stored in indexer for a given :address. - `/v1.0/address/:address/esdt` (GET) --> returns the account's ESDT tokens list for the given :address. - `/v1.0/address/:address/esdt/:tokenIdentifier` (GET) --> returns the token data for a given :address and ESDT token, such as balance and properties. - `/v1.0/address/:address/esdts-with-role/:role` (GET) --> returns the token identifiers for a given :address and the provided role. diff --git a/api/groups/baseAccountsGroup.go b/api/groups/baseAccountsGroup.go index 62ea2592..2daaca58 100644 --- a/api/groups/baseAccountsGroup.go +++ b/api/groups/baseAccountsGroup.go @@ -34,7 +34,6 @@ func NewAccountsGroup(facadeHandler data.FacadeHandler) (*accountsGroup, error) {Path: "/:address/nonce", Handler: ag.getNonce, Method: http.MethodGet}, {Path: "/:address/shard", Handler: ag.getShard, Method: http.MethodGet}, {Path: "/:address/code-hash", Handler: ag.getCodeHash, Method: http.MethodGet}, - {Path: "/:address/transactions", Handler: ag.getTransactions, Method: http.MethodGet}, {Path: "/:address/keys", Handler: ag.getKeyValuePairs, Method: http.MethodGet}, {Path: "/:address/key/:key", Handler: ag.getValueForKey, Method: http.MethodGet}, {Path: "/:address/esdt", Handler: ag.getESDTTokens, Method: http.MethodGet}, @@ -71,16 +70,6 @@ func (group *accountsGroup) respondWithAccount(c *gin.Context, transform func(*d shared.RespondWith(c, http.StatusOK, response, "", data.ReturnCodeSuccess) } -func (group *accountsGroup) getTransactionsFromFacade(c *gin.Context) ([]data.DatabaseTransaction, int, error) { - addr := c.Param("address") - transactions, err := group.facade.GetTransactions(addr) - if err != nil { - return nil, http.StatusInternalServerError, err - } - - return transactions, http.StatusOK, nil -} - // getAccount returns an accountResponse containing information // about the account correlated with provided address func (group *accountsGroup) getAccount(c *gin.Context) { @@ -157,17 +146,6 @@ func (group *accountsGroup) getAccounts(c *gin.Context) { shared.RespondWith(c, http.StatusOK, response, "", data.ReturnCodeSuccess) } -// getTransactions returns the transactions for the address parameter -func (group *accountsGroup) getTransactions(c *gin.Context) { - transactions, status, err := group.getTransactionsFromFacade(c) - if err != nil { - shared.RespondWith(c, status, nil, err.Error(), data.ReturnCodeInternalError) - return - } - - shared.RespondWith(c, http.StatusOK, gin.H{"transactions": transactions}, "", data.ReturnCodeSuccess) -} - // getKeyValuePairs returns the key-value pairs for the address parameter func (group *accountsGroup) getKeyValuePairs(c *gin.Context) { addr := c.Param("address") diff --git a/api/groups/interface.go b/api/groups/interface.go index a4c18868..c97a076b 100644 --- a/api/groups/interface.go +++ b/api/groups/interface.go @@ -13,7 +13,6 @@ import ( type AccountsFacadeHandler interface { GetAccount(address string, options common.AccountQueryOptions) (*data.AccountModel, error) GetCodeHash(address string, options common.AccountQueryOptions) (*data.GenericAPIResponse, error) - GetTransactions(address string) ([]data.DatabaseTransaction, error) GetShardIDForAddress(address string) (uint32, error) GetValueForKey(address string, key string, options common.AccountQueryOptions) (string, error) GetAllESDTTokens(address string, options common.AccountQueryOptions) (*data.GenericAPIResponse, error) diff --git a/cmd/proxy/config/apiConfig/v1_0.toml b/cmd/proxy/config/apiConfig/v1_0.toml index 1f5d2aed..6bfd4d85 100644 --- a/cmd/proxy/config/apiConfig/v1_0.toml +++ b/cmd/proxy/config/apiConfig/v1_0.toml @@ -45,7 +45,6 @@ Routes = [ { Name = "/:address/registered-nfts", Open = true, Secured = false, RateLimit = 0 }, { Name = "/:address/nft/:tokenIdentifier/nonce/:nonce", Open = true, Secured = false, RateLimit = 0 }, { Name = "/:address/shard", Open = true, Secured = false, RateLimit = 0 }, - { Name = "/:address/transactions", Open = true, Secured = false, RateLimit = 0 }, { Name = "/:address/guardian-data", Open = true, Secured = false, RateLimit = 0 }, { Name = "/:address/is-data-trie-migrated", Open = true, Secured = false, RateLimit = 0 } ] diff --git a/cmd/proxy/config/apiConfig/v_next.toml b/cmd/proxy/config/apiConfig/v_next.toml index 1bdf4e85..8fdb4dd1 100644 --- a/cmd/proxy/config/apiConfig/v_next.toml +++ b/cmd/proxy/config/apiConfig/v_next.toml @@ -45,7 +45,6 @@ Routes = [ { Name = "/:address/registered-nfts", Open = true, Secured = false, RateLimit = 0 }, { Name = "/:address/nft/:tokenIdentifier/nonce/:nonce", Open = true, Secured = false, RateLimit = 0 }, { Name = "/:address/shard", Open = true, Secured = false, RateLimit = 0 }, - { Name = "/:address/transactions", Open = true, Secured = false, RateLimit = 0 }, { Name = "/:address/guardian-data", Open = true, Secured = false, RateLimit = 0 }, { Name = "/:address/is-data-trie-migrated", Open = true, Secured = false, RateLimit = 0 } ] diff --git a/cmd/proxy/config/swagger/openapi.json b/cmd/proxy/config/swagger/openapi.json index 05c1e5b9..f27cc0a1 100644 --- a/cmd/proxy/config/swagger/openapi.json +++ b/cmd/proxy/config/swagger/openapi.json @@ -270,38 +270,6 @@ } } }, - "/address/{address}/transactions": { - "get": { - "tags": [ - "address" - ], - "summary": "returns the transactions of the provided address", - "parameters": [ - { - "name": "address", - "in": "path", - "description": "the address in bech32 format", - "required": true, - "schema": { - "type": "string", - "default": null - } - } - ], - "responses": { - "200": { - "description": "successful operation", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/AddressTransactions" - } - } - } - } - } - } - }, "/address/{address}/key/{key}": { "get": { "tags": [ @@ -2671,7 +2639,7 @@ "name": "fields", "in": "query", "description": "the requested transaction fields, comma sepparated. If none provided, only hash is returned. Possible values are: hash, nonce, sender, receiver, gaslimit, gasprice, receiverusername, data, value", - "schema" : { + "schema": { "type": "string", "default": null } @@ -2680,7 +2648,7 @@ "name": "shard-id", "in": "query", "description": "the shard id to return transactions pool", - "schema" : { + "schema": { "type": "string", "default": null } @@ -2689,7 +2657,7 @@ "name": "by-sender", "in": "query", "description": "the bech32 address of transactions' sender", - "schema" : { + "schema": { "type": "string", "default": null } @@ -2698,7 +2666,7 @@ "name": "last-nonce", "in": "query", "description": "returns the last nonce from pool. This parameter requires by-sender and does not work with fields", - "schema" : { + "schema": { "type": "boolean", "default": false } @@ -2707,7 +2675,7 @@ "name": "nonce-gaps", "in": "query", "description": "returns the nonce gaps from pool. This parameter requires by-sender and does not work with fields", - "schema" : { + "schema": { "type": "boolean", "default": false } @@ -3271,4 +3239,4 @@ } } } -} +} \ No newline at end of file diff --git a/facade/baseFacade.go b/facade/baseFacade.go index 01e04910..525937d7 100644 --- a/facade/baseFacade.go +++ b/facade/baseFacade.go @@ -161,11 +161,6 @@ func (pf *ProxyFacade) GetShardIDForAddress(address string) (uint32, error) { return pf.accountProc.GetShardIDForAddress(address) } -// GetTransactions returns transactions by address -func (pf *ProxyFacade) GetTransactions(address string) ([]data.DatabaseTransaction, error) { - return pf.accountProc.GetTransactions(address) -} - // GetESDTTokenData returns the token data for a given token name func (pf *ProxyFacade) GetESDTTokenData(address string, key string, options common.AccountQueryOptions) (*data.GenericAPIResponse, error) { return pf.accountProc.GetESDTTokenData(address, key, options) diff --git a/facade/interface.go b/facade/interface.go index a76d8edc..ac29e844 100644 --- a/facade/interface.go +++ b/facade/interface.go @@ -22,7 +22,6 @@ type AccountProcessor interface { GetAccounts(addresses []string, options common.AccountQueryOptions) (*data.AccountsModel, error) GetShardIDForAddress(address string) (uint32, error) GetValueForKey(address string, key string, options common.AccountQueryOptions) (string, error) - GetTransactions(address string) ([]data.DatabaseTransaction, error) GetAllESDTTokens(address string, options common.AccountQueryOptions) (*data.GenericAPIResponse, error) GetKeyValuePairs(address string, options common.AccountQueryOptions) (*data.GenericAPIResponse, error) GetESDTTokenData(address string, key string, options common.AccountQueryOptions) (*data.GenericAPIResponse, error) diff --git a/facade/mock/accountProccessorStub.go b/facade/mock/accountProccessorStub.go index e50e728c..03c6943e 100644 --- a/facade/mock/accountProccessorStub.go +++ b/facade/mock/accountProccessorStub.go @@ -89,11 +89,6 @@ func (aps *AccountProcessorStub) GetShardIDForAddress(address string) (uint32, e return aps.GetShardIDForAddressCalled(address) } -// GetTransactions - -func (aps *AccountProcessorStub) GetTransactions(address string) ([]data.DatabaseTransaction, error) { - return aps.GetTransactionsCalled(address) -} - // GetCodeHash - func (aps *AccountProcessorStub) GetCodeHash(address string, options common.AccountQueryOptions) (*data.GenericAPIResponse, error) { return aps.GetCodeHashCalled(address, options) diff --git a/process/accountProcessor.go b/process/accountProcessor.go index 22465f38..a749a4f0 100644 --- a/process/accountProcessor.go +++ b/process/accountProcessor.go @@ -452,15 +452,6 @@ func (ap *AccountProcessor) GetGuardianData(address string, options common.Accou return nil, WrapObserversError(apiResponse.Error) } -// GetTransactions resolves the request and returns a slice of transaction for the specific address -func (ap *AccountProcessor) GetTransactions(address string) ([]data.DatabaseTransaction, error) { - if _, err := ap.pubKeyConverter.Decode(address); err != nil { - return nil, fmt.Errorf("%w, %v", ErrInvalidAddress, err) - } - - return ap.connector.GetTransactionsByAddress(address) -} - // GetCodeHash returns the code hash for a given address func (ap *AccountProcessor) GetCodeHash(address string, options common.AccountQueryOptions) (*data.GenericAPIResponse, error) { availability := ap.availabilityProvider.AvailabilityForAccountQueryOptions(options) diff --git a/process/accountProcessor_test.go b/process/accountProcessor_test.go index b06959f2..608c0ebf 100644 --- a/process/accountProcessor_test.go +++ b/process/accountProcessor_test.go @@ -286,26 +286,6 @@ func TestAccountProcessor_GetShardIDForAddressShouldError(t *testing.T) { assert.Equal(t, expectedError, err) } -func TestAccountProcessor_GetTransactions(t *testing.T) { - t.Parallel() - - converter, _ := pubkeyConverter.NewBech32PubkeyConverter(32, "erd") - ap, _ := process.NewAccountProcessor( - &mock.ProcessorStub{}, - converter, - &mock.ElasticSearchConnectorMock{}, - ) - - _, err := ap.GetTransactions("invalidAddress") - assert.True(t, errors.Is(err, process.ErrInvalidAddress)) - - _, err = ap.GetTransactions("") - assert.True(t, errors.Is(err, process.ErrInvalidAddress)) - - _, err = ap.GetTransactions("erd1ycega644rvjtgtyd8hfzt6hl5ymaa8ml2nhhs5cv045cz5vxm00q022myr") - assert.Nil(t, err) -} - func TestAccountProcessor_GetESDTsWithRoleGetObserversFails(t *testing.T) { t.Parallel() diff --git a/process/database/elasticSearchConnector.go b/process/database/elasticSearchConnector.go index bc9e1573..0b6cd4c7 100644 --- a/process/database/elasticSearchConnector.go +++ b/process/database/elasticSearchConnector.go @@ -35,16 +35,6 @@ func NewElasticSearchConnector(url, username, password string) (*elasticSearchCo }, nil } -// GetTransactionsByAddress gets transactions TO or FROM the specified address -func (esc *elasticSearchConnector) GetTransactionsByAddress(address string) ([]data.DatabaseTransaction, error) { - decodedBody, err := esc.doSearchRequestTx(address, "transactions", numTopTransactions) - if err != nil { - return nil, err - } - - return convertObjectToTransactions(decodedBody) -} - // GetAtlasBlockByShardIDAndNonce gets from database a block with the specified shardID and nonce func (esc *elasticSearchConnector) GetAtlasBlockByShardIDAndNonce(shardID uint32, nonce uint64) (data.AtlasBlock, error) { query := blockByNonceAndShardIDQuery(nonce, shardID) diff --git a/process/database/elasticSearchConnector_test.go b/process/database/elasticSearchConnector_test.go index b6d6d991..2b6b1949 100644 --- a/process/database/elasticSearchConnector_test.go +++ b/process/database/elasticSearchConnector_test.go @@ -8,20 +8,6 @@ import ( "github.com/stretchr/testify/require" ) -func TestDatabaseReader(t *testing.T) { - t.Skip("this test queries Elastic Search") - - url := "https://elastic-aws.multiversx.com" - user := "" - password := "" - reader, err := NewElasticSearchConnector(url, user, password) - require.Nil(t, err) - - addr := "erd1ewshdn9yv0wx38xgs5cdhvcq4dz0n7tdlgh8wfj9nxugwmyunnyqpkpzal" - txs, err := reader.GetTransactionsByAddress(addr) - fmt.Println(txs) - require.Nil(t, err) -} func TestDatabaseReader_GetBlockByShardIDAndNonce(t *testing.T) { t.Skip("this test queries Elastic Search") diff --git a/process/interface.go b/process/interface.go index b6762d80..bbfb5932 100644 --- a/process/interface.go +++ b/process/interface.go @@ -31,7 +31,6 @@ type Processor interface { // ExternalStorageConnector defines what a external storage connector should be able to do type ExternalStorageConnector interface { - GetTransactionsByAddress(address string) ([]data.DatabaseTransaction, error) GetAtlasBlockByShardIDAndNonce(shardID uint32, nonce uint64) (data.AtlasBlock, error) IsInterfaceNil() bool } diff --git a/process/mock/elasticSearchConnectorMock.go b/process/mock/elasticSearchConnectorMock.go index ee174772..b6c97769 100644 --- a/process/mock/elasticSearchConnectorMock.go +++ b/process/mock/elasticSearchConnectorMock.go @@ -5,11 +5,6 @@ import "github.com/multiversx/mx-chain-proxy-go/data" type ElasticSearchConnectorMock struct { } -// GetTransactionsByAddress - -func (escm *ElasticSearchConnectorMock) GetTransactionsByAddress(_ string) ([]data.DatabaseTransaction, error) { - return nil, nil -} - // GetAtlasBlockByShardIDAndNonce - func (escm *ElasticSearchConnectorMock) GetAtlasBlockByShardIDAndNonce(_ uint32, _ uint64) (data.AtlasBlock, error) { return data.AtlasBlock{}, nil diff --git a/process/mock/externalStorageConnectorStub.go b/process/mock/externalStorageConnectorStub.go index 43a5873f..febec410 100644 --- a/process/mock/externalStorageConnectorStub.go +++ b/process/mock/externalStorageConnectorStub.go @@ -3,19 +3,9 @@ package mock import "github.com/multiversx/mx-chain-proxy-go/data" type ExternalStorageConnectorStub struct { - GetTransactionsByAddressCalled func(address string) ([]data.DatabaseTransaction, error) GetAtlasBlockByShardIDAndNonceCalled func(shardID uint32, nonce uint64) (data.AtlasBlock, error) } -// GetTransactionsByAddress - -func (e *ExternalStorageConnectorStub) GetTransactionsByAddress(address string) ([]data.DatabaseTransaction, error) { - if e.GetTransactionsByAddressCalled != nil { - return e.GetTransactionsByAddressCalled(address) - } - - return []data.DatabaseTransaction{{Fee: "0"}}, nil -} - // GetAtlasBlockByShardIDAndNonce - func (e *ExternalStorageConnectorStub) GetAtlasBlockByShardIDAndNonce(shardID uint32, nonce uint64) (data.AtlasBlock, error) { if e.GetAtlasBlockByShardIDAndNonceCalled != nil { From 39b655cb2d0706a000ce7e38b38355548303ed4d Mon Sep 17 00:00:00 2001 From: danielailie Date: Thu, 1 Aug 2024 15:59:19 +0300 Subject: [PATCH 24/25] Add empty new line at the and of file --- cmd/proxy/config/swagger/openapi.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/proxy/config/swagger/openapi.json b/cmd/proxy/config/swagger/openapi.json index f27cc0a1..075ef6bc 100644 --- a/cmd/proxy/config/swagger/openapi.json +++ b/cmd/proxy/config/swagger/openapi.json @@ -3239,4 +3239,4 @@ } } } -} \ No newline at end of file +} From e8a085ae8afdd931476e93bb399ce89bc22fd81e Mon Sep 17 00:00:00 2001 From: ssd04 Date: Thu, 1 Aug 2024 16:54:29 +0300 Subject: [PATCH 25/25] fix swagger esdts roles endpoint --- cmd/proxy/config/swagger/openapi.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/proxy/config/swagger/openapi.json b/cmd/proxy/config/swagger/openapi.json index 05c1e5b9..cdcbc189 100644 --- a/cmd/proxy/config/swagger/openapi.json +++ b/cmd/proxy/config/swagger/openapi.json @@ -375,7 +375,7 @@ } } }, - "/address/{address}/esdt/roles": { + "/address/{address}/esdts/roles": { "get": { "tags": [ "address"