通过 Cumulus 连接 Substrate 区块链到波卡

1. Substrate Cumulus Workshop

  • 官方文档: https://substrate.dev/cumulus-workshop/#/en/ (因为官方文档会更新,所以命令可能会变)
  • 此文档命令基于本地ubuntu虚拟机,与其他系统命令也大致相同,自己玩推荐使用2cpu,8gb内存,磁盘空间>=50G
  • 其它系统推荐mac os

2. Install Substrate Prerequisites (部署substrate环境)

3.安装基本库:

  • sudo apt update
  • sudo apt install -y cmake pkg-config libssl-dev git build-essential clang libclang-dev curl libz-dev

4.Rust Developer Environment (rust开发环境)

  • curl https://sh.rustup.rs -sSf | sh

  • source ~/.cargo/env

  • rustup default stable

  • rustup update

  • rustup update nightly

  • rustup target add wasm32-unknown-unknown --toolchain nightly

    运行完毕后上面三条命令再依此运行一遍,如下:

  • rustup update

  • rustup update nightly

  • rustup target add wasm32-unknown-unknown --toolchain nightly

  • rustup install nightly-2020-10-06

  • rustup target add wasm32-unknown-unknown --toolchain nightly-2020-10-06

5.构建中继链节点

  • git clone https://github.com/paritytech/polkadot.git
  • cd polkadot
  • git checkout 46c826f
  • cargo build --release --features=real-overseer
  • ./target/release/polkadot --help (如果运行此命令后输出了帮助页面,则证明polkadot节点构建成功)

6.构建Collator模板

  • git clone https://github.com/substrate-developer-hub/substrate-parachain-template
  • cd substrate-parachain-template
  • git checkout 465d539
  • cargo build --release
  • ./target/release/parachain-collator --help

7.Generate a Plain Chain Spec(创建链规范文件)

  • ./target/release/polkadot build-spec --chain rococo-local --disable-default-bootnode > rococo-custom-plain.json

8.Adjust the Chain Spec(修改链规范)

  • ./target/release/polkadot key inspect-key --scheme sr25519 --network substrate //Alice//stash
  • ./target/release/polkadot key inspect-key --scheme ed25519 --network substrate //Alice
  • ./target/release/polkadot key inspect-key --scheme sr25519 --network substrate //Alice

9.Convert to Raw Chain Spec(生成最终的 raw spec文件 )

  • ./target/release/polkadot build-spec --chain rococo-custom-plain.json --raw --disable-default-bootnode > rococo-custom.json

10.启动中继链

11.启动alice节点

  •   ./target/release/polkadot \
      --chain rococo-custom.json \
        --tmp \
        --ws-port 9944 \
        --port 30333 \
        --alice
      
    

12.连接UI界面(在虚拟机浏览器中运行)

13. 启动bob节点

  •   ./target/release/polkadot \
        --chain rococo-custom.json \
        --tmp \
        --ws-port 9955 \
        --port 30334 \
        --bob
        --bootnodes /ip4/<Alice IP>/tcp/30333/p2p/<Alice Peer ID>
    
  • bootnodes标志,如果您在单个本地系统上运行整个网络,那么这个bootnodes标志并不是严格必需的,但是在网络上运行时是必需的,这里不需要加上

启动其他节点(可选)

./target/release/polkadot \
  --chain rococo-custom.json \
  --tmp \
  --ws-port 9966 \
  --port 30335 \
  --charlie

14.运行平行链

生成初始状态

  • > 要注册一条平行链,中继链必须要知道平行链的初始状态。收集者节点可以为我们将该状态输出到文件中。 下面的命令将会创建一个文件,其中包括平行链的整个初始状态,十六进制编码。

  • ./target/release/parachain-collator export-genesis-state --parachain-id 200 > para-200-genesis

获取Wasm验证函数

  • > 中继链同样需要具体的平行链验证逻辑去验证平行链区块。收集者节点还有一个生成这个wasm blob的命令。

  • ./target/release/parachain-collator export-genesis-wasm > para-200-wasm

启动collator节点

./target/release/parachain-collator \
  --collator \
  --tmp \
  --parachain-id 200 \
  --port 40333 \
  --ws-port 9844 \
  --alice \
  -- \
  --execution wasm \
  --chain ../polkadot/rococo-custom.json\
  --port 30343 \
  --ws-port 9977

  • 关于这个命令,需要注意的一件事是,许多的参数在--之前被传递,以及更多的参数在它之后被传递。一个cumulus收集者包含实际的收集者节点,而且 也包含一个嵌入的中继链节点。这些参数在--之前是用于收集者,在--之后是用于嵌入的中继链节点。

    我们给收集者一个基本路径和端口,就像我们之前为中继链节点做的那样。我们也指定parachain ID。如果您对第二条平行链执行这些指令,请记住修改这些具体的收集者的值。 然后,我们给嵌入的中继链节点我们正在使用的中继链规范。最后,我们给嵌入的中继链节点一些对等的地址。

运行成功后会显示

2021-01-14 15:47:03  Cumulus Test Parachain Collator
2021-01-14 15:47:03  ✌️  version 0.1.0-4786231-x86_64-linux-gnu
2021-01-14 15:47:03  ❤️  by Parity Technologies <admin@parity.io>, 2017-2021
2021-01-14 15:47:03  📋 Chain specification: Local Testnet
2021-01-14 15:47:03  🏷 Node name: Alice
2021-01-14 15:47:03  👤 Role: AUTHORITY
2021-01-14 15:47:03  💾 Database: RocksDb at /tmp/substrateIZ0HQm/chains/local_testnet/db
2021-01-14 15:47:03  ⛓  Native runtime: cumulus-test-parachain-3 (cumulus-test-parachain-1.tx1.au1)
2021-01-14 15:47:03  Parachain id: Id(200)
2021-01-14 15:47:03  Parachain Account: 5Ec4AhPTL6nWnUnw58QzjJvFd3QATwHA3UJnvSD4GVSQ7Gop
2021-01-14 15:47:03  Parachain genesis state: 0x000000000000000000000000000000000000000000000000000000000000000000b86f2a5f94d1029bf54b07867c3c2fa0339e69e31748cfd5921bbb2f176ada6f03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c11131400
2021-01-14 15:47:03  Is collating: yes
2021-01-14 15:47:04  [Relaychain] 🔨 Initializing Genesis block/state (state: 0x1693…5e3f, header-hash: 0x2fc1…2ec3)
2021-01-14 15:47:04  [Relaychain] 👴 Loading GRANDPA authority set from genesis on what appears to be first startup.
2021-01-14 15:47:04  [Relaychain] ⏱  Loaded block-time = 6000 milliseconds from genesis on first-launch
2021-01-14 15:47:04  [Relaychain] 👶 Creating empty BABE epoch changes on what appears to be first startup.
2021-01-14 15:47:04  [Relaychain] 🏷 Local node identity is: 12D3KooWDTBqULpZPTTnRrEZtA53xG3Ade223mQfbLWstg7L3HA4
2021-01-14 15:47:04  [Relaychain] 📦 Highest known block at #0
2021-01-14 15:47:04  [Relaychain] 〽️ Prometheus server started at 127.0.0.1:9616
2021-01-14 15:47:04  [Relaychain] Listening for new connections on 127.0.0.1:9977.
2021-01-14 15:47:05  [Parachain] 🔨 Initializing Genesis block/state (state: 0xb86f…da6f, header-hash: 0x755b…42ca)
2021-01-14 15:47:05  [Parachain] Using default protocol ID "sup" because none is configured in the chain specs
2021-01-14 15:47:05  [Parachain] 🏷 Local node identity is: 12D3KooWEmhCGHnxfuYX9yWoWmnS1MSU7mkoZFnPSAKws2ZL3CCd
2021-01-14 15:47:05  [Parachain] 📦 Highest known block at #0
2021-01-14 15:47:05  [Parachain] Listening for new connections on 127.0.0.1:9855.
2021-01-14 15:47:06  [Relaychain] 🔍 Discovered new external address for our node: /ip4/127.0.0.1/tcp/30343/p2p/12D3KooWDTBqULpZPTTnRrEZtA53xG3Ade223mQfbLWstg7L3HA4
2021-01-14 15:47:06  [Relaychain] 🔍 Discovered new external address for our node: /ip4/192.168.178.77/tcp/30343/p2p/12D3KooWDTBqULpZPTTnRrEZtA53xG3Ade223mQfbLWstg7L3HA4
2021-01-14 15:47:06  [Parachain] 🔍 Discovered new external address for our node: /ip4/192.168.178.77/tcp/30433/p2p/12D3KooWEmhCGHnxfuYX9yWoWmnS1MSU7mkoZFnPSAKws2ZL3CCd
2021-01-14 15:47:08  [Relaychain] 👶 New epoch 29 launching at block 0x765e…c213 (block slot 268439271 >= start slot 268439271).
2021-01-14 15:47:08  [Relaychain] 👶 Next epoch starts at slot 268439281
2021-01-14 15:47:08  [Relaychain] ✨ Imported #291 (0x765e…c213)
2021-01-14 15:47:09  [Relaychain] 💤 Idle (3 peers), best: #291 (0x765e…c213), finalized #289 (0xca88…7eb1), ⬇ 196.9kiB/s ⬆ 161.9kiB/s
2021-01-14 15:47:10  [Parachain] 💤 Idle (0 peers), best: #0 (0x755b…42ca), finalized #0 (0x755b…42ca), ⬇ 809.4kiB/s ⬆ 773.7kiB/s
2021-01-14 15:47:12  [Relaychain] ✨ Imported #292 (0x1cdf…7cf7)
2021-01-14 15:47:12  [Relaychain] ✨ Imported #292 (0x26a5…7d91)
2021-01-14 15:47:14  [Relaychain] 💤 Idle (3 peers), best: #292 (0x1cdf…7cf7), finalized #289 (0xca88…7eb1), ⬇ 256.8kiB/s ⬆ 270.0kiB/s
2021-01-14 15:47:15  [Parachain] 💤 Idle (0 peers), best: #0 (0x755b…42ca), finalized #0 (0x755b…42ca), ⬇ 814.3kiB/s ⬆ 799.9kiB/s
2021-01-14 15:47:18  [Relaychain] ✨ Imported #293 (0x93d5…c54c)
2021-01-14 15:47:19  [Relaychain] 💤 Idle (3 peers), best: #293 (0x93d5…c54c), finalized #290 (0x1109…ea3d), ⬇ 203.6kiB/s ⬆ 200.5kiB/s
2021-01-14 15:47:20  [Parachain] 💤 Idle (0 peers), best: #0 (0x755b…42ca), finalized #0 (0x755b…42ca), ⬇ 751.0kiB/s ⬆ 730.2kiB/s
2021-01-14 15:47:24  [Relaychain] ✨ Imported #294 (0xbd35…8364)
2021-01-14 15:47:24  [Relaychain] 💤 Idle (3 peers), best: #294 (0xbd35…8364), finalized #290 (0x1109…ea3d), ⬇ 175.6kiB/s ⬆ 181.4kiB/s
2021-01-14 15:47:25  [Parachain] 💤 Idle (0 peers), best: #0 (0x755b…42ca), finalized #0 (0x755b…42ca), ⬇ 727.8kiB/s ⬆ 736.7kiB/s

15.注册交易

这个交易可以通过developer > Sudo > parasSudoWrapper > sudoScheduleParaInitialize进行,参数如下:

  • id: 200

  • ParaInfo: Always

  • code: upload the file para-200-wasm (from the previous step)

  • initial_head_data: upload the file para-200-genesis (from the previous step)

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-CrcqZfM1-1625558779560)(https://substrate.dev/cumulus-workshop/assets/img/registration-screenshot.png)]

    注意官网模块已更新,需要在developer > Sudo > parasSudoWrapper > sudoScheduleParaInitialize找到页面

区块生产

一旦成功注册后,收集者应该启动了生产平行链的区块(即排序)。收集者应该开始生成如下所示的日志信息:

注意:平行链出块可能需要等待一两分钟

2020-08-11 14:00:06 ✨ [Relaychain] Imported #28 (0x639d…d95b)
2020-08-11 14:00:06 🙌 Starting consensus session on top of parent 0xfbcfd7080ac31c2988240a6045217076b6debb3e70d4ad543f5cd09c96040630
2020-08-11 14:00:06 🎁 Prepared block for proposing at 1 [hash: 0x44a35ad9a5a6073a187a3e33022dfb40cbc96c5859fe790d710077ae426bc205; parent_hash: 0xfbcf…0630; extrinsics (3): [0x450c…68b5, 0x5dba…b245, 0x2259…cec2]]
2020-08-11 14:00:06 ✨ [Parachain] Imported #1 (0x44a3…c205)
2020-08-11 14:00:07 💤 [Relaychain] Idle (2 peers), best: #28 (0x639d…d95b), finalized #25 (0x65de…8e7a), ⬇ 182.7kiB/s ⬆ 1.1kiB/s
2020-08-11 14:00:11 💤 [Parachain] Idle (0 peers), best: #0 (0xfbcf…0630), finalized #0 (0xfbcf…0630), ⬇ 1.0kiB/s ⬆ 1.2kiB/s
2020-08-11 14:00:12 ✨ [Relaychain] Imported #29 (0x90b1…9d4a)
2020-08-11 14:00:12 🙌 Starting consensus session on top of parent 0x44a35ad9a5a6073a187a3e33022dfb40cbc96c5859fe790d710077ae426bc205
2020-08-11 14:00:12 🎁 Prepared block for proposing at 2 [hash: 0x08ea56463c6f5fe743c946b948e0e2f6b03c0f3c712b31957ae5522588863eb7; parent_hash: 0x44a3…c205; extrinsics (3): [0x33f3…0c81, 0x5629…0b51, 0x2259…cec2]]
2020-08-11 14:00:12 ✨ [Parachain] Imported #2 (0x08ea…3eb7)
2020-08-11 14:00:12 💤 [Relaychain] Idle (2 peers), best: #29 (0x90b1…9d4a), finalized #26 (0x8172…e683), ⬇ 274.1kiB/s ⬆ 274.0kiB/s
2020-08-11 14:00:16 💤 [Parachain] Idle (0 peers), best: #1 (0x44a3…c205), finalized #0 (0xfbcf…0630), ⬇ 0.8kiB/s ⬆ 0.8kiB/s

更新头部

中继链跟踪每个平行链的最新的头部信息。 当一个中继链的区块被确认,任何已经完成验证过程的平行链也都会完成。 这就是Polkadot如何实现共享安全的方式。

我们可以跟踪哪些平行链被注册了,以及它们的最新的头部数据在Apps ui里的Network > Parachains

Parachain Head Information

注意:官网未能显示此页面,应该是存在bug

16.连接平行链收集人UI界面

在新的浏览器窗口中打开另一个Apps示例,并将其连接到相应的端点。 如果您已经按照这些说明进行了操作,您可以在https://polkadot.js.org/apps/#/?rpc=ws://localhost:9844 连接页面

提交交易

可以进行一些简单的代币转账以确保平行链正常运行。您也可以通过提交Extrinsics -> System -> remark来进行链上的备注。

如果交易事务像期待中的运行的话,您就有了一个正在工作的平行链!

17.添加平行链节点

一条平行链 只能 使用一个收集者节点。但是这种配置并不是非常去中心化。一个恶意的对方只要关闭单个节点就可让平行链失控。

启动第二个收集者节点

运行其它收集者节点的命令如下。这个命令与我们用来启动第一个收集者节点的命令几乎完全相同,但是我们需要避免冲突的端口和目录

./target/release/parachain-collator \
  --collator \
  --tmp
  --parachain-id <Your ID> \
  --port <Your chosen libp2p port> \
  --ws-port <Your chosen websocket port> \
  --bootnodes <Your first collator> \
  --bob \
  -- \ # Any flags after this -- go to the embedded polkadot node
  --chain <relay chain spec json> \
  --port <Your chosen libp2p port> \
  --ws-port <Your chosen websocket port> \
  --bootnodes <Alice, and other relay chain collators>
 
 上方命令在运行时如果有问题,切换成如下格式: 
  
  ./target/release/parachain-collator --collator --tmp --parachain-id 200 --port 40123 --ws-port 9888 --bootnodes /ip4/192.168.136.138/tcp/40333/p2p/12D3KooWFi7yEWhpiQmA3jje3jJFFNbRhB5TqjRYp7rHkfpxNnT4 --bob -- --chain ../polkadot/rococo-custom.json --port 30123 --ws-port 9971 --bootnodes /ip4/192.168.136.138/tcp/30343/p2p/12D3KooWQaDttKQzzFuJhg1rBsdmB33fvyCASUmDSS2qhaUmyB3Y
  
   注意:bootnodes后面的代码需要根据自己电脑来修改

全节点

在平行链启动一个无收集人全节点也是可以的,只需省略——collator标志

./target/release/parachain-collator \
  --tmp
  --bootnodes <Your first collator> \
  --ws-port <Your chosen websocket port> \
  --port <Your chosen libp2p port> \
  --parachain-id <Your ID> \
  -- \ # Any flags after this -- go to the embedded polkadot node
  --chain spec.json \
  --bootnodes <Alice, Bob, and other relay chain collators>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
您好,以下是Cumulus交换机配置V-STP的步骤: 1. 首先,确认您的交换机支持V-STP功能,并且已经启用了STP协议。 2. 进入交换机的配置模式。 3. 输入以下命令启用V-STP功能: ``` switch(config)# spanning-tree protocol-version rstp-mst switch(config)# spanning-tree vlan 1-4094 mode mstp ``` 其中,vlan 1-4094表示启用所有VLAN的MSTP模式。 4. 配置V-STP实例。您可以为每个VLAN配置一个实例,或者将多个VLAN分配到同一个实例中。 ``` switch(config)# spanning-tree mst configuration switch(config-mst)# name instance1 switch(config-mst)# revision 1 switch(config-mst)# instance 1 vlan 10-20 switch(config-mst)# instance 2 vlan 30-40 ``` 其中,instance1表示实例名称,revision 1表示版本号,vlan 10-20和vlan 30-40表示将这些VLAN分配到实例1和实例2中。 5. 配置V-STP端口。将每个端口配置为所属的VLAN和实例。 ``` switch(config)# interface swp1 switch(config-if)# switchport switch(config-if)# switchport mode trunk switch(config-if)# switchport trunk allowed vlan 10-20 switch(config-if)# spanning-tree mst instance 1 vlan 10-20 ``` 其中,swp1表示端口名称,switchport mode trunk表示将端口配置为trunk模式,switchport trunk allowed vlan 10-20表示允许VLAN 10-20通过该端口,spanning-tree mst instance 1 vlan 10-20表示将该端口配置为实例1中的VLAN 10-20。 6. 最后,保存并应用配置。 ``` switch# save switch# exit ``` 以上就是在Cumulus交换机上配置V-STP的步骤,希望能对您有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值