Fix test node setup

This commit is contained in:
Łukasz Magiera 2019-07-16 18:02:51 +02:00
parent 041598dbb6
commit d30d9a30bc
5 changed files with 34 additions and 10 deletions

View File

@ -2,8 +2,6 @@ package node
import ( import (
"context" "context"
"github.com/ipfs/go-filestore"
"github.com/filecoin-project/go-lotus/api" "github.com/filecoin-project/go-lotus/api"
"github.com/filecoin-project/go-lotus/build" "github.com/filecoin-project/go-lotus/build"
"github.com/filecoin-project/go-lotus/chain" "github.com/filecoin-project/go-lotus/chain"
@ -23,7 +21,6 @@ type API struct {
Host host.Host Host host.Host
Chain *chain.ChainStore Chain *chain.ChainStore
PubSub *pubsub.PubSub PubSub *pubsub.PubSub
Filestore *filestore.Filestore
Mpool *chain.MessagePool Mpool *chain.MessagePool
Wallet *chain.Wallet Wallet *chain.Wallet
} }

View File

@ -168,8 +168,7 @@ func Online() Option {
Override(new(blockstore.GCLocker), blockstore.NewGCLocker), Override(new(blockstore.GCLocker), blockstore.NewGCLocker),
Override(new(blockstore.GCBlockstore), blockstore.NewGCBlockstore), Override(new(blockstore.GCBlockstore), blockstore.NewGCBlockstore),
Override(new(exchange.Interface), modules.Bitswap), Override(new(exchange.Interface), modules.Bitswap),
Override(new(*filestore.Filestore), modules.ClientFstore), Override(new(ipld.DAGService), testing.MemoryClientDag),
Override(new(ipld.DAGService), modules.ClientDAG),
// Filecoin services // Filecoin services
Override(new(*chain.Syncer), chain.NewSyncer), Override(new(*chain.Syncer), chain.NewSyncer),
@ -221,6 +220,9 @@ func Repo(r repo.Repo) Option {
Override(new(datastore.Batching), modules.Datastore), Override(new(datastore.Batching), modules.Datastore),
Override(new(blockstore.Blockstore), modules.Blockstore), Override(new(blockstore.Blockstore), modules.Blockstore),
Override(new(*filestore.Filestore), modules.ClientFstore),
Override(new(ipld.DAGService), modules.ClientDAG),
Override(new(ci.PrivKey), pk), Override(new(ci.PrivKey), pk),
Override(new(ci.PubKey), ci.PrivKey.GetPublic), Override(new(ci.PubKey), ci.PrivKey.GetPublic),
Override(new(peer.ID), peer.IDFromPublicKey), Override(new(peer.ID), peer.IDFromPublicKey),

View File

@ -2,6 +2,7 @@ package client
import ( import (
"context" "context"
"errors"
"github.com/filecoin-project/go-lotus/api" "github.com/filecoin-project/go-lotus/api"
"github.com/ipfs/go-filestore" "github.com/ipfs/go-filestore"
"go.uber.org/fx" "go.uber.org/fx"
@ -19,7 +20,7 @@ type LocalStorage struct {
fx.In fx.In
LocalDAG ipld.DAGService LocalDAG ipld.DAGService
Filestore *filestore.Filestore Filestore *filestore.Filestore `optional:"true"`
} }
func (s *LocalStorage) ClientImport(ctx context.Context, path string) (cid.Cid, error) { func (s *LocalStorage) ClientImport(ctx context.Context, path string) (cid.Cid, error) {
@ -60,6 +61,9 @@ func (s *LocalStorage) ClientImport(ctx context.Context, path string) (cid.Cid,
} }
func (s *LocalStorage) ClientListImports(ctx context.Context) ([]api.Import, error) { func (s *LocalStorage) ClientListImports(ctx context.Context) ([]api.Import, error) {
if s.Filestore == nil {
return nil, errors.New("listing imports is not supported with in-memory dag yet")
}
next, err := filestore.ListAll(s.Filestore, false) next, err := filestore.ListAll(s.Filestore, false)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -2,20 +2,20 @@ package modules
import ( import (
"context" "context"
"github.com/ipfs/go-blockservice"
"github.com/ipfs/go-datastore/namespace"
"github.com/ipfs/go-filestore"
"github.com/ipfs/go-merkledag"
"path/filepath" "path/filepath"
"github.com/ipfs/go-bitswap" "github.com/ipfs/go-bitswap"
"github.com/ipfs/go-bitswap/network" "github.com/ipfs/go-bitswap/network"
"github.com/ipfs/go-blockservice"
"github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore"
"github.com/ipfs/go-datastore/namespace"
"github.com/ipfs/go-filestore"
blockstore "github.com/ipfs/go-ipfs-blockstore" blockstore "github.com/ipfs/go-ipfs-blockstore"
exchange "github.com/ipfs/go-ipfs-exchange-interface" exchange "github.com/ipfs/go-ipfs-exchange-interface"
offline "github.com/ipfs/go-ipfs-exchange-offline" offline "github.com/ipfs/go-ipfs-exchange-offline"
ipld "github.com/ipfs/go-ipld-format" ipld "github.com/ipfs/go-ipld-format"
logging "github.com/ipfs/go-log" logging "github.com/ipfs/go-log"
"github.com/ipfs/go-merkledag"
"github.com/libp2p/go-libp2p-core/host" "github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/peerstore" "github.com/libp2p/go-libp2p-core/peerstore"
"github.com/libp2p/go-libp2p-core/routing" "github.com/libp2p/go-libp2p-core/routing"

View File

@ -1,9 +1,16 @@
package testing package testing
import ( import (
"context"
"github.com/ipfs/go-blockservice"
"github.com/ipfs/go-datastore" "github.com/ipfs/go-datastore"
dsync "github.com/ipfs/go-datastore/sync" dsync "github.com/ipfs/go-datastore/sync"
blockstore "github.com/ipfs/go-ipfs-blockstore" blockstore "github.com/ipfs/go-ipfs-blockstore"
offline "github.com/ipfs/go-ipfs-exchange-offline"
ipld "github.com/ipfs/go-ipld-format"
"github.com/ipfs/go-merkledag"
"go.uber.org/fx"
) )
func MapBlockstore() blockstore.Blockstore { func MapBlockstore() blockstore.Blockstore {
@ -16,3 +23,17 @@ func MapBlockstore() blockstore.Blockstore {
func MapDatastore() datastore.Batching { func MapDatastore() datastore.Batching {
return dsync.MutexWrap(datastore.NewMapDatastore()) return dsync.MutexWrap(datastore.NewMapDatastore())
} }
func MemoryClientDag(lc fx.Lifecycle) ipld.DAGService {
ibs := blockstore.NewBlockstore(datastore.NewMapDatastore())
bsvc := blockservice.New(ibs, offline.Exchange(ibs))
dag := merkledag.NewDAGService(bsvc)
lc.Append(fx.Hook{
OnStop: func(_ context.Context) error {
return bsvc.Close()
},
})
return dag
}