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

feat: FVM: always enable tracing for user-triggered executions #5323

Merged
merged 2 commits into from
Sep 26, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/consensus/expected.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func (c *Expected) RunStateTransition(ctx context.Context, ts *types.TipSet) (ci
Bsstore: c.bstore,
PRoot: ts.At(0).ParentStateRoot,
SysCallsImpl: c.syscallsImpl,
Tracing: false,
}

var parentEpoch abi.ChainEpoch
Expand Down
1 change: 1 addition & 0 deletions pkg/consensus/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (p *DefaultProcessor) ApplyBlocks(ctx context.Context,
PRoot: base,
Bsstore: vmOpts.Bsstore,
SysCallsImpl: vmOpts.SysCallsImpl,
Tracing: vmOpts.Tracing,
}

return fvm.NewVM(ctx, vmOpt)
Expand Down
14 changes: 3 additions & 11 deletions pkg/fvm/fvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"fmt"
"io"
"math"
"os"
"sort"
"sync"
Expand Down Expand Up @@ -316,7 +317,7 @@ func defaultFVMOpts(ctx context.Context, opts *vm.VmOption) (*ffi.FVMOpts, error
BaseCircSupply: circToReport,
NetworkVersion: opts.NetworkVersion,
StateBase: opts.PRoot,
Tracing: gas.EnableDetailedTracing,
Tracing: opts.Tracing || gas.EnableDetailedTracing,
}, nil
}

Expand Down Expand Up @@ -523,6 +524,7 @@ func (fvm *FVM) ApplyImplicitMessage(ctx context.Context, cmsg types.ChainMsg) (
start := constants.Clock.Now()
defer atomic.AddUint64(&StatApplied, 1)
vmMsg := cmsg.VMMessage()
vmMsg.GasLimit = math.MaxInt64 / 2
msgBytes, err := vmMsg.Serialize()
if err != nil {
return nil, fmt.Errorf("serializing msg: %w", err)
Expand Down Expand Up @@ -693,8 +695,6 @@ func (r *xRedirect) MarshalCBOR(w io.Writer) error {
return nil
}

var useFvmForMainnetV15 = os.Getenv("VENUS_USE_FVM_TO_SYNC_MAINNET_V15") == "1"

// WARNING: You will not affect your node's execution by misusing this feature, but you will confuse yourself thoroughly!
// An envvar that allows the user to specify debug actors bundles to be used by the FVM
// alongside regular execution. This is basically only to be used to print out specific logging information.
Expand All @@ -709,13 +709,5 @@ func NewVM(ctx context.Context, opts vm.VmOption) (vm.Interface, error) {
return NewFVM(ctx, &opts)
}

// Remove after v16 upgrade, this is only to support testing and validation of the FVM
if useFvmForMainnetV15 && opts.NetworkVersion >= network.Version15 {
if useFvmDebug {
return NewDebugFVM(ctx, &opts)
}
return NewFVM(ctx, &opts)
}

return vm.NewLegacyVM(ctx, opts)
}
2 changes: 2 additions & 0 deletions pkg/statemanger/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func (s *Stmgr) CallWithGas(ctx context.Context, msg *types.Message, priorMsgs [
Bsstore: buffStore,
SysCallsImpl: s.syscallsImpl,
Fork: s.fork,
Tracing: true,
}

vmi, err := fvm.NewVM(ctx, vmOption)
Expand Down Expand Up @@ -235,6 +236,7 @@ func (s *Stmgr) Call(ctx context.Context, msg *types.Message, ts *types.TipSet)
PRoot: ts.At(0).ParentStateRoot,
Bsstore: s.cs.Blockstore(),
SysCallsImpl: s.syscallsImpl,
Tracing: true,
}

v, err := fvm.NewVM(ctx, vmOption)
Expand Down
6 changes: 4 additions & 2 deletions pkg/vm/gas/gas_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ func (t *GasTracker) Charge(gas GasCharge, msg string, args ...interface{}) {
}
}

// EnableDetailedTracing, if true, outputs gas tracing in execution traces.
// EnableDetailedTracing has different behaviour in the LegacyVM and FVM.
// In the LegacyVM, it enables detailed gas tracing, slowing down execution.
// In the FVM, it enables execution traces, which are primarily used to observe subcalls.
var EnableDetailedTracing = os.Getenv("VENUS_VM_ENABLE_TRACING") == "1"

// TryCharge charges `amount` or `RemainingGas()``, whichever is smaller.
// TryCharge charges `amount` or `RemainingGas()`, whichever is smaller.
//
// Returns `True` if the there was enough gas To pay for `amount`.
func (t *GasTracker) TryCharge(gasCharge GasCharge) bool {
Expand Down
5 changes: 3 additions & 2 deletions pkg/vm/vmcontext/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ type VmOption struct { //nolint
PRoot cid.Cid
Bsstore blockstoreutil.Blockstore
SysCallsImpl SyscallsImpl
Tracing bool
}

//ChainRandomness define randomness method in filecoin
// ChainRandomness define randomness method in filecoin
type ILookBack interface {
StateView(ctx context.Context, ts *types.TipSet) (*state.View, error)
GetLookbackTipSetForRound(ctx context.Context, ts *types.TipSet, round abi.ChainEpoch, version network.Version) (*types.TipSet, cid.Cid, error)
Expand All @@ -56,7 +57,7 @@ func LookbackStateGetterForTipset(ctx context.Context, backer ILookBack, fork fo
}
}

//ChainRandomness define randomness method in filecoin
// ChainRandomness define randomness method in filecoin
type HeadChainRandomness interface {
ChainGetRandomnessFromBeacon(ctx context.Context, personalization acrypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) (abi.Randomness, error)
ChainGetRandomnessFromTickets(ctx context.Context, personalization acrypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) (abi.Randomness, error)
Expand Down
4 changes: 3 additions & 1 deletion tools/conformance/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func (d *Driver) ExecuteTipset(bs blockstoreutil.Blockstore, chainDs ds.Batching
PRoot: preroot,
Bsstore: bs,
SysCallsImpl: syscalls,
Tracing: true,
}
)

Expand Down Expand Up @@ -308,7 +309,8 @@ func (d *Driver) ExecuteMessage(bs blockstoreutil.Blockstore, params ExecuteMess
// messages that originate from secp256k senders, leaving all
// others untouched.
// TODO: generate a signature in the DSL so that it's encoded in
// the test vector.
//
// the test vector.
func toChainMsg(msg *types.Message) (ret types.ChainMsg) {
ret = msg
if msg.From.Protocol() == address.SECP256K1 {
Expand Down