Neo私链

为了研究Neo的代码,需要看一下Neo到底怎么运行的,在网络上跑一个智能合约,并且调试该网络。所以先搭建一个私链玩玩。

配置虚拟机

NEO 私有链的部署至少需要 4 台服务器才能取得共识,每台服务器对应一个共识节点。在阿里云上可以买按量付费的虚拟机(机器都是window server)。
记录下四台机器的内网IP地址,后面要用。

172.xxx.xxx.142

端口

如果你想让外部程序访问该节点的 API 需要开放防火墙端口:10331-10334, 20331-20334
阿里云的vpc如果在一个安全组内就不需要设置。也可以通过安全组开放所有入口。


阿里云安全组

安装运行时

  • 运行环境

运行 NEO 节点需要安装 .NET Core Runtime,需要安装 1.0.1 或以上版本

  • Windows 系统下的安装方法

在 Windows 系统下安装 .NET Core 非常方便,直接下载运行即可。

NOTE

Windows可能还需要安装Microsoft Visual C++ 2015 Redistributable Update 3(https://www.microsoft.com/en-... ,否则后面无法启动Neo-CLI。

创建钱包

在四台机器上分别创建钱包数据库,数据库文件会默认生成在neo-cli的目录下面

 create wallet wallet.json
  • db3后缀名的数据库文件不支持了

neo1

neo> create wallet wallet.db3
Wallet files in db3 format are not supported, please use a .json file extension.
neo> create wallet wallet.json
password: ********
password: ********
address: AS43TUy7VtuGpNJh2YC2NM3asTv3s6piyk
 pubkey: 02d57c9bbc42b45943867dff0180cb9df266b46db7d027a283eabc7c4b8819c86c

记录下另外几台机器的钱包公钥

neo2

address: AY35ZjJayg9JfmCeHg1nySN4LSMntFEq2h
 pubkey: 035022ce81faca930ebe6b9f8e830526150e47692f19f58affe1311e42cd0d43bb

neo3

address: AQZNtdGVXbfot5fSaR4ijBqrEwbnFQspmH
 pubkey: 029f21d56f9422e55f0ef7cf75c092854e01c99aeee73f0effeaa489a96fc7d2b1

neo4

address: AXctyT8ctWTXtWaUFM9o5FJas8BWdBbiqe
 pubkey: 02dc0e750e21c386537618079d89836eea39fad396206e2e56cfba16bdc014dc5d

修改节点的配置文件

{
  "ProtocolConfiguration": {
    "Magic": 1,
    "AddressVersion": 23,
    "StandbyValidators": [
      "02d57c9bbc42b45943867dff0180cb9df266b46db7d027a283eabc7c4b8819c86c",
      "035022ce81faca930ebe6b9f8e830526150e47692f19f58affe1311e42cd0d43bb",
      "029f21d56f9422e55f0ef7cf75c092854e01c99aeee73f0effeaa489a96fc7d2b1",
      "02dc0e750e21c386537618079d89836eea39fad396206e2e56cfba16bdc014dc5d"
    ],
    "SeedList": [
      "172.24.198.142:10333",
      "172.24.198.141:10333",
      "172.24.198.140:10333",
      "172.24.198.139:10333"
    ],
    "SystemFee": {
      "EnrollmentTransaction": 0,
      "IssueTransaction": 0,
      "PublishTransaction": 0,
      "RegisterTransaction": 0
    }
  }
}

打开钱包,开启共识

open wallet wallet.json
start consensus

如果前面打开过cli,请删除chain目录下的文件,这样区块链高度会从1开始。

  • 截取其中一个打印,后面方便调试的时候研究
neo> open wallet wallet.json
password: ********
neo> start consensus
[18:04:31] OnStart
[18:04:31] initialize: height=1 view=0 index=0 role=Backup
[18:04:47] OnChangeViewReceived: height=1 view=0 index=2 nv=2
[18:05:01] timeout: height=1 view=0 state=Backup
[18:05:01] request change view: height=1 view=0 nv=1 state=Backup, ViewChanging
[18:05:58] OnPrepareRequestReceived: height=1 view=0 index=1 tx=1
[18:05:58] send perpare response
[18:06:01] OnPrepareResponseReceived: height=1 view=0 index=2
[18:06:01] relay block: 0x8515184285fa2e454b0eca441580b5cce01cc0e5cb5dd6d7ff53ef13ec7f665e
[18:06:01] persist block: 0x8515184285fa2e454b0eca441580b5cce01cc0e5cb5dd6d7ff53ef13ec7f665e
[18:06:01] initialize: height=2 view=0 index=0 role=Backup
[18:06:16] OnPrepareRequestReceived: height=2 view=0 index=2 tx=1
[18:06:16] send perpare response
[18:06:19] OnPrepareResponseReceived: height=2 view=0 index=1
[18:06:19] relay block: 0x35b163f4f524a1ebcc1ef3053e878f9bb37b1f4a8531a060ef18cfd6efefdf45
[18:06:19] persist block: 0x35b163f4f524a1ebcc1ef3053e878f9bb37b1f4a8531a060ef18cfd6efefdf45
[18:06:19] initialize: height=3 view=0 index=0 role=Backup
[18:06:49] timeout: height=3 view=0 state=Backup
[18:06:49] request change view: height=3 view=0 nv=1 state=Backup, ViewChanging
[18:06:49] OnChangeViewReceived: height=3 view=0 index=1 nv=1
[18:06:53] OnChangeViewReceived: height=3 view=0 index=2 nv=1
[18:06:53] initialize: height=3 view=1 index=0 role=Backup
[18:06:55] OnPrepareRequestReceived: height=3 view=1 index=2 tx=1
[18:06:55] send perpare response
[18:06:55] OnPrepareResponseReceived: height=3 view=1 index=1
[18:06:55] relay block: 0x1766a0602903f513f76561c93fddf312f70d30801310abfecacc89feace5c412
[18:06:55] persist block: 0x1766a0602903f513f76561c93fddf312f70d30801310abfecacc89feace5c412
[18:06:55] initialize: height=4 view=0 index=0 role=Primary
[18:07:10] timeout: height=4 view=0 state=Primary
[18:07:10] send perpare request: height=4 view=0
[18:07:13] OnPrepareResponseReceived: height=4 view=0 index=3
[18:07:13] OnPrepareResponseReceived: height=4 view=0 index=2
[18:07:13] relay block: 0x5233d9086db97e59f86d73e8735093c1b3fe4569759697ff8a04e0eb8f389091
[18:07:13] persist block: 0x5233d9086db97e59f86d73e8735093c1b3fe4569759697ff8a04e0eb8f389091
[18:07:13] initialize: height=5 view=0 index=0 role=Backup

提取Neo

原来文章中有提取neo和gas的方法,但是我现在还不知道为什么要提取Neo,有什么意义,先跟着文档跑着看看。我用的window server会遇到crash,详情请看https://github.com/neo-projec...
希望Neo社区的大牛能解决一下这个问题。

一天后,社区给出的解决方案https://github.com/neo-projec...,需要下载两个包

结论

虽然配置成功了,但是还不知道能干吗,需要进一步研究。提取Neo也遇到崩溃的情况,发现这个问题,也算做贡献了。

参考文章
基于NEO的私链(Private Blockchain)
用 NEO 节点搭建私有链

作者:沈寅
链接:https://www.jianshu.com/p/df4...

你可能感兴趣的:(github)