Skip to content

Commit 9ee496a

Browse files
committed
splice: (todo del) fixes to go in other commits
1 parent 0229f90 commit 9ee496a

File tree

12 files changed

+471
-325
lines changed

12 files changed

+471
-325
lines changed

channeld/channeld.c

Lines changed: 212 additions & 166 deletions
Large diffs are not rendered by default.

channeld/channeld_wire.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ msgtype,channeld_got_revoke_reply,1122
191191

192192
# master->channeld: hello, I'd like to start a channel splice open
193193
msgtype,channeld_splice_init,7204
194+
msgdata,channeld_splice_init,psbt,wally_psbt,
195+
msgdata,channeld_splice_init,funding_amount,amount_sat,
194196

195197
# channeld->master: hello, I started a channel splice open
196198
msgtype,channeld_splice_confirmed_init,7205

channeld/full_channel.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,23 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,
299299
const struct pubkey *per_commitment_point,
300300
u64 commitment_number,
301301
enum side side)
302+
{
303+
return channel_splice_txs(ctx, &channel->funding, channel->funding_sats,
304+
htlcmap, direct_outputs, funding_wscript,
305+
channel, per_commitment_point,
306+
commitment_number, side);
307+
}
308+
309+
struct bitcoin_tx **channel_splice_txs(const tal_t *ctx,
310+
const struct bitcoin_outpoint *funding,
311+
struct amount_sat funding_sats,
312+
const struct htlc ***htlcmap,
313+
struct wally_tx_output *direct_outputs[NUM_SIDES],
314+
const u8 **funding_wscript,
315+
const struct channel *channel,
316+
const struct pubkey *per_commitment_point,
317+
u64 commitment_number,
318+
enum side side)
302319
{
303320
struct bitcoin_tx **txs;
304321
const struct htlc **committed;
@@ -322,8 +339,8 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,
322339

323340
txs = tal_arr(ctx, struct bitcoin_tx *, 1);
324341
txs[0] = commit_tx(
325-
ctx, &channel->funding,
326-
channel->funding_sats,
342+
ctx, funding,
343+
funding_sats,
327344
&channel->funding_pubkey[side],
328345
&channel->funding_pubkey[!side],
329346
channel->opener,

channeld/full_channel.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,
7676
u64 commitment_number,
7777
enum side side);
7878

79+
/* Version of `channel_txs` that lets you specify a custom funding outpoint
80+
* and funding_sats.
81+
*/
82+
struct bitcoin_tx **channel_splice_txs(const tal_t *ctx,
83+
const struct bitcoin_outpoint *funding,
84+
struct amount_sat funding_sats,
85+
const struct htlc ***htlcmap,
86+
struct wally_tx_output *direct_outputs[NUM_SIDES],
87+
const u8 **funding_wscript,
88+
const struct channel *channel,
89+
const struct pubkey *per_commitment_point,
90+
u64 commitment_number,
91+
enum side side);
92+
7993
/**
8094
* actual_feerate: what is the actual feerate for the local side.
8195
* @channel: The channel state

common/amount.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ struct amount_sat amount_msat_to_sat_round_down(struct amount_msat msat)
3737
return sat;
3838
}
3939

40+
struct amount_sat amount_msat_to_sat_round(struct amount_msat msat)
41+
{
42+
struct amount_sat sat;
43+
44+
sat.satoshis = msat.millisatoshis / MSAT_PER_SAT;
45+
if (msat.millisatoshis % MSAT_PER_SAT >= MSAT_PER_SAT / 2)
46+
sat.satoshis++;
47+
return sat;
48+
}
49+
4050
/* Different formatting by amounts: btc, sat and msat */
4151
const char *fmt_amount_msat_btc(const tal_t *ctx,
4252
struct amount_msat msat,

common/amount.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ WARN_UNUSED_RESULT bool amount_msat_to_sat(struct amount_sat *sat,
6060
/* You can always truncate millisatoshis->satoshis. */
6161
struct amount_sat amount_msat_to_sat_round_down(struct amount_msat msat);
6262

63+
struct amount_sat amount_msat_to_sat_round(struct amount_msat msat);
64+
6365
/* Simple operations: val = a + b, val = a - b. */
6466
WARN_UNUSED_RESULT bool amount_msat_add(struct amount_msat *val,
6567
struct amount_msat a,

0 commit comments

Comments
 (0)