Skip to content

Commit

Permalink
Merge pull request #36 from guydavis/develop
Browse files Browse the repository at this point in the history
Patch to latest Chia 1.1.6
  • Loading branch information
guydavis authored May 21, 2021
2 parents 254e82f + b818820 commit 8782945
Show file tree
Hide file tree
Showing 14 changed files with 215 additions and 60 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. Thanks to ChrisM! Nice solution!
- 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.
Expand Down
6 changes: 4 additions & 2 deletions CREDITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
17 changes: 0 additions & 17 deletions app/commands/chia_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
80 changes: 77 additions & 3 deletions app/commands/global_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -35,12 +57,64 @@ 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 "<UNSET>"
return os.environ['keys'].split(':')

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"]
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 '.dev' in last_chia_version:
sem_ver = last_chia_version.split('.')
last_chia_version = sem_ver[0] + '.' + sem_ver[1] + '.' + sem_ver[2]
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
17 changes: 5 additions & 12 deletions app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -52,17 +51,15 @@ 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')
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')
Expand All @@ -82,24 +79,20 @@ 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():
gc = global_config.load()
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():
Expand Down
42 changes: 42 additions & 0 deletions app/static/styles.css
Original file line number Diff line number Diff line change
@@ -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;
}
29 changes: 22 additions & 7 deletions app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<meta http-equiv="refresh" content="{{ reload_seconds }}">
{% endif %}
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}"/>
</head>

<body>
Expand All @@ -28,7 +29,7 @@
id="menu">
<li class="nav-item">
<a href="{{ url_for('index') }}" class="nav-link px-0 align-middle text-success">
<i class="fs-4 bi-house"></i> <span class="ms-1 d-none d-sm-inline ">Home</span>
<i class="fs-4 bi-house"></i> <span class="ms-1 d-none d-sm-inline ">Summary</span>
</a>
</li>
{% if not global_config.farming_only %}
Expand All @@ -48,7 +49,8 @@
<i class="fs-4 bi-wallet"></i> <span class="ms-1 d-none d-sm-inline">Wallet</span></a>
</li>
<li>
<a href="{{ url_for('network_blockchain') }}" class="nav-link px-0 align-middle text-success">
<a href="{{ url_for('network_blockchain') }}"
class="nav-link px-0 align-middle text-success">
<i class="fs-4 bi-globe"></i> <span class="ms-1 d-none d-sm-inline">Network</span></a>
</li>
{% endif %}
Expand Down Expand Up @@ -86,7 +88,7 @@
</ul>
<hr>
<div class="dropdown pb-4">
<a href="https://github.com/guydavis/machinaris" target="_blank" title="Version 0.2"
<a href="https://github.com/guydavis/machinaris" target="_blank"
class="d-flex align-items-center text-white text-decoration-none dropdown-toggle"
id="dropdownUser1" data-bs-toggle="dropdown" aria-expanded="false">
<i class="fs-4 bi-github"></i>&nbsp;<span class="ms-1 d-none d-sm-inline">About</span> </a>
Expand All @@ -107,12 +109,25 @@
</div>
</div>
<div class="col py-3">

{% block content %}{% endblock %}
{% if reload_seconds %}
<footer class="pt-3 mt-4 text-muted border-top ">
<small><i>Page refreshed at {{ now }}</i></small>

<footer class="pt-3 mt-4">
<div class="row">
<div class="col">
<small><i>Loaded: {{ global_config.now }}</i></small>
</div>
<div class="col">
<small><i>Machinaris {{ global_config.machinaris_version }}</i></small>
</div>
<div class="col">
<small><i>Plotman {{ global_config.plotman_version }}</i></small>
</div>
<div class="col">
<small><i>Chia™ {{ global_config.chia_version }}</i></small>
</div>
</div>
</footer>
{% endif %}
</div>
</div>
</div>
Expand Down
23 changes: 15 additions & 8 deletions app/templates/network/blockchain.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,21 @@
</a>
</header>

<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="{{ url_for('network_blockchain') }}">Blockchain</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ url_for('network_connections') }}">Connections</a>
</li>
</ul>
<style>
a.active.nav-link{background-color: #3d3f42!important }
</style>
<nav class="navbar navbar-dark" style="padding-bottom: 0px;">
<div class="container-fluid">
<ul class="nav nav-tabs bg-dark">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="{{ url_for('network_blockchain') }}">Blockchain</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{{ url_for('network_connections') }}">Connections</a>
</li>
</ul>
</div>
</nav>

<div class="p-5 mb-4 bg-light border rounded-3">
<div class="container-fluid">
Expand Down
Loading

0 comments on commit 8782945

Please sign in to comment.