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

fix(execution): execution of declare txs - fetch the class from the r… #1236

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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