Detecting unconfirmed double spends using bitcoind I want to get statistics on how many percentage of unconfirmed tx in the mempool are having attempted double spends and having what value. For this I want to get notification when an unconfirmed tx arrives that is conflicting with existing tx in mempool. I understand that bitcoind will accept the first transaction it sees and reject the next one, can I configure/patch bitcoind to send me notification on such double spend attempt ?

PS: I understand that a double spend can happen by directly including new tx in the next block without ever showing up in unconfirmed tx list. I think that requires direct access to mining pool and enough guarantees that the block will be mined. For my experiment, I am fine with ignoring this case as it has low probability.
bitcoind has a debugging option named mempoolrej. You can enable this by adding

debug=mempoolrej


to your bitcoin.conf file.

This debugging options tells bitcoind to print out information about the transactions that it rejects from the mempool, including why. You can thus enable this option and tail and grep the debug.log file looking for the string

was not accepted


This string is only found in the mempoolrej message which is of the form 

&lt;txid&gt; from peer=&lt;peer id&gt; was not accepted: &lt;reason&gt;


The reason you are looking for is txn-mempool-conflict. So you can tail and grep for the entire string:

was not accepted: txn-mempool-conflict


Then with some bash-fu you can make this notify you whenever this string is found in the debug.log file.