-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
storage
module: add go docs and minor code quality refactors
#6259
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
df7631d
docs: rename some wdpost methods; add docs.
raulk 5daacc0
docs: add docs to chain store methods.
raulk 1d6941b
rename storage/{sealing=>miner_sealing}.go
raulk c7d50fe
rename {storageMinerApi=>fullNodeFilteredAPI}; add docs.
raulk 2d7f4b1
docs: add godocs to storage module.
raulk 0187aa6
imports reorder.
raulk 89dfb0b
minor refactor, renames, docs in Miner#Run.
raulk 0f42701
rename {submitPost=>submitPoStMessage}.
raulk 28efa93
rename {setSender=>prepareMessage}.
raulk 9912212
minor refactor to anonymize interface.
raulk c77f8fb
adopt clearer method names; fix typo.
raulk 50360e6
rename {changeHandlerAPI=>wdPoStCommands} + add docs.
raulk 996feda
typo.
raulk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,6 @@ import ( | |
"errors" | ||
"time" | ||
|
||
"github.com/filecoin-project/go-state-types/network" | ||
|
||
"github.com/filecoin-project/go-state-types/dline" | ||
|
||
"github.com/filecoin-project/go-bitfield" | ||
|
||
"github.com/ipfs/go-cid" | ||
|
@@ -20,9 +16,13 @@ import ( | |
"github.com/filecoin-project/go-address" | ||
"github.com/filecoin-project/go-state-types/abi" | ||
"github.com/filecoin-project/go-state-types/crypto" | ||
"github.com/filecoin-project/go-state-types/dline" | ||
"github.com/filecoin-project/go-state-types/network" | ||
|
||
"github.com/filecoin-project/specs-storage/storage" | ||
|
||
sectorstorage "github.com/filecoin-project/lotus/extern/sector-storage" | ||
"github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper" | ||
"github.com/filecoin-project/specs-storage/storage" | ||
|
||
"github.com/filecoin-project/lotus/api" | ||
"github.com/filecoin-project/lotus/api/v1api" | ||
|
@@ -41,8 +41,16 @@ import ( | |
|
||
var log = logging.Logger("storageminer") | ||
|
||
// Miner is the central miner entrypoint object inside Lotus. It is | ||
// instantiated in the node builder, along with the WindowPoStScheduler. | ||
// | ||
// This object is the owner of the sealing pipeline. Most of the actual logic | ||
// lives in the storage-sealing module (sealing.Sealing), and the Miner object | ||
// exposes it to the rest of the system by proxying calls. | ||
// | ||
// Miner#Run starts the sealing FSM. | ||
type Miner struct { | ||
api storageMinerApi | ||
api fullNodeFilteredAPI | ||
feeCfg config.MinerFeeConfig | ||
h host.Host | ||
sealer sectorstorage.SectorManager | ||
|
@@ -70,7 +78,9 @@ type SealingStateEvt struct { | |
Error string | ||
} | ||
|
||
type storageMinerApi interface { | ||
// fullNodeFilteredAPI is the subset of the full node API the Miner needs from | ||
// a Lotus full node. | ||
type fullNodeFilteredAPI interface { | ||
// Call a read only method on actors (no interaction with the chain required) | ||
StateCall(context.Context, *types.Message, types.TipSetKey) (*api.InvocResult, error) | ||
StateMinerSectors(context.Context, address.Address, *bitfield.BitField, types.TipSetKey) ([]*miner.SectorOnChainInfo, error) | ||
|
@@ -116,7 +126,18 @@ type storageMinerApi interface { | |
WalletHas(context.Context, address.Address) (bool, error) | ||
} | ||
|
||
func NewMiner(api storageMinerApi, maddr address.Address, h host.Host, ds datastore.Batching, sealer sectorstorage.SectorManager, sc sealing.SectorIDCounter, verif ffiwrapper.Verifier, gsd dtypes.GetSealingConfigFunc, feeCfg config.MinerFeeConfig, journal journal.Journal, as *AddressSelector) (*Miner, error) { | ||
// NewMiner creates a new Miner object. | ||
func NewMiner(api fullNodeFilteredAPI, | ||
maddr address.Address, | ||
h host.Host, | ||
ds datastore.Batching, | ||
sealer sectorstorage.SectorManager, | ||
sc sealing.SectorIDCounter, | ||
verif ffiwrapper.Verifier, | ||
gsd dtypes.GetSealingConfigFunc, | ||
feeCfg config.MinerFeeConfig, | ||
journal journal.Journal, | ||
as *AddressSelector) (*Miner, error) { | ||
m := &Miner{ | ||
api: api, | ||
feeCfg: feeCfg, | ||
|
@@ -136,6 +157,7 @@ func NewMiner(api storageMinerApi, maddr address.Address, h host.Host, ds datast | |
return m, nil | ||
} | ||
|
||
// Run starts the sealing FSM in the background, running preliminary checks first. | ||
func (m *Miner) Run(ctx context.Context) error { | ||
if err := m.runPreflightChecks(ctx); err != nil { | ||
return xerrors.Errorf("miner preflight checks failed: %w", err) | ||
|
@@ -152,17 +174,37 @@ func (m *Miner) Run(ctx context.Context) error { | |
MaxTerminateGasFee: abi.TokenAmount(m.feeCfg.MaxTerminateGasFee), | ||
} | ||
|
||
evts := events.NewEvents(ctx, m.api) | ||
adaptedAPI := NewSealingAPIAdapter(m.api) | ||
// TODO: Maybe we update this policy after actor upgrades? | ||
pcp := sealing.NewBasicPreCommitPolicy(adaptedAPI, policy.GetMaxSectorExpirationExtension()-(md.WPoStProvingPeriod*2), md.PeriodStart%md.WPoStProvingPeriod) | ||
var ( | ||
// consumer of chain head changes. | ||
evts = events.NewEvents(ctx, m.api) | ||
evtsAdapter = NewEventsAdapter(evts) | ||
|
||
as := func(ctx context.Context, mi miner.MinerInfo, use api.AddrUse, goodFunds, minFunds abi.TokenAmount) (address.Address, abi.TokenAmount, error) { | ||
return m.addrSel.AddressFor(ctx, m.api, mi, use, goodFunds, minFunds) | ||
} | ||
// Create a shim to glue the API required by the sealing component | ||
// with the API that Lotus is capable of providing. | ||
// The shim translates between "tipset tokens" and tipset keys, and | ||
// provides extra methods. | ||
adaptedAPI = NewSealingAPIAdapter(m.api) | ||
|
||
// Instantiate a precommit policy. | ||
defaultDuration = policy.GetMaxSectorExpirationExtension() - (md.WPoStProvingPeriod * 2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest adding a comment to explain this calculation |
||
provingBoundary = md.PeriodStart % md.WPoStProvingPeriod | ||
|
||
// TODO: Maybe we update this policy after actor upgrades? | ||
pcp = sealing.NewBasicPreCommitPolicy(adaptedAPI, defaultDuration, provingBoundary) | ||
|
||
// address selector. | ||
as = func(ctx context.Context, mi miner.MinerInfo, use api.AddrUse, goodFunds, minFunds abi.TokenAmount) (address.Address, abi.TokenAmount, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest adding a comment explaining what the address selector does |
||
return m.addrSel.AddressFor(ctx, m.api, mi, use, goodFunds, minFunds) | ||
} | ||
|
||
// sealing configuration. | ||
cfg = sealing.GetSealingConfigFunc(m.getSealConfig) | ||
) | ||
|
||
m.sealing = sealing.New(adaptedAPI, fc, NewEventsAdapter(evts), m.maddr, m.ds, m.sealer, m.sc, m.verif, &pcp, sealing.GetSealingConfigFunc(m.getSealConfig), m.handleSealingNotifications, as) | ||
// Instantiate the sealing FSM. | ||
m.sealing = sealing.New(adaptedAPI, fc, evtsAdapter, m.maddr, m.ds, m.sealer, m.sc, m.verif, &pcp, cfg, m.handleSealingNotifications, as) | ||
|
||
// Run the sealing FSM. | ||
go m.sealing.Run(ctx) //nolint:errcheck // logged intside the function | ||
|
||
return nil | ||
|
@@ -184,6 +226,7 @@ func (m *Miner) Stop(ctx context.Context) error { | |
return m.sealing.Stop(ctx) | ||
} | ||
|
||
// runPreflightChecks verifies that preconditions to run the miner are satisfied. | ||
func (m *Miner) runPreflightChecks(ctx context.Context) error { | ||
mi, err := m.api.StateMinerInfo(ctx, m.maddr, types.EmptyTSK) | ||
if err != nil { | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is mostly tech debt, but it's really tricky to untangle storage-sealing from this object, which is why it's here