Browse Source

wallet: Clamp maxheight to positive number for large minconf

Fixes #2518

Signed-off-by: Christian Decker <decker.christian@gmail.com>
Changelog-fixed: `minconf` no longer gets wrapped around for large values, which was causing funds with insufficient confirmations to be selected.
htlc_accepted_hook
Christian Decker 6 years ago
committed by neil saitug
parent
commit
be853f563a
  1. 6
      common/wallet_tx.h
  2. 2
      tests/test_misc.py

6
common/wallet_tx.h

@ -38,6 +38,12 @@ static inline u32 minconf_to_maxheight(u32 minconf, struct lightningd *ld)
* selection */
if (minconf == 0)
return 0;
/* Avoid wrapping around and suddenly allowing any confirmed
* outputs. Since we can't have a coinbase output, and 0 is taken for
* the disable case, we can just clamp to 1. */
if (minconf >= ld->topology->tip->height)
return 1;
return ld->topology->tip->height - minconf + 1;
}
#endif /* LIGHTNING_COMMON_WALLET_TX_H */

2
tests/test_misc.py

@ -482,7 +482,7 @@ def test_withdraw(node_factory, bitcoind):
with pytest.raises(RpcError, match=r'Cannot afford transaction'):
l1.rpc.withdraw(waddr, 'all')
@pytest.mark.xfail(strict=True)
def test_minconf_withdraw(node_factory, bitcoind):
"""Issue 2518: ensure that ridiculous confirmation levels don't overflow

Loading…
Cancel
Save