Merge pull request #1520 from filecoin-project/feat/graphsync-chainsync-extension
Update to latest go-fil-markets w/ enhanced Graphsync
This commit is contained in:
@@ -8,7 +8,6 @@ import (
|
||||
blockstore "github.com/ipfs/go-ipfs-blockstore"
|
||||
exchange "github.com/ipfs/go-ipfs-exchange-interface"
|
||||
format "github.com/ipfs/go-ipld-format"
|
||||
"github.com/ipld/go-ipld-prime"
|
||||
|
||||
datatransfer "github.com/filecoin-project/go-data-transfer"
|
||||
"github.com/filecoin-project/go-fil-markets/piecestore"
|
||||
@@ -32,8 +31,6 @@ type ClientDAG format.DAGService
|
||||
type ClientDealStore *statestore.StateStore
|
||||
type ClientDatastore datastore.Batching
|
||||
|
||||
type GraphsyncLoader ipld.Loader
|
||||
type GraphsyncStorer ipld.Storer
|
||||
type Graphsync graphsync.GraphExchange
|
||||
|
||||
// ClientDataTransfer is a data transfer manager for the client
|
||||
|
||||
+29
-28
@@ -1,42 +1,43 @@
|
||||
package modules
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||
"github.com/filecoin-project/lotus/node/modules/helpers"
|
||||
graphsync "github.com/ipfs/go-graphsync/impl"
|
||||
"github.com/ipfs/go-graphsync/ipldbridge"
|
||||
"github.com/ipfs/go-graphsync"
|
||||
graphsyncimpl "github.com/ipfs/go-graphsync/impl"
|
||||
gsnet "github.com/ipfs/go-graphsync/network"
|
||||
"github.com/ipfs/go-graphsync/storeutil"
|
||||
"github.com/ipld/go-ipld-prime"
|
||||
"github.com/libp2p/go-libp2p-core/host"
|
||||
peer "github.com/libp2p/go-libp2p-peer"
|
||||
"go.uber.org/fx"
|
||||
)
|
||||
|
||||
// GraphsyncStorer creates a storer that stores data in the client blockstore
|
||||
func GraphsyncStorer(chainBs dtypes.ChainBlockstore) dtypes.GraphsyncStorer {
|
||||
return dtypes.GraphsyncStorer(storeutil.StorerForBlockstore(chainBs))
|
||||
}
|
||||
|
||||
// GraphsyncLoader creates a loader that reads from both the chain blockstore and the client blockstore
|
||||
func GraphsyncLoader(clientBs dtypes.ClientBlockstore, chainBs dtypes.ChainBlockstore) dtypes.GraphsyncLoader {
|
||||
clientLoader := storeutil.LoaderForBlockstore(clientBs)
|
||||
chainLoader := storeutil.LoaderForBlockstore(chainBs)
|
||||
return func(lnk ipld.Link, lnkCtx ipld.LinkContext) (io.Reader, error) {
|
||||
reader, err := chainLoader(lnk, lnkCtx)
|
||||
if err != nil {
|
||||
return clientLoader(lnk, lnkCtx)
|
||||
}
|
||||
return reader, err
|
||||
}
|
||||
}
|
||||
|
||||
// Graphsync creates a graphsync instance from the given loader and storer
|
||||
func Graphsync(mctx helpers.MetricsCtx, lc fx.Lifecycle, loader dtypes.GraphsyncLoader, storer dtypes.GraphsyncStorer, h host.Host) dtypes.Graphsync {
|
||||
func Graphsync(mctx helpers.MetricsCtx, lc fx.Lifecycle, clientBs dtypes.ClientBlockstore, chainBs dtypes.ChainBlockstore, h host.Host) (dtypes.Graphsync, error) {
|
||||
graphsyncNetwork := gsnet.NewFromLibp2pHost(h)
|
||||
ipldBridge := ipldbridge.NewIPLDBridge()
|
||||
gs := graphsync.New(helpers.LifecycleCtx(mctx, lc), graphsyncNetwork, ipldBridge, ipld.Loader(loader), ipld.Storer(storer))
|
||||
|
||||
return gs
|
||||
loader := storeutil.LoaderForBlockstore(clientBs)
|
||||
storer := storeutil.StorerForBlockstore(clientBs)
|
||||
gs := graphsyncimpl.New(helpers.LifecycleCtx(mctx, lc), graphsyncNetwork, loader, storer, graphsyncimpl.RejectAllRequestsByDefault())
|
||||
chainLoader := storeutil.LoaderForBlockstore(chainBs)
|
||||
chainStorer := storeutil.StorerForBlockstore(chainBs)
|
||||
err := gs.RegisterPersistenceOption("chainstore", chainLoader, chainStorer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
gs.RegisterIncomingRequestHook(func(p peer.ID, requestData graphsync.RequestData, hookActions graphsync.IncomingRequestHookActions) {
|
||||
_, has := requestData.Extension("chainsync")
|
||||
if has {
|
||||
// TODO: we should confirm the selector is a reasonable one before we validate
|
||||
// TODO: this code will get more complicated and should probably not live here eventually
|
||||
hookActions.ValidateRequest()
|
||||
hookActions.UsePersistenceOption("chainstore")
|
||||
}
|
||||
})
|
||||
gs.RegisterOutgoingRequestHook(func(p peer.ID, requestData graphsync.RequestData, hookActions graphsync.OutgoingRequestHookActions) {
|
||||
_, has := requestData.Extension("chainsync")
|
||||
if has {
|
||||
hookActions.UsePersistenceOption("chainstore")
|
||||
}
|
||||
})
|
||||
return gs, nil
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"github.com/ipfs/go-datastore"
|
||||
"github.com/ipfs/go-datastore/namespace"
|
||||
graphsync "github.com/ipfs/go-graphsync/impl"
|
||||
"github.com/ipfs/go-graphsync/ipldbridge"
|
||||
gsnet "github.com/ipfs/go-graphsync/network"
|
||||
"github.com/ipfs/go-graphsync/storeutil"
|
||||
blockstore "github.com/ipfs/go-ipfs-blockstore"
|
||||
@@ -250,10 +249,9 @@ func StagingDAG(mctx helpers.MetricsCtx, lc fx.Lifecycle, ibs dtypes.StagingBloc
|
||||
// to the StagingBlockstore
|
||||
func StagingGraphsync(mctx helpers.MetricsCtx, lc fx.Lifecycle, ibs dtypes.StagingBlockstore, h host.Host) dtypes.StagingGraphsync {
|
||||
graphsyncNetwork := gsnet.NewFromLibp2pHost(h)
|
||||
ipldBridge := ipldbridge.NewIPLDBridge()
|
||||
loader := storeutil.LoaderForBlockstore(ibs)
|
||||
storer := storeutil.StorerForBlockstore(ibs)
|
||||
gs := graphsync.New(helpers.LifecycleCtx(mctx, lc), graphsyncNetwork, ipldBridge, loader, storer)
|
||||
gs := graphsync.New(helpers.LifecycleCtx(mctx, lc), graphsyncNetwork, loader, storer, graphsync.RejectAllRequestsByDefault())
|
||||
|
||||
return gs
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user