dojoengine / dojo

Dojo is a toolchain for building provable games and autonomous worlds with Cairo
https://dojoengine.org
Apache License 2.0
407 stars 165 forks source link

Add fork provider for non-state data #1466

Open kariy opened 8 months ago

kariy commented 8 months ago

Currently katana only provides forked data for state-related info (eg storage, nonce, class hash) thru the SharedStateProvider. We should extend the forking functionality to also allow fetching non-state data as well (eg block, events, tx) from the forked network.

We can extend the Backend to handle more request types.

Proposed solution

We can mimic ForkedStateDb where it uses SharedStateProvider as the underlying db for CacheStateDb by creating similar forked provider type specifically for the CacheDb instead, that handles non-state data (ie block, tx). Unlike SharedStateProvider, we don't have to implement the provider traits as most of the traits are mainly for abstracting over the db layout. We only need to fetch data that can only be fetched from the RPC. So, that means we only need to implement fork handlers for data that can only be obtain from the Katana RPC.

Regarding caching (ie storing the fetch forked data into local storage), ideally we can store the fetched data directly into the main storage, but how the storage is laid out at the moment isn't very friendly to unordered insertion like this case. Maybe we can have the forked provider type to include a storage to store the data fetched from the forked RPC.

fishseabowl commented 7 months ago

@kariy can I take this? Thanks

kariy commented 7 months ago

Assigned! Let me know if you have any questions or require more context on the issue.

kariy commented 7 months ago

@fishseabowl I've updated the issue description for more context. Thanks for the contribution 🙂

kariy commented 7 months ago

Hey @fishseabowl. Any updates on this? Let me know if there's something blocking you.

fishseabowl commented 7 months ago

@kariy Thank you. I'm currently handling this. If I have any questions, I'll message you.

fishseabowl commented 6 months ago

@kariy Do you know where is a code example using the starknet-provider API, e.g. if I call API get_events, what are the parameters filter and chunk_size? Thanks

/// Returns all events matching the given filter
    async fn get_events(
        &self,
        filter: EventFilter,
        continuation_token: Option<String>,
        chunk_size: u64,
    ) -> Result<EventsPage, ProviderError>;
kariy commented 6 months ago

@fishseabowl I'm not sure about the example but you can refer to the RPC specs here to know what each of the params are used for.

glihm commented 6 months ago

@kariy Do you know where is a code example using the starknet-provider API, e.g. if I call API get_events, what are the parameters filter and chunk_size? Thanks

/// Returns all events matching the given filter
    async fn get_events(
        &self,
        filter: EventFilter,
        continuation_token: Option<String>,
        chunk_size: u64,
    ) -> Result<EventsPage, ProviderError>;

Some example of code from starknet-rs @fishseabowl: https://github.com/xJonathanLEI/starknet-rs/blob/400deb6f058447e8b67316a92ecd9ad3b6d4330c/starknet-providers/tests/jsonrpc.rs#L795.

The chunk size is expected to be None where no more data have to be fetched. You can see the fetching as paginated using this continuation token.