Feature/0.9.2+only monitoring (#475)

* Not testing or informing validator about pre 0.9.2 nodes

* Corrected version check

* Updated JS file to monitor 0.9.2+ nodes

* Restored updates every minute
This commit is contained in:
Jędrzej Stuczyński
2020-11-26 16:44:18 +00:00
committed by GitHub
parent c2a1ed855b
commit afb7825135
4 changed files with 82 additions and 20 deletions
+36 -9
View File
@@ -1,7 +1,4 @@
function websocketUrl() {
return "wss://testnet-explorer.nymtech.net";
if ($(location).attr("href").startsWith("http://localhost")) {
return "ws://localhost:1648";
} else if ($(location).attr("href").startsWith("http://qa-explorer")) {
@@ -11,6 +8,22 @@ function websocketUrl() {
}
}
function parseVersion(str) {
if (typeof (str) != 'string') { return false; }
var arr = str.split('.');
// parse int or default to 0
var maj = parseInt(arr[0]) || 0;
var min = parseInt(arr[1]) || 0;
var rest = parseInt(arr[2]) || 0;
return {
major: maj,
minor: min,
patch: rest
}
}
function getTopology() {
console.log("Getting topology...");
var topologyUrl = "/downloads/topology.json";
@@ -41,6 +54,11 @@ function clearStatus(element) {
}
function setNodeStatus(dotWrapper, reportData) {
// don't do anything to pre 0.9.2 nodes which have status 'active'
if (dotWrapper.children[0].hasAttribute("active")) {
return
}
let statusIndicator = dotWrapper.children[0];
clearStatus(statusIndicator)
@@ -111,9 +129,9 @@ function makeStatusDot(nodePubKey) {
return dotWrapper;
}
function tempDisabledStatus(nodePubKey) {
let statusText = "Temporarily disabled..."
function outdatedStatus(nodePubKey) {
let statusText = "Out of date"
let dotWrapper = document.getElementById(`dotWrapper${nodePubKey}`);
dotWrapper.classList.remove('statusDot')
let statusIndicator = dotWrapper.children[0];
@@ -185,11 +203,14 @@ function createMixnodeRows(mixNodes) {
if (purifiedRep.length === 0) {
purifiedRep = 0
}
let purifiedVersion = DOMPurify.sanitize(node.version)
var $tr = $('<tr>').append(
$('<input type="hidden" id="prev-timestamp-' + node.identityKey + '" value="' + currentUnixTime + '"> '),
$('<td>').html(makeStatusDot(node.identityKey)),
$('<td>').text(purifiedRep),
$('<td>').text(DOMPurify.sanitize(node.version)),
$('<td>').text(purifiedVersion),
$('<td>').text(DOMPurify.sanitize(node.identityKey)),
$('<td>').text(DOMPurify.sanitize(node.sphinxKey)),
$('<td>').text(DOMPurify.sanitize(node.location)),
@@ -199,7 +220,13 @@ function createMixnodeRows(mixNodes) {
$('<td id="' + "sent-" + DOMPurify.sanitize(node.identityKey) + '">').text("0")
).appendTo('#mixnodes-list');
tempDisabledStatus(node.identityKey);
let version = parseVersion(purifiedVersion)
if (version.major >= 1 || version.minor >= 10 || (version.minor == 9 && version.patch >= 2)) {
makeStatusDot(node.identityKey);
} else {
outdatedStatus(node.identityKey);
}
})
}
@@ -299,7 +326,7 @@ function updateTimeStampStorage(msg) {
document.addEventListener("DOMContentLoaded", function () {
// update every minute
// setInterval(updateNodesStatus, 60000);
setInterval(updateNodesStatus, 60000);
getTopology();
connectWebSocket();
});
+2
View File
@@ -50,6 +50,8 @@ const GATEWAY_SENDING_RATE_ARG: &str = "gateway-rate";
const DEFAULT_VALIDATOR: &str = "http://testnet-validator1.nymtech.net:8081";
const DEFAULT_GATEWAY_SENDING_RATE: usize = 500;
pub(crate) const PENALISE_OUTDATED: bool = false;
pub(crate) const TIME_CHUNK_SIZE: Duration = Duration::from_millis(50);
fn parse_args<'a>() -> ArgMatches<'a> {
+18 -7
View File
@@ -14,6 +14,7 @@
use crate::run_info::RunInfo;
use crate::test_packet::TestPacket;
use crate::PENALISE_OUTDATED;
use log::*;
use std::collections::{HashMap, HashSet};
use std::mem;
@@ -252,10 +253,16 @@ impl TestRun {
self.test_report.print(self.print_detailed_report);
}
let mut mix_status = Vec::with_capacity(
2 * (self.test_report.malformed.len() + self.test_report.outdated.len())
+ self.expected_run_packets.len(),
);
let mut mix_status = if PENALISE_OUTDATED {
Vec::with_capacity(
2 * (self.test_report.malformed.len() + self.test_report.outdated.len())
+ self.expected_run_packets.len(),
)
} else {
Vec::with_capacity(
2 * (self.test_report.malformed.len()) + self.expected_run_packets.len(),
)
};
// firstly we know all malformed and outdated nodes are definitely down - we haven't sent
// any test packets for those
@@ -263,9 +270,13 @@ impl TestRun {
let mut down_status = self.down_status(malformed.clone());
mix_status.append(&mut down_status);
}
for outdated in self.test_report.outdated.iter() {
let mut down_status = self.down_status(outdated.0.clone());
mix_status.append(&mut down_status);
// but don't inform validator about outdated nodes for now!
if PENALISE_OUTDATED {
for outdated in self.test_report.outdated.iter() {
let mut down_status = self.down_status(outdated.0.clone());
mix_status.append(&mut down_status);
}
}
let mut undelivered = mem::replace(&mut self.expected_run_packets, HashSet::new());
+26 -4
View File
@@ -62,6 +62,31 @@ impl PacketSender {
}
}
fn check_version_compatibility(&self, mix_version: &str) -> bool {
let semver_compatibility = version_checker::is_minor_version_compatible(
mix_version,
self.tested_network.system_version(),
);
if semver_compatibility {
// this can't fail as we know it's semver compatible
let version = version_checker::parse_version(mix_version).unwrap();
if version.major >= 1 {
return true;
}
if version.major == 0 && version.minor >= 10 {
return true;
}
if version.minor >= 9 && version.patch >= 2 {
true
} else {
false
}
} else {
false
}
}
fn make_test_mix(&self, mix: RegisteredMix) -> TestMix {
// the reason for that conversion is that I want to operate on concrete types
// rather than on "String" everywhere and also this way we remove obviously wrong
@@ -74,10 +99,7 @@ impl PacketSender {
TestMix::MalformedMix(mix_id)
}
Ok(mix) => {
if version_checker::is_minor_version_compatible(
&mix.version,
self.tested_network.system_version(),
) {
if self.check_version_compatibility(&mix.version) {
let v4_test_packet =
TestPacket::new(mix.identity_key, IpVersion::V4, self.nonce);
let v6_test_packet =