Skip to content

Commit

Permalink
Initial code for execution info (#4685)
Browse files Browse the repository at this point in the history
* Initial code for execution info

* Cargo clippy fixes

* Update protoc actions for CI

* Merge use

* Update ExecutionInfo with ExecutionInfoForSlot

* Fix bad rebase

* Cargo fmt pass

* Fix schnellru deps

* Update ExecuteInfoForSlot

* Cargo fmt pass
  • Loading branch information
sydhds authored May 15, 2024
1 parent a1a2190 commit 6f9acc3
Show file tree
Hide file tree
Showing 24 changed files with 461 additions and 187 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ jobs:
with:
shared-key: "check"
save-if: ${{ github.ref_name == 'main' }}
- uses: arduino/setup-protoc@v1
- uses: arduino/setup-protoc@v3
with:
version: '3.x'
version: '23.x'
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions-rs/cargo@v1
with:
Expand All @@ -89,9 +89,9 @@ jobs:
with:
shared-key: "clippy"
save-if: ${{ github.ref_name == 'main' }}
- uses: arduino/setup-protoc@v1
- uses: arduino/setup-protoc@v3
with:
version: '3.x'
version: '23.x'
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions-rs/clippy-check@v1
with:
Expand Down Expand Up @@ -199,7 +199,6 @@ jobs:
save-if: ${{ github.ref_name == 'main' }}
- uses: arduino/setup-protoc@v3
with:
# version: '3.x'
version: "23.x"
include-pre-releases: false
repo-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -282,9 +281,9 @@ jobs:
with:
shared-key: "doc"
save-if: ${{ github.ref_name == 'main' }}
- uses: arduino/setup-protoc@v1
- uses: arduino/setup-protoc@v3
with:
version: '3.x'
version: '23.x'
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions-rs/cargo@v1
with:
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions massa-api/src/tests/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,9 @@ async fn execute_read_only_bytecode() {
slot_trace: None,
#[cfg(feature = "dump-block")]
storage: None,
deferred_credits_execution: vec![],
cancel_async_message_execution: vec![],
auto_sell_execution: vec![],
},
gas_cost: 100,
call_result: "toto".as_bytes().to_vec(),
Expand Down Expand Up @@ -782,6 +785,9 @@ async fn execute_read_only_call() {
slot_trace: None,
#[cfg(feature = "dump-block")]
storage: None,
deferred_credits_execution: vec![],
cancel_async_message_execution: vec![],
auto_sell_execution: vec![],
},
gas_cost: 100,
call_result: "toto".as_bytes().to_vec(),
Expand Down
1 change: 1 addition & 0 deletions massa-execution-exports/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ gas_calibration = ["tempfile"]
test-exports = ["massa_models/test-exports", "tempfile", "mockall"]
execution-trace = ["massa-sc-runtime/execution-trace"]
dump-block = []
execution-info = ["execution-trace"]

[dependencies]
displaydoc = {workspace = true}
Expand Down
2 changes: 1 addition & 1 deletion massa-execution-exports/src/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::types::SlotExecutionOutput;

#[cfg(feature = "execution-trace")]
use crate::types::SlotAbiCallStack;
use crate::types_trace_info::SlotAbiCallStack;

/// channels used by the execution worker
#[derive(Clone)]
Expand Down
2 changes: 1 addition & 1 deletion massa-execution-exports/src/controller_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::collections::BTreeMap;
use std::collections::HashMap;

#[cfg(feature = "execution-trace")]
use crate::types::{AbiTrace, SlotAbiCallStack, Transfer};
use crate::types_trace_info::{AbiTrace, SlotAbiCallStack, Transfer};

#[cfg_attr(feature = "test-exports", mockall::automock)]
/// interface that communicates with the execution worker thread
Expand Down
5 changes: 4 additions & 1 deletion massa-execution-exports/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ pub use types::{
#[cfg(any(feature = "test-exports", feature = "gas_calibration"))]
pub mod test_exports;

/// types for execution-trace / execution-info
pub mod types_trace_info;

#[cfg(feature = "execution-trace")]
pub use types::{
pub use types_trace_info::{
AbiTrace, SCRuntimeAbiTraceType, SCRuntimeAbiTraceValue, SlotAbiCallStack, Transfer,
};
148 changes: 7 additions & 141 deletions massa-execution-exports/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,7 @@ use massa_storage::Storage;
use std::collections::{BTreeMap, BTreeSet};

#[cfg(feature = "execution-trace")]
use massa_models::prehash::PreHashMap;
#[cfg(feature = "execution-trace")]
pub use massa_sc_runtime::AbiTrace as SCRuntimeAbiTrace;
#[cfg(feature = "execution-trace")]
pub use massa_sc_runtime::AbiTraceType as SCRuntimeAbiTraceType;
#[cfg(feature = "execution-trace")]
pub use massa_sc_runtime::AbiTraceValue as SCRuntimeAbiTraceValue;
#[cfg(feature = "execution-trace")]
use std::collections::VecDeque;
use crate::types_trace_info::{SlotAbiCallStack, Transfer};

/// Metadata needed to execute the block
#[derive(Clone, Debug)]
Expand Down Expand Up @@ -214,118 +206,6 @@ pub struct ExecutionAddressInfo {
pub cycle_infos: Vec<ExecutionAddressCycleInfo>,
}

#[cfg(feature = "execution-trace")]
/// A trace of an abi call + its parameters + the result
#[derive(Debug, Clone)]
pub struct AbiTrace {
/// Abi name
pub name: String,
/// Abi parameters
pub parameters: Vec<SCRuntimeAbiTraceValue>,
/// Abi return value
pub return_value: SCRuntimeAbiTraceType,
/// Abi sub calls
pub sub_calls: Option<Vec<AbiTrace>>,
}

#[cfg(feature = "execution-trace")]
impl From<SCRuntimeAbiTrace> for AbiTrace {
fn from(trace: SCRuntimeAbiTrace) -> Self {
Self {
name: trace.name,
parameters: trace.params,
return_value: trace.return_value,
sub_calls: trace.sub_calls.map(|sub_calls| {
sub_calls
.into_iter()
.map(|sub_call| sub_call.into())
.collect()
}),
}
}
}

#[cfg(feature = "execution-trace")]
impl AbiTrace {
/// Flatten and filter for abi names in an AbiTrace
pub fn flatten_filter(&self, abi_names: &Vec<String>) -> Vec<&Self> {
let mut filtered: Vec<&Self> = Default::default();
let mut to_process: VecDeque<&Self> = vec![self].into();

while !to_process.is_empty() {
let t = to_process.pop_front();
if let Some(trace) = t {
if abi_names.iter().find(|t| *(*t) == trace.name).is_some() {
// filtered.extend(&trace)
filtered.push(trace);
}

if let Some(sub_call) = &trace.sub_calls {
for sc in sub_call.iter().rev() {
to_process.push_front(sc);
}
}
}
}

filtered
}

/// This function assumes that the abi trace is a transfer.
/// Calling this function on a non-transfer abi trace will have undefined behavior.
pub fn parse_transfer(&self) -> (String, String, u64) {
let t_from = self
.parameters
.iter()
.find_map(|p| {
if p.name == "from_address" {
if let SCRuntimeAbiTraceType::String(v) = &p.value {
return Some(v.clone());
}
}
None
})
.unwrap_or_default();
let t_to = self
.parameters
.iter()
.find_map(|p| {
if p.name == "to_address" {
if let SCRuntimeAbiTraceType::String(v) = &p.value {
return Some(v.clone());
}
}
None
})
.unwrap_or_default();
let t_amount = self
.parameters
.iter()
.find_map(|p| {
if p.name == "raw_amount" {
if let SCRuntimeAbiTraceType::U64(v) = &p.value {
return Some(v.clone());
}
}
None
})
.unwrap_or_default();
(t_from, t_to, t_amount)
}
}

#[cfg(feature = "execution-trace")]
#[derive(Debug, Clone)]
/// Structure for all abi calls in a slot
pub struct SlotAbiCallStack {
/// Slot
pub slot: Slot,
/// asc call stacks
pub asc_call_stacks: Vec<Vec<AbiTrace>>,
/// operation call stacks
pub operation_call_stacks: PreHashMap<OperationId, Vec<AbiTrace>>,
}

/// structure describing the output of the execution of a slot
#[derive(Debug, Clone)]
pub enum SlotExecutionOutput {
Expand Down Expand Up @@ -364,26 +244,12 @@ pub struct ExecutionOutput {
/// storage
#[cfg(feature = "dump-block")]
pub storage: Option<Storage>,
}

#[cfg(feature = "execution-trace")]
#[derive(Debug, Clone)]
/// structure describing a transfer
pub struct Transfer {
/// From
pub from: Address,
/// To
pub to: Address,
/// Amount
pub amount: Amount,
/// Effective received amount
pub effective_received_amount: Amount,
/// operation id
pub op_id: OperationId,
/// success or not
pub succeed: bool,
/// Fee
pub fee: Amount,
/// Deferred credits execution (empty if execution-info feature is NOT enabled)
pub deferred_credits_execution: Vec<(Address, Result<Amount, String>)>,
/// Cancel async message execution (empty if execution-info feature is NOT enabled)
pub cancel_async_message_execution: Vec<(Address, Result<Amount, String>)>,
/// Auto sell roll execution (empty if execution-info feature is NOT enabled)
pub auto_sell_execution: Vec<(Address, Amount)>,
}

/// structure describing the output of a read only execution
Expand Down
Loading

0 comments on commit 6f9acc3

Please sign in to comment.