Skip to content

Commit 5349448

Browse files
committed
fix sectors extend && make docsgen-cli
1 parent f907354 commit 5349448

File tree

3 files changed

+80
-66
lines changed

3 files changed

+80
-66
lines changed

cli/spcli/sectors.go

+78-64
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ func SectorsExtendCmd(getActorAddress ActorAddressGetter) *cli.Command {
620620
&cli.Int64Flag{
621621
Name: "max-sectors",
622622
Usage: "the maximum number of sectors contained in each message",
623+
Value: 500,
623624
},
624625
&cli.BoolFlag{
625626
Name: "really-do-it",
@@ -876,84 +877,97 @@ func SectorsExtendCmd(getActorAddress ActorAddressGetter) *cli.Command {
876877

877878
for l, exts := range extensions {
878879
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]
880+
batchSize := addrSectors
881+
882+
// The unfortunate thing about this approach is that batches less than batchSize in different partitions cannot be aggregated together to send messages.
883+
for i := 0; i < len(numbers); i += batchSize {
884+
end := i + batchSize
885+
if end > len(numbers) {
886+
end = len(numbers)
887+
}
888+
889+
batch := numbers[i:end]
890+
891+
sectorsWithoutClaimsToExtend := bitfield.New()
892+
numbersToExtend := make([]abi.SectorNumber, 0, len(numbers))
893+
var sectorsWithClaims []miner.SectorClaim
894+
895+
for _, sectorNumber := range batch {
896+
claimIdsToMaintain := make([]verifreg.ClaimId, 0)
897+
claimIdsToDrop := make([]verifreg.ClaimId, 0)
898+
cannotExtendSector := false
899+
claimIds, ok := claimIdsBySector[sectorNumber]
900+
// Nothing to check, add to ccSectors
901+
if !ok {
902+
sectorsWithoutClaimsToExtend.Set(uint64(sectorNumber))
903+
numbersToExtend = append(numbersToExtend, sectorNumber)
904+
} else {
905+
for _, claimId := range claimIds {
906+
claim, ok := claimsMap[claimId]
903907
if !ok {
904-
return xerrors.Errorf("failed to find sector in active sector set: %w", err)
908+
return xerrors.Errorf("failed to find claim for claimId %d", claimId)
905909
}
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
910+
claimExpiration := claim.TermStart + claim.TermMax
911+
// can be maintained in the extended sector
912+
if claimExpiration > newExp {
913+
claimIdsToMaintain = append(claimIdsToMaintain, claimId)
914+
} else {
915+
sectorInfo, ok := activeSectorsInfo[sectorNumber]
916+
if !ok {
917+
return xerrors.Errorf("failed to find sector in active sector set: %w", err)
918+
}
919+
if !cctx.Bool("drop-claims") ||
920+
// FIP-0045 requires the claim minimum duration to have passed
921+
currEpoch <= (claim.TermStart+claim.TermMin) ||
922+
// FIP-0045 requires the sector to be in its last 30 days of life
923+
(currEpoch <= sectorInfo.Expiration-builtin.EndOfLifeClaimDropPeriod) {
924+
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)
925+
cannotExtendSector = true
926+
break
927+
}
928+
929+
claimIdsToDrop = append(claimIdsToDrop, claimId)
914930
}
915931

916-
claimIdsToDrop = append(claimIdsToDrop, claimId)
932+
numbersToExtend = append(numbersToExtend, sectorNumber)
933+
}
934+
if cannotExtendSector {
935+
continue
917936
}
918937

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

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

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

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

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

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-
957971
}
958972
}
959973

documentation/en/cli-lotus-miner.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ OPTIONS:
842842
--drop-claims drop claims for sectors that can be extended, but only by dropping some of their verified power claims (default: false)
843843
--tolerance value don't try to extend sectors by fewer than this number of epochs, defaults to 7 days (default: 20160)
844844
--max-fee value use up to this amount of FIL for one message. pass this flag to avoid message congestion. (default: "0")
845-
--max-sectors value the maximum number of sectors contained in each message (default: 0)
845+
--max-sectors value the maximum number of sectors contained in each message (default: 500)
846846
--really-do-it pass this flag to really extend sectors, otherwise will only print out json representation of parameters (default: false)
847847
--help, -h show help
848848
```

documentation/en/cli-sptool.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ OPTIONS:
368368
--drop-claims drop claims for sectors that can be extended, but only by dropping some of their verified power claims (default: false)
369369
--tolerance value don't try to extend sectors by fewer than this number of epochs, defaults to 7 days (default: 20160)
370370
--max-fee value use up to this amount of FIL for one message. pass this flag to avoid message congestion. (default: "0")
371-
--max-sectors value the maximum number of sectors contained in each message (default: 0)
371+
--max-sectors value the maximum number of sectors contained in each message (default: 500)
372372
--really-do-it pass this flag to really extend sectors, otherwise will only print out json representation of parameters (default: false)
373373
--help, -h show help
374374
```

0 commit comments

Comments
 (0)