diff --git a/torba/client/basetransaction.py b/torba/client/basetransaction.py index cd46a33ad..e0b63fce9 100644 --- a/torba/client/basetransaction.py +++ b/torba/client/basetransaction.py @@ -444,7 +444,7 @@ class BaseTransaction: try: - for _ in range(2): + for _ in range(5): if payment < cost: deficit = cost - payment @@ -471,7 +471,7 @@ class BaseTransaction: if tx._outputs: break else: - # this condition and the outer range(2) loop cover an edge case + # this condition and the outer range(5) loop cover an edge case # whereby a single input is just enough to cover the fee and # has some change left over, but the change left over is less # than the cost_of_change: thus the input is completely @@ -479,7 +479,9 @@ class BaseTransaction: # to be able to spend this input we must increase the cost # of the TX and run through the balance algorithm a second time # adding an extra input and change output, making tx valid. - cost = cost + cost_of_change + 1 + # we do this 5 times in case the other UTXOs added are also + # less than the fee, after 5 attempts we give up and go home + cost += cost_of_change + 1 await tx.sign(funding_accounts)