Skip to content

lwangreen/Blockchain_simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to run:
python BlockchainSimulator.py -c [CONTACT_FREQUENCY] -t [TRANSACTION_RATE] --RANDOM_TRANS [True or False] --RANDOM_WINNERS [True or False] --RANDOM_CONNECT [True or False] --RANDOM_START_CONNECT [True or False]

Or simply run any of the .bat file.


Simulator Concepts:

Number of nodes: 20


Time unit: 600s
Mining winners: the winners are randomly chosen. Only 3 winners at most within a time unit.
Winners always generate new block no matter whether the incomplete transaction list is empty.


Keywords:
RANDOM_TRANS: _RT, random transactions
RANDOM_WINNERS: _RW, random winner
RANDOM_CONNECTION_TIME: _RC, random connection time to Internet
RANDOM_START_CONNECTION_TIME: _RSC, random start connection time to Internet for each node. It is randomly generated at the beginning of the simulation, but won't be changed during the simulation.
CONTACT_FREQ: contact frequency, the idle time of the connection between a node and Internet.
TRANS_RATE: transaction generation rate, the average number of transaction generated by a single node within a time unit (600s).


Input files:
transactions.txt: the transaction records.
Transaction format: [time, sender, recipient, amount]
Max transaction time: 85000 seconds
The transaction senders and recipients are selected randomly from nodes pool.
Number of transactions: 
transaction_1.txt: 2680
transaction_2.txt: 5360
transaction_3.txt: 8040

winners.txt: the winners. Max simulation time for winners: 1000000 seconds

Output files:
./Log:
filename format: [time]_[contact frequency]_[transaction rate]_[random transaction]_[random winner]_[random Internet connection time interval within a range]_[random start connecting to Internet time].txt
It displays all the blockchains exist in the simulator, and the owners for each blockchain.
Block difference section displays the blocks that different to other chain.

./Stats:
filename format: statistics_[random winner]_[random Internet connection time interval within a range]_[random start connecting to Internet time].csv
No keyword in the finame means the associate parameter is set to False.


Important ideas:

Block structure:
	-Index: block index
	-Transactions: the approved transaction list
	-previous_hash: previous block hash value
	-block generator: who genereates the current block
	-time: the timestamp of when the block is generated

Mining: Unlike Bitcoin Blockchain, there is not a particular solution for minning puzzle. The winners are selected from the pre-generated winners.txt file. The chosen node will generate a new block and append it to the blockchain.
             No more than 3 winners within a time unit. The mempool (pending transaction list) is emptied when a new block is generated without care about block size.

Resolve conflict: 
	-Nodes always update its blockchain to the longer one.
	-The transactions that in the mempool will be removed if they are already in the longer chain
	-The transactions in the approved transaction list are appended back to the mempool if they are not in the longer chain
	
Simulation stopping case: The simulation is stopped when all the nodes have an identical chain that covers all the transactions.


Procedures:
-While simulation time is not finish or nodes don't have an identical blockchain:
	-Within a time slot:
		- retrieve transactions from file (or randomly generate)
		- retrieve winners from file (or randomly generate)
		- winners generate new block
		- LOOP through pair-wise nodes:
			- if they are currently connecting to Internet:
				- broadcast incomplete transactions
				- resolve conflict
	- Move to next time slot
- Write blockchain information and statistics into appropriate files

Mistakes:
Wrong understanding on 6 blocks convention. Need to fix the code (and the statistics recollection and graph generation etc......).
Statistics is stored under the path /Blockchain statistics backup/Blockchain DTN

About

blockchain simulator

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages