Skip to content

Commit

Permalink
Rename the Lotus VM to LegacyVM
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Mar 15, 2022
1 parent e6117c4 commit 9ea623e
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 54 deletions.
2 changes: 1 addition & 1 deletion chain/consensus/filcns/compute_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, sm *stmgr.StateManager
if os.Getenv("LOTUS_USE_FVM_EXPERIMENTAL") == "1" {
// This is needed so that the FVM does not have to duplicate the genesis vesting schedule, one
// of the components of the circ supply calc.
// This field is NOT needed by the Lotus VM, and also NOT needed by the FVM from v15 onwards.
// This field is NOT needed by the LegacyVM, and also NOT needed by the FVM from v15 onwards.
filVested, err := sm.GetFilVested(ctx, e)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions chain/gen/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,9 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, sys vm.Sysca
NetworkVersion: nv,
BaseFee: big.Zero(),
}
vm, err := vm.NewLotusVM(ctx, &vmopt)
vm, err := vm.NewLegacyVM(ctx, &vmopt)
if err != nil {
return cid.Undef, xerrors.Errorf("failed to create NewLotusVM: %w", err)
return cid.Undef, xerrors.Errorf("failed to create NewLegacyVM: %w", err)
}

for mi, m := range template.Miners {
Expand Down
12 changes: 6 additions & 6 deletions chain/gen/genesis/miners.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
FilVested: big.Zero(),
}

vm, err := vm.NewLotusVM(ctx, vmopt)
vm, err := vm.NewLegacyVM(ctx, vmopt)
if err != nil {
return cid.Undef, xerrors.Errorf("failed to create NewLotusVM: %w", err)
return cid.Undef, xerrors.Errorf("failed to create NewLegacyVM: %w", err)
}

if len(miners) == 0 {
Expand Down Expand Up @@ -521,7 +521,7 @@ func (fr *fakeRand) GetBeaconRandomness(ctx context.Context, personalization cry
return out, nil
}

func currentTotalPower(ctx context.Context, vm *vm.VM, maddr address.Address) (*power0.CurrentTotalPowerReturn, error) {
func currentTotalPower(ctx context.Context, vm *vm.LegacyVM, maddr address.Address) (*power0.CurrentTotalPowerReturn, error) {
pwret, err := doExecValue(ctx, vm, power.Address, maddr, big.Zero(), builtin0.MethodsPower.CurrentTotalPower, nil)
if err != nil {
return nil, err
Expand All @@ -534,7 +534,7 @@ func currentTotalPower(ctx context.Context, vm *vm.VM, maddr address.Address) (*
return &pwr, nil
}

func dealWeight(ctx context.Context, vm *vm.VM, maddr address.Address, dealIDs []abi.DealID, sectorStart, sectorExpiry abi.ChainEpoch, av actors.Version) (abi.DealWeight, abi.DealWeight, error) {
func dealWeight(ctx context.Context, vm *vm.LegacyVM, maddr address.Address, dealIDs []abi.DealID, sectorStart, sectorExpiry abi.ChainEpoch, av actors.Version) (abi.DealWeight, abi.DealWeight, error) {
// TODO: This hack should move to market actor wrapper
if av <= actors.Version2 {
params := &market0.VerifyDealsForActivationParams{
Expand Down Expand Up @@ -594,7 +594,7 @@ func dealWeight(ctx context.Context, vm *vm.VM, maddr address.Address, dealIDs [
return dealWeights.Sectors[0].DealWeight, dealWeights.Sectors[0].VerifiedDealWeight, nil
}

func currentEpochBlockReward(ctx context.Context, vm *vm.VM, maddr address.Address, av actors.Version) (abi.StoragePower, builtin.FilterEstimate, error) {
func currentEpochBlockReward(ctx context.Context, vm *vm.LegacyVM, maddr address.Address, av actors.Version) (abi.StoragePower, builtin.FilterEstimate, error) {
rwret, err := doExecValue(ctx, vm, reward.Address, maddr, big.Zero(), reward.Methods.ThisEpochReward, nil)
if err != nil {
return big.Zero(), builtin.FilterEstimate{}, err
Expand Down Expand Up @@ -629,7 +629,7 @@ func currentEpochBlockReward(ctx context.Context, vm *vm.VM, maddr address.Addre
return epochReward.ThisEpochBaselinePower, builtin.FilterEstimate(epochReward.ThisEpochRewardSmoothed), nil
}

func circSupply(ctx context.Context, vmi *vm.VM, maddr address.Address) abi.TokenAmount {
func circSupply(ctx context.Context, vmi *vm.LegacyVM, maddr address.Address) abi.TokenAmount {
unsafeVM := &vm.UnsafeVM{VM: vmi}
rt := unsafeVM.MakeRuntime(ctx, &types.Message{
GasLimit: 1_000_000_000,
Expand Down
2 changes: 1 addition & 1 deletion chain/gen/genesis/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func mustEnc(i cbg.CBORMarshaler) []byte {
return enc
}

func doExecValue(ctx context.Context, vm *vm.VM, to, from address.Address, value types.BigInt, method abi.MethodNum, params []byte) ([]byte, error) {
func doExecValue(ctx context.Context, vm *vm.LegacyVM, to, from address.Address, value types.BigInt, method abi.MethodNum, params []byte) ([]byte, error) {
act, err := vm.StateTree().GetActor(from)
if err != nil {
return nil, xerrors.Errorf("doExec failed to get from actor (%s): %w", from, err)
Expand Down
6 changes: 3 additions & 3 deletions chain/stmgr/forks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func TestForkHeightTriggers(t *testing.T) {
inv.Register(nil, testActor{})

sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, error) {
nvm, err := vm.NewLotusVM(ctx, vmopt)
nvm, err := vm.NewLegacyVM(ctx, vmopt)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -282,7 +282,7 @@ func testForkRefuseCall(t *testing.T, nullsBefore, nullsAfter int) {
inv.Register(nil, testActor{})

sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, error) {
nvm, err := vm.NewLotusVM(ctx, vmopt)
nvm, err := vm.NewLegacyVM(ctx, vmopt)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -501,7 +501,7 @@ func TestForkPreMigration(t *testing.T) {
inv.Register(nil, testActor{})

sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, error) {
nvm, err := vm.NewLotusVM(ctx, vmopt)
nvm, err := vm.NewLegacyVM(ctx, vmopt)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion chain/vm/fvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type FvmExtern struct {
base cid.Cid
}

// VerifyConsensusFault is similar to the one in syscalls.go used by the Lotus VM, except it never errors
// VerifyConsensusFault is similar to the one in syscalls.go used by the LegacyVM, except it never errors
// Errors are logged and "no fault" is returned, which is functionally what go-actors does anyway
func (x *FvmExtern) VerifyConsensusFault(ctx context.Context, a, b, extra []byte) (*ffi_cgo.ConsensusFault, int64) {
totalGas := int64(0)
Expand Down
2 changes: 1 addition & 1 deletion chain/vm/gas.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func newGasCharge(name string, computeGas int64, storageGas int64) GasCharge {
}
}

// Pricelist provides prices for operations in the VM.
// Pricelist provides prices for operations in the LegacyVM.
//
// Note: this interface should be APPEND ONLY since last chain checkpoint
type Pricelist interface {
Expand Down
6 changes: 3 additions & 3 deletions chain/vm/gas_v0.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type pricelistV0 struct {
// whether it succeeds or fails in application) is given by:
// OnChainMessageBase + len(serialized message)*OnChainMessagePerByte
// Together, these account for the cost of message propagation and validation,
// up to but excluding any actual processing by the VM.
// up to but excluding any actual processing by the LegacyVM.
// This is the cost a block producer burns when including an invalid message.
onChainMessageComputeBase int64
onChainMessageStorageBase int64
Expand Down Expand Up @@ -83,11 +83,11 @@ type pricelistV0 struct {
sendInvokeMethod int64

// Gas cost for any Get operation to the IPLD store
// in the runtime VM context.
// in the runtime LegacyVM context.
ipldGetBase int64

// Gas cost (Base + len*PerByte) for any Put operation to the IPLD store
// in the runtime VM context.
// in the runtime LegacyVM context.
//
// Note: these costs should be significantly higher than the costs for Get
// operations, since they reflect not only serialization/deserialization
Expand Down
4 changes: 2 additions & 2 deletions chain/vm/invoker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func TestInvokerBasic(t *testing.T) {

{
_, aerr := code[1](&Runtime{
vm: &VM{networkVersion: network.Version0},
vm: &LegacyVM{networkVersion: network.Version0},
Message: &basicRtMessage{},
}, []byte{99})
if aerrors.IsFatal(aerr) {
Expand All @@ -146,7 +146,7 @@ func TestInvokerBasic(t *testing.T) {

{
_, aerr := code[1](&Runtime{
vm: &VM{networkVersion: network.Version7},
vm: &LegacyVM{networkVersion: network.Version7},
Message: &basicRtMessage{},
}, []byte{99})
if aerrors.IsFatal(aerr) {
Expand Down
4 changes: 2 additions & 2 deletions chain/vm/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type Runtime struct {

ctx context.Context

vm *VM
vm *LegacyVM
state *state.StateTree
height abi.ChainEpoch
cst ipldcbor.IpldStore
Expand Down Expand Up @@ -158,7 +158,7 @@ func (rt *Runtime) shimCall(f func() interface{}) (rval []byte, aerr aerrors.Act
defer func() {
if r := recover(); r != nil {
if ar, ok := r.(aerrors.ActorError); ok {
log.Warnf("VM.Call failure in call from: %s to %s: %+v", rt.Caller(), rt.Receiver(), ar)
log.Warnf("LegacyVM.Call failure in call from: %s to %s: %+v", rt.Caller(), rt.Receiver(), ar)
aerr = ar
return
}
Expand Down
44 changes: 22 additions & 22 deletions chain/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (bs *gasChargingBlocks) Put(ctx context.Context, blk block.Block) error {
return nil
}

func (vm *VM) makeRuntime(ctx context.Context, msg *types.Message, parent *Runtime) *Runtime {
func (vm *LegacyVM) makeRuntime(ctx context.Context, msg *types.Message, parent *Runtime) *Runtime {
rt := &Runtime{
ctx: ctx,
vm: vm,
Expand Down Expand Up @@ -188,7 +188,7 @@ func (vm *VM) makeRuntime(ctx context.Context, msg *types.Message, parent *Runti
}

type UnsafeVM struct {
VM *VM
VM *LegacyVM
}

func (vm *UnsafeVM) MakeRuntime(ctx context.Context, msg *types.Message) *Runtime {
Expand All @@ -201,9 +201,9 @@ type (
LookbackStateGetter func(context.Context, abi.ChainEpoch) (*state.StateTree, error)
)

var _ Interface = (*VM)(nil)
var _ Interface = (*LegacyVM)(nil)

type VM struct {
type LegacyVM struct {
cstate *state.StateTree
cst *cbor.BasicIpldStore
buf *blockstore.BufferedBlockstore
Expand Down Expand Up @@ -234,7 +234,7 @@ type VMOpts struct {
LookbackState LookbackStateGetter
}

func NewLotusVM(ctx context.Context, opts *VMOpts) (*VM, error) {
func NewLegacyVM(ctx context.Context, opts *VMOpts) (*LegacyVM, error) {
buf := blockstore.NewBuffered(opts.Bstore)
cst := cbor.NewCborStore(buf)
state, err := state.LoadStateTree(cst, opts.StateBase)
Expand All @@ -247,7 +247,7 @@ func NewLotusVM(ctx context.Context, opts *VMOpts) (*VM, error) {
return nil, err
}

return &VM{
return &LegacyVM{
cstate: state,
cst: cst,
buf: buf,
Expand Down Expand Up @@ -276,7 +276,7 @@ type ApplyRet struct {
GasCosts *GasOutputs
}

func (vm *VM) send(ctx context.Context, msg *types.Message, parent *Runtime,
func (vm *LegacyVM) send(ctx context.Context, msg *types.Message, parent *Runtime,
gasCharge *GasCharge, start time.Time) ([]byte, aerrors.ActorError, *Runtime) {
defer atomic.AddUint64(&StatSends, 1)

Expand Down Expand Up @@ -395,7 +395,7 @@ func checkMessage(msg *types.Message) error {
return nil
}

func (vm *VM) ApplyImplicitMessage(ctx context.Context, msg *types.Message) (*ApplyRet, error) {
func (vm *LegacyVM) ApplyImplicitMessage(ctx context.Context, msg *types.Message) (*ApplyRet, error) {
start := build.Clock.Now()
defer atomic.AddUint64(&StatApplied, 1)
ret, actorErr, rt := vm.send(ctx, msg, nil, nil, start)
Expand All @@ -413,7 +413,7 @@ func (vm *VM) ApplyImplicitMessage(ctx context.Context, msg *types.Message) (*Ap
}, actorErr
}

func (vm *VM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet, error) {
func (vm *LegacyVM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet, error) {
start := build.Clock.Now()
ctx, span := trace.StartSpan(ctx, "vm.ApplyMessage")
defer span.End()
Expand Down Expand Up @@ -620,7 +620,7 @@ func (vm *VM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet,
}, nil
}

func (vm *VM) ShouldBurn(ctx context.Context, st *state.StateTree, msg *types.Message, errcode exitcode.ExitCode) (bool, error) {
func (vm *LegacyVM) ShouldBurn(ctx context.Context, st *state.StateTree, msg *types.Message, errcode exitcode.ExitCode) (bool, error) {
if vm.networkVersion <= network.Version12 {
// Check to see if we should burn funds. We avoid burning on successful
// window post. This won't catch _indirect_ window post calls, but this
Expand Down Expand Up @@ -650,7 +650,7 @@ func (vm *VM) ShouldBurn(ctx context.Context, st *state.StateTree, msg *types.Me

type vmFlushKey struct{}

func (vm *VM) Flush(ctx context.Context) (cid.Cid, error) {
func (vm *LegacyVM) Flush(ctx context.Context) (cid.Cid, error) {
_, span := trace.StartSpan(ctx, "vm.Flush")
defer span.End()

Expand All @@ -669,9 +669,9 @@ func (vm *VM) Flush(ctx context.Context) (cid.Cid, error) {
return root, nil
}

// Get the buffered blockstore associated with the VM. This includes any temporary blocks produced
// during this VM's execution.
func (vm *VM) ActorStore(ctx context.Context) adt.Store {
// Get the buffered blockstore associated with the LegacyVM. This includes any temporary blocks produced
// during this LegacyVM's execution.
func (vm *LegacyVM) ActorStore(ctx context.Context) adt.Store {
return adt.WrapStore(ctx, vm.cst)
}

Expand Down Expand Up @@ -824,11 +824,11 @@ func copyRec(ctx context.Context, from, to blockstore.Blockstore, root cid.Cid,
return nil
}

func (vm *VM) StateTree() types.StateTree {
func (vm *LegacyVM) StateTree() types.StateTree {
return vm.cstate
}

func (vm *VM) Invoke(act *types.Actor, rt *Runtime, method abi.MethodNum, params []byte) ([]byte, aerrors.ActorError) {
func (vm *LegacyVM) Invoke(act *types.Actor, rt *Runtime, method abi.MethodNum, params []byte) ([]byte, aerrors.ActorError) {
ctx, span := trace.StartSpan(rt.ctx, "vm.Invoke")
defer span.End()
if span.IsRecordingEvents() {
Expand All @@ -851,11 +851,11 @@ func (vm *VM) Invoke(act *types.Actor, rt *Runtime, method abi.MethodNum, params
return ret, nil
}

func (vm *VM) SetInvoker(i *ActorRegistry) {
func (vm *LegacyVM) SetInvoker(i *ActorRegistry) {
vm.areg = i
}

func (vm *VM) GetCircSupply(ctx context.Context) (abi.TokenAmount, error) {
func (vm *LegacyVM) GetCircSupply(ctx context.Context) (abi.TokenAmount, error) {
// Before v15, this was recalculated on each invocation as the state tree was mutated
if vm.networkVersion <= network.Version14 {
return vm.circSupplyCalc(ctx, vm.blockHeight, vm.cstate)
Expand All @@ -864,14 +864,14 @@ func (vm *VM) GetCircSupply(ctx context.Context) (abi.TokenAmount, error) {
return vm.baseCircSupply, nil
}

func (vm *VM) incrementNonce(addr address.Address) error {
func (vm *LegacyVM) incrementNonce(addr address.Address) error {
return vm.cstate.MutateActor(addr, func(a *types.Actor) error {
a.Nonce++
return nil
})
}

func (vm *VM) transfer(from, to address.Address, amt types.BigInt, networkVersion network.Version) aerrors.ActorError {
func (vm *LegacyVM) transfer(from, to address.Address, amt types.BigInt, networkVersion network.Version) aerrors.ActorError {
var f *types.Actor
var fromID, toID address.Address
var err error
Expand Down Expand Up @@ -959,7 +959,7 @@ func (vm *VM) transfer(from, to address.Address, amt types.BigInt, networkVersio
return nil
}

func (vm *VM) transferToGasHolder(addr address.Address, gasHolder *types.Actor, amt types.BigInt) error {
func (vm *LegacyVM) transferToGasHolder(addr address.Address, gasHolder *types.Actor, amt types.BigInt) error {
if amt.LessThan(types.NewInt(0)) {
return xerrors.Errorf("attempted to transfer negative value to gas holder")
}
Expand All @@ -973,7 +973,7 @@ func (vm *VM) transferToGasHolder(addr address.Address, gasHolder *types.Actor,
})
}

func (vm *VM) transferFromGasHolder(addr address.Address, gasHolder *types.Actor, amt types.BigInt) error {
func (vm *LegacyVM) transferFromGasHolder(addr address.Address, gasHolder *types.Actor, amt types.BigInt) error {
if amt.LessThan(types.NewInt(0)) {
return xerrors.Errorf("attempted to transfer negative value from gas holder")
}
Expand Down
2 changes: 1 addition & 1 deletion chain/vm/vmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ func NewVM(ctx context.Context, opts *VMOpts) (Interface, error) {
return NewFVM(ctx, opts)
}

return NewLotusVM(ctx, opts)
return NewLegacyVM(ctx, opts)
}
Loading

0 comments on commit 9ea623e

Please sign in to comment.