From a11848caf4417bd66a1a8d176aa3f05a8e6f7c5f Mon Sep 17 00:00:00 2001 From: Liviu Ancas <83750585+liviuf-ancas@users.noreply.github.com> Date: Wed, 23 Oct 2024 14:31:38 +0300 Subject: [PATCH 01/16] Update Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 33ba0102..a3eb7170 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,7 @@ RUN apt-get update && apt-get install -y RUN useradd -m -u 1000 appuser USER appuser -COPY --from=builder /multiversx/cmd/elasticindexer /multiversx +COPY --from=builder --chown=appuser /multiversx/cmd/elasticindexer /multiversx EXPOSE 22111 From 956a1f23c5c1e565b60f5c46a1ccf73afbc172cb Mon Sep 17 00:00:00 2001 From: miiu Date: Mon, 18 Nov 2024 12:01:51 +0200 Subject: [PATCH 02/16] relayed v3 indexer integration --- data/transaction.go | 3 +- go.mod | 2 +- go.sum | 4 +- .../transactions/transactionDBBuilder.go | 6 ++ .../transactions/transactionDBBuilder_test.go | 74 +++++++++++++++++++ 5 files changed, 85 insertions(+), 4 deletions(-) diff --git a/data/transaction.go b/data/transaction.go index d0b41a9f..76060d3b 100644 --- a/data/transaction.go +++ b/data/transaction.go @@ -48,7 +48,8 @@ type Transaction struct { GuardianSignature string `json:"guardianSignature,omitempty"` ErrorEvent bool `json:"errorEvent,omitempty"` CompletedEvent bool `json:"completedEvent,omitempty"` - RelayedAddr string `json:"relayed,omitempty"` + RelayedAddr string `json:"relayer,omitempty"` + RelayedSignature string `json:"relayerSignature,omitempty"` ExecutionOrder int `json:"-"` SmartContractResults []*ScResult `json:"-"` Hash string `json:"-"` diff --git a/go.mod b/go.mod index eb32dd80..b040e945 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/gin-contrib/cors v1.4.0 github.com/gin-gonic/gin v1.9.1 github.com/multiversx/mx-chain-communication-go v1.1.0 - github.com/multiversx/mx-chain-core-go v1.2.21 + github.com/multiversx/mx-chain-core-go v1.2.24-0.20241029140551-8ed69b598c83 github.com/multiversx/mx-chain-logger-go v1.0.15 github.com/multiversx/mx-chain-vm-common-go v1.5.13 github.com/prometheus/client_model v0.4.0 diff --git a/go.sum b/go.sum index 82f3a0f7..178af96b 100644 --- a/go.sum +++ b/go.sum @@ -249,8 +249,8 @@ 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-communication-go v1.1.0 h1:J7bX6HoN3HiHY7cUeEjG8AJWgQDDPcY+OPDOsSUOkRE= github.com/multiversx/mx-chain-communication-go v1.1.0/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= -github.com/multiversx/mx-chain-core-go v1.2.21 h1:+XVKznPTlUU5EFS1A8chtS8fStW60upRIyF4Pgml19I= -github.com/multiversx/mx-chain-core-go v1.2.21/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.24-0.20241029140551-8ed69b598c83 h1:VuFFYZ9hpMacAcqcKM0hg6j4D16qKAGihi3X6PaF8qs= +github.com/multiversx/mx-chain-core-go v1.2.24-0.20241029140551-8ed69b598c83/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= 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= diff --git a/process/elasticproc/transactions/transactionDBBuilder.go b/process/elasticproc/transactions/transactionDBBuilder.go index c22fd07d..6a522b7a 100644 --- a/process/elasticproc/transactions/transactionDBBuilder.go +++ b/process/elasticproc/transactions/transactionDBBuilder.go @@ -83,6 +83,10 @@ func (dtb *dbTransactionBuilder) prepareTransaction( if len(tx.GuardianAddr) > 0 { guardianAddress = dtb.addressPubkeyConverter.SilentEncode(tx.GuardianAddr, log) } + relayedAddress := "" + if len(tx.RelayerAddr) > 0 { + relayedAddress = dtb.addressPubkeyConverter.SilentEncode(tx.RelayerAddr, log) + } senderUserName := converters.TruncateFieldIfExceedsMaxLengthBase64(string(tx.SndUserName)) receiverUserName := converters.TruncateFieldIfExceedsMaxLengthBase64(string(tx.RcvUserName)) @@ -119,6 +123,8 @@ func (dtb *dbTransactionBuilder) prepareTransaction( GuardianSignature: hex.EncodeToString(tx.GuardianSignature), ExecutionOrder: int(txInfo.ExecutionOrder), Operation: res.Operation, + RelayedSignature: hex.EncodeToString(tx.RelayerSignature), + RelayedAddr: relayedAddress, } eTx.Function = converters.TruncateFieldIfExceedsMaxLength(res.Function) diff --git a/process/elasticproc/transactions/transactionDBBuilder_test.go b/process/elasticproc/transactions/transactionDBBuilder_test.go index ceeca3de..0e3c9080 100644 --- a/process/elasticproc/transactions/transactionDBBuilder_test.go +++ b/process/elasticproc/transactions/transactionDBBuilder_test.go @@ -135,6 +135,80 @@ func TestGetTransactionByType_RewardTx(t *testing.T) { require.Equal(t, expectedTx, resultTx) } +func TestRelayedV3Transaction(t *testing.T) { + t.Parallel() + + txHash := []byte("txHash") + mbHash := []byte("mbHash") + mb := &block.MiniBlock{TxHashes: [][]byte{txHash}, Type: block.InvalidBlock} + header := &block.Header{Nonce: 2} + status := transaction.TxStatusInvalid.String() + gasPrice := uint64(1000) + gasLimit := uint64(1000) + cp := createCommonProcessor() + + tx := &transaction.Transaction{ + Nonce: 1, + Value: big.NewInt(1000), + RcvAddr: []byte("receiver"), + SndAddr: []byte("sender"), + GasPrice: gasPrice, + GasLimit: gasLimit, + Data: []byte("data"), + ChainID: []byte("1"), + Version: 1, + Signature: []byte("signature"), + RcvUserName: []byte("rcv"), + SndUserName: []byte("snd"), + RelayerAddr: []byte("relayer"), + RelayerSignature: []byte("relayerSignature"), + } + + expectedTx := &data.Transaction{ + Hash: hex.EncodeToString(txHash), + MBHash: hex.EncodeToString(mbHash), + Nonce: tx.Nonce, + Round: header.Round, + Value: tx.Value.String(), + ValueNum: 1e-15, + Receiver: cp.addressPubkeyConverter.SilentEncode(tx.RcvAddr, log), + Sender: cp.addressPubkeyConverter.SilentEncode(tx.SndAddr, log), + ReceiverShard: uint32(2), + SenderShard: mb.SenderShardID, + GasPrice: gasPrice, + GasLimit: gasLimit, + GasUsed: uint64(500), + InitialPaidFee: "100", + Data: tx.Data, + Signature: hex.EncodeToString(tx.Signature), + Timestamp: time.Duration(header.GetTimeStamp()), + Status: status, + Fee: "100", + FeeNum: 1e-16, + ReceiverUserName: []byte("rcv"), + SenderUserName: []byte("snd"), + Operation: "transfer", + Version: 1, + Receivers: []string{}, + ESDTValuesNum: []float64{}, + RelayedAddr: hex.EncodeToString(tx.RelayerAddr), + RelayedSignature: hex.EncodeToString(tx.RelayerSignature), + } + + txInfo := &outport.TxInfo{ + Transaction: tx, + FeeInfo: &outport.FeeInfo{ + GasUsed: 500, + Fee: big.NewInt(100), + InitialPaidFee: big.NewInt(100), + }, + ExecutionOrder: 0, + } + + dbTx := cp.prepareTransaction(txInfo, txHash, mbHash, mb, header, status, 3) + require.Equal(t, expectedTx, dbTx) +} + func TestGetMoveBalanceTransactionInvalid(t *testing.T) { t.Parallel() From 86138b42fec70cdc17bd0dd86c5ec16e3729e7e3 Mon Sep 17 00:00:00 2001 From: miiu Date: Fri, 22 Nov 2024 14:59:54 +0200 Subject: [PATCH 03/16] exclude dynamic meta esdt --- data/tokens.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/data/tokens.go b/data/tokens.go index e878facf..967e13ee 100644 --- a/data/tokens.go +++ b/data/tokens.go @@ -6,7 +6,10 @@ import ( "github.com/multiversx/mx-chain-core-go/core" ) -const metaESDT = "MetaESDT" +const ( + metaESDT = "MetaESDT" + dynamicMetaESDT = "DynamicMetaESDT" +) // NFTDataUpdate will contain the update information for an NFT or SFT type NFTDataUpdate struct { @@ -129,7 +132,7 @@ func (ti *tokensInfo) GetAll() []*TokenInfo { func (ti *tokensInfo) GetAllWithoutMetaESDT() []*TokenInfo { tokens := make([]*TokenInfo, 0) for _, tokenData := range ti.tokensInfo { - if tokenData.Type == metaESDT { + if tokenData.Type == metaESDT || tokenData.Type == dynamicMetaESDT { continue } From 7f83bb27c4a2592036d6aeafc3858c29d34dc860 Mon Sep 17 00:00:00 2001 From: miiu Date: Thu, 5 Dec 2024 12:51:06 +0200 Subject: [PATCH 04/16] revert changes transaction status --- process/elasticproc/logsevents/informativeLogsProcessor.go | 5 ----- process/elasticproc/transactions/serialize.go | 4 ---- 2 files changed, 9 deletions(-) diff --git a/process/elasticproc/logsevents/informativeLogsProcessor.go b/process/elasticproc/logsevents/informativeLogsProcessor.go index 8058d412..3e53cbd6 100644 --- a/process/elasticproc/logsevents/informativeLogsProcessor.go +++ b/process/elasticproc/logsevents/informativeLogsProcessor.go @@ -49,11 +49,6 @@ func (ilp *informativeLogsProcessor) processEvent(args *argsProcessEvent) argOut } } - setSuccess := tx.CompletedEvent && tx.ErrorEvent - if setSuccess { - tx.Status = transaction.TxStatusSuccess.String() - } - return argOutputProcessEvent{ processed: true, } diff --git a/process/elasticproc/transactions/serialize.go b/process/elasticproc/transactions/serialize.go index 939742a0..0c3a8803 100644 --- a/process/elasticproc/transactions/serialize.go +++ b/process/elasticproc/transactions/serialize.go @@ -136,10 +136,6 @@ func serializeTxHashStatus(buffSlice *data.BufferSlice, txHashStatusInfo map[str if (params.statusInfo.errorEvent) { ctx._source.errorEvent = params.statusInfo.errorEvent; } - - if ((ctx._source.completedEvent != null && ctx._source.completedEvent) && (ctx._source.errorEvent != null && ctx._source.errorEvent)) { - ctx._source.status = 'success'; - } ` serializedData := []byte(fmt.Sprintf(`{"script": {"source": "%s","lang": "painless","params": {"statusInfo": %s}}, "upsert": %s }`, converters.FormatPainlessSource(codeToExecute), string(marshaledStatusInfo), string(marshaledTx))) err = buffSlice.PutData(metaData, serializedData) From d14322627e18b615d3cfd4afdd2c0d58d6419711 Mon Sep 17 00:00:00 2001 From: miiu Date: Thu, 5 Dec 2024 15:06:44 +0200 Subject: [PATCH 05/16] integration test --- integrationtests/scDeploy_test.go | 85 +++++++++++++++++++ .../scDeploy/tx-deploy-with-error-event.json | 29 +++++++ 2 files changed, 114 insertions(+) create mode 100644 integrationtests/testdata/scDeploy/tx-deploy-with-error-event.json diff --git a/integrationtests/scDeploy_test.go b/integrationtests/scDeploy_test.go index 4a1603bb..646b8c47 100644 --- a/integrationtests/scDeploy_test.go +++ b/integrationtests/scDeploy_test.go @@ -201,3 +201,88 @@ func TestTransactionWithSCDeploy(t *testing.T) { string(genericResponse.Docs[0].Source), ) } + +func TestScDeployWithSignalErrorAndCompleteTxEvent(t *testing.T) { + setLogLevelDebug() + + esClient, err := createESClient(esURL) + require.Nil(t, err) + + esProc, err := CreateElasticProcessor(esClient) + require.Nil(t, err) + + txHash := []byte("scDeployHashWithErrorAndCompleteTxEvent") + header := &dataBlock.Header{ + Round: 50, + TimeStamp: 5040, + ShardID: 2, + } + body := &dataBlock.Body{ + MiniBlocks: dataBlock.MiniBlockSlice{ + { + Type: dataBlock.TxBlock, + SenderShardID: 2, + ReceiverShardID: 2, + TxHashes: [][]byte{txHash}, + }, + }, + } + sndAddress := "erd12m3x8jp6dl027pj5f2nw6ght2cyhhjfrs86cdwsa8xn83r375qfqrwpdx0" + tx := &transaction.Transaction{ + Nonce: 1, + SndAddr: decodeAddress(sndAddress), + RcvAddr: decodeAddress("erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6gq4hu"), + GasLimit: 1000000000, + GasPrice: 2000000, + Data: []byte("0061736d01000000010d036000006000017f60027f7f00023e0303656e760f6765744e756d417267756d656e7473000103656e760b7369676e616c4572726f72000203656e760e636865636b4e6f5061796d656e74000003030200000503010003060f027f00419980080b7f0041a080080b073705066d656d6f7279020004696e697400030863616c6c4261636b00040a5f5f646174615f656e6403000b5f5f686561705f6261736503010a180212001002100004404180800841191001000b0b0300010b0b210100418080080b1977726f6e67206e756d626572206f6620617267756d656e7473@0500@0502"), + Value: big.NewInt(0), + } + + txInfo := &outport.TxInfo{ + Transaction: tx, + FeeInfo: &outport.FeeInfo{ + GasUsed: 1130820, + Fee: big.NewInt(764698200000000), + InitialPaidFee: big.NewInt(773390000000000), + }, + ExecutionOrder: 0, + } + + pool := &outport.TransactionPool{ + Transactions: map[string]*outport.TxInfo{ + hex.EncodeToString(txHash): txInfo, + }, + Logs: []*outport.LogData{ + { + TxHash: hex.EncodeToString(txHash), + Log: &transaction.Log{ + Address: decodeAddress(sndAddress), + Events: []*transaction.Event{ + { + Address: decodeAddress(sndAddress), + Identifier: []byte(core.SignalErrorOperation), + Topics: [][]byte{decodeAddress("h1"), decodeAddress("h1"), []byte("h1")}, + }, + { + Address: decodeAddress(sndAddress), + Identifier: []byte(core.CompletedTxEventIdentifier), + Topics: [][]byte{decodeAddress("h2"), decodeAddress("h2"), []byte("h2")}, + }, + }, + }, + }, + }, + } + err = esProc.SaveTransactions(createOutportBlockWithHeader(body, header, pool, nil, testNumOfShards)) + require.Nil(t, err) + + genericResponse := &GenericResponse{} + ids := []string{hex.EncodeToString(txHash)} + err = esClient.DoMultiGet(context.Background(), ids, indexerData.OperationsIndex, true, genericResponse) + require.Nil(t, err) + + require.JSONEq(t, + readExpectedResult("./testdata/scDeploy/tx-deploy-with-error-event.json"), + string(genericResponse.Docs[0].Source), + ) +} diff --git a/integrationtests/testdata/scDeploy/tx-deploy-with-error-event.json b/integrationtests/testdata/scDeploy/tx-deploy-with-error-event.json new file mode 100644 index 00000000..1d1c44d4 --- /dev/null +++ b/integrationtests/testdata/scDeploy/tx-deploy-with-error-event.json @@ -0,0 +1,29 @@ +{ + "miniBlockHash": "4a0403ba564d86250446930d4917ad66ed68da53ae70c92b8cee3d731d68d2ae", + "nonce": 1, + "round": 50, + "value": "0", + "valueNum": 0, + "receiver": "erd1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq6gq4hu", + "sender": "erd12m3x8jp6dl027pj5f2nw6ght2cyhhjfrs86cdwsa8xn83r375qfqrwpdx0", + "receiverShard": 2, + "senderShard": 2, + "gasPrice": 2000000, + "gasLimit": 1000000000, + "gasUsed": 1130820, + "fee": "764698200000000", + "feeNum": 0.0007646982, + "initialPaidFee": "773390000000000", + "data": "MDA2MTczNmQwMTAwMDAwMDAxMGQwMzYwMDAwMDYwMDAwMTdmNjAwMjdmN2YwMDAyM2UwMzAzNjU2ZTc2MGY2NzY1NzQ0ZTc1NmQ0MTcyNjc3NTZkNjU2ZTc0NzMwMDAxMDM2NTZlNzYwYjczNjk2NzZlNjE2YzQ1NzI3MjZmNzIwMDAyMDM2NTZlNzYwZTYzNjg2NTYzNmI0ZTZmNTA2MTc5NmQ2NTZlNzQwMDAwMDMwMzAyMDAwMDA1MDMwMTAwMDMwNjBmMDI3ZjAwNDE5OTgwMDgwYjdmMDA0MWEwODAwODBiMDczNzA1MDY2ZDY1NmQ2ZjcyNzkwMjAwMDQ2OTZlNjk3NDAwMDMwODYzNjE2YzZjNDI2MTYzNmIwMDA0MGE1ZjVmNjQ2MTc0NjE1ZjY1NmU2NDAzMDAwYjVmNWY2ODY1NjE3MDVmNjI2MTczNjUwMzAxMGExODAyMTIwMDEwMDIxMDAwMDQ0MDQxODA4MDA4NDExOTEwMDEwMDBiMGIwMzAwMDEwYjBiMjEwMTAwNDE4MDgwMDgwYjE5Nzc3MjZmNmU2NzIwNmU3NTZkNjI2NTcyMjA2ZjY2MjA2MTcyNjc3NTZkNjU2ZTc0NzNAMDUwMEAwNTAy", + "signature": "", + "timestamp": 5040, + "status": "fail", + "searchOrder": 0, + "isScCall": true, + "hasOperations": true, + "hasLogs": true, + "type": "normal", + "operation": "scDeploy", + "errorEvent": true, + "completedEvent": true +} \ No newline at end of file From e6d4a77b4b4d4f7bdecdd1b736fb6955b57806e4 Mon Sep 17 00:00:00 2001 From: miiu Date: Thu, 5 Dec 2024 15:07:03 +0200 Subject: [PATCH 06/16] empty line --- .../testdata/scDeploy/tx-deploy-with-error-event.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrationtests/testdata/scDeploy/tx-deploy-with-error-event.json b/integrationtests/testdata/scDeploy/tx-deploy-with-error-event.json index 1d1c44d4..1229065c 100644 --- a/integrationtests/testdata/scDeploy/tx-deploy-with-error-event.json +++ b/integrationtests/testdata/scDeploy/tx-deploy-with-error-event.json @@ -26,4 +26,4 @@ "operation": "scDeploy", "errorEvent": true, "completedEvent": true -} \ No newline at end of file +} From 98010733c68ba1b9d6282a2968aa8355f426a07e Mon Sep 17 00:00:00 2001 From: miiu Date: Thu, 5 Dec 2024 15:09:39 +0200 Subject: [PATCH 07/16] fixes --- integrationtests/scDeploy_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integrationtests/scDeploy_test.go b/integrationtests/scDeploy_test.go index 646b8c47..6964030a 100644 --- a/integrationtests/scDeploy_test.go +++ b/integrationtests/scDeploy_test.go @@ -261,12 +261,12 @@ func TestScDeployWithSignalErrorAndCompleteTxEvent(t *testing.T) { { Address: decodeAddress(sndAddress), Identifier: []byte(core.SignalErrorOperation), - Topics: [][]byte{decodeAddress("h1"), decodeAddress("h1"), []byte("h1")}, + Topics: [][]byte{[]byte("h1"), []byte("h1"), []byte("h1")}, }, { Address: decodeAddress(sndAddress), Identifier: []byte(core.CompletedTxEventIdentifier), - Topics: [][]byte{decodeAddress("h2"), decodeAddress("h2"), []byte("h2")}, + Topics: [][]byte{[]byte("h2"), []byte("h2"), []byte("h2")}, }, }, }, From ceaca49de8e18886aeec03f2d025b413cd633d4f Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 9 Jan 2025 17:17:11 +0200 Subject: [PATCH 08/16] updated core-go --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index b040e945..ceddddaa 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/gin-contrib/cors v1.4.0 github.com/gin-gonic/gin v1.9.1 github.com/multiversx/mx-chain-communication-go v1.1.0 - github.com/multiversx/mx-chain-core-go v1.2.24-0.20241029140551-8ed69b598c83 + github.com/multiversx/mx-chain-core-go v1.2.24-0.20250109151319-81a62c045af8 github.com/multiversx/mx-chain-logger-go v1.0.15 github.com/multiversx/mx-chain-vm-common-go v1.5.13 github.com/prometheus/client_model v0.4.0 diff --git a/go.sum b/go.sum index 178af96b..f9acb8db 100644 --- a/go.sum +++ b/go.sum @@ -249,8 +249,8 @@ 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-communication-go v1.1.0 h1:J7bX6HoN3HiHY7cUeEjG8AJWgQDDPcY+OPDOsSUOkRE= github.com/multiversx/mx-chain-communication-go v1.1.0/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= -github.com/multiversx/mx-chain-core-go v1.2.24-0.20241029140551-8ed69b598c83 h1:VuFFYZ9hpMacAcqcKM0hg6j4D16qKAGihi3X6PaF8qs= -github.com/multiversx/mx-chain-core-go v1.2.24-0.20241029140551-8ed69b598c83/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.24-0.20250109151319-81a62c045af8 h1:0ivlwcl+dKK7BTVngm1uNM2aDneaXK2rhS0HVeBkvYg= +github.com/multiversx/mx-chain-core-go v1.2.24-0.20250109151319-81a62c045af8/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= 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= From 0d2cff53280d2ad07630cac6675f0d8480b0aedb Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 15 Jan 2025 15:14:32 +0200 Subject: [PATCH 09/16] multiple scrs with refund --- data/scresult.go | 1 + data/transaction.go | 9 +- go.mod | 2 +- go.sum | 4 +- integrationtests/relayedV3_test.go | 139 ++++++++++++++++++ .../relayedTxV3/relayed-v3-no-refund.json | 28 ++++ .../relayed-v3-with-one-refund.json | 28 ++++ .../relayed-v3-with-two-refunds.json | 28 ++++ .../transactions/scrsDataToTransactions.go | 11 +- process/elasticproc/transactions/serialize.go | 28 +++- .../transactions/serialize_test.go | 2 +- .../smartContractResultsProcessor.go | 1 + .../transactions/transactionDBBuilder.go | 6 +- 13 files changed, 270 insertions(+), 17 deletions(-) create mode 100644 integrationtests/relayedV3_test.go create mode 100644 integrationtests/testdata/relayedTxV3/relayed-v3-no-refund.json create mode 100644 integrationtests/testdata/relayedTxV3/relayed-v3-with-one-refund.json create mode 100644 integrationtests/testdata/relayedTxV3/relayed-v3-with-two-refunds.json diff --git a/data/scresult.go b/data/scresult.go index b246528d..95a71c5c 100644 --- a/data/scresult.go +++ b/data/scresult.go @@ -43,4 +43,5 @@ type ScResult struct { SenderAddressBytes []byte `json:"-"` InitialTxGasUsed uint64 `json:"-"` InitialTxFee string `json:"-"` + GasRefunded uint64 `json:"-"` } diff --git a/data/transaction.go b/data/transaction.go index 76060d3b..f923ec54 100644 --- a/data/transaction.go +++ b/data/transaction.go @@ -89,8 +89,9 @@ type ResponseTransactionDB struct { // FeeData is the structure that contains data about transaction fee and gas used type FeeData struct { - FeeNum float64 - Fee string - GasUsed uint64 - Receiver string + FeeNum float64 + Fee string + GasUsed uint64 + Receiver string + GasRefunded uint64 } diff --git a/go.mod b/go.mod index ceddddaa..dea4b419 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/gin-contrib/cors v1.4.0 github.com/gin-gonic/gin v1.9.1 github.com/multiversx/mx-chain-communication-go v1.1.0 - github.com/multiversx/mx-chain-core-go v1.2.24-0.20250109151319-81a62c045af8 + github.com/multiversx/mx-chain-core-go v1.2.24-0.20250115104420-0580ffeedb71 github.com/multiversx/mx-chain-logger-go v1.0.15 github.com/multiversx/mx-chain-vm-common-go v1.5.13 github.com/prometheus/client_model v0.4.0 diff --git a/go.sum b/go.sum index f9acb8db..ae842c5d 100644 --- a/go.sum +++ b/go.sum @@ -249,8 +249,8 @@ 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-communication-go v1.1.0 h1:J7bX6HoN3HiHY7cUeEjG8AJWgQDDPcY+OPDOsSUOkRE= github.com/multiversx/mx-chain-communication-go v1.1.0/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= -github.com/multiversx/mx-chain-core-go v1.2.24-0.20250109151319-81a62c045af8 h1:0ivlwcl+dKK7BTVngm1uNM2aDneaXK2rhS0HVeBkvYg= -github.com/multiversx/mx-chain-core-go v1.2.24-0.20250109151319-81a62c045af8/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.24-0.20250115104420-0580ffeedb71 h1:UZODeK+VpQxtLKaRU0iubQ9Jm1HIobFEXIf4N4Nvkwg= +github.com/multiversx/mx-chain-core-go v1.2.24-0.20250115104420-0580ffeedb71/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= 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= diff --git a/integrationtests/relayedV3_test.go b/integrationtests/relayedV3_test.go new file mode 100644 index 00000000..d7be24d1 --- /dev/null +++ b/integrationtests/relayedV3_test.go @@ -0,0 +1,139 @@ +//go:build integrationtests + +package integrationtests + +import ( + "context" + "encoding/hex" + "math/big" + "testing" + + dataBlock "github.com/multiversx/mx-chain-core-go/data/block" + "github.com/multiversx/mx-chain-core-go/data/outport" + "github.com/multiversx/mx-chain-core-go/data/smartContractResult" + "github.com/multiversx/mx-chain-core-go/data/transaction" + indexerdata "github.com/multiversx/mx-chain-es-indexer-go/process/dataindexer" + "github.com/stretchr/testify/require" +) + +func TestRelayedV3TransactionWithMultipleRefunds(t *testing.T) { + setLogLevelDebug() + + esClient, err := createESClient(esURL) + require.Nil(t, err) + + esProc, err := CreateElasticProcessor(esClient) + require.Nil(t, err) + + txHash := []byte("relayedTxV3WithMultipleRefunds") + header := &dataBlock.Header{ + Round: 50, + TimeStamp: 5040, + } + + body := &dataBlock.Body{ + MiniBlocks: dataBlock.MiniBlockSlice{ + { + Type: dataBlock.TxBlock, + SenderShardID: 0, + ReceiverShardID: 0, + TxHashes: [][]byte{txHash}, + }, + }, + } + + initialTx := &transaction.Transaction{ + Nonce: 1000, + SndAddr: decodeAddress("erd1ykqd64fxxpp4wsz0v7sjqem038wfpzlljhx4mhwx8w9lcxmdzcfszrp64a"), + RcvAddr: decodeAddress("erd1qqqqqqqqqqqqqpgqak8zt22wl2ph4tswtyc39namqx6ysa2sd8ss4xmlj3"), + RelayerAddr: decodeAddress("erd10ksryjr065ad5475jcg82pnjfg9j9qtszjsrp24anl6ym7cmeddshwnru8"), + Signature: []byte("d"), + RelayerSignature: []byte("a"), + GasLimit: 500_000_000, + GasPrice: 1000000000, + Value: big.NewInt(0), + Data: []byte("doSomething"), + } + + txInfo := &outport.TxInfo{ + Transaction: initialTx, + FeeInfo: &outport.FeeInfo{ + GasUsed: 180_150_000, + Fee: big.NewInt(2864760000000000), + InitialPaidFee: big.NewInt(2864760000000000), + }, + ExecutionOrder: 0, + } + + pool := &outport.TransactionPool{ + Transactions: map[string]*outport.TxInfo{ + hex.EncodeToString(txHash): txInfo, + }, + } + err = esProc.SaveTransactions(createOutportBlockWithHeader(body, header, pool, nil, testNumOfShards)) + require.Nil(t, err) + + ids := []string{hex.EncodeToString(txHash)} + genericResponse := &GenericResponse{} + err = esClient.DoMultiGet(context.Background(), ids, indexerdata.TransactionsIndex, true, genericResponse) + require.Nil(t, err) + + require.JSONEq(t, + readExpectedResult("./testdata/relayedTxV3/relayed-v3-no-refund.json"), + string(genericResponse.Docs[0].Source), + ) + + // execute first SCR with refund + pool = &outport.TransactionPool{ + SmartContractResults: map[string]*outport.SCRInfo{ + "scrHash": { + SmartContractResult: &smartContractResult.SmartContractResult{ + OriginalTxHash: txHash, + }, + FeeInfo: &outport.FeeInfo{ + GasRefunded: 9_692_000, + Fee: big.NewInt(96920000000000), + }, + }, + }, + } + err = esProc.SaveTransactions(createOutportBlockWithHeader(body, header, pool, nil, testNumOfShards)) + require.Nil(t, err) + + ids = []string{hex.EncodeToString(txHash)} + genericResponse = &GenericResponse{} + err = esClient.DoMultiGet(context.Background(), ids, indexerdata.TransactionsIndex, true, genericResponse) + require.Nil(t, err) + + require.JSONEq(t, + readExpectedResult("./testdata/relayedTxV3/relayed-v3-with-one-refund.json"), + string(genericResponse.Docs[0].Source), + ) + + // execute second SCR with refund + pool = &outport.TransactionPool{ + SmartContractResults: map[string]*outport.SCRInfo{ + "scrHash": { + SmartContractResult: &smartContractResult.SmartContractResult{ + OriginalTxHash: txHash, + }, + FeeInfo: &outport.FeeInfo{ + GasRefunded: 9_692_000, + Fee: big.NewInt(96920000000000), + }, + }, + }, + } + err = esProc.SaveTransactions(createOutportBlockWithHeader(body, header, pool, nil, testNumOfShards)) + require.Nil(t, err) + + ids = []string{hex.EncodeToString(txHash)} + genericResponse = &GenericResponse{} + err = esClient.DoMultiGet(context.Background(), ids, indexerdata.TransactionsIndex, true, genericResponse) + require.Nil(t, err) + + require.JSONEq(t, + readExpectedResult("./testdata/relayedTxV3/relayed-v3-with-two-refunds.json"), + string(genericResponse.Docs[0].Source), + ) +} diff --git a/integrationtests/testdata/relayedTxV3/relayed-v3-no-refund.json b/integrationtests/testdata/relayedTxV3/relayed-v3-no-refund.json new file mode 100644 index 00000000..e4c03f30 --- /dev/null +++ b/integrationtests/testdata/relayedTxV3/relayed-v3-no-refund.json @@ -0,0 +1,28 @@ +{ + "miniBlockHash": "785a251c08b314939528e553ac879dbee0627fbe2b76c0bca601c3f1e7162640", + "nonce": 1000, + "round": 50, + "value": "0", + "valueNum": 0, + "receiver": "erd1qqqqqqqqqqqqqpgqak8zt22wl2ph4tswtyc39namqx6ysa2sd8ss4xmlj3", + "sender": "erd1ykqd64fxxpp4wsz0v7sjqem038wfpzlljhx4mhwx8w9lcxmdzcfszrp64a", + "receiverShard": 0, + "senderShard": 0, + "gasPrice": 1000000000, + "gasLimit": 500000000, + "gasUsed": 180150000, + "fee": "2864760000000000", + "feeNum": 0.00286476, + "initialPaidFee": "2864760000000000", + "data": "ZG9Tb21ldGhpbmc=", + "signature": "64", + "timestamp": 5040, + "status": "success", + "searchOrder": 0, + "isScCall": true, + "operation": "transfer", + "function": "doSomething", + "isRelayed": true, + "relayer": "erd10ksryjr065ad5475jcg82pnjfg9j9qtszjsrp24anl6ym7cmeddshwnru8", + "relayerSignature": "61" +} diff --git a/integrationtests/testdata/relayedTxV3/relayed-v3-with-one-refund.json b/integrationtests/testdata/relayedTxV3/relayed-v3-with-one-refund.json new file mode 100644 index 00000000..9db41c27 --- /dev/null +++ b/integrationtests/testdata/relayedTxV3/relayed-v3-with-one-refund.json @@ -0,0 +1,28 @@ +{ + "miniBlockHash": "785a251c08b314939528e553ac879dbee0627fbe2b76c0bca601c3f1e7162640", + "nonce": 1000, + "round": 50, + "value": "0", + "valueNum": 0, + "receiver": "erd1qqqqqqqqqqqqqpgqak8zt22wl2ph4tswtyc39namqx6ysa2sd8ss4xmlj3", + "sender": "erd1ykqd64fxxpp4wsz0v7sjqem038wfpzlljhx4mhwx8w9lcxmdzcfszrp64a", + "receiverShard": 0, + "senderShard": 0, + "gasPrice": 1000000000, + "gasLimit": 500000000, + "gasUsed": 170458000, + "fee": "2767840000000000", + "feeNum": 0.00276784, + "initialPaidFee": "2864760000000000", + "data": "ZG9Tb21ldGhpbmc=", + "signature": "64", + "timestamp": 5040, + "status": "success", + "searchOrder": 0, + "isScCall": true, + "operation": "transfer", + "function": "doSomething", + "isRelayed": true, + "relayer": "erd10ksryjr065ad5475jcg82pnjfg9j9qtszjsrp24anl6ym7cmeddshwnru8", + "relayerSignature": "61" +} diff --git a/integrationtests/testdata/relayedTxV3/relayed-v3-with-two-refunds.json b/integrationtests/testdata/relayedTxV3/relayed-v3-with-two-refunds.json new file mode 100644 index 00000000..6b291b63 --- /dev/null +++ b/integrationtests/testdata/relayedTxV3/relayed-v3-with-two-refunds.json @@ -0,0 +1,28 @@ +{ + "miniBlockHash": "785a251c08b314939528e553ac879dbee0627fbe2b76c0bca601c3f1e7162640", + "nonce": 1000, + "round": 50, + "value": "0", + "valueNum": 0, + "receiver": "erd1qqqqqqqqqqqqqpgqak8zt22wl2ph4tswtyc39namqx6ysa2sd8ss4xmlj3", + "sender": "erd1ykqd64fxxpp4wsz0v7sjqem038wfpzlljhx4mhwx8w9lcxmdzcfszrp64a", + "receiverShard": 0, + "senderShard": 0, + "gasPrice": 1000000000, + "gasLimit": 500000000, + "gasUsed": 160766000, + "fee": "2670920000000000", + "feeNum": 0.0026709200000000002, + "initialPaidFee": "2864760000000000", + "data": "ZG9Tb21ldGhpbmc=", + "signature": "64", + "timestamp": 5040, + "status": "success", + "searchOrder": 0, + "isScCall": true, + "operation": "transfer", + "function": "doSomething", + "isRelayed": true, + "relayer": "erd10ksryjr065ad5475jcg82pnjfg9j9qtszjsrp24anl6ym7cmeddshwnru8", + "relayerSignature": "61" +} diff --git a/process/elasticproc/transactions/scrsDataToTransactions.go b/process/elasticproc/transactions/scrsDataToTransactions.go index f18aa741..af2a5148 100644 --- a/process/elasticproc/transactions/scrsDataToTransactions.go +++ b/process/elasticproc/transactions/scrsDataToTransactions.go @@ -54,7 +54,7 @@ func (st *scrsDataToTransactions) processTransactionsAfterSCRsWereAttached(trans func (st *scrsDataToTransactions) processSCRsWithoutTx(scrs []*data.ScResult) map[string]*data.FeeData { txHashRefund := make(map[string]*data.FeeData) for _, scr := range scrs { - if scr.InitialTxGasUsed == 0 { + if scr.InitialTxGasUsed == 0 && scr.GasRefunded == 0 { continue } @@ -70,10 +70,11 @@ func (st *scrsDataToTransactions) processSCRsWithoutTx(scrs []*data.ScResult) ma } txHashRefund[scr.OriginalTxHash] = &data.FeeData{ - FeeNum: feeNum, - Fee: scr.InitialTxFee, - GasUsed: scr.InitialTxGasUsed, - Receiver: scr.Receiver, + FeeNum: feeNum, + Fee: scr.InitialTxFee, + GasUsed: scr.InitialTxGasUsed, + Receiver: scr.Receiver, + GasRefunded: scr.GasRefunded, } } diff --git a/process/elasticproc/transactions/serialize.go b/process/elasticproc/transactions/serialize.go index 0c3a8803..793ec40b 100644 --- a/process/elasticproc/transactions/serialize.go +++ b/process/elasticproc/transactions/serialize.go @@ -51,7 +51,28 @@ func (tdp *txsDatabaseProcessor) SerializeReceipts(receipts []*data.Receipt, buf func (tdp *txsDatabaseProcessor) SerializeTransactionsFeeData(txHashRefund map[string]*data.FeeData, buffSlice *data.BufferSlice, index string) error { for txHash, feeData := range txHashRefund { meta := []byte(fmt.Sprintf(`{"update":{ "_index":"%s","_id":"%s"}}%s`, index, converters.JsonEscape(txHash), "\n")) - codeToExecute := ` + + var codeToExecute string + if feeData.GasRefunded != 0 { + codeToExecute = ` + if ('create' == ctx.op) { + ctx.op = 'noop' + } else { + BigInteger feeFromSource = new BigInteger(ctx._source.fee); + BigInteger fee = new BigInteger(params.fee); + if (feeFromSource.compareTo(fee) > 0) { + ctx._source.fee = feeFromSource.subtract(fee).toString(); + } + if (ctx._source.feeNum > params.feeNum) { + ctx._source.feeNum -= params.feeNum; + } + if (ctx._source.gasUsed > params.gasRefunded) { + ctx._source.gasUsed -= params.gasRefunded; + } + } + ` + } else { + codeToExecute = ` if ('create' == ctx.op) { ctx.op = 'noop' } else { @@ -60,13 +81,14 @@ func (tdp *txsDatabaseProcessor) SerializeTransactionsFeeData(txHashRefund map[s ctx._source.gasUsed = params.gasUsed; } ` + } serializedDataStr := fmt.Sprintf(`{"scripted_upsert": true, "script": {`+ `"source": "%s",`+ `"lang": "painless",`+ - `"params": {"fee": "%s", "gasUsed": %d, "feeNum": %g}},`+ + `"params": {"fee": "%s", "gasUsed": %d, "feeNum": %g, "gasRefunded": %d}},`+ `"upsert": {}}`, - converters.FormatPainlessSource(codeToExecute), feeData.Fee, feeData.GasUsed, feeData.FeeNum, + converters.FormatPainlessSource(codeToExecute), feeData.Fee, feeData.GasUsed, feeData.FeeNum, feeData.GasRefunded, ) err := buffSlice.PutData(meta, []byte(serializedDataStr)) diff --git a/process/elasticproc/transactions/serialize_test.go b/process/elasticproc/transactions/serialize_test.go index 1565ee2d..b4e2bf96 100644 --- a/process/elasticproc/transactions/serialize_test.go +++ b/process/elasticproc/transactions/serialize_test.go @@ -146,7 +146,7 @@ func TestTxsDatabaseProcessor_SerializeTransactionWithRefund(t *testing.T) { require.Nil(t, err) expectedBuff := `{"update":{ "_index":"transactions","_id":"txHash"}} -{"scripted_upsert": true, "script": {"source": "if ('create' == ctx.op) {ctx.op = 'noop'} else {ctx._source.fee = params.fee;ctx._source.feeNum = params.feeNum;ctx._source.gasUsed = params.gasUsed;}","lang": "painless","params": {"fee": "100000", "gasUsed": 5000, "feeNum": 5e-15}},"upsert": {}} +{"scripted_upsert": true, "script": {"source": "if ('create' == ctx.op) {ctx.op = 'noop'} else {ctx._source.fee = params.fee;ctx._source.feeNum = params.feeNum;ctx._source.gasUsed = params.gasUsed;}","lang": "painless","params": {"fee": "100000", "gasUsed": 5000, "feeNum": 5e-15, "gasRefunded": 0}},"upsert": {}} ` require.Equal(t, expectedBuff, buffSlice.Buffers()[0].String()) } diff --git a/process/elasticproc/transactions/smartContractResultsProcessor.go b/process/elasticproc/transactions/smartContractResultsProcessor.go index 2fcb7ccf..ce52062a 100644 --- a/process/elasticproc/transactions/smartContractResultsProcessor.go +++ b/process/elasticproc/transactions/smartContractResultsProcessor.go @@ -189,6 +189,7 @@ func (proc *smartContractResultsProcessor) prepareSmartContractResult( OriginalSender: originalSenderAddr, InitialTxFee: feeInfo.Fee.String(), InitialTxGasUsed: feeInfo.GasUsed, + GasRefunded: feeInfo.GasRefunded, ExecutionOrder: int(scrInfo.ExecutionOrder), } } diff --git a/process/elasticproc/transactions/transactionDBBuilder.go b/process/elasticproc/transactions/transactionDBBuilder.go index 6a522b7a..04560e41 100644 --- a/process/elasticproc/transactions/transactionDBBuilder.go +++ b/process/elasticproc/transactions/transactionDBBuilder.go @@ -127,10 +127,14 @@ func (dtb *dbTransactionBuilder) prepareTransaction( RelayedAddr: relayedAddress, } + hasValidRelayer := len(eTx.RelayedAddr) == len(eTx.Sender) && len(eTx.RelayedAddr) > 0 + hasValidRelayerSignature := len(eTx.RelayedSignature) == len(eTx.Signature) && len(eTx.RelayedSignature) > 0 + isRelayedV3 := hasValidRelayer && hasValidRelayerSignature + eTx.Function = converters.TruncateFieldIfExceedsMaxLength(res.Function) eTx.Tokens = converters.TruncateSliceElementsIfExceedsMaxLength(res.Tokens) eTx.ReceiversShardIDs = res.ReceiversShardID - eTx.IsRelayed = res.IsRelayed + eTx.IsRelayed = res.IsRelayed || isRelayedV3 return eTx } From 62f5c3451bedb89a941f38018b248e4b803b63f5 Mon Sep 17 00:00:00 2001 From: miiu Date: Thu, 16 Jan 2025 10:19:16 +0200 Subject: [PATCH 10/16] had refund --- data/transaction.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- .../testdata/relayedTxV3/relayed-v3-with-one-refund.json | 3 ++- .../relayedTxV3/relayed-v3-with-two-refunds.json | 3 ++- process/elasticproc/transactions/serialize.go | 9 ++++++++- process/elasticproc/transactions/transactionDBBuilder.go | 1 + 7 files changed, 17 insertions(+), 7 deletions(-) diff --git a/data/transaction.go b/data/transaction.go index f923ec54..0837a590 100644 --- a/data/transaction.go +++ b/data/transaction.go @@ -50,11 +50,11 @@ type Transaction struct { CompletedEvent bool `json:"completedEvent,omitempty"` RelayedAddr string `json:"relayer,omitempty"` RelayedSignature string `json:"relayerSignature,omitempty"` + HadRefund bool `json:"hadRefund,omitempty"` ExecutionOrder int `json:"-"` SmartContractResults []*ScResult `json:"-"` Hash string `json:"-"` BlockHash string `json:"-"` - HadRefund bool `json:"-"` } // Receipt is a structure containing all the fields that need to be safe for a Receipt diff --git a/go.mod b/go.mod index dea4b419..7962721f 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/gin-contrib/cors v1.4.0 github.com/gin-gonic/gin v1.9.1 github.com/multiversx/mx-chain-communication-go v1.1.0 - github.com/multiversx/mx-chain-core-go v1.2.24-0.20250115104420-0580ffeedb71 + github.com/multiversx/mx-chain-core-go v1.2.24-0.20250116081327-adb8c08089b4 github.com/multiversx/mx-chain-logger-go v1.0.15 github.com/multiversx/mx-chain-vm-common-go v1.5.13 github.com/prometheus/client_model v0.4.0 diff --git a/go.sum b/go.sum index ae842c5d..693b9fb2 100644 --- a/go.sum +++ b/go.sum @@ -249,8 +249,8 @@ 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-communication-go v1.1.0 h1:J7bX6HoN3HiHY7cUeEjG8AJWgQDDPcY+OPDOsSUOkRE= github.com/multiversx/mx-chain-communication-go v1.1.0/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= -github.com/multiversx/mx-chain-core-go v1.2.24-0.20250115104420-0580ffeedb71 h1:UZODeK+VpQxtLKaRU0iubQ9Jm1HIobFEXIf4N4Nvkwg= -github.com/multiversx/mx-chain-core-go v1.2.24-0.20250115104420-0580ffeedb71/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.24-0.20250116081327-adb8c08089b4 h1:rWYFL38q5cbo5MtdW2DvAp4+WMaVp8e7gBjmrLQ9SCY= +github.com/multiversx/mx-chain-core-go v1.2.24-0.20250116081327-adb8c08089b4/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= 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= diff --git a/integrationtests/testdata/relayedTxV3/relayed-v3-with-one-refund.json b/integrationtests/testdata/relayedTxV3/relayed-v3-with-one-refund.json index 9db41c27..d8aee273 100644 --- a/integrationtests/testdata/relayedTxV3/relayed-v3-with-one-refund.json +++ b/integrationtests/testdata/relayedTxV3/relayed-v3-with-one-refund.json @@ -24,5 +24,6 @@ "function": "doSomething", "isRelayed": true, "relayer": "erd10ksryjr065ad5475jcg82pnjfg9j9qtszjsrp24anl6ym7cmeddshwnru8", - "relayerSignature": "61" + "relayerSignature": "61", + "hadRefund": true } diff --git a/integrationtests/testdata/relayedTxV3/relayed-v3-with-two-refunds.json b/integrationtests/testdata/relayedTxV3/relayed-v3-with-two-refunds.json index 6b291b63..b060be66 100644 --- a/integrationtests/testdata/relayedTxV3/relayed-v3-with-two-refunds.json +++ b/integrationtests/testdata/relayedTxV3/relayed-v3-with-two-refunds.json @@ -24,5 +24,6 @@ "function": "doSomething", "isRelayed": true, "relayer": "erd10ksryjr065ad5475jcg82pnjfg9j9qtszjsrp24anl6ym7cmeddshwnru8", - "relayerSignature": "61" + "relayerSignature": "61", + "hadRefund": true } diff --git a/process/elasticproc/transactions/serialize.go b/process/elasticproc/transactions/serialize.go index 793ec40b..4cd6bf3f 100644 --- a/process/elasticproc/transactions/serialize.go +++ b/process/elasticproc/transactions/serialize.go @@ -58,7 +58,14 @@ func (tdp *txsDatabaseProcessor) SerializeTransactionsFeeData(txHashRefund map[s if ('create' == ctx.op) { ctx.op = 'noop' } else { - BigInteger feeFromSource = new BigInteger(ctx._source.fee); + BigInteger feeFromSource; + if ((ctx._source.containsKey('hadRefund')) && (ctx._source.hadRefund)) { + feeFromSource = new BigInteger(ctx._source.fee); + } else { + feeFromSource = new BigInteger(ctx._source.initialPaidFee); + ctx._source.hadRefund = true; + } + BigInteger fee = new BigInteger(params.fee); if (feeFromSource.compareTo(fee) > 0) { ctx._source.fee = feeFromSource.subtract(fee).toString(); diff --git a/process/elasticproc/transactions/transactionDBBuilder.go b/process/elasticproc/transactions/transactionDBBuilder.go index 04560e41..3aab4884 100644 --- a/process/elasticproc/transactions/transactionDBBuilder.go +++ b/process/elasticproc/transactions/transactionDBBuilder.go @@ -125,6 +125,7 @@ func (dtb *dbTransactionBuilder) prepareTransaction( Operation: res.Operation, RelayedSignature: hex.EncodeToString(tx.RelayerSignature), RelayedAddr: relayedAddress, + HadRefund: feeInfo.HadRefund, } hasValidRelayer := len(eTx.RelayedAddr) == len(eTx.Sender) && len(eTx.RelayedAddr) > 0 From e8de81a7059facd0728186308e48bc0cc519e4a5 Mon Sep 17 00:00:00 2001 From: Sorin Stanculeanu Date: Thu, 16 Jan 2025 13:30:14 +0200 Subject: [PATCH 11/16] updated core go --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 7962721f..e6d26bc2 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/gin-contrib/cors v1.4.0 github.com/gin-gonic/gin v1.9.1 github.com/multiversx/mx-chain-communication-go v1.1.0 - github.com/multiversx/mx-chain-core-go v1.2.24-0.20250116081327-adb8c08089b4 + github.com/multiversx/mx-chain-core-go v1.2.24 github.com/multiversx/mx-chain-logger-go v1.0.15 github.com/multiversx/mx-chain-vm-common-go v1.5.13 github.com/prometheus/client_model v0.4.0 diff --git a/go.sum b/go.sum index 693b9fb2..339a4473 100644 --- a/go.sum +++ b/go.sum @@ -249,8 +249,8 @@ 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-communication-go v1.1.0 h1:J7bX6HoN3HiHY7cUeEjG8AJWgQDDPcY+OPDOsSUOkRE= github.com/multiversx/mx-chain-communication-go v1.1.0/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= -github.com/multiversx/mx-chain-core-go v1.2.24-0.20250116081327-adb8c08089b4 h1:rWYFL38q5cbo5MtdW2DvAp4+WMaVp8e7gBjmrLQ9SCY= -github.com/multiversx/mx-chain-core-go v1.2.24-0.20250116081327-adb8c08089b4/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.24 h1:O0X7N9GfNVUCE9fukXA+dvfCRRjViYn88zOaE7feUog= +github.com/multiversx/mx-chain-core-go v1.2.24/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= 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= From 92a0eb00134c73a7fc4c2eb66eddd8e7c559a421 Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 22 Jan 2025 15:05:31 +0200 Subject: [PATCH 12/16] extra info error message --- client/data.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/data.go b/client/data.go index def58106..8b8314c3 100644 --- a/client/data.go +++ b/client/data.go @@ -28,8 +28,10 @@ type Item struct { Type string `json:"type"` Reason string `json:"reason"` Cause struct { - Type string `json:"type"` - Reason string `json:"reason"` + Type string `json:"type"` + Reason string `json:"reason"` + ScriptStack []string `json:"script_stack"` + Script string `json:"script"` } `json:"caused_by"` } `json:"error"` } From c658f09cc04341de9eb7076804a84de7572a3678 Mon Sep 17 00:00:00 2001 From: miiu Date: Wed, 22 Jan 2025 18:13:11 +0200 Subject: [PATCH 13/16] log error --- client/elasticClientCommon.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/elasticClientCommon.go b/client/elasticClientCommon.go index 41ed1034..553ca048 100644 --- a/client/elasticClientCommon.go +++ b/client/elasticClientCommon.go @@ -134,8 +134,8 @@ func extractErrorFromBulkBodyResponseBytes(bodyBytes []byte) error { } count++ - errorsString += fmt.Sprintf(`{ "index": "%s", "id": "%s", "statusCode": %d, "errorType": "%s", "reason": "%s", "causedBy": { "type": "%s", "reason": "%s" }}\n`, - selectedItem.Index, selectedItem.ID, selectedItem.Status, selectedItem.Error.Type, selectedItem.Error.Reason, selectedItem.Error.Cause.Type, selectedItem.Error.Cause.Reason) + errorsString += fmt.Sprintf(`{ "index": "%s", "id": "%s", "statusCode": %d, "errorType": "%s", "reason": "%s", "causedBy": { "type": "%s", "reason": "%s", "script_stack":"%s", "script":"%s" }}\n`, + selectedItem.Index, selectedItem.ID, selectedItem.Status, selectedItem.Error.Type, selectedItem.Error.Reason, selectedItem.Error.Cause.Type, selectedItem.Error.Cause.Reason, selectedItem.Error.Cause.ScriptStack, selectedItem.Error.Cause.Script) if count == numOfErrorsToExtractBulkResponse { break From b9d3793de7eb9501c66b15eef1f7c00a80a031d0 Mon Sep 17 00:00:00 2001 From: miiu Date: Thu, 23 Jan 2025 11:48:46 +0200 Subject: [PATCH 14/16] fixes --- process/elasticproc/transactions/serialize.go | 5 +++++ process/elasticproc/transactions/transactionsProcessor.go | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/process/elasticproc/transactions/serialize.go b/process/elasticproc/transactions/serialize.go index 4cd6bf3f..0f9b57a3 100644 --- a/process/elasticproc/transactions/serialize.go +++ b/process/elasticproc/transactions/serialize.go @@ -58,6 +58,11 @@ func (tdp *txsDatabaseProcessor) SerializeTransactionsFeeData(txHashRefund map[s if ('create' == ctx.op) { ctx.op = 'noop' } else { + boolean ok1 = ((ctx._source.containsKey('initialPaidFee')) && (ctx._source.initialPaidFee != null) && (!ctx._source.initialPaidFee.isEmpty())); + boolean ok2 = ((ctx._source.containsKey('fee')) && (ctx._source.fee != null) && (!ctx._source.fee.isEmpty())); + if (!ok1 || !ok2) { + return + } BigInteger feeFromSource; if ((ctx._source.containsKey('hadRefund')) && (ctx._source.hadRefund)) { feeFromSource = new BigInteger(ctx._source.fee); diff --git a/process/elasticproc/transactions/transactionsProcessor.go b/process/elasticproc/transactions/transactionsProcessor.go index 86e59b38..b85c9b71 100644 --- a/process/elasticproc/transactions/transactionsProcessor.go +++ b/process/elasticproc/transactions/transactionsProcessor.go @@ -157,7 +157,11 @@ func (tdp *txsDatabaseProcessor) GetHexEncodedHashesForRemove(header coreData.He selfShardID := header.GetShardID() encodedTxsHashes := make([]string, 0) encodedScrsHashes := make([]string, 0) - for _, miniblock := range body.MiniBlocks { + for mbIndex, miniblock := range body.MiniBlocks { + if shouldIgnoreProcessedMBScheduled(header, mbIndex) { + continue + } + shouldIgnore := isCrossShardAtSourceNormalTx(selfShardID, miniblock) if shouldIgnore { // ignore cross-shard miniblocks at source with normal txs From 5d843ef5da8ee102ba4dc2b495495a4a79d27634 Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Fri, 31 Jan 2025 11:15:05 +0200 Subject: [PATCH 15/16] go mod for sovereign --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 42d07487..e827ad7f 100644 --- a/go.mod +++ b/go.mod @@ -7,9 +7,9 @@ require ( github.com/gin-contrib/cors v1.4.0 github.com/gin-gonic/gin v1.9.1 github.com/multiversx/mx-chain-communication-go v1.1.0 - github.com/multiversx/mx-chain-core-go v1.2.24 + github.com/multiversx/mx-chain-core-go v1.2.25-0.20250131091121-26781bb55fe9 github.com/multiversx/mx-chain-logger-go v1.0.15 - github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241008143259-334f3a5bafe0 + github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241119132002-2fa80c5ec516 github.com/prometheus/client_model v0.4.0 github.com/prometheus/common v0.37.0 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index 86555889..267f913e 100644 --- a/go.sum +++ b/go.sum @@ -249,13 +249,13 @@ 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-communication-go v1.1.0 h1:J7bX6HoN3HiHY7cUeEjG8AJWgQDDPcY+OPDOsSUOkRE= github.com/multiversx/mx-chain-communication-go v1.1.0/go.mod h1:WK6bP4pGEHGDDna/AYRIMtl6G9OA0NByI1Lw8PmOnRM= -github.com/multiversx/mx-chain-core-go v1.2.24 h1:O0X7N9GfNVUCE9fukXA+dvfCRRjViYn88zOaE7feUog= -github.com/multiversx/mx-chain-core-go v1.2.24/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE= +github.com/multiversx/mx-chain-core-go v1.2.25-0.20250131091121-26781bb55fe9 h1:hm9b1I3ywGV6vOMFX86sZ5jZ7hdIqq1IH8EPNj0Pliw= +github.com/multiversx/mx-chain-core-go v1.2.25-0.20250131091121-26781bb55fe9/go.mod h1:P/YBoFnt25XUaCQ7Q/SD15vhnc9yV5JDhHxyFO9P8Z0= github.com/multiversx/mx-chain-crypto-go v1.2.12 h1:zWip7rpUS4CGthJxfKn5MZfMfYPjVjIiCID6uX5BSOk= github.com/multiversx/mx-chain-logger-go v1.0.15 h1:HlNdK8etyJyL9NQ+6mIXyKPEBo+wRqOwi3n+m2QIHXc= github.com/multiversx/mx-chain-logger-go v1.0.15/go.mod h1:t3PRKaWB1M+i6gUfD27KXgzLJJC+mAQiN+FLlL1yoGQ= -github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241008143259-334f3a5bafe0 h1:WpfFe6ueS+nRIq2RzVaeF1/TJStyYH/YLYPCmN8kdDM= -github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241008143259-334f3a5bafe0/go.mod h1:IOE+gYAtTEKZJwUr9ZhOnjdf4vFKrZdZ9RVEyuFsEP4= +github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241119132002-2fa80c5ec516 h1:PToP1B7aFkXjQBOF5MDCCvsc+ffWVqqBHtmemfCwVA8= +github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241119132002-2fa80c5ec516/go.mod h1:C7KVj6/+TAhxDjgY7oAMO5wSj7WbBYIJ5TCMzmxk2w0= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= From 72295e5fa14c7e30d189f3f9d93d0814d6dba8ef Mon Sep 17 00:00:00 2001 From: axenteoctavian Date: Fri, 31 Jan 2025 11:23:02 +0200 Subject: [PATCH 16/16] integration tests fix from past commit --- integrationtests/valuesIndex_test.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/integrationtests/valuesIndex_test.go b/integrationtests/valuesIndex_test.go index f76835f7..966163c3 100644 --- a/integrationtests/valuesIndex_test.go +++ b/integrationtests/valuesIndex_test.go @@ -7,10 +7,11 @@ import ( "fmt" "testing" + "github.com/stretchr/testify/require" + "github.com/multiversx/mx-chain-es-indexer-go/mock" indexerData "github.com/multiversx/mx-chain-es-indexer-go/process/dataindexer" "github.com/multiversx/mx-chain-es-indexer-go/process/elasticproc/factory" - "github.com/stretchr/testify/require" ) func TestCheckVersionIsIndexer(t *testing.T) { @@ -27,6 +28,8 @@ func TestCheckVersionIsIndexer(t *testing.T) { Denomination: 18, Version: version, EnabledIndexes: []string{indexerData.ValuesIndex}, + TxHashExtractor: &mock.TxHashExtractorMock{}, + RewardTxData: &mock.RewardTxDataMock{}, } _, err = factory.CreateElasticProcessor(args)