Skip to content

Commit 747cdd3

Browse files
committed
go/consensus: Show a list of available checkpoints
1 parent 4bbef74 commit 747cdd3

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

.changelog/5265.feature.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
go/oasis-node: Display checkpoints height and block header hash
2+
3+
A new field `checkpoints` has been added to the `oasis-node control status`
4+
output under the `consensus` status section. Unless empty, this field displays
5+
a list of local checkpoints with the following information:
6+
7+
1. The height for which checkpoint was created.
8+
2. The bock header hash of the given checkpoint.

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+
// Checkpoints is the list of node's local checkpoints.
380+
Checkpoints []*Checkpoint `json:"checkpoints,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+
// Checkpoint is the checkpoint's metadata.
399+
type Checkpoint struct {
400+
// Height is the height at which the checkpoint was created.
401+
Height uint64 `json:"height"`
402+
// BlockHash is the hash of the block header at the given height.
403+
BlockHash hash.Hash `json:"block_hash"`
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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,21 @@ func (n *commonNode) GetStatus(ctx context.Context) (*consensusAPI.Status, error
840840
// Failed to load validator set.
841841
status.IsValidator = false
842842
}
843+
844+
cps, err := n.mux.State().Storage().GetCheckpoints(ctx, &checkpoint.GetCheckpointsRequest{
845+
Version: 1,
846+
})
847+
switch err {
848+
case nil:
849+
for _, cp := range cps {
850+
status.Checkpoints = append(status.Checkpoints, &consensusAPI.Checkpoint{
851+
Height: cp.Root.Version,
852+
BlockHash: cp.Root.Hash,
853+
})
854+
}
855+
default:
856+
return nil, fmt.Errorf("failed to fetch checkpoints: %w", err)
857+
}
843858
}
844859

845860
return status, nil

0 commit comments

Comments
 (0)