Skip to content

Commit

Permalink
adding an GetEnabledSubsystems API to storage miner
Browse files Browse the repository at this point in the history
  • Loading branch information
nonsense committed Jul 28, 2021
1 parent 11d3f19 commit 7c6eb4f
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 5 deletions.
2 changes: 2 additions & 0 deletions api/api_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 61 additions & 0 deletions api/api_subsystems.go
Original file line number Diff line number Diff line change
@@ -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
}
11 changes: 6 additions & 5 deletions api/docgen/docgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}) {
Expand Down
13 changes: 13 additions & 0 deletions api/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified build/openrpc/full.json.gz
Binary file not shown.
Binary file modified build/openrpc/miner.json.gz
Binary file not shown.
Binary file modified build/openrpc/worker.json.gz
Binary file not shown.
14 changes: 14 additions & 0 deletions documentation/en/api-v0-methods-miner.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
* [DealsSetConsiderUnverifiedStorageDeals](#DealsSetConsiderUnverifiedStorageDeals)
* [DealsSetConsiderVerifiedStorageDeals](#DealsSetConsiderVerifiedStorageDeals)
* [DealsSetPieceCidBlocklist](#DealsSetPieceCidBlocklist)
* [Get](#Get)
* [GetEnabledSubsystems](#GetEnabledSubsystems)
* [I](#I)
* [ID](#ID)
* [Log](#Log)
Expand Down Expand Up @@ -533,6 +535,18 @@ Inputs:

Response: `{}`

## Get


### GetEnabledSubsystems


Perms: read

Inputs: `null`

Response: `null`

## I


Expand Down
2 changes: 2 additions & 0 deletions node/builder_miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions node/impl/storminer.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import (
type StorageMinerAPI struct {
fx.In

Subsystems *api.MinerSubsystem `optional:"true"`

api.Common
api.Net

Expand Down Expand Up @@ -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{}
19 changes: 19 additions & 0 deletions node/modules/storageminer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 7c6eb4f

Please sign in to comment.