Skip to content

Commit

Permalink
feat(blockifier): update gas and vm resources computations (#2153)
Browse files Browse the repository at this point in the history
  • Loading branch information
TzahiTaub authored and DvirYo-starkware committed Dec 17, 2024
1 parent c503127 commit 5f9e18f
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 29 deletions.
15 changes: 5 additions & 10 deletions crates/blockifier/src/execution/call_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,30 @@ macro_rules! retdata {
};
}

#[cfg_attr(any(test, feature = "testing"), derive(Clone))]
#[cfg_attr(feature = "transaction_serde", derive(serde::Deserialize))]
#[derive(Debug, Default, Eq, PartialEq, Serialize)]
#[derive(Debug, Default, Eq, PartialEq, Serialize, Clone)]
pub struct OrderedEvent {
pub order: usize,
pub event: EventContent,
}

#[cfg_attr(any(test, feature = "testing"), derive(Clone))]
#[cfg_attr(feature = "transaction_serde", derive(serde::Deserialize))]
#[derive(Debug, Default, Eq, PartialEq, Serialize)]
#[derive(Debug, Default, Eq, PartialEq, Serialize, Clone)]
pub struct MessageToL1 {
pub to_address: EthAddress,
pub payload: L2ToL1Payload,
}

#[cfg_attr(any(test, feature = "testing"), derive(Clone))]
#[cfg_attr(feature = "transaction_serde", derive(serde::Deserialize))]
#[derive(Debug, Default, Eq, PartialEq, Serialize)]
#[derive(Debug, Default, Eq, PartialEq, Serialize, Clone)]
pub struct OrderedL2ToL1Message {
pub order: usize,
pub message: MessageToL1,
}

/// Represents the effects of executing a single entry point.
#[cfg_attr(any(test, feature = "testing"), derive(Clone))]
#[cfg_attr(feature = "transaction_serde", derive(serde::Deserialize))]
#[derive(Debug, Default, Eq, PartialEq, Serialize)]
#[derive(Debug, Default, Eq, PartialEq, Serialize, Clone)]
pub struct CallExecution {
pub retdata: Retdata,
pub events: Vec<OrderedEvent>,
Expand Down Expand Up @@ -138,9 +134,8 @@ impl AddAssign<&ChargedResources> for ChargedResources {
}

/// Represents the full effects of executing an entry point, including the inner calls it invoked.
#[cfg_attr(any(test, feature = "testing"), derive(Clone))]
#[cfg_attr(feature = "transaction_serde", derive(serde::Deserialize))]
#[derive(Debug, Default, Eq, PartialEq, Serialize)]
#[derive(Debug, Default, Eq, PartialEq, Serialize, Clone)]
pub struct CallInfo {
pub call: CallEntryPoint,
pub execution: CallExecution,
Expand Down
12 changes: 4 additions & 8 deletions crates/blockifier/src/execution/stack_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ impl PreambleType {
}
}

#[cfg_attr(any(test, feature = "testing"), derive(Clone))]
#[cfg_attr(feature = "transaction_serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct EntryPointErrorFrame {
pub depth: usize,
pub preamble_type: PreambleType,
Expand Down Expand Up @@ -75,9 +74,8 @@ impl From<&EntryPointErrorFrame> for String {
}
}

#[cfg_attr(any(test, feature = "testing"), derive(Clone))]
#[cfg_attr(feature = "transaction_serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct VmExceptionFrame {
pub pc: Relocatable,
pub error_attr_value: Option<String>,
Expand All @@ -100,9 +98,8 @@ impl From<&VmExceptionFrame> for String {
}
}

#[cfg_attr(any(test, feature = "testing"), derive(Clone))]
#[cfg_attr(feature = "transaction_serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, PartialEq, derive_more::From)]
#[derive(Debug, PartialEq, derive_more::From, Clone)]
pub enum ErrorStackSegment {
EntryPoint(EntryPointErrorFrame),
Cairo1RevertSummary(Cairo1RevertSummary),
Expand Down Expand Up @@ -148,9 +145,8 @@ impl Display for ErrorStackHeader {
}
}

#[cfg_attr(any(test, feature = "testing"), derive(Clone))]
#[cfg_attr(feature = "transaction_serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Default, PartialEq)]
#[derive(Debug, Default, PartialEq, Clone)]
pub struct ErrorStack {
pub header: ErrorStackHeader,
pub stack: Vec<ErrorStackSegment>,
Expand Down
3 changes: 1 addition & 2 deletions crates/blockifier/src/fee/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ struct TransactionReceiptParameters<'a> {

// TODO(Gilad): Use everywhere instead of passing the `actual_{fee,resources}` tuple, which often
// get passed around together.
#[cfg_attr(any(test, feature = "testing"), derive(Clone))]
#[cfg_attr(feature = "transaction_serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Default, Debug, PartialEq)]
#[derive(Default, Debug, PartialEq, Clone)]
pub struct TransactionReceipt {
pub fee: Fee,
pub gas: GasVector,
Expand Down
3 changes: 1 addition & 2 deletions crates/blockifier/src/state/cached_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,7 @@ type StorageDiff = IndexMap<ContractAddress, IndexMap<StorageKey, Felt>>;

/// Holds uncommitted changes induced on Starknet contracts.
#[cfg_attr(feature = "transaction_serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(any(feature = "testing", test), derive(Clone))]
#[derive(Debug, Default, Eq, PartialEq)]
#[derive(Debug, Default, Eq, PartialEq, Clone)]
pub struct CommitmentStateDiff {
// Contract instance attributes (per address).
pub address_to_class_hash: IndexMap<ContractAddress, ClassHash>,
Expand Down
6 changes: 2 additions & 4 deletions crates/blockifier/src/transaction/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,8 @@ pub struct CommonAccountFields {
pub only_query: bool,
}

#[cfg_attr(any(test, feature = "testing"), derive(Clone))]
#[cfg_attr(feature = "transaction_serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, derive_more::Display, PartialEq)]
#[derive(Debug, derive_more::Display, PartialEq, Clone)]
pub enum RevertError {
Execution(ErrorStack),
PostExecution(FeeCheckError),
Expand All @@ -191,9 +190,8 @@ impl From<FeeCheckError> for RevertError {
}

/// Contains the information gathered by the execution of a transaction.
#[cfg_attr(any(test, feature = "testing"), derive(Clone))]
#[cfg_attr(feature = "transaction_serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Default, PartialEq)]
#[derive(Debug, Default, PartialEq, Clone)]
pub struct TransactionExecutionInfo {
/// Transaction validation call info; [None] for `L1Handler`.
pub validate_call_info: Option<CallInfo>,
Expand Down
1 change: 1 addition & 0 deletions crates/starknet_batcher/src/batcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ impl Batcher {
self.commit_proposal_and_block(state_diff, address_to_nonce, tx_hashes).await
}

// TODO(dvir): return `BlockExecutionArtifacts`
#[instrument(skip(self), err)]
pub async fn decision_reached(&mut self, input: DecisionReachedInput) -> BatcherResult<()> {
let proposal_id = input.proposal_id;
Expand Down
1 change: 1 addition & 0 deletions crates/starknet_batcher/src/batcher_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ async fn decision_reached() {
commitment: ProposalCommitment::default(),
tx_hashes: test_tx_hashes(),
nonces: test_contract_nonces(),
block_execution_artifacts: Default::default(),
}))
}
.boxed()
Expand Down
3 changes: 1 addition & 2 deletions crates/starknet_batcher/src/block_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ pub enum FailOnErrorCause {
TransactionFailed(BlockifierTransactionExecutorError),
}

#[cfg_attr(test, derive(Clone))]
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone, Default)]
pub struct BlockExecutionArtifacts {
pub execution_infos: IndexMap<TransactionHash, TransactionExecutionInfo>,
pub commitment_state_diff: CommitmentStateDiff,
Expand Down
12 changes: 11 additions & 1 deletion crates/starknet_batcher/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ pub(crate) struct ProposalOutput {
pub commitment: ProposalCommitment,
pub tx_hashes: HashSet<TransactionHash>,
pub nonces: HashMap<ContractAddress, Nonce>,
// Needed for writing to Aerospoke.
pub block_execution_artifacts: BlockExecutionArtifacts,
}

impl From<BlockExecutionArtifacts> for ProposalOutput {
fn from(artifacts: BlockExecutionArtifacts) -> Self {
let cloned_artifacts = artifacts.clone();

let commitment_state_diff = artifacts.commitment_state_diff;
let nonces = HashMap::from_iter(
commitment_state_diff
Expand All @@ -57,7 +61,13 @@ impl From<BlockExecutionArtifacts> for ProposalOutput {
ProposalCommitment { state_diff_commitment: calculate_state_diff_hash(&state_diff) };
let tx_hashes = HashSet::from_iter(artifacts.execution_infos.keys().copied());

Self { state_diff, commitment, tx_hashes, nonces }
Self {
state_diff,
commitment,
tx_hashes,
nonces,
block_execution_artifacts: cloned_artifacts,
}
}
}

Expand Down

0 comments on commit 5f9e18f

Please sign in to comment.