AdamISZ / CoinSwapCS

Simple implementation of Bitcoin CoinSwap, client-server
GNU General Public License v3.0
31 stars 14 forks source link

Transaction watching via twisted/polling, not http server thread #33

Closed AdamISZ closed 7 years ago

AdamISZ commented 7 years ago

Leaving notes here for future reference:

This was motivated by realisation that torsocks wrapping of the client side fails (in fact, segfaults) as soon as the client starts the http server for receiving notifications (via BitcoinCoreInterface.add_tx_notify) on localhost. This is a bug in torsocks (this should be analyzed and reported), but in any case there are other reasons for switching to a polling approach to receive updates on transactions:

The final point is that because CoinSwap is not a very fast protocol, an "every few seconds" polling loop is absolutely no problem performance wise. It is a little awkward to keep track of spending out transactions though; but that complexity already existed. Here it is addressed by monitoring utxos dropping out of the listunspent return value, and then scanning with listtransactions and getrawtransaction to find where the utxo was used as input (is there a better way via RPC to do this?).

The return value of listtransactions is reversed to focus on the most recent transactions, to make sure that even users with very large transaction histories will have no trouble finding the relevant spend.

Note that #25 is still not yet addressed, specifically malleation of TX2/TX3 must still trigger the relevant code branch if malleated forms are broadcast.