Skip to content

Commit

Permalink
feat: optimize ForEachClaim to return only eligible claims
Browse files Browse the repository at this point in the history
Avoids double AMT traversal

Signed-off-by: Jakub Sztandera <[email protected]>
  • Loading branch information
Kubuxu authored and rjan90 committed Dec 13, 2024
1 parent a420b04 commit 2994e9f
Show file tree
Hide file tree
Showing 27 changed files with 376 additions and 120 deletions.
2 changes: 1 addition & 1 deletion chain/actors/builtin/power/actor.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion chain/actors/builtin/power/power.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 2994e9f

Please sign in to comment.