Skip to content

Commit

Permalink
wallet: (fix) "batch_rbf" must not mutate LN funding txs
Browse files Browse the repository at this point in the history
The "Batch RBF transactions" feature mutates existing "local" and "unconfirmed RBF"
transactions when creating new transactions: it simply adds the new outputs to the
existing txs (and updates the change).
The "RBF" flag is only enforced for unconfirmed txs, not for local txs.
The bug was that given a local LN funding tx, when creating a new channel
with "batch_rbf" enabled, we would modify the existing local tx, and
broadcast that.

related: spesmilo#7298
  • Loading branch information
SomberNight committed May 15, 2021
1 parent 9c1a515 commit b2169b7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions electrum/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,10 @@ def get_public_keys_with_deriv_info(self, address: str) -> Dict[bytes, Tuple[Key
"""Returns a map: pubkey -> (keystore, derivation_suffix)"""
return {}

def is_lightning_funding_tx(self, txid: str) -> bool:
return any([chan.funding_outpoint.txid == txid
for chan in self.lnworker.channels.values()])

def get_tx_info(self, tx: Transaction) -> TxWalletDetails:
tx_wallet_delta = self.get_wallet_delta(tx)
is_relevant = tx_wallet_delta.is_relevant
Expand All @@ -598,8 +602,7 @@ def get_tx_info(self, tx: Transaction) -> TxWalletDetails:
tx_hash = tx.txid() # note: txid can be None! e.g. when called from GUI tx dialog
is_lightning_funding_tx = False
if self.has_lightning() and tx_hash is not None:
is_lightning_funding_tx = any([chan.funding_outpoint.txid == tx_hash
for chan in self.lnworker.channels.values()])
is_lightning_funding_tx = self.is_lightning_funding_tx(tx_hash)
tx_we_already_have_in_db = self.db.get_transaction(tx_hash)
can_save_as_local = (is_relevant and tx.txid() is not None
and (tx_we_already_have_in_db is None or not tx_we_already_have_in_db.is_complete()))
Expand Down Expand Up @@ -1241,6 +1244,9 @@ def get_unconfirmed_base_tx_for_batching(self) -> Optional[Transaction]:
# all inputs should be is_mine
if not all([self.is_mine(self.get_txin_address(txin)) for txin in tx.inputs()]):
continue
# do not mutate LN funding txs, as that would change their txid
if self.is_lightning_funding_tx(txid):
continue
# prefer txns already in mempool (vs local)
if hist_item.tx_mined_status.height == TX_HEIGHT_LOCAL:
candidate = tx
Expand Down

0 comments on commit b2169b7

Please sign in to comment.