mirror of
https://github.com/lalanza808/monero.fail.git
synced 2025-03-15 09:46:31 -04:00
mark nodes unhealthy if over 100 blocks away from highest (#13)
This commit is contained in:
parent
310905237f
commit
bac563254c
@ -15,7 +15,7 @@ from flask import render_template, flash, url_for
|
||||
from urllib.parse import urlparse, urlencode
|
||||
|
||||
from xmrnodes.helpers import determine_crypto, is_onion, make_request
|
||||
from xmrnodes.helpers import retrieve_peers, rw_cache
|
||||
from xmrnodes.helpers import retrieve_peers, rw_cache, get_highest_block
|
||||
from xmrnodes.forms import SubmitNode
|
||||
from xmrnodes.models import Node, HealthCheck, Peer
|
||||
from xmrnodes import config
|
||||
@ -29,6 +29,7 @@ logging.basicConfig(
|
||||
app = Flask(__name__)
|
||||
app.config.from_envvar("FLASK_SECRETS")
|
||||
app.secret_key = app.config["SECRET_KEY"]
|
||||
HEALTHY_BLOCK_DIFF = 100 # idc to config this. hardcode is fine.
|
||||
|
||||
@app.route("/", methods=["GET", "POST"])
|
||||
def index():
|
||||
@ -38,6 +39,8 @@ def index():
|
||||
onion = request.args.get("onion", False)
|
||||
show_all = "true" == request.args.get("all", "false")
|
||||
web_compatible = request.args.get("web_compatible", False)
|
||||
highest_block = get_highest_block(nettype, crypto)
|
||||
healthy_block = highest_block - HEALTHY_BLOCK_DIFF
|
||||
|
||||
nodes = Node.select().where(
|
||||
Node.validated == True,
|
||||
@ -49,10 +52,15 @@ def index():
|
||||
nodes = nodes.where(Node.web_compatible == True)
|
||||
|
||||
nodes_all = nodes.count()
|
||||
nodes_unhealthy = nodes.where(Node.available == False).count()
|
||||
nodes_unhealthy = nodes.where(
|
||||
(Node.available == False) | (Node.last_height < healthy_block)
|
||||
).count()
|
||||
|
||||
if not show_all:
|
||||
nodes = nodes.where(Node.available == True)
|
||||
nodes = nodes.where(
|
||||
Node.available == True,
|
||||
Node.last_height > healthy_block
|
||||
)
|
||||
|
||||
nodes = nodes.order_by(
|
||||
Node.datetime_entered.desc()
|
||||
@ -171,11 +179,17 @@ def check():
|
||||
has_cors = 'Access-Control-Allow-Origin' in r.headers
|
||||
is_ssl = node.url.startswith('https://')
|
||||
if r.json()["status"] == "OK":
|
||||
logging.info("success")
|
||||
node.available = True
|
||||
node.web_compatible = has_cors and is_ssl
|
||||
node.last_height = r.json()["height"]
|
||||
hc.health = True
|
||||
highest_block = get_highest_block(node.nettype, node.crypto)
|
||||
healthy_block = highest_block - HEALTHY_BLOCK_DIFF
|
||||
if r.json()["height"] < healthy_block:
|
||||
node.available = False
|
||||
logging.info("unhealthy")
|
||||
else:
|
||||
node.available = True
|
||||
logging.info("success")
|
||||
else:
|
||||
raise
|
||||
except:
|
||||
|
@ -9,6 +9,7 @@ from levin.bucket import Bucket
|
||||
from levin.ctypes import *
|
||||
from levin.constants import LEVIN_SIGNATURE
|
||||
|
||||
from xmrnodes.models import Node
|
||||
from xmrnodes import config
|
||||
|
||||
|
||||
@ -119,3 +120,11 @@ def retrieve_peers(host, port):
|
||||
return peers
|
||||
else:
|
||||
return None
|
||||
|
||||
def get_highest_block(nettype, crypto):
|
||||
highest = Node.select().where(
|
||||
Node.validated == True,
|
||||
Node.nettype == nettype,
|
||||
Node.crypto == crypto
|
||||
).order_by(Node.last_height.desc()).limit(1).first()
|
||||
return highest.last_height
|
||||
|
@ -42,7 +42,9 @@
|
||||
{% if nodes %}
|
||||
<div class="xmrnodes">
|
||||
<p class="center">
|
||||
Tracking {{ nodes_all }} {{ nettype }} {{ crypto | capitalize }} nodes in the database. Of those, {{ nodes_unhealthy }} nodes failed their last check-in.
|
||||
Tracking {{ nodes_all }} {{ nettype }} {{ crypto | capitalize }} nodes in the database.
|
||||
<br>
|
||||
Of those, {{ nodes_unhealthy }} nodes failed their last check-in (unresponsive to ping or over 100 blocks away from highest reported block).
|
||||
</p>
|
||||
<p class="center">Showing {{ nodes | length }} nodes.
|
||||
{% if 'all' not in request.args %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user