rpc: expose peer's GossipSyncer sync type

This commit is contained in:
Wilmer Paulino 2019-03-22 19:57:03 -07:00
parent 8b6a9bb5d3
commit ca01695330
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F
4 changed files with 735 additions and 626 deletions

File diff suppressed because it is too large Load Diff

View File

@ -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 {

View File

@ -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."
}
}
},

View File

@ -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)