From 673f558ba5dc133ff4915f04d18698310a0fce01 Mon Sep 17 00:00:00 2001 From: Aayush Date: Tue, 15 Mar 2022 18:46:56 -0400 Subject: [PATCH] Rename vm.VMI to vm.Interface --- chain/consensus/filcns/compute_state.go | 4 ++-- chain/stmgr/forks_test.go | 6 +++--- chain/stmgr/stmgr.go | 8 ++++---- chain/vm/fvm.go | 2 +- chain/vm/vm.go | 2 +- chain/vm/vmi.go | 8 ++++++-- conformance/driver.go | 2 +- 7 files changed, 18 insertions(+), 14 deletions(-) diff --git a/chain/consensus/filcns/compute_state.go b/chain/consensus/filcns/compute_state.go index addf641ed..687b0341a 100644 --- a/chain/consensus/filcns/compute_state.go +++ b/chain/consensus/filcns/compute_state.go @@ -95,7 +95,7 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, sm *stmgr.StateManager }() ctx = blockstore.WithHotView(ctx) - makeVmWithBaseStateAndEpoch := func(base cid.Cid, e abi.ChainEpoch) (vm.VMI, error) { + makeVmWithBaseStateAndEpoch := func(base cid.Cid, e abi.ChainEpoch) (vm.Interface, error) { vmopt := &vm.VMOpts{ StateBase: base, Epoch: e, @@ -122,7 +122,7 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, sm *stmgr.StateManager return sm.VMConstructor()(ctx, vmopt) } - runCron := func(vmCron vm.VMI, epoch abi.ChainEpoch) error { + runCron := func(vmCron vm.Interface, epoch abi.ChainEpoch) error { cronMsg := &types.Message{ To: cron.Address, From: builtin.SystemActorAddr, diff --git a/chain/stmgr/forks_test.go b/chain/stmgr/forks_test.go index d85aa810f..9ee808999 100644 --- a/chain/stmgr/forks_test.go +++ b/chain/stmgr/forks_test.go @@ -166,7 +166,7 @@ func TestForkHeightTriggers(t *testing.T) { inv := filcns.NewActorRegistry() inv.Register(nil, testActor{}) - sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.VMI, error) { + sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, error) { nvm, err := vm.NewLotusVM(ctx, vmopt) if err != nil { return nil, err @@ -281,7 +281,7 @@ func testForkRefuseCall(t *testing.T, nullsBefore, nullsAfter int) { inv := filcns.NewActorRegistry() inv.Register(nil, testActor{}) - sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.VMI, error) { + sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, error) { nvm, err := vm.NewLotusVM(ctx, vmopt) if err != nil { return nil, err @@ -500,7 +500,7 @@ func TestForkPreMigration(t *testing.T) { inv := filcns.NewActorRegistry() inv.Register(nil, testActor{}) - sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.VMI, error) { + sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, error) { nvm, err := vm.NewLotusVM(ctx, vmopt) if err != nil { return nil, err diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index fd58af8b2..d0bdd73e9 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -84,7 +84,7 @@ type StateManager struct { compWait map[string]chan struct{} stlk sync.Mutex genesisMsigLk sync.Mutex - newVM func(context.Context, *vm.VMOpts) (vm.VMI, error) + newVM func(context.Context, *vm.VMOpts) (vm.Interface, error) Syscalls vm.SyscallBuilder preIgnitionVesting []msig0.State postIgnitionVesting []msig0.State @@ -347,12 +347,12 @@ func (sm *StateManager) ValidateChain(ctx context.Context, ts *types.TipSet) err return nil } -func (sm *StateManager) SetVMConstructor(nvm func(context.Context, *vm.VMOpts) (vm.VMI, error)) { +func (sm *StateManager) SetVMConstructor(nvm func(context.Context, *vm.VMOpts) (vm.Interface, error)) { sm.newVM = nvm } -func (sm *StateManager) VMConstructor() func(context.Context, *vm.VMOpts) (vm.VMI, error) { - return func(ctx context.Context, opts *vm.VMOpts) (vm.VMI, error) { +func (sm *StateManager) VMConstructor() func(context.Context, *vm.VMOpts) (vm.Interface, error) { + return func(ctx context.Context, opts *vm.VMOpts) (vm.Interface, error) { return sm.newVM(ctx, opts) } } diff --git a/chain/vm/fvm.go b/chain/vm/fvm.go index c8f8a0d9e..a1359dce2 100644 --- a/chain/vm/fvm.go +++ b/chain/vm/fvm.go @@ -31,7 +31,7 @@ import ( "github.com/ipfs/go-cid" ) -var _ VMI = (*FVM)(nil) +var _ Interface = (*FVM)(nil) var _ ffi_cgo.Externs = (*FvmExtern)(nil) type FvmExtern struct { diff --git a/chain/vm/vm.go b/chain/vm/vm.go index ca9855b10..823682840 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -201,7 +201,7 @@ type ( LookbackStateGetter func(context.Context, abi.ChainEpoch) (*state.StateTree, error) ) -var _ VMI = (*VM)(nil) +var _ Interface = (*VM)(nil) type VM struct { cstate *state.StateTree diff --git a/chain/vm/vmi.go b/chain/vm/vmi.go index ee7fd046c..4cac7284d 100644 --- a/chain/vm/vmi.go +++ b/chain/vm/vmi.go @@ -8,13 +8,17 @@ import ( "github.com/ipfs/go-cid" ) -type VMI interface { +type Interface interface { + // Applies the given message onto the VM's current state, returning the result of the execution ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet, error) + // Same as above but for system messages (the Cron invocation and block reward payments). + // Must NEVER fail. ApplyImplicitMessage(ctx context.Context, msg *types.Message) (*ApplyRet, error) + // Flush all buffered objects into the state store provided to the VM at construction. Flush(ctx context.Context) (cid.Cid, error) } -func NewVM(ctx context.Context, opts *VMOpts) (VMI, error) { +func NewVM(ctx context.Context, opts *VMOpts) (Interface, error) { if os.Getenv("LOTUS_USE_FVM_EXPERIMENTAL") == "1" { return NewFVM(ctx, opts) } diff --git a/conformance/driver.go b/conformance/driver.go index 0a24f07ef..32ef8bf21 100644 --- a/conformance/driver.go +++ b/conformance/driver.go @@ -155,7 +155,7 @@ func (d *Driver) ExecuteTipset(bs blockstore.Blockstore, ds ds.Batching, params results: []*vm.ApplyRet{}, } - sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.VMI, error) { + sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, error) { vmopt.CircSupplyCalc = func(context.Context, abi.ChainEpoch, *state.StateTree) (abi.TokenAmount, error) { return big.Zero(), nil }