From 2994e9f75aa66201031c248db27db306ef1920b6 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 10 Dec 2024 16:32:22 +0100 Subject: [PATCH] feat: optimize ForEachClaim to return only eligible claims Avoids double AMT traversal Signed-off-by: Jakub Sztandera --- chain/actors/builtin/power/actor.go.template | 2 +- chain/actors/builtin/power/power.go | 2 +- chain/actors/builtin/power/state.go.template | 28 +++++++++++++++---- chain/actors/builtin/power/v0.go | 26 +++++++++++++---- chain/actors/builtin/power/v10.go | 25 +++++++++++++---- chain/actors/builtin/power/v11.go | 25 +++++++++++++---- chain/actors/builtin/power/v12.go | 25 +++++++++++++---- chain/actors/builtin/power/v13.go | 25 +++++++++++++---- chain/actors/builtin/power/v14.go | 25 +++++++++++++---- chain/actors/builtin/power/v15.go | 25 +++++++++++++---- chain/actors/builtin/power/v16.go | 25 +++++++++++++---- chain/actors/builtin/power/v2.go | 26 +++++++++++++---- chain/actors/builtin/power/v3.go | 26 +++++++++++++---- chain/actors/builtin/power/v4.go | 26 +++++++++++++---- chain/actors/builtin/power/v5.go | 26 +++++++++++++---- chain/actors/builtin/power/v6.go | 26 +++++++++++++---- chain/actors/builtin/power/v7.go | 26 +++++++++++++---- chain/actors/builtin/power/v8.go | 25 +++++++++++++---- chain/actors/builtin/power/v9.go | 25 +++++++++++++---- chain/lf3/ec.go | 11 +------- cmd/lotus-shed/sectors.go | 2 +- .../simulation/stages/precommit_stage.go | 2 +- .../simulation/stages/provecommit_stage.go | 2 +- .../simulation/stages/windowpost_stage.go | 2 +- go.mod | 12 ++++---- go.sum | 24 ++++++++-------- tools/stats/points/collect.go | 2 +- 27 files changed, 376 insertions(+), 120 deletions(-) diff --git a/chain/actors/builtin/power/actor.go.template b/chain/actors/builtin/power/actor.go.template index 2dbb04dc1ea..6364630be12 100644 --- a/chain/actors/builtin/power/actor.go.template +++ b/chain/actors/builtin/power/actor.go.template @@ -99,7 +99,7 @@ type State interface { MinerPower(address.Address) (Claim, bool, error) MinerNominalPowerMeetsConsensusMinimum(address.Address) (bool, error) ListAllMiners() ([]address.Address, error) - ForEachClaim(func(miner address.Address, claim Claim) error) error + ForEachClaim(cb func(miner address.Address, claim Claim) error, onlyEligible bool) error ClaimsChanged(State) (bool, error) // Testing or genesis setup only diff --git a/chain/actors/builtin/power/power.go b/chain/actors/builtin/power/power.go index 1347a483d80..ecc79c6a453 100644 --- a/chain/actors/builtin/power/power.go +++ b/chain/actors/builtin/power/power.go @@ -183,7 +183,7 @@ type State interface { MinerPower(address.Address) (Claim, bool, error) MinerNominalPowerMeetsConsensusMinimum(address.Address) (bool, error) ListAllMiners() ([]address.Address, error) - ForEachClaim(func(miner address.Address, claim Claim) error) error + ForEachClaim(cb func(miner address.Address, claim Claim) error, onlyEligible bool) error ClaimsChanged(State) (bool, error) // Testing or genesis setup only diff --git a/chain/actors/builtin/power/state.go.template b/chain/actors/builtin/power/state.go.template index 876fc31d538..5973b258817 100644 --- a/chain/actors/builtin/power/state.go.template +++ b/chain/actors/builtin/power/state.go.template @@ -147,7 +147,7 @@ func (s *state{{.v}}) ListAllMiners() ([]address.Address, error) { return miners, nil } -func (s *state{{.v}}) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { +func (s *state{{.v}}) ForEachClaim(cb func(miner address.Address, claim Claim) error, onlyEligible bool) error { claims, err := s.claims() if err != nil { return err @@ -159,10 +159,28 @@ func (s *state{{.v}}) ForEachClaim(cb func(miner address.Address, claim Claim) e if err != nil { return err } - return cb(a, Claim{ - RawBytePower: claim.RawBytePower, - QualityAdjPower: claim.QualityAdjPower, - }) + if !onlyEligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + {{if (ge .v 8)}} + eligible, err := s.State.ClaimMeetsConsensusMinimums(&claim) + {{else}} + //slow path + eligible, err := s.State.MinerNominalPowerMeetsConsensusMinimum(s.store, a) + {{end}} + if err != nil { + return fmt.Errorf("checking consensus minimums: %w", err) + } + if eligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + return nil }) } diff --git a/chain/actors/builtin/power/v0.go b/chain/actors/builtin/power/v0.go index 66ffa23c6df..726cf689b11 100644 --- a/chain/actors/builtin/power/v0.go +++ b/chain/actors/builtin/power/v0.go @@ -130,7 +130,7 @@ func (s *state0) ListAllMiners() ([]address.Address, error) { return miners, nil } -func (s *state0) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { +func (s *state0) ForEachClaim(cb func(miner address.Address, claim Claim) error, onlyEligible bool) error { claims, err := s.claims() if err != nil { return err @@ -142,10 +142,26 @@ func (s *state0) ForEachClaim(cb func(miner address.Address, claim Claim) error) if err != nil { return err } - return cb(a, Claim{ - RawBytePower: claim.RawBytePower, - QualityAdjPower: claim.QualityAdjPower, - }) + if !onlyEligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + + //slow path + eligible, err := s.State.MinerNominalPowerMeetsConsensusMinimum(s.store, a) + + if err != nil { + return fmt.Errorf("checking consensus minimums: %w", err) + } + if eligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + return nil }) } diff --git a/chain/actors/builtin/power/v10.go b/chain/actors/builtin/power/v10.go index bf51b014873..1bb2e52b53f 100644 --- a/chain/actors/builtin/power/v10.go +++ b/chain/actors/builtin/power/v10.go @@ -126,7 +126,7 @@ func (s *state10) ListAllMiners() ([]address.Address, error) { return miners, nil } -func (s *state10) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { +func (s *state10) ForEachClaim(cb func(miner address.Address, claim Claim) error, onlyEligible bool) error { claims, err := s.claims() if err != nil { return err @@ -138,10 +138,25 @@ func (s *state10) ForEachClaim(cb func(miner address.Address, claim Claim) error if err != nil { return err } - return cb(a, Claim{ - RawBytePower: claim.RawBytePower, - QualityAdjPower: claim.QualityAdjPower, - }) + if !onlyEligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + + eligible, err := s.State.ClaimMeetsConsensusMinimums(&claim) + + if err != nil { + return fmt.Errorf("checking consensus minimums: %w", err) + } + if eligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + return nil }) } diff --git a/chain/actors/builtin/power/v11.go b/chain/actors/builtin/power/v11.go index 817b400c3bf..c974018313e 100644 --- a/chain/actors/builtin/power/v11.go +++ b/chain/actors/builtin/power/v11.go @@ -126,7 +126,7 @@ func (s *state11) ListAllMiners() ([]address.Address, error) { return miners, nil } -func (s *state11) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { +func (s *state11) ForEachClaim(cb func(miner address.Address, claim Claim) error, onlyEligible bool) error { claims, err := s.claims() if err != nil { return err @@ -138,10 +138,25 @@ func (s *state11) ForEachClaim(cb func(miner address.Address, claim Claim) error if err != nil { return err } - return cb(a, Claim{ - RawBytePower: claim.RawBytePower, - QualityAdjPower: claim.QualityAdjPower, - }) + if !onlyEligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + + eligible, err := s.State.ClaimMeetsConsensusMinimums(&claim) + + if err != nil { + return fmt.Errorf("checking consensus minimums: %w", err) + } + if eligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + return nil }) } diff --git a/chain/actors/builtin/power/v12.go b/chain/actors/builtin/power/v12.go index d8f8ee51b50..d57f225d252 100644 --- a/chain/actors/builtin/power/v12.go +++ b/chain/actors/builtin/power/v12.go @@ -126,7 +126,7 @@ func (s *state12) ListAllMiners() ([]address.Address, error) { return miners, nil } -func (s *state12) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { +func (s *state12) ForEachClaim(cb func(miner address.Address, claim Claim) error, onlyEligible bool) error { claims, err := s.claims() if err != nil { return err @@ -138,10 +138,25 @@ func (s *state12) ForEachClaim(cb func(miner address.Address, claim Claim) error if err != nil { return err } - return cb(a, Claim{ - RawBytePower: claim.RawBytePower, - QualityAdjPower: claim.QualityAdjPower, - }) + if !onlyEligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + + eligible, err := s.State.ClaimMeetsConsensusMinimums(&claim) + + if err != nil { + return fmt.Errorf("checking consensus minimums: %w", err) + } + if eligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + return nil }) } diff --git a/chain/actors/builtin/power/v13.go b/chain/actors/builtin/power/v13.go index 8583e19ea79..f2cbe19edda 100644 --- a/chain/actors/builtin/power/v13.go +++ b/chain/actors/builtin/power/v13.go @@ -126,7 +126,7 @@ func (s *state13) ListAllMiners() ([]address.Address, error) { return miners, nil } -func (s *state13) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { +func (s *state13) ForEachClaim(cb func(miner address.Address, claim Claim) error, onlyEligible bool) error { claims, err := s.claims() if err != nil { return err @@ -138,10 +138,25 @@ func (s *state13) ForEachClaim(cb func(miner address.Address, claim Claim) error if err != nil { return err } - return cb(a, Claim{ - RawBytePower: claim.RawBytePower, - QualityAdjPower: claim.QualityAdjPower, - }) + if !onlyEligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + + eligible, err := s.State.ClaimMeetsConsensusMinimums(&claim) + + if err != nil { + return fmt.Errorf("checking consensus minimums: %w", err) + } + if eligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + return nil }) } diff --git a/chain/actors/builtin/power/v14.go b/chain/actors/builtin/power/v14.go index 0377003cb07..759b881cac2 100644 --- a/chain/actors/builtin/power/v14.go +++ b/chain/actors/builtin/power/v14.go @@ -126,7 +126,7 @@ func (s *state14) ListAllMiners() ([]address.Address, error) { return miners, nil } -func (s *state14) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { +func (s *state14) ForEachClaim(cb func(miner address.Address, claim Claim) error, onlyEligible bool) error { claims, err := s.claims() if err != nil { return err @@ -138,10 +138,25 @@ func (s *state14) ForEachClaim(cb func(miner address.Address, claim Claim) error if err != nil { return err } - return cb(a, Claim{ - RawBytePower: claim.RawBytePower, - QualityAdjPower: claim.QualityAdjPower, - }) + if !onlyEligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + + eligible, err := s.State.ClaimMeetsConsensusMinimums(&claim) + + if err != nil { + return fmt.Errorf("checking consensus minimums: %w", err) + } + if eligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + return nil }) } diff --git a/chain/actors/builtin/power/v15.go b/chain/actors/builtin/power/v15.go index 6bdebf9df72..679904bef26 100644 --- a/chain/actors/builtin/power/v15.go +++ b/chain/actors/builtin/power/v15.go @@ -126,7 +126,7 @@ func (s *state15) ListAllMiners() ([]address.Address, error) { return miners, nil } -func (s *state15) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { +func (s *state15) ForEachClaim(cb func(miner address.Address, claim Claim) error, onlyEligible bool) error { claims, err := s.claims() if err != nil { return err @@ -138,10 +138,25 @@ func (s *state15) ForEachClaim(cb func(miner address.Address, claim Claim) error if err != nil { return err } - return cb(a, Claim{ - RawBytePower: claim.RawBytePower, - QualityAdjPower: claim.QualityAdjPower, - }) + if !onlyEligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + + eligible, err := s.State.ClaimMeetsConsensusMinimums(&claim) + + if err != nil { + return fmt.Errorf("checking consensus minimums: %w", err) + } + if eligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + return nil }) } diff --git a/chain/actors/builtin/power/v16.go b/chain/actors/builtin/power/v16.go index 7617c8fd624..2113f338903 100644 --- a/chain/actors/builtin/power/v16.go +++ b/chain/actors/builtin/power/v16.go @@ -126,7 +126,7 @@ func (s *state16) ListAllMiners() ([]address.Address, error) { return miners, nil } -func (s *state16) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { +func (s *state16) ForEachClaim(cb func(miner address.Address, claim Claim) error, onlyEligible bool) error { claims, err := s.claims() if err != nil { return err @@ -138,10 +138,25 @@ func (s *state16) ForEachClaim(cb func(miner address.Address, claim Claim) error if err != nil { return err } - return cb(a, Claim{ - RawBytePower: claim.RawBytePower, - QualityAdjPower: claim.QualityAdjPower, - }) + if !onlyEligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + + eligible, err := s.State.ClaimMeetsConsensusMinimums(&claim) + + if err != nil { + return fmt.Errorf("checking consensus minimums: %w", err) + } + if eligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + return nil }) } diff --git a/chain/actors/builtin/power/v2.go b/chain/actors/builtin/power/v2.go index 6a36f81cd93..ae7d0e0a7a0 100644 --- a/chain/actors/builtin/power/v2.go +++ b/chain/actors/builtin/power/v2.go @@ -130,7 +130,7 @@ func (s *state2) ListAllMiners() ([]address.Address, error) { return miners, nil } -func (s *state2) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { +func (s *state2) ForEachClaim(cb func(miner address.Address, claim Claim) error, onlyEligible bool) error { claims, err := s.claims() if err != nil { return err @@ -142,10 +142,26 @@ func (s *state2) ForEachClaim(cb func(miner address.Address, claim Claim) error) if err != nil { return err } - return cb(a, Claim{ - RawBytePower: claim.RawBytePower, - QualityAdjPower: claim.QualityAdjPower, - }) + if !onlyEligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + + //slow path + eligible, err := s.State.MinerNominalPowerMeetsConsensusMinimum(s.store, a) + + if err != nil { + return fmt.Errorf("checking consensus minimums: %w", err) + } + if eligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + return nil }) } diff --git a/chain/actors/builtin/power/v3.go b/chain/actors/builtin/power/v3.go index 3db90fbe731..3427f2d14e1 100644 --- a/chain/actors/builtin/power/v3.go +++ b/chain/actors/builtin/power/v3.go @@ -126,7 +126,7 @@ func (s *state3) ListAllMiners() ([]address.Address, error) { return miners, nil } -func (s *state3) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { +func (s *state3) ForEachClaim(cb func(miner address.Address, claim Claim) error, onlyEligible bool) error { claims, err := s.claims() if err != nil { return err @@ -138,10 +138,26 @@ func (s *state3) ForEachClaim(cb func(miner address.Address, claim Claim) error) if err != nil { return err } - return cb(a, Claim{ - RawBytePower: claim.RawBytePower, - QualityAdjPower: claim.QualityAdjPower, - }) + if !onlyEligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + + //slow path + eligible, err := s.State.MinerNominalPowerMeetsConsensusMinimum(s.store, a) + + if err != nil { + return fmt.Errorf("checking consensus minimums: %w", err) + } + if eligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + return nil }) } diff --git a/chain/actors/builtin/power/v4.go b/chain/actors/builtin/power/v4.go index cac6d1cad54..bf9c1080139 100644 --- a/chain/actors/builtin/power/v4.go +++ b/chain/actors/builtin/power/v4.go @@ -126,7 +126,7 @@ func (s *state4) ListAllMiners() ([]address.Address, error) { return miners, nil } -func (s *state4) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { +func (s *state4) ForEachClaim(cb func(miner address.Address, claim Claim) error, onlyEligible bool) error { claims, err := s.claims() if err != nil { return err @@ -138,10 +138,26 @@ func (s *state4) ForEachClaim(cb func(miner address.Address, claim Claim) error) if err != nil { return err } - return cb(a, Claim{ - RawBytePower: claim.RawBytePower, - QualityAdjPower: claim.QualityAdjPower, - }) + if !onlyEligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + + //slow path + eligible, err := s.State.MinerNominalPowerMeetsConsensusMinimum(s.store, a) + + if err != nil { + return fmt.Errorf("checking consensus minimums: %w", err) + } + if eligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + return nil }) } diff --git a/chain/actors/builtin/power/v5.go b/chain/actors/builtin/power/v5.go index 7e2450f81b7..d54dfeeb659 100644 --- a/chain/actors/builtin/power/v5.go +++ b/chain/actors/builtin/power/v5.go @@ -126,7 +126,7 @@ func (s *state5) ListAllMiners() ([]address.Address, error) { return miners, nil } -func (s *state5) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { +func (s *state5) ForEachClaim(cb func(miner address.Address, claim Claim) error, onlyEligible bool) error { claims, err := s.claims() if err != nil { return err @@ -138,10 +138,26 @@ func (s *state5) ForEachClaim(cb func(miner address.Address, claim Claim) error) if err != nil { return err } - return cb(a, Claim{ - RawBytePower: claim.RawBytePower, - QualityAdjPower: claim.QualityAdjPower, - }) + if !onlyEligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + + //slow path + eligible, err := s.State.MinerNominalPowerMeetsConsensusMinimum(s.store, a) + + if err != nil { + return fmt.Errorf("checking consensus minimums: %w", err) + } + if eligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + return nil }) } diff --git a/chain/actors/builtin/power/v6.go b/chain/actors/builtin/power/v6.go index 493b278ec09..c033797d4d8 100644 --- a/chain/actors/builtin/power/v6.go +++ b/chain/actors/builtin/power/v6.go @@ -126,7 +126,7 @@ func (s *state6) ListAllMiners() ([]address.Address, error) { return miners, nil } -func (s *state6) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { +func (s *state6) ForEachClaim(cb func(miner address.Address, claim Claim) error, onlyEligible bool) error { claims, err := s.claims() if err != nil { return err @@ -138,10 +138,26 @@ func (s *state6) ForEachClaim(cb func(miner address.Address, claim Claim) error) if err != nil { return err } - return cb(a, Claim{ - RawBytePower: claim.RawBytePower, - QualityAdjPower: claim.QualityAdjPower, - }) + if !onlyEligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + + //slow path + eligible, err := s.State.MinerNominalPowerMeetsConsensusMinimum(s.store, a) + + if err != nil { + return fmt.Errorf("checking consensus minimums: %w", err) + } + if eligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + return nil }) } diff --git a/chain/actors/builtin/power/v7.go b/chain/actors/builtin/power/v7.go index bfa3fea2ffd..08df4f57d75 100644 --- a/chain/actors/builtin/power/v7.go +++ b/chain/actors/builtin/power/v7.go @@ -126,7 +126,7 @@ func (s *state7) ListAllMiners() ([]address.Address, error) { return miners, nil } -func (s *state7) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { +func (s *state7) ForEachClaim(cb func(miner address.Address, claim Claim) error, onlyEligible bool) error { claims, err := s.claims() if err != nil { return err @@ -138,10 +138,26 @@ func (s *state7) ForEachClaim(cb func(miner address.Address, claim Claim) error) if err != nil { return err } - return cb(a, Claim{ - RawBytePower: claim.RawBytePower, - QualityAdjPower: claim.QualityAdjPower, - }) + if !onlyEligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + + //slow path + eligible, err := s.State.MinerNominalPowerMeetsConsensusMinimum(s.store, a) + + if err != nil { + return fmt.Errorf("checking consensus minimums: %w", err) + } + if eligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + return nil }) } diff --git a/chain/actors/builtin/power/v8.go b/chain/actors/builtin/power/v8.go index e3ee24c831d..230c1472e4d 100644 --- a/chain/actors/builtin/power/v8.go +++ b/chain/actors/builtin/power/v8.go @@ -126,7 +126,7 @@ func (s *state8) ListAllMiners() ([]address.Address, error) { return miners, nil } -func (s *state8) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { +func (s *state8) ForEachClaim(cb func(miner address.Address, claim Claim) error, onlyEligible bool) error { claims, err := s.claims() if err != nil { return err @@ -138,10 +138,25 @@ func (s *state8) ForEachClaim(cb func(miner address.Address, claim Claim) error) if err != nil { return err } - return cb(a, Claim{ - RawBytePower: claim.RawBytePower, - QualityAdjPower: claim.QualityAdjPower, - }) + if !onlyEligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + + eligible, err := s.State.ClaimMeetsConsensusMinimums(&claim) + + if err != nil { + return fmt.Errorf("checking consensus minimums: %w", err) + } + if eligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + return nil }) } diff --git a/chain/actors/builtin/power/v9.go b/chain/actors/builtin/power/v9.go index d8d49858748..0c3a21b290c 100644 --- a/chain/actors/builtin/power/v9.go +++ b/chain/actors/builtin/power/v9.go @@ -126,7 +126,7 @@ func (s *state9) ListAllMiners() ([]address.Address, error) { return miners, nil } -func (s *state9) ForEachClaim(cb func(miner address.Address, claim Claim) error) error { +func (s *state9) ForEachClaim(cb func(miner address.Address, claim Claim) error, onlyEligible bool) error { claims, err := s.claims() if err != nil { return err @@ -138,10 +138,25 @@ func (s *state9) ForEachClaim(cb func(miner address.Address, claim Claim) error) if err != nil { return err } - return cb(a, Claim{ - RawBytePower: claim.RawBytePower, - QualityAdjPower: claim.QualityAdjPower, - }) + if !onlyEligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + + eligible, err := s.State.ClaimMeetsConsensusMinimums(&claim) + + if err != nil { + return fmt.Errorf("checking consensus minimums: %w", err) + } + if eligible { + return cb(a, Claim{ + RawBytePower: claim.RawBytePower, + QualityAdjPower: claim.QualityAdjPower, + }) + } + return nil }) } diff --git a/chain/lf3/ec.go b/chain/lf3/ec.go index f05bd0cfb36..2ad23658b5b 100644 --- a/chain/lf3/ec.go +++ b/chain/lf3/ec.go @@ -144,15 +144,6 @@ func (ec *ecWrapper) getPowerTableLotusTSK(ctx context.Context, tsk types.TipSet return nil } - // TODO: optimize - ok, err := powerState.MinerNominalPowerMeetsConsensusMinimum(minerAddr) - if err != nil { - return xerrors.Errorf("checking consensus minimums: %w", err) - } - if !ok { - return nil - } - id, err := address.IDFromAddress(minerAddr) if err != nil { return xerrors.Errorf("transforming address to ID: %w", err) @@ -199,7 +190,7 @@ func (ec *ecWrapper) getPowerTableLotusTSK(ctx context.Context, tsk types.TipSet pe.PubKey = waddr.Payload() powerEntries = append(powerEntries, pe) return nil - }) + }, true) if err != nil { return nil, xerrors.Errorf("collecting the power table: %w", err) } diff --git a/cmd/lotus-shed/sectors.go b/cmd/lotus-shed/sectors.go index 15ee49b311a..faa21f9d94e 100644 --- a/cmd/lotus-shed/sectors.go +++ b/cmd/lotus-shed/sectors.go @@ -729,7 +729,7 @@ var dumpSectorOnChainInfoCmd = &cli.Command{ } return nil - }) + }, false) if err != nil { return xerrors.Errorf("iterating over claims: %w", err) diff --git a/cmd/lotus-sim/simulation/stages/precommit_stage.go b/cmd/lotus-sim/simulation/stages/precommit_stage.go index f9e6ca80d69..5cbe77a4f42 100644 --- a/cmd/lotus-sim/simulation/stages/precommit_stage.go +++ b/cmd/lotus-sim/simulation/stages/precommit_stage.go @@ -313,7 +313,7 @@ func (stage *PreCommitStage) load(ctx context.Context, bb *blockbuilder.BlockBui sealList = append(sealList, onboardingInfo{addr, uint64(sectorCount)}) } return nil - }) + }, false) if err != nil { return err } diff --git a/cmd/lotus-sim/simulation/stages/provecommit_stage.go b/cmd/lotus-sim/simulation/stages/provecommit_stage.go index 0a850667886..515938ecc2d 100644 --- a/cmd/lotus-sim/simulation/stages/provecommit_stage.go +++ b/cmd/lotus-sim/simulation/stages/provecommit_stage.go @@ -376,7 +376,7 @@ func (stage *ProveCommitStage) load(ctx context.Context, bb *blockbuilder.BlockB return nil } return stage.loadMiner(ctx, bb, minerAddr) - }) + }, false) if err != nil { return err } diff --git a/cmd/lotus-sim/simulation/stages/windowpost_stage.go b/cmd/lotus-sim/simulation/stages/windowpost_stage.go index 65c29ccebc8..984ab7ef9e0 100644 --- a/cmd/lotus-sim/simulation/stages/windowpost_stage.go +++ b/cmd/lotus-sim/simulation/stages/windowpost_stage.go @@ -264,7 +264,7 @@ func (stage *WindowPoStStage) load(ctx context.Context, bb *blockbuilder.BlockBu stage.wpostPeriods[ppOffset] = append(stage.wpostPeriods[ppOffset], minerAddr) return stage.queueMiner(ctx, bb, minerAddr, minerState, commitEpoch, commitRand) - }) + }, false) } func (stage *WindowPoStStage) tick(ctx context.Context, bb *blockbuilder.BlockBuilder) error { diff --git a/go.mod b/go.mod index 8fe09b33115..7f0bc6abeca 100644 --- a/go.mod +++ b/go.mod @@ -50,7 +50,7 @@ require ( github.com/filecoin-project/go-jsonrpc v0.7.0 github.com/filecoin-project/go-padreader v0.0.1 github.com/filecoin-project/go-paramfetch v0.0.4 - github.com/filecoin-project/go-state-types v0.16.0-rc1 + github.com/filecoin-project/go-state-types v0.16.0-rc1.0.20241210151506-27c2d581aa19 github.com/filecoin-project/go-statemachine v1.0.3 github.com/filecoin-project/go-statestore v0.2.0 github.com/filecoin-project/go-storedcounter v0.1.0 @@ -153,12 +153,12 @@ require ( go.uber.org/fx v1.23.0 go.uber.org/multierr v1.11.0 go.uber.org/zap v1.27.0 - golang.org/x/crypto v0.29.0 + golang.org/x/crypto v0.30.0 golang.org/x/mod v0.21.0 golang.org/x/net v0.30.0 - golang.org/x/sync v0.9.0 - golang.org/x/sys v0.27.0 - golang.org/x/term v0.26.0 + golang.org/x/sync v0.10.0 + golang.org/x/sys v0.28.0 + golang.org/x/term v0.27.0 golang.org/x/time v0.5.0 golang.org/x/tools v0.26.0 golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da @@ -332,7 +332,7 @@ require ( go.uber.org/mock v0.5.0 // indirect go4.org v0.0.0-20230225012048-214862532bf5 // indirect golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect - golang.org/x/text v0.20.0 // indirect + golang.org/x/text v0.21.0 // indirect gonum.org/v1/gonum v0.15.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect google.golang.org/grpc v1.64.0 // indirect diff --git a/go.sum b/go.sum index 0d843ff4ceb..87001a05f48 100644 --- a/go.sum +++ b/go.sum @@ -298,8 +298,8 @@ github.com/filecoin-project/go-state-types v0.0.0-20200928172055-2df22083d8ab/go github.com/filecoin-project/go-state-types v0.0.0-20201102161440-c8033295a1fc/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g= github.com/filecoin-project/go-state-types v0.1.0/go.mod h1:ezYnPf0bNkTsDibL/psSz5dy4B5awOJ/E7P2Saeep8g= github.com/filecoin-project/go-state-types v0.1.6/go.mod h1:UwGVoMsULoCK+bWjEdd/xLCvLAQFBC7EDT477SKml+Q= -github.com/filecoin-project/go-state-types v0.16.0-rc1 h1:/51MhupBAjfmWygUKDZCdLOzAnKFcayPHX9ApTswgmo= -github.com/filecoin-project/go-state-types v0.16.0-rc1/go.mod h1:4rjTgHP6LWrkQXQCgx+dRGDa0gnk4WiJVCFwZtuDOGE= +github.com/filecoin-project/go-state-types v0.16.0-rc1.0.20241210151506-27c2d581aa19 h1:GQfLAYtHwV0IH1mDKMG8PfaWlq9DoqQdir/6hhYI9Aw= +github.com/filecoin-project/go-state-types v0.16.0-rc1.0.20241210151506-27c2d581aa19/go.mod h1:TwnMxZiLa6wUT4u4KWJ+02VMwIQS/EoDJrAowy3Z6G0= github.com/filecoin-project/go-statemachine v1.0.3 h1:N07o6alys+V1tNoSTi4WuuoeNC4erS/6jE74+NsgQuk= github.com/filecoin-project/go-statemachine v1.0.3/go.mod h1:jZdXXiHa61n4NmgWFG4w8tnqgvZVHYbJ3yW7+y8bF54= github.com/filecoin-project/go-statestore v0.1.0/go.mod h1:LFc9hD+fRxPqiHiaqUEZOinUJB4WARkRfNl10O7kTnI= @@ -1447,8 +1447,8 @@ golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= -golang.org/x/crypto v0.29.0 h1:L5SG1JTTXupVV3n6sUqMTeWbjAyfPwoda2DLX8J8FrQ= -golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg= +golang.org/x/crypto v0.30.0 h1:RwoQn3GkWiMkzlX562cLB7OxWvjH1L8xutO2WoJcRoY= +golang.org/x/crypto v0.30.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -1570,8 +1570,8 @@ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ= -golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= +golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180202135801-37707fdb30a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -1660,8 +1660,8 @@ golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s= -golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= +golang.org/x/sys v0.28.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-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= @@ -1673,8 +1673,8 @@ golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o= golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU= golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY= -golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU= -golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E= +golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q= +golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1688,8 +1688,8 @@ golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/text v0.20.0 h1:gK/Kv2otX8gz+wn7Rmb3vT96ZwuoxnQlY+HlJVj7Qug= -golang.org/x/text v0.20.0/go.mod h1:D4IsuqiFMhST5bX19pQ9ikHC2GsaKyk/oF+pn3ducp4= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/tools/stats/points/collect.go b/tools/stats/points/collect.go index 8b1d3e06c85..6f030fdb7c0 100644 --- a/tools/stats/points/collect.go +++ b/tools/stats/points/collect.go @@ -267,7 +267,7 @@ func (c *ChainPointCollector) collectStaterootPoints(ctx context.Context, pl *in pl.AddPoint(p) return nil - }) + }, false) } type msgTag struct {