Browse Source

Merge #868: When selecting utxos in yg, count in that change should be above dust threshold already on the first try

8639a96243 When selecting utxos in yg, count in that change should be above dust threshold already on the first try (Kristaps Kaupe)

Pull request description:

  <del>Should reduce number of</del> <ins>Eliminates</ins> the following errors for yield generators in cases when mixdepth with too low number of satoshis above cj amount + dust is choosen instead of different one with bigger balance.
  ```
  2021-05-06 10:00:01,998 [INFO]  filling offer, mixdepth=X, amount=YYY
  2021-05-06 10:00:02,236 [INFO]  sending output to address=ZZZ
  2021-05-06 10:00:02,428 [INFO]  dont have the required UTXOs to make a output above the dust threshold, quitting
  2021-05-06 10:00:02,428 [INFO]  Maker refuses to continue on receiving auth.
  ```
  Also makes code simpler. Test suite has specific tests for this case (that `if change_value <= jm_single().DUST_THRESHOLD` path in old code is chosen), they pass.

Top commit has no ACKs.

Tree-SHA512: 3e4f59fed41843baa783e80382f8e85d50fb8b7a88e1107155cda02ac43e27a859a0986f5a616230613babc77d6ba33606663c9132c2c1b651138c1e7a043b34
master
Kristaps Kaupe 5 years ago
parent
commit
7274f7fbf2
No known key found for this signature in database
GPG Key ID: 33E472FE870C7E5D
  1. 23
      jmclient/jmclient/yieldgenerator.py

23
jmclient/jmclient/yieldgenerator.py

@ -114,11 +114,14 @@ class YieldGeneratorBasic(YieldGenerator):
def oid_to_order(self, offer, amount):
total_amount = amount + offer["txfee"]
mix_balance = self.get_available_mixdepths()
real_cjfee = calc_cj_fee(offer["ordertype"], offer["cjfee"], amount)
required_amount = total_amount + \
jm_single().DUST_THRESHOLD + 1 - real_cjfee
mix_balance = self.get_available_mixdepths()
filtered_mix_balance = {m: b
for m, b in mix_balance.items()
if b >= total_amount}
if b >= required_amount}
if not filtered_mix_balance:
return None, None, None
jlog.debug('mix depths that have enough = ' + str(filtered_mix_balance))
@ -134,22 +137,8 @@ class YieldGeneratorBasic(YieldGenerator):
change_addr = self.wallet_service.get_internal_addr(mixdepth)
utxos = self.wallet_service.select_utxos(mixdepth, total_amount,
utxos = self.wallet_service.select_utxos(mixdepth, required_amount,
minconfs=1, includeaddr=True)
my_total_in = sum([va['value'] for va in utxos.values()])
real_cjfee = calc_cj_fee(offer["ordertype"], offer["cjfee"], amount)
change_value = my_total_in - amount - offer["txfee"] + real_cjfee
if change_value <= jm_single().DUST_THRESHOLD:
jlog.debug(('change value={} below dust threshold, '
'finding new utxos').format(change_value))
try:
utxos = self.wallet_service.select_utxos(mixdepth,
total_amount + jm_single().DUST_THRESHOLD,
minconfs=1, includeaddr=True)
except Exception:
jlog.info('dont have the required UTXOs to make a '
'output above the dust threshold, quitting')
return None, None, None
return utxos, cj_addr, change_addr

Loading…
Cancel
Save