In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to understand the Dapp back-end architecture". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to understand the Dapp back-end architecture".
1. Decentralized programs and block chains
Although blockchain faces many adoption and regulatory difficulties, it is a permanent technology no matter which algorithm is used, no matter which algorithm is used, whether it is block chain, hash chart, speed or any other distributed ledger technology.
The main value of blockchain and other similar technologies can be summarized as follows: they enable people to write and run programs that cannot actually be changed after they are created or tampered with during execution. In other words, these programs always run as designed, and neither side can influence their behavior. If we think of them as programs that define how coins are transferred back and forth, this definition is valid for many cryptocurrencies that exist today. This also explains why cryptocurrencies and multiple tokens have real value: they cannot be generated out of thin air through a defined "underlying program".
Contrary to Bitcoin, ethernet / EOS / Tron / … The platform implements a more complex program layer, which in turn implements the execution environment, allowing anyone to write their own decentralized programs on top of the platform. User-defined programs always run as designed, without any exceptions, and the platform ensures its security.
two。 Decentralized application
These secure and immutable programs that run on distributed networks, combined with traditional front-end and back-end technologies, are today called distributed applications (DApps). Through some of them can be semi-centralized, most of the activities in truly decentralized applications should take place under central control.
If someone asked me to draw the way DApps works today, I might draw this picture.
Imagine what we call a decentralized application today, taking any existing centralized Web resource such as _ YouTube_ or _ instagram_ as an example, and imagine binding your "encrypted identity" to a Web / mobile resource instead of a centralized password-protected account.
This is what the e-wallet software provides for you. The private key of this identity (secret, which you can operate on behalf of) is stored on the local device and will never be online, so no one can control this identity. With this identity, you can use the site as an access point and / or a graphical user interface in two different sets of operations (controlled by a central authority) and dispersed (which is different from the traditional WWW network, with the goal of eliminating the central authority). The whole point of this "password identity" is that your operation is protected by a password, and no one can change the content or signature of your signature.
Today, the computing and storage capacity of fault-tolerant distributed networks, such as Ethernet Square, EOS or Tron, is limited. If they are extensible, we can use a distributed network to store the entire distributed application, including its graphical user interface, data, and business logic. In this case, we call these applications truly distributed / distributed applications.
However, since these networks are currently not scalable, we have combined different approaches to achieve the maximum level of fragmentation for our applications. We know that there is no development in the "traditional" back end.
For example:
We use the back end to host the front end of the distributed application.
We use the back end to integrate with any other existing technologies and services. Real world-class applications cannot live in isolation.
We use the back end to store and process anything that can spread out the network (especially the blockchain). In fact, the entire application and its business logic are stored somewhere in the world, excluding only the blockchain portion. Not to mention, IPFS and similar storage tiers don't guarantee the accessibility of files, so we can't rely on them without hosting files ourselves. In other words, a dedicated running server is always required.
So far, secure and partially distributed applications cannot be built without a reliable back end, and the focus of this article is to explain how to do this correctly.
3. (decentralization) and tokens
Coincidentally, almost all distributed applications today are built around so-called tokens, which are cryptocurrencies that drive customization (or just simple cloning) of specific distributed applications. A token is just a programmable currency or asset, that's all.
Token intelligence contracts determine how users transmit tokens, and application intelligence contracts can extend everything that is missing in token intelligence contracts. Both types of smart contracts run on decentralized networks, and tokens are usually "smart contracts" written on decentralized platforms such as Ethernet Fong. By having some tokens, you can basically get different services on Web resources or mobile applications and replace that token with something else. The key point here is that the token itself exists and is not under the control of the central authority.
There are many examples of applications built around tokens: from many collectable games such as CryptoKitties (ERC721 tokens) to service-oriented applications such as LOOM Network, even browsers such as Brave and gaming platforms such as DreamTeam (ERC20-compatible tokens). Developers determine and decide for themselves how much control they will (or will not) have over their applications. They can build the business logic of the entire application based on smart contracts (as CryptoKitties does), or they can centralize all the content on the server without using smart contracts at all. But the best way is to be in the middle.
4. The back end of the distributed network
From a technical point of view, there must be a bridge to connect tokens and other smart contracts to Web / mobile applications.
In today's completely decentralized applications, clients interact directly with smart contracts, and this bridge is reduced to the JSON RPC API function of node pools such as public API or Infura, because not every device can run and support its own separate network nodes. However, this API provides only a basic and very narrow set of functions that only allow simple queries or efficient aggregation of data. As a result, a custom backend will eventually be introduced, making the application semi-centralized.
The entire interaction with the distributed network can be reduced to one or two points, depending on the needs of the application:
Hongmeng official Strategic Cooperation to build HarmonyOS Technology Community
Listen for network events (such as token transmission) / read network status.
Publish the deal (invoke the status change intelligent contract feature, such as token transfer).
The implementation of both aspects is tricky, especially if we want to build a secure and reliable back-end solution. Here are the main points we want to break down:
First of all, in Ethernet Square, event retrieval is not out of the box. Due to a variety of reasons: network nodes may fail to extract a large number of events, events may disappear or change due to network derivation, and so on. We must build an abstraction layer to synchronize events in the network and ensure their reliable delivery.
Like deal launches, we must abstract the low-end content of Ethernet Fong, such as random counters and natural gas estimates, as well as transaction rereleases to provide a reliable and stable interface. In addition, transactional publishing means using a private key, which requires advanced back-end security.
It's clear. We will take it seriously and face the problem that there is no guarantee that the private key will never be compromised at the back end. Fortunately, there is a way to design decentralized applications that do not even require a high degree of protection for back-end accounts.
In our practice, all of this enabled us to create a powerful back-end solution for Ethernet Fong, which we named Ethereum Gateway. It abstracts other microservices from the fun of ethernet and provides a reliable API to use it.
The back-end monitoring of Tai Fong. The activity demonstrated by the monitor is mainly related to our round robin billing function (although you can see a peak every hour).
5. Distributed application architecture
This section is highly dependent on the needs of specific decentralized applications, and we will try to sort out some basic interaction patterns based on building these applications (D platform = decentralized platform = Ethernet Square / EOS / Tron / Whatever):
Customer platform: completely distributed applications.
Clients (browsers or mobile applications) talk directly to distributed platforms with the help of ethernet "wallet" software (such as Metamask,Trust) or hardware wallets (such as Trezor or Ledger). Examples of building DApp in this way include CryptoKitties,Loom 's Delegated Call, encrypted wallet itself (Metamask,Trust,Tron Wallet, etc.), decentralized encrypted exchanges (such as Etherdelta), and so on.
Platform D? Customer? Back-end? d platform: centralized or semi-centralized applications.
The interaction between clients and distributed platforms and servers has little in common. A good example is any (centralized) cryptocurrency exchange today, such as BitFinex or Poloniex: the currency you trade on the exchange is only recorded in a traditional database. You can recharge the database balance by sending the asset to a specific address ("platform? client"), and then withdraw the asset after performing some actions in the application (background? d platform), but everything you do depends on the "application" itself (the client? The back end) does not mean that you interact directly with the D platform.
Another example is Etherscan.io, which uses a semi-centralized approach: you can perform all useful decentralization operations in it, but without their integrated back end, the application itself doesn't make any sense (Etherscan continuously synchronizes transactions, parses data, stores it, and ultimately provides comprehensive API / UI).
Content in between: static, centralized or semi-centralized applications.
Combined with the above methods. For example, we can have an application that provides a variety of services in exchange for encryption so that you can log in and sign the information using your encrypted identity.
It is hoped that the interaction mode of completely distributed applications (client-side Client platform) will not cause any problems. With amazing services such as Infura or Trongrid, you can simply build applications that don't need a server at all. Like almost all client libraries Ethers.js for vengeance or Web for Tron can connect to these public services and communicate with the network. However, for more complex queries and tasks, you may still need to assign your own server.
The rest of the interaction patterns involving the back end make things more interesting and complicated. To picture all of this, let's imagine how the back end reacts to certain events in the network. For example, users post a quota transaction that allows us to charge them a fee. To charge a fee, we must publish a fee transaction for the quota event issued:
Sample process of server response to user actions in a decentralized network from a back-end point of view, the following occurs:
We monitor specific network events by constantly polling the network.
After receiving the event, we will execute some business logic and then decide to issue a transaction in response.
Before we release the deal, we need to make sure that it will be exploited (in Ethernet Square, successful trading gas estimates mean that there are no errors relative to the current state of the network). However, there is no guarantee that the deal will be successfully exploited.
Using the private key, we sign and publish the transaction. In Ethernet Square, we must also determine the natural gas price and natural gas quota for the transaction.
After the deal is released, we will continuously poll the network to understand its status.
If it takes too long and we cannot get the status of the deal, we must republish it or trigger a "failure condition". Transactions may be lost for a variety of reasons: network congestion, peer drop, increased network load, and so on. In Ethernet Square, you can also consider re-signing the deal at different (actual) gasoline prices.
After we finalize the transaction, we can perform more business logic if necessary. For example, we can inform other back-end services about the fact that the transaction has been completed. In addition, consider waiting for confirmation several times before making a final decision on the deal: the network is distributed, so the results may change in a few seconds.
As you can see, a lot of things have happened! However, your application may not need some of these steps, depending on what you want to achieve. However, building a strong and stable backend needs to solve all of the above problems. Let's break it down.
6. Distributed application backend
Here, I would like to emphasize some of the main points that arise most of the problems, namely:
Listen for network events and read data from the network
Publish transactions and how to conduct transactions securely
7. Listen to network events
In ethernet and other decentralized networks, the concept of intelligent contract events (or event logs, or just logs) allows out-of-chain applications to understand what is going on in the blockchain. These events can be created by smart contract developers anywhere in the smart contract code.
For example, in the well-known ERC20 token standard, each token transfer must log a Transfer event so that the application under the chain knows that a token transfer has occurred. By "listening" for these events, we can perform any (re) operation. For example, when a token is transferred to your address, some mobile encrypted wallets send you a push / email notification.
In fact, there is no reliable solution to monitor network events out of the box. Different libraries allow you to track / listen for events, but in many cases something can go wrong, resulting in events being lost or unhandled. To avoid missing events, we must build a custom backend that maintains the event synchronization process.
Depending on your needs, the implementation may vary. But here's a picture of how to build reliable ethernet event delivery options based on the microservice architecture:
The Taifang event will be reliably delivered to all back-end services, and these components work in the following ways:
The event synchronization back-end service constantly polls the network to try to retrieve new events. Once some new events are available, it sends them to the message bus. After the event is successfully submitted to the message bus, as far as the blockchain is concerned, we can save the block of the previous event so that we can request a new event from that block next time. Keep in mind that retrieving too many events at a time can cause requests to always fail, so you must limit the number of events / blocks requested from the network.
A message bus, such as Rabbit MQ, routes events to each queue set up separately for each back-end service. Before the event is published, the event synchronization back-end service specifies the routing key (for example, smart contract address + event topic), while the consumer (other back-end services) creates a queue that subscribes only to specific events.
As a result, each back-end service gets only those events that are needed. In addition, the message bus ensures that all events are published to the event bus before they are delivered.
Of course, you can use other ways to replace the message bus: HTTP callbacks, sockets, and so on. In this case, you need to figure out how to make sure you provide callbacks: manage the index / custom callback retry and implement custom monitoring.
8. Publish deal
In order to publish the transaction to the distributed network, we must perform several steps:
Prepare to make a deal. Along with the transaction data, this step means requesting the network status to find out whether the transaction is valid and whether it will be exploited (gas estimate in Ethernet Square) and the serial number of the transaction (nonce in Ethernet Square). Some libraries try to do this in the background, but these steps are important.
Sign the deal. This step implies the use of the private key. Most likely, you will embed a custom private key assembly solution here.
Publish and republish transactions. One of the key points here is that your published deals always have the opportunity to be lost or lost from a distributed network. For example, in Ethernet Square, if the price of natural gas on the network rises suddenly, published deals may be discarded. In this case, you must republish the transaction. In addition, you may want to republish a transaction with other parameters (at least in the case of high gasoline prices) so that the transaction can take place as soon as possible. Therefore, if the replacement deal is not pre-signed (using different parameters), republishing the deal may mean re-signing it.
By using the above method, you can finally build something similar to what is shown in the following sequence diagram.
On this particular sequence diagram, I will demonstrate (in general!) How blockchain cycle billing works:
The user performs the function in the smart contract, which ultimately allows the back end to perform a successful fee transaction.
The back-end service responsible for specific tasks listens for fee limit events and publishes fee transactions.
Once a fee transaction is mined, the back-end service responsible for a specific task receives the event from the Ethernet Fong network and executes some logic (including setting the next charging date).
The general sequence diagram of the working principle of blockchain circular billing shows the back-end security and intelligent contract between the back-end service and the Ethernet Fong network.
Transactional publishing always involves the use of private keys. You may want to know if the private key can be protected. There are many complex policies and different types of software that make it very safe to store private keys on the back end. Some private key storage solutions use geographically distributed databases, while others even recommend special hardware. However, in any case, the place where a semi-centralized application is most vulnerable is where the private key is assembled and used to sign the transaction (or, in the case of special hardware, where the transaction signing process is triggered). Therefore, in theory, there is no 100% reliable solution to protect bulletproof from damaging the stored private key.
Thank you for reading, the above is the content of "how to understand the Dapp backend architecture". After the study of this article, I believe you have a deeper understanding of how to understand the Dapp backend architecture, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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: 222
*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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.