From 53494485b085c3b1ca93d1e9246265e568b6fc01 Mon Sep 17 00:00:00 2001 From: beck-8 <1504068285@qq.com> Date: Mon, 3 Jun 2024 21:35:37 +0800 Subject: [PATCH] fix sectors extend && make docsgen-cli --- cli/spcli/sectors.go | 142 +++++++++++++++------------- documentation/en/cli-lotus-miner.md | 2 +- documentation/en/cli-sptool.md | 2 +- 3 files changed, 80 insertions(+), 66 deletions(-) diff --git a/cli/spcli/sectors.go b/cli/spcli/sectors.go index 95acbcd111e..e1d7654a05f 100644 --- a/cli/spcli/sectors.go +++ b/cli/spcli/sectors.go @@ -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", @@ -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, - }) - } } diff --git a/documentation/en/cli-lotus-miner.md b/documentation/en/cli-lotus-miner.md index ed068624e9a..d7b1db98b79 100644 --- a/documentation/en/cli-lotus-miner.md +++ b/documentation/en/cli-lotus-miner.md @@ -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 ``` diff --git a/documentation/en/cli-sptool.md b/documentation/en/cli-sptool.md index e116f759fc7..f2e6365a349 100644 --- a/documentation/en/cli-sptool.md +++ b/documentation/en/cli-sptool.md @@ -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 ```