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

feat(katana): getStorageProof endpoint #2809

Merged
merged 23 commits into from
Dec 16, 2024
Merged

feat(katana): getStorageProof endpoint #2809

merged 23 commits into from
Dec 16, 2024

Conversation

kariy
Copy link
Member

@kariy kariy commented Dec 15, 2024

This PR introduces a new endpoint, starknet_getStorageProof for querying state proofs, including for historical states.

We are already computing all the state tries (ie classes, contracts, and storages) in #2609, but we don't store the historical trie nodes. Therefore, it's only possible to get the latest state proofs. To support historical tries requires, there are at least two approaches I have could thought of; (1) storing the entire trie including historical trie nodes, or (2) recomputing the trie at runtime.

Approach (2) may possibly be the simplest considering we already have historical states and fetching them is pretty easy with the provider abstractions. We also don't need to create new tables for storing the historical nodes. But computing the trie is a very expensive operation, and depending on the block for which we want to recompute the trie, if the state update is very large, it might consume a lot of resources (iterating over db entries to fetch all historical states, and then computing the trie itself).

We also have to take into account the primary consumer for this new endpoint, which is saya. It'll be primarily used to fetch the state proofs required to run SNOS for generating the proof of a block for settlement. It is understood very well that saya's proof generations will inevitably lag behind katana in block productions. So, saya could be asking katana for the state proofs of block 5 while katana is already producing block 10. To prevent overloading katana runtime performance (possibly impacting its perceived performance when executing transactions), we have opted for approach (1).

We introduced 6 new tables; ClassesTrieHistory, ContractsTrieHistory, StoragesTrieHistory, for storing the trie node at a particular block, and ClassesTrieChangeSet, ContractsTrieChangeSet, StoragesTrieChangeSet for indexing the list of blocks where a trie node has changed. These tables serve similar purposes to the already existing tables that are also suffixed by *History and *ChangeSet. This mean for each node that exist in a trie, we require 2 more entries stored in the aforementioned tables respectively.

We don't yet implement any pruning mechanism. This shall be implemented in the future.


The getStorageProof endpoint is also part of the RPC 0.8.0 spec. But we don't bump the RPC version as this PR doesn't include the other changes as defined in the new specification.

@kariy kariy force-pushed the katana/storage-proof branch from 27f3193 to 03c3cfa Compare December 16, 2024 14:40
@kariy kariy changed the base branch from main to katana/dev December 16, 2024 18:31
Copy link

codecov bot commented Dec 16, 2024

Codecov Report

Attention: Patch coverage is 46.99248% with 423 lines in your changes missing coverage. Please review.

Project coverage is 55.31%. Comparing base (8111b6d) to head (52941db).
Report is 1 commits behind head on katana/dev.

Files with missing lines Patch % Lines
crates/katana/storage/db/src/trie/mod.rs 42.37% 68 Missing ⚠️
...atana/storage/provider/src/providers/fork/state.rs 0.00% 66 Missing ⚠️
.../katana/storage/provider/src/providers/db/state.rs 20.98% 64 Missing ⚠️
crates/katana/storage/db/src/trie/snapshot.rs 0.00% 54 Missing ⚠️
crates/katana/executor/src/implementation/noop.rs 0.00% 26 Missing ⚠️
...na/executor/src/implementation/blockifier/state.rs 0.00% 24 Missing ⚠️
crates/katana/executor/src/abstraction/mod.rs 0.00% 22 Missing ⚠️
...ana/storage/provider/src/providers/fork/backend.rs 0.00% 21 Missing ⚠️
...s/katana/storage/db/src/abstraction/transaction.rs 39.39% 20 Missing ⚠️
crates/katana/rpc/rpc/src/starknet/mod.rs 70.45% 13 Missing ⚠️
... and 8 more
Additional details and impacted files
@@              Coverage Diff               @@
##           katana/dev    #2809      +/-   ##
==============================================
- Coverage       55.71%   55.31%   -0.41%     
==============================================
  Files             439      444       +5     
  Lines           55657    56230     +573     
==============================================
+ Hits            31010    31104      +94     
- Misses          24647    25126     +479     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@kariy kariy marked this pull request as ready for review December 16, 2024 19:39
@kariy kariy merged commit 5597b79 into katana/dev Dec 16, 2024
12 of 14 checks passed
@kariy kariy deleted the katana/storage-proof branch December 16, 2024 19:56
kariy added a commit that referenced this pull request Dec 16, 2024
kariy added a commit that referenced this pull request Dec 25, 2024
kariy added a commit that referenced this pull request Dec 31, 2024
@kariy kariy mentioned this pull request Dec 31, 2024
kariy added a commit that referenced this pull request Dec 31, 2024
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.

None yet

1 participant