From faaf1f57efbda992495a638f98dca94d028d2183 Mon Sep 17 00:00:00 2001 From: Ken Sedgwick Date: Sun, 18 Aug 2024 16:46:33 -0700 Subject: [PATCH 1/3] contrib: Update clboss-routing-stats to use alias cache --- contrib/clboss-routing-stats | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/contrib/clboss-routing-stats b/contrib/clboss-routing-stats index 3b078cf5a..4ed71f7c9 100755 --- a/contrib/clboss-routing-stats +++ b/contrib/clboss-routing-stats @@ -14,6 +14,7 @@ import argparse import json from tabulate import tabulate from wcwidth import wcswidth +from clboss.alias_cache import lookup_alias def run_lightning_cli_command(network_option, command, *args): try: @@ -85,15 +86,9 @@ def main(): "success_per_day": 0 } - # Run listnodes command for each unique peer_id and update alias for peer_id in peers.keys(): - listnodes_data = run_lightning_cli_command(network_option, 'listnodes', peer_id) - if listnodes_data: - nodes = listnodes_data.get("nodes", []) - for node in nodes: - alias = node.get("alias") - if peer_id in peers: - peers[peer_id]["alias"] = alias + alias = lookup_alias(run_lightning_cli_command, network_option, peer_id) + peers[peer_id]["alias"] = alias # Run clboss-status command and capture the output clboss_status_data = run_lightning_cli_command(network_option, 'clboss-status') From 48e8c4bc082b265e5c34cceaf63c8a91fe849fd1 Mon Sep 17 00:00:00 2001 From: Ken Sedgwick Date: Fri, 23 Aug 2024 10:27:37 -0700 Subject: [PATCH 2/3] contrib: Generalize clboss-routing-stats network param handling --- contrib/clboss-routing-stats | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/contrib/clboss-routing-stats b/contrib/clboss-routing-stats index 4ed71f7c9..db02967ca 100755 --- a/contrib/clboss-routing-stats +++ b/contrib/clboss-routing-stats @@ -39,17 +39,30 @@ def pad_string(s, width): pad = width - wcswidth(s) return s + ' ' * pad +import argparse + def main(): parser = argparse.ArgumentParser(description="Run lightning-cli with specified network") - parser.add_argument('--testnet', action='store_true', help='Run on testnet') + parser.add_argument('--mainnet', action='store_true', help='Run on mainnet') + parser.add_argument('--testnet', action='store_true', help='Run on testnet') + parser.add_argument('--signet', action='store_true', help='Run on signet') + parser.add_argument('--regtest', action='store_true', help='Run on regtest') + parser.add_argument('--network', help='Set the network explicitly') args = parser.parse_args() - if args.testnet: - network_option = '--testnet' + # Reconcile network option + if args.network: + network_option = f'--network={args.network}' + elif args.testnet: + network_option = '--network=testnet' + elif args.signet: + network_option = '--network=signet' + elif args.regtest: + network_option = '--network=regtest' else: - network_option = '--mainnet' # Default to mainnet if no option is specified + network_option = '--network=bitcoin' # lightning-cli wants "bitcoin" for mainnet # Run listpeerchannels command listpeerchannels_data = run_lightning_cli_command(network_option, 'listpeerchannels') From 4e329c2e2d67330ed552b372954b06cd385638cb Mon Sep 17 00:00:00 2001 From: Ken Sedgwick Date: Tue, 10 Sep 2024 11:13:21 -0700 Subject: [PATCH 3/3] contrib: Add opener column to clboss-routing-stats --- contrib/clboss-routing-stats | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/contrib/clboss-routing-stats b/contrib/clboss-routing-stats index db02967ca..88005ac82 100755 --- a/contrib/clboss-routing-stats +++ b/contrib/clboss-routing-stats @@ -135,12 +135,14 @@ def main(): peer = peers[peer_id] income_minus_expenditures, success_per_day = calculate_peer_score(peer) alias = pad_string(peer["alias"], max_alias_length) + opener = "L" if channels[short_channel_id]["opener"] == "local" else "R" to_us_msat = f"{channels[short_channel_id]['to_us_msat']:,}" # With commas income_minus_expenditures_formatted = f"{income_minus_expenditures:,}" # With commas spd_formatted = f"x{success_per_day:4.1f}" # Prefix w/ 'x', strip later, preserves padding table_data.append([ alias, short_channel_id, + opener, to_us_msat, peer["age"] // 86400, # Convert age from seconds to days income_minus_expenditures_formatted, @@ -150,9 +152,26 @@ def main(): # Print the table without grid table_str = tabulate(table_data, - headers=["Alias", "SCID", "to us", "Age", "Net msat", "SPD", "PeerID"], + headers=[ + "Alias", + "SCID", + "O", + "to us", + "Age", + "Net msat", + "SPD", + "PeerID" + ], tablefmt="plain", stralign="left", numalign="right", - colalign=("left", "left", "right", "right", "right", "left", "left")) + colalign=( + "left", + "left", + "left", + "right", + "right", + "right", + "left", + "left")) # Remove the "x" prefix from SPD values in the final output table_str = table_str.replace(" x", " ")