Finance reconciliation found that the total of all account balances drops after some failed transfers. In one incident a transfer of 30 from account a (balance 100) to account b (balance 20) failed with a database error raised while updating b; afterwards a held 70, b still held 20, and 30 had disappeared. Bad requests misbehave too: a transfer to an account that does not exist reports an error but still takes the money from the source, and transfers from a missing account, to the same account, or of a negative amount are accepted without any error.
Fix transfer(connection, source, destination, amount) in transfer.py so a failed transfer never changes any balance.