Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dual funding -> API changes/breakage #5670

Merged
merged 19 commits into from
Feb 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
0a8d942
dual-fund: update extracted CSVs to latest bolt draft
m-schmoock Jul 11, 2022
12843d4
dual-fund: update to latest, add in updates to rbf amounts
niftynei Jul 14, 2022
0b00be7
dual-fund: on re-init, re-populate opener_funding/accepter_funding
niftynei Oct 19, 2022
1d50947
df tests: use the amount from the logs to check for!
niftynei Oct 19, 2022
811720f
openingd: pull out validation for shutdown script
niftynei Oct 19, 2022
a9249db
dual-fund: validate upfront shutdown using taproot + anchors
niftynei Oct 19, 2022
c92fdb2
opening: helper for anchor flagged, use in dualopend also
niftynei Oct 19, 2022
f4a3de7
dual-fund: check features to print (anchors not assumed)
niftynei Oct 19, 2022
db88b7b
dual-fund: remove anchor assumption for all dual-funded channels
niftynei Oct 19, 2022
3e937d3
dual-fund: only allow for liquidity ads if both nodes support anchors
niftynei Oct 19, 2022
c05262d
connectd: patch valgrind error w/ buffers for error msgs
niftynei Oct 19, 2022
a7da33d
tests: anchors is only EXPERIMENTAL_FEATURES
niftynei Oct 19, 2022
90d7d25
tests: check that non-anchor opens can't use liquidity ads
niftynei Oct 19, 2022
4f5b8a7
dual-fund: patch in channel_type logic
niftynei Oct 21, 2022
a887dcd
test: restart node during rbf
niftynei Oct 24, 2022
8b70405
dual-open-rbf: remember the requested lease amount btw restarts
niftynei Oct 24, 2022
04340c5
fundpsbt: add option to filter out wrapped p2sh inputs
niftynei Oct 26, 2022
3f8bec1
upgradewallet: JSONRPC call to update p2sh outputs to a native segwit
niftynei Oct 26, 2022
62af76d
v2 opens: don't use p2sh inputs for v2 opens
niftynei Oct 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -2270,13 +2270,14 @@ static void peer_in(struct peer *peer, const u8 *msg)
case WIRE_TX_ADD_OUTPUT:
case WIRE_TX_REMOVE_OUTPUT:
case WIRE_TX_COMPLETE:
case WIRE_TX_ABORT:
case WIRE_OPEN_CHANNEL2:
case WIRE_ACCEPT_CHANNEL2:
case WIRE_TX_SIGNATURES:
handle_unexpected_tx_sigs(peer, msg);
return;
case WIRE_INIT_RBF:
case WIRE_ACK_RBF:
case WIRE_TX_INIT_RBF:
case WIRE_TX_ACK_RBF:
break;

case WIRE_CHANNEL_REESTABLISH:
Expand Down
4 changes: 4 additions & 0 deletions common/channel_type.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ struct channel_type *default_channel_type(const tal_t *ctx,
if (feature_negotiated(our_features, their_features,
OPT_ANCHOR_OUTPUTS))
return channel_type_anchor_outputs(ctx);
else if (feature_negotiated(our_features, their_features,
OPT_DUAL_FUND))
/* OPT_DUAL_FUND implies static remotekey */
return channel_type_static_remotekey(ctx);
/* BOLT #2:
* - otherwise, if `option_static_remotekey` was negotiated:
* - the `channel_type` is `option_static_remotekey` (bit 12)
Expand Down
4 changes: 2 additions & 2 deletions common/features.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ static const struct dependency feature_deps[] = {
/* BOLT-f53ca2301232db780843e894f55d95d512f297f9 #9:
* Name | Description | Context | Dependencies |
* ...
* `option_dual_fund` | ... | ... | `option_anchor_outputs`
* `option_dual_fund` | ... | ... | `option_static_remotekey`
*/
{ OPT_DUAL_FUND, OPT_ANCHOR_OUTPUTS },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No explicit signalling needed anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've removed the implicit dependence on anchor_outputs, instead we just assume that static_remotekey is required.

{ OPT_DUAL_FUND, OPT_STATIC_REMOTEKEY },
/* BOLT-route-blinding #9:
* Name | Description | Context | Dependencies |
* ...
Expand Down
9 changes: 5 additions & 4 deletions connectd/connectd.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <wire/wire_io.h>
#include <wire/wire_sync.h>

/*~ We are passed two file descriptors when exec'ed from `lightningd`: the
Expand Down Expand Up @@ -305,8 +306,8 @@ struct io_plan *peer_connected(struct io_conn *conn,
status_peer_unusual(id, "Unsupported feature %u", unsup);
msg = towire_warningfmt(NULL, NULL, "Unsupported feature %u",
unsup);
msg = cryptomsg_encrypt_msg(tmpctx, cs, take(msg));
return io_write(conn, msg, tal_count(msg), io_close_cb, NULL);
msg = cryptomsg_encrypt_msg(NULL, cs, take(msg));
return io_write_wire(conn, take(msg), io_close_cb, NULL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, just verified that io_write_wire takes data, despite not being annotated as such. It uses tal_dup_talarr which is marked as TAKES

}

if (!feature_check_depends(their_features, &depender, &missing)) {
Expand All @@ -315,8 +316,8 @@ struct io_plan *peer_connected(struct io_conn *conn,
msg = towire_warningfmt(NULL, NULL,
"Feature %zu requires feature %zu",
depender, missing);
msg = cryptomsg_encrypt_msg(tmpctx, cs, take(msg));
return io_write(conn, msg, tal_count(msg), io_close_cb, NULL);
msg = cryptomsg_encrypt_msg(NULL, cs, take(msg));
return io_write_wire(conn, take(msg), io_close_cb, NULL);
}

/* We've successfully connected. */
Expand Down
5 changes: 3 additions & 2 deletions connectd/gossip_rcvd_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ static bool is_msg_gossip_broadcast(const u8 *cursor)
case WIRE_TX_REMOVE_OUTPUT:
case WIRE_TX_COMPLETE:
case WIRE_TX_SIGNATURES:
case WIRE_TX_INIT_RBF:
case WIRE_TX_ACK_RBF:
case WIRE_TX_ABORT:
case WIRE_OPEN_CHANNEL2:
case WIRE_ACCEPT_CHANNEL2:
case WIRE_INIT_RBF:
case WIRE_ACK_RBF:
#if EXPERIMENTAL_FEATURES
case WIRE_STFU:
#endif
Expand Down
5 changes: 3 additions & 2 deletions connectd/gossip_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ static bool public_msg_type(enum peer_wire type)
case WIRE_CHANNEL_READY:
case WIRE_OPEN_CHANNEL2:
case WIRE_ACCEPT_CHANNEL2:
case WIRE_INIT_RBF:
case WIRE_ACK_RBF:
case WIRE_TX_INIT_RBF:
case WIRE_TX_ACK_RBF:
case WIRE_TX_ABORT:
case WIRE_SHUTDOWN:
case WIRE_CLOSING_SIGNED:
case WIRE_UPDATE_ADD_HTLC:
Expand Down
5 changes: 3 additions & 2 deletions connectd/multiplex.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ static bool is_urgent(enum peer_wire type)
case WIRE_TX_REMOVE_INPUT:
case WIRE_TX_REMOVE_OUTPUT:
case WIRE_TX_COMPLETE:
case WIRE_TX_ABORT:
case WIRE_TX_SIGNATURES:
case WIRE_OPEN_CHANNEL:
case WIRE_ACCEPT_CHANNEL:
Expand All @@ -363,8 +364,8 @@ static bool is_urgent(enum peer_wire type)
case WIRE_CHANNEL_READY:
case WIRE_OPEN_CHANNEL2:
case WIRE_ACCEPT_CHANNEL2:
case WIRE_INIT_RBF:
case WIRE_ACK_RBF:
case WIRE_TX_INIT_RBF:
case WIRE_TX_ACK_RBF:
case WIRE_SHUTDOWN:
case WIRE_CLOSING_SIGNED:
case WIRE_UPDATE_ADD_HTLC:
Expand Down
1 change: 1 addition & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ Core Lightning Documentation
lightning-txprepare <lightning-txprepare.7.md>
lightning-txsend <lightning-txsend.7.md>
lightning-unreserveinputs <lightning-unreserveinputs.7.md>
lightning-upgradewallet <lightning-upgradewallet.7.md>
lightning-utxopsbt <lightning-utxopsbt.7.md>
lightning-waitanyinvoice <lightning-waitanyinvoice.7.md>
lightning-waitblockheight <lightning-waitblockheight.7.md>
Expand Down
3 changes: 3 additions & 0 deletions doc/lightning-fundpsbt.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ the actual witness weight will be used.
*excess\_as\_change* is an optional boolean to flag to add a change output
for the excess sats.

*nonwrapped* is an optional boolean to signal to filter out any p2sh-wrapped
inputs from funding this PSBT.

EXAMPLE USAGE
-------------

Expand Down
58 changes: 58 additions & 0 deletions doc/lightning-upgradewallet.7.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
lightning-upgradewallet -- Command to spend all P2SH-wrapped inputs into a Native Segwit output
================================================================

SYNOPSIS
--------

**upgradewallet** [*feerate*] [*reservedok*]

DESCRIPTION
-----------

`upgradewallet` is a convenience RPC which will spend all p2sh-wrapped
Segwit deposits in a wallet into a single Native Segwit P2WPKH address.

*feerate* can be one of the feerates listed in lightning-feerates(7),
or one of the strings *urgent* (aim for next block), *normal* (next 4
blocks or so) or *slow* (next 100 blocks or so) to use lightningd's
internal estimates. It can also be a *feerate* is a number, with an
optional suffix: *perkw* means the number is interpreted as
satoshi-per-kilosipa (weight), and *perkb* means it is interpreted
bitcoind-style as satoshi-per-kilobyte. Omitting the suffix is
equivalent to *perkb*.

*reservedok* tells the wallet to include all P2SH-wrapped inputs, including
reserved ones.

EXAMPLE USAGE
-------------

The caller is trying to buy a liquidity ad but the command keeps failing.
They have funds in their wallet, but they're all P2SH-wrapped outputs.

The caller can call `upgradewallet` to convert their funds to native segwit
outputs, which are valid for liquidity ad buys.

RETURN VALUE
------------

[comment]: # (GENERATE-FROM-SCHEMA-START)
[comment]: # (GENERATE-FROM-SCHEMA-END)


AUTHOR
------

~niftynei~ <<[email protected]>> is mainly responsible.

SEE ALSO
--------

lightning-utxopsbt(7), lightning-reserveinputs(7), lightning-unreserveinputs(7).

RESOURCES
---------

Main web site: <https://github.com/ElementsProject/lightning>

[comment]: # ( SHA256STAMP:0f290582f49c6103258b7f781a9e7fa4075ec6c05335a459a91da0b6fd58c68d)
18 changes: 18 additions & 0 deletions doc/schemas/upgradewallet.request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [],
"additionalProperties": false,
"properties": {
"feerate": {
"type": "feerate",
"description": "Feerate for the upgrade transaction",
"added": "v23.02"
},
"reservedok": {
"type": "boolean",
"description": "Include already reserved funds or not",
"added": "v23.02"
}
}
}
30 changes: 30 additions & 0 deletions doc/schemas/upgradewallet.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"required": [
"upgraded_outs"
],
"properties": {
"upgraded_outs": {
"type": "u64",
"description": "Count of spent/upgraded UTXOs",
"added": "v23.02"
},
"psbt": {
"type": "string",
"description": "The PSBT that was finalized and sent",
"added": "v23.02"
},
"tx": {
"type": "hex",
"description": "The raw transaction which was sent",
"added": "v23.02"
},
"txid": {
"type": "txid",
"description": "The txid of the **tx**",
"added": "v23.02"
}
}
}
5 changes: 3 additions & 2 deletions gossipd/gossipd.c
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,12 @@ static void handle_recv_gossip(struct daemon *daemon, const u8 *outermsg)
case WIRE_TX_ADD_OUTPUT:
case WIRE_TX_REMOVE_OUTPUT:
case WIRE_TX_COMPLETE:
case WIRE_TX_ABORT:
case WIRE_TX_SIGNATURES:
case WIRE_TX_INIT_RBF:
case WIRE_TX_ACK_RBF:
case WIRE_OPEN_CHANNEL2:
case WIRE_ACCEPT_CHANNEL2:
case WIRE_INIT_RBF:
case WIRE_ACK_RBF:
case WIRE_ONION_MESSAGE:
#if EXPERIMENTAL_FEATURES
case WIRE_STFU:
Expand Down
9 changes: 5 additions & 4 deletions lightningd/channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ new_inflight(struct channel *channel,
const secp256k1_ecdsa_signature *lease_commit_sig,
const u32 lease_chan_max_msat, const u16 lease_chan_max_ppt,
const u32 lease_blockheight_start,
const struct amount_msat lease_fee)
const struct amount_msat lease_fee,
const struct amount_sat lease_amt)
{
struct wally_psbt *last_tx_psbt_clone;
struct channel_inflight *inflight
Expand Down Expand Up @@ -169,6 +170,7 @@ new_inflight(struct channel *channel,
inflight->lease_chan_max_msat = lease_chan_max_msat;
inflight->lease_chan_max_ppt = lease_chan_max_ppt;
inflight->lease_fee = lease_fee;
inflight->lease_amt = lease_amt;

list_add_tail(&channel->inflights, &inflight->list);
tal_add_destructor(inflight, destroy_inflight);
Expand Down Expand Up @@ -250,11 +252,10 @@ struct channel *new_unsaved_channel(struct peer *peer,
/* BOLT-7b04b1461739c5036add61782d58ac490842d98b #9
* | 222/223 | `option_dual_fund`
* | Use v2 of channel open, enables dual funding
* | IN9
* | `option_anchor_outputs` */
* | IN9 */
channel->static_remotekey_start[LOCAL]
= channel->static_remotekey_start[REMOTE] = 0;
channel->type = channel_type_anchor_outputs(channel);

channel->future_per_commitment_point = NULL;

channel->lease_commit_sig = NULL;
Expand Down
6 changes: 5 additions & 1 deletion lightningd/channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ struct channel_inflight {
/* We save this data so we can do nice accounting;
* on the channel we slot it into the 'push' field */
struct amount_msat lease_fee;

/* Amount requested to lease for this open */
struct amount_sat lease_amt;
};

struct open_attempt {
Expand Down Expand Up @@ -351,7 +354,8 @@ new_inflight(struct channel *channel,
const u32 lease_chan_max_msat,
const u16 lease_chan_max_ppt,
const u32 lease_blockheight_start,
const struct amount_msat lease_fee);
const struct amount_msat lease_fee,
const struct amount_sat lease_amt);

/* Given a txid, find an inflight channel stub. Returns NULL if none found */
struct channel_inflight *channel_inflight_find(struct channel *channel,
Expand Down
Loading