I understand a Bitcoin client can request a transaction from another client on the network, effectively a pull request. However can a client push a transaction to another client on the network, a push request?
Yes, but they aren't supposed to.
The sequence is that a node sends its peers "inv" (inventory) messages. This is a list of transaction and/or block hashes that the node has.
They can contain a single hash. If the peer doesn't have the transaction, it then sends a "getdata" message to request the transaction(s). This prevents transactions being sent to nodes that already have them and wasting bandwidth. Hashes are still 32 bytes per transaction though, so still uses up some bandwidth.
Nodes can simply send transactions ("tx" messages) without being asked for them, but that wastes bandwidth and isn't the recommended way to do it.
If so:
- What triggers the transaction being sent?
When a node commits a transaction to its memory pool, it then notifies all peers that it has the transaction.
Committing a transaction to the memory pool means that the transaction is valid and all inputs are either in blocks or also in the memory pool.
The memory pool is the list of transactions that the node would include in any block it created.
- Can you specify who the recipient is?
Uh, not sure what you mean here. Nodes can send transactions to only certain peers if they want. The default operation is to broadcast the "inv" message.
If Bloom filters are used, then only transactions which match the bloom filters are sent.
- Can you point me to the code which implements this?
This is where new transactions are handled and the memory pool is checked
here. If they are accepted, then there is a call to relay them.
The relay call is in
net.cpp. This calls push inventory.