From db676acdf85bdee7a5b31989a356c54a944708fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 17 Jun 2022 13:52:19 +0200 Subject: [PATCH] storage: Cleanup interfaces a bit --- chain/consensus/filcns/filecoin.go | 5 ++- chain/gen/gen.go | 5 ++- chain/stmgr/actors.go | 6 +-- chain/vm/syscalls.go | 5 ++- cmd/lotus-bench/caching_verifier.go | 6 +-- cmd/lotus-bench/import.go | 3 +- cmd/lotus-sim/simulation/mock/mock.go | 4 +- itests/kit/ensemble.go | 10 ++--- node/builder_chain.go | 5 ++- node/builder_miner.go | 6 +-- node/impl/full/state.go | 4 +- node/modules/storageminer.go | 6 +-- storage/miner.go | 15 ++++--- storage/pipeline/commit_batch.go | 6 +-- storage/pipeline/commit_batch_test.go | 4 +- storage/pipeline/sealing.go | 5 +-- storage/sealer/ffiwrapper/prover_cgo.go | 4 +- storage/sealer/ffiwrapper/sealer_cgo.go | 2 +- storage/sealer/ffiwrapper/types.go | 41 ------------------- storage/sealer/ffiwrapper/verifier_cgo.go | 2 +- storage/sealer/manager.go | 8 ++-- storage/sealer/manager_test.go | 10 ++--- storage/sealer/mock/mock.go | 4 +- storage/sealer/storiface/storage.go | 49 ++++++++++++++++++----- storage/sealer/teststorage_test.go | 3 +- storage/sealer/worker_local.go | 4 +- storage/wdpost/wdpost_sched.go | 9 ++--- 27 files changed, 110 insertions(+), 121 deletions(-) diff --git a/chain/consensus/filcns/filecoin.go b/chain/consensus/filcns/filecoin.go index b4fb40d5213..de3cf7cf7d6 100644 --- a/chain/consensus/filcns/filecoin.go +++ b/chain/consensus/filcns/filecoin.go @@ -43,6 +43,7 @@ import ( "github.com/filecoin-project/lotus/lib/sigs" "github.com/filecoin-project/lotus/metrics" "github.com/filecoin-project/lotus/storage/sealer/ffiwrapper" + "github.com/filecoin-project/lotus/storage/sealer/storiface" ) var log = logging.Logger("fil-consensus") @@ -57,7 +58,7 @@ type FilecoinEC struct { // the state manager handles making state queries sm *stmgr.StateManager - verifier ffiwrapper.Verifier + verifier storiface.Verifier genesis *types.TipSet } @@ -66,7 +67,7 @@ type FilecoinEC struct { // the theoretical max height based on systime are quickly rejected const MaxHeightDrift = 5 -func NewFilecoinExpectedConsensus(sm *stmgr.StateManager, beacon beacon.Schedule, verifier ffiwrapper.Verifier, genesis chain.Genesis) consensus.Consensus { +func NewFilecoinExpectedConsensus(sm *stmgr.StateManager, beacon beacon.Schedule, verifier storiface.Verifier, genesis chain.Genesis) consensus.Consensus { if build.InsecurePoStValidation { log.Warn("*********************************************************************************************") log.Warn(" [INSECURE-POST-VALIDATION] Insecure test validation is enabled. If you see this outside of a test, it is a severe bug! ") diff --git a/chain/gen/gen.go b/chain/gen/gen.go index 768da71e824..fe748020237 100644 --- a/chain/gen/gen.go +++ b/chain/gen/gen.go @@ -44,6 +44,7 @@ import ( "github.com/filecoin-project/lotus/journal" "github.com/filecoin-project/lotus/node/repo" "github.com/filecoin-project/lotus/storage/sealer/ffiwrapper" + "github.com/filecoin-project/lotus/storage/sealer/storiface" ) const msgsPerBlock = 20 @@ -592,7 +593,7 @@ type MiningCheckAPI interface { type mca struct { w *wallet.LocalWallet sm *stmgr.StateManager - pv ffiwrapper.Verifier + pv storiface.Verifier bcn beacon.Schedule } @@ -674,7 +675,7 @@ func ComputeVRF(ctx context.Context, sign SignFunc, worker address.Address, sigI type genFakeVerifier struct{} -var _ ffiwrapper.Verifier = (*genFakeVerifier)(nil) +var _ storiface.Verifier = (*genFakeVerifier)(nil) func (m genFakeVerifier) VerifySeal(svi proof7.SealVerifyInfo) (bool, error) { return true, nil diff --git a/chain/stmgr/actors.go b/chain/stmgr/actors.go index dca02ce3497..3ef5a3af965 100644 --- a/chain/stmgr/actors.go +++ b/chain/stmgr/actors.go @@ -26,7 +26,7 @@ import ( "github.com/filecoin-project/lotus/chain/rand" "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/chain/vm" - "github.com/filecoin-project/lotus/storage/sealer/ffiwrapper" + "github.com/filecoin-project/lotus/storage/sealer/storiface" ) func GetMinerWorkerRaw(ctx context.Context, sm *StateManager, st cid.Cid, maddr address.Address) (address.Address, error) { @@ -117,7 +117,7 @@ func MinerSectorInfo(ctx context.Context, sm *StateManager, maddr address.Addres return mas.GetSector(sid) } -func GetSectorsForWinningPoSt(ctx context.Context, nv network.Version, pv ffiwrapper.Verifier, sm *StateManager, st cid.Cid, maddr address.Address, rand abi.PoStRandomness) ([]builtin.ExtendedSectorInfo, error) { +func GetSectorsForWinningPoSt(ctx context.Context, nv network.Version, pv storiface.Verifier, sm *StateManager, st cid.Cid, maddr address.Address, rand abi.PoStRandomness) ([]builtin.ExtendedSectorInfo, error) { act, err := sm.LoadActorRaw(ctx, maddr, st) if err != nil { return nil, xerrors.Errorf("failed to load miner actor: %w", err) @@ -301,7 +301,7 @@ func ListMinerActors(ctx context.Context, sm *StateManager, ts *types.TipSet) ([ return powState.ListAllMiners() } -func MinerGetBaseInfo(ctx context.Context, sm *StateManager, bcs beacon.Schedule, tsk types.TipSetKey, round abi.ChainEpoch, maddr address.Address, pv ffiwrapper.Verifier) (*api.MiningBaseInfo, error) { +func MinerGetBaseInfo(ctx context.Context, sm *StateManager, bcs beacon.Schedule, tsk types.TipSetKey, round abi.ChainEpoch, maddr address.Address, pv storiface.Verifier) (*api.MiningBaseInfo, error) { ts, err := sm.ChainStore().LoadTipSet(ctx, tsk) if err != nil { return nil, xerrors.Errorf("failed to load tipset for mining base: %w", err) diff --git a/chain/vm/syscalls.go b/chain/vm/syscalls.go index 7120393194c..757453887a1 100644 --- a/chain/vm/syscalls.go +++ b/chain/vm/syscalls.go @@ -28,6 +28,7 @@ import ( "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/lib/sigs" "github.com/filecoin-project/lotus/storage/sealer/ffiwrapper" + "github.com/filecoin-project/lotus/storage/sealer/storiface" ) func init() { @@ -38,7 +39,7 @@ func init() { type SyscallBuilder func(ctx context.Context, rt *Runtime) runtime7.Syscalls -func Syscalls(verifier ffiwrapper.Verifier) SyscallBuilder { +func Syscalls(verifier storiface.Verifier) SyscallBuilder { return func(ctx context.Context, rt *Runtime) runtime7.Syscalls { return &syscallShim{ @@ -65,7 +66,7 @@ type syscallShim struct { actor address.Address cstate *state.StateTree cst cbor.IpldStore - verifier ffiwrapper.Verifier + verifier storiface.Verifier } func (ss *syscallShim) ComputeUnsealedSectorCID(st abi.RegisteredSealProof, pieces []abi.PieceInfo) (cid.Cid, error) { diff --git a/cmd/lotus-bench/caching_verifier.go b/cmd/lotus-bench/caching_verifier.go index f300a657754..4a4e8879ff7 100644 --- a/cmd/lotus-bench/caching_verifier.go +++ b/cmd/lotus-bench/caching_verifier.go @@ -12,12 +12,12 @@ import ( "github.com/filecoin-project/go-state-types/abi" prooftypes "github.com/filecoin-project/go-state-types/proof" - "github.com/filecoin-project/lotus/storage/sealer/ffiwrapper" + "github.com/filecoin-project/lotus/storage/sealer/storiface" ) type cachingVerifier struct { ds datastore.Datastore - backend ffiwrapper.Verifier + backend storiface.Verifier } const bufsize = 128 @@ -107,4 +107,4 @@ func (cv cachingVerifier) VerifyReplicaUpdate(update prooftypes.ReplicaUpdateInf return cv.backend.VerifyReplicaUpdate(update) } -var _ ffiwrapper.Verifier = (*cachingVerifier)(nil) +var _ storiface.Verifier = (*cachingVerifier)(nil) diff --git a/cmd/lotus-bench/import.go b/cmd/lotus-bench/import.go index 31ee0d51eaa..ce0b8d86e6b 100644 --- a/cmd/lotus-bench/import.go +++ b/cmd/lotus-bench/import.go @@ -44,6 +44,7 @@ import ( _ "github.com/filecoin-project/lotus/lib/sigs/secp" "github.com/filecoin-project/lotus/node/repo" "github.com/filecoin-project/lotus/storage/sealer/ffiwrapper" + "github.com/filecoin-project/lotus/storage/sealer/storiface" ) type TipSetExec struct { @@ -204,7 +205,7 @@ var importBenchCmd = &cli.Command{ defer c.Close() //nolint:errcheck } - var verifier ffiwrapper.Verifier = ffiwrapper.ProofVerifier + var verifier storiface.Verifier = ffiwrapper.ProofVerifier if cctx.IsSet("syscall-cache") { scds, err := badger.NewDatastore(cctx.String("syscall-cache"), &badger.DefaultOptions) if err != nil { diff --git a/cmd/lotus-sim/simulation/mock/mock.go b/cmd/lotus-sim/simulation/mock/mock.go index a37845daafd..4699b2aa665 100644 --- a/cmd/lotus-sim/simulation/mock/mock.go +++ b/cmd/lotus-sim/simulation/mock/mock.go @@ -15,7 +15,7 @@ import ( miner5 "github.com/filecoin-project/specs-actors/v5/actors/builtin/miner" tutils "github.com/filecoin-project/specs-actors/v5/support/testing" - "github.com/filecoin-project/lotus/storage/sealer/ffiwrapper" + "github.com/filecoin-project/lotus/storage/sealer/storiface" ) // Ideally, we'd use extern/sealer/mock. Unfortunately, those mocks are a bit _too_ accurate @@ -32,7 +32,7 @@ var log = logging.Logger("simulation-mock") // mockVerifier is a simple mock for verifying "fake" proofs. type mockVerifier struct{} -var Verifier ffiwrapper.Verifier = mockVerifier{} +var Verifier storiface.Verifier = mockVerifier{} func (mockVerifier) VerifySeal(proof prooftypes.SealVerifyInfo) (bool, error) { addr, err := address.NewIDAddress(uint64(proof.Miner)) diff --git a/itests/kit/ensemble.go b/itests/kit/ensemble.go index 4c71c238b23..4904ca14fe1 100644 --- a/itests/kit/ensemble.go +++ b/itests/kit/ensemble.go @@ -57,8 +57,8 @@ import ( "github.com/filecoin-project/lotus/node/repo" "github.com/filecoin-project/lotus/storage/paths" sectorstorage "github.com/filecoin-project/lotus/storage/sealer" - "github.com/filecoin-project/lotus/storage/sealer/ffiwrapper" "github.com/filecoin-project/lotus/storage/sealer/mock" + "github.com/filecoin-project/lotus/storage/sealer/storiface" ) func init() { @@ -363,8 +363,8 @@ func (n *Ensemble) Start() *Ensemble { // Are we mocking proofs? if n.options.mockProofs { opts = append(opts, - node.Override(new(ffiwrapper.Verifier), mock.MockVerifier), - node.Override(new(ffiwrapper.Prover), mock.MockProver), + node.Override(new(storiface.Verifier), mock.MockVerifier), + node.Override(new(storiface.Prover), mock.MockProver), ) } @@ -643,8 +643,8 @@ func (n *Ensemble) Start() *Ensemble { node.Override(new(sectorstorage.Unsealer), node.From(new(*mock.SectorMgr))), node.Override(new(sectorstorage.PieceProvider), node.From(new(*mock.SectorMgr))), - node.Override(new(ffiwrapper.Verifier), mock.MockVerifier), - node.Override(new(ffiwrapper.Prover), mock.MockProver), + node.Override(new(storiface.Verifier), mock.MockVerifier), + node.Override(new(storiface.Prover), mock.MockProver), node.Unset(new(*sectorstorage.Manager)), ) } diff --git a/node/builder_chain.go b/node/builder_chain.go index 21727459187..e24b2609734 100644 --- a/node/builder_chain.go +++ b/node/builder_chain.go @@ -40,6 +40,7 @@ import ( "github.com/filecoin-project/lotus/paychmgr" "github.com/filecoin-project/lotus/paychmgr/settler" "github.com/filecoin-project/lotus/storage/sealer/ffiwrapper" + "github.com/filecoin-project/lotus/storage/sealer/storiface" ) // Chain node provides access to the Filecoin blockchain, by setting up a full @@ -62,8 +63,8 @@ var ChainNode = Options( Override(new(dtypes.DrandBootstrap), modules.DrandBootstrap), // Consensus: crypto dependencies - Override(new(ffiwrapper.Verifier), ffiwrapper.ProofVerifier), - Override(new(ffiwrapper.Prover), ffiwrapper.ProofProver), + Override(new(storiface.Verifier), ffiwrapper.ProofVerifier), + Override(new(storiface.Prover), ffiwrapper.ProofProver), // Consensus: LegacyVM Override(new(vm.SyscallBuilder), vm.Syscalls), diff --git a/node/builder_miner.go b/node/builder_miner.go index fa214ca9f94..8c78091dc54 100644 --- a/node/builder_miner.go +++ b/node/builder_miner.go @@ -101,9 +101,9 @@ func ConfigStorageMiner(c interface{}) Option { If(!cfg.Subsystems.EnableSectorStorage, Error(xerrors.Errorf("sealing can't be disabled on a mining node yet"))), // Sector storage: Proofs - Override(new(ffiwrapper.Verifier), ffiwrapper.ProofVerifier), - Override(new(ffiwrapper.Prover), ffiwrapper.ProofProver), - Override(new(storiface.Prover), From(new(sectorstorage.SectorManager))), + Override(new(storiface.Verifier), ffiwrapper.ProofVerifier), + Override(new(storiface.Prover), ffiwrapper.ProofProver), + Override(new(storiface.ProverPoSt), From(new(sectorstorage.SectorManager))), // Sealing (todo should be under EnableSealing, but storagefsm is currently bundled with storage.Miner) Override(new(sealing.SectorIDCounter), modules.SectorIDCounter), diff --git a/node/impl/full/state.go b/node/impl/full/state.go index e586dff0250..b40924198d8 100644 --- a/node/impl/full/state.go +++ b/node/impl/full/state.go @@ -45,7 +45,7 @@ import ( "github.com/filecoin-project/lotus/chain/vm" "github.com/filecoin-project/lotus/chain/wallet" "github.com/filecoin-project/lotus/node/modules/dtypes" - "github.com/filecoin-project/lotus/storage/sealer/ffiwrapper" + "github.com/filecoin-project/lotus/storage/sealer/storiface" ) type StateModuleAPI interface { @@ -93,7 +93,7 @@ type StateAPI struct { StateModuleAPI - ProofVerifier ffiwrapper.Verifier + ProofVerifier storiface.Verifier StateManager *stmgr.StateManager Chain *store.ChainStore Beacon beacon.Schedule diff --git a/node/modules/storageminer.go b/node/modules/storageminer.go index 44d00bd4d18..3e538247771 100644 --- a/node/modules/storageminer.go +++ b/node/modules/storageminer.go @@ -70,7 +70,7 @@ import ( sealing "github.com/filecoin-project/lotus/storage/pipeline" "github.com/filecoin-project/lotus/storage/pipeline/sealiface" "github.com/filecoin-project/lotus/storage/sealer" - "github.com/filecoin-project/lotus/storage/sealer/ffiwrapper" + "github.com/filecoin-project/lotus/storage/sealer/storiface" "github.com/filecoin-project/lotus/storage/wdpost" ) @@ -211,8 +211,8 @@ type StorageMinerParams struct { MetadataDS dtypes.MetadataDS Sealer sealer.SectorManager SectorIDCounter sealing.SectorIDCounter - Verifier ffiwrapper.Verifier - Prover ffiwrapper.Prover + Verifier storiface.Verifier + Prover storiface.Prover GetSealingConfigFn dtypes.GetSealingConfigFunc Journal journal.Journal AddrSel *ctladdr.AddressSelector diff --git a/storage/miner.go b/storage/miner.go index b3c0d4a79ef..e4a7c8cfa7a 100644 --- a/storage/miner.go +++ b/storage/miner.go @@ -33,7 +33,6 @@ import ( "github.com/filecoin-project/lotus/storage/ctladdr" pipeline "github.com/filecoin-project/lotus/storage/pipeline" "github.com/filecoin-project/lotus/storage/sealer" - "github.com/filecoin-project/lotus/storage/sealer/ffiwrapper" "github.com/filecoin-project/lotus/storage/sealer/storiface" ) @@ -53,8 +52,8 @@ type Miner struct { sealer sealer.SectorManager ds datastore.Batching sc pipeline.SectorIDCounter - verif ffiwrapper.Verifier - prover ffiwrapper.Prover + verif storiface.Verifier + prover storiface.Prover addrSel *ctladdr.AddressSelector maddr address.Address @@ -136,8 +135,8 @@ func NewMiner(api fullNodeFilteredAPI, ds datastore.Batching, sealer sealer.SectorManager, sc pipeline.SectorIDCounter, - verif ffiwrapper.Verifier, - prover ffiwrapper.Prover, + verif storiface.Verifier, + prover storiface.Prover, gsd dtypes.GetSealingConfigFunc, feeCfg config.MinerFeeConfig, journal journal.Journal, @@ -240,13 +239,13 @@ func (m *Miner) runPreflightChecks(ctx context.Context) error { } type StorageWpp struct { - prover storiface.Prover - verifier ffiwrapper.Verifier + prover storiface.ProverPoSt + verifier storiface.Verifier miner abi.ActorID winnRpt abi.RegisteredPoStProof } -func NewWinningPoStProver(api v1api.FullNode, prover storiface.Prover, verifier ffiwrapper.Verifier, miner dtypes.MinerID) (*StorageWpp, error) { +func NewWinningPoStProver(api v1api.FullNode, prover storiface.ProverPoSt, verifier storiface.Verifier, miner dtypes.MinerID) (*StorageWpp, error) { ma, err := address.NewIDAddress(uint64(miner)) if err != nil { return nil, err diff --git a/storage/pipeline/commit_batch.go b/storage/pipeline/commit_batch.go index 128a03eab72..1e1993f6a77 100644 --- a/storage/pipeline/commit_batch.go +++ b/storage/pipeline/commit_batch.go @@ -26,7 +26,7 @@ import ( "github.com/filecoin-project/lotus/chain/types" "github.com/filecoin-project/lotus/node/config" "github.com/filecoin-project/lotus/storage/pipeline/sealiface" - "github.com/filecoin-project/lotus/storage/sealer/ffiwrapper" + "github.com/filecoin-project/lotus/storage/sealer/storiface" ) var aggFeeNum = big.NewInt(110) @@ -58,7 +58,7 @@ type CommitBatcher struct { addrSel AddrSel feeCfg config.MinerFeeConfig getConfig GetSealingConfigFunc - prover ffiwrapper.Prover + prover storiface.Prover cutoffs map[abi.SectorNumber]time.Time todo map[abi.SectorNumber]AggregateInput @@ -69,7 +69,7 @@ type CommitBatcher struct { lk sync.Mutex } -func NewCommitBatcher(mctx context.Context, maddr address.Address, api CommitBatcherApi, addrSel AddrSel, feeCfg config.MinerFeeConfig, getConfig GetSealingConfigFunc, prov ffiwrapper.Prover) *CommitBatcher { +func NewCommitBatcher(mctx context.Context, maddr address.Address, api CommitBatcherApi, addrSel AddrSel, feeCfg config.MinerFeeConfig, getConfig GetSealingConfigFunc, prov storiface.Prover) *CommitBatcher { b := &CommitBatcher{ api: api, maddr: maddr, diff --git a/storage/pipeline/commit_batch_test.go b/storage/pipeline/commit_batch_test.go index b8cebe1a816..a05b9e9cd9f 100644 --- a/storage/pipeline/commit_batch_test.go +++ b/storage/pipeline/commit_batch_test.go @@ -27,7 +27,7 @@ import ( pipeline "github.com/filecoin-project/lotus/storage/pipeline" "github.com/filecoin-project/lotus/storage/pipeline/mocks" "github.com/filecoin-project/lotus/storage/pipeline/sealiface" - "github.com/filecoin-project/lotus/storage/sealer/ffiwrapper" + "github.com/filecoin-project/lotus/storage/sealer/storiface" ) func TestCommitBatcher(t *testing.T) { @@ -391,7 +391,7 @@ func (f fakeProver) AggregateSealProofs(aggregateInfo prooftypes.AggregateSealVe return []byte("Trust me, I'm a proof"), nil } -var _ ffiwrapper.Prover = &fakeProver{} +var _ storiface.Prover = &fakeProver{} var dummyAddr = func() address.Address { a, _ := address.NewFromString("t00") diff --git a/storage/pipeline/sealing.go b/storage/pipeline/sealing.go index ac831674014..7196dfe5431 100644 --- a/storage/pipeline/sealing.go +++ b/storage/pipeline/sealing.go @@ -27,7 +27,6 @@ import ( "github.com/filecoin-project/lotus/node/config" "github.com/filecoin-project/lotus/storage/pipeline/sealiface" "github.com/filecoin-project/lotus/storage/sealer" - "github.com/filecoin-project/lotus/storage/sealer/ffiwrapper" "github.com/filecoin-project/lotus/storage/sealer/storiface" ) @@ -88,7 +87,7 @@ type Sealing struct { sealer sealer.SectorManager sectors *statemachine.StateGroup sc SectorIDCounter - verif ffiwrapper.Verifier + verif storiface.Verifier pcp PreCommitPolicy inputLk sync.Mutex @@ -150,7 +149,7 @@ type pendingPiece struct { accepted func(abi.SectorNumber, abi.UnpaddedPieceSize, error) } -func New(mctx context.Context, api SealingAPI, fc config.MinerFeeConfig, events Events, maddr address.Address, ds datastore.Batching, sealer sealer.SectorManager, sc SectorIDCounter, verif ffiwrapper.Verifier, prov ffiwrapper.Prover, pcp PreCommitPolicy, gc GetSealingConfigFunc, notifee SectorStateNotifee, as AddrSel) *Sealing { +func New(mctx context.Context, api SealingAPI, fc config.MinerFeeConfig, events Events, maddr address.Address, ds datastore.Batching, sealer sealer.SectorManager, sc SectorIDCounter, verif storiface.Verifier, prov storiface.Prover, pcp PreCommitPolicy, gc GetSealingConfigFunc, notifee SectorStateNotifee, as AddrSel) *Sealing { s := &Sealing{ Api: api, DealInfo: &CurrentDealInfoManager{api}, diff --git a/storage/sealer/ffiwrapper/prover_cgo.go b/storage/sealer/ffiwrapper/prover_cgo.go index a41b11a274d..abbd20b6e06 100644 --- a/storage/sealer/ffiwrapper/prover_cgo.go +++ b/storage/sealer/ffiwrapper/prover_cgo.go @@ -6,11 +6,13 @@ package ffiwrapper import ( ffi "github.com/filecoin-project/filecoin-ffi" "github.com/filecoin-project/go-state-types/proof" + + "github.com/filecoin-project/lotus/storage/sealer/storiface" ) var ProofProver = proofProver{} -var _ Prover = ProofProver +var _ storiface.Prover = ProofProver type proofProver struct{} diff --git a/storage/sealer/ffiwrapper/sealer_cgo.go b/storage/sealer/ffiwrapper/sealer_cgo.go index 0f89a6e8c53..4ed77375a84 100644 --- a/storage/sealer/ffiwrapper/sealer_cgo.go +++ b/storage/sealer/ffiwrapper/sealer_cgo.go @@ -34,7 +34,7 @@ import ( "github.com/filecoin-project/lotus/storage/sealer/storiface" ) -var _ Storage = &Sealer{} +var _ storiface.Storage = &Sealer{} func New(sectors SectorProvider) (*Sealer, error) { sb := &Sealer{ diff --git a/storage/sealer/ffiwrapper/types.go b/storage/sealer/ffiwrapper/types.go index b32a3cc8226..d20d581db4b 100644 --- a/storage/sealer/ffiwrapper/types.go +++ b/storage/sealer/ffiwrapper/types.go @@ -2,52 +2,11 @@ package ffiwrapper import ( "context" - "io" - - "github.com/ipfs/go-cid" - - "github.com/filecoin-project/go-state-types/abi" - "github.com/filecoin-project/go-state-types/proof" "github.com/filecoin-project/lotus/storage/sealer/ffiwrapper/basicfs" "github.com/filecoin-project/lotus/storage/sealer/storiface" ) -type Validator interface { - CanCommit(sector storiface.SectorPaths) (bool, error) - CanProve(sector storiface.SectorPaths) (bool, error) -} - -type StorageSealer interface { - storiface.Sealer - storiface.Storage -} - -type Storage interface { - storiface.Prover - StorageSealer - - UnsealPiece(ctx context.Context, sector storiface.SectorRef, offset storiface.UnpaddedByteIndex, size abi.UnpaddedPieceSize, randomness abi.SealRandomness, commd cid.Cid) error - ReadPiece(ctx context.Context, writer io.Writer, sector storiface.SectorRef, offset storiface.UnpaddedByteIndex, size abi.UnpaddedPieceSize) (bool, error) -} - -type Verifier interface { - VerifySeal(proof.SealVerifyInfo) (bool, error) - VerifyAggregateSeals(aggregate proof.AggregateSealVerifyProofAndInfos) (bool, error) - VerifyReplicaUpdate(update proof.ReplicaUpdateInfo) (bool, error) - VerifyWinningPoSt(ctx context.Context, info proof.WinningPoStVerifyInfo) (bool, error) - VerifyWindowPoSt(ctx context.Context, info proof.WindowPoStVerifyInfo) (bool, error) - - GenerateWinningPoStSectorChallenge(context.Context, abi.RegisteredPoStProof, abi.ActorID, abi.PoStRandomness, uint64) ([]uint64, error) -} - -// Prover contains cheap proving-related methods -type Prover interface { - // TODO: move GenerateWinningPoStSectorChallenge from the Verifier interface to here - - AggregateSealProofs(aggregateInfo proof.AggregateSealVerifyProofAndInfos, proofs [][]byte) ([]byte, error) -} - type SectorProvider interface { // * returns storiface.ErrSectorNotFound if a requested existing sector doesn't exist // * returns an error when allocate is set, and existing isn't, and the sector exists diff --git a/storage/sealer/ffiwrapper/verifier_cgo.go b/storage/sealer/ffiwrapper/verifier_cgo.go index 2ff5bc91a20..be41eac4349 100644 --- a/storage/sealer/ffiwrapper/verifier_cgo.go +++ b/storage/sealer/ffiwrapper/verifier_cgo.go @@ -128,7 +128,7 @@ func (sb *Sealer) pubExtendedSectorToPriv(ctx context.Context, mid abi.ActorID, return ffi.NewSortedPrivateSectorInfo(out...), skipped, done, nil } -var _ Verifier = ProofVerifier +var _ storiface.Verifier = ProofVerifier type proofVerifier struct{} diff --git a/storage/sealer/manager.go b/storage/sealer/manager.go index d1908d9f73b..47112cbc0f3 100644 --- a/storage/sealer/manager.go +++ b/storage/sealer/manager.go @@ -45,8 +45,8 @@ type Worker interface { } type SectorManager interface { - ffiwrapper.StorageSealer - storiface.Prover + storiface.Sealer + storiface.ProverPoSt storiface.WorkerReturn FaultTracker } @@ -64,7 +64,7 @@ type Manager struct { windowPoStSched *poStScheduler winningPoStSched *poStScheduler - localProver storiface.Prover + localProver storiface.ProverPoSt workLk sync.Mutex work *statestore.StateStore @@ -80,7 +80,7 @@ type Manager struct { waitRes map[WorkID]chan struct{} } -var _ storiface.Prover = &Manager{} +var _ storiface.ProverPoSt = &Manager{} type result struct { r interface{} diff --git a/storage/sealer/manager_test.go b/storage/sealer/manager_test.go index f71452b5e8c..75f12261c62 100644 --- a/storage/sealer/manager_test.go +++ b/storage/sealer/manager_test.go @@ -635,7 +635,7 @@ func TestRestartWorker(t *testing.T) { wds := datastore.NewMapDatastore() arch := make(chan chan apres) - w := newLocalWorker(func() (ffiwrapper.Storage, error) { + w := newLocalWorker(func() (storiface.Storage, error) { return &testExec{apch: arch}, nil }, WorkerConfig{ TaskTypes: localTasks, @@ -672,7 +672,7 @@ func TestRestartWorker(t *testing.T) { } // restart the worker - w = newLocalWorker(func() (ffiwrapper.Storage, error) { + w = newLocalWorker(func() (storiface.Storage, error) { return &testExec{apch: arch}, nil }, WorkerConfig{ TaskTypes: localTasks, @@ -708,7 +708,7 @@ func TestReenableWorker(t *testing.T) { wds := datastore.NewMapDatastore() arch := make(chan chan apres) - w := newLocalWorker(func() (ffiwrapper.Storage, error) { + w := newLocalWorker(func() (storiface.Storage, error) { return &testExec{apch: arch}, nil }, WorkerConfig{ TaskTypes: localTasks, @@ -781,7 +781,7 @@ func TestResUse(t *testing.T) { wds := datastore.NewMapDatastore() arch := make(chan chan apres) - w := newLocalWorker(func() (ffiwrapper.Storage, error) { + w := newLocalWorker(func() (storiface.Storage, error) { return &testExec{apch: arch}, nil }, WorkerConfig{ TaskTypes: localTasks, @@ -839,7 +839,7 @@ func TestResOverride(t *testing.T) { wds := datastore.NewMapDatastore() arch := make(chan chan apres) - w := newLocalWorker(func() (ffiwrapper.Storage, error) { + w := newLocalWorker(func() (storiface.Storage, error) { return &testExec{apch: arch}, nil }, WorkerConfig{ TaskTypes: localTasks, diff --git a/storage/sealer/mock/mock.go b/storage/sealer/mock/mock.go index 42ce7550147..baa644cc187 100644 --- a/storage/sealer/mock/mock.go +++ b/storage/sealer/mock/mock.go @@ -735,5 +735,5 @@ var MockVerifier = mockVerifProver{ var MockProver = MockVerifier var _ storiface.Sealer = &SectorMgr{} -var _ ffiwrapper.Verifier = MockVerifier -var _ ffiwrapper.Prover = MockProver +var _ storiface.Verifier = MockVerifier +var _ storiface.Prover = MockProver diff --git a/storage/sealer/storiface/storage.go b/storage/sealer/storiface/storage.go index 2872b76acb7..2271c95b0a9 100644 --- a/storage/sealer/storiface/storage.go +++ b/storage/sealer/storiface/storage.go @@ -19,17 +19,7 @@ type SectorRef struct { var NoSectorRef = SectorRef{} -type Storage interface { - // Creates a new empty sector (only allocate on disk. Layers above - // storage are responsible for assigning sector IDs) - NewSector(ctx context.Context, sector SectorRef) error - // Compute Data CID - DataCid(ctx context.Context, pieceSize abi.UnpaddedPieceSize, pieceData Data) (abi.PieceInfo, error) - // Add a piece to an existing *unsealed* sector - AddPiece(ctx context.Context, sector SectorRef, pieceSizes []abi.UnpaddedPieceSize, newPieceSize abi.UnpaddedPieceSize, pieceData Data) (abi.PieceInfo, error) -} - -type Prover interface { +type ProverPoSt interface { GenerateWinningPoSt(ctx context.Context, minerID abi.ActorID, sectorInfo []proof.ExtendedSectorInfo, randomness abi.PoStRandomness) ([]proof.PoStProof, error) GenerateWindowPoSt(ctx context.Context, minerID abi.ActorID, sectorInfo []proof.ExtendedSectorInfo, randomness abi.PoStRandomness) (proof []proof.PoStProof, skipped []abi.SectorID, err error) @@ -62,6 +52,10 @@ type ReplicaUpdateOut struct { } type Sealer interface { + NewSector(ctx context.Context, sector SectorRef) error + DataCid(ctx context.Context, pieceSize abi.UnpaddedPieceSize, pieceData Data) (abi.PieceInfo, error) + AddPiece(ctx context.Context, sector SectorRef, pieceSizes []abi.UnpaddedPieceSize, newPieceSize abi.UnpaddedPieceSize, pieceData Data) (abi.PieceInfo, error) + SealPreCommit1(ctx context.Context, sector SectorRef, ticket abi.SealRandomness, pieces []abi.PieceInfo) (PreCommit1Out, error) SealPreCommit2(ctx context.Context, sector SectorRef, pc1o PreCommit1Out) (SectorCids, error) @@ -92,3 +86,36 @@ type Sealer interface { FinalizeReplicaUpdate(ctx context.Context, sector SectorRef, keepUnsealed []Range) error } + +type Unsealer interface { + UnsealPiece(ctx context.Context, sector SectorRef, offset UnpaddedByteIndex, size abi.UnpaddedPieceSize, randomness abi.SealRandomness, commd cid.Cid) error + ReadPiece(ctx context.Context, writer io.Writer, sector SectorRef, offset UnpaddedByteIndex, size abi.UnpaddedPieceSize) (bool, error) +} + +type Storage interface { + ProverPoSt + Sealer + Unsealer +} + +type Validator interface { + CanCommit(sector SectorPaths) (bool, error) + CanProve(sector SectorPaths) (bool, error) +} + +type Verifier interface { + VerifySeal(proof.SealVerifyInfo) (bool, error) + VerifyAggregateSeals(aggregate proof.AggregateSealVerifyProofAndInfos) (bool, error) + VerifyReplicaUpdate(update proof.ReplicaUpdateInfo) (bool, error) + VerifyWinningPoSt(ctx context.Context, info proof.WinningPoStVerifyInfo) (bool, error) + VerifyWindowPoSt(ctx context.Context, info proof.WindowPoStVerifyInfo) (bool, error) + + GenerateWinningPoStSectorChallenge(context.Context, abi.RegisteredPoStProof, abi.ActorID, abi.PoStRandomness, uint64) ([]uint64, error) +} + +// Prover contains cheap proving-related methods +type Prover interface { + // TODO: move GenerateWinningPoStSectorChallenge from the Verifier interface to here + + AggregateSealProofs(aggregateInfo proof.AggregateSealVerifyProofAndInfos, proofs [][]byte) ([]byte, error) +} diff --git a/storage/sealer/teststorage_test.go b/storage/sealer/teststorage_test.go index 9fbe1bd6b7c..f88aa93556e 100644 --- a/storage/sealer/teststorage_test.go +++ b/storage/sealer/teststorage_test.go @@ -9,7 +9,6 @@ import ( "github.com/filecoin-project/go-state-types/abi" "github.com/filecoin-project/specs-actors/v7/actors/runtime/proof" - "github.com/filecoin-project/lotus/storage/sealer/ffiwrapper" "github.com/filecoin-project/lotus/storage/sealer/storiface" ) @@ -121,4 +120,4 @@ func (t *testExec) ReadPiece(ctx context.Context, writer io.Writer, sector stori panic("implement me") } -var _ ffiwrapper.Storage = &testExec{} +var _ storiface.Storage = &testExec{} diff --git a/storage/sealer/worker_local.go b/storage/sealer/worker_local.go index f2a2f5cc1af..78d4c3e5a4b 100644 --- a/storage/sealer/worker_local.go +++ b/storage/sealer/worker_local.go @@ -44,7 +44,7 @@ type WorkerConfig struct { } // used do provide custom proofs impl (mostly used in testing) -type ExecutorFunc func() (ffiwrapper.Storage, error) +type ExecutorFunc func() (storiface.Storage, error) type EnvFunc func(string) (string, bool) type LocalWorker struct { @@ -172,7 +172,7 @@ func (l *localWorkerPathProvider) AcquireSector(ctx context.Context, sector stor }, nil } -func (l *LocalWorker) ffiExec() (ffiwrapper.Storage, error) { +func (l *LocalWorker) ffiExec() (storiface.Storage, error) { return ffiwrapper.New(&localWorkerPathProvider{w: l}) } diff --git a/storage/wdpost/wdpost_sched.go b/storage/wdpost/wdpost_sched.go index 65cc8ba456d..6ac77d9ba91 100644 --- a/storage/wdpost/wdpost_sched.go +++ b/storage/wdpost/wdpost_sched.go @@ -25,7 +25,6 @@ import ( "github.com/filecoin-project/lotus/node/config" "github.com/filecoin-project/lotus/storage/ctladdr" "github.com/filecoin-project/lotus/storage/sealer" - "github.com/filecoin-project/lotus/storage/sealer/ffiwrapper" "github.com/filecoin-project/lotus/storage/sealer/storiface" ) @@ -66,8 +65,8 @@ type WindowPoStScheduler struct { api NodeAPI feeCfg config.MinerFeeConfig addrSel *ctladdr.AddressSelector - prover storiface.Prover - verifier ffiwrapper.Verifier + prover storiface.ProverPoSt + verifier storiface.Verifier faultTracker sealer.FaultTracker proofType abi.RegisteredPoStProof partitionSectors uint64 @@ -86,8 +85,8 @@ type WindowPoStScheduler struct { func NewWindowedPoStScheduler(api NodeAPI, cfg config.MinerFeeConfig, as *ctladdr.AddressSelector, - sp storiface.Prover, - verif ffiwrapper.Verifier, + sp storiface.ProverPoSt, + verif storiface.Verifier, ft sealer.FaultTracker, j journal.Journal, actor address.Address) (*WindowPoStScheduler, error) {