Skip to content

Commit

Permalink
propagate actor events and Receipt::events_root. (#332)
Browse files Browse the repository at this point in the history
  • Loading branch information
raulk authored Nov 16, 2022
1 parent 1537f74 commit 14151f5
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 26 deletions.
5 changes: 4 additions & 1 deletion cgo/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ type FvmMachineExecuteResponseGo struct {
GasBurned int64
ExecTrace []byte
FailureInfo string
Events []byte
EventsRoot []byte
}

func (ptr SliceBoxedUint8) slice() []byte {
Expand Down Expand Up @@ -612,7 +614,6 @@ func (ptr *PoStProof) Destroy() {
}
}


func (ptr *resultFvmMachineExecuteResponse) statusCode() FCPResponseStatus {
return FCPResponseStatus(ptr.status_code)
}
Expand Down Expand Up @@ -669,5 +670,7 @@ func (r FvmMachineExecuteResponse) copy() FvmMachineExecuteResponseGo {
GasBurned: int64(r.gas_burned),
ExecTrace: r.exec_trace.copy(),
FailureInfo: string(r.failure_info.slice()),
Events: r.events.copy(),
EventsRoot: r.events_root.copy(),
}
}
33 changes: 19 additions & 14 deletions fvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ package ffi
import "C"
import (
"context"
"fmt"
gobig "math/big"
"runtime"

Expand Down Expand Up @@ -129,20 +130,7 @@ func (f *FVM) ApplyMessage(msgBytes []byte, chainLen uint) (*ApplyRet, error) {
return nil, err
}

return &ApplyRet{
Return: resp.ReturnVal,
ExitCode: resp.ExitCode,
GasUsed: int64(resp.GasUsed),
MinerPenalty: reformBigInt(resp.PenaltyHi, resp.PenaltyLo),
MinerTip: reformBigInt(resp.MinerTipHi, resp.MinerTipLo),
BaseFeeBurn: reformBigInt(resp.BaseFeeBurnHi, resp.BaseFeeBurnLo),
OverEstimationBurn: reformBigInt(resp.OverEstimationBurnHi, resp.OverEstimationBurnLo),
Refund: reformBigInt(resp.RefundHi, resp.RefundLo),
GasRefund: int64(resp.GasRefund),
GasBurned: int64(resp.GasBurned),
ExecTraceBytes: resp.ExecTrace,
FailureInfo: resp.FailureInfo,
}, nil
return buildResponse(resp)
}

func (f *FVM) ApplyImplicitMessage(msgBytes []byte) (*ApplyRet, error) {
Expand All @@ -157,6 +145,19 @@ func (f *FVM) ApplyImplicitMessage(msgBytes []byte) (*ApplyRet, error) {
return nil, err
}

return buildResponse(resp)
}

func buildResponse(resp cgo.FvmMachineExecuteResponseGo) (*ApplyRet, error) {
var eventsRoot *cid.Cid
if len(resp.EventsRoot) > 0 {
if eventsRootCid, err := cid.Cast(resp.EventsRoot); err != nil {
return nil, fmt.Errorf("failed to cast events root CID: %w", err)
} else {
eventsRoot = &eventsRootCid
}
}

return &ApplyRet{
Return: resp.ReturnVal,
ExitCode: resp.ExitCode,
Expand All @@ -170,6 +171,8 @@ func (f *FVM) ApplyImplicitMessage(msgBytes []byte) (*ApplyRet, error) {
GasBurned: int64(resp.GasBurned),
ExecTraceBytes: resp.ExecTrace,
FailureInfo: resp.FailureInfo,
EventsRoot: eventsRoot,
EventsBytes: resp.Events,
}, nil
}

Expand All @@ -196,6 +199,8 @@ type ApplyRet struct {
GasBurned int64
ExecTraceBytes []byte
FailureInfo string
EventsRoot *cid.Cid
EventsBytes []byte
}

// NOTE: We only support 64bit platforms
Expand Down
22 changes: 13 additions & 9 deletions rust/Cargo.lock

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

4 changes: 2 additions & 2 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ memmap = "0.7"
rust-gpu-tools = { version = "0.5", optional = true, default-features = false }
storage-proofs-porep = { version = "~12.0", default-features = false }
fr32 = { version = "~5.0", default-features = false }
fvm3 = { package = "fvm", version = "3.0.0-alpha.7", default-features = false, features = ["f4-as-account"] }
fvm3_shared = { package = "fvm_shared", version = "3.0.0-alpha.10" }
fvm3 = { package = "fvm", version = "3.0.0-alpha.8", default-features = false, features = ["f4-as-account"] }
fvm3_shared = { package = "fvm_shared", version = "3.0.0-alpha.11" }
fvm3_ipld_encoding = { package = "fvm_ipld_encoding", version = "0.3.0" }
fvm2 = { package = "fvm", version = "2.1.0", default-features = false }
fvm2_shared = { package = "fvm_shared", version = "2.0.0" }
Expand Down
2 changes: 2 additions & 0 deletions rust/src/fvm/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ mod v2 {
exit_code: ExitCode::new(ret.msg_receipt.exit_code.value()),
return_data: RawBytes::new(ret.msg_receipt.return_data.into()),
gas_used: ret.msg_receipt.gas_used,
events_root: None,
},
penalty: TokenAmount::from_atto(ret.penalty.atto().clone()),
miner_tip: TokenAmount::from_atto(ret.miner_tip.atto().clone()),
Expand Down Expand Up @@ -314,6 +315,7 @@ mod v2 {
_ => None,
})
.collect(),
events: vec![],
}),
Err(x) => Err(x),
}
Expand Down
24 changes: 24 additions & 0 deletions rust/src/fvm/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ fn fvm_machine_execute_message(
exit_code,
return_data,
gas_used,
events_root,
} = apply_ret.msg_receipt;

let return_val = if return_data.is_empty() {
Expand All @@ -280,6 +281,23 @@ fn fvm_machine_execute_message(
Some(bytes.into_boxed_slice().into())
};

let events = if apply_ret.events.is_empty() {
None
} else {
// This field is informational, if for whatever reason we fail to serialize
// return a None and move on. What's important for consensus is the
// events_root in the receipt.
to_vec(&apply_ret.events)
.map_err(|err| {
log::warn!("[UNEXPECTED] failed to serialize events: {}", err);
err
})
.ok()
.map(|evts| evts.into_boxed_slice().into())
};

let events_root = events_root.map(|cid| cid.to_bytes().into_boxed_slice().into());

// TODO: Do something with the backtrace.
Ok(FvmMachineExecuteResponse {
exit_code: exit_code.value() as u64,
Expand All @@ -299,6 +317,8 @@ fn fvm_machine_execute_message(
gas_burned,
exec_trace,
failure_info,
events,
events_root,
})
})
}
Expand Down Expand Up @@ -377,6 +397,7 @@ fn build_lotus_trace(
exit_code: ExitCode::OK,
return_data: RawBytes::default(),
gas_used: 0,
events_root: None,
},
error: String::new(),
gas_charges: vec![],
Expand All @@ -395,6 +416,7 @@ fn build_lotus_trace(
exit_code: ExitCode::OK,
return_data,
gas_used: 0,
events_root: None,
};
return Ok(new_trace);
}
Expand All @@ -406,6 +428,7 @@ fn build_lotus_trace(
exit_code,
return_data: Default::default(),
gas_used: 0,
events_root: None,
};
return Ok(new_trace);
}
Expand All @@ -423,6 +446,7 @@ fn build_lotus_trace(
exit_code,
return_data: Default::default(),
gas_used: 0,
events_root: None,
};
return Ok(new_trace);
}
Expand Down
2 changes: 2 additions & 0 deletions rust/src/fvm/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ pub struct FvmMachineExecuteResponse {
pub gas_burned: i64,
pub exec_trace: Option<c_slice::Box<u8>>,
pub failure_info: Option<str::Box>,
pub events: Option<c_slice::Box<u8>>,
pub events_root: Option<c_slice::Box<u8>>,
}

0 comments on commit 14151f5

Please sign in to comment.