update VM interface references to use the executor, and call Done where appropriate
This commit is contained in:
parent
a1ce2d7fe4
commit
f6057e6f84
@ -93,7 +93,7 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context,
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
ctx = blockstore.WithHotView(ctx)
|
ctx = blockstore.WithHotView(ctx)
|
||||||
makeVm := func(base cid.Cid, e abi.ChainEpoch, timestamp uint64) (vm.Interface, error) {
|
makeVm := func(base cid.Cid, e abi.ChainEpoch, timestamp uint64) (vm.Executor, error) {
|
||||||
vmopt := &vm.VMOpts{
|
vmopt := &vm.VMOpts{
|
||||||
StateBase: base,
|
StateBase: base,
|
||||||
Epoch: e,
|
Epoch: e,
|
||||||
@ -109,6 +109,7 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context,
|
|||||||
TipSetGetter: stmgr.TipSetGetterForTipset(sm.ChainStore(), ts),
|
TipSetGetter: stmgr.TipSetGetterForTipset(sm.ChainStore(), ts),
|
||||||
Tracing: vmTracing,
|
Tracing: vmTracing,
|
||||||
ReturnEvents: sm.ChainStore().IsStoringEvents(),
|
ReturnEvents: sm.ChainStore().IsStoringEvents(),
|
||||||
|
ExecutionLane: vm.ExecutionLanePriority,
|
||||||
}
|
}
|
||||||
|
|
||||||
return sm.VMConstructor()(ctx, vmopt)
|
return sm.VMConstructor()(ctx, vmopt)
|
||||||
@ -116,7 +117,7 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context,
|
|||||||
|
|
||||||
var cronGas int64
|
var cronGas int64
|
||||||
|
|
||||||
runCron := func(vmCron vm.Interface, epoch abi.ChainEpoch) error {
|
runCron := func(vmCron vm.Executor, epoch abi.ChainEpoch) error {
|
||||||
cronMsg := &types.Message{
|
cronMsg := &types.Message{
|
||||||
To: cron.Address,
|
To: cron.Address,
|
||||||
From: builtin.SystemActorAddr,
|
From: builtin.SystemActorAddr,
|
||||||
@ -169,13 +170,17 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context,
|
|||||||
|
|
||||||
// run cron for null rounds if any
|
// run cron for null rounds if any
|
||||||
if err = runCron(vmCron, i); err != nil {
|
if err = runCron(vmCron, i); err != nil {
|
||||||
|
vmCron.Done()
|
||||||
return cid.Undef, cid.Undef, xerrors.Errorf("running cron: %w", err)
|
return cid.Undef, cid.Undef, xerrors.Errorf("running cron: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
pstate, err = vmCron.Flush(ctx)
|
pstate, err = vmCron.Flush(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
vmCron.Done()
|
||||||
return cid.Undef, cid.Undef, xerrors.Errorf("flushing cron vm: %w", err)
|
return cid.Undef, cid.Undef, xerrors.Errorf("flushing cron vm: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vmCron.Done()
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle state forks
|
// handle state forks
|
||||||
@ -195,6 +200,7 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, cid.Undef, xerrors.Errorf("making vm: %w", err)
|
return cid.Undef, cid.Undef, xerrors.Errorf("making vm: %w", err)
|
||||||
}
|
}
|
||||||
|
defer vmi.Done()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
receipts []*types.MessageReceipt
|
receipts []*types.MessageReceipt
|
||||||
|
@ -496,6 +496,7 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, sys vm.Sysca
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, xerrors.Errorf("failed to create VM: %w", err)
|
return cid.Undef, xerrors.Errorf("failed to create VM: %w", err)
|
||||||
}
|
}
|
||||||
|
defer vm.Done()
|
||||||
|
|
||||||
for mi, m := range template.Miners {
|
for mi, m := range template.Miners {
|
||||||
for si, s := range m.Sectors {
|
for si, s := range m.Sectors {
|
||||||
|
@ -88,7 +88,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
|
|||||||
return big.Zero(), nil
|
return big.Zero(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
newVM := func(base cid.Cid) (vm.Interface, error) {
|
newVM := func(base cid.Cid) (vm.Executor, error) {
|
||||||
vmopt := &vm.VMOpts{
|
vmopt := &vm.VMOpts{
|
||||||
StateBase: base,
|
StateBase: base,
|
||||||
Epoch: 0,
|
Epoch: 0,
|
||||||
@ -108,6 +108,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, fmt.Errorf("creating vm: %w", err)
|
return cid.Undef, fmt.Errorf("creating vm: %w", err)
|
||||||
}
|
}
|
||||||
|
defer genesisVm.Done()
|
||||||
|
|
||||||
if len(miners) == 0 {
|
if len(miners) == 0 {
|
||||||
return cid.Undef, xerrors.New("no genesis miners")
|
return cid.Undef, xerrors.New("no genesis miners")
|
||||||
@ -338,6 +339,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
|
|||||||
return cid.Undef, xerrors.Errorf("flushing state tree: %w", err)
|
return cid.Undef, xerrors.Errorf("flushing state tree: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
genesisVm.Done()
|
||||||
genesisVm, err = newVM(nh)
|
genesisVm, err = newVM(nh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, fmt.Errorf("creating new vm: %w", err)
|
return cid.Undef, fmt.Errorf("creating new vm: %w", err)
|
||||||
@ -410,6 +412,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
|
|||||||
return cid.Undef, xerrors.Errorf("flushing state tree: %w", err)
|
return cid.Undef, xerrors.Errorf("flushing state tree: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
genesisVm.Done()
|
||||||
genesisVm, err = newVM(nh)
|
genesisVm, err = newVM(nh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, fmt.Errorf("creating new vm: %w", err)
|
return cid.Undef, fmt.Errorf("creating new vm: %w", err)
|
||||||
@ -517,6 +520,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal
|
|||||||
return cid.Undef, xerrors.Errorf("flushing state tree: %w", err)
|
return cid.Undef, xerrors.Errorf("flushing state tree: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
genesisVm.Done()
|
||||||
genesisVm, err = newVM(nh)
|
genesisVm, err = newVM(nh)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cid.Undef, fmt.Errorf("creating new vm: %w", err)
|
return cid.Undef, fmt.Errorf("creating new vm: %w", err)
|
||||||
|
@ -56,6 +56,12 @@ const testForkHeight = 40
|
|||||||
type testActor struct {
|
type testActor struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type mockExecutor struct {
|
||||||
|
vm.Interface
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*mockExecutor) Done() {}
|
||||||
|
|
||||||
// must use existing actor that an account is allowed to exec.
|
// must use existing actor that an account is allowed to exec.
|
||||||
func (testActor) Code() cid.Cid { return builtin0.PaymentChannelActorCodeID }
|
func (testActor) Code() cid.Cid { return builtin0.PaymentChannelActorCodeID }
|
||||||
func (testActor) State() cbor.Er { return new(testActorState) }
|
func (testActor) State() cbor.Er { return new(testActorState) }
|
||||||
@ -178,13 +184,13 @@ func TestForkHeightTriggers(t *testing.T) {
|
|||||||
registry := builtin.MakeRegistryLegacy([]rtt.VMActor{testActor{}})
|
registry := builtin.MakeRegistryLegacy([]rtt.VMActor{testActor{}})
|
||||||
inv.Register(actorstypes.Version0, nil, registry)
|
inv.Register(actorstypes.Version0, nil, registry)
|
||||||
|
|
||||||
sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, error) {
|
sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Executor, error) {
|
||||||
nvm, err := vm.NewLegacyVM(ctx, vmopt)
|
nvm, err := vm.NewLegacyVM(ctx, vmopt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
nvm.SetInvoker(inv)
|
nvm.SetInvoker(inv)
|
||||||
return nvm, nil
|
return &mockExecutor{nvm}, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
cg.SetStateManager(sm)
|
cg.SetStateManager(sm)
|
||||||
@ -296,13 +302,13 @@ func testForkRefuseCall(t *testing.T, nullsBefore, nullsAfter int) {
|
|||||||
registry := builtin.MakeRegistryLegacy([]rtt.VMActor{testActor{}})
|
registry := builtin.MakeRegistryLegacy([]rtt.VMActor{testActor{}})
|
||||||
inv.Register(actorstypes.Version0, nil, registry)
|
inv.Register(actorstypes.Version0, nil, registry)
|
||||||
|
|
||||||
sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, error) {
|
sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Executor, error) {
|
||||||
nvm, err := vm.NewLegacyVM(ctx, vmopt)
|
nvm, err := vm.NewLegacyVM(ctx, vmopt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
nvm.SetInvoker(inv)
|
nvm.SetInvoker(inv)
|
||||||
return nvm, nil
|
return &mockExecutor{nvm}, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
cg.SetStateManager(sm)
|
cg.SetStateManager(sm)
|
||||||
@ -518,13 +524,13 @@ func TestForkPreMigration(t *testing.T) {
|
|||||||
registry := builtin.MakeRegistryLegacy([]rtt.VMActor{testActor{}})
|
registry := builtin.MakeRegistryLegacy([]rtt.VMActor{testActor{}})
|
||||||
inv.Register(actorstypes.Version0, nil, registry)
|
inv.Register(actorstypes.Version0, nil, registry)
|
||||||
|
|
||||||
sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, error) {
|
sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Executor, error) {
|
||||||
nvm, err := vm.NewLegacyVM(ctx, vmopt)
|
nvm, err := vm.NewLegacyVM(ctx, vmopt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
nvm.SetInvoker(inv)
|
nvm.SetInvoker(inv)
|
||||||
return nvm, nil
|
return &mockExecutor{nvm}, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
cg.SetStateManager(sm)
|
cg.SetStateManager(sm)
|
||||||
@ -592,11 +598,11 @@ func TestDisablePreMigration(t *testing.T) {
|
|||||||
registry := builtin.MakeRegistryLegacy([]rtt.VMActor{testActor{}})
|
registry := builtin.MakeRegistryLegacy([]rtt.VMActor{testActor{}})
|
||||||
inv.Register(actorstypes.Version0, nil, registry)
|
inv.Register(actorstypes.Version0, nil, registry)
|
||||||
|
|
||||||
sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, error) {
|
sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Executor, error) {
|
||||||
nvm, err := vm.NewLegacyVM(ctx, vmopt)
|
nvm, err := vm.NewLegacyVM(ctx, vmopt)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
nvm.SetInvoker(inv)
|
nvm.SetInvoker(inv)
|
||||||
return nvm, nil
|
return &mockExecutor{nvm}, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
cg.SetStateManager(sm)
|
cg.SetStateManager(sm)
|
||||||
@ -647,11 +653,11 @@ func TestMigrtionCache(t *testing.T) {
|
|||||||
registry := builtin.MakeRegistryLegacy([]rtt.VMActor{testActor{}})
|
registry := builtin.MakeRegistryLegacy([]rtt.VMActor{testActor{}})
|
||||||
inv.Register(actorstypes.Version0, nil, registry)
|
inv.Register(actorstypes.Version0, nil, registry)
|
||||||
|
|
||||||
sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, error) {
|
sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Executor, error) {
|
||||||
nvm, err := vm.NewLegacyVM(ctx, vmopt)
|
nvm, err := vm.NewLegacyVM(ctx, vmopt)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
nvm.SetInvoker(inv)
|
nvm.SetInvoker(inv)
|
||||||
return nvm, nil
|
return &mockExecutor{nvm}, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
cg.SetStateManager(sm)
|
cg.SetStateManager(sm)
|
||||||
@ -691,11 +697,11 @@ func TestMigrtionCache(t *testing.T) {
|
|||||||
index.DummyMsgIndex,
|
index.DummyMsgIndex,
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, error) {
|
sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Executor, error) {
|
||||||
nvm, err := vm.NewLegacyVM(ctx, vmopt)
|
nvm, err := vm.NewLegacyVM(ctx, vmopt)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
nvm.SetInvoker(inv)
|
nvm.SetInvoker(inv)
|
||||||
return nvm, nil
|
return &mockExecutor{nvm}, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
@ -128,7 +128,7 @@ type StateManager struct {
|
|||||||
compWait map[string]chan struct{}
|
compWait map[string]chan struct{}
|
||||||
stlk sync.Mutex
|
stlk sync.Mutex
|
||||||
genesisMsigLk sync.Mutex
|
genesisMsigLk sync.Mutex
|
||||||
newVM func(context.Context, *vm.VMOpts) (vm.Interface, error)
|
newVM func(context.Context, *vm.VMOpts) (vm.Executor, error)
|
||||||
Syscalls vm.SyscallBuilder
|
Syscalls vm.SyscallBuilder
|
||||||
preIgnitionVesting []msig0.State
|
preIgnitionVesting []msig0.State
|
||||||
postIgnitionVesting []msig0.State
|
postIgnitionVesting []msig0.State
|
||||||
@ -459,12 +459,12 @@ func (sm *StateManager) ValidateChain(ctx context.Context, ts *types.TipSet) err
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *StateManager) SetVMConstructor(nvm func(context.Context, *vm.VMOpts) (vm.Interface, error)) {
|
func (sm *StateManager) SetVMConstructor(nvm func(context.Context, *vm.VMOpts) (vm.Executor, error)) {
|
||||||
sm.newVM = nvm
|
sm.newVM = nvm
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sm *StateManager) VMConstructor() func(context.Context, *vm.VMOpts) (vm.Interface, error) {
|
func (sm *StateManager) VMConstructor() func(context.Context, *vm.VMOpts) (vm.Executor, error) {
|
||||||
return func(ctx context.Context, opts *vm.VMOpts) (vm.Interface, error) {
|
return func(ctx context.Context, opts *vm.VMOpts) (vm.Executor, error) {
|
||||||
return sm.newVM(ctx, opts)
|
return sm.newVM(ctx, opts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ func (d *Driver) ExecuteTipset(bs blockstore.Blockstore, ds ds.Batching, params
|
|||||||
results: []*vm.ApplyRet{},
|
results: []*vm.ApplyRet{},
|
||||||
}
|
}
|
||||||
|
|
||||||
sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, error) {
|
sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Executor, error) {
|
||||||
vmopt.CircSupplyCalc = func(context.Context, abi.ChainEpoch, *state.StateTree) (abi.TokenAmount, error) {
|
vmopt.CircSupplyCalc = func(context.Context, abi.ChainEpoch, *state.StateTree) (abi.TokenAmount, error) {
|
||||||
return big.Zero(), nil
|
return big.Zero(), nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user