From 1f04cc1f23b1a86d79ee1a9afa59180ac1699ab5 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Thu, 16 Dec 2021 23:59:26 -0500 Subject: [PATCH] VM: Circ supply should be constant per epoch --- chain/gen/genesis/genesis.go | 6 +++++- chain/vm/vm.go | 19 ++++++++++++++----- conformance/driver.go | 8 ++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/chain/gen/genesis/genesis.go b/chain/gen/genesis/genesis.go index 29f03e2af..45387df50 100644 --- a/chain/gen/genesis/genesis.go +++ b/chain/gen/genesis/genesis.go @@ -479,6 +479,10 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, sys vm.Sysca verifNeeds := make(map[address.Address]abi.PaddedPieceSize) var sum abi.PaddedPieceSize + csc := func(context.Context, abi.ChainEpoch, *state.StateTree) (abi.TokenAmount, error) { + return big.Zero(), nil + } + vmopt := vm.VMOpts{ StateBase: stateroot, Epoch: 0, @@ -486,7 +490,7 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, sys vm.Sysca Bstore: cs.StateBlockstore(), Actors: filcns.NewActorRegistry(), Syscalls: mkFakedSigSyscalls(sys), - CircSupplyCalc: nil, + CircSupplyCalc: csc, NtwkVersion: func(_ context.Context, _ abi.ChainEpoch) network.Version { return nv }, diff --git a/chain/vm/vm.go b/chain/vm/vm.go index 16ad5e2a4..d569dbbbf 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -202,9 +202,7 @@ type ( ) type VM struct { - cstate *state.StateTree - // TODO: Is base actually used? Can we delete it? - base cid.Cid + cstate *state.StateTree cst *cbor.BasicIpldStore buf *blockstore.BufferedBlockstore blockHeight abi.ChainEpoch @@ -214,6 +212,7 @@ type VM struct { ntwkVersion NtwkVersionGetter baseFee abi.TokenAmount lbStateGet LookbackStateGetter + baseCircSupply abi.TokenAmount Syscalls SyscallBuilder } @@ -239,9 +238,13 @@ func NewVM(ctx context.Context, opts *VMOpts) (*VM, error) { return nil, err } + baseCirc, err := opts.CircSupplyCalc(ctx, opts.Epoch, state) + if err != nil { + return nil, err + } + return &VM{ cstate: state, - base: opts.StateBase, cst: cst, buf: buf, blockHeight: opts.Epoch, @@ -251,6 +254,7 @@ func NewVM(ctx context.Context, opts *VMOpts) (*VM, error) { ntwkVersion: opts.NtwkVersion, Syscalls: opts.Syscalls, baseFee: opts.BaseFee, + baseCircSupply: baseCirc, lbStateGet: opts.LookbackState, }, nil } @@ -859,7 +863,12 @@ func (vm *VM) GetNtwkVersion(ctx context.Context, ce abi.ChainEpoch) network.Ver } func (vm *VM) GetCircSupply(ctx context.Context) (abi.TokenAmount, error) { - return vm.circSupplyCalc(ctx, vm.blockHeight, vm.cstate) + // Before v15, this was recalculated on each invocation as the state tree was mutated + if vm.GetNtwkVersion(ctx, vm.blockHeight) <= network.Version14 { + return vm.circSupplyCalc(ctx, vm.blockHeight, vm.cstate) + } + + return vm.baseCircSupply, nil } func (vm *VM) incrementNonce(addr address.Address) error { diff --git a/conformance/driver.go b/conformance/driver.go index 8669089da..c6a20e359 100644 --- a/conformance/driver.go +++ b/conformance/driver.go @@ -153,6 +153,14 @@ 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) { + vmopt.CircSupplyCalc = func(context.Context, abi.ChainEpoch, *state.StateTree) (abi.TokenAmount, error) { + return big.Zero(), nil + } + + return vm.NewVM(ctx, vmopt) + }) + postcid, receiptsroot, err := tse.ApplyBlocks(context.Background(), sm, params.ParentEpoch,