Skip to content

Commit

Permalink
feat: put blocks with codecs in the trace (#1654)
Browse files Browse the repository at this point in the history
Otherwise, users can't decode them.
  • Loading branch information
Stebalien authored Feb 9, 2023
1 parent 7c9de90 commit 4c7a6ba
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
19 changes: 6 additions & 13 deletions fvm/src/call_manager/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use anyhow::{anyhow, Context};
use cid::Cid;
use derive_more::{Deref, DerefMut};
use fvm_ipld_amt::Amt;
use fvm_ipld_encoding::{to_vec, RawBytes, CBOR};
use fvm_ipld_encoding::{to_vec, CBOR};
use fvm_shared::address::{Address, Payload};
use fvm_shared::econ::TokenAmount;
use fvm_shared::error::{ErrorNumber, ExitCode};
Expand Down Expand Up @@ -184,10 +184,7 @@ where
from,
to,
method,
params: params
.as_ref()
.map(|blk| blk.data().to_owned().into())
.unwrap_or_default(),
params: params.as_ref().map(Into::into),
value: value.clone(),
});
}
Expand Down Expand Up @@ -218,15 +215,11 @@ where

if self.machine.context().tracing {
self.trace(match &result {
Ok(InvocationResult { exit_code, value }) => ExecutionEvent::CallReturn(
*exit_code,
value
.as_ref()
.map(|blk| RawBytes::from(blk.data().to_vec()))
.unwrap_or_default(),
),
Ok(InvocationResult { exit_code, value }) => {
ExecutionEvent::CallReturn(*exit_code, value.as_ref().map(Into::into))
}
Err(ExecutionError::OutOfGas) => {
ExecutionEvent::CallReturn(ExitCode::SYS_OUT_OF_GAS, RawBytes::default())
ExecutionEvent::CallReturn(ExitCode::SYS_OUT_OF_GAS, None)
}
Err(ExecutionError::Fatal(_)) => {
ExecutionEvent::CallError(SyscallError::new(ErrorNumber::Forbidden, "fatal"))
Expand Down
22 changes: 22 additions & 0 deletions fvm/src/kernel/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::convert::TryInto;
use std::rc::Rc;

use fvm_ipld_encoding::ipld_block::IpldBlock;
use fvm_ipld_encoding::{CBOR, DAG_CBOR};
use fvm_shared::IPLD_RAW;
use thiserror::Error;
Expand Down Expand Up @@ -75,6 +76,27 @@ impl Block {
}
}

impl From<IpldBlock> for Block {
fn from(b: IpldBlock) -> Self {
Block::new(b.codec, b.data)
}
}

impl From<&IpldBlock> for Block {
fn from(b: &IpldBlock) -> Self {
Block::new(b.codec, &*b.data)
}
}

impl From<&Block> for IpldBlock {
fn from(b: &Block) -> Self {
IpldBlock {
codec: b.codec,
data: Vec::from(&**b.data),
}
}
}

#[derive(Error, Debug)]
pub enum BlockPutError {
#[error("too many blocks have been written")]
Expand Down
6 changes: 3 additions & 3 deletions fvm/src/trace/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2021-2023 Protocol Labs
// SPDX-License-Identifier: Apache-2.0, MIT
use fvm_ipld_encoding::RawBytes;
use fvm_ipld_encoding::ipld_block::IpldBlock;
use fvm_shared::address::Address;
use fvm_shared::econ::TokenAmount;
use fvm_shared::error::ExitCode;
Expand All @@ -23,9 +23,9 @@ pub enum ExecutionEvent {
from: ActorID,
to: Address,
method: MethodNum,
params: RawBytes,
params: Option<IpldBlock>,
value: TokenAmount,
},
CallReturn(ExitCode, RawBytes),
CallReturn(ExitCode, Option<IpldBlock>),
CallError(SyscallError),
}

0 comments on commit 4c7a6ba

Please sign in to comment.