mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
rpc: expose peer's GossipSyncer sync type
This commit is contained in:
parent
8b6a9bb5d3
commit
ca01695330
1294
lnrpc/rpc.pb.go
1294
lnrpc/rpc.pb.go
File diff suppressed because it is too large
Load Diff
@ -1257,6 +1257,26 @@ message Peer {
|
||||
|
||||
/// Ping time to this peer
|
||||
int64 ping_time = 9 [json_name = "ping_time"];
|
||||
|
||||
enum SyncType {
|
||||
/**
|
||||
Denotes that we cannot determine the peer's current sync type.
|
||||
*/
|
||||
UNKNOWN_SYNC = 0;
|
||||
|
||||
/**
|
||||
Denotes that we are actively receiving new graph updates from the peer.
|
||||
*/
|
||||
ACTIVE_SYNC = 1;
|
||||
|
||||
/**
|
||||
Denotes that we are not receiving new graph updates from the peer.
|
||||
*/
|
||||
PASSIVE_SYNC = 2;
|
||||
}
|
||||
|
||||
// The type of sync we are currently performing with this peer.
|
||||
SyncType sync_type = 10 [json_name = "sync_type"];
|
||||
}
|
||||
|
||||
message ListPeersRequest {
|
||||
|
@ -1305,6 +1305,16 @@
|
||||
],
|
||||
"default": "OPEN"
|
||||
},
|
||||
"PeerSyncType": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"UNKNOWN_SYNC",
|
||||
"ACTIVE_SYNC",
|
||||
"PASSIVE_SYNC"
|
||||
],
|
||||
"default": "UNKNOWN_SYNC",
|
||||
"description": " - UNKNOWN_SYNC: *\nDenotes that we cannot determine the peer's current sync type.\n - ACTIVE_SYNC: *\nDenotes that we are actively receiving new graph updates from the peer.\n - PASSIVE_SYNC: *\nDenotes that we are not receiving new graph updates from the peer."
|
||||
},
|
||||
"PendingChannelsResponseClosedChannel": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@ -2856,6 +2866,10 @@
|
||||
"type": "string",
|
||||
"format": "int64",
|
||||
"title": "/ Ping time to this peer"
|
||||
},
|
||||
"sync_type": {
|
||||
"$ref": "#/definitions/PeerSyncType",
|
||||
"description": "The type of sync we are currently performing with this peer."
|
||||
}
|
||||
}
|
||||
},
|
||||
|
33
rpcserver.go
33
rpcserver.go
@ -34,6 +34,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/chanbackup"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/channelnotifier"
|
||||
"github.com/lightningnetwork/lnd/discovery"
|
||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||
"github.com/lightningnetwork/lnd/input"
|
||||
"github.com/lightningnetwork/lnd/invoices"
|
||||
@ -2012,9 +2013,36 @@ func (r *rpcServer) ListPeers(ctx context.Context,
|
||||
satRecv += int64(c.TotalMSatReceived.ToSatoshis())
|
||||
}
|
||||
|
||||
nodePub := serverPeer.addr.IdentityKey.SerializeCompressed()
|
||||
nodePub := serverPeer.PubKey()
|
||||
|
||||
// Retrieve the peer's sync type. If we don't currently have a
|
||||
// syncer for the peer, then we'll default to a passive sync.
|
||||
// This can happen if the RPC is called while a peer is
|
||||
// initializing.
|
||||
syncer, ok := r.server.authGossiper.SyncManager().GossipSyncer(
|
||||
nodePub,
|
||||
)
|
||||
|
||||
var lnrpcSyncType lnrpc.Peer_SyncType
|
||||
if !ok {
|
||||
rpcsLog.Warnf("Gossip syncer for peer=%x not found",
|
||||
nodePub)
|
||||
lnrpcSyncType = lnrpc.Peer_UNKNOWN_SYNC
|
||||
} else {
|
||||
syncType := syncer.SyncType()
|
||||
switch syncType {
|
||||
case discovery.ActiveSync:
|
||||
lnrpcSyncType = lnrpc.Peer_ACTIVE_SYNC
|
||||
case discovery.PassiveSync:
|
||||
lnrpcSyncType = lnrpc.Peer_PASSIVE_SYNC
|
||||
default:
|
||||
return nil, fmt.Errorf("unhandled sync type %v",
|
||||
syncType)
|
||||
}
|
||||
}
|
||||
|
||||
peer := &lnrpc.Peer{
|
||||
PubKey: hex.EncodeToString(nodePub),
|
||||
PubKey: hex.EncodeToString(nodePub[:]),
|
||||
Address: serverPeer.conn.RemoteAddr().String(),
|
||||
Inbound: serverPeer.inbound,
|
||||
BytesRecv: atomic.LoadUint64(&serverPeer.bytesReceived),
|
||||
@ -2022,6 +2050,7 @@ func (r *rpcServer) ListPeers(ctx context.Context,
|
||||
SatSent: satSent,
|
||||
SatRecv: satRecv,
|
||||
PingTime: serverPeer.PingTime(),
|
||||
SyncType: lnrpcSyncType,
|
||||
}
|
||||
|
||||
resp.Peers = append(resp.Peers, peer)
|
||||
|
Loading…
Reference in New Issue
Block a user