Merge remote-tracking branch 'origin/master' into feat/post-worker
This commit is contained in:
+167
-40
@@ -41,47 +41,174 @@ const (
|
||||
fsKeystore = "keystore"
|
||||
)
|
||||
|
||||
type RepoType int
|
||||
|
||||
const (
|
||||
_ = iota // Default is invalid
|
||||
FullNode RepoType = iota
|
||||
StorageMiner
|
||||
Worker
|
||||
Wallet
|
||||
Markets
|
||||
)
|
||||
|
||||
func (t RepoType) String() string {
|
||||
s := [...]string{
|
||||
"__invalid__",
|
||||
"FullNode",
|
||||
"StorageMiner",
|
||||
"Worker",
|
||||
"Wallet",
|
||||
"Markets",
|
||||
func NewRepoTypeFromString(t string) RepoType {
|
||||
switch t {
|
||||
case "FullNode":
|
||||
return FullNode
|
||||
case "StorageMiner":
|
||||
return StorageMiner
|
||||
case "Worker":
|
||||
return Worker
|
||||
case "Wallet":
|
||||
return Wallet
|
||||
default:
|
||||
panic("unknown RepoType")
|
||||
}
|
||||
if t < 0 || int(t) > len(s) {
|
||||
return "__invalid__"
|
||||
}
|
||||
return s[t]
|
||||
}
|
||||
|
||||
func defConfForType(t RepoType) interface{} {
|
||||
switch t {
|
||||
case FullNode:
|
||||
return config.DefaultFullNode()
|
||||
case StorageMiner, Markets:
|
||||
// markets is a specialised miner service
|
||||
// this taxonomy needs to be cleaned up
|
||||
return config.DefaultStorageMiner()
|
||||
case Worker:
|
||||
return &struct{}{}
|
||||
case Wallet:
|
||||
return &struct{}{}
|
||||
default:
|
||||
panic(fmt.Sprintf("unknown RepoType(%d)", int(t)))
|
||||
}
|
||||
type RepoType interface {
|
||||
Type() string
|
||||
Config() interface{}
|
||||
|
||||
// APIFlags returns flags passed on the command line with the listen address
|
||||
// of the API server (only used by the tests), in the order of precedence they
|
||||
// should be applied for the requested kind of node.
|
||||
APIFlags() []string
|
||||
|
||||
RepoFlags() []string
|
||||
|
||||
// APIInfoEnvVars returns the environment variables to use in order of precedence
|
||||
// to determine the API endpoint of the specified node type.
|
||||
//
|
||||
// It returns the current variables and deprecated ones separately, so that
|
||||
// the user can log a warning when deprecated ones are found to be in use.
|
||||
APIInfoEnvVars() (string, []string, []string)
|
||||
}
|
||||
|
||||
// SupportsStagingDeals is a trait for services that support staging deals
|
||||
type SupportsStagingDeals interface {
|
||||
SupportsStagingDeals()
|
||||
}
|
||||
|
||||
var FullNode fullNode
|
||||
|
||||
type fullNode struct {
|
||||
}
|
||||
|
||||
func (fullNode) Type() string {
|
||||
return "FullNode"
|
||||
}
|
||||
|
||||
func (fullNode) Config() interface{} {
|
||||
return config.DefaultFullNode()
|
||||
}
|
||||
|
||||
func (fullNode) APIFlags() []string {
|
||||
return []string{"api-url"}
|
||||
}
|
||||
|
||||
func (fullNode) RepoFlags() []string {
|
||||
return []string{"repo"}
|
||||
}
|
||||
|
||||
func (fullNode) APIInfoEnvVars() (primary string, fallbacks []string, deprecated []string) {
|
||||
return "FULLNODE_API_INFO", nil, nil
|
||||
}
|
||||
|
||||
var StorageMiner storageMiner
|
||||
|
||||
type storageMiner struct{}
|
||||
|
||||
func (storageMiner) SupportsStagingDeals() {}
|
||||
|
||||
func (storageMiner) Type() string {
|
||||
return "StorageMiner"
|
||||
}
|
||||
|
||||
func (storageMiner) Config() interface{} {
|
||||
return config.DefaultStorageMiner()
|
||||
}
|
||||
|
||||
func (storageMiner) APIFlags() []string {
|
||||
return []string{"miner-api-url"}
|
||||
}
|
||||
|
||||
func (storageMiner) RepoFlags() []string {
|
||||
return []string{"miner-repo"}
|
||||
}
|
||||
|
||||
func (storageMiner) APIInfoEnvVars() (primary string, fallbacks []string, deprecated []string) {
|
||||
// TODO remove deprecated deprecation period
|
||||
return "MINER_API_INFO", nil, []string{"STORAGE_API_INFO"}
|
||||
}
|
||||
|
||||
var Markets markets
|
||||
|
||||
type markets struct{}
|
||||
|
||||
func (markets) SupportsStagingDeals() {}
|
||||
|
||||
func (markets) Type() string {
|
||||
return "Markets"
|
||||
}
|
||||
|
||||
func (markets) Config() interface{} {
|
||||
return config.DefaultStorageMiner()
|
||||
}
|
||||
|
||||
func (markets) APIFlags() []string {
|
||||
// support split markets-miner and monolith deployments.
|
||||
return []string{"markets-api-url", "miner-api-url"}
|
||||
}
|
||||
|
||||
func (markets) RepoFlags() []string {
|
||||
// support split markets-miner and monolith deployments.
|
||||
return []string{"markets-repo", "miner-repo"}
|
||||
}
|
||||
|
||||
func (markets) APIInfoEnvVars() (primary string, fallbacks []string, deprecated []string) {
|
||||
// support split markets-miner and monolith deployments.
|
||||
return "MARKETS_API_INFO", []string{"MINER_API_INFO"}, nil
|
||||
}
|
||||
|
||||
type worker struct {
|
||||
}
|
||||
|
||||
var Worker worker
|
||||
|
||||
func (worker) Type() string {
|
||||
return "Worker"
|
||||
}
|
||||
|
||||
func (worker) Config() interface{} {
|
||||
return &struct{}{}
|
||||
}
|
||||
|
||||
func (worker) APIFlags() []string {
|
||||
return []string{"worker-api-url"}
|
||||
}
|
||||
|
||||
func (worker) RepoFlags() []string {
|
||||
return []string{"worker-repo"}
|
||||
}
|
||||
|
||||
func (worker) APIInfoEnvVars() (primary string, fallbacks []string, deprecated []string) {
|
||||
return "WORKER_API_INFO", nil, nil
|
||||
}
|
||||
|
||||
var Wallet wallet
|
||||
|
||||
type wallet struct {
|
||||
}
|
||||
|
||||
func (wallet) Type() string {
|
||||
return "Wallet"
|
||||
}
|
||||
|
||||
func (wallet) Config() interface{} {
|
||||
return &struct{}{}
|
||||
}
|
||||
|
||||
func (wallet) APIFlags() []string {
|
||||
panic("not supported")
|
||||
}
|
||||
|
||||
func (wallet) RepoFlags() []string {
|
||||
panic("not supported")
|
||||
}
|
||||
|
||||
func (wallet) APIInfoEnvVars() (primary string, fallbacks []string, deprecated []string) {
|
||||
panic("not supported")
|
||||
}
|
||||
|
||||
var log = logging.Logger("repo")
|
||||
@@ -165,7 +292,7 @@ func (fsr *FsRepo) initConfig(t RepoType) error {
|
||||
return err
|
||||
}
|
||||
|
||||
comm, err := config.ConfigComment(defConfForType(t))
|
||||
comm, err := config.ConfigComment(t.Config())
|
||||
if err != nil {
|
||||
return xerrors.Errorf("comment: %w", err)
|
||||
}
|
||||
@@ -406,7 +533,7 @@ func (fsr *fsLockedRepo) Config() (interface{}, error) {
|
||||
}
|
||||
|
||||
func (fsr *fsLockedRepo) loadConfigFromDisk() (interface{}, error) {
|
||||
return config.FromFile(fsr.configPath, defConfForType(fsr.repoType))
|
||||
return config.FromFile(fsr.configPath, fsr.repoType.Config())
|
||||
}
|
||||
|
||||
func (fsr *fsLockedRepo) SetConfig(c func(interface{})) error {
|
||||
|
||||
+3
-11
@@ -40,9 +40,6 @@ type MemRepo struct {
|
||||
sc *stores.StorageConfig
|
||||
tempDir string
|
||||
|
||||
// given a repo type, produce the default config
|
||||
configF func(t RepoType) interface{}
|
||||
|
||||
// holds the current config value
|
||||
config struct {
|
||||
sync.Mutex
|
||||
@@ -108,7 +105,7 @@ func (lmem *lockedMemRepo) Path() string {
|
||||
panic(err) // only used in tests, probably fine
|
||||
}
|
||||
|
||||
if lmem.t == StorageMiner {
|
||||
if _, ok := lmem.t.(SupportsStagingDeals); ok {
|
||||
// this is required due to the method makeDealStaging from cmd/lotus-storage-miner/init.go
|
||||
// deal-staging is the directory deal files are staged in before being sealed into sectors
|
||||
// for offline deal flow.
|
||||
@@ -152,7 +149,6 @@ var _ Repo = &MemRepo{}
|
||||
// MemRepoOptions contains options for memory repo
|
||||
type MemRepoOptions struct {
|
||||
Ds datastore.Datastore
|
||||
ConfigF func(RepoType) interface{}
|
||||
KeyStore map[string]types.KeyInfo
|
||||
}
|
||||
|
||||
@@ -163,9 +159,6 @@ func NewMemory(opts *MemRepoOptions) *MemRepo {
|
||||
if opts == nil {
|
||||
opts = &MemRepoOptions{}
|
||||
}
|
||||
if opts.ConfigF == nil {
|
||||
opts.ConfigF = defConfForType
|
||||
}
|
||||
if opts.Ds == nil {
|
||||
opts.Ds = dssync.MutexWrap(datastore.NewMapDatastore())
|
||||
}
|
||||
@@ -177,7 +170,6 @@ func NewMemory(opts *MemRepoOptions) *MemRepo {
|
||||
repoLock: make(chan struct{}, 1),
|
||||
blockstore: blockstore.WrapIDStore(blockstore.NewMemorySync()),
|
||||
datastore: opts.Ds,
|
||||
configF: opts.ConfigF,
|
||||
keystore: opts.KeyStore,
|
||||
}
|
||||
}
|
||||
@@ -296,7 +288,7 @@ func (lmem *lockedMemRepo) Config() (interface{}, error) {
|
||||
defer lmem.mem.config.Unlock()
|
||||
|
||||
if lmem.mem.config.val == nil {
|
||||
lmem.mem.config.val = lmem.mem.configF(lmem.t)
|
||||
lmem.mem.config.val = lmem.t.Config()
|
||||
}
|
||||
|
||||
return lmem.mem.config.val, nil
|
||||
@@ -311,7 +303,7 @@ func (lmem *lockedMemRepo) SetConfig(c func(interface{})) error {
|
||||
defer lmem.mem.config.Unlock()
|
||||
|
||||
if lmem.mem.config.val == nil {
|
||||
lmem.mem.config.val = lmem.mem.configF(lmem.t)
|
||||
lmem.mem.config.val = lmem.t.Config()
|
||||
}
|
||||
|
||||
c(lmem.mem.config.val)
|
||||
|
||||
Reference in New Issue
Block a user