Nyzo manual autovoting

This tutorial is no longer relevant due to recent changes made to the entry mechanism.


In this post we will set up the Nyzo autovoter. The conception of this script / repository was born from the need to collide votes from multiple people into one entity, to ensure a fair entry of those waiting in the queue and to combat selfish growth of one malicious entity.
This autovoter will give you the possibility to add public id’s in a file and vote for them to join. The list is processed chronologically, yellow and red nodes are discarded and nodes who have successfully joined are removed from the list.

Multiple people are currently using an agreed upon list which consists of people waiting in queue and people who have dropped out due to DDoS attacks earlier. This list is not centralized and you are free to create your own list and gather support for it. This post explains you how to set it up and do so easily.

This installation expects you to have installed the nyzoVerifier on your machine. The machine you are installing this on does not have to be in the cycle.

On an Ubuntu machine. preferably 16.04 we need to prepare our environment first, download the scripts and give them the appropriate rights. You can verify how the scripts work below.

Please verify script integrity by visiting the URLs in the script below.

sudo apt-get install python3-bs4
mkdir /voting/
cd /voting/
wget https://raw.githubusercontent.com/nyzo-voting-repo/v01/master/voting.py
chmod +x voting.py
wget https://raw.githubusercontent.com/nyzo-voting-repo/Nyzo-voting/master/tst.sh
chmod +x tst.sh
nano tst.sh

We have created a voting directory, downloaded the first two scripts and gave it appropriate rights to execute. We also installed BeautifulSoup4 to parse the web data.

The last command should have opened a text editor.
Edit the file accordingly, every line needs to be updated with one private key, if there are more lines than private keys: remove the redundant lines. Make sure your nyzoVerifier path is correct. The path is different for generic Ubuntu installations and AWS installations. Save and close with CTRL + O , CTRL + X

Next, we will update our crontab to regularly vote. Select ‘2’ to open the editor if this is your first time editing the crontab.

sudo crontab -e

Add this line on a new line. Do not delete anything else.

0,14,32,43,51 * * * * cd /voting/; /usr/bin/python3 /voting/voting.py >> /voting/job.log 2>&1

Save and close with CTRL + O, CTRL +X

Next, we will need the list of nodes to vote for. This can be any list but many are currently (19/01/19) using this list, which consists of queue nodes and DDoS dropouts. If this article has dated, please check back in the discord for a new list.

wget https://raw.githubusercontent.com/nyzo-voting-repo/v01/master/randompubids.txt
chmod +x randompubids.txt

We can verify if the script is working with

python3 /voting/voting.py

It should look something like this:

exp

That’s it! This script will automatically execute four times an hour, voting for whoever is next.

If you have any doubts you are welcome to join the discord.
You can debug by tailing the log.

Live (will only move at the preset times in the crontab):

tail -f /voting/job.log

Or the last 100 lines (not live):

tail -100 /voting/job.log

Happy voting!
Benjamin


Contents of the script, please verify script integrity on Github before installing:

voting.py:

############################
# BEFORE RUNNING THIS:
############################

# mkdir /voting/
# cd /voting/
# wget https://raw.githubusercontent.com/nyzo-voting-repo/v01/master/voting.py
# chmod +x voting.py
# wget https://raw.githubusercontent.com/nyzo-voting-repo/Nyzo-voting/master/tst.sh
# chmod +x tst.sh
# nano tst.sh

# ##########################
# =====> ADD YOUR PRIVATE KEYS IN TST.SH, MAKE SURE YOUR NYZOVERIFIER PATH IS CORRECT AS WELL!
# ##########################
# crontab -e
#        add this line:
#        0,14,32,43,51 * * * * cd /voting/; /usr/bin/python3 /voting/voting.py >> /voting/job.log 2>&1
#
# ##########################
# LAST STEP:
# add the list of public identifiers in /voting/randompubids.txt ( 1 line = 1 public identifier )
# the list by chase s can be added with:
# wget https://raw.githubusercontent.com/nyzo-voting-repo/v01/master/randompubids.txt
# chmod +x randompubids.txt

import requests
from bs4 import BeautifulSoup
import subprocess
import os
import ast

mesh_url = 'http://nyzo.co/mesh'

in_x_blocks_end = ')</h3></div></div><div id="meshSection1">'
start_pos_filter = 'italic;">Current cycle:'
end_pos_filter = '.cycle-event a:link { text-decoration: none; } .cycle-event a:hover { text-decoration:'

request_url = requests.get(mesh_url)
page_decoded = request_url.content.decode('utf-8')
start_position = page_decoded.find(start_pos_filter)
end_position = page_decoded.find(end_pos_filter)
cycle_page = str(page_decoded[start_position: end_position])

in_x_blocks_end_position = page_decoded.find(in_x_blocks_end)
in_x_blocks_start_position = in_x_blocks_end_position - 40
in_x_blocks_blob = str(page_decoded[in_x_blocks_start_position:in_x_blocks_end_position])
in_x_blocks_blob_list = in_x_blocks_blob.split()
new_node_in_blocks = int(in_x_blocks_blob_list[-2])
new_node_past_height = int(in_x_blocks_blob_list[-4])

start_pos_filter = 'italic;">Verifiers waiting'
end_pos_filter = 'catch (error) { } }, 1000);</script></body></html>'
start_position = page_decoded.find(start_pos_filter)
end_position = page_decoded.find(end_pos_filter)
queue_page = str(page_decoded[start_position: end_position])

soup = BeautifulSoup(cycle_page, "lxml")
cycle_ids = []
for link in soup.findAll('a'):
    pre_url = link.get('href')
    pub_id = pre_url[11:]
    cycle_ids.append(pub_id)

soup = BeautifulSoup(queue_page, "lxml")
queue_ids = []
for link in soup.findAll('a'):
    pre_url = link.get('href')
    style = link.get('style')
    pub_id = pre_url[11:]
    if style is None or len(style) < 1:
        queue_ids.append(pub_id)
    else:
        print('skipped adding ' + pub_id + ' due to ' + style)

line_list = []
with open('randompubids.txt', 'r') as file:
    lines = file.readlines()
    for line in lines:
        line = line.rstrip()
        line_list.append(line)

for x in cycle_ids:
    for entry in line_list:
        short1_candidate = entry[:4]
        short2_candidate = entry[63:]
        short_candidate = (short1_candidate + '.' + short2_candidate).rstrip()
        if short_candidate in x:
            line_list.remove(entry)
            print(short_candidate, 'was found in the cycle. Removed from line_list. Going to the next candidate.')

if os.path.exists('last_vote.txt'):
    with open('last_vote.txt', 'r') as file:
        for line in file:
            if len(line) > 1:
                last_vote_list = ast.literal_eval(line)
                prev_voted = last_vote_list[0]
                prev_vote_state = last_vote_list[1]
            else:
                prev_voted = None
                prev_vote_state = None
else:
    with open('last_vote.txt', 'w') as file:
        generic_list = [None, None]
        file.write(str(generic_list))

        prev_voted = None
        prev_vote_state = None


def new_node_in_blocks_critical():
    if new_node_in_blocks > 1:
        return False
    if new_node_in_blocks == 1:
        return True


def is_entry_not_prev_voted(y):
    if y != prev_voted:
        return True
    else:
        return False


def vote_barrier(z):
    if new_node_in_blocks_critical() is False:
        print('Vote granted for ' + z + '. However, the node does not have to join yet, we start assigning '
              'states after the node is expected to do something')
        return True
    elif new_node_in_blocks_critical() is True:
        if prev_voted and prev_vote_state is not None:
            if z != prev_voted:
                print(z)
                print(prev_voted)
                print('Vote granted for ' + z + ' this is the first time we are voting for this node')
                return True
            elif z == prev_voted:
                if prev_vote_state == 0 or prev_vote_state == 1 or prev_vote_state == 2:
                    print('Vote granted for ' + z + ' we are '
                                                        'giving the node time, current state: ' + str(prev_vote_state))
                    return True
                if prev_vote_state >= 3:
                    print('Vote denied for ' + z + ', time is up!')
                    return False

                # example scenario: node is voted for and countdown hits 1 block, within 15 minutes
                # the state is changed to 1, within 30 minutes to 2 and
                # within 45 minutes the node will be blacklisted and
                # someone else will be voted for.

                # top voted verifiers get demoted after cycle_length * 2 + 3 + 50
                # current cycle = ( 500 * 2 ) + 3 + 50 = 122.85 minutes
                # we are well within spec and bad node pruning is accelerated 400% compared to nyzo demotion method

        else:
            print('Vote granted for ' + z + ', we have no history yet.')
            return True


def return_state():
    if prev_voted and prev_vote_state is not None:
        return prev_vote_state
    else:
        return 0


remove_list = []

for entry in line_list:
    short1_candidate = entry[:4]
    short2_candidate = entry[63:]
    short_candidate = (short1_candidate + '.' + short2_candidate).rstrip()
    if short_candidate in queue_ids:

        if vote_barrier(entry) is False:
            remove_list.append(entry)
            print(short_candidate, 'was denied entry by vote_barrier and removed from the list')
            continue
            # entry has been denied by the vote_barrier, we will continue to the next entry in line_list
            # because entry has been denied by vote_barrier, this node will be removed from the list
            # we break to the next node in our loop

        elif vote_barrier(entry) is True:
            for e in remove_list:
                line_list.remove(e)

            print('Rewriting randompubids.txt sans in_cycle and vote_barrier nodes')
            with open('randompubids.txt', 'w') as file:
                print(len(line_list))
                for x in line_list:
                    file.write(x + '\n')  # any changes are written to file (in-cycle nodes and vote_barrier blocks)

            if is_entry_not_prev_voted(entry) is True:
                if new_node_in_blocks_critical() is False:
                    print('Assigning state 0 to ' + entry)
                    state = 0
                elif new_node_in_blocks_critical() is True:  # *
                    print('Assigning state 1 to ' + entry)
                    state = 1
            else:  # we are determining if we want to increase the state,
                #  we only need to increase the state if it is critical to do so (new node in blocks = 1 *)
                #  using a fixed state for a new node, otherwise it would keep counting upon previous states
                if new_node_in_blocks_critical() is False:
                    state = return_state()
                    print('New node in blocks is not critical. Assigning state ' + str(state) + ' to ' + entry)
                elif new_node_in_blocks_critical() is True:  # *
                    state = return_state() + 1
                    print('New node in blocks IS critical. Assigning state '
                          + str(state-1) + ' + 1 (' + str(state) + ' to ' + entry)

            with open('last_vote.txt', 'w') as file:
                last_vote_list = [entry, state]
                file.write(str(last_vote_list))

            subprocess.check_call(['/voting/tst.sh', str(entry)])  # voting script is initiated
            print('I just voted for ' + str(entry))
            quit()  # python script is ended, loop has ended

tst.sh:

#!/bin/sh
# change path if necessary, amazon servers path might be something like this: /nyzoVerifier/build/libs/.....
sudo java -jar /home/ubuntu/nyzoVerifier/build/libs/nyzoVerifier-1.0.jar co.nyzo.verifier.scripts.NewVerifierVoteOverrideRequestScript YOUR-INCYCLE-VERIFIER-PRIVATE-KEY $1 &
sudo java -jar /home/ubuntu/nyzoVerifier/build/libs/nyzoVerifier-1.0.jar co.nyzo.verifier.scripts.NewVerifierVoteOverrideRequestScript YOUR-INCYCLE-VERIFIER-PRIVATE-KEY $1 &
sudo java -jar /home/ubuntu/nyzoVerifier/build/libs/nyzoVerifier-1.0.jar co.nyzo.verifier.scripts.NewVerifierVoteOverrideRequestScript YOUR-INCYCLE-VERIFIER-PRIVATE-KEY $1 &
sudo java -jar /home/ubuntu/nyzoVerifier/build/libs/nyzoVerifier-1.0.jar co.nyzo.verifier.scripts.NewVerifierVoteOverrideRequestScript YOUR-INCYCLE-VERIFIER-PRIVATE-KEY $1 &
sudo java -jar /home/ubuntu/nyzoVerifier/build/libs/nyzoVerifier-1.0.jar co.nyzo.verifier.scripts.NewVerifierVoteOverrideRequestScript YOUR-INCYCLE-VERIFIER-PRIVATE-KEY $1 &
sudo java -jar /home/ubuntu/nyzoVerifier/build/libs/nyzoVerifier-1.0.jar co.nyzo.verifier.scripts.NewVerifierVoteOverrideRequestScript YOUR-INCYCLE-VERIFIER-PRIVATE-KEY $1
sudo java -jar /home/ubuntu/nyzoVerifier/build/libs/nyzoVerifier-1.0.jar co.nyzo.verifier.scripts.NewVerifierVoteOverrideRequestScript YOUR-INCYCLE-VERIFIER-PRIVATE-KEY $1 &
sudo java -jar /home/ubuntu/nyzoVerifier/build/libs/nyzoVerifier-1.0.jar co.nyzo.verifier.scripts.NewVerifierVoteOverrideRequestScript YOUR-INCYCLE-VERIFIER-PRIVATE-KEY $1 &
sudo java -jar /home/ubuntu/nyzoVerifier/build/libs/nyzoVerifier-1.0.jar co.nyzo.verifier.scripts.NewVerifierVoteOverrideRequestScript YOUR-INCYCLE-VERIFIER-PRIVATE-KEY $1 &
sudo java -jar /home/ubuntu/nyzoVerifier/build/libs/nyzoVerifier-1.0.jar co.nyzo.verifier.scripts.NewVerifierVoteOverrideRequestScript YOUR-INCYCLE-VERIFIER-PRIVATE-KEY $1 &
sudo java -jar /home/ubuntu/nyzoVerifier/build/libs/nyzoVerifier-1.0.jar co.nyzo.verifier.scripts.NewVerifierVoteOverrideRequestScript YOUR-INCYCLE-VERIFIER-PRIVATE-KEY $1 &
sudo java -jar /home/ubuntu/nyzoVerifier/build/libs/nyzoVerifier-1.0.jar co.nyzo.verifier.scripts.NewVerifierVoteOverrideRequestScript YOUR-INCYCLE-VERIFIER-PRIVATE-KEY $1
sudo java -jar /home/ubuntu/nyzoVerifier/build/libs/nyzoVerifier-1.0.jar co.nyzo.verifier.scripts.NewVerifierVoteOverrideRequestScript YOUR-INCYCLE-VERIFIER-PRIVATE-KEY $1 &
sudo java -jar /home/ubuntu/nyzoVerifier/build/libs/nyzoVerifier-1.0.jar co.nyzo.verifier.scripts.NewVerifierVoteOverrideRequestScript YOUR-INCYCLE-VERIFIER-PRIVATE-KEY $1 &
sudo java -jar /home/ubuntu/nyzoVerifier/build/libs/nyzoVerifier-1.0.jar co.nyzo.verifier.scripts.NewVerifierVoteOverrideRequestScript YOUR-INCYCLE-VERIFIER-PRIVATE-KEY $1 &
sudo java -jar /home/ubuntu/nyzoVerifier/build/libs/nyzoVerifier-1.0.jar co.nyzo.verifier.scripts.NewVerifierVoteOverrideRequestScript YOUR-INCYCLE-VERIFIER-PRIVATE-KEY $1 &
sudo java -jar /home/ubuntu/nyzoVerifier/build/libs/nyzoVerifier-1.0.jar co.nyzo.verifier.scripts.NewVerifierVoteOverrideRequestScript YOUR-INCYCLE-VERIFIER-PRIVATE-KEY $1 &
sudo java -jar /home/ubuntu/nyzoVerifier/build/libs/nyzoVerifier-1.0.jar co.nyzo.verifier.scripts.NewVerifierVoteOverrideRequestScript YOUR-INCYCLE-VERIFIER-PRIVATE-KEY $1
sudo java -jar /home/ubuntu/nyzoVerifier/build/libs/nyzoVerifier-1.0.jar co.nyzo.verifier.scripts.NewVerifierVoteOverrideRequestScript YOUR-INCYCLE-VERIFIER-PRIVATE-KEY $1 &
sudo java -jar /home/ubuntu/nyzoVerifier/build/libs/nyzoVerifier-1.0.jar co.nyzo.verifier.scripts.NewVerifierVoteOverrideRequestScript YOUR-INCYCLE-VERIFIER-PRIVATE-KEY $1 &
sudo java -jar /home/ubuntu/nyzoVerifier/build/libs/nyzoVerifier-1.0.jar co.nyzo.verifier.scripts.NewVerifierVoteOverrideRequestScript YOUR-INCYCLE-VERIFIER-PRIVATE-KEY $1 &
sudo java -jar /home/ubuntu/nyzoVerifier/build/libs/nyzoVerifier-1.0.jar co.nyzo.verifier.scripts.NewVerifierVoteOverrideRequestScript YOUR-INCYCLE-VERIFIER-PRIVATE-KEY $1 &
sudo java -jar /home/ubuntu/nyzoVerifier/build/libs/nyzoVerifier-1.0.jar co.nyzo.verifier.scripts.NewVerifierVoteOverrideRequestScript YOUR-INCYCLE-VERIFIER-PRIVATE-KEY $1 &
sudo java -jar /home/ubuntu/nyzoVerifier/build/libs/nyzoVerifier-1.0.jar co.nyzo.verifier.scripts.NewVerifierVoteOverrideRequestScript YOUR-INCYCLE-VERIFIER-PRIVATE-KEY $1

One thought on “Nyzo manual autovoting

  1. Pingback: Nyzo Review • Proof Of Diversity Cryptocurrency • MyAltcoins

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.