diff --git a/node/builder_chain.go b/node/builder_chain.go index 49cf9d94e..31cb95984 100644 --- a/node/builder_chain.go +++ b/node/builder_chain.go @@ -168,10 +168,9 @@ func ConfigFullNode(c interface{}) Option { If(cfg.Client.UseIpfs, Override(new(dtypes.ClientBlockstore), modules.IpfsClientBlockstore(ipfsMaddr, cfg.Client.IpfsOnlineMode)), - // TODO Fix this when we use IPFS for retrieval here. - /*If(cfg.Client.IpfsUseForRetrieval, + If(cfg.Client.IpfsUseForRetrieval, Override(new(dtypes.ClientRetrievalStoreManager), modules.ClientBlockstoreRetrievalStoreManager), - ),*/ + ), ), Override(new(dtypes.Graphsync), modules.Graphsync(cfg.Client.SimultaneousTransfers)), diff --git a/node/impl/client/client.go b/node/impl/client/client.go index 2f024c39d..6763b70e8 100644 --- a/node/impl/client/client.go +++ b/node/impl/client/client.go @@ -84,8 +84,6 @@ type API struct { DataTransfer dtypes.ClientDataTransfer Host host.Host - - // TODO How do we inject the Repo Path here ? } func calcDealExpiration(minDuration uint64, md *dline.Info, startEpoch abi.ChainEpoch) abi.ChainEpoch { diff --git a/node/modules/client.go b/node/modules/client.go index c485f1b46..0e3a2e320 100644 --- a/node/modules/client.go +++ b/node/modules/client.go @@ -7,6 +7,7 @@ import ( "path/filepath" "time" + "github.com/filecoin-project/lotus/node/repo/retrievalstoremgr" "go.uber.org/fx" "golang.org/x/xerrors" @@ -209,3 +210,8 @@ func RetrievalClient(lc fx.Lifecycle, h host.Host, r repo.LockedRepo, dt dtypes. }) return client, nil } + +// ClientBlockstoreRetrievalStoreManager is the default version of the RetrievalStoreManager that runs on multistore +func ClientBlockstoreRetrievalStoreManager(bs dtypes.ClientBlockstore) dtypes.ClientRetrievalStoreManager { + return retrievalstoremgr.NewBlockstoreRetrievalStoreManager(bs) +} diff --git a/node/modules/dtypes/storage.go b/node/modules/dtypes/storage.go index 9f339ef6c..cea67f214 100644 --- a/node/modules/dtypes/storage.go +++ b/node/modules/dtypes/storage.go @@ -1,6 +1,7 @@ package dtypes import ( + "github.com/filecoin-project/lotus/node/repo/retrievalstoremgr" bserv "github.com/ipfs/go-blockservice" "github.com/ipfs/go-datastore" "github.com/ipfs/go-graphsync" @@ -70,6 +71,7 @@ type ClientBlockstore blockstore.BasicBlockstore type ClientDealStore *statestore.StateStore type ClientRequestValidator *requestvalidation.UnifiedRequestValidator type ClientDatastore datastore.Batching +type ClientRetrievalStoreManager retrievalstoremgr.RetrievalStoreManager type Graphsync graphsync.GraphExchange diff --git a/node/repo/retrievalstoremgr/retrievalstoremgr.go b/node/repo/retrievalstoremgr/retrievalstoremgr.go new file mode 100644 index 000000000..c7fe812c5 --- /dev/null +++ b/node/repo/retrievalstoremgr/retrievalstoremgr.go @@ -0,0 +1,55 @@ +package retrievalstoremgr + +import ( + "github.com/filecoin-project/lotus/blockstore" + "github.com/ipfs/go-blockservice" + offline "github.com/ipfs/go-ipfs-exchange-offline" + ipldformat "github.com/ipfs/go-ipld-format" + "github.com/ipfs/go-merkledag" +) + +// RetrievalStore references a store for a retrieval deal. +type RetrievalStore interface { + DAGService() ipldformat.DAGService +} + +// RetrievalStoreManager manages stores for retrieval deals, abstracting +// the underlying storage mechanism. +type RetrievalStoreManager interface { + NewStore() (RetrievalStore, error) + ReleaseStore(RetrievalStore) error +} + +// BlockstoreRetrievalStoreManager manages a single blockstore as if it were multiple stores +type BlockstoreRetrievalStoreManager struct { + bs blockstore.BasicBlockstore +} + +var _ RetrievalStoreManager = &BlockstoreRetrievalStoreManager{} + +// NewBlockstoreRetrievalStoreManager returns a new blockstore based RetrievalStoreManager +func NewBlockstoreRetrievalStoreManager(bs blockstore.BasicBlockstore) RetrievalStoreManager { + return &BlockstoreRetrievalStoreManager{ + bs: bs, + } +} + +// NewStore creates a new store (just uses underlying blockstore) +func (brsm *BlockstoreRetrievalStoreManager) NewStore() (RetrievalStore, error) { + return &blockstoreRetrievalStore{ + dagService: merkledag.NewDAGService(blockservice.New(brsm.bs, offline.Exchange(brsm.bs))), + }, nil +} + +// ReleaseStore for this implementation does nothing +func (brsm *BlockstoreRetrievalStoreManager) ReleaseStore(RetrievalStore) error { + return nil +} + +type blockstoreRetrievalStore struct { + dagService ipldformat.DAGService +} + +func (brs *blockstoreRetrievalStore) DAGService() ipldformat.DAGService { + return brs.dagService +}