dojo
dojo copied to clipboard
[katana] `get_events` on pending block is always empty
Describe the bug
When using get_events with to_block = Some(BlockId::Tag(BlockTag::Pending)), the event page is always empty.
Expected behavior We should return the events of the pending block's transactions.
Screenshots
Additional context The request enters here: https://github.com/dojoengine/dojo/blob/6b6219faf0a53b781b7fd83dabefc8e8f90b5995/crates/katana/rpc/rpc/src/starknet.rs#L453.
Then processed by the sequencer here: https://github.com/dojoengine/dojo/blob/6b6219faf0a53b781b7fd83dabefc8e8f90b5995/crates/katana/core/src/sequencer.rs#L299
Also, in the new JSON RPC spec, the block number can be None for the events of the pending block.
How do we handle pagination in that case? iirc the cursor schema is up to us, so we would need to include a txn index in it. not sure how we handle this today
How do we handle pagination in that case? iirc the cursor schema is up to us, so we would need to include a txn index in it. not sure how we handle this today
I'm not sure how it works but I think it just uses the pending block number (latest block number + 1) alongside the txn index + event index? Here's how it looks with the sepolia node.
As you can see, the events in the EventsPage have a None block_hash and block_number but the cursor still includes the block number.
How do we handle pagination in that case? iirc the cursor schema is up to us, so we would need to include a txn index in it. not sure how we handle this today
I'm not sure how it works but I think it just uses the pending block number (latest block number + 1) alongside the txn index + event index? Here's how it looks with the sepolia node.
As you can see, the events in the EventsPage have a None block_hash and block_number but the cursor still includes the block number.
![]()
Ok cool then I think supporting this should be pretty straight forward
To add on this, this seems to be the issue: https://github.com/dojoengine/dojo/blob/main/crates/katana/storage/provider/src/traits/block.rs#L40
The returned BlockId for the Pending block tag is none, which fallbacks to the latest block number here https://github.com/dojoengine/dojo/blob/main/crates/katana/storage/provider/src/traits/block.rs#L32
What would be the implications of simply returning the latest_block_number + 1?
This is not a Katana bug, it's because the from_block must point to the pending, and the to_block must be None.
@Larkooo this may be interesting to check if with all the reworks + this change, this may stabilize more the Torii behavior?
