Skip to content

Commit b4cf0ad

Browse files
committed
fix sectors extend
1 parent 06515b6 commit b4cf0ad

File tree

3 files changed

+86
-71
lines changed

3 files changed

+86
-71
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
- default to ProveCommit aggregation
3232
- remove config options: AggregateCommits, AggregateAboveBaseFee, BatchPreCommitAboveBaseFee
3333
- feat(paych): add EnablePaymentChannelManager config option and disable payment channel manager by default ([filecoin-project/lotus#13139](https://github.com/filecoin-project/lotus/pull/13139))
34+
- fix: cli: lotus-miner sectors extend command ([filecoin-project/lotus#11927](https://github.com/filecoin-project/lotus/pull/11928))
3435

3536
# Node v1.33.0 / 2025-05-08
3637
The Lotus v1.33.0 release introduces experimental v2 APIs with F3 awareness, featuring a new TipSet selection mechanism that significantly enhances how applications interact with the Filecoin blockchain. This release candidate also adds F3-aware Ethereum APIs via the /v2 endpoint. All of the /v2 APIs implement intelligent fallback mechanisms between F3 and Expected Consensus and are exposed through the Lotus Gateway.

cli/spcli/sectors.go

Lines changed: 84 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ func SectorsExtendCmd(getActorAddress ActorAddressGetter) *cli.Command {
627627
&cli.Int64Flag{
628628
Name: "max-sectors",
629629
Usage: "the maximum number of sectors contained in each message",
630+
Value: 500,
630631
},
631632
&cli.BoolFlag{
632633
Name: "really-do-it",
@@ -879,90 +880,103 @@ func SectorsExtendCmd(getActorAddress ActorAddressGetter) *cli.Command {
879880

880881
for l, exts := range extensions {
881882
for newExp, numbers := range exts {
882-
sectorsWithoutClaimsToExtend := bitfield.New()
883-
numbersToExtend := make([]abi.SectorNumber, 0, len(numbers))
884-
var sectorsWithClaims []miner.SectorClaim
885-
for _, sectorNumber := range numbers {
886-
claimIdsToMaintain := make([]verifreg.ClaimId, 0)
887-
claimIdsToDrop := make([]verifreg.ClaimId, 0)
888-
cannotExtendSector := false
889-
claimIds, ok := claimIdsBySector[sectorNumber]
890-
// Nothing to check, add to ccSectors
891-
if !ok {
892-
sectorsWithoutClaimsToExtend.Set(uint64(sectorNumber))
893-
numbersToExtend = append(numbersToExtend, sectorNumber)
894-
} else {
895-
for _, claimId := range claimIds {
896-
claim, ok := claimsMap[claimId]
897-
if !ok {
898-
return xerrors.Errorf("failed to find claim for claimId %d", claimId)
899-
}
900-
claimExpiration := claim.TermStart + claim.TermMax
901-
// can be maintained in the extended sector
902-
if claimExpiration > newExp {
903-
claimIdsToMaintain = append(claimIdsToMaintain, claimId)
904-
} else {
905-
sectorInfo, ok := activeSectorsInfo[sectorNumber]
883+
batchSize := addrSectors
884+
885+
// The unfortunate thing about this approach is that batches less than batchSize in different partitions cannot be aggregated together to send messages.
886+
for i := 0; i < len(numbers); i += batchSize {
887+
end := i + batchSize
888+
if end > len(numbers) {
889+
end = len(numbers)
890+
}
891+
892+
batch := numbers[i:end]
893+
894+
sectorsWithoutClaimsToExtend := bitfield.New()
895+
numbersToExtend := make([]abi.SectorNumber, 0, len(numbers))
896+
var sectorsWithClaims []miner.SectorClaim
897+
898+
for _, sectorNumber := range batch {
899+
claimIdsToMaintain := make([]verifreg.ClaimId, 0)
900+
claimIdsToDrop := make([]verifreg.ClaimId, 0)
901+
cannotExtendSector := false
902+
claimIds, ok := claimIdsBySector[sectorNumber]
903+
// Nothing to check, add to ccSectors
904+
if !ok {
905+
sectorsWithoutClaimsToExtend.Set(uint64(sectorNumber))
906+
numbersToExtend = append(numbersToExtend, sectorNumber)
907+
} else {
908+
for _, claimId := range claimIds {
909+
claim, ok := claimsMap[claimId]
906910
if !ok {
907-
return xerrors.Errorf("failed to find sector in active sector set: %w", err)
911+
return xerrors.Errorf("failed to find claim for claimId %d", claimId)
908912
}
909-
if !cctx.Bool("drop-claims") {
910-
fmt.Printf("skipping sector %d because claim %d (client f0%s, piece %s) cannot be maintained in the extended sector (use --drop-claims to drop claims)\n", sectorNumber, claimId, claim.Client, claim.Data)
911-
cannotExtendSector = true
912-
break
913-
} else if currEpoch <= (claim.TermStart + claim.TermMin) {
914-
// FIP-0045 requires the claim minimum duration to have passed
915-
fmt.Printf("skipping sector %d because claim %d (client f0%s, piece %s) has not reached its minimum duration\n", sectorNumber, claimId, claim.Client, claim.Data)
916-
cannotExtendSector = true
917-
break
918-
} else if currEpoch <= sectorInfo.Expiration-builtin.EndOfLifeClaimDropPeriod {
919-
// FIP-0045 requires the sector to be in its last 30 days of life
920-
fmt.Printf("skipping sector %d because claim %d (client f0%s, piece %s) is not in its last 30 days of life\n", sectorNumber, claimId, claim.Client, claim.Data)
921-
cannotExtendSector = true
922-
break
913+
claimExpiration := claim.TermStart + claim.TermMax
914+
// can be maintained in the extended sector
915+
if claimExpiration > newExp {
916+
claimIdsToMaintain = append(claimIdsToMaintain, claimId)
917+
} else {
918+
sectorInfo, ok := activeSectorsInfo[sectorNumber]
919+
if !ok {
920+
return xerrors.Errorf("failed to find sector in active sector set: %w", err)
921+
}
922+
if !cctx.Bool("drop-claims") {
923+
fmt.Printf("skipping sector %d because claim %d (client f0%s, piece %s) cannot be maintained in the extended sector (use --drop-claims to drop claims)\n", sectorNumber, claimId, claim.Client, claim.Data)
924+
cannotExtendSector = true
925+
break
926+
} else if currEpoch <= (claim.TermStart + claim.TermMin) {
927+
// FIP-0045 requires the claim minimum duration to have passed
928+
fmt.Printf("skipping sector %d because claim %d (client f0%s, piece %s) has not reached its minimum duration\n", sectorNumber, claimId, claim.Client, claim.Data)
929+
cannotExtendSector = true
930+
break
931+
} else if currEpoch <= sectorInfo.Expiration-builtin.EndOfLifeClaimDropPeriod {
932+
// FIP-0045 requires the sector to be in its last 30 days of life
933+
fmt.Printf("skipping sector %d because claim %d (client f0%s, piece %s) is not in its last 30 days of life\n", sectorNumber, claimId, claim.Client, claim.Data)
934+
cannotExtendSector = true
935+
break
936+
}
937+
938+
claimIdsToDrop = append(claimIdsToDrop, claimId)
923939
}
924940

925-
claimIdsToDrop = append(claimIdsToDrop, claimId)
941+
numbersToExtend = append(numbersToExtend, sectorNumber)
942+
}
943+
if cannotExtendSector {
944+
continue
926945
}
927946

928-
numbersToExtend = append(numbersToExtend, sectorNumber)
929-
}
930-
if cannotExtendSector {
931-
continue
947+
if len(claimIdsToMaintain)+len(claimIdsToDrop) != 0 {
948+
sectorsWithClaims = append(sectorsWithClaims, miner.SectorClaim{
949+
SectorNumber: sectorNumber,
950+
MaintainClaims: claimIdsToMaintain,
951+
DropClaims: claimIdsToDrop,
952+
})
953+
}
932954
}
955+
}
933956

934-
if len(claimIdsToMaintain)+len(claimIdsToDrop) != 0 {
935-
sectorsWithClaims = append(sectorsWithClaims, miner.SectorClaim{
936-
SectorNumber: sectorNumber,
937-
MaintainClaims: claimIdsToMaintain,
938-
DropClaims: claimIdsToDrop,
939-
})
940-
}
957+
sectorsWithoutClaimsCount, err := sectorsWithoutClaimsToExtend.Count()
958+
if err != nil {
959+
return xerrors.Errorf("failed to count cc sectors: %w", err)
941960
}
942-
}
943961

944-
sectorsWithoutClaimsCount, err := sectorsWithoutClaimsToExtend.Count()
945-
if err != nil {
946-
return xerrors.Errorf("failed to count cc sectors: %w", err)
947-
}
962+
sectorsInDecl := int(sectorsWithoutClaimsCount) + len(sectorsWithClaims)
963+
scount += sectorsInDecl
948964

949-
sectorsInDecl := int(sectorsWithoutClaimsCount) + len(sectorsWithClaims)
950-
scount += sectorsInDecl
965+
if scount > addrSectors || len(p.Extensions) >= policy.DeclarationsMax {
966+
params = append(params, p)
967+
p = miner.ExtendSectorExpiration2Params{}
968+
scount = sectorsInDecl
969+
}
951970

952-
if scount > addrSectors || len(p.Extensions) >= policy.DeclarationsMax {
953-
params = append(params, p)
954-
p = miner.ExtendSectorExpiration2Params{}
955-
scount = sectorsInDecl
971+
p.Extensions = append(p.Extensions, miner.ExpirationExtension2{
972+
Deadline: l.Deadline,
973+
Partition: l.Partition,
974+
Sectors: SectorNumsToBitfield(numbersToExtend),
975+
SectorsWithClaims: sectorsWithClaims,
976+
NewExpiration: newExp,
977+
})
956978
}
957979

958-
p.Extensions = append(p.Extensions, miner.ExpirationExtension2{
959-
Deadline: l.Deadline,
960-
Partition: l.Partition,
961-
Sectors: SectorNumsToBitfield(numbersToExtend),
962-
SectorsWithClaims: sectorsWithClaims,
963-
NewExpiration: newExp,
964-
})
965-
966980
}
967981
}
968982

documentation/en/cli-lotus-miner.md

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)