attempt UTXO check 5 times when UTXOs are less than the fee

This commit is contained in:
Lex Berezhny 2018-11-06 19:27:48 -05:00
parent 268e599423
commit 8fcbf48bdf

View file

@ -444,7 +444,7 @@ class BaseTransaction:
try: try:
for _ in range(2): for _ in range(5):
if payment < cost: if payment < cost:
deficit = cost - payment deficit = cost - payment
@ -471,7 +471,7 @@ class BaseTransaction:
if tx._outputs: if tx._outputs:
break break
else: 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 # whereby a single input is just enough to cover the fee and
# has some change left over, but the change left over is less # has some change left over, but the change left over is less
# than the cost_of_change: thus the input is completely # 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 # to be able to spend this input we must increase the cost
# of the TX and run through the balance algorithm a second time # of the TX and run through the balance algorithm a second time
# adding an extra input and change output, making tx valid. # 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) await tx.sign(funding_accounts)