In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Author: Li Yanpeng, current Ant Financial Services Group senior technical expert, author of distributed Service Architecture: principle, Design and practice and Scalable Service Architecture: framework and Middleware. He once worked as the technical head and chief architect of large IT Internet companies such as eBao pay, Citibank, Oracle, Sina Weibo and Reuters, and now focuses on the R & D and promotion of blockchain platform. Good at large-scale and high concurrency of online and offline third-party payment platform architecture planning and implementation.
1 background
For the current popular electronic currency-Bitcoin system, there are many introductory articles in moments, and some people try to vividly explain the characteristics of Bitcoin through cartoons, but they always miss the point, and there are always some problems that are not clear. In order to figure out these problems, I have recently studied several Bitcoin books and Bitcoin papers published by Satoshi Nakamoto. I can't wait to share my understanding with you. I hope to discuss with you and make progress together.
2 Bitcoin
Bitcoin is an e-cash system implemented using peer-to-peer technology that allows one organization to make online payments directly with another without the need for an intermediate authoritative clearing house.
In the Bitcoin world, if you want to own Bitcoin, you need to apply for a Bitcoin address, just like when you deposit in a bank, you need to open an account, and then you have this account, and you have your own account, and you can deposit money to your account, and others can transfer money to your account, when you need to withdraw money or when you transfer money to someone else. You need to show a key that can open this address, that is, your private key, just like you need to provide a password when you withdraw money on ATM.
Unlike the legal tender issued by banks, the issuance of legal tender is uniformly managed by central banks, which are believed to be reliable, will not be misrecorded and will not be made by others. However, the issuance of Bitcoin does not require an authority such as the central bank, which allows a transaction to be settled directly from one organization to another, eliminating the link of settlement by the authority and improving the efficiency of transaction and settlement. It saves the cost of transactions, especially cross-border transactions.
How can a peer-to-peer online trading system ensure the anonymity, correctness and unusurability of transactions? And how to prevent double payment and cheating?
The following chapters will unravel the mystery of Bitcoin in the most popular language, so that you can logically understand how Bitcoin works, so that learning Bitcoin does not leave a corner, so that all aspects of Bitcoin are clearly presented in your mind.
3 Block chain 3.1 how is the block chain stored?
For a cash account system, the first thing to solve is how to keep the account, where to keep the account, how to store the account and so on. For example, if you deposit with the Bank of China, the Bank of China opens an account for you, your account is stored on the server of the Bank of China, and you deposit with the Construction Bank, and the Construction Bank opens an account for you. Your account is stored on the server of the Construction Bank. If you need to transfer money to the accounts of others in the same bank, you need to transfer and settle accounts for you through this bank. If you need to transfer money to other accounts of other banks, you need to transfer and settle accounts for you through UnionPay. Although an ordinary user is not aware of so many processes, these steps do exist, from which we can see that the accounting system is dedicated. It is centralized, owned and maintained by an organization, which is usually authoritative and reliable.
Bitcoin does not have a centralized accounting system, but records the ownership and transaction information of Bitcoin through a distributed block chain. Each Bitcoin participant has a copy of the same blockchain, which contains multiple blocks sorted over time, and the latter block points to the previous block through a hash pointer to form a chain, passing through the pointer from the top of the chain. you can always find the first block at the bottom, and the first block becomes the Genesis block. Each block records the hash value of the previous block, which is actually the hash value of the previous node head. if you want to change the transactions contained in a block, you must change all transactions after that block. since the generation of each block requires conditions and time, and the conditions are quite stringent (which will be detailed later in articles related to the consensus mechanism), once a block is generated, And it is accepted by the nodes of the block chain, and a certain number of blocks are generated after this node, so this block can not be tampered with.
The schematic diagram of the block chain is as follows:
As can be seen from the above figure, the block chain is composed of several blocks, each of which contains the meta-information of the block and a pointer to the hash value of the previous block. this pointer is the key information to prevent the block chain from being tampered with. The block contains bitcoin transaction information, and the first transaction is a special transaction, a reward for mining nodes, which is the only way to generate bitcoin, that is, to issue bitcoin. the rest of the transactions are money transfers, and bitcoin is paid from one address to another, which is the only way to transfer the value of bitcoin. To sum up, Bitcoin can only be issued and transferred. After it comes into being, Bitcoin can only be transferred from one person to another, but cannot disappear out of thin air. The total amount of Bitcoin issued is limited, a total of 21 million, so it is a deflationary currency. We will describe the deflationary characteristics of Bitcoin in detail in related articles later.
3.2 how does the owner of Bitcoin prove that he owns Bitcoin?
The previous section introduced the storage of blockchain, which is actually a bitcoin ledger, recording who owns how much bitcoin, but this ledger is kept on the Internet and distributed, not stored by a central institution or server. With the ledger, the remaining question is how can the owner of bitcoin prove that he owns bitcoin? It's like opening an account with a bank. When you want to transfer money to someone else, you need to insert a card into ATM and enter your password. The card is equivalent to the address of Bitcoin, and the password is the key of Bitcoin. With the correct address and key, you can claim ownership of Bitcoin and transfer it to someone else to make a transfer transaction.
Withdraw a sum of cash on ATM, enter the password to unlock the account, and we believe that the ATM will not reveal the password. So in the Bitcoin world, how do we use the private key to verify the ownership of Bitcoin on an address?
The ownership of Bitcoin is realized through the technology in the field of encryption. Let's first understand the principle of the field of encryption. Generally speaking, the field of encryption has gone through three stages. The first stage is to spell the algorithm. The encryption logic is written in a very deep code. Later, it was found that no matter how complex the logic was written in the code, there was always a master who could crack it. As a result, symmetric key encryption is generated. Symmetric key encryption encrypts data through a symmetric key, then transmits or saves it, and then decrypts and restores the original data through the same secret key when needed. The disadvantage is that the secret key is shared and cannot be securely saved, especially in cross-organizational scenarios. Later, clever security scientists invented asymmetric encryption algorithms, such as RSA, the asymmetric algorithm has a pair of secret keys, a public key and a private key, the private key can derive the public key, but the public key cannot derive the private key, the public key encrypted data private key can be decrypted, the private key encrypted data public key can be decrypted, if organization A transfers data to organization B, then organization A uses the public key to encrypt. Organization B uses the private key for decryption, so organization B needs to keep the private key carefully, while the public key is public, which is a typical asymmetric encryption scenario, which can effectively prevent data from being peeped and tampered with. There is another scenario of asymmetric encryption, that is, the signature is the reverse scenario of the encryption scenario. Merchant B encrypts the data through its own private key, and then passes the encrypted data to merchant A, and merchant A decrypts it through the public key. If the decrypted data is correct, it means that the data is sent by A, which effectively ensures that the data is tamper-proof. From these two scenarios, we can see that the public key is public. It can be sent to anyone, and the private key is private and can be used for decryption or signature.
The schematic diagram of the bitcoin proof of ownership is as follows:
As can be seen from the picture above, in real life, we use the key to open the lock, we use the password to extract cash on ATM, then in the Bitcoin system, we use the secret key to transfer Bitcoin to achieve the transfer of value.
More specifically, a bitcoin transaction locks a certain number of scripts at an address, declares that the user who owns the address will prove that he owns the address through the signature of the key, and then spends the bitcoin. The bitcoin will not disappear after it is spent, it will be locked on someone else's address, and others can spend it in the same way.
From the above process, we summarize two actions, locking and unlocking, which corresponds to our usual locking and unlocking, which is achieved through locking and unlocking scripts in the Bitcoin system.
The locking script associates Bitcoin with a Bitcoin address, proving that Bitcoin belongs to that address. The unlock script provides proof that the address belongs to me and the bitcoin belongs to me, which I can use to pay.
Let's give an example to illustrate in detail:
User Alice owns 10 bitcoins on address An in Bitcoin. Alice wants to make a deal with Bob. Bob sells his car to Alice,Alice and has to pay Bob 10 Bitcoins. Bob's Bitcoin address is B.
In the previous transaction, 10 bitcoins owned by Alice were locked on Alice's Bitcoin address A, which may come from mining or money transfers from others. We will describe how to obtain Bitcoin in detail later. Here we will only focus on the locking script that proves that Alice owns Bitcoin.
The logical format of the lock script is:
Bitcoin quantity source lock address 10 mining address A
If you want to spend this locking script, the unlocking script you need is as follows:
Unlock address unlock the public key of address An address A sign the hash value of the previous block header with the private key
The specific unlocking process is as follows:
Use the public key of address A to derive the address and compare it with address A. if it is consistent, it proves that the public key is provided correctly, and proceed to the next step. Use the public key of address A to decrypt the signature, and if the value obtained is the same as the hash value of the previous block, it proves that the unlock is successful and the 10 bitcoins on the address can be spent.
In fact, locking and unlocking scripts are implemented through stack-based scripts against Polish notation. Due to the limited space of this article, we will not introduce them here, and the principles and processes of locking and unlocking scripts will be described in detail in subsequent articles.
4. Digging ore
The previous section introduced Bitcoin's use of a distributed storage blockchain as an accounting system, as well as the process of claiming ownership of Bitcoin and paying it to others. Now we have a new problem: since the blockchain is a distributed accounting system and each participating node has a copy, who is responsible for recording a transaction to the blockchain?
This has to introduce a new concept, that is, the consensus mechanism. Bitcoin determines the bookkeeping right through the consensus mechanism of workload proof. generally speaking, whoever proves that he has the greatest workload will be responsible for bookkeeping.
The schematic diagram of the workload proof is as follows:
The amount of work is reflected by calculating the hash value of bitcoin blocks that meet a certain standard. The node trying to keep accounts is called the mining node. The mining node will verify the transactions sent on the network node (the network propagation mechanism will be introduced in the next section). After verification, it will be stored in the buffer to form a certain transaction storage structure (transactions are stored in Merkle trees, followed by various introductions), put them in the block, and then construct the block head according to the basic information of the block. The block header usually contains the hash value of the previous block, the Merkle root (described in more detail in a later article), a timestamp, a difficulty target, and a populated random value. The random value is randomly generated and filled, and the mining process is to find a random value that can fill the block, so that the hash value of the block accords with a certain standard, for example, the first bit of the hash value is 0. the difficulty target is used to express the difficulty coefficient of the hash value standard, and the difficulty value and the possibility of mining success can be calculated by probability algorithm.
Each mining machine on the network receives and verifies a batch of transactions, and then starts mining, and the view calculates the hash value of the block head that meets a certain difficulty value. if the calculation is successful, the mining is successful and the mining results are broadcast to the whole net. after verification by the nodes of the whole network, the block is connected to the top of the block and agreed across the network. The mining machine needs to test the random filling value repeatedly to solve the problem, which is generally used to generate random numbers, try to fill the generated random numbers into the block, and then calculate the hash. the mining machine alliance will introduce the mining machine alliance. The mining machine alliance will divide the random number into multiple cells and assign it to the members of the alliance to solve the problem together.
In addition to the workload proof mechanism described above, there are also rights and interests proof, joint-stock rights and interests proof consensus mechanism and so on. I will share with you later in the special article on the consensus mechanism.
5. P2P network
The first two sections introduce the account system and accounting mechanism of Bitcoin. in this section, we discuss how Bitcoin's distributed block chain ledger is transmitted over the network, and how transactions are transmitted and verified over the network.
The nodes in the Bitcoin network are all peer-to-peer, there is no centralized server, there are different types of nodes, and different types have different responsibilities. We will describe it in detail in future articles. Here we will only introduce the whole node, that is, the working mechanism of the Bitcoin core client.
In addition to storing the complete block chain, the full nodes in Bitcoin also have the roles of miners, wallets, routing nodes, and so on. Their responsibilities are as follows:
Miners: just like miners, they do manual work, constantly trying to fill in the random fields of the constructed blocks to find hash values that meet certain criteria, and if found, connect the block to the top of the block chain and send the legal block chain to the adjacent node. Wallet: the blockchain records creative currency transactions and transfer transactions, which is different from the usual account system, which records the account balance, while the blockchain records only transactions and no balance. The wallet is used to calculate the balance of blocks owned by an address from the blockchain. If you have studied relational databases, you can understand the blockchain as an index of the database. It can also be thought of as a catalogue of a book. Routing node: responsible for delivering transactions and blocks in a decentralized network environment, one node creates a transaction and sends it to the neighboring nodes, which is verified by the neighboring nodes and then sent to the neighboring nodes, which will soon spread throughout the network. If a node finds a block that meets the standard through mining, the node will be passed to the neighboring nodes in the same way, and then the neighboring nodes will continue to propagate, so that all the nodes of the network agree.
The schematic diagram of P2P network propagation is as follows:
In the following articles, we will introduce the working mechanism of Bitcoin P2P network in detail, including node classification, node discovery, node connection and broadcast.
6. Summary
Due to the limited space, this paper introduces the three basic concepts of Bitcoin, including blockchain, mining and P2P network. It involves how to prevent double payment, smart contracts, blockchain bifurcation, deflation, locking and unlocking scripts, Merkle tree storage of transactions, storage format of transactions, probability of blockchain being * *, mining difficulty and mining success time, more consensus mechanisms, creative coin transactions and transfer transactions, performance of Bitcoin, different types of mining nodes, and Bitcoin application scenarios.
This article comes from the official account of Cloud Age Architecture.
Li Yanpeng, founder of the "Cloud Age Architecture" technology community, is the author of distributed Service Architecture: principle, Design and practice and Scalable Service Architecture: framework and Middleware. He is now the head of the architecture group of a well-known payment platform. He has worked as a technical leader and architect for large IT Internet companies such as Citibank, Oracle, Reuters and Sina Weibo. Now it focuses on the planning and implementation of the application architecture and technical architecture of large-scale and highly concurrent online and offline payment platforms, and is responsible for the design and implementation of core payment systems such as transaction, payment, channel, payment, risk control, reconciliation and so on. Practical experience in product application architecture planning and landing in business scenarios such as mobile payment, aggregate payment, compliance account, code-scanning payment, tagged payment and so on.
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: 0
*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.