2020-03-03 22:19:22 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"golang.org/x/xerrors"
|
2020-05-27 20:53:20 +00:00
|
|
|
|
2022-06-14 18:25:52 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/paths"
|
2022-06-14 18:03:38 +00:00
|
|
|
"github.com/filecoin-project/lotus/storage/sealer"
|
2020-03-03 22:19:22 +00:00
|
|
|
)
|
|
|
|
|
2022-06-14 18:25:52 +00:00
|
|
|
func StorageFromFile(path string, def *paths.StorageConfig) (*paths.StorageConfig, error) {
|
2020-03-03 22:19:22 +00:00
|
|
|
file, err := os.Open(path)
|
|
|
|
switch {
|
|
|
|
case os.IsNotExist(err):
|
|
|
|
if def == nil {
|
|
|
|
return nil, xerrors.Errorf("couldn't load storage config: %w", err)
|
|
|
|
}
|
|
|
|
return def, nil
|
|
|
|
case err != nil:
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
defer file.Close() //nolint:errcheck // The file is RO
|
2020-03-04 02:24:08 +00:00
|
|
|
return StorageFromReader(file)
|
2020-03-03 22:19:22 +00:00
|
|
|
}
|
|
|
|
|
2022-06-14 18:25:52 +00:00
|
|
|
func StorageFromReader(reader io.Reader) (*paths.StorageConfig, error) {
|
|
|
|
var cfg paths.StorageConfig
|
2020-03-03 22:19:22 +00:00
|
|
|
err := json.NewDecoder(reader).Decode(&cfg)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &cfg, nil
|
|
|
|
}
|
|
|
|
|
2022-06-14 18:25:52 +00:00
|
|
|
func WriteStorageFile(path string, config paths.StorageConfig) error {
|
2020-03-04 02:24:08 +00:00
|
|
|
b, err := json.MarshalIndent(config, "", " ")
|
2020-03-03 22:19:22 +00:00
|
|
|
if err != nil {
|
|
|
|
return xerrors.Errorf("marshaling storage config: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := ioutil.WriteFile(path, b, 0644); err != nil {
|
|
|
|
return xerrors.Errorf("persisting storage config (%s): %w", path, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2022-03-29 01:19:11 +00:00
|
|
|
|
2022-06-14 18:03:38 +00:00
|
|
|
func (c *StorageMiner) StorageManager() sealer.Config {
|
|
|
|
return sealer.Config{
|
2022-03-29 01:19:11 +00:00
|
|
|
ParallelFetchLimit: c.Storage.ParallelFetchLimit,
|
|
|
|
AllowAddPiece: c.Storage.AllowAddPiece,
|
|
|
|
AllowPreCommit1: c.Storage.AllowPreCommit1,
|
|
|
|
AllowPreCommit2: c.Storage.AllowPreCommit2,
|
|
|
|
AllowCommit: c.Storage.AllowCommit,
|
|
|
|
AllowUnseal: c.Storage.AllowUnseal,
|
|
|
|
AllowReplicaUpdate: c.Storage.AllowReplicaUpdate,
|
|
|
|
AllowProveReplicaUpdate2: c.Storage.AllowProveReplicaUpdate2,
|
|
|
|
AllowRegenSectorKey: c.Storage.AllowRegenSectorKey,
|
|
|
|
ResourceFiltering: c.Storage.ResourceFiltering,
|
2022-05-23 21:53:25 +00:00
|
|
|
DisallowRemoteFinalize: c.Storage.DisallowRemoteFinalize,
|
2022-03-29 01:19:11 +00:00
|
|
|
|
2022-05-23 15:38:13 +00:00
|
|
|
Assigner: c.Storage.Assigner,
|
|
|
|
|
2022-07-01 19:24:54 +00:00
|
|
|
ParallelCheckLimit: c.Proving.ParallelCheckLimit,
|
|
|
|
DisableBuiltinWindowPoSt: c.Proving.DisableBuiltinWindowPoSt,
|
|
|
|
DisableBuiltinWinningPoSt: c.Proving.DisableBuiltinWinningPoSt,
|
2022-03-29 01:19:11 +00:00
|
|
|
}
|
|
|
|
}
|