Skip to content

Commit

Permalink
check that sector has deals for unsealed sectors (#1502)
Browse files Browse the repository at this point in the history
* check that sector has deals for unsealed sectors

* simplify
  • Loading branch information
nonsense authored and LexLuthr committed Jul 20, 2023
1 parent f1405f4 commit d8ec5b7
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
4 changes: 3 additions & 1 deletion gql/resolver_lid.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ func (r *resolver) LID(ctx context.Context) (*lidState, error) {

var sealed, unsealed int32
for id, s := range lu.SectorStates { // TODO: consider adding this data directly in SSM
_, sectorHasDeals := lu.SectorWithDeals[id]

if s == db.SealStateUnsealed {
unsealed++
} else if s == db.SealStateSealed {
} else if s == db.SealStateSealed && sectorHasDeals {
sealed++

log.Debugw("LID only sealed sector", "miner", id.Miner, "sector_number", id.Number)
Expand Down
31 changes: 26 additions & 5 deletions sectorstatemgr/sectorstatemgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/filecoin-project/boost/node/config"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/lotus/api"
lotus_modules "github.com/filecoin-project/lotus/node/modules"
lotus_dtypes "github.com/filecoin-project/lotus/node/modules/dtypes"
Expand All @@ -23,10 +24,11 @@ import (
var log = logging.Logger("sectorstatemgr")

type SectorStateUpdates struct {
Updates map[abi.SectorID]db.SealState
ActiveSectors map[abi.SectorID]struct{}
SectorStates map[abi.SectorID]db.SealState
UpdatedAt time.Time
Updates map[abi.SectorID]db.SealState
ActiveSectors map[abi.SectorID]struct{}
SectorWithDeals map[abi.SectorID]struct{}
SectorStates map[abi.SectorID]db.SealState
UpdatedAt time.Time
}

type StorageAPI interface {
Expand Down Expand Up @@ -237,10 +239,16 @@ func (m *SectorStateMgr) refreshState(ctx context.Context) (*SectorStateUpdates,
return nil, err
}

allSet, err := m.fullnodeApi.StateMinerSectors(ctx, m.Maddr, nil, head.Key())
if err != nil {
return nil, err
}

mid, err := address.IDFromAddress(m.Maddr)
if err != nil {
return nil, err
}

activeSectors := make(map[abi.SectorID]struct{}, len(activeSet))
for _, info := range activeSet {
sectorID := abi.SectorID{
Expand All @@ -251,5 +259,18 @@ func (m *SectorStateMgr) refreshState(ctx context.Context) (*SectorStateUpdates,
activeSectors[sectorID] = struct{}{}
}

return &SectorStateUpdates{sectorUpdates, activeSectors, allSectorStates, time.Now()}, nil
sectorWithDeals := make(map[abi.SectorID]struct{})
zero := big.Zero()
for _, info := range allSet {
sectorID := abi.SectorID{
Miner: abi.ActorID(mid),
Number: info.SectorNumber,
}

if info.DealWeight.GreaterThan(zero) {
sectorWithDeals[sectorID] = struct{}{}
}
}

return &SectorStateUpdates{sectorUpdates, activeSectors, sectorWithDeals, allSectorStates, time.Now()}, nil
}

0 comments on commit d8ec5b7

Please sign in to comment.