Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link inner tx to results #6527

Closed
wants to merge 11 commits into from
Closed

Conversation

sstanculeanu
Copy link
Collaborator

@sstanculeanu sstanculeanu commented Oct 8, 2024

Reasoning behind the pull request

  • missing link between tx results and inner txs

Proposed changes

  • linked results to inner txs
  • now GetTransaction(innerTxHash) should return the inner tx as well with the results generated

Testing procedure

  • standard system test + full relayed v3 testing with lots of scenarios + relayed v1/v2 tests that confirm no change happened in terms of generated scrs/logs

Pre-requisites

Based on the Contributing Guidelines the PR author and the reviewers must check the following requirements are met:

  • was the PR targeted to the correct branch?
  • if this is a larger feature that probably needs more than one PR, is there a feat branch created?
  • if this is a feat branch merging, do all satellite projects have a proper tag inside go.mod?

now get transaction should return results for inner tx hashes
Copy link

github-actions bot commented Oct 8, 2024

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: a4b532de029b2d249d928b581f050803aa75a4a5
  • Current Branch: link_inner_tx_to_results
  • mx-chain-go Target Branch: rc/v1.7.next1
  • mx-chain-simulator-go Target Branch: rc/v1.7.next1
  • mx-chain-testing-suite Target Branch: rc/v1.7.next1

🚀 Environment Variables:

  • TIMESTAMP: 08102024-123836
  • PYTEST_EXIT_CODE: 1
    🎉 MultiversX CI/CD Workflow Complete!

@sasurobert sasurobert self-requested a review October 8, 2024 12:43
@AdoAdoAdo AdoAdoAdo self-requested a review October 8, 2024 12:48
@@ -789,6 +783,26 @@ func (txProc *txProcessor) processInnerTx(

txFee := txProc.computeInnerTxFee(innerTx)

innerTxHash := originalTxHash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you make a separate function for this ?

If would be easier to understand - otherwise you look at this and you do not seem that it is ok.

Also, can you rename originalTxHash - to relayerTxHash ?

Or it is relayerTxHash always ? If it is not, than it can stay originalTxHash.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added new method + kept originalTxHash.. in case of relayedV3, it can be either relayerTxHash either innerTxHash

log.Debug("txLogsProcessor.SaveLog failed", "error", ignorableErr.Error())
}
func (txProc *txProcessor) createCompletedRelayedTxV3EventLog(tx data.TransactionHandler, originalTxHash []byte) {
if len(txProc.relayedTxV3InnerHashes) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you change this and accumulate the inner hashes into a structure which is not a local variable for the txProc ?

I think it can be done.

Copy link

github-actions bot commented Oct 8, 2024

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: 11422d87320a69179709f7032ff358c7aaa63a36
  • Current Branch: link_inner_tx_to_results
  • mx-chain-go Target Branch: rc/v1.7.next1
  • mx-chain-simulator-go Target Branch: rc/v1.7.next1
  • mx-chain-testing-suite Target Branch: rc/v1.7.next1

🚀 Environment Variables:

  • TIMESTAMP: 08102024-134507
  • PYTEST_EXIT_CODE: 1
    🎉 MultiversX CI/CD Workflow Complete!

continue
}

for _, innerTx := range innerTxs {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you extract this into a method?

hr.recordInnerTx

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

for _, innerTx := range txInfoFromMap.tx.GetUserTransactions() {
innerTxHash, errCalculateHash := core.CalculateHash(bpp.marshalizer, bpp.hasher, innerTx)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you extract this into a method saveInnerTxToStorage

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

innerTxHash := originalTxHash

var err error
if txProc.enableEpochsHandler.IsFlagEnabled(common.HashForInnerTransactionFlag) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this method called only for v3?

otherwise this will change also the behavior for SCRs for v1 and v2 relay txs, those need to be retested

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, processInnerTx is specific to relayed v3

innerTxIdx)
}

txProc.relayedTxV3InnerHashes = append(txProc.relayedTxV3InnerHashes, innerTxHash)
Copy link
Contributor

@AdoAdoAdo AdoAdoAdo Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in case of a v1 or v2 tx, then this is not a relayedV3 inner hash

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method should be called for v3 only

}

prefix := miniblockHash[0]
actualHash := miniblockHash[1:]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actualHash is the relayTxHash, and it appears you are not returning this
It might be needed to create the link to the relayTx that included this inner tx

Copy link

github-actions bot commented Oct 8, 2024

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: dc57ade0c832262b22a107e6a1c5bf10b8f16bf4
  • Current Branch: link_inner_tx_to_results
  • mx-chain-go Target Branch: rc/v1.7.next1
  • mx-chain-simulator-go Target Branch: rc/v1.7.next1
  • mx-chain-testing-suite Target Branch: rc/v1.7.next1

🚀 Environment Variables:

  • TIMESTAMP: 08102024-151752
  • PYTEST_EXIT_CODE: 1
    🎉 MultiversX CI/CD Workflow Complete!

Copy link

github-actions bot commented Oct 8, 2024

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: d0c24356aeb2b2706a24c9d611240d3f291b1cf1
  • Current Branch: link_inner_tx_to_results
  • mx-chain-go Target Branch: rc/v1.7.next1
  • mx-chain-simulator-go Target Branch: rc/v1.7.next1
  • mx-chain-testing-suite Target Branch: rc/v1.7.next1

🚀 Environment Variables:

  • TIMESTAMP: 08102024-152923
  • PYTEST_EXIT_CODE: 1
    🎉 MultiversX CI/CD Workflow Complete!

sasurobert
sasurobert previously approved these changes Oct 9, 2024
Copy link

github-actions bot commented Oct 9, 2024

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: d1235cc50098cfce4e4514e6807825eab747eca5
  • Current Branch: link_inner_tx_to_results
  • mx-chain-go Target Branch: rc/v1.7.next1
  • mx-chain-simulator-go Target Branch: rc/v1.7.next1
  • mx-chain-testing-suite Target Branch: rc/v1.7.next1

🚀 Environment Variables:

  • TIMESTAMP: 09102024-100457
  • PYTEST_EXIT_CODE: 1
    🎉 MultiversX CI/CD Workflow Complete!

AdoAdoAdo
AdoAdoAdo previously approved these changes Oct 9, 2024
@@ -538,6 +538,11 @@ func (atp *apiTransactionProcessor) lookupHistoricalTransaction(hash []byte, wit
return nil, fmt.Errorf("%s: %w", ErrCannotRetrieveTransaction.Error(), err)
}

if len(parentTxHash) > 0 {
tx.OriginalTransactionHash = hex.EncodeToString(parentTxHash)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are doing twice the same encoding

AdoAdoAdo
AdoAdoAdo previously approved these changes Oct 9, 2024
Copy link
Contributor

@AdoAdoAdo AdoAdoAdo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check also V1 and V2 relay txs not changed (especially the refunding part).

Copy link

github-actions bot commented Oct 9, 2024

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: 96d44b78b28e892b176976930f7e285549bfdcd2
  • Current Branch: link_inner_tx_to_results
  • mx-chain-go Target Branch: rc/v1.7.next1
  • mx-chain-simulator-go Target Branch: rc/v1.7.next1
  • mx-chain-testing-suite Target Branch: rc/v1.7.next1

🚀 Environment Variables:

  • TIMESTAMP: 09102024-135646
  • PYTEST_EXIT_CODE: 1
    🎉 MultiversX CI/CD Workflow Complete!

sasurobert
sasurobert previously approved these changes Oct 9, 2024
Copy link

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: a2de898b8c5fa4d5219a5a942dcb5a9ebd770ea5
  • Current Branch: link_inner_tx_to_results
  • mx-chain-go Target Branch: rc/v1.7.next1
  • mx-chain-simulator-go Target Branch: rc/v1.7.next1
  • mx-chain-testing-suite Target Branch: rc/v1.7.next1

🚀 Environment Variables:

  • TIMESTAMP: 10102024-082702
  • PYTEST_EXIT_CODE: 1
    🎉 MultiversX CI/CD Workflow Complete!

Copy link

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: 666fd478d26aa0a33a1c247689cea50c2bc4369b
  • Current Branch: link_inner_tx_to_results
  • mx-chain-go Target Branch: rc/v1.7.next1
  • mx-chain-simulator-go Target Branch: rc/v1.7.next1
  • mx-chain-testing-suite Target Branch: rc/v1.7.next1

🚀 Environment Variables:

  • TIMESTAMP: 10102024-092621
  • PYTEST_EXIT_CODE: 1
    🎉 MultiversX CI/CD Workflow Complete!

Copy link

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: f6e69dc2453e911cd98f7f33052d9f153b0df145
  • Current Branch: link_inner_tx_to_results
  • mx-chain-go Target Branch: rc/v1.7.next1
  • mx-chain-simulator-go Target Branch: rc/v1.7.next1
  • mx-chain-testing-suite Target Branch: rc/v1.7.next1

🚀 Environment Variables:

  • TIMESTAMP: 10102024-093621
  • PYTEST_EXIT_CODE: 1
    🎉 MultiversX CI/CD Workflow Complete!

Copy link

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: a9a0019fc3ff2fc6f01e324ae85227de9eacf5a0
  • Current Branch: link_inner_tx_to_results
  • mx-chain-go Target Branch: rc/v1.7.next1
  • mx-chain-simulator-go Target Branch: rc/v1.7.next1
  • mx-chain-testing-suite Target Branch: rc/v1.7.next1

🚀 Environment Variables:

  • TIMESTAMP: 10102024-101448
  • PYTEST_EXIT_CODE: 1
    🎉 MultiversX CI/CD Workflow Complete!


tu.shardCoordinator.ComputeId(innerTx.RcvAddr)

frontEndTx := &transaction.ApiTransactionResult{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename the variable ?

innerTxHash = make([]byte, 0)
}

tu.shardCoordinator.ComputeId(innerTx.RcvAddr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be removed

Copy link

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: 3ff37f295e641142940eacf85a0497161e89ba4c
  • Current Branch: link_inner_tx_to_results
  • mx-chain-go Target Branch: rc/v1.7.next1
  • mx-chain-simulator-go Target Branch: rc/v1.7.next1
  • mx-chain-testing-suite Target Branch: rc/v1.7.next1

🚀 Environment Variables:

  • TIMESTAMP: 10102024-104831
  • PYTEST_EXIT_CODE: 1
    🎉 MultiversX CI/CD Workflow Complete!


# FixRelayedBaseCostEnableEpoch represents the epoch when the fix for relayed base cost will be enabled
FixRelayedBaseCostEnableEpoch = 7
RelayedTransactionsV3EnableEpoch = 4
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good, previous three merged into one, then added a new one 👍


relayedHashPrefix := []byte{byte(RelayedTxHash)}
relayedTxHashPrefixed := append(relayedHashPrefix, []byte(txHash)...)
errPut := hr.miniblockHashByTxHashIndex.Put(innerTxHash, relayedTxHashPrefixed)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thus, now we keep heterogeneous data in this storer. In a future PR, we should refactor to adjust its naming.

@@ -538,6 +544,13 @@ func (atp *apiTransactionProcessor) lookupHistoricalTransaction(hash []byte, wit
return nil, fmt.Errorf("%s: %w", ErrCannotRetrieveTransaction.Error(), err)
}

if len(parentTxHash) > 0 {
encodedParentTxHash := hex.EncodeToString(parentTxHash)
tx.OriginalTransactionHash = encodedParentTxHash
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

encodedParentTxHash := hex.EncodeToString(parentTxHash)
tx.OriginalTransactionHash = encodedParentTxHash
tx.PreviousTransactionHash = encodedParentTxHash
tx.Type = string(transaction.TxTypeInner)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should announce this, or should be extra careful on downstream applications. Can be considered a somehow-breaking change.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to double check from downstream applications.

}

hashSize := hr.hasher.Size()
if len(miniblockHash) == hashSize {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this adds a previously not needed check between the hasher.Size() and the hashSize.
if we would want to change the hasher, previously it would work without any changes, with the new code if the hash size is different it will not. Just to be aware in the future about this "connection"

@@ -569,6 +582,7 @@ func (atp *apiTransactionProcessor) lookupHistoricalTransaction(hash []byte, wit
func putMiniblockFieldsInTransaction(tx *transaction.ApiTransactionResult, miniblockMetadata *dblookupext.MiniblockMetadata) *transaction.ApiTransactionResult {
tx.Epoch = miniblockMetadata.Epoch
tx.Round = miniblockMetadata.Round
putRoundAndEpochOnInnerTxs(tx)

tx.MiniBlockType = block.Type(miniblockMetadata.Type).String()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for the next fields to be set in the inner txs?
maybe at least the miniblockHash and miniBlockType.

isForRelayer := bytes.Equal(dbScResult.RcvAddr, txWithRelayerAddr.GetRelayerAddr())
shouldConsiderScrForRelayer := isFlagEnabled && isForRelayer

return isForRelayed && (isForSender || shouldConsiderScrForRelayer) && differentHash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for after the fix, should the differentHash be true or false? If you have 1 SCR from an innerTx are OriginalTxHash and PrevTxHash equal or not?
could this be refactored somehow so that the functionality before and after is more visible?

}

if !bytes.Equal(relayedTxHash, originalTxHash) {
txProc.innerTxsHashesHolder.Append(originalTxHash)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the innerTxsHashedHolder appends only after the activation of the fix flag when the hashes are different.
the name getOriginalTxHashForInnerTxOfRelayedV3 might not be the most appropiate, because the originalTxHash and previousTxHash are actually set to the relayedTxHash... just an observation.

@@ -1293,16 +1308,32 @@ func (txProc *txProcessor) createCompleteEventLog(scr data.TransactionHandler, o
}
}

func (txProc *txProcessor) saveFailedLogsIfNeeded(originalTxHash []byte) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is removed without any flag, and the createCompletedRelayedTxV3EventLog was added;
these are backwards compatbile, right?
if someone processed the failedLogs, after the upgrade, with not activation flag it won't generate them any more.

isScrRefundForRelayer := scr.IsRefund && (scr.RcvAddr == tx.RelayerAddress)
shouldConsiderRefundSentToRelayer := isScrRefundForRelayer && isHashForInnerTxActive
isScrForTxSender := scr.RcvAddr == tx.Sender
if !scr.IsRefund || (!isScrForTxSender && !shouldConsiderRefundSentToRelayer) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is also very hard to understand what happens before and after the activation. Could it be refactored so that the before activation remains the same like before, and after the activation it has another logic?

@btc-fan
Copy link

btc-fan commented Oct 11, 2024

Run Tests:
mx-chain-simulator-go: fix-failed-test
mx-chain-testing-suite: link_inner_tx_to_results

@sstanculeanu sstanculeanu marked this pull request as draft October 11, 2024 14:40
Copy link

⚠️ No report was generated due to an error or cancellation of the process.
Please checkout gh action logs for details

@btc-fan
Copy link

btc-fan commented Oct 11, 2024

Run Tests:
mx-chain-simulator-go: link_inner_tx_to_results
mx-chain-testing-suite: fix-failed-test

Copy link

📊 MultiversX Automated Test Report: View Report

🔄 Build Details:

  • mx-chain-go Commit Hash: 3ff37f295e641142940eacf85a0497161e89ba4c
  • Current Branch: link_inner_tx_to_results
  • mx-chain-go Target Branch: rc/v1.7.next1
  • mx-chain-simulator-go Target Branch: link_inner_tx_to_results
  • mx-chain-testing-suite Target Branch: fix-failed-test

🚀 Environment Variables:

  • TIMESTAMP: 11102024-145403
  • PYTEST_EXIT_CODE: 1
    🎉 MultiversX CI/CD Workflow Complete!

@sstanculeanu
Copy link
Collaborator Author

proper fix in #6529

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants