v1.27.0-a #10

Closed
jonathanface wants to merge 473 commits from v1.27.0-a into master
3 changed files with 114 additions and 215 deletions
Showing only changes of commit d1a52cf04d - Show all commits

View File

@ -15,7 +15,6 @@ import (
"go.opencensus.io/tag"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/lotus/journal/alerting"
@ -578,53 +577,24 @@ func (dbi *DBIndex) StorageFindSector(ctx context.Context, s abi.SectorID, ft st
log.Debugf("not selecting on %s, not allowed by file type filters", row.StorageId)
continue
}
if len(row.AllowMiners) > 0 {
found := false
allowMiners := splitString(row.AllowMiners)
for _, m := range allowMiners {
m := m
maddr, err := address.NewFromString(m)
proceed, err := MinerFilter(allowMiners, false, s.Miner)
if err != nil {
return nil, xerrors.Errorf("parsing miner address: %w", err)
return nil, err
}
mid, err := address.IDFromAddress(maddr)
if err != nil {
return nil, xerrors.Errorf("parsing miner ID: %w", err)
}
if abi.ActorID(mid) == s.Miner {
found = true
break
}
}
if !found {
log.Debugf("not selecting on %s, not allowed by allow miners filters", row.StorageId)
if !proceed {
log.Debugf("not allocating on %s, miner %s not allowed", row.StorageId, s.Miner.String())
continue
}
}
if len(row.DenyMiners) > 0 {
found := false
denyMiners := splitString(row.DenyMiners)
for _, m := range denyMiners {
m := m
maddr, err := address.NewFromString(m)
proceed, err = MinerFilter(denyMiners, true, s.Miner)
if err != nil {
return nil, xerrors.Errorf("parsing miner address: %w", err)
return nil, err
}
mid, err := address.IDFromAddress(maddr)
if err != nil {
return nil, xerrors.Errorf("parsing miner ID: %w", err)
}
if abi.ActorID(mid) == s.Miner {
found = true
break
}
}
if found {
log.Debugf("not selecting on %s, not allowed by deny miners filters", row.StorageId)
if !proceed {
log.Debugf("not allocating on %s, miner %s denied", row.StorageId, s.Miner.String())
continue
}
}
if allowList != nil {
groups := splitString(row.Groups)
@ -776,51 +746,25 @@ func (dbi *DBIndex) StorageBestAlloc(ctx context.Context, allocate storiface.Sec
// Matching with 0 as a workaround to avoid having minerID
// present when calling TaskStorage.HasCapacity()
if !(miner == abi.ActorID(0)) {
if len(row.AllowMiners) > 0 {
found := false
allowMiners := splitString(row.AllowMiners)
for _, m := range allowMiners {
m := m
maddr, err := address.NewFromString(m)
proceed, err := MinerFilter(allowMiners, false, miner)
if err != nil {
return nil, xerrors.Errorf("parsing miner address: %w", err)
return nil, err
}
mid, err := address.IDFromAddress(maddr)
if err != nil {
return nil, xerrors.Errorf("parsing miner ID: %w", err)
}
if abi.ActorID(mid) == miner {
found = true
break
}
}
if !found {
if !proceed {
log.Debugf("not allocating on %s, miner %s not allowed", row.StorageId, miner.String())
continue
}
}
if len(row.DenyMiners) > 0 {
found := false
denyMiners := splitString(row.DenyMiners)
for _, m := range denyMiners {
m := m
maddr, err := address.NewFromString(m)
proceed, err = MinerFilter(denyMiners, true, miner)
if err != nil {
return nil, xerrors.Errorf("parsing miner address: %w", err)
return nil, err
}
mid, err := address.IDFromAddress(maddr)
if err != nil {
return nil, xerrors.Errorf("parsing miner ID: %w", err)
}
if abi.ActorID(mid) == miner {
found = true
break
}
}
if found {
if !proceed {
log.Debugf("not allocating on %s, miner %s denied", row.StorageId, miner.String())
continue
}
}
}
result = append(result, storiface.StorageInfo{
ID: storiface.ID(row.StorageId),

View File

@ -498,51 +498,25 @@ func (i *MemIndex) StorageFindSector(ctx context.Context, s abi.SectorID, ft sto
continue
}
if len(st.info.AllowMiners) > 0 {
found := false
for _, m := range st.info.AllowMiners {
minerIDStr := m
maddr, err := address.NewFromString(minerIDStr)
proceed, err := MinerFilter(st.info.AllowMiners, false, s.Miner)
if err != nil {
return nil, xerrors.Errorf("parsing miner address: %w", err)
return nil, err
}
mid, err := address.IDFromAddress(maddr)
if err != nil {
return nil, xerrors.Errorf("converting miner address to ID: %w", err)
}
if abi.ActorID(mid) == s.Miner {
found = true
break
}
}
if !found {
if !proceed {
log.Debugf("not allocating on %s, miner %s not allowed", st.info.ID, s.Miner.String())
continue
}
proceed, err = MinerFilter(st.info.DenyMiners, true, s.Miner)
if err != nil {
return nil, err
}
if len(st.info.DenyMiners) > 0 {
found := false
for _, m := range st.info.DenyMiners {
minerIDStr := m
maddr, err := address.NewFromString(minerIDStr)
if err != nil {
return nil, xerrors.Errorf("parsing miner address: %w", err)
}
mid, err := address.IDFromAddress(maddr)
if err != nil {
return nil, xerrors.Errorf("converting miner address to ID: %w", err)
}
if abi.ActorID(mid) == s.Miner {
found = true
break
}
}
if found {
if !proceed {
log.Debugf("not allocating on %s, miner %s denied", st.info.ID, s.Miner.String())
continue
}
}
if spaceReq > uint64(st.fsi.Available) {
log.Debugf("not selecting on %s, out of space (available: %d, need: %d)", st.info.ID, st.fsi.Available, spaceReq)
@ -699,51 +673,25 @@ func (i *MemIndex) StorageBestAlloc(ctx context.Context, allocate storiface.Sect
continue
}
if len(p.info.AllowMiners) > 0 {
found := false
for _, m := range p.info.AllowMiners {
minerIDStr := m
maddr, err := address.NewFromString(minerIDStr)
proceed, err := MinerFilter(p.info.AllowMiners, false, miner)
if err != nil {
return nil, xerrors.Errorf("parsing miner address: %w", err)
return nil, err
}
mid, err := address.IDFromAddress(maddr)
if err != nil {
return nil, xerrors.Errorf("converting miner address to ID: %w", err)
}
if abi.ActorID(mid) == miner {
found = true
break
}
}
if !found {
if !proceed {
log.Debugf("not allocating on %s, miner %s not allowed", p.info.ID, miner.String())
continue
}
proceed, err = MinerFilter(p.info.DenyMiners, true, miner)
if err != nil {
return nil, err
}
if len(p.info.DenyMiners) > 0 {
found := false
for _, m := range p.info.DenyMiners {
minerIDStr := m
maddr, err := address.NewFromString(minerIDStr)
if err != nil {
return nil, xerrors.Errorf("parsing miner address: %w", err)
}
mid, err := address.IDFromAddress(maddr)
if err != nil {
return nil, xerrors.Errorf("converting miner address to ID: %w", err)
}
if abi.ActorID(mid) == miner {
found = true
break
}
}
if found {
if !proceed {
log.Debugf("not allocating on %s, miner %s denied", p.info.ID, miner.String())
continue
}
}
if spaceReq > uint64(p.fsi.Available) {
log.Debugf("not allocating on %s, out of space (available: %d, need: %d)", p.info.ID, p.fsi.Available, spaceReq)
@ -802,3 +750,41 @@ func (i *MemIndex) FindSector(id abi.SectorID, typ storiface.SectorFileType) ([]
}
var _ SectorIndex = &MemIndex{}
func MinerFilter(miners []string, deny bool, miner abi.ActorID) (bool, error) {
if len(miners) > 0 {
found := false
for _, m := range miners {
minerIDStr := m
maddr, err := address.NewFromString(minerIDStr)
if err != nil {
return false, xerrors.Errorf("parsing miner address: %w", err)
}
mid, err := address.IDFromAddress(maddr)
if err != nil {
return false, xerrors.Errorf("converting miner address to ID: %w", err)
}
if abi.ActorID(mid) == miner {
found = true
break
}
}
// If not found in list
if !found {
// If this is allowed list
if !deny {
return false, nil
}
// If this is denied list
return true, nil
}
// If found in list and
// If this is allowed list
if !deny {
return true, nil
}
// If this is denied list
return false, nil
}
return true, nil
}

View File

@ -14,7 +14,6 @@ import (
"golang.org/x/xerrors"
ffi "github.com/filecoin-project/filecoin-ffi"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/abi"
"github.com/filecoin-project/go-state-types/proof"
@ -512,50 +511,20 @@ func (st *Local) AcquireSector(ctx context.Context, sid storiface.SectorRef, exi
if !fileType.Allowed(allowTypes, denyTypes) {
return false, nil
}
if len(allowMiners) > 0 {
found := false
for _, m := range allowMiners {
minerIDStr := m
maddr, err := address.NewFromString(minerIDStr)
proceed, err := MinerFilter(allowMiners, false, miner)
if err != nil {
return false, xerrors.Errorf("parsing miner address: %w", err)
return false, err
}
mid, err := address.IDFromAddress(maddr)
if err != nil {
return false, xerrors.Errorf("converting miner address to ID: %w", err)
}
if abi.ActorID(mid) == miner {
found = true
break
}
}
if !found {
if !proceed {
return false, nil
}
}
if len(denyMiners) > 0 {
found := false
for _, m := range denyMiners {
minerIDStr := m
maddr, err := address.NewFromString(minerIDStr)
proceed, err = MinerFilter(denyMiners, true, miner)
if err != nil {
return false, xerrors.Errorf("parsing miner address: %w", err)
return false, err
}
mid, err := address.IDFromAddress(maddr)
if err != nil {
return false, xerrors.Errorf("converting miner address to ID: %w", err)
}
if abi.ActorID(mid) == miner {
found = true
break
}
}
if found {
if !proceed {
return false, nil
}
}
return true, nil
}