Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the concept of Layer2 extension of blockchain

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article introduces in detail "What is the concept of Layer2 extension of blockchain" for everyone. The content is detailed, the steps are clear, and the details are handled properly. I hope this article "What is the concept of Layer2 extension of blockchain" can help you solve your doubts. Let's go deeper and learn new knowledge together with the ideas of the small editor.

1. How to evaluate the "performance" of blockchain?

If we ask a blockchain enthusiast or practitioner now: What do you think is the biggest technical problem facing mature public chains such as Bitcoin and Ethereum? I think most people's answers would be similar: long confirmation times (how long it takes for a transaction to be sent to final confirmation), heavy network congestion (if too many transactions are generated at the same time, some transactions cannot be processed immediately), and so on. This is often referred to as a "performance" problem.

For the evaluation of the so-called "performance" of the current public chain platform based on blockchain architecture, two aspects should be considered.

The most discussed is the so-called TPS (Transactions Per Second), which measures the number of transactions that a blockchain can process per unit of time; the so-called "expansion" we have most often mentioned in recent years refers to this dimension.

If Ethereum is compared to the "world computer", then at present, it can only use a single core (single thread) to calculate.(Only one miner can keep accounts at a time, or only one miner's account will be accepted); and the so-called "expansion" can be imagined as expanding the "world computer" to multi-core (multi-threaded), so that it can run multiple tasks simultaneously in a unit time (there are multiple miners keeping accounts at the same time, and their accounts can be accepted), which is ultimately reflected in the TPS increase. This is called Layer1 expansion. In Ethereum, it refers to Casper + Sharding, which has now been combined into one (I have previously sent a technical translation to explain the principle of Sharding, interested readers can refer to it for their own reference, which will not be expanded here).

But there is another dimension of performance that cannot be ignored in practical applications, that is,"average processing time." Based on the analogy, in Ethereum, this dimension is equivalent to the single-core (single-threaded) processing power of this "world computer."

2. What is "Layer2 Extension of Blockchain"?

Let's assume that a business process based on an Ethereum smart contract takes 5 steps (transactions) to complete, that is, I have roughly a smart contract that has 6 states: initial state, state 1,..., State 4, final state. Then it takes at least five blocks to complete the process (from initial state to state 1, transaction 1 is required to complete, and so on, at least five transactions are required to change state to final state).

Obviously, in this example, the bottleneck of blockchain performance becomes "block time." (This is because a smart contract is essentially a customizable state machine. If it has six states that change in one direction, it must change five times to reach the final state, so five transactions are necessary.) The block time is specified by the public chain protocol, such as 10 minutes in Bitcoin and about 16 seconds in Ethereum, which cannot be simply reduced; the 5 block time of the whole process is the most optimistic estimate, that is, the performance limit. So how can we shorten the execution time of this process and reduce the "average processing time"?

This is what the so-called blockchain Layer2 extension addresses. The answer is-off-chain.

The idea of this off-chain solution is that we can take business processing such as calculations and transactions outside the main chain to execute, only reflecting the final result on the main chain, and the intermediate process is not recorded in the main chain.

In this way, in the above example, the states we want to save on the main chain are the initial state and the final state. We can ignore the four state changes in the intermediate process, and the corresponding four transactions can be taken "out of the chain" to execute. Because off-chain solutions usually have very high processing performance (I will explain the principle of technical solutions in detail later), it is very likely that these four transactions will be processed within one block time of the main chain and the results will be sent back to the main chain (i.e. to the final state); thus, from the result point of view, the entire processing process is completed after only one block time (i.e. the confirmation transaction of the final state).

Obviously, the more complex the process, the greater the performance improvement; for example, some applications with high interactive performance requirements-games. In addition, for the payment scenario, because of the relatively high transaction fees, those high-frequency small transactions are obviously too expensive economically. Therefore, in both payment and contract application scenarios, there is a strong demand for Layer2 extensions.

3. Technical solution for Layer2 expansion

The general idea of the Off-chain scheme is similar: first, you need to take part of the "state" on the main chain to the outside of the chain, which can be stored locally (based on a certain client) or temporarily; then do specific operations outside the chain, such as transfer or other processing that will affect the "state"; when the processing is completed or reaches the time point where synchronization of the "state" is required, the final state is transmitted back to the main chain for storage.

The off-chain technical solutions that have been established at present can be roughly divided into two categories:

State Channel: represented by Bitcoin's Lightning Network [1] and Ethereum's Raiden Network [2]

Side-Chain: represented by Ethereum's Plasma [3] protocol

Let's first look at the "state channel."

The state channel is a temporary point-to-point Value transfer channel (between two participants in the transaction): When opened, a certain balance is usually locked on the main chain, and an effective time is set, and can be closed by any participant actively, that is, the participants will exchange data and transfer value (digital asset transfer) based on a specific technical agreement; Then when the network can be accessed, a certain agreed time point is reached, or a party actively synchronizes data to the main chain, the final result will be submitted to the main chain.

The status channel mainly solves the problem of excessive handling fees in scenarios such as high frequency and small payment mentioned above, but its limitations are also obvious:

First of all, it is a temporary pathway, and the data is not stored permanently, but is kept locally by both parties themselves; if one of the participants 'equipment fails, the loss is almost inevitable (although the absolute economic loss is probably not too high).

Second, a state channel can only support value transfer between two users; when there are a large number of state channels between users in the system at the same time, a channel network is actually formed: when two users in the network have transaction needs, they do not simply create a new channel between their two points, but use a specific routing algorithm to find out whether there is an available path, and then decide how to create a data channel between them; But this in itself increases the difficulty of implementation and the corresponding technical risks.

State channel network diagram (taken from Raiden Network website)

The diagram above shows a state channel network diagram. We can see that if A wants to transfer money to C, it can be done by A -> B -> C.(The path A -> B -> E -> D -> C can also be done, but this usually requires more network traffic, so it is not preferred); if D wants to transfer money to F, it can be done via D -> E -> B -> A -> F or D -> C -> B -> A -> F. So theoretically, if there is a channel between a node and any node in the state channel network, then there is no need to create a new channel, but the corresponding path can be found through the routing algorithm to complete the value transfer.

Of course, the state channel itself is designed to handle micropayment scenarios, so these limitations are acceptable; even if there is an irrecoverable failure, the actual economic loss is not too large. But the technology itself clearly limits the versatility and data capacity of scaling.

Thus, the so-called "side-chain" scheme, which can store permanently, accommodate more transactions, and have independent address space, was born.

The side chain can be considered as a branch of the main chain, a sub-block chain that can be independently bookkept and grown, so there will also be bookkeepers (miners), permanent storage mechanisms and consensus algorithms (because it is usually multiple nodes that implement the side chain protocol that participate in side chain bookkeeping).

4. Brief introduction of side chain scheme

Below, I will briefly introduce the implementation scheme of sidechain based on the idea of Plasma protocol of Ethereum.

As for the side chain, we can abstract its interaction with the main chain into several "State Transition": when the side chain is generated, several "states" need to be transferred to the "creation block" of the side chain as the "initial state" of the side chain; In the process of side chain evolution, it is necessary to record the state change of the side chain regularly in the main chain, so that the corresponding state can be restored in case of dispute or when a user wants to "quit" the side chain.

From an application point of view, the main technical problem to be solved by side chains is how users "enter" side chains and how to "exit" side chains.

Since the side chain itself is a blockchain, the side chain can also have its own address space; when the main chain user "enters" the side chain, all or part of the "state" of the main chain user-such as account balance or digital assets held (ERC20 or ERC721 Token)-can be transferred to the side chain address through simple "address mapping."

Complex, of course, is the "exit" mechanism.

When a user A wants to "exit" from the sidechain, he should make a request to map his "state" changes in the sidechain back to the main chain. But because the user's state changes in the sidechain must occur because of interactions (transactions) with other users, this will also affect the "state" of other users. Thus, this requires a dispute period during which, if other users of the sidechain object to User A's exit status, they can initiate a "dispute," submit their own retained "status" data, and submit "technical proof."(Or request a conflict-free third-party certifier on the side chain to provide "technical proof," such as a miner or a data state proof provided by all nodes); the so-called "arbitration contract" on the main chain can automatically determine whose state change is "legal" based on "technical proof," so as to make the final state change on the main chain.

Here is only a minimalist description, the actual technical solution is more complex, limited to the length of the article, it will not be expanded.

Interested readers can read the Reference [3] for themselves. The Plasma protocol defines an implementation protocol for a subset (sidechain) that includes five core components:

An incentive layer contract designed to economically incentivize permanent storage of the sidechain itself

Tree-structured transaction data designed to minimize transaction and settlement costs

State transition fraud verification mechanism based on MapReduce computing framework in conjunction with the above two components

Consensus algorithms within certain side chains depending on the main chain

A bitmap-UTXO technical proof mechanism for state transition designed to minimize user exit cost

Obviously, because the side chain itself is a sub-block chain with permanent storage, miners are also required to keep accounts, so economic incentive mechanisms, consensus algorithms and data storage structure design similar to ordinary public chains are all things that must be considered. In the side chain, PoS, DPoS or other improved algorithms are usually used instead of PoW algorithm in order to achieve higher processing performance. At the same time, the punishment mechanism for fraudulent miners will be considered in the economic model of the sidechain itself.

In addition, because the side chain itself is also a block chain, it is theoretically feasible to create a side chain on top of the side chain. This is equivalent to providing a multi-layered, almost infinite expansion scheme.

It looks like a "perfect" solution; there is no such thing as a "perfect" solution, and there are still a lot of problems to be solved in Plasma. (See Chapter 11 of Ref. 3 for a discussion, which will not be expanded here.) This is also the direction that the community and related projects are working on.

5. Smart contracts on the side chain?

Since sidechains can provide high "performance," running smart contracts on sidechains is naturally a very attractive thing.

There is one item that must be mentioned here-Loom. Loom is a sidechain development framework that references Minimal Viable Plasma [4] and has released its SDK in June this year, using which we can quickly create our own sidechains as back-end support for our own Dapps. Although this framework is weak at the moment, it is an available option. Because it is also open source, so the specific implementation of the side chain also has a high reference value. In addition, Celer Project, a general blockchain Layer2 extension framework with a very ambitious vision, has its own innovations in the implementation of state channel networks. However, I am personally concerned about its support for side chains, which also needs to wait for subsequent engineering progress.

In Plasma, to simplify the verification of "state transitions," the data model for the side chain uses the UTXO model, while the verification of account balance changes naturally uses the so-called "Merklized Proof." But such designs also pose challenges to the smart contract execution framework on the side chain.

We know that smart contracts are essentially a "state machine," so there must be permanent storage to store their state data, which is similar to the design of "Storage Trie" in Ethereum. So if you run smart contracts on sidechains, you also need some kind of mechanism to preserve the state of the contract.

The main reason why Ethereum chose the account model over the UTXO model was the difficulty of implementing a state machine; obviously, a state machine based on an account model is easier to implement and has a clearer paradigm. So there is a lot to study and discuss about how to implement a smart contract runtime environment on a UTXO model-based sidechain. We can build a state verification mechanism based on the UTXO model. The problem is that if the account state (balance) change is not generated directly by the transaction, but by the contract code, then how to prove that the change is "legal" becomes the key to the verification mechanism when the side chain performs state transfer between the main chain and the main chain.

We certainly hope that more projects will come up with feasible and verifiable solutions in this regard, because this will have a profound impact on the continued development of side-chain technology.

After reading here, this article "What is the concept of Layer2 extension of blockchain" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use them yourself before you can understand them. If you want to know more articles related to content, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 204

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report