Skip to content

Commit dd68c11

Browse files
committed
Finish async node API migration
Expose startup, shutdown, builder, wallet, liquidity, and bindings entrypoints as async so store-backed persistence no longer needs local synchronous future driving. Update tests and benches to await the async surface and keep store persistence helpers on the async storage path. Co-Authored-By: HAL 9000
1 parent c1fd9ff commit dd68c11

19 files changed

Lines changed: 943 additions & 931 deletions

benches/payments.rs

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ fn spawn_payment(node_a: Arc<Node>, node_b: Arc<Node>, amount_msat: u64) {
3535
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
3636
}
3737

38-
let payment_id = node_a.spontaneous_payment().send_with_preimage(
38+
let spontaneous_payment = node_a.spontaneous_payment();
39+
let payment_id = spontaneous_payment.send_with_preimage(
3940
amount_msat,
4041
node_b.node_id(),
4142
preimage,
4243
None,
4344
);
4445

45-
match payment_id {
46+
match payment_id.await {
4647
Ok(payment_id) => {
4748
println!(
4849
"{}: Awaiting payment with id {}",
@@ -93,7 +94,7 @@ async fn send_payments(node_a: Arc<Node>, node_b: Arc<Node>) -> std::time::Durat
9394
},
9495
}
9596

96-
node_a.event_handled().unwrap();
97+
node_a.event_handled().await.unwrap();
9798
}
9899

99100
let duration = start.elapsed();
@@ -110,37 +111,36 @@ async fn send_payments(node_a: Arc<Node>, node_b: Arc<Node>) -> std::time::Durat
110111
PaymentPreimage(preimage_bytes),
111112
None,
112113
)
114+
.await
113115
.ok()
114116
.unwrap();
115117

116118
duration
117119
}
118120

119121
fn payment_benchmark(c: &mut Criterion) {
120-
// Set up two nodes. Because this is slow, we reuse the same nodes for each sample.
121-
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
122-
let chain_source = random_chain_source(&bitcoind, &electrsd);
123-
124-
let (node_a, node_b) = setup_two_nodes_with_store(
125-
&chain_source,
126-
false,
127-
true,
128-
false,
129-
common::TestStoreType::Sqlite,
130-
);
131-
132122
let runtime =
133123
tokio::runtime::Builder::new_multi_thread().worker_threads(4).enable_all().build().unwrap();
134124

135-
let node_a = Arc::new(node_a);
136-
let node_b = Arc::new(node_b);
125+
// Set up two nodes. Because this is slow, we reuse the same nodes for each sample.
126+
let (setup_done, setup_result) = std::sync::mpsc::channel();
127+
runtime.spawn(async move {
128+
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();
129+
let chain_source = random_chain_source(&bitcoind, &electrsd);
130+
let (node_a, node_b) = setup_two_nodes_with_store(
131+
&chain_source,
132+
false,
133+
true,
134+
false,
135+
common::TestStoreType::Sqlite,
136+
)
137+
.await;
138+
139+
let node_a = Arc::new(node_a);
140+
let node_b = Arc::new(node_b);
137141

138-
// Fund the nodes and setup a channel between them. The criterion function cannot be async, so we need to execute
139-
// the setup using a runtime.
140-
let node_a_cloned = Arc::clone(&node_a);
141-
let node_b_cloned = Arc::clone(&node_b);
142-
runtime.block_on(async move {
143-
let address_a = node_a_cloned.onchain_payment().new_address().unwrap();
142+
// Fund the nodes and setup a channel between them.
143+
let address_a = node_a.onchain_payment().new_address().await.unwrap();
144144
let premine_sat = 25_000_000;
145145
premine_and_distribute_funds(
146146
&bitcoind.client,
@@ -149,23 +149,18 @@ fn payment_benchmark(c: &mut Criterion) {
149149
Amount::from_sat(premine_sat),
150150
)
151151
.await;
152-
node_a_cloned.sync_wallets().unwrap();
153-
node_b_cloned.sync_wallets().unwrap();
154-
open_channel_push_amt(
155-
&node_a_cloned,
156-
&node_b_cloned,
157-
16_000_000,
158-
Some(1_000_000_000),
159-
false,
160-
&electrsd,
161-
)
162-
.await;
152+
node_a.sync_wallets().await.unwrap();
153+
node_b.sync_wallets().await.unwrap();
154+
open_channel_push_amt(&node_a, &node_b, 16_000_000, Some(1_000_000_000), false, &electrsd)
155+
.await;
163156
generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 6).await;
164-
node_a_cloned.sync_wallets().unwrap();
165-
node_b_cloned.sync_wallets().unwrap();
166-
expect_channel_ready_event!(node_a_cloned, node_b_cloned.node_id());
167-
expect_channel_ready_event!(node_b_cloned, node_a_cloned.node_id());
157+
node_a.sync_wallets().await.unwrap();
158+
node_b.sync_wallets().await.unwrap();
159+
expect_channel_ready_event!(node_a, node_b.node_id());
160+
expect_channel_ready_event!(node_b, node_a.node_id());
161+
setup_done.send((node_a, node_b)).unwrap();
168162
});
163+
let (node_a, node_b) = setup_result.recv().unwrap();
169164

170165
let mut group = c.benchmark_group("payments");
171166
group.sample_size(10);

bindings/ldk_node.udl

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,35 +61,36 @@ interface Builder {
6161
[Throws=BuildError]
6262
void set_async_payments_role(AsyncPaymentsRole? role);
6363
void set_wallet_recovery_mode();
64-
[Throws=BuildError]
64+
[Async, Throws=BuildError]
6565
Node build(NodeEntropy node_entropy);
66-
[Throws=BuildError]
66+
[Async, Throws=BuildError]
6767
Node build_with_postgres_store(NodeEntropy node_entropy, string connection_string, string? db_name, string? kv_table_name, string? certificate_pem);
68-
[Throws=BuildError]
68+
[Async, Throws=BuildError]
6969
Node build_with_fs_store(NodeEntropy node_entropy);
70-
[Throws=BuildError]
70+
[Async, Throws=BuildError]
7171
Node build_with_vss_store(NodeEntropy node_entropy, string vss_url, string store_id, record<string, string> fixed_headers);
72-
[Throws=BuildError]
72+
[Async, Throws=BuildError]
7373
Node build_with_vss_store_and_lnurl_auth(NodeEntropy node_entropy, string vss_url, string store_id, string lnurl_auth_server_url, record<string, string> fixed_headers);
74-
[Throws=BuildError]
74+
[Async, Throws=BuildError]
7575
Node build_with_vss_store_and_fixed_headers(NodeEntropy node_entropy, string vss_url, string store_id, record<string, string> fixed_headers);
76-
[Throws=BuildError]
76+
[Async, Throws=BuildError]
7777
Node build_with_vss_store_and_header_provider(NodeEntropy node_entropy, string vss_url, string store_id, VssHeaderProvider header_provider);
7878
};
7979

8080
interface Node {
81-
[Throws=NodeError]
81+
[Async, Throws=NodeError]
8282
void start();
83-
[Throws=NodeError]
83+
[Async, Throws=NodeError]
8484
void stop();
8585
[Async]
8686
NodeStatus status();
8787
Config config();
8888
Event? next_event();
89+
[Async]
8990
Event wait_next_event();
9091
[Async]
9192
Event next_event_async();
92-
[Throws=NodeError]
93+
[Async, Throws=NodeError]
9394
void event_handled();
9495
PublicKey node_id();
9596
sequence<SocketAddress>? listening_addresses();
@@ -101,7 +102,7 @@ interface Node {
101102
OnchainPayment onchain_payment();
102103
UnifiedPayment unified_payment();
103104
LSPS1Liquidity lsps1_liquidity();
104-
[Throws=NodeError]
105+
[Async, Throws=NodeError]
105106
void lnurl_auth(string lnurl);
106107
[Async, Throws=NodeError]
107108
void connect(PublicKey node_id, SocketAddress address, boolean persist);

0 commit comments

Comments
 (0)