Use new MinerEligibleForElection method
This commit is contained in:
parent
a41904fb51
commit
a74a368c41
@ -569,7 +569,7 @@ func MinerGetBaseInfo(ctx context.Context, sm *StateManager, bcn beacon.RandomBe
|
|||||||
return nil, xerrors.Errorf("resolving worker address: %w", err)
|
return nil, xerrors.Errorf("resolving worker address: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
hmp, err := MinerHasMinPower(ctx, sm, maddr, lbts)
|
hmp, err := MinerEligibleForElection(ctx, sm, maddr, lbts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerrors.Errorf("determining if miner has min power failed: %w", err)
|
return nil, xerrors.Errorf("determining if miner has min power failed: %w", err)
|
||||||
}
|
}
|
||||||
@ -643,14 +643,32 @@ func GetReturnType(ctx context.Context, sm *StateManager, to address.Address, me
|
|||||||
return reflect.New(m.Ret.Elem()).Interface().(cbg.CBORUnmarshaler), nil
|
return reflect.New(m.Ret.Elem()).Interface().(cbg.CBORUnmarshaler), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func MinerHasMinPower(ctx context.Context, sm *StateManager, addr address.Address, ts *types.TipSet) (bool, error) {
|
func MinerEligibleForElection(ctx context.Context, sm *StateManager, addr address.Address, ts *types.TipSet) (bool, error) {
|
||||||
var ps power.State
|
|
||||||
_, err := sm.LoadActorState(ctx, builtin.StoragePowerActorAddr, &ps, ts)
|
var act types.Actor
|
||||||
|
err := sm.WithParentState(ts, sm.WithActor(addr, GetActor(&act)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, xerrors.Errorf("loading power actor state: %w", err)
|
return false, xerrors.Errorf("loading miner balance: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return ps.MinerNominalPowerMeetsConsensusMinimum(sm.ChainStore().Store(ctx), addr)
|
var ms miner.State
|
||||||
|
_, err = sm.LoadActorState(ctx, addr, &ms, ts)
|
||||||
|
if err != nil {
|
||||||
|
return false, xerrors.Errorf("loading miner actor state: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var rs reward.State
|
||||||
|
_, err = sm.LoadActorState(ctx, builtin.RewardActorAddr, &rs, ts)
|
||||||
|
if err != nil {
|
||||||
|
return false, xerrors.Errorf("loading reward actor state: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ret, err := miner.MinerEligibleForElection(sm.cs.Store(ctx), &ms, rs.ThisEpochReward, act.Balance, ts.Height())
|
||||||
|
if err != nil {
|
||||||
|
return false, xerrors.Errorf("determining election eligibility: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CheckTotalFIL(ctx context.Context, sm *StateManager, ts *types.TipSet) (abi.TokenAmount, error) {
|
func CheckTotalFIL(ctx context.Context, sm *StateManager, ts *types.TipSet) (abi.TokenAmount, error) {
|
||||||
|
@ -481,7 +481,7 @@ func (bv *BlockValidator) checkPowerAndGetWorkerKey(ctx context.Context, bh *typ
|
|||||||
return address.Undef, ErrSoftFailure
|
return address.Undef, ErrSoftFailure
|
||||||
}
|
}
|
||||||
|
|
||||||
hmp, err := stmgr.MinerHasMinPower(ctx, bv.stmgr, bh.Miner, lbts)
|
hmp, err := stmgr.MinerEligibleForElection(ctx, bv.stmgr, bh.Miner, lbts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("failed to determine if incoming block's miner has minimum power: %s", err)
|
log.Warnf("failed to determine if incoming block's miner has minimum power: %s", err)
|
||||||
return address.Undef, ErrSoftFailure
|
return address.Undef, ErrSoftFailure
|
||||||
|
@ -774,7 +774,7 @@ func (syncer *Syncer) ValidateBlock(ctx context.Context, b *types.FullBlock) (er
|
|||||||
return xerrors.Errorf("block is not claiming to be a winner")
|
return xerrors.Errorf("block is not claiming to be a winner")
|
||||||
}
|
}
|
||||||
|
|
||||||
hp, err := stmgr.MinerHasMinPower(ctx, syncer.sm, h.Miner, lbts)
|
hp, err := stmgr.MinerEligibleForElection(ctx, syncer.sm, h.Miner, lbts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("determining if miner has min power failed: %w", err)
|
return xerrors.Errorf("determining if miner has min power failed: %w", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user