Skip to content

Commit 89e3067

Browse files
committed
WIP changes
1 parent 07038ee commit 89e3067

15 files changed

Lines changed: 1166 additions & 301 deletions

File tree

channeld/channeld.c

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,16 @@ struct peer {
7676
/* What (additional) messages the HSM accepts */
7777
u32 *hsm_capabilities;
7878

79+
/* The feerate to initiate a splice */
80+
u32 feerate_splice;
81+
7982
/* Tolerable amounts for feerate (only relevant for fundee). */
8083
u32 feerate_min, feerate_max;
8184

8285
/* Feerate to be used when creating penalty transactions. */
8386
u32 feerate_penalty;
8487

85-
/* Feerate to be used when opening (or splicing) a channel. */
88+
/* Feerate to be used when opening a channel. */
8689
u32 feerate_opening;
8790

8891
/* Local next per-commit point. */
@@ -1894,9 +1897,9 @@ static void check_tx_abort(struct peer *peer, const u8 *msg, struct bitcoin_txid
18941897
exit(0);
18951898
}
18961899

1897-
static void splice_abort(struct peer *peer, const char *fmt, ...)
1900+
static void splice_abort(struct peer *peer, struct inflight *inflight,
1901+
const char *fmt, ...)
18981902
{
1899-
struct inflight *inflight = last_inflight(peer);
19001903
struct bitcoin_outpoint *outpoint;
19011904
u8 *msg;
19021905
char *reason;
@@ -3337,7 +3340,8 @@ static struct amount_sat calc_balance(struct peer *peer)
33373340
}
33383341

33393342
/* Returns the total channel funding output amount if all checks pass.
3340-
* Otherwise, exits via peer_failed_warn. */
3343+
* Otherwise, exits via peer_failed_warn.
3344+
* Note: Should only be called before adding splice to inflights. */
33413345
static struct amount_sat check_balances(struct peer *peer,
33423346
enum tx_role our_role,
33433347
const struct wally_psbt *psbt,
@@ -3388,15 +3392,15 @@ static struct amount_sat check_balances(struct peer *peer,
33883392
* additional funds are otherwise contributed. */
33893393
if (!amount_msat_can_add_sat_s64(in[TX_INITIATOR],
33903394
peer->splicing->opener_relative)) {
3391-
splice_abort(peer, "Intiator is attempting to splice out"
3395+
splice_abort(peer, NULL, "Intiator is attempting to splice out"
33923396
" %"PRId64"sat funds out of channel while only "
33933397
"having %s funds attributable to them.",
33943398
peer->splicing->opener_relative,
33953399
fmt_amount_m_as_sat(tmpctx, in[TX_INITIATOR]));
33963400
}
33973401
if (!amount_msat_can_add_sat_s64(in[TX_ACCEPTER],
33983402
peer->splicing->accepter_relative)) {
3399-
splice_abort(peer, "Accepter is attempting to splice out"
3403+
splice_abort(peer, NULL, "Accepter is attempting to splice out"
34003404
" %"PRId64"sat funds out of channel while only "
34013405
"having %s funds attributable to them.",
34023406
peer->splicing->accepter_relative,
@@ -3452,7 +3456,7 @@ static struct amount_sat check_balances(struct peer *peer,
34523456
*/
34533457
if (!amount_msat_add_sat_s64(&funding_amount, funding_amount,
34543458
peer->splicing->opener_relative))
3455-
splice_abort(peer, "Splice initiator did not provide enough"
3459+
splice_abort(peer, NULL, "Splice initiator did not provide enough"
34563460
" funding, funding_amount: %s, opener_relative:"
34573461
" %"PRIu64,
34583462
fmt_amount_msat(tmpctx, funding_amount),
@@ -3469,7 +3473,7 @@ static struct amount_sat check_balances(struct peer *peer,
34693473

34703474
if (!amount_msat_add_sat_s64(&funding_amount, funding_amount,
34713475
peer->splicing->accepter_relative))
3472-
splice_abort(peer, "Splice accepter did not provide enough"
3476+
splice_abort(peer, NULL, "Splice accepter did not provide enough"
34733477
" funding");
34743478
if (!amount_msat_add_sat_s64(&out[TX_ACCEPTER], out[TX_ACCEPTER],
34753479
peer->splicing->accepter_relative))
@@ -3486,7 +3490,7 @@ static struct amount_sat check_balances(struct peer *peer,
34863490
out[TX_INITIATOR],
34873491
true);
34883492
wire_sync_write(MASTER_FD, take(msg));
3489-
splice_abort(peer,
3493+
splice_abort(peer, NULL,
34903494
"Initiator funding is less than commited"
34913495
" amount. Initiator contributing %s but they"
34923496
" committed to %s. Pending offered HTLC"
@@ -3513,7 +3517,7 @@ static struct amount_sat check_balances(struct peer *peer,
35133517
out[TX_INITIATOR],
35143518
true);
35153519
wire_sync_write(MASTER_FD, take(msg));
3516-
splice_abort(peer,
3520+
splice_abort(peer, NULL,
35173521
"Accepter funding is less than commited"
35183522
" amount. Accepter contributing %s but they"
35193523
" committed to %s. Pending offered HTLC"
@@ -3543,10 +3547,10 @@ static struct amount_sat check_balances(struct peer *peer,
35433547
calc_weight(TX_INITIATOR, psbt, opener));
35443548

35453549
if (opener) {
3546-
status_debug("User specified fee of %s. Opening feerate %"PRIu32
3550+
status_debug("User specified fee of %s. Splice feerate %"PRIu32
35473551
" * weight %lu / 1000 = %s",
35483552
fmt_amount_m_as_sat(tmpctx, initiator_fee),
3549-
peer->feerate_opening,
3553+
peer->feerate_splice,
35503554
calc_weight(TX_INITIATOR, psbt, false),
35513555
fmt_amount_sat(tmpctx, max_initiator_fee));
35523556
}
@@ -3556,7 +3560,7 @@ static struct amount_sat check_balances(struct peer *peer,
35563560
msg = towire_channeld_splice_feerate_error(NULL, initiator_fee,
35573561
false);
35583562
wire_sync_write(MASTER_FD, take(msg));
3559-
splice_abort(peer,
3563+
splice_abort(peer, NULL,
35603564
"%s fee (%s) was too low, must be at least %s",
35613565
opener ? "Our" : "Your",
35623566
fmt_amount_msat(tmpctx, initiator_fee),
@@ -3576,7 +3580,7 @@ static struct amount_sat check_balances(struct peer *peer,
35763580

35773581
wire_sync_write(MASTER_FD, take(msg));
35783582

3579-
splice_abort(peer,
3583+
splice_abort(peer, NULL,
35803584
"Our own fee (%s) is too high to use without"
35813585
" forcing. Opening feerate %"PRIu32
35823586
" x weight %lu / 1000 = %s (max)",
@@ -3590,7 +3594,7 @@ static struct amount_sat check_balances(struct peer *peer,
35903594
msg = towire_channeld_splice_feerate_error(NULL, accepter_fee,
35913595
false);
35923596
wire_sync_write(MASTER_FD, take(msg));
3593-
splice_abort(peer,
3597+
splice_abort(peer, NULL,
35943598
"%s fee (%s) was too low, must be at least %s"
35953599
" weight: %"PRIu64", feerate_max: %"PRIu32,
35963600
opener ? "Your" : "Our",
@@ -3604,7 +3608,7 @@ static struct amount_sat check_balances(struct peer *peer,
36043608
msg = towire_channeld_splice_feerate_error(NULL, accepter_fee,
36053609
true);
36063610
wire_sync_write(MASTER_FD, take(msg));
3607-
splice_abort(peer,
3611+
splice_abort(peer, NULL,
36083612
"Our own fee (%s) was too high, max without"
36093613
" forcing is %s.",
36103614
fmt_amount_msat(tmpctx, accepter_fee),
@@ -5027,7 +5031,7 @@ static void handle_abort_req(struct peer *peer, const u8 *inmsg)
50275031
if (!fromwire_channeld_abort(inmsg))
50285032
master_badmsg(WIRE_CHANNELD_ABORT, inmsg);
50295033

5030-
splice_abort(peer, "requested by user");
5034+
splice_abort(peer, last_inflight(peer), "requested by user");
50315035
}
50325036

50335037
static void peer_in(struct peer *peer, const u8 *msg)
@@ -5883,7 +5887,8 @@ static void peer_reconnect(struct peer *peer,
58835887
" channel, ignoring it: %s",
58845888
fmt_bitcoin_outpoint(tmpctx, &peer->channel->funding));
58855889
else
5886-
splice_abort(peer, "next_funding_txid not recognized.");
5890+
splice_abort(peer, NULL,
5891+
"next_funding_txid not recognized.");
58875892
}
58885893

58895894
/* BOLT #2:
@@ -6377,11 +6382,13 @@ static void handle_feerates(struct peer *peer, const u8 *inmsg)
63776382
{
63786383
u32 feerate;
63796384

6380-
if (!fromwire_channeld_feerates(inmsg, &feerate,
6381-
&peer->feerate_min,
6382-
&peer->feerate_max,
6383-
&peer->feerate_penalty,
6384-
&peer->feerate_opening))
6385+
if (!fromwire_channeld_feerates(inmsg,
6386+
&feerate,
6387+
&peer->feerate_min,
6388+
&peer->feerate_max,
6389+
&peer->feerate_penalty,
6390+
&peer->feerate_opening,
6391+
&peer->feerate_splice))
63856392
master_badmsg(WIRE_CHANNELD_FEERATES, inmsg);
63866393

63876394
/* BOLT #2:
@@ -6749,6 +6756,7 @@ static void init_channel(struct peer *peer)
67496756
&lease_expiry,
67506757
&conf[LOCAL], &conf[REMOTE],
67516758
&fee_states,
6759+
&peer->feerate_splice,
67526760
&peer->feerate_min,
67536761
&peer->feerate_max,
67546762
&peer->feerate_penalty,

channeld/channeld_wire.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ msgdata,channeld_init,lease_expiry,u32,
2828
msgdata,channeld_init,our_config,channel_config,
2929
msgdata,channeld_init,their_config,channel_config,
3030
msgdata,channeld_init,fee_states,fee_states,
31+
msgdata,channeld_init,feerate_splice,u32,
3132
msgdata,channeld_init,feerate_min,u32,
3233
msgdata,channeld_init,feerate_max,u32,
3334
msgdata,channeld_init,feerate_penalty,u32,
@@ -331,6 +332,7 @@ msgdata,channeld_feerates,min_feerate,u32,
331332
msgdata,channeld_feerates,max_feerate,u32,
332333
msgdata,channeld_feerates,penalty_feerate,u32,
333334
msgdata,channeld_feerates,opening_feerate,u32,
335+
msgdata,channeld_feerates,feerate_splice,u32,
334336

335337
# master -> channeld: do you have a memleak?
336338
msgtype,channeld_dev_memleak,1033

common/splice_script.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2777,11 +2777,13 @@ char *splice_to_string(const tal_t *ctx,
27772777
result->feerate_per_kw);
27782778

27792779
if (!amount_sat_is_zero(result->in_sat))
2780-
tal_append_fmt(&str, "%sput %s%s into ", into_prefix,
2780+
tal_append_fmt(&str, "%sput %s%s %s ", into_prefix,
27812781
fmt_amount_sat(ctx, result->in_sat),
2782-
fee_str);
2782+
fee_str,
2783+
result->in_ppm ? "and" : "into");
27832784
if (result->in_ppm)
2784-
tal_append_fmt(&str, "%sput %s%s of rest into ", into_prefix,
2785+
tal_append_fmt(&str, "%s%s%s%s of rest into ", into_prefix,
2786+
amount_sat_is_zero(result->in_sat) ? "put " : "",
27852787
ppm_to_str(ctx, result->in_ppm),
27862788
fee_str);
27872789

@@ -2807,7 +2809,9 @@ char *splice_to_string(const tal_t *ctx,
28072809
fmt_amount_sat(ctx, result->out_sat),
28082810
fee_str);
28092811
if (result->out_ppm)
2810-
tal_append_fmt(&str, " withdraw %s%s",
2812+
tal_append_fmt(&str, " %s %s%s",
2813+
amount_sat_is_zero(result->out_sat)
2814+
? "withdraw" : "and",
28112815
ppm_to_str(ctx, result->out_ppm),
28122816
fee_str);
28132817

contrib/pyln-testing/pyln/testing/utils.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ def fundbalancedchannel(self, remote_node, total_capacity=FUNDAMOUNT, announce=T
10921092
if txid == res['txid']:
10931093
txnum = i
10941094

1095-
return '{}x{}x{}'.format(self.bitcoin.rpc.getblockcount(), txnum, res['outnum'])
1095+
return '{}x{}x{}'.format(self.bitcoin.rpc.getblockcount(), txnum, res['outnum']), res['txid']
10961096

10971097
def db_query(self, query):
10981098
return self.db.query(query)
@@ -1702,7 +1702,7 @@ def get_node_id(self):
17021702
self.next_id += 1
17031703
return node_id
17041704

1705-
def get_nodes(self, num_nodes, opts=None):
1705+
def get_nodes(self, num_nodes, opts=None, allow_bad_gossip=False):
17061706
"""Start a number of nodes in parallel, each with its own options
17071707
"""
17081708
if opts is None:
@@ -1727,7 +1727,8 @@ def get_nodes(self, num_nodes, opts=None):
17271727
jobs.append(self.executor.submit(
17281728
self.get_node, options=cli_opts,
17291729
node_id=self.get_node_id(), **node_opts,
1730-
valgrind_plugins=valgrind_plugins[i]
1730+
valgrind_plugins=valgrind_plugins[i],
1731+
allow_bad_gossip=allow_bad_gossip
17311732
))
17321733

17331734
return [j.result() for j in jobs]
@@ -1789,7 +1790,7 @@ def get_node(self, node_id=None, options=None, dbfile=None,
17891790
raise
17901791
return node
17911792

1792-
def join_nodes(self, nodes, fundchannel=True, fundamount=FUNDAMOUNT, wait_for_announce=False, announce_channels=True) -> None:
1793+
def join_nodes(self, nodes, fundchannel=True, fundamount=FUNDAMOUNT, wait_for_announce=False, announce_channels=True, balance_channels=False) -> None:
17931794
"""Given nodes, connect them in a line, optionally funding a channel, wait_for_announce waits for channel and node announcements"""
17941795
assert not (wait_for_announce and not announce_channels), "You've asked to wait for an announcement that's not coming. (wait_for_announce=True,announce_channels=False)"
17951796
connections = [(nodes[i], nodes[i + 1]) for i in range(len(nodes) - 1)]
@@ -1815,10 +1816,15 @@ def join_nodes(self, nodes, fundchannel=True, fundamount=FUNDAMOUNT, wait_for_an
18151816
sync_blockheight(bitcoind, nodes)
18161817
txids = []
18171818
for src, dst in connections:
1818-
txids.append(src.rpc.fundchannel(dst.info['id'], fundamount, announce=announce_channels)['txid'])
1819+
if balance_channels:
1820+
_, txid = src.fundbalancedchannel(remote_node=dst, total_capacity=fundamount, announce=announce_channels)
1821+
txids.append(txid)
1822+
else:
1823+
txids.append(src.rpc.fundchannel(dst.info['id'], fundamount, announce=announce_channels)['txid'])
18191824

1820-
# Confirm all channels and wait for them to become usable
1821-
bitcoind.generate_block(1, wait_for_mempool=txids)
1825+
if not balance_channels:
1826+
# Confirm all channels and wait for them to become usable
1827+
bitcoind.generate_block(1, wait_for_mempool=txids)
18221828
scids = []
18231829
for src, dst in connections:
18241830
wait_for(lambda: src.channel_state(dst) == 'CHANNELD_NORMAL')
@@ -1846,12 +1852,12 @@ def join_nodes(self, nodes, fundchannel=True, fundamount=FUNDAMOUNT, wait_for_an
18461852
alias = n2.rpc.getinfo()['alias']
18471853
wait_for(lambda: [n.get('alias') for n in n.rpc.listnodes(n2.info['id'])['nodes']] == [alias])
18481854

1849-
def line_graph(self, num_nodes, fundchannel=True, fundamount=FUNDAMOUNT, wait_for_announce=False, opts=None, announce_channels=True):
1855+
def line_graph(self, num_nodes, fundchannel=True, fundamount=FUNDAMOUNT, wait_for_announce=False, opts=None, announce_channels=True, balanced=False, allow_bad_gossip=False):
18501856
""" Create nodes, connect them and optionally fund channels.
18511857
"""
1852-
nodes = self.get_nodes(num_nodes, opts=opts)
1858+
nodes = self.get_nodes(num_nodes, opts=opts, allow_bad_gossip=allow_bad_gossip)
18531859

1854-
self.join_nodes(nodes, fundchannel, fundamount, wait_for_announce, announce_channels)
1860+
self.join_nodes(nodes, fundchannel, fundamount, wait_for_announce, announce_channels, balanced)
18551861
return nodes
18561862

18571863
def get_unused_port(self):

gossipd/gossmap_manage.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -703,10 +703,18 @@ void gossmap_manage_handle_get_txout_reply(struct gossmap_manage *gm, const u8 *
703703
* - MUST ignore the message.
704704
*/
705705
if (tal_count(outscript) == 0) {
706-
peer_warning(gm, pca->source_peer,
707-
"channel_announcement: no unspent txout %s",
708-
fmt_short_channel_id(tmpctx, scid));
709-
goto bad;
706+
/* Splices that happen soon after a channel open can result in
707+
* the receiving of stale channel announcement (Splice spends
708+
* the txout of the original channel).
709+
*
710+
* We used to treat this as a warning and reset the peer
711+
* connection but the spec simply says "ignore the message". So
712+
* Now we just ignore these stale channel announcements. */
713+
714+
status_peer_trace(pca->source_peer,
715+
"channel_announcement: no unspent txout %s",
716+
fmt_short_channel_id(tmpctx, scid));
717+
goto out;
710718
}
711719

712720
if (!tal_arr_eq(outscript, pca->scriptpubkey)) {
@@ -810,10 +818,14 @@ static const char *process_channel_update(const tal_t *ctx,
810818
/* Seeker may want to ask about this. */
811819
query_unknown_channel(gm->daemon, source_peer, scid);
812820

813-
/* Don't send them warning, it can happen. */
814-
bad_gossip(source_peer,
815-
tal_fmt(tmpctx, "Unknown channel %s",
816-
fmt_short_channel_id(tmpctx, scid)));
821+
/* Splices that happen soon after a channel open can result in
822+
* the receiving of stale channel announcement (Splice spends
823+
* the txout of the original channel).
824+
*
825+
* We used to record this as as bad_gossip but now we log it
826+
* without the 'bad gossip' because that triggers CI. */
827+
status_peer_trace(source_peer, "gossip unknown channel: %s",
828+
fmt_short_channel_id(tmpctx, scid));
817829
return NULL;
818830
}
819831

lightningd/chaintopology.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,14 @@ static struct command_result *json_feerates(struct command *cmd,
712712
if (rate)
713713
json_add_num(response, "penalty",
714714
feerate_to_style(rate, *style));
715+
rate = unilateral_feerate(topo, true);
716+
if (rate) {
717+
rate += cmd->ld->config.feerate_offset;
718+
if (rate > feerate_max(cmd->ld, NULL))
719+
rate = feerate_max(cmd->ld, NULL);
720+
json_add_num(response, "splice",
721+
feerate_to_style(rate, *style));
722+
}
715723

716724
json_add_u64(response, "min_acceptable",
717725
feerate_to_style(feerate_min(cmd->ld, NULL), *style));

0 commit comments

Comments
 (0)