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

fix: remove block_id from starknet_subscribeTransactionStatus #2501

Merged
merged 3 commits into from
Jan 22, 2025

Conversation

vbar
Copy link
Contributor

@vbar vbar commented Jan 20, 2025

Fixes #2495 .

@vbar vbar requested a review from a team as a code owner January 20, 2025 16:16
@vbar vbar force-pushed the vbar/remove-block-id branch from 4d60637 to 6138c2e Compare January 21, 2025 06:59
doc/rpc/v08/starknet_ws_api.json Outdated Show resolved Hide resolved
Comment on lines 145 to 152
},
{
"name": "block_id",
"summary": "The block to get notifications from, default is latest, limited to 1024 blocks back",
"required": false,
"schema": {
"$ref": "./api/starknet_api_openrpc.json#/components/schemas/BLOCK_ID"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here -- I've already updated the specs in PR #2500, could be moved to a separate PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Funnily enough, this must be updated, to make the rpc_routing test pass...

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay. The spec change is already on main though, so if you rebase this should be fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, rebased

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I think something might have gone wrong with that rebase, because we're now re-adding block_id to the spec.

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'm afraid git is too complex for me... Fixed in d161be1 .

util::task::spawn_blocking(move |_| -> Result<_, RpcError> {
let mut conn = storage.connection().map_err(RpcError::InternalError)?;
let db = conn.transaction().map_err(RpcError::InternalError)?;
let first_block = db
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I understand this part. first_block used to be the block_id parameter received in the request, while now it's essentially the latest block number.

Why do we need this at all?

I think the logic below could be simplified to use l1_block_number and tx_with_receipt only:

  • if we have tx_with_receipt (that is, the tx was already found in a block):
    • send RECEIVED
    • send L2_ACCEPTED
    • depending on the relation of the block in which the tx was found and l1_block_number, send L1_ACCEPTED
  • if we don't have the tx yet, just continue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, not really understanding the logic, I went for a minimal change - but yes, it should be simplified...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, not really understanding the logic, I went for a minimal change - but yes, it should be simplified...

...except sending RECEIVED unconditionally changes existing behavior: as far as I understood the discussion, the change should make the call behave as if the removed block_id always referred to the latest block... I tried to test that (in cb01b5c ), and the original implementation stopped sending the RECEIVED messages. I suppose a case could be made that "an event with the current known transaction status" is singular, and the updates before that are historical & not included in the new subscription. On the other hand, keeping the tested behavior unchanged also has its attractions... So, is the unconditional RECEIVED correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

@sistemd I think RECEIVED was just being sent so that we have the same set of statuses emitted irrespective of where those transaction statuses actually came from, right?

It might be worth double-checking the expected behavior with regard to these "historical" updates with the author(s) of the specification.

@kkovaacs
Copy link
Contributor

Another question: once we reach L1_ACCEPTED, which is effectively a final state, do we close the subscription?

@vbar
Copy link
Contributor Author

vbar commented Jan 21, 2025

Another question: once we reach L1_ACCEPTED, which is effectively a final state, do we close the subscription?

Well, transaction_already_exists_in_db_accepted_on_l2_succeeded does test "No more messages expected." - is that what you mean?

@kkovaacs
Copy link
Contributor

Another question: once we reach L1_ACCEPTED, which is effectively a final state, do we close the subscription?

Well, transaction_already_exists_in_db_accepted_on_l2_succeeded does test "No more messages expected." - is that what you mean?

Not quite. That test does test that there are no more messages sent -- but the subscription is still kept open, even though there's no possibility of further messages once we've reached a final status. In this state we're effectively waiting for the client to close the subscription -- maybe we should close it ourselves?

@sistemd What do you think?

@sistemd
Copy link
Contributor

sistemd commented Jan 21, 2025

What do you think?

@kkovaacs AFAIR, I decided to not close the subscription because there can be more messages coming in due to reorgs. The user can close the connection themselves if they explicitly don't care about reorgs.

@kkovaacs
Copy link
Contributor

What do you think?

@kkovaacs AFAIR, I decided to not close the subscription because there can be more messages coming in due to reorgs. The user can close the connection themselves if they explicitly don't care about reorgs.

Hmm, that's a good point, I was missing reorgs... Makes sense!

@vbar vbar force-pushed the vbar/remove-block-id branch from 0aa4c1c to 1eb1176 Compare January 21, 2025 14:49
@vbar vbar force-pushed the vbar/remove-block-id branch from cbd73ae to a977074 Compare January 22, 2025 07:11
@vbar vbar merged commit ea5bb52 into main Jan 22, 2025
8 checks passed
@vbar vbar deleted the vbar/remove-block-id branch January 22, 2025 07:21
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.

Remove block ID from starknet_subscribeTransactionStatus
3 participants