Skip to content
This repository has been archived by the owner on Dec 26, 2024. It is now read-only.

Commit

Permalink
fix(JSON-RPC): use rpc's TransactionTrace in api (#1781)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShahakShama authored Mar 7, 2024
1 parent 412167c commit f1ca12e
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 36 deletions.
44 changes: 42 additions & 2 deletions crates/papyrus_rpc/resources/V0_7/starknet_api_openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3721,8 +3721,8 @@
"price_in_fri"
]
},
"EXECUTION_RESOURCES": {
"title": "Execution resources",
"COMPUTATION_RESOURCES": {
"title": "Computation resources",
"description": "The resources consumed by the VM",
"type": "object",
"properties": {
Expand Down Expand Up @@ -3810,6 +3810,46 @@
"required": [
"steps"
]
},
"EXECUTION_RESOURCES": {
"type": "object",
"title": "Execution resources",
"description": "the resources consumed by the transaction, includes both computation and data",
"allOf": [
{
"title": "ComputationResources",
"$ref": "#/components/schemas/COMPUTATION_RESOURCES"
},
{
"type": "object",
"title": "DataResources",
"description": "the data-availability resources of this transaction",
"properties": {
"data_availability": {
"type": "object",
"properties": {
"l1_gas": {
"title": "L1Gas",
"description": "the gas consumed by this transaction's data, 0 if it uses data gas for DA",
"type": "integer"
},
"l1_data_gas": {
"title": "L1DataGas",
"description": "the data gas consumed by this transaction's data, 0 if it uses gas for DA",
"type": "integer"
}
},
"required": [
"l1_gas",
"l1_data_gas"
]
}
},
"required": [
"data_availability"
]
}
]
}
},
"errors": {
Expand Down
31 changes: 25 additions & 6 deletions crates/papyrus_rpc/resources/V0_7/starknet_trace_api_openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@
"description": "the state diffs induced by the transaction",
"$ref": "#/components/schemas/STATE_DIFF"
},
"execution_resources": {
"title": "Execution resources",
"description": "the resources consumed by the transaction, includes both computation and data",
"$ref": "#/components/schemas/EXECUTION_RESOURCES"
},
"type": {
"title": "Type",
"type": "string",
Expand All @@ -196,7 +201,8 @@
},
"required": [
"type",
"execute_invocation"
"execute_invocation",
"execution_resources"
]
},
{
Expand All @@ -215,6 +221,11 @@
"description": "the state diffs induced by the transaction",
"$ref": "#/components/schemas/STATE_DIFF"
},
"execution_resources": {
"title": "Execution resources",
"description": "the resources consumed by the transaction, includes both computation and data",
"$ref": "#/components/schemas/EXECUTION_RESOURCES"
},
"type": {
"title": "Type",
"type": "string",
Expand All @@ -224,7 +235,8 @@
}
},
"required": [
"type"
"type",
"execution_resources"
]
},
{
Expand All @@ -247,6 +259,11 @@
"description": "the state diffs induced by the transaction",
"$ref": "#/components/schemas/STATE_DIFF"
},
"execution_resources": {
"title": "Execution resources",
"description": "the resources consumed by the transaction, includes both computation and data",
"$ref": "#/components/schemas/EXECUTION_RESOURCES"
},
"type": {
"title": "Type",
"type": "string",
Expand All @@ -257,6 +274,7 @@
},
"required": [
"type",
"execution_resources",
"constructor_invocation"
]
},
Expand Down Expand Up @@ -357,11 +375,9 @@
}
},
"execution_resources": {
"title": "Execution resources",
"title": "Computation resources",
"description": "Resources consumed by the internal call",
"items": {
"$ref": "#/components/schemas/EXECUTION_RESOURCES"
}
"$ref": "#/components/schemas/COMPUTATION_RESOURCES"
}
},
"required": [
Expand Down Expand Up @@ -458,6 +474,9 @@
"STATE_DIFF": {
"$ref": "./starknet_api_openrpc.json#/components/schemas/STATE_DIFF"
},
"COMPUTATION_RESOURCES": {
"$ref": "./starknet_api_openrpc.json#/components/schemas/COMPUTATION_RESOURCES"
},
"EXECUTION_RESOURCES": {
"$ref": "./starknet_api_openrpc.json#/components/schemas/EXECUTION_RESOURCES"
}
Expand Down
22 changes: 15 additions & 7 deletions crates/papyrus_rpc/src/v0_7/api/api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use jsonrpsee::types::ErrorObjectOwned;
use jsonrpsee::RpcModule;
use lazy_static::lazy_static;
use papyrus_common::pending_classes::{PendingClasses, PendingClassesTrait};
use papyrus_execution::objects::{PendingData as ExecutionPendingData, TransactionTrace};
use papyrus_execution::objects::PendingData as ExecutionPendingData;
use papyrus_execution::{
estimate_fee as exec_estimate_fee,
execute_call,
Expand Down Expand Up @@ -76,6 +76,7 @@ use super::super::error::{
TOO_MANY_KEYS_IN_FILTER,
TRANSACTION_HASH_NOT_FOUND,
};
use super::super::execution::TransactionTrace;
use super::super::state::{AcceptedStateUpdate, PendingStateUpdate, StateUpdate};
use super::super::transaction::{
get_block_tx_hashes_by_number,
Expand Down Expand Up @@ -1097,7 +1098,11 @@ impl JsonRpcServer for JsonRpcServerImpl {
Ok(simulation_results
.into_iter()
.map(|simulation_output| SimulatedTransaction {
transaction_trace: simulation_output.transaction_trace,
transaction_trace: (
simulation_output.transaction_trace,
simulation_output.induced_state_diff,
)
.into(),
fee_estimation: FeeEstimate::from(
simulation_output.gas_price,
simulation_output.fee,
Expand Down Expand Up @@ -1245,10 +1250,9 @@ impl JsonRpcServer for JsonRpcServerImpl {

block_not_reverted_validator.validate(&self.storage_reader)?;

Ok(simulation_results
.pop()
.expect("Should have transaction exeuction result")
.transaction_trace)
let simulation_result =
simulation_results.pop().expect("Should have transaction exeuction result");
Ok((simulation_result.transaction_trace, simulation_result.induced_state_diff).into())
}

#[instrument(skip(self), level = "debug", err)]
Expand Down Expand Up @@ -1369,7 +1373,11 @@ impl JsonRpcServer for JsonRpcServerImpl {
.zip(transaction_hashes)
.map(|(simulation_output, transaction_hash)| TransactionTraceWithHash {
transaction_hash,
trace_root: simulation_output.transaction_trace,
trace_root: (
simulation_output.transaction_trace,
simulation_output.induced_state_diff,
)
.into(),
})
.collect())
}
Expand Down
3 changes: 2 additions & 1 deletion crates/papyrus_rpc/src/v0_7/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use jsonrpsee::types::ErrorObjectOwned;
use papyrus_common::deprecated_class_abi::calculate_deprecated_class_abi_length;
use papyrus_common::pending_classes::ApiContractClass;
use papyrus_common::BlockHashAndNumber;
use papyrus_execution::objects::{PriceUnit, TransactionTrace};
use papyrus_execution::objects::PriceUnit;
use papyrus_execution::{AbiSize, ExecutableTransactionInput, ExecutionError, SierraSize};
use papyrus_proc_macros::versioned_rpc;
use papyrus_storage::compiled_class::CasmStorageReader;
Expand Down Expand Up @@ -39,6 +39,7 @@ use super::error::{
CONTRACT_NOT_FOUND,
INVALID_CONTINUATION_TOKEN,
};
use super::execution::TransactionTrace;
use super::state::{ContractClass, StateUpdate};
use super::transaction::{
DeployAccountTransaction,
Expand Down
Loading

0 comments on commit f1ca12e

Please sign in to comment.