Skip to content

Commit

Permalink
splice: (todo del) fixes to go in other commits
Browse files Browse the repository at this point in the history
  • Loading branch information
ddustin committed Nov 23, 2022
1 parent 0229f90 commit 8b0713a
Show file tree
Hide file tree
Showing 13 changed files with 474 additions and 326 deletions.
378 changes: 212 additions & 166 deletions channeld/channeld.c

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions channeld/channeld_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ msgtype,channeld_got_revoke_reply,1122

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

# channeld->master: hello, I started a channel splice open
msgtype,channeld_splice_confirmed_init,7205
Expand Down
21 changes: 19 additions & 2 deletions channeld/full_channel.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,23 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,
const struct pubkey *per_commitment_point,
u64 commitment_number,
enum side side)
{
return channel_splice_txs(ctx, &channel->funding, channel->funding_sats,
htlcmap, direct_outputs, funding_wscript,
channel, per_commitment_point,
commitment_number, side);
}

struct bitcoin_tx **channel_splice_txs(const tal_t *ctx,
const struct bitcoin_outpoint *funding,
struct amount_sat funding_sats,
const struct htlc ***htlcmap,
struct wally_tx_output *direct_outputs[NUM_SIDES],
const u8 **funding_wscript,
const struct channel *channel,
const struct pubkey *per_commitment_point,
u64 commitment_number,
enum side side)
{
struct bitcoin_tx **txs;
const struct htlc **committed;
Expand All @@ -322,8 +339,8 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,

txs = tal_arr(ctx, struct bitcoin_tx *, 1);
txs[0] = commit_tx(
ctx, &channel->funding,
channel->funding_sats,
ctx, funding,
funding_sats,
&channel->funding_pubkey[side],
&channel->funding_pubkey[!side],
channel->opener,
Expand Down
14 changes: 14 additions & 0 deletions channeld/full_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ struct bitcoin_tx **channel_txs(const tal_t *ctx,
u64 commitment_number,
enum side side);

/* Version of `channel_txs` that lets you specify a custom funding outpoint
* and funding_sats.
*/
struct bitcoin_tx **channel_splice_txs(const tal_t *ctx,
const struct bitcoin_outpoint *funding,
struct amount_sat funding_sats,
const struct htlc ***htlcmap,
struct wally_tx_output *direct_outputs[NUM_SIDES],
const u8 **funding_wscript,
const struct channel *channel,
const struct pubkey *per_commitment_point,
u64 commitment_number,
enum side side);

/**
* actual_feerate: what is the actual feerate for the local side.
* @channel: The channel state
Expand Down
10 changes: 10 additions & 0 deletions common/amount.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ struct amount_sat amount_msat_to_sat_round_down(struct amount_msat msat)
return sat;
}

struct amount_sat amount_msat_to_sat_round(struct amount_msat msat)
{
struct amount_sat sat;

sat.satoshis = msat.millisatoshis / MSAT_PER_SAT;
if (msat.millisatoshis % MSAT_PER_SAT >= MSAT_PER_SAT / 2)
sat.satoshis++;
return sat;
}

/* Different formatting by amounts: btc, sat and msat */
const char *fmt_amount_msat_btc(const tal_t *ctx,
struct amount_msat msat,
Expand Down
2 changes: 2 additions & 0 deletions common/amount.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ WARN_UNUSED_RESULT bool amount_msat_to_sat(struct amount_sat *sat,
/* You can always truncate millisatoshis->satoshis. */
struct amount_sat amount_msat_to_sat_round_down(struct amount_msat msat);

struct amount_sat amount_msat_to_sat_round(struct amount_msat msat);

/* Simple operations: val = a + b, val = a - b. */
WARN_UNUSED_RESULT bool amount_msat_add(struct amount_msat *val,
struct amount_msat a,
Expand Down
Loading

0 comments on commit 8b0713a

Please sign in to comment.