Skip to content

Commit

Permalink
fix sectors extend && make docsgen-cli
Browse files Browse the repository at this point in the history
  • Loading branch information
beck-8 committed Jun 3, 2024
1 parent f907354 commit 5349448
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 66 deletions.
142 changes: 78 additions & 64 deletions cli/spcli/sectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ func SectorsExtendCmd(getActorAddress ActorAddressGetter) *cli.Command {
&cli.Int64Flag{
Name: "max-sectors",
Usage: "the maximum number of sectors contained in each message",
Value: 500,
},
&cli.BoolFlag{
Name: "really-do-it",
Expand Down Expand Up @@ -876,84 +877,97 @@ func SectorsExtendCmd(getActorAddress ActorAddressGetter) *cli.Command {

for l, exts := range extensions {
for newExp, numbers := range exts {
sectorsWithoutClaimsToExtend := bitfield.New()
numbersToExtend := make([]abi.SectorNumber, 0, len(numbers))
var sectorsWithClaims []miner.SectorClaim
for _, sectorNumber := range numbers {
claimIdsToMaintain := make([]verifreg.ClaimId, 0)
claimIdsToDrop := make([]verifreg.ClaimId, 0)
cannotExtendSector := false
claimIds, ok := claimIdsBySector[sectorNumber]
// Nothing to check, add to ccSectors
if !ok {
sectorsWithoutClaimsToExtend.Set(uint64(sectorNumber))
numbersToExtend = append(numbersToExtend, sectorNumber)
} else {
for _, claimId := range claimIds {
claim, ok := claimsMap[claimId]
if !ok {
return xerrors.Errorf("failed to find claim for claimId %d", claimId)
}
claimExpiration := claim.TermStart + claim.TermMax
// can be maintained in the extended sector
if claimExpiration > newExp {
claimIdsToMaintain = append(claimIdsToMaintain, claimId)
} else {
sectorInfo, ok := activeSectorsInfo[sectorNumber]
batchSize := addrSectors

// The unfortunate thing about this approach is that batches less than batchSize in different partitions cannot be aggregated together to send messages.
for i := 0; i < len(numbers); i += batchSize {
end := i + batchSize
if end > len(numbers) {
end = len(numbers)
}

batch := numbers[i:end]

sectorsWithoutClaimsToExtend := bitfield.New()
numbersToExtend := make([]abi.SectorNumber, 0, len(numbers))
var sectorsWithClaims []miner.SectorClaim

for _, sectorNumber := range batch {
claimIdsToMaintain := make([]verifreg.ClaimId, 0)
claimIdsToDrop := make([]verifreg.ClaimId, 0)
cannotExtendSector := false
claimIds, ok := claimIdsBySector[sectorNumber]
// Nothing to check, add to ccSectors
if !ok {
sectorsWithoutClaimsToExtend.Set(uint64(sectorNumber))
numbersToExtend = append(numbersToExtend, sectorNumber)
} else {
for _, claimId := range claimIds {
claim, ok := claimsMap[claimId]
if !ok {
return xerrors.Errorf("failed to find sector in active sector set: %w", err)
return xerrors.Errorf("failed to find claim for claimId %d", claimId)
}
if !cctx.Bool("drop-claims") ||
// FIP-0045 requires the claim minimum duration to have passed
currEpoch <= (claim.TermStart+claim.TermMin) ||
// FIP-0045 requires the sector to be in its last 30 days of life
(currEpoch <= sectorInfo.Expiration-builtin.EndOfLifeClaimDropPeriod) {
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)
cannotExtendSector = true
break
claimExpiration := claim.TermStart + claim.TermMax
// can be maintained in the extended sector
if claimExpiration > newExp {
claimIdsToMaintain = append(claimIdsToMaintain, claimId)
} else {
sectorInfo, ok := activeSectorsInfo[sectorNumber]
if !ok {
return xerrors.Errorf("failed to find sector in active sector set: %w", err)
}
if !cctx.Bool("drop-claims") ||
// FIP-0045 requires the claim minimum duration to have passed
currEpoch <= (claim.TermStart+claim.TermMin) ||
// FIP-0045 requires the sector to be in its last 30 days of life
(currEpoch <= sectorInfo.Expiration-builtin.EndOfLifeClaimDropPeriod) {
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)
cannotExtendSector = true
break
}

claimIdsToDrop = append(claimIdsToDrop, claimId)
}

claimIdsToDrop = append(claimIdsToDrop, claimId)
numbersToExtend = append(numbersToExtend, sectorNumber)
}
if cannotExtendSector {
continue
}

numbersToExtend = append(numbersToExtend, sectorNumber)
}
if cannotExtendSector {
continue
if len(claimIdsToMaintain)+len(claimIdsToDrop) != 0 {
sectorsWithClaims = append(sectorsWithClaims, miner.SectorClaim{
SectorNumber: sectorNumber,
MaintainClaims: claimIdsToMaintain,
DropClaims: claimIdsToDrop,
})
}
}
}

if len(claimIdsToMaintain)+len(claimIdsToDrop) != 0 {
sectorsWithClaims = append(sectorsWithClaims, miner.SectorClaim{
SectorNumber: sectorNumber,
MaintainClaims: claimIdsToMaintain,
DropClaims: claimIdsToDrop,
})
}
sectorsWithoutClaimsCount, err := sectorsWithoutClaimsToExtend.Count()
if err != nil {
return xerrors.Errorf("failed to count cc sectors: %w", err)
}
}

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

sectorsInDecl := int(sectorsWithoutClaimsCount) + len(sectorsWithClaims)
scount += sectorsInDecl
if scount > addrSectors || len(p.Extensions) >= declMax {
params = append(params, p)
p = miner.ExtendSectorExpiration2Params{}
scount = sectorsInDecl
}

if scount > addrSectors || len(p.Extensions) >= declMax {
params = append(params, p)
p = miner.ExtendSectorExpiration2Params{}
scount = sectorsInDecl
p.Extensions = append(p.Extensions, miner.ExpirationExtension2{
Deadline: l.Deadline,
Partition: l.Partition,
Sectors: SectorNumsToBitfield(numbersToExtend),
SectorsWithClaims: sectorsWithClaims,
NewExpiration: newExp,
})
}

p.Extensions = append(p.Extensions, miner.ExpirationExtension2{
Deadline: l.Deadline,
Partition: l.Partition,
Sectors: SectorNumsToBitfield(numbersToExtend),
SectorsWithClaims: sectorsWithClaims,
NewExpiration: newExp,
})

}
}

Expand Down
2 changes: 1 addition & 1 deletion documentation/en/cli-lotus-miner.md
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ OPTIONS:
--drop-claims drop claims for sectors that can be extended, but only by dropping some of their verified power claims (default: false)
--tolerance value don't try to extend sectors by fewer than this number of epochs, defaults to 7 days (default: 20160)
--max-fee value use up to this amount of FIL for one message. pass this flag to avoid message congestion. (default: "0")
--max-sectors value the maximum number of sectors contained in each message (default: 0)
--max-sectors value the maximum number of sectors contained in each message (default: 500)
--really-do-it pass this flag to really extend sectors, otherwise will only print out json representation of parameters (default: false)
--help, -h show help
```
Expand Down
2 changes: 1 addition & 1 deletion documentation/en/cli-sptool.md
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ OPTIONS:
--drop-claims drop claims for sectors that can be extended, but only by dropping some of their verified power claims (default: false)
--tolerance value don't try to extend sectors by fewer than this number of epochs, defaults to 7 days (default: 20160)
--max-fee value use up to this amount of FIL for one message. pass this flag to avoid message congestion. (default: "0")
--max-sectors value the maximum number of sectors contained in each message (default: 0)
--max-sectors value the maximum number of sectors contained in each message (default: 500)
--really-do-it pass this flag to really extend sectors, otherwise will only print out json representation of parameters (default: false)
--help, -h show help
```
Expand Down

0 comments on commit 5349448

Please sign in to comment.