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
8 changed files with 3609 additions and 3238 deletions

View File

@ -10,6 +10,8 @@ import (
"math"
"net"
"net/http"
"os"
"path/filepath"
"runtime"
"sort"
"strconv"
@ -330,6 +332,19 @@ func MainRPCServerPermissions() map[string][]bakery.Op {
Entity: "info",
Action: "read",
}},
"/lnrpc.Lightning/GetDebugInfo": {{
Entity: "info",
Action: "read",
}, {
Entity: "offchain",
Action: "read",
}, {
Entity: "onchain",
Action: "read",
}, {
Entity: "peers",
Action: "read",
}},
"/lnrpc.Lightning/GetRecoveryInfo": {{
Entity: "info",
Action: "read",
@ -3020,6 +3035,31 @@ func (r *rpcServer) GetInfo(_ context.Context,
}, 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
// in recovery mode, whether the recovery is finished, and the progress made
// so far.