diff --git a/electrum/transaction.py b/electrum/transaction.py index 9d971fd6f..ccb6305d0 100644 --- a/electrum/transaction.py +++ b/electrum/transaction.py @@ -1171,6 +1171,10 @@ class PartialTxInput(TxInput, PSBTSection): @classmethod def from_txin(cls, txin: TxInput, *, strip_witness: bool = True) -> 'PartialTxInput': + # FIXME: if strip_witness is True, res.is_segwit() will return False, + # and res.estimated_size() will return an incorrect value. These methods + # will return the correct values after we call add_input_info(). (see dscancel and bump_fee) + # This is very fragile: the value returned by estimate_size() depends on the calling order. res = PartialTxInput(prevout=txin.prevout, script_sig=None if strip_witness else txin.script_sig, nsequence=txin.nsequence, diff --git a/electrum/wallet.py b/electrum/wallet.py index 537258650..f918b1f3b 100644 --- a/electrum/wallet.py +++ b/electrum/wallet.py @@ -1394,12 +1394,12 @@ class Abstract_Wallet(AddressSynchronizer, ABC): if tx.is_final(): raise CannotBumpFee(_('Transaction is final')) new_fee_rate = quantize_feerate(new_fee_rate) # strip excess precision - old_tx_size = tx.estimated_size() try: # note: this might download input utxos over network tx.add_info_from_wallet(self, ignore_network_issues=False) except NetworkException as e: raise CannotBumpFee(repr(e)) + old_tx_size = tx.estimated_size() old_fee = tx.get_fee() assert old_fee is not None old_fee_rate = old_fee / old_tx_size # sat/vbyte @@ -1573,12 +1573,12 @@ class Abstract_Wallet(AddressSynchronizer, ABC): if tx.is_final(): raise CannotDoubleSpendTx(_('Transaction is final')) new_fee_rate = quantize_feerate(new_fee_rate) # strip excess precision - old_tx_size = tx.estimated_size() try: # note: this might download input utxos over network tx.add_info_from_wallet(self, ignore_network_issues=False) except NetworkException as e: raise CannotDoubleSpendTx(repr(e)) + old_tx_size = tx.estimated_size() old_fee = tx.get_fee() assert old_fee is not None old_fee_rate = old_fee / old_tx_size # sat/vbyte