Skip to content

Commit f4a8e46

Browse files
committed
Remove race condition in test unified_send_receive
Decrease timeouts to not falsely conclude some tests as passing
1 parent eeb9e1c commit f4a8e46

File tree

2 files changed

+19
-33
lines changed

2 files changed

+19
-33
lines changed

tests/common/mod.rs

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use electrsd::{corepc_node, ElectrsD};
2828
use electrum_client::ElectrumApi;
2929
use ldk_node::config::{
3030
AsyncPaymentsRole, CbfSyncConfig, Config, ElectrumSyncConfig, EsploraSyncConfig,
31+
SyncTimeoutsConfig,
3132
};
3233
use ldk_node::entropy::{generate_entropy_mnemonic, NodeEntropy};
3334
use ldk_node::io::sqlite_store::SqliteStore;
@@ -498,7 +499,18 @@ pub(crate) fn setup_node(chain_source: &TestChainSource, config: TestConfig) ->
498499
TestChainSource::Cbf(bitcoind) => {
499500
let p2p_socket = bitcoind.params.p2p_socket.expect("P2P must be enabled for CBF");
500501
let peer_addr = format!("{}", p2p_socket);
501-
let sync_config = CbfSyncConfig { background_sync_config: None, ..Default::default() };
502+
let timeouts_config = SyncTimeoutsConfig {
503+
onchain_wallet_sync_timeout_secs: 3,
504+
lightning_wallet_sync_timeout_secs: 3,
505+
fee_rate_cache_update_timeout_secs: 3,
506+
tx_broadcast_timeout_secs: 3,
507+
per_request_timeout_secs: 3,
508+
};
509+
let sync_config = CbfSyncConfig {
510+
background_sync_config: None,
511+
timeouts_config,
512+
..Default::default()
513+
};
502514
builder.set_chain_source_cbf(vec![peer_addr], Some(sync_config), None);
503515
},
504516
}
@@ -628,31 +640,6 @@ pub(crate) async fn wait_for_outpoint_spend<E: ElectrumApi>(electrs: &E, outpoin
628640
.await;
629641
}
630642

631-
/// Wait until a transaction spending the given outpoint appears in bitcoind's mempool.
632-
///
633-
/// This is more reliable than the electrum-based `wait_for_outpoint_spend` for CBF nodes,
634-
/// where the close tx is broadcast via P2P and electrs may not index it immediately.
635-
pub(crate) async fn wait_for_outpoint_spend_in_mempool(
636-
bitcoind: &BitcoindClient, outpoint: OutPoint,
637-
) {
638-
let check = || {
639-
let mempool = bitcoind.get_raw_mempool().unwrap().into_model().unwrap();
640-
for txid in mempool.0 {
641-
let tx = bitcoind.get_raw_transaction(txid).unwrap().into_model().unwrap().0;
642-
if tx.input.iter().any(|inp| inp.previous_output == outpoint) {
643-
return Some(());
644-
}
645-
}
646-
None
647-
};
648-
649-
if check().is_some() {
650-
return;
651-
}
652-
653-
exponential_backoff_poll(check).await;
654-
}
655-
656643
pub(crate) async fn wait_for_cbf_sync(node: &TestNode) {
657644
let before = node.status().latest_onchain_wallet_sync_timestamp;
658645
let mut delay = Duration::from_millis(200);
@@ -1364,10 +1351,8 @@ pub(crate) async fn do_channel_full_cycle<E: ElectrumApi>(
13641351

13651352
// After splices, the latest funding outpoint is from the last splice.
13661353
// We must wait for the close tx (which spends the latest funding output)
1367-
// to reach bitcoind's mempool before mining. For CBF nodes the close tx
1368-
// is broadcast via P2P so we poll bitcoind directly rather than relying
1369-
// on electrs indexing.
1370-
wait_for_outpoint_spend_in_mempool(bitcoind, splice_in_txo).await;
1354+
// to propagate before mining.
1355+
wait_for_outpoint_spend(electrsd, splice_in_txo).await;
13711356

13721357
generate_blocks_and_wait(&bitcoind, electrsd, 1).await;
13731358
node_a.sync_wallets().unwrap();

tests/integration_tests_rust.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ use common::{
2323
expect_payment_successful_event, expect_splice_pending_event, generate_blocks_and_wait,
2424
open_channel, open_channel_push_amt, open_channel_with_all, premine_and_distribute_funds,
2525
premine_blocks, prepare_rbf, random_chain_source, random_config, random_listening_addresses,
26-
setup_bitcoind_and_electrsd, setup_builder, setup_node, setup_two_nodes, splice_in_with_all,
27-
skip_if_cbf, wait_for_cbf_sync, wait_for_tx, TestChainSource, TestStoreType, TestSyncStore,
26+
setup_bitcoind_and_electrsd, setup_builder, setup_node, setup_two_nodes, skip_if_cbf,
27+
splice_in_with_all, wait_for_cbf_sync, wait_for_tx, TestChainSource, TestStoreType,
28+
TestSyncStore,
2829
};
2930
use ldk_node::config::{AsyncPaymentsRole, EsploraSyncConfig};
3031
use ldk_node::entropy::NodeEntropy;
@@ -1669,8 +1670,8 @@ async fn unified_send_receive_bip21_uri() {
16691670
},
16701671
};
16711672

1672-
generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 6).await;
16731673
wait_for_tx(&electrsd.client, txid).await;
1674+
generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 6).await;
16741675

16751676
node_a.sync_wallets().unwrap();
16761677
node_b.sync_wallets().unwrap();

0 commit comments

Comments
 (0)