Merge pull request #9842 from spesmilo/txbatcher_notenoughfunds
txbatcher: remove outputs if NotEnoughFunds is raised
This commit is contained in:
@@ -439,10 +439,16 @@ class TxBatch(Logger):
|
|||||||
to_sweep_now[k] = v
|
to_sweep_now[k] = v
|
||||||
else:
|
else:
|
||||||
self.wallet.add_future_tx(v, wanted_height)
|
self.wallet.add_future_tx(v, wanted_height)
|
||||||
if not to_pay and not to_sweep_now and not self._should_bump_fee(base_tx):
|
|
||||||
return
|
|
||||||
while True:
|
while True:
|
||||||
tx = self._create_batch_tx(base_tx, to_sweep_now, to_pay)
|
if not to_pay and not to_sweep_now and not self._should_bump_fee(base_tx):
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
tx = self._create_batch_tx(base_tx, to_sweep_now, to_pay)
|
||||||
|
except NotEnoughFunds:
|
||||||
|
k = max(to_pay, key=lambda x: x.value)
|
||||||
|
self.logger.info(f'Not enough funds, removing output {k}')
|
||||||
|
to_pay.remove(k)
|
||||||
|
continue
|
||||||
# 100 kb max standardness rule
|
# 100 kb max standardness rule
|
||||||
if tx.estimated_size() < 100_000:
|
if tx.estimated_size() < 100_000:
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -153,13 +153,21 @@ class TestTxBatcher(ElectrumTestCase):
|
|||||||
# to_self_payment tx1
|
# to_self_payment tx1
|
||||||
output1 = PartialTxOutput.from_address_and_value("tb1qyfnv3y866ufedugxxxfksyratv4pz3h78g9dad", 20_000)
|
output1 = PartialTxOutput.from_address_and_value("tb1qyfnv3y866ufedugxxxfksyratv4pz3h78g9dad", 20_000)
|
||||||
wallet.txbatcher.add_payment_output('default', output1, self.fee_policy_descriptor)
|
wallet.txbatcher.add_payment_output('default', output1, self.fee_policy_descriptor)
|
||||||
toself_tx = await self.network.next_tx()
|
tx1 = await self.network.next_tx()
|
||||||
assert len(toself_tx.outputs()) == 2
|
assert len(tx1.outputs()) == 2
|
||||||
assert output1 in toself_tx.outputs()
|
assert output1 in tx1.outputs()
|
||||||
|
|
||||||
# outgoing payment tx2
|
# outgoing payment tx2
|
||||||
output2 = PartialTxOutput.from_address_and_value("tb1qkfn0fude7z789uys2u7sf80kd4805zpvs3na0h", 90_000)
|
output2 = PartialTxOutput.from_address_and_value("tb1qkfn0fude7z789uys2u7sf80kd4805zpvs3na0h", 90_000)
|
||||||
wallet.txbatcher.add_payment_output('default', output2, self.fee_policy_descriptor)
|
wallet.txbatcher.add_payment_output('default', output2, self.fee_policy_descriptor)
|
||||||
|
# before tx1 gets confirmed, txbatch.create_transaction will raise notenoughfunds
|
||||||
|
await asyncio.sleep(wallet.txbatcher.SLEEP_INTERVAL)
|
||||||
|
|
||||||
|
# tx1 gets confirmed
|
||||||
|
wallet.adb.receive_tx_callback(tx1, tx_height=1)
|
||||||
|
tx_mined_status = wallet.adb.get_tx_height(tx1.txid())
|
||||||
|
wallet.adb.add_verified_tx(tx1.txid(), tx_mined_status._replace(conf=1))
|
||||||
|
|
||||||
tx2 = await self.network.next_tx()
|
tx2 = await self.network.next_tx()
|
||||||
assert len(tx2.outputs()) == 2
|
assert len(tx2.outputs()) == 2
|
||||||
assert output2 in tx2.outputs()
|
assert output2 in tx2.outputs()
|
||||||
|
|||||||
Reference in New Issue
Block a user