-
Notifications
You must be signed in to change notification settings - Fork 76
feat: add get_messages_status #776
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
base: main
Are you sure you want to change the base?
Conversation
9a336b0 to
8233d54
Compare
cchudant
left a comment
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.
Missing failure_reason / execution_status fields.
| let mut results = Vec::new(); | ||
| for msg in l1_handlers { | ||
| let transaction_hash = msg.tx.compute_hash(starknet.chain_id(), false, false); | ||
| let finality_status = get_transaction_status(starknet, transaction_hash).await?.finality_status; |
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 we're supposed to return something meaningful when the transaction is not on l2 here
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.
Alright - I am looking at the latest v0.9 spec. I also looked at the v0.8 rpc spec but I figured I would focus on v0.9 spec because we'll have to do that as well, and the corner cases are similar.
Here is the interpretation of the spec.
-
If the transaction can't be found on L1, TxnHashNotFound (correct)
-
finality_status: this can be PreConfirmed, AcceptedOnL1 and AcceptedOnL2
You are fine here since it's get_transaction_status that handles that (esp. AcceptedOnL1).
I don't think we're supposed to return Received status here (because messages from l1 txs can't be in the mempool) nor Candidate status because execution_status is required. -
execution_status: you are missing this field. This field is returned by get_transaction_status, so you should just pass it to the resulting DTO. Weirdly enough, this field is required, so we can't return finality_status Candidate in this endpoint. I should bring this up with the spec authors tbh, it's probably something they haven't thought about.
-
failure_reason: you are also missing this field. This is the revert reason, and you can also get it from the output of get_transaction_status where it's also named
failure_reason. It's optional and should be None for the other statuses. -
What if the transaction is on L1 and not on l2/preconfirmed? This is not as far-fetched of an idea as you may think, the sequencer can totally just omit L1HandlerTransactions and/or miss them.
Either, 1) none of the messages are on l2 yet. 2) the rare case where one of the messages to l2 is on l2 but one of the others are missing.
I don't know what the proper interpretation is here - iffinality_statuswas nullable I would say we should return a None finality_status. Since it's not, I think skipping the transaction makes sense. If we were allowed to return a nullexecution_status, I think it could also kinda make sense to return Received.
I've looked at how pathfinder interprets the spec, and it's a bit weird? Here is how they interpret it: if aget_transaction_statuscall for one of the messages returns TxnHashNotFound, the whole getMessagesStatus returns TxnHashNotFound. Which means, the endpoint can't be used at all when case 2) hits, like, if a message is skipped by the sequencer somehow or if one of the messages arrives on l2 before another (could happen for a lot of reason). But here is the weird part: if aget_transaction_statuscall returnsCandidate(orReceived), the given transaction is skipped from the output because there is no associatedexecution_status. This feels weird to me? i am super confused.
I think I need to bring this up to the spec authors, but in the meantime, my opinion is that you should:
- add the
execution_statusandfinality_statusfields to match the spec. Just use what get_transaction_status returns here. - I think it kind of make sense to return
TxnHashNotFoundlike you did if a transaction is not on l2 in the meantime, to match pathfinder's interpretation. I think it would be weird for users to get an empty array if their tx has not hit l2 yet, but I haven't checked how consumers use the API. - candidate shenanigans might require spec change, let's worry about that later when we're doing v0.9.
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 implementation is only for v0.8.1
| })?; | ||
|
|
||
| let mut results = Vec::new(); | ||
| for msg in l1_handlers { |
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.
oh btw,
stream::iter(messages).then(|msg| async move {
let transaction_hash = msg.tx.compute_hash(starknet.chain_id(), false, false);
let finality_status = get_transaction_status(starknet, transaction_hash).await?.finality_status;
Ok(TxnHashWithStatus { transaction_hash, finality_status })
}).collect().awaitshould work
(https://docs.rs/futures/latest/futures/stream/index.html, and https://docs.rs/futures/latest/futures/stream/trait.StreamExt.html#method.then which is the async version of iterator map)
(it doesn't change anything, the fetches will still be sequential but i think it looks nicer? maybe overcomplicated for nothing idk)
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’s a slight overhead with the stream I think, and I’m not sure there’s more than 1 message per TX
8233d54 to
073909a
Compare
Pull Request type
Please add the labels corresponding to the type of changes your PR introduces:
What is the current behavior?
Resolves: #NA
What is the new behavior?
Does this introduce a breaking change?
No
Other information