Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#124 Show inflight htlc route #125

Merged
merged 3 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gui/templates/channel.html
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ <h2>Last 5 <a href="/payments" target="_blank">Payments Sent</a></h2>
{% for payment in payments %}
<tr>
<td title="{{ payment.creation_date }}">{{ payment.creation_date|naturaltime }}</td>
<td>{{ payment.payment_hash }}</td>
<td><a href="/route?={{ payment.payment_hash }}" target="_blank">{{ payment.payment_hash }}</td>
<td>{{ payment.value|add:"0"|intcomma }}</td>
<td>{{ payment.fee|intcomma }}</td>
<td>{{ payment.ppm|intcomma }}</td>
Expand Down Expand Up @@ -313,7 +313,7 @@ <h2>Last 5 <a href="/invoices" target="_blank">Payments Received</a></h2>
<tr>
<td title="{{ invoice.creation_date }}">{{ invoice.creation_date|naturaltime }}</td>
<td title="{{ invoice.settle_date }}">{% if invoice.state == 1 %}{{ invoice.settle_date|naturaltime }}{% else %}---{% endif %}</td>
<td>{{ invoice.r_hash }}</td>
<td><a href="/route?={{ invoice.r_hash }}" target="_blank">{{ invoice.r_hash }}</td>
<td>{{ invoice.value|add:"0"|intcomma }}</td>
<td>{% if invoice.state == 1 %}{{ invoice.amt_paid|intcomma }}{% else %}---{% endif %}</td>
<td>{% if invoice.state == 0 %}Open{% elif invoice.state == 1 %}Settled{% elif invoice.state == 2 %}Canceled{% else %}{{ invoice.state }}{% endif %}</td>
Expand Down
4 changes: 2 additions & 2 deletions gui/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ <h2>Last 5 <a href="/payments" target="_blank">Payments Sent</a></h2>
{% for payment in payments %}
<tr>
<td title="{{ payment.creation_date }}">{{ payment.creation_date|naturaltime }}</td>
<td>{{ payment.payment_hash }}</td>
<td><a href="/route?={{ payment.payment_hash }}" target="_blank">{{ payment.payment_hash }}</a></td>
<td>{{ payment.value|add:"0"|intcomma }}</td>
<td>{{ payment.fee|intcomma }}</td>
<td>{{ payment.ppm|intcomma }}</td>
Expand Down Expand Up @@ -524,7 +524,7 @@ <h2>Last 5 <a href="/invoices" target="_blank">Payments Received</a></h2>
<tr>
<td title="{{ invoice.creation_date }}">{{ invoice.creation_date|naturaltime }}</td>
<td title="{{ invoice.settle_date }}">{% if invoice.state == 1 %}{{ invoice.settle_date|naturaltime }}{% else %}---{% endif %}</td>
<td>{{ invoice.r_hash }}</td>
<td><a href="/route?={{ invoice.r_hash }}" target="_blank">{{ invoice.r_hash }}</td>
<td>{{ invoice.value|add:"0"|intcomma }}</td>
<td>{% if invoice.state == 1 %}{{ invoice.amt_paid|intcomma }}{% else %}---{% endif %}</td>
<td>{% if invoice.state == 0 %}Open{% elif invoice.state == 1 %}Settled{% elif invoice.state == 2 %}Canceled{% else %}{{ invoice.state }}{% endif %}</td>
Expand Down
2 changes: 1 addition & 1 deletion gui/templates/invoices.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h2>Last 150 Invoices</h2>
<tr>
<td title="{{ invoice.creation_date }}">{{ invoice.creation_date|naturaltime }}</td>
<td title="{{ invoice.settle_date }}">{% if invoice.state == 1 %}{{ invoice.settle_date|naturaltime }}{% else %}---{% endif %}</td>
<td>{{ invoice.r_hash }}</td>
<td><a href="/route?={{ invoice.r_hash }}" target="_blank">{{ invoice.r_hash }}</td>
<td>{{ invoice.value|add:"0"|intcomma }}</td>
<td>{% if invoice.state == 1 %}{{ invoice.amt_paid|intcomma }}{% else %}---{% endif %}</td>
<td>{% if invoice.state == 0 %}Open{% elif invoice.state == 1 %}Settled{% elif invoice.state == 2 %}Canceled{% else %}{{ invoice.state }}{% endif %}</td>
Expand Down
2 changes: 1 addition & 1 deletion gui/templates/payments.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h2>Last 150 Payments</h2>
{% for payment in payments %}
<tr>
<td title="{{ payment.creation_date }}">{{ payment.creation_date|naturaltime }}</td>
<td>{{ payment.payment_hash }}</td>
<td><a href="/route?={{ payment.payment_hash }}" target="_blank">{{ payment.payment_hash }}</td>
<td>{{ payment.value|add:"0"|intcomma }}</td>
<td>{{ payment.fee|intcomma }}</td>
<td>{{ payment.ppm|intcomma }}</td>
Expand Down
4 changes: 2 additions & 2 deletions gui/templates/pending_htlcs.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h2>Outgoing HTLCs</h2>
<td>{% if htlc.forwarding_alias == '' %}---{% else %}{{ htlc.forwarding_alias }}{% endif %}</td>
<td>{{ htlc.amount|intcomma }}</td>
<td title="{{ htlc.blocks_til_expiration|intcomma }} blocks to {{ htlc.expiration_height|intcomma }}">{{ htlc.hours_til_expiration }} hours</td>
<td>{{ htlc.hash_lock }}</td>
<td><a href="/route?={{ htlc.hash_lock }}" target="_blank">{{ htlc.hash_lock }}</a></td>
</tr>
{% endfor %}
</table>
Expand All @@ -50,7 +50,7 @@ <h2>Incoming HTLCs</h2>
<td>{% if htlc.forwarding_alias == '' %}---{% else %}{{ htlc.forwarding_alias }}{% endif %}</td>
<td>{{ htlc.amount|intcomma }}</td>
<td title="{{ htlc.blocks_til_expiration|intcomma }} blocks to {{ htlc.expiration_height|intcomma }}">{{ htlc.hours_til_expiration }} hours</td>
<td>{{ htlc.hash_lock }}</td>
<td><a href="/route?={{ htlc.hash_lock }}" target="_blank">{{ htlc.hash_lock }}</a></td>
</tr>
{% endfor %}
</table>
Expand Down
11 changes: 9 additions & 2 deletions gui/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,14 @@ def channel(request):
'graph_links': graph_links(),
'network_links': network_links()
}
return render(request, 'channel.html', context)
try:
return render(request, 'channel.html', context)
except Exception as e:
try:
error = str(e.code())
except:
error = str(e)
return render(request, 'error.html', {'error': error})
else:
return redirect('home')

Expand Down Expand Up @@ -1369,7 +1376,7 @@ def failed_htlcs(request):
def payments(request):
if request.method == 'GET':
context = {
'payments': Payments.objects.filter(status=2).annotate(ppm=Round((Sum('fee')*1000000)/Sum('value'), output_field=IntegerField())).order_by('-creation_date')[:150],
'payments': Payments.objects.exclude(status=3).annotate(ppm=Round((Sum('fee')*1000000)/Sum('value'), output_field=IntegerField())).order_by('-creation_date')[:150],
}
return render(request, 'payments.html', context)
else:
Expand Down
11 changes: 6 additions & 5 deletions jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def update_payments(stub):
inflight_payments = Payments.objects.filter(status=1).order_by('index')
for payment in inflight_payments:
payment_data = stub.ListPayments(ln.ListPaymentsRequest(include_incomplete=True, index_offset=payment.index-1, max_payments=1)).payments
if len(payment_data) > 0 and payment.payment_hash == payment_data[0].payment_hash:
#Ignore inflight payments before 30 days
if len(payment_data) > 0 and payment.payment_hash == payment_data[0].payment_hash and payment.creation_date > (datetime.now() - timedelta(days=30)):
update_payment(stub, payment_data[0], self_pubkey)
else:
payment.status = 3
Expand All @@ -31,9 +32,9 @@ def update_payments(stub):
try:
new_payment = Payments(creation_date=datetime.fromtimestamp(payment.creation_date), payment_hash=payment.payment_hash, value=round(payment.value_msat/1000, 3), fee=round(payment.fee_msat/1000, 3), status=payment.status, index=payment.payment_index)
new_payment.save()
if payment.status == 2:
if payment.status == 2 or payment.status == 1:
for attempt in payment.htlcs:
if attempt.status == 1:
if attempt.status == 1 or attempt.status == 0:
hops = attempt.route.hops
hop_count = 0
cost_to = 0
Expand Down Expand Up @@ -74,10 +75,10 @@ def update_payment(stub, payment, self_pubkey):
db_payment.status = payment.status
db_payment.index = payment.payment_index
db_payment.save()
if payment.status == 2:
if payment.status == 2 or payment.status == 1:
PaymentHops.objects.filter(payment_hash=db_payment).delete()
for attempt in payment.htlcs:
if attempt.status == 1:
if attempt.status == 1 or attempt.status == 0:
hops = attempt.route.hops
hop_count = 0
cost_to = 0
Expand Down