-
Notifications
You must be signed in to change notification settings - Fork 137
Optional fvm for curio #550
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
Merged
+257
−81
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e58a290
optional fvm for curio
snadrus cb93391
Merge branch 'master' into fvm-optional
snadrus d6570b0
tests
snadrus a9f1473
fvm feature list
snadrus 8080caf
Update install-filcrypto for consistency
snadrus 4ba7b36
Update install-filcrypto to declare feature list only when available
snadrus bf0e4b4
Update install-filcrypto opt-out FVM
snadrus 05bc4f8
cgo-bindings gcc12
snadrus 3084e07
lint
snadrus 3779805
merge
snadrus 41eef0e
Apply suggestions from code review
snadrus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| //go:build fvm | ||
|
|
||
| package cgo | ||
|
|
||
| /* | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| //go:build fvm | ||
|
|
||
| package cgo | ||
|
|
||
| /* | ||
| #cgo LDFLAGS: -L${SRCDIR}/.. | ||
| #cgo pkg-config: ${SRCDIR}/../filcrypto.pc | ||
| #include "../filcrypto.h" | ||
| #include <stdlib.h> | ||
| */ | ||
| import "C" | ||
|
|
||
| type FvmRegisteredVersion C.FvmRegisteredVersion_t | ||
|
|
||
| type FvmMachine C.InnerFvmMachine_t | ||
| type FvmMachineExecuteResponse C.FvmMachineExecuteResponse_t | ||
|
|
||
| type resultFvmMachine C.Result_InnerFvmMachine_ptr_t | ||
| type resultFvmMachineExecuteResponse C.Result_FvmMachineExecuteResponse_t | ||
|
|
||
| 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) | ||
| } | ||
|
|
||
| func (ptr *resultFvmMachine) errorMsg() *SliceBoxedUint8 { | ||
| return (*SliceBoxedUint8)(&ptr.error_msg) | ||
| } | ||
|
|
||
| func (ptr *resultFvmMachine) destroy() { | ||
| if ptr != nil { | ||
| C.destroy_create_fvm_machine_response((*C.Result_InnerFvmMachine_ptr_t)(ptr)) | ||
| ptr = nil | ||
| } | ||
| } | ||
|
|
||
| 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(), | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| //go:build !fvm | ||
|
|
||
| package ffi | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
|
|
||
| "github.com/filecoin-project/filecoin-ffi/cgo" | ||
| "github.com/filecoin-project/go-state-types/abi" | ||
| "github.com/filecoin-project/go-state-types/big" | ||
| "github.com/filecoin-project/go-state-types/network" | ||
| "github.com/ipfs/go-cid" | ||
| "golang.org/x/xerrors" | ||
| ) | ||
|
|
||
| type FVM struct{} | ||
|
|
||
| type FVMOpts struct { | ||
| FVMVersion uint64 | ||
| Externs cgo.Externs | ||
|
|
||
| Epoch abi.ChainEpoch | ||
| Timestamp uint64 | ||
| ChainID uint64 | ||
| BaseFee abi.TokenAmount | ||
| BaseCircSupply abi.TokenAmount | ||
| NetworkVersion network.Version | ||
| StateBase cid.Cid | ||
| Tracing bool | ||
| FlushAllBlocks bool | ||
|
|
||
| Debug bool | ||
| ActorRedirect cid.Cid | ||
| } | ||
|
|
||
| func CreateFVM(opts *FVMOpts) (*FVM, error) { | ||
| return nil, errors.New("FVM support not built in this binary") | ||
| } | ||
|
|
||
| func (f *FVM) ApplyMessage(_ []byte, _ uint) (*ApplyRet, error) { | ||
| return nil, errors.New("FVM support not built in this binary") | ||
| } | ||
|
|
||
| func (f *FVM) ApplyImplicitMessage(_ []byte) (*ApplyRet, error) { | ||
| return nil, errors.New("FVM support not built in this binary") | ||
| } | ||
|
|
||
| func (f *FVM) Flush() (cid.Cid, error) { | ||
| return cid.Undef, errors.New("FVM support not built in this binary") | ||
| } | ||
|
|
||
| // Minimal stubs to satisfy references | ||
| type ApplyRet struct { | ||
| 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 | ||
| EventsRoot *cid.Cid | ||
| EventsBytes []byte | ||
| } | ||
|
|
||
| // Ensure cgo.Externs referenced to avoid unused import when stubbed | ||
| var _ = func() any { return context.TODO() } | ||
|
|
||
| // splitBigInt splits a big.Int into high and low uint64 values. | ||
| // This is used by tests and needs to be available even when FVM is not built. | ||
| func splitBigInt(i big.Int) (hi uint64, lo uint64, err error) { | ||
| if i.Sign() < 0 { | ||
| return 0, 0, xerrors.Errorf("negative number: %s", i) | ||
| } | ||
| words := i.Bits() | ||
| switch len(words) { | ||
| case 2: | ||
| hi = uint64(words[1]) | ||
| fallthrough | ||
| case 1: | ||
| lo = uint64(words[0]) | ||
| case 0: | ||
| default: | ||
| return 0, 0, xerrors.Errorf("exceeds max bigint size: %s", i) | ||
| } | ||
| return hi, lo, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.