Transaction isolation level/design for write-only ledger
Be sure to have FOR UPDATE on the end of the SELECTs.  Else another connection could sneak in and change the results of the SELECTs.

Also, steps 1,2,3 need to be inside a single TRANSACTION.

Once you do all that, you can probably leave the isolation level at the default.