From 4526f464b19b78ce11261f0bf06dd69d9084ca3a Mon Sep 17 00:00:00 2001 From: Carsten Otto Date: Thu, 29 Jul 2021 16:44:25 +0200 Subject: [PATCH] cleanup --- README.md | 57 ++++++++++++++++++++++++++++++++-------------------- rebalance.py | 24 +++++++++++++--------- 2 files changed, 49 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 9ed3e49..b939805 100644 --- a/README.md +++ b/README.md @@ -239,8 +239,9 @@ Please make sure to set realistic fee rates, which at best are already known to ### Command line arguments ``` -usage: rebalance.py [-h] [--lnddir LNDDIR] [--grpc GRPC] [-l] [--show-all | --show-only CHANNEL] [-o | -i] [-f CHANNEL] [-t CHANNEL] [-a AMOUNT | -p PERCENTAGE] - [--min-amount MIN_AMOUNT] [--min-local MIN_LOCAL] [--min-remote MIN_REMOTE] [-e EXCLUDE] [--reckless] +usage: rebalance.py [-h] [--lnddir LNDDIR] [--grpc GRPC] [-l] [--show-all | --show-only CHANNEL | -c] [-o | -i] + [-f CHANNEL] [-t CHANNEL] [-a AMOUNT | -p PERCENTAGE] [--min-amount MIN_AMOUNT] + [--min-local MIN_LOCAL] [--min-remote MIN_REMOTE] [-e EXCLUDE] [--reckless] [--fee-factor FEE_FACTOR | --fee-limit FEE_LIMIT | --fee-ppm-limit FEE_PPM_LIMIT] optional arguments: @@ -254,8 +255,9 @@ list candidates: -l, --list-candidates list candidate channels for rebalance --show-all also show channels with zero rebalance amount - --show-only SHOW_ONLY - only show information about the given channel + --show-only CHANNEL only show information about the given channel + -c, --compact Shows a compact list of all channels, one per line including ID, inbound/outbound + liquidity, and alias -o, --outgoing lists channels with less than 1,500,00 satoshis inbound liquidity -i, --incoming (default) lists channels with less than 1,500,00 satoshis outbound liquidity @@ -263,34 +265,45 @@ rebalance: Rebalance a channel. You need to specify at least the 'from' channel (-f) or the 'to' channel (-t). -f CHANNEL, --from CHANNEL - Channel ID of the outgoing channel (funds will be taken from this channel). You may also specify the ID using the colon notation (12345:12:1), or the x - notation (12345x12x1). You may also use -1 to choose a random candidate. + Channel ID of the outgoing channel (funds will be taken from this channel). You may also + specify the ID using the colon notation (12345:12:1), or the x notation (12345x12x1). + You may also use -1 to choose a random candidate. -t CHANNEL, --to CHANNEL - Channel ID of the incoming channel (funds will be sent to this channel). You may also specify the ID using the colon notation (12345:12:1), or the x - notation (12345x12x1). You may also use -1 to choose a random candidate. + Channel ID of the incoming channel (funds will be sent to this channel). You may also + specify the ID using the colon notation (12345:12:1), or the x notation (12345x12x1). + You may also use -1 to choose a random candidate. -a AMOUNT, --amount AMOUNT - Amount of the rebalance, in satoshis. If not specified, the amount computed for a perfect rebalance will be used (up to the maximum of 4,294,967 - satoshis) + Amount of the rebalance, in satoshis. If not specified, the amount computed for a + perfect rebalance will be used (up to the maximum of 4,294,967 satoshis) -p PERCENTAGE, --percentage PERCENTAGE - Set the amount to a percentage of the computed amount. As an example, if this is set to 50, half of the computed amount will be used. See --amount. + Set the amount to a percentage of the computed amount. As an example, if this is set to + 50, half of the computed amount will be used. See --amount. --min-amount MIN_AMOUNT - (Default: 10,000) If the given or computed rebalance amount is below this limit, nothing is done. + (Default: 10,000) If the given or computed rebalance amount is below this limit, nothing + is done. --min-local MIN_LOCAL - (Default: 1,000,000) Ensure that the channels have at least this amount as outbound liquidity. + (Default: 1,000,000) Ensure that the channels have at least this amount as outbound + liquidity. --min-remote MIN_REMOTE - (Default: 1,000,000) Ensure that the channels have at least this amount as inbound liquidity. + (Default: 1,000,000) Ensure that the channels have at least this amount as inbound + liquidity. -e EXCLUDE, --exclude EXCLUDE - Exclude the given channel ID as the outgoing channel (no funds will be taken out of excluded channels) - --reckless Allow rebalance transactions that are not economically viable. You might also want to set --min-local 0 and --min-local 0. If set, you also need to set - --amount and either --fee-limit or --fee-ppm-limit. + Exclude the given channel ID as the outgoing channel (no funds will be taken out of + excluded channels) + --reckless Allow rebalance transactions that are not economically viable. You might also want to + set --min-local 0 and --min-local 0. If set, you also need to set --amount and either + --fee-limit or --fee-ppm-limit. --fee-factor FEE_FACTOR - (default: 1.0) Compare the costs against the expected income, scaled by this factor. As an example, with --fee-factor 1.5, routes that cost at most - 150% of the expected earnings are tried. Use values smaller than 1.0 to restrict routes to only consider those earning more/costing less. This factor - is ignored with --reckless. + (default: 1.0) Compare the costs against the expected income, scaled by this factor. As + an example, with --fee-factor 1.5, routes that cost at most 150% of the expected + earnings are tried. Use values smaller than 1.0 to restrict routes to only consider + those earning more/costing less. This factor is ignored with --reckless. --fee-limit FEE_LIMIT - If set, only consider rebalance transactions that cost up to the given number of satoshis. + If set, only consider rebalance transactions that cost up to the given number of + satoshis. --fee-ppm-limit FEE_PPM_LIMIT - If set, only consider rebalance transactions that cost up to the given number of satoshis per 1M satoshis sent. + If set, only consider rebalance transactions that cost up to the given number of + satoshis per 1M satoshis sent. ``` ## Contributing diff --git a/rebalance.py b/rebalance.py index a1ae413..d555444 100755 --- a/rebalance.py +++ b/rebalance.py @@ -185,7 +185,11 @@ def list_channels_compact(self): reverse=False ) for candidate in candidates: - print(f"{format_boring_string(candidate.chan_id)} | {format_amount_green(get_local_available(candidate), 11)} | {format_amount(get_remote_available(candidate), 11)} | {format_alias(self.lnd.get_node_alias(candidate.remote_pubkey))}") + id_formatted = format_boring_string(candidate.chan_id) + local_formatted = format_amount_green(get_local_available(candidate), 11) + remote_formatted = format_amount(get_remote_available(candidate), 11) + alias_formatted = format_alias(self.lnd.get_node_alias(candidate.remote_pubkey)) + print(f"{id_formatted} | {local_formatted} | {remote_formatted} | {alias_formatted}") def start(self): if self.arguments.list_candidates and self.arguments.show_only: @@ -194,7 +198,7 @@ def start(self): self.show_channel(channel) sys.exit(0) - if self.arguments.listchannelscompact: + if self.arguments.listcompact: self.list_channels_compact() sys.exit(0) @@ -296,7 +300,7 @@ def main(): first_hop_channel_id = vars(arguments)["from"] last_hop_channel_id = arguments.to - if not arguments.listchannelscompact and not arguments.list_candidates and last_hop_channel_id is None and first_hop_channel_id is None: + if not arguments.listcompact and not arguments.list_candidates and last_hop_channel_id is None and first_hop_channel_id is None: argument_parser.print_help() sys.exit(1) @@ -317,13 +321,6 @@ def get_argument_parser(): dest="grpc", help="(default localhost:10009) lnd gRPC endpoint", ) - parser.add_argument( - "-cl", - "--compact-list", - action="store_true", - dest="listchannelscompact", - help="Shows a compact list of all channels, one per line including id, inbound/outbound liquidity and alias", - ) list_group = parser.add_argument_group( "list candidates", "Show the unbalanced channels." ) @@ -347,6 +344,13 @@ def get_argument_parser(): metavar="CHANNEL", help="only show information about the given channel", ) + show_options.add_argument( + "-c", + "--compact", + action="store_true", + dest="listcompact", + help="Shows a compact list of all channels, one per line including ID, inbound/outbound liquidity, and alias", + ) direction_group = list_group.add_mutually_exclusive_group() direction_group.add_argument(