Fix double locking

License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
Jakub Sztandera 2019-10-30 23:33:31 +01:00
parent 3ea0997c93
commit 407183b258
No known key found for this signature in database
GPG Key ID: 9A9AF56F8B3879BA

View File

@ -294,52 +294,40 @@ func ConfigFullNode(cfg *config.FullNode) Option {
)
}
func repoFull(r repo.Repo) Option {
lr, err := r.Lock(repo.RepoFullNode)
if err != nil {
return Error(err)
}
c, err := lr.Config()
if err != nil {
return Error(err)
}
func configFull(c interface{}) Option {
cfg, ok := c.(*config.FullNode)
if !ok {
return Error(xerrors.Errorf("invalid config from repo, got: %T", c))
}
return Options(
ConfigFullNode(cfg),
Override(new(repo.LockedRepo), modules.LockedRepo(lr)), // module handles closing
)
}
func repoMiner(r repo.Repo) Option {
lr, err := r.Lock(repo.RepoStorageMiner)
if err != nil {
return Error(err)
}
c, err := lr.Config()
if err != nil {
return Error(err)
return ConfigFullNode(cfg)
}
func configMiner(c interface{}) Option {
cfg, ok := c.(*config.StorageMiner)
if !ok {
return Error(xerrors.Errorf("invalid config from repo, got: %T", c))
}
return Options(
ConfigCommon(&cfg.Common),
Override(new(repo.LockedRepo), modules.LockedRepo(lr)), // module handles closing
)
return ConfigCommon(&cfg.Common)
}
func Repo(r repo.Repo) Option {
return func(settings *Settings) error {
lr, err := r.Lock(settings.nodeType)
if err != nil {
return err
}
c, err := lr.Config()
if err != nil {
return err
}
return Options(
ApplyIf(isType(repo.RepoFullNode), repoFull(r)),
ApplyIf(isType(repo.RepoStorageMiner), repoMiner(r)),
Override(new(repo.LockedRepo), modules.LockedRepo(lr)), // module handles closing
ApplyIf(isType(repo.RepoFullNode), configFull(c)),
ApplyIf(isType(repo.RepoStorageMiner), configMiner(c)),
Override(new(dtypes.MetadataDS), modules.Datastore),
Override(new(dtypes.ChainBlockstore), modules.ChainBlockstore),
@ -355,7 +343,8 @@ func Repo(r repo.Repo) Option {
Override(new(types.KeyStore), modules.KeyStore),
Override(new(*dtypes.APIAlg), modules.APISecret),
)
)(settings)
}
}
func FullAPI(out *api.FullNode) Option {