Skip to content

Commit f24dc91

Browse files
committed
wallet: add "reserved_to_block" field to listfunds.
We already have this field in reserveinputs and unreserveinputs. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Changelog-Added: JSON-RPC: `listfunds` has a new `reserved_to_block` field.
1 parent 94419c7 commit f24dc91

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

doc/lightning-listfunds.7

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/lightning-listfunds.7.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Each entry in *outputs* will include:
3434
- *redeemscript* (the redeemscript of the output, in hex, only if it's p2sh-wrapped)
3535
- *status* (whether *unconfirmed*, *confirmed*, or *spent*)
3636
- *reserved* (whether this is UTXO is currently reserved for an in-flight tx)
37+
- *reserved_to_block* (when reservation expires, if *reserved* is true)
3738

3839
Each entry in *channels* will include:
3940
- *peer\_id* - the peer with which the channel is opened.

tests/test_misc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ def dont_spend_outputs(n, txid):
634634
for out in l1.rpc.listfunds()['outputs']:
635635
if out['reserved']:
636636
inputs += [{'txid': out['txid'], 'vout': out['output']}]
637+
assert out['reserved_to_block'] > bitcoind.rpc.getblockchaininfo()['blocks']
637638
l1.rpc.unreserveinputs(bitcoind.rpc.createpsbt(inputs, []))
638639

639640
# Test withdrawal to self.

tests/test_wallet.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,27 +441,34 @@ def test_reserveinputs(node_factory, bitcoind, chainparams):
441441
l1.rpc.reserveinputs(psbt)
442442

443443
assert all(o['reserved'] for o in l1.rpc.listfunds()['outputs'])
444+
reserveheight = bitcoind.rpc.getblockchaininfo()['blocks'] + 72
445+
assert all(o['reserved_to_block'] == reserveheight for o in l1.rpc.listfunds()['outputs'])
444446

445447
# Unreserve as a batch.
446448
psbt = bitcoind.rpc.createpsbt([{'txid': out[0], 'vout': out[1]} for out in outputs], [])
447449
l1.rpc.unreserveinputs(psbt)
448450
assert not any(o['reserved'] for o in l1.rpc.listfunds()['outputs'])
451+
assert not any('reserved_to_block' in o for o in l1.rpc.listfunds()['outputs'])
449452

450453
# Reserve twice fails unless exclusive.
451454
l1.rpc.reserveinputs(psbt)
452455
with pytest.raises(RpcError, match=r"already reserved"):
453456
l1.rpc.reserveinputs(psbt)
454457
l1.rpc.reserveinputs(psbt, False)
458+
assert all(o['reserved_to_block'] == reserveheight + 72 for o in l1.rpc.listfunds()['outputs'])
455459
l1.rpc.unreserveinputs(psbt)
456460
assert all(o['reserved'] for o in l1.rpc.listfunds()['outputs'])
461+
assert all(o['reserved_to_block'] == reserveheight for o in l1.rpc.listfunds()['outputs'])
457462

458463
# Stays reserved across restarts.
459464
l1.restart()
460465
assert all(o['reserved'] for o in l1.rpc.listfunds()['outputs'])
466+
assert all(o['reserved_to_block'] == reserveheight for o in l1.rpc.listfunds()['outputs'])
461467

462468
# Final unreserve works.
463469
l1.rpc.unreserveinputs(psbt)
464470
assert not any(o['reserved'] for o in l1.rpc.listfunds()['outputs'])
471+
assert not any('reserved_to_block' in o for o in l1.rpc.listfunds()['outputs'])
465472

466473

467474
def test_fundpsbt(node_factory, bitcoind, chainparams):

wallet/walletrpc.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ static void json_add_utxo(struct json_stream *response,
247247
const struct utxo *utxo)
248248
{
249249
const char *out;
250+
bool reserved;
250251

251252
json_object_start(response, fieldname);
252253
json_add_txid(response, "txid", &utxo->txid);
@@ -284,9 +285,12 @@ static void json_add_utxo(struct json_stream *response,
284285
} else
285286
json_add_string(response, "status", "unconfirmed");
286287

287-
json_add_bool(response, "reserved",
288-
utxo_is_reserved(utxo,
289-
get_block_height(wallet->ld->topology)));
288+
reserved = utxo_is_reserved(utxo,
289+
get_block_height(wallet->ld->topology));
290+
json_add_bool(response, "reserved", reserved);
291+
if (reserved)
292+
json_add_num(response, "reserved_to_block",
293+
utxo->reserved_til);
290294
json_object_end(response);
291295
}
292296

0 commit comments

Comments
 (0)