2ebc111b70
Remove the bespoke instantiation of libp2p host and datatransfer manager for index provider and reuse the existing instances used by markets. The rationale for reuse is the following: 1. Separation of host introduces a discovery problem, where without gossipsub the index provider endpoint will not be discoverable. Using the same host as markets would mean the chain can be used to discover addresses, putting less empassis on criticality of gossipsub considering its set-up cost and lack of message delivery guarantees. 2. Only a single instance of graphsync/datatransfer can be instantiated per libp2p host; therefore, if the host is shared, so should datatransfer manager. 3. it is not clear if the assumptions under which separation was decided still hold.
72 lines
2.2 KiB
Go
72 lines
2.2 KiB
Go
package modules
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/ipfs/go-datastore"
|
|
"github.com/libp2p/go-libp2p-core/peer"
|
|
"github.com/libp2p/go-libp2p-core/peerstore"
|
|
"go.uber.org/fx"
|
|
|
|
"github.com/filecoin-project/go-address"
|
|
provider "github.com/filecoin-project/index-provider"
|
|
"github.com/filecoin-project/index-provider/engine"
|
|
"github.com/ipfs/go-datastore/namespace"
|
|
"github.com/libp2p/go-libp2p-core/host"
|
|
"golang.org/x/xerrors"
|
|
|
|
"github.com/filecoin-project/lotus/node/config"
|
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
|
)
|
|
|
|
type IdxProv struct {
|
|
fx.In
|
|
|
|
fx.Lifecycle
|
|
Datastore dtypes.MetadataDS
|
|
PeerID peer.ID
|
|
peerstore.Peerstore
|
|
}
|
|
|
|
func IndexProvider(cfg config.IndexProviderConfig) func(params IdxProv, marketHost host.Host, dt dtypes.ProviderDataTransfer, maddr dtypes.MinerAddress) (provider.Interface, error) {
|
|
return func(args IdxProv, marketHost host.Host, dt dtypes.ProviderDataTransfer, maddr dtypes.MinerAddress) (provider.Interface, error) {
|
|
ipds := namespace.Wrap(args.Datastore, datastore.NewKey("/index-provider"))
|
|
|
|
pkey := args.Peerstore.PrivKey(args.PeerID)
|
|
if pkey == nil {
|
|
return nil, xerrors.Errorf("missing private key for node ID: %s", args.PeerID)
|
|
}
|
|
|
|
var retAdds []string
|
|
for _, a := range marketHost.Addrs() {
|
|
retAdds = append(retAdds, a.String())
|
|
}
|
|
|
|
// Get the miner ID and set as extra gossip data.
|
|
// The extra data is required by the lotus-specific index-provider gossip message validators.
|
|
ma := address.Address(maddr)
|
|
log.Infof("Using extra gossip data in index provider engine: %s", ma)
|
|
|
|
e, err := engine.New(cfg.Ingest, pkey, dt, marketHost, ipds, retAdds, engine.WithExtraGossipData(ma.Bytes()))
|
|
if err != nil {
|
|
return nil, xerrors.Errorf("creating indexer provider engine: %w", err)
|
|
}
|
|
|
|
args.Lifecycle.Append(fx.Hook{
|
|
OnStart: func(ctx context.Context) error {
|
|
if err := e.Start(ctx); err != nil {
|
|
return xerrors.Errorf("starting indexer provider engine: %w", err)
|
|
}
|
|
return nil
|
|
},
|
|
OnStop: func(_ context.Context) error {
|
|
if err := e.Shutdown(); err != nil {
|
|
return xerrors.Errorf("shutting down indexer provider engine: %w", err)
|
|
}
|
|
return nil
|
|
},
|
|
})
|
|
return e, nil
|
|
}
|
|
}
|