Flattening state update storage #1026
Closed
Mirko-von-Leipzig
started this conversation in
Ideas
Replies: 2 comments 6 replies
-
Overall I like the proposal. Just a few questions:
|
Beta Was this translation helpful? Give feedback.
6 replies
-
Implemented :) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Status Quo
State updates are currently stored as compressed json in a single table. This is because the only (current) usage of them is to serve
starknet_getStateUpdate
requests, which makes storing them exactly as required by this method convenient.Motivation
All other state related methods query the state tree's to discover relevant information, such as when a contract was deployed, or what value a contract's nonce or storage has. This works because we currently store the state tree for every block. These tree's now comprise 2/3 of our storage requirements which is a lot. The flattening of state trees would let us move from querying state trees to querying the state update data directly instead. As such, this flattening is part of our larger goal of moving from storing all state trees to only the latest -- and thereby reducing our storage requirements.
State update data
A block's state update from the gateway contains:
RPC Usage
get_class_at
,get_class_hash_at
andget_nonce
travel the global tree to get the state hash, which in turn is used to lookup the class, class hash or nonce.get_storage_at
travels both the global and contract tree's to retrieve the storage value.get_state_update
just reads the current compressed json as is.get_proof
travels both global and contract tree's to create the proof. This method will affected by this change. Options are:N
blocksget_proof
work at any block.call
,estimateFee
,simulateTransaction
all rely on state trees for:i
)i
)Proposal
New tables:
Contract address should probably be a reference to contract's table where possible i.e. intern it there. We can also intern storage key, if we decide that the space savings are worth it 🤷 Probably requires some stats to back up that decision -- although at that point maybe all hashes should just be interned into a single table -- or maybe there is some nice sqlite function somehow? (not really this proposals problem though).
We can also make replaced classes more obvious by adding a
replaced: bool
column -- this will make it easier to know if its a replaced class or a new deployment.I think
old_declared_contracts
anddeclared_classes
are already tracked? I haven't fully checked though, so maybe they need something similar, or an ammendment to what is there now.Beta Was this translation helpful? Give feedback.
All reactions