Skip to content

Commit 7b3a479

Browse files
niftyneiShahanaFarooqui
authored andcommitted
coin-moves: when a splice confirms, send a channel_closed event
We weren't properly notifying that a channel output has been spent in the case of it being spent in a splice. This fixes the notification side of the equation, however there's still some issues remaining for the bookkeeper side (to come). Changelog-Fixed: We now send a `coin_movement` notification for splice confirmations of channel funding outpoint spends.
1 parent 89f01f1 commit 7b3a479

File tree

8 files changed

+77
-16
lines changed

8 files changed

+77
-16
lines changed

common/coin_mvt.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ static const char *mvt_tags[] = {
4040
"leased",
4141
"stealable",
4242
"channel_proposed",
43+
"splice",
4344
};
4445

4546
const char *mvt_tag_str(enum mvt_tag tag)
@@ -177,19 +178,31 @@ struct chain_coin_mvt *new_onchaind_deposit(const tal_t *ctx,
177178
}
178179

179180
struct chain_coin_mvt *new_coin_channel_close(const tal_t *ctx,
181+
const struct channel_id *chan_id,
180182
const struct bitcoin_txid *txid,
181183
const struct bitcoin_outpoint *out,
182184
u32 blockheight,
183185
const struct amount_msat amount,
184186
const struct amount_sat output_val,
185-
u32 output_count)
187+
u32 output_count,
188+
bool is_splice)
186189
{
187-
return new_chain_coin_mvt(ctx, NULL, txid,
190+
struct chain_coin_mvt *mvt;
191+
enum mvt_tag *tags = new_tag_arr(NULL, CHANNEL_CLOSE);
192+
193+
if (is_splice)
194+
tal_arr_expand(&tags, SPLICE);
195+
196+
mvt = new_chain_coin_mvt(ctx, NULL, txid,
188197
out, NULL, blockheight,
189-
take(new_tag_arr(NULL, CHANNEL_CLOSE)),
198+
take(tags),
190199
amount, false,
191200
output_val,
192201
output_count);
202+
if (chan_id)
203+
mvt->account_name = fmt_channel_id(mvt, chan_id);
204+
205+
return mvt;
193206
}
194207

195208
struct chain_coin_mvt *new_coin_channel_open_proposed(const tal_t *ctx,

common/coin_mvt.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ enum mvt_type {
1414
CHANNEL_MVT = 1,
1515
};
1616

17-
#define NUM_MVT_TAGS (CHANNEL_PROPOSED + 1)
17+
#define NUM_MVT_TAGS (SPLICE + 1)
1818
enum mvt_tag {
1919
DEPOSIT = 0,
2020
WITHDRAWAL = 1,
@@ -40,6 +40,7 @@ enum mvt_tag {
4040
LEASED = 21,
4141
STEALABLE = 22,
4242
CHANNEL_PROPOSED = 23,
43+
SPLICE = 24,
4344
};
4445

4546
struct channel_coin_mvt {
@@ -181,13 +182,15 @@ struct chain_coin_mvt *new_onchaind_deposit(const tal_t *ctx,
181182
NON_NULL_ARGS(2);
182183

183184
struct chain_coin_mvt *new_coin_channel_close(const tal_t *ctx,
185+
const struct channel_id *chan_id,
184186
const struct bitcoin_txid *txid,
185187
const struct bitcoin_outpoint *out,
186188
u32 blockheight,
187189
const struct amount_msat amount,
188190
const struct amount_sat output_val,
189-
u32 output_count)
190-
NON_NULL_ARGS(2, 3);
191+
u32 output_count,
192+
bool is_splice)
193+
NON_NULL_ARGS(3, 4);
191194

192195
struct chain_coin_mvt *new_coin_channel_open_proposed(const tal_t *ctx,
193196
const struct channel_id *chan_id,

lightningd/channel_control.c

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,27 @@ static void handle_update_inflight(struct lightningd *ld,
912912
wallet_inflight_save(ld->wallet, inflight);
913913
}
914914

915+
static void channel_record_splice(struct channel *channel,
916+
struct amount_msat orig_our_msats,
917+
struct amount_sat orig_funding_sats,
918+
struct bitcoin_outpoint *funding,
919+
u32 blockheight, struct bitcoin_txid *txid, const struct channel_inflight *inflight)
920+
{
921+
struct chain_coin_mvt *mvt;
922+
u32 output_count;
923+
924+
output_count = inflight->funding_psbt->num_outputs;
925+
mvt = new_coin_channel_close(tmpctx, &channel->cid,
926+
txid,
927+
funding,
928+
blockheight,
929+
orig_our_msats,
930+
orig_funding_sats,
931+
output_count,
932+
/* is_splice = */true);
933+
notify_chain_mvt(channel->peer->ld, mvt);
934+
}
935+
915936
void channel_record_open(struct channel *channel, u32 blockheight, bool record_push)
916937
{
917938
struct chain_coin_mvt *mvt;
@@ -1039,7 +1060,9 @@ bool channel_on_channel_ready(struct channel *channel,
10391060

10401061
static void handle_peer_splice_locked(struct channel *channel, const u8 *msg)
10411062
{
1042-
struct amount_sat funding_sats;
1063+
struct amount_sat funding_sats, prev_funding_sats;
1064+
struct amount_msat prev_our_msats;
1065+
struct bitcoin_outpoint prev_funding_out;
10431066
s64 splice_amnt;
10441067
struct channel_inflight *inflight;
10451068
struct bitcoin_txid locked_txid;
@@ -1054,16 +1077,22 @@ static void handle_peer_splice_locked(struct channel *channel, const u8 *msg)
10541077
return;
10551078
}
10561079

1057-
channel->our_msat.millisatoshis += splice_amnt * 1000; /* Raw: splicing */
1058-
channel->msat_to_us_min.millisatoshis += splice_amnt * 1000; /* Raw: splicing */
1059-
channel->msat_to_us_max.millisatoshis += splice_amnt * 1000; /* Raw: splicing */
1060-
10611080
inflight = channel_inflight_find(channel, &locked_txid);
10621081
if(!inflight)
10631082
channel_internal_error(channel, "Unable to load inflight for"
10641083
" locked_txid %s",
10651084
fmt_bitcoin_txid(tmpctx, &locked_txid));
10661085

1086+
/* Stash prev funding data so we can log it after scid is updated
1087+
* (to get the blockheight) */
1088+
prev_our_msats = channel->our_msat;
1089+
prev_funding_sats = channel->funding_sats;
1090+
prev_funding_out = channel->funding;
1091+
1092+
channel->our_msat.millisatoshis += splice_amnt * 1000; /* Raw: splicing */
1093+
channel->msat_to_us_min.millisatoshis += splice_amnt * 1000; /* Raw: splicing */
1094+
channel->msat_to_us_max.millisatoshis += splice_amnt * 1000; /* Raw: splicing */
1095+
10671096
wallet_htlcsigs_confirm_inflight(channel->peer->ld->wallet, channel,
10681097
&inflight->funding->outpoint);
10691098

@@ -1085,6 +1114,16 @@ static void handle_peer_splice_locked(struct channel *channel, const u8 *msg)
10851114
/* That freed watchers in inflights: now watch funding tx */
10861115
channel_watch_funding(channel->peer->ld, channel);
10871116

1117+
/* Log that funding output has been spent */
1118+
channel_record_splice(channel,
1119+
prev_our_msats,
1120+
prev_funding_sats,
1121+
&prev_funding_out,
1122+
channel->scid ?
1123+
short_channel_id_blocknum(*channel->scid) : 0,
1124+
&locked_txid,
1125+
inflight);
1126+
10881127
/* Put the successful inflight back in as a memory-only object.
10891128
* peer_control's funding_spent function will pick this up and clean up
10901129
* our inflight.

onchaind/onchaind.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3463,14 +3463,15 @@ int main(int argc, char *argv[])
34633463
FUNDING_OUTPUT, NULL, NULL, NULL);
34643464

34653465
/* Record funding output spent */
3466-
send_coin_mvt(take(new_coin_channel_close(NULL, &tx->txid,
3466+
send_coin_mvt(take(new_coin_channel_close(NULL, NULL, &tx->txid,
34673467
&funding, tx_blockheight,
34683468
our_msat,
34693469
funding_sats,
34703470
is_elements(chainparams) ?
34713471
/* Minus 1, fee output */
34723472
tal_count(tx->outputs) - 1 :
3473-
tal_count(tx->outputs))));
3473+
tal_count(tx->outputs),
3474+
/* is_splice? */ false)));
34743475

34753476
status_debug("Remote per-commit point: %s",
34763477
fmt_pubkey(tmpctx, &remote_per_commit_point));

onchaind/test/run-grind_feerate-bug.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,14 @@ void memleak_status_broken(void *unused UNNEEDED, const char *fmt UNNEEDED, ...)
103103
{ fprintf(stderr, "memleak_status_broken called!\n"); abort(); }
104104
/* Generated stub for new_coin_channel_close */
105105
struct chain_coin_mvt *new_coin_channel_close(const tal_t *ctx UNNEEDED,
106+
const struct channel_id *chan_id UNNEEDED,
106107
const struct bitcoin_txid *txid UNNEEDED,
107108
const struct bitcoin_outpoint *out UNNEEDED,
108109
u32 blockheight UNNEEDED,
109110
const struct amount_msat amount UNNEEDED,
110111
const struct amount_sat output_val UNNEEDED,
111-
u32 output_count)
112+
u32 output_count UNNEEDED,
113+
bool is_splice)
112114

113115
{ fprintf(stderr, "new_coin_channel_close called!\n"); abort(); }
114116
/* Generated stub for new_coin_external_deposit */

onchaind/test/run-grind_feerate.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,14 @@ void memleak_status_broken(void *unused UNNEEDED, const char *fmt UNNEEDED, ...)
153153
{ fprintf(stderr, "memleak_status_broken called!\n"); abort(); }
154154
/* Generated stub for new_coin_channel_close */
155155
struct chain_coin_mvt *new_coin_channel_close(const tal_t *ctx UNNEEDED,
156+
const struct channel_id *chan_id UNNEEDED,
156157
const struct bitcoin_txid *txid UNNEEDED,
157158
const struct bitcoin_outpoint *out UNNEEDED,
158159
u32 blockheight UNNEEDED,
159160
const struct amount_msat amount UNNEEDED,
160161
const struct amount_sat output_val UNNEEDED,
161-
u32 output_count)
162+
u32 output_count UNNEEDED,
163+
bool is_splice)
162164

163165
{ fprintf(stderr, "new_coin_channel_close called!\n"); abort(); }
164166
/* Generated stub for new_coin_external_deposit */

plugins/bkpr/recorder.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,7 @@ void maybe_update_account(struct db *db,
12941294
case TO_MINER:
12951295
case LEASE_FEE:
12961296
case STEALABLE:
1297+
case SPLICE:
12971298
/* Ignored */
12981299
break;
12991300
}

wallet/test/run-wallet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,7 +1002,7 @@ void topology_add_sync_waiter_(const tal_t *ctx UNNEEDED,
10021002
u8 *towire_announcement_signatures(const tal_t *ctx UNNEEDED, const struct channel_id *channel_id UNNEEDED, struct short_channel_id short_channel_id UNNEEDED, const secp256k1_ecdsa_signature *node_signature UNNEEDED, const secp256k1_ecdsa_signature *bitcoin_signature UNNEEDED)
10031003
{ fprintf(stderr, "towire_announcement_signatures called!\n"); abort(); }
10041004
/* Generated stub for towire_channel_reestablish */
1005-
u8 *towire_channel_reestablish(const tal_t *ctx UNNEEDED, const struct channel_id *channel_id UNNEEDED, u64 next_commitment_number UNNEEDED, u64 next_revocation_number UNNEEDED, const struct secret *your_last_per_commitment_secret UNNEEDED, const struct pubkey *my_current_per_commitment_point UNNEEDED, const struct tlv_channel_reestablish_tlvs *channel_reestablish UNNEEDED)
1005+
u8 *towire_channel_reestablish(const tal_t *ctx UNNEEDED, const struct channel_id *channel_id UNNEEDED, u64 next_commitment_number UNNEEDED, u64 next_revocation_number UNNEEDED, const struct secret *your_last_per_commitment_secret UNNEEDED, const struct pubkey *my_current_per_commitment_point UNNEEDED, const struct tlv_channel_reestablish_tlvs *tlvs UNNEEDED)
10061006
{ fprintf(stderr, "towire_channel_reestablish called!\n"); abort(); }
10071007
/* Generated stub for towire_channeld_dev_memleak */
10081008
u8 *towire_channeld_dev_memleak(const tal_t *ctx UNNEEDED)

0 commit comments

Comments
 (0)