Skip to content

Commit ff433a1

Browse files
committed
lightningd: save funding PSBT to database if we're to withhold it.
Normally we don't care, but if we're withholding it, keep it around so we can sign & broadcast later. Signed-off-by: Rusty Russell <[email protected]>
1 parent df5f38d commit ff433a1

File tree

11 files changed

+44
-13
lines changed

11 files changed

+44
-13
lines changed

lightningd/channel.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ struct channel *new_unsaved_channel(struct peer *peer,
436436
channel->channel_gossip = NULL;
437437
channel->forgets = tal_arr(channel, struct command *, 0);
438438
channel->funding_psbt = NULL;
439+
channel->withheld = false;
439440
list_add_tail(&peer->channels, &channel->list);
440441
channel->rr_number = peer->ld->rr_counter++;
441442
tal_add_destructor(channel, destroy_channel);
@@ -558,7 +559,8 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
558559
u64 last_stable_connection,
559560
const struct channel_stats *stats,
560561
struct channel_state_change **state_changes STEALS,
561-
const struct wally_psbt *funding_psbt STEALS)
562+
const struct wally_psbt *funding_psbt STEALS,
563+
bool withheld)
562564
{
563565
struct channel *channel = tal(peer->ld, struct channel);
564566
struct amount_msat htlc_min, htlc_max;
@@ -735,6 +737,7 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
735737
&channel->cid,
736738
"We can't be together anymore.");
737739
channel->funding_psbt = tal_steal(channel, funding_psbt);
740+
channel->withheld = withheld;
738741
return channel;
739742
}
740743

lightningd/channel.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,9 @@ struct channel {
359359

360360
/* Unsigned PSBT if we initiated the open channel */
361361
const struct wally_psbt *funding_psbt;
362+
363+
/* Are we not broadcasting the open tx? */
364+
bool withheld;
362365
};
363366

364367
/* Is channel owned (and should be talking to peer) */
@@ -445,7 +448,8 @@ struct channel *new_channel(struct peer *peer, u64 dbid,
445448
u64 last_stable_connection,
446449
const struct channel_stats *stats,
447450
struct channel_state_change **state_changes STEALS,
448-
const struct wally_psbt *funding_psbt STEALS);
451+
const struct wally_psbt *funding_psbt STEALS,
452+
bool withheld);
449453

450454
/* new_inflight - Create a new channel_inflight for a channel */
451455
struct channel_inflight *new_inflight(struct channel *channel,

lightningd/closed_channel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct closed_channel {
3131
/* NULL for older closed channels */
3232
const struct shachain *their_shachain;
3333
const struct wally_psbt *funding_psbt;
34+
bool withheld;
3435
};
3536

3637
static inline const struct channel_id *keyof_closed_channel(const struct closed_channel *cc)

lightningd/opening_common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ struct funding_channel {
104104

105105
/* Were we the one to publish the commitment/splicing tx? */
106106
const struct wally_psbt *funding_psbt;
107+
108+
/* Were we told to withhold the commitment tx? */
109+
bool withheld;
107110
};
108111

109112
struct uncommitted_channel *new_uncommitted_channel(struct peer *peer);

lightningd/opening_control.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ wallet_commit_channel(struct lightningd *ld,
9797
const u8 *our_upfront_shutdown_script,
9898
const u8 *remote_upfront_shutdown_script,
9999
const struct channel_type *type,
100-
const struct wally_psbt *funding_psbt)
100+
const struct wally_psbt *funding_psbt,
101+
bool withheld)
101102
{
102103
struct channel *channel;
103104
struct amount_msat our_msat;
@@ -237,7 +238,8 @@ wallet_commit_channel(struct lightningd *ld,
237238
0,
238239
&zero_channel_stats,
239240
tal_arr(NULL, struct channel_state_change *, 0),
240-
funding_psbt);
241+
funding_psbt,
242+
withheld);
241243

242244
/* Now we finally put it in the database. */
243245
wallet_channel_insert(ld->wallet, channel);
@@ -446,7 +448,8 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
446448
fc->our_upfront_shutdown_script,
447449
remote_upfront_shutdown_script,
448450
type,
449-
fc->funding_psbt);
451+
fc->funding_psbt,
452+
fc->withheld);
450453
if (!channel) {
451454
was_pending(command_fail(fc->cmd, LIGHTNINGD,
452455
"Key generation failure"));
@@ -550,7 +553,8 @@ static void opening_fundee_finished(struct subd *openingd,
550553
local_upfront_shutdown_script,
551554
remote_upfront_shutdown_script,
552555
type,
553-
NULL);
556+
NULL,
557+
false);
554558
if (!channel) {
555559
uncommitted_channel_disconnect(uc, LOG_BROKEN,
556560
"Commit channel failed");
@@ -1096,6 +1100,9 @@ static struct command_result *json_fundchannel_complete(struct command *cmd,
10961100

10971101
fc->funding_psbt = tal_steal(fc, funding_psbt);
10981102

1103+
/* FIXME: Set by option */
1104+
fc->withheld = false;
1105+
10991106
/* Set the cmd to this new cmd */
11001107
peer->uncommitted_channel->fc->cmd = cmd;
11011108
msg = towire_openingd_funder_complete(NULL,
@@ -1644,7 +1651,8 @@ static struct channel *stub_chan(struct command *cmd,
16441651
0,
16451652
&zero_channel_stats,
16461653
tal_arr(NULL, struct channel_state_change *, 0),
1647-
NULL);
1654+
NULL,
1655+
false);
16481656

16491657
/* We don't want to gossip about this, ever. */
16501658
channel->channel_gossip = tal_free(channel->channel_gossip);

wallet/db.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,7 @@ static struct migration dbmigrations[] = {
11011101
" PRIMARY KEY (id)"
11021102
")"), NULL},
11031103
{NULL, migrate_fail_pending_payments_without_htlcs},
1104+
{SQL("ALTER TABLE channels ADD withheld INTEGER DEFAULT 0;"), NULL},
11041105
};
11051106

11061107
/**

wallet/test/run-chain_moves_duplicate-detect.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ struct channel *new_channel(struct peer *peer UNNEEDED, u64 dbid UNNEEDED,
235235
u64 last_stable_connection UNNEEDED,
236236
const struct channel_stats *stats UNNEEDED,
237237
struct channel_state_change **state_changes STEALS UNNEEDED,
238-
const struct wally_psbt *funding_psbt STEALS UNNEEDED)
238+
const struct wally_psbt *funding_psbt STEALS UNNEEDED,
239+
bool withheld UNNEEDED)
239240
{ fprintf(stderr, "new_channel called!\n"); abort(); }
240241
/* Generated stub for new_channel_state_change */
241242
struct channel_state_change *new_channel_state_change(const tal_t *ctx UNNEEDED,

wallet/test/run-db.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ struct channel *new_channel(struct peer *peer UNNEEDED, u64 dbid UNNEEDED,
243243
u64 last_stable_connection UNNEEDED,
244244
const struct channel_stats *stats UNNEEDED,
245245
struct channel_state_change **state_changes STEALS UNNEEDED,
246-
const struct wally_psbt *funding_psbt STEALS UNNEEDED)
246+
const struct wally_psbt *funding_psbt STEALS UNNEEDED,
247+
bool withheld UNNEEDED)
247248
{ fprintf(stderr, "new_channel called!\n"); abort(); }
248249
/* Generated stub for new_channel_state_change */
249250
struct channel_state_change *new_channel_state_change(const tal_t *ctx UNNEEDED,

wallet/test/run-migrate_remove_chain_moves_duplicates.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ struct channel *new_channel(struct peer *peer UNNEEDED, u64 dbid UNNEEDED,
250250
u64 last_stable_connection UNNEEDED,
251251
const struct channel_stats *stats UNNEEDED,
252252
struct channel_state_change **state_changes STEALS UNNEEDED,
253-
const struct wally_psbt *funding_psbt STEALS UNNEEDED)
253+
const struct wally_psbt *funding_psbt STEALS UNNEEDED,
254+
bool withheld UNNEEDED)
254255
{ fprintf(stderr, "new_channel called!\n"); abort(); }
255256
/* Generated stub for new_channel_state_change */
256257
struct channel_state_change *new_channel_state_change(const tal_t *ctx UNNEEDED,

wallet/test/run-wallet.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,8 @@ static bool test_channel_inflight_crud(struct lightningd *ld, const tal_t *ctx)
16251625
0,
16261626
stats,
16271627
tal_arr(NULL, struct channel_state_change *, 0),
1628-
NULL);
1628+
NULL,
1629+
false);
16291630
db_begin_transaction(w->db);
16301631
CHECK(!wallet_err);
16311632
wallet_channel_insert(w, chan);

0 commit comments

Comments
 (0)