Merge pull request #11090 from accumulator/self_dirty_qetransactionlistmodel
What changed, and why it matters
This commit is a code-quality refactor for Electrum's QML (mobile/light desktop) user interface. It moves responsibility for refreshing the transaction history list from one UI component into the transaction list model itself, and adds explicit 'mark dirty' calls when addresses are deleted. There is no direct evidence in the commit of a security vulnerability being fixed; it appears to address stale or missing UI updates in the transaction history view.
Treat as a normal functional/UI refactor. No urgent security action is indicated by the diff. If monitoring the PR, verify that the moved event listeners preserve existing behavior and that the explicit setDirty() call resolves the reported stale-history edge case.
Security signals we found
UI state synchronization refactor
Defensive dirty-flag marking on address deletion edge case
No input validation, cryptography, or privilege changes
No mention of vulnerability, CVE, or security fix in commit message
Evidence from the diff
The patch relocates event listeners (new_transaction, removed_transaction, adb_tx_height_changed, wallet_updated, payment_succeeded, request_status) that trigger refresh of the transaction history model from QEQmlWallet into QETransactionListModel. It also adds a setDirty() call in QEAddressDetails.deleteAddress() because wallet.delete_address may not fire adb_removed_tx when a removed address shares a transaction with another imported address. A minor bugfix changes self.wallet.wallet.can_delete_address() to self._wallet.wallet.can_delete_address(). The changes are defensive UI consistency improvements, not a patch for an exploitable flaw.
Changed components
electrum/gui/qml/qeaddressdetails.pyelectrum/gui/qml/qetransactionlistmodel.pyelectrum/gui/qml/qewallet.pyInspect captured patch +42 / −19
### electrum/gui/qml/qeaddressdetails.py
@@ -143,6 +143,8 @@ def deleteAddress(self):
assert self.canDelete
try:
self._wallet.wallet.delete_address(self._address)
+ # explicit mark-dirty, as delete_address is not guaranteed to trigger adb_removed_tx callback.
+ # (e.g. when the removed address shares a tx with another imported address)
self._wallet.historyModel.setDirty()
except UserFacingException as e:
self.addressDeleteFailed.emit(str(e))
@@ -166,5 +168,5 @@ def update(self):
if self._wallet.derivationPrefix:
self._derivationPath = self._derivationPath.replace('m', self._wallet.derivationPrefix)
self._numtx = self._wallet.wallet.adb.get_address_history_len(self._address)
- self._candelete = self.wallet.wallet.can_delete_address()
+ self._candelete = self._wallet.wallet.can_delete_address()
self.detailsChanged.emit()
### electrum/gui/qml/qetransactionlistmodel.py
@@ -7,6 +7,7 @@
from electrum.logging import get_logger
from electrum.util import Satoshis, TxMinedInfo
from electrum.address_synchronizer import TX_HEIGHT_FUTURE, TX_HEIGHT_LOCAL
+from electrum.invoices import PR_PAID
from electrum.gui.common_qt.util import QtEventListener, qt_event_listener
@@ -87,6 +88,44 @@ def on_event_labels_received(self, wallet, labels):
if wallet == self.wallet:
self.initModel(True) # TODO: be less dramatic
+ @qt_event_listener
+ def on_event_new_transaction(self, wallet, tx):
+ if wallet == self.wallet:
+ self.setDirty() # assuming wallet.is_up_to_date triggers after
+
+ @qt_event_listener
+ def on_event_removed_transaction(self, wallet, tx):
+ if wallet == self.wallet:
+ self.setDirty()
+
+ @qt_event_listener
+ def on_event_adb_tx_height_changed(self, adb, txid, old_height, new_height):
+ if adb == self.wallet.adb:
+ self._logger.debug(f'tx_height_changed {txid}. {old_height} -> {new_height}')
+ self.setDirty() # assuming wallet.is_up_to_date triggers after
+
+ @qt_event_listener
+ def on_event_wallet_updated(self, wallet):
+ if wallet == self.wallet:
+ if self.include_lightning:
+ self.setDirty() # lightning history changes don't come with tx events, see #9856
+ if wallet.is_up_to_date():
+ self.initModel() # refresh if dirty
+
+ @qt_event_listener
+ def on_event_payment_succeeded(self, wallet, key):
+ # only on include_lightning, as the payment_succeeded callback is lightning only
+ if wallet == self.wallet and self.include_lightning:
+ # TODO: we can probably just add the payment instead of recreating the whole history (expensive)
+ self.initModel(True)
+
+ @qt_event_listener
+ def on_event_request_status(self, wallet, key, status):
+ # only on include_lightning, as the new_transaction callback already handles on-chain
+ if wallet == self.wallet and status == PR_PAID and self.include_lightning:
+ # TODO: we can probably just add the payment instead of recreating the whole history (expensive)
+ self.initModel(True)
+
def rowCount(self, index):
return len(self.tx_history)
### electrum/gui/qml/qewallet.py
@@ -188,12 +188,6 @@ def on_event_request_status(self, wallet, key, status):
if wallet == self.wallet:
self._logger.debug('request status %d for key %s' % (status, key))
self.requestStatusChanged.emit(key, status)
- if status == PR_PAID:
- # might be new incoming LN payment, update history
- # TODO: only update if it was paid over lightning,
- # and even then, we can probably just add the payment instead
- # of recreating the whole history (expensive)
- self.historyModel.initModel(True)
@event_listener
def on_event_invoice_status(self, wallet, key, status):
@@ -206,36 +200,25 @@ def on_event_new_transaction(self, wallet: 'Abstract_Wallet', tx: Transaction):
if wallet == self.wallet:
self._logger.debug(f'new transaction {tx.txid()}')
self.add_tx_notification(tx)
- self.historyModel.setDirty() # assuming wallet.is_up_to_date triggers after
if self.wallet.is_up_to_date():
# don't update during sync as this recomputes the balance on each new tx, blocking the UI thread.
# on_event_wallet_updated emits balanceChanged once we are up-to-date.
self.balanceChanged.emit()
- @qt_event_listener
- def on_event_adb_tx_height_changed(self, adb, txid, old_height, new_height):
- if adb == self.wallet.adb:
- self._logger.debug(f'tx_height_changed {txid}. {old_height} -> {new_height}')
- self.historyModel.setDirty() # assuming wallet.is_up_to_date triggers after
-
@qt_event_listener
def on_event_removed_transaction(self, wallet, tx):
# NOTE: this event only triggers once, only for the first deleted tx, when for imported wallets an address
# is deleted along with multiple associated txs
if wallet == self.wallet:
self._logger.info(f'removed transaction {tx.txid()}')
- self.historyModel.setDirty()
self.balanceChanged.emit()
@qt_event_listener
def on_event_wallet_updated(self, wallet):
if wallet == self.wallet:
self._logger.debug('wallet_updated')
self.balanceChanged.emit()
- self.historyModel.setDirty()
self.synchronizing = not wallet.is_up_to_date()
- if not self.synchronizing:
- self.historyModel.initModel() # refresh if dirty
@event_listener
def on_event_channel(self, wallet, channel):
@@ -253,7 +236,6 @@ def on_event_channels_updated(self, wallet):
def on_event_payment_succeeded(self, wallet, key):
if wallet == self.wallet:
self.paymentSucceeded.emit(key)
- self.historyModel.initModel(True) # TODO: be less dramatic
@event_listener
def on_event_payment_failed(self, wallet, key, reason):Why this scored 22/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.