Don't build full API in storage miner
This commit is contained in:
parent
8d529d1ae7
commit
d0cbf02d36
@ -44,7 +44,7 @@ var runCmd = &cli.Command{
|
|||||||
return xerrors.Errorf("repo at '%s' is not initialized, run 'lotus-storage-miner init' to set it up", cctx.String(FlagStorageRepo))
|
return xerrors.Errorf("repo at '%s' is not initialized, run 'lotus-storage-miner init' to set it up", cctx.String(FlagStorageRepo))
|
||||||
}
|
}
|
||||||
|
|
||||||
minerapi, err := node.New(ctx,
|
err = node.New(ctx,
|
||||||
node.StorageMiner(),
|
node.StorageMiner(),
|
||||||
node.Online(),
|
node.Online(),
|
||||||
node.Repo(r),
|
node.Repo(r),
|
||||||
@ -66,7 +66,7 @@ var runCmd = &cli.Command{
|
|||||||
log.Infof("Remote version %s", v)
|
log.Infof("Remote version %s", v)
|
||||||
|
|
||||||
rpcServer := jsonrpc.NewServer()
|
rpcServer := jsonrpc.NewServer()
|
||||||
rpcServer.Register("Filecoin", minerapi)
|
//rpcServer.Register("Filecoin", minerapi)
|
||||||
http.Handle("/rpc/v0", rpcServer)
|
http.Handle("/rpc/v0", rpcServer)
|
||||||
return http.ListenAndServe("127.0.0.1:"+cctx.String("api"), http.DefaultServeMux)
|
return http.ListenAndServe("127.0.0.1:"+cctx.String("api"), http.DefaultServeMux)
|
||||||
},
|
},
|
||||||
|
@ -4,6 +4,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-lotus/api"
|
||||||
"github.com/multiformats/go-multiaddr"
|
"github.com/multiformats/go-multiaddr"
|
||||||
"gopkg.in/urfave/cli.v2"
|
"gopkg.in/urfave/cli.v2"
|
||||||
|
|
||||||
@ -32,7 +34,10 @@ var DaemonCmd = &cli.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
api, err := node.New(ctx,
|
var api api.API
|
||||||
|
err = node.New(ctx,
|
||||||
|
node.FullAPI(&api),
|
||||||
|
|
||||||
node.Online(),
|
node.Online(),
|
||||||
node.Repo(r),
|
node.Repo(r),
|
||||||
|
|
||||||
|
@ -71,6 +71,8 @@ const (
|
|||||||
HandleIncomingMessagesKey
|
HandleIncomingMessagesKey
|
||||||
|
|
||||||
// daemon
|
// daemon
|
||||||
|
ExtractApiKey
|
||||||
|
|
||||||
SetApiEndpointKey
|
SetApiEndpointKey
|
||||||
|
|
||||||
_nInvokes // keep this last
|
_nInvokes // keep this last
|
||||||
@ -125,10 +127,6 @@ func defaults() []Option {
|
|||||||
return []Option{
|
return []Option{
|
||||||
Override(new(helpers.MetricsCtx), context.Background),
|
Override(new(helpers.MetricsCtx), context.Background),
|
||||||
Override(new(record.Validator), modules.RecordValidator),
|
Override(new(record.Validator), modules.RecordValidator),
|
||||||
|
|
||||||
// Filecoin modules
|
|
||||||
|
|
||||||
Override(new(*chain.ChainStore), chain.NewChainStore),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -165,7 +163,6 @@ func libp2p() Option {
|
|||||||
// Online sets up basic libp2p node
|
// Online sets up basic libp2p node
|
||||||
func Online() Option {
|
func Online() Option {
|
||||||
return Options(
|
return Options(
|
||||||
Override(HandleIncomingMessagesKey, modules.HandleIncomingMessages),
|
|
||||||
// make sure that online is applied before Config.
|
// make sure that online is applied before Config.
|
||||||
// This is important because Config overrides some of Online units
|
// This is important because Config overrides some of Online units
|
||||||
func(s *Settings) error { s.Online = true; return nil },
|
func(s *Settings) error { s.Online = true; return nil },
|
||||||
@ -178,6 +175,12 @@ func Online() Option {
|
|||||||
// Full node
|
// Full node
|
||||||
|
|
||||||
ApplyIf(func(s *Settings) bool { return s.nodeType == nodeFull },
|
ApplyIf(func(s *Settings) bool { return s.nodeType == nodeFull },
|
||||||
|
// TODO: Fix offline mode
|
||||||
|
|
||||||
|
Override(HandleIncomingMessagesKey, modules.HandleIncomingMessages),
|
||||||
|
|
||||||
|
Override(new(*chain.ChainStore), chain.NewChainStore),
|
||||||
|
|
||||||
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),
|
||||||
@ -265,9 +268,17 @@ func Repo(r repo.Repo) Option {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// New builds and starts new Filecoin node
|
func FullAPI(out *api.API) Option {
|
||||||
func New(ctx context.Context, opts ...Option) (api.API, error) {
|
return func(s *Settings) error {
|
||||||
resAPI := &API{}
|
resAPI := &API{}
|
||||||
|
s.invokes[ExtractApiKey] = fx.Extract(resAPI)
|
||||||
|
*out = resAPI
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// New builds and starts new Filecoin node
|
||||||
|
func New(ctx context.Context, opts ...Option) error {
|
||||||
settings := Settings{
|
settings := Settings{
|
||||||
modules: map[interface{}]fx.Option{},
|
modules: map[interface{}]fx.Option{},
|
||||||
invokes: make([]fx.Option, _nInvokes),
|
invokes: make([]fx.Option, _nInvokes),
|
||||||
@ -275,7 +286,7 @@ func New(ctx context.Context, opts ...Option) (api.API, error) {
|
|||||||
|
|
||||||
// apply module options in the right order
|
// apply module options in the right order
|
||||||
if err := Options(Options(defaults()...), Options(opts...))(&settings); err != nil {
|
if err := Options(Options(defaults()...), Options(opts...))(&settings); err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// gather constructors for fx.Options
|
// gather constructors for fx.Options
|
||||||
@ -295,8 +306,6 @@ func New(ctx context.Context, opts ...Option) (api.API, error) {
|
|||||||
fx.Options(ctors...),
|
fx.Options(ctors...),
|
||||||
fx.Options(settings.invokes...),
|
fx.Options(settings.invokes...),
|
||||||
|
|
||||||
fx.Extract(resAPI),
|
|
||||||
|
|
||||||
fx.NopLogger,
|
fx.NopLogger,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -304,10 +313,10 @@ func New(ctx context.Context, opts ...Option) (api.API, error) {
|
|||||||
// on this context, and implement closing logic through lifecycles
|
// on this context, and implement closing logic through lifecycles
|
||||||
// correctly
|
// correctly
|
||||||
if err := app.Start(ctx); err != nil {
|
if err := app.Start(ctx); err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return resAPI, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// In-memory / testing
|
// In-memory / testing
|
||||||
|
@ -24,7 +24,8 @@ func builder(t *testing.T, n int) []api.API {
|
|||||||
|
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
var err error
|
var err error
|
||||||
out[i], err = node.New(ctx,
|
err = node.New(ctx,
|
||||||
|
node.FullAPI(&out[i]),
|
||||||
node.Online(),
|
node.Online(),
|
||||||
node.Repo(repo.NewMemory(nil)),
|
node.Repo(repo.NewMemory(nil)),
|
||||||
MockHost(mn),
|
MockHost(mn),
|
||||||
|
Loading…
Reference in New Issue
Block a user