dojo icon indicating copy to clipboard operation
dojo copied to clipboard

[katana] `get_events` on pending block is always empty

Open glihm opened this issue 1 year ago • 4 comments
trafficstars

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 image

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.

glihm avatar Apr 27 '24 18:04 glihm

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

tarrencev avatar Apr 27 '24 18:04 tarrencev

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.

image image

Larkooo avatar Apr 27 '24 19:04 Larkooo

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.

image image

Ok cool then I think supporting this should be pretty straight forward

tarrencev avatar Apr 27 '24 19:04 tarrencev

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?

Larkooo avatar Apr 30 '24 13:04 Larkooo

This is not a Katana bug, it's because the from_block must point to the pending, and the to_block must be None.

glihm avatar Jun 19 '24 23:06 glihm

@Larkooo this may be interesting to check if with all the reworks + this change, this may stabilize more the Torii behavior?

glihm avatar Jun 20 '24 00:06 glihm