Skip to content

Commit

Permalink
Suggested open list (cryptosharks131#7)
Browse files Browse the repository at this point in the history
Add link to page with a suggested open list based on payments your node has sent through the network
  • Loading branch information
cryptosharks131 authored Dec 25, 2021
1 parent d7e84f7 commit adc22dd
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 16 deletions.
11 changes: 6 additions & 5 deletions gui/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ <h4>Wallet Balance: {{ balances.total_balance|intcomma }} | Confirmed Wallet Bal
</form>
</div>
<div class="w3-container w3-padding-small">
<h4>Completed Payments: {{ total_payments }} | Sats Sent: {{ total_sent|intcomma }} | Fees Paid: {{ fees_paid|intcomma }}</h4>
<h4>Completed Payments: {{ total_payments }} | Sats Sent: {{ total_sent|intcomma }} | Fees Paid: {{ fees_paid|intcomma }} [{{ payments_ppm|intcomma }}]</h4>
<h4>Paid Invoices: {{ total_invoices }} | Sats Received: {{ total_received|intcomma }}</h4>
<h4>Lifetime Routed: {{ total_forwards|intcomma }} | Value: {{ total_value_forwards|intcomma }} | Fees Earned: {{ earned|intcomma }} | Onchain Fees: {{ onchain_costs|intcomma }} | Percent Cost: {{ percent_cost }}%</h4>
<h4>7-Day Routed: {{ routed_7day|intcomma }} | Value: {{ routed_7day_amt|intcomma }} | Fees Earned: {{ earned_7day|intcomma }} | Onchain Fees: {{ onchain_costs_7day|intcomma }} | Offchain Fees: {{ total_7day_fees|intcomma }} | Percent Cost: {{ percent_cost_7day }}% | Profit/Outbound: {{ profit_per_outbound|intcomma }} [{{ profit_per_outbound_real|intcomma }}] | Outbound Utilization: {{ routed_7day_percent }}%</h4>
<h4>Lifetime Routed: {{ total_forwards|intcomma }} | Value: {{ total_value_forwards|intcomma }} | Fees Earned: {{ earned|intcomma }} [{{ routed_ppm|intcomma }}] | Onchain Fees: {{ onchain_costs|intcomma }} | Percent Cost: {{ percent_cost }}%</h4>
<h4>7-Day Routed: {{ routed_7day|intcomma }} | Value: {{ routed_7day_amt|intcomma }} | Fees Earned: {{ earned_7day|intcomma }} [{{ 7day_routed_ppm|intcomma }}] | Onchain Fees: {{ onchain_costs_7day|intcomma }} | Offchain Fees: {{ total_7day_fees|intcomma }} [{{ 7day_payments_ppm|intcomma }}] | Percent Cost: {{ percent_cost_7day }}% | Profit/Outbound: {{ profit_per_outbound|intcomma }} [{{ profit_per_outbound_real|intcomma }}] | Outbound Utilization: {{ routed_7day_percent }}%</h4>
</div>
<div class="w3-container w3-padding-small">
<h4>Inbound Liquidity: {{ inbound|intcomma }} | Outbound Liquidity: {{ outbound|intcomma }}</h4>
<h4>Inbound Liquidity: {{ inbound|intcomma }} | Outbound Liquidity: {{ outbound|intcomma }} | Liquidity Ratio: {{ liq_ratio }}%</h4>
<h4>Balance In Limbo: {{ limbo_balance|intcomma }} | Unsettled Liquidity: {{ unsettled|intcomma }} | <a href="/pending_htlcs" target="_blank">Pending HTLCs</a>: {{ pending_htlc_count }}</h4>
<h4><a href="/suggested_opens" target="_blank">Suggested New Peers</a></h4>
</div>
{% if active_channels %}
<div class="w3-container w3-padding-small">
Expand Down Expand Up @@ -402,7 +403,7 @@ <h2>Last 10 Failed HTLCs</h2>
<td>{{ failed_htlc.amount|intcomma }}</td>
<td>{{ failed_htlc.missed_fee|intcomma }}</td>
<td>{% if failed_htlc.wire_failure == 15 %}Temporary Channel Failure{% elif failed_htlc.wire_failure == 18 %}Unknown Next Peer{% elif failed_htlc.wire_failure == 12 %}Fee Insufficient{% else %}{{ failed_htlc.wire_failure }}{% endif %}</td>
<td>{% if failed_htlc.failure_detail == 1 %}---{% elif failed_htlc.failure_detail == 5 %}HTLC Exceeds Max{% elif failed_htlc.failure_detail == 6 %}Insufficient Balance{% elif failed_htlc.failure_detail == 20 %}Invalid Keysend{% else %}{{ failed_htlc.failure_detail }}{% endif %}</td>
<td>{% if failed_htlc.failure_detail == 1 %}---{% elif failed_htlc.failure_detail == 5 %}HTLC Exceeds Max{% elif failed_htlc.failure_detail == 6 %}Insufficient Balance{% elif failed_htlc.failure_detail == 20 %}Invalid Keysend{% elif failed_htlc.failure_detail == 22 %}Circular Route{% else %}{{ failed_htlc.failure_detail }}{% endif %}</td>
</tr>
{% endfor %}
</table>
Expand Down
31 changes: 31 additions & 0 deletions gui/templates/open_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{% extends "base.html" %}
{% block content %}
{% load humanize %}
{% if open_list %}
<div class="w3-container w3-padding-small">
<h2>Suggested Open List</h2>
<table class="w3-table-all w3-centered w3-hoverable">
<tr>
<th>Node Pubkey</th>
<th width=15%>Node Alias</th>
<th width=15%>Successful Payments Routed</th>
<th width=12%>Amount Routed</th>
<th width=12%>Fees Paid</th>
<th width=12%>Effective PPM</th>
<th width=12%>Volume Score</th>
</tr>
{% for node in open_list %}
<tr>
<td>{{ node.node_pubkey }}</td>
<td>{{ node.alias }}</td>
<td>{{ node.count }}</td>
<td>{{ node.amount|add:"0"|intcomma }}</td>
<td>{{ node.fees|add:"0"|intcomma }}</td>
<td>{{ node.ppm|add:"0"|intcomma }}</td>
<td>{{ node.score }}</td>
</tr>
{% endfor %}
</table>
</div>
{% endif %}
{% endblock %}
1 change: 1 addition & 0 deletions gui/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
path('updatechanpolicy/', views.update_chan_policy, name='updatechanpolicy'),
path('autorebalance/', views.auto_rebalance, name='auto-rebalance'),
path('ar_target/', views.ar_target, name='ar-target'),
path('suggested_opens/', views.suggested_opens, name='suggested-opens'),
path('api/', include(router.urls), name='api-root'),
path('api/connectpeer/', views.connect_peer, name='connect-peer'),
path('api/openchannel/', views.open_channel, name='open-channel'),
Expand Down
42 changes: 31 additions & 11 deletions gui/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import messages
from django.shortcuts import get_object_or_404, render, redirect
from django.db.models import Sum, IntegerField
from django.db.models import Sum, IntegerField, Count
from django.db.models.functions import Round
from django.conf import settings
from datetime import datetime, timedelta
Expand Down Expand Up @@ -52,8 +52,9 @@ def home(request):
routed_7day = forwards.filter(forward_date__gte=filter_7day).count()
routed_7day_amt = 0 if routed_7day == 0 else int(forwards.filter(forward_date__gte=filter_7day).aggregate(Sum('amt_out_msat'))['amt_out_msat__sum']/1000)
total_earned_7day = 0 if routed_7day == 0 else forwards.filter(forward_date__gte=filter_7day).aggregate(Sum('fee'))['fee__sum']
payments_7day = payments.filter(status=2).filter(creation_date__gte=filter_7day).count()
total_7day_fees = 0 if payments_7day == 0 else payments.filter(creation_date__gte=filter_7day).aggregate(Sum('fee'))['fee__sum']
payments_7day = payments.filter(status=2).filter(creation_date__gte=filter_7day)
payments_7day_amt = 0 if payments_7day.count() == 0 else payments_7day.aggregate(Sum('value'))['value__sum']
total_7day_fees = 0 if payments_7day.count() == 0 else payments_7day.aggregate(Sum('fee'))['fee__sum']
pending_htlcs = PendingHTLCs.objects.all()
pending_htlc_count = pending_htlcs.count()
pending_outbound = 0 if pending_htlcs.filter(incoming=False).count() == 0 else pending_htlcs.filter(incoming=False).aggregate(Sum('amount'))['amount__sum']
Expand Down Expand Up @@ -106,26 +107,26 @@ def home(request):
'balances': balances,
'payments': payments[:6],
'total_sent': int(total_sent),
'fees_paid': round(total_fees, 1),
'fees_paid': int(total_fees),
'total_payments': total_payments,
'invoices': invoices[:6],
'total_received': total_received,
'total_invoices': total_invoices,
'forwards': forwards[:15],
'earned': round(total_earned, 1),
'earned': int(total_earned),
'total_forwards': total_forwards,
'total_value_forwards': total_value_forwards,
'routed_7day': routed_7day,
'routed_7day_amt': routed_7day_amt,
'earned_7day': round(total_earned_7day, 1),
'earned_7day': int(total_earned_7day),
'routed_7day_percent': 0 if sum_outbound == 0 else int((routed_7day_amt/sum_outbound)*100),
'profit_per_outbound': 0 if sum_outbound == 0 else int((total_earned_7day - total_7day_fees) / (sum_outbound / 1000000)),
'profit_per_outbound_real': 0 if sum_outbound == 0 else int((total_earned_7day - total_costs_7day) / (sum_outbound / 1000000)),
'profit_per_outbound': 0 if sum_outbound == 0 else int((total_earned_7day - total_7day_fees)/(sum_outbound/1000000)),
'profit_per_outbound_real': 0 if sum_outbound == 0 else int((total_earned_7day - total_costs_7day)/(sum_outbound/1000000)),
'percent_cost': 0 if total_earned == 0 else int((total_costs/total_earned)*100),
'percent_cost_7day': 0 if total_earned_7day == 0 else int((total_costs_7day/total_earned_7day)*100),
'onchain_costs': onchain_costs,
'onchain_costs_7day': onchain_costs_7day,
'total_7day_fees': round(total_7day_fees, 1),
'total_7day_fees': int(total_7day_fees),
'active_channels': detailed_active_channels,
'capacity': total_capacity,
'inbound': total_inbound,
Expand All @@ -142,7 +143,12 @@ def home(request):
'chan_policy_form': ChanPolicyForm,
'local_settings': local_settings,
'pending_htlc_count': pending_htlc_count,
'failed_htlcs': FailedHTLCs.objects.all().order_by('-timestamp')[:10]
'failed_htlcs': FailedHTLCs.objects.all().order_by('-timestamp')[:10],
'payments_ppm': 0 if total_sent == 0 else int((total_fees/total_sent)*1000000),
'routed_ppm': 0 if total_value_forwards == 0 else int((total_earned/total_value_forwards)*1000000),
'7day_routed_ppm': 0 if routed_7day_amt == 0 else int((total_earned_7day/routed_7day_amt)*1000000),
'7day_payments_ppm': 0 if payments_7day_amt == 0 else int((total_7day_fees/payments_7day_amt)*1000000),
'liq_ratio': 0 if total_outbound == 0 else int((total_inbound/sum_outbound)*100)
}
return render(request, 'home.html', context)
else:
Expand All @@ -161,7 +167,6 @@ def route(request):

def peers(request):
if request.method == 'GET':
stub = lnrpc.LightningStub(lnd_connect(settings.LND_DIR_PATH, settings.LND_NETWORK, settings.LND_RPC_SERVER))
context = {
'peers': Peers.objects.filter(connected=True)
}
Expand All @@ -180,6 +185,21 @@ def balances(request):
else:
return redirect('home')

def suggested_opens(request):
if request.method == 'GET':
stub = lnrpc.LightningStub(lnd_connect(settings.LND_DIR_PATH, settings.LND_NETWORK, settings.LND_RPC_SERVER))
self_pubkey = stub.GetInfo(ln.GetInfoRequest()).identity_pubkey
current_peers = Channels.objects.filter(is_open=True).values_list('remote_pubkey')
filter_60day = datetime.now() - timedelta(days=60)
payments_60day = Payments.objects.filter(creation_date__gte=filter_60day).values_list('payment_hash')
open_list = PaymentHops.objects.filter(payment_hash__in=payments_60day).exclude(node_pubkey=self_pubkey).exclude(node_pubkey__in=current_peers).values('node_pubkey', 'alias').annotate(ppm=(Sum('fee')/Sum('amt'))*1000000).annotate(score=Round((Round(Count('id')/5, output_field=IntegerField())+Round(Sum('amt')/500000, output_field=IntegerField()))/10, output_field=IntegerField())).annotate(count=Count('id')).annotate(amount=Sum('amt')).annotate(fees=Sum('fee')).order_by('-score', 'ppm')[:21]
context = {
'open_list': open_list
}
return render(request, 'open_list.html', context)
else:
return redirect('home')

def pending_htlcs(request):
if request.method == 'GET':
context = {
Expand Down

0 comments on commit adc22dd

Please sign in to comment.