Skip to content

Commit

Permalink
Merge pull request #12770 from filecoin-project/kubuxu/state/claim-check
Browse files Browse the repository at this point in the history
* feat: optimize ForEachClaim to return only eligible claims

Avoids double AMT traversal

Signed-off-by: Jakub Sztandera <[email protected]>

* add comment, bump go-state-types

Signed-off-by: Jakub Sztandera <[email protected]>

---------

Signed-off-by: Jakub Sztandera <[email protected]>
  • Loading branch information
Kubuxu authored Dec 11, 2024
2 parents 9bfd0b4 + 04406f4 commit fce526e
Show file tree
Hide file tree
Showing 27 changed files with 382 additions and 120 deletions.
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

0 comments on commit fce526e

Please sign in to comment.