Skip to content

Commit 23af7c0

Browse files
committed
fixup! channeld: Code to implement splicing
Add raw satoshi access warning stoppers
1 parent dc6eb40 commit 23af7c0

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
lines changed

channeld/channeld.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,8 +1613,8 @@ static void send_commit(struct peer *peer)
16131613
* feerate order.
16141614
*/
16151615
for (u32 i = 0; i < tal_count(peer->splice_state.inflights); i++) {
1616-
s64 funding_diff = (s64)peer->splice_state.inflights[i]->amnt.satoshis
1617-
- peer->channel->funding_sats.satoshis;
1616+
s64 funding_diff = (s64)peer->splice_state.inflights[i]->amnt.satoshis /* Raw: splicing */
1617+
- peer->channel->funding_sats.satoshis; /* Raw: splicing */
16181618
s64 remote_splice_amnt = funding_diff
16191619
- peer->splice_state.inflights[i]->splice_amnt;
16201620

@@ -2074,8 +2074,8 @@ static struct commitsig *handle_peer_commit_sig(struct peer *peer,
20742074
* inflight splices. Since consequtive is requred, we recurse for
20752075
* each expected message, blocking until all are received. */
20762076
for (i = 0; i < tal_count(peer->splice_state.inflights); i++) {
2077-
s64 funding_diff = (s64)peer->splice_state.inflights[i]->amnt.satoshis
2078-
- peer->channel->funding_sats.satoshis;
2077+
s64 funding_diff = (s64)peer->splice_state.inflights[i]->amnt.satoshis /* Raw: splicing */
2078+
- peer->channel->funding_sats.satoshis; /* Raw: splicing */
20792079
s64 sub_splice_amnt = peer->splice_state.inflights[i]->splice_amnt;
20802080

20812081
splice_msg = peer_read(tmpctx, peer->pps);
@@ -3058,10 +3058,10 @@ static int find_channel_funding_input(struct wally_psbt *psbt,
30583058
static void update_view_from_inflights(struct peer *peer)
30593059
{
30603060
struct inflight **inflights = peer->splice_state.inflights;
3061-
s64 orig_sats = peer->channel->funding_sats.satoshis;
3061+
s64 orig_sats = peer->channel->funding_sats.satoshis; /* Raw: splicing */
30623062

30633063
for (size_t i = 0; i < tal_count(inflights); i++) {
3064-
s64 splice_amnt = inflights[i]->amnt.satoshis;
3064+
s64 splice_amnt = inflights[i]->amnt.satoshis; /* Raw: splicing */
30653065
s64 funding_diff = splice_amnt - orig_sats;
30663066
s64 remote_splice_amnt = funding_diff - inflights[i]->splice_amnt;
30673067

channeld/full_channel.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,11 @@ struct bitcoin_tx **channel_splice_txs(const tal_t *ctx,
343343
other_side_pay = channel->view[side].owed[!side];
344344

345345
if (side == LOCAL) {
346-
side_pay.millisatoshis += splice_amnt * 1000;
347-
other_side_pay.millisatoshis += remote_splice_amnt * 1000;
346+
side_pay.millisatoshis += splice_amnt * 1000; /* Raw: splicing */
347+
other_side_pay.millisatoshis += remote_splice_amnt * 1000; /* Raw: splicing */
348348
} else if (side == REMOTE) {
349-
side_pay.millisatoshis += remote_splice_amnt * 1000;
350-
other_side_pay.millisatoshis += splice_amnt * 1000;
349+
side_pay.millisatoshis += remote_splice_amnt * 1000; /* Raw: splicing */
350+
other_side_pay.millisatoshis += splice_amnt * 1000; /* Raw: splicing */
351351
}
352352

353353
txs = tal_arr(ctx, struct bitcoin_tx *, 1);
@@ -394,13 +394,13 @@ static bool get_room_above_reserve(const struct channel *channel,
394394
struct amount_msat owed = view->owed[side];
395395

396396
/* `lowest_splice_amnt` will always be negative or 0 */
397-
if (-view->lowest_splice_amnt[side] > owed.millisatoshis) {
397+
if (-view->lowest_splice_amnt[side] > owed.millisatoshis) { /* Raw: splicing */
398398
status_debug("Relative splice balance invalid");
399399
return false;
400400
}
401401

402402
/* `lowest_splice_amnt` is a relative amount */
403-
owed.millisatoshis -= -view->lowest_splice_amnt[side];
403+
owed.millisatoshis -= -view->lowest_splice_amnt[side]; /* Raw: splicing */
404404

405405
to_balance(&balance, owed);
406406

common/initial_channel.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,25 +156,25 @@ const char *channel_update_funding(struct channel *channel,
156156
struct amount_sat funding_sats,
157157
s64 splice_amnt)
158158
{
159-
s64 funding_diff = (s64)funding_sats.satoshis - (s64)channel->funding_sats.satoshis;
159+
s64 funding_diff = (s64)funding_sats.satoshis - (s64)channel->funding_sats.satoshis; /* Raw: splicing */
160160
s64 remote_splice_amnt = funding_diff - splice_amnt;
161161

162162
channel->funding = *funding;
163163
channel->funding_sats = funding_sats;
164164

165-
if (splice_amnt * 1000 + channel->view[LOCAL].owed[LOCAL].millisatoshis < 0)
165+
if (splice_amnt * 1000 + channel->view[LOCAL].owed[LOCAL].millisatoshis < 0) /* Raw: splicing */
166166
return tal_fmt(tmpctx, "Channel funding update would make local"
167167
" balance negative.");
168168

169-
channel->view[LOCAL].owed[LOCAL].millisatoshis += splice_amnt * 1000;
170-
channel->view[REMOTE].owed[LOCAL].millisatoshis += splice_amnt * 1000;
169+
channel->view[LOCAL].owed[LOCAL].millisatoshis += splice_amnt * 1000; /* Raw: splicing */
170+
channel->view[REMOTE].owed[LOCAL].millisatoshis += splice_amnt * 1000; /* Raw: splicing */
171171

172-
if (remote_splice_amnt * 1000 + channel->view[LOCAL].owed[REMOTE].millisatoshis < 0)
172+
if (remote_splice_amnt * 1000 + channel->view[LOCAL].owed[REMOTE].millisatoshis < 0) /* Raw: splicing */
173173
return tal_fmt(tmpctx, "Channel funding update would make"
174174
" remote balance negative.");
175175

176-
channel->view[LOCAL].owed[REMOTE].millisatoshis += remote_splice_amnt * 1000;
177-
channel->view[REMOTE].owed[REMOTE].millisatoshis += remote_splice_amnt * 1000;
176+
channel->view[LOCAL].owed[REMOTE].millisatoshis += remote_splice_amnt * 1000; /* Raw: splicing */
177+
channel->view[REMOTE].owed[REMOTE].millisatoshis += remote_splice_amnt * 1000; /* Raw: splicing */
178178

179179
return NULL;
180180
}

lightningd/channel_control.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -797,9 +797,9 @@ static void handle_peer_splice_locked(struct channel *channel, const u8 *msg)
797797
return;
798798
}
799799

800-
channel->our_msat.millisatoshis += splice_amnt * 1000;
801-
channel->msat_to_us_min.millisatoshis += splice_amnt * 1000;
802-
channel->msat_to_us_max.millisatoshis += splice_amnt * 1000;
800+
channel->our_msat.millisatoshis += splice_amnt * 1000; /* Raw: splicing */
801+
channel->msat_to_us_min.millisatoshis += splice_amnt * 1000; /* Raw: splicing */
802+
channel->msat_to_us_max.millisatoshis += splice_amnt * 1000; /* Raw: splicing */
803803

804804
inflight = channel_inflight_find(channel, &locked_txid);
805805
if(!inflight)

lightningd/peer_control.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1738,7 +1738,7 @@ void update_channel_from_inflight(struct lightningd *ld,
17381738
channel->funding_sats = inflight->funding->total_funds;
17391739

17401740
channel->our_funds = inflight->funding->our_funds;
1741-
channel->our_funds.satoshis += inflight->funding->splice_amnt;
1741+
channel->our_funds.satoshis += inflight->funding->splice_amnt; /* Raw: splicing */
17421742

17431743
/* Lease infos ! */
17441744
channel->lease_expiry = inflight->lease_expiry;

0 commit comments

Comments
 (0)