Skip to content
This repository has been archived by the owner on Dec 26, 2024. It is now read-only.

Commit

Permalink
fix(execution): execution of declare txs - fetch the class from the r… (
Browse files Browse the repository at this point in the history
#1236)

fix(execution): fetch the class from the right block
  • Loading branch information
yair-starkware authored Oct 4, 2023
1 parent a6f06fa commit 1c639f1
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions crates/papyrus_rpc/src/v0_4_0/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,16 +312,7 @@ pub(crate) fn stored_txn_to_executable_txn(
let class_hash = value.class_hash;
Ok(ExecutableTransactionInput::DeclareV0(
value,
storage_txn
.get_state_reader()
.map_err(internal_server_error)?
.get_deprecated_class_definition_at(state_number, &class_hash)
.map_err(internal_server_error)?
.ok_or_else(|| {
internal_server_error(format!(
"Missing deprecated class definition of {class_hash}."
))
})?,
get_deprecated_class_for_re_execution(storage_txn, state_number, class_hash)?,
))
}
starknet_api::transaction::Transaction::Declare(
Expand All @@ -331,16 +322,7 @@ pub(crate) fn stored_txn_to_executable_txn(
let class_hash = value.class_hash;
Ok(ExecutableTransactionInput::DeclareV1(
value,
storage_txn
.get_state_reader()
.map_err(internal_server_error)?
.get_deprecated_class_definition_at(state_number, &class_hash)
.map_err(internal_server_error)?
.ok_or_else(|| {
internal_server_error(format!(
"Missing deprecated class definition of {class_hash}."
))
})?,
get_deprecated_class_for_re_execution(storage_txn, state_number, class_hash)?,
))
}
starknet_api::transaction::Transaction::Declare(
Expand Down Expand Up @@ -391,6 +373,25 @@ pub(crate) fn stored_txn_to_executable_txn(
}
}

// For re-execution (traceTransaction, traceBlockTransactions) we need to get the class definition
// of declare transactions from the storage before the execution. They are stored in the state after
// the block in which they appeared, so we need to get it from the state after given block.
fn get_deprecated_class_for_re_execution(
storage_txn: &StorageTxn<'_, RO>,
state_number: StateNumber,
class_hash: ClassHash,
) -> Result<starknet_api::deprecated_contract_class::ContractClass, ErrorObjectOwned> {
let state_number_after_block = StateNumber::right_after_block(state_number.block_after());
storage_txn
.get_state_reader()
.map_err(internal_server_error)?
.get_deprecated_class_definition_at(state_number_after_block, &class_hash)
.map_err(internal_server_error)?
.ok_or_else(|| {
internal_server_error(format!("Missing deprecated class definition of {class_hash}."))
})
}

impl TryFrom<BroadcastedDeclareTransaction> for ExecutableTransactionInput {
type Error = ErrorObjectOwned;
fn try_from(value: BroadcastedDeclareTransaction) -> Result<Self, Self::Error> {
Expand Down

0 comments on commit 1c639f1

Please sign in to comment.