Transaction exchange
Each client broadcasts locally generated transactions and transfers them to transactions from other nodes. This document describes the exchange and transfer processes between transactions.
You can also read the following articles to understand how Transaction is determined to be legal.
Https://en.bitcoin.it/wiki/Protocol_rules#.22tx.22_messages
Wallet sending transaction
The client regularly calls the SendMessages () function in main. cpp. In this function, ResendWalletTransactions is called to send locally generated transactions.
Here, he will check whether there is a new block recently. If yes and the local transaction is not in the block, the transaction will be sent to the connected node, this check will only be performed once every 30 minutes.
Transaction is broadcast again only when the timestamp is more than 5 minutes earlier than the newly received block. The sending order will be the older the transaction, the more first it will be sent.
Scheduled broadcast
The client regularly calls the SendMessages () function in main. cpp. This function also determines whether a message will be sent to other nodes.
In each message processing process, a node selected as the trickle node is selected and only used to receive addr messages.
The client randomly extracts 1/4 of the transaction data for sending. Unless the remote node is a trickle node, the trickle node will receive all transactions. It looks strange here, but it does. If a node only receives 1/4 (not all data), and all the transaction data from the local wallet is also removed when the code is implemented in the 1/4 data, note that this is to increase privacy.
Forward messages
If a client receives a tx transaction message, which is called RelayMessage, also called RelayInventory, it will also be placed in a message pool to be sent to other nodes.
Some key code descriptions:
1. CWallet: ResendWalletTransactions in wallet. cpp
2. pnodeTrickle = [GetRand (vNodesCopy. size ()];
SendMessages (pnode, pnode = pnodeTrickle );
Code ThreadMessageHandler2 () in net. cpp ()
3. In main. cpp's SendMessages (),
If (fSendTrickle)
4. In SendMessages () of main. cpp
Bool fTrickleWait = (hashRand & 3 )! = 0)
5. In SendMessages () of main. cpp
// Trickle out tx inv to protect privacy
If (inv. type = MSG_TX &&! FSendTrickle)
{
6. In SendMessages () of main. cpp
// Always trickle our own transactions
If (! FTrickleWait)
{
CWalletTx wtx;
If (GetTransaction (inv. hash, wtx ))
If (wtx. fFromMe)
FTrickleWait = true;
}
RelayMessage and RelayInventory in 7.net. h
(To be continued)