In previous version we had deposit collection flow based on amqp daemon (deposit_collection_fees, deposit_collection)
Legacy deposit process diagram:
deposit_collection daemon processing message and trying to collect deposit depending on the deposit spread.
The main problem for this approach that we don't wait till the transaction that we generated in the deposit_collection_fees daemon successfully executed and we are failing on deposit collection in the last step (it happens mostly for each erc20 deposit). Also, there is some chance that we can miss amqp message due to server instability.
We decided to remove to AMQP base deposit daemons and create a new deposit daemon that will work on deposit states changes and will prevent immediate proceeding of erc20 deposits.
New deposit process diagram:
processingdeposits we are checking if plugin implement method
prepare_deposit_collection!if it doesn't we immediately process the deposit and collect deposit to the
coldwallets. If plugin implement method
prepare_deposit_collection!daemon processing of collection fees and change deposit state to
fee_processing. For deposits with
fee_processingstate, we select each minute deposits that have
updated_atolder than 5 minutes and process them. With time condition we are sure that fee transaction has already been executed.
In 3.1 release we are intoducing new feature - recording expenses on blockchain transactions.
Deposits now have 3 new states:
Accepted -> Processing -> Collecting -> Collected
Now, instead of marking deposit as collected right after sending collection transaction, we put it into
Then, as soon, as Peatio process block with this transaction, we confirm transaction success, record expenses related to fee we spent and put deposit in
Accepted -> Processing -> Fee_Collecting -> Fee_Collected-> Collecting -> Collected
After sending fees from Fee wallet to user payment address, instead of waiting for 5 minutes, we are waiting for the block with this transaction to being processed by Blockchain daemon. As soon, as Peatio process target block, deposit state is changed to Fee_Collected.
When fees arrives to user payment address, we are creating deposit collection transaction and change deposit state to
collecting. After that, the flow is the same as for Coin deposit.