Bitcoin blog

The essence of Bitcoin is innovation that be related to remittance, asset holding rights, liberation, and freedom.

Network

Overview
Bitcoin is builded as peer-to-peer(P2P) network on internet. P2P network is essentially decentralize and open. This network is formed by connecting mutually equal nodes. we calling computer terminal participating in the network as “node”, and Bitcoin network means that entire note running the P2P protocol. This node can be divided into several roles according below.


Node type
The Bitcoin node is collection of functions such as routing, block chain database, mining, and wallet.

Wallet
User wallet has two types of full node and SPV node.
Miner
Mining nodes are competing to create new blocks.
Full blockchain
It refers to full node with a complete blockchain.
Routing node
All nodes must have routing function in order to join the network.


Extended network type
It shows the main type on the extended Bitcoin network.
f:id:adrenaline2017:20170620165104j:plain


Join the network
When new node launch, the node must find another node to join Bitcoin network. And this node has to find and connect at least one node. Geographical location of other nodes is irrelevant. Becouse topology of Bitcoin network isn't desided in reration to geography. The node can be randomly chosen.

①The node establish TCP conection(use port 8333)
TCP (Transmission Control Protocol):It is a standard protocol used to realize reliable communication in the Internet.

②Stand up to New node(It find and connect at least one node)

③Contact DNS server (DNS seed provide IP address of Bitcoin node)
DNS(Domain Name System):It tells IP address based on hostname.

④ As soon as establishing a connection, the node sending“version message”
version message:It include basic Identification information

⑤The peer node returns " verack " to acknowledge the connection and establish it
verack:It inform that trying to connect

⑥When the node establish one or more connections, New node sends "addr message" to the adjacent node
addr message: It include IP address

⑦Adjacent nodes communicate "addr message" to another adjacent nodes one after another

⑧Also, when send "getaddr" to adjacent node
getaddr:It get to return IP address of other peer

⑨The node connects to plurality of different peers

⑩node must always keep finding new node


Full node working
Full node is node managing a complete blockchain including all transactions.

①Full node sends to “version message”
version message:It is included to“Bestheight”that shows current blockchain hight of node

②By looking at "version messages", the nodes know how many peers the peer holds and can compare with our own blockchains

③Then the peer node exchanges "getblocks message" containing the top block hash (fingerprint) of each other local blockchain

④The node can compare with the hash of other node and identify which block the other node wants

⑤Identify the first 500 blocks to share with other nodes
"inv message" include in this infomation

⑥Send “inv message” to other node

⑦Pick a hash of missing blocks and request "getdata messages" to be sent full block data

※The node keeps track of how many blocks per peer are still in the "transmitting" state that has not yet been sent.
※It continues checking so that it does not exceed the maximum number of blocks during transmission for one peer.


Simplified payment verification
As Bitcoin grows in usage the datasize amount needed to download blocks and transaction broadcasts increases. All notes can't hold a full blockchain. The data size problem occer when running Bitcoin wallet on low spec machin like smartphone. Convenience will be lost unless irrelevant transactions are discarded and block chains are not synchronized quickly. The SPV is used so that network processes can be executed without holding a full blockchain.

Solution method
The SPV node downloads only the block header and does not download transaction. It only validates all blockchains and transactions associated with this SPV node. So the SPV node can't verify that UTXO is not in use.
Instead, the SPV node uses merkle path to tie the transaction to block containing this transaction. The SPV node can check existence of the transaction in the block by requesting the stead node for merkle path certification and by verifying the proof of work in blockchain.

※The SPV node can prove that the transaction exists reliably, but it can not verify whether there is a transaction like dual use of the same UTXO.So the SPV node needs to be connected randomly to several nodes.


What is Bloom filter?
With the protocol extension proposed in BIP0037,SPV client can efficiently download only transactions related to myself address by using "Bloom filter".Bloom filter operates at a very high speed and is a data structure that can probabilistically determine whether an element is included in a set.
"Stochastic" means that sometimes to say "Although do not included,it contains",but it does not say "despite being included in it, not included" .
※there is a false positive but false There is no negative


How does Bloom filter work?
①Initialize bloom filter with empty state
f:id:adrenaline2017:20170614104547j:plain

②Create list of all the addresses the wallet has

③Create a search pattern for each Bitcoin address

④These search patterns are passed through a hash function to obtain a number between 1 and N

⑤Find bits in the bit string corresponding to this number and set "1"
f:id:adrenaline2017:20170614105534j:plain

⑥It will do this further by the number of the pattern(already remains 1 stands place where 1)
f:id:adrenaline2017:20170614105741j:plain
※Accuracy decreases as the number of patterns increases.Conversely, the larger the size (N) of the bit string and the number (M) of hash functions, the more accurate it becomes.Using larger bit strings and more hash functions makes more accurate.

⑦bloom fliter send to peer

⑧The peer uses sent bloom filter to find out which transaction matches the search pattern

⑨Use bloom filter to check pattern "X" exists.
If the place where the bit pattern is "1" is the same "1" in the bit string of the bloom filter,the bit pattern may be included in the bloom filter.
f:id:adrenaline2017:20170614110042j:plain

⑩Conversely, to check that a pattern is not included in the bloom filter, make sure that any one of the bit strings of the corresponding bloom filter is 0.
f:id:adrenaline2017:20170614110312j:plain


Bloom Filter and Inventory
1.SPV node send "filterload(include bloom filter)" to peer

2.Peer chack this bloom filter

3.Peer send "transaction(only matching bloom filter)" to SPV node

4.SPV node send "getdata message" to peer

5.Peer send "merkleblock message" to SPV node
※Block header and transaction correspond to merkle path

6.Peer send "tx message" to SPV node
※Contains transactions matching "bloom filter"