From a463c90057c7a8f2df419c4e0aa5beea8b926802 Mon Sep 17 00:00:00 2001 From: zenground0 Date: Tue, 1 Mar 2022 11:27:03 -0700 Subject: [PATCH 1/2] remove endpoint from cli --- api/api_storage.go | 6 +- cmd/lotus-miner/sectors.go | 55 -------------- documentation/en/cli-lotus-miner.md | 14 ---- extern/storage-sealing/states_sealing.go | 17 +---- extern/storage-sealing/upgrade_queue.go | 95 ------------------------ storage/miner_sealing.go | 8 +- 6 files changed, 6 insertions(+), 189 deletions(-) diff --git a/api/api_storage.go b/api/api_storage.go index da66a9a0358..e0c8c657369 100644 --- a/api/api_storage.go +++ b/api/api_storage.go @@ -92,7 +92,8 @@ type StorageMiner interface { SectorsUpdate(context.Context, abi.SectorNumber, SectorState) error //perm:admin // SectorRemove removes the sector from storage. It doesn't terminate it on-chain, which can // be done with SectorTerminate. Removing and not terminating live sectors will cause additional penalties. - SectorRemove(context.Context, abi.SectorNumber) error //perm:admin + SectorRemove(context.Context, abi.SectorNumber) error //perm:admin + SectorMarkForUpgrade(ctx context.Context, id abi.SectorNumber, snap bool) error //perm:admin // SectorTerminate terminates the sector on-chain (adding it to a termination batch first), then // automatically removes it from storage SectorTerminate(context.Context, abi.SectorNumber) error //perm:admin @@ -100,8 +101,7 @@ type StorageMiner interface { // Returns null if message wasn't sent SectorTerminateFlush(ctx context.Context) (*cid.Cid, error) //perm:admin // SectorTerminatePending returns a list of pending sector terminations to be sent in the next batch message - SectorTerminatePending(ctx context.Context) ([]abi.SectorID, error) //perm:admin - SectorMarkForUpgrade(ctx context.Context, id abi.SectorNumber, snap bool) error //perm:admin + SectorTerminatePending(ctx context.Context) ([]abi.SectorID, error) //perm:admin // SectorPreCommitFlush immediately sends a PreCommit message with sectors batched for PreCommit. // Returns null if message wasn't sent SectorPreCommitFlush(ctx context.Context) ([]sealiface.PreCommitBatchRes, error) //perm:admin diff --git a/cmd/lotus-miner/sectors.go b/cmd/lotus-miner/sectors.go index 24098b5581e..bc21504f210 100644 --- a/cmd/lotus-miner/sectors.go +++ b/cmd/lotus-miner/sectors.go @@ -11,9 +11,6 @@ import ( "strings" "time" - "github.com/filecoin-project/lotus/build" - "github.com/filecoin-project/lotus/chain/actors/builtin" - "github.com/docker/go-units" "github.com/fatih/color" cbor "github.com/ipfs/go-ipld-cbor" @@ -56,7 +53,6 @@ var sectorsCmd = &cli.Command{ sectorsRemoveCmd, sectorsSnapUpCmd, sectorsSnapAbortCmd, - sectorsMarkForUpgradeCmd, sectorsStartSealCmd, sectorsSealDelayCmd, sectorsCapacityCollateralCmd, @@ -1568,57 +1564,6 @@ var sectorsSnapAbortCmd = &cli.Command{ }, } -var sectorsMarkForUpgradeCmd = &cli.Command{ - Name: "mark-for-upgrade", - Usage: "Mark a committed capacity sector for replacement by a sector with deals", - ArgsUsage: "", - Action: func(cctx *cli.Context) error { - if cctx.Args().Len() != 1 { - return lcli.ShowHelp(cctx, xerrors.Errorf("must pass sector number")) - } - - nodeApi, closer, err := lcli.GetStorageMinerAPI(cctx) - if err != nil { - return err - } - defer closer() - - api, nCloser, err := lcli.GetFullNodeAPI(cctx) - if err != nil { - return err - } - defer nCloser() - ctx := lcli.ReqContext(cctx) - - nv, err := api.StateNetworkVersion(ctx, types.EmptyTSK) - if err != nil { - return xerrors.Errorf("failed to get network version: %w", err) - } - if nv >= network.Version15 { - return xerrors.Errorf("classic cc upgrades disabled v15 and beyond, use `snap-up`") - } - - // disable mark for upgrade two days before the ntwk v15 upgrade - // TODO: remove the following block in v1.15.1 - head, err := api.ChainHead(ctx) - if err != nil { - return xerrors.Errorf("failed to get chain head: %w", err) - } - twoDays := abi.ChainEpoch(2 * builtin.EpochsInDay) - if head.Height() > (build.UpgradeOhSnapHeight - twoDays) { - return xerrors.Errorf("OhSnap is coming soon, " + - "please use `snap-up` to upgrade your cc sectors after the network v15 upgrade!") - } - - id, err := strconv.ParseUint(cctx.Args().Get(0), 10, 64) - if err != nil { - return xerrors.Errorf("could not parse sector number: %w", err) - } - - return nodeApi.SectorMarkForUpgrade(ctx, abi.SectorNumber(id), false) - }, -} - var sectorsStartSealCmd = &cli.Command{ Name: "seal", Usage: "Manually start sealing a sector (filling any unused space with junk)", diff --git a/documentation/en/cli-lotus-miner.md b/documentation/en/cli-lotus-miner.md index f455aeacefb..84aaff7bc6f 100644 --- a/documentation/en/cli-lotus-miner.md +++ b/documentation/en/cli-lotus-miner.md @@ -1581,7 +1581,6 @@ COMMANDS: remove Forcefully remove a sector (WARNING: This means losing power and collateral for the removed sector (use 'terminate' for lower penalty)) snap-up Mark a committed capacity sector to be filled with deals abort-upgrade Abort the attempted (SnapDeals) upgrade of a CC sector, reverting it to as before - mark-for-upgrade Mark a committed capacity sector for replacement by a sector with deals seal Manually start sealing a sector (filling any unused space with junk) set-seal-delay Set the time, in minutes, that a new sector waits for deals before sealing starts get-cc-collateral Get the collateral required to pledge a committed capacity sector @@ -1831,19 +1830,6 @@ OPTIONS: ``` -### lotus-miner sectors mark-for-upgrade -``` -NAME: - lotus-miner sectors mark-for-upgrade - Mark a committed capacity sector for replacement by a sector with deals - -USAGE: - lotus-miner sectors mark-for-upgrade [command options] - -OPTIONS: - --help, -h show help (default: false) - -``` - ### lotus-miner sectors seal ``` NAME: diff --git a/extern/storage-sealing/states_sealing.go b/extern/storage-sealing/states_sealing.go index 3dba325ee42..38e25899218 100644 --- a/extern/storage-sealing/states_sealing.go +++ b/extern/storage-sealing/states_sealing.go @@ -279,14 +279,6 @@ func (m *Sealing) handlePreCommit2(ctx statemachine.Context, sector SectorInfo) }) } -// TODO: We should probably invoke this method in most (if not all) state transition failures after handlePreCommitting -func (m *Sealing) remarkForUpgrade(ctx context.Context, sid abi.SectorNumber) { - err := m.MarkForUpgrade(ctx, sid) - if err != nil { - log.Errorf("error re-marking sector %d as for upgrade: %+v", sid, err) - } -} - func (m *Sealing) preCommitParams(ctx statemachine.Context, sector SectorInfo) (*miner.SectorPreCommitInfo, big.Int, TipSetToken, error) { tok, height, err := m.Api.ChainHead(ctx.Context()) if err != nil { @@ -360,16 +352,12 @@ func (m *Sealing) preCommitParams(ctx statemachine.Context, sector SectorInfo) ( DealIDs: sector.dealIDs(), } - depositMinimum := m.tryUpgradeSector(ctx.Context(), params) - collateral, err := m.Api.StateMinerPreCommitDepositForPower(ctx.Context(), m.maddr, *params, tok) if err != nil { return nil, big.Zero(), nil, xerrors.Errorf("getting initial pledge collateral: %w", err) } - deposit := big.Max(depositMinimum, collateral) - - return params, deposit, tok, nil + return params, collateral, tok, nil } func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInfo) error { @@ -423,9 +411,6 @@ func (m *Sealing) handlePreCommitting(ctx statemachine.Context, sector SectorInf log.Infof("submitting precommit for sector %d (deposit: %s): ", sector.SectorNumber, deposit) mcid, err := m.Api.SendMsg(ctx.Context(), from, m.maddr, miner.Methods.PreCommitSector, deposit, big.Int(m.feeCfg.MaxPreCommitGasFee), enc.Bytes()) if err != nil { - if params.ReplaceCapacity { - m.remarkForUpgrade(ctx.Context(), params.ReplaceSectorNumber) - } return ctx.Send(SectorChainPreCommitFailed{xerrors.Errorf("pushing message to mpool: %w", err)}) } diff --git a/extern/storage-sealing/upgrade_queue.go b/extern/storage-sealing/upgrade_queue.go index 1e5bef67c80..941ed312ea0 100644 --- a/extern/storage-sealing/upgrade_queue.go +++ b/extern/storage-sealing/upgrade_queue.go @@ -4,51 +4,13 @@ import ( "context" "github.com/filecoin-project/go-address" - "github.com/filecoin-project/lotus/chain/actors/builtin/miner" market7 "github.com/filecoin-project/specs-actors/v7/actors/builtin/market" "golang.org/x/xerrors" "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/big" ) -func (m *Sealing) IsMarkedForUpgrade(id abi.SectorNumber) bool { - m.upgradeLk.Lock() - _, found := m.toUpgrade[id] - m.upgradeLk.Unlock() - return found -} - -func (m *Sealing) MarkForUpgrade(ctx context.Context, id abi.SectorNumber) error { - - m.upgradeLk.Lock() - defer m.upgradeLk.Unlock() - - _, found := m.toUpgrade[id] - if found { - return xerrors.Errorf("sector %d already marked for upgrade", id) - } - - si, err := m.GetSectorInfo(id) - if err != nil { - return xerrors.Errorf("getting sector info: %w", err) - } - if si.State != Proving { - return xerrors.Errorf("can't mark sectors not in the 'Proving' state for upgrade") - } - if len(si.Pieces) != 1 { - return xerrors.Errorf("not a committed-capacity sector, expected 1 piece") - } - if si.Pieces[0].DealInfo != nil { - return xerrors.Errorf("not a committed-capacity sector, has deals") - } - - m.toUpgrade[id] = struct{}{} - - return nil -} - func (m *Sealing) MarkForSnapUpgrade(ctx context.Context, id abi.SectorNumber) error { cfg, err := m.getConfig() if err != nil { @@ -119,60 +81,3 @@ func sectorActive(ctx context.Context, api SealingAPI, maddr address.Address, to } return found, nil } - -func (m *Sealing) tryUpgradeSector(ctx context.Context, params *miner.SectorPreCommitInfo) big.Int { - if len(params.DealIDs) == 0 { - return big.Zero() - } - replace := m.maybeUpgradableSector() - if replace != nil { - loc, err := m.Api.StateSectorPartition(ctx, m.maddr, *replace, nil) - if err != nil { - log.Errorf("error calling StateSectorPartition for replaced sector: %+v", err) - return big.Zero() - } - - params.ReplaceCapacity = true - params.ReplaceSectorNumber = *replace - params.ReplaceSectorDeadline = loc.Deadline - params.ReplaceSectorPartition = loc.Partition - - log.Infof("replacing sector %d with %d", *replace, params.SectorNumber) - - ri, err := m.Api.StateSectorGetInfo(ctx, m.maddr, *replace, nil) - if err != nil { - log.Errorf("error calling StateSectorGetInfo for replaced sector: %+v", err) - return big.Zero() - } - if ri == nil { - log.Errorf("couldn't find sector info for sector to replace: %+v", replace) - return big.Zero() - } - - if params.Expiration < ri.Expiration { - // TODO: Some limit on this - params.Expiration = ri.Expiration - } - - return ri.InitialPledge - } - - return big.Zero() -} - -func (m *Sealing) maybeUpgradableSector() *abi.SectorNumber { - m.upgradeLk.Lock() - defer m.upgradeLk.Unlock() - for number := range m.toUpgrade { - // TODO: checks to match actor constraints - - // this one looks good - /*if checks */ - { - delete(m.toUpgrade, number) - return &number - } - } - - return nil -} diff --git a/storage/miner_sealing.go b/storage/miner_sealing.go index a22c32a40a2..8421c7148db 100644 --- a/storage/miner_sealing.go +++ b/storage/miner_sealing.go @@ -79,11 +79,7 @@ func (m *Miner) MarkForUpgrade(ctx context.Context, id abi.SectorNumber, snap bo if snap { return m.sealing.MarkForSnapUpgrade(ctx, id) } - return m.sealing.MarkForUpgrade(ctx, id) -} - -func (m *Miner) IsMarkedForUpgrade(id abi.SectorNumber) bool { - return m.sealing.IsMarkedForUpgrade(id) + return xerrors.Errorf("Old CC upgrade deprecated, use snap deals CC upgrade") } func (m *Miner) SectorAbortUpgrade(sectorNum abi.SectorNumber) error { @@ -147,7 +143,7 @@ func (m *Miner) SectorsStatus(ctx context.Context, sid abi.SectorNumber, showOnC PreCommitMsg: info.PreCommitMessage, CommitMsg: info.CommitMessage, Retries: info.InvalidProofs, - ToUpgrade: m.IsMarkedForUpgrade(sid), + ToUpgrade: false, LastErr: info.LastErr, Log: log, From 59ef2fe1b8285ca1e5de51c077d1d756cf145bc0 Mon Sep 17 00:00:00 2001 From: zenground0 Date: Tue, 1 Mar 2022 11:46:36 -0700 Subject: [PATCH 2/2] Remove unused fields from sealing --- extern/storage-sealing/sealing.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/extern/storage-sealing/sealing.go b/extern/storage-sealing/sealing.go index 81f6b38e93c..5aeeda7bea4 100644 --- a/extern/storage-sealing/sealing.go +++ b/extern/storage-sealing/sealing.go @@ -106,9 +106,6 @@ type Sealing struct { assignedPieces map[abi.SectorID][]cid.Cid creating *abi.SectorNumber // used to prevent a race where we could create a new sector more than once - upgradeLk sync.Mutex - toUpgrade map[abi.SectorNumber]struct{} - notifee SectorStateNotifee addrSel AddrSel @@ -168,7 +165,6 @@ func New(mctx context.Context, api SealingAPI, fc config.MinerFeeConfig, events sectorTimers: map[abi.SectorID]*time.Timer{}, pendingPieces: map[cid.Cid]*pendingPiece{}, assignedPieces: map[abi.SectorID][]cid.Cid{}, - toUpgrade: map[abi.SectorNumber]struct{}{}, notifee: notifee, addrSel: as,