Skip to content

Commit

Permalink
fixup! channeld: Code to implement splicing
Browse files Browse the repository at this point in the history
CI fixes
  • Loading branch information
ddustin committed Jul 20, 2023
1 parent b520e49 commit ed0f20d
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ jobs:
pip3 install --user pip wheel poetry
poetry export -o requirements.txt --with dev --without-hashes
python3 -m pip install -r requirements.txt
./configure --enable-debugbuild CC="$COMPILER"
./configure --enable-debugbuild --enable-experimental-splicing CC="$COMPILER"
make -j $(nproc) testpack.tar.bz2
Expand Down Expand Up @@ -270,6 +270,7 @@ jobs:
COMPILER: gcc
TEST_NETWORK: regtest
DEVELOPER: 1
EXPERIMENTAL_DUAL_FUND: 1
EXPERIMENTAL_SPLICING: 1
steps:
- name: Checkout
Expand Down
45 changes: 29 additions & 16 deletions channeld/channeld.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,14 @@ static void check_mutual_splice_locked(struct peer *peer)
billboard_update(peer);
send_channel_update(peer, 0);

/* valgrind complains last_tx is leaked so we explicitly free it
* DTODO: investigate this more. */
for (size_t i = 0; i < tal_count(peer->splice_state->inflights); i++) {
inflight = peer->splice_state->inflights[i];
tal_free(inflight->last_tx);
tal_free(inflight);
}

peer->splice_state->inflights = tal_free(peer->splice_state->inflights);
peer->splice_state->count = 0;
peer->splice_state->revoked_count = 0;
Expand Down Expand Up @@ -2068,9 +2076,9 @@ static struct commitsig *handle_peer_commit_sig(struct peer *peer,
tal_hex(tmpctx, msg2));

result = tal(tmpctx, struct commitsig);
result->tx = tal_steal(result, txs[0]);
result->tx = clone_bitcoin_tx(result, txs[0]);
result->commit_signature = commit_sig;
result->htlc_signatures = tal_steal(result, htlc_sigs);
result->htlc_signatures = htlc_sigs;

/* Only the parent call continues from here.
* Return for all child calls. */
Expand All @@ -2095,6 +2103,7 @@ static struct commitsig *handle_peer_commit_sig(struct peer *peer,
"WIRE_COMMITMENT_SIGNED but got %s",
peer_wire_name(type));

/* We purposely just store the last commit msg */
result = handle_peer_commit_sig(peer, splice_msg, i + 1,
changed_htlcs, sub_splice_amnt,
funding_diff - sub_splice_amnt);
Expand All @@ -2116,6 +2125,7 @@ static struct commitsig *handle_peer_commit_sig(struct peer *peer,
if (want_fee_update(peer, NULL))
start_commit_timer(peer);

/* We return the last commit commit msg */
return result;
}

Expand Down Expand Up @@ -3137,7 +3147,7 @@ static void resume_splice_negotiation(struct peer *peer,
their_commit = interactive_send_commitments(peer, current_psbt,
our_role);

inflight->last_tx = tal_steal(peer, their_commit->tx);
inflight->last_tx = tal_steal(inflight, their_commit->tx);
inflight->last_sig = their_commit->commit_signature;

msg = towire_channeld_update_inflight(NULL, current_psbt,
Expand Down Expand Up @@ -3333,16 +3343,18 @@ static void resume_splice_negotiation(struct peer *peer,
send_channel_update(peer, 0);
}

static struct inflight *init_inflights(const tal_t *ctx, struct peer *peer)
static struct inflight *inflights_new(struct peer *peer)
{
struct inflight *inf;
struct inflight *inf = tal(peer->splice_state->inflights, struct inflight);
int i = tal_count(peer->splice_state->inflights);

if (!peer->splice_state->inflights)
peer->splice_state->inflights = tal_arr(ctx, struct inflight *, 0);

inf = tal(peer->splice_state->inflights, struct inflight);
if (i)
tal_resize(&peer->splice_state->inflights, i + 1);
else
peer->splice_state->inflights = tal_arr(peer->splice_state,
struct inflight *, 1);

tal_arr_expand(&peer->splice_state->inflights, inf);
peer->splice_state->inflights[i] = inf;
return inf;
}

Expand Down Expand Up @@ -3471,12 +3483,13 @@ static void splice_accepter(struct peer *peer, const u8 *inmsg)
master_wait_sync_reply(tmpctx, peer, take(msg),
WIRE_CHANNELD_GOT_INFLIGHT);

new_inflight = init_inflights(peer, peer);
new_inflight = inflights_new(peer);

psbt_txid(tmpctx, ictx->current_psbt, &new_inflight->outpoint.txid, NULL);
psbt_txid(new_inflight, ictx->current_psbt,
&new_inflight->outpoint.txid, NULL);
new_inflight->outpoint = outpoint;
new_inflight->amnt = both_amount;
new_inflight->psbt = ictx->current_psbt;
new_inflight->psbt = tal_steal(new_inflight, ictx->current_psbt);
new_inflight->splice_amnt = peer->splice->accepter_relative;
new_inflight->i_am_initiator = false;

Expand Down Expand Up @@ -3704,11 +3717,11 @@ static void splice_initiator_user_finalized(struct peer *peer)
master_wait_sync_reply(tmpctx, peer, take(outmsg),
WIRE_CHANNELD_GOT_INFLIGHT);

new_inflight = init_inflights(peer, peer);
new_inflight = inflights_new(peer);

psbt_txid(tmpctx, ictx->current_psbt, &new_inflight->outpoint.txid, NULL);
new_inflight->outpoint.n = chan_output_index;
new_inflight->psbt = ictx->current_psbt;
new_inflight->psbt = tal_steal(new_inflight, ictx->current_psbt);
new_inflight->amnt = amount_sat(new_chan_output->amount);
new_inflight->splice_amnt = peer->splice->opener_relative;
new_inflight->i_am_initiator = true;
Expand Down Expand Up @@ -4912,7 +4925,6 @@ static void peer_reconnect(struct peer *peer,
if (type)
set_channel_type(peer->channel, type);
}
tal_free(send_tlvs);

/* Now stop, we've been polite long enough. */
if (reestablish_only) {
Expand Down Expand Up @@ -4976,6 +4988,7 @@ static void peer_reconnect(struct peer *peer,
: TX_ACCEPTER);
}
}
tal_free(send_tlvs);

/* Corner case: we didn't send shutdown before because update_add_htlc
* pending, but now they're cleared by restart, and we're actually
Expand Down
2 changes: 1 addition & 1 deletion channeld/full_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ struct bitcoin_tx **channel_splice_txs(const tal_t *ctx,

txs = tal_arr(ctx, struct bitcoin_tx *, 1);
txs[0] = commit_tx(
ctx, funding,
txs, funding,
funding_sats,
&channel->funding_pubkey[side],
&channel->funding_pubkey[!side],
Expand Down
6 changes: 5 additions & 1 deletion doc/lightning-listconfigs.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ On success, an object is returned, containing:
- **experimental-dual-fund** (object, optional):
- **set** (boolean): `true` if set in config or cmdline
- **source** (string): source of configuration setting
- **experimental-splicing** (object, optional) *(added v23.08)*:
- **set** (boolean): `true` if set in config or cmdline
- **source** (string): source of configuration setting
- **experimental-onion-messages** (object, optional):
- **set** (boolean): `true` if set in config or cmdline
- **source** (string): source of configuration setting
Expand Down Expand Up @@ -298,6 +301,7 @@ On success, an object is returned, containing:
- **wallet** (string, optional): `wallet` field from config or cmdline default **deprecated, removal in v24.05**
- **large-channels** (boolean, optional): `large-channels` field from config or cmdline, or default **deprecated, removal in v24.05**
- **experimental-dual-fund** (boolean, optional): `experimental-dual-fund` field from config or cmdline, or default **deprecated, removal in v24.05**
- **experimental-splicing** (boolean, optional): `experimental-splicing` field from config or cmdline, or default **deprecated, removal in v24.05**
- **experimental-onion-messages** (boolean, optional): `experimental-onion-messages` field from config or cmdline, or default **deprecated, removal in v24.05**
- **experimental-offers** (boolean, optional): `experimental-offers` field from config or cmdline, or default **deprecated, removal in v24.05**
- **experimental-shutdown-wrong-funding** (boolean, optional): `experimental-shutdown-wrong-funding` field from config or cmdline, or default **deprecated, removal in v24.05**
Expand Down Expand Up @@ -467,4 +471,4 @@ RESOURCES

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

[comment]: # ( SHA256STAMP:a40882cad0d889aa736a2932250102be43ae7e62b3d2429b26e0961e4c315f7b)
[comment]: # ( SHA256STAMP:8e7ec36b820cb17ecfc3066802bb07e159fffdd8dfe049d092b8f3b804e05588)
24 changes: 24 additions & 0 deletions doc/schemas/listconfigs.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,25 @@
}
}
},
"experimental-splicing": {
"added": "v23.08",
"type": "object",
"additionalProperties": false,
"required": [
"set",
"source"
],
"properties": {
"set": {
"type": "boolean",
"description": "`true` if set in config or cmdline"
},
"source": {
"type": "string",
"description": "source of configuration setting"
}
}
},
"experimental-onion-messages": {
"type": "object",
"additionalProperties": false,
Expand Down Expand Up @@ -1449,6 +1468,11 @@
"type": "boolean",
"description": "`experimental-dual-fund` field from config or cmdline, or default"
},
"experimental-splicing": {
"deprecated": "v23.08",
"type": "boolean",
"description": "`experimental-splicing` field from config or cmdline, or default"
},
"experimental-onion-messages": {
"deprecated": "v23.08",
"type": "boolean",
Expand Down
2 changes: 2 additions & 0 deletions lightningd/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,8 @@ static char *opt_set_splicing(struct lightningd *ld)
feature_set_or(ld->our_features,
take(feature_set_for_feature(NULL,
OPTIONAL_FEATURE(OPT_SPLICE))));
/* Splicing requires dual-fund to be enabled */
opt_set_dual_fund(ld);
return NULL;
}

Expand Down
5 changes: 4 additions & 1 deletion tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3942,6 +3942,8 @@ def test_sql(node_factory, bitcoind):
'type': 'string'},
{'name': 'total_funding_msat',
'type': 'msat'},
{'name': 'splice_amount',
'type': 's64'},
{'name': 'our_funding_msat',
'type': 'msat'},
{'name': 'scratch_txid',
Expand Down Expand Up @@ -4079,6 +4081,7 @@ def test_sql(node_factory, bitcoind):
'u16': 'INTEGER',
'u32': 'INTEGER',
'u64': 'INTEGER',
's64': 'INTEGER',
'msat': 'INTEGER',
'hex': 'BLOB',
'hash': 'BLOB',
Expand Down Expand Up @@ -4149,7 +4152,7 @@ def test_sql(node_factory, bitcoind):
assert len(bytes.fromhex(val)) == 32
elif col['type'] == "pubkey":
assert len(bytes.fromhex(val)) == 33
elif col['type'] in ("msat", "integer", "u64", "u32", "u16", "u8", "boolean"):
elif col['type'] in ("msat", "integer", "s64", "u64", "u32", "u16", "u8", "boolean"):
int(val)
elif col['type'] == "number":
float(val)
Expand Down
10 changes: 6 additions & 4 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ def expected_peer_features(wumbo_channels=False, extra=[]):
# option_dual_fund
features += [29]
if EXPERIMENTAL_SPLICING:
# option_splice
features += [63]
features += [29] # option_dual_fund
features += [35] # option_quiesce
features += [63] # option_splice
return hex_bits(features + extra)


Expand All @@ -59,8 +60,9 @@ def expected_node_features(wumbo_channels=False, extra=[]):
# option_dual_fund
features += [29]
if EXPERIMENTAL_SPLICING:
# option_splice
features += [63]
features += [29] # option_dual_fund
features += [35] # option_quiesce
features += [63] # option_splice
return hex_bits(features + extra)


Expand Down

0 comments on commit ed0f20d

Please sign in to comment.