diff --git a/chain/consensus/filcns/compute_state.go b/chain/consensus/filcns/compute_state.go index 929ac9f2f..5c22813ad 100644 --- a/chain/consensus/filcns/compute_state.go +++ b/chain/consensus/filcns/compute_state.go @@ -96,11 +96,6 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, sm *stmgr.StateManager ctx = blockstore.WithHotView(ctx) makeVmWithBaseStateAndEpoch := func(base cid.Cid, e abi.ChainEpoch) (vm.VMI, error) { - filVested, err := sm.GetFilVested(ctx, e) - if err != nil { - return nil, err - } - vmopt := &vm.VMOpts{ StateBase: base, Epoch: e, @@ -109,13 +104,18 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, sm *stmgr.StateManager Actors: NewActorRegistry(), Syscalls: sm.Syscalls, CircSupplyCalc: sm.GetVMCirculatingSupply, - FilVested: filVested, NetworkVersion: sm.GetNetworkVersion(ctx, e), BaseFee: baseFee, LookbackState: stmgr.LookbackStateGetterForTipset(sm, ts), } if os.Getenv("LOTUS_USE_FVM_DOESNT_WORK_YET") == "1" { + filVested, err := sm.GetFilVested(ctx, e) + if err != nil { + return nil, err + } + + vmopt.FilVested = filVested return vm.NewFVM(ctx, vmopt) } diff --git a/chain/stmgr/forks_test.go b/chain/stmgr/forks_test.go index fbf7b6785..d85aa810f 100644 --- a/chain/stmgr/forks_test.go +++ b/chain/stmgr/forks_test.go @@ -166,7 +166,7 @@ func TestForkHeightTriggers(t *testing.T) { inv := filcns.NewActorRegistry() inv.Register(nil, testActor{}) - sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (*vm.VM, error) { + sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.VMI, error) { nvm, err := vm.NewLotusVM(ctx, vmopt) if err != nil { return nil, err @@ -281,7 +281,7 @@ func testForkRefuseCall(t *testing.T, nullsBefore, nullsAfter int) { inv := filcns.NewActorRegistry() inv.Register(nil, testActor{}) - sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (*vm.VM, error) { + sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.VMI, error) { nvm, err := vm.NewLotusVM(ctx, vmopt) if err != nil { return nil, err @@ -500,7 +500,7 @@ func TestForkPreMigration(t *testing.T) { inv := filcns.NewActorRegistry() inv.Register(nil, testActor{}) - sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (*vm.VM, error) { + sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.VMI, error) { nvm, err := vm.NewLotusVM(ctx, vmopt) if err != nil { return nil, err diff --git a/chain/vm/fvm.go b/chain/vm/fvm.go index 743e0fdee..c8f8a0d9e 100644 --- a/chain/vm/fvm.go +++ b/chain/vm/fvm.go @@ -5,6 +5,8 @@ import ( "context" "time" + "github.com/filecoin-project/go-state-types/network" + "github.com/filecoin-project/go-state-types/big" "github.com/filecoin-project/lotus/build" @@ -215,9 +217,24 @@ type FVM struct { } func NewFVM(ctx context.Context, opts *VMOpts) (*FVM, error) { + circToReport := opts.FilVested + // For v14 (and earlier), we perform the FilVested portion of the calculation, and let the FVM dynamically do the rest + // v15 and after, the circ supply is always constant per epoch, so we calculate the base and report it at creation + if opts.NetworkVersion >= network.Version15 { + state, err := state.LoadStateTree(cbor.NewCborStore(opts.Bstore), opts.StateBase) + if err != nil { + return nil, err + } + + circToReport, err = opts.CircSupplyCalc(ctx, opts.Epoch, state) + if err != nil { + return nil, err + } + } + fvm, err := ffi.CreateFVM(0, &FvmExtern{Rand: opts.Rand, Blockstore: opts.Bstore, lbState: opts.LookbackState, base: opts.StateBase, epoch: opts.Epoch}, - opts.Epoch, opts.BaseFee, opts.FilVested, opts.NetworkVersion, opts.StateBase, + opts.Epoch, opts.BaseFee, circToReport, opts.NetworkVersion, opts.StateBase, ) if err != nil { return nil, err diff --git a/conformance/driver.go b/conformance/driver.go index 6af4372d2..0a24f07ef 100644 --- a/conformance/driver.go +++ b/conformance/driver.go @@ -155,7 +155,7 @@ func (d *Driver) ExecuteTipset(bs blockstore.Blockstore, ds ds.Batching, params results: []*vm.ApplyRet{}, } - sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (*vm.VM, error) { + sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.VMI, error) { vmopt.CircSupplyCalc = func(context.Context, abi.ChainEpoch, *state.StateTree) (abi.TokenAmount, error) { return big.Zero(), nil } diff --git a/extern/filecoin-ffi b/extern/filecoin-ffi index 9ff230110..084ee8673 160000 --- a/extern/filecoin-ffi +++ b/extern/filecoin-ffi @@ -1 +1 @@ -Subproject commit 9ff2301105fcf25101f1fcda52e6417f3e2ca60b +Subproject commit 084ee8673f6487c71b60996e6d8d6c5fa2cf04ab