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.
This commit is contained in:
parent
e40b7c5584
commit
be853f563a
|
@ -38,6 +38,12 @@ static inline u32 minconf_to_maxheight(u32 minconf, struct lightningd *ld)
|
||||||
* selection */
|
* selection */
|
||||||
if (minconf == 0)
|
if (minconf == 0)
|
||||||
return 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;
|
return ld->topology->tip->height - minconf + 1;
|
||||||
}
|
}
|
||||||
#endif /* LIGHTNING_COMMON_WALLET_TX_H */
|
#endif /* LIGHTNING_COMMON_WALLET_TX_H */
|
||||||
|
|
|
@ -482,7 +482,7 @@ def test_withdraw(node_factory, bitcoind):
|
||||||
with pytest.raises(RpcError, match=r'Cannot afford transaction'):
|
with pytest.raises(RpcError, match=r'Cannot afford transaction'):
|
||||||
l1.rpc.withdraw(waddr, 'all')
|
l1.rpc.withdraw(waddr, 'all')
|
||||||
|
|
||||||
@pytest.mark.xfail(strict=True)
|
|
||||||
def test_minconf_withdraw(node_factory, bitcoind):
|
def test_minconf_withdraw(node_factory, bitcoind):
|
||||||
"""Issue 2518: ensure that ridiculous confirmation levels don't overflow
|
"""Issue 2518: ensure that ridiculous confirmation levels don't overflow
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue