Refactor: VM: Remove the NetworkVersionGetter
This commit is contained in:
parent
6f6f5d79fb
commit
670bd993f3
@ -101,7 +101,7 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, sm *stmgr.StateManager
|
|||||||
Actors: NewActorRegistry(),
|
Actors: NewActorRegistry(),
|
||||||
Syscalls: sm.Syscalls,
|
Syscalls: sm.Syscalls,
|
||||||
CircSupplyCalc: sm.GetVMCirculatingSupply,
|
CircSupplyCalc: sm.GetVMCirculatingSupply,
|
||||||
NtwkVersion: sm.GetNetworkVersion,
|
NetworkVersion: sm.GetNetworkVersion(ctx, epoch),
|
||||||
BaseFee: baseFee,
|
BaseFee: baseFee,
|
||||||
LookbackState: stmgr.LookbackStateGetterForTipset(sm, ts),
|
LookbackState: stmgr.LookbackStateGetterForTipset(sm, ts),
|
||||||
}
|
}
|
||||||
|
@ -491,10 +491,8 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, sys vm.Sysca
|
|||||||
Actors: filcns.NewActorRegistry(),
|
Actors: filcns.NewActorRegistry(),
|
||||||
Syscalls: mkFakedSigSyscalls(sys),
|
Syscalls: mkFakedSigSyscalls(sys),
|
||||||
CircSupplyCalc: csc,
|
CircSupplyCalc: csc,
|
||||||
NtwkVersion: func(_ context.Context, _ abi.ChainEpoch) network.Version {
|
NetworkVersion: nv,
|
||||||
return nv
|
BaseFee: types.NewInt(0),
|
||||||
},
|
|
||||||
BaseFee: types.NewInt(0),
|
|
||||||
}
|
}
|
||||||
vm, err := vm.NewVM(ctx, &vmopt)
|
vm, err := vm.NewVM(ctx, &vmopt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -94,10 +94,8 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
|
|||||||
Actors: filcns.NewActorRegistry(),
|
Actors: filcns.NewActorRegistry(),
|
||||||
Syscalls: mkFakedSigSyscalls(sys),
|
Syscalls: mkFakedSigSyscalls(sys),
|
||||||
CircSupplyCalc: csc,
|
CircSupplyCalc: csc,
|
||||||
NtwkVersion: func(_ context.Context, _ abi.ChainEpoch) network.Version {
|
NetworkVersion: nv,
|
||||||
return nv
|
BaseFee: types.NewInt(0),
|
||||||
},
|
|
||||||
BaseFee: types.NewInt(0),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vm, err := vm.NewVM(ctx, vmopt)
|
vm, err := vm.NewVM(ctx, vmopt)
|
||||||
|
@ -80,7 +80,7 @@ func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types.
|
|||||||
Actors: sm.tsExec.NewActorRegistry(),
|
Actors: sm.tsExec.NewActorRegistry(),
|
||||||
Syscalls: sm.Syscalls,
|
Syscalls: sm.Syscalls,
|
||||||
CircSupplyCalc: sm.GetVMCirculatingSupply,
|
CircSupplyCalc: sm.GetVMCirculatingSupply,
|
||||||
NtwkVersion: sm.GetNetworkVersion,
|
NetworkVersion: sm.GetNetworkVersion(ctx, pheight+1),
|
||||||
BaseFee: types.NewInt(0),
|
BaseFee: types.NewInt(0),
|
||||||
LookbackState: LookbackStateGetterForTipset(sm, ts),
|
LookbackState: LookbackStateGetterForTipset(sm, ts),
|
||||||
}
|
}
|
||||||
@ -204,7 +204,7 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, pri
|
|||||||
Actors: sm.tsExec.NewActorRegistry(),
|
Actors: sm.tsExec.NewActorRegistry(),
|
||||||
Syscalls: sm.Syscalls,
|
Syscalls: sm.Syscalls,
|
||||||
CircSupplyCalc: sm.GetVMCirculatingSupply,
|
CircSupplyCalc: sm.GetVMCirculatingSupply,
|
||||||
NtwkVersion: sm.GetNetworkVersion,
|
NetworkVersion: sm.GetNetworkVersion(ctx, ts.Height()+1),
|
||||||
BaseFee: ts.Blocks()[0].ParentBaseFee,
|
BaseFee: ts.Blocks()[0].ParentBaseFee,
|
||||||
LookbackState: LookbackStateGetterForTipset(sm, ts),
|
LookbackState: LookbackStateGetterForTipset(sm, ts),
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,7 @@ func ComputeState(ctx context.Context, sm *StateManager, height abi.ChainEpoch,
|
|||||||
Actors: sm.tsExec.NewActorRegistry(),
|
Actors: sm.tsExec.NewActorRegistry(),
|
||||||
Syscalls: sm.Syscalls,
|
Syscalls: sm.Syscalls,
|
||||||
CircSupplyCalc: sm.GetVMCirculatingSupply,
|
CircSupplyCalc: sm.GetVMCirculatingSupply,
|
||||||
NtwkVersion: sm.GetNetworkVersion,
|
NetworkVersion: sm.GetNetworkVersion(ctx, height),
|
||||||
BaseFee: ts.Blocks()[0].ParentBaseFee,
|
BaseFee: ts.Blocks()[0].ParentBaseFee,
|
||||||
LookbackState: LookbackStateGetterForTipset(sm, ts),
|
LookbackState: LookbackStateGetterForTipset(sm, ts),
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package vm
|
package vm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
@ -136,9 +135,7 @@ func TestInvokerBasic(t *testing.T) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
_, aerr := code[1](&Runtime{
|
_, aerr := code[1](&Runtime{
|
||||||
vm: &VM{ntwkVersion: func(ctx context.Context, epoch abi.ChainEpoch) network.Version {
|
vm: &VM{networkVersion: network.Version0},
|
||||||
return network.Version0
|
|
||||||
}},
|
|
||||||
Message: &basicRtMessage{},
|
Message: &basicRtMessage{},
|
||||||
}, []byte{99})
|
}, []byte{99})
|
||||||
if aerrors.IsFatal(aerr) {
|
if aerrors.IsFatal(aerr) {
|
||||||
@ -149,9 +146,7 @@ func TestInvokerBasic(t *testing.T) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
_, aerr := code[1](&Runtime{
|
_, aerr := code[1](&Runtime{
|
||||||
vm: &VM{ntwkVersion: func(ctx context.Context, epoch abi.ChainEpoch) network.Version {
|
vm: &VM{networkVersion: network.Version7},
|
||||||
return network.Version7
|
|
||||||
}},
|
|
||||||
Message: &basicRtMessage{},
|
Message: &basicRtMessage{},
|
||||||
}, []byte{99})
|
}, []byte{99})
|
||||||
if aerrors.IsFatal(aerr) {
|
if aerrors.IsFatal(aerr) {
|
||||||
|
@ -92,7 +92,7 @@ func (rt *Runtime) BaseFee() abi.TokenAmount {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rt *Runtime) NetworkVersion() network.Version {
|
func (rt *Runtime) NetworkVersion() network.Version {
|
||||||
return rt.vm.GetNtwkVersion(rt.ctx, rt.CurrEpoch())
|
return rt.vm.networkVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rt *Runtime) TotalFilCircSupply() abi.TokenAmount {
|
func (rt *Runtime) TotalFilCircSupply() abi.TokenAmount {
|
||||||
|
@ -169,7 +169,7 @@ func (vm *VM) makeRuntime(ctx context.Context, msg *types.Message, parent *Runti
|
|||||||
}
|
}
|
||||||
vmm.From = resF
|
vmm.From = resF
|
||||||
|
|
||||||
if vm.ntwkVersion(ctx, vm.blockHeight) <= network.Version3 {
|
if vm.networkVersion <= network.Version3 {
|
||||||
rt.Message = &vmm
|
rt.Message = &vmm
|
||||||
} else {
|
} else {
|
||||||
resT, _ := rt.ResolveAddress(msg.To)
|
resT, _ := rt.ResolveAddress(msg.To)
|
||||||
@ -209,7 +209,7 @@ type VM struct {
|
|||||||
areg *ActorRegistry
|
areg *ActorRegistry
|
||||||
rand Rand
|
rand Rand
|
||||||
circSupplyCalc CircSupplyCalculator
|
circSupplyCalc CircSupplyCalculator
|
||||||
ntwkVersion NtwkVersionGetter
|
networkVersion network.Version
|
||||||
baseFee abi.TokenAmount
|
baseFee abi.TokenAmount
|
||||||
lbStateGet LookbackStateGetter
|
lbStateGet LookbackStateGetter
|
||||||
baseCircSupply abi.TokenAmount
|
baseCircSupply abi.TokenAmount
|
||||||
@ -225,7 +225,7 @@ type VMOpts struct {
|
|||||||
Actors *ActorRegistry
|
Actors *ActorRegistry
|
||||||
Syscalls SyscallBuilder
|
Syscalls SyscallBuilder
|
||||||
CircSupplyCalc CircSupplyCalculator
|
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
|
BaseFee abi.TokenAmount
|
||||||
LookbackState LookbackStateGetter
|
LookbackState LookbackStateGetter
|
||||||
}
|
}
|
||||||
@ -251,7 +251,7 @@ func NewVM(ctx context.Context, opts *VMOpts) (*VM, error) {
|
|||||||
areg: opts.Actors,
|
areg: opts.Actors,
|
||||||
rand: opts.Rand, // TODO: Probably should be a syscall
|
rand: opts.Rand, // TODO: Probably should be a syscall
|
||||||
circSupplyCalc: opts.CircSupplyCalc,
|
circSupplyCalc: opts.CircSupplyCalc,
|
||||||
ntwkVersion: opts.NtwkVersion,
|
networkVersion: opts.NetworkVersion,
|
||||||
Syscalls: opts.Syscalls,
|
Syscalls: opts.Syscalls,
|
||||||
baseFee: opts.BaseFee,
|
baseFee: opts.BaseFee,
|
||||||
baseCircSupply: baseCirc,
|
baseCircSupply: baseCirc,
|
||||||
@ -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")
|
return nil, aerrors.Wrapf(err, "could not create account")
|
||||||
}
|
}
|
||||||
toActor = a
|
toActor = a
|
||||||
if vm.ntwkVersion(ctx, vm.blockHeight) <= network.Version3 {
|
if vm.networkVersion <= network.Version3 {
|
||||||
// Leave the rt.Message as is
|
// Leave the rt.Message as is
|
||||||
} else {
|
} else {
|
||||||
nmsg := Message{
|
nmsg := Message{
|
||||||
@ -340,7 +340,7 @@ func (vm *VM) send(ctx context.Context, msg *types.Message, parent *Runtime,
|
|||||||
defer rt.chargeGasSafe(newGasCharge("OnMethodInvocationDone", 0, 0))
|
defer rt.chargeGasSafe(newGasCharge("OnMethodInvocationDone", 0, 0))
|
||||||
|
|
||||||
if types.BigCmp(msg.Value, types.NewInt(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")
|
return nil, aerrors.Wrap(err, "failed to transfer funds")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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) {
|
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
|
// 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
|
// window post. This won't catch _indirect_ window post calls, but this
|
||||||
// is the best we can get for now.
|
// is the best we can get for now.
|
||||||
@ -855,13 +855,9 @@ func (vm *VM) SetInvoker(i *ActorRegistry) {
|
|||||||
vm.areg = i
|
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) {
|
func (vm *VM) GetCircSupply(ctx context.Context) (abi.TokenAmount, error) {
|
||||||
// Before v15, this was recalculated on each invocation as the state tree was mutated
|
// 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)
|
return vm.circSupplyCalc(ctx, vm.blockHeight, vm.cstate)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ func NewBlockBuilder(ctx context.Context, logger *zap.SugaredLogger, sm *stmgr.S
|
|||||||
Actors: filcns.NewActorRegistry(),
|
Actors: filcns.NewActorRegistry(),
|
||||||
Syscalls: sm.VMSys(),
|
Syscalls: sm.VMSys(),
|
||||||
CircSupplyCalc: sm.GetVMCirculatingSupply,
|
CircSupplyCalc: sm.GetVMCirculatingSupply,
|
||||||
NtwkVersion: sm.GetNetworkVersion,
|
NetworkVersion: sm.GetNetworkVersion(ctx, parentTs.Height()+1),
|
||||||
BaseFee: abi.NewTokenAmount(0),
|
BaseFee: abi.NewTokenAmount(0),
|
||||||
LookbackState: stmgr.LookbackStateGetterForTipset(sm, parentTs),
|
LookbackState: stmgr.LookbackStateGetterForTipset(sm, parentTs),
|
||||||
}
|
}
|
||||||
|
@ -225,9 +225,9 @@ func (d *Driver) ExecuteMessage(bs blockstore.Blockstore, params ExecuteMessageP
|
|||||||
CircSupplyCalc: func(_ context.Context, _ abi.ChainEpoch, _ *state.StateTree) (abi.TokenAmount, error) {
|
CircSupplyCalc: func(_ context.Context, _ abi.ChainEpoch, _ *state.StateTree) (abi.TokenAmount, error) {
|
||||||
return params.CircSupply, nil
|
return params.CircSupply, nil
|
||||||
},
|
},
|
||||||
Rand: params.Rand,
|
Rand: params.Rand,
|
||||||
BaseFee: params.BaseFee,
|
BaseFee: params.BaseFee,
|
||||||
NtwkVersion: sm.GetNetworkVersion,
|
NetworkVersion: sm.GetNetworkVersion(context.Background(), params.Epoch),
|
||||||
}
|
}
|
||||||
|
|
||||||
lvm, err := vm.NewVM(context.TODO(), vmOpts)
|
lvm, err := vm.NewVM(context.TODO(), vmOpts)
|
||||||
|
Loading…
Reference in New Issue
Block a user