Editor's Note: This article comes from PolkaWorld(ID:gh_6c4c2038ddba)Editor's Note: This article comes from
, Author: Shawn Tabrizi, reprinted with authorization by Odaily.
In this article, I will try to explain the Substrate blockchain framework in a way that anyone with even a modicum of technical experience can understand.
You may have heard of Substrate as an extensible, modular, and open-source framework for building blockchains. But what exactly does that mean?
transaction queue
Internet connection
transaction queue
consensus
consensus
However, before we can get into all these details, we first need to reach a consensus on "what is the blockchain"...
secondary title
In its most basic form, a blockchain is a simple data structure in which blocks of data are linked together to form an ordered chain. The specifics of a blockchain vary depending on the functionality of the chain. In general, however, all blockchains should share some common properties.
block
block
Each block in the blockchain holds some data that can be used to generate a unique identifier for that block. Part of this data is the unique identifier of the previous block, the "parent block". Since each block has a pointer connecting its parent blocks, all blocks can be ordered in a deterministic manner.
A slight change in the data within any single block will change its unique ID. As the ID of the block is changed, the blocks (sub-blocks) generated after that will also be changed. The same goes for the next sub-block, and the next one, and the next... In fact, all blocks generated after the improved original block will have to change their unique IDs to maintain the whole chain stability. This means that two blockchains can easily be verified to have the exact same data by simply checking the unique identifier of the last block on the chain.https://anders.com/blockchain/
To learn more about the basics of blockchain, please visit the demo/video address:
block generation
Because of these properties, blockchain systems are commonly used to record a shared ledger. The contents of the ledger are changed not by changing an existing block, but by adding new blocks to the blockchain according to instructions on how to change the state of the ledger from block to block . These instructions are often called transactions.
There are usually rules about how changes are made to the ledger, defined by a state transition function. For a cryptocurrency system, the rules are pretty simple. For example:
Rules: Users can only spend their own funds.
The rules can also be more complex, even allowing the blockchain system to function as a Turing-complete computer, with the ledger serving as the computer's storage.
Once a valid set of transactions is collected, they are put into a block, which is then placed at the end of the chain. This process of block generation allows the underlying state of the blockchain to change over time.
final confirmation of the block
Forks are normal, expected, and generally not a threat. The finalization process of blocks is designed to help non-standardized chains resynchronize. We will continue to explain the content of forks in the second half of this article.
node
node
Blockchain systems are usually "open source" systems, meaning anyone can participate. To deter malicious actors, mechanisms are built to incentivize good behavior and punish bad behavior. With the above mechanisms in place, a blockchain system becomes an unstoppable machine.
secondary title
Substrate components
Now that you have a higher level understanding of what a blockchain is, we can start to understand how Substrate works as a framework to build it. The first explanation for the Substrate framework is scalability. This means it makes as few assumptions as possible about how a blockchain should be designed and tries to be as general as possible.
As we have teased out, at the heart of a blockchain is its shared ledger, which must be maintained and stored. Substrate makes no assumptions about the content or structure of data in the blockchain. The underlying database uses a simple key-value store on which a modified Patricia Merkle tree (trie) is implemented. This special storage structure allows us to easily verify that an element is in that storage. This is especially important to support lightweight clients that will rely on these proofs of storage for lightweight but trustless interactions with the blockchain network.
Internet connection
Internet connection
In order for the decentralized blockchain system to communicate, it is necessary to build a point-to-point network connection protocol. Substrate uses libp2p as a modular peer-to-peer networking stack. Through this network connection layer, Substrate-based blockchains can share transactions, blocks, nodes, and other system-critical details without the need for a centralized server.
Following Substrate's philosophy, libp2p is unique in that it makes no assumptions about any particular network protocol. Therefore, you can implement and use different protocols on Substrate-based blockchains.
As mentioned above, transactions are collected, form blocks, and ultimately define changes to the state of the blockchain. However, the order of these transactions can have an impact on the final state of the ledger. Substrate gives you full control over the independence and queue management of transactions in the network. Substrate only assumes that a transaction has a weight and a set of prerequisite labels for creating the dependency graph. These dependency graphs are linear in the simplest case, but they can also become more complex. Substrate will automatically handle these complex dependencies for you.
consensus
Blockchain networks can reach consensus based on chain changes in different ways. Traditionally, these consensus engines are tightly coupled to other blockchain components. However, Substrate has taken extra effort to design a consensus layer that can be easily changed during development. In fact, the ultimate goal of this design is to be able to perform consensus hot swaps after the chain goes live! A variety of different consensus engines are built into Substrate, such as the traditional proof-of-work mechanism (POW), Aura (Authority Round), and Polkadot consensus. Its uniqueness lies in the separation of the block generation process (BABE) from the block finalization process (GRANDPA).
secondary title
Substrate runtime environment
So far, we have covered all the core blockchain components that Substrate can provide. As you've read, Substrate has gone out of its way to be versatile and extensible. However, arguably the most customizable aspect of Substrate is its modular runtime environment. The operating environment refers to the state transition function of Substrate mentioned earlier.
Substrate believes that the average blockchain developer does not need to care too much about the blockchain components listed above. As long as the components are field-hardened and production-ready, the details of the implementation often don't matter that much. However, the core logic of a blockchain that determines whether content in a network is valid is usually of considerable importance for any chain.
Substrate Runtime Module Library (SRML)
Therefore, the core idea of Substrate is to make the development of blockchain operation as flexible and simple as possible.
The operating environment of a blockchain can be divided into different logical components, which are called operating modules. These modules will control certain parts of the on-chain logic managed by the blockchain. You can think of these modules as "plugins" to your system. As a Substrate developer, you can pick and choose which modules and features you want included in the chain.
For example, there is a module called "balance" that manages the currency on the chain. There are also a set of modules such as "Collection", "Democracy" and "Election" that handle the on-chain decision-making and governance process. There is even a module called "contracts" that can turn any Substrate-based chain into a smart contract platform. These modules are automatically provided for you when you build on Substrate.
However, you are not limited to using the modules provided by Substrate. In fact, developers can easily build their own runtime modules as independent logical components, and even interact directly with other runtime modules to build more complex logic. We believe that in the long run, the module system in Substrate will become more like an "app store", where users can easily select the functions they want to include, and deploy distributed blockchain networks with entry-level technical knowledge!
Running updates without forking
If we follow the analogy of the Substrate modular ecosystem to the app store, then we also have to address the question of how to update the runtime environment. Whether it's bug fixes, general improvements to existing modules, or even adding new functionality to the blockchain, Substrate already has a first-class ability to change the environment in which it operates.
However, changes to the on-chain state transition function can also affect the consensus of the network. If a node running in the network has one version of the logic, and another node has a different version of the logic, then the two nodes will not be able to reach a consensus. They will fundamentally overrule the true state of the distributed ledger, leading to the result of the fork we defined earlier. These uncoordinated forks will reduce the security of the network and have a bad impact, causing only a part of the nodes to correctly generate and verify new blocks.
In the spirit of flexibility, Substrate eliminates the need to manually enable this feature at all. If you want to disable on-chain upgrades, you can do that too. In fact, Substrate will give you all the tools you need for your chain up front.
secondary title
free and open source
Substrate is a completely free and open source project. It is built using the Rust programming language, which is designed to help develop fast and inherently safe software. Coordination and development of Substrate takes place with the help of more than 100 individual contributors in public communities such as Github and Riot.
secondary title
Summarize
Summarize
Translator: Silvia (PolkaWorld Super Agent)
