Skip to content

Commit f790560

Browse files
committed
Manually accept inbound channels
Since we plan to add support for opening anchor outputs channels, we'll need to support manually accepting inbound channels first to do so.
1 parent 34a748c commit f790560

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/main.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,34 @@ async fn handle_ldk_events(
278278
}
279279
persister.persist(OUTBOUND_PAYMENTS_FNAME, &*outbound).unwrap();
280280
}
281-
Event::OpenChannelRequest { .. } => {
282-
// Unreachable, we don't set manually_accept_inbound_channels
281+
Event::OpenChannelRequest {
282+
ref temporary_channel_id, ref counterparty_node_id, ..
283+
} => {
284+
let mut random_bytes = [0u8; 16];
285+
random_bytes.copy_from_slice(&keys_manager.get_secure_random_bytes()[..16]);
286+
let user_channel_id = u128::from_be_bytes(random_bytes);
287+
let res = channel_manager.accept_inbound_channel(
288+
temporary_channel_id,
289+
counterparty_node_id,
290+
user_channel_id,
291+
);
292+
293+
if let Err(e) = res {
294+
print!(
295+
"\nEVENT: Failed to accept inbound channel ({}) from {}: {:?}",
296+
hex_utils::hex_str(&temporary_channel_id[..]),
297+
hex_utils::hex_str(&counterparty_node_id.serialize()),
298+
e,
299+
);
300+
} else {
301+
print!(
302+
"\nEVENT: Accepted inbound channel ({}) from {}",
303+
hex_utils::hex_str(&temporary_channel_id[..]),
304+
hex_utils::hex_str(&counterparty_node_id.serialize()),
305+
);
306+
}
307+
print!("> ");
308+
io::stdout().flush().unwrap();
283309
}
284310
Event::PaymentPathSuccessful { .. } => {}
285311
Event::PaymentPathFailed { .. } => {}
@@ -566,6 +592,7 @@ async fn start_ldk() {
566592
// Step 11: Initialize the ChannelManager
567593
let mut user_config = UserConfig::default();
568594
user_config.channel_handshake_limits.force_announced_channel_preference = false;
595+
user_config.manually_accept_inbound_channels = true;
569596
let mut restarting_node = true;
570597
let (channel_manager_blockhash, channel_manager) = {
571598
if let Ok(mut f) = fs::File::open(format!("{}/manager", ldk_data_dir.clone())) {

0 commit comments

Comments
 (0)