From 14eddb95bae30dd9d95de6a3c0008a17a896b6d8 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 26 May 2021 10:49:38 +0930 Subject: [PATCH] fundchannel, multifundchannel: reserve inputs for two weeks, not 12 hours. Signed-off-by: Rusty Russell Changelog-Changed: Plugins: `fundchannel` and `multifundchannel` will now reserve funding they use for 2 weeks instead of 12 hours. --- plugins/spender/multifundchannel.c | 14 ++++++++++++-- tests/test_connection.py | 11 ++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/plugins/spender/multifundchannel.c b/plugins/spender/multifundchannel.c index 3ce71b8bd1b6..72fbe4e8cacf 100644 --- a/plugins/spender/multifundchannel.c +++ b/plugins/spender/multifundchannel.c @@ -205,6 +205,7 @@ mfc_cleanup_psbt(struct command *cmd, } json_add_psbt(req->js, "psbt", take(pruned_psbt)); + json_add_u32(req->js, "reserve", 2016); send_outreq(cmd->plugin, req); } @@ -651,6 +652,9 @@ after_signpsbt(struct command *cmd, &mfc_forward_error, mfc); json_add_psbt(req->js, "psbt", mfc->psbt); + /* We already reserved inputs by 2 weeks, we don't need + * another 72 blocks. */ + json_add_u32(req->js, "reserve", 0); return send_outreq(mfc->cmd->plugin, req); } @@ -1405,8 +1409,14 @@ perform_fundpsbt(struct multifundchannel_command *mfc) json_add_u32(req->js, "minconf", mfc->minconf); } - /* The entire point is to reserve the inputs. */ - json_add_bool(req->js, "reserve", true); + /* The entire point is to reserve the inputs. */ + /* BOLT #2: + * The sender: + *... + * - SHOULD ensure the funding transaction confirms in the next 2016 + * blocks. + */ + json_add_u32(req->js, "reserve", 2016); /* How much do we need to reserve? */ if (has_all(mfc)) json_add_string(req->js, "satoshi", "all"); diff --git a/tests/test_connection.py b/tests/test_connection.py index a67de1899537..a44103d2933b 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -260,11 +260,12 @@ def test_channel_abandon(node_factory, bitcoind): opening_utxo = only_one([o for o in l1.rpc.listfunds()['outputs'] if o['reserved']]) psbt = l1.rpc.utxopsbt(0, "253perkw", 0, [opening_utxo['txid'] + ':' + str(opening_utxo['output'])], reserve=False, reservedok=True)['psbt'] - # Unreserve until it's considered unreserved. - count = 0 - while only_one(l1.rpc.unreserveinputs(psbt)['reservations'])['reserved']: - count += 1 - assert count == 1 + # We expect a reservation for 2016 blocks; unreserve it. + reservations = only_one(l1.rpc.unreserveinputs(psbt, reserve=2015)['reservations']) + assert reservations['reserved'] + assert reservations['reserved_to_block'] == bitcoind.rpc.getblockchaininfo()['blocks'] + 1 + + assert only_one(l1.rpc.unreserveinputs(psbt, reserve=1)['reservations'])['reserved'] is False # Now it's unreserved, we can doublespend it (as long as we exceed # previous fee to RBF!).