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

Separate out claim check to to avoid double claim load in Lotus #333

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
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
Loading