Coder Social home page Coder Social logo

zhayujie / blockchain-simulator Goto Github PK

View Code? Open in Web Editor NEW
39.0 3.0 11.0 47 KB

Some simulations of blockchain consensus based on ns3. Currently implemented consensus protocols include Raft, Paxos and PBFT.

License: MIT License

C++ 100.00%
ns3-simulator paxos pbft raft

blockchain-simulator's Introduction

blockchain-simulator

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.

Quick start

1.Download ns3

The version 3.29 or 3.25 of NS3 is recommended.

2.Place code

Next, you need to place all the files from blockchain-simulator to the respective folders under ns-allinone-3.xx/ns-3.xx.

3.Update the wscript file

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', 

4.Build and run the simulator

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

Switch consensus

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.

1.Update the blockchain-simulator.cc

Modify the class name "RaftNode" to "PbftNode":

LogComponentEnable ("PbftNode", LOG_LEVEL_INFO);

2.Update the network-helper.cc

Modify all "RaftNode" to "PbftNode", and switch the reference of the header file.

3.Update the wscript

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.

blockchain-simulator's People

Contributors

zhayujie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

blockchain-simulator's Issues

Error in simulation

Hi, I try to run the code but I get this error:

/workspace/ns-allinone-3.25/ns-3.25$ ./waf --run scratch/blockchain-simulator

Waf: Leaving directory `/home/rabeb/workspace/ns-allinone-3.25/ns-3.25/build'
Build failed
-> task in 'ns3-applications' failed (exit status 1):
{task 140411083174544: cxx network-helper.cc -> network-helper.cc.1.o}
['/usr/bin/g++', '-std=c++11', '-Wno-unused-parameter', '-fPIC', '-pthread', '-I.', '-I..', '-DNS3_BUILD_PROFILE_DEBUG', '-DNS3_ASSERT_ENABLE', '-DNS3_LOG_ENABLE', '-DHAVE_SYS_IOCTL_H=1', '-DHAVE_IF_NETS_H=1', '-DHAVE_NET_ETHERNET_H=1', '-DHAVE_PACKET_H=1', '-DHAVE_IF_TUN_H=1', '../src/applications/helper/network-helper.cc', '-c', '-o', '/home/rabeb/workspace/ns-allinone-3.25/ns-3.25/build/src/applications/helper/network-helper.cc.1.o']

Could you help me, please?
Thank you

Error in the simulation

Hi, I try to run the code but I get this error:

zakaria@ubuntu:~/ns-allinone-3.25/ns-3.25$ ./waf --run scratch/blockchain-simulator
Waf: Entering directory /home/zakaria/ns-allinone-3.25/ns-3.25/build' Waf: Leaving directory /home/zakaria/ns-allinone-3.25/ns-3.25/build'
Build commands will be stored in build/compile_commands.json
'build' finished successfully (0.910s)
node0 start
node1 start
node2 start
node3 start
node4 start
node5 start
node6 start
node7 start
node8 start
node9 start
node10 start
node11 start
node12 start
node13 start
node14 start
node15 start
assert failed. cond="cur->tid != tag.GetInstanceTypeId ()", msg="Error: cannot add the same kind of tag twice.", file=../src/network/model/packet-tag-list.cc, line=250
terminate called without an active exception
Command ['/home/zakaria/ns-allinone-3.25/ns-3.25/build/scratch/blockchain-simulator'] terminated with signal SIGIOT. Run it under a debugger to get more information (./waf --run --command-template="gdb --args %s ").

Could you help me, please?
Regards,
Zakaria.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.