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

refactor: rpc types #395

Merged
merged 6 commits into from
Dec 4, 2024
Merged

refactor: rpc types #395

merged 6 commits into from
Dec 4, 2024

Conversation

jbcaron
Copy link
Member

@jbcaron jbcaron commented Nov 22, 2024

Pull Request type

Please add the labels corresponding to the type of changes your PR introduces:

  • Refactoring (no functional changes, no API changes)

What is the current behavior?

Resolves: #382 #187

What is the new behavior?

Does this introduce a breaking change?

Yes DB

Other information

@jbcaron jbcaron self-assigned this Nov 22, 2024
@jbcaron jbcaron force-pushed the refactor/rpc-types branch 3 times, most recently from 62c7fa6 to 8d3805b Compare November 27, 2024 18:43
@jbcaron jbcaron marked this pull request as ready for review November 27, 2024 18:44
Copy link
Collaborator

@Trantorian1 Trantorian1 left a comment

Choose a reason for hiding this comment

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

Awesome work, seems like this will be much more pleasant to develop with in the future :)

Cargo.lock Outdated
[[package]]
name = "starknet-types-rpc"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d717a1b5ff67fa9ec13b09381513a4824fdd73ec5440fcc116088be6744aac4"
source = "git+https://github.com/jbcaron/types-rs.git?branch=fork#234b5f03f91d7f791003e61ae1cfcfc1f096a539"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we should move this to madara-alliance?

@@ -8643,7 +8651,7 @@ dependencies = [
"serde_json",
"sha3",
"starknet-crypto 0.5.2",
"starknet-types-core",
"starknet-types-core 0.1.7 (git+https://github.com/kasarlabs/types-rs.git?branch=feat-deserialize-v0.1.7)",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same for this repo

Comment on lines +53 to +66
let execution_resources = starknet_types_rpc::ExecutionResources {
bitwise_builtin_applications: computation_resources.bitwise_builtin_applications,
ec_op_builtin_applications: computation_resources.ec_op_builtin_applications,
ecdsa_builtin_applications: computation_resources.ecdsa_builtin_applications,
keccak_builtin_applications: computation_resources.keccak_builtin_applications,
memory_holes: computation_resources.memory_holes,
pedersen_builtin_applications: computation_resources.pedersen_builtin_applications,
poseidon_builtin_applications: computation_resources.poseidon_builtin_applications,
range_check_builtin_applications: computation_resources.range_check_builtin_applications,
segment_arena_builtin: computation_resources.segment_arena_builtin,
steps: computation_resources.steps,
data_availability: starknet_types_rpc::DataAvailability {
l1_gas: execution_info.transaction_receipt.da_gas.l1_gas,
l1_data_gas: execution_info.transaction_receipt.da_gas.l1_data_gas,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we are working off a fork, consider implementing From

crates/client/exec/src/trace.rs Show resolved Hide resolved
crates/client/rpc/src/test_utils.rs Outdated Show resolved Hide resolved
crates/primitives/receipt/src/into_starknet_types.rs Outdated Show resolved Hide resolved
crates/primitives/receipt/src/into_starknet_types.rs Outdated Show resolved Hide resolved
crates/primitives/receipt/src/into_starknet_types.rs Outdated Show resolved Hide resolved
Comment on lines 354 to 389
// #[cfg(test)]
// mod test {
// use super::*;
// use crate::{
// tests::dummy_declare_receipt, tests::dummy_deploy_account_receipt, tests::dummy_deploy_receipt,
// tests::dummy_invoke_receipt, tests::dummy_l1_handler_receipt,
// };

// #[test]
// fn test_into_starknet_types_receipt() {
// let receipt: TransactionReceipt = dummy_invoke_receipt().into();
// let core_receipt = receipt.clone().to_starknet_types(starknet_types_rpc::TxnFinalityStatus::L1);
// let receipt_back: TransactionReceipt = core_receipt.into();
// assert_eq!(receipt, receipt_back);

// let receipt: TransactionReceipt = dummy_l1_handler_receipt().into();
// let core_receipt = receipt.clone().to_starknet_types(starknet_types_rpc::TxnFinalityStatus::L1);
// let receipt_back: TransactionReceipt = core_receipt.into();
// assert_eq!(receipt, receipt_back);

// let receipt: TransactionReceipt = dummy_declare_receipt().into();
// let core_receipt = receipt.clone().to_starknet_types(starknet_types_rpc::TxnFinalityStatus::L1);
// let receipt_back: TransactionReceipt = core_receipt.into();
// assert_eq!(receipt, receipt_back);

// let receipt: TransactionReceipt = dummy_deploy_receipt().into();
// let core_receipt = receipt.clone().to_starknet_types(starknet_types_rpc::TxnFinalityStatus::L1);
// let receipt_back: TransactionReceipt = core_receipt.into();
// assert_eq!(receipt, receipt_back);

// let receipt: TransactionReceipt = dummy_deploy_account_receipt().into();
// let core_receipt = receipt.clone().to_starknet_types(starknet_types_rpc::TxnFinalityStatus::L1);
// let receipt_back: TransactionReceipt = core_receipt.into();
// assert_eq!(receipt, receipt_back);
// }
// }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why remove these tests?

Comment on lines 90 to 164
let class_info =
SierraClassInfo { contract_class: Arc::new(flatten_sierra_class), compiled_class_hash };
(
Some(blockifier::execution::contract_class::ClassInfo::new(&class_blockifier, 0, 0)?),
Some(class_hash),
Some(ConvertedClass::Legacy(LegacyConvertedClass { class_hash, info: class_info })),
)
}
starknet_types_rpc::BroadcastedDeclareTxn::V2(starknet_types_rpc::BroadcastedDeclareTxnV2 {
compiled_class_hash,
contract_class,
..
})
| starknet_types_rpc::BroadcastedDeclareTxn::QueryV2(
starknet_types_rpc::BroadcastedDeclareTxnV2 { compiled_class_hash, contract_class, .. },
)
| starknet_types_rpc::BroadcastedDeclareTxn::V3(starknet_types_rpc::BroadcastedDeclareTxnV3 {
compiled_class_hash,
contract_class,
..
})
| starknet_types_rpc::BroadcastedDeclareTxn::QueryV3(
starknet_types_rpc::BroadcastedDeclareTxnV3 { compiled_class_hash, contract_class, .. },
) => {
let flatten_sierra_class: FlattenedSierraClass = contract_class.clone().into();
let class_hash = flatten_sierra_class
.compute_class_hash()
.map_err(BroadcastedToBlockifierError::ComputeSierraClassHashFailed)?;
let (compiled_class_hash_computed, compiled) = flatten_sierra_class.compile_to_casm()?;
if compiled_class_hash != &compiled_class_hash_computed {
return Err(BroadcastedToBlockifierError::CompiledClassHashMismatch {
expected: *compiled_class_hash,
compilation: compiled_class_hash_computed,
});
}
let class_info = SierraClassInfo {
contract_class: Arc::new(flatten_sierra_class),
compiled_class_hash: compiled_class_hash_computed,
};

(
Some(blockifier::execution::contract_class::ClassInfo::new(
&compiled.to_blockifier_class()?,
tx.contract_class.sierra_program.len(),
tx.contract_class.abi.len(),
)?),
Some(class_hash),
Some(ConvertedClass::Sierra(SierraConvertedClass {
class_hash,
info: class_info,
compiled: Arc::new(compiled),
})),
)
}
starknet_core::types::BroadcastedDeclareTransaction::V3(tx) => {
let class_hash = tx.contract_class.class_hash();
let flatten_sierra_class: FlattenedSierraClass = (*tx.contract_class).clone().into();
let (compiled_class_hash, compiled) = flatten_sierra_class.compile_to_casm()?;
if tx.compiled_class_hash != compiled_class_hash {
return Err(BroadcastedToBlockifierError::CompiledClassHashMismatch {
expected: tx.compiled_class_hash,
compilation: compiled_class_hash,
});
(
Some(blockifier::execution::contract_class::ClassInfo::new(
&compiled.to_blockifier_class()?,
contract_class.sierra_program.len(),
contract_class.abi.as_ref().map(|abi| abi.len()).unwrap_or(0),
)?),
Some(class_hash),
Some(ConvertedClass::Sierra(SierraConvertedClass {
class_hash,
info: class_info,
compiled: Arc::new(compiled),
})),
)
}
}
let class_info =
SierraClassInfo { contract_class: Arc::new(flatten_sierra_class), compiled_class_hash };

(
Some(blockifier::execution::contract_class::ClassInfo::new(
&compiled.to_blockifier_class()?,
tx.contract_class.sierra_program.len(),
tx.contract_class.abi.len(),
)?),
Some(class_hash),
Some(ConvertedClass::Sierra(SierraConvertedClass {
class_hash,
info: class_info,
compiled: Arc::new(compiled),
})),
)
}
},
_ => (None, None, None),
};
_ => (None, None, None),
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider refactoring this into sub-functions to make it more readable, I'm havin a hard time sifting through this on review 😵‍💫

@jbcaron jbcaron force-pushed the refactor/rpc-types branch 7 times, most recently from ca4977e to 48aa647 Compare December 1, 2024 19:26
Copy link
Collaborator

@Trantorian1 Trantorian1 left a comment

Choose a reason for hiding this comment

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

Seems great!

}
}

fn nullify_zero(u: u64) -> Option<u64> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider making this a helper function inside of impl From<ExecutionResources> for starknet_types_rpc::ExecutionResources (nitpick)

@jbcaron jbcaron requested a review from antiyro December 2, 2024 13:15
@jbcaron jbcaron force-pushed the refactor/rpc-types branch from 48aa647 to 64ebb10 Compare December 2, 2024 22:03
@jbcaron jbcaron force-pushed the refactor/rpc-types branch from 64ebb10 to 2b95231 Compare December 3, 2024 15:34
Copy link
Member

@antiyro antiyro left a comment

Choose a reason for hiding this comment

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

tested locally works fine on e2e test read calls

@antiyro antiyro merged commit 86b2380 into main Dec 4, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

refactor(rpc): migrate rpc types from starknet-rs to types-rs
3 participants