-
Notifications
You must be signed in to change notification settings - Fork 18
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
Conversation
iulianpascalau
commented
May 22, 2023
- added transaction processed status
data/transaction.go
Outdated
// ProcessedStatus: will contain the transaction status after local processing | ||
type ExtendedApiTransactionResult struct { | ||
*transaction.ApiTransactionResult | ||
ProcessedStatus transaction.TxStatus `json:"processingStatus,omitempty"` |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
"receiver": "erd1qqqqqqqqqqqqqpgq50dge6rrpcra4tp9hl57jl0893a4r2r72jpsk39rjj", | ||
"sender": "erd1nfqu46k8ffc2zkzme3dunh675sv69vnjp605c8pk77akk4f3e6kq5hegux", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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": "Y2xhaW1SZXdhcmRzQDM2QDEyND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0ODdlNjJmZTBmOWE1YzQ3NEBhZjRiOTI1ZDZhODZlNGE3ZDFjNGMzOWM1ZGJjNjUzY2MyOTAxMjUyNzg3YjMxNmM3MDMwY2NkZjU5ODM3N2E4Y2NlNTEyOTdkMTAxYTRhMDM1ZWFmZWUzYWM1NDU0ODdiMzE5ZTlmNDg2YzdjZmJkZjM3MTU5Mjk4NmQ0YzkwOQ==", |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curated the test file
process/transactionProcessor.go
Outdated
txCompleted = "completedTxEvent" | ||
txFailed = "signalError" | ||
scDeploy = "SCDeploy" |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
process/transactionProcessor.go
Outdated
if findIdentifierInLogs(tx, txFailed) { | ||
return transaction.TxStatusFail | ||
} | ||
containsCompletion := findIdentifierInLogs(tx, txCompleted) || findIdentifierInLogs(tx, scDeploy) |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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
@@ -0,0 +1,123 @@ | |||
{ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, will add
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
process/transactionProcessor.go
Outdated
fieldsParam = "?fields=" | ||
lastNonceParam = "?last-nonce=true" | ||
nonceGapsParam = "?nonce-gaps=true" | ||
txCompletedEvent = "completedTxEvent" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you use these constants from here https://github.com/multiversx/mx-chain-core-go/blob/16023cace5b78df86fbaa1e6a6b3778873f58c25/core/constants.go#L250
for the logs identifiers
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great, will do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
process/transactionProcessor.go
Outdated
if findIdentifierInLogs(tx, txFailedEvent) { | ||
return transaction.TxStatusFail | ||
} | ||
containsCompletion := findIdentifierInLogs(tx, txCompletedEvent) || findIdentifierInLogs(tx, scDeployEvent) |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
"options": 0 | ||
} | ||
] | ||
} |
There was a problem hiding this comment.
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 | ||
} | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add empty line
"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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not implemented *
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
process/transactionProcessor.go
Outdated
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
withResults
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
process/transactionProcessor.go
Outdated
if findIdentifierInLogs(logs, core.SignalErrorOperation) { | ||
return true | ||
} | ||
if findIdentifierInLogs(logs, internalVMErrorsEventIdentifier) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switched
process/transactionProcessor.go
Outdated
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
withResults
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
api/groups/baseTransactionGroup.go
Outdated
@@ -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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
processingStatus
vs. processStatus
There was a problem hiding this comment.
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
d51b5e4
"version": 1, | ||
"options": 0 | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add empty line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
"options": 0 | ||
} | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add empty line
There was a problem hiding this comment.
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 | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add empty line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
"options": 0 | ||
} | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add empty line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
"options": 0 | ||
} | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add empty line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
System test passed.