Here are some simulations of blockchain consensus protocol based on NS3, which aims to simulate the relationship between blockchain performance and consensus protocol, network scale, block size, bandwidth, delay and other factors.
The version 3.29 or 3.25 of NS3 is recommended.
Next, you need to place all the files from blockchain-simulator to the respective folders under ns-allinone-3.xx/ns-3.xx
.
The path of the wscript file is ns-allinone-3.xx/ns-3.xx/src/applications/wscript
- Add the following lines in module.source:
'model/raft-node.cc',
'helper/network-helper.cc',
- Add the following lines in headers.source:
'model/raft-node.h',
'helper/network-helper.h',
Under path ns-allinone-3.xx/ns-3.xx
, execute the following commands in sequence:
CXXFLAGS="-std=c++11 -Wno-unused-parameter" ./waf configure
./waf
./waf --run scratch/blockchain-simulator
You can set the network scale and other factors in blockchain-simulator.cc
.
More detailed usage use of NS3 can be found in https://github.com/arthurgervais/Bitcoin-Simulator
There are three consensus protocols to choose from, including raft, paxos and pbft, The default is raft. If you need to switch the consensus protocol, such as from raft to pbft, You need to modify some files.
Modify the class name "RaftNode" to "PbftNode":
LogComponentEnable ("PbftNode", LOG_LEVEL_INFO);
Modify all "RaftNode" to "PbftNode", and switch the reference of the header file.
Modify the "raft-node" to "pbft-node" in module.source
and headers.source
. The two cannot coexist, otherwise an error will be reported.
After modification, you need to recompile and run.