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): implement Arbitrary trait for all db types #2568

Merged
merged 4 commits into from
Oct 22, 2024

Conversation

kariy
Copy link
Member

@kariy kariy commented Oct 22, 2024

implement the Arbitray trait for all types that are used in the database. this is for generating random values of all the database types. helpful for

due to Rust's orphan rule, there are some types that we use from external crate (mainly starknet-rs) that don't implement the trait, so we can't directly derive it. to get around this, the simplest solution is to just own the types and define it ourselves. this approach requires that we do more marshalling between our primitives types to the rpc types (rpc we mostly use types from starknet-rs). which is not the most elegant solution. i think eventually we probably should not rely on external crate for our rpc types and maintain them ourselves for more flexibility (if the changes that we need cant be included upstream).

the idea for this PR, is to use this for generating bunch of random values for all db types and use them in a benchmark.


test db needs to be updated because of the we define the ExecutionResources and it doesn't serde into the same format as the one we used before (from the cairo-vm)

i would prefer to keep the breaking serde, mainly because it doesnt de/serialize the builtin_instance_counter as raw strings of the builtin names. therefore more storage optimized. we're still using the builin name types from cairo-vm anyway so marshalling between them is straightforward as we dont need to convert the individual map entry.

though this changes break the db format, as we already bumped it at #2560, and it hasnt been included in a release yet, theres no need to bump it again.

@kariy kariy changed the base branch from katana/db-benchmark to katana/simplify-in-memory-provider October 22, 2024 17:58
@kariy kariy force-pushed the katana/simplify-in-memory-provider branch from fd5d1ed to 63d0330 Compare October 22, 2024 17:59
@kariy kariy changed the title feat: implement Arbitrary trait for all db types feat(katana): implement Arbitrary trait for all db types Oct 22, 2024
Copy link

codecov bot commented Oct 22, 2024

Codecov Report

Attention: Patch coverage is 25.11628% with 161 lines in your changes missing coverage. Please review.

Please upload report for BASE (katana/simplify-in-memory-provider@59c6dcf). Learn more about missing BASE report.

Files with missing lines Patch % Lines
crates/katana/rpc/rpc-types/src/transaction.rs 28.37% 53 Missing ⚠️
crates/saya/provider/src/rpc/transaction.rs 0.00% 28 Missing ⚠️
crates/katana/primitives/src/transaction.rs 28.57% 15 Missing ⚠️
crates/katana/rpc/rpc-types/src/block.rs 16.66% 10 Missing ⚠️
crates/saya/provider/src/rpc/mod.rs 0.00% 8 Missing ⚠️
crates/katana/primitives/src/receipt.rs 0.00% 7 Missing ⚠️
crates/katana/primitives/src/trace.rs 12.50% 7 Missing ⚠️
crates/katana/primitives/src/fee.rs 14.28% 6 Missing ⚠️
crates/katana/core/src/backend/storage.rs 0.00% 3 Missing ⚠️
crates/katana/primitives/src/block.rs 0.00% 3 Missing ⚠️
... and 12 more
Additional details and impacted files
@@                          Coverage Diff                          @@
##             katana/simplify-in-memory-provider    #2568   +/-   ##
=====================================================================
  Coverage                                      ?   69.54%           
=====================================================================
  Files                                         ?      401           
  Lines                                         ?    50753           
  Branches                                      ?        0           
=====================================================================
  Hits                                          ?    35295           
  Misses                                        ?    15458           
  Partials                                      ?        0           

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

@kariy kariy merged commit 81b6fa7 into katana/simplify-in-memory-provider Oct 22, 2024
15 checks passed
@kariy kariy deleted the katana/arbitrary branch October 22, 2024 21:21
kariy added a commit that referenced this pull request Oct 23, 2024
implement the [`Arbitray`](https://docs.rs/arbitrary/latest/arbitrary/trait.Arbitrary.html) trait for all types that are used in the database. this is for generating random values  of all the database types. helpful for 

due to Rust's orphan rule, there are some types that we use from external crate (mainly `starknet-rs`) that don't implement the trait, so we can't directly derive it. to get around this, the simplest solution is to just own the types and define it ourselves. this approach requires that we do more marshalling between our primitives types to the rpc types (rpc we mostly use types from starknet-rs). which is not the most elegant solution. i think eventually we probably should not rely on external crate for our rpc types and maintain them ourselves for more flexibility (if the changes that we need cant be included upstream).

the idea for this PR, is to use this for generating bunch of random values for all db types and use them in a benchmark. 

---

test db needs to be updated because of the we define the [`ExecutionResources`](https://github.com/dojoengine/dojo/blob/a4ee208b517daead41ac1a6b855af3abb03294c3/crates/katana/primitives/src/trace.rs#L12-L20) and it doesn't serde into the same format as the one we used before (from the [cairo-vm](https://github.com/dojoengine/dojo/blob/a4ee208b517daead41ac1a6b855af3abb03294c3/crates/katana/primitives/src/trace.rs#L12-L20))

i would prefer to keep the breaking serde, mainly because it doesnt de/serialize the `builtin_instance_counter` as raw strings of the builtin names. therefore more storage optimized. we're still using the builin name types from cairo-vm anyway so marshalling between them is straightforward as we dont need to convert the individual map entry.

though this changes break the db format, as we already bumped it at #2560, and it hasnt been included in a release yet, theres no need to bump it again.
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.

1 participant