Substrate 升级2.0及经验分享--by Skyh(好早之前废弃)

昨天在升级substrate,问了大牛亮哥(https://mp.weixin.qq.com/s/pp7brVHizDu-a0S-qEe9bA)很多问题,今天来做个总结如何升级2.0

不在乎过程,可以直接翻到下面模板的github地址

1.0 生成

在产生新substrate模块中

substrate-node-new substrate-node-template 

产生的节点是 1.0的目录结构是


image.png

1.1 修改

如果升级2.0,现在仍没有详细文档, 最基本的模板在substrate的仓库node-template里https://github.com/paritytech/substrate/blob/0c08276bdbeac2e0f9bf1a5bc91b04271460e652/node-template/Cargo.toml

image.png

但是直接复制来出错,因为cargo都是引用相对路径的,这时只要改成git就好了。
以下是根目录cargo.toml的代码,可以直接复制以下代码:

# Cargo.toml
[package]
name = "skystrate-node"
version = "2.0.0"
authors = ["Skyh"]
build = "build.rs"
edition = "2018"

[profile.release]
panic = "unwind"

[[bin]]
name = "skystrate-node"
path = "src/main.rs"

[dependencies]
derive_more = "0.14.0"
futures = "0.1"
log = "0.4"
tokio = "0.1"
exit-future = "0.1"
parking_lot = "0.9.0"
trie-root = "0.15.2"
codec = { package = "parity-scale-codec", version = "1.0.0" }
ctrlc = { version = "3.0", features = ["termination"] }

sr-io = { git = "https://github.com/paritytech/substrate.git" }
substrate-cli = { git = "https://github.com/paritytech/substrate.git" }
substrate-client = { git = "https://github.com/paritytech/substrate.git" }
substrate-service = { git = "https://github.com/paritytech/substrate.git" }
substrate-executor = { git = "https://github.com/paritytech/substrate.git" }

network = { package = "substrate-network", git = "https://github.com/paritytech/substrate.git" }
inherents = { package = "substrate-inherents", git = "https://github.com/paritytech/substrate.git" }
basic-authorship = { package = "substrate-basic-authorship", git = "https://github.com/paritytech/substrate.git" }
transaction-pool = { package = "substrate-transaction-pool", git = "https://github.com/paritytech/substrate.git" }

primitives = { package = "substrate-primitives", git = "https://github.com/paritytech/substrate.git" }
babe = { package = "substrate-consensus-babe", git = "https://github.com/paritytech/substrate.git" }
grandpa = { package = "substrate-finality-grandpa", git = "https://github.com/paritytech/substrate.git" }
babe-primitives = { package = "substrate-consensus-babe-primitives", git = "https://github.com/paritytech/substrate.git" }
grandpa-primitives = { package = "substrate-finality-grandpa-primitives", git = "https://github.com/paritytech/substrate.git" }

skystrate-node-runtime = { path = "runtime" }

[build-dependencies]
vergen = "3"

基本上就把相对路径化成git地址了,

2.0新增了grandpa共识和新的功能,很多接口也变了地方了,检查很久才发现还在runtime多了一个生产wasm的build.rc文件
还有以下文件需要改

image.png

难道要贴代码吗?为了节省时间我把改好模板放到git上自己下载,是最新版的2.0改过来的,花了一整天

2.0 Git地址

直接clone就可以
https://github.com/skyh24/substrate-node20

另外就是把我的node名字改成自己的就OK

grep -r skystrate *
image.png

于是运行

cargo build

cargo run -- --dev

2.1 问题

改toml也慢慢试出rust排错的方法,可以尝试其中substrate很多模板,自己在toml里面增加就可以


image.png

RLS好像可以自动查找定义模块的定义,必须在根目录有toml,但是运行好慢,运行起来还会卡主其他cargo build进程,有没有更好的工具求推荐


image.png

可以查到定义


image.png

Cargo这个工具好耗资源,每次都要重新网上下载重新编译,RLS也是,这也是rust开发限制,cpu8核都像爆炸一样,如果有国人做个可以复用包管理工具类似npm等的更好

你可能感兴趣的:(Substrate 升级2.0及经验分享--by Skyh(好早之前废弃))