diff --git a/cmd/lotus-storage-miner/run.go b/cmd/lotus-storage-miner/run.go index fb8cabfa3..76f1192d7 100644 --- a/cmd/lotus-storage-miner/run.go +++ b/cmd/lotus-storage-miner/run.go @@ -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)) } - minerapi, err := node.New(ctx, + err = node.New(ctx, node.StorageMiner(), node.Online(), node.Repo(r), @@ -66,7 +66,7 @@ var runCmd = &cli.Command{ log.Infof("Remote version %s", v) rpcServer := jsonrpc.NewServer() - rpcServer.Register("Filecoin", minerapi) + //rpcServer.Register("Filecoin", minerapi) http.Handle("/rpc/v0", rpcServer) return http.ListenAndServe("127.0.0.1:"+cctx.String("api"), http.DefaultServeMux) }, diff --git a/cmd/lotus/daemon.go b/cmd/lotus/daemon.go index 3ad9f4620..5fa7b0764 100644 --- a/cmd/lotus/daemon.go +++ b/cmd/lotus/daemon.go @@ -4,6 +4,8 @@ package main import ( "context" + + "github.com/filecoin-project/go-lotus/api" "github.com/multiformats/go-multiaddr" "gopkg.in/urfave/cli.v2" @@ -32,7 +34,10 @@ var DaemonCmd = &cli.Command{ return err } - api, err := node.New(ctx, + var api api.API + err = node.New(ctx, + node.FullAPI(&api), + node.Online(), node.Repo(r), diff --git a/node/builder.go b/node/builder.go index cbd15ca82..95e45b35a 100644 --- a/node/builder.go +++ b/node/builder.go @@ -71,6 +71,8 @@ const ( HandleIncomingMessagesKey // daemon + ExtractApiKey + SetApiEndpointKey _nInvokes // keep this last @@ -125,10 +127,6 @@ func defaults() []Option { return []Option{ Override(new(helpers.MetricsCtx), context.Background), 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 func Online() Option { return Options( - Override(HandleIncomingMessagesKey, modules.HandleIncomingMessages), // make sure that online is applied before Config. // This is important because Config overrides some of Online units func(s *Settings) error { s.Online = true; return nil }, @@ -178,6 +175,12 @@ func Online() Option { // Full node 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.GCBlockstore), blockstore.NewGCBlockstore), Override(new(exchange.Interface), modules.Bitswap), @@ -265,9 +268,17 @@ func Repo(r repo.Repo) Option { ) } +func FullAPI(out *api.API) Option { + return func(s *Settings) error { + 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) (api.API, error) { - resAPI := &API{} +func New(ctx context.Context, opts ...Option) error { settings := Settings{ modules: map[interface{}]fx.Option{}, 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 if err := Options(Options(defaults()...), Options(opts...))(&settings); err != nil { - return nil, err + return err } // gather constructors for fx.Options @@ -295,8 +306,6 @@ func New(ctx context.Context, opts ...Option) (api.API, error) { fx.Options(ctors...), fx.Options(settings.invokes...), - fx.Extract(resAPI), - 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 // correctly if err := app.Start(ctx); err != nil { - return nil, err + return err } - return resAPI, nil + return nil } // In-memory / testing diff --git a/node/node_test.go b/node/node_test.go index a6c6d4f1f..a02d588aa 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -24,7 +24,8 @@ func builder(t *testing.T, n int) []api.API { for i := 0; i < n; i++ { var err error - out[i], err = node.New(ctx, + err = node.New(ctx, + node.FullAPI(&out[i]), node.Online(), node.Repo(repo.NewMemory(nil)), MockHost(mn),