区块链同步技术,区块链数据同步原理
请查看相关英文文档
1. Blockchain synchronizes all users’ data to all users’ computers. True or false
True.
In layman's terms, Internet data can travel tens of thousands of kilometers and reach the computer users who need it. This is mainly because the Internet world has formed a unified information dissemination mechanism, so it is correct.
Blockchain is a chain composed of blocks one after another. Each block stores a certain amount of information, and they are connected into a chain in the order in which they were generated. This chain is saved in all servers. As long as one server in the entire system can work, the entire blockchain is safe.
2. What exactly is the blockchain?
The blockchain is a special network ledger. The core of blockchain technology is digital encryption. As early as 1991, a group of young people invented a new encryption technology that mutually verifies each other in order to prevent the date of electronic documents from being tampered with. They use cryptography to concatenate and protect concatenated text records (also known as blocks) of content.
The unit in which blockchain stores data is a block, and each block is strictly queued in order to form a "chain". If someone wants to change the content of a certain block, the unique characteristics of the block will also change accordingly, and subsequent blocks will immediately reject it, and this "fake" block will have to be detached from the chain.
(2) Blockchain reading and writing synchronization extended reading
Users around the world can connect their servers to In the blockchain network, it becomes an independent node in this distributed database storage system. Once joined, the node has the same rights and obligations as all other nodes.
Thus, people who provide services on the blockchain can perform read and write operations on any node in the system. All nodes around the world will complete synchronization again and again according to a certain mechanism, so that the data of all nodes in the blockchain network is completely consistent.
It is precisely because of the two characteristics of immutability and decentralization. Blockchain has well solved the trust problem that is a headache in modern business society. It has already emerged in social fields such as financial services, Internet of Things, public services, social welfare and supply chain management.
3. Briefly explain what is blockchain
Blockchain is a database storage system distributed around the world that can operate collaboratively.
Different from traditional database operations where read and write permissions are in the hands of a company or a centralized authority (centralized characteristics), blockchain believes that anyone with the ability to set up a server can participate.
Nuggets from all over the world have deployed their own servers locally and connected to the blockchain network to become a node in this distributed database storage system; once added, the node enjoys the same All other nodes have exactly the same rights and obligations (decentralized and distributed characteristics). At the same time, for those who develop services on the blockchain, they can enter this systemAny node performs read and write operations. Finally, all nodes in the world will complete synchronization one after another according to a certain mechanism, thereby achieving complete consistency of data in all nodes in the blockchain network.
Extended informationBlockchain is the underlying technology of Bitcoin. It is like a database ledger that records all transaction records. This technology has gradually attracted the attention of the banking and financial industries because of its safety and convenience.
On March 31, 2018, "Blockchain Technology Principles and Development Practice" was officially introduced into university lectures, and the first course was held at the South Campus of Xi'an University of Electronic Science and Technology.
In April 2018, a group of scholars from Oxford University announced the establishment of the world’s first blockchain university, Woolf University. On May 29, a new blockchain function was launched on the network to ensure that entry editing is fair and transparent.
4. How to set up the computer to synchronize network node block links quickly
The solution is as follows:
1. Regularly clean the dust in the computer and shut it down. Open the case and use a hair dryer to blow cold air!
2. Use 360 Defender, Kingsoft Defender and other tools to clean up system junk and temporary files generated online, and detect and kill malicious software
2.
3. The computer configuration is poor, try to set the virtual memory as large as possible, and install anti-virus software that takes up less resources, such as nod32, or only install an auxiliary anti-virus software.
4. Try to set the IP to a static IP, which can reduce the computer startup time.
5. Don’t put too many files and icons on the computer desktop, which will slow down the computer’s response. Try not to install software on the C drive.
6. Defragment the disk regularly. Open the My Computer drive where you want to defragment the disk - Properties - Tools - select the disk to be defragmented and open the "Disk Defragmenter" "Window - Analysis - Defragmentation - the system will start defragmenting
.
5. [Ethereum source code analysis][p2p network 07]: Synchronization of blocks and transactions
Synchronization is the synchronization of blockchain data. There are two synchronization methods. One is to synchronize the local blockchain with the blockchain of the remote node, and the other is to evenly synchronize transactions to adjacent nodes.
01. Synchronize the blockchain
02. Synchronize transactions
03. Summary
Go pm.syncer() coroutine in ProtocolManager protocol management .
First start the fetcher, which is used to assist in synchronizing blocks. Then wait for different events to trigger different synchronization methods.
Synchronous procedure call pm.synchronise method.
The go pm.txsyncLoop() coroutine in ProtocolManager protocol management.
Synchronous transaction loop txsyncLoop is divided into three parts:
Function to send transactions.
Pick a function.
Three cases of listening coroutines.
6. Tutorials for getting started with blockchain
However, there are very few simple and easy-to-understand introductory articles. What exactly blockchain is and what makes it special is rarely explained.
Next, I will try to write a best-understood blockchain tutorial. After all, it is not difficult. The core concept is very simple and can be explained clearly in a few sentences. I hope that after reading this article, you will not only understand the blockchain, but also understand what mining is, why mining is getting more and more difficult, and other issues.
It should be noted that I am not an expert in this area. Although I have been paying attention to it for a long time, my detailed understanding of blockchain started at the beginning of this year. You are welcome to correct any errors or inaccuracies in the article.
1. The essence of blockchain
What is blockchain? In a word, it is a special distributed database.
First of all, the main function of blockchain is to store information. Any information that needs to be saved can be written to the blockchain and read from it, so it is a database.
Secondly, anyone can set up a server, join the blockchain network, and become a node. In the world of blockchain, there is no central node. Every node is equal and stores the entire database. You can write/read data to any node, because all nodes will eventually be synchronized to ensure that the blockchain is consistent.
2. The biggest features of blockchain
Distributed databases are not a new invention, and there have been such products on the market for a long time. However, blockchain has a revolutionary feature.
Blockchain has no administrator, it is completely centerless. Other databases have administrators, but blockchain does not. If one wanted to add auditing to the blockchain, it would not be possible because it is designed to prevent the emergence of a central authority.
It is precisely because it is unmanageable that blockchain can be uncontrollable. Otherwise, once big companies and large groups control the management, they will control the entire platform, and other users will have to take orders from them.
However, without an administrator, everyone can write data into it. How can we ensure that the data is trustworthy? What if it is modified by a bad person? Please read on, this is the wonderful thing about blockchain place.
3. Block
Blockchain is composed of blocks. Blocks are much like database records. Every time data is written, a block is created.
Each block contains two parts.
Block header (Head): Record the characteristic values of the current block
Body: Actual data
The block header contains multiple characteristic values of the current block.
Generation time
Hash of the actual data (i.e. block body)
Hash of the previous block
...
Here, you need to understand what a hash is , which is necessary to understand blockchain.
The so-called hashing means that the computer can calculate a characteristic value of the same length for any content. The hash length of the blockchain is 256 bits, which means that no matter what the original content is, a 256-bit binary number will be calculated in the end. And it can be guaranteed that as long as the original content is different, the corresponding hash must be different.
For example, the hash of the string 123 is (hexadecimal), which is 256 bits when converted to binary, and only 123 can get this hash. (Theoretically, it is possible for other strings to get this hash, but the probability is extremely low and can be approximated as impossible.)
Therefore, there are two important inferences.
Corollary 1: The hash of each block is different, and the block can be identified by the hash.
Corollary 2: If the content of the block changes, its hash will definitely change.
4. The non-modifiable nature of Hash
Blocks and hashes have a one-to-one correspondence, and the hash of each block is calculated based on the block header (Head). That is to say, the characteristic values of the block header are connected together in order to form a very long string, and then the hash is calculated on this string.
Hash = SHA256 (block header)
The above is the calculation formula of block hash. SHA256 is the hash algorithm of the blockchain. Note that this formula only contains the block header and not the block body. In other words, the hash is uniquely determined by the block header.
As mentioned before, the block header contains a lot of content, including the hash of the current block body. , and the hash of the previous block. This means that if the content of the current block body changes, or the hash of the previous block changes, it will definitely cause the hash of the current block to change.
This point has great significance for blockchain. If someone modifies a block, the hash of the block changes. In order for subsequent blocks to still be connected to it (because the next block contains the hash of the previous block), the person must modify all subsequent blocks in sequence, otherwise the modified block will be removed from the blockchain . Due to the reasons mentioned later, hash calculation is very time-consuming, and it is almost impossible to modify multiple blocks in a short period of time, unless someone controls more than 51% of the computing power of the entire network.
It is through this linkage mechanism that the blockchain ensures its own reliability. Once the data is written, it cannot be tampered with. This is just like history, what happened happened, and it can’t be changed from now on.
Each block is connected to the previous block, which is where the name blockchain comes from.
5. Mining
Since synchronization between nodes must be guaranteed, new blocksThe adding speed should not be too fast. Just imagine, you have just synchronized a block and are preparing to generate the next block based on it, but at this time, another node generates a new block, and you have to give up half of the calculations and synchronize again. Because each block can only be followed by one block, you can only generate the next block after the latest block. So, you have no choice but to sync as soon as you hear the signal.
So, the inventor of the blockchain, Satoshi Nakamoto (this is a pseudonym, and his true identity is still unknown) deliberately made it difficult to add new blocks. His design is that on average, the entire network can generate a new block every 10 minutes, which is only six per hour.
This output speed is not achieved through commands, but by deliberately setting up massive calculations. In other words, only through an extremely large amount of calculations can the effective hash of the current block be obtained and the new block added to the blockchain. Because the amount of calculation is too large, it cannot be done quickly.
This process is called mining, because the difficulty of calculating a valid hash is like finding a grain of sand that meets the conditions among the sand in the world. The machine that calculates hashes is called a mining machine, and the person who operates the mining machine is called a miner.
6. Difficulty coefficient
After reading this, you may have a question. People say that mining is difficult, but isn’t mining just about using a computer to calculate a hash? This is the strength of computers. How could it be? It becomes very difficult, why can’t it be calculated?
It turns out that not just any hash can be used, only hashes that meet the conditions will be accepted by the blockchain. This condition is particularly harsh, causing most hashes to fail to meet the requirements and must be recalculated.
It turns out that the block header contains a difficulty coefficient (difficulty), which determines the difficulty of calculating the hash. For example, the difficulty coefficient of the 100,000th block is 14484.16236122.
The blockchain protocol stipulates that the target value (target) can be obtained by dividing the difficulty coefficient by a constant. Obviously, the greater the difficulty coefficient, the smaller the target value.
The validity of the hash is closely related to the target value. Only hashes smaller than the target value are valid, otherwise the hash is invalid and must be recalculated. Since the target value is very small, the chance that the hash is smaller than this value is extremely slim, and it may be calculated 1 billion times before it is considered a hit. This is the fundamental reason why mining is so slow.
As mentioned earlier, the hash of the current block is uniquely determined by the block header. If the hash of the same block needs to be calculated repeatedly, it means that the block header must keep changing, otherwise it is impossible to calculate different hashes. All feature values in the block header are fixed. In order to make the block header change, Satoshi Nakamoto deliberately added a random item called Nonce.
Nonce is a random value. The role of the miner is actually to guess the value of Nonce so that the hash of the block header can be smaller than the target value so that it can be written to the blockchain. Nonce is very difficult to guess. At present, we can only use trial and error one by one through exhaustive methods.According to the protocol, Nonce is a 32-bit binary value, which can reach a maximum of 2.147 billion. The Nonce value of the 100,000th block is 274148111. It can be understood that the miner started from 0 and calculated 274 million times before obtaining a valid Nonce value so that the calculated hash can meet the conditions.
If you are lucky, you may find Nonce in a while. If you are unlucky, you may have calculated it 2.147 billion times without finding the Nonce, that is, it is impossible to calculate a hash that meets the conditions for the current block body. At this time, the protocol allows miners to change the block body and start a new calculation.
7. Dynamic adjustment of difficulty coefficient
As mentioned in the previous section, mining is random, and there is no guarantee that a block will be produced in exactly ten minutes. Sometimes it can be calculated in one minute, and sometimes it may take several hours. No result. Overall, with the improvement of hardware equipment and the increase in the number of mining machines, the computing speed will definitely become faster and faster.
In order to keep the output rate constant at ten minutes, Satoshi Nakamoto also designed a dynamic adjustment mechanism for the difficulty coefficient. He stipulated that the difficulty factor should be adjusted every two weeks (2016 blocks). If the average block generation speed in these two weeks is 9 minutes, it means that it is 10% faster than the legal speed, so the next difficulty factor will be increased by 10%; if the average block generation speed is 11 minutes, it means It is 10% slower than the legal speed, so the difficulty factor of the next step must be lowered by 10%.
The difficulty coefficient is adjusted higher and higher (the target value is getting smaller and smaller), which makes mining more and more difficult.
8. Forks of the blockchain
Even if the blockchain is reliable, there is still an unresolved problem: if two people write data to the blockchain at the same time, that is to say, two people write data to the blockchain at the same time. Blocks join because they are connected to the previous block, forming a fork. Which block should be adopted at this time?
The current rule is that new nodes always adopt the longest blockchain. If there is a fork in the blockchain, it will look at which branch is behind the fork to reach 6 new blocks first (called six confirmations). Based on a block calculation of 10 minutes, it can be confirmed in one hour.
Since the generation speed of new blocks is determined by computing power, this rule means that the branch with the most computing power is the authentic blockchain.
9. Summary
Blockchain, as an unmanaged distributed database, has been running for 8 years since 2009 without major problems. This proves it works.
However, in order to ensure the reliability of data, blockchain also has its own price. The first is efficiency. You have to wait at least ten minutes to write data to the blockchain. All nodes synchronize the data, which requires more time. The second is energy consumption. The generation of blocks requires miners to perform countless meaningless calculations. This is Very energy consuming.
Therefore, the applicable scenarios of blockchain are actually very limited.
There is no governing authority that all members trust
The data written does notRequires real-time use
The benefits of mining can make up for its own costs
If the above conditions cannot be met, then the traditional database is a better solution.
Currently, the largest application scenario (and possibly the only application scenario) of blockchain is the cryptocurrency represented by Bitcoin.
7. What is the concept of blockchain? Read it in three minutes!
On October 25, 2019, Xinwen Broadcast sent a very important signal: the country must vigorously develop blockchain. After that, blockchain has become an Internet celebrity, and the figure of "blockchain" is floating in the streets and alleys. In fact, many technology companies have already deployed blockchain technology.
Although blockchain is very popular, many people do not know much about blockchain.
What is blockchain?
Let’s first take a look at how Du Niang explained it. Network display: Blockchain is a new application model of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, and encryption algorithms.
Why is blockchain called blockchain?
The blockchain is linked by blocks one by one, and the blocks are storage units one by one, which record the communication information of each block node. The blocks are much like the records of the database. Writing data every time creates a block. With the expansion of information exchange, one block continues with another, and the result is called a blockchain.
What are the characteristics of blockchain?
Blockchain mainly has the following characteristics:
1. Decentralization: In the blockchain system, every node has equal rights. and obligations, there is no central control here. Decentralization has well established trust relationships with each other. Although there is no central management organization, people can collaborate with each other and trust each other. This mainly applies blockchain distributed ledger technology.
2. Openness: Blockchain data is open to everyone. Except for some encrypted information that is not open, everyone can check the data here.
3. Independence: The entire blockchain system does not rely on other third parties. All nodes can automatically and securely verify and exchange data within the system without any human intervention.
4. Security: Blockchain has a certain degree of security and cannot be tampered with. Because everyone in the blockchain system has the same ledger, if someone wants to tamper with it, it is possible to forge a non-existent record only if they control more than 51% of the accounting nodes. Of course, this is basically impossible. This is mainly due to the core technology of blockchain: consensus mechanism. The consensus mechanism has the characteristics of "the minority obeys the majority" and "everyone is equal".
5. Anonymity: Many people think that if the blockchain is so open and transparent, will we lose privacy? In fact, no, although the transaction information in the blockchain is open and transparent, the identity information of the account is encrypted and can only be accessed with authorization.
Now let me tell you a story to help you better understand the blockchain.
There are three people in the family, mom, dad, older brother and younger brother. Last year, my father was in charge of the family's account books. He was responsible for all the family's income and expenses alone.
However, on the day of Double Eleven, my mother, who has always been frugal, wanted to buy herself a beautiful piece of clothing on a certain online store. When she checked the account book, she found something was wrong. It stands to reason that except for some money deposited in banks and financial management, the whereabouts of the daily consumption money at home are all in this account book, but no matter how you look at it, it is wrong. Some consumption is clearly not recorded, but is recorded.
Later, my father took the initiative to confess that he couldn’t help but buy a pack of cigarettes.
Later, my mother changed her strategy and the whole family kept accounts. Everyone recorded their monthly consumption expenditure in their own account books. Whenever there was a transaction or consumption at home, my mother would shout, "Book it," and everyone would record the transaction in their own books. This is the decentralized accounting model, where everyone is the center and everyone has a ledger.
The previous accounting model for dad was centralized accounting. If dad wanted to do something alone, it would be difficult for anyone to see it. The decentralized accounting model has solved the problem of centralization very well. The disadvantage of bookkeeping is that it is very difficult for dad to tamper with the books.
For example, if dad wants to take some money from the ledger and secretly buy cigarettes, the amount of money is limited, and if he wants to take the money, he has to change the ledger, but he only tampered with his own ledger. No, he had to change the accounts of three people including himself. And this is undoubtedly more difficult than reaching the sky.
So, many times my father had the idea of smoking, but he had no choice but to give up the idea due to the current situation.
Are blockchain and Bitcoin the same thing?
In fact, blockchain and Bitcoin are not the same thing. It is just the underlying technology of Bitcoin. Bitcoin is the first digital currency applied by blockchain.
In 2008, Satoshi Nakamoto first proposed the concept of blockchain. In the following years, it became a core component of the electronic currency Bitcoin, serving as a public account book for all transactions. Blockchain was first applied to Bitcoin.
The origin of blockchain is to solve the problem of trust, and one of the most successful applications of blockchain is digital currency. Bitcoin is arguably the most successful application of blockchain so far.
What are the applications of blockchain?
The application of blockchain is actually very wide. In addition to digital currency, the future applications of Bitcoin are still very extensive. Blockchain technology has been widely used in different industries. Such as product traceability, copyright protection and transactions, payment and settlement, Internet of Things, digital marketing, medical care, etc., promoting different industries to quickly enter the "blockchain+" era.
1. Payment and clearing: Blockchain can abandon the role of transit banks, realize point-to-point payment, reduce transit fees, and accelerate fund utilization.
2. Product traceability: For example, if we buy a piece of clothing on a certain store, we can see the past and present life of this piece of clothing.
3. Securities trading: Traditional securities trading requires the coordination of four major institutions, which is inefficient and costly. Blockchain technology can independently complete one-stop services.
4. Supply chain: Introducing blockchain technology into the supply chain system, synchronizing information within the system can control all links, better complete division of labor and collaboration, and facilitate subsequent accountability.
5. Intellectual property rights: With copyright on the chain, our photographic works, musical works, literary works, etc. will become our information, and the ownership of the information will be confirmed and become our property.