This repository has been archived by the owner on May 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
getting node status: ``` > grpcurl -plaintext -d '{}' 127.0.0.1:9092 spacemesh.v2alpha1.NodeService.Status { "connectedPeers": "111", "status": "SYNC_STATUS_SYNCING", "latestLayer": 50373, "appliedLayer": 50372, "processedLayer": 50372, "currentLayer": 54315 } ```
- Loading branch information
Showing
7 changed files
with
423 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package v2alpha1 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime" | ||
spacemeshv2alpha1 "github.com/spacemeshos/api/release/go/spacemesh/v2alpha1" | ||
"google.golang.org/grpc" | ||
|
||
"github.com/spacemeshos/go-spacemesh/common/types" | ||
"github.com/spacemeshos/go-spacemesh/timesync" | ||
) | ||
|
||
const ( | ||
Node = "node_v2alpha1" | ||
) | ||
|
||
// nodePeerCounter is an api to get current peer count. | ||
type nodePeerCounter interface { | ||
PeerCount() uint64 | ||
} | ||
|
||
// nodeMeshAPI is an api for getting mesh status. | ||
type nodeMeshAPI interface { | ||
LatestLayer() types.LayerID | ||
LatestLayerInState() types.LayerID | ||
ProcessedLayer() types.LayerID | ||
} | ||
|
||
// nodeSyncer is an API to get sync status. | ||
type nodeSyncer interface { | ||
IsSynced(context.Context) bool | ||
} | ||
|
||
func NewNodeService(peers nodePeerCounter, msh nodeMeshAPI, clock *timesync.NodeClock, syncer nodeSyncer) *NodeService { | ||
return &NodeService{ | ||
mesh: msh, | ||
clock: clock, | ||
peerCounter: peers, | ||
syncer: syncer, | ||
} | ||
} | ||
|
||
type NodeService struct { | ||
mesh nodeMeshAPI | ||
clock *timesync.NodeClock | ||
peerCounter nodePeerCounter | ||
syncer nodeSyncer | ||
} | ||
|
||
func (s *NodeService) RegisterService(server *grpc.Server) { | ||
spacemeshv2alpha1.RegisterNodeServiceServer(server, s) | ||
} | ||
|
||
func (s *NodeService) RegisterHandlerService(mux *runtime.ServeMux) error { | ||
return spacemeshv2alpha1.RegisterNodeServiceHandlerServer(context.Background(), mux, s) | ||
} | ||
|
||
// String returns the service name. | ||
func (s *NodeService) String() string { | ||
return "NodeService" | ||
} | ||
|
||
func (s *NodeService) Status(ctx context.Context, _ *spacemeshv2alpha1.NodeStatusRequest) ( | ||
*spacemeshv2alpha1.NodeStatusResponse, error, | ||
) { | ||
var status spacemeshv2alpha1.NodeStatusResponse_SyncStatus | ||
|
||
if s.syncer.IsSynced(ctx) { | ||
status = spacemeshv2alpha1.NodeStatusResponse_SYNC_STATUS_SYNCED | ||
} else { | ||
status = spacemeshv2alpha1.NodeStatusResponse_SYNC_STATUS_SYNCING | ||
} | ||
|
||
return &spacemeshv2alpha1.NodeStatusResponse{ | ||
ConnectedPeers: s.peerCounter.PeerCount(), | ||
Status: status, | ||
LatestLayer: s.mesh.LatestLayer().Uint32(), // latest layer node has seen from blocks | ||
AppliedLayer: s.mesh.LatestLayerInState().Uint32(), // last layer node has applied to the state | ||
ProcessedLayer: s.mesh.ProcessedLayer().Uint32(), // last layer whose votes have been processed | ||
CurrentLayer: s.clock.CurrentLayer().Uint32(), // current layer, based on clock time | ||
}, nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.