Compiled class hash not found in CachedState
after executing Declare
tx #1246
Description
If you try to get the compiled class hash after executing a declare tx, you will get a NoneCompiledHash
error. This is what i try to do in the contract_execution
example:
//* --------------------------------------------
//* Declare new contract class
//* --------------------------------------------
let declare_tx = Declare::new_with_tx_hash(
&sierra_contract_class,
Some(casm_class),
compiled_class_hash,
account_contract_address.clone(),
Default::default(), // max fee
2.into(),
signature.clone(),
1.into(), // nonce
// Value hardcoded to pass signature validation
2718.into(),
)
.expect("couldn't create declare transaction");
let class_hash = declare_tx.sierra_class_hash;
declare_tx
.execute(
&mut state,
&block_context,
#[cfg(feature = "cairo-native")]
None,
)
.expect("could not declare the contract class");
// This will return `NoneCompiledHash` error
let actual_compiled_class_hash = state
.get_compiled_class_hash(&(class_hash.into()))
.expect("should have compiled class hash");
this probably what caused it, here it sets the compiled hash in cache.compiled_hash_writes
:
starknet_in_rust/src/state/cached_state.rs
Lines 306 to 318 in 370d406
but the get_compiled_class_hash()
implementation doesn't read from it, but instead from cache.class_hash_to_compiled_class_hash
:
starknet_in_rust/src/state/cached_state.rs
Lines 177 to 185 in 370d406
if i replace line 179 above with self.cache.get_compiled_class_hash(class_hash)
, which reads from the compiled_class_hash_writes
field, the issue is fixed.
Activity