Skip to content

Commit

Permalink
feat: separate out ClaimMeetsConsensusMinimums for more efficient cal…
Browse files Browse the repository at this point in the history
…ls (#333)

Signed-off-by: Jakub Sztandera <oss@kubuxu.com>
  • Loading branch information
Kubuxu authored Dec 11, 2024
1 parent 65763fd commit 0573764
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 162 deletions.
41 changes: 23 additions & 18 deletions builtin/v10/power/power_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,8 @@ type CronEvent struct {
CallbackPayload []byte
}

// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
// winners outside the chain state. If the miner has over a threshold of power
// the miner meets the minimum. If the network is a below a threshold of
// miners and has power > zero the miner meets the minimum.
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
if err != nil {
return false, xerrors.Errorf("failed to load claims: %w", err)
}

claim, ok, err := getClaim(claims, miner)
if err != nil {
return false, err
}
if !ok {
return false, xerrors.Errorf("no claim for actor %w", miner)
}

// ClaimMeetsConsensusMinimums checks if given claim meets the minimums set by the network for mining.
func (st *State) ClaimMeetsConsensusMinimums(claim *Claim) (bool, error) {
minerNominalPower := claim.RawBytePower
minerMinPower, err := builtin.ConsensusMinerMinPower(claim.WindowPoStProofType)
if err != nil {
Expand All @@ -155,6 +139,27 @@ func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.
return minerNominalPower.GreaterThan(abi.NewStoragePower(0)), nil
}

// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
// winners outside the chain state. If the miner has over a threshold of power
// the miner meets the minimum. If the network is a below a threshold of
// miners and has power > zero the miner meets the minimum.
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
if err != nil {
return false, xerrors.Errorf("failed to load claims: %w", err)
}

claim, ok, err := getClaim(claims, miner)
if err != nil {
return false, err
}
if !ok {
return false, xerrors.Errorf("no claim for actor %w", miner)
}

return st.ClaimMeetsConsensusMinimums(claim)
}

func (st *State) GetClaim(s adt.Store, a addr.Address) (*Claim, bool, error) {
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
if err != nil {
Expand Down
41 changes: 23 additions & 18 deletions builtin/v11/power/power_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,8 @@ type CronEvent struct {
CallbackPayload []byte
}

// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
// winners outside the chain state. If the miner has over a threshold of power
// the miner meets the minimum. If the network is a below a threshold of
// miners and has power > zero the miner meets the minimum.
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
if err != nil {
return false, xerrors.Errorf("failed to load claims: %w", err)
}

claim, ok, err := getClaim(claims, miner)
if err != nil {
return false, err
}
if !ok {
return false, xerrors.Errorf("no claim for actor %w", miner)
}

// ClaimMeetsConsensusMinimums checks if given claim meets the minimums set by the network for mining.
func (st *State) ClaimMeetsConsensusMinimums(claim *Claim) (bool, error) {
minerNominalPower := claim.RawBytePower
minerMinPower, err := builtin.ConsensusMinerMinPower(claim.WindowPoStProofType)
if err != nil {
Expand All @@ -155,6 +139,27 @@ func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.
return minerNominalPower.GreaterThan(abi.NewStoragePower(0)), nil
}

// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
// winners outside the chain state. If the miner has over a threshold of power
// the miner meets the minimum. If the network is a below a threshold of
// miners and has power > zero the miner meets the minimum.
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
if err != nil {
return false, xerrors.Errorf("failed to load claims: %w", err)
}

claim, ok, err := getClaim(claims, miner)
if err != nil {
return false, err
}
if !ok {
return false, xerrors.Errorf("no claim for actor %w", miner)
}

return st.ClaimMeetsConsensusMinimums(claim)
}

func (st *State) GetClaim(s adt.Store, a addr.Address) (*Claim, bool, error) {
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
if err != nil {
Expand Down
41 changes: 23 additions & 18 deletions builtin/v12/power/power_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,8 @@ type CronEvent struct {
CallbackPayload []byte
}

// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
// winners outside the chain state. If the miner has over a threshold of power
// the miner meets the minimum. If the network is a below a threshold of
// miners and has power > zero the miner meets the minimum.
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
if err != nil {
return false, xerrors.Errorf("failed to load claims: %w", err)
}

claim, ok, err := getClaim(claims, miner)
if err != nil {
return false, err
}
if !ok {
return false, xerrors.Errorf("no claim for actor %w", miner)
}

// ClaimMeetsConsensusMinimums checks if given claim meets the minimums set by the network for mining.
func (st *State) ClaimMeetsConsensusMinimums(claim *Claim) (bool, error) {
minerNominalPower := claim.RawBytePower
minerMinPower, err := builtin.ConsensusMinerMinPower(claim.WindowPoStProofType)
if err != nil {
Expand All @@ -156,6 +140,27 @@ func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.
return minerNominalPower.GreaterThan(abi.NewStoragePower(0)), nil
}

// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
// winners outside the chain state. If the miner has over a threshold of power
// the miner meets the minimum. If the network is a below a threshold of
// miners and has power > zero the miner meets the minimum.
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
if err != nil {
return false, xerrors.Errorf("failed to load claims: %w", err)
}

claim, ok, err := getClaim(claims, miner)
if err != nil {
return false, err
}
if !ok {
return false, xerrors.Errorf("no claim for actor %w", miner)
}

return st.ClaimMeetsConsensusMinimums(claim)
}

func (st *State) GetClaim(s adt.Store, a addr.Address) (*Claim, bool, error) {
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
if err != nil {
Expand Down
41 changes: 23 additions & 18 deletions builtin/v13/power/power_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,8 @@ type CronEvent struct {
CallbackPayload []byte
}

// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
// winners outside the chain state. If the miner has over a threshold of power
// the miner meets the minimum. If the network is a below a threshold of
// miners and has power > zero the miner meets the minimum.
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
if err != nil {
return false, xerrors.Errorf("failed to load claims: %w", err)
}

claim, ok, err := getClaim(claims, miner)
if err != nil {
return false, err
}
if !ok {
return false, xerrors.Errorf("no claim for actor %w", miner)
}

// ClaimMeetsConsensusMinimums checks if given claim meets the minimums set by the network for mining.
func (st *State) ClaimMeetsConsensusMinimums(claim *Claim) (bool, error) {
minerNominalPower := claim.RawBytePower
minerMinPower, err := builtin.ConsensusMinerMinPower(claim.WindowPoStProofType)
if err != nil {
Expand All @@ -156,6 +140,27 @@ func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.
return minerNominalPower.GreaterThan(abi.NewStoragePower(0)), nil
}

// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
// winners outside the chain state. If the miner has over a threshold of power
// the miner meets the minimum. If the network is a below a threshold of
// miners and has power > zero the miner meets the minimum.
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
if err != nil {
return false, xerrors.Errorf("failed to load claims: %w", err)
}

claim, ok, err := getClaim(claims, miner)
if err != nil {
return false, err
}
if !ok {
return false, xerrors.Errorf("no claim for actor %w", miner)
}

return st.ClaimMeetsConsensusMinimums(claim)
}

func (st *State) GetClaim(s adt.Store, a addr.Address) (*Claim, bool, error) {
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
if err != nil {
Expand Down
41 changes: 23 additions & 18 deletions builtin/v14/power/power_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,8 @@ type CronEvent struct {
CallbackPayload []byte
}

// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
// winners outside the chain state. If the miner has over a threshold of power
// the miner meets the minimum. If the network is a below a threshold of
// miners and has power > zero the miner meets the minimum.
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
if err != nil {
return false, xerrors.Errorf("failed to load claims: %w", err)
}

claim, ok, err := getClaim(claims, miner)
if err != nil {
return false, err
}
if !ok {
return false, xerrors.Errorf("no claim for actor %w", miner)
}

// ClaimMeetsConsensusMinimums checks if given claim meets the minimums set by the network for mining.
func (st *State) ClaimMeetsConsensusMinimums(claim *Claim) (bool, error) {
minerNominalPower := claim.RawBytePower
minerMinPower, err := builtin.ConsensusMinerMinPower(claim.WindowPoStProofType)
if err != nil {
Expand All @@ -156,6 +140,27 @@ func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.
return minerNominalPower.GreaterThan(abi.NewStoragePower(0)), nil
}

// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
// winners outside the chain state. If the miner has over a threshold of power
// the miner meets the minimum. If the network is a below a threshold of
// miners and has power > zero the miner meets the minimum.
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
if err != nil {
return false, xerrors.Errorf("failed to load claims: %w", err)
}

claim, ok, err := getClaim(claims, miner)
if err != nil {
return false, err
}
if !ok {
return false, xerrors.Errorf("no claim for actor %w", miner)
}

return st.ClaimMeetsConsensusMinimums(claim)
}

func (st *State) GetClaim(s adt.Store, a addr.Address) (*Claim, bool, error) {
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
if err != nil {
Expand Down
41 changes: 23 additions & 18 deletions builtin/v15/power/power_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,8 @@ type CronEvent struct {
CallbackPayload []byte
}

// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
// winners outside the chain state. If the miner has over a threshold of power
// the miner meets the minimum. If the network is a below a threshold of
// miners and has power > zero the miner meets the minimum.
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
if err != nil {
return false, xerrors.Errorf("failed to load claims: %w", err)
}

claim, ok, err := getClaim(claims, miner)
if err != nil {
return false, err
}
if !ok {
return false, xerrors.Errorf("no claim for actor %w", miner)
}

// ClaimMeetsConsensusMinimums checks if given claim meets the minimums set by the network for mining.
func (st *State) ClaimMeetsConsensusMinimums(claim *Claim) (bool, error) {
minerNominalPower := claim.RawBytePower
minerMinPower, err := builtin.ConsensusMinerMinPower(claim.WindowPoStProofType)
if err != nil {
Expand All @@ -167,6 +151,27 @@ func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.
return minerNominalPower.GreaterThan(abi.NewStoragePower(0)), nil
}

// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
// winners outside the chain state. If the miner has over a threshold of power
// the miner meets the minimum. If the network is a below a threshold of
// miners and has power > zero the miner meets the minimum.
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
if err != nil {
return false, xerrors.Errorf("failed to load claims: %w", err)
}

claim, ok, err := getClaim(claims, miner)
if err != nil {
return false, err
}
if !ok {
return false, xerrors.Errorf("no claim for actor %w", miner)
}

return st.ClaimMeetsConsensusMinimums(claim)
}

func (st *State) GetClaim(s adt.Store, a addr.Address) (*Claim, bool, error) {
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
if err != nil {
Expand Down
41 changes: 23 additions & 18 deletions builtin/v16/power/power_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,8 @@ type CronEvent struct {
CallbackPayload []byte
}

// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
// winners outside the chain state. If the miner has over a threshold of power
// the miner meets the minimum. If the network is a below a threshold of
// miners and has power > zero the miner meets the minimum.
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
if err != nil {
return false, xerrors.Errorf("failed to load claims: %w", err)
}

claim, ok, err := getClaim(claims, miner)
if err != nil {
return false, err
}
if !ok {
return false, xerrors.Errorf("no claim for actor %w", miner)
}

// ClaimMeetsConsensusMinimums checks if given claim meets the minimums set by the network for mining.
func (st *State) ClaimMeetsConsensusMinimums(claim *Claim) (bool, error) {
minerNominalPower := claim.RawBytePower
minerMinPower, err := builtin.ConsensusMinerMinPower(claim.WindowPoStProofType)
if err != nil {
Expand All @@ -167,6 +151,27 @@ func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.
return minerNominalPower.GreaterThan(abi.NewStoragePower(0)), nil
}

// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
// winners outside the chain state. If the miner has over a threshold of power
// the miner meets the minimum. If the network is a below a threshold of
// miners and has power > zero the miner meets the minimum.
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
if err != nil {
return false, xerrors.Errorf("failed to load claims: %w", err)
}

claim, ok, err := getClaim(claims, miner)
if err != nil {
return false, err
}
if !ok {
return false, xerrors.Errorf("no claim for actor %w", miner)
}

return st.ClaimMeetsConsensusMinimums(claim)
}

func (st *State) GetClaim(s adt.Store, a addr.Address) (*Claim, bool, error) {
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
if err != nil {
Expand Down
Loading

0 comments on commit 0573764

Please sign in to comment.