-
Notifications
You must be signed in to change notification settings - Fork 46
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
refactor: rpc types #395
Conversation
62c7fa6
to
8d3805b
Compare
There was a problem hiding this 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" |
There was a problem hiding this comment.
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)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for this repo
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, |
There was a problem hiding this comment.
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
// #[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); | ||
// } | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove these tests?
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), | ||
}; |
There was a problem hiding this comment.
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 😵💫
ca4977e
to
48aa647
Compare
There was a problem hiding this 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> { |
There was a problem hiding this comment.
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)
48aa647
to
64ebb10
Compare
64ebb10
to
2b95231
Compare
There was a problem hiding this 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
Pull Request type
Please add the labels corresponding to the type of changes your PR introduces:
What is the current behavior?
Resolves: #382 #187
What is the new behavior?
Does this introduce a breaking change?
Yes DB
Other information