lotus/chain/vm/vmi.go

38 lines
1.1 KiB
Go
Raw Normal View History

2021-12-17 03:38:13 +00:00
package vm
import (
"context"
"os"
2021-12-17 03:38:13 +00:00
2022-06-14 15:00:51 +00:00
"github.com/ipfs/go-cid"
2022-03-01 03:57:40 +00:00
"github.com/filecoin-project/go-state-types/network"
2022-06-14 15:00:51 +00:00
2021-12-17 03:38:13 +00:00
"github.com/filecoin-project/lotus/chain/types"
)
2022-03-15 22:46:56 +00:00
type Interface interface {
// Applies the given message onto the VM's current state, returning the result of the execution
2021-12-17 03:38:13 +00:00
ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet, error)
2022-03-15 22:46:56 +00:00
// Same as above but for system messages (the Cron invocation and block reward payments).
// Must NEVER fail.
2021-12-17 03:38:13 +00:00
ApplyImplicitMessage(ctx context.Context, msg *types.Message) (*ApplyRet, error)
2022-03-15 22:46:56 +00:00
// Flush all buffered objects into the state store provided to the VM at construction.
2021-12-17 03:38:13 +00:00
Flush(ctx context.Context) (cid.Cid, error)
}
var experimentalUseFvm = os.Getenv("LOTUS_USE_FVM_TO_SYNC_MAINNET_V15") == "1"
2022-04-14 16:38:49 +00:00
func NewVM(ctx context.Context, opts *VMOpts) (Interface, error) {
2022-03-01 03:57:40 +00:00
if opts.NetworkVersion >= network.Version16 {
return NewFVM(ctx, opts)
}
// Remove after v16 upgrade, this is only to support testing and validation of the FVM
if experimentalUseFvm && opts.NetworkVersion >= network.Version15 {
return NewFVM(ctx, opts)
}
2022-03-15 23:40:17 +00:00
return NewLegacyVM(ctx, opts)
}