bitforge-me / beryllium

1 stars 9 forks source link

create withdrawal lock files to halt withdrawal processing if there was an error in the process #108

Closed djpnewton closed 1 year ago

djpnewton commented 1 year ago

When processing withdrawals there is a potential mismatch in state between the DB and the BTC wallet. Take the following example:

1. start withdrawal process (check balances etc)
2. make withdrawal via BTC wallet
3. set state to COMPLETED in DB

This is fine normally but what if the following happens:

1. start withdrawal process
2. make withdrawal via BTC wallet
3. critical EXECPTION occurs!

_five minutes passes_

1. start withdrawal process
2. make withdrawal via BTC wallet
3. critical EXECPTION occurs!

As you can see if there is an error in the process we could end up endlessly [over]paying the withdrawal. This PR changes the process to:

1. start withdrawal process
2. create LOCKFILE for withdrawal (important! exit and log error if lockfile already exists)
3. make withdrawal via BTC wallet
4. set state to COMPLETED in DB
5. remove LOCKFILE for withdrawal

If there is an error in the process the lockfile will stop overpayment and an admin will need to come and a) set the withdrawal to completed if it was completed and b) fix the error