Skip to content

Commit

Permalink
Merge pull request #169 from cryptosharks131/v1.4.0
Browse files Browse the repository at this point in the history
Co-authored-by: BhhagBoseDK <[email protected]>
Co-authored-by: Bitcoinite <[email protected]>
  • Loading branch information
3 people authored Nov 20, 2022
2 parents 446822a + e6c67e9 commit 57019b9
Show file tree
Hide file tree
Showing 37 changed files with 1,172 additions and 311 deletions.
3 changes: 1 addition & 2 deletions delete_payments.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from lndg import settings
from gui.lnd_deps import lightning_pb2 as ln
from gui.lnd_deps import lightning_pb2_grpc as lnrpc
from gui.lnd_deps.lnd_connect import lnd_connect

def main():
stub = lnrpc.LightningStub(lnd_connect(settings.LND_DIR_PATH, settings.LND_NETWORK, settings.LND_RPC_SERVER))
stub = lnrpc.LightningStub(lnd_connect())
try:
stub.DeleteAllPayments(ln.DeleteAllPaymentsRequest(failed_payments_only=False, failed_htlcs_only=True))
stub.DeleteAllPayments(ln.DeleteAllPaymentsRequest(failed_payments_only=True, failed_htlcs_only=False))
Expand Down
18 changes: 17 additions & 1 deletion gui/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,30 @@ class AutoRebalanceForm(forms.Form):
(7, 'channel_state'),
(8, 'auto_fees'),
(9, 'cltv'),
(10, 'closing_costs'),
(10, 'min_htlc'),
(11, 'max_htlc'),
]

class UpdateChannel(forms.Form):
chan_id = forms.IntegerField(label='chan_id')
target = forms.IntegerField(label='target')
update_target = forms.ChoiceField(label='update_target', choices=updates_channel_codes)

class UpdateClosing(forms.Form):
funding_txid = forms.CharField(label='funding_txid', max_length=64)
funding_index = forms.IntegerField(label='funding_index')
target = forms.IntegerField(label='target')

class UpdateKeysend(forms.Form):
r_hash = forms.CharField(label='r_hash', max_length=64)

class AddAvoid(forms.Form):
pubkey = forms.CharField(label='avoid_pubkey', max_length=66)
notes = forms.CharField(label='avoid_notes', max_length=1000, required=False)

class RemoveAvoid(forms.Form):
pubkey = forms.CharField(label='avoid_pubkey', max_length=66)

class UpdatePending(forms.Form):
funding_txid = forms.CharField(label='funding_txid', max_length=64)
output_index = forms.IntegerField(label='output_index')
Expand Down
9 changes: 5 additions & 4 deletions gui/lnd_deps/lnd_connect.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import os, codecs, grpc
from lndg import settings

def lnd_connect(LND_DIR_PATH, LND_NETWORK, LND_RPC_SERVER):
def lnd_connect():
#Open connection with lnd via grpc
with open(os.path.expanduser(LND_DIR_PATH + '/data/chain/bitcoin/' + LND_NETWORK + '/admin.macaroon'), 'rb') as f:
with open(os.path.expanduser(settings.LND_MACAROON_PATH), 'rb') as f:
macaroon_bytes = f.read()
macaroon = codecs.encode(macaroon_bytes, 'hex')
def metadata_callback(context, callback):
callback([('macaroon', macaroon)], None)
os.environ["GRPC_SSL_CIPHER_SUITES"] = 'HIGH+ECDSA'
cert = open(os.path.expanduser(LND_DIR_PATH + '/tls.cert'), 'rb').read()
cert = open(os.path.expanduser(settings.LND_TLS_PATH), 'rb').read()
cert_creds = grpc.ssl_channel_credentials(cert)
auth_creds = grpc.metadata_call_credentials(metadata_callback)
creds = grpc.composite_channel_credentials(cert_creds, auth_creds)
channel = grpc.secure_channel(LND_RPC_SERVER, creds, options=[('grpc.max_send_message_length', 29999999), ('grpc.max_receive_message_length', 29999999),])
channel = grpc.secure_channel(settings.LND_RPC_SERVER, creds, options=[('grpc.max_send_message_length', 29999999), ('grpc.max_receive_message_length', 29999999),])
return channel

def main():
Expand Down
7 changes: 3 additions & 4 deletions gui/migrations/0021_auto_20220221_1309.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
from gui.lnd_deps import signer_pb2 as lns
from gui.lnd_deps import signer_pb2_grpc as lnsigner
from gui.lnd_deps.lnd_connect import lnd_connect
from lndg import settings

def update_messages(apps, schedma_editor):
invoices = apps.get_model('gui', 'invoices')
try:
messages = invoices.objects.exclude(message=None)
if len(messages) > 0:
stub = lnrpc.LightningStub(lnd_connect(settings.LND_DIR_PATH, settings.LND_NETWORK, settings.LND_RPC_SERVER))
signerstub = lnsigner.SignerStub(lnd_connect(settings.LND_DIR_PATH, settings.LND_NETWORK, settings.LND_RPC_SERVER))
stub = lnrpc.LightningStub(lnd_connect())
signerstub = lnsigner.SignerStub(lnd_connect())
self_pubkey = stub.GetInfo(ln.GetInfoRequest()).identity_pubkey
for message in messages:
records = stub.LookupInvoice(ln.PaymentHash(r_hash=bytes.fromhex(message.r_hash))).htlcs[0].custom_records
Expand Down Expand Up @@ -46,7 +45,7 @@ def update_rebal_channel(apps, schedma_editor):
payments = apps.get_model('gui', 'payments')
hops = apps.get_model('gui', 'paymenthops')
try:
stub = lnrpc.LightningStub(lnd_connect(settings.LND_DIR_PATH, settings.LND_NETWORK, settings.LND_RPC_SERVER))
stub = lnrpc.LightningStub(lnd_connect())
self_pubkey = stub.GetInfo(ln.GetInfoRequest()).identity_pubkey
for payment in payments.objects.filter(status=2).iterator():
last_hop = hops.objects.filter(payment_hash=payment.payment_hash).order_by('-step')[0] if hops.objects.filter(payment_hash=payment.payment_hash).exists() else None
Expand Down
35 changes: 35 additions & 0 deletions gui/migrations/0032_auto_20220913_1035.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 3.2.7 on 2022-09-13 10:35

from django.db import migrations, models

def migrate_close_fees(apps, schedma_editor):
channels = apps.get_model('gui', 'channels')
closures = apps.get_model('gui', 'closures')
close_fees = channels.objects.filter(closing_costs__gt=0)
for close_fee in close_fees:
closure = closures.objects.filter(funding_txid=close_fee.funding_txid, funding_index=close_fee.output_index)[0] if closures.objects.filter(funding_txid=close_fee.funding_txid, funding_index=close_fee.output_index).exists() else None
if closure:
closure.closing_costs = close_fee.closing_costs
closure.save()

def revert_close_fees(apps, schedma_editor):
pass

class Migration(migrations.Migration):

dependencies = [
('gui', '0031_pendingchannels'),
]

operations = [
migrations.AddField(
model_name='closures',
name='closing_costs',
field=models.IntegerField(default=0),
),
migrations.RunPython(migrate_close_fees, revert_close_fees),
migrations.RemoveField(
model_name='channels',
name='closing_costs',
),
]
51 changes: 51 additions & 0 deletions gui/migrations/0033_auto_20220926_1658.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Generated by Django 3.2.7 on 2022-09-27 01:38

from django.db import migrations, models
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
('gui', '0032_auto_20220913_1035'),
]

operations = [
migrations.CreateModel(
name='AvoidNodes',
fields=[
('pubkey', models.CharField(max_length=66, primary_key=True, serialize=False)),
('notes', models.CharField(max_length=1000, null=True)),
('updated', models.DateTimeField(default=django.utils.timezone.now)),
],
),
migrations.AddField(
model_name='channels',
name='local_max_htlc_msat',
field=models.BigIntegerField(default=0),
preserve_default=False,
),
migrations.AddField(
model_name='channels',
name='local_min_htlc_msat',
field=models.BigIntegerField(default=0),
preserve_default=False,
),
migrations.AddField(
model_name='channels',
name='remote_max_htlc_msat',
field=models.BigIntegerField(default=0),
preserve_default=False,
),
migrations.AddField(
model_name='channels',
name='remote_min_htlc_msat',
field=models.BigIntegerField(default=0),
preserve_default=False,
),
migrations.AddField(
model_name='invoices',
name='is_revenue',
field=models.BooleanField(default=False),
),
]
16 changes: 14 additions & 2 deletions gui/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Invoices(models.Model):
sender = models.CharField(null=True, max_length=66)
sender_alias = models.CharField(null=True, max_length=32)
index = models.IntegerField()
is_revenue = models.BooleanField(default=False)
class Meta:
app_label = 'gui'

Expand Down Expand Up @@ -86,10 +87,14 @@ class Channels(models.Model):
local_fee_rate = models.IntegerField()
local_disabled = models.BooleanField()
local_cltv = models.IntegerField()
local_min_htlc_msat = models.BigIntegerField()
local_max_htlc_msat = models.BigIntegerField()
remote_base_fee = models.IntegerField()
remote_fee_rate = models.IntegerField()
remote_disabled = models.BooleanField()
remote_cltv = models.IntegerField()
remote_min_htlc_msat = models.BigIntegerField()
remote_max_htlc_msat = models.BigIntegerField()
is_active = models.BooleanField()
is_open = models.BooleanField()
last_update = models.DateTimeField()
Expand All @@ -100,7 +105,6 @@ class Channels(models.Model):
ar_max_cost = models.IntegerField()
fees_updated = models.DateTimeField(default=timezone.now)
auto_fees = models.BooleanField()
closing_costs = models.IntegerField(default=0)

def save(self, *args, **kwargs):
if self.auto_fees is None:
Expand Down Expand Up @@ -203,6 +207,7 @@ class Closures(models.Model):
open_initiator = models.IntegerField()
close_initiator = models.IntegerField()
resolution_count = models.IntegerField()
closing_costs = models.IntegerField(default=0)
class Meta:
app_label = 'gui'
unique_together = (('funding_txid', 'funding_index'),)
Expand Down Expand Up @@ -279,4 +284,11 @@ class PendingChannels(models.Model):
auto_fees = models.BooleanField(null=True, default=None)
class Meta:
app_label = 'gui'
unique_together = (('funding_txid', 'output_index'),)
unique_together = (('funding_txid', 'output_index'),)

class AvoidNodes(models.Model):
pubkey = models.CharField(max_length=66, primary_key=True)
notes = models.CharField(null=True, max_length=1000)
updated = models.DateTimeField(default=timezone.now)
class Meta:
app_label = 'gui'
Binary file added gui/static/favicon.ico
Binary file not shown.
29 changes: 27 additions & 2 deletions gui/templates/advanced.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@ <h2>Advanced Channel Settings</h2>
<input type="hidden" name="key" value="ALL-CLTV">
</form>
</td>
<th colspan="2"></th>
<td title="Update all channel min HTLCs">
<form action="/update_setting/" method="post">
{% csrf_token %}
<input style="text-align:center;width:100px" id="value" type="number" step="0.001" min="1" name="value" value="">
<input type="hidden" name="key" value="ALL-minHTLC">
</form>
</td>
<th colspan="3"></th>
<td title="Update all channel AR amount amounts">
<form action="/update_setting/" method="post">
{% csrf_token %}
Expand Down Expand Up @@ -79,6 +86,8 @@ <h2>Advanced Channel Settings</h2>
<th>oRate</th>
<th>oBase</th>
<th>oCLTV</th>
<th>minHTLC</th>
<th>maxHTLC</th>
<th>iRate</th>
<th>iBase</th>
<th title="When AR is ENABLED for the channel, the size of the rebalance attempts that should be tried during attempts to refill the channel.">Target Amt</th>
Expand Down Expand Up @@ -133,6 +142,22 @@ <h2>Advanced Channel Settings</h2>
<input type="hidden" name="update_target" value="9">
</form>
</td>
<td {% if channel.local_disabled == True %}style="background-color: #fadbd5"{% elif channel.private == True %}style="background-color: #dbd5fa"{% endif %}>
<form action="/update_channel/" method="post">
{% csrf_token %}
<input style="text-align:center;width:100px" id="target" type="number" step="0.001" min="1" name="target" value="{{ channel.local_min_htlc }}">
<input type="hidden" name="chan_id" value="{{ channel.chan_id }}">
<input type="hidden" name="update_target" value="10">
</form>
</td>
<td {% if channel.local_disabled == True %}style="background-color: #fadbd5"{% elif channel.private == True %}style="background-color: #dbd5fa"{% endif %}>
<form action="/update_channel/" method="post">
{% csrf_token %}
<input style="text-align:center;width:150px" id="target" type="number" step="0.001" min="1" name="target" value="{{ channel.local_max_htlc }}">
<input type="hidden" name="chan_id" value="{{ channel.chan_id }}">
<input type="hidden" name="update_target" value="11">
</form>
</td>
<td title="Fee Ratio: {{ channel.fee_ratio }}%" {% if channel.remote_disabled == True %}style="background-color: #fadbd5"{% endif %}>{{ channel.remote_fee_rate|intcomma }}</td>
<td {% if channel.remote_disabled == True %}style="background-color: #fadbd5"{% endif %}>{{ channel.remote_base_fee|intcomma }}</td>
<td>
Expand Down Expand Up @@ -204,7 +229,7 @@ <h2>Update Local Settings</h2>
{% csrf_token %}
{% if settings.key == 'AR-Target%' %}
<input style="text-align:center" id="value" type="number" step="0.1" min="0.1" max="100" name="value" value="{{ settings.value }}">
{% elif settings.key|slice:"-1:" == '%' or settings.key == 'AR-Variance' or settings.key == 'AF-Increment' or settings.key == 'AF-Multiplier' or settings.key == 'AF-FailedHTLCs' or settings.key == 'AR-WaitPeriod' or settings.key == 'AR-APDays' %}
{% elif settings.key|slice:"-1:" == '%' or settings.key == 'AR-Variance' or settings.key == 'AF-Increment' or settings.key == 'AF-Multiplier' or settings.key == 'AF-FailedHTLCs' or settings.key == 'AR-WaitPeriod' or settings.key == 'AR-APDays' or settings.key == 'AF-UpdateHours' %}
<input style="text-align:center" id="value" type="number" min="1" max="100" name="value" value="{{ settings.value }}">
{% elif settings.key == 'AR-Time' %}
<input style="text-align:center" id="value" type="number" min="1" max="60" name="value" value="{{ settings.value }}">
Expand Down
8 changes: 4 additions & 4 deletions gui/templates/autofees.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% load humanize %}
{% if autofees %}
<div class="w3-container w3-padding-small">
<h2>Autofees Logs</h2>
<h2><a href="/autofees/">Our Fees Logs</a></h2>
<table class="w3-table-all w3-centered w3-hoverable">
<tr>
<th>Timestamp</th>
Expand All @@ -18,7 +18,7 @@ <h2>Autofees Logs</h2>
<tr>
<td title="{{ log.timestamp }}">{{ log.timestamp|naturaltime }}</td>
<td><a href="/channel?={{ log.chan_id }}" target="_blank">{{ log.chan_id }}</a></td>
<td>{% if log.peer_alias == '' %}---{% else %}{{ log.peer_alias }}{% endif %}</td>
<td><a href="/autofees?={{ log.chan_id }}" target="_blank">{% if log.peer_alias == '' %}---{% else %}{{ log.peer_alias }}{% endif %}</a></td>
<td>{{ log.setting }}</td>
<td>{{ log.old_value }}</td>
<td {% if log.new_value > log.old_value %}style="background-color: #d5fadb"{% else %}style="background-color: #fadbd5"{% endif %}>{{ log.new_value }}</td>
Expand All @@ -29,8 +29,8 @@ <h2>Autofees Logs</h2>
{% endif %}
{% if not autofees %}
<div class="w3-container w3-padding-small">
<center><h1>No autofees logs to see here yet!</h1></center>
<center><h1>No our fees logs to see here yet!</h1></center>
<center><h6>Experimental. This will allow LNDg to automatically act upon the suggestions found <a href="/fees" target="_blank">here</a>.</h6></center>
</div>
{% endif %}
{% endblock %}
{% endblock %}
6 changes: 3 additions & 3 deletions gui/templates/autopilot.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{% load humanize %}
{% if autopilot %}
<div class="w3-container w3-padding-small">
<h2>Autopilot Logs</h2>
<h2><a href="/autopilot/">Autopilot Logs</a></h2>
<table class="w3-table-all w3-centered w3-hoverable">
<tr>
<th>Timestamp</th>
Expand All @@ -18,7 +18,7 @@ <h2>Autopilot Logs</h2>
<tr>
<td title="{{ log.timestamp }}">{{ log.timestamp|naturaltime }}</td>
<td><a href="/channel?={{ log.chan_id }}" target="_blank">{{ log.chan_id }}</a></td>
<td>{% if log.peer_alias == '' %}---{% else %}{{ log.peer_alias }}{% endif %}</td>
<td><a href="/autopilot?={{ log.chan_id }}" target="_blank">{% if log.peer_alias == '' %}---{% else %}{{ log.peer_alias }}{% endif %}</a></td>
<td>{{ log.setting }}</td>
<td>{{ log.old_value }}</td>
<td {% if log.new_value == 1 %}style="background-color: #d5fadb"{% else %}style="background-color: #fadbd5"{% endif %}>{{ log.new_value }}</td>
Expand All @@ -33,4 +33,4 @@ <h2>Autopilot Logs</h2>
<center><h6>Experimental. This will allow LNDg to automatically act upon the suggestions found <a href="/actions" target="_blank">here</a>.</h6></center>
</div>
{% endif %}
{% endblock %}
{% endblock %}
3 changes: 2 additions & 1 deletion gui/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
</style>
<head>
<meta charset="utf-8">
{% block meta %}{% endblock %}
<title>{% block title %}LNDg{% endblock %}</title>
{% load static %}
{% load qr_code %}
Expand All @@ -28,7 +29,7 @@ <h1><a href="/">My Lnd Overview</a></h1>
<footer>
<div id="footer">
<div class="w3-container w3-padding-small">
<center>LNDg v1.3.1</center>
<center>LNDg v1.4.0</center>
</div>
</div>
</footer>
Expand Down
Loading

0 comments on commit 57019b9

Please sign in to comment.