Skip to content

Commit

Permalink
Updated off-chain termination calculation for network v12
Browse files Browse the repository at this point in the history
Requires Lotus build on master branch with this PR:

* filecoin-project/lotus#11566
  • Loading branch information
Jim Pick committed Jan 23, 2024
1 parent 1b52715 commit d656775
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
4 changes: 2 additions & 2 deletions terminate/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 16 additions & 6 deletions terminate/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand All @@ -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,
}
Expand Down Expand Up @@ -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)),
}
Expand Down
3 changes: 1 addition & 2 deletions util/termination.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
}
Expand Down

0 comments on commit d656775

Please sign in to comment.