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: handle deprecated classes and modularize and optimize compile class build #331

Merged
merged 12 commits into from
Sep 2, 2024

Conversation

HermanObst
Copy link
Collaborator

@HermanObst HermanObst commented Aug 29, 2024

Description

Problem:

  • We need to continue clearing main function
  • We are making too many useful rpc calls

Solution:
Modularize and use cache

⚠️ Check that now we are only using the inner calls to get all the accessed contracts (and not the StateDiff). This may result in a problem later

@HermanObst HermanObst changed the title WIP: investigation on contract keys Chore: modularize and optimize compile class build Aug 29, 2024

let mut class_hash_to_compiled_class_hash = processed_state_update.class_hash_to_compiled_class_hash.clone();
let class_hash_to_compiled_class_hash = processed_state_update.class_hash_to_compiled_class_hash.clone();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove .clone(), it's useless.

@@ -29,8 +25,7 @@ pub struct FormattedStateUpdate {
pub(crate) async fn get_processed_state_update(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You renamed the struct, you can also rename the function to format_state_update.

})
.collect();
address_to_nonce
async fn build_compiled_class_and_maybe_update_class_hash_to_compiled_class_hash(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function deserves to be documented.

GenericSierraContractClass::from(flattened_sierra_cc)
}
starknet::core::types::ContractClass::Legacy(_) => {
unimplemented!("Fixme: Support legacy contract class")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no Sierra notion of Sierra class for Cairo0. The compiled class is the contract class. I think the cleanest solution here will be to return a tuple of (compiled_contract_classes, deprecated_compiled_contract_classes).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be resolved before merging the PR.

accessed_addresses: &HashSet<Felt252>,
address_to_class_hash: &HashMap<Felt252, Felt252>,
class_hash_to_compiled_class_hash: &mut HashMap<Felt252, Felt252>,
) -> Result<HashMap<Felt252, GenericCasmContractClass>, Error> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we moved to the latest Blockifier, don't hesitate to use types like CompiledClassHash, ClassHash etc. This will make the code cleaner and we can get the felt inside by accessing the .0 field.

for contract_address in accessed_addresses {
let class_hash = match address_to_class_hash.get(contract_address) {
Some(class_hash) => class_hash,
None => &provider.get_class_hash_at(block_id, contract_address).await?,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that with anyhow, you can add with_context("<some explanation>") to any Result value so that you get a human-readable message + details on failure.

@HermanObst HermanObst force-pushed the refactor-prove-block branch from 481ee6e to 4fd6e23 Compare August 30, 2024 14:26
@HermanObst HermanObst changed the title Chore: modularize and optimize compile class build Fear: handle deprecated classes and modularize and optimize compile class build Aug 30, 2024
@HermanObst HermanObst changed the title Fear: handle deprecated classes and modularize and optimize compile class build Feat: handle deprecated classes and modularize and optimize compile class build Aug 30, 2024
@@ -63,6 +64,9 @@ impl fmt::Display for ProveBlockError {
ProveBlockError::TreeError(err) => write!(f, "Tree Error: {}", err),
ProveBlockError::ContractClassError(err) => write!(f, "Contract Class Error: {}", err),
ProveBlockError::SnOsError(err) => write!(f, "SnOs Error: {}", err),
ProveBlockError::LegacyContractDecompressionError(err) => {
write!(f, "Legacy class decompression Error: {}", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this enum in my review of @whichqua 's PR but we should definitely derive thiserror::Error for ProveBlockError instead of implementing this manually.

let class_hash_to_compiled_class_hash: HashMap<Felt252, Felt252> = format_declared_classes(&state_diff);
let storage_updates: HashMap<Felt252, HashMap<Felt252, Felt252>> = format_storage_updates(&state_diff);
let address_to_class_hash = format_deployed_contracts(&state_diff);
// TODO: Handle deprecated clasees
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// TODO: Handle deprecated clasees
// TODO: Handle deprecated classes


// Define your error enum
#[derive(Debug)]
#[derive(Debug, Error)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: there are so many Error traits, specifying that you're deriving thiserror::Error clarifies things.

@odesenfans odesenfans merged commit 30824d0 into main Sep 2, 2024
6 checks passed
@odesenfans odesenfans deleted the refactor-prove-block branch September 2, 2024 21:29
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.

2 participants