Skip to content

Commit 0573764

Browse files
authored
feat: separate out ClaimMeetsConsensusMinimums for more efficient calls (#333)
Signed-off-by: Jakub Sztandera <[email protected]>
1 parent 65763fd commit 0573764

File tree

9 files changed

+207
-162
lines changed

9 files changed

+207
-162
lines changed

builtin/v10/power/power_state.go

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -117,24 +117,8 @@ type CronEvent struct {
117117
CallbackPayload []byte
118118
}
119119

120-
// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
121-
// winners outside the chain state. If the miner has over a threshold of power
122-
// the miner meets the minimum. If the network is a below a threshold of
123-
// miners and has power > zero the miner meets the minimum.
124-
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
125-
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
126-
if err != nil {
127-
return false, xerrors.Errorf("failed to load claims: %w", err)
128-
}
129-
130-
claim, ok, err := getClaim(claims, miner)
131-
if err != nil {
132-
return false, err
133-
}
134-
if !ok {
135-
return false, xerrors.Errorf("no claim for actor %w", miner)
136-
}
137-
120+
// ClaimMeetsConsensusMinimums checks if given claim meets the minimums set by the network for mining.
121+
func (st *State) ClaimMeetsConsensusMinimums(claim *Claim) (bool, error) {
138122
minerNominalPower := claim.RawBytePower
139123
minerMinPower, err := builtin.ConsensusMinerMinPower(claim.WindowPoStProofType)
140124
if err != nil {
@@ -155,6 +139,27 @@ func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.
155139
return minerNominalPower.GreaterThan(abi.NewStoragePower(0)), nil
156140
}
157141

142+
// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
143+
// winners outside the chain state. If the miner has over a threshold of power
144+
// the miner meets the minimum. If the network is a below a threshold of
145+
// miners and has power > zero the miner meets the minimum.
146+
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
147+
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
148+
if err != nil {
149+
return false, xerrors.Errorf("failed to load claims: %w", err)
150+
}
151+
152+
claim, ok, err := getClaim(claims, miner)
153+
if err != nil {
154+
return false, err
155+
}
156+
if !ok {
157+
return false, xerrors.Errorf("no claim for actor %w", miner)
158+
}
159+
160+
return st.ClaimMeetsConsensusMinimums(claim)
161+
}
162+
158163
func (st *State) GetClaim(s adt.Store, a addr.Address) (*Claim, bool, error) {
159164
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
160165
if err != nil {

builtin/v11/power/power_state.go

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -117,24 +117,8 @@ type CronEvent struct {
117117
CallbackPayload []byte
118118
}
119119

120-
// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
121-
// winners outside the chain state. If the miner has over a threshold of power
122-
// the miner meets the minimum. If the network is a below a threshold of
123-
// miners and has power > zero the miner meets the minimum.
124-
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
125-
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
126-
if err != nil {
127-
return false, xerrors.Errorf("failed to load claims: %w", err)
128-
}
129-
130-
claim, ok, err := getClaim(claims, miner)
131-
if err != nil {
132-
return false, err
133-
}
134-
if !ok {
135-
return false, xerrors.Errorf("no claim for actor %w", miner)
136-
}
137-
120+
// ClaimMeetsConsensusMinimums checks if given claim meets the minimums set by the network for mining.
121+
func (st *State) ClaimMeetsConsensusMinimums(claim *Claim) (bool, error) {
138122
minerNominalPower := claim.RawBytePower
139123
minerMinPower, err := builtin.ConsensusMinerMinPower(claim.WindowPoStProofType)
140124
if err != nil {
@@ -155,6 +139,27 @@ func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.
155139
return minerNominalPower.GreaterThan(abi.NewStoragePower(0)), nil
156140
}
157141

142+
// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
143+
// winners outside the chain state. If the miner has over a threshold of power
144+
// the miner meets the minimum. If the network is a below a threshold of
145+
// miners and has power > zero the miner meets the minimum.
146+
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
147+
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
148+
if err != nil {
149+
return false, xerrors.Errorf("failed to load claims: %w", err)
150+
}
151+
152+
claim, ok, err := getClaim(claims, miner)
153+
if err != nil {
154+
return false, err
155+
}
156+
if !ok {
157+
return false, xerrors.Errorf("no claim for actor %w", miner)
158+
}
159+
160+
return st.ClaimMeetsConsensusMinimums(claim)
161+
}
162+
158163
func (st *State) GetClaim(s adt.Store, a addr.Address) (*Claim, bool, error) {
159164
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
160165
if err != nil {

builtin/v12/power/power_state.go

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,24 +118,8 @@ type CronEvent struct {
118118
CallbackPayload []byte
119119
}
120120

121-
// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
122-
// winners outside the chain state. If the miner has over a threshold of power
123-
// the miner meets the minimum. If the network is a below a threshold of
124-
// miners and has power > zero the miner meets the minimum.
125-
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
126-
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
127-
if err != nil {
128-
return false, xerrors.Errorf("failed to load claims: %w", err)
129-
}
130-
131-
claim, ok, err := getClaim(claims, miner)
132-
if err != nil {
133-
return false, err
134-
}
135-
if !ok {
136-
return false, xerrors.Errorf("no claim for actor %w", miner)
137-
}
138-
121+
// ClaimMeetsConsensusMinimums checks if given claim meets the minimums set by the network for mining.
122+
func (st *State) ClaimMeetsConsensusMinimums(claim *Claim) (bool, error) {
139123
minerNominalPower := claim.RawBytePower
140124
minerMinPower, err := builtin.ConsensusMinerMinPower(claim.WindowPoStProofType)
141125
if err != nil {
@@ -156,6 +140,27 @@ func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.
156140
return minerNominalPower.GreaterThan(abi.NewStoragePower(0)), nil
157141
}
158142

143+
// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
144+
// winners outside the chain state. If the miner has over a threshold of power
145+
// the miner meets the minimum. If the network is a below a threshold of
146+
// miners and has power > zero the miner meets the minimum.
147+
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
148+
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
149+
if err != nil {
150+
return false, xerrors.Errorf("failed to load claims: %w", err)
151+
}
152+
153+
claim, ok, err := getClaim(claims, miner)
154+
if err != nil {
155+
return false, err
156+
}
157+
if !ok {
158+
return false, xerrors.Errorf("no claim for actor %w", miner)
159+
}
160+
161+
return st.ClaimMeetsConsensusMinimums(claim)
162+
}
163+
159164
func (st *State) GetClaim(s adt.Store, a addr.Address) (*Claim, bool, error) {
160165
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
161166
if err != nil {

builtin/v13/power/power_state.go

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,24 +118,8 @@ type CronEvent struct {
118118
CallbackPayload []byte
119119
}
120120

121-
// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
122-
// winners outside the chain state. If the miner has over a threshold of power
123-
// the miner meets the minimum. If the network is a below a threshold of
124-
// miners and has power > zero the miner meets the minimum.
125-
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
126-
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
127-
if err != nil {
128-
return false, xerrors.Errorf("failed to load claims: %w", err)
129-
}
130-
131-
claim, ok, err := getClaim(claims, miner)
132-
if err != nil {
133-
return false, err
134-
}
135-
if !ok {
136-
return false, xerrors.Errorf("no claim for actor %w", miner)
137-
}
138-
121+
// ClaimMeetsConsensusMinimums checks if given claim meets the minimums set by the network for mining.
122+
func (st *State) ClaimMeetsConsensusMinimums(claim *Claim) (bool, error) {
139123
minerNominalPower := claim.RawBytePower
140124
minerMinPower, err := builtin.ConsensusMinerMinPower(claim.WindowPoStProofType)
141125
if err != nil {
@@ -156,6 +140,27 @@ func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.
156140
return minerNominalPower.GreaterThan(abi.NewStoragePower(0)), nil
157141
}
158142

143+
// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
144+
// winners outside the chain state. If the miner has over a threshold of power
145+
// the miner meets the minimum. If the network is a below a threshold of
146+
// miners and has power > zero the miner meets the minimum.
147+
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
148+
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
149+
if err != nil {
150+
return false, xerrors.Errorf("failed to load claims: %w", err)
151+
}
152+
153+
claim, ok, err := getClaim(claims, miner)
154+
if err != nil {
155+
return false, err
156+
}
157+
if !ok {
158+
return false, xerrors.Errorf("no claim for actor %w", miner)
159+
}
160+
161+
return st.ClaimMeetsConsensusMinimums(claim)
162+
}
163+
159164
func (st *State) GetClaim(s adt.Store, a addr.Address) (*Claim, bool, error) {
160165
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
161166
if err != nil {

builtin/v14/power/power_state.go

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,24 +118,8 @@ type CronEvent struct {
118118
CallbackPayload []byte
119119
}
120120

121-
// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
122-
// winners outside the chain state. If the miner has over a threshold of power
123-
// the miner meets the minimum. If the network is a below a threshold of
124-
// miners and has power > zero the miner meets the minimum.
125-
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
126-
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
127-
if err != nil {
128-
return false, xerrors.Errorf("failed to load claims: %w", err)
129-
}
130-
131-
claim, ok, err := getClaim(claims, miner)
132-
if err != nil {
133-
return false, err
134-
}
135-
if !ok {
136-
return false, xerrors.Errorf("no claim for actor %w", miner)
137-
}
138-
121+
// ClaimMeetsConsensusMinimums checks if given claim meets the minimums set by the network for mining.
122+
func (st *State) ClaimMeetsConsensusMinimums(claim *Claim) (bool, error) {
139123
minerNominalPower := claim.RawBytePower
140124
minerMinPower, err := builtin.ConsensusMinerMinPower(claim.WindowPoStProofType)
141125
if err != nil {
@@ -156,6 +140,27 @@ func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.
156140
return minerNominalPower.GreaterThan(abi.NewStoragePower(0)), nil
157141
}
158142

143+
// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
144+
// winners outside the chain state. If the miner has over a threshold of power
145+
// the miner meets the minimum. If the network is a below a threshold of
146+
// miners and has power > zero the miner meets the minimum.
147+
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
148+
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
149+
if err != nil {
150+
return false, xerrors.Errorf("failed to load claims: %w", err)
151+
}
152+
153+
claim, ok, err := getClaim(claims, miner)
154+
if err != nil {
155+
return false, err
156+
}
157+
if !ok {
158+
return false, xerrors.Errorf("no claim for actor %w", miner)
159+
}
160+
161+
return st.ClaimMeetsConsensusMinimums(claim)
162+
}
163+
159164
func (st *State) GetClaim(s adt.Store, a addr.Address) (*Claim, bool, error) {
160165
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
161166
if err != nil {

builtin/v15/power/power_state.go

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -129,24 +129,8 @@ type CronEvent struct {
129129
CallbackPayload []byte
130130
}
131131

132-
// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
133-
// winners outside the chain state. If the miner has over a threshold of power
134-
// the miner meets the minimum. If the network is a below a threshold of
135-
// miners and has power > zero the miner meets the minimum.
136-
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
137-
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
138-
if err != nil {
139-
return false, xerrors.Errorf("failed to load claims: %w", err)
140-
}
141-
142-
claim, ok, err := getClaim(claims, miner)
143-
if err != nil {
144-
return false, err
145-
}
146-
if !ok {
147-
return false, xerrors.Errorf("no claim for actor %w", miner)
148-
}
149-
132+
// ClaimMeetsConsensusMinimums checks if given claim meets the minimums set by the network for mining.
133+
func (st *State) ClaimMeetsConsensusMinimums(claim *Claim) (bool, error) {
150134
minerNominalPower := claim.RawBytePower
151135
minerMinPower, err := builtin.ConsensusMinerMinPower(claim.WindowPoStProofType)
152136
if err != nil {
@@ -167,6 +151,27 @@ func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.
167151
return minerNominalPower.GreaterThan(abi.NewStoragePower(0)), nil
168152
}
169153

154+
// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
155+
// winners outside the chain state. If the miner has over a threshold of power
156+
// the miner meets the minimum. If the network is a below a threshold of
157+
// miners and has power > zero the miner meets the minimum.
158+
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
159+
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
160+
if err != nil {
161+
return false, xerrors.Errorf("failed to load claims: %w", err)
162+
}
163+
164+
claim, ok, err := getClaim(claims, miner)
165+
if err != nil {
166+
return false, err
167+
}
168+
if !ok {
169+
return false, xerrors.Errorf("no claim for actor %w", miner)
170+
}
171+
172+
return st.ClaimMeetsConsensusMinimums(claim)
173+
}
174+
170175
func (st *State) GetClaim(s adt.Store, a addr.Address) (*Claim, bool, error) {
171176
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
172177
if err != nil {

builtin/v16/power/power_state.go

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -129,24 +129,8 @@ type CronEvent struct {
129129
CallbackPayload []byte
130130
}
131131

132-
// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
133-
// winners outside the chain state. If the miner has over a threshold of power
134-
// the miner meets the minimum. If the network is a below a threshold of
135-
// miners and has power > zero the miner meets the minimum.
136-
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
137-
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
138-
if err != nil {
139-
return false, xerrors.Errorf("failed to load claims: %w", err)
140-
}
141-
142-
claim, ok, err := getClaim(claims, miner)
143-
if err != nil {
144-
return false, err
145-
}
146-
if !ok {
147-
return false, xerrors.Errorf("no claim for actor %w", miner)
148-
}
149-
132+
// ClaimMeetsConsensusMinimums checks if given claim meets the minimums set by the network for mining.
133+
func (st *State) ClaimMeetsConsensusMinimums(claim *Claim) (bool, error) {
150134
minerNominalPower := claim.RawBytePower
151135
minerMinPower, err := builtin.ConsensusMinerMinPower(claim.WindowPoStProofType)
152136
if err != nil {
@@ -167,6 +151,27 @@ func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.
167151
return minerNominalPower.GreaterThan(abi.NewStoragePower(0)), nil
168152
}
169153

154+
// MinerNominalPowerMeetsConsensusMinimum is used to validate Election PoSt
155+
// winners outside the chain state. If the miner has over a threshold of power
156+
// the miner meets the minimum. If the network is a below a threshold of
157+
// miners and has power > zero the miner meets the minimum.
158+
func (st *State) MinerNominalPowerMeetsConsensusMinimum(s adt.Store, miner addr.Address) (bool, error) { //nolint:deadcode,unused
159+
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
160+
if err != nil {
161+
return false, xerrors.Errorf("failed to load claims: %w", err)
162+
}
163+
164+
claim, ok, err := getClaim(claims, miner)
165+
if err != nil {
166+
return false, err
167+
}
168+
if !ok {
169+
return false, xerrors.Errorf("no claim for actor %w", miner)
170+
}
171+
172+
return st.ClaimMeetsConsensusMinimums(claim)
173+
}
174+
170175
func (st *State) GetClaim(s adt.Store, a addr.Address) (*Claim, bool, error) {
171176
claims, err := adt.AsMap(s, st.Claims, builtin.DefaultHamtBitwidth)
172177
if err != nil {

0 commit comments

Comments
 (0)