Skip to content

Commit

Permalink
race condition btc failure
Browse files Browse the repository at this point in the history
  • Loading branch information
taureau75 committed Jun 14, 2023
1 parent aa5d7b5 commit 18a0709
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions scripts/eth_btc/btc_pay.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ async function makePayments() {
outgoing_amount = Number(outgoing_amount.toFixed(8));
if (walletInfo.balance < outgoing_amount) continue;

const select_deposit = await db.query("SELECT paid FROM bridges WHERE deposit_txid = $1", [bridge.deposit_txid]);
if (select_deposit.rows.length != 1 || select_deposit.rows[0].paid) throw new Error("Double payment? Race condition activated");

const update_paid = await db.query("UPDATE bridges SET paid=true WHERE deposit_txid = $1", [bridge.deposit_txid]);
if (update_paid.rowCount !== 1) throw new Error("Weird failure in paid update");

Expand Down
3 changes: 3 additions & 0 deletions scripts/eth_btc/eth_pay.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ async function makePayments() {
const outgoing_amount = ethers.BigNumber.from((bridge.deposit_amount * 0.998 * btc_price / eth_price * 1e18).toFixed(0)).sub(network_fee)
if (makerBalance.lt(outgoing_amount)) continue;

const select_deposit = await db.query("SELECT paid FROM bridges WHERE deposit_txid = $1", [bridge.deposit_txid]);
if (select_deposit.rows.length != 1 || select_deposit.rows[0].paid) throw new Error("Double payment? Race condition activated");

const update_paid = await db.query("UPDATE bridges SET paid=true WHERE deposit_txid = $1", [bridge.deposit_txid]);
if (update_paid.rowCount !== 1) throw new Error("Weird failure in paid update");

Expand Down

1 comment on commit 18a0709

@vercel
Copy link

@vercel vercel bot commented on 18a0709 Jun 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.