diff --git a/core/node/builder.go b/core/node/builder.go index 029ebd37d..5228310f2 100644 --- a/core/node/builder.go +++ b/core/node/builder.go @@ -84,10 +84,10 @@ func (cfg *BuildCfg) fillDefaults() error { } // options creates fx option group from this build config -func (cfg *BuildCfg) options(ctx context.Context) fx.Option { +func (cfg *BuildCfg) options(ctx context.Context) (fx.Option, *cfg.Config) { err := cfg.fillDefaults() if err != nil { - return fx.Error(err) + return fx.Error(err), nil } repoOption := fx.Provide(func(lc fx.Lifecycle) repo.Repo { @@ -112,12 +112,17 @@ func (cfg *BuildCfg) options(ctx context.Context) fx.Option { return cfg.Routing }) + conf, err := cfg.Repo.Config() + if err != nil { + return fx.Error(err), nil + } + return fx.Options( repoOption, hostOption, routingOption, metricsCtx, - ) + ), conf } func defaultRepo(dstore repo.Datastore) (repo.Repo, error) { diff --git a/core/node/groups.go b/core/node/groups.go index 1a69f03de..56f2f3538 100644 --- a/core/node/groups.go +++ b/core/node/groups.go @@ -9,6 +9,7 @@ import ( offline "github.com/ipfs/go-ipfs-exchange-offline" offroute "github.com/ipfs/go-ipfs-routing/offline" + uio "github.com/ipfs/go-unixfs/io" "github.com/ipfs/go-path/resolver" "go.uber.org/fx" ) @@ -122,21 +123,33 @@ func Networked(cfg *BuildCfg) fx.Option { } // IPFS builds a group of fx Options based on the passed BuildCfg -func IPFS(ctx context.Context, cfg *BuildCfg) fx.Option { - if cfg == nil { - cfg = new(BuildCfg) +func IPFS(ctx context.Context, bcfg *BuildCfg) fx.Option { + if bcfg == nil { + bcfg = new(BuildCfg) } + bcfgOpts, cfg := bcfg.options(ctx) + if cfg == nil { + return bcfgOpts // error + } + + // TEMP: setting global sharding switch here + uio.UseHAMTSharding = cfg.Experimental.ShardingEnabled + + + + + + return fx.Options( - cfg.options(ctx), + bcfgOpts, fx.Provide(baseProcess), - fx.Invoke(setupSharding), - Storage(cfg), + Storage(bcfg), Identity, IPNS, - Networked(cfg), + Networked(bcfg), Core, ) diff --git a/core/node/helpers.go b/core/node/helpers.go index 17954b63a..2c91ff5f9 100644 --- a/core/node/helpers.go +++ b/core/node/helpers.go @@ -3,8 +3,6 @@ package node import ( "context" - config "github.com/ipfs/go-ipfs-config" - uio "github.com/ipfs/go-unixfs/io" "github.com/jbenet/goprocess" "github.com/pkg/errors" "go.uber.org/fx" @@ -45,11 +43,6 @@ func maybeProvide(opt interface{}, enable bool) fx.Option { return fx.Options() } -func setupSharding(cfg *config.Config) { - // TEMP: setting global sharding switch here - uio.UseHAMTSharding = cfg.Experimental.ShardingEnabled -} - // baseProcess creates a goprocess which is closed when the lifecycle signals it to stop func baseProcess(lc fx.Lifecycle) goprocess.Process { p := goprocess.WithParent(goprocess.Background())