Merge pull request #9604 from filecoin-project/steb/fix-tvx-fvm

fix: tvx: make it work with the FVM
This commit is contained in:
Aayush Rajasekaran 2022-11-08 14:28:18 +00:00 committed by GitHub
commit 9c5f3854ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 15 deletions

View File

@ -227,6 +227,10 @@ type VMOpts struct {
}
func NewLegacyVM(ctx context.Context, opts *VMOpts) (*LegacyVM, error) {
if opts.NetworkVersion >= network.Version16 {
return nil, xerrors.Errorf("the legacy VM does not support network versions 16+")
}
buf := blockstore.NewBuffered(opts.Bstore)
cst := cbor.NewCborStore(buf)
state, err := state.LoadStateTree(cst, opts.StateBase)

View File

@ -16,6 +16,7 @@ import (
cbor "github.com/ipfs/go-ipld-cbor"
format "github.com/ipfs/go-ipld-format"
"github.com/ipfs/go-merkledag"
"golang.org/x/xerrors"
"github.com/filecoin-project/lotus/api/v0api"
"github.com/filecoin-project/lotus/blockstore"
@ -158,3 +159,12 @@ func (pb *proxyingBlockstore) PutMany(ctx context.Context, blocks []blocks.Block
pb.lk.Unlock()
return pb.Blockstore.PutMany(ctx, blocks)
}
func (pb *proxyingBlockstore) View(ctx context.Context, c cid.Cid, callback func([]byte) error) error {
blk, err := pb.Get(ctx, c)
if err != nil {
return xerrors.Errorf("failed to Get cid %s: %w", c, err)
}
return callback(blk.RawData())
}

View File

@ -160,7 +160,7 @@ func (d *Driver) ExecuteTipset(bs blockstore.Blockstore, ds ds.Batching, params
return big.Zero(), nil
}
return vm.NewLegacyVM(ctx, vmopt)
return vm.NewVM(ctx, vmopt)
})
postcid, receiptsroot, err := tse.ApplyBlocks(context.Background(),
@ -242,23 +242,38 @@ func (d *Driver) ExecuteMessage(bs blockstore.Blockstore, params ExecuteMessageP
LookbackState: lookback,
}
lvm, err := vm.NewLegacyVM(context.TODO(), vmOpts)
if err != nil {
return nil, cid.Undef, err
}
invoker := filcns.NewActorRegistry()
// register the chaos actor if required by the vector.
var vmi vm.Interface
if chaosOn, ok := d.selector["chaos_actor"]; ok && chaosOn == "true" {
lvm, err := vm.NewLegacyVM(context.TODO(), vmOpts)
if err != nil {
return nil, cid.Undef, err
}
invoker := filcns.NewActorRegistry()
av, _ := actorstypes.VersionForNetwork(params.NetworkVersion)
registry := builtin.MakeRegistryLegacy([]rtt.VMActor{chaos.Actor{}})
invoker.Register(av, nil, registry)
lvm.SetInvoker(invoker)
vmi = lvm
} else {
if vmOpts.NetworkVersion >= network.Version16 {
fvm, err := vm.NewFVM(context.TODO(), vmOpts)
if err != nil {
return nil, cid.Undef, err
}
vmi = fvm
} else {
lvm, err := vm.NewLegacyVM(context.TODO(), vmOpts)
if err != nil {
return nil, cid.Undef, err
}
invoker := filcns.NewActorRegistry()
lvm.SetInvoker(invoker)
vmi = lvm
}
}
lvm.SetInvoker(invoker)
ret, err := lvm.ApplyMessage(d.ctx, toChainMsg(params.Message))
ret, err := vmi.ApplyMessage(d.ctx, toChainMsg(params.Message))
if err != nil {
return nil, cid.Undef, err
}
@ -266,10 +281,10 @@ func (d *Driver) ExecuteMessage(bs blockstore.Blockstore, params ExecuteMessageP
var root cid.Cid
if d.vmFlush {
// flush the VM, committing the state tree changes and forcing a
// recursive copoy from the temporary blcokstore to the real blockstore.
root, err = lvm.Flush(d.ctx)
// recursive copy from the temporary blockstore to the real blockstore.
root, err = vmi.Flush(d.ctx)
} else {
root, err = lvm.StateTree().(*state.StateTree).Flush(d.ctx)
root, err = vmi.(*vm.LegacyVM).StateTree().(*state.StateTree).Flush(d.ctx)
}
return ret, root, err