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

Fix/refract code #31

Merged
merged 1 commit into from
Nov 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 19 additions & 17 deletions api/impl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package impl
import (
"context"
"fmt"
"github.com/filecoin-project/venus-market/models/repo"
"os"
"sort"
"time"
Expand Down Expand Up @@ -60,13 +61,14 @@ type MarketNodeImpl struct {
RetrievalAskHandler retrievaladapter.IAskHandler
DataTransfer network.ProviderDataTransfer
DealPublisher *storageadapter2.DealPublisher
PieceStore piece.PieceStoreEx
Messager clients2.IMessager `optional:"true"`
DAGStore *dagstore.DAGStore
PieceStorage piece.IPieceStorage
MinerMgr minermgr.IMinerMgr
PaychAPI paych3.PaychAPI

DealAssigner piece.DealAssiger

Messager clients2.IMessager `optional:"true"`
DAGStore *dagstore.DAGStore
PieceStorage piece.IPieceStorage
MinerMgr minermgr.IMinerMgr
PaychAPI paych3.PaychAPI
Repo repo.Repo
ConsiderOnlineStorageDealsConfigFunc config.ConsiderOnlineStorageDealsConfigFunc
SetConsiderOnlineStorageDealsConfigFunc config.SetConsiderOnlineStorageDealsConfigFunc
ConsiderOnlineRetrievalDealsConfigFunc config.ConsiderOnlineRetrievalDealsConfigFunc
Expand Down Expand Up @@ -241,23 +243,23 @@ func (m MarketNodeImpl) MarketPublishPendingDeals(ctx context.Context) error {
}

func (m MarketNodeImpl) PiecesListPieces(ctx context.Context) ([]cid.Cid, error) {
return m.PieceStore.ListPieceInfoKeys()
return m.DealAssigner.ListPieceInfoKeys()
}

func (m MarketNodeImpl) PiecesListCidInfos(ctx context.Context) ([]cid.Cid, error) {
return m.PieceStore.ListCidInfoKeys()
return m.Repo.CidInfoRepo().ListCidInfoKeys()
}

func (m MarketNodeImpl) PiecesGetPieceInfo(ctx context.Context, pieceCid cid.Cid) (*piecestore.PieceInfo, error) {
pi, err := m.PieceStore.GetPieceInfo(pieceCid)
pi, err := m.DealAssigner.GetPieceInfo(pieceCid)
if err != nil {
return nil, err
}
return &pi, nil
}

func (m MarketNodeImpl) PiecesGetCIDInfo(ctx context.Context, payloadCid cid.Cid) (*piecestore.CIDInfo, error) {
ci, err := m.PieceStore.GetCIDInfo(payloadCid)
ci, err := m.Repo.CidInfoRepo().GetCIDInfo(payloadCid)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -630,23 +632,23 @@ func (m MarketNodeImpl) DagstoreGC(ctx context.Context) ([]types.DagstoreShardRe
}

func (m MarketNodeImpl) GetUnPackedDeals(ctx context.Context, miner address.Address, spec *piece.GetDealSpec) ([]*piece.DealInfoIncludePath, error) {
return m.PieceStore.GetUnPackedDeals(ctx, miner, spec)
return m.DealAssigner.GetUnPackedDeals(ctx, miner, spec)
}

func (m MarketNodeImpl) AssignUnPackedDeals(ctx context.Context, miner address.Address, ssize abi.SectorSize, spec *piece.GetDealSpec) ([]*piece.DealInfoIncludePath, error) {
return m.PieceStore.AssignUnPackedDeals(ctx, miner, ssize, spec)
return m.DealAssigner.AssignUnPackedDeals(ctx, miner, ssize, spec)
}

func (m MarketNodeImpl) MarkDealsAsPacking(ctx context.Context, miner address.Address, deals []abi.DealID) error {
return m.PieceStore.MarkDealsAsPacking(ctx, miner, deals)
return m.DealAssigner.MarkDealsAsPacking(ctx, miner, deals)
}

func (m MarketNodeImpl) UpdateDealOnPacking(ctx context.Context, miner address.Address, dealId abi.DealID, sectorid abi.SectorNumber, offset abi.PaddedPieceSize) error {
return m.PieceStore.UpdateDealOnPacking(ctx, miner, dealId, sectorid, offset)
return m.DealAssigner.UpdateDealOnPacking(ctx, miner, dealId, sectorid, offset)
}

func (m MarketNodeImpl) UpdateDealStatus(ctx context.Context, miner address.Address, dealId abi.DealID, status string) error {
return m.PieceStore.UpdateDealStatus(ctx, miner, dealId, status)
return m.DealAssigner.UpdateDealStatus(ctx, miner, dealId, status)
}

func (m MarketNodeImpl) DealsImportData(ctx context.Context, dealPropCid cid.Cid, fname string) error {
Expand All @@ -660,7 +662,7 @@ func (m MarketNodeImpl) DealsImportData(ctx context.Context, dealPropCid cid.Cid
}

func (m MarketNodeImpl) GetDeals(ctx context.Context, miner address.Address, pageIndex, pageSize int) ([]*piece.DealInfo, error) {
return m.PieceStore.GetDeals(ctx, miner, pageIndex, pageSize)
return m.DealAssigner.GetDeals(ctx, miner, pageIndex, pageSize)
}

func (m MarketNodeImpl) PaychVoucherList(ctx context.Context, pch address.Address) ([]*paych.SignedVoucher, error) {
Expand Down
11 changes: 11 additions & 0 deletions builder/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ func ApplyIf(check func(s *Settings) bool, opts ...Option) Option {
}
}

func ApplyIfElse(check func(s *Settings) bool, ifOpt Option, elseOpt Option) Option {
return func(s *Settings) error {
if check(s) {
return Options(ifOpt)(s)
} else {
return Options(ifOpt)(s)
}
return nil
}
}

func If(b bool, opts ...Option) Option {
return ApplyIf(func(s *Settings) bool {
return b
Expand Down
12 changes: 6 additions & 6 deletions client/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"context"
"github.com/filecoin-project/venus-market/models/badger"
"os"
"path/filepath"
"time"
Expand All @@ -27,7 +28,6 @@ import (
"github.com/filecoin-project/venus-market/config"
"github.com/filecoin-project/venus-market/imports"
"github.com/filecoin-project/venus-market/journal"
"github.com/filecoin-project/venus-market/models/repo"
"github.com/filecoin-project/venus-market/network"
"github.com/filecoin-project/venus-market/paychmgr"
"github.com/filecoin-project/venus-market/retrievaladapter"
Expand All @@ -42,7 +42,7 @@ type StorageProviderEvt struct {
Deal storagemarket.MinerDeal
}

func NewLocalDiscovery(lc fx.Lifecycle, ds repo.ClientDealsDS) (*discoveryimpl.Local, error) {
func NewLocalDiscovery(lc fx.Lifecycle, ds badger.ClientDealsDS) (*discoveryimpl.Local, error) {
local, err := discoveryimpl.NewLocal(ds) //todo need new discoveryimpl base on sql
if err != nil {
return nil, err
Expand All @@ -60,7 +60,7 @@ func RetrievalResolver(l *discoveryimpl.Local) discovery.PeerResolver {
return discoveryimpl.Multi(l)
}

func NewClientImportMgr(ns repo.ImportClientDS, r *config.HomeDir) (ClientImportMgr, error) {
func NewClientImportMgr(ns badger.ImportClientDS, r *config.HomeDir) (ClientImportMgr, error) {
// store the imports under the repo's `imports` subdirectory.
dir := filepath.Join(string(*r), "imports")
if err := os.MkdirAll(dir, 0755); err != nil {
Expand All @@ -72,7 +72,7 @@ func NewClientImportMgr(ns repo.ImportClientDS, r *config.HomeDir) (ClientImport

// NewClientGraphsyncDataTransfer returns a data transfer manager that just
// uses the clients's Client DAG service for transfers
func NewClientGraphsyncDataTransfer(lc fx.Lifecycle, h host.Host, gs network.Graphsync, dtDs repo.ClientTransferDS, homeDir *config.HomeDir) (network.ClientDataTransfer, error) {
func NewClientGraphsyncDataTransfer(lc fx.Lifecycle, h host.Host, gs network.Graphsync, dtDs badger.ClientTransferDS, homeDir *config.HomeDir) (network.ClientDataTransfer, error) {
// go-data-transfer protocol retries:
// 1s, 5s, 25s, 2m5s, 5m x 11 ~= 1 hour
dtRetryParams := dtnet.RetryParameters(time.Second, 5*time.Minute, 15, 5)
Expand Down Expand Up @@ -137,7 +137,7 @@ func RetrievalBlockstoreAccessor(r *config.HomeDir) (retrievalmarket.BlockstoreA
}

func StorageClient(lc fx.Lifecycle, h host.Host, dataTransfer network.ClientDataTransfer, discovery *discoveryimpl.Local,
deals repo.ClientDatastore, scn storagemarket.StorageClientNode, accessor storagemarket.BlockstoreAccessor, j journal.Journal) (storagemarket.StorageClient, error) {
deals badger.ClientDatastore, scn storagemarket.StorageClientNode, accessor storagemarket.BlockstoreAccessor, j journal.Journal) (storagemarket.StorageClient, error) {
// go-fil-markets protocol retries:
// 1s, 5s, 25s, 2m5s, 5m x 11 ~= 1 hour
marketsRetryParams := smnet.RetryParameters(time.Second, 5*time.Minute, 15, 5)
Expand Down Expand Up @@ -166,7 +166,7 @@ func StorageClient(lc fx.Lifecycle, h host.Host, dataTransfer network.ClientData

// RetrievalClient creates a new retrieval client attached to the client blockstore
func RetrievalClient(lc fx.Lifecycle, h host.Host, dt network.ClientDataTransfer, payAPI *paychmgr.PaychAPI, resolver discovery.PeerResolver,
ds repo.RetrievalClientDS, fullApi apiface.FullNode, accessor retrievalmarket.BlockstoreAccessor, j journal.Journal) (retrievalmarket.RetrievalClient, error) {
ds badger.RetrievalClientDS, fullApi apiface.FullNode, accessor retrievalmarket.BlockstoreAccessor, j journal.Journal) (retrievalmarket.RetrievalClient, error) {

adapter := retrievaladapter.NewRetrievalClientNode(payAPI, fullApi)
libP2pHost := rmnet.NewFromLibp2pHost(h)
Expand Down
2 changes: 1 addition & 1 deletion cmd/market-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"github.com/filecoin-project/venus-market/models"
"log"
"os"

Expand All @@ -17,7 +18,6 @@ import (
"github.com/filecoin-project/venus-market/fundmgr"
"github.com/filecoin-project/venus-market/journal"
"github.com/filecoin-project/venus-market/metrics"
"github.com/filecoin-project/venus-market/models"
"github.com/filecoin-project/venus-market/network"
"github.com/filecoin-project/venus-market/paychmgr"
"github.com/filecoin-project/venus-market/rpc"
Expand Down
6 changes: 3 additions & 3 deletions cmd/venus-market/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"context"
"github.com/filecoin-project/venus-market/dagstore"
"github.com/filecoin-project/venus-market/models"
"log"
"os"

Expand All @@ -16,13 +18,11 @@ import (
"github.com/filecoin-project/venus-market/fundmgr"
"github.com/filecoin-project/venus-market/journal"
"github.com/filecoin-project/venus-market/metrics"
"github.com/filecoin-project/venus-market/models"
"github.com/filecoin-project/venus-market/network"
"github.com/filecoin-project/venus-market/paychmgr"
"github.com/filecoin-project/venus-market/piece"
"github.com/filecoin-project/venus-market/retrievaladapter"
"github.com/filecoin-project/venus-market/rpc"
"github.com/filecoin-project/venus-market/sealer"
"github.com/filecoin-project/venus-market/storageadapter"
"github.com/filecoin-project/venus-market/types"
"github.com/filecoin-project/venus-market/utils"
Expand Down Expand Up @@ -192,7 +192,7 @@ func daemon(cctx *cli.Context) error {
network.NetworkOpts(true, cfg.SimultaneousTransfers),
piece.PieceOpts(cfg),
fundmgr.FundMgrOpts,
sealer.SealerOpts,
dagstore.DagstoreOpts,
paychmgr.PaychOpts,
// Markets
storageadapter.StorageProviderOpts(cfg),
Expand Down
Loading