Skip to content

Commit 662f8e2

Browse files
authored
fix(cli): make lotus-miner sectors extend command resilient to higher gas (#11928)
1 parent b05d3c9 commit 662f8e2

File tree

3 files changed

+76
-81
lines changed

3 files changed

+76
-81
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
- default to ProveCommit aggregation
3333
- remove config options: AggregateCommits, AggregateAboveBaseFee, BatchPreCommitAboveBaseFee
3434
- 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))
35+
- fix(cli): make lotus-miner sectors extend command resilient to higher gas ([filecoin-project/lotus#11927](https://github.com/filecoin-project/lotus/pull/11928))
3536

3637
# Node v1.33.0 / 2025-05-08
3738
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: 74 additions & 80 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",
@@ -874,103 +875,96 @@ func SectorsExtendCmd(getActorAddress ActorAddressGetter) *cli.Command {
874875

875876
var params []miner.ExtendSectorExpiration2Params
876877

877-
p := miner.ExtendSectorExpiration2Params{}
878-
scount := 0
879-
880878
for l, exts := range extensions {
881879
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]
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+
p := miner.ExtendSectorExpiration2Params{}
895+
896+
for _, sectorNumber := range batch {
897+
claimIdsToMaintain := make([]verifreg.ClaimId, 0)
898+
claimIdsToDrop := make([]verifreg.ClaimId, 0)
899+
cannotExtendSector := false
900+
claimIds, ok := claimIdsBySector[sectorNumber]
901+
// Nothing to check, add to ccSectors
902+
if !ok {
903+
sectorsWithoutClaimsToExtend.Set(uint64(sectorNumber))
904+
numbersToExtend = append(numbersToExtend, sectorNumber)
905+
} else {
906+
for _, claimId := range claimIds {
907+
claim, ok := claimsMap[claimId]
906908
if !ok {
907-
return xerrors.Errorf("failed to find sector in active sector set: %w", err)
909+
return xerrors.Errorf("failed to find claim for claimId %d", claimId)
908910
}
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
911+
claimExpiration := claim.TermStart + claim.TermMax
912+
// can be maintained in the extended sector
913+
if claimExpiration > newExp {
914+
claimIdsToMaintain = append(claimIdsToMaintain, claimId)
915+
} else {
916+
sectorInfo, ok := activeSectorsInfo[sectorNumber]
917+
if !ok {
918+
return xerrors.Errorf("failed to find sector in active sector set: %w", err)
919+
}
920+
if !cctx.Bool("drop-claims") {
921+
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)
922+
cannotExtendSector = true
923+
break
924+
} else if currEpoch <= (claim.TermStart + claim.TermMin) {
925+
// FIP-0045 requires the claim minimum duration to have passed
926+
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)
927+
cannotExtendSector = true
928+
break
929+
} else if currEpoch <= sectorInfo.Expiration-builtin.EndOfLifeClaimDropPeriod {
930+
// FIP-0045 requires the sector to be in its last 30 days of life
931+
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)
932+
cannotExtendSector = true
933+
break
934+
}
935+
936+
claimIdsToDrop = append(claimIdsToDrop, claimId)
923937
}
924938

925-
claimIdsToDrop = append(claimIdsToDrop, claimId)
939+
numbersToExtend = append(numbersToExtend, sectorNumber)
940+
}
941+
if cannotExtendSector {
942+
continue
926943
}
927944

928-
numbersToExtend = append(numbersToExtend, sectorNumber)
929-
}
930-
if cannotExtendSector {
931-
continue
932-
}
933-
934-
if len(claimIdsToMaintain)+len(claimIdsToDrop) != 0 {
935-
sectorsWithClaims = append(sectorsWithClaims, miner.SectorClaim{
936-
SectorNumber: sectorNumber,
937-
MaintainClaims: claimIdsToMaintain,
938-
DropClaims: claimIdsToDrop,
939-
})
945+
if len(claimIdsToMaintain)+len(claimIdsToDrop) != 0 {
946+
sectorsWithClaims = append(sectorsWithClaims, miner.SectorClaim{
947+
SectorNumber: sectorNumber,
948+
MaintainClaims: claimIdsToMaintain,
949+
DropClaims: claimIdsToDrop,
950+
})
951+
}
940952
}
941953
}
942-
}
943-
944-
sectorsWithoutClaimsCount, err := sectorsWithoutClaimsToExtend.Count()
945-
if err != nil {
946-
return xerrors.Errorf("failed to count cc sectors: %w", err)
947-
}
948954

949-
sectorsInDecl := int(sectorsWithoutClaimsCount) + len(sectorsWithClaims)
950-
scount += sectorsInDecl
951-
952-
if scount > addrSectors || len(p.Extensions) >= policy.DeclarationsMax {
955+
p.Extensions = append(p.Extensions, miner.ExpirationExtension2{
956+
Deadline: l.Deadline,
957+
Partition: l.Partition,
958+
Sectors: SectorNumsToBitfield(numbersToExtend),
959+
SectorsWithClaims: sectorsWithClaims,
960+
NewExpiration: newExp,
961+
})
953962
params = append(params, p)
954-
p = miner.ExtendSectorExpiration2Params{}
955-
scount = sectorsInDecl
956963
}
957964

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-
966965
}
967966
}
968967

969-
// if we have any sectors, then one last append is needed here
970-
if scount != 0 {
971-
params = append(params, p)
972-
}
973-
974968
if len(params) == 0 {
975969
fmt.Println("nothing to extend")
976970
return nil

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)