So, my question is, what wallet and account solution mining pools use? What software cryptsy, btc-e and bitstamp use?
custom stuff. it's not easy/cheap to have 100% security. there is no account solution. you have bitcoind which generates N addresses. then you have your own account database and do a 1:1 mapping. move is a simple as doing an update on your own database.
Sure, I could build everything by myself, but there are many problems such as data integrity between my app and wallet software, HUGE number of problems with non-atomic functionality, etc.
I don't understand - what are the details? no bitcoin transaction is atomic for small latencies. what kind of micropayments?? bitcoind has not implemented micropayments, only bitcoinj. I've not seen anybody using it.
Data integrity: Lets say I do not use bitcoind accounts. I have N addresses in Wallet and my own SQL database with addr-user (n:1) mapping. I really need user to have many addresses. So, when I display
addr A to some user, I have to check for transactions to the
addr A in some point in time and update my SQL - cron could be my friend in this case.
But, I have to scan all the addresses in my SQL with current balance to find out user balance! I have to use "deep" scan - I can not assume each address has static balance - the wallet sends btc from addresses it decides are optimal. So, I have to use for example blockchain.info API where I can pass many addresses with minconf and it returns balance from corresponding TXs which have minconf confirmations.
Edit: yes, it is abstraction "address has balance" - addresses have transactions, transactions have amounts, so "addresses have balances"I am sure bitcoind's rpc functions do not support many addresses as input and not sure if it could retrieve balance at minconf from one addr either.
It is pointless to cache user balances in SQL, because it may be changed at every user withdrawal. No way to say "send ONLY from THIS address".
And many more problems...
Atomic or synchronization problems: User wants withdrawal:
0. I need to set set semaphore/lock or make this withdrawal function serialized.
1. I deep-rescan his balance B1.
2. From this moment, the actual balance A1 >= B1 (he could send funds to his addr in the meantime).
3. The second withdrawal (attack attempt) comes at this time. Because of point zero 0, it waits blocked.
4a. If point 0. does not exists, each of two or more server instances/threads retrieved balance B1 (in fact, B1 and B2, B1==B2 or B1!=B2) and I command my wallet "send B1 amount to some user address" - two times!
4b. If point 0. exists, I commant my wallet "send B1 amount to some user address" - only once.
5. Withdrawal function ends and unlocks second attempt to withdrawal, which continues from point 1.
bitcoind provides sendfrom
[minconfirm=1] which is atomic function and fails if there is not enough balance "in the minconfirm state". test-and-do atomic operation.
The bitcoind account functionality in terms of problems like this is almost perfect. Yes, there are problems like it test-and-do balance with no fees includes and it may results in negative account balance, but this is intended and there are reasons for this behavior.
It is difficult (at least for me) to code two separate systems which must be synchronized.