Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changelog/5265.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go/oasis-node: Display consensus checkpoint heights

A new field `heights` has been added to the `oasis-node control status` output
under the `consensus.checkpoint` status section. If checkpointer is not
disabled and there is at least one checkpoint, this field displays a list
of local checkpoint heights.
11 changes: 11 additions & 0 deletions go/consensus/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,9 @@ type Status struct {

// P2P is the P2P status of the node.
P2P *P2PStatus `json:"p2p,omitempty"`

// Checkpoint is the checkpoints status of the node.
Checkpoint *CheckpointStatus `json:"checkpoint,omitempty"`
}

// P2PStatus is the P2P status of a node.
Expand All @@ -392,6 +395,14 @@ type P2PStatus struct {
Peers []string `json:"peers"`
}

// CheckpointStatus is the checkpoints status of the node.
type CheckpointStatus struct {
// Heights is a list of consensus heights for which the node has checkpoints locally.
//
// Heights are sorted in descending order.
Heights []uint64 `json:"heights"`
}

// Service is an interface that a consensus backend service must provide.
type Service interface {
service.BackgroundService
Expand Down
37 changes: 33 additions & 4 deletions go/consensus/cometbft/full/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package full
import (
"context"
"fmt"
"slices"
"sync"
"sync/atomic"

Expand Down Expand Up @@ -831,19 +832,47 @@ func (n *commonNode) GetStatus(ctx context.Context) (*consensusAPI.Status, error
valSetHeight = status.GenesisHeight
}
vals, err := n.stateStore.LoadValidators(valSetHeight)
if err != nil {
// Failed to load validator set.
status.IsValidator = false
} else {
switch err {
case nil:
consensusPk := n.identity.ConsensusSigner.Public()
consensusAddr := []byte(crypto.PublicKeyToCometBFT(&consensusPk).Address())
status.IsValidator = vals.HasAddress(consensusAddr)
default:
// Failed to load validator set.
status.IsValidator = false
}

if n.Checkpointer() != nil {
status.Checkpoint = n.fetchCheckpointStatus(ctx)
}
}

return status, nil
}

// fetchCheckpointStatus fetches checkpoint status.
//
// In case of zero checkpoints or error a nil status is returned.
func (n *commonNode) fetchCheckpointStatus(ctx context.Context) *consensusAPI.CheckpointStatus {
cps, err := n.mux.State().Storage().GetCheckpoints(ctx, &checkpoint.GetCheckpointsRequest{
Version: 1,
})
if err != nil {
n.Logger.Error("failed to fetch checkpoints status", "err", err)
return nil
}
var heights []uint64
for _, cp := range cps {
heights = append(heights, cp.Root.Version)
}
if len(heights) <= 0 {
return nil
}
slices.Sort(heights)
slices.Reverse(heights)
return &consensusAPI.CheckpointStatus{Heights: heights}
}

// Unimplemented methods.

// Implements consensusAPI.Backend.
Expand Down
Loading