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 826a1ae88780ce7bbe7feae280eb239c1eec6d49 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Fri, 5 Apr 2024 09:56:53 +0300 Subject: [PATCH 03/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 fbe7165d56b0d70d7cb06479a564e463fe314680 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Tue, 28 May 2024 16:28:11 +0300 Subject: [PATCH 04/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 3f9f7fc91fdcd4e1f09fb9a346538024781017bb Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 29 May 2024 20:01:39 +0300 Subject: [PATCH 05/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 06/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 07/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 e60a623e288d3c251ca96e2e5080a2d397c7fb4d Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 5 Jun 2024 18:05:33 +0300 Subject: [PATCH 08/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 09/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 10/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 507170f34c61860dcce85d27a43747d44b66f33f Mon Sep 17 00:00:00 2001 From: Daniel Drasovean Date: Mon, 17 Jun 2024 15:04:22 +0300 Subject: [PATCH 11/25] Update actions workflow to support multi-architecture docker image builds --- .github/workflows/deploy-docker.yaml | 45 ++++++++++++++++++---------- docker/Dockerfile | 1 + 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/.github/workflows/deploy-docker.yaml b/.github/workflows/deploy-docker.yaml index da7eeb45..f4479772 100644 --- a/.github/workflows/deploy-docker.yaml +++ b/.github/workflows/deploy-docker.yaml @@ -7,6 +7,7 @@ name: Build Docker image & push on: release: types: [published] + pull_request: jobs: build-docker-image: @@ -17,19 +18,31 @@ jobs: steps: - name: Check out code into the Go module directory - uses: actions/checkout@v3 - - - name: Get the version - id: get_version - run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/} - - - name: Build image - run: | - TAG_VERSION=${{ steps.get_version.outputs.VERSION }} - cd ${GITHUB_WORKSPACE} && docker build -t "${REGISTRY_HOSTNAME}/${IMAGE_NODE}:${TAG_VERSION}" -f ./docker/Dockerfile . - - name: Push image - run: | - docker login --username ${{ secrets.DOCKERHUB_USERNAME }} --password ${{ secrets.DOCKERHUB_TOKEN }} - TAG_VERSION=${{ steps.get_version.outputs.VERSION }} - docker push "${REGISTRY_HOSTNAME}/${IMAGE_NODE}:${TAG_VERSION}" - docker logout + uses: actions/checkout@v4 + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_HOSTNAME }}/${{ env.IMAGE_NODE }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log into Docker Hub + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push image to Docker Hub + id: push + uses: docker/build-push-action@v5 + with: + context: . + file: ./docker/Dockerfile + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/docker/Dockerfile b/docker/Dockerfile index 430e211e..f377e9fb 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,4 +1,5 @@ FROM golang:1.20.7 as builder +LABEL maintainer="multiversx" WORKDIR /mx-chain-proxy-go COPY . . From b28ae65afbe2d0c66ae70f201c210b41c5d8f7a4 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Wed, 19 Jun 2024 17:04:03 +0300 Subject: [PATCH 12/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 13/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 14/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 15/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 16/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 17/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 18/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 19/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 20/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 21/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" From d2dea9c81f5591c4664785e6cc4b731cbf85463d Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 5 Aug 2024 16:37:39 +0300 Subject: [PATCH 22/25] Remove code that serves endpoint /block-atlas --- README.md | 5 - api/apiHandler.go | 6 - api/groups/baseBlockAtlasGroup.go | 58 ------ api/groups/baseBlockAtlasGroup_test.go | 132 ------------- api/groups/baseBlockGroup_test.go | 6 +- api/groups/interface.go | 5 - api/mock/facadeStub.go | 6 - cmd/proxy/config/apiConfig/v1_0.toml | 5 - cmd/proxy/config/apiConfig/v_next.toml | 5 - cmd/proxy/config/external.toml | 4 - cmd/proxy/config/swagger/openapi.json | 82 +-------- cmd/proxy/main.go | 52 +----- config/config.go | 13 -- data/block.go | 8 - facade/baseFacade.go | 6 - facade/interface.go | 1 - facade/mock/blockProcessorStub.go | 6 - go.mod | 1 - go.sum | 2 - process/accountProcessor.go | 7 +- process/accountProcessor_test.go | 29 +-- process/blockProcessor.go | 13 +- process/blockProcessor_test.go | 115 +++++------- .../disabledElasticSearchConnector.go | 30 --- process/database/elasticSearchConnector.go | 173 ------------------ .../database/elasticSearchConnector_test.go | 24 --- process/interface.go | 6 - process/mock/elasticSearchConnectorMock.go | 16 -- process/mock/externalStorageConnectorStub.go | 21 --- 29 files changed, 62 insertions(+), 775 deletions(-) delete mode 100644 api/groups/baseBlockAtlasGroup.go delete mode 100644 api/groups/baseBlockAtlasGroup_test.go delete mode 100644 cmd/proxy/config/external.toml delete mode 100644 process/database/disabledElasticSearchConnector.go delete mode 100644 process/database/elasticSearchConnector.go delete mode 100644 process/database/elasticSearchConnector_test.go delete mode 100644 process/mock/elasticSearchConnectorMock.go delete mode 100644 process/mock/externalStorageConnectorStub.go diff --git a/README.md b/README.md index 5967add5..9262d6c1 100644 --- a/README.md +++ b/README.md @@ -82,11 +82,6 @@ Please note that `altered-accounts` endpoints will only work if the backing obse - `/v1.0/blocks/by-round/:round` (GET) --> returns all blocks by round -### block-atlas - -- `/v1.0/block-atlas/:shard/:nonce` (GET) --> returns a block by nonce, as required by Block Atlas - - ### hyperblock - `/v1.0/hyperblock/by-nonce/:nonce` (GET) --> returns a hyperblock by nonce, with transactions included diff --git a/api/apiHandler.go b/api/apiHandler.go index 87a275aa..4035f8dc 100644 --- a/api/apiHandler.go +++ b/api/apiHandler.go @@ -49,11 +49,6 @@ func initBaseGroupsWithFacade(facade data.FacadeHandler) (map[string]data.GroupH return nil, err } - blockAtlasGroup, err := groups.NewBlockAtlasGroup(facade) - if err != nil { - return nil, err - } - hyperBlocksGroup, err := groups.NewHyperBlockGroup(facade) if err != nil { return nil, err @@ -110,7 +105,6 @@ func initBaseGroupsWithFacade(facade data.FacadeHandler) (map[string]data.GroupH "/block": blockGroup, "/blocks": blocksGroup, "/internal": internalGroup, - "/block-atlas": blockAtlasGroup, "/hyperblock": hyperBlocksGroup, "/network": networkGroup, "/node": nodeGroup, diff --git a/api/groups/baseBlockAtlasGroup.go b/api/groups/baseBlockAtlasGroup.go deleted file mode 100644 index 6cdd40f0..00000000 --- a/api/groups/baseBlockAtlasGroup.go +++ /dev/null @@ -1,58 +0,0 @@ -package groups - -import ( - "net/http" - - "github.com/gin-gonic/gin" - apiErrors "github.com/multiversx/mx-chain-proxy-go/api/errors" - "github.com/multiversx/mx-chain-proxy-go/api/shared" - "github.com/multiversx/mx-chain-proxy-go/data" -) - -type blockAtlasGroup struct { - facade BlockAtlasFacadeHandler - *baseGroup -} - -// NewBlockAtlasGroup returns a new instance of blockAtlasGroup -func NewBlockAtlasGroup(facadeHandler data.FacadeHandler) (*blockAtlasGroup, error) { - facade, ok := facadeHandler.(BlockAtlasFacadeHandler) - if !ok { - return nil, ErrWrongTypeAssertion - } - - bag := &blockAtlasGroup{ - facade: facade, - baseGroup: &baseGroup{}, - } - - baseRoutesHandlers := []*data.EndpointHandlerData{ - {Path: "/:shard/:nonce", Handler: bag.getBlockByShardIDAndNonceFromElastic, Method: http.MethodGet}, - } - bag.baseGroup.endpoints = baseRoutesHandlers - - return bag, nil -} - -// getBlockByShardIDAndNonceFromElastic returns the block by shardID and nonce -func (group *blockAtlasGroup) getBlockByShardIDAndNonceFromElastic(c *gin.Context) { - shardID, err := shared.FetchShardIDFromRequest(c) - if err != nil { - shared.RespondWith(c, http.StatusBadRequest, nil, apiErrors.ErrCannotParseShardID.Error(), data.ReturnCodeRequestError) - return - } - - nonce, err := shared.FetchNonceFromRequest(c) - if err != nil { - shared.RespondWith(c, http.StatusBadRequest, nil, apiErrors.ErrCannotParseNonce.Error(), data.ReturnCodeRequestError) - return - } - - apiBlock, err := group.facade.GetAtlasBlockByShardIDAndNonce(shardID, nonce) - if err != nil { - shared.RespondWith(c, http.StatusInternalServerError, nil, err.Error(), data.ReturnCodeInternalError) - return - } - - shared.RespondWith(c, http.StatusOK, gin.H{"block": apiBlock}, "", data.ReturnCodeSuccess) -} diff --git a/api/groups/baseBlockAtlasGroup_test.go b/api/groups/baseBlockAtlasGroup_test.go deleted file mode 100644 index efb8c6e9..00000000 --- a/api/groups/baseBlockAtlasGroup_test.go +++ /dev/null @@ -1,132 +0,0 @@ -package groups_test - -import ( - "errors" - "net/http" - "net/http/httptest" - "testing" - - apiErrors "github.com/multiversx/mx-chain-proxy-go/api/errors" - "github.com/multiversx/mx-chain-proxy-go/api/groups" - "github.com/multiversx/mx-chain-proxy-go/api/mock" - "github.com/multiversx/mx-chain-proxy-go/data" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" -) - -const blockAtlasPath = "/blockatlas" - -type blockResponseData struct { - Block data.AtlasBlock `json:"block"` -} - -type blockResponse struct { - Data blockResponseData `json:"data"` - Error string `json:"error"` - Code string `json:"code"` -} - -func TestNewBlockAtlasGroup_WrongFacadeShouldErr(t *testing.T) { - wrongFacade := &mock.WrongFacade{} - group, err := groups.NewBlockAtlasGroup(wrongFacade) - require.Nil(t, group) - require.Equal(t, groups.ErrWrongTypeAssertion, err) -} - -func TestGetBlockByShardIDAndNonceFromElastic_FailWhenShardParamIsInvalid(t *testing.T) { - t.Parallel() - - facade := &mock.FacadeStub{} - - baseBlockAtlasGroup, err := groups.NewBlockAtlasGroup(facade) - require.NoError(t, err) - ws := startProxyServer(baseBlockAtlasGroup, blockAtlasPath) - - req, _ := http.NewRequest("GET", "/blockatlas/invalid_shard_id/1", nil) - resp := httptest.NewRecorder() - ws.ServeHTTP(resp, req) - - apiResp := data.GenericAPIResponse{} - loadResponse(resp.Body, &apiResp) - - assert.Equal(t, http.StatusBadRequest, resp.Code) - assert.Empty(t, apiResp.Data) - assert.Equal(t, apiErrors.ErrCannotParseShardID.Error(), apiResp.Error) -} - -func TestGetBlockByShardIDAndNonceFromElastic_FailWhenNonceParamIsInvalid(t *testing.T) { - t.Parallel() - - facade := &mock.FacadeStub{} - baseBlockAtlasGroup, err := groups.NewBlockAtlasGroup(facade) - require.NoError(t, err) - ws := startProxyServer(baseBlockAtlasGroup, blockAtlasPath) - - req, _ := http.NewRequest("GET", "/blockatlas/0/invalid_nonce", nil) - resp := httptest.NewRecorder() - ws.ServeHTTP(resp, req) - - apiResp := data.GenericAPIResponse{} - loadResponse(resp.Body, &apiResp) - - assert.Equal(t, http.StatusBadRequest, resp.Code) - assert.Empty(t, apiResp.Data) - assert.Equal(t, apiErrors.ErrCannotParseNonce.Error(), apiResp.Error) -} - -func TestGetBlockByShardIDAndNonceFromElastic_FailWhenFacadeGetAccountFails(t *testing.T) { - t.Parallel() - - returnedError := errors.New("i am an error") - facade := &mock.FacadeStub{ - GetBlockByShardIDAndNonceHandler: func(_ uint32, _ uint64) (data.AtlasBlock, error) { - return data.AtlasBlock{}, returnedError - }, - } - baseBlockAtlasGroup, err := groups.NewBlockAtlasGroup(facade) - require.NoError(t, err) - ws := startProxyServer(baseBlockAtlasGroup, blockAtlasPath) - - req, _ := http.NewRequest("GET", "/blockatlas/0/1", nil) - resp := httptest.NewRecorder() - ws.ServeHTTP(resp, req) - - apiResp := data.GenericAPIResponse{} - loadResponse(resp.Body, &apiResp) - - assert.Equal(t, http.StatusInternalServerError, resp.Code) - assert.Empty(t, apiResp.Data) - assert.Equal(t, returnedError.Error(), apiResp.Error) -} - -func TestGetBlockByShardIDAndNonceFromElastic_ReturnsSuccessfully(t *testing.T) { - t.Parallel() - - nonce := uint64(37) - hash := "hashhh" - facade := &mock.FacadeStub{ - GetBlockByShardIDAndNonceHandler: func(_ uint32, _ uint64) (data.AtlasBlock, error) { - return data.AtlasBlock{ - Nonce: nonce, - Hash: hash, - }, nil - }, - } - - baseBlockAtlasGroup, err := groups.NewBlockAtlasGroup(facade) - require.NoError(t, err) - ws := startProxyServer(baseBlockAtlasGroup, blockAtlasPath) - - req, _ := http.NewRequest("GET", "/blockatlas/0/1", nil) - resp := httptest.NewRecorder() - ws.ServeHTTP(resp, req) - - apiResp := blockResponse{} - loadResponse(resp.Body, &apiResp) - - assert.Equal(t, http.StatusOK, resp.Code) - assert.Equal(t, apiResp.Data.Block.Nonce, nonce) - assert.Equal(t, apiResp.Data.Block.Hash, hash) - assert.Empty(t, apiResp.Error) - assert.Equal(t, string(data.ReturnCodeSuccess), apiResp.Code) -} diff --git a/api/groups/baseBlockGroup_test.go b/api/groups/baseBlockGroup_test.go index 9e6c17eb..0ab93625 100644 --- a/api/groups/baseBlockGroup_test.go +++ b/api/groups/baseBlockGroup_test.go @@ -18,7 +18,7 @@ import ( "github.com/stretchr/testify/require" ) -const blockPath = "/block" +const blockPath = "/block" func TestNewBlockGroup_WrongFacadeShouldErr(t *testing.T) { wrongFacade := &mock.WrongFacade{} @@ -138,7 +138,7 @@ func TestGetBlockByNonce_ReturnsSuccessfully(t *testing.T) { resp := httptest.NewRecorder() ws.ServeHTTP(resp, req) - apiResp := blockResponse{} + apiResp := data.BlockApiResponse{} loadResponse(resp.Body, &apiResp) assert.Equal(t, http.StatusOK, resp.Code) @@ -258,7 +258,7 @@ func TestGetBlockByHash_ReturnsSuccessfully(t *testing.T) { resp := httptest.NewRecorder() ws.ServeHTTP(resp, req) - apiResp := blockResponse{} + apiResp := data.BlockApiResponse{} loadResponse(resp.Body, &apiResp) assert.Equal(t, http.StatusOK, resp.Code) diff --git a/api/groups/interface.go b/api/groups/interface.go index c97a076b..f5a4e4fd 100644 --- a/api/groups/interface.go +++ b/api/groups/interface.go @@ -49,11 +49,6 @@ type InternalFacadeHandler interface { GetInternalStartOfEpochValidatorsInfo(epoch uint32) (*data.ValidatorsInfoApiResponse, error) } -// BlockAtlasFacadeHandler interface defines methods that can be used from facade context variable -type BlockAtlasFacadeHandler interface { - GetAtlasBlockByShardIDAndNonce(shardID uint32, nonce uint64) (data.AtlasBlock, error) -} - // HyperBlockFacadeHandler defines the actions needed for fetching the hyperblocks from the nodes type HyperBlockFacadeHandler interface { GetHyperBlockByNonce(nonce uint64, options common.HyperblockQueryOptions) (*data.HyperblockApiResponse, error) diff --git a/api/mock/facadeStub.go b/api/mock/facadeStub.go index 27888b72..66417554 100644 --- a/api/mock/facadeStub.go +++ b/api/mock/facadeStub.go @@ -49,7 +49,6 @@ type FacadeStub struct { GetDirectStakedInfoCalled func() (*data.GenericAPIResponse, error) GetDelegatedInfoCalled func() (*data.GenericAPIResponse, error) GetRatingsConfigCalled func() (*data.GenericAPIResponse, error) - GetBlockByShardIDAndNonceHandler func(shardID uint32, nonce uint64) (data.AtlasBlock, error) GetTransactionByHashAndSenderAddressHandler func(txHash string, sndAddr string, withResults bool) (*transaction.ApiTransactionResult, int, error) GetBlockByHashCalled func(shardID uint32, hash string, options common.BlockQueryOptions) (*data.BlockApiResponse, error) GetBlockByNonceCalled func(shardID uint32, nonce uint64, options common.BlockQueryOptions) (*data.BlockApiResponse, error) @@ -443,11 +442,6 @@ func (f *FacadeStub) GetHeartbeatData() (*data.HeartbeatResponse, error) { return f.GetHeartbeatDataHandler() } -// GetAtlasBlockByShardIDAndNonce - -func (f *FacadeStub) GetAtlasBlockByShardIDAndNonce(shardID uint32, nonce uint64) (data.AtlasBlock, error) { - return f.GetBlockByShardIDAndNonceHandler(shardID, nonce) -} - // GetBlockByHash - func (f *FacadeStub) GetBlockByHash(shardID uint32, hash string, options common.BlockQueryOptions) (*data.BlockApiResponse, error) { return f.GetBlockByHashCalled(shardID, hash, options) diff --git a/cmd/proxy/config/apiConfig/v1_0.toml b/cmd/proxy/config/apiConfig/v1_0.toml index 6bfd4d85..f90ee4ae 100644 --- a/cmd/proxy/config/apiConfig/v1_0.toml +++ b/cmd/proxy/config/apiConfig/v1_0.toml @@ -115,11 +115,6 @@ Routes = [ { Name = "/by-round/:round", Secured = false, Open = true, RateLimit = 0 }, ] -[APIPackages.block-atlas] -Routes = [ - { Name = "/:shard/:nonce", Secured = false, Open = true, RateLimit = 0 } -] - [APIPackages.proof] Routes = [ { Name = "/root-hash/:roothash/address/:address", Secured = false, Open = false, RateLimit = 0 }, diff --git a/cmd/proxy/config/apiConfig/v_next.toml b/cmd/proxy/config/apiConfig/v_next.toml index 8fdb4dd1..fbb7c733 100644 --- a/cmd/proxy/config/apiConfig/v_next.toml +++ b/cmd/proxy/config/apiConfig/v_next.toml @@ -115,11 +115,6 @@ Routes = [ { Name = "/by-round/:round", Secured = false, Open = true, RateLimit = 0 }, ] -[APIPackages.block-atlas] -Routes = [ - { Name = "/:shard/:nonce", Secured = false, Open = true, RateLimit = 0 } -] - [APIPackages.proof] Routes = [ { Name = "/root-hash/:roothash/address/:address", Secured = false, Open = false, RateLimit = 0 }, diff --git a/cmd/proxy/config/external.toml b/cmd/proxy/config/external.toml deleted file mode 100644 index 9bc54b1a..00000000 --- a/cmd/proxy/config/external.toml +++ /dev/null @@ -1,4 +0,0 @@ -# ElasticSearchConnector defines settings related to ElasticSearch such as login information or URL -[ElasticSearchConnector] - Enabled = false - URL = "" diff --git a/cmd/proxy/config/swagger/openapi.json b/cmd/proxy/config/swagger/openapi.json index 75f33e76..dad65efa 100644 --- a/cmd/proxy/config/swagger/openapi.json +++ b/cmd/proxy/config/swagger/openapi.json @@ -574,86 +574,6 @@ } } }, - "/block-atlas/{shard}/{nonce}": { - "get": { - "tags": [ - "block-atlas" - ], - "summary": "get a block from a specified shard and at a specified nonce", - "parameters": [ - { - "name": "shard", - "in": "path", - "description": "the shard ID to look after", - "required": true, - "schema": { - "type": "integer" - } - }, - { - "name": "nonce", - "in": "path", - "description": "the nonce to look after", - "required": true, - "schema": { - "type": "integer" - } - } - ], - "responses": { - "200": { - "description": "successful operation", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/GenericResponse" - } - } - } - } - } - } - }, - "/block-atlas/{shard}/by-hash/{hash}": { - "get": { - "tags": [ - "block" - ], - "summary": "get a block from a specified shard and with a specified hash", - "parameters": [ - { - "name": "shard", - "in": "path", - "description": "the shard ID to look after", - "required": true, - "schema": { - "type": "integer" - } - }, - { - "name": "hash", - "in": "path", - "description": "the hash to look after", - "required": true, - "schema": { - "type": "string" - } - } - ], - "responses": { - "200": { - "description": "successful operation", - "content": { - "application/json": { - "schema": { - "$ref": "#/components/schemas/GenericResponse" - } - } - } - } - } - } - }, "/blocks/by-round/{round}": { "get": { "tags": [ @@ -3239,4 +3159,4 @@ } } } -} +} \ No newline at end of file diff --git a/cmd/proxy/main.go b/cmd/proxy/main.go index d32470a1..2e1b1af2 100644 --- a/cmd/proxy/main.go +++ b/cmd/proxy/main.go @@ -27,7 +27,6 @@ import ( "github.com/multiversx/mx-chain-proxy-go/observer" "github.com/multiversx/mx-chain-proxy-go/process" "github.com/multiversx/mx-chain-proxy-go/process/cache" - "github.com/multiversx/mx-chain-proxy-go/process/database" processFactory "github.com/multiversx/mx-chain-proxy-go/process/factory" "github.com/multiversx/mx-chain-proxy-go/testing" versionsFactory "github.com/multiversx/mx-chain-proxy-go/versions/factory" @@ -105,13 +104,6 @@ VERSION: Usage: "This represents the path of the walletKey.pem file", Value: "./config/walletKey.pem", } - // externalConfigFile defines a flag for the path to the external toml configuration file - externalConfigFile = cli.StringFlag{ - Name: "config-external", - Usage: "The path for the external configuration file. This TOML file contains" + - " external configurations such as ElasticSearch's URL and login information", - Value: "./config/external.toml", - } // credentialsConfigFile defines a flag for the path to the credentials toml configuration file credentialsConfigFile = cli.StringFlag{ @@ -182,7 +174,6 @@ func main() { app.Usage = "This is the entry point for starting a new Multiversx node proxy" app.Flags = []cli.Flag{ configurationFile, - externalConfigFile, credentialsConfigFile, apiConfigDirectory, profileMode, @@ -271,12 +262,6 @@ func startProxy(ctx *cli.Context) error { } log.Info(fmt.Sprintf("Initialized with main config from: %s", configurationFile)) - externalConfigurationFileName := ctx.GlobalString(externalConfigFile.Name) - externalConfig, err := loadExternalConfig(externalConfigurationFileName) - if err != nil { - return err - } - closableComponents := data.NewClosableComponentsHandler() credentialsConfigurationFileName := ctx.GlobalString(credentialsConfigFile.Name) @@ -288,7 +273,7 @@ func startProxy(ctx *cli.Context) error { statusMetricsProvider := metrics.NewStatusMetrics() shouldStartSwaggerUI := ctx.GlobalBool(startSwaggerUI.Name) - versionsRegistry, err := createVersionsRegistryTestOrProduction(ctx, generalConfig, configurationFileName, externalConfig, statusMetricsProvider, closableComponents) + versionsRegistry, err := createVersionsRegistryTestOrProduction(ctx, generalConfig, configurationFileName, statusMetricsProvider, closableComponents) if err != nil { return err } @@ -318,21 +303,10 @@ func loadMainConfig(filepath string) (*config.Config, error) { return cfg, nil } -func loadExternalConfig(filepath string) (*config.ExternalConfig, error) { - cfg := &config.ExternalConfig{} - err := core.LoadTomlFile(cfg, filepath) - if err != nil { - return nil, err - } - - return cfg, nil -} - func createVersionsRegistryTestOrProduction( ctx *cli.Context, cfg *config.Config, configurationFilePath string, - exCfg *config.ExternalConfig, statusMetricsHandler data.StatusMetricsProvider, closableComponents *data.ClosableComponentsHandler, ) (data.VersionsRegistryHandler, error) { @@ -395,7 +369,6 @@ func createVersionsRegistryTestOrProduction( return createVersionsRegistry( testCfg, configurationFilePath, - exCfg, statusMetricsHandler, ctx.GlobalString(walletKeyPemFile.Name), ctx.GlobalString(apiConfigDirectory.Name), @@ -406,7 +379,6 @@ func createVersionsRegistryTestOrProduction( return createVersionsRegistry( cfg, configurationFilePath, - exCfg, statusMetricsHandler, ctx.GlobalString(walletKeyPemFile.Name), ctx.GlobalString(apiConfigDirectory.Name), @@ -417,7 +389,6 @@ func createVersionsRegistryTestOrProduction( func createVersionsRegistry( cfg *config.Config, configurationFilePath string, - exCfg *config.ExternalConfig, statusMetricsHandler data.StatusMetricsProvider, pemFileLocation string, apiConfigDirectoryPath string, @@ -471,12 +442,7 @@ func createVersionsRegistry( } bp.StartNodesSyncStateChecks() - connector, err := createElasticSearchConnector(exCfg) - if err != nil { - return nil, err - } - - accntProc, err := process.NewAccountProcessor(bp, pubKeyConverter, connector) + accntProc, err := process.NewAccountProcessor(bp, pubKeyConverter) if err != nil { return nil, err } @@ -534,7 +500,7 @@ func createVersionsRegistry( valStatsProc.StartCacheUpdate() nodeStatusProc.StartCacheUpdate() - blockProc, err := process.NewBlockProcessor(connector, bp) + blockProc, err := process.NewBlockProcessor(bp) if err != nil { return nil, err } @@ -590,18 +556,6 @@ func createVersionsRegistry( return versionsFactory.CreateVersionsRegistry(facadeArgs, apiConfigParser) } -func createElasticSearchConnector(exCfg *config.ExternalConfig) (process.ExternalStorageConnector, error) { - if !exCfg.ElasticSearchConnector.Enabled { - return database.NewDisabledElasticSearchConnector(), nil - } - - return database.NewElasticSearchConnector( - exCfg.ElasticSearchConnector.URL, - exCfg.ElasticSearchConnector.Username, - exCfg.ElasticSearchConnector.Password, - ) -} - func getShardCoordinator(cfg *config.Config) (common.Coordinator, error) { maxShardID := uint32(0) for _, obs := range cfg.Observers { diff --git a/config/config.go b/config/config.go index b5d23613..5cd581b4 100644 --- a/config/config.go +++ b/config/config.go @@ -52,16 +52,3 @@ type CredentialsConfig struct { Credentials []data.Credential Hasher TypeConfig } - -// ExternalConfig will hold the configurations for external tools, such as Explorer or Elastic Search -type ExternalConfig struct { - ElasticSearchConnector ElasticSearchConfig -} - -// ElasticSearchConfig will hold the configuration for the elastic search -type ElasticSearchConfig struct { - Enabled bool - URL string - Username string - Password string -} diff --git a/data/block.go b/data/block.go index 1c213a26..ac70eb0c 100644 --- a/data/block.go +++ b/data/block.go @@ -5,14 +5,6 @@ import ( "github.com/multiversx/mx-chain-core-go/data/api" ) -// AtlasBlock is a block, as required by BlockAtlas -// Will be removed when using the "hyperblock" route in BlockAtlas as well. -type AtlasBlock struct { - Nonce uint64 `form:"nonce" json:"nonce"` - Hash string `form:"hash" json:"hash"` - Transactions []DatabaseTransaction `form:"transactions" json:"transactions"` -} - // BlockApiResponse is a response holding a block type BlockApiResponse struct { Data BlockApiResponsePayload `json:"data"` diff --git a/facade/baseFacade.go b/facade/baseFacade.go index 525937d7..3dd96691 100644 --- a/facade/baseFacade.go +++ b/facade/baseFacade.go @@ -17,7 +17,6 @@ var _ groups.ActionsFacadeHandler = (*ProxyFacade)(nil) var _ groups.AccountsFacadeHandler = (*ProxyFacade)(nil) var _ groups.BlockFacadeHandler = (*ProxyFacade)(nil) var _ groups.BlocksFacadeHandler = (*ProxyFacade)(nil) -var _ groups.BlockAtlasFacadeHandler = (*ProxyFacade)(nil) var _ groups.HyperBlockFacadeHandler = (*ProxyFacade)(nil) var _ groups.NetworkFacadeHandler = (*ProxyFacade)(nil) var _ groups.NodeFacadeHandler = (*ProxyFacade)(nil) @@ -416,11 +415,6 @@ func (epf *ProxyFacade) AuctionList() ([]*data.AuctionListValidatorAPIResponse, return auctionList.AuctionListValidators, nil } -// GetAtlasBlockByShardIDAndNonce returns block by shardID and nonce in a BlockAtlas-friendly-format -func (pf *ProxyFacade) GetAtlasBlockByShardIDAndNonce(shardID uint32, nonce uint64) (data.AtlasBlock, error) { - return pf.blockProc.GetAtlasBlockByShardIDAndNonce(shardID, nonce) -} - // GetAddressConverter returns the address converter func (pf *ProxyFacade) GetAddressConverter() (core.PubkeyConverter, error) { return pf.pubKeyConverter, nil diff --git a/facade/interface.go b/facade/interface.go index ac29e844..9ed6c19c 100644 --- a/facade/interface.go +++ b/facade/interface.go @@ -107,7 +107,6 @@ type BlocksProcessor interface { // BlockProcessor defines what a block processor should do type BlockProcessor interface { - GetAtlasBlockByShardIDAndNonce(shardID uint32, nonce uint64) (data.AtlasBlock, error) GetBlockByHash(shardID uint32, hash string, options common.BlockQueryOptions) (*data.BlockApiResponse, error) GetBlockByNonce(shardID uint32, nonce uint64, options common.BlockQueryOptions) (*data.BlockApiResponse, error) GetHyperBlockByHash(hash string, options common.HyperblockQueryOptions) (*data.HyperblockApiResponse, error) diff --git a/facade/mock/blockProcessorStub.go b/facade/mock/blockProcessorStub.go index 08b09f2b..87d8702a 100644 --- a/facade/mock/blockProcessorStub.go +++ b/facade/mock/blockProcessorStub.go @@ -7,7 +7,6 @@ import ( // BlockProcessorStub - type BlockProcessorStub struct { - GetBlockByShardIDAndNonceCalled func(shardID uint32, nonce uint64) (data.AtlasBlock, error) GetBlockByHashCalled func(shardID uint32, hash string, options common.BlockQueryOptions) (*data.BlockApiResponse, error) GetBlockByNonceCalled func(shardID uint32, nonce uint64, options common.BlockQueryOptions) (*data.BlockApiResponse, error) GetHyperBlockByHashCalled func(hash string, options common.HyperblockQueryOptions) (*data.HyperblockApiResponse, error) @@ -27,11 +26,6 @@ func (bps *BlockProcessorStub) GetBlockByNonce(shardID uint32, nonce uint64, opt return bps.GetBlockByNonceCalled(shardID, nonce, options) } -// GetAtlasBlockByShardIDAndNonce - -func (bps *BlockProcessorStub) GetAtlasBlockByShardIDAndNonce(shardID uint32, nonce uint64) (data.AtlasBlock, error) { - return bps.GetBlockByShardIDAndNonceCalled(shardID, nonce) -} - // GetHyperBlockByHash - func (bps *BlockProcessorStub) GetHyperBlockByHash(hash string, options common.HyperblockQueryOptions) (*data.HyperblockApiResponse, error) { if bps.GetHyperBlockByHashCalled != nil { diff --git a/go.mod b/go.mod index fbb90512..1bd7ba8f 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,6 @@ module github.com/multiversx/mx-chain-proxy-go go 1.20 require ( - github.com/elastic/go-elasticsearch/v7 v7.12.0 github.com/gin-contrib/cors v1.4.0 github.com/gin-contrib/pprof v1.4.0 github.com/gin-contrib/static v0.0.1 diff --git a/go.sum b/go.sum index 3ff90b70..ea5cead0 100644 --- a/go.sum +++ b/go.sum @@ -39,8 +39,6 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeC github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218= github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ= github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI= -github.com/elastic/go-elasticsearch/v7 v7.12.0 h1:j4tvcMrZJLp39L2NYvBb7f+lHKPqPHSL3nvB8+/DV+s= -github.com/elastic/go-elasticsearch/v7 v7.12.0/go.mod h1:OJ4wdbtDNk5g503kvlHLyErCgQwwzmDtaFC4XyOxXA4= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= diff --git a/process/accountProcessor.go b/process/accountProcessor.go index a749a4f0..3846b22e 100644 --- a/process/accountProcessor.go +++ b/process/accountProcessor.go @@ -18,28 +18,23 @@ const addressPath = "/address/" // AccountProcessor is able to process account requests type AccountProcessor struct { - connector ExternalStorageConnector proc Processor pubKeyConverter core.PubkeyConverter availabilityProvider availabilityCommon.AvailabilityProvider } // NewAccountProcessor creates a new instance of AccountProcessor -func NewAccountProcessor(proc Processor, pubKeyConverter core.PubkeyConverter, connector ExternalStorageConnector) (*AccountProcessor, error) { +func NewAccountProcessor(proc Processor, pubKeyConverter core.PubkeyConverter) (*AccountProcessor, error) { if check.IfNil(proc) { return nil, ErrNilCoreProcessor } if check.IfNil(pubKeyConverter) { return nil, ErrNilPubKeyConverter } - if check.IfNil(connector) { - return nil, ErrNilDatabaseConnector - } return &AccountProcessor{ proc: proc, pubKeyConverter: pubKeyConverter, - connector: connector, availabilityProvider: availabilityCommon.AvailabilityProvider{}, }, nil } diff --git a/process/accountProcessor_test.go b/process/accountProcessor_test.go index 608c0ebf..312b2fc2 100644 --- a/process/accountProcessor_test.go +++ b/process/accountProcessor_test.go @@ -12,7 +12,6 @@ import ( "github.com/multiversx/mx-chain-proxy-go/common" "github.com/multiversx/mx-chain-proxy-go/data" "github.com/multiversx/mx-chain-proxy-go/process" - "github.com/multiversx/mx-chain-proxy-go/process/database" "github.com/multiversx/mx-chain-proxy-go/process/mock" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -21,7 +20,7 @@ import ( func TestNewAccountProcessor_NilCoreProcessorShouldErr(t *testing.T) { t.Parallel() - ap, err := process.NewAccountProcessor(nil, &mock.PubKeyConverterMock{}, database.NewDisabledElasticSearchConnector()) + ap, err := process.NewAccountProcessor(nil, &mock.PubKeyConverterMock{}) assert.Nil(t, ap) assert.Equal(t, process.ErrNilCoreProcessor, err) @@ -30,7 +29,7 @@ func TestNewAccountProcessor_NilCoreProcessorShouldErr(t *testing.T) { func TestNewAccountProcessor_NilPubKeyConverterShouldErr(t *testing.T) { t.Parallel() - ap, err := process.NewAccountProcessor(&mock.ProcessorStub{}, nil, database.NewDisabledElasticSearchConnector()) + ap, err := process.NewAccountProcessor(&mock.ProcessorStub{}, nil) assert.Nil(t, ap) assert.Equal(t, process.ErrNilPubKeyConverter, err) @@ -39,7 +38,7 @@ func TestNewAccountProcessor_NilPubKeyConverterShouldErr(t *testing.T) { func TestNewAccountProcessor_WithCoreProcessorShouldWork(t *testing.T) { t.Parallel() - ap, err := process.NewAccountProcessor(&mock.ProcessorStub{}, &mock.PubKeyConverterMock{}, database.NewDisabledElasticSearchConnector()) + ap, err := process.NewAccountProcessor(&mock.ProcessorStub{}, &mock.PubKeyConverterMock{}) assert.NotNil(t, ap) assert.Nil(t, err) @@ -50,7 +49,7 @@ func TestNewAccountProcessor_WithCoreProcessorShouldWork(t *testing.T) { func TestAccountProcessor_GetAccountInvalidHexAddressShouldErr(t *testing.T) { t.Parallel() - ap, _ := process.NewAccountProcessor(&mock.ProcessorStub{}, &mock.PubKeyConverterMock{}, database.NewDisabledElasticSearchConnector()) + ap, _ := process.NewAccountProcessor(&mock.ProcessorStub{}, &mock.PubKeyConverterMock{}) accnt, err := ap.GetAccount("invalid hex number", common.AccountQueryOptions{}) assert.Nil(t, accnt) @@ -69,7 +68,6 @@ func TestAccountProcessor_GetAccountComputeShardIdFailsShouldErr(t *testing.T) { }, }, &mock.PubKeyConverterMock{}, - database.NewDisabledElasticSearchConnector(), ) address := "DEADBEEF" accnt, err := ap.GetAccount(address, common.AccountQueryOptions{}) @@ -92,7 +90,6 @@ func TestAccountProcessor_GetAccountGetObserversFailsShouldErr(t *testing.T) { }, }, &mock.PubKeyConverterMock{}, - database.NewDisabledElasticSearchConnector(), ) address := "DEADBEEF" accnt, err := ap.GetAccount(address, common.AccountQueryOptions{}) @@ -121,7 +118,6 @@ func TestAccountProcessor_GetAccountSendingFailsOnAllObserversShouldErr(t *testi }, }, &mock.PubKeyConverterMock{}, - database.NewDisabledElasticSearchConnector(), ) address := "DEADBEEF" accnt, err := ap.GetAccount(address, common.AccountQueryOptions{}) @@ -162,7 +158,6 @@ func TestAccountProcessor_GetAccountSendingFailsOnFirstObserverShouldStillSend(t }, }, &mock.PubKeyConverterMock{}, - database.NewDisabledElasticSearchConnector(), ) address := "DEADBEEF" accountModel, err := ap.GetAccount(address, common.AccountQueryOptions{}) @@ -192,7 +187,6 @@ func TestAccountProcessor_GetValueForAKeyShouldWork(t *testing.T) { }, }, &mock.PubKeyConverterMock{}, - database.NewDisabledElasticSearchConnector(), ) key := "key" @@ -221,7 +215,6 @@ func TestAccountProcessor_GetValueForAKeyShouldError(t *testing.T) { }, }, &mock.PubKeyConverterMock{}, - database.NewDisabledElasticSearchConnector(), ) key := "key" @@ -255,7 +248,6 @@ func TestAccountProcessor_GetShardIForAddressShouldWork(t *testing.T) { }, }, bech32C, - database.NewDisabledElasticSearchConnector(), ) shardID, err := ap.GetShardIDForAddress(addressShard1) @@ -278,7 +270,6 @@ func TestAccountProcessor_GetShardIDForAddressShouldError(t *testing.T) { }, }, &mock.PubKeyConverterMock{}, - database.NewDisabledElasticSearchConnector(), ) shardID, err := ap.GetShardIDForAddress("aaaa") @@ -297,7 +288,6 @@ func TestAccountProcessor_GetESDTsWithRoleGetObserversFails(t *testing.T) { }, }, &mock.PubKeyConverterMock{}, - &mock.ElasticSearchConnectorMock{}, ) result, err := ap.GetESDTsWithRole("address", "role", common.AccountQueryOptions{}) @@ -325,7 +315,6 @@ func TestAccountProcessor_GetESDTsWithRoleApiCallFails(t *testing.T) { }, }, &mock.PubKeyConverterMock{}, - &mock.ElasticSearchConnectorMock{}, ) result, err := ap.GetESDTsWithRole("address", "role", common.AccountQueryOptions{}) @@ -354,7 +343,6 @@ func TestAccountProcessor_GetESDTsWithRoleShouldWork(t *testing.T) { }, }, &mock.PubKeyConverterMock{}, - database.NewDisabledElasticSearchConnector(), ) address := "DEADBEEF" response, err := ap.GetESDTsWithRole(address, "role", common.AccountQueryOptions{}) @@ -373,7 +361,6 @@ func TestAccountProcessor_GetESDTsRolesGetObserversFails(t *testing.T) { }, }, &mock.PubKeyConverterMock{}, - &mock.ElasticSearchConnectorMock{}, ) result, err := ap.GetESDTsRoles("address", common.AccountQueryOptions{}) @@ -401,7 +388,6 @@ func TestAccountProcessor_GetESDTsRolesApiCallFails(t *testing.T) { }, }, &mock.PubKeyConverterMock{}, - &mock.ElasticSearchConnectorMock{}, ) result, err := ap.GetESDTsRoles("address", common.AccountQueryOptions{}) @@ -430,7 +416,6 @@ func TestAccountProcessor_GetESDTsRolesShouldWork(t *testing.T) { }, }, &mock.PubKeyConverterMock{}, - database.NewDisabledElasticSearchConnector(), ) address := "DEADBEEF" response, err := ap.GetESDTsRoles(address, common.AccountQueryOptions{}) @@ -458,7 +443,6 @@ func TestAccountProcessor_GetCodeHash(t *testing.T) { }, }, &mock.PubKeyConverterMock{}, - database.NewDisabledElasticSearchConnector(), ) address := "DEADBEEF" response, err := ap.GetCodeHash(address, common.AccountQueryOptions{}) @@ -477,7 +461,6 @@ func TestAccountProcessor_IsDataTrieMigrated(t *testing.T) { }, }, &mock.PubKeyConverterMock{}, - &mock.ElasticSearchConnectorMock{}, ) result, err := ap.IsDataTrieMigrated("address", common.AccountQueryOptions{}) @@ -505,7 +488,6 @@ func TestAccountProcessor_IsDataTrieMigrated(t *testing.T) { }, }, &mock.PubKeyConverterMock{}, - &mock.ElasticSearchConnectorMock{}, ) result, err := ap.IsDataTrieMigrated("DEADBEEF", common.AccountQueryOptions{}) @@ -535,7 +517,6 @@ func TestAccountProcessor_IsDataTrieMigrated(t *testing.T) { }, }, &mock.PubKeyConverterMock{}, - &mock.ElasticSearchConnectorMock{}, ) result, err := ap.IsDataTrieMigrated("DEADBEEF", common.AccountQueryOptions{}) @@ -582,7 +563,6 @@ func TestAccountProcessor_GetAccounts(t *testing.T) { }, }, &mock.PubKeyConverterMock{}, - &mock.ElasticSearchConnectorMock{}, ) result, err := ap.GetAccounts([]string{"aabb", "bbaa"}, common.AccountQueryOptions{}) @@ -628,7 +608,6 @@ func TestAccountProcessor_GetAccounts(t *testing.T) { }, }, &mock.PubKeyConverterMock{}, - &mock.ElasticSearchConnectorMock{}, ) result, err := ap.GetAccounts([]string{"aabb", "bbaa"}, common.AccountQueryOptions{}) diff --git a/process/blockProcessor.go b/process/blockProcessor.go index 63388e37..63dfaedd 100644 --- a/process/blockProcessor.go +++ b/process/blockProcessor.go @@ -38,29 +38,20 @@ const ( // BlockProcessor handles blocks retrieving type BlockProcessor struct { proc Processor - dbReader ExternalStorageConnector } // NewBlockProcessor will create a new block processor -func NewBlockProcessor(dbReader ExternalStorageConnector, proc Processor) (*BlockProcessor, error) { - if check.IfNil(dbReader) { - return nil, ErrNilDatabaseConnector - } +func NewBlockProcessor(proc Processor) (*BlockProcessor, error) { if check.IfNil(proc) { return nil, ErrNilCoreProcessor } return &BlockProcessor{ - dbReader: dbReader, proc: proc, }, nil } -// GetAtlasBlockByShardIDAndNonce return the block byte shardID and nonce -func (bp *BlockProcessor) GetAtlasBlockByShardIDAndNonce(shardID uint32, nonce uint64) (data.AtlasBlock, error) { - return bp.dbReader.GetAtlasBlockByShardIDAndNonce(shardID, nonce) -} - + // GetBlockByHash will return the block based on its hash func (bp *BlockProcessor) GetBlockByHash(shardID uint32, hash string, options common.BlockQueryOptions) (*data.BlockApiResponse, error) { observers, err := bp.getObserversOrFullHistoryNodes(shardID) diff --git a/process/blockProcessor_test.go b/process/blockProcessor_test.go index 146deef1..2451f03b 100644 --- a/process/blockProcessor_test.go +++ b/process/blockProcessor_test.go @@ -18,18 +18,10 @@ import ( "github.com/stretchr/testify/require" ) -func TestNewBlockProcessor_NilExternalStorageConnectorShouldErr(t *testing.T) { - t.Parallel() - - bp, err := process.NewBlockProcessor(nil, &mock.ProcessorStub{}) - require.Nil(t, bp) - require.Equal(t, process.ErrNilDatabaseConnector, err) -} - func TestNewBlockProcessor_NilProcessorShouldErr(t *testing.T) { t.Parallel() - bp, err := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, nil) + bp, err := process.NewBlockProcessor(nil) require.Nil(t, bp) require.Equal(t, process.ErrNilCoreProcessor, err) } @@ -37,22 +29,11 @@ func TestNewBlockProcessor_NilProcessorShouldErr(t *testing.T) { func TestNewBlockProcessor_ShouldWork(t *testing.T) { t.Parallel() - bp, err := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, &mock.ProcessorStub{}) + bp, err := process.NewBlockProcessor(&mock.ProcessorStub{}) require.NotNil(t, bp) require.NoError(t, err) } -func TestBlockProcessor_GetAtlasBlockByShardIDAndNonce(t *testing.T) { - t.Parallel() - - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, &mock.ProcessorStub{}) - require.NotNil(t, bp) - - res, err := bp.GetAtlasBlockByShardIDAndNonce(0, 1) - require.NoError(t, err) - require.NotNil(t, res) -} - func TestBlockProcessor_GetBlockByHashShouldGetFullHistoryNodes(t *testing.T) { t.Parallel() @@ -70,7 +51,7 @@ func TestBlockProcessor_GetBlockByHashShouldGetFullHistoryNodes(t *testing.T) { }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) _, _ = bp.GetBlockByHash(0, "hash", common.BlockQueryOptions{}) @@ -96,7 +77,7 @@ func TestBlockProcessor_GetBlockByHashShouldGetObservers(t *testing.T) { }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) _, _ = bp.GetBlockByHash(0, "hash", common.BlockQueryOptions{}) @@ -118,7 +99,7 @@ func TestBlockProcessor_GetBlockByHashNoFullNodesOrObserversShouldErr(t *testing }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) res, err := bp.GetBlockByHash(0, "hash", common.BlockQueryOptions{}) @@ -139,7 +120,7 @@ func TestBlockProcessor_GetBlockByHashCallGetFailsShouldErr(t *testing.T) { }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) res, err := bp.GetBlockByHash(0, "hash", common.BlockQueryOptions{}) @@ -162,7 +143,7 @@ func TestBlockProcessor_GetBlockByHashShouldWork(t *testing.T) { }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) res, err := bp.GetBlockByHash(0, "hash", common.BlockQueryOptions{}) @@ -190,7 +171,7 @@ func TestBlockProcessor_GetBlockByHashShouldWorkAndIncludeAlsoTxs(t *testing.T) }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) res, err := bp.GetBlockByHash(0, "hash", common.BlockQueryOptions{WithTransactions: true}) @@ -219,7 +200,7 @@ func TestBlockProcessor_GetBlockByNonceShouldGetFullHistoryNodes(t *testing.T) { }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) _, _ = bp.GetBlockByNonce(0, 0, common.BlockQueryOptions{}) @@ -245,7 +226,7 @@ func TestBlockProcessor_GetBlockByNonceShouldGetObservers(t *testing.T) { }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) _, _ = bp.GetBlockByNonce(0, 1, common.BlockQueryOptions{}) @@ -267,7 +248,7 @@ func TestBlockProcessor_GetBlockByNonceNoFullNodesOrObserversShouldErr(t *testin }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) res, err := bp.GetBlockByNonce(0, 1, common.BlockQueryOptions{}) @@ -288,7 +269,7 @@ func TestBlockProcessor_GetBlockByNonceCallGetFailsShouldErr(t *testing.T) { }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) res, err := bp.GetBlockByNonce(0, 0, common.BlockQueryOptions{}) @@ -311,7 +292,7 @@ func TestBlockProcessor_GetBlockByNonceShouldWork(t *testing.T) { }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) res, err := bp.GetBlockByNonce(0, nonce, common.BlockQueryOptions{}) @@ -339,7 +320,7 @@ func TestBlockProcessor_GetBlockByNonceShouldWorkAndIncludeAlsoTxs(t *testing.T) }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) res, err := bp.GetBlockByNonce(0, 3, common.BlockQueryOptions{WithTransactions: true}) @@ -378,7 +359,7 @@ func TestBlockProcessor_GetHyperBlock(t *testing.T) { }, } - processor, err := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + processor, err := process.NewBlockProcessor(proc) require.Nil(t, err) require.NotNil(t, processor) @@ -410,7 +391,7 @@ func TestBlockProcessor_GetInternalBlockByNonceInvalidOutputFormat_ShouldFail(t }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) blk, err := bp.GetInternalBlockByNonce(0, 0, 2) @@ -435,7 +416,7 @@ func TestBlockProcessor_GetInternalBlockByNonceShouldGetFullHistoryNodes(t *test }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) _, _ = bp.GetInternalBlockByNonce(0, 0, common.Internal) @@ -461,7 +442,7 @@ func TestBlockProcessor_GetInternalBlockByNonceShouldGetObservers(t *testing.T) }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) _, _ = bp.GetInternalBlockByNonce(0, 1, common.Internal) @@ -483,7 +464,7 @@ func TestBlockProcessor_GetInternalBlockByNonceNoFullNodesOrObserversShouldErr(t }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) res, err := bp.GetInternalBlockByNonce(0, 1, common.Internal) @@ -504,7 +485,7 @@ func TestBlockProcessor_GetInternalBlockByNonceCallGetFailsShouldErr(t *testing. }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) res, err := bp.GetInternalBlockByNonce(0, 0, common.Internal) @@ -533,7 +514,7 @@ func TestBlockProcessor_GetInternalBlockByNonceShouldWork(t *testing.T) { }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) res, err := bp.GetInternalBlockByNonce(0, nonce, common.Internal) @@ -558,7 +539,7 @@ func TestBlockProcessor_GetInternalBlockByHashInvalidOutputFormat_ShouldFail(t * }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) blk, err := bp.GetInternalBlockByHash(0, "aaaa", 2) @@ -583,7 +564,7 @@ func TestBlockProcessor_GetInternalBlockByHashShouldGetFullHistoryNodes(t *testi }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) _, _ = bp.GetInternalBlockByHash(0, "aaaa", common.Internal) @@ -609,7 +590,7 @@ func TestBlockProcessor_GetInternalBlockByHashShouldGetObservers(t *testing.T) { }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) _, _ = bp.GetInternalBlockByHash(0, "aaaa", common.Internal) @@ -631,7 +612,7 @@ func TestBlockProcessor_GetInternalBlockByHashNoFullNodesOrObserversShouldErr(t }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) res, err := bp.GetInternalBlockByHash(0, "aaaa", common.Internal) @@ -652,7 +633,7 @@ func TestBlockProcessor_GetInternalBlockByHashCallGetFailsShouldErr(t *testing.T }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) res, err := bp.GetInternalBlockByHash(0, "aaaa", common.Internal) @@ -680,7 +661,7 @@ func TestBlockProcessor_GetInternalBlockByHashShouldWork(t *testing.T) { }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) res, err := bp.GetInternalBlockByHash(0, "aaaa", common.Internal) @@ -705,7 +686,7 @@ func TestBlockProcessor_GetInternalMiniBlockByHashInvalidOutputFormat_ShouldFail }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) blk, err := bp.GetInternalMiniBlockByHash(0, "aaaa", 1, 2) @@ -730,7 +711,7 @@ func TestBlockProcessor_GetInternalMiniBlockByHashShouldGetFullHistoryNodes(t *t }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) _, _ = bp.GetInternalMiniBlockByHash(0, "aaaa", 1, common.Internal) @@ -756,7 +737,7 @@ func TestBlockProcessor_GetInternalMiniBlockByHashShouldGetObservers(t *testing. }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) _, _ = bp.GetInternalMiniBlockByHash(0, "aaaa", 1, common.Internal) @@ -778,7 +759,7 @@ func TestBlockProcessor_GetInternalMiniBlockByHashNoFullNodesOrObserversShouldEr }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) res, err := bp.GetInternalMiniBlockByHash(0, "aaaa", 1, common.Internal) @@ -799,7 +780,7 @@ func TestBlockProcessor_GetInternalMiniBlockByHashCallGetFailsShouldErr(t *testi }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) res, err := bp.GetInternalMiniBlockByHash(0, "aaaa", 1, common.Internal) @@ -827,7 +808,7 @@ func TestBlockProcessor_GetInternalMiniBlockByHashShouldWork(t *testing.T) { }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) res, err := bp.GetInternalMiniBlockByHash(0, "aaaa", 1, common.Internal) @@ -852,7 +833,7 @@ func TestBlockProcessor_GetInternalStartOfEpochMetaBlockInvalidOutputFormat_Shou }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) blk, err := bp.GetInternalStartOfEpochMetaBlock(0, 2) @@ -877,7 +858,7 @@ func TestBlockProcessor_GetInternalStartOfEpochMetaBlockShouldGetFullHistoryNode }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) _, _ = bp.GetInternalStartOfEpochMetaBlock(0, common.Internal) @@ -903,7 +884,7 @@ func TestBlockProcessor_GetInternalStartOfEpochMetaBlockShouldGetObservers(t *te }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) _, _ = bp.GetInternalStartOfEpochMetaBlock(0, common.Internal) @@ -925,7 +906,7 @@ func TestBlockProcessor_GetInternalStartOfEpochMetaBlockNoFullNodesOrObserversSh }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) res, err := bp.GetInternalStartOfEpochMetaBlock(0, common.Internal) @@ -947,7 +928,7 @@ func TestBlockProcessor_GetInternalStartOfEpochMetaBlockCallGetFailsShouldErr(t }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) res, err := bp.GetInternalStartOfEpochMetaBlock(0, common.Internal) @@ -975,7 +956,7 @@ func TestBlockProcessor_GetInternalStartOfEpochMetaBlockShouldWork(t *testing.T) }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) res, err := bp.GetInternalStartOfEpochMetaBlock(1, common.Internal) @@ -1005,7 +986,7 @@ func TestBlockProcessor_GetAlteredAccountsByNonce(t *testing.T) { }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) res, err := bp.GetAlteredAccountsByNonce(requestedShardID, 4, common.GetAlteredAccountsForBlockOptions{}) require.Equal(t, expectedErr, err) require.Nil(t, res) @@ -1034,7 +1015,7 @@ func TestBlockProcessor_GetAlteredAccountsByNonce(t *testing.T) { }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) res, err := bp.GetAlteredAccountsByNonce(requestedShardID, 4, common.GetAlteredAccountsForBlockOptions{}) require.Equal(t, 2, callGetEndpointCt) require.True(t, errors.Is(err, process.ErrSendingRequest)) @@ -1063,7 +1044,7 @@ func TestBlockProcessor_GetAlteredAccountsByNonce(t *testing.T) { }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) res, err := bp.GetAlteredAccountsByNonce(requestedShardID, 4, common.GetAlteredAccountsForBlockOptions{}) require.Nil(t, err) require.Equal(t, &data.AlteredAccountsApiResponse{ @@ -1092,7 +1073,7 @@ func TestBlockProcessor_GetAlteredAccountsByHash(t *testing.T) { }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) res, err := bp.GetAlteredAccountsByHash(requestedShardID, "hash", common.GetAlteredAccountsForBlockOptions{}) require.Equal(t, expectedErr, err) require.Nil(t, res) @@ -1121,7 +1102,7 @@ func TestBlockProcessor_GetAlteredAccountsByHash(t *testing.T) { }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) res, err := bp.GetAlteredAccountsByHash(requestedShardID, "hash", common.GetAlteredAccountsForBlockOptions{}) require.Equal(t, 2, callGetEndpointCt) require.True(t, errors.Is(err, process.ErrSendingRequest)) @@ -1150,7 +1131,7 @@ func TestBlockProcessor_GetAlteredAccountsByHash(t *testing.T) { }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) res, err := bp.GetAlteredAccountsByHash(requestedShardID, "hash", common.GetAlteredAccountsForBlockOptions{}) require.Nil(t, err) require.Equal(t, &data.AlteredAccountsApiResponse{ @@ -1245,7 +1226,7 @@ func TestBlockProcessor_GetHyperBlockByNonceWithAlteredAccounts(t *testing.T) { }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) res, err := bp.GetHyperBlockByNonce(4, common.HyperblockQueryOptions{WithAlteredAccounts: true}) require.Nil(t, err) @@ -1362,7 +1343,7 @@ func TestBlockProcessor_GetHyperBlockByHashWithAlteredAccounts(t *testing.T) { }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) res, err := bp.GetHyperBlockByHash("abcdef", common.HyperblockQueryOptions{WithAlteredAccounts: true}) require.Nil(t, err) @@ -1419,7 +1400,7 @@ func TestBlockProcessor_GetInternalStartOfEpochValidatorsInfo(t *testing.T) { }, } - bp, _ := process.NewBlockProcessor(&mock.ExternalStorageConnectorStub{}, proc) + bp, _ := process.NewBlockProcessor(proc) require.NotNil(t, bp) res, err := bp.GetInternalStartOfEpochValidatorsInfo(1) diff --git a/process/database/disabledElasticSearchConnector.go b/process/database/disabledElasticSearchConnector.go deleted file mode 100644 index 3f82d070..00000000 --- a/process/database/disabledElasticSearchConnector.go +++ /dev/null @@ -1,30 +0,0 @@ -package database - -import ( - "errors" - - "github.com/multiversx/mx-chain-proxy-go/data" -) - -var errDatabaseConnectionIsDisabled = errors.New("database connection is disabled") - -type disabledElasticSearchConnector struct{} - -func NewDisabledElasticSearchConnector() *disabledElasticSearchConnector { - return new(disabledElasticSearchConnector) -} - -// GetTransactionsByAddress will return error because database connection is disabled -func (desc *disabledElasticSearchConnector) GetTransactionsByAddress(_ string) ([]data.DatabaseTransaction, error) { - return nil, errDatabaseConnectionIsDisabled -} - -// GetAtlasBlockByShardIDAndNonce will return error because database connection is disabled -func (desc *disabledElasticSearchConnector) GetAtlasBlockByShardIDAndNonce(_ uint32, _ uint64) (data.AtlasBlock, error) { - return data.AtlasBlock{}, errDatabaseConnectionIsDisabled -} - -// IsInterfaceNil - -func (desc *disabledElasticSearchConnector) IsInterfaceNil() bool { - return desc == nil -} diff --git a/process/database/elasticSearchConnector.go b/process/database/elasticSearchConnector.go deleted file mode 100644 index 0b6cd4c7..00000000 --- a/process/database/elasticSearchConnector.go +++ /dev/null @@ -1,173 +0,0 @@ -package database - -import ( - "encoding/json" - "fmt" - - "github.com/elastic/go-elasticsearch/v7" - "github.com/multiversx/mx-chain-proxy-go/data" -) - -const ( - numTopTransactions = 20 - numTransactionFromAMiniblock = 100 -) - -type elasticSearchConnector struct { - client *elasticsearch.Client -} - -// NewElasticSearchConnector create a new elastic search database reader object -func NewElasticSearchConnector(url, username, password string) (*elasticSearchConnector, error) { - cfg := elasticsearch.Config{ - Addresses: []string{url}, - Username: username, - Password: password, - } - - client, err := elasticsearch.NewClient(cfg) - if err != nil { - return nil, fmt.Errorf("cannot create database reader %w", err) - } - - return &elasticSearchConnector{ - client: client, - }, nil -} - -// 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) - decodedBody, err := esc.doSearchRequest(query, "blocks", 1) - if err != nil { - return data.AtlasBlock{}, err - } - - metaBlock, metaBlockHash, err := convertObjectToBlock(decodedBody) - if err != nil { - return data.AtlasBlock{}, err - } - - txs, err := esc.getTxsByMiniblockHashes(metaBlock.MiniBlocksHashes) - if err != nil { - return data.AtlasBlock{}, err - } - - transactions, err := esc.getTxsByNotarizedBlockHashes(metaBlock.NotarizedBlocksHashes) - if err != nil { - return data.AtlasBlock{}, err - } - - txs = append(txs, transactions...) - - return data.AtlasBlock{ - Nonce: metaBlock.Nonce, - Hash: metaBlockHash, - Transactions: txs, - }, nil -} - -func (esc *elasticSearchConnector) getTxsByNotarizedBlockHashes(hashes []string) ([]data.DatabaseTransaction, error) { - txs := make([]data.DatabaseTransaction, 0) - for _, hash := range hashes { - query := blockByHashQuery(hash) - decodedBody, err := esc.doSearchRequest(query, "blocks", 1) - if err != nil { - return nil, err - } - - shardBlock, _, err := convertObjectToBlock(decodedBody) - if err != nil { - return nil, err - } - - transactions, err := esc.getTxsByMiniblockHashes(shardBlock.MiniBlocksHashes) - if err != nil { - return nil, err - } - - txs = append(txs, transactions...) - } - return txs, nil -} - -func (esc *elasticSearchConnector) getTxsByMiniblockHashes(hashes []string) ([]data.DatabaseTransaction, error) { - txs := make([]data.DatabaseTransaction, 0) - for _, hash := range hashes { - query := txsByMiniblockHashQuery(hash) - decodedBody, err := esc.doSearchRequest(query, "transactions", numTransactionFromAMiniblock) - if err != nil { - return nil, err - } - - transactions, err := convertObjectToTransactions(decodedBody) - if err != nil { - return nil, err - } - - txs = append(txs, transactions...) - } - return txs, nil -} - -func (esc *elasticSearchConnector) doSearchRequest(query object, index string, size int) (object, error) { - buff, err := encodeQuery(query) - if err != nil { - return nil, err - } - - res, err := esc.client.Search( - esc.client.Search.WithIndex(index), - esc.client.Search.WithSize(size), - esc.client.Search.WithBody(&buff), - ) - if err != nil { - return nil, fmt.Errorf("cannot get data from database: %w", err) - } - - defer func() { - _ = res.Body.Close() - }() - if res.IsError() { - return nil, fmt.Errorf("cannot get data from database: %v", res) - } - - var decodedBody map[string]interface{} - if err := json.NewDecoder(res.Body).Decode(&decodedBody); err != nil { - return nil, err - } - - return decodedBody, nil -} - -func (esc *elasticSearchConnector) doSearchRequestTx(address string, index string, size int) (object, error) { - query := fmt.Sprintf("sender:%s OR receiver:%s", address, address) - res, err := esc.client.Search( - esc.client.Search.WithIndex(index), - esc.client.Search.WithSize(size), - esc.client.Search.WithQuery(query), - esc.client.Search.WithSort("timestamp:desc"), - ) - if err != nil { - return nil, fmt.Errorf("cannot get data from database: %w", err) - } - - defer func() { - _ = res.Body.Close() - }() - if res.IsError() { - return nil, fmt.Errorf("cannot get data from database: %v", res) - } - - var decodedBody map[string]interface{} - if err := json.NewDecoder(res.Body).Decode(&decodedBody); err != nil { - return nil, err - } - - return decodedBody, nil -} - -// IsInterfaceNil returns true if there is no value under the interface -func (esc *elasticSearchConnector) IsInterfaceNil() bool { - return esc == nil -} diff --git a/process/database/elasticSearchConnector_test.go b/process/database/elasticSearchConnector_test.go deleted file mode 100644 index 2b6b1949..00000000 --- a/process/database/elasticSearchConnector_test.go +++ /dev/null @@ -1,24 +0,0 @@ -package database - -import ( - "fmt" - "testing" - - "github.com/multiversx/mx-chain-core-go/core" - "github.com/stretchr/testify/require" -) - - -func TestDatabaseReader_GetBlockByShardIDAndNonce(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) - - block, err := reader.GetAtlasBlockByShardIDAndNonce(core.MetachainShardId, 7720) - fmt.Println(block) - require.Nil(t, err) -} diff --git a/process/interface.go b/process/interface.go index bbfb5932..eb7e558c 100644 --- a/process/interface.go +++ b/process/interface.go @@ -29,12 +29,6 @@ type Processor interface { IsInterfaceNil() bool } -// ExternalStorageConnector defines what a external storage connector should be able to do -type ExternalStorageConnector interface { - GetAtlasBlockByShardIDAndNonce(shardID uint32, nonce uint64) (data.AtlasBlock, error) - IsInterfaceNil() bool -} - // PrivateKeysLoaderHandler defines what a component which handles loading of the private keys file should do type PrivateKeysLoaderHandler interface { PrivateKeysByShard() (map[uint32][]crypto.PrivateKey, error) diff --git a/process/mock/elasticSearchConnectorMock.go b/process/mock/elasticSearchConnectorMock.go deleted file mode 100644 index b6c97769..00000000 --- a/process/mock/elasticSearchConnectorMock.go +++ /dev/null @@ -1,16 +0,0 @@ -package mock - -import "github.com/multiversx/mx-chain-proxy-go/data" - -type ElasticSearchConnectorMock struct { -} - -// GetAtlasBlockByShardIDAndNonce - -func (escm *ElasticSearchConnectorMock) GetAtlasBlockByShardIDAndNonce(_ uint32, _ uint64) (data.AtlasBlock, error) { - return data.AtlasBlock{}, nil -} - -// IsInterfaceNil - -func (escm *ElasticSearchConnectorMock) IsInterfaceNil() bool { - return escm == nil -} diff --git a/process/mock/externalStorageConnectorStub.go b/process/mock/externalStorageConnectorStub.go deleted file mode 100644 index febec410..00000000 --- a/process/mock/externalStorageConnectorStub.go +++ /dev/null @@ -1,21 +0,0 @@ -package mock - -import "github.com/multiversx/mx-chain-proxy-go/data" - -type ExternalStorageConnectorStub struct { - GetAtlasBlockByShardIDAndNonceCalled func(shardID uint32, nonce uint64) (data.AtlasBlock, error) -} - -// GetAtlasBlockByShardIDAndNonce - -func (e *ExternalStorageConnectorStub) GetAtlasBlockByShardIDAndNonce(shardID uint32, nonce uint64) (data.AtlasBlock, error) { - if e.GetAtlasBlockByShardIDAndNonceCalled != nil { - return e.GetAtlasBlockByShardIDAndNonceCalled(shardID, nonce) - } - - return data.AtlasBlock{Hash: "hash"}, nil -} - -// IsInterfaceNil - -func (e *ExternalStorageConnectorStub) IsInterfaceNil() bool { - return e == nil -} From 980d416d0e211592c1828a7d8c280036a0513b68 Mon Sep 17 00:00:00 2001 From: danielailie Date: Mon, 5 Aug 2024 16:51:21 +0300 Subject: [PATCH 23/25] Remove whitespaces --- api/groups/baseBlockGroup_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/groups/baseBlockGroup_test.go b/api/groups/baseBlockGroup_test.go index 0ab93625..9d0e9b67 100644 --- a/api/groups/baseBlockGroup_test.go +++ b/api/groups/baseBlockGroup_test.go @@ -18,7 +18,7 @@ import ( "github.com/stretchr/testify/require" ) -const blockPath = "/block" +const blockPath = "/block" func TestNewBlockGroup_WrongFacadeShouldErr(t *testing.T) { wrongFacade := &mock.WrongFacade{} From 7865fa548de65ba56025afb52147c3cf1c1de915 Mon Sep 17 00:00:00 2001 From: Daniel Drasovean Date: Fri, 9 Aug 2024 14:12:39 +0300 Subject: [PATCH 24/25] Replaced 'hash' with 'nonce' in get-by-nonce description --- cmd/proxy/config/swagger/openapi.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/proxy/config/swagger/openapi.json b/cmd/proxy/config/swagger/openapi.json index dad65efa..8d3b7497 100644 --- a/cmd/proxy/config/swagger/openapi.json +++ b/cmd/proxy/config/swagger/openapi.json @@ -624,7 +624,7 @@ { "name": "nonce", "in": "path", - "description": "the hash to look after", + "description": "the nonce to look after", "required": true, "schema": { "type": "integer" @@ -655,7 +655,7 @@ { "name": "nonce", "in": "path", - "description": "the hash to look after", + "description": "the nonce to look after", "required": true, "schema": { "type": "integer" @@ -3159,4 +3159,4 @@ } } } -} \ No newline at end of file +} From b06b627f11f70944c1c06f3b151f8dd8cf78332b Mon Sep 17 00:00:00 2001 From: Iuga Mihai <50499646+miiu96@users.noreply.github.com> Date: Wed, 14 Aug 2024 11:58:41 +0300 Subject: [PATCH 25/25] Fix get transaction endpoint (#456) * fix get transaction endpoint * empty scr list * fix rcv address * pending scr check * unit tests * fix * remove folder * fix * fixes after merge * fixes after review --- api/errors/errors.go | 3 + data/transaction.go | 12 ++ process/testdata/transactionWithScrs.json | 206 ++++++++++++++++++++++ process/transactionProcessor.go | 172 ++++++++++++++++-- process/transactionProcessor_test.go | 59 ++++++- 5 files changed, 437 insertions(+), 15 deletions(-) create mode 100644 process/testdata/transactionWithScrs.json diff --git a/api/errors/errors.go b/api/errors/errors.go index d3499a73..5f45ff38 100644 --- a/api/errors/errors.go +++ b/api/errors/errors.go @@ -98,6 +98,9 @@ var ErrInvalidReceiverAddress = errors.New("invalid hex receiver address provide // ErrTransactionNotFound signals that a transaction was not found var ErrTransactionNotFound = errors.New("transaction not found") +// ErrSCRsNoFound signals that smart contract results were not found +var ErrSCRsNoFound = errors.New("smart contract results not found") + // ErrTransactionsNotFoundInPool signals that no transaction was not found in pool var ErrTransactionsNotFoundInPool = errors.New("transactions not found in pool") diff --git a/data/transaction.go b/data/transaction.go index 9173a883..e283e468 100644 --- a/data/transaction.go +++ b/data/transaction.go @@ -43,6 +43,18 @@ type GetTransactionResponse struct { Code string `json:"code"` } +// GetSCRsResponseData follows the format of the data field of get smart contract results response +type GetSCRsResponseData struct { + SCRs []*transaction.ApiSmartContractResult `json:"scrs"` +} + +// GetSCRsResponse defines a response from the node holding the smart contract results +type GetSCRsResponse struct { + Data GetSCRsResponseData `json:"data"` + Error string `json:"error"` + Code string `json:"code"` +} + // transactionWrapper is a wrapper over a normal transaction in order to implement the interface needed in mx-chain-go // for computing gas cost for a transaction type transactionWrapper struct { diff --git a/process/testdata/transactionWithScrs.json b/process/testdata/transactionWithScrs.json new file mode 100644 index 00000000..4551425d --- /dev/null +++ b/process/testdata/transactionWithScrs.json @@ -0,0 +1,206 @@ +{ + "transaction": { + "type": "normal", + "processingTypeOnSource": "SCInvoking", + "processingTypeOnDestination": "SCInvoking", + "hash": "70ddb98dca6fd7cf9abdffdc61d8b7cd5faa76ee090304135a8704996f4aafb7", + "nonce": 1, + "round": 23, + "epoch": 1, + "value": "10000000000000000", + "receiver": "erd1qqqqqqqqqqqqqpgqmzzm05jeav6d5qvna0q2pmcllelkz8xddz3syjszx5", + "sender": "erd1l6xt0rqlyzw56a3k8xwwshq2dcjwy3q9cppucvqsmdyw8r98dz3sae0kxl", + "gasPrice": 1000000000, + "gasLimit": 100000000, + "gasUsed": 100000000, + "data": "aXNzdWU=", + "signature": "64756d6d79", + "sourceShard": 1, + "destinationShard": 1, + "blockNonce": 23, + "blockHash": "e0d6fc125d63ce24694bdc6c16ec49f9354eb4298eb2ab02eab86ea16c0b7fef", + "notarizedAtSourceInMetaNonce": 25, + "NotarizedAtSourceInMetaHash": "c48e6170b51619173e2d30d223c9be23c148eca52f55d6a9f4164e76e47b9e65", + "notarizedAtDestinationInMetaNonce": 25, + "notarizedAtDestinationInMetaHash": "c48e6170b51619173e2d30d223c9be23c148eca52f55d6a9f4164e76e47b9e65", + "miniblockType": "TxBlock", + "miniblockHash": "6712ac7ec8504f46a74ca7b346bab4669ae21b68a2c153f772c96bbace614354", + "hyperblockNonce": 25, + "hyperblockHash": "c48e6170b51619173e2d30d223c9be23c148eca52f55d6a9f4164e76e47b9e65", + "timestamp": 1722930888, + "smartContractResults": [ + { + "hash": "7059ea78e7e0fc194f159c848b76276fe50d0673eb8f053113dde9bfb320f354", + "nonce": 0, + "value": 10000000000000000, + "receiver": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u", + "sender": "erd1qqqqqqqqqqqqqpgqmzzm05jeav6d5qvna0q2pmcllelkz8xddz3syjszx5", + "data": "issue@54455354@54455354@@@63616e467265657a65@74727565@63616e57697065@74727565@63616e5061757365@74727565@63616e4d696e74@66616c7365@63616e4275726e@66616c7365@63616e4368616e67654f776e6572@74727565@63616e55706772616465@74727565@63616e4164645370656369616c526f6c6573@74727565@24cc3c6b7d5bcc3733ca038eb5685fb49b86a7079042d8e075265a72c2cb0d50@70ddb98dca6fd7cf9abdffdc61d8b7cd5faa76ee090304135a8704996f4aafb7@4159b0", + "prevTxHash": "70ddb98dca6fd7cf9abdffdc61d8b7cd5faa76ee090304135a8704996f4aafb7", + "originalTxHash": "70ddb98dca6fd7cf9abdffdc61d8b7cd5faa76ee090304135a8704996f4aafb7", + "gasLimit": 98349849, + "gasPrice": 1000000000, + "callType": 1, + "originalSender": "erd1l6xt0rqlyzw56a3k8xwwshq2dcjwy3q9cppucvqsmdyw8r98dz3sae0kxl", + "logs": { + "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u", + "events": [ + { + "address": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u", + "identifier": "signalError", + "topics": [ + "AAAAAAAAAAAFANiFt9JZ6zTaAZPrwKDvH/5/YRzNaKM=", + "Y2FsbFZhbHVlIG5vdCBlcXVhbHMgd2l0aCBiYXNlSXNzdWluZ0Nvc3Q=" + ], + "data": "QDA0QDYzNjE2YzZjNTY2MTZjNzU2NTIwNmU2Zjc0MjA2NTcxNzU2MTZjNzMyMDc3Njk3NDY4MjA2MjYxNzM2NTQ5NzM3Mzc1Njk2ZTY3NDM2ZjczNzRAYWM5NDdlNDM5Mjg5MzI4NDI2MzExMWNhMTk1MzFkZjY0ZWRkMzBhYzdiYWU0MmUyMmU2OTY4N2JjYTE5MzcwNEAyNGNjM2M2YjdkNWJjYzM3MzNjYTAzOGViNTY4NWZiNDliODZhNzA3OTA0MmQ4ZTA3NTI2NWE3MmMyY2IwZDUwQDcwZGRiOThkY2E2ZmQ3Y2Y5YWJkZmZkYzYxZDhiN2NkNWZhYTc2ZWUwOTAzMDQxMzVhODcwNDk5NmY0YWFmYjdAMDA=", + "additionalData": [ + "QDA0QDYzNjE2YzZjNTY2MTZjNzU2NTIwNmU2Zjc0MjA2NTcxNzU2MTZjNzMyMDc3Njk3NDY4MjA2MjYxNzM2NTQ5NzM3Mzc1Njk2ZTY3NDM2ZjczNzRAYWM5NDdlNDM5Mjg5MzI4NDI2MzExMWNhMTk1MzFkZjY0ZWRkMzBhYzdiYWU0MmUyMmU2OTY4N2JjYTE5MzcwNEAyNGNjM2M2YjdkNWJjYzM3MzNjYTAzOGViNTY4NWZiNDliODZhNzA3OTA0MmQ4ZTA3NTI2NWE3MmMyY2IwZDUwQDcwZGRiOThkY2E2ZmQ3Y2Y5YWJkZmZkYzYxZDhiN2NkNWZhYTc2ZWUwOTAzMDQxMzVhODcwNDk5NmY0YWFmYjdAMDA=" + ] + } + ] + }, + "operation": "transfer", + "function": "issue" + }, + { + "hash": "818b468a55536bb3e38afd754da17fb5f1c739726cccc938a8b94077d50f22c5", + "nonce": 1, + "value": 30999900000000, + "receiver": "erd1qqqqqqqqqqqqqpgqmzzm05jeav6d5qvna0q2pmcllelkz8xddz3syjszx5", + "sender": "erd1qqqqqqqqqqqqqpgqmzzm05jeav6d5qvna0q2pmcllelkz8xddz3syjszx5", + "data": "@6f6b", + "prevTxHash": "280d36aae1061f3d31550872e09afa9485ea1d58cb0def0732369d4631707439", + "originalTxHash": "70ddb98dca6fd7cf9abdffdc61d8b7cd5faa76ee090304135a8704996f4aafb7", + "gasLimit": 0, + "gasPrice": 1000000000, + "callType": 0, + "operation": "transfer", + "isRefund": true + }, + { + "hash": "280d36aae1061f3d31550872e09afa9485ea1d58cb0def0732369d4631707439", + "nonce": 0, + "value": 10000000000000000, + "receiver": "erd1qqqqqqqqqqqqqpgqmzzm05jeav6d5qvna0q2pmcllelkz8xddz3syjszx5", + "sender": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u", + "data": "@04@63616c6c56616c7565206e6f7420657175616c732077697468206261736549737375696e67436f7374@ac947e4392893284263111ca19531df64edd30ac7bae42e22e69687bca193704@24cc3c6b7d5bcc3733ca038eb5685fb49b86a7079042d8e075265a72c2cb0d50@70ddb98dca6fd7cf9abdffdc61d8b7cd5faa76ee090304135a8704996f4aafb7@00", + "prevTxHash": "7059ea78e7e0fc194f159c848b76276fe50d0673eb8f053113dde9bfb320f354", + "originalTxHash": "70ddb98dca6fd7cf9abdffdc61d8b7cd5faa76ee090304135a8704996f4aafb7", + "gasLimit": 4282800, + "gasPrice": 1000000000, + "callType": 2, + "returnMessage": "callValue not equals with baseIssuingCost", + "originalSender": "erd1qqqqqqqqqqqqqpgqmzzm05jeav6d5qvna0q2pmcllelkz8xddz3syjszx5", + "logs": { + "address": "erd1qqqqqqqqqqqqqpgqmzzm05jeav6d5qvna0q2pmcllelkz8xddz3syjszx5", + "events": [ + { + "address": "erd1qqqqqqqqqqqqqpgqmzzm05jeav6d5qvna0q2pmcllelkz8xddz3syjszx5", + "identifier": "completedTxEvent", + "topics": [ + "cFnqeOfg/BlPFZyEi3Ynb+UNBnPrjwUxE93pv7Mg81Q=" + ], + "data": null, + "additionalData": null + } + ] + }, + "operation": "transfer" + } + ], + "logs": { + "address": "erd1qqqqqqqqqqqqqpgqmzzm05jeav6d5qvna0q2pmcllelkz8xddz3syjszx5", + "events": [ + { + "address": "erd1qqqqqqqqqqqqqpgqmzzm05jeav6d5qvna0q2pmcllelkz8xddz3syjszx5", + "identifier": "transferValueOnly", + "topics": [ + "I4byb8EAAA==", + "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAC//8=" + ], + "data": "QXN5bmNDYWxs", + "additionalData": [ + "QXN5bmNDYWxs", + "aXNzdWU=", + "VEVTVA==", + "VEVTVA==", + "", + "", + "Y2FuRnJlZXpl", + "dHJ1ZQ==", + "Y2FuV2lwZQ==", + "dHJ1ZQ==", + "Y2FuUGF1c2U=", + "dHJ1ZQ==", + "Y2FuTWludA==", + "ZmFsc2U=", + "Y2FuQnVybg==", + "ZmFsc2U=", + "Y2FuQ2hhbmdlT3duZXI=", + "dHJ1ZQ==", + "Y2FuVXBncmFkZQ==", + "dHJ1ZQ==", + "Y2FuQWRkU3BlY2lhbFJvbGVz", + "dHJ1ZQ==" + ] + }, + { + "address": "erd1qqqqqqqqqqqqqpgqmzzm05jeav6d5qvna0q2pmcllelkz8xddz3syjszx5", + "identifier": "writeLog", + "topics": [ + "/oy3jB8gnU12Njmc6FwKbiTiRAXAQ8wwENtI44ynaKM=" + ], + "data": "QDZmNmI=", + "additionalData": [ + "QDZmNmI=" + ] + } + ] + }, + "status": "success", + "operation": "transfer", + "function": "issue", + "initiallyPaidFee": "1056925000000000", + "fee": "1056925000000000", + "chainID": "chain", + "version": 2, + "options": 0 + }, + "scrs": [ + { + "type": "unsigned", + "processingTypeOnSource": "SCInvoking", + "processingTypeOnDestination": "SCInvoking", + "hash": "280d36aae1061f3d31550872e09afa9485ea1d58cb0def0732369d4631707439", + "nonce": 0, + "round": 26, + "epoch": 1, + "value": "10000000000000000", + "receiver": "erd1qqqqqqqqqqqqqpgqmzzm05jeav6d5qvna0q2pmcllelkz8xddz3syjszx5", + "sender": "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzllls8a5w6u", + "gasPrice": 1000000000, + "gasLimit": 4282800, + "gasUsed": 476000, + "data": "QDA0QDYzNjE2YzZjNTY2MTZjNzU2NTIwNmU2Zjc0MjA2NTcxNzU2MTZjNzMyMDc3Njk3NDY4MjA2MjYxNzM2NTQ5NzM3Mzc1Njk2ZTY3NDM2ZjczNzRAYWM5NDdlNDM5Mjg5MzI4NDI2MzExMWNhMTk1MzFkZjY0ZWRkMzBhYzdiYWU0MmUyMmU2OTY4N2JjYTE5MzcwNEAyNGNjM2M2YjdkNWJjYzM3MzNjYTAzOGViNTY4NWZiNDliODZhNzA3OTA0MmQ4ZTA3NTI2NWE3MmMyY2IwZDUwQDcwZGRiOThkY2E2ZmQ3Y2Y5YWJkZmZkYzYxZDhiN2NkNWZhYTc2ZWUwOTAzMDQxMzVhODcwNDk5NmY0YWFmYjdAMDA=", + "previousTransactionHash": "7059ea78e7e0fc194f159c848b76276fe50d0673eb8f053113dde9bfb320f354", + "originalTransactionHash": "70ddb98dca6fd7cf9abdffdc61d8b7cd5faa76ee090304135a8704996f4aafb7", + "returnMessage": "callValue not equals with baseIssuingCost", + "originalSender": "erd1qqqqqqqqqqqqqpgqmzzm05jeav6d5qvna0q2pmcllelkz8xddz3syjszx5", + "sourceShard": 4294967295, + "destinationShard": 1, + "blockNonce": 26, + "blockHash": "3d69e4b55225947cfe1b1aeb467868b5ce14e84538f0360761629eb931a19989", + "notarizedAtSourceInMetaNonce": 25, + "NotarizedAtSourceInMetaHash": "c48e6170b51619173e2d30d223c9be23c148eca52f55d6a9f4164e76e47b9e65", + "miniblockType": "SmartContractResultBlock", + "miniblockHash": "20419d6c4e5091a6802f8c954291b24cf94c744d784961361169218831ef565e", + "timestamp": 1722930906, + "status": "pending", + "operation": "transfer", + "fee": "0", + "callType": "asynchronousCallBack", + "options": 0 + } + ] +} + diff --git a/process/transactionProcessor.go b/process/transactionProcessor.go index 9d55ee1a..1fb7d985 100644 --- a/process/transactionProcessor.go +++ b/process/transactionProcessor.go @@ -30,8 +30,12 @@ const TransactionSimulatePath = "/transaction/simulate" // MultipleTransactionsPath defines the multiple transactions send path of the node const MultipleTransactionsPath = "/transaction/send-multiple" +// SCRsByTxHash defines smart contract results by transaction hash path of the node +const SCRsByTxHash = "/transaction/scrs-by-tx-hash/" + const ( withResultsParam = "?withResults=true" + scrHashParam = "?scrHash=%s" checkSignatureFalse = "?checkSignature=false" bySenderParam = "&by-sender=" fieldsParam = "?fields=" @@ -65,6 +69,11 @@ type erdTransaction struct { Version uint32 `json:"version"` } +type tupleHashWasFetched struct { + hash string + fetched bool +} + // TransactionProcessor is able to process transaction requests type TransactionProcessor struct { proc Processor @@ -451,6 +460,20 @@ func (tp *TransactionProcessor) computeTransactionStatus(tx *transaction.ApiTran } } + allLogs, allScrs, err := tp.gatherAllLogsAndScrs(tx) + if err != nil { + log.Warn("error in TransactionProcessor.computeTransactionStatus", "error", err) + return &data.ProcessStatusResponse{ + Status: string(data.TxStatusUnknown), + } + } + + if hasPendingSCR(allScrs) { + return &data.ProcessStatusResponse{ + Status: string(transaction.TxStatusPending), + } + } + txLogsOnFirstLevel := []*transaction.ApiLogs{tx.Logs} failed, reason := checkIfFailed(txLogsOnFirstLevel) if failed { @@ -460,14 +483,6 @@ func (tp *TransactionProcessor) computeTransactionStatus(tx *transaction.ApiTran } } - allLogs, allScrs, err := tp.gatherAllLogsAndScrs(tx) - if err != nil { - log.Warn("error in TransactionProcessor.computeTransactionStatus", "error", err) - return &data.ProcessStatusResponse{ - Status: string(data.TxStatusUnknown), - } - } - allLogs, err = tp.addMissingLogsOnProcessingExceptions(tx, allLogs, allScrs) if err != nil { log.Warn("error in TransactionProcessor.computeTransactionStatus on addMissingLogsOnProcessingExceptions call", "error", err) @@ -497,7 +512,8 @@ func (tp *TransactionProcessor) computeTransactionStatus(tx *transaction.ApiTran } } - if checkIfCompleted(allLogs) { + isUnsigned := string(transaction.TxTypeUnsigned) == tx.Type + if checkIfCompleted(allLogs) || isUnsigned { return &data.ProcessStatusResponse{ Status: string(transaction.TxStatusSuccess), } @@ -508,6 +524,16 @@ func (tp *TransactionProcessor) computeTransactionStatus(tx *transaction.ApiTran } } +func hasPendingSCR(scrs []*transaction.ApiTransactionResult) bool { + for _, scr := range scrs { + if scr.Status == transaction.TxStatusPending { + return true + } + } + + return false +} + func checkIfFailedOnReturnMessage(allScrs []*transaction.ApiTransactionResult, tx *transaction.ApiTransactionResult) bool { hasReturnMessageWithZeroValue := len(tx.ReturnMessage) > 0 && isZeroValue(tx.Value) if hasReturnMessageWithZeroValue && !isRefundScr(tx.ReturnMessage) { @@ -700,6 +726,7 @@ func (tp *TransactionProcessor) gatherAllLogsAndScrs(tx *transaction.ApiTransact func (tp *TransactionProcessor) getTxFromObservers(txHash string, reqType requestType, withResults bool) (*transaction.ApiTransactionResult, error) { observersShardIDs := tp.proc.GetShardIDs() + shardIDWasFetch := make(map[uint32]*tupleHashWasFetched) for _, observerShardID := range observersShardIDs { nodesInShard, err := tp.getNodesInShard(observerShardID, reqType) if err != nil { @@ -726,6 +753,10 @@ func (tp *TransactionProcessor) getTxFromObservers(txHash string, reqType reques "sender address", getTxResponse.Data.Transaction.Sender, "error", err.Error()) } + shardIDWasFetch[sndShardID] = &tupleHashWasFetched{ + hash: getTxResponse.Data.Transaction.Hash, + fetched: false, + } rcvShardID, err := tp.getShardByAddress(getTxResponse.Data.Transaction.Receiver) if err != nil { @@ -733,6 +764,10 @@ func (tp *TransactionProcessor) getTxFromObservers(txHash string, reqType reques "receiver address", getTxResponse.Data.Transaction.Receiver, "error", err.Error()) } + shardIDWasFetch[rcvShardID] = &tupleHashWasFetched{ + hash: getTxResponse.Data.Transaction.Hash, + fetched: false, + } if isRelayedTxV3(getTxResponse.Data.Transaction) { return tp.mergeSCRLogsFromInnerReceivers(&getTxResponse.Data.Transaction, withResults), nil @@ -742,24 +777,52 @@ func (tp *TransactionProcessor) getTxFromObservers(txHash string, reqType reques observerIsInDestShard := rcvShardID == observerShardID if isIntraShard { - return &getTxResponse.Data.Transaction, nil + shardIDWasFetch[sndShardID].fetched = true + if len(getTxResponse.Data.Transaction.SmartContractResults) == 0 { + return &getTxResponse.Data.Transaction, nil + } + + tp.extraShardFromSCRs(getTxResponse.Data.Transaction.SmartContractResults, shardIDWasFetch) } if observerIsInDestShard { // need to get transaction from source shard and merge scResults // if withEvents is true - return tp.alterTxWithScResultsFromSourceIfNeeded(txHash, &getTxResponse.Data.Transaction, withResults), nil + txFromSource := tp.alterTxWithScResultsFromSourceIfNeeded(txHash, &getTxResponse.Data.Transaction, withResults, shardIDWasFetch) + + tp.extraShardFromSCRs(txFromSource.SmartContractResults, shardIDWasFetch) + + err = tp.fetchSCRSBasedOnShardMap(txFromSource, shardIDWasFetch) + if err != nil { + return nil, err + } + + return txFromSource, nil } // get transaction from observer that is in destination shard txFromDstShard, ok := tp.getTxFromDestShard(txHash, rcvShardID, withResults) if ok { + tp.extraShardFromSCRs(txFromDstShard.SmartContractResults, shardIDWasFetch) + alteredTxFromDest := tp.mergeScResultsFromSourceAndDestIfNeeded(&getTxResponse.Data.Transaction, txFromDstShard, withResults) + + err = tp.fetchSCRSBasedOnShardMap(alteredTxFromDest, shardIDWasFetch) + if err != nil { + return nil, err + } + return alteredTxFromDest, nil } // return transaction from observer from source shard // if did not get ok responses from observers from destination shard + + err = tp.fetchSCRSBasedOnShardMap(&getTxResponse.Data.Transaction, shardIDWasFetch) + if err != nil { + return nil, err + } + return &getTxResponse.Data.Transaction, nil } @@ -825,7 +888,86 @@ func (tp *TransactionProcessor) groupTxsByReceiverShard(tx *transaction.ApiTrans return txsByReceiverShardMap } -func (tp *TransactionProcessor) alterTxWithScResultsFromSourceIfNeeded(txHash string, tx *transaction.ApiTransactionResult, withResults bool) *transaction.ApiTransactionResult { +func (tp *TransactionProcessor) fetchSCRSBasedOnShardMap(tx *transaction.ApiTransactionResult, shardIDWasFetch map[uint32]*tupleHashWasFetched) error { + for shardID, info := range shardIDWasFetch { + scrs, err := tp.fetchSCRs(tx.Hash, info.hash, shardID) + if err != nil { + return err + } + + scResults := append(tx.SmartContractResults, scrs...) + scResultsNew := tp.getScResultsUnion(scResults) + + tx.SmartContractResults = scResultsNew + info.fetched = true + } + + return nil +} + +func (tp *TransactionProcessor) fetchSCRs(txHash, scrHash string, shardID uint32) ([]*transaction.ApiSmartContractResult, error) { + observers, err := tp.getNodesInShard(shardID, requestTypeFullHistoryNodes) + if err != nil { + return nil, err + } + + apiPath := SCRsByTxHash + txHash + fmt.Sprintf(scrHashParam, scrHash) + for _, observer := range observers { + getTxResponseDst := &data.GetSCRsResponse{} + respCode, errG := tp.proc.CallGetRestEndPoint(observer.Address, apiPath, getTxResponseDst) + if errG != nil { + log.Trace("cannot get smart contract results", "address", observer.Address, "error", errG) + continue + } + + if respCode != http.StatusOK { + continue + } + + return getTxResponseDst.Data.SCRs, nil + } + + return []*transaction.ApiSmartContractResult{}, nil + +} + +func (tp *TransactionProcessor) extraShardFromSCRs(scrs []*transaction.ApiSmartContractResult, shardIDWasFetch map[uint32]*tupleHashWasFetched) { + for _, scr := range scrs { + sndShardID, err := tp.getShardByAddress(scr.SndAddr) + if err != nil { + log.Warn("cannot compute shard ID from sender address", + "sender address", scr.SndAddr, + "error", err.Error()) + continue + } + + _, found := shardIDWasFetch[sndShardID] + if !found { + shardIDWasFetch[sndShardID] = &tupleHashWasFetched{ + hash: scr.Hash, + fetched: false, + } + } + + rcvShardID, err := tp.getShardByAddress(scr.RcvAddr) + if err != nil { + log.Warn("cannot compute shard ID from receiver address", + "receiver address", scr.RcvAddr, + "error", err.Error()) + continue + } + + _, found = shardIDWasFetch[rcvShardID] + if !found { + shardIDWasFetch[rcvShardID] = &tupleHashWasFetched{ + hash: scr.Hash, + fetched: false, + } + } + } +} + +func (tp *TransactionProcessor) alterTxWithScResultsFromSourceIfNeeded(txHash string, tx *transaction.ApiTransactionResult, withResults bool, shardIDWasFetch map[uint32]*tupleHashWasFetched) *transaction.ApiTransactionResult { if !withResults || len(tx.SmartContractResults) == 0 { return tx } @@ -842,6 +984,12 @@ func (tp *TransactionProcessor) alterTxWithScResultsFromSourceIfNeeded(txHash st } alteredTxFromDest := tp.mergeScResultsFromSourceAndDestIfNeeded(&getTxResponse.Data.Transaction, tx, withResults) + + shardIDWasFetch[tx.SourceShard] = &tupleHashWasFetched{ + hash: getTxResponse.Data.Transaction.Hash, + fetched: true, + } + return alteredTxFromDest } diff --git a/process/transactionProcessor_test.go b/process/transactionProcessor_test.go index 350f7de6..2e6b5096 100644 --- a/process/transactionProcessor_test.go +++ b/process/transactionProcessor_test.go @@ -650,7 +650,10 @@ func TestTransactionProcessor_GetTransactionStatusCrossShardTransaction(t *testi }, nil }, CallGetRestEndPointCalled: func(address string, path string, value interface{}) (i int, err error) { - responseGetTx := value.(*data.GetTransactionResponse) + responseGetTx, ok := value.(*data.GetTransactionResponse) + if !ok { + return http.StatusOK, nil + } responseGetTx.Data.Transaction = transaction.ApiTransactionResult{ Receiver: sndrShard1, @@ -718,7 +721,10 @@ func TestTransactionProcessor_GetTransactionStatusCrossShardTransactionDestinati return http.StatusBadRequest, nil } - responseGetTx := value.(*data.GetTransactionResponse) + responseGetTx, ok := value.(*data.GetTransactionResponse) + if !ok { + return http.StatusOK, nil + } responseGetTx.Data.Transaction = transaction.ApiTransactionResult{ Receiver: sndrShard1, @@ -1255,7 +1261,11 @@ func TestTransactionProcessor_GetTransactionWithEventsFirstFromDstShardAndAfterS return nil, nil }, CallGetRestEndPointCalled: func(address string, path string, value interface{}) (i int, err error) { - responseGetTx := value.(*data.GetTransactionResponse) + responseGetTx, ok := value.(*data.GetTransactionResponse) + if !ok { + return http.StatusOK, nil + } + if strings.Contains(path, scHash1) { responseGetTx.Data.Transaction.Hash = scHash1 return http.StatusOK, nil @@ -2183,6 +2193,49 @@ func TestTransactionProcessor_GetProcessedTransactionStatus(t *testing.T) { assert.Equal(t, string(transaction.TxStatusPending), status.Status) // not a move balance tx with missing finish markers } +func TestTransactionProcessor_GetProcessedStatusIntraShardTxWithPendingSCR(t *testing.T) { + txWithSCRs := loadJsonIntoTxAndScrs(t, "./testdata/transactionWithScrs.json") + + processorStub := &mock.ProcessorStub{ + GetShardIDsCalled: func() []uint32 { + return []uint32{0} // force everything intra-shard for test setup simplicity + }, + ComputeShardIdCalled: func(addressBuff []byte) (uint32, error) { + return 0, nil + }, + GetObserversCalled: func(shardId uint32, dataAvailability data.ObserverDataAvailabilityType) ([]*data.NodeData, error) { + return []*data.NodeData{ + { + Address: "test", + ShardId: 0, + }, + }, nil + }, + CallGetRestEndPointCalled: func(address string, path string, value interface{}) (int, error) { + valueC, ok := value.(*data.GetTransactionResponse) + if !ok { + return http.StatusOK, nil + } + valueC.Data.Transaction = *txWithSCRs.SCRs[0] + + return http.StatusOK, nil + }, + } + tp, _ := process.NewTransactionProcessor( + processorStub, + testPubkeyConverter, + hasher, + marshalizer, + funcNewTxCostHandler, + logsMerger, + false, + ) + + status := tp.ComputeTransactionStatus(txWithSCRs.Transaction, true) + require.Equal(t, string(transaction.TxStatusPending), status.Status) + +} + func TestCheckIfFailed(t *testing.T) { t.Parallel()