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

fix(class): Fix Sierra classes conversion (missing abis) #60

Merged
merged 13 commits into from
Apr 18, 2024
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ cairo_venv
run.sh
password.txt
nohup.out
deoxys.log
# pyenv
.python-version

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ git # Deoxys Changelog

## Next release

- fix(class): Fix Sierra classes conversion (missing abis)
- fix(compute): Fixed prepare_data_availability_modes computation
- feat(rpc): add pending block to `get_block_with_receipts` rpc call
- chore: update bonsai-trie (benefit from perf boost)
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 2 additions & 20 deletions crates/client/sync/src/fetch/fetchers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ where
let provider = Arc::clone(&arc_provider);
let state_update = Arc::clone(state_update);
let class_hash = *class_hash;
set.spawn(
async move { fetch_class(class_hash, block_hash_deoxys(&state_update), &provider, block_number).await },
);
set.spawn(async move { fetch_class(class_hash, block_hash_deoxys(&state_update), &provider).await });
set
});

Expand All @@ -181,32 +179,16 @@ async fn fetch_class(
class_hash: FieldElement,
block_hash: FieldElement,
provider: &SequencerGatewayProvider,
block_number: u64,
) -> Result<ContractClassData, L2SyncError> {
let core_class = provider.get_class(BlockIdCore::Hash(block_hash), class_hash).await?;
// Check for Starknet versions for block number >= 30000 (TODO: this is for mainnet, add support for
// Sepolia)
let starknet_version: Option<String> =
if block_number >= 31600u64 { Some(fetch_starknet_version(provider, block_number).await?) } else { None };
Ok(ContractClassData {
hash: ClassHash(Felt252Wrapper::from(class_hash).into()),
// TODO: remove this expect when ContractClassWrapper::try_from does proper error handling using
// thiserror
contract_class: ContractClassWrapper::try_from((core_class, starknet_version))
.expect("converting contract class"),
contract_class: ContractClassWrapper::try_from(core_class).expect("converting contract class"),
})
}

/// Fetch Starknet version at a specific block number
///
/// This function is used to convert a class definition based on a specific Starknet version
/// TODO: replace this with a thread safe canal between the fetch block thread
async fn fetch_starknet_version(provider: &SequencerGatewayProvider, block_number: u64) -> Result<String, L2SyncError> {
let block = provider.get_block(BlockId::Number(block_number)).await?;

Ok(block.starknet_version.unwrap())
}

/// Filters out class declarations in the Starknet sequencer state update
/// and retains only those which are not stored in the local Substrate db.
fn fetch_missing_classes<'a>(
Expand Down
7 changes: 3 additions & 4 deletions crates/primitives/contract/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ pub mod convert {

// Wrapper Class conversion

impl TryFrom<(ContractClassCore, Option<String>)> for ContractClassWrapper {
impl TryFrom<ContractClassCore> for ContractClassWrapper {
type Error = anyhow::Error;

fn try_from(inputs: (ContractClassCore, Option<String>)) -> Result<Self, Self::Error> {
let (contract_class, starknet_version) = inputs;
let contract = from_rpc_contract_class(&contract_class, starknet_version)?;
fn try_from(contract_class: ContractClassCore) -> Result<Self, Self::Error> {
let contract = from_rpc_contract_class(contract_class.clone())?;
let abi = match &contract_class {
ContractClassCore::Sierra(class_sierra) => ContractAbi::Sierra(class_sierra.abi.clone()),
ContractClassCore::Legacy(class_cairo) => {
Expand Down
2 changes: 2 additions & 0 deletions crates/primitives/convert/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ casm-compiler-v2_6_0 = { package = "cairo-lang-starknet", version = "=2.6.0" }
flate2 = { workspace = true }
indexmap = { workspace = true }
mp-felt = { workspace = true }
mp-transactions = { workspace = true }
num-bigint = { workspace = true }
scale-info = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
starknet-core = { workspace = true }
starknet-providers = { workspace = true }
starknet_api = { workspace = true }
log = { workspace = true }

[features]
default = ["std"]
Expand Down
Loading
Loading