基于区块链的毕业设计Substrate Node Template – 基板节点模板

本文提供基于区块链的毕业设计国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,基于区块链的毕业设计Substrate Node Template – 基板节点模板 是一篇很好的国外资料

Substrate Node Template

A new FRAME-based Substrate node, ready for hacking 🚀

Local Development

Follow these steps to prepare a local Substrate development environment 🛠️

Simple Setup

Install all the required dependencies with a single command (be patient, this can take up to 30 minutes).

curl https://getsubstrate.io -sSf | bash -s -- --fast

Manual Setup

Find manual setup instructions at the Substrate Developer Hub.

Build

Once the development environment is set up, build the node template. This command will build the Wasm and native code:

cargo build --release

Run

Single Node Development Chain

Purge any existing dev chain state:

./target/release/node-template purge-chain --dev

Start a dev chain:

./target/release/node-template --dev

Or, start a dev chain with detailed logging:

RUST_LOG=debug RUST_BACKTRACE=1 ./target/release/node-template -lruntime=debug --dev

Multi-Node Local Testnet

To see the multi-node consensus algorithm in action, run a local testnet with two validator nodes, Alice and Bob, that have been configured as the initial authorities of the local testnet chain and endowed with testnet units.

Note: this will require two terminal sessions (one for each node).

Start Alice’s node first. The command below uses the default TCP port (30333) and specifies /tmp/alice as the chain database location. Alice’s node ID will be 12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp (legacy representation: QmRpheLN4JWdAnY7HGJfWFNbfkQCb6tFf4vvA6hgjMZKrR); this is determined by the node-key.

cargo run --    --base-path /tmp/alice    --chain=local    --alice    --node-key 0000000000000000000000000000000000000000000000000000000000000001    --telemetry-url 'ws://telemetry.polkadot.io:1024 0'    --validator

In another terminal, use the following command to start Bob’s node on a different TCP port (30334) and with a chain database location of /tmp/bob. The --bootnodes option will connect his node to Alice’s on TCP port 30333:

cargo run --    --base-path /tmp/bob    --bootnodes /ip4/127.0.0.1/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp    --chain=local    --bob    --port 30334    --ws-port 9945    --telemetry-url 'ws://telemetry.polkadot.io:1024 0'    --validator

Execute cargo run -- --help to learn more about the template node’s CLI options.

Template Structure

A Substrate project such as this consists of a number of components that are spread across a few directories.

Node

A blockchain node is an application that allows users to participate in a blockchain network. Substrate-based blockchain nodes expose a number of capabilities:

  • Networking: Substrate nodes use the libp2p networking stack to allow the nodes in the network to communicate with one another.
  • Consensus: Blockchains must have a way to come to consensus on the state of the network. Substrate makes it possible to supply custom consensus engines and also ships with several consensus mechanisms that have been built on top of Web3 Foundation research.
  • RPC Server: A remote procedure call (RPC) server is used to interact with Substrate nodes.

There are several files in the node directory – take special note of the following:

  • chain_spec.rs: A chain specification is a source code file that defines a Substrate chain’s initial (genesis) state. Chain specifications are useful for development and testing, and critical when architecting the launch of a production chain. Take note of the development_config and testnet_genesis functions, which are used to define the genesis state for the local development chain configuration. These functions identify some well-known accounts and use them to configure the blockchain’s initial state.
  • service.rs: This file defines the node implementation. Take note of the libraries that this file imports and the names of the functions it invokes. In particular, there are references to consensus-related topics, such as the longest chain rule, the Aura block authoring mechanism and the GRANDPA finality gadget.

After the node has been built, refer to the embedded documentation to learn more about the capabilities and configuration parameters that it exposes:

./target/release/node-template --help

Runtime

In Substrate, the terms “runtime” and “state transition function” are analogous – they refer to the core logic of the blockchain that is responsible for validating blocks and executing the state changes they define. The Substrate project in this repository uses the FRAME framework to construct a blockchain runtime. FRAME allows runtime developers to declare domain-specific logic in modules called “pallets”. At the heart of FRAME is a helpful macro language that makes it easy to create pallets and flexibly compose them to create blockchains that can address a variety of needs.

Review the FRAME runtime implementation included in this template and note the following:

  • This file configures several pallets to include in the runtime. Each pallet configuration is defined by a code block that begins with impl $PALLET_NAME::Trait for Runtime.
  • The pallets are composed into a single runtime by way of the construct_runtime! macro, which is part of the core FRAME Support library.

Pallets

The runtime in this project is constructed using many FRAME pallets that ship with the core Substrate repository and a template pallet that is defined in the pallets directory.

A FRAME pallet is compromised of a number of blockchain primitives:

  • Storage: FRAME defines a rich set of powerful storage abstractions that makes it easy to use Substrate’s efficient key-value database to manage the evolving state of a blockchain.
  • Dispatchables: FRAME pallets define special types of functions that can be invoked (dispatched) from outside of the runtime in order to update its state.
  • Events: Substrate uses events to notify users of important changes in the runtime.
  • Errors: When a dispatchable fails, it returns an error.
  • Trait: The Trait configuration interface is used to define the types and parameters upon which a FRAME pallet depends.

Generate a Custom Node Template

Generate a Substrate node template based on a particular commit by running the following commands:

# Clone from the main Substrate repo git clone https://github.com/paritytech/substrate.git cd substrate  # Switch to the branch or commit to base the template on git checkout <branch/tag/sha1>  # Run the helper script to generate a node template. This script compiles Substrate, so it will take # a while to complete. It expects a single parameter: the location for the script's output expressed # as a relative path. .maintain/node-template-release.sh ../node-template.tar.gz

Custom node templates are not supported. Please use a recently tagged version of the Substrate Developer Node Template in order to receive support.

We use optional third-party analytics cookies to understand how you use GitHub.com so we can build better products. Learn more.


基板节点模板

一个新的基于框架的基板节点,准备黑客攻击🚀

本地开发

按照这些步骤准备一个本地基板开发环境🛠️

简单设置

用一个命令安装所有必需的依赖项(耐心点,这可能需要30分钟)。

curl https://getsubstrate.io -sSf | bash -s -- --fast

构建

在基板显影剂中心找到手动设置说明。

运行

一旦开发环境设置好,就构建节点模板。此命令将生成Wasm和本机代码:

cargo build --release

单节点开发链

多节点本地测试网

清除任何现有的开发人员链状态:

./target/release/node-template purge-chain --dev

启动一个开发人员链:

./target/release/node-template --dev

或者,启动一个具有详细日志记录的开发链:

RUST_LOG=debug RUST_BACKTRACE=1 ./target/release/node-template -lruntime=debug --dev

模板结构

若要查看多节点一致性算法的实际运行,请使用两个验证节点Alice和Bob运行本地testnet,被配置为本地testnet链的初始权限并被赋予testnet单元。

注意:这需要两个终端会话(每个节点一个)。

首先启动Alice的节点。下面的命令使用默认的TCP端口(30333)并指定/tmp/alice作为链数据库位置。Alice的节点ID将是12d3kooweyoppncx8yx66ov9fjnrixwccxwddua2kj6vnc6idep(传统表示:qmrheln4jwdany7hgjfwfnbfkqcb6tf4vva6hgjmzkrr);这由节点键决定。

cargo run --    --base-path /tmp/alice    --chain=local    --alice    --node-key 0000000000000000000000000000000000000000000000000000000000000001    --telemetry-url 'ws://telemetry.polkadot.io:1024 0'    --validator

在另一个终端中,使用以下命令在另一个TCP端口(30334)上启动Bob的节点,该端口的链数据库位置为/tmp/Bob。–bootnodes选项将把他的节点连接到TCP端口30333上的Alice节点:

cargo run --    --base-path /tmp/bob    --bootnodes /ip4/127.0.0.1/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp    --chain=local    --bob    --port 30334    --ws-port 9945    --telemetry-url 'ws://telemetry.polkadot.io:1024 0'    --validator

执行货物运行—-帮助了解有关模板节点的CLI选项的更多信息。

节点

像这样的底层项目由许多分布在几个目录中的组件组成。

运行时

区块链blockchain节点是允许用户参与区块链blockchain网络的应用程序。基于基片的区块链blockchain节点公开了许多功能:

  • 联网:底层节点使用libp2p网络堆栈来允许网络中的节点彼此通信。
  • 共识:区块链blockchain必须有办法就网络状态达成共识。基板使它能够提供定制的共识引擎,也有几个共识机制已经建立在Web3基金会研究之上。
  • RPC服务器:远程过程调用(RPC)服务器用于与底层节点交互。

在节点目录中有几个文件-请特别注意以下几点:

  • 链条_规范rs:链规范是定义基板链初始(genesis)状态的源代码文件。链规范对于开发和测试非常有用,在构建生产链的启动时非常重要。注意development_config和testnet_genesis函数,它们用于定义本地开发链配置的genesis状态。这些功能识别一些知名账户,并使用它们来配置区块链blockchain的初始状态。
  • 服务.rs:此文件定义节点实现。请注意此文件导入的库及其调用的函数的名称。特别是,这里提到了与共识相关的主题,比如最长链规则、Aura块创作机制和grandon final gadget。

在构建节点之后,请参阅嵌入的文档,以了解有关其公开的功能和配置参数的更多信息:

./target/release/node-template --help

托盘

在Substrate中,术语“运行时”和“状态转换功能”是类似的-它们指的是区块链blockchain的核心逻辑,负责验证块并执行它们定义的状态更改。此存储库中的底层项目使用框架框架构建区块链blockchain运行时。FRAME允许运行时开发人员在称为“托盘”的模块中声明特定于域的逻辑。FRAME的核心是一种有用的宏语言,它使创建托盘和灵活组合托盘变得容易,从而创建能够满足各种需求的区块链blockchain

查看此模板中包含的帧运行时实现,并注意以下事项:

  • 此文件配置多个托盘以包含在运行时中。每个托盘配置由一个代码块定义,该代码块以impl$pallel_NAME::Trait for Runtime开头。
  • 通过constructu运行时,托盘被组合成一个运行时!宏,它是核心框架支持库的一部分。

生成一个自定义节点模板

此项目中的运行时是使用核心基板存储库附带的多个框架托盘和托盘目录中定义的模板托盘构建的。

框架托盘受到许多区块链blockchain原语的影响:

  • 存储:FRAME定义了一组功能强大的存储抽象集,使得使用基板的有效键值数据库来管理区块链blockchain的演变状态变得容易。
  • 可分派:帧托盘定义了可以从运行时外部调用(调度)的特殊类型的函数,以便更新其状态。
  • 事件:Substrate使用事件通知用户运行时的重要更改。
  • 错误:当可分派文件失败时,它将返回一个错误。
  • Trait:Trait配置接口用于定义框架托盘依赖的类型和参数。在

基本cookies

通过运行以下命令,基于特定提交生成基板节点模板:

# Clone from the main Substrate repo git clone https://github.com/paritytech/substrate.git cd substrate  # Switch to the branch or commit to base the template on git checkout <branch/tag/sha1>  # Run the helper script to generate a node template. This script compiles Substrate, so it will take # a while to complete. It expects a single parameter: the location for the script's output expressed # as a relative path. .maintain/node-template-release.sh ../node-template.tar.gz

不支持自定义节点模板。请使用最近标记的基板显影剂节点模板,以获得支持。

我们使用可选的第三方分析cookies来了解您如何使用GitHub.com网站所以我们可以制造更好的产品。了解更多。

部分转自网络,侵权联系删除区块链源码网

www.interchains.cc

https://www.interchains.cc/18405.html

区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 !
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » 基于区块链的毕业设计Substrate Node Template – 基板节点模板

提供最优质的资源集合

立即查看 了解详情