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

Added transaction processed status #386

Merged
merged 13 commits into from
Jun 26, 2023
Merged

Conversation

iulianpascalau
Copy link
Contributor

  • added transaction processed status

// ProcessedStatus: will contain the transaction status after local processing
type ExtendedApiTransactionResult struct {
*transaction.ApiTransactionResult
ProcessedStatus transaction.TxStatus `json:"processingStatus,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

might add a TODO to move it into mx-chain-core-go for rc/v1.6.0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 10 to 11
"receiver": "erd1qqqqqqqqqqqqqpgq50dge6rrpcra4tp9hl57jl0893a4r2r72jpsk39rjj",
"sender": "erd1nfqu46k8ffc2zkzme3dunh675sv69vnjp605c8pk77akk4f3e6kq5hegux",
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally, we should use dummy addresses - at least for user addresses.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, even though, our blockchain is public by design

Copy link
Contributor

@andreibancioiu andreibancioiu May 22, 2023

Choose a reason for hiding this comment

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

Indeed, but at least search engines won't match the Github page when searching for a real address.

"status": "success",
"tokens": [
"RIDE-7d18e9",
"SRIDE-4ab1d4-0695ed"
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally, we should use invented token IDs (can also stay like this, though).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

"gasPrice": 1000000000,
"gasLimit": 40000000,
"gasUsed": 26406638,
"data": "Y2xhaW1SZXdhcmRzQDM2QDEyNDU3NDY5YzYzMDEzYzBiN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Q3NEBhZjRiOTI1ZDZhODZlNGE3ZDFjNGMzOWM1ZGJjNjUzY2MyOTAxMjUyNzg3YjMxNmM3MDMwY2NkZjU5ODM3N2E4Y2NlNTEyOTdkMTAxYTRhMDM1ZWFmZWUzYWM1NDU0ODdiMzE5ZTlmNDg2YzdjZmJkZjM3MTU5Mjk4NmQ0YzkwOQ==",
Copy link
Contributor

Choose a reason for hiding this comment

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

Fields that aren't involved into the computation of status can be omitted. However, if these test files will be used by some other tests, they can remain, of course (opinion).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

curated the test file

Comment on lines 40 to 42
txCompleted = "completedTxEvent"
txFailed = "signalError"
scDeploy = "SCDeploy"
Copy link
Contributor

Choose a reason for hiding this comment

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

The constants can be prefixed or suffixed with "event" (or something similar). Furthermore, moveBalanceTransaction can be renamed to include the prefix or suffix "processing type".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

if findIdentifierInLogs(tx, txFailed) {
return transaction.TxStatusFail
}
containsCompletion := findIdentifierInLogs(tx, txCompleted) || findIdentifierInLogs(tx, scDeploy)
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately, a transaction may have multiple txCompleted events, and finding the first ones do not indicate actual completion (e.g. think of smart contract calls that perform a few ESDT transfers within the SC execution, one of them intra shard, others cross shard). However, this should be sufficient for now (in my opinion).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this will be refactored in the upcoming VM v1.5. I would leave it as it is for now, as I do not have a better idea how to implement what you have enumerated :(

"initiallyPaidFee": "407005000000000",
"fee": "407005000000000",
"chainID": "1",
"chainID": "T",
Copy link
Contributor

Choose a reason for hiding this comment

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

empty line at the end of the file

andreibancioiu
andreibancioiu previously approved these changes May 22, 2023
@@ -0,0 +1,123 @@
{
Copy link
Contributor

@miiu96 miiu96 May 23, 2023

Choose a reason for hiding this comment

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

can you add also this transaction in your test data, it's a complex one that failed https://explorer.multiversx.com/transactions/a93ab7b43150786e2a9639137d3ba13c31273b2f82b9555b1fb2a76b3d711151

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, will add

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

fieldsParam = "?fields="
lastNonceParam = "?last-nonce=true"
nonceGapsParam = "?nonce-gaps=true"
txCompletedEvent = "completedTxEvent"
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

also, take into consideration the log with the identifier internalVMErrors

Copy link
Contributor Author

Choose a reason for hiding this comment

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

great, will do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

if findIdentifierInLogs(tx, txFailedEvent) {
return transaction.TxStatusFail
}
containsCompletion := findIdentifierInLogs(tx, txCompletedEvent) || findIdentifierInLogs(tx, scDeployEvent)
Copy link
Contributor

Choose a reason for hiding this comment

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

why do you search here for the log with the scDeploysEvent ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

"options": 0
}
]
}
Copy link
Contributor

Choose a reason for hiding this comment

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

empty line at the end of the file

"options": 0
}
]
}
Copy link
Contributor

Choose a reason for hiding this comment

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

add empty line

miiu96
miiu96 previously approved these changes May 24, 2023
"math/big"

"github.com/multiversx/mx-chain-core-go/data/transaction"
"github.com/multiversx/mx-chain-proxy-go/data"
)

var errNotImplemented = errors.New("not implement")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not implemented *

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, thanks

@@ -0,0 +1,96 @@
package mock
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that a logger mock and/or stub should be exported from the mx-chain-logger-go. similar to http vs http test:

	"net/http"
	"net/http/httptest"

Copy link
Contributor

Choose a reason for hiding this comment

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

this way we don't have to redeclare these files everywhere

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's actually a bad habit. Interfaces & stubs should be replicated in each repo for maximum code reuse.
I could have used the mock from the core repo but I did not use it, specifically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Mocks & other test components that have some logic inside.... yes, we might import them but that might prove a careless move in the long run, so I would avoid them

func (tp *TransactionProcessor) GetProcessedTransactionStatus(txHash string, sender string) (string, error) {
tx, err := tp.getTransaction(txHash, sender, true)
func (tp *TransactionProcessor) GetProcessedTransactionStatus(txHash string) (string, error) {
const withResult = true
Copy link
Contributor

Choose a reason for hiding this comment

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

withResults

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

if findIdentifierInLogs(logs, core.SignalErrorOperation) {
return true
}
if findIdentifierInLogs(logs, internalVMErrorsEventIdentifier) {
Copy link
Contributor

Choose a reason for hiding this comment

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

might switch the 2 checks. based on the test data, internal vm errors event seems to appear before the signal error one. just a slight improvement for early exits

Copy link
Contributor Author

Choose a reason for hiding this comment

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

switched

@@ -468,6 +504,22 @@ func findIdentifierInLogs(tx *transaction.ApiTransactionResult, identifier strin
return false
}

func (tp *TransactionProcessor) gatherAllLogs(tx *transaction.ApiTransactionResult) ([]*transaction.ApiLogs, error) {
const withResult = true
Copy link
Contributor

Choose a reason for hiding this comment

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

withResults

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

andreibancioiu
andreibancioiu previously approved these changes May 24, 2023
@@ -247,6 +248,22 @@ func (group *transactionGroup) getTransaction(c *gin.Context) {
shared.RespondWith(c, http.StatusOK, gin.H{"transaction": tx}, "", data.ReturnCodeSuccess)
}

func (group *transactionGroup) getProcessStatus(c *gin.Context) {
Copy link
Contributor

Choose a reason for hiding this comment

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

processingStatus vs. processStatus

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually I think it's better getProcessedTransactionStatus to align with the facade

miiu96
miiu96 previously approved these changes May 24, 2023
bogdan-rosianu
bogdan-rosianu previously approved these changes May 24, 2023
andreibancioiu
andreibancioiu previously approved these changes May 24, 2023
"version": 1,
"options": 0
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

add empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

"options": 0
}
]
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

add empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

"fee": "5852440000000000",
"options": 0
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

add empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

"options": 0
}
]
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

add empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

"options": 0
}
]
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

add empty line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@gabi-vuls gabi-vuls left a comment

Choose a reason for hiding this comment

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

System test passed.

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

Successfully merging this pull request may close these issues.

5 participants