Merge pull request #2277 from valentinewallace/2023-05-fix-big-oms
authorvalentinewallace <valentinewallace@users.noreply.github.com>
Tue, 9 May 2023 12:50:28 +0000 (08:50 -0400)
committerGitHub <noreply@github.com>
Tue, 9 May 2023 12:50:28 +0000 (08:50 -0400)
Fix large onion message packet generation

50 files changed:
fuzz/src/bin/gen_target.sh
fuzz/src/bin/msg_accept_channel_v2_target.rs [new file with mode: 0644]
fuzz/src/bin/msg_open_channel_v2_target.rs [new file with mode: 0644]
fuzz/src/bin/msg_tx_abort_target.rs [new file with mode: 0644]
fuzz/src/bin/msg_tx_ack_rbf_target.rs [new file with mode: 0644]
fuzz/src/bin/msg_tx_add_input_target.rs [new file with mode: 0644]
fuzz/src/bin/msg_tx_add_output_target.rs [new file with mode: 0644]
fuzz/src/bin/msg_tx_complete_target.rs [new file with mode: 0644]
fuzz/src/bin/msg_tx_init_rbf_target.rs [new file with mode: 0644]
fuzz/src/bin/msg_tx_remove_input_target.rs [new file with mode: 0644]
fuzz/src/bin/msg_tx_remove_output_target.rs [new file with mode: 0644]
fuzz/src/bin/msg_tx_signatures_target.rs [new file with mode: 0644]
fuzz/src/msg_targets/gen_target.sh
fuzz/src/msg_targets/mod.rs
fuzz/src/msg_targets/msg_accept_channel_v2.rs [new file with mode: 0644]
fuzz/src/msg_targets/msg_channel_reestablish.rs
fuzz/src/msg_targets/msg_open_channel_v2.rs [new file with mode: 0644]
fuzz/src/msg_targets/msg_tx_abort.rs [new file with mode: 0644]
fuzz/src/msg_targets/msg_tx_ack_rbf.rs [new file with mode: 0644]
fuzz/src/msg_targets/msg_tx_add_input.rs [new file with mode: 0644]
fuzz/src/msg_targets/msg_tx_add_output.rs [new file with mode: 0644]
fuzz/src/msg_targets/msg_tx_complete.rs [new file with mode: 0644]
fuzz/src/msg_targets/msg_tx_init_rbf.rs [new file with mode: 0644]
fuzz/src/msg_targets/msg_tx_remove_input.rs [new file with mode: 0644]
fuzz/src/msg_targets/msg_tx_remove_output.rs [new file with mode: 0644]
fuzz/src/msg_targets/msg_tx_signatures.rs [new file with mode: 0644]
fuzz/src/router.rs
fuzz/targets.h
lightning-invoice/src/payment.rs
lightning-invoice/src/utils.rs
lightning-net-tokio/src/lib.rs
lightning/src/chain/channelmonitor.rs
lightning/src/events/mod.rs
lightning/src/ln/channel.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/features.rs
lightning/src/ln/functional_test_utils.rs
lightning/src/ln/functional_tests.rs
lightning/src/ln/msgs.rs
lightning/src/ln/onion_route_tests.rs
lightning/src/ln/outbound_payment.rs
lightning/src/ln/payment_tests.rs
lightning/src/ln/peer_handler.rs
lightning/src/ln/priv_short_conf_tests.rs
lightning/src/ln/shutdown_tests.rs
lightning/src/ln/wire.rs
lightning/src/routing/router.rs
lightning/src/util/ser.rs
lightning/src/util/test_utils.rs
pending_changelog/blinded_pay_param_compat.txt [new file with mode: 0644]

index d7928188d8c57d4cbc959943d40e89a3c1e2a6d6..34cae5107d34418b62c3a89e703bcfd896deb8be 100755 (executable)
@@ -56,3 +56,15 @@ GEN_TEST msg_ping msg_targets::
 GEN_TEST msg_pong msg_targets::
 
 GEN_TEST msg_channel_details msg_targets::
+
+GEN_TEST msg_open_channel_v2 msg_targets::
+GEN_TEST msg_accept_channel_v2 msg_targets::
+GEN_TEST msg_tx_add_input msg_targets::
+GEN_TEST msg_tx_add_output msg_targets::
+GEN_TEST msg_tx_remove_input msg_targets::
+GEN_TEST msg_tx_remove_output msg_targets::
+GEN_TEST msg_tx_complete msg_targets::
+GEN_TEST msg_tx_signatures msg_targets::
+GEN_TEST msg_tx_init_rbf msg_targets::
+GEN_TEST msg_tx_ack_rbf msg_targets::
+GEN_TEST msg_tx_abort msg_targets::
diff --git a/fuzz/src/bin/msg_accept_channel_v2_target.rs b/fuzz/src/bin/msg_accept_channel_v2_target.rs
new file mode 100644 (file)
index 0000000..354a5a8
--- /dev/null
@@ -0,0 +1,113 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+// This file is auto-generated by gen_target.sh based on target_template.txt
+// To modify it, modify target_template.txt and run gen_target.sh instead.
+
+#![cfg_attr(feature = "libfuzzer_fuzz", no_main)]
+
+#[cfg(not(fuzzing))]
+compile_error!("Fuzz targets need cfg=fuzzing");
+
+extern crate lightning_fuzz;
+use lightning_fuzz::msg_targets::msg_accept_channel_v2::*;
+
+#[cfg(feature = "afl")]
+#[macro_use] extern crate afl;
+#[cfg(feature = "afl")]
+fn main() {
+       fuzz!(|data| {
+               msg_accept_channel_v2_run(data.as_ptr(), data.len());
+       });
+}
+
+#[cfg(feature = "honggfuzz")]
+#[macro_use] extern crate honggfuzz;
+#[cfg(feature = "honggfuzz")]
+fn main() {
+       loop {
+               fuzz!(|data| {
+                       msg_accept_channel_v2_run(data.as_ptr(), data.len());
+               });
+       }
+}
+
+#[cfg(feature = "libfuzzer_fuzz")]
+#[macro_use] extern crate libfuzzer_sys;
+#[cfg(feature = "libfuzzer_fuzz")]
+fuzz_target!(|data: &[u8]| {
+       msg_accept_channel_v2_run(data.as_ptr(), data.len());
+});
+
+#[cfg(feature = "stdin_fuzz")]
+fn main() {
+       use std::io::Read;
+
+       let mut data = Vec::with_capacity(8192);
+       std::io::stdin().read_to_end(&mut data).unwrap();
+       msg_accept_channel_v2_run(data.as_ptr(), data.len());
+}
+
+#[test]
+fn run_test_cases() {
+       use std::fs;
+       use std::io::Read;
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_accept_channel_v2_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
+       if let Ok(tests) = fs::read_dir("test_cases/msg_accept_channel_v2") {
+               for test in tests {
+                       let mut data: Vec<u8> = Vec::new();
+                       let path = test.unwrap().path();
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_accept_channel_v2_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       let mut failed_outputs = Vec::new();
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("\nOutput of {}:\n{}\n", test, output);
+                       failed_outputs.push(test);
+               }
+       }
+       if !failed_outputs.is_empty() {
+               println!("Test cases which failed: ");
+               for case in failed_outputs {
+                       println!("{}", case);
+               }
+               panic!();
+       }
+}
diff --git a/fuzz/src/bin/msg_open_channel_v2_target.rs b/fuzz/src/bin/msg_open_channel_v2_target.rs
new file mode 100644 (file)
index 0000000..c7949bf
--- /dev/null
@@ -0,0 +1,113 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+// This file is auto-generated by gen_target.sh based on target_template.txt
+// To modify it, modify target_template.txt and run gen_target.sh instead.
+
+#![cfg_attr(feature = "libfuzzer_fuzz", no_main)]
+
+#[cfg(not(fuzzing))]
+compile_error!("Fuzz targets need cfg=fuzzing");
+
+extern crate lightning_fuzz;
+use lightning_fuzz::msg_targets::msg_open_channel_v2::*;
+
+#[cfg(feature = "afl")]
+#[macro_use] extern crate afl;
+#[cfg(feature = "afl")]
+fn main() {
+       fuzz!(|data| {
+               msg_open_channel_v2_run(data.as_ptr(), data.len());
+       });
+}
+
+#[cfg(feature = "honggfuzz")]
+#[macro_use] extern crate honggfuzz;
+#[cfg(feature = "honggfuzz")]
+fn main() {
+       loop {
+               fuzz!(|data| {
+                       msg_open_channel_v2_run(data.as_ptr(), data.len());
+               });
+       }
+}
+
+#[cfg(feature = "libfuzzer_fuzz")]
+#[macro_use] extern crate libfuzzer_sys;
+#[cfg(feature = "libfuzzer_fuzz")]
+fuzz_target!(|data: &[u8]| {
+       msg_open_channel_v2_run(data.as_ptr(), data.len());
+});
+
+#[cfg(feature = "stdin_fuzz")]
+fn main() {
+       use std::io::Read;
+
+       let mut data = Vec::with_capacity(8192);
+       std::io::stdin().read_to_end(&mut data).unwrap();
+       msg_open_channel_v2_run(data.as_ptr(), data.len());
+}
+
+#[test]
+fn run_test_cases() {
+       use std::fs;
+       use std::io::Read;
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_open_channel_v2_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
+       if let Ok(tests) = fs::read_dir("test_cases/msg_open_channel_v2") {
+               for test in tests {
+                       let mut data: Vec<u8> = Vec::new();
+                       let path = test.unwrap().path();
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_open_channel_v2_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       let mut failed_outputs = Vec::new();
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("\nOutput of {}:\n{}\n", test, output);
+                       failed_outputs.push(test);
+               }
+       }
+       if !failed_outputs.is_empty() {
+               println!("Test cases which failed: ");
+               for case in failed_outputs {
+                       println!("{}", case);
+               }
+               panic!();
+       }
+}
diff --git a/fuzz/src/bin/msg_tx_abort_target.rs b/fuzz/src/bin/msg_tx_abort_target.rs
new file mode 100644 (file)
index 0000000..6678356
--- /dev/null
@@ -0,0 +1,113 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+// This file is auto-generated by gen_target.sh based on target_template.txt
+// To modify it, modify target_template.txt and run gen_target.sh instead.
+
+#![cfg_attr(feature = "libfuzzer_fuzz", no_main)]
+
+#[cfg(not(fuzzing))]
+compile_error!("Fuzz targets need cfg=fuzzing");
+
+extern crate lightning_fuzz;
+use lightning_fuzz::msg_targets::msg_tx_abort::*;
+
+#[cfg(feature = "afl")]
+#[macro_use] extern crate afl;
+#[cfg(feature = "afl")]
+fn main() {
+       fuzz!(|data| {
+               msg_tx_abort_run(data.as_ptr(), data.len());
+       });
+}
+
+#[cfg(feature = "honggfuzz")]
+#[macro_use] extern crate honggfuzz;
+#[cfg(feature = "honggfuzz")]
+fn main() {
+       loop {
+               fuzz!(|data| {
+                       msg_tx_abort_run(data.as_ptr(), data.len());
+               });
+       }
+}
+
+#[cfg(feature = "libfuzzer_fuzz")]
+#[macro_use] extern crate libfuzzer_sys;
+#[cfg(feature = "libfuzzer_fuzz")]
+fuzz_target!(|data: &[u8]| {
+       msg_tx_abort_run(data.as_ptr(), data.len());
+});
+
+#[cfg(feature = "stdin_fuzz")]
+fn main() {
+       use std::io::Read;
+
+       let mut data = Vec::with_capacity(8192);
+       std::io::stdin().read_to_end(&mut data).unwrap();
+       msg_tx_abort_run(data.as_ptr(), data.len());
+}
+
+#[test]
+fn run_test_cases() {
+       use std::fs;
+       use std::io::Read;
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_tx_abort_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
+       if let Ok(tests) = fs::read_dir("test_cases/msg_tx_abort") {
+               for test in tests {
+                       let mut data: Vec<u8> = Vec::new();
+                       let path = test.unwrap().path();
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_tx_abort_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       let mut failed_outputs = Vec::new();
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("\nOutput of {}:\n{}\n", test, output);
+                       failed_outputs.push(test);
+               }
+       }
+       if !failed_outputs.is_empty() {
+               println!("Test cases which failed: ");
+               for case in failed_outputs {
+                       println!("{}", case);
+               }
+               panic!();
+       }
+}
diff --git a/fuzz/src/bin/msg_tx_ack_rbf_target.rs b/fuzz/src/bin/msg_tx_ack_rbf_target.rs
new file mode 100644 (file)
index 0000000..2e6aaed
--- /dev/null
@@ -0,0 +1,113 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+// This file is auto-generated by gen_target.sh based on target_template.txt
+// To modify it, modify target_template.txt and run gen_target.sh instead.
+
+#![cfg_attr(feature = "libfuzzer_fuzz", no_main)]
+
+#[cfg(not(fuzzing))]
+compile_error!("Fuzz targets need cfg=fuzzing");
+
+extern crate lightning_fuzz;
+use lightning_fuzz::msg_targets::msg_tx_ack_rbf::*;
+
+#[cfg(feature = "afl")]
+#[macro_use] extern crate afl;
+#[cfg(feature = "afl")]
+fn main() {
+       fuzz!(|data| {
+               msg_tx_ack_rbf_run(data.as_ptr(), data.len());
+       });
+}
+
+#[cfg(feature = "honggfuzz")]
+#[macro_use] extern crate honggfuzz;
+#[cfg(feature = "honggfuzz")]
+fn main() {
+       loop {
+               fuzz!(|data| {
+                       msg_tx_ack_rbf_run(data.as_ptr(), data.len());
+               });
+       }
+}
+
+#[cfg(feature = "libfuzzer_fuzz")]
+#[macro_use] extern crate libfuzzer_sys;
+#[cfg(feature = "libfuzzer_fuzz")]
+fuzz_target!(|data: &[u8]| {
+       msg_tx_ack_rbf_run(data.as_ptr(), data.len());
+});
+
+#[cfg(feature = "stdin_fuzz")]
+fn main() {
+       use std::io::Read;
+
+       let mut data = Vec::with_capacity(8192);
+       std::io::stdin().read_to_end(&mut data).unwrap();
+       msg_tx_ack_rbf_run(data.as_ptr(), data.len());
+}
+
+#[test]
+fn run_test_cases() {
+       use std::fs;
+       use std::io::Read;
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_tx_ack_rbf_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
+       if let Ok(tests) = fs::read_dir("test_cases/msg_tx_ack_rbf") {
+               for test in tests {
+                       let mut data: Vec<u8> = Vec::new();
+                       let path = test.unwrap().path();
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_tx_ack_rbf_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       let mut failed_outputs = Vec::new();
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("\nOutput of {}:\n{}\n", test, output);
+                       failed_outputs.push(test);
+               }
+       }
+       if !failed_outputs.is_empty() {
+               println!("Test cases which failed: ");
+               for case in failed_outputs {
+                       println!("{}", case);
+               }
+               panic!();
+       }
+}
diff --git a/fuzz/src/bin/msg_tx_add_input_target.rs b/fuzz/src/bin/msg_tx_add_input_target.rs
new file mode 100644 (file)
index 0000000..1da8bbd
--- /dev/null
@@ -0,0 +1,113 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+// This file is auto-generated by gen_target.sh based on target_template.txt
+// To modify it, modify target_template.txt and run gen_target.sh instead.
+
+#![cfg_attr(feature = "libfuzzer_fuzz", no_main)]
+
+#[cfg(not(fuzzing))]
+compile_error!("Fuzz targets need cfg=fuzzing");
+
+extern crate lightning_fuzz;
+use lightning_fuzz::msg_targets::msg_tx_add_input::*;
+
+#[cfg(feature = "afl")]
+#[macro_use] extern crate afl;
+#[cfg(feature = "afl")]
+fn main() {
+       fuzz!(|data| {
+               msg_tx_add_input_run(data.as_ptr(), data.len());
+       });
+}
+
+#[cfg(feature = "honggfuzz")]
+#[macro_use] extern crate honggfuzz;
+#[cfg(feature = "honggfuzz")]
+fn main() {
+       loop {
+               fuzz!(|data| {
+                       msg_tx_add_input_run(data.as_ptr(), data.len());
+               });
+       }
+}
+
+#[cfg(feature = "libfuzzer_fuzz")]
+#[macro_use] extern crate libfuzzer_sys;
+#[cfg(feature = "libfuzzer_fuzz")]
+fuzz_target!(|data: &[u8]| {
+       msg_tx_add_input_run(data.as_ptr(), data.len());
+});
+
+#[cfg(feature = "stdin_fuzz")]
+fn main() {
+       use std::io::Read;
+
+       let mut data = Vec::with_capacity(8192);
+       std::io::stdin().read_to_end(&mut data).unwrap();
+       msg_tx_add_input_run(data.as_ptr(), data.len());
+}
+
+#[test]
+fn run_test_cases() {
+       use std::fs;
+       use std::io::Read;
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_tx_add_input_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
+       if let Ok(tests) = fs::read_dir("test_cases/msg_tx_add_input") {
+               for test in tests {
+                       let mut data: Vec<u8> = Vec::new();
+                       let path = test.unwrap().path();
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_tx_add_input_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       let mut failed_outputs = Vec::new();
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("\nOutput of {}:\n{}\n", test, output);
+                       failed_outputs.push(test);
+               }
+       }
+       if !failed_outputs.is_empty() {
+               println!("Test cases which failed: ");
+               for case in failed_outputs {
+                       println!("{}", case);
+               }
+               panic!();
+       }
+}
diff --git a/fuzz/src/bin/msg_tx_add_output_target.rs b/fuzz/src/bin/msg_tx_add_output_target.rs
new file mode 100644 (file)
index 0000000..a06d51a
--- /dev/null
@@ -0,0 +1,113 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+// This file is auto-generated by gen_target.sh based on target_template.txt
+// To modify it, modify target_template.txt and run gen_target.sh instead.
+
+#![cfg_attr(feature = "libfuzzer_fuzz", no_main)]
+
+#[cfg(not(fuzzing))]
+compile_error!("Fuzz targets need cfg=fuzzing");
+
+extern crate lightning_fuzz;
+use lightning_fuzz::msg_targets::msg_tx_add_output::*;
+
+#[cfg(feature = "afl")]
+#[macro_use] extern crate afl;
+#[cfg(feature = "afl")]
+fn main() {
+       fuzz!(|data| {
+               msg_tx_add_output_run(data.as_ptr(), data.len());
+       });
+}
+
+#[cfg(feature = "honggfuzz")]
+#[macro_use] extern crate honggfuzz;
+#[cfg(feature = "honggfuzz")]
+fn main() {
+       loop {
+               fuzz!(|data| {
+                       msg_tx_add_output_run(data.as_ptr(), data.len());
+               });
+       }
+}
+
+#[cfg(feature = "libfuzzer_fuzz")]
+#[macro_use] extern crate libfuzzer_sys;
+#[cfg(feature = "libfuzzer_fuzz")]
+fuzz_target!(|data: &[u8]| {
+       msg_tx_add_output_run(data.as_ptr(), data.len());
+});
+
+#[cfg(feature = "stdin_fuzz")]
+fn main() {
+       use std::io::Read;
+
+       let mut data = Vec::with_capacity(8192);
+       std::io::stdin().read_to_end(&mut data).unwrap();
+       msg_tx_add_output_run(data.as_ptr(), data.len());
+}
+
+#[test]
+fn run_test_cases() {
+       use std::fs;
+       use std::io::Read;
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_tx_add_output_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
+       if let Ok(tests) = fs::read_dir("test_cases/msg_tx_add_output") {
+               for test in tests {
+                       let mut data: Vec<u8> = Vec::new();
+                       let path = test.unwrap().path();
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_tx_add_output_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       let mut failed_outputs = Vec::new();
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("\nOutput of {}:\n{}\n", test, output);
+                       failed_outputs.push(test);
+               }
+       }
+       if !failed_outputs.is_empty() {
+               println!("Test cases which failed: ");
+               for case in failed_outputs {
+                       println!("{}", case);
+               }
+               panic!();
+       }
+}
diff --git a/fuzz/src/bin/msg_tx_complete_target.rs b/fuzz/src/bin/msg_tx_complete_target.rs
new file mode 100644 (file)
index 0000000..5bb2f85
--- /dev/null
@@ -0,0 +1,113 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+// This file is auto-generated by gen_target.sh based on target_template.txt
+// To modify it, modify target_template.txt and run gen_target.sh instead.
+
+#![cfg_attr(feature = "libfuzzer_fuzz", no_main)]
+
+#[cfg(not(fuzzing))]
+compile_error!("Fuzz targets need cfg=fuzzing");
+
+extern crate lightning_fuzz;
+use lightning_fuzz::msg_targets::msg_tx_complete::*;
+
+#[cfg(feature = "afl")]
+#[macro_use] extern crate afl;
+#[cfg(feature = "afl")]
+fn main() {
+       fuzz!(|data| {
+               msg_tx_complete_run(data.as_ptr(), data.len());
+       });
+}
+
+#[cfg(feature = "honggfuzz")]
+#[macro_use] extern crate honggfuzz;
+#[cfg(feature = "honggfuzz")]
+fn main() {
+       loop {
+               fuzz!(|data| {
+                       msg_tx_complete_run(data.as_ptr(), data.len());
+               });
+       }
+}
+
+#[cfg(feature = "libfuzzer_fuzz")]
+#[macro_use] extern crate libfuzzer_sys;
+#[cfg(feature = "libfuzzer_fuzz")]
+fuzz_target!(|data: &[u8]| {
+       msg_tx_complete_run(data.as_ptr(), data.len());
+});
+
+#[cfg(feature = "stdin_fuzz")]
+fn main() {
+       use std::io::Read;
+
+       let mut data = Vec::with_capacity(8192);
+       std::io::stdin().read_to_end(&mut data).unwrap();
+       msg_tx_complete_run(data.as_ptr(), data.len());
+}
+
+#[test]
+fn run_test_cases() {
+       use std::fs;
+       use std::io::Read;
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_tx_complete_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
+       if let Ok(tests) = fs::read_dir("test_cases/msg_tx_complete") {
+               for test in tests {
+                       let mut data: Vec<u8> = Vec::new();
+                       let path = test.unwrap().path();
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_tx_complete_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       let mut failed_outputs = Vec::new();
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("\nOutput of {}:\n{}\n", test, output);
+                       failed_outputs.push(test);
+               }
+       }
+       if !failed_outputs.is_empty() {
+               println!("Test cases which failed: ");
+               for case in failed_outputs {
+                       println!("{}", case);
+               }
+               panic!();
+       }
+}
diff --git a/fuzz/src/bin/msg_tx_init_rbf_target.rs b/fuzz/src/bin/msg_tx_init_rbf_target.rs
new file mode 100644 (file)
index 0000000..74556ab
--- /dev/null
@@ -0,0 +1,113 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+// This file is auto-generated by gen_target.sh based on target_template.txt
+// To modify it, modify target_template.txt and run gen_target.sh instead.
+
+#![cfg_attr(feature = "libfuzzer_fuzz", no_main)]
+
+#[cfg(not(fuzzing))]
+compile_error!("Fuzz targets need cfg=fuzzing");
+
+extern crate lightning_fuzz;
+use lightning_fuzz::msg_targets::msg_tx_init_rbf::*;
+
+#[cfg(feature = "afl")]
+#[macro_use] extern crate afl;
+#[cfg(feature = "afl")]
+fn main() {
+       fuzz!(|data| {
+               msg_tx_init_rbf_run(data.as_ptr(), data.len());
+       });
+}
+
+#[cfg(feature = "honggfuzz")]
+#[macro_use] extern crate honggfuzz;
+#[cfg(feature = "honggfuzz")]
+fn main() {
+       loop {
+               fuzz!(|data| {
+                       msg_tx_init_rbf_run(data.as_ptr(), data.len());
+               });
+       }
+}
+
+#[cfg(feature = "libfuzzer_fuzz")]
+#[macro_use] extern crate libfuzzer_sys;
+#[cfg(feature = "libfuzzer_fuzz")]
+fuzz_target!(|data: &[u8]| {
+       msg_tx_init_rbf_run(data.as_ptr(), data.len());
+});
+
+#[cfg(feature = "stdin_fuzz")]
+fn main() {
+       use std::io::Read;
+
+       let mut data = Vec::with_capacity(8192);
+       std::io::stdin().read_to_end(&mut data).unwrap();
+       msg_tx_init_rbf_run(data.as_ptr(), data.len());
+}
+
+#[test]
+fn run_test_cases() {
+       use std::fs;
+       use std::io::Read;
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_tx_init_rbf_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
+       if let Ok(tests) = fs::read_dir("test_cases/msg_tx_init_rbf") {
+               for test in tests {
+                       let mut data: Vec<u8> = Vec::new();
+                       let path = test.unwrap().path();
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_tx_init_rbf_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       let mut failed_outputs = Vec::new();
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("\nOutput of {}:\n{}\n", test, output);
+                       failed_outputs.push(test);
+               }
+       }
+       if !failed_outputs.is_empty() {
+               println!("Test cases which failed: ");
+               for case in failed_outputs {
+                       println!("{}", case);
+               }
+               panic!();
+       }
+}
diff --git a/fuzz/src/bin/msg_tx_remove_input_target.rs b/fuzz/src/bin/msg_tx_remove_input_target.rs
new file mode 100644 (file)
index 0000000..d6b9cff
--- /dev/null
@@ -0,0 +1,113 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+// This file is auto-generated by gen_target.sh based on target_template.txt
+// To modify it, modify target_template.txt and run gen_target.sh instead.
+
+#![cfg_attr(feature = "libfuzzer_fuzz", no_main)]
+
+#[cfg(not(fuzzing))]
+compile_error!("Fuzz targets need cfg=fuzzing");
+
+extern crate lightning_fuzz;
+use lightning_fuzz::msg_targets::msg_tx_remove_input::*;
+
+#[cfg(feature = "afl")]
+#[macro_use] extern crate afl;
+#[cfg(feature = "afl")]
+fn main() {
+       fuzz!(|data| {
+               msg_tx_remove_input_run(data.as_ptr(), data.len());
+       });
+}
+
+#[cfg(feature = "honggfuzz")]
+#[macro_use] extern crate honggfuzz;
+#[cfg(feature = "honggfuzz")]
+fn main() {
+       loop {
+               fuzz!(|data| {
+                       msg_tx_remove_input_run(data.as_ptr(), data.len());
+               });
+       }
+}
+
+#[cfg(feature = "libfuzzer_fuzz")]
+#[macro_use] extern crate libfuzzer_sys;
+#[cfg(feature = "libfuzzer_fuzz")]
+fuzz_target!(|data: &[u8]| {
+       msg_tx_remove_input_run(data.as_ptr(), data.len());
+});
+
+#[cfg(feature = "stdin_fuzz")]
+fn main() {
+       use std::io::Read;
+
+       let mut data = Vec::with_capacity(8192);
+       std::io::stdin().read_to_end(&mut data).unwrap();
+       msg_tx_remove_input_run(data.as_ptr(), data.len());
+}
+
+#[test]
+fn run_test_cases() {
+       use std::fs;
+       use std::io::Read;
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_tx_remove_input_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
+       if let Ok(tests) = fs::read_dir("test_cases/msg_tx_remove_input") {
+               for test in tests {
+                       let mut data: Vec<u8> = Vec::new();
+                       let path = test.unwrap().path();
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_tx_remove_input_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       let mut failed_outputs = Vec::new();
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("\nOutput of {}:\n{}\n", test, output);
+                       failed_outputs.push(test);
+               }
+       }
+       if !failed_outputs.is_empty() {
+               println!("Test cases which failed: ");
+               for case in failed_outputs {
+                       println!("{}", case);
+               }
+               panic!();
+       }
+}
diff --git a/fuzz/src/bin/msg_tx_remove_output_target.rs b/fuzz/src/bin/msg_tx_remove_output_target.rs
new file mode 100644 (file)
index 0000000..2c6b17d
--- /dev/null
@@ -0,0 +1,113 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+// This file is auto-generated by gen_target.sh based on target_template.txt
+// To modify it, modify target_template.txt and run gen_target.sh instead.
+
+#![cfg_attr(feature = "libfuzzer_fuzz", no_main)]
+
+#[cfg(not(fuzzing))]
+compile_error!("Fuzz targets need cfg=fuzzing");
+
+extern crate lightning_fuzz;
+use lightning_fuzz::msg_targets::msg_tx_remove_output::*;
+
+#[cfg(feature = "afl")]
+#[macro_use] extern crate afl;
+#[cfg(feature = "afl")]
+fn main() {
+       fuzz!(|data| {
+               msg_tx_remove_output_run(data.as_ptr(), data.len());
+       });
+}
+
+#[cfg(feature = "honggfuzz")]
+#[macro_use] extern crate honggfuzz;
+#[cfg(feature = "honggfuzz")]
+fn main() {
+       loop {
+               fuzz!(|data| {
+                       msg_tx_remove_output_run(data.as_ptr(), data.len());
+               });
+       }
+}
+
+#[cfg(feature = "libfuzzer_fuzz")]
+#[macro_use] extern crate libfuzzer_sys;
+#[cfg(feature = "libfuzzer_fuzz")]
+fuzz_target!(|data: &[u8]| {
+       msg_tx_remove_output_run(data.as_ptr(), data.len());
+});
+
+#[cfg(feature = "stdin_fuzz")]
+fn main() {
+       use std::io::Read;
+
+       let mut data = Vec::with_capacity(8192);
+       std::io::stdin().read_to_end(&mut data).unwrap();
+       msg_tx_remove_output_run(data.as_ptr(), data.len());
+}
+
+#[test]
+fn run_test_cases() {
+       use std::fs;
+       use std::io::Read;
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_tx_remove_output_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
+       if let Ok(tests) = fs::read_dir("test_cases/msg_tx_remove_output") {
+               for test in tests {
+                       let mut data: Vec<u8> = Vec::new();
+                       let path = test.unwrap().path();
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_tx_remove_output_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       let mut failed_outputs = Vec::new();
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("\nOutput of {}:\n{}\n", test, output);
+                       failed_outputs.push(test);
+               }
+       }
+       if !failed_outputs.is_empty() {
+               println!("Test cases which failed: ");
+               for case in failed_outputs {
+                       println!("{}", case);
+               }
+               panic!();
+       }
+}
diff --git a/fuzz/src/bin/msg_tx_signatures_target.rs b/fuzz/src/bin/msg_tx_signatures_target.rs
new file mode 100644 (file)
index 0000000..ee650ec
--- /dev/null
@@ -0,0 +1,113 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+// This file is auto-generated by gen_target.sh based on target_template.txt
+// To modify it, modify target_template.txt and run gen_target.sh instead.
+
+#![cfg_attr(feature = "libfuzzer_fuzz", no_main)]
+
+#[cfg(not(fuzzing))]
+compile_error!("Fuzz targets need cfg=fuzzing");
+
+extern crate lightning_fuzz;
+use lightning_fuzz::msg_targets::msg_tx_signatures::*;
+
+#[cfg(feature = "afl")]
+#[macro_use] extern crate afl;
+#[cfg(feature = "afl")]
+fn main() {
+       fuzz!(|data| {
+               msg_tx_signatures_run(data.as_ptr(), data.len());
+       });
+}
+
+#[cfg(feature = "honggfuzz")]
+#[macro_use] extern crate honggfuzz;
+#[cfg(feature = "honggfuzz")]
+fn main() {
+       loop {
+               fuzz!(|data| {
+                       msg_tx_signatures_run(data.as_ptr(), data.len());
+               });
+       }
+}
+
+#[cfg(feature = "libfuzzer_fuzz")]
+#[macro_use] extern crate libfuzzer_sys;
+#[cfg(feature = "libfuzzer_fuzz")]
+fuzz_target!(|data: &[u8]| {
+       msg_tx_signatures_run(data.as_ptr(), data.len());
+});
+
+#[cfg(feature = "stdin_fuzz")]
+fn main() {
+       use std::io::Read;
+
+       let mut data = Vec::with_capacity(8192);
+       std::io::stdin().read_to_end(&mut data).unwrap();
+       msg_tx_signatures_run(data.as_ptr(), data.len());
+}
+
+#[test]
+fn run_test_cases() {
+       use std::fs;
+       use std::io::Read;
+       use lightning_fuzz::utils::test_logger::StringBuffer;
+
+       use std::sync::{atomic, Arc};
+       {
+               let data: Vec<u8> = vec![0];
+               msg_tx_signatures_run(data.as_ptr(), data.len());
+       }
+       let mut threads = Vec::new();
+       let threads_running = Arc::new(atomic::AtomicUsize::new(0));
+       if let Ok(tests) = fs::read_dir("test_cases/msg_tx_signatures") {
+               for test in tests {
+                       let mut data: Vec<u8> = Vec::new();
+                       let path = test.unwrap().path();
+                       fs::File::open(&path).unwrap().read_to_end(&mut data).unwrap();
+                       threads_running.fetch_add(1, atomic::Ordering::AcqRel);
+
+                       let thread_count_ref = Arc::clone(&threads_running);
+                       let main_thread_ref = std::thread::current();
+                       threads.push((path.file_name().unwrap().to_str().unwrap().to_string(),
+                               std::thread::spawn(move || {
+                                       let string_logger = StringBuffer::new();
+
+                                       let panic_logger = string_logger.clone();
+                                       let res = if ::std::panic::catch_unwind(move || {
+                                               msg_tx_signatures_test(&data, panic_logger);
+                                       }).is_err() {
+                                               Some(string_logger.into_string())
+                                       } else { None };
+                                       thread_count_ref.fetch_sub(1, atomic::Ordering::AcqRel);
+                                       main_thread_ref.unpark();
+                                       res
+                               })
+                       ));
+                       while threads_running.load(atomic::Ordering::Acquire) > 32 {
+                               std::thread::park();
+                       }
+               }
+       }
+       let mut failed_outputs = Vec::new();
+       for (test, thread) in threads.drain(..) {
+               if let Some(output) = thread.join().unwrap() {
+                       println!("\nOutput of {}:\n{}\n", test, output);
+                       failed_outputs.push(test);
+               }
+       }
+       if !failed_outputs.is_empty() {
+               println!("Test cases which failed: ");
+               for case in failed_outputs {
+                       println!("{}", case);
+               }
+               panic!();
+       }
+}
index 753a98325a4c37713ee8ecaa837dfb85d30869d4..3937c5001eaba1d127a213b7002b122d9b76301a 100755 (executable)
@@ -33,8 +33,8 @@ GEN_TEST lightning::ln::msgs::UpdateFailHTLC test_msg_simple ""
 GEN_TEST lightning::ln::msgs::UpdateFailMalformedHTLC test_msg_simple ""
 GEN_TEST lightning::ln::msgs::UpdateFee test_msg_simple ""
 GEN_TEST lightning::ln::msgs::UpdateFulfillHTLC test_msg_simple ""
+GEN_TEST lightning::ln::msgs::ChannelReestablish test_msg_simple ""
 
-GEN_TEST lightning::ln::msgs::ChannelReestablish test_msg ""
 GEN_TEST lightning::ln::msgs::DecodedOnionErrorPacket test_msg ""
 
 GEN_TEST lightning::ln::msgs::ChannelAnnouncement test_msg_exact ""
@@ -47,3 +47,15 @@ GEN_TEST lightning::ln::msgs::WarningMessage test_msg_hole ", 32, 2"
 GEN_TEST lightning::ln::msgs::ChannelUpdate test_msg_hole ", 108, 1"
 
 GEN_TEST lightning::ln::channelmanager::ChannelDetails test_msg_simple ""
+
+GEN_TEST lightning::ln::msgs::OpenChannelV2 test_msg_simple ""
+GEN_TEST lightning::ln::msgs::AcceptChannelV2 test_msg_simple ""
+GEN_TEST lightning::ln::msgs::TxAddInput test_msg_simple ""
+GEN_TEST lightning::ln::msgs::TxAddOutput test_msg_simple ""
+GEN_TEST lightning::ln::msgs::TxRemoveInput test_msg_simple ""
+GEN_TEST lightning::ln::msgs::TxRemoveOutput test_msg_simple ""
+GEN_TEST lightning::ln::msgs::TxComplete test_msg_simple ""
+GEN_TEST lightning::ln::msgs::TxSignatures test_msg_simple ""
+GEN_TEST lightning::ln::msgs::TxInitRbf test_msg_simple ""
+GEN_TEST lightning::ln::msgs::TxAckRbf test_msg_simple ""
+GEN_TEST lightning::ln::msgs::TxAbort test_msg_simple ""
index 67d66e23f5da8635a9c3d8e78e11358b71563a7f..fe3bd14a7c9e25e4645f0c069d5d07a9ac3e0627 100644 (file)
@@ -31,3 +31,14 @@ pub mod msg_error_message;
 pub mod msg_warning_message;
 pub mod msg_channel_update;
 pub mod msg_channel_details;
+pub mod msg_open_channel_v2;
+pub mod msg_accept_channel_v2;
+pub mod msg_tx_add_input;
+pub mod msg_tx_add_output;
+pub mod msg_tx_remove_input;
+pub mod msg_tx_remove_output;
+pub mod msg_tx_complete;
+pub mod msg_tx_signatures;
+pub mod msg_tx_init_rbf;
+pub mod msg_tx_ack_rbf;
+pub mod msg_tx_abort;
diff --git a/fuzz/src/msg_targets/msg_accept_channel_v2.rs b/fuzz/src/msg_targets/msg_accept_channel_v2.rs
new file mode 100644 (file)
index 0000000..36b6466
--- /dev/null
@@ -0,0 +1,25 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+// This file is auto-generated by gen_target.sh based on msg_target_template.txt
+// To modify it, modify msg_target_template.txt and run gen_target.sh instead.
+
+use crate::msg_targets::utils::VecWriter;
+use crate::utils::test_logger;
+
+#[inline]
+pub fn msg_accept_channel_v2_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
+       test_msg_simple!(lightning::ln::msgs::AcceptChannelV2, data);
+}
+
+#[no_mangle]
+pub extern "C" fn msg_accept_channel_v2_run(data: *const u8, datalen: usize) {
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg_simple!(lightning::ln::msgs::AcceptChannelV2, data);
+}
index 0857555805ac406f70994e3086fe08de6d2c82c6..fdc2d1fa62b217049218ed0ff0fcf69b70a87fcf 100644 (file)
@@ -15,11 +15,11 @@ use crate::utils::test_logger;
 
 #[inline]
 pub fn msg_channel_reestablish_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
-       test_msg!(lightning::ln::msgs::ChannelReestablish, data);
+       test_msg_simple!(lightning::ln::msgs::ChannelReestablish, data);
 }
 
 #[no_mangle]
 pub extern "C" fn msg_channel_reestablish_run(data: *const u8, datalen: usize) {
        let data = unsafe { std::slice::from_raw_parts(data, datalen) };
-       test_msg!(lightning::ln::msgs::ChannelReestablish, data);
+       test_msg_simple!(lightning::ln::msgs::ChannelReestablish, data);
 }
diff --git a/fuzz/src/msg_targets/msg_open_channel_v2.rs b/fuzz/src/msg_targets/msg_open_channel_v2.rs
new file mode 100644 (file)
index 0000000..4f6457a
--- /dev/null
@@ -0,0 +1,25 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+// This file is auto-generated by gen_target.sh based on msg_target_template.txt
+// To modify it, modify msg_target_template.txt and run gen_target.sh instead.
+
+use crate::msg_targets::utils::VecWriter;
+use crate::utils::test_logger;
+
+#[inline]
+pub fn msg_open_channel_v2_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
+       test_msg_simple!(lightning::ln::msgs::OpenChannelV2, data);
+}
+
+#[no_mangle]
+pub extern "C" fn msg_open_channel_v2_run(data: *const u8, datalen: usize) {
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg_simple!(lightning::ln::msgs::OpenChannelV2, data);
+}
diff --git a/fuzz/src/msg_targets/msg_tx_abort.rs b/fuzz/src/msg_targets/msg_tx_abort.rs
new file mode 100644 (file)
index 0000000..c361b65
--- /dev/null
@@ -0,0 +1,25 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+// This file is auto-generated by gen_target.sh based on msg_target_template.txt
+// To modify it, modify msg_target_template.txt and run gen_target.sh instead.
+
+use crate::msg_targets::utils::VecWriter;
+use crate::utils::test_logger;
+
+#[inline]
+pub fn msg_tx_abort_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
+       test_msg_simple!(lightning::ln::msgs::TxAbort, data);
+}
+
+#[no_mangle]
+pub extern "C" fn msg_tx_abort_run(data: *const u8, datalen: usize) {
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg_simple!(lightning::ln::msgs::TxAbort, data);
+}
diff --git a/fuzz/src/msg_targets/msg_tx_ack_rbf.rs b/fuzz/src/msg_targets/msg_tx_ack_rbf.rs
new file mode 100644 (file)
index 0000000..9931bfc
--- /dev/null
@@ -0,0 +1,25 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+// This file is auto-generated by gen_target.sh based on msg_target_template.txt
+// To modify it, modify msg_target_template.txt and run gen_target.sh instead.
+
+use crate::msg_targets::utils::VecWriter;
+use crate::utils::test_logger;
+
+#[inline]
+pub fn msg_tx_ack_rbf_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
+       test_msg_simple!(lightning::ln::msgs::TxAckRbf, data);
+}
+
+#[no_mangle]
+pub extern "C" fn msg_tx_ack_rbf_run(data: *const u8, datalen: usize) {
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg_simple!(lightning::ln::msgs::TxAckRbf, data);
+}
diff --git a/fuzz/src/msg_targets/msg_tx_add_input.rs b/fuzz/src/msg_targets/msg_tx_add_input.rs
new file mode 100644 (file)
index 0000000..f212b59
--- /dev/null
@@ -0,0 +1,25 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+// This file is auto-generated by gen_target.sh based on msg_target_template.txt
+// To modify it, modify msg_target_template.txt and run gen_target.sh instead.
+
+use crate::msg_targets::utils::VecWriter;
+use crate::utils::test_logger;
+
+#[inline]
+pub fn msg_tx_add_input_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
+       test_msg_simple!(lightning::ln::msgs::TxAddInput, data);
+}
+
+#[no_mangle]
+pub extern "C" fn msg_tx_add_input_run(data: *const u8, datalen: usize) {
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg_simple!(lightning::ln::msgs::TxAddInput, data);
+}
diff --git a/fuzz/src/msg_targets/msg_tx_add_output.rs b/fuzz/src/msg_targets/msg_tx_add_output.rs
new file mode 100644 (file)
index 0000000..49b2321
--- /dev/null
@@ -0,0 +1,25 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+// This file is auto-generated by gen_target.sh based on msg_target_template.txt
+// To modify it, modify msg_target_template.txt and run gen_target.sh instead.
+
+use crate::msg_targets::utils::VecWriter;
+use crate::utils::test_logger;
+
+#[inline]
+pub fn msg_tx_add_output_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
+       test_msg_simple!(lightning::ln::msgs::TxAddOutput, data);
+}
+
+#[no_mangle]
+pub extern "C" fn msg_tx_add_output_run(data: *const u8, datalen: usize) {
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg_simple!(lightning::ln::msgs::TxAddOutput, data);
+}
diff --git a/fuzz/src/msg_targets/msg_tx_complete.rs b/fuzz/src/msg_targets/msg_tx_complete.rs
new file mode 100644 (file)
index 0000000..c4227b1
--- /dev/null
@@ -0,0 +1,25 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+// This file is auto-generated by gen_target.sh based on msg_target_template.txt
+// To modify it, modify msg_target_template.txt and run gen_target.sh instead.
+
+use crate::msg_targets::utils::VecWriter;
+use crate::utils::test_logger;
+
+#[inline]
+pub fn msg_tx_complete_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
+       test_msg_simple!(lightning::ln::msgs::TxComplete, data);
+}
+
+#[no_mangle]
+pub extern "C" fn msg_tx_complete_run(data: *const u8, datalen: usize) {
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg_simple!(lightning::ln::msgs::TxComplete, data);
+}
diff --git a/fuzz/src/msg_targets/msg_tx_init_rbf.rs b/fuzz/src/msg_targets/msg_tx_init_rbf.rs
new file mode 100644 (file)
index 0000000..ea021dc
--- /dev/null
@@ -0,0 +1,25 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+// This file is auto-generated by gen_target.sh based on msg_target_template.txt
+// To modify it, modify msg_target_template.txt and run gen_target.sh instead.
+
+use crate::msg_targets::utils::VecWriter;
+use crate::utils::test_logger;
+
+#[inline]
+pub fn msg_tx_init_rbf_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
+       test_msg_simple!(lightning::ln::msgs::TxInitRbf, data);
+}
+
+#[no_mangle]
+pub extern "C" fn msg_tx_init_rbf_run(data: *const u8, datalen: usize) {
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg_simple!(lightning::ln::msgs::TxInitRbf, data);
+}
diff --git a/fuzz/src/msg_targets/msg_tx_remove_input.rs b/fuzz/src/msg_targets/msg_tx_remove_input.rs
new file mode 100644 (file)
index 0000000..fe69ad4
--- /dev/null
@@ -0,0 +1,25 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+// This file is auto-generated by gen_target.sh based on msg_target_template.txt
+// To modify it, modify msg_target_template.txt and run gen_target.sh instead.
+
+use crate::msg_targets::utils::VecWriter;
+use crate::utils::test_logger;
+
+#[inline]
+pub fn msg_tx_remove_input_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
+       test_msg_simple!(lightning::ln::msgs::TxRemoveInput, data);
+}
+
+#[no_mangle]
+pub extern "C" fn msg_tx_remove_input_run(data: *const u8, datalen: usize) {
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg_simple!(lightning::ln::msgs::TxRemoveInput, data);
+}
diff --git a/fuzz/src/msg_targets/msg_tx_remove_output.rs b/fuzz/src/msg_targets/msg_tx_remove_output.rs
new file mode 100644 (file)
index 0000000..6c09d4d
--- /dev/null
@@ -0,0 +1,25 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+// This file is auto-generated by gen_target.sh based on msg_target_template.txt
+// To modify it, modify msg_target_template.txt and run gen_target.sh instead.
+
+use crate::msg_targets::utils::VecWriter;
+use crate::utils::test_logger;
+
+#[inline]
+pub fn msg_tx_remove_output_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
+       test_msg_simple!(lightning::ln::msgs::TxRemoveOutput, data);
+}
+
+#[no_mangle]
+pub extern "C" fn msg_tx_remove_output_run(data: *const u8, datalen: usize) {
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg_simple!(lightning::ln::msgs::TxRemoveOutput, data);
+}
diff --git a/fuzz/src/msg_targets/msg_tx_signatures.rs b/fuzz/src/msg_targets/msg_tx_signatures.rs
new file mode 100644 (file)
index 0000000..54392d4
--- /dev/null
@@ -0,0 +1,25 @@
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+// This file is auto-generated by gen_target.sh based on msg_target_template.txt
+// To modify it, modify msg_target_template.txt and run gen_target.sh instead.
+
+use crate::msg_targets::utils::VecWriter;
+use crate::utils::test_logger;
+
+#[inline]
+pub fn msg_tx_signatures_test<Out: test_logger::Output>(data: &[u8], _out: Out) {
+       test_msg_simple!(lightning::ln::msgs::TxSignatures, data);
+}
+
+#[no_mangle]
+pub extern "C" fn msg_tx_signatures_run(data: *const u8, datalen: usize) {
+       let data = unsafe { std::slice::from_raw_parts(data, datalen) };
+       test_msg_simple!(lightning::ln::msgs::TxSignatures, data);
+}
index fe6f1647f4d20c182558938b2ce475d6b7d1037b..7c09c860025f8ce084cafd854a05cf9569384335 100644 (file)
@@ -300,7 +300,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
                                        let final_cltv_expiry_delta = slice_to_be32(get_slice!(4));
                                        let route_params = RouteParameters {
                                                payment_params: PaymentParameters::from_node_id(*target, final_cltv_expiry_delta)
-                                                       .with_route_hints(last_hops.clone()),
+                                                       .with_route_hints(last_hops.clone()).unwrap(),
                                                final_value_msat,
                                        };
                                        let _ = find_route(&our_pubkey, &route_params, &net_graph,
index 8f846c5e037e0e53edc9924f5643a7ebce94fb1f..eb8d66f412a5b62c9126979cf03bef0eea589d87 100644 (file)
@@ -44,3 +44,14 @@ void msg_onion_hop_data_run(const unsigned char* data, size_t data_len);
 void msg_ping_run(const unsigned char* data, size_t data_len);
 void msg_pong_run(const unsigned char* data, size_t data_len);
 void msg_channel_details_run(const unsigned char* data, size_t data_len);
+void msg_open_channel_v2_run(const unsigned char* data, size_t data_len);
+void msg_accept_channel_v2_run(const unsigned char* data, size_t data_len);
+void msg_tx_add_input_run(const unsigned char* data, size_t data_len);
+void msg_tx_add_output_run(const unsigned char* data, size_t data_len);
+void msg_tx_remove_input_run(const unsigned char* data, size_t data_len);
+void msg_tx_remove_output_run(const unsigned char* data, size_t data_len);
+void msg_tx_complete_run(const unsigned char* data, size_t data_len);
+void msg_tx_signatures_run(const unsigned char* data, size_t data_len);
+void msg_tx_init_rbf_run(const unsigned char* data, size_t data_len);
+void msg_tx_ack_rbf_run(const unsigned char* data, size_t data_len);
+void msg_tx_abort_run(const unsigned char* data, size_t data_len);
index a67510f61f0ac23d1be1039b695608d9101be575..c08a00a0ca23ec18f31fcfbbe1afca9aff6ba57e 100644 (file)
@@ -152,9 +152,9 @@ fn pay_invoice_using_amount<P: Deref>(
        let mut payment_params = PaymentParameters::from_node_id(invoice.recover_payee_pub_key(),
                invoice.min_final_cltv_expiry_delta() as u32)
                .with_expiry_time(expiry_time_from_unix_epoch(invoice).as_secs())
-               .with_route_hints(invoice.route_hints());
+               .with_route_hints(invoice.route_hints()).unwrap();
        if let Some(features) = invoice.features() {
-               payment_params = payment_params.with_features(features.clone());
+               payment_params = payment_params.with_bolt11_features(features.clone()).unwrap();
        }
        let route_params = RouteParameters {
                payment_params,
index fac9989497b6cfc8e78b10398599ca19e1136f77..b3b7c2b91e8b2702ed5ad693cc8971143b625292 100644 (file)
@@ -838,8 +838,8 @@ mod test {
 
                let payment_params = PaymentParameters::from_node_id(invoice.recover_payee_pub_key(),
                                invoice.min_final_cltv_expiry_delta() as u32)
-                       .with_features(invoice.features().unwrap().clone())
-                       .with_route_hints(invoice.route_hints());
+                       .with_bolt11_features(invoice.features().unwrap().clone()).unwrap()
+                       .with_route_hints(invoice.route_hints()).unwrap();
                let route_params = RouteParameters {
                        payment_params,
                        final_value_msat: invoice.amount_milli_satoshis().unwrap(),
@@ -1294,8 +1294,8 @@ mod test {
 
                let payment_params = PaymentParameters::from_node_id(invoice.recover_payee_pub_key(),
                                invoice.min_final_cltv_expiry_delta() as u32)
-                       .with_features(invoice.features().unwrap().clone())
-                       .with_route_hints(invoice.route_hints());
+                       .with_bolt11_features(invoice.features().unwrap().clone()).unwrap()
+                       .with_route_hints(invoice.route_hints()).unwrap();
                let params = RouteParameters {
                        payment_params,
                        final_value_msat: invoice.amount_milli_satoshis().unwrap(),
index 2a93ca433c0c4fa66b147a3a921b9eb550de7a33..2f0c96396bf92f69d2c9f88e4a1526c4990c96d7 100644 (file)
@@ -529,6 +529,17 @@ mod tests {
                fn handle_update_fee(&self, _their_node_id: &PublicKey, _msg: &UpdateFee) {}
                fn handle_announcement_signatures(&self, _their_node_id: &PublicKey, _msg: &AnnouncementSignatures) {}
                fn handle_channel_update(&self, _their_node_id: &PublicKey, _msg: &ChannelUpdate) {}
+               fn handle_open_channel_v2(&self, _their_node_id: &PublicKey, _msg: &OpenChannelV2) {}
+               fn handle_accept_channel_v2(&self, _their_node_id: &PublicKey, _msg: &AcceptChannelV2) {}
+               fn handle_tx_add_input(&self, _their_node_id: &PublicKey, _msg: &TxAddInput) {}
+               fn handle_tx_add_output(&self, _their_node_id: &PublicKey, _msg: &TxAddOutput) {}
+               fn handle_tx_remove_input(&self, _their_node_id: &PublicKey, _msg: &TxRemoveInput) {}
+               fn handle_tx_remove_output(&self, _their_node_id: &PublicKey, _msg: &TxRemoveOutput) {}
+               fn handle_tx_complete(&self, _their_node_id: &PublicKey, _msg: &TxComplete) {}
+               fn handle_tx_signatures(&self, _their_node_id: &PublicKey, _msg: &TxSignatures) {}
+               fn handle_tx_init_rbf(&self, _their_node_id: &PublicKey, _msg: &TxInitRbf) {}
+               fn handle_tx_ack_rbf(&self, _their_node_id: &PublicKey, _msg: &TxAckRbf) {}
+               fn handle_tx_abort(&self, _their_node_id: &PublicKey, _msg: &TxAbort) {}
                fn peer_disconnected(&self, their_node_id: &PublicKey) {
                        if *their_node_id == self.expected_pubkey {
                                self.disconnected_flag.store(true, Ordering::SeqCst);
index 7d1a325c7210500696495677511c2686a47c7b90..e3be6bff2fa88b4191d9b3fdc8bccf665d4ac580 100644 (file)
@@ -2339,8 +2339,16 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
                F::Target: FeeEstimator,
                L::Target: Logger,
        {
-               log_info!(logger, "Applying update to monitor {}, bringing update_id from {} to {} with {} changes.",
-                       log_funding_info!(self), self.latest_update_id, updates.update_id, updates.updates.len());
+               if self.latest_update_id == CLOSED_CHANNEL_UPDATE_ID && updates.update_id == CLOSED_CHANNEL_UPDATE_ID {
+                       log_info!(logger, "Applying post-force-closed update to monitor {} with {} change(s).",
+                               log_funding_info!(self), updates.updates.len());
+               } else if updates.update_id == CLOSED_CHANNEL_UPDATE_ID {
+                       log_info!(logger, "Applying force close update to monitor {} with {} change(s).",
+                               log_funding_info!(self), updates.updates.len());
+               } else {
+                       log_info!(logger, "Applying update to monitor {}, bringing update_id from {} to {} with {} change(s).",
+                               log_funding_info!(self), self.latest_update_id, updates.update_id, updates.updates.len());
+               }
                // ChannelMonitor updates may be applied after force close if we receive a preimage for a
                // broadcasted commitment transaction HTLC output that we'd like to claim on-chain. If this
                // is the case, we no longer have guaranteed access to the monitor's update ID, so we use a
@@ -2407,6 +2415,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
                                                                _ => false,
                                                        }).is_some();
                                                if detected_funding_spend {
+                                                       log_trace!(logger, "Avoiding commitment broadcast, already detected confirmed spend onchain");
                                                        continue;
                                                }
                                                self.broadcast_latest_holder_commitment_txn(broadcaster, logger);
@@ -2457,7 +2466,9 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
 
                self.latest_update_id = updates.update_id;
 
-               if ret.is_ok() && self.funding_spend_seen {
+               // Refuse updates after we've detected a spend onchain, but only if we haven't processed a
+               // force closed monitor update yet.
+               if ret.is_ok() && self.funding_spend_seen && self.latest_update_id != CLOSED_CHANNEL_UPDATE_ID {
                        log_error!(logger, "Refusing Channel Monitor Update as counterparty attempted to update commitment after funding was spent");
                        Err(())
                } else { ret }
index 4d8b8cee94b32c906784dfdd1b79ad282c75acb2..76a7f884ad27ceb3a1550e1b7235bf7dc8795f6d 100644 (file)
@@ -498,6 +498,8 @@ pub enum Event {
                payment_id: PaymentId,
                /// The hash that was given to [`ChannelManager::send_payment`].
                ///
+               /// This will be `Some` for all payments which completed on LDK 0.0.104 or later.
+               ///
                /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
                payment_hash: Option<PaymentHash>,
                /// The payment path that was successful.
@@ -518,6 +520,8 @@ pub enum Event {
        PaymentPathFailed {
                /// The `payment_id` passed to [`ChannelManager::send_payment`].
                ///
+               /// This will be `Some` for all payment paths which failed on LDK 0.0.103 or later.
+               ///
                /// [`ChannelManager::send_payment`]: crate::ln::channelmanager::ChannelManager::send_payment
                /// [`ChannelManager::abandon_payment`]: crate::ln::channelmanager::ChannelManager::abandon_payment
                payment_id: Option<PaymentId>,
@@ -1436,6 +1440,14 @@ pub enum MessageSendEvent {
                /// The message which should be sent.
                msg: msgs::AcceptChannel,
        },
+       /// Used to indicate that we've accepted a V2 channel open and should send the accept_channel2
+       /// message provided to the given peer.
+       SendAcceptChannelV2 {
+               /// The node_id of the node which should receive this message
+               node_id: PublicKey,
+               /// The message which should be sent.
+               msg: msgs::AcceptChannelV2,
+       },
        /// Used to indicate that we've initiated a channel open and should send the open_channel
        /// message provided to the given peer.
        SendOpenChannel {
@@ -1444,6 +1456,14 @@ pub enum MessageSendEvent {
                /// The message which should be sent.
                msg: msgs::OpenChannel,
        },
+       /// Used to indicate that we've initiated a V2 channel open and should send the open_channel2
+       /// message provided to the given peer.
+       SendOpenChannelV2 {
+               /// The node_id of the node which should receive this message
+               node_id: PublicKey,
+               /// The message which should be sent.
+               msg: msgs::OpenChannelV2,
+       },
        /// Used to indicate that a funding_created message should be sent to the peer with the given node_id.
        SendFundingCreated {
                /// The node_id of the node which should receive this message
@@ -1458,6 +1478,69 @@ pub enum MessageSendEvent {
                /// The message which should be sent.
                msg: msgs::FundingSigned,
        },
+       /// Used to indicate that a tx_add_input message should be sent to the peer with the given node_id.
+       SendTxAddInput {
+               /// The node_id of the node which should receive this message
+               node_id: PublicKey,
+               /// The message which should be sent.
+               msg: msgs::TxAddInput,
+       },
+       /// Used to indicate that a tx_add_output message should be sent to the peer with the given node_id.
+       SendTxAddOutput {
+               /// The node_id of the node which should receive this message
+               node_id: PublicKey,
+               /// The message which should be sent.
+               msg: msgs::TxAddOutput,
+       },
+       /// Used to indicate that a tx_remove_input message should be sent to the peer with the given node_id.
+       SendTxRemoveInput {
+               /// The node_id of the node which should receive this message
+               node_id: PublicKey,
+               /// The message which should be sent.
+               msg: msgs::TxRemoveInput,
+       },
+       /// Used to indicate that a tx_remove_output message should be sent to the peer with the given node_id.
+       SendTxRemoveOutput {
+               /// The node_id of the node which should receive this message
+               node_id: PublicKey,
+               /// The message which should be sent.
+               msg: msgs::TxRemoveOutput,
+       },
+       /// Used to indicate that a tx_complete message should be sent to the peer with the given node_id.
+       SendTxComplete {
+               /// The node_id of the node which should receive this message
+               node_id: PublicKey,
+               /// The message which should be sent.
+               msg: msgs::TxComplete,
+       },
+       /// Used to indicate that a tx_signatures message should be sent to the peer with the given node_id.
+       SendTxSignatures {
+               /// The node_id of the node which should receive this message
+               node_id: PublicKey,
+               /// The message which should be sent.
+               msg: msgs::TxSignatures,
+       },
+       /// Used to indicate that a tx_init_rbf message should be sent to the peer with the given node_id.
+       SendTxInitRbf {
+               /// The node_id of the node which should receive this message
+               node_id: PublicKey,
+               /// The message which should be sent.
+               msg: msgs::TxInitRbf,
+       },
+       /// Used to indicate that a tx_ack_rbf message should be sent to the peer with the given node_id.
+       SendTxAckRbf {
+               /// The node_id of the node which should receive this message
+               node_id: PublicKey,
+               /// The message which should be sent.
+               msg: msgs::TxAckRbf,
+       },
+       /// Used to indicate that a tx_abort message should be sent to the peer with the given node_id.
+       SendTxAbort {
+               /// The node_id of the node which should receive this message
+               node_id: PublicKey,
+               /// The message which should be sent.
+               msg: msgs::TxAddInput,
+       },
        /// Used to indicate that a channel_ready message should be sent to the peer with the given node_id.
        SendChannelReady {
                /// The node_id of the node which should receive these message(s)
index 4fd612a4b91e33c99659c46e592bf6b22d70a3ec..11f0261d677a3df37b2fa36f94ea142e5ce8f16c 100644 (file)
@@ -4092,7 +4092,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
 
                if msg.next_local_commitment_number >= INITIAL_COMMITMENT_NUMBER || msg.next_remote_commitment_number >= INITIAL_COMMITMENT_NUMBER ||
                        msg.next_local_commitment_number == 0 {
-                       return Err(ChannelError::Close("Peer sent a garbage channel_reestablish".to_owned()));
+                       return Err(ChannelError::Close("Peer sent a garbage channel_reestablish (usually an lnd node with lost state asking us to force-close for them)".to_owned()));
                }
 
                if msg.next_remote_commitment_number > 0 {
@@ -5774,6 +5774,10 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
                        next_remote_commitment_number: INITIAL_COMMITMENT_NUMBER - self.cur_counterparty_commitment_transaction_number - 1,
                        your_last_per_commitment_secret: remote_last_secret,
                        my_current_per_commitment_point: dummy_pubkey,
+                       // TODO(dual_funding): If we've sent `commtiment_signed` for an interactive transaction
+                       // construction but have not received `tx_signatures` we MUST set `next_funding_txid` to the
+                       // txid of that interactive transaction, else we MUST NOT set it.
+                       next_funding_txid: None,
                }
        }
 
index 3bf215d0a4aef8d40a923b332ea62c44f403a199..d6cd6e24cadfeada3bf918a4ee949a1501fe33f3 100644 (file)
@@ -45,7 +45,7 @@ use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, No
 #[cfg(any(feature = "_test_utils", test))]
 use crate::ln::features::InvoiceFeatures;
 use crate::routing::gossip::NetworkGraph;
-use crate::routing::router::{BlindedTail, DefaultRouter, InFlightHtlcs, Path, PaymentParameters, Route, RouteHop, RouteParameters, Router};
+use crate::routing::router::{BlindedTail, DefaultRouter, InFlightHtlcs, Path, Payee, PaymentParameters, Route, RouteHop, RouteParameters, Router};
 use crate::routing::scoring::ProbabilisticScorer;
 use crate::ln::msgs;
 use crate::ln::onion_utils;
@@ -6488,11 +6488,23 @@ where
                let _ = handle_error!(self, self.internal_open_channel(counterparty_node_id, msg), *counterparty_node_id);
        }
 
+       fn handle_open_channel_v2(&self, counterparty_node_id: &PublicKey, msg: &msgs::OpenChannelV2) {
+               let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
+                       "Dual-funded channels not supported".to_owned(),
+                        msg.temporary_channel_id.clone())), *counterparty_node_id);
+       }
+
        fn handle_accept_channel(&self, counterparty_node_id: &PublicKey, msg: &msgs::AcceptChannel) {
                let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier);
                let _ = handle_error!(self, self.internal_accept_channel(counterparty_node_id, msg), *counterparty_node_id);
        }
 
+       fn handle_accept_channel_v2(&self, counterparty_node_id: &PublicKey, msg: &msgs::AcceptChannelV2) {
+               let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
+                       "Dual-funded channels not supported".to_owned(),
+                        msg.temporary_channel_id.clone())), *counterparty_node_id);
+       }
+
        fn handle_funding_created(&self, counterparty_node_id: &PublicKey, msg: &msgs::FundingCreated) {
                let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(&self.total_consistency_lock, &self.persistence_notifier);
                let _ = handle_error!(self, self.internal_funding_created(counterparty_node_id, msg), *counterparty_node_id);
@@ -6595,23 +6607,40 @@ where
                                });
                                pending_msg_events.retain(|msg| {
                                        match msg {
+                                               // V1 Channel Establishment
                                                &events::MessageSendEvent::SendAcceptChannel { .. } => false,
                                                &events::MessageSendEvent::SendOpenChannel { .. } => false,
                                                &events::MessageSendEvent::SendFundingCreated { .. } => false,
                                                &events::MessageSendEvent::SendFundingSigned { .. } => false,
+                                               // V2 Channel Establishment
+                                               &events::MessageSendEvent::SendAcceptChannelV2 { .. } => false,
+                                               &events::MessageSendEvent::SendOpenChannelV2 { .. } => false,
+                                               // Common Channel Establishment
                                                &events::MessageSendEvent::SendChannelReady { .. } => false,
                                                &events::MessageSendEvent::SendAnnouncementSignatures { .. } => false,
+                                               // Interactive Transaction Construction
+                                               &events::MessageSendEvent::SendTxAddInput { .. } => false,
+                                               &events::MessageSendEvent::SendTxAddOutput { .. } => false,
+                                               &events::MessageSendEvent::SendTxRemoveInput { .. } => false,
+                                               &events::MessageSendEvent::SendTxRemoveOutput { .. } => false,
+                                               &events::MessageSendEvent::SendTxComplete { .. } => false,
+                                               &events::MessageSendEvent::SendTxSignatures { .. } => false,
+                                               &events::MessageSendEvent::SendTxInitRbf { .. } => false,
+                                               &events::MessageSendEvent::SendTxAckRbf { .. } => false,
+                                               &events::MessageSendEvent::SendTxAbort { .. } => false,
+                                               // Channel Operations
                                                &events::MessageSendEvent::UpdateHTLCs { .. } => false,
                                                &events::MessageSendEvent::SendRevokeAndACK { .. } => false,
                                                &events::MessageSendEvent::SendClosingSigned { .. } => false,
                                                &events::MessageSendEvent::SendShutdown { .. } => false,
                                                &events::MessageSendEvent::SendChannelReestablish { .. } => false,
+                                               &events::MessageSendEvent::HandleError { .. } => false,
+                                               // Gossip
                                                &events::MessageSendEvent::SendChannelAnnouncement { .. } => false,
                                                &events::MessageSendEvent::BroadcastChannelAnnouncement { .. } => true,
                                                &events::MessageSendEvent::BroadcastChannelUpdate { .. } => true,
                                                &events::MessageSendEvent::BroadcastNodeAnnouncement { .. } => true,
                                                &events::MessageSendEvent::SendChannelUpdate { .. } => false,
-                                               &events::MessageSendEvent::HandleError { .. } => false,
                                                &events::MessageSendEvent::SendChannelRangeQuery { .. } => false,
                                                &events::MessageSendEvent::SendShortIdsQuery { .. } => false,
                                                &events::MessageSendEvent::SendReplyChannelRange { .. } => false,
@@ -6768,6 +6797,60 @@ where
        fn provided_init_features(&self, _their_init_features: &PublicKey) -> InitFeatures {
                provided_init_features(&self.default_configuration)
        }
+
+       fn handle_tx_add_input(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAddInput) {
+               let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
+                       "Dual-funded channels not supported".to_owned(),
+                        msg.channel_id.clone())), *counterparty_node_id);
+       }
+
+       fn handle_tx_add_output(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAddOutput) {
+               let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
+                       "Dual-funded channels not supported".to_owned(),
+                        msg.channel_id.clone())), *counterparty_node_id);
+       }
+
+       fn handle_tx_remove_input(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxRemoveInput) {
+               let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
+                       "Dual-funded channels not supported".to_owned(),
+                        msg.channel_id.clone())), *counterparty_node_id);
+       }
+
+       fn handle_tx_remove_output(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxRemoveOutput) {
+               let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
+                       "Dual-funded channels not supported".to_owned(),
+                        msg.channel_id.clone())), *counterparty_node_id);
+       }
+
+       fn handle_tx_complete(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxComplete) {
+               let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
+                       "Dual-funded channels not supported".to_owned(),
+                        msg.channel_id.clone())), *counterparty_node_id);
+       }
+
+       fn handle_tx_signatures(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxSignatures) {
+               let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
+                       "Dual-funded channels not supported".to_owned(),
+                        msg.channel_id.clone())), *counterparty_node_id);
+       }
+
+       fn handle_tx_init_rbf(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxInitRbf) {
+               let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
+                       "Dual-funded channels not supported".to_owned(),
+                        msg.channel_id.clone())), *counterparty_node_id);
+       }
+
+       fn handle_tx_ack_rbf(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAckRbf) {
+               let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
+                       "Dual-funded channels not supported".to_owned(),
+                        msg.channel_id.clone())), *counterparty_node_id);
+       }
+
+       fn handle_tx_abort(&self, counterparty_node_id: &PublicKey, msg: &msgs::TxAbort) {
+               let _: Result<(), _> = handle_error!(self, Err(MsgHandleErrInternal::send_err_msg_no_close(
+                       "Dual-funded channels not supported".to_owned(),
+                        msg.channel_id.clone())), *counterparty_node_id);
+       }
 }
 
 /// Fetches the set of [`NodeFeatures`] flags which are provided by or required by
@@ -7168,8 +7251,10 @@ impl Readable for HTLCSource {
                                        return Err(DecodeError::InvalidValue);
                                }
                                if let Some(params) = payment_params.as_mut() {
-                                       if params.final_cltv_expiry_delta == 0 {
-                                               params.final_cltv_expiry_delta = path.final_cltv_expiry_delta().ok_or(DecodeError::InvalidValue)?;
+                                       if let Payee::Clear { ref mut final_cltv_expiry_delta, .. } = params.payee {
+                                               if final_cltv_expiry_delta == &0 {
+                                                       *final_cltv_expiry_delta = path.final_cltv_expiry_delta().ok_or(DecodeError::InvalidValue)?;
+                                               }
                                        }
                                }
                                Ok(HTLCSource::OutboundRoute {
@@ -7756,6 +7841,8 @@ where
 
                for (funding_txo, _) in args.channel_monitors.iter() {
                        if !funding_txo_set.contains(funding_txo) {
+                               log_info!(args.logger, "Queueing monitor update to ensure missing channel {} is force closed",
+                                       log_bytes!(funding_txo.to_channel_id()));
                                let monitor_update = ChannelMonitorUpdate {
                                        update_id: CLOSED_CHANNEL_UPDATE_ID,
                                        updates: vec![ChannelMonitorUpdateStep::ChannelForceClosed { should_broadcast: true }],
@@ -9343,7 +9430,7 @@ pub mod bench {
                macro_rules! send_payment {
                        ($node_a: expr, $node_b: expr) => {
                                let payment_params = PaymentParameters::from_node_id($node_b.get_our_node_id(), TEST_FINAL_CLTV)
-                                       .with_features($node_b.invoice_features());
+                                       .with_bolt11_features($node_b.invoice_features()).unwrap();
                                let mut payment_preimage = PaymentPreimage([0; 32]);
                                payment_preimage.0[0..8].copy_from_slice(&payment_count.to_le_bytes());
                                payment_count += 1;
index 8ccbf4166bbe71294a64309ed4832b9364845fa9..ca8150b09cfa580d69e55550cc6661b3068ea15c 100644 (file)
@@ -532,6 +532,14 @@ impl InvoiceFeatures {
        }
 }
 
+impl Bolt12InvoiceFeatures {
+       /// Converts `Bolt12InvoiceFeatures` to `Features<C>`. Only known `Bolt12InvoiceFeatures` relevant
+       /// to context `C` are included in the result.
+       pub(crate) fn to_context<C: sealed::Context>(&self) -> Features<C> {
+               self.to_context_internal()
+       }
+}
+
 impl ChannelTypeFeatures {
        // Maps the relevant `InitFeatures` to `ChannelTypeFeatures`. Any unknown features to
        // `ChannelTypeFeatures` are not included in the result.
@@ -791,6 +799,7 @@ impl_feature_len_prefixed_write!(InitFeatures);
 impl_feature_len_prefixed_write!(ChannelFeatures);
 impl_feature_len_prefixed_write!(NodeFeatures);
 impl_feature_len_prefixed_write!(InvoiceFeatures);
+impl_feature_len_prefixed_write!(Bolt12InvoiceFeatures);
 impl_feature_len_prefixed_write!(BlindedHopFeatures);
 
 // Some features only appear inside of TLVs, so they don't have a length prefix when serialized.
index 47df7c30e0a1bdb599d7282ff2eb87dd24349ca2..637c05ff2e447ce5202d59ad70a16dcdeb0a547b 100644 (file)
@@ -724,6 +724,39 @@ pub fn remove_first_msg_event_to_node(msg_node_id: &PublicKey, msg_events: &mut
                MessageSendEvent::SendGossipTimestampFilter { node_id, .. } => {
                        node_id == msg_node_id
                },
+               MessageSendEvent::SendAcceptChannelV2 { node_id, .. } => {
+                       node_id == msg_node_id
+               },
+               MessageSendEvent::SendOpenChannelV2 { node_id, .. } => {
+                       node_id == msg_node_id
+               },
+               MessageSendEvent::SendTxAddInput { node_id, .. } => {
+                       node_id == msg_node_id
+               },
+               MessageSendEvent::SendTxAddOutput { node_id, .. } => {
+                       node_id == msg_node_id
+               },
+               MessageSendEvent::SendTxRemoveInput { node_id, .. } => {
+                       node_id == msg_node_id
+               },
+               MessageSendEvent::SendTxRemoveOutput { node_id, .. } => {
+                       node_id == msg_node_id
+               },
+               MessageSendEvent::SendTxComplete { node_id, .. } => {
+                       node_id == msg_node_id
+               },
+               MessageSendEvent::SendTxSignatures { node_id, .. } => {
+                       node_id == msg_node_id
+               },
+               MessageSendEvent::SendTxInitRbf { node_id, .. } => {
+                       node_id == msg_node_id
+               },
+               MessageSendEvent::SendTxAckRbf { node_id, .. } => {
+                       node_id == msg_node_id
+               },
+               MessageSendEvent::SendTxAbort { node_id, .. } => {
+                       node_id == msg_node_id
+               },
        }});
        if ev_index.is_some() {
                msg_events.remove(ev_index.unwrap())
@@ -1724,7 +1757,7 @@ macro_rules! get_route {
 macro_rules! get_route_and_payment_hash {
        ($send_node: expr, $recv_node: expr, $recv_value: expr) => {{
                let payment_params = $crate::routing::router::PaymentParameters::from_node_id($recv_node.node.get_our_node_id(), TEST_FINAL_CLTV)
-                       .with_features($recv_node.node.invoice_features());
+                       .with_bolt11_features($recv_node.node.invoice_features()).unwrap();
                $crate::get_route_and_payment_hash!($send_node, $recv_node, payment_params, $recv_value)
        }};
        ($send_node: expr, $recv_node: expr, $payment_params: expr, $recv_value: expr) => {{
@@ -2273,7 +2306,7 @@ pub const TEST_FINAL_CLTV: u32 = 70;
 
 pub fn route_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) -> (PaymentPreimage, PaymentHash, PaymentSecret) {
        let payment_params = PaymentParameters::from_node_id(expected_route.last().unwrap().node.get_our_node_id(), TEST_FINAL_CLTV)
-               .with_features(expected_route.last().unwrap().node.invoice_features());
+               .with_bolt11_features(expected_route.last().unwrap().node.invoice_features()).unwrap();
        let route = get_route(origin_node, &payment_params, recv_value).unwrap();
        assert_eq!(route.paths.len(), 1);
        assert_eq!(route.paths[0].hops.len(), expected_route.len());
@@ -2287,7 +2320,7 @@ pub fn route_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route:
 
 pub fn route_over_limit<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64)  {
        let payment_params = PaymentParameters::from_node_id(expected_route.last().unwrap().node.get_our_node_id(), TEST_FINAL_CLTV)
-               .with_features(expected_route.last().unwrap().node.invoice_features());
+               .with_bolt11_features(expected_route.last().unwrap().node.invoice_features()).unwrap();
        let network_graph = origin_node.network_graph.read_only();
        let scorer = test_utils::TestScorer::new();
        let seed = [0u8; 32];
index 68d7d6708c0c704f52e2a32204867df6542a24de..bbff80b1f6267275c16acba2d7dd8f3091e53ee5 100644 (file)
@@ -1829,7 +1829,7 @@ fn test_channel_reserve_holding_cell_htlcs() {
        // attempt to send amt_msat > their_max_htlc_value_in_flight_msat
        {
                let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV)
-                       .with_features(nodes[2].node.invoice_features()).with_max_channel_saturation_power_of_half(0);
+                       .with_bolt11_features(nodes[2].node.invoice_features()).unwrap().with_max_channel_saturation_power_of_half(0);
                let (mut route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, recv_value_0);
                route.paths[0].hops.last_mut().unwrap().fee_msat += 1;
                assert!(route.paths[0].hops.iter().rev().skip(1).all(|h| h.fee_msat == feemsat));
@@ -1856,7 +1856,7 @@ fn test_channel_reserve_holding_cell_htlcs() {
                }
 
                let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV)
-                       .with_features(nodes[2].node.invoice_features()).with_max_channel_saturation_power_of_half(0);
+                       .with_bolt11_features(nodes[2].node.invoice_features()).unwrap().with_max_channel_saturation_power_of_half(0);
                let route = get_route!(nodes[0], payment_params, recv_value_0).unwrap();
                let (payment_preimage, ..) = send_along_route(&nodes[0], route, &[&nodes[1], &nodes[2]], recv_value_0);
                claim_payment(&nodes[0], &[&nodes[1], &nodes[2]], payment_preimage);
@@ -4795,7 +4795,7 @@ fn test_duplicate_payment_hash_one_failure_one_success() {
        // script push size limit so that the below script length checks match
        // ACCEPTED_HTLC_SCRIPT_WEIGHT.
        let payment_params = PaymentParameters::from_node_id(nodes[3].node.get_our_node_id(), TEST_FINAL_CLTV - 40)
-               .with_features(nodes[3].node.invoice_features());
+               .with_bolt11_features(nodes[3].node.invoice_features()).unwrap();
        let (route, _, _, _) = get_route_and_payment_hash!(nodes[0], nodes[3], payment_params, 800_000);
        send_along_route_with_secret(&nodes[0], route, &[&[&nodes[1], &nodes[2], &nodes[3]]], 800_000, duplicate_payment_hash, payment_secret);
 
@@ -6101,7 +6101,7 @@ fn test_update_add_htlc_bolt2_sender_cltv_expiry_too_high() {
        let _chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 0);
 
        let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), 0)
-               .with_features(nodes[1].node.invoice_features());
+               .with_bolt11_features(nodes[1].node.invoice_features()).unwrap();
        let (mut route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], payment_params, 100000000);
        route.paths[0].hops.last_mut().unwrap().cltv_expiry_delta = 500000001;
        unwrap_send_err!(nodes[0].node.send_payment_with_route(&route, our_payment_hash,
@@ -7043,7 +7043,7 @@ fn test_check_htlc_underpaying() {
 
        let scorer = test_utils::TestScorer::new();
        let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
-       let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV).with_features(nodes[1].node.invoice_features());
+       let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV).with_bolt11_features(nodes[1].node.invoice_features()).unwrap();
        let route = get_route(&nodes[0].node.get_our_node_id(), &payment_params, &nodes[0].network_graph.read_only(), None, 10_000, nodes[0].logger, &scorer, &random_seed_bytes).unwrap();
        let (_, our_payment_hash, _) = get_payment_preimage_hash!(nodes[0]);
        let our_payment_secret = nodes[1].node.create_inbound_payment_for_hash(our_payment_hash, Some(100_000), 7200, None).unwrap();
@@ -7189,7 +7189,7 @@ fn test_bump_penalty_txn_on_revoked_commitment() {
 
        let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0;
        let payment_params = PaymentParameters::from_node_id(nodes[0].node.get_our_node_id(), 30)
-               .with_features(nodes[0].node.invoice_features());
+               .with_bolt11_features(nodes[0].node.invoice_features()).unwrap();
        let (route,_, _, _) = get_route_and_payment_hash!(nodes[1], nodes[0], payment_params, 3000000);
        send_along_route(&nodes[1], route, &vec!(&nodes[0])[..], 3000000);
 
@@ -7294,13 +7294,13 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
 
        let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000);
        // Lock HTLC in both directions (using a slightly lower CLTV delay to provide timely RBF bumps)
-       let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), 50).with_features(nodes[1].node.invoice_features());
+       let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), 50).with_bolt11_features(nodes[1].node.invoice_features()).unwrap();
        let scorer = test_utils::TestScorer::new();
        let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
        let route = get_route(&nodes[0].node.get_our_node_id(), &payment_params, &nodes[0].network_graph.read_only(), None,
                3_000_000, nodes[0].logger, &scorer, &random_seed_bytes).unwrap();
        let payment_preimage = send_along_route(&nodes[0], route, &[&nodes[1]], 3_000_000).0;
-       let payment_params = PaymentParameters::from_node_id(nodes[0].node.get_our_node_id(), 50).with_features(nodes[0].node.invoice_features());
+       let payment_params = PaymentParameters::from_node_id(nodes[0].node.get_our_node_id(), 50).with_bolt11_features(nodes[0].node.invoice_features()).unwrap();
        let route = get_route(&nodes[1].node.get_our_node_id(), &payment_params, &nodes[1].network_graph.read_only(), None,
                3_000_000, nodes[0].logger, &scorer, &random_seed_bytes).unwrap();
        send_along_route(&nodes[1], route, &[&nodes[0]], 3_000_000);
@@ -9300,7 +9300,7 @@ fn do_test_dup_htlc_second_rejected(test_for_second_fail_panic: bool) {
        let _chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 10001);
 
        let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV)
-               .with_features(nodes[1].node.invoice_features());
+               .with_bolt11_features(nodes[1].node.invoice_features()).unwrap();
        let route = get_route!(nodes[0], payment_params, 10_000).unwrap();
 
        let (our_payment_preimage, our_payment_hash, our_payment_secret) = get_payment_preimage_hash!(&nodes[1]);
@@ -9409,7 +9409,7 @@ fn test_inconsistent_mpp_params() {
        let chan_2_3 =create_announced_chan_between_nodes_with_value(&nodes, 2, 3, 100_000, 0);
 
        let payment_params = PaymentParameters::from_node_id(nodes[3].node.get_our_node_id(), TEST_FINAL_CLTV)
-               .with_features(nodes[3].node.invoice_features());
+               .with_bolt11_features(nodes[3].node.invoice_features()).unwrap();
        let mut route = get_route!(nodes[0], payment_params, 15_000_000).unwrap();
        assert_eq!(route.paths.len(), 2);
        route.paths.sort_by(|path_a, _| {
index df6a2aba3b9df821f742421aa90feca5f4a31069..27f8544e3b52021345f66ccd9c434beea2876bf2 100644 (file)
@@ -26,7 +26,7 @@
 
 use bitcoin::secp256k1::PublicKey;
 use bitcoin::secp256k1::ecdsa::Signature;
-use bitcoin::secp256k1;
+use bitcoin::{secp256k1, Witness, Transaction};
 use bitcoin::blockdata::script::Script;
 use bitcoin::hash_types::{Txid, BlockHash};
 
@@ -158,6 +158,8 @@ pub struct Pong {
 
 /// An [`open_channel`] message to be sent to or received from a peer.
 ///
+/// Used in V1 channel establishment
+///
 /// [`open_channel`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-open_channel-message
 #[derive(Clone, Debug, PartialEq, Eq)]
 pub struct OpenChannel {
@@ -208,8 +210,69 @@ pub struct OpenChannel {
        pub channel_type: Option<ChannelTypeFeatures>,
 }
 
+/// An open_channel2 message to be sent by or received from the channel initiator.
+///
+/// Used in V2 channel establishment
+///
+// TODO(dual_funding): Add spec link for `open_channel2`.
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub struct OpenChannelV2 {
+       /// The genesis hash of the blockchain where the channel is to be opened
+       pub chain_hash: BlockHash,
+       /// A temporary channel ID derived using a zeroed out value for the channel acceptor's revocation basepoint
+       pub temporary_channel_id: [u8; 32],
+       /// The feerate for the funding transaction set by the channel initiator
+       pub funding_feerate_sat_per_1000_weight: u32,
+       /// The feerate for the commitment transaction set by the channel initiator
+       pub commitment_feerate_sat_per_1000_weight: u32,
+       /// Part of the channel value contributed by the channel initiator
+       pub funding_satoshis: u64,
+       /// The threshold below which outputs on transactions broadcast by the channel initiator will be
+       /// omitted
+       pub dust_limit_satoshis: u64,
+       /// The maximum inbound HTLC value in flight towards channel initiator, in milli-satoshi
+       pub max_htlc_value_in_flight_msat: u64,
+       /// The minimum HTLC size incoming to channel initiator, in milli-satoshi
+       pub htlc_minimum_msat: u64,
+       /// The number of blocks which the counterparty will have to wait to claim on-chain funds if they
+       /// broadcast a commitment transaction
+       pub to_self_delay: u16,
+       /// The maximum number of inbound HTLCs towards channel initiator
+       pub max_accepted_htlcs: u16,
+       /// The locktime for the funding transaction
+       pub locktime: u32,
+       /// The channel initiator's key controlling the funding transaction
+       pub funding_pubkey: PublicKey,
+       /// Used to derive a revocation key for transactions broadcast by counterparty
+       pub revocation_basepoint: PublicKey,
+       /// A payment key to channel initiator for transactions broadcast by counterparty
+       pub payment_basepoint: PublicKey,
+       /// Used to derive a payment key to channel initiator for transactions broadcast by channel
+       /// initiator
+       pub delayed_payment_basepoint: PublicKey,
+       /// Used to derive an HTLC payment key to channel initiator
+       pub htlc_basepoint: PublicKey,
+       /// The first to-be-broadcast-by-channel-initiator transaction's per commitment point
+       pub first_per_commitment_point: PublicKey,
+       /// The second to-be-broadcast-by-channel-initiator transaction's per commitment point
+       pub second_per_commitment_point: PublicKey,
+       /// Channel flags
+       pub channel_flags: u8,
+       /// Optionally, a request to pre-set the to-channel-initiator output's scriptPubkey for when we
+       /// collaboratively close
+       pub shutdown_scriptpubkey: Option<Script>,
+       /// The channel type that this channel will represent. If none is set, we derive the channel
+       /// type from the intersection of our feature bits with our counterparty's feature bits from
+       /// the Init message.
+       pub channel_type: Option<ChannelTypeFeatures>,
+       /// Optionally, a requirement that only confirmed inputs can be added
+       pub require_confirmed_inputs: Option<()>,
+}
+
 /// An [`accept_channel`] message to be sent to or received from a peer.
 ///
+/// Used in V1 channel establishment
+///
 /// [`accept_channel`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-accept_channel-message
 #[derive(Clone, Debug, PartialEq, Eq)]
 pub struct AcceptChannel {
@@ -254,8 +317,63 @@ pub struct AcceptChannel {
        pub next_local_nonce: Option<musig2::types::PublicNonce>,
 }
 
+/// An accept_channel2 message to be sent by or received from the channel accepter.
+///
+/// Used in V2 channel establishment
+///
+// TODO(dual_funding): Add spec link for `accept_channel2`.
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub struct AcceptChannelV2 {
+       /// The same `temporary_channel_id` received from the initiator's `open_channel2` message.
+       pub temporary_channel_id: [u8; 32],
+       /// Part of the channel value contributed by the channel acceptor
+       pub funding_satoshis: u64,
+       /// The threshold below which outputs on transactions broadcast by the channel acceptor will be
+       /// omitted
+       pub dust_limit_satoshis: u64,
+       /// The maximum inbound HTLC value in flight towards channel acceptor, in milli-satoshi
+       pub max_htlc_value_in_flight_msat: u64,
+       /// The minimum HTLC size incoming to channel acceptor, in milli-satoshi
+       pub htlc_minimum_msat: u64,
+       /// Minimum depth of the funding transaction before the channel is considered open
+       pub minimum_depth: u32,
+       /// The number of blocks which the counterparty will have to wait to claim on-chain funds if they
+       /// broadcast a commitment transaction
+       pub to_self_delay: u16,
+       /// The maximum number of inbound HTLCs towards channel acceptor
+       pub max_accepted_htlcs: u16,
+       /// The channel acceptor's key controlling the funding transaction
+       pub funding_pubkey: PublicKey,
+       /// Used to derive a revocation key for transactions broadcast by counterparty
+       pub revocation_basepoint: PublicKey,
+       /// A payment key to channel acceptor for transactions broadcast by counterparty
+       pub payment_basepoint: PublicKey,
+       /// Used to derive a payment key to channel acceptor for transactions broadcast by channel
+       /// acceptor
+       pub delayed_payment_basepoint: PublicKey,
+       /// Used to derive an HTLC payment key to channel acceptor for transactions broadcast by counterparty
+       pub htlc_basepoint: PublicKey,
+       /// The first to-be-broadcast-by-channel-acceptor transaction's per commitment point
+       pub first_per_commitment_point: PublicKey,
+       /// The second to-be-broadcast-by-channel-acceptor transaction's per commitment point
+       pub second_per_commitment_point: PublicKey,
+       /// Optionally, a request to pre-set the to-channel-acceptor output's scriptPubkey for when we
+       /// collaboratively close
+       pub shutdown_scriptpubkey: Option<Script>,
+       /// The channel type that this channel will represent. If none is set, we derive the channel
+       /// type from the intersection of our feature bits with our counterparty's feature bits from
+       /// the Init message.
+       ///
+       /// This is required to match the equivalent field in [`OpenChannelV2::channel_type`].
+       pub channel_type: Option<ChannelTypeFeatures>,
+       /// Optionally, a requirement that only confirmed inputs can be added
+       pub require_confirmed_inputs: Option<()>,
+}
+
 /// A [`funding_created`] message to be sent to or received from a peer.
 ///
+/// Used in V1 channel establishment
+///
 /// [`funding_created`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-funding_created-message
 #[derive(Clone, Debug, PartialEq, Eq)]
 pub struct FundingCreated {
@@ -277,6 +395,8 @@ pub struct FundingCreated {
 
 /// A [`funding_signed`] message to be sent to or received from a peer.
 ///
+/// Used in V1 channel establishment
+///
 /// [`funding_signed`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-funding_signed-message
 #[derive(Clone, Debug, PartialEq, Eq)]
 pub struct FundingSigned {
@@ -305,6 +425,167 @@ pub struct ChannelReady {
        pub short_channel_id_alias: Option<u64>,
 }
 
+/// A wrapper for a `Transaction` which can only be constructed with [`TransactionU16LenLimited::new`]
+/// if the `Transaction`'s consensus-serialized length is <= u16::MAX.
+///
+/// Use [`TransactionU16LenLimited::into_transaction`] to convert into the contained `Transaction`.
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub struct TransactionU16LenLimited(Transaction);
+
+impl TransactionU16LenLimited {
+       /// Constructs a new `TransactionU16LenLimited` from a `Transaction` only if it's consensus-
+       /// serialized length is <= u16::MAX.
+       pub fn new(transaction: Transaction) -> Result<Self, ()> {
+               if transaction.serialized_length() > (u16::MAX as usize) {
+                       Err(())
+               } else {
+                       Ok(Self(transaction))
+               }
+       }
+
+       /// Consumes this `TransactionU16LenLimited` and returns its contained `Transaction`.
+       pub fn into_transaction(self) -> Transaction {
+               self.0
+       }
+}
+
+impl Writeable for TransactionU16LenLimited {
+       fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
+               (self.0.serialized_length() as u16).write(w)?;
+               self.0.write(w)
+       }
+}
+
+impl Readable for TransactionU16LenLimited {
+       fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
+               let len = <u16 as Readable>::read(r)?;
+               let mut tx_reader = FixedLengthReader::new(r, len as u64);
+               Ok(Self(Readable::read(&mut tx_reader)?))
+       }
+}
+
+/// A tx_add_input message for adding an input during interactive transaction construction
+///
+// TODO(dual_funding): Add spec link for `tx_add_input`.
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub struct TxAddInput {
+       /// The channel ID
+       pub channel_id: [u8; 32],
+       /// A randomly chosen unique identifier for this input, which is even for initiators and odd for
+       /// non-initiators.
+       pub serial_id: u64,
+       /// Serialized transaction that contains the output this input spends to verify that it is non
+       /// malleable.
+       pub prevtx: TransactionU16LenLimited,
+       /// The index of the output being spent
+       pub prevtx_out: u32,
+       /// The sequence number of this input
+       pub sequence: u32,
+}
+
+/// A tx_add_output message for adding an output during interactive transaction construction.
+///
+// TODO(dual_funding): Add spec link for `tx_add_output`.
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub struct TxAddOutput {
+       /// The channel ID
+       pub channel_id: [u8; 32],
+       /// A randomly chosen unique identifier for this output, which is even for initiators and odd for
+       /// non-initiators.
+       pub serial_id: u64,
+       /// The satoshi value of the output
+       pub sats: u64,
+       /// The scriptPubKey for the output
+       pub script: Script,
+}
+
+/// A tx_remove_input message for removing an input during interactive transaction construction.
+///
+// TODO(dual_funding): Add spec link for `tx_remove_input`.
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub struct TxRemoveInput {
+       /// The channel ID
+       pub channel_id: [u8; 32],
+       /// The serial ID of the input to be removed
+       pub serial_id: u64,
+}
+
+/// A tx_remove_output message for removing an output during interactive transaction construction.
+///
+// TODO(dual_funding): Add spec link for `tx_remove_output`.
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub struct TxRemoveOutput {
+       /// The channel ID
+       pub channel_id: [u8; 32],
+       /// The serial ID of the output to be removed
+       pub serial_id: u64,
+}
+
+/// A tx_complete message signalling the conclusion of a peer's transaction contributions during
+/// interactive transaction construction.
+///
+// TODO(dual_funding): Add spec link for `tx_complete`.
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub struct TxComplete {
+       /// The channel ID
+       pub channel_id: [u8; 32],
+}
+
+/// A tx_signatures message containing the sender's signatures for a transaction constructed with
+/// interactive transaction construction.
+///
+// TODO(dual_funding): Add spec link for `tx_signatures`.
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub struct TxSignatures {
+       /// The channel ID
+       pub channel_id: [u8; 32],
+       /// The TXID
+       pub tx_hash: Txid,
+       /// The list of witnesses
+       pub witnesses: Vec<Witness>,
+}
+
+/// A tx_init_rbf message which initiates a replacement of the transaction after it's been
+/// completed.
+///
+// TODO(dual_funding): Add spec link for `tx_init_rbf`.
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub struct TxInitRbf {
+       /// The channel ID
+       pub channel_id: [u8; 32],
+       /// The locktime of the transaction
+       pub locktime: u32,
+       /// The feerate of the transaction
+       pub feerate_sat_per_1000_weight: u32,
+       /// The number of satoshis the sender will contribute to or, if negative, remove from
+       /// (e.g. splice-out) the funding output of the transaction
+       pub funding_output_contribution: Option<i64>,
+}
+
+/// A tx_ack_rbf message which acknowledges replacement of the transaction after it's been
+/// completed.
+///
+// TODO(dual_funding): Add spec link for `tx_ack_rbf`.
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub struct TxAckRbf {
+       /// The channel ID
+       pub channel_id: [u8; 32],
+       /// The number of satoshis the sender will contribute to or, if negative, remove from
+       /// (e.g. splice-out) the funding output of the transaction
+       pub funding_output_contribution: Option<i64>,
+}
+
+/// A tx_abort message which signals the cancellation of an in-progress transaction negotiation.
+///
+// TODO(dual_funding): Add spec link for `tx_abort`.
+#[derive(Clone, Debug, PartialEq, Eq)]
+pub struct TxAbort {
+       /// The channel ID
+       pub channel_id: [u8; 32],
+       /// Message data
+       pub data: Vec<u8>,
+}
+
 /// A [`shutdown`] message to be sent to or received from a peer.
 ///
 /// [`shutdown`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#closing-initiation-shutdown
@@ -474,6 +755,8 @@ pub struct ChannelReestablish {
        pub your_last_per_commitment_secret: [u8; 32],
        /// The sender's per-commitment point for their current commitment transaction
        pub my_current_per_commitment_point: PublicKey,
+       /// The next funding transaction ID
+       pub next_funding_txid: Option<Txid>,
 }
 
 /// An [`announcement_signatures`] message to be sent to or received from a peer.
@@ -567,7 +850,7 @@ impl NetAddress {
 }
 
 impl Writeable for NetAddress {
-       fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
+fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
                match self {
                        &NetAddress::IPv4 { ref addr, ref port } => {
                                1u8.write(writer)?;
@@ -954,8 +1237,12 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider {
        // Channel init:
        /// Handle an incoming `open_channel` message from the given peer.
        fn handle_open_channel(&self, their_node_id: &PublicKey, msg: &OpenChannel);
+       /// Handle an incoming `open_channel2` message from the given peer.
+       fn handle_open_channel_v2(&self, their_node_id: &PublicKey, msg: &OpenChannelV2);
        /// Handle an incoming `accept_channel` message from the given peer.
        fn handle_accept_channel(&self, their_node_id: &PublicKey, msg: &AcceptChannel);
+       /// Handle an incoming `accept_channel2` message from the given peer.
+       fn handle_accept_channel_v2(&self, their_node_id: &PublicKey, msg: &AcceptChannelV2);
        /// Handle an incoming `funding_created` message from the given peer.
        fn handle_funding_created(&self, their_node_id: &PublicKey, msg: &FundingCreated);
        /// Handle an incoming `funding_signed` message from the given peer.
@@ -969,6 +1256,26 @@ pub trait ChannelMessageHandler : MessageSendEventsProvider {
        /// Handle an incoming `closing_signed` message from the given peer.
        fn handle_closing_signed(&self, their_node_id: &PublicKey, msg: &ClosingSigned);
 
+       // Interactive channel construction
+       /// Handle an incoming `tx_add_input message` from the given peer.
+       fn handle_tx_add_input(&self, their_node_id: &PublicKey, msg: &TxAddInput);
+       /// Handle an incoming `tx_add_output` message from the given peer.
+       fn handle_tx_add_output(&self, their_node_id: &PublicKey, msg: &TxAddOutput);
+       /// Handle an incoming `tx_remove_input` message from the given peer.
+       fn handle_tx_remove_input(&self, their_node_id: &PublicKey, msg: &TxRemoveInput);
+       /// Handle an incoming `tx_remove_output` message from the given peer.
+       fn handle_tx_remove_output(&self, their_node_id: &PublicKey, msg: &TxRemoveOutput);
+       /// Handle an incoming `tx_complete message` from the given peer.
+       fn handle_tx_complete(&self, their_node_id: &PublicKey, msg: &TxComplete);
+       /// Handle an incoming `tx_signatures` message from the given peer.
+       fn handle_tx_signatures(&self, their_node_id: &PublicKey, msg: &TxSignatures);
+       /// Handle an incoming `tx_init_rbf` message from the given peer.
+       fn handle_tx_init_rbf(&self, their_node_id: &PublicKey, msg: &TxInitRbf);
+       /// Handle an incoming `tx_ack_rbf` message from the given peer.
+       fn handle_tx_ack_rbf(&self, their_node_id: &PublicKey, msg: &TxAckRbf);
+       /// Handle an incoming `tx_abort message` from the given peer.
+       fn handle_tx_abort(&self, their_node_id: &PublicKey, msg: &TxAbort);
+
        // HTLC handling:
        /// Handle an incoming `update_add_htlc` message from the given peer.
        fn handle_update_add_htlc(&self, their_node_id: &PublicKey, msg: &UpdateAddHTLC);
@@ -1284,6 +1591,82 @@ impl_writeable_msg!(AcceptChannel, {
        (4, next_local_nonce, option),
 });
 
+impl_writeable_msg!(AcceptChannelV2, {
+       temporary_channel_id,
+       funding_satoshis,
+       dust_limit_satoshis,
+       max_htlc_value_in_flight_msat,
+       htlc_minimum_msat,
+       minimum_depth,
+       to_self_delay,
+       max_accepted_htlcs,
+       funding_pubkey,
+       revocation_basepoint,
+       payment_basepoint,
+       delayed_payment_basepoint,
+       htlc_basepoint,
+       first_per_commitment_point,
+       second_per_commitment_point,
+}, {
+       (0, shutdown_scriptpubkey, option),
+       (1, channel_type, option),
+       (2, require_confirmed_inputs, option),
+});
+
+impl_writeable_msg!(TxAddInput, {
+       channel_id,
+       serial_id,
+       prevtx,
+       prevtx_out,
+       sequence,
+}, {});
+
+impl_writeable_msg!(TxAddOutput, {
+       channel_id,
+       serial_id,
+       sats,
+       script,
+}, {});
+
+impl_writeable_msg!(TxRemoveInput, {
+       channel_id,
+       serial_id,
+}, {});
+
+impl_writeable_msg!(TxRemoveOutput, {
+       channel_id,
+       serial_id,
+}, {});
+
+impl_writeable_msg!(TxComplete, {
+       channel_id,
+}, {});
+
+impl_writeable_msg!(TxSignatures, {
+       channel_id,
+       tx_hash,
+       witnesses,
+}, {});
+
+impl_writeable_msg!(TxInitRbf, {
+       channel_id,
+       locktime,
+       feerate_sat_per_1000_weight,
+}, {
+       (0, funding_output_contribution, option),
+});
+
+impl_writeable_msg!(TxAckRbf, {
+       channel_id,
+}, {
+       (0, funding_output_contribution, option),
+});
+
+impl_writeable_msg!(TxAbort, {
+       channel_id,
+       data,
+}, {});
+
 impl_writeable_msg!(AnnouncementSignatures, {
        channel_id,
        short_channel_id,
@@ -1297,7 +1680,9 @@ impl_writeable_msg!(ChannelReestablish, {
        next_remote_commitment_number,
        your_last_per_commitment_secret,
        my_current_per_commitment_point,
-}, {});
+}, {
+       (0, next_funding_txid, option),
+});
 
 impl_writeable_msg!(ClosingSigned,
        { channel_id, fee_satoshis, signature },
@@ -1422,6 +1807,32 @@ impl_writeable_msg!(OpenChannel, {
        (1, channel_type, option),
 });
 
+impl_writeable_msg!(OpenChannelV2, {
+       chain_hash,
+       temporary_channel_id,
+       funding_feerate_sat_per_1000_weight,
+       commitment_feerate_sat_per_1000_weight,
+       funding_satoshis,
+       dust_limit_satoshis,
+       max_htlc_value_in_flight_msat,
+       htlc_minimum_msat,
+       to_self_delay,
+       max_accepted_htlcs,
+       locktime,
+       funding_pubkey,
+       revocation_basepoint,
+       payment_basepoint,
+       delayed_payment_basepoint,
+       htlc_basepoint,
+       first_per_commitment_point,
+       second_per_commitment_point,
+       channel_flags,
+}, {
+       (0, shutdown_scriptpubkey, option),
+       (1, channel_type, option),
+       (2, require_confirmed_inputs, option),
+});
+
 #[cfg(not(taproot))]
 impl_writeable_msg!(RevokeAndACK, {
        channel_id,
@@ -2039,10 +2450,11 @@ impl_writeable_msg!(GossipTimestampFilter, {
 
 #[cfg(test)]
 mod tests {
+       use bitcoin::{Transaction, PackedLockTime, TxIn, Script, Sequence, Witness, TxOut};
        use hex;
        use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret};
        use crate::ln::features::{ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
-       use crate::ln::msgs;
+       use crate::ln::msgs::{self, TransactionU16LenLimited};
        use crate::ln::msgs::{FinalOnionHopData, OnionErrorPacket, OnionHopDataFormat};
        use crate::routing::gossip::{NodeAlias, NodeId};
        use crate::util::ser::{Writeable, Readable, Hostname};
@@ -2060,6 +2472,9 @@ mod tests {
        use crate::io::{self, Cursor};
        use crate::prelude::*;
        use core::convert::TryFrom;
+       use core::str::FromStr;
+
+       use crate::chain::transaction::OutPoint;
 
        #[test]
        fn encoding_channel_reestablish() {
@@ -2074,12 +2489,53 @@ mod tests {
                        next_remote_commitment_number: 4,
                        your_last_per_commitment_secret: [9;32],
                        my_current_per_commitment_point: public_key,
+                       next_funding_txid: None,
+               };
+
+               let encoded_value = cr.encode();
+               assert_eq!(
+                       encoded_value,
+                       vec![
+                               4, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, // channel_id
+                               0, 0, 0, 0, 0, 0, 0, 3, // next_local_commitment_number
+                               0, 0, 0, 0, 0, 0, 0, 4, // next_remote_commitment_number
+                               9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, // your_last_per_commitment_secret
+                               3, 27, 132, 197, 86, 123, 18, 100, 64, 153, 93, 62, 213, 170, 186, 5, 101, 215, 30, 24, 52, 96, 72, 25, 255, 156, 23, 245, 233, 213, 221, 7, 143, // my_current_per_commitment_point
+                       ]
+               );
+       }
+
+       #[test]
+       fn encoding_channel_reestablish_with_next_funding_txid() {
+               let public_key = {
+                       let secp_ctx = Secp256k1::new();
+                       PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&hex::decode("0101010101010101010101010101010101010101010101010101010101010101").unwrap()[..]).unwrap())
+               };
+
+               let cr = msgs::ChannelReestablish {
+                       channel_id: [4, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0],
+                       next_local_commitment_number: 3,
+                       next_remote_commitment_number: 4,
+                       your_last_per_commitment_secret: [9;32],
+                       my_current_per_commitment_point: public_key,
+                       next_funding_txid: Some(Txid::from_hash(bitcoin::hashes::Hash::from_slice(&[
+                               48, 167, 250, 69, 152, 48, 103, 172, 164, 99, 59, 19, 23, 11, 92, 84, 15, 80, 4, 12, 98, 82, 75, 31, 201, 11, 91, 23, 98, 23, 53, 124,
+                       ]).unwrap())),
                };
 
                let encoded_value = cr.encode();
                assert_eq!(
                        encoded_value,
-                       vec![4, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 3, 27, 132, 197, 86, 123, 18, 100, 64, 153, 93, 62, 213, 170, 186, 5, 101, 215, 30, 24, 52, 96, 72, 25, 255, 156, 23, 245, 233, 213, 221, 7, 143]
+                       vec![
+                               4, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, // channel_id
+                               0, 0, 0, 0, 0, 0, 0, 3, // next_local_commitment_number
+                               0, 0, 0, 0, 0, 0, 0, 4, // next_remote_commitment_number
+                               9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, // your_last_per_commitment_secret
+                               3, 27, 132, 197, 86, 123, 18, 100, 64, 153, 93, 62, 213, 170, 186, 5, 101, 215, 30, 24, 52, 96, 72, 25, 255, 156, 23, 245, 233, 213, 221, 7, 143, // my_current_per_commitment_point
+                               0, // Type (next_funding_txid)
+                               32, // Length
+                               48, 167, 250, 69, 152, 48, 103, 172, 164, 99, 59, 19, 23, 11, 92, 84, 15, 80, 4, 12, 98, 82, 75, 31, 201, 11, 91, 23, 98, 23, 53, 124, // Value
+                       ]
                );
        }
 
@@ -2395,6 +2851,98 @@ mod tests {
                do_encoding_open_channel(true, true, true);
        }
 
+       fn do_encoding_open_channelv2(random_bit: bool, shutdown: bool, incl_chan_type: bool, require_confirmed_inputs: bool) {
+               let secp_ctx = Secp256k1::new();
+               let (_, pubkey_1) = get_keys_from!("0101010101010101010101010101010101010101010101010101010101010101", secp_ctx);
+               let (_, pubkey_2) = get_keys_from!("0202020202020202020202020202020202020202020202020202020202020202", secp_ctx);
+               let (_, pubkey_3) = get_keys_from!("0303030303030303030303030303030303030303030303030303030303030303", secp_ctx);
+               let (_, pubkey_4) = get_keys_from!("0404040404040404040404040404040404040404040404040404040404040404", secp_ctx);
+               let (_, pubkey_5) = get_keys_from!("0505050505050505050505050505050505050505050505050505050505050505", secp_ctx);
+               let (_, pubkey_6) = get_keys_from!("0606060606060606060606060606060606060606060606060606060606060606", secp_ctx);
+               let (_, pubkey_7) = get_keys_from!("0707070707070707070707070707070707070707070707070707070707070707", secp_ctx);
+               let open_channelv2 = msgs::OpenChannelV2 {
+                       chain_hash: BlockHash::from_hex("6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000").unwrap(),
+                       temporary_channel_id: [2; 32],
+                       funding_feerate_sat_per_1000_weight: 821716,
+                       commitment_feerate_sat_per_1000_weight: 821716,
+                       funding_satoshis: 1311768467284833366,
+                       dust_limit_satoshis: 3608586615801332854,
+                       max_htlc_value_in_flight_msat: 8517154655701053848,
+                       htlc_minimum_msat: 2316138423780173,
+                       to_self_delay: 49340,
+                       max_accepted_htlcs: 49340,
+                       locktime: 305419896,
+                       funding_pubkey: pubkey_1,
+                       revocation_basepoint: pubkey_2,
+                       payment_basepoint: pubkey_3,
+                       delayed_payment_basepoint: pubkey_4,
+                       htlc_basepoint: pubkey_5,
+                       first_per_commitment_point: pubkey_6,
+                       second_per_commitment_point: pubkey_7,
+                       channel_flags: if random_bit { 1 << 5 } else { 0 },
+                       shutdown_scriptpubkey: if shutdown { Some(Address::p2pkh(&::bitcoin::PublicKey{compressed: true, inner: pubkey_1}, Network::Testnet).script_pubkey()) } else { None },
+                       channel_type: if incl_chan_type { Some(ChannelTypeFeatures::empty()) } else { None },
+                       require_confirmed_inputs: if require_confirmed_inputs { Some(()) } else { None },
+               };
+               let encoded_value = open_channelv2.encode();
+               let mut target_value = Vec::new();
+               target_value.append(&mut hex::decode("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f").unwrap());
+               target_value.append(&mut hex::decode("0202020202020202020202020202020202020202020202020202020202020202").unwrap());
+               target_value.append(&mut hex::decode("000c89d4").unwrap());
+               target_value.append(&mut hex::decode("000c89d4").unwrap());
+               target_value.append(&mut hex::decode("1234567890123456").unwrap());
+               target_value.append(&mut hex::decode("3214466870114476").unwrap());
+               target_value.append(&mut hex::decode("7633030896203198").unwrap());
+               target_value.append(&mut hex::decode("00083a840000034d").unwrap());
+               target_value.append(&mut hex::decode("c0bc").unwrap());
+               target_value.append(&mut hex::decode("c0bc").unwrap());
+               target_value.append(&mut hex::decode("12345678").unwrap());
+               target_value.append(&mut hex::decode("031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f").unwrap());
+               target_value.append(&mut hex::decode("024d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d0766").unwrap());
+               target_value.append(&mut hex::decode("02531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe337").unwrap());
+               target_value.append(&mut hex::decode("03462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b").unwrap());
+               target_value.append(&mut hex::decode("0362c0a046dacce86ddd0343c6d3c7c79c2208ba0d9c9cf24a6d046d21d21f90f7").unwrap());
+               target_value.append(&mut hex::decode("03f006a18d5653c4edf5391ff23a61f03ff83d237e880ee61187fa9f379a028e0a").unwrap());
+               target_value.append(&mut hex::decode("02989c0b76cb563971fdc9bef31ec06c3560f3249d6ee9e5d83c57625596e05f6f").unwrap());
+
+               if random_bit {
+                       target_value.append(&mut hex::decode("20").unwrap());
+               } else {
+                       target_value.append(&mut hex::decode("00").unwrap());
+               }
+               if shutdown {
+                       target_value.append(&mut hex::decode("001b").unwrap()); // Type 0 + Length 27
+                       target_value.append(&mut hex::decode("001976a91479b000887626b294a914501a4cd226b58b23598388ac").unwrap());
+               }
+               if incl_chan_type {
+                       target_value.append(&mut hex::decode("0100").unwrap());
+               }
+               if require_confirmed_inputs {
+                       target_value.append(&mut hex::decode("0200").unwrap());
+               }
+               assert_eq!(encoded_value, target_value);
+       }
+
+       #[test]
+       fn encoding_open_channelv2() {
+               do_encoding_open_channelv2(false, false, false, false);
+               do_encoding_open_channelv2(false, false, false, true);
+               do_encoding_open_channelv2(false, false, true, false);
+               do_encoding_open_channelv2(false, false, true, true);
+               do_encoding_open_channelv2(false, true, false, false);
+               do_encoding_open_channelv2(false, true, false, true);
+               do_encoding_open_channelv2(false, true, true, false);
+               do_encoding_open_channelv2(false, true, true, true);
+               do_encoding_open_channelv2(true, false, false, false);
+               do_encoding_open_channelv2(true, false, false, true);
+               do_encoding_open_channelv2(true, false, true, false);
+               do_encoding_open_channelv2(true, false, true, true);
+               do_encoding_open_channelv2(true, true, false, false);
+               do_encoding_open_channelv2(true, true, false, true);
+               do_encoding_open_channelv2(true, true, true, false);
+               do_encoding_open_channelv2(true, true, true, true);
+       }
+
        fn do_encoding_accept_channel(shutdown: bool) {
                let secp_ctx = Secp256k1::new();
                let (_, pubkey_1) = get_keys_from!("0101010101010101010101010101010101010101010101010101010101010101", secp_ctx);
@@ -2437,6 +2985,64 @@ mod tests {
                do_encoding_accept_channel(true);
        }
 
+       fn do_encoding_accept_channelv2(shutdown: bool) {
+               let secp_ctx = Secp256k1::new();
+               let (_, pubkey_1) = get_keys_from!("0101010101010101010101010101010101010101010101010101010101010101", secp_ctx);
+               let (_, pubkey_2) = get_keys_from!("0202020202020202020202020202020202020202020202020202020202020202", secp_ctx);
+               let (_, pubkey_3) = get_keys_from!("0303030303030303030303030303030303030303030303030303030303030303", secp_ctx);
+               let (_, pubkey_4) = get_keys_from!("0404040404040404040404040404040404040404040404040404040404040404", secp_ctx);
+               let (_, pubkey_5) = get_keys_from!("0505050505050505050505050505050505050505050505050505050505050505", secp_ctx);
+               let (_, pubkey_6) = get_keys_from!("0606060606060606060606060606060606060606060606060606060606060606", secp_ctx);
+               let (_, pubkey_7) = get_keys_from!("0707070707070707070707070707070707070707070707070707070707070707", secp_ctx);
+               let accept_channelv2 = msgs::AcceptChannelV2 {
+                       temporary_channel_id: [2; 32],
+                       funding_satoshis: 1311768467284833366,
+                       dust_limit_satoshis: 1311768467284833366,
+                       max_htlc_value_in_flight_msat: 2536655962884945560,
+                       htlc_minimum_msat: 2316138423780173,
+                       minimum_depth: 821716,
+                       to_self_delay: 49340,
+                       max_accepted_htlcs: 49340,
+                       funding_pubkey: pubkey_1,
+                       revocation_basepoint: pubkey_2,
+                       payment_basepoint: pubkey_3,
+                       delayed_payment_basepoint: pubkey_4,
+                       htlc_basepoint: pubkey_5,
+                       first_per_commitment_point: pubkey_6,
+                       second_per_commitment_point: pubkey_7,
+                       shutdown_scriptpubkey: if shutdown { Some(Address::p2pkh(&::bitcoin::PublicKey{compressed: true, inner: pubkey_1}, Network::Testnet).script_pubkey()) } else { None },
+                       channel_type: None,
+                       require_confirmed_inputs: None,
+               };
+               let encoded_value = accept_channelv2.encode();
+               let mut target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202").unwrap(); // temporary_channel_id
+               target_value.append(&mut hex::decode("1234567890123456").unwrap()); // funding_satoshis
+               target_value.append(&mut hex::decode("1234567890123456").unwrap()); // dust_limit_satoshis
+               target_value.append(&mut hex::decode("2334032891223698").unwrap()); // max_htlc_value_in_flight_msat
+               target_value.append(&mut hex::decode("00083a840000034d").unwrap()); // htlc_minimum_msat
+               target_value.append(&mut hex::decode("000c89d4").unwrap()); //  minimum_depth
+               target_value.append(&mut hex::decode("c0bc").unwrap()); // to_self_delay
+               target_value.append(&mut hex::decode("c0bc").unwrap()); // max_accepted_htlcs
+               target_value.append(&mut hex::decode("031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f").unwrap()); // funding_pubkey
+               target_value.append(&mut hex::decode("024d4b6cd1361032ca9bd2aeb9d900aa4d45d9ead80ac9423374c451a7254d0766").unwrap()); // revocation_basepoint
+               target_value.append(&mut hex::decode("02531fe6068134503d2723133227c867ac8fa6c83c537e9a44c3c5bdbdcb1fe337").unwrap()); // payment_basepoint
+               target_value.append(&mut hex::decode("03462779ad4aad39514614751a71085f2f10e1c7a593e4e030efb5b8721ce55b0b").unwrap()); // delayed_payment_basepoint
+               target_value.append(&mut hex::decode("0362c0a046dacce86ddd0343c6d3c7c79c2208ba0d9c9cf24a6d046d21d21f90f7").unwrap()); // htlc_basepoint
+               target_value.append(&mut hex::decode("03f006a18d5653c4edf5391ff23a61f03ff83d237e880ee61187fa9f379a028e0a").unwrap()); // first_per_commitment_point
+               target_value.append(&mut hex::decode("02989c0b76cb563971fdc9bef31ec06c3560f3249d6ee9e5d83c57625596e05f6f").unwrap()); // second_per_commitment_point
+               if shutdown {
+                       target_value.append(&mut hex::decode("001b").unwrap()); // Type 0 + Length 27
+                       target_value.append(&mut hex::decode("001976a91479b000887626b294a914501a4cd226b58b23598388ac").unwrap());
+               }
+               assert_eq!(encoded_value, target_value);
+       }
+
+       #[test]
+       fn encoding_accept_channelv2() {
+               do_encoding_accept_channelv2(false);
+               do_encoding_accept_channelv2(true);
+       }
+
        #[test]
        fn encoding_funding_created() {
                let secp_ctx = Secp256k1::new();
@@ -2487,6 +3093,180 @@ mod tests {
                assert_eq!(encoded_value, target_value);
        }
 
+       #[test]
+       fn encoding_tx_add_input() {
+               let tx_add_input = msgs::TxAddInput {
+                       channel_id: [2; 32],
+                       serial_id: 4886718345,
+                       prevtx: TransactionU16LenLimited::new(Transaction {
+                               version: 2,
+                               lock_time: PackedLockTime(0),
+                               input: vec![TxIn {
+                                       previous_output: OutPoint { txid: Txid::from_hex("305bab643ee297b8b6b76b320792c8223d55082122cb606bf89382146ced9c77").unwrap(), index: 2 }.into_bitcoin_outpoint(),
+                                       script_sig: Script::new(),
+                                       sequence: Sequence(0xfffffffd),
+                                       witness: Witness::from_vec(vec![
+                                               hex::decode("304402206af85b7dd67450ad12c979302fac49dfacbc6a8620f49c5da2b5721cf9565ca502207002b32fed9ce1bf095f57aeb10c36928ac60b12e723d97d2964a54640ceefa701").unwrap(),
+                                               hex::decode("0301ab7dc16488303549bfcdd80f6ae5ee4c20bf97ab5410bbd6b1bfa85dcd6944").unwrap()]),
+                               }],
+                               output: vec![
+                                       TxOut {
+                                               value: 12704566,
+                                               script_pubkey: Address::from_str("bc1qzlffunw52jav8vwdu5x3jfk6sr8u22rmq3xzw2").unwrap().script_pubkey(),
+                                       },
+                                       TxOut {
+                                               value: 245148,
+                                               script_pubkey: Address::from_str("bc1qxmk834g5marzm227dgqvynd23y2nvt2ztwcw2z").unwrap().script_pubkey(),
+                                       },
+                               ],
+                       }).unwrap(),
+                       prevtx_out: 305419896,
+                       sequence: 305419896,
+               };
+               let encoded_value = tx_add_input.encode();
+               let target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202000000012345678900de02000000000101779ced6c148293f86b60cb222108553d22c89207326bb7b6b897e23e64ab5b300200000000fdffffff0236dbc1000000000016001417d29e4dd454bac3b1cde50d1926da80cfc5287b9cbd03000000000016001436ec78d514df462da95e6a00c24daa8915362d420247304402206af85b7dd67450ad12c979302fac49dfacbc6a8620f49c5da2b5721cf9565ca502207002b32fed9ce1bf095f57aeb10c36928ac60b12e723d97d2964a54640ceefa701210301ab7dc16488303549bfcdd80f6ae5ee4c20bf97ab5410bbd6b1bfa85dcd6944000000001234567812345678").unwrap();
+               assert_eq!(encoded_value, target_value);
+       }
+
+       #[test]
+       fn encoding_tx_add_output() {
+               let tx_add_output = msgs::TxAddOutput {
+                       channel_id: [2; 32],
+                       serial_id: 4886718345,
+                       sats: 4886718345,
+                       script: Address::from_str("bc1qxmk834g5marzm227dgqvynd23y2nvt2ztwcw2z").unwrap().script_pubkey(),
+               };
+               let encoded_value = tx_add_output.encode();
+               let target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202000000012345678900000001234567890016001436ec78d514df462da95e6a00c24daa8915362d42").unwrap();
+               assert_eq!(encoded_value, target_value);
+       }
+
+       #[test]
+       fn encoding_tx_remove_input() {
+               let tx_remove_input = msgs::TxRemoveInput {
+                       channel_id: [2; 32],
+                       serial_id: 4886718345,
+               };
+               let encoded_value = tx_remove_input.encode();
+               let target_value = hex::decode("02020202020202020202020202020202020202020202020202020202020202020000000123456789").unwrap();
+               assert_eq!(encoded_value, target_value);
+       }
+
+       #[test]
+       fn encoding_tx_remove_output() {
+               let tx_remove_output = msgs::TxRemoveOutput {
+                       channel_id: [2; 32],
+                       serial_id: 4886718345,
+               };
+               let encoded_value = tx_remove_output.encode();
+               let target_value = hex::decode("02020202020202020202020202020202020202020202020202020202020202020000000123456789").unwrap();
+               assert_eq!(encoded_value, target_value);
+       }
+
+       #[test]
+       fn encoding_tx_complete() {
+               let tx_complete = msgs::TxComplete {
+                       channel_id: [2; 32],
+               };
+               let encoded_value = tx_complete.encode();
+               let target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202").unwrap();
+               assert_eq!(encoded_value, target_value);
+       }
+
+       #[test]
+       fn encoding_tx_signatures() {
+               let tx_signatures = msgs::TxSignatures {
+                       channel_id: [2; 32],
+                       tx_hash: Txid::from_hex("c2d4449afa8d26140898dd54d3390b057ba2a5afcf03ba29d7dc0d8b9ffe966e").unwrap(),
+                       witnesses: vec![
+                               Witness::from_vec(vec![
+                                       hex::decode("304402206af85b7dd67450ad12c979302fac49dfacbc6a8620f49c5da2b5721cf9565ca502207002b32fed9ce1bf095f57aeb10c36928ac60b12e723d97d2964a54640ceefa701").unwrap(),
+                                       hex::decode("0301ab7dc16488303549bfcdd80f6ae5ee4c20bf97ab5410bbd6b1bfa85dcd6944").unwrap()]),
+                               Witness::from_vec(vec![
+                                       hex::decode("3045022100ee00dbf4a862463e837d7c08509de814d620e4d9830fa84818713e0fa358f145022021c3c7060c4d53fe84fd165d60208451108a778c13b92ca4c6bad439236126cc01").unwrap(),
+                                       hex::decode("028fbbf0b16f5ba5bcb5dd37cd4047ce6f726a21c06682f9ec2f52b057de1dbdb5").unwrap()]),
+                       ],
+               };
+               let encoded_value = tx_signatures.encode();
+               let mut target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202").unwrap(); // channel_id
+               target_value.append(&mut hex::decode("6e96fe9f8b0ddcd729ba03cfafa5a27b050b39d354dd980814268dfa9a44d4c2").unwrap()); // tx_hash (sha256) (big endian byte order)
+               target_value.append(&mut hex::decode("0002").unwrap()); // num_witnesses (u16)
+               // Witness 1
+               target_value.append(&mut hex::decode("006b").unwrap()); // len of witness_data
+               target_value.append(&mut hex::decode("02").unwrap()); // num_witness_elements (VarInt)
+               target_value.append(&mut hex::decode("47").unwrap()); // len of witness element data (VarInt)
+               target_value.append(&mut hex::decode("304402206af85b7dd67450ad12c979302fac49dfacbc6a8620f49c5da2b5721cf9565ca502207002b32fed9ce1bf095f57aeb10c36928ac60b12e723d97d2964a54640ceefa701").unwrap());
+               target_value.append(&mut hex::decode("21").unwrap()); // len of witness element data (VarInt)
+               target_value.append(&mut hex::decode("0301ab7dc16488303549bfcdd80f6ae5ee4c20bf97ab5410bbd6b1bfa85dcd6944").unwrap());
+               // Witness 2
+               target_value.append(&mut hex::decode("006c").unwrap()); // len of witness_data
+               target_value.append(&mut hex::decode("02").unwrap()); // num_witness_elements (VarInt)
+               target_value.append(&mut hex::decode("48").unwrap()); // len of witness element data (VarInt)
+               target_value.append(&mut hex::decode("3045022100ee00dbf4a862463e837d7c08509de814d620e4d9830fa84818713e0fa358f145022021c3c7060c4d53fe84fd165d60208451108a778c13b92ca4c6bad439236126cc01").unwrap());
+               target_value.append(&mut hex::decode("21").unwrap()); // len of witness element data (VarInt)
+               target_value.append(&mut hex::decode("028fbbf0b16f5ba5bcb5dd37cd4047ce6f726a21c06682f9ec2f52b057de1dbdb5").unwrap());
+               assert_eq!(encoded_value, target_value);
+       }
+
+       fn do_encoding_tx_init_rbf(funding_value_with_hex_target: Option<(i64, &str)>) {
+               let tx_init_rbf = msgs::TxInitRbf {
+                       channel_id: [2; 32],
+                       locktime: 305419896,
+                       feerate_sat_per_1000_weight: 20190119,
+                       funding_output_contribution: if let Some((value, _)) = funding_value_with_hex_target { Some(value) } else { None },
+               };
+               let encoded_value = tx_init_rbf.encode();
+               let mut target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202").unwrap(); // channel_id
+               target_value.append(&mut hex::decode("12345678").unwrap()); // locktime
+               target_value.append(&mut hex::decode("013413a7").unwrap()); // feerate_sat_per_1000_weight
+               if let Some((_, target)) = funding_value_with_hex_target {
+                       target_value.push(0x00); // Type
+                       target_value.push(target.len() as u8 / 2); // Length
+                       target_value.append(&mut hex::decode(target).unwrap()); // Value (i64)
+               }
+               assert_eq!(encoded_value, target_value);
+       }
+
+       #[test]
+       fn encoding_tx_init_rbf() {
+               do_encoding_tx_init_rbf(Some((1311768467284833366, "1234567890123456")));
+               do_encoding_tx_init_rbf(Some((13117684672, "000000030DDFFBC0")));
+               do_encoding_tx_init_rbf(None);
+       }
+
+       fn do_encoding_tx_ack_rbf(funding_value_with_hex_target: Option<(i64, &str)>) {
+               let tx_ack_rbf = msgs::TxAckRbf {
+                       channel_id: [2; 32],
+                       funding_output_contribution: if let Some((value, _)) = funding_value_with_hex_target { Some(value) } else { None },
+               };
+               let encoded_value = tx_ack_rbf.encode();
+               let mut target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202").unwrap();
+               if let Some((_, target)) = funding_value_with_hex_target {
+                       target_value.push(0x00); // Type
+                       target_value.push(target.len() as u8 / 2); // Length
+                       target_value.append(&mut hex::decode(target).unwrap()); // Value (i64)
+               }
+               assert_eq!(encoded_value, target_value);
+       }
+
+       #[test]
+       fn encoding_tx_ack_rbf() {
+               do_encoding_tx_ack_rbf(Some((1311768467284833366, "1234567890123456")));
+               do_encoding_tx_ack_rbf(Some((13117684672, "000000030DDFFBC0")));
+               do_encoding_tx_ack_rbf(None);
+       }
+
+       #[test]
+       fn encoding_tx_abort() {
+               let tx_abort = msgs::TxAbort {
+                       channel_id: [2; 32],
+                       data: hex::decode("54686520717569636B2062726F776E20666F78206A756D7073206F76657220746865206C617A7920646F672E").unwrap(),
+               };
+               let encoded_value = tx_abort.encode();
+               let target_value = hex::decode("0202020202020202020202020202020202020202020202020202020202020202002C54686520717569636B2062726F776E20666F78206A756D7073206F76657220746865206C617A7920646F672E").unwrap();
+               assert_eq!(encoded_value, target_value);
+       }
+
        fn do_encoding_shutdown(script_type: u8) {
                let secp_ctx = Secp256k1::new();
                let (_, pubkey_1) = get_keys_from!("0101010101010101010101010101010101010101010101010101010101010101", secp_ctx);
index d186f4d725fbafcf990ac697f4bf765f5e367c9a..86bf8bdc3fabda830931ea61f26d74644ae88ca5 100644 (file)
@@ -714,8 +714,8 @@ fn do_test_onion_failure_stale_channel_update(announced_channel: bool) {
                        htlc_minimum_msat: None,
                }])];
                let payment_params = PaymentParameters::from_node_id(*channel_to_update_counterparty, TEST_FINAL_CLTV)
-                       .with_features(nodes[2].node.invoice_features())
-                       .with_route_hints(hop_hints);
+                       .with_bolt11_features(nodes[2].node.invoice_features()).unwrap()
+                       .with_route_hints(hop_hints).unwrap();
                get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, PAYMENT_AMT)
        };
        send_along_route_with_secret(&nodes[0], route.clone(), &[&[&nodes[1], &nodes[2]]], PAYMENT_AMT,
@@ -861,7 +861,7 @@ fn test_always_create_tlv_format_onion_payloads() {
        create_announced_chan_between_nodes(&nodes, 1, 2);
 
        let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV)
-               .with_features(InvoiceFeatures::empty());
+               .with_bolt11_features(InvoiceFeatures::empty()).unwrap();
        let (route, _payment_hash, _payment_preimage, _payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, 40000);
 
        let hops = &route.paths[0].hops;
@@ -963,7 +963,7 @@ macro_rules! get_phantom_route {
                let phantom_pubkey = $nodes[1].keys_manager.get_node_id(Recipient::PhantomNode).unwrap();
                let phantom_route_hint = $nodes[1].node.get_phantom_route_hints();
                let payment_params = PaymentParameters::from_node_id(phantom_pubkey, TEST_FINAL_CLTV)
-                       .with_features($nodes[1].node.invoice_features())
+                       .with_bolt11_features($nodes[1].node.invoice_features()).unwrap()
                        .with_route_hints(vec![RouteHint(vec![
                                        RouteHintHop {
                                                src_node_id: $nodes[0].node.get_our_node_id(),
@@ -987,7 +987,7 @@ macro_rules! get_phantom_route {
                                                htlc_minimum_msat: None,
                                                htlc_maximum_msat: None,
                                        }
-               ])]);
+               ])]).unwrap();
                let scorer = test_utils::TestScorer::new();
                let network_graph = $nodes[0].network_graph.read_only();
                (get_route(
index 569e664bad18302ec9cc801ef401874da9d7f2e4..f107f3b558395fe7ea9da8f8a8194f8f52a9f634 100644 (file)
@@ -60,6 +60,7 @@ pub(crate) enum PendingOutboundPayment {
        /// and add a pending payment that was already fulfilled.
        Fulfilled {
                session_privs: HashSet<[u8; 32]>,
+               /// Filled in for any payment which moved to `Fulfilled` on LDK 0.0.104 or later.
                payment_hash: Option<PaymentHash>,
                timer_ticks_without_htlcs: u8,
        },
@@ -1168,9 +1169,11 @@ impl OutboundPayments {
                                if let hash_map::Entry::Occupied(mut payment) = outbounds.entry(payment_id) {
                                        assert!(payment.get().is_fulfilled());
                                        if payment.get_mut().remove(&session_priv_bytes, None) {
+                                               let payment_hash = payment.get().payment_hash();
+                                               debug_assert!(payment_hash.is_some());
                                                pending_events.push_back((events::Event::PaymentPathSuccessful {
                                                        payment_id,
-                                                       payment_hash: payment.get().payment_hash(),
+                                                       payment_hash,
                                                        path,
                                                }, None));
                                        }
index 0cdc2c9153f634953b83b217067002ecc711e306..ba7da5d5e6b5b184a500d430ef494f43a7135ba2 100644 (file)
@@ -857,7 +857,7 @@ fn get_ldk_payment_preimage() {
        let (payment_hash, payment_secret) = nodes[1].node.create_inbound_payment(Some(amt_msat), expiry_secs, None).unwrap();
 
        let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV)
-               .with_features(nodes[1].node.invoice_features());
+               .with_bolt11_features(nodes[1].node.invoice_features()).unwrap();
        let scorer = test_utils::TestScorer::new();
        let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
        let random_seed_bytes = keys_manager.get_secure_random_bytes();
@@ -1409,8 +1409,8 @@ fn do_test_intercepted_payment(test: InterceptTest) {
                                htlc_minimum_msat: None,
                                htlc_maximum_msat: None,
                        }])
-               ])
-               .with_features(nodes[2].node.invoice_features());
+               ]).unwrap()
+               .with_bolt11_features(nodes[2].node.invoice_features()).unwrap();
        let route_params = RouteParameters {
                payment_params,
                final_value_msat: amt_msat,
@@ -1600,7 +1600,7 @@ fn do_automatic_retries(test: AutoRetry) {
        invoice_features.set_basic_mpp_optional();
        let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV)
                .with_expiry_time(payment_expiry_secs as u64)
-               .with_features(invoice_features);
+               .with_bolt11_features(invoice_features).unwrap();
        let route_params = RouteParameters {
                payment_params,
                final_value_msat: amt_msat,
@@ -1819,7 +1819,7 @@ fn auto_retry_partial_failure() {
        invoice_features.set_basic_mpp_optional();
        let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV)
                .with_expiry_time(payment_expiry_secs as u64)
-               .with_features(invoice_features);
+               .with_bolt11_features(invoice_features).unwrap();
        let route_params = RouteParameters {
                payment_params,
                final_value_msat: amt_msat,
@@ -2031,7 +2031,7 @@ fn auto_retry_zero_attempts_send_error() {
        invoice_features.set_basic_mpp_optional();
        let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV)
                .with_expiry_time(payment_expiry_secs as u64)
-               .with_features(invoice_features);
+               .with_bolt11_features(invoice_features).unwrap();
        let route_params = RouteParameters {
                payment_params,
                final_value_msat: amt_msat,
@@ -2071,7 +2071,7 @@ fn fails_paying_after_rejected_by_payee() {
        invoice_features.set_basic_mpp_optional();
        let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV)
                .with_expiry_time(payment_expiry_secs as u64)
-               .with_features(invoice_features);
+               .with_bolt11_features(invoice_features).unwrap();
        let route_params = RouteParameters {
                payment_params,
                final_value_msat: amt_msat,
@@ -2118,7 +2118,7 @@ fn retry_multi_path_single_failed_payment() {
        invoice_features.set_basic_mpp_optional();
        let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV)
                .with_expiry_time(payment_expiry_secs as u64)
-               .with_features(invoice_features);
+               .with_bolt11_features(invoice_features).unwrap();
        let route_params = RouteParameters {
                payment_params: payment_params.clone(),
                final_value_msat: amt_msat,
@@ -2212,7 +2212,7 @@ fn immediate_retry_on_failure() {
        invoice_features.set_basic_mpp_optional();
        let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV)
                .with_expiry_time(payment_expiry_secs as u64)
-               .with_features(invoice_features);
+               .with_bolt11_features(invoice_features).unwrap();
        let route_params = RouteParameters {
                payment_params,
                final_value_msat: amt_msat,
@@ -2301,7 +2301,7 @@ fn no_extra_retries_on_back_to_back_fail() {
        invoice_features.set_basic_mpp_optional();
        let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV)
                .with_expiry_time(payment_expiry_secs as u64)
-               .with_features(invoice_features);
+               .with_bolt11_features(invoice_features).unwrap();
        let route_params = RouteParameters {
                payment_params,
                final_value_msat: amt_msat,
@@ -2503,7 +2503,7 @@ fn test_simple_partial_retry() {
        invoice_features.set_basic_mpp_optional();
        let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV)
                .with_expiry_time(payment_expiry_secs as u64)
-               .with_features(invoice_features);
+               .with_bolt11_features(invoice_features).unwrap();
        let route_params = RouteParameters {
                payment_params,
                final_value_msat: amt_msat,
@@ -2669,7 +2669,7 @@ fn test_threaded_payment_retries() {
        invoice_features.set_basic_mpp_optional();
        let payment_params = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV)
                .with_expiry_time(payment_expiry_secs as u64)
-               .with_features(invoice_features);
+               .with_bolt11_features(invoice_features).unwrap();
        let mut route_params = RouteParameters {
                payment_params,
                final_value_msat: amt_msat,
@@ -2906,7 +2906,7 @@ fn do_claim_from_closed_chan(fail_payment: bool) {
        let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[3]);
        let mut route_params = RouteParameters {
                payment_params: PaymentParameters::from_node_id(nodes[3].node.get_our_node_id(), TEST_FINAL_CLTV)
-                       .with_features(nodes[1].node.invoice_features()),
+                       .with_bolt11_features(nodes[1].node.invoice_features()).unwrap(),
                final_value_msat: 10_000_000,
        };
        let mut route = nodes[0].router.find_route(&nodes[0].node.get_our_node_id(), &route_params,
@@ -3050,7 +3050,7 @@ fn do_test_payment_metadata_consistency(do_reload: bool, do_modify: bool) {
        let payment_metadata = vec![44, 49, 52, 142];
 
        let payment_params = PaymentParameters::from_node_id(nodes[3].node.get_our_node_id(), TEST_FINAL_CLTV)
-               .with_features(nodes[1].node.invoice_features());
+               .with_bolt11_features(nodes[1].node.invoice_features()).unwrap();
        let mut route_params = RouteParameters {
                payment_params,
                final_value_msat: amt_msat,
index 046bbad923541a9138245706c2dca626da9f3576..0659412f774190ba7adee5ab599d3c4e0174cbb0 100644 (file)
@@ -252,7 +252,52 @@ impl ChannelMessageHandler for ErroringMessageHandler {
                features.set_zero_conf_optional();
                features
        }
+
+       fn handle_open_channel_v2(&self, their_node_id: &PublicKey, msg: &msgs::OpenChannelV2) {
+               ErroringMessageHandler::push_error(self, their_node_id, msg.temporary_channel_id);
+       }
+
+       fn handle_accept_channel_v2(&self, their_node_id: &PublicKey, msg: &msgs::AcceptChannelV2) {
+               ErroringMessageHandler::push_error(self, their_node_id, msg.temporary_channel_id);
+       }
+
+       fn handle_tx_add_input(&self, their_node_id: &PublicKey, msg: &msgs::TxAddInput) {
+               ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id);
+       }
+
+       fn handle_tx_add_output(&self, their_node_id: &PublicKey, msg: &msgs::TxAddOutput) {
+               ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id);
+       }
+
+       fn handle_tx_remove_input(&self, their_node_id: &PublicKey, msg: &msgs::TxRemoveInput) {
+               ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id);
+       }
+
+       fn handle_tx_remove_output(&self, their_node_id: &PublicKey, msg: &msgs::TxRemoveOutput) {
+               ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id);
+       }
+
+       fn handle_tx_complete(&self, their_node_id: &PublicKey, msg: &msgs::TxComplete) {
+               ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id);
+       }
+
+       fn handle_tx_signatures(&self, their_node_id: &PublicKey, msg: &msgs::TxSignatures) {
+               ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id);
+       }
+
+       fn handle_tx_init_rbf(&self, their_node_id: &PublicKey, msg: &msgs::TxInitRbf) {
+               ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id);
+       }
+
+       fn handle_tx_ack_rbf(&self, their_node_id: &PublicKey, msg: &msgs::TxAckRbf) {
+               ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id);
+       }
+
+       fn handle_tx_abort(&self, their_node_id: &PublicKey, msg: &msgs::TxAbort) {
+               ErroringMessageHandler::push_error(self, their_node_id, msg.channel_id);
+       }
 }
+
 impl Deref for ErroringMessageHandler {
        type Target = ErroringMessageHandler;
        fn deref(&self) -> &Self { self }
@@ -1497,9 +1542,15 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
                        wire::Message::OpenChannel(msg) => {
                                self.message_handler.chan_handler.handle_open_channel(&their_node_id, &msg);
                        },
+                       wire::Message::OpenChannelV2(msg) => {
+                               self.message_handler.chan_handler.handle_open_channel_v2(&their_node_id, &msg);
+                       },
                        wire::Message::AcceptChannel(msg) => {
                                self.message_handler.chan_handler.handle_accept_channel(&their_node_id, &msg);
                        },
+                       wire::Message::AcceptChannelV2(msg) => {
+                               self.message_handler.chan_handler.handle_accept_channel_v2(&their_node_id, &msg);
+                       },
 
                        wire::Message::FundingCreated(msg) => {
                                self.message_handler.chan_handler.handle_funding_created(&their_node_id, &msg);
@@ -1511,6 +1562,35 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
                                self.message_handler.chan_handler.handle_channel_ready(&their_node_id, &msg);
                        },
 
+                       // Interactive transaction construction messages:
+                       wire::Message::TxAddInput(msg) => {
+                               self.message_handler.chan_handler.handle_tx_add_input(&their_node_id, &msg);
+                       },
+                       wire::Message::TxAddOutput(msg) => {
+                               self.message_handler.chan_handler.handle_tx_add_output(&their_node_id, &msg);
+                       },
+                       wire::Message::TxRemoveInput(msg) => {
+                               self.message_handler.chan_handler.handle_tx_remove_input(&their_node_id, &msg);
+                       },
+                       wire::Message::TxRemoveOutput(msg) => {
+                               self.message_handler.chan_handler.handle_tx_remove_output(&their_node_id, &msg);
+                       },
+                       wire::Message::TxComplete(msg) => {
+                               self.message_handler.chan_handler.handle_tx_complete(&their_node_id, &msg);
+                       },
+                       wire::Message::TxSignatures(msg) => {
+                               self.message_handler.chan_handler.handle_tx_signatures(&their_node_id, &msg);
+                       },
+                       wire::Message::TxInitRbf(msg) => {
+                               self.message_handler.chan_handler.handle_tx_init_rbf(&their_node_id, &msg);
+                       },
+                       wire::Message::TxAckRbf(msg) => {
+                               self.message_handler.chan_handler.handle_tx_ack_rbf(&their_node_id, &msg);
+                       },
+                       wire::Message::TxAbort(msg) => {
+                               self.message_handler.chan_handler.handle_tx_abort(&their_node_id, &msg);
+                       }
+
                        wire::Message::Shutdown(msg) => {
                                self.message_handler.chan_handler.handle_shutdown(&their_node_id, &msg);
                        },
@@ -1776,12 +1856,24 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
                                                                log_bytes!(msg.temporary_channel_id));
                                                self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
                                        },
+                                       MessageSendEvent::SendAcceptChannelV2 { ref node_id, ref msg } => {
+                                               log_debug!(self.logger, "Handling SendAcceptChannelV2 event in peer_handler for node {} for channel {}",
+                                                               log_pubkey!(node_id),
+                                                               log_bytes!(msg.temporary_channel_id));
+                                               self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
+                                       },
                                        MessageSendEvent::SendOpenChannel { ref node_id, ref msg } => {
                                                log_debug!(self.logger, "Handling SendOpenChannel event in peer_handler for node {} for channel {}",
                                                                log_pubkey!(node_id),
                                                                log_bytes!(msg.temporary_channel_id));
                                                self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
                                        },
+                                       MessageSendEvent::SendOpenChannelV2 { ref node_id, ref msg } => {
+                                               log_debug!(self.logger, "Handling SendOpenChannelV2 event in peer_handler for node {} for channel {}",
+                                                               log_pubkey!(node_id),
+                                                               log_bytes!(msg.temporary_channel_id));
+                                               self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
+                                       },
                                        MessageSendEvent::SendFundingCreated { ref node_id, ref msg } => {
                                                log_debug!(self.logger, "Handling SendFundingCreated event in peer_handler for node {} for channel {} (which becomes {})",
                                                                log_pubkey!(node_id),
@@ -1803,6 +1895,60 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
                                                                log_bytes!(msg.channel_id));
                                                self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
                                        },
+                                       MessageSendEvent::SendTxAddInput { ref node_id, ref msg } => {
+                                               log_debug!(self.logger, "Handling SendTxAddInput event in peer_handler for node {} for channel {}",
+                                                               log_pubkey!(node_id),
+                                                               log_bytes!(msg.channel_id));
+                                               self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
+                                       },
+                                       MessageSendEvent::SendTxAddOutput { ref node_id, ref msg } => {
+                                               log_debug!(self.logger, "Handling SendTxAddOutput event in peer_handler for node {} for channel {}",
+                                                               log_pubkey!(node_id),
+                                                               log_bytes!(msg.channel_id));
+                                               self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
+                                       },
+                                       MessageSendEvent::SendTxRemoveInput { ref node_id, ref msg } => {
+                                               log_debug!(self.logger, "Handling SendTxRemoveInput event in peer_handler for node {} for channel {}",
+                                                               log_pubkey!(node_id),
+                                                               log_bytes!(msg.channel_id));
+                                               self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
+                                       },
+                                       MessageSendEvent::SendTxRemoveOutput { ref node_id, ref msg } => {
+                                               log_debug!(self.logger, "Handling SendTxRemoveOutput event in peer_handler for node {} for channel {}",
+                                                               log_pubkey!(node_id),
+                                                               log_bytes!(msg.channel_id));
+                                               self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
+                                       },
+                                       MessageSendEvent::SendTxComplete { ref node_id, ref msg } => {
+                                               log_debug!(self.logger, "Handling SendTxComplete event in peer_handler for node {} for channel {}",
+                                                               log_pubkey!(node_id),
+                                                               log_bytes!(msg.channel_id));
+                                               self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
+                                       },
+                                       MessageSendEvent::SendTxSignatures { ref node_id, ref msg } => {
+                                               log_debug!(self.logger, "Handling SendTxSignatures event in peer_handler for node {} for channel {}",
+                                                               log_pubkey!(node_id),
+                                                               log_bytes!(msg.channel_id));
+                                               self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
+                                       },
+                                       MessageSendEvent::SendTxInitRbf { ref node_id, ref msg } => {
+                                               log_debug!(self.logger, "Handling SendTxInitRbf event in peer_handler for node {} for channel {}",
+                                                               log_pubkey!(node_id),
+                                                               log_bytes!(msg.channel_id));
+                                               self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
+                                       },
+                                       MessageSendEvent::SendTxAckRbf { ref node_id, ref msg } => {
+                                               log_debug!(self.logger, "Handling SendTxAckRbf event in peer_handler for node {} for channel {}",
+                                                               log_pubkey!(node_id),
+                                                               log_bytes!(msg.channel_id));
+                                               self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
+                                       },
+                                       MessageSendEvent::SendTxAbort { ref node_id, ref msg } => {
+                                               log_debug!(self.logger, "Handling SendTxAbort event in peer_handler for node {} for channel {}",
+                                                               log_pubkey!(node_id),
+                                                               log_bytes!(msg.channel_id));
+                                               self.enqueue_message(&mut *get_peer_for_forwarding!(node_id), msg);
+                                       },
                                        MessageSendEvent::SendAnnouncementSignatures { ref node_id, ref msg } => {
                                                log_debug!(self.logger, "Handling SendAnnouncementSignatures event in peer_handler for node {} for channel {})",
                                                                log_pubkey!(node_id),
index e5049e564c107d1df2d3efaba85bb655c83b6dc9..cfcc46dfedace4a7048341ad495ca437ae9b1122 100644 (file)
@@ -67,8 +67,8 @@ fn test_priv_forwarding_rejection() {
        }]);
        let last_hops = vec![route_hint];
        let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), TEST_FINAL_CLTV)
-               .with_features(nodes[2].node.invoice_features())
-               .with_route_hints(last_hops);
+               .with_bolt11_features(nodes[2].node.invoice_features()).unwrap()
+               .with_route_hints(last_hops).unwrap();
        let (route, our_payment_hash, our_payment_preimage, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, 10_000);
 
        nodes[0].node.send_payment_with_route(&route, our_payment_hash,
@@ -236,8 +236,8 @@ fn test_routed_scid_alias() {
                htlc_minimum_msat: None,
        }])];
        let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), 42)
-               .with_features(nodes[2].node.invoice_features())
-               .with_route_hints(hop_hints);
+               .with_bolt11_features(nodes[2].node.invoice_features()).unwrap()
+               .with_route_hints(hop_hints).unwrap();
        let (route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, 100_000);
        assert_eq!(route.paths[0].hops[1].short_channel_id, last_hop[0].inbound_scid_alias.unwrap());
        nodes[0].node.send_payment_with_route(&route, payment_hash,
@@ -402,8 +402,8 @@ fn test_inbound_scid_privacy() {
                htlc_minimum_msat: None,
        }])];
        let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), 42)
-               .with_features(nodes[2].node.invoice_features())
-               .with_route_hints(hop_hints.clone());
+               .with_bolt11_features(nodes[2].node.invoice_features()).unwrap()
+               .with_route_hints(hop_hints.clone()).unwrap();
        let (route, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, 100_000);
        assert_eq!(route.paths[0].hops[1].short_channel_id, last_hop[0].inbound_scid_alias.unwrap());
        nodes[0].node.send_payment_with_route(&route, payment_hash,
@@ -418,8 +418,8 @@ fn test_inbound_scid_privacy() {
        hop_hints[0].0[0].short_channel_id = last_hop[0].short_channel_id.unwrap();
 
        let payment_params_2 = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), 42)
-               .with_features(nodes[2].node.invoice_features())
-               .with_route_hints(hop_hints);
+               .with_bolt11_features(nodes[2].node.invoice_features()).unwrap()
+               .with_route_hints(hop_hints).unwrap();
        let (route_2, payment_hash_2, _, payment_secret_2) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params_2, 100_000);
        assert_eq!(route_2.paths[0].hops[1].short_channel_id, last_hop[0].short_channel_id.unwrap());
        nodes[0].node.send_payment_with_route(&route_2, payment_hash_2,
@@ -470,8 +470,8 @@ fn test_scid_alias_returned() {
                htlc_minimum_msat: None,
        }])];
        let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id(), 42)
-               .with_features(nodes[2].node.invoice_features())
-               .with_route_hints(hop_hints);
+               .with_bolt11_features(nodes[2].node.invoice_features()).unwrap()
+               .with_route_hints(hop_hints).unwrap();
        let (mut route, payment_hash, _, payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, 10_000);
        assert_eq!(route.paths[0].hops[1].short_channel_id, nodes[2].node.list_usable_channels()[0].inbound_scid_alias.unwrap());
 
index 54648fa661565a8cbbbb25207a8336f69c04b970..81a02f8a4b8c83979941194b56b8f17c5079c02c 100644 (file)
@@ -94,9 +94,9 @@ fn updates_shutdown_wait() {
 
        let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[0]);
 
-       let payment_params_1 = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV).with_features(nodes[1].node.invoice_features());
+       let payment_params_1 = PaymentParameters::from_node_id(nodes[1].node.get_our_node_id(), TEST_FINAL_CLTV).with_bolt11_features(nodes[1].node.invoice_features()).unwrap();
        let route_1 = get_route(&nodes[0].node.get_our_node_id(), &payment_params_1, &nodes[0].network_graph.read_only(), None, 100000, &logger, &scorer, &random_seed_bytes).unwrap();
-       let payment_params_2 = PaymentParameters::from_node_id(nodes[0].node.get_our_node_id(), TEST_FINAL_CLTV).with_features(nodes[0].node.invoice_features());
+       let payment_params_2 = PaymentParameters::from_node_id(nodes[0].node.get_our_node_id(), TEST_FINAL_CLTV).with_bolt11_features(nodes[0].node.invoice_features()).unwrap();
        let route_2 = get_route(&nodes[1].node.get_our_node_id(), &payment_params_2, &nodes[1].network_graph.read_only(), None, 100000, &logger, &scorer, &random_seed_bytes).unwrap();
        unwrap_send_err!(nodes[0].node.send_payment_with_route(&route_1, payment_hash,
                        RecipientOnionFields::secret_only(payment_secret), PaymentId(payment_hash.0)
index 532eb00b871034ebbc4913b7f0b3ffc75035f145..1a01e33826dbb9790086afb1063219ea2f42c98c 100644 (file)
@@ -54,9 +54,20 @@ pub(crate) enum Message<T> where T: core::fmt::Debug + Type + TestEq {
        Ping(msgs::Ping),
        Pong(msgs::Pong),
        OpenChannel(msgs::OpenChannel),
+       OpenChannelV2(msgs::OpenChannelV2),
        AcceptChannel(msgs::AcceptChannel),
+       AcceptChannelV2(msgs::AcceptChannelV2),
        FundingCreated(msgs::FundingCreated),
        FundingSigned(msgs::FundingSigned),
+       TxAddInput(msgs::TxAddInput),
+       TxAddOutput(msgs::TxAddOutput),
+       TxRemoveInput(msgs::TxRemoveInput),
+       TxRemoveOutput(msgs::TxRemoveOutput),
+       TxComplete(msgs::TxComplete),
+       TxSignatures(msgs::TxSignatures),
+       TxInitRbf(msgs::TxInitRbf),
+       TxAckRbf(msgs::TxAckRbf),
+       TxAbort(msgs::TxAbort),
        ChannelReady(msgs::ChannelReady),
        Shutdown(msgs::Shutdown),
        ClosingSigned(msgs::ClosingSigned),
@@ -95,9 +106,20 @@ impl<T> Message<T> where T: core::fmt::Debug + Type + TestEq {
                        &Message::Ping(ref msg) => msg.type_id(),
                        &Message::Pong(ref msg) => msg.type_id(),
                        &Message::OpenChannel(ref msg) => msg.type_id(),
+                       &Message::OpenChannelV2(ref msg) => msg.type_id(),
                        &Message::AcceptChannel(ref msg) => msg.type_id(),
+                       &Message::AcceptChannelV2(ref msg) => msg.type_id(),
                        &Message::FundingCreated(ref msg) => msg.type_id(),
                        &Message::FundingSigned(ref msg) => msg.type_id(),
+                       &Message::TxAddInput(ref msg) => msg.type_id(),
+                       &Message::TxAddOutput(ref msg) => msg.type_id(),
+                       &Message::TxRemoveInput(ref msg) => msg.type_id(),
+                       &Message::TxRemoveOutput(ref msg) => msg.type_id(),
+                       &Message::TxComplete(ref msg) => msg.type_id(),
+                       &Message::TxSignatures(ref msg) => msg.type_id(),
+                       &Message::TxInitRbf(ref msg) => msg.type_id(),
+                       &Message::TxAckRbf(ref msg) => msg.type_id(),
+                       &Message::TxAbort(ref msg) => msg.type_id(),
                        &Message::ChannelReady(ref msg) => msg.type_id(),
                        &Message::Shutdown(ref msg) => msg.type_id(),
                        &Message::ClosingSigned(ref msg) => msg.type_id(),
@@ -135,7 +157,7 @@ impl<T> Message<T> where T: core::fmt::Debug + Type + TestEq {
 ///
 /// # Errors
 ///
-/// Returns an error if the message payload code not be decoded as the specified type.
+/// Returns an error if the message payload could not be decoded as the specified type.
 pub(crate) fn read<R: io::Read, T, H: core::ops::Deref>(buffer: &mut R, custom_reader: H)
 -> Result<Message<T>, (msgs::DecodeError, Option<u16>)> where
        T: core::fmt::Debug + Type + Writeable,
@@ -169,15 +191,48 @@ fn do_read<R: io::Read, T, H: core::ops::Deref>(buffer: &mut R, message_type: u1
                msgs::OpenChannel::TYPE => {
                        Ok(Message::OpenChannel(Readable::read(buffer)?))
                },
+               msgs::OpenChannelV2::TYPE => {
+                       Ok(Message::OpenChannelV2(Readable::read(buffer)?))
+               },
                msgs::AcceptChannel::TYPE => {
                        Ok(Message::AcceptChannel(Readable::read(buffer)?))
                },
+               msgs::AcceptChannelV2::TYPE => {
+                       Ok(Message::AcceptChannelV2(Readable::read(buffer)?))
+               },
                msgs::FundingCreated::TYPE => {
                        Ok(Message::FundingCreated(Readable::read(buffer)?))
                },
                msgs::FundingSigned::TYPE => {
                        Ok(Message::FundingSigned(Readable::read(buffer)?))
                },
+               msgs::TxAddInput::TYPE => {
+                       Ok(Message::TxAddInput(Readable::read(buffer)?))
+               },
+               msgs::TxAddOutput::TYPE => {
+                       Ok(Message::TxAddOutput(Readable::read(buffer)?))
+               },
+               msgs::TxRemoveInput::TYPE => {
+                       Ok(Message::TxRemoveInput(Readable::read(buffer)?))
+               },
+               msgs::TxRemoveOutput::TYPE => {
+                       Ok(Message::TxRemoveOutput(Readable::read(buffer)?))
+               },
+               msgs::TxComplete::TYPE => {
+                       Ok(Message::TxComplete(Readable::read(buffer)?))
+               },
+               msgs::TxSignatures::TYPE => {
+                       Ok(Message::TxSignatures(Readable::read(buffer)?))
+               },
+               msgs::TxInitRbf::TYPE => {
+                       Ok(Message::TxInitRbf(Readable::read(buffer)?))
+               },
+               msgs::TxAckRbf::TYPE => {
+                       Ok(Message::TxAckRbf(Readable::read(buffer)?))
+               },
+               msgs::TxAbort::TYPE => {
+                       Ok(Message::TxAbort(Readable::read(buffer)?))
+               },
                msgs::ChannelReady::TYPE => {
                        Ok(Message::ChannelReady(Readable::read(buffer)?))
                },
@@ -349,6 +404,50 @@ impl Encode for msgs::ClosingSigned {
        const TYPE: u16 = 39;
 }
 
+impl Encode for msgs::OpenChannelV2 {
+       const TYPE: u16 = 64;
+}
+
+impl Encode for msgs::AcceptChannelV2 {
+       const TYPE: u16 = 65;
+}
+
+impl Encode for msgs::TxAddInput {
+       const TYPE: u16 = 66;
+}
+
+impl Encode for msgs::TxAddOutput {
+       const TYPE: u16 = 67;
+}
+
+impl Encode for msgs::TxRemoveInput {
+       const TYPE: u16 = 68;
+}
+
+impl Encode for msgs::TxRemoveOutput {
+       const TYPE: u16 = 69;
+}
+
+impl Encode for msgs::TxComplete {
+       const TYPE: u16 = 70;
+}
+
+impl Encode for msgs::TxSignatures {
+       const TYPE: u16 = 71;
+}
+
+impl Encode for msgs::TxInitRbf {
+       const TYPE: u16 = 72;
+}
+
+impl Encode for msgs::TxAckRbf {
+       const TYPE: u16 = 73;
+}
+
+impl Encode for msgs::TxAbort {
+       const TYPE: u16 = 74;
+}
+
 impl Encode for msgs::OnionMessage {
        const TYPE: u16 = 513;
 }
index d1d0296b501bafffba25e3eb124a07b08ef5ebf5..46010475cebfd56550ef06ede0cba4824265684a 100644 (file)
@@ -16,7 +16,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
 use crate::blinded_path::{BlindedHop, BlindedPath};
 use crate::ln::PaymentHash;
 use crate::ln::channelmanager::{ChannelDetails, PaymentId};
-use crate::ln::features::{ChannelFeatures, InvoiceFeatures, NodeFeatures};
+use crate::ln::features::{Bolt12InvoiceFeatures, ChannelFeatures, InvoiceFeatures, NodeFeatures};
 use crate::ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT};
 use crate::offers::invoice::BlindedPayInfo;
 use crate::routing::gossip::{DirectedChannelInfo, EffectiveCapacity, ReadOnlyNetworkGraph, NetworkGraph, NodeId, RoutingFees};
@@ -29,7 +29,7 @@ use crate::io;
 use crate::prelude::*;
 use crate::sync::Mutex;
 use alloc::collections::BinaryHeap;
-use core::cmp;
+use core::{cmp, fmt};
 use core::ops::Deref;
 
 /// A [`Router`] implemented using [`find_route`].
@@ -442,7 +442,7 @@ impl Writeable for RouteParameters {
                        (2, self.final_value_msat, required),
                        // LDK versions prior to 0.0.114 had the `final_cltv_expiry_delta` parameter in
                        // `RouteParameters` directly. For compatibility, we write it here.
-                       (4, self.payment_params.final_cltv_expiry_delta, required),
+                       (4, self.payment_params.payee.final_cltv_expiry_delta(), option),
                });
                Ok(())
        }
@@ -453,11 +453,13 @@ impl Readable for RouteParameters {
                _init_and_read_tlv_fields!(reader, {
                        (0, payment_params, (required: ReadableArgs, 0)),
                        (2, final_value_msat, required),
-                       (4, final_cltv_expiry_delta, required),
+                       (4, final_cltv_delta, option),
                });
                let mut payment_params: PaymentParameters = payment_params.0.unwrap();
-               if payment_params.final_cltv_expiry_delta == 0 {
-                       payment_params.final_cltv_expiry_delta = final_cltv_expiry_delta.0.unwrap();
+               if let Payee::Clear { ref mut final_cltv_expiry_delta, .. } = payment_params.payee {
+                       if final_cltv_expiry_delta == &0 {
+                               *final_cltv_expiry_delta = final_cltv_delta.ok_or(DecodeError::InvalidValue)?;
+                       }
                }
                Ok(Self {
                        payment_params,
@@ -490,22 +492,11 @@ const MEDIAN_HOP_CLTV_EXPIRY_DELTA: u32 = 40;
 // down from (1300-93) / 61 = 19.78... to arrive at a conservative estimate of 19.
 const MAX_PATH_LENGTH_ESTIMATE: u8 = 19;
 
-/// The recipient of a payment.
+/// Information used to route a payment.
 #[derive(Clone, Debug, Hash, PartialEq, Eq)]
 pub struct PaymentParameters {
-       /// The node id of the payee.
-       pub payee_pubkey: PublicKey,
-
-       /// Features supported by the payee.
-       ///
-       /// May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
-       /// does not contain any features.
-       ///
-       /// [`for_keysend`]: Self::for_keysend
-       pub features: Option<InvoiceFeatures>,
-
-       /// Hints for routing to the payee, containing channels connecting the payee to public nodes.
-       pub route_hints: Hints,
+       /// Information about the payee, such as their features and route hints for their channels.
+       pub payee: Payee,
 
        /// Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
        pub expiry_time: Option<u64>,
@@ -537,30 +528,27 @@ pub struct PaymentParameters {
        /// payment to fail. Future attempts for the same payment shouldn't be relayed through any of
        /// these SCIDs.
        pub previously_failed_channels: Vec<u64>,
-
-       /// The minimum CLTV delta at the end of the route. This value must not be zero.
-       pub final_cltv_expiry_delta: u32,
 }
 
 impl Writeable for PaymentParameters {
        fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
                let mut clear_hints = &vec![];
                let mut blinded_hints = &vec![];
-               match &self.route_hints {
-                       Hints::Clear(hints) => clear_hints = hints,
-                       Hints::Blinded(hints) => blinded_hints = hints,
+               match &self.payee {
+                       Payee::Clear { route_hints, .. } => clear_hints = route_hints,
+                       Payee::Blinded { route_hints, .. } => blinded_hints = route_hints,
                }
                write_tlv_fields!(writer, {
-                       (0, self.payee_pubkey, required),
+                       (0, self.payee.node_id(), option),
                        (1, self.max_total_cltv_expiry_delta, required),
-                       (2, self.features, option),
+                       (2, self.payee.features(), option),
                        (3, self.max_path_count, required),
                        (4, *clear_hints, vec_type),
                        (5, self.max_channel_saturation_power_of_half, required),
                        (6, self.expiry_time, option),
                        (7, self.previously_failed_channels, vec_type),
                        (8, *blinded_hints, optional_vec),
-                       (9, self.final_cltv_expiry_delta, required),
+                       (9, self.payee.final_cltv_expiry_delta(), option),
                });
                Ok(())
        }
@@ -569,9 +557,9 @@ impl Writeable for PaymentParameters {
 impl ReadableArgs<u32> for PaymentParameters {
        fn read<R: io::Read>(reader: &mut R, default_final_cltv_expiry_delta: u32) -> Result<Self, DecodeError> {
                _init_and_read_tlv_fields!(reader, {
-                       (0, payee_pubkey, required),
+                       (0, payee_pubkey, option),
                        (1, max_total_cltv_expiry_delta, (default_value, DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA)),
-                       (2, features, option),
+                       (2, features, (option: ReadableArgs, payee_pubkey.is_some())),
                        (3, max_path_count, (default_value, DEFAULT_MAX_PATH_COUNT)),
                        (4, route_hints, vec_type),
                        (5, max_channel_saturation_power_of_half, (default_value, 2)),
@@ -582,22 +570,27 @@ impl ReadableArgs<u32> for PaymentParameters {
                });
                let clear_route_hints = route_hints.unwrap_or(vec![]);
                let blinded_route_hints = blinded_route_hints.unwrap_or(vec![]);
-               let route_hints = if blinded_route_hints.len() != 0 {
-                       if clear_route_hints.len() != 0 { return Err(DecodeError::InvalidValue) }
-                       Hints::Blinded(blinded_route_hints)
+               let payee = if blinded_route_hints.len() != 0 {
+                       if clear_route_hints.len() != 0 || payee_pubkey.is_some() { return Err(DecodeError::InvalidValue) }
+                       Payee::Blinded {
+                               route_hints: blinded_route_hints,
+                               features: features.and_then(|f: Features| f.bolt12()),
+                       }
                } else {
-                       Hints::Clear(clear_route_hints)
+                       Payee::Clear {
+                               route_hints: clear_route_hints,
+                               node_id: payee_pubkey.ok_or(DecodeError::InvalidValue)?,
+                               features: features.and_then(|f| f.bolt11()),
+                               final_cltv_expiry_delta: final_cltv_expiry_delta.0.unwrap(),
+                       }
                };
                Ok(Self {
-                       payee_pubkey: _init_tlv_based_struct_field!(payee_pubkey, required),
                        max_total_cltv_expiry_delta: _init_tlv_based_struct_field!(max_total_cltv_expiry_delta, (default_value, unused)),
-                       features,
                        max_path_count: _init_tlv_based_struct_field!(max_path_count, (default_value, unused)),
-                       route_hints,
+                       payee,
                        max_channel_saturation_power_of_half: _init_tlv_based_struct_field!(max_channel_saturation_power_of_half, (default_value, unused)),
                        expiry_time,
                        previously_failed_channels: previously_failed_channels.unwrap_or(Vec::new()),
-                       final_cltv_expiry_delta: _init_tlv_based_struct_field!(final_cltv_expiry_delta, (default_value, unused)),
                })
        }
 }
@@ -610,15 +603,12 @@ impl PaymentParameters {
        /// provided.
        pub fn from_node_id(payee_pubkey: PublicKey, final_cltv_expiry_delta: u32) -> Self {
                Self {
-                       payee_pubkey,
-                       features: None,
-                       route_hints: Hints::Clear(vec![]),
+                       payee: Payee::Clear { node_id: payee_pubkey, route_hints: vec![], features: None, final_cltv_expiry_delta },
                        expiry_time: None,
                        max_total_cltv_expiry_delta: DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA,
                        max_path_count: DEFAULT_MAX_PATH_COUNT,
                        max_channel_saturation_power_of_half: 2,
                        previously_failed_channels: Vec::new(),
-                       final_cltv_expiry_delta,
                }
        }
 
@@ -627,21 +617,39 @@ impl PaymentParameters {
        /// The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
        /// provided.
        pub fn for_keysend(payee_pubkey: PublicKey, final_cltv_expiry_delta: u32) -> Self {
-               Self::from_node_id(payee_pubkey, final_cltv_expiry_delta).with_features(InvoiceFeatures::for_keysend())
+               Self::from_node_id(payee_pubkey, final_cltv_expiry_delta).with_bolt11_features(InvoiceFeatures::for_keysend()).expect("PaymentParameters::from_node_id should always initialize the payee as unblinded")
        }
 
-       /// Includes the payee's features.
+       /// Includes the payee's features. Errors if the parameters were initialized with blinded payment
+       /// paths.
        ///
        /// This is not exported to bindings users since bindings don't support move semantics
-       pub fn with_features(self, features: InvoiceFeatures) -> Self {
-               Self { features: Some(features), ..self }
+       pub fn with_bolt11_features(self, features: InvoiceFeatures) -> Result<Self, ()> {
+               match self.payee {
+                       Payee::Blinded { .. } => Err(()),
+                       Payee::Clear { route_hints, node_id, final_cltv_expiry_delta, .. } =>
+                               Ok(Self {
+                                       payee: Payee::Clear {
+                                               route_hints, node_id, features: Some(features), final_cltv_expiry_delta
+                                       }, ..self
+                               })
+               }
        }
 
-       /// Includes hints for routing to the payee.
+       /// Includes hints for routing to the payee. Errors if the parameters were initialized with
+       /// blinded payment paths.
        ///
        /// This is not exported to bindings users since bindings don't support move semantics
-       pub fn with_route_hints(self, route_hints: Vec<RouteHint>) -> Self {
-               Self { route_hints: Hints::Clear(route_hints), ..self }
+       pub fn with_route_hints(self, route_hints: Vec<RouteHint>) -> Result<Self, ()> {
+               match self.payee {
+                       Payee::Blinded { .. } => Err(()),
+                       Payee::Clear { node_id, features, final_cltv_expiry_delta, .. } =>
+                               Ok(Self {
+                                       payee: Payee::Clear {
+                                               route_hints, node_id, features, final_cltv_expiry_delta,
+                                       }, ..self
+                               })
+               }
        }
 
        /// Includes a payment expiration in seconds relative to the UNIX epoch.
@@ -673,14 +681,111 @@ impl PaymentParameters {
        }
 }
 
-/// Routing hints for the tail of the route.
+/// The recipient of a payment, differing based on whether they've hidden their identity with route
+/// blinding.
 #[derive(Clone, Debug, Hash, PartialEq, Eq)]
-pub enum Hints {
+pub enum Payee {
        /// The recipient provided blinded paths and payinfo to reach them. The blinded paths themselves
        /// will be included in the final [`Route`].
-       Blinded(Vec<(BlindedPayInfo, BlindedPath)>),
+       Blinded {
+               /// Aggregated routing info and blinded paths, for routing to the payee without knowing their
+               /// node id.
+               route_hints: Vec<(BlindedPayInfo, BlindedPath)>,
+               /// Features supported by the payee.
+               ///
+               /// May be set from the payee's invoice. May be `None` if the invoice does not contain any
+               /// features.
+               features: Option<Bolt12InvoiceFeatures>,
+       },
        /// The recipient included these route hints in their BOLT11 invoice.
-       Clear(Vec<RouteHint>),
+       Clear {
+               /// The node id of the payee.
+               node_id: PublicKey,
+               /// Hints for routing to the payee, containing channels connecting the payee to public nodes.
+               route_hints: Vec<RouteHint>,
+               /// Features supported by the payee.
+               ///
+               /// May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
+               /// does not contain any features.
+               ///
+               /// [`for_keysend`]: PaymentParameters::for_keysend
+               features: Option<InvoiceFeatures>,
+               /// The minimum CLTV delta at the end of the route. This value must not be zero.
+               final_cltv_expiry_delta: u32,
+       },
+}
+
+impl Payee {
+       fn node_id(&self) -> Option<PublicKey> {
+               match self {
+                       Self::Clear { node_id, .. } => Some(*node_id),
+                       _ => None,
+               }
+       }
+       fn node_features(&self) -> Option<NodeFeatures> {
+               match self {
+                       Self::Clear { features, .. } => features.as_ref().map(|f| f.to_context()),
+                       Self::Blinded { features, .. } => features.as_ref().map(|f| f.to_context()),
+               }
+       }
+       fn supports_basic_mpp(&self) -> bool {
+               match self {
+                       Self::Clear { features, .. } => features.as_ref().map_or(false, |f| f.supports_basic_mpp()),
+                       Self::Blinded { features, .. } => features.as_ref().map_or(false, |f| f.supports_basic_mpp()),
+               }
+       }
+       fn features(&self) -> Option<FeaturesRef> {
+               match self {
+                       Self::Clear { features, .. } => features.as_ref().map(|f| FeaturesRef::Bolt11(f)),
+                       Self::Blinded { features, .. } => features.as_ref().map(|f| FeaturesRef::Bolt12(f)),
+               }
+       }
+       fn final_cltv_expiry_delta(&self) -> Option<u32> {
+               match self {
+                       Self::Clear { final_cltv_expiry_delta, .. } => Some(*final_cltv_expiry_delta),
+                       _ => None,
+               }
+       }
+}
+
+enum FeaturesRef<'a> {
+       Bolt11(&'a InvoiceFeatures),
+       Bolt12(&'a Bolt12InvoiceFeatures),
+}
+enum Features {
+       Bolt11(InvoiceFeatures),
+       Bolt12(Bolt12InvoiceFeatures),
+}
+
+impl Features {
+       fn bolt12(self) -> Option<Bolt12InvoiceFeatures> {
+               match self {
+                       Self::Bolt12(f) => Some(f),
+                       _ => None,
+               }
+       }
+       fn bolt11(self) -> Option<InvoiceFeatures> {
+               match self {
+                       Self::Bolt11(f) => Some(f),
+                       _ => None,
+               }
+       }
+}
+
+impl<'a> Writeable for FeaturesRef<'a> {
+       fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
+               match self {
+                       Self::Bolt11(f) => Ok(f.write(w)?),
+                       Self::Bolt12(f) => Ok(f.write(w)?),
+               }
+       }
+}
+
+impl ReadableArgs<bool> for Features {
+       fn read<R: io::Read>(reader: &mut R, bolt11: bool) -> Result<Self, DecodeError> {
+               if bolt11 { return Ok(Self::Bolt11(Readable::read(reader)?)) }
+               Ok(Self::Bolt12(Readable::read(reader)?))
+       }
 }
 
 /// A list of hops along a payment path terminating with a channel to the recipient.
@@ -1067,6 +1172,21 @@ fn default_node_features() -> NodeFeatures {
        features
 }
 
+struct LoggedPayeePubkey(Option<PublicKey>);
+impl fmt::Display for LoggedPayeePubkey {
+       fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+               match self.0 {
+                       Some(pk) => {
+                               "payee node id ".fmt(f)?;
+                               pk.fmt(f)
+                       },
+                       None => {
+                               "blinded payee".fmt(f)
+                       },
+               }
+       }
+}
+
 /// Finds a route from us (payer) to the given target node (payee).
 ///
 /// If the payee provided features in their invoice, they should be provided via `params.payee`.
@@ -1116,10 +1236,16 @@ pub(crate) fn get_route<L: Deref, S: Score>(
        _random_seed_bytes: &[u8; 32]
 ) -> Result<Route, LightningError>
 where L::Target: Logger {
-       let payee_node_id = NodeId::from_pubkey(&payment_params.payee_pubkey);
+       // If we're routing to a blinded recipient, we won't have their node id. Therefore, keep the
+       // unblinded payee id as an option. We also need a non-optional "payee id" for path construction,
+       // so use a dummy id for this in the blinded case.
+       let payee_node_id_opt = payment_params.payee.node_id().map(|pk| NodeId::from_pubkey(&pk));
+       const DUMMY_BLINDED_PAYEE_ID: [u8; 33] = [42u8; 33];
+       let maybe_dummy_payee_pk = payment_params.payee.node_id().unwrap_or_else(|| PublicKey::from_slice(&DUMMY_BLINDED_PAYEE_ID).unwrap());
+       let maybe_dummy_payee_node_id = NodeId::from_pubkey(&maybe_dummy_payee_pk);
        let our_node_id = NodeId::from_pubkey(&our_node_pubkey);
 
-       if payee_node_id == our_node_id {
+       if payee_node_id_opt.map_or(false, |payee| payee == our_node_id) {
                return Err(LightningError{err: "Cannot generate a route to ourselves".to_owned(), action: ErrorAction::IgnoreError});
        }
 
@@ -1131,11 +1257,11 @@ where L::Target: Logger {
                return Err(LightningError{err: "Cannot send a payment of 0 msat".to_owned(), action: ErrorAction::IgnoreError});
        }
 
-       match &payment_params.route_hints {
-               Hints::Clear(hints) => {
-                       for route in hints.iter() {
+       match &payment_params.payee {
+               Payee::Clear { route_hints, node_id, .. } => {
+                       for route in route_hints.iter() {
                                for hop in &route.0 {
-                                       if hop.src_node_id == payment_params.payee_pubkey {
+                                       if hop.src_node_id == *node_id {
                                                return Err(LightningError{err: "Route hint cannot have the payee as the source.".to_owned(), action: ErrorAction::IgnoreError});
                                        }
                                }
@@ -1144,7 +1270,8 @@ where L::Target: Logger {
                _ => return Err(LightningError{err: "Routing to blinded paths isn't supported yet".to_owned(), action: ErrorAction::IgnoreError}),
 
        }
-       if payment_params.max_total_cltv_expiry_delta <= payment_params.final_cltv_expiry_delta {
+       let final_cltv_expiry_delta = payment_params.payee.final_cltv_expiry_delta().unwrap_or(0);
+       if payment_params.max_total_cltv_expiry_delta <= final_cltv_expiry_delta {
                return Err(LightningError{err: "Can't find a route where the maximum total CLTV expiry delta is below the final CLTV expiry.".to_owned(), action: ErrorAction::IgnoreError});
        }
 
@@ -1216,16 +1343,15 @@ where L::Target: Logger {
        // work reliably.
        let allow_mpp = if payment_params.max_path_count == 1 {
                false
-       } else if let Some(features) = &payment_params.features {
-               features.supports_basic_mpp()
-       } else if let Some(node) = network_nodes.get(&payee_node_id) {
-               if let Some(node_info) = node.announcement_info.as_ref() {
-                       node_info.features.supports_basic_mpp()
-               } else { false }
+       } else if payment_params.payee.supports_basic_mpp() {
+               true
+       } else if let Some(payee) = payee_node_id_opt {
+               network_nodes.get(&payee).map_or(false, |node| node.announcement_info.as_ref().map_or(false,
+                       |info| info.features.supports_basic_mpp()))
        } else { false };
 
-       log_trace!(logger, "Searching for a route from payer {} to payee {} {} MPP and {} first hops {}overriding the network graph", our_node_pubkey,
-               payment_params.payee_pubkey, if allow_mpp { "with" } else { "without" },
+       log_trace!(logger, "Searching for a route from payer {} to {} {} MPP and {} first hops {}overriding the network graph", our_node_pubkey,
+               LoggedPayeePubkey(payment_params.payee.node_id()), if allow_mpp { "with" } else { "without" },
                first_hops.map(|hops| hops.len()).unwrap_or(0), if first_hops.is_some() { "" } else { "not " });
 
        // Step (1).
@@ -1328,7 +1454,8 @@ where L::Target: Logger {
                });
        }
 
-       log_trace!(logger, "Building path from {} (payee) to {} (us/payer) for value {} msat.", payment_params.payee_pubkey, our_node_pubkey, final_value_msat);
+       log_trace!(logger, "Building path from {} to payer {} for value {} msat.",
+               LoggedPayeePubkey(payment_params.payee.node_id()), our_node_pubkey, final_value_msat);
 
        macro_rules! add_entry {
                // Adds entry which goes from $src_node_id to $dest_node_id over the $candidate hop.
@@ -1375,9 +1502,9 @@ where L::Target: Logger {
                                        // In order to already account for some of the privacy enhancing random CLTV
                                        // expiry delta offset we add on top later, we subtract a rough estimate
                                        // (2*MEDIAN_HOP_CLTV_EXPIRY_DELTA) here.
-                                       let max_total_cltv_expiry_delta = (payment_params.max_total_cltv_expiry_delta - payment_params.final_cltv_expiry_delta)
+                                       let max_total_cltv_expiry_delta = (payment_params.max_total_cltv_expiry_delta - final_cltv_expiry_delta)
                                                .checked_sub(2*MEDIAN_HOP_CLTV_EXPIRY_DELTA)
-                                               .unwrap_or(payment_params.max_total_cltv_expiry_delta - payment_params.final_cltv_expiry_delta);
+                                               .unwrap_or(payment_params.max_total_cltv_expiry_delta - final_cltv_expiry_delta);
                                        let hop_total_cltv_delta = ($next_hops_cltv_delta as u32)
                                                .saturating_add($candidate.cltv_expiry_delta());
                                        let exceeds_cltv_delta_limit = hop_total_cltv_delta > max_total_cltv_expiry_delta;
@@ -1577,7 +1704,7 @@ where L::Target: Logger {
                                // Entries are added to dist in add_entry!() when there is a channel from a node.
                                // Because there are no channels from payee, it will not have a dist entry at this point.
                                // If we're processing any other node, it is always be the result of a channel from it.
-                               assert_eq!($node_id, payee_node_id);
+                               debug_assert_eq!($node_id, maybe_dummy_payee_node_id);
                                false
                        };
 
@@ -1637,35 +1764,35 @@ where L::Target: Logger {
 
                // If first hop is a private channel and the only way to reach the payee, this is the only
                // place where it could be added.
-               if let Some(first_channels) = first_hop_targets.get(&payee_node_id) {
+               payee_node_id_opt.map(|payee| first_hop_targets.get(&payee).map(|first_channels| {
                        for details in first_channels {
                                let candidate = CandidateRouteHop::FirstHop { details };
-                               let added = add_entry!(candidate, our_node_id, payee_node_id, 0, path_value_msat,
+                               let added = add_entry!(candidate, our_node_id, payee, 0, path_value_msat,
                                                                        0, 0u64, 0, 0);
                                log_trace!(logger, "{} direct route to payee via SCID {}",
                                                if added { "Added" } else { "Skipped" }, candidate.short_channel_id());
                        }
-               }
+               }));
 
                // Add the payee as a target, so that the payee-to-payer
                // search algorithm knows what to start with.
-               match network_nodes.get(&payee_node_id) {
+               payee_node_id_opt.map(|payee| match network_nodes.get(&payee) {
                        // The payee is not in our network graph, so nothing to add here.
                        // There is still a chance of reaching them via last_hops though,
                        // so don't yet fail the payment here.
                        // If not, targets.pop() will not even let us enter the loop in step 2.
                        None => {},
                        Some(node) => {
-                               add_entries_to_cheapest_to_target_node!(node, payee_node_id, 0, path_value_msat, 0, 0u64, 0, 0);
+                               add_entries_to_cheapest_to_target_node!(node, payee, 0, path_value_msat, 0, 0u64, 0, 0);
                        },
-               }
+               });
 
                // Step (2).
                // If a caller provided us with last hops, add them to routing targets. Since this happens
                // earlier than general path finding, they will be somewhat prioritized, although currently
                // it matters only if the fees are exactly the same.
-               let route_hints = match &payment_params.route_hints {
-                       Hints::Clear(hints) => hints,
+               let route_hints = match &payment_params.payee {
+                       Payee::Clear { route_hints, .. } => route_hints,
                        _ => return Err(LightningError{err: "Routing to blinded paths isn't supported yet".to_owned(), action: ErrorAction::IgnoreError}),
                };
                for route in route_hints.iter().filter(|route| !route.0.is_empty()) {
@@ -1680,7 +1807,7 @@ where L::Target: Logger {
                                // We start building the path from reverse, i.e., from payee
                                // to the first RouteHintHop in the path.
                                let hop_iter = route.0.iter().rev();
-                               let prev_hop_iter = core::iter::once(&payment_params.payee_pubkey).chain(
+                               let prev_hop_iter = core::iter::once(&maybe_dummy_payee_pk).chain(
                                        route.0.iter().skip(1).rev().map(|hop| &hop.src_node_id));
                                let mut hop_used = true;
                                let mut aggregate_next_hops_fee_msat: u64 = 0;
@@ -1840,7 +1967,7 @@ where L::Target: Logger {
                                        // save this path for the payment route. Also, update the liquidity
                                        // remaining on the used hops, so that we take them into account
                                        // while looking for more paths.
-                                       if ordered_hops.last().unwrap().0.node_id == payee_node_id {
+                                       if ordered_hops.last().unwrap().0.node_id == maybe_dummy_payee_node_id {
                                                break 'path_walk;
                                        }
 
@@ -1923,7 +2050,7 @@ where L::Target: Logger {
                        // If we found a path back to the payee, we shouldn't try to process it again. This is
                        // the equivalent of the `elem.was_processed` check in
                        // add_entries_to_cheapest_to_target_node!() (see comment there for more info).
-                       if node_id == payee_node_id { continue 'path_construction; }
+                       if node_id == maybe_dummy_payee_node_id { continue 'path_construction; }
 
                        // Otherwise, since the current target node is not us,
                        // keep "unrolling" the payment graph from payee to payer by
@@ -2067,7 +2194,7 @@ where L::Target: Logger {
                }).collect::<Vec<_>>();
                // Propagate the cltv_expiry_delta one hop backwards since the delta from the current hop is
                // applicable for the previous hop.
-               path.iter_mut().rev().fold(payment_params.final_cltv_expiry_delta, |prev_cltv_expiry_delta, hop| {
+               path.iter_mut().rev().fold(final_cltv_expiry_delta, |prev_cltv_expiry_delta, hop| {
                        core::mem::replace(&mut hop.as_mut().unwrap().cltv_expiry_delta, prev_cltv_expiry_delta)
                });
                selected_paths.push(path);
@@ -2075,10 +2202,10 @@ where L::Target: Logger {
        // Make sure we would never create a route with more paths than we allow.
        debug_assert!(selected_paths.len() <= payment_params.max_path_count.into());
 
-       if let Some(features) = &payment_params.features {
+       if let Some(node_features) = payment_params.payee.node_features() {
                for path in selected_paths.iter_mut() {
                        if let Ok(route_hop) = path.last_mut().unwrap() {
-                               route_hop.node_features = features.to_context();
+                               route_hop.node_features = node_features.clone();
                        }
                }
        }
@@ -2093,7 +2220,7 @@ where L::Target: Logger {
                paths,
                payment_params: Some(payment_params.clone()),
        };
-       log_info!(logger, "Got route to {}: {}", payment_params.payee_pubkey, log_route!(route));
+       log_info!(logger, "Got route: {}", log_route!(route));
        Ok(route)
 }
 
@@ -2528,7 +2655,7 @@ mod tests {
                let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph();
                let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
                let config = UserConfig::default();
-               let payment_params = PaymentParameters::from_node_id(nodes[2], 42).with_features(channelmanager::provided_invoice_features(&config));
+               let payment_params = PaymentParameters::from_node_id(nodes[2], 42).with_bolt11_features(channelmanager::provided_invoice_features(&config)).unwrap();
                let scorer = ln_test_utils::TestScorer::new();
                let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
@@ -2926,13 +3053,13 @@ mod tests {
                let mut invalid_last_hops = last_hops_multi_private_channels(&nodes);
                invalid_last_hops.push(invalid_last_hop);
                {
-                       let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(invalid_last_hops);
+                       let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(invalid_last_hops).unwrap();
                        if let Err(LightningError{err, action: ErrorAction::IgnoreError}) = get_route(&our_id, &payment_params, &network_graph.read_only(), None, 100, Arc::clone(&logger), &scorer, &random_seed_bytes) {
                                assert_eq!(err, "Route hint cannot have the payee as the source.");
                        } else { panic!(); }
                }
 
-               let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops_multi_private_channels(&nodes));
+               let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops_multi_private_channels(&nodes)).unwrap();
                let route = get_route(&our_id, &payment_params, &network_graph.read_only(), None, 100, Arc::clone(&logger), &scorer, &random_seed_bytes).unwrap();
                assert_eq!(route.paths[0].hops.len(), 5);
 
@@ -3002,7 +3129,7 @@ mod tests {
        fn ignores_empty_last_hops_test() {
                let (secp_ctx, network_graph, _, _, logger) = build_graph();
                let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
-               let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(empty_last_hop(&nodes));
+               let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(empty_last_hop(&nodes)).unwrap();
                let scorer = ln_test_utils::TestScorer::new();
                let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
@@ -3082,7 +3209,7 @@ mod tests {
                let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph();
                let (_, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
                let last_hops = multi_hop_last_hops_hint([nodes[2], nodes[3]]);
-               let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops.clone());
+               let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops.clone()).unwrap();
                let scorer = ln_test_utils::TestScorer::new();
                let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
@@ -3156,7 +3283,7 @@ mod tests {
                let non_announced_pubkey = PublicKey::from_secret_key(&secp_ctx, &non_announced_privkey);
 
                let last_hops = multi_hop_last_hops_hint([nodes[2], non_announced_pubkey]);
-               let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops.clone());
+               let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops.clone()).unwrap();
                let scorer = ln_test_utils::TestScorer::new();
                // Test through channels 2, 3, 0xff00, 0xff01.
                // Test shows that multiple hop hints are considered.
@@ -3262,7 +3389,7 @@ mod tests {
        fn last_hops_with_public_channel_test() {
                let (secp_ctx, network_graph, _, _, logger) = build_graph();
                let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
-               let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops_with_public_channel(&nodes));
+               let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops_with_public_channel(&nodes)).unwrap();
                let scorer = ln_test_utils::TestScorer::new();
                let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
@@ -3321,7 +3448,7 @@ mod tests {
                // Simple test with outbound channel to 4 to test that last_hops and first_hops connect
                let our_chans = vec![get_channel_details(Some(42), nodes[3].clone(), InitFeatures::from_le_bytes(vec![0b11]), 250_000_000)];
                let mut last_hops = last_hops(&nodes);
-               let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops.clone());
+               let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops.clone()).unwrap();
                let route = get_route(&our_id, &payment_params, &network_graph.read_only(), Some(&our_chans.iter().collect::<Vec<_>>()), 100, Arc::clone(&logger), &scorer, &random_seed_bytes).unwrap();
                assert_eq!(route.paths[0].hops.len(), 2);
 
@@ -3342,7 +3469,7 @@ mod tests {
                last_hops[0].0[0].fees.base_msat = 1000;
 
                // Revert to via 6 as the fee on 8 goes up
-               let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops);
+               let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops).unwrap();
                let route = get_route(&our_id, &payment_params, &network_graph.read_only(), None, 100, Arc::clone(&logger), &scorer, &random_seed_bytes).unwrap();
                assert_eq!(route.paths[0].hops.len(), 4);
 
@@ -3435,7 +3562,7 @@ mod tests {
                        htlc_minimum_msat: None,
                        htlc_maximum_msat: last_hop_htlc_max,
                }]);
-               let payment_params = PaymentParameters::from_node_id(target_node_id, 42).with_route_hints(vec![last_hops]);
+               let payment_params = PaymentParameters::from_node_id(target_node_id, 42).with_route_hints(vec![last_hops]).unwrap();
                let our_chans = vec![get_channel_details(Some(42), middle_node_id, InitFeatures::from_le_bytes(vec![0b11]), outbound_capacity_msat)];
                let scorer = ln_test_utils::TestScorer::new();
                let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
@@ -3501,7 +3628,7 @@ mod tests {
                let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
                let config = UserConfig::default();
-               let payment_params = PaymentParameters::from_node_id(nodes[2], 42).with_features(channelmanager::provided_invoice_features(&config));
+               let payment_params = PaymentParameters::from_node_id(nodes[2], 42).with_bolt11_features(channelmanager::provided_invoice_features(&config)).unwrap();
 
                // We will use a simple single-path route from
                // our node to node2 via node0: channels {1, 3}.
@@ -3777,7 +3904,7 @@ mod tests {
                let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
                let config = UserConfig::default();
-               let payment_params = PaymentParameters::from_node_id(nodes[3], 42).with_features(channelmanager::provided_invoice_features(&config));
+               let payment_params = PaymentParameters::from_node_id(nodes[3], 42).with_bolt11_features(channelmanager::provided_invoice_features(&config)).unwrap();
 
                // Path via {node7, node2, node4} is channels {12, 13, 6, 11}.
                // {12, 13, 11} have the capacities of 100, {6} has a capacity of 50.
@@ -3952,7 +4079,7 @@ mod tests {
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
                let config = UserConfig::default();
                let payment_params = PaymentParameters::from_node_id(nodes[2], 42)
-                       .with_features(channelmanager::provided_invoice_features(&config));
+                       .with_bolt11_features(channelmanager::provided_invoice_features(&config)).unwrap();
 
                // We need a route consisting of 3 paths:
                // From our node to node2 via node0, node7, node1 (three paths one hop each).
@@ -4111,7 +4238,7 @@ mod tests {
                let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
                let config = UserConfig::default();
-               let payment_params = PaymentParameters::from_node_id(nodes[3], 42).with_features(channelmanager::provided_invoice_features(&config));
+               let payment_params = PaymentParameters::from_node_id(nodes[3], 42).with_bolt11_features(channelmanager::provided_invoice_features(&config)).unwrap();
 
                // We need a route consisting of 3 paths:
                // From our node to node3 via {node0, node2}, {node7, node2, node4} and {node7, node2}.
@@ -4276,7 +4403,7 @@ mod tests {
                let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
                let config = UserConfig::default();
-               let payment_params = PaymentParameters::from_node_id(nodes[3], 42).with_features(channelmanager::provided_invoice_features(&config));
+               let payment_params = PaymentParameters::from_node_id(nodes[3], 42).with_bolt11_features(channelmanager::provided_invoice_features(&config)).unwrap();
 
                // This test checks that if we have two cheaper paths and one more expensive path,
                // so that liquidity-wise any 2 of 3 combination is sufficient,
@@ -4446,7 +4573,7 @@ mod tests {
                let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
                let config = UserConfig::default();
-               let payment_params = PaymentParameters::from_node_id(nodes[3], 42).with_features(channelmanager::provided_invoice_features(&config));
+               let payment_params = PaymentParameters::from_node_id(nodes[3], 42).with_bolt11_features(channelmanager::provided_invoice_features(&config)).unwrap();
 
                // We need a route consisting of 2 paths:
                // From our node to node3 via {node0, node2} and {node7, node2, node4}.
@@ -4628,7 +4755,7 @@ mod tests {
                let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
                let config = UserConfig::default();
-               let payment_params = PaymentParameters::from_node_id(PublicKey::from_slice(&[02; 33]).unwrap(), 42).with_features(channelmanager::provided_invoice_features(&config))
+               let payment_params = PaymentParameters::from_node_id(PublicKey::from_slice(&[02; 33]).unwrap(), 42).with_bolt11_features(channelmanager::provided_invoice_features(&config)).unwrap()
                        .with_route_hints(vec![RouteHint(vec![RouteHintHop {
                                src_node_id: nodes[2],
                                short_channel_id: 42,
@@ -4636,7 +4763,7 @@ mod tests {
                                cltv_expiry_delta: 42,
                                htlc_minimum_msat: None,
                                htlc_maximum_msat: None,
-                       }])]).with_max_channel_saturation_power_of_half(0);
+                       }])]).unwrap().with_max_channel_saturation_power_of_half(0);
 
                // Keep only two paths from us to nodes[2], both with a 99sat HTLC maximum, with one with
                // no fee and one with a 1msat fee. Previously, trying to route 100 sats to nodes[2] here
@@ -4720,7 +4847,7 @@ mod tests {
                let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
                let config = UserConfig::default();
-               let payment_params = PaymentParameters::from_node_id(nodes[2], 42).with_features(channelmanager::provided_invoice_features(&config))
+               let payment_params = PaymentParameters::from_node_id(nodes[2], 42).with_bolt11_features(channelmanager::provided_invoice_features(&config)).unwrap()
                        .with_max_channel_saturation_power_of_half(0);
 
                // We need a route consisting of 3 paths:
@@ -5076,7 +5203,7 @@ mod tests {
                let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
                let config = UserConfig::default();
-               let payment_params = PaymentParameters::from_node_id(nodes[2], 42).with_features(channelmanager::provided_invoice_features(&config));
+               let payment_params = PaymentParameters::from_node_id(nodes[2], 42).with_bolt11_features(channelmanager::provided_invoice_features(&config)).unwrap();
 
                // We modify the graph to set the htlc_minimum of channel 2 and 4 as needed - channel 2
                // gets an htlc_maximum_msat of 80_000 and channel 4 an htlc_minimum_msat of 90_000. We
@@ -5144,7 +5271,7 @@ mod tests {
                let network_graph = NetworkGraph::new(Network::Testnet, Arc::clone(&logger));
                let scorer = ln_test_utils::TestScorer::new();
                let config = UserConfig::default();
-               let payment_params = PaymentParameters::from_node_id(nodes[0], 42).with_features(channelmanager::provided_invoice_features(&config));
+               let payment_params = PaymentParameters::from_node_id(nodes[0], 42).with_bolt11_features(channelmanager::provided_invoice_features(&config)).unwrap();
                let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
 
@@ -5210,7 +5337,7 @@ mod tests {
        fn prefers_shorter_route_with_higher_fees() {
                let (secp_ctx, network_graph, _, _, logger) = build_graph();
                let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
-               let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops(&nodes));
+               let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops(&nodes)).unwrap();
 
                // Without penalizing each hop 100 msats, a longer path with lower fees is chosen.
                let scorer = ln_test_utils::TestScorer::new();
@@ -5283,7 +5410,7 @@ mod tests {
        fn avoids_routing_through_bad_channels_and_nodes() {
                let (secp_ctx, network, _, _, logger) = build_graph();
                let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
-               let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops(&nodes));
+               let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops(&nodes)).unwrap();
                let network_graph = network.read_only();
 
                // A path to nodes[6] exists when no penalties are applied to any channel.
@@ -5406,7 +5533,7 @@ mod tests {
 
                // Make sure that generally there is at least one route available
                let feasible_max_total_cltv_delta = 1008;
-               let feasible_payment_params = PaymentParameters::from_node_id(nodes[6], 0).with_route_hints(last_hops(&nodes))
+               let feasible_payment_params = PaymentParameters::from_node_id(nodes[6], 0).with_route_hints(last_hops(&nodes)).unwrap()
                        .with_max_total_cltv_expiry_delta(feasible_max_total_cltv_delta);
                let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
@@ -5416,7 +5543,7 @@ mod tests {
 
                // But not if we exclude all paths on the basis of their accumulated CLTV delta
                let fail_max_total_cltv_delta = 23;
-               let fail_payment_params = PaymentParameters::from_node_id(nodes[6], 0).with_route_hints(last_hops(&nodes))
+               let fail_payment_params = PaymentParameters::from_node_id(nodes[6], 0).with_route_hints(last_hops(&nodes)).unwrap()
                        .with_max_total_cltv_expiry_delta(fail_max_total_cltv_delta);
                match get_route(&our_id, &fail_payment_params, &network_graph, None, 100, Arc::clone(&logger), &scorer, &random_seed_bytes)
                {
@@ -5436,7 +5563,7 @@ mod tests {
                let network_graph = network.read_only();
 
                let scorer = ln_test_utils::TestScorer::new();
-               let mut payment_params = PaymentParameters::from_node_id(nodes[6], 0).with_route_hints(last_hops(&nodes))
+               let mut payment_params = PaymentParameters::from_node_id(nodes[6], 0).with_route_hints(last_hops(&nodes)).unwrap()
                        .with_max_path_count(1);
                let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
@@ -5492,7 +5619,7 @@ mod tests {
 
                let scorer = ln_test_utils::TestScorer::new();
 
-               let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops(&nodes));
+               let payment_params = PaymentParameters::from_node_id(nodes[6], 42).with_route_hints(last_hops(&nodes)).unwrap();
                let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
                let route = get_route(&our_id, &payment_params, &network_graph.read_only(), None, 100, Arc::clone(&logger), &scorer, &random_seed_bytes).unwrap();
@@ -5638,7 +5765,7 @@ mod tests {
                });
 
                let config = UserConfig::default();
-               let payment_params = PaymentParameters::from_node_id(nodes[2], 42).with_features(channelmanager::provided_invoice_features(&config));
+               let payment_params = PaymentParameters::from_node_id(nodes[2], 42).with_bolt11_features(channelmanager::provided_invoice_features(&config)).unwrap();
                let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
                let random_seed_bytes = keys_manager.get_secure_random_bytes();
                // 100,000 sats is less than the available liquidity on each channel, set above.
@@ -5723,7 +5850,7 @@ mod tests {
                                let src = &PublicKey::from_slice(nodes.unordered_keys().skip(seed % nodes.len()).next().unwrap().as_slice()).unwrap();
                                seed = seed.overflowing_mul(0xdeadbeef).0;
                                let dst = PublicKey::from_slice(nodes.unordered_keys().skip(seed % nodes.len()).next().unwrap().as_slice()).unwrap();
-                               let payment_params = PaymentParameters::from_node_id(dst, 42).with_features(channelmanager::provided_invoice_features(&config));
+                               let payment_params = PaymentParameters::from_node_id(dst, 42).with_bolt11_features(channelmanager::provided_invoice_features(&config)).unwrap();
                                let amt = seed as u64 % 200_000_000;
                                let params = ProbabilisticScoringParameters::default();
                                let scorer = ProbabilisticScorer::new(params, &graph, &logger);
@@ -6069,7 +6196,7 @@ mod benches {
                                let src = PublicKey::from_slice(nodes.unordered_keys().skip(seed % nodes.len()).next().unwrap().as_slice()).unwrap();
                                seed *= 0xdeadbeef;
                                let dst = PublicKey::from_slice(nodes.unordered_keys().skip(seed % nodes.len()).next().unwrap().as_slice()).unwrap();
-                               let params = PaymentParameters::from_node_id(dst, 42).with_features(features.clone());
+                               let params = PaymentParameters::from_node_id(dst, 42).with_bolt11_features(features.clone()).unwrap();
                                let first_hop = first_hop(src);
                                let amt = seed as u64 % 1_000_000;
                                if let Ok(route) = get_route(&payer, &params, &graph.read_only(), Some(&[&first_hop]), amt, &DummyLogger{}, &scorer, &random_seed_bytes) {
index e276e72719e4853d7094af615caed56e1415fd8d..707ca2b326d0d5720cae5abec48885e443b46a59 100644 (file)
@@ -31,7 +31,7 @@ use bitcoin::secp256k1::schnorr;
 use bitcoin::blockdata::constants::ChainHash;
 use bitcoin::blockdata::script::{self, Script};
 use bitcoin::blockdata::transaction::{OutPoint, Transaction, TxOut};
-use bitcoin::consensus;
+use bitcoin::{consensus, Witness};
 use bitcoin::consensus::Encodable;
 use bitcoin::hashes::sha256d::Hash as Sha256dHash;
 use bitcoin::hash_types::{Txid, BlockHash};
@@ -512,6 +512,10 @@ impl_writeable_primitive!(u128, 16);
 impl_writeable_primitive!(u64, 8);
 impl_writeable_primitive!(u32, 4);
 impl_writeable_primitive!(u16, 2);
+impl_writeable_primitive!(i64, 8);
+impl_writeable_primitive!(i32, 4);
+impl_writeable_primitive!(i16, 2);
+impl_writeable_primitive!(i8, 1);
 
 impl Writeable for u8 {
        #[inline]
@@ -832,6 +836,40 @@ impl_for_vec!((A, B), A, B);
 impl_writeable_for_vec!(&crate::routing::router::BlindedTail);
 impl_readable_for_vec!(crate::routing::router::BlindedTail);
 
+impl Writeable for Vec<Witness> {
+       #[inline]
+       fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
+               (self.len() as u16).write(w)?;
+               for witness in self {
+                       (witness.serialized_len() as u16).write(w)?;
+                       witness.write(w)?;
+               }
+               Ok(())
+       }
+}
+
+impl Readable for Vec<Witness> {
+       #[inline]
+       fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
+               let num_witnesses = <u16 as Readable>::read(r)? as usize;
+               let mut witnesses = Vec::with_capacity(num_witnesses);
+               for _ in 0..num_witnesses {
+                       // Even though the length of each witness can be inferred in its consensus-encoded form,
+                       // the spec includes a length prefix so that implementations don't have to deserialize
+                       //  each initially. We do that here anyway as in general we'll need to be able to make
+                       // assertions on some properties of the witnesses when receiving a message providing a list
+                       // of witnesses. We'll just do a sanity check for the lengths and error if there is a mismatch.
+                       let witness_len = <u16 as Readable>::read(r)? as usize;
+                       let witness = <Witness as Readable>::read(r)?;
+                       if witness.serialized_len() != witness_len {
+                               return Err(DecodeError::BadLengthDescriptor);
+                       }
+                       witnesses.push(witness);
+               }
+               Ok(witnesses)
+       }
+}
+
 impl Writeable for Script {
        fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
                (self.len() as u16).write(w)?;
@@ -1135,6 +1173,7 @@ macro_rules! impl_consensus_ser {
 }
 impl_consensus_ser!(Transaction);
 impl_consensus_ser!(TxOut);
+impl_consensus_ser!(Witness);
 
 impl<T: Readable> Readable for Mutex<T> {
        fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
index 658876fe33a6a478865da7f2ccaf1d729cb15569..ee5180be70a5ec45a7c19c852818bdfcff95958c 100644 (file)
@@ -469,6 +469,50 @@ impl msgs::ChannelMessageHandler for TestChannelMessageHandler {
        fn provided_init_features(&self, _their_init_features: &PublicKey) -> InitFeatures {
                channelmanager::provided_init_features(&UserConfig::default())
        }
+
+       fn handle_open_channel_v2(&self, _their_node_id: &PublicKey, msg: &msgs::OpenChannelV2) {
+               self.received_msg(wire::Message::OpenChannelV2(msg.clone()));
+       }
+
+       fn handle_accept_channel_v2(&self, _their_node_id: &PublicKey, msg: &msgs::AcceptChannelV2) {
+               self.received_msg(wire::Message::AcceptChannelV2(msg.clone()));
+       }
+
+       fn handle_tx_add_input(&self, _their_node_id: &PublicKey, msg: &msgs::TxAddInput) {
+               self.received_msg(wire::Message::TxAddInput(msg.clone()));
+       }
+
+       fn handle_tx_add_output(&self, _their_node_id: &PublicKey, msg: &msgs::TxAddOutput) {
+               self.received_msg(wire::Message::TxAddOutput(msg.clone()));
+       }
+
+       fn handle_tx_remove_input(&self, _their_node_id: &PublicKey, msg: &msgs::TxRemoveInput) {
+               self.received_msg(wire::Message::TxRemoveInput(msg.clone()));
+       }
+
+       fn handle_tx_remove_output(&self, _their_node_id: &PublicKey, msg: &msgs::TxRemoveOutput) {
+               self.received_msg(wire::Message::TxRemoveOutput(msg.clone()));
+       }
+
+       fn handle_tx_complete(&self, _their_node_id: &PublicKey, msg: &msgs::TxComplete) {
+               self.received_msg(wire::Message::TxComplete(msg.clone()));
+       }
+
+       fn handle_tx_signatures(&self, _their_node_id: &PublicKey, msg: &msgs::TxSignatures) {
+               self.received_msg(wire::Message::TxSignatures(msg.clone()));
+       }
+
+       fn handle_tx_init_rbf(&self, _their_node_id: &PublicKey, msg: &msgs::TxInitRbf) {
+               self.received_msg(wire::Message::TxInitRbf(msg.clone()));
+       }
+
+       fn handle_tx_ack_rbf(&self, _their_node_id: &PublicKey, msg: &msgs::TxAckRbf) {
+               self.received_msg(wire::Message::TxAckRbf(msg.clone()));
+       }
+
+       fn handle_tx_abort(&self, _their_node_id: &PublicKey, msg: &msgs::TxAbort) {
+               self.received_msg(wire::Message::TxAbort(msg.clone()));
+       }
 }
 
 impl events::MessageSendEventsProvider for TestChannelMessageHandler {
diff --git a/pending_changelog/blinded_pay_param_compat.txt b/pending_changelog/blinded_pay_param_compat.txt
new file mode 100644 (file)
index 0000000..8e91e00
--- /dev/null
@@ -0,0 +1,3 @@
+## Backwards Compatibility
+
+* `PaymentParameters` written with blinded path info using 0.0.115 will not be readable in 0.0.116