From 2a669b95fbd898942440330a9dd6bdb0d051e374 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Thu, 16 Dec 2021 22:38:13 -0500 Subject: [PATCH 01/27] :Hook up the FVM --- chain/consensus/filcns/compute_state.go | 9 +- chain/vm/fvm.go | 154 ++++++++++++++++++++++++ chain/vm/vm.go | 2 + chain/vm/vmi.go | 14 +++ extern/filecoin-ffi | 2 +- 5 files changed, 178 insertions(+), 3 deletions(-) create mode 100644 chain/vm/fvm.go create mode 100644 chain/vm/vmi.go diff --git a/chain/consensus/filcns/compute_state.go b/chain/consensus/filcns/compute_state.go index f7f6284d0a0..37e78874db2 100644 --- a/chain/consensus/filcns/compute_state.go +++ b/chain/consensus/filcns/compute_state.go @@ -2,6 +2,7 @@ package filcns import ( "context" + "os" "sync/atomic" "github.com/filecoin-project/lotus/chain/rand" @@ -92,7 +93,7 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, sm *stmgr.StateManager partDone() }() - makeVmWithBaseStateAndEpoch := func(base cid.Cid, e abi.ChainEpoch) (*vm.VM, error) { + makeVmWithBaseStateAndEpoch := func(base cid.Cid, e abi.ChainEpoch) (vm.VMI, error) { vmopt := &vm.VMOpts{ StateBase: base, Epoch: e, @@ -106,10 +107,14 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, sm *stmgr.StateManager LookbackState: stmgr.LookbackStateGetterForTipset(sm, ts), } + if os.Getenv("LOTUS_USE_FVM_DOESNT_WORK_YET") == "1" { + return vm.NewFVM(ctx, vmopt) + } + return sm.VMConstructor()(ctx, vmopt) } - runCron := func(vmCron *vm.VM, epoch abi.ChainEpoch) error { + runCron := func(vmCron vm.VMI, epoch abi.ChainEpoch) error { cronMsg := &types.Message{ To: cron.Address, From: builtin.SystemActorAddr, diff --git a/chain/vm/fvm.go b/chain/vm/fvm.go new file mode 100644 index 00000000000..0630c145bdf --- /dev/null +++ b/chain/vm/fvm.go @@ -0,0 +1,154 @@ +package vm + +import ( + "context" + + "github.com/filecoin-project/go-address" + "github.com/filecoin-project/go-state-types/crypto" + "github.com/filecoin-project/lotus/chain/actors/aerrors" + "github.com/filecoin-project/specs-actors/v7/actors/runtime" + + "github.com/filecoin-project/go-state-types/abi" + "github.com/filecoin-project/go-state-types/exitcode" + + "golang.org/x/xerrors" + + "github.com/filecoin-project/lotus/blockstore" + "github.com/filecoin-project/lotus/chain/state" + cbor "github.com/ipfs/go-ipld-cbor" + + ffi "github.com/filecoin-project/filecoin-ffi" + + "github.com/filecoin-project/lotus/chain/types" + "github.com/ipfs/go-cid" +) + +var _ VMI = (*FVM)(nil) + +type Extern interface { + GetRandomnessFromTickets(personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) abi.Randomness + GetRandomnessFromBeacon(personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) abi.Randomness + VerifyConsensusFault(a, b, extra []byte) (address.Address, abi.ChainEpoch, runtime.ConsensusFaultType) +} +type FvmExtern struct { + rand Rand +} + +func (e *FvmExtern) GetRandomnessFromTickets(personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) abi.Randomness { + res, err := e.rand.GetChainRandomness(context.Background(), personalization, randEpoch, entropy) + + if err != nil { + panic(aerrors.Fatalf("could not get ticket randomness: %s", err)) + } + return res +} + +func (e *FvmExtern) GetRandomnessFromBeacon(personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) abi.Randomness { + res, err := e.rand.GetBeaconRandomness(context.Background(), personalization, randEpoch, entropy) + + if err != nil { + panic(aerrors.Fatalf("could not get ticket randomness: %s", err)) + } + return res +} + +type FVM struct { + machineId uint64 + extern FvmExtern +} + +func NewFVM(ctx context.Context, opts *VMOpts) (*FVM, error) { + buf := blockstore.NewBuffered(opts.Bstore) + cst := cbor.NewCborStore(buf) + state, err := state.LoadStateTree(cst, opts.StateBase) + if err != nil { + return nil, err + } + + baseCirc, err := opts.CircSupplyCalc(ctx, opts.Epoch, state) + if err != nil { + return nil, err + } + + id, err := ffi.CreateFVM(0, opts.Epoch, opts.BaseFee, baseCirc, opts.NetworkVersion, opts.StateBase) + if err != nil { + return nil, err + } + + return &FVM{ + extern: FvmExtern{rand: opts.Rand}, + machineId: id, + }, nil +} + +func (vm *FVM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet, error) { + msgBytes, err := cmsg.VMMessage().Serialize() + if err != nil { + return nil, xerrors.Errorf("serializing msg: %w", err) + } + + ret, err := ffi.ApplyMessage(vm.machineId, msgBytes) + if err != nil { + return nil, xerrors.Errorf("applying msg: %w", err) + } + + return &ApplyRet{ + MessageReceipt: types.MessageReceipt{ + Return: ret.Return, + ExitCode: exitcode.ExitCode(ret.ExitCode), + GasUsed: ret.GasUsed, + }, + GasCosts: &GasOutputs{ + // TODO: do the other optional fields eventually + BaseFeeBurn: abi.TokenAmount{}, + OverEstimationBurn: abi.TokenAmount{}, + MinerPenalty: ret.MinerPenalty, + MinerTip: ret.MinerTip, + Refund: abi.TokenAmount{}, + GasRefund: 0, + GasBurned: 0, + }, + // TODO: do these eventually, not consensus critical + ActorErr: nil, + ExecutionTrace: types.ExecutionTrace{}, + Duration: 0, + }, nil +} + +func (vm *FVM) ApplyImplicitMessage(ctx context.Context, cmsg *types.Message) (*ApplyRet, error) { + msgBytes, err := cmsg.VMMessage().Serialize() + if err != nil { + return nil, xerrors.Errorf("serializing msg: %w", err) + } + + ret, err := ffi.ApplyMessage(vm.machineId, msgBytes) + if err != nil { + return nil, xerrors.Errorf("applying msg: %w", err) + } + + return &ApplyRet{ + MessageReceipt: types.MessageReceipt{ + Return: ret.Return, + ExitCode: exitcode.ExitCode(ret.ExitCode), + GasUsed: ret.GasUsed, + }, + GasCosts: &GasOutputs{ + // TODO: do the other optional fields eventually + BaseFeeBurn: abi.TokenAmount{}, + OverEstimationBurn: abi.TokenAmount{}, + MinerPenalty: ret.MinerPenalty, + MinerTip: ret.MinerTip, + Refund: abi.TokenAmount{}, + GasRefund: 0, + GasBurned: 0, + }, + // TODO: do these eventually, not consensus critical + ActorErr: nil, + ExecutionTrace: types.ExecutionTrace{}, + Duration: 0, + }, nil +} + +func (vm *FVM) Flush(ctx context.Context) (cid.Cid, error) { + return cid.Undef, nil +} diff --git a/chain/vm/vm.go b/chain/vm/vm.go index 1ab97bc33f8..2ee732d5e20 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -201,6 +201,8 @@ type ( LookbackStateGetter func(context.Context, abi.ChainEpoch) (*state.StateTree, error) ) +var _ VMI = (*VM)(nil) + type VM struct { cstate *state.StateTree cst *cbor.BasicIpldStore diff --git a/chain/vm/vmi.go b/chain/vm/vmi.go new file mode 100644 index 00000000000..4903354d221 --- /dev/null +++ b/chain/vm/vmi.go @@ -0,0 +1,14 @@ +package vm + +import ( + "context" + + "github.com/filecoin-project/lotus/chain/types" + "github.com/ipfs/go-cid" +) + +type VMI interface { + ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet, error) + ApplyImplicitMessage(ctx context.Context, msg *types.Message) (*ApplyRet, error) + Flush(ctx context.Context) (cid.Cid, error) +} diff --git a/extern/filecoin-ffi b/extern/filecoin-ffi index e660df5616e..7e1f3a991e4 160000 --- a/extern/filecoin-ffi +++ b/extern/filecoin-ffi @@ -1 +1 @@ -Subproject commit e660df5616e397b2d8ac316f45ddfa7a44637971 +Subproject commit 7e1f3a991e410a71ed9ef33becee8d56d5cb9d26 From fc74a6c8cacae697d9553313f7e17271150d59cb Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 31 Jan 2022 02:31:58 -0800 Subject: [PATCH 02/27] update fvm/ffi bindings --- chain/vm/fvm.go | 50 ++++++++++++++------------------------------- extern/filecoin-ffi | 2 +- go.mod | 4 +--- go.sum | 7 ++----- 4 files changed, 19 insertions(+), 44 deletions(-) diff --git a/chain/vm/fvm.go b/chain/vm/fvm.go index 0630c145bdf..f864966c37d 100644 --- a/chain/vm/fvm.go +++ b/chain/vm/fvm.go @@ -3,11 +3,6 @@ package vm import ( "context" - "github.com/filecoin-project/go-address" - "github.com/filecoin-project/go-state-types/crypto" - "github.com/filecoin-project/lotus/chain/actors/aerrors" - "github.com/filecoin-project/specs-actors/v7/actors/runtime" - "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/exitcode" @@ -18,6 +13,7 @@ import ( cbor "github.com/ipfs/go-ipld-cbor" ffi "github.com/filecoin-project/filecoin-ffi" + ffi_cgo "github.com/filecoin-project/filecoin-ffi/cgo" "github.com/filecoin-project/lotus/chain/types" "github.com/ipfs/go-cid" @@ -25,36 +21,18 @@ import ( var _ VMI = (*FVM)(nil) -type Extern interface { - GetRandomnessFromTickets(personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) abi.Randomness - GetRandomnessFromBeacon(personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) abi.Randomness - VerifyConsensusFault(a, b, extra []byte) (address.Address, abi.ChainEpoch, runtime.ConsensusFaultType) -} type FvmExtern struct { - rand Rand -} - -func (e *FvmExtern) GetRandomnessFromTickets(personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) abi.Randomness { - res, err := e.rand.GetChainRandomness(context.Background(), personalization, randEpoch, entropy) - - if err != nil { - panic(aerrors.Fatalf("could not get ticket randomness: %s", err)) - } - return res + Rand + blockstore.Blockstore } -func (e *FvmExtern) GetRandomnessFromBeacon(personalization crypto.DomainSeparationTag, randEpoch abi.ChainEpoch, entropy []byte) abi.Randomness { - res, err := e.rand.GetBeaconRandomness(context.Background(), personalization, randEpoch, entropy) - - if err != nil { - panic(aerrors.Fatalf("could not get ticket randomness: %s", err)) - } - return res +func (x *FvmExtern) VerifyConsensusFault(ctx context.Context, h1, h2, extra []byte) (*ffi_cgo.ConsensusFault, error) { + // TODO + panic("unimplemented") } type FVM struct { - machineId uint64 - extern FvmExtern + fvm *ffi.FVM } func NewFVM(ctx context.Context, opts *VMOpts) (*FVM, error) { @@ -70,14 +48,16 @@ func NewFVM(ctx context.Context, opts *VMOpts) (*FVM, error) { return nil, err } - id, err := ffi.CreateFVM(0, opts.Epoch, opts.BaseFee, baseCirc, opts.NetworkVersion, opts.StateBase) + fvm, err := ffi.CreateFVM(0, + &FvmExtern{Rand: opts.Rand, Blockstore: opts.Bstore}, + opts.Epoch, opts.BaseFee, baseCirc, opts.NetworkVersion, opts.StateBase, + ) if err != nil { return nil, err } return &FVM{ - extern: FvmExtern{rand: opts.Rand}, - machineId: id, + fvm: fvm, }, nil } @@ -87,7 +67,7 @@ func (vm *FVM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet return nil, xerrors.Errorf("serializing msg: %w", err) } - ret, err := ffi.ApplyMessage(vm.machineId, msgBytes) + ret, err := vm.fvm.ApplyMessage(msgBytes) if err != nil { return nil, xerrors.Errorf("applying msg: %w", err) } @@ -121,7 +101,7 @@ func (vm *FVM) ApplyImplicitMessage(ctx context.Context, cmsg *types.Message) (* return nil, xerrors.Errorf("serializing msg: %w", err) } - ret, err := ffi.ApplyMessage(vm.machineId, msgBytes) + ret, err := vm.fvm.ApplyMessage(msgBytes) if err != nil { return nil, xerrors.Errorf("applying msg: %w", err) } @@ -150,5 +130,5 @@ func (vm *FVM) ApplyImplicitMessage(ctx context.Context, cmsg *types.Message) (* } func (vm *FVM) Flush(ctx context.Context) (cid.Cid, error) { - return cid.Undef, nil + return vm.fvm.Flush() } diff --git a/extern/filecoin-ffi b/extern/filecoin-ffi index 7e1f3a991e4..a7295282a51 160000 --- a/extern/filecoin-ffi +++ b/extern/filecoin-ffi @@ -1 +1 @@ -Subproject commit 7e1f3a991e410a71ed9ef33becee8d56d5cb9d26 +Subproject commit a7295282a51d2b24e1e02e228a5b9f5f7b412bc2 diff --git a/go.mod b/go.mod index 16602b398ec..1c1da6149ea 100644 --- a/go.mod +++ b/go.mod @@ -50,7 +50,7 @@ require ( github.com/filecoin-project/specs-actors/v4 v4.0.1 github.com/filecoin-project/specs-actors/v5 v5.0.4 github.com/filecoin-project/specs-actors/v6 v6.0.1 - github.com/filecoin-project/specs-actors/v7 v7.0.0-rc1 + github.com/filecoin-project/specs-actors/v7 v7.0.0-rc1.0.20220118005651-2470cb39827e github.com/filecoin-project/specs-storage v0.1.1-0.20211228030229-6d460d25a0c9 github.com/filecoin-project/test-vectors/schema v0.0.5 github.com/gbrlsnchs/jwt/v3 v3.0.1 @@ -159,7 +159,6 @@ require ( go.uber.org/fx v1.9.0 go.uber.org/multierr v1.7.0 go.uber.org/zap v1.19.1 - golang.org/x/crypto v0.0.0-20211209193657-4570a0811e8b // indirect golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 golang.org/x/sync v0.0.0-20210220032951-036812b2e83c golang.org/x/sys v0.0.0-20211209171907-798191bca915 @@ -168,7 +167,6 @@ require ( golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 gopkg.in/cheggaaa/pb.v1 v1.0.28 gotest.tools v2.2.0+incompatible - lukechampine.com/blake3 v1.1.7 // indirect ) replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi diff --git a/go.sum b/go.sum index 817c9e1ba35..dd6abce8eab 100644 --- a/go.sum +++ b/go.sum @@ -321,7 +321,6 @@ github.com/filecoin-project/go-data-transfer v1.14.0/go.mod h1:wNJKhaLLYBJDM3VFv github.com/filecoin-project/go-ds-versioning v0.0.0-20211206185234-508abd7c2aff/go.mod h1:C9/l9PnB1+mwPa26BBVpCjG/XQCB0yj/q5CK2J8X1I4= github.com/filecoin-project/go-ds-versioning v0.1.1 h1:JiyBqaQlwC+UM0WhcBtVEeT3XrX59mQhT8U3p7nu86o= github.com/filecoin-project/go-ds-versioning v0.1.1/go.mod h1:C9/l9PnB1+mwPa26BBVpCjG/XQCB0yj/q5CK2J8X1I4= -github.com/filecoin-project/go-fil-commcid v0.0.0-20200716160307-8f644712406f/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ= github.com/filecoin-project/go-fil-commcid v0.0.0-20201016201715-d41df56b4f6a/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ= github.com/filecoin-project/go-fil-commcid v0.1.0 h1:3R4ds1A9r6cr8mvZBfMYxTS88OqLYEo6roi+GiIeOh8= github.com/filecoin-project/go-fil-commcid v0.1.0/go.mod h1:Eaox7Hvus1JgPrL5+M3+h7aSPHc0cVqpSxA+TxIEpZQ= @@ -378,10 +377,9 @@ github.com/filecoin-project/specs-actors/v5 v5.0.4/go.mod h1:5BAKRAMsOOlD8+qCw4U github.com/filecoin-project/specs-actors/v6 v6.0.0/go.mod h1:V1AYfi5GkHXipx1mnVivoICZh3wtwPxDVuds+fbfQtk= github.com/filecoin-project/specs-actors/v6 v6.0.1 h1:laxvHNsvrq83Y9n+W7znVCePi3oLyRf0Rkl4jFO8Wew= github.com/filecoin-project/specs-actors/v6 v6.0.1/go.mod h1:V1AYfi5GkHXipx1mnVivoICZh3wtwPxDVuds+fbfQtk= -github.com/filecoin-project/specs-actors/v7 v7.0.0-20211117170924-fd07a4c7dff9/go.mod h1:p6LIOFezA1rgRLMewbvdi3Pp6SAu+q9FtJ9CAleSjrE= github.com/filecoin-project/specs-actors/v7 v7.0.0-20211222192039-c83bea50c402/go.mod h1:p6LIOFezA1rgRLMewbvdi3Pp6SAu+q9FtJ9CAleSjrE= -github.com/filecoin-project/specs-actors/v7 v7.0.0-rc1 h1:FuDaXIbcw2hRsFI8SDTmsGGCE+NumpF6aiBoU/2X5W4= -github.com/filecoin-project/specs-actors/v7 v7.0.0-rc1/go.mod h1:TA5FwCna+Yi36POaT7SLKXsgEDvJwc0V/L6ZsO19B9M= +github.com/filecoin-project/specs-actors/v7 v7.0.0-rc1.0.20220118005651-2470cb39827e h1:3P14MvJ5MA0jwEB4WDeROrci4o8KwVVAv2mJ70grbf0= +github.com/filecoin-project/specs-actors/v7 v7.0.0-rc1.0.20220118005651-2470cb39827e/go.mod h1:TA5FwCna+Yi36POaT7SLKXsgEDvJwc0V/L6ZsO19B9M= github.com/filecoin-project/specs-storage v0.1.1-0.20211228030229-6d460d25a0c9 h1:oUYOvF7EvdXS0Zmk9mNkaB6Bu0l+WXBYPzVodKMiLug= github.com/filecoin-project/specs-storage v0.1.1-0.20211228030229-6d460d25a0c9/go.mod h1:Tb88Zq+IBJbvAn3mS89GYj3jdRThBTE/771HCVZdRJU= github.com/filecoin-project/test-vectors/schema v0.0.5 h1:w3zHQhzM4pYxJDl21avXjOKBLF8egrvwUwjpT8TquDg= @@ -2328,7 +2326,6 @@ golang.org/x/tools v0.0.0-20200711155855-7342f9734a7d/go.mod h1:njjCfa9FT2d7l9Bc golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.0.0-20201112185108-eeaa07dd7696/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= From 04092f3e6b6e10b736d2dda9d5e290d899d75a88 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 1 Feb 2022 20:13:45 -0800 Subject: [PATCH 03/27] update ffi --- extern/filecoin-ffi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extern/filecoin-ffi b/extern/filecoin-ffi index a7295282a51..b71619c2afa 160000 --- a/extern/filecoin-ffi +++ b/extern/filecoin-ffi @@ -1 +1 @@ -Subproject commit a7295282a51d2b24e1e02e228a5b9f5f7b412bc2 +Subproject commit b71619c2afa2487f2f4c5aceb4ba8f1fcb05ba52 From 279cdd0760f93961d73e36538f000b66be970616 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Mon, 7 Feb 2022 10:33:57 -0800 Subject: [PATCH 04/27] fvm: fix implicit messages and message inclusion gas charging --- chain/vm/fvm.go | 4 ++-- extern/filecoin-ffi | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/chain/vm/fvm.go b/chain/vm/fvm.go index f864966c37d..5b4756dff17 100644 --- a/chain/vm/fvm.go +++ b/chain/vm/fvm.go @@ -67,7 +67,7 @@ func (vm *FVM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet return nil, xerrors.Errorf("serializing msg: %w", err) } - ret, err := vm.fvm.ApplyMessage(msgBytes) + ret, err := vm.fvm.ApplyMessage(msgBytes, uint(cmsg.ChainLength())) if err != nil { return nil, xerrors.Errorf("applying msg: %w", err) } @@ -101,7 +101,7 @@ func (vm *FVM) ApplyImplicitMessage(ctx context.Context, cmsg *types.Message) (* return nil, xerrors.Errorf("serializing msg: %w", err) } - ret, err := vm.fvm.ApplyMessage(msgBytes) + ret, err := vm.fvm.ApplyImplicitMessage(msgBytes) if err != nil { return nil, xerrors.Errorf("applying msg: %w", err) } diff --git a/extern/filecoin-ffi b/extern/filecoin-ffi index b71619c2afa..1e18dc4148d 160000 --- a/extern/filecoin-ffi +++ b/extern/filecoin-ffi @@ -1 +1 @@ -Subproject commit b71619c2afa2487f2f4c5aceb4ba8f1fcb05ba52 +Subproject commit 1e18dc4148d5f8aedc91e173b87b632635ad01ee From 32b3618c7476b189bad02c8d263898d0e2beb5b7 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 8 Feb 2022 13:20:03 -0800 Subject: [PATCH 05/27] fvm: feed in correct "base" circulating supply --- chain/consensus/filcns/compute_state.go | 11 +++++++++++ chain/vm/fvm.go | 16 +--------------- chain/vm/vm.go | 2 ++ 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/chain/consensus/filcns/compute_state.go b/chain/consensus/filcns/compute_state.go index 37e78874db2..82763c05240 100644 --- a/chain/consensus/filcns/compute_state.go +++ b/chain/consensus/filcns/compute_state.go @@ -94,6 +94,16 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, sm *stmgr.StateManager }() makeVmWithBaseStateAndEpoch := func(base cid.Cid, e abi.ChainEpoch) (vm.VMI, error) { + st, err := sm.StateTree(base) + if err != nil { + return nil, err + } + supply, err := sm.GetVMCirculatingSupplyDetailed(ctx, e, st) + if err != nil { + return nil, err + } + circulating := big.Add(supply.FilMined, supply.FilVested) + vmopt := &vm.VMOpts{ StateBase: base, Epoch: e, @@ -102,6 +112,7 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, sm *stmgr.StateManager Actors: NewActorRegistry(), Syscalls: sm.Syscalls, CircSupplyCalc: sm.GetVMCirculatingSupply, + BaseCircSupply: circulating, NetworkVersion: sm.GetNetworkVersion(ctx, e), BaseFee: baseFee, LookbackState: stmgr.LookbackStateGetterForTipset(sm, ts), diff --git a/chain/vm/fvm.go b/chain/vm/fvm.go index 5b4756dff17..1049a8ddc22 100644 --- a/chain/vm/fvm.go +++ b/chain/vm/fvm.go @@ -9,8 +9,6 @@ import ( "golang.org/x/xerrors" "github.com/filecoin-project/lotus/blockstore" - "github.com/filecoin-project/lotus/chain/state" - cbor "github.com/ipfs/go-ipld-cbor" ffi "github.com/filecoin-project/filecoin-ffi" ffi_cgo "github.com/filecoin-project/filecoin-ffi/cgo" @@ -36,21 +34,9 @@ type FVM struct { } func NewFVM(ctx context.Context, opts *VMOpts) (*FVM, error) { - buf := blockstore.NewBuffered(opts.Bstore) - cst := cbor.NewCborStore(buf) - state, err := state.LoadStateTree(cst, opts.StateBase) - if err != nil { - return nil, err - } - - baseCirc, 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}, - opts.Epoch, opts.BaseFee, baseCirc, opts.NetworkVersion, opts.StateBase, + opts.Epoch, opts.BaseFee, opts.BaseCircSupply, opts.NetworkVersion, opts.StateBase, ) if err != nil { return nil, err diff --git a/chain/vm/vm.go b/chain/vm/vm.go index 2ee732d5e20..831b5825466 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -227,6 +227,8 @@ type VMOpts struct { Actors *ActorRegistry Syscalls SyscallBuilder CircSupplyCalc CircSupplyCalculator + // Amount of FIL vested & mined. + BaseCircSupply abi.TokenAmount NetworkVersion network.Version BaseFee abi.TokenAmount LookbackState LookbackStateGetter From e8d771fcac1ac3394b461ce24b99cd94dc1b79cf Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 8 Feb 2022 15:26:20 -0800 Subject: [PATCH 06/27] pass only fil-vested into FVM --- chain/consensus/filcns/compute_state.go | 3 +-- chain/vm/fvm.go | 2 +- chain/vm/vm.go | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/chain/consensus/filcns/compute_state.go b/chain/consensus/filcns/compute_state.go index 82763c05240..ceebf8b357d 100644 --- a/chain/consensus/filcns/compute_state.go +++ b/chain/consensus/filcns/compute_state.go @@ -102,7 +102,6 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, sm *stmgr.StateManager if err != nil { return nil, err } - circulating := big.Add(supply.FilMined, supply.FilVested) vmopt := &vm.VMOpts{ StateBase: base, @@ -112,7 +111,7 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, sm *stmgr.StateManager Actors: NewActorRegistry(), Syscalls: sm.Syscalls, CircSupplyCalc: sm.GetVMCirculatingSupply, - BaseCircSupply: circulating, + FilVested: supply.FilVested, NetworkVersion: sm.GetNetworkVersion(ctx, e), BaseFee: baseFee, LookbackState: stmgr.LookbackStateGetterForTipset(sm, ts), diff --git a/chain/vm/fvm.go b/chain/vm/fvm.go index 1049a8ddc22..1e394a20258 100644 --- a/chain/vm/fvm.go +++ b/chain/vm/fvm.go @@ -36,7 +36,7 @@ type FVM struct { func NewFVM(ctx context.Context, opts *VMOpts) (*FVM, error) { fvm, err := ffi.CreateFVM(0, &FvmExtern{Rand: opts.Rand, Blockstore: opts.Bstore}, - opts.Epoch, opts.BaseFee, opts.BaseCircSupply, opts.NetworkVersion, opts.StateBase, + opts.Epoch, opts.BaseFee, opts.FilVested, opts.NetworkVersion, opts.StateBase, ) if err != nil { return nil, err diff --git a/chain/vm/vm.go b/chain/vm/vm.go index 831b5825466..3e2b76fe61c 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -227,8 +227,8 @@ type VMOpts struct { Actors *ActorRegistry Syscalls SyscallBuilder CircSupplyCalc CircSupplyCalculator - // Amount of FIL vested & mined. - BaseCircSupply abi.TokenAmount + // Amount of FIL vested from genesis actors. + FilVested abi.TokenAmount NetworkVersion network.Version BaseFee abi.TokenAmount LookbackState LookbackStateGetter From e8bdf8171bbed0cb24ee38c7bfc92120854b55ad Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 8 Feb 2022 20:54:53 -0800 Subject: [PATCH 07/27] chore: cleanup fil vested calculation 1. Move lock, loading, etc into GetFilVested. 2. Call it directly when creating the FVM. 3. Detach GetFilLocked from state manager. Really, this just makes it a bit easier to reason about this code. --- chain/consensus/filcns/compute_state.go | 8 +--- chain/stmgr/supply.go | 57 ++++++++++++++----------- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/chain/consensus/filcns/compute_state.go b/chain/consensus/filcns/compute_state.go index ceebf8b357d..28bdc0eb39a 100644 --- a/chain/consensus/filcns/compute_state.go +++ b/chain/consensus/filcns/compute_state.go @@ -94,11 +94,7 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, sm *stmgr.StateManager }() makeVmWithBaseStateAndEpoch := func(base cid.Cid, e abi.ChainEpoch) (vm.VMI, error) { - st, err := sm.StateTree(base) - if err != nil { - return nil, err - } - supply, err := sm.GetVMCirculatingSupplyDetailed(ctx, e, st) + filVested, err := sm.GetFilVested(ctx, e) if err != nil { return nil, err } @@ -111,7 +107,7 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, sm *stmgr.StateManager Actors: NewActorRegistry(), Syscalls: sm.Syscalls, CircSupplyCalc: sm.GetVMCirculatingSupply, - FilVested: supply.FilVested, + FilVested: filVested, NetworkVersion: sm.GetNetworkVersion(ctx, e), BaseFee: baseFee, LookbackState: stmgr.LookbackStateGetterForTipset(sm, ts), diff --git a/chain/stmgr/supply.go b/chain/stmgr/supply.go index 0744c02aa02..7e239d2dba3 100644 --- a/chain/stmgr/supply.go +++ b/chain/stmgr/supply.go @@ -196,8 +196,32 @@ func (sm *StateManager) setupPostCalicoVesting(ctx context.Context) error { // GetVestedFunds returns all funds that have "left" actors that are in the genesis state: // - For Multisigs, it counts the actual amounts that have vested at the given epoch // - For Accounts, it counts max(currentBalance - genesisBalance, 0). -func (sm *StateManager) GetFilVested(ctx context.Context, height abi.ChainEpoch, st *state.StateTree) (abi.TokenAmount, error) { +func (sm *StateManager) GetFilVested(ctx context.Context, height abi.ChainEpoch) (abi.TokenAmount, error) { vf := big.Zero() + + sm.genesisMsigLk.Lock() + defer sm.genesisMsigLk.Unlock() + + // TODO: combine all this? + if sm.preIgnitionVesting == nil || sm.genesisPledge.IsZero() || sm.genesisMarketFunds.IsZero() { + err := sm.setupGenesisVestingSchedule(ctx) + if err != nil { + return vf, xerrors.Errorf("failed to setup pre-ignition vesting schedule: %w", err) + } + } + if sm.postIgnitionVesting == nil { + err := sm.setupPostIgnitionVesting(ctx) + if err != nil { + return vf, xerrors.Errorf("failed to setup post-ignition vesting schedule: %w", err) + } + } + if sm.postCalicoVesting == nil { + err := sm.setupPostCalicoVesting(ctx) + if err != nil { + return vf, xerrors.Errorf("failed to setup post-calico vesting schedule: %w", err) + } + } + if height <= build.UpgradeIgnitionHeight { for _, v := range sm.preIgnitionVesting { au := big.Sub(v.InitialBalance, v.AmountLocked(height)) @@ -282,7 +306,7 @@ func getFilPowerLocked(ctx context.Context, st *state.StateTree) (abi.TokenAmoun return pst.TotalLocked() } -func (sm *StateManager) GetFilLocked(ctx context.Context, st *state.StateTree) (abi.TokenAmount, error) { +func GetFilLocked(ctx context.Context, st *state.StateTree) (abi.TokenAmount, error) { filMarketLocked, err := getFilMarketLocked(ctx, st) if err != nil { @@ -315,29 +339,12 @@ func (sm *StateManager) GetVMCirculatingSupply(ctx context.Context, height abi.C return cs.FilCirculating, err } -func (sm *StateManager) GetVMCirculatingSupplyDetailed(ctx context.Context, height abi.ChainEpoch, st *state.StateTree) (api.CirculatingSupply, error) { - sm.genesisMsigLk.Lock() - defer sm.genesisMsigLk.Unlock() - if sm.preIgnitionVesting == nil || sm.genesisPledge.IsZero() || sm.genesisMarketFunds.IsZero() { - err := sm.setupGenesisVestingSchedule(ctx) - if err != nil { - return api.CirculatingSupply{}, xerrors.Errorf("failed to setup pre-ignition vesting schedule: %w", err) - } - } - if sm.postIgnitionVesting == nil { - err := sm.setupPostIgnitionVesting(ctx) - if err != nil { - return api.CirculatingSupply{}, xerrors.Errorf("failed to setup post-ignition vesting schedule: %w", err) - } - } - if sm.postCalicoVesting == nil { - err := sm.setupPostCalicoVesting(ctx) - if err != nil { - return api.CirculatingSupply{}, xerrors.Errorf("failed to setup post-calico vesting schedule: %w", err) - } - } +func (sm *StateManager) loadGenesisMsigs(ctx context.Context) error { + return nil +} - filVested, err := sm.GetFilVested(ctx, height, st) +func (sm *StateManager) GetVMCirculatingSupplyDetailed(ctx context.Context, height abi.ChainEpoch, st *state.StateTree) (api.CirculatingSupply, error) { + filVested, err := sm.GetFilVested(ctx, height) if err != nil { return api.CirculatingSupply{}, xerrors.Errorf("failed to calculate filVested: %w", err) } @@ -360,7 +367,7 @@ func (sm *StateManager) GetVMCirculatingSupplyDetailed(ctx context.Context, heig return api.CirculatingSupply{}, xerrors.Errorf("failed to calculate filBurnt: %w", err) } - filLocked, err := sm.GetFilLocked(ctx, st) + filLocked, err := GetFilLocked(ctx, st) if err != nil { return api.CirculatingSupply{}, xerrors.Errorf("failed to calculate filLocked: %w", err) } From 743862857efb2516038a2fc1bb3b554b5317cec6 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Tue, 8 Feb 2022 20:57:20 -0800 Subject: [PATCH 08/27] ffi: update FFI for fvm changes --- extern/filecoin-ffi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extern/filecoin-ffi b/extern/filecoin-ffi index 1e18dc4148d..73f84f3d3c9 160000 --- a/extern/filecoin-ffi +++ b/extern/filecoin-ffi @@ -1 +1 @@ -Subproject commit 1e18dc4148d5f8aedc91e173b87b632635ad01ee +Subproject commit 73f84f3d3c96c260ebea01ccad6a9754a51f3f99 From 0d6eb7fefcbc59d2d3c8b69c3721b5f412494615 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 9 Feb 2022 14:13:58 -0800 Subject: [PATCH 09/27] ffi: update for fixed FVM lifetime management --- extern/filecoin-ffi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extern/filecoin-ffi b/extern/filecoin-ffi index 73f84f3d3c9..f029f279a84 160000 --- a/extern/filecoin-ffi +++ b/extern/filecoin-ffi @@ -1 +1 @@ -Subproject commit 73f84f3d3c96c260ebea01ccad6a9754a51f3f99 +Subproject commit f029f279a84dfc187d13f275edc7545ee2299cf5 From 7ef1513f9bc8d764c19675d60f68e2cf72eebe8d Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Thu, 10 Feb 2022 07:56:27 -0800 Subject: [PATCH 10/27] ffi: update fvm --- extern/filecoin-ffi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extern/filecoin-ffi b/extern/filecoin-ffi index f029f279a84..0ddea125555 160000 --- a/extern/filecoin-ffi +++ b/extern/filecoin-ffi @@ -1 +1 @@ -Subproject commit f029f279a84dfc187d13f275edc7545ee2299cf5 +Subproject commit 0ddea1255554c9ace81df3bdda4055f010d8b39d From d835cade1509758ac74eff31803e1adfa778d516 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 16 Feb 2022 17:47:25 -0800 Subject: [PATCH 11/27] chore: update FFI Updates the FVM --- extern/filecoin-ffi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extern/filecoin-ffi b/extern/filecoin-ffi index a220a540a05..d65d3770c90 160000 --- a/extern/filecoin-ffi +++ b/extern/filecoin-ffi @@ -1 +1 @@ -Subproject commit a220a540a05d6d683cf2b119b36e172da94c580b +Subproject commit d65d3770c90ebdb8b3282f11fdf10a84c3ef0355 From 393479ea69d845fe8793a970921720e6c848d7a2 Mon Sep 17 00:00:00 2001 From: Aayush Date: Tue, 15 Feb 2022 18:00:39 -0500 Subject: [PATCH 12/27] Fvm: impl VerifyConsensusFault --- chain/vm/fvm.go | 203 +++++++++++++++++++++++++++++++++++++++++++- extern/filecoin-ffi | 2 +- 2 files changed, 200 insertions(+), 5 deletions(-) diff --git a/chain/vm/fvm.go b/chain/vm/fvm.go index 1e394a20258..f98c043dd69 100644 --- a/chain/vm/fvm.go +++ b/chain/vm/fvm.go @@ -1,10 +1,16 @@ package vm import ( + "bytes" "context" + "github.com/filecoin-project/lotus/chain/state" + cbor "github.com/ipfs/go-ipld-cbor" + + "github.com/filecoin-project/go-address" "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/go-state-types/exitcode" + "github.com/filecoin-project/lotus/lib/sigs" "golang.org/x/xerrors" @@ -13,20 +19,209 @@ import ( ffi "github.com/filecoin-project/filecoin-ffi" ffi_cgo "github.com/filecoin-project/filecoin-ffi/cgo" + "github.com/filecoin-project/lotus/chain/actors/adt" + "github.com/filecoin-project/lotus/chain/actors/builtin/miner" "github.com/filecoin-project/lotus/chain/types" "github.com/ipfs/go-cid" ) var _ VMI = (*FVM)(nil) +var _ ffi_cgo.Externs = (*FvmExtern)(nil) type FvmExtern struct { Rand blockstore.Blockstore + epoch abi.ChainEpoch + lbState LookbackStateGetter + base cid.Cid +} + +// Similar to the one in syscalls.go used by the Lotus VM, except it never errors +// Errors are logged and "no fault" is returned, which is functionally what go-actors does anyway +func (x *FvmExtern) VerifyConsensusFault(ctx context.Context, a, b, extra []byte) *ffi_cgo.ConsensusFaultWithGas { + ret := &ffi_cgo.ConsensusFaultWithGas{ + // TODO: is this gonna be a problem on the receiving end? should we return address.NewIDAddress(0) instead? + Target: address.Undef, + Type: ffi_cgo.ConsensusFaultNone, + } + + // Note that block syntax is not validated. Any validly signed block will be accepted pursuant to the below conditions. + // Whether or not it could ever have been accepted in a chain is not checked/does not matter here. + // for that reason when checking block parent relationships, rather than instantiating a Tipset to do so + // (which runs a syntactic check), we do it directly on the CIDs. + + // (0) cheap preliminary checks + + // can blocks be decoded properly? + var blockA, blockB types.BlockHeader + if decodeErr := blockA.UnmarshalCBOR(bytes.NewReader(a)); decodeErr != nil { + log.Info("invalid consensus fault: cannot decode first block header: %w", decodeErr) + return ret + } + + if decodeErr := blockB.UnmarshalCBOR(bytes.NewReader(b)); decodeErr != nil { + log.Info("invalid consensus fault: cannot decode second block header: %w", decodeErr) + return ret + } + + // Commented out from the Lotus VM code: FvmExtern only supports v14 and onwards + // workaround chain halt + //if build.IsNearUpgrade(blockA.Height, build.UpgradeOrangeHeight) { + // return nil, xerrors.Errorf("consensus reporting disabled around Upgrade Orange") + //} + //if build.IsNearUpgrade(blockB.Height, build.UpgradeOrangeHeight) { + // return nil, xerrors.Errorf("consensus reporting disabled around Upgrade Orange") + //} + + // are blocks the same? + if blockA.Cid().Equals(blockB.Cid()) { + log.Info("invalid consensus fault: submitted blocks are the same") + return ret + } + // (1) check conditions necessary to any consensus fault + + // were blocks mined by same miner? + if blockA.Miner != blockB.Miner { + log.Info("invalid consensus fault: blocks not mined by the same miner") + return ret + } + + ret.Target = blockA.Miner + + // block a must be earlier or equal to block b, epoch wise (ie at least as early in the chain). + if blockB.Height < blockA.Height { + log.Info("invalid consensus fault: first block must not be of higher height than second") + return ret + } + + ret.Epoch = blockB.Height + + faultType := ffi_cgo.ConsensusFaultNone + + // (2) check for the consensus faults themselves + // (a) double-fork mining fault + if blockA.Height == blockB.Height { + faultType = ffi_cgo.ConsensusFaultDoubleForkMining + } + + // (b) time-offset mining fault + // strictly speaking no need to compare heights based on double fork mining check above, + // but at same height this would be a different fault. + if types.CidArrsEqual(blockA.Parents, blockB.Parents) && blockA.Height != blockB.Height { + faultType = ffi_cgo.ConsensusFaultTimeOffsetMining + } + + // (c) parent-grinding fault + // Here extra is the "witness", a third block that shows the connection between A and B as + // A's sibling and B's parent. + // Specifically, since A is of lower height, it must be that B was mined omitting A from its tipset + // + // B + // | + // [A, C] + var blockC types.BlockHeader + if len(extra) > 0 { + if decodeErr := blockC.UnmarshalCBOR(bytes.NewReader(extra)); decodeErr != nil { + log.Info("invalid consensus fault: cannot decode extra: %w", decodeErr) + // just to match Lotus VM consensus, zero out any already-set faults + faultType = ffi_cgo.ConsensusFaultNone + return ret + } + + if types.CidArrsEqual(blockA.Parents, blockC.Parents) && blockA.Height == blockC.Height && + types.CidArrsContains(blockB.Parents, blockC.Cid()) && !types.CidArrsContains(blockB.Parents, blockA.Cid()) { + faultType = ffi_cgo.ConsensusFaultParentGrinding + } + } + + // (3) return if no consensus fault by now + if faultType == ffi_cgo.ConsensusFaultNone { + log.Info("invalid consensus fault: no fault detected") + return ret + } + + // else + // (4) expensive final checks + + // check blocks are properly signed by their respective miner + // note we do not need to check extra's: it is a parent to block b + // which itself is signed, so it was willingly included by the miner + gasUsed, sigErr := x.VerifyBlockSig(ctx, &blockA) + ret.GasUsed += gasUsed + if sigErr != nil { + log.Info("invalid consensus fault: cannot verify first block sig: %w", sigErr) + return ret + } + + gasUsed, sigErr = x.VerifyBlockSig(ctx, &blockB) + ret.GasUsed += gasUsed + if sigErr != nil { + log.Info("invalid consensus fault: cannot verify second block sig: %w", sigErr) + return ret + } + + ret.Type = faultType + + return ret +} + +func (x *FvmExtern) VerifyBlockSig(ctx context.Context, blk *types.BlockHeader) (int64, error) { + waddr, gasUsed, err := x.workerKeyAtLookback(ctx, blk.Miner, blk.Height) + if err != nil { + return gasUsed, err + } + + return gasUsed, sigs.CheckBlockSignature(ctx, blk, waddr) } -func (x *FvmExtern) VerifyConsensusFault(ctx context.Context, h1, h2, extra []byte) (*ffi_cgo.ConsensusFault, error) { - // TODO - panic("unimplemented") +func (x *FvmExtern) workerKeyAtLookback(ctx context.Context, minerId address.Address, height abi.ChainEpoch) (address.Address, int64, error) { + // Commented out from the Lotus VM code: FvmExtern only supports v14 and onwards + //if x.networkVersion >= network.Version7 && height < x.epoch-policy.ChainFinality { + // return address.Undef, xerrors.Errorf("cannot get worker key (currEpoch %d, height %d)", ss.epoch, height) + //} + + gasUsed := int64(0) + gasAdder := func(gc GasCharge) { + // technically not overflow safe, but that's fine + gasUsed += gc.Total() + } + + cstWithoutGas := cbor.NewCborStore(x.Blockstore) + cbb := &gasChargingBlocks{gasAdder, PricelistByEpoch(x.epoch), x.Blockstore} + cstWithGas := cbor.NewCborStore(cbb) + + lbState, err := x.lbState(ctx, height) + if err != nil { + return address.Undef, gasUsed, err + } + // get appropriate miner actor + act, err := lbState.GetActor(minerId) + if err != nil { + return address.Undef, gasUsed, err + } + + // use that to get the miner state + mas, err := miner.Load(adt.WrapStore(ctx, cstWithGas), act) + if err != nil { + return address.Undef, gasUsed, err + } + + info, err := mas.Info() + if err != nil { + return address.Undef, gasUsed, err + } + + stateTree, err := state.LoadStateTree(cstWithoutGas, x.base) + if err != nil { + return address.Undef, gasUsed, err + } + + raddr, err := ResolveToKeyAddr(stateTree, cstWithGas, info.Worker) + if err != nil { + return address.Undef, gasUsed, err + } + + return raddr, gasUsed, nil } type FVM struct { @@ -35,7 +230,7 @@ type FVM struct { func NewFVM(ctx context.Context, opts *VMOpts) (*FVM, error) { fvm, err := ffi.CreateFVM(0, - &FvmExtern{Rand: opts.Rand, Blockstore: opts.Bstore}, + &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, ) if err != nil { diff --git a/extern/filecoin-ffi b/extern/filecoin-ffi index d65d3770c90..9ff2301105f 160000 --- a/extern/filecoin-ffi +++ b/extern/filecoin-ffi @@ -1 +1 @@ -Subproject commit d65d3770c90ebdb8b3282f11fdf10a84c3ef0355 +Subproject commit 9ff2301105fcf25101f1fcda52e6417f3e2ca60b From 5be125ad1afe01ef6f3eff58eca9091623571bf5 Mon Sep 17 00:00:00 2001 From: Aayush Date: Wed, 16 Feb 2022 23:21:06 -0500 Subject: [PATCH 13/27] address review feedback --- chain/vm/fvm.go | 68 +++++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 42 deletions(-) diff --git a/chain/vm/fvm.go b/chain/vm/fvm.go index f98c043dd69..962b27be6c3 100644 --- a/chain/vm/fvm.go +++ b/chain/vm/fvm.go @@ -4,6 +4,8 @@ import ( "bytes" "context" + "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/lotus/chain/state" cbor "github.com/ipfs/go-ipld-cbor" @@ -36,13 +38,12 @@ type FvmExtern struct { base cid.Cid } -// Similar to the one in syscalls.go used by the Lotus VM, except it never errors +// VerifyConsensusFault is similar to the one in syscalls.go used by the Lotus VM, except it never errors // Errors are logged and "no fault" is returned, which is functionally what go-actors does anyway -func (x *FvmExtern) VerifyConsensusFault(ctx context.Context, a, b, extra []byte) *ffi_cgo.ConsensusFaultWithGas { - ret := &ffi_cgo.ConsensusFaultWithGas{ - // TODO: is this gonna be a problem on the receiving end? should we return address.NewIDAddress(0) instead? - Target: address.Undef, - Type: ffi_cgo.ConsensusFaultNone, +func (x *FvmExtern) VerifyConsensusFault(ctx context.Context, a, b, extra []byte) (*ffi_cgo.ConsensusFault, int64) { + totalGas := int64(0) + ret := &ffi_cgo.ConsensusFault{ + Type: ffi_cgo.ConsensusFaultNone, } // Note that block syntax is not validated. Any validly signed block will be accepted pursuant to the below conditions. @@ -56,42 +57,31 @@ func (x *FvmExtern) VerifyConsensusFault(ctx context.Context, a, b, extra []byte var blockA, blockB types.BlockHeader if decodeErr := blockA.UnmarshalCBOR(bytes.NewReader(a)); decodeErr != nil { log.Info("invalid consensus fault: cannot decode first block header: %w", decodeErr) - return ret + return ret, totalGas } if decodeErr := blockB.UnmarshalCBOR(bytes.NewReader(b)); decodeErr != nil { log.Info("invalid consensus fault: cannot decode second block header: %w", decodeErr) - return ret + return ret, totalGas } - // Commented out from the Lotus VM code: FvmExtern only supports v14 and onwards - // workaround chain halt - //if build.IsNearUpgrade(blockA.Height, build.UpgradeOrangeHeight) { - // return nil, xerrors.Errorf("consensus reporting disabled around Upgrade Orange") - //} - //if build.IsNearUpgrade(blockB.Height, build.UpgradeOrangeHeight) { - // return nil, xerrors.Errorf("consensus reporting disabled around Upgrade Orange") - //} - // are blocks the same? if blockA.Cid().Equals(blockB.Cid()) { log.Info("invalid consensus fault: submitted blocks are the same") - return ret + return ret, totalGas } // (1) check conditions necessary to any consensus fault // were blocks mined by same miner? if blockA.Miner != blockB.Miner { log.Info("invalid consensus fault: blocks not mined by the same miner") - return ret + return ret, totalGas } - ret.Target = blockA.Miner - // block a must be earlier or equal to block b, epoch wise (ie at least as early in the chain). if blockB.Height < blockA.Height { log.Info("invalid consensus fault: first block must not be of higher height than second") - return ret + return ret, totalGas } ret.Epoch = blockB.Height @@ -123,9 +113,7 @@ func (x *FvmExtern) VerifyConsensusFault(ctx context.Context, a, b, extra []byte if len(extra) > 0 { if decodeErr := blockC.UnmarshalCBOR(bytes.NewReader(extra)); decodeErr != nil { log.Info("invalid consensus fault: cannot decode extra: %w", decodeErr) - // just to match Lotus VM consensus, zero out any already-set faults - faultType = ffi_cgo.ConsensusFaultNone - return ret + return ret, totalGas } if types.CidArrsEqual(blockA.Parents, blockC.Parents) && blockA.Height == blockC.Height && @@ -137,7 +125,7 @@ func (x *FvmExtern) VerifyConsensusFault(ctx context.Context, a, b, extra []byte // (3) return if no consensus fault by now if faultType == ffi_cgo.ConsensusFaultNone { log.Info("invalid consensus fault: no fault detected") - return ret + return ret, totalGas } // else @@ -146,23 +134,24 @@ func (x *FvmExtern) VerifyConsensusFault(ctx context.Context, a, b, extra []byte // check blocks are properly signed by their respective miner // note we do not need to check extra's: it is a parent to block b // which itself is signed, so it was willingly included by the miner - gasUsed, sigErr := x.VerifyBlockSig(ctx, &blockA) - ret.GasUsed += gasUsed + gasA, sigErr := x.VerifyBlockSig(ctx, &blockA) + totalGas += gasA if sigErr != nil { log.Info("invalid consensus fault: cannot verify first block sig: %w", sigErr) - return ret + return ret, totalGas } - gasUsed, sigErr = x.VerifyBlockSig(ctx, &blockB) - ret.GasUsed += gasUsed + gas2, sigErr := x.VerifyBlockSig(ctx, &blockB) + totalGas += gas2 if sigErr != nil { log.Info("invalid consensus fault: cannot verify second block sig: %w", sigErr) - return ret + return ret, totalGas } ret.Type = faultType - - return ret + ret.Target = blockA.Miner + + return ret, totalGas } func (x *FvmExtern) VerifyBlockSig(ctx context.Context, blk *types.BlockHeader) (int64, error) { @@ -175,11 +164,6 @@ func (x *FvmExtern) VerifyBlockSig(ctx context.Context, blk *types.BlockHeader) } func (x *FvmExtern) workerKeyAtLookback(ctx context.Context, minerId address.Address, height abi.ChainEpoch) (address.Address, int64, error) { - // Commented out from the Lotus VM code: FvmExtern only supports v14 and onwards - //if x.networkVersion >= network.Version7 && height < x.epoch-policy.ChainFinality { - // return address.Undef, xerrors.Errorf("cannot get worker key (currEpoch %d, height %d)", ss.epoch, height) - //} - gasUsed := int64(0) gasAdder := func(gc GasCharge) { // technically not overflow safe, but that's fine @@ -261,11 +245,11 @@ func (vm *FVM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet }, GasCosts: &GasOutputs{ // TODO: do the other optional fields eventually - BaseFeeBurn: abi.TokenAmount{}, - OverEstimationBurn: abi.TokenAmount{}, + BaseFeeBurn: big.Zero(), + OverEstimationBurn: big.Zero(), MinerPenalty: ret.MinerPenalty, MinerTip: ret.MinerTip, - Refund: abi.TokenAmount{}, + Refund: big.Zero(), GasRefund: 0, GasBurned: 0, }, From aad376296ea4aab180cb35981055dcc80169f0db Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 23 Feb 2022 19:22:47 +0000 Subject: [PATCH 14/27] fvm: set gas costs to nil for implicit messages This is what the lotus VM does. --- chain/vm/fvm.go | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/chain/vm/fvm.go b/chain/vm/fvm.go index 962b27be6c3..6b410ff93b1 100644 --- a/chain/vm/fvm.go +++ b/chain/vm/fvm.go @@ -277,16 +277,7 @@ func (vm *FVM) ApplyImplicitMessage(ctx context.Context, cmsg *types.Message) (* ExitCode: exitcode.ExitCode(ret.ExitCode), GasUsed: ret.GasUsed, }, - GasCosts: &GasOutputs{ - // TODO: do the other optional fields eventually - BaseFeeBurn: abi.TokenAmount{}, - OverEstimationBurn: abi.TokenAmount{}, - MinerPenalty: ret.MinerPenalty, - MinerTip: ret.MinerTip, - Refund: abi.TokenAmount{}, - GasRefund: 0, - GasBurned: 0, - }, + GasCosts: nil, // TODO: do these eventually, not consensus critical ActorErr: nil, ExecutionTrace: types.ExecutionTrace{}, From 420c5fb568b74d83146039cac39b81b69dd13c54 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 23 Feb 2022 19:23:20 +0000 Subject: [PATCH 15/27] fvm: time message execution --- chain/vm/fvm.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/chain/vm/fvm.go b/chain/vm/fvm.go index 6b410ff93b1..743e0fdeeb1 100644 --- a/chain/vm/fvm.go +++ b/chain/vm/fvm.go @@ -3,9 +3,11 @@ package vm import ( "bytes" "context" + "time" "github.com/filecoin-project/go-state-types/big" + "github.com/filecoin-project/lotus/build" "github.com/filecoin-project/lotus/chain/state" cbor "github.com/ipfs/go-ipld-cbor" @@ -150,7 +152,7 @@ func (x *FvmExtern) VerifyConsensusFault(ctx context.Context, a, b, extra []byte ret.Type = faultType ret.Target = blockA.Miner - + return ret, totalGas } @@ -227,6 +229,7 @@ func NewFVM(ctx context.Context, opts *VMOpts) (*FVM, error) { } func (vm *FVM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet, error) { + start := build.Clock.Now() msgBytes, err := cmsg.VMMessage().Serialize() if err != nil { return nil, xerrors.Errorf("serializing msg: %w", err) @@ -256,16 +259,16 @@ func (vm *FVM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet // TODO: do these eventually, not consensus critical ActorErr: nil, ExecutionTrace: types.ExecutionTrace{}, - Duration: 0, + Duration: time.Since(start), }, nil } func (vm *FVM) ApplyImplicitMessage(ctx context.Context, cmsg *types.Message) (*ApplyRet, error) { + start := build.Clock.Now() msgBytes, err := cmsg.VMMessage().Serialize() if err != nil { return nil, xerrors.Errorf("serializing msg: %w", err) } - ret, err := vm.fvm.ApplyImplicitMessage(msgBytes) if err != nil { return nil, xerrors.Errorf("applying msg: %w", err) @@ -281,7 +284,7 @@ func (vm *FVM) ApplyImplicitMessage(ctx context.Context, cmsg *types.Message) (* // TODO: do these eventually, not consensus critical ActorErr: nil, ExecutionTrace: types.ExecutionTrace{}, - Duration: 0, + Duration: time.Since(start), }, nil } From 9bb936b75cd033fe88b9233e1b7e7be90f3a1953 Mon Sep 17 00:00:00 2001 From: Aayush Date: Tue, 22 Feb 2022 22:01:21 -0500 Subject: [PATCH 16/27] chore: refactor: rename NewVM to NewLotusVM --- chain/gen/genesis/genesis.go | 4 ++-- chain/gen/genesis/miners.go | 4 ++-- chain/stmgr/forks_test.go | 6 +++--- chain/stmgr/stmgr.go | 2 +- chain/vm/vm.go | 2 +- cmd/lotus-sim/simulation/blockbuilder/blockbuilder.go | 2 +- conformance/driver.go | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/chain/gen/genesis/genesis.go b/chain/gen/genesis/genesis.go index 6ab101e7893..bb3d7d47792 100644 --- a/chain/gen/genesis/genesis.go +++ b/chain/gen/genesis/genesis.go @@ -494,9 +494,9 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, sys vm.Sysca NetworkVersion: nv, BaseFee: types.NewInt(0), } - vm, err := vm.NewVM(ctx, &vmopt) + vm, err := vm.NewLotusVM(ctx, &vmopt) if err != nil { - return cid.Undef, xerrors.Errorf("failed to create NewVM: %w", err) + return cid.Undef, xerrors.Errorf("failed to create NewLotusVM: %w", err) } for mi, m := range template.Miners { diff --git a/chain/gen/genesis/miners.go b/chain/gen/genesis/miners.go index 2749181470c..b705c6afed7 100644 --- a/chain/gen/genesis/miners.go +++ b/chain/gen/genesis/miners.go @@ -98,9 +98,9 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal BaseFee: types.NewInt(0), } - vm, err := vm.NewVM(ctx, vmopt) + vm, err := vm.NewLotusVM(ctx, vmopt) if err != nil { - return cid.Undef, xerrors.Errorf("failed to create NewVM: %w", err) + return cid.Undef, xerrors.Errorf("failed to create NewLotusVM: %w", err) } if len(miners) == 0 { diff --git a/chain/stmgr/forks_test.go b/chain/stmgr/forks_test.go index 4fad1e4fc8f..fbf7b6785b0 100644 --- a/chain/stmgr/forks_test.go +++ b/chain/stmgr/forks_test.go @@ -167,7 +167,7 @@ func TestForkHeightTriggers(t *testing.T) { inv.Register(nil, testActor{}) sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (*vm.VM, error) { - nvm, err := vm.NewVM(ctx, vmopt) + nvm, err := vm.NewLotusVM(ctx, vmopt) if err != nil { return nil, err } @@ -282,7 +282,7 @@ func testForkRefuseCall(t *testing.T, nullsBefore, nullsAfter int) { inv.Register(nil, testActor{}) sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (*vm.VM, error) { - nvm, err := vm.NewVM(ctx, vmopt) + nvm, err := vm.NewLotusVM(ctx, vmopt) if err != nil { return nil, err } @@ -501,7 +501,7 @@ func TestForkPreMigration(t *testing.T) { inv.Register(nil, testActor{}) sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (*vm.VM, error) { - nvm, err := vm.NewVM(ctx, vmopt) + nvm, err := vm.NewLotusVM(ctx, vmopt) if err != nil { return nil, err } diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index 45dd52ec88b..ed007b756ff 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -142,7 +142,7 @@ func NewStateManager(cs *store.ChainStore, exec Executor, sys vm.SyscallBuilder, latestVersion: lastVersion, stateMigrations: stateMigrations, expensiveUpgrades: expensiveUpgrades, - newVM: vm.NewVM, + newVM: vm.NewLotusVM, Syscalls: sys, cs: cs, tsExec: exec, diff --git a/chain/vm/vm.go b/chain/vm/vm.go index 3e2b76fe61c..ca9855b104b 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -234,7 +234,7 @@ type VMOpts struct { LookbackState LookbackStateGetter } -func NewVM(ctx context.Context, opts *VMOpts) (*VM, error) { +func NewLotusVM(ctx context.Context, opts *VMOpts) (*VM, error) { buf := blockstore.NewBuffered(opts.Bstore) cst := cbor.NewCborStore(buf) state, err := state.LoadStateTree(cst, opts.StateBase) diff --git a/cmd/lotus-sim/simulation/blockbuilder/blockbuilder.go b/cmd/lotus-sim/simulation/blockbuilder/blockbuilder.go index fb822eb6e77..7aaaf0ec7c6 100644 --- a/cmd/lotus-sim/simulation/blockbuilder/blockbuilder.go +++ b/cmd/lotus-sim/simulation/blockbuilder/blockbuilder.go @@ -92,7 +92,7 @@ func NewBlockBuilder(ctx context.Context, logger *zap.SugaredLogger, sm *stmgr.S BaseFee: abi.NewTokenAmount(0), LookbackState: stmgr.LookbackStateGetterForTipset(sm, parentTs), } - bb.vm, err = vm.NewVM(bb.ctx, vmopt) + bb.vm, err = vm.NewLotusVM(bb.ctx, vmopt) if err != nil { return nil, err } diff --git a/conformance/driver.go b/conformance/driver.go index a065d15305d..6af4372d2ec 100644 --- a/conformance/driver.go +++ b/conformance/driver.go @@ -160,7 +160,7 @@ func (d *Driver) ExecuteTipset(bs blockstore.Blockstore, ds ds.Batching, params return big.Zero(), nil } - return vm.NewVM(ctx, vmopt) + return vm.NewLotusVM(ctx, vmopt) }) postcid, receiptsroot, err := tse.ApplyBlocks(context.Background(), @@ -226,7 +226,7 @@ func (d *Driver) ExecuteMessage(bs blockstore.Blockstore, params ExecuteMessageP NetworkVersion: params.NetworkVersion, } - lvm, err := vm.NewVM(context.TODO(), vmOpts) + lvm, err := vm.NewLotusVM(context.TODO(), vmOpts) if err != nil { return nil, cid.Undef, err } From b6682f4bbe24cf398c65f0f1aa201cfeed081203 Mon Sep 17 00:00:00 2001 From: Aayush Date: Tue, 22 Feb 2022 22:43:14 -0500 Subject: [PATCH 17/27] feat: use either lotus vm or fvm consistently --- chain/stmgr/call.go | 14 ++++++++++++-- chain/stmgr/stmgr.go | 10 +++++----- chain/vm/vmi.go | 9 +++++++++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/chain/stmgr/call.go b/chain/stmgr/call.go index 31639701dad..955e0bcc895 100644 --- a/chain/stmgr/call.go +++ b/chain/stmgr/call.go @@ -112,7 +112,12 @@ func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types. ) } - fromActor, err := vmi.StateTree().GetActor(msg.From) + stTree, err := sm.StateTree(bstate) + if err != nil { + return nil, err + } + + fromActor, err := stTree.GetActor(msg.From) if err != nil { return nil, xerrors.Errorf("call raw get actor: %s", err) } @@ -219,7 +224,12 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, pri } } - fromActor, err := vmi.StateTree().GetActor(msg.From) + stTree, err := sm.StateTree(state) + if err != nil { + return nil, err + } + + fromActor, err := stTree.GetActor(msg.From) if err != nil { return nil, xerrors.Errorf("call raw get actor: %s", err) } diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index ed007b756ff..fd58af8b269 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -84,7 +84,7 @@ type StateManager struct { compWait map[string]chan struct{} stlk sync.Mutex genesisMsigLk sync.Mutex - newVM func(context.Context, *vm.VMOpts) (*vm.VM, error) + newVM func(context.Context, *vm.VMOpts) (vm.VMI, error) Syscalls vm.SyscallBuilder preIgnitionVesting []msig0.State postIgnitionVesting []msig0.State @@ -142,7 +142,7 @@ func NewStateManager(cs *store.ChainStore, exec Executor, sys vm.SyscallBuilder, latestVersion: lastVersion, stateMigrations: stateMigrations, expensiveUpgrades: expensiveUpgrades, - newVM: vm.NewLotusVM, + newVM: vm.NewVM, Syscalls: sys, cs: cs, tsExec: exec, @@ -347,12 +347,12 @@ func (sm *StateManager) ValidateChain(ctx context.Context, ts *types.TipSet) err return nil } -func (sm *StateManager) SetVMConstructor(nvm func(context.Context, *vm.VMOpts) (*vm.VM, error)) { +func (sm *StateManager) SetVMConstructor(nvm func(context.Context, *vm.VMOpts) (vm.VMI, error)) { sm.newVM = nvm } -func (sm *StateManager) VMConstructor() func(context.Context, *vm.VMOpts) (*vm.VM, error) { - return func(ctx context.Context, opts *vm.VMOpts) (*vm.VM, error) { +func (sm *StateManager) VMConstructor() func(context.Context, *vm.VMOpts) (vm.VMI, error) { + return func(ctx context.Context, opts *vm.VMOpts) (vm.VMI, error) { return sm.newVM(ctx, opts) } } diff --git a/chain/vm/vmi.go b/chain/vm/vmi.go index 4903354d221..b180f84f20a 100644 --- a/chain/vm/vmi.go +++ b/chain/vm/vmi.go @@ -2,6 +2,7 @@ package vm import ( "context" + "os" "github.com/filecoin-project/lotus/chain/types" "github.com/ipfs/go-cid" @@ -12,3 +13,11 @@ type VMI interface { ApplyImplicitMessage(ctx context.Context, msg *types.Message) (*ApplyRet, error) Flush(ctx context.Context) (cid.Cid, error) } + +func NewVM(ctx context.Context, opts *VMOpts) (VMI, error) { + if os.Getenv("LOTUS_USE_FVM_DOESNT_WORK_YET") == "1" { + return NewFVM(ctx, opts) + } + + return NewLotusVM(ctx, opts) +} From d58babe32cd24ef06da10e91e7b101ecb1f501a5 Mon Sep 17 00:00:00 2001 From: Aayush Date: Wed, 23 Feb 2022 18:17:05 -0500 Subject: [PATCH 18/27] fix: set FilVested when constructing VmOpts --- chain/gen/genesis/genesis.go | 3 ++- chain/gen/genesis/miners.go | 3 ++- chain/stmgr/call.go | 12 ++++++++++++ chain/stmgr/utils.go | 6 ++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/chain/gen/genesis/genesis.go b/chain/gen/genesis/genesis.go index bb3d7d47792..78b06637ce4 100644 --- a/chain/gen/genesis/genesis.go +++ b/chain/gen/genesis/genesis.go @@ -491,8 +491,9 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, sys vm.Sysca Actors: filcns.NewActorRegistry(), Syscalls: mkFakedSigSyscalls(sys), CircSupplyCalc: csc, + FilVested: big.Zero(), NetworkVersion: nv, - BaseFee: types.NewInt(0), + BaseFee: big.Zero(), } vm, err := vm.NewLotusVM(ctx, &vmopt) if err != nil { diff --git a/chain/gen/genesis/miners.go b/chain/gen/genesis/miners.go index b705c6afed7..93861e6812b 100644 --- a/chain/gen/genesis/miners.go +++ b/chain/gen/genesis/miners.go @@ -95,7 +95,8 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal Syscalls: mkFakedSigSyscalls(sys), CircSupplyCalc: csc, NetworkVersion: nv, - BaseFee: types.NewInt(0), + BaseFee: big.Zero(), + FilVested: big.Zero(), } vm, err := vm.NewLotusVM(ctx, vmopt) diff --git a/chain/stmgr/call.go b/chain/stmgr/call.go index 955e0bcc895..fd5f7cd05aa 100644 --- a/chain/stmgr/call.go +++ b/chain/stmgr/call.go @@ -72,6 +72,11 @@ func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types. return nil, fmt.Errorf("failed to handle fork: %w", err) } + filVested, err := sm.GetFilVested(ctx, pheight+1) + if err != nil { + return nil, err + } + vmopt := &vm.VMOpts{ StateBase: bstate, Epoch: pheight + 1, @@ -82,6 +87,7 @@ func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types. CircSupplyCalc: sm.GetVMCirculatingSupply, NetworkVersion: sm.GetNetworkVersion(ctx, pheight+1), BaseFee: types.NewInt(0), + FilVested: filVested, LookbackState: LookbackStateGetterForTipset(sm, ts), } @@ -201,6 +207,11 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, pri ) } + filVested, err := sm.GetFilVested(ctx, ts.Height()+1) + if err != nil { + return nil, err + } + vmopt := &vm.VMOpts{ StateBase: state, Epoch: ts.Height() + 1, @@ -211,6 +222,7 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, pri CircSupplyCalc: sm.GetVMCirculatingSupply, NetworkVersion: sm.GetNetworkVersion(ctx, ts.Height()+1), BaseFee: ts.Blocks()[0].ParentBaseFee, + FilVested: filVested, LookbackState: LookbackStateGetterForTipset(sm, ts), } vmi, err := sm.newVM(ctx, vmopt) diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 2a84c777b3a..49dd4700a21 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -79,6 +79,11 @@ func ComputeState(ctx context.Context, sm *StateManager, height abi.ChainEpoch, // future. It's not guaranteed to be accurate... but that's fine. } + filVested, err := sm.GetFilVested(ctx, height) + if err != nil { + return cid.Undef, nil, err + } + r := rand.NewStateRand(sm.cs, ts.Cids(), sm.beacon, sm.GetNetworkVersion) vmopt := &vm.VMOpts{ StateBase: base, @@ -90,6 +95,7 @@ func ComputeState(ctx context.Context, sm *StateManager, height abi.ChainEpoch, CircSupplyCalc: sm.GetVMCirculatingSupply, NetworkVersion: sm.GetNetworkVersion(ctx, height), BaseFee: ts.Blocks()[0].ParentBaseFee, + FilVested: filVested, LookbackState: LookbackStateGetterForTipset(sm, ts), } vmi, err := sm.newVM(ctx, vmopt) From 2ba34add2a0bc5d39067477f74f42f1a848401f5 Mon Sep 17 00:00:00 2001 From: Aayush Date: Thu, 24 Feb 2022 12:19:59 -0500 Subject: [PATCH 19/27] stmgr: call needs to flush VM before fetching nonce --- chain/stmgr/call.go | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/chain/stmgr/call.go b/chain/stmgr/call.go index fd5f7cd05aa..fb7f33d0347 100644 --- a/chain/stmgr/call.go +++ b/chain/stmgr/call.go @@ -5,6 +5,12 @@ import ( "errors" "fmt" + cbor "github.com/ipfs/go-ipld-cbor" + + "github.com/filecoin-project/lotus/chain/state" + + "github.com/filecoin-project/lotus/blockstore" + "github.com/filecoin-project/lotus/chain/rand" "github.com/filecoin-project/go-address" @@ -64,6 +70,7 @@ func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types. pheight = ts.Height() - 1 } + vmHeight := pheight + 1 bstate := ts.ParentState() // Run the (not expensive) migration. @@ -72,14 +79,14 @@ func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types. return nil, fmt.Errorf("failed to handle fork: %w", err) } - filVested, err := sm.GetFilVested(ctx, pheight+1) + filVested, err := sm.GetFilVested(ctx, vmHeight) if err != nil { return nil, err } vmopt := &vm.VMOpts{ StateBase: bstate, - Epoch: pheight + 1, + Epoch: vmHeight, Rand: rand.NewStateRand(sm.cs, ts.Cids(), sm.beacon, sm.GetNetworkVersion), Bstore: sm.cs.StateBlockstore(), Actors: sm.tsExec.NewActorRegistry(), @@ -186,13 +193,15 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, pri } } - state, _, err := sm.TipSetState(ctx, ts) + vmHeight := ts.Height() + 1 + + stateCid, _, err := sm.TipSetState(ctx, ts) if err != nil { return nil, xerrors.Errorf("computing tipset state: %w", err) } // Technically, the tipset we're passing in here should be ts+1, but that may not exist. - state, err = sm.HandleStateForks(ctx, state, ts.Height(), nil, ts) + stateCid, err = sm.HandleStateForks(ctx, stateCid, ts.Height(), nil, ts) if err != nil { return nil, fmt.Errorf("failed to handle fork: %w", err) } @@ -207,16 +216,17 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, pri ) } - filVested, err := sm.GetFilVested(ctx, ts.Height()+1) + filVested, err := sm.GetFilVested(ctx, vmHeight) if err != nil { return nil, err } + buffStore := blockstore.NewBuffered(sm.cs.StateBlockstore()) vmopt := &vm.VMOpts{ - StateBase: state, - Epoch: ts.Height() + 1, + StateBase: stateCid, + Epoch: vmHeight, Rand: r, - Bstore: sm.cs.StateBlockstore(), + Bstore: buffStore, Actors: sm.tsExec.NewActorRegistry(), Syscalls: sm.Syscalls, CircSupplyCalc: sm.GetVMCirculatingSupply, @@ -236,9 +246,14 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, pri } } - stTree, err := sm.StateTree(state) + stateCid, err = vmi.Flush(ctx) if err != nil { - return nil, err + return nil, xerrors.Errorf("flushing vm: %w", err) + } + + stTree, err := state.LoadStateTree(cbor.NewCborStore(buffStore), stateCid) + if err != nil { + return nil, xerrors.Errorf("loading state tree: %w", err) } fromActor, err := stTree.GetActor(msg.From) From d2054e8653bad72bce6ca429cebcc5908e4afe10 Mon Sep 17 00:00:00 2001 From: Aayush Date: Fri, 4 Mar 2022 13:52:41 -0500 Subject: [PATCH 20/27] FVM: support nv15 --- chain/consensus/filcns/compute_state.go | 12 ++++++------ chain/stmgr/forks_test.go | 6 +++--- chain/vm/fvm.go | 19 ++++++++++++++++++- conformance/driver.go | 2 +- extern/filecoin-ffi | 2 +- 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/chain/consensus/filcns/compute_state.go b/chain/consensus/filcns/compute_state.go index 929ac9f2fd6..5c22813adac 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 fbf7b6785b0..d85aa810f72 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 743e0fdeeb1..c8f8a0d9e19 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 6af4372d2ec..0a24f07ef15 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 9ff2301105f..084ee8673f6 160000 --- a/extern/filecoin-ffi +++ b/extern/filecoin-ffi @@ -1 +1 @@ -Subproject commit 9ff2301105fcf25101f1fcda52e6417f3e2ca60b +Subproject commit 084ee8673f6487c71b60996e6d8d6c5fa2cf04ab From 05fa9c81deab06d026088d79d4596aec80c8e2d4 Mon Sep 17 00:00:00 2001 From: Aayush Date: Sat, 12 Mar 2022 11:03:43 -0500 Subject: [PATCH 21/27] Rename FVM envvar to LOTUS_USE_FVM_EXPERIMENTAL --- chain/consensus/filcns/compute_state.go | 2 +- chain/vm/vmi.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/chain/consensus/filcns/compute_state.go b/chain/consensus/filcns/compute_state.go index 5c22813adac..addf641ed69 100644 --- a/chain/consensus/filcns/compute_state.go +++ b/chain/consensus/filcns/compute_state.go @@ -109,7 +109,7 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, sm *stmgr.StateManager LookbackState: stmgr.LookbackStateGetterForTipset(sm, ts), } - if os.Getenv("LOTUS_USE_FVM_DOESNT_WORK_YET") == "1" { + if os.Getenv("LOTUS_USE_FVM_EXPERIMENTAL") == "1" { filVested, err := sm.GetFilVested(ctx, e) if err != nil { return nil, err diff --git a/chain/vm/vmi.go b/chain/vm/vmi.go index b180f84f20a..ee7fd046cae 100644 --- a/chain/vm/vmi.go +++ b/chain/vm/vmi.go @@ -15,7 +15,7 @@ type VMI interface { } func NewVM(ctx context.Context, opts *VMOpts) (VMI, error) { - if os.Getenv("LOTUS_USE_FVM_DOESNT_WORK_YET") == "1" { + if os.Getenv("LOTUS_USE_FVM_EXPERIMENTAL") == "1" { return NewFVM(ctx, opts) } From 1bf40ad9df6a2638361d04b9b47c54516e475e29 Mon Sep 17 00:00:00 2001 From: Aayush Date: Sat, 12 Mar 2022 14:31:04 -0500 Subject: [PATCH 22/27] Fix broken go.sum --- go.sum | 1 + 1 file changed, 1 insertion(+) diff --git a/go.sum b/go.sum index a25ddb72d46..79629f1b51e 100644 --- a/go.sum +++ b/go.sum @@ -1942,6 +1942,7 @@ github.com/whyrusleeping/cbor-gen v0.0.0-20200826160007-0b9f6c5fb163/go.mod h1:f github.com/whyrusleeping/cbor-gen v0.0.0-20210118024343-169e9d70c0c2/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= github.com/whyrusleeping/cbor-gen v0.0.0-20210219115102-f37d292932f2/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= github.com/whyrusleeping/cbor-gen v0.0.0-20210303213153-67a261a1d291/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= +github.com/whyrusleeping/cbor-gen v0.0.0-20210713220151-be142a5ae1a8/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= github.com/whyrusleeping/cbor-gen v0.0.0-20220224212727-7a699437a831/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= github.com/whyrusleeping/cbor-gen v0.0.0-20220302191723-37c43cae8e14 h1:vo2wkP2ceHyGyZwFFtAabpot03EeSxxwAe57pOI9E/4= github.com/whyrusleeping/cbor-gen v0.0.0-20220302191723-37c43cae8e14/go.mod h1:fgkXqYy7bV2cFeIEOkVTZS/WjXARfBqSH6Q2qHL33hQ= From 6c51adc334336783926dcb764fd6f035413dd257 Mon Sep 17 00:00:00 2001 From: Aayush Date: Tue, 15 Mar 2022 11:07:25 -0400 Subject: [PATCH 23/27] Update FFI: fix cargo.lock --- extern/filecoin-ffi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extern/filecoin-ffi b/extern/filecoin-ffi index 084ee8673f6..5d65755dc49 160000 --- a/extern/filecoin-ffi +++ b/extern/filecoin-ffi @@ -1 +1 @@ -Subproject commit 084ee8673f6487c71b60996e6d8d6c5fa2cf04ab +Subproject commit 5d65755dc49ffb2a5282066bf1e848388dbbaada From 673f558ba5dc133ff4915f04d18698310a0fce01 Mon Sep 17 00:00:00 2001 From: Aayush Date: Tue, 15 Mar 2022 18:46:56 -0400 Subject: [PATCH 24/27] Rename vm.VMI to vm.Interface --- chain/consensus/filcns/compute_state.go | 4 ++-- chain/stmgr/forks_test.go | 6 +++--- chain/stmgr/stmgr.go | 8 ++++---- chain/vm/fvm.go | 2 +- chain/vm/vm.go | 2 +- chain/vm/vmi.go | 8 ++++++-- conformance/driver.go | 2 +- 7 files changed, 18 insertions(+), 14 deletions(-) diff --git a/chain/consensus/filcns/compute_state.go b/chain/consensus/filcns/compute_state.go index addf641ed69..687b0341aa3 100644 --- a/chain/consensus/filcns/compute_state.go +++ b/chain/consensus/filcns/compute_state.go @@ -95,7 +95,7 @@ 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) { + makeVmWithBaseStateAndEpoch := func(base cid.Cid, e abi.ChainEpoch) (vm.Interface, error) { vmopt := &vm.VMOpts{ StateBase: base, Epoch: e, @@ -122,7 +122,7 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, sm *stmgr.StateManager return sm.VMConstructor()(ctx, vmopt) } - runCron := func(vmCron vm.VMI, epoch abi.ChainEpoch) error { + runCron := func(vmCron vm.Interface, epoch abi.ChainEpoch) error { cronMsg := &types.Message{ To: cron.Address, From: builtin.SystemActorAddr, diff --git a/chain/stmgr/forks_test.go b/chain/stmgr/forks_test.go index d85aa810f72..9ee808999c6 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.VMI, error) { + sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, 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.VMI, error) { + sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, 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.VMI, error) { + sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, error) { nvm, err := vm.NewLotusVM(ctx, vmopt) if err != nil { return nil, err diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index fd58af8b269..d0bdd73e916 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -84,7 +84,7 @@ type StateManager struct { compWait map[string]chan struct{} stlk sync.Mutex genesisMsigLk sync.Mutex - newVM func(context.Context, *vm.VMOpts) (vm.VMI, error) + newVM func(context.Context, *vm.VMOpts) (vm.Interface, error) Syscalls vm.SyscallBuilder preIgnitionVesting []msig0.State postIgnitionVesting []msig0.State @@ -347,12 +347,12 @@ func (sm *StateManager) ValidateChain(ctx context.Context, ts *types.TipSet) err return nil } -func (sm *StateManager) SetVMConstructor(nvm func(context.Context, *vm.VMOpts) (vm.VMI, error)) { +func (sm *StateManager) SetVMConstructor(nvm func(context.Context, *vm.VMOpts) (vm.Interface, error)) { sm.newVM = nvm } -func (sm *StateManager) VMConstructor() func(context.Context, *vm.VMOpts) (vm.VMI, error) { - return func(ctx context.Context, opts *vm.VMOpts) (vm.VMI, error) { +func (sm *StateManager) VMConstructor() func(context.Context, *vm.VMOpts) (vm.Interface, error) { + return func(ctx context.Context, opts *vm.VMOpts) (vm.Interface, error) { return sm.newVM(ctx, opts) } } diff --git a/chain/vm/fvm.go b/chain/vm/fvm.go index c8f8a0d9e19..a1359dce299 100644 --- a/chain/vm/fvm.go +++ b/chain/vm/fvm.go @@ -31,7 +31,7 @@ import ( "github.com/ipfs/go-cid" ) -var _ VMI = (*FVM)(nil) +var _ Interface = (*FVM)(nil) var _ ffi_cgo.Externs = (*FvmExtern)(nil) type FvmExtern struct { diff --git a/chain/vm/vm.go b/chain/vm/vm.go index ca9855b104b..823682840fd 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -201,7 +201,7 @@ type ( LookbackStateGetter func(context.Context, abi.ChainEpoch) (*state.StateTree, error) ) -var _ VMI = (*VM)(nil) +var _ Interface = (*VM)(nil) type VM struct { cstate *state.StateTree diff --git a/chain/vm/vmi.go b/chain/vm/vmi.go index ee7fd046cae..4cac7284d8c 100644 --- a/chain/vm/vmi.go +++ b/chain/vm/vmi.go @@ -8,13 +8,17 @@ import ( "github.com/ipfs/go-cid" ) -type VMI interface { +type Interface interface { + // Applies the given message onto the VM's current state, returning the result of the execution ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet, error) + // Same as above but for system messages (the Cron invocation and block reward payments). + // Must NEVER fail. ApplyImplicitMessage(ctx context.Context, msg *types.Message) (*ApplyRet, error) + // Flush all buffered objects into the state store provided to the VM at construction. Flush(ctx context.Context) (cid.Cid, error) } -func NewVM(ctx context.Context, opts *VMOpts) (VMI, error) { +func NewVM(ctx context.Context, opts *VMOpts) (Interface, error) { if os.Getenv("LOTUS_USE_FVM_EXPERIMENTAL") == "1" { return NewFVM(ctx, opts) } diff --git a/conformance/driver.go b/conformance/driver.go index 0a24f07ef15..32ef8bf2109 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.VMI, error) { + sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, error) { vmopt.CircSupplyCalc = func(context.Context, abi.ChainEpoch, *state.StateTree) (abi.TokenAmount, error) { return big.Zero(), nil } From e6117c49ef228da43e8652f9f6300c63918fc93a Mon Sep 17 00:00:00 2001 From: Aayush Date: Tue, 15 Mar 2022 19:34:59 -0400 Subject: [PATCH 25/27] Address review --- chain/consensus/filcns/compute_state.go | 3 +++ chain/stmgr/call.go | 6 +++++- chain/vm/fvm.go | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/chain/consensus/filcns/compute_state.go b/chain/consensus/filcns/compute_state.go index 687b0341aa3..05d802948a6 100644 --- a/chain/consensus/filcns/compute_state.go +++ b/chain/consensus/filcns/compute_state.go @@ -110,6 +110,9 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, sm *stmgr.StateManager } if os.Getenv("LOTUS_USE_FVM_EXPERIMENTAL") == "1" { + // This is needed so that the FVM does not have to duplicate the genesis vesting schedule, one + // of the components of the circ supply calc. + // This field is NOT needed by the Lotus VM, and also NOT needed by the FVM from v15 onwards. filVested, err := sm.GetFilVested(ctx, e) if err != nil { return nil, err diff --git a/chain/stmgr/call.go b/chain/stmgr/call.go index fb7f33d0347..5db508008db 100644 --- a/chain/stmgr/call.go +++ b/chain/stmgr/call.go @@ -70,6 +70,7 @@ func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types. pheight = ts.Height() - 1 } + // Since we're simulating a future message, pretend we're applying it in the "next" tipset vmHeight := pheight + 1 bstate := ts.ParentState() @@ -127,7 +128,7 @@ func (sm *StateManager) Call(ctx context.Context, msg *types.Message, ts *types. stTree, err := sm.StateTree(bstate) if err != nil { - return nil, err + return nil, xerrors.Errorf("failed to load state tree: %w", err) } fromActor, err := stTree.GetActor(msg.From) @@ -193,6 +194,7 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, pri } } + // Since we're simulating a future message, pretend we're applying it in the "next" tipset vmHeight := ts.Height() + 1 stateCid, _, err := sm.TipSetState(ctx, ts) @@ -246,6 +248,8 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, pri } } + // We flush to get the VM's view of the state tree after applying the above messages + // This is needed to get the correct nonce from the actor state to match the VM stateCid, err = vmi.Flush(ctx) if err != nil { return nil, xerrors.Errorf("flushing vm: %w", err) diff --git a/chain/vm/fvm.go b/chain/vm/fvm.go index a1359dce299..b13f9340ab7 100644 --- a/chain/vm/fvm.go +++ b/chain/vm/fvm.go @@ -274,6 +274,7 @@ func (vm *FVM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet GasBurned: 0, }, // TODO: do these eventually, not consensus critical + // https://github.com/filecoin-project/ref-fvm/issues/318 ActorErr: nil, ExecutionTrace: types.ExecutionTrace{}, Duration: time.Since(start), @@ -299,6 +300,7 @@ func (vm *FVM) ApplyImplicitMessage(ctx context.Context, cmsg *types.Message) (* }, GasCosts: nil, // TODO: do these eventually, not consensus critical + // https://github.com/filecoin-project/ref-fvm/issues/318 ActorErr: nil, ExecutionTrace: types.ExecutionTrace{}, Duration: time.Since(start), From 9ea623e1254e61c8287eeb32ace2c64ad1ef8ae3 Mon Sep 17 00:00:00 2001 From: Aayush Date: Tue, 15 Mar 2022 19:40:17 -0400 Subject: [PATCH 26/27] Rename the Lotus VM to LegacyVM --- chain/consensus/filcns/compute_state.go | 2 +- chain/gen/genesis/genesis.go | 4 +- chain/gen/genesis/miners.go | 12 ++--- chain/gen/genesis/util.go | 2 +- chain/stmgr/forks_test.go | 6 +-- chain/vm/fvm.go | 2 +- chain/vm/gas.go | 2 +- chain/vm/gas_v0.go | 6 +-- chain/vm/invoker_test.go | 4 +- chain/vm/runtime.go | 4 +- chain/vm/vm.go | 44 +++++++++---------- chain/vm/vmi.go | 2 +- .../simulation/blockbuilder/blockbuilder.go | 12 ++--- conformance/driver.go | 4 +- node/builder_chain.go | 2 +- 15 files changed, 54 insertions(+), 54 deletions(-) diff --git a/chain/consensus/filcns/compute_state.go b/chain/consensus/filcns/compute_state.go index 05d802948a6..9b2183a5913 100644 --- a/chain/consensus/filcns/compute_state.go +++ b/chain/consensus/filcns/compute_state.go @@ -112,7 +112,7 @@ func (t *TipSetExecutor) ApplyBlocks(ctx context.Context, sm *stmgr.StateManager if os.Getenv("LOTUS_USE_FVM_EXPERIMENTAL") == "1" { // This is needed so that the FVM does not have to duplicate the genesis vesting schedule, one // of the components of the circ supply calc. - // This field is NOT needed by the Lotus VM, and also NOT needed by the FVM from v15 onwards. + // This field is NOT needed by the LegacyVM, and also NOT needed by the FVM from v15 onwards. filVested, err := sm.GetFilVested(ctx, e) if err != nil { return nil, err diff --git a/chain/gen/genesis/genesis.go b/chain/gen/genesis/genesis.go index 78b06637ce4..a1d1d01b854 100644 --- a/chain/gen/genesis/genesis.go +++ b/chain/gen/genesis/genesis.go @@ -495,9 +495,9 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, sys vm.Sysca NetworkVersion: nv, BaseFee: big.Zero(), } - vm, err := vm.NewLotusVM(ctx, &vmopt) + vm, err := vm.NewLegacyVM(ctx, &vmopt) if err != nil { - return cid.Undef, xerrors.Errorf("failed to create NewLotusVM: %w", err) + return cid.Undef, xerrors.Errorf("failed to create NewLegacyVM: %w", err) } for mi, m := range template.Miners { diff --git a/chain/gen/genesis/miners.go b/chain/gen/genesis/miners.go index 93861e6812b..fd83a7640f3 100644 --- a/chain/gen/genesis/miners.go +++ b/chain/gen/genesis/miners.go @@ -99,9 +99,9 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sys vm.Syscal FilVested: big.Zero(), } - vm, err := vm.NewLotusVM(ctx, vmopt) + vm, err := vm.NewLegacyVM(ctx, vmopt) if err != nil { - return cid.Undef, xerrors.Errorf("failed to create NewLotusVM: %w", err) + return cid.Undef, xerrors.Errorf("failed to create NewLegacyVM: %w", err) } if len(miners) == 0 { @@ -521,7 +521,7 @@ func (fr *fakeRand) GetBeaconRandomness(ctx context.Context, personalization cry return out, nil } -func currentTotalPower(ctx context.Context, vm *vm.VM, maddr address.Address) (*power0.CurrentTotalPowerReturn, error) { +func currentTotalPower(ctx context.Context, vm *vm.LegacyVM, maddr address.Address) (*power0.CurrentTotalPowerReturn, error) { pwret, err := doExecValue(ctx, vm, power.Address, maddr, big.Zero(), builtin0.MethodsPower.CurrentTotalPower, nil) if err != nil { return nil, err @@ -534,7 +534,7 @@ func currentTotalPower(ctx context.Context, vm *vm.VM, maddr address.Address) (* return &pwr, nil } -func dealWeight(ctx context.Context, vm *vm.VM, maddr address.Address, dealIDs []abi.DealID, sectorStart, sectorExpiry abi.ChainEpoch, av actors.Version) (abi.DealWeight, abi.DealWeight, error) { +func dealWeight(ctx context.Context, vm *vm.LegacyVM, maddr address.Address, dealIDs []abi.DealID, sectorStart, sectorExpiry abi.ChainEpoch, av actors.Version) (abi.DealWeight, abi.DealWeight, error) { // TODO: This hack should move to market actor wrapper if av <= actors.Version2 { params := &market0.VerifyDealsForActivationParams{ @@ -594,7 +594,7 @@ func dealWeight(ctx context.Context, vm *vm.VM, maddr address.Address, dealIDs [ return dealWeights.Sectors[0].DealWeight, dealWeights.Sectors[0].VerifiedDealWeight, nil } -func currentEpochBlockReward(ctx context.Context, vm *vm.VM, maddr address.Address, av actors.Version) (abi.StoragePower, builtin.FilterEstimate, error) { +func currentEpochBlockReward(ctx context.Context, vm *vm.LegacyVM, maddr address.Address, av actors.Version) (abi.StoragePower, builtin.FilterEstimate, error) { rwret, err := doExecValue(ctx, vm, reward.Address, maddr, big.Zero(), reward.Methods.ThisEpochReward, nil) if err != nil { return big.Zero(), builtin.FilterEstimate{}, err @@ -629,7 +629,7 @@ func currentEpochBlockReward(ctx context.Context, vm *vm.VM, maddr address.Addre return epochReward.ThisEpochBaselinePower, builtin.FilterEstimate(epochReward.ThisEpochRewardSmoothed), nil } -func circSupply(ctx context.Context, vmi *vm.VM, maddr address.Address) abi.TokenAmount { +func circSupply(ctx context.Context, vmi *vm.LegacyVM, maddr address.Address) abi.TokenAmount { unsafeVM := &vm.UnsafeVM{VM: vmi} rt := unsafeVM.MakeRuntime(ctx, &types.Message{ GasLimit: 1_000_000_000, diff --git a/chain/gen/genesis/util.go b/chain/gen/genesis/util.go index 67a4e9579a7..452bc835b26 100644 --- a/chain/gen/genesis/util.go +++ b/chain/gen/genesis/util.go @@ -21,7 +21,7 @@ func mustEnc(i cbg.CBORMarshaler) []byte { return enc } -func doExecValue(ctx context.Context, vm *vm.VM, to, from address.Address, value types.BigInt, method abi.MethodNum, params []byte) ([]byte, error) { +func doExecValue(ctx context.Context, vm *vm.LegacyVM, to, from address.Address, value types.BigInt, method abi.MethodNum, params []byte) ([]byte, error) { act, err := vm.StateTree().GetActor(from) if err != nil { return nil, xerrors.Errorf("doExec failed to get from actor (%s): %w", from, err) diff --git a/chain/stmgr/forks_test.go b/chain/stmgr/forks_test.go index 9ee808999c6..9389734298c 100644 --- a/chain/stmgr/forks_test.go +++ b/chain/stmgr/forks_test.go @@ -167,7 +167,7 @@ func TestForkHeightTriggers(t *testing.T) { inv.Register(nil, testActor{}) sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, error) { - nvm, err := vm.NewLotusVM(ctx, vmopt) + nvm, err := vm.NewLegacyVM(ctx, vmopt) if err != nil { return nil, err } @@ -282,7 +282,7 @@ func testForkRefuseCall(t *testing.T, nullsBefore, nullsAfter int) { inv.Register(nil, testActor{}) sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, error) { - nvm, err := vm.NewLotusVM(ctx, vmopt) + nvm, err := vm.NewLegacyVM(ctx, vmopt) if err != nil { return nil, err } @@ -501,7 +501,7 @@ func TestForkPreMigration(t *testing.T) { inv.Register(nil, testActor{}) sm.SetVMConstructor(func(ctx context.Context, vmopt *vm.VMOpts) (vm.Interface, error) { - nvm, err := vm.NewLotusVM(ctx, vmopt) + nvm, err := vm.NewLegacyVM(ctx, vmopt) if err != nil { return nil, err } diff --git a/chain/vm/fvm.go b/chain/vm/fvm.go index b13f9340ab7..922eb77c5ab 100644 --- a/chain/vm/fvm.go +++ b/chain/vm/fvm.go @@ -42,7 +42,7 @@ type FvmExtern struct { base cid.Cid } -// VerifyConsensusFault is similar to the one in syscalls.go used by the Lotus VM, except it never errors +// VerifyConsensusFault is similar to the one in syscalls.go used by the LegacyVM, except it never errors // Errors are logged and "no fault" is returned, which is functionally what go-actors does anyway func (x *FvmExtern) VerifyConsensusFault(ctx context.Context, a, b, extra []byte) (*ffi_cgo.ConsensusFault, int64) { totalGas := int64(0) diff --git a/chain/vm/gas.go b/chain/vm/gas.go index e75c86b9fb4..5beaae40ba5 100644 --- a/chain/vm/gas.go +++ b/chain/vm/gas.go @@ -50,7 +50,7 @@ func newGasCharge(name string, computeGas int64, storageGas int64) GasCharge { } } -// Pricelist provides prices for operations in the VM. +// Pricelist provides prices for operations in the LegacyVM. // // Note: this interface should be APPEND ONLY since last chain checkpoint type Pricelist interface { diff --git a/chain/vm/gas_v0.go b/chain/vm/gas_v0.go index 1bda6dfae21..7e0ece769d4 100644 --- a/chain/vm/gas_v0.go +++ b/chain/vm/gas_v0.go @@ -50,7 +50,7 @@ type pricelistV0 struct { // whether it succeeds or fails in application) is given by: // OnChainMessageBase + len(serialized message)*OnChainMessagePerByte // Together, these account for the cost of message propagation and validation, - // up to but excluding any actual processing by the VM. + // up to but excluding any actual processing by the LegacyVM. // This is the cost a block producer burns when including an invalid message. onChainMessageComputeBase int64 onChainMessageStorageBase int64 @@ -83,11 +83,11 @@ type pricelistV0 struct { sendInvokeMethod int64 // Gas cost for any Get operation to the IPLD store - // in the runtime VM context. + // in the runtime LegacyVM context. ipldGetBase int64 // Gas cost (Base + len*PerByte) for any Put operation to the IPLD store - // in the runtime VM context. + // in the runtime LegacyVM context. // // Note: these costs should be significantly higher than the costs for Get // operations, since they reflect not only serialization/deserialization diff --git a/chain/vm/invoker_test.go b/chain/vm/invoker_test.go index fb9910ecdd0..e75d0c854b3 100644 --- a/chain/vm/invoker_test.go +++ b/chain/vm/invoker_test.go @@ -135,7 +135,7 @@ func TestInvokerBasic(t *testing.T) { { _, aerr := code[1](&Runtime{ - vm: &VM{networkVersion: network.Version0}, + vm: &LegacyVM{networkVersion: network.Version0}, Message: &basicRtMessage{}, }, []byte{99}) if aerrors.IsFatal(aerr) { @@ -146,7 +146,7 @@ func TestInvokerBasic(t *testing.T) { { _, aerr := code[1](&Runtime{ - vm: &VM{networkVersion: network.Version7}, + vm: &LegacyVM{networkVersion: network.Version7}, Message: &basicRtMessage{}, }, []byte{99}) if aerrors.IsFatal(aerr) { diff --git a/chain/vm/runtime.go b/chain/vm/runtime.go index 0e2adc87983..c27c4537131 100644 --- a/chain/vm/runtime.go +++ b/chain/vm/runtime.go @@ -65,7 +65,7 @@ type Runtime struct { ctx context.Context - vm *VM + vm *LegacyVM state *state.StateTree height abi.ChainEpoch cst ipldcbor.IpldStore @@ -158,7 +158,7 @@ func (rt *Runtime) shimCall(f func() interface{}) (rval []byte, aerr aerrors.Act defer func() { if r := recover(); r != nil { if ar, ok := r.(aerrors.ActorError); ok { - log.Warnf("VM.Call failure in call from: %s to %s: %+v", rt.Caller(), rt.Receiver(), ar) + log.Warnf("LegacyVM.Call failure in call from: %s to %s: %+v", rt.Caller(), rt.Receiver(), ar) aerr = ar return } diff --git a/chain/vm/vm.go b/chain/vm/vm.go index 823682840fd..a0ca446a7c0 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -122,7 +122,7 @@ func (bs *gasChargingBlocks) Put(ctx context.Context, blk block.Block) error { return nil } -func (vm *VM) makeRuntime(ctx context.Context, msg *types.Message, parent *Runtime) *Runtime { +func (vm *LegacyVM) makeRuntime(ctx context.Context, msg *types.Message, parent *Runtime) *Runtime { rt := &Runtime{ ctx: ctx, vm: vm, @@ -188,7 +188,7 @@ func (vm *VM) makeRuntime(ctx context.Context, msg *types.Message, parent *Runti } type UnsafeVM struct { - VM *VM + VM *LegacyVM } func (vm *UnsafeVM) MakeRuntime(ctx context.Context, msg *types.Message) *Runtime { @@ -201,9 +201,9 @@ type ( LookbackStateGetter func(context.Context, abi.ChainEpoch) (*state.StateTree, error) ) -var _ Interface = (*VM)(nil) +var _ Interface = (*LegacyVM)(nil) -type VM struct { +type LegacyVM struct { cstate *state.StateTree cst *cbor.BasicIpldStore buf *blockstore.BufferedBlockstore @@ -234,7 +234,7 @@ type VMOpts struct { LookbackState LookbackStateGetter } -func NewLotusVM(ctx context.Context, opts *VMOpts) (*VM, error) { +func NewLegacyVM(ctx context.Context, opts *VMOpts) (*LegacyVM, error) { buf := blockstore.NewBuffered(opts.Bstore) cst := cbor.NewCborStore(buf) state, err := state.LoadStateTree(cst, opts.StateBase) @@ -247,7 +247,7 @@ func NewLotusVM(ctx context.Context, opts *VMOpts) (*VM, error) { return nil, err } - return &VM{ + return &LegacyVM{ cstate: state, cst: cst, buf: buf, @@ -276,7 +276,7 @@ type ApplyRet struct { GasCosts *GasOutputs } -func (vm *VM) send(ctx context.Context, msg *types.Message, parent *Runtime, +func (vm *LegacyVM) send(ctx context.Context, msg *types.Message, parent *Runtime, gasCharge *GasCharge, start time.Time) ([]byte, aerrors.ActorError, *Runtime) { defer atomic.AddUint64(&StatSends, 1) @@ -395,7 +395,7 @@ func checkMessage(msg *types.Message) error { return nil } -func (vm *VM) ApplyImplicitMessage(ctx context.Context, msg *types.Message) (*ApplyRet, error) { +func (vm *LegacyVM) ApplyImplicitMessage(ctx context.Context, msg *types.Message) (*ApplyRet, error) { start := build.Clock.Now() defer atomic.AddUint64(&StatApplied, 1) ret, actorErr, rt := vm.send(ctx, msg, nil, nil, start) @@ -413,7 +413,7 @@ func (vm *VM) ApplyImplicitMessage(ctx context.Context, msg *types.Message) (*Ap }, actorErr } -func (vm *VM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet, error) { +func (vm *LegacyVM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet, error) { start := build.Clock.Now() ctx, span := trace.StartSpan(ctx, "vm.ApplyMessage") defer span.End() @@ -620,7 +620,7 @@ func (vm *VM) ApplyMessage(ctx context.Context, cmsg types.ChainMsg) (*ApplyRet, }, nil } -func (vm *VM) ShouldBurn(ctx context.Context, st *state.StateTree, msg *types.Message, errcode exitcode.ExitCode) (bool, error) { +func (vm *LegacyVM) ShouldBurn(ctx context.Context, st *state.StateTree, msg *types.Message, errcode exitcode.ExitCode) (bool, error) { 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 @@ -650,7 +650,7 @@ func (vm *VM) ShouldBurn(ctx context.Context, st *state.StateTree, msg *types.Me type vmFlushKey struct{} -func (vm *VM) Flush(ctx context.Context) (cid.Cid, error) { +func (vm *LegacyVM) Flush(ctx context.Context) (cid.Cid, error) { _, span := trace.StartSpan(ctx, "vm.Flush") defer span.End() @@ -669,9 +669,9 @@ func (vm *VM) Flush(ctx context.Context) (cid.Cid, error) { return root, nil } -// Get the buffered blockstore associated with the VM. This includes any temporary blocks produced -// during this VM's execution. -func (vm *VM) ActorStore(ctx context.Context) adt.Store { +// Get the buffered blockstore associated with the LegacyVM. This includes any temporary blocks produced +// during this LegacyVM's execution. +func (vm *LegacyVM) ActorStore(ctx context.Context) adt.Store { return adt.WrapStore(ctx, vm.cst) } @@ -824,11 +824,11 @@ func copyRec(ctx context.Context, from, to blockstore.Blockstore, root cid.Cid, return nil } -func (vm *VM) StateTree() types.StateTree { +func (vm *LegacyVM) StateTree() types.StateTree { return vm.cstate } -func (vm *VM) Invoke(act *types.Actor, rt *Runtime, method abi.MethodNum, params []byte) ([]byte, aerrors.ActorError) { +func (vm *LegacyVM) Invoke(act *types.Actor, rt *Runtime, method abi.MethodNum, params []byte) ([]byte, aerrors.ActorError) { ctx, span := trace.StartSpan(rt.ctx, "vm.Invoke") defer span.End() if span.IsRecordingEvents() { @@ -851,11 +851,11 @@ func (vm *VM) Invoke(act *types.Actor, rt *Runtime, method abi.MethodNum, params return ret, nil } -func (vm *VM) SetInvoker(i *ActorRegistry) { +func (vm *LegacyVM) SetInvoker(i *ActorRegistry) { vm.areg = i } -func (vm *VM) GetCircSupply(ctx context.Context) (abi.TokenAmount, error) { +func (vm *LegacyVM) GetCircSupply(ctx context.Context) (abi.TokenAmount, error) { // Before v15, this was recalculated on each invocation as the state tree was mutated if vm.networkVersion <= network.Version14 { return vm.circSupplyCalc(ctx, vm.blockHeight, vm.cstate) @@ -864,14 +864,14 @@ func (vm *VM) GetCircSupply(ctx context.Context) (abi.TokenAmount, error) { return vm.baseCircSupply, nil } -func (vm *VM) incrementNonce(addr address.Address) error { +func (vm *LegacyVM) incrementNonce(addr address.Address) error { return vm.cstate.MutateActor(addr, func(a *types.Actor) error { a.Nonce++ return nil }) } -func (vm *VM) transfer(from, to address.Address, amt types.BigInt, networkVersion network.Version) aerrors.ActorError { +func (vm *LegacyVM) transfer(from, to address.Address, amt types.BigInt, networkVersion network.Version) aerrors.ActorError { var f *types.Actor var fromID, toID address.Address var err error @@ -959,7 +959,7 @@ func (vm *VM) transfer(from, to address.Address, amt types.BigInt, networkVersio return nil } -func (vm *VM) transferToGasHolder(addr address.Address, gasHolder *types.Actor, amt types.BigInt) error { +func (vm *LegacyVM) transferToGasHolder(addr address.Address, gasHolder *types.Actor, amt types.BigInt) error { if amt.LessThan(types.NewInt(0)) { return xerrors.Errorf("attempted to transfer negative value to gas holder") } @@ -973,7 +973,7 @@ func (vm *VM) transferToGasHolder(addr address.Address, gasHolder *types.Actor, }) } -func (vm *VM) transferFromGasHolder(addr address.Address, gasHolder *types.Actor, amt types.BigInt) error { +func (vm *LegacyVM) transferFromGasHolder(addr address.Address, gasHolder *types.Actor, amt types.BigInt) error { if amt.LessThan(types.NewInt(0)) { return xerrors.Errorf("attempted to transfer negative value from gas holder") } diff --git a/chain/vm/vmi.go b/chain/vm/vmi.go index 4cac7284d8c..9ffd8d830f9 100644 --- a/chain/vm/vmi.go +++ b/chain/vm/vmi.go @@ -23,5 +23,5 @@ func NewVM(ctx context.Context, opts *VMOpts) (Interface, error) { return NewFVM(ctx, opts) } - return NewLotusVM(ctx, opts) + return NewLegacyVM(ctx, opts) } diff --git a/cmd/lotus-sim/simulation/blockbuilder/blockbuilder.go b/cmd/lotus-sim/simulation/blockbuilder/blockbuilder.go index 7aaaf0ec7c6..392eaa7c815 100644 --- a/cmd/lotus-sim/simulation/blockbuilder/blockbuilder.go +++ b/cmd/lotus-sim/simulation/blockbuilder/blockbuilder.go @@ -44,7 +44,7 @@ type BlockBuilder struct { parentTs *types.TipSet parentSt *state.StateTree - vm *vm.VM + vm *vm.LegacyVM sm *stmgr.StateManager gasTotal int64 @@ -73,9 +73,9 @@ func NewBlockBuilder(ctx context.Context, logger *zap.SugaredLogger, sm *stmgr.S parentSt: parentSt, } - // Then we construct a VM to execute messages for gas estimation. + // Then we construct a LegacyVM to execute messages for gas estimation. // - // Most parts of this VM are "real" except: + // Most parts of this LegacyVM are "real" except: // 1. We don't charge a fee. // 2. The runtime has "fake" proof logic. // 3. We don't actually save any of the results. @@ -92,7 +92,7 @@ func NewBlockBuilder(ctx context.Context, logger *zap.SugaredLogger, sm *stmgr.S BaseFee: abi.NewTokenAmount(0), LookbackState: stmgr.LookbackStateGetterForTipset(sm, parentTs), } - bb.vm, err = vm.NewLotusVM(bb.ctx, vmopt) + bb.vm, err = vm.NewLegacyVM(bb.ctx, vmopt) if err != nil { return nil, err } @@ -190,12 +190,12 @@ func (bb *BlockBuilder) PushMessage(msg *types.Message) (*types.MessageReceipt, return &ret.MessageReceipt, nil } -// ActorStore returns the VM's current (pending) blockstore. +// ActorStore returns the LegacyVM's current (pending) blockstore. func (bb *BlockBuilder) ActorStore() adt.Store { return bb.vm.ActorStore(bb.ctx) } -// StateTree returns the VM's current (pending) state-tree. This includes any changes made by +// StateTree returns the LegacyVM's current (pending) state-tree. This includes any changes made by // successfully pushed messages. // // You probably want ParentStateTree diff --git a/conformance/driver.go b/conformance/driver.go index 32ef8bf2109..f6ca9f9db76 100644 --- a/conformance/driver.go +++ b/conformance/driver.go @@ -160,7 +160,7 @@ func (d *Driver) ExecuteTipset(bs blockstore.Blockstore, ds ds.Batching, params return big.Zero(), nil } - return vm.NewLotusVM(ctx, vmopt) + return vm.NewLegacyVM(ctx, vmopt) }) postcid, receiptsroot, err := tse.ApplyBlocks(context.Background(), @@ -226,7 +226,7 @@ func (d *Driver) ExecuteMessage(bs blockstore.Blockstore, params ExecuteMessageP NetworkVersion: params.NetworkVersion, } - lvm, err := vm.NewLotusVM(context.TODO(), vmOpts) + lvm, err := vm.NewLegacyVM(context.TODO(), vmOpts) if err != nil { return nil, cid.Undef, err } diff --git a/node/builder_chain.go b/node/builder_chain.go index afee868fd15..226ecac687e 100644 --- a/node/builder_chain.go +++ b/node/builder_chain.go @@ -65,7 +65,7 @@ var ChainNode = Options( Override(new(ffiwrapper.Verifier), ffiwrapper.ProofVerifier), Override(new(ffiwrapper.Prover), ffiwrapper.ProofProver), - // Consensus: VM + // Consensus: LegacyVM Override(new(vm.SyscallBuilder), vm.Syscalls), // Consensus: Chain storage/access From 37539ccb84625975710b682de61feb15ab4ad162 Mon Sep 17 00:00:00 2001 From: Aayush Date: Wed, 16 Mar 2022 11:58:23 -0400 Subject: [PATCH 27/27] CircSupply: Remove unused method --- chain/stmgr/supply.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/chain/stmgr/supply.go b/chain/stmgr/supply.go index 7e239d2dba3..7c55a1a0dc1 100644 --- a/chain/stmgr/supply.go +++ b/chain/stmgr/supply.go @@ -339,10 +339,6 @@ func (sm *StateManager) GetVMCirculatingSupply(ctx context.Context, height abi.C return cs.FilCirculating, err } -func (sm *StateManager) loadGenesisMsigs(ctx context.Context) error { - return nil -} - func (sm *StateManager) GetVMCirculatingSupplyDetailed(ctx context.Context, height abi.ChainEpoch, st *state.StateTree) (api.CirculatingSupply, error) { filVested, err := sm.GetFilVested(ctx, height) if err != nil {