Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 16 additions & 0 deletions cgo/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ package cgo
// #cgo darwin LDFLAGS: ${SRCDIR}/../libfilcrypto.a -Wl,-undefined,dynamic_lookup
// #cgo pkg-config: ${SRCDIR}/../filcrypto.pc
// #include "../filcrypto.h"
// // Provide fallbacks when FVM is not compiled into filcrypto
// #ifndef FVM_ERROR_INVALID_HANDLE
// #define FVM_ERROR_INVALID_HANDLE -1
// #endif
// #ifndef FVM_ERROR_NOT_FOUND
// #define FVM_ERROR_NOT_FOUND -2
// #endif
// #ifndef FVM_ERROR_IO
// #define FVM_ERROR_IO -3
// #endif
// #ifndef FVM_ERROR_INVALID_ARGUMENT
// #define FVM_ERROR_INVALID_ARGUMENT -4
// #endif
// #ifndef FVM_ERROR_PANIC
// #define FVM_ERROR_PANIC -5
// #endif
import "C"
import (
"fmt"
Expand Down
2 changes: 2 additions & 0 deletions cgo/fvm.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build fvm

package cgo

/*
Expand Down
69 changes: 7 additions & 62 deletions cgo/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type RegisteredAggregationProof C.RegisteredAggregationProof_t
type RegisteredPoStProof C.RegisteredPoStProof_t
type RegisteredUpdateProof C.RegisteredUpdateProof_t

type FvmRegisteredVersion C.FvmRegisteredVersion_t
// FVM types moved to types_fvm.go behind build tag
Comment thread
snadrus marked this conversation as resolved.

type AggregationInputs C.AggregationInputs_t

Expand Down Expand Up @@ -49,8 +49,7 @@ type ByteArray32 C.uint8_32_array_t
type ByteArray48 C.uint8_48_array_t
type ByteArray96 C.uint8_96_array_t

type FvmMachine C.InnerFvmMachine_t
type FvmMachineExecuteResponse C.FvmMachineExecuteResponse_t
// FVM types moved to types_fvm.go behind build tag

type resultBool C.Result_bool_t
type resultGeneratePieceCommitment C.Result_GeneratePieceCommitment_t
Expand All @@ -70,8 +69,7 @@ type resultGenerateFallbackSectorChallenges C.Result_GenerateFallbackSectorChall
type resultGenerateSingleWindowPoStWithVanilla C.Result_GenerateSingleWindowPoStWithVanilla_t
type resultPoStProof C.Result_PoStProof_t

type resultFvmMachine C.Result_InnerFvmMachine_ptr_t
type resultFvmMachineExecuteResponse C.Result_FvmMachineExecuteResponse_t
// FVM types moved to types_fvm.go behind build tag

type result interface {
statusCode() FCPResponseStatus
Expand Down Expand Up @@ -606,63 +604,10 @@ func (ptr *PoStProof) Destroy() {
}
}

func (ptr *resultFvmMachineExecuteResponse) statusCode() FCPResponseStatus {
return FCPResponseStatus(ptr.status_code)
}

func (ptr *resultFvmMachineExecuteResponse) errorMsg() *SliceBoxedUint8 {
return (*SliceBoxedUint8)(&ptr.error_msg)
}

func (ptr *resultFvmMachineExecuteResponse) destroy() {
if ptr != nil {
C.destroy_fvm_machine_execute_response((*C.Result_FvmMachineExecuteResponse_t)(ptr))
ptr = nil
}
}

func (ptr *resultFvmMachine) statusCode() FCPResponseStatus {
return FCPResponseStatus(ptr.status_code)
}
// FVM helpers moved to types_fvm.go

func (ptr *resultFvmMachine) errorMsg() *SliceBoxedUint8 {
return (*SliceBoxedUint8)(&ptr.error_msg)
}
// FVM helpers moved to types_fvm.go

func (ptr *resultFvmMachine) destroy() {
if ptr != nil {
C.destroy_create_fvm_machine_response((*C.Result_InnerFvmMachine_ptr_t)(ptr))
ptr = nil
}
}
// FVM helpers moved to types_fvm.go

func (ptr *FvmMachine) Destroy() {
if ptr != nil {
C.drop_fvm_machine((*C.InnerFvmMachine_t)(ptr))
ptr = nil
}
}

func (r FvmMachineExecuteResponse) copy() FvmMachineExecuteResponseGo {
return FvmMachineExecuteResponseGo{
ExitCode: uint64(r.exit_code),
ReturnVal: (*SliceBoxedUint8)(&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: (*SliceBoxedUint8)(&r.exec_trace).copy(),
FailureInfo: string((*SliceBoxedUint8)(&r.failure_info).slice()),
Events: (*SliceBoxedUint8)(&r.events).copy(),
EventsRoot: (*SliceBoxedUint8)(&r.events_root).copy(),
}
}
// FVM helpers moved to types_fvm.go
3 changes: 2 additions & 1 deletion fvm.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//go:build cgo && (amd64 || arm64 || riscv64)
//go:build cgo && (amd64 || arm64 || riscv64) && fvm
// +build cgo
// +build amd64 arm64 riscv64
// +build fvm

package ffi

Expand Down
29 changes: 20 additions & 9 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ rayon = "1.10.0"
anyhow = "1.0.97"
serde_json = "1.0.140"
rust-gpu-tools = { version = "0.7", optional = true, default-features = false }
fvm4 = { package = "fvm", version = "~4.7.4", default-features = false, features = ["verify-signature", "nv28-dev"] }
fvm4_shared = { package = "fvm_shared", version = "~4.7.4" }
fvm3 = { package = "fvm", version = "~3.13.0", default-features = false }
fvm3_shared = { package = "fvm_shared", version = "~3.13.0" }
fvm2 = { package = "fvm", version = "~2.11.0", default-features = false }
fvm2_shared = { package = "fvm_shared", version = "~2.11.0" }
fvm_ipld_encoding = "0.5.3"
fvm_ipld_blockstore = "0.3.1"
fvm4 = { package = "fvm", version = "~4.7.4", default-features = false, features = ["verify-signature", "nv28-dev"], optional = true }
fvm4_shared = { package = "fvm_shared", version = "~4.7.4", optional = true }
fvm3 = { package = "fvm", version = "~3.13.0", default-features = false, optional = true }
fvm3_shared = { package = "fvm_shared", version = "~3.13.0", optional = true }
fvm2 = { package = "fvm", version = "~2.11.0", default-features = false, optional = true }
fvm2_shared = { package = "fvm_shared", version = "~2.11.0", optional = true }
fvm_ipld_encoding = { version = "0.5.3", optional = true }
fvm_ipld_blockstore = { version = "0.3.1", optional = true }
num-traits = "0.2.19"
cid = { version = "0.11.1", features = ["serde"], default-features = false }
lazy_static = "1.5.0"
Expand All @@ -54,7 +54,18 @@ memmap2 = "0.9"
tempfile = "3.19.1"

[features]
default = ["cuda", "multicore-sdr"]
default = ["cuda", "multicore-sdr", "fvm"]
fvm = [
"fvm2",
"fvm3",
"fvm4",
"fvm2_shared",
"fvm3_shared",
"fvm4_shared",
"fvm_ipld_encoding",
"fvm_ipld_blockstore",
]
curio = []
blst-portable = ["bls-signatures/blst-portable", "blstrs/portable"]
cuda = [
"filecoin-proofs-api/cuda",
Expand Down
4 changes: 3 additions & 1 deletion rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
#![allow(clippy::upper_case_acronyms)]

pub mod bls;
pub mod fvm;
pub mod proofs;
pub mod util;

#[cfg(feature = "fvm")]
pub mod fvm;

// Generates the headers.
// Run `HEADER_DIR=<dir> cargo test --locked build_headers --features c-headers` to build
#[safer_ffi::cfg_headers]
Expand Down
Loading