Skip to content

Commit

Permalink
Merge pull request #3785 from oasisprotocol/ptrus/feature/node-status
Browse files Browse the repository at this point in the history
go/control/api: Add node status to registration status response
  • Loading branch information
ptrus authored Mar 16, 2021
2 parents 9e0190b + 9784de1 commit c669a30
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions .changelog/3783.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go/control/api: Add node status to registration status response
3 changes: 3 additions & 0 deletions go/control/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ type RegistrationStatus struct {
// Descriptor is the node descriptor that the node successfully registered with. In case the
// node did not successfully register yet, it will be nil.
Descriptor *node.Node `json:"descriptor,omitempty"`

// NodeStatus is the registry live status of the node.
NodeStatus *registry.NodeStatus `json:"node_status,omitempty"`
}

// RuntimeStatus is the per-runtime status overview.
Expand Down
14 changes: 12 additions & 2 deletions go/worker/registration/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,20 @@ func (w *Worker) registrationStopped() {
// GetRegistrationStatus returns the node's current registration status.
func (w *Worker) GetRegistrationStatus(ctx context.Context) (*control.RegistrationStatus, error) {
w.RLock()
defer w.RUnlock()

status := new(control.RegistrationStatus)
*status = w.status
w.RUnlock()

if status == nil || status.Descriptor == nil {
return status, nil
}

ns, err := w.registry.GetNodeStatus(ctx, &registry.IDQuery{ID: status.Descriptor.ID, Height: consensus.HeightLatest})
if err != nil {
return nil, err
}
status.NodeStatus = ns

return status, nil
}

Expand Down

0 comments on commit c669a30

Please sign in to comment.