@@ -4,32 +4,41 @@ import (
44 "context"
55 "time"
66
7+ "google.golang.org/grpc/codes"
8+ "google.golang.org/grpc/status"
9+
10+ "github.com/iotaledger/hive.go/ierrors"
11+ "github.com/iotaledger/hive.go/kvstore"
712 "github.com/iotaledger/hive.go/runtime/event"
813 "github.com/iotaledger/hive.go/runtime/workerpool"
914 inx "github.com/iotaledger/inx/go"
1015 "github.com/iotaledger/iota-core/pkg/protocol/engine/syncmanager"
1116)
1217
13- func inxNodeStatus (status * syncmanager.SyncStatus ) * inx.NodeStatus {
14- finalizedCommitment , err := deps .Protocol .Engines .Main .Get ().Storage .Commitments ().Load (status .LatestFinalizedSlot )
18+ func inxNodeStatus (syncStatus * syncmanager.SyncStatus ) ( * inx.NodeStatus , error ) {
19+ finalizedCommitment , err := deps .Protocol .Engines .Main .Get ().Storage .Commitments ().Load (syncStatus .LatestFinalizedSlot )
1520 if err != nil {
16- return nil
21+ if ierrors .Is (err , kvstore .ErrKeyNotFound ) {
22+ return nil , status .Errorf (codes .NotFound , "finalized commitment (slot %d) not found" , syncStatus .LatestFinalizedSlot )
23+ }
24+
25+ return nil , status .Errorf (codes .Internal , "failed to load finalized commitment (slot %d): %s" , syncStatus .LatestFinalizedSlot , err .Error ())
1726 }
1827
1928 return & inx.NodeStatus {
20- IsHealthy : status .NodeSynced ,
21- IsBootstrapped : status .NodeBootstrapped ,
22- LastAcceptedBlockSlot : uint32 (status .LastAcceptedBlockSlot ),
23- LastConfirmedBlockSlot : uint32 (status .LastConfirmedBlockSlot ),
24- LatestCommitment : inxCommitment (status .LatestCommitment ),
29+ IsHealthy : syncStatus .NodeSynced ,
30+ IsBootstrapped : syncStatus .NodeBootstrapped ,
31+ LastAcceptedBlockSlot : uint32 (syncStatus .LastAcceptedBlockSlot ),
32+ LastConfirmedBlockSlot : uint32 (syncStatus .LastConfirmedBlockSlot ),
33+ LatestCommitment : inxCommitment (syncStatus .LatestCommitment ),
2534 LatestFinalizedCommitment : inxCommitment (finalizedCommitment ),
26- PruningEpoch : uint32 (status .LastPrunedEpoch ),
27- HasPruned : status .HasPruned ,
28- }
35+ PruningEpoch : uint32 (syncStatus .LastPrunedEpoch ),
36+ HasPruned : syncStatus .HasPruned ,
37+ }, nil
2938}
3039
3140func (s * Server ) ReadNodeStatus (context.Context , * inx.NoParams ) (* inx.NodeStatus , error ) {
32- return inxNodeStatus (deps .Protocol .Engines .Main .Get ().SyncManager .SyncStatus ()), nil
41+ return inxNodeStatus (deps .Protocol .Engines .Main .Get ().SyncManager .SyncStatus ())
3342}
3443
3544func (s * Server ) ListenToNodeStatus (req * inx.NodeStatusRequest , srv inx.INX_ListenToNodeStatusServer ) error {
@@ -56,7 +65,11 @@ func (s *Server) ListenToNodeStatus(req *inx.NodeStatusRequest, srv inx.INX_List
5665 lastUpdateTimer = nil
5766 }
5867
59- nodeStatus := inxNodeStatus (status )
68+ nodeStatus , err := inxNodeStatus (status )
69+ if err != nil {
70+ Component .LogErrorf ("failed to convert sync status to inx node status: %s" , err .Error ())
71+ return
72+ }
6073
6174 // Use cool-down if the node is syncing
6275 if coolDownDuration > 0 && ! nodeStatus .GetIsHealthy () {
0 commit comments