Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

propagate actor events and Receipt::events_root. #332

Merged
merged 14 commits into from
Nov 16, 2022
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
19 changes: 7 additions & 12 deletions rust/Cargo.lock

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

7 changes: 7 additions & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,10 @@ opencl = ["filecoin-proofs-api/opencl", "bellperson/opencl", "storage-proofs-por
cuda = ["filecoin-proofs-api/cuda", "bellperson/cuda", "storage-proofs-porep/cuda", "rust-gpu-tools/cuda", "fvm3/cuda", "fvm2/cuda"]
multicore-sdr = ["storage-proofs-porep/multicore-sdr"]
c-headers = ["safer-ffi/headers"]


[patch.crates-io]
raulk marked this conversation as resolved.
Show resolved Hide resolved
fvm3 = { package = "fvm", git = "https://github.com/filecoin-project/ref-fvm", branch = "raulk/events" }
fvm3_shared = { package = "fvm_shared", git = "https://github.com/filecoin-project/ref-fvm", branch = "raulk/events" }
fvm3_ipld_encoding = { package = "fvm_ipld_encoding", git = "https://github.com/filecoin-project/ref-fvm", branch = "raulk/events" }
fvm_ipld_blockstore = { git = "https://github.com/filecoin-project/ref-fvm", branch = "raulk/events" }
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
20 changes: 20 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,19 @@ 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)
.ok()
raulk marked this conversation as resolved.
Show resolved Hide resolved
.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 +313,8 @@ fn fvm_machine_execute_message(
gas_burned,
exec_trace,
failure_info,
events,
events_root,
})
})
}
Expand Down Expand Up @@ -377,6 +393,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 +412,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 +424,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 +442,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>>,
}