Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sequencing): add execution info central object #3238

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion crates/sequencing/papyrus_consensus_orchestrator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ description = "Implements the consensus context and orchestrates the node's comp
assert_matches.workspace = true
async-trait.workspace = true
cairo-lang-starknet-classes.workspace = true
blockifier.workspace = true
chrono.workspace = true
futures.workspace = true
indexmap.workspace = true
Expand All @@ -21,7 +22,7 @@ papyrus_storage.workspace = true
paste.workspace = true
reqwest = { workspace = true, features = ["json"] }
serde.workspace = true
serde_json.workspace = true
serde_json = { workspace = true, features = ["arbitrary_precision"] }
starknet-types-core.workspace = true
starknet_api.workspace = true
starknet_batcher_types = { workspace = true, features = ["testing"] }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
use std::collections::HashMap;

use assert_matches::assert_matches;
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 cairo_lang_starknet_classes::casm_contract_class::CasmContractClass;
use cairo_lang_starknet_classes::NestedIntList;
use indexmap::{indexmap, IndexMap};
Expand Down Expand Up @@ -27,6 +33,7 @@ use starknet_api::executable_transaction::{
L1HandlerTransaction,
Transaction,
};
use starknet_api::execution_resources::GasVector;
use starknet_api::state::{StorageKey, ThinStateDiff};
use starknet_api::transaction::fields::{
AccountDeploymentData,
Expand Down Expand Up @@ -370,3 +377,52 @@ pub fn casm_contract_class_central_format(
..compiled_class_hash
}
}

/// A mapping from a transaction execution resource to its actual usage.
#[derive(Debug, 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)
}
}

#[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(),
}
}
}
22 changes: 17 additions & 5 deletions crates/sequencing/papyrus_consensus_orchestrator/src/cende/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ use std::future::ready;
use std::sync::Arc;

use async_trait::async_trait;
use central_objects::{CentralStateDiff, CentralTransactionWritten};
use blockifier::transaction::objects::TransactionExecutionInfo;
use central_objects::{
CentralStateDiff,
CentralTransactionExecutionInfo,
CentralTransactionWritten,
};
#[cfg(test)]
use mockall::automock;
use papyrus_config::dumping::{ser_param, SerializeConfig};
Expand All @@ -29,6 +34,7 @@ pub(crate) struct AerospikeBlob {
block_number: BlockNumber,
state_diff: CentralStateDiff,
transactions: Vec<CentralTransactionWritten>,
execution_infos: Vec<CentralTransactionExecutionInfo>,
}

#[cfg_attr(test, automock)]
Expand Down Expand Up @@ -177,13 +183,14 @@ async fn send_write_blob(request_builder: RequestBuilder, blob: &AerospikeBlob)
}
}

#[derive(Clone, Debug, Default)]
#[derive(Debug, Default)]
pub struct BlobParameters {
// TODO(dvir): add here all the information needed for creating the blob: tranasctions,
// classes, block info, BlockExecutionArtifacts.
// TODO(dvir): add here all the information needed for creating the blob: classes,
// bouncer_weights.
pub(crate) block_info: BlockInfo,
pub(crate) state_diff: ThinStateDiff,
pub(crate) transactions: Vec<Transaction>,
pub(crate) execution_infos: Vec<TransactionExecutionInfo>,
}

impl From<BlobParameters> for AerospikeBlob {
Expand All @@ -200,7 +207,12 @@ impl From<BlobParameters> for AerospikeBlob {
.into_iter()
.map(|tx| CentralTransactionWritten::from((tx, block_timestamp)))
.collect();
let execution_infos = blob_parameters
.execution_infos
.into_iter()
.map(CentralTransactionExecutionInfo::from)
.collect();

AerospikeBlob { block_number, state_diff, transactions }
AerospikeBlob { block_number, state_diff, transactions, execution_infos }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ impl ConsensusContext for SequencerConsensusContext {
block_info: BlockInfo { block_number: BlockNumber(height), ..Default::default() },
state_diff,
transactions,
// TODO(Yael): add the execution_infos to DecisionReachedResponse.
execution_infos: Default::default(),
})
.await;

Expand Down
Loading