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 all gas outputs in ApplyRet #275

Merged
merged 7 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 34 additions & 18 deletions cgo/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,23 @@ type PoStProofGo struct {

/// FvmMachineExecuteResponse is a go allocated version of `FvmMachineExecuteResponse`.
type FvmMachineExecuteResponseGo struct {
ExitCode uint64
ReturnVal []byte
GasUsed uint64
PenaltyHi uint64
PenaltyLo uint64
MinerTipHi uint64
MinerTipLo uint64
ExecTrace []byte
FailureInfo string
ExitCode uint64
ReturnVal []byte
GasUsed uint64
PenaltyHi uint64
PenaltyLo uint64
MinerTipHi uint64
MinerTipLo uint64
BaseFeeBurnHi uint64
BaseFeeBurnLo uint64
OverEstimationBurnHi uint64
OverEstimationBurnLo uint64
RefundHi uint64
RefundLo uint64
GasRefund int64
GasBurned int64
ExecTrace []byte
FailureInfo string
}

func (ptr SliceBoxedUint8) slice() []byte {
Expand Down Expand Up @@ -636,14 +644,22 @@ func (ptr *FvmMachine) Destroy() {

func (r FvmMachineExecuteResponse) copy() FvmMachineExecuteResponseGo {
return FvmMachineExecuteResponseGo{
ExitCode: uint64(r.exit_code),
ReturnVal: r.return_val.copy(),
GasUsed: uint64(r.gas_used),
PenaltyHi: uint64(r.penalty_hi),
PenaltyLo: uint64(r.penalty_lo),
MinerTipHi: uint64(r.miner_tip_hi),
MinerTipLo: uint64(r.miner_tip_lo),
ExecTrace: r.exec_trace.copy(),
FailureInfo: string(r.failure_info.slice()),
ExitCode: uint64(r.exit_code),
ReturnVal: r.return_val.copy(),
GasUsed: uint64(r.gas_used),
PenaltyHi: uint64(r.penalty_hi),
PenaltyLo: uint64(r.penalty_lo),
MinerTipHi: uint64(r.miner_tip_hi),
MinerTipLo: uint64(r.miner_tip_lo),
BaseFeeBurnHi: uint64(r.base_fee_burn_hi),
BaseFeeBurnLo: uint64(r.base_fee_burn_lo),
OverEstimationBurnHi: uint64(r.over_estimation_burn_hi),
OverEstimationBurnLo: uint64(r.over_estimation_burn_lo),
RefundHi: uint64(r.refund_hi),
RefundLo: uint64(r.refund_lo),
GasRefund: int64(r.gas_refund),
GasBurned: int64(r.gas_burned),
ExecTrace: r.exec_trace.copy(),
FailureInfo: string(r.failure_info.slice()),
}
}
55 changes: 35 additions & 20 deletions fvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,18 @@ func (f *FVM) ApplyMessage(msgBytes []byte, chainLen uint) (*ApplyRet, error) {
}

return &ApplyRet{
Return: resp.ReturnVal,
ExitCode: resp.ExitCode,
GasUsed: int64(resp.GasUsed),
MinerPenalty: reformBigInt(resp.PenaltyHi, resp.PenaltyLo),
MinerTip: reformBigInt(resp.MinerTipHi, resp.MinerTipLo),
ExecTraceBytes: resp.ExecTrace,
FailureInfo: resp.FailureInfo,
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
}

Expand All @@ -130,12 +135,17 @@ func (f *FVM) ApplyImplicitMessage(msgBytes []byte) (*ApplyRet, error) {
}

return &ApplyRet{
Return: resp.ReturnVal,
ExitCode: resp.ExitCode,
GasUsed: int64(resp.GasUsed),
MinerPenalty: reformBigInt(resp.PenaltyHi, resp.PenaltyLo),
MinerTip: reformBigInt(resp.MinerTipHi, resp.MinerTipLo),
FailureInfo: resp.FailureInfo,
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),
FailureInfo: resp.FailureInfo,
}, nil
}

Expand All @@ -150,13 +160,18 @@ func (f *FVM) Flush() (cid.Cid, error) {
}

type ApplyRet struct {
Return []byte
ExitCode uint64
GasUsed int64
MinerPenalty abi.TokenAmount
MinerTip abi.TokenAmount
ExecTraceBytes []byte
FailureInfo string
Return []byte
ExitCode uint64
GasUsed int64
MinerPenalty abi.TokenAmount
MinerTip abi.TokenAmount
BaseFeeBurn abi.TokenAmount
OverEstimationBurn abi.TokenAmount
Refund abi.TokenAmount
GasRefund int64
GasBurned int64
ExecTraceBytes []byte
FailureInfo string
}

// NOTE: We only support 64bit platforms
Expand Down
13 changes: 13 additions & 0 deletions rust/src/fvm/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ fn fvm_machine_execute_message(
// TODO: use the non-bigint token amount everywhere in the FVM
let penalty: u128 = apply_ret.penalty.try_into().unwrap();
let miner_tip: u128 = apply_ret.miner_tip.try_into().unwrap();
let base_fee_burn: u128 = apply_ret.base_fee_burn.try_into().unwrap();
let over_estimation_burn: u128 = apply_ret.over_estimation_burn.try_into().unwrap();
let refund: u128 = apply_ret.refund.try_into().unwrap();
let gas_refund = apply_ret.gas_refund;
let gas_burned = apply_ret.gas_burned;

let Receipt {
exit_code,
Expand All @@ -197,6 +202,14 @@ fn fvm_machine_execute_message(
penalty_lo: penalty as u64,
miner_tip_hi: (miner_tip >> u64::BITS) as u64,
miner_tip_lo: miner_tip as u64,
base_fee_burn_hi: (base_fee_burn >> u64::BITS) as u64,
base_fee_burn_lo: base_fee_burn as u64,
over_estimation_burn_hi: (over_estimation_burn >> u64::BITS) as u64,
over_estimation_burn_lo: over_estimation_burn as u64,
refund_hi: (refund >> u64::BITS) as u64,
refund_lo: refund as u64,
gas_refund,
gas_burned,
exec_trace,
failure_info,
})
Expand Down
8 changes: 8 additions & 0 deletions rust/src/fvm/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ pub struct FvmMachineExecuteResponse {
pub penalty_lo: u64,
pub miner_tip_hi: u64,
pub miner_tip_lo: u64,
pub base_fee_burn_hi: u64,
pub base_fee_burn_lo: u64,
pub over_estimation_burn_hi: u64,
pub over_estimation_burn_lo: u64,
pub refund_hi: u64,
pub refund_lo: u64,
pub gas_refund: i64,
pub gas_burned: i64,
pub exec_trace: Option<c_slice::Box<u8>>,
pub failure_info: Option<str::Box>,
}