<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by GearFans on Medium]]></title>
        <description><![CDATA[Stories by GearFans on Medium]]></description>
        <link>https://medium.com/@gearfans?source=rss-aec9a73b8ab------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*NcGitiHeKDtDftL8C-Ihgg.png</url>
            <title>Stories by GearFans on Medium</title>
            <link>https://medium.com/@gearfans?source=rss-aec9a73b8ab------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 17:12:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gearfans/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Gear 社区 3 月技术周报｜Week 3]]></title>
            <link>https://medium.com/@gearfans/gear-%E7%A4%BE%E5%8C%BA-3-%E6%9C%88%E6%8A%80%E6%9C%AF%E5%91%A8%E6%8A%A5-week-3-cd3604cd5a1d?source=rss-aec9a73b8ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd3604cd5a1d</guid>
            <category><![CDATA[gear-protocol]]></category>
            <category><![CDATA[polkadot]]></category>
            <category><![CDATA[smart-contract-blockchain]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[GearFans]]></dc:creator>
            <pubDate>Thu, 30 Mar 2023 05:18:21 GMT</pubDate>
            <atom:updated>2023-03-30T05:18:21.549Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pzrBGmMokcHhBSxq.png" /></figure><p>是时候来看看上周 Gear 技术进展啦 👨💻 🛠</p><p>探索 Gear Builders 的开发进程！Dive in 👇</p><h4>1⃣️ 我们正在构建首个用 C++ 编写的 Gear 智能合约库。</h4><p><a href="https://github.com/gear-tech/bindings/pull/1">https://github.com/gear-tech/bindings/pull/1</a></p><h4>2⃣️ 内部任务</h4><p>增加了检查流程。确保 WASM 程序二进制文件的 Gear 栈末端指针不重叠。</p><p><a href="https://github.com/gear-tech/gear/pull/2396">https://github.com/gear-tech/gear/pull/2396</a></p><h4>3⃣️ 在 “wasm-gen” crate 中增加了 “handle_reply” 方法的生成</h4><p><a href="https://github.com/gear-tech/gear/pull/2411">https://github.com/gear-tech/gear/pull/2411</a></p><h4>4⃣️ 正在调研如何为 Gear 实现一个沙盒，而不是修补 Substrate。</h4><h4>5⃣️ Gear 测试网 V7 版本上线</h4><p><a href="https://github.com/gear-tech/gear/pull/2452">https://github.com/gear-tech/gear/pull/2452</a></p><h4>6⃣️ 使用gcli工具为 @VaraNetwork 添加测试</h4><p><a href="https://github.com/gear-tech/gear/pull/2408">https://github.com/gear-tech/gear/pull/2408</a></p><h4>7⃣️ 优化了项目版本依赖</h4><p>使用 cargo 的新功能优化依赖关系的版本（来自工作区的版本管理）。</p><p><a href="https://github.com/gear-tech/gear/pull/2427">https://github.com/gear-tech/gear/pull/2427</a></p><p>本周技术更新如上，下期见！</p><h3>关于 GearFans</h3><p>Gear 是波卡生态的计算组件，GearFans 是 Gear 爱好者社区。</p><ul><li>官网：https://gear-tech.io/</li><li>Twitter：https://twitter.com/gear_techs</li><li>中文 Twitter：https://twitter.com/gear_fans</li><li>Vara Twitter：https://twitter.com/VaraNetwork</li><li>Vara Twitter CN：https://twitter.com/VaraNetwork_CN</li><li>GitHub：https://github.com/gear-tech</li><li>Discord：https://discord.com/invite/7BQznC9uD9</li><li>Medium：https://medium.com/@gear_techs</li><li>Telegram 群：https://t.me/gear_tech</li><li>Telegram 中文群：https://t.me/Gear_CN</li><li>Telegram 中文开发群：https://t.me/gear_dev_cn</li><li>Vara Telegram CN：https://t.me/varanetwork_cn</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd3604cd5a1d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gear 智能合约开发常用技术 1｜Gear Wiki]]></title>
            <link>https://medium.com/@gearfans/gear-%E6%99%BA%E8%83%BD%E5%90%88%E7%BA%A6%E5%BC%80%E5%8F%91%E5%B8%B8%E7%94%A8%E6%8A%80%E6%9C%AF-1-gear-wiki-fb68650a670?source=rss-aec9a73b8ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb68650a670</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[gear-protocol]]></category>
            <category><![CDATA[smart-contract-blockchain]]></category>
            <category><![CDATA[polkadot]]></category>
            <dc:creator><![CDATA[GearFans]]></dc:creator>
            <pubDate>Mon, 27 Mar 2023 09:44:39 GMT</pubDate>
            <atom:updated>2023-03-27T10:14:54.205Z</atom:updated>
            <content:encoded><![CDATA[<h4>提示</h4><blockquote><em>本篇文章介绍与 Gear 智能合约相关技术，帮助你更好的了解 Gear。</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nqA5drOhcsaMDFhRtPByag.png" /></figure><h3>可执行函数</h3><p>程序是 Gear 组件的主要单元。程序代码存储为不可变的 Wasm 二进制文件（blob）。 每个程序都有一个固定的内存，在消息处理之间持续存在（所谓的静态区域）。</p><p><strong><em>基础结构</em></strong></p><p>任何程序最多可以包含 3 个入口点，它们在程序生命周期中执行各种功能：init()、handle()、handle_reply()。 它们都是可选的，但任何程序都需要至少有一个方法：init() 或 handle()。</p><p>Gear 协议引入的另一个特殊系统入口点是 handle_signal()。如果有必要的通知（信号）与程序消息相关的某些事件已经发生，它允许系统与程序通信。</p><p><strong><em>init()</em></strong></p><p>init()方法是可选的，在程序初始化时只被调用一次。并处理传入的 init payload，如果有的话。</p><pre>#[no_mangle]<br>extern &quot;C&quot; fn init() {<br>    // execute this code during contract initialization<br>}</pre><p><strong><em>handle()</em></strong></p><p>handle()方法（同样可选）将在每次程序收到传入的消息时被调用。在这种情况下，payload将被处理。</p><pre>#[no_mangle]<br>extern &quot;C&quot; fn handle() {<br>    // execute this code during explicitly incoming message<br>}</pre><p><strong><em>handle_reply()</em></strong></p><p>在 Gear 程序中对信息的回复，使用handle_reply函数进行处理。</p><pre>#[no_mangle]<br>extern &quot;C&quot; fn handle_reply() {<br>    // execute this code during handling reply on the previously sent message<br>}</pre><h3>Gear 库</h3><p>Gear Protocol 的库 gstd 为开发智能合约提供了所有必要和完善的功能和方法。</p><p><strong><em>通过 prelude 导入相似的类型</em></strong></p><p>gstd的默认 prelude 模块列出了 Rust 自动导入每个程序中的东西。它重新导入了默认的 std 模块和 traits。在 Rust 的 Gear 程序中，std 可以安全地替换为 gstd。</p><p>更多详细内容请看 <a href="https://docs.gear.rs/gstd/prelude/index.html">https://docs.gear.rs/gstd/prelude/index.html</a></p><p><strong><em>消息处理</em></strong></p><p>Gear Protocol 允许用户和程序通过消息与其他用户和程序进行交互。消息可以包含在 payload，它能够在消息执行期间处理。通过模块 msg，我们可以与消息交互：</p><pre>use gstd::msg;</pre><p>消息处理只能在定义的函数 init()、handle() 和 hadle_reply() 内进行。它们还定义了处理此类消息的上下文。</p><ul><li>获取当前正在处理的消息的 payload 并对其进行解码：</li></ul><pre>#![no_std]<br>use gstd::{msg, prelude::*};</pre><pre>#[no_mangle]<br>extern &quot;C&quot; fn handle() {<br>    let payload_string: String = msg::load().expect(&quot;Unable to decode `String`&quot;);<br>}</pre><ul><li>使用payload回复消息：</li></ul><pre>#![no_std]<br>use gstd::msg;</pre><pre>#[no_mangle]<br>extern &quot;C&quot; fn handle() {<br>    msg::reply(&quot;PONG&quot;, 0).expect(&quot;Unable to reply&quot;);<br>}</pre><ul><li>向用户发送消息：</li></ul><pre>#![no_std]<br>use gstd::{msg, prelude::*};</pre><pre>#[no_mangle]<br>extern &quot;C&quot; fn handle() {<br>    // ...<br>    let id = msg::source();<br>    let message_string = &quot;Hello there&quot;.to_string();<br>    msg::send(id, message_string, 0).expect(&quot;Unable to send message&quot;);<br>}</pre><p>关于 msg 的更多用法，请看 <a href="https://docs.gear.rs/gstd/msg/index.html">https://docs.gear.rs/gstd/msg/index.html</a></p><p><strong><em>执行信息</em></strong></p><p>程序可以通过使用 exec 模块获取有关当前执行上下文的一些有用信息：</p><pre>use gstd::exec;</pre><ul><li>在区块时间戳到达指定日期后发送回复消息：</li></ul><pre>#![no_std]<br>use gstd::{exec, msg};</pre><pre>#[no_mangle]<br>extern &quot;C&quot; fn handle() {<br>    // Timestamp is in milliseconds since the Unix epoch<br>    if exec::block_timestamp() &gt;= 1672531200000 {<br>        msg::reply(b&quot;Current block has been generated after January 01, 2023&quot;, 0)<br>            .expect(&quot;Unable to reply&quot;);<br>    }<br>}</pre><ul><li>获得一个程序的余额：</li></ul><pre>#![no_std]<br>use gstd::exec;</pre><pre>#[no_mangle]<br>extern &quot;C&quot; fn handle() {<br>    // Get self value balance in program<br>    let my_balance = exec::value_available();<br>}</pre><p>关于 syscalls 的更多用法，请看 <a href="https://docs.gear.rs/gstd/exec/index.html">https://docs.gear.rs/gstd/exec/index.html</a></p><p><strong><em>在合约内部进行调试</em></strong></p><p>宏 gstd::debug 提供在程序执行期间调试合约的能力：</p><pre>#![no_std]<br>use gstd::{debug, msg, prelude::*};</pre><pre>#[no_mangle]<br>extern &quot;C&quot; fn handle() {<br>    let payload_string: String = msg::load().expect(&quot;Unable to decode `String`&quot;);<br>    debug!(&quot;{:?} received message: &quot;, payload_string);<br>}</pre><h3>Mailbox</h3><p>当程序向用户发送消息时，这条消息会被放在用户的 mailbox 里。实际上，mailbox 是一个专门的存储器，用于保存从程序中收到的信息。</p><p>用户可以通过订阅 UserMessageSent 事件来检测收到的信息</p><p>在使用 IDEA 网站时，应该进入 https://idea.gear-tech.io/mailbox。</p><h4>备注</h4><blockquote><em>一条信息在 mailbox 中是要收费的。因此，信息在 mailbox 中的存在时间是有限的。 我们来探讨一下用户对 mailbox 信息的可能反应。</em></blockquote><p><strong><em>用户对信息进行回复</em></strong></p><p>程序可以向用户发送一条信息，并等待回复。用户可以使用 send_reply extrinsic 来回复。与消息相关的余额被转移到用户的账户，信息被从 mailbox 中删除，而新的回复信息被添加到信息队列中。</p><p><strong><em>用户从 mailbox 的信息中获取余额</em></strong></p><p>如果 mailbox 中的消息具有关联的余额，则用户可以使用 claim_value extrinsic 声明它。余额被转移到用户的帐户，消息从 mailbox 中删除。</p><p><strong><em>用户忽略 mailbox 中的消息</em></strong></p><p>一条消息在其 gas 限制内对 mailbox 中的每一个区块都要收费。如果消息没有明确的 gas 限制，则从源头的限制中借用 gas（例如，启动执行的行为者）。</p><p>当信息的 gas 耗尽时，信息将从 mailbox 中删除，并将相关转账金额转回给信息发送者。</p><h3>State 函数</h3><p><strong><em>存储数据</em></strong></p><p>Gear 智能合约的持久化数据的存储方式与传统程序相同，不需要初始化外部存储。</p><pre>// ...<br>// describe state structure<br>#[derive(TypeInfo, Decode, Encode, Clone)]<br>pub struct Wallet {<br>    pub id: ActorId,<br>    pub person: String,<br>}</pre><pre>// declare and initialize the state<br>static mut WALLETS: Vec&lt;Wallet&gt; = Vec::new();</pre><p>如果用 Rust 或其他面向对象的语言编程，你应该对大多数类型都很熟悉。然而，在 Gear 上开发合约时，ActorId 类型是一个新内容。</p><p>一级引用如下：</p><h4>信息</h4><blockquote><em>ActorId 是一个特殊的类型，代表一个 32 字节的数组，并定义了 Gear Protocol 中所有的 </em><em>ID。</em></blockquote><p><strong><em>State 函数</em></strong></p><p>为了显示合约状态信息（类似于view函数），使用 state() 函数。它可以立即读取合约状态（例如，余额）。读取状态是一个免费函数，不需要消耗任何 gas。</p><p>要返回 State 使用：</p><pre>#[no_mangle]<br>extern &quot;C&quot; fn state() {<br>    msg::reply(unsafe { WALLETS.clone() }, 0).expect(&quot;Failed to share state&quot;);<br>}</pre><p>默认情况下，state() 函数返合约的整体状态。</p><p><strong><em>自定义程序读取状态</em></strong></p><p>此外，你可以创建自己的程序来读取状态。这个包装器将允许你为客户端实现自定义函数，而不依赖于主程序。</p><p>这有很多优点，例如，即使程序改变了，也始终能够读取状态（只要输入或输出的类型没有改变）。或者你正在基于一个已经存在的程序创建服务，你需要一些自己的函数来从状态中获得你自己的数据块。</p><p>为此，我们需要创建一个独立的程序并在 metawasm 特征中描述必要的功能。例如：</p><pre>// ...<br>use gmeta::metawasm;</pre><pre>#[metawasm]<br>pub trait Metawasm {<br>    type State = Vec&lt;Wallet&gt;;</pre><pre>    fn all_wallets(state: Self::State) -&gt; Vec&lt;Wallet&gt; {<br>        state<br>    }</pre><pre>    fn first_wallet(state: Self::State) -&gt; Option&lt;Wallet&gt; {<br>        state.first().cloned()<br>    }</pre><pre>    fn last_wallet(state: Self::State) -&gt; Option&lt;Wallet&gt; {<br>        state.last().cloned()<br>    }<br>}</pre><p>更多复杂的例子：</p><pre>// ...<br>use gmeta::metawasm;</pre><pre>#[metawasm]<br>pub trait Metawasm {<br>    type State = Vec&lt;Wallet&gt;;</pre><pre>    fn wallet_by_id(id: Id, state: Self::State) -&gt; Option&lt;Wallet&gt; {<br>        state.into_iter().find(|w| w.id == id)<br>    }</pre><pre>    fn wallet_by_person(person: String, state: Self::State) -&gt; Option&lt;Wallet&gt; {<br>        state.into_iter().find(|w| w.person == person)<br>    }<br>}</pre><p>要构建 meta.wasm，需要在项目根目录下设置 build.rs 文件：</p><pre>fn main() {<br>    gear_wasm_builder::build_metawasm();<br>}</pre><h3>元数据</h3><p>元数据是一种接口映射，有助于将一组字节转换为可理解的结构，并展示出该结构的用途。元数据决定了所有传入和传出数据的编码/解码方式。</p><p>元数据允许 dApp 的各个部分 — 智能合约和客户端（JavaScript）相互理解并交互数据。</p><p>要描述元数据接口，请使用 gmeta：</p><pre>use gmeta::{InOut, Metadata};</pre><pre>pub struct ProgramMetadata;</pre><pre>// 一定要描述所有的类型。<br>// 但如果程序中缺少任一入口，请使用 () 代替；<br>// 如 `type Signal` 所示</pre><pre>impl Metadata for ProgramMetadata {<br>    type Init = InOut&lt;MessageInitIn, MessageInitOut&gt;;<br>    type Handle = InOut&lt;MessageIn, MessageOut&gt;;<br>    type Others = InOut&lt;MessageAsyncIn, Option&lt;u8&gt;&gt;;<br>    type Reply = InOut&lt;String, Vec&lt;u16&gt;&gt;;<br>    type Signal = ();<br>    type State = Vec&lt;Wallet&gt;;<br>}</pre><p>正如我们所看到的，元数据使你能够确定合约在每个端点的输入/输出的预期数据格式：</p><ul><li>Init — init() 函数的输入/输出类型。</li><li>Handle -handle()函数的输入/输出类型。</li><li>Others- 在异步交互的情况下，main()函数的输入/输出类型。</li><li>Reply — 使用 handle_reply 函数执行的消息的输入/输出类型。</li><li>Signal — 只描述在处理系统信号时从程序中输出的类型。</li><li>State — 查询的状态的类型</li></ul><p><strong><em>生成元数据</em></strong></p><p>要生成元数据，需要在项目文件夹的根目录下添加 build.rs 文件：</p><pre>// build.rs<br>// Where ProgramMetadata is your metadata structure</pre><pre>use meta_io::ProgramMetadata;</pre><pre>fn main() {<br>    gear_wasm_builder::build_with_metadata::&lt;ProgramMetadata&gt;();<br>}</pre><p>作为智能合约编译的结果，将生成一个 meta.txt 文件。这个元数据文件可用于与该智能合约互动的用户界面应用程序。文件的内容看起来像一个十六进制字符串：</p><pre>01000000000103000000010500000001090000000102000000010d000000010f0000000111000000000112000000a9094c00083064656d6f5f6d6574615f696f344d657373616765496e6974496e0000080118616d6f756e74040108753800012063757272656e6379080118537472696e6700000400000503000800000502000c083064656d6f5f6d6574615f696f384d657373616765496e69744f7574000008013465786368616e67655f72617465100138526573756c743c75382c2075383e00010c73756d04010875380000100418526573756c740804540104044501040108084f6b040004000000000c457272040004000001000014083064656d6f5f6d6574615f696f244d657373616765496e000004010869641801084964000018083064656d6f5f6d6574615f696f084964000008011c646563696d616c1c010c75363400010c68657820011c5665633c75383e00001c000005060020000002040024083064656d6f5f6d6574615f696f284d6573736167654f7574000004010c7265732801384f7074696f6e3c57616c6c65743e00002804184f7074696f6e040454012c0108104e6f6e6500000010536f6d6504002c00000100002c083064656d6f5f6d6574615f696f1857616c6c6574000008010869641801084964000118706572736f6e300118506572736f6e000030083064656d6f5f6d6574615f696f18506572736f6e000008011c7375726e616d65080118537472696e670001106e616d65080118537472696e6700003400000238003800000504003c083064656d6f5f6d6574615f696f384d6573736167654173796e63496e0000040114656d707479400108282900004000000400004404184f7074696f6e04045401040108104e6f6e6500000010536f6d650400040000010000480000022c00</pre><p><strong><em>验证元数据</em></strong></p><p>为了验证程序的元数据，可以使用metahash()函数。它允许在链上验证元数据。</p><pre>#[no_mangle]<br>// It returns the Hash of metadata.<br>// .metahash is generating automatically while you are using build.rs<br>extern &quot;C&quot; fn metahash() {<br>    let metahash: [u8; 32] = include!(&quot;../.metahash&quot;);<br>    msg::reply(metahash, 0).expect(&quot;Failed to share metahash&quot;);<br>}</pre><h3>数据序列化/反序列化</h3><p>为了优化数据在网络上的发送和接收方式，Gear 使用 parity-scale-codec，这是 SCALE 编解码器的 Rust 实现。这个编解码器被 Substrate 节点的内部 runtime 所使用。SCALE 是一种轻量级的编码格式，能够实现数据的序列化和反序列化。使用 SCALE 对数据进行编码（和解码），它非常适用于资源受限的执行环境，如区块链运行时间和低功耗、低内存设备。</p><p>在程序中使用 SCALE codec，Cargo.toml 需要添加以下内容：</p><pre>[dependencies]</pre><pre>// ...<br>codec = { package = &quot;parity-scale-codec&quot;, version = &quot;3.1.2&quot;, default-features = false }</pre><pre>use codec::{Decode, Encode};</pre><pre>#[derive(Encode, Decode)]<br>enum MyType {<br>    MyStruct { field: ... },<br>    ...<br>}</pre><h4>信息</h4><blockquote><em>我们只需要在使用 </em><em>gstd 的包装方法时使用 Encode 和 Decode 特性，例如 </em><em>msg::send，</em><em>msg::reply，</em><em>send_for_reply 等。像 </em><em>send_byte 或 </em><em>reply_bytes 这样的方法，我们操作的是字节数组，所以不需要进行解码/编码。</em></blockquote><p>更多的内容请看 SCALE Codec。</p><p><a href="https://github.com/paritytech/parity-scale-codec">https://github.com/paritytech/parity-scale-codec</a></p><h4>scale-info</h4><p>scale-info 是一个描述 Rust 类型的库，提供有关可编码 SCALE 类型结构的信息。</p><p>这些第三方工具 (例如 UI 客户端) 提供了关于它们如何能够解码不受语言影响的类型的信息。Gear 程序使用 scale-info 的接口称为 metadata。它为所有必要的入口点定义了输入和输出类型，并允许合约和客户端相互理解。</p><h4>信息</h4><blockquote><em>如何在合约中使用 </em><em>metadata，请看链接</em></blockquote><p>在项目中使用 scale-info：</p><pre>[dependencies]</pre><pre>// ...<br>scale-info = { version = &quot;2.1.1&quot;, default-features = false, features = [&quot;derive&quot;] }</pre><p>更多的内容请看 scale-info。 <a href="https://github.com/paritytech/scale-info">https://github.com/paritytech/scale-info</a></p><h3>关于 GearFans</h3><p>Gear 是波卡生态的计算组件，GearFans 是 Gear 爱好者社区。</p><ul><li>官网：https://gear-tech.io/</li><li>Twitter：https://twitter.com/gear_techs</li><li>中文 Twitter：https://twitter.com/gear_fans</li><li>Vara Twitter：https://twitter.com/VaraNetwork</li><li>Vara Twitter CN：https://twitter.com/VaraNetwork_CN</li><li>GitHub：https://github.com/gear-tech</li><li>Discord：https://discord.com/invite/7BQznC9uD9</li><li>Medium：https://medium.com/@gear_techs</li><li>Telegram 群：https://t.me/gear_tech</li><li>Telegram 中文群：https://t.me/Gear_CN</li><li>Telegram 中文开发群：https://t.me/gear_dev_cn</li><li>Vara Telegram CN：https://t.me/varanetwork_cn</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb68650a670" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[公告｜Gear 测试网 V7 版本上线]]></title>
            <link>https://medium.com/@gearfans/%E5%85%AC%E5%91%8A-gear-%E6%B5%8B%E8%AF%95%E7%BD%91-v7-%E7%89%88%E6%9C%AC%E4%B8%8A%E7%BA%BF-a2eb33434864?source=rss-aec9a73b8ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2eb33434864</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[polkadot]]></category>
            <category><![CDATA[gear-protocol]]></category>
            <category><![CDATA[smart-contract-blockchain]]></category>
            <dc:creator><![CDATA[GearFans]]></dc:creator>
            <pubDate>Mon, 27 Mar 2023 09:18:56 GMT</pubDate>
            <atom:updated>2023-03-27T09:18:56.515Z</atom:updated>
            <content:encoded><![CDATA[<p>Gear 已经重置了测试网络，正式进入测试网下一阶段。</p><p>请及时更新节点执行文件，加入 Gear Staging Testnet V7！</p><p>0.请根据官方文档配置节点 <a href="https://wiki.gear-tech.io/docs/node/node-as-service">https://wiki.gear-tech.io/docs/node/node-as-service</a></p><p>1.在更新前，我们建议你清除之前的网络</p><pre>sudo systemctl stop gear-node<br>gear purge-chain -y</pre><p>2.更新节点执行文件至最新版本，该文件包含连接到Gear网络的所有内容。</p><pre>wget https://get.gear.rs/gear-nightly-linux-x86_64.tar.xz<br>sudo tar -xvf gear-nightly-linux-x86_64.tar.xz -C /usr/bin<br>rm gear-nightly-linux-x86_64.tar.xz</pre><p>3.启动新版本（Gear Staging Testnet V7):</p><pre>sudo systemctl start gear-node</pre><p>4.(可选) 如果你想使用与之前相同的个人 ID，可以从之前的链上复制网络密钥文件。</p><pre>sudo systemctl stop gear-node<br>cd /root/.local/share/gear/chains<br>sudo cp gear_staging_testnet_v6/network/secret_ed25519 gear_staging_testnet_v7/network/secret_ed25519<br>sudo systemctl start gear-node</pre><p><strong>关于网络密钥文件：</strong></p><p><a href="https://wiki.gear-tech.io/docs/node/backup-restore#network-key">https://wiki.gear-tech.io/docs/node/backup-restore#network-key</a></p><p>5.前往 https://telemetry.gear-tech.io/，你可以在 Gear Staging Testnet V7 下找到你的节点。</p><p>Gear Staging Testnet V7 下找到你的节点。</p><p><a href="https://wiki.gear-tech.io/docs/node/node-as-service/">https://wiki.gear-tech.io/docs/node/node-as-service/</a></p><p><a href="https://wiki.gear-tech.io/docs/node/backup-restore/">https://wiki.gear-tech.io/docs/node/backup-restore/</a></p><h3>关于 GearFans</h3><p>Gear 是波卡生态的计算组件，GearFans 是 Gear 爱好者社区。</p><ul><li>官网：https://gear-tech.io/</li><li>Twitter：https://twitter.com/gear_techs</li><li>中文 Twitter：https://twitter.com/gear_fans</li><li>Vara Twitter：https://twitter.com/VaraNetwork</li><li>Vara Twitter CN：https://twitter.com/VaraNetwork_CN</li><li>GitHub：https://github.com/gear-tech</li><li>Discord：https://discord.com/invite/7BQznC9uD9</li><li>Medium：https://medium.com/@gear_techs</li><li>Telegram 群：https://t.me/gear_tech</li><li>Telegram 中文群：https://t.me/Gear_CN</li><li>Telegram 中文开发群：https://t.me/gear_dev_cn</li><li>Vara Telegram CN：https://t.me/varanetwork_cn</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2eb33434864" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gear 社区 3 月技术周报｜Week 2]]></title>
            <link>https://medium.com/@gearfans/gear-%E7%A4%BE%E5%8C%BA-3-%E6%9C%88%E6%8A%80%E6%9C%AF%E5%91%A8%E6%8A%A5-week-2-f5a73ec65e91?source=rss-aec9a73b8ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/f5a73ec65e91</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[gear-protocol]]></category>
            <category><![CDATA[polkadot]]></category>
            <category><![CDATA[crypto]]></category>
            <dc:creator><![CDATA[GearFans]]></dc:creator>
            <pubDate>Thu, 23 Mar 2023 11:37:54 GMT</pubDate>
            <atom:updated>2023-03-23T11:37:54.601Z</atom:updated>
            <content:encoded><![CDATA[<p>#GearProtocol 社区持续专注于技术构建，一起来看看本月 Week 2 的技术更新！</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/612/0*mkOU7JWftO5JCDiw.png" /></figure><h4>1. 批量消息 🍺</h4><p>实现了一个负载测试，用于检查节点是否能够处理区块内的一批消息（每条消息都发送给专用程序）。</p><p><a href="https://github.com/gear-tech/gear/pull/2346"><strong>https://github.com/gear-tech/gear/pull/2346</strong></a></p><h4>2. 实现了一个实用功能，并将其添加至 gclient 库。✔️</h4><p>该功能允许开发者在测试内部启动一个 Vara 开发节点（除了之前实现的 Gear 开发节点）。</p><p><a href="https://github.com/gear-tech/gear/pull/2364"><strong>https://github.com/gear-tech/gear/pull/2364</strong></a></p><h4>3. 移除了旧的内存页计费方式。😎</h4><p>send(reply)_input 中 gas 消耗过大问题也得到了修复。</p><p><a href="https://github.com/gear-tech/gear/pull/2266"><strong>https://github.com/gear-tech/gear/pull/2266</strong></a></p><h4>4. 修复了当智能合约使用 async 时，gstd 中 locks map 不断增长的问题。🍻</h4><p><a href="https://github.com/gear-tech/gear/pull/2363"><strong>https://github.com/gear-tech/gear/pull/2363</strong></a></p><h4>5. 在 CI 上进行交叉编译 🦄</h4><p>在 CI 上开发交叉编译至 Windows，以减少在 Windows 上构建的错误。 🔗最终合并</p><p><a href="https://github.com/gear-tech/gear/pull/2305"><strong>https://github.com/gear-tech/gear/pull/2305</strong></a></p><h4>6. 优化调度器中缺失区块的存储问题 🤓</h4><p><a href="https://github.com/gear-tech/gear/pull/2404"><strong>https://github.com/gear-tech/gear/pull/2404</strong></a></p><h4>7. 完成 Gear 节点加载器 🤩</h4><p>使用 gear-node-loader 测试所有的外部函数。目前，加载器的主要功能已经完成。</p><p><a href="https://github.com/gear-tech/gear/pull/2290"><strong>https://github.com/gear-tech/gear/pull/2290</strong></a></p><h4>8. 修复严重错误 👍</h4><p>为 “reservation_reply” 和 “reply” 系统调用的有效负载大小添加了 gas 费，修复了节点停止生成区块的严重错误。</p><p><a href="https://github.com/gear-tech/gear/pull/2354"><strong>https://github.com/gear-tech/gear/pull/2354</strong></a></p><p>请享用近期的技术周报，新一期技术更新即将到来，食用愉快！😋</p><p>在 Gear 上构建你的应用吧！ <a href="https://gear-tech.io/contacts"><strong>https://gear-tech.io/contacts</strong></a></p><h3>关于 GearFans</h3><p>Gear 是波卡生态的计算组件，GearFans 是 Gear 爱好者社区。</p><ul><li>官网：https://gear-tech.io/</li><li>Twitter：https://twitter.com/gear_techs</li><li>中文 Twitter：https://twitter.com/gear_fans</li><li>Vara Twitter：https://twitter.com/VaraNetwork</li><li>Vara Twitter CN：https://twitter.com/VaraNetwork_CN</li><li>GitHub：https://github.com/gear-tech</li><li>Discord：https://discord.com/invite/7BQznC9uD9</li><li>Medium：https://medium.com/@gear_techs</li><li>Telegram 群：https://t.me/gear_tech</li><li>Telegram 中文群：https://t.me/Gear_CN</li><li>Telegram 中文开发群：https://t.me/gear_dev_cn</li><li>Vara Telegram CN：https://t.me/varanetwork_cn</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f5a73ec65e91" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[使用 Gear IDEA 快速上传智能合约｜Gear Wiki]]></title>
            <link>https://medium.com/@gearfans/%E4%BD%BF%E7%94%A8-gear-idea-%E5%BF%AB%E9%80%9F%E4%B8%8A%E4%BC%A0%E6%99%BA%E8%83%BD%E5%90%88%E7%BA%A6-gear-wiki-82961778efcb?source=rss-aec9a73b8ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/82961778efcb</guid>
            <category><![CDATA[wiki]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[gear-protocol]]></category>
            <dc:creator><![CDATA[GearFans]]></dc:creator>
            <pubDate>Sun, 19 Mar 2023 15:53:09 GMT</pubDate>
            <atom:updated>2023-03-19T15:53:09.666Z</atom:updated>
            <content:encoded><![CDATA[<h3><em>导语</em></h3><blockquote><em>本篇文章中，我们将详细介绍 Gear IDEA，使大家熟悉 Gear 平台，用最简单快速的方式上传智能合约！</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PiL-dqUDhsXTnmqP.png" /></figure><h4><strong>Gear IDEA online</strong></h4><p>Gear IDEA 是一个方便的工具，其目的是让用户熟悉 Gear 平台。它为智能合约开发者提供了最简单、最快捷的方式来编写、编译、测试并直接通过浏览器将智能合约上传到测试网络，而无需额外的配置。</p><p>这是一个演示应用程序，实现了在 Gear 中与智能合约互动的所有可能性，同时管理账户、账户余额、事件和其他信息。</p><p>你现在就可以在 <a href="https://idea.gear-tech.io/">https://idea.gear-tech.io/</a> ，开始进行实验。</p><h4><strong>IDEA 组件和微服务</strong></h4><p><strong><em>frontend</em></strong></p><p>基于 React 的前端应用，用来为 Gear IDEA 提供合约交互能力。</p><p><strong><em>events-listener</em></strong></p><p>监听 Gear 节点上的所有事件的微服务，将事件发送到存储服务 (data-storage)。</p><p><strong><em>data-storage</em></strong></p><p>存储上传的程序元数据和相关事件的微服务。</p><p><strong><em>api-gateway</em></strong></p><p>为外部用户提供同事件、元数据进行交互的微服务。</p><p><strong><em>test-balance</em></strong></p><p>用来获取测试代币的微服务</p><p><strong><em>wasm-compiler</em></strong></p><p>用来将 Rust 项目编译成 Wasm 的微服务。</p><h4><strong>如何创建账户</strong></h4><p><strong><em>关键信息和安全提示</em></strong></p><p>帐户代表一种身份 — — 通常是一个人或一个组织，能够进行交易或持有资金。用户可以上传智能合约，并通过建立在 Gear Protocol 之上的区块链网络进行交易。为了实现这一点，用户需要连接一个 Substrate 账户。Gear Idea 网站可以与任何连接的 Gear-powered 网络中的 Substrate 账户一起工作。此外，该账户可用于在 Dotsama 生态系统的任何网络中持有资金和进行交易，想了解更多，请点击此<strong>链接</strong>[1]。</p><p>有几种方法来创建一个 Substrate 账户，这取决于你是使用台式机还是移动设备。</p><p>一个账户主要有 2 个关键部分 — 地址和私钥：</p><ul><li>地址是账户的公开部分。可以将它分享给他人，以便发送交易。</li><li>私钥是账户的私有部分。这是使你作为一个账户所有者能够访问地址的原因。访问你的账户的唯一方法是通过你的私钥（使用助记词，种子密码，或你的账户的 JSON 文件和一个密码）。</li></ul><h4><strong><em>保存你的帐户</em></strong></h4><blockquote><strong><em>提示</em></strong></blockquote><blockquote><em>种子密码 你的种子密码或助记词是你账户的钥匙。如果你丢失了种子密码，你将失去对你账户的访问。我们建议你将你的种子储存在安全的地方，如加密的硬盘、非数字设备，最好是纸张。永远不要与任何人分享你的私钥。</em></blockquote><blockquote><strong><em>提示</em></strong></blockquote><blockquote><em>JSON 文件 JSON 文件是一个用密码加密的账户的备份。通过使用 JSON，你可以在任何钱包中 导入/恢复 你的账户。没有密码，你将无法恢复对你的账户的访问。如果你使用 JSON，请将文件和密码保存在一个安全的地方。</em></blockquote><h4><strong>如何创建账号</strong></h4><blockquote><strong>通过 Talisman 钱包</strong></blockquote><p>Talisman 是一个流行的和用户友好的钱包，用于创建和管理 Substrate 账户。Talisman 浏览器插件与各种网络中的 web3 应用程序相连，允许存储、发送和接收资产。</p><ol><li>通过 <a href="https://talisman.xyz/">https://talisman.xyz/</a> 安装 tailsmain 插件</li><li>通过点击菜单栏中的 logo，打开扩展程序。</li><li>打开应用，点击 “New wallet”</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fiXWq6vtH7xnkGQ-.png" /></figure><p>4. 输入一个强密码</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-xtsEpH1Sp3EkTkk.png" /></figure><p>然后，你的地址已经创建好了：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BzRgSsEbzW92JGvT.png" /></figure><blockquote><strong>通过 Subwallet</strong></blockquote><p>Subwallet 是另一个高级钱包，用于管理 Substrate 以及 EVM 账户。</p><ol><li>通过 <a href="https://subwallet.app/download.html">https://subwallet.app/download.html</a> 安装 Subwallet</li><li>通过点击菜单栏中的 logo，打开 Subwallet</li><li>点击 “Create new account”:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cwJVY3aCdwwDpW0g.png" /></figure><p>4. 选择你想要创建的账户类型 (Subwallet 允许你同时创建 substrate 和以太坊的账户)。复制你的种子密码，并保持在相同的地方：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xMbDomB_gRYuNggE.png" /></figure><p>5. 在下一步中提供密码。点击 “Add the account with the generated seed”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*S6HEg-xyLdj14Oq_.png" /></figure><p>恭喜，你的地址已经创建成功！</p><blockquote><strong>通过 Polkadot.js 插件</strong></blockquote><p>polkadot.js 浏览器扩展是 Parity Technologies 创建的用于管理 Substate 账户的原声应用。通过安装 polkadot.js 插件，并将其作为一个独立于浏览器的 “虚拟保险库”，用来以存储私钥和签署交易。</p><ol><li>你可以通过以下链接安装扩展。</li></ol><ul><li>Chromium</li><li>FireFox</li></ul><p>2. 通过单击菜单栏中的 logo 打开程序</p><p>3. 单击大加号按钮来创建一个新帐户。或者，你可以导航到右上角较小的加号图标，并选择“Create New Account”。</p><p>4. 使用本文开头的安全建议将“种子密码”保存在安全的地方。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SPOWQvBIqV30ChvU.png" /></figure><p>5. 设定帐户名称和用于进行交易的强密码。点击“Add the account with the generated seed”。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*E2qSG2vIGwxYBcQa.png" /></figure><blockquote><strong><em>备注</em></strong></blockquote><blockquote><em>你在此选择的密码将用于加密此帐户的信息。尝试处理任何类型的转出交易或使用它对消息进行加密签名时，都需要重新输入它。此密码存储在本地浏览器扩展中。</em></blockquote><p>你现在已经使用 polkadot.js 浏览器扩展成功创建了一个新帐户。</p><blockquote><strong>通过手机应用</strong></blockquote><p>如果你需要在移动设备上访问帐户，那么你可以将以下移动钱包用于 Polkadot/Kusama 生态系统：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/356/0*kL8Ued4vDWfIJ1uD.png" /></figure><p>你可以在<strong>此处</strong>[2] 查看所有受支持的钱包。</p><blockquote><strong>通过控制台</strong></blockquote><p>如果你安装了 Gear node，可以使用以下命令生成新的“种子密码”：</p><pre>./gear key generate | grep phrase</pre><p>然后将生成的助记词 import 到钱包中。</p><blockquote><strong>常见问题</strong></blockquote><ol><li>账户是便携式的吗？</li></ol><ul><li>是的，只要你拥有种子短语或者账户的 JSON 文件，你就能在任何不同设备和钱包上访问你的账户，与帐户关联的短语或 JSON 文件。</li></ul><p>2. 能在 polkadot.js 浏览器插件中进行交易吗？</p><ul><li>没有直接在 polkadot.js 浏览器扩展中进行交易的功能。要进行交易，需要在浏览器上访问 Gear Idea。在进行任何交易之前，必须允许 Gear Idea 访问你的帐户。浏览器扩展程序会保存你的帐户信息。您可以选择哪些网站可以访问此信息。</li></ul><h4>SS58 地址格式</h4><p>SS58 是一种简单的地址格式，是为基于 Substrate 框架的区块链所设计。其基本思想是使用 base-58 编码的值来区分不同的链上的不同账户。</p><p>关于格式的更多信息可以参考：https://docs.substrate.io/v3/advanced/ss58/</p><p>选择对应的地址格式来使用 Gear 测试网</p><p>Gear Idea 后端使用 Substrate 地址格式。当你参与一些 Gear 的活动或相关事件时，例如 workshop、在线 AMA 等，会收到一些奖励的代币，此时你需要提供你的 Substrate 格式的账户地址。</p><p>如果你已经有一个 Polkadot 账户、Kusama 账户或者任何其他基于 Substrate 的区块链网络的账户，你可以在 polkadot.js 插件中为你的钱包设置地址格式。</p><ol><li>在浏览器中打开 polkadot.js插件，点击右上角的 设置 图标。</li><li>在打开的窗口中点击下拉菜单显示地址格式，选择 Substrate：</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/0*sl9xtWcemS7sROns.png" /></figure><blockquote><strong>SS58 地址转换</strong></blockquote><p>不幸的是，SS58 格式的地址对于使用 Gear IDEA 中的智能合约很不方便，因为它们接受的地址是 256 位公钥 (也称为 actor ID)。 你可以自己把地址转换成公钥，或者使用这个简单的在线转换器：https://ss58.org（别忘了选择 <strong>地址</strong> → <strong>钥匙</strong> 标签）。</p><h4>参考资料</h4><p>[1]链接: <a href="https://docs.substrate.io/fundamentals/accounts-addresses-keys/"><em>https://docs.substrate.io/fundamentals/accounts-addresses-keys/</em></a></p><p>[2]此处: <a href="https://wiki.polkadot.network/docs/wallets"><em>https://wiki.polkadot.network/docs/wallets</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82961778efcb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Gear 技术周报｜第一期]]></title>
            <link>https://medium.com/@gearfans/gear-%E6%8A%80%E6%9C%AF%E5%91%A8%E6%8A%A5-%E7%AC%AC%E4%B8%80%E6%9C%9F-7e886590bd4e?source=rss-aec9a73b8ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e886590bd4e</guid>
            <category><![CDATA[polkadot]]></category>
            <category><![CDATA[gear-protocol]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[GearFans]]></dc:creator>
            <pubDate>Thu, 16 Mar 2023 10:27:53 GMT</pubDate>
            <atom:updated>2023-03-16T10:27:53.965Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mZqz6juYmVBu5q9b" /></figure><p><strong>Gear 社区一直在全力以赴地修补 bug、持续改进 GearProtocol。一起看看最新的技术更新！</strong></p><blockquote><strong>1. 能够从基于 gclient 的测试中直接生成开发节点</strong></blockquote><p>在运行基于 gclient 的测试之前，在 dev-mode 中运行 Gear 节点是一个手动过程。现在 Gear 添加了一个新的结构，允许开发者从测试中启动节点并在其完成后关闭。</p><p><em>PR：https://github.com/gear-tech/gear/pull/2214</em></p><blockquote><strong>2.在验证者不足时，提高网络的稳健性</strong></blockquote><p>现在，Gear 网络可以实现：</p><ul><li>如果网络上验证者不足，网络会切换模式，产生最小的区块。</li><li>保持上述模式，直到恢复产生完整区块。</li></ul><p><em>PR: </em><a href="https://github.com/gear-tech/gear/pull/2286"><em>https://github.com/gear-tech/gear/pull/2286</em></a></p><blockquote><strong>3. 对从 Wasm 中调用导入函数的权重做了微调，可以直接精确的反映 gas 变化。</strong></blockquote><p><em>PR: </em><a href="https://github.com/gear-tech/gear/pull/2266"><em>https://github.com/gear-tech/gear/pull/2266</em></a></p><blockquote><strong>4. 修复了在 sys-calls 逻辑中 log::debug 的调用问题，原来的问题导致 sys-calls 的执行时间更长。</strong></blockquote><p><em>PR: </em><a href="https://github.com/gear-tech/gear/pull/2285"><em>https://github.com/gear-tech/gear/pull/2285</em></a></p><blockquote><strong>5. 通过增加运行时堆内存大小，Gear 社区解决了#Substrate 分配器 “内存不足的问题”。</strong></blockquote><p><em>PR: </em><a href="https://github.com/gear-tech/gear/pull/2299"><em>https://github.com/gear-tech/gear/pull/2299</em></a></p><blockquote><strong>6. 修复了在 Windows 上构建二进制的回归错误。</strong></blockquote><p><em>PR: </em><a href="https://github.com/gear-tech/gear/pull/2288"><em>https://github.com/gear-tech/gear/pull/2288</em></a></p><blockquote><strong>7. Gear 社区为 Gear 引入了 rust sdk：(gsdk)</strong></blockquote><p><a href="https://docs.gear.rs/gsdk/index.html"><em>https://docs.gear.rs/gsdk/index.html</em></a><em> </em>开发者可以直接使用 rust 代码调用 Gear API!</p><blockquote><strong>8. 在 CI 上进行交叉编译</strong></blockquote><p>在 CI 上开发一个交叉编译到 Windows 的功能，以减少在 Windows 上构建的错误。</p><p><em>PR: </em><a href="https://github.com/gear-tech/gear/pull/2305"><em>https://github.com/gear-tech/gear/pull/2305</em></a></p><blockquote><strong>9. 增加了一个全新的 fuzz-testing 工具</strong></blockquote><p>我们在内部工具库里添加了一个运行时 fuzzer 测试工具。该工具用于确保在 Gear 运行时不会发生错误。</p><p><em>PR: </em><a href="https://github.com/gear-tech/gear/pull/2183"><em>https://github.com/gear-tech/gear/pull/2183</em></a></p><p>开发人员还准备了一个 dockerfile，不仅便于引擎运行，还将不断测试其他运行时。</p><p><a href="https://github.com/gear-tech/gear/pull/2340"><em>https://github.com/gear-tech/gear/pull/2340</em></a></p><p>在 “gear-node-loader “和 “runtime-fuzzer “中引入程序间通信，可以显著提高 fuzz-test 的质量。通过所提供的修改，开发人员可以在 fuzz-test 中模拟合约调用的几种情况。</p><p><a href="https://github.com/gear-tech/gear/issues/2184"><em>https://github.com/gear-tech/gear/issues/2184</em></a></p><blockquote><strong>10. DApp 迁移</strong></blockquote><p>开发了一个 gclient 代码，允许 #dApp 开发者将程序从一个节点迁移到另一个节点。例如，从测试网迁移到他们的本地开发网。</p><p><em>PR: </em><a href="https://github.com/gear-tech/gear/pull/2331"><em>https://github.com/gear-tech/gear/pull/2331</em></a></p><blockquote><strong>11. 开发人员显著改进了用于编写智能合约的标准库文档。</strong></blockquote><p>Gear Protocol 有一个gstd库，在使用 Rust 编写智能合约时，该 gstd库作为标准库使用。</p><p>我们重新编写了 gstd 文档，文档内容得到了显著改善，开发人员能够顺利地编写智能合约。</p><p><em>查看gstd库的文档 👉：https://docs.gear.rs/gstd/</em></p><p><a href="https://github.com/gear-tech/gear/pull/1982"><em>https://github.com/gear-tech/gear/pull/1982</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e886590bd4e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[关于节点的常见问题及错误 | Gear Wiki]]></title>
            <link>https://medium.com/@gearfans/%E5%85%B3%E4%BA%8E%E8%8A%82%E7%82%B9%E7%9A%84%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98%E5%8F%8A%E9%94%99%E8%AF%AF-gear-wiki-1e90c7720fa3?source=rss-aec9a73b8ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e90c7720fa3</guid>
            <category><![CDATA[node]]></category>
            <category><![CDATA[gear-protocol]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <dc:creator><![CDATA[GearFans]]></dc:creator>
            <pubDate>Sun, 12 Mar 2023 04:47:43 GMT</pubDate>
            <atom:updated>2023-03-12T04:48:03.146Z</atom:updated>
            <content:encoded><![CDATA[<h3>导语</h3><blockquote><em>我们在本篇文章中介绍了 21 种节点常见的问题及 5 种运行节点过程中常见的错误，希望能帮助你更好的运行 Gear 节点。</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nMeC_wz-TYqwr9zp.png" /></figure><blockquote>节点常见问题</blockquote><h4>1. 现在可以运行节点吗？</h4><p>当然可以，这篇文章中就如何在 MacOS、Linux 和 Windows 系统中设置和运行 Gear 节点进行了说明，你可以根据指示操作。https://wiki.gear-tech.io/zh-cn/node/setting-up</p><h4>2. Gear 节点对硬件有什么要求？</h4><p>除了连接到测试网或在开发网模式下运行 Gear 节点的 SSD，没有特殊的硬件要求。对于生产网络中的节点，将会有额外的硬件要求。</p><h4>3. 运行节点有奖励吗？</h4><p>在生产网络中运行一个节点将得到相应奖励。在测试网中运行节点没有常规奖励，但参与社区活动会得到部分奖励。请继续关注最新资讯。</p><h4>4. 现在可以运行 collator/validator 吗？</h4><p>目前不能。请继续关注最新资讯。</p><h4>5. 如果节点在节点监控器中显示并同步区块，一切运行正常吗？</h4><p>是的，节点运行正常。</p><h4>6. 运行节点后需要做什么？</h4><p>目前只需运行节点，请关注后续更新。</p><h4>7. 如何使节点在后台工作？</h4><p>解决方案是将 Gear 节点配置为一个服务：https://wiki.gear-tech.io/zh-cn/node/node-as-service/</p><h4>8. 遇到以下问题该如何解决？</h4><p>IO error: While lock file &lt;path&gt;: Resource temporarily unavailable</p><p>你似乎正在运行几个 Gear 节点实例。你很可能把节点配置为一个服务，然后从命令行运行了第二个实例。你应该停止配置服务或者停止从命令行运行 Gear 节点。</p><h4>9. 所使用的云主机供应商称该节点滥用他们的网络。</h4><p>你可以在运行节点时添加--no-private-ipv4参数来解决这一问题。 如果由于某些原因，该参数不能解决你的问题，那么你可以禁止出站流量：</p><pre>10.0.0.0/8<br>172.16.0.0/12<br>192.168.0.0/16<br>100.64.0.0/10<br>169.254.0.0/16</pre><p>例如，你可以使用这个手册进行操作：https://community.hetzner.com/tutorials/block-outgoing-traffic-to-private-networks</p><h4>10. 将节点配置为服务后应该怎样更新节点？</h4><p>你只需要把节点的可执行文件（gear）替换成最新版本，然后重新执行。例如，如果你的 Linux 可执行文件位于/usr/bin，你将运行：</p><pre>wget https://get.gear.rs/gear-nightly-linux-x86_64.tar.xz<br>sudo tar -xvf gear-nightly-linux-x86_64.tar.xz -C /usr/bin<br>rm gear-nightly-linux-x86_64.tar.xz<br>sudo systemctl restart gear-node</pre><h4>11. 节点在某个区块编号后停止增加区块高度。</h4><p>你需要将节点的二进制文件更新到最新版本。</p><h4>12. 如果默认的端口号已经被其他软件使用，如何改变端口号？</h4><p>请在运行节点时使用其支持的 flag。</p><pre>--port &lt;PORT&gt;<br>    Specify p2p protocol TCP port</pre><pre>--prometheus-port &lt;PORT&gt;<br>    Specify Prometheus exporter TCP Port</pre><pre>--rpc-port &lt;PORT&gt;<br>    Specify HTTP RPC server TCP port</pre><pre>--ws-port &lt;PORT&gt;<br>    Specify WebSockets RPC server TCP port</pre><h4>13. 遇到以下问题该如何解决？</h4><p>Verification failed for block &lt;block-id&gt; received from peer &lt;peer-id&gt;</p><p>请将节点二进制文件更新到最新版本。</p><h4>14. 如何查看 Gear 节点服务日志？</h4><pre>sudo journalctl -n 100 -f -u gear-node</pre><h4>15. “runtime requires function imports which are not present on the host”遇到以上问题该如何解决？</h4><p>请将节点二进制文件更新到最新版本。</p><h4>16. 节点的同步时间是多少？</h4><p>完整的节点同步时间可以用日志中的信息来计算： syncing_time (secs) = (target_block - finalized_block) / bps 例如：</p><pre>Log record -&gt; `Syncing 143.1 bps, target=#3313788 ... finalized #3223552`<br>syncing_time = (3313788 - 3223552) / 143.1 = 630 secs (10.5 mins)</pre><h4>17. 节点同步时，是否可以在节点监控器中观察到该节点？</h4><p>是的，你可以在节点监控器中看到该节点 — — https://telemetry.gear-tech.io。在区块高度完成更新前，该节点呈灰色。</p><h4>18. 在启动节点服务时，遇到了该问题 “error: Found argument ‘’ which wasn’t expected, or isn’t valid in this context” 请问如何解决？</h4><p>gear-node.service 配置文件似乎配置不当。请参考 - https://wiki.gear-tech.io/zh-cn/node/node-as-service/，将节点正确配置为一个服务。</p><h4>19. 需要将钱包连接节点吗？</h4><p>目前无需进行该操作。</p><h4>20. 是否有任何命令用以检查节点的最新更新？</h4><p>没有这样的命令。</p><h4>21. 遇到以下问题该如何解决？</h4><p>Failed to start gear-node.service: Unit gear-node.service is masked.</p><p>请查看 — — <a href="https://askubuntu.com/questions/1017311/what-is-a-masked-service">https://askubuntu.com/questions/1017311/what-is-a-masked-service</a></p><blockquote>常见错误</blockquote><p>这里介绍了常见的错误和解决方案。</p><h4>1. LOCK 文件不可用</h4><p>错误： IO 错误：While lock file /root/.local/share/gear/chains/gear_staging_testnet_v6/db/full/LOCK: Resource temporarily unavailable</p><p>解决方式： 你似乎在运行几个 Gear 节点实例。注意，只允许运行一个节点实例。你很可能把节点配置为一个服务，然后从命令行运行第二个实例。你应该停止该服务，或者不要从命令行运行 Gear 节点。</p><p>你可以通过运行命令查看当前的节点进程：</p><pre>ps aux | grep gear</pre><p>如果你想停止所有的节点进程，可以运行：</p><pre>pkill -sigint gear</pre><p>注意，SystemD 服务不能通过上述命令停止。改为运行：</p><pre>sudo systemctl stop gear-node</pre><h4>2. 启动节点服务时出现意外参数</h4><p>错误： Found argument &#39;\&#39; which wasn&#39;t expected, or isn&#39;t valid in this context</p><p>解决方式： gear-node.service 配置文件似乎有错误。某些版本的 SystemD 不接受反斜线字符 (\) 作为分行符。因此，最好将每个配置项写在一行。</p><p>请参考 https://wiki.gear-tech.io/node/node-as-service，将节点正确配置为服务。</p><p>不要忘记在修复服务配置后重新启动节点：</p><pre>sudo systemctl daemon-reload<br>sudo systemctl restart gear-node</pre><h4>3. 损坏的数据库</h4><p>错误： Database version cannot be read from existing db_version file</p><p>替代错误： Invalid argument: Column families not opened: ..., col2, col1, col0</p><p>解决方式： 这个问题的根源是磁盘空间不足。你可以用以下命令检查可用空间。</p><pre>df -h</pre><p>此外，你可以检查区块链数据库使用了多少空间。</p><pre>du -h $HOME/.local/share/gear/chains/gear_staging_testnet_v6/db/full</pre><p>请参考 系统要求，查看所需的最小磁盘空间。</p><p>你需要释放更多的空间，然后裁剪链：</p><pre>sudo systemctl stop gear-node<br># Provide more free space on the disk<br>gear purge-chain<br>sudo systemctl start gear-node</pre><h4>4. 节点可执行文件过期</h4><p>错误： Verification failed for block &lt;block-id&gt; received from peer &lt;peer-id&gt;</p><p>替代错误： runtime requires function imports which are not present on the host</p><p>解决方式： 更新 node 到最新版本。</p><h4>5. 服务被锁定</h4><p>错误： Failed to start gear-node.service: Unit gear-node.service is masked.</p><p>解决方式： 请检查此链接：https://askubuntu.com/questions/1017311/what-is-a-masked-service</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e90c7720fa3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[如何快速备份及恢复节点 | Gear Wiki]]></title>
            <link>https://medium.com/@gearfans/%E5%A6%82%E4%BD%95%E5%BF%AB%E9%80%9F%E5%A4%87%E4%BB%BD%E5%8F%8A%E6%81%A2%E5%A4%8D%E8%8A%82%E7%82%B9-gear-wiki-59eb7a8102ed?source=rss-aec9a73b8ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/59eb7a8102ed</guid>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[gear-protocol]]></category>
            <category><![CDATA[polkadot]]></category>
            <dc:creator><![CDATA[GearFans]]></dc:creator>
            <pubDate>Thu, 02 Mar 2023 22:28:10 GMT</pubDate>
            <atom:updated>2023-03-02T22:33:55.298Z</atom:updated>
            <content:encoded><![CDATA[<h4><em>导语</em></h4><blockquote><em>本篇文章主要介绍如何备份、恢复节点的数据，帮助你更好的了解 Gear。</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EV9POPTszp9im-KO.png" /></figure><blockquote><strong>数据格式</strong></blockquote><p>Gear 将节点数据存储在专用目录中。</p><ul><li>Linux：$HOME/.local/share/gear</li><li>macOS：$HOME/Library/Application Support/gear</li><li>Windows：%USERPROFILE%\AppData\Local\gear.exe</li></ul><p>例如，在 Linux 操作系统中以 root 用户运行节点 ($HOME = /root)，节点数据目录的绝对路径为：</p><pre>/root/.local/share/gear</pre><p>让我们研究下节点存储在这个目录中的数据。</p><pre>└── gear<br>    └── chains<br>        ├── dev<br>        │   └── ...<br>        ├── gear_staging_testnet_v6<br>        │   ├── db<br>        │   │   └── full<br>        │   ├── keystore<br>        │   └── network<br>        └── vara_network<br>            ├── db<br>            │   └── full<br>            ├── keystore<br>            └── network</pre><blockquote><strong>链</strong></blockquote><p>节点可以连接到不同的链。可以使用 --chain 参数来选择链。目前默认的链是 staging test 网络。它的数据位于 gear/chains/gear_staging_testnet_v6目录中。</p><p>如果连接到 Vara 网络，链的子目录名称是vara_network，路径是 gear/chains/vara_network。</p><p>如果使用--dev参数启动节点，开发模式下的虚拟网络将节点数据存储在gear/chains/dev。</p><blockquote><strong>数据库</strong></blockquote><p>数据库将区块链状态保存在本地节点存储中。它通过 p2p 协议与其他节点同步。可以使用 --database 参数选择不同的数据库类型。可选项是：</p><ul><li>rocksdb (默认)：使用 RocksDB 作为数据库引擎，数据存储在 &lt;chain&gt;/db/full 子目录中。</li><li>paritydb：使用 ParityDB 作为数据库引擎，数据存储在 &lt;chain&gt;/paritydb/full 子目录中。</li><li>paritydb-experimental：已弃用的 ParityDB 引擎实验模式 (将在未来的版本中删除)，数据存储在&lt;chain&gt;/paritydb/full 子目录中。</li></ul><p>注意，数据库内容取决于节点的修剪模式。默认情况下，节点只保留最后 256 个块。要保留所有的块，在运行节点时，请使用 --pruning=archive参数。</p><p>可以在任何时候删除和同步数据库。使用gear purge-chain命令将完全删除数据库。</p><blockquote><strong>网络密钥</strong></blockquote><p>网络私钥用于计算唯一的节点标识符 (以12D3KooW开头)。这个密钥存储在 &lt;chain&gt;/network/secret_ed25519 文件中。密钥文件是一个二进制文件，包含了 32 字节 Ed25519 私钥 (默认) 。你可以使用 hexdump 命令读取密钥：</p><pre>hexdump -e &#39;1/1 &quot;%02x&quot;&#39; /root/.local/share/gear/chains/gear_staging_testnet_v6/network/secret_ed25519</pre><pre># 42bb2fdd46edfa4f41a5f0f9c1a5a1d407a39bafbce6f07456a2c8d9963c8f5c</pre><p>你可以通过运行带有--node-key参数的节点来覆盖这个密钥：</p><pre>gear --node-key=42bb2fdd46edfa4f41a5f0f9c1a5a1d407a39bafbce6f07456a2c8d9963c8f5c</pre><pre># Discovered new external address for our node: /ip4/127.0.0.1/tcp/30333/ws/p2p/12D3KooWMRApe2S5QMdhHwmcDapDxZ7xf2Xa3z2HfCCYoHTmjiXV</pre><p>如果没有--node-key参数，节点使用secret_ed25519文件中的密钥。如果该文件不存在，则用新生成的密钥创建。</p><p>网络密钥文件一旦丢失就无法恢复。因此，你要保留它（或私钥本身），以便有可能以相同的 peer ID 运行节点。</p><blockquote><strong>迁移节点</strong></blockquote><p>要把节点移到新的服务器上，需要备份然后恢复以下内容（提供的路径是默认的 Staging Testnet V6 节点的参数）。</p><p><strong>节点的网络密钥：</strong></p><ul><li>Linux: $HOME/.local/share/gear/chains/gear_staging_testnet_v6/network/secret_ed25519</li><li>macOS: $HOME/Library/Application Support/gear/chains/gear_staging_testnet_v6/network/secret_ed25519</li><li>Windows: %USERPROFILE%\AppData\Local\gear.exe\chains\gear_staging_testnet_v6\network\secret_ed25519</li></ul><p><strong>7(可选) 数据库：</strong></p><ul><li>Linux: $HOME/.local/share/gear/chains/gear_staging_testnet_v6/db/full</li><li>macOS: $HOME/Library/Application Support/gear/chains/gear_staging_testnet_v6/db/full</li><li>Windows: %USERPROFILE%\AppData\Local\gear.exe\chains\gear_staging_testnet_v6\db\full</li></ul><p>(可选) 如果你已经将节点配置为服务，则服务配置： Linux: /etc/systemd/system/gear-node.service</p><blockquote><strong>信息</strong></blockquote><blockquote><em>在备份数据库之前，不要忘记停止节点。否则，你可能会得到一个损坏的数据库。</em></blockquote><blockquote><em>sudo systemctl stop gear-node</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59eb7a8102ed" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[一文读懂 Gear 节点运行与开发 | Gear Wiki]]></title>
            <link>https://medium.com/@gearfans/%E4%B8%80%E6%96%87%E8%AF%BB%E6%87%82-gear-%E8%8A%82%E7%82%B9%E8%BF%90%E8%A1%8C%E4%B8%8E%E5%BC%80%E5%8F%91-gear-wiki-71e327d71c85?source=rss-aec9a73b8ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/71e327d71c85</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[polkadot]]></category>
            <category><![CDATA[gear-protocol]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <dc:creator><![CDATA[GearFans]]></dc:creator>
            <pubDate>Thu, 02 Mar 2023 22:26:43 GMT</pubDate>
            <atom:updated>2023-03-02T22:26:43.911Z</atom:updated>
            <content:encoded><![CDATA[<h4><strong><em>导语</em></strong></h4><blockquote><em>本篇文章主要让你了解安装及运行 Gear 节点的主要步骤、如何将节点程序配置成 Linux 服务、配置 Gear 节点监测以及如何创建一个多节点的本地测试网络。</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*za7FAitthYgo-Z3l.png" /></figure><blockquote><strong>配置本地节点</strong></blockquote><h4>1.介绍</h4><p>本教程覆盖了安装和运行 Gear 节点所需的步骤。</p><p>这里有两种方式来开始运行 Gear 节点。第一种方式，你可以下载预编译好的二进制文件，直接运行。第二种方式，你可以自行编译和配置。使用已经准备好的编译文件是最快和最便捷的开始方式，因为你可以跳过诸如安装 Rust、安装依赖和节点编译的过程。从另一方面来讲，如果你决定要采用自己编译的方式来创建你的开发节点，那么它将花费大约 20 分钟时间或者更多，这一切取决于你的机器配置。</p><blockquote><strong>！信息</strong></blockquote><blockquote><em>系统配置要求</em></blockquote><blockquote><em>由于需要对 AVX 和 SSE 4.2 的支持，Gear 节点不能在 QEMU 虚拟 CPU 上正常工作。</em></blockquote><blockquote><em>Gear 节点并不要求特殊的硬件配置，除了建议使用 SSD 硬盘。</em></blockquote><h4>2.采用预编译的二进制文件来安装</h4><p>依据你的操作系统，你需要下载 Gear 节点的nightly build版本：</p><p><strong><em>Windows x64</em></strong></p><p>Terminal:</p><p>curl -O <a href="https://get.gear.rs/gear-nightly-windows-x86_64.zip">https://get.gear.rs/gear-nightly-windows-x86_64.zip</a></p><p>或</p><p>Windows x64: gear-nightly-windows-x86_64.zip</p><p><strong><em>MacOS ARM</em></strong></p><p>Terminal:</p><pre>wget https://get.gear.rs/gear-nightly-macos-m.tar.gz &amp;&amp; \<br>tar xvf gear-nightly-macos-m.tar.gz &amp;&amp; \<br>rm gear-nightly-macos-m.tar.gz</pre><p>或</p><p>macOS M1: gear-nightly-macos-m.tar.gz</p><p><strong><em>MacOS x64</em></strong></p><p>Terminal:</p><pre>wget https://get.gear.rs/gear-nightly-macos-x86_64.tar.gz &amp;&amp; \<br>tar xvf gear-nightly-macos-x86_64.tar.gz &amp;&amp; \<br>rm gear-nightly-macos-x86_64.tar.gz</pre><p>或</p><p>macOS Intel x64: gear-nightly-macos-x86_64.tar.gz</p><p><strong><em>Linux x64</em></strong></p><p>Terminal:</p><pre>wget https://get.gear.rs/gear-nightly-linux-x86_64.tar.xz &amp;&amp; \<br>tar xvf gear-nightly-linux-x86_64.tar.xz &amp;&amp; \<br>rm gear-nightly-linux-x86_64.tar.xz</pre><p>或</p><p>Linux x64: gear-nightly-linux-x86_64.tar.xz</p><h4>3.自行编译 Gear 节点</h4><p>自行编译版本需要花费一些时间，同时需要安装一些依赖：</p><p><strong><em>前期准备</em></strong></p><p>Linux 用户需要依照自己的发行版本来安装 GCC 和 Clang。 另外，需要安装包含所需的 wasm-opt 工具的 binaryen 工具集。</p><p>例如在 Ubuntu 上使用如下命令：</p><pre>sudo apt install -y clang build-essential binaryen cmake protobuf-compiler</pre><p>在 macOS 上，你可以通过运行以下命令得到编译器工具集和在 macOS 上，你可以通过运行以下命令得到编译器工具集和 binaryen。</p><pre>xcode-select --install<br>brew install binaryen</pre><p><strong><em>安装 Rust</em></strong></p><p>如果你已经安装 Rust，你可以跳过这一步。</p><pre>curl --proto &#39;=https&#39; --tlsv1.2 -sSf https://sh.rustup.rs | sh</pre><p>之后你需要重启你的终端。</p><p><strong><em>安装 Wasm Toolchains:</em></strong></p><pre>rustup toolchain add nightly<br>rustup target add wasm32-unknown-unknown --toolchain nightly</pre><p><strong><em>下载 Gear 代码</em></strong></p><pre>git clone https://github.com/gear-tech/gear.git<br>cd gear</pre><p><strong><em>编译</em></strong></p><pre>cargo build -p gear-cli --release</pre><p>或</p><pre>make node-release</pre><blockquote><strong>备注</strong></blockquote><blockquote><em>你将在 </em><em>/gear/target/release/gear 找到最终的编译输出</em></blockquote><blockquote><em>前往： </em><em>cd target/release</em></blockquote><h4><strong><em>4.运行 Gear 节点</em></strong></h4><blockquote><strong>信息</strong></blockquote><blockquote><em>这一步同是否是下载的预编译版本还是自己编译的版本无关。在 </em><em>gear-node 安装的目录运行如下命令来链接测试网：</em></blockquote><pre>./gear</pre><p>采用如下命令来运行开发模式的 Gear 节点：</p><pre>./gear --dev --tmp</pre><h4>5.命令标记和选项</h4><pre>gear [flags][options]</pre><p>--staging</p><p>链接到 Gear 测试网。</p><p>--dev</p><p>运行单节点 Gear 开发网络。</p><p>--tmp</p><p>采用临时目录来运行节点。临时目录会被创建出来，用来存储配置信息，并且在进程结束时被删除。</p><p>purge-chain</p><p>删除选定链的存储。需要明确链的类型 --staging 或 --dev。</p><p>--help</p><p>帮助信息。</p><h4>6.特殊环境变量</h4><p>运行 Gear 节点时开启合约日志：</p><pre>RUST_LOG=&quot;gwasm=debug&quot; gear [flags]</pre><blockquote><strong>将节点程序配置成 Linux 服务</strong></blockquote><h4>1.前期准备</h4><p>你需要依据自己的操作系统下载或者自行编译 gear-node 可执行文件。</p><h4>2.配置服务</h4><p>为了将 Gear 节点程序作为 Linux 的服务，你需要参照以下方式来配置 systemd 文件：</p><p>从 root 目录开始：</p><pre>cd /etc/systemd/system<br>sudo nano gear-node.service</pre><p>配置并保存：</p><pre>[Unit]<br>Description=Gear Node<br>After=network.target</pre><pre>[Service]<br>Type=simple<br>User=root<br>WorkingDirectory=/root/<br>ExecStart=/usr/bin/gear --name &quot;NODE_NAME&quot; --telemetry-url &quot;ws://telemetry-backend-shard.gear-tech.io:32001/submit 0&quot;<br>Restart=always<br>RestartSec=3<br>LimitNOFILE=10000</pre><pre>[Install]<br>WantedBy=multi-user.target</pre><blockquote><strong>备注</strong></blockquote><blockquote><em>ExecStart 指向 </em><em>gear 二进制文件所在的位置。在示例中是在 </em><em>/usr/bin 目录。 使用 </em><em>--引入额外的启动参数，但这些参数并不是必须的。</em></blockquote><h4>3.运行节点</h4><p>到这里我们就可以使用以下命令来启动服务：</p><pre>sudo systemctl start gear-node</pre><p>使其能够随系统自动启动：</p><pre>sudo systemctl enable gear-node</pre><p>检查 gear-node 服务状态：</p><pre>sudo systemctl status gear-node</pre><h4>4.检查日志</h4><p>运行以下命令可以查看服务日志：</p><pre>journalctl -u gear-node</pre><p>使用导航键浏览日志，使用 q 键退出。</p><p>你可以通过添加参数 -n 50 来查看最后 50 行日志：</p><pre>journalctl -u gear-node -n 50</pre><p>添加 -f 参数，在连续模式下查看日志的最后一行 (按 Ctrl+C 退出)：</p><pre>journalctl -u gear-node -fn 50</pre><h4>5.更新节点版本</h4><p>你只需要把节点的可执行文件（gear）替换成最新版本，然后重新启动执行。 例如，如果你的 Linux 可执行文件位于/usr/bin（如我们上面的配置），你要运行：</p><pre>wget https://get.gear.rs/gear-nightly-linux-x86_64.tar.xz<br>sudo tar -xvf gear-nightly-linux-x86_64.tar.xz -C /usr/bin<br>rm gear-nightly-linux-x86_64.tar.xz<br>sudo systemctl restart gear-node</pre><h4>6.删除节点</h4><p>运行以下命令，删除节点的存储、服务配置和可执行文件：</p><pre>sudo systemctl stop gear-node<br>sudo systemctl disable gear-node<br>sudo rm -rf /root/.local/share/gear<br>sudo rm /etc/systemd/system/gear-node.service<br>sudo rm /usr/bin/gear</pre><blockquote><strong>配置 Gear 节点监测</strong></blockquote><p>需要监控每个 Gear 节点和整个网络的健康状况，以确保真正的去中心化和稳健的运营。这包括各种块生成指标以及在 PoS 网络中至关重要的节点正常运行时间。</p><p>与任何其他基于 Substrate 的节点一样，Gear 节点可以通过 --telemetry-url 连接到任意的监测后端。</p><p>要开始向任意的监测服务器实例发送监测消息，需要在节点运行期间指定一个额外的选项，该选项将启用向指定的 http 地址发送监测消息。</p><p>如果你愿意参与并分享你的监测数据，那么请使用一下选项来运行你的节点：</p><pre>gear --telemetry-url &quot;ws://telemetry-backend-shard.gear-tech.io:32001/submit 0&quot;</pre><p>同时使用以下选项来提供你的节点名称：</p><pre>gear --name &quot;NODE NAME&quot;</pre><p>如何启动节点监测？ cd 到你的节点二进制文件所在的目录，然后运行一下命令：</p><pre>./gear --telemetry-url &quot;ws://telemetry-backend-shard.gear-tech.io:32001/submit 0&quot; --name &quot;My_Gear_node_name&quot;</pre><p>要检查当前运行节点的监测信息，请访问 https://telemetry.gear-tech.io。</p><blockquote><strong>运行一个 Gear 开发节点</strong></blockquote><p>开发节点对于开发和调试智能合约非常有用。你可以直接上传程序到本地节点，向程序发送消息，并验证程序的逻辑。</p><p>使用开发模式运行 Gear 节点：</p><ol><li>按照 <a href="https://wiki.gear-tech.io/zh-cn/node/setting-up/">https://wiki.gear-tech.io/zh-cn/node/setting-up/</a> 中的描述，为你的操作系统编译或下载最新构建版本。</li><li>使用开发模式运行节点：</li></ol><pre>./gear --dev --tmp</pre><ol><li>访问 <a href="https://idea.gear-tech.io/">https://idea.gear-tech.io/</a> 并连接到本地开发节点。通过左上方的按钮点击网络切换，选择 Development -&gt; Local node，然后点击切换按钮。使用 Idea 发送消息，读取程序状态等。</li><li>要清除开发链的节点数据，请使用：</li></ol><pre>./gear purge-chain --dev</pre><ol><li>要运行一个有详细日志的开发链，请使用：</li></ol><pre>RUST_LOG=debug RUST_BACKTRACE=1 ./gear -lruntime=debug --dev</pre><blockquote><strong>创建一个多节点本地测试网络</strong></blockquote><p>对于更高级的智能合约调试和测试，更接近真实的网络环境，你可以建立本地测试网，由几个互连的节点组成。这种模式可以看到多节点共识算法的运行情况。</p><p>运行具有两个验证节点的本地测试网，分别为 Alice 和 Bob，它们拥有 local 测试网的初始权限，并被赋予测试网单元，更多细节请看配置。</p><p>注意：这将需要两个终端 (每个节点一个)。</p><ol><li>首先运行 Alice 节点。下面的命令使用默认的 TCP 端口 (30333)，并指定 /tmp/alice 作为链数据库位置。 Alice 的节点 ID 是 12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp（传统表示为：QmRpheLN4JWdAnY7HGJfWFNbfkQCb6tFf4vA6hgjMZKrR）；这由 node-key 决定。</li></ol><pre>./gear \<br> --base-path /tmp/alice \<br> --chain=local \<br> --alice \<br> --node-key 0000000000000000000000000000000000000000000000000000000000000001 \<br> --telemetry-url &#39;ws://telemetry-backend-shard.gear-tech.io:32001/submit 0&#39;</pre><p>Alice 节点将在 块#0 以空闲模式运行，等待第二个验证节点。</p><pre>Gear Node<br>✌️ version 0.1.0-6dc8d24edd9<br>❤️ by Gear Technologies, 2021-2022<br>📋 Chain specification: Gear Local Testnet<br>🏷 Node name: Alice<br>👤 Role: AUTHORITY<br>💾 Database: RocksDb at /tmp/alice/chains/gear_local_testnet/db/full<br>⛓ Native runtime: gear-610 (gear-1.tx1.au1)<br>👶 Creating empty BABE epoch changes on what appears to be first startup.<br>Using default protocol ID &quot;sup&quot; because none is configured in the chain specs<br>🏷 Local node identity is: 12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp<br>💻 Operating system: macos<br>💻 CPU architecture: aarch64<br>📦 Highest known block at #0<br>〽️ Prometheus exporter started at 127.0.0.1:9615<br>Running JSON-RPC HTTP server: addr=127.0.0.1:9933, allowed origins=Some([&quot;http://localhost:*&quot;, &quot;http://127.0.0.1:*&quot;, &quot;https://localhost:*&quot;, &quot;https://127.0.0.1:*&quot;, &quot;https://polkadot.js.org&quot;])<br>Running JSON-RPC WS server: addr=127.0.0.1:9944, allowed origins=Some([&quot;http://localhost:*&quot;, &quot;http://127.0.0.1:*&quot;, &quot;https://localhost:*&quot;, &quot;https://127.0.0.1:*&quot;, &quot;https://polkadot.js.org&quot;])<br>🏁 CPU score: 1020MB/s<br>🏁 Memory score: 37732MB/s<br>🏁 Disk score (seq. writes): 1496MB/s<br>🏁 Disk score (rand. writes): 421MB/s<br>👶 Starting BABE Authorship worker<br>💤 Idle (0 peers), best: #0 (0x22c7…6847), finalized #0 (0x22c7…6847), ⬇ 0 ⬆ 0<br>💤 Idle (0 peers), best: #0 (0x22c7…6847), finalized #0 (0x22c7…6847), ⬇ 0 ⬆ 0<br>💤 Idle (0 peers), best: #0 (0x22c7…6847), finalized #0 (0x22c7…6847), ⬇ 0 ⬆ 0<br>💤 Idle (0 peers), best: #0 (0x22c7…6847), finalized #0 (0x22c7…6847), ⬇ 0 ⬆ 0</pre><p>另外，你可以在监测网站（https://telemetry.gear-tech.io）的 Gear Local Testnet 标签下找到 Alice 节点名称。</p><ol><li>在另一个终端，使用下面的命令，在不同的 TCP 端口（30334）上启动 Bob 的节点，链数据库位置在 /tmp/bob。--bootnodes 选项将使 Bob 节点与 Alice 节点在 TCP 30333 端口连接。</li></ol><pre>./gear \<br> --base-path /tmp/bob \<br> --bootnodes /ip4/127.0.0.1/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp \<br> --chain=local \<br> --bob \<br> --port 30334 \<br> --ws-port 9945 \<br> --telemetry-url &#39;ws://telemetry-backend-shard.gear-tech.io:32001/submit 0&#39;</pre><p>运行第二个验证者节点后，网络开始产生新的区块。</p><pre>Gear Node<br>✌️ version 0.1.0-6dc8d24edd9<br>❤️ by Gear Technologies, 2021-2022<br>📋 Chain specification: Gear Local Testnet<br>🏷 Node name: Bob<br>👤 Role: AUTHORITY<br>💾 Database: RocksDb at /tmp/bob/chains/gear_local_testnet/db/full<br>⛓ Native runtime: gear-610 (gear-1.tx1.au1)<br>🔨 Initializing Genesis block/state (state: 0xf470…d2dc, header-hash: 0x22c7…6847)<br>👴 Loading GRANDPA authority set from genesis on what appears to be first startup.<br>👶 Creating empty BABE epoch changes on what appears to be first startup.<br>Using default protocol ID &quot;sup&quot; because none is configured in the chain specs<br>🏷 Local node identity is: 12D3KooWHpsf9Gp59ct6t6d1MmKHxbmZRvSWcUej7cUNmWNBdvZE<br>💻 Operating system: macos<br>💻 CPU architecture: aarch64<br>📦 Highest known block at #0<br>Running JSON-RPC HTTP server: addr=127.0.0.1:61429, allowed origins=Some([&quot;http://localhost:*&quot;, &quot;http://127.0.0.1:*&quot;, &quot;https://localhost:*&quot;, &quot;https://127.0.0.1:*&quot;, &quot;https://polkadot.js.org&quot;])<br>Running JSON-RPC WS server: addr=127.0.0.1:9945, allowed origins=Some([&quot;http://localhost:*&quot;, &quot;http://127.0.0.1:*&quot;, &quot;https://localhost:*&quot;, &quot;https://127.0.0.1:*&quot;, &quot;https://polkadot.js.org&quot;])<br>🏁 CPU score: 875MB/s<br>🏁 Memory score: 38353MB/s<br>🏁 Disk score (seq. writes): 1497MB/s<br>🏁 Disk score (rand. writes): 421MB/s<br>👶 Starting BABE Authorship worker<br>discovered: 12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp /ip4/192.168.1.4/tcp/30333<br>discovered: 12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp /ip6/::1/tcp/30333<br>discovered: 12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp /ip4/127.0.0.1/tcp/30333<br>🙌 Starting consensus session on top of parent 0x22c70bb6baf611e5c9a6b1886b307dfa25cf1972b3400e70eb15d624c8b96847<br>🎁 Prepared block for proposing at 1 (0 ms) [hash: 0x1f55c4a9daf8c35d4388313ad67deec4ff5e472659e2fec310bd3032bcbdfe71; parent_hash: 0x22c7…6847; extrinsics (2): [0x8bbd…2a85, 0x7d5c…0b86]]<br>🔖 Pre-sealed block for proposal at 1. Hash now 0xe46f6031bb73710e239665d0da4212fbdcca77d57f9504d357c078f3b315389e, previously 0x1f55c4a9daf8c35d4388313ad67deec4ff5e472659e2fec310bd3032bcbdfe71.<br>👶 New epoch 0 launching at block 0xe46f…389e (block slot 1667197557 &gt;= start slot 1667197557).<br>👶 Next epoch starts at slot 1667198157<br>✨ Imported #1 (0xe46f…389e)<br>🙌 Starting consensus session on top of parent 0xe46f6031bb73710e239665d0da4212fbdcca77d57f9504d357c078f3b315389e<br>🎁 Prepared block for proposing at 2 (0 ms) [hash: 0x66281c25f34157c713876cda6f39324a0da6a9a50c0c32310683bca875c1ab4c; parent_hash: 0xe46f…389e; extrinsics (2): [0xcb81…f7c3, 0x7d5c…0b86]]<br>🔖 Pre-sealed block for proposal at 2. Hash now 0x2ab179fe98969cab0970df085b86e03dbee33daed527f6595bcdbeffebc64175, previously 0x66281c25f34157c713876cda6f39324a0da6a9a50c0c32310683bca875c1ab4c.<br>✨ Imported #2 (0x2ab1…4175)<br>🙌 Starting consensus session on top of parent 0x2ab179fe98969cab0970df085b86e03dbee33daed527f6595bcdbeffebc64175<br>🎁 Prepared block for proposing at 3 (0 ms) [hash: 0xb5b9be01adb191671e0421f4673f8bee0751481aaac7ea453d806161e3b46dd7; parent_hash: 0x2ab1…4175; extrinsics (2): [0x7771…de48, 0x7d5c…0b86]]<br>🔖 Pre-sealed block for proposal at 3. Hash now 0xf2ed128d41d96da623281745555a0fe00a033630aacf57ac02acc31ced267db0, previously 0xb5b9be01adb191671e0421f4673f8bee0751481aaac7ea453d806161e3b46dd7.<br>✨ Imported #3 (0xf2ed…7db0)</pre><ol><li>网络已经启动！如果想停止网络，只需在两个运行会话中按下 Ctrl + C 即可。</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71e327d71c85" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[使用 Gear 必须掌握的技术｜Gear Wiki]]></title>
            <link>https://medium.com/@gearfans/%E4%BD%BF%E7%94%A8-gear-%E5%BF%85%E9%A1%BB%E6%8E%8C%E6%8F%A1%E7%9A%84%E6%8A%80%E6%9C%AF-gear-wiki-76488ceea679?source=rss-aec9a73b8ab------2</link>
            <guid isPermaLink="false">https://medium.com/p/76488ceea679</guid>
            <category><![CDATA[gear-protocol]]></category>
            <category><![CDATA[wiki]]></category>
            <category><![CDATA[smart-contract-blockchain]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[GearFans]]></dc:creator>
            <pubDate>Thu, 02 Mar 2023 21:40:29 GMT</pubDate>
            <atom:updated>2023-03-02T21:40:29.660Z</atom:updated>
            <content:encoded><![CDATA[<h4>导语</h4><blockquote><em>本篇文章我们将为你介绍 Gear 使用的 Actor 模型、Substrate 框架、WebAssembly、持久内存的概念及工作方法、Gear 状态组件，以帮助你更好的了解 Gear。</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*k9pdCC1LooTCMIx4.png" /></figure><blockquote><strong>Actor 模型</strong></blockquote><p>在并行计算系统中，“消息通信” 意味着程序通过消息交换进行通信。它比 “共享内存通信” 更具有优势。消息传递并发比共享内存并发更容易理解。它通常被认为更健壮，比共享内存具有更好的性能。</p><p>对于进程间通信，Gear 使用 Actor 模型方案。Actor 模型的原则是，程序从不共享任何状态，只是在彼此之间交换信息。</p><p>通过 Actor 模型，系统由同时运作的对象组成，这些对象之间完全通过消息传递进行交流。虽然普通的 Actor 模型不保证消息的顺序，但 Gear 提供了一些额外的保证，即两个特定程序之间的消息的顺序被保留下来。</p><p>在 Actor 模型中，一个系统由同时运作的功能对象组成，这些对象之间完全通过消息传递进行通信。虽然一般 Actor 模型并不保证消息的顺序，但 Gear 提供了一些额外的保证，即两个特定程序之间的消息顺序被保存下来。</p><p>Actor 模型保障了高可扩展性和高容错性。</p><h4>Actor</h4><p>Actor 模型中的 Actor 是可以发送和接收消息的原子计算单元。在 Gear 中，Actor 是一个程序 (智能合约) 或向程序发送消息的用户。每个 Actor 都有一个内部私有状态和一个信箱。通信是异步的，消息从信箱中弹出并分配给消息处理流，在那里按周期处理。</p><p>当一个 Actor 收到并处理一个消息时，可以响应以下内容：</p><ul><li>向另一个 Actor 发送消息</li><li>创建另一个 Actor</li><li>改变自己的内部状态</li></ul><p>Actor 是独立的，它们从不分享任何状态，只是相互交换信息。</p><p>使用 Actor 模型方案提供了一种在程序（智能合约）逻辑中实现基于 Actor 的并发性的方法。它可以利用各种语言构造进行异步编程（Rust 中的 Futures 和 async-await）。</p><h4><strong>Async/await 支持</strong></h4><p>与类不同，actor 一次只允许一个任务访问它们的可变状态，这使得多个任务中的代码可以安全地与同一个 actor 实例交互。</p><p>异步函数大大简化了并发管理，但它们无法处理死锁或状态损坏的情况。为了避免死锁或状态损坏，异步函数应该避免调用可能阻塞其线程的函数。为了实现这一点，他们选择使用 await 表达式。</p><p>目前，典型的智能合约代码中缺乏对 async/await 模式的支持，这给智能合约开发人员带来了很多问题。实际上，通过手工添加函数（在 Solidity 智能合约中），以在智能合约程序流中实现更好的控制的方式，或多或少是可行的。但是问题在于，一些合约中的函数会让人们很容易混淆在合约生命周期中的哪个阶段可以调用哪个函数。</p><p>Gear 为程序提供了通用的 async/await 语法。它极大地简化了开发和测试，并减少了智能合约开发中出错的可能性。如果程序逻辑需要，Gear API 也允许通过简单地不使用 await 表达式来使用同步消息。</p><blockquote><strong>Substrate</strong></blockquote><p>Substrate 是一个模块化框架，通过组合定制或预先构建的组件，可以创建独特的区块链。</p><p>从名字上很容易理解 Substrate 的功能。Substrate 是一个模板，提供了开箱即用的可扩展能力，包括共识机制、治理功能、Wasm 等等。</p><p>Substrate 有以下几个功能：</p><ul><li>无分叉升级</li><li>内部协调（Built-in Coordination）</li><li>基于 WebAssembly 的跨语言支持</li><li>对轻客户端友好</li><li>最终一致性</li><li>无缝集成</li></ul><p>Substrate 使我们能够大大减少开发时间，并专注于开发主要的 Gear 组件。Rust 保证了程序的安全性和高性能。</p><p>更多关于Substrate的内容，请看 https://www.substrate.io/</p><blockquote><strong>什么是 WebAssembly(Wasm)</strong></blockquote><p>WebAssembly 是一种将 JavaScript 以外的编程语言的应用程序作为网页运行的方式。从本质上讲，Wasm 只是一个在所有现代浏览器上运行的虚拟机，但在过去，你需要使用 JavaScript 来运行网页中的代码，而 Wasm 使你有可能在 JavaScript 以外的编程语言的浏览器中运行代码。</p><p>由于技术的特殊性，WebAssembly 虚拟机，简称 Wasm，被证明比任何其他虚拟机都快。WebAssembly 的使用使 Gear 的智能合约能够直接编译成机器代码，并以接近原生的速度运行。更高的速度意味着更低的交易成本和更高的效率。</p><p>所有 Gear 程序和智能合约都是作为 WebAssembly 程序运行的。这意味着，例如，开发人员可以将他们的应用程序带到网络上，并在网络浏览器中实现应用程序的全部性能--它们通常在 Windows 或 Mac 上运行原生程序时具有的性能。开发人员实际上也不必直接编写 Wasm 代码。相反，他们将使用 Wasm 作为用其他语言编写的程序的编译目标。</p><p>Wasm 解决的主要问题是无法在网络上使用 JavaScript 以外的编程语言。虽然 JavaScript 是一种伟大的编程语言，但它的设计并不是为了在大型应用程序中实现超高速。Wasm 改变游戏规则的地方在于，它以一种完全安全的方式将用其他编程语言编写的本地应用程序的性能带到了网络上。</p><p>Wasm 应该在两个主要方面提供显著的速度提升。首先，它应该大大增加应用程序的启动速度。事实上，已经使用 Wasm 的应用程序已经能够将应用程序的启动时间减少一半，而且随着更多的优化，它只会继续进一步提高启动速度。这将使巨大的应用程序能够非常、非常迅速地加载起来。其次，Wasm 在吞吐量方面也有很大的好处，这意味着一旦代码被编译，它的运行速度会更快--使应用程序更有效，反应更快，这将大大改善用户体验。</p><p>WebAssembly 有以下优点：</p><ul><li>Wasm 是非常快速、高效和可移植的。代码可以在不同的平台上以接近原生的速度执行。</li><li>Wasm 也是可读和可调试的。虽然 WebAssembly 是一种低级语言，但它确实有一种人类可读的文本格式，可以用手写、查看和调试代码。</li><li>它也是非常安全的，因为它是在一个安全的沙盒环境中运行的，像其他网络代码一样，它将执行浏览器的同源和无权限安全策略。</li><li>Wasm 格式允许 Gear Protocol 的开发者现在使用 Rust 开发，未来 C#/C++、Go 和 Javascript 也可以编写应用程序。</li></ul><blockquote><strong>持久化内存</strong></blockquote><p>Gear Protocol 的另一个突出特点是持久性内存方法。它使开发更容易，消除了很多复杂性，并使协议内存管理与实际硬件和操作系统相匹配。</p><p>在 Gear 网络中运行的程序不使用存储，而是将全部状态持久化，这确保了区块链上下文的 API 面要小得多。它避免了特定领域的语言特征，也允许使用更复杂的语言结构--持久化的闭包、合成器等。</p><p>Gear Protocol 使用了巧妙的内存虚拟化技术 (尽管普通的 Wasm 没有)，内存分配和回收是该协议的第一等系统调用，还会跟踪内存访问，只加载/存储所需的内存页。这使得存储在区块链状态中的智能合约的堆栈框架（通常在期货及其合成器中发现）能够被无缝持久化，并在需要时被调用，在请求时保留其状态。</p><p>程序代码存储为一个不可变的 Wasm blob。每个程序都有固定数量的内存，在消息处理之间存在 (所谓的静态区域)。</p><p>Gear 实例持有每个程序的单独内存空间，并保证持久性。一个程序只能在它自己的内存空间内进行读写，不能访问其他程序的内存空间。单独的内存空间在程序初始化期间为其保留，不需要额外的费用（它包含在程序的初始化的费用中）。</p><p>程序可以按 64KB 的块分配所需的内存量。每个内存块分配都需要 gas 费。每个页面 (64KB) 单独存储在分布式数据库后端，但在运行时，Gear 节点构造连续运行时内存，并允许程序在其上运行而无需重新加载。</p><h4>内存并行</h4><p>每个程序单独的独立内存空间允许 Gear 节点上的消息处理并行化。并行处理流的数量等于 CPU 核数。每个流处理用于一组已定义程序的消息。它涉及从其他程序或外部发送的消息 (用户事务)。</p><p>例如，给定一个消息队列，其中包含针对 100 个不同程序的消息，Gear 节点运行在一个配置了 2 个处理线程的网络上。Gear 引擎使用运行时定义的流数量 (等于一个典型的验证机上的 CPU 核的数量)，将目标程序的总数除以流的数量，并为每个流创建一个消息池 (每个流 50 个程序)。</p><p>程序被分发到不同的流中，每个消息出现在定义了目标程序的流中。因此，所有发给特定程序的消息都出现在一个处理流中。</p><p>在每个周期中，目标程序可以有多个消息，一个流处理大量程序的消息。消息处理的结果是来自每个流的一组新消息被添加到消息队列中，然后循环往复。在消息处理过程中生成的结果消息通常被发送到另一个地址 (返回原点或下一个程序)。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aQVOOaIOKAu-hcNZXDQ_-w.jpeg" /></figure><blockquote><strong>状态组件</strong></blockquote><p>与任何区块链系统一样，Gear 保持分布式状态。编译为 WebAssembly 的运行时代码，成为区块链存储状态的一部分。</p><p>Gear 确保了其中一个决定性的特征--无障碍运行时升级。如果使用终结性小工具，状态也可以保证被终结。</p><p>存储状态由以下组件组成：</p><ul><li>程序和内存（包括程序代码和私有内存）</li><li>消息队列（网络的全局消息队列）</li><li>账户（网络账户及其余额）</li></ul><h4>程序</h4><p>程序是 Gear 网络状态下的头等公民。</p><p>程序代码存储为不可变的 Wasm 二进制文件（blob）。每个程序都有固定数量的内存，在消息处理之间保持不变（所谓的静态区域）。</p><p>程序可以从 Gear 实例提供的内存池中分配更多内存。一个特定的程序只能在专门分配给它的内存中读写。</p><h4>内存</h4><p>每个程序都有固定的内存大小，Gear 允许对其进行控制。程序只能在其内存中读写，不能访问其他程序的内存空间。每个程序都有独立的内存空间，可以在 Gear 节点上并行处理消息。</p><p>程序可以以 64KB 的块为单位分配所需的内存量。每个内存块分配都需要 gas 费。每个页面（64KB）单独存储在分布式数据库后端，但在运行时，Gear 节点构建连续运行时内存并允许程序在其上运行而无需重新加载。</p><h4>消息队列</h4><p>Gear 实例拥有一个全局消息队列。使用 Gear 节点，用户可以将带有一条或多条消息的交易发送到特定程序。这会填满消息队列。在块构造期间，消息出列并路由到特定程序。</p><h4>账户</h4><p>对于公共网络，防止 DOS 攻击总是需要 gas/fee 来处理交易。Gear 提供了一个 balance 模块，允许存储用户和程序的余额并支付交易费用。</p><p>一般来说，一个特定的 Gear 网络实例可以定义为有许可和无许可的公共区块链。在许可场景中，不需要 balance 模块。</p><blockquote><strong>状态转移</strong></blockquote><p>每个系统都遵循系统状态演变所依据的规则。当网络处理新的输入数据时，状态会根据状态转换规则前进。这些输入数据被打包在被称为交易 (transactions) 的细粒度信息中。</p><p>Gear 节点维护和同步一个交易池，其中包含所有新交易。当任何节点（无论是否为验证者）收到一个交易时，该节点会将这个交传播给所有连接的节点。关于交易池如何运作的更高级内容，请参考 Substrate 文档 。链接替换为 https://docs.substrate.io/v3/concepts/tx-pool/</p><p>当 Gear 验证节点生成新块时，池中的一些（或所有）交易将合并到一个区块中，网络将通过该块进行状态转换。在生成下一个块之前，上一个块中未打包的交易将保留在池子中，直到产生下一个区块。</p><p>Gear 网络支持以下类型的交易：</p><ol><li>上传程序 - 用户上传新的程序（智能合约）</li><li>上传代码 - 用户上传代码，以便以后用它来3. 创建程序 - 程序或用户根据先前上传的代码创建一个程序</li><li>发送消息 - 程序或用户将消息放入消息队列</li><li>发送回复消息 - 与消息类似，但只能作为对收到的信息的回复来发送</li><li>从 mailebox 提款 - 用户要求提走与他的 mailbox 中的信息相关的余额</li><li>取出消息 - 验证器（区块生产者）对多个信息进行排队，运行相关程序</li><li>转账交易 - Gear 引擎执行 用户—程序—验证者 之间的转账交易</li></ol><p>消息处理在块构建/导入时的预留空间中进行。它保证消息处理将在每个块中执行，并且至少以当前实例设置确定的某个特定速率执行。</p><h4>上传程序</h4><p>Gear 网络的指定机构 (或任何公开实现的用户) 可以提出一个新的程序保存到状态种。对于公共网络，还提供与程序相关的余额。这个新的余额将会设置为初始余额（存在抵押）。</p><h4>上传代码</h4><p>无需初始化即可上传 Wasm 代码。此代码不能作为程序执行，但它会保存到存储中，并可用于从中创建新程序。用户和程序都可以从上传的代码创建程序。</p><h4>创建程序</h4><p>用户和程序都可以从上传的代码创建新程序。代码可以多次重用以生成多个程序。</p><h4>发送消息</h4><p>终端用户通过向 Gear 网络发送信息与程序进行交互。发送到 Gear 网络的消息填充全局消息队列。这个队列可以被看作是一个运行时驱动的交易队列，但是要保证它接收的任何消息最终都会被处理。将消息放入队列不是免费的，因此可以保证消息会被发送。</p><p>程序之间也会交换消息。接收到的消息的结果可以是另一个消息 (回复)，发送给另一个程序或用户或指定的行为，用于它接收到的下一个消息。一个程序还可以发送一个消息，其执行结果将是创建另一个程序。</p><h4>发送回复消息</h4><p>回复与上述消息类似，唯一不同的是，回复只能作为对收到的消息的回应而发送。用户可以将回复发送给他们 mailbox 中包含的信息。</p><h4>从 mailbox 提款</h4><p>在接收到具有关联的资产的消息后，用户必须提取资产，才能将其从消息转账到用户。未认领的将在邮件耗尽 gas 限制后离开 mailbox 后返回给发件人。</p><h4>取出消息</h4><p>当轮到验证器生成下一个区块时，验证者可以选择让哪些消息出列。它不需要每个特定的验证器来维护完整内存状态。出队列只发生在每个块的末尾。在退出队列期间，可以生成新的消息。它们也可以在此阶段被处理，但也可以留在队列中等待下一个块 (和另一个验证器)。</p><h4>转账交易</h4><p>常规转账交易可以通过两种方式进行。第一种方法是使用相应的外在因素 (例如transfer, setBalance等)。第二种方式是将一个用户的信息发送给另一个用户，并附附带相关的余额。</p><h4>消息、区块和事件的生命周期</h4><p>下图说明了 Gear 的全生命周期。正如面向通信领域的 actor 模型所规定的，除了消息可以共享，再没有任何东西是可以共享的了。以“系统”为目的地的消息最终会出现在事件日志中，以便在用户空间进行检查。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GmWKkRT10ezBt2-1UNkdDw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76488ceea679" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>