To start your peer, follow these steps:
- Open a terminal.
- Run the following command:
python main.py [arguments]
[ip]
: optional ip address in format192.168.y.x
for host, by default it'ssilicon.cs.umanitoba.ca
[port]
: optional port number, by default it's8793
- ...
The synchronization process may take approximately 1.5
minutes. During synchronization, you can expect to see on the terminal, all the blocks, gossips and stats that have been requested or responded to.
The consensus code for choosing which chain to synchronize is located in the file main.py
at lines 202-224
. It picks chains by doing the following:
- iterating through the
chains
list, which contains stats of all peers that answered before timeout. - It identifies the chain with the maximum height (
max_height
)- In the case of a tie, it appends all chains with the same height and matching top hash to the
longest_chains
list.
- In the case of a tie, it appends all chains with the same height and matching top hash to the
- It updates the list of tracked peers (
tracked_peers
) based on the chosen longest chains and returns the list of longest chains.
The cleanup process for peers can be found in the file main.py
at lines 262-266, 113-116
. It cleans up peers by doing the following:
- Every peer has an instance variable of
last_message_time
that keeps track of the last time a message was receivedlast_message_time
changes every timehandle_msg
is called since it holds tuple of an address which I find the peer associated with, by callingfind_peer_by_addr
- The peers finally get cleaned up by comparing every peer's
last_message_time
tocurrent_time
with the constantCLEANUP_INTERVAL
added tolast_message_time
which is false, it kicks out that peer from the peer list