diff --git a/api/api_storage.go b/api/api_storage.go index 154abcea713..3d33f38f43b 100644 --- a/api/api_storage.go +++ b/api/api_storage.go @@ -166,6 +166,8 @@ type StorageMiner interface { MarketPendingDeals(ctx context.Context) (PendingDealInfo, error) //perm:write MarketPublishPendingDeals(ctx context.Context) error //perm:admin + GetEnabledSubsystems(ctx context.Context) ([]MinerSubsystem, error) //perm:read + DealsImportData(ctx context.Context, dealPropCid cid.Cid, file string) error //perm:admin DealsList(ctx context.Context) ([]MarketDeal, error) //perm:admin DealsConsiderOnlineStorageDeals(context.Context) (bool, error) //perm:admin diff --git a/api/api_subsystems.go b/api/api_subsystems.go new file mode 100644 index 00000000000..0eb0b67a174 --- /dev/null +++ b/api/api_subsystems.go @@ -0,0 +1,61 @@ +package api + +import ( + "bytes" + "encoding/json" +) + +type MinerSubsystem int + +const ( + MarketsSubsystem MinerSubsystem = 1 << iota + MiningSubsystem + SealingSubsystem + SectorStorageSubsystem + + MinerSubsystems = iota +) + +func (ms MinerSubsystem) Add(single MinerSubsystem) MinerSubsystem { + return ms | single +} + +func (ms MinerSubsystem) Has(single MinerSubsystem) bool { + return ms&single == single +} + +func (ms MinerSubsystem) String() string { + return MinerSubsystemToString[ms] +} + +var MinerSubsystemToString = map[MinerSubsystem]string{ + MarketsSubsystem: "Markets", + MiningSubsystem: "Mining", + SealingSubsystem: "Sealing", + SectorStorageSubsystem: "SectorStorage", +} + +var MinerSubsystemToID = map[string]MinerSubsystem{ + "Markets": MarketsSubsystem, + "Mining": MiningSubsystem, + "Sealing": SealingSubsystem, + "SectorStorage": SectorStorageSubsystem, +} + +func (ms MinerSubsystem) MarshalJSON() ([]byte, error) { + buffer := bytes.NewBufferString(`"`) + buffer.WriteString(MinerSubsystemToString[ms]) + buffer.WriteString(`"`) + return buffer.Bytes(), nil +} + +func (ms *MinerSubsystem) UnmarshalJSON(b []byte) error { + var j string + err := json.Unmarshal(b, &j) + if err != nil { + return err + } + // TODO: handle zero value + *ms = MinerSubsystemToID[j] + return nil +} diff --git a/api/docgen/docgen.go b/api/docgen/docgen.go index 39980023f0a..1e712a0aeab 100644 --- a/api/docgen/docgen.go +++ b/api/docgen/docgen.go @@ -46,11 +46,12 @@ import ( ) var ExampleValues = map[reflect.Type]interface{}{ - reflect.TypeOf(auth.Permission("")): auth.Permission("write"), - reflect.TypeOf(""): "string value", - reflect.TypeOf(uint64(42)): uint64(42), - reflect.TypeOf(byte(7)): byte(7), - reflect.TypeOf([]byte{}): []byte("byte array"), + reflect.TypeOf(api.MinerSubsystem(0)): api.MinerSubsystem(1), + reflect.TypeOf(auth.Permission("")): auth.Permission("write"), + reflect.TypeOf(""): "string value", + reflect.TypeOf(uint64(42)): uint64(42), + reflect.TypeOf(byte(7)): byte(7), + reflect.TypeOf([]byte{}): []byte("byte array"), } func addExample(v interface{}) { diff --git a/api/proxy_gen.go b/api/proxy_gen.go index 7d96425ffab..4c9f936d757 100644 --- a/api/proxy_gen.go +++ b/api/proxy_gen.go @@ -635,6 +635,8 @@ type StorageMinerStruct struct { DealsSetPieceCidBlocklist func(p0 context.Context, p1 []cid.Cid) error `perm:"admin"` + GetEnabledSubsystems func(p0 context.Context) ([]MinerSubsystem, error) `perm:"read"` + MarketCancelDataTransfer func(p0 context.Context, p1 datatransfer.TransferID, p2 peer.ID, p3 bool) error `perm:"write"` MarketDataTransferUpdates func(p0 context.Context) (<-chan DataTransferChannel, error) `perm:"write"` @@ -3743,6 +3745,17 @@ func (s *StorageMinerStub) DealsSetPieceCidBlocklist(p0 context.Context, p1 []ci return ErrNotSupported } +func (s *StorageMinerStruct) GetEnabledSubsystems(p0 context.Context) ([]MinerSubsystem, error) { + if s.Internal.GetEnabledSubsystems == nil { + return *new([]MinerSubsystem), ErrNotSupported + } + return s.Internal.GetEnabledSubsystems(p0) +} + +func (s *StorageMinerStub) GetEnabledSubsystems(p0 context.Context) ([]MinerSubsystem, error) { + return *new([]MinerSubsystem), ErrNotSupported +} + func (s *StorageMinerStruct) MarketCancelDataTransfer(p0 context.Context, p1 datatransfer.TransferID, p2 peer.ID, p3 bool) error { if s.Internal.MarketCancelDataTransfer == nil { return ErrNotSupported diff --git a/build/openrpc/full.json.gz b/build/openrpc/full.json.gz index c940d921b0a..6a9d9cb6838 100644 Binary files a/build/openrpc/full.json.gz and b/build/openrpc/full.json.gz differ diff --git a/build/openrpc/miner.json.gz b/build/openrpc/miner.json.gz index 41e51a13ec0..d767235bdf4 100644 Binary files a/build/openrpc/miner.json.gz and b/build/openrpc/miner.json.gz differ diff --git a/build/openrpc/worker.json.gz b/build/openrpc/worker.json.gz index 075b54c3277..2bc7dba2d17 100644 Binary files a/build/openrpc/worker.json.gz and b/build/openrpc/worker.json.gz differ diff --git a/documentation/en/api-v0-methods-miner.md b/documentation/en/api-v0-methods-miner.md index e8598ff0ceb..a6f19b5ccfe 100644 --- a/documentation/en/api-v0-methods-miner.md +++ b/documentation/en/api-v0-methods-miner.md @@ -35,6 +35,8 @@ * [DealsSetConsiderUnverifiedStorageDeals](#DealsSetConsiderUnverifiedStorageDeals) * [DealsSetConsiderVerifiedStorageDeals](#DealsSetConsiderVerifiedStorageDeals) * [DealsSetPieceCidBlocklist](#DealsSetPieceCidBlocklist) +* [Get](#Get) + * [GetEnabledSubsystems](#GetEnabledSubsystems) * [I](#I) * [ID](#ID) * [Log](#Log) @@ -533,6 +535,18 @@ Inputs: Response: `{}` +## Get + + +### GetEnabledSubsystems + + +Perms: read + +Inputs: `null` + +Response: `null` + ## I diff --git a/node/builder_miner.go b/node/builder_miner.go index 0c0f9d15af9..444e82d733e 100644 --- a/node/builder_miner.go +++ b/node/builder_miner.go @@ -72,6 +72,7 @@ func ConfigStorageMiner(c interface{}) Option { return Options( ConfigCommon(&cfg.Common, enableLibp2pNode), + Override(new(*api.MinerSubsystem), modules.AddMinerSubsystems(cfg.Subsystems)), Override(new(stores.LocalStorage), From(new(repo.LockedRepo))), Override(new(*stores.Local), modules.LocalStorage), Override(new(*stores.Remote), modules.RemoteStorage), @@ -215,6 +216,7 @@ func StorageMiner(out *api.StorageMiner, subsystemsCfg config.MinerSubsystemConf func(s *Settings) error { resAPI := &impl.StorageMinerAPI{} + s.invokes[ExtractApiKey] = fx.Populate(resAPI) *out = resAPI return nil diff --git a/node/impl/storminer.go b/node/impl/storminer.go index 9db6a3775ce..f820f9b2224 100644 --- a/node/impl/storminer.go +++ b/node/impl/storminer.go @@ -48,6 +48,8 @@ import ( type StorageMinerAPI struct { fx.In + Subsystems *api.MinerSubsystem `optional:"true"` + api.Common api.Net @@ -703,4 +705,15 @@ func (sm *StorageMinerAPI) ComputeProof(ctx context.Context, ssi []builtin.Secto return sm.Epp.ComputeProof(ctx, ssi, rand) } +func (sm *StorageMinerAPI) GetEnabledSubsystems(context.Context) (res []api.MinerSubsystem, err error) { + index := 1 + for i := 0; i < api.MinerSubsystems; i++ { + if sm.Subsystems.Has(api.MinerSubsystem(index)) { + res = append(res, api.MinerSubsystem(index)) + } + index *= 2 + } + return +} + var _ api.StorageMiner = &StorageMinerAPI{} diff --git a/node/modules/storageminer.go b/node/modules/storageminer.go index 3a3914e0c85..fef01ba797d 100644 --- a/node/modules/storageminer.go +++ b/node/modules/storageminer.go @@ -1007,3 +1007,22 @@ func mutateCfg(r repo.LockedRepo, mutator func(*config.StorageMiner)) error { return multierr.Combine(typeErr, setConfigErr) } + +func AddMinerSubsystems(cfg config.MinerSubsystemConfig) *api.MinerSubsystem { + var res api.MinerSubsystem + + if cfg.EnableMining { + res = res.Add(api.MiningSubsystem) + } + if cfg.EnableSealing { + res = res.Add(api.SealingSubsystem) + } + if cfg.EnableSectorStorage { + res = res.Add(api.SectorStorageSubsystem) + } + if cfg.EnableMarkets { + res = res.Add(api.MarketsSubsystem) + } + + return &res +}