diff --git a/node/impl/client/client.go b/node/impl/client/client.go index 8026d7e7c..e4e1aa7f9 100644 --- a/node/impl/client/client.go +++ b/node/impl/client/client.go @@ -66,6 +66,8 @@ type API struct { Chain *store.ChainStore Imports dtypes.ClientImportMgr + + RetBstore dtypes.ClientBlockstore // TODO: try to remove } func calcDealExpiration(minDuration uint64, md *miner.DeadlineInfo, startEpoch abi.ChainEpoch) abi.ChainEpoch { @@ -384,13 +386,13 @@ func (a *API) ClientRetrieve(ctx context.Context, order api.RetrievalOrder, ref return xerrors.Errorf("cannot make retrieval deal for zero bytes") } - id, st, err := a.imgr().NewStore() + /*id, st, err := a.imgr().NewStore() if err != nil { return err } if err := a.imgr().AddLabel(id, "source", "retrieval"); err != nil { return err - } + }*/ retrievalResult := make(chan error, 1) @@ -429,7 +431,7 @@ func (a *API) ClientRetrieve(ctx context.Context, order api.RetrievalOrder, ref ppb := types.BigDiv(order.Total, types.NewInt(order.Size)) - _, err = a.Retrieval.Retrieve( + _, err := a.Retrieval.Retrieve( ctx, order.Root, rm.NewParamsV0(ppb, order.PaymentInterval, order.PaymentIntervalIncrease), @@ -456,23 +458,25 @@ func (a *API) ClientRetrieve(ctx context.Context, order api.RetrievalOrder, ref return nil } + rdag := merkledag.NewDAGService(blockservice.New(a.RetBstore, offline.Exchange(a.RetBstore))) + if ref.IsCAR { f, err := os.OpenFile(ref.Path, os.O_CREATE|os.O_WRONLY, 0644) if err != nil { return err } - err = car.WriteCar(ctx, st.DAG, []cid.Cid{order.Root}, f) + err = car.WriteCar(ctx, rdag, []cid.Cid{order.Root}, f) if err != nil { return err } return f.Close() } - nd, err := st.DAG.Get(ctx, order.Root) + nd, err := rdag.Get(ctx, order.Root) if err != nil { return xerrors.Errorf("ClientRetrieve: %w", err) } - file, err := unixfile.NewUnixfsFile(ctx, st.DAG, nd) + file, err := unixfile.NewUnixfsFile(ctx, rdag, nd) if err != nil { return xerrors.Errorf("ClientRetrieve: %w", err) } diff --git a/node/modules/client.go b/node/modules/client.go index da0f3be06..55a6ae196 100644 --- a/node/modules/client.go +++ b/node/modules/client.go @@ -2,7 +2,7 @@ package modules import ( "context" - + "github.com/filecoin-project/lotus/lib/bufbstore" blockstore "github.com/ipfs/go-ipfs-blockstore" "github.com/libp2p/go-libp2p-core/host" "go.uber.org/fx" @@ -50,7 +50,12 @@ func ClientImportMgr(mds dtypes.ClientMultiDstore, ds dtypes.MetadataDS) dtypes. } func ClientBlockstore(imgr dtypes.ClientImportMgr) dtypes.ClientBlockstore { - return blockstore.NewIdStore(imgr.Blockstore) + // TODO: This isn't.. the best + // - If it's easy to pass per-retrieval blockstores with markets we don't need this + // - If it's not easy, we need to store this in a separate datastore on disk + defaultWrite := blockstore.NewBlockstore(datastore.NewMapDatastore()) + + return blockstore.NewIdStore(bufbstore.NewTieredBstore(imgr.Blockstore, defaultWrite)) } // RegisterClientValidator is an initialization hook that registers the client diff --git a/node/repo/importmgr/multistore.go b/node/repo/importmgr/multistore.go index 705a3c947..31bf7be35 100644 --- a/node/repo/importmgr/multistore.go +++ b/node/repo/importmgr/multistore.go @@ -18,7 +18,7 @@ type dsProvider interface { DeleteDatastore(namespace string) error } -type MultiStore struct { +type MultiStore struct { provider dsProvider namespace string