Skip to content

Commit d44fa2f

Browse files
committed
lightningd: re-xmit funding txs on startup.
Signed-off-by: Rusty Russell <[email protected]> Changelog-Fixed: Protocol: we now re-transmit unseen funding transactions on startup, for more robustness.
1 parent ae9ecba commit d44fa2f

File tree

8 files changed

+70
-3
lines changed

8 files changed

+70
-3
lines changed

lightningd/bitcoind.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void bitcoind_sendrawtx_(const tal_t *ctx,
7777
const char *id_prefix TAKES,
7878
const char *hextx,
7979
bool allowhighfees,
80-
void (*cb)(struct bitcoind *bitcoind,
80+
void (*cb)(struct bitcoind *,
8181
bool success, const char *msg, void *),
8282
void *arg);
8383
#define bitcoind_sendrawtx(ctx, bitcoind_, id_prefix, hextx, allowhighfees, cb, arg) \

lightningd/lightningd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1447,9 +1447,10 @@ int main(int argc, char *argv[])
14471447
plugin_hook_call_recover(ld, NULL, payload);
14481448
}
14491449

1450-
/*~ If we have channels closing, make sure we re-xmit the last
1450+
/*~ If we have channels closing or opening, make sure we re-xmit the last
14511451
* transaction, in case bitcoind lost it. */
14521452
db_begin_transaction(ld->wallet->db);
1453+
resend_opening_transactions(ld);
14531454
resend_closing_transactions(ld);
14541455
db_commit_transaction(ld->wallet->db);
14551456

lightningd/peer_control.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,47 @@ void resend_closing_transactions(struct lightningd *ld)
478478
}
479479
}
480480

481+
static void resend_funding_done(struct bitcoind *bitcoind,
482+
bool success,
483+
const char *msg,
484+
struct channel *channel)
485+
{
486+
if (success)
487+
log_info(channel->log, "Successfully rexmitted funding tx");
488+
else
489+
log_unusual(channel->log, "Failed to re-transmit funding tx: %s", msg);
490+
}
491+
492+
void resend_opening_transactions(struct lightningd *ld)
493+
{
494+
struct peer *peer;
495+
struct channel *channel;
496+
struct peer_node_id_map_iter it;
497+
498+
for (peer = peer_node_id_map_first(ld->peers, &it);
499+
peer;
500+
peer = peer_node_id_map_next(ld->peers, &it)) {
501+
list_for_each(&peer->channels, channel, list) {
502+
struct wally_tx *wtx;
503+
if (channel_state_uncommitted(channel->state))
504+
continue;
505+
if (!channel->funding_psbt)
506+
continue;
507+
if (channel->depth != 0)
508+
continue;
509+
wtx = psbt_final_tx(tmpctx, channel->funding_psbt);
510+
if (!wtx)
511+
continue;
512+
bitcoind_sendrawtx(channel,
513+
ld->topology->bitcoind,
514+
NULL,
515+
tal_hex(tmpctx,
516+
linearize_wtx(tmpctx, wtx)),
517+
false, resend_funding_done, channel);
518+
}
519+
}
520+
}
521+
481522
void channel_errmsg(struct channel *channel,
482523
struct peer_fd *peer_fd,
483524
const char *desc,

lightningd/peer_control.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ void peer_set_dbid(struct peer *peer, u64 dbid);
119119
/* At startup, re-send any transactions we want bitcoind to have */
120120
void resend_closing_transactions(struct lightningd *ld);
121121

122+
/* At startup, re-send any funding transactions we want bitcoind to have */
123+
void resend_opening_transactions(struct lightningd *ld);
124+
122125
/* Initiate the close of a channel, maybe broadcast. If we've seen a
123126
* unilateral close, pass it here (means we don't need to broadcast
124127
* our own, or any anchors). */

lightningd/test/run-find_my_abspath.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ void plugins_set_builtin_plugins_dir(struct plugins *plugins UNNEEDED,
184184
/* Generated stub for resend_closing_transactions */
185185
void resend_closing_transactions(struct lightningd *ld UNNEEDED)
186186
{ fprintf(stderr, "resend_closing_transactions called!\n"); abort(); }
187+
/* Generated stub for resend_opening_transactions */
188+
void resend_opening_transactions(struct lightningd *ld UNNEEDED)
189+
{ fprintf(stderr, "resend_opening_transactions called!\n"); abort(); }
187190
/* Generated stub for runes_early_init */
188191
struct runes *runes_early_init(struct lightningd *ld UNNEEDED)
189192
{ fprintf(stderr, "runes_early_init called!\n"); abort(); }

lightningd/test/run-invoice-select-inchan.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ void bitcoind_getutxout_(const tal_t *ctx UNNEEDED,
2929
void *) UNNEEDED,
3030
void *arg UNNEEDED)
3131
{ fprintf(stderr, "bitcoind_getutxout_ called!\n"); abort(); }
32+
/* Generated stub for bitcoind_sendrawtx_ */
33+
void bitcoind_sendrawtx_(const tal_t *ctx UNNEEDED,
34+
struct bitcoind *bitcoind UNNEEDED,
35+
const char *id_prefix TAKES UNNEEDED,
36+
const char *hextx UNNEEDED,
37+
bool allowhighfees UNNEEDED,
38+
void (*cb)(struct bitcoind * UNNEEDED,
39+
bool success UNNEEDED, const char *msg UNNEEDED, void *) UNNEEDED,
40+
void *arg UNNEEDED)
41+
{ fprintf(stderr, "bitcoind_sendrawtx_ called!\n"); abort(); }
3242
/* Generated stub for broadcast_tx_ */
3343
void broadcast_tx_(const tal_t *ctx UNNEEDED,
3444
struct chain_topology *topo UNNEEDED,

tests/test_opening.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2827,7 +2827,6 @@ def test_opening_below_min_capacity_sat(bitcoind, node_factory):
28272827
assert not l2.daemon.is_in_log('peer_in WIRE_ERROR')
28282828

28292829

2830-
@pytest.mark.xfail(strict=True)
28312830
@pytest.mark.openchannel('v1')
28322831
@pytest.mark.openchannel('v2')
28332832
def test_opening_crash(bitcoind, node_factory):

wallet/test/run-wallet.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ void bitcoind_getutxout_(const tal_t *ctx UNNEEDED,
6767
void *) UNNEEDED,
6868
void *arg UNNEEDED)
6969
{ fprintf(stderr, "bitcoind_getutxout_ called!\n"); abort(); }
70+
/* Generated stub for bitcoind_sendrawtx_ */
71+
void bitcoind_sendrawtx_(const tal_t *ctx UNNEEDED,
72+
struct bitcoind *bitcoind UNNEEDED,
73+
const char *id_prefix TAKES UNNEEDED,
74+
const char *hextx UNNEEDED,
75+
bool allowhighfees UNNEEDED,
76+
void (*cb)(struct bitcoind * UNNEEDED,
77+
bool success UNNEEDED, const char *msg UNNEEDED, void *) UNNEEDED,
78+
void *arg UNNEEDED)
79+
{ fprintf(stderr, "bitcoind_sendrawtx_ called!\n"); abort(); }
7080
/* Generated stub for broadcast_tx_ */
7181
void broadcast_tx_(const tal_t *ctx UNNEEDED,
7282
struct chain_topology *topo UNNEEDED,

0 commit comments

Comments
 (0)