Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optimize ForEachClaim to return only eligible claims #12770

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion chain/actors/builtin/power/actor.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ 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 iterates over claims in the power actor.
// If onlyEligible is true, it applies the MinerNominalPowerMeetsConsensusMinimum check
// before returning the actor.
ForEachClaim(cb func(miner address.Address, claim Claim) error, onlyEligible bool) error
ClaimsChanged(State) (bool, error)

// Testing or genesis setup only
Expand Down
5 changes: 4 additions & 1 deletion chain/actors/builtin/power/power.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ 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 iterates over claims in the power actor.
// If onlyEligible is true, it applies the MinerNominalPowerMeetsConsensusMinimum check
// before returning the actor.
ForEachClaim(cb func(miner address.Address, claim Claim) error, onlyEligible bool) error
ClaimsChanged(State) (bool, error)

// Testing or genesis setup only
Expand Down
28 changes: 23 additions & 5 deletions chain/actors/builtin/power/state.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
})
}

Expand Down
26 changes: 21 additions & 5 deletions chain/actors/builtin/power/v0.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 20 additions & 5 deletions chain/actors/builtin/power/v10.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 20 additions & 5 deletions chain/actors/builtin/power/v11.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 20 additions & 5 deletions chain/actors/builtin/power/v12.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 20 additions & 5 deletions chain/actors/builtin/power/v13.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 20 additions & 5 deletions chain/actors/builtin/power/v14.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 20 additions & 5 deletions chain/actors/builtin/power/v15.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 20 additions & 5 deletions chain/actors/builtin/power/v16.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading