Simulation of a P2P Cryptocurrency Network
For the assignment we have used a python package 'SimPy' to do discrete event simulation in time.
We demonstrate a simulation of
- random peer connections in the network
- random transaction generation by each peer with a value chosen from poisson distribution
- broadcasting the messages (transactions/blocks) in a loopless manner
- simulating network latencies based on propogation delay, message size, link speeds of nodes, and queing delay
- random block creating with arrival times chosen from a poisson distribution
- propogation of blocks on the block chain
- addition of blocks to a local blockchain of a node and resolution of forks based on block arrival time, the chain with first arrived one is extended.
Classes Defined:
- Peer - to define a peer, create a p2p network
- Manager - to simulate each peer in time, a peer manager
- Transaction
- Block
- Blockchain
- Connection - to create a connection bw 2 peers
Input Parameter:
- n = No. of peers
- z = percent of slow nodes
- txn_interval_mean = mean for dist. to choose arrival time from, in ms
- mean_Tk = mean value for dist. for choosing Tk for each node,in ms
- mean_links = mean for binomial dist., higher the value, denser is the network
- SIM_DURATION = duration of simulation in ms
To start the simulation-
- In the project folder, '$python run.py' [with proper arguments].
- To see the network graph, set VISUALIZATION = True in 'run.py', this can be done to check if the graph is connected/ dissconnected.
- At the end of the simulation, for each peer, file having tree at the node is created in the project folder.