From d656775a2404550df6fe58d8b1640bed2aaff3b5 Mon Sep 17 00:00:00 2001 From: Jim Pick Date: Mon, 22 Jan 2024 19:57:15 -0800 Subject: [PATCH] Updated off-chain termination calculation for network v12 Requires Lotus build on master branch with this PR: * https://github.com/filecoin-project/lotus/pull/11566 --- go.mod | 10 +++++----- go.sum | 6 ++++++ terminate/impl.go | 4 ++-- terminate/stats.go | 22 ++++++++++++++++------ util/termination.go | 3 +-- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index e69ef7c..d601a3c 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/filecoin-project/go-crypto v0.0.1 github.com/filecoin-project/go-jsonrpc v0.3.1 github.com/filecoin-project/go-state-types v0.12.8 - github.com/filecoin-project/lotus v1.25.1 + github.com/filecoin-project/lotus v1.25.3-0.20240122193923-8f73f1579334 github.com/filecoin-project/specs-actors v0.9.15 github.com/filecoin-project/specs-actors/v6 v6.0.2 github.com/filecoin-project/specs-actors/v8 v8.0.1 @@ -102,7 +102,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 // indirect github.com/libp2p/go-buffer-pool v0.1.0 // indirect github.com/libp2p/go-flow-metrics v0.1.0 // indirect - github.com/libp2p/go-libp2p v0.30.0 // indirect + github.com/libp2p/go-libp2p v0.31.1 // indirect github.com/libp2p/go-libp2p-pubsub v0.9.3 // indirect github.com/libp2p/go-msgio v0.3.0 // indirect github.com/magefile/mage v1.9.0 // indirect @@ -115,7 +115,7 @@ require ( github.com/mr-tron/base58 v1.2.0 // indirect github.com/multiformats/go-base32 v0.1.0 // indirect github.com/multiformats/go-base36 v0.2.0 // indirect - github.com/multiformats/go-multiaddr v0.11.0 // indirect + github.com/multiformats/go-multiaddr v0.12.1 // indirect github.com/multiformats/go-multiaddr-dns v0.3.1 // indirect github.com/multiformats/go-multibase v0.2.0 // indirect github.com/multiformats/go-multicodec v0.9.0 // indirect @@ -147,11 +147,11 @@ require ( go.uber.org/atomic v1.11.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.25.0 // indirect - golang.org/x/crypto v0.12.0 // indirect + golang.org/x/crypto v0.17.0 // indirect golang.org/x/mod v0.12.0 // indirect golang.org/x/net v0.14.0 // indirect golang.org/x/sync v0.3.0 // indirect - golang.org/x/sys v0.11.0 // indirect + golang.org/x/sys v0.15.0 // indirect golang.org/x/time v0.1.0 // indirect golang.org/x/tools v0.12.1-0.20230815132531-74c255bcf846 // indirect google.golang.org/protobuf v1.30.0 // indirect diff --git a/go.sum b/go.sum index bc754f9..cbd7fb6 100644 --- a/go.sum +++ b/go.sum @@ -150,6 +150,8 @@ github.com/filecoin-project/kubo-api-client v0.0.1 h1:IR1b+sm+VYxSRvbgECVv9SbhIg github.com/filecoin-project/kubo-api-client v0.0.1/go.mod h1:c36PPMIVOkKfHDwDG5U05gUlPRY9wNuh/BePwo0e+6Y= github.com/filecoin-project/lotus v1.25.1 h1:Fnr05Hax2s9SlgEh4hi8fWWkkRipdakjCWlLF8sOLio= github.com/filecoin-project/lotus v1.25.1/go.mod h1:7How7BIQEbV/2gHJBjsNQ7ynHb7zXUmtO7QYImo4L3w= +github.com/filecoin-project/lotus v1.25.3-0.20240122193923-8f73f1579334 h1:BY10vM10924FGyo1psUgpQRKCgqxLRIgwV8bHdDb9Hs= +github.com/filecoin-project/lotus v1.25.3-0.20240122193923-8f73f1579334/go.mod h1:MbE5qZ2WmoXhtDFMsIOIxkwRiJaxqaP6bii9e+Q17qQ= github.com/filecoin-project/specs-actors v0.9.4/go.mod h1:BStZQzx5x7TmCkLv0Bpa07U6cPKol6fd3w9KjMPZ6Z4= github.com/filecoin-project/specs-actors v0.9.13/go.mod h1:TS1AW/7LbG+615j4NsjMK1qlpAwaFsG9w0V2tg2gSao= github.com/filecoin-project/specs-actors v0.9.15-0.20220514164640-94e0d5e123bd/go.mod h1:pjGEe3QlWtK20ju/aFRsiArbMX6Cn8rqEhhsiCM9xYE= @@ -458,6 +460,7 @@ github.com/libp2p/go-libp2p v0.1.0/go.mod h1:6D/2OBauqLUoqcADOJpn9WbKqvaM07tDw68 github.com/libp2p/go-libp2p v0.1.1/go.mod h1:I00BRo1UuUSdpuc8Q2mN7yDF/oTUTRAX6JWpTiK9Rp8= github.com/libp2p/go-libp2p v0.30.0 h1:9EZwFtJPFBcs/yJTnP90TpN1hgrT/EsFfM+OZuwV87U= github.com/libp2p/go-libp2p v0.30.0/go.mod h1:nr2g5V7lfftwgiJ78/HrID+pwvayLyqKCEirT2Y3Byg= +github.com/libp2p/go-libp2p v0.31.1/go.mod h1:+9TCv+XySSOdaxPF1WIgTK8rXP9jBb8WbemlMCSXGsU= github.com/libp2p/go-libp2p-asn-util v0.3.0 h1:gMDcMyYiZKkocGXDQ5nsUQyquC9+H+iLEQHwOCZ7s8s= github.com/libp2p/go-libp2p-autonat v0.1.0/go.mod h1:1tLf2yXxiE/oKGtDwPYWTSYG3PtvYlJmg7NeVtPRqH8= github.com/libp2p/go-libp2p-blankhost v0.1.1/go.mod h1:pf2fvdLJPsC1FsVrNP3DUUvMzUts2dsLLBEpo1vW1ro= @@ -561,6 +564,7 @@ github.com/multiformats/go-multiaddr v0.0.4/go.mod h1:xKVEak1K9cS1VdmPZW3LSIb6lg github.com/multiformats/go-multiaddr v0.2.0/go.mod h1:0nO36NvPpyV4QzvTLi/lafl2y95ncPj0vFwVF6k6wJ4= github.com/multiformats/go-multiaddr v0.11.0 h1:XqGyJ8ufbCE0HmTDwx2kPdsrQ36AGPZNZX6s6xfJH10= github.com/multiformats/go-multiaddr v0.11.0/go.mod h1:gWUm0QLR4thQ6+ZF6SXUw8YjtwQSPapICM+NmCkxHSM= +github.com/multiformats/go-multiaddr v0.12.1/go.mod h1:7mPkiBMmLeFipt+nNSq9pHZUeJSt8lHBgH6yhj0YQzE= github.com/multiformats/go-multiaddr-dns v0.0.1/go.mod h1:9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q= github.com/multiformats/go-multiaddr-dns v0.0.2/go.mod h1:9kWcqw/Pj6FwxAwW38n/9403szc57zJPs45fmnznu3Q= github.com/multiformats/go-multiaddr-dns v0.3.1 h1:QgQgR+LQVt3NPTjbrLLpsaT2ufAA2y0Mkk+QRVJbW3A= @@ -788,6 +792,7 @@ golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0 golang.org/x/crypto v0.1.0/go.mod h1:RecgLatLF4+eUMCP1PoPZQb+cVrJcOPbHkTkbkB9sbw= golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk= golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= +golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 h1:m64FZMko/V45gv0bNmrNYoDEq8U5YUhetc9cBWKS1TQ= golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63/go.mod h1:0v4NqG35kSWCMzLaMeX+IQrlSnVE/bqGSyC2cz/9Le8= @@ -871,6 +876,7 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= diff --git a/terminate/impl.go b/terminate/impl.go index f55cffc..6d4d683 100644 --- a/terminate/impl.go +++ b/terminate/impl.go @@ -152,13 +152,13 @@ func terminateSectors( // the termination penalty calculation termFee := miner8.PledgePenaltyForTermination( s.ExpectedDayReward, - height-s.Activation, + height-s.PowerBaseEpoch, s.ExpectedStoragePledge, smoothedPow, sectorPower, smoothedRew, s.ReplacedDayReward, - s.ReplacedSectorAge, + s.PowerBaseEpoch-s.Activation, ) // the daily sector fee calculation diff --git a/terminate/stats.go b/terminate/stats.go index 37d79ed..bac37b2 100644 --- a/terminate/stats.go +++ b/terminate/stats.go @@ -5,7 +5,7 @@ import ( "math/big" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/builtin/v9/miner" + "github.com/filecoin-project/go-state-types/builtin/v12/miner" ) type SectorStats struct { @@ -25,7 +25,9 @@ type SectorStats struct { InitialPledge *big.Int ExpectedDayReward *big.Int ExpectedStoragePledge *big.Int - ReplacedSectorAge *big.Int + PowerBaseEpoch *big.Int + MinPowerBaseEpoch abi.ChainEpoch + MaxPowerBaseEpoch abi.ChainEpoch ReplacedDayReward *big.Int SectorCount int64 } @@ -48,7 +50,9 @@ func NewSectorStats() *SectorStats { InitialPledge: big.NewInt(0), ExpectedDayReward: big.NewInt(0), ExpectedStoragePledge: big.NewInt(0), - ReplacedSectorAge: big.NewInt(0), + PowerBaseEpoch: big.NewInt(0), + MinPowerBaseEpoch: abi.ChainEpoch(math.MaxInt64), + MaxPowerBaseEpoch: abi.ChainEpoch(0), ReplacedDayReward: big.NewInt(0), SectorCount: 0, } @@ -78,7 +82,9 @@ func (st *SectorStats) AddSector( InitialPledge: st.InitialPledge.Add(st.InitialPledge, s.InitialPledge.Int), ExpectedDayReward: st.ExpectedDayReward.Add(st.ExpectedDayReward, s.ExpectedDayReward.Int), ExpectedStoragePledge: st.ExpectedStoragePledge.Add(st.ExpectedStoragePledge, s.ExpectedStoragePledge.Int), - ReplacedSectorAge: st.ReplacedSectorAge.Add(st.ReplacedSectorAge, big.NewInt(int64(s.ReplacedSectorAge))), + PowerBaseEpoch: st.PowerBaseEpoch.Add(st.PowerBaseEpoch, big.NewInt(int64(s.PowerBaseEpoch))), + MinPowerBaseEpoch: min(st.MinPowerBaseEpoch, s.PowerBaseEpoch), + MaxPowerBaseEpoch: max(st.MaxPowerBaseEpoch, s.PowerBaseEpoch), ReplacedDayReward: st.ReplacedDayReward.Add(st.ReplacedDayReward, s.ReplacedDayReward.Int), SectorCount: st.SectorCount + 1, } @@ -102,7 +108,9 @@ func (st *SectorStats) Accumulate(addStats *SectorStats) *SectorStats { InitialPledge: st.InitialPledge.Add(st.InitialPledge, addStats.InitialPledge), ExpectedDayReward: st.ExpectedDayReward.Add(st.ExpectedDayReward, addStats.ExpectedDayReward), ExpectedStoragePledge: st.ExpectedStoragePledge.Add(st.ExpectedStoragePledge, addStats.ExpectedStoragePledge), - ReplacedSectorAge: st.ReplacedSectorAge.Add(st.ReplacedSectorAge, addStats.ReplacedSectorAge), + PowerBaseEpoch: st.PowerBaseEpoch.Add(st.PowerBaseEpoch, addStats.PowerBaseEpoch), + MinPowerBaseEpoch: min(st.MinPowerBaseEpoch, addStats.MinPowerBaseEpoch), + MaxPowerBaseEpoch: max(st.MaxPowerBaseEpoch, addStats.MaxPowerBaseEpoch), ReplacedDayReward: st.ReplacedDayReward.Add(st.ReplacedDayReward, addStats.ReplacedDayReward), SectorCount: st.SectorCount + addStats.SectorCount, } @@ -132,7 +140,9 @@ func (st *SectorStats) ScaleUp(sectorsCount int64, sampledSectorsCount int64) *S InitialPledge: scaleBigInt(st.InitialPledge), ExpectedDayReward: scaleBigInt(st.ExpectedDayReward), ExpectedStoragePledge: scaleBigInt(st.ExpectedStoragePledge), - ReplacedSectorAge: scaleBigInt(st.ReplacedSectorAge), + PowerBaseEpoch: scaleBigInt(st.PowerBaseEpoch), + MinPowerBaseEpoch: st.MinPowerBaseEpoch, + MaxPowerBaseEpoch: st.MaxPowerBaseEpoch, ReplacedDayReward: scaleBigInt(st.ReplacedDayReward), SectorCount: int64(float64(st.SectorCount) * float64(sectorsCount) / float64(sampledSectorsCount)), } diff --git a/util/termination.go b/util/termination.go index 0fc81cf..f0acc97 100644 --- a/util/termination.go +++ b/util/termination.go @@ -3,7 +3,7 @@ package util import ( "context" - "github.com/filecoin-project/go-state-types/builtin/v9/miner" + "github.com/filecoin-project/go-state-types/builtin/v12/miner" lotusapi "github.com/filecoin-project/lotus/api" "github.com/filecoin-project/lotus/blockstore" "github.com/filecoin-project/lotus/chain/actors/adt" @@ -29,7 +29,6 @@ func ConvertSectorType(sector *miner.SectorOnChainInfo) *miner8.SectorOnChainInf InitialPledge: sector.InitialPledge, ExpectedDayReward: sector.ExpectedDayReward, ExpectedStoragePledge: sector.ExpectedStoragePledge, - ReplacedSectorAge: sector.ReplacedSectorAge, ReplacedDayReward: sector.ReplacedDayReward, SectorKeyCID: sector.SectorKeyCID, }