lnrpc+lncli: display peer errors in listpeers

This change adds a set of errors to the peer struct returned by list
peers. A latest error boolean is added to allow for more succinct
default lncli responses.
This commit is contained in:
carla 2020-03-13 09:15:49 +02:00
parent 54089febd6
commit 4c48d0361d
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91
6 changed files with 991 additions and 812 deletions

View File

@ -1335,7 +1335,13 @@ var listPeersCommand = cli.Command{
Name: "listpeers",
Category: "Peers",
Usage: "List all active, currently connected peers.",
Action: actionDecorator(listPeers),
Flags: []cli.Flag{
cli.BoolFlag{
Name: "list_errors",
Usage: "list a full set of most recent errors for the peer",
},
},
Action: actionDecorator(listPeers),
}
func listPeers(ctx *cli.Context) error {
@ -1343,7 +1349,11 @@ func listPeers(ctx *cli.Context) error {
client, cleanUp := getClient(ctx)
defer cleanUp()
req := &lnrpc.ListPeersRequest{}
// By default, we display a single error on the cli. If the user
// specifically requests a full error set, then we will provide it.
req := &lnrpc.ListPeersRequest{
LatestError: !ctx.IsSet("list_errors"),
}
resp, err := client.ListPeers(ctxb, req)
if err != nil {
return err

File diff suppressed because it is too large Load Diff

View File

@ -269,10 +269,18 @@ func request_Lightning_DisconnectPeer_0(ctx context.Context, marshaler runtime.M
}
var (
filter_Lightning_ListPeers_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
)
func request_Lightning_ListPeers_0(ctx context.Context, marshaler runtime.Marshaler, client LightningClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq ListPeersRequest
var metadata runtime.ServerMetadata
if err := runtime.PopulateQueryParameters(&protoReq, req.URL.Query(), filter_Lightning_ListPeers_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.ListPeers(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err

View File

@ -1571,9 +1571,32 @@ message Peer {
/// Features advertised by the remote peer in their init message.
map<uint32, Feature> features = 11;
/*
The latest errors received from our peer with timestamps, limited to the 10
most recent errors. These errors are tracked across peer connections, but
are not persisted across lnd restarts. Note that these errors are only
stored for peers that we have channels open with, to prevent peers from
spamming us with errors at no cost.
*/
repeated TimestampedError errors = 12;
}
message TimestampedError {
// The unix timestamp in seconds when the error occurred.
uint64 timestamp = 1;
// The string representation of the error sent by our peer.
string error = 2;
}
message ListPeersRequest {
/*
If true, only the last error that our peer sent us will be returned with
the peer's information, rather than the full set of historic errors we have
stored.
*/
bool latest_error = 1;
}
message ListPeersResponse {
/// The list of currently connected peers

View File

@ -1186,6 +1186,16 @@
}
}
},
"parameters": [
{
"name": "latest_error",
"description": "If true, only the last error that our peer sent us will be returned with\nthe peer's information, rather than the full set of historic errors we have\nstored.",
"in": "query",
"required": false,
"type": "boolean",
"format": "boolean"
}
],
"tags": [
"Lightning"
]
@ -3819,6 +3829,13 @@
"$ref": "#/definitions/lnrpcFeature"
},
"description": "/ Features advertised by the remote peer in their init message."
},
"errors": {
"type": "array",
"items": {
"$ref": "#/definitions/lnrpcTimestampedError"
},
"description": "The latest errors received from our peer with timestamps, limited to the 10\nmost recent errors. These errors are tracked across peer connections, but\nare not persisted across lnd restarts. Note that these errors are only\nstored for peers that we have channels open with, to prevent peers from\nspamming us with errors at no cost."
}
}
},
@ -4270,6 +4287,20 @@
"lnrpcStopResponse": {
"type": "object"
},
"lnrpcTimestampedError": {
"type": "object",
"properties": {
"timestamp": {
"type": "string",
"format": "uint64",
"description": "The unix timestamp in seconds when the error occurred."
},
"error": {
"type": "string",
"description": "The string representation of the error sent by our peer."
}
}
},
"lnrpcTransaction": {
"type": "object",
"properties": {

View File

@ -2459,6 +2459,33 @@ func (r *rpcServer) ListPeers(ctx context.Context,
Features: features,
}
var peerErrors []interface{}
// If we only want the most recent error, get the most recent
// error from the buffer and add it to our list of errors if
// it is non-nil. If we want all the stored errors, simply
// add the full list to our set of errors.
if in.LatestError {
latestErr := serverPeer.errorBuffer.Latest()
if latestErr != nil {
peerErrors = []interface{}{latestErr}
}
} else {
peerErrors = serverPeer.errorBuffer.List()
}
// Add the relevant peer errors to our response.
for _, error := range peerErrors {
tsError := error.(*timestampedError)
rpcErr := &lnrpc.TimestampedError{
Timestamp: uint64(tsError.timestamp.Unix()),
Error: tsError.error.Error(),
}
peer.Errors = append(peer.Errors, rpcErr)
}
resp.Peers = append(resp.Peers, peer)
}