Skip to content

Commit e4e7863

Browse files
committed
go/consensus: Show a list of available checkpoints
1 parent 2c46523 commit e4e7863

3 files changed

Lines changed: 45 additions & 0 deletions

File tree

.changelog/5265.feature.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
go/oasis-node: Display consensus checkpoint heights
2+
3+
A new field `heights` has been added to the `oasis-node control status` output
4+
under the `consensus.checkpoint` status section. If checkpointer is not disabled
5+
and there is at least one checkpoint, this field displays a list of local
6+
checkpoint heights.

go/consensus/api/api.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,9 @@ type Status struct {
375375

376376
// P2P is the P2P status of the node.
377377
P2P *P2PStatus `json:"p2p,omitempty"`
378+
379+
// Checkpoint is the checkpoints status of the node.
380+
Checkpoint *CheckpointStatus `json:"checkpoint,omitempty"`
378381
}
379382

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

398+
// CheckpointStatus is the checkpoints status of the node.
399+
type CheckpointStatus struct {
400+
// Heights is a list of consensus heights for which the node has checkpoints locally.
401+
//
402+
// Heights are sorted in descending order.
403+
Heights []uint64 `json:"heights"`
404+
}
405+
395406
// Service is an interface that a consensus backend service must provide.
396407
type Service interface {
397408
service.BackgroundService

go/consensus/cometbft/full/common.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package full
33
import (
44
"context"
55
"fmt"
6+
"slices"
67
"sync"
78
"sync/atomic"
89

@@ -840,11 +841,38 @@ func (n *commonNode) GetStatus(ctx context.Context) (*consensusAPI.Status, error
840841
// Failed to load validator set.
841842
status.IsValidator = false
842843
}
844+
845+
if n.Checkpointer() != nil {
846+
status.Checkpoint = n.fetchCheckpointStatus(ctx)
847+
}
843848
}
844849

845850
return status, nil
846851
}
847852

853+
// fetchCheckpointStatus fetches checkpoint status.
854+
//
855+
// In case of zero checkpoints or error a nil status is returned.
856+
func (n *commonNode) fetchCheckpointStatus(ctx context.Context) *consensusAPI.CheckpointStatus {
857+
cps, err := n.mux.State().Storage().GetCheckpoints(ctx, &checkpoint.GetCheckpointsRequest{
858+
Version: 1,
859+
})
860+
if err != nil {
861+
n.Logger.Error("failed to fetch checkpoints status", "err", err)
862+
return nil
863+
}
864+
var heights []uint64
865+
for _, cp := range cps {
866+
heights = append(heights, cp.Root.Version)
867+
}
868+
if len(heights) <= 0 {
869+
return nil
870+
}
871+
slices.Sort(heights)
872+
slices.Reverse(heights)
873+
return &consensusAPI.CheckpointStatus{Heights: heights}
874+
}
875+
848876
// Unimplemented methods.
849877

850878
// Implements consensusAPI.Backend.

0 commit comments

Comments
 (0)