Skip to content

Commit 970e3aa

Browse files
committed
go/consensus: Show a list of available checkpoints
1 parent 92292a2 commit 970e3aa

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

.changelog/5265.feature.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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. Unless node has no local
5+
checkpoints, this field displays a list of local 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 { // nolint: maligned
375375

376376
// P2P is the P2P status of the node.
377377
P2P *P2PStatus `json:"p2p,omitempty"`
378+
379+
// CheckpointStatus 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: 27 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,37 @@ func (n *commonNode) GetStatus(ctx context.Context) (*consensusAPI.Status, error
840841
// Failed to load validator set.
841842
status.IsValidator = false
842843
}
844+
845+
if status.Checkpoint, err = n.fetchCheckpointStatus(ctx); err != nil {
846+
return nil, fmt.Errorf("failed to fetch checkpoints: %w", err)
847+
}
843848
}
844849

845850
return status, nil
846851
}
847852

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

850877
// Implements consensusAPI.Backend.

0 commit comments

Comments
 (0)