-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(native_blockifier, starknet_consensus_orchestrator): share e…
…xecution objects
- Loading branch information
1 parent
4a0c186
commit 00aeb44
Showing
13 changed files
with
111 additions
and
139 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "shared_execution_objects" | ||
version.workspace = true | ||
edition.workspace = true | ||
repository.workspace = true | ||
license-file.workspace = true | ||
|
||
[features] | ||
deserialize = ["blockifier/transaction_serde"] | ||
|
||
[dependencies] | ||
blockifier.workspace = true | ||
serde.workspace = true | ||
starknet_api.workspace = true | ||
|
||
[lints] | ||
workspace = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod objects; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use std::collections::HashMap; | ||
|
||
use blockifier::abi::constants as abi_constants; | ||
use blockifier::execution::call_info::CallInfo; | ||
use blockifier::fee::receipt::TransactionReceipt; | ||
use blockifier::transaction::objects::{ExecutionResourcesTraits, TransactionExecutionInfo}; | ||
use serde::Serialize; | ||
use starknet_api::execution_resources::GasVector; | ||
use starknet_api::transaction::fields::Fee; | ||
|
||
/// A mapping from a transaction execution resource to its actual usage. | ||
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] | ||
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize)] | ||
pub struct ResourcesMapping(pub HashMap<String, usize>); | ||
|
||
impl From<TransactionReceipt> for ResourcesMapping { | ||
fn from(receipt: TransactionReceipt) -> ResourcesMapping { | ||
let vm_resources = &receipt.resources.computation.vm_resources; | ||
let mut resources = HashMap::from([( | ||
abi_constants::N_STEPS_RESOURCE.to_string(), | ||
vm_resources.total_n_steps() + receipt.resources.computation.n_reverted_steps, | ||
)]); | ||
resources.extend( | ||
vm_resources | ||
.prover_builtins() | ||
.iter() | ||
.map(|(builtin, value)| (builtin.to_str_with_suffix().to_string(), *value)), | ||
); | ||
|
||
ResourcesMapping(resources) | ||
} | ||
} | ||
|
||
/// The TransactionExecutionInfo object as used by the Python code. | ||
#[cfg_attr(feature = "deserialize", derive(serde::Deserialize))] | ||
#[derive(Debug, Serialize)] | ||
pub struct CentralTransactionExecutionInfo { | ||
pub validate_call_info: Option<CallInfo>, | ||
pub execute_call_info: Option<CallInfo>, | ||
pub fee_transfer_call_info: Option<CallInfo>, | ||
pub actual_fee: Fee, | ||
pub da_gas: GasVector, | ||
pub actual_resources: ResourcesMapping, | ||
pub revert_error: Option<String>, | ||
pub total_gas: GasVector, | ||
} | ||
|
||
impl From<TransactionExecutionInfo> for CentralTransactionExecutionInfo { | ||
fn from(tx_execution_info: TransactionExecutionInfo) -> CentralTransactionExecutionInfo { | ||
CentralTransactionExecutionInfo { | ||
validate_call_info: tx_execution_info.validate_call_info, | ||
execute_call_info: tx_execution_info.execute_call_info, | ||
fee_transfer_call_info: tx_execution_info.fee_transfer_call_info, | ||
actual_fee: tx_execution_info.receipt.fee, | ||
da_gas: tx_execution_info.receipt.da_gas, | ||
revert_error: tx_execution_info.revert_error.map(|error| error.to_string()), | ||
total_gas: tx_execution_info.receipt.gas, | ||
actual_resources: tx_execution_info.receipt.into(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.