Skip to content

Commit be6aaf8

Browse files
committed
devrpc: add read-only FetchReputation RPC
Expose the local reputation subsystem's computed state through a new unary, read-only FetchReputation method on the devrpc (dev/debug) sub-server. The handler calls Manager.Snapshot() and marshals the per-channel state into the new ChannelReputation / BucketOccupancy proto messages. The reputation manager is wired into the devrpc Config through PopulateDependencies. It is nil unless the experimental --routing.reputation flag is set; the handler is nil-safe and returns a clear "reputation subsystem disabled" error in that case. The method requires a read-only offchain macaroon permission, and an lncli "fetchreputation" command and a harness RPC wrapper are added to drive it. Generated proto stubs regenerated via 'make rpc' (docker-based gen_protos).
1 parent 4c0ac85 commit be6aaf8

13 files changed

Lines changed: 768 additions & 21 deletions

File tree

cmd/commands/devrpc_active.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ func devCommands() []cli.Command {
2424
ArgsUsage: "graph-json-file",
2525
Action: actionDecorator(importGraph),
2626
},
27+
{
28+
Name: "fetchreputation",
29+
Category: "Development",
30+
Description: "Fetches a read-only snapshot of the " +
31+
"local reputation subsystem's computed " +
32+
"per-channel state. Requires the node to be " +
33+
"running with --routing.reputation.",
34+
Usage: "Fetch the local reputation snapshot.",
35+
Action: actionDecorator(fetchReputation),
36+
},
2737
}
2838
}
2939

@@ -60,3 +70,20 @@ func importGraph(ctx *cli.Context) error {
6070
printRespJSON(res)
6171
return nil
6272
}
73+
74+
func fetchReputation(ctx *cli.Context) error {
75+
ctxc := getContext()
76+
client, cleanUp := getDevClient(ctx)
77+
defer cleanUp()
78+
79+
res, err := client.FetchReputation(
80+
ctxc, &devrpc.FetchReputationRequest{},
81+
)
82+
if err != nil {
83+
return err
84+
}
85+
86+
printRespJSON(res)
87+
88+
return nil
89+
}

lnrpc/devrpc/config_active.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/btcsuite/btcd/chaincfg"
88
graphdb "github.com/lightningnetwork/lnd/graph/db"
99
"github.com/lightningnetwork/lnd/htlcswitch"
10+
"github.com/lightningnetwork/lnd/reputation"
1011
)
1112

1213
// Config is the primary configuration struct for the DEV RPC server. It
@@ -18,4 +19,10 @@ type Config struct {
1819
ActiveNetParams *chaincfg.Params
1920
GraphDB *graphdb.ChannelGraph
2021
Switch *htlcswitch.Switch
22+
23+
// ReputationManager is the optional read-only local reputation
24+
// subsystem. It is nil unless the experimental --routing.reputation
25+
// flag is set; the FetchReputation RPC returns a clear error when it is
26+
// nil.
27+
ReputationManager *reputation.Manager
2128
}

0 commit comments

Comments
 (0)