lnrpc+rpcserver: add new GetDebugInfo RPC method

This commit is contained in:
Oliver Gugger 2023-11-15 21:19:24 -06:00
parent becbe7085d
commit 8a2c3a3d85
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
8 changed files with 3609 additions and 3238 deletions

File diff suppressed because it is too large Load Diff

View File

@ -550,6 +550,24 @@ func local_request_Lightning_GetInfo_0(ctx context.Context, marshaler runtime.Ma
} }
func request_Lightning_GetDebugInfo_0(ctx context.Context, marshaler runtime.Marshaler, client LightningClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq GetDebugInfoRequest
var metadata runtime.ServerMetadata
msg, err := client.GetDebugInfo(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_Lightning_GetDebugInfo_0(ctx context.Context, marshaler runtime.Marshaler, server LightningServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq GetDebugInfoRequest
var metadata runtime.ServerMetadata
msg, err := server.GetDebugInfo(ctx, &protoReq)
return msg, metadata, err
}
func request_Lightning_GetRecoveryInfo_0(ctx context.Context, marshaler runtime.Marshaler, client LightningClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { func request_Lightning_GetRecoveryInfo_0(ctx context.Context, marshaler runtime.Marshaler, client LightningClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq GetRecoveryInfoRequest var protoReq GetRecoveryInfoRequest
var metadata runtime.ServerMetadata var metadata runtime.ServerMetadata
@ -2892,6 +2910,29 @@ func RegisterLightningHandlerServer(ctx context.Context, mux *runtime.ServeMux,
}) })
mux.Handle("GET", pattern_Lightning_GetDebugInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/lnrpc.Lightning/GetDebugInfo", runtime.WithHTTPPathPattern("/v1/getdebuginfo"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_Lightning_GetDebugInfo_0(rctx, inboundMarshaler, server, req, pathParams)
md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer())
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Lightning_GetDebugInfo_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("GET", pattern_Lightning_GetRecoveryInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { mux.Handle("GET", pattern_Lightning_GetRecoveryInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context()) ctx, cancel := context.WithCancel(req.Context())
defer cancel() defer cancel()
@ -4266,6 +4307,26 @@ func RegisterLightningHandlerClient(ctx context.Context, mux *runtime.ServeMux,
}) })
mux.Handle("GET", pattern_Lightning_GetDebugInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
rctx, err := runtime.AnnotateContext(ctx, mux, req, "/lnrpc.Lightning/GetDebugInfo", runtime.WithHTTPPathPattern("/v1/getdebuginfo"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_Lightning_GetDebugInfo_0(rctx, inboundMarshaler, client, req, pathParams)
ctx = runtime.NewServerMetadataContext(ctx, md)
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
forward_Lightning_GetDebugInfo_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("GET", pattern_Lightning_GetRecoveryInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { mux.Handle("GET", pattern_Lightning_GetRecoveryInfo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context()) ctx, cancel := context.WithCancel(req.Context())
defer cancel() defer cancel()
@ -5322,6 +5383,8 @@ var (
pattern_Lightning_GetInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getinfo"}, "")) pattern_Lightning_GetInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getinfo"}, ""))
pattern_Lightning_GetDebugInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getdebuginfo"}, ""))
pattern_Lightning_GetRecoveryInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getrecoveryinfo"}, "")) pattern_Lightning_GetRecoveryInfo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "getrecoveryinfo"}, ""))
pattern_Lightning_PendingChannels_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "channels", "pending"}, "")) pattern_Lightning_PendingChannels_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "channels", "pending"}, ""))
@ -5458,6 +5521,8 @@ var (
forward_Lightning_GetInfo_0 = runtime.ForwardResponseMessage forward_Lightning_GetInfo_0 = runtime.ForwardResponseMessage
forward_Lightning_GetDebugInfo_0 = runtime.ForwardResponseMessage
forward_Lightning_GetRecoveryInfo_0 = runtime.ForwardResponseMessage forward_Lightning_GetRecoveryInfo_0 = runtime.ForwardResponseMessage
forward_Lightning_PendingChannels_0 = runtime.ForwardResponseMessage forward_Lightning_PendingChannels_0 = runtime.ForwardResponseMessage

View File

@ -455,6 +455,31 @@ func RegisterLightningJSONCallbacks(registry map[string]func(ctx context.Context
callback(string(respBytes), nil) callback(string(respBytes), nil)
} }
registry["lnrpc.Lightning.GetDebugInfo"] = func(ctx context.Context,
conn *grpc.ClientConn, reqJSON string, callback func(string, error)) {
req := &GetDebugInfoRequest{}
err := marshaler.Unmarshal([]byte(reqJSON), req)
if err != nil {
callback("", err)
return
}
client := NewLightningClient(conn)
resp, err := client.GetDebugInfo(ctx, req)
if err != nil {
callback("", err)
return
}
respBytes, err := marshaler.Marshal(resp)
if err != nil {
callback("", err)
return
}
callback(string(respBytes), nil)
}
registry["lnrpc.Lightning.GetRecoveryInfo"] = func(ctx context.Context, registry["lnrpc.Lightning.GetRecoveryInfo"] = func(ctx context.Context,
conn *grpc.ClientConn, reqJSON string, callback func(string, error)) { conn *grpc.ClientConn, reqJSON string, callback func(string, error)) {

View File

@ -143,6 +143,13 @@ service Lightning {
*/ */
rpc GetInfo (GetInfoRequest) returns (GetInfoResponse); rpc GetInfo (GetInfoRequest) returns (GetInfoResponse);
/* lncli: 'getdebuginfo'
GetDebugInfo returns debug information concerning the state of the daemon
and its subsystems. This includes the full configuration and the latest log
entries from the log file.
*/
rpc GetDebugInfo (GetDebugInfoRequest) returns (GetDebugInfoResponse);
/** lncli: `getrecoveryinfo` /** lncli: `getrecoveryinfo`
GetRecoveryInfo returns information concerning the recovery mode including GetRecoveryInfo returns information concerning the recovery mode including
whether it's in a recovery mode, whether the recovery is finished, and the whether it's in a recovery mode, whether the recovery is finished, and the
@ -1955,6 +1962,14 @@ message GetInfoResponse {
bool store_final_htlc_resolutions = 22; bool store_final_htlc_resolutions = 22;
} }
message GetDebugInfoRequest {
}
message GetDebugInfoResponse {
map<string, string> config = 1;
repeated string log = 2;
}
message GetRecoveryInfoRequest { message GetRecoveryInfoRequest {
} }
message GetRecoveryInfoResponse { message GetRecoveryInfoResponse {

View File

@ -1061,6 +1061,29 @@
] ]
} }
}, },
"/v1/getdebuginfo": {
"get": {
"summary": "lncli: 'getdebuginfo'\nGetDebugInfo returns debug information concerning the state of the daemon\nand its subsystems. This includes the full configuration and the latest log\nentries from the log file.",
"operationId": "Lightning_GetDebugInfo",
"responses": {
"200": {
"description": "A successful response.",
"schema": {
"$ref": "#/definitions/lnrpcGetDebugInfoResponse"
}
},
"default": {
"description": "An unexpected error response.",
"schema": {
"$ref": "#/definitions/rpcStatus"
}
}
},
"tags": [
"Lightning"
]
}
},
"/v1/getinfo": { "/v1/getinfo": {
"get": { "get": {
"summary": "lncli: `getinfo`\nGetInfo returns general information concerning the lightning node including\nit's identity pubkey, alias, the chains it is connected to, and information\nconcerning the number of open+pending channels.", "summary": "lncli: `getinfo`\nGetInfo returns general information concerning the lightning node including\nit's identity pubkey, alias, the chains it is connected to, and information\nconcerning the number of open+pending channels.",
@ -4866,6 +4889,23 @@
} }
} }
}, },
"lnrpcGetDebugInfoResponse": {
"type": "object",
"properties": {
"config": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"log": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"lnrpcGetInfoResponse": { "lnrpcGetInfoResponse": {
"type": "object", "type": "object",
"properties": { "properties": {

View File

@ -44,6 +44,8 @@ http:
get: "/v1/peers/subscribe" get: "/v1/peers/subscribe"
- selector: lnrpc.Lightning.GetInfo - selector: lnrpc.Lightning.GetInfo
get: "/v1/getinfo" get: "/v1/getinfo"
- selector: lnrpc.Lightning.GetDebugInfo
get: "/v1/getdebuginfo"
- selector: lnrpc.Lightning.GetRecoveryInfo - selector: lnrpc.Lightning.GetRecoveryInfo
get: "/v1/getrecoveryinfo" get: "/v1/getrecoveryinfo"
- selector: lnrpc.Lightning.PendingChannels - selector: lnrpc.Lightning.PendingChannels

View File

@ -102,6 +102,11 @@ type LightningClient interface {
// it's identity pubkey, alias, the chains it is connected to, and information // it's identity pubkey, alias, the chains it is connected to, and information
// concerning the number of open+pending channels. // concerning the number of open+pending channels.
GetInfo(ctx context.Context, in *GetInfoRequest, opts ...grpc.CallOption) (*GetInfoResponse, error) GetInfo(ctx context.Context, in *GetInfoRequest, opts ...grpc.CallOption) (*GetInfoResponse, error)
// lncli: 'getdebuginfo'
// GetDebugInfo returns debug information concerning the state of the daemon
// and its subsystems. This includes the full configuration and the latest log
// entries from the log file.
GetDebugInfo(ctx context.Context, in *GetDebugInfoRequest, opts ...grpc.CallOption) (*GetDebugInfoResponse, error)
// * lncli: `getrecoveryinfo` // * lncli: `getrecoveryinfo`
// GetRecoveryInfo returns information concerning the recovery mode including // GetRecoveryInfo returns information concerning the recovery mode including
// whether it's in a recovery mode, whether the recovery is finished, and the // whether it's in a recovery mode, whether the recovery is finished, and the
@ -611,6 +616,15 @@ func (c *lightningClient) GetInfo(ctx context.Context, in *GetInfoRequest, opts
return out, nil return out, nil
} }
func (c *lightningClient) GetDebugInfo(ctx context.Context, in *GetDebugInfoRequest, opts ...grpc.CallOption) (*GetDebugInfoResponse, error) {
out := new(GetDebugInfoResponse)
err := c.cc.Invoke(ctx, "/lnrpc.Lightning/GetDebugInfo", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *lightningClient) GetRecoveryInfo(ctx context.Context, in *GetRecoveryInfoRequest, opts ...grpc.CallOption) (*GetRecoveryInfoResponse, error) { func (c *lightningClient) GetRecoveryInfo(ctx context.Context, in *GetRecoveryInfoRequest, opts ...grpc.CallOption) (*GetRecoveryInfoResponse, error) {
out := new(GetRecoveryInfoResponse) out := new(GetRecoveryInfoResponse)
err := c.cc.Invoke(ctx, "/lnrpc.Lightning/GetRecoveryInfo", in, out, opts...) err := c.cc.Invoke(ctx, "/lnrpc.Lightning/GetRecoveryInfo", in, out, opts...)
@ -1409,6 +1423,11 @@ type LightningServer interface {
// it's identity pubkey, alias, the chains it is connected to, and information // it's identity pubkey, alias, the chains it is connected to, and information
// concerning the number of open+pending channels. // concerning the number of open+pending channels.
GetInfo(context.Context, *GetInfoRequest) (*GetInfoResponse, error) GetInfo(context.Context, *GetInfoRequest) (*GetInfoResponse, error)
// lncli: 'getdebuginfo'
// GetDebugInfo returns debug information concerning the state of the daemon
// and its subsystems. This includes the full configuration and the latest log
// entries from the log file.
GetDebugInfo(context.Context, *GetDebugInfoRequest) (*GetDebugInfoResponse, error)
// * lncli: `getrecoveryinfo` // * lncli: `getrecoveryinfo`
// GetRecoveryInfo returns information concerning the recovery mode including // GetRecoveryInfo returns information concerning the recovery mode including
// whether it's in a recovery mode, whether the recovery is finished, and the // whether it's in a recovery mode, whether the recovery is finished, and the
@ -1773,6 +1792,9 @@ func (UnimplementedLightningServer) SubscribePeerEvents(*PeerEventSubscription,
func (UnimplementedLightningServer) GetInfo(context.Context, *GetInfoRequest) (*GetInfoResponse, error) { func (UnimplementedLightningServer) GetInfo(context.Context, *GetInfoRequest) (*GetInfoResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetInfo not implemented") return nil, status.Errorf(codes.Unimplemented, "method GetInfo not implemented")
} }
func (UnimplementedLightningServer) GetDebugInfo(context.Context, *GetDebugInfoRequest) (*GetDebugInfoResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetDebugInfo not implemented")
}
func (UnimplementedLightningServer) GetRecoveryInfo(context.Context, *GetRecoveryInfoRequest) (*GetRecoveryInfoResponse, error) { func (UnimplementedLightningServer) GetRecoveryInfo(context.Context, *GetRecoveryInfoRequest) (*GetRecoveryInfoResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetRecoveryInfo not implemented") return nil, status.Errorf(codes.Unimplemented, "method GetRecoveryInfo not implemented")
} }
@ -2233,6 +2255,24 @@ func _Lightning_GetInfo_Handler(srv interface{}, ctx context.Context, dec func(i
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
func _Lightning_GetDebugInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetDebugInfoRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(LightningServer).GetDebugInfo(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/lnrpc.Lightning/GetDebugInfo",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(LightningServer).GetDebugInfo(ctx, req.(*GetDebugInfoRequest))
}
return interceptor(ctx, in, info, handler)
}
func _Lightning_GetRecoveryInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { func _Lightning_GetRecoveryInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetRecoveryInfoRequest) in := new(GetRecoveryInfoRequest)
if err := dec(in); err != nil { if err := dec(in); err != nil {
@ -3267,6 +3307,10 @@ var Lightning_ServiceDesc = grpc.ServiceDesc{
MethodName: "GetInfo", MethodName: "GetInfo",
Handler: _Lightning_GetInfo_Handler, Handler: _Lightning_GetInfo_Handler,
}, },
{
MethodName: "GetDebugInfo",
Handler: _Lightning_GetDebugInfo_Handler,
},
{ {
MethodName: "GetRecoveryInfo", MethodName: "GetRecoveryInfo",
Handler: _Lightning_GetRecoveryInfo_Handler, Handler: _Lightning_GetRecoveryInfo_Handler,

View File

@ -10,6 +10,8 @@ import (
"math" "math"
"net" "net"
"net/http" "net/http"
"os"
"path/filepath"
"runtime" "runtime"
"sort" "sort"
"strconv" "strconv"
@ -330,6 +332,19 @@ func MainRPCServerPermissions() map[string][]bakery.Op {
Entity: "info", Entity: "info",
Action: "read", Action: "read",
}}, }},
"/lnrpc.Lightning/GetDebugInfo": {{
Entity: "info",
Action: "read",
}, {
Entity: "offchain",
Action: "read",
}, {
Entity: "onchain",
Action: "read",
}, {
Entity: "peers",
Action: "read",
}},
"/lnrpc.Lightning/GetRecoveryInfo": {{ "/lnrpc.Lightning/GetRecoveryInfo": {{
Entity: "info", Entity: "info",
Action: "read", Action: "read",
@ -3020,6 +3035,31 @@ func (r *rpcServer) GetInfo(_ context.Context,
}, nil }, nil
} }
// GetDebugInfo returns debug information concerning the state of the daemon
// and its subsystems. This includes the full configuration and the latest log
// entries from the log file.
func (r *rpcServer) GetDebugInfo(_ context.Context,
_ *lnrpc.GetDebugInfoRequest) (*lnrpc.GetDebugInfoResponse, error) {
flatConfig, err := configToFlatMap(*r.cfg)
if err != nil {
return nil, fmt.Errorf("error converting config to flat map: "+
"%w", err)
}
logFileName := filepath.Join(r.cfg.LogDir, defaultLogFilename)
logContent, err := os.ReadFile(logFileName)
if err != nil {
return nil, fmt.Errorf("error reading log file '%s': %w",
logFileName, err)
}
return &lnrpc.GetDebugInfoResponse{
Config: flatConfig,
Log: strings.Split(string(logContent), "\n"),
}, nil
}
// GetRecoveryInfo returns a boolean indicating whether the wallet is started // GetRecoveryInfo returns a boolean indicating whether the wallet is started
// in recovery mode, whether the recovery is finished, and the progress made // in recovery mode, whether the recovery is finished, and the progress made
// so far. // so far.