Block chain Note: The backbone of Bitcoin, the nodes of the network, business transaction data structure, UTXO, block content, mining principle, eventual consistency, SPV

Bitcoin backbone

  • We will stand in angles of currency bit block chains to a more particular description of
  • It is only a block chain general term for a class of technology, and the use of credit is the bit block chain technique first developed a typical application
  • Therefore, our knowledge of the technology block chain starting from Bitcoin is a necessary way
  • First we look at, what is Bitcoin backbone?
    • First Bitcoin block chain is a network system, then what is the backbone of it? It is also a major chain, is equivalent to a full version or the production environment of our software system
    • Because in the process block chain formation, not just a single strand, in the case where in fact several points
    • First, the first one, is a chain of concept testing, such as Bitcoin community as we provide a test network, the equivalent of a test version of the software, then the test network inside it, we can do any operation, do not worry about what assets loss or other problems
    • With respect to the test network is a test version of the main chain is
    • The second case, in the process of forming the block chain (a process of competition among packed), will appear more difficult to meet the block, since the bit by means of a coin which is demonstrated to enhance work area packaged right block
    • So in the process of packing the right to compete for the whole network, and no mechanism can only be defined at the same time a node, it is possible to have multiple nodes get the right package
    • Well, this time for it, there are multiple nodes may produce more in line with the difficulty of blocks
    • So way, as shown, it is actually possible to produce such a bifurcation in the process
    • In Bitcoin inside, no matter what kind of bifurcation produce (temporarily generate bifurcation in the middle), always with the greatest difficulty that a chain as the main chain
    • So Bitcoin inside the main chain refers to the official network, to maintain the most difficult that a chain is the backbone of Bitcoin, that is truly effective in the Bitcoin network, a data link
    • In fact, this we can see in the block chain inside, it's such a specific storage structures and mechanisms for consensus, so that the storage of such data as unlike traditional centralized server is very clear, in this process it is possible It will have some copies of bifurcation of these data
    • Therefore, the entire block chain network, what data is truly effective data, often need to go through to confirm the subsequent blocks
    • The so-called biggest difficulty is to maintain the block in the subsequent confirmation of a chain, in the chain, is the largest mining difficult, so this is actually one of the criteria (protocol)
    • Of course it is not all in the other block chain system this practice, this is to Bitcoin for example, it is one of its features.

Bit network node credits

  • What is Bitcoin node it? Standing software point of view, it actually refers to a program on a set of nodes.
    • 完全节点 English called "full node" that is on this nodes it contains all the features and bitcoin block chain data books, is a major Bitcoin network support, or is the most important support.
    • In addition to full node, other nodes with respective special proprietary features stripped out, such as:
      • Dedicated to 挖矿的节点(retain only the mining function)
      • 网络路由节点For convergence p2p communication between the different nodes, it is mainly responsible for routing data
      • 钱包Of course purse is actually not really a node, but also points situation, if that is the kind of wallet with full node to work together, called the full node wallet
      • If some lightweight wallet (other forms of web version, Mobile wallet, etc.), this is actually a more wallet belongs to a client, it can keep full node communicates to the actual transfer payments .
  • We can see that in the bit currency node in the network, which node is divided into many types of
  • We can put all of these functions are integrated in deployment time together, that is integrated node
  • Bit node in the network requires a number of credits to be composed by nodes point to point network communications

Trading transaction data structure

  • Bitcoin function it is very simple, it is primarily to achieve a similar transactions like bank and transfer of such a system (system)
  • Well, since it is the realization of the transfer transaction, there is a trade transaction, transactional matters in the end is what kind of data structure?
    • In fact, it is mainly composed of two parts: the first part is called 输入交易, called the second half输出交易
    • We can see in the input transactions, which contains the hash values ​​of the leading input, which is input over the previous corresponding hash value, and the script input (for a verification procedure)
    • Transaction terms of output, the first contains the value of the transfers (that is, the number of revolutions), and the output of the script (for some verification procedures)
    • May decide to convert bitcoins matches ownership through the input and output script, so we can see the so-called transactional matters, not like exactly like banks, just turn a sum, which is included with the verification script
    • At the same time the previous trading links affairs, in fact, just inside the warehouse business, as there are in storage, there is a library, the library must correspond to storage, then such a chain formation of such a link
    • We can see the formation of such a link between not only block the deal between things also formed such a chain, it is also to be linked through this hash value, pointing to a previous transaction data
    • This is a basic structure of things bitcoin trading

About UTXO

  • Let's look at a more specific business transaction - UTXO: Unspend transaction Output (unspent transaction output)
  • The first example below, a transaction corresponding to the transaction is generated, the input from the output of two parts
  • Coinbase equivalent to that generated by the system rewards mining affairs, rather than turn over by someone else, we can see that it outputs a 12.5 Bitcoin address to Alice
  • Next we look at transaction number 002 is Article 2 of transactional matters, this is an ordinary transfer transactions, it began to turn from Alice's address, go to Bob's address
  • In the input, it is actually pointing to output 001 transaction number, which is why the relationship between input and output is a link to the corresponding (must be prior to output, in order to have input after)
  • Alice to Bob transfers, she turned six, and Alice's mining reward is 12.5, this transfer six to Bob, so she give yourself the change 6.5, so thus forming a new relationship between the input and output .
  • For Alice is concerned, the transaction number 001 inside by 12.5 Bitcoin mining reward obtained is that it can be used to balance cost, that is, the so-called unspent transaction output, that is, UTXO
  • So we can put UTXO seen as unspent balances, but it is not a summary of the balance of such a number, but such a transaction transactions (output transactions)
  • We have seen in 002 years of Bob won six Bitcoin, then, Bob also be a transfer to Lily, the transaction number 003 inside, we can see Bob turn two bitcoins to Lily, to find himself zero four
  • We can see that the number 001,002,003 transactions connected end to end, continue to complete input and output, input and output links such a way, and at every output are included that can be used at your own time input value, also known as UTXO
  • But it is still very similar to the concept now inside the warehouse storage library, it can be understood in contrast

Content block contained

1) and the header area of ​​the block body bitcoin

  • Content block included in the bit credits is very simple: it is a header region and a body consisting of blocks
  • In block ahead contains six main fields:
    • 区块版本: Is the version number, the current protocols and data structures,
    • 前一个区块哈希: A block of hash in the previous block to generate a link pointing to the front
    • 时间戳: Refers to the time this block generated
    • 梅克尔根: Refers to the body block all transactions transactions to calculate a hash value, will further detail later in this article
    • 难度值: This is associated with the mining of the Bitcoin, in the process of mining, it is actually carried out by two consecutive hash value is calculated to obtain a more difficult target to meet the zone header, this value is difficult to match the mining of qualifying
    • 随机数: Also associated with mining, because we need to use brute force as similar as the data header area will be continuous double hash calculation, in which the hash calculation process it, will continue to match a random number to as the hash calculation parameters. When we calculate the value in line with the difficulty of the target block, random numbers that we use will be credited to the area inside the header.
  • Block body is a sum of transaction transaction

2) Detailed Merkel root (tree)

  • To understand the root Merkel, we will look at a tree structure called Meckel tree
  • We assume that this block there are five transactional matters, namely: A, B, C, D, E,
  • 5 this business transaction which were calculated hash value, generated by A, B, C, D, E 5 hash values
  • 5 hash value and then paired together once again to calculate the hash value: A combination with B, C and D binding, E only you, and that is combined with their own to create a new hash value
  • New hash value once again paired together until calculate the root, each node in the tree Merkel inside, each node of a tree, in fact, are the hash value, the tree is also called Merkel Ha Greek tree
  • Merkel then the root (or tree) what is it? We know that the data block is the need for continuous transfer of Bitcoin nodes, then the process of the transfer of useful data damage or other problems may occur
  • When one node (receiving node) receives the block, it will block trading transaction once again to calculate the hash value to restore what Merkel tree
  • So if the calculated root Merkel Merkel header in the root zone and inconsistent, it shows acquired in a business transaction there is a problem, then this time we can come back in the end through which a root Merkel transactional matters out of the question
  • For instance, we have a problem trading transactions C, then by Merkel root view, it is N1 and N2, which a hash value out of the problem? So by comparison, if that is found to N1 with the hash value of the original tree which Merkel is not the same
  • Then along this line look, we came to see that there is a problem H1 or H2, H2 is that if you find a problem, then look again according to this line of C or D is a problem
  • After such a constant backtracking, you can find this at a relatively high speed data in which a piece of the data in question, so that you do not need to re-download the entire block transaction data, but only to go to download the corresponding question that a
  • This is the role of Merkel tree, which means it is used to prove the integrity of the data, and can be a more efficient way to find the problem of data blocks

3) validation rules timestamp

  • Usually in the center of the server software architecture of the time in question basically is relatively easy to solve, because time can be unified from a time server (from the server itself)
  • Not to block chain system in terms of dedicated server, of course, we also Bitcoin specifically deployed in the network time service, it is also possible
  • Since Bitcoin network itself it is a point of such a network architecture, therefore, the time zone where each node is also likely to be different
  • Bits in the time stamp token validation rules:
    • Bitcoin Generally there is no specific time server, but we can go to the server to deploy such a service for the Bitcoin
    • The average time stamp before the new block must be greater than the time stamp in the bit block 11 coins, and less than the next two hours
    • This is a coin validation rules bit timestamp
  • Since the point of this architecture, we can not go to get a certain unity of time
  • You can only have such a validation rules, to make it a time stamp for each block will not have a very very big difference

Mining process principles

  • In fact, there Bitcoin mining is part of a consensus mechanism
  • For such a point to point network software, its data is no single authoritative reference to do a service center
  • It must be a mechanism, each over a period of time, select a packager data to the packager packaged data subject to synchronize data consistency with other nodes
  • Who will pack it every once in a while? In Bitcoin which is enhanced by a mechanism that is the workload proved such a mechanism
  • This effort proved to be the image of the process is called 挖矿, in this process, operators will need to consume a lot of computer power to calculate, just as a mining labor
  • What that means constantly hash value calculation block (of course, made two hash, double hash)
  • We are the only refers to the calculation of the double header area hashes header inside the area, not every parameter is adjustable, for example blocks of hash, a timestamp, Merkel roots, etc.
    • In these different parameters, Merkel root can change, because if we adjusted the number of blocks inside the body of the transaction is a transaction or order, then the root Merkel will change, so Mei Kerr is one of the main root parameter calculation of participation (or participation in mining, said the main parameters calculated hash calculation)
    • Of course, the time stamp can be adjusted, but not great adjustable range
    • Other parameters, it is mainly random number, relatively speaking, the adjustable range is relatively large, it is concerned this calculation it is easier to find such a qualified value in a wide range of
  • So no matter which parameter adjustment to be calculated by this adjustment, so that the results match the difficulty of a target block, once the match is successful, even if successful mining ah, even the end
  • So-called mining refers to the process parameters on the composition of the constant region of the double header hash calculation
  • In Bitcoin inside, SHA256 hash algorithm mainly refers such an algorithm

The final consistency network

  • The so-called eventual consistency of the data refers to their books Bitcoin each node in the network they have is not all the same
  • Bitcoin itself will bifurcation occurs, it is difficult by a particularly clear way, so that the books in the data bitcoin always always consistent, then this is hard to do
  • In addition, FLP principle, we know that the Internet asynchronous network, because any time a node is down, so a variety of damage happens
  • So Bitcoin network, it can not reach a consistent deterministic real-time, but only to reach a final consistency
  • For instance, we transfer a sum of Bitcoin, such as our record in this transfer transaction block No. 5
  • This time we would recommend, if you want to ensure the safety, then it waits for an acknowledgment six blocks, that is to say until 11 blocks generated after 5 + 6 = 11 until produced after the first 11 blocks
  • If we deal before the transaction is still in the main chain, it shows basically no problem
  • Of course, this problem is not only a probability, can only say that the possibility of tampering has been very low, so that as long as this is based on an asynchronous network, basically eventual consistency rather than the certainty of consistency from time to time

About SPV

  • SPV: Simplified Payment Verification simple payment verification
  • The concept of Bitcoin network transfers will be paid out of that business transaction verification and transaction verification, which is relatively easy to confuse the two
  • Payment verification: that I paid a sum of money (Bitcoin), is to verify the legitimacy of a payment that occurs itself, for example, my balance is adequate, I pay this in itself is not a legal
  • Transaction Verification: verification is the most complete, it will be one of the most complete data validation based on the books.
  • For payment verification, because just want to prove that this payment is present in the block, then it is not necessary with a complete books to verify the data
  • Because data are often full of books over time will be very large, Bitcoin has reached a size of more than 200 G
  • Then for payment verification, due only to test whether the payment of the transaction exists, therefore, it can only be based on a block up the whole basis of this verification without books
  • The SPV verification process:
    • If we had to pay a bit of money to someone, we now verify
    • As the only region to acquire header, the body does not get the block, so we can only get there then the data header area of ​​several fields
    • First Capture header (header refers to Capture the longest chain, is the greatest difficulty that also refers to a chain backbone, which is the backbone area header)
    • After obtaining the header area, we calculated the business transaction (payment transactions affairs) hash value, look up the block trading firm in by the hash value payment transactions
    • Later found, you can get root calculate the hash value Merkel
    • To calculate Merkel root, one approach is to be calculated separately for each hash value of a thing, then be calculated by the general procedure
    • A second type is that we get the hash value Merkel tree intermediate node, there is no need to go one by one separately calculated for each of the things
    • So we brought out one of the branches of the tree, it can be calculated directly Merkel root
    • Next, we compare the header area just in Merkel root, if both are equal, it means that the affairs of this payment transaction is there, if not equal, it shows that there is no
    • This is a relatively simple payment verification
Published 432 original articles · won praise 251 · views 710 000 +

Guess you like

Origin blog.csdn.net/Tyro_java/article/details/104814639