Skip to content

Commit 12e188c

Browse files
committed
fix sectors extend
1 parent f907354 commit 12e188c

File tree

1 file changed

+76
-64
lines changed

1 file changed

+76
-64
lines changed

cli/spcli/sectors.go

+76-64
Original file line numberDiff line numberDiff line change
@@ -876,84 +876,96 @@ func SectorsExtendCmd(getActorAddress ActorAddressGetter) *cli.Command {
876876

877877
for l, exts := range extensions {
878878
for newExp, numbers := range exts {
879-
sectorsWithoutClaimsToExtend := bitfield.New()
880-
numbersToExtend := make([]abi.SectorNumber, 0, len(numbers))
881-
var sectorsWithClaims []miner.SectorClaim
882-
for _, sectorNumber := range numbers {
883-
claimIdsToMaintain := make([]verifreg.ClaimId, 0)
884-
claimIdsToDrop := make([]verifreg.ClaimId, 0)
885-
cannotExtendSector := false
886-
claimIds, ok := claimIdsBySector[sectorNumber]
887-
// Nothing to check, add to ccSectors
888-
if !ok {
889-
sectorsWithoutClaimsToExtend.Set(uint64(sectorNumber))
890-
numbersToExtend = append(numbersToExtend, sectorNumber)
891-
} else {
892-
for _, claimId := range claimIds {
893-
claim, ok := claimsMap[claimId]
894-
if !ok {
895-
return xerrors.Errorf("failed to find claim for claimId %d", claimId)
896-
}
897-
claimExpiration := claim.TermStart + claim.TermMax
898-
// can be maintained in the extended sector
899-
if claimExpiration > newExp {
900-
claimIdsToMaintain = append(claimIdsToMaintain, claimId)
901-
} else {
902-
sectorInfo, ok := activeSectorsInfo[sectorNumber]
879+
batchSize := addrSectors
880+
881+
for i := 0; i < len(numbers); i += batchSize {
882+
end := i + batchSize
883+
if end > len(numbers) {
884+
end = len(numbers)
885+
}
886+
887+
batch := numbers[i:end]
888+
889+
sectorsWithoutClaimsToExtend := bitfield.New()
890+
numbersToExtend := make([]abi.SectorNumber, 0, len(numbers))
891+
var sectorsWithClaims []miner.SectorClaim
892+
893+
for _, sectorNumber := range batch {
894+
claimIdsToMaintain := make([]verifreg.ClaimId, 0)
895+
claimIdsToDrop := make([]verifreg.ClaimId, 0)
896+
cannotExtendSector := false
897+
claimIds, ok := claimIdsBySector[sectorNumber]
898+
// Nothing to check, add to ccSectors
899+
if !ok {
900+
sectorsWithoutClaimsToExtend.Set(uint64(sectorNumber))
901+
numbersToExtend = append(numbersToExtend, sectorNumber)
902+
} else {
903+
for _, claimId := range claimIds {
904+
claim, ok := claimsMap[claimId]
903905
if !ok {
904-
return xerrors.Errorf("failed to find sector in active sector set: %w", err)
906+
return xerrors.Errorf("failed to find claim for claimId %d", claimId)
905907
}
906-
if !cctx.Bool("drop-claims") ||
907-
// FIP-0045 requires the claim minimum duration to have passed
908-
currEpoch <= (claim.TermStart+claim.TermMin) ||
909-
// FIP-0045 requires the sector to be in its last 30 days of life
910-
(currEpoch <= sectorInfo.Expiration-builtin.EndOfLifeClaimDropPeriod) {
911-
fmt.Printf("skipping sector %d because claim %d (client f0%s, piece %s) does not live long enough \n", sectorNumber, claimId, claim.Client, claim.Data)
912-
cannotExtendSector = true
913-
break
908+
claimExpiration := claim.TermStart + claim.TermMax
909+
// can be maintained in the extended sector
910+
if claimExpiration > newExp {
911+
claimIdsToMaintain = append(claimIdsToMaintain, claimId)
912+
} else {
913+
sectorInfo, ok := activeSectorsInfo[sectorNumber]
914+
if !ok {
915+
return xerrors.Errorf("failed to find sector in active sector set: %w", err)
916+
}
917+
if !cctx.Bool("drop-claims") ||
918+
// FIP-0045 requires the claim minimum duration to have passed
919+
currEpoch <= (claim.TermStart+claim.TermMin) ||
920+
// FIP-0045 requires the sector to be in its last 30 days of life
921+
(currEpoch <= sectorInfo.Expiration-builtin.EndOfLifeClaimDropPeriod) {
922+
fmt.Printf("skipping sector %d because claim %d (client f0%s, piece %s) does not live long enough \n", sectorNumber, claimId, claim.Client, claim.Data)
923+
cannotExtendSector = true
924+
break
925+
}
926+
927+
claimIdsToDrop = append(claimIdsToDrop, claimId)
914928
}
915929

916-
claimIdsToDrop = append(claimIdsToDrop, claimId)
930+
numbersToExtend = append(numbersToExtend, sectorNumber)
931+
}
932+
if cannotExtendSector {
933+
continue
917934
}
918935

919-
numbersToExtend = append(numbersToExtend, sectorNumber)
920-
}
921-
if cannotExtendSector {
922-
continue
936+
if len(claimIdsToMaintain)+len(claimIdsToDrop) != 0 {
937+
sectorsWithClaims = append(sectorsWithClaims, miner.SectorClaim{
938+
SectorNumber: sectorNumber,
939+
MaintainClaims: claimIdsToMaintain,
940+
DropClaims: claimIdsToDrop,
941+
})
942+
}
923943
}
944+
}
924945

925-
if len(claimIdsToMaintain)+len(claimIdsToDrop) != 0 {
926-
sectorsWithClaims = append(sectorsWithClaims, miner.SectorClaim{
927-
SectorNumber: sectorNumber,
928-
MaintainClaims: claimIdsToMaintain,
929-
DropClaims: claimIdsToDrop,
930-
})
931-
}
946+
sectorsWithoutClaimsCount, err := sectorsWithoutClaimsToExtend.Count()
947+
if err != nil {
948+
return xerrors.Errorf("failed to count cc sectors: %w", err)
932949
}
933-
}
934950

935-
sectorsWithoutClaimsCount, err := sectorsWithoutClaimsToExtend.Count()
936-
if err != nil {
937-
return xerrors.Errorf("failed to count cc sectors: %w", err)
938-
}
951+
sectorsInDecl := int(sectorsWithoutClaimsCount) + len(sectorsWithClaims)
952+
scount += sectorsInDecl
939953

940-
sectorsInDecl := int(sectorsWithoutClaimsCount) + len(sectorsWithClaims)
941-
scount += sectorsInDecl
954+
if scount > addrSectors || len(p.Extensions) >= declMax {
955+
params = append(params, p)
956+
p = miner.ExtendSectorExpiration2Params{}
957+
scount = sectorsInDecl
958+
}
942959

943-
if scount > addrSectors || len(p.Extensions) >= declMax {
944-
params = append(params, p)
945-
p = miner.ExtendSectorExpiration2Params{}
946-
scount = sectorsInDecl
960+
p.Extensions = append(p.Extensions, miner.ExpirationExtension2{
961+
Deadline: l.Deadline,
962+
Partition: l.Partition,
963+
Sectors: SectorNumsToBitfield(numbersToExtend),
964+
SectorsWithClaims: sectorsWithClaims,
965+
NewExpiration: newExp,
966+
})
947967
}
948968

949-
p.Extensions = append(p.Extensions, miner.ExpirationExtension2{
950-
Deadline: l.Deadline,
951-
Partition: l.Partition,
952-
Sectors: SectorNumsToBitfield(numbersToExtend),
953-
SectorsWithClaims: sectorsWithClaims,
954-
NewExpiration: newExp,
955-
})
956-
957969
}
958970
}
959971

0 commit comments

Comments
 (0)