区块链仿真工具SimBlock使用

news2025/2/27 23:49:31

1. Environment requirements

SimBlock 可以在 Windows、MacOS、Ubuntu Linux 或任何支持 Java 的 Unix 平台上运行。

它需要以下版本的 JDK 和 Gradle。

请注意,SimBlock 的仓库中包含 Gradle Wrapper,因此您也可以自动安装 Gradle(我们稍后会提到)。

Software

Version

JDK

1.8.0 or later

Gradle

5.1.1 or later

2. 下载

Download the SimBlock repository as a zip file from GitHub and unzip, or clone the repository.

Release list: Releases · dsg-titech/simblock · GitHub
Command for clone: $ git clone git@github.com:dsg-titech/simblock.git

从GitHub和Unzip下载Simblock存储库作为ZIP文件,或克隆存储库。

发布列表:Releases · dsg-titech/simblock · GitHub

克隆命令:$ git clone git@github.com:dsg-titech/simblock.git

我的命令:

  1. wget https://github.com/dsg-titech/simblock/archive/refs/tags/v0.8.0.zip
  2. unzip v0.8.0.zip

2-a. 目录结构

The structure of the unzipped or cloned directory is as follows:(解压缩或者克隆后的目录结构如下所示)

simblock
+-- docs
+-- gradle
|   +-- wrapper
+-- simulator
    +-- src
        +-- dist
        |   +-- conf
        |   +-- out
        |       +-- graph
        +-- main
            +-- java
                +-- SimBlock
                    +-- ...
                    :

Directory 目录

Description 描述

docs

Documents about SimBlock (e.g., user manual)

gradle/wrapper

For Gradle wrapper

simulator/src/dist/conf

Directory in which to place the files that simulator reads

simulator/src/dist/out

Directory where files output by simulator are stored

simulator/src/main/java/SimBlock

Source codes

3. Build

此后,解压缩或克隆的存储库的根目录的名称表示为<root_dir>。

首先,打开一个终端软件(例如xterm,命令提示等),然后来到到<root_dir>目录。

3-a. 如果Gradle 已安装

You can build by the following Gradle command, if you have already installed Gradle.

如果您已经安装了Gradle,则可以通过以下Gradle命令进行构建。

没安装的话安装gradle

$ gradle build

If successful, build directory will be created under <ROOT_DIR>/simulator.

如果成功,将在<ROOT_DIR>/simulator下创建build目录。

<ROOT_DIR>
+-- simulator
    +-- build
        +-- classes
        +-- distributions
        +-- libs
        +-- scripts
        +-- tmp

Directory 目录

Description 说明

simulator/build/classes

Directory where built class files are stored

存储构建类文件的目录

simulator/build/distributions

Directory where distribution archive files (zip, tar) are stored

存储分发存档文件(zip、tar)的目录

simulator/build/libs

Directory where jar files are stored

simulator/build/scripts

Directory where startup scripts are stored

启动脚本的目录

Note that the startup scripts in simulator/build/scripts are generated for inclusion in the distribution archive; if you run the scripts with the directory structure as it is, an error will occur.

请注意,simulator/build/scripts 中的启动脚本是为了包含在分发存档中而生成的;如果按原样运行目录结构的脚本,将出现错误。

3-b. If Gradle is not installed(忽略)

You can use gradlewgradlew.bat, for Windows user)in <ROOT_DIR> instead of running Gradle command.

您可以在<ROOT_DIR>中使用gradlew(gradlew.bat,适用于Windows用户),而不是运行Gradle命令。

$ gradlew build

This is a program called Gradle wrapper, which will automatically install Gradle if it is not installed and call it.

这是一个名为Gradle包装器的程序,如果未安装Gradle,它将自动安装Gradle并调用它

3-c. Discard build products(忽略)

The following Gradle command will delete the files generated by the above build process.

以下Gradle命令将删除上述构建过程生成的文件。

$ gradle clean

You can also instruct the execution of clean and build at one time as follows:

您还可以指示一次执行清理和构建,如下所示:

$ gradle clean build

在这种情况下,构建是在清理后执行的

4. Run SimBlock

There are two main ways to run SimBlock: by using Gradle command and by using build products.

4-a. Run with Gradle command

Run following Gradle command in <ROOT_DIR>, then the simulator starts up.

$ gradle :simulator:run

Output files of the simulator will be stored in <ROOT_DIR>/simulator/src/dist/output.

到这里已经成功运行,我们可以将/simulator/src/dist/output/output.json上传到SimBlock Visualizer来可视化区块链仿真:

当然,可以继续看下面的介绍来属性simbolck的使用。

4-b. Run with build product(忽略)

Extract the distribution archive (zip, tar) of <ROOT_DIR>/simulator/build/distributions. Then, the following directory structure will be created.

SimBlock
+-- bin
+-- conf
+-- lib
+-- output

A script for execution is in bin directory.

By executing runSimBlock (runSimBlock.bat for Windows) in the terminal, the simulator starts up.

Output files of the simulator will be stored in output directory.

4-c. Other ways(忽略)

The extracted distribution archive contains the jar file of SimBlock (lib/simulator.jar). Of course, it is also possible to execute this jar file directly with the java command. Note that it is required to set the classpath appropriately.

You can also run SimBlock on IDEs, such as Eclipse. It is explained later in the section of "Import to IDE".

5. 仿真参数

参数

定义的位置

描述

区域列表

BlockChainSimulator.settings.NetworkConfiguration#REGION_LIST

节点可以存在的区域列表。

延迟列表

BlockChainSimulator.settings.NetworkConfiguration#LATENCY

分配给每个区域的延迟列表。(单位:毫秒)

上传带宽列表

BlockChainSimulator.settings.NetworkConfiguration#UPLOAD_BANDWIDTH

分配给每个区域的上传带宽列表。(单位:比特每秒)

下载带宽列表

BlockChainSimulator.settings.NetworkConfiguration#DOWNLOAD_BANDWIDTH

分配给每个区域的下载带宽列表。(单位:比特每秒)

区域分布

BlockChainSimulator.settings.NetworkConfiguration#REGION_DISTRIBUTION

节点区域的分布。每个值表示该区域内节点数量与所有节点数量之比。

度数分布

BlockChainSimulator.settings.SimulationConfiguration#DEGREE_DISTRIBUTION

出站连接数的累积分布。参考:Andrew Miller 等人,“Discovering bitcoin's public topology and influential nodes”,2015年。

节点数量

BlockChainSimulator.settings.SimulationConfiguration#NUM_OF_NODES

参与区块链网络的节点数量。

路由表

BlockChainSimulator.settings.SimulationConfiguration#TABLE

路由表的种类。

区块间隔

BlockChainSimulator.settings.SimulationConfiguration#INTERVAL

区块生成间隔的期望值。挖矿难度会根据该值和挖矿能力的总和自动调整。(单位:毫秒)

平均挖矿能力

BlockChainSimulator.settings.SimulationConfiguration#AVERAGE_MINING_POWER

每个节点的平均挖矿能力。挖矿能力对应于比特币中的哈希率,即每毫秒执行的挖矿(哈希计算)次数。

挖矿能力标准差

BlockChainSimulator.settings.SimulationConfiguration#STDEV_OF_MINING_POWER

每个节点的挖矿能力根据正态分布随机确定,其均值为 AVERAGE_MINING_POWER,标准差为 STDEV_OF_MINING_POWER。

最大区块高度

BlockChainSimulator.settings.SimulationConfiguration#END_BLOCK_HEIGHT

模拟结束时的区块高度。

区块大小

BlockChainSimulator.settings.SimulationConfiguration#BLOCK_SIZE

区块大小。(单位:字节)

CBR使用率

BlockChainSimulator.settings.SimulationConfiguration#CBR_USAGE_RATE

紧凑区块中继(CBR)协议的使用率。

节点变动率

BlockChainSimulator.settings.SimulationConfiguration#CHURN_NODE_RATE

造成节点变动的节点比例。

紧凑区块大小

BlockChainSimulator.settings.SimulationConfiguration#COMPACT_BLOCK_SIZE

紧凑区块大小。(单位:字节)

控制节点CBR失败率

BlockChainSimulator.settings.SimulationConfiguration#CBR_FAILURE_RATE_FOR_CONTROL_NODE

始终连接网络的控制节点的CBR失败率。

节点变动节点CBR失败率

BlockChainSimulator.settings.SimulationConfiguration#CBR_FAILURE_RATE_FOR_CHURN_NODE

造成节点变动的节点的CBR失败率。

控制节点CBR失败区块大小分布

BlockChainSimulator.settings.SimulationConfiguration#CBR_FAILURE_BLOCK_SIZE_DISTRIBUTION_FOR_CONTROL_NODE

控制节点在CBR失败时接收的数据大小分布。

节点变动节点CBR失败区块大小分布

BlockChainSimulator.settings.SimulationConfiguration#CBR_FAILURE_BLOCK_SIZE_DISTRIBUTION_FOR_CHURN_NODE

变动节点在CBR失败时接收的数据大小分布。

SimBlock.settings package has two classes which have these parameters: NetworkConfiguration.java and SimulationConfiguration.java. The former has parameters related to network parameters, and the latter has blockchain parameters. By changing these parameters and doing build, you can conduct different patterns of simulation.( SimBlock.settings 包含两个类,它们具有这些参数:NetworkConfiguration.java 和 SimulationConfiguration.java。前者包含与网络参数相关的参数,后者包含与区块链参数相关的参数。通过修改这些参数并进行构建,可以进行不同模式的模拟。 )

6. Output

模拟器将模拟结果输出到标准输出和一些文件。文件输出位置为

<ROOT_DIR>/simulator/src/dist/out(通过 Gradle 命令执行时)以及 SimBlock/output(通过构建产品运行时)。输出内容如下:

  • Standard output and out.txt
    • The following is listed under block ID
      • <node ID, propagation time>
        • Propagation time: The time from when the block of the block ID is generated to when the node of the node ID is reached.
  • Blocklist.txt
    • <fork information, block height, block ID>
      • Fork information: One of "OnChain" and "Orphan". "OnChain" denote block is on Main chain. "Orphan" denote block is an orphan block.
  • graph/
    • ${number}.txt: Network information when block height is ${number}
      • <node ID, node ID>
        • Connection from left node ID to right node ID.
  • output.json
    • This file is listing occurred events. By uploading this file into SimBlock Visualizer, you can see the visualization.
      • <event, content>
      • Event
        • add-link: Add a node to neighbor nodes.
        • remove-link: Remove a node from neighbor nodes.
        • flow-block: Block transmmission.
        • simulation-end: Simulation end.
      • content
        • timestamp: Order of events.
        • block-id: Block id.
        • transmission-timestamp: Timestamp when a block is transmitted.
        • reception-timestamp: Timestamp when a block is recieved.
        • begin-node-id: Source node.
        • end-node-id: End node.

7. Import to IDE

By using Gradle, you can generate configuration files of an IDE and easily import them into it.

通过使用 Gradle,您可以生成 IDE 的配置文件,并轻松地将其导入到 IDE 中。

7-a. For IntelliJ IDEA

By executing the following Gradle command, configuration files for IntelliJ IDEA are generated.

$ gradle idea

Generated files are listed as follows:

File

<ROOT_DIR>/<ROOT_DIR>.iml

<ROOT_DIR>/<ROOT_DIR>.ipr

<ROOT_DIR>/<ROOT_DIR>.iws

<ROOT_DIR>/simulator/simulator.iml

With IntelliJ IDEA, select File -> Open and select <ROOT_DIR>.ipr. <ROOT_DIR>/simulator will be imported as a module.

Then, you can run the simulator with the IDE. For example, select <ROOT_DIR>/simulator/src/main/java/SimBlock/simulator/Main.java from the tool window of the project structure, right click and execute Run 'Main.main ()'. Output files will be stored in <ROOT_DIR>/simulator/src/dist/output. Do not import as Gradle project if offered.

Discard products

The following Gradle command will delete the files generated by $ gradle idea. Note that <ROOT_DIR>.iws file will not be deleted. Also, if the project is left open in the IDE, the deleted files may be automatically regenerated by the IDE.)

$ gradle cleanIdea

You can also instruct the execution of cleanIdea and idea at one time as follows:

$ gradle cleanIdea idea

In this case, idea is executed after cleanIdea.

7-b. For Eclipse

By executing the following Gradle command, configuration files for Eclipse are generated.

$ gradle eclipse

Generated files are listed as follows:

File

<ROOT_DIR>/.project

<ROOT_DIR>/simulator/.classpath

<ROOT_DIR>/simulator/.project

<ROOT_DIR>/simulator/.settings

With Eclipse, select File -> Open Projects from File System and select <ROOT_DIR> as Import source. Check the listed two Eclipse projects, and click Finish. <ROOT_DIR>/simulator and <ROOT_DIR> will be imported as a project respectively.

Then, you can run the simulator with the IDE. For example, select the simulator project from Package Explorer, right-click and execute Run As -> Java Application to start the simulator. Output files will be stored in <ROOT_DIR>/simulator/src/dist/output.

Discard products

The following Gradle command will delete the files generated by $ gradle eclipse.

$ gradle cleanEclipse

You can also instruct the execution of cleanEclipse and eclipse at one time as follows:

$ gradle cleanEclipse eclipse

In this case, eclipse is executed after cleanEclipse.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2307095.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

面试八股文--数据库基础知识总结(2) MySQL

本文介绍关于MySQL的相关面试知识 一、关系型数据库 1、定义 关系型数据库&#xff08;Relational Database&#xff09;是一种基于关系模型的数据库管理系统&#xff08;DBMS&#xff09;&#xff0c;它将数据存储在表格&#xff08;表&#xff09;中&#xff0c;并通过表格…

江协科技/江科大-51单片机入门教程——P[1-3] 单片机及开发板介绍

前言&#xff1a;本节主要的任务是了解一下 51 单片机和所用的普中51开发板。 目录 一、单片机介绍 二、单片机的应用领域 三、STC89C52单片机 四、命名规则 五、单片机内部拆解 六、单片机内部结构图 七、单片机管脚图 八、单片机最小系统 九、开发板介绍 十、开发…

【Uniapp-Vue3】导入uni-id用户体系

在uniapp官网的uniCloud中下载uni-id用户体系 或者直接进入加载&#xff0c;下载地址&#xff1a;uni-id-pages - DCloud 插件市场 进入以后下载插件&#xff0c;打开HbuilderX 选中项目&#xff0c;点击确定 点击跳过 点击合并 右键uniCloud文件夹下的database文件夹&#x…

如何免费使用稳定的deepseek

0、背景&#xff1a; 在AI辅助工作中&#xff0c;除了使用cursor做编程外&#xff0c;使用deepseek R1进行问题分析、数据分析、代码分析效果非常好。现在我经常会去拿行业信息、遇到的问题等去咨询R1&#xff0c;也给了自己不少启示。但是由于官网稳定性很差&#xff0c;很多…

基于 ‌MySQL 数据库‌对三级视图(用户视图、DBA视图、内部视图)的详细解释

基于 ‌MySQL 数据库‌对三级视图&#xff08;用户视图、DBA视图、内部视图&#xff09;的详细解释&#xff0c;结合理论与实际操作说明&#xff1a; 一、三级视图核心概念 数据库的三级视图是 ANSI/SPARC 体系结构的核心思想&#xff0c;MySQL 的实现逻辑如下&#xff1a; …

easyexcel和poi同时存在版本问题,使用easyexcel导出excel设置日期格式

这两天在使用easyexcel导出excel的时候日期格式全都是字符串导致导出的excel列无法筛选 后来调整了一下终于弄好了&#xff0c;看一下最终效果 这里涉及到easyexcel和poi版本冲突的问题&#xff0c;一直没搞定&#xff0c;最后狠下心来把所有的都升级到了最新版&#xff0c;然…

取topN不同算法的实现的性能差别

背景 最近在实现一个需求&#xff0c;需要对大量数据中排序出前N&#xff0c;最暴力的方法肯定是直接全量排序。这里很明显是可以不用全量排序的&#xff0c;取前N&#xff0c;我们自然而然可以想到一个算法——堆排序。 一开始自己先写好了一版&#xff0c;后来想起&#xff…

【实战 ES】实战 Elasticsearch:快速上手与深度实践-1.1.2典型应用场景:日志分析、实时搜索、推荐系统

&#x1f449; 点击关注不迷路 &#x1f449; 点击关注不迷路 &#x1f449; 点击关注不迷路 文章大纲 为什么选择Elasticsearch&#xff1f;——典型应用场景深度解析1. 引言2. 日志分析&#xff1a;海量数据的实时洞察2.1 行业痛点2.2 ES解决方案关键技术实现&#xff1a; 2.…

Spring Cloud Alibaba学习 3- Sentinel入门使用

Spring Cloud Alibaba学习 3- Sentinel入门使用 中文文档参考&#xff1a;Sentinel中文文档 一. SpringCloud整合Sentinel 1.1 下载Sentinel-Dashboard Sentinel下载地址&#xff1a;Sentinel-Dashboard 到下载目录&#xff0c;cmd输入 java -jar sentinel-dashboard-1.8…

使用DeepSeek/chatgpt等AI工具辅助网络协议流量数据包分析

随着deepseek,chatgpt等大模型的能力越来越强大&#xff0c;本文将介绍一下deepseek等LLM在分数流量数据包这方面的能力。为需要借助LLM等大模型辅助分析流量数据包的同学提供参考&#xff0c;也了解一下目前是否有必要继续学习wireshark工具以及复杂的协议知识。 pcap格式 目…

C语言 --- 经典习题1

C语言 --- 经典习题1 第 一 题 - - - 交 换 两 个 整 数 的 值&#xff08;四 种 方 法&#xff09;第 二 题 - - - 最 大 公 约 数 和 最 小 公 倍 数 之 和总结 &#x1f4bb;作者简介&#xff1a;曾 与 你 一 样 迷 茫&#xff0c;现 以 经 验 助 你 入 门 C 语 言 &#x1…

自定义mybatis拦截器,在springboot项目中不起作用的解决方法

自定义mybatis拦截器&#xff0c;在springboot项目中不起作用的解决方法 自定义mybatis拦截器&#xff0c;在若依springboot项目中不起作用的原因 找到 MyBatisConfig 配置类&#xff0c;引入自定义配置 在sqlSessionFactory中添加自定义拦截器&#xff0c;就可以正常使用了…

记录一下在k3s快速创建gitlab

废话不多说&#xff0c;直接上配置文件 需要修改的地方&#xff08;备注都有写&#xff09;&#xff1a; 1.命名空间 namespace 2. claimName 文件挂载 Deployment kind: Deployment apiVersion: apps/v1 metadata:name: gitlabnamespace: cicd # 替换为您的命名空间la…

AWQ和GPTQ量化的区别

一、前言 本地化部署deepseek时发现&#xff0c;如果是量化版的deepseek&#xff0c;会节约很多的内容&#xff0c;然后一般有两种量化技术&#xff0c;那么这两种量化技术有什么区别呢&#xff1f; 二、量化技术对比 在模型量化领域&#xff0c;AWQ 和 GPTQ 是两种不同的量…

线性模型 - 支持向量机

支持向量机&#xff08;SVM&#xff09;是一种用于分类&#xff08;和回归&#xff09;的监督学习算法&#xff0c;其主要目标是找到一个最佳决策超平面&#xff0c;将数据点分为不同的类别&#xff0c;并且使得分类边界与最近的数据点之间的间隔&#xff08;margin&#xff09…

湖北中医药大学谱度众合(武汉)生命科技有限公司研究生工作站揭牌

2025年2月11日&#xff0c;湖北中医药大学&谱度众合&#xff08;武汉&#xff09;生命科技有限公司研究生工作站揭牌仪式在武汉生物技术研究院一楼101会议室举行&#xff0c;湖北中医药大学研究生院院长刘娅教授、基础医学院院长孔明望教授、基础医学院赵敏教授、基础医学院…

面试基础---深入解析 AQS

深入解析 AQS&#xff1a;从源码到实践&#xff0c;剖析 ReentrantLock 和 Semaphore 的实现 引言 在 Java 并发编程中&#xff0c;AbstractQueuedSynchronizer&#xff08;AQS&#xff09;是一个核心框架&#xff0c;它为构建锁和其他同步器提供了基础支持。ReentrantLock 和…

从 0 到 1,用 Python 构建超实用 Web 实时聊天应用

从 0 到 1&#xff0c;用 Python 构建超实用 Web 实时聊天应用 本文深入剖析如何运用 Python 的 Flask 框架与 SocketIO 扩展&#xff0c;搭建一个功能完备的 Web 实时聊天应用。从环境搭建、前后端代码实现&#xff0c;到最终运行展示&#xff0c;逐步拆解关键步骤&#xff0…

Vue2+Element实现Excel文件上传下载预览【超详细图解】

目录 一、需求背景 二、落地实现 1.文件上传 图片示例 HTML代码 业务代码 2.文件下载 图片示例 方式一&#xff1a;代码 方式二&#xff1a;代码 3.文件预览 图片示例 方式一&#xff1a;代码 方式二&#xff1a;代码 一、需求背景 在一个愉快的年后&#xff…

[记录贴] 火绒奇怪的进程保护

最近一次更新火绒6.0到最新版&#xff0c;发现processhacker的结束进程功能无法杀掉火绒的进程&#xff0c;弹窗提示如下&#xff1a; 可能是打开进程时做了权限过滤&#xff0c;火绒注册了两个回调函数如下&#xff1a; 但奇怪的是&#xff0c;在另外一台机器上面更新到最新版…