feat: integrate decided blocks into storage adapter#3282
Conversation
c92ce6f to
0eb4587
Compare
0eb4587 to
715ee5f
Compare
ce9d67a to
8af1c4e
Compare
zvolin
left a comment
There was a problem hiding this comment.
a first pass, will get back to this
54420db to
37d0617
Compare
9555e33 to
f35d970
Compare
|
BTW: serialized casm definition as well as serialized sierra definition should be newtyped so that we don't pass around naked |
There was a problem hiding this comment.
in general looks good, left some idea, curious what you think.
but maan, I must say those decided:: helpers are veeryy hard to understand, my brain unfolds when I read them 😅 almost a rust riddles
I was thinking if we could make them easier to digest, and in general there are two patterns.
First the match on blockid, each function basically has the same code in latest and number arms, maybe we could just prepare the correct iterator beforehand?
fn blocks_for_id(decided_blocks, id) -> impl Iterator<...> {
// or just match and Boxes
blocks.iter().rev().filter(move |(bn, _)| match block_id {
BlockId::Number(n) => **bn <= n,
BlockId::Latest => true,
// decided blocks have no hash
BlockId::Hash(_) => false,
})
// maybe also map out the number at this point?
}doesn't look too good, but should remove half of the code :p
The other pattern is searchig for classes / contract updates. Another helpers for that could maybe also make it more readable?
fn find_class(block, class_hash) -> Option<&DeclaredClass> {
block
.declared_classes
.iter()
.find(|c| c.sierra_hash == SierraHash(class_hash.0))
}- something similar for state updates, should get rid of one round of
find_map+then_some
Fixes: #3248