Substrate 升級2.0及經(jīng)驗分享--by Skyh(好早之前廢棄)

昨天在升級substrate,問了大牛亮哥(https://mp.weixin.qq.com/s/pp7brVHizDu-a0S-qEe9bA)很多問題,今天來做個總結(jié)如何升級2.0

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

1.0 生成

在產(chǎn)生新substrate模塊中

substrate-node-new substrate-node-template <author-name>

產(chǎn)生的節(jié)點是 1.0的目錄結(jié)構(gòu)是


image.png

1.1 修改

如果升級2.0,現(xiàn)在仍沒有詳細文檔, 最基本的模板在substrate的倉庫node-template里https://github.com/paritytech/substrate/blob/0c08276bdbeac2e0f9bf1a5bc91b04271460e652/node-template/Cargo.toml

image.png

但是直接復(fù)制來出錯,因為cargo都是引用相對路徑的,這時只要改成git就好了。
以下是根目錄cargo.toml的代碼,可以直接復(fù)制以下代碼:

# 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共識和新的功能,很多接口也變了地方了,檢查很久才發(fā)現(xiàn)還在runtime多了一個生產(chǎn)wasm的build.rc文件
還有以下文件需要改

image.png

難道要貼代碼嗎?為了節(jié)省時間我把改好模板放到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這個工具好耗資源,每次都要重新網(wǎng)上下載重新編譯,RLS也是,這也是rust開發(fā)限制,cpu8核都像爆炸一樣,如果有國人做個可以復(fù)用包管理工具類似npm等的更好

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容