diff --git a/chain/gen/genesis/genesis.go b/chain/gen/genesis/genesis.go index d6523cc06a4..ac22b5b1942 100644 --- a/chain/gen/genesis/genesis.go +++ b/chain/gen/genesis/genesis.go @@ -6,6 +6,8 @@ import ( "encoding/json" "fmt" + "github.com/filecoin-project/specs-actors/actors/runtime" + "github.com/ipfs/go-cid" "github.com/ipfs/go-datastore" cbor "github.com/ipfs/go-ipld-cbor" @@ -404,6 +406,10 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, stateroot ci verifNeeds := make(map[address.Address]abi.PaddedPieceSize) var sum abi.PaddedPieceSize + nwv := func(context.Context, abi.ChainEpoch) runtime.NetworkVersion { + return runtime.NetworkVersion1 + } + vmopt := vm.VMOpts{ StateBase: stateroot, Epoch: 0, @@ -411,6 +417,7 @@ func VerifyPreSealedData(ctx context.Context, cs *store.ChainStore, stateroot ci Bstore: cs.Blockstore(), Syscalls: mkFakedSigSyscalls(cs.VMSys()), CircSupplyCalc: nil, + NtwkVersion: nwv, BaseFee: types.NewInt(0), } vm, err := vm.NewVM(&vmopt) diff --git a/chain/gen/genesis/miners.go b/chain/gen/genesis/miners.go index 6322ff9a0f6..d8441c66cd4 100644 --- a/chain/gen/genesis/miners.go +++ b/chain/gen/genesis/miners.go @@ -61,6 +61,10 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid return big.Zero(), nil } + nwv := func(context.Context, abi.ChainEpoch) runtime.NetworkVersion { + return runtime.NetworkVersion1 + } + vmopt := &vm.VMOpts{ StateBase: sroot, Epoch: 0, @@ -68,6 +72,7 @@ func SetupStorageMiners(ctx context.Context, cs *store.ChainStore, sroot cid.Cid Bstore: cs.Blockstore(), Syscalls: mkFakedSigSyscalls(cs.VMSys()), CircSupplyCalc: csc, + NtwkVersion: nwv, BaseFee: types.NewInt(0), } diff --git a/chain/stmgr/call.go b/chain/stmgr/call.go index cb9ac6d6f03..4b83842b4d1 100644 --- a/chain/stmgr/call.go +++ b/chain/stmgr/call.go @@ -29,6 +29,7 @@ func (sm *StateManager) CallRaw(ctx context.Context, msg *types.Message, bstate Bstore: sm.cs.Blockstore(), Syscalls: sm.cs.VMSys(), CircSupplyCalc: sm.GetCirculatingSupply, + NtwkVersion: sm.GetNtwkVersion, BaseFee: types.NewInt(0), } @@ -130,6 +131,7 @@ func (sm *StateManager) CallWithGas(ctx context.Context, msg *types.Message, pri Bstore: sm.cs.Blockstore(), Syscalls: sm.cs.VMSys(), CircSupplyCalc: sm.GetCirculatingSupply, + NtwkVersion: sm.GetNtwkVersion, BaseFee: ts.Blocks()[0].ParentBaseFee, } vmi, err := vm.NewVM(vmopt) diff --git a/chain/stmgr/stmgr.go b/chain/stmgr/stmgr.go index 60af4006583..5679991aef6 100644 --- a/chain/stmgr/stmgr.go +++ b/chain/stmgr/stmgr.go @@ -5,6 +5,8 @@ import ( "fmt" "sync" + "github.com/filecoin-project/specs-actors/actors/runtime" + "github.com/filecoin-project/specs-actors/actors/builtin/power" "github.com/filecoin-project/specs-actors/actors/builtin/multisig" @@ -154,6 +156,7 @@ func (sm *StateManager) ApplyBlocks(ctx context.Context, parentEpoch abi.ChainEp Bstore: sm.cs.Blockstore(), Syscalls: sm.cs.VMSys(), CircSupplyCalc: sm.GetCirculatingSupply, + NtwkVersion: sm.GetNtwkVersion, BaseFee: baseFee, } @@ -1120,3 +1123,15 @@ func (sm *StateManager) GetCirculatingSupply(ctx context.Context, height abi.Cha return csi.FilCirculating, nil } + +func (sm *StateManager) GetNtwkVersion(ctx context.Context, height abi.ChainEpoch) runtime.NetworkVersion { + if build.UpgradeBreezeHeight == 0 { + return runtime.NetworkVersion1 + } + + if height <= build.UpgradeBreezeHeight { + return runtime.NetworkVersion0 + } + + return runtime.NetworkVersion1 +} diff --git a/chain/stmgr/utils.go b/chain/stmgr/utils.go index 0cb49133774..ab7f4f47231 100644 --- a/chain/stmgr/utils.go +++ b/chain/stmgr/utils.go @@ -446,6 +446,7 @@ func ComputeState(ctx context.Context, sm *StateManager, height abi.ChainEpoch, Bstore: sm.cs.Blockstore(), Syscalls: sm.cs.VMSys(), CircSupplyCalc: sm.GetCirculatingSupply, + NtwkVersion: sm.GetNtwkVersion, BaseFee: ts.Blocks()[0].ParentBaseFee, } vmi, err := vm.NewVM(vmopt) diff --git a/chain/vm/runtime.go b/chain/vm/runtime.go index b353bcb34d9..043ea3a45f4 100644 --- a/chain/vm/runtime.go +++ b/chain/vm/runtime.go @@ -56,6 +56,10 @@ type Runtime struct { lastGasCharge *types.GasTrace } +func (rt *Runtime) NetworkVersion() vmr.NetworkVersion { + return rt.vm.GetNtwkVersion(rt.ctx, rt.CurrEpoch()) +} + func (rt *Runtime) TotalFilCircSupply() abi.TokenAmount { cs, err := rt.vm.GetCircSupply(rt.ctx) if err != nil { diff --git a/chain/vm/vm.go b/chain/vm/vm.go index 92a50c5cd4e..eb6c2f354a0 100644 --- a/chain/vm/vm.go +++ b/chain/vm/vm.go @@ -7,6 +7,8 @@ import ( "reflect" "time" + "github.com/filecoin-project/specs-actors/actors/runtime" + bstore "github.com/filecoin-project/lotus/lib/blockstore" "github.com/filecoin-project/go-state-types/big" @@ -140,6 +142,7 @@ func (vm *UnsafeVM) MakeRuntime(ctx context.Context, msg *types.Message, origin } type CircSupplyCalculator func(context.Context, abi.ChainEpoch, *state.StateTree) (abi.TokenAmount, error) +type NtwkVersionGetter func(context.Context, abi.ChainEpoch) runtime.NetworkVersion type VM struct { cstate *state.StateTree @@ -150,6 +153,7 @@ type VM struct { inv *Invoker rand Rand circSupplyCalc CircSupplyCalculator + ntwkVersion NtwkVersionGetter baseFee abi.TokenAmount Syscalls SyscallBuilder @@ -162,6 +166,7 @@ type VMOpts struct { Bstore bstore.Blockstore Syscalls SyscallBuilder CircSupplyCalc CircSupplyCalculator + NtwkVersion NtwkVersionGetter BaseFee abi.TokenAmount } @@ -182,6 +187,7 @@ func NewVM(opts *VMOpts) (*VM, error) { inv: NewInvoker(), rand: opts.Rand, // TODO: Probably should be a syscall circSupplyCalc: opts.CircSupplyCalc, + ntwkVersion: opts.NtwkVersion, Syscalls: opts.Syscalls, baseFee: opts.BaseFee, }, nil @@ -716,6 +722,10 @@ func (vm *VM) SetInvoker(i *Invoker) { vm.inv = i } +func (vm *VM) GetNtwkVersion(ctx context.Context, ce abi.ChainEpoch) runtime.NetworkVersion { + return vm.ntwkVersion(ctx, ce) +} + func (vm *VM) GetCircSupply(ctx context.Context) (abi.TokenAmount, error) { return vm.circSupplyCalc(ctx, vm.blockHeight, vm.cstate) } diff --git a/go.mod b/go.mod index 86b76f50d93..2f3dc6a5495 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,7 @@ require ( github.com/filecoin-project/go-crypto v0.0.0-20191218222705-effae4ea9f03 github.com/filecoin-project/go-data-transfer v0.6.3 github.com/filecoin-project/go-fil-commcid v0.0.0-20200716160307-8f644712406f - github.com/filecoin-project/go-fil-markets v0.5.10-0.20200907031006-9d489e10498b + github.com/filecoin-project/go-fil-markets v0.6.0 github.com/filecoin-project/go-jsonrpc v0.1.2-0.20200822201400-474f4fdccc52 github.com/filecoin-project/go-multistore v0.0.3 github.com/filecoin-project/go-padreader v0.0.0-20200903213702-ed5fae088b20 @@ -39,7 +39,7 @@ require ( github.com/filecoin-project/go-statemachine v0.0.0-20200813232949-df9b130df370 github.com/filecoin-project/go-statestore v0.1.0 github.com/filecoin-project/go-storedcounter v0.0.0-20200421200003-1c99c62e8a5b - github.com/filecoin-project/specs-actors v0.9.6 + github.com/filecoin-project/specs-actors v0.9.7 github.com/filecoin-project/specs-storage v0.1.1-0.20200907031224-ed2e5cd13796 github.com/filecoin-project/statediff v0.0.1 github.com/filecoin-project/test-vectors v0.0.0-20200907193218-2c0739eccce6 diff --git a/go.sum b/go.sum index c0a367217c6..afd23c0c52e 100644 --- a/go.sum +++ b/go.sum @@ -251,8 +251,8 @@ github.com/filecoin-project/go-fil-commcid v0.0.0-20200716160307-8f644712406f h1 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-markets v0.5.6-0.20200814234959-80b1788108ac/go.mod h1:umicPCaN99ysHTiYOmwhuLxTFbOwcsI+mdw/t96vvM4= github.com/filecoin-project/go-fil-markets v0.5.8/go.mod h1:6ZX1vbZbnukbVQ8tCB/MmEizuW/bmRX7SpGAltU3KVg= -github.com/filecoin-project/go-fil-markets v0.5.10-0.20200907031006-9d489e10498b h1:Xe+ngO0+FV1JESIz9rlyzygwIEnI8M3bDvKqljdIoJA= -github.com/filecoin-project/go-fil-markets v0.5.10-0.20200907031006-9d489e10498b/go.mod h1:w0wCAf/fT7UfvJAZEMjjCQfsbwvrdjU4sN4QFLWsPrk= +github.com/filecoin-project/go-fil-markets v0.6.0 h1:gfxMweUHo4u+2BZh2Q7/7+cV0/ttikuJfhkkxLRsE2Q= +github.com/filecoin-project/go-fil-markets v0.6.0/go.mod h1:LhSFYLkjaoe0vFRKABGYyw1Jz+9jCpF1sPA7yOftLTw= github.com/filecoin-project/go-jsonrpc v0.1.2-0.20200817153016-2ea5cbaf5ec0/go.mod h1:XBBpuKIMaXIIzeqzO1iucq4GvbF8CxmXRFoezRh+Cx4= github.com/filecoin-project/go-jsonrpc v0.1.2-0.20200822201400-474f4fdccc52 h1:FXtCp0ybqdQL9knb3OGDpkNTaBbPxgkqPeWKotUwkH0= github.com/filecoin-project/go-jsonrpc v0.1.2-0.20200822201400-474f4fdccc52/go.mod h1:XBBpuKIMaXIIzeqzO1iucq4GvbF8CxmXRFoezRh+Cx4= @@ -293,6 +293,8 @@ github.com/filecoin-project/specs-actors v0.9.3/go.mod h1:YasnVUOUha0DN5wB+twl+V github.com/filecoin-project/specs-actors v0.9.4/go.mod h1:BStZQzx5x7TmCkLv0Bpa07U6cPKol6fd3w9KjMPZ6Z4= github.com/filecoin-project/specs-actors v0.9.6 h1:U3PU4jrHcmXxfEP0CC1fGETx4RrXlm5RYJeuT5eWjhI= github.com/filecoin-project/specs-actors v0.9.6/go.mod h1:wM2z+kwqYgXn5Z7scV1YHLyd1Q1cy0R8HfTIWQ0BFGU= +github.com/filecoin-project/specs-actors v0.9.7 h1:7PAZ8kdqwBdmgf/23FCkQZLCXcVu02XJrkpkhBikiA8= +github.com/filecoin-project/specs-actors v0.9.7/go.mod h1:wM2z+kwqYgXn5Z7scV1YHLyd1Q1cy0R8HfTIWQ0BFGU= github.com/filecoin-project/specs-storage v0.1.1-0.20200622113353-88a9704877ea/go.mod h1:Pr5ntAaxsh+sLG/LYiL4tKzvA83Vk5vLODYhfNwOg7k= github.com/filecoin-project/specs-storage v0.1.1-0.20200730063404-f7db367e9401/go.mod h1:Pr5ntAaxsh+sLG/LYiL4tKzvA83Vk5vLODYhfNwOg7k= github.com/filecoin-project/specs-storage v0.1.1-0.20200907031224-ed2e5cd13796 h1:dJsTPWpG2pcTeojO2pyn0c6l+x/3MZYCBgo/9d11JEk= diff --git a/node/impl/full/state.go b/node/impl/full/state.go index 3798480654c..c068bab93ac 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -1150,7 +1150,13 @@ func (a *StateAPI) StateDealProviderCollateralBounds(ctx context.Context, size a return api.DealCollateralBounds{}, xerrors.Errorf("getting total circulating supply: %w", err) } - min, max := market.DealProviderCollateralBounds(size, verified, powerState.ThisEpochQualityAdjPower, rewardState.ThisEpochBaselinePower, circ.FilCirculating) + min, max := market.DealProviderCollateralBounds(size, + verified, + powerState.TotalRawBytePower, + powerState.ThisEpochQualityAdjPower, + rewardState.ThisEpochBaselinePower, + circ.FilCirculating, + a.StateManager.GetNtwkVersion(ctx, ts.Height())) return api.DealCollateralBounds{ Min: types.BigDiv(types.BigMul(min, dealProviderCollateralNum), dealProviderCollateralDen), Max: max,