From 20ead08592681f1f82644dc925570e9f7167cd78 Mon Sep 17 00:00:00 2001 From: Guy Davis Date: Fri, 21 May 2021 08:38:06 -0600 Subject: [PATCH 1/6] Patch to latest Chia. --- CHANGELOG.md | 6 ++ README.md | 2 +- app/commands/chia_cli.py | 17 ------ app/commands/global_config.py | 80 +++++++++++++++++++++++++- app/routes.py | 17 ++---- app/static/styles.css | 42 ++++++++++++++ app/templates/base.html | 27 +++++++-- app/templates/network/blockchain.html | 24 +++++--- app/templates/network/connections.html | 19 +++--- app/templates/settings/farming.html | 2 +- app/templates/settings/plotting.html | 2 +- dockerfile | 2 +- patch_chia.sh | 31 ++++++++++ 13 files changed, 213 insertions(+), 58 deletions(-) create mode 100644 app/static/styles.css create mode 100644 patch_chia.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index a3f2d7a8..965dbd44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.2.1] - 2021-05-21 + +- Dark mode CSS patch contributed by Hukuma1. Looks great! Thanks for the help! +- Patch to latest Chia binaries version at 1.1.6, display versions on page footer. +- Fix broken 'Add Connection' button on Network | Connections page. + ## [0.2] - 2021-05-20 - Improved key handling including generation (if needed) and supporting multiple keys. diff --git a/README.md b/README.md index c0348c03..e0b3dd96 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ To get started with Machinaris, follow an install guide for your platform: [Wind ## Plotting View -[Plotman](https://github.com/ericaltendorf/plotman) is used manage staggered/parallel plotting jobs, also exposed via the Machinaris web interface: +[Plotman](https://github.com/ericaltendorf/plotman) manages staggered/parallel plotting jobs, also exposed via the Machinaris web interface: ![Plotting](https://raw.githubusercontent.com/guydavis/machinaris-unraid/master/docs/img/machinaris_plotting.png) diff --git a/app/commands/chia_cli.py b/app/commands/chia_cli.py index fc1bc6d7..f6b68c62 100644 --- a/app/commands/chia_cli.py +++ b/app/commands/chia_cli.py @@ -292,20 +292,3 @@ def remove_connection(node_id, ip): app.logger.info(traceback.format_exc()) app.logger.info("Successfully removed connection to {0}".format(ip)) return True - -def prune_leechers(): - global last_connections_show - removed = 0 - connections = load_connections_show() - for conn in connections.conns: - if conn['type'] == 'FULL_NODE': - if (conn['mib_down'] == 0) and (conn['mib_up'] == 0): - app.logger.debug("Removing {0} because at {1} was {2} up and {3} down.".format( \ - conn['ip'], conn['last_connect'], conn['mib_up'], conn['mib_down'])) - if remove_connection(conn['nodeid'], conn['ip']): - removed += 1 - if removed > 0: - last_connections_show = None # Force reset on next load. - flash('Successfully pruned {0} leechers sitting at 0.0 MiB both up and down.'.format(removed), 'success') - else: - flash('Found no leechers to remove. All good!', 'info') \ No newline at end of file diff --git a/app/commands/global_config.py b/app/commands/global_config.py index 72180f85..c4aa76bd 100644 --- a/app/commands/global_config.py +++ b/app/commands/global_config.py @@ -2,20 +2,42 @@ # Common configuration functions. # +import datetime import os +import shutil +import socket +import time import traceback +import yaml + +from flask import Flask, jsonify, abort, request, flash +from stat import S_ISREG, ST_CTIME, ST_MTIME, ST_MODE, ST_SIZE +from subprocess import Popen, TimeoutExpired, PIPE +from os import path from app import app +from app.models import chia +from app.commands import global_config + +CHIA_BINARY = '/chia-blockchain/venv/bin/chia' +PLOTMAN_SCRIPT = '/chia-blockchain/venv/bin/plotman' + +RELOAD_MINIMUM_DAYS = 1 # Don't run binaries for version again until this time expires def load(): cfg = {} cfg['plotting_only'] = plotting_only() cfg['farming_only'] = farming_only() + cfg['now'] = datetime.datetime.now(tz=None).strftime("%Y-%m-%d %H:%M:%S") + cfg['machinaris_version'] = "0.2.1" # TODO Get this from tag? + cfg['plotman_version'] = load_plotman_version() + cfg['chia_version'] = load_chia_version() return cfg def is_setup(): if "keys" not in os.environ: - app.logger.info("No 'keys' environment variable set for this run. Set an in-container path to mnemonic.txt.") + app.logger.info( + "No 'keys' environment variable set for this run. Set an in-container path to mnemonic.txt.") return False keys = os.environ['keys'] app.logger.debug("Trying with full keys='{0}'".format(keys)) @@ -35,7 +57,8 @@ def is_setup(): def get_key_paths(): if "keys" not in os.environ: - app.logger.info("No 'keys' environment variable set for this run. Set an in-container path to mnemonic.txt.") + app.logger.info( + "No 'keys' environment variable set for this run. Set an in-container path to mnemonic.txt.") return "" return os.environ['keys'].split(':') @@ -43,4 +66,55 @@ def plotting_only(): return "mode" in os.environ and os.environ['mode'] == "plotter" def farming_only(): - return "mode" in os.environ and os.environ['mode'] in ["harvester", "farmer"] \ No newline at end of file + return "mode" in os.environ and os.environ['mode'] in ["harvester", "farmer"] + +last_chia_version = None +last_chia_version_load_time = None + +def load_chia_version(): + global last_chia_version + global last_chia_version_load_time + if last_chia_version and last_chia_version_load_time >= \ + (datetime.datetime.now() - datetime.timedelta(days=RELOAD_MINIMUM_DAYS)): + return last_chia_version + proc = Popen("{0} version".format(CHIA_BINARY), + stdout=PIPE, stderr=PIPE, shell=True) + try: + outs, errs = proc.communicate(timeout=90) + except TimeoutExpired: + proc.kill() + proc.communicate() + abort(500, description="The timeout is expired!") + if errs: + abort(500, description=errs.decode('utf-8')) + last_chia_version = outs.decode('utf-8').strip() + if last_chia_version.endswith('.dev0'): + sem_ver = last_chia_version.split('.') + last_chia_version = sem_ver[0] + '.' + sem_ver[1] + '.' + str(int(sem_ver[2])-1) + last_chia_version_load_time = datetime.datetime.now() + return last_chia_version + +last_plotman_version = None +last_plotman_version_load_time = None + +def load_plotman_version(): + global last_plotman_version + global last_plotman_version_load_time + if last_plotman_version and last_plotman_version_load_time >= \ + (datetime.datetime.now() - datetime.timedelta(days=RELOAD_MINIMUM_DAYS)): + return last_plotman_version + proc = Popen("{0} version < /dev/tty".format(PLOTMAN_SCRIPT), + stdout=PIPE, stderr=PIPE, shell=True) + try: + outs, errs = proc.communicate(timeout=90) + except TimeoutExpired: + proc.kill() + proc.communicate() + abort(500, description="The timeout is expired!") + if errs: + abort(500, description=errs.decode('utf-8')) + last_plotman_version = outs.decode('utf-8').strip() + if last_plotman_version.startswith('plotman'): + last_plotman_version = last_plotman_version[len('plotman'):].strip() + last_plotman_version_load_time = datetime.datetime.now() + return last_plotman_version diff --git a/app/routes.py b/app/routes.py index 75da8d84..98afc9da 100644 --- a/app/routes.py +++ b/app/routes.py @@ -21,8 +21,7 @@ def index(): return redirect(url_for('setup')) farming = chia_cli.load_farm_summary() plotting = plotman_cli.load_plotting_summary() - now = datetime.now(tz=None) - return render_template('index.html', reload_seconds=60, now=now, + return render_template('index.html', reload_seconds=60, farming=farming.__dict__, plotting=plotting.__dict__, global_config=gc) @@ -52,8 +51,7 @@ def plotting(): else: app.logger.info("Unknown plotting form: {0}".format(request.form)) plotting = plotman_cli.load_plotting_summary() - now = datetime.now(tz=None) - return render_template('plotting.html', reload_seconds=60, now=now, plotting=plotting, + return render_template('plotting.html', reload_seconds=60, plotting=plotting, global_config=gc) @app.route('/farming') @@ -61,8 +59,7 @@ def farming(): gc = global_config.load() farming = chia_cli.load_farm_summary() plots = chia_cli.load_plots_farming() - now = datetime.now(tz=None) - return render_template('farming.html', now=now, farming=farming, plots=plots, + return render_template('farming.html', farming=farming, plots=plots, global_config=gc) @app.route('/alerts') @@ -82,9 +79,8 @@ def wallet(): def network_blockchain(): gc = global_config.load() blockchain = chia_cli.load_blockchain_show() - now = datetime.now(tz=None) return render_template('network/blockchain.html', reload_seconds=60, - blockchain=blockchain.text, global_config=gc, now=now) + blockchain=blockchain.text, global_config=gc, now=gc['now']) @app.route('/network/connections', methods=['GET', 'POST']) def network_connections(): @@ -92,14 +88,11 @@ def network_connections(): if request.method == 'POST': if request.form.get('action') == "add": chia_cli.add_connection(request.form.get("connection")) - elif request.form.get('action') == "prune": - chia_cli.prune_leechers() else: app.logger.info("Unknown form action: {0}".format(request.form)) connections = chia_cli.load_connections_show() - now = datetime.now(tz=None) return render_template('network/connections.html', reload_seconds=60, - connections=connections.text, global_config=gc, now=now) + connections=connections.text, global_config=gc, now=gc['now']) @app.route('/settings/plotting', methods=['GET', 'POST']) def settings_plotting(): diff --git a/app/static/styles.css b/app/static/styles.css new file mode 100644 index 00000000..e24bd318 --- /dev/null +++ b/app/static/styles.css @@ -0,0 +1,42 @@ +/* Main background color */ +body { + background-color: #15171a; + color: #c7c7c7; +} + +/* Rounded sections */ +.rounded-3 { + border-radius: .5rem!important; + background-color: #212529!important; + -webkit-box-shadow: 0px 1px 0px 0px #000; + box-shadow: 0px 1px 0px 0px #000; + border: 0!important; +} + +.text-success { + color: #3aac59!important; + font-weight: 500; +} + +.display-6 { + color: #c7c7c7; +} + +.nav-link.active { + color: #3aac59!important; + font-weight: 500; +} + +.nav-link { + color: #3aac59!important; + font-weight: 500; +} + +.fs-4 { + color: #c7c7c7; +} + +/* Menu */ +.col-auto.col-md-3.col-xl-2.px-sm-2.px-0.bg-dark { + border-right: 1px solid #000; +} \ No newline at end of file diff --git a/app/templates/base.html b/app/templates/base.html index cd436889..9b13618a 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -13,6 +13,7 @@ {% endif %} + @@ -28,7 +29,7 @@ id="menu"> {% if not global_config.farming_only %} @@ -48,7 +49,8 @@ Wallet
  • - + Network
  • {% endif %} @@ -107,12 +109,25 @@
    + {% block content %}{% endblock %} - {% if reload_seconds %} -
    - Page refreshed at {{ now }} + +
    +
    +
    + Loaded: {{ global_config.now }} +
    +
    + Machinaris {{ global_config.machinaris_version }} +
    +
    + Plotman {{ global_config.plotman_version }} +
    +
    + Chia™ {{ global_config.chia_version }} +
    +
    - {% endif %}
    diff --git a/app/templates/network/blockchain.html b/app/templates/network/blockchain.html index 4f59778f..ffaa6f7a 100644 --- a/app/templates/network/blockchain.html +++ b/app/templates/network/blockchain.html @@ -8,14 +8,22 @@ - + +
    diff --git a/app/templates/network/connections.html b/app/templates/network/connections.html index 5205ddf0..f53851f1 100644 --- a/app/templates/network/connections.html +++ b/app/templates/network/connections.html @@ -24,11 +24,15 @@ {% endwith %}
    -
    - + diff --git a/app/templates/settings/plotting.html b/app/templates/settings/plotting.html index 85c7e193..de0ebac6 100644 --- a/app/templates/settings/plotting.html +++ b/app/templates/settings/plotting.html @@ -30,7 +30,7 @@ - + diff --git a/dockerfile b/dockerfile index 21f0e4e2..d3c0d121 100644 --- a/dockerfile +++ b/dockerfile @@ -23,7 +23,7 @@ ENV FLASK_APP=/machinaris/main.py ENV XDG_CONFIG_HOME=/root/.chia COPY . /machinaris/ -RUN DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata && \ +RUN DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata && sh ./patch_chia.txt && \ /chia-blockchain/venv/bin/pip3 install git+https://github.com/ericaltendorf/plotman@main && \ venv/bin/pip3 install -r /machinaris/requirements.txt && \ cp -f /machinaris/entrypoint.sh /chia-blockchain/ && \ diff --git a/patch_chia.sh b/patch_chia.sh new file mode 100644 index 00000000..dd65e4d2 --- /dev/null +++ b/patch_chia.sh @@ -0,0 +1,31 @@ +#!/bin/env bash +# +# As the official Docker image is out of date, this performs an upgrade install of latest Chia +# + +echo 'Upgrading Chia...' + +cd /chia-blockchain +rm -f entrypoint.sh +. ./activate +chia stop -d all +deactivate +git fetch +git stash +git checkout latest +git reset --hard FETCH_HEAD + +# If you get RELEASE.dev0 then delete the package-lock.json in chia-blockchain-gui and install.sh again + +git status + +# git status should say "nothing to commit, working tree clean", +# if you have uncommitted changes, RELEASE.dev0 will be reported. + +sh install.sh + +. ./activate + +chia init + +deactivate From 20b030c7ceb5ab90e8f9b438f0f10534e25eea6b Mon Sep 17 00:00:00 2001 From: Guy Davis Date: Fri, 21 May 2021 08:42:10 -0600 Subject: [PATCH 2/6] Path to patch script. --- dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfile b/dockerfile index d3c0d121..cbf7bed2 100644 --- a/dockerfile +++ b/dockerfile @@ -23,7 +23,7 @@ ENV FLASK_APP=/machinaris/main.py ENV XDG_CONFIG_HOME=/root/.chia COPY . /machinaris/ -RUN DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata && sh ./patch_chia.txt && \ +RUN DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata && . /machinaris/patch_chia.txt && \ /chia-blockchain/venv/bin/pip3 install git+https://github.com/ericaltendorf/plotman@main && \ venv/bin/pip3 install -r /machinaris/requirements.txt && \ cp -f /machinaris/entrypoint.sh /chia-blockchain/ && \ From af8c0e722c901b83e67207c6bd6d3f9940c111ea Mon Sep 17 00:00:00 2001 From: Guy Davis Date: Fri, 21 May 2021 08:45:27 -0600 Subject: [PATCH 3/6] Script extension. --- dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dockerfile b/dockerfile index cbf7bed2..a7cb05a7 100644 --- a/dockerfile +++ b/dockerfile @@ -23,7 +23,7 @@ ENV FLASK_APP=/machinaris/main.py ENV XDG_CONFIG_HOME=/root/.chia COPY . /machinaris/ -RUN DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata && . /machinaris/patch_chia.txt && \ +RUN DEBIAN_FRONTEND=noninteractive apt-get install -y tzdata && . /machinaris/patch_chia.sh && \ /chia-blockchain/venv/bin/pip3 install git+https://github.com/ericaltendorf/plotman@main && \ venv/bin/pip3 install -r /machinaris/requirements.txt && \ cp -f /machinaris/entrypoint.sh /chia-blockchain/ && \ From d587ac56f6f50f0f8c1b75bd62d347db51f817cd Mon Sep 17 00:00:00 2001 From: Guy Davis Date: Fri, 21 May 2021 09:04:07 -0600 Subject: [PATCH 4/6] Match more upstream version # changes. --- app/commands/global_config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/commands/global_config.py b/app/commands/global_config.py index c4aa76bd..8e38e74e 100644 --- a/app/commands/global_config.py +++ b/app/commands/global_config.py @@ -88,9 +88,9 @@ def load_chia_version(): if errs: abort(500, description=errs.decode('utf-8')) last_chia_version = outs.decode('utf-8').strip() - if last_chia_version.endswith('.dev0'): + if '.dev' in last_chia_version: sem_ver = last_chia_version.split('.') - last_chia_version = sem_ver[0] + '.' + sem_ver[1] + '.' + str(int(sem_ver[2])-1) + last_chia_version = sem_ver[0] + '.' + sem_ver[1] + '.' + sem_ver[2] last_chia_version_load_time = datetime.datetime.now() return last_chia_version From 3fff8a527d0ff50160496d156e27e8b925a5609e Mon Sep 17 00:00:00 2001 From: Guy Davis Date: Fri, 21 May 2021 09:16:24 -0600 Subject: [PATCH 5/6] Change log and version. --- CHANGELOG.md | 2 +- CREDITS.md | 6 ++++-- app/templates/base.html | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 965dbd44..69038c3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format ## [0.2.1] - 2021-05-21 - Dark mode CSS patch contributed by Hukuma1. Looks great! Thanks for the help! -- Patch to latest Chia binaries version at 1.1.6, display versions on page footer. +- Patch to latest Chia binaries version at 1.1.6. Thanks to ChrisM! Nice solution! - Fix broken 'Add Connection' button on Network | Connections page. ## [0.2] - 2021-05-20 diff --git a/CREDITS.md b/CREDITS.md index 1d07a90b..7e4b0775 100644 --- a/CREDITS.md +++ b/CREDITS.md @@ -20,6 +20,10 @@ A huge thank-you to the great teams/devs behind these projects, being used by Ma ## Testers and Developers A big thanks to all that contributed with dev and test including: +* Hukuma1 +* ChrisM +* gabiroli +* Geezus * LordKDG * seythis * gleech @@ -28,8 +32,6 @@ A big thanks to all that contributed with dev and test including: * TechNotWiz * belchi0r * yass15 -* gabiroli -* Geezus ## Trademark Notice CHIA NETWORK INC, CHIA™, the CHIA BLOCKCHAIN™, the CHIA PROTOCOL™, CHIALISP™ and the “leaf Logo” (including the leaf logo alone when it refers to or indicates Chia), are trademarks or registered trademarks of Chia Network, Inc., a Delaware corporation. diff --git a/app/templates/base.html b/app/templates/base.html index 9b13618a..0fb1834f 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -88,7 +88,7 @@