Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sealing: Sector upgrade queue #8330

Merged
merged 15 commits into from
Mar 16, 2022
Merged

feat: sealing: Sector upgrade queue #8330

merged 15 commits into from
Mar 16, 2022

Conversation

magik6k
Copy link
Contributor

@magik6k magik6k commented Mar 16, 2022

Related Issues

Closes #8231

Proposed Changes

  • Add a new Available sector state for CC sectors available for upgrading ('available storage')
  • After sectors are marked for upgrade, they go into the Available state instead of SnapDealsWaitDeals
  • When a deal arrives to the sealing pipeline, and it can't be matched to any sectors:
    • We'll try to see if any Available sectors can accept it - we'll select a candidate with lowest initial pledge (most rational to upgrade?)
    • If we don't find any good available sectors, we'll just create a new CC sector if that's not disabled in the config

Additional Info

TODO:

  • Test on a real setup
  • Add a config which would make newly sealed sectors automatically become Available (maybe a separate PR)
  • When considering Active sectors run all snapdeal checks
  • Support reverting from Available to Proving

Checklist

Before you mark the PR ready for review, please make sure that:

  • All commits have a clear commit message.
  • The PR title is in the form of of <PR type>: <area>: <change being made>
    • example: fix: mempool: Introduce a cache for valid signatures
    • PR type: fix, feat, INTERFACE BREAKING CHANGE, CONSENSUS BREAKING, build, chore, ci, docs,perf, refactor, revert, style, test
    • area: api, chain, state, vm, data transfer, market, mempool, message, block production, multisig, networking, paychan, proving, sealing, wallet, deps
  • This PR has tests for new functionality or change in behaviour
  • If new user-facing features are introduced, clear usage guidelines and / or documentation updates should be included in https://lotus.filecoin.io or Discussion Tutorials.
  • CI is green

@magik6k magik6k requested a review from a team as a code owner March 16, 2022 16:44
@magik6k magik6k marked this pull request as draft March 16, 2022 16:47
Copy link
Contributor

@ZenGround0 ZenGround0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, keep me posted when this gets out of draft

@@ -106,6 +106,8 @@ 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

available map[abi.SectorID]struct{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will become stale if the miner restarts. Are there existing patterns for traversing sector infos to repopulate this for all infos in Available state?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Available state handler gets called on restart, so this will get repopulated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woah cool, is this the same for all state handlers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep

extern/storage-sealing/states_proving.go Show resolved Hide resolved
extern/storage-sealing/input.go Outdated Show resolved Hide resolved
itests/ccupgrade_test.go Outdated Show resolved Hide resolved
extern/storage-sealing/input.go Outdated Show resolved Hide resolved
extern/storage-sealing/input.go Outdated Show resolved Hide resolved
@magik6k magik6k marked this pull request as ready for review March 16, 2022 19:33
Copy link
Contributor

@ZenGround0 ZenGround0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unsure about a few things but looks ready for minerX testing.

#
# type: bool
# env var: LOTUS_SEALING_MAKECCSECTORSAVAILABLE
#MakeCCSectorsAvailable = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

@@ -136,6 +137,7 @@ var fsmPlanners = map[SectorState]func(events []statemachine.Event, state *Secto

FinalizeSector: planOne(
on(SectorFinalized{}, Proving),
on(SectorFinalizedAvailable{}, Available),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of FinalizedAvailable? Why not instead go to Available from proving if the MakeCCSectorsAvailable config is set? That way we can avoid coupling with CommitFinalize.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't really distinguish CC sectors already in the proving state from CC sectors entering the proving state (that's because on restart we run all state handlers for current states of all sectors). If we were to do that without tracking existing CC sectors, all CC sectors would get converted to Available, which I'm quite sure is not what SPs will want.

Other things we could do instead of this event:

  • Additional state deciding this
    • Now we need 2 events, and an additional state
  • Add a boolean to SectorInfo to track which CC sectors are Proving already, and shouldn't be auto-converted to Available
    • Pretty sure this still requires an additional event to update this variable. Also adds more bits of private per-sector state, which ideally wouldn't exist

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks makes sense. That run all state handlers on restart fact is pretty important.


log.Infow("Upgrading sector", "number", candidate.Number, "type", "deal", "proofType", sp, "expiration", bestExpiration, "pledge", types.FIL(bestPledge))
delete(m.available, candidate)
m.creating = &candidate.Number
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why set creating I thought this was only needed when making a new sector, not dealing with an existing one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This var is used to synchronize sector event processing - basically we want to make sure that we don't re-enter tryGetDealSector before the sector we've just asked to enter WaitDeals* adds itself to m.openSectors.

Renamed the var to something which makes more sense given that we now also use it for snapdeals

@@ -63,7 +64,7 @@ type SealingAPI interface {
StateMinerInfo(context.Context, address.Address, TipSetToken) (miner.MinerInfo, error)
StateMinerAvailableBalance(context.Context, address.Address, TipSetToken) (big.Int, error)
StateMinerSectorAllocated(context.Context, address.Address, abi.SectorNumber, TipSetToken) (bool, error)
StateMinerActiveSectors(context.Context, address.Address, TipSetToken) ([]*miner.SectorOnChainInfo, error)
StateMinerActiveSectors(context.Context, address.Address, TipSetToken) (bitfield.BitField, error)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

way better

@@ -106,6 +106,8 @@ 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

available map[abi.SectorID]struct{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

woah cool, is this the same for all state handlers?

@codecov
Copy link

codecov bot commented Mar 16, 2022

Codecov Report

Merging #8330 (60ba133) into master (159da73) will decrease coverage by 0.04%.
The diff coverage is 62.50%.

❗ Current head 60ba133 differs from pull request most recent head a431fdb. Consider uploading reports for the commit a431fdb to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8330      +/-   ##
==========================================
- Coverage   40.38%   40.33%   -0.05%     
==========================================
  Files         679      679              
  Lines       73898    73985      +87     
==========================================
  Hits        29842    29842              
- Misses      38845    38903      +58     
- Partials     5211     5240      +29     
Impacted Files Coverage Δ
cmd/lotus-miner/info.go 60.11% <ø> (ø)
extern/storage-sealing/mocks/api.go 0.00% <0.00%> (ø)
extern/storage-sealing/states_failed.go 0.00% <0.00%> (ø)
extern/storage-sealing/states_sealing.go 38.10% <0.00%> (-0.17%) ⬇️
extern/storage-sealing/fsm_events.go 50.62% <50.00%> (+0.62%) ⬆️
storage/adapter_storage_miner.go 50.00% <50.00%> (-0.22%) ⬇️
extern/storage-sealing/input.go 54.61% <58.94%> (+1.04%) ⬆️
extern/storage-sealing/upgrade_queue.go 32.14% <83.33%> (-13.10%) ⬇️
extern/storage-sealing/fsm.go 57.04% <100.00%> (-0.73%) ⬇️
extern/storage-sealing/sealing.go 78.88% <100.00%> (+0.23%) ⬆️
... and 27 more

@jennijuju
Copy link
Member

COOOOOOOOOLLLL

@jennijuju
Copy link
Member

oh yess this is cool we should have it in v1.15.1

@jennijuju jennijuju added this to the v1.15.1 milestone Mar 16, 2022
@magik6k magik6k merged commit a3bdd29 into master Mar 16, 2022
@magik6k magik6k deleted the feat/snap-queue branch March 16, 2022 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Snap Deals big pipe for onboarding
3 participants