Skip to content

Commit 27b9889

Browse files
committed
lightningd: fail too-large txs *before* opening channel.
Due to a bug elsewhere I actually triggered this path, and it broadcast the tx anyway, *then* closed the channel. We should abandon the channel if we can, instead. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent c0ddfa2 commit 27b9889

File tree

1 file changed

+47
-45
lines changed

1 file changed

+47
-45
lines changed

lightningd/dual_open_control.c

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,7 +1825,7 @@ static void handle_peer_tx_sigs_sent(struct subd *dualopend,
18251825
!inflight->tx_broadcast) {
18261826
inflight->tx_broadcast = true;
18271827

1828-
wtx = psbt_final_tx(NULL, inflight->funding_psbt);
1828+
wtx = psbt_final_tx(tmpctx, inflight->funding_psbt);
18291829
if (!wtx) {
18301830
channel_internal_error(channel,
18311831
"Unable to extract final tx"
@@ -1835,29 +1835,6 @@ static void handle_peer_tx_sigs_sent(struct subd *dualopend,
18351835
return;
18361836
}
18371837

1838-
/* Saves the now finalized version of the psbt */
1839-
wallet_inflight_save(dualopend->ld->wallet, inflight);
1840-
send_funding_tx(channel, take(wtx));
1841-
1842-
/* Must be in an "init" state */
1843-
assert(channel->state == DUALOPEND_OPEN_COMMITTED
1844-
|| channel->state == DUALOPEND_AWAITING_LOCKIN);
1845-
1846-
channel_set_state(channel, channel->state,
1847-
DUALOPEND_AWAITING_LOCKIN,
1848-
REASON_UNKNOWN,
1849-
"Sigs exchanged, waiting for lock-in");
1850-
1851-
/* Mimic the old behavior, notify a channel has been opened,
1852-
* for the accepter side */
1853-
if (channel->opener == REMOTE)
1854-
/* Tell plugins about the success */
1855-
notify_channel_opened(dualopend->ld,
1856-
&channel->peer->id,
1857-
&channel->funding_sats,
1858-
&channel->funding.txid,
1859-
channel->remote_channel_ready);
1860-
18611838
/* BOLT #2
18621839
* The receiving node: ...
18631840
* - MUST fail the channel if:
@@ -1879,7 +1856,31 @@ static void handle_peer_tx_sigs_sent(struct subd *dualopend,
18791856
/* Notify the peer we're failing */
18801857
subd_send_msg(dualopend,
18811858
take(towire_dualopend_fail(NULL, errmsg)));
1859+
return;
18821860
}
1861+
1862+
/* Saves the now finalized version of the psbt */
1863+
wallet_inflight_save(dualopend->ld->wallet, inflight);
1864+
send_funding_tx(channel, take(wtx));
1865+
1866+
/* Must be in an "init" state */
1867+
assert(channel->state == DUALOPEND_OPEN_COMMITTED
1868+
|| channel->state == DUALOPEND_AWAITING_LOCKIN);
1869+
1870+
channel_set_state(channel, channel->state,
1871+
DUALOPEND_AWAITING_LOCKIN,
1872+
REASON_UNKNOWN,
1873+
"Sigs exchanged, waiting for lock-in");
1874+
1875+
/* Mimic the old behavior, notify a channel has been opened,
1876+
* for the accepter side */
1877+
if (channel->opener == REMOTE)
1878+
/* Tell plugins about the success */
1879+
notify_channel_opened(dualopend->ld,
1880+
&channel->peer->id,
1881+
&channel->funding_sats,
1882+
&channel->funding.txid,
1883+
channel->remote_channel_ready);
18831884
}
18841885
}
18851886

@@ -2170,7 +2171,7 @@ static void handle_peer_tx_sigs_msg(struct subd *dualopend,
21702171

21712172
/* Saves the now finalized version of the psbt */
21722173
wallet_inflight_save(ld->wallet, inflight);
2173-
wtx = psbt_final_tx(NULL, inflight->funding_psbt);
2174+
wtx = psbt_final_tx(tmpctx, inflight->funding_psbt);
21742175
if (!wtx) {
21752176
channel_internal_error(channel,
21762177
"Unable to extract final tx"
@@ -2180,26 +2181,6 @@ static void handle_peer_tx_sigs_msg(struct subd *dualopend,
21802181
return;
21812182
}
21822183

2183-
send_funding_tx(channel, take(wtx));
2184-
2185-
assert(channel->state == DUALOPEND_OPEN_COMMITTED
2186-
/* We might be reconnecting */
2187-
|| channel->state == DUALOPEND_AWAITING_LOCKIN);
2188-
channel_set_state(channel, channel->state,
2189-
DUALOPEND_AWAITING_LOCKIN,
2190-
REASON_UNKNOWN,
2191-
"Sigs exchanged, waiting for lock-in");
2192-
2193-
/* Mimic the old behavior, notify a channel has been opened,
2194-
* for the accepter side */
2195-
if (channel->opener == REMOTE)
2196-
/* Tell plugins about the success */
2197-
notify_channel_opened(dualopend->ld,
2198-
&channel->peer->id,
2199-
&channel->funding_sats,
2200-
&channel->funding.txid,
2201-
channel->remote_channel_ready);
2202-
22032184
/* BOLT #2
22042185
* The receiving node: ...
22052186
* - MUST fail the channel if:
@@ -2221,7 +2202,28 @@ static void handle_peer_tx_sigs_msg(struct subd *dualopend,
22212202
/* Notify the peer we're failing */
22222203
subd_send_msg(dualopend,
22232204
take(towire_dualopend_fail(NULL, errmsg)));
2205+
return;
22242206
}
2207+
send_funding_tx(channel, take(wtx));
2208+
2209+
assert(channel->state == DUALOPEND_OPEN_COMMITTED
2210+
/* We might be reconnecting */
2211+
|| channel->state == DUALOPEND_AWAITING_LOCKIN);
2212+
channel_set_state(channel, channel->state,
2213+
DUALOPEND_AWAITING_LOCKIN,
2214+
REASON_UNKNOWN,
2215+
"Sigs exchanged, waiting for lock-in");
2216+
2217+
/* Mimic the old behavior, notify a channel has been opened,
2218+
* for the accepter side */
2219+
if (channel->opener == REMOTE)
2220+
/* Tell plugins about the success */
2221+
notify_channel_opened(dualopend->ld,
2222+
&channel->peer->id,
2223+
&channel->funding_sats,
2224+
&channel->funding.txid,
2225+
channel->remote_channel_ready);
2226+
22252227
}
22262228

22272229
/* Send notification with peer's signed PSBT */

0 commit comments

Comments
 (0)