Improve LND restart status

This commit is contained in:
Taylor Helsper 2021-04-30 23:39:58 -05:00
parent bbcedb2c0a
commit 384a4c8af2
4 changed files with 121 additions and 92 deletions

View File

@ -29,6 +29,7 @@ lightning_payments = None
lightning_invoices = None lightning_invoices = None
lightning_watchtower_server_info = None lightning_watchtower_server_info = None
lightning_desync_count = 0 lightning_desync_count = 0
lightning_update_count = 0
LND_FOLDER = "/mnt/hdd/mynode/lnd/" LND_FOLDER = "/mnt/hdd/mynode/lnd/"
TLS_CERT_FILE = "/mnt/hdd/mynode/lnd/tls.cert" TLS_CERT_FILE = "/mnt/hdd/mynode/lnd/tls.cert"
@ -46,10 +47,17 @@ def update_lightning_info():
global lightning_invoices global lightning_invoices
global lightning_watchtower_server_info global lightning_watchtower_server_info
global lightning_desync_count global lightning_desync_count
global lightning_update_count
global lnd_ready global lnd_ready
# Check logged in
#while not is_lnd_logged_in():
# lnd_ready = False
# time.sleep(10)
# Get latest LN info # Get latest LN info
lightning_info = lnd_get("/getinfo") lightning_info = lnd_get("/getinfo")
lightning_update_count = lightning_update_count + 1
# Set is LND ready # Set is LND ready
if lightning_info != None and "synced_to_chain" in lightning_info and lightning_info['synced_to_chain']: if lightning_info != None and "synced_to_chain" in lightning_info and lightning_info['synced_to_chain']:
@ -76,11 +84,12 @@ def update_lightning_info():
lightning_channels = lnd_get("/channels") lightning_channels = lnd_get("/channels")
lightning_channel_balance = lnd_get("/balance/channels") lightning_channel_balance = lnd_get("/balance/channels")
lightning_wallet_balance = lnd_get("/balance/blockchain") lightning_wallet_balance = lnd_get("/balance/blockchain")
#lightning_transactions = lnd_get("/transactions")
#lightning_payments = lnd_get("/payments")
#lightning_invoices = lnd_get("/invoices")
lightning_watchtower_server_info = lnd_get_v2("/watchtower/server") lightning_watchtower_server_info = lnd_get_v2("/watchtower/server")
# Poll slower
if lightning_update_count % 2 == 0:
update_lightning_tx_info()
return True return True
def update_lightning_tx_info(): def update_lightning_tx_info():
@ -335,9 +344,11 @@ def restart_lnd_actual():
os.system("systemctl restart lnd_admin") os.system("systemctl restart lnd_admin")
def restart_lnd(): def restart_lnd():
t = Timer(1.0, restart_lnd_actual) t = Timer(0.1, restart_lnd_actual)
t.start() t.start()
time.sleep(1)
def is_testnet_enabled(): def is_testnet_enabled():
return os.path.isfile("/mnt/hdd/mynode/settings/.testnet_enabled") return os.path.isfile("/mnt/hdd/mynode/settings/.testnet_enabled")

View File

@ -49,6 +49,7 @@ def page_lnd():
check_logged_in() check_logged_in()
height = 0 height = 0
refresh_rate = 3600
alias = get_lnd_alias_file_data() alias = get_lnd_alias_file_data()
num_peers = "0" num_peers = "0"
num_active_channels = "TODO" num_active_channels = "TODO"
@ -93,6 +94,7 @@ def page_lnd():
"version": get_lnd_version(), "version": get_lnd_version(),
"loop_version": get_loop_version(), "loop_version": get_loop_version(),
"pool_version": get_pool_version(), "pool_version": get_pool_version(),
"refresh_rate": 10,
"ui_settings": read_ui_settings() "ui_settings": read_ui_settings()
} }
return render_template('lnd.html', **templateData) return render_template('lnd.html', **templateData)
@ -152,10 +154,14 @@ def page_lnd():
"header": "Lightning Status", "header": "Lightning Status",
#"message": str(e), #"message": str(e),
"message": traceback.format_exc(), "message": traceback.format_exc(),
"refresh_rate": 10,
"ui_settings": read_ui_settings() "ui_settings": read_ui_settings()
} }
return render_template('error.html', **templateData) return render_template('error.html', **templateData)
if not is_lnd_ready():
refresh_rate = 15
templateData = { templateData = {
"title": "myNode Lightning Status", "title": "myNode Lightning Status",
"wallet_exists": wallet_exists, "wallet_exists": wallet_exists,
@ -189,6 +195,7 @@ def page_lnd():
"payments": payments, "payments": payments,
"invoices": invoices, "invoices": invoices,
"tx_display_limit": 8, "tx_display_limit": 8,
"refresh_rate": refresh_rate,
"ui_settings": read_ui_settings() "ui_settings": read_ui_settings()
} }
return render_template('lnd.html', **templateData) return render_template('lnd.html', **templateData)
@ -200,7 +207,7 @@ def lnd_regen_tls_cert():
os.system("rm /mnt/hdd/mynode/lnd/tls.cert") os.system("rm /mnt/hdd/mynode/lnd/tls.cert")
os.system("rm /mnt/hdd/mynode/lnd/tls.key") os.system("rm /mnt/hdd/mynode/lnd/tls.key")
t = Timer(1.0, restart_lnd) t = Timer(3.0, restart_lnd)
t.start() t.start()
flash("TLS Certificate Regenerated!", category="message") flash("TLS Certificate Regenerated!", category="message")

View File

@ -2,6 +2,10 @@
<head> <head>
<title>{{ title }}</title> <title>{{ title }}</title>
{% include 'includes/head.html' %} {% include 'includes/head.html' %}
{% if refresh_rate is defined and refresh_rate is not none %}
<meta http-equiv="refresh" content="{{ refresh_rate }}">
{% endif %}
</head> </head>
<body> <body>

View File

@ -3,6 +3,10 @@
<title>{{ title }}</title> <title>{{ title }}</title>
{% include 'includes/head.html' %} {% include 'includes/head.html' %}
{% if refresh_rate is defined and refresh_rate is not none %}
<meta http-equiv="refresh" content="{{ refresh_rate }}">
{% endif %}
<script> <script>
$(document).ready(function() { $(document).ready(function() {
@ -311,7 +315,7 @@
</div> </div>
{% endif %} {% endif %}
{% if watchtower_enabled %} {% if wallet_logged_in and watchtower_enabled %}
<!-- URI Tile / Row --> <!-- URI Tile / Row -->
<div class="app_tile_row"> <div class="app_tile_row">
<div class="info_tile"> <div class="info_tile">
@ -375,98 +379,99 @@
</div> </div>
</div> </div>
<br/> {% if transactions and transactions|length > 0 or payments and payments|length > 0 or invoices and invoices|length > 0 %}
<div class="main_header">Recent Transactions</div> <br/>
<div class="app_tile_row"> <div class="main_header">Recent Transactions</div>
{% if transactions and transactions|length > 0 %} <div class="app_tile_row">
<table style="font-size: 12px; width: 300px; margin: 10px;" class="bitcoin_table"> {% if transactions and transactions|length > 0 %}
<thead class="bitcoin_table_header"> <table style="font-size: 12px; width: 300px; margin: 10px;" class="bitcoin_table">
<td colspan=9 style="text-align: center;">On-chain TX</td> <thead class="bitcoin_table_header">
</thead> <td colspan=9 style="text-align: center;">On-chain</td>
<thead class="bitcoin_table_header"> </thead>
<td>Date</td> <thead class="bitcoin_table_header">
<td>Amount</td> <td>Date</td>
<td>Confirmations</td> <td>Amount</td>
</thead> <td>Confirmations</td>
<tbody> </thead>
{% for tx in transactions[:tx_display_limit] %} <tbody>
<tr> {% for tx in transactions[:tx_display_limit] %}
<td>{{ tx.date_str }}</td> <tr>
<td>{{ tx.amount_str }}</td> <td>{{ tx.date_str }}</td>
<td>{{ tx.num_confirmations }}</td> <td>{{ tx.amount_str }}</td>
</tr> <td>{{ tx.num_confirmations }}</td>
{% endfor %} </tr>
{% if transactions|length >= tx_display_limit %} {% endfor %}
<td colspan=9>more...</td> {% if transactions|length >= tx_display_limit %}
{% endif %}
</tbody>
</table>
{% endif %}
{% if payments and payments|length > 0 %}
<table style="font-size: 12px; width: 300px; margin: 10px;" class="bitcoin_table">
<thead class="bitcoin_table_header">
<td colspan=9 style="text-align: center;">Payments</td>
</thead>
<thead class="bitcoin_table_header">
<td>Date</td>
<td>Amount</td>
<td>Fee</td>
<!--<td>Status</td>-->
</thead>
<tbody>
{% for tx in payments[:tx_display_limit] %}
<tr>
<td>{{ tx.date_str }}</td>
<td>{{ tx.value_str }}</td>
<td>{{ tx.fee_str }}</td>
<!--<td>{{ tx.status }}</td>-->
</tr>
{% endfor %}
{% if payments|length >= tx_display_limit %}
<td colspan=9>more...</td>
{% endif %}
</tbody>
</table>
{% endif %}
{% if invoices and invoices|length > 0 %}
<table style="font-size: 12px; width: 300px; margin: 10px;" class="bitcoin_table">
<thead class="bitcoin_table_header">
<td colspan=9 style="text-align: center;">Invoices</td>
</thead>
<thead class="bitcoin_table_header">
<td>Date</td>
<td>Amount</td>
<td>Memo</td>
<td>State</td>
</thead>
<tbody>
{% for tx in invoices[:tx_display_limit] %}
<tr>
<td>{{ tx.date_str }}</td>
<td>{{ tx.value_str }}</td>
<td>
{% if tx.memo != "" %}
<img style="width: 16px;" src="{{ url_for('static', filename="images/memo.png")}}" title="{{ tx.memo }}"/>
{% endif %}
</td>
<td>{{ tx.state }}</td>
</tr>
{% if invoices|length >= tx_display_limit %}
<td colspan=9>more...</td> <td colspan=9>more...</td>
{% endif %} {% endif %}
{% endfor %} </tbody>
</tbody> </table>
</table> {% endif %}
{% if payments and payments|length > 0 %}
<table style="font-size: 12px; width: 300px; margin: 10px;" class="bitcoin_table">
<thead class="bitcoin_table_header">
<td colspan=9 style="text-align: center;">Payments</td>
</thead>
<thead class="bitcoin_table_header">
<td>Date</td>
<td>Amount</td>
<td>Fee</td>
<!--<td>Status</td>-->
</thead>
<tbody>
{% for tx in payments[:tx_display_limit] %}
<tr>
<td>{{ tx.date_str }}</td>
<td>{{ tx.value_str }}</td>
<td>{{ tx.fee_str }}</td>
<!--<td>{{ tx.status }}</td>-->
</tr>
{% endfor %}
{% if payments|length >= tx_display_limit %}
<td colspan=9>more...</td>
{% endif %}
</tbody>
</table>
{% endif %}
{% if invoices and invoices|length > 0 %}
<table style="font-size: 12px; width: 300px; margin: 10px;" class="bitcoin_table">
<thead class="bitcoin_table_header">
<td colspan=9 style="text-align: center;">Invoices</td>
</thead>
<thead class="bitcoin_table_header">
<td>Date</td>
<td>Amount</td>
<td>Memo</td>
<td>State</td>
</thead>
<tbody>
{% for tx in invoices[:tx_display_limit] %}
<tr>
<td>{{ tx.date_str }}</td>
<td>{{ tx.value_str }}</td>
<td>
{% if tx.memo != "" %}
<img style="width: 16px;" src="{{ url_for('static', filename="images/memo.png")}}" title="{{ tx.memo }}"/>
{% endif %}
</td>
<td>{{ tx.state }}</td>
</tr>
{% if invoices|length >= tx_display_limit %}
<td colspan=9>more...</td>
{% endif %}
{% endfor %}
</tbody>
</table>
{% endif %}
</div>
{% endif %} {% endif %}
</div>
{% if channels and channels|length > 0 %}
<br/> <br/>
<div class="main_header">Channels</div> <div class="main_header">Channels</div>
{% if channels|length > 0 %}
<div class="app_tile_row"> <div class="app_tile_row">
<div class="lightning_channel_container" style="width: 1000px;"> <div class="lightning_channel_container" style="width: 1000px;">
{% for c in channels %} {% for c in channels %}
@ -510,6 +515,7 @@
</div> </div>
{% endif %} {% endif %}
{% if peers and peers|length > 0 %}
<br/> <br/>
<div class="main_header">Peers</div> <div class="main_header">Peers</div>
<div class="app_tile_row"> <div class="app_tile_row">
@ -536,6 +542,7 @@
</tbody> </tbody>
</table> </table>
</div> </div>
{% endif %}
{% endif %} {% endif %}
{% if wallet_exists and wallet_logged_in %} {% if wallet_exists and wallet_logged_in %}