Satoshi Client Transaction Exchange: Difference between revisions

From Bitcoin Wiki
Jump to navigation Jump to search
Wickrick22 (talk | contribs)
Initial content
Newar (talk | contribs)
m formatting
 
(4 intermediate revisions by 4 users not shown)
Line 5: Line 5:
that deal with this exchange of transactions.
that deal with this exchange of transactions.


See this article for more information on how transactions are validated:
Transactions are exchanged only if they are [[IsStandard|standard]] and [[Invalid block|valid]].
[https://en.bitcoin.it/wiki/Protocol_rules#.22tx.22_messages Protocol Rules]
 


== Wallet Send ==
== Wallet Send ==


The client periodically calls SendMessages() (in main.cpp) which calls
The client periodically calls SendMessages() (in main.cpp) which calls
ResendWalletTransactions to send transactions generated locallly.
ResendWalletTransactions to send transactions generated locally.
This routine looks to see if there has been a new block since last time,
This routine looks to see if there has been a new block since last time,
and if so, and the local transaction are still not in a block,
and if so, and the local transaction are still not in a block,
Line 20: Line 18:
Transactions are only rebroadcast if they have a timestamp at least
Transactions are only rebroadcast if they have a timestamp at least
5 minutes older than the last block was received. They are sorted
5 minutes older than the last block was received. They are sorted
and sent oldest first.[1]
and sent oldest first.<ref>See: <code>CWallet::ResendWalletTransactions</code> in wallet.cpp.</ref>
 


== Periodic Advertisement ==
== Periodic Advertisement ==
Line 28: Line 25:
determines if a message should be sent to a remote node.
determines if a message should be sent to a remote node.
For each message processing iteration, one node is chosen as the
For each message processing iteration, one node is chosen as the
"trickle node".[2]  This node is the only one chosen to receive
"trickle node".<ref>See: <br><code>pnodeTrickle = vNodesCopy[GetRand(vNodesCopy.size())];</code><br>
an "addr" message, if appropriate.[3]
and <br><code>SendMessages(pnode, pnode == pnodeTrickle);</code><br> in ThreadMessageHandler2() in net.cpp.</ref> This node is the only one chosen to receive
an "addr" message, if appropriate.<ref>See:<br><code>
        //<br>
        // Message: addr<br>
        //<br>
        if (fSendTrickle)<br>
        {  </code><br>
in SendMessages() in main.cpp.</ref>


In the section for inventory, the client sends 1/4 of the transaction
In the section for inventory, the client sends 1/4 of the transaction
inventory, determined randomly [4], UNLESS they are the trickle node,
inventory, determined randomly<ref>See: <br><code>bool fTrickleWait = ((hashRand & 3) != 0);</code><br>
in which case they receive ALL transactions.[5] Yes that seems reversed,
in SendMessages() in main.cpp.</ref>, UNLESS they are the trickle node,
in which case they receive ALL transactions.<ref>See:<br><code>
        // trickle out tx inv to protect privacy<br>
        if (inv.type == MSG_TX && !fSendTrickle)<br>
        {  </code><br>
in SendMessages() in main.cpp.</ref> Yes, that seems reversed,
but it is what it is. If the node is to receive 1/4 (not all), then the
but it is what it is. If the node is to receive 1/4 (not all), then the
code also avoids sending any transactions that came from the local
code also avoids sending any transactions that came from the local
wallet.[6] The comments indicate this is intended to increase privacy.
wallet.<ref>See:<br><code>
 
        // always trickle our own transactions<br>
 
        if (!fTrickleWait)<br>
        {  <br>
            CWalletTx wtx;<br>
            if (GetTransaction(inv.hash, wtx))<br>
              if (wtx.fFromMe)<br>
                  fTrickleWait = true;<br>
        }</code><br>
in SendMessages() in main.cpp.</ref> The comments indicate this is intended to increase privacy.


== Relay ==
== Relay ==
Line 44: Line 60:
When the client receives a transaction via a "tx" messages,
When the client receives a transaction via a "tx" messages,
it calls RelayMessage, which calls RelayInventory, which queues the
it calls RelayMessage, which calls RelayInventory, which queues the
inventory to be sent to all other nodes.[7]
inventory to be sent to all other nodes.<ref>Both RelayMessage and RelayInventory in net.h.</ref>
 


==See Also==
[[Transaction_broadcasting | Transaction broadcasting]]


==Footnotes==
==Footnotes==
1. See CWallet::ResendWalletTransactions in wallet.cpp.
2. See:
      pnodeTrickle = vNodesCopy[GetRand(vNodesCopy.size())];
and
      SendMessages(pnode, pnode == pnodeTrickle);
in ThreadMessageHandler2() in net.cpp.
3. See:
        //
        // Message: addr
        //
        if (fSendTrickle)
        { 
in SendMessages() in main.cpp.
4. See:
      bool fTrickleWait = ((hashRand & 3) != 0);
in SendMessages() in main.cpp.
5. See:
        // trickle out tx inv to protect privacy
        if (inv.type == MSG_TX && !fSendTrickle)
        { 
in SendMessages() in main.cpp.
6. See:
        // always trickle our own transactions
        if (!fTrickleWait)
        { 
            CWalletTx wtx;
            if (GetTransaction(inv.hash, wtx))
              if (wtx.fFromMe)
                  fTrickleWait = true;
        }
in SendMessages() in main.cpp.
7. Both RelayMessage and RelayInventory in net.h.
[[Category:Developer]]
[[Category:Developer]]
[[Category:Technical]]
[[Category:Technical]]

Latest revision as of 14:24, 18 September 2015

Overview

The Satoshi client advertises locally generated transactions and relays transactions from other nodes. This article describes the operations that deal with this exchange of transactions.

Transactions are exchanged only if they are standard and valid.

Wallet Send

The client periodically calls SendMessages() (in main.cpp) which calls ResendWalletTransactions to send transactions generated locally. This routine looks to see if there has been a new block since last time, and if so, and the local transaction are still not in a block, then the transactions are sent to all nodes. This is done only about every 30 minutes.

Transactions are only rebroadcast if they have a timestamp at least 5 minutes older than the last block was received. They are sorted and sent oldest first.[1]

Periodic Advertisement

The client periodically calls SendMessages() (in main.cpp) which determines if a message should be sent to a remote node. For each message processing iteration, one node is chosen as the "trickle node".[2] This node is the only one chosen to receive an "addr" message, if appropriate.[3]

In the section for inventory, the client sends 1/4 of the transaction inventory, determined randomly[4], UNLESS they are the trickle node, in which case they receive ALL transactions.[5] Yes, that seems reversed, but it is what it is. If the node is to receive 1/4 (not all), then the code also avoids sending any transactions that came from the local wallet.[6] The comments indicate this is intended to increase privacy.

Relay

When the client receives a transaction via a "tx" messages, it calls RelayMessage, which calls RelayInventory, which queues the inventory to be sent to all other nodes.[7]

See Also

Transaction broadcasting

Footnotes

  1. See: CWallet::ResendWalletTransactions in wallet.cpp.
  2. See:
    pnodeTrickle = vNodesCopy[GetRand(vNodesCopy.size())];
    and
    SendMessages(pnode, pnode == pnodeTrickle);
    in ThreadMessageHandler2() in net.cpp.
  3. See:
    //
    // Message: addr
    //
    if (fSendTrickle)
    {

    in SendMessages() in main.cpp.
  4. See:
    bool fTrickleWait = ((hashRand & 3) != 0);
    in SendMessages() in main.cpp.
  5. See:
    // trickle out tx inv to protect privacy
    if (inv.type == MSG_TX && !fSendTrickle)
    {

    in SendMessages() in main.cpp.
  6. See:
    // always trickle our own transactions
    if (!fTrickleWait)
    {
    CWalletTx wtx;
    if (GetTransaction(inv.hash, wtx))
    if (wtx.fFromMe)
    fTrickleWait = true;
    }

    in SendMessages() in main.cpp.
  7. Both RelayMessage and RelayInventory in net.h.