-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(blockifier): move BlockExecutionArtifacts to the blockifier …
…crate
- Loading branch information
1 parent
4a95470
commit 7d3d8df
Showing
8 changed files
with
102 additions
and
79 deletions.
There are no files selected for viewing
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,57 @@ | ||
use std::collections::{HashMap, HashSet}; | ||
|
||
use indexmap::IndexMap; | ||
use starknet_api::block_hash::state_diff_hash::calculate_state_diff_hash; | ||
use starknet_api::core::{ContractAddress, Nonce, StateDiffCommitment}; | ||
use starknet_api::execution_resources::GasAmount; | ||
use starknet_api::state::ThinStateDiff; | ||
use starknet_api::transaction::TransactionHash; | ||
|
||
use crate::blockifier::transaction_executor::VisitedSegmentsMapping; | ||
use crate::bouncer::BouncerWeights; | ||
use crate::state::cached_state::CommitmentStateDiff; | ||
use crate::transaction::objects::TransactionExecutionInfo; | ||
|
||
#[cfg_attr(any(test, feature = "testing"), derive(Clone))] | ||
#[derive(Debug, PartialEq)] | ||
pub struct BlockExecutionArtifacts { | ||
pub execution_infos: IndexMap<TransactionHash, TransactionExecutionInfo>, | ||
pub commitment_state_diff: CommitmentStateDiff, | ||
pub visited_segments_mapping: VisitedSegmentsMapping, | ||
pub bouncer_weights: BouncerWeights, | ||
pub l2_gas_used: GasAmount, | ||
} | ||
|
||
impl BlockExecutionArtifacts { | ||
pub fn address_to_nonce(&self) -> HashMap<ContractAddress, Nonce> { | ||
HashMap::from_iter( | ||
self.commitment_state_diff | ||
.address_to_nonce | ||
.iter() | ||
.map(|(address, nonce)| (*address, *nonce)), | ||
) | ||
} | ||
|
||
pub fn tx_hashes(&self) -> HashSet<TransactionHash> { | ||
HashSet::from_iter(self.execution_infos.keys().copied()) | ||
} | ||
|
||
pub fn state_diff(&self) -> ThinStateDiff { | ||
// TODO(Ayelet): Remove the clones. | ||
let storage_diffs = self.commitment_state_diff.storage_updates.clone(); | ||
let nonces = self.commitment_state_diff.address_to_nonce.clone(); | ||
ThinStateDiff { | ||
deployed_contracts: IndexMap::new(), | ||
storage_diffs, | ||
declared_classes: IndexMap::new(), | ||
nonces, | ||
// TODO: Remove this when the structure of storage diffs changes. | ||
deprecated_declared_classes: Vec::new(), | ||
replaced_classes: IndexMap::new(), | ||
} | ||
} | ||
|
||
pub fn commitment(&self) -> StateDiffCommitment { | ||
calculate_state_diff_hash(&self.state_diff()) | ||
} | ||
} |
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
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