bitcoin/bitcoin — pull request #3883 by dgenr8 (2014-03-16 19:51:22+00:00)
Title: Relay first double spend transactions (rebase)

Rebased version of [#3354](https://github.com/bitcoin/bitcoin/pull/3354).

Instead of dropping double-spend transactions, relay them to peers. This is crucial to allowing all parts of the network to detect double-spend attempts as quickly as possible, i.e. reducing the "confirmation" time for buying coffee to a time on par with credit card transactions. Only the first respend seen is relayed.

I successfully completed a primary test running 3 copies of bitcoin-qt in regtest mode with this patch applied, connected in a **node1-newtorknode-node2** configuration.

I used the rawtransaction API for steps 2 and 3, but with -salvagewallet and a single funding transaction, tests would be possible that did not require rawtransactions.

Still TODO: Regression test plan

Primary Test Details
Step 1
- Send transaction from node1 to a node2 address
* * Transaction **is relayed** through networknode, to node2
* * Transaction appears in node2 wallet

Step 2
- Restart node1 with -salvagewallet (so it forgets about 1st spend)
- Send new transaction using same input (first double-spend), using rawtransaction API
* * Transaction **is relayed** through networknode, to node2
* * node2 does not accept the double-spend into its mempool and it does not appear in node2 wallet

Step 3
- Restart node1 with -salvagewallet again
- Send transaction using same input (second double spend), using rawtransaction API
* * Transaction **is not relayed** through networknode

Step 4
One more test for good measure
- Restart node1 with -salvagewallet again
- Using regular UI (not rawtransaction API), send entire wallet balance to node2 (third double spend). This included additional inputs besides the spent one.
* * Transaction **is not relayed** through networknode