Add an API method to list all faults occuring in a certain range
This commit is contained in:
parent
1c01799a4b
commit
ec0baefc48
@ -148,6 +148,8 @@ type FullNode interface {
|
||||
StateMinerInfo(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error)
|
||||
StateMinerDeadlines(context.Context, address.Address, types.TipSetKey) (*miner.Deadlines, error)
|
||||
StateMinerFaults(context.Context, address.Address, types.TipSetKey) (*abi.BitField, error)
|
||||
// Returns all non-expired Faults that occur within lookback epochs of the given tipset
|
||||
StateAllMinerFaults(ctx context.Context, lookback abi.ChainEpoch, ts types.TipSetKey) ([]*Fault, error)
|
||||
StateMinerRecoveries(context.Context, address.Address, types.TipSetKey) (*abi.BitField, error)
|
||||
StateMinerInitialPledgeCollateral(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (types.BigInt, error)
|
||||
StateMinerAvailableBalance(context.Context, address.Address, types.TipSetKey) (types.BigInt, error)
|
||||
@ -453,3 +455,8 @@ const (
|
||||
MsigApprove MsigProposeResponse = iota
|
||||
MsigCancel
|
||||
)
|
||||
|
||||
type Fault struct {
|
||||
Miner address.Address
|
||||
Epoch abi.ChainEpoch
|
||||
}
|
||||
|
@ -123,6 +123,7 @@ type FullNodeStruct struct {
|
||||
StateMinerInfo func(context.Context, address.Address, types.TipSetKey) (miner.MinerInfo, error) `perm:"read"`
|
||||
StateMinerDeadlines func(context.Context, address.Address, types.TipSetKey) (*miner.Deadlines, error) `perm:"read"`
|
||||
StateMinerFaults func(context.Context, address.Address, types.TipSetKey) (*abi.BitField, error) `perm:"read"`
|
||||
StateAllMinerFaults func(context.Context, abi.ChainEpoch, types.TipSetKey) ([]*api.Fault, error) `perm:"read"`
|
||||
StateMinerRecoveries func(context.Context, address.Address, types.TipSetKey) (*abi.BitField, error) `perm:"read"`
|
||||
StateMinerInitialPledgeCollateral func(context.Context, address.Address, abi.SectorNumber, types.TipSetKey) (types.BigInt, error) `perm:"read"`
|
||||
StateMinerAvailableBalance func(context.Context, address.Address, types.TipSetKey) (types.BigInt, error) `perm:"read"`
|
||||
@ -540,6 +541,10 @@ func (c *FullNodeStruct) StateMinerFaults(ctx context.Context, actor address.Add
|
||||
return c.Internal.StateMinerFaults(ctx, actor, tsk)
|
||||
}
|
||||
|
||||
func (c *FullNodeStruct) StateAllMinerFaults(ctx context.Context, cutoff abi.ChainEpoch, endTsk types.TipSetKey) ([]*api.Fault, error) {
|
||||
return c.Internal.StateAllMinerFaults(ctx, cutoff, endTsk)
|
||||
}
|
||||
|
||||
func (c *FullNodeStruct) StateMinerRecoveries(ctx context.Context, actor address.Address, tsk types.TipSetKey) (*abi.BitField, error) {
|
||||
return c.Internal.StateMinerRecoveries(ctx, actor, tsk)
|
||||
}
|
||||
|
@ -116,6 +116,47 @@ func (a *StateAPI) StateMinerFaults(ctx context.Context, addr address.Address, t
|
||||
return stmgr.GetMinerFaults(ctx, a.StateManager, ts, addr)
|
||||
}
|
||||
|
||||
func (a *StateAPI) StateAllMinerFaults(ctx context.Context, lookback abi.ChainEpoch, endTsk types.TipSetKey) ([]*api.Fault, error) {
|
||||
endTs, err := a.Chain.GetTipSetFromKey(endTsk)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("loading end tipset %s: %w", endTsk, err)
|
||||
}
|
||||
|
||||
cutoff := endTs.Height() - lookback
|
||||
miners, err := stmgr.ListMinerActors(ctx, a.StateManager, endTs)
|
||||
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("loading miners: %w", err)
|
||||
}
|
||||
|
||||
var allFaults []*api.Fault
|
||||
|
||||
for _, m := range miners {
|
||||
var mas miner.State
|
||||
_, err := a.StateManager.LoadActorState(ctx, m, &mas, endTs)
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failed to load miner actor state %s: %w", m, err)
|
||||
}
|
||||
|
||||
err = mas.ForEachFaultEpoch(a.Chain.Store(ctx), func(faultStart abi.ChainEpoch, faults *abi.BitField) error {
|
||||
if faultStart >= cutoff {
|
||||
allFaults = append(allFaults, &api.Fault{
|
||||
Miner: m,
|
||||
Epoch: faultStart,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, xerrors.Errorf("failure when iterating over miner states: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
return allFaults, nil
|
||||
}
|
||||
|
||||
func (a *StateAPI) StateMinerRecoveries(ctx context.Context, addr address.Address, tsk types.TipSetKey) (*abi.BitField, error) {
|
||||
ts, err := a.Chain.GetTipSetFromKey(tsk)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user