Skip to content

Commit

Permalink
feat(sequencing): add execution info central object
Browse files Browse the repository at this point in the history
  • Loading branch information
Yael-Starkware committed Jan 15, 2025
1 parent 0d45204 commit 1a9a65b
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 6 deletions.
4 changes: 3 additions & 1 deletion crates/sequencing/papyrus_consensus_orchestrator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ description = "Implements the consensus context and orchestrates the node's comp
[dependencies]
assert_matches.workspace = true
async-trait.workspace = true
blockifier.workspace = true
chrono.workspace = true
futures.workspace = true
indexmap.workspace = true
Expand All @@ -18,7 +19,8 @@ papyrus_network.workspace = true
papyrus_protobuf.workspace = true
papyrus_storage.workspace = true
reqwest = { workspace = true, features = ["json"] }
serde.workspace = true
serde = { 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 indexmap::{indexmap, IndexMap};
use serde::Serialize;
use starknet_api::block::{
Expand All @@ -25,6 +31,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 @@ -352,3 +359,52 @@ impl From<(Transaction, u64)> for CentralTransactionWritten {
}
}
}

/// 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(|execution_info| CentralTransactionExecutionInfo::from(execution_info))
.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

0 comments on commit 1a9a65b

Please sign in to comment.