Blockchain ancestor bitcoin 12: (SPV) node and bloom filter

Yin Cheng 2021-11-24 08:11:00 阅读数:425

blockchain ancestor bitcoin spv node


   (SPV) node

        Not all nodes have the ability to store a complete blockchain . Many bitcoin clients are designed to run On devices with limited space and power , Like smart phones 、 The tablet 、 Embedded system, etc. . For this What kind of equipment , Through simplified payment verification (SPV) In such a way that they do not have to store complete blocks

Work in the case of a chain . This type of client is called SPV Client or lightweight client . With the popularity of bitcoin ,SPV Nodes gradually become bitcoin nodes ( Especially bitcoin wallet ) the The most common form used .SPV The node only needs to download the block header , Instead of downloading the transaction information contained in each block . thus
The generated blockchain does not contain transaction information , The size is only the size of a complete blockchain 1/1000.SPV Nodes cannot Build all available for consumption UTXO The whole picture of , This is because they don't know all the transactions on the network The complete information of .SPV The method used by nodes to validate transactions is slightly different , This method depends on Equal node On demand Provide a partial view of relevant parts of the blockchain . For example , Each whole node is like a tourist in a strange city , He was carrying a bag Including each street 、 A detailed map of each address . by comparison ,SPV Nodes are like this strange city Tourists in the know only the name of one main road , Obtain segmented lanes by randomly asking strangers in the city Directions . Although both types of tourists can verify the existence of a street through field visits , But there's no map Tourists don't know which streets are in each alley , I don't know what other streets are nearby . No way The tourists in the picture are Church Street 23 Number In front of , I don't know if there are other articles in this city Church Street 23 Number , I don't know if the one in front of me is the one I'm looking for . For him, , first-class The way is to ask enough people for directions , And I hope some of them are not trying to rob him . Simple payment verification refers to the depth of the transaction in the blockchain , Not height , To verify them . A node with a complete blockchain will construct a verification chain , This chain is formed by reversing the time along the blockchain The sequence can be traced back to thousands of blocks and transaction components of Genesis block . And one SPV The node validates all zones
Chain of blocks ( But not all transactions ), And link the blockchain with relevant transactions . for example , A full node needs to check the second node 300,000 A transaction in block No , It will take from the block It started all the way back to the creation block 300,000 All the blocks are linked , And build a complete
Of UTXO database , By confirming the UTXO Has not been paid to confirm the validity of the transaction . SPV Nodes cannot be verified UTXO Whether it has not been paid . By contraries ,SPV The node will display the transaction information and Between the blocks where it is located merkle route Create a link . then
SPV The node has been waiting , Until the serial number starts from 300,001 To 300,006 Six blocks are stacked in the transaction On the block , And by establishing the depth of the transaction is in the 300,006 block ~ The first 300,001 District Block down to verify the effectiveness of the transaction . in fact , If all other nodes in the network accept the second 300,000 block , And through enough work, six more blocks are generated on this block , According to the proxy gateway agreement , It can be proved that the transaction is not double payment . If a transaction doesn't actually exist ,SPV The node will not mistakenly believe that the transaction exists in a block .SPV The node will pass the request merkle Proof of path and proof of workload in the verification blockchain , To confirm the existence of the transaction . But , The existence of a transaction is possible for SPV node hide Of .SPV section There is no doubt about the existence of a transaction , But it can't verify a transaction ( Like a UTXO Double payment for ) non-existent , This is because SPV The node does not have a record of all transactions . This vulnerability will be targeted SPV Node denial of service attack or double payment attack . In case of Resist these attacks ,SPV Nodes need to be randomly connected to multiple nodes , To increase communication with at least one reliable node Probability of connection . The need for this random connection means SPV Nodes are also vulnerable to network partition attacks or attacks Sybil attack . In the latter case ,SPV Nodes are connected to false nodes or false networks , No, A connection to a reliable node or a real bitcoin network . In most practical situations , Having a good connection SPV Nodes are secure enough , It's in resource demand 、 Maintain the right balance between practicality and security . Of course , If you want to ensure foolproof security , The most reliable method is the node running the complete blockchain .

Bloom filter

       Bloom A filter is a base that allows users to describe a specific keyword combination without having to express it accurately Probability based filtering method . It allows users to effectively search keywords while protecting their privacy . stay SPV Node , This method is used to send transaction information query requests to peer nodes , At the same time The site will not be exposed . Our previous example , A tourist without a map needs to ask for directions to specific places . If he asks a stranger Church Street 23 Where is the number , Inadvertently , He exposed his Destination .Bloom The filter will ask , There is a belt nearby hall Word Street ? Such a question The method contains slightly fewer keywords than before . The tourist can choose how much information to include , such as With Don Street ending perhaps “‘ teach Streets beginning with words . If he asks less , Get more to Yes, please , Privacy is protected , But there are some irrelevant results in these addresses ; If he asks very Specifically , While getting more accurate results, he also exposed his privacy .Bloom The filter allows SPV Node specifies the search mode for the transaction , The search pattern can be based on Considerations of accuracy or privacy are adjusted . A very specific Bloom The filter will produce more accurate result , But it will also display the address used in the user's wallet ; conversely , If the filter contains only simple key word , More corresponding transactions will be searched , It contains a number of unrelated transactions and has a higher Privacy . First ,SPV The node initializes a that does not match any keywords blank ”Bloom Filter device . Next ,SPV The node will create a list containing all address information in the wallet , And create a A search pattern matching the transaction output corresponding to each address . Usually , This search pattern is a Hash script for payment to public key 、, The script is a locking script that will appear in every transaction paying for the public key hash address . If SPV Nodes need to be tracked P2SH Address balance , The search mode will change become P2SH Script . then ,SPV The node adds each search pattern to Bloom In the filter , In this way, as long as the keyword appears in the transaction, it can be recognized by the filter . Last , The peer node will use To the Bloom Filter to match transmission to SPV Node transactions .Bloom The filter is implemented by a variable length (N) Binary array of (N Bit binary number Form a bit field ) And variable quantity (M) Consists of a set of hash functions .. The output of these hash functions The value is always 1 and N Between , This value corresponds to a binary array . And the function is a deterministic function , That is, any one uses the same Bloom The nodes of the filter can be adjusted for specific input through this function To the same result .Bloom The accuracy and privacy of the filter are improved by changing the length (N) And ha The number of Greek functions (M) To adjust .

Bloom The initial value of each number in the filter array is zero . Keywords are added to Bloom Filter Before the , It will be calculated once through each hash function in turn . The input is calculated by the first hash function I got one in 1 and N Number between , It's in the array ( The serial numbers are 1 to N) Corresponding to The bit of is set to 1, So as to record the output of the hash function . Then proceed to the next hash function operation , Put another position as 1; And so on . When all M After all the hash functions have been calculated , One share M The value of a bit ranges from 0 Turned into 1, This keyword is also Record In the Bloom In the filter . chart Show Simple and easy Bloom Add keywords to the filter “A”.

The second key is to simply repeat the previous steps . Keywords are calculated by each hash function in turn after , The corresponding bit becomes 1,Bloom The filter records the keyword . It should be noted that , When Bloom When the keywords in the filter increase , The bits of the output value of a hash function corresponding to it may have been Jing Shi 1 了 , In this case , This bit will not change again . in other words , As more keywords point to Repeated bits ,Bloom The filter follows the bit 1 Saturated with the increase of , The accuracy is also reduced . The The reason why the filter is a probability based data structure , It is because the increase of keywords will lead to the decrease of accuracy low . Accuracy depends on the number of keywords and the size of the array (N) And the number of hash functions (M). Larger arrays and more hash functions record more keywords to improve accuracy . Small arrays and limited hash functions can only record limited keywords, thus reducing the accuracy .

chart Shows how to add to the list Bloom Add a second keyword to the filter “B”.

To test whether a keyword is recorded in a Bloom In the filter , We put the keyword one by one One is substituted into each hash function for operation , The results are compared with the original array . If all the results The corresponding bits become 1, It indicates that this keyword may have been recorded by the filter . The reason for this The conclusion is uncertain , Because these bytes 1 It may also be the overlapping result of other keyword operations . Simple Come on ,Bloom A positive filter match represents May be . The figure below Is a validation keyword “X” Whether in the above Bloom Legend in filter . The corresponding bits are set to 1, So this keyword is likely to match .

If the result is a probable positive match , said May be . On the other hand , If we substitute the key The result of word calculation is 0, Indicates that the keyword is not recorded in the filter . Negative match The result of matching is not possible , It must be . in other words , A negative match means It must not be . The figure below   Is a validation keyword “Y” Whether it exists in simple Bloom Legend in filter . In the figure A result field is 0, This field must not have been matched .

Bloom Filters are used to filter SPV The transaction information received by the node from the peer node .SPV Meeting Build one that can only work with SPV Filter for address matching in node wallet . And then ,SPV The node will be directed to Wait for the node to send a message containing the filter to be used in the connection filterload news . When the filter is built After good , The peer node substitutes the output value of each transaction into the filter for verification . Those matching fairs Transmitted back to SPV node . In response from SPV Node getdata Information , The peer node will send a message containing only and filter Block header information of the block matched by the , And the matching transactions merkle Trees . This section The point will also send a matching transaction tx news . This node can send a message by filteradd Information to its Bloom Add keywords to the filter , Can also send filterclear Information to clear the entire filter . Because you can't delete off... Directly from the filter Key words , So if a keyword is no longer needed , Nodes must be cleared and added to replace the original filter device .





website :

Want to get the coinage technology and a full set of virtual machine information

Blockchain technology exchange QQ Group :254416566



版权声明:本文为[Yin Cheng]所创,转载请带上原文链接,感谢。