@@ -1413,50 +1413,19 @@ static void handle_local_private_channel(struct subd *dualopend,
1413
1413
struct channel_send {
1414
1414
const struct wally_tx * wtx ;
1415
1415
struct channel * channel ;
1416
+ const char * err_msg ;
1416
1417
};
1417
1418
1418
- static void sendfunding_done (struct bitcoind * bitcoind UNUSED ,
1419
- bool success , const char * msg ,
1420
- struct channel_send * cs )
1419
+ static void handle_tx_broadcast (struct channel_send * cs )
1421
1420
{
1422
1421
struct lightningd * ld = cs -> channel -> peer -> ld ;
1423
- struct channel * channel = cs -> channel ;
1424
1422
const struct wally_tx * wtx = cs -> wtx ;
1423
+ struct channel * channel = cs -> channel ;
1424
+ struct command * cmd = channel -> openchannel_signed_cmd ;
1425
1425
struct json_stream * response ;
1426
1426
struct bitcoin_txid txid ;
1427
1427
struct amount_sat unused ;
1428
1428
int num_utxos ;
1429
- struct command * cmd = channel -> openchannel_signed_cmd ;
1430
- channel -> openchannel_signed_cmd = NULL ;
1431
-
1432
- if (!cmd && channel -> opener == LOCAL )
1433
- log_unusual (channel -> log ,
1434
- "No outstanding command for channel %s,"
1435
- " funding sent was success? %d" ,
1436
- type_to_string (tmpctx , struct channel_id ,
1437
- & channel -> cid ),
1438
- success );
1439
-
1440
- if (!success ) {
1441
- if (cmd )
1442
- was_pending (command_fail (cmd ,
1443
- FUNDING_BROADCAST_FAIL ,
1444
- "Error broadcasting funding "
1445
- "tx: %s. Unsent tx discarded "
1446
- "%s." ,
1447
- msg ,
1448
- type_to_string (tmpctx ,
1449
- struct wally_tx ,
1450
- wtx )));
1451
- log_unusual (channel -> log ,
1452
- "Error broadcasting funding "
1453
- "tx: %s. Unsent tx discarded "
1454
- "%s." ,
1455
- msg ,
1456
- type_to_string (tmpctx , struct wally_tx , wtx ));
1457
- tal_free (cs );
1458
- return ;
1459
- }
1460
1429
1461
1430
/* This might have spent UTXOs from our wallet */
1462
1431
num_utxos = wallet_extract_owned_outputs (ld -> wallet ,
@@ -1472,11 +1441,78 @@ static void sendfunding_done(struct bitcoind *bitcoind UNUSED,
1472
1441
json_add_txid (response , "txid" , & txid );
1473
1442
json_add_channel_id (response , "channel_id" , & channel -> cid );
1474
1443
was_pending (command_success (cmd , response ));
1444
+
1445
+ cs -> channel -> openchannel_signed_cmd = NULL ;
1475
1446
}
1447
+ }
1448
+
1449
+ static void check_utxo_block (struct bitcoind * bitcoind UNUSED ,
1450
+ const struct bitcoin_tx_output * txout ,
1451
+ void * arg )
1452
+ {
1453
+ struct channel_send * cs = arg ;
1454
+ struct command * cmd = cs -> channel -> openchannel_signed_cmd ;
1455
+ const struct wally_tx * wtx = cs -> wtx ;
1456
+
1457
+ /* note: if this tx has been included in a block *and spent*
1458
+ * then this will also fail... */
1459
+ if (!txout ) {
1460
+ if (cmd ) {
1461
+ was_pending (command_fail (cmd ,
1462
+ FUNDING_BROADCAST_FAIL ,
1463
+ "Error broadcasting funding "
1464
+ "tx: %s. Unsent tx discarded "
1465
+ "%s." ,
1466
+ cs -> err_msg ,
1467
+ type_to_string (tmpctx ,
1468
+ struct wally_tx ,
1469
+ wtx )));
1470
+ cs -> channel -> openchannel_signed_cmd = NULL ;
1471
+ }
1472
+
1473
+ log_unusual (cs -> channel -> log ,
1474
+ "Error broadcasting funding "
1475
+ "tx: %s. Unsent tx discarded "
1476
+ "%s." ,
1477
+ cs -> err_msg ,
1478
+ type_to_string (tmpctx , struct wally_tx , wtx ));
1479
+ } else
1480
+ handle_tx_broadcast (cs );
1476
1481
1477
1482
tal_free (cs );
1478
1483
}
1479
1484
1485
+ static void sendfunding_done (struct bitcoind * bitcoind UNUSED ,
1486
+ bool success , const char * msg ,
1487
+ struct channel_send * cs )
1488
+ {
1489
+ struct lightningd * ld = cs -> channel -> peer -> ld ;
1490
+ struct channel * channel = cs -> channel ;
1491
+ struct command * cmd = channel -> openchannel_signed_cmd ;
1492
+
1493
+ if (!cmd && channel -> opener == LOCAL )
1494
+ log_unusual (channel -> log ,
1495
+ "No outstanding command for channel %s,"
1496
+ " funding sent was success? %d" ,
1497
+ type_to_string (tmpctx , struct channel_id ,
1498
+ & channel -> cid ),
1499
+ success );
1500
+
1501
+ if (success ) {
1502
+ handle_tx_broadcast (cs );
1503
+ tal_free (cs );
1504
+ } else {
1505
+ /* If the tx was mined into a block, it's possible
1506
+ * that the broadcast would fail. Verify that's not
1507
+ * the case here. */
1508
+ cs -> err_msg = tal_strdup (cs , msg );
1509
+ bitcoind_getutxout (ld -> topology -> bitcoind ,
1510
+ & channel -> funding ,
1511
+ check_utxo_block ,
1512
+ cs );
1513
+ }
1514
+ }
1515
+
1480
1516
1481
1517
static void send_funding_tx (struct channel * channel ,
1482
1518
const struct wally_tx * wtx TAKES )
0 commit comments