Added watch for validity of votes.

This fork adds a validity section where the monitor checks for every vote every authority receives from every other authority.

The mechanism is designed to detect equivocation, i.e. when one authority broadcasts different votes to different authorities.

Merge request reports

Loading
+2 −2
Changes for data/consensus.cfg: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
# control consensus-health output

# do not show all fallback directory output
ignore_fallback_authorities False
ignore_fallback_authorities True

# do not show values less than this amount on the graph. For small testing networks set to 1
graph_logical_min 125
@@ -15,7 +15,7 @@ clockskew_threshold 20
# bwauths that should be graphed

bwauths maatuska
bwauths faravahar
# bwauths faravahar
bwauths bastet
bwauths moria1
bwauths gabelmoo
+14 −1
Changes for .gitignore: 14 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
*.p
*.swp


out/bwauth*
out/index.html
out/graphs.html
out/vote-stats.csv
@@ -13,3 +13,16 @@ out/fallback-dir-stats.csv
out/historical.db

data/historical.db

update.sh

*.orig
*.pyc
*.swp
*.swo
.editorconfig
.tox
stem-git/.idea/
stem-git/.mypy_cache/
stem-git/test/data/
stem-git/docs/_build/
+77 −1
Changes for utility.py: 77 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -73,6 +73,82 @@ def get_votes():
	return _get_documents('vote', '/tor/status-vote/current/authority.z')


# Multithreading
import concurrent.futures

def _validate_from_one_vote(authority, recv_authority):
	_downloader = stem.descriptor.remote.DescriptorDownloader(
		timeout = 30,
		retries = 5,
		fall_back_to_authority = False,
		document_handler = stem.descriptor.DocumentHandler.DOCUMENT,
	)
	query = _downloader.query(
		'/tor/status-vote/current/%s.z' % authority.v3ident,
		endpoints = [stem.DirPort(recv_authority.address, recv_authority.dir_port)],
		default_params = False,
		start = False
	)
	# Re-add the .z suffix per #25782
	query.resource = query.resource + ".z"
	exception = ""
	for i in range(5):
		try:
			recv_vote = query.run()[0]
			return ("OK", recv_vote)
		except Exception as exc:
			exception = str(exc)
			time.sleep(10)
			continue
	return (exception, "")


def validate_votes():
	"""
	Confirm that there is no discrepency within votes.

	:returns: dict of the form {sender => {receiver => {URL, err}}}
	"""
	validation = {}
	validation_queue = {}
	validation_result = {}
	with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:
		for (nickname, authority) in get_dirauths().items():
			if authority.v3ident is None:
				continue
			validation[nickname] = {}
			validation_queue[nickname] = {}
			validation_result[nickname] = {}
			for (recv_nickname, recv_authority) in get_dirauths().items():
				if recv_authority.v3ident is None:
					continue
				validation_queue[nickname][recv_nickname] = executor.submit(_validate_from_one_vote, authority, recv_authority)
		for (nickname, authority) in get_dirauths().items():
			if authority.v3ident is None:
				continue
			for (recv_nickname, recv_authority) in get_dirauths().items():
				if recv_authority.v3ident is None:
					continue
				validation[nickname][recv_nickname] = validation_queue[nickname][recv_nickname].result()
		for (nickname, authority) in get_dirauths().items():
			if authority.v3ident is None:
				continue
			for (recv_nickname, recv_authority) in get_dirauths().items():
				if recv_authority.v3ident is None:
					continue
				url = 'http://' + str(recv_authority.address) + ':' + str(recv_authority.dir_port) + \
					'/tor/status-vote/current/%s.z' % authority.v3ident
				if validation[nickname][recv_nickname][0] != "OK":
					validation_result[nickname][recv_nickname] = (url, validation[nickname][recv_nickname][0])
				elif validation[nickname][nickname][0] != "OK":
					validation_result[nickname][recv_nickname] = (url, "Unable to validate the vote with the sender")
				elif validation[nickname][nickname] != validation[nickname][recv_nickname]:
					validation_result[nickname][recv_nickname] = (url, "Discrepency detected")
				else:
					validation_result[nickname][recv_nickname] = (url, "OK")
	return validation_result


def _get_documents(label, resource):
	documents, issues, runtimes = {}, [], {}

@@ -132,7 +208,7 @@ def get_clockskew():
			if processing > 5:
				clockskew[nickname] -= datetime.timedelta(seconds=(processing / 2))
			clockskew[nickname] -= startTimeStamp
			clockskew[nickname] = round(clockskew[nickname].total_seconds(), 2)
			clockskew[nickname] = clockskew[nickname].total_seconds()
		except Exception as e:
			print("Clockskew Exception:", e)
			continue
+39 −2
Changes for website.py: 39 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ class WebsiteWriter:
	votes = None
	fallback_dirs = None
	clockskew = None
	validation = None
	known_authorities = []
	bandwidth_authorities = []
	consensus_expiry = datetime.timedelta(hours=3)
@@ -64,6 +65,7 @@ class WebsiteWriter:
		self._write_authority_versions()
		self._write_download_statistics()
		self._write_relay_info_summary()
		self._write_vote_validity()
		if include_relay_info:
			self._write_relay_info_table()
		else:
@@ -89,6 +91,8 @@ class WebsiteWriter:
		self.fallback_dirs = fallback_dirs
	def set_clockskew(self, clockskew):
		self.clockskew = clockskew
	def set_validation(self, validation):
		self.validation = validation
	def get_consensus_time(self):
		return self.consensus.valid_after
	def all_votes_present(self):
@@ -233,7 +237,7 @@ class WebsiteWriter:
			+ "directory consensus process.")
		if not include_relay_info:
			self.site.write("<br />This is the abbreviated page. The "
			+ "<a href=\"/consensus-health.html\">detailed page</a> "
			+ "<a href=\"consensus-health.html\">detailed page</a> "
			+ "which includes the (large) relay info table is also "
			+ "available.")
		self.site.write("</p>\n")
@@ -1519,6 +1523,37 @@ class WebsiteWriter:
				+ "  </tr>\n")
		self.site.write("</table>\n")

	#-----------------------------------------------------------------------------------------
	def _write_vote_validity(self):
		"""
		Write the vote validity
		"""
		self.site.write("<br>\n\n\n"
		+ " <!-- ================================================================= -->"
		+ "<a name=\"vote\">\n"
		+ "<h3><a href=\"#vote\" class=\"anchor\">Validity "
		+ "of votes</a></h3>\n"
		+ "<br>\n"
		+ "<p>This table monitors the votes each authority receives from other authorities.</p>\n"
		+ "<br>\n"
		+ "<table border=\"0\" cellpadding=\"4\" cellspacing=\"0\" summary=\"\">\n"
		+ "  <colgroup>\n"
		+ "    <col width=\"160\">\n"
		+ "    <col width=\"630\">\n"
		+ "  </colgroup>\n"
		+ "  <tr>\n" 
		+ "    <td><b>Sender</b></td>\n"
		+ "    <td><b>Receiver</b></td>\n")
		for dirauth_sender in self.validation:
			self.site.write("<tr>\n" + "<td>" + dirauth_sender + "</td>\n<td>\n")
			for (dirauth_receiver, validation) in self.validation[dirauth_sender].items():
				self.site.write("<a style = \"color: " + ("blue" if validation[1] == 'OK' else "red") + \
					"\" href = \"" + validation[0] + \
					"\" title = \"" + validation[1] + "\">" + \
					dirauth_receiver + "</a> \n")
			self.site.write("</td></tr>\n")
		self.site.write("</table>\n")

	#-----------------------------------------------------------------------------------------
	def _write_relay_info_pointer(self):
		"""
@@ -1530,7 +1565,7 @@ class WebsiteWriter:
		+ "<h3><a href=\"#relayinfo\" class=\"anchor\">Relay info</a></h3>\n"
		+ "<br>\n"
		+ "<p>Looking for the (huge) relay info table? It's been moved to the <a "
		+ "href=\"/consensus-health.html\">detailed page</a> to speed up this page.</p>\n\n"
		+ "href=\"consensus-health.html\">detailed page</a> to speed up this page.</p>\n\n"
		+ "<p id=\"relay-addition-javascript-pointer\">If you enable javascript, you will be able "
		+ "to add individual relays from the current consensus to this page.</p>\n\n"
		+ "<script src=\"jquery-3.3.1.min.js\"></script>\n"
@@ -1880,6 +1915,8 @@ if __name__ == '__main__':
	w.set_votes(v)
	f = pickle.load(open('fallback_dirs.p', 'rb'))
	w.set_fallback_dirs(f)
	va = pickle.load(open('validation.p', 'rb'))
	w.set_validation(va)
		

	w.set_config(CONFIG)
+3 −1
Changes for write_website.py: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ def main():
	config.load(os.path.join(os.path.dirname(__file__), 'data', 'consensus.cfg'))
	set_config(CONFIG)

	validation = validate_votes()
	consensuses, consensus_fetching_issues, consensus_fetching_runtimes = get_consensuses()
	votes, vote_fetching_issues, vote_fetching_runtimes = get_votes()
	clockskew = get_clockskew()
@@ -81,7 +82,7 @@ def main():
	# pickle.dump(consensuses, open('consensus.p', 'wb'))
	# pickle.dump(votes, open('votes.p', 'wb'))
	# pickle.dump(fallback_dirs, open('fallback_dirs.p', 'wb'))

	# pickle.dump(validation, open('validation.p', 'wb'))

	dbc = sqlite3.connect(os.path.join('data', 'historical.db'))

@@ -306,6 +307,7 @@ def main():
	w.set_votes(votes)
	w.set_fallback_dirs(fallback_dirs)
	w.set_clockskew(clockskew)
	w.set_validation(validation)
	w.write_website(os.path.join(os.path.dirname(__file__), 'out', 'consensus-health.html'), \
		True, os.path.join(os.path.dirname(__file__), 'out', 'relay-indexes.txt'))
	w.write_website(os.path.join(os.path.dirname(__file__), 'out', 'index.html'), False)
Loading