electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit 01ed5e7345ba2c0960b2cea6aa2aed2a942a2495
parent b080df9cff55675935ca3649c6aaa01e8e667b37
Author: SomberNight <somber.night@protonmail.com>
Date:   Sat, 13 Feb 2021 03:29:23 +0100

wallet.bump_fee: (fix) method2 was bumping too much if output was rm-ed

regression from bafe8a2fff1077de7a19a32dc359df5f12a2e32c

Diffstat:
Melectrum/tests/test_wallet_vertical.py | 10+++++-----
Melectrum/wallet.py | 11+++++------
2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/electrum/tests/test_wallet_vertical.py b/electrum/tests/test_wallet_vertical.py @@ -1027,7 +1027,7 @@ class TestWalletSending(TestCaseForTestnet): tx.version = 2 if simulate_moving_txs: partial_tx = tx.serialize_as_bytes().hex() - self.assertEqual("70736274ff01005502000000014e679224851da8e67493fb536ab1d3ecf7b9f64ccdeff2ef1b717b5f61d8980d0000000000fdffffff01d4ed0600000000001976a914ac55156f62fa9085c114fc6496aee5ab153cb22888ac14f71c00000100e102000000000101a3a9d94039c1051102e36b835764b89985602608a3e121c91cb63d67277355080100000000fdffffff0220a10700000000001976a9143decc30f4f7eec45c5775347050b85a43ac7ee0b88ac203c3500000000001600149d91f0053172fab394d277ae27e9fa5c5a4921090247304402207a2b4abe2c4128fe80db297d636b81487feda2ee3c51a95bc670b7b377b09ca402205147bc550dfdff72e9159554c19045111daf6d95f556a4f4dc370c90aa37a3e0012102cccad56b36e7bd1ae44c37d69019d006d8911b43071725d6dcbbdfcade05650313f71c00220603d4ce4ba5be0b861d2ee7c715b84ab0e791ccd36530bd8652babae37eda693c390c11aad9ae000000000000000000220203feceda5212994b3552847c93288c47490404784d90f1966b7d02e009ba40680e0c11aad9ae000000000100000000", + self.assertEqual("70736274ff01005502000000014e679224851da8e67493fb536ab1d3ecf7b9f64ccdeff2ef1b717b5f61d8980d0000000000fdffffff01200b0700000000001976a914ac55156f62fa9085c114fc6496aee5ab153cb22888ac14f71c00000100e102000000000101a3a9d94039c1051102e36b835764b89985602608a3e121c91cb63d67277355080100000000fdffffff0220a10700000000001976a9143decc30f4f7eec45c5775347050b85a43ac7ee0b88ac203c3500000000001600149d91f0053172fab394d277ae27e9fa5c5a4921090247304402207a2b4abe2c4128fe80db297d636b81487feda2ee3c51a95bc670b7b377b09ca402205147bc550dfdff72e9159554c19045111daf6d95f556a4f4dc370c90aa37a3e0012102cccad56b36e7bd1ae44c37d69019d006d8911b43071725d6dcbbdfcade05650313f71c00220603d4ce4ba5be0b861d2ee7c715b84ab0e791ccd36530bd8652babae37eda693c390c11aad9ae000000000000000000220203feceda5212994b3552847c93288c47490404784d90f1966b7d02e009ba40680e0c11aad9ae000000000100000000", partial_tx) tx = tx_from_any(partial_tx) # simulates moving partial txn between cosigners self.assertFalse(tx.is_complete()) @@ -1036,13 +1036,13 @@ class TestWalletSending(TestCaseForTestnet): self.assertTrue(tx.is_complete()) self.assertFalse(tx.is_segwit()) tx_copy = tx_from_any(tx.serialize()) - self.assertEqual('02000000014e679224851da8e67493fb536ab1d3ecf7b9f64ccdeff2ef1b717b5f61d8980d000000006a473044022024ce838fb02d482ca33872197175a15fed66cf139ebcdb4cc840e227273a15f70220466306a037f2b9f9702b4a331672efcadde32a4df25dc4e28abd019b68eb2761012103d4ce4ba5be0b861d2ee7c715b84ab0e791ccd36530bd8652babae37eda693c39fdffffff01d4ed0600000000001976a914ac55156f62fa9085c114fc6496aee5ab153cb22888ac14f71c00', + self.assertEqual('02000000014e679224851da8e67493fb536ab1d3ecf7b9f64ccdeff2ef1b717b5f61d8980d000000006a473044022043b34ed26822f120a2454aa9dd271400883e5c7133d3cd58ac018ddfa8ba4648022010394ca68edaf75df31217d3097f1171a87c846facfd963e49618fb1af89b66d012103d4ce4ba5be0b861d2ee7c715b84ab0e791ccd36530bd8652babae37eda693c39fdffffff01200b0700000000001976a914ac55156f62fa9085c114fc6496aee5ab153cb22888ac14f71c00', str(tx_copy)) - self.assertEqual('198d85f7a2ab342f1d98c6838ef1d68fb79d10cb1c1842a5b152d4fffefbe483', tx_copy.txid()) - self.assertEqual('198d85f7a2ab342f1d98c6838ef1d68fb79d10cb1c1842a5b152d4fffefbe483', tx_copy.wtxid()) + self.assertEqual('9599a45a566251a5949b4f4b4a5f8d9a34c9e38e1ead9337c8338e34ea5bcd6e', tx_copy.txid()) + self.assertEqual('9599a45a566251a5949b4f4b4a5f8d9a34c9e38e1ead9337c8338e34ea5bcd6e', tx_copy.wtxid()) wallet.receive_tx_callback(tx.txid(), tx, TX_HEIGHT_UNCONFIRMED) - self.assertEqual((0, 454100, 0), wallet.get_balance()) + self.assertEqual((0, 461600, 0), wallet.get_balance()) @mock.patch.object(wallet.Abstract_Wallet, 'save_db') diff --git a/electrum/wallet.py b/electrum/wallet.py @@ -1549,7 +1549,7 @@ class Abstract_Wallet(AddressSynchronizer, ABC): tx.add_info_from_wallet(self) assert tx.get_fee() is not None inputs = tx.inputs() - outputs = list(tx.outputs()) + outputs = tx._outputs # note: we will mutate this directly # use own outputs s = list(filter(lambda o: self.is_mine(o.address), outputs)) @@ -1559,14 +1559,14 @@ class Abstract_Wallet(AddressSynchronizer, ABC): x_fee = run_hook('get_tx_extra_fee', self, tx) if x_fee: x_fee_address, x_fee_amount = x_fee - s = filter(lambda o: o.address != x_fee_address, s) + s = list(filter(lambda o: o.address != x_fee_address, s)) if not s: raise CannotBumpFee('No outputs at all??') # prioritize low value outputs, to get rid of dust s = sorted(s, key=lambda o: o.value) for o in s: - target_fee = int(round(tx.estimated_size() * new_fee_rate)) + target_fee = int(math.ceil(tx.estimated_size() * new_fee_rate)) delta = target_fee - tx.get_fee() i = outputs.index(o) if o.value - delta >= self.dust_threshold(): @@ -1577,9 +1577,8 @@ class Abstract_Wallet(AddressSynchronizer, ABC): break else: del outputs[i] - delta -= o.value - # note: delta might be negative now, in which case - # the value of the next output will be increased + # note: we mutated the outputs of tx, which will affect + # tx.estimated_size() in the next iteration if delta > 0: raise CannotBumpFee(_('Could not find suitable outputs'))