Skip to content

Commit

Permalink
Merge pull request #5080 from oasisprotocol/peternose/feature/km-glob…
Browse files Browse the repository at this point in the history
…al-status

go/worker/keymanager: Show global key manager status in node status
  • Loading branch information
peternose authored Nov 30, 2022
2 parents d649c80 + 21f9af8 commit 8a08747
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
1 change: 1 addition & 0 deletions .changelog/5080.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go/worker/keymanager: Show global key manager status in node status
13 changes: 11 additions & 2 deletions go/worker/keymanager/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,17 @@ type RuntimeAccessList struct {
Peers []core.PeerID `json:"peers"`
}

// Status is the key manager worker status.
// Status is the key manager global and worker status.
type Status struct {
// GlobalStatus is the global key manager committee status.
GlobalStatus *api.Status `json:"global"`

// WorkerStatus is the key manager worker status.
WorkerStatus WorkerStatus `json:"worker"`
}

// WorkerStatus is the key manager worker status.
type WorkerStatus struct {
// Status is a concise status of the key manager worker.
Status StatusState `json:"status"`

Expand All @@ -100,7 +109,7 @@ type Status struct {
PrivatePeers []core.PeerID `json:"private_peers"`

// Policy is the key manager policy.
Policy *api.SignedPolicySGX `json:"signed_policy"`
Policy *api.SignedPolicySGX `json:"policy"`
// PolicyChecksum is the checksum of the key manager policy.
PolicyChecksum []byte `json:"policy_checksum"`
}
15 changes: 7 additions & 8 deletions go/worker/keymanager/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ func (w *Worker) GetStatus(ctx context.Context) (*api.Status, error) {
ss = api.StatusStateStarting
}

var rid *common.Namespace
if w.runtime != nil {
id := w.runtime.ID()
rid = &id
}

ps := make([]peer.ID, 0, len(w.privatePeers))
for p := range w.privatePeers {
ps = append(ps, p)
Expand All @@ -63,14 +57,19 @@ func (w *Worker) GetStatus(ctx context.Context) (*api.Status, error) {
al = append(al, ral)
}

return &api.Status{
gs := w.globalStatus
ws := api.WorkerStatus{
Status: ss,
MayGenerate: w.mayGenerate,
RuntimeID: rid,
ClientRuntimes: rts,
AccessList: al,
PrivatePeers: ps,
Policy: w.policy,
PolicyChecksum: w.policyChecksum,
}

return &api.Status{
GlobalStatus: gs,
WorkerStatus: ws,
}, nil
}
19 changes: 15 additions & 4 deletions go/worker/keymanager/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,12 @@ type Worker struct { // nolint: maligned
accessListByRuntime map[common.Namespace][]core.PeerID
privatePeers map[core.PeerID]struct{}

commonWorker *workerCommon.Worker
roleProvider registration.RoleProvider
enclaveStatus *api.SignedInitResponse
backend api.Backend
commonWorker *workerCommon.Worker
roleProvider registration.RoleProvider
backend api.Backend

globalStatus *api.Status
enclaveStatus *api.SignedInitResponse
policy *api.SignedPolicySGX
policyChecksum []byte

Expand Down Expand Up @@ -384,6 +385,13 @@ func extractMessageResponsePayload(raw []byte) ([]byte, error) {
return cbor.Marshal(msg.Response.Body.Success), nil
}

func (w *Worker) setStatus(status *api.Status) {
w.Lock()
defer w.Unlock()

w.globalStatus = status
}

func (w *Worker) addClientRuntimeWatcher(n common.Namespace, crw *clientRuntimeWatcher) {
w.Lock()
defer w.Unlock()
Expand Down Expand Up @@ -646,6 +654,9 @@ func (w *Worker) worker() { // nolint: gocyclo

w.logger.Info("received key manager status update")

// Cache the latest status.
w.setStatus(status)

// Check if this is the first update and we need to initialize the
// worker host.
hrt := w.GetHostedRuntime()
Expand Down

0 comments on commit 8a08747

Please sign in to comment.