The concept of Bitcoin (BitCoin) was first proposed by Satoshi Nakamoto in 2009. The open-source software designed and released according to Satoshi Nakamoto’s ideas, as well as the P2P network built on it, are Bitcoin. Bitcoin is a P2P form of lottery and How to find it. Peer-to-peer transmission means a decentralized payment system.
Unlike most currencies, Bitcoin does not rely on a specific currency institution for issuance. It is generated through a specific algorithm through a large amount of computation. The Bitcoin economy uses a distributed database consisting of many nodes in the entire P2P network to confirm and record all transaction activities, and uses cryptographic design to ensure the security of all links in the currency circulation. The decentralized nature of P2P and the algorithm itself can ensure that it is impossible to manipulate the value of the currency by artificially manufacturing a large number of bitcoins. The cryptographic design ensures that Bitcoin can only be transferred or paid by the actual owner. This also ensures the anonymity of currency ownership and the circulation of transactions. The biggest difference between Bitcoin and other Online casino and How to find it is that its total amount is very limited, with strong scarcity. This currency system had no more than 10.5 million in 4 years, and the total amount will be permanently limited to 21 million after that.
Peer-to-peer network, each node in the network is both a Client and a Server as shown in the following figure:
Overall P2P architecture
Nodes communicate with each other by sending message commands. The following diagram shows the corresponding message command format:
sports betting tutorial and The latest method
Message command format
The class diagram of CMessageHeader is as follows:
CMessageHeader class diagram
online casino tutorial and Latest Address
The following table shows the message commands used in the node communication process:
Command
Message content
Description
version
nVersion,nService,nTime,address
Version, service identifier, time; address
addr
vector
Address list
inv
vector
Inventory information list: Add the corresponding inventory sending message to the inventory sending known
getdata
vector
According to the type of inv, perform different processing, that is, convert the corresponding request message into the command to be requested and place it in the node’s corresponding sending message cache
getblocks
CBlockLocator locator;uint256 hashStop;
According to the locator, locate the block on the chain and start finding the corresponding next from this position, until the hash of the corresponding block’s block is equal to hashStop, and then send all the found blocks to the inventory setInventoryKnown2 to wait for transmission
Tx
CTransaction
Put the transaction message into the corresponding known inventorysports betting and The most exciting gameplay. If this transaction can be accepted, broadcast this message and recursively process all dependent orphan transactions corresponding to this transaction; if the transaction is not accepted, put this transaction into the orphan transaction list mapOrphanTransactions and mapOrphanTransactionsByPrev
block
CBlock
Block message: Put the received block into the corresponding known inventory, and process this block accordingly. Then, remove this block from the mapAlreadyAskedFor query
The corresponding overall process is shown in the following figure:
Overall process
The LoadAdreess method reads the corresponding address information from the address file addr.dat and puts it into the corresponding global memory object mapAddresses. The structure of addr.dat is as follows:
Key
Value
Description
Objects stored in memory
addr
CAddress
The database saves the corresponding address information
map
The LoadBlockIndex method reads the corresponding block index information from the block index file blkindex.dat and puts it into the corresponding global memory object mapBlockIndex. The structure of blkindex.dat is as follows:
Key
Value
Description
Objects stored in memory
blockindex
CDiskBlockIndex
Block index database
map
The corresponding source code is as follows:
The LoadWallet method reads the corresponding wallet transaction information and other configuration information from the file wallet.dat and puts them into different global memory objects. The format (key-value structure) of wallet.dat is as follows:
Key
Value
Description
Objects stored in memory
Type
Key1
Key is divided into type type and key
name
Bitcoin address
Bitcoin address corresponding to name
Mapping between address and name
A map
Tx
Transaction hash value
Wallet transaction object CWalletTx
Mapping between transaction hash and transaction
map
Key
Public key
Private key
Corresponding relationship between public key and private key
map
defaultkey
vector
Default key corresponds to the corresponding value
setting
fGenerateBitcoins
Mark for generating bitcoins
Mining mark
int fGenerateBitcoins
setting
nTransactionFee
The value of the transaction fee
Transaction fee
int64 nTransactionFee
setting
addrIncoming
CAddress object
Obtain the current corresponding external address for receiving external connections
CAddress addrIncoming
The source code content is as follows:
Three main threads were started, ThreadOpenConnections, ThreadSocketHandler, and ThreadMessageHandler. The main processing flows corresponding to these three threads are shown in the following figures:
The processing flow corresponding to the thread ThreadOpenConnections is shown in the following figure:
ThreadOpenConnections processing flow
The source code is as follows:
The processing flow corresponding to the thread ThreadSocketHandler is as follows:
ThreadSocketHandler processing flow
The source code is as follows:
The processing flow corresponding to the thread ThreadMessageHandler is as follows:
ThreadMessageHandler processing flow
The source code is as follows:
The processing relationship between nodes corresponding to different buffer areas is shown in the following figure:
Nodes correspond to different buffer areas
The mining processing flow is shown in the following figure:
Mining processing flow
The source code content is as follows:
I have added detailed comments to the bitcoin-0.1.0 source code, corresponding download address: https://github.com/lwjaiyjk/bitcoin-comment-0.1.0.git
Please indicate the source for reproduction