Skip to content

Commit

Permalink
Don't use non-change Rune UTXOs with too few confirmations
Browse files Browse the repository at this point in the history
  • Loading branch information
koirikivi committed May 14, 2024
1 parent a91c484 commit bfee7c8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions bridge_node/bridge/bridges/runes/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ def scan_rune_deposits(self):
deposit.net_amount_raw = amounts.net_amount_raw
deposit.rune_id = rune.id
if tx_confirmations >= required_confirmations and deposit.status == RuneDepositStatus.DETECTED:
assert deposit.status == RuneDepositStatus.DETECTED
deposit.status = RuneDepositStatus.ACCEPTED
dbsession.flush()

Expand Down
5 changes: 5 additions & 0 deletions bridge_node/bridge/bridges/runes/wiring.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,18 @@ def wire_rune_bridge(
base_url=_add_auth(config.ord_api_url, secrets.ord_api_auth),
)

min_non_change_rune_utxo_confirmations = config.btc_min_confirmations
if config.btc_network == "mainnet":
# We particularly don't want to have these race conditions on mainnet
min_non_change_rune_utxo_confirmations += 1
ord_multisig = OrdMultisig(
master_xpriv=secrets.btc_master_xpriv,
master_xpubs=secrets.btc_master_xpubs,
num_required_signers=config.btc_num_required_signers,
base_derivation_path=config.btc_base_derivation_path,
bitcoin_rpc=bitcoin_rpc,
ord_client=ord_client,
min_non_change_rune_utxo_confirmations=min_non_change_rune_utxo_confirmations,
)

evm_account = Account.from_key(secrets.evm_private_key)
Expand Down
13 changes: 13 additions & 0 deletions bridge_node/bridge/common/ord/multisig.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def __init__(
bitcoin_rpc: BitcoinRPC,
ord_client: OrdApiClient,
btc_wallet_name: str | None = None, # optional bitcoin wallet name for testing
min_non_change_rune_utxo_confirmations: int = 1,
):
_xprv = CCoinExtKey(master_xpriv)
self._get_master_xpriv = lambda: _xprv
Expand Down Expand Up @@ -108,6 +109,7 @@ def __init__(
)

self._btc_wallet_name = btc_wallet_name
self._min_non_change_rune_utxo_confirmations = min_non_change_rune_utxo_confirmations

@property
def name(self) -> str:
Expand Down Expand Up @@ -373,6 +375,17 @@ def add_psbt_input(utxo: UTXO):
# )
# continue

if utxo.address != self.change_address:
# We have a possible race condition in that a Rune UTXO from an user can be spent before it's processed,
# So we need to add some additional confirmations before using them.
if utxo.confirmations < self._min_non_change_rune_utxo_confirmations:
logger.info(
"Refusing to use non-change Rune UTXO %s with few confirmations (%s)",
utxo,
utxo.confirmations,
)
continue

relevant_rune_balances_in_utxo = {rune: ord_output.get_rune_balance(rune) for rune in used_runes}
if not any(relevant_rune_balances_in_utxo.values()):
# No runes in this UTXO
Expand Down

0 comments on commit bfee7c8

Please sign in to comment.