Skip to content

Commit

Permalink
Refactor: VM: Remove the NetworkVersionGetter
Browse files Browse the repository at this point in the history
  • Loading branch information
arajasek committed Dec 18, 2021
1 parent 6f6f5d7 commit 670bd99
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 36 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 @@ -101,7 +101,7 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, sm *stmgr.StateManager
Actors: NewActorRegistry(),
Syscalls: sm.Syscalls,
CircSupplyCalc: sm.GetVMCirculatingSupply,
NtwkVersion: sm.GetNetworkVersion,
NetworkVersion: sm.GetNetworkVersion(ctx, epoch),
BaseFee: baseFee,
LookbackState: stmgr.LookbackStateGetterForTipset(sm, ts),
}
Expand Down
6 changes: 2 additions & 4 deletions chain/gen/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,8 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, sys vm.Sysca
Actors: filcns.NewActorRegistry(),
Syscalls: mkFakedSigSyscalls(sys),
CircSupplyCalc: csc,
NtwkVersion: func(_ context.Context, _ abi.ChainEpoch) network.Version {
return nv
},
BaseFee: types.NewInt(0),
NetworkVersion: nv,
BaseFee: types.NewInt(0),
}
vm, err := vm.NewVM(ctx, &vmopt)
if err != nil {
Expand Down
6 changes: 2 additions & 4 deletions chain/gen/genesis/miners.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,8 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
Actors: filcns.NewActorRegistry(),
Syscalls: mkFakedSigSyscalls(sys),
CircSupplyCalc: csc,
NtwkVersion: func(_ context.Context, _ abi.ChainEpoch) network.Version {
return nv
},
BaseFee: types.NewInt(0),
NetworkVersion: nv,
BaseFee: types.NewInt(0),
}

vm, err := vm.NewVM(ctx, vmopt)
Expand Down
4 changes: 2 additions & 2 deletions chain/stmgr/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types.
Actors: sm.tsExec.NewActorRegistry(),
Syscalls: sm.Syscalls,
CircSupplyCalc: sm.GetVMCirculatingSupply,
NtwkVersion: sm.GetNetworkVersion,
NetworkVersion: sm.GetNetworkVersion(ctx, pheight+1),
BaseFee: types.NewInt(0),
LookbackState: LookbackStateGetterForTipset(sm, ts),
}
Expand Down Expand Up @@ -204,7 +204,7 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, pri
Actors: sm.tsExec.NewActorRegistry(),
Syscalls: sm.Syscalls,
CircSupplyCalc: sm.GetVMCirculatingSupply,
NtwkVersion: sm.GetNetworkVersion,
NetworkVersion: sm.GetNetworkVersion(ctx, ts.Height()+1),
BaseFee: ts.Blocks()[0].ParentBaseFee,
LookbackState: LookbackStateGetterForTipset(sm, ts),
}
Expand Down
2 changes: 1 addition & 1 deletion chain/stmgr/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func ComputeState(ctx context.Context, sm *StateManager, height abi.ChainEpoch,
Actors: sm.tsExec.NewActorRegistry(),
Syscalls: sm.Syscalls,
CircSupplyCalc: sm.GetVMCirculatingSupply,
NtwkVersion: sm.GetNetworkVersion,
NetworkVersion: sm.GetNetworkVersion(ctx, height),
BaseFee: ts.Blocks()[0].ParentBaseFee,
LookbackState: LookbackStateGetterForTipset(sm, ts),
}
Expand Down
9 changes: 2 additions & 7 deletions chain/vm/invoker_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package vm

import (
"context"
"fmt"
"io"
"testing"
Expand Down Expand Up @@ -136,9 +135,7 @@ func TestInvokerBasic(t *testing.T) {

{
_, aerr := code[1](&Runtime{
vm: &VM{ntwkVersion: func(ctx context.Context, epoch abi.ChainEpoch) network.Version {
return network.Version0
}},
vm: &VM{networkVersion: network.Version0},
Message: &basicRtMessage{},
}, []byte{99})
if aerrors.IsFatal(aerr) {
Expand All @@ -149,9 +146,7 @@ func TestInvokerBasic(t *testing.T) {

{
_, aerr := code[1](&Runtime{
vm: &VM{ntwkVersion: func(ctx context.Context, epoch abi.ChainEpoch) network.Version {
return network.Version7
}},
vm: &VM{networkVersion: network.Version7},
Message: &basicRtMessage{},
}, []byte{99})
if aerrors.IsFatal(aerr) {
Expand Down
2 changes: 1 addition & 1 deletion chain/vm/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (rt *Runtime) BaseFee() abi.TokenAmount {
}

func (rt *Runtime) NetworkVersion() network.Version {
return rt.vm.GetNtwkVersion(rt.ctx, rt.CurrEpoch())
return rt.vm.networkVersion
}

func (rt *Runtime) TotalFilCircSupply() abi.TokenAmount {
Expand Down
20 changes: 8 additions & 12 deletions chain/vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (vm *VM) makeRuntime(ctx context.Context, msg *types.Message, parent *Runti
}
vmm.From = resF

if vm.ntwkVersion(ctx, vm.blockHeight) <= network.Version3 {
if vm.networkVersion <= network.Version3 {
rt.Message = &vmm
} else {
resT, _ := rt.ResolveAddress(msg.To)
Expand Down Expand Up @@ -209,7 +209,7 @@ type VM struct {
areg *ActorRegistry
rand Rand
circSupplyCalc CircSupplyCalculator
ntwkVersion NtwkVersionGetter
networkVersion network.Version
baseFee abi.TokenAmount
lbStateGet LookbackStateGetter
baseCircSupply abi.TokenAmount
Expand All @@ -225,7 +225,7 @@ type VMOpts struct {
Actors *ActorRegistry
Syscalls SyscallBuilder
CircSupplyCalc CircSupplyCalculator
NtwkVersion NtwkVersionGetter // TODO: stebalien: In what cases do we actually need this? It seems like even when creating new networks we want to use the 'global'/build-default version getter
NetworkVersion network.Version
BaseFee abi.TokenAmount
LookbackState LookbackStateGetter
}
Expand All @@ -251,7 +251,7 @@ func NewVM(ctx context.Context, opts *VMOpts) (*VM, error) {
areg: opts.Actors,
rand: opts.Rand, // TODO: Probably should be a syscall
circSupplyCalc: opts.CircSupplyCalc,
ntwkVersion: opts.NtwkVersion,
networkVersion: opts.NetworkVersion,
Syscalls: opts.Syscalls,
baseFee: opts.BaseFee,
baseCircSupply: baseCirc,
Expand Down Expand Up @@ -313,7 +313,7 @@ func (vm *VM) send(ctx context.Context, msg *types.Message, parent *Runtime,
return nil, aerrors.Wrapf(err, "could not create account")
}
toActor = a
if vm.ntwkVersion(ctx, vm.blockHeight) <= network.Version3 {
if vm.networkVersion <= network.Version3 {
// Leave the rt.Message as is
} else {
nmsg := Message{
Expand All @@ -340,7 +340,7 @@ func (vm *VM) send(ctx context.Context, msg *types.Message, parent *Runtime,
defer rt.chargeGasSafe(newGasCharge("OnMethodInvocationDone", 0, 0))

if types.BigCmp(msg.Value, types.NewInt(0)) != 0 {
if err := vm.transfer(msg.From, msg.To, msg.Value, vm.ntwkVersion(ctx, vm.blockHeight)); err != nil {
if err := vm.transfer(msg.From, msg.To, msg.Value, vm.networkVersion); err != nil {
return nil, aerrors.Wrap(err, "failed to transfer funds")
}
}
Expand Down Expand Up @@ -617,7 +617,7 @@ func (vm *VM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet,
}

func (vm *VM) ShouldBurn(ctx context.Context, st *state.StateTree, msg *types.Message, errcode exitcode.ExitCode) (bool, error) {
if vm.ntwkVersion(ctx, vm.blockHeight) <= network.Version12 {
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
// is the best we can get for now.
Expand Down Expand Up @@ -855,13 +855,9 @@ func (vm *VM) SetInvoker(i *ActorRegistry) {
vm.areg = i
}

func (vm *VM) GetNtwkVersion(ctx context.Context, ce abi.ChainEpoch) network.Version {
return vm.ntwkVersion(ctx, ce)
}

func (vm *VM) GetCircSupply(ctx context.Context) (abi.TokenAmount, error) {
// Before v15, this was recalculated on each invocation as the state tree was mutated
if vm.GetNtwkVersion(ctx, vm.blockHeight) <= network.Version14 {
if vm.networkVersion <= network.Version14 {
return vm.circSupplyCalc(ctx, vm.blockHeight, vm.cstate)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/lotus-sim/simulation/blockbuilder/blockbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func NewBlockBuilder(ctx context.Context, logger *zap.SugaredLogger, sm *stmgr.S
Actors: filcns.NewActorRegistry(),
Syscalls: sm.VMSys(),
CircSupplyCalc: sm.GetVMCirculatingSupply,
NtwkVersion: sm.GetNetworkVersion,
NetworkVersion: sm.GetNetworkVersion(ctx, parentTs.Height()+1),
BaseFee: abi.NewTokenAmount(0),
LookbackState: stmgr.LookbackStateGetterForTipset(sm, parentTs),
}
Expand Down
6 changes: 3 additions & 3 deletions conformance/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ func (d *Driver) ExecuteMessage(bs blockstore.Blockstore, params ExecuteMessageP
CircSupplyCalc: func(_ context.Context, _ abi.ChainEpoch, _ *state.StateTree) (abi.TokenAmount, error) {
return params.CircSupply, nil
},
Rand: params.Rand,
BaseFee: params.BaseFee,
NtwkVersion: sm.GetNetworkVersion,
Rand: params.Rand,
BaseFee: params.BaseFee,
NetworkVersion: sm.GetNetworkVersion(context.Background(), params.Epoch),
}

lvm, err := vm.NewVM(context.TODO(), vmOpts)
Expand Down

0 comments on commit 670bd99

Please sign in to comment.