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

Commit

Permalink
Formatting fix (#584)
Browse files Browse the repository at this point in the history
- Moved build_tx_executor so it isn't between a struct and its impl
- Moved `PyContractClassSizes`, it isn't important enough to be this high
  up.
  • Loading branch information
giladchase authored Jun 8, 2023
1 parent a93048d commit 14ba5e6
Showing 1 changed file with 42 additions and 42 deletions.
84 changes: 42 additions & 42 deletions crates/native_blockifier/src/py_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,6 @@ pub fn py_tx(
}
}

#[pyclass]
#[derive(Clone)]
pub struct PyContractClassSizes {
#[pyo3(get)]
pub bytecode_length: usize,
#[pyo3(get)]
// For a Cairo 1.0 contract class, builtins are an attribute of an entry point,
// and not of the entire class.
pub n_builtins: Option<usize>,
}

#[pyclass]
// To access a field you must use `self.borrow_{field_name}()`.
// Alternately, you can borrow the whole object using `self.with[_mut]()`.
Expand All @@ -308,37 +297,6 @@ pub struct PyTransactionExecutor {
pub state: CachedState<PapyrusStateReader<'this>>,
}

pub fn build_tx_executor(
block_context: BlockContext,
storage_reader: papyrus_storage::StorageReader,
) -> NativeBlockifierResult<PyTransactionExecutor> {
// The following callbacks are required to capture the local lifetime parameter.
fn storage_tx_builder(
storage_reader: &papyrus_storage::StorageReader,
) -> NativeBlockifierResult<papyrus_storage::StorageTxn<'_, RO>> {
Ok(storage_reader.begin_ro_txn()?)
}

fn state_builder<'a>(
storage_tx: &'a papyrus_storage::StorageTxn<'a, RO>,
block_number: BlockNumber,
) -> NativeBlockifierResult<CachedState<PapyrusStateReader<'a>>> {
let state_reader = storage_tx.get_state_reader()?;
let papyrus_reader = PapyrusStateReader::new(state_reader, block_number);
Ok(CachedState::new(papyrus_reader))
}

let block_number = block_context.block_number;
// The builder struct below is implicitly created by `ouroboros`.
let py_tx_executor_builder = PyTransactionExecutorTryBuilder {
block_context,
storage_reader,
storage_tx_builder,
state_builder: |storage_tx| state_builder(storage_tx, block_number),
};
py_tx_executor_builder.try_build()
}

#[pymethods]
impl PyTransactionExecutor {
#[new]
Expand Down Expand Up @@ -446,6 +404,48 @@ impl PyTransactionExecutor {
}
}

pub fn build_tx_executor(
block_context: BlockContext,
storage_reader: papyrus_storage::StorageReader,
) -> NativeBlockifierResult<PyTransactionExecutor> {
// The following callbacks are required to capture the local lifetime parameter.
fn storage_tx_builder(
storage_reader: &papyrus_storage::StorageReader,
) -> NativeBlockifierResult<papyrus_storage::StorageTxn<'_, RO>> {
Ok(storage_reader.begin_ro_txn()?)
}

fn state_builder<'a>(
storage_tx: &'a papyrus_storage::StorageTxn<'a, RO>,
block_number: BlockNumber,
) -> NativeBlockifierResult<CachedState<PapyrusStateReader<'a>>> {
let state_reader = storage_tx.get_state_reader()?;
let papyrus_reader = PapyrusStateReader::new(state_reader, block_number);
Ok(CachedState::new(papyrus_reader))
}

let block_number = block_context.block_number;
// The builder struct below is implicitly created by `ouroboros`.
let py_tx_executor_builder = PyTransactionExecutorTryBuilder {
block_context,
storage_reader,
storage_tx_builder,
state_builder: |storage_tx| state_builder(storage_tx, block_number),
};
py_tx_executor_builder.try_build()
}

#[pyclass]
#[derive(Clone)]
pub struct PyContractClassSizes {
#[pyo3(get)]
pub bytecode_length: usize,
#[pyo3(get)]
// For a Cairo 1.0 contract class, builtins are an attribute of an entry point,
// and not of the entire class.
pub n_builtins: Option<usize>,
}

fn unexpected_callback_error(error: &PyErr) -> bool {
let error_string = error.to_string();
!(error_string.contains("BatchFull") || error_string.contains("TransactionBiggerThanBatch"))
Expand Down

0 comments on commit 14ba5e6

Please sign in to comment.