Skip to content

Commit

Permalink
fundchannel, multifundchannel: reserve inputs for two weeks, not 12 h…
Browse files Browse the repository at this point in the history
…ours.

Signed-off-by: Rusty Russell <[email protected]>
Changelog-Changed: Plugins: `fundchannel` and `multifundchannel` will now reserve funding they use for 2 weeks instead of 12 hours.
  • Loading branch information
rustyrussell committed May 26, 2021
1 parent efe29c9 commit 14eddb9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
14 changes: 12 additions & 2 deletions plugins/spender/multifundchannel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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");
Expand Down
11 changes: 6 additions & 5 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!).
Expand Down

0 comments on commit 14eddb9

Please sign in to comment.