├── Resource
├── 2开发者社区中文.jpg
├── 2开发者社区英文(1).jpg
├── 社区奖励机制说明1倍.png
└── 社区奖励机制说明 英文1倍.png
├── Doc
├── SmartMeshWhitePaperCN.pdf
├── SPECTRUM WRITEPAPER(EN).pdf
└── Opporty技术交流文档
│ ├── Status Update 6_26_2018.docx
│ ├── Opporty 3 layered Ecosystem.pptx
│ └── Project Status Update (6_10_2018).docx
├── Github pull request操作说明.pdf
├── Task
├── 长期任务归档
│ ├── img
│ │ ├── Casper+ShardingChainV2.1-01.png
│ │ └── Casper+ShardingChainV2.1-02.png
│ └── 译文-Casper+ShardingChainV2.1.md
├── 长期任务.md
├── 第一期任务归档-20180828
│ ├── task_20180828.rst
│ ├── Spectrum链开发 -- MacOS开发环境搭建.md
│ ├── Spectrum链开发--IDE断点调试.md
│ ├── Spectrum链开发--Linux环境搭建.md
│ ├── Spectrum链开发 -- Windows开发环境搭建.md
│ ├── Spectrum链开发--Windows环境下单元测试.md
│ └── Spectrum链开发--测试网络搭建.md
└── 第二期任务归档-20180911
│ ├── task_20180911.rst
│ ├── Spectrum链主网开发实战篇-主网搭建教程.md
│ └── smt无网微支付解读.md
├── Discussion
└── 2018.8.6_Opporty_CEO技术交流.md
└── README.md
/Resource/2开发者社区中文.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartMeshFoundation/developer-community/HEAD/Resource/2开发者社区中文.jpg
--------------------------------------------------------------------------------
/Resource/2开发者社区英文(1).jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartMeshFoundation/developer-community/HEAD/Resource/2开发者社区英文(1).jpg
--------------------------------------------------------------------------------
/Resource/社区奖励机制说明1倍.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartMeshFoundation/developer-community/HEAD/Resource/社区奖励机制说明1倍.png
--------------------------------------------------------------------------------
/Resource/社区奖励机制说明 英文1倍.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartMeshFoundation/developer-community/HEAD/Resource/社区奖励机制说明 英文1倍.png
--------------------------------------------------------------------------------
/Doc/SmartMeshWhitePaperCN.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartMeshFoundation/developer-community/HEAD/Doc/SmartMeshWhitePaperCN.pdf
--------------------------------------------------------------------------------
/Github pull request操作说明.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartMeshFoundation/developer-community/HEAD/Github pull request操作说明.pdf
--------------------------------------------------------------------------------
/Doc/SPECTRUM WRITEPAPER(EN).pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartMeshFoundation/developer-community/HEAD/Doc/SPECTRUM WRITEPAPER(EN).pdf
--------------------------------------------------------------------------------
/Doc/Opporty技术交流文档/Status Update 6_26_2018.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartMeshFoundation/developer-community/HEAD/Doc/Opporty技术交流文档/Status Update 6_26_2018.docx
--------------------------------------------------------------------------------
/Task/长期任务归档/img/Casper+ShardingChainV2.1-01.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartMeshFoundation/developer-community/HEAD/Task/长期任务归档/img/Casper+ShardingChainV2.1-01.png
--------------------------------------------------------------------------------
/Task/长期任务归档/img/Casper+ShardingChainV2.1-02.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartMeshFoundation/developer-community/HEAD/Task/长期任务归档/img/Casper+ShardingChainV2.1-02.png
--------------------------------------------------------------------------------
/Doc/Opporty技术交流文档/Opporty 3 layered Ecosystem.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartMeshFoundation/developer-community/HEAD/Doc/Opporty技术交流文档/Opporty 3 layered Ecosystem.pptx
--------------------------------------------------------------------------------
/Doc/Opporty技术交流文档/Project Status Update (6_10_2018).docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SmartMeshFoundation/developer-community/HEAD/Doc/Opporty技术交流文档/Project Status Update (6_10_2018).docx
--------------------------------------------------------------------------------
/Discussion/2018.8.6_Opporty_CEO技术交流.md:
--------------------------------------------------------------------------------
1 | # Opporty公司CEO Sergey Grybniak来访技术交流
2 |
3 |
4 | Opporty在Plasma Cash开发上目前处于世界前沿,Opporty他们现在做了一个plasma cash的mvp,是目前唯一两个做出mvp原型的公司,另一个是omisego。目前smartmesh正在开发smartPlasma,他们对共建Smartmesh生态非常感兴趣,和我们开发人员做了深入交流,收获很大。
5 |
6 | 感兴趣的朋友,可以看看。
7 | https://github.com/opporty-com/Plasma-Cash
8 |
9 | https://github.com/omisego/plasma-mvp
10 |
11 | https://github.com/SmartMeshFoundation/SmartPlasma
12 |
--------------------------------------------------------------------------------
/Task/长期任务.md:
--------------------------------------------------------------------------------
1 | # 长期任务
2 | 二选一
3 |
4 | ## 1,在技术论坛,博客发表一篇技术心得
5 | 要求:阅读SmartMesh白皮书(包括不限于官方白皮书,Spectrum白皮书)。然后结合自己的工作经历和对区块链的认识,可以对其中一个技术点进行分析(比如smartRaiden的技术特点分析,Spectrum的共识算法分析),也可以对整个smartmesh体系进行评价(比如smartmesh的通证经济激励模型的思考),写一篇技术心得。 文字和图片量超500字,为原创文章,观点,论据真实可信。单纯的网上各种资讯文章的摘抄不会通过审核。
6 |
7 | 任务难度:E,F级
8 |
9 | 参与人员:不限。
10 |
11 | 工作量预计:本项任务仅发放F级奖励,但有重大理论性突破的,可以发放额外奖金。官方保留解释权。
12 |
13 | 奖励方式:每名参与人员发放1000smt(F级),重大理论性突破的,根据审核可上浮奖励到E级(1500smt)。
14 |
15 | 文件格式:文件格式为markdown格式(文件后缀名为md),或者文件格式为wiki格式(文件后缀名为rst),发到自己的博客,发布成功后,需要pr到官方github(归档地址:https://github.com/SmartMeshFoundation/developer-community/tree/master/Task)做文档归档。
16 |
17 | 审核标准:
18 |
19 |
20 | F级(1000smt):原创文章,不是简单的摘抄网上新闻文章,在各技术论坛,博客发布,有独特的思考和见解,有建设性的意见,帮助传播;
21 |
22 | E级(1500smt):原创文章,不是简单的摘抄网上新闻文章,有独特的思考和见解,能在medium上发布英文文章,有建设性的意见,观点新颖,有重大理论性突破的;
23 |
24 |
25 | 参考资料:
26 | 公链白皮书https://github.com/SmartMeshFoundation/Spectrum/wiki/Spectrum-Whitepaper
27 |
28 | ## 2,运行SmartMesh的代码,分享截图
29 | 要求:Folk SmartMesh Github的代码(https://github.com/SmartMeshFoundation),正常运行后,微信分享。
30 |
31 | 任务难度:D,E,F级
32 |
33 | 参与人员:不限。
34 |
35 | 工作量预计:2h
36 |
37 | 奖励方式:每名参与人员发放1000smt(F级),能成功跑通SmartRaiden的奖励到E级(1500smt),能成功跑通SmartPlasma的奖励D级(2000smt),在微信上,或其他技术平台分享。
38 |
39 | 参考资料:
40 | https://github.com/SmartMeshFoundation
41 |
42 |
--------------------------------------------------------------------------------
/Task/第一期任务归档-20180828/task_20180828.rst:
--------------------------------------------------------------------------------
1 | SmartMesh开发者社区第一期任务-20180828
2 | ==========================================
3 |
4 | ## Spectrum光谱链开发文档完善
5 |
6 | * 任务描述:
7 | 任务描述:
8 | Spectrum光谱链将会完成主网映射,需要开发参与完成主网测试版文档验证工作,以方便后期开始需要更多开发者加入社区, 进行公链的研究,开发,测试,和重构优化,应用开发等工作, 本开发者平台包括:
9 | · 1、环境构建
10 | · 2、架构分析和源代码分析
11 | · 3、测试代码完善
12 | · 4、智能合约开发手册
13 | · 5、SDK接口文档等等
14 |
15 |
16 | * 本期任务主要完成:
17 | 1、环境构建部分。帮助开发者最快最全完成环境搭建,快速进入开发中。
18 |
19 | * 模块设计:
20 | 一、环境构建
21 | · 苹果开发环境搭建
22 | · Window环境搭建
23 | · Ubuntu环境搭建
24 | · 测试网络搭建
25 | · IDE断点调试
26 | · 调通测试代码
27 | · 编译打包
28 |
29 |
30 | * 工作量预计:7人编辑(一个一个小任务),2人审阅(一人校阅三个或四个小任务)
31 | * 工作计划:
32 | 2018-08-31前完成人员报名,2018-09-03前完成文档编辑,2018-09-05完成文档审阅,2018-09-07完善文稿并发布。
33 |
34 |
35 | * 符合条件的人员加入一个项目组微信协调群,并配置专人跟踪,指导答疑。
36 | * 任务难度:A级(整个任务输出物需要很丰富详实,能经的起后续学习者使用)
37 | * 奖励方式:__文档包括中文和英文__,任务验证无误后,文档撰写人员每人发放**5000smt**, 文档审核者每人发放**5000smt**(需要审阅3到4个文档,并本地测试通过),采用新的工具和新的技术,加分。
38 |
39 | * 文件格式:
40 | 中文投稿到简书专栏(SmartMesh Developer Community):
41 | https://www.jianshu.com/c/23cb48c9db6f
42 | 英文投稿的medium:https://medium.com/@SmartMesh_Dev
43 | 文件格式为markdown格式(文件后缀名为md,任务文档的后缀是rst),或者文件格式为wiki格式。pull request文件到件到:github开发者社区任务文件夹下归档。
44 |
45 |
46 |
47 | ## 开发参考文档:
48 |
49 | * 安装说明:https://github.com/SmartMeshFoundation/Spectrum/wiki/Building-Specturm
50 |
51 | * 源代码:https://github.com/SmartMeshFoundation/Spectrum
--------------------------------------------------------------------------------
/Task/第二期任务归档-20180911/task_20180911.rst:
--------------------------------------------------------------------------------
1 | SmartMesh开发者社区第一期任务-20180911
2 | ==========================================
3 |
4 | ## 开发文档完善
5 |
6 | * 任务描述:
7 | 任务描述:
8 | Spectrum光谱链将会完成主网映射,需要开发参与完成主网测试版文档验证工作,以方便后期开始需要更多开发者加入社区, 进行公链的研究,开发,测试,和重构优化,应用开发等工作, 本开发者平台包括:
9 | · 1、环境构建
10 | · 2、架构分析和源代码分析
11 | · 3、测试代码完善
12 | · 4、智能合约开发手册
13 | · 5、SDK接口文档等等
14 |
15 |
16 | * 本期任务主要完成:
17 | 帮助开发者完成开发者文档,快速进入开发中。
18 |
19 | 1,Spectrum主网搭建教程 5000smt
20 | 2,Spectrum持续集成打包Travis-ci脚本 5000smt
21 | 3,Spectrum共识机制(proof of capability)解读 5000smt
22 | 4,SmartRaiden无网微支付解读 5000smt
23 | 5,SmartRaiden运行教程 5000smt
24 | 6,Spectrum一个小demo dapp开发教程 5000smt
25 | 7,Smartmesh通证模型解读 5000smt
26 | 8,SmartPlama的解读 5000smt
27 |
28 |
29 | * 工作量预计:8人编辑(一个一个小任务)
30 | * 工作计划:
31 | 2018-09-11前完成人员报名,2018-09-14前完成文档编辑,2018-09-15完成文档审阅,2018-09-17完善文稿并发布。
32 |
33 |
34 | * 符合条件的人员加入一个项目组微信协调群,并配置专人跟踪,指导答疑。
35 | * 任务难度:A级(整个任务输出物需要很丰富详实,能经的起后续学习者使用)
36 | * 奖励方式:__文档包括中文和英文__,任务验证无误后,文档撰写人员每人发放**5000smt**, 文档审核者每人发放**5000smt**(需要审阅3到4个文档,并本地测试通过),采用新的工具和新的技术,加分。
37 |
38 | * 文件格式:
39 | 中文投稿到简书专栏(SmartMesh Developer Community):
40 | https://www.jianshu.com/c/23cb48c9db6f
41 | 英文投稿的medium:https://medium.com/@SmartMesh_Dev
42 | 文件格式为markdown格式(文件后缀名为md,任务文档的后缀是rst),或者文件格式为wiki格式。pull request文件到件到:github开发者社区任务文件夹下归档。
43 |
44 |
45 |
46 | ## 开发参考文档:
47 |
48 | * https://github.com/SmartMeshFoundation
49 |
--------------------------------------------------------------------------------
/Task/第一期任务归档-20180828/Spectrum链开发 -- MacOS开发环境搭建.md:
--------------------------------------------------------------------------------
1 | How to build Spectrum under Mac OS
2 | ==================================
3 |
4 | editor:@sxsong04 reviewer:@rectinajh
5 |
6 | ## environment setup
7 | #### install golang
8 | ```
9 | brew install go
10 | ```
11 | #### setup golang environment variables
12 | ```
13 | vim ~/.bash_profile
14 | ```
15 | edit ~/.bash_profile , add $GOPATH
16 | ```
17 | #replace ~/go_project with your path
18 | export GOPATH=~/go_project
19 | export PATH=.:$PATH:$GOPATH:$GOPATH/bin
20 | ```
21 | create src,pkg,bin folder under $GOPATH
22 | ```
23 | mkdir -p $GOPATH/bin $GOPATH/pkg $GOPATH/src
24 | ```
25 | test go
26 | ```
27 | source ~/.bash_profile
28 | go env
29 | ```
30 | #### install git
31 | ```
32 | brew install git
33 | ```
34 | ---
35 | ## build from source
36 | clone latest source code to $GOPATH
37 | ```
38 | mkdir -p $GOPATH/src/github.com/SmartMeshFoundation
39 | cd $GOPATH/src/github.com/SmartMeshFoundation
40 | git clone https://github.com/SmartMeshFoundation/Spectrum
41 | ```
42 | build smc
43 | ```
44 | cd $GOPATH/src/github.com/SmartMeshFoundation/Spectrum/
45 | go install -v ./cmd/smc
46 | ```
47 | smc excutable file:$GOPAT/bin/smc
48 | test smc
49 | ```
50 | smc console
51 | ```
52 | ---
53 | ## About IDE
54 | The popular golang IDE under Mac are GoLand,VSCode,GoVim...,choose the IDE you like.
55 |
56 | Take GoLand as an example to debug Spectrum.
57 |
58 | File -> Open -> $GOPATH/src/github.com/SmartMeshFoundation/Spectrum/
59 |
60 | go to cmd/smc/main.go, Press F5.
61 |
62 | 
63 |
--------------------------------------------------------------------------------
/Task/第一期任务归档-20180828/Spectrum链开发--IDE断点调试.md:
--------------------------------------------------------------------------------
1 | # Spectrum 链开发--IDE 断点调试介绍
2 |
3 | `编辑人:@GirpZhang 审阅人:@rectinajh`
4 |
5 | ## 开发环境
6 |
7 | * Windows10
8 |
9 | * go1.9.2.windows-amd64
10 |
11 | * Visual Studio Code
12 |
13 | * Git 2.18.0
14 |
15 | ## 需要完成 Visual Studio Code + GoLang 开发环境配置
16 |
17 | * 安装 go1.9.2.windows-amd64,配置 GOPATH
18 |
19 | * 安装 Git
20 |
21 | `本例中使用的 "GOPATH":"E:/GoPath";"GOROOT":"E:/Go"`
22 |
23 | * 安装 Visual Studio Code,安装 Go 插件,介绍中是 Rich Go language support for Visual Studio Code
24 |
25 | * 调试配置:
26 |
27 | `VSCode->查看->调试->添加调试目标,在"没有调试"的下拉框中点击"添加配置.."` 添加目标调试配置:
28 |
29 | ```
30 |
31 | {
32 |
33 | "version": "0.2.0",
34 |
35 | "configurations": [
36 |
37 | {
38 |
39 | "name": "Launch",
40 |
41 | "type": "go",
42 |
43 | "request": "launch",
44 |
45 | "mode": "debug",
46 |
47 | "remotePath": "",
48 |
49 | "port": 2345,
50 |
51 | "host": "127.0.0.1",
52 |
53 | "program": "${fileDirname}",
54 |
55 | "env": {
56 |
57 | "GOPATH":"E:/GoPath",
58 |
59 | "GOROOT":"E:/Go"
60 |
61 | },
62 |
63 | "args": [],
64 |
65 | "showLog": true
66 |
67 | }
68 |
69 | ]
70 |
71 | }
72 |
73 | ```
74 |
75 | ## 下载 Spectrum 代码
76 |
77 | ```
78 |
79 | git clone git@github.com:SmartMeshFoundation/Spectrum.git
80 |
81 | ```
82 |
83 | ## 调试准备
84 |
85 | * 在 E:/GoPath/src 下新建多级目录:\github.com\SmartMeshFoundation\Spectrum
86 |
87 | * 将下载下来的 Spectrum.git 中的代码复制到 E:/GoPath/src/github.com/SmartMeshFoundation/Spectrum 下
88 | 
89 |
90 |
91 | * 打开 VSCode,选择 文件->打开文件夹->打开 Spectrum 文件夹
92 |
93 | * 打开 cmd->smc->main.go 文件,如下:
94 | 
95 |
96 | * F5 调试,会提示如下错误:
97 |
98 | ```
99 |
100 | Failded to continue:"Cannot find Delve debugger. Install from https://github.com/derekparker/delve & ensure it is in your "GOPATH/bin" or "PATH"
101 |
102 | ```
103 |
104 | * 然后我们使用 Go 命令行编译调试器、将 dlv 调试器放在 GOPATH 的 bin 目录下
105 |
106 | * 使用 cmd 命令行,进入目录 E:\GoPath\bin
107 |
108 | * 执行命令安装 dlv
109 |
110 | ```
111 |
112 | go get github.com/derekparker/delve/cmd/dlv
113 |
114 | ```
115 | 
116 |
117 |
118 | * 安装完成后就可以正常调试了,在需要的地方打上断点进行单步调试:
119 |
120 | 
121 |
--------------------------------------------------------------------------------
/Task/第一期任务归档-20180828/Spectrum链开发--Linux环境搭建.md:
--------------------------------------------------------------------------------
1 | # Spectrum链开发--Linux环境搭建
2 |
3 | 编辑人:@ruur
4 | 审阅人:@朱春雷
5 |
6 | 本文主要介绍在Linux环境下Spectrum链开发的基础环境安装,包括Ubuntu和CentOS环境。同时,也提供了打造Docker镜像的方法。推荐使用docker环境安装,能够避免因环境的差异造成安装不成功,也可快速部署。
7 |
8 | ## 安装
9 |
10 | ### 系统环境(以下环境已测试通过)
11 |
12 | * Ubuntu: Ubuntu 16.04.4 LTS
13 |
14 | * CentOS: CentOS Linux release 7.5.1804
15 |
16 | * Docker: Version 18.06.1-ce-mac73 (26764)
17 |
18 | > 注:不同Linux发布版本安装过程可能略有不同
19 |
20 | ### 工具安装
21 |
22 | #### 安装依赖
23 |
24 | * Ubuntu
25 |
26 | ```
27 | $ apt-get install git
28 | $ apt-get install wget
29 | ```
30 |
31 | * CentOS
32 |
33 | ```
34 | $ yum install git
35 | $ yum install wget
36 | $ yum -y install gcc automake autoconf libtool make
37 | ```
38 |
39 | * Docker(使用Golang镜像,无需手动安装Go)
40 |
41 | ```
42 | $ docker pull golang
43 | $ docker run -i -t golang /bin/bash
44 | $ go version
45 | go version go1.11 linux/amd64
46 | ```
47 |
48 | ### 安装Go
49 | #### 版本检查
50 | ```
51 | $ go version
52 | ```
53 | #### 版本支持
54 | * 经测试,Golang1.9.2 -- Golang1.11均可
55 | * 安装项目之前需检查是否安装了符合要求的Golang,若已安装或使用Golang的Docker镜像,请忽略下一个步骤【下载及安装】
56 |
57 | #### 下载及安装
58 |
59 | ##### 下载及解压
60 |
61 | ```
62 | $ wget -c -t 3 https://dl.google.com/go/go1.9.2.linux-amd64.tar.gz
63 | $ tar -C /usr/local -xzf go1.9.2.linux-amd64.tar.gz
64 | ```
65 |
66 | ##### 设置环境变量
67 | * 执行
68 | ```
69 | $ export GOROOT=/usr/local/go
70 | $ export PATH=$GOROOT/bin:$PATH
71 | ```
72 | * 也可把环境变量添加到profile文件中,把以上环境变量加入到 `$HOME/.profile` 文件中,同时执行 `source $HOME/.profile`
73 |
74 | #### 检查版本
75 |
76 | * 执行
77 | ```
78 | $ go version
79 | ```
80 |
81 | * 结果
82 | ```
83 | go version go1.9.2 linux/amd64
84 | ```
85 |
86 | * Golang安装过程如下图:
87 |
88 |
89 | ### Spectrum安装
90 | #### 下载源文件
91 | ```
92 | $ git clone https://github.com/SmartMeshFoundation/Spectrum.git
93 | ```
94 |
95 | #### 编译
96 | ```
97 | $ cd Spectrum
98 | $ make smc
99 | ```
100 |
101 | #### 编译结果
102 | * 编译结果如下表示即成功
103 | ```
104 | Done building.
105 | Run "/your_path/Spectrum/build/bin/smc" to launch smc.
106 | ```
107 | * 编译过程如下图:
108 |
109 | ## 运行
110 | #### 执行命令
111 | ```
112 | $ /your_path/Spectrum/build/bin/smc console
113 | ```
114 | > 注: `/your_path/`表示Spectrum项目代码所在的系统路径
115 |
116 | * 运行过程如下图:
117 |
118 |
119 | #### 创建账号
120 |
121 | ```
122 | > personal.newAccount()
123 | ```
124 |
125 | * 创建账号如下图:
126 |
127 | #### 查看节点
128 |
129 | ```
130 | > tribe.getStatus()
131 | ```
132 |
133 | * 查看节点如下图:
134 |
135 | #### 查看历史
136 |
137 | ```
138 | > tribe.getHistory(11,false)
139 | ```
140 |
141 | * 查看历史如下图:
142 |
143 | ## 其他
144 | * 完成以上安装过程即表示Spectrum链基础环境已安装成功,可以进行接下来的开发工作。
145 | * 执行`/your_path/Spectrum/build/bin/smc console`命令时可能会同步下载大量的Spectrum链数据,这可能会需要数十分钟至几个小时(依网络情况而定)。
146 | * 另外,请保证系统环境有足够的空间可完成数据的下载更新。数据存储路径为 `~/.spectrum/smc/chaindata/`,如需移除项目,请同步删除数据文件,操作命令为: `rm -rf ~/.spectrum`。
147 | * 中文版发布:https://www.jianshu.com/p/92d067c44b3c
148 | * 英文版发布:https://medium.com/@ruur/spectrum-chain-installation-for-linux-ae0a9e59179
149 |
--------------------------------------------------------------------------------
/Task/第一期任务归档-20180828/Spectrum链开发 -- Windows开发环境搭建.md:
--------------------------------------------------------------------------------
1 |
2 | 编辑人:@牛志成 审阅人:@rectinajh
3 |
4 |
5 | 1 环境准备
6 |
7 | 1.1 操作系统环境
8 |
9 | Windows 7 专业版
10 |
11 | 1.2 我们首先安装GO的工具包
12 |
13 | 1.2.1 下载 并且 安装Go安装包(需要V1.7+以上版本)Goland的V1.10.3官网最新下载地址:https://dl.google.com/go/go1.10.3.windows-amd64.msi需要梯子】,最新的百度下载地址如下所示:
14 |
15 | Windwos 32位系统 百度下载链接:https://pan.baidu.com/s/1_uR-rEiOwDYPYcHwLCBZwA密码:qdyg
16 |
17 | Windows 64位系统 百度下载链接:https://pan.baidu.com/s/1mKeVZ9mWVcWUE0JJeaQ40w密码:s91q
18 |
19 | 选择自己windows系统合适的版本, 这里我选择go1.10.3.windows-amd64.msi进行安装,下载下来后,双击点击文件进行安装,大家可以自己自定义安装路径,这里我安装的路径为E:\Go。
20 |
21 | 1.2.2 配置Go环境变量
22 |
23 | 一 如果是msi安装文件,Go语言的环境变量会自动设置好。
24 |
25 | 二 配值环境变量的配置, 具体参考如下:
26 |
27 | (1). 变量名:GOPATH 变量值 :E:\Gopath 注:Gopath 这个文件夹是我在E盘下面手动建立作为资源存放
28 |
29 | 1.2.3.下面是环境变量设置的地方 这里为大家截图展示
30 |
31 |
32 | 
33 | 
34 | 
35 |
36 | 1.2.4 验证Go安装环境是否成功
37 |
38 | 打开Windows中的命令提示符(cmd.exe)
39 |
40 | 执行命令:go version 正常情况下会显示:go version go1.10.3 windows/amd64如果出现 “’go‘不是内部或外部命令,也不是可运行的程序或批处理文件”, 请参考“1.2.2 配置Go环境变量”重新设置一下,直到验证成功为止。
41 |
42 | 这里显示出版本号即为成功 安装GO
43 |
44 | 
45 |
46 | 1.3 安装Git
47 |
48 | 选择最新Git下载:
49 |
50 | 64位git-2.18.0-64-bit.exe下载地址:https://github.com/git-for-windows/git/releases/download/v2.18.0.windows.1/Git-2.18.0-64-bit.exe
51 |
52 | 32位git-2.1.8.0-32-bit.exe下载地址:https://github.com/git-for-windows/git/releases/download/v2.18.0.windows.1/Git-2.18.0-64-bit.exe
53 |
54 | 下载完成后,双击安装,这里我选在64位git-2.18.0-64-bit.exe, 安装路径用户可以自定义,我的安装路径为E:\Program Files\Git,在该路径下面找到git-bash.exe文件,双击打开,会弹出一个MinGW64的命令行窗口,就可以执行git相关命令了,
55 | 执行git --version ,如果显示版本即成功。
56 |
57 | 
58 |
59 |
60 | 1.4 安装编译器GCC
61 |
62 | 1.由于要在windows上编译Spectrum代码,我们需要安装一个编译器MinGW,
63 | MinGW全称Minimalist GNU For Windows,是个精简的Windows平台C/C++、ADA及Fortran编译器。
64 | MinGW-w64-for32 and 64 bit Window
65 | 下载地址:https://sourceforge.net/projects/mingw-w64/files/latest/download,
66 | 下载完成后,就开始安装了,64位电脑安装配置如下所示:
67 |
68 | 
69 |
70 | 2.配置gcc的环境变量
71 |
72 | 这里我的安装目录是:E:\GCC
73 |
74 | 环境变量我们再 PATH里面 追加 E:\GCC\mingw64\bin 自己安装Gcc的bin文件夹
75 |
76 | 环境变量的设置方法参考:1.2.3
77 |
78 | 
79 |
80 | 1.5 设置Spectrum资源存放的文件夹
81 |
82 | 1.5.1 首先GOPATH设置的文件夹里面一次建立文件夹
83 |
84 | 我的GOPATH 对应的文件夹是 E:\Gopath
85 |
86 | src ——》github.com----》SmartMeshFoundation 依次建立文件夹
87 |
88 | 最终我们建立的目标路径:E:\Gopath\src\github.com\SmartMeshFoundation
89 |
90 | 1.5.2 编译Spectrum
91 |
92 | 打开cmd 切换到我们1.5.1设置的文件夹路径
93 |
94 | 
95 |
96 | 1.5.4 把Spectrum的源码文件下载下来
97 |
98 | 执行命令 git clone https://github.com/SmartMeshFoundation/Spectrum
99 |
100 | 
101 |
102 | 1.5.5 进度达到100%以后我们可以到我们设置的文件夹 查看
103 |
104 | E:\Gopath\src\github.com\SmartMeshFoundation
105 |
106 | 
107 |
108 |
109 | 1.5.6 切换到Spectrum文件夹
110 |
111 | 执行编译命令
112 |
113 | go install -v ./cmd/smc
114 |
115 | 
116 | 
117 |
118 | 1.5.7 测试编译是否成功
119 |
120 | 
121 | 
122 |
123 | 出现开始同步节点,即为编译成功
124 |
125 | 问题总结:
126 |
127 | 初步编译Spectrum出现问题 编译失败,出现找不到部分文件
128 |
129 | 解决方法:
130 |
131 | 重新删除GO语言安装环境,重新安装
132 |
133 | 
134 |
135 |
136 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SmartMesh Developer Community Wiki
2 |
3 | [](https://gitter.im/SmartMesh-Developer-Community/Lobby)
4 |
5 |
6 | ## Introduction
7 | SmartMesh是一个基于区块链token激励机制的开放式、共享型Mesh网络基础协议,SmartMesh生态的本质是一个庞大的通证生态。生态的建设离不开SmartMesh开发者社区,SmartMesh开发者社区希望吸引全球对SmartMesh项目感兴趣的朋友,一起交流一起讨论,可以从理论开始探讨,从不同维度和视角思考SmartMesh的生态体系,从更高的维度对SmartMesh和MeshBox提出面向未来的规划和需求,并参与实施与落地。我们希望这是一个很科幻,很脑洞的社区,鼓励乌托邦式的想法,仰望星空但要脚踏实地,所以开发者社区会大力激励有创想有能力的开发人才,一起大胆的想,大胆的干!
8 |
9 |
10 | SmartMesh is an open, shared Mesh network protocol that works on blockchain-based tokenized incentive mechanisms. Now a developer community is being launched in hopes of attracting developers from around the world to work on SmartMesh projects. At first, we can look at potential projects from theoretical and abstract perspectives.
11 | Devising concepts for SmartMesh and MeshBox projects is an imaginative process. We hope that our community can embrace the unbridled innovation of science fiction, the knowledge of academia and engineering, and the vision of utopian ideals. We are seeking far more than just "coders", but true innovators who can write the chapters of the future for human civilization into an ambitious and robust ecosystem!
12 |
13 |
14 | ## Unique concept
15 | 区块链思维:社区成员是一个个区块链节点,鼓励连接和价值传递,平等,独立,自由,有价值的观点、成果,会得到尊重和激励。
16 |
17 | Community members are blockchain nodes who will be respected and incentivized, and that encourage connectivity and value transfers, equality, independence, freedom, valuable perspectives, and results.
18 |
19 | ## Operating mechanism
20 | 一个分布式自治模式的区块链开发者社区
21 | An autonomous community of blockchain developers.
22 |
23 | 解读:我们希望开发者社区,不要消耗公司过多的精力来管理,只需要很少的公司内部人员就可以完成协作。开发者社区吸引世界上对SmartMesh项目感兴趣的开发者,社区成员作为一个个区块链节点,按照我们设定的共识机制,自组织,自管理,自运行。
24 |
25 | Interpretation: We want the developer community to avoid devoting too much energy to management, and only require a few core members to collaborate on organizational tasks. The developer community will attract developers from around the world who are interested in SmartMesh projects. Community members act as blockchain nodes that are self-organizing, self-managing, and self-running according to the consensus mechanism we have implemented.
26 |
27 | 社区共识机制:
28 | Community Consensus Mechanism:
29 |
30 | Proof of Capability (POC)(这是spectrum公链的共识机制,把区块链运行的方式放到开发者社区,所以这是真正的区块链社区)
31 |
32 | Proof of Capability (POC) (the Spectrum public chain's consensus mechanism, integrating the developer community into a 'true' blockchain community)
33 |
34 | 社区为了达到自组织,自运行,需要社区成员组织起来,分工合作,都来参与社区的协作。
35 |
36 | In order to achieve self-organization and self-operation, the community needs its members to organize, work together, and collaborate.
37 |
38 | 社区分为四个模块,每个模块由节点组成,每个节点其实是开发者社区成员。
39 |
40 | The community is divided into four modules that consist of nodes which are actually members of the developer community. These are:
41 |
42 | 1)激励模块:负责审核社区smt token激励的预算,审核和发放。
43 |
44 | Incentive Module: Responsible for reviewing the budget, and reviewing and releasing of community SMT Token incentives.
45 |
46 | 2)需求池模块:对内负责收集和提交对SmartMesh好的意见和想法,对外收集和整理目前公司内部暂时做不了的需求,适当放出一些。每周出一些主题题目,鼓励社区成员pr,获得奖励。
47 |
48 | Demand Pool Module: Responsible for collecting and submitting good suggestions and ideas for SmartMesh, collecting and sorting out the current needs of the company, and releasing some of them appropriately. They will also generate some topics every week and encourage community members to earn rewards.
49 |
50 | 3)审核决策模块:审核复杂有争议的事物,最高决策节点。如:当社区运行出错时,对形势进行判断,进行回滚或者暂停社区运行的决策。
51 |
52 | Audit Evaluation Module: The highest decision-making nodes. Reviewing complex and controversial events and issues. For example, when the community goes awry, this node will pass judgement on the situation and make a decision whether or not to roll back or suspend the community operation.
53 |
54 | 4)开发者模块:通过审核的有能力(开发能力)节点,接需求池的需求,固定时间完成需求任务获得奖励。将是一个弱中心化组织,各节点群出块(正确做事),可以获得奖励。
55 |
56 | Developer Module: These nodes will audit development capability according to the requirements released by SmartMesh, and will be rewarded at fixed times. It will be a weakly centralized organization, and each node group generates blocks (by acting correctly) and earns rewards.
57 |
58 | ## SMT Rewards
59 | 1)做任务,获得smt奖励。任务包括但不限于写文章或者提交代码;具体任务需求每周再讨论。
60 |
61 | Complete tasks and earn SMT rewards. Tasks include, but are not limited to, writing articles or submitting code; different tasks will be released on a weekly basis.
62 |
63 | 2)技术分享,获得smt奖励。包括但不限于区块链技术,无网mesh技术,AI,任何对SmartMesh生态有价值的技术,都可以。
64 |
65 | Share technology and earn SMT rewards. Including but not limited to blockchain technology, MESH technology, AI, and any technology that is valuable to the SmartMesh ecosystem.
66 |
67 | 3)理论创新,获得奖励。从理论开始探讨,从不同维度和视角思考SmartMesh的生态体系,从更高的维度对SmartMesh和MeshBox提出面向未来的规划和需求。
68 |
69 | Devise innovative theories, concepts and plans and earn rewards. Contemplating future directions and possibilities for SmartMesh's ecosystem from different dimensions and perspectives, and proposing future-oriented planning and requirements for SmartMesh and MeshBox.
70 |
71 |
72 | ## Recruit
73 | 社区成员的对象:对区块链技术具有强烈学习兴趣的全球IT开发者。
74 |
75 | Community Member Pre-requisites: Global IT developers with a strong interest in blockchain technology, a passion for innovation, and a creative approach to community development and involvement.
76 |
77 | 社区成员加入方式:邀请或者申请,有一个门槛设置,比如提交申请(比如您可以告诉我们您可以施展你的才能帮助社区做什么?),或者我们会邀请有行业影响力或者技术影响力的朋友。
78 |
79 | How community members join: By invitation or application. This could be as easy as you telling us what you can do to help the SmartMesh ecosystem develop. Simultaneously, we will invite candidates who we have identified to possess industry or technical experience, influence and prowess.
80 |
81 |
82 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/Task/第一期任务归档-20180828/Spectrum链开发--Windows环境下单元测试.md:
--------------------------------------------------------------------------------
1 | 作者: 唐爽 校阅者: rectinajh
2 |
3 |
4 | 系统环境 win10
5 | 注:不同windows发布版本安装过程可能略有不同
6 |
环境依赖:
Go, GCC
Go下载地址: https://golang.org/dl/
笔者下载的是1.10.2. 64位版本:
完整下载地址: https://dl.google.com/go/go1.10.2.windows-amd64.msi
安装:
笔者安装的路径为 C:\Go目录下. 添加 C:\Go\bin到环境变量中.
13 | 任意目录下执行go version,显示版本号则安装配置成功.
14 | C:\Users\tangshua>go version
15 | go version go1.10.2 windows/amd64
16 |
MinGw下载地址 : https://sourceforge.net/projects/mingw-w64/
笔者下载的GW完整下载地址: https://jaist.dl.sourceforge.net/project/mingw-w64/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/installer/mingw-w64-install.exe
安装MinGW:
笔者安装在D:\mingw-w64,安装完成后如下. 添加D:\mingw-w64\bin到环境变量中.
Spectrum安装
下载源文件
https://github.com/SmartMeshFoundation/Spectrum
笔者放在了D盘.切换到tests目录. 执行Go test -v
41 | 其它点:
42 | 执行报错解决办法:
43 | 1. 将代码放在Go目录下.
44 | C:\Go\src\github.com\SmartMeshFoundation\Spectrum
45 | 笔者在block_test_util.go代码中发现如下定义,可能导致相应类库无法找到而报错.
46 | import (
47 | "bytes"
48 | "encoding/hex"
49 | "encoding/json"
50 | "fmt"
51 | "math/big"
52 |
53 | "github.com/SmartMeshFoundation/Spectrum/common"
54 | "github.com/SmartMeshFoundation/Spectrum/common/hexutil"
55 | "github.com/SmartMeshFoundation/Spectrum/common/math"
56 | "github.com/SmartMeshFoundation/Spectrum/consensus/ethash"
57 | "github.com/SmartMeshFoundation/Spectrum/core"
58 | "github.com/SmartMeshFoundation/Spectrum/core/state"
59 | "github.com/SmartMeshFoundation/Spectrum/core/types"
60 | "github.com/SmartMeshFoundation/Spectrum/core/vm"
61 | "github.com/SmartMeshFoundation/Spectrum/ethdb"
62 | "github.com/SmartMeshFoundation/Spectrum/params"
63 | "github.com/SmartMeshFoundation/Spectrum/rlp"
64 | )
65 |
66 | 2. 在tests目录下创建testdata目录,同时在testdata目录下分别创建
67 | BlockchainTests,GeneralStateTests,TransactionTests,VMTests,RLPTests,BasicTests目录。
68 | 笔者在init_test.go 文件中发现如下定义:
69 | var (
70 | baseDir = filepath.Join(".", "testdata")
71 | blockTestDir = filepath.Join(baseDir, "BlockchainTests")
72 | stateTestDir = filepath.Join(baseDir, "GeneralStateTests")
73 | transactionTestDir = filepath.Join(baseDir, "TransactionTests")
74 | vmTestDir = filepath.Join(baseDir, "VMTests")
75 | rlpTestDir = filepath.Join(baseDir, "RLPTests")
76 | difficultyTestDir = filepath.Join(baseDir, "BasicTests")
77 | )
78 | 但是并未在文件夹中发现,因此手动创建了改文件夹.
79 |
80 |
93 |
94 |
--------------------------------------------------------------------------------
/Task/第一期任务归档-20180828/Spectrum链开发--测试网络搭建.md:
--------------------------------------------------------------------------------
1 | 编辑人:@anray 审阅人:@rectinajh
2 |
3 | 本文将演示在服务器端搭建Spectrum测试网络的过程,操作系统为CentOS 7.4 64位,已安装并配置好go运行环境,同时已下载Spectrum源码并成功编译。对上述系统环境搭建不熟悉的读者,可以参考《[Spectrum链开发--Linux环境搭建](https://github.com/SmartMeshFoundation/developer-community/blob/master/Task/%E7%AC%AC%E4%B8%80%E6%9C%9F%E4%BB%BB%E5%8A%A1%E5%BD%92%E6%A1%A3-20180828/Spectrum%E9%93%BE%E5%BC%80%E5%8F%91--Linux%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA.md)》一文。
4 |
5 | #### 1. 初始化创世区块
6 | ##### 1.1 准备创世区块配置文件genesis.json
7 | 首先,新建一个目录用来存放genesis.json。假设新建目录为\~/spectrumchain,genesis.json保存在\~/spectrumchain中,目录结构如下:
8 | ```
9 | spectrumchain
10 | └── genesis.json
11 | ```
12 | 然后,编辑genesis.json文件,内容如下:
13 | ```
14 | {
15 | "config": {
16 | "chainId": 20180908,
17 | "homesteadBlock": 0,
18 | "eip155Block": 0,
19 | "eip158Block": 0
20 | },
21 | "coinbase" : "0x0000000000000000000000000000000000000000",
22 | "difficulty" : "0x20000",
23 | "extraData" : "",
24 | "gasLimit" : "0x2fefd8",
25 | "nonce" : "0x0000000000000042",
26 | "mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
27 | "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
28 | "timestamp" : "0x00",
29 | "alloc" : {}
30 | }
31 | ```
32 | 主要参数介绍:
33 | 参数名称 | 说明
34 | ---|---
35 | chainId | 区块链ID,下文中出现的 --networkid 参数需要与 chainId 值一致
36 | coinbase | 矿工账号
37 | difficulty | 难度值
38 | extraData | 附加信息
39 | gasLimit | gas的消耗总量限制,用来限制区块能包含的交易信息总和
40 | nonce | 64位随机数,用于挖矿
41 | mixhash | 与nonce配合用于挖矿
42 | parentHash | 上一个区块的hash值,因为是创世块,所以这个值是0
43 | timestamp | 设置创世块的时间戳
44 | alloc | 预置账号以及账号的SMT数量
45 |
46 | ##### 1.2 写入创世区块
47 | 准备好创世区块配置文件后,需要初始化Spectrum链,将上述创世区块信息写入Spectrum中。在spectrumchain目录中新建一个目录spectrumdata,用来存放区块链数据,此时目录结构如下:
48 | ```
49 | spectrumchain
50 | ├── spectrumdata
51 | └── genesis.json
52 | ```
53 | 进入spectrumchain目录中,执行初始化命令:
54 | ```
55 | $ cd spectrumchain
56 | $ smc --datadir spectrumdata init genesis.json
57 | ```
58 | 上面的命令主体是smc init,表示初始化Spectrum链,命令可以带有选项和参数,其中--datadir选项后面跟目录名,这里为spectrumdata,表示指定区块链数据存放目录为spectrumdata,genesis.json是init命令的参数,即创世区块配置文件。
59 |
60 | 执行命令后,会读取genesis.json文件,根据其内容将创世区块写入到区块链中。如果看到以下的输出内容,说明初始化成功了。
61 | ```
62 | Successfully wrote genesis state database=lightchaindata hash=5e1fc7…d790e0
63 | ```
64 | 初始化成功后,会在数据目录spectrumdata中生成smc和keystore两个文件夹,此时目录结构如下:
65 | ```
66 | spectrumchain
67 | ├── spectrumdata
68 | │ ├── smc
69 | │ │ └── chaindata
70 | │ │ ├── 000001.log
71 | │ │ ├── CURRENT
72 | │ │ ├── LOCK
73 | │ │ ├── LOG
74 | │ │ └── MANIFEST-000000
75 | │ │ └── lightchaindata
76 | │ │ ├── 000001.log
77 | │ │ ├── CURRENT
78 | │ │ ├── LOCK
79 | │ │ ├── LOG
80 | │ │ └── MANIFEST-000000
81 | │ └── keystore
82 | └── genesis.json
83 | ```
84 | 其中smc/chaindata中存放的是区块数据,keystore中存放的是账户数据。
85 |
86 | #### 2. 启动测试网络
87 | 初始化完成后,可以启动测试网络了。执行下面的命令启动节点:
88 | ```
89 | $ smc --datadir spectrumdata --networkid 20180908 console
90 | ```
91 | 上面命令的主体是smc console,表示启动节点并进入交互式控制台,--datadir选项指定使用spectrumdata作为数据目录,--networkid选项后必须与genesis.json中的chainId一致,在连接到其他节点时会用到。
92 |
93 | 执行上述命令后,就启动了区块链节点并进入控制台:
94 | ```
95 | ...
96 | Welcome to the Geth JavaScript console!
97 |
98 | instance: Smc/v0.5.1-unstable-9bbe523c/linux-amd64/go1.9.4
99 | modules: admin:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 txpool:1.0 web3:1.0
100 |
101 | >
102 | ```
103 |
104 | #### 3. 使用测试网络
105 | ##### 3.1 创建账户
106 | 启动了测试网络后,就可以创建账户了。初次运行的测试网络是没有任何账户的,可以在console中输入eth.accounts查看:
107 | ```
108 | > eth.accounts
109 | []
110 | ```
111 | 可以使用personal.newAccount()创建一个账户,会提示输入密码和确认密码,输入密码不会有显示,回车后返回新创建的账户地址:
112 | ```
113 | > personal.newAccount()
114 | Passphrase:
115 | Repeat passphrase:
116 | "0xc4cc8cd3c8a4e6a05cf21d182ebbf41868401275"
117 | ```
118 | 可以创建多个账户,为方便演示账户间的交易,再来创建一个账户:
119 | ```
120 | > personal.newAccount()
121 | Passphrase:
122 | Repeat passphrase:
123 | "0x9358844d589f31c5c5515d65d156c3233d2fdc24"
124 | ```
125 | 再输入eth.accounts就可以查看到两个账户了:
126 | ```
127 | > eth.accounts
128 | ["0xc4cc8cd3c8a4e6a05cf21d182ebbf41868401275", "0x9358844d589f31c5c5515d65d156c3233d2fdc24"]
129 | ```
130 | 账户默认会保存在数据目录的keystore文件夹中。查看目录结构,发现spectrumdata/keystore中多了两个文件,这两个文件对应新创建的两个账户。这是json格式的文本文件,内容是私钥经过加密后的信息。
131 | ```
132 | spectrumdata
133 | ├── smc
134 | ├── smc.ipc
135 | ├── history
136 | └── keystore
137 | ├── UTC--2018-09-08T09-37-02.526965006Z--c4cc8cd3c8a4e6a05cf21d182ebbf41868401275
138 | └── UTC--2018-09-08T09-38-02.713900919Z--9358844d589f31c5c5515d65d156c3233d2fdc24
139 | ```
140 |
141 | ##### 3.2 查询账户余额
142 | eth.getBalance()可以查看指定账户的余额:
143 | ```
144 | > eth.getBalance(eth.accounts[0])
145 | 0
146 | > eth.getBalance(eth.accounts[1])
147 | 0
148 | ```
149 | 当前两个账户的余额都是0,要使账户有余额,可以从其他账户转账过来,或者通过挖矿来获得奖励。
150 |
151 | ##### 3.3 启动&停止挖矿
152 | miner.start()可以启动挖矿:
153 | ```
154 | > miner.start(1)
155 | ```
156 | 其中start的参数表示挖矿使用的线程数。第一次启动挖矿会生成挖矿所需的DAG文件,在生成进度达到100%后,就会开始挖矿,此时屏幕会被挖矿信息刷屏。
157 |
158 | miner.stop()可以停止挖矿:
159 | ```
160 | > miner.stop()
161 | ```
162 | 注意:输入的字符可能会被挖矿刷屏信息冲掉,不用担心,只要输入完整的miner.stop()回车,即可停止挖矿。
163 |
164 | 挖矿所得的奖励会进入矿工的账户,这个账户叫做coinbase,默认情况下coinbase是本地账户中的第一个账户:
165 | ```
166 | > eth.coinbase
167 | "0xc4cc8cd3c8a4e6a05cf21d182ebbf41868401275"
168 | ```
169 | 挖到区块以后,coinbase中就有余额了:
170 | ```
171 | > eth.getBalance(eth.coinbase)
172 | 150000000000000000000
173 | ```
174 | getBalance()返回值的单位是wei,1个SMT=10的18次方个wei。要查看有多少个SMT,可以用web3.fromWei()将返回值换算成SMT:
175 | ```
176 | > web3.fromWei(eth.getBalance(eth.accounts[0]),'ether')
177 | 150
178 | ```
179 | 如果想使用别的账户作为coinbase,可以通过miner.setEtherbase()将其他账户设置成coinbase:
180 | ```
181 | > miner.setEtherbase(eth.accounts[1])
182 | true
183 | > eth.coinbase
184 | "0x9358844d589f31c5c5515d65d156c3233d2fdc24"
185 | ```
186 |
187 | ##### 3.4 发送交易
188 | 目前,两个账户余额分别是:
189 | ```
190 | > eth.getBalance(eth.accounts[0])
191 | 150000000000000000000
192 | > eth.getBalance(eth.accounts[1])
193 | 0
194 | ```
195 | 可以发送一笔交易,从eth.accounts[0]向eth.accounts[1]转移5个SMT:
196 | ```
197 | > amount = web3.toWei(5,'ether')
198 | "5000000000000000000"
199 | > eth.sendTransaction({from:eth.accounts[0], to:eth.accounts[1], value:amount})
200 | Error: authentication needed: password or unlock
201 | at web3.js:3143:20
202 | at web3.js:6347:15
203 | at web3.js:5081:36
204 | at :1:1
205 | ```
206 | 这里报错了,因为要发送交易,必须先解锁账户:
207 | ```
208 | > personal.unlockAccount(eth.accounts[0])
209 | Unlock account 0xc4cc8cd3c8a4e6a05cf21d182ebbf41868401275
210 | Passphrase:
211 | true
212 | ```
213 | 输入账户密码就可以成功解锁账户。然后再发送交易:
214 | ```
215 | > amount = web3.toWei(5,'ether')
216 | "5000000000000000000"
217 | > eth.sendTransaction({from:eth.accounts[0], to:eth.accounts[1], value:amount})
218 | INFO [09-08|20:08:40] Submitted transaction fullhash=0x250470a72b41109aab1b64cb487b8f5c5754a03203b9a4243eb97a1a6d8f2521 recipient=0x9358844d589f31C5c5515D65d156c3233D2fDC24
219 | "0x250470a72b41109aab1b64cb487b8f5c5754a03203b9a4243eb97a1a6d8f2521"
220 | ```
221 | 此时交易已经提交到区块链,返回了交易的hash,但还未被处理,可以使用txpool.status来验证:
222 | ```
223 | > txpool.status
224 | {
225 | pending: 1,
226 | queued: 0
227 | }
228 | ```
229 | 其中有一条pending的交易,pending表示已提交但还未被处理的交易。
230 |
231 | 要使交易被处理,必须要挖矿。这里我们启动挖矿,然后等待挖到一个区块之后就停止挖矿:
232 | ```
233 | > miner.start(1); admin.sleepBlocks(1); miner.stop();
234 | true
235 | ```
236 | 当miner.stop()返回true后,再执行txpool.status会发现pending的数量已变为0,说明交易已经被处理了:
237 | ```
238 | > txpool.status
239 | {
240 | pending: 0,
241 | queued: 0
242 | }
243 | ```
244 | 此时,交易已经生效,eth.accounts[1]中应该已收到了5个SMT了:
245 | ```
246 | > web3.fromWei(eth.getBalance(eth.accounts[1]),'ether')
247 | 5
248 | ```
249 | 通过eth.getTransaction()可以查看此笔交易信息:
250 | ```
251 | > eth.getTransaction("0x250470a72b41109aab1b64cb487b8f5c5754a03203b9a4243eb97a1a6d8f2521")
252 | {
253 | blockHash: "0x1ce828d9dce08dc7868f3aab92f22d7115186515cdbc426d9a7b8a6d96ae979d",
254 | blockNumber: 35,
255 | from: "0xc4cc8cd3c8a4e6a05cf21d182ebbf41868401275",
256 | gas: 90000,
257 | gasPrice: 18000000000,
258 | hash: "0x250470a72b41109aab1b64cb487b8f5c5754a03203b9a4243eb97a1a6d8f2521",
259 | input: "0x",
260 | nonce: 0,
261 | r: "0x1577c4f7a78e6b37e5159b2488d5636feb2bbb5ef10e8b01484155dc3710e884",
262 | s: "0x2837e1477e77431a7ab946de5d96ced06b71bab364453e1d36ffba7caf65acc3",
263 | to: "0x9358844d589f31c5c5515d65d156c3233d2fdc24",
264 | transactionIndex: 0,
265 | v: "0x267df7b",
266 | value: 5000000000000000000
267 | }
268 | ```
269 |
270 | #### 4. 连接到其他节点
271 | 节点间要相互连通,需满足三个条件:
272 | 1. 网络是相通的;
273 | 2. 使用相同的genesis.json初始化节点;
274 | 3. 启动节点时,--networkid选项指定相同的networkid。
275 |
276 | 现有两个节点,节点1与节点2,networkid都是20180908,通过下面的步骤建立连接。
277 | 1. 在节点1控制台使用admin.nodeInfo.enode获取enode信息
278 | ```
279 | > admin.nodeInfo.enode
280 | "enode://cfbed48b370aa24e31728459c45f4e0751026ce678bfebb618743bb9db37cb3104d50b8a1db6d8f435bfb7b8b6ca033389f1a336a75f708b07b4c96dd54effd8@[::]:60303"
281 | ```
282 | 2. 在节点2控制台使用admin.addPeer()加载节点1的enode信息
283 | ```
284 | > admin.addPeer("enode://cfbed48b370aa24e31728459c45f4e0751026ce678bfebb618743bb9db37cb3104d50b8a1db6d8f435bfb7b8b6ca033389f1a336a75f708b07b4c96dd54effd8@172.17.0.12:60303")
285 | true
286 | ```
287 | 3. 等待两个节点连接成功后,节点2就会开始同步节点1的区块,同步完成后,任意一个节点开始挖矿,另一个节点会自动同步区块。
288 |
--------------------------------------------------------------------------------
/Task/第二期任务归档-20180911/Spectrum链主网开发实战篇-主网搭建教程.md:
--------------------------------------------------------------------------------
1 | 作者: 唐爽 校阅者: rectinajh
2 |
3 |
4 |
系统版本: win7 64位
所需工具
1. Go version 1.7 或更高版本
2. GCC
安装Go:
完整下载地址: https://dl.google.com/go/go1.10.2.windows-amd64.msi
安装的路径为 C:\Go\目录下. 添加 C:\Go\bin到环境变量中.
安装GCC编译环境
下载地址: https://jaist.dl.sourceforge.net/project/mingw-w64/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/installer/mingw-w64-install.exe
添加 bin目录到环境变量中. win7,笔者默认路径在C:\mingw-w64\x86_64-7.1.0-win32-sjlj-rt_v5-rev0\mingw64\bin
测试是否安装成功.
命令行模式下:
1. go version
2. gcc
如果有显示则表示安装和配置成功.
编译 Spectrum链
下载源文件
下载地址:https://github.com/SmartMeshFoundation/Spectrum
将代码下载后解压到以下目录:
C:\Go\src\github.com\SmartMeshFoundation\Spectrum
执行命令: go install -v ./cmd/smc
启动网络
smc --datadir d:/specturm/data console
smc console,表示启动节点并进入交互式控制台,--datadir选项指定使用spectrum作为数据的目录
personal.newAccount()创建账户
相应的keystore会生成在data目录.
导入钱包:
下载smartmesh APP,安装
https://smartmesh.io/app/
复制keystore,导入到钱包.
转账测试
区块的速度确认相当快速,差不多5分钟就到账了,在APP中则基本上提交成功后就能显示到账记录.
控制台上用eth.getBalance('93d8eb9ca297d7a08ff12f709378c7502a0e6aef')查询也显示已经到账
89 |
90 |
91 |
--------------------------------------------------------------------------------
/Task/长期任务归档/译文-Casper+ShardingChainV2.1.md:
--------------------------------------------------------------------------------
1 | # Casper+Sharding chain v2.1
2 | ###### 译者:程阳
3 | 原文:https://notes.ethereum.org/SCIg8AH5SA-O4C1G1LYZHQ
4 |
5 | ### 工作正在进行中!!!
6 |
7 | 这是描述Casper + Sharding链第2.1版规范的工作进度文档。
8 |
9 | 在这个协议中,有一条中心PoS链存储和管理当前活跃的PoS验证者们。成为一名初始验证者唯一可用的机制是在现有的PoW主链上发送一条包含32ETH的交易。当你这样做了,PoS链一处理区块,你将会处在一个队列中,并最终以一名活跃的验证者正式加入,直到你自愿退出,或者因异常行为被处罚而被强制注销。
10 |
11 | PoS链上的主要负载源是认证(attestations)。一个认证包括两方面角色:
12 | 1. 证实信标区块(beacon chain)中的一些父区块
13 | 2. 证实一个区块在分片(shard)中的哈希(足够多这样的证明会创建一个交联(crosslink),来确保分片中的区块进入主链)
14 |
15 | 每个分片(总共可能有1024个分片)都是一个PoS链,分片链存储交易和账户信息。交联提供“确认”分片中的片段进入主链的服务,同时也是不同分片之间进行通信的主要方式。
16 |
17 | 值得一提的是,还可以考虑一种更简单的“最小切分算法”,其中交联只是提交的数据块的散列,这些数据块本身并不以任何方式相互链接。
18 |
19 | 注意: 在[https://github.com/ethereum/beacon_chain](https://github.com/ethereum/beacon_chain) 的python代码和 [an ethresear.ch post](https://ethresear.ch/t/convenience-link-to-full-casper-chain-v2-spec/2332)没有反映最新的更改。如果有人么差异,这个文档很可能会反映出最新的变化。
20 |
21 | ##### 术语:
22 | - 验证者(Validator)—— Casper/分片共识系统的参与者。通过存32ETH到Casper机制中就能成为一名验证者。
23 |
24 | - 活跃验证者集合(Active validator set)—— 那些正在参与的验证者,同时也是Casper机制寻求产生以及证明区块,交联和其他共识对象的验证者。
25 |
26 | - 委员会(Committee)—— 从活跃验证者集合中(伪)随机抽样的子集。当一个委员会被集体提及时,如“该委员会证明X”,这种假定为“该委员会的某个子集包含足够的验证者,该协议承认其代表委员会”。
27 |
28 | - 提案者(Proposer)—— 创建一个区块的验证者
29 |
30 | - 证明者(Attester)—— 在区块上签名的委员会中的一名验证者
31 |
32 | - 信标链(Beacon chain)—— 中心PoS链是分片系统的基础
33 |
34 | - 分片链(Shard chain)—— 进行交易和存储账户数据的链之一
35 |
36 | - 交联(Crosslink)—— 来自委员会的一组签名,证明一个块在分片链中,(签名)可以包含在信标链中。交联是信标链“了解”分片链更新状态的主要手段。
37 |
38 | - 时间槽(Slot)—— 每8秒一个周期,在一个周期里提案者可以创建一个区块,证明者可以去做验证
39 |
40 | - 改朝换代(Dynasty transition)—— 更换验证者集合
41 |
42 | - 朝代(Dynasty)—— 创世以来,在一个给定的链中改朝换代的次数
43 |
44 | - 时代(Cycle)—— 所有验证这都有一次机会进行验证的一组块
45 |
46 | - 最终化,合理(Finalized, justified) —— 参见Casper FFG终稿https://arxiv.org/abs/1710.09437
47 |
48 | ##### 常量:
49 | - SHARD_COUNT —— 分片数量的常量。现在设置的是1024
50 |
51 | - DEPOSIT_SIZE —— 32ETH
52 |
53 | - MAX_VALIDATOR_COUNT —— 222 = 4194304 # 注意:这意味着在同一时间最多只能下注1.34亿ETH
54 | 译者注:4194304 * 32 ETH = 134217728 ETH
55 |
56 | - SLOT_DURATION —— 8秒
57 |
58 | - CYCLE_LENGTH —— 64个时间槽
59 |
60 | - MIN_COMMITTEE_SIZE —— 128(理论基础:参见这里推荐的最小值111 [https://vitalik.ca/files/Ithaca201807_Sharding.pdf](https://vitalik.ca/files/Ithaca201807_Sharding.pdf))
61 |
62 | ##### PoW 主链的改变:
63 | 本PoS/分片提案可以独立于现存的PoW主链实施。主链只需要做两处变更(且第二个在技术上讲不是严格必要的)。
64 |
65 | - 在主链上添加一个合约。该合约允许你存```DEPOSIT_SIZE```(32)个ETH。```deposit```函数接收5个参数,分别是(i)```pubkey```(bytes),(ii)```withdrawal_shard_id```(int),(iii)```withdrawal_addr```(address),(iv)```randao_commitment```(bytes32),(v) ```bls_proof_of_possession```
66 | - 主链客户端将实现一个方法,```prioritize(block_hash,value)```。如果该区块可用并得到验证,该方法将(区块)分数设定为给定值,并递归调整所有后代的分数。这允许PoS信标链的终结小工具也能隐式地最终化主链区块。注意,将该方法实施到PoW客户端是对PoW分叉选择规则的更改,因此也是一种分叉。
67 |
68 | ##### 信标链
69 | 信标链是PoS系统中的“主链”。信标链的主要职责是:
70 | - 存储和维护活跃的,处于排队中和退出的验证者集合
71 | - 处理交联(参见前面)
72 | - 逐块处理共识,以及FFG终结小工具
73 |
74 | 这是进入每个信标链的区块的字段:
75 | ```
76 | fields = {
77 | # Hash of the parent block
78 | 'parent_hash': 'hash32',
79 | # Slot number (for the PoS mechanism)
80 | 'slot_number': 'int64',
81 | # Randao commitment reveal
82 | 'randao_reveal': 'hash32',
83 | # Attestations
84 | 'attestations': [AttestationRecord],
85 | # Reference to PoW chain block
86 | 'pow_chain_ref': 'hash32',
87 | # Hash of the active state
88 | 'active_state_root': 'hash32',
89 | # Hash of the crystallized state
90 | 'crystallized_state_root': 'hash32',
91 | }
92 | ```
93 |
94 | 信标链状态被分为两部分,活跃状态和结晶状态。
95 | 这是 ```ActiveState```:
96 | ```
97 | fields = {
98 | # Attestations that have not yet been processed
99 | 'pending_attestations': [AttestationRecord],
100 | # Most recent 2 * CYCLE_LENGTH block hashes, older to newer
101 | 'recent_block_hashes': ['hash32']
102 | }
103 | ```
104 |
105 | 这是 ```CrystallizedState```:
106 | ```
107 | fields = {
108 | # List of validators
109 | 'validators': [ValidatorRecord],
110 | # Last CrystallizedState recalculation
111 | 'last_state_recalc': 'int64',
112 | # What active validators are part of the attester set
113 | # at what slot, and in what shard. Starts at slot
114 | # last_state_recalc - CYCLE_LENGTH
115 | 'indices_for_slots': [[ShardAndCommittee]],
116 | # The last justified slot
117 | 'last_justified_slot': 'int64',
118 | # Number of consecutive justified slots ending at this one
119 | 'justified_streak': 'int64',
120 | # The last finalized slot
121 | 'last_finalized_slot': 'int64',
122 | # The current dynasty
123 | 'current_dynasty': 'int64',
124 | # The next shard that crosslinking assignment will start from
125 | 'crosslinking_start_shard': 'int16',
126 | # Records about the most recent crosslink `for each shard
127 | 'crosslink_records': [CrosslinkRecord],
128 | # Total balance of deposits
129 | 'total_deposits': 'int256',
130 | # Used to select the committees for each shard
131 | 'dynasty_seed': 'hash32',
132 | # Last time the crosslink seed was reset
133 | 'dynasty_seed_last_reset': 'int64'
134 | }
135 | ```
136 |
137 | 这是```ShardAndCommittee``` 对象的形式:
138 |
139 | ```
140 | fields = {
141 | # The shard ID
142 | 'shard_id': 'int16',
143 | # Validator indices
144 | 'committee': ['int24']
145 | }
146 | ```
147 |
148 | 每一个```ValidatorRecord```都包含了一个验证者(validator)的信息:
149 | ```
150 | fields = {
151 | # The validator's public key
152 | 'pubkey': 'int256',
153 | # What shard the validator's balance will be sent to
154 | # after withdrawal
155 | 'withdrawal_shard': 'int16',
156 | # And what address
157 | 'withdrawal_address': 'address',
158 | # The validator's current RANDAO beacon commitment
159 | 'randao_commitment': 'hash32',
160 | # Current balance
161 | 'balance': 'int64',
162 | # Dynasty where the validator is inducted
163 | 'start_dynasty': 'int64',
164 | # Dynasty where the validator leaves
165 | 'end_dynasty': 'int64'
166 | }
167 | ```
168 |
169 | 在```CrosslinkRecord``` 包含了上一个被提交到链上的完整的交联信息:
170 | ```
171 | fields = {
172 | # What dynasty the crosslink was submitted in
173 | 'dynasty': 'int64',
174 | # The block hash
175 | 'hash': 'hash32'
176 | }
177 | ```
178 |
179 | ##### 信标链处理
180 | 在很多方面,处理信标链基本上与处理一条PoW的链很相似。客户端下载和处理区块,并维护当前“权威链”的一个视图,在当前“块头”终止。然而,由于信标链与现有的PoW链的关系,并且因为它是一个PoS链,因此还是有一些区别。
181 |
182 | 对于信标链上的区块想要被一个node处理,得满足三个条件:
183 | - ```parent_hash```指向的双亲已经被处理并被接受
184 | - ```pow_chain_ref```指向PoW的主链区块已经被处理并被接受
185 | - node的本地时钟时间大于或等于```GENESIS_TIME + slot_number * SLOT_DURATION```计算而得的最小时间戳
186 |
187 | 如果不满足这三个条件,客户端应该会延迟处理该区块直到三个条件全部满足。
188 |
189 | 因为权益证明机制区块生产稍有不同。客户端要创建一个区块的时候,会简单的检查它认为权威的链,而且会查看他的slot numbner;当该时间槽(slot)到来时,它根据需要选择提案或者验证一个区块。
190 |
191 | ##### 信标链分叉选择规则
192 | 信标链使用 Casper FFG 的“热衷于包含(slot number)得分最高的合法区块的链”作为分叉选择规则。为了选择从同一合法区块派生的链,该链使用了“即时消息驱动GHOST(immediate message driven GHOST)”(IMD GHOST)来选择链头。
193 |
194 | 详细信息参见:[https://ethresear.ch/t/beacon-chain-casper-ffg-rpj-mini-spec/2760](https://ethresear.ch/t/beacon-chain-casper-ffg-rpj-mini-spec/2760)
195 |
196 | 对于具有网络仿真器的实现,请参见:[https://github.com/ethereum/research/blob/master/clock_disparity/ghost_node.py](https://github.com/ethereum/research/blob/master/clock_disparity/ghost_node.py)
197 |
198 | 这里有一个它的工作示例(绿色的是终结区块,黄色的是合法区块,灰色的是证明)
199 |
200 | 
201 |
202 | ##### 信标链状态转移函数
203 | 我们现在定义状态转移函数。从比较高的层面讲,状态转移由2部分组成:
204 | 1. 结晶状态重计算(crystallized state recalculation),只发生在```block.slot_number >= last_state_recalc + CYCLE_LENGTH```,并且影响```CrystallizedState```(结晶状态)和```ActiveState```(活跃状态)。
205 | 2. 处理每个块(per-block processing),这发生在每个块(如果是在结晶状态重计算期间,它发生在结晶状态重计算之后)并且只影响```ActiveState```(活跃状态)。
206 |
207 | 结晶状态重计算一般侧重验证人集合的改变上,包括调整余额,添加和移除验证者,以及处理交联和管理区块校验,而处理每个块一般侧重验证聚合签名和在活跃状态中保存相关区块内活动的临时记录。
208 |
209 | ##### 辅助函数
210 | 我们通过定义一些辅助算法开始。首先,该函数会选择以ixe活跃的验证者:
211 | ```
212 | def get_active_validator_indices(validators, dynasty):
213 | o = []
214 | for i in range(len(validators)):
215 | if validators[i].start_dynasty <= dynasty < \
216 | validators[i].end_dynasty:
217 | o.append(i)
218 | return o
219 | ```
220 |
221 | 现在,一个函数把这个列表打乱:
222 | ```
223 | def shuffle(lst, seed):
224 | assert len(lst) <= 16777216
225 | o = [x for x in lst]
226 | source = seed
227 | i = 0
228 | while i < len(lst):
229 | source = blake(source)
230 | for pos in range(0, 30, 3):
231 | m = int.from_bytes(source[pos:pos+3], 'big')
232 | remaining = len(lst) - i
233 | if remaining == 0:
234 | break
235 | rand_max = 16777216 - 16777216 % remaining
236 | if m < rand_max:
237 | replacement_pos = (m % remaining) + i
238 | o[i], o[replacement_pos] = o[replacement_pos], o[i]
239 | i += 1
240 | return o
241 | ```
242 |
243 | 然后,把这个列表分成N个片段:
244 | ```
245 | def split(lst, N):
246 | return [lst[len(lst)*i//N: len(lst)*(i+1)//N] for i in range(N)]
247 | ```
248 |
249 | 现在,把这些辅助方法集合到一起:
250 | ```
251 | def get_new_shuffling(seed, validators, dynasty, crosslinking_start_shard):
252 | avs = get_active_validator_indices(validators, dynasty)
253 | if len(avs) >= CYCLE_LENGTH * MIN_COMMITTEE_SIZE:
254 | committees_per_slot = len(avs) // CYCLE_LENGTH // (MIN_COMMITTEE_SIZE * 2) + 1
255 | slots_per_committee = 1
256 | else:
257 | committees_per_slot = 1
258 | slots_per_committee = 1
259 | while len(avs) * slots_per_committee < CYCLE_LENGTH * MIN_COMMITTEE_SIZE \
260 | and slots_per_committee < CYCLE_LENGTH:
261 | slots_per_committee *= 2
262 | o = []
263 | for i, slot_indices in enumerate(split(shuffle(avs, seed), CYCLE_LENGTH)):
264 | shard_indices = split(slot_indices, committees_per_slot)
265 | shard_id_start = crosslinking_start_shard + \
266 | i * committees_per_slot // slots_per_committee
267 | o.append([ShardAndCommittee(
268 | shard_id = (shard_id_start + j) % SHARD_COUNT,
269 | committee = indices
270 | ) for j, indices in enumerate(shard_indices)])
271 | return o
272 | ```
273 |
274 | 下边是一张工作流程示意图:
275 |
276 | 
277 |
278 | 同时,我们定义
279 | ```
280 | def get_indices_for_slot(crystallized_state, slot):
281 | ifh_start = crystallized_state.last_state_recalc - CYCLE_LENGTH
282 | assert ifh_start <= slot < ifh_start + CYCLE_LENGTH * 2
283 | return crystallized_state.indices_for_slots[slot - ifh_start]
284 |
285 | def get_block_hash(active_state, curblock, slot):
286 | sback = curblock.slot_number - CYCLE_LENGTH * 2
287 | assert sback <= slot < sback + CYCLE_LENGTH * 2
288 | return active_state.recent_block_hashes[slot - sback]
289 | ```
290 |
291 | 这里,```get_block_hash(*, *, h)``` 应该总是在时间 ```h``` 的时候返回一个区块,```get_indices_for_slot(*, h)``` 在朝代(dynasty)变更之前不应该有变化。
292 |
293 | ##### 启动时
294 | - 让 ```x = get_new_shuffling(bytes([0] * 32), validators, 1, 0)``` 然后设置 ```crystallized_state.indices_for_slots``` 为 ```x + x```
295 |
296 | - 设置 ```crystallized_state.dynasty = 1```
297 |
298 | - 设置 ```crystallized_state.crosslink_records``` 为 ```[CrosslinkRecord(dynasty=0, hash= bytes([0] * 32)) for i in range(SHARD_COUNT)]```
299 |
300 | - 设置 ```total_deposits``` 为 ```sum([x.balance for x in validators])```
301 |
302 | - 设置 ```recent_block_hashes``` 为 ```[bytes([0] * 32) for _ in range(CYCLE_LENGTH * 2)]```
303 |
304 | 其他在活动或者终结状态的值可以根据上下文设为0或者空。
305 |
306 | ##### 处理每个块
307 | 首先,将```recent_block_hashes```设置为下边输出的样子:
308 | ```
309 | def get_new_recent_block_hashes(old_block_hashes, parent_slot,
310 | current_slot, parent_hash):
311 | d = current_slot - parent_slot
312 | return old_block_hashes[d:] + [parent_hash] * min(d, len(old_block_hashes))
313 | ```
314 |
315 | 这里,```get_block_hash``` 的输出不应该改变,除非他不再抛出 ```current_slot - 1````, 而抛出 ```current_slot - CYCLE_LENGTH * 2 - 1```
316 |
317 | 一个区块可以有0个或者多个 ```AttestationRecord```,每一个 ```AttestationRecord``` 对象结构如下:
318 | ```
319 | fields = {
320 | # Slot number
321 | 'slot': 'int64',
322 | # Shard ID
323 | 'shard_id': 'int16',
324 | # List of block hashes that this signature is signing over that
325 | # are NOT part of the current chain, in order of oldest to newest
326 | 'oblique_parent_hashes': ['hash32'],
327 | # Block hash in the shard that we are attesting to
328 | 'shard_block_hash': 'hash32',
329 | # Who is participating
330 | 'attester_bitfield': 'bytes',
331 | # Last justified block
332 | 'justified_slot': 'int256',
333 | 'justified_block_hash': 'hash32',
334 | # The actual signature
335 | 'aggregate_sig': ['int256']
336 | }
337 | ```
338 |
339 | 每个证明需要作一下验证:
340 | - 验证 ```slot < block.slot_number``` 和 ```slot >= max(block.slot_number - CYCLE_LENGTH, 0)```
341 |
342 | - 验证链中给出的 ```justified_slot``` 和 ```justified_block_hash``` 等于或早于终结状态中的 ```last_justified_slot```
343 |
344 | - 计算 ```parent_hashes``` = ```[get_block_hash(active_state, block, slot - CYCLE_LENGTH + i) for i in range(1, CYCLE_LENGTH - len(oblique_parent_hashes) + 1)] + oblique_parent_hashes``` (例如,如果```CYCLE_LENGTH = 4```, ```slot = 5```,实际区块从时间0开始的哈希是 ```Z A B C D E F G H I J```,而且 ```oblique_parent_hashes = [D', E']``` 则 ```parent_hashes = [B, C, D' E']```)
345 |
346 | - 让 ```attestation_indices``` 成为 ```get_indices_for_slot(crystallized_state, slot)[x]```, 选择 ```x``` 所以 ```attestation_indices.shard_id``` 和创建验证记录的检验者集合的 ```shard_id```的值相等
347 |
348 | - 验证 ```len(attester_bitfield) == ceil_div8(len(attestation_indices))```,其中```ceil_div8 = (x + 7) // 8```。 验证位```len(attestation_indices)....```和更高的,如果出现了(比如,```len(attestation_indices``` 不是8的倍数),就全为0
349 |
350 | - 通过将所有测试者的公钥加入 ```attestation_indices``` 来为对应```attester_bitfield```(第i位是```attester_bitfield[i // 8] >> (7 - (i %8))) % 2```)等于1的人导出公钥集合
351 |
352 | - 通过生成的公钥组和消息 ```hash(slot.to_bytes(8, 'big') + parent_hashes + shard_id + shard_block_hash)``` 验证 ```aggregate_sig```
353 |
354 | 在 ```active_state``` 中扩展 ```AttestationRecord``` 对象的列表,按照块中新添加的顺序排列。
355 |
356 | 确认 ```get_indices_for_slot(crystallized_state, slot)[0]``` 中的第 ```slot % len(get_indices_for_slot(crystallized_state, slot)[0])``` 个验证者在至少一个```AttestationRecord```对象中;然后这个验证者就可以创建区块提案了。
357 |
358 | ##### 状态重计算
359 | 重复 ```slot - last_state_recalc >= CYCLE_LENGTH``` :
360 |
361 | 所有 ```last_state_recalc - CYCLE_LENGTH ... last_state_recalc - 1``` 中的时间槽 ```s```:
362 | - 最少判定一次合法区块中的全部验证者集合
363 |
364 | - 判定所有验证者的总余额。如果这个值的乘以3等于或者大于所有活跃验证者集合总余额的2倍,就设置 ```last_justified_slot = max(last_justified_slot, s)``` 和 ```justified_streak += 1```,否则```justified_streak = 0```
365 |
366 | - 如果 ```justified_streak >= CYCLE_LENGTH + 1``` ,则令 ```last_finalized_slot = max(last_finalized_slot, s - CYCLE_LENGTH - 1)```
367 |
368 | - 删除所有早于的 ```last_state_recalc``` 证明记录
369 |
370 | 同时:
371 | - 令 ```last_state_recalc += CYCLE_LENGTH```
372 | - 令 ```indices_for_slots[:CYCLE_LENGTH] = indices_for_slots[CYCLE_LENGTH:]```
373 |
374 | 对于所有的(```shard_id, shard_block_hash```)元组,计算证实分片上那个区块哈希的验证者的总存款。如果这个值乘以3等于或者大于委员会中所有验证者总余额的2倍,而且但前朝代超过了 ```crosslink_records[shard_id].dynasty```,就令```crosslink_records[shard_id] = CrosslinkRecord(dynasty=current_dynasty, hash=shard_block_hash)```。
375 |
376 | TODO:
377 | - 奖励FFG成员
378 | - 奖励委员会成员
379 |
380 | ##### 改朝换代
381 | TODO。正在完成中。
382 |
383 | ***
384 | 备注: 完成度大约70%。缺失的主要章节是:
385 | - Validator login/logout logic
386 |
387 | - Logic for the formats of shard chains, who proposes shard blocks, etc. (in an initial release, if desired we could make crosslinks just be Merkle roots of blobs of data; in any case, one can philosophically view the whole point of the shard chains as being a coordination device for choosing what blobs of data to propose as crosslinks)
388 |
389 | - Logic for inducting queued validators from the main chain
390 |
391 | - Penalties for signing or attesting to non-canonical-chain blocks (update: may not be necessary, see [https://ethresear.ch/t/attestation-committee-based-full-pos-chains/2259](https://ethresear.ch/t/attestation-committee-based-full-pos-chains/2259))
392 |
393 | - Slashing conditions
394 |
395 | - Logic for withdrawing deposits to shards
396 |
397 | - Per-validator proofs of custody
398 |
399 | - Full rewards and penalties
400 |
401 | - Versioning and upgrades
402 |
403 | 削减条件可能包括:
404 | ```
405 | Casper FFG slot equivocation
406 | Casper FFG surround
407 | Beacon chain proposal equivocation
408 | Shard chain proposal equivocation
409 | Proof of custody secret leak
410 | Proof of custody wrong custody bit
411 | Proof of custody no secret reveal
412 | RANDAO leak
413 | ```
414 |
--------------------------------------------------------------------------------
/Task/第二期任务归档-20180911/smt无网微支付解读.md:
--------------------------------------------------------------------------------
1 | 编辑人:@GirpZhang 审阅人:@rectinajh
2 | ### 引言
3 | `在互联网十分发达的今天,很多人已经习惯了数字支付,只要有网,随时都可以进行转账操作;但是依旧有许多情况下没有网络连接,比如一些偏远地区、岛屿、地下室等网络信号难以覆盖的地方或者手机停机等突发状况,这时候如何进行支付呢?有人可能会说支付宝微信即使没有网络也可以出示付款码,但这种方式的前提是对方(收款方)必须有网,我们在前面列举的一些场景中是交易双方都没有网络连接的,这就需要某些新技术和解决方案了,SmartRaiden 无网微支付就很好地解决了这一问题,下面我们就从设计和实现角度来看看它到底是什么。`
4 | ### 介绍
5 | SmartRaiden 无网微支付是基于 Raiden 网络扩展的 SmartMesh 支付协议,SmartMesh
6 | 用户之间通过手机 WiFi 或其他直连信号,P2P 传输签名加密交易信息,进行无网支付。SmartRaiden 是使用 Golang 编写的标准的 Raiden 网络协议,它可以在移动平台上实现离线交易,并且可以在没有互联网连接时运行。
7 | SmartRaiden 核心实现代码见:
8 | ### Raiden Network
9 | Raiden Network 是一种 off-chain 的可扩展性解决方案,可在 Ethereal 上实现符合 erc-20 标准的 token 传输。它允许参与者之间在没有任何全局共识机制的情况下进行安全的 token 交易,这是通过预先设置的带有数字签名和锁哈希的链上存款支付来实现的。因为仍要依赖于几个链上的操作来打开和关闭一对节点的支付通道,所以网络上的每对节点都难以创建通道。但是,如果(至少)存在一个通道,通过网络中的其他节点来连接两个支付节点,那么我们就不需要为这两个节点创建单独的通道了。该网络被命名为 Raiden Network,它具有类似路由算法和互锁信道通信的所有合约。
10 | Smartraiden 使用与 raiden 网络相同原理的支付通道网络技术,但 Smartraiden 是为更好地适应移动节点而特别设计的。我们将包含移动节点的支付渠道网络称为 smartraiden 网络,以区别于传统的 raiden 网络。
11 | 
12 |
13 |
14 |
15 | ### SmartRaiden 交易展示
16 | 假设我们有一个节点使用 AET 令牌连接到我们的通道网络,在这种情况下,该节点连接到另外 5 个节点,可以轻易将 token 转移到其直连节点。如果这个通道网络变得复杂,那么我们通过几个节点转移 token,这个通道的节点状态会连续改变。
17 | 交易前:
18 | 
19 |
20 | 交易后:
21 | 
22 | 在该图中,五个节点的地址分别是:
23 | * node 1 : 0x69C5621db8093ee9a26cc2e253f929316E6E5b92
24 | * node 2 : 0x31DdaC67e610c22d19E887fB1937BEE3079B56Cd
25 | * node 3 : 0xf0f6E53d6bbB9Debf35Da6531eC9f1141cd549d5
26 | * node 4 : 0x6B9E4D89EE3828e7a477eA9AA7B62810260e27E9
27 | * node 5 : 0x088da4d932A716946B3542A10a7E84edc98F72d8
28 |
29 | 交易流程从节点 1 开始,到节点 5 结束。然而,在图中我们只有一条到 5 的路径,即 1 到 2 到 4 到 5。交易完成后,此通道中 token 余额的变更为:
30 | node 1 to node 2 : 0xc4327c664D9c47230Be07436980Ea633cA3265e4
31 | node 1 initial deposit : 200
32 | node 2 initial deposit : 100
33 | node 1 balance : 150
34 | node 2 balance : 150
35 | node 2 to node 3 : 0xd1102D7a78B6f92De1ed3C7a182788DA3a630DDA
36 | node 2 initial deposit : 100
37 | node 3 initial deposit : 100
38 | node 2 balance : 100
39 | node 3 balance : 100
40 | node 2 to node 4 : 0xdF474bBc5802bFadc4A25cf46ad9a06589D5AF7D
41 | node 2 initial deposit : 200
42 | node 4 initial deposit : 100
43 | node 2 balance : 150
44 | node 4 balance : 150
45 | node 4 to node 5 : 0xd5CF2248292e75531d314B118a0390132bc7a5F0
46 | node 4 initial deposit : 100
47 | node 5 initial deposit : 100
48 | node 4 balance : 50
49 | node 5 balance : 150
50 |
51 | ### SmartRaiden 合约和通道的各种状态
52 | SmartRaiden 合约包括:
53 | - Netting Channel Library : 0xad5cb8fa8813f3106f3ab216176b6457ab08eb75
54 | - Channel Manager Library : 0xdb3a4dbae2b761ed2751f867ce197c531911382a
55 | - Registry Contract : 0x68e1b6ed7d2670e2211a585d68acfa8b60ccb828
56 | - Discovery Contract : 0x1e3941d8c05fffa7466216480209240cc26ea577
57 |
58 | Spectrum 合约发布地址 = 0x41Df0be8c4e4917f9Fc5F6F5F32e03F226E2410B
59 |
60 | #### 通道各状态解读
61 | 这里结合 SmartRaiden 合约代码来解读通道在生命周期内的各个状态。
62 | * 通道不存在
63 |
64 | 通道不存在有两种情况:一种是我们的通道永远不存在,另一种是我们已经完成了交易,因此通道和参与者的所有数据都已被删除。在这两种情况下,我们无法验证节点之间的交易,除非为交易再创建通道。
65 |
66 | * 通道打开
67 |
68 | 在节点与其直连节点之间创建通道时,通道的创建者有权指定 token 的地址,对方的地址,要存入的 token 的数量以及结算的时间段。一旦通道打开,参与者就可以进行交易。合约实现如下:
69 | ```
70 | /*
71 | 允许任何人调用,多次调用.
72 | 创建通道:
73 | 1. 允许任意两个不同有效地址之间创建通道
74 | 2. 两地址之间不能有多个通道
75 | 参数数说明:
76 | participant1,participant2 通道参与双方,都必须是有效地址,且不能相同
77 | settle_timeout 通道结算等待时间
78 | */
79 | /// @notice function to open a payment channel.
80 | /// @dev It can be invoked by anyone, any times. Any pair of distinct addresses can create a channel, but cannot create multiple channels within the pair.
81 | /// @param participant1 An address for a channel participant
82 | /// @param participant2 The address for another other channel participant, cannot be the same as participant1.
83 | /// @param settle_timeout Waited time between channel close and channel settle.
84 | function openChannel(address participant1, address participant2, uint64 settle_timeout)
85 | settleTimeoutValid(settle_timeout)
86 | public
87 | {
88 | bytes32 channel_identifier;
89 | require(participant1 != 0x0);
90 | require(participant2 != 0x0);
91 | require(participant1 != participant2);
92 | channel_identifier = getChannelIdentifier(participant1, participant2);
93 | Channel storage channel = channels[channel_identifier];
94 |
95 | // ensure that channel has not been created.
96 | require(channel.state == 0);
97 | // Store channel information
98 | channel.settle_timeout = settle_timeout;
99 | channel.open_block_number = uint64(block.number);
100 | // Mark channel as opened
101 | channel.state = 1;
102 |
103 | emit ChannelOpened(channel_identifier, participant1, participant2, settle_timeout);
104 | }
105 |
106 | ```
107 | * 通道存款
108 |
109 | 在支付通道打开后,只有一个节点进行存款,因此只有这个节点可以将他的 token 转移给他的交易对象。然后该节点可以发送消息,通知已存在为对方打开的交易支付渠道,之后对方也能够存入其 token。
110 | 存款部分实现是这样:
111 | ```
112 | /*
113 | 必须在通道 open 状态调用,可以重复调用多次,任何人都可以调用.
114 | 参数说明:
115 | participant 存钱给谁
116 | partner 通道另一方
117 | amount 存多少 token
118 | */
119 | /// @notice internal function to be invoked when depositing tokens into this channel.
120 | /// @dev this function must be invoked when channel has opened yet.
121 | /// @param participant channel creator
122 | /// @param partner the counterpart corresponding to participant.
123 | /// @param amount the amount of tokens deposited in this channel.
124 | /// @param from another address that transfers tokens to this channel.
125 | /// @param need_transfer a boolean value confirms whether this channel need another source of value.
126 | function depositInternal(address participant, address partner, uint256 amount, address from, bool need_transfer)
127 | internal
128 | {
129 | /*
130 | 为0,可能会在 TransferFrom 的时候成功,但是没有任何意义.
131 |
132 | */
133 | require(amount > 0);
134 | uint256 total_deposit;
135 | bytes32 channel_identifier;
136 | channel_identifier = getChannelIdentifier(participant, partner);
137 | Channel storage channel = channels[channel_identifier];
138 | Participant storage participant_state = channel.participants[participant];
139 | total_deposit = participant_state.deposit;
140 | if (need_transfer) {
141 | // Do the transfer
142 | require(token.transferFrom(from, address(this), amount));
143 | }
144 | require(channel.state == 1);
145 |
146 | // Update the participant's channel deposit
147 | total_deposit += amount;
148 | participant_state.deposit = total_deposit;
149 |
150 | emit ChannelNewDeposit(channel_identifier, participant, total_deposit);
151 | }
152 |
153 | ```
154 | 一般将通道打开和存款放在一起,这样可以节约不少 gas:
155 | ```
156 | /*
157 | 有三种调用途径:
158 | 分别是
159 | 1. 用户直接调用openChannelWithDeposit,
160 | 2. token 是 ERC223,通过 tokenFallback 调用
161 | 3. token 提供了 ApproveAndCall, 通过receiveApproval调用
162 | */
163 | /// @notice function to open channel and meanwhile make some deposits inside with certain threshold of settle_timeout.
164 | /// @dev parameter settle_timeout has to meet certain threshold in which case this function is able to operate.
165 | /// @param participant channel creator
166 | /// @param partner the counterpart corresponding to participant.
167 | /// @param settle_timeout time period for channel to settle.
168 | /// @param amount the amount of tokens to be deposited into this channel.
169 | /// @param from another third party address to deposit tokens if need_transfer is true.
170 | /// @param need_transfer a boolean value to confirm whether this channel need any token from outside.
171 | function openChannelWithDepositInternal(address participant, address partner, uint64 settle_timeout, uint256 amount, address from, bool need_transfer)
172 | settleTimeoutValid(settle_timeout)
173 | internal
174 | {
175 | bytes32 channel_identifier;
176 | require(participant != 0x0);
177 | require(partner != 0x0);
178 | require(participant != partner);
179 | require(amount > 0);
180 | channel_identifier = getChannelIdentifier(participant, partner);
181 | Channel storage channel = channels[channel_identifier];
182 | Participant storage participant_state = channel.participants[participant];
183 |
184 | // make sure that this channel has not been created.
185 | require(channel.state == 0);
186 |
187 | // Store channel information
188 | channel.settle_timeout = settle_timeout;
189 | channel.open_block_number = uint64(block.number);
190 |
191 | // Mark channel as opened
192 | channel.state = 1;
193 | if (need_transfer) {
194 | require(token.transferFrom(from, address(this), amount));
195 | }
196 | participant_state.deposit = amount;
197 | emit ChannelOpenedAndDeposit(channel_identifier, participant, partner, settle_timeout, amount);
198 | }
199 | ```
200 |
201 | * 通道转账
202 |
203 | 一旦节点通过 AET 令牌连接到支付通网络,它就可以访问另外 5 个节点。这个节点很容易将其 token 发送到另一个直连的节点,但如果想要发送到它们之间的中间节点,它们都需要构建到中间节点的通道,如果这些节点中的 token 可以满足此交易,则发生交易。
204 | 交易部分实现:
205 | ```
206 | /*
207 | 功能:在不关闭通道的情况下提现,任何人都可以调用
208 |
209 | 一旦一方提出 withdraw, 实际上和提出 cooperative settle 效果是一样的,就是不能再进行任何交易了.
210 | 必须等待 withdraw 完成才能重置交易数据,重新开始交易
211 | 参数说明:
212 | participant,partner 通道参与双方
213 | participant_balance: 取款方的 balance 是多少
214 | participant_withdraw:取款方需要取多少钱
215 | participant_signature,partner_signature 双方对这次提现的签名
216 | */
217 | /// @notice function to withdraw tokens while channel state is open. Anyone can invoke it.
218 | /// @dev Once a participant proposes to withdraw, which has the same effect as cooperative settle, that is, any transfer are forbidden.
219 | /// @dev After withdraw completes, transfers are able to resume.
220 | /// @param participant The address for a channel participant
221 | /// @param partner The address for the counterparts of participate
222 | /// @param participant_balance The token balance of participant
223 | /// @param participant_withdraw The amount of tokens that participant needs to withdraw
224 | /// @param participant_signature The signature of participant
225 | /// @param partner_signature The signature of partner
226 | function withDraw(
227 | address participant,
228 | address partner,
229 | uint256 participant_balance,
230 | uint256 participant_withdraw,
231 | bytes participant_signature,
232 | bytes partner_signature
233 | )
234 | public
235 | {
236 | uint256 total_deposit;
237 | bytes32 channel_identifier;
238 | uint64 open_block_number;
239 | uint256 partner_balance;
240 | channel_identifier = getChannelIdentifier(participant, partner);
241 | Channel storage channel = channels[channel_identifier];
242 | open_block_number = channel.open_block_number;
243 | require(channel.state == 1);
244 | // 验证双方签名有效
245 | require(participant == recoverAddressFromWithdrawProof(channel_identifier,
246 | participant,
247 | participant_balance,
248 | participant_withdraw,
249 | open_block_number,
250 | participant_signature
251 | ));
252 | require(partner == recoverAddressFromWithdrawProof(channel_identifier,
253 | participant,
254 | participant_balance,
255 | participant_withdraw,
256 | open_block_number,
257 | partner_signature
258 | ));
259 |
260 | Participant storage participant_state = channel.participants[participant];
261 | Participant storage partner_state = channel.participants[partner];
262 | //The sum of the provided deposit must be equal to the total available deposit
263 | total_deposit = participant_state.deposit + partner_state.deposit;
264 | partner_balance = total_deposit - participant_balance;
265 |
266 |
267 | /*
268 | 谨慎一点,应该先扣钱再转账,尽量按照规范来,如果有的话.
269 | */
270 |
271 | /*
272 | 提议提现的人,金额一定不能是0,否则就应该调用 cooperative settle
273 | */
274 | require(participant_withdraw > 0);
275 | require(participant_withdraw <= participant_balance);
276 | //防止溢出
277 | require(total_deposit >= participant_balance);
278 | require(total_deposit >= partner_balance);
279 |
280 | participant_balance -= participant_withdraw;
281 | participant_state.deposit = participant_balance;
282 | partner_state.deposit = partner_balance;
283 |
284 | // 相当于 通道 settle 又新开了.老的签名都作废了.
285 | channel.open_block_number = uint64(block.number);
286 | require(token.transfer(participant, participant_withdraw));
287 |
288 |
289 | //channel's status right now
290 | emit ChannelWithdraw(channel_identifier, participant, participant_balance, partner, partner_balance);
291 |
292 | }
293 | ```
294 |
295 | * 通道关闭
296 |
297 | 如果任何节点想要关闭连接到它的某个通道,他可以调用 close 方法。之后,通道关闭操作者及其对应节点需要在结算期间提交余额证明。
298 | 关闭通道操作:
299 | ```
300 | /*
301 | 只能是通道参与方调用,只能调用一次,必须是在通道打开状态调用.
302 | 参数说明:
303 | partner 通道的另一方
304 | transferred_amount 另一方给的直接转账金额
305 | locksroot 另一方彻底完成交易集合
306 | nonce 另一方交易编号
307 | additional_hash 为了辅助实现用
308 | signature partner 的签名
309 | */
310 | /// @notice function to close a payment channel with balance proof from his channel counterpart.
311 | /// @dev It can be invoked merely when channel state is open, and only by channel participants and only once.
312 | /// @param partner The address of channel partner.
313 | /// @param transferred_amount The amount of tokens that partner has been transferred till now.
314 | /// @param locksroot The set of incomplete transfers that have been hash locked in partner's balanceproof.
315 | /// @param nonce The newest serial number for partner's transfer.
316 | /// @param additional_hash A hash value for auxiliary usage.
317 | /// @param signature Partner's signature.
318 | function closeChannel(
319 | address partner,
320 | uint256 transferred_amount,
321 | bytes32 locksroot,
322 | uint64 nonce,
323 | bytes32 additional_hash,
324 | bytes signature
325 | )
326 | public
327 | {
328 | bytes32 channel_identifier;
329 | address recovered_partner_address;
330 | channel_identifier = getChannelIdentifier(msg.sender, partner);
331 | Channel storage channel = channels[channel_identifier];
332 | require(channel.state == 1);
333 | // Mark the channel as closed and mark the closing participant
334 | channel.state = 2;
335 | // This is the block number at which the channel can be settled.
336 | channel.settle_block_number = channel.settle_timeout + uint64(block.number);
337 | // Nonce 0 means that the closer never received a transfer, therefore never received a
338 | // balance proof, or he is intentionally not providing the latest transfer, in which case
339 | // the closing party is going to lose the tokens that were transferred to him.
340 | if (nonce > 0) {
341 | Participant storage partner_state = channel.participants[partner];
342 | recovered_partner_address = recoverAddressFromBalanceProof(
343 | channel_identifier,
344 | transferred_amount,
345 | locksroot,
346 | nonce,
347 | channel.open_block_number,
348 | additional_hash,
349 | signature
350 | );
351 | require(partner == recovered_partner_address);
352 | partner_state.balance_hash = calceBalanceHash(transferred_amount, locksroot);
353 | partner_state.nonce = nonce;
354 | }
355 | emit ChannelClosed(channel_identifier, msg.sender, locksroot, transferred_amount);
356 | }
357 | ```
358 |
359 | * 通道结算
360 |
361 | 一旦调用 close 方法, timeout 开始计时。在此期间,两个节点都会提交最新消息。 timeout 结束后,通道完成结算。合约代码:
362 | ```
363 | /*
364 | 只能通道参与方调用,不限制 close 和非 close 方,可以调用多次,只要在有效期内.
365 | 包括 closing 方和非 close 方都可以反复调用在,只要能够提供更新的 nonce 即可.
366 | 目的是更新partner 的 balance proof, 只是自己直接调用,不经过第三方委托.
367 | 参数说明:
368 | partner: 证据待更新一方
369 | transferred_amount locksroot 的直接转账金额
370 | locksroot partner 未彻底完成交易集合
371 | nonce partner 给出交易变化
372 | additional_hash 实现辅助信息
373 | partner_signature partner 一方对于给出证据的签名
374 | */
375 | /// @notice function to update channel partner's balance proof.
376 | /// @dev It can be invoked merely by channel participants with multiples times if in channel lifecycle.
377 | /// @param partner The address whose balance proof is about to get updated.
378 | /// @param transferred_amount The amount of tokens that has been transferred from partner.
379 | /// @param locksroot The set of transfers that has been hash locked.
380 | /// @param nonce The serial number of transfers that partner has sent out.
381 | /// @param additional_hash The hash value used for auxiliary usage.
382 | /// @param partner_signature The signature of channel partner.
383 | function updateBalanceProof(
384 | address partner,
385 | uint256 transferred_amount,
386 | bytes32 locksroot,
387 | uint64 nonce,
388 | bytes32 additional_hash,
389 | bytes partner_signature
390 | )
391 | public
392 | {
393 | bytes32 channel_identifier;
394 | channel_identifier = getChannelIdentifier(partner, msg.sender);
395 | Channel storage channel = channels[channel_identifier];
396 | Participant storage partner_state = channel.participants[partner];
397 | require(channel.state == 2);
398 | require(channel.settle_block_number >= block.number);
399 | //明确要求,必须有更新的 balance proof, 否则没必要调用
400 | require(nonce > partner_state.nonce);
401 |
402 | require(partner == recoverAddressFromBalanceProof(
403 | channel_identifier,
404 | transferred_amount,
405 | locksroot,
406 | nonce,
407 | channel.open_block_number,
408 | additional_hash,
409 | partner_signature
410 | ));
411 | partner_state.balance_hash = calceBalanceHash(transferred_amount, locksroot);
412 | partner_state.nonce = nonce;
413 | emit BalanceProofUpdated(channel_identifier, partner, locksroot, transferred_amount);
414 | }
415 | ```
416 |
417 | ### SmartRaiden 的主要功能和特性
418 | SmartRaiden 的主要目标是构建一个结构,为 SmartRaiden Network 实施一个 off chain 可扩展性解决方案,从而提高可用性,兼容性和安全性。
419 | 其常规功能包括查询,注册,通道依赖和不同场景下的传输,API 详见 [rest_api](https://smartraiden.readthedocs.io/en/latest/rest_api/)。
420 | 其他功能包括:
421 | * 跨平台和移动端适应
422 | SmartRaiden 网络支持多个平台,并且可以实现移动智能设备上的分布式微支付。SmartRaiden 目前可以在 Windows,Linux,Android,iOS 等上运行。SmartRaiden 在 XMPP 而非 P2P上构建自己的消息传递机制,同时具备单独的节点和启动过程,确保它能够在具有正确操作的多个平台上运行。
423 | * 节点状态同步
424 | 为了保证交易安全,SmartRaiden 采用状态机来设计节点,确保相关操作是原子性的。例如,它能确保接收到的数据解锁记录和ACK报文发送的信息一致,两者都成功或者都不成功,不存在中间状态。在交易处理过程中,如果出现任何错误的情况,都会确保双方的交易状态一致,在崩溃恢复后,要么交易继续,要么交易失败,没有任何 token 损失。
425 |
426 | * 无网付款
427 | 它是 SmartRaiden 中添加的一项特殊功能。通过 meshbox 中的网络构建功能,SmartRaiden 能够在不依赖互联网的情况下实施 off chain 的资金转移。
428 |
429 | * 第三方代委托
430 | 第三方委托服务,也称为 SmartRaiden 监控,主要用于在移动设备在离线时由第三方委托来帮助在区块链上强制执行 UpdateTransferDelegate 或 WithDraw 操作。第三方服务与其系统外部的 App,SmartRaiden 和 spectrum 三部分进行交互。
431 |
432 | * 固定费用
433 | 与 Lightning Network 类似,我们在 token 转账的过程中还有一个额外的固定费率收费功能。受此费用的激励,该路由上的所有节点将保留通道的余额,以提高效率和交易的成功率。
434 |
435 | ## 结论
436 |
437 | 前面结合代码实现解读了有关 SmartRaiden 的概念和功能。如需进一步使用,请参阅安装[说明](https://smartraiden.readthedocs.io/en/latest/installation_guide/)和[教程](https://smartraiden.readthedocs.io/en/latest/api_walkthrough/)或 [SmartRaiden 规范](https://smartraiden.readthedocs.io/en/latest/spec/)
--------------------------------------------------------------------------------